进阶玩法
CLI 调用 Kition Agent
`kition run --prompt "..."` — 在终端跑 Agent,适合 CI / 脚本 / cron。
为什么要走 CLI
CLI 是 Kition 把桌面端的 Agent 能力暴露给脚本世界的入口。同一个 Vault、同一套工具、同一个 provider 配置 — 区别只是没有 UI、用 stdin / stdout / 退出码沟通。CI 里可以做代码审查、变更日志生成、issue 分流;本地可以挂 cron 跑日报、周报、备份审计。
所有 CLI 命令都尊重 Vault 配置 — 包括 Hooks、权限、provider 路由。换句话说,CLI 跑的就是“无头版的你”。
Kition CLI 不是桌面端的简化版 — 它是同一颗 Agent 内核,只换了 IO 层。这意味着你在 UI 里写的工具、调好的 system prompt、调过参数的 subagent 全都直接可用。
安装
CLI 与桌面端共用 binary — 装了 Kition 桌面端,CLI 就在 PATH 里。纯服务器场景(没装桌面端)可以单独装 CLI 包:
# macOS / Linux via the install script
curl -fsSL https://get.kition.ai/cli | sh
# Or with Homebrew
brew install kition-ai/tap/kition
# Verify
kition --version
kition doctor # checks vault, providers, MCP servers基础命令
# Run a one-shot prompt against the default vault
kition run --prompt "summarize this week's notes"
# Pick a vault explicitly
kition --vault ~/Work run --prompt "draft standup from today's commits"
# Pin a model
kition run --model claude-opus-4-7 --prompt "review staged diff"
# Pipe stdin in
git diff --staged | kition run --prompt "write a commit message for this diff"
# Resume a previous session by id
kition run --resume sess_8h2k --prompt "now publish the post"
# List recent sessions
kition sessions list --limit 10输出格式
默认输出是人类可读的 markdown。脚本里通常会想要 --json 拿到结构化结果 — 包含每一轮 message、tool call、token 用量、最终文本。
--stream 模式输出 NDJSON(每行一个 JSON event),适合长任务里实时拿进展。
kition run --json --prompt "list TODOs in src/" \
| jq -r '.events[] | select(.type=="tool_result") | .content'
kition run --stream --prompt "..." # NDJSON, one event per line
kition run --output-file out.md --prompt "..." # write final text to file
# Capture only the cost summary
kition run --json --prompt "..." | jq '.usage'退出码
- 0 — 成功
- 1 — 模型 / 网络错误(可重试)
- 2 — Hooks 拒绝(合规拦截,重试无意义)
- 3 — 工具调用失败
- 4 — 配置错误(Vault / provider / 权限)
- 5 — 上下文超长(建议拆分或换长上下文模型)
- 130 — 用户中断(SIGINT)
在 CI 里用
GitHub Actions / GitLab CI / 任意 runner 都行 — 关键是把 API key 通过 secrets 注入、把 Vault 用 actions/checkout 拉下来。下面是一个最小化的 PR 审查 workflow。
name: agent-review
on: pull_request
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: kition-ai/setup-kition@v1
with: { version: latest }
- run: |
git fetch origin ${{ github.base_ref }}
git diff origin/${{ github.base_ref }}...HEAD > /tmp/diff
kition run \
--vault ./.kition \
--prompt "Review this diff. Flag bugs only." \
--input-file /tmp/diff \
--output-file /tmp/review.md
env:
KITION_API_KEY: ${{ secrets.KITION_API_KEY }}
- uses: actions/upload-artifact@v4
with: { name: review, path: /tmp/review.md }常见陷阱
- Vault 路径必须可读写 — CI 里别忘了
actions/checkout之后 cd 进去 - Hooks 在 CI 里也会跑 — 想跳过用
--no-hooks(仅 dev 场景) --prompt太长时改用--input-file或 stdin,避免 shell 转义炸- cron 里设
KITION_NONINTERACTIVE=1,避免 ask 类工具阻塞 - 不要把 API key 写进 Vault 里 — CI secrets 或 OS keychain 才是正解
- CI 跑完记得
kition sessions prune --older-than 7d,避免历史堆积