Skip to content

fix(agent-core-v2): update import-from-cc-codex for current Claude Code and Codex layouts - #4331

Merged
RealKai42 merged 4 commits into
mainfrom
fix/import-cc-codex-refresh
Oct 22, 2026
Merged

RealKai42 merged 4 commits into
mainfrom
fix/import-cc-codex-refresh

Conversation

@RealKai42

@RealKai42 RealKai42 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

内置 skill /import-from-cc-codex 的扫描路径和字段映射已落后于当前 Claude Code(v2.1.300)与 Codex 的配置布局,导入结果不完整或映射错误。

Bug Reproduction Steps

  1. 设置 CLAUDE_CONFIG_DIR 或 CODEX_HOME 指向非默认目录后运行 /import-from-cc-codex:skill 只扫 ~/.claude / ~/.codex,报告"没有找到"。
  2. 项目只有根目录 CLAUDE.md(Kimi 不读该文件):skill 明确跳过它,指令无法导入。
  3. ~/.claude.json 里的条目使用 Claude 真实字段 type: "http" + timeout:skill 按不存在于 Claude 的字段名(startupTimeoutMs、bearerTokenEnvVar 等)去读,timeout 被丢弃。
  4. 用户使用 AGENTS.override.md、Claude rules 或嵌套项目指令后运行导入:旧指引不扫描这些来源;仍有效的项目技能目录也需要继续支持。

Root Cause

skill 文本自 #582 之后没有随两个上游更新:用户级 skills 已支持 .agents/skills,同时仍兼容原用户技能根和项目 .codex/skills;新增 AGENTS.override.md、MCP 字段大量变化(startup_timeout_ms、auth、environment_id 等,旧的 experimental_environment 已不存在);Claude Code 的 rules/、CLAUDE.local.md、.claude.json 里 projects[...] 的本地 MCP 作用域、${VAR} 占位符都未覆盖,而 .claude/AGENTS.md、项目 .codex/AGENTS.md 和 .codex/CLAUDE.md 不应作为独立入口扫描;有效来源的软链接和 @path 引用仍需展开。

这是根本修复:对照两边当前源码重写来源清单与字段映射,并逐条回到源码核对。

Code Changes

只改一个内置 skill 的 markdown(纯 prompt 文本,无 TypeScript 逻辑变化)和一个 changeset。

 源目录
-  ~/.claude、~/.codex 写死
+  $CLAUDE_CONFIG_DIR ?? ~/.claude(.claude.json 跟随该目录);$CODEX_HOME ?? ~/.codex
 Claude 指令
-  ~/.claude/AGENTS.md、~/.claude/CLAUDE.md、<root>/.claude/{AGENTS,CLAUDE}.md
+  <claude home>/CLAUDE.md、<claude home>/rules/**/*.md
+  项目根→cwd 每级目录:CLAUDE.md、.claude/CLAUDE.md、CLAUDE.local.md、.claude/rules/**
+  @path 导入在项目/home 范围内按来源文件位置内联(≤5 层)
+  导入后读回,仅删除本次新增、且有同等或更广作用域覆盖的完全重复指令块
 Codex 指令
-  ~/.codex/{AGENTS,CLAUDE}.md、<root>/.codex/{AGENTS,CLAUDE}.md
+  <codex home>/AGENTS.override.md 或 AGENTS.md(取第一个非空)
+  每级目录:AGENTS.override.md;project_doc_fallback_filenames 仅当该目录没有 AGENTS*.md
 Skills
-  ~/.claude/skills、<root>/.claude/skills、~/.codex/skills、<root>/.codex/skills;接受扁平 <name>.md
+  <claude home>/skills(跳过 synced)、<codex home>/skills(跳过 .system)
+  每级目录 .claude/skills 与 .codex/skills,按项目 Claude → 项目另一工具 → 用户 Claude → 用户另一工具处理同目标冲突
+  只接受 <name>/SKILL.md 目录包;frontmatter 兼容性警告按两边当前字段表更新
 MCP
-  ~/.claude.json 顶层 mcpServers;Codex 旧字段表
+  .claude.json 顶层 + projects[<repo root>].mcpServers(Claude 本地作用域)
+  当前来源项目 disabledMcpServers 命中的用户级/本地级候选均跳过并说明,不生成全局禁用配置
+  Claude 真实字段映射:type→transport、timeout→toolTimeoutMs、alwaysLoad:true→deferred:false;ws/sdk/claudeai-proxy 丢弃
+  ${VAR} 占位符:Authorization: Bearer ${VAR}→bearerTokenEnvVar;透传 env 丢弃(Kimi 继承父进程 env);其余阻断该条目
+  Codex 字段按 RawMcpServerConfig 全集映射;environment_id≠local、auth=chatgpt/ema_auth 的条目丢弃
 写入目标
-  项目指令统一写 <root>/.kimi-code/AGENTS.md
+  按来源目录写 <dir>/.kimi-code/AGENTS.md(Kimi 逐级读取,保留原目录作用域)
+  含 paths 的 Claude rules 一律跳过并列出源路径、glob 和手动适配原因

事实来源:Claude Code v2.1.300 解包源码(记忆文件加载、skills 目录扫描、MCP zod schema 与作用域解析);Codex 仓库 codex-rs/config/src/mcp_types.rs、codex-home/src/instructions、exec-server/src/discoverV2/capability_locations.rs、core/src/agents_md.rs 及其自带的 external-agent-migration;Kimi 侧 mcpCore/config-schema.ts、skill/catalog/skillRoots.ts、agent/profile/context.ts、skill/catalog/parser.ts。

Behavior Changes and Affected Users

本 PR 只改 prompt 文本。受影响人群:在 TUI、desktop、web 中手动运行 /import-from-cc-codex 的用户(skill 带 disable-model-invocation,模型不会自行触发)。写入前仍要求用户预览并确认,MCP 仍不直接写文件、仍通过 /mcp-config 手动跟进。

Behavior Before After Who relies on the old behavior Escape hatch
源目录解析 固定 ~/.claude、~/.codex 优先 CLAUDE_CONFIG_DIR、CODEX_HOME,未设置时不变 无(默认路径行为不变) —
扫描 ~/.claude/AGENTS.md、<root>/.claude/AGENTS.md 导入 不再作为独立入口扫描;有效 CLAUDE.md 的软链接或 @path 仍会展开 手工维护了 .claude/AGENTS.md 的用户 手动复制,或改名为 CLAUDE.md 后再导入
旧项目隐藏指令入口 扫描项目 .codex/AGENTS.md、.codex/CLAUDE.md,以及 <codex home>/CLAUDE.md 不再作为独立入口扫描;有效来源引用它们时仍展开 在这些路径手工维护指令的用户 手动复制到 Kimi 指令文件
项目根 CLAUDE.md、CLAUDE.local.md 明确跳过 导入;相对引用以来源文件目录解析,私有文件导入时提示 gitignore 区别 使用项目根 Claude 指令的用户 预览阶段取消
~/.claude/rules、.claude/rules 不扫描 无 paths 则导入正文;含 paths 则全部跳过并报告源路径、glob 和作用域不兼容原因 使用无条件或文件匹配规则的用户 带 paths 的规则手动适配
skills 目录下扁平 <name>.md 作为 skill 复制 跳过并报告(Claude Code 与 Codex 都不加载) 把 commands 风格 .md 放进 skills 目录的用户 手动复制到 .kimi-code/skills(Kimi 支持扁平 skill)
Claude MCP 字段映射 按 Kimi 字段名读 Claude 条目(Claude 并无这些字段) 按 Claude 真实字段映射;ws/sdk/claudeai-proxy 条目丢弃并报告 — —
Claude 本地作用域 MCP(.claude.json projects[...]) 不读 读取并归入 <cwd>/.kimi-code/mcp.json 的预览;当前项目禁用名命中的用户/本地候选跳过并说明 配有本地或已禁用 MCP 的用户 禁用项可手动配置;不把项目禁用写入全局
Codex MCP 字段映射 旧字段表,含已不存在的 experimental_environment 当前字段全集;environment_id≠local、auth=chatgpt/ema_auth 条目丢弃并报告 — —
项目指令写入目标 统一 <root>/.kimi-code/AGENTS.md 按来源目录写 <dir>/.kimi-code/AGENTS.md — —
导入后的重复指令检查 只按已有导入标记避免重复 读回真实加载范围,只清理本次新增且被同等或更广作用域覆盖的完全重复块;相似、冲突或不确定时保留并报告 同时维护多种来源指令、全局及嵌套指令的用户 保留既有内容,预览取消
项目技能 只扫项目根的两种品牌技能目录 保留有效来源并扫描根到 cwd 的每一级;同目标冲突优先项目 Claude、项目另一工具、用户 Claude、用户另一工具,同类取最近目录 使用项目品牌技能目录及嵌套技能的用户 预览取消;已存在目标不覆盖
缓存与插件管理技能 没有明确跳过 synced/.system,排除插件管理目录 跳过同步和系统缓存;含插件元数据的目录包可导入并提示,隐藏元数据不复制 使用同步或插件管理技能的用户 预览取消;源文件不改
来源专有技能语法 概括提示 明确字段和变量兼容性警告,保留源文件原文 使用工具专有 frontmatter、变量或动态命令的用户 手动适配,或配置额外技能目录
项目根以上的 Claude 指令 不扫描 仅报告项目外来源,保留不导入的边界 在项目祖先目录维护指令的用户 按提示手动选择处理

受影响模块与测试覆盖:

  • 内置 skill 注册、指令加载与提醒、技能解析与目录发现、MCP 配置加载与存储共 8 个测试文件、166 条现有测试全部通过;最后版本的内置 skill 7 条测试再次通过。
  • 当前源码 SDK + 真实模型在隔离合成目录中完成分类确认、预览确认、实际写入、去重与读回,14 项断言全部通过;确认发生在首个写入前,原有内容保留,带 paths 规则跳过,恢复的项目技能及支持文件完整复制,禁用 MCP 未进入待应用 JSON,未直接写任何 mcp.json。
  • 当前真实运行时的 MCP 探针确认:禁用项不启动,正常项完成连接与 echo 调用,其他项目禁用状态不影响当前项目;指令清理探针确认:仅删除新重复块,原有字节与跨项目覆盖保持不变。
  • 新增模型和运行时探针是本地验证,未提交为自动测试;changeset 已列明移除的独立入口、扁平技能及手动复制退路。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…de and Codex layouts

Honor CLAUDE_CONFIG_DIR and CODEX_HOME, import project CLAUDE.md, CLAUDE.local.md, Claude rules, Codex AGENTS.override.md, and Claude project-local MCP servers, and map the current Claude Code and Codex MCP fields. Stop scanning .claude/AGENTS.md, .codex/AGENTS.md, and .codex/skills, which neither tool reads.
Copilot AI balanced review requested due to automatic review settings October 22, 2026 07:11
@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1e9d234

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T12:41:35.866705Z 1e9d234 New commits
🔒 Security Review ✅ Completed 2026-10-22T07:17:12.713419Z 9f7916d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@1e9d234
npx https://pkg.pr.new/@moonshot-ai/kimi-code@1e9d234

commit: 1e9d234

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f7916d1d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03f4b37192

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

RealKai42 and others added 2 commits October 22, 2026 05:12
…cc-codex

The skill renderer substitutes argument and KIMI placeholders anywhere in a skill body, so the migration guidance reached the model with the session ID and a builtin path in place of the Kimi placeholder names, and invocation arguments were spliced into the prose. Name the placeholders without their literal forms and pin the rendered body in a test.
@RealKai42
RealKai42 merged commit 759958a into main Oct 22, 2026
16 checks passed
@RealKai42
RealKai42 deleted the fix/import-cc-codex-refresh branch October 22, 2026 12:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e9d23461a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +374 to +376
- `startup_timeout_sec` (may be fractional) -> `startupTimeoutMs`
- `startup_timeout_ms` -> `startupTimeoutMs`
- `tool_timeout_sec` -> `toolTimeoutMs`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Convert Codex timeout seconds to milliseconds

When a Codex MCP entry specifies startup_timeout_sec or tool_timeout_sec, this mapping no longer tells the model to multiply the value by 1000 before writing Kimi's *TimeoutMs field. Codex defines both fields in seconds (upstream definition), so a normal value such as 10 becomes 10 ms rather than 10 seconds and will make many imported servers time out immediately. Restore the unit conversion and specify that startup_timeout_sec takes precedence when both startup fields exist.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

Comment on lines +33 to +35
current working directory. The project root is the nearest parent
directory containing `.git`; if no `.git` exists, use the current working
directory.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor Codex's configured project root

For users who set project_root_markers in Codex, fixing the source project root to the nearest .git scans the wrong instruction chain: a custom marker below the Git root causes unrelated ancestor instructions to be imported, while a marker above it causes active instructions to be missed. Codex derives this boundary from the effective marker configuration and even allows an empty list to disable parent traversal (discovery implementation); resolve the Codex source range with those settings instead of reusing Kimi's Git-root destination boundary.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

Comment on lines +331 to +335
- Read `disabledMcpServers` from that project's object before normalizing
candidates. Skip any Claude user-scope or local-scope candidate whose name
is listed there, and report it as "disabled in the source project; not
imported". This is a project-specific choice, so do not turn it into a
user-global `enabled: false` entry or silently re-enable the server.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve disabled user MCP servers outside this project

When the current Claude project disables a user-scoped server, these instructions discard that global candidate entirely, so after migration it is also unavailable in every other Kimi project. Claude stores disabledMcpServers as a per-project preference while user-scoped servers remain available across projects (scope documentation, disable behavior); preserve the global entry and represent the current project's opt-out with a complete project-local enabled: false override instead.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

- `type: sse` -> `transport: "sse"`
- `command`, `args`, `env`, `url`, `headers` -> same names
- `timeout` -> `toolTimeoutMs`
- `alwaysLoad: true` -> `deferred: false`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Map explicit Claude deferral to Kimi

For a Claude server with alwaysLoad: false, this one-sided mapping omits Kimi's deferred field, whose effective default is false, and therefore changes explicitly deferred tools into eagerly exposed tools. Claude documents that alwaysLoad: false keeps every tool behind tool search, including tools the server author marked for upfront loading (Claude MCP documentation); map it to deferred: true while retaining the existing true mapping.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

Comment on lines +175 to +179
Claude Code expands `@path` import lines (`@./docs/style.md`, `@~/notes.md`)
inside `CLAUDE.md` files, ignoring `@` inside fenced code blocks, inline code
spans, and HTML comments. Kimi does not expand imports at all. For each
imported block that contains such lines, inline the referenced file's content
in place of the line when the file exists, is a text file, and lives inside

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Parse Claude imports as tokens rather than whole lines

For valid Claude instructions such as See @README for context or @Design\ Docs/rules.md, treating imports as standalone lines either misses the import or replaces surrounding instruction text and resolves the wrong truncated path. Claude permits imports anywhere outside code spans and fences and uses backslash-escaped spaces rather than quoted paths (Claude memory documentation); parse and replace the import token itself instead of replacing an assumed whole line.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

Comment on lines +308 to +311
Kimi's stdio servers inherit the parent process environment and then apply
`env` on top, so pass-through declarations (Codex `env_vars`, Claude
`"KEY": "${KEY}"`) need no Kimi equivalent; drop them and note that the
variable is inherited.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Verify pass-through variables before dropping them

When an env_vars or ${KEY} pass-through names a variable supplied only by Claude settings or by the process that launched Codex, the Kimi process running this importer need not contain it; dropping the declaration and claiming inheritance then produces an MCP server with a missing credential or setting. Check the current Kimi environment before dropping each pass-through and block or warn on absent variables rather than reporting that they are inherited.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

- `url` -> `url`
- `bearer_token_env_var` -> `bearerTokenEnvVar`
- `http_headers` -> `headers`
- `auth = "oauth"` -> `auth: "oauth"` (also Codex's default; omit when absent)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve Codex's default OAuth mode

For a remote Codex server that omits auth, especially one with additional http_headers, this instruction removes Codex's default OAuth mode instead of translating it. Codex defaults McpServerAuth to OAuth (upstream definition), while Kimi treats a header-bearing entry without auth: "oauth" as non-OAuth in mcpManagementService.ts and connection-manager.ts, so sign-in is not offered and authentication failures are not classified correctly. Emit auth: "oauth" for the absent Codex value as well as the explicit one.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

Comment on lines 360 to 361
- Read selected `config.toml` files only if MCP was selected.
- Look for `[mcp_servers.<name>]` tables.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Merge Codex MCP layers before normalizing servers

For a newly discovered nested .codex/config.toml that only overrides part of a user server, reading each [mcp_servers.<name>] table independently does not reproduce Codex's effective configuration. Codex recursively merges project configuration over lower layers (loader documentation), whereas Kimi replaces an entire same-name server entry; for example, a project layer containing only enabled = false is invalid by itself and leaves the imported global server running. Materialize each complete effective server after applying the Codex layer stack before generating the scoped Kimi entries.

AGENTS.md reference: AGENTS.md:L112-L112

Useful? React with 👍 / 👎.

Comment on lines +115 to +117
- any filename listed under `project_doc_fallback_filenames` in a Codex
`config.toml`, only when neither file above exists in `<dir>` and the
name is not already covered by another source in this list

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject fallback paths that Codex ignores

When project_doc_fallback_filenames contains a path-like value such as ../CLAUDE.md, these instructions can traverse outside <dir> and import it even though Codex rejects that value and never treats the file as instructions. Codex filters empty names, ./.., NUL, path separators, and Windows-invalid separators before probing (upstream validation); apply the same validation before scanning fallback filenames.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

Comment on lines +101 to +105
- Claude instructions, per directory `<dir>`:
- `<dir>/CLAUDE.md`
- `<dir>/.claude/CLAUDE.md`
- `<dir>/CLAUDE.local.md` (private, usually gitignored)
- `<dir>/.claude/rules/*.md` (recursive)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor Claude instruction exclusion settings

For users whose claudeMdExcludes matches one of the newly scanned .claude/rules/*.md or CLAUDE.md files, this unconditional source list imports inactive content and makes it active in Kimi. Claude applies exclusion globs from its settings layers to absolute instruction paths, including symlink paths and targets (Claude memory documentation); resolve those settings during discovery and omit or clearly report excluded files rather than importing them.

AGENTS.md reference: AGENTS.md:L118-L120

Useful? React with 👍 / 👎.

This was referenced Oct 27, 2026
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.

4 participants