Skip to content

Commit 4697252

Browse files
committed
feat(integration): update Kimi integration for Kimi Code CLI
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
1 parent 7a37102 commit 4697252

9 files changed

Lines changed: 340 additions & 43 deletions

File tree

‎.devcontainer/post-create.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ fi
8888
run_command "$kiro_binary --help > /dev/null"
8989
echo "✅ Done"
9090

91-
echo -e "\n🤖 Installing Kimi CLI..."
91+
echo -e "\n🤖 Installing Kimi Code CLI..."
9292
# https://code.kimi.com
93-
run_command "pipx install kimi-cli"
93+
run_command "npm install -g @moonshot-ai/kimi-code@latest"
9494
echo "✅ Done"
9595

9696
echo -e "\n🤖 Installing CodeBuddy CLI..."

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
### Changed
2323

24+
- feat(integration): update Kimi integration for Kimi Code CLI (`@moonshot-ai/kimi-code`): skills path moved from `.kimi/skills/` to `.kimi-code/skills/`, context file moved from `KIMI.md` to `AGENTS.md`; `--migrate-legacy` migrates old installs and `teardown()` cleans up leftover legacy directories
2425
- Add Research Harness extension to community catalog (#2935)
2526
- Add Coding Standards Drift Control extension to community catalog (#2934)
2627
- Add Spec Trace extension to community catalog (#2527)

‎docs/reference/integrations.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The Specify CLI supports a wide range of AI coding agents. When you run `specify
2424
| [iFlow CLI](https://docs.iflow.cn/en/cli/quickstart) | `iflow` | |
2525
| [Junie](https://junie.jetbrains.com/) | `junie` | |
2626
| [Kilo Code](https://github.com/Kilo-Org/kilocode) | `kilocode` | |
27-
| [Kimi Code](https://code.kimi.com/) | `kimi` | Skills-based integration; supports `--migrate-legacy` for dotted→hyphenated directory migration |
27+
| [Kimi Code](https://code.kimi.com/) | `kimi` | Skills-based integration; installs into `.kimi-code/skills/`. `--migrate-legacy` moves old `.kimi/skills/` installs and `KIMI.md` context to the new paths |
2828
| [Kiro CLI](https://kiro.dev/docs/cli/) | `kiro-cli` | Kiro CLI does not substitute `$ARGUMENTS` in file-based prompts, so Spec Kit ships a prose fallback at render time (see [Manage prompts](https://kiro.dev/docs/cli/chat/manage-prompts/) and issue [#1926](https://github.com/github/spec-kit/issues/1926)). Alias: `--integration kiro` |
2929
| [Lingma](https://lingma.aliyun.com/) | `lingma` | Skills-based integration; skills are installed automatically |
3030
| [Mistral Vibe](https://github.com/mistralai/mistral-vibe) | `vibe` | |
@@ -154,7 +154,7 @@ Some integrations accept additional options via `--integration-options`:
154154
| Integration | Option | Description |
155155
| ----------- | ------------------- | -------------------------------------------------------------- |
156156
| `generic` | `--commands-dir` | Required. Directory for command files |
157-
| `kimi` | `--migrate-legacy` | Migrate legacy dotted skill directories to hyphenated format |
157+
| `kimi` | `--migrate-legacy` | Migrate legacy `.kimi/skills/` installs and `KIMI.md` to `.kimi-code/skills/` and `AGENTS.md`, including dotted→hyphenated directory names |
158158

159159
Example:
160160

@@ -187,7 +187,7 @@ The currently declared multi-install safe integrations are:
187187
| `iflow` | `.iflow/commands`, `IFLOW.md` |
188188
| `junie` | `.junie/commands`, `.junie/AGENTS.md` |
189189
| `kilocode` | `.kilocode/workflows`, `.kilocode/rules/specify-rules.md` |
190-
| `kimi` | `.kimi/skills`, `KIMI.md` |
190+
| `kimi` | `.kimi-code/skills`, `AGENTS.md` |
191191
| `qodercli` | `.qoder/commands`, `QODER.md` |
192192
| `qwen` | `.qwen/commands`, `QWEN.md` |
193193
| `roo` | `.roo/commands`, `.roo/rules/specify-rules.md` |

‎src/specify_cli/integrations/kimi/__init__.py‎

Lines changed: 200 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Kimi Code integration — skills-based agent (Moonshot AI).
22
3-
Kimi uses the ``.kimi/skills/speckit-<name>/SKILL.md`` layout with
3+
Kimi uses the ``.kimi-code/skills/speckit-<name>/SKILL.md`` layout with
44
``/skill:speckit-<name>`` invocation syntax.
55
66
Includes legacy migration logic for projects initialised before Kimi
7-
moved from dotted skill directories (``speckit.xxx``) to hyphenated
8-
(``speckit-xxx``).
7+
Code CLI adopted the ``.kimi-code/`` directory, as well as for the
8+
older dotted skill directory naming (``speckit.xxx`` → ``speckit-xxx``).
99
"""
1010

1111
from __future__ import annotations
@@ -14,7 +14,7 @@
1414
from pathlib import Path
1515
from typing import Any
1616

17-
from ..base import IntegrationOption, SkillsIntegration
17+
from ..base import IntegrationBase, IntegrationOption, SkillsIntegration
1818
from ..manifest import IntegrationManifest
1919

2020

@@ -24,19 +24,19 @@ class KimiIntegration(SkillsIntegration):
2424
key = "kimi"
2525
config = {
2626
"name": "Kimi Code",
27-
"folder": ".kimi/",
27+
"folder": ".kimi-code/",
2828
"commands_subdir": "skills",
2929
"install_url": "https://code.kimi.com/",
3030
"requires_cli": True,
3131
}
3232
registrar_config = {
33-
"dir": ".kimi/skills",
33+
"dir": ".kimi-code/skills",
3434
"format": "markdown",
3535
"args": "$ARGUMENTS",
3636
"extension": "/SKILL.md",
3737
}
38-
context_file = "KIMI.md"
39-
multi_install_safe = True
38+
context_file = "AGENTS.md"
39+
multi_install_safe = False
4040

4141
@classmethod
4242
def options(cls) -> list[IntegrationOption]:
@@ -51,7 +51,10 @@ def options(cls) -> list[IntegrationOption]:
5151
"--migrate-legacy",
5252
is_flag=True,
5353
default=False,
54-
help="Migrate legacy dotted skill dirs (speckit.xxx → speckit-xxx)",
54+
help=(
55+
"Migrate legacy Kimi installations: "
56+
".kimi/skills/ → .kimi-code/skills/ and speckit.xxx → speckit-xxx"
57+
),
5558
),
5659
]
5760

@@ -62,47 +65,98 @@ def setup(
6265
parsed_options: dict[str, Any] | None = None,
6366
**opts: Any,
6467
) -> list[Path]:
65-
"""Install skills with optional legacy dotted-name migration."""
68+
"""Install skills with optional legacy migration."""
6669
parsed_options = parsed_options or {}
6770

68-
# Run base setup first so hyphenated targets (speckit-*) exist,
69-
# then migrate/clean legacy dotted dirs without risking user content loss.
71+
# Run base setup first so new-path targets (speckit-*) exist,
72+
# then migrate/clean legacy dirs without risking user content loss.
7073
created = super().setup(
7174
project_root, manifest, parsed_options=parsed_options, **opts
7275
)
7376

7477
if parsed_options.get("migrate_legacy", False):
75-
skills_dir = self.skills_dest(project_root)
76-
if skills_dir.is_dir():
77-
_migrate_legacy_kimi_dotted_skills(skills_dir)
78+
new_skills_dir = self.skills_dest(project_root)
79+
old_skills_dir = project_root / ".kimi" / "skills"
80+
if old_skills_dir.is_dir():
81+
_migrate_legacy_kimi_skills_dir(old_skills_dir, new_skills_dir)
82+
_migrate_legacy_kimi_context_file(project_root)
7883

7984
return created
8085

86+
def teardown(
87+
self,
88+
project_root: Path,
89+
manifest: IntegrationManifest,
90+
*,
91+
force: bool = False,
92+
) -> tuple[list[Path], list[Path]]:
93+
"""Uninstall Kimi skills and remove leftover legacy directories."""
94+
removed, skipped = super().teardown(project_root, manifest, force=force)
8195

82-
def _migrate_legacy_kimi_dotted_skills(skills_dir: Path) -> tuple[int, int]:
83-
"""Migrate legacy Kimi dotted skill dirs (speckit.xxx) to hyphenated format.
96+
old_skills_dir = project_root / ".kimi" / "skills"
97+
if old_skills_dir.is_dir():
98+
legacy_dirs = sorted(
99+
[*old_skills_dir.glob("speckit-*"), *old_skills_dir.glob("speckit.*")]
100+
)
101+
for legacy_dir in legacy_dirs:
102+
if not legacy_dir.is_dir():
103+
continue
104+
if _is_speckit_generated_skill(legacy_dir):
105+
try:
106+
shutil.rmtree(legacy_dir)
107+
removed.append(legacy_dir)
108+
except OSError:
109+
skipped.append(legacy_dir)
110+
111+
try:
112+
old_skills_dir.rmdir()
113+
except OSError:
114+
pass
115+
116+
return removed, skipped
117+
118+
119+
def _migrate_legacy_kimi_skills_dir(
120+
old_skills_dir: Path, new_skills_dir: Path
121+
) -> tuple[int, int]:
122+
"""Migrate skills from the legacy ``.kimi/skills/`` directory to ``.kimi-code/skills/``.
123+
124+
Handles both hyphenated (``speckit-xxx``) and dotted (``speckit.xxx``)
125+
legacy directory names. If a target already exists, the legacy dir is
126+
only removed when its ``SKILL.md`` is byte-identical and no extra user
127+
files are present.
84128
85129
Returns ``(migrated_count, removed_count)``.
86130
"""
87-
if not skills_dir.is_dir():
131+
if not old_skills_dir.is_dir():
88132
return (0, 0)
89133

90134
migrated_count = 0
91135
removed_count = 0
92136

93-
for legacy_dir in sorted(skills_dir.glob("speckit.*")):
137+
# Process hyphenated dirs first, then dotted dirs.
138+
legacy_dirs = sorted(old_skills_dir.glob("speckit-*")) + sorted(
139+
old_skills_dir.glob("speckit.*")
140+
)
141+
142+
for legacy_dir in legacy_dirs:
94143
if not legacy_dir.is_dir():
95144
continue
96145
if not (legacy_dir / "SKILL.md").exists():
97146
continue
98147

99-
suffix = legacy_dir.name[len("speckit."):]
100-
if not suffix:
148+
target_name = _legacy_to_target_name(legacy_dir.name)
149+
if not target_name:
101150
continue
102151

103-
target_dir = skills_dir / f"speckit-{suffix.replace('.', '-')}"
152+
target_dir = new_skills_dir / target_name
153+
154+
# Skip if the legacy dir is already the target dir (same-directory call).
155+
if legacy_dir.resolve() == target_dir.resolve():
156+
continue
104157

105158
if not target_dir.exists():
159+
target_dir.parent.mkdir(parents=True, exist_ok=True)
106160
shutil.move(str(legacy_dir), str(target_dir))
107161
migrated_count += 1
108162
continue
@@ -122,4 +176,128 @@ def _migrate_legacy_kimi_dotted_skills(skills_dir: Path) -> tuple[int, int]:
122176
except OSError:
123177
pass
124178

179+
# Remove the legacy skills directory if it is now empty.
180+
try:
181+
old_skills_dir.rmdir()
182+
except OSError:
183+
pass
184+
125185
return (migrated_count, removed_count)
186+
187+
188+
def _legacy_to_target_name(legacy_name: str) -> str:
189+
"""Convert a legacy skill directory name to the modern hyphenated form."""
190+
if legacy_name.startswith("speckit-"):
191+
return legacy_name
192+
if legacy_name.startswith("speckit."):
193+
suffix = legacy_name[len("speckit."):]
194+
if suffix:
195+
return f"speckit-{suffix.replace('.', '-')}"
196+
return ""
197+
198+
199+
def _is_speckit_generated_skill(skill_dir: Path) -> bool:
200+
"""Return True when *skill_dir* contains a Speckit-generated SKILL.md.
201+
202+
Uses the ``metadata.author`` and ``metadata.source`` fields written by
203+
``SkillsIntegration.setup()`` to avoid deleting user-authored skills.
204+
"""
205+
skill_file = skill_dir / "SKILL.md"
206+
if not skill_file.is_file():
207+
return False
208+
209+
try:
210+
content = skill_file.read_text(encoding="utf-8")
211+
except OSError:
212+
return False
213+
214+
if not content.startswith("---"):
215+
return False
216+
217+
parts = content.split("---", 2)
218+
if len(parts) < 3:
219+
return False
220+
221+
try:
222+
import yaml
223+
224+
frontmatter = yaml.safe_load(parts[1])
225+
except Exception:
226+
return False
227+
228+
if not isinstance(frontmatter, dict):
229+
return False
230+
231+
metadata = frontmatter.get("metadata", {})
232+
if not isinstance(metadata, dict):
233+
return False
234+
235+
author = metadata.get("author", "")
236+
source = metadata.get("source", "")
237+
return author == "github-spec-kit" or (
238+
isinstance(source, str) and source.startswith("templates/commands/")
239+
)
240+
241+
242+
def _migrate_legacy_kimi_context_file(project_root: Path) -> bool:
243+
"""Migrate user content from legacy ``KIMI.md`` to ``AGENTS.md``.
244+
245+
The Speckit managed section is stripped from ``KIMI.md`` before the
246+
remaining content is appended to ``AGENTS.md``. The legacy file is
247+
deleted if it becomes empty. Returns ``True`` if ``KIMI.md`` existed
248+
and was processed.
249+
"""
250+
legacy_path = project_root / "KIMI.md"
251+
if not legacy_path.is_file():
252+
return False
253+
254+
marker_start = IntegrationBase.CONTEXT_MARKER_START
255+
marker_end = IntegrationBase.CONTEXT_MARKER_END
256+
257+
content = legacy_path.read_text(encoding="utf-8-sig")
258+
start_idx = content.find(marker_start)
259+
end_idx = content.find(marker_end, start_idx if start_idx != -1 else 0)
260+
261+
if start_idx != -1 and end_idx != -1 and end_idx > start_idx:
262+
removal_start = start_idx
263+
removal_end = end_idx + len(marker_end)
264+
if removal_end < len(content) and content[removal_end] == "\r":
265+
removal_end += 1
266+
if removal_end < len(content) and content[removal_end] == "\n":
267+
removal_end += 1
268+
if removal_start > 0 and content[removal_start - 1] == "\n":
269+
if removal_start > 1 and content[removal_start - 2] == "\n":
270+
removal_start -= 1
271+
content = content[:removal_start] + content[removal_end:]
272+
273+
user_content = content.replace("\r\n", "\n").replace("\r", "\n").strip()
274+
if not user_content:
275+
legacy_path.unlink()
276+
return True
277+
278+
target_path = project_root / "AGENTS.md"
279+
if target_path.is_file():
280+
existing = target_path.read_text(encoding="utf-8-sig")
281+
existing = existing.replace("\r\n", "\n").replace("\r", "\n")
282+
if not existing.endswith("\n"):
283+
existing += "\n"
284+
new_content = existing + "\n" + user_content + "\n"
285+
else:
286+
new_content = user_content + "\n"
287+
288+
target_path.parent.mkdir(parents=True, exist_ok=True)
289+
target_path.write_bytes(new_content.encode("utf-8"))
290+
legacy_path.unlink()
291+
return True
292+
293+
294+
def _migrate_legacy_kimi_dotted_skills(skills_dir: Path) -> tuple[int, int]:
295+
"""Migrate legacy Kimi dotted skill dirs (speckit.xxx) to hyphenated format.
296+
297+
.. deprecated::
298+
Kept for direct callers/tests; new code should use
299+
``_migrate_legacy_kimi_skills_dir``.
300+
301+
Returns ``(migrated_count, removed_count)``.
302+
"""
303+
return _migrate_legacy_kimi_skills_dir(skills_dir, skills_dir)

0 commit comments

Comments
 (0)