feat(kimi): modernize Kimi adapter for Kimi Code CLI v0.18.0+#939
feat(kimi): modernize Kimi adapter for Kimi Code CLI v0.18.0+#939Jucomu3P wants to merge 8 commits into
Conversation
Adds a Renovate-tracked pinned version for the new Kimi Code CLI (TypeScript/npm-based), replacing the legacy Python/uv-based kimi-cli install path.
Replaces the legacy uv/Python-based install path with the official npm-based distribution for Kimi Code CLI v0.18.0+. Adds Kimi to the npm-based agent set and removes the uv-specific preflight check.
Adds ~/.kimi-code/skills and .kimi-code/skills to the skill discovery paths so that repo-local and user-level Kimi Code skills are indexed by the skill registry.
Updates the Kimi adapter to target the new TypeScript-based Kimi Code CLI instead of the legacy Python/uv-based kimi-cli: - Config dir changed from ~/.kimi to ~/.kimi-code - System prompt changed from KIMI.md (Jinja) to AGENTS.md (FileReplace) - Skills dir changed to ~/.kimi-code/skills - MCP config path changed to ~/.kimi-code/mcp.json - findKimi now searches npm global paths on Windows - BootstrapTemplate only writes AGENTS.md if missing (preserves user content) - PostInstallMessage updated with new paths
Adds a minimal AGENTS.md skeleton that uses the same marker-based section injection pattern as other StrategyFileReplace agents. This preserves user-authored content while allowing Gentle AI to manage persona, output style, engram, SDD, TDD, and trigger sections.
Adapts the Claude Code engram protocol to the Kimi Code CLI context. This asset is injected into AGENTS.md via the Engram component and provides the mandatory memory persistence protocol for Kimi users.
The markers must match the format expected by filemerge.InjectMarkdownSection:
<!-- gentle-ai:{section} --> and <!-- /gentle-ai:{section} -->.
An empty/minimal base allows the persona injector to write the full persona content on first install, and subsequent injectors (SDD, Engram) to append their managed sections with proper markers. This avoids the preserveManagedSections split issue where the base template headers would be preserved before the persona content.
📝 WalkthroughWalkthroughThe Kimi agent integration is migrated from the legacy Python/uv-based ChangesKimi uv→npm migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/agents/kimi/adapter.go`:
- Around line 285-292: The os.Stat call checking for skeletonPath only handles
the os.IsNotExist case and silently ignores other error types like permission or
I/O failures. Modify the error handling logic to first check if err is not nil,
then verify if it is specifically os.IsNotExist before proceeding with the file
creation. If the error is any other type (permission denied, I/O error, etc.),
return it as an error instead of silently continuing execution.
In `@internal/assets/kimi/engram-protocol.md`:
- Line 1: The markdown file has two structural issues to fix: First, change the
level-2 heading at the start of the document (## Engram Persistent Memory —
Protocol) to a level-1 heading using a single hash mark (#) instead of double
hash marks. Second, ensure all section headings at lines 74, 77, 80, 83, 86, and
89 have blank lines before and after them to comply with markdownlint
requirements. This means adding an empty line above and below each of these
headings to properly separate them from surrounding content.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8fbb18ce-c5ee-4884-88bc-6b697c7852cf
📒 Files selected for processing (6)
internal/agents/kimi/adapter.gointernal/assets/kimi/AGENTS.mdinternal/assets/kimi/engram-protocol.mdinternal/installcmd/resolver.gointernal/skillregistry/registry.gointernal/versions/versions.go
| // We write the skeleton only if AGENTS.md does not already exist so we | ||
| // do not clobber user-authored instructions on a re-install. | ||
| if _, err := os.Stat(skeletonPath); os.IsNotExist(err) { | ||
| content := assets.MustRead("kimi/AGENTS.md") | ||
| if _, err := filemerge.WriteFileAtomic(skeletonPath, []byte(content), 0o644); err != nil { | ||
| return fmt.Errorf("write AGENTS.md skeleton: %w", err) | ||
| } | ||
| } |
There was a problem hiding this comment.
Propagate non-NotExist stat failures in bootstrap.
At Line 287, non-ENOENT os.Stat errors are ignored, so permission/I/O failures can silently skip AGENTS.md creation and continue as “success.”
Suggested fix
- if _, err := os.Stat(skeletonPath); os.IsNotExist(err) {
- content := assets.MustRead("kimi/AGENTS.md")
- if _, err := filemerge.WriteFileAtomic(skeletonPath, []byte(content), 0o644); err != nil {
- return fmt.Errorf("write AGENTS.md skeleton: %w", err)
- }
- }
+ if _, err := os.Stat(skeletonPath); err != nil {
+ if !os.IsNotExist(err) {
+ return fmt.Errorf("stat AGENTS.md skeleton path: %w", err)
+ }
+ content := assets.MustRead("kimi/AGENTS.md")
+ if _, err := filemerge.WriteFileAtomic(skeletonPath, []byte(content), 0o644); err != nil {
+ return fmt.Errorf("write AGENTS.md skeleton: %w", err)
+ }
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // We write the skeleton only if AGENTS.md does not already exist so we | |
| // do not clobber user-authored instructions on a re-install. | |
| if _, err := os.Stat(skeletonPath); os.IsNotExist(err) { | |
| content := assets.MustRead("kimi/AGENTS.md") | |
| if _, err := filemerge.WriteFileAtomic(skeletonPath, []byte(content), 0o644); err != nil { | |
| return fmt.Errorf("write AGENTS.md skeleton: %w", err) | |
| } | |
| } | |
| // We write the skeleton only if AGENTS.md does not already exist so we | |
| // do not clobber user-authored instructions on a re-install. | |
| if _, err := os.Stat(skeletonPath); err != nil { | |
| if !os.IsNotExist(err) { | |
| return fmt.Errorf("stat AGENTS.md skeleton path: %w", err) | |
| } | |
| content := assets.MustRead("kimi/AGENTS.md") | |
| if _, err := filemerge.WriteFileAtomic(skeletonPath, []byte(content), 0o644); err != nil { | |
| return fmt.Errorf("write AGENTS.md skeleton: %w", err) | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/agents/kimi/adapter.go` around lines 285 - 292, The os.Stat call
checking for skeletonPath only handles the os.IsNotExist case and silently
ignores other error types like permission or I/O failures. Modify the error
handling logic to first check if err is not nil, then verify if it is
specifically os.IsNotExist before proceeding with the file creation. If the
error is any other type (permission denied, I/O error, etc.), return it as an
error instead of silently continuing execution.
| @@ -0,0 +1,101 @@ | |||
| ## Engram Persistent Memory — Protocol | |||
There was a problem hiding this comment.
Resolve markdown heading-structure lint warnings.
Line 1 starts with a level-2 heading, and Lines 74/77/80/83/86/89 are missing the required surrounding blank lines per markdownlint hints.
Also applies to: 74-90
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 1-1: First line in a file should be a top-level heading
(MD041, first-line-heading, first-line-h1)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/assets/kimi/engram-protocol.md` at line 1, The markdown file has two
structural issues to fix: First, change the level-2 heading at the start of the
document (## Engram Persistent Memory — Protocol) to a level-1 heading using a
single hash mark (#) instead of double hash marks. Second, ensure all section
headings at lines 74, 77, 80, 83, 86, and 89 have blank lines before and after
them to comply with markdownlint requirements. This means adding an empty line
above and below each of these headings to properly separate them from
surrounding content.
Source: Linters/SAST tools
Alan-TheGentleman
left a comment
There was a problem hiding this comment.
Thanks for pushing the Kimi migration forward. This is the right area to modernize, but this PR is not safe to merge yet.
Blocking issues:
- The install command uses
--ignore-scripts, but the upstream package has apostinstallscript that appears responsible for moving legacy Pythonkimishims out of the way. Disabling it can produce a successful install that still runs the old CLI. @moonshot-ai/kimi-code@0.18.0requires Node>=22.19.0, but the preflight only checks for npm. Users with older Node can pass preflight and get a broken install.- The Kimi tests and related preflight expectations are not migrated yet. The adapter still needs coverage for
.kimi-code,AGENTS.md,StrategyFileReplace, npm install behavior, and SDD injection expectations. - This is a breaking migration, so docs/migration guidance cannot be follow-up work.
Please decide the legacy-shim strategy, add Node version preflight, migrate the tests, and include the docs/migration update before the next review.
Summary
This PR updates the Kimi adapter in
gentle-aito target the modern Kimi Code CLI (@moonshot-ai/kimi-code, TypeScript/npm-based, v0.18.0+) instead of the legacy Python/uv-basedkimi-cli.Key Changes
1. Version Pinning (
internal/versions/versions.go)Kimi = "0.18.0"constant for@moonshot-ai/kimi-code.2. Install Resolver (
internal/installcmd/resolver.go)uv tool install --python 3.13 kimi-cliwithnpm install -g --ignore-scripts @moonshot-ai/kimi-code@0.18.0.AgentKimitonpmBasedAgentsso Node.js/npm preflight checks apply.uv-specific preflight validation.3. Config Paths (
internal/agents/kimi/adapter.go)GlobalConfigDir:~/.kimi→~/.kimi-codeSystemPromptFile:~/.kimi/KIMI.md→~/.kimi-code/AGENTS.mdSystemPromptStrategy:StrategyJinjaModules→StrategyFileReplaceSkillsDir:~/.config/agents/skills→~/.kimi-code/skillsMCPConfigPath:~/.kimi/mcp.json→~/.kimi-code/mcp.jsonSubAgentsDir:~/.kimi/agents→~/.kimi-code/agentsfindKimi: adds npm global paths on Windows (AppData/Roaming/npm/kimi.cmd)BootstrapTemplate: only writesAGENTS.mdif missing (preserves user content)PostInstallMessage: updated with new paths4. Skill Registry (
internal/skillregistry/registry.go)~/.kimi-code/skillstoUserSkillDirs()..kimi-code/skillstoProjectSkillDirs().5. New Assets (
internal/assets/kimi/)AGENTS.md: Minimal base template forStrategyFileReplaceinjection.engram-protocol.md: Adapted Engram persistent memory protocol for Kimi users.Backwards Compatibility
The legacy Python
kimi-cliis no longer supported. Users on the old version should runkimi migrate(built into the new CLI) to port their config and sessions to~/.kimi-codebefore installing Gentle AI.Testing
internal/agents/kimi/adapter_test.goshould be updated to reflect new paths.StrategyFileReplacescenarios.gentle-ai install kimion a clean machine with npm.Checklist
docs/agents.md) (follow-up needed)Summary by CodeRabbit
New Features
Refactor
.kimito.kimi-codeKIMI.mdtoAGENTS.md