kimi-plugin-cc 2.0.7 → 2.0.8

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.
Files changed (64) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +29 -0
  4. package/README.md +21 -5
  5. package/agents/kimi-ask.md +3 -0
  6. package/agents/kimi-challenge.md +3 -1
  7. package/agents/kimi-rescue.md +3 -0
  8. package/agents/kimi-review.md +3 -1
  9. package/commands/ask.md +6 -2
  10. package/commands/challenge.md +6 -2
  11. package/commands/rescue.md +6 -2
  12. package/commands/review.md +6 -2
  13. package/dist/cli-client.js +29 -12
  14. package/dist/commands/ask.js +9 -4
  15. package/dist/commands/cli-helpers.js +31 -0
  16. package/dist/commands/pursue.js +2 -1
  17. package/dist/commands/repair-sessions.js +2 -1
  18. package/dist/commands/replay.js +3 -2
  19. package/dist/commands/rescue.js +10 -3
  20. package/dist/commands/result.js +4 -0
  21. package/dist/commands/review.js +6 -4
  22. package/dist/commands/setup.js +2 -1
  23. package/dist/commands/swarm.js +4 -2
  24. package/dist/companion.js +6 -0
  25. package/dist/help.js +40 -0
  26. package/dist/hooks/config-safety.js +3 -2
  27. package/dist/job-store.js +8 -3
  28. package/dist/jobs.js +7 -3
  29. package/dist/kimi-engine.js +1 -0
  30. package/dist/kimi-errors.js +35 -1
  31. package/dist/kimi-timeouts.js +7 -7
  32. package/dist/parsing.js +87 -13
  33. package/dist/render.js +19 -1
  34. package/dist/version.js +1 -1
  35. package/docs/migration.md +3 -3
  36. package/docs/registry-releases.md +14 -1
  37. package/package.json +2 -2
  38. package/plugins/kimi-codex/.codex-plugin/plugin.json +1 -1
  39. package/plugins/kimi-codex/dist/cli-client.js +29 -12
  40. package/plugins/kimi-codex/dist/commands/ask.js +9 -4
  41. package/plugins/kimi-codex/dist/commands/cli-helpers.js +31 -0
  42. package/plugins/kimi-codex/dist/commands/pursue.js +2 -1
  43. package/plugins/kimi-codex/dist/commands/repair-sessions.js +2 -1
  44. package/plugins/kimi-codex/dist/commands/replay.js +3 -2
  45. package/plugins/kimi-codex/dist/commands/rescue.js +10 -3
  46. package/plugins/kimi-codex/dist/commands/result.js +4 -0
  47. package/plugins/kimi-codex/dist/commands/review.js +6 -4
  48. package/plugins/kimi-codex/dist/commands/setup.js +2 -1
  49. package/plugins/kimi-codex/dist/commands/swarm.js +4 -2
  50. package/plugins/kimi-codex/dist/companion.js +6 -0
  51. package/plugins/kimi-codex/dist/help.js +40 -0
  52. package/plugins/kimi-codex/dist/hooks/config-safety.js +3 -2
  53. package/plugins/kimi-codex/dist/job-store.js +8 -3
  54. package/plugins/kimi-codex/dist/jobs.js +7 -3
  55. package/plugins/kimi-codex/dist/kimi-engine.js +1 -0
  56. package/plugins/kimi-codex/dist/kimi-errors.js +35 -1
  57. package/plugins/kimi-codex/dist/kimi-timeouts.js +7 -7
  58. package/plugins/kimi-codex/dist/parsing.js +87 -13
  59. package/plugins/kimi-codex/dist/render.js +19 -1
  60. package/plugins/kimi-codex/dist/version.js +1 -1
  61. package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +3 -1
  62. package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +2 -1
  63. package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +3 -1
  64. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +3 -2
@@ -17,7 +17,7 @@ import { renderManagedJobOutput, writeArtifact } from "../render.js";
17
17
  import { RuntimeError } from "../errors.js";
18
18
  import { resolveRepoIdentity } from "../git.js";
19
19
  import { hookRefusalDetails, hookRefusalRetryProtocol, maybeWarnHookMissing, verifyHookInstalled, } from "../hooks/install.js";
20
- import { assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing } from "./cli-helpers.js";
20
+ import { captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing } from "./cli-helpers.js";
21
21
  import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
22
22
  // v1.0 cutover note (PR 2):
23
23
  //
@@ -81,6 +81,7 @@ export async function runReview(argv, context, commandType) {
81
81
  model: parsed.model ?? null,
82
82
  thinking: parsed.thinking ?? null,
83
83
  background: false,
84
+ budget_ms: parsed.budgetMs ?? null,
84
85
  pid: process.pid,
85
86
  kimi_pid: null,
86
87
  status: "running",
@@ -113,7 +114,7 @@ export async function runReview(argv, context, commandType) {
113
114
  model: parsed.model,
114
115
  logPath,
115
116
  signal: handlers.signal,
116
- }, KIMI_REVIEW_PROMPT_TIMEOUT_MS, `${commandType}.prompt`);
117
+ }, job.budget_ms ?? KIMI_REVIEW_PROMPT_TIMEOUT_MS, `${commandType}.prompt`);
117
118
  store.updateRunningJob(job.job_id, observedExecutionFields(result));
118
119
  if (handlers.cancelling) {
119
120
  throw new RuntimeError(cancel.errorCodes.cancelled, cancel.cancelMessages.afterPrompt, `${commandType}.runtime`);
@@ -163,8 +164,9 @@ export async function runReview(argv, context, commandType) {
163
164
  await markJobCancelled(store, paths, job, cancel.cancelledSummary, cancelledError);
164
165
  throw cancelledError;
165
166
  }
166
- const classified = classifyManagedCommandFailure(error, commandType, job.job_id);
167
- await markJobFailed(store, paths, job, classified, cancel.failedSummary);
167
+ const classified = classifyManagedCommandFailure(error, commandType, job.job_id, { background: job.background, budgetMs: job.budget_ms ?? KIMI_REVIEW_PROMPT_TIMEOUT_MS });
168
+ const partialOutput = captureTimeoutPartialOutput(classified, store, job);
169
+ await markJobFailed(store, paths, job, classified, cancel.failedSummary, { partialOutput });
168
170
  throw classified;
169
171
  }
170
172
  finally {
@@ -1,3 +1,4 @@
1
+ import { SETUP_SUPPORTED_FLAGS } from "../parsing.js";
1
2
  // Managed-block installer for the kimi-code PreToolUse hook.
2
3
  //
3
4
  // Replaces the v0.4 Wire-based setup probe. In v1.0 the load-bearing
@@ -127,7 +128,7 @@ function parseArgs(argv) {
127
128
  disableReviewGate = true;
128
129
  break;
129
130
  default:
130
- throw new RuntimeError("INVALID_ARGS", `Unknown setup flag ${token}. Supported flags: --check, --uninstall, --all (with --uninstall), --enable-review-gate, --disable-review-gate.`, "setup.parse");
131
+ throw new RuntimeError("INVALID_ARGS", `Unknown setup flag ${token}. Supported flags: ${SETUP_SUPPORTED_FLAGS}.`, "setup.parse");
131
132
  }
132
133
  }
133
134
  if (enableReviewGate && disableReviewGate) {
@@ -210,6 +210,7 @@ async function runReadSwarm(parsed, objective, context) {
210
210
  model: parsed.model ?? null,
211
211
  thinking: parsed.thinking ?? null,
212
212
  background: false,
213
+ budget_ms: parsed.budgetMs ?? KIMI_SWARM_DEFAULT_BUDGET_MS,
213
214
  pid: process.pid,
214
215
  kimi_pid: null,
215
216
  status: "running",
@@ -235,7 +236,7 @@ async function runReadSwarm(parsed, objective, context) {
235
236
  await markJobFailed(store, paths, job, classified, "Swarm failed.", { phase: "failed" });
236
237
  throw classified;
237
238
  }
238
- const completed = await executeSwarmJob(job.job_id, prompt, objective, parsed.budgetMs ?? KIMI_SWARM_DEFAULT_BUDGET_MS, resolveSwarmMaxConcurrency(parsed.maxConcurrency), context);
239
+ const completed = await executeSwarmJob(job.job_id, prompt, objective, job.budget_ms, resolveSwarmMaxConcurrency(parsed.maxConcurrency), context);
239
240
  if (!completed.final_output_path) {
240
241
  throw new RuntimeError("SWARM_RESULT_MISSING", "Swarm finished without a rendered result.", "swarm.result");
241
242
  }
@@ -308,6 +309,7 @@ async function runWriteSwarm(parsed, objective, context) {
308
309
  model: parsed.model ?? null,
309
310
  thinking: parsed.thinking ?? null,
310
311
  background: false,
312
+ budget_ms: parsed.budgetMs ?? KIMI_SWARM_DEFAULT_BUDGET_MS,
311
313
  pid: process.pid,
312
314
  kimi_pid: null,
313
315
  status: "running",
@@ -335,7 +337,7 @@ async function runWriteSwarm(parsed, objective, context) {
335
337
  });
336
338
  throw classified;
337
339
  }
338
- const completed = await executeSwarmJob(job.job_id, prompt, objective, parsed.budgetMs ?? KIMI_SWARM_DEFAULT_BUDGET_MS, resolveSwarmWriteMaxConcurrency(parsed.maxConcurrency), context, { spawnCwd: worktreePath, workspaceRoot: worktreePath });
340
+ const completed = await executeSwarmJob(job.job_id, prompt, objective, job.budget_ms, resolveSwarmWriteMaxConcurrency(parsed.maxConcurrency), context, { spawnCwd: worktreePath, workspaceRoot: worktreePath });
339
341
  if (!completed.final_output_path) {
340
342
  throw new RuntimeError("SWARM_RESULT_MISSING", "Swarm (write) finished without a rendered result.", "swarm.result");
341
343
  }
package/dist/companion.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { companionHelp } from "./help.js";
1
2
  import { runAsk } from "./commands/ask.js";
2
3
  import { runModelInventory } from "./commands/models.js";
3
4
  import { runCancel } from "./commands/cancel.js";
@@ -15,6 +16,11 @@ import { runWorker } from "./commands/worker.js";
15
16
  import { formatError, RuntimeError } from "./errors.js";
16
17
  import { resolveKimiHome } from "./kimi-home.js";
17
18
  async function main(argv) {
19
+ const help = companionHelp(argv);
20
+ if (help !== undefined) {
21
+ process.stdout.write(`${help}\n`);
22
+ return;
23
+ }
18
24
  const [command, ...rest] = argv;
19
25
  const cwd = process.env.KIMI_PLUGIN_CC_WORKSPACE_CWD || process.cwd();
20
26
  const context = {
package/dist/help.js ADDED
@@ -0,0 +1,40 @@
1
+ import { hasHelpFlag, ASK_SUPPORTED_FLAGS, RESCUE_SUPPORTED_FLAGS, REVIEW_SUPPORTED_FLAGS, PURSUE_SUPPORTED_FLAGS, SWARM_SUPPORTED_FLAGS, JOB_LOOKUP_SUPPORTED_FLAGS, SETUP_SUPPORTED_FLAGS, REPAIR_SESSIONS_SUPPORTED_FLAGS, REPLAY_SUPPORTED_FLAGS, } from "./parsing.js";
2
+ const SUBCOMMANDS = "setup, review, task, ask, status, result, cancel, replay, repair-sessions";
3
+ const TASK_KINDS = "rescue, challenge, pursue, swarm";
4
+ /** Help is a dispatch-only, side-effect-free exception to normal argument parsing. */
5
+ export function companionHelp(argv) {
6
+ const [command, kind] = argv;
7
+ // Scan only the argument region: the subcommand (and a task kind) are
8
+ // positional names, not prose, so they must not end the flag region.
9
+ const argumentStart = command === "--help" || command === "-h" ? 0
10
+ : command === "task" && kind !== undefined && !kind.startsWith("-") ? 2
11
+ : 1;
12
+ if (!hasHelpFlag(argv.slice(argumentStart)))
13
+ return undefined;
14
+ const suffix = " Use --help or -h among the leading flags (before any prompt text or --) to show this usage.";
15
+ const usage = (name, positionals, flags, description) => `Usage: companion.sh ${name}${positionals ? ` ${positionals}` : ""}. ${description} Supported flags: ${flags}.${suffix}`;
16
+ switch (command) {
17
+ case "--help":
18
+ case "-h":
19
+ return `Usage: companion.sh <subcommand> [arguments]. Subcommands: ${SUBCOMMANDS}. Use <subcommand> --help for usage.`;
20
+ case "task":
21
+ switch (kind) {
22
+ case "rescue": return usage("task rescue", "[options] [--] <task>", RESCUE_SUPPORTED_FLAGS, "Write-capable task; default budget 45m. Backgrounding does not extend the budget.");
23
+ case "challenge": return usage("task challenge", "[options] [--] [focus]", REVIEW_SUPPORTED_FLAGS, "Read-only challenge; default budget 30m. Foreground-only (no --background/--wait).");
24
+ case "pursue": return usage("task pursue", "[options] [--] <objective>", PURSUE_SUPPORTED_FLAGS, "Autonomous goal; default budget 45m. Runtime foreground-only.");
25
+ case "swarm": return usage("task swarm", "[options] [--] <objective>", SWARM_SUPPORTED_FLAGS, "Parallel task; default budget 30m. Runtime foreground-only; --write produces a patch.");
26
+ default: return `Usage: companion.sh task <kind> [arguments]. Task kinds: ${TASK_KINDS}. Use task <kind> --help for usage.`;
27
+ }
28
+ case "ask": return usage(command, "[options] [--] [prompt]", ASK_SUPPORTED_FLAGS, "Read-only question; default budget 30m. Backgrounding does not extend the budget.");
29
+ case "review": return usage(command, "[options] [--] [focus]", REVIEW_SUPPORTED_FLAGS, "Read-only review; default budget 30m. Foreground-only (no --background/--wait).");
30
+ case "setup": return usage(command, "[options]", SETUP_SUPPORTED_FLAGS, "Install, check, or remove this host's managed hook, or list configured models.");
31
+ case "status":
32
+ case "result":
33
+ case "cancel":
34
+ return usage(command, "[job-id] [options]", JOB_LOOKUP_SUPPORTED_FLAGS, command === "status" ? "Show job state as JSON." : command === "result" ? "Read a terminal artifact, optionally in a JSON envelope." : "Cancel a running job; without an id, target the repository's latest running job.");
35
+ case "replay": return usage(command, "<job-id>", REPLAY_SUPPORTED_FLAGS, "Replay a completed job's persisted stream log.");
36
+ case "repair-sessions": return usage(command, "[options]", REPAIR_SESSIONS_SUPPORTED_FLAGS, "Preview session metadata repair; --apply writes, --all selects all host-owned repositories.");
37
+ case "worker": return "Usage: companion.sh worker <ask|rescue> <job-id>. Internal detached-worker entry point; launched by ask/rescue, not manually.";
38
+ default: return undefined;
39
+ }
40
+ }
@@ -585,14 +585,15 @@ function validateVersionSensitiveEvents(events, version) {
585
585
  return invalidHookSet(`version-sensitive event ${JSON.stringify(first.event)} requires a verified kimi-code version`, first.entry, first.line);
586
586
  }
587
587
  // Exact schemas reviewed at 2.0.0 (1b89e4b0), 2.0.1 (caf7d4e2),
588
- // 2.0.2 (9d07f634), 2.1.0 (52437299), and 2.1.1 (f67e6398):
588
+ // 2.0.2 (9d07f634), 2.1.0 (52437299), 2.1.1 (f67e6398) and 2.2.0 (472192c3):
589
589
  // the additive events and HookDefSchema are unchanged. Require the full
590
590
  // version string AND matching components; no inferred 2.x compatibility.
591
591
  if (version.major === 2 && ((version.minor === 0 && ((version.version === "2.0.0" && version.patch === 0) ||
592
592
  (version.version === "2.0.1" && version.patch === 1) ||
593
593
  (version.version === "2.0.2" && version.patch === 2))) ||
594
594
  (version.minor === 1 && ((version.version === "2.1.0" && version.patch === 0) ||
595
- (version.version === "2.1.1" && version.patch === 1))))) {
595
+ (version.version === "2.1.1" && version.patch === 1))) ||
596
+ (version.minor === 2 && ((version.version === "2.2.0" && version.patch === 0))))) {
596
597
  return { valid: true };
597
598
  }
598
599
  if (version.major !== 0) {
package/dist/job-store.js CHANGED
@@ -58,6 +58,7 @@ export class JobStore {
58
58
  prompt_digest TEXT NOT NULL,
59
59
  summary TEXT NOT NULL,
60
60
  phase TEXT,
61
+ budget_ms INTEGER,
61
62
  final_output_path TEXT,
62
63
  stream_log_path TEXT NOT NULL,
63
64
  error TEXT
@@ -66,6 +67,9 @@ export class JobStore {
66
67
  if (!tableHasColumn(this.db, "phase")) {
67
68
  this.db.exec(`ALTER TABLE jobs ADD COLUMN phase TEXT;`);
68
69
  }
70
+ if (!tableHasColumn(this.db, "budget_ms")) {
71
+ this.db.exec(`ALTER TABLE jobs ADD COLUMN budget_ms INTEGER;`);
72
+ }
69
73
  // Additive provenance migration. Existing rows deliberately remain NULL:
70
74
  // v1.9.5 plus kimi-code 0.33/0.34 could have routed to native v2 before the
71
75
  // legacy pin landed, so a blanket historical v1 backfill would invent fact.
@@ -162,14 +166,14 @@ export class JobStore {
162
166
  background, pid, kimi_pid, status, kimi_session_id,
163
167
  operation_kind, intended_engine, observed_engine, kimi_version, system_version,
164
168
  kimi_command, kimi_prefix_args, plan_certification, resumed_from_job_id, safety_profile,
165
- agent_profile, prompt_digest, summary, phase, final_output_path, stream_log_path, error
169
+ agent_profile, prompt_digest, summary, phase, budget_ms, final_output_path, stream_log_path, error
166
170
  )
167
171
  VALUES (
168
172
  @job_id, @repo_id, @command_type, @created_at, @updated_at, @cwd, @model, @thinking,
169
173
  @background, @pid, @kimi_pid, @status, @kimi_session_id,
170
174
  @operation_kind, @intended_engine, @observed_engine, @kimi_version, @system_version,
171
175
  @kimi_command, @kimi_prefix_args, @plan_certification, @resumed_from_job_id, @safety_profile,
172
- @agent_profile, @prompt_digest, @summary, @phase, @final_output_path, @stream_log_path, @error
176
+ @agent_profile, @prompt_digest, @summary, @phase, @budget_ms, @final_output_path, @stream_log_path, @error
173
177
  )
174
178
  `, {
175
179
  ...serializeRecord(input),
@@ -276,7 +280,7 @@ export class JobStore {
276
280
  return this.updateWhere(jobId, { ...patch, status: "cancelled", pid: null, kimi_pid: null }, "status = 'running'");
277
281
  }
278
282
  static JOBS_COLUMNS = new Set([
279
- "status", "summary", "phase", "pid", "kimi_pid",
283
+ "status", "summary", "phase", "budget_ms", "pid", "kimi_pid",
280
284
  "final_output_path", "stream_log_path", "kimi_session_id",
281
285
  "error", "command_type", "prompt_digest", "repo_id",
282
286
  "cwd", "model", "thinking", "background", "agent_profile",
@@ -320,6 +324,7 @@ function serializeRecord(record) {
320
324
  return {
321
325
  ...record,
322
326
  phase: record.phase ?? null,
327
+ budget_ms: record.budget_ms ?? null,
323
328
  operation_kind: record.operation_kind ?? null,
324
329
  intended_engine: record.intended_engine ?? null,
325
330
  observed_engine: record.observed_engine ?? null,
package/dist/jobs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { RuntimeError } from "./errors.js";
3
- import { renderTerminalJobArtifact, writeArtifact } from "./render.js";
3
+ import { formatBudgetDuration, renderTerminalJobArtifact, writeArtifact } from "./render.js";
4
4
  export function digestPrompt(prompt) {
5
5
  return createHash("sha256").update(prompt).digest("hex");
6
6
  }
@@ -30,10 +30,14 @@ export function normalizeJobError(error) {
30
30
  };
31
31
  }
32
32
  export async function markJobFailed(store, paths, job, error, summary = "Job failed.", options) {
33
+ if (options?.partialOutput) {
34
+ const label = job.command_type[0].toUpperCase() + job.command_type.slice(1);
35
+ summary = `${label} timed out after ${formatBudgetDuration(options.partialOutput.budgetMs)}; partial output captured (${options.partialOutput.text.trim().length} chars).`;
36
+ }
33
37
  const normalized = normalizeJobError(error);
34
38
  const phase = options?.phase;
35
39
  const artifactJob = {
36
- ...job,
40
+ ...(store.getJob(job.job_id) ?? job),
37
41
  status: "failed",
38
42
  summary,
39
43
  error: normalized,
@@ -42,7 +46,7 @@ export async function markJobFailed(store, paths, job, error, summary = "Job fai
42
46
  kimi_pid: null,
43
47
  ...(phase !== undefined ? { phase } : {}),
44
48
  };
45
- const artifactPath = await writeArtifact(paths, artifactJob, renderTerminalJobArtifact(artifactJob));
49
+ const artifactPath = await writeArtifact(paths, artifactJob, renderTerminalJobArtifact(artifactJob, options?.partialOutput));
46
50
  return (store.markFailed(job.job_id, {
47
51
  summary,
48
52
  error: normalized,
@@ -38,6 +38,7 @@ export const NATIVE_V2_CERTIFIED_VERSIONS = Object.freeze([
38
38
  "2.0.2",
39
39
  "2.1.0",
40
40
  "2.1.1",
41
+ "2.2.0",
41
42
  ]);
42
43
  /** Per-operation native-v2 certification. One green operation never certifies another. */
43
44
  export const NATIVE_V2_CERTIFIED = new Map([
@@ -1,9 +1,35 @@
1
1
  import { RuntimeError, formatError } from "./errors.js";
2
+ const BUDGET_CEILING_MS = 24 * 60 * 60 * 1_000;
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
+ }
2
22
  export function classifyManagedCommandFailure(error, commandType, jobId, options) {
3
23
  const classification = classifyKimiAvailability(error);
4
24
  if (!classification) {
5
25
  return error instanceof Error ? error : new Error(String(error));
6
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
+ }
7
33
  const label = formatCommandLabel(commandType);
8
34
  const stage = options?.preserveStage && error instanceof RuntimeError
9
35
  ? error.stage
@@ -18,6 +44,14 @@ export function classifyManagedCommandFailure(error, commandType, jobId, options
18
44
  const details = { availability: classification.kind };
19
45
  if (error instanceof RuntimeError) {
20
46
  details.cause_code = error.code;
47
+ if (error.code === "RESPONSE_TIMEOUT") {
48
+ for (const key of ["budget_ms", "record_count", "partial_output_chars", "aborted", "settled_post_abort"]) {
49
+ if (error.details[key] !== undefined)
50
+ details[key] = error.details[key];
51
+ }
52
+ if (details.budget_ms === undefined && options?.budgetMs !== undefined)
53
+ details.budget_ms = options.budgetMs;
54
+ }
21
55
  }
22
56
  if (error instanceof Error && error.message.length > 0) {
23
57
  details.cause_message = truncateCauseMessageForDetails(error.message);
@@ -170,7 +204,7 @@ function classifyKimiAvailability(error) {
170
204
  return {
171
205
  kind: "response_timeout",
172
206
  summary: "Kimi started and accepted the prompt but never returned a final response.",
173
- nextStep: "Reduce the prompt scope (or for /kimi:ask and /kimi:rescue, retry with --background to detach). If the response still hangs after a fresh run, check local Kimi version and report upstream.",
207
+ 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.",
174
208
  runtimeProbe: "ok",
175
209
  authProbe: "ok",
176
210
  };
@@ -12,23 +12,23 @@
12
12
  // kimi-code spends real wallclock on extended reasoning before emitting
13
13
  // the first assistant record; pre-alpha.4 budgets (300s/600s) were sized
14
14
  // against the non-thinking path and timed out in production smoke
15
- // testing under default flags. Raised to 900/1800/1800 so a real
16
- // thinking-on review/rescue session has headroom; review-gate stays at
15
+ // testing under default flags. Defaults are now 1800/1800/2700 seconds
16
+ // for ask/review/rescue to allow repo-wide work; review-gate stays at
17
17
  // 8s because it fires inside Claude Code's Stop hook and is forced to
18
18
  // thinking-off in its own caller.
19
19
  /** Ask budget. Conversational; thinking-on free-form reasoning. */
20
- export const KIMI_ASK_PROMPT_TIMEOUT_MS = 900_000;
20
+ export const KIMI_ASK_PROMPT_TIMEOUT_MS = 1_800_000; // 30 minutes
21
21
  /** Review/challenge budget. Thinking-on single-turn analysis over the workspace. */
22
22
  export const KIMI_REVIEW_PROMPT_TIMEOUT_MS = 1_800_000;
23
23
  /** Rescue budget. Thinking-on multi-step apply/test/verify loops. */
24
- export const KIMI_RESCUE_PROMPT_TIMEOUT_MS = 1_800_000;
24
+ export const KIMI_RESCUE_PROMPT_TIMEOUT_MS = 2_700_000; // 45 minutes
25
25
  /**
26
26
  * Pursue (autonomous goal mode) DEFAULT wall-clock ceiling when the user
27
27
  * passes no `--budget`. This is the ONLY hard bound on an autonomous goal —
28
28
  * headless goal create sets no token/turn budget (only the model, via
29
- * SetGoalBudget, or this AbortController stops the loop). Larger than the
30
- * single-turn rescue budget (a goal spans multiple continuation turns) but
31
- * deliberately finite. Overridable per-job via `--budget` (parsed to ms in
29
+ * SetGoalBudget, or this AbortController stops the loop). The same duration as
30
+ * the single-turn rescue default, but a safety ceiling rather than a patience
31
+ * knob. Deliberately finite. Overridable per-job via `--budget` (parsed to ms in
32
32
  * parsePursueArgs). See runtime/commands/pursue.ts and docs/safety.md.
33
33
  */
34
34
  export const KIMI_PURSUE_DEFAULT_BUDGET_MS = 2_700_000; // 45 minutes
package/dist/parsing.js CHANGED
@@ -21,8 +21,13 @@ function looksLikeFlag(token) {
21
21
  // Short flag: a single dash followed by exactly one letter (`-r`, `-m`).
22
22
  return /^-[a-zA-Z]$/.test(token);
23
23
  }
24
- const ASK_SUPPORTED_FLAGS = "-m/--model <name>, --background, --wait, --fresh, -r, --resume <job-id|session-id>";
25
- const RESCUE_SUPPORTED_FLAGS = "-m/--model <name>, --background, --wait, --fresh, -r, --resume <job-id|session-id>";
24
+ export const ASK_SUPPORTED_FLAGS = "-m/--model <name>, --budget <30m|1h|90s>, --background, --wait, --fresh, -r, --resume <job-id|session-id>";
25
+ export const RESCUE_SUPPORTED_FLAGS = "-m/--model <name>, --budget <30m|1h|90s>, --background, --wait, --fresh, -r, --resume <job-id|session-id>";
26
+ export const REVIEW_SUPPORTED_FLAGS = "--base <ref>, -m/--model <name>, --budget <30m|1h|90s>";
27
+ export const JOB_LOOKUP_SUPPORTED_FLAGS = "--type <review|challenge|rescue|review_gate|ask>, --json";
28
+ export const SETUP_SUPPORTED_FLAGS = "--check, --uninstall, --all (with --uninstall), --enable-review-gate, --disable-review-gate, --models [--json] (without other setup flags)";
29
+ export const REPAIR_SESSIONS_SUPPORTED_FLAGS = "--apply, --all";
30
+ export const REPLAY_SUPPORTED_FLAGS = "none (one job-id required)";
26
31
  // Thinking-on is always-on for user-facing commands in v1.0. review-gate
27
32
  // pins thinking=false via the cli-client options bag instead of an argv
28
33
  // flag (see runtime/cli-client.ts::CliClientOptions). The parser rejects
@@ -39,8 +44,8 @@ function isRemovedThinkingFlag(token) {
39
44
  token.startsWith("--thinking=") ||
40
45
  token.startsWith("--no-thinking="));
41
46
  }
42
- const PURSUE_SUPPORTED_FLAGS = "-m/--model <name>, --budget <30m|1h|90s>, --turns <N>";
43
- const SWARM_SUPPORTED_FLAGS = "-m/--model <name>, --budget <30m|1h|90s>, --cap <N>, --max-concurrency <N>, --write";
47
+ export const PURSUE_SUPPORTED_FLAGS = "-m/--model <name>, --budget <30m|1h|90s>, --turns <N>";
48
+ export const SWARM_SUPPORTED_FLAGS = "-m/--model <name>, --budget <30m|1h|90s>, --cap <N>, --max-concurrency <N>, --write";
44
49
  /**
45
50
  * Parser for /kimi:swarm (read-only parallel fan-out). Foreground-only:
46
51
  * no --background/--fresh/--resume. Trailing tokens are the objective.
@@ -85,7 +90,7 @@ export function parseSwarmArgs(argv) {
85
90
  if (!value || value.startsWith("-")) {
86
91
  throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", "swarm.parse");
87
92
  }
88
- budgetMs = parseDurationMs(value, "--budget");
93
+ budgetMs = parseDurationMs(value, "--budget", "swarm.parse", "safety");
89
94
  index += 1;
90
95
  break;
91
96
  }
@@ -154,20 +159,23 @@ export const MAX_DURATION_MS = 24 * 60 * 60 * 1_000;
154
159
  * into milliseconds. Throws INVALID_ARGS on a malformed, non-positive, or
155
160
  * absurdly large value (> {@link MAX_DURATION_MS}).
156
161
  */
157
- export function parseDurationMs(token, flag) {
162
+ export function parseDurationMs(token, flag, stage, budgetKind) {
163
+ const limitReason = budgetKind === "safety"
164
+ ? "the budget is a safety ceiling, not a scheduler"
165
+ : "the budget is a response-time limit; a timed-out job is still a safe failure";
158
166
  const match = /^(\d+)(s|m|h)?$/.exec(token.trim());
159
167
  if (!match) {
160
- throw new RuntimeError("INVALID_ARGS", `${flag} expects a duration like 30m, 1h, or 90s (bare number = minutes); got "${token}".`, "pursue.parse");
168
+ throw new RuntimeError("INVALID_ARGS", `${flag} expects a duration like 30m, 1h, or 90s (bare number = minutes); got "${token}".`, stage);
161
169
  }
162
170
  const value = Number(match[1]);
163
171
  const unit = match[2] ?? "m";
164
172
  if (!Number.isFinite(value) || value <= 0) {
165
- throw new RuntimeError("INVALID_ARGS", `${flag} must be a positive duration.`, "pursue.parse");
173
+ throw new RuntimeError("INVALID_ARGS", `${flag} must be a positive duration.`, stage);
166
174
  }
167
175
  const unitMs = unit === "s" ? 1_000 : unit === "h" ? 3_600_000 : 60_000;
168
176
  const ms = value * unitMs;
169
177
  if (ms > MAX_DURATION_MS) {
170
- throw new RuntimeError("INVALID_ARGS", `${flag} must be at most 24h (got "${token}"); the budget is a safety ceiling, not a scheduler.`, "pursue.parse");
178
+ throw new RuntimeError("INVALID_ARGS", `${flag} must be at most 24h (got "${token}"); ${limitReason}.`, stage);
171
179
  }
172
180
  return ms;
173
181
  }
@@ -211,7 +219,7 @@ export function parsePursueArgs(argv) {
211
219
  if (!value || value.startsWith("-")) {
212
220
  throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", "pursue.parse");
213
221
  }
214
- budgetMs = parseDurationMs(value, "--budget");
222
+ budgetMs = parseDurationMs(value, "--budget", "pursue.parse", "safety");
215
223
  index += 1;
216
224
  break;
217
225
  }
@@ -248,7 +256,38 @@ export function parsePursueArgs(argv) {
248
256
  objective: trailingTokens?.join(" "),
249
257
  };
250
258
  }
259
+ /** Help before -- wins even over malformed flags or prose trailing-token mode. */
260
+ const VALUE_TAKING_FLAGS = new Set(["-m", "--model", "--budget", "--resume", "--base", "--cap", "--max-concurrency", "--turns", "--type"]);
261
+ /**
262
+ * `--help` / `-h` counts only inside the leading flag region: before `--`
263
+ * and before the first prose token. The value of a value-taking flag is
264
+ * skipped, so `-m kimi -h` is still a help request (`kimi` is a value, not
265
+ * prose) and `--budget --help` asks for help rather than failing on a bad
266
+ * duration. Once prose starts (`ask what does du -h print`), nothing after it
267
+ * is a flag — the whole remainder is the prompt.
268
+ */
269
+ export function hasHelpFlag(argv) {
270
+ for (let index = 0; index < argv.length; index += 1) {
271
+ const token = argv[index];
272
+ if (token === "--")
273
+ return false;
274
+ if (token === "--help" || token === "-h")
275
+ return true;
276
+ if (!token.startsWith("-"))
277
+ return false;
278
+ if (VALUE_TAKING_FLAGS.has(token)) {
279
+ const value = argv[index + 1];
280
+ if (value === "--help" || value === "-h")
281
+ return true;
282
+ index += 1;
283
+ }
284
+ }
285
+ return false;
286
+ }
251
287
  export function parseAskArgs(argv) {
288
+ if (hasHelpFlag(argv))
289
+ return { help: true, background: false, wait: false, fresh: false, resume: false };
290
+ let budgetMs;
252
291
  let model;
253
292
  // Thinking is on by default across ask/review/challenge/rescue. The
254
293
  // parser rejects --thinking / --no-thinking; review-gate's runtime
@@ -272,6 +311,15 @@ export function parseAskArgs(argv) {
272
311
  break;
273
312
  }
274
313
  switch (token) {
314
+ case "--budget": {
315
+ const value = argv[index + 1];
316
+ if (!value || value.startsWith("-")) {
317
+ throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", "ask.parse");
318
+ }
319
+ budgetMs = parseDurationMs(value, "--budget", "ask.parse", "response");
320
+ index += 1;
321
+ break;
322
+ }
275
323
  case "-m":
276
324
  case "--model": {
277
325
  const value = argv[index + 1];
@@ -327,6 +375,7 @@ export function parseAskArgs(argv) {
327
375
  throw new RuntimeError("INVALID_ARGS", "--resume only accepts a job-id or session-id. Use -r to resume the latest ask session with a prompt.", "ask.parse");
328
376
  }
329
377
  return {
378
+ budgetMs,
330
379
  background,
331
380
  wait,
332
381
  fresh,
@@ -338,8 +387,9 @@ export function parseAskArgs(argv) {
338
387
  };
339
388
  }
340
389
  export function parseReviewArgs(argv, commandName = "review") {
341
- const parsed = parseKnownFlags(argv, new Set(["--base", "--background", "--wait", "-m", "--model"]), commandName);
390
+ const parsed = parseKnownFlags(argv, new Set(["--budget", "--base", "--background", "--wait", "-m", "--model"]), commandName);
342
391
  return {
392
+ budgetMs: parsed.budgetMs,
343
393
  base: parsed.base,
344
394
  background: parsed.background,
345
395
  wait: parsed.wait,
@@ -349,6 +399,9 @@ export function parseReviewArgs(argv, commandName = "review") {
349
399
  };
350
400
  }
351
401
  export function parseRescueArgs(argv) {
402
+ if (hasHelpFlag(argv))
403
+ return { help: true, background: false, wait: false, fresh: false, resume: false };
404
+ let budgetMs;
352
405
  let model;
353
406
  let thinking = true;
354
407
  let background = false;
@@ -369,6 +422,15 @@ export function parseRescueArgs(argv) {
369
422
  break;
370
423
  }
371
424
  switch (token) {
425
+ case "--budget": {
426
+ const value = argv[index + 1];
427
+ if (!value || value.startsWith("-")) {
428
+ throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", "rescue.parse");
429
+ }
430
+ budgetMs = parseDurationMs(value, "--budget", "rescue.parse", "response");
431
+ index += 1;
432
+ break;
433
+ }
372
434
  case "-m":
373
435
  case "--model": {
374
436
  const value = argv[index + 1];
@@ -424,6 +486,7 @@ export function parseRescueArgs(argv) {
424
486
  throw new RuntimeError("INVALID_ARGS", "--resume only accepts a job-id or session-id. Use -r to resume the latest rescue session with a prompt.", "rescue.parse");
425
487
  }
426
488
  return {
489
+ budgetMs,
427
490
  background,
428
491
  wait,
429
492
  fresh,
@@ -454,7 +517,7 @@ export function parseJobLookupArgs(argv) {
454
517
  continue;
455
518
  }
456
519
  if (token.startsWith("-")) {
457
- throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token}. Supported flags: --type <review|challenge|rescue|review_gate|ask>, --json.`, "args.parse");
520
+ throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token}. Supported flags: ${JOB_LOOKUP_SUPPORTED_FLAGS}.`, "args.parse");
458
521
  }
459
522
  if (jobId) {
460
523
  throw new RuntimeError("INVALID_ARGS", "Only one optional job id may be supplied.", "args.parse");
@@ -475,6 +538,7 @@ function isManagedCommandType(value) {
475
538
  value === "ask");
476
539
  }
477
540
  function parseKnownFlags(argv, knownFlags, commandName) {
541
+ let budgetMs;
478
542
  let model;
479
543
  let thinking = true;
480
544
  let base;
@@ -497,12 +561,21 @@ function parseKnownFlags(argv, knownFlags, commandName) {
497
561
  // slurping them into focus text produced a bloated prompt that
498
562
  // looked like a hang. Hard-fail with the supported list inline so
499
563
  // the error message itself is the correction.
500
- throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token} for ${commandName}. Supported flags: --base <ref>, -m/--model <name>. Use \`--\` before flag-shaped focus text to pass it through.`, "args.parse");
564
+ throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token} for ${commandName}. Supported flags: ${REVIEW_SUPPORTED_FLAGS}. Use \`--\` before flag-shaped focus text to pass it through.`, "args.parse");
501
565
  }
502
566
  trailingTokens = argv.slice(index);
503
567
  break;
504
568
  }
505
569
  switch (token) {
570
+ case "--budget": {
571
+ const value = argv[index + 1];
572
+ if (!value || value.startsWith("-")) {
573
+ throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", `${commandName}.parse`);
574
+ }
575
+ budgetMs = parseDurationMs(value, "--budget", `${commandName}.parse`, "response");
576
+ index += 1;
577
+ break;
578
+ }
506
579
  case "-m":
507
580
  case "--model": {
508
581
  const value = argv[index + 1];
@@ -543,6 +616,7 @@ function parseKnownFlags(argv, knownFlags, commandName) {
543
616
  }
544
617
  }
545
618
  return {
619
+ budgetMs,
546
620
  base,
547
621
  background,
548
622
  wait,
package/dist/render.js CHANGED
@@ -126,7 +126,16 @@ export function renderReviewGateArtifact(job, output) {
126
126
  }
127
127
  return `${lines.join("\n")}\n`;
128
128
  }
129
- export function renderTerminalJobArtifact(job) {
129
+ export function formatBudgetDuration(ms) {
130
+ if (ms % 3_600_000 === 0)
131
+ return `${ms / 3_600_000}h`;
132
+ if (ms % 60_000 === 0)
133
+ return `${ms / 60_000}m`;
134
+ if (ms % 1_000 === 0)
135
+ return `${ms / 1_000}s`;
136
+ return `${ms}ms`;
137
+ }
138
+ export function renderTerminalJobArtifact(job, partialOutput) {
130
139
  const lines = [
131
140
  `# ${capitalize(job.status)} Job`,
132
141
  "",
@@ -149,6 +158,15 @@ export function renderTerminalJobArtifact(job) {
149
158
  }
150
159
  }
151
160
  }
161
+ if (partialOutput) {
162
+ lines.push("", `## Partial output (budget exhausted after ${formatBudgetDuration(partialOutput.budgetMs)} — NOT a final answer)`, "", partialOutput.text.trim()
163
+ ? partialOutput.text
164
+ : partialOutput.recordCount === 0
165
+ ? "No stream records arrived before the budget expired (the model had not produced any output yet)."
166
+ : partialOutput.toolCalls
167
+ ? "No assistant prose was emitted before the budget (tool calls only)."
168
+ : "No assistant prose was emitted before the budget.");
169
+ }
152
170
  return lines.join("\n");
153
171
  }
154
172
  function capitalize(value) {
package/dist/version.js CHANGED
@@ -4,4 +4,4 @@
4
4
  // and AGENTS.md on every release. A future improvement would read this from
5
5
  // package.json at build time, but that adds a build-step dependency we
6
6
  // don't want yet.
7
- export const KIMI_PLUGIN_CC_VERSION = "2.0.7";
7
+ export const KIMI_PLUGIN_CC_VERSION = "2.0.8";
package/docs/migration.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Compatibility and upgrades
2
2
 
3
- For plugin 2.0.3, use Kimi Code CLI 2.0.1. The plugin also certifies exact native-v2 versions `0.42.0`, `0.43.0`, `0.43.1`, and `2.0.0` for all eight operations. It does not automatically accept later patches or minor releases.
3
+ For plugin 2.0.7, use Kimi Code CLI 2.1.1. The plugin certifies exact native-v2 versions `0.42.0`, `0.43.0`, `0.43.1`, `2.0.0`, `2.0.1`, `2.0.2`, `2.1.0`, and `2.1.1` for all eight operations. It does not automatically accept later patches or minor releases. The npm distribution adds an installation channel; it does not change this compatibility table.
4
4
 
5
5
  Explicitly pinned legacy-v1 binaries remain supported within `KIMI_TESTED_MINORS`, through 0.41.x, subject to each operation's minimum version. The [runtime table](../runtime/kimi-engine.ts) is the authority.
6
6
 
@@ -8,8 +8,8 @@ Use the [README installation and update steps](../README.md) for Claude Code or
8
8
 
9
9
  ## Plugin versions and upgrades
10
10
 
11
- Plugin versions advance independently using ordinary SemVer. Plugin 2.0.3 certifies
12
- exact Kimi Code CLI 2.0.1; the runtime table records that mapping. Each compatible
11
+ Plugin versions advance independently using ordinary SemVer. Plugin 2.0.7 retains
12
+ the exact CLI certifications from 2.0.6; the runtime table records that mapping. Each compatible
13
13
  maintenance or certification update takes the next unused plugin patch. Published
14
14
  versions and tags are never reused. Every upstream patch requires its own certification.
15
15
  The native-v2 no-plan profile, plugin/marketplace IDs and existing job store are preserved.