@aibyzero/cm-workflow 0.21.4 → 0.21.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.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +13 -0
- package/README.md +7 -2
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +1 -0
- package/install.ps1 +3 -0
- package/install.sh +2 -0
- package/package.json +1 -1
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-check/host.mjs +37 -8
- package/runtime/js/cm-prd/accepted-design.mjs +4 -0
- package/runtime/js/cm-prd/disposition-plan.mjs +4 -2
- package/runtime/js/cm-prd/narrow-review.mjs +210 -0
- package/runtime/js/cm-prd/review-correction.mjs +161 -8
- package/runtime/js/cm-prd/review-disposition.mjs +8 -1
- package/runtime/js/cm-prd/review-findings.mjs +8 -0
- package/runtime/js/notify.mjs +1 -0
- package/scripts/ci-test-weights.json +1 -0
- package/scripts/cm-check-doc-links.mjs +29 -0
- package/scripts/cm-check-host.test.mjs +46 -0
- package/scripts/cm-check-runtime.sh +15 -0
- package/scripts/cm-claude-install-layout.test.mjs +12 -0
- package/scripts/cm-doc-links-shared.mjs +139 -0
- package/scripts/cm-doc-links.test.mjs +110 -0
- package/scripts/cm-prd-design-phase.test.mjs +36 -4
- package/scripts/cm-prd-drive.mjs +12 -6
- package/scripts/cm-prd-host.mjs +15 -5
- package/scripts/cm-prd-narrow-review.test.mjs +429 -0
- package/scripts/cm-prd-review-gate.mjs +3 -0
- package/scripts/cm-rewrite-doc-links.mjs +34 -0
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-check/SKILL.md +1 -1
- package/skills/cm-prd/SKILL.md +1 -0
- package/skills/cm-prd/references/js-change-recovery.md +2 -0
- package/skills/cm-prd/references/js-host.md +17 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cm-workflow",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.6",
|
|
4
4
|
"description": "Spec-driven product development workflow for Codex: external research, PRD, implementation, read-only feature testing, review, QA, fixes, refactors, and documentation.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "cm-workflow maintainers",
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@
|
|
|
5
5
|
|
|
6
6
|
## 未发布
|
|
7
7
|
|
|
8
|
+
(暂无)
|
|
9
|
+
|
|
10
|
+
## 0.21.6 — 2026-11-25
|
|
11
|
+
|
|
12
|
+
- **修复 Claude 兼容安装下技能的 docs 链接失效**:安装时把本包技能里的 `../docs/` 链接改写为 `../cm-workflow/docs/`,并随包写入范围清单,`cm-check` 机器检查链接可达且不误查用户自装技能;`cm-notify` 不属于读取运行时合同的核心技能,第 2 组口径与检查一并改正。
|
|
13
|
+
- **修复 `cm-check-drive` 被大文件误阻断**:快照不再让超过 1MB 的非 CM 文本触发 `init_draft_target_invalid`,超限文件按内容摘要或大小与时间核对漂移,阻断信息带出具体文件路径。
|
|
14
|
+
|
|
15
|
+
## 0.21.5 — 2026-11-25
|
|
16
|
+
|
|
17
|
+
- **cm-prd 设计阶段支持修正后窄审,最多两轮**:设计审查返回问题、原修正保存后,同一份审查包下可用 `narrow_review` 记录窄审(审查方、会话、逐条分级、四个是否题、阻断触发场景),作者据此再修正,每轮修正必须有对应审查记录并逐项写处置;第三轮被拒,第二轮仍有阻断停在「待用户拍板」,不自动放行。有窄审记录时,原处置回执和旧入口 `record` 都要窄审通过。只对新写出的原修正存档生效,在途旧运行与 split 阶段不变。
|
|
18
|
+
- **审查模型不可用时可记降级窄审**:`self-degraded` 轮仅留痕,通过也不放行;审查模型恢复后若还剩一轮,可对同一份设计再记一轮独立审查(不得复用作者或降级会话)再放行。
|
|
19
|
+
- **修复窄审通过后拆分阶段改设计被误判为漂移**:窄审关卡改为核对设计回执冻结的字节,并带上已保存的拆分计划。
|
|
20
|
+
|
|
8
21
|
## 0.21.4 — 2026-11-24
|
|
9
22
|
|
|
10
23
|
0.21.3 未能发布到 npm(发布中断后该版本号被 npm 占用),内容原样改用 0.21.4 发布。
|
package/README.md
CHANGED
|
@@ -17,7 +17,12 @@
|
|
|
17
17
|
|
|
18
18
|
## 最近更新
|
|
19
19
|
|
|
20
|
-
**0.21.
|
|
20
|
+
**0.21.6**
|
|
21
|
+
|
|
22
|
+
- **修复 Claude 兼容安装下技能里的文档链接失效**:技能里指向 `docs/` 的链接装完后能打开;`cm-check` 新增链接可达检查,不会误查你自己装的技能。
|
|
23
|
+
- **修复 `cm-check` 被大文件误阻断**:技能目录里有超过 1MB 的文本(如其他技能自带的压缩脚本)时不再启动即报 `init_draft_target_invalid`,阻断信息会指出具体文件。详见[更新日志](CHANGELOG.md)。
|
|
24
|
+
|
|
25
|
+
**0.21.5**
|
|
21
26
|
|
|
22
27
|
- **cm-ai 新任务支持软链**:项目里有软链不再一建基线就报错;开发可以新建、改指向或删除软链,CM 会核对它不指出项目、不指进 `.git` 和规格目录。已有任务不受影响。
|
|
23
28
|
- **当前会话运行可放宽单次调用期限**:设备检查等耗时长的步骤,可用 `--call-timeout-minutes`(30–60)放宽,已因超时停下的运行恢复时可补上。
|
|
@@ -293,7 +298,7 @@ $cm-check
|
|
|
293
298
|
|
|
294
299
|
仓库直接分发 Skills 和脚本,无需在仓库根目录运行 `npm install` 或构建。完整安装行为、覆盖范围和卸载说明见[安装指南](docs/installation.md)。
|
|
295
300
|
|
|
296
|
-
需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.21.
|
|
301
|
+
需要固定版本时可使用 `npx @aibyzero/cm-workflow@0.21.6 install`,请在 CM Workflow 源码仓库以外的目录执行,例如用户主目录。npm 安装入口复用原安装器,要求与覆盖范围见[安装指南](docs/installation.md#npm-installation-macos-codex)。
|
|
297
302
|
|
|
298
303
|
## 升级旧版本
|
|
299
304
|
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.21.
|
|
1
|
+
0.21.6
|
package/docs/installation.md
CHANGED
|
@@ -76,7 +76,7 @@ Install or upgrade with the same command:
|
|
|
76
76
|
npx @aibyzero/cm-workflow@latest install
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
To pin a version, use `npx @aibyzero/cm-workflow@0.21.
|
|
79
|
+
To pin a version, use `npx @aibyzero/cm-workflow@0.21.6 install` from outside
|
|
80
80
|
the CM Workflow source checkout (for example, your home directory). Inside a
|
|
81
81
|
checkout with the same package name and version, npm can select the local
|
|
82
82
|
uninstalled package and report `cm-workflow: command not found`.
|
|
@@ -1765,6 +1765,7 @@ evidenceDigest绑定完整feature清单、原状态文件和精确规格/审查
|
|
|
1765
1765
|
在改规格前写不可覆盖的`.reviews/prd-{slug}-{stage}-correction.md`,保存原文件正文、原包身份和逐项提案;它是私有host报告,不是批准或处置回执。每次替换前核对原r1精确SHA、原gate仍待处置及全部文件当前hash,0600临时文件替换后fsync/回读;失败保留correction_save_unknown现场,不回滚或重新生成。既有归档返回correction_recovery_required,须走下方显式恢复入口。correction_saved返回decisions/artifacts供上方原自检与处置,不完成审批。当前仅证明临时CLI产品代码完成原稿保存→修订写入→自检→原处置,宿主提案/自检/review仍为合成响应,未做真实语义验收。
|
|
1766
1766
|
`{requestId,operation:"inspect_correction",stage,feature}`只读原v1修订档案:严格UTF8、精确字节重构、原包/feature/stage、完整原文件sha和正文、逐项处置及机械检查后,对当前文件标记matches_correction或needs_correction。只接受原稿或档案修订稿;第三种内容/不安全路径/权限异常直接拒绝。此只读入口在人审停点后也可用。
|
|
1767
1767
|
`{requestId,operation:"resume_correction",stage,feature}`须同样显式启用spec和review写入,只补原档案未完成写入;复用初次写入函数,逐步核对档案/r1/gate/所有文件版本,已匹配文件不重写,已完成处置不得再补改。没有宿主生成或review调用;新进程可读取同一v1档案继续。已完整写入时返回原decisions/artifacts,原处置已完成则提示检查旧回执;这不是审批或新的自检证明。测试重建了全未写和多文件部分写入前缀并由新Node进程补齐,不等于断电/跨平台验收。无档案调用中断、修正自检轮次和完整会话恢复仍待收口。
|
|
1768
|
+
设计阶段窄审轮次(2026-11-24,仅新运行):原修正保存后,`{requestId,operation:"narrow_review",stage:"design",feature,packageDigest,round,designSha256,reviewer,sessionId,independent,at,verdict,summary,findings}` 在同一原 packageDigest 下写不可覆盖的 `.reviews/prd-{slug}-design-narrow-review-rN.json`;`narrow_status` 只读。链为 原修正档案→窄审1→修正1→窄审2,每份记录绑定上一份的摘要与被审 design.md 的 SHA;修正档案 `...-narrow-correction-rN.md` 绑定所答复的审查摘要并保存逐项处置。第 3 轮报 `prd_narrow_round_limit`;第 2 轮仍有阻断→`awaiting_user_decision`,修正、再审与 `review_disposition` 均拒绝,不自动放行。有窄审记录时 `review_disposition` 须窄审 approved(`prd_narrow_review_pending`);无窄审记录与旧流程完全一致。审查模型不可用时可记 `reviewer:"self-degraded"` 降级轮(须 `degradedReason`、`sessionId`=宿主作者上下文、`independent:false`):仅留痕,降级 approved 进入 `awaiting_user_decision` 不放行。若还剩一轮,可对同一份设计再记一轮独立审查(链到降级记录,不得降级、不得复用降级会话)后放行。split 阶段不扩展:已有强制自检,且改动含任务文件,评估后本次不做。
|
|
1768
1769
|
|
|
1769
1770
|
宿主启动时显式追加`--allow-review-write --host-context {真实作者上下文ID}`后,自检报告通过可发`{requestId,operation:"final_review",stage:"design"|"split",feature:"1.slug",mode:"independent"|"self-degraded"}`。这只启用原dispatch/r1写入,不授权provider/CLI启动或外发;当前宿主仍须有真实审查通道权限。独立/降级模式在占用前选定,占用后不能切换补审。
|
|
1770
1771
|
`review-host.mjs`串联重新准备/核对原包→原claim→`prd_review`宿主请求→再核对→原r1发布。请求给出精确packageDigest/examinedPaths、真实作者ID、代码项目及steelman-review参考;宿主核实真实独立上下文并原样转交结果,不得自行伪造来源。取消/status沿同一JSONL控制通道,reviewState单独展示审查进度。
|
package/install.ps1
CHANGED
|
@@ -114,6 +114,9 @@ try {
|
|
|
114
114
|
Stage-Tree (Join-Path $Src "docs") "cm-workflow\docs"
|
|
115
115
|
Stage-Tree (Join-Path $Src "assets") "cm-workflow\assets"
|
|
116
116
|
Stage-File (Join-Path $Src "README.md") "cm-workflow\README.md"
|
|
117
|
+
# docs 装在 cm-workflow\docs,技能里的 ../docs/ 相对链接要跟着改写。
|
|
118
|
+
node (Join-Path $Src "scripts\cm-rewrite-doc-links.mjs") $Stage | Out-Null
|
|
119
|
+
if ($LASTEXITCODE -ne 0) { throw "改写文档链接失败。" }
|
|
117
120
|
|
|
118
121
|
foreach ($pair in @(
|
|
119
122
|
@("dashboard", "dashboard"),
|
package/install.sh
CHANGED
|
@@ -374,6 +374,8 @@ done
|
|
|
374
374
|
stage_tree "$SRC_DIR/docs" "cm-workflow/docs"
|
|
375
375
|
stage_tree "$SRC_DIR/assets" "cm-workflow/assets"
|
|
376
376
|
stage_file "$SRC_DIR/README.md" "cm-workflow/README.md"
|
|
377
|
+
# docs 装在 cm-workflow/docs/,技能里的 ../docs/ 相对链接要跟着改写。
|
|
378
|
+
node "$SRC_DIR/scripts/cm-rewrite-doc-links.mjs" "$STAGE" >/dev/null || { echo "改写文档链接失败,安装已停止,未修改任何文件。" >&2; exit 1; }
|
|
377
379
|
|
|
378
380
|
for wrapper in "$SRC_DIR"/compat/claude-commands/cm-*.md; do
|
|
379
381
|
name="$(basename "$wrapper" .md)"
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@ export function parseHostInputLimit(raw){
|
|
|
17
17
|
return value;
|
|
18
18
|
}
|
|
19
19
|
const operationNames=new Set(['prepare_diagnosis_module_correction','revision_test_check','prepare_test_type_correction','prepare_command_correction','prepare_verification_recovery','repair_review_response','reconcile_review','retry_review','rediagnose','replace_inputs','read_batch','recover_final_review','abandon_step','abandon_review','rerun_blocked_step','abandon_effect','bootstrap_review_recover','completion_rework','development_rework','revise_scope','develop_redo','advance','start','plan_design','promote_design','select_design_reviews','status','fix_status','fix_advance','fix_action','fix_run','decision','complete','qa','qa_result','prepare_revision','prepare_save',
|
|
20
|
-
'context_refresh','finish','completion_evidence','run_finalize','review_findings','review_disposition','save_draft','save_design','correct_findings','prepare_summary','publish_summary','inspect_correction','resume_correction','cancel','resume','prepare_judge_revision','cause_review_package','cause_review','red_test','baseline','author_tests','repair','regression','retrospective','learning_writeback','handoff','final_review_package','final_review','publish_review','check_n5','post_review_regression','publish_dossier','walkthrough']);
|
|
20
|
+
'context_refresh','finish','completion_evidence','run_finalize','review_findings','review_disposition','save_draft','save_design','correct_findings','prepare_summary','publish_summary','inspect_correction','resume_correction','narrow_review','narrow_status','cancel','resume','prepare_judge_revision','cause_review_package','cause_review','red_test','baseline','author_tests','repair','regression','retrospective','learning_writeback','handoff','final_review_package','final_review','publish_review','check_n5','post_review_regression','publish_dossier','walkthrough']);
|
|
21
21
|
|
|
22
22
|
// Which contract codes may reach the peer is a deliberate boundary: the host
|
|
23
23
|
// exposes chosen ones as a blocked result with a reason and redacts the rest to
|
|
@@ -6,8 +6,17 @@ import {createCmCheckInvocation} from '../../../scripts/cm-check-entry.mjs';
|
|
|
6
6
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
7
7
|
import {need,shape,json,digest} from '../cm-ai/effect-contract.mjs';
|
|
8
8
|
|
|
9
|
-
const directories=['skills','runtime','agents','compat/claude-commands','templates','scripts','.codex-plugin'];
|
|
10
|
-
const topFiles=['VERSION','README.md','package.json','install.sh','install.ps1','install-codex.sh','install-codex.ps1'];
|
|
9
|
+
const directories=['skills','runtime','agents','compat/claude-commands','templates','scripts','.codex-plugin','docs','cm-workflow/docs'];
|
|
10
|
+
const topFiles=['cm-workflow/doc-links-scope.txt','VERSION','README.md','package.json','install.sh','install.ps1','install-codex.sh','install-codex.ps1'];
|
|
11
|
+
const READ_LIMIT=1048576; // 与 readCmInitSource 的单文件上限一致
|
|
12
|
+
const OVERSIZE_HASH_LIMIT=16*1024*1024;
|
|
13
|
+
function readOversize(file,size){
|
|
14
|
+
const fd=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
15
|
+
try{
|
|
16
|
+
const opened=fs.fstatSync(fd);need(opened.isFile()&&opened.nlink===1&&opened.size===size,'check_source_changed');
|
|
17
|
+
const bytes=Buffer.alloc(size);need(fs.readSync(fd,bytes,0,size,0)===size,'check_source_changed');return bytes;
|
|
18
|
+
}finally{fs.closeSync(fd);}
|
|
19
|
+
}
|
|
11
20
|
const optionalIds=['statusline','updater','subagents','isolated_review','external_browser'];
|
|
12
21
|
// Groups 1 and 7 inspect the Codex plugin manifest, the root VERSION and the root README.
|
|
13
22
|
// A Claude-compatible installation legitimately owns none of them, so only these two may be
|
|
@@ -24,14 +33,27 @@ function snapshot(root){
|
|
|
24
33
|
if(stat.isDirectory()){
|
|
25
34
|
need(fs.realpathSync(target)===target,'check_source_path_changed');
|
|
26
35
|
files[relative]={directory:true};
|
|
27
|
-
|
|
36
|
+
let names;
|
|
37
|
+
try{names=fs.readdirSync(target).sort();}catch(error){if(error&&typeof error==='object')error.file=relative;throw error;}
|
|
38
|
+
for(const name of names)visit(relative+'/'+name);
|
|
28
39
|
}else{
|
|
29
40
|
need(stat.isFile()&&stat.nlink===1,'check_source_file_invalid');
|
|
30
|
-
|
|
41
|
+
// 超过 readCmInitSource 单文件上限(1MB)的文本(如非 CM 技能自带的 babel.min.js,约 3MB)不再走它,
|
|
42
|
+
// 否则整次检查会以 init_draft_target_invalid 阻断(2026-11 反馈:~/.claude/skills/huashu-design)。
|
|
43
|
+
// 仍要发现检查期间的改动:16MB 内的按内容算摘要,更大的只记大小与修改时间。
|
|
44
|
+
const text=/\.(?:md|mjs|js|json|ya?ml|py|sh|ps1|toml|txt|ts|css|html)$/.test(relative)||relative==='VERSION';
|
|
45
|
+
if(text&&stat.size<=READ_LIMIT){
|
|
31
46
|
bytes+=stat.size;need(bytes<=64*1024*1024,'check_inventory_limit');
|
|
32
|
-
|
|
47
|
+
let data;
|
|
48
|
+
try{data=readCmInitSource(root,relative);need(data!==null,'check_source_changed');}
|
|
49
|
+
catch(error){if(error&&typeof error==='object')error.file=relative;throw error;}
|
|
33
50
|
files[relative]={digest:digest(data.toString('base64')),lines:data.toString('utf8').split('\n').length};
|
|
34
|
-
}else
|
|
51
|
+
}else if(text&&stat.size<=OVERSIZE_HASH_LIMIT){
|
|
52
|
+
bytes+=stat.size;need(bytes<=64*1024*1024,'check_inventory_limit');
|
|
53
|
+
let data;
|
|
54
|
+
try{data=readOversize(target,stat.size);}catch(error){if(error&&typeof error==='object')error.file=relative;throw error;}
|
|
55
|
+
files[relative]={size:stat.size,mode:stat.mode&0o777,oversized:true,digest:digest(data.toString('base64')),lines:data.toString('utf8').split('\n').length};
|
|
56
|
+
}else files[relative]={size:stat.size,mode:stat.mode&0o777,...(text?{oversized:true,mtimeMs:stat.mtimeMs,ctimeMs:stat.ctimeMs}:{})};
|
|
35
57
|
}
|
|
36
58
|
}
|
|
37
59
|
for(const relative of [...directories,...topFiles])visit(relative);
|
|
@@ -51,7 +73,14 @@ export function createCmCheckHost(raw,{call}){
|
|
|
51
73
|
return {...source,digest:digest({source:source.digest,configs})};
|
|
52
74
|
};
|
|
53
75
|
const status=()=>json({stage,mechanical,result,completionAuthorized:false});
|
|
54
|
-
const current=baseline=>
|
|
76
|
+
const current=baseline=>{
|
|
77
|
+
const now=capture();
|
|
78
|
+
if(now.digest===baseline.digest)return;
|
|
79
|
+
const e=new Error('check_source_changed');e.code='check_source_changed';
|
|
80
|
+
const keys=[...new Set([...Object.keys(baseline.files),...Object.keys(now.files)])].sort();
|
|
81
|
+
const file=keys.find(k=>JSON.stringify(baseline.files[k])!==JSON.stringify(now.files[k]));
|
|
82
|
+
if(file)e.file=file;throw e;
|
|
83
|
+
};
|
|
55
84
|
async function start(){
|
|
56
85
|
need(stage==='ready','check_already_started');stage='mechanical';
|
|
57
86
|
try{
|
|
@@ -110,7 +139,7 @@ export function createCmCheckHost(raw,{call}){
|
|
|
110
139
|
findingsCount:assessment.checks.filter(row=>row.status==='failed').reduce((sum,row)=>sum+row.findings.length,0),
|
|
111
140
|
semanticChecked:true,completionAuthorized:false};
|
|
112
141
|
stage='reported';return status();
|
|
113
|
-
}catch(error){stage=controller.signal.aborted?'cancelled':'blocked';result={overall:'BLOCKED',reason:error?.code??'check_failed',completionAuthorized:false};return status();}
|
|
142
|
+
}catch(error){stage=controller.signal.aborted?'cancelled':'blocked';result={overall:'BLOCKED',reason:error?.code??'check_failed',...(typeof error?.file==='string'?{file:error.file}:{}),completionAuthorized:false};return status();}
|
|
114
143
|
}
|
|
115
144
|
return Object.freeze({async handle(request){
|
|
116
145
|
shape(request,['requestId','operation']);
|
|
@@ -4,6 +4,7 @@ import {inspectPrdSplitDesign} from './split-design.mjs';
|
|
|
4
4
|
import {TextDecoder} from 'node:util';
|
|
5
5
|
import {createHash} from 'node:crypto';
|
|
6
6
|
import {inspectPrdFindings} from './review-findings.mjs';
|
|
7
|
+
import {assertPrdNarrowDispositionReady} from './review-correction.mjs';
|
|
7
8
|
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
8
9
|
import {prdFeatureInventory} from './draft.mjs';
|
|
9
10
|
import {inspectPrdDesignRiskSelection,requireUnreviewedPrdDesign} from './design-risk.mjs';
|
|
@@ -45,6 +46,9 @@ export function inspectAcceptedPrdDesign(specs,original,selection=null,{draftDig
|
|
|
45
46
|
const receiptBytes=readCmInitSource(specs,receiptPath),receipt=JSON.parse(receiptBytes.toString('utf8'));
|
|
46
47
|
need(receipt.artifacts.length===1&&receipt.artifacts[0].path===`${feature.directory}/design.md`,
|
|
47
48
|
'prd_design_receipt_scope_invalid');
|
|
49
|
+
// A receipt written by any path still needs the recorded narrow review chain to have approved the receipt's bytes;
|
|
50
|
+
// a saved split correction may have changed design.md since, which the checks below bind separately.
|
|
51
|
+
assertPrdNarrowDispositionReady({specs,feature:feature.directory,pendingSplit,designSha256:receipt.artifacts[0].sha256});
|
|
48
52
|
need(review.reviewedArtifacts.length===2,'prd_design_review_scope_invalid');
|
|
49
53
|
const documents=feature.documents.map(doc=>{
|
|
50
54
|
const relative=`${feature.directory}/${doc.path}`,bytes=readCmInitSource(specs,relative);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Shared finding-to-artifact accounting for proposal and recorded disposition.
|
|
2
2
|
import {need,shape,json} from '../cm-ai/effect-contract.mjs';
|
|
3
|
-
|
|
3
|
+
// alsoChanged: paths a recorded narrow review chain legitimately changed after the original decisions.
|
|
4
|
+
export function inspectPrdDispositionPlan(review,rawDecisions,rawArtifacts,{alsoChanged=[]}={}){
|
|
4
5
|
const decisions=json(rawDecisions,64*1024),artifacts=json(rawArtifacts,64*1024);
|
|
5
6
|
need(Array.isArray(decisions)&&decisions.length===review.findings.length,'prd_disposition_coverage');
|
|
6
7
|
const originals=new Map(review.reviewedArtifacts.map(item=>[item.path,item.sha256]));
|
|
@@ -27,7 +28,8 @@ export function inspectPrdDispositionPlan(review,rawDecisions,rawArtifacts){
|
|
|
27
28
|
shape(item,['path','sha256']);
|
|
28
29
|
need(originals.has(item.path)&&!seen.has(item.path)&&typeof item.sha256==='string'
|
|
29
30
|
&&/^[0-9a-f]{64}$/.test(item.sha256),'prd_disposition_artifact_inventory');seen.add(item.path);
|
|
30
|
-
|
|
31
|
+
const differs=originals.get(item.path)!==item.sha256;
|
|
32
|
+
need(differs===changed.has(item.path)||(differs&&alsoChanged.includes(item.path)),'prd_disposition_unaccounted_change');
|
|
31
33
|
}
|
|
32
34
|
return {decisions,artifacts,changed,unresolved};
|
|
33
35
|
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Design-stage narrow review rounds after the single original correction.
|
|
2
|
+
// Evidence only: it never dispatches a reviewer, approves a spec or completes a gate.
|
|
3
|
+
// Chain per original package: original correction archive -> N1 -> (C1) -> N2.
|
|
4
|
+
// Every correction needs the recorded review it answers; a correction is never the
|
|
5
|
+
// last step, so no unreviewed bytes reach the original disposition (2026-11-24: the
|
|
6
|
+
// third design version after a narrow review could not enter CM).
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import {createHash} from 'node:crypto';
|
|
10
|
+
import {TextDecoder} from 'node:util';
|
|
11
|
+
import {readCmInitSource} from '../cm-init/draft-inspection.mjs';
|
|
12
|
+
import {writeImmutableWorkflowFile} from '../cm-ai/review-evidence-file.mjs';
|
|
13
|
+
import {need,json,shape,digest,id} from '../cm-ai/effect-contract.mjs';
|
|
14
|
+
import {inspectPrdDispositionPlan} from './disposition-plan.mjs';
|
|
15
|
+
|
|
16
|
+
export const PRD_NARROW_MAX_ROUNDS=2;
|
|
17
|
+
const PRD_NARROW_SCAN_ROUNDS=8; // stray files of any later round name are refused, not ignored
|
|
18
|
+
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
19
|
+
const FLAGS=['security','dataLoss','silentFailure','violatesWrittenRule'];
|
|
20
|
+
const SEVERITIES=['blocker','major','minor'];
|
|
21
|
+
const FINDING_KEYS=['id','severity',...FLAGS,'scenario','message'];
|
|
22
|
+
const REVIEW_KEYS=['version','kind','feature','packageDigest','round','priorDigest','designSha256','reviewer','sessionId',
|
|
23
|
+
'independent','at','verdict','summary','findings'];
|
|
24
|
+
const hex=value=>typeof value==='string'&&/^[a-f0-9]{64}$/.test(value);
|
|
25
|
+
|
|
26
|
+
export function narrowNames(feature){
|
|
27
|
+
const name=feature.replace(/^\d+\./,'');
|
|
28
|
+
return {review:round=>`prd-${name}-design-narrow-review-r${round}.json`,
|
|
29
|
+
correction:round=>`prd-${name}-design-narrow-correction-r${round}.md`};
|
|
30
|
+
}
|
|
31
|
+
// Reviewer's grade plus four yes/no answers decide blocking; the author cannot reclassify.
|
|
32
|
+
export const isBlockingNarrowFinding=item=>item.severity!=='minor'||FLAGS.some(flag=>item[flag]===true);
|
|
33
|
+
|
|
34
|
+
const permissions=file=>need((fs.lstatSync(file).mode&0o777)===0o600,'prd_narrow_file_permissions');
|
|
35
|
+
function readFileBytes(specs,name){
|
|
36
|
+
const bytes=readCmInitSource(specs,`.reviews/${name}`);
|
|
37
|
+
if(bytes===null)return null;permissions(path.join(specs,'.reviews',name));return bytes;
|
|
38
|
+
}
|
|
39
|
+
// Any unexpected read failure (dangling link, unreadable file) becomes the fixed invalid-record code.
|
|
40
|
+
const guarded=read=>(...args)=>{try{return read(...args);}catch(error){
|
|
41
|
+
throw typeof error?.code==='string'&&error.code.startsWith('prd_narrow_')?error:Object.assign(new Error('prd_narrow_record_invalid'),{code:'prd_narrow_record_invalid'});}};
|
|
42
|
+
const readReview=guarded(function readReview(specs,name){
|
|
43
|
+
const bytes=readFileBytes(specs,name);if(bytes===null)return null;
|
|
44
|
+
const value=json(JSON.parse(new TextDecoder('utf-8',{fatal:true,ignoreBOM:true}).decode(bytes)),128*1024);
|
|
45
|
+
need(Buffer.from(JSON.stringify(value)+'\n').equals(bytes),'prd_narrow_record_invalid');return value;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export function narrowCorrectionBytes(value){
|
|
49
|
+
return Buffer.from('# Narrow design review correction\n\nNot review approval or completion. Private host-attested material.\n```json\n'
|
|
50
|
+
+JSON.stringify(value)+'\n```\n');
|
|
51
|
+
}
|
|
52
|
+
const readCorrection=guarded(function readCorrection(specs,name){
|
|
53
|
+
const bytes=readFileBytes(specs,name);if(bytes===null)return null;
|
|
54
|
+
const match=new TextDecoder('utf-8',{fatal:true,ignoreBOM:true}).decode(bytes).match(/\n```json\n([^\n]+)\n```\n$/);
|
|
55
|
+
need(match,'prd_narrow_record_invalid');
|
|
56
|
+
const value=json(JSON.parse(match[1]),256*1024);need(narrowCorrectionBytes(value).equals(bytes),'prd_narrow_record_invalid');
|
|
57
|
+
return {value,bytes};
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
function validateFindings(findings){
|
|
61
|
+
need(Array.isArray(findings)&&findings.length<=60,'prd_narrow_findings_invalid');const ids=new Set();
|
|
62
|
+
for(const item of findings){
|
|
63
|
+
shape(item,FINDING_KEYS);
|
|
64
|
+
need(typeof item.id==='string'&&/^[A-Za-z0-9][A-Za-z0-9._-]{0,39}$/.test(item.id)&&!ids.has(item.id),'prd_narrow_findings_invalid');ids.add(item.id);
|
|
65
|
+
need(SEVERITIES.includes(item.severity)&&FLAGS.every(flag=>typeof item[flag]==='boolean'),'prd_narrow_findings_invalid');
|
|
66
|
+
need(typeof item.message==='string'&&item.message.trim()&&item.message.length<=2000&&typeof item.scenario==='string'
|
|
67
|
+
&&item.scenario.length<=2000,'prd_narrow_findings_invalid');
|
|
68
|
+
// A blocking finding must name the concrete trigger; without one it is a suggestion.
|
|
69
|
+
need(!isBlockingNarrowFinding(item)||item.scenario.trim(),'prd_narrow_blocking_scenario_required');
|
|
70
|
+
}
|
|
71
|
+
return findings;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function validateReviewRecord(value,{feature,packageDigest,round,priorDigest,designSha}){
|
|
75
|
+
const degraded=value?.reviewer==='self-degraded';
|
|
76
|
+
shape(value,degraded?[...REVIEW_KEYS,'degradedReason']:REVIEW_KEYS);
|
|
77
|
+
need(value.version===1&&value.kind==='prd_design_narrow_review'&&value.feature===feature&&value.packageDigest===packageDigest
|
|
78
|
+
&&value.round===round&&value.priorDigest===priorDigest&&value.designSha256===designSha,'prd_narrow_record_invalid');
|
|
79
|
+
// A degraded round (the review model was unavailable, the author model reviewed) is evidence only: it declares
|
|
80
|
+
// itself, carries the reason, and can never be the approving round (see inspectPrdNarrowState).
|
|
81
|
+
need(typeof value.reviewer==='string'&&value.reviewer.trim()&&(degraded?value.independent===false
|
|
82
|
+
&&typeof value.degradedReason==='string'&&value.degradedReason.trim()&&value.degradedReason.length<=1000:value.independent===true),
|
|
83
|
+
'prd_narrow_reviewer_not_independent');
|
|
84
|
+
id(value.sessionId);
|
|
85
|
+
need(typeof value.at==='string'&&/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?Z$/.test(value.at)&&!Number.isNaN(Date.parse(value.at)),'prd_narrow_record_invalid');
|
|
86
|
+
need(typeof value.summary==='string'&&value.summary.trim()&&value.summary.length<=4000,'prd_narrow_record_invalid');
|
|
87
|
+
validateFindings(value.findings);
|
|
88
|
+
const blocking=value.findings.filter(isBlockingNarrowFinding).length;
|
|
89
|
+
need(value.verdict==='approved'?blocking===0:value.verdict==='changes_requested'&&blocking>0,'prd_narrow_verdict_findings_mismatch');
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// base: {designSha256 (design.md after the original correction), originalDesignSha256, archiveSha256}.
|
|
94
|
+
export function inspectPrdNarrowState({specs,feature,packageDigest,base,currentDesignSha256}){
|
|
95
|
+
need(hex(packageDigest)&&hex(base.designSha256)&&hex(base.archiveSha256)&&hex(base.requirementsSha256)&&hex(currentDesignSha256),'prd_narrow_binding_invalid');
|
|
96
|
+
const degradedSessions=new Set(),names=narrowNames(feature),rounds=[];let tip=base.designSha256,prior=base.archiveSha256,phase=null,last=null;
|
|
97
|
+
for(let round=1;round<=PRD_NARROW_MAX_ROUNDS;round++){
|
|
98
|
+
const review=readReview(specs,names.review(round)),correction=readCorrection(specs,names.correction(round));
|
|
99
|
+
if(review===null){need(correction===null,'prd_narrow_record_invalid');phase={status:'awaiting_review',round};break;}
|
|
100
|
+
validateReviewRecord(review,{feature,packageDigest,round,priorDigest:prior,designSha:tip});
|
|
101
|
+
// Read-back enforces the same independence the writer does: an independent record never reuses the original
|
|
102
|
+
// author's context or a context that signed a degraded round.
|
|
103
|
+
if(review.reviewer==='self-degraded')degradedSessions.add(review.sessionId);
|
|
104
|
+
else need(review.sessionId!==base.authorContextId&&!degradedSessions.has(review.sessionId),'prd_narrow_reviewer_not_independent');
|
|
105
|
+
const row={round,review,reviewDigest:digest(review),correction:null};rounds.push(row);
|
|
106
|
+
if(review.verdict==='approved'){
|
|
107
|
+
need(correction===null,'prd_narrow_record_invalid');
|
|
108
|
+
// Only an independent approval releases the design; a degraded one stops for the user.
|
|
109
|
+
if(review.reviewer!=='self-degraded'){phase={status:'approved',round};break;}
|
|
110
|
+
// Degraded approval never releases. While a round remains, one independent review of the same bytes may follow
|
|
111
|
+
// (chained to the degraded record) once the review model is back.
|
|
112
|
+
if(round<PRD_NARROW_MAX_ROUNDS){
|
|
113
|
+
prior=sha(Buffer.from(JSON.stringify(review)+'\n'));
|
|
114
|
+
if(readReview(specs,names.review(round+1))!==null)continue;
|
|
115
|
+
}
|
|
116
|
+
phase={status:'awaiting_user_decision',round,reason:'degraded_review_only',
|
|
117
|
+
independentFollowUpAllowed:round<PRD_NARROW_MAX_ROUNDS};break;
|
|
118
|
+
}
|
|
119
|
+
if(round===PRD_NARROW_MAX_ROUNDS){
|
|
120
|
+
need(correction===null,'prd_narrow_record_invalid');phase={status:'awaiting_user_decision',round};break;
|
|
121
|
+
}
|
|
122
|
+
if(correction===null){phase={status:'awaiting_correction',round};break;}
|
|
123
|
+
const value=correction.value;
|
|
124
|
+
shape(value,['version','kind','feature','packageDigest','round','narrowReviewDigest','beforeSha256','afterSha256','before','proposal']);
|
|
125
|
+
need(value.version===1&&value.kind==='prd_design_narrow_correction'&&value.feature===feature&&value.packageDigest===packageDigest
|
|
126
|
+
&&value.round===round&&value.narrowReviewDigest===row.reviewDigest&&value.beforeSha256===tip&&hex(value.afterSha256)
|
|
127
|
+
&&Array.isArray(value.before),'prd_narrow_record_invalid');
|
|
128
|
+
// The archived per-finding decisions must still satisfy the same plan rules as when they were saved.
|
|
129
|
+
const design=`${feature}/design.md`;
|
|
130
|
+
try{
|
|
131
|
+
const proposed=value.proposal;shape(proposed,['decisions','documents']);need(Array.isArray(proposed.documents),'x');
|
|
132
|
+
const requirements=`${feature}/requirements.md`,after=proposed.documents.find(item=>item.path===design);
|
|
133
|
+
// The archived originals must be exactly what the chain reviewed: this round's design tip and the unchanged requirements.
|
|
134
|
+
need(value.before.length===2&&proposed.documents.length===2,'x');
|
|
135
|
+
const beforeDesign=value.before.find(item=>item.path===design),beforeRequirements=value.before.find(item=>item.path===requirements);
|
|
136
|
+
need(beforeDesign&&beforeRequirements&&beforeDesign.sha256===tip&&sha(Buffer.from(beforeDesign.content))===tip
|
|
137
|
+
&&beforeRequirements.sha256===base.requirementsSha256&&sha(Buffer.from(beforeRequirements.content))===base.requirementsSha256,'x');
|
|
138
|
+
const requirementsAfter=proposed.documents.find(item=>item.path===requirements);
|
|
139
|
+
need(requirementsAfter&&sha(Buffer.from(requirementsAfter.content))===base.requirementsSha256,'x');
|
|
140
|
+
const doc=after;need(doc&&sha(Buffer.from(doc.content))===value.afterSha256,'x');
|
|
141
|
+
inspectPrdDispositionPlan({stage:'design',feature,findings:review.findings,
|
|
142
|
+
reviewedArtifacts:value.before.map(item=>({path:item.path,sha256:item.sha256}))},proposed.decisions,
|
|
143
|
+
value.before.map(item=>({path:item.path,sha256:item.path===design?value.afterSha256:item.sha256})));
|
|
144
|
+
}catch{need(false,'prd_narrow_record_invalid');}
|
|
145
|
+
row.correction=value;last=value;tip=value.afterSha256;prior=sha(correction.bytes);
|
|
146
|
+
}
|
|
147
|
+
// Nothing may exist beyond the chain's current phase (a dangling or stray later round is never ignored).
|
|
148
|
+
const exists=name=>{try{fs.lstatSync(path.join(specs,'.reviews',name));return true;}catch(error){if(error.code==='ENOENT')return false;return true;}};
|
|
149
|
+
for(let round=1;round<=PRD_NARROW_SCAN_ROUNDS;round++){
|
|
150
|
+
need(round<=rounds.length||!exists(names.review(round)),'prd_narrow_record_invalid');
|
|
151
|
+
need(rounds[round-1]?.correction||!exists(names.correction(round)),'prd_narrow_record_invalid');
|
|
152
|
+
}
|
|
153
|
+
if(currentDesignSha256!==tip){
|
|
154
|
+
// Only a crash between the durable archive and the design write may differ, and
|
|
155
|
+
// only before the next review exists.
|
|
156
|
+
if(phase.status==='awaiting_review'&&last!==null&&phase.round===last.round+1&¤tDesignSha256===last.beforeSha256)
|
|
157
|
+
phase={status:'correction_incomplete',round:last.round};
|
|
158
|
+
else need(false,rounds.length===0&¤tDesignSha256===base.originalDesignSha256&&base.originalDesignSha256!==base.designSha256
|
|
159
|
+
?'prd_narrow_original_correction_incomplete':'prd_narrow_design_changed');
|
|
160
|
+
}
|
|
161
|
+
return {feature,packageDigest,phase,rounds,tipDesignSha256:tip,priorDigest:prior,currentDesignSha256};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function narrowPublicState(state){
|
|
165
|
+
const nextByPhase={awaiting_review:`record_narrow_review_r${state.phase.round}`,awaiting_correction:'correct_findings',
|
|
166
|
+
correction_incomplete:'correct_findings',approved:'review_disposition',awaiting_user_decision:'user_decision_required'};
|
|
167
|
+
return {status:'narrow_state',feature:state.feature,packageDigest:state.packageDigest,maxRounds:PRD_NARROW_MAX_ROUNDS,
|
|
168
|
+
phase:state.phase,designSha256:state.currentDesignSha256,
|
|
169
|
+
rounds:state.rounds.map(({round,review,reviewDigest,correction})=>({round,verdict:review.verdict,reviewer:review.reviewer,
|
|
170
|
+
sessionId:review.sessionId,reviewDigest,findingCount:review.findings.length,
|
|
171
|
+
blockingCount:review.findings.filter(isBlockingNarrowFinding).length,corrected:correction!==null,
|
|
172
|
+
degraded:review.reviewer==='self-degraded'})),
|
|
173
|
+
next:state.phase.independentFollowUpAllowed?`record_independent_narrow_review_r${state.phase.round+1}`:nextByPhase[state.phase.status],
|
|
174
|
+
independentFollowUpAllowed:state.phase.independentFollowUpAllowed===true,userDecisionRequired:state.phase.status==='awaiting_user_decision',
|
|
175
|
+
autoReleaseAllowed:false,completionAuthorized:false};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// The caller (review-correction) supplies the original-correction base and the
|
|
179
|
+
// current design bytes; this writes exactly one new round record, never overwrites.
|
|
180
|
+
export function recordPrdNarrowReview({specs,feature,packageDigest,state,input,authorContextId,originalAuthorContextId,writeEnabled}){
|
|
181
|
+
need(writeEnabled===true,'prd_narrow_not_enabled');
|
|
182
|
+
need(typeof authorContextId==='string','prd_review_host_context_required');
|
|
183
|
+
const degraded=input?.reviewer==='self-degraded';
|
|
184
|
+
shape(input,['round','designSha256','reviewer','sessionId','independent','at','verdict','summary','findings',...(degraded?['degradedReason']:[])]);
|
|
185
|
+
need(Number.isInteger(input.round)&&input.round>=1,'prd_narrow_round_invalid');
|
|
186
|
+
need(input.round<=PRD_NARROW_MAX_ROUNDS,'prd_narrow_round_limit');
|
|
187
|
+
const status=state.phase.status;
|
|
188
|
+
// After a degraded approval one independent follow-up on the same bytes is the only way past the stop.
|
|
189
|
+
const followUp=status==='awaiting_user_decision'&&state.phase.independentFollowUpAllowed===true;
|
|
190
|
+
need(status!=='awaiting_user_decision'||followUp,'prd_narrow_awaiting_user_decision');
|
|
191
|
+
need(status!=='approved','prd_narrow_already_approved');
|
|
192
|
+
need(followUp?input.round===state.phase.round+1&&!degraded:status==='awaiting_review'&&state.phase.round===input.round,
|
|
193
|
+
followUp&°raded?'prd_narrow_reviewer_not_independent':'prd_narrow_round_out_of_order');
|
|
194
|
+
need(input.designSha256===state.currentDesignSha256,'prd_narrow_design_changed');
|
|
195
|
+
// Degraded: the author context itself reviews, so it must declare exactly that context.
|
|
196
|
+
need(degraded?input.sessionId===authorContextId:input.sessionId!==authorContextId&&input.sessionId!==originalAuthorContextId,'prd_narrow_reviewer_not_independent');
|
|
197
|
+
// A context that already signed a degraded (author-model) round can never later sign an independent one, whatever host resumed.
|
|
198
|
+
need(degraded||!state.rounds.some(row=>row.review.reviewer==='self-degraded'&&row.review.sessionId===input.sessionId),
|
|
199
|
+
'prd_narrow_reviewer_not_independent');
|
|
200
|
+
const value=validateReviewRecord({version:1,kind:'prd_design_narrow_review',feature,packageDigest,round:input.round,
|
|
201
|
+
priorDigest:state.priorDigest,designSha256:input.designSha256,reviewer:input.reviewer,sessionId:input.sessionId,
|
|
202
|
+
independent:input.independent,...(degraded?{degradedReason:input.degradedReason}:{}),at:input.at,verdict:input.verdict,summary:input.summary,findings:input.findings},
|
|
203
|
+
{feature,packageDigest,round:input.round,priorDigest:state.priorDigest,designSha:state.currentDesignSha256});
|
|
204
|
+
const bytes=Buffer.from(JSON.stringify(value)+'\n');
|
|
205
|
+
// The reader accepts at most 128 KiB; never write a record the host cannot read back.
|
|
206
|
+
need(bytes.length<=96*1024,'prd_narrow_record_too_large');
|
|
207
|
+
writeImmutableWorkflowFile({reviewsDir:path.join(specs,'.reviews'),name:narrowNames(feature).review(input.round),
|
|
208
|
+
bytes,validate:permissions,exclusive:true});
|
|
209
|
+
return value;
|
|
210
|
+
}
|