peaks-loop 4.1.12 → 4.1.14
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 +118 -0
- 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/code-gate-command.d.ts +18 -0
- package/dist/cli/commands/code-gate-command.js +95 -32
- 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/context/context-schema.d.ts +1 -1
- package/dist/services/hooks/pre-tool-code-gate.d.ts +33 -1
- package/dist/services/hooks/pre-tool-code-gate.js +67 -6
- 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/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.14"
|
|
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.14",
|
|
11
11
|
"author": {
|
|
12
12
|
"name": "SquabbyZ"
|
|
13
13
|
},
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,123 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.1.14 — 2026-10-21(门禁按文件判而不是按写法判、发布包在任何 npm 布局下都能启动、门禁判不了时说得出来)
|
|
4
|
+
|
|
5
|
+
**版本级别**: 未发布区间 `v4.1.13..HEAD` 共 **4 个 commit**(**3 fix / 1 docs**)。取 **patch**,依维护者 2026-07-22 的常设规则"默认版本新增采用最小的版本位"。本次是**纯修复**:既有 CLI 参数、门禁的六个硬阻断族成员、fail-open 策略、auto-compact 三档阈值、peaks-code 的 11 步工序与 Gate A–G **一字不改**。两处行为变化都是本次要修的:**硬阻断路径的绝对写法现在被拒**(原先放行),以及**判不了的 payload 从静默放行变成留下可见标记**。
|
|
6
|
+
|
|
7
|
+
### 1. 门禁按文件判,不按写法判(`eeb02060`)
|
|
8
|
+
|
|
9
|
+
- 门禁此前用**裸 `startsWith`** 把硬阻断族和 payload 里的路径对起来,**整条门禁路径上没有任何归一化**。
|
|
10
|
+
族是项目相对前缀(`src/` `tests/unit/` …),于是 `src/x.ts` **被拒**,而 `./src/x.ts` 和**同一个文件的绝对写法被放行** ——
|
|
11
|
+
同一处编辑,换个写法就过,**而且过的正是那个写法**。门禁自己的测试**只用过相对写法**,另两种从未被执行。
|
|
12
|
+
- 现在:项目根**以内**的绝对路径先变成项目相对形式再匹配,开头的 `./` 去掉,分隔符折成 `/`。
|
|
13
|
+
**项目根之外**的绝对路径保持绝对:这些族名的是**本项目**的目录,别的仓库是别的仓库的事,
|
|
14
|
+
而且**修之前所有绝对路径本来就放行**,所以这**不是放宽**。
|
|
15
|
+
- `..` 段**故意不解析**:相对路径是相对**工具调用自己的工作目录**的,门禁并不知道那个目录,
|
|
16
|
+
拿项目根去解析是猜。
|
|
17
|
+
- `.sh` 兄弟脚本只做**拼写层面**的折叠:它不收环境变量也没有参数,**没有项目根**,硬猜会变成误拦;
|
|
18
|
+
它仍然**不**解析 driver —— 那会是同一个决定的第二个实现。
|
|
19
|
+
|
|
20
|
+
### 2. 发布包在任何 npm 布局下都能启动(`386ff9d9`)
|
|
21
|
+
|
|
22
|
+
- `peaks-loop-shared` **只发布 `dist/**`**(里面没有 `skills/`),所以它**永远不可能**是"skills 在哪"的答案;
|
|
23
|
+
旧的查找靠向上找一个**同时有 `package.json` 和 `skills/`** 的目录。
|
|
24
|
+
⇒ 只有当子包**嵌套在根包之下**时才找得到 —— 而那恰好是 npm **全局**安装的布局,
|
|
25
|
+
所以 `npm i -g peaks-loop` 一直好用;**本地**安装把子包**提升**到根包旁边,于是发布的 CLI **一 import 就死**:
|
|
26
|
+
`Error: Unable to locate Peaks repository root from .../node_modules/peaks-loop-shared/dist`。
|
|
27
|
+
**README 只写了全局安装**,所以坏掉的正是没写的那条路。
|
|
28
|
+
- 现在:查找在**每一层**都多问一句"根包是不是**在我旁边**",嵌套、提升、pnpm store 三种布局都覆盖;
|
|
29
|
+
根包根本不在盘上时,回落到**真源资产库**(`PEAKS_HOME` 或 `~/.peaks`)—— skills 的法定居所。
|
|
30
|
+
- 共享包只发布 `dist/**`,**不能** import 根包的脚本,所以那个环境变量名在**两处各写一遍**,
|
|
31
|
+
并在两处都记下了原因。
|
|
32
|
+
|
|
33
|
+
### 3. 门禁判不了的时候,说得出话(`8060706e`)
|
|
34
|
+
|
|
35
|
+
- payload 缺失或解析不了时门禁**仍然放行**,这是有意的:payload 送不到时**每次编辑都被拦**比放行更糟。
|
|
36
|
+
但那个放行**是静默的**,而它藏起来的失败恰是最贵的那种 ——
|
|
37
|
+
用管道喂 payload 的验收(有些 shell 根本不往进程转发 stdin)会**每个用例都过,却什么都没验**。
|
|
38
|
+
- 现在判不了的那一处在 **stderr 上留下 `PEAKS_CODE_GATE_UNDECIDABLE`**(PreToolUse 的 stderr 本来就喂给 LLM),
|
|
39
|
+
并把"用**文件重定向**喂 payload"的配方一并写出来。
|
|
40
|
+
|
|
41
|
+
### 4. 三个残留,**诚实记录**(不是本次的回归)
|
|
42
|
+
|
|
43
|
+
QA 独立复核时把 pre-fix 的源码抽出来实际跑过,确认以下三种写法**修之前也放行**,所以不是本次引入的:
|
|
44
|
+
|
|
45
|
+
| 残留 | 修前 | 修后 | 严重度 |
|
|
46
|
+
|---|---|---|---|
|
|
47
|
+
| `SRC/foo.ts` —— 族名的**大小写变体** | allow | allow | LOW |
|
|
48
|
+
| `docs/../src/foo.ts` —— 相对路径里**没解析的 `..`** | allow | allow | LOW |
|
|
49
|
+
| `.sh` 兄弟脚本 vs Node 命令(绝对硬阻断路径) | 都 allow | shell allow / node **deny** | MEDIUM |
|
|
50
|
+
| 项目**嵌在 git 仓库里** —— 绝对写法按 git 根判 | allow | allow | MEDIUM |
|
|
51
|
+
|
|
52
|
+
⇒ **"拼写无关"这条不变量,只在「项目根就是 git 根」时成立。** 前两条与刚修的缺陷**同类**
|
|
53
|
+
(大小写不敏感的文件系统上 `SRC/foo.ts` **就是** `src/foo.ts`)。判 LOW 的理由:这道门防的是
|
|
54
|
+
**误操作**,不是敌手。**留待后续决定是否再开一个 slice。**
|
|
55
|
+
|
|
56
|
+
### 5. 证据
|
|
57
|
+
|
|
58
|
+
- QA **独立复核**(不是采信 RD 的报告):三个变异**自己重推**,结果与 RD 报的**完全一致**
|
|
59
|
+
(归一化关掉 8 红 / 「根包在旁边」关掉 1 红 / 去掉两处 `reportUndecidable` 2 红)。
|
|
60
|
+
- 全量 `pnpm test:unit`:**565 文件 / 6204 通过 / 3 skip / exit 0,零失败**;
|
|
61
|
+
`tsc` 0 错;`node .husky/peaks-gate.mjs repo` 绿且**每个上限未动**(两个 eslint 上限各**降** 1)。
|
|
62
|
+
- 真实环境:5 个打包好的 tarball 装进**仓库之外**的全新目录,**npm 自己的提升布局、没手工挪** ⇒
|
|
63
|
+
`peaks --version` 起得来;**pre-fix** 的查找在同一条路径上**复现**了
|
|
64
|
+
`Unable to locate Peaks repository root`。
|
|
65
|
+
- 拼写矩阵(**文件重定向**喂 payload,绝不走管道):相对 / `./` / Windows 反斜杠 / `.\` / 绝对
|
|
66
|
+
—— **五种写法同一个判定,全部 deny**。
|
|
67
|
+
|
|
68
|
+
## 4.1.13 — 2026-10-21(peaks-race-code 批量模式:一次门禁归因、scoped test 前置的修复阶段、上下文监控)
|
|
69
|
+
|
|
70
|
+
**版本级别**: 未发布区间 `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` 参数 —— **缺省时行为逐字不变**,对非批量用户无影响。
|
|
71
|
+
|
|
72
|
+
### 1. 批量模式骨架与只读诊断(`d860b4cc`)
|
|
73
|
+
|
|
74
|
+
- `decideBatchMode(itemCount)`:**一项 ⇒ 走今天的路**。批量机制(诊断 fan-out、规则预读、定档)存在的意义是把准备成本摊到多项上;用在一项上,它花掉的和省下的一样多,还改动了单任务路径的行为 —— 而那正是批量模式被禁止做的事。所以**一项读作 `single`**。
|
|
75
|
+
- 拓扑由**实测文件集**决定:波次规划器按**字符串全等**匹配文件,Windows 上 `src\a.ts` 与 `src/a.ts` 是两个不同文件 ⇒ 碰同一个文件的两项会看起来不相干、落进同一波、两个 agent 同时改一个文件。归一化在**喂进去之前**做(`normalizeFileSet`),规划器只做它那一件事。
|
|
76
|
+
- 诊断 prompt **复用共享的 dispatch 前缀**而不是手搓一份会漂移的副本,并且**禁止 Edit / Write / MultiEdit** —— 诊断 agent 报告的文件集是定档唯一的输入,一个边写边报的 agent 报的是猜测。
|
|
77
|
+
|
|
78
|
+
### 2. 统一验证:门禁一次跑完,而且能归因(`7a495a3c` / `60a4f147`)
|
|
79
|
+
|
|
80
|
+
- 门禁就是单任务 lane 跑的那一个,逐字相同:`['test','tsc','lint']`。批量模式把它**跑一次**而不是每项一次 ⇒ **严格程度一点没降**,变的只是次数。
|
|
81
|
+
- 红灯要能说清是哪一类坏:每项 scoped test 都绿 ⇒ `integration`(问题在项与项之间);有项没绿 ⇒ `single-item`,并在 detail 里**点名是哪一项**。
|
|
82
|
+
- ⚠️ **构建产物缺失不是红灯**。`tsc -p tsconfig.json` 把子路径导出解析进未跟踪的 `packages/*/dist`,而 `pnpm test` **不会**触发 `pretest`(pnpm 10 默认不跑 pre/post 脚本)⇒ dist 缺失时 tsc 全是 TS2307/TS7016。这种形状现在是 **`blocked`**、归因 `unknown`、**不点名** —— 否则一个构建产物问题会被**伪造成某个无辜项的失败**。仓库自己的门禁早就这么处理(`.husky/gate/repo.mjs`)。
|
|
83
|
+
|
|
84
|
+
### 3. 修复阶段:scoped test 是状态翻转的前置条件(`05d8077f`)
|
|
85
|
+
|
|
86
|
+
- 修完一项 → **立刻**跑该项的 scoped test → 绿了才 `appendBatchItem(status:'fixed')`;红则状态留在 `diagnosed`,失败信息随结果回传。
|
|
87
|
+
- 这一步是第 2 节归因的**前提**:统一门禁只有知道每项自己那次的结果,才分得清"一项坏了"和"合在一起坏了"。**scoped test 不能攒到最后一起跑。**
|
|
88
|
+
- 测试用**变异**证明这个顺序是承重的:把状态翻转移到 scoped test 之前 ⇒ 3 个测试变红(含专门盯顺序的那个)。
|
|
89
|
+
|
|
90
|
+
### 4. 上下文监控(`c29bf911` / `6f9e4cdd` / `d00bd364`)
|
|
91
|
+
|
|
92
|
+
- **报告落盘,窗口里只留 ≤2 KB 摘要**(结论 + 文件集 + 一行草图)。批量模式下 N 份报告一次性涌入是真实风险(实测 20 份 ≈ 60 KB ≈ 15K token),完整报告留在盘上,编排器按需再读。
|
|
93
|
+
- **阶段边界是最佳压缩点,不是推迟的理由**。既有的 in-flight 推迟会把压缩推到整个批次之后 —— 而那正是窗口最胀的时候(该推的先被推了)。到边界时(①→② / ③→④)压缩**现在就发生**。缺省 `atPhaseBoundary` 时行为逐字不变。
|
|
94
|
+
- **提醒只陈述事实,绝不把压缩甩给用户**:≤0.80 完全不说;≥0.80 之后**每个阶段边界说一次**,不是每轮说。
|
|
95
|
+
- 阶段推进只有**一个主人**(`batch-phase-advance.ts`),所以两个边界不可能各自漂移;边界那句话的措辞仍然只有**一个来源**(第 2 节的 `buildPhaseBoundaryNotice`)。
|
|
96
|
+
|
|
97
|
+
### 5. 规范预读与 micro-cycle 的 lint 腿(`249cdf5c` / `1a259471`)
|
|
98
|
+
|
|
99
|
+
- 生效规则有**三个来源**,缺一不可:项目自己的规则、OCR delegate 的规则、ECC 的规则。预读是**项目无关、语言无关**的 —— 识别 eslint / stylelint / golangci-lint / ruff / flake8 / gofmt / swiftlint,**没有语言分叉**;项目没声明 lint 工具时返回**显式理由**而不是假装有。
|
|
100
|
+
- 命名空间决定身份:`lint:silent-warning` 是 lint 步,`test:lint` 是测试(它跑的是 lint 配置的测试)。按**第一段命名空间**判断,才不会把"恰好碰到 lint 的测试"算成 lint 步。
|
|
101
|
+
|
|
102
|
+
### 6. 进度落盘与用户可见表面(`7f2690b7` / `8240e6b6`)
|
|
103
|
+
|
|
104
|
+
- 批量的阶段、条目、实测文件集落盘 ⇒ **一次压缩丢不掉它**,定档才有输入。
|
|
105
|
+
- `skills/peaks-race-code/SKILL.md` 加一节"批量模式":什么时候进(≥2 项互不依赖)、四个阶段、诊断阶段**只读**、风险面**逐项**判定(命中就退出批量走单任务路)。风险面清单**不复制** —— 单一真源在 fast-lane norm。
|
|
106
|
+
|
|
107
|
+
### 7. 两个只在共享路径上才暴露的缺陷(`60a4f147` / `ee5e48c2`)
|
|
108
|
+
|
|
109
|
+
- 批量查询**曾经**把 `getSessionDir` 放在 `try` 之外 ⇒ session id 不是单段时抛出去,而它在**每一次** auto-compact 都会经过 ⇒ 压缩路径被批量代码搞崩。抓住它的是一个**本次功能之前就存在**的测试。
|
|
110
|
+
- 现在:不可用的 session id ⇒ "没有批次可列"(只读方不写,所以拒绝**查找**就是全部答案);`resolveBatchCompactionBoundary` **永不抛** ⇒ 判断不出边界就当"不在边界",压缩路径照旧。
|
|
111
|
+
- 教训进了项目记忆:**改了共享路径,就要去跑那条路径上既有的测试**;只跑"我改的那个目录"的 scoped 测试不够。
|
|
112
|
+
|
|
113
|
+
### 8. 证据
|
|
114
|
+
|
|
115
|
+
- 全量 `pnpm test:unit`:**562 files / 6181 passed / 3 skipped**,exit 0。
|
|
116
|
+
- `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` 红线测试通过。
|
|
117
|
+
- 其余 CI 各腿本地实测:silent-warning 门、workspace packages、vitest lint 配置、format / coverage ratchet、e2e、capability-guard 全绿。
|
|
118
|
+
- 十个切片都走 PRD → RD → QA;security / perf 审计由 CLI 出件,karpathy 复核 4 项全 pass。
|
|
119
|
+
- 棘轮基线刷新 7 次,每次都只刷新**因新增 in-scope 文件而陈旧**的普查记录,**没有一次抬高上限**。
|
|
120
|
+
|
|
3
121
|
## 4.1.12 — 2026-10-20(macOS CI 红灯、frontend-only 正面证据制,与 Node 门槛声明修正)
|
|
4
122
|
|
|
5
123
|
**版本级别**: 未发布区间 `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 参数不变,无破坏性变更。
|
|
@@ -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
|
+
}
|