openfeel 1.5.25 → 1.6.0
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/README.en.md +7 -0
- package/README.zh-CN.md +7 -0
- package/dist/commands/flow.d.ts.map +1 -1
- package/dist/commands/flow.js +117 -23
- package/dist/commands/flow.js.map +1 -1
- package/dist/commands/lint.d.ts +3 -1
- package/dist/commands/lint.d.ts.map +1 -1
- package/dist/commands/lint.js +96 -0
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/req.d.ts.map +1 -1
- package/dist/commands/req.js +378 -27
- package/dist/commands/req.js.map +1 -1
- package/dist/commands/stage.d.ts.map +1 -1
- package/dist/commands/stage.js +19 -0
- package/dist/commands/stage.js.map +1 -1
- package/dist/core/dev-status.d.ts +25 -0
- package/dist/core/dev-status.d.ts.map +1 -1
- package/dist/core/dev-status.js +35 -0
- package/dist/core/dev-status.js.map +1 -1
- package/dist/core/errors.d.ts +13 -3
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +9 -3
- package/dist/core/errors.js.map +1 -1
- package/dist/core/flow-manager.d.ts +109 -3
- package/dist/core/flow-manager.d.ts.map +1 -1
- package/dist/core/flow-manager.js +326 -14
- package/dist/core/flow-manager.js.map +1 -1
- package/dist/core/i18n-data/en.d.ts.map +1 -1
- package/dist/core/i18n-data/en.js +54 -2
- package/dist/core/i18n-data/en.js.map +1 -1
- package/dist/core/i18n-data/zh-CN.d.ts.map +1 -1
- package/dist/core/i18n-data/zh-CN.js +54 -2
- package/dist/core/i18n-data/zh-CN.js.map +1 -1
- package/dist/core/lint-req.d.ts +17 -1
- package/dist/core/lint-req.d.ts.map +1 -1
- package/dist/core/lint-req.js +14 -2
- package/dist/core/lint-req.js.map +1 -1
- package/dist/core/plan/body-lint.d.ts +58 -0
- package/dist/core/plan/body-lint.d.ts.map +1 -0
- package/dist/core/plan/body-lint.js +197 -0
- package/dist/core/plan/body-lint.js.map +1 -0
- package/dist/core/plan/filled.d.ts +143 -0
- package/dist/core/plan/filled.d.ts.map +1 -0
- package/dist/core/plan/filled.js +244 -0
- package/dist/core/plan/filled.js.map +1 -0
- package/dist/core/plan/path.d.ts +24 -0
- package/dist/core/plan/path.d.ts.map +1 -1
- package/dist/core/plan/path.js +56 -0
- package/dist/core/plan/path.js.map +1 -1
- package/dist/core/req/aggregate.d.ts.map +1 -1
- package/dist/core/req/aggregate.js +5 -0
- package/dist/core/req/aggregate.js.map +1 -1
- package/dist/core/req/body-file.d.ts +66 -0
- package/dist/core/req/body-file.d.ts.map +1 -1
- package/dist/core/req/body-file.js +184 -2
- package/dist/core/req/body-file.js.map +1 -1
- package/dist/core/req/requirement-ops.d.ts +128 -14
- package/dist/core/req/requirement-ops.d.ts.map +1 -1
- package/dist/core/req/requirement-ops.js +341 -16
- package/dist/core/req/requirement-ops.js.map +1 -1
- package/dist/core/req/types.d.ts +55 -0
- package/dist/core/req/types.d.ts.map +1 -1
- package/dist/core/template-loader.d.ts.map +1 -1
- package/dist/core/template-loader.js +75 -0
- package/dist/core/template-loader.js.map +1 -1
- package/dsh/ACTION-GUIDE.md +41 -8
- package/dsh/ADAPTER.md +58 -13
- package/dsh/README.md +45 -24
- package/dsh/docs/compat/persistence.md +13 -0
- package/dsh/docs/compat/pipeline.md +12 -0
- package/dsh/docs/compat/req.md +14 -0
- package/dsh/docs/compat/stage.md +13 -0
- package/dsh/lib/adapters/dispatch-ledger.js +293 -0
- package/dsh/lib/adapters/dispatch.js +54 -6
- package/dsh/lib/adapters/next-action.js +336 -0
- package/dsh/lib/guard.js +9 -2
- package/dsh/lib/index.js +37 -0
- package/dsh/lib/surface/prompt.js +62 -178
- package/dsh/lib/tools/index.js +434 -10
- package/dsh/package.json +2 -2
- package/package.json +1 -1
package/dsh/README.md
CHANGED
|
@@ -29,6 +29,23 @@ OpenFeel 是一个给 AI 助手用的记录本和工作流程,主要解决两
|
|
|
29
29
|
|
|
30
30
|
模式可以按项目切换,也可以改全局默认;直接让 AI 帮忙改就行。两种模式共用同一套记录和检查条件,区别只是要不要强制执行。
|
|
31
31
|
|
|
32
|
+
### 硬规则:主会话只调度(v1.6.0 起)
|
|
33
|
+
|
|
34
|
+
- **必须派发子 Agent**:写文件 / 改代码 / 跑测试一律交给子 agent;主会话只做「判断该谁做 + 派发 + 记账 + 裁决」。**主会话直接改仓库即违规**(台账无记录 = 未派发)。
|
|
35
|
+
- **每次派发都记账**:`feel_dispatch` 追加一行到 `.openfeel/dev/dispatch.jsonl`(`feel_status.dispatch.records` 可查;该文件受 guard 保护,手写会被拒)。示例:
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
feel_dispatch stage=v1.6.0-stage-132 phase=exec_running targetAgent=openfeel-executor role=executor
|
|
39
|
+
goal="T13 文档对账:把 docs/json-contract.md 计数改为 46/47 并通过 npm run build"
|
|
40
|
+
files=["docs/json-contract.md","CHANGELOG.md"]
|
|
41
|
+
returnFormat="≤10 行:结论/改动文件/验证/阻塞"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- **需求正文必须写实**:正文只经 `feel_req action=body` 写(`section=摘要|目标与验收`,`text` 或 `file`);空壳需求在**状态流转**(`→scheduled` / `→in_progress` / `→done`)时被 `REQ_BODY_GATE` 拦住(认领不校验正文;放行用 `advance` / `complete` 的 `--force` 留痕)。
|
|
45
|
+
- **执行前必须有需求级计划**:`.openfeel/plan/reqs/REQ-NNN.plan.md` 写实后才可 `→in_progress`;有关联阶段的需求同时受阶段 exec 门(`STAGE_PLAN_GATE`)约束。
|
|
46
|
+
- **全模式强制 plan → exec → review**:`general` / `fast` / `full` 都要求「需求级计划 → 执行 → 审查」,区别只在阶段级是否裁剪 scheme/test 相位;`--force` 只留痕放行,**不放宽** done 门(review + verify)/ blocking REV / 归档判据。
|
|
47
|
+
- **适用模式**:以上是 **Feel Mode(流程模式)** 的硬规则;**Free Mode**(`feel_mode=disabled`)下流程与检查点可选(写入门禁仍生效),但派发台账、正文写入口与需求级计划仍可用——记录照常,只是不强制。
|
|
48
|
+
|
|
32
49
|
## 记录存在哪
|
|
33
50
|
|
|
34
51
|
记录都在项目根目录的 `.openfeel/` 文件夹里,不在对话中,换会话或关软件都不会丢。内容包括当前进度、待办清单、检查记录、历史版本和项目设置,由 OpenFeel 自己维护,不需要手改。
|
|
@@ -134,18 +151,20 @@ Windows 上的 `openfeel.cmd` 垫片。
|
|
|
134
151
|
|
|
135
152
|
---
|
|
136
153
|
|
|
137
|
-
### 工具面(
|
|
154
|
+
### 工具面(15 个)
|
|
138
155
|
|
|
139
|
-
适配器在 DSH 工具注册表上注册
|
|
156
|
+
适配器在 DSH 工具注册表上注册 15 个工具,全部经 `openfeel` CLI 执行(`feel_dispatch` 例外:它直接维护派发台账)。
|
|
140
157
|
|
|
141
158
|
| 工具 | 覆盖的 CLI | 能力域 |
|
|
142
159
|
|---|---|---|
|
|
143
|
-
| `feel_status` | `flow next --json`(权威)→ 失败回退 `flow status --json` + `flow mode --json`(+`req list --json`) | **状态快照**:宏观相位、每阶段相位、模式与来源、合法下一相位、负责 Agent
|
|
144
|
-
| `feel_next` | 同上快照的派生决策(`flow next --json` 字段直出) | **该谁做**:负责 Agent
|
|
160
|
+
| `feel_status` | `flow next --json`(权威)→ 失败回退 `flow status --json` + `flow mode --json`(+`req list --json`) | **状态快照**:宏观相位、每阶段相位、模式与来源、合法下一相位、负责 Agent、审查档位、守卫、阻塞审查、`dispatch{required,records,missingRoles}`、动作型 `nextAction`。默认 **compact**(去 `mode.transitionsByMode` / `recovery.handoff` / `observability`,按需用 `feel_flow action=phases|mode` 现取);`detail: "full"` 返回完整快照(v1.5.7) |
|
|
161
|
+
| `feel_next` | 同上快照的派生决策(`flow next --json` 字段直出) | **该谁做**:负责 Agent、合法下一相位、建议命令、守卫、阻塞审查、工具化 `dispatch`(goal/context/boundaries/returnFormat)、`nextAction`、`[HANDOFF: agent]` 标记 |
|
|
145
162
|
| `feel_flow` | `flow advance/current/overview/phases/mode/log/metrics/retry/repair/migrate/review_*` | 流水线推进与审查条目(`review_add` 的 `op` / `stage` 二选一,v1.3.4) |
|
|
146
163
|
| `feel_stage` | `plan stage add/list`、`stage status/set/task`、`flow stage set/reset/remove` | 阶段与 `status.md` |
|
|
147
164
|
| `feel_op` | `flow ops list`、`plan scheme create/publish/rename/remove/register`、`flow attempt/retry` | 操作方案与执行结果 |
|
|
148
|
-
| `feel_req` | `req add/list/show/board/next/claim/release/set/link/advance/split/review/verify/release-check/rollover` | 需求分发(7
|
|
165
|
+
| `feel_req` | `req add/list/show/board/next/claim/release/set/link/advance/split/review/verify/release-check/rollover` + **`body`(v1.6.0)** | 需求分发(7 状态);`action=body` 是**正文唯一写入口**(`section/text/file/append/replace`),元信息小节受保护 |
|
|
166
|
+
| `feel_dispatch` | 无 CLI(适配器直写 `.openfeel/dev/dispatch.jsonl`) | **派发台账(v1.6.0)**:`stage/phase/targetAgent/role/goal/files/returnFormat` → 一行 JSONL + `dispatchId`;5 分钟去重、24h / 200 行清理;文件受 guard 保护 |
|
|
167
|
+
| `feel_dev` | `dev sync` / `dev status` | **开发账本(v1.6.0)**:`action=sync\|status`;写命令成功出口已自动同步,通常只需 `status` 核对 `due` |
|
|
149
168
|
| `feel_checkpoint` | `flow checkpoint list/restore` | 检查点快照与选择性回退 |
|
|
150
169
|
| `feel_archive` | `flow archive <version>/list/show`、`archive <stage>` | 版本分片归档(`allow_unfinished` 显式放行发布软门)+ 阶段摘要归档 |
|
|
151
170
|
| `feel_kb` | `knowledge list/add/search/index/dedup` | 知识库(4 个固定分类) |
|
|
@@ -224,17 +243,18 @@ provider 桥接层会把「只有 description、没有 type」的节点转成 `t
|
|
|
224
243
|
|
|
225
244
|
### 系统提示面
|
|
226
245
|
|
|
227
|
-
启用 `autoPrompt` 时注入 `<feel_mode>` 段落,教会 agent **OpenFeel
|
|
246
|
+
启用 `autoPrompt` 时注入 `<feel_mode>` 段落,教会 agent **OpenFeel 的纪律**而非重复工具说明。v1.6.0 起提示**只有三节**(角色 / 三个可判定检查点 / 兜底),预算 **≤1200 字符、≤25 行**(实测 zh 700/817、en 1038/1154,含 Free Mode 附录):
|
|
228
247
|
|
|
229
|
-
-
|
|
230
|
-
-
|
|
231
|
-
-
|
|
232
|
-
-
|
|
233
|
-
-
|
|
234
|
-
- `
|
|
235
|
-
-
|
|
248
|
+
- **角色**:调度者不是执行者——写文件 / 改代码 / 跑测试由子 agent 完成。
|
|
249
|
+
- **检查点一(入口)**:无开启阶段或没有需求 → 先 `feel_stage action=add` + `feel_req action=add`,并用 `feel_req action=body` 写实正文;否则写入被拒 / 流转被拒(`REQ_BODY_GATE`)。
|
|
250
|
+
- **检查点二(计划)**:需求没有 `.openfeel/plan/reqs/REQ-NNN.plan.md` 或仍是占位空壳 → 停止执行,先补正文与计划;否则 `REQ_PLAN_GATE` / `STAGE_PLAN_GATE`。
|
|
251
|
+
- **检查点三(派发)**:要执行任何一步 → 必须派发子 agent 并用 `feel_dispatch` 记账;主会话只收 ≤10 行回报,直接改仓库即违规。
|
|
252
|
+
- **兜底**:不确定时调 `feel_status` / `feel_next`,不凭记忆;禁止手改 `flow.json` / `status.md`。
|
|
253
|
+
- **每轮提醒(v1.6.0)**:经 `ctx.systemPrompt.context` 注入,写类工具之后或每 5 步一次(首选档 `post-execute.additionalContexts` 不可用,降级原因见 [ADAPTER.md](ADAPTER.md));行文形如 `阶段 X / 相位 Y|下一步:subagent(goal=…)`。
|
|
254
|
+
- **状态与记录(v1.5.0;v1.6.0 收口)**:只有 Feel 写状态;子 agent 不读不写 `dev_last*` / `current.md` / `status.md` / `flow.json`;`feel_next` / `feel_status` 返回 `statusSync`(`due` / `lastSync` / `intervalMinutes`=30)。**同步用 `feel_dev action=sync`,不再用 shell 跑 `openfeel dev sync`**(写命令经 shell 会被门禁拒;且写成功出口已自动同步)。
|
|
236
255
|
- **命令执行工具(v1.3.5)**:Windows 优先 `bash`(Git Bash),其次 `pwsh`(PowerShell 7);macOS / Linux 用 `bash`;默认不用 `cmd.exe`;同一任务保持同一 shell。
|
|
237
|
-
-
|
|
256
|
+
- 门禁拒绝是预期结果,`--force` 只留痕放行(**不能**绕过 done 门 / blocking REV / 归档判据);退出码 `2` = 并发冲突可重试、`3` = 内部故障。
|
|
257
|
+
- **调度目标是活跃阶段**:`pipeline.phase` 只是宏观态,取 `phase != done` 的阶段;`auto_advance=disabled` 时推进前必须询问用户。
|
|
238
258
|
- **流程入口闸(v1.5.2)**:`feel_status` / `feel_next` 在无活跃阶段时返回 `workflowGate`;无阶段写 `docs/research/**` 被拒(chore 不能绕过,拒绝写 `guard-audit.jsonl`);提示段要求先 `feel_status`、不得以「调研/只读」为由跳过阶段。
|
|
239
259
|
- **派发/恢复(v1.5.3)**:`feel_next.dispatch`(goal/context/boundaries/returnFormat;子 agent 禁读状态文件、返回 ≤10 行);`feel_status.recovery`(lastTransition / handoff / nextAction);提示段新增派发契约节。
|
|
240
260
|
- **快照与空转(v1.5.4)**:`feel_status`/`feel_next` 返回 `revision` / `snapshotAt` / `stale`;`plan_pending` 停留 >10 分钟时提示空转。
|
|
@@ -258,7 +278,7 @@ provider 桥接层会把「只有 description、没有 type」的节点转成 `t
|
|
|
258
278
|
适配器在 `apply()` 中用 DSH 的 `ctx.tools.guard()` 注册同步守卫(`dsh/lib/guard.js`):
|
|
259
279
|
|
|
260
280
|
- **文件工具与 shell 都受守(v1.5.11)**:文件工具 `edit` / `write` / `apply_patch` / `str_replace_editor`;shell `bash` / `pwsh`(`shell` / `execute_command` / `exec` 在本宿主不存在,仅预置为跨宿主防御条目)。`feel_*`、`read`、`todo_write` 等不受影响。
|
|
261
|
-
- `.openfeel/**` 是**流程产物区**:plan / scheme / review 产物在任意阶段可写;但 `.openfeel/flow.json` 与 `.openfeel/**/status.md` **始终拒绝**(用 `feel_
|
|
281
|
+
- `.openfeel/**` 是**流程产物区**:plan / scheme / review 产物在任意阶段可写;但 `.openfeel/flow.json` 与 `.openfeel/**/status.md` **始终拒绝**(用 `feel_*`),`dev/dispatch.jsonl` 由 `feel_dispatch` 独占(手写 → deny)。受保护路径按**会话工作区 `<cwd>`** 判定;执行阶段仍可编辑其他项目的 `.openfeel/`(不做跨项目全局保护)。
|
|
262
282
|
- **风险分层(v1.3.3 / v1.4.0)**——源码(`src/**` 等)仍要求存在 `exec_running` 阶段;以下两类在无活跃阶段或非 `exec_running` 相位也放行,**混合目标从严**(任一源码 → 按源码规则):
|
|
263
283
|
- **doc/note**:`docs/**` 与 `.md/.mdx/.txt/.rst/.adoc`;
|
|
264
284
|
- **静态展示资源(v1.4.0)**:`.css/.scss/.html/.svg/.png/.jpg/.jpeg/.webp`,以及路径含 `assets/` 或 `public/`(支持 `crates/cli/assets/index.html` 这类嵌套资产目录;**源码扩展名不因目录豁免**,如 `assets/gen.ts` 仍按源码门禁)。
|
|
@@ -285,9 +305,9 @@ provider 桥接层会把「只有 description、没有 type」的节点转成 `t
|
|
|
285
305
|
|
|
286
306
|
```powershell
|
|
287
307
|
cd plugin
|
|
288
|
-
node test/contract.js # DSH 契约:schema 子集、无 type:null、参数契约(
|
|
289
|
-
node test/verify.js # 行为:真实 CLI + 真实 .openfeel 副本(
|
|
290
|
-
node test/guard.js # 写入门禁:fake ToolExecution + 临时工作区(
|
|
308
|
+
node test/contract.js # DSH 契约:schema 子集、无 type:null、参数契约(53 项)
|
|
309
|
+
node test/verify.js # 行为:真实 CLI + 真实 .openfeel 副本(129 项)
|
|
310
|
+
node test/guard.js # 写入门禁:fake ToolExecution + 临时工作区(180 项)
|
|
291
311
|
node test/integration.js # 真实注册表:真 cordis + 真 ToolRuntime 挂载(10 项)
|
|
292
312
|
```
|
|
293
313
|
|
|
@@ -295,7 +315,7 @@ node test/integration.js # 真实注册表:真 cordis + 真 ToolRuntime 挂
|
|
|
295
315
|
- `verify.js` 对真实 OpenFeel 项目做只读校验,**所有写操作只打在 `os.tmpdir()` 副本上**,并断言原项目 `revision` 未被改动。
|
|
296
316
|
**前置条件**:当前项目必须至少有 1 个已注册阶段(`flow.json` 的 `stages` 非空)。版本归档(`flow archive <version>`)会把阶段从 `flow.json` 移出,归档后 `stages = 0` 时脚本会在 `[2] 只读工具 — 真实项目快照` 报「需要至少一个阶段用于适配器验证」并退出 1——这是**前置条件不满足**,不是适配器缺陷。此时先 `openfeel plan stage add <临时阶段>`(或切到有活跃阶段的工作区)再跑;CI 不执行本脚本(CI 只跑 `node --check dsh/lib/**` 与 `npm test`),不影响发布门禁。
|
|
297
317
|
- `guard.js` 覆盖 `off/project/always`、`.openfeel/**` 产物、`exec_running`、general 需求、apply_patch 混合/无头/Move 同块、受保护路径、bootstrap 文案、shell 四类判定与 `OPENFEEL_SHELL_GATE` 三档等 138 条。
|
|
298
|
-
- `integration.js` 构造真实 Cordis 上下文 + 真实 `ToolRuntime`,调用适配器 `apply()`,断言
|
|
318
|
+
- `integration.js` 构造真实 Cordis 上下文 + 真实 `ToolRuntime`,调用适配器 `apply()`,断言 **15** 个工具真的完成注册与投影。
|
|
299
319
|
|
|
300
320
|
依赖提取:`contract.js` / `integration.js` 默认读 `%TEMP%\dsh-asar\dsh\node_modules\@deepseek-ai`(从宿主
|
|
301
321
|
`app.asar` 解出的包)。缺失时 `contract.js` / `integration.js` 会跳过并说明。
|
|
@@ -317,7 +337,7 @@ dsh/ # OpenFeel 仓库内的一等适配器目录
|
|
|
317
337
|
│ │ ├── workspace.js # 会话工作区 = 项目根(与 CLI 一致,**不回溯**)
|
|
318
338
|
│ │ └── dashboard.js # 状态快照 + 「下一步」决策(消费 flow next/status,无相位→Agent 本地镜像)
|
|
319
339
|
│ ├── tools/
|
|
320
|
-
│ │ ├── index.js #
|
|
340
|
+
│ │ ├── index.js # 15 个工具定义与 CLI argv 翻译
|
|
321
341
|
│ │ └── shared.js # 输出封装、参数编译、渲染
|
|
322
342
|
│ └── surface/
|
|
323
343
|
│ ├── command.js # /feel 命令
|
|
@@ -349,12 +369,13 @@ dsh/ # OpenFeel 仓库内的一等适配器目录
|
|
|
349
369
|
3. **CLI 契约(v1.3.0)**:`flow next --json` 提供调度决策;`flow status --json` 的
|
|
350
370
|
`stages[]` 已含 `workflowMode` / `requirementId` / `reviewTier` / `effectiveReviewTier` /
|
|
351
371
|
`opsSummary`;`--json` 失败输出 envelope(`error.code` / `kind` / `detail`)为分类权威;
|
|
352
|
-
`flow advance --json` 仅用于失败 envelope。v1.
|
|
353
|
-
|
|
372
|
+
`flow advance --json` 仅用于失败 envelope。v1.6.0 起共 **46 个成功 `--json` 出口 / 47 个注册选项**;
|
|
373
|
+
适配器按需消费其中一部分(具体调用点见各工具实现,不再按出口总数折算)。详见 [操作指南](https://github.com/Liuary/OpenFeel/blob/master/dsh/ACTION-GUIDE.md) 与
|
|
354
374
|
[更新说明](https://github.com/Liuary/OpenFeel/blob/master/docs/dsh-cli-requirements-supplement-1.2.3.md)。
|
|
355
375
|
4. **读命令已全面结构化**:v1.2.4 补齐了 `plan stage list` / `model list|get` / `flow retry` /
|
|
356
|
-
`lint` / `roadmap show` / `config get --all
|
|
357
|
-
|
|
376
|
+
`lint` / `roadmap show` / `config get --all`;v1.6.0 补 `req body`(`feel_req action=body`)与
|
|
377
|
+
`lint fill`。适配器仅剩 `dev status` 的**文本回显**(该子命令无 `--json`;`feel_dev` 另读
|
|
378
|
+
`.sync.json` 补结构化字段)与 `instructions` 的 XML 默认形态(合理)。
|
|
358
379
|
5. **`stage_summary` 默认拒绝覆盖**:v1.2.4 起 `archive <stage>` 对已存在的归档文件返回
|
|
359
380
|
`ARCHIVE_EXISTS`(refusal)且零写盘;确需覆盖须传 `force=true`,会冲掉人工整理的摘要。
|
|
360
381
|
6. **超时**:默认单次 120s。超大 `flow.json`(数百 KB)的 `flow status` 可能接近上限。
|
|
@@ -1011,3 +1011,16 @@ Top-level keys in order: `meta, pipeline, stages, reviews, log` (no `requirement
|
|
|
1011
1011
|
20. CLI runtime log line `[ISO][LEVEL][pid] message`, `cli start:` / `cli done exit=… [duration_ms=…] [project=…] [session=…]`, `~/.openfeel/cli/logs/openfeel-YYYY-MM-DD.log`, best-effort, no rotation.
|
|
1012
1012
|
21. `.info.json` = `{user, lang}`; `user` is never overwritten; `lang` defaults to `zh-CN`.
|
|
1013
1013
|
22. `openfeel archive <stage>` writes `.openfeel/log/archive-{stage}.md`, appends one `archive_stage` log entry, saves `flow.json`, optionally seeds `kb/patterns.md` — and removes nothing.
|
|
1014
|
+
|
|
1015
|
+
---
|
|
1016
|
+
|
|
1017
|
+
## v1.6.0 增量(现行契约;以上 v1.2.1 正文保持冻结)
|
|
1018
|
+
|
|
1019
|
+
> 实现锚点:`src/core/dev-status.ts`(`maybeSyncDevStatus` / `getDevStatus`)、`src/core/flow-manager.ts`、`dsh/lib/adapters/dispatch-ledger.js`、`dsh/lib/guard.js`。
|
|
1020
|
+
|
|
1021
|
+
1. **`dev/` 自动同步(REQ-059)**:`maybeSyncDevStatus(projectPath)` 在 `due === true` 或节点相位(start / turning point / end)时调 `syncDevStatus`,**异常不再吞**(返回 `error`,调用方输出一行 stderr)。挂在**写成功出口**:`flow advance`、`stage set` / `stage task` / `stage verify`、`req advance` / `complete` / `review` / `verify` / `body`;读命令不调。`blockChanged()` 保证状态未变不重写。
|
|
1022
|
+
2. **`DEV_SYNC_STALE` 门**:`archiving → done` 前仍 `due === true` ⇒ refusal / exit 1、零写盘;门之前必先跑一次 `maybeSyncDevStatus`,正常路径不会触发(只有同步本身失败 / `.openfeel/dev/` 不可写才拦),`--force` 留痕放行(`gate_overrides` 追加 `'dev_sync'`)。**正常 CLI 序列不可复现**,取证只认构造法单测(注入 `syncDevStatus` 抛错 / 目录只读)。
|
|
1023
|
+
3. **`.openfeel/dev/dispatch.jsonl`(REQ-057,派发台账)**:每行一条 UTF-8 / LF JSON,键序 `dispatchId, ts, leadSessionId, origin, stage, phase, targetAgent, role, taskId, goal, files, returnFormat, dispatchDepth`。同 `leadSessionId + taskId + goal` 5 分钟内去重(返回既有 `dispatchId`);保留 24h / 上限 200 行(读侧跳过畸形行;文件不存在视同空)。由适配器 `feel_dispatch` 原子写(temp + rename),**在 `PROTECTED_OPENFEEL_PATHS` 内**(agent 工具直写 → deny)。`origin` / `dispatchDepth` 按 schema 缺省 `root` / `1`,会话头读取路径**未在真实宿主验证**。
|
|
1024
|
+
4. **新增持久面:需求级计划** `.openfeel/plan/reqs/REQ-NNN.plan.md`(全局固定,不随阶段/版本漂移;`mkdir` 幂等);`requirements[*].plan = {path, sha256(前 12 位), recorded_at, deviations?}` 在阶段计划门通过时盖章。
|
|
1025
|
+
5. **新增可选需求字段**:`body_waiver` / `plan_waiver`(`{at, by, reason, gate}`)与 `plan`;旧数据缺省即未 waiver / 未盖章(读侧宽容)。
|
|
1026
|
+
6. **既有持久面零改动**:`flow.json` 的 revision / `.bak` / 锁顺序、`sessions.json` / `.preflight.json` / `guard-state.json` / `.sync.json` 的格式与写入时机均不变(`dispatch.jsonl` 是新文件,不参与 `flow.json` 事务)。
|
|
@@ -1571,3 +1571,15 @@ Errors surface as `错误:{msg}` (`common.errorTmpl`) → exit 1; `isFlowConcu
|
|
|
1571
1571
|
15. **The `done` git commit must happen after `save()`**, driven by the `true` return of
|
|
1572
1572
|
`advanceStagePhase`.
|
|
1573
1573
|
16. **`flow phases` shows the unpruned table even when it reports `reviewTier: "lean"`.**
|
|
1574
|
+
|
|
1575
|
+
---
|
|
1576
|
+
|
|
1577
|
+
## v1.6.0 增量(现行契约;以上 v1.2.1 正文保持冻结)
|
|
1578
|
+
|
|
1579
|
+
> 实现锚点:`src/core/flow-manager.ts:resolveTransitionsForMode`、`src/core/req/requirement-ops.ts`、`src/core/pipeline-schema.ts`(本版**零改动**)。
|
|
1580
|
+
|
|
1581
|
+
1. **阶段级转移表一字不改**:`resolveTransitionsForMode` 的 `general → {}` **保留**;`flow phases --mode general` 仍为空表(`no-path` + 专用 `generalNoPipeline` 文案);`pipeline.yaml` 的 `transitions`(full)与 `fast_transitions` 均不变,**不新增 `general_transitions`**。`fast` 表本就含 `plan_review` + `review`,本版只补「进入 exec_running 前必须有写实计划」的门,表不变。
|
|
1582
|
+
2. **`general` 的强制链落在需求生命周期(REQ-058)**:`general` 需求(有/无阶段)与零关联阶段的 `fast`/`full` 需求,`→in_progress` 前必须有写实的 `.openfeel/plan/reqs/REQ-NNN.plan.md`(内部码 `plan_missing`,CLI 文案 + exit 1);`→done` 前计划被改动须写实 `## 偏差与回写`(`plan_deviation`)。有阶段的 `fast`/`full` 需求由阶段 exec 门(`STAGE_PLAN_GATE`)覆盖,本门不重复判。
|
|
1583
|
+
3. **为何不给阶段表加 `general_transitions`**:阶段级 `general` 在写入面即被拒(`src/commands/stage.ts` / `src/commands/plan.ts` 的 `general_mode_conflict`),表没有消费者——加了是死代码。`flow advance --force` 对阶段级 general 的既有行为不变(仍可强制移动,属既有边界,非本版新增)。
|
|
1584
|
+
4. **门不进 done / 归档判据**:`describeStageDoneGate`、`requirementDoneBlocker`(review + verify)、`flow archive` 判据**一字不改**;正文门与计划门是不参与这三处的独立前置检查(存量债因此可经 `--force` 留痕到达归档)。
|
|
1585
|
+
5. **`PipelineConfigSchema.parse` 失败仍是硬错**(`flow-manager.ts:5087-5113` 现状)。
|
package/dsh/docs/compat/req.md
CHANGED
|
@@ -1241,3 +1241,17 @@ split(data, parentId, children):
|
|
|
1241
1241
|
| `req next --limit 2` with 0 candidates | `(无可接取需求)`; `--json` → `requirement: null, candidates: []` |
|
|
1242
1242
|
| `req next --limit 0` | exit 1, `非法 --limit 值(应为 ≥1 的整数)` |
|
|
1243
1243
|
| `req claim REQ-001 --json` | commander unknown-option error (write commands have no `--json`) |
|
|
1244
|
+
|
|
1245
|
+
---
|
|
1246
|
+
|
|
1247
|
+
## v1.6.0 增量(现行契约;以上 v1.2.1 正文保持冻结)
|
|
1248
|
+
|
|
1249
|
+
> 本节只登记 v1.2.1 之后**新增或改变**的语义;与上文冲突时以本节为准。实现锚点:`src/core/req/requirement-ops.ts`、`src/core/plan/filled.ts`、`src/commands/req.ts`。
|
|
1250
|
+
|
|
1251
|
+
1. **`req body <id>` —— 正文唯一业务小节写入口(REQ-055)**。`--section <name>` 必填;`--text` / `--file` 恰一;`--append` / `--replace` 互斥(缺省替换整节)。只改目标小节,元信息小节(`状态` / `变更记录` 等)返回 legacy `protected_section`;每次成功写入追加一条 `## 变更记录`。`--json` 出口 #45:`{schemaVersion,id,section,path,lines,created}`;失败 legacy `{schemaVersion,error,errorKind}`,`error ∈ {not_found,protected_section,empty_text,invalid_field}`,exit 1、零写盘。
|
|
1252
|
+
2. **写实判据单点**:`src/core/plan/filled.ts` 的 `isRequirementBodyFilled`。`## 摘要` / `## 目标与验收` 各需 ≥40 个非空白字符(`MIN_FILLED_CHARS`),`## 目标与验收` 至少一行判据(`-` / `*` / `A1` / `验收` 开头);占位行(`- [ ] 待补充` / `(待补充)` / `TODO` 等)整行剔除。禁止子串判定(`includes('待补充')` 会误伤正文引用)。
|
|
1253
|
+
3. **正文门(REQ-055 / REV-013)**:`applyStatusChange` 在 `targetStatus ∈ {scheduled,in_progress,done}` 且无 `body_waiver` 时判(判据 `requirementBodyBlocker`)。**`claimRequirement` 不校验正文**——认领 ≠ 开工,`req add --claim` 必须原子成功;`req claim --force` 仅为旧脚本兼容保留,**当前无实际作用**。空壳 ⇒ exit 1 专用文案(提示 `req body` 补写),零写盘;`req advance|complete --force` 写 `body_waiver={at,by,reason}` + 审计 `requirement_body_forced`(`gate: advance|complete`),再次流转放行。`draft` / `blocked` / `cancelled` / `rejected` 不受此门;`general` 与零关联阶段需求**同样生效**;**不进入** done 门(归档判据不受影响)。
|
|
1254
|
+
4. **需求级计划门(REQ-056 / REQ-058)**:计划文件全局固定 `.openfeel/plan/reqs/REQ-NNN.plan.md`(不随版本漂移,`rollover` 后仍在)。适用面三种组合:① `workflow_mode === 'general'`(有/无阶段);② `fast` / `full` 且关联阶段数 **0**;③ 有阶段的 `fast`/`full` **不走本门**(由阶段 exec 门覆盖)。`→in_progress` 前计划缺失或未写实 ⇒ `plan_missing`(`REQ_PLAN_GATE`);`req claim` **不**挂计划门(claim ≠ 开工)。
|
|
1255
|
+
5. **偏差门(REQ-056)**:`→done` 前比对 `requirements[*].plan.sha256`(执行前盖章的前 12 位)与当前计划文件;不一致且 `## 偏差与回写` 未写实 ⇒ `plan_deviation`(`REQ_PLAN_DEVIATION`);`plan.recorded_at` 缺失的历史需求放行 + `console.warn` + 独立审计 `requirement_plan_unstamped`(不阻塞)。顺序:正文门 → 计划门 → done 门(review + verify)→ 偏差门;缺 review/verify 仍先得 `invalid_status`。
|
|
1256
|
+
6. **错误码通道**:`RequirementErrorCode` 由 7 值扩到 10 值(+`body_empty` / `plan_missing` / `plan_deviation`)。`req claim/advance/complete` **均无 `--json`**;三码只由 `advance` / `complete` 触发,目前以 i18n 文案 + exit 1 呈现(`REQ_*` envelope 码尚未进入 `src/core/errors.ts`)。
|
|
1257
|
+
7. **既有行为零改动**:`requirementDoneBlocker`(done 门的 review + verify 两条判据)、`req claim --json` 的 unknown-option 行为、7 状态值域与 `general` 阶段级拒绝均不变。
|
package/dsh/docs/compat/stage.md
CHANGED
|
@@ -1435,3 +1435,16 @@ const SchemaSchema = z.object({
|
|
|
1435
1435
|
`~/.openfeel/schemas/{name}/schema.yaml` → `node_modules/openfeel/schemas/{name}/schema.yaml`;
|
|
1436
1436
|
otherwise throws `找不到 Schema "{name}": 已搜索路径 {paths}`
|
|
1437
1437
|
- No CLI command in this repository consumes `ArtifactGraph`; the stage/op layer never reads `schemas/`.
|
|
1438
|
+
|
|
1439
|
+
---
|
|
1440
|
+
|
|
1441
|
+
## v1.6.0 增量(现行契约;以上 v1.2.1 正文保持冻结)
|
|
1442
|
+
|
|
1443
|
+
> 实现锚点:`src/core/flow-manager.ts`(`describeStagePlanGate` / `advanceStagePhase` / `resetStagePhase`)、`src/commands/flow.ts`、`src/core/plan/filled.ts`。
|
|
1444
|
+
|
|
1445
|
+
1. **执行前计划门(REQ-056 / REV-014)**:`advanceStagePhase` 在 done 门之后、写盘之前插入;条件是本次相位路径**跨越** `exec_running`(`crossesExecRunning`:`fromPhase` 严格早于 `exec_running` 且 `targetPhase` 等于或晚于 `exec_running`;`--force` 单跳如 `plan_passed → review_pending` 同样触发,已在 `exec_running` 及之后的阶段不重复触发),而非 `targetPhase === 'exec_running'`。要求阶段 `plan.md`(`findStagePlanPath` 三级回退)与每个在办需求(`scheduled`/`in_progress`,**全局扫描**,含零关联阶段与 `general`)的 `.openfeel/plan/reqs/REQ-NNN.plan.md` 存在**且写实**(`isStagePlanFilled` / `isRequirementPlanFilled`)。拒绝 ⇒ `STAGE_PLAN_GATE` / refusal / exit 1,`detail = {stagePlanMissing, stagePlanUnfilled, requirementsMissingPlan[], requirementsUnfilledPlan[]}`,**零写盘**(revision 不变)。
|
|
1446
|
+
2. **`--force` 语义**:`flow advance` / `flow stage reset` 把 `allowGateOverride: true` 传给核心层;放行时 `appendLog` 的条目 detail 追加 `gate_overrides:['plan']` 与 `gate_missing` 快照。**不是静默放行**,也不改变 done 门 / blocking REV 门 / 归档判据。`--dry-run` 只预览相位,不预演证据门。
|
|
1447
|
+
3. **复位同口径(REV-005 / 裁定①)**:`flow stage reset <stage> --to exec_running` 复检同一谓词;**不加 `--force` 拒绝**(零写盘,提示「补计划 / 加 `--force`」两条出路);加 `--force` 时审计条目不叫 `advance_stage_phase` 而是 `reset_stage_phase`,detail 同样是 `gate_overrides` + `gate_missing`。
|
|
1448
|
+
4. **账本陈旧门(REQ-059)**:`advanceStagePhase` 入口**先**跑 `maybeSyncDevStatus()`,再在 done 门之前判 `targetPhase === 'done' && fromPhase !== 'done'` 且 `getDevStatus().due === true` ⇒ `DEV_SYNC_STALE` / refusal / exit 1,零写盘;同一 `allowGateOverride` 放行并在 `gate_overrides` 追加 `'dev_sync'`。正常路径同步成功即 `due=false`,不会触发(构造法单测见 `test/core/dev-status.test.ts`)。
|
|
1449
|
+
5. **盖章(REQ-056)**:计划门**通过时**对每个在办需求写 `requirements[*].plan = {path, sha256(前 12 位), recorded_at}`(已有 `deviations` 保留);拒绝路径零写盘。
|
|
1450
|
+
6. **既有行为零改动**:`describeStageDoneGate`(`archiving → done` 的 verification + 关联需求全 done)、`status.md` 投影、`reset_stage_phase` / `advance_stage_phase` 既有字段、`--force` 跳过非法 phase 的既有语义均不变。
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 派发台账(v1.6.0 / REQ-057)— DSH 适配器侧
|
|
3
|
+
*
|
|
4
|
+
* 文件:`<project>/.openfeel/dev/dispatch.jsonl`(UTF-8 / LF,一行一条 JSON)。
|
|
5
|
+
* 行 schema(plan §5.4):
|
|
6
|
+
* { dispatchId, ts, leadSessionId, origin, stage, phase,
|
|
7
|
+
* targetAgent, role, taskId, goal, files[], returnFormat, dispatchDepth }
|
|
8
|
+
*
|
|
9
|
+
* 职责:把「派给谁、派什么、允许写哪些文件」变成可审计的记录,供
|
|
10
|
+
* `feel_status.dispatch` 汇总(提示级,不做硬拦——用户裁定 ②)。
|
|
11
|
+
*
|
|
12
|
+
* 纪律:
|
|
13
|
+
* - 只有适配器进程直接 fs 写;该文件在 `PROTECTED_OPENFEEL_PATHS` 里,
|
|
14
|
+
* agent 的工具写(write/edit/shell)会被 guard 拒绝(防伪造「已派发」证据)。
|
|
15
|
+
* - 读写全部 best-effort:台账是观测手段,任何异常都不得阻断 `feel_*` 主流程。
|
|
16
|
+
* - 原子写沿用 `sessions.js` 的习惯:同目录 temp + rename(整文件重写,顺带 prune)。
|
|
17
|
+
* - 并发语义与 `sessions.js` 相同:无文件锁,读-改-写之间可能有丢行风险;
|
|
18
|
+
* 台账每行独立、去重按 `leadSessionId+taskId+goal`,丢一行只影响审计完整性,
|
|
19
|
+
* 不影响门禁判定(因此不引入锁)。
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
23
|
+
import { randomBytes } from 'node:crypto';
|
|
24
|
+
import { dirname, join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
/** 台账相对项目根的路径(POSIX 风格,供提示与测试断言)。 */
|
|
27
|
+
export const DISPATCH_LEDGER_REL_PATH = '.openfeel/dev/dispatch.jsonl';
|
|
28
|
+
|
|
29
|
+
/** 合法角色闭集(`feel_dispatch.role` 枚举同源)。 */
|
|
30
|
+
export const DISPATCH_ROLES = Object.freeze(['planner', 'executor', 'reviewer', 'tester', 'archiver']);
|
|
31
|
+
|
|
32
|
+
/** 台账保留时长(24h;超龄行在下次写入时清理)。 */
|
|
33
|
+
export const DISPATCH_RETENTION_MS = 24 * 60 * 60_000;
|
|
34
|
+
|
|
35
|
+
/** 台账行数上限(超出只保留最近 200 行)。 */
|
|
36
|
+
export const DISPATCH_MAX_RECORDS = 200;
|
|
37
|
+
|
|
38
|
+
/** 去重窗口(同 `leadSessionId+taskId+goal` 5 分钟内视为重复)。 */
|
|
39
|
+
export const DISPATCH_DEDUP_WINDOW_MS = 5 * 60_000;
|
|
40
|
+
|
|
41
|
+
/** 缺省返回格式(plan §5.4 的派发契约)。 */
|
|
42
|
+
export const DEFAULT_RETURN_FORMAT = '≤10 行:结论/改动文件/验证/阻塞';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 台账文件绝对路径。
|
|
46
|
+
* @param {string} projectPath
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
export function dispatchLedgerPath(projectPath) {
|
|
50
|
+
return join(projectPath, '.openfeel', 'dev', 'dispatch.jsonl');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 取字符串字段(缺省 → '')。
|
|
55
|
+
* @param {unknown} value
|
|
56
|
+
* @returns {string}
|
|
57
|
+
*/
|
|
58
|
+
function asString(value) {
|
|
59
|
+
return typeof value === 'string' ? value : '';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 取字符串数组(过滤非字符串 / 空串)。
|
|
64
|
+
* @param {unknown} value
|
|
65
|
+
* @returns {string[]}
|
|
66
|
+
*/
|
|
67
|
+
function asStringArray(value) {
|
|
68
|
+
if (!Array.isArray(value)) return [];
|
|
69
|
+
return value
|
|
70
|
+
.filter((entry) => typeof entry === 'string')
|
|
71
|
+
.map((entry) => entry.trim())
|
|
72
|
+
.filter((entry) => entry !== '');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 归一化一条台账记录(字段齐全、类型稳定)。
|
|
77
|
+
* @param {Record<string, unknown>} raw
|
|
78
|
+
* @returns {Record<string, any>}
|
|
79
|
+
*/
|
|
80
|
+
function normalizeRecord(raw) {
|
|
81
|
+
const depth = Number.isInteger(raw?.dispatchDepth) && raw.dispatchDepth >= 0 ? raw.dispatchDepth : 1;
|
|
82
|
+
return {
|
|
83
|
+
dispatchId: asString(raw?.dispatchId),
|
|
84
|
+
ts: asString(raw?.ts),
|
|
85
|
+
leadSessionId: asString(raw?.leadSessionId),
|
|
86
|
+
origin: asString(raw?.origin) || 'root',
|
|
87
|
+
stage: asString(raw?.stage),
|
|
88
|
+
phase: asString(raw?.phase),
|
|
89
|
+
targetAgent: asString(raw?.targetAgent),
|
|
90
|
+
role: asString(raw?.role),
|
|
91
|
+
taskId: asString(raw?.taskId),
|
|
92
|
+
goal: asString(raw?.goal),
|
|
93
|
+
files: asStringArray(raw?.files),
|
|
94
|
+
returnFormat: asString(raw?.returnFormat) || DEFAULT_RETURN_FORMAT,
|
|
95
|
+
dispatchDepth: depth,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 读全部记录(文件缺失 / 单行损坏 → 跳过,绝不抛错)。
|
|
101
|
+
* @param {string} projectPath
|
|
102
|
+
* @returns {Array<Record<string, any>>}
|
|
103
|
+
*/
|
|
104
|
+
function readAllDispatches(projectPath) {
|
|
105
|
+
let text;
|
|
106
|
+
try {
|
|
107
|
+
text = readFileSync(dispatchLedgerPath(projectPath), 'utf-8');
|
|
108
|
+
} catch {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
const records = [];
|
|
112
|
+
for (const line of text.split(/\r?\n/)) {
|
|
113
|
+
if (line.trim() === '') continue;
|
|
114
|
+
try {
|
|
115
|
+
const parsed = JSON.parse(line);
|
|
116
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) continue;
|
|
117
|
+
records.push(normalizeRecord(parsed));
|
|
118
|
+
} catch {
|
|
119
|
+
// 损坏行跳过:台账是观测数据,不因一行坏掉丢失全部证据
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return records;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 读台账(按文件顺序,最多返回最近 `limit` 条)。
|
|
127
|
+
* @param {string} projectPath
|
|
128
|
+
* @param {{ limit?: number }} [options]
|
|
129
|
+
* @returns {Array<Record<string, any>>}
|
|
130
|
+
*/
|
|
131
|
+
export function readDispatches(projectPath, options = {}) {
|
|
132
|
+
const all = readAllDispatches(projectPath);
|
|
133
|
+
const limit = Number.isInteger(options.limit) && options.limit > 0 ? options.limit : null;
|
|
134
|
+
return limit === null ? all : all.slice(-limit);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 24h / 200 行清理(纯函数,便于单测)。
|
|
139
|
+
* @param {Array<Record<string, any>>} records
|
|
140
|
+
* @param {number} now 毫秒时间戳
|
|
141
|
+
* @returns {Array<Record<string, any>>}
|
|
142
|
+
*/
|
|
143
|
+
function pruneRecords(records, now) {
|
|
144
|
+
const cutoff = now - DISPATCH_RETENTION_MS;
|
|
145
|
+
const kept = records.filter((record) => {
|
|
146
|
+
const at = Date.parse(record.ts);
|
|
147
|
+
// 时间戳不可解析的行没有审计价值(也无法判断新旧),按陈旧丢弃
|
|
148
|
+
return Number.isFinite(at) && at >= cutoff;
|
|
149
|
+
});
|
|
150
|
+
return kept.length > DISPATCH_MAX_RECORDS ? kept.slice(-DISPATCH_MAX_RECORDS) : kept;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 原子写整份台账(同目录 temp + rename;目录不存在时幂等创建)。
|
|
155
|
+
* @param {string} projectPath
|
|
156
|
+
* @param {Array<Record<string, any>>} records
|
|
157
|
+
* @returns {string} 台账绝对路径
|
|
158
|
+
*/
|
|
159
|
+
function writeDispatches(projectPath, records) {
|
|
160
|
+
const file = dispatchLedgerPath(projectPath);
|
|
161
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
162
|
+
const body = records.map((record) => JSON.stringify(record)).join('\n');
|
|
163
|
+
const tmp = `${file}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`;
|
|
164
|
+
writeFileSync(tmp, body === '' ? '' : `${body}\n`, 'utf-8');
|
|
165
|
+
renameSync(tmp, file);
|
|
166
|
+
return file;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* 推下一条 `dispatchId`(`d-0001` 形式;读现有记录的最大序号 +1)。
|
|
171
|
+
* @param {Array<Record<string, any>>} records
|
|
172
|
+
* @returns {string}
|
|
173
|
+
*/
|
|
174
|
+
function nextDispatchId(records) {
|
|
175
|
+
let max = 0;
|
|
176
|
+
for (const record of records) {
|
|
177
|
+
const match = /^d-(\d+)$/.exec(record.dispatchId);
|
|
178
|
+
if (match !== null) max = Math.max(max, Number(match[1]));
|
|
179
|
+
}
|
|
180
|
+
return `d-${String(max + 1).padStart(4, '0')}`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 追加一条派发记录(顺带 24h / 200 行清理)。
|
|
185
|
+
*
|
|
186
|
+
* 去重:同 `leadSessionId + taskId + goal` 且时间差 ≤ 5 分钟 → 返回既有记录
|
|
187
|
+
* 的 `dispatchId`,**不追加新行**(防模型重试造成假派发证据)。
|
|
188
|
+
*
|
|
189
|
+
* @param {string} projectPath
|
|
190
|
+
* @param {Record<string, unknown>} record
|
|
191
|
+
* @param {{ now?: number }} [options] `now` 注入便于单测(缺省 `Date.now()`)
|
|
192
|
+
* @returns {{ dispatchId: string, path: string, duplicate: boolean }}
|
|
193
|
+
*/
|
|
194
|
+
export function appendDispatch(projectPath, record = {}, options = {}) {
|
|
195
|
+
const now = Number.isFinite(options.now) ? /** @type {number} */ (options.now) : Date.now();
|
|
196
|
+
const incoming = normalizeRecord({
|
|
197
|
+
...record,
|
|
198
|
+
ts: asString(record.ts) || new Date(now).toISOString(),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const existing = readAllDispatches(projectPath);
|
|
202
|
+
|
|
203
|
+
for (let index = existing.length - 1; index >= 0; index -= 1) {
|
|
204
|
+
const previous = existing[index];
|
|
205
|
+
if (
|
|
206
|
+
previous.leadSessionId === incoming.leadSessionId
|
|
207
|
+
&& previous.taskId === incoming.taskId
|
|
208
|
+
&& previous.goal === incoming.goal
|
|
209
|
+
) {
|
|
210
|
+
const at = Date.parse(previous.ts);
|
|
211
|
+
if (Number.isFinite(at) && Math.abs(now - at) <= DISPATCH_DEDUP_WINDOW_MS) {
|
|
212
|
+
return { dispatchId: previous.dispatchId, path: dispatchLedgerPath(projectPath), duplicate: true };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
incoming.dispatchId = nextDispatchId(existing);
|
|
218
|
+
const kept = pruneRecords([...existing, incoming], now);
|
|
219
|
+
const path = writeDispatches(projectPath, kept);
|
|
220
|
+
return { dispatchId: incoming.dispatchId, path, duplicate: false };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 清理超龄 / 超上限记录(无变化时不重写文件)。
|
|
225
|
+
* @param {string} projectPath
|
|
226
|
+
* @param {{ now?: number }} [options]
|
|
227
|
+
* @returns {{ path: string, total: number, kept: number, removed: number }}
|
|
228
|
+
*/
|
|
229
|
+
export function pruneDispatches(projectPath, options = {}) {
|
|
230
|
+
const now = Number.isFinite(options.now) ? /** @type {number} */ (options.now) : Date.now();
|
|
231
|
+
const records = readAllDispatches(projectPath);
|
|
232
|
+
const kept = pruneRecords(records, now);
|
|
233
|
+
if (kept.length !== records.length) writeDispatches(projectPath, kept);
|
|
234
|
+
return {
|
|
235
|
+
path: dispatchLedgerPath(projectPath),
|
|
236
|
+
total: records.length,
|
|
237
|
+
kept: kept.length,
|
|
238
|
+
removed: records.length - kept.length,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** `feel_status.dispatch.records` 暴露的最近条数(足够证明「派发过」,不撑上下文)。 */
|
|
243
|
+
export const DISPATCH_STATUS_RECENT = 5;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 台账里一条记录的摘要(`feel_status.dispatch.records` 的元素)。
|
|
247
|
+
* @param {Record<string, any>} record 已归一化的台账行
|
|
248
|
+
* @returns {Record<string, any>}
|
|
249
|
+
*/
|
|
250
|
+
function summarizeDispatch(record) {
|
|
251
|
+
return {
|
|
252
|
+
dispatchId: record.dispatchId,
|
|
253
|
+
ts: record.ts,
|
|
254
|
+
stage: record.stage,
|
|
255
|
+
phase: record.phase,
|
|
256
|
+
targetAgent: record.targetAgent,
|
|
257
|
+
role: record.role,
|
|
258
|
+
taskId: record.taskId,
|
|
259
|
+
goal: record.goal,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 派发汇总(`feel_status.dispatch` 的数据源)。
|
|
265
|
+
*
|
|
266
|
+
* - `required`:恒 `true`——**提示级**(用户裁定 ②:只做台账 + 强提示,不做硬拦);
|
|
267
|
+
* - `total`:台账总行数;
|
|
268
|
+
* - `sincePhase`:当前 `stage` + `phase` 范围内的派发条数;
|
|
269
|
+
* - `missingRoles`:当前 `stage` + `phase` 范围内**尚未出现**的角色
|
|
270
|
+
* (五个闭集角色,固定顺序);
|
|
271
|
+
* - `records`:最近 `DISPATCH_STATUS_RECENT` 条派发摘要(A7 的 `records` 证据面)。
|
|
272
|
+
*
|
|
273
|
+
* @param {string} projectPath
|
|
274
|
+
* @param {{ stage?: string, phase?: string }} [options]
|
|
275
|
+
* @returns {{ required: true, total: number, sincePhase: number, missingRoles: string[], records: Array<Record<string, any>> }}
|
|
276
|
+
*/
|
|
277
|
+
export function dispatchSummary(projectPath, options = {}) {
|
|
278
|
+
const records = readAllDispatches(projectPath);
|
|
279
|
+
const stage = typeof options.stage === 'string' ? options.stage : '';
|
|
280
|
+
const phase = typeof options.phase === 'string' ? options.phase : '';
|
|
281
|
+
|
|
282
|
+
const stageScoped = stage === '' ? records : records.filter((record) => record.stage === stage);
|
|
283
|
+
const phaseScoped = phase === '' ? stageScoped : stageScoped.filter((record) => record.phase === phase);
|
|
284
|
+
const roles = new Set(phaseScoped.map((record) => record.role));
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
required: true,
|
|
288
|
+
total: records.length,
|
|
289
|
+
sincePhase: phaseScoped.length,
|
|
290
|
+
missingRoles: DISPATCH_ROLES.filter((role) => !roles.has(role)),
|
|
291
|
+
records: records.slice(-DISPATCH_STATUS_RECENT).map(summarizeDispatch),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 派发 / 返回契约(v1.
|
|
2
|
+
* 派发 / 返回契约(v1.6.0 / REQ-057)
|
|
3
3
|
*
|
|
4
4
|
* Feel 派发给 subagent 的能力/边界/返回格式模板。
|
|
5
5
|
* 目的:主会话不把子任务细节留在自己的上下文里;子 agent 不重复探索、不读写状态文件。
|
|
6
|
+
*
|
|
7
|
+
* v1.6.0 / T9 step2:`goal` 与 `boundaries.write` 改为**用真实快照填充**
|
|
8
|
+
* (stage / phase / phaseLabel / responsibleAgent / 关联需求),不再输出
|
|
9
|
+
* 泛型占位句——占位文案会被模型原样粘进 subagent prompt,等于没派发。
|
|
10
|
+
* `returnFormat` 是固定契约(≤10 行),不由快照派生。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 取当前阶段关联需求(**只用快照已有字段**,零新增 I/O)。
|
|
15
|
+
*
|
|
16
|
+
* 优先级:
|
|
17
|
+
* 1. `snapshot.recovery.requirement`(CLI 交接标记,`flow` 侧的权威值);
|
|
18
|
+
* 2. 回退 `snapshot.stages[*].requirementId`(`flow status --json` 的阶段条目)。
|
|
19
|
+
*
|
|
20
|
+
* @param {Record<string, any>} snapshot readSnapshot 结果
|
|
21
|
+
* @returns {string} 需求 ID;取不到 → 空串
|
|
6
22
|
*/
|
|
23
|
+
function requirementOf(snapshot) {
|
|
24
|
+
const recovery = snapshot?.recovery?.requirement;
|
|
25
|
+
if (typeof recovery === 'string' && recovery !== '') return recovery;
|
|
26
|
+
const stageId = snapshot?.focus?.stage;
|
|
27
|
+
const stages = Array.isArray(snapshot?.stages) ? snapshot.stages : [];
|
|
28
|
+
const stage = stages.find((entry) => entry?.id === stageId || entry?.name === stageId);
|
|
29
|
+
return typeof stage?.requirementId === 'string' ? stage.requirementId : '';
|
|
30
|
+
}
|
|
7
31
|
|
|
8
32
|
/**
|
|
9
33
|
* @param {Record<string, any>} snapshot readSnapshot 结果
|
|
@@ -11,16 +35,40 @@
|
|
|
11
35
|
*/
|
|
12
36
|
export function buildDispatchTemplate(snapshot) {
|
|
13
37
|
const focus = snapshot?.focus ?? {};
|
|
14
|
-
const
|
|
15
|
-
const
|
|
38
|
+
const hasFocus = typeof focus.stage === 'string' && focus.stage !== '';
|
|
39
|
+
const stage = hasFocus ? focus.stage : '(无活跃阶段)';
|
|
40
|
+
const phase = typeof focus.phase === 'string' && focus.phase !== '' ? focus.phase : (hasFocus ? '(无相位)' : '(无)');
|
|
41
|
+
const phaseLabel = typeof focus.phaseLabel === 'string' && focus.phaseLabel !== '' ? focus.phaseLabel : phase;
|
|
42
|
+
const agent = typeof focus.responsibleAgent === 'string' && focus.responsibleAgent !== ''
|
|
43
|
+
? focus.responsibleAgent
|
|
44
|
+
: '(未知角色)';
|
|
45
|
+
const requirement = requirementOf(snapshot);
|
|
46
|
+
const suggested = typeof focus.suggestedCommand === 'string' ? focus.suggestedCommand : '';
|
|
47
|
+
|
|
48
|
+
// goal 用真实调度上下文填充:做什么(阶段/相位)、给谁(Agent)、哪个需求、怎么算完成。
|
|
49
|
+
// 无活跃阶段时不留占位句,而是把「现在没有可派发对象」说清楚(避免被原样粘进 prompt)。
|
|
50
|
+
const goal = !hasFocus
|
|
51
|
+
? '当前无活跃阶段:先用 feel_status 选定阶段/需求,再据此填写一句话目标(须可验收:命令 + 退出码)'
|
|
52
|
+
: (requirement === ''
|
|
53
|
+
? `在 ${stage} 的 ${phase}(${phaseLabel})由 ${agent} 交付本相位产物;完成判据须可验收(给出命令与退出码)`
|
|
54
|
+
: `在 ${stage} 的 ${phase}(${phaseLabel})由 ${agent} 完成需求 ${requirement} 的本相位产物;完成判据须可验收(给出命令与退出码)`);
|
|
55
|
+
|
|
16
56
|
return {
|
|
17
|
-
goal
|
|
57
|
+
goal,
|
|
18
58
|
context: [
|
|
19
|
-
`阶段:${stage} / ${phase}`,
|
|
59
|
+
`阶段:${stage} / ${phase}(${phaseLabel});负责 Agent:${agent}`,
|
|
60
|
+
requirement === '' ? '关联需求:无(按阶段产物验收)' : `关联需求:${requirement}`,
|
|
61
|
+
...(suggested === '' ? [] : [`CLI 权威下一步:${suggested}`]),
|
|
20
62
|
'只附必要文件路径(plan / op / REV / 目标源码),不附整目录或整仓内容',
|
|
21
63
|
],
|
|
22
64
|
boundaries: {
|
|
23
|
-
|
|
65
|
+
// 写面按当前阶段派生:本任务文件由派发方在 goal 里点明,未点明的一律只读。
|
|
66
|
+
write: hasFocus
|
|
67
|
+
? [
|
|
68
|
+
`${stage} / ${phase} 下本任务的文件(派发时点明具体路径;未点明的一律只读)`,
|
|
69
|
+
'.openfeel/plan/**(仅计划/方案文档;需求正文走 feel_req action=body)',
|
|
70
|
+
]
|
|
71
|
+
: ['(无活跃阶段:无可写面;先开阶段或接取需求)'],
|
|
24
72
|
neverRead: ['dev_last*', 'dev/current.md', 'status.md', 'flow.json'],
|
|
25
73
|
neverWrite: ['dev_last*', 'dev/current.md', 'status.md', 'flow.json'],
|
|
26
74
|
escalate: '越界或需要用户决策时立即停止并回报,不要自行扩大范围',
|