Skip to content

fix(kiro): update ACP adapter for kiro-cli 2.x protocol#149

Merged
royosherove merged 5 commits into
mainfrom
fix/kiro-acp-protocol-compat
May 20, 2026
Merged

fix(kiro): update ACP adapter for kiro-cli 2.x protocol#149
royosherove merged 5 commits into
mainfrom
fix/kiro-acp-protocol-compat

Conversation

@royosherove
Copy link
Copy Markdown
Member

Summary

  • Spawn command: kiro-cli acp --agent <name> replaces the removed kiro-cli chat --agent <name> --acp invocation
  • Protocol handshake: protocolVersion is now integer 1 (was string "1.0"); adds clientCapabilities
  • Session creation: session/new requires cwd and mcpServers params (was empty {})
  • Prompt format: session/prompt uses prompt: [{type: "text", text: "..."}] content-block array (was plain text string)
  • Event model: kiro-cli 2.x sends all events via session/update notifications with an update.sessionUpdate discriminator (agent_message_chunk, tool_call, tool_call_update) instead of separate method-name notifications. Turn completion is derived from the session/prompt RPC response rather than a complete notification.

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

  • Verified kiro-cli acp spawns and stays alive
  • Verified initializesession/newsession/prompt round-trip works with correct field names
  • Verified text streaming and tool-use events arrive via session/update notifications
  • End-to-end test via Telegram bot with kiro backend responding to messages

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>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agents/kiro/kiro-adapter.ts Outdated
Comment thread src/agents/kiro/kiro-adapter.ts Outdated
osherove and others added 3 commits May 20, 2026 13:15
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>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agents/kiro/kiro-adapter.ts Outdated
Comment thread src/agents/kiro/kiro-adapter.ts Outdated
…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>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agents/kiro/kiro-adapter.ts
@royosherove royosherove merged commit 6242303 into main May 20, 2026
1 check passed
royosherove added a commit that referenced this pull request May 20, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant