openfeel 1.6.0 → 1.6.1
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/dashboard.d.ts.map +1 -1
- package/dist/commands/dashboard.js +10 -1
- package/dist/commands/dashboard.js.map +1 -1
- package/dist/commands/flow.d.ts.map +1 -1
- package/dist/commands/flow.js +19 -12
- 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 +279 -2
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/req.d.ts.map +1 -1
- package/dist/commands/req.js +470 -95
- package/dist/commands/req.js.map +1 -1
- package/dist/core/adherence.d.ts +135 -0
- package/dist/core/adherence.d.ts.map +1 -0
- package/dist/core/adherence.js +221 -0
- package/dist/core/adherence.js.map +1 -0
- package/dist/core/dashboard/aggregate.d.ts +39 -0
- package/dist/core/dashboard/aggregate.d.ts.map +1 -1
- package/dist/core/dashboard/aggregate.js +64 -5
- package/dist/core/dashboard/aggregate.js.map +1 -1
- package/dist/core/dashboard/render.d.ts.map +1 -1
- package/dist/core/dashboard/render.js +88 -1
- package/dist/core/dashboard/render.js.map +1 -1
- package/dist/core/errors.d.ts +27 -2
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +15 -2
- package/dist/core/errors.js.map +1 -1
- package/dist/core/flow/gate-override.d.ts +72 -0
- package/dist/core/flow/gate-override.d.ts.map +1 -0
- package/dist/core/flow/gate-override.js +71 -0
- package/dist/core/flow/gate-override.js.map +1 -0
- package/dist/core/flow-manager.d.ts +13 -4
- package/dist/core/flow-manager.d.ts.map +1 -1
- package/dist/core/flow-manager.js +47 -16
- 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 +45 -6
- 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 +45 -6
- package/dist/core/i18n-data/zh-CN.js.map +1 -1
- package/dist/core/req/body-file.d.ts +37 -0
- package/dist/core/req/body-file.d.ts.map +1 -1
- package/dist/core/req/body-file.js +39 -2
- package/dist/core/req/body-file.js.map +1 -1
- package/dist/core/req/plan-file.d.ts +83 -0
- package/dist/core/req/plan-file.d.ts.map +1 -0
- package/dist/core/req/plan-file.js +205 -0
- package/dist/core/req/plan-file.js.map +1 -0
- package/dist/core/req/requirement-ops.d.ts +25 -3
- package/dist/core/req/requirement-ops.d.ts.map +1 -1
- package/dist/core/req/requirement-ops.js +66 -11
- package/dist/core/req/requirement-ops.js.map +1 -1
- package/dist/core/req/types.d.ts +8 -2
- package/dist/core/req/types.d.ts.map +1 -1
- package/dist/core/req/types.js +10 -2
- package/dist/core/req/types.js.map +1 -1
- package/dist/core/template-loader.d.ts.map +1 -1
- package/dist/core/template-loader.js +12 -0
- package/dist/core/template-loader.js.map +1 -1
- package/dist/core/templates.d.ts +1 -1
- package/dist/core/templates.d.ts.map +1 -1
- package/dist/core/templates.js +18 -0
- package/dist/core/templates.js.map +1 -1
- package/dsh/ACTION-GUIDE.md +15 -6
- package/dsh/ADAPTER.md +62 -1
- package/dsh/README.md +13 -11
- package/dsh/docs/compat/persistence.md +13 -0
- package/dsh/docs/compat/pipeline.md +12 -0
- package/dsh/docs/compat/req.md +15 -0
- package/dsh/docs/compat/stage.md +12 -0
- package/dsh/lib/adapters/dispatch-ledger.js +149 -10
- package/dsh/lib/guard.js +685 -22
- package/dsh/lib/surface/prompt.js +4 -0
- package/dsh/lib/tools/index.js +113 -22
- package/dsh/package.json +2 -2
- package/package.json +2 -1
package/dist/commands/req.js
CHANGED
|
@@ -5,13 +5,15 @@ import { FlowManager, isFlowConcurrentError } from '../core/flow-manager.js';
|
|
|
5
5
|
import { handleConcurrentConflict } from './shared/errors.js';
|
|
6
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';
|
|
7
7
|
import { REQ_STATUSES, REQ_ID_PATTERN } from '../core/req/types.js';
|
|
8
|
-
import { writeRequirementBodySkeleton, updateRequirementBody, getRequirementBodyPath, RequirementBodyUpdateError } from '../core/req/body-file.js';
|
|
8
|
+
import { writeRequirementBodySkeleton, updateRequirementBody, importRequirementBodySections, getRequirementBodyPath, RequirementBodyUpdateError } from '../core/req/body-file.js';
|
|
9
|
+
import { writeRequirementPlanSkeleton, toRequirementPlanSeed, RequirementPlanFileError } from '../core/req/plan-file.js';
|
|
9
10
|
import { computeRequirementAggregate, listLinkedStages } from '../core/req/aggregate.js';
|
|
10
11
|
import { stageRequirementIds } from '../core/req/stage-links.js';
|
|
11
12
|
import { findArchivedRequirement, listArchivedRequirements, archivedRequirementMaxSeq } from '../core/flow-archive/archive-ops.js';
|
|
12
13
|
import { withSchemaVersion, emitJson } from './shared/json-output.js';
|
|
14
|
+
import { CLI_ERROR_CODES, getCliErrorSpec } from '../core/errors.js';
|
|
13
15
|
import { getUserName } from '../core/workspace/identity.js';
|
|
14
|
-
import { normalizeStageId } from '../core/plan/path.js';
|
|
16
|
+
import { normalizeStageId, getRequirementPlanRelPath } from '../core/plan/path.js';
|
|
15
17
|
import { getSessionId, resolveActorName } from '../core/session.js';
|
|
16
18
|
import { maybeSyncDevStatus } from '../core/dev-status.js';
|
|
17
19
|
/** 当前会话标识(写入审查/验证记录,用于人机区分与回溯;v1.5.24 / REQ-049) */
|
|
@@ -71,6 +73,72 @@ function failCode(lang, code, msgs) {
|
|
|
71
73
|
console.error(msgs[code] ?? t('common.errorTmpl', lang, { msg: code }));
|
|
72
74
|
process.exitCode = 1;
|
|
73
75
|
}
|
|
76
|
+
/** 引擎错误码 → 本地化文案(与 {@link failCode} 同源;`--json` 失败出口复用) */
|
|
77
|
+
function codeMessage(lang, code, msgs) {
|
|
78
|
+
return msgs[code] ?? t('common.errorTmpl', lang, { msg: code });
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 需求门码 → CLI 稳定错误码(**单点映射**;v1.6.1 / REQ-063 A63.3)。
|
|
82
|
+
*
|
|
83
|
+
* 只登记「与具体门一一对应」的五个码(A63.2 两码 + 既有三码);其余需求侧码
|
|
84
|
+
* (`not_found` / `invalid_status` / `invalid_field` / `already_claimed` …)与门无关,
|
|
85
|
+
* 归 `INVALID_ARGUMENT`——它们表达的是参数 / 存在性 / 流转表拒绝,不冒充门禁码。
|
|
86
|
+
*/
|
|
87
|
+
const REQ_GATE_ERROR_CODE = {
|
|
88
|
+
body_empty: 'REQ_BODY_GATE',
|
|
89
|
+
plan_missing: 'REQ_PLAN_GATE',
|
|
90
|
+
plan_deviation: 'REQ_PLAN_DEVIATION',
|
|
91
|
+
review_required: 'REQ_REVIEW_REQUIRED',
|
|
92
|
+
verification_required: 'REQ_VERIFY_REQUIRED',
|
|
93
|
+
};
|
|
94
|
+
/** 需求侧错误码 → CLI 码(非法码兜底 `INVALID_ARGUMENT`,防 `getCliErrorSpec` 取空) */
|
|
95
|
+
function reqJsonCode(code) {
|
|
96
|
+
const mapped = REQ_GATE_ERROR_CODE[code];
|
|
97
|
+
if (mapped !== undefined) {
|
|
98
|
+
return mapped;
|
|
99
|
+
}
|
|
100
|
+
return Object.prototype.hasOwnProperty.call(CLI_ERROR_CODES, code) ? code : 'INVALID_ARGUMENT';
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* `req claim/advance/complete --json` 的失败文档(A63.3):
|
|
104
|
+
* `{ schemaVersion, error:{code,kind,message,detail}, errorKind }`——`error.code` 为稳定码,
|
|
105
|
+
* `errorKind` 为 legacy 兼容末键(与既有 `failJson` 同语义),stdout **恰一个**文档。
|
|
106
|
+
*/
|
|
107
|
+
function failReqJson(code, message, detail) {
|
|
108
|
+
const spec = getCliErrorSpec(code);
|
|
109
|
+
console.log(JSON.stringify({
|
|
110
|
+
schemaVersion: 1,
|
|
111
|
+
error: { code: spec.code, kind: spec.kind, message, detail: detail ?? null },
|
|
112
|
+
errorKind: spec.kind,
|
|
113
|
+
}, null, 2));
|
|
114
|
+
process.exitCode = spec.exitCode;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 需求写命令统一失败出口(v1.6.1 / REQ-063 A63.3):
|
|
118
|
+
* `--json` → 单文档 + 门码(`REQ_*`);human → stderr 文案 + exit 1(既有语义零改动)。
|
|
119
|
+
*/
|
|
120
|
+
function failReqWrite(lang, asJson, code, message, detail) {
|
|
121
|
+
if (asJson) {
|
|
122
|
+
failReqJson(reqJsonCode(code), message, detail);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
console.error(message);
|
|
126
|
+
process.exitCode = 1;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 需求写命令 `--json` 成功文档(A63.3 键序冻结):
|
|
130
|
+
* `schemaVersion, id, from, to, status`,`gates` 为**条件出现键**(仅 `--force` 实际放行过门时)。
|
|
131
|
+
* 值为门名闭集(与 `src/core/flow/gate-override.ts` 的 `GateOverrideGate` 同源)。
|
|
132
|
+
*/
|
|
133
|
+
function emitReqWriteJson(doc) {
|
|
134
|
+
emitJson(withSchemaVersion({
|
|
135
|
+
id: doc.id,
|
|
136
|
+
from: doc.from,
|
|
137
|
+
to: doc.to,
|
|
138
|
+
status: doc.status,
|
|
139
|
+
...(doc.gates !== undefined && doc.gates.length > 0 ? { gates: doc.gates } : {}),
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
74
142
|
/** 通用错误文案 + 退出码 1(非并发异常统一出口;不 return,由调用方 return) */
|
|
75
143
|
function failGeneric(lang, err) {
|
|
76
144
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -332,7 +400,7 @@ export function registerReqCommand(program) {
|
|
|
332
400
|
req
|
|
333
401
|
.command('list')
|
|
334
402
|
.description('列出需求(可按状态/版本/认领人过滤;--include-archived 合并已随版本归档的需求)')
|
|
335
|
-
.option('--status <status>', '按状态过滤(draft/scheduled/in_progress/done/blocked/cancelled/rejected)')
|
|
403
|
+
.option('--status <status>', '按状态过滤(draft/scheduled/in_progress/review_pending/done/blocked/cancelled/rejected)')
|
|
336
404
|
.option('--target-version <version>', '按预估版本过滤')
|
|
337
405
|
.option('--owner <owner>', '按认领人过滤')
|
|
338
406
|
.option('--include-archived', '包含已随版本归档的需求(只读;合并 .openfeel/flow-archive/*.json)')
|
|
@@ -525,41 +593,44 @@ export function registerReqCommand(program) {
|
|
|
525
593
|
// 关联阶段 = 原始只读枚举(零聚合计算 / 零阶段推进字段读取——归后续阶段);命令层输出面复用单点过滤(REV-97-006)
|
|
526
594
|
emitRequirement(active, listLinkedStages(data, id).map((l) => l.id), getRequirements(data).filter((r) => r.parent_id === id), null);
|
|
527
595
|
});
|
|
528
|
-
// ── req claim <id> [--owner <name>] [--force] ──
|
|
596
|
+
// ── req claim <id> [--owner <name>] [--force] [--json] ──
|
|
529
597
|
req
|
|
530
598
|
.command('claim <id>')
|
|
531
599
|
.description('认领需求(占用校验;已被他人认领则拒绝)')
|
|
532
600
|
.option('--owner <owner>', '认领人(缺省:.openfeel/.info.json user → git config user.name)')
|
|
533
601
|
.option('--force', '正文门留痕放行(写 body_waiver + 审计 requirement_body_forced;仍应先补写正文)')
|
|
534
|
-
.
|
|
602
|
+
.option('--json', '以 JSON 输出 { schemaVersion, id, from, to, status, gates? }(v1.6.1 / REQ-063)')
|
|
603
|
+
.action((id, options, command) => {
|
|
535
604
|
const lang = getCliLang(process.cwd());
|
|
605
|
+
const asJson = asJsonOf(options, command);
|
|
536
606
|
const mgr = createManager();
|
|
537
607
|
if (!mgr.isLoaded()) {
|
|
538
|
-
|
|
608
|
+
failReqWrite(lang, asJson, 'NO_INIT', t('common.errorNoInit', lang), { reason: 'no-init' });
|
|
539
609
|
return;
|
|
540
610
|
}
|
|
541
611
|
const data = mgr.getData();
|
|
542
612
|
if (!isValidReqId(id)) {
|
|
543
|
-
|
|
544
|
-
process.exitCode = 1;
|
|
613
|
+
failReqWrite(lang, asJson, 'INVALID_ARGUMENT', t('req.invalidIdTmpl', lang, { input: id }), { field: 'id', value: id });
|
|
545
614
|
return;
|
|
546
615
|
}
|
|
547
616
|
// v1.5.5:认领前先读状态(放在 ID 校验之后,避免非法参数先报 preflight)
|
|
548
617
|
// v1.5.6-stage-114:收敛到统一 helper;**位置不变**(ID 校验仍在门前)
|
|
549
|
-
if (!enforcePreflightOrFail(process.cwd(), lang
|
|
618
|
+
if (!enforcePreflightOrFail(process.cwd(), lang, asJson
|
|
619
|
+
? { reject: (m) => failReqJson('INVALID_ARGUMENT', m, { reason: 'preflight-required' }) }
|
|
620
|
+
: undefined))
|
|
550
621
|
return;
|
|
551
622
|
// --owner 缺省链:.info.json user → git config user.name → 哨兵 'unknown' 拒绝(禁硬编码)
|
|
552
623
|
let owner = options.owner;
|
|
553
624
|
if (owner === undefined) {
|
|
554
625
|
const resolved = getUserName(process.cwd());
|
|
555
626
|
if (resolved === '' || resolved === 'unknown') {
|
|
556
|
-
|
|
557
|
-
process.exitCode = 1;
|
|
627
|
+
failReqWrite(lang, asJson, 'invalid_field', t('req.claim.ownerUnresolvedTmpl', lang));
|
|
558
628
|
return;
|
|
559
629
|
}
|
|
560
630
|
owner = resolved;
|
|
561
631
|
}
|
|
562
632
|
const projectPath = process.cwd();
|
|
633
|
+
const beforeStatus = getRequirement(data, id)?.status ?? '';
|
|
563
634
|
// 返回码分流(命令层仅映射,零校验):占用 / 终态均由引擎单点判定。
|
|
564
635
|
// v1.6.0 / REV-013:claim **不再校验正文**(认领 ≠ 开工),因此 `body_empty` 分支
|
|
565
636
|
// 目前不可达——保留 `--force` 选项与分支只为兼容旧脚本(选项键仍在 help 锁内)。
|
|
@@ -571,33 +642,44 @@ export function registerReqCommand(program) {
|
|
|
571
642
|
by: resolveActorName(projectPath), reason: 'claim-force', gate: 'claim',
|
|
572
643
|
});
|
|
573
644
|
if (!forced.ok) {
|
|
574
|
-
|
|
645
|
+
failReqWrite(lang, asJson, forced.code, codeMessage(lang, forced.code, {
|
|
575
646
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
576
647
|
invalid_status: t('req.claim.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
577
|
-
});
|
|
648
|
+
}), { id });
|
|
578
649
|
return;
|
|
579
650
|
}
|
|
580
651
|
r = claimRequirement(data, id, owner, { projectPath });
|
|
581
652
|
bodyForced = r.ok;
|
|
582
653
|
}
|
|
583
654
|
if (!r.ok) {
|
|
584
|
-
|
|
655
|
+
failReqWrite(lang, asJson, r.code, codeMessage(lang, r.code, {
|
|
585
656
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
586
657
|
already_claimed: t('req.err.alreadyClaimedTmpl', lang, { id }),
|
|
587
658
|
invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
|
|
588
659
|
invalid_status: t('req.claim.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
589
660
|
body_empty: bodyGateMessage(lang, data, id),
|
|
590
|
-
});
|
|
661
|
+
}), { id });
|
|
591
662
|
return;
|
|
592
663
|
}
|
|
664
|
+
// 状态不因认领而变(claim 只写 owner/claimed_at):`from` / `to` 同为当前状态
|
|
665
|
+
const statusNow = getRequirement(data, id)?.status ?? beforeStatus;
|
|
666
|
+
const gates = bodyForced ? ['req_body'] : undefined;
|
|
593
667
|
if (!r.changed) {
|
|
594
668
|
// 同 owner 幂等:不 save(revision 不变)
|
|
669
|
+
if (asJson) {
|
|
670
|
+
emitReqWriteJson({ id, from: beforeStatus, to: statusNow, status: statusNow, gates });
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
595
673
|
console.log(t('req.claim.idempotentTmpl', lang, { id, owner }));
|
|
596
674
|
return;
|
|
597
675
|
}
|
|
598
676
|
if (!saveOrFail(mgr, lang)) {
|
|
599
677
|
return;
|
|
600
678
|
}
|
|
679
|
+
if (asJson) {
|
|
680
|
+
emitReqWriteJson({ id, from: beforeStatus, to: statusNow, status: statusNow, gates });
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
601
683
|
console.log(t('req.claim.doneTmpl', lang, { id, owner })
|
|
602
684
|
+ (bodyForced ? t('req.claim.bodyForcedSuffix', lang) : ''));
|
|
603
685
|
});
|
|
@@ -682,6 +764,8 @@ export function registerReqCommand(program) {
|
|
|
682
764
|
// done 门专用文案(stage-93 BUG-002):静态表放行 done 而仍被拒 ⇒ 唯一可能是完成门
|
|
683
765
|
const doneGate = options.status === 'done'
|
|
684
766
|
&& getAllowedNextStatuses(current).includes('done');
|
|
767
|
+
// v1.6.1 / REQ-063 A63.1:`in_progress → done` 直连被流转表拒绝 → 指向 review_pending
|
|
768
|
+
const reviewPhaseBlocked = options.status === 'done' && current === 'in_progress' && r.code === 'invalid_status';
|
|
685
769
|
failCode(lang, r.code, {
|
|
686
770
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
687
771
|
invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
|
|
@@ -690,14 +774,19 @@ export function registerReqCommand(program) {
|
|
|
690
774
|
// v1.6.0 / stage-132 T4 · T7:正文门 / 需求级计划门(`set` 无 --force,文案指向 advance --force)
|
|
691
775
|
body_empty: bodyGateMessage(lang, data, id),
|
|
692
776
|
plan_missing: planGateMessage(lang, id),
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
777
|
+
// v1.6.1 / REQ-063 A63.2:done 门两码(`set` 无 --json,沿用 human 文案)
|
|
778
|
+
review_required: t('req.err.reviewRequiredTmpl', lang, { id, current }),
|
|
779
|
+
verification_required: t('req.err.verificationRequiredTmpl', lang, { id, current }),
|
|
780
|
+
invalid_status: reviewPhaseBlocked
|
|
781
|
+
? t('req.err.reviewPhaseRequiredTmpl', lang, { id })
|
|
782
|
+
: (doneGate
|
|
783
|
+
? doneGateMessage(lang, data, id, current)
|
|
784
|
+
: t('req.err.invalidStatusTmpl', lang, {
|
|
785
|
+
id,
|
|
786
|
+
to: options.status ?? '',
|
|
787
|
+
current,
|
|
788
|
+
targets: getAllowedNextStatuses(current).join(', '),
|
|
789
|
+
})),
|
|
701
790
|
general_mode_conflict: t('req.err.generalModeConflictTmpl', lang, { id }),
|
|
702
791
|
});
|
|
703
792
|
return;
|
|
@@ -802,29 +891,32 @@ export function registerReqCommand(program) {
|
|
|
802
891
|
console.log(t('req.link.doneTmpl', lang, { stage: stageKey, id: requirementId ?? '' }));
|
|
803
892
|
}
|
|
804
893
|
});
|
|
805
|
-
// ── req advance <id> --to <status> [--force] ──
|
|
894
|
+
// ── req advance <id> --to <status> [--force] [--json] ──
|
|
806
895
|
req
|
|
807
896
|
.command('advance <id>')
|
|
808
|
-
.description('显式推进需求状态(合法目标由引擎流转表判定;done
|
|
897
|
+
.description('显式推进需求状态(合法目标由引擎流转表判定;done 须先经 review_pending,零关联可直接完成,关联阶段进入 exec_running 及之后相位即可完成)')
|
|
809
898
|
.requiredOption('--to <status>', '目标状态(合法目标由引擎判定)')
|
|
810
|
-
.option('--force', '门留痕放行(正文/计划门写 waiver、计划偏差 +1;均留审计,文件仍须补写)')
|
|
811
|
-
.
|
|
899
|
+
.option('--force', '门留痕放行(正文/计划门写 waiver、计划偏差 +1、in_progress→done 跳链记 req_review;均留审计,文件仍须补写)')
|
|
900
|
+
.option('--json', '以 JSON 输出 { schemaVersion, id, from, to, status, gates? }(v1.6.1 / REQ-063)')
|
|
901
|
+
.action((id, options, command) => {
|
|
812
902
|
const lang = getCliLang(process.cwd());
|
|
903
|
+
const asJson = asJsonOf(options, command);
|
|
813
904
|
const mgr = createManager();
|
|
814
905
|
if (!mgr.isLoaded()) {
|
|
815
|
-
|
|
906
|
+
failReqWrite(lang, asJson, 'NO_INIT', t('common.errorNoInit', lang), { reason: 'no-init' });
|
|
816
907
|
return;
|
|
817
908
|
}
|
|
818
909
|
const data = mgr.getData();
|
|
819
910
|
if (!isValidReqId(id)) {
|
|
820
|
-
|
|
821
|
-
process.exitCode = 1;
|
|
911
|
+
failReqWrite(lang, asJson, 'INVALID_ARGUMENT', t('req.invalidIdTmpl', lang, { input: id }), { field: 'id', value: id });
|
|
822
912
|
return;
|
|
823
913
|
}
|
|
824
914
|
// 读当前状态仅供成功文案与失败 targets 渲染(纯读,非校验)
|
|
825
915
|
const before = getRequirement(data, id)?.status;
|
|
826
916
|
// v1.5.6-stage-114:写前 preflight(ID 校验已在门前)
|
|
827
|
-
if (!enforcePreflightOrFail(process.cwd(), lang
|
|
917
|
+
if (!enforcePreflightOrFail(process.cwd(), lang, asJson
|
|
918
|
+
? { reject: (m) => failReqJson('INVALID_ARGUMENT', m, { reason: 'preflight-required' }) }
|
|
919
|
+
: undefined))
|
|
828
920
|
return;
|
|
829
921
|
const projectPath = process.cwd();
|
|
830
922
|
// v1.6.0 / REQ-056 T6:未盖章历史需求(plan? 缺省)在 done 时**放行但提示**——
|
|
@@ -834,6 +926,30 @@ export function registerReqCommand(program) {
|
|
|
834
926
|
let r = advanceRequirement(data, id, options.to, { projectPath });
|
|
835
927
|
let planDeviationForced = false;
|
|
836
928
|
let gateForced = false;
|
|
929
|
+
/** 是否走过「审查相位跳链」留痕通道(`--force`;后续重试必须继续携带,否则表外再拒) */
|
|
930
|
+
let reviewSkipped = false;
|
|
931
|
+
/** 实际被 `--force` 放行的门(JSON 成功文档的 `gates`;与 GateOverrideGate 同闭集) */
|
|
932
|
+
const gates = [];
|
|
933
|
+
// v1.6.1 / REQ-063 A63.1:`in_progress → done` 的跳链留痕放行(唯一例外通道)——
|
|
934
|
+
// 引擎侧 `allowReviewSkip` 只放行**流转表**这一条拒绝,done 门(review+verify)照旧生效。
|
|
935
|
+
if (!r.ok && r.code === 'invalid_status' && options.to === 'done'
|
|
936
|
+
&& before === 'in_progress' && options.force === true) {
|
|
937
|
+
r = advanceRequirement(data, id, 'done', {
|
|
938
|
+
projectPath,
|
|
939
|
+
allowReviewSkip: true,
|
|
940
|
+
by: resolveActorName(projectPath),
|
|
941
|
+
gateReason: 'advance-force',
|
|
942
|
+
});
|
|
943
|
+
reviewSkipped = true;
|
|
944
|
+
}
|
|
945
|
+
/** 重试选项:跳链已放行时必须续带 `allowReviewSkip`(否则同一条流转又被流转表拒绝) */
|
|
946
|
+
const retryOpts = (extra = {}) => ({
|
|
947
|
+
projectPath,
|
|
948
|
+
...(reviewSkipped
|
|
949
|
+
? { allowReviewSkip: true, by: resolveActorName(projectPath), gateReason: 'advance-force' }
|
|
950
|
+
: {}),
|
|
951
|
+
...extra,
|
|
952
|
+
});
|
|
837
953
|
// v1.6.0 / stage-132 T4 · T7:正文门 / 计划门的 --force 通道——
|
|
838
954
|
// 写入 waiver(留痕)+ 审计后,用**同一谓词**重新求值(门本体不重写)。
|
|
839
955
|
// 同一次流转可能**连撞两门**(空壳正文 + 无计划):循环上限 = 门数(2),逐个留痕放行。
|
|
@@ -843,55 +959,83 @@ export function registerReqCommand(program) {
|
|
|
843
959
|
? forceRequirementBodyWaiver(data, id, { by: resolveActorName(projectPath), reason: 'advance-force', gate: 'advance' })
|
|
844
960
|
: forceRequirementPlanWaiver(data, id, { by: resolveActorName(projectPath), reason: 'advance-force', gate: 'advance' });
|
|
845
961
|
if (!forced.ok) {
|
|
846
|
-
|
|
962
|
+
failReqWrite(lang, asJson, forced.code, codeMessage(lang, forced.code, {
|
|
847
963
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
848
964
|
invalid_status: t('req.err.invalidStatusTmpl', lang, {
|
|
849
965
|
id, to: options.to, current: before ?? '',
|
|
850
966
|
targets: before !== undefined ? getAllowedNextStatuses(before).join(', ') : '',
|
|
851
967
|
}),
|
|
852
|
-
});
|
|
968
|
+
}), { id, to: options.to });
|
|
853
969
|
return;
|
|
854
970
|
}
|
|
855
|
-
|
|
856
|
-
|
|
971
|
+
const forcedGate = r.code === 'body_empty' ? 'req_body' : 'req_plan';
|
|
972
|
+
r = advanceRequirement(data, id, options.to, retryOpts());
|
|
973
|
+
if (r.ok) {
|
|
974
|
+
if (!gates.includes(forcedGate)) {
|
|
975
|
+
gates.push(forcedGate);
|
|
976
|
+
}
|
|
977
|
+
gateForced = true;
|
|
978
|
+
}
|
|
857
979
|
}
|
|
858
980
|
if (!r.ok && r.code === 'plan_deviation' && options.force === true) {
|
|
859
981
|
// 留痕放行:先记偏差次数 + 审计(判据本体不重写),再走同一门放行通道
|
|
860
982
|
const forced = forceRequirementPlanDeviation(data, id, { by: resolveActorName(projectPath) });
|
|
861
983
|
if (!forced.ok) {
|
|
862
|
-
|
|
984
|
+
failReqWrite(lang, asJson, forced.code, codeMessage(lang, forced.code, {
|
|
863
985
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
864
986
|
invalid_status: t('req.advance.forceRequiresStampTmpl', lang, { id }),
|
|
865
|
-
});
|
|
987
|
+
}), { id, to: options.to });
|
|
866
988
|
return;
|
|
867
989
|
}
|
|
868
|
-
r = advanceRequirement(data, id, options.to, {
|
|
990
|
+
r = advanceRequirement(data, id, options.to, retryOpts({ allowPlanDeviation: true }));
|
|
869
991
|
planDeviationForced = r.ok;
|
|
992
|
+
if (r.ok && !gates.includes('req_plan')) {
|
|
993
|
+
gates.push('req_plan');
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
// 跳链与偏差可能在不同重试轮次才成功:成功时统一补登 `req_review`(审计已在引擎侧写入)
|
|
997
|
+
if (r.ok && reviewSkipped) {
|
|
998
|
+
gateForced = true;
|
|
999
|
+
if (!gates.includes('req_review')) {
|
|
1000
|
+
gates.unshift('req_review');
|
|
1001
|
+
}
|
|
870
1002
|
}
|
|
1003
|
+
const statusNow = getRequirement(data, id)?.status ?? (before ?? '');
|
|
871
1004
|
if (!r.ok) {
|
|
872
1005
|
// done 门专用文案(stage-93 BUG-002):静态表放行 done 而仍被拒 ⇒ 唯一可能是完成门
|
|
873
1006
|
const doneGate = options.to === 'done'
|
|
874
1007
|
&& before !== undefined
|
|
875
1008
|
&& getAllowedNextStatuses(before).includes('done');
|
|
876
|
-
|
|
1009
|
+
// v1.6.1 / REQ-063 A63.1:`in_progress → done` 直连被流转表拒绝 → 指向 review_pending
|
|
1010
|
+
const reviewPhaseBlocked = options.to === 'done' && before === 'in_progress' && r.code === 'invalid_status';
|
|
1011
|
+
failReqWrite(lang, asJson, r.code, codeMessage(lang, r.code, {
|
|
877
1012
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
878
1013
|
// v1.6.0 / REQ-056 T6:计划被执行改动且 `## 偏差与回写` 未写实(done 门已通过后才可能到这)
|
|
879
1014
|
plan_deviation: t('req.err.planDeviationTmpl', lang, { id }),
|
|
880
1015
|
// v1.6.0 / stage-132 T4 · T7:正文门 / 需求级计划门(补写指引 + 可复制的命令)
|
|
881
1016
|
body_empty: bodyGateMessage(lang, data, id),
|
|
882
1017
|
plan_missing: planGateMessage(lang, id),
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1018
|
+
// v1.6.1 / REQ-063 A63.2:done 门两码(判据单源 requirementDoneBlocker)
|
|
1019
|
+
review_required: t('req.err.reviewRequiredTmpl', lang, { id, current: before ?? '' }),
|
|
1020
|
+
verification_required: t('req.err.verificationRequiredTmpl', lang, { id, current: before ?? '' }),
|
|
1021
|
+
invalid_status: reviewPhaseBlocked
|
|
1022
|
+
? t('req.err.reviewPhaseRequiredTmpl', lang, { id })
|
|
1023
|
+
: (doneGate
|
|
1024
|
+
? doneGateMessage(lang, data, id, before ?? '')
|
|
1025
|
+
: t('req.err.invalidStatusTmpl', lang, {
|
|
1026
|
+
id,
|
|
1027
|
+
to: options.to,
|
|
1028
|
+
current: before ?? '',
|
|
1029
|
+
targets: before !== undefined ? getAllowedNextStatuses(before).join(', ') : '',
|
|
1030
|
+
})),
|
|
1031
|
+
}), { id, to: options.to, current: before ?? null });
|
|
892
1032
|
return;
|
|
893
1033
|
}
|
|
894
1034
|
if (!r.changed) {
|
|
1035
|
+
if (asJson) {
|
|
1036
|
+
emitReqWriteJson({ id, from: before ?? statusNow, to: options.to, status: statusNow, gates });
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
895
1039
|
console.log(t('req.advance.noopTmpl', lang, { id, to: options.to }));
|
|
896
1040
|
return;
|
|
897
1041
|
}
|
|
@@ -901,6 +1045,10 @@ export function registerReqCommand(program) {
|
|
|
901
1045
|
if (planUnstamped) {
|
|
902
1046
|
console.warn(t('req.warn.planUnstampedTmpl', lang, { id }));
|
|
903
1047
|
}
|
|
1048
|
+
if (asJson) {
|
|
1049
|
+
emitReqWriteJson({ id, from: before ?? '', to: options.to, status: statusNow, gates });
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
904
1052
|
console.log(t('req.advance.doneTmpl', lang, { id, from: before ?? '', to: options.to })
|
|
905
1053
|
+ (planDeviationForced ? t('req.advance.planDeviationForcedSuffix', lang) : '')
|
|
906
1054
|
+ (gateForced ? t('req.advance.gateForcedSuffix', lang) : ''));
|
|
@@ -993,13 +1141,14 @@ export function registerReqCommand(program) {
|
|
|
993
1141
|
? t('req.trivial.revokedTmpl', lang, { id })
|
|
994
1142
|
: t('req.trivial.doneTmpl', lang, { id, reason: options.reason ?? '' }));
|
|
995
1143
|
});
|
|
996
|
-
// ── req complete <id> --result pass --note <t> [--kind] [--evidence] [--by] [--independent|--self] [--force] ──
|
|
1144
|
+
// ── req complete <id> --result pass --note <t> [--kind] [--evidence] [--by] [--independent|--self] [--force] [--json] ──
|
|
997
1145
|
// v1.5.23 / REQ-043(六期反馈 #1):一次收口 = review + verify + advance(done)。
|
|
998
1146
|
// 复用既有判据单点(recordRequirementReview / recordRequirementVerification / advanceRequirement
|
|
999
1147
|
// → canCompleteRequirement);任一步失败即返回,**不 save ⇒ flow.json 零变更**。
|
|
1148
|
+
// v1.6.1 / REQ-063 A63.1:收口链改为 in_progress → review_pending → done(审查相位不再被跳过)。
|
|
1000
1149
|
req
|
|
1001
1150
|
.command('complete <id>')
|
|
1002
|
-
.description('一次收口:记录审查+验证并推进 done
|
|
1151
|
+
.description('一次收口:记录审查+验证并推进 done(经 review_pending 相位;复用既有 done 门;任一失败零写盘)')
|
|
1003
1152
|
.requiredOption('--result <result>', '审验结论(pass / fail;pass 才能收口)')
|
|
1004
1153
|
.option('--kind <kind>', '验证种类(test / manual / build;缺省 manual)')
|
|
1005
1154
|
.requiredOption('--note <text>', '结论摘要(进入归档摘要)')
|
|
@@ -1008,49 +1157,58 @@ export function registerReqCommand(program) {
|
|
|
1008
1157
|
.option('--independent', '独立审查(推荐)')
|
|
1009
1158
|
.option('--self', '自我审查(非独立;归档摘要标注 self-review)')
|
|
1010
1159
|
.option('--force', '门留痕放行(正文/计划门写 waiver + 审计;文件仍须补写)')
|
|
1011
|
-
.
|
|
1160
|
+
.option('--json', '以 JSON 输出 { schemaVersion, id, from, to, status, gates? }(v1.6.1 / REQ-063)')
|
|
1161
|
+
.action((id, options, command) => {
|
|
1012
1162
|
const lang = getCliLang(process.cwd());
|
|
1163
|
+
const asJson = asJsonOf(options, command);
|
|
1013
1164
|
const mgr = createManager();
|
|
1014
1165
|
if (!mgr.isLoaded()) {
|
|
1015
|
-
|
|
1166
|
+
failReqWrite(lang, asJson, 'NO_INIT', t('common.errorNoInit', lang), { reason: 'no-init' });
|
|
1016
1167
|
return;
|
|
1017
1168
|
}
|
|
1018
1169
|
const data = mgr.getData();
|
|
1019
1170
|
if (!isValidReqId(id)) {
|
|
1020
|
-
|
|
1021
|
-
process.exitCode = 1;
|
|
1171
|
+
failReqWrite(lang, asJson, 'INVALID_ARGUMENT', t('req.invalidIdTmpl', lang, { input: id }), { field: 'id', value: id });
|
|
1022
1172
|
return;
|
|
1023
1173
|
}
|
|
1024
1174
|
if (options.independent === true && options.self === true) {
|
|
1025
|
-
|
|
1026
|
-
process.exitCode = 1;
|
|
1175
|
+
failReqWrite(lang, asJson, 'INVALID_ARGUMENT', t('req.review.exclusiveFlagTmpl', lang));
|
|
1027
1176
|
return;
|
|
1028
1177
|
}
|
|
1029
|
-
if (!enforcePreflightOrFail(process.cwd(), lang
|
|
1178
|
+
if (!enforcePreflightOrFail(process.cwd(), lang, asJson
|
|
1179
|
+
? { reject: (m) => failReqJson('INVALID_ARGUMENT', m, { reason: 'preflight-required' }) }
|
|
1180
|
+
: undefined))
|
|
1030
1181
|
return;
|
|
1031
1182
|
const by = resolveActorName(process.cwd(), options.by);
|
|
1032
1183
|
const independent = options.independent === true;
|
|
1033
1184
|
// v1.5.24 / REQ-051:收口请求可直接从 draft / scheduled 起——自动补状态链
|
|
1034
1185
|
// (这正是一条命令收口的完整语义;blocked / 终态仍需人工先处理)。
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1186
|
+
// v1.6.1 / REQ-063 A63.1:`review_pending` 亦为合法起点(已挂审查窗口的需求可一次收口)。
|
|
1187
|
+
const fromStatus = getRequirement(data, id)?.status ?? '';
|
|
1188
|
+
let stateNow = fromStatus;
|
|
1189
|
+
if (!['draft', 'scheduled', 'in_progress', 'review_pending'].includes(stateNow)) {
|
|
1190
|
+
failReqWrite(lang, asJson, 'invalid_status', t('req.complete.statusTmpl', lang, { id, status: stateNow }), { id });
|
|
1039
1191
|
return;
|
|
1040
1192
|
}
|
|
1041
1193
|
const projectPath = process.cwd();
|
|
1194
|
+
/** 实际被 `--force` 放行的门(JSON 成功文档的 `gates`) */
|
|
1195
|
+
const gates = [];
|
|
1042
1196
|
/** 门的 --force 通道(T4 正文 / T7 计划):写 waiver + 审计后由调用方用同一谓词重试 */
|
|
1043
1197
|
const forceGate = (code) => {
|
|
1044
1198
|
const forced = code === 'body_empty'
|
|
1045
1199
|
? forceRequirementBodyWaiver(data, id, { by, reason: 'complete-force', gate: 'complete' })
|
|
1046
1200
|
: forceRequirementPlanWaiver(data, id, { by, reason: 'complete-force', gate: 'complete' });
|
|
1047
1201
|
if (!forced.ok) {
|
|
1048
|
-
|
|
1202
|
+
failReqWrite(lang, asJson, forced.code, codeMessage(lang, forced.code, {
|
|
1049
1203
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
1050
1204
|
invalid_status: t('req.complete.statusTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
1051
|
-
});
|
|
1205
|
+
}), { id });
|
|
1052
1206
|
return false;
|
|
1053
1207
|
}
|
|
1208
|
+
const forcedGate = code === 'body_empty' ? 'req_body' : 'req_plan';
|
|
1209
|
+
if (!gates.includes(forcedGate)) {
|
|
1210
|
+
gates.push(forcedGate);
|
|
1211
|
+
}
|
|
1054
1212
|
return true;
|
|
1055
1213
|
};
|
|
1056
1214
|
let gateForced = false;
|
|
@@ -1067,7 +1225,7 @@ export function registerReqCommand(program) {
|
|
|
1067
1225
|
gateForced = moved.ok;
|
|
1068
1226
|
}
|
|
1069
1227
|
if (!moved.ok) {
|
|
1070
|
-
|
|
1228
|
+
failReqWrite(lang, asJson, moved.code, codeMessage(lang, moved.code, {
|
|
1071
1229
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
1072
1230
|
invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
|
|
1073
1231
|
// v1.6.0 / stage-132 T4 · T7:自动补链同样过正文门 / 计划门(不因「一条命令」而绕过)
|
|
@@ -1077,18 +1235,18 @@ export function registerReqCommand(program) {
|
|
|
1077
1235
|
id, to: step, current: stateNow, targets: getAllowedNextStatuses(stateNow).join(', '),
|
|
1078
1236
|
}),
|
|
1079
1237
|
general_mode_conflict: t('req.err.generalModeConflictTmpl', lang, { id }),
|
|
1080
|
-
});
|
|
1238
|
+
}), { id, to: step, current: stateNow });
|
|
1081
1239
|
return;
|
|
1082
1240
|
}
|
|
1083
1241
|
stateNow = step;
|
|
1084
1242
|
}
|
|
1085
1243
|
const review = recordRequirementReview(data, id, { result: options.result, by, note: options.note, independent, session: currentSession() });
|
|
1086
1244
|
if (!review.ok) {
|
|
1087
|
-
|
|
1245
|
+
failReqWrite(lang, asJson, review.code, codeMessage(lang, review.code, {
|
|
1088
1246
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
1089
1247
|
invalid_status: t('req.review.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
1090
1248
|
invalid_field: t('req.review.invalidTmpl', lang),
|
|
1091
|
-
});
|
|
1249
|
+
}), { id });
|
|
1092
1250
|
return;
|
|
1093
1251
|
}
|
|
1094
1252
|
const verification = recordRequirementVerification(data, id, {
|
|
@@ -1100,14 +1258,30 @@ export function registerReqCommand(program) {
|
|
|
1100
1258
|
session: currentSession(),
|
|
1101
1259
|
});
|
|
1102
1260
|
if (!verification.ok) {
|
|
1103
|
-
|
|
1261
|
+
failReqWrite(lang, asJson, verification.code, codeMessage(lang, verification.code, {
|
|
1104
1262
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
1105
1263
|
invalid_status: t('req.verify.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
1106
1264
|
invalid_field: t('req.verify.invalidTmpl', lang),
|
|
1107
|
-
});
|
|
1265
|
+
}), { id });
|
|
1108
1266
|
return;
|
|
1109
1267
|
}
|
|
1110
|
-
|
|
1268
|
+
// v1.6.1 / REQ-063 A63.1:先入审查相位(in_progress → review_pending),再由审查相位 → done。
|
|
1269
|
+
// 这一步不经 `--force`:一条命令收口的语义就是「走完整条链」,跳链只留给显式 advance --force。
|
|
1270
|
+
if (stateNow === 'in_progress') {
|
|
1271
|
+
const hop = advanceRequirement(data, id, 'review_pending', { projectPath });
|
|
1272
|
+
if (!hop.ok) {
|
|
1273
|
+
failReqWrite(lang, asJson, hop.code, codeMessage(lang, hop.code, {
|
|
1274
|
+
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
1275
|
+
invalid_status: t('req.err.invalidStatusTmpl', lang, {
|
|
1276
|
+
id, to: 'review_pending', current: stateNow,
|
|
1277
|
+
targets: getAllowedNextStatuses(stateNow).join(', '),
|
|
1278
|
+
}),
|
|
1279
|
+
}), { id, to: 'review_pending', current: stateNow });
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
stateNow = 'review_pending';
|
|
1283
|
+
}
|
|
1284
|
+
const current = getRequirement(data, id)?.status ?? stateNow;
|
|
1111
1285
|
let advanced = advanceRequirement(data, id, 'done', { projectPath });
|
|
1112
1286
|
for (let i = 0; i < 2 && !advanced.ok && options.force === true
|
|
1113
1287
|
&& (advanced.code === 'body_empty' || advanced.code === 'plan_missing'); i += 1) {
|
|
@@ -1118,7 +1292,7 @@ export function registerReqCommand(program) {
|
|
|
1118
1292
|
}
|
|
1119
1293
|
if (!advanced.ok) {
|
|
1120
1294
|
// 走到这里 = 审验记录已写但状态没推进:不 save(零写盘),按 done 门文案说明缺什么
|
|
1121
|
-
|
|
1295
|
+
failReqWrite(lang, asJson, advanced.code, codeMessage(lang, advanced.code, {
|
|
1122
1296
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
1123
1297
|
invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
|
|
1124
1298
|
// v1.6.0 / REQ-056 T6:计划偏差门(done 门通过后)
|
|
@@ -1126,14 +1300,21 @@ export function registerReqCommand(program) {
|
|
|
1126
1300
|
// v1.6.0 / stage-132 T4 · T7:正文门 / 计划门(先于 done 门)
|
|
1127
1301
|
body_empty: bodyGateMessage(lang, data, id),
|
|
1128
1302
|
plan_missing: planGateMessage(lang, id),
|
|
1303
|
+
// v1.6.1 / REQ-063 A63.2:done 门两码
|
|
1304
|
+
review_required: t('req.err.reviewRequiredTmpl', lang, { id, current }),
|
|
1305
|
+
verification_required: t('req.err.verificationRequiredTmpl', lang, { id, current }),
|
|
1129
1306
|
invalid_status: doneGateMessage(lang, data, id, current),
|
|
1130
1307
|
general_mode_conflict: t('req.err.generalModeConflictTmpl', lang, { id }),
|
|
1131
|
-
});
|
|
1308
|
+
}), { id, to: 'done', current });
|
|
1132
1309
|
return;
|
|
1133
1310
|
}
|
|
1134
1311
|
if (!saveOrFail(mgr, lang)) {
|
|
1135
1312
|
return;
|
|
1136
1313
|
}
|
|
1314
|
+
if (asJson) {
|
|
1315
|
+
emitReqWriteJson({ id, from: fromStatus, to: 'done', status: 'done', gates });
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1137
1318
|
const suffix = independent ? '' : t('req.review.selfSuffix', lang);
|
|
1138
1319
|
console.log(t('req.complete.doneTmpl', lang, {
|
|
1139
1320
|
id, result: options.result, kind: options.kind ?? 'manual',
|
|
@@ -1342,7 +1523,7 @@ export function registerReqCommand(program) {
|
|
|
1342
1523
|
// ── req board [--target-version <v>] [--json] ──
|
|
1343
1524
|
req
|
|
1344
1525
|
.command('board')
|
|
1345
|
-
.description('需求看板(按状态分组;
|
|
1526
|
+
.description('需求看板(按状态分组;8 组固定顺序 = REQ_STATUSES 声明序)')
|
|
1346
1527
|
.option('--target-version <version>', '按预估版本过滤')
|
|
1347
1528
|
.option('--json', '以 JSON 输出 { schemaVersion, groups }')
|
|
1348
1529
|
.action((options, command) => {
|
|
@@ -1356,7 +1537,8 @@ export function registerReqCommand(program) {
|
|
|
1356
1537
|
const data = mgr.getData();
|
|
1357
1538
|
// 只读保证:不 save / 不 appendLog / 零写盘
|
|
1358
1539
|
const rows = listRequirements(data, { target_version: options.targetVersion });
|
|
1359
|
-
//
|
|
1540
|
+
// 8 组固定顺序 = 状态值域声明序(v1.6.1 / REQ-063:新增 review_pending,旧 7 组一个不删)
|
|
1541
|
+
// 恒含空组(域外脏状态不渲染)
|
|
1360
1542
|
const groups = {};
|
|
1361
1543
|
for (const s of REQ_STATUSES) {
|
|
1362
1544
|
groups[s] = rows.filter((r) => r.status === s);
|
|
@@ -1592,17 +1774,126 @@ export function registerReqCommand(program) {
|
|
|
1592
1774
|
console.log(t('req.rollover.itemTmpl', lang, { id: moved.id, status: moved.status, title: moved.title }));
|
|
1593
1775
|
}
|
|
1594
1776
|
});
|
|
1777
|
+
// ── req plan <id> [--force] [--json] ──(v1.6.1 / REQ-064 A64.1)
|
|
1778
|
+
// 需求级计划从「照模板手写」变成一条命令生成:四节内容一律从需求正文派生(不编判据)。
|
|
1779
|
+
req
|
|
1780
|
+
.command('plan <id>')
|
|
1781
|
+
.description('生成需求级计划骨架(.openfeel/plan/reqs/REQ-NNN.plan.md;已存在默认拒绝,--force 覆盖)')
|
|
1782
|
+
.option('--force', '已存在时覆盖(会冲掉手写内容;默认拒绝且零写盘)')
|
|
1783
|
+
.option('--json', '以 JSON 输出 { schemaVersion, id, path, created, overwritten, lines }')
|
|
1784
|
+
.action((id, options, command) => {
|
|
1785
|
+
const lang = getCliLang(process.cwd());
|
|
1786
|
+
const asJson = asJsonOf(options, command);
|
|
1787
|
+
const mgr = createManager();
|
|
1788
|
+
if (!mgr.isLoaded()) {
|
|
1789
|
+
failNoInit(lang, asJson);
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
if (!isValidReqId(id)) {
|
|
1793
|
+
if (asJson) {
|
|
1794
|
+
failJson({ error: 'invalid-argument', field: 'id', value: id });
|
|
1795
|
+
}
|
|
1796
|
+
else {
|
|
1797
|
+
console.error(t('req.invalidIdTmpl', lang, { input: id }));
|
|
1798
|
+
process.exitCode = 1;
|
|
1799
|
+
}
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1802
|
+
const data = mgr.getData();
|
|
1803
|
+
const req_ = getRequirement(data, id);
|
|
1804
|
+
if (!req_) {
|
|
1805
|
+
if (asJson) {
|
|
1806
|
+
failJson({ error: 'not_found', id });
|
|
1807
|
+
}
|
|
1808
|
+
else {
|
|
1809
|
+
console.error(t('req.err.notFoundTmpl', lang, { id }));
|
|
1810
|
+
process.exitCode = 1;
|
|
1811
|
+
}
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1814
|
+
// v1.5.6-stage-114:写前 preflight(参数 / ID / 存在性校验已在门前)
|
|
1815
|
+
if (!enforcePreflightOrFail(process.cwd(), lang))
|
|
1816
|
+
return;
|
|
1817
|
+
try {
|
|
1818
|
+
const result = writeRequirementPlanSkeleton(process.cwd(), toRequirementPlanSeed(req_), {
|
|
1819
|
+
force: options.force === true,
|
|
1820
|
+
by: resolveActorName(process.cwd(), undefined),
|
|
1821
|
+
});
|
|
1822
|
+
if (asJson) {
|
|
1823
|
+
const doc = {
|
|
1824
|
+
id: req_.id,
|
|
1825
|
+
path: result.path,
|
|
1826
|
+
created: result.created,
|
|
1827
|
+
overwritten: result.overwritten,
|
|
1828
|
+
lines: result.lines,
|
|
1829
|
+
};
|
|
1830
|
+
// v1.6.1 / REQ-065(REQ-064 A64.1 的 `replaced:true` 取证键):
|
|
1831
|
+
// 只在**覆盖了已存在的计划**时末位追加条件键 `replaced:true`——
|
|
1832
|
+
// 新建路径的 6 键键集/键序与出口 #50 的冻结契约(`test/cli/json-contract.test.ts`)逐字不变,
|
|
1833
|
+
// 覆盖路径则同时给出 `overwritten`(语义等价)与 `replaced`(判据要求的键名)。
|
|
1834
|
+
if (result.overwritten) {
|
|
1835
|
+
doc.replaced = true;
|
|
1836
|
+
}
|
|
1837
|
+
emitJson(withSchemaVersion(doc));
|
|
1838
|
+
}
|
|
1839
|
+
else {
|
|
1840
|
+
console.log(result.created
|
|
1841
|
+
? `已生成需求计划 ${req_.id}:${result.path}(${result.lines} 行)`
|
|
1842
|
+
: `已覆盖需求计划 ${req_.id}:${result.path}(${result.lines} 行)`);
|
|
1843
|
+
}
|
|
1844
|
+
// 写后自检(A64.1):未写实说明需求正文摘要/验收仍是空壳——如实提示,不伪造内容
|
|
1845
|
+
if (!result.filled) {
|
|
1846
|
+
console.error(`注意:${req_.id} 的计划尚未通过写实判据(\`isRequirementPlanFilled\`);`
|
|
1847
|
+
+ '请先用 `req body` 补写 `## 摘要` / `## 目标与验收`,再 `req plan --force` 重新生成。');
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
catch (err) {
|
|
1851
|
+
if (err instanceof RequirementPlanFileError) {
|
|
1852
|
+
if (err.code === 'exists') {
|
|
1853
|
+
if (asJson) {
|
|
1854
|
+
// legacy 失败形态(`error` 恒 string,兼容既有消费方)+ 机器可读 `code`
|
|
1855
|
+
// (与 `error` 同值的稳定码;`errorKind:'refusal'` 由 failJson 统一追加在末尾)。
|
|
1856
|
+
failJson({
|
|
1857
|
+
error: 'plan_exists',
|
|
1858
|
+
code: 'plan_exists',
|
|
1859
|
+
id,
|
|
1860
|
+
path: getRequirementPlanRelPath(id),
|
|
1861
|
+
hint: 'use --force to overwrite',
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
else {
|
|
1865
|
+
console.error(`需求计划已存在:${err.existingPath ?? ''};如需覆盖请加 --force(会冲掉手写内容)。`);
|
|
1866
|
+
process.exitCode = 1;
|
|
1867
|
+
}
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
if (asJson) {
|
|
1871
|
+
// 其它计划文件错误(如 invalid_field):同样保留 legacy `error` 字符串,
|
|
1872
|
+
// 并追加机器可读 `code`(`errorKind:'refusal'` 由 failJson 统一追加在末尾)。
|
|
1873
|
+
failJson({ error: err.code, code: err.code, id });
|
|
1874
|
+
}
|
|
1875
|
+
else {
|
|
1876
|
+
console.error(err.message);
|
|
1877
|
+
process.exitCode = 1;
|
|
1878
|
+
}
|
|
1879
|
+
return;
|
|
1880
|
+
}
|
|
1881
|
+
failGeneric(lang, err);
|
|
1882
|
+
}
|
|
1883
|
+
});
|
|
1595
1884
|
// ── req body <id> --section <name> (--text <md> | --file <path>) [--append|--replace] [--json] ──
|
|
1596
1885
|
// v1.6.0-stage-132 / T2:需求正文**唯一写入口**(元信息小节受保护;每次写入追加 `## 变更记录`)
|
|
1886
|
+
// v1.6.1 / REQ-064 A64.2:新增 `--from <md>` —— 按 `##` 一次导入多节,元信息小节跳过并报告
|
|
1597
1887
|
req
|
|
1598
1888
|
.command('body <id>')
|
|
1599
1889
|
.description('写入需求正文的业务小节(元信息小节受保护;每次写入追加变更记录)')
|
|
1600
|
-
.
|
|
1890
|
+
.option('--section <name>', '小节名(如 摘要 / 目标与验收 / 问题 / 初步规划;与 --from 二选一)')
|
|
1891
|
+
.option('--from <path>', '从 Markdown 文件按 `##` 分节一次导入多个业务小节(与 --section/--text/--file 互斥)')
|
|
1601
1892
|
.option('--text <md>', '小节正文(Markdown;与 --file 二选一)')
|
|
1602
1893
|
.option('--file <path>', '从文件读取小节正文(与 --text 二选一;相对路径按项目根解析)')
|
|
1603
1894
|
.option('--append', '追加到该小节末尾(缺省替换整节)')
|
|
1604
1895
|
.option('--replace', '替换整节(缺省;与 --append 互斥)')
|
|
1605
|
-
.option('--json', '以 JSON 输出 { schemaVersion, id, section, path, lines, created }')
|
|
1896
|
+
.option('--json', '以 JSON 输出 { schemaVersion, id, section, path, lines, created }(--from 时为 { schemaVersion, id, sections })')
|
|
1606
1897
|
.action((id, options, command) => {
|
|
1607
1898
|
const lang = getCliLang(process.cwd());
|
|
1608
1899
|
const asJson = asJsonOf(options, command);
|
|
@@ -1633,32 +1924,70 @@ export function registerReqCommand(program) {
|
|
|
1633
1924
|
}
|
|
1634
1925
|
return;
|
|
1635
1926
|
}
|
|
1636
|
-
// argument-shape
|
|
1927
|
+
// argument-shape 守卫(非业务校验):
|
|
1928
|
+
// --from 独占(不与 --section/--text/--file 同用);否则 --section 必填 + --text/--file 恰一;--append/--replace 互斥
|
|
1929
|
+
const hasFrom = options.from !== undefined;
|
|
1637
1930
|
const hasText = options.text !== undefined;
|
|
1638
1931
|
const hasFile = options.file !== undefined;
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1932
|
+
const sectionName = options.section ?? '';
|
|
1933
|
+
if (hasFrom) {
|
|
1934
|
+
if (options.section !== undefined || hasText || hasFile) {
|
|
1935
|
+
if (asJson) {
|
|
1936
|
+
failJson({ error: 'invalid_field', id, field: 'from' });
|
|
1937
|
+
}
|
|
1938
|
+
else {
|
|
1939
|
+
console.error('--from 与 --section / --text / --file 互斥:一次只能选一种导入方式。');
|
|
1940
|
+
process.exitCode = 1;
|
|
1941
|
+
}
|
|
1942
|
+
return;
|
|
1642
1943
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1944
|
+
// --from 恒整节替换;--append / --replace 在该通道无意义,显式拒绝而不是静默忽略
|
|
1945
|
+
if (options.append === true || options.replace === true) {
|
|
1946
|
+
if (asJson) {
|
|
1947
|
+
failJson({ error: 'invalid_field', id, field: 'append' });
|
|
1948
|
+
}
|
|
1949
|
+
else {
|
|
1950
|
+
console.error('--from 恒整节替换:不要与 --append / --replace 同用。');
|
|
1951
|
+
process.exitCode = 1;
|
|
1952
|
+
}
|
|
1953
|
+
return;
|
|
1646
1954
|
}
|
|
1647
|
-
return;
|
|
1648
1955
|
}
|
|
1649
|
-
|
|
1650
|
-
if (
|
|
1651
|
-
|
|
1956
|
+
else {
|
|
1957
|
+
if (sectionName.trim() === '') {
|
|
1958
|
+
if (asJson) {
|
|
1959
|
+
failJson({ error: 'invalid_field', id, field: 'section' });
|
|
1960
|
+
}
|
|
1961
|
+
else {
|
|
1962
|
+
console.error('需要 --section <name>(或用 --from <file> 一次导入多节)。');
|
|
1963
|
+
process.exitCode = 1;
|
|
1964
|
+
}
|
|
1965
|
+
return;
|
|
1652
1966
|
}
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1967
|
+
if (!hasText && !hasFile) {
|
|
1968
|
+
if (asJson) {
|
|
1969
|
+
failJson({ error: 'empty_text', id, section: sectionName });
|
|
1970
|
+
}
|
|
1971
|
+
else {
|
|
1972
|
+
console.error(t('req.body.noTextTmpl', lang));
|
|
1973
|
+
process.exitCode = 1;
|
|
1974
|
+
}
|
|
1975
|
+
return;
|
|
1976
|
+
}
|
|
1977
|
+
if (hasText && hasFile) {
|
|
1978
|
+
if (asJson) {
|
|
1979
|
+
failJson({ error: 'invalid_field', id, section: sectionName, field: 'file' });
|
|
1980
|
+
}
|
|
1981
|
+
else {
|
|
1982
|
+
console.error(t('req.body.exclusiveTmpl', lang));
|
|
1983
|
+
process.exitCode = 1;
|
|
1984
|
+
}
|
|
1985
|
+
return;
|
|
1656
1986
|
}
|
|
1657
|
-
return;
|
|
1658
1987
|
}
|
|
1659
1988
|
if (options.append === true && options.replace === true) {
|
|
1660
1989
|
if (asJson) {
|
|
1661
|
-
failJson({ error: 'invalid_field', id, section:
|
|
1990
|
+
failJson({ error: 'invalid_field', id, section: sectionName, field: 'append' });
|
|
1662
1991
|
}
|
|
1663
1992
|
else {
|
|
1664
1993
|
console.error(t('req.body.flagExclusiveTmpl', lang));
|
|
@@ -1669,9 +1998,55 @@ export function registerReqCommand(program) {
|
|
|
1669
1998
|
// v1.5.6-stage-114:写前 preflight(参数 / ID 校验已在门前)
|
|
1670
1999
|
if (!enforcePreflightOrFail(process.cwd(), lang))
|
|
1671
2000
|
return;
|
|
2001
|
+
// ── --from:按 `##` 一次导入多节(A64.2;元信息小节跳过并报告,每节各追加一条变更记录) ──
|
|
2002
|
+
if (hasFrom) {
|
|
2003
|
+
try {
|
|
2004
|
+
const imported = importRequirementBodySections(process.cwd(), req_, {
|
|
2005
|
+
file: options.from,
|
|
2006
|
+
by: resolveActorName(process.cwd(), undefined),
|
|
2007
|
+
});
|
|
2008
|
+
if (imported.sections.length === 0) {
|
|
2009
|
+
if (asJson) {
|
|
2010
|
+
failJson({ error: 'invalid_field', id, field: 'from', detail: imported.skipped });
|
|
2011
|
+
}
|
|
2012
|
+
else {
|
|
2013
|
+
console.error(`未写入任何小节(元信息受保护 / 空白 / 名称非法):${imported.skipped.join('、')}`);
|
|
2014
|
+
process.exitCode = 1;
|
|
2015
|
+
}
|
|
2016
|
+
return;
|
|
2017
|
+
}
|
|
2018
|
+
// v1.6.0 / REQ-059 T8:正文写入成功即自动同步开发账本(--json 的告警走 stderr,不污染 stdout)
|
|
2019
|
+
syncDevAfterWrite(process.cwd(), lang);
|
|
2020
|
+
if (imported.skipped.length > 0) {
|
|
2021
|
+
console.error(`已跳过小节:${imported.skipped.join('、')}(元信息受保护 / 空白 / 名称非法)`);
|
|
2022
|
+
}
|
|
2023
|
+
if (asJson) {
|
|
2024
|
+
emitJson(withSchemaVersion({ id: req_.id, sections: imported.sections }));
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
console.log(`已从 ${options.from} 导入 ${imported.sections.length} 个小节到 ${req_.id} 正文(${imported.path}):`);
|
|
2028
|
+
for (const section of imported.sections) {
|
|
2029
|
+
console.log(` ${section.name}(${section.lines} 行${section.created ? ',新建' : ''})`);
|
|
2030
|
+
}
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
catch (err) {
|
|
2034
|
+
if (err instanceof RequirementBodyUpdateError) {
|
|
2035
|
+
if (asJson) {
|
|
2036
|
+
failJson({ error: err.code, id, field: 'from' });
|
|
2037
|
+
return;
|
|
2038
|
+
}
|
|
2039
|
+
console.error(`导入失败:${err.message}`);
|
|
2040
|
+
process.exitCode = 1;
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
failGeneric(lang, err);
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
1672
2047
|
try {
|
|
1673
2048
|
const result = updateRequirementBody(process.cwd(), req_, {
|
|
1674
|
-
section:
|
|
2049
|
+
section: sectionName,
|
|
1675
2050
|
...(options.text !== undefined ? { text: options.text } : {}),
|
|
1676
2051
|
...(options.file !== undefined ? { file: options.file } : {}),
|
|
1677
2052
|
append: options.append === true,
|
|
@@ -1705,13 +2080,13 @@ export function registerReqCommand(program) {
|
|
|
1705
2080
|
catch (err) {
|
|
1706
2081
|
if (err instanceof RequirementBodyUpdateError) {
|
|
1707
2082
|
if (asJson) {
|
|
1708
|
-
failJson({ error: err.code, id, section:
|
|
2083
|
+
failJson({ error: err.code, id, section: sectionName });
|
|
1709
2084
|
return;
|
|
1710
2085
|
}
|
|
1711
2086
|
const key = err.code === 'protected_section'
|
|
1712
2087
|
? 'req.body.protectedTmpl'
|
|
1713
2088
|
: (err.code === 'empty_text' ? 'req.body.emptyTmpl' : 'req.body.invalidFieldTmpl');
|
|
1714
|
-
console.error(t(key, lang, { id, section:
|
|
2089
|
+
console.error(t(key, lang, { id, section: sectionName }));
|
|
1715
2090
|
process.exitCode = 1;
|
|
1716
2091
|
return;
|
|
1717
2092
|
}
|