Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down
78 changes: 78 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>) =>
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<string, string>();
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
Expand Down
6 changes: 4 additions & 2 deletions packages/provider-acp-registry/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}),
Expand Down
10 changes: 6 additions & 4 deletions packages/provider-acp/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export interface AcpAdapterV2Flavor {
readonly mcpOverHttp?: boolean;
readonly normalizeSessionUpdate?: (
notification: EffectAcpSchema.SessionNotification,
) => EffectAcpSchema.SessionNotification;
) => ReadonlyArray<EffectAcpSchema.SessionNotification>;
/**
* 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
Expand Down Expand Up @@ -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) =>
Expand Down
42 changes: 28 additions & 14 deletions packages/provider-kiro/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, { held: string; inNote: boolean }>();
const releaseHeld = (sessionId: string): ReadonlyArray<EffectAcpSchema.SessionNotification> => {
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<EffectAcpSchema.SessionNotification> => {
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 = "";
Expand All @@ -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 } },
},
];
};
}

Expand Down
Loading