Skip to content

feat(agents): add Kimi Code runtime support#522

Open
moonixt wants to merge 2 commits into
cline:mainfrom
moonixt:feat/kimi-code-runtime
Open

feat(agents): add Kimi Code runtime support#522
moonixt wants to merge 2 commits into
cline:mainfrom
moonixt:feat/kimi-code-runtime

Conversation

@moonixt

@moonixt moonixt commented May 30, 2026

Copy link
Copy Markdown

Summary

Adds Kimi Code as a supported Kanban runtime agent.

Changes

  • Adds kimi to the runtime agent catalog, API contract, CLI options, web settings, and onboarding UI
  • Adds Kimi Code launch adapter support for:
    • resume via --continue
    • autonomous mode via --yolo
    • plan mode via --plan
    • deferred startup prompt injection for the interactive TUI
  • Adds Kanban-managed Kimi hook config generation with a single top-level hooks = [...] array
  • Adds side panel prompt injection using a Kanban-managed Kimi --agent-file that extends the default Kimi agent
  • Respects Kimi’s official KIMI_SHARE_DIR config location, with compatibility fallback for KIMI_CODE_HOME
  • Adds tests for Kimi config generation, agent-file generation, adapter behavior, runtime detection, and lifecycle handling

Related

Related discussion: #521

Validation

  • npm run check
  • npm run build

@greptile-apps

greptile-apps Bot commented May 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds Kimi Code as a fully-supported runtime agent, wiring it into every layer of the stack: API contract, catalog, config auto-selection, CLI options, settings UI, onboarding carousel, and the PTY adapter pipeline. The two new core files (kimi-config.ts, kimi-agent-config.ts) implement Kimi-specific TOML config generation and agent-file injection for the sidebar system prompt.

  • kimi-config.ts hand-rolls a quote-aware TOML array scanner to preserve and merge user hook entries; a bug in ensureTomlArrayBodyTrailingComma places the separator comma inside any trailing # comment, producing invalid TOML.
  • kimi-agent-config.ts writes JSON.stringify output to agent.yaml; works today with YAML 1.2 parsers but the extension mismatch is worth confirming.
  • session-manager.ts / agent-session-adapters.ts follow the established deferred-startup-input and adapter patterns cleanly.

Confidence Score: 3/5

Safe to merge for adapter plumbing and catalog wiring; the TOML config generation has a defect that produces an invalid config file when a user hook carries a trailing line comment.

The comma-insertion logic in ensureTomlArrayBodyTrailingComma appends to the full raw line including any trailing comment, making the comma invisible to the TOML parser. Any Kimi user whose config has a comment on the last hook will get a malformed generated config and Kimi will fail to load its hooks. All other changes are clean.

src/terminal/kimi-config.ts — ensureTomlArrayBodyTrailingComma and findFirstTomlTableLineIndex. src/terminal/kimi-agent-config.ts — confirm the .yaml extension matches Kimi's --agent-file expectations.

Important Files Changed

Filename Overview
src/terminal/kimi-config.ts New file: TOML config generator with hand-rolled bracket/quote scanner. Bug in trailing-comma insertion corrupts configs with commented hook entries.
src/terminal/kimi-agent-config.ts New file: generates --agent-file content as JSON saved with .yaml extension.
src/terminal/agent-session-adapters.ts Adds kimiAdapter with --continue, --yolo, --plan, --config-file, and --agent-file injection.
src/terminal/session-manager.ts Adds trySendDeferredKimiStartupInput triggered on first non-empty terminal output.
src/core/agent-catalog.ts Adds kimi catalog entry and launch-supported ID.
src/core/api-contract.ts Extends runtimeAgentIdSchema to include kimi.
src/config/runtime-config.ts Adds kimi to AUTO_SELECT_AGENT_PRIORITY and normalizeAgentId allowlist.
test/runtime/terminal/kimi-config.test.ts Good coverage of TOML merging; missing test for trailing comment on last user hook.
web-ui/src/components/runtime-settings-dialog.tsx Adds kimi to SETTINGS_AGENT_ORDER.
web-ui/src/components/task-start-agent-onboarding-carousel.tsx Adds kimi to onboarding carousel with description and install link.

Sequence Diagram

sequenceDiagram
    participant SM as SessionManager
    participant Adapter as kimiAdapter
    participant KimiCfg as kimi-config.ts
    participant KimiAgent as kimi-agent-config.ts
    participant PTY as PtySession (kimi)

    SM->>Adapter: prepare(input)
    Adapter->>KimiAgent: ensureKimiKanbanAgentFile()
    KimiAgent-->>Adapter: agentFilePath
    Adapter->>KimiCfg: ensureKimiKanbanConfig()
    KimiCfg->>KimiCfg: read ~/.kimi/config.toml
    KimiCfg->>KimiCfg: strip old kanban region
    KimiCfg->>KimiCfg: extract and re-merge user hooks
    KimiCfg-->>Adapter: configPath
    Adapter-->>SM: args env deferredStartupInput
    SM->>PTY: spawn kimi with flags
    PTY-->>SM: onData first output chunk
    SM->>PTY: write bracketed-paste of task prompt
Loading
Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
src/terminal/kimi-config.ts:153-171
**Trailing TOML comment swallows separator comma**

`ensureTomlArrayBodyTrailingComma` appends `,` to the raw end of the line, including any trailing `# comment`. If a user's last hook entry has a trailing comment — e.g. `{ event = "Stop", command = "echo done", timeout = 5 } # stop hook` — the function produces `... # stop hook,` where the comma is inside the TOML comment and is therefore ignored by the parser. The next array element (the first Kanban hook) then has no preceding comma, making the generated `config.toml` invalid TOML and preventing Kimi from reading the hooks config at all.

A fix would strip (or scan past) any trailing comment before checking or appending the comma, using the same character-by-character quote-aware scan already present in `countTomlArrayBracketDelta`.

### Issue 2 of 3
src/terminal/kimi-agent-config.ts:14-28
**JSON content written to a `.yaml` file**

`buildKimiKanbanAgentFileContent` uses `JSON.stringify` to produce the file content, but the output path ends in `agent.yaml`. JSON is valid YAML 1.2, so most modern YAML parsers will accept it. However, if Kimi's `--agent-file` reader enforces YAML-specific syntax or schema-validates based on file extension, this could silently break. The accompanying test also uses `JSON.parse` directly, suggesting the intent is JSON — the file extension may be a mismatch worth confirming against Kimi's documented agent-file format.

### Issue 3 of 3
src/terminal/kimi-config.ts:110-112
**Regex may treat an indented inline-array line as a table header**

`/^\s*\[/` matches any line that starts with optional whitespace followed by `[`. An array element written on its own line (e.g. `  ["inner", "value"]` inside a top-level array key) would also match, causing `findFirstTomlTableLineIndex` to report a false table boundary and misplace the generated `hooks = [...]` block. Tightening to `^\s*\[(?!\[)\w` to require a word character after the bracket would reduce false-match risk.

Reviews (1): Last reviewed commit: "feat(agents): add Kimi Code runtime supp..." | Re-trigger Greptile

Comment thread src/terminal/kimi-config.ts
Comment thread src/terminal/kimi-agent-config.ts
Comment thread src/terminal/kimi-config.ts
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