kimi-plugin-cc 2.0.7

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 (190) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/.claude-plugin/marketplace.json +16 -0
  3. package/.claude-plugin/plugin.json +32 -0
  4. package/CHANGELOG.md +1096 -0
  5. package/LICENSE +201 -0
  6. package/README.md +772 -0
  7. package/agents/kimi-ask.md +82 -0
  8. package/agents/kimi-challenge.md +82 -0
  9. package/agents/kimi-pursue.md +91 -0
  10. package/agents/kimi-rescue.md +85 -0
  11. package/agents/kimi-review.md +82 -0
  12. package/agents/kimi-swarm-write.md +92 -0
  13. package/agents/kimi-swarm.md +83 -0
  14. package/commands/README.md +16 -0
  15. package/commands/ask.md +32 -0
  16. package/commands/cancel.md +17 -0
  17. package/commands/challenge.md +29 -0
  18. package/commands/pursue.md +37 -0
  19. package/commands/replay.md +13 -0
  20. package/commands/rescue.md +32 -0
  21. package/commands/result.md +13 -0
  22. package/commands/review.md +29 -0
  23. package/commands/setup.md +23 -0
  24. package/commands/status.md +13 -0
  25. package/commands/swarm.md +38 -0
  26. package/dist/background-spawn.js +224 -0
  27. package/dist/cli-cancellation.js +43 -0
  28. package/dist/cli-client.js +845 -0
  29. package/dist/commands/ask.js +327 -0
  30. package/dist/commands/cancel.js +178 -0
  31. package/dist/commands/cli-helpers.js +112 -0
  32. package/dist/commands/models.js +140 -0
  33. package/dist/commands/not-implemented.js +4 -0
  34. package/dist/commands/pursue.js +311 -0
  35. package/dist/commands/registry.js +87 -0
  36. package/dist/commands/repair-sessions.js +159 -0
  37. package/dist/commands/replay.js +123 -0
  38. package/dist/commands/rescue.js +333 -0
  39. package/dist/commands/result.js +58 -0
  40. package/dist/commands/review-gate.js +393 -0
  41. package/dist/commands/review.js +218 -0
  42. package/dist/commands/setup.js +1132 -0
  43. package/dist/commands/status.js +27 -0
  44. package/dist/commands/swarm.js +576 -0
  45. package/dist/commands/worker.js +31 -0
  46. package/dist/companion.js +114 -0
  47. package/dist/config.js +22 -0
  48. package/dist/errors.js +40 -0
  49. package/dist/git.js +215 -0
  50. package/dist/hooks/approval-hook.js +112 -0
  51. package/dist/hooks/approval-policy.js +254 -0
  52. package/dist/hooks/config-safety.js +637 -0
  53. package/dist/hooks/install-paths.js +504 -0
  54. package/dist/hooks/install.js +281 -0
  55. package/dist/hooks/managed-block.js +745 -0
  56. package/dist/hooks/review-gate-stop.js +19 -0
  57. package/dist/job-store.js +559 -0
  58. package/dist/jobs.js +202 -0
  59. package/dist/kimi-command.js +72 -0
  60. package/dist/kimi-engine.js +624 -0
  61. package/dist/kimi-errors.js +220 -0
  62. package/dist/kimi-home.js +9 -0
  63. package/dist/kimi-timeouts.js +68 -0
  64. package/dist/kimi-version-probe.js +1410 -0
  65. package/dist/logging.js +22 -0
  66. package/dist/native-v2-preflight.js +417 -0
  67. package/dist/package.json +1 -0
  68. package/dist/parsing.js +553 -0
  69. package/dist/paths.js +27 -0
  70. package/dist/plugin-data.js +98 -0
  71. package/dist/process-tree.js +448 -0
  72. package/dist/render.js +159 -0
  73. package/dist/rescue-approval.js +951 -0
  74. package/dist/schemas/review-gate-output.js +43 -0
  75. package/dist/session-title.js +293 -0
  76. package/dist/stream-json.js +498 -0
  77. package/dist/types.js +1 -0
  78. package/dist/vendor/shell-quote/LICENSE +24 -0
  79. package/dist/vendor/shell-quote/index.js +1 -0
  80. package/dist/vendor/shell-quote/parse.js +229 -0
  81. package/dist/vendor/smol-toml/LICENSE +24 -0
  82. package/dist/vendor/smol-toml/date.js +127 -0
  83. package/dist/vendor/smol-toml/error.js +63 -0
  84. package/dist/vendor/smol-toml/extract.js +100 -0
  85. package/dist/vendor/smol-toml/parse.js +148 -0
  86. package/dist/vendor/smol-toml/primitive.js +179 -0
  87. package/dist/vendor/smol-toml/struct.js +184 -0
  88. package/dist/vendor/smol-toml/util.js +113 -0
  89. package/dist/version.js +7 -0
  90. package/docs/migration.md +215 -0
  91. package/docs/models.md +82 -0
  92. package/docs/registry-releases.md +70 -0
  93. package/docs/safety.md +318 -0
  94. package/docs/session-visibility.md +32 -0
  95. package/hooks/README.md +9 -0
  96. package/hooks/hooks.json +16 -0
  97. package/package.json +67 -0
  98. package/plugins/kimi-codex/.codex-plugin/plugin.json +39 -0
  99. package/plugins/kimi-codex/dist/background-spawn.js +224 -0
  100. package/plugins/kimi-codex/dist/cli-cancellation.js +43 -0
  101. package/plugins/kimi-codex/dist/cli-client.js +845 -0
  102. package/plugins/kimi-codex/dist/commands/ask.js +327 -0
  103. package/plugins/kimi-codex/dist/commands/cancel.js +178 -0
  104. package/plugins/kimi-codex/dist/commands/cli-helpers.js +112 -0
  105. package/plugins/kimi-codex/dist/commands/models.js +140 -0
  106. package/plugins/kimi-codex/dist/commands/not-implemented.js +4 -0
  107. package/plugins/kimi-codex/dist/commands/pursue.js +311 -0
  108. package/plugins/kimi-codex/dist/commands/registry.js +87 -0
  109. package/plugins/kimi-codex/dist/commands/repair-sessions.js +159 -0
  110. package/plugins/kimi-codex/dist/commands/replay.js +123 -0
  111. package/plugins/kimi-codex/dist/commands/rescue.js +333 -0
  112. package/plugins/kimi-codex/dist/commands/result.js +58 -0
  113. package/plugins/kimi-codex/dist/commands/review-gate.js +393 -0
  114. package/plugins/kimi-codex/dist/commands/review.js +218 -0
  115. package/plugins/kimi-codex/dist/commands/setup.js +1132 -0
  116. package/plugins/kimi-codex/dist/commands/status.js +27 -0
  117. package/plugins/kimi-codex/dist/commands/swarm.js +576 -0
  118. package/plugins/kimi-codex/dist/commands/worker.js +31 -0
  119. package/plugins/kimi-codex/dist/companion.js +114 -0
  120. package/plugins/kimi-codex/dist/config.js +22 -0
  121. package/plugins/kimi-codex/dist/errors.js +40 -0
  122. package/plugins/kimi-codex/dist/git.js +215 -0
  123. package/plugins/kimi-codex/dist/hooks/approval-hook.js +112 -0
  124. package/plugins/kimi-codex/dist/hooks/approval-policy.js +254 -0
  125. package/plugins/kimi-codex/dist/hooks/config-safety.js +637 -0
  126. package/plugins/kimi-codex/dist/hooks/install-paths.js +504 -0
  127. package/plugins/kimi-codex/dist/hooks/install.js +281 -0
  128. package/plugins/kimi-codex/dist/hooks/managed-block.js +745 -0
  129. package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +19 -0
  130. package/plugins/kimi-codex/dist/job-store.js +559 -0
  131. package/plugins/kimi-codex/dist/jobs.js +202 -0
  132. package/plugins/kimi-codex/dist/kimi-command.js +72 -0
  133. package/plugins/kimi-codex/dist/kimi-engine.js +624 -0
  134. package/plugins/kimi-codex/dist/kimi-errors.js +220 -0
  135. package/plugins/kimi-codex/dist/kimi-home.js +9 -0
  136. package/plugins/kimi-codex/dist/kimi-timeouts.js +68 -0
  137. package/plugins/kimi-codex/dist/kimi-version-probe.js +1410 -0
  138. package/plugins/kimi-codex/dist/logging.js +22 -0
  139. package/plugins/kimi-codex/dist/native-v2-preflight.js +417 -0
  140. package/plugins/kimi-codex/dist/package.json +1 -0
  141. package/plugins/kimi-codex/dist/parsing.js +553 -0
  142. package/plugins/kimi-codex/dist/paths.js +27 -0
  143. package/plugins/kimi-codex/dist/plugin-data.js +98 -0
  144. package/plugins/kimi-codex/dist/process-tree.js +448 -0
  145. package/plugins/kimi-codex/dist/render.js +159 -0
  146. package/plugins/kimi-codex/dist/rescue-approval.js +951 -0
  147. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +43 -0
  148. package/plugins/kimi-codex/dist/session-title.js +293 -0
  149. package/plugins/kimi-codex/dist/stream-json.js +498 -0
  150. package/plugins/kimi-codex/dist/types.js +1 -0
  151. package/plugins/kimi-codex/dist/vendor/shell-quote/LICENSE +24 -0
  152. package/plugins/kimi-codex/dist/vendor/shell-quote/index.js +1 -0
  153. package/plugins/kimi-codex/dist/vendor/shell-quote/parse.js +229 -0
  154. package/plugins/kimi-codex/dist/vendor/smol-toml/LICENSE +24 -0
  155. package/plugins/kimi-codex/dist/vendor/smol-toml/date.js +127 -0
  156. package/plugins/kimi-codex/dist/vendor/smol-toml/error.js +63 -0
  157. package/plugins/kimi-codex/dist/vendor/smol-toml/extract.js +100 -0
  158. package/plugins/kimi-codex/dist/vendor/smol-toml/parse.js +148 -0
  159. package/plugins/kimi-codex/dist/vendor/smol-toml/primitive.js +179 -0
  160. package/plugins/kimi-codex/dist/vendor/smol-toml/struct.js +184 -0
  161. package/plugins/kimi-codex/dist/vendor/smol-toml/util.js +113 -0
  162. package/plugins/kimi-codex/dist/version.js +7 -0
  163. package/plugins/kimi-codex/scripts/companion.sh +37 -0
  164. package/plugins/kimi-codex/scripts/review-gate-hook.sh +32 -0
  165. package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +31 -0
  166. package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +6 -0
  167. package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +25 -0
  168. package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +6 -0
  169. package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +31 -0
  170. package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +6 -0
  171. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +30 -0
  172. package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +6 -0
  173. package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +25 -0
  174. package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +6 -0
  175. package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +30 -0
  176. package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +6 -0
  177. package/plugins/kimi-codex/skills/kimi-result/SKILL.md +25 -0
  178. package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +6 -0
  179. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +31 -0
  180. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +6 -0
  181. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +32 -0
  182. package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +6 -0
  183. package/plugins/kimi-codex/skills/kimi-status/SKILL.md +25 -0
  184. package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +6 -0
  185. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +31 -0
  186. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +6 -0
  187. package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +32 -0
  188. package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +6 -0
  189. package/scripts/companion.sh +37 -0
  190. package/scripts/review-gate-hook.sh +32 -0
@@ -0,0 +1,220 @@
1
+ import { RuntimeError, formatError } from "./errors.js";
2
+ export function classifyManagedCommandFailure(error, commandType, jobId, options) {
3
+ const classification = classifyKimiAvailability(error);
4
+ if (!classification) {
5
+ return error instanceof Error ? error : new Error(String(error));
6
+ }
7
+ const label = formatCommandLabel(commandType);
8
+ const stage = options?.preserveStage && error instanceof RuntimeError
9
+ ? error.stage
10
+ : `${commandType}.runtime`;
11
+ // Thread the cause's code and message into `details` so the underlying
12
+ // failure survives the wrap on every channel (formatError renders details
13
+ // as a JSON line; normalizeJobError persists them in the job row). Without
14
+ // this, a CLI_NONZERO_EXIT whose message embeds kimi's stderr tail (e.g.
15
+ // `auth.login_required` on 2026-08-08) was reduced to the generic
16
+ // "run /kimi:setup" advice with the real cause reachable only as `cause`,
17
+ // which no output channel serializes — an LLM caller could not diagnose it.
18
+ const details = { availability: classification.kind };
19
+ if (error instanceof RuntimeError) {
20
+ details.cause_code = error.code;
21
+ }
22
+ if (error instanceof Error && error.message.length > 0) {
23
+ details.cause_message = truncateCauseMessageForDetails(error.message);
24
+ }
25
+ 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 });
26
+ }
27
+ /**
28
+ * Cap the cause message carried in `details` so a large stderr tail cannot
29
+ * bloat the SQLite job row or the rendered details JSON line. Keep the TAIL
30
+ * end: for a crashed subprocess the informative lines (kimi's own `error:`
31
+ * output) are the trailing bytes of stderr, which cli-helpers appends last.
32
+ */
33
+ const CAUSE_MESSAGE_DETAILS_MAX = 2000;
34
+ function truncateCauseMessageForDetails(message) {
35
+ if (message.length <= CAUSE_MESSAGE_DETAILS_MAX) {
36
+ return message;
37
+ }
38
+ return `…${message.slice(-CAUSE_MESSAGE_DETAILS_MAX)}`;
39
+ }
40
+ export function summarizeKimiAvailabilityWarning(error, commandType) {
41
+ const classification = classifyKimiAvailability(error);
42
+ if (!classification) {
43
+ return null;
44
+ }
45
+ if (classification.kind === "auth_unavailable") {
46
+ return `Kimi ${formatCommandLabel(commandType).toLowerCase()} is not configured for model access; allowing stop.`;
47
+ }
48
+ if (classification.kind === "binary_unavailable") {
49
+ return `Kimi ${formatCommandLabel(commandType).toLowerCase()} could not find the Kimi CLI; allowing stop.`;
50
+ }
51
+ if (classification.kind === "startup_failed") {
52
+ return `Kimi ${formatCommandLabel(commandType).toLowerCase()} could not start a usable Kimi subprocess; allowing stop.`;
53
+ }
54
+ switch (classification.kind) {
55
+ case "startup_timeout":
56
+ return `Kimi ${formatCommandLabel(commandType).toLowerCase()} did not respond during startup; allowing stop.`;
57
+ case "initialize_timeout":
58
+ return `Kimi ${formatCommandLabel(commandType).toLowerCase()} did not complete session initialization; allowing stop.`;
59
+ case "response_timeout":
60
+ return `Kimi ${formatCommandLabel(commandType).toLowerCase()} did not return a final response; allowing stop.`;
61
+ case "max_steps_reached":
62
+ return `Kimi ${formatCommandLabel(commandType).toLowerCase()} exhausted its step budget; allowing stop.`;
63
+ case "timeout":
64
+ return `Kimi ${formatCommandLabel(commandType).toLowerCase()} timed out; allowing stop.`;
65
+ }
66
+ }
67
+ export function classifySetupFailure(error) {
68
+ return classifyKimiAvailability(error);
69
+ }
70
+ function classifyKimiAvailability(error) {
71
+ const message = formatError(error);
72
+ // kimi-code's managed OAuth store emits `auth.login_required: OAuth
73
+ // provider "managed:kimi-code" requires login…` on stderr when the token
74
+ // is missing or expired (observed on 0.34.0 after an out-of-band binary
75
+ // upgrade invalidated the token). The line reaches us inside the
76
+ // CLI_NONZERO_EXIT message because cli-helpers embeds the stderr tail.
77
+ // This MUST precede the code-based CLI_NONZERO_EXIT branch below, which
78
+ // would otherwise misclassify a logged-out CLI as startup_failed and
79
+ // point the user at /kimi:setup — which cannot fix auth.
80
+ if (message.includes("auth.login_required")) {
81
+ return {
82
+ kind: "auth_unavailable",
83
+ summary: "the local Kimi CLI is logged out (its OAuth login is missing or expired).",
84
+ nextStep: "Run `kimi login` to re-authenticate, then retry. `/kimi:setup` does not repair auth.",
85
+ runtimeProbe: "ok",
86
+ authProbe: "failed",
87
+ };
88
+ }
89
+ if (message.includes("LLM is not set") || message.includes("LLM service error")) {
90
+ return {
91
+ kind: "auth_unavailable",
92
+ summary: "local Kimi authentication or model configuration is not usable.",
93
+ nextStep: "Run `/kimi:setup`, then `kimi login` or fix the local Kimi model configuration and retry.",
94
+ runtimeProbe: "ok",
95
+ authProbe: "failed",
96
+ };
97
+ }
98
+ if (error instanceof RuntimeError && error.code === "CLI_SPAWN_FAILED") {
99
+ return {
100
+ kind: "binary_unavailable",
101
+ summary: "the Kimi CLI is missing from PATH or not executable in this environment.",
102
+ nextStep: "Run `/kimi:setup` to verify the install, then expose `kimi` on PATH and retry.",
103
+ runtimeProbe: "failed",
104
+ authProbe: "failed",
105
+ };
106
+ }
107
+ // v1.0 cli-client surfaces async ENOENT (Bun) as CLI_PROCESS_ERROR with
108
+ // "spawn ... ENOENT" in the message. Map that to binary_unavailable so
109
+ // the failure message points users at /kimi:setup.
110
+ if (error instanceof RuntimeError &&
111
+ error.code === "CLI_PROCESS_ERROR" &&
112
+ /\bENOENT\b/.test(message)) {
113
+ return {
114
+ kind: "binary_unavailable",
115
+ summary: "the Kimi CLI is missing from PATH or not executable in this environment.",
116
+ nextStep: "Run `/kimi:setup` to verify the install, then expose `kimi` on PATH and retry.",
117
+ runtimeProbe: "failed",
118
+ authProbe: "failed",
119
+ };
120
+ }
121
+ // v1.0 cli-client surfaces non-ENOENT process errors and non-zero
122
+ // exits as CLI_PROCESS_ERROR / CLI_NONZERO_EXIT. Treat both as
123
+ // startup-failed for classifier purposes — the next step is the same
124
+ // (run /kimi:setup) and the distinction between "kimi crashed during
125
+ // init" vs "kimi exited with status 1" is post-hoc.
126
+ if (error instanceof RuntimeError &&
127
+ (error.code === "CLI_PROCESS_ERROR" || error.code === "CLI_NONZERO_EXIT")) {
128
+ return {
129
+ kind: "startup_failed",
130
+ summary: "the Kimi CLI exited before completing the requested operation.",
131
+ nextStep: "Run `/kimi:setup` to verify local Kimi health, then retry.",
132
+ runtimeProbe: "failed",
133
+ authProbe: "failed",
134
+ };
135
+ }
136
+ if (error instanceof RuntimeError && error.code === "MAX_STEPS_REACHED") {
137
+ return {
138
+ kind: "max_steps_reached",
139
+ summary: "Kimi exhausted its step budget before finalizing the turn.",
140
+ nextStep: "Retry with a more focused prompt or a higher step budget.",
141
+ runtimeProbe: "ok",
142
+ authProbe: "ok",
143
+ };
144
+ }
145
+ if (error instanceof RuntimeError) {
146
+ // STARTUP_TIMEOUT and INITIALIZE_TIMEOUT predate the v1.0 subprocess
147
+ // transport (the v0.4 Wire client had a three-phase startup). The
148
+ // v1.0 cli-client only emits RESPONSE_TIMEOUT, so these branches are
149
+ // defensive — callers that synthesize the old codes (or load v0.4
150
+ // job rows from SQLite) still get a useful classification.
151
+ if (error.code === "STARTUP_TIMEOUT") {
152
+ return {
153
+ kind: "startup_timeout",
154
+ summary: "the Kimi CLI did not respond during startup.",
155
+ nextStep: "Run `/kimi:setup` to verify local Kimi health, then retry.",
156
+ runtimeProbe: "failed",
157
+ authProbe: "failed",
158
+ };
159
+ }
160
+ if (error.code === "INITIALIZE_TIMEOUT") {
161
+ return {
162
+ kind: "initialize_timeout",
163
+ summary: "the Kimi session started but did not finish initializing in time.",
164
+ nextStep: "Run `/kimi:setup` to verify local Kimi configuration and retry.",
165
+ runtimeProbe: "failed",
166
+ authProbe: "failed",
167
+ };
168
+ }
169
+ if (error.code === "RESPONSE_TIMEOUT") {
170
+ return {
171
+ kind: "response_timeout",
172
+ 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.",
174
+ runtimeProbe: "ok",
175
+ authProbe: "ok",
176
+ };
177
+ }
178
+ }
179
+ if (message.includes("timed out")) {
180
+ return {
181
+ kind: "timeout",
182
+ summary: "the Kimi runtime did not become ready within the expected time budget.",
183
+ nextStep: "Run `/kimi:setup` to check local Kimi auth and network health, then retry.",
184
+ runtimeProbe: "failed",
185
+ authProbe: "failed",
186
+ };
187
+ }
188
+ return null;
189
+ }
190
+ function mapAvailabilityCode(kind, commandType) {
191
+ const prefix = commandType.toUpperCase();
192
+ switch (kind) {
193
+ case "auth_unavailable":
194
+ return `${prefix}_KIMI_AUTH_UNAVAILABLE`;
195
+ case "binary_unavailable":
196
+ return `${prefix}_KIMI_BINARY_UNAVAILABLE`;
197
+ case "startup_failed":
198
+ return `${prefix}_KIMI_STARTUP_FAILED`;
199
+ case "startup_timeout":
200
+ return `${prefix}_KIMI_STARTUP_TIMEOUT`;
201
+ case "initialize_timeout":
202
+ return `${prefix}_KIMI_INITIALIZE_TIMEOUT`;
203
+ case "response_timeout":
204
+ return `${prefix}_KIMI_RESPONSE_TIMEOUT`;
205
+ case "timeout":
206
+ return `${prefix}_KIMI_TIMEOUT`;
207
+ case "max_steps_reached":
208
+ return `${prefix}_KIMI_MAX_STEPS_REACHED`;
209
+ }
210
+ }
211
+ function formatCommandLabel(commandType) {
212
+ switch (commandType) {
213
+ case "challenge":
214
+ return "challenge";
215
+ case "review_gate":
216
+ return "review gate";
217
+ default:
218
+ return commandType.replaceAll("_", " ");
219
+ }
220
+ }
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1,68 @@
1
+ // Per-command response-budget constants for the v1.0 cli-client path.
2
+ //
3
+ // v0.4 also exposed startup / initialize timeouts plus a generic
4
+ // `withTimeout` helper. Those existed because the Wire transport had a
5
+ // three-phase lifecycle (spawn → initialize → prompt). The v1.0
6
+ // subprocess transport collapses spawn + prompt into a single
7
+ // `runCliPromptWithBudget` call (see `runtime/cli-client.ts`), and
8
+ // startup failures surface as CLI_SPAWN_FAILED / CLI_PROCESS_ERROR —
9
+ // not as separate timeouts. So only the per-command response budgets
10
+ // remain.
11
+ // Budgets are sized for thinking-on workflow (the default since v1.0).
12
+ // kimi-code spends real wallclock on extended reasoning before emitting
13
+ // the first assistant record; pre-alpha.4 budgets (300s/600s) were sized
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
17
+ // 8s because it fires inside Claude Code's Stop hook and is forced to
18
+ // thinking-off in its own caller.
19
+ /** Ask budget. Conversational; thinking-on free-form reasoning. */
20
+ export const KIMI_ASK_PROMPT_TIMEOUT_MS = 900_000;
21
+ /** Review/challenge budget. Thinking-on single-turn analysis over the workspace. */
22
+ export const KIMI_REVIEW_PROMPT_TIMEOUT_MS = 1_800_000;
23
+ /** Rescue budget. Thinking-on multi-step apply/test/verify loops. */
24
+ export const KIMI_RESCUE_PROMPT_TIMEOUT_MS = 1_800_000;
25
+ /**
26
+ * Pursue (autonomous goal mode) DEFAULT wall-clock ceiling when the user
27
+ * passes no `--budget`. This is the ONLY hard bound on an autonomous goal —
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
32
+ * parsePursueArgs). See runtime/commands/pursue.ts and docs/safety.md.
33
+ */
34
+ export const KIMI_PURSUE_DEFAULT_BUDGET_MS = 2_700_000; // 45 minutes
35
+ /**
36
+ * Swarm (read-only parallel fan-out) DEFAULT wall-clock ceiling when the user
37
+ * passes no `--budget`. Read-only swarm opens no write surface, so the only new
38
+ * risk is COST/runaway from N parallel model runs (plus possible nested
39
+ * AgentSwarm). This AbortController is the hard bound on that; the `--cap`
40
+ * subagent count is a soft prompt-injected hint (not hook-enforceable —
41
+ * the hook is stateless and can't count subagents). Sized like the single-turn
42
+ * review budget — a swarm fans review work out in parallel within one process,
43
+ * so 30m of wall-clock is generous headroom. Overridable per-job via `--budget`
44
+ * (parsed to ms in parseSwarmArgs). See runtime/commands/swarm.ts and
45
+ * docs/safety.md.
46
+ */
47
+ export const KIMI_SWARM_DEFAULT_BUDGET_MS = 1_800_000; // 30 minutes
48
+ /**
49
+ * Review-gate budget. Fires inside Claude Code's Stop hook so any value
50
+ * above the user's perceptible wait makes the gate feel broken.
51
+ *
52
+ * kimi-code 0.1.1 has no per-spawn CLI flag for thinking control
53
+ * (Round 2 multi-agent review caught this — emitting `--no-thinking`
54
+ * triggers an unknown-option crash). The 8s budget assumes the user
55
+ * has either `default_thinking = false` or `[thinking].mode = "off"`
56
+ * in `~/.kimi-code/config.toml`, OR a non-thinking-capable model
57
+ * selected for review-gate (via KIMI_PLUGIN_CC_REVIEW_GATE_MODEL).
58
+ * Under thinking-on the gate will time out — the gate is fail-open on
59
+ * timeout by design, so the worst case is the gate becomes
60
+ * always-allow. See docs/safety.md.
61
+ */
62
+ export const KIMI_REVIEW_GATE_TIMEOUT_MS = 8_000;
63
+ export function isTimeoutCode(code) {
64
+ return (code === "TIMEOUT" ||
65
+ code === "STARTUP_TIMEOUT" ||
66
+ code === "INITIALIZE_TIMEOUT" ||
67
+ code === "RESPONSE_TIMEOUT");
68
+ }