@aibyzero/cm-workflow 0.16.4 → 0.16.6

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 (283) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +22 -0
  3. package/CHANGELOG.md +57 -0
  4. package/README.md +22 -4
  5. package/THIRD_PARTY_NOTICES.md +9 -0
  6. package/VERSION +1 -1
  7. package/docs/architecture.md +43 -0
  8. package/docs/execution-optimizations.md +33 -0
  9. package/docs/external-models.md +114 -0
  10. package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
  11. package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
  12. package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
  13. package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
  14. package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
  15. package/docs/human-correction.md +31 -0
  16. package/docs/installation.md +48 -7
  17. package/docs/js-workflow-control.md +293 -33
  18. package/docs/live-evidence-drivers.md +62 -0
  19. package/docs/next-steps.md +15 -10
  20. package/docs/runtime-failover.md +1 -1
  21. package/docs/untested-branches.md +27 -4
  22. package/docs/user-guide.md +23 -8
  23. package/install-codex.sh +28 -11
  24. package/package.json +1 -1
  25. package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
  26. package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
  27. package/runtime/js/cm-ai/claude-review-adapter.mjs +7 -4
  28. package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
  29. package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
  30. package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -41
  31. package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
  32. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +208 -34
  33. package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
  34. package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
  35. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +181 -57
  36. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +15 -58
  37. package/runtime/js/cm-ai/codex-config.mjs +3 -2
  38. package/runtime/js/cm-ai/codex-review-adapter.mjs +56 -17
  39. package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
  40. package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
  41. package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
  42. package/runtime/js/cm-ai/drive-bootstrap.mjs +315 -0
  43. package/runtime/js/cm-ai/drive-core.mjs +47 -9
  44. package/runtime/js/cm-ai/durable-runner-state.mjs +413 -56
  45. package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
  46. package/runtime/js/cm-ai/effect-contract.mjs +44 -2
  47. package/runtime/js/cm-ai/execution-policy.mjs +58 -0
  48. package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
  49. package/runtime/js/cm-ai/execution-store.mjs +6 -4
  50. package/runtime/js/cm-ai/external-group-models.mjs +53 -0
  51. package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
  52. package/runtime/js/cm-ai/external-models.mjs +52 -0
  53. package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
  54. package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
  55. package/runtime/js/cm-ai/host-bootstrap.mjs +126 -29
  56. package/runtime/js/cm-ai/host-check.mjs +30 -4
  57. package/runtime/js/cm-ai/host-conversation-execution.mjs +66 -20
  58. package/runtime/js/cm-ai/host-handoff.mjs +13 -6
  59. package/runtime/js/cm-ai/host-progress.mjs +80 -0
  60. package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
  61. package/runtime/js/cm-ai/host-qa-executor.mjs +23 -9
  62. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +23 -6
  63. package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
  64. package/runtime/js/cm-ai/host-session.mjs +12 -4
  65. package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
  66. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +16 -5
  67. package/runtime/js/cm-ai/host.mjs +1 -1
  68. package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
  69. package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
  70. package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
  71. package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
  72. package/runtime/js/cm-ai/live-evidence.mjs +96 -0
  73. package/runtime/js/cm-ai/log-rows.mjs +21 -0
  74. package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
  75. package/runtime/js/cm-ai/model_configuration_write.py +214 -0
  76. package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
  77. package/runtime/js/cm-ai/operator-guidance.mjs +86 -0
  78. package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
  79. package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
  80. package/runtime/js/cm-ai/provider-review-observation.mjs +68 -9
  81. package/runtime/js/cm-ai/provider-usage.mjs +39 -0
  82. package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
  83. package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
  84. package/runtime/js/cm-ai/review-package.mjs +438 -31
  85. package/runtime/js/cm-ai/review-presentation.mjs +45 -0
  86. package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
  87. package/runtime/js/cm-ai/review-runner.mjs +47 -1
  88. package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
  89. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
  90. package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
  91. package/runtime/js/cm-ai/specification-material.mjs +154 -12
  92. package/runtime/js/cm-ai/status-projection.mjs +93 -0
  93. package/runtime/js/cm-ai/task-commit.mjs +2 -2
  94. package/runtime/js/cm-ai/task-runner.mjs +658 -75
  95. package/runtime/js/cm-ai/tool-preview.mjs +8 -4
  96. package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
  97. package/runtime/js/cm-ai/worker-claude.mjs +63 -19
  98. package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
  99. package/runtime/js/cm-ai/worker-codex.mjs +45 -19
  100. package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
  101. package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
  102. package/runtime/js/cm-fix/cause-package.mjs +10 -1
  103. package/runtime/js/cm-fix/execution.mjs +279 -52
  104. package/runtime/js/cm-fix/final-review.mjs +18 -10
  105. package/runtime/js/cm-fix/host-review.mjs +32 -9
  106. package/runtime/js/cm-fix/host.mjs +6 -1
  107. package/runtime/js/cm-fix/layout.mjs +1 -1
  108. package/runtime/js/cm-fix/progress.mjs +5 -0
  109. package/runtime/js/cm-fix/protected-edits.mjs +15 -4
  110. package/runtime/js/cm-fix/qa-source.mjs +6 -4
  111. package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
  112. package/runtime/js/cm-prd/analysis.mjs +2 -1
  113. package/runtime/js/cm-prd/change.mjs +28 -10
  114. package/runtime/js/cm-prd/draft.mjs +5 -2
  115. package/runtime/js/cm-prd/response-recovery.mjs +23 -0
  116. package/runtime/js/cm-prd/review-preparation.mjs +10 -3
  117. package/runtime/js/cm-prd/review-publication.mjs +27 -15
  118. package/runtime/js/cm-prd/review-time.mjs +29 -0
  119. package/runtime/js/cm-prd/self-check.mjs +6 -3
  120. package/runtime/js/cm-prd/session.mjs +53 -6
  121. package/runtime/js/cm-prd/summary.mjs +3 -1
  122. package/runtime/js/cm-prd/validation-reason.mjs +20 -0
  123. package/runtime/js/cm-security/finalize.mjs +32 -0
  124. package/runtime/js/spec-task-line.mjs +117 -0
  125. package/runtime/js/specs-status.mjs +10 -3
  126. package/runtime/review.md +5 -0
  127. package/runtime/task-gates.md +6 -0
  128. package/runtime/workflow-config.md +10 -1
  129. package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
  130. package/scripts/cm-ai-admission.mjs +18 -11
  131. package/scripts/cm-ai-admission.test.mjs +65 -1
  132. package/scripts/cm-ai-batch-drive.mjs +135 -34
  133. package/scripts/cm-ai-batch-drive.test.mjs +209 -3
  134. package/scripts/cm-ai-batch-host.mjs +63 -24
  135. package/scripts/cm-ai-batch-host.test.mjs +2 -1
  136. package/scripts/cm-ai-batch-run.mjs +101 -34
  137. package/scripts/cm-ai-batch-run.test.mjs +56 -5
  138. package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
  139. package/scripts/cm-ai-bootstrap-flow.test.mjs +159 -0
  140. package/scripts/cm-ai-bootstrap-merge.test.mjs +162 -0
  141. package/scripts/cm-ai-bootstrap.test.mjs +174 -89
  142. package/scripts/cm-ai-conversation-entry-ops.test.mjs +97 -2
  143. package/scripts/cm-ai-develop-driver-gaps.test.mjs +924 -0
  144. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
  145. package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
  146. package/scripts/cm-ai-drive.mjs +526 -60
  147. package/scripts/cm-ai-drive.test.mjs +336 -10
  148. package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
  149. package/scripts/cm-ai-host.mjs +142 -43
  150. package/scripts/cm-ai-host.test.mjs +232 -12
  151. package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
  152. package/scripts/cm-ai-multi-root.test.mjs +9 -3
  153. package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
  154. package/scripts/cm-ai-progress.test.mjs +521 -0
  155. package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
  156. package/scripts/cm-ai-qa-config-revision.test.mjs +187 -15
  157. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
  158. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
  159. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
  160. package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
  161. package/scripts/cm-ai-review-failure.test.mjs +977 -0
  162. package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
  163. package/scripts/cm-ai-review-timeout.test.mjs +199 -4
  164. package/scripts/cm-ai-run.mjs +206 -62
  165. package/scripts/cm-ai-run.test.mjs +6 -4
  166. package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
  167. package/scripts/cm-ai-selection-guard.test.mjs +100 -0
  168. package/scripts/cm-ai-session-chain.test.mjs +7 -3
  169. package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
  170. package/scripts/cm-ai-supersede.test.mjs +571 -17
  171. package/scripts/cm-ai-verification-gate.test.mjs +2 -1
  172. package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
  173. package/scripts/cm-capability-gate.test.mjs +21 -2
  174. package/scripts/cm-check-drive.test.mjs +2 -1
  175. package/scripts/cm-check-host.test.mjs +1 -1
  176. package/scripts/cm-check-runtime.sh +12 -1
  177. package/scripts/cm-claude-developer-worker.test.mjs +3 -1
  178. package/scripts/cm-claude-install-layout.test.mjs +26 -0
  179. package/scripts/cm-claude-probe.test.mjs +10 -2
  180. package/scripts/cm-claude-review-stream.test.mjs +25 -0
  181. package/scripts/cm-claude-worker.test.mjs +11 -4
  182. package/scripts/cm-codex-developer-worker.test.mjs +4 -2
  183. package/scripts/cm-codex-plugin-metadata.py +83 -0
  184. package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
  185. package/scripts/cm-efficiency-checks.test.mjs +37 -0
  186. package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
  187. package/scripts/cm-efficiency-offline.mjs +35 -0
  188. package/scripts/cm-efficiency-policy.test.mjs +48 -0
  189. package/scripts/cm-efficiency-presentation.test.mjs +35 -0
  190. package/scripts/cm-efficiency-response.test.mjs +117 -0
  191. package/scripts/cm-efficiency-usage.test.mjs +148 -0
  192. package/scripts/cm-external-batch-host.test.mjs +157 -0
  193. package/scripts/cm-external-fix-host.test.mjs +281 -0
  194. package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
  195. package/scripts/cm-external-group-models.test.mjs +60 -0
  196. package/scripts/cm-external-model-host.test.mjs +180 -0
  197. package/scripts/cm-external-model-recovery.test.mjs +108 -0
  198. package/scripts/cm-external-models.test.mjs +89 -0
  199. package/scripts/cm-external-process-cleanup.test.mjs +71 -0
  200. package/scripts/cm-external-qa-fix.test.mjs +170 -0
  201. package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
  202. package/scripts/cm-failover.mjs +8 -8
  203. package/scripts/cm-fix-abandon.test.mjs +123 -5
  204. package/scripts/cm-fix-cause-package.test.mjs +2 -0
  205. package/scripts/cm-fix-drive.mjs +70 -23
  206. package/scripts/cm-fix-drive.test.mjs +36 -1
  207. package/scripts/cm-fix-final-review.test.mjs +11 -6
  208. package/scripts/cm-fix-host.mjs +24 -14
  209. package/scripts/cm-fix-protected-edits.test.mjs +12 -0
  210. package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
  211. package/scripts/cm-fix-review-budget.test.mjs +147 -0
  212. package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
  213. package/scripts/cm-host-check.test.mjs +6 -3
  214. package/scripts/cm-host-qa-executor.test.mjs +213 -17
  215. package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
  216. package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
  217. package/scripts/cm-knowledge-closeout.test.mjs +160 -0
  218. package/scripts/cm-live-evidence.test.mjs +64 -0
  219. package/scripts/cm-log-event.mjs +25 -2
  220. package/scripts/cm-log-event.py +15 -0
  221. package/scripts/cm-log-event.test.mjs +31 -0
  222. package/scripts/cm-model-setup.mjs +79 -0
  223. package/scripts/cm-prd-completion.test.mjs +75 -0
  224. package/scripts/cm-prd-draft.test.mjs +14 -0
  225. package/scripts/cm-prd-drive.mjs +32 -11
  226. package/scripts/cm-prd-drive.test.mjs +15 -0
  227. package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
  228. package/scripts/cm-prd-host.mjs +13 -4
  229. package/scripts/cm-prd-review-gate.mjs +126 -81
  230. package/scripts/cm-prd-review-gate.test.mjs +105 -1
  231. package/scripts/cm-prd-review-preparation.test.mjs +15 -0
  232. package/scripts/cm-prd-review-publication.test.mjs +6 -0
  233. package/scripts/cm-prd-self-check.test.mjs +6 -0
  234. package/scripts/cm-prd-summary.test.mjs +9 -0
  235. package/scripts/cm-release-smoke.sh +5 -1
  236. package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
  237. package/scripts/cm-review-inventory.test.mjs +253 -1
  238. package/scripts/cm-runtime-i18n.mjs +15 -4
  239. package/scripts/cm-runtime-install.mjs +8 -4
  240. package/scripts/cm-runtime.mjs +116 -23
  241. package/scripts/cm-runtime.test.mjs +121 -12
  242. package/scripts/cm-security.test.mjs +32 -0
  243. package/scripts/cm-spec-manifest.mjs +28 -10
  244. package/scripts/cm-spec-manifest.test.mjs +8 -4
  245. package/scripts/cm-spec-task-line.test.mjs +138 -0
  246. package/scripts/cm-specs-status.test.mjs +12 -1
  247. package/scripts/cm-task-gate-correction.test.mjs +117 -0
  248. package/scripts/cm-task-gate.mjs +164 -20
  249. package/scripts/cm-task-gate.py +2 -1
  250. package/scripts/cm-test-branch-impact.test.mjs +6 -3
  251. package/scripts/cm-test-drive.mjs +10 -4
  252. package/scripts/cm-test-drive.test.mjs +14 -1
  253. package/scripts/cm-tool-preview-context.test.mjs +12 -0
  254. package/scripts/cm-usage-report.py +22 -3
  255. package/scripts/cm-workflow-config.mjs +10 -1
  256. package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
  257. package/scripts/fixtures/claude-review-process.mjs +1 -0
  258. package/scripts/fixtures/live-evidence-driver.mjs +35 -0
  259. package/scripts/fixtures/process-cleanup.mjs +101 -0
  260. package/scripts/test-cm-log-event.py +2 -0
  261. package/scripts/test-cm-native-usage.py +62 -0
  262. package/scripts/test-cm-prd-review-gate.py +2 -1
  263. package/scripts/test-external-model-setup.py +91 -0
  264. package/scripts/test-model-configuration-write.py +201 -0
  265. package/scripts/test-npm-install.py +11 -2
  266. package/scripts/test-scan-public-safety.py +1 -1
  267. package/scripts/test-spec-manifest.py +16 -8
  268. package/scripts/test-task-gate.py +2 -2
  269. package/scripts/test-workflow-config.py +1 -0
  270. package/scripts/validate-public-repo.py +1 -0
  271. package/skills/cm-ai/SKILL.md +2 -2
  272. package/skills/cm-ai/references/N1-init.md +1 -1
  273. package/skills/cm-ai/references/N8-finish.md +5 -0
  274. package/skills/cm-ai/references/js-host.md +270 -43
  275. package/skills/cm-ai/references/knowledge-closeout.md +90 -0
  276. package/skills/cm-fix/SKILL.md +1 -1
  277. package/skills/cm-fix/references/js-host.md +52 -3
  278. package/skills/cm-prd/references/js-change-recovery.md +1 -1
  279. package/skills/cm-prd/references/js-host.md +6 -0
  280. package/skills/cm-runtime/SKILL.md +29 -6
  281. package/skills/cm-security/SKILL.md +4 -2
  282. package/skills/cm-security/references/scan-contract.md +1 -0
  283. package/templates/cm-workflow.yml +1 -1
@@ -0,0 +1,91 @@
1
+ """Real terminal setup: no installed providers, network, auth, or model calls."""
2
+ import json
3
+ import os
4
+ from pathlib import Path
5
+ import pty
6
+ import select
7
+ import shutil
8
+ import subprocess
9
+ import tempfile
10
+ import time
11
+ import unittest
12
+
13
+ SCRIPT = Path(__file__).resolve().with_name('cm-model-setup.mjs')
14
+ NODE = shutil.which('node')
15
+
16
+
17
+ class TerminalSetup(unittest.TestCase):
18
+ def setUp(self):
19
+ self.temp = tempfile.TemporaryDirectory(prefix='cm-external-terminal-')
20
+ self.addCleanup(self.temp.cleanup)
21
+ self.root = Path(self.temp.name).resolve()
22
+ self.settings = self.root / 'external-models-v1.json'
23
+
24
+ def interact(self, arguments, steps):
25
+ master, slave = pty.openpty()
26
+ process = subprocess.Popen([NODE, str(SCRIPT)] + arguments,
27
+ stdin=slave, stdout=slave, stderr=slave,
28
+ env=dict(os.environ, CM_WORKFLOW_HOME=str(self.root)))
29
+ os.close(slave)
30
+ output = b''
31
+ try:
32
+ for prompt, answer, before in steps:
33
+ deadline = time.monotonic() + 5
34
+ while prompt.encode() not in output:
35
+ if time.monotonic() > deadline:
36
+ self.fail('missing prompt: ' + prompt + '\n' + output.decode(errors='replace'))
37
+ if select.select([master], [], [], 0.1)[0]:
38
+ output += os.read(master, 65536)
39
+ if before:
40
+ before()
41
+ os.write(master, answer.encode() + b'\r')
42
+ output = b''
43
+ # Drain the terminal while waiting: TTY writes can block without a reader.
44
+ deadline = time.monotonic() + 5
45
+ while process.poll() is None and time.monotonic() < deadline:
46
+ if select.select([master], [], [], 0.1)[0]:
47
+ try:
48
+ output += os.read(master, 65536)
49
+ except OSError:
50
+ break
51
+ return process.wait(timeout=1)
52
+ finally:
53
+ if process.poll() is None:
54
+ process.kill()
55
+ process.wait(timeout=5)
56
+ os.close(master)
57
+
58
+ def test_codex_free_model_and_default_effort(self):
59
+ status = self.interact(['configure', '--provider', 'codex'], [
60
+ ('codex external model ID:', 'fixture-codex', None),
61
+ ('Effort (Enter = adapter default):', '', None),
62
+ ('Save this provider pair?', 'y', None)])
63
+ self.assertEqual(status, 0)
64
+ self.assertEqual(json.loads(self.settings.read_text())['providers']['codex'],
65
+ dict(model='fixture-codex', effort='high'))
66
+
67
+ def test_claude_optional_effort_is_not_sent(self):
68
+ status = self.interact(['configure', '--provider', 'claude'], [
69
+ ('claude external model ID:', 'fixture-claude', None),
70
+ ('Effort (Enter = adapter default):', '', None),
71
+ ('Save this provider pair?', 'yes', None)])
72
+ self.assertEqual(status, 0)
73
+ self.assertIsNone(json.loads(self.settings.read_text())['providers']['claude']['effort'])
74
+
75
+ def test_cancel_keeps_absent_file(self):
76
+ self.assertEqual(self.interact(['configure', '--provider', 'codex', '--model', 'fixture'],
77
+ [('Save this provider pair?', 'n', None)]), 0)
78
+ self.assertFalse(self.settings.exists())
79
+
80
+ def test_confirmation_cannot_overwrite_concurrent_bytes(self):
81
+ old = dict(schemaVersion=1, providers=dict(codex=dict(model='old', effort='high')))
82
+ self.settings.write_text(json.dumps(old))
83
+ changed = json.dumps(old, indent=4).encode()
84
+ status = self.interact(['configure', '--provider', 'codex', '--model', 'new'],
85
+ [('Save this provider pair?', 'y', lambda: self.settings.write_bytes(changed))])
86
+ self.assertEqual(status, 1)
87
+ self.assertEqual(self.settings.read_bytes(), changed)
88
+
89
+
90
+ if __name__ == '__main__':
91
+ unittest.main()
@@ -0,0 +1,201 @@
1
+ """Synthetic publication interleavings; no provider/global configuration access."""
2
+ import base64
3
+ import errno
4
+ import fcntl
5
+ import hashlib
6
+ import importlib.util
7
+ import json
8
+ import os
9
+ from pathlib import Path
10
+ import stat
11
+ import subprocess
12
+ import sys
13
+ import tempfile
14
+ import unittest
15
+ from unittest.mock import patch
16
+
17
+ HELPER = Path(__file__).resolve().parents[1] / 'runtime/js/cm-ai/model_configuration_write.py'
18
+ spec = importlib.util.spec_from_file_location('publisher', HELPER)
19
+ publisher = importlib.util.module_from_spec(spec)
20
+ spec.loader.exec_module(publisher)
21
+
22
+
23
+ class Publication(unittest.TestCase):
24
+ def setUp(self):
25
+ self.temp = tempfile.TemporaryDirectory(prefix='cm-publisher-')
26
+ self.addCleanup(self.temp.cleanup)
27
+ self.root = Path(self.temp.name).resolve()
28
+ self.target = self.root / 'choice.json'
29
+
30
+ def request(self, content=b'{"new":true}\n', existing=b'{"old":true}\n', target=None):
31
+ target = target or self.target
32
+ if existing is not None:
33
+ target.write_bytes(existing)
34
+ return dict(target=str(target), bytes=base64.b64encode(content).decode(),
35
+ expectedSha256=None if existing is None else hashlib.sha256(existing).hexdigest(),
36
+ replace=True, createParents=False, sourceGuard=None)
37
+
38
+ def run_helper(self, request):
39
+ result = subprocess.run([sys.executable, '-I', '-B', str(HELPER)], input=json.dumps(request),
40
+ text=True, capture_output=True, timeout=5)
41
+ return json.loads(result.stdout)
42
+
43
+ def test_first_publication_collision(self):
44
+ request = self.request(existing=None)
45
+ original = os.link
46
+ def collide(source, destination, **kwargs):
47
+ self.target.write_bytes(b'concurrent original')
48
+ original(source, destination, **kwargs)
49
+ with patch.object(os, 'link', collide), self.assertRaisesRegex(publisher.Refusal, 'model_configuration_changed'):
50
+ publisher.publish(request)
51
+ self.assertEqual(self.target.read_bytes(), b'concurrent original')
52
+ self.assertEqual(set(os.listdir(self.root)), {'choice.json', publisher.LOCK})
53
+
54
+ def test_pre_replace_failure(self):
55
+ request = self.request()
56
+ with patch.object(os, 'replace', side_effect=OSError(errno.EIO, 'fixture')), self.assertRaises(OSError):
57
+ publisher.publish(request)
58
+ self.assertEqual(self.target.read_bytes(), b'{"old":true}\n')
59
+ self.assertEqual(set(os.listdir(self.root)), {'choice.json', publisher.LOCK})
60
+
61
+ def test_post_publication_failure_is_unknown(self):
62
+ for existing in (None, b'{"old":true}\n'):
63
+ self.target.unlink(missing_ok=True)
64
+ request = self.request(existing=existing)
65
+ original = os.fsync
66
+ def fail_directory(fd):
67
+ if stat.S_ISDIR(os.fstat(fd).st_mode):
68
+ raise OSError(errno.EIO, 'fixture')
69
+ return original(fd)
70
+ with patch.object(os, 'fsync', fail_directory), self.assertRaisesRegex(publisher.Refusal, 'model_configuration_write_unknown'):
71
+ publisher.publish(request)
72
+ self.assertEqual(self.target.read_bytes(), b'{"new":true}\n')
73
+
74
+ def test_two_processes_same_byte_snapshot_one_winner(self):
75
+ request = self.request()
76
+ processes = [subprocess.Popen([sys.executable, '-I', '-B', str(HELPER)], stdin=subprocess.PIPE,
77
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) for _ in range(2)]
78
+ for child in processes:
79
+ child.stdin.write(json.dumps(request)); child.stdin.close(); child.stdin = None
80
+ results = [json.loads(child.communicate(timeout=5)[0]) for child in processes]
81
+ self.assertEqual(sum(result['ok'] for result in results), 1)
82
+ failure = next(result for result in results if not result['ok'])
83
+ self.assertIn(failure['code'], ('model_configuration_busy', 'model_configuration_changed'))
84
+ self.assertEqual(self.target.read_bytes(), b'{"new":true}\n')
85
+ self.assertEqual(self.run_helper(request)['code'], 'model_configuration_changed')
86
+
87
+ def test_repeated_temporary_unlink_failure_after_link_is_unknown(self):
88
+ request = self.request(existing=None)
89
+ with patch.object(os, 'unlink', side_effect=OSError(errno.EIO, 'fixture')):
90
+ with self.assertRaisesRegex(publisher.Refusal, 'model_configuration_write_unknown'):
91
+ publisher.publish(request)
92
+ self.assertEqual(self.target.read_bytes(), b'{"new":true}\n')
93
+
94
+ def test_lock_close_failure_after_publication_is_unknown(self):
95
+ request = self.request(existing=None)
96
+ original = os.close
97
+ def close(fd):
98
+ info = os.fstat(fd)
99
+ is_lock = (self.root / publisher.LOCK).exists() and info.st_ino == (self.root / publisher.LOCK).stat().st_ino
100
+ original(fd)
101
+ if is_lock and self.target.exists():
102
+ raise OSError(errno.EIO, 'fixture')
103
+ with patch.object(os, 'close', close):
104
+ with self.assertRaisesRegex(publisher.Refusal, 'model_configuration_write_unknown'):
105
+ publisher.publish(request)
106
+ self.assertEqual(self.target.read_bytes(), b'{"new":true}\n')
107
+
108
+ def test_second_writer_at_replace_cannot_enter(self):
109
+ request = self.request()
110
+ original = os.replace
111
+ def interleave(source, destination, **kwargs):
112
+ self.assertEqual(self.run_helper(request)['code'], 'model_configuration_busy')
113
+ return original(source, destination, **kwargs)
114
+ with patch.object(os, 'replace', interleave):
115
+ publisher.publish(request)
116
+ inode = (self.root / publisher.LOCK).stat().st_ino
117
+ publisher.publish(self.request(existing=self.target.read_bytes()))
118
+ self.assertEqual((self.root / publisher.LOCK).stat().st_ino, inode)
119
+
120
+ def test_ancestor_swap_never_redirects_into_run_evidence(self):
121
+ for move_temporary in (False, True):
122
+ with self.subTest(move_temporary=move_temporary), tempfile.TemporaryDirectory(dir=self.root) as temp:
123
+ root = Path(temp); safe = root / 'safe'; safe.mkdir()
124
+ evidence = root / '.reviews'; evidence.mkdir()
125
+ target = safe / 'choice.json'; request = self.request(target=target)
126
+ original = os.replace
127
+ def swap(source, destination, **kwargs):
128
+ os.rename(safe, root / 'old-safe')
129
+ if move_temporary:
130
+ os.rename(root / 'old-safe' / source, evidence / source)
131
+ safe.symlink_to(evidence, target_is_directory=True)
132
+ return original(source, destination, **kwargs)
133
+ with patch.object(os, 'replace', swap):
134
+ if move_temporary:
135
+ with self.assertRaises(FileNotFoundError): publisher.publish(request)
136
+ else:
137
+ with self.assertRaisesRegex(publisher.Refusal, 'model_configuration_write_unknown'):
138
+ publisher.publish(request)
139
+ self.assertEqual((root / 'old-safe' / 'choice.json').read_bytes(), b'{"new":true}\n')
140
+ self.assertFalse((evidence / 'choice.json').exists())
141
+ # Moving the pinned directory itself is deliberately outside the same-UID trust boundary.
142
+
143
+ def test_legacy_source_guard_rejects_changed_bytes(self):
144
+ source = self.root / 'v1.json'; source.write_bytes(b'{}\n')
145
+ request = self.request(existing=None)
146
+ request['sourceGuard'] = dict(file=str(source), sha256=hashlib.sha256(source.read_bytes()).hexdigest())
147
+ source.write_bytes(b'{ }\n')
148
+ with self.assertRaisesRegex(publisher.Refusal, 'model_configuration_changed'): publisher.publish(request)
149
+ self.assertFalse(self.target.exists()); self.assertEqual(source.read_bytes(), b'{ }\n')
150
+
151
+ def test_initial_bytes_not_just_semantics(self):
152
+ request = self.request(existing=b'{"old":true}\n')
153
+ self.target.write_bytes(b'{ "old": true }\n')
154
+ with self.assertRaisesRegex(publisher.Refusal, 'model_configuration_changed'): publisher.publish(request)
155
+ self.assertEqual(self.target.read_bytes(), b'{ "old": true }\n')
156
+
157
+ def test_forbidden_names_have_no_side_effects(self):
158
+ for target in (self.root / '.REVIEWS' / 'x.json', self.root / '.CM-MODEL-CONFIG.LOCK',
159
+ self.root / '.cm-model-snapshot-v1.json'):
160
+ request = self.request(existing=None, target=target); request['createParents'] = True
161
+ with self.assertRaisesRegex(publisher.Refusal, 'model_output_run_path_forbidden'): publisher.publish(request)
162
+ self.assertEqual(os.listdir(self.root), [])
163
+
164
+ def test_symlink_parent_is_not_followed(self):
165
+ outside = self.root / 'outside'; outside.mkdir(); alias = self.root / 'alias'; alias.symlink_to(outside)
166
+ request = self.request(existing=None, target=alias / 'nested' / 'x.json'); request['createParents'] = True
167
+ with self.assertRaises(OSError): publisher.publish(request)
168
+ self.assertEqual(os.listdir(outside), [])
169
+
170
+ def test_lock_symlink_and_hardlink_refused(self):
171
+ request = self.request(); lock = self.root / publisher.LOCK
172
+ lock.symlink_to(self.target)
173
+ with self.assertRaises(OSError): publisher.publish(request)
174
+ lock.unlink(); os.link(self.target, lock)
175
+ with self.assertRaisesRegex(publisher.Refusal, 'invalid_model_configuration_lock'): publisher.publish(request)
176
+ self.assertEqual(self.target.read_bytes(), b'{"old":true}\n')
177
+
178
+ def test_group_writable_parent_refused(self):
179
+ request = self.request(existing=None); self.root.chmod(0o770)
180
+ with self.assertRaisesRegex(publisher.Refusal, 'model_configuration_untrusted_directory'): publisher.publish(request)
181
+ self.root.chmod(0o700); self.assertEqual(os.listdir(self.root), [])
182
+
183
+ def test_unsupported_platform_refuses_before_mkdir(self):
184
+ request = self.request(existing=None, target=self.root / 'new' / 'choice.json'); request['createParents'] = True
185
+ with patch.object(publisher, 'SECURE_PLATFORM', False), self.assertRaisesRegex(publisher.Refusal, 'model_secure_write_unavailable'):
186
+ publisher.publish(request)
187
+ self.assertEqual(os.listdir(self.root), [])
188
+
189
+ def test_fifo_target_refused_without_blocking(self):
190
+ request = self.request(existing=None); os.mkfifo(self.target)
191
+ self.assertEqual(self.run_helper(request)['code'], 'invalid_model_configuration_file')
192
+
193
+ def test_valid_publication_creates_private_parents(self):
194
+ request = self.request(existing=None, target=self.root / 'nested' / 'choice.json'); request['createParents'] = True
195
+ self.assertTrue(self.run_helper(request)['ok'])
196
+ self.assertEqual(stat.S_IMODE((self.root / 'nested').stat().st_mode), 0o700)
197
+ self.assertEqual(stat.S_IMODE((self.root / 'nested' / 'choice.json').stat().st_mode), 0o600)
198
+
199
+
200
+ if __name__ == '__main__':
201
+ unittest.main()
@@ -19,7 +19,7 @@ ROOT = Path(__file__).resolve().parent.parent
19
19
 
20
20
 
21
21
  def run(args, *, cwd=ROOT, env=None, expected=0, input=None):
22
- result = subprocess.run(args, cwd=cwd, env=env, input=input, text=True,
22
+ result = subprocess.run(args, cwd=cwd, env=env, input=input, text=True, encoding="utf-8",
23
23
  stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
24
24
  if result.returncode != expected:
25
25
  raise AssertionError(f"{args[0]} exited {result.returncode}, expected {expected}\n{result.stdout}")
@@ -52,6 +52,8 @@ def relocated(source, home, helpers):
52
52
  def main():
53
53
  assert sys.platform == 'darwin', 'This integration fixture requires macOS'
54
54
  helpers = Path(os.environ.get('CODEX_HOME', str(Path.home() / '.codex'))) / 'skills/.system/plugin-creator'
55
+ if not (helpers / 'scripts/create_basic_plugin.py').is_file():
56
+ helpers = Path(os.environ.get('CODEX_HOME', str(Path.home() / '.codex'))) / '.tmp/plugins/.agents/skills/plugin-creator'
55
57
  assert (helpers / 'scripts/create_basic_plugin.py').is_file(), 'Codex bundled helpers required'
56
58
  with tempfile.TemporaryDirectory(prefix='cm-npm-fixture-') as folder:
57
59
  temp = Path(folder).resolve()
@@ -129,10 +131,17 @@ process.exitCode=main(args,{run:(command,argv,options)=>{
129
131
  print('PASS: tarball contents, offline npm CLI and fresh file installation', flush=True)
130
132
 
131
133
  upgrade = temp / 'existing user'
132
- install(source, upgrade, npm=False)
134
+ # Seed predecessor files, without claiming its now-incompatible installer
135
+ # works with the current minimal official creator. New installer transaction
136
+ # code is exercised below for decline, rollback and successful upgrade.
133
137
  dest = upgrade / 'plugins/cm-workflow'
138
+ shutil.copytree(source, dest)
134
139
  marketplace = upgrade / '.agents/plugins/marketplace.json'
140
+ run([sys.executable, str(helpers / 'scripts/create_basic_plugin.py'), 'cm-workflow',
141
+ '--path', str(temp / 'predecessor scaffold'), '--with-skills', '--with-marketplace',
142
+ '--marketplace-path', str(marketplace), '--force'])
135
143
  payload = json.loads(marketplace.read_text())
144
+ payload['name'] = 'fixture-personal'
136
145
  sibling = {**payload['plugins'][0], 'name': 'unrelated-plugin'}
137
146
  payload['plugins'].append(sibling)
138
147
  marketplace.write_text(json.dumps(payload))
@@ -38,7 +38,7 @@ class PublicSafetyTests(unittest.TestCase):
38
38
  )
39
39
  return subprocess.run(
40
40
  [sys.executable, str(script)], cwd=root,
41
- capture_output=True, text=True, check=False,
41
+ capture_output=True, text=True, encoding="utf-8", check=False,
42
42
  )
43
43
 
44
44
  def test_reviewed_loopback_literals_and_local_port_templates(self):
@@ -16,11 +16,12 @@ ROOT = Path(__file__).resolve().parents[1]
16
16
  SCRIPT = ROOT / "scripts" / "cm-spec-manifest.py"
17
17
 
18
18
 
19
- def invoke(*args: str, expected_exit: int = 0) -> subprocess.CompletedProcess[str]:
19
+ def invoke(*args: str, expected_exit: int = 0, oracle_exit: int | None = None) -> subprocess.CompletedProcess[str]:
20
20
  result = subprocess.run(
21
21
  [sys.executable, str(SCRIPT), *args],
22
22
  cwd=ROOT,
23
23
  text=True,
24
+ encoding="utf-8",
24
25
  capture_output=True,
25
26
  check=False,
26
27
  )
@@ -28,15 +29,18 @@ def invoke(*args: str, expected_exit: int = 0) -> subprocess.CompletedProcess[st
28
29
  # not against two entrypoints which now execute the same implementation.
29
30
  oracle = subprocess.run(
30
31
  [sys.executable, str(ROOT / "scripts" / "fixtures" / "spec-manifest-python-oracle.py"), *args],
31
- cwd=ROOT, text=True, capture_output=True, check=False,
32
+ cwd=ROOT, text=True, encoding="utf-8", capture_output=True, check=False,
32
33
  )
33
34
  javascript = subprocess.run(
34
35
  [os.environ.get("CM_NODE_BIN", "node"), str(ROOT / "scripts" / "cm-spec-manifest.mjs"), *args],
35
- cwd=ROOT, text=True, capture_output=True, check=False,
36
+ cwd=ROOT, text=True, encoding="utf-8", capture_output=True, check=False,
36
37
  )
37
- if javascript.returncode != result.returncode or oracle.returncode != result.returncode:
38
+ # oracle_exit marks a deliberate post-migration grammar change: the frozen
39
+ # oracle keeps its old answer and must not be compared byte for byte.
40
+ expected_oracle = result.returncode if oracle_exit is None else oracle_exit
41
+ if javascript.returncode != result.returncode or oracle.returncode != expected_oracle:
38
42
  raise AssertionError(f"JS/Python exit mismatch: {javascript.stderr} / {result.stderr}")
39
- if result.returncode == 0 and not (
43
+ if result.returncode == 0 and oracle_exit is None and not (
40
44
  json.loads(javascript.stdout) == json.loads(result.stdout) == json.loads(oracle.stdout)
41
45
  ):
42
46
  raise AssertionError("JS/Python semantic manifest mismatch")
@@ -176,13 +180,17 @@ def main() -> int:
176
180
  ),
177
181
  encoding="utf-8",
178
182
  )
179
- indented_example = invoke(
183
+ # The shared tasks.md grammar (runtime/js/spec-task-line.mjs) reads an
184
+ # indented task line as a declaration, exactly as admission and N5 do,
185
+ # so its checkbox is runtime state. The frozen oracle still mismatches.
186
+ indented_task = invoke(
180
187
  str(specs),
181
188
  "--status-file",
182
189
  str(status),
183
- expected_exit=1,
190
+ expected_exit=0,
191
+ oracle_exit=1,
184
192
  )
185
- assert "approved spec manifest does not match" in indented_example.stderr
193
+ assert json.loads(indented_task.stdout)["status"] == "matched"
186
194
 
187
195
  (feature / "tasks.md").write_text(tasks_completed, encoding="utf-8")
188
196
 
@@ -29,10 +29,10 @@ def main() -> int:
29
29
 
30
30
  arguments = ["check-n4", "--help"]
31
31
  direct = subprocess.run(
32
- ["node", str(JS_GATE), *arguments], text=True, capture_output=True, check=False
32
+ ["node", str(JS_GATE), *arguments], text=True, encoding="utf-8", capture_output=True, check=False
33
33
  )
34
34
  compatibility = subprocess.run(
35
- [sys.executable, str(PYTHON_GATE), *arguments], text=True, capture_output=True, check=False
35
+ [sys.executable, str(PYTHON_GATE), *arguments], text=True, encoding="utf-8", capture_output=True, check=False
36
36
  )
37
37
  assert compatibility.returncode == direct.returncode
38
38
  assert compatibility.stdout == direct.stdout
@@ -16,6 +16,7 @@ def main() -> int:
16
16
  check=False,
17
17
  capture_output=True,
18
18
  text=True,
19
+ encoding="utf-8",
19
20
  env={**os.environ, "CM_PYTHON_BIN": sys.executable},
20
21
  )
21
22
  if result.returncode != 0:
@@ -34,6 +34,7 @@ CM_AI_RUNTIME = (
34
34
  "codex-review-adapter.mjs",
35
35
  "contracts.mjs",
36
36
  "durable-runner-state.mjs",
37
+ "diagnostic-reason.mjs",
37
38
  "effect-contract.mjs",
38
39
  "execution-store.mjs",
39
40
  "gate-bridge.mjs",
@@ -54,7 +54,7 @@ START
54
54
  ┌─► [N2: 进入 Feature] ── 读取 specs、分析依赖、输出执行计划
55
55
  │ │
56
56
  │ ▼
57
- │ ┌─► [N3: 执行 Task] ── 检查 skill → 开发
57
+ │ ┌─► [N3: 执行 Task] ── 开发 → 末任务文档同步 → Learning/handoff 定稿
58
58
  │ │ │
59
59
  │ │ ▼
60
60
  │ │ [N4: Review] ── 主执行者自审 → 独立审查
@@ -82,7 +82,7 @@ START
82
82
  │ NO
83
83
  │ │
84
84
  │ ▼
85
- [N8: 完成] ── 调用 cm-doc-syncer → 输出总结
85
+ [N8: 完成] ── 只读文档/收尾核对 → 原完成门禁 → 输出总结
86
86
  │
87
87
  ▼
88
88
  END
@@ -44,7 +44,7 @@
44
44
  以 JS admission 的结果为准;模型不得自行拼写或修改 `.cm-specs-status`:
45
45
 
46
46
  - `ready` / `complete` → 沿用现有准入结果;旧版无 `specFiles` 的文件仍可读取,不在本节点自行补造批准证据。
47
- - `awaiting_spec_approval` → 展示规格摘要卡(无卡时可现场汇总,但不得据此生成或替换 `summaryDigest`),等用户明确回复“开始”。泛化授权语(“继续”“按最优解处理”“你看着办”)不构成审批,须回问“规格摘要卡确认开始吗?”(实跑失守:泛化授权曾被误视为审批通过)。
47
+ - `awaiting_spec_approval` → 展示规格摘要卡(无卡时可现场汇总,但不得据此生成或替换 `summaryDigest`),请用户明确回复“开始”。JS 仅接受“开始”“开始吧”“可以开始”“确认开始”“开始执行”“现在开始”,可带尾部中英文句末标点和空白;泛化授权语(“继续”“可以”“好”“好的”“OK”“按最优解处理”“你看着办”“行”)仍不构成审批,未命中时明确提示回复“开始”(实跑失守:泛化授权曾被误视为审批通过)。
48
48
  - 取得明确回复后运行以下写入口,`--approval-response` 传用户原话;多个代码项目全部传入:
49
49
 
50
50
  ```bash
@@ -2,6 +2,10 @@
2
2
 
3
3
  所有 feature 的所有任务完成后:
4
4
 
5
+ 具备 `documentation_inspect` 的新 JS run 按创建时快照默认执行一次
6
+ [收尾资料核对](knowledge-closeout.md),与下文原检查共用请求;旧 run 不自动开启。
7
+ 用户要求关闭时仅在创建前设 `knowledgeCloseout:false`;不能改变已有快照或跳过必需资料。
8
+
5
9
  ## 1. 核验文档同步
6
10
 
7
11
  项目文档已在最后任务的 N3、定稿 handoff 和 N4 Review 前通过 `cm-doc-syncer`
@@ -97,6 +101,7 @@ staging/体验版验证。
97
101
  📂 Features: {完成数}/{总数}
98
102
  📋 总任务: {完成数}/{总数}
99
103
  📝 文档同步: 已完成
104
+ 🔎 收尾核对: {按原结果附六行报告,或未完成原因/已关闭;不能据此代替 Review/QA}
100
105
  🚀 生产发布待决清单: 已编制,等待人工决策
101
106
 
102
107
  各 Feature 摘要: