feat: add Kimi Code (kimi) agent support - #247
Open
SilasWander wants to merge 1 commit into
Open
Conversation
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.
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:
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a third agent kind,
kimi, bridging Feishu/Lark chats to the local Kimi Code CLI, alongside the existingclaudeandcodexagents.How it works
The kimi adapter follows the same process-level pattern as the claude/codex adapters:
kimi -p <prompt> --output-format stream-json [--session <id>] [-m <model>]. The bridge system prompt is prepended to the prompt (theprefixBridgeSystemPromptapproach, same as codex) and passed via argv — kimi has no--append-system-prompt-fileand does not read the prompt from stdin.src/agent/kimi/stream-json.ts): kimi's JSONL schema isrole-discriminated (meta/assistant/tool). Intermediate assistant text streams astextdeltas using the pending-message pattern (like the codex translator); the trailing message flushes as the final answer beforedone.meta.session.resume_hintlines carry the session id, which is surfaced as asystemevent and stored for continuation.--session <id>resumes natively)./resumelists local history from~/.kimi-code/session_index.jsonl(newsrc/session/kimi-history.ts, parse-fault tolerant).-pmode is mutually exclusive with--yolo/--auto/--plan, so no permission flag is passed; the adapter ignores sandbox/permissionMode and/statusdisplays the bridge access mode instead.All previously two-way
claude | codexbranches (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)
system.version/assistant(tool_calls)/tool/assistant(content)/session.resume_hint--session <id>continuation across runs (second turn recalled the first)Tests
tests/unit/agent/kimi-argv.test.ts— argv contract (prompt on-p,--sessionbefore-m, no permission flags)tests/unit/agent/kimi-stream-json.test.ts— translator: tool calls, pending-message flush, dedup, terminal semantics, drift tolerancetests/process/kimi-adapter.test.ts— fake-executable process test: exact argv, stdin closed immediately, full event sequence with resumed session idpnpm typecheckcleanNotes
cmd.exeshim issue claude had (.cmdshim interpreting<bridge_context>redirects). Left a comment in the adapter; macOS/Linux spawn without a shell and are unaffected.