@aibyzero/cm-workflow 0.16.3 → 0.16.5
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.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +8 -0
- package/CHANGELOG.md +59 -0
- package/README.md +55 -3
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- package/docs/next-steps.md +14 -24
- package/docs/runtime-failover.md +1 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +30 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +116 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +180 -53
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +305 -0
- package/runtime/js/cm-ai/drive-core.mjs +39 -7
- package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
- package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +20 -5
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +427 -31
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +502 -65
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-fix/execution.mjs +109 -25
- package/runtime/js/cm-fix/host-review.mjs +7 -3
- package/runtime/js/cm-fix/host.mjs +3 -1
- package/runtime/js/cm-fix/progress.mjs +1 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/summary.mjs +6 -2
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +14 -3
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +19 -10
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +93 -21
- package/scripts/cm-ai-batch-drive.test.mjs +171 -3
- package/scripts/cm-ai-batch-host.mjs +37 -13
- package/scripts/cm-ai-batch-host.test.mjs +26 -0
- package/scripts/cm-ai-batch-run.mjs +33 -10
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +158 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap.test.mjs +99 -7
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +480 -47
- package/scripts/cm-ai-drive.test.mjs +247 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +89 -25
- package/scripts/cm-ai-host.test.mjs +274 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +166 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +917 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +160 -60
- package/scripts/cm-ai-run.test.mjs +4 -3
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.mjs +4 -3
- package/scripts/cm-check-drive.test.mjs +17 -1
- package/scripts/cm-check-entry.mjs +13 -2
- package/scripts/cm-check-host.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +57 -1
- package/scripts/cm-check-runtime.sh +16 -7
- package/scripts/cm-claude-developer-worker.test.mjs +43 -2
- package/scripts/cm-claude-probe.test.mjs +9 -1
- package/scripts/cm-claude-review-stream.test.mjs +68 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +45 -13
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-host.mjs +9 -6
- package/scripts/cm-fix-review-budget.test.mjs +141 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +192 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-log-event.mjs +17 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-prd-completion.test.mjs +105 -2
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +13 -7
- package/scripts/cm-prd-drive.test.mjs +10 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +40 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +31 -1
- package/scripts/cm-task-gate.mjs +18 -10
- package/scripts/cm-task-gate.py +1 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/process-cleanup.mjs +99 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-npm-install.py +1 -1
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-shell-compat.sh +67 -0
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +264 -40
- package/skills/cm-check/SKILL.md +6 -1
- package/skills/cm-check/references/js-host.md +3 -3
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +30 -0
- package/skills/cm-prd/references/js-host.md +6 -0
package/docs/next-steps.md
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
# 接下来要做的事
|
|
2
2
|
|
|
3
|
-
写于 2026-09-22,0.16.
|
|
3
|
+
写于 2026-09-22,2026-09-26 在 0.16.3 发布后更新。按优先级排,每条写清:为什么要做、做完是什么样、动手前要先弄清什么。
|
|
4
4
|
|
|
5
5
|
## 现状
|
|
6
6
|
|
|
7
|
-
- npm 上是 **0.16.
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- #117 整理后续工作文档
|
|
13
|
-
- #118 + #120 cm-fix 在签授权前记下每个接手会话,并修好交叉审查发现的两处缺陷
|
|
14
|
-
- #119 cm-ai 父运行可以换会话接着跑
|
|
15
|
-
- #121 QA 修复子运行也能换会话接着跑
|
|
16
|
-
- 已补齐 cm-check 可选能力三态、cm-test 中断步骤恢复;本次补齐 cm-refactor 规则三态和四个停机码,A 类清单已完成
|
|
17
|
-
- 自动检查:每个 PR 跑 119 份,发版时跑满 126 份。
|
|
18
|
-
- 盘点脚本 `scripts/audit-untested-enums.mjs` 报告:**38 个取值缺覆盖,分布在 40 处**(本次由 45 个、42 处降下)。
|
|
19
|
-
- 已完成两份「归档让路」实现的收拢:单一实现位于 `runtime/js/cm-ai/review-evidence-file.mjs`,`host-handoff.mjs` 与 cm-fix 共用;交接文件归档行为逐字节保持不变。
|
|
7
|
+
- npm 上是 **0.16.3**(2026-09-26 发布,标记 `v0.16.3`)。下载回来拆包核对过,本次改动都在包里。
|
|
8
|
+
- 主干在发版之后只有文档更新(#150 README、#151 本文件及其审查修正),没有未发布的功能改动。
|
|
9
|
+
- 自动检查:每个 PR 跑 `scripts/` 下 138 份,另有不阻断合并的历史兼容夹具任务跑 `experiments/` 下 24 份;发版时由 `cm-release-smoke.sh` 补跑 CI 跑不了的 7 份。
|
|
10
|
+
- 盘点脚本 `scripts/audit-untested-enums.mjs` 报告:**24 个取值缺覆盖,分布在 22 处**(上次记录为 38 个、40 处)。
|
|
11
|
+
- 已在真实环境验证:「已审交接后 QA 卡住的任务作废重跑」在 e2e 存量项目和全真模型临时项目上各跑通一次(2026-09-25);公司项目上的原始事故尚待维护者本人跑一次确认。
|
|
20
12
|
|
|
21
13
|
---
|
|
22
14
|
|
|
@@ -43,7 +35,7 @@
|
|
|
43
35
|
|
|
44
36
|
## 第二档:已拍板的设计问题
|
|
45
37
|
|
|
46
|
-
### 1. cm-fix 本地 unknown
|
|
38
|
+
### 1. cm-fix 本地 unknown 步骤的显式放弃与重做(已发布于 0.16.3)
|
|
47
39
|
|
|
48
40
|
**决定**:保留所有 `unknown` 的默认不重派。仅对复现、诊断、测试编写与运行、修复、回归、复盘、走查及对应第二轮本地步骤,
|
|
49
41
|
在原运行中增加带原因和独立启动旗标的 `abandon_step`;每次保留旧 intent,追加绑定摘要的记录和日志,再用新的 retry ID 重做。
|
|
@@ -56,7 +48,7 @@
|
|
|
56
48
|
|
|
57
49
|
## 第三档:已知缺口,值得做但不急
|
|
58
50
|
|
|
59
|
-
### 2. QA
|
|
51
|
+
### 2. QA 修复子运行换会话恢复(已发布于 0.16.3)
|
|
60
52
|
|
|
61
53
|
cm-ai 的 V3 会话父运行用 `--original-host-context` 恢复后,QA 修复子运行也使用当前真实会话打开和签审查授权;已有子配置保持不变。新建子运行只接受当前会话或父运行的持久创建会话,runtime 仍须匹配。父子运行继续串行交接同一把锁,原逐项授权不变。
|
|
62
54
|
|
|
@@ -78,7 +70,7 @@ cm-ai 的 V3 会话父运行用 `--original-host-context` 恢复后,QA 修复
|
|
|
78
70
|
|
|
79
71
|
- **受保护模式跑不了 `tsx` / `vitest` 这类命令**。它们要开本地 socket,而沙箱把这个和「联网」放在同一个开关下。放开就等于给测试命令开整个外网,不划算。替代写法见 `skills/cm-fix/references/js-host.md`。驾驶员在建运行前会预警。
|
|
80
72
|
- **有 7 份测试只在发版时跑**。它们要启动 Codex 沙箱,GitHub 的机器不给这个权限。已接进 `cm-release-smoke.sh`,发版必过;CI 里有一句断言钉死这 7 份的名单,不会悄悄变多。
|
|
81
|
-
- **盘点脚本只认一种写法**(`['a','b'].includes(x)`),`switch`、对象查表、`Set.has` 都漏掉了。所以「
|
|
73
|
+
- **盘点脚本只认一种写法**(`['a','b'].includes(x)`),`switch`、对象查表、`Set.has` 都漏掉了。所以「24」是下限。
|
|
82
74
|
- **读代码找不到所有问题**。0.16.1 修的四个缺陷全是跑真实项目跑出来的。拿工作流去跑真实项目,仍然是发现问题最有效的办法。
|
|
83
75
|
|
|
84
76
|
---
|
|
@@ -97,14 +89,12 @@ cm-ai 的 V3 会话父运行用 `--original-host-context` 恢复后,QA 修复
|
|
|
97
89
|
|
|
98
90
|
---
|
|
99
91
|
|
|
100
|
-
##
|
|
92
|
+
## 发版
|
|
101
93
|
|
|
102
|
-
|
|
94
|
+
0.16.3 已于 2026-09-26 发布。下一版是否发、什么时候发,由维护者决定。
|
|
103
95
|
|
|
104
|
-
|
|
96
|
+
**流程**(0.16.1~0.16.3 都这样走):改六处版本号(`package.json`、`VERSION`、`.codex-plugin/plugin.json`、README 两处、`docs/installation.md`)→ 把 CHANGELOG「未发布」切成新版本 → 跑全套检查和 `cm-release-smoke.sh` → 开 PR 合并 → 在 `cm-workflow-dev` 目录的终端 `npm publish` 并过两步验证(这一步必须本人做)→ 下载包核对 → 在发版提交上打标记 → 两端重新安装。
|
|
105
97
|
|
|
106
|
-
|
|
98
|
+
**README 的「最近更新」要重写正文,不能只换版本号**。0.16.0~0.16.2 发版时只替换了版本号,结果那段一直挂着 0.15.5 的内容,直到 #150 才改回来。
|
|
107
99
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
**注意**:npm 登录会过期。`npm whoami` 报 401 时,先 `npm login`,确认打印出 `aibyzero` 再发。过期时 npm 报的是 404「找不到包」,很容易误判成包出了问题。
|
|
100
|
+
**注意**:npm 登录会过期。`npm whoami` 报 401 时,先 `npm login`,确认打印出 `aibyzero` 再发。过期时 npm 报的是 404「找不到包」,很容易误判成包出了问题。浏览器登录那一步超时时,可以改用 `npm login --auth-type=legacy`,在终端里依次输入用户名、密码和两步验证码。`npm publish` 过程中还会再弹一次网页确认,链接出来就尽快打开,别让它过期。
|
package/docs/runtime-failover.md
CHANGED
|
@@ -58,7 +58,7 @@ node scripts/cm-failover.mjs probe
|
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
60
|
node scripts/cm-ai-host.mjs serve --config {CONFIG} --mode create \
|
|
61
|
-
--host-context {ID} --allow-development --failover
|
|
61
|
+
--host-context {ID} --allow-development --review-config {REVIEW_CONFIG} --failover
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
传入后,host 在构造 execution **之前**按 `developer` 角色选路。**声明为主、探测为校验**:
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
// Journal data grammar. Only the trusted serial host supplies original owner evidence.
|
|
2
2
|
import {digest,hex,id,json,need,shape,validIdentity} from './effect-contract.mjs';
|
|
3
3
|
import {qaFixIdentity} from '../cm-fix/qa-source.mjs';
|
|
4
|
-
import {composeFixCode} from './fix-code-association.mjs';
|
|
4
|
+
import {associationRecord,composeFixCode,readSteps} from './fix-code-association.mjs';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// resolveSteps: steps -> resolved steps from the named runs' verified stores, or
|
|
7
|
+
// null when a store is absent. Pure journal replay has no stores: a version 2
|
|
8
|
+
// record is then checked for shape and chain only, and the runner re-proves its
|
|
9
|
+
// composition against the stores (and every live use refuses what it cannot).
|
|
10
|
+
export function validateAcceptedFix({record,previous,baseline,parentPackage,feature,resolveSteps=null}){
|
|
7
11
|
shape(record,['evidence','association','qaRound']);
|
|
8
12
|
const {evidence:e,association:a,qaRound}=record;
|
|
9
13
|
shape(e,['version','kind','identity','qaSource','checkpointRevision','reviewPackage','reviewRegistrationDigest',
|
|
@@ -21,8 +25,22 @@ export function validateAcceptedFix({record,previous,baseline,parentPackage,feat
|
|
|
21
25
|
}
|
|
22
26
|
need(qaRound===previous.length+1&&qaRound<=2,'fix_chain_invalid');
|
|
23
27
|
need(!previous.some(item=>item.evidence.qaSource.testRunId===e.qaSource.testRunId),'fix_chain_invalid');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
// Version 1: strict chain. Version 2 keeps the previous record's interleaved
|
|
29
|
+
// deliveries as an exact prefix and may add only steps preceding this fix.
|
|
30
|
+
const steps=a?.version===2?a.laterDeliveries:[],prior=previous.at(-1)?.association.laterDeliveries??[];
|
|
31
|
+
need(Array.isArray(steps)&&(a?.version!==2||steps.length>0)&&steps.length>=prior.length
|
|
32
|
+
&&digest(steps.slice(0,prior.length))===digest(prior)
|
|
33
|
+
&&steps.slice(prior.length).every(step=>step?.beforeFix===previous.length),'fix_association_invalid');
|
|
34
|
+
const fixPackages=[...previous.map(item=>item.evidence.reviewPackage),e.reviewPackage];
|
|
35
|
+
readSteps(steps,fixPackages.length);
|
|
36
|
+
const resolved=steps.length?(typeof resolveSteps==='function'?resolveSteps(steps):null):[];
|
|
37
|
+
if(resolved){
|
|
38
|
+
const composed=composeFixCode({baseline,parentPackage,fixPackages,steps:resolved});
|
|
39
|
+
need(digest(a)===digest(associationRecord({...composed,steps})),'fix_association_invalid');
|
|
40
|
+
}else{
|
|
41
|
+
shape(a,['version','kind','parentPackageDigest','fixPackageDigest','currentFilesDigest','laterDeliveries']);
|
|
42
|
+
need(a.kind==='cm-fix-code-association'&&a.parentPackageDigest===parentPackage.packageDigest
|
|
43
|
+
&&a.fixPackageDigest===e.reviewPackage.packageDigest,'fix_association_invalid');hex(a.currentFilesDigest);
|
|
44
|
+
}
|
|
27
45
|
return json(record,12*1024*1024);
|
|
28
46
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {readSpecsStatus} from '../specs-status.mjs';
|
|
2
|
+
|
|
3
|
+
// One feature-name decision. A specs path reads its approved manifest;
|
|
4
|
+
// data-only replay callers pass their already-bound feature list.
|
|
5
|
+
export function identifyApprovedBootstrapFeature(source){
|
|
6
|
+
const status=typeof source==='string'?readSpecsStatus(source):null;
|
|
7
|
+
if(status&&!(status.kind==='valid'&&status.value.status==='approved'))
|
|
8
|
+
throw Object.assign(new Error('bootstrap_approval_required'),{code:'bootstrap_approval_required'});
|
|
9
|
+
const features=status?status.value.features:source;
|
|
10
|
+
if(!Array.isArray(features)||!features.every(name=>typeof name==='string'))
|
|
11
|
+
throw Object.assign(new Error('bootstrap_approval_required'),{code:'bootstrap_approval_required'});
|
|
12
|
+
const candidates=features.filter(name=>/^\d+\.bootstrap$/.test(name));
|
|
13
|
+
if(candidates.length>1)throw Object.assign(new Error('bootstrap_feature_ambiguous'),{code:'bootstrap_feature_ambiguous'});
|
|
14
|
+
return candidates[0]??null;
|
|
15
|
+
}
|
|
@@ -10,6 +10,16 @@ export function reportClaudeRateLimitNotice(raw, onNotice) {
|
|
|
10
10
|
try { onNotice({kind:'rate_limit', info}); } catch {}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export function reportClaudeDevIntentNotice(onNotice) {
|
|
14
|
+
if (typeof onNotice !== 'function') return;
|
|
15
|
+
try { onNotice({kind:'claude_system_notice', subtype:'dev_intent'}); } catch {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Error classes observed from Claude CLI 2.1.274; anything else is reviewer_api_error.
|
|
19
|
+
const API_ERROR_CLASSES = Object.freeze({authentication_failed:'reviewer_auth_failed',
|
|
20
|
+
billing_error:'reviewer_billing_error', rate_limit:'reviewer_rate_limited',
|
|
21
|
+
server_error:'reviewer_server_error', model_not_found:'reviewer_model_not_found'});
|
|
22
|
+
|
|
13
23
|
export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
14
24
|
let session = null, stage = 'init', value, noticeCount = 0, thinkingCount = 0, rejectedAttempts = 0;
|
|
15
25
|
const pendingTools = new Map(), toolIds = new Set();
|
|
@@ -22,6 +32,13 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
|
22
32
|
|| message.session_id.length > 256) reject('invalid_session');
|
|
23
33
|
if (session !== null && session !== message.session_id) reject('session_mismatch');
|
|
24
34
|
if (stage === 'init') {
|
|
35
|
+
if (message.type === 'system' && message.subtype === 'dev_intent') {
|
|
36
|
+
if (noticeCount >= 32) reject('unexpected_event');
|
|
37
|
+
noticeCount++;
|
|
38
|
+
session = message.session_id;
|
|
39
|
+
reportClaudeDevIntentNotice(onNotice);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
25
42
|
if (message.type !== 'system' || message.subtype !== 'init') reject('missing_init');
|
|
26
43
|
session = message.session_id;
|
|
27
44
|
stage = 'assistant';
|
|
@@ -36,6 +53,12 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
|
36
53
|
return;
|
|
37
54
|
}
|
|
38
55
|
if (message.type === 'system') {
|
|
56
|
+
if (message.subtype === 'dev_intent') {
|
|
57
|
+
if (noticeCount >= 32) reject('unexpected_event');
|
|
58
|
+
noticeCount++;
|
|
59
|
+
reportClaudeDevIntentNotice(onNotice);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
39
62
|
if (message.subtype === 'thinking_tokens') {
|
|
40
63
|
// Long reviews emit usage heartbeats; worker-claude also caps total output at 1 MB.
|
|
41
64
|
if (thinkingCount >= 4096) reject('unexpected_event');
|
|
@@ -55,6 +78,13 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
|
55
78
|
return;
|
|
56
79
|
}
|
|
57
80
|
if (message.type === 'assistant') {
|
|
81
|
+
// CLI 2.1.x reports an API failure as a synthetic assistant message with
|
|
82
|
+
// a string error class, then an is_error result. Before any tool call it
|
|
83
|
+
// carries no verdict: stop with the class so the user knows what to fix.
|
|
84
|
+
if (typeof message.error === 'string' && message.parent_tool_use_id === null
|
|
85
|
+
&& message.message?.role === 'assistant' && toolIds.size === 0) {
|
|
86
|
+
reject(Object.hasOwn(API_ERROR_CLASSES, message.error) ? API_ERROR_CLASSES[message.error] : 'reviewer_api_error');
|
|
87
|
+
}
|
|
58
88
|
if (message.parent_tool_use_id !== null || message.error != null
|
|
59
89
|
|| message.message?.role !== 'assistant') reject('unexpected_assistant');
|
|
60
90
|
const content = message.message.content;
|
|
@@ -5,27 +5,27 @@ import { createHash } from 'node:crypto';
|
|
|
5
5
|
import { spawnSync } from 'node:child_process';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import {readSpecsStatus,writeSpecsStatus} from '../specs-status.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
|
|
9
|
+
import {buildManifest,verifyApprovedManifest} from '../../../scripts/cm-spec-manifest.mjs';
|
|
10
|
+
import {outstandingFeatureQa,describeOutstandingQa} from './project-qa-gate.mjs';
|
|
11
|
+
import {taskLines,taskDeclarations,approvedTaskGrammar,TASK_GRAMMAR,LEGACY_TASK_GRAMMAR} from '../spec-task-line.mjs';
|
|
12
|
+
export {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
|
|
9
13
|
|
|
10
|
-
const
|
|
11
|
-
const DEPENDENCY=/^\s*-\s*(T-[A-Za-z0-9][A-Za-z0-9._-]*)\s+依赖\s+(.+)$/;
|
|
14
|
+
export const DEPENDENCY=/^\s*-\s*(T-[A-Za-z0-9][A-Za-z0-9._-]*)\s+依赖\s+(.+)$/;
|
|
12
15
|
const TASK_ID=/^T-[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
13
16
|
const ACCEPTANCE=/^\s*[-*]\s+(?:\[[ xX]\]\s+)?(?:\[(AC-\d{3,})\]|(AC-\d{3,}))(?=[:\s])/;
|
|
14
17
|
const FEATURE=/^(\d+)\.(.+)$/;
|
|
15
18
|
const TEST_CASE_VALIDATOR=fileURLToPath(new URL('../../../scripts/validate-test-cases.mjs',import.meta.url));
|
|
16
19
|
|
|
17
|
-
export function parseCmAiTaskLine(line){
|
|
18
|
-
const match=line.match(TASK);
|
|
19
|
-
return match?{id:match[2],completed:match[1].toLowerCase()==='x'}:null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
20
|
// Greenfield's T-001 scaffolds; its subsequent instruction task (normally
|
|
23
21
|
// T-002) owns init-equivalent rules. Use the existing parser and approval gate.
|
|
24
22
|
export function inspectCmAiBootstrapTask({specsDir,codeProject,taskId},inProgress=false) {
|
|
25
23
|
const admission=admissionFor({specsDir,codeProject},inProgress?taskId:null);
|
|
26
24
|
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
27
25
|
if(!['ready','complete'].includes(admission.state))fail(admission.reason);
|
|
28
|
-
const
|
|
26
|
+
const feature=identifyApprovedBootstrapFeature(readSpecsStatus(admission.specsDir).value.features);
|
|
27
|
+
if(feature===null)fail('bootstrap_task_required');
|
|
28
|
+
const parsed=readFeature(admission.specsDir,feature);if(parsed.error)fail(parsed.error);
|
|
29
29
|
const task=parsed.tasks.find(item=>item.id===taskId&&!item.dropped);
|
|
30
30
|
const mode=task?.id==='T-001'&&/(?:脚手架|骨架|scaffold)/i.test(task.description)?'scaffold':'instructions';
|
|
31
31
|
if(!task||mode==='instructions'&&(!/(?:cm-init|\.claude\/|AGENTS\.md)/i.test(task.description)
|
|
@@ -87,7 +87,9 @@ function directory(value){
|
|
|
87
87
|
function approvalIntent(response,assumeYes){
|
|
88
88
|
if(assumeYes===true)return 'explicit';
|
|
89
89
|
if(response===undefined||response===null||response==='')return 'none';
|
|
90
|
-
|
|
90
|
+
if(typeof response!=='string')return 'not_approval';
|
|
91
|
+
const normalized=response.trim().replace(/[。!!.~~\s]+$/gu,'');
|
|
92
|
+
return new Set(['开始','开始吧','可以开始','确认开始','开始执行','现在开始']).has(normalized)?'explicit':'not_approval';
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
|
|
@@ -102,12 +104,13 @@ function discoverFeatures(specsDir){
|
|
|
102
104
|
.filter(entry=>entry.isDirectory()&&FEATURE.test(entry.name))
|
|
103
105
|
.map(entry=>entry.name)
|
|
104
106
|
.sort((a,b)=>{
|
|
105
|
-
if(a
|
|
106
|
-
if(b
|
|
107
|
+
if(/^\d+\.bootstrap$/.test(a))return /^\d+\.bootstrap$/.test(b)?0:-1;
|
|
108
|
+
if(/^\d+\.bootstrap$/.test(b))return 1;
|
|
107
109
|
const an=Number(a.match(FEATURE)[1]),bn=Number(b.match(FEATURE)[1]);
|
|
108
110
|
return an-bn||(a<b?-1:a>b?1:0);
|
|
109
111
|
});
|
|
110
112
|
if(!names.length)return {error:'features_missing'};
|
|
113
|
+
try{identifyApprovedBootstrapFeature(names);}catch(error){return {error:error.code};}
|
|
111
114
|
const reviewKeys=names.flatMap(name=>[name,name.replace(/^\d+\./,'')]);
|
|
112
115
|
if(new Set(reviewKeys).size!==reviewKeys.length)return {error:'feature_contract_invalid'};
|
|
113
116
|
for(const name of names){
|
|
@@ -151,7 +154,7 @@ function validTestContract(target,featureName){
|
|
|
151
154
|
try{sources=['requirements.md','design.md','tasks.md'].map(file=>fs.readFileSync(path.join(featureRoot,file),'utf8'));}
|
|
152
155
|
catch{return false;}
|
|
153
156
|
const acIds=new Set(sources.flatMap(source=>source.split(/\r?\n/).map(line=>line.match(ACCEPTANCE)).filter(Boolean).map(match=>match[1]||match[2])));
|
|
154
|
-
const taskIds=new Set(sources[2]
|
|
157
|
+
const taskIds=new Set(taskDeclarations(sources[2],{grammar:approvedTaskGrammar(path.dirname(featureRoot))}).map(task=>task.id));
|
|
155
158
|
return data.cases.every(item=>item.acIds.every(id=>acIds.has(id))&&item.taskIds.every(id=>taskIds.has(id)));
|
|
156
159
|
}
|
|
157
160
|
|
|
@@ -197,7 +200,8 @@ function validateTestCases(specsDir,status,names){
|
|
|
197
200
|
}
|
|
198
201
|
|
|
199
202
|
function readFeature(specsDir,name){
|
|
200
|
-
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8'),
|
|
203
|
+
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8'),
|
|
204
|
+
{allowDependencyPunctuation:true,grammar:approvedTaskGrammar(specsDir)});
|
|
201
205
|
if(parsed.error)parsed.detail={feature:name,...parsed.detail};
|
|
202
206
|
return parsed;
|
|
203
207
|
}
|
|
@@ -206,24 +210,26 @@ export function declaredAcceptanceIds(source){
|
|
|
206
210
|
return new Set(source.split(/\r?\n/).map(line=>line.match(ACCEPTANCE)).filter(Boolean).map(match=>match[1]||match[2]));
|
|
207
211
|
}
|
|
208
212
|
|
|
209
|
-
|
|
210
|
-
|
|
213
|
+
// Shared declaration grammar (spec-task-line.mjs), versioned by the approval.
|
|
214
|
+
export function parseFeatureTaskText(source,{allowDependencyPunctuation=false,grammar=TASK_GRAMMAR}={}){
|
|
215
|
+
const lines=taskLines(source,{grammar});
|
|
211
216
|
const tasks=[];
|
|
212
217
|
const taskIds=new Set();
|
|
213
218
|
const dependencies=new Map();
|
|
214
219
|
const dependencyLocations=new Map();
|
|
215
|
-
const location=index=>({line:index+1,text:lines[index].slice(0,120)});
|
|
220
|
+
const location=index=>({line:index+1,text:lines[index].body.slice(0,120)});
|
|
216
221
|
const invalid=(error,index)=>({error,detail:location(index)});
|
|
217
|
-
for(const
|
|
218
|
-
|
|
222
|
+
for(const {index,body:line,fenced,declaration:task} of lines){
|
|
223
|
+
if(fenced)continue;
|
|
219
224
|
if(task){
|
|
220
|
-
if(taskIds.has(task
|
|
221
|
-
taskIds.add(task
|
|
222
|
-
const
|
|
225
|
+
if(taskIds.has(task.id))return invalid('tasks_invalid',index);
|
|
226
|
+
taskIds.add(task.id);
|
|
227
|
+
const rest=task.description;
|
|
228
|
+
const dropped=/\[DROPPED(?:\s[^\]]*)?\]/.test(rest);
|
|
223
229
|
tasks.push({
|
|
224
|
-
id:task
|
|
225
|
-
description:
|
|
226
|
-
completed:task
|
|
230
|
+
id:task.id,
|
|
231
|
+
description:rest.replace(/~~\s*\[DROPPED(?:\s[^\]]*)?\].*$/,'').trim(),
|
|
232
|
+
completed:task.completed,
|
|
227
233
|
dropped,
|
|
228
234
|
});
|
|
229
235
|
continue;
|
|
@@ -239,7 +245,7 @@ export function parseFeatureTaskText(source,{allowDependencyPunctuation=false}={
|
|
|
239
245
|
dependencyLocations.set(dependency[1],location(index));
|
|
240
246
|
}
|
|
241
247
|
}
|
|
242
|
-
if(!tasks.length)return invalid('tasks_invalid',Math.max(0,lines.findIndex(line=>line.trim())));
|
|
248
|
+
if(!tasks.length)return invalid('tasks_invalid',Math.max(0,lines.findIndex(line=>line.body.trim())));
|
|
243
249
|
return {tasks,dependencies,dependencyLocations};
|
|
244
250
|
}
|
|
245
251
|
|
|
@@ -267,10 +273,10 @@ function invalidDependency(tasks,dependencies){
|
|
|
267
273
|
|
|
268
274
|
function validateBootstrap(codeProject,specsDir,names){
|
|
269
275
|
const empty=fs.readdirSync(codeProject).length===0;
|
|
270
|
-
const
|
|
271
|
-
if(empty&&!
|
|
272
|
-
if(!empty&&
|
|
273
|
-
const parsed=readFeature(specsDir,
|
|
276
|
+
const bootstrap=identifyApprovedBootstrapFeature(names);
|
|
277
|
+
if(empty&&!bootstrap)return 'bootstrap_required';
|
|
278
|
+
if(!empty&&bootstrap){
|
|
279
|
+
const parsed=readFeature(specsDir,bootstrap);
|
|
274
280
|
if(parsed.error)return null; // Let selection retain the parser's location and feature summaries.
|
|
275
281
|
const bootstrapTask=parsed.tasks.find(task=>task.id==='T-001');
|
|
276
282
|
if(bootstrapTask&&!bootstrapTask.completed&&!bootstrapTask.dropped)return 'bootstrap_conflict';
|
|
@@ -298,6 +304,13 @@ function missingReviewIds(featureName,tasks,evidenceNames){
|
|
|
298
304
|
});
|
|
299
305
|
}
|
|
300
306
|
|
|
307
|
+
function dependenciesSatisfied(task,parsed,byId){
|
|
308
|
+
return (parsed.dependencies.get(task.id)||[]).every(id=>{
|
|
309
|
+
const dependency=byId.get(id);
|
|
310
|
+
return dependency&&(dependency.completed||dependency.dropped);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
301
314
|
function selectTask(specsDir,names){
|
|
302
315
|
const features=[];
|
|
303
316
|
const warnings=[];
|
|
@@ -322,18 +335,26 @@ function selectTask(specsDir,names){
|
|
|
322
335
|
pending:pending.length,
|
|
323
336
|
});
|
|
324
337
|
if(!pending.length)continue;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
338
|
+
// One dependency rule for nextTask and --task/parallel eligibility: a
|
|
339
|
+
// prerequisite is satisfied once it is completed or DROPPED.
|
|
340
|
+
const ready=task=>dependenciesSatisfied(task,parsed,byId);
|
|
341
|
+
const eligible=pending.find(ready);
|
|
329
342
|
if(!eligible)return {error:'dependencies_not_ready',features,warnings};
|
|
330
343
|
return {features,warnings,nextTask:{feature:name,id:eligible.id,description:eligible.description},
|
|
331
|
-
eligibleTasks:pending.filter(
|
|
332
|
-
.map(task=>({feature:name,id:task.id}))};
|
|
344
|
+
eligibleTasks:pending.filter(ready).map(task=>({feature:name,id:task.id}))};
|
|
333
345
|
}
|
|
334
346
|
return {features,warnings,nextTask:null};
|
|
335
347
|
}
|
|
336
348
|
|
|
349
|
+
// Selection stays tasks.md-driven; an earlier feature's unfinished QA is surfaced
|
|
350
|
+
// here and enforced at N8 (finish/run_finalize), never by reordering tasks.
|
|
351
|
+
function featureQaWarnings(specsDir,features){
|
|
352
|
+
try{
|
|
353
|
+
return outstandingFeatureQa({specsDir,features:features.map(({name,pending})=>({name,pending}))}).map(item=>
|
|
354
|
+
`⚠ QA 未通过: ${describeOutstandingQa(item)};它通过之前项目不能收尾(run_done)`);
|
|
355
|
+
}catch{return ['⚠ QA 日志无法读取,未能确认各 feature 的最新 QA 是否通过'];}
|
|
356
|
+
}
|
|
357
|
+
|
|
337
358
|
export function inspectCmAiAdmission(options){
|
|
338
359
|
return admissionFor(options);
|
|
339
360
|
}
|
|
@@ -343,7 +364,7 @@ export function approveCmAiSpecs(options){
|
|
|
343
364
|
const projects=options.codeProjects??[options.codeProject];
|
|
344
365
|
const inspect=()=>projects.map(codeProject=>inspectCmAiAdmission({...options,codeProject}));
|
|
345
366
|
const projectResults=inspect();
|
|
346
|
-
const refuse=approveRefused=>({projectResults,approveRefused});
|
|
367
|
+
const refuse=(approveRefused,approveReason=null)=>({projectResults,approveRefused,...(approveReason?{approveReason}:{})});
|
|
347
368
|
if(options.assumeYes)return refuse('assume_yes_not_allowed');
|
|
348
369
|
if(typeof options.approvalResponse!=='string'||!options.approvalResponse.trim())
|
|
349
370
|
return refuse('approval_response_required');
|
|
@@ -356,10 +377,37 @@ export function approveCmAiSpecs(options){
|
|
|
356
377
|
try{
|
|
357
378
|
const discovered=discoverFeatures(specsDir);
|
|
358
379
|
if(discovered.error)return refuse(discovered.error);
|
|
380
|
+
// An approval binds grammar 2 to every feature, including ones this change
|
|
381
|
+
// did not touch. Refuse rather than silently re-reading bytes that an older
|
|
382
|
+
// approval parsed differently (e.g. an unfenced `- [ ] T-001:例` becoming a
|
|
383
|
+
// duplicate of the real T-001), and rather than keeping grammar 1, which
|
|
384
|
+
// would leave newly drafted full-width task lines silently not tasks.
|
|
385
|
+
// Moving from the pre-grammar parse must not change which lines are tasks
|
|
386
|
+
// either (e.g. a unique `- [ ] T-099:示例` would become a pending task). The
|
|
387
|
+
// status carries the last approval's grammar through cm-prd publication;
|
|
388
|
+
// once a project is on grammar 2 there is nothing to reconcile.
|
|
389
|
+
// No status at all means nothing was approved before: no earlier meaning to keep.
|
|
390
|
+
const fromLegacy=status.kind==='valid'&&status.value.taskGrammar!==TASK_GRAMMAR;
|
|
391
|
+
for(const name of discovered.names){
|
|
392
|
+
const source=fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8');
|
|
393
|
+
const parsed=parseFeatureTaskText(source,{allowDependencyPunctuation:true,grammar:TASK_GRAMMAR});
|
|
394
|
+
if(parsed.error)return refuse('task_grammar_conflict',`${name}/tasks.md 第 ${parsed.detail.line} 行在新任务行语法下无效(${parsed.error}):`
|
|
395
|
+
+`${parsed.detail.text}。此前的批准把它当作说明文字;把这类示例放进 \`\`\` 围栏或删去后再批准。`);
|
|
396
|
+
if(!fromLegacy)continue;
|
|
397
|
+
const view=grammar=>taskDeclarations(source,{grammar}).map(item=>({line:item.index+1,key:`${item.id}\0${item.completed}\0${item.body.trim()}`,text:item.body.trim()}));
|
|
398
|
+
const legacy=view(LEGACY_TASK_GRAMMAR),current=view(TASK_GRAMMAR);
|
|
399
|
+
const legacyKeys=new Set(legacy.map(item=>item.key)),currentKeys=new Set(current.map(item=>item.key));
|
|
400
|
+
const differing=[...current.filter(item=>!legacyKeys.has(item.key)),...legacy.filter(item=>!currentKeys.has(item.key))]
|
|
401
|
+
.sort((a,b)=>a.line-b.line);
|
|
402
|
+
if(differing.length)return refuse('task_grammar_conflict',`${name}/tasks.md 在新任务行语法下任务集合会变化:`
|
|
403
|
+
+differing.slice(0,5).map(item=>`第 ${item.line} 行 ${item.text}`).join(';')+`${differing.length>5?` 等 ${differing.length} 行`:''}`
|
|
404
|
+
+'。此前的批准不把这些行当任务(或反之);是示例就放进 ``` 围栏或删去,是任务就改用英文冒号「:」写法后再批准。');
|
|
405
|
+
}
|
|
359
406
|
const specFiles=buildManifest(specsDir),at=new Date().toISOString();
|
|
360
407
|
writeSpecsStatus(specsDir,{status:'approved',summaryDigest:status.value?.summaryDigest??null,at,
|
|
361
408
|
features:discovered.names,specFiles,testCases:specFiles.filter(item=>item.path.endsWith('/test-cases.json')),
|
|
362
|
-
approval:{response:options.approvalResponse,at}
|
|
409
|
+
approval:{response:options.approvalResponse,at},taskGrammar:TASK_GRAMMAR,
|
|
410
|
+
...(status.value&&Object.hasOwn(status.value,'revisionDigest')?{revisionDigest:status.value.revisionDigest}:{})});
|
|
363
411
|
}catch(error){return refuse(error.code??error.message);}
|
|
364
412
|
return {projectResults:inspect()};
|
|
365
413
|
}
|
|
@@ -382,7 +430,7 @@ function admissionFor(options,inProgressBootstrap=null){
|
|
|
382
430
|
if(featuresProblem==='spec_features_changed')return result(base,'awaiting_spec_approval',featuresProblem);
|
|
383
431
|
if(featuresProblem)return result(base,'blocked',featuresProblem);
|
|
384
432
|
if(Object.hasOwn(status.value,'specFiles')){
|
|
385
|
-
try{
|
|
433
|
+
try{verifyApprovedManifest(specsDir,path.join(specsDir,'.cm-specs-status'));}
|
|
386
434
|
catch{return result(base,'blocked','spec_drift');}
|
|
387
435
|
}
|
|
388
436
|
const testCasesProblem=validateTestCases(specsDir,status.value,discovered.names);
|
|
@@ -394,8 +442,32 @@ function admissionFor(options,inProgressBootstrap=null){
|
|
|
394
442
|
const selection=selectTask(specsDir,discovered.names);
|
|
395
443
|
if(selection.error)return result(base,'blocked',selection.error,{features:selection.features,warnings:selection.warnings,
|
|
396
444
|
...(selection.detail?{detail:selection.detail}:{})});
|
|
397
|
-
|
|
398
|
-
return result(base,'
|
|
445
|
+
const warnings=[...selection.warnings,...featureQaWarnings(specsDir,selection.features)];
|
|
446
|
+
if(!selection.nextTask)return result(base,'complete','all_tasks_terminal',{features:selection.features,warnings});
|
|
447
|
+
return result(base,'ready','task_selected',{features:selection.features,nextTask:selection.nextTask,eligibleTasks:selection.eligibleTasks,warnings});
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// Diagnostic only: why an explicit --task selection is not eligible. Never used
|
|
451
|
+
// to grant a selection; matchesCmAiTaskSelection remains the sole gate.
|
|
452
|
+
export function explainCmAiTaskSelection(admission,{feature,taskId,selection=null}){
|
|
453
|
+
if(admission.state!=='ready')return `当前准入状态为 ${admission.state}/${admission.reason},不能选择任务`;
|
|
454
|
+
const next=admission.nextTask;
|
|
455
|
+
if(next&&next.feature!==feature)return `--task 只能选择当前 feature ${next.feature} 的任务(运行定义为 ${feature})`;
|
|
456
|
+
if(!admission.specsDir)return `${taskId} 不在可选任务中`;
|
|
457
|
+
let parsed;
|
|
458
|
+
try{parsed=readFeature(admission.specsDir,feature);}catch{return `无法读取 ${feature}/tasks.md`;}
|
|
459
|
+
if(parsed.error)return `${feature}/tasks.md 无法解析(${parsed.error})`;
|
|
460
|
+
const byId=new Map(parsed.tasks.map(task=>[task.id,task]));
|
|
461
|
+
const task=byId.get(taskId);
|
|
462
|
+
if(!task)return `${feature}/tasks.md 中没有任务 ${taskId}`;
|
|
463
|
+
if(task.dropped)return `${taskId} 已标记 DROPPED`;
|
|
464
|
+
if(task.completed)return `${taskId} 已勾选完成`;
|
|
465
|
+
const waiting=(parsed.dependencies.get(taskId)||[]).filter(id=>{const item=byId.get(id);return !item||!item.completed&&!item.dropped;});
|
|
466
|
+
if(waiting.length)return `${taskId} 依赖的 ${waiting.join('、')} 尚未完成`;
|
|
467
|
+
const eligible=(admission.eligibleTasks??[]).filter(item=>item.feature===feature).map(item=>item.id);
|
|
468
|
+
if(selection===null&&next&&next.id!==taskId&&eligible.includes(taskId))
|
|
469
|
+
return `运行定义未写 taskSelection,只能运行 nextTask ${next.id};改选 ${taskId} 请用 cm-ai-admission.mjs --print-run-definition --task ${taskId} 重新生成运行定义`;
|
|
470
|
+
return `${taskId} 不在可选任务中;当前可选:${eligible.join('、')||'无'}`;
|
|
399
471
|
}
|
|
400
472
|
|
|
401
473
|
// Trusted caller selection is data bound by openControlRun, never message authority.
|
|
@@ -403,6 +475,9 @@ export function matchesCmAiTaskSelection(admission,feature,taskId,parallelSelect
|
|
|
403
475
|
if(parallelSelection===null)return admission.state==='ready'
|
|
404
476
|
&&admission.nextTask?.feature===feature&&admission.nextTask.id===taskId;
|
|
405
477
|
const value=parallelSelection;
|
|
478
|
+
if(value?.version===1&&Object.keys(value).sort().join(',')==='taskId,version')
|
|
479
|
+
return value.taskId===taskId&&admission.state==='ready'
|
|
480
|
+
&&admission.eligibleTasks?.some(task=>task.feature===feature&&task.id===taskId)===true;
|
|
406
481
|
return admission.state==='ready'&&value?.version===1
|
|
407
482
|
&&Object.keys(value).sort().join(',')==='group,version'&&Array.isArray(value.group)
|
|
408
483
|
&&value.group.length>=2&&new Set(value.group).size===value.group.length
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {createHash} from 'node:crypto';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import {inspectCmAiAdmission,matchesCmAiTaskSelection} from './cm-ai-admission.mjs';
|
|
5
|
+
import {inspectCmAiAdmission,matchesCmAiTaskSelection,identifyApprovedBootstrapFeature} from './cm-ai-admission.mjs';
|
|
6
6
|
import {arrayItems,digest,freeze,hex,json,need,shape,text,validIdentity,validTaskLearningInput} from './effect-contract.mjs';
|
|
7
7
|
|
|
8
8
|
const BASELINE_RULES=['coding-style.md','testing.md','security.md'];
|
|
@@ -62,7 +62,8 @@ export function inspectCmAiContextRefresh(input,{admission:trustedAdmission=null
|
|
|
62
62
|
shape(input,['specsDir','codeProject','feature','applicableAgentFiles']);
|
|
63
63
|
text(input.specsDir);text(input.codeProject);text(input.feature);
|
|
64
64
|
const admission=trustedAdmission??inspectCmAiAdmission({specsDir:input.specsDir,codeProject:input.codeProject});
|
|
65
|
-
if(trustedAdmission!==null)need(input.feature===
|
|
65
|
+
if(trustedAdmission!==null)need(input.feature===identifyApprovedBootstrapFeature(
|
|
66
|
+
trustedAdmission.features.map(item=>item.name))
|
|
66
67
|
&&admission.specsDir===input.specsDir&&admission.codeProject===input.codeProject,'context_invalid');
|
|
67
68
|
if(!['ready','complete'].includes(admission.state))return freeze({state:admission.state,reason:admission.reason,
|
|
68
69
|
nextTask:null,eligibleTasks:[],contextDigest:null,contextFiles:[]});
|