mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-26 05:27:06 +00:00
feat(claude): mid-turn Steer for remote Claude sessions (#2259)
* feat(claude): mid-turn Steer for remote Claude sessions Queued messages can now be steered into a running Claude turn, the same as Ctrl+X Ctrl+S in the Claude TUI. The row is written to the live stream-json stdin and Claude folds it in at its next tool boundary. - Spawn Claude with --replay-user-messages and tag every stdin message with a uuid; the echo acks pickup and is never relayed to chat - A result that arrives while a steer is still unacked does not end the turn: Claude runs a follow-up turn for it, so ready waits for that result - Launcher registers steer-queued-message: reserve the row, reject control commands and mode mismatches, ack the hub after the write, mark consumed (steered) on the echo; abort before pickup holds the row indeterminate, an unprompted exit requeues it - Open the shared steer gate and peer/hub wording to Claude (remote only) * fix(claude): retire completed input before a steer follow-up turn - Generalize onCompactResultAccepted to onResultAccepted and fire it when a result arrives with a steer still unacked, so a stream failure during the follow-up turn recovers only the steer instead of replaying the finished prompt - Close the steer target and settle pending steers when query() setup throws, so a retry backoff cannot accept a steer nobody will read
This commit is contained in:
@@ -149,7 +149,7 @@ describe('isSteeringSupportedForFlavor', () => {
|
||||
expect(isSteeringSupportedForFlavor('codex')).toBe(true)
|
||||
expect(isSteeringSupportedForFlavor('cursor')).toBe(true)
|
||||
expect(isSteeringSupportedForFlavor('pi')).toBe(true)
|
||||
expect(isSteeringSupportedForFlavor('claude')).toBe(false)
|
||||
expect(isSteeringSupportedForFlavor('claude')).toBe(true)
|
||||
expect(isSteeringSupportedForFlavor('opencode')).toBe(false)
|
||||
expect(isSteeringSupportedForFlavor(undefined)).toBe(false)
|
||||
expect(isSteeringSupportedForFlavor(null)).toBe(false)
|
||||
@@ -160,6 +160,7 @@ describe('isSteeringSupportedForSession', () => {
|
||||
it('supports codex and pi sessions', () => {
|
||||
expect(isSteeringSupportedForSession({ flavor: 'codex' })).toBe(true)
|
||||
expect(isSteeringSupportedForSession({ flavor: 'pi' })).toBe(true)
|
||||
expect(isSteeringSupportedForSession({ flavor: 'claude' })).toBe(true)
|
||||
})
|
||||
|
||||
it('supports Cursor ACP sessions', () => {
|
||||
@@ -184,7 +185,7 @@ describe('isSteeringSupportedForSession', () => {
|
||||
})
|
||||
|
||||
it('rejects non-steerable flavors', () => {
|
||||
expect(isSteeringSupportedForSession({ flavor: 'claude' })).toBe(false)
|
||||
expect(isSteeringSupportedForSession({ flavor: 'opencode' })).toBe(false)
|
||||
expect(isSteeringSupportedForSession(null)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
+5
-3
@@ -194,10 +194,12 @@ export function getCodexCollaborationModeOptions(): CodexCollaborationModeOption
|
||||
* - Cursor ACP: concurrent `session/prompt` soft-send (no cancel). Legacy
|
||||
* stream-json Cursor sessions are NOT steerable — gate with
|
||||
* {@link isSteeringSupportedForSession}.
|
||||
* - Claude: stream-json stdin write during the turn (TUI Ctrl+X Ctrl+S);
|
||||
* Claude folds it in at the next tool boundary. Remote mode only.
|
||||
*
|
||||
* Claude / others: not supported (no reachable soft-steer path) — UI hides Steer.
|
||||
* Others: not supported — UI hides Steer.
|
||||
*/
|
||||
export const STEERING_SUPPORTED_FLAVORS = ['codex', 'cursor', 'pi'] as const
|
||||
export const STEERING_SUPPORTED_FLAVORS = ['claude', 'codex', 'cursor', 'pi'] as const
|
||||
|
||||
export function isSteeringSupportedForFlavor(flavor?: string | null): boolean {
|
||||
return (STEERING_SUPPORTED_FLAVORS as readonly string[]).includes(flavor ?? '')
|
||||
@@ -216,7 +218,7 @@ export function isSteeringSupportedForSession(metadata?: {
|
||||
cursorSessionId?: string | null
|
||||
cursorSessionProtocol?: 'acp' | 'stream-json' | null
|
||||
} | null): boolean {
|
||||
if (metadata?.flavor === 'codex' || metadata?.flavor === 'pi') {
|
||||
if (metadata?.flavor === 'claude' || metadata?.flavor === 'codex' || metadata?.flavor === 'pi') {
|
||||
return true
|
||||
}
|
||||
if (metadata?.flavor !== 'cursor') {
|
||||
|
||||
@@ -32,7 +32,7 @@ export const PEER_DELIVERY_MODE_DESCRIPTION =
|
||||
'steer: use for important, time-sensitive findings the peer needs to know now, not after finishing its current turn ' +
|
||||
'(e.g. a correction that invalidates its assumptions, a blocker, or a result that changes its next action). ' +
|
||||
'State why the finding matters now and what the peer should adjust. ' +
|
||||
'Steer requires insertion into an active Pi, Codex, or Cursor ACP turn; unsupported, idle, or inactive targets are rejected before sending. ' +
|
||||
'Steer requires insertion into an active Claude, Pi, Codex, or Cursor ACP turn; unsupported, idle, or inactive targets are rejected before sending. ' +
|
||||
'Steering does not abort the current turn or guarantee an immediate response. ' +
|
||||
'If send or steer is unconfirmed after submission, inspect the target before retrying; do not resend automatically.'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user