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,73 +0,0 @@
1
- export const SWARM_POLICY_ENV = "KIMI_PLUGIN_CC_SWARM_POLICY";
2
- export const SWARM_WAVE_SIZE_ENV = "KIMI_PLUGIN_CC_SWARM_WAVE_SIZE";
3
- export const BOUNDED_SWARM_POLICY = "bounded-waves/1";
4
- // Native retry timeouts can return a wave before its child work settles. This
5
- // valid upstream timer exceeds the plugin's finite <=24h job deadline, so only
6
- // terminal whole-job cancellation can interrupt a wave. Environment 0 is ignored.
7
- export const SWARM_CHILD_TIMEOUT_MS = 2_147_483_647;
8
- export function usesBoundedSwarmPolicy(plan) {
9
- return plan.intendedEngine === "native-v2" &&
10
- (plan.kimiVersion === "2.6.2" || plan.kimiVersion === "2.6.3" || plan.kimiVersion === "2.7.2" || plan.kimiVersion === "2.7.3") &&
11
- (plan.operationKind === "swarm" || plan.operationKind === "swarm-write");
12
- }
13
- function plainObject(value) {
14
- return value !== null && typeof value === "object" && !Array.isArray(value) &&
15
- (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
16
- }
17
- function nonemptyString(value) {
18
- return typeof value === "string" && value.trim().length > 0;
19
- }
20
- const SWARM_INPUT_KEYS = new Set([
21
- "description", "subagent_type", "prompt_template", "items", "fork", "resume_agent_ids", "model",
22
- ]);
23
- /** Stateless admission; repeated host hooks cannot consume or refund slots. */
24
- export function evaluateSwarmWaveInput(input, policy, waveSize) {
25
- const deny = (reason) => ({
26
- decision: "deny",
27
- reason: `kimi-plugin-cc safety hook: AgentSwarm denied: ${reason}`,
28
- });
29
- if (policy !== BOUNDED_SWARM_POLICY)
30
- return deny("missing or unrecognized swarm policy.");
31
- const width = typeof waveSize === "string" && /^[1-9][0-9]*$/.test(waveSize)
32
- ? Number(waveSize) : NaN;
33
- if (!Number.isSafeInteger(width) || width < 1)
34
- return deny("missing or invalid trusted wave size.");
35
- if (width === 1) {
36
- return deny("concurrency 1 uses one worker directly; complete the task yourself without delegation.");
37
- }
38
- if (!plainObject(input))
39
- return deny("arguments must be an object.");
40
- if (Reflect.ownKeys(input).some((key) => typeof key !== "string" || !SWARM_INPUT_KEYS.has(key))) {
41
- return deny("unrecognized arguments.");
42
- }
43
- if (!nonemptyString(input.description))
44
- return deny("description must be a nonempty string.");
45
- for (const key of ["subagent_type", "prompt_template"]) {
46
- if (input[key] !== undefined && !nonemptyString(input[key]))
47
- return deny(`${key} must be a nonempty string.`);
48
- }
49
- if (input.model !== undefined && typeof input.model !== "string")
50
- return deny("model must be a string.");
51
- if (input.fork !== undefined && input.fork !== false)
52
- return deny("forked subagents are not supported.");
53
- if (input.items !== undefined && (!Array.isArray(input.items) || !input.items.every(nonemptyString))) {
54
- return deny("items must be an array of nonempty strings.");
55
- }
56
- if (input.resume_agent_ids !== undefined && (!plainObject(input.resume_agent_ids) ||
57
- Reflect.ownKeys(input.resume_agent_ids).some((key) => typeof key !== "string" ||
58
- !nonemptyString(key) || !nonemptyString(input.resume_agent_ids[key])))) {
59
- return deny("resume_agent_ids must map nonempty agent IDs to nonempty prompts.");
60
- }
61
- const fresh = Array.isArray(input.items) ? input.items.length : 0;
62
- const resumed = plainObject(input.resume_agent_ids) ? Object.keys(input.resume_agent_ids).length : 0;
63
- const total = fresh + resumed;
64
- if (total === 0)
65
- return deny("a wave must contain at least one new or resumed entry.");
66
- if (total > width) {
67
- return deny(`wave has ${total} new and resumed entries, exceeding the limit ${width}; split the work into sequential waves of at most ${width} entries and wait for each wave to finish.`);
68
- }
69
- if (fresh === 1 && resumed === 0) {
70
- return deny("fresh-only waves require at least two entries; regroup targets into disjoint entries within the wave limit, or resume an existing child for the remaining work.");
71
- }
72
- return { decision: "allow" };
73
- }
@@ -1,165 +0,0 @@
1
- import { RuntimeError } from "./errors.js";
2
- import { collectDescendantIdentities, collectProcessGroupsIdentities, probeProcessIdentity, revalidateProcessIdentities } from "./process-tree.js";
3
- export function recordRecoveryEvent(store, record, event) {
4
- record.complete = false;
5
- if (event.kind === "session") {
6
- record.session = { sessionId: event.sessionId, workspaceId: event.workspaceId };
7
- // Write-ahead: this must commit before the profile mutation is attempted.
8
- record.sessionDirty = true;
9
- }
10
- else if (event.kind === "disabled") {
11
- record.sessionDirty = false;
12
- }
13
- else if (event.kind.endsWith("-spawn")) {
14
- record.launches.push({ kind: event.kind === "web-spawn" ? "web" : "print", pending: true, identities: [], quiescent: false, uncertain: false });
15
- }
16
- else {
17
- const kind = event.kind.startsWith("web-") ? "web" : "print";
18
- const launch = [...record.launches].reverse().find((entry) => entry.kind === kind);
19
- if (!launch)
20
- throw recoveryError("Missing durable launch intent.");
21
- if (event.kind === "web-exit" || event.kind === "print-exit") {
22
- launch.quiescent = true;
23
- launch.pending = false;
24
- }
25
- else if (event.kind === "print-processes-snapshot") {
26
- const root = launch.identities[0];
27
- if (!root)
28
- throw recoveryError("The print root identity was not durably recorded before its process snapshot.");
29
- // The root remains the recovery anchor after exit. Complete bounded
30
- // snapshots replace historical descendants; an incomplete observation
31
- // cannot discard an identity whose exit has not been proven.
32
- const previous = new Map(launch.identities.map((identity) => [processIdentityKey(identity), identity]));
33
- const current = event.identities.map((identity) => previous.get(processIdentityKey(identity)) ?? identity);
34
- const all = event.complete ? [root, ...current] : [...launch.identities, ...current];
35
- launch.identities = [...new Map(all.map((identity) => [processIdentityKey(identity), identity])).values()];
36
- launch.pending = false;
37
- launch.uncertain = !event.complete;
38
- launch.boundedSnapshot = true;
39
- }
40
- else if ("identities" in event) {
41
- const all = [...launch.identities, ...event.identities];
42
- launch.identities = [...new Map(all.map((identity) => [`${identity.pid}:${identity.startToken}:${identity.processGroupId}`, identity])).values()];
43
- launch.pending = launch.identities.length === 0;
44
- launch.uncertain ||= !event.complete;
45
- }
46
- }
47
- store.saveSwarmRecovery(record.jobId, record);
48
- }
49
- function processIdentityKey(identity) {
50
- // A changed process group is not a new ownership grant for the same process.
51
- return `${identity.pid}:${identity.startToken}`;
52
- }
53
- export function finishRecoveryRecord(store, record) {
54
- record.complete = !record.sessionDirty && record.launches.every((entry) => entry.quiescent)
55
- && (record.workspaceRoot === null || record.patchPath !== null);
56
- store.saveSwarmRecovery(record.jobId, record);
57
- }
58
- export function recoveryError(message) {
59
- return new RuntimeError("SWARM_RECOVERY_REQUIRED", message, "swarm.recovery");
60
- }
61
- export async function assertRecoveryOwnerGone(record) {
62
- if (!record.owner || process.platform === "win32")
63
- throw recoveryError("No durable, verifiable owner identity; recovery requires manual inspection on this host.");
64
- const probe = await probeProcessIdentity(record.ownerPid);
65
- if (!probe.complete)
66
- throw recoveryError("Cannot verify the original companion's identity.");
67
- if (probe.identity?.startToken === record.owner.startToken && !/^[ZX]/i.test(probe.identity.state)) {
68
- throw recoveryError("The original companion is still alive. Use cancel for a running job, not recovery.");
69
- }
70
- }
71
- /**
72
- * Older Linux records may retain ps start tokens while current snapshots use
73
- * /proc start ticks. Prove both representations current around the known identity
74
- * read; never accept a member based on PID/PGID equality alone.
75
- */
76
- export async function validateRecoveryGroupMembers(known, members, validate = revalidateProcessIdentities) {
77
- const membership = await validate(members);
78
- const ownership = await validate(known);
79
- const membershipAfter = await validate(membership.identities);
80
- for (const proof of [membership, ownership, membershipAfter]) {
81
- if (!proof.complete || proof.groupChanged?.length)
82
- throw recoveryError("Process ownership or group membership is uncertain.");
83
- }
84
- for (const member of membershipAfter.identities) {
85
- const owner = ownership.identities.find((id) => id.pid === member.pid && id.processGroupId === member.processGroupId);
86
- const crossNamespace = owner && ((owner.startToken.startsWith("proc:") && member.startToken.startsWith("ps:")) ||
87
- (owner.startToken.startsWith("ps:") && member.startToken.startsWith("proc:")));
88
- if (!owner || (owner.startToken !== member.startToken && !crossNamespace)) {
89
- throw recoveryError("An unrecorded process survives in the recorded group; refusing group cleanup.");
90
- }
91
- }
92
- return ownership.identities;
93
- }
94
- export async function inspectRecoveryLaunchProcesses(launch, validate = revalidateProcessIdentities, collect = collectProcessGroupsIdentities) {
95
- let known = launch.identities;
96
- if (launch.kind === "print" && launch.boundedSnapshot === true) {
97
- const live = await validate(known);
98
- if (!live.complete || live.groupChanged?.length) {
99
- throw recoveryError("Process ownership or group membership is uncertain.");
100
- }
101
- // The saved root remains first for ancestry recovery, but an exited root
102
- // grants no ownership of its numeric group after that group is reused.
103
- known = live.identities;
104
- if (known.length === 0)
105
- return [];
106
- }
107
- const members = await collect(known.map((identity) => identity.processGroupId));
108
- if (members === undefined)
109
- throw recoveryError("Process group membership is unreadable.");
110
- return validateRecoveryGroupMembers(known, members, validate);
111
- }
112
- /** Never signal an unproven group, PID replacement, or changed-PGID process. */
113
- export async function recoverLaunch(launch, persist, signal) {
114
- if (launch.quiescent)
115
- return;
116
- if (launch.pending || launch.uncertain || launch.identities.length === 0) {
117
- throw recoveryError("Launch ownership was not fully recorded before interruption; manual inspection is required. No process was signalled.");
118
- }
119
- const root = launch.identities[0];
120
- const rootProbe = await probeProcessIdentity(root.pid);
121
- if (!rootProbe.complete)
122
- throw recoveryError("Process identity probe is incomplete.");
123
- if (rootProbe.identity?.startToken === root.startToken) {
124
- if (rootProbe.identity.processGroupId !== root.processGroupId)
125
- throw recoveryError("The recorded root changed process groups; refusing to signal it.");
126
- const descendants = await collectDescendantIdentities(root.pid);
127
- // Revalidate the ancestry anchor after collection before retaining new identities.
128
- const after = await probeProcessIdentity(root.pid);
129
- if (!after.complete || after.identity?.startToken !== root.startToken || after.identity.processGroupId !== root.processGroupId) {
130
- throw recoveryError("Process ownership changed during recovery inspection.");
131
- }
132
- launch.identities = [...new Map([...launch.identities, ...descendants].map((id) => [`${id.pid}:${id.startToken}:${id.processGroupId}`, id])).values()];
133
- persist();
134
- }
135
- const inspect = () => inspectRecoveryLaunchProcesses(launch);
136
- for (const [killSignal, waitMs] of [["SIGTERM", 1500], ["SIGKILL", 500]]) {
137
- signal?.throwIfAborted();
138
- for (const identity of await inspect()) {
139
- signal?.throwIfAborted();
140
- const current = await revalidateProcessIdentities([identity]);
141
- if (!current.complete || current.groupChanged?.length)
142
- throw recoveryError("Process identity changed before signalling.");
143
- if (current.identities.length) {
144
- try {
145
- process.kill(identity.pid, killSignal);
146
- }
147
- catch (error) {
148
- if (error.code !== "ESRCH")
149
- throw recoveryError("Unable to stop the recorded process.");
150
- }
151
- }
152
- }
153
- const deadline = Date.now() + waitMs;
154
- do {
155
- signal?.throwIfAborted();
156
- if ((await inspect()).length === 0) {
157
- launch.quiescent = true;
158
- persist();
159
- return;
160
- }
161
- await new Promise((resolve) => setTimeout(resolve, 25));
162
- } while (Date.now() < deadline);
163
- }
164
- throw recoveryError("Recorded processes did not become quiescent; recovery remains pending.");
165
- }
@@ -1,146 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { constants } from "node:fs";
3
- import { link, lstat, mkdir, open, realpath, unlink } from "node:fs/promises";
4
- import path from "node:path";
5
- import { RuntimeError } from "./errors.js";
6
- const POLICY_CONTENT = `${JSON.stringify({ disabledTools: ["TaskStop"] })}\n`;
7
- const POLICY_MAX_BYTES = 4096;
8
- const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,255}$/;
9
- /**
10
- * Called only for our fresh, stopped, journal-proven session before its first
11
- * print turn. TaskStop is already denied by the managed hook; disabling it in
12
- * native policy also makes Bash's allowBackground false for every child,
13
- * including its automatic foreground-timeout detachment path.
14
- */
15
- export async function installBoundedSwarmToolPolicy(kimiHome, identity, signal) {
16
- const directories = [];
17
- let candidatePath;
18
- let candidateIdentity;
19
- try {
20
- checkSignal(signal);
21
- if (!SAFE_ID.test(identity.sessionId) || !SAFE_ID.test(identity.workspaceId)) {
22
- throw policyFailure("invalid-session-identity");
23
- }
24
- const canonicalHome = await realpath(kimiHome);
25
- let current = canonicalHome;
26
- for (const segment of [undefined, "sessions", identity.workspaceId, identity.sessionId]) {
27
- if (segment !== undefined)
28
- current = path.join(current, segment);
29
- directories.push(await directoryIdentity(current));
30
- checkSignal(signal);
31
- }
32
- const policyDir = path.join(current, "tool-policy");
33
- await assertDirectoriesUnchanged(directories);
34
- await mkdir(policyDir, { mode: 0o700 }).catch((error) => {
35
- if (error.code !== "EEXIST")
36
- throw error;
37
- });
38
- directories.push(await directoryIdentity(policyDir));
39
- const statePath = path.join(policyDir, "state.json");
40
- // No merge or replacement: this is a fresh-session construction, not an
41
- // operator-policy editor. link() below closes this absence-check race.
42
- const existing = await lstat(statePath).catch((error) => {
43
- if (error.code === "ENOENT")
44
- return undefined;
45
- throw error;
46
- });
47
- if (existing !== undefined)
48
- throw policyFailure("policy-already-exists");
49
- checkSignal(signal);
50
- await assertDirectoriesUnchanged(directories);
51
- candidatePath = path.join(policyDir, `.state.${process.pid}.${randomUUID()}.tmp`);
52
- const candidate = await open(candidatePath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
53
- try {
54
- const stats = await candidate.stat({ bigint: true });
55
- candidateIdentity = { dev: stats.dev, ino: stats.ino };
56
- if (!stats.isFile())
57
- throw policyFailure("candidate-not-regular");
58
- if (process.platform !== "win32")
59
- await candidate.chmod(0o600);
60
- await candidate.writeFile(POLICY_CONTENT, "utf8");
61
- await candidate.sync();
62
- }
63
- finally {
64
- await candidate.close();
65
- }
66
- checkSignal(signal);
67
- await assertDirectoriesUnchanged(directories);
68
- // A hard link publishes the complete synced inode atomically and refuses
69
- // an existing destination, unlike rename(), which could replace policy.
70
- await link(candidatePath, statePath);
71
- await verifyPublishedPolicy(statePath, candidateIdentity);
72
- await assertDirectoriesUnchanged(directories);
73
- checkSignal(signal);
74
- }
75
- catch (error) {
76
- if (signal?.aborted)
77
- throw policyFailure("cancelled", true);
78
- if (error instanceof RuntimeError)
79
- throw error;
80
- throw policyFailure("policy-installation-failed");
81
- }
82
- finally {
83
- // Never unlink a replacement or follow a replaced ancestor while cleaning
84
- // up our private candidate. An uncertain path remains as failure evidence.
85
- if (candidatePath !== undefined && candidateIdentity !== undefined) {
86
- try {
87
- await assertDirectoriesUnchanged(directories);
88
- const stats = await lstat(candidatePath, { bigint: true });
89
- if (stats.isFile() && sameIdentity(stats, candidateIdentity))
90
- await unlink(candidatePath);
91
- }
92
- catch { /* Preserve uncertain paths. */ }
93
- }
94
- }
95
- }
96
- async function directoryIdentity(directory) {
97
- const stats = await lstat(directory, { bigint: true });
98
- if (!stats.isDirectory() || stats.isSymbolicLink() || await realpath(directory) !== directory) {
99
- throw policyFailure("unsafe-session-directory");
100
- }
101
- return { path: directory, dev: stats.dev, ino: stats.ino };
102
- }
103
- async function assertDirectoriesUnchanged(directories) {
104
- for (const directory of directories) {
105
- const current = await directoryIdentity(directory.path);
106
- if (!sameIdentity(current, directory))
107
- throw policyFailure("session-directory-changed");
108
- }
109
- }
110
- async function verifyPublishedPolicy(statePath, expected) {
111
- const file = await open(statePath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
112
- try {
113
- const before = await file.stat({ bigint: true });
114
- if (!before.isFile() || before.size > BigInt(POLICY_MAX_BYTES) || !sameIdentity(before, expected)) {
115
- throw policyFailure("published-policy-invalid");
116
- }
117
- const bytes = Buffer.alloc(Number(before.size));
118
- let offset = 0;
119
- while (offset < bytes.length) {
120
- const { bytesRead } = await file.read(bytes, offset, bytes.length - offset, offset);
121
- if (bytesRead === 0)
122
- break;
123
- offset += bytesRead;
124
- }
125
- const after = await file.stat({ bigint: true });
126
- const named = await lstat(statePath, { bigint: true });
127
- if (offset !== bytes.length || bytes.toString("utf8") !== POLICY_CONTENT ||
128
- before.size !== after.size || !sameIdentity(after, expected) ||
129
- !named.isFile() || !sameIdentity(named, expected)) {
130
- throw policyFailure("published-policy-changed");
131
- }
132
- }
133
- finally {
134
- await file.close();
135
- }
136
- }
137
- function sameIdentity(a, b) {
138
- return a.dev === b.dev && a.ino === b.ino;
139
- }
140
- function checkSignal(signal) {
141
- if (signal?.aborted)
142
- throw policyFailure("cancelled", true);
143
- }
144
- function policyFailure(reason, cancelled = false) {
145
- return new RuntimeError("SWARM_ACTIVATION_FAILED", "The fresh swarm session could not install its native tool restriction; refusing the model turn.", "swarm-activation.tool-policy", { details: { reason, ...(cancelled ? { cancelled: true } : {}) } });
146
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
1
- The MIT License
2
-
3
- Copyright (c) 2013 James Halliday (mail@substack.net)
4
-
5
- Permission is hereby granted, free of charge,
6
- to any person obtaining a copy of this software and
7
- associated documentation files (the "Software"), to
8
- deal in the Software without restriction, including
9
- without limitation the rights to use, copy, modify,
10
- merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom
12
- the Software is furnished to do so,
13
- subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice
16
- shall be included in all copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
22
- ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1 +0,0 @@
1
- export { parse } from "./parse.js";
@@ -1,229 +0,0 @@
1
- // @ts-nocheck
2
- // Vendored from shell-quote 1.8.3 with the upstream 1.9.0 linear-finalization fix.
3
- // MIT, James Halliday. See ./LICENSE and ./README.md for provenance.
4
- 'use strict';
5
- // '<(' is process substitution operator and
6
- // can be parsed the same as control operator
7
- var CONTROL = '(?:' + [
8
- '\\|\\|',
9
- '\\&\\&',
10
- ';;',
11
- '\\|\\&',
12
- '\\<\\(',
13
- '\\<\\<\\<',
14
- '>>',
15
- '>\\&',
16
- '<\\&',
17
- '[&;()|<>]'
18
- ].join('|') + ')';
19
- var controlRE = new RegExp('^' + CONTROL + '$');
20
- var META = '|&;()<> \\t';
21
- var SINGLE_QUOTE = '"((\\\\"|[^"])*?)"';
22
- var DOUBLE_QUOTE = '\'((\\\\\'|[^\'])*?)\'';
23
- var hash = /^#$/;
24
- var SQ = "'";
25
- var DQ = '"';
26
- var DS = '$';
27
- var TOKEN = '';
28
- var mult = 0x100000000; // Math.pow(16, 8);
29
- for (var i = 0; i < 4; i++) {
30
- TOKEN += (mult * Math.random()).toString(16);
31
- }
32
- var startsWithToken = new RegExp('^' + TOKEN);
33
- function matchAll(s, r) {
34
- var origIndex = r.lastIndex;
35
- var matches = [];
36
- var matchObj;
37
- while ((matchObj = r.exec(s))) {
38
- matches.push(matchObj);
39
- if (r.lastIndex === matchObj.index) {
40
- r.lastIndex += 1;
41
- }
42
- }
43
- r.lastIndex = origIndex;
44
- return matches;
45
- }
46
- function getVar(env, pre, key) {
47
- var r = typeof env === 'function' ? env(key) : env[key];
48
- if (typeof r === 'undefined' && key != '') {
49
- r = '';
50
- }
51
- else if (typeof r === 'undefined') {
52
- r = '$';
53
- }
54
- if (typeof r === 'object') {
55
- return pre + TOKEN + JSON.stringify(r) + TOKEN;
56
- }
57
- return pre + r;
58
- }
59
- function parseInternal(string, env, opts) {
60
- if (!opts) {
61
- opts = {};
62
- }
63
- var BS = opts.escape || '\\';
64
- var BAREWORD = '(\\' + BS + '[\'"' + META + ']|[^\\s\'"' + META + '])+';
65
- var chunker = new RegExp([
66
- '(' + CONTROL + ')', // control chars
67
- '(' + BAREWORD + '|' + SINGLE_QUOTE + '|' + DOUBLE_QUOTE + ')+'
68
- ].join('|'), 'g');
69
- var matches = matchAll(string, chunker);
70
- if (matches.length === 0) {
71
- return [];
72
- }
73
- if (!env) {
74
- env = {};
75
- }
76
- var commented = false;
77
- return matches.map(function (match) {
78
- var s = match[0];
79
- if (!s || commented) {
80
- return void undefined;
81
- }
82
- if (controlRE.test(s)) {
83
- return { op: s };
84
- }
85
- // Hand-written scanner/parser for Bash quoting rules:
86
- //
87
- // 1. inside single quotes, all characters are printed literally.
88
- // 2. inside double quotes, all characters are printed literally
89
- // except variables prefixed by '$' and backslashes followed by
90
- // either a double quote or another backslash.
91
- // 3. outside of any quotes, backslashes are treated as escape
92
- // characters and not printed (unless they are themselves escaped)
93
- // 4. quote context can switch mid-token if there is no whitespace
94
- // between the two quote contexts (e.g. all'one'"token" parses as
95
- // "allonetoken")
96
- var quote = false;
97
- var esc = false;
98
- var out = '';
99
- var isGlob = false;
100
- var i;
101
- function parseEnvVar() {
102
- i += 1;
103
- var varend;
104
- var varname;
105
- var char = s.charAt(i);
106
- if (char === '{') {
107
- i += 1;
108
- if (s.charAt(i) === '}') {
109
- throw new Error('Bad substitution: ' + s.slice(i - 2, i + 1));
110
- }
111
- varend = s.indexOf('}', i);
112
- if (varend < 0) {
113
- throw new Error('Bad substitution: ' + s.slice(i));
114
- }
115
- varname = s.slice(i, varend);
116
- i = varend;
117
- }
118
- else if ((/[*@#?$!_-]/).test(char)) {
119
- varname = char;
120
- i += 1;
121
- }
122
- else {
123
- var slicedFromI = s.slice(i);
124
- varend = slicedFromI.match(/[^\w\d_]/);
125
- if (!varend) {
126
- varname = slicedFromI;
127
- i = s.length;
128
- }
129
- else {
130
- varname = slicedFromI.slice(0, varend.index);
131
- i += varend.index - 1;
132
- }
133
- }
134
- return getVar(env, '', varname);
135
- }
136
- for (i = 0; i < s.length; i++) {
137
- var c = s.charAt(i);
138
- isGlob = isGlob || (!quote && (c === '*' || c === '?'));
139
- if (esc) {
140
- out += c;
141
- esc = false;
142
- }
143
- else if (quote) {
144
- if (c === quote) {
145
- quote = false;
146
- }
147
- else if (quote == SQ) {
148
- out += c;
149
- }
150
- else { // Double quote
151
- if (c === BS) {
152
- i += 1;
153
- c = s.charAt(i);
154
- if (c === DQ || c === BS || c === DS) {
155
- out += c;
156
- }
157
- else {
158
- out += BS + c;
159
- }
160
- }
161
- else if (c === DS) {
162
- out += parseEnvVar();
163
- }
164
- else {
165
- out += c;
166
- }
167
- }
168
- }
169
- else if (c === DQ || c === SQ) {
170
- quote = c;
171
- }
172
- else if (controlRE.test(c)) {
173
- return { op: s };
174
- }
175
- else if (hash.test(c)) {
176
- commented = true;
177
- var commentObj = { comment: string.slice(match.index + i + 1) };
178
- if (out.length) {
179
- return [out, commentObj];
180
- }
181
- return [commentObj];
182
- }
183
- else if (c === BS) {
184
- esc = true;
185
- }
186
- else if (c === DS) {
187
- out += parseEnvVar();
188
- }
189
- else {
190
- out += c;
191
- }
192
- }
193
- if (isGlob) {
194
- return { op: 'glob', pattern: out };
195
- }
196
- return out;
197
- }).reduce(function (prev, arg) {
198
- if (typeof arg === 'undefined') {
199
- return prev;
200
- }
201
- [].concat(arg).forEach(function (entry) {
202
- prev[prev.length] = entry;
203
- });
204
- return prev;
205
- }, []);
206
- }
207
- export function parse(s, env, opts) {
208
- var mapped = parseInternal(s, env, opts);
209
- if (typeof env !== 'function') {
210
- return mapped;
211
- }
212
- return mapped.reduce(function (acc, value) {
213
- if (typeof value === 'object') {
214
- acc[acc.length] = value;
215
- return acc;
216
- }
217
- var xs = value.split(RegExp('(' + TOKEN + '.*?' + TOKEN + ')', 'g'));
218
- if (xs.length === 1) {
219
- acc[acc.length] = xs[0];
220
- return acc;
221
- }
222
- xs.filter(Boolean).forEach(function (x) {
223
- acc[acc.length] = startsWithToken.test(x)
224
- ? JSON.parse(x.split(TOKEN)[1])
225
- : x;
226
- });
227
- return acc;
228
- }, []);
229
- }
@@ -1,24 +0,0 @@
1
- Copyright (c) Squirrel Chat et al., All rights reserved.
2
-
3
- Redistribution and use in source and binary forms, with or without
4
- modification, are permitted provided that the following conditions are met:
5
-
6
- 1. Redistributions of source code must retain the above copyright notice, this
7
- list of conditions and the following disclaimer.
8
- 2. Redistributions in binary form must reproduce the above copyright notice,
9
- this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
11
- 3. Neither the name of the copyright holder nor the names of its contributors
12
- may be used to endorse or promote products derived from this software without
13
- specific prior written permission.
14
-
15
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.