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.
Files changed (81) hide show
  1. package/README.en.md +7 -0
  2. package/README.zh-CN.md +7 -0
  3. package/dist/commands/flow.d.ts.map +1 -1
  4. package/dist/commands/flow.js +117 -23
  5. package/dist/commands/flow.js.map +1 -1
  6. package/dist/commands/lint.d.ts +3 -1
  7. package/dist/commands/lint.d.ts.map +1 -1
  8. package/dist/commands/lint.js +96 -0
  9. package/dist/commands/lint.js.map +1 -1
  10. package/dist/commands/req.d.ts.map +1 -1
  11. package/dist/commands/req.js +378 -27
  12. package/dist/commands/req.js.map +1 -1
  13. package/dist/commands/stage.d.ts.map +1 -1
  14. package/dist/commands/stage.js +19 -0
  15. package/dist/commands/stage.js.map +1 -1
  16. package/dist/core/dev-status.d.ts +25 -0
  17. package/dist/core/dev-status.d.ts.map +1 -1
  18. package/dist/core/dev-status.js +35 -0
  19. package/dist/core/dev-status.js.map +1 -1
  20. package/dist/core/errors.d.ts +13 -3
  21. package/dist/core/errors.d.ts.map +1 -1
  22. package/dist/core/errors.js +9 -3
  23. package/dist/core/errors.js.map +1 -1
  24. package/dist/core/flow-manager.d.ts +109 -3
  25. package/dist/core/flow-manager.d.ts.map +1 -1
  26. package/dist/core/flow-manager.js +326 -14
  27. package/dist/core/flow-manager.js.map +1 -1
  28. package/dist/core/i18n-data/en.d.ts.map +1 -1
  29. package/dist/core/i18n-data/en.js +54 -2
  30. package/dist/core/i18n-data/en.js.map +1 -1
  31. package/dist/core/i18n-data/zh-CN.d.ts.map +1 -1
  32. package/dist/core/i18n-data/zh-CN.js +54 -2
  33. package/dist/core/i18n-data/zh-CN.js.map +1 -1
  34. package/dist/core/lint-req.d.ts +17 -1
  35. package/dist/core/lint-req.d.ts.map +1 -1
  36. package/dist/core/lint-req.js +14 -2
  37. package/dist/core/lint-req.js.map +1 -1
  38. package/dist/core/plan/body-lint.d.ts +58 -0
  39. package/dist/core/plan/body-lint.d.ts.map +1 -0
  40. package/dist/core/plan/body-lint.js +197 -0
  41. package/dist/core/plan/body-lint.js.map +1 -0
  42. package/dist/core/plan/filled.d.ts +143 -0
  43. package/dist/core/plan/filled.d.ts.map +1 -0
  44. package/dist/core/plan/filled.js +244 -0
  45. package/dist/core/plan/filled.js.map +1 -0
  46. package/dist/core/plan/path.d.ts +24 -0
  47. package/dist/core/plan/path.d.ts.map +1 -1
  48. package/dist/core/plan/path.js +56 -0
  49. package/dist/core/plan/path.js.map +1 -1
  50. package/dist/core/req/aggregate.d.ts.map +1 -1
  51. package/dist/core/req/aggregate.js +5 -0
  52. package/dist/core/req/aggregate.js.map +1 -1
  53. package/dist/core/req/body-file.d.ts +66 -0
  54. package/dist/core/req/body-file.d.ts.map +1 -1
  55. package/dist/core/req/body-file.js +184 -2
  56. package/dist/core/req/body-file.js.map +1 -1
  57. package/dist/core/req/requirement-ops.d.ts +128 -14
  58. package/dist/core/req/requirement-ops.d.ts.map +1 -1
  59. package/dist/core/req/requirement-ops.js +341 -16
  60. package/dist/core/req/requirement-ops.js.map +1 -1
  61. package/dist/core/req/types.d.ts +55 -0
  62. package/dist/core/req/types.d.ts.map +1 -1
  63. package/dist/core/template-loader.d.ts.map +1 -1
  64. package/dist/core/template-loader.js +75 -0
  65. package/dist/core/template-loader.js.map +1 -1
  66. package/dsh/ACTION-GUIDE.md +41 -8
  67. package/dsh/ADAPTER.md +58 -13
  68. package/dsh/README.md +45 -24
  69. package/dsh/docs/compat/persistence.md +13 -0
  70. package/dsh/docs/compat/pipeline.md +12 -0
  71. package/dsh/docs/compat/req.md +14 -0
  72. package/dsh/docs/compat/stage.md +13 -0
  73. package/dsh/lib/adapters/dispatch-ledger.js +293 -0
  74. package/dsh/lib/adapters/dispatch.js +54 -6
  75. package/dsh/lib/adapters/next-action.js +336 -0
  76. package/dsh/lib/guard.js +9 -2
  77. package/dsh/lib/index.js +37 -0
  78. package/dsh/lib/surface/prompt.js +62 -178
  79. package/dsh/lib/tools/index.js +434 -10
  80. package/dsh/package.json +2 -2
  81. package/package.json +1 -1
@@ -1,10 +1,11 @@
1
+ import { existsSync, rmSync } from 'node:fs';
1
2
  import { t, getCliLang } from '../core/i18n.js';
2
3
  import { enforcePreflightOrFail } from './shared/preflight-gate.js';
3
4
  import { FlowManager, isFlowConcurrentError } from '../core/flow-manager.js';
4
5
  import { handleConcurrentConflict } from './shared/errors.js';
5
- import { addRequirement, getRequirement, getRequirements, listRequirements, claimRequirement, releaseRequirement, updateRequirement, advanceRequirement, linkRequirement, getAllowedNextStatuses, splitRequirement, requirementDoneBlocker, recordRequirementReview, recordRequirementVerification, releaseCheckRequirements, rolloverRequirements, isTerminalRequirementStatus, waiveRequirement, revokeRequirementWaiver, markRequirementTrivial, clearRequirementTrivial, raiseRequirementSeqFloor, } from '../core/req/requirement-ops.js';
6
+ import { addRequirement, getRequirement, getRequirements, listRequirements, claimRequirement, releaseRequirement, updateRequirement, advanceRequirement, linkRequirement, getAllowedNextStatuses, splitRequirement, requirementDoneBlocker, recordRequirementReview, recordRequirementVerification, releaseCheckRequirements, rolloverRequirements, isTerminalRequirementStatus, waiveRequirement, revokeRequirementWaiver, markRequirementTrivial, clearRequirementTrivial, raiseRequirementSeqFloor, forceRequirementPlanDeviation, forceRequirementBodyWaiver, forceRequirementPlanWaiver, requirementBodyEmptySections, } from '../core/req/requirement-ops.js';
6
7
  import { REQ_STATUSES, REQ_ID_PATTERN } from '../core/req/types.js';
7
- import { writeRequirementBodySkeleton } from '../core/req/body-file.js';
8
+ import { writeRequirementBodySkeleton, updateRequirementBody, getRequirementBodyPath, RequirementBodyUpdateError } from '../core/req/body-file.js';
8
9
  import { computeRequirementAggregate, listLinkedStages } from '../core/req/aggregate.js';
9
10
  import { stageRequirementIds } from '../core/req/stage-links.js';
10
11
  import { findArchivedRequirement, listArchivedRequirements, archivedRequirementMaxSeq } from '../core/flow-archive/archive-ops.js';
@@ -12,6 +13,7 @@ import { withSchemaVersion, emitJson } from './shared/json-output.js';
12
13
  import { getUserName } from '../core/workspace/identity.js';
13
14
  import { normalizeStageId } from '../core/plan/path.js';
14
15
  import { getSessionId, resolveActorName } from '../core/session.js';
16
+ import { maybeSyncDevStatus } from '../core/dev-status.js';
15
17
  /** 当前会话标识(写入审查/验证记录,用于人机区分与回溯;v1.5.24 / REQ-049) */
16
18
  function currentSession() {
17
19
  return getSessionId({ projectPath: process.cwd() });
@@ -92,6 +94,27 @@ function doneGateMessage(lang, data, id, current) {
92
94
  }
93
95
  return t('req.err.doneGateTmpl', lang, { id, current });
94
96
  }
97
+ /**
98
+ * 正文门拒绝文案(v1.6.0 / stage-132 T4)。
99
+ * 判据单源 = `requirementBodyBlocker`(引擎);本层只把「未写实的小节名」拼进 i18n 模板,
100
+ * 并给出可复制的 `req body` 补写命令(A2 的「提示用 req body 补写」要求)。
101
+ */
102
+ function bodyGateMessage(lang, data, id) {
103
+ const req = getRequirement(data, id);
104
+ const sections = req ? requirementBodyEmptySections(process.cwd(), req) : [];
105
+ return t('req.err.bodyEmptyTmpl', lang, {
106
+ id,
107
+ sections: sections.length > 0 ? sections.join('、') : '摘要、目标与验收',
108
+ });
109
+ }
110
+ /**
111
+ * 需求级计划门拒绝文案(v1.6.0 / stage-132 T7)。
112
+ * `openfeel req plan` 尚不存在,因此文案给出**按模板创建文件**的具体路径与必备小节
113
+ * (真实指引优于虚构命令)。
114
+ */
115
+ function planGateMessage(lang, id) {
116
+ return t('req.err.planMissingTmpl', lang, { id });
117
+ }
95
118
  /**
96
119
  * 保存并收敛并发:成功返回 true;并发冲突 → 单点处理(JSON 置码 2 返回 / 非 JSON exit 2),
97
120
  * 其他异常 → 通用文案 exit 1 并返回 false。返回 false 时调用方须早返回。
@@ -111,6 +134,17 @@ function saveOrFail(mgr, lang) {
111
134
  return false;
112
135
  }
113
136
  }
137
+ /**
138
+ * v1.6.0 / REQ-059 T8:**写成功出口**自动同步开发账本(`.openfeel/dev/**` + `dev_last.md`)。
139
+ * 需求写操作已成功,因此同步失败**不改变退出码**,只输出一行 stderr(不再静默吞掉)。
140
+ * 调用点仅限写命令成功出口(advance / complete / review / verify / body),读命令不调。
141
+ */
142
+ function syncDevAfterWrite(projectPath, lang) {
143
+ const sync = maybeSyncDevStatus(projectPath);
144
+ if (sync.error !== undefined) {
145
+ console.warn(t('flow.dev.syncFailedTmpl', lang, { err: sync.error }));
146
+ }
147
+ }
114
148
  /** `req` 命令组注册入口 */
115
149
  export function registerReqCommand(program) {
116
150
  const req = program
@@ -126,6 +160,11 @@ export function registerReqCommand(program) {
126
160
  .option('--claim', '创建后立即认领(v1.5.23:一次开单+认领)')
127
161
  .option('--stage <stageId>', '创建后立即关联到该阶段(v1.5.23:一次开单+关联)')
128
162
  .option('--start', '创建后直接进入 in_progress(自动 scheduled → in_progress;v1.5.25 / REQ-053)')
163
+ .option('--summary <md>', '正文 ## 摘要 小节(v1.6.0:正文写实;与 --goal/--acceptance 配合即可一步写实)')
164
+ .option('--problem <md>', '正文 ## 问题 小节(v1.6.0:正文写实)')
165
+ .option('--goal <md>', '正文 ## 目标与验收 → 目标 子节(v1.6.0:正文写实)')
166
+ .option('--acceptance <md>', '正文 ## 目标与验收 → 验收 子节(v1.6.0:正文写实)')
167
+ .option('--plan <md>', '正文 ## 初步规划 小节(v1.6.0:正文写实)')
129
168
  .action((title, options) => {
130
169
  const lang = getCliLang(process.cwd());
131
170
  const mgr = createManager();
@@ -150,10 +189,13 @@ export function registerReqCommand(program) {
150
189
  workflow_mode: options.workflowMode,
151
190
  });
152
191
  // v1.5.23 / REQ-043(六期反馈 #1):一次开单 + 认领 + 关联
192
+ // v1.6.0 / REV-013:claim / advance 都**显式传项目根**(不靠 cwd 推导)——
193
+ // claim 自 REV-013 起不校验正文(认领 ≠ 开工),但传根保证调用面同形;
194
+ // advance 的正文门(scheduled / in_progress / done)必须能定位正文文件。
153
195
  let claimedOwner;
154
196
  if (options.claim === true) {
155
197
  const owner = getUserName(process.cwd());
156
- const c = claimRequirement(data, created.id, owner);
198
+ const c = claimRequirement(data, created.id, owner, { projectPath: process.cwd() });
157
199
  if (!c.ok) {
158
200
  failGeneric(lang, new Error(t('req.add.claimFailedTmpl', lang, { id: created.id })));
159
201
  return;
@@ -180,13 +222,77 @@ export function registerReqCommand(program) {
180
222
  }
181
223
  linkedStage = stageKey;
182
224
  }
225
+ // 正文骨架 + 可选业务小节:**先于** `--start` 落盘。
226
+ // 原因(REV-013):`add --start` 走真实状态流转,正文门必须判到「本轮写下的正文」
227
+ // 而不是「还没有正文文件 ⇒ 无正文可判 ⇒ 放行」的空档;同时 `--goal/--acceptance`
228
+ // 等先写入,带正文内容的 `--start` 不会被误拦。
229
+ let bodyPath;
230
+ const bodyFilePath = getRequirementBodyPath(process.cwd(), created.id);
231
+ const bodyExistedBefore = existsSync(bodyFilePath);
232
+ /** 失败路径清理本轮新建的正文文件(不把孤儿正文留给下一次同 ID 复用) */
233
+ const discardNewBody = () => {
234
+ if (bodyExistedBefore) {
235
+ return;
236
+ }
237
+ try {
238
+ rmSync(bodyFilePath, { force: true });
239
+ }
240
+ catch { /* 清理失败不掩盖主错误 */ }
241
+ };
242
+ try {
243
+ bodyPath = writeRequirementBodySkeleton(process.cwd(), created);
244
+ }
245
+ catch (err) {
246
+ failGeneric(lang, err);
247
+ return;
248
+ }
249
+ // v1.6.0-stage-132 / T2:可选正文业务小节(未给的保持骨架占位;元信息小节不碰)
250
+ try {
251
+ const bodyActor = resolveActorName(process.cwd(), undefined);
252
+ const writeSection = (section, text) => {
253
+ updateRequirementBody(process.cwd(), created, {
254
+ section,
255
+ text,
256
+ createSectionIfMissing: true,
257
+ by: bodyActor,
258
+ });
259
+ };
260
+ if (options.summary !== undefined) {
261
+ // v1.6.0-stage-132 / T2(REQ-061):## 摘要 与 ## 目标与验收 都写实 ⇒ add --start 可一步过正文门
262
+ writeSection('摘要', options.summary);
263
+ }
264
+ if (options.problem !== undefined) {
265
+ writeSection('问题', options.problem);
266
+ }
267
+ if (options.goal !== undefined || options.acceptance !== undefined) {
268
+ // --goal 与 --acceptance 合并进 目标与验收 的两个子标题
269
+ const parts = [];
270
+ if (options.goal !== undefined) {
271
+ parts.push(`### 目标\n\n${options.goal.trim()}`);
272
+ }
273
+ if (options.acceptance !== undefined) {
274
+ parts.push(`### 验收\n\n${options.acceptance.trim()}`);
275
+ }
276
+ writeSection('目标与验收', parts.join('\n\n'));
277
+ }
278
+ if (options.plan !== undefined) {
279
+ writeSection('初步规划', options.plan);
280
+ }
281
+ }
282
+ catch (err) {
283
+ discardNewBody();
284
+ failGeneric(lang, err);
285
+ return;
286
+ }
183
287
  // v1.5.25 / REQ-053:一次开单到 in_progress(scheduled → in_progress 属引擎流转,
184
- // 命令层不另写判据;失败则整体不 save)
288
+ // 命令层不另写判据;失败则整体不 save,并清掉本轮新建的正文文件)
289
+ // v1.6.0 / REV-013:显式传项目根 —— 空壳正文在 scheduled 步即被正文门拦下。
185
290
  let startedStatus;
186
291
  if (options.start === true) {
187
292
  for (const step of ['scheduled', 'in_progress']) {
188
- const moved = advanceRequirement(data, created.id, step);
293
+ const moved = advanceRequirement(data, created.id, step, { projectPath: process.cwd() });
189
294
  if (!moved.ok) {
295
+ discardNewBody();
190
296
  failCode(lang, moved.code, {
191
297
  not_found: t('req.err.notFoundTmpl', lang, { id: created.id }),
192
298
  invalid_field: t('req.err.invalidFieldTmpl', lang, { id: created.id }),
@@ -194,21 +300,14 @@ export function registerReqCommand(program) {
194
300
  id: created.id, to: step, current: created.status, targets: getAllowedNextStatuses(created.status).join(', '),
195
301
  }),
196
302
  general_mode_conflict: t('req.err.generalModeConflictTmpl', lang, { id: created.id }),
303
+ body_empty: bodyGateMessage(lang, data, created.id),
304
+ plan_missing: planGateMessage(lang, created.id),
197
305
  });
198
306
  return;
199
307
  }
200
308
  }
201
309
  startedStatus = 'in_progress';
202
310
  }
203
- // 正文骨架:认领/关联都成功后再落盘(失败路径不留孤儿正文)
204
- let bodyPath;
205
- try {
206
- bodyPath = writeRequirementBodySkeleton(process.cwd(), created);
207
- }
208
- catch (err) {
209
- failGeneric(lang, err);
210
- return;
211
- }
212
311
  if (!saveOrFail(mgr, lang)) {
213
312
  return;
214
313
  }
@@ -426,11 +525,12 @@ export function registerReqCommand(program) {
426
525
  // 关联阶段 = 原始只读枚举(零聚合计算 / 零阶段推进字段读取——归后续阶段);命令层输出面复用单点过滤(REV-97-006)
427
526
  emitRequirement(active, listLinkedStages(data, id).map((l) => l.id), getRequirements(data).filter((r) => r.parent_id === id), null);
428
527
  });
429
- // ── req claim <id> [--owner <name>] ──
528
+ // ── req claim <id> [--owner <name>] [--force] ──
430
529
  req
431
530
  .command('claim <id>')
432
531
  .description('认领需求(占用校验;已被他人认领则拒绝)')
433
532
  .option('--owner <owner>', '认领人(缺省:.openfeel/.info.json user → git config user.name)')
533
+ .option('--force', '正文门留痕放行(写 body_waiver + 审计 requirement_body_forced;仍应先补写正文)')
434
534
  .action((id, options) => {
435
535
  const lang = getCliLang(process.cwd());
436
536
  const mgr = createManager();
@@ -459,14 +559,34 @@ export function registerReqCommand(program) {
459
559
  }
460
560
  owner = resolved;
461
561
  }
462
- // 返回码分流(命令层仅映射,零校验):占用 / 终态 / owner 空串均由引擎单点判定
463
- const r = claimRequirement(data, id, owner);
562
+ const projectPath = process.cwd();
563
+ // 返回码分流(命令层仅映射,零校验):占用 / 终态均由引擎单点判定。
564
+ // v1.6.0 / REV-013:claim **不再校验正文**(认领 ≠ 开工),因此 `body_empty` 分支
565
+ // 目前不可达——保留 `--force` 选项与分支只为兼容旧脚本(选项键仍在 help 锁内)。
566
+ let r = claimRequirement(data, id, owner, { projectPath });
567
+ let bodyForced = false;
568
+ if (!r.ok && r.code === 'body_empty' && options.force === true) {
569
+ // v1.6.0 / T4(A2c):--force = 留痕放行(body_waiver + 审计),随后用同一谓词重试
570
+ const forced = forceRequirementBodyWaiver(data, id, {
571
+ by: resolveActorName(projectPath), reason: 'claim-force', gate: 'claim',
572
+ });
573
+ if (!forced.ok) {
574
+ failCode(lang, forced.code, {
575
+ not_found: t('req.err.notFoundTmpl', lang, { id }),
576
+ invalid_status: t('req.claim.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
577
+ });
578
+ return;
579
+ }
580
+ r = claimRequirement(data, id, owner, { projectPath });
581
+ bodyForced = r.ok;
582
+ }
464
583
  if (!r.ok) {
465
584
  failCode(lang, r.code, {
466
585
  not_found: t('req.err.notFoundTmpl', lang, { id }),
467
586
  already_claimed: t('req.err.alreadyClaimedTmpl', lang, { id }),
468
587
  invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
469
588
  invalid_status: t('req.claim.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
589
+ body_empty: bodyGateMessage(lang, data, id),
470
590
  });
471
591
  return;
472
592
  }
@@ -478,7 +598,8 @@ export function registerReqCommand(program) {
478
598
  if (!saveOrFail(mgr, lang)) {
479
599
  return;
480
600
  }
481
- console.log(t('req.claim.doneTmpl', lang, { id, owner }));
601
+ console.log(t('req.claim.doneTmpl', lang, { id, owner })
602
+ + (bodyForced ? t('req.claim.bodyForcedSuffix', lang) : ''));
482
603
  });
483
604
  // ── req release <id> ──
484
605
  req
@@ -555,7 +676,7 @@ export function registerReqCommand(program) {
555
676
  target_version: options.targetVersion,
556
677
  priority: options.priority,
557
678
  workflow_mode: options.workflowMode,
558
- });
679
+ }, { projectPath: process.cwd() });
559
680
  if (!r.ok) {
560
681
  const current = getRequirement(data, id)?.status ?? '';
561
682
  // done 门专用文案(stage-93 BUG-002):静态表放行 done 而仍被拒 ⇒ 唯一可能是完成门
@@ -564,6 +685,11 @@ export function registerReqCommand(program) {
564
685
  failCode(lang, r.code, {
565
686
  not_found: t('req.err.notFoundTmpl', lang, { id }),
566
687
  invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
688
+ // v1.6.0 / REQ-056 T6:`set --status done` 与 advance 同判据(done 门通过后才可能到这)
689
+ plan_deviation: t('req.err.planDeviationTmpl', lang, { id }),
690
+ // v1.6.0 / stage-132 T4 · T7:正文门 / 需求级计划门(`set` 无 --force,文案指向 advance --force)
691
+ body_empty: bodyGateMessage(lang, data, id),
692
+ plan_missing: planGateMessage(lang, id),
567
693
  invalid_status: doneGate
568
694
  ? doneGateMessage(lang, data, id, current)
569
695
  : t('req.err.invalidStatusTmpl', lang, {
@@ -676,11 +802,12 @@ export function registerReqCommand(program) {
676
802
  console.log(t('req.link.doneTmpl', lang, { stage: stageKey, id: requirementId ?? '' }));
677
803
  }
678
804
  });
679
- // ── req advance <id> --to <status> ──
805
+ // ── req advance <id> --to <status> [--force] ──
680
806
  req
681
807
  .command('advance <id>')
682
808
  .description('显式推进需求状态(合法目标由引擎流转表判定;done:零关联可直接完成,关联阶段进入 exec_running 及之后相位即可完成)')
683
809
  .requiredOption('--to <status>', '目标状态(合法目标由引擎判定)')
810
+ .option('--force', '门留痕放行(正文/计划门写 waiver、计划偏差 +1;均留审计,文件仍须补写)')
684
811
  .action((id, options) => {
685
812
  const lang = getCliLang(process.cwd());
686
813
  const mgr = createManager();
@@ -699,8 +826,48 @@ export function registerReqCommand(program) {
699
826
  // v1.5.6-stage-114:写前 preflight(ID 校验已在门前)
700
827
  if (!enforcePreflightOrFail(process.cwd(), lang))
701
828
  return;
702
- // 命令层零校验:合法目标 + done 门均在引擎单点
703
- const r = advanceRequirement(data, id, options.to);
829
+ const projectPath = process.cwd();
830
+ // v1.6.0 / REQ-056 T6:未盖章历史需求(plan? 缺省)在 done 时**放行但提示**——
831
+ // 不阻塞存量,审计另记 `plan_unstamped:true`(在 requirement_status 条目里)。
832
+ const planUnstamped = options.to === 'done' && getRequirement(data, id)?.plan === undefined;
833
+ // 命令层零校验:合法目标 + 正文门 + 计划门 + done 门 + 计划偏差门均在引擎单点
834
+ let r = advanceRequirement(data, id, options.to, { projectPath });
835
+ let planDeviationForced = false;
836
+ let gateForced = false;
837
+ // v1.6.0 / stage-132 T4 · T7:正文门 / 计划门的 --force 通道——
838
+ // 写入 waiver(留痕)+ 审计后,用**同一谓词**重新求值(门本体不重写)。
839
+ // 同一次流转可能**连撞两门**(空壳正文 + 无计划):循环上限 = 门数(2),逐个留痕放行。
840
+ for (let i = 0; i < 2 && !r.ok && options.force === true
841
+ && (r.code === 'body_empty' || r.code === 'plan_missing'); i += 1) {
842
+ const forced = r.code === 'body_empty'
843
+ ? forceRequirementBodyWaiver(data, id, { by: resolveActorName(projectPath), reason: 'advance-force', gate: 'advance' })
844
+ : forceRequirementPlanWaiver(data, id, { by: resolveActorName(projectPath), reason: 'advance-force', gate: 'advance' });
845
+ if (!forced.ok) {
846
+ failCode(lang, forced.code, {
847
+ not_found: t('req.err.notFoundTmpl', lang, { id }),
848
+ invalid_status: t('req.err.invalidStatusTmpl', lang, {
849
+ id, to: options.to, current: before ?? '',
850
+ targets: before !== undefined ? getAllowedNextStatuses(before).join(', ') : '',
851
+ }),
852
+ });
853
+ return;
854
+ }
855
+ r = advanceRequirement(data, id, options.to, { projectPath });
856
+ gateForced = r.ok;
857
+ }
858
+ if (!r.ok && r.code === 'plan_deviation' && options.force === true) {
859
+ // 留痕放行:先记偏差次数 + 审计(判据本体不重写),再走同一门放行通道
860
+ const forced = forceRequirementPlanDeviation(data, id, { by: resolveActorName(projectPath) });
861
+ if (!forced.ok) {
862
+ failCode(lang, forced.code, {
863
+ not_found: t('req.err.notFoundTmpl', lang, { id }),
864
+ invalid_status: t('req.advance.forceRequiresStampTmpl', lang, { id }),
865
+ });
866
+ return;
867
+ }
868
+ r = advanceRequirement(data, id, options.to, { projectPath, allowPlanDeviation: true });
869
+ planDeviationForced = r.ok;
870
+ }
704
871
  if (!r.ok) {
705
872
  // done 门专用文案(stage-93 BUG-002):静态表放行 done 而仍被拒 ⇒ 唯一可能是完成门
706
873
  const doneGate = options.to === 'done'
@@ -708,6 +875,11 @@ export function registerReqCommand(program) {
708
875
  && getAllowedNextStatuses(before).includes('done');
709
876
  failCode(lang, r.code, {
710
877
  not_found: t('req.err.notFoundTmpl', lang, { id }),
878
+ // v1.6.0 / REQ-056 T6:计划被执行改动且 `## 偏差与回写` 未写实(done 门已通过后才可能到这)
879
+ plan_deviation: t('req.err.planDeviationTmpl', lang, { id }),
880
+ // v1.6.0 / stage-132 T4 · T7:正文门 / 需求级计划门(补写指引 + 可复制的命令)
881
+ body_empty: bodyGateMessage(lang, data, id),
882
+ plan_missing: planGateMessage(lang, id),
711
883
  invalid_status: doneGate
712
884
  ? doneGateMessage(lang, data, id, before ?? '')
713
885
  : t('req.err.invalidStatusTmpl', lang, {
@@ -726,7 +898,14 @@ export function registerReqCommand(program) {
726
898
  if (!saveOrFail(mgr, lang)) {
727
899
  return;
728
900
  }
729
- console.log(t('req.advance.doneTmpl', lang, { id, from: before ?? '', to: options.to }));
901
+ if (planUnstamped) {
902
+ console.warn(t('req.warn.planUnstampedTmpl', lang, { id }));
903
+ }
904
+ console.log(t('req.advance.doneTmpl', lang, { id, from: before ?? '', to: options.to })
905
+ + (planDeviationForced ? t('req.advance.planDeviationForcedSuffix', lang) : '')
906
+ + (gateForced ? t('req.advance.gateForcedSuffix', lang) : ''));
907
+ // v1.6.0 / REQ-059 T8:流转成功即自动同步开发账本
908
+ syncDevAfterWrite(projectPath, lang);
730
909
  });
731
910
  // ── req waive <id> --reason <text> [--by] [--revoke] ──(v1.5.23 / REQ-043 / 六期 #8)
732
911
  req
@@ -814,7 +993,7 @@ export function registerReqCommand(program) {
814
993
  ? t('req.trivial.revokedTmpl', lang, { id })
815
994
  : t('req.trivial.doneTmpl', lang, { id, reason: options.reason ?? '' }));
816
995
  });
817
- // ── req complete <id> --result pass --note <t> [--kind] [--evidence] [--by] [--independent|--self] ──
996
+ // ── req complete <id> --result pass --note <t> [--kind] [--evidence] [--by] [--independent|--self] [--force] ──
818
997
  // v1.5.23 / REQ-043(六期反馈 #1):一次收口 = review + verify + advance(done)。
819
998
  // 复用既有判据单点(recordRequirementReview / recordRequirementVerification / advanceRequirement
820
999
  // → canCompleteRequirement);任一步失败即返回,**不 save ⇒ flow.json 零变更**。
@@ -828,6 +1007,7 @@ export function registerReqCommand(program) {
828
1007
  .option('--evidence <path>', '证据(测试命令 / 报告路径 / 摘要)')
829
1008
  .option('--independent', '独立审查(推荐)')
830
1009
  .option('--self', '自我审查(非独立;归档摘要标注 self-review)')
1010
+ .option('--force', '门留痕放行(正文/计划门写 waiver + 审计;文件仍须补写)')
831
1011
  .action((id, options) => {
832
1012
  const lang = getCliLang(process.cwd());
833
1013
  const mgr = createManager();
@@ -858,14 +1038,41 @@ export function registerReqCommand(program) {
858
1038
  process.exitCode = 1;
859
1039
  return;
860
1040
  }
1041
+ const projectPath = process.cwd();
1042
+ /** 门的 --force 通道(T4 正文 / T7 计划):写 waiver + 审计后由调用方用同一谓词重试 */
1043
+ const forceGate = (code) => {
1044
+ const forced = code === 'body_empty'
1045
+ ? forceRequirementBodyWaiver(data, id, { by, reason: 'complete-force', gate: 'complete' })
1046
+ : forceRequirementPlanWaiver(data, id, { by, reason: 'complete-force', gate: 'complete' });
1047
+ if (!forced.ok) {
1048
+ failCode(lang, forced.code, {
1049
+ not_found: t('req.err.notFoundTmpl', lang, { id }),
1050
+ invalid_status: t('req.complete.statusTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
1051
+ });
1052
+ return false;
1053
+ }
1054
+ return true;
1055
+ };
1056
+ let gateForced = false;
861
1057
  for (const step of ['scheduled', 'in_progress']) {
862
1058
  if (stateNow !== 'draft' && stateNow !== 'scheduled')
863
1059
  break;
864
- const moved = advanceRequirement(data, id, step);
1060
+ let moved = advanceRequirement(data, id, step, { projectPath });
1061
+ // 同一流转可能连撞两门(正文 + 计划):循环上限 = 门数(2),逐个留痕放行
1062
+ for (let i = 0; i < 2 && !moved.ok && options.force === true
1063
+ && (moved.code === 'body_empty' || moved.code === 'plan_missing'); i += 1) {
1064
+ if (!forceGate(moved.code))
1065
+ return;
1066
+ moved = advanceRequirement(data, id, step, { projectPath });
1067
+ gateForced = moved.ok;
1068
+ }
865
1069
  if (!moved.ok) {
866
1070
  failCode(lang, moved.code, {
867
1071
  not_found: t('req.err.notFoundTmpl', lang, { id }),
868
1072
  invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
1073
+ // v1.6.0 / stage-132 T4 · T7:自动补链同样过正文门 / 计划门(不因「一条命令」而绕过)
1074
+ body_empty: bodyGateMessage(lang, data, id),
1075
+ plan_missing: planGateMessage(lang, id),
869
1076
  invalid_status: t('req.err.invalidStatusTmpl', lang, {
870
1077
  id, to: step, current: stateNow, targets: getAllowedNextStatuses(stateNow).join(', '),
871
1078
  }),
@@ -901,12 +1108,24 @@ export function registerReqCommand(program) {
901
1108
  return;
902
1109
  }
903
1110
  const current = getRequirement(data, id)?.status ?? '';
904
- const advanced = advanceRequirement(data, id, 'done');
1111
+ let advanced = advanceRequirement(data, id, 'done', { projectPath });
1112
+ for (let i = 0; i < 2 && !advanced.ok && options.force === true
1113
+ && (advanced.code === 'body_empty' || advanced.code === 'plan_missing'); i += 1) {
1114
+ if (!forceGate(advanced.code))
1115
+ return;
1116
+ advanced = advanceRequirement(data, id, 'done', { projectPath });
1117
+ gateForced = advanced.ok;
1118
+ }
905
1119
  if (!advanced.ok) {
906
1120
  // 走到这里 = 审验记录已写但状态没推进:不 save(零写盘),按 done 门文案说明缺什么
907
1121
  failCode(lang, advanced.code, {
908
1122
  not_found: t('req.err.notFoundTmpl', lang, { id }),
909
1123
  invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
1124
+ // v1.6.0 / REQ-056 T6:计划偏差门(done 门通过后)
1125
+ plan_deviation: t('req.err.planDeviationTmpl', lang, { id }),
1126
+ // v1.6.0 / stage-132 T4 · T7:正文门 / 计划门(先于 done 门)
1127
+ body_empty: bodyGateMessage(lang, data, id),
1128
+ plan_missing: planGateMessage(lang, id),
910
1129
  invalid_status: doneGateMessage(lang, data, id, current),
911
1130
  general_mode_conflict: t('req.err.generalModeConflictTmpl', lang, { id }),
912
1131
  });
@@ -918,7 +1137,9 @@ export function registerReqCommand(program) {
918
1137
  const suffix = independent ? '' : t('req.review.selfSuffix', lang);
919
1138
  console.log(t('req.complete.doneTmpl', lang, {
920
1139
  id, result: options.result, kind: options.kind ?? 'manual',
921
- }) + suffix);
1140
+ }) + suffix + (gateForced ? t('req.complete.gateForcedSuffix', lang) : ''));
1141
+ // v1.6.0 / REQ-059 T8:收口成功即自动同步开发账本
1142
+ syncDevAfterWrite(projectPath, lang);
922
1143
  });
923
1144
  // ── req review <id> --result pass|fail --by <who> --note <text> [--independent|--self] ──
924
1145
  req
@@ -974,6 +1195,8 @@ export function registerReqCommand(program) {
974
1195
  }
975
1196
  const suffix = options.independent === true ? '' : t('req.review.selfSuffix', lang);
976
1197
  console.log(t('req.review.doneTmpl', lang, { id, result: options.result, by }) + suffix);
1198
+ // v1.6.0 / REQ-059 T8:审查记录写入成功即自动同步开发账本
1199
+ syncDevAfterWrite(process.cwd(), lang);
977
1200
  });
978
1201
  // ── req verify <id> --result pass|fail --kind test|manual|build --by <who> --note <text> [--evidence <path>] ──
979
1202
  req
@@ -1023,6 +1246,8 @@ export function registerReqCommand(program) {
1023
1246
  return;
1024
1247
  }
1025
1248
  console.log(t('req.verify.doneTmpl', lang, { id, kind: options.kind, result: options.result, by }));
1249
+ // v1.6.0 / REQ-059 T8:验证记录写入成功即自动同步开发账本
1250
+ syncDevAfterWrite(process.cwd(), lang);
1026
1251
  });
1027
1252
  // ── req split <id> --into <title> [--into <title>...] [--json] ──
1028
1253
  req
@@ -1367,5 +1592,131 @@ export function registerReqCommand(program) {
1367
1592
  console.log(t('req.rollover.itemTmpl', lang, { id: moved.id, status: moved.status, title: moved.title }));
1368
1593
  }
1369
1594
  });
1595
+ // ── req body <id> --section <name> (--text <md> | --file <path>) [--append|--replace] [--json] ──
1596
+ // v1.6.0-stage-132 / T2:需求正文**唯一写入口**(元信息小节受保护;每次写入追加 `## 变更记录`)
1597
+ req
1598
+ .command('body <id>')
1599
+ .description('写入需求正文的业务小节(元信息小节受保护;每次写入追加变更记录)')
1600
+ .requiredOption('--section <name>', '小节名(如 摘要 / 目标与验收 / 问题 / 初步规划;元信息小节不可写)')
1601
+ .option('--text <md>', '小节正文(Markdown;与 --file 二选一)')
1602
+ .option('--file <path>', '从文件读取小节正文(与 --text 二选一;相对路径按项目根解析)')
1603
+ .option('--append', '追加到该小节末尾(缺省替换整节)')
1604
+ .option('--replace', '替换整节(缺省;与 --append 互斥)')
1605
+ .option('--json', '以 JSON 输出 { schemaVersion, id, section, path, lines, created }')
1606
+ .action((id, options, command) => {
1607
+ const lang = getCliLang(process.cwd());
1608
+ const asJson = asJsonOf(options, command);
1609
+ const mgr = createManager();
1610
+ if (!mgr.isLoaded()) {
1611
+ failNoInit(lang, asJson);
1612
+ return;
1613
+ }
1614
+ if (!isValidReqId(id)) {
1615
+ if (asJson) {
1616
+ failJson({ error: 'invalid-argument', field: 'id', value: id });
1617
+ }
1618
+ else {
1619
+ console.error(t('req.invalidIdTmpl', lang, { input: id }));
1620
+ process.exitCode = 1;
1621
+ }
1622
+ return;
1623
+ }
1624
+ const data = mgr.getData();
1625
+ const req_ = getRequirement(data, id);
1626
+ if (!req_) {
1627
+ if (asJson) {
1628
+ failJson({ error: 'not_found', id });
1629
+ }
1630
+ else {
1631
+ console.error(t('req.err.notFoundTmpl', lang, { id }));
1632
+ process.exitCode = 1;
1633
+ }
1634
+ return;
1635
+ }
1636
+ // argument-shape 守卫(非业务校验):--text / --file 恰一;--append / --replace 互斥
1637
+ const hasText = options.text !== undefined;
1638
+ const hasFile = options.file !== undefined;
1639
+ if (!hasText && !hasFile) {
1640
+ if (asJson) {
1641
+ failJson({ error: 'empty_text', id, section: options.section });
1642
+ }
1643
+ else {
1644
+ console.error(t('req.body.noTextTmpl', lang));
1645
+ process.exitCode = 1;
1646
+ }
1647
+ return;
1648
+ }
1649
+ if (hasText && hasFile) {
1650
+ if (asJson) {
1651
+ failJson({ error: 'invalid_field', id, section: options.section, field: 'file' });
1652
+ }
1653
+ else {
1654
+ console.error(t('req.body.exclusiveTmpl', lang));
1655
+ process.exitCode = 1;
1656
+ }
1657
+ return;
1658
+ }
1659
+ if (options.append === true && options.replace === true) {
1660
+ if (asJson) {
1661
+ failJson({ error: 'invalid_field', id, section: options.section, field: 'append' });
1662
+ }
1663
+ else {
1664
+ console.error(t('req.body.flagExclusiveTmpl', lang));
1665
+ process.exitCode = 1;
1666
+ }
1667
+ return;
1668
+ }
1669
+ // v1.5.6-stage-114:写前 preflight(参数 / ID 校验已在门前)
1670
+ if (!enforcePreflightOrFail(process.cwd(), lang))
1671
+ return;
1672
+ try {
1673
+ const result = updateRequirementBody(process.cwd(), req_, {
1674
+ section: options.section,
1675
+ ...(options.text !== undefined ? { text: options.text } : {}),
1676
+ ...(options.file !== undefined ? { file: options.file } : {}),
1677
+ append: options.append === true,
1678
+ replace: options.replace === true,
1679
+ createSectionIfMissing: true,
1680
+ by: resolveActorName(process.cwd(), undefined),
1681
+ });
1682
+ // v1.6.0 / REQ-059 T8:正文写入成功即自动同步开发账本(--json 的告警走 stderr,不污染 stdout)
1683
+ syncDevAfterWrite(process.cwd(), lang);
1684
+ if (asJson) {
1685
+ emitJson(withSchemaVersion({
1686
+ id: req_.id,
1687
+ section: result.section,
1688
+ path: result.path,
1689
+ lines: result.lines,
1690
+ created: result.created,
1691
+ }));
1692
+ return;
1693
+ }
1694
+ const actionKey = result.created
1695
+ ? 'req.body.actionCreated'
1696
+ : (options.append === true ? 'req.body.actionAppended' : 'req.body.actionReplaced');
1697
+ console.log(t('req.body.doneTmpl', lang, {
1698
+ id: req_.id,
1699
+ section: result.section,
1700
+ lines: String(result.lines),
1701
+ path: result.path,
1702
+ action: t(actionKey, lang),
1703
+ }));
1704
+ }
1705
+ catch (err) {
1706
+ if (err instanceof RequirementBodyUpdateError) {
1707
+ if (asJson) {
1708
+ failJson({ error: err.code, id, section: options.section });
1709
+ return;
1710
+ }
1711
+ const key = err.code === 'protected_section'
1712
+ ? 'req.body.protectedTmpl'
1713
+ : (err.code === 'empty_text' ? 'req.body.emptyTmpl' : 'req.body.invalidFieldTmpl');
1714
+ console.error(t(key, lang, { id, section: options.section }));
1715
+ process.exitCode = 1;
1716
+ return;
1717
+ }
1718
+ failGeneric(lang, err);
1719
+ }
1720
+ });
1370
1721
  }
1371
1722
  //# sourceMappingURL=req.js.map