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.
Files changed (281) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +3 -14
  3. package/README.md +428 -572
  4. package/assets/logo.svg +6 -0
  5. package/cordis.patch.yml +18 -0
  6. package/dist/background-spawn.js +4 -2
  7. package/dist/cli-client.js +105 -66
  8. package/dist/commands/ask.js +27 -12
  9. package/dist/commands/cancel.js +4 -13
  10. package/dist/commands/cli-helpers.js +1 -1
  11. package/dist/commands/pursue.js +3 -2
  12. package/dist/commands/registry.js +7 -26
  13. package/dist/commands/repair-sessions.js +7 -4
  14. package/dist/commands/replay.js +4 -3
  15. package/dist/commands/rescue.js +17 -5
  16. package/dist/commands/review.js +18 -5
  17. package/dist/commands/setup.js +277 -262
  18. package/dist/commands/swarm.js +20 -7
  19. package/dist/companion.js +142 -18
  20. package/dist/help.js +11 -7
  21. package/dist/hook-escape.js +7 -16
  22. package/dist/hooks/approval-hook.js +1762 -124
  23. package/dist/hooks/approval-policy.js +15 -10
  24. package/dist/hooks/config-safety.js +15 -24
  25. package/dist/hooks/hook-timing.js +1 -1
  26. package/dist/hooks/install-paths.js +179 -107
  27. package/dist/hooks/install.js +44 -166
  28. package/dist/hooks/managed-block.js +44 -95
  29. package/dist/job-store.js +117 -49
  30. package/dist/jobs.js +53 -1
  31. package/dist/kimi-engine.js +68 -92
  32. package/dist/kimi-errors.js +1 -1
  33. package/dist/kimi-journal.js +3 -2
  34. package/dist/kimi-releases.js +28 -49
  35. package/dist/kimi-timeouts.js +1 -15
  36. package/dist/kimi-version-probe.js +24 -72
  37. package/dist/logging.js +12 -7
  38. package/dist/mcp/binding.js +13 -4
  39. package/dist/mcp/job-control.js +386 -89
  40. package/dist/mcp/launcher.js +1 -1
  41. package/dist/mcp/operations.js +387 -193
  42. package/dist/mcp/protocol.js +116 -27
  43. package/dist/mcp/skills.js +130 -0
  44. package/dist/mcp/stdio.js +15 -2
  45. package/dist/native-v2-preflight.js +127 -35
  46. package/dist/parsing.js +45 -11
  47. package/dist/paths.js +20 -10
  48. package/dist/plugin-data.js +28 -83
  49. package/dist/read-scope.js +2 -2
  50. package/dist/render.js +13 -38
  51. package/dist/session-references.js +216 -0
  52. package/dist/session-title.js +1 -1
  53. package/dist/surface-routing.js +92 -5
  54. package/dist/swarm-activation.js +26 -137
  55. package/dist/version.js +1 -1
  56. package/docs/migration.md +45 -227
  57. package/docs/models.md +24 -66
  58. package/docs/safety.md +195 -400
  59. package/docs/session-visibility.md +24 -14
  60. package/docs/swarm-recovery.md +26 -20
  61. package/dsh/index.json +54 -0
  62. package/mcp_config.json +10 -0
  63. package/package.json +23 -82
  64. package/plugin.json +19 -0
  65. package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
  66. package/plugins/kimi-codex/.mcp.json +2 -3
  67. package/plugins/kimi-codex/dist/background-spawn.js +4 -2
  68. package/plugins/kimi-codex/dist/cli-client.js +105 -66
  69. package/plugins/kimi-codex/dist/commands/ask.js +27 -12
  70. package/plugins/kimi-codex/dist/commands/cancel.js +4 -13
  71. package/plugins/kimi-codex/dist/commands/cli-helpers.js +1 -1
  72. package/plugins/kimi-codex/dist/commands/pursue.js +3 -2
  73. package/plugins/kimi-codex/dist/commands/registry.js +7 -26
  74. package/plugins/kimi-codex/dist/commands/repair-sessions.js +7 -4
  75. package/plugins/kimi-codex/dist/commands/replay.js +4 -3
  76. package/plugins/kimi-codex/dist/commands/rescue.js +17 -5
  77. package/plugins/kimi-codex/dist/commands/review.js +18 -5
  78. package/plugins/kimi-codex/dist/commands/setup.js +277 -262
  79. package/plugins/kimi-codex/dist/commands/swarm.js +20 -7
  80. package/plugins/kimi-codex/dist/companion.js +142 -18
  81. package/plugins/kimi-codex/dist/help.js +11 -7
  82. package/plugins/kimi-codex/dist/hook-escape.js +7 -16
  83. package/plugins/kimi-codex/dist/hooks/approval-hook.js +1762 -124
  84. package/plugins/kimi-codex/dist/hooks/approval-policy.js +15 -10
  85. package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -24
  86. package/plugins/kimi-codex/dist/hooks/hook-timing.js +1 -1
  87. package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
  88. package/plugins/kimi-codex/dist/hooks/install.js +44 -166
  89. package/plugins/kimi-codex/dist/hooks/managed-block.js +44 -95
  90. package/plugins/kimi-codex/dist/job-store.js +117 -49
  91. package/plugins/kimi-codex/dist/jobs.js +53 -1
  92. package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
  93. package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
  94. package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
  95. package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
  96. package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
  97. package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
  98. package/plugins/kimi-codex/dist/logging.js +12 -7
  99. package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
  100. package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
  101. package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
  102. package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
  103. package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
  104. package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
  105. package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
  106. package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
  107. package/plugins/kimi-codex/dist/parsing.js +45 -11
  108. package/plugins/kimi-codex/dist/paths.js +20 -10
  109. package/plugins/kimi-codex/dist/plugin-data.js +28 -83
  110. package/plugins/kimi-codex/dist/read-scope.js +2 -2
  111. package/plugins/kimi-codex/dist/render.js +13 -38
  112. package/plugins/kimi-codex/dist/session-references.js +216 -0
  113. package/plugins/kimi-codex/dist/session-title.js +1 -1
  114. package/plugins/kimi-codex/dist/surface-routing.js +92 -5
  115. package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
  116. package/plugins/kimi-codex/dist/version.js +1 -1
  117. package/plugins/kimi-codex/scripts/companion.sh +4 -15
  118. package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
  119. package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
  120. package/scripts/companion.sh +4 -15
  121. package/skills/kimi/SKILL.md +77 -0
  122. package/skills/kimi/agents/openai.yaml +6 -0
  123. package/CHANGELOG.md +0 -1402
  124. package/agents/kimi-pursue.md +0 -93
  125. package/agents/kimi-review.md +0 -86
  126. package/agents/kimi-swarm.md +0 -88
  127. package/agents/kimi-task.md +0 -93
  128. package/commands/README.md +0 -14
  129. package/commands/cancel.md +0 -17
  130. package/commands/pursue.md +0 -41
  131. package/commands/replay.md +0 -13
  132. package/commands/result.md +0 -13
  133. package/commands/review.md +0 -40
  134. package/commands/setup.md +0 -25
  135. package/commands/status.md +0 -13
  136. package/commands/swarm.md +0 -45
  137. package/commands/task.md +0 -40
  138. package/dist/commands/review-gate.js +0 -391
  139. package/dist/config.js +0 -22
  140. package/dist/dsh/companion.js +0 -177
  141. package/dist/dsh/index.js +0 -167
  142. package/dist/hooks/review-gate-stop.js +0 -19
  143. package/dist/schemas/review-gate-output.js +0 -41
  144. package/docs/registry-releases.md +0 -228
  145. package/docs/upstream-2.4.1-certification.md +0 -54
  146. package/docs/upstream-2.5.0-certification.md +0 -52
  147. package/docs/upstream-2.5.1-certification.md +0 -47
  148. package/docs/upstream-2.5.2-certification.md +0 -40
  149. package/docs/upstream-2.5.3-certification.md +0 -73
  150. package/docs/upstream-2.6.0-certification.md +0 -65
  151. package/docs/upstream-2.6.2-certification.md +0 -144
  152. package/docs/upstream-2.6.3-certification.md +0 -100
  153. package/docs/upstream-2.7.2-certification.md +0 -113
  154. package/docs/upstream-2.7.3-certification.md +0 -95
  155. package/docs/windows-validation.md +0 -39
  156. package/hooks/README.md +0 -9
  157. package/hooks/hooks.json +0 -16
  158. package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
  159. package/plugins/kimi-codex/dist/config.js +0 -22
  160. package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
  161. package/plugins/kimi-codex/dist/dsh/index.js +0 -167
  162. package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
  163. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
  164. package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
  165. package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
  166. package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
  167. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
  168. package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
  169. package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
  170. package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
  171. package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
  172. package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
  173. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
  174. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
  175. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
  176. package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
  177. package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
  178. package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
  179. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
  180. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
  181. package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
  182. package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
  183. package/plugins/kimi-dsh/LICENSE +0 -201
  184. package/plugins/kimi-dsh/README.md +0 -84
  185. package/plugins/kimi-dsh/cordis.patch.yml +0 -45
  186. package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
  187. package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
  188. package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
  189. package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
  190. package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
  191. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
  192. package/plugins/kimi-dsh/dist/commands/models.js +0 -139
  193. package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
  194. package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
  195. package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
  196. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
  197. package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
  198. package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
  199. package/plugins/kimi-dsh/dist/commands/result.js +0 -72
  200. package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
  201. package/plugins/kimi-dsh/dist/commands/review.js +0 -217
  202. package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
  203. package/plugins/kimi-dsh/dist/commands/status.js +0 -27
  204. package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
  205. package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
  206. package/plugins/kimi-dsh/dist/companion.js +0 -99
  207. package/plugins/kimi-dsh/dist/config.js +0 -22
  208. package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
  209. package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
  210. package/plugins/kimi-dsh/dist/errors.js +0 -40
  211. package/plugins/kimi-dsh/dist/git.js +0 -216
  212. package/plugins/kimi-dsh/dist/help.js +0 -43
  213. package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
  214. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
  215. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
  216. package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
  217. package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
  218. package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
  219. package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
  220. package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
  221. package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
  222. package/plugins/kimi-dsh/dist/job-id.js +0 -12
  223. package/plugins/kimi-dsh/dist/job-store.js +0 -631
  224. package/plugins/kimi-dsh/dist/jobs.js +0 -212
  225. package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
  226. package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
  227. package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
  228. package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
  229. package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
  230. package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
  231. package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
  232. package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
  233. package/plugins/kimi-dsh/dist/logging.js +0 -22
  234. package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
  235. package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
  236. package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
  237. package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
  238. package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
  239. package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
  240. package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
  241. package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
  242. package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
  243. package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
  244. package/plugins/kimi-dsh/dist/model-command.js +0 -34
  245. package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
  246. package/plugins/kimi-dsh/dist/package.json +0 -1
  247. package/plugins/kimi-dsh/dist/parsing.js +0 -554
  248. package/plugins/kimi-dsh/dist/paths.js +0 -35
  249. package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
  250. package/plugins/kimi-dsh/dist/process-tree.js +0 -597
  251. package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
  252. package/plugins/kimi-dsh/dist/read-scope.js +0 -435
  253. package/plugins/kimi-dsh/dist/render.js +0 -214
  254. package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
  255. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
  256. package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
  257. package/plugins/kimi-dsh/dist/session-title.js +0 -313
  258. package/plugins/kimi-dsh/dist/stream-json.js +0 -344
  259. package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
  260. package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
  261. package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
  262. package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
  263. package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
  264. package/plugins/kimi-dsh/dist/types.js +0 -1
  265. package/plugins/kimi-dsh/dist/util.js +0 -28
  266. package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
  267. package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
  268. package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
  269. package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
  270. package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
  271. package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
  272. package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
  273. package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
  274. package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
  275. package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
  276. package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
  277. package/plugins/kimi-dsh/dist/version.js +0 -7
  278. package/plugins/kimi-dsh/package.json +0 -78
  279. package/plugins/kimi-dsh/scripts/companion.sh +0 -37
  280. package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
  281. package/scripts/review-gate-hook.sh +0 -32
@@ -1,19 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { runReviewGateStopHook } from "../commands/review-gate.js";
3
- import { formatError } from "../errors.js";
4
- async function main() {
5
- const raw = readFileSync(0, "utf8");
6
- const input = JSON.parse(raw);
7
- const context = {
8
- cwd: process.env.KIMI_PLUGIN_CC_WORKSPACE_CWD || process.cwd(),
9
- env: process.env,
10
- stdout: process.stdout,
11
- stderr: process.stderr,
12
- };
13
- const output = await runReviewGateStopHook(input, context);
14
- process.stdout.write(`${JSON.stringify(output)}\n`);
15
- }
16
- main().catch((error) => {
17
- process.stderr.write(`${formatError(error)}\n`);
18
- process.exitCode = 1;
19
- });
@@ -1,12 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { RuntimeError } from "./errors.js";
3
- const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
4
- export function allocateJobId(context) {
5
- const fixed = context.mcpJobId;
6
- if (fixed === undefined)
7
- return randomUUID();
8
- if (!UUID_PATTERN.test(fixed)) {
9
- throw new RuntimeError("MCP_INVALID_JOB_ID", "The supervised job ID must be a valid UUID.", "mcp.child");
10
- }
11
- return fixed;
12
- }
@@ -1,631 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import { RuntimeError, formatError } from "./errors.js";
3
- export class JobStore {
4
- db;
5
- constructor(paths) {
6
- // Open the adapter into a local before assigning to this.db so the
7
- // catch can release the handle even if pragma throws AFTER the
8
- // adapter opened — `journal_mode = WAL` on a read-only mount, for
9
- // example, would otherwise leak the handle because the constructor
10
- // exits via throw before any caller reference exists for cleanup.
11
- let db;
12
- try {
13
- db = createSqliteAdapter(paths.stateDbPath);
14
- // busy_timeout FIRST: switching the journal mode takes a brief write lock,
15
- // and a second opener (status/result racing a worker) otherwise fails
16
- // immediately with SQLITE_BUSY instead of waiting (seen 2026-10-14).
17
- db.pragma("busy_timeout = 5000");
18
- db.pragma("journal_mode = WAL");
19
- }
20
- catch (error) {
21
- try {
22
- db?.close();
23
- }
24
- catch {
25
- // Best-effort — original error takes priority over close failure.
26
- }
27
- throw translateSqliteError(error);
28
- }
29
- this.db = db;
30
- // Every `this.db.exec` / `existingColumns` below can throw on a
31
- // corrupt DB, full disk, mid-migration failure, etc. Catch
32
- // internally, close the adapter, and rethrow the translated error
33
- // so the SQLite handle never leaks past a failed migration.
34
- try {
35
- this.db.exec(`
36
- CREATE TABLE IF NOT EXISTS jobs (
37
- job_id TEXT PRIMARY KEY,
38
- repo_id TEXT NOT NULL,
39
- command_type TEXT NOT NULL,
40
- created_at TEXT NOT NULL,
41
- updated_at TEXT NOT NULL,
42
- cwd TEXT NOT NULL,
43
- model TEXT,
44
- thinking INTEGER,
45
- background INTEGER NOT NULL,
46
- pid INTEGER,
47
- kimi_pid INTEGER,
48
- status TEXT NOT NULL,
49
- kimi_session_id TEXT,
50
- operation_kind TEXT,
51
- intended_engine TEXT,
52
- observed_engine TEXT,
53
- kimi_version TEXT,
54
- system_version TEXT,
55
- kimi_command TEXT,
56
- kimi_prefix_args TEXT,
57
- plan_certification TEXT,
58
- resumed_from_job_id TEXT,
59
- safety_profile TEXT,
60
- agent_profile TEXT NOT NULL,
61
- prompt_digest TEXT NOT NULL,
62
- summary TEXT NOT NULL,
63
- phase TEXT,
64
- budget_ms INTEGER,
65
- final_output_path TEXT,
66
- stream_log_path TEXT NOT NULL,
67
- error TEXT
68
- );
69
- `);
70
- for (const [column, type] of ADDED_JOB_COLUMNS) {
71
- // Re-read per column: another process may be migrating the same store.
72
- if (!existingColumns(this.db, "jobs").has(column)) {
73
- this.db.exec(`ALTER TABLE jobs ADD COLUMN ${column} ${type};`);
74
- }
75
- }
76
- this.db.exec(`
77
- CREATE TABLE IF NOT EXISTS mcp_tasks (
78
- task_id TEXT PRIMARY KEY,
79
- operation_kind TEXT NOT NULL,
80
- repo_id TEXT NOT NULL,
81
- workspace_cwd TEXT NOT NULL,
82
- companion_pid INTEGER,
83
- companion_identity TEXT,
84
- kimi_identity TEXT,
85
- stdout_path TEXT NOT NULL,
86
- stderr_path TEXT NOT NULL,
87
- launch_state TEXT NOT NULL,
88
- launch_error TEXT,
89
- created_at TEXT NOT NULL,
90
- attached_at TEXT,
91
- updated_at TEXT NOT NULL
92
- );
93
-
94
- CREATE INDEX IF NOT EXISTS mcp_tasks_workspace_updated_idx
95
- ON mcp_tasks (workspace_cwd, updated_at DESC);
96
-
97
- CREATE INDEX IF NOT EXISTS jobs_repo_updated_idx
98
- ON jobs (repo_id, updated_at DESC);
99
-
100
- CREATE TABLE IF NOT EXISTS swarm_recovery (job_id TEXT PRIMARY KEY, payload TEXT NOT NULL, recovery_owner TEXT);
101
-
102
- CREATE INDEX IF NOT EXISTS jobs_repo_type_updated_idx
103
- ON jobs (repo_id, command_type, updated_at DESC);
104
-
105
- CREATE INDEX IF NOT EXISTS jobs_session_id_idx ON jobs (kimi_session_id);
106
-
107
- CREATE INDEX IF NOT EXISTS jobs_session_idx
108
- ON jobs (repo_id, kimi_session_id, updated_at DESC);
109
-
110
- DROP INDEX IF EXISTS jobs_running_rescue_session_idx;
111
-
112
- -- Reconcile orphaned duplicate running rows before creating the unique
113
- -- partial index. A 0.1.3 database with a hard-crashed worker can contain
114
- -- multiple (repo_id, command_type, kimi_session_id) rows at status='running',
115
- -- which would fail the CREATE UNIQUE INDEX at open and brick the store.
116
- -- Keep the most recently updated row per group; mark the rest as failed.
117
- UPDATE jobs
118
- SET status = 'failed',
119
- updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
120
- error = COALESCE(
121
- error,
122
- '{"code":"JOB_STORE_ORPHANED_ON_UPGRADE","message":"Orphaned duplicate running job reconciled on 0.1.4 schema upgrade","stage":"job-store.migrate"}'
123
- )
124
- WHERE status = 'running'
125
- AND command_type IN ('rescue', 'ask')
126
- AND kimi_session_id IS NOT NULL
127
- AND rowid NOT IN (
128
- SELECT rowid FROM (
129
- SELECT rowid,
130
- ROW_NUMBER() OVER (
131
- PARTITION BY repo_id, command_type, kimi_session_id
132
- ORDER BY updated_at DESC, rowid DESC
133
- ) AS rn
134
- FROM jobs
135
- WHERE status = 'running'
136
- AND command_type IN ('rescue', 'ask')
137
- AND kimi_session_id IS NOT NULL
138
- )
139
- WHERE rn = 1
140
- );
141
-
142
- CREATE UNIQUE INDEX IF NOT EXISTS jobs_running_session_idx
143
- ON jobs (repo_id, command_type, kimi_session_id)
144
- WHERE status = 'running' AND command_type IN ('rescue', 'ask');
145
-
146
- -- 0.1.6 migration: rename adversarial_review to challenge
147
- UPDATE jobs SET command_type = 'challenge' WHERE command_type = 'adversarial_review';
148
- `);
149
- if (!existingColumns(this.db, "mcp_tasks").has("kimi_identity")) {
150
- this.db.exec("ALTER TABLE mcp_tasks ADD COLUMN kimi_identity TEXT;");
151
- }
152
- }
153
- catch (error) {
154
- // Migration failed — close the adapter so the OS handle is released
155
- // before propagating. Wrap close() in its own try so a double-fault
156
- // doesn't mask the original migration error.
157
- try {
158
- this.db.close();
159
- }
160
- catch {
161
- // intentionally swallow — original error takes priority
162
- }
163
- throw translateSqliteError(error);
164
- }
165
- }
166
- getSwarmRecovery(jobId) {
167
- const row = this.db.get("SELECT payload, recovery_owner FROM swarm_recovery WHERE job_id = ?", jobId);
168
- return row ? { record: JSON.parse(row.payload), owner: row.recovery_owner } : null;
169
- }
170
- saveSwarmRecovery(jobId, record) {
171
- this.db.run("INSERT INTO swarm_recovery (job_id, payload) VALUES (?, ?) ON CONFLICT(job_id) DO UPDATE SET payload = excluded.payload", [jobId, JSON.stringify(record)]);
172
- }
173
- claimSwarmRecovery(jobId, expected, owner) {
174
- this.db.run("UPDATE swarm_recovery SET recovery_owner = ? WHERE job_id = ? AND recovery_owner IS ?", [owner, jobId, expected]);
175
- return this.db.get("SELECT changes() AS count").count === 1;
176
- }
177
- close() {
178
- this.db.close();
179
- }
180
- createJob(input) {
181
- const now = new Date().toISOString();
182
- try {
183
- this.db.run(INSERT_JOB_SQL, {
184
- ...serializeRecord(input),
185
- created_at: now,
186
- updated_at: now,
187
- });
188
- }
189
- catch (error) {
190
- if (isSqliteConstraintError(error)) {
191
- if (input.command_type === "rescue") {
192
- throw new RuntimeError("RESCUE_ALREADY_RUNNING", `A rescue job for session ${input.kimi_session_id ?? "<unknown>"} is already running in this repo. Use /kimi:status to find it.`, "rescue.resume", error instanceof Error ? { cause: error } : undefined);
193
- }
194
- if (input.command_type === "ask") {
195
- throw new RuntimeError("ASK_ALREADY_RUNNING", `An ask session ${input.kimi_session_id ?? "<unknown>"} is already running in this repo. Use /kimi:status to find it.`, "ask.resume", error instanceof Error ? { cause: error } : undefined);
196
- }
197
- }
198
- throw translateSqliteError(error);
199
- }
200
- return this.getJob(input.job_id);
201
- }
202
- getJob(jobId) {
203
- const row = this.db.get("SELECT * FROM jobs WHERE job_id = ?", jobId);
204
- return row ? hydrateRow(row) : null;
205
- }
206
- /** Global across repos and terminal states; optionally exclude the current row. */
207
- hasSessionId(sessionId, exceptJobId = "") {
208
- return Boolean(this.db.get("SELECT 1 FROM jobs WHERE kimi_session_id = ? AND job_id != ? LIMIT 1", sessionId, exceptJobId));
209
- }
210
- /** Every job recorded for a Kimi session, across repos and states, oldest first. */
211
- listJobsBySessionId(sessionId) {
212
- return this.db.all("SELECT * FROM jobs WHERE kimi_session_id = ? ORDER BY created_at", sessionId).map(hydrateRow);
213
- }
214
- findLatestJob(options) {
215
- const conditions = ["repo_id = @repo_id"];
216
- const params = {
217
- repo_id: options.repoId,
218
- };
219
- if (options.commandType) {
220
- conditions.push("command_type = @command_type");
221
- params.command_type = options.commandType;
222
- }
223
- if (options.terminalOnly) {
224
- conditions.push("status IN ('completed', 'failed', 'cancelled')");
225
- }
226
- if (options.runningOnly) {
227
- conditions.push("status = 'running'");
228
- }
229
- const row = this.db.get(`SELECT * FROM jobs WHERE ${conditions.join(" AND ")} ORDER BY updated_at DESC LIMIT 1`, params);
230
- return row ? hydrateRow(row) : null;
231
- }
232
- listRunningJobsWithProcessHints() {
233
- const rows = this.db.all(`SELECT * FROM jobs WHERE status = 'running' AND (pid IS NOT NULL OR kimi_pid IS NOT NULL)`);
234
- return rows.map(hydrateRow);
235
- }
236
- findRescueJobBySession(repoId, sessionId) {
237
- return this.findJobBySession("rescue", repoId, sessionId);
238
- }
239
- findAskJobBySession(repoId, sessionId) {
240
- return this.findJobBySession("ask", repoId, sessionId);
241
- }
242
- findJobBySession(commandType, repoId, sessionId) {
243
- const row = this.db.get(`
244
- SELECT *
245
- FROM jobs
246
- WHERE repo_id = ?
247
- AND command_type = ?
248
- AND kimi_session_id = ?
249
- ORDER BY updated_at DESC
250
- LIMIT 1
251
- `, repoId, commandType, sessionId);
252
- return row ? hydrateRow(row) : null;
253
- }
254
- createMcpTask(input) {
255
- const now = new Date().toISOString();
256
- try {
257
- this.db.run(`
258
- INSERT INTO mcp_tasks (
259
- task_id, operation_kind, repo_id, workspace_cwd, companion_pid, companion_identity, kimi_identity,
260
- stdout_path, stderr_path, launch_state, launch_error, created_at, attached_at, updated_at
261
- ) VALUES (
262
- @task_id, @operation_kind, @repo_id, @workspace_cwd, NULL, NULL, NULL,
263
- @stdout_path, @stderr_path, 'starting', NULL, @created_at, NULL, @updated_at
264
- )
265
- `, { ...input, created_at: now, updated_at: now });
266
- }
267
- catch (error) {
268
- throw translateSqliteError(error);
269
- }
270
- return this.getMcpTask(input.task_id);
271
- }
272
- getMcpTask(taskId) {
273
- return this.db.get("SELECT * FROM mcp_tasks WHERE task_id = ?", taskId) ?? null;
274
- }
275
- updateMcpTask(taskId, patch) {
276
- const updates = ["updated_at = @updated_at"];
277
- const params = { task_id: taskId, updated_at: new Date().toISOString() };
278
- for (const key of ["companion_pid", "companion_identity", "kimi_identity", "launch_state", "launch_error", "attached_at"]) {
279
- const value = patch[key];
280
- if (value === undefined)
281
- continue;
282
- updates.push(`${key} = @${key}`);
283
- params[key] = value;
284
- }
285
- this.db.run(`UPDATE mcp_tasks SET ${updates.join(", ")} WHERE task_id = @task_id`, params);
286
- return this.getMcpTask(taskId);
287
- }
288
- /** Terminal states are permanent: every update is guarded by status = 'running'. */
289
- updateRunningJob(jobId, patch) {
290
- const updates = ["updated_at = @updated_at"];
291
- const params = {
292
- job_id: jobId,
293
- updated_at: new Date().toISOString(),
294
- };
295
- for (const [key, value] of Object.entries(serializePatch(patch))) {
296
- if (value === undefined || !UPDATABLE_JOB_COLUMNS.has(key))
297
- continue;
298
- updates.push(`${key} = @${key}`);
299
- params[key] = value;
300
- }
301
- this.db.run(`
302
- UPDATE jobs
303
- SET ${updates.join(", ")}
304
- WHERE job_id = @job_id AND status = 'running'
305
- `, params);
306
- return this.getJob(jobId);
307
- }
308
- /** Recheck uniqueness atomically: another worker can claim an ID during the
309
- * asynchronous directory scan. Ordinary announced/resumed IDs may be shared. */
310
- claimRecoveredSessionId(jobId, sessionId) {
311
- this.db.run(`UPDATE jobs
312
- SET kimi_session_id = @session_id, kimi_session_id_source = 'recovered_session_dir',
313
- updated_at = @updated_at
314
- WHERE job_id = @job_id AND status = 'running' AND kimi_session_id IS NULL
315
- AND NOT EXISTS (SELECT 1 FROM jobs WHERE kimi_session_id = @session_id AND job_id != @job_id)`, { job_id: jobId, session_id: sessionId, updated_at: new Date().toISOString() });
316
- const job = this.getJob(jobId);
317
- return job?.status === "running" && job.kimi_session_id === sessionId &&
318
- job.kimi_session_id_source === "recovered_session_dir" ? job : null;
319
- }
320
- /**
321
- * Evidence-only backfill for pre-provenance rows. COALESCE prevents forensic
322
- * inspection from overwriting a field already recorded at execution time.
323
- * updated_at is intentionally unchanged so a status lookup cannot reorder
324
- * historical jobs merely because their logs were inspected.
325
- */
326
- backfillHistoricalProvenance(jobId, patch) {
327
- this.db.run(`
328
- UPDATE jobs
329
- SET operation_kind = COALESCE(operation_kind, @operation_kind),
330
- observed_engine = COALESCE(observed_engine, @observed_engine),
331
- kimi_version = COALESCE(kimi_version, @kimi_version),
332
- system_version = COALESCE(system_version, @system_version)
333
- WHERE job_id = @job_id
334
- `, {
335
- job_id: jobId,
336
- operation_kind: patch.operation_kind ?? null,
337
- observed_engine: patch.observed_engine ?? null,
338
- kimi_version: patch.kimi_version ?? null,
339
- system_version: patch.system_version ?? null,
340
- });
341
- return this.getJob(jobId);
342
- }
343
- markCompleted(jobId, patch) {
344
- return this.updateRunningJob(jobId, { ...patch, status: "completed", pid: null, kimi_pid: null });
345
- }
346
- markFailed(jobId, patch) {
347
- return this.updateRunningJob(jobId, { ...patch, status: "failed", pid: null, kimi_pid: null });
348
- }
349
- markCancelled(jobId, patch) {
350
- return this.updateRunningJob(jobId, { ...patch, status: "cancelled", pid: null, kimi_pid: null });
351
- }
352
- }
353
- /** Columns added after the first schema, in the order older stores receive them. */
354
- const ADDED_JOB_COLUMNS = [
355
- ["phase", "TEXT"],
356
- ["budget_ms", "INTEGER"],
357
- ["kimi_session_id_source", "TEXT"],
358
- ["budget_source", "TEXT"],
359
- ["thinking_effort", "TEXT"],
360
- ["hook_escapes", "TEXT"],
361
- // Additive provenance migration. Existing rows deliberately remain NULL:
362
- // v1.9.5 plus kimi-code 0.33/0.34 could have routed to native v2 before the
363
- // legacy pin landed, so a blanket historical v1 backfill would invent fact.
364
- ["operation_kind", "TEXT"],
365
- ["intended_engine", "TEXT"],
366
- ["observed_engine", "TEXT"],
367
- ["kimi_version", "TEXT"],
368
- ["system_version", "TEXT"],
369
- ["kimi_command", "TEXT"],
370
- ["kimi_prefix_args", "TEXT"],
371
- ["plan_certification", "TEXT"],
372
- ["resumed_from_job_id", "TEXT"],
373
- ["safety_profile", "TEXT"],
374
- ["warnings", "TEXT"],
375
- ["read_scope", "TEXT"],
376
- ];
377
- /** Columns createJob writes, in INSERT order. hook_escapes is written only by updates. */
378
- const INSERT_JOB_COLUMNS = [
379
- "job_id", "repo_id", "command_type", "created_at", "updated_at", "cwd", "model", "thinking", "thinking_effort",
380
- "background", "pid", "kimi_pid", "status", "kimi_session_id", "kimi_session_id_source", "budget_source",
381
- "operation_kind", "intended_engine", "observed_engine", "kimi_version", "system_version",
382
- "kimi_command", "kimi_prefix_args", "plan_certification", "resumed_from_job_id", "safety_profile", "warnings",
383
- "read_scope", "agent_profile", "prompt_digest", "summary", "phase", "budget_ms", "final_output_path", "stream_log_path", "error",
384
- ];
385
- const INSERT_JOB_SQL = `INSERT INTO jobs (${INSERT_JOB_COLUMNS.join(", ")}) VALUES (${INSERT_JOB_COLUMNS.map((column) => `@${column}`).join(", ")})`;
386
- /** Columns an update may set; identity and timestamps are store-owned. */
387
- const UPDATABLE_JOB_COLUMNS = new Set([
388
- ...INSERT_JOB_COLUMNS.filter((column) => column !== "job_id" && column !== "created_at" && column !== "updated_at"),
389
- "hook_escapes",
390
- ]);
391
- function hydrateRow(row) {
392
- // A warning-free row keeps its historical shape, so every JSON surface that
393
- // spreads a JobRecord stays byte-identical.
394
- const { warnings, read_scope, ...rest } = row;
395
- return {
396
- ...rest,
397
- ...(warnings !== null && warnings !== undefined ? { warnings } : {}),
398
- ...(read_scope !== null && read_scope !== undefined ? { read_scope } : {}),
399
- thinking: row.thinking === null ? null : Boolean(row.thinking),
400
- background: Boolean(row.background),
401
- error: row.error ? JSON.parse(row.error) : null,
402
- };
403
- }
404
- // Spreads the whole input so node:sqlite still rejects keys that are not INSERT parameters.
405
- function serializeRecord(record) {
406
- const row = { ...record };
407
- for (const column of INSERT_JOB_COLUMNS)
408
- row[column] ??= null;
409
- return {
410
- ...row,
411
- thinking: record.thinking === null ? null : Number(record.thinking),
412
- background: Number(record.background),
413
- error: record.error ? JSON.stringify(record.error) : null,
414
- };
415
- }
416
- function serializePatch(patch) {
417
- const result = {};
418
- for (const [key, value] of Object.entries(patch)) {
419
- if (key === "thinking") {
420
- result[key] = value === null ? null : Number(Boolean(value));
421
- continue;
422
- }
423
- if (key === "background") {
424
- result[key] = Number(Boolean(value));
425
- continue;
426
- }
427
- if (key === "error") {
428
- result[key] = value ? JSON.stringify(value) : null;
429
- continue;
430
- }
431
- result[key] = value;
432
- }
433
- return result;
434
- }
435
- function createSqliteAdapter(filename) {
436
- const require = createRequire(import.meta.url);
437
- if (typeof Bun !== "undefined") {
438
- const { Database } = require("bun:sqlite");
439
- const db = new Database(filename);
440
- return {
441
- pragma(statement) {
442
- db.exec(`PRAGMA ${statement}`);
443
- },
444
- exec(statement) {
445
- db.exec(statement);
446
- },
447
- run(statement, params) {
448
- const query = db.query(rewriteNamedParamsForBun(statement));
449
- if (Array.isArray(params)) {
450
- query.run(...params);
451
- return;
452
- }
453
- query.run(rewriteNamedBindingsForBun((params ?? {})));
454
- },
455
- get(statement, ...params) {
456
- const query = db.query(rewriteNamedParamsForBun(statement));
457
- if (params.length === 1) {
458
- const first = params[0];
459
- return query.get(typeof first === "object" && first !== null && !Array.isArray(first)
460
- ? rewriteNamedBindingsForBun(first)
461
- : first);
462
- }
463
- return query.get(...params);
464
- },
465
- all(statement, ...params) {
466
- const query = db.query(rewriteNamedParamsForBun(statement));
467
- if (params.length === 1) {
468
- const first = params[0];
469
- return query.all(typeof first === "object" && first !== null && !Array.isArray(first)
470
- ? rewriteNamedBindingsForBun(first)
471
- : first);
472
- }
473
- return query.all(...params);
474
- },
475
- close() {
476
- db.close();
477
- },
478
- };
479
- }
480
- // Node 22.5+ ships node:sqlite as a built-in. We use it via createRequire so the compiled
481
- // dist/ has zero native dependencies — no `bun install` step required for drop-in plugin
482
- // installs, no platform-specific compiled binaries to ship. See package.json engines.node.
483
- let nodeSqlite;
484
- try {
485
- nodeSqlite = require("node:sqlite");
486
- }
487
- catch (error) {
488
- throw new RuntimeError("JOB_STORE_UNSUPPORTED_RUNTIME", "kimi-plugin-cc requires Node >= 22.5 for its built-in node:sqlite module. Upgrade Node, or set KIMI_PLUGIN_CC_NODE_BIN to a qualifying binary.", "job-store", error instanceof Error ? { cause: error } : undefined);
489
- }
490
- const db = new nodeSqlite.DatabaseSync(filename);
491
- return {
492
- pragma(statement) {
493
- db.exec(`PRAGMA ${statement}`);
494
- },
495
- exec(statement) {
496
- db.exec(statement);
497
- },
498
- run(statement, params) {
499
- // Cast through `any` so the prepared-statement methods are called as methods (preserving
500
- // `this`). Pulling them off the instance via `const fn = stmt.run` strips the binding and
501
- // node:sqlite throws "Illegal invocation".
502
- const stmt = db.prepare(statement);
503
- if (Array.isArray(params)) {
504
- stmt.run(...params);
505
- return;
506
- }
507
- stmt.run(normalizeNodeSqliteBindings((params ?? {})));
508
- },
509
- get(statement, ...params) {
510
- const stmt = db.prepare(statement);
511
- if (params.length === 1 && isPlainObject(params[0])) {
512
- return stmt.get(normalizeNodeSqliteBindings(params[0]));
513
- }
514
- return stmt.get(...params);
515
- },
516
- all(statement, ...params) {
517
- const stmt = db.prepare(statement);
518
- if (params.length === 1 && isPlainObject(params[0])) {
519
- return stmt.all(normalizeNodeSqliteBindings(params[0]));
520
- }
521
- return stmt.all(...params);
522
- },
523
- close() {
524
- db.close();
525
- },
526
- };
527
- }
528
- // node:sqlite's prepared-statement binding API accepts objects whose keys omit the parameter
529
- // prefix (so SQL `@job_id` binds from `{ job_id: ... }`). Normalize optional values to null,
530
- // coerce booleans to 0/1, and fail fast on unsupported binding types before they reach the
531
- // native layer as opaque SQLITE_MISMATCH errors.
532
- function normalizeNodeSqliteBindings(bindings) {
533
- const result = {};
534
- for (const [key, value] of Object.entries(bindings)) {
535
- if (value === undefined) {
536
- result[key] = null;
537
- continue;
538
- }
539
- if (value === null) {
540
- result[key] = null;
541
- continue;
542
- }
543
- if (typeof value === "boolean") {
544
- result[key] = value ? 1 : 0;
545
- continue;
546
- }
547
- if (typeof value === "string" ||
548
- typeof value === "number" ||
549
- typeof value === "bigint" ||
550
- value instanceof Uint8Array) {
551
- result[key] = value;
552
- continue;
553
- }
554
- throw new Error(`node:sqlite binding for ${key} has unsupported type ${typeof value} (${value?.constructor?.name ?? "unknown"})`);
555
- }
556
- return result;
557
- }
558
- function isPlainObject(value) {
559
- return typeof value === "object" && value !== null && !Array.isArray(value);
560
- }
561
- function rewriteNamedParamsForBun(statement) {
562
- return statement.replaceAll(/@([A-Za-z0-9_]+)/g, (_, key) => `$${key}`);
563
- }
564
- function rewriteNamedBindingsForBun(bindings) {
565
- return Object.fromEntries(Object.entries(bindings).map(([key, value]) => [`$${key}`, value]));
566
- }
567
- function existingColumns(db, table) {
568
- return new Set(db.all(`PRAGMA table_info(${table})`).map((column) => column.name));
569
- }
570
- function isSqliteConstraintError(error) {
571
- const message = formatError(error).toLowerCase();
572
- return message.includes("unique constraint") || message.includes("constraint failed");
573
- }
574
- function isSqliteBusyError(error) {
575
- const message = formatError(error).toLowerCase();
576
- return message.includes("database is locked") || message.includes("busy");
577
- }
578
- function translateSqliteError(error) {
579
- if (isSqliteBusyError(error)) {
580
- return new RuntimeError("JOB_STORE_BUSY", "The plugin job store is locked by another process. Wait a moment and retry, or check for stuck rescue workers with /kimi:status.", "job-store", error instanceof Error ? { cause: error } : undefined);
581
- }
582
- if (error instanceof RuntimeError) {
583
- return error;
584
- }
585
- return new RuntimeError("JOB_STORE_ERROR", `Job store operation failed: ${formatError(error)}`, "job-store", error instanceof Error ? { cause: error } : undefined);
586
- }
587
- /**
588
- * Run a function with a temporary `JobStore`, closing its handle on return or
589
- * throw after construction succeeds. The constructor owns cleanup when opening
590
- * or migrating the store fails.
591
- */
592
- export async function withJobStore(paths, fn) {
593
- // Keep construction inside try: the constructor cleans up its own failures,
594
- // while this finally closes every successfully constructed store.
595
- let store;
596
- try {
597
- store = new JobStore(paths);
598
- return await fn(store);
599
- }
600
- finally {
601
- store?.close();
602
- }
603
- }
604
- /** Parsed `hook_escapes` column for JSON envelopes: [] when NULL or unreadable. */
605
- export function parseHookEscapes(raw) {
606
- if (!raw)
607
- return [];
608
- try {
609
- const parsed = JSON.parse(raw);
610
- return Array.isArray(parsed) ? parsed : [];
611
- }
612
- catch {
613
- return [];
614
- }
615
- }
616
- /** Parsed `warnings` column: [] when NULL or unreadable. */
617
- export function parseJobWarnings(raw) {
618
- if (!raw)
619
- return [];
620
- try {
621
- const parsed = JSON.parse(raw);
622
- return Array.isArray(parsed) ? parsed.filter((entry) => typeof entry === "string") : [];
623
- }
624
- catch {
625
- return [];
626
- }
627
- }
628
- /** Old non-null budgets have unknown provenance; never invent explicit intent. */
629
- export function renderBudgetSource(job) {
630
- return job.budget_source ?? (job.budget_ms === null ? "default" : "unknown");
631
- }