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,435 +0,0 @@
1
- import { realpathSync } from "node:fs";
2
- import { lstat, realpath, stat } from "node:fs/promises";
3
- import path from "node:path";
4
- import { RuntimeError } from "./errors.js";
5
- /**
6
- * Per-call scope for the read-only operations (ask, review, challenge,
7
- * read-only swarm). kimi-code approves Read, Grep, Glob, ReadMediaFile,
8
- * WebSearch and FetchURL itself, so the PreToolUse hook is the only place
9
- * these can be scoped. Web access is coupled to read confinement: a job that
10
- * can send data out may read only the workspace and the caller's read roots.
11
- *
12
- * The plugin sets or deletes both variables on every spawn; the hook reads
13
- * only these, never the hook payload's cwd.
14
- */
15
- export const READ_ROOTS_ENV = "KIMI_PLUGIN_CC_READ_ROOTS";
16
- export const NETWORK_ENV = "KIMI_PLUGIN_CC_NETWORK";
17
- /** Hook labels that may carry a non-default scope. */
18
- export const READ_SCOPE_LABELS = new Set(["ask", "review", "challenge", "swarm"]);
19
- export const SCOPE_FLAGS_WRITE_MESSAGE = "--read-root and --network apply only to read-only operations (ask, review, challenge, read-only swarm). " +
20
- "Write-capable operations can read through allowlisted shell commands, so read confinement could not be honoured there.";
21
- /** Validate --read-root values and build the scope; undefined means the default scope. */
22
- export async function resolveReadScope(readRoots, network, stage) {
23
- const requested = readRoots ?? [];
24
- if (requested.length === 0 && network !== true)
25
- return undefined;
26
- const resolved = [];
27
- for (const root of requested) {
28
- if (!path.isAbsolute(root)) {
29
- throw new RuntimeError("INVALID_ARGS", `--read-root must be an absolute directory path; got "${root}".`, stage);
30
- }
31
- let real;
32
- if (root.includes("\\")) {
33
- throw new RuntimeError("INVALID_ARGS", `--read-root ${root} contains a backslash, which kimi-code reads as a path separator.`, stage);
34
- }
35
- try {
36
- real = await realpath(root);
37
- if (!(await stat(real)).isDirectory())
38
- throw new Error("not a directory");
39
- }
40
- catch {
41
- throw new RuntimeError("INVALID_ARGS", `--read-root ${root} is not an existing directory.`, stage);
42
- }
43
- if (real.includes("\\")) {
44
- throw new RuntimeError("INVALID_ARGS", `--read-root ${root} contains a backslash, which kimi-code reads as a path separator.`, stage);
45
- }
46
- if (!resolved.includes(real))
47
- resolved.push(real);
48
- }
49
- return Object.freeze({ readRoots: Object.freeze(resolved), network: network === true });
50
- }
51
- /**
52
- * Read confinement rests on tool schemas verified at certified releases only.
53
- * --read-root can only narrow, so it runs anywhere; --network is the
54
- * relaxation and is refused on an uncertified release.
55
- */
56
- export function assertScopeSupported(scope, certification, code, stage) {
57
- if (scope?.network === true && certification === "uncertified") {
58
- throw new RuntimeError(code, "--network is refused on an uncertified kimi-code release: read confinement is verified only against certified releases. Run without --network, or install a certified kimi-code release.", stage);
59
- }
60
- }
61
- /** The roots the hook confines reads to: the run directory first, then the read roots. */
62
- export function effectiveReadRoots(scope, cwd) {
63
- // Root 1 is the directory kimi runs in, so relative and defaulted tool
64
- // paths resolve inside it exactly as upstream resolves them.
65
- if (cwd.includes("\\")) {
66
- throw new RuntimeError("READ_SCOPE_INVALID", `Read confinement cannot use ${cwd}: it contains a backslash, which kimi-code reads as a path separator.`, "read-scope.roots");
67
- }
68
- const roots = [realpathSync.native(cwd)];
69
- for (const root of scope.readRoots)
70
- if (!roots.includes(root))
71
- roots.push(root);
72
- // kimi-code resolves with pathe, which reads "\\" as a separator, so such a
73
- // root would name a different directory to kimi than to the hook.
74
- const slashed = roots.find((root) => root.includes("\\"));
75
- if (slashed !== undefined) {
76
- throw new RuntimeError("READ_SCOPE_INVALID", `Read confinement cannot use ${slashed}: it contains a backslash, which kimi-code reads as a path separator.`, "read-scope.roots");
77
- }
78
- return roots;
79
- }
80
- /** True when every root in `inner` lies within some root in `outer`. */
81
- export function rootsWithin(inner, outer) {
82
- return inner.every((root) => outer.some((candidate) => isWithin(candidate, root)));
83
- }
84
- /** Child-environment values for one spawn; both absent for the default scope. */
85
- export function readScopeEnvironment(scope, cwd) {
86
- if (scope === undefined || (scope.readRoots.length === 0 && !scope.network))
87
- return {};
88
- return {
89
- [READ_ROOTS_ENV]: JSON.stringify(effectiveReadRoots(scope, cwd)),
90
- ...(scope.network ? { [NETWORK_ENV]: "1" } : {}),
91
- };
92
- }
93
- const FAIL_CLOSED = Object.freeze({ confined: true, roots: Object.freeze([]), network: false });
94
- /**
95
- * Hook-side parse of the plugin-set variables. Both absent is the default
96
- * scope. Anything malformed (bad JSON, empty array, relative or unnormalized
97
- * entries, a network value other than "1", network without roots) confines
98
- * reads to NO roots with network off.
99
- */
100
- export function parseScopeEnvironment(rawRoots, rawNetwork) {
101
- if (rawRoots === undefined && rawNetwork === undefined)
102
- return { confined: false, network: false };
103
- if (rawRoots === undefined)
104
- return FAIL_CLOSED;
105
- if (rawNetwork !== undefined && rawNetwork !== "1")
106
- return FAIL_CLOSED;
107
- let parsed;
108
- try {
109
- parsed = JSON.parse(rawRoots);
110
- }
111
- catch {
112
- return FAIL_CLOSED;
113
- }
114
- if (!Array.isArray(parsed) || parsed.length === 0)
115
- return FAIL_CLOSED;
116
- for (const entry of parsed) {
117
- if (typeof entry !== "string" || entry.includes("\0") || entry.includes("\\") || !path.isAbsolute(entry) || path.resolve(entry) !== entry) {
118
- return FAIL_CLOSED;
119
- }
120
- }
121
- return Object.freeze({ confined: true, roots: Object.freeze([...parsed]), network: rawNetwork === "1" });
122
- }
123
- /** Persisted job-row form; NULL for the default scope so old rows keep their shape. */
124
- export function serializeReadScope(scope) {
125
- if (scope === undefined || (scope.readRoots.length === 0 && !scope.network))
126
- return null;
127
- return JSON.stringify({ read_roots: scope.readRoots, network: scope.network });
128
- }
129
- /** Inverse of serializeReadScope. A corrupt row refuses rather than run unconfined. */
130
- export function parseJobReadScope(raw) {
131
- if (raw === null || raw === undefined)
132
- return undefined;
133
- let parsed;
134
- try {
135
- parsed = JSON.parse(raw);
136
- }
137
- catch {
138
- parsed = undefined;
139
- }
140
- const record = parsed;
141
- if (typeof record !== "object" || record === null ||
142
- !Array.isArray(record.read_roots) || typeof record.network !== "boolean" ||
143
- !record.read_roots.every((root) => typeof root === "string" && path.isAbsolute(root))) {
144
- throw new RuntimeError("READ_SCOPE_INVALID", "The job's stored read scope is unreadable; refusing to run it unconfined.", "read-scope.load");
145
- }
146
- return Object.freeze({ readRoots: Object.freeze([...record.read_roots]), network: record.network });
147
- }
148
- /** Header line for a non-default scope; undefined for the default. */
149
- export function describeReadScope(scope) {
150
- if (scope === undefined || (scope.readRoots.length === 0 && !scope.network))
151
- return undefined;
152
- const roots = scope.readRoots.length === 0
153
- ? "the workspace"
154
- : `the workspace and ${scope.readRoots.length} read root${scope.readRoots.length === 1 ? "" : "s"} (${scope.readRoots.join(", ")})`;
155
- return `Scope: reads confined to ${roots}; network ${scope.network ? "on" : "off"}`;
156
- }
157
- // ---------------------------------------------------------------------------
158
- // Hook enforcement of confined reads.
159
- //
160
- // Input schemas are those of kimi-code 0.41.0 (legacy agent-core), 2.0.0 and
161
- // 2.7.3 (agent-core-v2): Read/ReadMediaFile resolve `path`; Glob and Grep
162
- // search `path` or, when omitted, the session cwd; Glob's `pattern` and Grep's
163
- // `glob` are ripgrep --glob filters inside that search root. Upstream expands
164
- // `~`, resolves relative paths against the cwd and normalizes `..` lexically
165
- // before access. ripgrep runs without --follow, so links met while walking are
166
- // skipped; links named directly are followed, hence realpath below.
167
- // ---------------------------------------------------------------------------
168
- const SCOPED_READ_KEYS = {
169
- Read: new Set(["path", "line_offset", "column_offset", "n_lines", "max_chars"]),
170
- ReadMediaFile: new Set(["path", "region", "full_resolution"]),
171
- Glob: new Set(["pattern", "path", "head_limit", "offset", "include_ignored", "include_dirs"]),
172
- Grep: new Set([
173
- "pattern", "path", "glob", "type", "output_mode", "-i", "-n", "-A", "-B", "-C",
174
- "head_limit", "offset", "multiline", "include_ignored",
175
- ]),
176
- };
177
- export const SCOPED_READ_TOOLS = new Set(Object.keys(SCOPED_READ_KEYS));
178
- class ScopeDenial extends Error {
179
- }
180
- export async function evaluateScopedRead(toolName, toolInput, roots) {
181
- const deny = (why) => ({
182
- decision: "deny",
183
- reason: `kimi-plugin-cc safety hook: reads are confined to ${roots.length === 0 ? "no readable roots (the scope variables are malformed)" : roots.join(", ")}; tool "${toolName}" denied: ${why}`,
184
- });
185
- if (roots.length === 0)
186
- return deny("no path can be read.");
187
- const allowedKeys = SCOPED_READ_KEYS[toolName];
188
- if (allowedKeys === undefined)
189
- return deny("the tool has no confinement rule.");
190
- if (typeof toolInput !== "object" || toolInput === null || Array.isArray(toolInput)) {
191
- return deny("its arguments are not an object.");
192
- }
193
- const args = toolInput;
194
- for (const key of Object.keys(args)) {
195
- if (!allowedKeys.has(key))
196
- return deny(`argument "${key}" cannot be checked.`);
197
- }
198
- try {
199
- const targets = [];
200
- if (toolName === "Read" || toolName === "ReadMediaFile") {
201
- targets.push(requirePath(args.path, "path"));
202
- }
203
- else {
204
- targets.push(args.path === undefined ? roots[0] : requirePath(args.path, "path"));
205
- const patternKey = toolName === "Glob" ? "pattern" : "glob";
206
- const pattern = args[patternKey];
207
- if (toolName === "Glob" || pattern !== undefined) {
208
- const anchor = patternAnchor(pattern, patternKey);
209
- if (anchor !== undefined)
210
- targets.push(anchor);
211
- }
212
- }
213
- for (const target of targets) {
214
- const absolute = path.isAbsolute(target) ? path.resolve(target) : path.resolve(roots[0], target);
215
- const real = await realTarget(absolute);
216
- if (!roots.some((root) => isWithin(root, real))) {
217
- return deny(`"${target}" resolves outside the read roots.`);
218
- }
219
- }
220
- }
221
- catch (error) {
222
- return deny(error instanceof ScopeDenial ? error.message : "its target could not be resolved.");
223
- }
224
- return { decision: "allow" };
225
- }
226
- function requirePath(value, key) {
227
- if (typeof value !== "string" || value.length === 0 || value.includes("\0")) {
228
- throw new ScopeDenial(`argument "${key}" is not a usable path.`);
229
- }
230
- // Upstream expands ~ against the home directory and treats kimi-file://
231
- // as a session attachment; neither target is a workspace path.
232
- if (value.startsWith("~"))
233
- throw new ScopeDenial(`"${value}" uses home-directory expansion.`);
234
- if (/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(value))
235
- throw new ScopeDenial(`"${value}" is not a filesystem path.`);
236
- denyAmbiguousSpelling(value, "path");
237
- return value;
238
- }
239
- // Upstream resolves with pathe, which reads "\\" as a separator and a drive
240
- // prefix as absolute; node:path on POSIX reads neither. Deny those spellings
241
- // instead of imitating pathe.
242
- function denyAmbiguousSpelling(value, noun) {
243
- if (value.includes("\\"))
244
- throw new ScopeDenial(`${noun} "${value}" contains a backslash.`);
245
- if (/^[A-Za-z]:/.test(value))
246
- throw new ScopeDenial(`${noun} "${value}" starts with a drive letter.`);
247
- }
248
- /** Literal directory an absolute glob names; undefined for a relative glob. */
249
- function patternAnchor(value, key) {
250
- if (typeof value !== "string" || value.includes("\0")) {
251
- throw new ScopeDenial(`argument "${key}" is not a usable glob.`);
252
- }
253
- const body = value.startsWith("!") ? value.slice(1) : value;
254
- if (body.startsWith("~"))
255
- throw new ScopeDenial(`glob "${value}" uses home-directory expansion.`);
256
- denyAmbiguousSpelling(body, "glob");
257
- const segments = body.split("/");
258
- if (segments.includes(".."))
259
- throw new ScopeDenial(`glob "${value}" climbs with "..".`);
260
- if (!path.isAbsolute(body))
261
- return undefined;
262
- const literal = [];
263
- for (const segment of segments) {
264
- if (/[*?[\]{}!]/.test(segment))
265
- break;
266
- literal.push(segment);
267
- }
268
- return literal.join("/") || "/";
269
- }
270
- /** Physical location of `absolute`: realpath when it exists, else the nearest existing ancestor's. */
271
- async function realTarget(absolute) {
272
- try {
273
- return await realpath(absolute);
274
- }
275
- catch (error) {
276
- const code = error.code;
277
- if (code !== "ENOENT" && code !== "ENOTDIR")
278
- throw error;
279
- }
280
- // A dangling link may later point anywhere; only a truly absent path falls back.
281
- try {
282
- await lstat(absolute);
283
- throw new ScopeDenial(`"${absolute}" is a link whose target cannot be resolved.`);
284
- }
285
- catch (error) {
286
- if (error instanceof ScopeDenial)
287
- throw error;
288
- }
289
- let ancestor = path.dirname(absolute);
290
- while (true) {
291
- try {
292
- const real = await realpath(ancestor);
293
- return path.resolve(real, path.relative(ancestor, absolute));
294
- }
295
- catch (error) {
296
- const code = error.code;
297
- if (code !== "ENOENT" && code !== "ENOTDIR")
298
- throw error;
299
- const parent = path.dirname(ancestor);
300
- if (parent === ancestor)
301
- throw error;
302
- ancestor = parent;
303
- }
304
- }
305
- }
306
- function isWithin(root, candidate) {
307
- const relative = path.relative(root, candidate);
308
- return relative === "" || (relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
309
- }
310
- // ---------------------------------------------------------------------------
311
- // FetchURL targets under --network: http(s) without credentials, and never a
312
- // local name or an IP literal that is not global unicast. The WHATWG parser
313
- // canonicalizes the hostname; the raw authority is compared so that integer,
314
- // hex, octal or percent-encoded IPv4 spellings are refused rather than decoded.
315
- // ---------------------------------------------------------------------------
316
- const NON_GLOBAL_IPV4 = [
317
- [0x00000000, 8], // this network
318
- [0x0a000000, 8], // private
319
- [0x64400000, 10], // shared address space
320
- [0x7f000000, 8], // loopback
321
- [0xa9fe0000, 16], // link-local
322
- [0xac100000, 12], // private
323
- [0xc0000000, 24], // IETF protocol assignments
324
- [0xc0000200, 24], // documentation
325
- [0xc0586300, 24], // deprecated 6to4 relay anycast
326
- [0xc0a80000, 16], // private
327
- [0xc6120000, 15], // benchmarking
328
- [0xc6336400, 24], // documentation
329
- [0xcb007100, 24], // documentation
330
- [0xe0000000, 4], // multicast
331
- [0xf0000000, 4], // reserved, including broadcast
332
- ];
333
- /** True when `url` is an allowed FetchURL target. */
334
- export function isAllowedFetchUrl(url) {
335
- if (typeof url !== "string" || !/^https?:\/\//i.test(url))
336
- return false;
337
- let parsed;
338
- try {
339
- parsed = new URL(url);
340
- }
341
- catch {
342
- return false;
343
- }
344
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
345
- return false;
346
- if (parsed.username !== "" || parsed.password !== "")
347
- return false;
348
- const host = parsed.hostname;
349
- if (host.startsWith("[")) {
350
- const hextets = ipv6Hextets(host.slice(1, -1));
351
- return hextets !== undefined && isGlobalIpv6(hextets);
352
- }
353
- const ipv4 = ipv4Value(host);
354
- if (ipv4 !== undefined) {
355
- // The parser accepts many IPv4 spellings; only the canonical one is allowed.
356
- if (rawHost(url) !== host)
357
- return false;
358
- return isGlobalIpv4(ipv4);
359
- }
360
- const name = host.replace(/\.+$/, "");
361
- if (name.length === 0 || /^[0-9]+$/.test(name))
362
- return false;
363
- return !(name === "localhost" || name.endsWith(".localhost") || name.endsWith(".local") || name.endsWith(".internal"));
364
- }
365
- function rawHost(url) {
366
- const authority = url.replace(/^https?:\/\//i, "").split(/[/\\?#]/, 1)[0];
367
- const hostPort = authority.slice(authority.lastIndexOf("@") + 1);
368
- return hostPort.replace(/:[0-9]*$/, "").toLowerCase();
369
- }
370
- function ipv4Value(host) {
371
- const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
372
- if (!match)
373
- return undefined;
374
- const octets = match.slice(1).map(Number);
375
- if (octets.some((octet) => octet > 255))
376
- return undefined;
377
- return ((octets[0] << 24) >>> 0) + (octets[1] << 16) + (octets[2] << 8) + octets[3];
378
- }
379
- function inRange(value, base, bits) {
380
- const mask = bits === 0 ? 0 : (0xffffffff << (32 - bits)) >>> 0;
381
- return ((value & mask) >>> 0) === base;
382
- }
383
- function ipv6Hextets(text) {
384
- const halves = text.split("::");
385
- if (halves.length > 2)
386
- return undefined;
387
- const parse = (part) => {
388
- if (part === "")
389
- return [];
390
- const out = [];
391
- for (const piece of part.split(":")) {
392
- if (piece.includes(".")) {
393
- const v4 = ipv4Value(piece);
394
- if (v4 === undefined)
395
- return undefined;
396
- out.push(v4 >>> 16, v4 & 0xffff);
397
- }
398
- else if (/^[0-9a-f]{1,4}$/i.test(piece)) {
399
- out.push(parseInt(piece, 16));
400
- }
401
- else {
402
- return undefined;
403
- }
404
- }
405
- return out;
406
- };
407
- const head = parse(halves[0]);
408
- const tail = halves.length === 2 ? parse(halves[1]) : [];
409
- if (head === undefined || tail === undefined)
410
- return undefined;
411
- const fill = 8 - head.length - tail.length;
412
- if (halves.length === 2 ? fill < 0 : fill !== 0)
413
- return undefined;
414
- return [...head, ...new Array(halves.length === 2 ? fill : 0).fill(0), ...tail];
415
- }
416
- function isGlobalIpv4(value) {
417
- return !NON_GLOBAL_IPV4.some(([base, bits]) => inRange(value, base, bits));
418
- }
419
- /** Only global unicast 2000::/3, less its special-purpose blocks; NAT64 by its IPv4. */
420
- function isGlobalIpv6(h) {
421
- if (h[0] === 0x64 && h[1] === 0xff9b && h.slice(2, 6).every((part) => part === 0)) {
422
- return isGlobalIpv4(((h[6] << 16) >>> 0) + h[7]);
423
- }
424
- if ((h[0] & 0xe000) !== 0x2000)
425
- return false;
426
- if (h[0] === 0x2001 && h[1] < 0x0200)
427
- return false; // 2001::/23 IETF assignments, Teredo 2001::/32
428
- if (h[0] === 0x2001 && h[1] === 0x0db8)
429
- return false; // documentation
430
- if (h[0] === 0x2002)
431
- return false; // 6to4 embeds an IPv4 address
432
- if (h[0] === 0x3fff && h[1] < 0x1000)
433
- return false; // documentation 3fff::/20
434
- return true;
435
- }
@@ -1,214 +0,0 @@
1
- import { readFile, writeFile } from "node:fs/promises";
2
- import path from "node:path";
3
- import { parseJobWarnings } from "./job-store.js";
4
- import { describeReadScope, parseJobReadScope } from "./read-scope.js";
5
- import { getManagedCommandConfig } from "./commands/registry.js";
6
- import { RuntimeError } from "./errors.js";
7
- import { parseReviewGateOutput } from "./schemas/review-gate-output.js";
8
- const EMPTY_SUMMARY_FALLBACK = "Rescue did not return a final message.";
9
- export async function writeArtifact(paths, job, markdown) {
10
- const artifactPath = path.join(paths.artifactsDir, `${job.command_type}-${job.job_id}.md`);
11
- await writeFile(artifactPath, markdown.endsWith("\n") ? markdown : `${markdown}\n`, "utf8");
12
- return artifactPath;
13
- }
14
- export async function readArtifact(artifactPath) {
15
- return readFile(artifactPath, "utf8");
16
- }
17
- /**
18
- * Prefix a "Warnings:" block when the job carries launch warnings. Wrapper
19
- * models read stdout and artifacts, never stderr, so this is the load-bearing
20
- * copy. Without warnings the text is returned unchanged, byte for byte.
21
- */
22
- export function withWarningsBlock(job, text) {
23
- const warnings = parseJobWarnings(job.warnings);
24
- if (warnings.length === 0)
25
- return text;
26
- return `Warnings:\n${warnings.map((warning) => `- ${warning}`).join("\n")}\n\n${text}`;
27
- }
28
- /** Prefix the non-default read scope so callers see what they asked for; unchanged otherwise. */
29
- export function withScopeLine(job, text) {
30
- const line = describeReadScope(parseJobReadScope(job.read_scope));
31
- return line === undefined ? text : `${line}\n\n${text}`;
32
- }
33
- export function renderManagedJobOutput(job, finalText) {
34
- const rendered = renderManagedJobOutputBody(job, finalText);
35
- if (parseJobWarnings(job.warnings).length === 0 && !job.read_scope)
36
- return rendered;
37
- const decorate = (text) => withWarningsBlock(job, withScopeLine(job, text));
38
- return {
39
- ...rendered,
40
- // review_gate's output is the parsed decision object; its warnings live in the artifact only.
41
- output: typeof rendered.output === "string" ? decorate(rendered.output) : rendered.output,
42
- rendered: decorate(rendered.rendered),
43
- };
44
- }
45
- function renderManagedJobOutputBody(job, finalText) {
46
- assertOutputModeConsistency(job.command_type, finalText);
47
- switch (job.command_type) {
48
- case "ask": {
49
- const trimmed = finalText.trim();
50
- if (!trimmed) {
51
- throw new RuntimeError("ASK_EMPTY_OUTPUT", "ask returned an empty final response.", "ask.prompt");
52
- }
53
- return {
54
- output: trimmed,
55
- rendered: trimmed,
56
- summary: trimmed.slice(0, 160),
57
- };
58
- }
59
- case "review":
60
- case "challenge": {
61
- const trimmed = finalText.trim();
62
- if (!trimmed) {
63
- throw new RuntimeError(job.command_type === "challenge" ? "CHALLENGE_EMPTY_OUTPUT" : "REVIEW_EMPTY_OUTPUT", `${job.command_type} returned an empty final response.`, `${job.command_type}.prompt`);
64
- }
65
- return {
66
- output: trimmed,
67
- rendered: renderReviewArtifact(job, trimmed),
68
- summary: firstMeaningfulLine(trimmed),
69
- };
70
- }
71
- case "review_gate": {
72
- const output = parseReviewGateOutput(finalText.trim());
73
- return {
74
- output,
75
- rendered: renderReviewGateArtifact(job, output),
76
- summary: output.summary,
77
- };
78
- }
79
- case "rescue": {
80
- const trimmed = finalText.trim();
81
- if (!trimmed) {
82
- throw new RuntimeError("RESCUE_EMPTY_OUTPUT", "Rescue returned empty output.", "rescue.runtime");
83
- }
84
- return {
85
- output: finalText,
86
- rendered: renderRescueArtifact(finalText),
87
- summary: firstMeaningfulLine(finalText),
88
- };
89
- }
90
- default:
91
- return assertNever(job.command_type);
92
- }
93
- }
94
- export function assertOutputModeConsistency(commandType, finalText) {
95
- const { outputMode } = getManagedCommandConfig(commandType);
96
- switch (outputMode) {
97
- case "passthrough":
98
- return;
99
- case "parsed":
100
- try {
101
- JSON.parse(finalText);
102
- }
103
- catch (error) {
104
- throw new RuntimeError(`${commandType.toUpperCase()}_PARSE_FAILED`, `${commandType} is configured for parsed output but returned malformed JSON: ${error.message}`, `${commandType}.parse`, error instanceof Error ? { cause: error } : undefined);
105
- }
106
- return;
107
- default:
108
- return assertNever(outputMode);
109
- }
110
- }
111
- export function renderReviewArtifact(job, output) {
112
- const header = [
113
- `# ${job.command_type === "challenge" ? "Challenge" : "Review"} Result`,
114
- "",
115
- `- Job: ${job.job_id}`,
116
- ...(job.kimi_session_id ? [`- Kimi session: ${job.kimi_session_id}`] : []),
117
- ].join("\n");
118
- // Blank line between header and body, plus trailing newline so the rendered
119
- // string is well-formed even before writeArtifact's newline normalization.
120
- return `${header}\n\n${output.trim()}\n`;
121
- }
122
- export function renderRescueArtifact(rawOutput) {
123
- return rawOutput.endsWith("\n") ? rawOutput : `${rawOutput}\n`;
124
- }
125
- export function firstMeaningfulLine(text, fallback = EMPTY_SUMMARY_FALLBACK) {
126
- const line = String(text ?? "")
127
- .split(/\r?\n/)
128
- .map((value) => value.trim())
129
- .find(Boolean);
130
- return line ?? fallback;
131
- }
132
- export function renderReviewGateArtifact(job, output) {
133
- const lines = [
134
- "# Review Gate Result",
135
- "",
136
- `- Job: ${job.job_id}`,
137
- `- Decision: ${output.decision}`,
138
- `- Confidence: ${output.confidence}`,
139
- `- Summary: ${output.summary}`,
140
- ...(job.kimi_session_id ? [`- Kimi session: ${job.kimi_session_id}`] : []),
141
- ];
142
- if (output.issues.length === 0) {
143
- lines.push("", "No issues.");
144
- return `${lines.join("\n")}\n`;
145
- }
146
- lines.push("", "## Issues");
147
- for (const issue of output.issues) {
148
- lines.push("", `### ${issue.title}`, `- Severity: ${issue.severity}`, issue.body);
149
- }
150
- return `${lines.join("\n")}\n`;
151
- }
152
- export function formatBudgetDuration(ms) {
153
- if (ms % 3_600_000 === 0)
154
- return `${ms / 3_600_000}h`;
155
- if (ms % 60_000 === 0)
156
- return `${ms / 60_000}m`;
157
- if (ms % 1_000 === 0)
158
- return `${ms / 1_000}s`;
159
- return `${ms}ms`;
160
- }
161
- export function renderTerminalJobArtifact(job, partialOutput) {
162
- const lines = [
163
- `# ${capitalize(job.status)} Job`,
164
- "",
165
- `- Job: ${job.job_id}`,
166
- `- Command: ${job.command_type}`,
167
- `- Status: ${job.status}`,
168
- `- Summary: ${job.summary}`,
169
- ...(job.kimi_session_id ? [`- Kimi session: ${job.kimi_session_id}`] : []),
170
- ...terminalScopeLine(job),
171
- ];
172
- const warnings = parseJobWarnings(job.warnings);
173
- if (warnings.length > 0) {
174
- lines.push("", "Warnings:", ...warnings.map((warning) => `- ${warning}`));
175
- }
176
- if (job.error) {
177
- lines.push("", "## Error", `- Code: ${job.error.code}`, `- Stage: ${job.error.stage}`, job.error.message);
178
- // Structured context (e.g. `drift_axis` / `retryable_after_setup`) so a
179
- // caller reading the rendered artifact — not just `result --json` — can
180
- // branch on it. Deterministic key order keeps artifacts stable.
181
- const details = job.error.details;
182
- if (details !== undefined && Object.keys(details).length > 0) {
183
- lines.push("", "### Details");
184
- for (const key of Object.keys(details).sort()) {
185
- lines.push(`- ${key}: ${JSON.stringify(details[key])}`);
186
- }
187
- }
188
- }
189
- if (partialOutput) {
190
- lines.push("", `## Partial output (budget exhausted after ${formatBudgetDuration(partialOutput.budgetMs)} — NOT a final answer)`, "", partialOutput.text.trim()
191
- ? partialOutput.text
192
- : partialOutput.recordCount === 0
193
- ? "No stream records arrived before the budget expired (the model had not produced any output yet)."
194
- : partialOutput.toolCalls
195
- ? "No assistant prose was emitted before the budget (tool calls only)."
196
- : "No assistant prose was emitted before the budget.");
197
- }
198
- return lines.join("\n");
199
- }
200
- function terminalScopeLine(job) {
201
- try {
202
- const line = describeReadScope(parseJobReadScope(job.read_scope));
203
- return line === undefined ? [] : [`- ${line}`];
204
- }
205
- catch {
206
- return ["- Scope: unreadable stored scope"];
207
- }
208
- }
209
- export function capitalize(value) {
210
- return value.slice(0, 1).toUpperCase() + value.slice(1);
211
- }
212
- function assertNever(value) {
213
- throw new RuntimeError("UNSUPPORTED_COMMAND_TYPE", `Unsupported command type for rendering: ${String(value)}`, "render");
214
- }