Skip to content

feat: add Kimi Code (kimi) agent support - #247

Open
SilasWander wants to merge 1 commit into
zarazhangrui:mainfrom
SilasWander:feat/kimi-agent
Open

feat: add Kimi Code (kimi) agent support#247
SilasWander wants to merge 1 commit into
zarazhangrui:mainfrom
SilasWander:feat/kimi-agent

Conversation

@SilasWander

Copy link
Copy Markdown

Summary

Add a third agent kind, kimi, bridging Feishu/Lark chats to the local Kimi Code CLI, alongside the existing claude and codex agents.

lark-channel-bridge profile create kimi --agent kimi
lark-channel-bridge start --profile kimi

How it works

The kimi adapter follows the same process-level pattern as the claude/codex adapters:

  • Spawn: kimi -p <prompt> --output-format stream-json [--session <id>] [-m <model>]. The bridge system prompt is prepended to the prompt (the prefixBridgeSystemPrompt approach, same as codex) and passed via argv — kimi has no --append-system-prompt-file and does not read the prompt from stdin.
  • Stream translation (src/agent/kimi/stream-json.ts): kimi's JSONL schema is role-discriminated (meta / assistant / tool). Intermediate assistant text streams as text deltas using the pending-message pattern (like the codex translator); the trailing message flushes as the final answer before done. meta.session.resume_hint lines carry the session id, which is surfaced as a system event and stored for continuation.
  • Sessions: kimi rides the claude-style sessionId channel (--session <id> resumes natively). /resume lists local history from ~/.kimi-code/session_index.jsonl (new src/session/kimi-history.ts, parse-fault tolerant).
  • Permissions: kimi's -p mode is mutually exclusive with --yolo/--auto/--plan, so no permission flag is passed; the adapter ignores sandbox/permissionMode and /status displays the bridge access mode instead.

All previously two-way claude | codex branches (profile schema, capability, preflight, detection, bootstrap, registry, locks, catalog, run-flow, comments, channel, orchestrator, commands, models, migrate, CLI help, service display) are now three-way.

Verified against kimi 0.33.0 (live probes)

  • stream-json schema: system.version / assistant(tool_calls) / tool / assistant(content) / session.resume_hint
  • --session <id> continuation across runs (second turn recalled the first)
  • resume_hint capture for session persistence

Tests

  • tests/unit/agent/kimi-argv.test.ts — argv contract (prompt on -p, --session before -m, no permission flags)
  • tests/unit/agent/kimi-stream-json.test.ts — translator: tool calls, pending-message flush, dedup, terminal semantics, drift tolerance
  • tests/process/kimi-adapter.test.ts — fake-executable process test: exact argv, stdin closed immediately, full event sequence with resumed session id
  • Full suite green: 107 files / 710 tests, pnpm typecheck clean

Notes

  • Windows: prompt-on-argv may hit the same cmd.exe shim issue claude had (.cmd shim interpreting <bridge_context> redirects). Left a comment in the adapter; macOS/Linux spawn without a shell and are unaffected.
  • kimi's stream-json carries no usage/cost fields, so no usage events are emitted.

Add a third agent kind 'kimi' alongside claude and codex, bridging Feishu
chats to the local Kimi Code CLI (kimi -p --output-format stream-json).

- src/agent/kimi: adapter (argv prompt with bridge system prompt prefix,
  --session resume, no permission flags since they conflict with -p),
  argv builder, and a stream-json translator using the pending-message
  pattern (intermediate assistant text streams as text deltas, the final
  message flushes before done; session.resume_hint carries the session id)
- Three-way agent branching across profile schema, capability, preflight,
  agent detection, bootstrap, registry, locks, session catalog, run-flow,
  comments, channel, orchestrator, commands (/resume via
  ~/.kimi-code/session_index.jsonl, /status access display), models,
  migrate, CLI help, service display
- Tests: unit (argv, translator) and process-level fake-executable adapter
  tests; README/README.zh updated

Verified against kimi 0.33.0: stream-json schema, --session continuation,
and resume_hint capture all probed live.
@SilasWander

Copy link
Copy Markdown
Author

Hi @zarazhangrui — a note for review triage: I only realized after opening this that #162 (opened a month ago) also adds Kimi Code agent support, so the two PRs overlap.

This PR covers the same ground, plus a few extras:

  • /resume support via a fault-tolerant parser for ~/.kimi-code/session_index.jsonl
  • Verified against kimi 0.33.0 with live probes (stream-json schema, session resume, permission-flag exclusivity)
  • All claude | codex two-way branches updated to three-way (preflight, detection, registry, locks, catalog, commands, migrate, CLI help, etc.)

Happy to reconcile with #162 in whichever way you prefer — e.g. I can rebase on top of it, incorporate anything it does better, or close this one if you'd rather go with the earlier PR. Just let me know which direction works for you. Thanks!

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