feat: add Kimi Code (Moonshot AI) preset and hook installer#1298
Open
Krishnachaitanyakc wants to merge 1 commit into
Open
feat: add Kimi Code (Moonshot AI) preset and hook installer#1298Krishnachaitanyakc wants to merge 1 commit into
Krishnachaitanyakc wants to merge 1 commit into
Conversation
Adds first-class support for kimi-cli, Moonshot AI's Python coding assistant, against the new agent-preset framework that landed on main in May 2026. Replaces the closed PR git-ai-project#751, which was scoped to the old per-preset arms in git_ai_handlers and is structurally incompatible with the rewritten orchestrator. Preset (`presets/kimi_code.rs`): - Pure parser implementing `AgentPreset::parse`. Handles `PreToolUse` / `PostToolUse` for `WriteFile`, `StrReplaceFile`, and `Shell`. Accepts the alias keys (`tool_use_id` / `toolUseId`) in addition to kimi-cli's native `tool_call_id`. - Strict event handling: lifecycle events (`SessionStart`, `Stop`, `SubagentStart`, `PostToolUseFailure`, etc.) return `PresetError` rather than fabricating a phantom file-edit checkpoint. - `transcript_source: None` for now. kimi-cli stores sessions on disk under `$KIMI_SHARE_DIR/sessions/...` but the hook payload does not surface that path; a dedicated reader can land in a follow-up. Installer (`mdm/agents/kimi_code.rs`): - Writes `[[hooks]]` entries into `~/.kimi/config.toml` per the upstream hook documentation. No `matcher` field; the preset itself filters tool events. - Idempotent — repeat install with the desired command is a no-op. - Token-based ownership matching (`is_git_ai_kimi_command`) so that a hypothetical sibling preset like `kimi-code-pro` is never misidentified or clobbered. - Uninstall removes only kimi-code entries; user-defined hooks survive. - 16 unit tests covering fresh install, idempotency, dedup with same and differing paths, dry-run, parent-dir creation, mixed uninstall, missing-config and corrupt-TOML tolerance. Tool classification (`bash_tool.rs`): - New `Agent::KimiCode` variant. `WriteFile`/`StrReplaceFile` map to `FileEdit`, `Shell` maps to `Bash`, all else `Skip`. Wiring: - `presets/mod.rs::resolve_preset` accepts `kimi-code`. - `mdm/agents/mod.rs::get_all_installers` includes `KimiCodeInstaller`. - `git_ai_handlers` help text lists `kimi-code`. - `tests/integration/repos/test_file.rs::AI_AUTHOR_NAMES` and `test_repo.rs::is_known_checkpoint_preset` learn `kimi-code`. Tests: 14 preset unit tests, 16 installer unit tests, 11 integration tests including 3 full E2E flows (`WriteFile` attribution, pre+post isolation of human vs AI lines, `StrReplaceFile` attribution). `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps`, and the full lib test suite (1467 tests) all pass locally. Closes git-ai-project#639
6b155a6 to
e844942
Compare
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
Adds first-class support for kimi-cli, Moonshot AI's Python coding assistant, against the new agent-preset framework that landed on main in May 2026. Replaces the closed PR #751, which was scoped to the old per-preset arms and is structurally incompatible with the rewritten orchestrator.
Closes #639. Continues the work from #751 per @svarlamov's request to rebase on the simpler agent preset structure.
Preset (
presets/kimi_code.rs)AgentPreset::parse. HandlesPreToolUse/PostToolUseforWriteFile,StrReplaceFile, andShell.SessionStart,Stop,SubagentStart,PostToolUseFailure, etc.) returnPresetErrorrather than fabricating a phantom file-edit checkpoint.transcript_source: Nonefor now — kimi-cli stores sessions on disk under$KIMI_SHARE_DIR/sessions/...but the hook payload doesn't surface that path. A dedicated reader can land in a follow-up.agent_id.modeldefaults to"unknown"because kimi-cli does not surface the active model in hook payloads.Installer (
mdm/agents/kimi_code.rs)[[hooks]]entries into~/.kimi/config.tomlper the upstream hook documentation. Nomatcherfield — the preset itself filters tool events.is_git_ai_kimi_command): a hypothetical sibling preset likekimi-code-prois never misidentified.hookskey is removed entirely so the file isn't left with a danglinghooks = [].Tool classification (
bash_tool.rs)Agent::KimiCodevariant:WriteFile/StrReplaceFile→FileEdit,Shell→Bash, all else →Skip.Wiring
presets/mod.rs::resolve_presetacceptskimi-code.mdm/agents/mod.rs::get_all_installersincludesKimiCodeInstaller.git_ai_handlershelp text listskimi-code.tests/integration/repos/test_file.rs::AI_AUTHOR_NAMESandtest_repo.rs::is_known_checkpoint_presetlearnkimi-code.Test plan
cargo fmt --checkcleancargo clippy --all-targets -- -D warningsclean (no#[allow(...)]annotations added)RUSTDOCFLAGS="-D warnings" cargo doc --no-depscleanpresets::kimi_code::tests::*) — pre/post for WriteFile/StrReplaceFile/Shell, lifecycle event rejection, unsupported tool rejection, missing field errors, invalid JSON, alias key acceptance, tolerance for extratool_outputfieldmdm::agents::kimi_code::tests::*) — fresh install (s1), idempotency (s2), preserves unrelated hooks (s3), updates outdated path (s4), dedup with same and differing paths (s5/s5b), no matcher (s6), dry-run (s7), creates parent dir (s8); uninstall variants (u1-u5); invalid TOML/wrong type errors (e1-e3); ownership-token tests (substring lookalikes never match)tests/integration/kimi_code.rs) — preset routing for all 4 event types, full lifecycle/tool rejection sweep (11 events × 6 tools), 3 E2E flows via realgit-ai checkpoint kimi-codesubprocess assertingassert_lines_and_blameand session metadata