fix(kiro): update ACP adapter for kiro-cli 2.x protocol#149
Conversation
kiro-cli 2.x moved ACP to a top-level subcommand and changed the JSON-RPC protocol in several breaking ways. This updates the adapter to match the current protocol: - Spawn `kiro-cli acp --agent <name>` instead of `kiro-cli chat --agent <name> --acp` - Send `protocolVersion` as integer `1` (not string "1.0") - Pass required `cwd` and `mcpServers` params to `session/new` - Use `prompt` field (content block array) for `session/prompt` - Handle `session/update` notifications with `update.sessionUpdate` discriminator instead of separate method-name events - Derive turn completion from the `session/prompt` RPC response Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5da415f9e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Agent turns can run for minutes (tool use, reading files, etc.). The 60s default timeout on the ACP client would kill the call mid-turn. Pass timeout=0 to disable the timer for session/prompt while keeping the default 60s timeout for short-lived calls like initialize and session/new. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ll-tools When a thread had a persisted sessionId from an earlier run, the adapter called session/load on a fresh kiro-cli process. kiro-cli responds to an unknown sessionId by exiting cleanly (code 0) instead of returning a JSON-RPC error, which closed the AcpClient. The catch around session/load swallowed the rejection, but the subsequent fallback to session/new then ran on a dead process and failed with "ACP client is closed". Recovery now: - Clears the stale persisted id via SessionStore.clearPersistedSessionId - Detects that the AcpClient closed and respawns kiro-cli before falling through to session/new - Logs stderr on unexpected kiro-cli exits to surface protocol errors instead of failing silently Also pass --trust-all-tools to the spawn so tool-use prompts don't block waiting for permission responses we don't implement. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ner closure capture Two changes from a code review pass: 1. Extracted JSON-RPC method names, notification names, and session/update discriminator values into src/agents/kiro/acp/methods.ts as AcpMethod / AcpEvent / SessionUpdateKind. Adapter call sites and subscribe/unsubscribe pairs now reference the constants. A protocol rev now touches one file instead of every call site, and typos at call sites become compile errors. 2. The exit listener in ensureProcess() referenced this.mainProcess from inside its closure. If the process exited *after* a respawn replaced this.mainProcess, the listener would read the new process's stderr instead of the dead one's. The listener now captures the AcpProcess in a local so it always reports stderr for the process it was registered on. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1abf19b3ef
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…e lifecycle, dual subscribe, hardcoded window Four findings from the automated PR review: 1. session/load was missing required `cwd` and `mcpServers` params per the ACP v1 spec. With the wrong shape, kiro-cli rejects the request, our catch clears the persisted id, and we silently fall through to session/new — defeating thread resumption. Pass the correct shape. Note: kiro-cli sessions are per-process and don't survive a kiro-cli restart, so session/load fails legitimately when the original kiro-cli process is gone — recovery still handles that path correctly. 2. tool_call_update arrives multiple times per tool call (in-progress updates plus a terminal completed/failed transition). Emitting tool_end on every one prematurely closed the gateway's tool lifecycle and masked failures. Gate tool_end on terminal status and derive isError from `status === "failed"`. 3. The adapter subscribed the same handler to both `session/update` and `_kiro.dev/session/update`. The two are not mirrors — they multiplex disjoint sets of update kinds. Subscribing to both either no-ops (today, since we don't handle tool_call_chunk) or duplicates events (the moment we do). Subscribe only to the canonical session/update. 4. The 200k context window magic number is now a documented module-level constant `KIRO_DEFAULT_CONTEXT_WINDOW` with an explanation of why we approximate (kiro emits percent only; pressure classifier short- circuits if window is null) and what to replace it with when kiro exposes a real window field. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80333193f7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Bumps to 0.5.41 to publish the kiro adapter fixes merged in #149: ACP 2.x protocol compatibility, stale-session-id recovery, session/load shape, tool_call_update terminal-only emission, and single-channel session/update subscription. Co-authored-by: osherove <osherove@amazon.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
kiro-cli acp --agent <name>replaces the removedkiro-cli chat --agent <name> --acpinvocationprotocolVersionis now integer1(was string"1.0"); addsclientCapabilitiessession/newrequirescwdandmcpServersparams (was empty{})session/promptusesprompt: [{type: "text", text: "..."}]content-block array (was plaintextstring)session/updatenotifications with anupdate.sessionUpdatediscriminator (agent_message_chunk,tool_call,tool_call_update) instead of separate method-name notifications. Turn completion is derived from thesession/promptRPC response rather than acompletenotification.Context
kiro-cli 2.x introduced breaking changes to the ACP protocol. The adapter was written against a pre-release spec that no longer matches the shipping CLI. These changes were validated against kiro-cli 2.4.0.
Test plan
kiro-cli acpspawns and stays aliveinitialize→session/new→session/promptround-trip works with correct field namessession/updatenotifications