@aibyzero/cm-workflow 0.17.1 → 0.18.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 (352) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +23 -0
  3. package/CHANGELOG.md +224 -0
  4. package/README.md +14 -3
  5. package/THIRD_PARTY_NOTICES.md +13 -0
  6. package/VERSION +1 -1
  7. package/compat/claude-commands/cm-challenge.md +3 -0
  8. package/docs/architecture.md +11 -0
  9. package/docs/cm-control-policy-v2.md +127 -9
  10. package/docs/installation.md +310 -4
  11. package/docs/js-workflow-control.md +150 -15
  12. package/docs/live-evidence-drivers.md +28 -4
  13. package/docs/out-of-scope/README.md +25 -0
  14. package/docs/out-of-scope/background-supervisor.md +32 -0
  15. package/docs/reviewed-integration.md +48 -0
  16. package/docs/user-guide.md +50 -21
  17. package/install-codex.sh +331 -18
  18. package/install.ps1 +28 -2
  19. package/install.sh +321 -17
  20. package/package.json +2 -1
  21. package/runtime/js/cm-ai/batch-location.mjs +55 -0
  22. package/runtime/js/cm-ai/batch-plan.mjs +242 -0
  23. package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
  24. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
  25. package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
  26. package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
  27. package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
  28. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
  29. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
  30. package/runtime/js/cm-ai/codex-config.mjs +6 -2
  31. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
  32. package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
  33. package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
  34. package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
  35. package/runtime/js/cm-ai/control-policy.mjs +21 -4
  36. package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
  37. package/runtime/js/cm-ai/drive-core.mjs +114 -11
  38. package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
  39. package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
  40. package/runtime/js/cm-ai/effect-contract.mjs +11 -2
  41. package/runtime/js/cm-ai/execution-policy.mjs +3 -1
  42. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
  43. package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
  44. package/runtime/js/cm-ai/execution-store.mjs +60 -17
  45. package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
  46. package/runtime/js/cm-ai/host-check.mjs +11 -5
  47. package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
  48. package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
  49. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
  50. package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
  51. package/runtime/js/cm-ai/host-replay.mjs +148 -0
  52. package/runtime/js/cm-ai/host-session.mjs +1 -1
  53. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
  54. package/runtime/js/cm-ai/host.mjs +1 -1
  55. package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
  56. package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
  57. package/runtime/js/cm-ai/live-evidence.mjs +28 -6
  58. package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
  59. package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
  60. package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
  61. package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
  62. package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
  63. package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
  64. package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
  65. package/runtime/js/cm-ai/review-package.mjs +79 -7
  66. package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
  67. package/runtime/js/cm-ai/review-presentation.mjs +177 -8
  68. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
  69. package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
  70. package/runtime/js/cm-ai/scope-revision.mjs +38 -0
  71. package/runtime/js/cm-ai/specification-material.mjs +2 -2
  72. package/runtime/js/cm-ai/task-runner.mjs +242 -39
  73. package/runtime/js/cm-ai/verification-auto.mjs +38 -0
  74. package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
  75. package/runtime/js/cm-ai/worker-claude.mjs +35 -13
  76. package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
  77. package/runtime/js/cm-ai/worker-codex.mjs +41 -7
  78. package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
  79. package/runtime/js/cm-fix/cause-package.mjs +46 -1
  80. package/runtime/js/cm-fix/command-correction.mjs +37 -0
  81. package/runtime/js/cm-fix/cooperative.mjs +12 -0
  82. package/runtime/js/cm-fix/dossier.mjs +8 -2
  83. package/runtime/js/cm-fix/execution.mjs +578 -100
  84. package/runtime/js/cm-fix/final-review.mjs +39 -8
  85. package/runtime/js/cm-fix/finish.mjs +15 -11
  86. package/runtime/js/cm-fix/host-review.mjs +65 -10
  87. package/runtime/js/cm-fix/host.mjs +35 -12
  88. package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
  89. package/runtime/js/cm-fix/metrics.mjs +18 -5
  90. package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
  91. package/runtime/js/cm-fix/regression.mjs +16 -7
  92. package/runtime/js/cm-fix/repair.mjs +29 -8
  93. package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
  94. package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
  95. package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
  96. package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
  97. package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
  98. package/runtime/js/cm-fix/review-verification.mjs +214 -0
  99. package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
  100. package/runtime/js/cm-fix/start.mjs +6 -3
  101. package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
  102. package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
  103. package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
  104. package/runtime/js/cm-prd/accepted-design.mjs +8 -0
  105. package/runtime/js/cm-prd/analysis.mjs +13 -9
  106. package/runtime/js/cm-prd/change.mjs +37 -16
  107. package/runtime/js/cm-prd/draft-save.mjs +13 -6
  108. package/runtime/js/cm-prd/draft.mjs +31 -3
  109. package/runtime/js/cm-prd/failed-correction.mjs +19 -3
  110. package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
  111. package/runtime/js/cm-prd/review-correction.mjs +6 -4
  112. package/runtime/js/cm-prd/review-disposition.mjs +7 -1
  113. package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
  114. package/runtime/js/cm-prd/self-check.mjs +125 -6
  115. package/runtime/js/cm-prd/session.mjs +30 -1
  116. package/runtime/js/cm-prd/summary.mjs +11 -5
  117. package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
  118. package/runtime/js/cm-prd/tree-digest.mjs +34 -0
  119. package/runtime/js/cm-prd/validation-reason.mjs +8 -4
  120. package/runtime/js/cm-security/scan.mjs +1 -1
  121. package/runtime/js/commander/decision.mjs +44 -0
  122. package/runtime/js/commander/dispatch-registry.mjs +110 -0
  123. package/runtime/js/commander/ledger.mjs +265 -0
  124. package/runtime/js/commander/preflight.mjs +107 -0
  125. package/runtime/js/notify-later.mjs +13 -0
  126. package/runtime/js/notify-send.mjs +6 -2
  127. package/runtime/js/notify.mjs +570 -63
  128. package/runtime/js/review-findings.mjs +38 -0
  129. package/runtime/js/session-boundary.mjs +56 -0
  130. package/runtime/js/session-handoff.mjs +68 -0
  131. package/runtime/js/spec-task-line.mjs +27 -13
  132. package/runtime/js/specs-status.mjs +1 -1
  133. package/runtime/js/task-scope.mjs +197 -0
  134. package/runtime/logging.md +6 -1
  135. package/runtime/model-efficiency.md +69 -10
  136. package/runtime/orchestration.md +3 -1
  137. package/runtime/project-learning.md +2 -0
  138. package/runtime/review.md +3 -2
  139. package/runtime/test-contract.md +1 -0
  140. package/scripts/ci-test-weights.json +3 -0
  141. package/scripts/cm-ai-admission.mjs +11 -5
  142. package/scripts/cm-ai-admission.test.mjs +23 -2
  143. package/scripts/cm-ai-batch-drive.mjs +79 -18
  144. package/scripts/cm-ai-batch-drive.test.mjs +169 -3
  145. package/scripts/cm-ai-batch-host.mjs +38 -9
  146. package/scripts/cm-ai-batch-host.test.mjs +6 -5
  147. package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
  148. package/scripts/cm-ai-batch-location.test.mjs +57 -0
  149. package/scripts/cm-ai-batch-plan.mjs +52 -0
  150. package/scripts/cm-ai-batch-plan.test.mjs +397 -0
  151. package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
  152. package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
  153. package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
  154. package/scripts/cm-ai-batch-run.mjs +471 -57
  155. package/scripts/cm-ai-batch-run.test.mjs +23 -4
  156. package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
  157. package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
  158. package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
  159. package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
  160. package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
  161. package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
  162. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
  163. package/scripts/cm-ai-control-launch.test.mjs +21 -0
  164. package/scripts/cm-ai-control-policy.test.mjs +14 -0
  165. package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
  166. package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
  167. package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
  168. package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
  169. package/scripts/cm-ai-development-rework.test.mjs +423 -0
  170. package/scripts/cm-ai-drive.mjs +73 -17
  171. package/scripts/cm-ai-drive.test.mjs +34 -2
  172. package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
  173. package/scripts/cm-ai-host.mjs +60 -19
  174. package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
  175. package/scripts/cm-ai-integration-independence.test.mjs +23 -0
  176. package/scripts/cm-ai-integration-launch.test.mjs +240 -0
  177. package/scripts/cm-ai-integration-preview.mjs +41 -0
  178. package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
  179. package/scripts/cm-ai-nested-execution.test.mjs +29 -1
  180. package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
  181. package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
  182. package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
  183. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
  184. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
  185. package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
  186. package/scripts/cm-ai-review-failure.test.mjs +150 -5
  187. package/scripts/cm-ai-run.mjs +88 -21
  188. package/scripts/cm-ai-scope-revision.test.mjs +341 -0
  189. package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
  190. package/scripts/cm-ai-supersede.test.mjs +28 -0
  191. package/scripts/cm-ai-verification-auto.test.mjs +99 -0
  192. package/scripts/cm-announce-hook.mjs +35 -8
  193. package/scripts/cm-announce-hook.test.mjs +25 -0
  194. package/scripts/cm-challenge.test.mjs +61 -0
  195. package/scripts/cm-check-drive-files.mjs +1 -1
  196. package/scripts/cm-check-runtime.sh +58 -1
  197. package/scripts/cm-claude-developer-worker.test.mjs +56 -7
  198. package/scripts/cm-claude-install-layout.test.mjs +1 -1
  199. package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
  200. package/scripts/cm-claude-review-stream.test.mjs +13 -0
  201. package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
  202. package/scripts/cm-codex-developer-worker.test.mjs +120 -0
  203. package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
  204. package/scripts/cm-codex-prompt-input.test.mjs +153 -0
  205. package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
  206. package/scripts/cm-commander-ledger.test.mjs +260 -0
  207. package/scripts/cm-commander-p2.test.mjs +295 -0
  208. package/scripts/cm-commander-preflight.mjs +84 -0
  209. package/scripts/cm-commander.mjs +116 -0
  210. package/scripts/cm-config-lock.mjs +35 -0
  211. package/scripts/cm-controlled-correction.test.mjs +10 -1
  212. package/scripts/cm-developer-failure-code.test.mjs +62 -0
  213. package/scripts/cm-display-task-id.test.mjs +41 -0
  214. package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
  215. package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
  216. package/scripts/cm-external-batch-host.test.mjs +4 -3
  217. package/scripts/cm-external-process-cleanup.test.mjs +128 -0
  218. package/scripts/cm-external-qa-fix.test.mjs +89 -7
  219. package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
  220. package/scripts/cm-failover.mjs +48 -10
  221. package/scripts/cm-failover.test.mjs +46 -0
  222. package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
  223. package/scripts/cm-fix-command-correction.mjs +17 -0
  224. package/scripts/cm-fix-command-correction.test.mjs +211 -0
  225. package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
  226. package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
  227. package/scripts/cm-fix-drive.mjs +33 -5
  228. package/scripts/cm-fix-drive.test.mjs +49 -0
  229. package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
  230. package/scripts/cm-fix-host-review.test.mjs +21 -9
  231. package/scripts/cm-fix-host.mjs +26 -8
  232. package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
  233. package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
  234. package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
  235. package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
  236. package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
  237. package/scripts/cm-fix-review-preflight.mjs +24 -0
  238. package/scripts/cm-fix-review-storage.test.mjs +233 -0
  239. package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
  240. package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
  241. package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
  242. package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
  243. package/scripts/cm-fix-review-verification.test.mjs +146 -0
  244. package/scripts/cm-fix-revision-transport.test.mjs +81 -0
  245. package/scripts/cm-fix-source-correction.test.mjs +296 -0
  246. package/scripts/cm-fix-test-type-correction.mjs +18 -0
  247. package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
  248. package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
  249. package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
  250. package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
  251. package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
  252. package/scripts/cm-fix-verification-recovery.mjs +33 -0
  253. package/scripts/cm-host-qa-executor.test.mjs +77 -0
  254. package/scripts/cm-host-replay.test.mjs +176 -0
  255. package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
  256. package/scripts/cm-install-manifest.sh +351 -0
  257. package/scripts/cm-live-evidence.test.mjs +59 -1
  258. package/scripts/cm-log-event.mjs +61 -10
  259. package/scripts/cm-log-event.test.mjs +121 -1
  260. package/scripts/cm-matt-skills.mjs +576 -0
  261. package/scripts/cm-matt-skills.test.mjs +550 -0
  262. package/scripts/cm-notify-command.test.mjs +42 -10
  263. package/scripts/cm-notify.mjs +14 -10
  264. package/scripts/cm-notify.test.mjs +575 -59
  265. package/scripts/cm-patrol.mjs +4 -1
  266. package/scripts/cm-patrol.test.mjs +23 -5
  267. package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
  268. package/scripts/cm-prd-completion.test.mjs +56 -13
  269. package/scripts/cm-prd-design-phase.test.mjs +78 -8
  270. package/scripts/cm-prd-draft-save.test.mjs +12 -0
  271. package/scripts/cm-prd-draft.test.mjs +1 -1
  272. package/scripts/cm-prd-drive.mjs +13 -6
  273. package/scripts/cm-prd-drive.test.mjs +45 -1
  274. package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
  275. package/scripts/cm-prd-host.mjs +10 -5
  276. package/scripts/cm-prd-host.test.mjs +4 -2
  277. package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
  278. package/scripts/cm-prd-review-disposition.test.mjs +124 -8
  279. package/scripts/cm-prd-revision.test.mjs +1 -1
  280. package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
  281. package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
  282. package/scripts/cm-prd-self-check.test.mjs +105 -5
  283. package/scripts/cm-prd-summary.test.mjs +24 -3
  284. package/scripts/cm-prd-task-grouping.test.mjs +6 -6
  285. package/scripts/cm-prd-tree-digest.test.mjs +74 -0
  286. package/scripts/cm-refactor-drive.mjs +2 -1
  287. package/scripts/cm-refactor-drive.test.mjs +9 -0
  288. package/scripts/cm-release-smoke.sh +1 -1
  289. package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
  290. package/scripts/cm-skill-hints-exam.mjs +149 -0
  291. package/scripts/cm-skill-hints-install.test.mjs +168 -0
  292. package/scripts/cm-skill-hints.exam.json +706 -0
  293. package/scripts/cm-skill-hints.json +119 -0
  294. package/scripts/cm-skill-hints.mjs +669 -0
  295. package/scripts/cm-skill-hints.test.mjs +831 -0
  296. package/scripts/cm-skill-judge.mjs +181 -0
  297. package/scripts/cm-skill-judge.test.mjs +255 -0
  298. package/scripts/cm-specs-status.test.mjs +4 -2
  299. package/scripts/cm-start-check.mjs +208 -0
  300. package/scripts/cm-start-check.test.mjs +321 -0
  301. package/scripts/cm-task-gate.mjs +150 -29
  302. package/scripts/cm-task-gate.test.mjs +73 -1
  303. package/scripts/cm-task-id-grammar.test.mjs +66 -0
  304. package/scripts/cm-task-scope.test.mjs +308 -0
  305. package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
  306. package/scripts/cm-upgrade-compat.test.mjs +239 -0
  307. package/scripts/cm-workflow-config.mjs +12 -2
  308. package/scripts/fixtures/fix-verification-claude.mjs +44 -0
  309. package/scripts/fixtures/reviewed-integration.mjs +202 -0
  310. package/scripts/scan-public-safety.py +1 -0
  311. package/scripts/session-boundary.test.mjs +170 -0
  312. package/scripts/test-npm-install.py +14 -3
  313. package/scripts/test-shell-compat.sh +2 -0
  314. package/scripts/validate-public-repo.py +1 -0
  315. package/scripts/validate-test-cases.mjs +3 -2
  316. package/skills/cm-ai/SKILL.md +5 -2
  317. package/skills/cm-ai/references/N4-review.md +2 -1
  318. package/skills/cm-ai/references/N6-qa-eval.md +3 -1
  319. package/skills/cm-ai/references/N8-finish.md +22 -0
  320. package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
  321. package/skills/cm-ai/references/js-host-recovery.md +79 -3
  322. package/skills/cm-ai/references/js-host.md +56 -16
  323. package/skills/cm-challenge/SKILL.md +65 -0
  324. package/skills/cm-challenge/evals/README.md +18 -0
  325. package/skills/cm-challenge/evals/trigger-cases.json +20 -0
  326. package/skills/cm-challenge/evals/trigger-config.json +28 -0
  327. package/skills/cm-challenge/references/examples.md +15 -0
  328. package/skills/cm-check/SKILL.md +5 -0
  329. package/skills/cm-check/references/js-host.md +2 -0
  330. package/skills/cm-fix/SKILL.md +12 -3
  331. package/skills/cm-fix/references/command-correction.md +67 -0
  332. package/skills/cm-fix/references/isolated-review.md +54 -0
  333. package/skills/cm-fix/references/js-host.md +62 -2
  334. package/skills/cm-fix/references/test-type-correction.md +72 -0
  335. package/skills/cm-fix/references/verification-recovery.md +114 -0
  336. package/skills/cm-idea/SKILL.md +2 -0
  337. package/skills/cm-idea/references/js-host.md +2 -0
  338. package/skills/cm-notify/SKILL.md +2 -0
  339. package/skills/cm-prd/SKILL.md +12 -8
  340. package/skills/cm-prd/references/brownfield.md +8 -1
  341. package/skills/cm-prd/references/change-mode.md +6 -0
  342. package/skills/cm-prd/references/greenfield.md +4 -0
  343. package/skills/cm-prd/references/js-host.md +4 -2
  344. package/skills/cm-prd/references/spec-self-check.md +5 -1
  345. package/skills/cm-refactor/SKILL.md +8 -0
  346. package/skills/cm-refactor/references/js-host.md +2 -0
  347. package/skills/cm-test/SKILL.md +4 -0
  348. package/templates/dashboard/dashboard.html +2 -2
  349. package/templates/pixel/cm-pixel.html +1 -1
  350. package/templates/pixel/cm-pixel.sh +1 -1
  351. package/templates/pixel/dev/template.html +1 -1
  352. package/templates/statusline/cm-statusline.sh +1 -1
@@ -4,6 +4,8 @@ import {spawn} from 'node:child_process';
4
4
  import fs from 'node:fs';
5
5
  import os from 'node:os';
6
6
  import path from 'node:path';
7
+ import {EventEmitter} from 'node:events';
8
+ import {PassThrough} from 'node:stream';
7
9
  import {codexDeveloperWorker,developerArgs} from '../runtime/js/cm-ai/worker-codex-developer.mjs';
8
10
  import {commonArgs} from '../runtime/js/cm-ai/codex-config.mjs';
9
11
  import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
@@ -211,3 +213,121 @@ for(const mode of ['omitted','non-function','throwing'])test(`developer notice c
211
213
  assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),
212
214
  {status:'unavailable',code:'worker_dispatch_limit'});
213
215
  }));
216
+
217
+ // 2026-10-26: a Codex developer that hits the API rate limit (429 / Too Many Requests /
218
+ // rate limit, the same rule as the Codex reviewer) ends as developer_rate_limited;
219
+ // other provider failures stay provider_failed. Only the class is kept.
220
+ const limitedScript=message=>`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
221
+ const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
222
+ emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
223
+ emit({type:'error',message:${JSON.stringify(message)}});emit({type:'turn.failed',error:{message:${JSON.stringify(message)}}});
224
+ setTimeout(()=>process.exit(1),5000);
225
+ });`;
226
+ for(const [message,code] of [['exceeded retry limit, last status: 429 Too Many Requests','developer_rate_limited'],
227
+ ['unexpected status HTTP 429','developer_rate_limited'],['Rate limit reached','developer_rate_limited'],
228
+ ['request failed','provider_failed'],['error 4290 unrelated id','provider_failed']])
229
+ test(`Codex developer failure "${message}" ends as ${code}`,()=>fixture(async cwd=>{
230
+ const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
231
+ spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',limitedScript(message)],options)});
232
+ const result=await worker({prompt:'synthetic'},{signal:new AbortController().signal});
233
+ assert.deepEqual(result,{status:'unknown',code});
234
+ }));
235
+
236
+ // Codex review round 1: the class is collected from every failure event of the turn
237
+ // (as the Codex reviewer does), whichever carries it; the terminal stays the first.
238
+ const failedPair=(first,second)=>`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
239
+ const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
240
+ emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
241
+ emit({type:'error',message:${JSON.stringify(first)}});emit({type:'turn.failed',error:{message:${JSON.stringify(second)}}});
242
+ setTimeout(()=>process.exit(1),5000);
243
+ });`;
244
+ for(const [first,second,code] of [['Request failed','HTTP 429 Too Many Requests','developer_rate_limited'],
245
+ ['HTTP 429 Too Many Requests','Request failed','developer_rate_limited'],['Request failed','stream closed','provider_failed']])
246
+ test(`Codex developer error "${first}" then turn.failed "${second}" ends as ${code}`,()=>fixture(async cwd=>{
247
+ const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
248
+ spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',failedPair(first,second)],options)});
249
+ assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code});
250
+ }));
251
+
252
+ // Ticket 11: Codex can write the generic error line first and the turn.failed naming
253
+ // the 429 a moment later. Killing the group on the first line used to lose the class.
254
+ const delayedPair=delayMs=>`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
255
+ const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
256
+ emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
257
+ emit({type:'error',message:'Request failed'});
258
+ ${delayMs===null?'':`setTimeout(()=>emit({type:'turn.failed',error:{message:'HTTP 429 Too Many Requests'}}),${delayMs});`}
259
+ setTimeout(()=>process.exit(1),5000);
260
+ });`;
261
+ test('Codex developer keeps the 429 of a turn.failed written 400 ms after a generic error',()=>fixture(async cwd=>{
262
+ const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
263
+ spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',delayedPair(400)],options)});
264
+ assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'developer_rate_limited'});
265
+ }));
266
+ test('Codex developer stops a lone generic error within the short grace, not the call timeout',()=>fixture(async cwd=>{
267
+ const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',timeoutMs:60000,
268
+ spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',delayedPair(null)],options)});
269
+ const started=Date.now();
270
+ assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'provider_failed'});
271
+ assert.ok(Date.now()-started<4500,`stopped after ${Date.now()-started} ms`);
272
+ }));
273
+
274
+ // Codex review r1 (ticket 11): a cancel or timeout during the grace keeps its own code,
275
+ // and a second error line stops at once instead of waiting out the grace.
276
+ test('Codex developer cancel and timeout during the error grace keep cancelled and timeout',()=>fixture(async cwd=>{
277
+ const cancelled=new AbortController();
278
+ const cancel=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
279
+ spawnProcess:(_,__,options)=>{setTimeout(()=>cancelled.abort(),300);return spawn(process.execPath,['-e',delayedPair(null)],options);}});
280
+ assert.deepEqual(await cancel({prompt:'synthetic'},{signal:cancelled.signal}),{status:'unknown',code:'cancelled'});
281
+ const timeout=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',timeoutMs:500,
282
+ spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',delayedPair(null)],options)});
283
+ assert.deepEqual(await timeout({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'timeout'});
284
+ }));
285
+ test('Codex developer stops at once on a second error line and keeps its 429 class',()=>fixture(async cwd=>{
286
+ const script=`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
287
+ const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
288
+ emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
289
+ emit({type:'error',message:'Request failed'});setTimeout(()=>emit({type:'error',message:'HTTP 429 Too Many Requests'}),100);
290
+ setTimeout(()=>process.exit(1),5000);
291
+ });`;
292
+ const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
293
+ spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',script],options)});
294
+ const started=Date.now();
295
+ assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'developer_rate_limited'});
296
+ // Without the immediate stop the 2 s grace plus the 1 s kill escalation would pass 3 s.
297
+ assert.ok(Date.now()-started<2700,`stopped after ${Date.now()-started} ms`);
298
+ }));
299
+
300
+ test('Codex developer starts no grace for an unterminated error read at close',async()=>{
301
+ const timers=()=>process.getActiveResourcesInfo().filter(name=>name==='Timeout').length;
302
+ const worker=codexDeveloperWorker({cwd:'/fixture',model:'fixture',schemaPath:'/unused',
303
+ spawnProcess(){
304
+ // In-memory child without a pid: group signals are skipped, only the stream matters.
305
+ const child=new EventEmitter();child.stdin=new PassThrough();child.stdout=new PassThrough();child.stderr=new PassThrough();
306
+ child.stdin.on('finish',()=>{
307
+ child.stdout.write([{type:'thread.started',thread_id:'fixture'},{type:'turn.started'}].map(x=>JSON.stringify(x)+'\n').join(''));
308
+ child.stdout.end(JSON.stringify({type:'error',message:'Request failed'}));
309
+ child.stdout.once('end',()=>{child.emit('exit',1,null);child.emit('close',1,null);});
310
+ });
311
+ return child;
312
+ }});
313
+ const before=timers();
314
+ assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'provider_failed'});
315
+ assert.equal(timers(),before,'no grace timer left after the call settled');
316
+ });
317
+
318
+ // 2026-10-27: a Codex developer that exits right after its failed turn (its group is
319
+ // then only our unreaped zombie child, EPERM on macOS) is proven stopped, so the call
320
+ // keeps its class instead of process_cleanup_failed.
321
+ test('Codex developer exiting at once after a 429 keeps developer_rate_limited (no cleanup failure)',()=>fixture(async cwd=>{
322
+ const script=`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
323
+ const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
324
+ emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
325
+ emit({type:'error',message:'HTTP 429 Too Many Requests'});emit({type:'turn.failed',error:{message:'HTTP 429 Too Many Requests'}});
326
+ process.exit(1);
327
+ });`;
328
+ for(let attempt=0;attempt<3;attempt++){
329
+ const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
330
+ spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',script],options)});
331
+ assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'developer_rate_limited'},`attempt ${attempt}`);
332
+ }
333
+ }));
@@ -0,0 +1,436 @@
1
+ // Codex installer: replacing ~/plugins/cm-workflow must stop on files
2
+ // hand-edited since the last install, even with --yes. Runs in a disposable
3
+ // HOME/CODEX_HOME with a stub plugin creator and a stub `codex` CLI, so it
4
+ // never touches the real ~/plugins, ~/.agents or ~/.codex.
5
+ import test from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ import fs from 'node:fs';
8
+ import os from 'node:os';
9
+ import path from 'node:path';
10
+ import {spawn, spawnSync} from 'node:child_process';
11
+ import {fileURLToPath} from 'node:url';
12
+
13
+ const source = fileURLToPath(new URL('..', import.meta.url));
14
+ const MANIFEST = '.cm-install-manifest.sha256';
15
+ const EDITED = 'skills/cm-check/SKILL.md';
16
+
17
+ const STUB_CREATOR = `import json, pathlib, sys
18
+ args = sys.argv[1:]
19
+ path = pathlib.Path(args[args.index('--marketplace-path') + 1])
20
+ # Every run changes the file, so a later rollback has something to undo.
21
+ data = json.loads(path.read_text()) if path.exists() else {'name': 'personal', 'plugins': [{'name': 'cm-workflow'}]}
22
+ data['stubWrites'] = data.get('stubWrites', 0) + 1
23
+ path.parent.mkdir(parents=True, exist_ok=True)
24
+ path.write_text(json.dumps(data) + '\\n')
25
+ `;
26
+
27
+ function sandbox(t) {
28
+ const home = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cm-codex-install-guard-')));
29
+ t.after(() => fs.rmSync(home, {recursive: true, force: true}));
30
+ const codexHome = path.join(home, '.codex');
31
+ const creator = path.join(codexHome, 'skills/.system/plugin-creator/scripts');
32
+ fs.mkdirSync(creator, {recursive: true});
33
+ fs.writeFileSync(path.join(creator, 'create_basic_plugin.py'), STUB_CREATOR);
34
+ const bin = path.join(home, 'bin');
35
+ fs.mkdirSync(bin);
36
+ fs.writeFileSync(path.join(bin, 'codex'), '#!/bin/sh\nexit 0\n', {mode: 0o755});
37
+ const env = {...process.env, HOME: home, CODEX_HOME: codexHome, PATH: `${bin}:${process.env.PATH}`,
38
+ CM_WORKFLOW_HOME: path.join(home, 'workflow'), CM_WORKFLOW_LOG_HOME: path.join(home, 'logs'), CM_MATT_SKILLS_INSTALL: 'off'};
39
+ return {home, bin, plugin: path.join(home, 'plugins/cm-workflow'), marketplace: path.join(home, '.agents/plugins/marketplace.json'), env};
40
+ }
41
+
42
+ function install(env, args) {
43
+ return spawnSync('/bin/bash', [path.join(source, 'install-codex.sh'), ...args],
44
+ {cwd: source, env, encoding: 'utf8', timeout: 240000, maxBuffer: 8 * 1024 * 1024, input: ''});
45
+ }
46
+
47
+ const output = result => result.stdout + result.stderr;
48
+ const lockOf = target => path.join(path.dirname(target), `.${path.basename(target)}.cm-install.lock`);
49
+
50
+ // Run an interactive install, call onPrompt() once the replace prompt is
51
+ // reached, then answer "y" (simulates another session editing meanwhile).
52
+ function installAtPrompt(env, onPrompt) {
53
+ return new Promise((resolve, reject) => {
54
+ const child = spawn('/bin/bash', [path.join(source, 'install-codex.sh')], {cwd: source, env});
55
+ let stdout = '', stderr = '', answered = false;
56
+ const timer = setTimeout(() => child.kill('SIGKILL'), 240000);
57
+ const check = () => {
58
+ if (answered || !/Replace the existing Codex plugin/.test(stdout)) return;
59
+ answered = true;
60
+ onPrompt();
61
+ child.stdin.end('y\n');
62
+ };
63
+ child.stdout.on('data', chunk => { stdout += chunk; check(); });
64
+ child.stderr.on('data', chunk => { stderr += chunk; });
65
+ child.on('error', reject);
66
+ child.on('close', status => { clearTimeout(timer); resolve({status, stdout, stderr, answered}); });
67
+ });
68
+ }
69
+
70
+ test('codex install manifest: first install records hashes, unchanged reinstall passes, --yes cannot overwrite a hand edit, --overwrite-local-edits can',
71
+ {skip: process.platform === 'win32', timeout: 900000}, async t => {
72
+ const {plugin, marketplace, env} = sandbox(t);
73
+ const manifest = path.join(plugin, MANIFEST);
74
+
75
+ const first = install(env, ['--yes']);
76
+ assert.equal(first.status, 0, output(first));
77
+ assert.match(first.stdout, /No previous install manifest found/);
78
+ const lines = fs.readFileSync(manifest, 'utf8').trimEnd().split('\n');
79
+ assert.equal(lines[0], '# cm-workflow install manifest v1');
80
+ const recorded = new Map(lines.slice(1).map(line => [line.slice(66), line.slice(0, 64)]));
81
+ assert.match(recorded.get(EDITED) ?? '', /^[0-9a-f]{64}$/);
82
+ // The cache-version stamp happens before hashing, so the installed manifest is recorded as installed.
83
+ assert.ok(recorded.has('.codex-plugin/plugin.json'));
84
+ assert.equal(recorded.has(MANIFEST), false, 'the manifest must not record itself');
85
+
86
+ const unchanged = install(env, ['--yes']);
87
+ assert.equal(unchanged.status, 0, output(unchanged));
88
+ assert.doesNotMatch(output(unchanged), /changed since the last install/);
89
+
90
+ const edited = path.join(plugin, EDITED);
91
+ const handEdit = fs.readFileSync(edited, 'utf8') + '\n<!-- approved local edit -->\n';
92
+
93
+ // Regression: edited by another session while this one waits at the replace prompt.
94
+ const marketplaceBefore = fs.readFileSync(marketplace, 'utf8');
95
+ const raced = await installAtPrompt(env, () => fs.writeFileSync(edited, handEdit));
96
+ assert.equal(raced.answered, true, output(raced));
97
+ assert.equal(raced.status, 3, output(raced));
98
+ assert.match(raced.stderr, /skills\/cm-check\/SKILL\.md/);
99
+ assert.equal(fs.readFileSync(edited, 'utf8'), handEdit, 'an edit made while waiting at the prompt must survive "y"');
100
+ assert.equal(fs.readFileSync(marketplace, 'utf8'), marketplaceBefore);
101
+ // A file the installer never recorded is not judged.
102
+ fs.writeFileSync(path.join(plugin, 'scripts/my-own-tool.sh'), 'echo mine\n');
103
+
104
+ const refused = install(env, ['--yes']);
105
+ assert.equal(refused.status, 3, output(refused));
106
+ assert.match(refused.stderr, /changed since the last install/);
107
+ assert.match(refused.stderr, /skills\/cm-check\/SKILL\.md/);
108
+ assert.doesNotMatch(refused.stderr, /my-own-tool/);
109
+ assert.equal(fs.readFileSync(edited, 'utf8'), handEdit, 'the hand edit must survive a refused --yes reinstall');
110
+
111
+ const overwritten = install(env, ['--overwrite-local-edits', '--yes']);
112
+ assert.equal(overwritten.status, 0, output(overwritten));
113
+ assert.match(overwritten.stdout, /these edits will be replaced/);
114
+ assert.equal(fs.readFileSync(edited, 'utf8'), fs.readFileSync(path.join(source, EDITED), 'utf8'));
115
+ assert.equal(fs.existsSync(lockOf(plugin)), false,
116
+ 'every finished install releases its lock');
117
+ });
118
+
119
+ test('codex install manifest: a manifest path that is a directory is a corrupt manifest, not a missing one',
120
+ {skip: process.platform === 'win32', timeout: 120000}, t => {
121
+ const {plugin, env} = sandbox(t);
122
+ fs.mkdirSync(path.join(plugin, MANIFEST), {recursive: true});
123
+ fs.mkdirSync(path.join(plugin, 'skills/cm-check'), {recursive: true});
124
+ fs.writeFileSync(path.join(plugin, EDITED), 'hand edit\n');
125
+ const refused = install(env, ['--yes']);
126
+ assert.equal(refused.status, 3, output(refused));
127
+ assert.match(refused.stderr, /Unrecognized install manifest/);
128
+ assert.doesNotMatch(refused.stdout, /No previous install manifest found/);
129
+ assert.equal(fs.readFileSync(path.join(plugin, EDITED), 'utf8'), 'hand edit\n');
130
+ });
131
+
132
+ test('codex install lock: a held lock refuses the install without writing; a stale one is reported, never taken over',
133
+ {skip: process.platform === 'win32', timeout: 120000}, async t => {
134
+ const {plugin, marketplace, env} = sandbox(t);
135
+ const lock = lockOf(plugin);
136
+ fs.mkdirSync(lock, {recursive: true});
137
+ const holder = spawn('/bin/sleep', ['60']);
138
+ t.after(() => holder.kill('SIGKILL'));
139
+ const owner = pid => `pid=${pid}\nstarted=2026-10-20T00:00:00Z\ntarget=${plugin}\n`;
140
+ fs.writeFileSync(path.join(lock, 'owner'), owner(holder.pid));
141
+
142
+ const busy = install(env, ['--yes']);
143
+ assert.equal(busy.status, 4, output(busy));
144
+ assert.match(busy.stderr, /Another CM install is writing the same target/);
145
+ assert.match(busy.stderr, new RegExp(`Holder pid: ${holder.pid}`));
146
+ assert.match(busy.stderr, /still running/);
147
+ assert.equal(fs.existsSync(plugin), false);
148
+ assert.equal(fs.existsSync(marketplace), false);
149
+ assert.equal(fs.readFileSync(path.join(lock, 'owner'), 'utf8'), owner(holder.pid));
150
+
151
+ const exited = new Promise(resolve => holder.on('close', resolve));
152
+ holder.kill('SIGKILL');
153
+ await exited;
154
+ const stale = install(env, ['--yes']);
155
+ assert.equal(stale.status, 4, output(stale));
156
+ assert.match(stale.stderr, /no longer running/);
157
+ assert.ok(stale.stderr.includes(`rm -rf ${lock}`), stale.stderr);
158
+ assert.equal(fs.existsSync(plugin), false);
159
+ assert.equal(fs.readFileSync(path.join(lock, 'owner'), 'utf8'), owner(holder.pid));
160
+ });
161
+
162
+ function writeHook(dir, lines) {
163
+ const hook = path.join(dir, 'hook.sh');
164
+ fs.writeFileSync(hook, ['#!/bin/sh', ...lines, 'exit 0', ''].join('\n'), {mode: 0o755});
165
+ return hook;
166
+ }
167
+
168
+ test('codex fault: a signal between taking the install lock and registering it still releases the lock',
169
+ {skip: process.platform === 'win32', timeout: 120000}, t => {
170
+ const {plugin, marketplace, env} = sandbox(t);
171
+ const hook = writeHook(path.dirname(path.dirname(plugin)), ['[ "$1" = lock-acquired ] || exit 0', 'kill -TERM "$PPID"']);
172
+ const result = install({...env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
173
+ assert.equal(result.status, 143, output(result));
174
+ assert.equal(fs.existsSync(lockOf(plugin)), false);
175
+ assert.equal(fs.existsSync(plugin), false);
176
+ assert.equal(fs.existsSync(marketplace), false);
177
+ });
178
+
179
+ test('codex fault: a signal right after the new plugin is renamed into place restores the previous plugin',
180
+ {skip: process.platform === 'win32', timeout: 600000}, t => {
181
+ const {plugin, marketplace, env} = sandbox(t);
182
+ const first = install(env, ['--yes']);
183
+ assert.equal(first.status, 0, output(first));
184
+ const pluginJson = path.join(plugin, '.codex-plugin/plugin.json');
185
+ const before = {json: fs.readFileSync(pluginJson), manifest: fs.readFileSync(path.join(plugin, MANIFEST)),
186
+ marketplace: fs.readFileSync(marketplace)};
187
+ const hook = writeHook(path.dirname(path.dirname(plugin)), ['[ "$1" = after-stage-moved ] || exit 0', 'kill -TERM "$PPID"']);
188
+ const result = install({...env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
189
+ assert.equal(result.status, 143, output(result));
190
+ assert.deepEqual(fs.readFileSync(pluginJson), before.json, 'the previous plugin (its cache-version stamp) is back');
191
+ assert.deepEqual(fs.readFileSync(path.join(plugin, MANIFEST)), before.manifest);
192
+ assert.deepEqual(fs.readFileSync(marketplace), before.marketplace);
193
+ assert.equal(fs.existsSync(lockOf(plugin)), false);
194
+ assert.deepEqual(fs.readdirSync(path.dirname(plugin)).filter(name => name !== 'cm-workflow'), []);
195
+ });
196
+
197
+ test('codex access: a plugins directory that becomes unsearchable after the rename reports an incomplete rollback and keeps the lock and backup',
198
+ {skip: process.platform === 'win32' || process.getuid?.() === 0, timeout: 600000}, t => {
199
+ const {plugin, marketplace, env} = sandbox(t);
200
+ const first = install(env, ['--yes']);
201
+ assert.equal(first.status, 0, output(first));
202
+ const pluginJson = path.join(plugin, '.codex-plugin/plugin.json');
203
+ const before = {json: fs.readFileSync(pluginJson), marketplace: fs.readFileSync(marketplace)};
204
+ const plugins = path.dirname(plugin);
205
+ t.after(() => { try { fs.chmodSync(plugins, 0o755); } catch {} });
206
+ const hook = writeHook(path.dirname(plugins), ['[ "$1" = after-stage-moved ] || exit 0',
207
+ `chmod 000 '${plugins}'`, 'kill -TERM "$PPID"']);
208
+ const result = install({...env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
209
+ assert.equal(result.status, 143, output(result));
210
+ assert.match(result.stderr, /rollback is incomplete/, 'the skipped restore must be reported');
211
+ assert.match(result.stderr, /plugins directory cannot be accessed/);
212
+ assert.doesNotMatch(result.stderr, /was replaced during the install/, 'unsearchable is not "replaced"');
213
+ fs.chmodSync(plugins, 0o755);
214
+ const lock = lockOf(plugin);
215
+ assert.equal(fs.existsSync(lock), true, 'the lock is left for a person, not removed blind');
216
+ assert.match(result.stderr, new RegExp(path.basename(lock).replace(/\./g, '\\.')));
217
+ const kept = fs.readdirSync(plugins).filter(name => name.startsWith('.cm-workflow.backup.'));
218
+ assert.equal(kept.length, 1, 'the previous plugin must be kept');
219
+ assert.deepEqual(fs.readFileSync(path.join(plugins, kept[0], '.codex-plugin/plugin.json')), before.json);
220
+ assert.match(result.stderr, new RegExp(kept[0].replace(/\./g, '\\.')), 'its location is printed');
221
+ });
222
+
223
+ test('codex path safety: a symlinked marketplace or plugins root is refused before anything is written',
224
+ {skip: process.platform === 'win32', timeout: 120000}, t => {
225
+ const {plugin, marketplace, env} = sandbox(t);
226
+ const home = path.dirname(path.dirname(plugin));
227
+ const outside = path.join(home, 'outside-marketplace.json');
228
+ fs.writeFileSync(outside, '{"name":"someone-else","plugins":[]}\n');
229
+ fs.mkdirSync(path.dirname(marketplace), {recursive: true});
230
+ fs.symlinkSync(outside, marketplace);
231
+ const linkedMarketplace = install(env, ['--yes']);
232
+ assert.equal(linkedMarketplace.status, 2, output(linkedMarketplace));
233
+ assert.match(linkedMarketplace.stderr, /Refusing a symlinked or wrong-type install path/);
234
+ assert.equal(fs.readFileSync(outside, 'utf8'), '{"name":"someone-else","plugins":[]}\n');
235
+ assert.equal(fs.existsSync(plugin), false);
236
+ fs.unlinkSync(marketplace);
237
+
238
+ const realPlugins = path.join(home, 'real-plugins');
239
+ fs.mkdirSync(realPlugins);
240
+ fs.symlinkSync(realPlugins, path.dirname(plugin));
241
+ const linkedRoot = install(env, ['--yes']);
242
+ assert.equal(linkedRoot.status, 2, output(linkedRoot));
243
+ assert.match(linkedRoot.stderr, /Refusing a symlinked install path/);
244
+ assert.deepEqual(fs.readdirSync(realPlugins), []);
245
+ assert.equal(fs.existsSync(marketplace), false);
246
+ });
247
+
248
+ // ---- Fault injection on a copy of one real install --------------------------
249
+ let codexTemplate;
250
+ function installedCodexClone(t) {
251
+ if (!codexTemplate) {
252
+ const home = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cm-codex-install-template-')));
253
+ process.on('exit', () => fs.rmSync(home, {recursive: true, force: true}));
254
+ const box = sandbox({after: () => {}});
255
+ const first = install(box.env, ['--yes']);
256
+ assert.equal(first.status, 0, output(first));
257
+ for (const dir of ['plugins', '.agents']) {
258
+ assert.equal(spawnSync('cp', ['-Rp', path.join(box.home, dir), path.join(home, dir)]).status, 0);
259
+ }
260
+ fs.rmSync(box.home, {recursive: true, force: true});
261
+ codexTemplate = home;
262
+ }
263
+ const box = sandbox(t);
264
+ for (const dir of ['plugins', '.agents']) {
265
+ assert.equal(spawnSync('cp', ['-Rp', path.join(codexTemplate, dir), path.join(box.home, dir)]).status, 0);
266
+ }
267
+ const pluginJson = path.join(box.plugin, '.codex-plugin/plugin.json');
268
+ box.before = {json: fs.readFileSync(pluginJson), manifest: fs.readFileSync(path.join(box.plugin, MANIFEST)),
269
+ marketplace: fs.readFileSync(box.marketplace)};
270
+ box.pluginJson = pluginJson;
271
+ return box;
272
+ }
273
+
274
+ const realTool = name => spawnSync('/bin/sh', ['-c', `command -v ${name}`], {encoding: 'utf8'}).stdout.trim();
275
+ function fakeTool(bin, name, body) {
276
+ fs.writeFileSync(path.join(bin, name), ['#!/bin/sh', ...body, ''].join('\n'), {mode: 0o755});
277
+ }
278
+ const pluginsLeftovers = plugin => fs.readdirSync(path.dirname(plugin)).filter(name => name !== 'cm-workflow');
279
+
280
+ test('codex fault: a rename that completes but is then killed by a group signal still restores the previous plugin',
281
+ {skip: process.platform === 'win32', timeout: 600000}, t => {
282
+ const box = installedCodexClone(t);
283
+ const mv = realTool('mv');
284
+ // Real side effect first, then the signal reaches both the installer and this command.
285
+ fakeTool(box.bin, 'mv', [`${mv} "$@"; rc=$?`,
286
+ 'case "$1" in *"/.cm-workflow.stage."*) kill -TERM "$PPID"; kill -TERM $$ ;; esac', 'exit $rc']);
287
+ const result = install(box.env, ['--yes']);
288
+ assert.equal(result.status, 143, output(result));
289
+ assert.deepEqual(fs.readFileSync(box.pluginJson), box.before.json, 'the previous plugin is back');
290
+ assert.deepEqual(fs.readFileSync(path.join(box.plugin, MANIFEST)), box.before.manifest);
291
+ assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
292
+ assert.equal(fs.existsSync(lockOf(box.plugin)), false);
293
+ assert.deepEqual(pluginsLeftovers(box.plugin), []);
294
+ });
295
+
296
+ test('codex fault: a failing rollback step still restores the marketplace, unlocks and keeps the previous plugin',
297
+ {skip: process.platform === 'win32', timeout: 600000}, t => {
298
+ const box = installedCodexClone(t);
299
+ const mv = realTool('mv');
300
+ fakeTool(box.bin, 'codex', ['exit 17']);
301
+ fakeTool(box.bin, 'mv', ['case "$2" in *"/.cm-workflow.failed."*) exit 1 ;; esac', `exec ${mv} "$@"`]);
302
+ const result = install(box.env, ['--yes']);
303
+ assert.equal(result.status, 17, output(result));
304
+ assert.match(result.stderr, /rollback is incomplete/);
305
+ assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace, 'later restores still run');
306
+ assert.equal(fs.existsSync(lockOf(box.plugin)), false, 'the lock is released even when the rollback is incomplete');
307
+ const kept = pluginsLeftovers(box.plugin).filter(name => name.startsWith('.cm-workflow.backup.'));
308
+ assert.equal(kept.length, 1, 'the previous plugin must be kept');
309
+ assert.deepEqual(fs.readFileSync(path.join(path.dirname(box.plugin), kept[0], '.codex-plugin/plugin.json')), box.before.json);
310
+ assert.match(result.stderr, new RegExp(kept[0].replace(/\./g, '\\.')));
311
+ });
312
+
313
+ test('codex fault: an edit landing right before the old plugin is renamed aside is caught there and the plugin is put back',
314
+ {skip: process.platform === 'win32', timeout: 600000}, t => {
315
+ const box = installedCodexClone(t);
316
+ const edited = path.join(box.plugin, EDITED);
317
+ const handEdit = fs.readFileSync(edited, 'utf8') + '\n<!-- edited during the install -->\n';
318
+ const hook = writeHook(box.home, ['[ "$1" = before-plugin-rename ] || exit 0',
319
+ `printf '\\n<!-- edited during the install -->\\n' >> '${edited}'`]);
320
+ const result = install({...box.env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
321
+ assert.equal(result.status, 3, output(result));
322
+ assert.match(result.stderr, /changed during the install/);
323
+ assert.equal(fs.readFileSync(edited, 'utf8'), handEdit);
324
+ assert.deepEqual(fs.readFileSync(path.join(box.plugin, MANIFEST)), box.before.manifest);
325
+ assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
326
+ assert.equal(fs.existsSync(lockOf(box.plugin)), false);
327
+ assert.deepEqual(pluginsLeftovers(box.plugin), []);
328
+ });
329
+
330
+ test('codex path safety: a marketplace parent swapped for a symlink before the marketplace is written is refused',
331
+ {skip: process.platform === 'win32', timeout: 600000}, t => {
332
+ const box = installedCodexClone(t);
333
+ const elsewhere = path.join(box.home, 'elsewhere');
334
+ fs.mkdirSync(elsewhere);
335
+ fs.writeFileSync(path.join(elsewhere, 'marketplace.json'), '{"name":"someone-else","plugins":[]}\n');
336
+ const parent = path.dirname(box.marketplace);
337
+ const hook = writeHook(box.home, ['[ "$1" = before-marketplace-check ] || exit 0',
338
+ `mv '${parent}' '${parent}.moved'`, `ln -s '${elsewhere}' '${parent}'`]);
339
+ const result = install({...box.env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
340
+ assert.equal(result.status, 2, output(result));
341
+ assert.match(result.stderr, /symlinked or wrong-type install path/);
342
+ assert.equal(fs.readFileSync(path.join(elsewhere, 'marketplace.json'), 'utf8'), '{"name":"someone-else","plugins":[]}\n');
343
+ assert.deepEqual(fs.readFileSync(path.join(`${parent}.moved`, 'marketplace.json')), box.before.marketplace);
344
+ assert.deepEqual(fs.readFileSync(box.pluginJson), box.before.json);
345
+ assert.equal(fs.existsSync(lockOf(box.plugin)), false);
346
+ assert.deepEqual(pluginsLeftovers(box.plugin), []);
347
+ });
348
+
349
+ test('codex fault: a marketplace that became a directory is not "restored" into it; the backup is kept and reported',
350
+ {skip: process.platform === 'win32', timeout: 600000}, t => {
351
+ const box = installedCodexClone(t);
352
+ fakeTool(box.bin, 'codex', [`rm -f '${box.marketplace}'`, `mkdir '${box.marketplace}'`, 'exit 17']);
353
+ const result = install(box.env, ['--yes']);
354
+ assert.equal(result.status, 17, output(result));
355
+ assert.match(result.stderr, /rollback is incomplete/);
356
+ assert.ok(fs.statSync(box.marketplace).isDirectory());
357
+ assert.deepEqual(fs.readdirSync(box.marketplace), [], 'nothing may be copied into the directory');
358
+ const kept = pluginsLeftovers(box.plugin).filter(name => name.startsWith('.cm-workflow.marketplace.backup.'));
359
+ assert.equal(kept.length, 1, 'the marketplace backup must be kept');
360
+ assert.deepEqual(fs.readFileSync(path.join(path.dirname(box.plugin), kept[0])), box.before.marketplace);
361
+ assert.deepEqual(fs.readFileSync(box.pluginJson), box.before.json, 'the previous plugin is still restored');
362
+ assert.equal(fs.existsSync(lockOf(box.plugin)), false);
363
+ });
364
+
365
+ test('codex path safety: a plugins directory replaced by a symlink during the install stops at the next check',
366
+ {skip: process.platform === 'win32', timeout: 600000}, t => {
367
+ const box = installedCodexClone(t);
368
+ const plugins = path.dirname(box.plugin);
369
+ const elsewhere = path.join(box.home, 'elsewhere-plugins');
370
+ fs.mkdirSync(elsewhere);
371
+ const hook = writeHook(box.home, ['[ "$1" = before-marketplace-check ] || exit 0',
372
+ `mv '${plugins}' '${plugins}.moved'`, `ln -s '${elsewhere}' '${plugins}'`]);
373
+ const result = install({...box.env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
374
+ assert.equal(result.status, 2, output(result));
375
+ assert.match(result.stderr, /no longer the one checked at start/);
376
+ assert.match(result.stderr, /lock location cannot be confirmed/);
377
+ assert.deepEqual(fs.readdirSync(elsewhere), [], 'nothing may be written through the replaced directory');
378
+ const moved = path.join(`${plugins}.moved`, 'cm-workflow');
379
+ assert.deepEqual(fs.readFileSync(path.join(moved, '.codex-plugin/plugin.json')), box.before.json);
380
+ assert.deepEqual(fs.readFileSync(path.join(moved, MANIFEST)), box.before.manifest);
381
+ assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
382
+ });
383
+
384
+ test('codex path safety: ~/.agents replaced by a symlink before the marketplace directory is created is refused there',
385
+ {skip: process.platform === 'win32', timeout: 300000}, t => {
386
+ const {home, plugin, env} = sandbox(t);
387
+ const elsewhere = path.join(home, 'elsewhere-agents');
388
+ const hook = writeHook(home, ['[ "$1" = before-marketplace-check ] || exit 0',
389
+ `mkdir '${elsewhere}'`, `ln -s '${elsewhere}' '${path.join(home, '.agents')}'`]);
390
+ const result = install({...env, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
391
+ assert.equal(result.status, 2, output(result));
392
+ assert.match(result.stderr, /symlinked or wrong-type install path/);
393
+ assert.deepEqual(fs.readdirSync(elsewhere), [], 'no directory may be created through the symlink');
394
+ assert.equal(fs.existsSync(plugin), false);
395
+ assert.equal(fs.existsSync(lockOf(plugin)), false);
396
+ });
397
+
398
+ test('codex fault: an unreadable scan file during the last check stops the install instead of reporting no edits',
399
+ {skip: process.platform === 'win32' || process.getuid?.() === 0, timeout: 600000}, t => {
400
+ const box = installedCodexClone(t);
401
+ const tmp = path.join(box.home, 'tmp');
402
+ fs.mkdirSync(tmp);
403
+ const edited = path.join(box.plugin, EDITED);
404
+ const handEdit = fs.readFileSync(edited, 'utf8') + '\n<!-- edited during the install -->\n';
405
+ // Right before the last scan: a hand edit lands, and the scan's own list becomes write-only.
406
+ const hook = writeHook(box.home, ['[ "$1" = before-plugin-rename ] || exit 0',
407
+ `printf '\\n<!-- edited during the install -->\\n' >> '${edited}'`,
408
+ `for work in '${tmp}'/cm-install-guard.*; do : > "$work/recorded-paths"; chmod 0200 "$work/recorded-paths"; done`]);
409
+ const result = install({...box.env, TMPDIR: tmp, CM_INSTALL_TEST_HOOK: hook}, ['--yes']);
410
+ assert.equal(result.status, 2, output(result));
411
+ assert.match(result.stderr, /changed during the install/);
412
+ assert.equal(fs.readFileSync(edited, 'utf8'), handEdit, 'the hand edit must not be replaced');
413
+ assert.deepEqual(fs.readFileSync(path.join(box.plugin, MANIFEST)), box.before.manifest);
414
+ assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
415
+ assert.equal(fs.existsSync(lockOf(box.plugin)), false);
416
+ assert.deepEqual(pluginsLeftovers(box.plugin), []);
417
+ });
418
+
419
+ test('codex access: a hand-edited file under a directory that cannot be searched stops the install',
420
+ {skip: process.platform === 'win32' || process.getuid?.() === 0, timeout: 600000}, t => {
421
+ const box = installedCodexClone(t);
422
+ const edited = path.join(box.plugin, EDITED);
423
+ const handEdit = fs.readFileSync(edited, 'utf8') + '\n<!-- hand edit -->\n';
424
+ fs.writeFileSync(edited, handEdit);
425
+ const hidden = path.dirname(edited);
426
+ fs.chmodSync(hidden, 0o644);
427
+ t.after(() => { if (fs.existsSync(hidden)) fs.chmodSync(hidden, 0o755); });
428
+ const result = install(box.env, ['--yes']);
429
+ fs.chmodSync(hidden, 0o755);
430
+ assert.equal(result.status, 2, output(result));
431
+ assert.equal(fs.readFileSync(edited, 'utf8'), handEdit, 'the hand edit must not be replaced');
432
+ assert.deepEqual(fs.readFileSync(path.join(box.plugin, MANIFEST)), box.before.manifest);
433
+ assert.deepEqual(fs.readFileSync(box.marketplace), box.before.marketplace);
434
+ assert.equal(fs.existsSync(lockOf(box.plugin)), false);
435
+ assert.deepEqual(pluginsLeftovers(box.plugin), []);
436
+ });