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
@@ -1,43 +0,0 @@
1
- import { RuntimeError } from "../errors.js";
2
- const ALLOWED_DECISIONS = new Set(["ALLOW", "BLOCK"]);
3
- const ALLOWED_SEVERITIES = new Set(["low", "medium", "high"]);
4
- const ALLOWED_CONFIDENCE = new Set(["low", "medium", "high"]);
5
- export function parseReviewGateOutput(text) {
6
- let parsed;
7
- try {
8
- parsed = JSON.parse(text);
9
- }
10
- catch (error) {
11
- throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", `Review gate output is not valid JSON: ${error.message}`, "review_gate.parse", { cause: error });
12
- }
13
- if (!isObject(parsed)) {
14
- throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", "Review gate output must be a JSON object.", "review_gate.parse");
15
- }
16
- const { decision, confidence, summary, issues } = parsed;
17
- if (!ALLOWED_DECISIONS.has(String(decision)) ||
18
- !ALLOWED_CONFIDENCE.has(String(confidence)) ||
19
- typeof summary !== "string" ||
20
- !Array.isArray(issues)) {
21
- throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", "Review gate output must contain decision, confidence, summary, and issues.", "review_gate.parse");
22
- }
23
- return {
24
- decision: decision,
25
- confidence: confidence,
26
- summary,
27
- issues: issues.map((issue, index) => normalizeIssue(issue, index)),
28
- };
29
- }
30
- function normalizeIssue(issue, index) {
31
- if (!isObject(issue)) {
32
- throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", `Review gate issue ${index + 1} must be an object.`, "review_gate.parse");
33
- }
34
- if (typeof issue.title !== "string" ||
35
- typeof issue.body !== "string" ||
36
- !ALLOWED_SEVERITIES.has(String(issue.severity))) {
37
- throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", `Review gate issue ${index + 1} is missing a required field.`, "review_gate.parse");
38
- }
39
- return issue;
40
- }
41
- function isObject(value) {
42
- return typeof value === "object" && value !== null && !Array.isArray(value);
43
- }
@@ -1,202 +0,0 @@
1
- import { constants } from "node:fs";
2
- import { lstat, open, opendir, realpath } from "node:fs/promises";
3
- import path from "node:path";
4
- import { digestPrompt } from "./jobs.js";
5
- // Total entries visited across both enumeration levels. The cap guards against
6
- // a pathological tree rather than budgeting normal store size. opendir streams,
7
- // so entries are not buffered. Dot-entries (`.index-dirty`, `.index-cache`) are
8
- // upstream index state, never workspaces, and are skipped without being counted.
9
- // Directories whose mtime predates the spawn cannot have been created by this
10
- // run and are skipped before any read, so the byte budget scales with concurrent
11
- // activity, not with store size.
12
- const DIR_ENUM_CAP = 65_536;
13
- const STATE_MAX_BYTES = 1024 * 1024;
14
- const JOURNAL_PREFIX_BYTES = 4 * 1024 * 1024; // The prompt is argv-bounded (< 1 MiB); the first user message follows a few config records.
15
- const SCAN_MAX_BYTES = 64 * 1024 * 1024;
16
- const MTIME_SLACK_MS = 1000; // Filesystems with coarse mtime granularity.
17
- const SESSION_ID = /^session_[0-9a-f-]{36}$/;
18
- /** Metadata recovery only, never a substitute for resume lineage/plan scans.
19
- * A capped or unreadable enumeration cannot establish uniqueness and refuses;
20
- * skipping symlinked or dot entries is not partial — neither can be a session
21
- * the child created.
22
- *
23
- * A candidate is bound to THIS job by content, not only by time: the first
24
- * user message in the session's main journal must carry a text item whose
25
- * sha256 equals the caller-supplied digest of the exact `-p` argument. Native
26
- * goal print stores the unwrapped objective, so the smoke recovery control
27
- * supplies that digest. Production pursue does not perform store recovery. Time and
28
- * cwd alone would admit a concurrent TUI session, another host's finished job
29
- * (host-local stores cannot see each other's session ids), or a `state.json`
30
- * planted by repository code running under rescue. The digest is not unique
31
- * on its own either (the same prompt can run twice), so the window and the
32
- * exactly-one rule stay in force. */
33
- export async function recoverSessionIdFromStore(options) {
34
- const entryCap = options.entryCap ?? DIR_ENUM_CAP;
35
- let entries = 0;
36
- let bytes = 0;
37
- let digestMismatches = 0;
38
- let missingJournals = 0;
39
- const candidates = [];
40
- const capped = new Error("enumeration_capped");
41
- async function* directories(dir) {
42
- if ((await lstat(dir)).isSymbolicLink())
43
- throw new Error("unreadable");
44
- const handle = await opendir(dir);
45
- for await (const entry of handle) {
46
- if (entry.name.startsWith("."))
47
- continue;
48
- if (++entries > entryCap)
49
- throw capped;
50
- // A symlinked entry is never a session the child created; skipping it
51
- // keeps one stray link from disabling recovery host-wide. Directories
52
- // we descend are still lstat-anchored above.
53
- if (entry.isSymbolicLink())
54
- continue;
55
- if (entry.isDirectory())
56
- yield entry.name;
57
- }
58
- }
59
- // Bounded no-follow read of a regular file. Returns undefined when the file
60
- // is absent; throws "unreadable" for anything that is not a plain file. With
61
- // `prefix`, a larger file yields its first `maxBytes` instead of refusing.
62
- async function readBounded(file, maxBytes, prefix = false) {
63
- let handle;
64
- try {
65
- handle = await open(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
66
- }
67
- catch (error) {
68
- if (error.code === "ENOENT")
69
- return undefined;
70
- throw error;
71
- }
72
- try {
73
- const stat = await handle.stat();
74
- if (!stat.isFile() || (stat.size > maxBytes && !prefix))
75
- throw new Error("unreadable");
76
- const size = Math.min(stat.size, maxBytes);
77
- bytes += size;
78
- if (bytes > SCAN_MAX_BYTES)
79
- throw capped;
80
- const buffer = Buffer.alloc(size);
81
- let offset = 0;
82
- while (offset < buffer.length) {
83
- const read = await handle.read(buffer, offset, buffer.length - offset, offset);
84
- if (!read.bytesRead)
85
- break;
86
- offset += read.bytesRead;
87
- }
88
- return buffer.subarray(0, offset);
89
- }
90
- finally {
91
- await handle.close();
92
- }
93
- }
94
- try {
95
- if (!Number.isFinite(options.spawnedAt) || !Number.isFinite(options.settledAt) ||
96
- options.settledAt < options.spawnedAt || !/^[0-9a-f]{64}$/.test(options.promptDigest)) {
97
- return { reason: "none" };
98
- }
99
- const cwd = await realpath(options.cwd);
100
- const sessions = path.join(options.kimiHome, "sessions");
101
- // Missing nested dirs mean an incomplete scan; only a missing root is normal.
102
- try {
103
- await lstat(sessions);
104
- }
105
- catch (error) {
106
- if (error.code === "ENOENT")
107
- return { reason: "none" };
108
- throw error;
109
- }
110
- for await (const workspace of directories(sessions)) {
111
- const workspacePath = path.join(sessions, workspace);
112
- for await (const session of directories(workspacePath)) {
113
- if (!SESSION_ID.test(session))
114
- continue;
115
- const sessionPath = path.join(workspacePath, session);
116
- // A directory this run created was modified at or after the spawn.
117
- if ((await lstat(sessionPath)).mtimeMs < options.spawnedAt - MTIME_SLACK_MS)
118
- continue;
119
- const raw = await readBounded(path.join(sessionPath, "state.json"), STATE_MAX_BYTES);
120
- if (!raw)
121
- continue;
122
- let state;
123
- try {
124
- state = JSON.parse(raw.toString("utf8"));
125
- }
126
- catch {
127
- continue;
128
- }
129
- if (!state || typeof state !== "object")
130
- continue;
131
- const value = state;
132
- // The child writes createdAt after the parent stamped spawnedAt on the
133
- // same clock, so causality orders them; no pre-spawn slack is justified.
134
- if (value.version !== 2 || typeof value.cwd !== "string" || !path.isAbsolute(value.cwd) ||
135
- typeof value.id !== "string" || !SESSION_ID.test(value.id) || value.id !== session ||
136
- typeof value.createdAt !== "number" || !Number.isFinite(value.createdAt) ||
137
- value.createdAt < options.spawnedAt || value.createdAt > options.settledAt)
138
- continue;
139
- let stateCwd;
140
- try {
141
- stateCwd = await realpath(value.cwd);
142
- }
143
- catch {
144
- continue;
145
- }
146
- if (stateCwd !== cwd || options.store.hasSessionId(value.id, options.jobId))
147
- continue;
148
- const journal = await readBounded(path.join(sessionPath, "agents", "main", "wire.jsonl"), JOURNAL_PREFIX_BYTES, true);
149
- if (!journal) {
150
- missingJournals += 1;
151
- continue;
152
- }
153
- // A prefix cut mid-record must never be parsed as a complete line.
154
- const text = journal.length === JOURNAL_PREFIX_BYTES
155
- ? journal.subarray(0, journal.lastIndexOf(0x0a) + 1).toString("utf8") : journal.toString("utf8");
156
- if (!firstUserMessageMatches(text, options.promptDigest)) {
157
- digestMismatches += 1;
158
- continue;
159
- }
160
- candidates.push(value.id);
161
- }
162
- }
163
- if (candidates.length === 1)
164
- return { sessionId: candidates[0] };
165
- if (candidates.length > 1)
166
- return { reason: `ambiguous:${candidates.length}` };
167
- if (digestMismatches > 0)
168
- return { reason: `digest_mismatch:${digestMismatches}` };
169
- return { reason: missingJournals > 0 ? `journal_missing:${missingJournals}` : "none" };
170
- }
171
- catch (error) {
172
- return { reason: error === capped ? "enumeration_capped" : "unreadable" };
173
- }
174
- }
175
- /** True when the FIRST user message in a native-v2 main journal carries a
176
- * text item equal to the prompt the job spawned with. Later user turns are
177
- * never consulted: only the opening prompt binds a session to its spawn. */
178
- export function firstUserMessageMatches(journal, promptDigest) {
179
- for (const line of journal.split("\n")) {
180
- if (!line.trim())
181
- continue;
182
- let record;
183
- try {
184
- record = JSON.parse(line);
185
- }
186
- catch {
187
- continue;
188
- }
189
- if (!record || typeof record !== "object")
190
- continue;
191
- const message = record.message;
192
- if (!message || typeof message !== "object" || message.role !== "user")
193
- continue;
194
- const content = message.content;
195
- if (!Array.isArray(content))
196
- return false;
197
- return content.some((item) => item && typeof item === "object" && item.type === "text" &&
198
- typeof item.text === "string" &&
199
- digestPrompt(item.text) === promptDigest);
200
- }
201
- return false;
202
- }
@@ -1,293 +0,0 @@
1
- import { basename, isAbsolute, relative, resolve } from "node:path";
2
- import path from "node:path";
3
- import { constants } from "node:fs";
4
- import { randomUUID } from "node:crypto";
5
- import { lstat, mkdir, open, realpath, rename, rm, writeFile } from "node:fs/promises";
6
- import { resolveKimiHome } from "./kimi-home.js";
7
- export const KIMI_SESSION_TITLE_MAX_LENGTH = 120;
8
- const SESSION_INDEX_MAX_BYTES = 16 * 1024 * 1024;
9
- const SESSION_INDEX_LINE_MAX_BYTES = 1024 * 1024;
10
- const SESSION_STATE_MAX_BYTES = 1024 * 1024;
11
- const DISPLAY_NAMES = {
12
- ask: "Ask",
13
- review: "Review",
14
- challenge: "Challenge",
15
- rescue: "Rescue",
16
- pursue: "Pursue",
17
- swarm: "Swarm",
18
- "swarm-write": "Swarm Write",
19
- };
20
- export function buildKimiSessionTitle(command, summary) {
21
- const prefix = `Kimi ${DISPLAY_NAMES[command] ?? "Session"}`;
22
- const normalized = promptMetadataText(summary ?? "") ?? "";
23
- return shortenForTitle(normalized ? `${prefix}: ${normalized}` : prefix, KIMI_SESSION_TITLE_MAX_LENGTH);
24
- }
25
- export function normalizeTitleFragment(text) {
26
- return text
27
- .replace(/[\u0000-\u001f\u007f]/g, " ")
28
- .replace(/\s+/g, " ")
29
- .trim();
30
- }
31
- /** Mirrors kimi-code 2.0.0 promptMetadataTextFromText: redact BEFORE truncating. */
32
- export function promptMetadataText(text) {
33
- const sanitized = text
34
- .replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/gi, "[redacted]")
35
- .replace(/\b(authorization)\s*:\s*bearer\s+\S+/gi, "$1: Bearer [redacted]")
36
- .replace(/\b(api[_-]?key|token|secret|password|passwd|pwd)\b\s*[:=]\s*(?:"[^"]*"|'[^']*'|\S+)/gi, "$1=[redacted]")
37
- .replace(/\bsk-[A-Za-z0-9_-]{12,}\b/g, "[redacted]")
38
- .replace(/\b[A-Za-z0-9][A-Za-z0-9+/=_-]{39,}\b/g, "[redacted]")
39
- .replace(/\p{Cc}+/gu, " ")
40
- .replace(/\s+/g, " ")
41
- .trim();
42
- return sanitized ? sanitized.slice(0, 4000) : undefined;
43
- }
44
- export function shortenForTitle(text, maxLength) {
45
- const normalized = normalizeTitleFragment(text);
46
- if (normalized.length <= maxLength) {
47
- return normalized;
48
- }
49
- return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}…`;
50
- }
51
- export async function syncKimiSessionTitle(options) {
52
- const sessionId = options.sessionId?.trim();
53
- if (!sessionId) {
54
- return "missing-session-id";
55
- }
56
- if (sessionId === "." || sessionId === ".." || /[/\\\p{Cc}]/u.test(sessionId)) {
57
- warn(options.stderr, `session metadata sync skipped for ${formatSessionIdForLog(sessionId)}: unsafe session id`);
58
- return "unsafe-entry";
59
- }
60
- const kimiHome = resolveKimiHome(options.env, options.cwd);
61
- const sessionsRoot = path.join(kimiHome, "sessions");
62
- const indexPath = path.join(kimiHome, "session_index.jsonl");
63
- const indexRead = await readUtf8FileCapped(indexPath, SESSION_INDEX_MAX_BYTES);
64
- if (!indexRead.ok) {
65
- if (indexRead.reason === "too-large") {
66
- warn(options.stderr, `session title sync skipped: session_index.jsonl is too large`);
67
- }
68
- return "missing-index";
69
- }
70
- const entry = findSessionIndexEntry(indexRead.text, sessionId, options.stderr);
71
- if (!entry) {
72
- return "missing-entry";
73
- }
74
- const safeSessionId = formatSessionIdForLog(sessionId);
75
- const sessionDir = resolve(entry.sessionDir);
76
- if (!isAbsolute(entry.sessionDir) ||
77
- !isPathInside(sessionsRoot, sessionDir) ||
78
- basename(sessionDir) !== sessionId) {
79
- warn(options.stderr, `session title sync skipped for ${safeSessionId}: unsafe session index entry`);
80
- return "unsafe-entry";
81
- }
82
- if (!(await isSafeSessionsRoot(sessionsRoot))) {
83
- warn(options.stderr, `session title sync skipped for ${safeSessionId}: unsafe sessions root`);
84
- return "unsafe-entry";
85
- }
86
- if (!(await isRealPathInside(sessionsRoot, sessionDir))) {
87
- warn(options.stderr, `session title sync skipped for ${safeSessionId}: unsafe session index target`);
88
- return "unsafe-entry";
89
- }
90
- const statePath = path.join(sessionDir, "state.json");
91
- const stateFileMode = await readSafeStateFileMode(statePath, options.stderr, sessionId);
92
- if (stateFileMode === null) {
93
- return "unsafe-entry";
94
- }
95
- let parsed;
96
- const stateRead = await readUtf8FileCapped(statePath, SESSION_STATE_MAX_BYTES);
97
- if (!stateRead.ok) {
98
- const reason = stateRead.reason === "too-large" ? "oversized state.json" : "missing or invalid state.json";
99
- warn(options.stderr, `session title sync skipped for ${safeSessionId}: ${reason}`);
100
- return "missing-state";
101
- }
102
- try {
103
- parsed = JSON.parse(stateRead.text);
104
- }
105
- catch {
106
- warn(options.stderr, `session title sync skipped for ${safeSessionId}: missing or invalid state.json`);
107
- return "missing-state";
108
- }
109
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
110
- warn(options.stderr, `session title sync skipped for ${safeSessionId}: invalid state.json shape`);
111
- return "invalid-state";
112
- }
113
- const state = parsed;
114
- const nativeV2 = state.version === 2;
115
- if (options.requireNativeV2 && !nativeV2)
116
- return "unsupported-state";
117
- if (nativeV2 && typeof state.id === "string" && state.id !== sessionId)
118
- return "invalid-state";
119
- // Custom-title normalization also recognizes titleKind and the older customTitle.
120
- const customTitle = state.isCustomTitle === true || state.titleKind === "custom" ||
121
- (typeof state.customTitle === "string" && state.customTitle.trim().length > 0);
122
- const generatedTitle = state.titleKind === "generated";
123
- const next = { ...state };
124
- const preview = options.promptText === undefined ? undefined : promptMetadataText(options.promptText);
125
- if (nativeV2 && preview && (typeof state.lastPrompt !== "string" || !state.lastPrompt.trim())) {
126
- next.lastPrompt = preview;
127
- }
128
- if (!options.preserveTitle && !customTitle && !generatedTitle) {
129
- next.title = promptMetadataText(options.title)?.slice(0, KIMI_SESSION_TITLE_MAX_LENGTH) ?? "Kimi Session";
130
- // Native UI generation must remain eligible; a deterministic fallback is not
131
- // a human rename. Legacy engines retain their existing custom-title behavior.
132
- next.isCustomTitle = !nativeV2;
133
- if (nativeV2)
134
- next.titleKind = "replaceable";
135
- }
136
- const changed = JSON.stringify(next) !== JSON.stringify(state);
137
- if (options.dryRun)
138
- return changed ? "would-update" : "unchanged";
139
- try {
140
- if (changed && !(await writeStateFileAtomic(statePath, `${JSON.stringify(next, null, 2)}\n`, stateFileMode, stateRead.text))) {
141
- warn(options.stderr, "session metadata sync skipped: state changed concurrently; retry after the session is idle");
142
- return "state-changed";
143
- }
144
- }
145
- catch {
146
- warn(options.stderr, `session metadata sync skipped for ${safeSessionId}: failed to write state.json`);
147
- return "write-failed";
148
- }
149
- if (nativeV2) {
150
- try {
151
- // Also re-mark unchanged metadata, so a previous invalidation failure is
152
- // repairable without rewriting the state or changing a manual title.
153
- await markSessionIndexDirty(sessionsRoot, sessionId);
154
- }
155
- catch {
156
- warn(options.stderr, `session metadata saved for ${safeSessionId}, but index notification failed; retry repair-sessions --apply when idle`);
157
- return "index-failed";
158
- }
159
- }
160
- return changed ? "updated" : customTitle && !options.preserveTitle ? "custom-title" : "unchanged";
161
- }
162
- function findSessionIndexEntry(indexText, sessionId, stderr) {
163
- for (const line of indexText.split(/\r?\n/)) {
164
- const trimmed = line.trim();
165
- if (!trimmed)
166
- continue;
167
- if (Buffer.byteLength(trimmed, "utf8") > SESSION_INDEX_LINE_MAX_BYTES) {
168
- warn(stderr, `session title sync skipped oversized session index line`);
169
- continue;
170
- }
171
- let parsed;
172
- try {
173
- parsed = JSON.parse(trimmed);
174
- }
175
- catch {
176
- warn(stderr, `session title sync skipped malformed session index line`);
177
- continue;
178
- }
179
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
180
- continue;
181
- }
182
- const entry = parsed;
183
- if (entry.sessionId === sessionId &&
184
- typeof entry.sessionDir === "string") {
185
- return {
186
- sessionId,
187
- sessionDir: entry.sessionDir,
188
- };
189
- }
190
- }
191
- return null;
192
- }
193
- function isPathInside(parent, child) {
194
- const rel = relative(resolve(parent), resolve(child));
195
- return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
196
- }
197
- async function isSafeSessionsRoot(sessionsRoot) {
198
- try {
199
- const stats = await lstat(sessionsRoot);
200
- return stats.isDirectory() && !stats.isSymbolicLink();
201
- }
202
- catch {
203
- return false;
204
- }
205
- }
206
- async function isRealPathInside(parent, child) {
207
- try {
208
- let current = parent;
209
- for (const part of relative(parent, child).split(path.sep)) {
210
- current = path.join(current, part);
211
- const info = await lstat(current);
212
- if (!info.isDirectory() || info.isSymbolicLink())
213
- return false;
214
- }
215
- const realParent = await realpath(parent);
216
- const realChild = await realpath(child);
217
- return isPathInside(realParent, realChild);
218
- }
219
- catch {
220
- return false;
221
- }
222
- }
223
- async function readSafeStateFileMode(statePath, stderr, sessionId) {
224
- try {
225
- const stats = await lstat(statePath);
226
- if (stats.isSymbolicLink() || !stats.isFile()) {
227
- warn(stderr, `session title sync skipped for ${formatSessionIdForLog(sessionId)}: unsafe state.json`);
228
- return null;
229
- }
230
- return stats.mode & 0o777;
231
- }
232
- catch {
233
- return 0o600;
234
- }
235
- }
236
- async function writeStateFileAtomic(statePath, contents, mode, expected) {
237
- const tmpPath = `${statePath}.${process.pid}.${randomUUID()}.tmp`;
238
- try {
239
- await writeFile(tmpPath, contents, { encoding: "utf8", mode, flag: "wx" });
240
- const current = await readUtf8FileCapped(statePath, SESSION_STATE_MAX_BYTES);
241
- if (!current.ok || current.text !== expected)
242
- return false;
243
- await rename(tmpPath, statePath);
244
- return true;
245
- }
246
- finally {
247
- await rm(tmpPath, { force: true }).catch(() => { });
248
- }
249
- }
250
- async function markSessionIndexDirty(sessionsRoot, sessionId) {
251
- if (!(await isSafeSessionsRoot(sessionsRoot)))
252
- throw new Error("Unsafe sessions root");
253
- const dir = path.join(sessionsRoot, ".index-dirty");
254
- await mkdir(dir, { mode: 0o700 }).catch((error) => {
255
- if (error.code !== "EEXIST")
256
- throw error;
257
- });
258
- if (!(await isRealPathInside(sessionsRoot, dir)))
259
- throw new Error("Unsafe dirty journal");
260
- // Upstream splits at the LAST dot; the unique suffix must contain no dots.
261
- const file = await open(path.join(dir, `${sessionId}.${Date.now()}-${randomUUID()}`), constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
262
- await file.close();
263
- }
264
- async function readUtf8FileCapped(filePath, maxBytes) {
265
- let file;
266
- try {
267
- file = await open(filePath, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
268
- }
269
- catch {
270
- return { ok: false, reason: "missing" };
271
- }
272
- try {
273
- const stats = await file.stat();
274
- if (!stats.isFile()) {
275
- return { ok: false, reason: "not-file" };
276
- }
277
- if (stats.size > maxBytes) {
278
- return { ok: false, reason: "too-large" };
279
- }
280
- const buffer = Buffer.alloc(stats.size);
281
- const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
282
- return { ok: true, text: buffer.subarray(0, bytesRead).toString("utf8") };
283
- }
284
- finally {
285
- await file.close();
286
- }
287
- }
288
- function formatSessionIdForLog(sessionId) {
289
- return JSON.stringify(normalizeTitleFragment(sessionId));
290
- }
291
- function warn(stderr, message) {
292
- stderr?.write(`[kimi-plugin-cc] ${message}.\n`);
293
- }