kimi-plugin-cc 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +3 -14
- package/README.md +428 -572
- package/assets/logo.svg +6 -0
- package/cordis.patch.yml +18 -0
- package/dist/background-spawn.js +4 -2
- package/dist/cli-client.js +105 -66
- package/dist/commands/ask.js +27 -12
- package/dist/commands/cancel.js +4 -13
- package/dist/commands/cli-helpers.js +1 -1
- package/dist/commands/pursue.js +3 -2
- package/dist/commands/registry.js +7 -26
- package/dist/commands/repair-sessions.js +7 -4
- package/dist/commands/replay.js +4 -3
- package/dist/commands/rescue.js +17 -5
- package/dist/commands/review.js +18 -5
- package/dist/commands/setup.js +277 -262
- package/dist/commands/swarm.js +20 -7
- package/dist/companion.js +142 -18
- package/dist/help.js +11 -7
- package/dist/hook-escape.js +7 -16
- package/dist/hooks/approval-hook.js +1762 -124
- package/dist/hooks/approval-policy.js +15 -10
- package/dist/hooks/config-safety.js +15 -24
- package/dist/hooks/hook-timing.js +1 -1
- package/dist/hooks/install-paths.js +179 -107
- package/dist/hooks/install.js +44 -166
- package/dist/hooks/managed-block.js +44 -95
- package/dist/job-store.js +117 -49
- package/dist/jobs.js +53 -1
- package/dist/kimi-engine.js +68 -92
- package/dist/kimi-errors.js +1 -1
- package/dist/kimi-journal.js +3 -2
- package/dist/kimi-releases.js +28 -49
- package/dist/kimi-timeouts.js +1 -15
- package/dist/kimi-version-probe.js +24 -72
- package/dist/logging.js +12 -7
- package/dist/mcp/binding.js +13 -4
- package/dist/mcp/job-control.js +386 -89
- package/dist/mcp/launcher.js +1 -1
- package/dist/mcp/operations.js +387 -193
- package/dist/mcp/protocol.js +116 -27
- package/dist/mcp/skills.js +130 -0
- package/dist/mcp/stdio.js +15 -2
- package/dist/native-v2-preflight.js +127 -35
- package/dist/parsing.js +45 -11
- package/dist/paths.js +20 -10
- package/dist/plugin-data.js +28 -83
- package/dist/read-scope.js +2 -2
- package/dist/render.js +13 -38
- package/dist/session-references.js +216 -0
- package/dist/session-title.js +1 -1
- package/dist/surface-routing.js +92 -5
- package/dist/swarm-activation.js +26 -137
- package/dist/version.js +1 -1
- package/docs/migration.md +45 -227
- package/docs/models.md +24 -66
- package/docs/safety.md +195 -400
- package/docs/session-visibility.md +24 -14
- package/docs/swarm-recovery.md +26 -20
- package/dsh/index.json +54 -0
- package/mcp_config.json +10 -0
- package/package.json +23 -82
- package/plugin.json +19 -0
- package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
- package/plugins/kimi-codex/.mcp.json +2 -3
- package/plugins/kimi-codex/dist/background-spawn.js +4 -2
- package/plugins/kimi-codex/dist/cli-client.js +105 -66
- package/plugins/kimi-codex/dist/commands/ask.js +27 -12
- package/plugins/kimi-codex/dist/commands/cancel.js +4 -13
- package/plugins/kimi-codex/dist/commands/cli-helpers.js +1 -1
- package/plugins/kimi-codex/dist/commands/pursue.js +3 -2
- package/plugins/kimi-codex/dist/commands/registry.js +7 -26
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +7 -4
- package/plugins/kimi-codex/dist/commands/replay.js +4 -3
- package/plugins/kimi-codex/dist/commands/rescue.js +17 -5
- package/plugins/kimi-codex/dist/commands/review.js +18 -5
- package/plugins/kimi-codex/dist/commands/setup.js +277 -262
- package/plugins/kimi-codex/dist/commands/swarm.js +20 -7
- package/plugins/kimi-codex/dist/companion.js +142 -18
- package/plugins/kimi-codex/dist/help.js +11 -7
- package/plugins/kimi-codex/dist/hook-escape.js +7 -16
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +1762 -124
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +15 -10
- package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -24
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +1 -1
- package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
- package/plugins/kimi-codex/dist/hooks/install.js +44 -166
- package/plugins/kimi-codex/dist/hooks/managed-block.js +44 -95
- package/plugins/kimi-codex/dist/job-store.js +117 -49
- package/plugins/kimi-codex/dist/jobs.js +53 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
- package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
- package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
- package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
- package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
- package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
- package/plugins/kimi-codex/dist/logging.js +12 -7
- package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
- package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
- package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
- package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
- package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
- package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
- package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
- package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
- package/plugins/kimi-codex/dist/parsing.js +45 -11
- package/plugins/kimi-codex/dist/paths.js +20 -10
- package/plugins/kimi-codex/dist/plugin-data.js +28 -83
- package/plugins/kimi-codex/dist/read-scope.js +2 -2
- package/plugins/kimi-codex/dist/render.js +13 -38
- package/plugins/kimi-codex/dist/session-references.js +216 -0
- package/plugins/kimi-codex/dist/session-title.js +1 -1
- package/plugins/kimi-codex/dist/surface-routing.js +92 -5
- package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/scripts/companion.sh +4 -15
- package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
- package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
- package/scripts/companion.sh +4 -15
- package/skills/kimi/SKILL.md +77 -0
- package/skills/kimi/agents/openai.yaml +6 -0
- package/CHANGELOG.md +0 -1402
- package/agents/kimi-pursue.md +0 -93
- package/agents/kimi-review.md +0 -86
- package/agents/kimi-swarm.md +0 -88
- package/agents/kimi-task.md +0 -93
- package/commands/README.md +0 -14
- package/commands/cancel.md +0 -17
- package/commands/pursue.md +0 -41
- package/commands/replay.md +0 -13
- package/commands/result.md +0 -13
- package/commands/review.md +0 -40
- package/commands/setup.md +0 -25
- package/commands/status.md +0 -13
- package/commands/swarm.md +0 -45
- package/commands/task.md +0 -40
- package/dist/commands/review-gate.js +0 -391
- package/dist/config.js +0 -22
- package/dist/dsh/companion.js +0 -177
- package/dist/dsh/index.js +0 -167
- package/dist/hooks/review-gate-stop.js +0 -19
- package/dist/schemas/review-gate-output.js +0 -41
- package/docs/registry-releases.md +0 -228
- package/docs/upstream-2.4.1-certification.md +0 -54
- package/docs/upstream-2.5.0-certification.md +0 -52
- package/docs/upstream-2.5.1-certification.md +0 -47
- package/docs/upstream-2.5.2-certification.md +0 -40
- package/docs/upstream-2.5.3-certification.md +0 -73
- package/docs/upstream-2.6.0-certification.md +0 -65
- package/docs/upstream-2.6.2-certification.md +0 -144
- package/docs/upstream-2.6.3-certification.md +0 -100
- package/docs/upstream-2.7.2-certification.md +0 -113
- package/docs/upstream-2.7.3-certification.md +0 -95
- package/docs/windows-validation.md +0 -39
- package/hooks/README.md +0 -9
- package/hooks/hooks.json +0 -16
- package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-codex/dist/config.js +0 -22
- package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
- package/plugins/kimi-codex/dist/dsh/index.js +0 -167
- package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
- package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
- package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
- package/plugins/kimi-dsh/LICENSE +0 -201
- package/plugins/kimi-dsh/README.md +0 -84
- package/plugins/kimi-dsh/cordis.patch.yml +0 -45
- package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
- package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
- package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
- package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
- package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
- package/plugins/kimi-dsh/dist/commands/models.js +0 -139
- package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
- package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
- package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
- package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
- package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
- package/plugins/kimi-dsh/dist/commands/result.js +0 -72
- package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-dsh/dist/commands/review.js +0 -217
- package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
- package/plugins/kimi-dsh/dist/commands/status.js +0 -27
- package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
- package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
- package/plugins/kimi-dsh/dist/companion.js +0 -99
- package/plugins/kimi-dsh/dist/config.js +0 -22
- package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
- package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
- package/plugins/kimi-dsh/dist/errors.js +0 -40
- package/plugins/kimi-dsh/dist/git.js +0 -216
- package/plugins/kimi-dsh/dist/help.js +0 -43
- package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
- package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
- package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
- package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
- package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-dsh/dist/job-id.js +0 -12
- package/plugins/kimi-dsh/dist/job-store.js +0 -631
- package/plugins/kimi-dsh/dist/jobs.js +0 -212
- package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
- package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
- package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
- package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
- package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
- package/plugins/kimi-dsh/dist/logging.js +0 -22
- package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
- package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
- package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
- package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
- package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
- package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
- package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
- package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
- package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
- package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
- package/plugins/kimi-dsh/dist/model-command.js +0 -34
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
- package/plugins/kimi-dsh/dist/package.json +0 -1
- package/plugins/kimi-dsh/dist/parsing.js +0 -554
- package/plugins/kimi-dsh/dist/paths.js +0 -35
- package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
- package/plugins/kimi-dsh/dist/process-tree.js +0 -597
- package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
- package/plugins/kimi-dsh/dist/read-scope.js +0 -435
- package/plugins/kimi-dsh/dist/render.js +0 -214
- package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
- package/plugins/kimi-dsh/dist/session-title.js +0 -313
- package/plugins/kimi-dsh/dist/stream-json.js +0 -344
- package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
- package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
- package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
- package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
- package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
- package/plugins/kimi-dsh/dist/types.js +0 -1
- package/plugins/kimi-dsh/dist/util.js +0 -28
- package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
- package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
- package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
- package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
- package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
- package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
- package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
- package/plugins/kimi-dsh/dist/version.js +0 -7
- package/plugins/kimi-dsh/package.json +0 -78
- package/plugins/kimi-dsh/scripts/companion.sh +0 -37
- package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
- package/scripts/review-gate-hook.sh +0 -32
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { RuntimeError, formatError } from "./errors.js";
|
|
2
|
-
import { MAX_DURATION_MS as BUDGET_CEILING_MS } from "./parsing.js";
|
|
3
|
-
function formatBudgetMs(ms) {
|
|
4
|
-
if (ms % 3_600_000 === 0)
|
|
5
|
-
return `${ms / 3_600_000}h`;
|
|
6
|
-
if (ms % 60_000 === 0)
|
|
7
|
-
return `${ms / 60_000}m`;
|
|
8
|
-
return `${Math.ceil(ms / 1_000)}s`;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Suggest a concrete next budget from the one that just expired: double it,
|
|
12
|
-
* capped at the 24h ceiling. At the ceiling there is nothing left to raise,
|
|
13
|
-
* so the only honest advice is to narrow the prompt.
|
|
14
|
-
*/
|
|
15
|
-
function budgetAdvice(budgetMs) {
|
|
16
|
-
if (budgetMs === undefined || !Number.isFinite(budgetMs) || budgetMs <= 0)
|
|
17
|
-
return "raise the budget (`--budget <dur>`, at most 24h)";
|
|
18
|
-
if (budgetMs >= BUDGET_CEILING_MS)
|
|
19
|
-
return "note the budget is already at the 24h ceiling, so narrowing the prompt is the only remaining lever";
|
|
20
|
-
return `raise the budget (e.g. \`--budget ${formatBudgetMs(Math.min(budgetMs * 2, BUDGET_CEILING_MS))}\`)`;
|
|
21
|
-
}
|
|
22
|
-
export function classifyManagedCommandFailure(error, commandType, jobId, options) {
|
|
23
|
-
const classification = classifyKimiAvailability(error);
|
|
24
|
-
if (!classification) {
|
|
25
|
-
return error instanceof Error ? error : new Error(String(error));
|
|
26
|
-
}
|
|
27
|
-
if (classification.kind === "response_timeout" && commandType !== "review_gate" && options?.background !== undefined) {
|
|
28
|
-
const foregroundAdvice = !options?.background && (commandType === "ask" || commandType === "rescue")
|
|
29
|
-
? " Or run with --background so the caller's shell timeout is not the limit."
|
|
30
|
-
: "";
|
|
31
|
-
classification.nextStep = `Narrow the prompt or ${budgetAdvice(options.budgetMs)}. Partial output, if any, is in the artifact (\`result ${jobId}\`).${foregroundAdvice}`;
|
|
32
|
-
}
|
|
33
|
-
const label = formatCommandLabel(commandType);
|
|
34
|
-
const stage = options?.preserveStage && error instanceof RuntimeError
|
|
35
|
-
? error.stage
|
|
36
|
-
: `${commandType}.runtime`;
|
|
37
|
-
// Thread the cause's code and message into `details` so the underlying
|
|
38
|
-
// failure survives the wrap on every channel (formatError renders details
|
|
39
|
-
// as a JSON line; normalizeJobError persists them in the job row). Without
|
|
40
|
-
// this, a CLI_NONZERO_EXIT whose message embeds kimi's stderr tail (e.g.
|
|
41
|
-
// `auth.login_required` on 2026-08-08) was reduced to the generic
|
|
42
|
-
// "run /kimi:setup" advice with the real cause reachable only as `cause`,
|
|
43
|
-
// which no output channel serializes — an LLM caller could not diagnose it.
|
|
44
|
-
const details = { availability: classification.kind };
|
|
45
|
-
if (error instanceof RuntimeError) {
|
|
46
|
-
details.cause_code = error.code;
|
|
47
|
-
for (const key of ["spawn_code", "spawn_errno", "spawn_message"]) {
|
|
48
|
-
if (error.details[key] !== undefined)
|
|
49
|
-
details[key] = key === "spawn_message" && typeof error.details[key] === "string"
|
|
50
|
-
? truncateCauseMessageForDetails(error.details[key]) : error.details[key];
|
|
51
|
-
}
|
|
52
|
-
if (error.code === "RESPONSE_TIMEOUT") {
|
|
53
|
-
for (const key of ["budget_ms", "record_count", "partial_output_chars", "aborted", "settled_post_abort", "hook_escapes"]) {
|
|
54
|
-
if (error.details[key] !== undefined)
|
|
55
|
-
details[key] = error.details[key];
|
|
56
|
-
}
|
|
57
|
-
if (details.budget_ms === undefined && options?.budgetMs !== undefined)
|
|
58
|
-
details.budget_ms = options.budgetMs;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (error instanceof Error && error.message.length > 0) {
|
|
62
|
-
details.cause_message = truncateCauseMessageForDetails(error.message);
|
|
63
|
-
}
|
|
64
|
-
return new RuntimeError(mapAvailabilityCode(classification.kind, commandType), `${label} could not run because ${classification.summary} ${classification.nextStep} Job ${jobId} was persisted as failed.`, stage, error instanceof Error ? { cause: error, details } : { details });
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Cap the cause message carried in `details` so a large stderr tail cannot
|
|
68
|
-
* bloat the SQLite job row or the rendered details JSON line. Keep the TAIL
|
|
69
|
-
* end: for a crashed subprocess the informative lines (kimi's own `error:`
|
|
70
|
-
* output) are the trailing bytes of stderr, which cli-helpers appends last.
|
|
71
|
-
*/
|
|
72
|
-
const CAUSE_MESSAGE_DETAILS_MAX = 2000;
|
|
73
|
-
function truncateCauseMessageForDetails(message) {
|
|
74
|
-
if (message.length <= CAUSE_MESSAGE_DETAILS_MAX) {
|
|
75
|
-
return message;
|
|
76
|
-
}
|
|
77
|
-
return `…${message.slice(-CAUSE_MESSAGE_DETAILS_MAX)}`;
|
|
78
|
-
}
|
|
79
|
-
export function summarizeKimiAvailabilityWarning(error, commandType) {
|
|
80
|
-
const classification = classifyKimiAvailability(error);
|
|
81
|
-
if (!classification) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
return `Kimi ${formatCommandLabel(commandType).toLowerCase()} ${AVAILABILITY_WARNING_PHRASES[classification.kind]}; allowing stop.`;
|
|
85
|
-
}
|
|
86
|
-
const AVAILABILITY_WARNING_PHRASES = {
|
|
87
|
-
auth_unavailable: "is not configured for model access",
|
|
88
|
-
binary_unavailable: "could not find the Kimi CLI",
|
|
89
|
-
startup_failed: "could not start a usable Kimi subprocess",
|
|
90
|
-
startup_timeout: "did not respond during startup",
|
|
91
|
-
initialize_timeout: "did not complete session initialization",
|
|
92
|
-
response_timeout: "did not return a final response",
|
|
93
|
-
max_steps_reached: "exhausted its step budget",
|
|
94
|
-
timeout: "timed out",
|
|
95
|
-
};
|
|
96
|
-
export function classifySetupFailure(error) {
|
|
97
|
-
return classifyKimiAvailability(error);
|
|
98
|
-
}
|
|
99
|
-
function classifyKimiAvailability(error) {
|
|
100
|
-
const message = formatError(error);
|
|
101
|
-
// kimi-code's managed OAuth store emits `auth.login_required: OAuth
|
|
102
|
-
// provider "managed:kimi-code" requires login…` on stderr when the token
|
|
103
|
-
// is missing or expired (observed on 0.34.0 after an out-of-band binary
|
|
104
|
-
// upgrade invalidated the token). The line reaches us inside the
|
|
105
|
-
// CLI_NONZERO_EXIT message because cli-helpers embeds the stderr tail.
|
|
106
|
-
// This MUST precede the code-based CLI_NONZERO_EXIT branch below, which
|
|
107
|
-
// would otherwise misclassify a logged-out CLI as startup_failed and
|
|
108
|
-
// point the user at /kimi:setup — which cannot fix auth.
|
|
109
|
-
if (message.includes("auth.login_required")) {
|
|
110
|
-
return {
|
|
111
|
-
kind: "auth_unavailable",
|
|
112
|
-
summary: "the local Kimi CLI is logged out (its OAuth login is missing or expired).",
|
|
113
|
-
nextStep: "Run `kimi login` to re-authenticate, then retry. `/kimi:setup` does not repair auth.",
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
if (message.includes("LLM is not set") || message.includes("LLM service error")) {
|
|
117
|
-
return {
|
|
118
|
-
kind: "auth_unavailable",
|
|
119
|
-
summary: "local Kimi authentication or model configuration is not usable.",
|
|
120
|
-
nextStep: "Run `/kimi:setup`, then `kimi login` or fix the local Kimi model configuration and retry.",
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
if (error instanceof RuntimeError &&
|
|
124
|
-
(error.code === "CLI_SPAWN_FAILED" || error.code === "CLI_PROCESS_ERROR")) {
|
|
125
|
-
const spawnCode = error.details.spawn_code;
|
|
126
|
-
const binaryUnavailable = typeof spawnCode === "string" && ["ENOENT", "EACCES", "ENOEXEC"].includes(spawnCode);
|
|
127
|
-
if (typeof spawnCode === "string" && !binaryUnavailable) {
|
|
128
|
-
return {
|
|
129
|
-
kind: "startup_failed",
|
|
130
|
-
summary: "the Kimi subprocess could not be started or used.",
|
|
131
|
-
nextStep: "Check the underlying process error; shorten the prompt or environment if an argument-size limit was exceeded, then retry.",
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
// Keep opaque synchronous failures and legacy async ENOENT diagnostics compatible.
|
|
135
|
-
if (binaryUnavailable || error.code === "CLI_SPAWN_FAILED" || /\bENOENT\b/.test(message)) {
|
|
136
|
-
return {
|
|
137
|
-
kind: "binary_unavailable",
|
|
138
|
-
summary: "the Kimi CLI is missing from PATH or not executable in this environment.",
|
|
139
|
-
nextStep: "Run `/kimi:setup` to verify the install, then expose `kimi` on PATH and retry.",
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// v1.0 cli-client surfaces non-ENOENT process errors and non-zero
|
|
144
|
-
// exits as CLI_PROCESS_ERROR / CLI_NONZERO_EXIT. Treat both as
|
|
145
|
-
// startup-failed for classifier purposes — the next step is the same
|
|
146
|
-
// (run /kimi:setup) and the distinction between "kimi crashed during
|
|
147
|
-
// init" vs "kimi exited with status 1" is post-hoc.
|
|
148
|
-
if (error instanceof RuntimeError &&
|
|
149
|
-
(error.code === "CLI_PROCESS_ERROR" || error.code === "CLI_NONZERO_EXIT")) {
|
|
150
|
-
return {
|
|
151
|
-
kind: "startup_failed",
|
|
152
|
-
summary: "the Kimi CLI exited before completing the requested operation.",
|
|
153
|
-
nextStep: "Run `/kimi:setup` to verify local Kimi health, then retry.",
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
if (error instanceof RuntimeError && error.code === "MAX_STEPS_REACHED") {
|
|
157
|
-
return {
|
|
158
|
-
kind: "max_steps_reached",
|
|
159
|
-
summary: "Kimi exhausted its step budget before finalizing the turn.",
|
|
160
|
-
nextStep: "Retry with a more focused prompt or a higher step budget.",
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
if (error instanceof RuntimeError) {
|
|
164
|
-
// STARTUP_TIMEOUT and INITIALIZE_TIMEOUT predate the v1.0 subprocess
|
|
165
|
-
// transport (the v0.4 Wire client had a three-phase startup). The
|
|
166
|
-
// v1.0 cli-client only emits RESPONSE_TIMEOUT, so these branches are
|
|
167
|
-
// defensive — callers that synthesize the old codes (or load v0.4
|
|
168
|
-
// job rows from SQLite) still get a useful classification.
|
|
169
|
-
if (error.code === "STARTUP_TIMEOUT") {
|
|
170
|
-
return {
|
|
171
|
-
kind: "startup_timeout",
|
|
172
|
-
summary: "the Kimi CLI did not respond during startup.",
|
|
173
|
-
nextStep: "Run `/kimi:setup` to verify local Kimi health, then retry.",
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
if (error.code === "INITIALIZE_TIMEOUT") {
|
|
177
|
-
return {
|
|
178
|
-
kind: "initialize_timeout",
|
|
179
|
-
summary: "the Kimi session started but did not finish initializing in time.",
|
|
180
|
-
nextStep: "Run `/kimi:setup` to verify local Kimi configuration and retry.",
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
if (error.code === "RESPONSE_TIMEOUT") {
|
|
184
|
-
return {
|
|
185
|
-
kind: "response_timeout",
|
|
186
|
-
summary: "Kimi started and accepted the prompt but never returned a final response.",
|
|
187
|
-
nextStep: "Narrow the prompt or raise the budget (`--budget <dur>`, at most 24h). Check the job artifact (`result <jobId>`) for any captured partial output. Backgrounding does not extend the runtime budget.",
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (message.includes("timed out")) {
|
|
192
|
-
return {
|
|
193
|
-
kind: "timeout",
|
|
194
|
-
summary: "the Kimi runtime did not become ready within the expected time budget.",
|
|
195
|
-
nextStep: "Run `/kimi:setup` to check local Kimi auth and network health, then retry.",
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
function mapAvailabilityCode(kind, commandType) {
|
|
201
|
-
return `${commandType.toUpperCase()}_KIMI_${kind.toUpperCase()}`;
|
|
202
|
-
}
|
|
203
|
-
function formatCommandLabel(commandType) {
|
|
204
|
-
return commandType.replaceAll("_", " ");
|
|
205
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import os from "node:os";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
export function resolveKimiHome(env, baseCwd = process.cwd()) {
|
|
4
|
-
const override = env.KIMI_CODE_HOME?.trim();
|
|
5
|
-
if (override) {
|
|
6
|
-
return path.resolve(baseCwd, override);
|
|
7
|
-
}
|
|
8
|
-
return path.join(os.homedir(), ".kimi-code");
|
|
9
|
-
}
|
|
10
|
-
export function kimiCodeConfigPath(kimiHome) {
|
|
11
|
-
return path.join(kimiHome, "config.toml");
|
|
12
|
-
}
|
|
13
|
-
export function resolveKimiCodeConfigPath(env, baseCwd = process.cwd()) {
|
|
14
|
-
return kimiCodeConfigPath(resolveKimiHome(env, baseCwd));
|
|
15
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/** Marker for a framed journal line that is not valid JSON. */
|
|
2
|
-
export const UNPARSEABLE_JOURNAL_LINE = Symbol("unparseable-journal-line");
|
|
3
|
-
/**
|
|
4
|
-
* kimi-code's append-log framing (appendLogStore.read/parseLine, identical at
|
|
5
|
-
* 2.4.0 and 2.7.3): one TextDecoder over the stream, split on "\n" only, strip
|
|
6
|
-
* ONE trailing "\r", skip only a zero-length line, else JSON.parse. A
|
|
7
|
-
* terminated line that fails to parse is corruption and wire replay stops
|
|
8
|
-
* there; an unparseable unterminated last line is dropped as truncated.
|
|
9
|
-
*/
|
|
10
|
-
export async function* kimiJournalRecords(chunks) {
|
|
11
|
-
const decoder = new TextDecoder();
|
|
12
|
-
let pending = "";
|
|
13
|
-
const frame = (raw, terminated) => {
|
|
14
|
-
const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
|
|
15
|
-
if (line.length === 0)
|
|
16
|
-
return undefined;
|
|
17
|
-
try {
|
|
18
|
-
return { line, parsed: JSON.parse(line), terminated };
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
return { line, parsed: UNPARSEABLE_JOURNAL_LINE, terminated };
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
for await (const chunk of chunks) {
|
|
25
|
-
pending += decoder.decode(chunk, { stream: true });
|
|
26
|
-
let newline = pending.indexOf("\n");
|
|
27
|
-
while (newline !== -1) {
|
|
28
|
-
const framed = frame(pending.slice(0, newline), true);
|
|
29
|
-
pending = pending.slice(newline + 1);
|
|
30
|
-
if (framed !== undefined)
|
|
31
|
-
yield framed;
|
|
32
|
-
newline = pending.indexOf("\n");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
pending += decoder.decode();
|
|
36
|
-
if (pending.length > 0) {
|
|
37
|
-
const framed = frame(pending, false);
|
|
38
|
-
if (framed !== undefined)
|
|
39
|
-
yield framed;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Exact kimi-code releases certified for native v2: one row per release.
|
|
3
|
-
*
|
|
4
|
-
* Certifying a release adds one row here (plus its evidence document, its
|
|
5
|
-
* tag-scan row and the hash-pinned host surfaces). Every version-gated branch
|
|
6
|
-
* in the runtime asks this table through `resolveKimiRelease` (directly or via
|
|
7
|
-
* `kimiReleaseHas`); none spells a version list of its own.
|
|
8
|
-
*
|
|
9
|
-
* Certification is by exact version string: upstream ships behavioural changes
|
|
10
|
-
* in patch releases, so a new release is certified for nothing until its row
|
|
11
|
-
* exists. `resolveKimiRelease` lets an unlisted plain 2.x borrow the argv
|
|
12
|
-
* mechanics of the highest row below it for read-only operations; it never
|
|
13
|
-
* borrows the hook schema, a swarm capability or a per-release relaxation.
|
|
14
|
-
*
|
|
15
|
-
* This module imports nothing. The per-tool-call hook and the config verifier
|
|
16
|
-
* load it, and neither may pull in the engine.
|
|
17
|
-
*/
|
|
18
|
-
// Rows share these arrays, so each is frozen: a mutated preset would change every row using it.
|
|
19
|
-
const preset = (...capabilities) => Object.freeze(capabilities);
|
|
20
|
-
const NONE = preset();
|
|
21
|
-
const HOOK_SCHEMA = preset("hook-schema");
|
|
22
|
-
const WEB = preset(...HOOK_SCHEMA, "web-preactivation");
|
|
23
|
-
const WEB_CANCEL = preset(...WEB, "print-cancels-plan");
|
|
24
|
-
const LOCAL = preset(...WEB_CANCEL, "local-environment", "agent-state");
|
|
25
|
-
const MODERN_WS = preset(...LOCAL, "modern-ws-control");
|
|
26
|
-
const BOUNDED = preset(...MODERN_WS, "bounded-swarm");
|
|
27
|
-
const JSON_READY = preset(...BOUNDED, "web-json-ready");
|
|
28
|
-
/** Ascending. Order is visible in error messages and in the exported version arrays. */
|
|
29
|
-
export const KIMI_V2_RELEASES = Object.freeze([
|
|
30
|
-
{ version: "0.42.0", commit: "6954d2c8", scope: "all", capabilities: NONE },
|
|
31
|
-
{ version: "0.43.0", commit: "ffa94fae", scope: "all", capabilities: NONE },
|
|
32
|
-
{ version: "0.43.1", commit: "75ac010b", scope: "all", capabilities: NONE },
|
|
33
|
-
{ version: "2.0.0", commit: "1b89e4b0", scope: "all", capabilities: HOOK_SCHEMA },
|
|
34
|
-
{ version: "2.0.1", commit: "caf7d4e2", scope: "all", capabilities: HOOK_SCHEMA },
|
|
35
|
-
{ version: "2.0.2", commit: "9d07f634", scope: "all", capabilities: HOOK_SCHEMA },
|
|
36
|
-
{ version: "2.1.0", commit: "52437299", scope: "all", capabilities: HOOK_SCHEMA },
|
|
37
|
-
{ version: "2.1.1", commit: "f67e6398", scope: "all", capabilities: HOOK_SCHEMA },
|
|
38
|
-
{ version: "2.2.0", commit: "472192c3", scope: "all", capabilities: HOOK_SCHEMA },
|
|
39
|
-
{ version: "2.3.0", commit: "b5e28fd6", scope: "all", capabilities: HOOK_SCHEMA },
|
|
40
|
-
{ version: "2.3.1", commit: "684bae9e", scope: "all", capabilities: HOOK_SCHEMA },
|
|
41
|
-
{ version: "2.3.2", commit: "b8dd3a13", scope: "all", capabilities: WEB },
|
|
42
|
-
{ version: "2.3.3", commit: "ec495f0c", scope: "all", capabilities: WEB },
|
|
43
|
-
{ version: "2.4.0", commit: "f26e4d91", scope: "all", capabilities: WEB_CANCEL },
|
|
44
|
-
{ version: "2.4.1", commit: "2c73f3f5", scope: "all", capabilities: WEB_CANCEL },
|
|
45
|
-
{ version: "2.5.0", commit: "41c34143", scope: "all", capabilities: LOCAL },
|
|
46
|
-
{ version: "2.5.1", commit: "1b02030d", scope: "all", capabilities: LOCAL },
|
|
47
|
-
{ version: "2.5.2", commit: "1c142a00", scope: "all", capabilities: LOCAL },
|
|
48
|
-
{ version: "2.5.3", commit: "5af9942e", scope: "all", capabilities: LOCAL },
|
|
49
|
-
// Swarm is refused on 2.6.0; its web flags support candidate integration only.
|
|
50
|
-
{ version: "2.6.0", commit: "740d6c0b", scope: "non-swarm", capabilities: MODERN_WS },
|
|
51
|
-
{ version: "2.6.2", commit: "6a8493df", scope: "all", capabilities: BOUNDED },
|
|
52
|
-
{ version: "2.6.3", commit: "b0de2fbd", scope: "all", capabilities: BOUNDED },
|
|
53
|
-
{ version: "2.7.2", commit: "56145f84", scope: "all", capabilities: JSON_READY },
|
|
54
|
-
{ version: "2.7.3", commit: "a8f643ad", scope: "all", capabilities: JSON_READY },
|
|
55
|
-
]);
|
|
56
|
-
/**
|
|
57
|
-
* Mechanics an uncertified release borrows from its row: only the fresh-print
|
|
58
|
-
* argv (`--environment local`, which can only narrow where it runs).
|
|
59
|
-
* Everything else (hook schema, swarm, web lifecycle, and every per-release
|
|
60
|
-
* relaxation) stays exact, because each rests on behaviour proven for that
|
|
61
|
-
* release only.
|
|
62
|
-
*/
|
|
63
|
-
const BORROWABLE_CAPABILITIES = new Set([
|
|
64
|
-
"local-environment",
|
|
65
|
-
]);
|
|
66
|
-
const PLAIN_VERSION = /^(\d+)\.(\d+)\.(\d+)$/;
|
|
67
|
-
function versionTriple(version) {
|
|
68
|
-
const match = PLAIN_VERSION.exec(version);
|
|
69
|
-
return match === null ? null : [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
70
|
-
}
|
|
71
|
-
function compareTriples(left, right) {
|
|
72
|
-
for (let index = 0; index < 3; index += 1) {
|
|
73
|
-
if (left[index] !== right[index])
|
|
74
|
-
return left[index] - right[index];
|
|
75
|
-
}
|
|
76
|
-
return 0;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* The single answer to "which row's mechanics apply, and is it certified".
|
|
80
|
-
* An exact row resolves to itself. Otherwise only a plain `2.y.z` newer than
|
|
81
|
-
* the lowest 2.x row borrows the highest row at or below it; pre-release and
|
|
82
|
-
* build-suffixed versions, other majors and `strict` resolve to null.
|
|
83
|
-
*/
|
|
84
|
-
export function resolveKimiRelease(version, options = {}) {
|
|
85
|
-
if (typeof version !== "string")
|
|
86
|
-
return null;
|
|
87
|
-
const exact = KIMI_V2_RELEASES.find((release) => release.version === version);
|
|
88
|
-
if (exact !== undefined)
|
|
89
|
-
return { release: exact, certified: true };
|
|
90
|
-
if (options.strict === true)
|
|
91
|
-
return null;
|
|
92
|
-
const triple = versionTriple(version);
|
|
93
|
-
if (triple === null || triple[0] !== 2)
|
|
94
|
-
return null;
|
|
95
|
-
let borrowed;
|
|
96
|
-
let lowest;
|
|
97
|
-
for (const release of KIMI_V2_RELEASES) {
|
|
98
|
-
const row = versionTriple(release.version);
|
|
99
|
-
if (row === null || row[0] !== 2)
|
|
100
|
-
continue;
|
|
101
|
-
if (lowest === undefined || compareTriples(row, lowest) < 0)
|
|
102
|
-
lowest = row;
|
|
103
|
-
if (compareTriples(row, triple) <= 0 &&
|
|
104
|
-
(borrowed === undefined || compareTriples(row, versionTriple(borrowed.version)) > 0)) {
|
|
105
|
-
borrowed = release;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (lowest === undefined || borrowed === undefined || compareTriples(triple, lowest) <= 0)
|
|
109
|
-
return null;
|
|
110
|
-
return { release: borrowed, certified: false };
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* True when the version's resolved row has the capability: exact rows report
|
|
114
|
-
* their own list; an uncertified version only the borrowable mechanics.
|
|
115
|
-
*/
|
|
116
|
-
export function kimiReleaseHas(version, capability) {
|
|
117
|
-
const resolved = resolveKimiRelease(version);
|
|
118
|
-
if (resolved === null)
|
|
119
|
-
return false;
|
|
120
|
-
if (!resolved.certified && !BORROWABLE_CAPABILITIES.has(capability))
|
|
121
|
-
return false;
|
|
122
|
-
return resolved.release.capabilities.includes(capability);
|
|
123
|
-
}
|
|
124
|
-
/** True only when this exact certified row has the capability; borrowed rows never qualify. */
|
|
125
|
-
export function kimiCertifiedReleaseHas(version, capability) {
|
|
126
|
-
const resolved = resolveKimiRelease(version);
|
|
127
|
-
return resolved !== null && resolved.certified && resolved.release.capabilities.includes(capability);
|
|
128
|
-
}
|
|
129
|
-
/** Exact versions with the capability, ascending. */
|
|
130
|
-
export function kimiVersionsWith(capability) {
|
|
131
|
-
return KIMI_V2_RELEASES
|
|
132
|
-
.filter((release) => release.capabilities.includes(capability))
|
|
133
|
-
.map((release) => release.version);
|
|
134
|
-
}
|
|
135
|
-
/** Exact versions certified with the scope, ascending. */
|
|
136
|
-
export function kimiVersionsInScope(scope) {
|
|
137
|
-
return KIMI_V2_RELEASES.filter((release) => release.scope === scope).map((release) => release.version);
|
|
138
|
-
}
|
|
139
|
-
/** "a, b, c or d": the wording refusal and setup messages use to offer a choice of versions. */
|
|
140
|
-
export function formatVersionChoice(versions) {
|
|
141
|
-
if (versions.length <= 1)
|
|
142
|
-
return versions.join("");
|
|
143
|
-
return `${versions.slice(0, -1).join(", ")} or ${versions.at(-1)}`;
|
|
144
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// Per-command response budgets leave room for thinking-capable workflows;
|
|
2
|
-
// per-run effort is only a request. Ask/review default to 30 minutes and rescue
|
|
3
|
-
// to 45 minutes for repo-wide work. Review-gate stays at 8 seconds because it
|
|
4
|
-
// runs inside Claude Code's Stop hook and requests thinking off by default;
|
|
5
|
-
// KIMI_PLUGIN_CC_REVIEW_GATE_THINKING can override that request.
|
|
6
|
-
/** Ask budget. Conversational; thinking-on free-form reasoning. */
|
|
7
|
-
export const KIMI_ASK_PROMPT_TIMEOUT_MS = 1_800_000; // 30 minutes
|
|
8
|
-
/** Review/challenge budget. Thinking-on single-turn analysis over the workspace. */
|
|
9
|
-
export const KIMI_REVIEW_PROMPT_TIMEOUT_MS = 1_800_000;
|
|
10
|
-
/** Rescue budget. Thinking-on multi-step apply/test/verify loops. */
|
|
11
|
-
export const KIMI_RESCUE_PROMPT_TIMEOUT_MS = 2_700_000; // 45 minutes
|
|
12
|
-
/**
|
|
13
|
-
* Pursue (autonomous goal mode) DEFAULT wall-clock ceiling when the user
|
|
14
|
-
* passes no `--budget`. This is the ONLY hard bound on an autonomous goal —
|
|
15
|
-
* headless goal create sets no token/turn budget, and the managed hook denies
|
|
16
|
-
* SetGoalBudget. The same duration as
|
|
17
|
-
* the single-turn rescue default, but a safety ceiling rather than a patience
|
|
18
|
-
* knob. Deliberately finite. Overridable per-job via `--budget` (parsed to ms in
|
|
19
|
-
* parsePursueArgs). See runtime/commands/pursue.ts and docs/safety.md.
|
|
20
|
-
*/
|
|
21
|
-
export const KIMI_PURSUE_DEFAULT_BUDGET_MS = 2_700_000; // 45 minutes
|
|
22
|
-
/**
|
|
23
|
-
* Swarm (read-only parallel fan-out) DEFAULT wall-clock ceiling when the user
|
|
24
|
-
* passes no `--budget`. Read-only swarm opens no write surface, so the only new
|
|
25
|
-
* risk is cost/runaway from repeated model work. This AbortController bounds
|
|
26
|
-
* the whole job; `--cap` remains a soft lifetime-count hint. A bounded-swarm release also
|
|
27
|
-
* bounds wave cardinality and prevents child timeouts from overlapping waves;
|
|
28
|
-
* a requested concurrency of one runs a direct worker. Sized like the single-turn
|
|
29
|
-
* review budget — a swarm fans review work out in parallel within one process,
|
|
30
|
-
* so 30m of wall-clock is generous headroom. Overridable per-job via `--budget`
|
|
31
|
-
* (parsed to ms in parseSwarmArgs). See runtime/commands/swarm.ts and
|
|
32
|
-
* docs/safety.md.
|
|
33
|
-
*/
|
|
34
|
-
export const KIMI_SWARM_DEFAULT_BUDGET_MS = 1_800_000; // 30 minutes
|
|
35
|
-
/**
|
|
36
|
-
* Review-gate budget. Fires inside Claude Code's Stop hook so any value
|
|
37
|
-
* above the user's perceptible wait makes the gate feel broken.
|
|
38
|
-
*
|
|
39
|
-
* The gate requests off through KIMI_MODEL_THINKING_EFFORT by default;
|
|
40
|
-
* KIMI_PLUGIN_CC_REVIEW_GATE_THINKING can inherit or request another effort.
|
|
41
|
-
* BYO/non-trait-driven providers and always-thinking models can ignore it.
|
|
42
|
-
* The 8s timeout remains fail-open; a request never guarantees completion.
|
|
43
|
-
* Hook-escape findings annotate the result and never block or change job outcome.
|
|
44
|
-
* See docs/safety.md.
|
|
45
|
-
*/
|
|
46
|
-
export const KIMI_REVIEW_GATE_TIMEOUT_MS = 8_000;
|
|
47
|
-
export function isTimeoutCode(code) {
|
|
48
|
-
return (code === "TIMEOUT" ||
|
|
49
|
-
code === "STARTUP_TIMEOUT" ||
|
|
50
|
-
code === "INITIALIZE_TIMEOUT" ||
|
|
51
|
-
code === "RESPONSE_TIMEOUT");
|
|
52
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// Probe the installed kimi-code CLI version and check it against the
|
|
2
|
-
// range kimi-plugin-cc has been tested against.
|
|
3
|
-
//
|
|
4
|
-
// Setup probes the installed command and warns outside the tested range;
|
|
5
|
-
// model jobs probe the exact command + prefix tuple to build a fail-closed
|
|
6
|
-
// execution plan before spawn. The latter is the durable engine-provenance
|
|
7
|
-
// gate: an operation outside its certified engine/version range is refused
|
|
8
|
-
// rather than guessed.
|
|
9
|
-
//
|
|
10
|
-
// What this module is NOT:
|
|
11
|
-
//
|
|
12
|
-
// - Not, by itself, the policy decision. setup still warns; the execution-
|
|
13
|
-
// plan layer (`kimi-engine.ts`) decides whether an exact result is certified.
|
|
14
|
-
// - Not a license to infer historical versions. Old job rows remain unknown
|
|
15
|
-
// unless their saved logs contain positive evidence.
|
|
16
|
-
import { spawn } from "node:child_process";
|
|
17
|
-
import { resolveKimiRelease } from "./kimi-releases.js";
|
|
18
|
-
const KIMI_VERSION_PROBE_TIMEOUT_MS = 5_000;
|
|
19
|
-
/**
|
|
20
|
-
* Legacy-v1 kimi-code minors tested for plugin use. Membership is by
|
|
21
|
-
* `{major, minor}`; every patch within a listed minor is accepted.
|
|
22
|
-
*
|
|
23
|
-
* The table is 0.1 through 0.41 and never gains 0.42, which removed legacy v1.
|
|
24
|
-
* Exact native-v2 certification lives in `kimi-releases.ts` (rows) and
|
|
25
|
-
* `kimi-engine.ts` (per operation).
|
|
26
|
-
*/
|
|
27
|
-
const LEGACY_V1_LAST_MINOR = 41;
|
|
28
|
-
export const KIMI_TESTED_MINORS = Array.from({ length: LEGACY_V1_LAST_MINOR }, (_, index) => ({ major: 0, minor: index + 1 }));
|
|
29
|
-
/**
|
|
30
|
-
* Spawn `<kimi-bin> --version` and parse the output. Never throws;
|
|
31
|
-
* failures resolve to `{kind: "failed", reason}` so callers can decide
|
|
32
|
-
* the policy. The kimi binary path defaults to bare `kimi` (PATH
|
|
33
|
-
* lookup); callers that need an explicit absolute path should pass it.
|
|
34
|
-
*/
|
|
35
|
-
export async function probeKimiVersion(options) {
|
|
36
|
-
const bin = options.kimiBin ?? "kimi";
|
|
37
|
-
const args = [...(options.prefixArgs ?? []), "--version"];
|
|
38
|
-
const timeoutMs = options.timeoutMs ?? KIMI_VERSION_PROBE_TIMEOUT_MS;
|
|
39
|
-
return await new Promise((resolve) => {
|
|
40
|
-
let settled = false;
|
|
41
|
-
const settle = (result) => {
|
|
42
|
-
if (settled)
|
|
43
|
-
return;
|
|
44
|
-
settled = true;
|
|
45
|
-
resolve(result);
|
|
46
|
-
};
|
|
47
|
-
let child;
|
|
48
|
-
try {
|
|
49
|
-
child = spawn(bin, args, {
|
|
50
|
-
cwd: options.cwd,
|
|
51
|
-
env: options.env,
|
|
52
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
settle({
|
|
57
|
-
kind: "failed",
|
|
58
|
-
reason: `spawn failed: ${err.message}`,
|
|
59
|
-
});
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
let stdout = "";
|
|
63
|
-
let stderr = "";
|
|
64
|
-
child.stdout.setEncoding("utf8");
|
|
65
|
-
child.stderr.setEncoding("utf8");
|
|
66
|
-
child.stdout.on("data", (chunk) => {
|
|
67
|
-
stdout += chunk;
|
|
68
|
-
});
|
|
69
|
-
child.stderr.on("data", (chunk) => {
|
|
70
|
-
stderr += chunk;
|
|
71
|
-
});
|
|
72
|
-
const timer = setTimeout(() => {
|
|
73
|
-
try {
|
|
74
|
-
child.kill("SIGTERM");
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
}
|
|
78
|
-
settle({
|
|
79
|
-
kind: "failed",
|
|
80
|
-
reason: `\`${[bin, ...args].join(" ")}\` timed out after ${timeoutMs}ms`,
|
|
81
|
-
});
|
|
82
|
-
}, timeoutMs);
|
|
83
|
-
child.on("error", (err) => {
|
|
84
|
-
clearTimeout(timer);
|
|
85
|
-
settle({
|
|
86
|
-
kind: "failed",
|
|
87
|
-
reason: `spawn error: ${err.message}`,
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
child.on("close", (code) => {
|
|
91
|
-
clearTimeout(timer);
|
|
92
|
-
if (code !== 0) {
|
|
93
|
-
const detail = stderr.trim() !== "" ? stderr.trim() : `exit ${code}`;
|
|
94
|
-
settle({
|
|
95
|
-
kind: "failed",
|
|
96
|
-
reason: `\`${[bin, ...args].join(" ")}\` failed: ${detail}`,
|
|
97
|
-
});
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const parsed = parseVersionLine(stdout);
|
|
101
|
-
if (parsed === undefined) {
|
|
102
|
-
settle({
|
|
103
|
-
kind: "failed",
|
|
104
|
-
reason: `could not parse \`${[bin, ...args].join(" ")}\` output: ${JSON.stringify(stdout.slice(0, 80))}`,
|
|
105
|
-
});
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
settle({
|
|
109
|
-
kind: "ok",
|
|
110
|
-
version: parsed.raw,
|
|
111
|
-
major: parsed.major,
|
|
112
|
-
minor: parsed.minor,
|
|
113
|
-
patch: parsed.patch,
|
|
114
|
-
inTestedRange: isInTestedRange(parsed.major, parsed.minor),
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Parse a `kimi --version` stdout into a structured version. Accepts
|
|
121
|
-
* bare semver (`0.2.0`), `v`-prefixed (`v0.2.0`), and trailing
|
|
122
|
-
* pre-release / build metadata (`0.2.0-beta.1`, `0.2.0+sha.abc`). The
|
|
123
|
-
* major/minor/patch numbers are the leading three components only —
|
|
124
|
-
* pre-release / build metadata is preserved in `raw` but doesn't
|
|
125
|
-
* affect the tested-range check.
|
|
126
|
-
*
|
|
127
|
-
* Returns undefined when the first nonempty line doesn't look like a version.
|
|
128
|
-
*/
|
|
129
|
-
export function parseVersionLine(stdout) {
|
|
130
|
-
const firstLine = stdout.split(/\r?\n/).find((line) => line.trim().length > 0);
|
|
131
|
-
if (firstLine === undefined)
|
|
132
|
-
return undefined;
|
|
133
|
-
const trimmed = firstLine.trim().replace(/^v/, "");
|
|
134
|
-
const match = trimmed.match(/^(\d+)\.(\d+)\.(\d+)(?:[-+][0-9A-Za-z.-]+)?$/);
|
|
135
|
-
if (match === null)
|
|
136
|
-
return undefined;
|
|
137
|
-
return {
|
|
138
|
-
raw: trimmed,
|
|
139
|
-
major: Number.parseInt(match[1], 10),
|
|
140
|
-
minor: Number.parseInt(match[2], 10),
|
|
141
|
-
patch: Number.parseInt(match[3], 10),
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
export function isInTestedRange(major, minor) {
|
|
145
|
-
return KIMI_TESTED_MINORS.some((entry) => entry.major === major && entry.minor === minor);
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* The newest `{major, minor}` in the legacy-v1 tested set. Native-v2-certified
|
|
149
|
-
* versions lie outside this table. Set membership already warns for anything
|
|
150
|
-
* outside the legacy range; this upper bound lets the warning distinguish a
|
|
151
|
-
* newer, unverified legacy release from a below/gap version.
|
|
152
|
-
*/
|
|
153
|
-
export function maxTestedMinor() {
|
|
154
|
-
return KIMI_TESTED_MINORS.reduce((max, entry) => entry.major > max.major || (entry.major === max.major && entry.minor > max.minor)
|
|
155
|
-
? entry
|
|
156
|
-
: max);
|
|
157
|
-
}
|
|
158
|
-
function compareVersions(a, b) {
|
|
159
|
-
const pa = a.split(".").map((part) => Number.parseInt(part, 10));
|
|
160
|
-
const pb = b.split(".").map((part) => Number.parseInt(part, 10));
|
|
161
|
-
for (let i = 0; i < 3; i += 1) {
|
|
162
|
-
const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
163
|
-
if (diff !== 0)
|
|
164
|
-
return diff;
|
|
165
|
-
}
|
|
166
|
-
return 0;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Format a user-facing warning line for an out-of-range version probe.
|
|
170
|
-
* Setup itself may complete. An uncertified 2.x runs read-only operations
|
|
171
|
-
* with a warning; everything else refuses at the execution-plan gate until the
|
|
172
|
-
* operator installs or selects a certified binary or updates the plugin.
|
|
173
|
-
* `nativeV2Certified` is the exact native-v2 table; both engines are named so
|
|
174
|
-
* the newest certified version is not misreported as the legacy-v1 bound.
|
|
175
|
-
*/
|
|
176
|
-
export function formatVersionOutOfRangeWarning(probe, pluginVersion, nativeV2Certified = []) {
|
|
177
|
-
const tested = KIMI_TESTED_MINORS.map((entry) => `${entry.major}.${entry.minor}.x`).join(", ");
|
|
178
|
-
const max = maxTestedMinor();
|
|
179
|
-
const newestNative = [...nativeV2Certified].sort(compareVersions).at(-1);
|
|
180
|
-
const probeRaw = `${probe.major}.${probe.minor}.${probe.patch}`;
|
|
181
|
-
const aboveMax = newestNative !== undefined
|
|
182
|
-
? compareVersions(probeRaw, newestNative) > 0
|
|
183
|
-
: probe.major > max.major || (probe.major === max.major && probe.minor > max.minor);
|
|
184
|
-
const certified = nativeV2Certified.length > 0
|
|
185
|
-
? `legacy-v1 ${tested}; native-v2 exact ${nativeV2Certified.join(", ")}`
|
|
186
|
-
: tested;
|
|
187
|
-
const lines = [
|
|
188
|
-
`WARNING: kimi-code version ${probe.version} is outside the versions kimi-plugin-cc ${pluginVersion} certifies (${certified}).`,
|
|
189
|
-
];
|
|
190
|
-
if (aboveMax) {
|
|
191
|
-
// Commonly out-of-band auto-upgrade drift past the last certification.
|
|
192
|
-
lines.push(` This is NEWER than the newest certified version (${newestNative ?? `${max.major}.${max.minor}.x`}) and is not yet certified for model execution.`);
|
|
193
|
-
}
|
|
194
|
-
lines.push(resolveKimiRelease(probeRaw)?.certified === false
|
|
195
|
-
? ` Read-only commands (ask, review, challenge, review gate) run on it with a warning; rescue, pursue and swarm refuse until the version is certified.`
|
|
196
|
-
: ` Setup can complete, but model-spawning commands will refuse before Kimi starts rather than run an unreviewed engine/version route.`, ` Run setup --install-kimi to give the plugin its own copy of the newest certified kimi-code, update kimi-plugin-cc to a release that certifies this version, or point KIMI_PLUGIN_CC_KIMI_BIN at a certified binary.`, ` KIMI_PLUGIN_CC_SKIP_VERSION_PROBE is a test/smoke seam, not a production compatibility override.`);
|
|
197
|
-
return lines.join("\n");
|
|
198
|
-
}
|