openfeel 1.5.25 → 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 +14 -0
- package/README.zh-CN.md +14 -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 +126 -25
- package/dist/commands/flow.js.map +1 -1
- package/dist/commands/lint.d.ts +5 -1
- package/dist/commands/lint.d.ts.map +1 -1
- package/dist/commands/lint.js +373 -0
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/req.d.ts.map +1 -1
- package/dist/commands/req.js +814 -88
- package/dist/commands/req.js.map +1 -1
- package/dist/commands/stage.d.ts.map +1 -1
- package/dist/commands/stage.js +19 -0
- package/dist/commands/stage.js.map +1 -1
- package/dist/core/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/dev-status.d.ts +25 -0
- package/dist/core/dev-status.d.ts.map +1 -1
- package/dist/core/dev-status.js +35 -0
- package/dist/core/dev-status.js.map +1 -1
- package/dist/core/errors.d.ts +38 -3
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +22 -3
- 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 +118 -3
- package/dist/core/flow-manager.d.ts.map +1 -1
- package/dist/core/flow-manager.js +357 -14
- package/dist/core/flow-manager.js.map +1 -1
- package/dist/core/i18n-data/en.d.ts.map +1 -1
- package/dist/core/i18n-data/en.js +96 -5
- 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 +96 -5
- package/dist/core/i18n-data/zh-CN.js.map +1 -1
- package/dist/core/lint-req.d.ts +17 -1
- package/dist/core/lint-req.d.ts.map +1 -1
- package/dist/core/lint-req.js +14 -2
- package/dist/core/lint-req.js.map +1 -1
- package/dist/core/plan/body-lint.d.ts +58 -0
- package/dist/core/plan/body-lint.d.ts.map +1 -0
- package/dist/core/plan/body-lint.js +197 -0
- package/dist/core/plan/body-lint.js.map +1 -0
- package/dist/core/plan/filled.d.ts +143 -0
- package/dist/core/plan/filled.d.ts.map +1 -0
- package/dist/core/plan/filled.js +244 -0
- package/dist/core/plan/filled.js.map +1 -0
- package/dist/core/plan/path.d.ts +24 -0
- package/dist/core/plan/path.d.ts.map +1 -1
- package/dist/core/plan/path.js +56 -0
- package/dist/core/plan/path.js.map +1 -1
- package/dist/core/req/aggregate.d.ts.map +1 -1
- package/dist/core/req/aggregate.js +5 -0
- package/dist/core/req/aggregate.js.map +1 -1
- package/dist/core/req/body-file.d.ts +103 -0
- package/dist/core/req/body-file.d.ts.map +1 -1
- package/dist/core/req/body-file.js +221 -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 +151 -15
- package/dist/core/req/requirement-ops.d.ts.map +1 -1
- package/dist/core/req/requirement-ops.js +402 -22
- package/dist/core/req/requirement-ops.js.map +1 -1
- package/dist/core/req/types.d.ts +63 -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 +87 -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 +50 -8
- package/dsh/ADAPTER.md +119 -13
- package/dsh/README.md +49 -26
- package/dsh/docs/compat/persistence.md +26 -0
- package/dsh/docs/compat/pipeline.md +24 -0
- package/dsh/docs/compat/req.md +29 -0
- package/dsh/docs/compat/stage.md +25 -0
- package/dsh/lib/adapters/dispatch-ledger.js +432 -0
- package/dsh/lib/adapters/dispatch.js +54 -6
- package/dsh/lib/adapters/next-action.js +336 -0
- package/dsh/lib/guard.js +694 -24
- package/dsh/lib/index.js +37 -0
- package/dsh/lib/surface/prompt.js +66 -178
- package/dsh/lib/tools/index.js +527 -12
- package/dsh/package.json +2 -2
- package/package.json +2 -1
package/dist/commands/req.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
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, importRequirementBodySections, getRequirementBodyPath, RequirementBodyUpdateError } from '../core/req/body-file.js';
|
|
9
|
+
import { writeRequirementPlanSkeleton, toRequirementPlanSeed, RequirementPlanFileError } from '../core/req/plan-file.js';
|
|
8
10
|
import { computeRequirementAggregate, listLinkedStages } from '../core/req/aggregate.js';
|
|
9
11
|
import { stageRequirementIds } from '../core/req/stage-links.js';
|
|
10
12
|
import { findArchivedRequirement, listArchivedRequirements, archivedRequirementMaxSeq } from '../core/flow-archive/archive-ops.js';
|
|
11
13
|
import { withSchemaVersion, emitJson } from './shared/json-output.js';
|
|
14
|
+
import { CLI_ERROR_CODES, getCliErrorSpec } from '../core/errors.js';
|
|
12
15
|
import { getUserName } from '../core/workspace/identity.js';
|
|
13
|
-
import { normalizeStageId } from '../core/plan/path.js';
|
|
16
|
+
import { normalizeStageId, getRequirementPlanRelPath } from '../core/plan/path.js';
|
|
14
17
|
import { getSessionId, resolveActorName } from '../core/session.js';
|
|
18
|
+
import { maybeSyncDevStatus } from '../core/dev-status.js';
|
|
15
19
|
/** 当前会话标识(写入审查/验证记录,用于人机区分与回溯;v1.5.24 / REQ-049) */
|
|
16
20
|
function currentSession() {
|
|
17
21
|
return getSessionId({ projectPath: process.cwd() });
|
|
@@ -69,6 +73,72 @@ function failCode(lang, code, msgs) {
|
|
|
69
73
|
console.error(msgs[code] ?? t('common.errorTmpl', lang, { msg: code }));
|
|
70
74
|
process.exitCode = 1;
|
|
71
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
|
+
}
|
|
72
142
|
/** 通用错误文案 + 退出码 1(非并发异常统一出口;不 return,由调用方 return) */
|
|
73
143
|
function failGeneric(lang, err) {
|
|
74
144
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -92,6 +162,27 @@ function doneGateMessage(lang, data, id, current) {
|
|
|
92
162
|
}
|
|
93
163
|
return t('req.err.doneGateTmpl', lang, { id, current });
|
|
94
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* 正文门拒绝文案(v1.6.0 / stage-132 T4)。
|
|
167
|
+
* 判据单源 = `requirementBodyBlocker`(引擎);本层只把「未写实的小节名」拼进 i18n 模板,
|
|
168
|
+
* 并给出可复制的 `req body` 补写命令(A2 的「提示用 req body 补写」要求)。
|
|
169
|
+
*/
|
|
170
|
+
function bodyGateMessage(lang, data, id) {
|
|
171
|
+
const req = getRequirement(data, id);
|
|
172
|
+
const sections = req ? requirementBodyEmptySections(process.cwd(), req) : [];
|
|
173
|
+
return t('req.err.bodyEmptyTmpl', lang, {
|
|
174
|
+
id,
|
|
175
|
+
sections: sections.length > 0 ? sections.join('、') : '摘要、目标与验收',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 需求级计划门拒绝文案(v1.6.0 / stage-132 T7)。
|
|
180
|
+
* `openfeel req plan` 尚不存在,因此文案给出**按模板创建文件**的具体路径与必备小节
|
|
181
|
+
* (真实指引优于虚构命令)。
|
|
182
|
+
*/
|
|
183
|
+
function planGateMessage(lang, id) {
|
|
184
|
+
return t('req.err.planMissingTmpl', lang, { id });
|
|
185
|
+
}
|
|
95
186
|
/**
|
|
96
187
|
* 保存并收敛并发:成功返回 true;并发冲突 → 单点处理(JSON 置码 2 返回 / 非 JSON exit 2),
|
|
97
188
|
* 其他异常 → 通用文案 exit 1 并返回 false。返回 false 时调用方须早返回。
|
|
@@ -111,6 +202,17 @@ function saveOrFail(mgr, lang) {
|
|
|
111
202
|
return false;
|
|
112
203
|
}
|
|
113
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* v1.6.0 / REQ-059 T8:**写成功出口**自动同步开发账本(`.openfeel/dev/**` + `dev_last.md`)。
|
|
207
|
+
* 需求写操作已成功,因此同步失败**不改变退出码**,只输出一行 stderr(不再静默吞掉)。
|
|
208
|
+
* 调用点仅限写命令成功出口(advance / complete / review / verify / body),读命令不调。
|
|
209
|
+
*/
|
|
210
|
+
function syncDevAfterWrite(projectPath, lang) {
|
|
211
|
+
const sync = maybeSyncDevStatus(projectPath);
|
|
212
|
+
if (sync.error !== undefined) {
|
|
213
|
+
console.warn(t('flow.dev.syncFailedTmpl', lang, { err: sync.error }));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
114
216
|
/** `req` 命令组注册入口 */
|
|
115
217
|
export function registerReqCommand(program) {
|
|
116
218
|
const req = program
|
|
@@ -126,6 +228,11 @@ export function registerReqCommand(program) {
|
|
|
126
228
|
.option('--claim', '创建后立即认领(v1.5.23:一次开单+认领)')
|
|
127
229
|
.option('--stage <stageId>', '创建后立即关联到该阶段(v1.5.23:一次开单+关联)')
|
|
128
230
|
.option('--start', '创建后直接进入 in_progress(自动 scheduled → in_progress;v1.5.25 / REQ-053)')
|
|
231
|
+
.option('--summary <md>', '正文 ## 摘要 小节(v1.6.0:正文写实;与 --goal/--acceptance 配合即可一步写实)')
|
|
232
|
+
.option('--problem <md>', '正文 ## 问题 小节(v1.6.0:正文写实)')
|
|
233
|
+
.option('--goal <md>', '正文 ## 目标与验收 → 目标 子节(v1.6.0:正文写实)')
|
|
234
|
+
.option('--acceptance <md>', '正文 ## 目标与验收 → 验收 子节(v1.6.0:正文写实)')
|
|
235
|
+
.option('--plan <md>', '正文 ## 初步规划 小节(v1.6.0:正文写实)')
|
|
129
236
|
.action((title, options) => {
|
|
130
237
|
const lang = getCliLang(process.cwd());
|
|
131
238
|
const mgr = createManager();
|
|
@@ -150,10 +257,13 @@ export function registerReqCommand(program) {
|
|
|
150
257
|
workflow_mode: options.workflowMode,
|
|
151
258
|
});
|
|
152
259
|
// v1.5.23 / REQ-043(六期反馈 #1):一次开单 + 认领 + 关联
|
|
260
|
+
// v1.6.0 / REV-013:claim / advance 都**显式传项目根**(不靠 cwd 推导)——
|
|
261
|
+
// claim 自 REV-013 起不校验正文(认领 ≠ 开工),但传根保证调用面同形;
|
|
262
|
+
// advance 的正文门(scheduled / in_progress / done)必须能定位正文文件。
|
|
153
263
|
let claimedOwner;
|
|
154
264
|
if (options.claim === true) {
|
|
155
265
|
const owner = getUserName(process.cwd());
|
|
156
|
-
const c = claimRequirement(data, created.id, owner);
|
|
266
|
+
const c = claimRequirement(data, created.id, owner, { projectPath: process.cwd() });
|
|
157
267
|
if (!c.ok) {
|
|
158
268
|
failGeneric(lang, new Error(t('req.add.claimFailedTmpl', lang, { id: created.id })));
|
|
159
269
|
return;
|
|
@@ -180,13 +290,77 @@ export function registerReqCommand(program) {
|
|
|
180
290
|
}
|
|
181
291
|
linkedStage = stageKey;
|
|
182
292
|
}
|
|
293
|
+
// 正文骨架 + 可选业务小节:**先于** `--start` 落盘。
|
|
294
|
+
// 原因(REV-013):`add --start` 走真实状态流转,正文门必须判到「本轮写下的正文」
|
|
295
|
+
// 而不是「还没有正文文件 ⇒ 无正文可判 ⇒ 放行」的空档;同时 `--goal/--acceptance`
|
|
296
|
+
// 等先写入,带正文内容的 `--start` 不会被误拦。
|
|
297
|
+
let bodyPath;
|
|
298
|
+
const bodyFilePath = getRequirementBodyPath(process.cwd(), created.id);
|
|
299
|
+
const bodyExistedBefore = existsSync(bodyFilePath);
|
|
300
|
+
/** 失败路径清理本轮新建的正文文件(不把孤儿正文留给下一次同 ID 复用) */
|
|
301
|
+
const discardNewBody = () => {
|
|
302
|
+
if (bodyExistedBefore) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
rmSync(bodyFilePath, { force: true });
|
|
307
|
+
}
|
|
308
|
+
catch { /* 清理失败不掩盖主错误 */ }
|
|
309
|
+
};
|
|
310
|
+
try {
|
|
311
|
+
bodyPath = writeRequirementBodySkeleton(process.cwd(), created);
|
|
312
|
+
}
|
|
313
|
+
catch (err) {
|
|
314
|
+
failGeneric(lang, err);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
// v1.6.0-stage-132 / T2:可选正文业务小节(未给的保持骨架占位;元信息小节不碰)
|
|
318
|
+
try {
|
|
319
|
+
const bodyActor = resolveActorName(process.cwd(), undefined);
|
|
320
|
+
const writeSection = (section, text) => {
|
|
321
|
+
updateRequirementBody(process.cwd(), created, {
|
|
322
|
+
section,
|
|
323
|
+
text,
|
|
324
|
+
createSectionIfMissing: true,
|
|
325
|
+
by: bodyActor,
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
if (options.summary !== undefined) {
|
|
329
|
+
// v1.6.0-stage-132 / T2(REQ-061):## 摘要 与 ## 目标与验收 都写实 ⇒ add --start 可一步过正文门
|
|
330
|
+
writeSection('摘要', options.summary);
|
|
331
|
+
}
|
|
332
|
+
if (options.problem !== undefined) {
|
|
333
|
+
writeSection('问题', options.problem);
|
|
334
|
+
}
|
|
335
|
+
if (options.goal !== undefined || options.acceptance !== undefined) {
|
|
336
|
+
// --goal 与 --acceptance 合并进 目标与验收 的两个子标题
|
|
337
|
+
const parts = [];
|
|
338
|
+
if (options.goal !== undefined) {
|
|
339
|
+
parts.push(`### 目标\n\n${options.goal.trim()}`);
|
|
340
|
+
}
|
|
341
|
+
if (options.acceptance !== undefined) {
|
|
342
|
+
parts.push(`### 验收\n\n${options.acceptance.trim()}`);
|
|
343
|
+
}
|
|
344
|
+
writeSection('目标与验收', parts.join('\n\n'));
|
|
345
|
+
}
|
|
346
|
+
if (options.plan !== undefined) {
|
|
347
|
+
writeSection('初步规划', options.plan);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
catch (err) {
|
|
351
|
+
discardNewBody();
|
|
352
|
+
failGeneric(lang, err);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
183
355
|
// v1.5.25 / REQ-053:一次开单到 in_progress(scheduled → in_progress 属引擎流转,
|
|
184
|
-
// 命令层不另写判据;失败则整体不 save
|
|
356
|
+
// 命令层不另写判据;失败则整体不 save,并清掉本轮新建的正文文件)
|
|
357
|
+
// v1.6.0 / REV-013:显式传项目根 —— 空壳正文在 scheduled 步即被正文门拦下。
|
|
185
358
|
let startedStatus;
|
|
186
359
|
if (options.start === true) {
|
|
187
360
|
for (const step of ['scheduled', 'in_progress']) {
|
|
188
|
-
const moved = advanceRequirement(data, created.id, step);
|
|
361
|
+
const moved = advanceRequirement(data, created.id, step, { projectPath: process.cwd() });
|
|
189
362
|
if (!moved.ok) {
|
|
363
|
+
discardNewBody();
|
|
190
364
|
failCode(lang, moved.code, {
|
|
191
365
|
not_found: t('req.err.notFoundTmpl', lang, { id: created.id }),
|
|
192
366
|
invalid_field: t('req.err.invalidFieldTmpl', lang, { id: created.id }),
|
|
@@ -194,21 +368,14 @@ export function registerReqCommand(program) {
|
|
|
194
368
|
id: created.id, to: step, current: created.status, targets: getAllowedNextStatuses(created.status).join(', '),
|
|
195
369
|
}),
|
|
196
370
|
general_mode_conflict: t('req.err.generalModeConflictTmpl', lang, { id: created.id }),
|
|
371
|
+
body_empty: bodyGateMessage(lang, data, created.id),
|
|
372
|
+
plan_missing: planGateMessage(lang, created.id),
|
|
197
373
|
});
|
|
198
374
|
return;
|
|
199
375
|
}
|
|
200
376
|
}
|
|
201
377
|
startedStatus = 'in_progress';
|
|
202
378
|
}
|
|
203
|
-
// 正文骨架:认领/关联都成功后再落盘(失败路径不留孤儿正文)
|
|
204
|
-
let bodyPath;
|
|
205
|
-
try {
|
|
206
|
-
bodyPath = writeRequirementBodySkeleton(process.cwd(), created);
|
|
207
|
-
}
|
|
208
|
-
catch (err) {
|
|
209
|
-
failGeneric(lang, err);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
379
|
if (!saveOrFail(mgr, lang)) {
|
|
213
380
|
return;
|
|
214
381
|
}
|
|
@@ -233,7 +400,7 @@ export function registerReqCommand(program) {
|
|
|
233
400
|
req
|
|
234
401
|
.command('list')
|
|
235
402
|
.description('列出需求(可按状态/版本/认领人过滤;--include-archived 合并已随版本归档的需求)')
|
|
236
|
-
.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)')
|
|
237
404
|
.option('--target-version <version>', '按预估版本过滤')
|
|
238
405
|
.option('--owner <owner>', '按认领人过滤')
|
|
239
406
|
.option('--include-archived', '包含已随版本归档的需求(只读;合并 .openfeel/flow-archive/*.json)')
|
|
@@ -426,59 +593,95 @@ export function registerReqCommand(program) {
|
|
|
426
593
|
// 关联阶段 = 原始只读枚举(零聚合计算 / 零阶段推进字段读取——归后续阶段);命令层输出面复用单点过滤(REV-97-006)
|
|
427
594
|
emitRequirement(active, listLinkedStages(data, id).map((l) => l.id), getRequirements(data).filter((r) => r.parent_id === id), null);
|
|
428
595
|
});
|
|
429
|
-
// ── req claim <id> [--owner <name>] ──
|
|
596
|
+
// ── req claim <id> [--owner <name>] [--force] [--json] ──
|
|
430
597
|
req
|
|
431
598
|
.command('claim <id>')
|
|
432
599
|
.description('认领需求(占用校验;已被他人认领则拒绝)')
|
|
433
600
|
.option('--owner <owner>', '认领人(缺省:.openfeel/.info.json user → git config user.name)')
|
|
434
|
-
.
|
|
601
|
+
.option('--force', '正文门留痕放行(写 body_waiver + 审计 requirement_body_forced;仍应先补写正文)')
|
|
602
|
+
.option('--json', '以 JSON 输出 { schemaVersion, id, from, to, status, gates? }(v1.6.1 / REQ-063)')
|
|
603
|
+
.action((id, options, command) => {
|
|
435
604
|
const lang = getCliLang(process.cwd());
|
|
605
|
+
const asJson = asJsonOf(options, command);
|
|
436
606
|
const mgr = createManager();
|
|
437
607
|
if (!mgr.isLoaded()) {
|
|
438
|
-
|
|
608
|
+
failReqWrite(lang, asJson, 'NO_INIT', t('common.errorNoInit', lang), { reason: 'no-init' });
|
|
439
609
|
return;
|
|
440
610
|
}
|
|
441
611
|
const data = mgr.getData();
|
|
442
612
|
if (!isValidReqId(id)) {
|
|
443
|
-
|
|
444
|
-
process.exitCode = 1;
|
|
613
|
+
failReqWrite(lang, asJson, 'INVALID_ARGUMENT', t('req.invalidIdTmpl', lang, { input: id }), { field: 'id', value: id });
|
|
445
614
|
return;
|
|
446
615
|
}
|
|
447
616
|
// v1.5.5:认领前先读状态(放在 ID 校验之后,避免非法参数先报 preflight)
|
|
448
617
|
// v1.5.6-stage-114:收敛到统一 helper;**位置不变**(ID 校验仍在门前)
|
|
449
|
-
if (!enforcePreflightOrFail(process.cwd(), lang
|
|
618
|
+
if (!enforcePreflightOrFail(process.cwd(), lang, asJson
|
|
619
|
+
? { reject: (m) => failReqJson('INVALID_ARGUMENT', m, { reason: 'preflight-required' }) }
|
|
620
|
+
: undefined))
|
|
450
621
|
return;
|
|
451
622
|
// --owner 缺省链:.info.json user → git config user.name → 哨兵 'unknown' 拒绝(禁硬编码)
|
|
452
623
|
let owner = options.owner;
|
|
453
624
|
if (owner === undefined) {
|
|
454
625
|
const resolved = getUserName(process.cwd());
|
|
455
626
|
if (resolved === '' || resolved === 'unknown') {
|
|
456
|
-
|
|
457
|
-
process.exitCode = 1;
|
|
627
|
+
failReqWrite(lang, asJson, 'invalid_field', t('req.claim.ownerUnresolvedTmpl', lang));
|
|
458
628
|
return;
|
|
459
629
|
}
|
|
460
630
|
owner = resolved;
|
|
461
631
|
}
|
|
462
|
-
|
|
463
|
-
const
|
|
632
|
+
const projectPath = process.cwd();
|
|
633
|
+
const beforeStatus = getRequirement(data, id)?.status ?? '';
|
|
634
|
+
// 返回码分流(命令层仅映射,零校验):占用 / 终态均由引擎单点判定。
|
|
635
|
+
// v1.6.0 / REV-013:claim **不再校验正文**(认领 ≠ 开工),因此 `body_empty` 分支
|
|
636
|
+
// 目前不可达——保留 `--force` 选项与分支只为兼容旧脚本(选项键仍在 help 锁内)。
|
|
637
|
+
let r = claimRequirement(data, id, owner, { projectPath });
|
|
638
|
+
let bodyForced = false;
|
|
639
|
+
if (!r.ok && r.code === 'body_empty' && options.force === true) {
|
|
640
|
+
// v1.6.0 / T4(A2c):--force = 留痕放行(body_waiver + 审计),随后用同一谓词重试
|
|
641
|
+
const forced = forceRequirementBodyWaiver(data, id, {
|
|
642
|
+
by: resolveActorName(projectPath), reason: 'claim-force', gate: 'claim',
|
|
643
|
+
});
|
|
644
|
+
if (!forced.ok) {
|
|
645
|
+
failReqWrite(lang, asJson, forced.code, codeMessage(lang, forced.code, {
|
|
646
|
+
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
647
|
+
invalid_status: t('req.claim.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
648
|
+
}), { id });
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
r = claimRequirement(data, id, owner, { projectPath });
|
|
652
|
+
bodyForced = r.ok;
|
|
653
|
+
}
|
|
464
654
|
if (!r.ok) {
|
|
465
|
-
|
|
655
|
+
failReqWrite(lang, asJson, r.code, codeMessage(lang, r.code, {
|
|
466
656
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
467
657
|
already_claimed: t('req.err.alreadyClaimedTmpl', lang, { id }),
|
|
468
658
|
invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
|
|
469
659
|
invalid_status: t('req.claim.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
470
|
-
|
|
660
|
+
body_empty: bodyGateMessage(lang, data, id),
|
|
661
|
+
}), { id });
|
|
471
662
|
return;
|
|
472
663
|
}
|
|
664
|
+
// 状态不因认领而变(claim 只写 owner/claimed_at):`from` / `to` 同为当前状态
|
|
665
|
+
const statusNow = getRequirement(data, id)?.status ?? beforeStatus;
|
|
666
|
+
const gates = bodyForced ? ['req_body'] : undefined;
|
|
473
667
|
if (!r.changed) {
|
|
474
668
|
// 同 owner 幂等:不 save(revision 不变)
|
|
669
|
+
if (asJson) {
|
|
670
|
+
emitReqWriteJson({ id, from: beforeStatus, to: statusNow, status: statusNow, gates });
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
475
673
|
console.log(t('req.claim.idempotentTmpl', lang, { id, owner }));
|
|
476
674
|
return;
|
|
477
675
|
}
|
|
478
676
|
if (!saveOrFail(mgr, lang)) {
|
|
479
677
|
return;
|
|
480
678
|
}
|
|
481
|
-
|
|
679
|
+
if (asJson) {
|
|
680
|
+
emitReqWriteJson({ id, from: beforeStatus, to: statusNow, status: statusNow, gates });
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
console.log(t('req.claim.doneTmpl', lang, { id, owner })
|
|
684
|
+
+ (bodyForced ? t('req.claim.bodyForcedSuffix', lang) : ''));
|
|
482
685
|
});
|
|
483
686
|
// ── req release <id> ──
|
|
484
687
|
req
|
|
@@ -555,23 +758,35 @@ export function registerReqCommand(program) {
|
|
|
555
758
|
target_version: options.targetVersion,
|
|
556
759
|
priority: options.priority,
|
|
557
760
|
workflow_mode: options.workflowMode,
|
|
558
|
-
});
|
|
761
|
+
}, { projectPath: process.cwd() });
|
|
559
762
|
if (!r.ok) {
|
|
560
763
|
const current = getRequirement(data, id)?.status ?? '';
|
|
561
764
|
// done 门专用文案(stage-93 BUG-002):静态表放行 done 而仍被拒 ⇒ 唯一可能是完成门
|
|
562
765
|
const doneGate = options.status === 'done'
|
|
563
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';
|
|
564
769
|
failCode(lang, r.code, {
|
|
565
770
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
566
771
|
invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
772
|
+
// v1.6.0 / REQ-056 T6:`set --status done` 与 advance 同判据(done 门通过后才可能到这)
|
|
773
|
+
plan_deviation: t('req.err.planDeviationTmpl', lang, { id }),
|
|
774
|
+
// v1.6.0 / stage-132 T4 · T7:正文门 / 需求级计划门(`set` 无 --force,文案指向 advance --force)
|
|
775
|
+
body_empty: bodyGateMessage(lang, data, id),
|
|
776
|
+
plan_missing: planGateMessage(lang, id),
|
|
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
|
+
})),
|
|
575
790
|
general_mode_conflict: t('req.err.generalModeConflictTmpl', lang, { id }),
|
|
576
791
|
});
|
|
577
792
|
return;
|
|
@@ -676,57 +891,169 @@ export function registerReqCommand(program) {
|
|
|
676
891
|
console.log(t('req.link.doneTmpl', lang, { stage: stageKey, id: requirementId ?? '' }));
|
|
677
892
|
}
|
|
678
893
|
});
|
|
679
|
-
// ── req advance <id> --to <status> ──
|
|
894
|
+
// ── req advance <id> --to <status> [--force] [--json] ──
|
|
680
895
|
req
|
|
681
896
|
.command('advance <id>')
|
|
682
|
-
.description('显式推进需求状态(合法目标由引擎流转表判定;done
|
|
897
|
+
.description('显式推进需求状态(合法目标由引擎流转表判定;done 须先经 review_pending,零关联可直接完成,关联阶段进入 exec_running 及之后相位即可完成)')
|
|
683
898
|
.requiredOption('--to <status>', '目标状态(合法目标由引擎判定)')
|
|
684
|
-
.
|
|
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) => {
|
|
685
902
|
const lang = getCliLang(process.cwd());
|
|
903
|
+
const asJson = asJsonOf(options, command);
|
|
686
904
|
const mgr = createManager();
|
|
687
905
|
if (!mgr.isLoaded()) {
|
|
688
|
-
|
|
906
|
+
failReqWrite(lang, asJson, 'NO_INIT', t('common.errorNoInit', lang), { reason: 'no-init' });
|
|
689
907
|
return;
|
|
690
908
|
}
|
|
691
909
|
const data = mgr.getData();
|
|
692
910
|
if (!isValidReqId(id)) {
|
|
693
|
-
|
|
694
|
-
process.exitCode = 1;
|
|
911
|
+
failReqWrite(lang, asJson, 'INVALID_ARGUMENT', t('req.invalidIdTmpl', lang, { input: id }), { field: 'id', value: id });
|
|
695
912
|
return;
|
|
696
913
|
}
|
|
697
914
|
// 读当前状态仅供成功文案与失败 targets 渲染(纯读,非校验)
|
|
698
915
|
const before = getRequirement(data, id)?.status;
|
|
699
916
|
// v1.5.6-stage-114:写前 preflight(ID 校验已在门前)
|
|
700
|
-
if (!enforcePreflightOrFail(process.cwd(), lang
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
917
|
+
if (!enforcePreflightOrFail(process.cwd(), lang, asJson
|
|
918
|
+
? { reject: (m) => failReqJson('INVALID_ARGUMENT', m, { reason: 'preflight-required' }) }
|
|
919
|
+
: undefined))
|
|
920
|
+
return;
|
|
921
|
+
const projectPath = process.cwd();
|
|
922
|
+
// v1.6.0 / REQ-056 T6:未盖章历史需求(plan? 缺省)在 done 时**放行但提示**——
|
|
923
|
+
// 不阻塞存量,审计另记 `plan_unstamped:true`(在 requirement_status 条目里)。
|
|
924
|
+
const planUnstamped = options.to === 'done' && getRequirement(data, id)?.plan === undefined;
|
|
925
|
+
// 命令层零校验:合法目标 + 正文门 + 计划门 + done 门 + 计划偏差门均在引擎单点
|
|
926
|
+
let r = advanceRequirement(data, id, options.to, { projectPath });
|
|
927
|
+
let planDeviationForced = false;
|
|
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
|
+
});
|
|
953
|
+
// v1.6.0 / stage-132 T4 · T7:正文门 / 计划门的 --force 通道——
|
|
954
|
+
// 写入 waiver(留痕)+ 审计后,用**同一谓词**重新求值(门本体不重写)。
|
|
955
|
+
// 同一次流转可能**连撞两门**(空壳正文 + 无计划):循环上限 = 门数(2),逐个留痕放行。
|
|
956
|
+
for (let i = 0; i < 2 && !r.ok && options.force === true
|
|
957
|
+
&& (r.code === 'body_empty' || r.code === 'plan_missing'); i += 1) {
|
|
958
|
+
const forced = r.code === 'body_empty'
|
|
959
|
+
? forceRequirementBodyWaiver(data, id, { by: resolveActorName(projectPath), reason: 'advance-force', gate: 'advance' })
|
|
960
|
+
: forceRequirementPlanWaiver(data, id, { by: resolveActorName(projectPath), reason: 'advance-force', gate: 'advance' });
|
|
961
|
+
if (!forced.ok) {
|
|
962
|
+
failReqWrite(lang, asJson, forced.code, codeMessage(lang, forced.code, {
|
|
963
|
+
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
964
|
+
invalid_status: t('req.err.invalidStatusTmpl', lang, {
|
|
965
|
+
id, to: options.to, current: before ?? '',
|
|
966
|
+
targets: before !== undefined ? getAllowedNextStatuses(before).join(', ') : '',
|
|
967
|
+
}),
|
|
968
|
+
}), { id, to: options.to });
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
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
|
+
}
|
|
979
|
+
}
|
|
980
|
+
if (!r.ok && r.code === 'plan_deviation' && options.force === true) {
|
|
981
|
+
// 留痕放行:先记偏差次数 + 审计(判据本体不重写),再走同一门放行通道
|
|
982
|
+
const forced = forceRequirementPlanDeviation(data, id, { by: resolveActorName(projectPath) });
|
|
983
|
+
if (!forced.ok) {
|
|
984
|
+
failReqWrite(lang, asJson, forced.code, codeMessage(lang, forced.code, {
|
|
985
|
+
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
986
|
+
invalid_status: t('req.advance.forceRequiresStampTmpl', lang, { id }),
|
|
987
|
+
}), { id, to: options.to });
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
r = advanceRequirement(data, id, options.to, retryOpts({ allowPlanDeviation: true }));
|
|
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
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
const statusNow = getRequirement(data, id)?.status ?? (before ?? '');
|
|
704
1004
|
if (!r.ok) {
|
|
705
1005
|
// done 门专用文案(stage-93 BUG-002):静态表放行 done 而仍被拒 ⇒ 唯一可能是完成门
|
|
706
1006
|
const doneGate = options.to === 'done'
|
|
707
1007
|
&& before !== undefined
|
|
708
1008
|
&& getAllowedNextStatuses(before).includes('done');
|
|
709
|
-
|
|
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, {
|
|
710
1012
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
1013
|
+
// v1.6.0 / REQ-056 T6:计划被执行改动且 `## 偏差与回写` 未写实(done 门已通过后才可能到这)
|
|
1014
|
+
plan_deviation: t('req.err.planDeviationTmpl', lang, { id }),
|
|
1015
|
+
// v1.6.0 / stage-132 T4 · T7:正文门 / 需求级计划门(补写指引 + 可复制的命令)
|
|
1016
|
+
body_empty: bodyGateMessage(lang, data, id),
|
|
1017
|
+
plan_missing: planGateMessage(lang, id),
|
|
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 });
|
|
720
1032
|
return;
|
|
721
1033
|
}
|
|
722
1034
|
if (!r.changed) {
|
|
1035
|
+
if (asJson) {
|
|
1036
|
+
emitReqWriteJson({ id, from: before ?? statusNow, to: options.to, status: statusNow, gates });
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
723
1039
|
console.log(t('req.advance.noopTmpl', lang, { id, to: options.to }));
|
|
724
1040
|
return;
|
|
725
1041
|
}
|
|
726
1042
|
if (!saveOrFail(mgr, lang)) {
|
|
727
1043
|
return;
|
|
728
1044
|
}
|
|
729
|
-
|
|
1045
|
+
if (planUnstamped) {
|
|
1046
|
+
console.warn(t('req.warn.planUnstampedTmpl', lang, { id }));
|
|
1047
|
+
}
|
|
1048
|
+
if (asJson) {
|
|
1049
|
+
emitReqWriteJson({ id, from: before ?? '', to: options.to, status: statusNow, gates });
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
console.log(t('req.advance.doneTmpl', lang, { id, from: before ?? '', to: options.to })
|
|
1053
|
+
+ (planDeviationForced ? t('req.advance.planDeviationForcedSuffix', lang) : '')
|
|
1054
|
+
+ (gateForced ? t('req.advance.gateForcedSuffix', lang) : ''));
|
|
1055
|
+
// v1.6.0 / REQ-059 T8:流转成功即自动同步开发账本
|
|
1056
|
+
syncDevAfterWrite(projectPath, lang);
|
|
730
1057
|
});
|
|
731
1058
|
// ── req waive <id> --reason <text> [--by] [--revoke] ──(v1.5.23 / REQ-043 / 六期 #8)
|
|
732
1059
|
req
|
|
@@ -814,13 +1141,14 @@ export function registerReqCommand(program) {
|
|
|
814
1141
|
? t('req.trivial.revokedTmpl', lang, { id })
|
|
815
1142
|
: t('req.trivial.doneTmpl', lang, { id, reason: options.reason ?? '' }));
|
|
816
1143
|
});
|
|
817
|
-
// ── req complete <id> --result pass --note <t> [--kind] [--evidence] [--by] [--independent|--self] ──
|
|
1144
|
+
// ── req complete <id> --result pass --note <t> [--kind] [--evidence] [--by] [--independent|--self] [--force] [--json] ──
|
|
818
1145
|
// v1.5.23 / REQ-043(六期反馈 #1):一次收口 = review + verify + advance(done)。
|
|
819
1146
|
// 复用既有判据单点(recordRequirementReview / recordRequirementVerification / advanceRequirement
|
|
820
1147
|
// → canCompleteRequirement);任一步失败即返回,**不 save ⇒ flow.json 零变更**。
|
|
1148
|
+
// v1.6.1 / REQ-063 A63.1:收口链改为 in_progress → review_pending → done(审查相位不再被跳过)。
|
|
821
1149
|
req
|
|
822
1150
|
.command('complete <id>')
|
|
823
|
-
.description('一次收口:记录审查+验证并推进 done
|
|
1151
|
+
.description('一次收口:记录审查+验证并推进 done(经 review_pending 相位;复用既有 done 门;任一失败零写盘)')
|
|
824
1152
|
.requiredOption('--result <result>', '审验结论(pass / fail;pass 才能收口)')
|
|
825
1153
|
.option('--kind <kind>', '验证种类(test / manual / build;缺省 manual)')
|
|
826
1154
|
.requiredOption('--note <text>', '结论摘要(进入归档摘要)')
|
|
@@ -828,60 +1156,97 @@ export function registerReqCommand(program) {
|
|
|
828
1156
|
.option('--evidence <path>', '证据(测试命令 / 报告路径 / 摘要)')
|
|
829
1157
|
.option('--independent', '独立审查(推荐)')
|
|
830
1158
|
.option('--self', '自我审查(非独立;归档摘要标注 self-review)')
|
|
831
|
-
.
|
|
1159
|
+
.option('--force', '门留痕放行(正文/计划门写 waiver + 审计;文件仍须补写)')
|
|
1160
|
+
.option('--json', '以 JSON 输出 { schemaVersion, id, from, to, status, gates? }(v1.6.1 / REQ-063)')
|
|
1161
|
+
.action((id, options, command) => {
|
|
832
1162
|
const lang = getCliLang(process.cwd());
|
|
1163
|
+
const asJson = asJsonOf(options, command);
|
|
833
1164
|
const mgr = createManager();
|
|
834
1165
|
if (!mgr.isLoaded()) {
|
|
835
|
-
|
|
1166
|
+
failReqWrite(lang, asJson, 'NO_INIT', t('common.errorNoInit', lang), { reason: 'no-init' });
|
|
836
1167
|
return;
|
|
837
1168
|
}
|
|
838
1169
|
const data = mgr.getData();
|
|
839
1170
|
if (!isValidReqId(id)) {
|
|
840
|
-
|
|
841
|
-
process.exitCode = 1;
|
|
1171
|
+
failReqWrite(lang, asJson, 'INVALID_ARGUMENT', t('req.invalidIdTmpl', lang, { input: id }), { field: 'id', value: id });
|
|
842
1172
|
return;
|
|
843
1173
|
}
|
|
844
1174
|
if (options.independent === true && options.self === true) {
|
|
845
|
-
|
|
846
|
-
process.exitCode = 1;
|
|
1175
|
+
failReqWrite(lang, asJson, 'INVALID_ARGUMENT', t('req.review.exclusiveFlagTmpl', lang));
|
|
847
1176
|
return;
|
|
848
1177
|
}
|
|
849
|
-
if (!enforcePreflightOrFail(process.cwd(), lang
|
|
1178
|
+
if (!enforcePreflightOrFail(process.cwd(), lang, asJson
|
|
1179
|
+
? { reject: (m) => failReqJson('INVALID_ARGUMENT', m, { reason: 'preflight-required' }) }
|
|
1180
|
+
: undefined))
|
|
850
1181
|
return;
|
|
851
1182
|
const by = resolveActorName(process.cwd(), options.by);
|
|
852
1183
|
const independent = options.independent === true;
|
|
853
1184
|
// v1.5.24 / REQ-051:收口请求可直接从 draft / scheduled 起——自动补状态链
|
|
854
1185
|
// (这正是一条命令收口的完整语义;blocked / 终态仍需人工先处理)。
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
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 });
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
const projectPath = process.cwd();
|
|
1194
|
+
/** 实际被 `--force` 放行的门(JSON 成功文档的 `gates`) */
|
|
1195
|
+
const gates = [];
|
|
1196
|
+
/** 门的 --force 通道(T4 正文 / T7 计划):写 waiver + 审计后由调用方用同一谓词重试 */
|
|
1197
|
+
const forceGate = (code) => {
|
|
1198
|
+
const forced = code === 'body_empty'
|
|
1199
|
+
? forceRequirementBodyWaiver(data, id, { by, reason: 'complete-force', gate: 'complete' })
|
|
1200
|
+
: forceRequirementPlanWaiver(data, id, { by, reason: 'complete-force', gate: 'complete' });
|
|
1201
|
+
if (!forced.ok) {
|
|
1202
|
+
failReqWrite(lang, asJson, forced.code, codeMessage(lang, forced.code, {
|
|
1203
|
+
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
1204
|
+
invalid_status: t('req.complete.statusTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
1205
|
+
}), { id });
|
|
1206
|
+
return false;
|
|
1207
|
+
}
|
|
1208
|
+
const forcedGate = code === 'body_empty' ? 'req_body' : 'req_plan';
|
|
1209
|
+
if (!gates.includes(forcedGate)) {
|
|
1210
|
+
gates.push(forcedGate);
|
|
1211
|
+
}
|
|
1212
|
+
return true;
|
|
1213
|
+
};
|
|
1214
|
+
let gateForced = false;
|
|
861
1215
|
for (const step of ['scheduled', 'in_progress']) {
|
|
862
1216
|
if (stateNow !== 'draft' && stateNow !== 'scheduled')
|
|
863
1217
|
break;
|
|
864
|
-
|
|
1218
|
+
let moved = advanceRequirement(data, id, step, { projectPath });
|
|
1219
|
+
// 同一流转可能连撞两门(正文 + 计划):循环上限 = 门数(2),逐个留痕放行
|
|
1220
|
+
for (let i = 0; i < 2 && !moved.ok && options.force === true
|
|
1221
|
+
&& (moved.code === 'body_empty' || moved.code === 'plan_missing'); i += 1) {
|
|
1222
|
+
if (!forceGate(moved.code))
|
|
1223
|
+
return;
|
|
1224
|
+
moved = advanceRequirement(data, id, step, { projectPath });
|
|
1225
|
+
gateForced = moved.ok;
|
|
1226
|
+
}
|
|
865
1227
|
if (!moved.ok) {
|
|
866
|
-
|
|
1228
|
+
failReqWrite(lang, asJson, moved.code, codeMessage(lang, moved.code, {
|
|
867
1229
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
868
1230
|
invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
|
|
1231
|
+
// v1.6.0 / stage-132 T4 · T7:自动补链同样过正文门 / 计划门(不因「一条命令」而绕过)
|
|
1232
|
+
body_empty: bodyGateMessage(lang, data, id),
|
|
1233
|
+
plan_missing: planGateMessage(lang, id),
|
|
869
1234
|
invalid_status: t('req.err.invalidStatusTmpl', lang, {
|
|
870
1235
|
id, to: step, current: stateNow, targets: getAllowedNextStatuses(stateNow).join(', '),
|
|
871
1236
|
}),
|
|
872
1237
|
general_mode_conflict: t('req.err.generalModeConflictTmpl', lang, { id }),
|
|
873
|
-
});
|
|
1238
|
+
}), { id, to: step, current: stateNow });
|
|
874
1239
|
return;
|
|
875
1240
|
}
|
|
876
1241
|
stateNow = step;
|
|
877
1242
|
}
|
|
878
1243
|
const review = recordRequirementReview(data, id, { result: options.result, by, note: options.note, independent, session: currentSession() });
|
|
879
1244
|
if (!review.ok) {
|
|
880
|
-
|
|
1245
|
+
failReqWrite(lang, asJson, review.code, codeMessage(lang, review.code, {
|
|
881
1246
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
882
1247
|
invalid_status: t('req.review.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
883
1248
|
invalid_field: t('req.review.invalidTmpl', lang),
|
|
884
|
-
});
|
|
1249
|
+
}), { id });
|
|
885
1250
|
return;
|
|
886
1251
|
}
|
|
887
1252
|
const verification = recordRequirementVerification(data, id, {
|
|
@@ -893,32 +1258,69 @@ export function registerReqCommand(program) {
|
|
|
893
1258
|
session: currentSession(),
|
|
894
1259
|
});
|
|
895
1260
|
if (!verification.ok) {
|
|
896
|
-
|
|
1261
|
+
failReqWrite(lang, asJson, verification.code, codeMessage(lang, verification.code, {
|
|
897
1262
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
898
1263
|
invalid_status: t('req.verify.terminalTmpl', lang, { id, status: getRequirement(data, id)?.status ?? '' }),
|
|
899
1264
|
invalid_field: t('req.verify.invalidTmpl', lang),
|
|
900
|
-
});
|
|
1265
|
+
}), { id });
|
|
901
1266
|
return;
|
|
902
1267
|
}
|
|
903
|
-
|
|
904
|
-
|
|
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;
|
|
1285
|
+
let advanced = advanceRequirement(data, id, 'done', { projectPath });
|
|
1286
|
+
for (let i = 0; i < 2 && !advanced.ok && options.force === true
|
|
1287
|
+
&& (advanced.code === 'body_empty' || advanced.code === 'plan_missing'); i += 1) {
|
|
1288
|
+
if (!forceGate(advanced.code))
|
|
1289
|
+
return;
|
|
1290
|
+
advanced = advanceRequirement(data, id, 'done', { projectPath });
|
|
1291
|
+
gateForced = advanced.ok;
|
|
1292
|
+
}
|
|
905
1293
|
if (!advanced.ok) {
|
|
906
1294
|
// 走到这里 = 审验记录已写但状态没推进:不 save(零写盘),按 done 门文案说明缺什么
|
|
907
|
-
|
|
1295
|
+
failReqWrite(lang, asJson, advanced.code, codeMessage(lang, advanced.code, {
|
|
908
1296
|
not_found: t('req.err.notFoundTmpl', lang, { id }),
|
|
909
1297
|
invalid_field: t('req.err.invalidFieldTmpl', lang, { id }),
|
|
1298
|
+
// v1.6.0 / REQ-056 T6:计划偏差门(done 门通过后)
|
|
1299
|
+
plan_deviation: t('req.err.planDeviationTmpl', lang, { id }),
|
|
1300
|
+
// v1.6.0 / stage-132 T4 · T7:正文门 / 计划门(先于 done 门)
|
|
1301
|
+
body_empty: bodyGateMessage(lang, data, id),
|
|
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 }),
|
|
910
1306
|
invalid_status: doneGateMessage(lang, data, id, current),
|
|
911
1307
|
general_mode_conflict: t('req.err.generalModeConflictTmpl', lang, { id }),
|
|
912
|
-
});
|
|
1308
|
+
}), { id, to: 'done', current });
|
|
913
1309
|
return;
|
|
914
1310
|
}
|
|
915
1311
|
if (!saveOrFail(mgr, lang)) {
|
|
916
1312
|
return;
|
|
917
1313
|
}
|
|
1314
|
+
if (asJson) {
|
|
1315
|
+
emitReqWriteJson({ id, from: fromStatus, to: 'done', status: 'done', gates });
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
918
1318
|
const suffix = independent ? '' : t('req.review.selfSuffix', lang);
|
|
919
1319
|
console.log(t('req.complete.doneTmpl', lang, {
|
|
920
1320
|
id, result: options.result, kind: options.kind ?? 'manual',
|
|
921
|
-
}) + suffix);
|
|
1321
|
+
}) + suffix + (gateForced ? t('req.complete.gateForcedSuffix', lang) : ''));
|
|
1322
|
+
// v1.6.0 / REQ-059 T8:收口成功即自动同步开发账本
|
|
1323
|
+
syncDevAfterWrite(projectPath, lang);
|
|
922
1324
|
});
|
|
923
1325
|
// ── req review <id> --result pass|fail --by <who> --note <text> [--independent|--self] ──
|
|
924
1326
|
req
|
|
@@ -974,6 +1376,8 @@ export function registerReqCommand(program) {
|
|
|
974
1376
|
}
|
|
975
1377
|
const suffix = options.independent === true ? '' : t('req.review.selfSuffix', lang);
|
|
976
1378
|
console.log(t('req.review.doneTmpl', lang, { id, result: options.result, by }) + suffix);
|
|
1379
|
+
// v1.6.0 / REQ-059 T8:审查记录写入成功即自动同步开发账本
|
|
1380
|
+
syncDevAfterWrite(process.cwd(), lang);
|
|
977
1381
|
});
|
|
978
1382
|
// ── req verify <id> --result pass|fail --kind test|manual|build --by <who> --note <text> [--evidence <path>] ──
|
|
979
1383
|
req
|
|
@@ -1023,6 +1427,8 @@ export function registerReqCommand(program) {
|
|
|
1023
1427
|
return;
|
|
1024
1428
|
}
|
|
1025
1429
|
console.log(t('req.verify.doneTmpl', lang, { id, kind: options.kind, result: options.result, by }));
|
|
1430
|
+
// v1.6.0 / REQ-059 T8:验证记录写入成功即自动同步开发账本
|
|
1431
|
+
syncDevAfterWrite(process.cwd(), lang);
|
|
1026
1432
|
});
|
|
1027
1433
|
// ── req split <id> --into <title> [--into <title>...] [--json] ──
|
|
1028
1434
|
req
|
|
@@ -1117,7 +1523,7 @@ export function registerReqCommand(program) {
|
|
|
1117
1523
|
// ── req board [--target-version <v>] [--json] ──
|
|
1118
1524
|
req
|
|
1119
1525
|
.command('board')
|
|
1120
|
-
.description('需求看板(按状态分组;
|
|
1526
|
+
.description('需求看板(按状态分组;8 组固定顺序 = REQ_STATUSES 声明序)')
|
|
1121
1527
|
.option('--target-version <version>', '按预估版本过滤')
|
|
1122
1528
|
.option('--json', '以 JSON 输出 { schemaVersion, groups }')
|
|
1123
1529
|
.action((options, command) => {
|
|
@@ -1131,7 +1537,8 @@ export function registerReqCommand(program) {
|
|
|
1131
1537
|
const data = mgr.getData();
|
|
1132
1538
|
// 只读保证:不 save / 不 appendLog / 零写盘
|
|
1133
1539
|
const rows = listRequirements(data, { target_version: options.targetVersion });
|
|
1134
|
-
//
|
|
1540
|
+
// 8 组固定顺序 = 状态值域声明序(v1.6.1 / REQ-063:新增 review_pending,旧 7 组一个不删)
|
|
1541
|
+
// 恒含空组(域外脏状态不渲染)
|
|
1135
1542
|
const groups = {};
|
|
1136
1543
|
for (const s of REQ_STATUSES) {
|
|
1137
1544
|
groups[s] = rows.filter((r) => r.status === s);
|
|
@@ -1367,5 +1774,324 @@ export function registerReqCommand(program) {
|
|
|
1367
1774
|
console.log(t('req.rollover.itemTmpl', lang, { id: moved.id, status: moved.status, title: moved.title }));
|
|
1368
1775
|
}
|
|
1369
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
|
+
});
|
|
1884
|
+
// ── req body <id> --section <name> (--text <md> | --file <path>) [--append|--replace] [--json] ──
|
|
1885
|
+
// v1.6.0-stage-132 / T2:需求正文**唯一写入口**(元信息小节受保护;每次写入追加 `## 变更记录`)
|
|
1886
|
+
// v1.6.1 / REQ-064 A64.2:新增 `--from <md>` —— 按 `##` 一次导入多节,元信息小节跳过并报告
|
|
1887
|
+
req
|
|
1888
|
+
.command('body <id>')
|
|
1889
|
+
.description('写入需求正文的业务小节(元信息小节受保护;每次写入追加变更记录)')
|
|
1890
|
+
.option('--section <name>', '小节名(如 摘要 / 目标与验收 / 问题 / 初步规划;与 --from 二选一)')
|
|
1891
|
+
.option('--from <path>', '从 Markdown 文件按 `##` 分节一次导入多个业务小节(与 --section/--text/--file 互斥)')
|
|
1892
|
+
.option('--text <md>', '小节正文(Markdown;与 --file 二选一)')
|
|
1893
|
+
.option('--file <path>', '从文件读取小节正文(与 --text 二选一;相对路径按项目根解析)')
|
|
1894
|
+
.option('--append', '追加到该小节末尾(缺省替换整节)')
|
|
1895
|
+
.option('--replace', '替换整节(缺省;与 --append 互斥)')
|
|
1896
|
+
.option('--json', '以 JSON 输出 { schemaVersion, id, section, path, lines, created }(--from 时为 { schemaVersion, id, sections })')
|
|
1897
|
+
.action((id, options, command) => {
|
|
1898
|
+
const lang = getCliLang(process.cwd());
|
|
1899
|
+
const asJson = asJsonOf(options, command);
|
|
1900
|
+
const mgr = createManager();
|
|
1901
|
+
if (!mgr.isLoaded()) {
|
|
1902
|
+
failNoInit(lang, asJson);
|
|
1903
|
+
return;
|
|
1904
|
+
}
|
|
1905
|
+
if (!isValidReqId(id)) {
|
|
1906
|
+
if (asJson) {
|
|
1907
|
+
failJson({ error: 'invalid-argument', field: 'id', value: id });
|
|
1908
|
+
}
|
|
1909
|
+
else {
|
|
1910
|
+
console.error(t('req.invalidIdTmpl', lang, { input: id }));
|
|
1911
|
+
process.exitCode = 1;
|
|
1912
|
+
}
|
|
1913
|
+
return;
|
|
1914
|
+
}
|
|
1915
|
+
const data = mgr.getData();
|
|
1916
|
+
const req_ = getRequirement(data, id);
|
|
1917
|
+
if (!req_) {
|
|
1918
|
+
if (asJson) {
|
|
1919
|
+
failJson({ error: 'not_found', id });
|
|
1920
|
+
}
|
|
1921
|
+
else {
|
|
1922
|
+
console.error(t('req.err.notFoundTmpl', lang, { id }));
|
|
1923
|
+
process.exitCode = 1;
|
|
1924
|
+
}
|
|
1925
|
+
return;
|
|
1926
|
+
}
|
|
1927
|
+
// argument-shape 守卫(非业务校验):
|
|
1928
|
+
// --from 独占(不与 --section/--text/--file 同用);否则 --section 必填 + --text/--file 恰一;--append/--replace 互斥
|
|
1929
|
+
const hasFrom = options.from !== undefined;
|
|
1930
|
+
const hasText = options.text !== undefined;
|
|
1931
|
+
const hasFile = options.file !== undefined;
|
|
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;
|
|
1943
|
+
}
|
|
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;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
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;
|
|
1966
|
+
}
|
|
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;
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
if (options.append === true && options.replace === true) {
|
|
1989
|
+
if (asJson) {
|
|
1990
|
+
failJson({ error: 'invalid_field', id, section: sectionName, field: 'append' });
|
|
1991
|
+
}
|
|
1992
|
+
else {
|
|
1993
|
+
console.error(t('req.body.flagExclusiveTmpl', lang));
|
|
1994
|
+
process.exitCode = 1;
|
|
1995
|
+
}
|
|
1996
|
+
return;
|
|
1997
|
+
}
|
|
1998
|
+
// v1.5.6-stage-114:写前 preflight(参数 / ID 校验已在门前)
|
|
1999
|
+
if (!enforcePreflightOrFail(process.cwd(), lang))
|
|
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
|
+
}
|
|
2047
|
+
try {
|
|
2048
|
+
const result = updateRequirementBody(process.cwd(), req_, {
|
|
2049
|
+
section: sectionName,
|
|
2050
|
+
...(options.text !== undefined ? { text: options.text } : {}),
|
|
2051
|
+
...(options.file !== undefined ? { file: options.file } : {}),
|
|
2052
|
+
append: options.append === true,
|
|
2053
|
+
replace: options.replace === true,
|
|
2054
|
+
createSectionIfMissing: true,
|
|
2055
|
+
by: resolveActorName(process.cwd(), undefined),
|
|
2056
|
+
});
|
|
2057
|
+
// v1.6.0 / REQ-059 T8:正文写入成功即自动同步开发账本(--json 的告警走 stderr,不污染 stdout)
|
|
2058
|
+
syncDevAfterWrite(process.cwd(), lang);
|
|
2059
|
+
if (asJson) {
|
|
2060
|
+
emitJson(withSchemaVersion({
|
|
2061
|
+
id: req_.id,
|
|
2062
|
+
section: result.section,
|
|
2063
|
+
path: result.path,
|
|
2064
|
+
lines: result.lines,
|
|
2065
|
+
created: result.created,
|
|
2066
|
+
}));
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
const actionKey = result.created
|
|
2070
|
+
? 'req.body.actionCreated'
|
|
2071
|
+
: (options.append === true ? 'req.body.actionAppended' : 'req.body.actionReplaced');
|
|
2072
|
+
console.log(t('req.body.doneTmpl', lang, {
|
|
2073
|
+
id: req_.id,
|
|
2074
|
+
section: result.section,
|
|
2075
|
+
lines: String(result.lines),
|
|
2076
|
+
path: result.path,
|
|
2077
|
+
action: t(actionKey, lang),
|
|
2078
|
+
}));
|
|
2079
|
+
}
|
|
2080
|
+
catch (err) {
|
|
2081
|
+
if (err instanceof RequirementBodyUpdateError) {
|
|
2082
|
+
if (asJson) {
|
|
2083
|
+
failJson({ error: err.code, id, section: sectionName });
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
const key = err.code === 'protected_section'
|
|
2087
|
+
? 'req.body.protectedTmpl'
|
|
2088
|
+
: (err.code === 'empty_text' ? 'req.body.emptyTmpl' : 'req.body.invalidFieldTmpl');
|
|
2089
|
+
console.error(t(key, lang, { id, section: sectionName }));
|
|
2090
|
+
process.exitCode = 1;
|
|
2091
|
+
return;
|
|
2092
|
+
}
|
|
2093
|
+
failGeneric(lang, err);
|
|
2094
|
+
}
|
|
2095
|
+
});
|
|
1370
2096
|
}
|
|
1371
2097
|
//# sourceMappingURL=req.js.map
|