From dc52fc41780a020357336c36505fa7f1b10d2dd0 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Sun, 8 Nov 2026 00:56:28 +0000 Subject: [PATCH] fix(kiro): steered replies no longer lose or move a trailing "[" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After a steer, the Kiro adapter holds back a chunk end that could start Kiro's "[STEERING steer-…]" note. Nothing released it: a reply ending in "[" lost the bracket at turn end, and a "[" before a tool call moved to the start of the next message. The steering filter now releases held text as its own chunk when a non-text update (such as a tool call) or the steer's start or end arrives. The shared ACP normalizeSessionUpdate hook returns a list so a flavor can emit that extra chunk. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/AcpAdapterV2.test.ts | 6 +- .../Adapters/KiroAdapterV2.test.ts | 78 +++++++++++++++++++ .../src/server/adapter.ts | 6 +- packages/provider-acp/src/server/adapter.ts | 10 ++- packages/provider-kiro/src/server/adapter.ts | 42 ++++++---- 5 files changed, 119 insertions(+), 23 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index f63a220fb519..2bf3baaa571e 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -2680,7 +2680,7 @@ describe("AcpAdapterV2", () => { flavor: { driver: ACP_TEST_DRIVER, capabilities: AcpProviderCapabilitiesV2, - normalizeSessionUpdate: normalizeDevinSessionUpdate, + normalizeSessionUpdate: (notification) => [normalizeDevinSessionUpdate(notification)], normalizeToolCall: normalizeDevinToolCall, extractSubagentUpdate: extractDevinSubagentUpdate, makeRuntime: makeMockRuntime({ @@ -2819,7 +2819,7 @@ describe("AcpAdapterV2", () => { flavor: { driver: ACP_TEST_DRIVER, capabilities: AcpProviderCapabilitiesV2, - normalizeSessionUpdate: normalizeDevinSessionUpdate, + normalizeSessionUpdate: (notification) => [normalizeDevinSessionUpdate(notification)], normalizeToolCall: normalizeDevinToolCall, extractSubagentUpdate: extractDevinSubagentUpdate, makeRuntime: makeMockRuntime({ @@ -3146,7 +3146,7 @@ describe("AcpAdapterV2", () => { driver: ACP_TEST_DRIVER, capabilities: AcpProviderCapabilitiesV2, registerExtensions: routing.registerExtensions, - normalizeSessionUpdate: routing.normalizeSessionUpdate, + normalizeSessionUpdate: (notification) => [routing.normalizeSessionUpdate(notification)], extractSubagentUpdate: extractCopilotSubagentUpdate, makeRuntime: makeMockRuntime({ childProcessSpawner, diff --git a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts index 30304449c0f0..8bb25a0a3be5 100644 --- a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts @@ -1324,6 +1324,84 @@ describe("KiroAdapterV2 MCP tools", () => { ); }); +describe("KiroAdapterV2 steering note", () => { + // Frame shapes from the Kiro 2.33.1 recording in fixtures/kiro_message_steering. + const kiroInfo = (kiro: Record) => + update({ sessionUpdate: "session_info_update", _meta: { kiro } }); + const steerId = "steer-00000000-0000-4000-9000-000000000003"; + const steeringInjected = kiroInfo({ + kind: "steering_injected", + messageId: steerId, + content: "Answer differently", + }); + const turnEnd = kiroInfo({ + turnEnd: { stopReason: "end_turn" }, + kind: "turn_end", + stopReason: "end_turn", + }); + const steeringCleared = kiroInfo({ kind: "steering_cleared", messageIds: [steerId] }); + const chunk = (text: string) => + update({ sessionUpdate: "agent_message_chunk", content: { type: "text", text } }); + const readFile = [ + update({ + sessionUpdate: "tool_call", + toolCallId: "tool-read", + title: "Read file", + kind: "read", + status: "pending", + rawInput: { path: "README.md" }, + }), + update({ + sessionUpdate: "tool_call_update", + toolCallId: "tool-read", + status: "completed", + rawOutput: "ok", + content: [{ type: "content", content: { type: "text", text: "ok" } }], + }), + ]; + + it.effect.each([ + { + label: "at the end of the turn", + reply: [chunk("Fill in the blank: x = [")], + messages: ["Fill in the blank: x = ["], + }, + { + label: "before a tool call", + reply: [chunk("Checking the list ["), ...readFile, chunk("All good.")], + messages: ["Checking the list [", "All good."], + }, + ])("keeps a steered reply's trailing '[' in place $label", ({ label, reply, messages }) => + runKiroScript({ + scenario: `steering-bracket-${label.replaceAll(" ", "-")}`, + frames: [ + ...openSessionFrames({ + initialize: KIRO_V3_INITIALIZE, + configOptions: [modeOption, autopilotOption("on")], + }), + turnPrompt, + steeringInjected, + ...reply, + turnEnd, + steeringCleared, + answer("session/prompt", { stopReason: "end_turn" }), + ...closeSession, + ], + drive: ({ events, startTurn }) => + Effect.gen(function* () { + yield* startTurn; + const texts = new Map(); + for (const event of yield* collectTurn(events)) { + if (event.type === "turn_item.updated" && event.turnItem.type === "assistant_message") { + texts.set(event.turnItem.id, event.turnItem.text); + } + } + assert.deepEqual([...texts.values()], messages); + }), + }).pipe(Effect.provide(testLayer), Effect.scoped), + ); +}); + describe("KiroAdapterV2 unknown model", () => { // Recorded live from Kiro 2.27.0 with the thread on a model id the account // lacks. Kiro has not advertised `model` yet, so T3 sends the id; Kiro diff --git a/packages/provider-acp-registry/src/server/adapter.ts b/packages/provider-acp-registry/src/server/adapter.ts index 1b8b4240fd00..3683c3cc8ce4 100644 --- a/packages/provider-acp-registry/src/server/adapter.ts +++ b/packages/provider-acp-registry/src/server/adapter.ts @@ -242,7 +242,7 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu "cognition.ai/subagentSupport": true, "cognition.ai/messageGrouping": true, }, - normalizeSessionUpdate: normalizeDevinSessionUpdate, + normalizeSessionUpdate: (notification) => [normalizeDevinSessionUpdate(notification)], normalizeToolCall: normalizeDevinToolCall, extractSubagentUpdate: extractDevinSubagentUpdate, } @@ -254,7 +254,9 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu // Copilot CLI 1.0.105 rejects stdio MCP servers from the client. mcpOverHttp: true, registerExtensions: copilotRouting.registerExtensions, - normalizeSessionUpdate: copilotRouting.normalizeSessionUpdate, + normalizeSessionUpdate: (notification) => [ + copilotRouting.normalizeSessionUpdate(notification), + ], extractSubagentUpdate: extractCopilotSubagentUpdate, restartRuntimeAfterPromptError: isCopilotLostSessionError, }), diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index c4fc2f092644..c11beb19fb10 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -335,7 +335,7 @@ export interface AcpAdapterV2Flavor { readonly mcpOverHttp?: boolean; readonly normalizeSessionUpdate?: ( notification: EffectAcpSchema.SessionNotification, - ) => EffectAcpSchema.SessionNotification; + ) => ReadonlyArray; /** * Agent updates that belong to no turn (Kiro's own cloud-config fetch). They * are dropped before anything reads them, so they neither show in the turn @@ -6335,9 +6335,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( ) ?? Effect.void ); } - yield* handleSessionUpdate( - flavor.normalizeSessionUpdate?.(notification) ?? notification, - ); + for (const normalized of flavor.normalizeSessionUpdate?.(notification) ?? [ + notification, + ]) { + yield* handleSessionUpdate(normalized); + } }, Effect.mapError( (cause) => diff --git a/packages/provider-kiro/src/server/adapter.ts b/packages/provider-kiro/src/server/adapter.ts index 6815b60e8f22..940fa78afcc6 100644 --- a/packages/provider-kiro/src/server/adapter.ts +++ b/packages/provider-kiro/src/server/adapter.ts @@ -414,28 +414,40 @@ function steeringNotePrefixLength(text: string): number { /** * After an injected steer, Kiro's model ends its reply with a `[STEERING steer-…: …]` * note meant for Kiro's own UI. This drops it from the streamed text, holding back a - * chunk end that may be the start of the note until the next chunk shows otherwise. + * chunk end that may be the start of the note until the next chunk shows otherwise, + * or a tool call, another non-text update or the steer's end releases it. */ function makeKiroSteeringNoteFilter() { const sessions = new Map(); + const releaseHeld = (sessionId: string): ReadonlyArray => { + const state = sessions.get(sessionId); + if (state === undefined || state.held === "") return []; + const text = state.held; + state.held = ""; + return [ + { + sessionId, + update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text } }, + }, + ]; + }; return ( notification: EffectAcpSchema.SessionNotification, - ): EffectAcpSchema.SessionNotification => { + ): ReadonlyArray => { const { update } = notification; if (update.sessionUpdate === "session_info_update") { const kind = Option.getOrUndefined(decodeKiroSteeringInfo(update._meta))?.kiro.kind; + if (kind !== "steering_injected" && kind !== "steering_cleared") return [notification]; + const released = releaseHeld(notification.sessionId); if (kind === "steering_injected") { sessions.set(notification.sessionId, { held: "", inNote: false }); - } else if (kind === "steering_cleared") sessions.delete(notification.sessionId); - return notification; + } else sessions.delete(notification.sessionId); + return [...released, notification]; } const state = sessions.get(notification.sessionId); - if ( - state === undefined || - update.sessionUpdate !== "agent_message_chunk" || - update.content.type !== "text" - ) { - return notification; + if (state === undefined) return [notification]; + if (update.sessionUpdate !== "agent_message_chunk" || update.content.type !== "text") { + return [...releaseHeld(notification.sessionId), notification]; } let pending = state.held + update.content.text; let visible = ""; @@ -460,10 +472,12 @@ function makeKiroSteeringNoteFilter() { state.held = pending.slice(pending.length - held); break; } - return { - ...notification, - update: { ...update, content: { ...update.content, text: visible } }, - }; + return [ + { + ...notification, + update: { ...update, content: { ...update.content, text: visible } }, + }, + ]; }; }