peaks-loop 4.1.11 → 4.1.13
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/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +88 -0
- package/README-en.md +1 -1
- package/README.md +1 -1
- package/dist/cli/commands/_register.js +2 -0
- package/dist/cli/commands/batch-commands.d.ts +6 -0
- package/dist/cli/commands/batch-commands.js +70 -0
- package/dist/cli/commands/batch-diagnose-command.d.ts +10 -0
- package/dist/cli/commands/batch-diagnose-command.js +196 -0
- package/dist/cli/commands/batch-diagnose-envelope.d.ts +25 -0
- package/dist/cli/commands/batch-diagnose-envelope.js +60 -0
- package/dist/cli/commands/batch-diagnose-record.d.ts +21 -0
- package/dist/cli/commands/batch-diagnose-record.js +51 -0
- package/dist/cli/commands/batch-item-input.d.ts +59 -0
- package/dist/cli/commands/batch-item-input.js +113 -0
- package/dist/cli/commands/batch-report-command.d.ts +22 -0
- package/dist/cli/commands/batch-report-command.js +199 -0
- package/dist/cli/commands/core/skill-context-verdict.d.ts +16 -1
- package/dist/cli/commands/core/skill-context-verdict.js +38 -8
- package/dist/cli/commands/lint-commands.js +8 -0
- package/dist/cli/commands/lint-rules-command.d.ts +14 -0
- package/dist/cli/commands/lint-rules-command.js +44 -0
- package/dist/services/batch/batch-active-batch.d.ts +55 -0
- package/dist/services/batch/batch-active-batch.js +127 -0
- package/dist/services/batch/batch-context-reminder.d.ts +85 -0
- package/dist/services/batch/batch-context-reminder.js +201 -0
- package/dist/services/batch/batch-diagnosis-finding.d.ts +25 -0
- package/dist/services/batch/batch-diagnosis-finding.js +227 -0
- package/dist/services/batch/batch-diagnosis-report-store.d.ts +49 -0
- package/dist/services/batch/batch-diagnosis-report-store.js +133 -0
- package/dist/services/batch/batch-diagnosis-summary.d.ts +31 -0
- package/dist/services/batch/batch-diagnosis-summary.js +129 -0
- package/dist/services/batch/batch-diagnosis.d.ts +36 -0
- package/dist/services/batch/batch-diagnosis.js +107 -0
- package/dist/services/batch/batch-entry.d.ts +22 -0
- package/dist/services/batch/batch-entry.js +42 -0
- package/dist/services/batch/batch-fix-agent.d.ts +39 -0
- package/dist/services/batch/batch-fix-agent.js +126 -0
- package/dist/services/batch/batch-fix-types.d.ts +85 -0
- package/dist/services/batch/batch-fix-types.js +11 -0
- package/dist/services/batch/batch-fix.d.ts +15 -0
- package/dist/services/batch/batch-fix.js +229 -0
- package/dist/services/batch/batch-phase-advance.d.ts +45 -0
- package/dist/services/batch/batch-phase-advance.js +105 -0
- package/dist/services/batch/batch-progress-store.d.ts +52 -0
- package/dist/services/batch/batch-progress-store.js +219 -0
- package/dist/services/batch/batch-progress-types.d.ts +79 -0
- package/dist/services/batch/batch-progress-types.js +10 -0
- package/dist/services/batch/batch-recovery.d.ts +5 -0
- package/dist/services/batch/batch-recovery.js +24 -0
- package/dist/services/batch/batch-verify.d.ts +93 -0
- package/dist/services/batch/batch-verify.js +216 -0
- package/dist/services/code/auto-compact-decision.d.ts +17 -0
- package/dist/services/code/auto-compact-decision.js +6 -0
- package/dist/services/code/auto-compact-orchestrator.js +6 -0
- package/dist/services/code/batch-compaction-point.d.ts +45 -0
- package/dist/services/code/batch-compaction-point.js +99 -0
- package/dist/services/code/orchestrator-can-do-probes.d.ts +10 -0
- package/dist/services/code/orchestrator-can-do-probes.js +12 -2
- package/dist/services/context/context-schema.d.ts +1 -1
- package/dist/services/lint/curated-rule-reader.d.ts +37 -0
- package/dist/services/lint/curated-rule-reader.js +179 -0
- package/dist/services/lint/project-lint-declarations.d.ts +27 -0
- package/dist/services/lint/project-lint-declarations.js +217 -0
- package/dist/services/lint/project-lint-tool-detection.d.ts +14 -0
- package/dist/services/lint/project-lint-tool-detection.js +208 -0
- package/dist/services/lint/project-lint-tool-rules.d.ts +19 -0
- package/dist/services/lint/project-lint-tool-rules.js +199 -0
- package/dist/services/lint/rule-pre-read-types.d.ts +66 -0
- package/dist/services/lint/rule-pre-read-types.js +22 -0
- package/dist/services/lint/rule-pre-read.d.ts +20 -0
- package/dist/services/lint/rule-pre-read.js +145 -0
- package/dist/services/scan/archetype-service.js +24 -8
- package/dist/services/scan/frontend-evidence.d.ts +19 -0
- package/dist/services/scan/frontend-evidence.js +142 -0
- package/dist/services/scan/scan-types.d.ts +8 -1
- package/dist/services/skill/skill-search-service.d.ts +3 -3
- package/package.json +5 -5
- package/skills/peaks-code/references/micro-cycle.md +13 -1
- package/skills/peaks-race-code/SKILL.md +40 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"metadata": {
|
|
3
3
|
"pluginRoot": ".",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.13"
|
|
5
5
|
},
|
|
6
6
|
"plugins": [
|
|
7
7
|
{
|
|
8
8
|
"name": "peaks-loop",
|
|
9
9
|
"description": "Loop Engineering CLI — workflow primitive / loop guards / evaluators / slice orchestration",
|
|
10
|
-
"version": "4.1.
|
|
10
|
+
"version": "4.1.13",
|
|
11
11
|
"author": {
|
|
12
12
|
"name": "SquabbyZ"
|
|
13
13
|
},
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,93 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.1.13 — 2026-10-21(peaks-race-code 批量模式:一次门禁归因、scoped test 前置的修复阶段、上下文监控)
|
|
4
|
+
|
|
5
|
+
**版本级别**: 未发布区间 `v4.1.12..HEAD` 共 **32 个 commit**(**10 feat / 11 fix / 11 docs**)。取 **patch**,依维护者 2026-07-22 的常设规则"默认版本新增采用最小的版本位"。本次是**纯追加**:新的 `peaks batch` 命令组、新的 `src/services/batch/**` 与 `src/services/lint/**` 模块;既有 CLI 参数、peaks-code 的 11 步工序、Gate A–G 与 transition 状态机**一字不改**。唯一触及既有共享路径的两处 —— `auto-compact-decision.ts` 的可选 `atPhaseBoundary`、`skill-context-verdict.ts` 的可选 `batch` 参数 —— **缺省时行为逐字不变**,对非批量用户无影响。
|
|
6
|
+
|
|
7
|
+
### 1. 批量模式骨架与只读诊断(`d860b4cc`)
|
|
8
|
+
|
|
9
|
+
- `decideBatchMode(itemCount)`:**一项 ⇒ 走今天的路**。批量机制(诊断 fan-out、规则预读、定档)存在的意义是把准备成本摊到多项上;用在一项上,它花掉的和省下的一样多,还改动了单任务路径的行为 —— 而那正是批量模式被禁止做的事。所以**一项读作 `single`**。
|
|
10
|
+
- 拓扑由**实测文件集**决定:波次规划器按**字符串全等**匹配文件,Windows 上 `src\a.ts` 与 `src/a.ts` 是两个不同文件 ⇒ 碰同一个文件的两项会看起来不相干、落进同一波、两个 agent 同时改一个文件。归一化在**喂进去之前**做(`normalizeFileSet`),规划器只做它那一件事。
|
|
11
|
+
- 诊断 prompt **复用共享的 dispatch 前缀**而不是手搓一份会漂移的副本,并且**禁止 Edit / Write / MultiEdit** —— 诊断 agent 报告的文件集是定档唯一的输入,一个边写边报的 agent 报的是猜测。
|
|
12
|
+
|
|
13
|
+
### 2. 统一验证:门禁一次跑完,而且能归因(`7a495a3c` / `60a4f147`)
|
|
14
|
+
|
|
15
|
+
- 门禁就是单任务 lane 跑的那一个,逐字相同:`['test','tsc','lint']`。批量模式把它**跑一次**而不是每项一次 ⇒ **严格程度一点没降**,变的只是次数。
|
|
16
|
+
- 红灯要能说清是哪一类坏:每项 scoped test 都绿 ⇒ `integration`(问题在项与项之间);有项没绿 ⇒ `single-item`,并在 detail 里**点名是哪一项**。
|
|
17
|
+
- ⚠️ **构建产物缺失不是红灯**。`tsc -p tsconfig.json` 把子路径导出解析进未跟踪的 `packages/*/dist`,而 `pnpm test` **不会**触发 `pretest`(pnpm 10 默认不跑 pre/post 脚本)⇒ dist 缺失时 tsc 全是 TS2307/TS7016。这种形状现在是 **`blocked`**、归因 `unknown`、**不点名** —— 否则一个构建产物问题会被**伪造成某个无辜项的失败**。仓库自己的门禁早就这么处理(`.husky/gate/repo.mjs`)。
|
|
18
|
+
|
|
19
|
+
### 3. 修复阶段:scoped test 是状态翻转的前置条件(`05d8077f`)
|
|
20
|
+
|
|
21
|
+
- 修完一项 → **立刻**跑该项的 scoped test → 绿了才 `appendBatchItem(status:'fixed')`;红则状态留在 `diagnosed`,失败信息随结果回传。
|
|
22
|
+
- 这一步是第 2 节归因的**前提**:统一门禁只有知道每项自己那次的结果,才分得清"一项坏了"和"合在一起坏了"。**scoped test 不能攒到最后一起跑。**
|
|
23
|
+
- 测试用**变异**证明这个顺序是承重的:把状态翻转移到 scoped test 之前 ⇒ 3 个测试变红(含专门盯顺序的那个)。
|
|
24
|
+
|
|
25
|
+
### 4. 上下文监控(`c29bf911` / `6f9e4cdd` / `d00bd364`)
|
|
26
|
+
|
|
27
|
+
- **报告落盘,窗口里只留 ≤2 KB 摘要**(结论 + 文件集 + 一行草图)。批量模式下 N 份报告一次性涌入是真实风险(实测 20 份 ≈ 60 KB ≈ 15K token),完整报告留在盘上,编排器按需再读。
|
|
28
|
+
- **阶段边界是最佳压缩点,不是推迟的理由**。既有的 in-flight 推迟会把压缩推到整个批次之后 —— 而那正是窗口最胀的时候(该推的先被推了)。到边界时(①→② / ③→④)压缩**现在就发生**。缺省 `atPhaseBoundary` 时行为逐字不变。
|
|
29
|
+
- **提醒只陈述事实,绝不把压缩甩给用户**:≤0.80 完全不说;≥0.80 之后**每个阶段边界说一次**,不是每轮说。
|
|
30
|
+
- 阶段推进只有**一个主人**(`batch-phase-advance.ts`),所以两个边界不可能各自漂移;边界那句话的措辞仍然只有**一个来源**(第 2 节的 `buildPhaseBoundaryNotice`)。
|
|
31
|
+
|
|
32
|
+
### 5. 规范预读与 micro-cycle 的 lint 腿(`249cdf5c` / `1a259471`)
|
|
33
|
+
|
|
34
|
+
- 生效规则有**三个来源**,缺一不可:项目自己的规则、OCR delegate 的规则、ECC 的规则。预读是**项目无关、语言无关**的 —— 识别 eslint / stylelint / golangci-lint / ruff / flake8 / gofmt / swiftlint,**没有语言分叉**;项目没声明 lint 工具时返回**显式理由**而不是假装有。
|
|
35
|
+
- 命名空间决定身份:`lint:silent-warning` 是 lint 步,`test:lint` 是测试(它跑的是 lint 配置的测试)。按**第一段命名空间**判断,才不会把"恰好碰到 lint 的测试"算成 lint 步。
|
|
36
|
+
|
|
37
|
+
### 6. 进度落盘与用户可见表面(`7f2690b7` / `8240e6b6`)
|
|
38
|
+
|
|
39
|
+
- 批量的阶段、条目、实测文件集落盘 ⇒ **一次压缩丢不掉它**,定档才有输入。
|
|
40
|
+
- `skills/peaks-race-code/SKILL.md` 加一节"批量模式":什么时候进(≥2 项互不依赖)、四个阶段、诊断阶段**只读**、风险面**逐项**判定(命中就退出批量走单任务路)。风险面清单**不复制** —— 单一真源在 fast-lane norm。
|
|
41
|
+
|
|
42
|
+
### 7. 两个只在共享路径上才暴露的缺陷(`60a4f147` / `ee5e48c2`)
|
|
43
|
+
|
|
44
|
+
- 批量查询**曾经**把 `getSessionDir` 放在 `try` 之外 ⇒ session id 不是单段时抛出去,而它在**每一次** auto-compact 都会经过 ⇒ 压缩路径被批量代码搞崩。抓住它的是一个**本次功能之前就存在**的测试。
|
|
45
|
+
- 现在:不可用的 session id ⇒ "没有批次可列"(只读方不写,所以拒绝**查找**就是全部答案);`resolveBatchCompactionBoundary` **永不抛** ⇒ 判断不出边界就当"不在边界",压缩路径照旧。
|
|
46
|
+
- 教训进了项目记忆:**改了共享路径,就要去跑那条路径上既有的测试**;只跑"我改的那个目录"的 scoped 测试不够。
|
|
47
|
+
|
|
48
|
+
### 8. 证据
|
|
49
|
+
|
|
50
|
+
- 全量 `pnpm test:unit`:**562 files / 6181 passed / 3 skipped**,exit 0。
|
|
51
|
+
- `tsc --noEmit` 0 error;`node .husky/peaks-gate.mjs repo` **exit 0,全部 ceiling 持平**(逐个比对未动,17 个上限一个没涨);`peaks workflow verify-pipeline` `complete: true`;`no-ai-co-author-trailer` 红线测试通过。
|
|
52
|
+
- 其余 CI 各腿本地实测:silent-warning 门、workspace packages、vitest lint 配置、format / coverage ratchet、e2e、capability-guard 全绿。
|
|
53
|
+
- 十个切片都走 PRD → RD → QA;security / perf 审计由 CLI 出件,karpathy 复核 4 项全 pass。
|
|
54
|
+
- 棘轮基线刷新 7 次,每次都只刷新**因新增 in-scope 文件而陈旧**的普查记录,**没有一次抬高上限**。
|
|
55
|
+
|
|
56
|
+
## 4.1.12 — 2026-10-20(macOS CI 红灯、frontend-only 正面证据制,与 Node 门槛声明修正)
|
|
57
|
+
|
|
58
|
+
**版本级别**: 未发布区间 `v4.1.11..HEAD` 共 **5 个 commit**(**3 fix / 1 docs / 1 chore**)。取 **patch**,依维护者 2026-07-22 的常设规则"默认版本新增采用最小的版本位"。`ProjectArchetype` 新增 `cli` 取值、`ArchetypeReport.detected` 新增 `hasBin` 与 `frontendEvidence` 两个字段,均为**追加**;既有 archetype 取值、`frontendOnly` 的布尔语义与全部 CLI 参数不变,无破坏性变更。
|
|
59
|
+
|
|
60
|
+
### 1. macOS CI 的唯一红灯来自 Q2 探针预算(`8e7a1cac`)
|
|
61
|
+
|
|
62
|
+
- 4.1.11 的 CI 在 `macos-latest` 上只有一条失败:`orchestrator-can-do.test.ts` 的 Q2 探针。用例耗时 **5035 ms**,而探针的 `execFile` 预算是 **5000 ms**——超时被 `catch` 统一读成 `false`,于是"慢"变成了"sub-agent dispatch 不可用"。
|
|
63
|
+
- 同一次 CI 里,Q4 探针用 10000 ms 预算并通过;这就是对照证据。本次把 Q2 预算提为具名常量 `SUB_AGENT_PROBE_TIMEOUT_MS = 15_000`,Q4 也改为具名 `CONTEXT_RATIO_PROBE_TIMEOUT_MS = 10_000`(值未动)。
|
|
64
|
+
- 新增回归断言:**Q2 预算不得低于 Q4 预算**,失败信息点名被改小的常量。负向对照(把 Q2 改回 `5_000`)确实变红,断言不是同义反复。
|
|
65
|
+
- 断言放在新文件 `orchestrator-can-do-probe-budgets.test.ts`:`orchestrator-can-do.test.ts` 在 HEAD 已 564 行、超过 tests 的 500 行上限,staged size ratchet 拒绝增长。
|
|
66
|
+
|
|
67
|
+
### 2. frontend-only 不再等于"没有后端"(`20062aa3`)
|
|
68
|
+
|
|
69
|
+
- `decideFrontendOnly` 此前只有一条判据:`arctype === frontend-monorepo` 或 `!hasBackend && !hasSwaggerOrProto`。一个没有任何前端产物的 TypeScript CLI 因此被报成 `frontend-monorepo` + `frontendOnly: true`,并写进 project-scan 供 PRD/RD 读取。
|
|
70
|
+
- 现在要求**正面证据**(任一):前端框架/运行时依赖;CSS 相关依赖;或 `src|app|pages|components|public` 下存在 `css|scss|sass|less|styl|html|htm|vue|svelte` 文件。目录遍历跳过 `node_modules|dist|build|out|coverage` 与点目录,并且**只认应用根**——本仓库 `examples/**` 与 `skills/**` 里的样式不计入。
|
|
71
|
+
- 新增 `cli` archetype:`bin` 非空 + 无后端 + 无前端证据。本仓库自扫现在是 `cli` / `false` / `archetype=cli`,monorepo 分支不再把它吞掉。
|
|
72
|
+
- 探测放在新模块 `src/services/scan/frontend-evidence.ts`:`archetype-detection.ts` 已 363 行、超过 src 的 300 行上限,闸门拒绝增长。
|
|
73
|
+
- 测试 fixture 里原本断言 `frontendOnly: true` 的用例都补上了真实证据;旧的 `no-backend-no-swagger` 期望被替换,而不是作为期望值保留。
|
|
74
|
+
|
|
75
|
+
### 3. 证据标签与 bin 探针分支(`4c338be4`)
|
|
76
|
+
|
|
77
|
+
- 文件证据的 reason 从 `css-under-<root>` 改为 `asset-under-<root>`:HTML 与 `.vue`/`.svelte` 此前被标成 CSS。
|
|
78
|
+
- 新增 `readRootBin` 的直接单测:manifest 缺失 / 非法 JSON / `bin: {}` → false;字符串 `bin` 与非空对象 → true。
|
|
79
|
+
|
|
80
|
+
### 4. README 的 Node 门槛(`a6233fc4`)
|
|
81
|
+
|
|
82
|
+
- 两个 README 的徽章从 `node ≥20` 改为 `≥24`。真实门槛由 `bin/node-floor.mjs` 的 `MIN_NODE_MAJOR = 24` 决定,`package.json#engines` 也已是 `>=24`;旧徽章会让 Node 20–23 的用户按错误的前提安装。
|
|
83
|
+
|
|
84
|
+
### 5. 证据
|
|
85
|
+
|
|
86
|
+
- 全量 `pnpm test:unit`:**540 files / 5980 passed / 3 skipped**,exit 0(3 个 skip 为既有 `@slow` / `@replay` 标记)。首轮曾因新测试文件未进体积基线而红了两条 standards 测试(census 784 vs `shadow.measuredFiles` 783),重生成基线后转绿;`shadow` 783→784,17 个 ceiling 逐一比对未动。
|
|
87
|
+
- `tsc --noEmit` 0 error;`pnpm build` 成功且 `dist` 携带 4.1.12;`node .husky/peaks-gate.mjs repo` 全部 ceiling 持平;`peaks changeset check` 通过;`no-ai-co-author-trailer` 红线测试通过。
|
|
88
|
+
- 三个代码切片均走 PRD → RD → QA:security / perf 审计由 CLI 出件(全部 `pass`,0 violations),karpathy 复核 4 项全部 pass,`peaks workflow verify-pipeline` 三份均 `gateC=pass / gateH=pass`、0 violations。
|
|
89
|
+
- OCR 1.x 补充评审:直接调用在 60 s 预算处超时;改走无凭据的 delegation 路径(出包 → 宿主模型按包内规则审 → `ocr-delegate-record` 回录),抓到一条 LOW——正是第 3 节修掉的 `css-under-` 标签。ESLint 仍是主闸,全程 0 findings。
|
|
90
|
+
|
|
3
91
|
## 4.1.11 — 2026-10-20(生产依赖升版、OCR 全语言路由,与 delegation 双阶段评审路径)
|
|
4
92
|
|
|
5
93
|
**版本级别**: 未发布区间 `v4.1.10..HEAD` 共 **3 个 commit**(**2 feat / 1 refactor**)。取 **patch**,依维护者 2026-07-22 的常设规则"默认版本新增采用最小的版本位"。`peaks code-review run-ocr-18` 新增 `--languages auto|<csv>` 与 `--delegate` 两条路径、新增 `peaks code-review ocr-delegate-record` 一个动词,均是在既有 service 之上的新入口;既有的 `--language <lang>` 单语言路径与 API 路径行为不变,无破坏性变更。
|
package/README-en.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://github.com/SquabbyZ/peaks-loop/actions/workflows/publish.yml)
|
|
9
9
|
[](https://github.com/SquabbyZ/peaks-loop/actions/workflows/ci.yml)
|
|
10
10
|
[](./LICENSE)
|
|
11
|
-
[](https://www.npmjs.com/package/peaks-loop)
|
|
12
12
|
[](https://github.com/SquabbyZ/peaks-loop/stargazers)
|
|
13
13
|
|
|
14
14
|
**English** · [简体中文](./README.md)
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://github.com/SquabbyZ/peaks-loop/actions/workflows/publish.yml)
|
|
9
9
|
[](https://github.com/SquabbyZ/peaks-loop/actions/workflows/ci.yml)
|
|
10
10
|
[](./LICENSE)
|
|
11
|
-
[](https://www.npmjs.com/package/peaks-loop)
|
|
12
12
|
[](https://github.com/SquabbyZ/peaks-loop/stargazers)
|
|
13
13
|
|
|
14
14
|
[English](./README-en.md) · **简体中文**
|
|
@@ -2,6 +2,7 @@ import { registerAdapterCommands } from './adapter-commands.js';
|
|
|
2
2
|
import { registerAdapterS2ACommands } from './adapter-commands-s2a.js';
|
|
3
3
|
import { registerAssetCommands } from './asset-commands.js';
|
|
4
4
|
import { registerAuditCommands } from './audit-commands.js';
|
|
5
|
+
import { registerBatchCommands } from './batch-commands.js';
|
|
5
6
|
import { registerBaselineCommands } from './baseline-commands.js';
|
|
6
7
|
import { registerBeeCommands } from './bee-commands.js';
|
|
7
8
|
import { registerBestPracticeScanCommand } from './best-practice-scan-command.js';
|
|
@@ -155,6 +156,7 @@ const REGISTRATIONS = [
|
|
|
155
156
|
['loop-eval-commands', registerWorkflowEvalCommands],
|
|
156
157
|
['evolution-commands', registerEvolutionCommands],
|
|
157
158
|
['asset-commands', registerAssetCommands],
|
|
159
|
+
['batch-commands', registerBatchCommands],
|
|
158
160
|
['evidence-commands', registerEvidenceCommands],
|
|
159
161
|
['fresh-context-commands', registerFreshContextCommands],
|
|
160
162
|
['bee-commands', registerBeeCommands],
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/cli/commands/batch-commands.ts
|
|
2
|
+
//
|
|
3
|
+
// `peaks batch` — the batch-mode surface of the race lane.
|
|
4
|
+
//
|
|
5
|
+
// The `batch` group is the lane's own surface, the way `race` is. The
|
|
6
|
+
// ACTION lives beside this file (`batch-diagnose-command.ts`), split out to
|
|
7
|
+
// honor the repo's file-size cap; the two share no logic — this one is the
|
|
8
|
+
// group and its option surface.
|
|
9
|
+
//
|
|
10
|
+
// WHY THE GROUP EXISTS AT ALL. Batch mode is an ADDITION to the lane, never
|
|
11
|
+
// a substitute for it. The lane's single-task path is unchanged by a batch,
|
|
12
|
+
// and the only thing that decides whether a request takes the batch path is
|
|
13
|
+
// how many independent items the user handed over — one item is not a batch.
|
|
14
|
+
// The action enforces that; the group exists so the surface is nameable.
|
|
15
|
+
import { addJsonOption } from '../cli-helpers.js';
|
|
16
|
+
import { runBatchDiagnose } from './batch-diagnose-command.js';
|
|
17
|
+
import { runBatchReportRead, runBatchReportWrite } from './batch-report-command.js';
|
|
18
|
+
/**
|
|
19
|
+
* Register `peaks batch` and its `diagnose` and `report` actions.
|
|
20
|
+
*/
|
|
21
|
+
export function registerBatchCommands(program, io) {
|
|
22
|
+
const batch = program
|
|
23
|
+
.command('batch')
|
|
24
|
+
.description('Batch mode for the race lane: diagnose N mutually independent items in parallel, ' +
|
|
25
|
+
'then plan the waves from the file sets they measured. One item is not a batch.');
|
|
26
|
+
addJsonOption(batch
|
|
27
|
+
.command('diagnose')
|
|
28
|
+
.description('Diagnose a batch: one read-only diagnosis per item, recorded in the batch ' +
|
|
29
|
+
'progress record. Dry-run by design — the CLI produces the toolCalls and the ' +
|
|
30
|
+
'LLM executes them.')
|
|
31
|
+
.option('--rid <rid>', 'the request this batch belongs to')
|
|
32
|
+
.option('--project <path>', 'target project root (defaults to the current directory)')
|
|
33
|
+
.option('--items <file>', 'JSON file holding the batch items')
|
|
34
|
+
.option('--items-json <json>', 'the batch items as inline JSON')).action((options) => {
|
|
35
|
+
runBatchDiagnose(options, io);
|
|
36
|
+
});
|
|
37
|
+
registerBatchReportCommands(batch, io);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Register `peaks batch report` and its `write` and `read` actions.
|
|
41
|
+
*
|
|
42
|
+
* Split out of the group so each function stays inside the repo's line
|
|
43
|
+
* cap: the group is a list of actions, and one action is a list of its own.
|
|
44
|
+
*/
|
|
45
|
+
function registerBatchReportCommands(batch, io) {
|
|
46
|
+
const report = batch
|
|
47
|
+
.command('report')
|
|
48
|
+
.description('The batch diagnosis reports: land one on disk and keep only its summary in the ' +
|
|
49
|
+
'window, or read it back on demand.');
|
|
50
|
+
addJsonOption(report
|
|
51
|
+
.command('write')
|
|
52
|
+
.description("Land one item's diagnosis report on disk and answer with its ≤2 KB summary — " +
|
|
53
|
+
'the conclusion, the measured file set, and a one-line sketch.')
|
|
54
|
+
.option('--rid <rid>', 'the request this batch belongs to')
|
|
55
|
+
.option('--item <id>', 'the item this report is about')
|
|
56
|
+
.option('--file <path>', 'the file holding the report text')
|
|
57
|
+
.option('--project <path>', 'target project root (defaults to the current directory)')).action((options) => {
|
|
58
|
+
runBatchReportWrite(options, io);
|
|
59
|
+
});
|
|
60
|
+
addJsonOption(report
|
|
61
|
+
.command('read')
|
|
62
|
+
.description("Read one item's diagnosis report back: the summary by default, the whole " +
|
|
63
|
+
'report with --full.')
|
|
64
|
+
.option('--rid <rid>', 'the request this batch belongs to')
|
|
65
|
+
.option('--item <id>', 'the item this report is about')
|
|
66
|
+
.option('--full', 'return the whole report instead of the summary')
|
|
67
|
+
.option('--project <path>', 'target project root (defaults to the current directory)')).action((options) => {
|
|
68
|
+
runBatchReportRead(options, io);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ProgramIO } from '../cli-helpers.js';
|
|
2
|
+
import { type BatchDiagnoseOptions } from './batch-item-input.js';
|
|
3
|
+
/**
|
|
4
|
+
* Run the batch's diagnosis stage.
|
|
5
|
+
*
|
|
6
|
+
* The envelope is dry-run by design, exactly like `peaks sub-agent dispatch`:
|
|
7
|
+
* the CLI produces the toolCall descriptors and the LLM executes them in its
|
|
8
|
+
* own environment.
|
|
9
|
+
*/
|
|
10
|
+
export declare function runBatchDiagnose(options: BatchDiagnoseOptions, io: ProgramIO): void;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// src/cli/commands/batch-diagnose-command.ts
|
|
2
|
+
//
|
|
3
|
+
// The `peaks batch diagnose` action: the batch lane's read-only diagnosis
|
|
4
|
+
// fan-out, and the batch record it writes.
|
|
5
|
+
//
|
|
6
|
+
// Split out of `batch-commands.ts` to honor the repo's file-size cap. The
|
|
7
|
+
// two files share no logic: this one is the ACTION, and the registrar beside
|
|
8
|
+
// it is the group.
|
|
9
|
+
//
|
|
10
|
+
// WHY THIS EXISTS. Batch mode is an ADDITION to the race lane, never a
|
|
11
|
+
// substitute for it, so this command is reached only when the user handed
|
|
12
|
+
// over two or more mutually independent items. With ONE item the lane takes
|
|
13
|
+
// exactly the path it takes today, and this command refuses rather than
|
|
14
|
+
// running the machinery on a single item — the machinery exists to amortize
|
|
15
|
+
// setup across several items, and on one item it costs what it saves.
|
|
16
|
+
//
|
|
17
|
+
// WHAT IT DOES, IN TWO HALVES THAT BELONG TOGETHER.
|
|
18
|
+
// 1. It produces one read-only diagnosis `toolCall` per item that still
|
|
19
|
+
// needs a diagnosis, in the same dry-run envelope shape
|
|
20
|
+
// `peaks sub-agent dispatch` produces: the CLI produces the toolCall and
|
|
21
|
+
// the LLM executes it. The diagnostician only READS and REPORTS; the
|
|
22
|
+
// file set it reports is the only input the topology step has, so a
|
|
23
|
+
// diagnostician that also wrote files would be reporting a guess.
|
|
24
|
+
// 2. It records the batch in the progress record Task 6 wrote, and plans
|
|
25
|
+
// the waves from the file sets the diagnosticians MEASURED.
|
|
26
|
+
//
|
|
27
|
+
// WHY THE ITEM LIST IS AN INPUT AND NOT A GUESS. The batch's items are
|
|
28
|
+
// facts about the user's request that only the caller holds, so the caller
|
|
29
|
+
// supplies them. That is also why the item's STATUS is explicit: a diagnosed
|
|
30
|
+
// item is one whose file set was measured, and a pending one is one that
|
|
31
|
+
// still needs a diagnostician. Nothing is inferred from an absent field,
|
|
32
|
+
// because an item whose diagnosis found NO files is still diagnosed.
|
|
33
|
+
//
|
|
34
|
+
// WHY THE PROGRESS RECORD IS WRITTEN HERE. The record is what survives a
|
|
35
|
+
// compaction: the batch's stage, its items, and their measured file sets.
|
|
36
|
+
// Without it a compaction mid-batch loses the measured file sets, and the
|
|
37
|
+
// topology step has nothing to plan from.
|
|
38
|
+
import { fail } from 'peaks-loop-shared/result';
|
|
39
|
+
import { printResult } from '../cli-helpers.js';
|
|
40
|
+
import { recordBatch } from './batch-diagnose-record.js';
|
|
41
|
+
import { printDiagnoseResult } from './batch-diagnose-envelope.js';
|
|
42
|
+
import { decideBatchMode } from '../../services/batch/batch-entry.js';
|
|
43
|
+
import { buildDiagnosisPrompt } from '../../services/batch/batch-diagnosis.js';
|
|
44
|
+
import { REQUEST_ID_PATTERN } from '../../services/artifacts/request-artifact-service.js';
|
|
45
|
+
import { getCurrentSessionId } from '../../services/skills/skill-presence-service.js';
|
|
46
|
+
import { detectInstalledIde } from '../../services/ide/ide-detector.js';
|
|
47
|
+
import { getAdapter } from '../../services/ide/ide-registry.js';
|
|
48
|
+
import { hasSymptom, readItems } from './batch-item-input.js';
|
|
49
|
+
/** The role the diagnosticians are dispatched as: the lane's own RD role. */
|
|
50
|
+
const DIAGNOSIS_ROLE = 'rd';
|
|
51
|
+
/**
|
|
52
|
+
* The request the batch belongs to, or the refusal for it.
|
|
53
|
+
*
|
|
54
|
+
* A batch is not a free-standing thing: it is one request's worth of
|
|
55
|
+
* independent items, so the request id has to be nameable and has to be a
|
|
56
|
+
* real one — it becomes a path segment in the batch record.
|
|
57
|
+
*/
|
|
58
|
+
function resolveRid(options) {
|
|
59
|
+
const rid = options.rid;
|
|
60
|
+
if (rid === undefined || rid === '') {
|
|
61
|
+
return {
|
|
62
|
+
kind: 'refused',
|
|
63
|
+
code: 'MISSING_RID',
|
|
64
|
+
message: 'a batch belongs to a request, so --rid is required',
|
|
65
|
+
data: { rid: null, itemCount: 0, toolCalls: [] },
|
|
66
|
+
nextActions: ['Re-run with --rid <rid> naming the request this batch belongs to.']
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (!REQUEST_ID_PATTERN.test(rid)) {
|
|
70
|
+
return {
|
|
71
|
+
kind: 'refused',
|
|
72
|
+
code: 'INVALID_RID',
|
|
73
|
+
message: `the request id "${rid}" is not a valid request id`,
|
|
74
|
+
data: { rid: null, itemCount: 0, toolCalls: [] },
|
|
75
|
+
nextActions: [
|
|
76
|
+
'A request id is letters, digits, dots, dashes and underscores (see REQUEST_ID_PATTERN).'
|
|
77
|
+
]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return rid;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolve the batch's preconditions.
|
|
84
|
+
*
|
|
85
|
+
* The checks live here rather than inside the action so the action stays
|
|
86
|
+
* one thing: dispatch the diagnosis fan-out. Every refusal names the
|
|
87
|
+
* precondition that was missing, so a caller can fix it and re-run.
|
|
88
|
+
*/
|
|
89
|
+
function resolveBatch(options) {
|
|
90
|
+
const projectRoot = options.project ?? process.cwd();
|
|
91
|
+
const rid = resolveRid(options);
|
|
92
|
+
if (typeof rid !== 'string')
|
|
93
|
+
return rid;
|
|
94
|
+
const parsed = readItems(options);
|
|
95
|
+
if (parsed.kind === 'invalid') {
|
|
96
|
+
return {
|
|
97
|
+
kind: 'refused',
|
|
98
|
+
code: 'INVALID_ITEMS',
|
|
99
|
+
message: parsed.message,
|
|
100
|
+
data: { rid, itemCount: 0, toolCalls: [] },
|
|
101
|
+
nextActions: [
|
|
102
|
+
'Supply the items as {"items":[{"id":"i1","label":"...","symptom":"...","status":"pending"}]}',
|
|
103
|
+
'via --items <file> or --items-json <json>.'
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const items = parsed.items;
|
|
108
|
+
const mode = decideBatchMode(items.length);
|
|
109
|
+
if (mode === 'single') {
|
|
110
|
+
return {
|
|
111
|
+
kind: 'refused',
|
|
112
|
+
code: 'BATCH_MODE_NOT_APPLICABLE',
|
|
113
|
+
message: `one item is not a batch: ${items.length} item supplied`,
|
|
114
|
+
data: { rid, itemCount: items.length, toolCalls: [] },
|
|
115
|
+
nextActions: [
|
|
116
|
+
'Run the single-task path instead — a single task takes exactly the path it takes today.',
|
|
117
|
+
'Batch mode needs two or more mutually independent items.'
|
|
118
|
+
]
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const sessionId = getCurrentSessionId(projectRoot);
|
|
122
|
+
if (sessionId === null) {
|
|
123
|
+
return {
|
|
124
|
+
kind: 'refused',
|
|
125
|
+
code: 'NO_SESSION',
|
|
126
|
+
message: `no peaks session is bound to ${projectRoot}, so the batch cannot be recorded`,
|
|
127
|
+
data: { rid, itemCount: items.length, toolCalls: [] },
|
|
128
|
+
nextActions: ['Run `peaks workspace init --project .` first, then re-run this command.']
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return { kind: 'ready', projectRoot, rid, sessionId, items, mode };
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Build one read-only diagnosis toolCall per pending item.
|
|
135
|
+
*
|
|
136
|
+
* The RECORD is the source of the prompt, not the caller's input: the
|
|
137
|
+
* record accumulates across runs, so an item that a previous run left
|
|
138
|
+
* pending is dispatched here even when this run's input did not repeat it —
|
|
139
|
+
* and the symptom it carries is the one the record kept, not a label
|
|
140
|
+
* standing in for it.
|
|
141
|
+
*/
|
|
142
|
+
function buildDiagnosisToolCalls(projectRoot, rid, sessionId, pending) {
|
|
143
|
+
const ide = detectInstalledIde(projectRoot) ?? 'claude-code';
|
|
144
|
+
const dispatcher = getAdapter(ide).subAgentDispatcher;
|
|
145
|
+
const toolCalls = pending.filter(hasSymptom).map((item) => dispatcher.buildToolCall({
|
|
146
|
+
role: DIAGNOSIS_ROLE,
|
|
147
|
+
prompt: buildDiagnosisPrompt({
|
|
148
|
+
id: item.id,
|
|
149
|
+
label: item.label,
|
|
150
|
+
symptom: item.symptom
|
|
151
|
+
}),
|
|
152
|
+
requestId: `${rid}-${item.id}`,
|
|
153
|
+
sessionId
|
|
154
|
+
}));
|
|
155
|
+
const undiagnosable = pending.filter((item) => !hasSymptom(item)).map((item) => item.id);
|
|
156
|
+
return { toolCalls, undiagnosable };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Run the batch's diagnosis stage.
|
|
160
|
+
*
|
|
161
|
+
* The envelope is dry-run by design, exactly like `peaks sub-agent dispatch`:
|
|
162
|
+
* the CLI produces the toolCall descriptors and the LLM executes them in its
|
|
163
|
+
* own environment.
|
|
164
|
+
*/
|
|
165
|
+
export function runBatchDiagnose(options, io) {
|
|
166
|
+
const asJson = options.json === true;
|
|
167
|
+
const resolved = resolveBatch(options);
|
|
168
|
+
if (resolved.kind === 'refused') {
|
|
169
|
+
printResult(io, fail('batch.diagnose', resolved.code, resolved.message, resolved.data, [
|
|
170
|
+
...resolved.nextActions
|
|
171
|
+
]), asJson);
|
|
172
|
+
process.exitCode = 1;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const { projectRoot, rid, sessionId, items, mode } = resolved;
|
|
176
|
+
const { progress, compaction } = recordBatch({
|
|
177
|
+
projectRoot,
|
|
178
|
+
sessionId,
|
|
179
|
+
batchId: rid,
|
|
180
|
+
items
|
|
181
|
+
});
|
|
182
|
+
const pending = progress.items.filter((item) => item.status === 'pending');
|
|
183
|
+
const { toolCalls, undiagnosable } = buildDiagnosisToolCalls(projectRoot, rid, sessionId, pending);
|
|
184
|
+
printDiagnoseResult({
|
|
185
|
+
io,
|
|
186
|
+
asJson,
|
|
187
|
+
mode,
|
|
188
|
+
rid,
|
|
189
|
+
sessionId,
|
|
190
|
+
progress,
|
|
191
|
+
pendingCount: pending.length,
|
|
192
|
+
toolCalls,
|
|
193
|
+
undiagnosable,
|
|
194
|
+
compaction
|
|
195
|
+
});
|
|
196
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ProgramIO } from '../cli-helpers.js';
|
|
2
|
+
import type { BatchMode } from '../../services/batch/batch-entry.js';
|
|
3
|
+
import type { BatchProgress } from '../../services/batch/batch-progress-types.js';
|
|
4
|
+
import type { BatchCompactionPoint } from '../../services/code/batch-compaction-point.js';
|
|
5
|
+
import type { SubAgentToolCall } from '../../services/dispatch/sub-agent-dispatcher.js';
|
|
6
|
+
/**
|
|
7
|
+
* The envelope the diagnosis stage answers with.
|
|
8
|
+
*
|
|
9
|
+
* Split out so the action stays one thing: the stage runs, and the answer
|
|
10
|
+
* is built. The compaction block is part of the answer because the phase
|
|
11
|
+
* advance is what CHOOSES the compaction point — the caller is told which
|
|
12
|
+
* point it is, rather than left to work it out.
|
|
13
|
+
*/
|
|
14
|
+
export declare function printDiagnoseResult(input: {
|
|
15
|
+
readonly io: ProgramIO;
|
|
16
|
+
readonly asJson: boolean;
|
|
17
|
+
readonly mode: BatchMode;
|
|
18
|
+
readonly rid: string;
|
|
19
|
+
readonly sessionId: string;
|
|
20
|
+
readonly progress: BatchProgress;
|
|
21
|
+
readonly pendingCount: number;
|
|
22
|
+
readonly toolCalls: readonly SubAgentToolCall[];
|
|
23
|
+
readonly undiagnosable: readonly string[];
|
|
24
|
+
readonly compaction: BatchCompactionPoint;
|
|
25
|
+
}): void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/cli/commands/batch-diagnose-envelope.ts
|
|
2
|
+
//
|
|
3
|
+
// The envelope the batch's diagnosis stage answers with.
|
|
4
|
+
//
|
|
5
|
+
// WHY THIS IS ITS OWN FILE. The action beside it was already close to the
|
|
6
|
+
// repo's file-size cap, and building the answer is a second responsibility:
|
|
7
|
+
// the action runs the stage, this builds what the caller is told.
|
|
8
|
+
//
|
|
9
|
+
// WHY THE COMPACTION BLOCK IS PART OF THE ANSWER. The phase advance is what
|
|
10
|
+
// CHOOSES the compaction point, so the caller is told which point it is
|
|
11
|
+
// rather than left to work it out — and the line that tells it to compact
|
|
12
|
+
// appears only when a compaction is actually chosen.
|
|
13
|
+
import { ok } from 'peaks-loop-shared/result';
|
|
14
|
+
import { printResult } from '../cli-helpers.js';
|
|
15
|
+
/**
|
|
16
|
+
* What the caller is told to do next.
|
|
17
|
+
*
|
|
18
|
+
* The compaction line appears only when a compaction is actually chosen:
|
|
19
|
+
* a stage that did not cross a boundary says nothing about compaction.
|
|
20
|
+
*/
|
|
21
|
+
function diagnoseNextActions(compaction) {
|
|
22
|
+
return [
|
|
23
|
+
'Execute each toolCall; each diagnostician reads and reports, and changes nothing.',
|
|
24
|
+
'Re-run this command with the measured file sets to record them and plan the waves.',
|
|
25
|
+
...(compaction.shouldCompact
|
|
26
|
+
? [
|
|
27
|
+
'The batch crossed a phase boundary and the window is in the auto-compact zone: ' +
|
|
28
|
+
'this is the cheapest moment to compact, because the progress is on disk. ' +
|
|
29
|
+
'Run the auto-compact command yourself now.'
|
|
30
|
+
]
|
|
31
|
+
: [])
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The envelope the diagnosis stage answers with.
|
|
36
|
+
*
|
|
37
|
+
* Split out so the action stays one thing: the stage runs, and the answer
|
|
38
|
+
* is built. The compaction block is part of the answer because the phase
|
|
39
|
+
* advance is what CHOOSES the compaction point — the caller is told which
|
|
40
|
+
* point it is, rather than left to work it out.
|
|
41
|
+
*/
|
|
42
|
+
export function printDiagnoseResult(input) {
|
|
43
|
+
const { io, asJson, mode, rid, sessionId, progress, pendingCount, toolCalls, undiagnosable } = input;
|
|
44
|
+
printResult(io, ok('batch.diagnose', {
|
|
45
|
+
envelopeVersion: '2.1.0',
|
|
46
|
+
mode,
|
|
47
|
+
rid,
|
|
48
|
+
sessionId,
|
|
49
|
+
itemCount: progress.items.length,
|
|
50
|
+
pendingCount,
|
|
51
|
+
toolCalls,
|
|
52
|
+
topology: progress.topology,
|
|
53
|
+
compaction: {
|
|
54
|
+
point: input.compaction.kind,
|
|
55
|
+
shouldCompact: input.compaction.shouldCompact,
|
|
56
|
+
ratio: input.compaction.ratio,
|
|
57
|
+
atBoundary: input.compaction.atBoundary
|
|
58
|
+
}
|
|
59
|
+
}, undiagnosable.map((id) => `item ${id} is pending but carries no symptom, so no diagnosis was dispatched for it`), diagnoseNextActions(input.compaction)), asJson);
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BatchCompactionPoint } from '../../services/code/batch-compaction-point.js';
|
|
2
|
+
import type { BatchProgress } from '../../services/batch/batch-progress-types.js';
|
|
3
|
+
import { type BatchItemInput } from './batch-item-input.js';
|
|
4
|
+
/**
|
|
5
|
+
* Record every item, then read the record back and stamp it with the batch's
|
|
6
|
+
* stage and the wave plan.
|
|
7
|
+
*
|
|
8
|
+
* The per-item append is what makes a partial run recoverable: each item
|
|
9
|
+
* lands on disk as it is measured, so a compaction between two items loses
|
|
10
|
+
* neither. The final write carries the two facts that are only knowable once
|
|
11
|
+
* every item is in: the stage, and the plan the measured file sets produce.
|
|
12
|
+
*/
|
|
13
|
+
export declare function recordBatch(input: {
|
|
14
|
+
projectRoot: string;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
batchId: string;
|
|
17
|
+
items: readonly BatchItemInput[];
|
|
18
|
+
}): {
|
|
19
|
+
progress: BatchProgress;
|
|
20
|
+
compaction: BatchCompactionPoint;
|
|
21
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/cli/commands/batch-diagnose-record.ts
|
|
2
|
+
//
|
|
3
|
+
// The batch record the diagnosis stage writes, and the context ratio the
|
|
4
|
+
// compaction point is judged against.
|
|
5
|
+
//
|
|
6
|
+
// WHY THIS IS ITS OWN FILE. The action beside it (`batch-diagnose-command.ts`)
|
|
7
|
+
// was already close to the repo's file-size cap, and the phase advance —
|
|
8
|
+
// which chooses the compaction point and records the boundary notice — is a
|
|
9
|
+
// second responsibility. Split out, both stay readable.
|
|
10
|
+
//
|
|
11
|
+
// WHY THE PHASE ADVANCE CHOOSES THE COMPACTION POINT. When the diagnosis
|
|
12
|
+
// stage is over, the batch crosses ①→②: the diagnosis results are on disk,
|
|
13
|
+
// no diagnosis agent is in flight, and the window is at its heaviest. That
|
|
14
|
+
// is the cheapest moment to compact, so the stage that crosses the boundary
|
|
15
|
+
// is the stage that says so.
|
|
16
|
+
import { planBatchTopology } from '../../services/batch/batch-diagnosis.js';
|
|
17
|
+
import { advanceBatchPhase } from '../../services/batch/batch-phase-advance.js';
|
|
18
|
+
import { appendBatchItem, readBatchProgress } from '../../services/batch/batch-progress-store.js';
|
|
19
|
+
import { toBatchItem } from './batch-item-input.js';
|
|
20
|
+
/**
|
|
21
|
+
* Record every item, then read the record back and stamp it with the batch's
|
|
22
|
+
* stage and the wave plan.
|
|
23
|
+
*
|
|
24
|
+
* The per-item append is what makes a partial run recoverable: each item
|
|
25
|
+
* lands on disk as it is measured, so a compaction between two items loses
|
|
26
|
+
* neither. The final write carries the two facts that are only knowable once
|
|
27
|
+
* every item is in: the stage, and the plan the measured file sets produce.
|
|
28
|
+
*/
|
|
29
|
+
export function recordBatch(input) {
|
|
30
|
+
const { projectRoot, sessionId, batchId, items } = input;
|
|
31
|
+
for (const item of items) {
|
|
32
|
+
appendBatchItem(projectRoot, sessionId, batchId, toBatchItem(item));
|
|
33
|
+
}
|
|
34
|
+
const current = readBatchProgress(projectRoot, sessionId, batchId);
|
|
35
|
+
const recorded = current?.items ?? [];
|
|
36
|
+
const diagnosed = recorded.filter((item) => item.status !== 'pending');
|
|
37
|
+
const phase = diagnosed.length === recorded.length ? 'topology' : 'diagnosis';
|
|
38
|
+
// The ①→② boundary is crossed here: the diagnosis stage is over, its
|
|
39
|
+
// results are on disk, and this is the cheapest moment to compact. The
|
|
40
|
+
// advance owns the rule — the notice, the compaction point and the
|
|
41
|
+
// write — so the fix phase's boundary cannot drift from this one.
|
|
42
|
+
const advanced = advanceBatchPhase({
|
|
43
|
+
projectRoot,
|
|
44
|
+
sessionId,
|
|
45
|
+
batchId,
|
|
46
|
+
toPhase: phase,
|
|
47
|
+
items: recorded,
|
|
48
|
+
topology: planBatchTopology(diagnosed)
|
|
49
|
+
});
|
|
50
|
+
return { progress: advanced.progress, compaction: advanced.compaction };
|
|
51
|
+
}
|