GeezerVison is showing github.com — feat(kiro): messages sent during a Kiro turn steer it natively · pingdotgg/t3code@7cd21e1
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2/testkit/fixtures
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/testkit/fixtures/index.ts +14-6Lines changed: 14 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,6 +38,8 @@ import { claudeResultIsErrorInput } from "./claude_result_is_error/input.ts"; | 38 | 38 | import { assertClaudeResultIsErrorOutput } from "./claude_result_is_error/output.ts"; | 39 | 39 | import { grokAutoBlockedCommandInput } from "./grok_auto_blocked_command/input.ts"; | 40 | 40 | import { kiroCompactionInput } from "./kiro_compaction/input.ts"; | | 41 | +import { kiroMessageSteeringInput } from "./kiro_message_steering/input.ts"; | | 42 | +import { assertKiroMessageSteeringOutput } from "./kiro_message_steering/output.ts"; | 41 | 43 | import { assertKiroCompactionOutput } from "./kiro_compaction/output.ts"; | 42 | 44 | import { KIRO_EFFORT_LEVEL, KIRO_EFFORT_MODEL, kiroEffortInput } from "./kiro_effort/input.ts"; | 43 | 45 | import { assertKiroEffortOutput } from "./kiro_effort/output.ts"; | @@ -546,6 +548,18 @@ export const ORCHESTRATOR_REPLAY_FIXTURES: ReadonlyArray<OrchestratorReplayFixtu | 546 | 548 | }, | 547 | 549 | ], | 548 | 550 | }, | | 551 | + { | | 552 | + name: "kiro_message_steering", | | 553 | + buildInput: kiroMessageSteeringInput, | | 554 | + providers: [ | | 555 | + { | | 556 | + driver: ProviderDriverKind.make("kiro"), | | 557 | + transcriptFile: new URL("./kiro_message_steering/kiro_transcript.ndjson", import.meta.url), | | 558 | + modelSelection: KIRO_MODEL_SELECTION, | | 559 | + assertOutput: assertKiroMessageSteeringOutput, | | 560 | + }, | | 561 | + ], | | 562 | + }, | 549 | 563 | { | 550 | 564 | name: "kiro_compaction", | 551 | 565 | buildInput: kiroCompactionInput, | @@ -1722,12 +1736,6 @@ export const ORCHESTRATOR_REPLAY_FIXTURES: ReadonlyArray<OrchestratorReplayFixtu | 1722 | 1736 | modelSelection: FX_MODEL_SELECTION, | 1723 | 1737 | assertOutput: assertGrokMessageSteeringOutput, | 1724 | 1738 | }, | 1725 | | - { | 1726 | | - driver: ProviderDriverKind.make("kiro"), | 1727 | | - transcriptFile: new URL("./message_steering/kiro_transcript.ndjson", import.meta.url), | 1728 | | - modelSelection: KIRO_MODEL_SELECTION, | 1729 | | - assertOutput: assertGrokMessageSteeringOutput, | 1730 | | - }, | 1731 | 1739 | { | 1732 | 1740 | driver: ProviderDriverKind.make("acpRegistry"), | 1733 | 1741 | transcriptFile: new URL("./message_steering/registry_transcript.ndjson", import.meta.url), | |
Collapse file Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { MESSAGE_STEERING_STEER_PROMPT, type OrchestratorFixtureInput } from "../shared.ts"; | | 2 | + | | 3 | +export const KIRO_MESSAGE_STEERING_PROMPT = | | 4 | + "Run the shell command `sleep 5` once, then respond with exactly: steering fixture initial response"; | | 5 | + | | 6 | +/** The command keeps the turn running, so the steer lands before Kiro's last step. */ | | 7 | +export function kiroMessageSteeringInput(): OrchestratorFixtureInput { | | 8 | + return { | | 9 | + runtimeMode: "full-access", | | 10 | + steps: [ | | 11 | + { type: "message", text: KIRO_MESSAGE_STEERING_PROMPT }, | | 12 | + { type: "steer", text: MESSAGE_STEERING_STEER_PROMPT, targetRunIndex: 1 }, | | 13 | + ], | | 14 | + }; | | 15 | +} |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/testkit/fixtures/kiro_message_steering/kiro_transcript.ndjson +69Lines changed: 69 additions & 0 deletions Large diffs are not rendered by default. Collapse file Copy file name to clipboard +56Lines changed: 56 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { assert } from "@effect/vitest"; | | 2 | +import type { ProviderReplayTranscript } from "@t3tools/contracts"; | | 3 | + | | 4 | +import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts"; | | 5 | +import { | | 6 | + assertAssistantTextIncludes, | | 7 | + assertBaseProjection, | | 8 | + assertSemanticProjectionIntegrity, | | 9 | + assertUserMessageInputIntents, | | 10 | + assertUserMessagesInclude, | | 11 | + MESSAGE_STEERING_STEER_PROMPT, | | 12 | + projectionFor, | | 13 | +} from "../shared.ts"; | | 14 | +import { KIRO_MESSAGE_STEERING_PROMPT } from "./input.ts"; | | 15 | + | | 16 | +function field(value: unknown, key: string): unknown { | | 17 | + return typeof value === "object" && value !== null ? Reflect.get(value, key) : undefined; | | 18 | +} | | 19 | + | | 20 | +export function assertKiroMessageSteeringOutput( | | 21 | + result: OrchestratorV2ScenarioResult, | | 22 | + transcript: ProviderReplayTranscript, | | 23 | +) { | | 24 | + const methods = transcript.entries.flatMap((entry) => | | 25 | + entry.type === "expect_outbound" ? [String(field(entry.frame, "method"))] : [], | | 26 | + ); | | 27 | + // Kiro steers natively: one prompt, one `_session/steer`, and no cancel-and-re-prompt. | | 28 | + assert.deepEqual( | | 29 | + ["session/prompt", "_session/steer", "session/cancel"].map( | | 30 | + (method) => methods.filter((candidate) => candidate === method).length, | | 31 | + ), | | 32 | + [1, 1, 0], | | 33 | + ); | | 34 | + | | 35 | + assertBaseProjection({ result, transcript, runCount: 1, runStatuses: ["completed"] }); | | 36 | + const projection = projectionFor(result, transcript.scenario); | | 37 | + assertSemanticProjectionIntegrity(projection); | | 38 | + assertUserMessagesInclude(projection, [ | | 39 | + KIRO_MESSAGE_STEERING_PROMPT, | | 40 | + MESSAGE_STEERING_STEER_PROMPT, | | 41 | + ]); | | 42 | + assertUserMessageInputIntents(projection, ["turn_start", "steer"]); | | 43 | + assertAssistantTextIncludes(projection, "steering fixture observed"); | | 44 | + // Kiro's model appends a `[STEERING steer-…]` note for Kiro's own UI; T3 drops it. | | 45 | + assert.notInclude( | | 46 | + projection.turnItems | | 47 | + .map((item) => (item.type === "assistant_message" ? item.text : "")) | | 48 | + .join(""), | | 49 | + "[STEERING", | | 50 | + ); | | 51 | + assert.equal( | | 52 | + projection.providerTurns.length, | | 53 | + 1, | | 54 | + "active steering must not create a new provider turn", | | 55 | + ); | | 56 | +} |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/testkit/fixtures/message_steering/kiro_transcript.ndjson -40Lines changed: 0 additions & 40 deletions Collapse file Copy file name to clipboardExpand all lines: packages/provider-acp/src/server/adapter.ts +93-7Lines changed: 93 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -344,6 +344,20 @@ export interface AcpAdapterV2Flavor { | 344 | 344 | ) => Effect.Effect<void>; | 345 | 345 | readonly subagentsIdleOnTurnCompletion?: boolean; | 346 | 346 | readonly supportsCompaction?: boolean; | | 347 | + /** | | 348 | + * Native steering: `send` queues a message into the running turn and returns the | | 349 | + * agent's id for it, which `injectedSteerId` reads from the update that delivers it. | | 350 | + */ | | 351 | + readonly steering?: { | | 352 | + readonly send: ( | | 353 | + runtime: AcpSessionRuntime.AcpSessionRuntime["Service"], | | 354 | + sessionId: string, | | 355 | + text: string, | | 356 | + ) => Effect.Effect<string, EffectAcpErrors.AcpError>; | | 357 | + readonly injectedSteerId: ( | | 358 | + notification: EffectAcpSchema.SessionNotification, | | 359 | + ) => string | undefined; | | 360 | + }; | 347 | 361 | /** Compacts with the agent's own request, for agents that answer a `/compact` prompt as chat. */ | 348 | 362 | readonly compactSession?: ( | 349 | 363 | runtime: AcpSessionRuntime.AcpSessionRuntime["Service"], | @@ -606,6 +620,8 @@ export const AcpProviderCapabilitiesV2 = { | 606 | 620 | }, | 607 | 621 | } satisfies OrchestrationV2ProviderCapabilities; | 608 | 622 |
| | 623 | +const STEER_DELIVERY_BOUND = "2 seconds"; | | 624 | + | 609 | 625 | function isCompactionMessage(message: ProviderAdapter.ProviderAdapterV2TurnMessage): boolean { | 610 | 626 | return message.text.trim() === "/compact" && message.attachments.length === 0; | 611 | 627 | } | @@ -1609,6 +1625,15 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | 1609 | 1625 | input.runtimePolicy; | 1610 | 1626 | const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>(); | 1611 | 1627 | const activeTurn = yield* Ref.make<ActiveAcpTurn | null>(null); | | 1628 | + // Keyed by the agent's steer id; an injection can arrive before its send returns. | | 1629 | + const steerInjections = new Map<string, Deferred.Deferred<void>>(); | | 1630 | + const steerInjection = (steerId: string) => { | | 1631 | + const existing = steerInjections.get(steerId); | | 1632 | + if (existing !== undefined) return existing; | | 1633 | + const created = Deferred.makeUnsafe<void>(); | | 1634 | + steerInjections.set(steerId, created); | | 1635 | + return created; | | 1636 | + }; | 1612 | 1637 | let pendingStopCloseTurn: ActiveAcpTurn | null = null; | 1613 | 1638 | let followsAgentWorkState = false; | 1614 | 1639 | let agentWork: Extract< | @@ -5887,6 +5912,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | 5887 | 5912 | Effect.fnUntraced( | 5888 | 5913 | function* (rawNotification: EffectAcpSchema.SessionNotification) { | 5889 | 5914 | if (flavor.ignoreSessionUpdate?.(rawNotification) === true) return; | | 5915 | + const injectedSteerId = flavor.steering?.injectedSteerId(rawNotification); | | 5916 | + if (injectedSteerId !== undefined) { | | 5917 | + yield* Deferred.succeed(steerInjection(injectedSteerId), undefined); | | 5918 | + } | 5890 | 5919 | yield* markPromptStarted(rawNotification); | 5891 | 5920 | const embedded = embeddedTerminalIdsFromSessionUpdate(rawNotification); | 5892 | 5921 | if (embedded !== undefined) { | @@ -7278,6 +7307,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | 7278 | 7307 | } | 7279 | 7308 | } | 7280 | 7309 | yield* Ref.set(activeTurn, null); | | 7310 | + steerInjections.clear(); | 7281 | 7311 | if ( | 7282 | 7312 | postSettleContinuationEnabled && | 7283 | 7313 | settledStatus === "completed" && | @@ -8141,13 +8171,69 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | 8141 | 8171 | }), | 8142 | 8172 | } | 8143 | 8173 | : {}), | 8144 | | - steerTurn: (turnInput) => | 8145 | | - Effect.fail( | 8146 | | - new ProviderAdapter.ProviderAdapterSteerRunUnsupportedError({ | 8147 | | - driver, | 8148 | | - providerThreadId: turnInput.providerThread.id, | 8149 | | - }), | 8150 | | - ), | | 8174 | + steerTurn: Effect.fn("AcpAdapterV2.steerTurn")( | | 8175 | + function* (turnInput) { | | 8176 | + const steering = flavor.steering; | | 8177 | + // The agent takes text only, so a steer with attachments waits for the next turn. | | 8178 | + if (steering === undefined || turnInput.message.attachments.length > 0) { | | 8179 | + return yield* new ProviderAdapter.ProviderAdapterSteerRunUnsupportedError({ | | 8180 | + driver, | | 8181 | + providerThreadId: turnInput.providerThread.id, | | 8182 | + }); | | 8183 | + } | | 8184 | + const context = yield* Ref.get(activeTurn); | | 8185 | + if ( | | 8186 | + context === null || | | 8187 | + context.finalized || | | 8188 | + context.providerTurnId !== turnInput.providerTurnId | | 8189 | + ) { | | 8190 | + return yield* new ProviderAdapter.ProviderAdapterProtocolError({ | | 8191 | + driver, | | 8192 | + detail: `Provider turn ${turnInput.providerTurnId} is not active and cannot be steered.`, | | 8193 | + }); | | 8194 | + } | | 8195 | + // An agent that drops an early cancel drops an early steer too. | | 8196 | + const startHold = flavor.cancelAfterPromptStarts; | | 8197 | + if (startHold !== undefined) { | | 8198 | + yield* Deferred.await(context.promptStarted).pipe( | | 8199 | + Effect.timeoutOption(startHold.bound), | | 8200 | + ); | | 8201 | + } | | 8202 | + const steerId = yield* steering.send( | | 8203 | + runtime, | | 8204 | + context.nativeThreadId, | | 8205 | + turnInput.message.text, | | 8206 | + ); | | 8207 | + const injected = steerInjection(steerId); | | 8208 | + // The agent reads a steer at its next step. One that lands after the last | | 8209 | + // step is dropped, and the turn settles right after; the orchestrator then | | 8210 | + // sends it as a follow-up. The bound keeps Stop from queueing behind a tool. | | 8211 | + const outcome = yield* Effect.raceFirst( | | 8212 | + Deferred.await(injected).pipe(Effect.as("injected" as const)), | | 8213 | + Deferred.await(context.promptWireSettled).pipe(Effect.as("settled" as const)), | | 8214 | + ).pipe(Effect.timeoutOption(STEER_DELIVERY_BOUND)); | | 8215 | + steerInjections.delete(steerId); | | 8216 | + if (Option.contains(outcome, "settled") && !(yield* Deferred.isDone(injected))) { | | 8217 | + return yield* new ProviderAdapter.ProviderAdapterProtocolError({ | | 8218 | + driver, | | 8219 | + detail: `Provider turn ${turnInput.providerTurnId} ended before it read the steering message.`, | | 8220 | + }); | | 8221 | + } | | 8222 | + }, | | 8223 | + (effect, turnInput) => | | 8224 | + effect.pipe( | | 8225 | + Effect.mapError((cause) => | | 8226 | + cause._tag === "ProviderAdapterSteerRunUnsupportedError" | | 8227 | + ? cause | | 8228 | + : new ProviderAdapter.ProviderAdapterSteerRunError({ | | 8229 | + driver, | | 8230 | + providerThreadId: turnInput.providerThread.id, | | 8231 | + providerTurnId: turnInput.providerTurnId, | | 8232 | + cause, | | 8233 | + }), | | 8234 | + ), | | 8235 | + ), | | 8236 | + ), | 8151 | 8237 | interruptTurn: Effect.fn("AcpAdapterV2.interruptTurn")( | 8152 | 8238 | function* (turnInput: ProviderAdapter.ProviderAdapterV2InterruptInput) { | 8153 | 8239 | return yield* Effect.uninterruptibleMask((restore) => | |
|