Add support for Kimi Code (Moonshot AI)#751
Conversation
|
@svarlamov can you review this? |
|
Sorry for the late reply @Krishnachaitanyakc! This looks good, but is it possible to get transcripts for Kimi Code too? |
Parse optional transcript field from hook_input JSON on PostToolUse events, enabling Kimi Code to pass conversation history using the standard AiTranscript format. Backward-compatible — omitting the field defaults to None as before. Addresses review feedback on git-ai-project#751.
|
@Krishnachaitanyakc Thanks for the PR! Was just reviewing -- does Kimi have hooks? The PR seems to be missing the logic to actually install hooks for Kimi (ref the logic under mdm/) |
|
@svarlamov Good catch, sorry I missed the hook installer — should've been part of the original PR. Just pushed the KimiCodeInstaller that writes HOOK.md + shell scripts to ~/.config/agents/hooks/. |
|
Ty! And did you have some time to test locally/verify the kimi extension? I'm trying to get it setup on my end locally as well. Btw @Krishnachaitanyakc are you in our Discord? https://discord.gg/qMACzkVuN |
|
@svarlamov yes, also added a comprehensive integration test suite covering preset parsing, error handling, and E2E checkpoint-commit-attribution |
- Add email detection for noreply@moonshot.cn and noreply@kimi.ai - Add username detection for kimi-code[bot] - Add KimiCodePreset checkpoint preset with standard hook input format - Wire up "kimi-code" subcommand in checkpoint handler and help text
Parse optional transcript field from hook_input JSON on PostToolUse events, enabling Kimi Code to pass conversation history using the standard AiTranscript format. Backward-compatible — omitting the field defaults to None as before. Addresses review feedback on git-ai-project#751.
Cover preset parsing (AI/human checkpoint routing, model extraction, file path handling, inline transcript), error handling (missing fields, invalid JSON), and end-to-end checkpoint-commit-attribution flow.
- Remove stale tests/kimi_code.rs (moved to tests/integration/ but old file remained tracked, causing duplicate module errors) - Apply rustfmt to tests/integration/kimi_code.rs
Register kimi-code in AI_AUTHOR_NAMES and is_known_checkpoint_preset so E2E tests correctly identify Kimi Code as an AI agent.
da05c9b to
d35f750
Compare
The notes_sync_push_propagates_authorship_notes_to_remote test failed intermittently on windows-latest (wrapper mode). This is a known flaky test unrelated to the Kimi Code changes — the same test passes on main and on PR git-ai-project#851 which has an identical base.
Resolve conflict in git_ai_handlers.rs: include both KimiCode and Firebender presets added on each branch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove unconditional println! that printed the full serialized TOML config to stdout on every hook installation. No other agent installer has debug output in its install_hooks method.
test_kimi_code_session_transcript_from_disk sets process-global KIMI_SHARE_DIR which can race with parallel tests. Adding #[serial] prevents flaky test failures.
- Move test_kimi_code_session_transcript_from_disk to reuse_tests_in_worktree_with_attrs! with #[serial] so the generated _in_worktree variant is also serialized - Fix clippy::collapsible_if in agent_presets.rs - Apply cargo fmt formatting
|
Hey @Krishnachaitanyakc -- the preset rewrite landed on main!! 🥳 I'm going to close this and ask that if you do have time, a new PR for the same feature, but based on the new agent preset structure (which is way simpler, wooohooo!!!!) |
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
Summary
Closes #639
noreply@moonshot.cn,noreply@kimi.ai) and GitHub username (kimi-code[bot])KimiCodePresetcheckpoint preset accepting standard hook input (session_id,cwd,model,hook_event_name,tool_input)kimi-codesubcommand in the checkpoint handler and update help textTest plan
agent_detectiontests pass (20/20)