Skip to content

feat(integration): update Kimi integration for Kimi Code CLI#2979

Open
meymchen wants to merge 7 commits into
github:mainfrom
meymchen:feat/1532-kimi-code-cli-compatibility
Open

feat(integration): update Kimi integration for Kimi Code CLI#2979
meymchen wants to merge 7 commits into
github:mainfrom
meymchen:feat/1532-kimi-code-cli-compatibility

Conversation

@meymchen

Copy link
Copy Markdown

Summary

Updates the built-in Kimi integration to align with the new Kimi Code CLI layout from Moonshot AI.

Relates to #1532.

Changes

  • Skills directory moved from .kimi/skills/ to .kimi-code/skills/
  • Context file moved from KIMI.md to AGENTS.md
  • --migrate-legacy now also migrates:
    • old .kimi/skills/ installs to .kimi-code/skills/
    • dotted skill directory names (speckit.xxx) to hyphenated (speckit-xxx)
    • user content from KIMI.md to AGENTS.md
  • teardown() removes leftover Speckit-generated .kimi/skills/speckit-* directories
  • multi_install_safe set to False because Kimi now shares AGENTS.md with Codex
  • Devcontainer installer switched from pipx install kimi-cli to npm install -g @moonshot-ai/kimi-code@latest
  • Updated docs/reference/integrations.md, CHANGELOG.md, and tests

Testing

  • uv run pytest tests/integrations/test_integration_kimi.py — 43 passed
  • uv run pytest tests/integrations/ — 2218 passed
  • uv run pytest tests/ -k kimi — 57 passed

AI Assistance Disclosure

This change was developed with AI assistance for codebase exploration, implementation planning, and test generation. The final design decisions, code review, and verification were done by a human contributor.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the built-in kimi integration to match Moonshot AI’s newer Kimi Code CLI project layout, including new install locations, legacy migration behavior, and devcontainer installation instructions.

Changes:

  • Move Kimi skills install path from .kimi/skills/ to .kimi-code/skills/ and switch the context file from KIMI.md to AGENTS.md.
  • Expand --migrate-legacy to migrate old skill installs and migrate user-authored content from KIMI.mdAGENTS.md.
  • Update docs, changelog, devcontainer installer, and tests to reflect the new Kimi Code CLI integration behavior.
Show a summary per file
File Description
src/specify_cli/integrations/kimi/__init__.py Updates Kimi integration paths, adds migration + legacy cleanup logic, and changes multi-install safety.
tests/integrations/test_integration_kimi.py Updates Kimi integration expectations and adds tests for legacy skills dir + context migration and teardown cleanup.
tests/integrations/test_integration_subcommand.py Adjusts integration switch test expectations for Kimi’s new skills directory.
tests/test_presets.py Updates preset-related tests to use the new Kimi skills directory location.
tests/test_extensions.py Updates parametrized “skill agents” test cases to use .kimi-code/skills.
tests/test_agent_config_consistency.py Ensures runtime and registrar configs match the new .kimi-code/ folder layout.
docs/reference/integrations.md Documents new Kimi paths and expanded --migrate-legacy behavior.
CHANGELOG.md Adds a changelog entry describing the Kimi Code CLI integration update.
.devcontainer/post-create.sh Switches Kimi installation from pipx install kimi-cli to npm install -g @moonshot-ai/kimi-code@latest.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 9/9 changed files
  • Comments generated: 4

Comment thread src/specify_cli/integrations/kimi/__init__.py
Comment thread src/specify_cli/integrations/kimi/__init__.py
Comment thread src/specify_cli/integrations/kimi/__init__.py
Comment thread docs/reference/integrations.md Outdated
@mnriem

mnriem commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

meymchen added 2 commits June 17, 2026 00:27
Update the Kimi integration to target the new Kimi Code CLI
(MoonshotAI/kimi-code) layout:

- Change skills directory from .kimi/skills/ to .kimi-code/skills/
- Change context file from KIMI.md to AGENTS.md
- Extend --migrate-legacy to move old .kimi/skills/ installs and
  migrate KIMI.md user content to AGENTS.md
- Clean up leftover legacy .kimi/skills/ directories on teardown
- Update devcontainer installer to @moonshot-ai/kimi-code
- Update docs and tests

Relates to github#1532
- Override build_command_invocation to emit /skill:speckit-<stem>
  so dispatched commands match Kimi Code CLI's native slash syntax.
- Skip symlinked .kimi/skills directories during legacy migration
  and teardown to avoid operating on files outside the project.
- Remove kimi from the multi-install-safe integrations table.
- Add tests for command invocation and symlink safety.
@meymchen meymchen force-pushed the feat/1532-kimi-code-cli-compatibility branch from 65d3f30 to a5dc347 Compare June 16, 2026 17:05
@meymchen

Copy link
Copy Markdown
Author

@mnriem All Copilot feedback has been addressed in the latest commit (a5dc347).

Changes made:

  • Fixed Kimi skill invocation to use /skill:speckit-<stem> so it matches Kimi Code CLI's native slash command format.
  • Hardened --migrate-legacy to skip symlinked .kimi/skills directories and avoid moving content from outside the project.
  • Updated teardown legacy cleanup to skip symlinks and non-directory entries before removal.
  • Removed kimi from the multi-install-safe integrations table to align with multi_install_safe = False.

I also resolved the Copilot review threads. Let me know if anything else needs adjustment.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 9/9 changed files
  • Comments generated: 1

Comment thread src/specify_cli/integrations/kimi/__init__.py Outdated
@mnriem

mnriem commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

meymchen added 2 commits June 17, 2026 07:18
…tion

Use IntegrationBase._resolve_context_markers() when migrating legacy
KIMI.md content so that projects with customized context_markers in
.specify/extensions/agent-context/agent-context-config.yml have the
managed section stripped with the correct markers instead of the
hard-coded defaults.

Adds a test verifying custom markers are respected during
--migrate-legacy.
@meymchen

Copy link
Copy Markdown
Author

Posted on behalf of @meymchen by Kimi Code CLI agent.

Latest Copilot feedback has been addressed in commit a207446:

  • _migrate_legacy_kimi_context_file() now uses the same marker resolution logic as IntegrationBase.upsert_context_section() via self._resolve_context_markers(project_root).
  • Custom context_markers configured in .specify/extensions/agent-context/agent-context-config.yml are now respected when stripping the managed section from legacy KIMI.md during --migrate-legacy.
  • Added test_setup_migrate_legacy_uses_custom_context_markers to cover the custom-marker case.
  • All 49 Kimi integration tests pass after syncing with upstream/main.

Per project convention, I am leaving the review conversations for the reviewer/PR author to resolve.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 9/9 changed files
  • Comments generated: 2

Comment on lines +141 to +158
def _is_safe_legacy_dir(path: Path, project_root: Path) -> bool:
"""Return ``True`` when *path* is a real directory safely inside *project_root*.

Legacy migration and cleanup ``shutil.move()`` and ``shutil.rmtree()``
directories, so a symlinked ``.kimi``/``.kimi/skills`` (or one reached
through a symlinked parent) must never be followed: doing so could
relocate or delete content living outside the project tree. We reject
the path when it is itself a symlink, when it is not a directory, or
when resolving every symlink lands outside *project_root*.
"""
if path.is_symlink() or not path.is_dir():
return False
try:
resolved = path.resolve()
root = project_root.resolve()
except OSError:
return False
return resolved == root or root in resolved.parents
Comment on lines +322 to +333
target_path = project_root / "AGENTS.md"
if target_path.is_file():
existing = target_path.read_text(encoding="utf-8-sig")
existing = existing.replace("\r\n", "\n").replace("\r", "\n")
if not existing.endswith("\n"):
existing += "\n"
new_content = existing + "\n" + user_content + "\n"
else:
new_content = user_content + "\n"

target_path.parent.mkdir(parents=True, exist_ok=True)
target_path.write_bytes(new_content.encode("utf-8"))

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback. If not applicable, please explain why

@meymchen

Copy link
Copy Markdown
Author

@mnriem Posted on behalf of @meymchen by Kimi Code CLI agent.

Latest Copilot feedback has been addressed in commit 2d66414:

  • Tightened _is_safe_legacy_dir() to reject any symlink in path components between project_root and the legacy dir, preventing migration/teardown from operating on the wrong in-tree directory (e.g., .kimi -> . making .kimi/skills resolve to ./skills).
  • Added symlink guards to _migrate_legacy_kimi_context_file() so a symlinked KIMI.md is never followed and a symlinked AGENTS.md is never written through, blocking arbitrary file reads/writes outside the project root.
  • Added regression tests for symlinked legacy parent dirs, symlinked AGENTS.md writes, and symlinked KIMI.md reads.
  • All 53 Kimi integration tests pass.

Per project convention, I am leaving the review conversations for the reviewer/PR author to resolve.

@meymchen meymchen requested a review from mnriem June 17, 2026 16:08
@mnriem

mnriem commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Not seeing the latest commit?

@meymchen

Copy link
Copy Markdown
Author

Not seeing the latest commit?

Sorry about the mistake, recommitted.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 9/9 changed files
  • Comments generated: 7

Comment on lines 6 to +8
Includes legacy migration logic for projects initialised before Kimi
moved from dotted skill directories (``speckit.xxx``) to hyphenated
(``speckit-xxx``).
Code CLI adopted the ``.kimi-code/`` directory, as well as for the
older dotted skill directory naming (``speckit.xxx`` → ``speckit-xxx``).
Comment on lines +205 to 208
if legacy_dir.is_symlink() or not legacy_dir.is_dir():
continue
if not (legacy_dir / "SKILL.md").exists():
continue
Comment on lines 220 to 224
if not target_dir.exists():
target_dir.parent.mkdir(parents=True, exist_ok=True)
shutil.move(str(legacy_dir), str(target_dir))
migrated_count += 1
continue
Comment on lines +267 to +269
skill_file = skill_dir / "SKILL.md"
if not skill_file.is_file():
return False
Comment thread tests/test_presets.py
skills_dir = project_dir / ".kimi-code" / "skills"
self._create_skill(skills_dir, "speckit.specify", body="untouched")

(project_dir / ".kimi" / "commands").mkdir(parents=True, exist_ok=True)
Comment thread tests/test_presets.py
skills_dir = project_dir / ".kimi-code" / "skills"
self._create_skill(skills_dir, "speckit-specify", body="untouched")

(project_dir / ".kimi" / "commands").mkdir(parents=True, exist_ok=True)
Comment thread tests/test_presets.py
skills_dir = project_dir / ".kimi" / "skills"
skills_dir = project_dir / ".kimi-code" / "skills"
self._create_skill(skills_dir, "speckit-specify", body="untouched")
(project_dir / ".kimi" / "commands").mkdir(parents=True, exist_ok=True)
@mnriem

mnriem commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

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.

3 participants