feat(cli): add kimi import command for cross-tool session transfer#2141
feat(cli): add kimi import command for cross-tool session transfer#2141NOLANeight wants to merge 2 commits into
Conversation
Add session import CLI command supporting Claude Code as first source. Closes MoonshotAI#2102.
🦋 Changeset detectedLatest commit: 9ab749c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d39c77c62
ℹ️ 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".
| reject(new Error(`${event.code}: ${event.message}`)); | ||
| return; | ||
| } | ||
| if (event.type === 'turn.ended') { |
There was a problem hiding this comment.
Wait only for the main prompt turn to finish
When kimi import --prompt runs a prompt that spawns a subagent or other non-main agent, that agent can emit turn.ended before the main follow-up prompt is done; this listener resolves immediately and the code closes the session afterward, cutting off the active main turn. Track the main agent/turn completion (and non-completed reasons) before resolving.
Useful? React with 👍 / 👎.
| for (const tr of toolResults) { | ||
| conversation.push({ | ||
| kind: 'tool-result', | ||
| toolName: lastToolCallName || 'tool', |
There was a problem hiding this comment.
Map tool results by their tool_use_id
When an assistant message contains multiple tool_use blocks before the following user message returns their tool_result blocks, every result is labeled with only the last tool name because tool_use_id is ignored. This corrupts the imported handoff history for common multi-tool turns; keep an id-to-name map and use tr.tool_use_id when building each result.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| if (input === 0 && output === 0) return undefined; | ||
| return { input, output, ...(cacheRead > 0 ? { cacheRead } : {}), ...(cacheCreation > 0 ? { cacheCreation } : {}) }; |
There was a problem hiding this comment.
Replace conditional spreads for optional fields
This new object literal uses conditional spreads for optional properties, and the same pattern appears later in the new parser; the local coding requirements explicitly say optional object properties should be passed as undefined directly instead. Please rewrite these as direct optional fields so the new import code follows the app-wide convention.
AGENTS.md reference: apps/kimi-code/AGENTS.md:L66-L69
Useful? React with 👍 / 👎.
- Track main agent turn.ended to avoid subagent race condition\n- Use tool_use_id map for multi-tool result labeling\n- Replace conditional spreads with direct undefined assignments
Summary
Add
kimi importCLI command for importing session context from external AI coding tools into Kimi Code. Enables migrating conversation history, tool activity, and project context. Starting with Claude Code support. Closes #2102.Changes
apps/kimi-code/src/cli/import/sources/types.ts— SourceParser interface + HandoffContext typesapps/kimi-code/src/cli/import/sources/claude-code.ts— Claude Code session JSONL parserapps/kimi-code/src/cli/sub/import.ts— kimi import CLI commandapps/kimi-code/test/cli/import.test.ts— 5 testsapps/kimi-code/src/cli/commands.ts— register import commandUsage
kimi import --from claude-code(interactive),--session,--prompt,--file,--printHow it works
Scans CC sessions → parses JSONL → generates handoff Markdown →
harness.createSession()+session.importContext()→ persisted, resumable viakimi -rVerification
pnpm typecheck: clean | oxlint: 0/0 | vitest: 5/5 new, 18/18 total | tested with real CC sessions