openfeel 1.5.7 → 1.5.8

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 (79) hide show
  1. package/README.md +3 -1
  2. package/dist/commands/archive.d.ts.map +1 -1
  3. package/dist/commands/archive.js +29 -3
  4. package/dist/commands/archive.js.map +1 -1
  5. package/dist/commands/flow.d.ts.map +1 -1
  6. package/dist/commands/flow.js +77 -6
  7. package/dist/commands/flow.js.map +1 -1
  8. package/dist/commands/req.d.ts +1 -1
  9. package/dist/commands/req.d.ts.map +1 -1
  10. package/dist/commands/req.js +396 -74
  11. package/dist/commands/req.js.map +1 -1
  12. package/dist/commands/shared/json-output.d.ts.map +1 -1
  13. package/dist/commands/shared/json-output.js +1 -0
  14. package/dist/commands/shared/json-output.js.map +1 -1
  15. package/dist/commands/stage.d.ts.map +1 -1
  16. package/dist/commands/stage.js +76 -2
  17. package/dist/commands/stage.js.map +1 -1
  18. package/dist/core/archive/merge.d.ts +35 -5
  19. package/dist/core/archive/merge.d.ts.map +1 -1
  20. package/dist/core/archive/merge.js +275 -5
  21. package/dist/core/archive/merge.js.map +1 -1
  22. package/dist/core/dev/sessions.d.ts +106 -0
  23. package/dist/core/dev/sessions.d.ts.map +1 -0
  24. package/dist/core/dev/sessions.js +197 -0
  25. package/dist/core/dev/sessions.js.map +1 -0
  26. package/dist/core/dev-status.d.ts.map +1 -1
  27. package/dist/core/dev-status.js +3 -1
  28. package/dist/core/dev-status.js.map +1 -1
  29. package/dist/core/flow-archive/archive-file.d.ts +14 -3
  30. package/dist/core/flow-archive/archive-file.d.ts.map +1 -1
  31. package/dist/core/flow-archive/archive-file.js.map +1 -1
  32. package/dist/core/flow-archive/archive-ops.d.ts +24 -0
  33. package/dist/core/flow-archive/archive-ops.d.ts.map +1 -1
  34. package/dist/core/flow-archive/archive-ops.js +52 -5
  35. package/dist/core/flow-archive/archive-ops.js.map +1 -1
  36. package/dist/core/flow-archive/grouping.d.ts +5 -0
  37. package/dist/core/flow-archive/grouping.d.ts.map +1 -1
  38. package/dist/core/flow-archive/grouping.js +31 -0
  39. package/dist/core/flow-archive/grouping.js.map +1 -1
  40. package/dist/core/flow-manager.d.ts +119 -2
  41. package/dist/core/flow-manager.d.ts.map +1 -1
  42. package/dist/core/flow-manager.js +236 -18
  43. package/dist/core/flow-manager.js.map +1 -1
  44. package/dist/core/harness.d.ts +15 -0
  45. package/dist/core/harness.d.ts.map +1 -0
  46. package/dist/core/harness.js +75 -0
  47. package/dist/core/harness.js.map +1 -0
  48. package/dist/core/i18n-data/en.d.ts.map +1 -1
  49. package/dist/core/i18n-data/en.js +91 -6
  50. package/dist/core/i18n-data/en.js.map +1 -1
  51. package/dist/core/i18n-data/zh-CN.d.ts.map +1 -1
  52. package/dist/core/i18n-data/zh-CN.js +91 -6
  53. package/dist/core/i18n-data/zh-CN.js.map +1 -1
  54. package/dist/core/req/aggregate.d.ts +20 -4
  55. package/dist/core/req/aggregate.d.ts.map +1 -1
  56. package/dist/core/req/aggregate.js +55 -40
  57. package/dist/core/req/aggregate.js.map +1 -1
  58. package/dist/core/req/body-file.js +1 -1
  59. package/dist/core/req/body-file.js.map +1 -1
  60. package/dist/core/req/requirement-ops.d.ts +137 -10
  61. package/dist/core/req/requirement-ops.d.ts.map +1 -1
  62. package/dist/core/req/requirement-ops.js +319 -35
  63. package/dist/core/req/requirement-ops.js.map +1 -1
  64. package/dist/core/req/stage-links.d.ts +35 -0
  65. package/dist/core/req/stage-links.d.ts.map +1 -0
  66. package/dist/core/req/stage-links.js +46 -0
  67. package/dist/core/req/stage-links.js.map +1 -0
  68. package/dist/core/req/types.d.ts +53 -0
  69. package/dist/core/req/types.d.ts.map +1 -1
  70. package/dist/core/req/types.js +4 -0
  71. package/dist/core/req/types.js.map +1 -1
  72. package/dsh/ADAPTER.md +7 -4
  73. package/dsh/README.md +23 -3
  74. package/dsh/lib/adapters/sessions.js +183 -0
  75. package/dsh/lib/adapters/workflow-gate.js +4 -2
  76. package/dsh/lib/surface/prompt.js +12 -0
  77. package/dsh/lib/tools/index.js +169 -9
  78. package/dsh/package.json +4 -3
  79. package/package.json +4 -2
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * req 命令组注册 — 需求流转命令面(stage-82)
3
3
  *
4
- * 职责:注册 `openfeel req` 顶层命令组(10 子命令)与输出呈现。
4
+ * 职责:注册 `openfeel req` 顶层命令组(15 子命令)与输出呈现。
5
5
  * 命令层零业务逻辑:解析 / 校验 / ID 分配 / 写入全部单点在 `src/core/req/`;本文件仅做
6
6
  * 「参数解析 → 调用引擎原语 → 错误码→文案映射 → 退出码」。
7
7
  * 命令层零校验:状态流转合法性 / 认领占用 / 关联唯一性 / 写命令字段校验一律由引擎单点判定。
@@ -1 +1 @@
1
- {"version":3,"file":"req.d.ts","sourceRoot":"","sources":["../../src/commands/req.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2FpC,oBAAoB;AACpB,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA4pBzD"}
1
+ {"version":3,"file":"req.d.ts","sourceRoot":"","sources":["../../src/commands/req.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6HpC,oBAAoB;AACpB,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA87BzD"}
@@ -2,10 +2,12 @@ import { t, getCliLang } from '../core/i18n.js';
2
2
  import { enforcePreflightOrFail } from './shared/preflight-gate.js';
3
3
  import { FlowManager, isFlowConcurrentError } from '../core/flow-manager.js';
4
4
  import { handleConcurrentConflict } from './shared/errors.js';
5
- import { addRequirement, getRequirement, getRequirements, listRequirements, claimRequirement, releaseRequirement, updateRequirement, advanceRequirement, linkRequirement, getAllowedNextStatuses, splitRequirement, } from '../core/req/requirement-ops.js';
5
+ import { addRequirement, getRequirement, getRequirements, listRequirements, claimRequirement, releaseRequirement, updateRequirement, advanceRequirement, linkRequirement, getAllowedNextStatuses, splitRequirement, requirementDoneBlocker, recordRequirementReview, recordRequirementVerification, releaseCheckRequirements, rolloverRequirements, isTerminalRequirementStatus, } from '../core/req/requirement-ops.js';
6
6
  import { REQ_STATUSES, REQ_ID_PATTERN } from '../core/req/types.js';
7
7
  import { writeRequirementBodySkeleton } from '../core/req/body-file.js';
8
8
  import { computeRequirementAggregate, listLinkedStages } from '../core/req/aggregate.js';
9
+ import { stageRequirementIds } from '../core/req/stage-links.js';
10
+ import { findArchivedRequirement, listArchivedRequirements } from '../core/flow-archive/archive-ops.js';
9
11
  import { withSchemaVersion, emitJson } from './shared/json-output.js';
10
12
  import { getUserName } from '../core/workspace/identity.js';
11
13
  import { normalizeStageId } from '../core/plan/path.js';
@@ -41,6 +43,18 @@ function failNoInit(lang, asJson) {
41
43
  function isValidReqId(id) {
42
44
  return REQ_ID_PATTERN.test(id);
43
45
  }
46
+ /**
47
+ * 需求 ID 的数值序号(排序用;v1.5.8 / REQ-030)。
48
+ * 解析 `REQ-(\d+)` 后取 int;解析失败返回 null(调用方退回字符串比较——异常 id 不崩)。
49
+ */
50
+ function reqIdSeq(id) {
51
+ const m = REQ_ID_PATTERN.exec(id);
52
+ if (!m) {
53
+ return null;
54
+ }
55
+ const n = Number.parseInt(m[1], 10);
56
+ return Number.isFinite(n) ? n : null;
57
+ }
44
58
  /** --into 累积(repeatable option;**本仓首个 repeatable**——既有先例为 variadic `<ids...>`(`flow.ts:665` 选项描述自警「建议置于命令末尾」),其有吞后续参数风险故不采用) */
45
59
  function collectInto(value, previous) {
46
60
  return [...previous, value];
@@ -56,6 +70,23 @@ function failGeneric(lang, err) {
56
70
  console.error(t('common.errorTmpl', lang, { msg }));
57
71
  process.exitCode = 1;
58
72
  }
73
+ /**
74
+ * done 门拒绝文案分流(v1.5.8 / REQ-027「完成必审验」)。
75
+ * 触发前提(既有判类,stage-93 BUG-002):静态流转表放行 `done` 而引擎仍返回 invalid_status ⇒ 唯一可能是完成门。
76
+ * 判据单源 = `requirementDoneBlocker`(引擎);命令层只做「判据 → i18n 模板」映射:
77
+ * 未审 → `req.err.reviewRequiredTmpl`;未验 → `req.err.verificationRequiredTmpl`;阶段相位 → 既有 `doneGateTmpl`。
78
+ */
79
+ function doneGateMessage(lang, data, id, current) {
80
+ const req = getRequirement(data, id);
81
+ const blocker = req ? requirementDoneBlocker(data, req) : null;
82
+ if (blocker === 'review') {
83
+ return t('req.err.reviewRequiredTmpl', lang, { id, current });
84
+ }
85
+ if (blocker === 'verification') {
86
+ return t('req.err.verificationRequiredTmpl', lang, { id, current });
87
+ }
88
+ return t('req.err.doneGateTmpl', lang, { id, current });
89
+ }
59
90
  /**
60
91
  * 保存并收敛并发:成功返回 true;并发冲突 → 单点处理(JSON 置码 2 返回 / 非 JSON exit 2),
61
92
  * 其他异常 → 通用文案 exit 1 并返回 false。返回 false 时调用方须早返回。
@@ -127,13 +158,14 @@ export function registerReqCommand(program) {
127
158
  failGeneric(lang, err);
128
159
  }
129
160
  });
130
- // ── req list [--status <s>] [--target-version <v>] [--owner <o>] [--json] ──
161
+ // ── req list [--status <s>] [--target-version <v>] [--owner <o>] [--include-archived] [--json] ──
131
162
  req
132
163
  .command('list')
133
- .description('列出需求(可按状态/版本/认领人过滤)')
164
+ .description('列出需求(可按状态/版本/认领人过滤;--include-archived 合并已随版本归档的需求)')
134
165
  .option('--status <status>', '按状态过滤(draft/scheduled/in_progress/done/blocked/cancelled/rejected)')
135
166
  .option('--target-version <version>', '按预估版本过滤')
136
167
  .option('--owner <owner>', '按认领人过滤')
168
+ .option('--include-archived', '包含已随版本归档的需求(只读;合并 .openfeel/flow-archive/*.json)')
137
169
  .option('--json', '以 JSON 输出 { schemaVersion, requirements }')
138
170
  .action((options, command) => {
139
171
  const lang = getCliLang(process.cwd());
@@ -164,26 +196,65 @@ export function registerReqCommand(program) {
164
196
  target_version: options.targetVersion,
165
197
  owner: options.owner,
166
198
  });
199
+ // v1.5.8 / REQ-030:--include-archived 合并归档文件中的终态需求(只读;活跃需求优先,不重复输出)
200
+ const archivedRows = [];
201
+ const activeIds = new Set(rows.map((r) => r.id));
202
+ if (options.includeArchived === true) {
203
+ const seen = new Set();
204
+ for (const { requirement } of listArchivedRequirements(process.cwd())) {
205
+ if (activeIds.has(requirement.id) || seen.has(requirement.id)) {
206
+ continue;
207
+ }
208
+ // 归档只收终态:读到非终态(人工篡改)跳过,避免把活跃需求当归档输出
209
+ if (!isTerminalRequirementStatus(requirement.status)) {
210
+ continue;
211
+ }
212
+ seen.add(requirement.id);
213
+ if (options.status !== undefined && requirement.status !== options.status) {
214
+ continue;
215
+ }
216
+ if (options.targetVersion !== undefined && requirement.target_version !== options.targetVersion) {
217
+ continue;
218
+ }
219
+ if (options.owner !== undefined && requirement.owner !== options.owner) {
220
+ continue;
221
+ }
222
+ archivedRows.push(requirement);
223
+ }
224
+ }
167
225
  if (asJson) {
168
- // 末位追加关联阶段与进度(既有 RequirementData 键序零改;聚合/关联阶段共用单点实现)
169
- const requirements = rows.map((r) => {
170
- const agg = computeRequirementAggregate(data, r.id);
171
- return {
226
+ // 末位追加关联阶段与进度(既有 RequirementData 键序零改;聚合/关联阶段共用单点实现);
227
+ // 归档需求末位再追加 `archived: true`(可选键,活跃需求不出现)
228
+ const requirements = [
229
+ ...rows.map((r) => {
230
+ const agg = computeRequirementAggregate(data, r.id);
231
+ return {
232
+ ...r,
233
+ linkedStages: listLinkedStages(data, r.id),
234
+ progress: { done: agg.doneCount, total: agg.stageCount },
235
+ };
236
+ }),
237
+ ...archivedRows.map((r) => ({
172
238
  ...r,
173
- linkedStages: listLinkedStages(data, r.id),
174
- progress: { done: agg.doneCount, total: agg.stageCount },
175
- };
176
- });
239
+ linkedStages: [],
240
+ progress: { done: 0, total: 0 },
241
+ archived: true,
242
+ })),
243
+ ];
177
244
  emitJson(withSchemaVersion({ requirements }));
178
245
  return;
179
246
  }
180
- if (rows.length === 0) {
247
+ if (rows.length === 0 && archivedRows.length === 0) {
181
248
  console.log(t('req.list.empty', lang));
182
249
  return;
183
250
  }
184
251
  for (const r of rows) {
185
252
  console.log(t('req.list.itemTmpl', lang, { id: r.id, status: r.status, title: r.title }));
186
253
  }
254
+ for (const r of archivedRows) {
255
+ console.log(t('req.list.itemTmpl', lang, { id: r.id, status: r.status, title: r.title })
256
+ + t('req.list.archivedSuffixTmpl', lang));
257
+ }
187
258
  });
188
259
  // ── req show <id> [--json] ──
189
260
  req
@@ -209,60 +280,80 @@ export function registerReqCommand(program) {
209
280
  }
210
281
  return;
211
282
  }
212
- const r = getRequirement(data, id);
213
- if (!r) {
283
+ const active = getRequirement(data, id);
284
+ // 子需求行(活跃集存储顺序枚举;不额外排序——避免第二排序源;对齐 stages 无排序先例)
285
+ /** 统一人类 / JSON 输出(活跃与归档共用,键序零改动) */
286
+ const emitRequirement = (r, stageIds, childRows, archivedVersion) => {
287
+ const children = childRows.map((c) => c.id);
288
+ // 父需求 ID **原样回显**(悬空不报错、不做存在性判定——悬空对账职责单点在 requirementHealthItems,REV-87-004①)
289
+ const parent = r.parent_id ?? null;
214
290
  if (asJson) {
215
- failJson({ error: 'not_found', id });
291
+ // `archived` 为**末尾可选键**(仅归档回退路径出现;活跃需求既有 5 键键序零改)
292
+ console.log(JSON.stringify(archivedVersion === null
293
+ ? { schemaVersion: 1, requirement: r, stages: stageIds, parent, children }
294
+ : { schemaVersion: 1, requirement: r, stages: stageIds, parent, children, archived: true }, null, 2));
295
+ return;
296
+ }
297
+ if (archivedVersion !== null) {
298
+ console.log(t('req.show.archivedTmpl', lang, { version: archivedVersion }));
299
+ }
300
+ console.log(t('req.show.titleTmpl', lang, { id: r.id, title: r.title }));
301
+ console.log(t('req.show.metaTmpl', lang, {
302
+ status: r.status,
303
+ targetVersion: r.target_version ?? t('common.none', lang),
304
+ priority: r.priority ?? t('common.none', lang),
305
+ }));
306
+ console.log(r.owner
307
+ ? t('req.show.ownerTmpl', lang, { owner: r.owner, claimedAt: r.claimed_at ?? '' })
308
+ : t('req.show.ownerNone', lang));
309
+ console.log(t('req.show.timesTmpl', lang, { created: r.created_at, updated: r.updated_at }));
310
+ console.log(t('req.show.bodyTmpl', lang, { path: r.body_path ?? t('common.none', lang) }));
311
+ console.log(parent !== null
312
+ ? t('req.show.parentTmpl', lang, { parent })
313
+ : t('req.show.parentNone', lang));
314
+ if (childRows.length === 0) {
315
+ console.log(t('req.show.childrenNone', lang));
216
316
  }
217
317
  else {
218
- console.error(t('req.err.notFoundTmpl', lang, { id }));
219
- process.exitCode = 1;
318
+ console.log(t('req.show.childrenLabel', lang));
319
+ for (const c of childRows) {
320
+ console.log(t('req.show.childItemTmpl', lang, { id: c.id, status: c.status, title: c.title }));
321
+ }
220
322
  }
221
- return;
222
- }
223
- // 关联阶段 = 原始只读枚举(零聚合计算 / 零阶段推进字段读取——归后续阶段);命令层输出面复用单点过滤(REV-97-006)
224
- const stages = listLinkedStages(data, id).map((l) => l.id);
225
- // 子需求 = 存储顺序枚举(不额外排序——避免第二排序源;对齐 stages 无排序先例)
226
- const childRows = getRequirements(data).filter((r) => r.parent_id === id);
227
- const children = childRows.map((c) => c.id);
228
- // 父需求 ID **原样回显**(悬空不报错、不做存在性判定——悬空对账职责单点在 requirementHealthItems,REV-87-004①)
229
- const parent = r.parent_id ?? null;
230
- if (asJson) {
231
- console.log(JSON.stringify({ schemaVersion: 1, requirement: r, stages, parent, children }, null, 2));
232
- return;
233
- }
234
- console.log(t('req.show.titleTmpl', lang, { id: r.id, title: r.title }));
235
- console.log(t('req.show.metaTmpl', lang, {
236
- status: r.status,
237
- targetVersion: r.target_version ?? t('common.none', lang),
238
- priority: r.priority ?? t('common.none', lang),
239
- }));
240
- console.log(r.owner
241
- ? t('req.show.ownerTmpl', lang, { owner: r.owner, claimedAt: r.claimed_at ?? '' })
242
- : t('req.show.ownerNone', lang));
243
- console.log(t('req.show.timesTmpl', lang, { created: r.created_at, updated: r.updated_at }));
244
- console.log(t('req.show.bodyTmpl', lang, { path: r.body_path ?? t('common.none', lang) }));
245
- console.log(parent !== null
246
- ? t('req.show.parentTmpl', lang, { parent })
247
- : t('req.show.parentNone', lang));
248
- if (childRows.length === 0) {
249
- console.log(t('req.show.childrenNone', lang));
250
- }
251
- else {
252
- console.log(t('req.show.childrenLabel', lang));
253
- for (const c of childRows) {
254
- console.log(t('req.show.childItemTmpl', lang, { id: c.id, status: c.status, title: c.title }));
323
+ if (stageIds.length === 0) {
324
+ console.log(t('req.show.stagesNone', lang));
255
325
  }
256
- }
257
- if (stages.length === 0) {
258
- console.log(t('req.show.stagesNone', lang));
259
- }
260
- else {
261
- console.log(t('req.show.stagesLabel', lang));
262
- for (const s of stages) {
263
- console.log(t('req.show.stageItemTmpl', lang, { stage: s }));
326
+ else {
327
+ console.log(t('req.show.stagesLabel', lang));
328
+ for (const s of stageIds) {
329
+ console.log(t('req.show.stageItemTmpl', lang, { stage: s }));
330
+ }
331
+ }
332
+ };
333
+ if (!active) {
334
+ // 已归档回退(只读;v1.5.8 / REQ-030):命中归档文件 → 标记 archived;否则维持 not_found
335
+ const hit = findArchivedRequirement(process.cwd(), id);
336
+ if (!hit) {
337
+ if (asJson) {
338
+ failJson({ error: 'not_found', id });
339
+ }
340
+ else {
341
+ console.error(t('req.err.notFoundTmpl', lang, { id }));
342
+ process.exitCode = 1;
343
+ }
344
+ return;
264
345
  }
346
+ // 关联阶段 / 子需求从归档文件派生(单点 stageRequirementIds;读侧宽容)
347
+ const archivedStages = Object.entries(hit.file.stages ?? {})
348
+ .filter(([, stage]) => stageRequirementIds(stage).includes(id))
349
+ .map(([stageId]) => stageId);
350
+ const archivedChildren = (Array.isArray(hit.file.requirements) ? hit.file.requirements : [])
351
+ .filter((c) => c?.parent_id === id);
352
+ emitRequirement(hit.requirement, archivedStages, archivedChildren, hit.version);
353
+ return;
265
354
  }
355
+ // 关联阶段 = 原始只读枚举(零聚合计算 / 零阶段推进字段读取——归后续阶段);命令层输出面复用单点过滤(REV-97-006)
356
+ emitRequirement(active, listLinkedStages(data, id).map((l) => l.id), getRequirements(data).filter((r) => r.parent_id === id), null);
266
357
  });
267
358
  // ── req claim <id> [--owner <name>] ──
268
359
  req
@@ -403,7 +494,7 @@ export function registerReqCommand(program) {
403
494
  not_found: t('req.err.notFoundTmpl', lang, { id }),
404
495
  invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
405
496
  invalid_status: doneGate
406
- ? t('req.err.doneGateTmpl', lang, { id, current })
497
+ ? doneGateMessage(lang, data, id, current)
407
498
  : t('req.err.invalidStatusTmpl', lang, {
408
499
  id,
409
500
  to: options.status ?? '',
@@ -434,13 +525,13 @@ export function registerReqCommand(program) {
434
525
  }
435
526
  console.log(t('req.set.doneTmpl', lang, { id }));
436
527
  });
437
- // ── req link --stage <stageId> (--requirement <id> | --unlink) ──
528
+ // ── req link --stage <stageId> (--requirement <id> [--unlink] | --unlink) ──
438
529
  req
439
530
  .command('link')
440
- .description('关联需求到阶段 / 解绑(--requirement 与 --unlink 二选一)')
531
+ .description('关联需求到阶段(可多个)/ 解绑(--unlink 单个或全部)')
441
532
  .requiredOption('--stage <stageId>', '阶段 ID(stage-NN 或 vX.Y.Z-stage-NN)')
442
- .option('--requirement <id>', '需求 ID(关联用;与 --unlink 互斥)')
443
- .option('--unlink', '解除该阶段的需求关联')
533
+ .option('--requirement <id>', '需求 ID(关联用;与 --unlink 同用时表示只解绑该需求)')
534
+ .option('--unlink', '解除该阶段的需求关联(缺省清空全部;与 --requirement 同用只解该需求)')
444
535
  .action((options) => {
445
536
  const lang = getCliLang(process.cwd());
446
537
  const mgr = createManager();
@@ -449,11 +540,11 @@ export function registerReqCommand(program) {
449
540
  return;
450
541
  }
451
542
  const data = mgr.getData();
452
- // 互斥守卫(argument-shape):both / neither 均拒绝
543
+ // 参数守卫(argument-shape):至少提供一个(v1.5.8 / REQ-028:两者同用 = 只解绑该需求)
453
544
  const hasRequirement = options.requirement !== undefined;
454
545
  const hasUnlink = options.unlink === true;
455
- if (hasRequirement === hasUnlink) {
456
- console.error(t('req.link.exclusiveTmpl', lang));
546
+ if (!hasRequirement && !hasUnlink) {
547
+ console.error(t('req.link.needArgTmpl', lang));
457
548
  process.exitCode = 1;
458
549
  return;
459
550
  }
@@ -468,10 +559,13 @@ export function registerReqCommand(program) {
468
559
  }
469
560
  requirementId = options.requirement;
470
561
  }
471
- // v1.5.6-stage-114:写前 preflight(互斥守卫 / reqId 校验已在门前)
562
+ // v1.5.6-stage-114:写前 preflight(参数守卫 / reqId 校验已在门前)
472
563
  if (!enforcePreflightOrFail(process.cwd(), lang))
473
564
  return;
474
- const r = linkRequirement(data, stageKey, requirementId);
565
+ // 三分支:link(追加)/ unlink 单个 / unlink 全部
566
+ const r = hasUnlink
567
+ ? linkRequirement(data, stageKey, null, hasRequirement ? { unlinkRequirementId: requirementId } : {})
568
+ : linkRequirement(data, stageKey, requirementId);
475
569
  if (!r.ok) {
476
570
  failCode(lang, r.code, {
477
571
  stage_not_found: t('req.err.stageNotFoundTmpl', lang, { stage: stageKey }),
@@ -493,7 +587,7 @@ export function registerReqCommand(program) {
493
587
  return;
494
588
  }
495
589
  // stage-90 T2.3:需求级模式下发(需求携带 workflow_mode 时经单点同步到关联阶段)
496
- if (hasRequirement && requirementId) {
590
+ if (!hasUnlink && hasRequirement && requirementId) {
497
591
  const reqLinked = getRequirement(data, requirementId);
498
592
  if (reqLinked?.workflow_mode) {
499
593
  const synced = mgr.syncConfigFieldToStages('workflow_mode', reqLinked.workflow_mode, { onlyStages: [stageKey] });
@@ -502,9 +596,14 @@ export function registerReqCommand(program) {
502
596
  }
503
597
  }
504
598
  }
505
- console.log(hasRequirement
506
- ? t('req.link.doneTmpl', lang, { stage: stageKey, id: requirementId ?? '' })
507
- : t('req.link.unlinkDoneTmpl', lang, { stage: stageKey }));
599
+ if (hasUnlink) {
600
+ console.log(hasRequirement
601
+ ? t('req.link.unlinkOneTmpl', lang, { stage: stageKey, id: requirementId ?? '' })
602
+ : t('req.link.unlinkDoneTmpl', lang, { stage: stageKey }));
603
+ }
604
+ else {
605
+ console.log(t('req.link.doneTmpl', lang, { stage: stageKey, id: requirementId ?? '' }));
606
+ }
508
607
  });
509
608
  // ── req advance <id> --to <status> ──
510
609
  req
@@ -539,7 +638,7 @@ export function registerReqCommand(program) {
539
638
  failCode(lang, r.code, {
540
639
  not_found: t('req.err.notFoundTmpl', lang, { id }),
541
640
  invalid_status: doneGate
542
- ? t('req.err.doneGateTmpl', lang, { id, current: before ?? '' })
641
+ ? doneGateMessage(lang, data, id, before ?? '')
543
642
  : t('req.err.invalidStatusTmpl', lang, {
544
643
  id,
545
644
  to: options.to,
@@ -558,6 +657,104 @@ export function registerReqCommand(program) {
558
657
  }
559
658
  console.log(t('req.advance.doneTmpl', lang, { id, from: before ?? '', to: options.to }));
560
659
  });
660
+ // ── req review <id> --result pass|fail --by <who> --note <text> [--independent|--self] ──
661
+ req
662
+ .command('review <id>')
663
+ .description('记录需求审查(v1.5.8 完成必审:done 门要求 review.result=pass;--independent 独立审查 / --self 自我审查)')
664
+ .requiredOption('--result <result>', '审查结论(pass / fail)')
665
+ .requiredOption('--by <who>', '审查者')
666
+ .requiredOption('--note <text>', '结论摘要(进入归档摘要)')
667
+ .option('--independent', '独立审查(推荐)')
668
+ .option('--self', '自我审查(非独立;归档摘要标注 self-review)')
669
+ .action((id, options) => {
670
+ const lang = getCliLang(process.cwd());
671
+ const mgr = createManager();
672
+ if (!mgr.isLoaded()) {
673
+ failNoInit(lang, false);
674
+ return;
675
+ }
676
+ const data = mgr.getData();
677
+ if (!isValidReqId(id)) {
678
+ console.error(t('req.invalidIdTmpl', lang, { input: id }));
679
+ process.exitCode = 1;
680
+ return;
681
+ }
682
+ // 参数互斥守卫(argument-shape,非业务校验)
683
+ if (options.independent === true && options.self === true) {
684
+ console.error(t('req.review.exclusiveFlagTmpl', lang));
685
+ process.exitCode = 1;
686
+ return;
687
+ }
688
+ // v1.5.6-stage-114:写前 preflight(ID / 互斥守卫已在门前)
689
+ if (!enforcePreflightOrFail(process.cwd(), lang))
690
+ return;
691
+ // 命令层零校验:值域(result)/ 非空(by/note)/ 终态全在引擎单点
692
+ const r = recordRequirementReview(data, id, {
693
+ result: options.result,
694
+ by: options.by,
695
+ note: options.note,
696
+ independent: options.independent === true,
697
+ });
698
+ if (!r.ok) {
699
+ failCode(lang, r.code, {
700
+ not_found: t('req.err.notFoundTmpl', lang, { id }),
701
+ invalid_status: t('req.review.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
702
+ invalid_field: t('req.review.invalidTmpl', lang),
703
+ });
704
+ return;
705
+ }
706
+ if (!saveOrFail(mgr, lang)) {
707
+ return;
708
+ }
709
+ const suffix = options.independent === true ? '' : t('req.review.selfSuffix', lang);
710
+ console.log(t('req.review.doneTmpl', lang, { id, result: options.result, by: options.by }) + suffix);
711
+ });
712
+ // ── req verify <id> --result pass|fail --kind test|manual|build --by <who> --note <text> [--evidence <path>] ──
713
+ req
714
+ .command('verify <id>')
715
+ .description('记录需求验证(v1.5.8 完成必验:done 门要求 verification.result=pass)')
716
+ .requiredOption('--result <result>', '验证结论(pass / fail)')
717
+ .requiredOption('--kind <kind>', '验证种类(test / manual / build)')
718
+ .requiredOption('--by <who>', '验证者')
719
+ .requiredOption('--note <text>', '结论摘要(进入归档摘要)')
720
+ .option('--evidence <path>', '证据(测试命令 / 报告路径 / 摘要)')
721
+ .action((id, options) => {
722
+ const lang = getCliLang(process.cwd());
723
+ const mgr = createManager();
724
+ if (!mgr.isLoaded()) {
725
+ failNoInit(lang, false);
726
+ return;
727
+ }
728
+ const data = mgr.getData();
729
+ if (!isValidReqId(id)) {
730
+ console.error(t('req.invalidIdTmpl', lang, { input: id }));
731
+ process.exitCode = 1;
732
+ return;
733
+ }
734
+ // v1.5.6-stage-114:写前 preflight(ID 校验已在门前)
735
+ if (!enforcePreflightOrFail(process.cwd(), lang))
736
+ return;
737
+ // 命令层零校验:值域(result / kind)/ 非空(by/note)/ 终态全在引擎单点
738
+ const r = recordRequirementVerification(data, id, {
739
+ result: options.result,
740
+ kind: options.kind,
741
+ by: options.by,
742
+ note: options.note,
743
+ evidence: options.evidence,
744
+ });
745
+ if (!r.ok) {
746
+ failCode(lang, r.code, {
747
+ not_found: t('req.err.notFoundTmpl', lang, { id }),
748
+ invalid_status: t('req.verify.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
749
+ invalid_field: t('req.verify.invalidTmpl', lang),
750
+ });
751
+ return;
752
+ }
753
+ if (!saveOrFail(mgr, lang)) {
754
+ return;
755
+ }
756
+ console.log(t('req.verify.doneTmpl', lang, { id, kind: options.kind, result: options.result, by: options.by }));
757
+ });
561
758
  // ── req split <id> --into <title> [--into <title>...] [--json] ──
562
759
  req
563
760
  .command('split <id>')
@@ -739,6 +936,13 @@ export function registerReqCommand(program) {
739
936
  return a.created_at < b.created_at ? -1 : 1;
740
937
  }
741
938
  if (a.id !== b.id) {
939
+ // 第三排序键 = **数值**升序(v1.5.8 / REQ-030:字符串比较会让 REQ-1000 排在 REQ-999 之前);
940
+ // 解析失败退回字符串比较(异常 id 不崩、确定性不变)
941
+ const an = reqIdSeq(a.id);
942
+ const bn = reqIdSeq(b.id);
943
+ if (an !== null && bn !== null && an !== bn) {
944
+ return an - bn;
945
+ }
742
946
  return a.id < b.id ? -1 : 1;
743
947
  }
744
948
  return 0;
@@ -774,5 +978,123 @@ export function registerReqCommand(program) {
774
978
  console.log(line);
775
979
  }
776
980
  });
981
+ // ── req release-check <version> [--json] ──(v1.5.8 / REQ-030)
982
+ req
983
+ .command('release-check <version>')
984
+ .description('发布门(软):列出该版本的已完成 / 未完成 / 其它需求;只读、退出码恒 0')
985
+ .option('--json', '以 JSON 输出 { schemaVersion, version, done, unfinished, counts }')
986
+ .action((version, options, command) => {
987
+ const lang = getCliLang(process.cwd());
988
+ const asJson = asJsonOf(options, command);
989
+ const mgr = createManager();
990
+ if (!mgr.isLoaded()) {
991
+ failNoInit(lang, asJson);
992
+ return;
993
+ }
994
+ const data = mgr.getData();
995
+ // 只读保证:不 save / 不 appendLog / 零写盘;软门恒 exit 0(未完成需求只报告,不拒绝)
996
+ const check = releaseCheckRequirements(data, version);
997
+ if (asJson) {
998
+ emitJson(withSchemaVersion({
999
+ version: check.version,
1000
+ done: check.done.map((r) => r.id),
1001
+ unfinished: check.unfinished.map((r) => r.id),
1002
+ counts: check.counts,
1003
+ }));
1004
+ return;
1005
+ }
1006
+ console.log(t('req.releaseCheck.titleTmpl', lang, { version: check.version, total: String(check.counts.total) }));
1007
+ const section = (label, rows) => {
1008
+ console.log(label);
1009
+ if (rows.length === 0) {
1010
+ console.log(t('req.releaseCheck.emptySection', lang));
1011
+ return;
1012
+ }
1013
+ for (const r of rows) {
1014
+ console.log(t('req.releaseCheck.itemTmpl', lang, { id: r.id, status: r.status, title: r.title }));
1015
+ }
1016
+ };
1017
+ section(t('req.releaseCheck.doneLabel', lang, { n: String(check.counts.done) }), check.done);
1018
+ section(t('req.releaseCheck.unfinishedLabel', lang, { n: String(check.counts.unfinished) }), check.unfinished);
1019
+ section(t('req.releaseCheck.otherLabel', lang, { n: String(check.counts.other) }), check.other);
1020
+ console.log(t('req.releaseCheck.countsTmpl', lang, {
1021
+ done: String(check.counts.done),
1022
+ unfinished: String(check.counts.unfinished),
1023
+ other: String(check.counts.other),
1024
+ total: String(check.counts.total),
1025
+ }));
1026
+ if (check.unfinished.length > 0) {
1027
+ console.log(t('req.releaseCheck.unfinishedHintTmpl', lang, { version: check.version }));
1028
+ }
1029
+ });
1030
+ // ── req rollover --from <version> --to <version> (--id <REQ> | --all) ──(v1.5.8 / REQ-030)
1031
+ req
1032
+ .command('rollover')
1033
+ .description('顺延未完成需求到新版本(改写 target_version + carried_from 溯源;仅非终态需求)')
1034
+ .requiredOption('--from <version>', '来源版本(如 v1.5.8)')
1035
+ .requiredOption('--to <version>', '目标版本(如 v1.6.0)')
1036
+ .option('--id <id>', '只顺延该需求(与 --all 互斥)')
1037
+ .option('--all', '顺延该版本全部未完成需求(与 --id 互斥)')
1038
+ .action((options) => {
1039
+ const lang = getCliLang(process.cwd());
1040
+ const mgr = createManager();
1041
+ if (!mgr.isLoaded()) {
1042
+ failNoInit(lang, false);
1043
+ return;
1044
+ }
1045
+ const data = mgr.getData();
1046
+ // argument-shape 守卫(非业务校验):--id 与 --all 必须且只能提供一个
1047
+ if ((options.id !== undefined) === (options.all === true)) {
1048
+ console.error(t('req.rollover.exclusiveTmpl', lang));
1049
+ process.exitCode = 1;
1050
+ return;
1051
+ }
1052
+ if (options.id !== undefined && !isValidReqId(options.id)) {
1053
+ console.error(t('req.invalidIdTmpl', lang, { input: options.id }));
1054
+ process.exitCode = 1;
1055
+ return;
1056
+ }
1057
+ // v1.5.6-stage-114:写前 preflight(参数 / ID 校验已在门前)
1058
+ if (!enforcePreflightOrFail(process.cwd(), lang))
1059
+ return;
1060
+ // 命令层零校验:版本门 / 终态门 / 归属门 / carried_from 与审计全在引擎单点
1061
+ const r = rolloverRequirements(data, options.from, options.to, {
1062
+ ...(options.id !== undefined ? { id: options.id } : {}),
1063
+ all: options.all === true,
1064
+ });
1065
+ if (!r.ok) {
1066
+ failCode(lang, r.code, {
1067
+ not_found: t('req.err.notFoundTmpl', lang, { id: options.id ?? '' }),
1068
+ invalid_status: t('req.rollover.terminalTmpl', lang, {
1069
+ id: options.id ?? '',
1070
+ status: options.id !== undefined ? (getRequirement(data, options.id)?.status ?? '') : '',
1071
+ }),
1072
+ invalid_field: options.id !== undefined
1073
+ ? t('req.rollover.notInVersionTmpl', lang, {
1074
+ id: options.id,
1075
+ from: options.from,
1076
+ current: getRequirement(data, options.id)?.target_version ?? t('common.none', lang),
1077
+ })
1078
+ : t('req.rollover.invalidVersionTmpl', lang, { from: options.from, to: options.to }),
1079
+ });
1080
+ return;
1081
+ }
1082
+ if (r.moved.length === 0) {
1083
+ // no-op:不 save(revision 不变)
1084
+ console.log(t('req.rollover.noopTmpl', lang, { from: options.from }));
1085
+ return;
1086
+ }
1087
+ if (!saveOrFail(mgr, lang)) {
1088
+ return;
1089
+ }
1090
+ console.log(t('req.rollover.doneTmpl', lang, {
1091
+ count: String(r.moved.length),
1092
+ from: options.from,
1093
+ to: options.to,
1094
+ }));
1095
+ for (const moved of r.moved) {
1096
+ console.log(t('req.rollover.itemTmpl', lang, { id: moved.id, status: moved.status, title: moved.title }));
1097
+ }
1098
+ });
777
1099
  }
778
1100
  //# sourceMappingURL=req.js.map