Skip to content

feat: first-class Kiro CLI executor on its subscription login - #4

Merged
goodloris merged 8 commits into
mainfrom
feat/kiro-cli
Nov 17, 2026
Merged

goodloris merged 8 commits into
mainfrom
feat/kiro-cli

Conversation

@goodloris

Copy link
Copy Markdown
Owner

依赖 / Depends on: 本 PR 的前两个提交就是 #2(credits)和 #3(MCP null 字段)。建议先合并那两个,或者只审查 1f441cf 之后的 5 个提交。
The first two commits are #2 (credits) and #3 (MCP null fields). Merge those first, or review only the five commits from 1f441cf on.

动机 / Why

让 Kiro CLI 成为一等执行器,能力与 Codex 对齐:SOP 节点、Main Bot 对话、对话工作区、Docker 沙箱、用量统计都可用。

真实部署使用 订阅登录(kiro-cli login,IAM Identity Center),不使用 KIRO_API_KEY。因此本 PR 的核心问题是:在不泄露、不改写宿主机登录的前提下,把登录交给各种沙箱。

Make Kiro CLI a first-class executor on par with Codex: SOP nodes, Main Bot chat, conversation workspaces, Docker sandboxes and usage accounting. Real deployments use the subscription login (kiro-cli login), never an API key, so the core problem is handing that login to sandboxes without exposing or modifying the host's.

改动 / Changes

runtime(1f441cf)

  • 新增执行器 kind kiro,二进制 kiro-cli 3.3.0。命令为 kiro-cli chat --v3 --no-interactive --output-format stream-json。SOP 节点和工作区使用 --trust-all-tools;只读对话只信任 read/grep/glob、skill / sub-agent 加载和会话的 MCP server。
  • domain.AgentCLIAuthMode("kiro") 固定为本机登录。runner 上报运行时、修改认证方式时都保持这一点。
  • KIRO_HOME 指向私有 HOME,MCP、hooks、agents、sessions 都放在那里。每次运行都写入 settings/cli.json,关闭 tool search。开启时 Kiro 会把 MCP schema 藏到 tool_load 后面,模型曾因此报告 submit_assistant_reply 不可用。
  • 登录副本(kiro_login.go):凡是沙箱(Docker、seatbelt、bwrap),以及只挂载了宿主登录的平台(AGENTFLOW_KIRO_DATA_DIR),都运行在一份登录副本上。副本用 SQLite VACUUM INTO 生成,只保留 auth_kv 的 kirocli:odic:* 行、migrations,以及 state 中的 profile 和 IdC 设置,不含任何对话和历史。沙箱里的 agent 因此读不到也写不了宿主的 kiro-cli 数据。refresh token 不轮换,副本刷新 access token 不会让宿主掉线(已用 IAM Identity Center 验证)。
  • 只有不进沙箱(local driver)时,Kiro 才直接使用本机登录。
  • 运行时缓存:kiro-cli 的运行时约 415 MB。
    • 进程沙箱共用一份由宿主解压一次的只读运行时(EnsureKiroHostRuntime),以 kiro-cli 版本作为 key,并在完整性检查通过后才发布。
    • Docker 沙箱使用镜像内的 KIRO_RUNTIME_DIR,没有时每次运行解压一次。
    • 镜像里没有 kiro-cli 时,使用执行机器 AGENTFLOW_RUNTIME_CLI_DIR 中的缓存;缓存也没有,就在 Docker 内安装固定版本,并校验 SHA-256。
  • 包装脚本删除过期的 session lease(否则跨容器 --resume-id 会被拒绝),并在 prompt 前刷新 token。Docker 之外不把 HOME 下的任何目录放进 PATH,系统工具用绝对路径调用。
  • ACP 流翻译:文本、推理、工具调用、子 agent 派发(Task)、skill 加载(Skill);隐藏 schema 加载。credits 分两份上报:usage.credits 是会话累计,交给 engine 的 per-session cursor 拆分到每次 SOP 调用;usage.turn_credits 是本次调用的用量。
  • 对话审批:在 KIRO_HOME/hooks 安装全局 PreToolUse hook。每次对话启动时清理 KIRO_HOME,只保留 sessions、logs、登录状态和平台会重写的文件,这样工作区回合植入的 hooks、权限规则、steering 不会在之后的平台模式回合中生效。所有 provider 的审批 hook 改用 python3 -I 启动,忽略 HOME 中的 usercustomize.py 和 PYTHON* 变量。

assistant(cf2a0d2)

  • Kiro 作为对话引擎,没有 key。引擎列表在以下情况下标为已配置:本服务器装有 kiro-cli 且已登录,或用户自己的某台在线执行机器上报了 kiro。回合不会被提前拒绝,缺少 kiro-cli 或登录时,由实际执行的机器报告。
  • 对话累加每次调用的 credits(turn_credits)。
  • 项目角色转成 Kiro V3 Markdown agent,写到 KIRO_HOME/agents;skills 写到 KIRO_HOME/skills。
  • 原生审批认识 Kiro 的工具名:mcp_<server>_<tool>、tool_load、disclose_context、invoke_sub_agent。
  • chatbot 的执行器切换里加入 Kiro CLI。

web(d565845)

  • 角色、SOP 页面的执行器选项加入 Kiro。SOP 运行检查提示需要 kiro-cli login,而不是 API Key。
  • 执行机器页面显示 kiro 运行时,认证来源固定为「本机登录(订阅)」。

build / docs(9c30554)

  • Dockerfile 安装 kiro-cli 3.3.0(amd64 / arm64,校验 SHA-256),并把运行时预解压到 KIRO_RUNTIME_DIR=/opt/kiro-runtime。
  • compose.yaml 把 LOOPFORGE_KIRO_DATA_DIR 只读挂载到 /kiro-host。
  • README 和 docs/deployment.md 补充 Kiro 部署说明。

e2e(694e917)

  • local.sh 设置 AGENTFLOW_E2E_EXECUTOR=kiro 后,用本机的 kiro-cli 登录运行真实模型场景,不需要 CodeBuddy key。

验证 / Verification

  • 每个提交单独执行 go build ./... 和 go vet 均通过。
  • go test ./... -count=1:没有新增失败(见下方基线)。
  • chatbot vitest:373 passed;go test ./web/ 通过。
  • e2e 全量 local.sh:176 tests,157 pass,1 fail,16 skipped。与 origin/main 结果完全相同,唯一的失败是下面列出的既有失败。
  • Kiro 真实模型 e2e(api/40-model.test.mjs,claude-haiku-5.5):
  • seatbelt 沙箱实测:使用登录副本和共享只读运行时,31 秒完成写文件任务,并上报 credits。
  • 安全审查:独立 reviewer subagent 审查了三轮。提出的问题(hooks 持久化、HOME PATH 劫持、credits cursor 不一致、进程沙箱写宿主登录、可用性判断)均已修复,最终结论 APPROVE。

风险与已知限制 / Risks

  • KIRO_HOME 是未公开的环境变量,只在 kiro-cli 3.3.0 上验证过,升级 Kiro 时需要回归。
  • Docker 沙箱的镜像如果没有预置运行时,每次运行需要约 20 秒解压。
  • 早期运行中,Kiro 偶尔声称 submit_assistant_reply 不可用,已通过关闭 tool search 处理。之后的两轮模型 e2e 没有再出现。

既有失败 / Pre-existing failures

以下测试在本机(macOS arm64)的 origin/main 69e4bf0 上同样失败,与本 PR 无关:
These fail on this macOS arm64 machine on origin/main 69e4bf0 as well, independent of this PR:

  • deploy: TestBindCLIReinstallStopsTheRunnerNamedInServicePID, TestBindCLIUninstallSignalsOnlyTheBackgroundRunner, TestBindCLIUninstallStopsARunnerWhoseArgv0IsTheScript, TestBindCLIUninstallStopsTheRunnerNamedInServicePID
  • internal/gitwork: TestGitDiscoveryStopsBeforeParentRepository
  • internal/runtime: TestLocalWorkspaceGitDiscoveryCannotReachParent, TestProcessSandboxPathsProfilesAndCommands, TestProjectAgentGitIndexLockWaitStopsOnCancel
  • cmd/agentflow: TestSDNotifySendsReadyAndMainPID
  • internal/engine(偶发 / flaky): TestMaterializeConversationWorkspaceStopsAStalledClone
  • e2e api/30-runs: "approval gate: reject reworks upstream in the same workspace, approve completes"

CLIs on a subscription (Kiro CLI) bill in credits instead of tokens, so
their runs and chats showed no usage at all. TokenUsage gains Credits:

- the stream adapter parses usage.credits; ClaudeStream.SetCredits puts
  it on the result line for translated agent CLIs
- the engine accumulates it per session cursor like tokens and emits a
  credits metric
- chat turns, conversation workspaces and the analytics summary
  (totalCredits) add it up; the run panel shows it next to cost

Credits are never priced into CostUSD.
An MCP entry without arguments, such as the gate server, carries a nil
[]string. Stored in a map[string]any it is not nil as an interface, so
the agent CLI MCP writers emitted "args": null. Kiro CLI drops such a
server without an error, so a node never saw submit_gate_result and
waited until it timed out. mcpValueSet checks for typed nils in every
writer (default, OpenCode, DeepSeek Harness).
…ion login

Kiro CLI (kind kiro, binary kiro-cli 3.3.0) runs SOP nodes, conversation
workspaces and AI chat turns. It authenticates with a machine's
`kiro-cli login` subscription, never an API key:

- domain.AgentCLIAuthMode pins kiro to local login; runner inventory and
  SetRunnerRuntimeAuthMode keep it there
- argv: `kiro-cli chat --v3 --no-interactive --output-format stream-json`;
  SOP nodes and workspaces trust all tools, read-only use trusts only
  read/grep/glob, skill and sub-agent loading (chat adds its MCP servers)
- KIRO_HOME moves ~/.kiro (MCP, hooks, agents, sessions) into the private
  home; without a sandbox HOME stays the machine's own. Every run writes
  settings/cli.json with toolSearch.enabled false: with tool search on,
  Kiro hides MCP schemas behind tool_load and models then reported
  platform tools such as submit_assistant_reply as unavailable
- every sandbox (Docker, seatbelt, bwrap), and a platform that mounts the
  host login read-only (AGENTFLOW_KIRO_DATA_DIR), runs on a copy of only the
  login (kiro_login.go): auth_kv login rows plus the selected profile, no
  conversations or history, so no sandboxed agent writes the machine's
  kiro-cli data. The refresh token does not rotate, so the host stays
  logged in (verified with IAM Identity Center). Stale session leases are
  removed and the token refreshed before a turn
- process sandboxes share one read-only kiro-cli runtime that the machine
  unpacks once (EnsureKiroHostRuntime); Docker sandboxes use the image's
  KIRO_RUNTIME_DIR or unpack per run. An image without kiro-cli uses the
  execution machine's cached copy in AGENTFLOW_RUNTIME_CLI_DIR (runner
  default ~/.agentflow-runner/cli), otherwise installs the pinned release
  with a SHA-256 check
- the ACP stream translator maps text, reasoning, tools, sub-agent dispatch
  (Task) and skill loads (Skill), hides schema loading, and reports credits
  as the session total (usage.credits, which the engine's per-session
  cursor splits per SOP invocation) plus this invocation's share
  (usage.turn_credits)
- conversation approval: a global PreToolUse hook in KIRO_HOME/hooks; each
  conversation start clears KIRO_HOME of everything but sessions, logs,
  login state and platform-written files, so hooks or permission rules a
  workspace turn planted cannot load in a later turn. Outside Docker the
  wrapper never puts HOME on PATH and runs rm by absolute path, and every
  approval hook runs as `python3 -I`, so an executable or usercustomize.py
  planted in the persistent HOME cannot run in platform mode either
- kiro is a chat engine with no key. The engine list marks it configured
  when this server has kiro-cli and a login, or one of the user's execution
  machines is online with kiro-cli; a turn is never refused up front, since
  the machine it runs on reports a missing kiro-cli or login itself
- read-only trust list names the session MCP servers; workspace mode
  trusts all tools
- chat sums each invocation's credits (usage.turn_credits) rather than the
  session total an SOP node's cursor needs
- project roles become Kiro V3 Markdown agents in KIRO_HOME/agents (Main
  Bot's own tools in excludedTools, skills as skill:// resources); skills
  go to KIRO_HOME/skills
- native approval accepts Kiro's tool names (mcp_<server>_<tool>,
  tool_load, disclose_context, invoke_sub_agent)
- chatbot: Kiro CLI in the executor switch
- executor picker and SOP run checks list Kiro CLI; the run check reports
  the kiro-cli login instead of an API key
- the execution machine page lists the discovered kiro runtime with a
  fixed 本机登录(订阅) source, since Kiro cannot use a personal key
- Dockerfile installs kiro-cli 3.3.0 (SHA-256 checked, amd64/arm64) and
  unpacks its 415 MB runtime once into KIRO_RUNTIME_DIR=/opt/kiro-runtime
- compose.yaml mounts LOOPFORGE_KIRO_DATA_DIR read-only at /kiro-host
  (AGENTFLOW_KIRO_DATA_DIR) so the platform can copy the login
- README and docs/deployment.md describe Kiro's subscription login
local.sh with AGENTFLOW_E2E_EXECUTOR=kiro enables the real-model scenarios
on this machine's kiro-cli login, without a CodeBuddy key. 40-model takes
the assistant model from AGENTFLOW_E2E_ASSISTANT_MODEL, accepts credits
as usage and skips run evaluation, which always runs on CodeBuddy.
# Conflicts:
#	internal/runtime/agent_cli_mcp_null_test.go
#	internal/runtime/agent_cli_stream.go
@goodloris
goodloris merged commit 32ae26b into main Nov 17, 2026
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.

2 participants