kimi-plugin-cc 2.7.3 → 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 (317) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +3 -16
  3. package/README.md +428 -515
  4. package/assets/logo.svg +6 -0
  5. package/cordis.patch.yml +18 -0
  6. package/dist/background-spawn.js +14 -19
  7. package/dist/cli-client.js +163 -105
  8. package/dist/commands/ask.js +44 -96
  9. package/dist/commands/cancel.js +11 -59
  10. package/dist/commands/cli-helpers.js +102 -1
  11. package/dist/commands/models.js +2 -3
  12. package/dist/commands/pursue.js +8 -21
  13. package/dist/commands/registry.js +7 -26
  14. package/dist/commands/repair-sessions.js +121 -12
  15. package/dist/commands/replay.js +4 -3
  16. package/dist/commands/rescue.js +29 -87
  17. package/dist/commands/result.js +7 -1
  18. package/dist/commands/review.js +28 -18
  19. package/dist/commands/setup.js +813 -462
  20. package/dist/commands/status.js +2 -2
  21. package/dist/commands/swarm.js +112 -125
  22. package/dist/commands/worker.js +1 -2
  23. package/dist/companion.js +145 -19
  24. package/dist/git.js +1 -9
  25. package/dist/help.js +13 -9
  26. package/dist/hook-escape.js +7 -16
  27. package/dist/hooks/approval-hook.js +1766 -87
  28. package/dist/hooks/approval-policy.js +86 -19
  29. package/dist/hooks/config-safety.js +31 -64
  30. package/dist/hooks/hook-timing.js +48 -0
  31. package/dist/hooks/install-paths.js +179 -107
  32. package/dist/hooks/install.js +126 -53
  33. package/dist/hooks/managed-block.js +121 -127
  34. package/dist/job-store.js +206 -166
  35. package/dist/jobs.js +66 -19
  36. package/dist/kimi-command.js +74 -1
  37. package/dist/kimi-engine.js +198 -127
  38. package/dist/kimi-errors.js +15 -70
  39. package/dist/kimi-home.js +6 -0
  40. package/dist/kimi-journal.js +42 -0
  41. package/dist/kimi-releases.js +123 -0
  42. package/dist/kimi-timeouts.js +2 -16
  43. package/dist/kimi-version-probe.js +24 -108
  44. package/dist/logging.js +12 -7
  45. package/dist/mcp/binding.js +13 -4
  46. package/dist/mcp/job-control.js +390 -95
  47. package/dist/mcp/launcher.js +13 -7
  48. package/dist/mcp/operations.js +405 -179
  49. package/dist/mcp/protocol.js +124 -33
  50. package/dist/mcp/skills.js +130 -0
  51. package/dist/mcp/stdio.js +18 -4
  52. package/dist/model-command.js +5 -3
  53. package/dist/native-v2-preflight.js +243 -80
  54. package/dist/parsing.js +211 -243
  55. package/dist/paths.js +28 -10
  56. package/dist/plugin-data.js +28 -83
  57. package/dist/process-tree.js +35 -24
  58. package/dist/read-scope.js +435 -0
  59. package/dist/render.js +58 -46
  60. package/dist/rescue-approval.js +461 -84
  61. package/dist/session-references.js +216 -0
  62. package/dist/session-title.js +26 -6
  63. package/dist/stream-json.js +1 -3
  64. package/dist/surface-routing.js +108 -0
  65. package/dist/swarm-activation.js +74 -188
  66. package/dist/swarm-policy.js +2 -1
  67. package/dist/swarm-recovery.js +2 -1
  68. package/dist/util.js +28 -0
  69. package/dist/version.js +1 -1
  70. package/docs/migration.md +45 -206
  71. package/docs/models.md +24 -66
  72. package/docs/safety.md +198 -353
  73. package/docs/session-visibility.md +25 -13
  74. package/docs/swarm-recovery.md +26 -20
  75. package/dsh/index.json +54 -0
  76. package/mcp_config.json +10 -0
  77. package/package.json +23 -82
  78. package/plugin.json +19 -0
  79. package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
  80. package/plugins/kimi-codex/.mcp.json +3 -3
  81. package/plugins/kimi-codex/dist/background-spawn.js +14 -19
  82. package/plugins/kimi-codex/dist/cli-client.js +163 -105
  83. package/plugins/kimi-codex/dist/commands/ask.js +44 -96
  84. package/plugins/kimi-codex/dist/commands/cancel.js +11 -59
  85. package/plugins/kimi-codex/dist/commands/cli-helpers.js +102 -1
  86. package/plugins/kimi-codex/dist/commands/models.js +2 -3
  87. package/plugins/kimi-codex/dist/commands/pursue.js +8 -21
  88. package/plugins/kimi-codex/dist/commands/registry.js +7 -26
  89. package/plugins/kimi-codex/dist/commands/repair-sessions.js +121 -12
  90. package/plugins/kimi-codex/dist/commands/replay.js +4 -3
  91. package/plugins/kimi-codex/dist/commands/rescue.js +29 -87
  92. package/plugins/kimi-codex/dist/commands/result.js +7 -1
  93. package/plugins/kimi-codex/dist/commands/review.js +28 -18
  94. package/plugins/kimi-codex/dist/commands/setup.js +813 -462
  95. package/plugins/kimi-codex/dist/commands/status.js +2 -2
  96. package/plugins/kimi-codex/dist/commands/swarm.js +112 -125
  97. package/plugins/kimi-codex/dist/commands/worker.js +1 -2
  98. package/plugins/kimi-codex/dist/companion.js +145 -19
  99. package/plugins/kimi-codex/dist/git.js +1 -9
  100. package/plugins/kimi-codex/dist/help.js +13 -9
  101. package/plugins/kimi-codex/dist/hook-escape.js +7 -16
  102. package/plugins/kimi-codex/dist/hooks/approval-hook.js +1766 -87
  103. package/plugins/kimi-codex/dist/hooks/approval-policy.js +86 -19
  104. package/plugins/kimi-codex/dist/hooks/config-safety.js +31 -64
  105. package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
  106. package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
  107. package/plugins/kimi-codex/dist/hooks/install.js +126 -53
  108. package/plugins/kimi-codex/dist/hooks/managed-block.js +121 -127
  109. package/plugins/kimi-codex/dist/job-store.js +206 -166
  110. package/plugins/kimi-codex/dist/jobs.js +66 -19
  111. package/plugins/kimi-codex/dist/kimi-command.js +74 -1
  112. package/plugins/kimi-codex/dist/kimi-engine.js +198 -127
  113. package/plugins/kimi-codex/dist/kimi-errors.js +15 -70
  114. package/plugins/kimi-codex/dist/kimi-home.js +6 -0
  115. package/plugins/kimi-codex/dist/kimi-journal.js +42 -0
  116. package/plugins/kimi-codex/dist/kimi-releases.js +123 -0
  117. package/plugins/kimi-codex/dist/kimi-timeouts.js +2 -16
  118. package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -108
  119. package/plugins/kimi-codex/dist/logging.js +12 -7
  120. package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
  121. package/plugins/kimi-codex/dist/mcp/job-control.js +390 -95
  122. package/plugins/kimi-codex/dist/mcp/launcher.js +13 -7
  123. package/plugins/kimi-codex/dist/mcp/operations.js +405 -179
  124. package/plugins/kimi-codex/dist/mcp/protocol.js +124 -33
  125. package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
  126. package/plugins/kimi-codex/dist/mcp/stdio.js +18 -4
  127. package/plugins/kimi-codex/dist/model-command.js +5 -3
  128. package/plugins/kimi-codex/dist/native-v2-preflight.js +243 -80
  129. package/plugins/kimi-codex/dist/parsing.js +211 -243
  130. package/plugins/kimi-codex/dist/paths.js +28 -10
  131. package/plugins/kimi-codex/dist/plugin-data.js +28 -83
  132. package/plugins/kimi-codex/dist/process-tree.js +35 -24
  133. package/plugins/kimi-codex/dist/read-scope.js +435 -0
  134. package/plugins/kimi-codex/dist/render.js +58 -46
  135. package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
  136. package/plugins/kimi-codex/dist/session-references.js +216 -0
  137. package/plugins/kimi-codex/dist/session-title.js +26 -6
  138. package/plugins/kimi-codex/dist/stream-json.js +1 -3
  139. package/plugins/kimi-codex/dist/surface-routing.js +108 -0
  140. package/plugins/kimi-codex/dist/swarm-activation.js +74 -188
  141. package/plugins/kimi-codex/dist/swarm-policy.js +2 -1
  142. package/plugins/kimi-codex/dist/swarm-recovery.js +2 -1
  143. package/plugins/kimi-codex/dist/util.js +28 -0
  144. package/plugins/kimi-codex/dist/version.js +1 -1
  145. package/plugins/kimi-codex/scripts/companion.sh +4 -15
  146. package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
  147. package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
  148. package/scripts/companion.sh +4 -15
  149. package/skills/kimi/SKILL.md +77 -0
  150. package/skills/kimi/agents/openai.yaml +6 -0
  151. package/CHANGELOG.md +0 -1333
  152. package/agents/kimi-ask.md +0 -89
  153. package/agents/kimi-challenge.md +0 -86
  154. package/agents/kimi-pursue.md +0 -93
  155. package/agents/kimi-rescue.md +0 -92
  156. package/agents/kimi-review.md +0 -86
  157. package/agents/kimi-swarm-write.md +0 -96
  158. package/agents/kimi-swarm.md +0 -86
  159. package/commands/README.md +0 -16
  160. package/commands/ask.md +0 -38
  161. package/commands/cancel.md +0 -17
  162. package/commands/challenge.md +0 -35
  163. package/commands/pursue.md +0 -41
  164. package/commands/replay.md +0 -13
  165. package/commands/rescue.md +0 -38
  166. package/commands/result.md +0 -13
  167. package/commands/review.md +0 -35
  168. package/commands/setup.md +0 -23
  169. package/commands/status.md +0 -13
  170. package/commands/swarm.md +0 -44
  171. package/dist/commands/not-implemented.js +0 -4
  172. package/dist/commands/review-gate.js +0 -390
  173. package/dist/config.js +0 -22
  174. package/dist/dsh/companion.js +0 -177
  175. package/dist/dsh/index.js +0 -169
  176. package/dist/hooks/review-gate-stop.js +0 -19
  177. package/dist/schemas/review-gate-output.js +0 -43
  178. package/docs/registry-releases.md +0 -228
  179. package/docs/upstream-2.4.1-certification.md +0 -54
  180. package/docs/upstream-2.5.0-certification.md +0 -52
  181. package/docs/upstream-2.5.1-certification.md +0 -47
  182. package/docs/upstream-2.5.2-certification.md +0 -40
  183. package/docs/upstream-2.5.3-certification.md +0 -73
  184. package/docs/upstream-2.6.0-certification.md +0 -65
  185. package/docs/upstream-2.6.2-certification.md +0 -144
  186. package/docs/upstream-2.6.3-certification.md +0 -100
  187. package/docs/upstream-2.7.2-certification.md +0 -113
  188. package/docs/upstream-2.7.3-certification.md +0 -83
  189. package/docs/windows-validation.md +0 -39
  190. package/hooks/README.md +0 -9
  191. package/hooks/hooks.json +0 -16
  192. package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
  193. package/plugins/kimi-codex/dist/commands/review-gate.js +0 -390
  194. package/plugins/kimi-codex/dist/config.js +0 -22
  195. package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
  196. package/plugins/kimi-codex/dist/dsh/index.js +0 -169
  197. package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
  198. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -43
  199. package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
  200. package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +0 -35
  201. package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
  202. package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
  203. package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
  204. package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +0 -34
  205. package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +0 -6
  206. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
  207. package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
  208. package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
  209. package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
  210. package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +0 -34
  211. package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +0 -6
  212. package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
  213. package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
  214. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -34
  215. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
  216. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -34
  217. package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
  218. package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
  219. package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
  220. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -35
  221. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
  222. package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +0 -36
  223. package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +0 -6
  224. package/plugins/kimi-dsh/LICENSE +0 -201
  225. package/plugins/kimi-dsh/README.md +0 -83
  226. package/plugins/kimi-dsh/cordis.patch.yml +0 -45
  227. package/plugins/kimi-dsh/dist/background-spawn.js +0 -216
  228. package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
  229. package/plugins/kimi-dsh/dist/cli-client.js +0 -1078
  230. package/plugins/kimi-dsh/dist/commands/ask.js +0 -336
  231. package/plugins/kimi-dsh/dist/commands/cancel.js +0 -216
  232. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -201
  233. package/plugins/kimi-dsh/dist/commands/models.js +0 -140
  234. package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
  235. package/plugins/kimi-dsh/dist/commands/pursue.js +0 -307
  236. package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
  237. package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
  238. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -160
  239. package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
  240. package/plugins/kimi-dsh/dist/commands/rescue.js +0 -347
  241. package/plugins/kimi-dsh/dist/commands/result.js +0 -66
  242. package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -390
  243. package/plugins/kimi-dsh/dist/commands/review.js +0 -220
  244. package/plugins/kimi-dsh/dist/commands/setup.js +0 -1129
  245. package/plugins/kimi-dsh/dist/commands/status.js +0 -27
  246. package/plugins/kimi-dsh/dist/commands/swarm.js +0 -849
  247. package/plugins/kimi-dsh/dist/commands/worker.js +0 -25
  248. package/plugins/kimi-dsh/dist/companion.js +0 -97
  249. package/plugins/kimi-dsh/dist/config.js +0 -22
  250. package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
  251. package/plugins/kimi-dsh/dist/dsh/index.js +0 -169
  252. package/plugins/kimi-dsh/dist/errors.js +0 -40
  253. package/plugins/kimi-dsh/dist/git.js +0 -224
  254. package/plugins/kimi-dsh/dist/help.js +0 -43
  255. package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
  256. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -104
  257. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -233
  258. package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -665
  259. package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
  260. package/plugins/kimi-dsh/dist/hooks/install.js +0 -210
  261. package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -684
  262. package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
  263. package/plugins/kimi-dsh/dist/job-id.js +0 -12
  264. package/plugins/kimi-dsh/dist/job-store.js +0 -659
  265. package/plugins/kimi-dsh/dist/jobs.js +0 -217
  266. package/plugins/kimi-dsh/dist/kimi-command.js +0 -71
  267. package/plugins/kimi-dsh/dist/kimi-engine.js +0 -675
  268. package/plugins/kimi-dsh/dist/kimi-errors.js +0 -260
  269. package/plugins/kimi-dsh/dist/kimi-home.js +0 -9
  270. package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
  271. package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -234
  272. package/plugins/kimi-dsh/dist/logging.js +0 -22
  273. package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
  274. package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -345
  275. package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -257
  276. package/plugins/kimi-dsh/dist/mcp/operations.js +0 -301
  277. package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -275
  278. package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
  279. package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -78
  280. package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
  281. package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
  282. package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
  283. package/plugins/kimi-dsh/dist/model-command.js +0 -32
  284. package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -525
  285. package/plugins/kimi-dsh/dist/package.json +0 -1
  286. package/plugins/kimi-dsh/dist/parsing.js +0 -620
  287. package/plugins/kimi-dsh/dist/paths.js +0 -27
  288. package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
  289. package/plugins/kimi-dsh/dist/process-tree.js +0 -586
  290. package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
  291. package/plugins/kimi-dsh/dist/render.js +0 -177
  292. package/plugins/kimi-dsh/dist/rescue-approval.js +0 -865
  293. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -43
  294. package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
  295. package/plugins/kimi-dsh/dist/session-title.js +0 -293
  296. package/plugins/kimi-dsh/dist/stream-json.js +0 -346
  297. package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1197
  298. package/plugins/kimi-dsh/dist/swarm-policy.js +0 -73
  299. package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -165
  300. package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
  301. package/plugins/kimi-dsh/dist/types.js +0 -1
  302. package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
  303. package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
  304. package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
  305. package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
  306. package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
  307. package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
  308. package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
  309. package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
  310. package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
  311. package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
  312. package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
  313. package/plugins/kimi-dsh/dist/version.js +0 -7
  314. package/plugins/kimi-dsh/package.json +0 -78
  315. package/plugins/kimi-dsh/scripts/companion.sh +0 -37
  316. package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
  317. package/scripts/review-gate-hook.sh +0 -32
@@ -0,0 +1,435 @@
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,
161
+ // 2.7.3 and 2.8.0 (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,8 +1,9 @@
1
1
  import { readFile, writeFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
+ import { parseJobWarnings } from "./job-store.js";
4
+ import { describeReadScope, parseJobReadScope } from "./read-scope.js";
3
5
  import { getManagedCommandConfig } from "./commands/registry.js";
4
6
  import { RuntimeError } from "./errors.js";
5
- import { parseReviewGateOutput } from "./schemas/review-gate-output.js";
6
7
  const EMPTY_SUMMARY_FALLBACK = "Rescue did not return a final message.";
7
8
  export async function writeArtifact(paths, job, markdown) {
8
9
  const artifactPath = path.join(paths.artifactsDir, `${job.command_type}-${job.job_id}.md`);
@@ -12,7 +13,47 @@ export async function writeArtifact(paths, job, markdown) {
12
13
  export async function readArtifact(artifactPath) {
13
14
  return readFile(artifactPath, "utf8");
14
15
  }
16
+ /**
17
+ * Prefix a "Warnings:" block when the job carries launch warnings. Wrapper
18
+ * models read stdout and artifacts, never stderr, so this is the load-bearing
19
+ * copy. Without warnings the text is returned unchanged, byte for byte.
20
+ */
21
+ export function withWarningsBlock(job, text) {
22
+ const warnings = parseJobWarnings(job.warnings);
23
+ if (warnings.length === 0)
24
+ return text;
25
+ return `Warnings:\n${warnings.map((warning) => `- ${warning}`).join("\n")}\n\n${text}`;
26
+ }
27
+ /** Prefix the non-default read scope so callers see what they asked for; unchanged otherwise. */
28
+ export function withScopeLine(job, text) {
29
+ const line = describeReadScope(parseJobReadScope(job.read_scope));
30
+ return line === undefined ? text : `${line}\n\n${text}`;
31
+ }
15
32
  export function renderManagedJobOutput(job, finalText) {
33
+ const rendered = renderManagedJobOutputBody(job, finalText);
34
+ if (parseJobWarnings(job.warnings).length === 0 && !job.read_scope)
35
+ return rendered;
36
+ const decorate = (text) => withWarningsBlock(job, withScopeLine(job, text));
37
+ return {
38
+ ...rendered,
39
+ output: typeof rendered.output === "string" ? decorate(rendered.output) : rendered.output,
40
+ rendered: decorate(rendered.rendered),
41
+ };
42
+ }
43
+ function renderManagedJobOutputBody(job, finalText) {
44
+ // Historical v3.0 review_gate rows remain readable for replay/inspection
45
+ // without re-registering review_gate as a live managed command.
46
+ if (job.command_type === "review_gate") {
47
+ const trimmed = finalText.trim();
48
+ if (!trimmed) {
49
+ throw new RuntimeError("REVIEW_GATE_EMPTY_OUTPUT", "Historical review_gate job returned empty output.", "render");
50
+ }
51
+ return {
52
+ output: trimmed,
53
+ rendered: `${trimmed}\n`,
54
+ summary: firstMeaningfulLine(trimmed, "Historical review_gate output."),
55
+ };
56
+ }
16
57
  assertOutputModeConsistency(job.command_type, finalText);
17
58
  switch (job.command_type) {
18
59
  case "ask": {
@@ -22,9 +63,8 @@ export function renderManagedJobOutput(job, finalText) {
22
63
  }
23
64
  return {
24
65
  output: trimmed,
25
- rendered: renderAskArtifact(trimmed),
66
+ rendered: trimmed,
26
67
  summary: trimmed.slice(0, 160),
27
- error: null,
28
68
  };
29
69
  }
30
70
  case "review":
@@ -37,16 +77,6 @@ export function renderManagedJobOutput(job, finalText) {
37
77
  output: trimmed,
38
78
  rendered: renderReviewArtifact(job, trimmed),
39
79
  summary: firstMeaningfulLine(trimmed),
40
- error: null,
41
- };
42
- }
43
- case "review_gate": {
44
- const output = parseReviewGateOutput(finalText.trim());
45
- return {
46
- output,
47
- rendered: renderReviewGateArtifact(job, output),
48
- summary: output.summary,
49
- error: null,
50
80
  };
51
81
  }
52
82
  case "rescue": {
@@ -58,7 +88,6 @@ export function renderManagedJobOutput(job, finalText) {
58
88
  output: finalText,
59
89
  rendered: renderRescueArtifact(finalText),
60
90
  summary: firstMeaningfulLine(finalText),
61
- error: null,
62
91
  };
63
92
  }
64
93
  default:
@@ -70,21 +99,10 @@ export function assertOutputModeConsistency(commandType, finalText) {
70
99
  switch (outputMode) {
71
100
  case "passthrough":
72
101
  return;
73
- case "parsed":
74
- try {
75
- JSON.parse(finalText);
76
- }
77
- catch (error) {
78
- 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);
79
- }
80
- return;
81
102
  default:
82
103
  return assertNever(outputMode);
83
104
  }
84
105
  }
85
- export function renderAskArtifact(output) {
86
- return output.trim();
87
- }
88
106
  export function renderReviewArtifact(job, output) {
89
107
  const header = [
90
108
  `# ${job.command_type === "challenge" ? "Challenge" : "Review"} Result`,
@@ -106,26 +124,6 @@ export function firstMeaningfulLine(text, fallback = EMPTY_SUMMARY_FALLBACK) {
106
124
  .find(Boolean);
107
125
  return line ?? fallback;
108
126
  }
109
- export function renderReviewGateArtifact(job, output) {
110
- const lines = [
111
- "# Review Gate Result",
112
- "",
113
- `- Job: ${job.job_id}`,
114
- `- Decision: ${output.decision}`,
115
- `- Confidence: ${output.confidence}`,
116
- `- Summary: ${output.summary}`,
117
- ...(job.kimi_session_id ? [`- Kimi session: ${job.kimi_session_id}`] : []),
118
- ];
119
- if (output.issues.length === 0) {
120
- lines.push("", "No issues.");
121
- return `${lines.join("\n")}\n`;
122
- }
123
- lines.push("", "## Issues");
124
- for (const issue of output.issues) {
125
- lines.push("", `### ${issue.title}`, `- Severity: ${issue.severity}`, issue.body);
126
- }
127
- return `${lines.join("\n")}\n`;
128
- }
129
127
  export function formatBudgetDuration(ms) {
130
128
  if (ms % 3_600_000 === 0)
131
129
  return `${ms / 3_600_000}h`;
@@ -144,7 +142,12 @@ export function renderTerminalJobArtifact(job, partialOutput) {
144
142
  `- Status: ${job.status}`,
145
143
  `- Summary: ${job.summary}`,
146
144
  ...(job.kimi_session_id ? [`- Kimi session: ${job.kimi_session_id}`] : []),
145
+ ...terminalScopeLine(job),
147
146
  ];
147
+ const warnings = parseJobWarnings(job.warnings);
148
+ if (warnings.length > 0) {
149
+ lines.push("", "Warnings:", ...warnings.map((warning) => `- ${warning}`));
150
+ }
148
151
  if (job.error) {
149
152
  lines.push("", "## Error", `- Code: ${job.error.code}`, `- Stage: ${job.error.stage}`, job.error.message);
150
153
  // Structured context (e.g. `drift_axis` / `retryable_after_setup`) so a
@@ -169,7 +172,16 @@ export function renderTerminalJobArtifact(job, partialOutput) {
169
172
  }
170
173
  return lines.join("\n");
171
174
  }
172
- function capitalize(value) {
175
+ function terminalScopeLine(job) {
176
+ try {
177
+ const line = describeReadScope(parseJobReadScope(job.read_scope));
178
+ return line === undefined ? [] : [`- ${line}`];
179
+ }
180
+ catch {
181
+ return ["- Scope: unreadable stored scope"];
182
+ }
183
+ }
184
+ export function capitalize(value) {
173
185
  return value.slice(0, 1).toUpperCase() + value.slice(1);
174
186
  }
175
187
  function assertNever(value) {