ylcwf 0.4.0 → 0.5.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/CHANGELOG.md +70 -0
- package/README.md +97 -15
- package/dist/index.js +2388 -837
- package/package.json +1 -1
- package/ui-dist/assets/{index-CQv426tT.js → index-B_FY7yA5.js} +2 -2
- package/ui-dist/assets/index-CFsU6qYJ.css +2 -0
- package/ui-dist/index.html +2 -2
- package/ui-dist/assets/index-D33Av3k5.css +0 -2
package/dist/index.js
CHANGED
|
@@ -9283,6 +9283,9 @@ function isStringArray(value) {
|
|
|
9283
9283
|
function parsePathList(input) {
|
|
9284
9284
|
return input.split(/[,,;;]/).map((item)=>item.trim()).filter((item)=>item.length > 0);
|
|
9285
9285
|
}
|
|
9286
|
+
function escapeRegExp(input) {
|
|
9287
|
+
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
9288
|
+
}
|
|
9286
9289
|
const ROLES = [
|
|
9287
9290
|
'frontend',
|
|
9288
9291
|
'backend',
|
|
@@ -9646,6 +9649,7 @@ function checkConfig(raw, options = {}) {
|
|
|
9646
9649
|
docs,
|
|
9647
9650
|
terminals
|
|
9648
9651
|
};
|
|
9652
|
+
if (0 === Object.keys(terminals).length) issues.push(warning('TERMINALS_EMPTY', "尚未配置任何终端映射:ylcwf resolve、任务「所属端」与仓库归属校验、doc migrate 回填都将不可用。\n 补配置:ylcwf terminal add <终端名> --frontend <仓库路径>\n (后端仓库用 --backend,两端都有就同时传;每端多个仓库可重复该选项)", 'terminals'));
|
|
9649
9653
|
issues.push(...checkTerminalIdentity(terminals));
|
|
9650
9654
|
if (true === options.checkFs) {
|
|
9651
9655
|
checkFsOfDocs(config, issues);
|
|
@@ -10012,6 +10016,12 @@ async function runInit(options) {
|
|
|
10012
10016
|
}
|
|
10013
10017
|
assertWritable(doc, configPath);
|
|
10014
10018
|
saveDocument(doc, configPath);
|
|
10019
|
+
const terminalCount = Object.keys(doc.toJS().terminals ?? {}).length;
|
|
10020
|
+
if (0 === terminalCount) {
|
|
10021
|
+
log.warn('未配置终端映射:ylcwf resolve、任务「所属端」与仓库归属校验、doc migrate 回填都会不可用。');
|
|
10022
|
+
log.info('稍后补配置:ylcwf terminal add <PRD 中的终端名> --frontend <仓库路径>');
|
|
10023
|
+
log.info('(后端仓库用 --backend;每端多个仓库可重复传该选项)');
|
|
10024
|
+
}
|
|
10015
10025
|
outro(`已写入 ${configPath}\n下一步:ylcwf doctor 校验,ylcwf show 查看;后续追加仓库用 ylcwf terminal repo add`);
|
|
10016
10026
|
printLine('');
|
|
10017
10027
|
}
|
|
@@ -10602,566 +10612,857 @@ function registerTerminal(program) {
|
|
|
10602
10612
|
runTerminalRepoRemove(key, options);
|
|
10603
10613
|
});
|
|
10604
10614
|
}
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
const trimmed = value.trim();
|
|
10608
|
-
if (!SAFE_SEGMENT.test(trimmed) || '.' === trimmed || '..' === trimmed) throw new errors_CliError(`${label} 不合法:${value}`, errors_EXIT.USAGE);
|
|
10609
|
-
return trimmed;
|
|
10610
|
-
}
|
|
10611
|
-
function buildCommitMessage(iteration, action, taskIds, _action) {
|
|
10612
|
-
const meta = ACTION_META[action];
|
|
10613
|
-
return `docs(${iteration}): ${meta.label} ${taskIds.join(',')}(${meta.from}→${meta.to})`;
|
|
10614
|
-
}
|
|
10615
|
-
function nowStamp() {
|
|
10616
|
-
const now = new Date();
|
|
10617
|
-
const pad = (value)=>String(value).padStart(2, '0');
|
|
10618
|
-
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`;
|
|
10615
|
+
function normalizeIterationKey(value) {
|
|
10616
|
+
return value.trim().toLowerCase().replace(/[-_.\s]+/g, '-');
|
|
10619
10617
|
}
|
|
10620
|
-
|
|
10621
|
-
start: {
|
|
10622
|
-
label: '开始实施',
|
|
10623
|
-
from: '未开始',
|
|
10624
|
-
to: '进行中'
|
|
10625
|
-
},
|
|
10626
|
-
submit: {
|
|
10627
|
-
label: '提交验收',
|
|
10628
|
-
from: '进行中',
|
|
10629
|
-
to: '待验收'
|
|
10630
|
-
},
|
|
10631
|
-
accept: {
|
|
10632
|
-
label: '验收通过',
|
|
10633
|
-
from: '待验收',
|
|
10634
|
-
to: '已完成'
|
|
10635
|
-
},
|
|
10636
|
-
reject: {
|
|
10637
|
-
label: '验收驳回',
|
|
10638
|
-
from: '待验收',
|
|
10639
|
-
to: '进行中'
|
|
10640
|
-
}
|
|
10641
|
-
};
|
|
10642
|
-
function commitInDocsRepo(docsRoot, file, message, push) {
|
|
10643
|
-
const run = (args)=>{
|
|
10644
|
-
try {
|
|
10645
|
-
const output = execFileSync('git', args, {
|
|
10646
|
-
cwd: docsRoot,
|
|
10647
|
-
encoding: 'utf8',
|
|
10648
|
-
stdio: [
|
|
10649
|
-
'ignore',
|
|
10650
|
-
'pipe',
|
|
10651
|
-
'pipe'
|
|
10652
|
-
]
|
|
10653
|
-
});
|
|
10654
|
-
return {
|
|
10655
|
-
ok: true,
|
|
10656
|
-
output
|
|
10657
|
-
};
|
|
10658
|
-
} catch (error) {
|
|
10659
|
-
const stderr = error.stderr ?? '';
|
|
10660
|
-
return {
|
|
10661
|
-
ok: false,
|
|
10662
|
-
output: stderr.trim() || String(error)
|
|
10663
|
-
};
|
|
10664
|
-
}
|
|
10665
|
-
};
|
|
10666
|
-
const inside = run([
|
|
10667
|
-
'rev-parse',
|
|
10668
|
-
'--is-inside-work-tree'
|
|
10669
|
-
]);
|
|
10670
|
-
if (!inside.ok || 'true' !== inside.output.trim()) return {
|
|
10671
|
-
committed: false,
|
|
10672
|
-
pushed: false,
|
|
10673
|
-
message: '文档仓库不是 git 仓库,已跳过提交'
|
|
10674
|
-
};
|
|
10675
|
-
let realRoot = docsRoot;
|
|
10676
|
-
let realFile = file;
|
|
10618
|
+
function currentBranch(docsRoot) {
|
|
10677
10619
|
try {
|
|
10678
|
-
|
|
10679
|
-
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
|
-
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
|
|
10620
|
+
const output = execFileSync('git', [
|
|
10621
|
+
'rev-parse',
|
|
10622
|
+
'--abbrev-ref',
|
|
10623
|
+
'HEAD'
|
|
10624
|
+
], {
|
|
10625
|
+
cwd: docsRoot,
|
|
10626
|
+
encoding: 'utf8',
|
|
10627
|
+
stdio: [
|
|
10628
|
+
'ignore',
|
|
10629
|
+
'pipe',
|
|
10630
|
+
'pipe'
|
|
10631
|
+
]
|
|
10632
|
+
});
|
|
10633
|
+
const branch = output.trim();
|
|
10634
|
+
if (0 === branch.length || 'HEAD' === branch) return null;
|
|
10635
|
+
return branch;
|
|
10636
|
+
} catch (error) {
|
|
10637
|
+
const message = error instanceof Error ? error.message.split('\n')[0] ?? '' : String(error);
|
|
10638
|
+
if (message.includes('not a git repository')) throw new errors_CliError(`${docsRoot} 不是 git 仓库,无法读取当前分支`, errors_EXIT.NOT_FOUND);
|
|
10639
|
+
return null;
|
|
10640
|
+
}
|
|
10641
|
+
}
|
|
10642
|
+
function resolveIterationFromBranch(docsRoot, iterations) {
|
|
10643
|
+
const branch = currentBranch(docsRoot);
|
|
10644
|
+
if (null === branch) return {
|
|
10645
|
+
branch: null,
|
|
10646
|
+
iteration: null,
|
|
10647
|
+
candidates: []
|
|
10686
10648
|
};
|
|
10687
|
-
const
|
|
10688
|
-
|
|
10689
|
-
|
|
10690
|
-
|
|
10691
|
-
|
|
10692
|
-
if (
|
|
10693
|
-
|
|
10694
|
-
|
|
10695
|
-
|
|
10649
|
+
const key = normalizeIterationKey(branch);
|
|
10650
|
+
const all = iterations.map((name)=>({
|
|
10651
|
+
name,
|
|
10652
|
+
key: normalizeIterationKey(name)
|
|
10653
|
+
})).filter((item)=>item.key.length > 0).filter((item)=>key === item.key || key.endsWith(`-${item.key}`) || key.endsWith(`/${item.key}`)).sort((left, right)=>right.key.length - left.key.length);
|
|
10654
|
+
if (0 === all.length) return {
|
|
10655
|
+
branch,
|
|
10656
|
+
iteration: null,
|
|
10657
|
+
candidates: []
|
|
10696
10658
|
};
|
|
10697
|
-
const
|
|
10698
|
-
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10702
|
-
relativePath
|
|
10703
|
-
]);
|
|
10704
|
-
if (!committed.ok) {
|
|
10705
|
-
const firstLine = committed.output.split('\n')[0] ?? '';
|
|
10706
|
-
return {
|
|
10707
|
-
committed: false,
|
|
10708
|
-
pushed: false,
|
|
10709
|
-
message: `提交未完成:${firstLine}`
|
|
10710
|
-
};
|
|
10711
|
-
}
|
|
10712
|
-
if (!push) return {
|
|
10713
|
-
committed: true,
|
|
10714
|
-
pushed: false,
|
|
10715
|
-
message: '已提交(未推送)'
|
|
10659
|
+
const best = all[0];
|
|
10660
|
+
if (void 0 === best) return {
|
|
10661
|
+
branch,
|
|
10662
|
+
iteration: null,
|
|
10663
|
+
candidates: []
|
|
10716
10664
|
};
|
|
10717
|
-
const
|
|
10718
|
-
|
|
10719
|
-
|
|
10720
|
-
|
|
10721
|
-
|
|
10722
|
-
pushed: false,
|
|
10723
|
-
message: `已提交但推送失败,请手动处理:${pushed.output.split('\n')[0] ?? ''}`
|
|
10665
|
+
const tied = all.filter((item)=>item.key.length === best.key.length).map((item)=>item.name);
|
|
10666
|
+
if (tied.length > 1) return {
|
|
10667
|
+
branch,
|
|
10668
|
+
iteration: null,
|
|
10669
|
+
candidates: tied
|
|
10724
10670
|
};
|
|
10725
10671
|
return {
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
|
|
10672
|
+
branch,
|
|
10673
|
+
iteration: best.name,
|
|
10674
|
+
candidates: []
|
|
10729
10675
|
};
|
|
10730
10676
|
}
|
|
10731
|
-
|
|
10732
|
-
|
|
10733
|
-
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
|
|
10738
|
-
|
|
10739
|
-
...entry
|
|
10740
|
-
})}\n`, 'utf8');
|
|
10741
|
-
} catch {}
|
|
10677
|
+
const PROTECTED_BRANCHES = new Set([
|
|
10678
|
+
'main',
|
|
10679
|
+
'master'
|
|
10680
|
+
]);
|
|
10681
|
+
function assertWritableBranch(docsRoot) {
|
|
10682
|
+
const branch = currentBranch(docsRoot);
|
|
10683
|
+
if (null === branch) throw new errors_CliError("文档仓库处于 detached HEAD,无法确认所在分支,写操作已拒绝。\n请先切到迭代分支再重试:git switch <分支>", errors_EXIT.INVALID);
|
|
10684
|
+
if (PROTECTED_BRANCHES.has(branch.toLowerCase())) throw new errors_CliError(`文档仓库当前在 ${branch} 分支,禁止直接修改文档。\n请先切到该迭代的分支再重试,例如:\n git switch -c feature_<迭代名>`, errors_EXIT.INVALID);
|
|
10742
10685
|
}
|
|
10743
|
-
|
|
10744
|
-
|
|
10745
|
-
|
|
10746
|
-
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
10686
|
+
const TASK_TYPE_GROUPS = [
|
|
10687
|
+
'frontend',
|
|
10688
|
+
'backend'
|
|
10689
|
+
];
|
|
10690
|
+
const SUPPORTED_SCHEMA_VERSION = 1;
|
|
10691
|
+
const SCHEMA_FILENAME = 'schema.json';
|
|
10692
|
+
function docSchemaPath(docsRoot) {
|
|
10693
|
+
return external_node_path_join(docsRoot, SCHEMA_FILENAME);
|
|
10694
|
+
}
|
|
10695
|
+
function fail(docsRoot, reason) {
|
|
10696
|
+
throw new errors_CliError(`文档仓库的 ${SCHEMA_FILENAME} 不可用:${reason}\n路径:${docSchemaPath(docsRoot)}\n该文件是文档格式的唯一来源,请拉取文档仓库最新版本后重试。`, errors_EXIT.NOT_FOUND);
|
|
10697
|
+
}
|
|
10698
|
+
function requireStringArray(value, where, docsRoot) {
|
|
10699
|
+
if (!Array.isArray(value) || 0 === value.length) fail(docsRoot, `${where} 必须是非空字符串数组`);
|
|
10700
|
+
return value.map((item, index)=>{
|
|
10701
|
+
if ('string' != typeof item || 0 === item.trim().length) fail(docsRoot, `${where}[${index}] 必须是非空字符串`);
|
|
10702
|
+
return item;
|
|
10703
|
+
});
|
|
10704
|
+
}
|
|
10705
|
+
function requireString(value, where, docsRoot) {
|
|
10706
|
+
if ('string' != typeof value || 0 === value.trim().length) fail(docsRoot, `${where} 必须是非空字符串`);
|
|
10707
|
+
return value;
|
|
10708
|
+
}
|
|
10709
|
+
function requireRecord(value, where, docsRoot) {
|
|
10710
|
+
if ('object' != typeof value || null === value || Array.isArray(value)) fail(docsRoot, `${where} 必须是对象`);
|
|
10711
|
+
return value;
|
|
10712
|
+
}
|
|
10713
|
+
function parseDocSchema(raw, docsRoot) {
|
|
10714
|
+
const data = requireRecord(raw, 'schema', docsRoot);
|
|
10715
|
+
const version = data.schemaVersion;
|
|
10716
|
+
if ('number' != typeof version || !Number.isInteger(version)) fail(docsRoot, 'schemaVersion 必须是整数');
|
|
10717
|
+
if (version > SUPPORTED_SCHEMA_VERSION) fail(docsRoot, `schemaVersion ${version} 高于当前 ylcwf 支持的 ${SUPPORTED_SCHEMA_VERSION},请升级 ylcwf`);
|
|
10718
|
+
const requirementTable = requireRecord(data.requirementTable, 'requirementTable', docsRoot);
|
|
10719
|
+
const taskTable = requireRecord(data.taskTable, 'taskTable', docsRoot);
|
|
10720
|
+
const REQUIRED_REQUIREMENT_KEYS = [
|
|
10721
|
+
'id',
|
|
10722
|
+
'status',
|
|
10723
|
+
'progress',
|
|
10724
|
+
'updatedAt'
|
|
10725
|
+
];
|
|
10726
|
+
const REQUIRED_TASK_KEYS = [
|
|
10727
|
+
'id',
|
|
10728
|
+
'requirement',
|
|
10729
|
+
'name',
|
|
10730
|
+
'type',
|
|
10731
|
+
'scope',
|
|
10732
|
+
'terminal',
|
|
10733
|
+
'dependencies',
|
|
10734
|
+
'selfTest',
|
|
10735
|
+
'acceptance',
|
|
10736
|
+
'status',
|
|
10737
|
+
'updatedAt'
|
|
10738
|
+
];
|
|
10739
|
+
const readKeys = (table, headers, required, where)=>{
|
|
10740
|
+
const raw = table.keys;
|
|
10741
|
+
if (void 0 === raw) fail(docsRoot, `${where}.keys 必须声明列语义`);
|
|
10742
|
+
const record = requireRecord(raw, `${where}.keys`, docsRoot);
|
|
10743
|
+
const result = {};
|
|
10744
|
+
for (const semantic of required){
|
|
10745
|
+
const value = record[semantic];
|
|
10746
|
+
if ('string' != typeof value || 0 === value.trim().length) fail(docsRoot, `${where}.keys 缺少必需语义:${semantic}`);
|
|
10747
|
+
if (!headers.includes(value)) fail(docsRoot, `${where}.keys.${semantic} 指向的列「${value}」不在 headers 中`);
|
|
10748
|
+
result[semantic] = value;
|
|
10759
10749
|
}
|
|
10750
|
+
return result;
|
|
10751
|
+
};
|
|
10752
|
+
const progressRaw = requirementTable.progressRange;
|
|
10753
|
+
let progressRange = [
|
|
10754
|
+
0,
|
|
10755
|
+
100
|
|
10756
|
+
];
|
|
10757
|
+
if (void 0 !== progressRaw) {
|
|
10758
|
+
if (!Array.isArray(progressRaw) || 2 !== progressRaw.length) fail(docsRoot, 'requirementTable.progressRange 必须是 [最小值, 最大值]');
|
|
10759
|
+
const [low, high] = progressRaw;
|
|
10760
|
+
if ('number' != typeof low || 'number' != typeof high) fail(docsRoot, 'requirementTable.progressRange 必须是数字');
|
|
10761
|
+
progressRange = [
|
|
10762
|
+
low,
|
|
10763
|
+
high
|
|
10764
|
+
];
|
|
10760
10765
|
}
|
|
10761
|
-
|
|
10766
|
+
const enumsRaw = requireRecord(data.enums, 'enums', docsRoot);
|
|
10767
|
+
const taskTypesRaw = requireRecord(data.taskTypes, 'taskTypes', docsRoot);
|
|
10768
|
+
const taskTypes = {};
|
|
10769
|
+
for (const group of TASK_TYPE_GROUPS){
|
|
10770
|
+
const items = taskTypesRaw[group];
|
|
10771
|
+
if (!Array.isArray(items) || 0 === items.length) fail(docsRoot, `taskTypes.${group} 必须是非空数组`);
|
|
10772
|
+
taskTypes[group] = items.map((item, index)=>{
|
|
10773
|
+
const entry = requireRecord(item, `taskTypes.${group}[${index}]`, docsRoot);
|
|
10774
|
+
return {
|
|
10775
|
+
name: requireString(entry.name, `taskTypes.${group}[${index}].name`, docsRoot),
|
|
10776
|
+
desc: requireString(entry.desc, `taskTypes.${group}[${index}].desc`, docsRoot)
|
|
10777
|
+
};
|
|
10778
|
+
});
|
|
10779
|
+
}
|
|
10780
|
+
for (const group of TASK_TYPE_GROUPS){
|
|
10781
|
+
const seenInGroup = new Set();
|
|
10782
|
+
for (const item of taskTypes[group]){
|
|
10783
|
+
if (seenInGroup.has(item.name)) fail(docsRoot, `taskTypes.${group} 内任务类型重复:${item.name}`);
|
|
10784
|
+
seenInGroup.add(item.name);
|
|
10785
|
+
}
|
|
10786
|
+
}
|
|
10787
|
+
const rolesRaw = requireRecord(data.roles, 'roles', docsRoot);
|
|
10788
|
+
const roles = {};
|
|
10789
|
+
for (const [role, value] of Object.entries(rolesRaw)){
|
|
10790
|
+
const where = `roles.${role}`;
|
|
10791
|
+
const entry = requireRecord(value, where, docsRoot);
|
|
10792
|
+
const groups = requireStringArray(entry.taskTypeGroups, `${where}.taskTypeGroups`, docsRoot);
|
|
10793
|
+
for (const group of groups)if (!TASK_TYPE_GROUPS.includes(group)) fail(docsRoot, `${where}.taskTypeGroups 引用了未知分组:${group}`);
|
|
10794
|
+
roles[role] = {
|
|
10795
|
+
scope: requireString(entry.scope, `${where}.scope`, docsRoot),
|
|
10796
|
+
scopeRequires: requireStringArray(entry.scopeRequires, `${where}.scopeRequires`, docsRoot),
|
|
10797
|
+
detailFields: void 0 === entry.detailFields ? [] : requireStringArray(entry.detailFields, `${where}.detailFields`, docsRoot),
|
|
10798
|
+
taskTypeGroups: groups
|
|
10799
|
+
};
|
|
10800
|
+
}
|
|
10801
|
+
if (0 === Object.keys(roles).length) fail(docsRoot, 'roles 不能为空');
|
|
10802
|
+
const scopeEnumRaw = taskTable.scopeEnum;
|
|
10803
|
+
const scopeEnum = requireStringArray(scopeEnumRaw, 'taskTable.scopeEnum', docsRoot);
|
|
10804
|
+
for (const value of scopeEnum){
|
|
10805
|
+
const matched = Object.entries(roles).filter(([, config])=>config.scope === value);
|
|
10806
|
+
if (1 !== matched.length) fail(docsRoot, `所属端「${value}」需唯一对应一个 roles.* 角色,实际匹配:${matched.length} 个`);
|
|
10807
|
+
const owner = matched[0];
|
|
10808
|
+
if (void 0 === owner || 0 === owner[1].detailFields.length) fail(docsRoot, `roles.${owner?.[0] ?? '?'} 负责所属端「${value}」,必须声明 detailFields`);
|
|
10809
|
+
}
|
|
10810
|
+
const requirementHeaders = requireStringArray(requirementTable.headers, 'requirementTable.headers', docsRoot);
|
|
10811
|
+
const taskHeaders = requireStringArray(taskTable.headers, 'taskTable.headers', docsRoot);
|
|
10812
|
+
return {
|
|
10813
|
+
version,
|
|
10814
|
+
sections: requireStringArray(data.sections, 'sections', docsRoot),
|
|
10815
|
+
iterationFields: requireStringArray(data.iterationFields, 'iterationFields', docsRoot),
|
|
10816
|
+
requirementHeaders,
|
|
10817
|
+
requirementKeys: readKeys(requirementTable, requirementHeaders, REQUIRED_REQUIREMENT_KEYS, 'requirementTable'),
|
|
10818
|
+
requirementIdPattern: requireString(requirementTable.idPattern, 'requirementTable.idPattern', docsRoot),
|
|
10819
|
+
progressRange,
|
|
10820
|
+
taskHeaders,
|
|
10821
|
+
taskKeys: readKeys(taskTable, taskHeaders, REQUIRED_TASK_KEYS, 'taskTable'),
|
|
10822
|
+
taskIdPattern: requireString(taskTable.idPattern, 'taskTable.idPattern', docsRoot),
|
|
10823
|
+
taskScopeEnum: requireStringArray(taskTable.scopeEnum, 'taskTable.scopeEnum', docsRoot),
|
|
10824
|
+
enums: {
|
|
10825
|
+
requirementStatus: requireStringArray(enumsRaw.requirementStatus, 'enums.requirementStatus', docsRoot),
|
|
10826
|
+
taskStatus: requireStringArray(enumsRaw.taskStatus, 'enums.taskStatus', docsRoot),
|
|
10827
|
+
selfTest: requireStringArray(enumsRaw.selfTest, 'enums.selfTest', docsRoot),
|
|
10828
|
+
acceptance: requireStringArray(enumsRaw.acceptance, 'enums.acceptance', docsRoot)
|
|
10829
|
+
},
|
|
10830
|
+
taskTypes,
|
|
10831
|
+
updatedAtFormat: requireString(data.updatedAtFormat, 'updatedAtFormat', docsRoot),
|
|
10832
|
+
roles
|
|
10833
|
+
};
|
|
10762
10834
|
}
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
10770
|
-
}
|
|
10771
|
-
|
|
10772
|
-
|
|
10773
|
-
|
|
10774
|
-
|
|
10775
|
-
|
|
10776
|
-
}
|
|
10777
|
-
|
|
10778
|
-
const index = headerCells.findIndex((cell)=>cell.trim() === name);
|
|
10779
|
-
if (index < 0) throw new errors_CliError(`表格缺少列「${name}」,无法安全写入`, errors_EXIT.INVALID);
|
|
10780
|
-
return index;
|
|
10835
|
+
function loadDocSchema(docsRoot) {
|
|
10836
|
+
const target = docSchemaPath(docsRoot);
|
|
10837
|
+
let text;
|
|
10838
|
+
try {
|
|
10839
|
+
text = readFileSync(target, 'utf8');
|
|
10840
|
+
} catch {
|
|
10841
|
+
fail(docsRoot, '文件不存在或不可读');
|
|
10842
|
+
}
|
|
10843
|
+
let raw;
|
|
10844
|
+
try {
|
|
10845
|
+
raw = JSON.parse(text);
|
|
10846
|
+
} catch (error) {
|
|
10847
|
+
fail(docsRoot, `不是合法 JSON:${error instanceof Error ? error.message : String(error)}`);
|
|
10848
|
+
}
|
|
10849
|
+
return parseDocSchema(raw, docsRoot);
|
|
10781
10850
|
}
|
|
10782
|
-
function
|
|
10783
|
-
const
|
|
10784
|
-
|
|
10785
|
-
const
|
|
10786
|
-
|
|
10851
|
+
function taskTypesOf(schema, role) {
|
|
10852
|
+
const config = schema.roles[role];
|
|
10853
|
+
if (void 0 === config) return [];
|
|
10854
|
+
const names = [];
|
|
10855
|
+
for (const group of config.taskTypeGroups)for (const item of schema.taskTypes[group])if (!names.includes(item.name)) names.push(item.name);
|
|
10856
|
+
return names;
|
|
10787
10857
|
}
|
|
10788
|
-
function
|
|
10789
|
-
|
|
10858
|
+
function roleOfScope(schema, scope) {
|
|
10859
|
+
for (const [role, config] of Object.entries(schema.roles))if (config.scope === scope) return role;
|
|
10860
|
+
return null;
|
|
10790
10861
|
}
|
|
10791
|
-
function
|
|
10792
|
-
const
|
|
10793
|
-
|
|
10862
|
+
function detailFieldsOfScope(schema, scope) {
|
|
10863
|
+
const role = roleOfScope(schema, scope);
|
|
10864
|
+
if (null === role) return [];
|
|
10865
|
+
return schema.roles[role]?.detailFields ?? [];
|
|
10866
|
+
}
|
|
10867
|
+
function sideOfTypeName(schema, typeName) {
|
|
10868
|
+
const inFront = schema.taskTypes.frontend.some((item)=>item.name === typeName);
|
|
10869
|
+
const inBack = schema.taskTypes.backend.some((item)=>item.name === typeName);
|
|
10870
|
+
if (inFront && inBack) return 'both';
|
|
10871
|
+
if (inFront) return 'frontend';
|
|
10872
|
+
if (inBack) return 'backend';
|
|
10873
|
+
return null;
|
|
10794
10874
|
}
|
|
10795
|
-
function
|
|
10796
|
-
const
|
|
10797
|
-
|
|
10798
|
-
|
|
10799
|
-
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10875
|
+
function buildRepoSideIndex(terminals) {
|
|
10876
|
+
const byName = new Map();
|
|
10877
|
+
for (const terminal of Object.values(terminals))for (const side of [
|
|
10878
|
+
'frontend',
|
|
10879
|
+
'backend'
|
|
10880
|
+
])for (const repoPath of terminal.repos[side]){
|
|
10881
|
+
const name = basename(repoPath);
|
|
10882
|
+
if (0 === name.length) continue;
|
|
10883
|
+
const existing = byName.get(name) ?? new Set();
|
|
10884
|
+
existing.add(side);
|
|
10885
|
+
byName.set(name, existing);
|
|
10805
10886
|
}
|
|
10887
|
+
return {
|
|
10888
|
+
byName
|
|
10889
|
+
};
|
|
10890
|
+
}
|
|
10891
|
+
function sideOfRepo(index, repoName) {
|
|
10892
|
+
const sides = index.byName.get(repoName.trim());
|
|
10893
|
+
if (void 0 === sides || 1 !== sides.size) return null;
|
|
10806
10894
|
return [
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
];
|
|
10895
|
+
...sides
|
|
10896
|
+
][0] ?? null;
|
|
10810
10897
|
}
|
|
10811
|
-
function
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10898
|
+
function isKnownRepo(index, repoName) {
|
|
10899
|
+
return index.byName.has(repoName.trim());
|
|
10900
|
+
}
|
|
10901
|
+
function validateTaskSides(options) {
|
|
10902
|
+
const issues = [];
|
|
10903
|
+
let checked = 0;
|
|
10904
|
+
let skipped = 0;
|
|
10905
|
+
for (const task of options.tasks){
|
|
10906
|
+
const expected = '前端' === task.scope ? 'frontend' : '后端' === task.scope ? 'backend' : null;
|
|
10907
|
+
if (null === expected) {
|
|
10908
|
+
skipped += 1;
|
|
10821
10909
|
continue;
|
|
10822
10910
|
}
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
index
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10911
|
+
const repoSide = sideOfRepo(options.index, task.terminal);
|
|
10912
|
+
if (null === repoSide) {
|
|
10913
|
+
skipped += 1;
|
|
10914
|
+
if (options.index.byName.size > 0) issues.push({
|
|
10915
|
+
taskId: task.id,
|
|
10916
|
+
scope: task.scope,
|
|
10917
|
+
terminal: task.terminal,
|
|
10918
|
+
repoSide: null,
|
|
10919
|
+
level: 'warning',
|
|
10920
|
+
message: isKnownRepo(options.index, task.terminal) ? `任务 ${task.id} 的终端「${task.terminal}」在本机配置中同时对应前后端仓库,无法校验归属` : `任务 ${task.id} 的终端「${task.terminal}」不在本机终端配置中,无法校验所属端与仓库是否一致`
|
|
10921
|
+
});
|
|
10922
|
+
continue;
|
|
10923
|
+
}
|
|
10924
|
+
checked += 1;
|
|
10925
|
+
if (repoSide !== expected) issues.push({
|
|
10926
|
+
taskId: task.id,
|
|
10927
|
+
scope: task.scope,
|
|
10928
|
+
terminal: task.terminal,
|
|
10929
|
+
repoSide,
|
|
10930
|
+
level: 'warning',
|
|
10931
|
+
message: `任务 ${task.id} 的所属端是「${task.scope}」,但终端「${task.terminal}」在本机配置里是${describeSide(repoSide)}仓库,请核对`
|
|
10833
10932
|
});
|
|
10834
10933
|
}
|
|
10835
|
-
if (null === header) throw new errors_CliError('未找到任务清单表头,无法安全写入', errors_EXIT.INVALID);
|
|
10836
10934
|
return {
|
|
10837
|
-
|
|
10838
|
-
|
|
10935
|
+
issues,
|
|
10936
|
+
checked,
|
|
10937
|
+
skipped
|
|
10839
10938
|
};
|
|
10840
10939
|
}
|
|
10841
|
-
function
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10940
|
+
function describeSide(side) {
|
|
10941
|
+
return 'backend' === side ? '后端' : '前端';
|
|
10942
|
+
}
|
|
10943
|
+
const FILE_CHANGES = [
|
|
10944
|
+
'新增',
|
|
10945
|
+
'修改',
|
|
10946
|
+
'删除'
|
|
10947
|
+
];
|
|
10948
|
+
function docplan_fail(message) {
|
|
10949
|
+
throw new errors_CliError(`plan 校验失败:${message}`, errors_EXIT.INVALID);
|
|
10950
|
+
}
|
|
10951
|
+
function docplan_isRecord(value) {
|
|
10952
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
10953
|
+
}
|
|
10954
|
+
function optionalString(value, where) {
|
|
10955
|
+
if (null == value) return;
|
|
10956
|
+
if ('string' != typeof value) docplan_fail(`${where} 必须是字符串`);
|
|
10957
|
+
return value;
|
|
10958
|
+
}
|
|
10959
|
+
function docplan_requireString(value, where) {
|
|
10960
|
+
if ('string' != typeof value || 0 === value.trim().length) docplan_fail(`${where} 必须是非空字符串`);
|
|
10961
|
+
return value.trim();
|
|
10962
|
+
}
|
|
10963
|
+
function optionalStringArray(value, where) {
|
|
10964
|
+
if (null == value) return [];
|
|
10965
|
+
if (!Array.isArray(value)) docplan_fail(`${where} 必须是字符串数组`);
|
|
10966
|
+
return value.map((item, index)=>docplan_requireString(item, `${where}[${index}]`));
|
|
10967
|
+
}
|
|
10968
|
+
function normalizeCode(raw) {
|
|
10969
|
+
const trimmed = raw.trim();
|
|
10970
|
+
const withoutHash = trimmed.startsWith('#') ? trimmed.slice(1) : trimmed;
|
|
10971
|
+
if (!/^\d{3,6}$/.test(withoutHash)) docplan_fail(`需求编号格式非法(应为 2755 或 #2755):${raw}`);
|
|
10972
|
+
return `#${withoutHash}`;
|
|
10973
|
+
}
|
|
10974
|
+
function parseDocPlan(raw, schema, role) {
|
|
10975
|
+
if (!docplan_isRecord(raw)) docplan_fail('顶层必须是对象');
|
|
10976
|
+
const iterationRaw = raw.iteration;
|
|
10977
|
+
let iteration = {};
|
|
10978
|
+
if (null != iterationRaw) {
|
|
10979
|
+
if (!docplan_isRecord(iterationRaw)) docplan_fail('iteration 必须是对象');
|
|
10980
|
+
const collected = {};
|
|
10981
|
+
for (const field of schema.iterationFields){
|
|
10982
|
+
const value = optionalString(iterationRaw[field], `iteration.${field}`);
|
|
10983
|
+
if (void 0 !== value && value.trim().length > 0) collected[field] = value.trim();
|
|
10984
|
+
}
|
|
10985
|
+
iteration = collected;
|
|
10986
|
+
}
|
|
10987
|
+
if (!Array.isArray(raw.requirements)) docplan_fail('requirements 必须是数组');
|
|
10988
|
+
if (!Array.isArray(raw.tasks)) docplan_fail('tasks 必须是数组');
|
|
10989
|
+
if (0 === raw.tasks.length) docplan_fail('tasks 不能为空');
|
|
10990
|
+
const requirements = raw.requirements.map((item, index)=>{
|
|
10991
|
+
if (!docplan_isRecord(item)) docplan_fail(`requirements[${index}] 必须是对象`);
|
|
10992
|
+
return {
|
|
10993
|
+
code: normalizeCode(docplan_requireString(item.code, `requirements[${index}].code`)),
|
|
10994
|
+
name: docplan_requireString(item.name, `requirements[${index}].name`),
|
|
10995
|
+
terminal: docplan_requireString(item.terminal, `requirements[${index}].terminal`),
|
|
10996
|
+
note: optionalString(item.note, `requirements[${index}].note`) ?? ''
|
|
10997
|
+
};
|
|
10998
|
+
});
|
|
10999
|
+
const seenRequirements = new Set();
|
|
11000
|
+
for (const requirement of requirements){
|
|
11001
|
+
if (seenRequirements.has(requirement.code)) docplan_fail(`需求编号重复:${requirement.code}`);
|
|
11002
|
+
seenRequirements.add(requirement.code);
|
|
11003
|
+
}
|
|
11004
|
+
const allowedTypes = new Set(taskTypesOf(schema, role));
|
|
11005
|
+
const scopeEnum = schema.taskScopeEnum;
|
|
11006
|
+
const tasks = raw.tasks.map((item, index)=>{
|
|
11007
|
+
const where = `tasks[${index}]`;
|
|
11008
|
+
if (!docplan_isRecord(item)) docplan_fail(`${where} 必须是对象`);
|
|
11009
|
+
const type = docplan_requireString(item.type, `${where}.type`);
|
|
11010
|
+
if (allowedTypes.size > 0 && !allowedTypes.has(type)) docplan_fail(`${where}.type 非法:${type}(角色 ${role} 允许:${[
|
|
11011
|
+
...allowedTypes
|
|
11012
|
+
].join('、')})`);
|
|
11013
|
+
const filesRaw = item.files;
|
|
11014
|
+
let files = [];
|
|
11015
|
+
if (null != filesRaw) {
|
|
11016
|
+
if (!Array.isArray(filesRaw)) docplan_fail(`${where}.files 必须是数组`);
|
|
11017
|
+
files = filesRaw.map((entry, fileIndex)=>{
|
|
11018
|
+
if (!docplan_isRecord(entry)) docplan_fail(`${where}.files[${fileIndex}] 必须是对象`);
|
|
11019
|
+
const change = docplan_requireString(entry.change, `${where}.files[${fileIndex}].change`);
|
|
11020
|
+
if (!FILE_CHANGES.includes(change)) docplan_fail(`${where}.files[${fileIndex}].change 只能是 ${FILE_CHANGES.join(' / ')}`);
|
|
11021
|
+
return {
|
|
11022
|
+
path: docplan_requireString(entry.path, `${where}.files[${fileIndex}].path`),
|
|
11023
|
+
change: change
|
|
11024
|
+
};
|
|
11025
|
+
});
|
|
11026
|
+
}
|
|
11027
|
+
const selfTestRaw = item.selfTest;
|
|
11028
|
+
let selfTest = [];
|
|
11029
|
+
if (null != selfTestRaw) {
|
|
11030
|
+
if (!Array.isArray(selfTestRaw)) docplan_fail(`${where}.selfTest 必须是数组`);
|
|
11031
|
+
selfTest = selfTestRaw.map((entry, testIndex)=>{
|
|
11032
|
+
if (!docplan_isRecord(entry)) docplan_fail(`${where}.selfTest[${testIndex}] 必须是对象`);
|
|
11033
|
+
return {
|
|
11034
|
+
cmd: docplan_requireString(entry.cmd, `${where}.selfTest[${testIndex}].cmd`),
|
|
11035
|
+
result: docplan_requireString(entry.result, `${where}.selfTest[${testIndex}].result`)
|
|
11036
|
+
};
|
|
11037
|
+
});
|
|
11038
|
+
}
|
|
11039
|
+
let detailFields;
|
|
11040
|
+
if (void 0 !== item.detailFields && null !== item.detailFields) {
|
|
11041
|
+
if (!docplan_isRecord(item.detailFields)) docplan_fail(`${where}.detailFields 必须是对象`);
|
|
11042
|
+
const allowed = new Set(schema.roles[role]?.detailFields ?? []);
|
|
11043
|
+
detailFields = {};
|
|
11044
|
+
for (const [key, value] of Object.entries(item.detailFields)){
|
|
11045
|
+
if (allowed.size > 0 && !allowed.has(key)) docplan_fail(`${where}.detailFields 含未知字段「${key}」(角色 ${role} 允许:${[
|
|
11046
|
+
...allowed
|
|
11047
|
+
].join('、')};新增字段请先改 schema.json 与模板)`);
|
|
11048
|
+
if ('string' == typeof value) {
|
|
11049
|
+
detailFields[key] = value;
|
|
11050
|
+
continue;
|
|
11051
|
+
}
|
|
11052
|
+
if (Array.isArray(value)) {
|
|
11053
|
+
detailFields[key] = value.map((entry, index)=>docplan_requireString(entry, `${where}.detailFields.${key}[${index}]`));
|
|
11054
|
+
continue;
|
|
11055
|
+
}
|
|
11056
|
+
docplan_fail(`${where}.detailFields.${key} 必须是字符串或字符串数组`);
|
|
11057
|
+
}
|
|
11058
|
+
}
|
|
11059
|
+
const declaredScope = optionalString(item.scope, `${where}.scope`)?.trim();
|
|
11060
|
+
let scope;
|
|
11061
|
+
if (void 0 !== declaredScope && declaredScope.length > 0) {
|
|
11062
|
+
if (!scopeEnum.includes(declaredScope)) docplan_fail(`${where}.scope 非法:${declaredScope}(允许值:${scopeEnum.join('、')})`);
|
|
11063
|
+
scope = declaredScope;
|
|
11064
|
+
} else {
|
|
11065
|
+
const side = sideOfTypeName(schema, type);
|
|
11066
|
+
const inferred = 'frontend' === side ? '前端' : 'backend' === side ? '后端' : void 0;
|
|
11067
|
+
if (void 0 === inferred) docplan_fail(`${where}.scope 必须显式指定:类型「${type}」两端都可用,无法自动判断(允许值:${scopeEnum.join('、')})`);
|
|
11068
|
+
scope = inferred;
|
|
11069
|
+
}
|
|
11070
|
+
const typeSide = sideOfTypeName(schema, type);
|
|
11071
|
+
const expectedScope = 'frontend' === typeSide ? '前端' : 'backend' === typeSide ? '后端' : void 0;
|
|
11072
|
+
if (void 0 !== expectedScope && scope !== expectedScope) docplan_fail(`${where}.type「${type}」属于${expectedScope},但 scope 填的是「${scope}」`);
|
|
11073
|
+
return {
|
|
11074
|
+
requirement: normalizeCode(docplan_requireString(item.requirement, `${where}.requirement`)),
|
|
11075
|
+
name: docplan_requireString(item.name, `${where}.name`),
|
|
11076
|
+
type,
|
|
11077
|
+
scope,
|
|
11078
|
+
terminal: docplan_requireString(item.terminal, `${where}.terminal`),
|
|
11079
|
+
dependsOn: optionalStringArray(item.dependsOn, `${where}.dependsOn`),
|
|
11080
|
+
files,
|
|
11081
|
+
plan: optionalStringArray(item.plan, `${where}.plan`),
|
|
11082
|
+
selfTest,
|
|
11083
|
+
testForms: optionalStringArray(item.testForms, `${where}.testForms`),
|
|
11084
|
+
regression: optionalStringArray(item.regression, `${where}.regression`),
|
|
11085
|
+
notes: optionalString(item.notes, `${where}.notes`) ?? '无',
|
|
11086
|
+
detailFields
|
|
11087
|
+
};
|
|
11088
|
+
});
|
|
11089
|
+
return {
|
|
11090
|
+
iteration,
|
|
11091
|
+
requirements,
|
|
11092
|
+
tasks
|
|
11093
|
+
};
|
|
11094
|
+
}
|
|
11095
|
+
function validatePlanReferences(options) {
|
|
11096
|
+
const knownRepos = new Set();
|
|
11097
|
+
for (const [name] of options.index.byName)knownRepos.add(name);
|
|
11098
|
+
const requirementCodes = new Set(options.plan.requirements.map((item)=>item.code));
|
|
11099
|
+
for (const task of options.plan.tasks){
|
|
11100
|
+
if (!requirementCodes.has(task.requirement)) docplan_fail(`任务「${task.name}」关联的需求 ${task.requirement} 不在 requirements 中`);
|
|
11101
|
+
if (knownRepos.size > 0 && !isKnownRepo(options.index, task.terminal)) process.stderr.write(`提示:任务「${task.name}」的终端「${task.terminal}」不在本机终端配置中,跳过归属校验\n`);
|
|
11102
|
+
for (const dependency of task.dependsOn ?? []){
|
|
11103
|
+
const normalized = dependency.startsWith('#') ? dependency : `#${dependency}`;
|
|
11104
|
+
if (!options.knownTaskIds.includes(normalized)) {
|
|
11105
|
+
if (!options.plan.tasks.some((item)=>item.name === dependency)) docplan_fail(`任务「${task.name}」的前置依赖 ${dependency} 既不在文档中,也不在本次计划中`);
|
|
11106
|
+
}
|
|
10852
11107
|
}
|
|
10853
|
-
if (cells.every((cell)=>/^:?-{2,}:?$/.test(cell))) continue;
|
|
10854
|
-
const id = cells[columnIndex(header, REQUIREMENT_HEADERS.id)] ?? '';
|
|
10855
|
-
if (/^#\d{3,6}$/.test(id)) rows.push({
|
|
10856
|
-
index,
|
|
10857
|
-
cells,
|
|
10858
|
-
id
|
|
10859
|
-
});
|
|
10860
11108
|
}
|
|
10861
|
-
|
|
11109
|
+
}
|
|
11110
|
+
const PENDING_STATUS = '未开始';
|
|
11111
|
+
const PENDING_SELF_TEST = '未执行';
|
|
11112
|
+
const PENDING_ACCEPTANCE = '待验收';
|
|
11113
|
+
function headings(schema) {
|
|
10862
11114
|
return {
|
|
10863
|
-
|
|
10864
|
-
|
|
11115
|
+
info: `## ${schema.sections[0] ?? '一、迭代信息'}`,
|
|
11116
|
+
requirement: `## ${schema.sections[1] ?? '二、需求清单'}`,
|
|
11117
|
+
task: `## ${schema.sections[2] ?? '三、任务清单'}`,
|
|
11118
|
+
detail: `## ${schema.sections[3] ?? '四、任务详情'}`
|
|
10865
11119
|
};
|
|
10866
11120
|
}
|
|
11121
|
+
function joinRow(cells) {
|
|
11122
|
+
return `| ${cells.join(' | ')} |`;
|
|
11123
|
+
}
|
|
11124
|
+
function docrender_separator(count) {
|
|
11125
|
+
return joinRow(Array.from({
|
|
11126
|
+
length: count
|
|
11127
|
+
}, ()=>'---'));
|
|
11128
|
+
}
|
|
11129
|
+
function nextSequence(existingTasks) {
|
|
11130
|
+
const counters = new Map();
|
|
11131
|
+
for (const task of existingTasks){
|
|
11132
|
+
const matched = /^#(\d{3,6})-T(\d+)$/.exec(task.id);
|
|
11133
|
+
if (null === matched) continue;
|
|
11134
|
+
const requirementId = `#${matched[1] ?? ''}`;
|
|
11135
|
+
const sequence = Number(matched[2] ?? '0');
|
|
11136
|
+
const current = counters.get(requirementId) ?? 0;
|
|
11137
|
+
if (sequence > current) counters.set(requirementId, sequence);
|
|
11138
|
+
}
|
|
11139
|
+
return counters;
|
|
11140
|
+
}
|
|
10867
11141
|
function aggregateRequirementStatus(statuses) {
|
|
10868
11142
|
if (0 === statuses.length) return '未开始';
|
|
10869
|
-
if (statuses.every((status)=>'未开始' === status)) return '未开始';
|
|
10870
11143
|
if (statuses.every((status)=>'已完成' === status)) return '已完成';
|
|
11144
|
+
if (statuses.every((status)=>status === PENDING_STATUS)) return '未开始';
|
|
10871
11145
|
return '进行中';
|
|
10872
11146
|
}
|
|
10873
|
-
function
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
10882
|
-
|
|
11147
|
+
function progressOf(statuses) {
|
|
11148
|
+
if (0 === statuses.length) return 0;
|
|
11149
|
+
const done = statuses.filter((status)=>'已完成' === status).length;
|
|
11150
|
+
return Math.round(done / statuses.length * 100);
|
|
11151
|
+
}
|
|
11152
|
+
function renderDetail(options) {
|
|
11153
|
+
const { taskId, task, requirement } = options;
|
|
11154
|
+
const builtin = new Map();
|
|
11155
|
+
builtin.set('任务状态', {
|
|
11156
|
+
items: [
|
|
11157
|
+
PENDING_STATUS
|
|
11158
|
+
],
|
|
11159
|
+
list: false
|
|
11160
|
+
});
|
|
11161
|
+
builtin.set('自测状态', {
|
|
11162
|
+
items: [
|
|
11163
|
+
PENDING_SELF_TEST
|
|
11164
|
+
],
|
|
11165
|
+
list: false
|
|
11166
|
+
});
|
|
11167
|
+
builtin.set('人工验收', {
|
|
11168
|
+
items: [
|
|
11169
|
+
PENDING_ACCEPTANCE
|
|
11170
|
+
],
|
|
11171
|
+
list: false
|
|
11172
|
+
});
|
|
11173
|
+
builtin.set('所属需求', {
|
|
11174
|
+
items: [
|
|
11175
|
+
`${requirement.code} ${requirement.name}`
|
|
11176
|
+
],
|
|
11177
|
+
list: false
|
|
11178
|
+
});
|
|
11179
|
+
builtin.set('任务类型', {
|
|
11180
|
+
items: [
|
|
11181
|
+
task.type
|
|
11182
|
+
],
|
|
11183
|
+
list: false
|
|
11184
|
+
});
|
|
11185
|
+
builtin.set('核心文件清单', {
|
|
11186
|
+
items: (task.files ?? []).map((file)=>`\`${file.path}\`(${file.change})`),
|
|
11187
|
+
list: true
|
|
11188
|
+
});
|
|
11189
|
+
builtin.set('详细实现方案', {
|
|
11190
|
+
items: task.plan ?? [],
|
|
11191
|
+
list: true
|
|
11192
|
+
});
|
|
11193
|
+
builtin.set('AI 单测与自检证据', {
|
|
11194
|
+
items: (task.selfTest ?? []).map((item)=>`\`${item.cmd}\`:${item.result}`),
|
|
11195
|
+
list: true
|
|
11196
|
+
});
|
|
11197
|
+
builtin.set('自测形式', {
|
|
11198
|
+
items: task.testForms ?? [],
|
|
11199
|
+
list: true
|
|
11200
|
+
});
|
|
11201
|
+
builtin.set('QA 历史功能影响范围 (Regression Scope)', {
|
|
11202
|
+
items: task.regression ?? [],
|
|
11203
|
+
list: true
|
|
11204
|
+
});
|
|
11205
|
+
builtin.set('待联调/遗留事项', {
|
|
11206
|
+
items: [
|
|
11207
|
+
task.notes ?? '无'
|
|
11208
|
+
],
|
|
11209
|
+
list: false
|
|
11210
|
+
});
|
|
11211
|
+
const lines = [
|
|
11212
|
+
`### [${taskId}] ${task.name}`,
|
|
11213
|
+
''
|
|
10883
11214
|
];
|
|
10884
|
-
for(
|
|
11215
|
+
for (const field of detailFieldsOfScope(options.schema, task.scope)){
|
|
11216
|
+
const custom = task.detailFields?.[field];
|
|
11217
|
+
const value = builtin.get(field) ?? (void 0 === custom ? void 0 : {
|
|
11218
|
+
items: Array.isArray(custom) ? custom : [
|
|
11219
|
+
custom
|
|
11220
|
+
],
|
|
11221
|
+
list: Array.isArray(custom)
|
|
11222
|
+
});
|
|
11223
|
+
if (void 0 === value) {
|
|
11224
|
+
lines.push(`- **${field}**:<待补充>`);
|
|
11225
|
+
continue;
|
|
11226
|
+
}
|
|
11227
|
+
if (!value.list && 1 === value.items.length) {
|
|
11228
|
+
lines.push(`- **${field}**:${value.items[0]}`);
|
|
11229
|
+
continue;
|
|
11230
|
+
}
|
|
11231
|
+
lines.push(`- **${field}**:`);
|
|
11232
|
+
for (const item of 0 === value.items.length ? [
|
|
11233
|
+
'<待补充>'
|
|
11234
|
+
] : value.items)lines.push(` - ${item}`);
|
|
11235
|
+
}
|
|
11236
|
+
lines.push('');
|
|
11237
|
+
return lines;
|
|
11238
|
+
}
|
|
11239
|
+
function appendTableRows(options) {
|
|
11240
|
+
const { lines, sectionHeading, headers, rows } = options;
|
|
11241
|
+
if (0 === rows.length) return lines;
|
|
11242
|
+
const start = lines.findIndex((line)=>line.trim() === sectionHeading);
|
|
11243
|
+
if (start < 0) {
|
|
11244
|
+
const block = [
|
|
11245
|
+
sectionHeading,
|
|
11246
|
+
'',
|
|
11247
|
+
joinRow([
|
|
11248
|
+
...headers
|
|
11249
|
+
]),
|
|
11250
|
+
docrender_separator(headers.length),
|
|
11251
|
+
...rows,
|
|
11252
|
+
''
|
|
11253
|
+
];
|
|
11254
|
+
return [
|
|
11255
|
+
...lines,
|
|
11256
|
+
...block
|
|
11257
|
+
];
|
|
11258
|
+
}
|
|
11259
|
+
let tableEnd = -1;
|
|
11260
|
+
let tableStart = -1;
|
|
11261
|
+
for(let index = start + 1; index < lines.length; index += 1){
|
|
10885
11262
|
const line = lines[index] ?? '';
|
|
10886
|
-
|
|
10887
|
-
if (
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
11263
|
+
if (/^##\s+/.test(line)) break;
|
|
11264
|
+
if (line.trim().startsWith('|')) {
|
|
11265
|
+
if (tableStart < 0) tableStart = index;
|
|
11266
|
+
tableEnd = index;
|
|
11267
|
+
}
|
|
11268
|
+
}
|
|
11269
|
+
if (tableStart < 0) {
|
|
11270
|
+
const block = [
|
|
11271
|
+
'',
|
|
11272
|
+
joinRow([
|
|
11273
|
+
...headers
|
|
11274
|
+
]),
|
|
11275
|
+
docrender_separator(headers.length),
|
|
11276
|
+
...rows
|
|
11277
|
+
];
|
|
11278
|
+
return [
|
|
11279
|
+
...lines.slice(0, start + 1),
|
|
11280
|
+
...block,
|
|
11281
|
+
...lines.slice(start + 1)
|
|
11282
|
+
];
|
|
10891
11283
|
}
|
|
10892
|
-
return
|
|
11284
|
+
return [
|
|
11285
|
+
...lines.slice(0, tableEnd + 1),
|
|
11286
|
+
...rows,
|
|
11287
|
+
...lines.slice(tableEnd + 1)
|
|
11288
|
+
];
|
|
10893
11289
|
}
|
|
10894
|
-
function
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
|
|
10898
|
-
}
|
|
10899
|
-
|
|
11290
|
+
function buildSkeleton(options) {
|
|
11291
|
+
const { schema, role, plan, developer } = options;
|
|
11292
|
+
const head = headings(schema);
|
|
11293
|
+
const lines = [];
|
|
11294
|
+
lines.push(`# ${developer}`, '');
|
|
11295
|
+
lines.push(head.info, '');
|
|
11296
|
+
lines.push(joinRow([
|
|
11297
|
+
'项',
|
|
11298
|
+
'内容'
|
|
11299
|
+
]));
|
|
11300
|
+
lines.push(docrender_separator(2));
|
|
11301
|
+
for (const field of schema.iterationFields){
|
|
11302
|
+
const provided = plan.iteration[field];
|
|
11303
|
+
const fallback = '负责人' === field ? developer : '负责范围' === field ? schema.roles[role]?.scope ?? '' : '';
|
|
11304
|
+
lines.push(joinRow([
|
|
11305
|
+
field,
|
|
11306
|
+
provided ?? fallback
|
|
11307
|
+
]));
|
|
10900
11308
|
}
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
const statusIndex = columnIndex(header, TASK_HEADERS.status);
|
|
10921
|
-
const acceptanceIndex = columnIndex(header, TASK_HEADERS.acceptance);
|
|
10922
|
-
const currentStatus = target.status;
|
|
10923
|
-
const currentAcceptance = target.acceptance;
|
|
10924
|
-
const meta = ACTION_META[action];
|
|
10925
|
-
if (currentStatus !== meta.from) throw new errors_CliError(`任务 ${taskId} 当前状态为「${currentStatus}」,无法执行「${meta.label}」(要求「${meta.from}」)`, errors_EXIT.USAGE);
|
|
10926
|
-
if ('submit' === action && !canSubmit(target.selfTest)) throw new errors_CliError(`任务 ${taskId} 的 AI 自测状态为「${target.selfTest}」,未通过自测不能提交验收`, errors_EXIT.USAGE);
|
|
10927
|
-
const nextStatus = meta.to;
|
|
10928
|
-
const nextAcceptance = 'accept' === action ? '验收通过' : 'reject' === action ? '验收驳回' : currentAcceptance;
|
|
11309
|
+
lines.push('');
|
|
11310
|
+
lines.push(head.requirement, '');
|
|
11311
|
+
lines.push(joinRow([
|
|
11312
|
+
...schema.requirementHeaders
|
|
11313
|
+
]));
|
|
11314
|
+
lines.push(docrender_separator(schema.requirementHeaders.length));
|
|
11315
|
+
lines.push('');
|
|
11316
|
+
lines.push(head.task, '');
|
|
11317
|
+
lines.push(joinRow([
|
|
11318
|
+
...schema.taskHeaders
|
|
11319
|
+
]));
|
|
11320
|
+
lines.push(docrender_separator(schema.taskHeaders.length));
|
|
11321
|
+
lines.push('');
|
|
11322
|
+
lines.push(head.detail, '');
|
|
11323
|
+
lines.push('');
|
|
11324
|
+
return lines;
|
|
11325
|
+
}
|
|
11326
|
+
function renderPlan(options) {
|
|
11327
|
+
const { schema, role, plan, existing, stamp, developer } = options;
|
|
10929
11328
|
const changes = [];
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
const
|
|
10933
|
-
const
|
|
10934
|
-
|
|
10935
|
-
];
|
|
10936
|
-
const
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
10940
|
-
|
|
10941
|
-
|
|
10942
|
-
|
|
10943
|
-
|
|
10944
|
-
|
|
10945
|
-
|
|
10946
|
-
|
|
10947
|
-
|
|
10948
|
-
|
|
10949
|
-
|
|
10950
|
-
|
|
10951
|
-
|
|
10952
|
-
|
|
10953
|
-
|
|
10954
|
-
|
|
10955
|
-
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
const previousProgress = requirementCells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.progress)] ?? '';
|
|
10959
|
-
requirementCells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.status)] = requirementStatus;
|
|
10960
|
-
requirementCells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.progress)] = String(progress);
|
|
10961
|
-
if (previousStatus !== requirementStatus || previousProgress !== String(progress)) requirementCells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.updatedAt)] = stamp;
|
|
10962
|
-
withDetail[requirementTarget.index] = joinRow(requirementCells);
|
|
10963
|
-
if (previousStatus !== requirementStatus) changes.push(`需求 ${target.requirementId} 开发状态:${previousStatus} → ${requirementStatus}`);
|
|
10964
|
-
if (previousProgress !== String(progress)) changes.push(`需求 ${target.requirementId} 开发进度:${previousProgress}% → ${progress}%`);
|
|
10965
|
-
return {
|
|
10966
|
-
lines: withDetail,
|
|
10967
|
-
changes
|
|
10968
|
-
};
|
|
10969
|
-
}
|
|
10970
|
-
function commit(context, lines, changes, message, iteration, developer, action, taskIds, options) {
|
|
10971
|
-
if (statSync(context.file).mtimeMs !== context.mtime) throw new errors_CliError('文件已被外部修改,请刷新后重试', errors_EXIT.INVALID);
|
|
10972
|
-
const output = lines.join('\n');
|
|
10973
|
-
if (output === context.original) return {
|
|
10974
|
-
ok: true,
|
|
10975
|
-
message: '状态未发生变化',
|
|
10976
|
-
changes: [],
|
|
10977
|
-
file: context.file
|
|
10978
|
-
};
|
|
10979
|
-
writeFileSync(context.file, output, 'utf8');
|
|
10980
|
-
const violation = validateAfterWrite(external_node_path_dirname(context.file), iteration, developer);
|
|
10981
|
-
if (null !== violation) {
|
|
10982
|
-
writeFileSync(context.file, context.original, 'utf8');
|
|
10983
|
-
throw new errors_CliError(`写入被校验器拒绝,已回滚:${violation}`, errors_EXIT.INVALID);
|
|
11329
|
+
const assigned = [];
|
|
11330
|
+
const existingRequirementIds = new Set(existing.requirements.map((item)=>item.id));
|
|
11331
|
+
const existingTaskNames = new Set(existing.tasks.map((item)=>`${item.requirementId}/${item.name}`));
|
|
11332
|
+
const counters = nextSequence(existing.tasks);
|
|
11333
|
+
const taskIdsByPlanName = new Map();
|
|
11334
|
+
const newTasks = [];
|
|
11335
|
+
for (const task of plan.tasks){
|
|
11336
|
+
const key = `${task.requirement}/${task.name}`;
|
|
11337
|
+
if (existingTaskNames.has(key)) {
|
|
11338
|
+
changes.push(`跳过已存在的任务:${task.requirement} ${task.name}`);
|
|
11339
|
+
continue;
|
|
11340
|
+
}
|
|
11341
|
+
const next = (counters.get(task.requirement) ?? 0) + 1;
|
|
11342
|
+
counters.set(task.requirement, next);
|
|
11343
|
+
const id = `${task.requirement}-T${next}`;
|
|
11344
|
+
const requirement = plan.requirements.find((item)=>item.code === task.requirement);
|
|
11345
|
+
if (void 0 !== requirement) {
|
|
11346
|
+
taskIdsByPlanName.set(task.name, id);
|
|
11347
|
+
newTasks.push({
|
|
11348
|
+
id,
|
|
11349
|
+
task,
|
|
11350
|
+
requirement
|
|
11351
|
+
});
|
|
11352
|
+
assigned.push({
|
|
11353
|
+
name: task.name,
|
|
11354
|
+
id
|
|
11355
|
+
});
|
|
11356
|
+
}
|
|
10984
11357
|
}
|
|
10985
|
-
|
|
10986
|
-
|
|
11358
|
+
const requirementRows = [];
|
|
11359
|
+
const requirementStatuses = new Map();
|
|
11360
|
+
for (const item of existing.tasks){
|
|
11361
|
+
const list = requirementStatuses.get(item.requirementId) ?? [];
|
|
11362
|
+
list.push(item.status);
|
|
11363
|
+
requirementStatuses.set(item.requirementId, list);
|
|
11364
|
+
}
|
|
11365
|
+
for (const entry of newTasks){
|
|
11366
|
+
const list = requirementStatuses.get(entry.task.requirement) ?? [];
|
|
11367
|
+
list.push(PENDING_STATUS);
|
|
11368
|
+
requirementStatuses.set(entry.task.requirement, list);
|
|
11369
|
+
}
|
|
11370
|
+
const newRequirementCodes = new Set();
|
|
11371
|
+
for (const requirement of plan.requirements){
|
|
11372
|
+
if (existingRequirementIds.has(requirement.code)) {
|
|
11373
|
+
changes.push(`跳过已存在的需求:${requirement.code} ${requirement.name}`);
|
|
11374
|
+
continue;
|
|
11375
|
+
}
|
|
11376
|
+
newRequirementCodes.add(requirement.code);
|
|
11377
|
+
const statuses = requirementStatuses.get(requirement.code) ?? [];
|
|
11378
|
+
const cells = [
|
|
11379
|
+
requirement.code,
|
|
11380
|
+
requirement.name,
|
|
11381
|
+
requirement.terminal,
|
|
11382
|
+
aggregateRequirementStatus(statuses),
|
|
11383
|
+
String(progressOf(statuses)),
|
|
11384
|
+
requirement.note ?? '',
|
|
11385
|
+
stamp
|
|
11386
|
+
];
|
|
11387
|
+
requirementRows.push(joinRow(cells));
|
|
11388
|
+
changes.push(`新增需求:${requirement.code} ${requirement.name}`);
|
|
11389
|
+
}
|
|
11390
|
+
const taskRows = newTasks.map(({ id, task })=>{
|
|
11391
|
+
const dependencies = (task.dependsOn ?? []).map((dependency)=>taskIdsByPlanName.get(dependency) ?? dependency).join(',');
|
|
11392
|
+
const cells = [
|
|
11393
|
+
id,
|
|
11394
|
+
task.requirement,
|
|
11395
|
+
task.name,
|
|
11396
|
+
task.type,
|
|
11397
|
+
task.scope,
|
|
11398
|
+
task.terminal,
|
|
11399
|
+
dependencies,
|
|
11400
|
+
PENDING_SELF_TEST,
|
|
11401
|
+
PENDING_ACCEPTANCE,
|
|
11402
|
+
PENDING_STATUS,
|
|
11403
|
+
stamp
|
|
11404
|
+
];
|
|
11405
|
+
changes.push(`新增任务:${id} ${task.name}`);
|
|
11406
|
+
return joinRow(cells);
|
|
11407
|
+
});
|
|
11408
|
+
const head = headings(schema);
|
|
11409
|
+
let lines = null === existing.lines ? buildSkeleton({
|
|
11410
|
+
schema,
|
|
11411
|
+
role,
|
|
11412
|
+
plan,
|
|
10987
11413
|
developer,
|
|
10988
|
-
|
|
10989
|
-
|
|
10990
|
-
|
|
11414
|
+
stamp
|
|
11415
|
+
}) : [
|
|
11416
|
+
...existing.lines
|
|
11417
|
+
];
|
|
11418
|
+
lines = appendTableRows({
|
|
11419
|
+
lines,
|
|
11420
|
+
sectionHeading: head.requirement,
|
|
11421
|
+
headers: schema.requirementHeaders,
|
|
11422
|
+
rows: requirementRows
|
|
10991
11423
|
});
|
|
10992
|
-
|
|
11424
|
+
lines = appendTableRows({
|
|
11425
|
+
lines,
|
|
11426
|
+
sectionHeading: head.task,
|
|
11427
|
+
headers: schema.taskHeaders,
|
|
11428
|
+
rows: taskRows
|
|
11429
|
+
});
|
|
11430
|
+
if (newTasks.length > 0) {
|
|
11431
|
+
const detailLines = newTasks.flatMap(({ id, task, requirement })=>renderDetail({
|
|
11432
|
+
schema,
|
|
11433
|
+
role,
|
|
11434
|
+
taskId: id,
|
|
11435
|
+
task,
|
|
11436
|
+
requirement
|
|
11437
|
+
}));
|
|
11438
|
+
while(lines.length > 0 && '' === (lines[lines.length - 1] ?? '').trim())lines.pop();
|
|
11439
|
+
lines.push('');
|
|
11440
|
+
lines.push(...detailLines);
|
|
11441
|
+
}
|
|
11442
|
+
while(lines.length > 0 && '' === (lines[lines.length - 1] ?? '').trim())lines.pop();
|
|
10993
11443
|
return {
|
|
10994
|
-
|
|
10995
|
-
message,
|
|
11444
|
+
markdown: lines.join('\n') + '\n',
|
|
10996
11445
|
changes,
|
|
10997
|
-
|
|
10998
|
-
git
|
|
11446
|
+
assigned
|
|
10999
11447
|
};
|
|
11000
11448
|
}
|
|
11001
|
-
|
|
11002
|
-
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
const context = loadDoc(options.docsRoot, options.iteration, options.developer);
|
|
11019
|
-
const result = computeUpdate(context.lines, options.taskId, options.action);
|
|
11020
|
-
return commit(context, result.lines, result.changes, `已执行「${ACTION_META[options.action].label}」`, safeSegment(options.iteration, '迭代目录'), safeSegment(options.developer, '开发者标识'), options.action, [
|
|
11021
|
-
options.taskId
|
|
11022
|
-
], {
|
|
11023
|
-
docsRoot: options.docsRoot,
|
|
11024
|
-
policy: options.policy,
|
|
11025
|
-
commitMessage: buildCommitMessage(options.iteration, options.action, [
|
|
11026
|
-
options.taskId
|
|
11027
|
-
], options.action)
|
|
11028
|
-
});
|
|
11029
|
-
}
|
|
11030
|
-
function validateAfterWrite(docsRoot, iteration, developer) {
|
|
11031
|
-
const script = external_node_path_join(docsRoot, "scripts", 'validate_task_doc.py');
|
|
11032
|
-
if (!external_node_fs_existsSync(script)) return null;
|
|
11033
|
-
for (const bin of [
|
|
11034
|
-
'python3',
|
|
11035
|
-
'python',
|
|
11036
|
-
'py'
|
|
11037
|
-
])try {
|
|
11038
|
-
const stdout = execFileSync(bin, [
|
|
11039
|
-
script,
|
|
11040
|
-
'--docs-root',
|
|
11041
|
-
docsRoot,
|
|
11042
|
-
'--iteration',
|
|
11043
|
-
iteration,
|
|
11044
|
-
'--developer',
|
|
11045
|
-
developer,
|
|
11046
|
-
'--format',
|
|
11047
|
-
'json'
|
|
11048
|
-
], {
|
|
11049
|
-
encoding: 'utf8',
|
|
11050
|
-
timeout: 15000,
|
|
11051
|
-
maxBuffer: 16777216
|
|
11052
|
-
});
|
|
11053
|
-
const payload = JSON.parse(stdout);
|
|
11054
|
-
const first = payload.errors?.[0];
|
|
11055
|
-
return first?.message ?? null;
|
|
11056
|
-
} catch (error) {
|
|
11057
|
-
const stdout = error.stdout ?? '';
|
|
11058
|
-
if (0 === stdout.trim().length) continue;
|
|
11059
|
-
try {
|
|
11060
|
-
const payload = JSON.parse(stdout);
|
|
11061
|
-
return payload.errors?.[0]?.message ?? '校验器未通过';
|
|
11062
|
-
} catch {
|
|
11063
|
-
break;
|
|
11064
|
-
}
|
|
11065
|
-
}
|
|
11066
|
-
return null;
|
|
11067
|
-
}
|
|
11068
|
-
function recalcRequirements(options) {
|
|
11069
|
-
const context = loadDoc(options.docsRoot, options.iteration, options.developer);
|
|
11070
|
-
const { rows: taskRows } = parseTaskRows(context.lines);
|
|
11071
|
-
const requirementParse = parseRequirementRows(context.lines);
|
|
11072
|
-
const lines = [
|
|
11073
|
-
...context.lines
|
|
11074
|
-
];
|
|
11075
|
-
const changes = [];
|
|
11076
|
-
for (const requirement of requirementParse.rows){
|
|
11077
|
-
const own = taskRows.filter((row)=>row.requirementId === requirement.id);
|
|
11078
|
-
const status = aggregateRequirementStatus(own.map((row)=>row.status));
|
|
11079
|
-
const completed = own.filter((row)=>'已完成' === row.status).length;
|
|
11080
|
-
const progress = 0 === own.length ? 0 : Math.round(completed / own.length * 100);
|
|
11081
|
-
const cells = [
|
|
11082
|
-
...requirement.cells
|
|
11083
|
-
];
|
|
11084
|
-
const previousStatus = cells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.status)] ?? '';
|
|
11085
|
-
const previousProgress = cells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.progress)] ?? '';
|
|
11086
|
-
if (previousStatus !== status || previousProgress !== String(progress)) {
|
|
11087
|
-
cells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.status)] = status;
|
|
11088
|
-
cells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.progress)] = String(progress);
|
|
11089
|
-
lines[requirement.index] = joinRow(cells);
|
|
11090
|
-
if (previousStatus !== status) changes.push(`${requirement.id} 开发状态:${previousStatus} → ${status}`);
|
|
11091
|
-
if (previousProgress !== String(progress)) changes.push(`${requirement.id} 开发进度:${previousProgress}% → ${progress}%`);
|
|
11092
|
-
}
|
|
11093
|
-
}
|
|
11094
|
-
if (true === options.dryRun || 0 === changes.length) return {
|
|
11095
|
-
changes,
|
|
11096
|
-
file: context.file
|
|
11097
|
-
};
|
|
11098
|
-
return {
|
|
11099
|
-
changes,
|
|
11100
|
-
file: commit(context, lines, changes, `已重算 ${requirementParse.rows.length} 个需求的状态与进度`, safeSegment(options.iteration, '迭代目录'), safeSegment(options.developer, '开发者标识'), 'start', [], {
|
|
11101
|
-
docsRoot: options.docsRoot,
|
|
11102
|
-
policy: {
|
|
11103
|
-
commit: false,
|
|
11104
|
-
push: false
|
|
11105
|
-
},
|
|
11106
|
-
commitMessage: `docs(${options.iteration}): 重算需求状态与进度`
|
|
11107
|
-
}).file
|
|
11108
|
-
};
|
|
11109
|
-
}
|
|
11110
|
-
function availableActions(options) {
|
|
11111
|
-
const iteration = safeSegment(options.iteration, '迭代目录');
|
|
11112
|
-
const developer = safeSegment(options.developer, '开发者标识');
|
|
11113
|
-
const file = external_node_path_join(options.docsRoot, iteration, `${developer}.md`);
|
|
11114
|
-
if (!external_node_fs_existsSync(file)) return {};
|
|
11115
|
-
const lines = readFileSync(file, 'utf8').split('\n');
|
|
11116
|
-
const { rows } = parseTaskRows(lines);
|
|
11117
|
-
const result = {};
|
|
11118
|
-
for (const row of rows){
|
|
11119
|
-
const list = [];
|
|
11120
|
-
if ('未开始' === row.status) list.push({
|
|
11121
|
-
action: 'start',
|
|
11122
|
-
enabled: true,
|
|
11123
|
-
reason: ''
|
|
11124
|
-
});
|
|
11125
|
-
if ('进行中' === row.status) {
|
|
11126
|
-
const ok = canSubmit(row.selfTest);
|
|
11127
|
-
list.push({
|
|
11128
|
-
action: 'submit',
|
|
11129
|
-
enabled: ok,
|
|
11130
|
-
reason: ok ? '' : `AI 自测为「${row.selfTest}」,需先通过自测`
|
|
11131
|
-
});
|
|
11132
|
-
}
|
|
11133
|
-
if ('待验收' === row.status) {
|
|
11134
|
-
list.push({
|
|
11135
|
-
action: 'accept',
|
|
11136
|
-
enabled: true,
|
|
11137
|
-
reason: ''
|
|
11138
|
-
});
|
|
11139
|
-
list.push({
|
|
11140
|
-
action: 'reject',
|
|
11141
|
-
enabled: true,
|
|
11142
|
-
reason: ''
|
|
11143
|
-
});
|
|
11144
|
-
}
|
|
11145
|
-
result[row.taskId] = list;
|
|
11146
|
-
}
|
|
11147
|
-
return result;
|
|
11148
|
-
}
|
|
11149
|
-
const RESERVED_FILES = new Set([
|
|
11150
|
-
'README.md',
|
|
11151
|
-
'AGENTS.md',
|
|
11152
|
-
'CLAUDE.md'
|
|
11153
|
-
]);
|
|
11154
|
-
const RESERVED_PREFIXES = [
|
|
11155
|
-
'skills/',
|
|
11156
|
-
"scripts/",
|
|
11157
|
-
'_prd/'
|
|
11158
|
-
];
|
|
11159
|
-
const git_SAFE_SEGMENT = /^[A-Za-z0-9._\-\u4e00-\u9fa5]+$/;
|
|
11160
|
-
function git_git(docsRoot, args, timeoutMs = 15000) {
|
|
11161
|
-
return execFileSync('git', [
|
|
11162
|
-
'-C',
|
|
11163
|
-
docsRoot,
|
|
11164
|
-
...args
|
|
11449
|
+
const RESERVED_FILES = new Set([
|
|
11450
|
+
'README.md',
|
|
11451
|
+
'AGENTS.md',
|
|
11452
|
+
'CLAUDE.md'
|
|
11453
|
+
]);
|
|
11454
|
+
const RESERVED_PREFIXES = [
|
|
11455
|
+
'skills/',
|
|
11456
|
+
"scripts/",
|
|
11457
|
+
'docs/',
|
|
11458
|
+
'_prd/'
|
|
11459
|
+
];
|
|
11460
|
+
const SAFE_SEGMENT = /^[A-Za-z0-9._\-\u4e00-\u9fa5]+$/;
|
|
11461
|
+
function git_git(docsRoot, args, timeoutMs = 15000) {
|
|
11462
|
+
return execFileSync('git', [
|
|
11463
|
+
'-C',
|
|
11464
|
+
docsRoot,
|
|
11465
|
+
...args
|
|
11165
11466
|
], {
|
|
11166
11467
|
encoding: 'utf8',
|
|
11167
11468
|
timeout: timeoutMs,
|
|
@@ -11180,9 +11481,9 @@ function tryGit(docsRoot, args, timeoutMs) {
|
|
|
11180
11481
|
return null;
|
|
11181
11482
|
}
|
|
11182
11483
|
}
|
|
11183
|
-
function
|
|
11484
|
+
function safeSegment(value, label) {
|
|
11184
11485
|
const trimmed = value.trim();
|
|
11185
|
-
if (!
|
|
11486
|
+
if (!SAFE_SEGMENT.test(trimmed) || '.' === trimmed || '..' === trimmed) throw new errors_CliError(`${label} 不合法:${value}`, errors_EXIT.USAGE);
|
|
11186
11487
|
return trimmed;
|
|
11187
11488
|
}
|
|
11188
11489
|
function getGitStatus(docsRoot) {
|
|
@@ -11413,8 +11714,8 @@ function materializeRemote(docsRoot, ref) {
|
|
|
11413
11714
|
return dir;
|
|
11414
11715
|
}
|
|
11415
11716
|
function exportRemoteDoc(docsRoot, ref, iteration, developer) {
|
|
11416
|
-
const safeIteration =
|
|
11417
|
-
const safeDeveloper =
|
|
11717
|
+
const safeIteration = safeSegment(iteration, '迭代目录');
|
|
11718
|
+
const safeDeveloper = safeSegment(developer, '开发者标识');
|
|
11418
11719
|
const relative = `${safeIteration}/${safeDeveloper}.md`;
|
|
11419
11720
|
const markdown = gitShow(docsRoot, ref.sha, relative);
|
|
11420
11721
|
if (null === markdown) throw new errors_CliError(`远程快照中不存在该文档:${relative}`, errors_EXIT.NOT_FOUND);
|
|
@@ -11429,6 +11730,11 @@ function exportRemoteDoc(docsRoot, ref, iteration, developer) {
|
|
|
11429
11730
|
const script = gitShow(docsRoot, ref.sha, "scripts/validate_task_doc.py");
|
|
11430
11731
|
if (null !== script) writeFileSync(scriptPath, script, 'utf8');
|
|
11431
11732
|
}
|
|
11733
|
+
const schemaPath = external_node_path_join(dir, 'schema.json');
|
|
11734
|
+
if (!external_node_fs_existsSync(schemaPath)) {
|
|
11735
|
+
const schemaText = gitShow(docsRoot, ref.sha, 'schema.json');
|
|
11736
|
+
if (null !== schemaText) writeFileSync(schemaPath, schemaText, 'utf8');
|
|
11737
|
+
}
|
|
11432
11738
|
return {
|
|
11433
11739
|
dir,
|
|
11434
11740
|
markdown,
|
|
@@ -11466,6 +11772,7 @@ const RESERVED_DIRS = new Set([
|
|
|
11466
11772
|
'_prd',
|
|
11467
11773
|
"scripts",
|
|
11468
11774
|
'skills',
|
|
11775
|
+
'docs',
|
|
11469
11776
|
'node_modules',
|
|
11470
11777
|
'.git',
|
|
11471
11778
|
'.idea',
|
|
@@ -11633,6 +11940,7 @@ function coerceTask(value) {
|
|
|
11633
11940
|
requirementId: 'string' == typeof value['requirementId'] ? value['requirementId'] : '',
|
|
11634
11941
|
name: 'string' == typeof value['name'] ? value['name'] : '',
|
|
11635
11942
|
type: 'string' == typeof value['type'] ? value['type'] : '',
|
|
11943
|
+
scope: 'string' == typeof value['scope'] ? value['scope'] : '',
|
|
11636
11944
|
terminal: 'string' == typeof value['terminal'] ? value['terminal'] : '',
|
|
11637
11945
|
dependencies: isStringArray(value['dependencies']) ? value['dependencies'] : [],
|
|
11638
11946
|
selfTest: 'string' == typeof value['selfTest'] ? value['selfTest'] : '',
|
|
@@ -11691,316 +11999,1398 @@ function runValidator(input) {
|
|
|
11691
11999
|
'python',
|
|
11692
12000
|
'py'
|
|
11693
12001
|
])try {
|
|
11694
|
-
const stdout = execFileSync(bin, args, {
|
|
12002
|
+
const stdout = execFileSync(bin, args, {
|
|
12003
|
+
encoding: 'utf8',
|
|
12004
|
+
timeout: 10000,
|
|
12005
|
+
maxBuffer: 16777216
|
|
12006
|
+
});
|
|
12007
|
+
const parsed = coercePayload(JSON.parse(stdout));
|
|
12008
|
+
if (null !== parsed) return parsed;
|
|
12009
|
+
} catch (error) {
|
|
12010
|
+
const stdout = error.stdout;
|
|
12011
|
+
if ('string' == typeof stdout && stdout.trim().length > 0) try {
|
|
12012
|
+
const parsed = coercePayload(JSON.parse(stdout));
|
|
12013
|
+
if (null !== parsed) return parsed;
|
|
12014
|
+
} catch {}
|
|
12015
|
+
}
|
|
12016
|
+
return null;
|
|
12017
|
+
}
|
|
12018
|
+
function extractSection(markdown, heading) {
|
|
12019
|
+
const lines = markdown.split(/\r?\n/);
|
|
12020
|
+
let start = -1;
|
|
12021
|
+
for(let index = 0; index < lines.length; index += 1)if ((lines[index] ?? '').trim() === heading) {
|
|
12022
|
+
start = index + 1;
|
|
12023
|
+
break;
|
|
12024
|
+
}
|
|
12025
|
+
if (start < 0) return '';
|
|
12026
|
+
const collected = [];
|
|
12027
|
+
for(let index = start; index < lines.length; index += 1){
|
|
12028
|
+
const line = lines[index] ?? '';
|
|
12029
|
+
if (/^##\s+/.test(line)) break;
|
|
12030
|
+
collected.push(line);
|
|
12031
|
+
}
|
|
12032
|
+
return collected.join('\n').trim();
|
|
12033
|
+
}
|
|
12034
|
+
function splitDetails(markdown) {
|
|
12035
|
+
const section = extractSection(markdown, '## 四、任务详情');
|
|
12036
|
+
if (0 === section.length) return [];
|
|
12037
|
+
const blocks = [];
|
|
12038
|
+
const parts = section.split(/^###\s+/m).slice(1);
|
|
12039
|
+
for (const part of parts){
|
|
12040
|
+
const [firstLine, ...rest] = part.split(/\r?\n/);
|
|
12041
|
+
const heading = (firstLine ?? '').trim();
|
|
12042
|
+
const match = /^\[?([#\w\-\u4e00-\u9fa5]+)\]?\s*(.*)$/.exec(heading);
|
|
12043
|
+
const id = match?.[1] ?? heading;
|
|
12044
|
+
const name = match?.[2]?.trim() ?? '';
|
|
12045
|
+
blocks.push({
|
|
12046
|
+
id,
|
|
12047
|
+
name,
|
|
12048
|
+
markdown: rest.join('\n').trim()
|
|
12049
|
+
});
|
|
12050
|
+
}
|
|
12051
|
+
return blocks;
|
|
12052
|
+
}
|
|
12053
|
+
function parseMarkdownDoc(markdown, schema) {
|
|
12054
|
+
const structureErrors = [];
|
|
12055
|
+
const readTable = (sectionHeading, required)=>{
|
|
12056
|
+
const section = extractSection(markdown, sectionHeading);
|
|
12057
|
+
const rows = section.split(/\r?\n/).map((line)=>line.trim()).filter((line)=>line.startsWith('|')).map((line)=>line.replace(/^\|/, '').replace(/\|$/, '').split('|').map((cell)=>cell.trim())).filter((cells)=>!cells.every((cell)=>/^:?-{2,}:?$/.test(cell) || 0 === cell.length));
|
|
12058
|
+
const [header, ...body] = rows;
|
|
12059
|
+
if (void 0 === header) return {
|
|
12060
|
+
records: [],
|
|
12061
|
+
missing: [
|
|
12062
|
+
...required
|
|
12063
|
+
]
|
|
12064
|
+
};
|
|
12065
|
+
const missing = required.filter((name)=>!header.includes(name));
|
|
12066
|
+
if (missing.length > 0) return {
|
|
12067
|
+
records: [],
|
|
12068
|
+
missing
|
|
12069
|
+
};
|
|
12070
|
+
const records = body.map((cells)=>{
|
|
12071
|
+
const record = {};
|
|
12072
|
+
header.forEach((name, index)=>{
|
|
12073
|
+
record[name] = cells[index] ?? '';
|
|
12074
|
+
});
|
|
12075
|
+
return record;
|
|
12076
|
+
});
|
|
12077
|
+
return {
|
|
12078
|
+
records,
|
|
12079
|
+
missing: []
|
|
12080
|
+
};
|
|
12081
|
+
};
|
|
12082
|
+
const heading = (index, fallback)=>`## ${schema.sections[index] ?? fallback}`;
|
|
12083
|
+
const requirementRead = readTable(heading(1, '二、需求清单'), schema.requirementHeaders);
|
|
12084
|
+
const taskRead = readTable(heading(2, '三、任务清单'), schema.taskHeaders);
|
|
12085
|
+
if (requirementRead.missing.length > 0) structureErrors.push({
|
|
12086
|
+
level: 'error',
|
|
12087
|
+
code: 'REQUIREMENT_TABLE_MISMATCH',
|
|
12088
|
+
message: `需求清单表头缺少列:${requirementRead.missing.join('、')},请按最新模板补齐`
|
|
12089
|
+
});
|
|
12090
|
+
if (taskRead.missing.length > 0) structureErrors.push({
|
|
12091
|
+
level: 'error',
|
|
12092
|
+
code: 'TASK_TABLE_MISMATCH',
|
|
12093
|
+
message: `任务清单表头缺少列:${taskRead.missing.join('、')},请按最新模板补齐`
|
|
12094
|
+
});
|
|
12095
|
+
const rk = schema.requirementKeys;
|
|
12096
|
+
const at = (record, keys, semantic)=>record[keys[semantic] ?? ''] ?? '';
|
|
12097
|
+
const requirements = requirementRead.records.map((record)=>({
|
|
12098
|
+
id: at(record, rk, 'id'),
|
|
12099
|
+
title: at(record, rk, 'title'),
|
|
12100
|
+
terminal: at(record, rk, 'terminal'),
|
|
12101
|
+
status: at(record, rk, 'status'),
|
|
12102
|
+
progress: at(record, rk, 'progress'),
|
|
12103
|
+
note: at(record, rk, 'note'),
|
|
12104
|
+
updatedAt: at(record, rk, 'updatedAt'),
|
|
12105
|
+
taskIds: []
|
|
12106
|
+
}));
|
|
12107
|
+
const tk = schema.taskKeys;
|
|
12108
|
+
const tasks = taskRead.records.map((record)=>({
|
|
12109
|
+
id: at(record, tk, 'id'),
|
|
12110
|
+
requirementId: at(record, tk, 'requirement'),
|
|
12111
|
+
name: at(record, tk, 'name'),
|
|
12112
|
+
type: at(record, tk, 'type'),
|
|
12113
|
+
scope: at(record, tk, 'scope'),
|
|
12114
|
+
terminal: at(record, tk, 'terminal'),
|
|
12115
|
+
dependencies: at(record, tk, 'dependencies').split(/[,,]/).map((item)=>item.trim()).filter((item)=>item.length > 0),
|
|
12116
|
+
selfTest: at(record, tk, 'selfTest'),
|
|
12117
|
+
acceptance: at(record, tk, 'acceptance'),
|
|
12118
|
+
status: at(record, tk, 'status'),
|
|
12119
|
+
updatedAt: at(record, tk, 'updatedAt')
|
|
12120
|
+
}));
|
|
12121
|
+
for (const requirement of requirements)requirement.taskIds = tasks.filter((task)=>task.requirementId === requirement.id).map((task)=>task.id);
|
|
12122
|
+
const details = splitDetails(markdown);
|
|
12123
|
+
const iterationInfo = {};
|
|
12124
|
+
for (const field of schema.iterationFields){
|
|
12125
|
+
const matched = new RegExp(`\\|\\s*${escapeRegExp(field)}\\s*\\|\\s*([^|]*)\\|`).exec(markdown);
|
|
12126
|
+
const value = matched?.[1]?.trim();
|
|
12127
|
+
if (void 0 !== value && value.length > 0) iterationInfo[field] = value;
|
|
12128
|
+
}
|
|
12129
|
+
return {
|
|
12130
|
+
valid: false,
|
|
12131
|
+
iterationInfo,
|
|
12132
|
+
stats: {
|
|
12133
|
+
requirements: requirements.length,
|
|
12134
|
+
tasks: tasks.length,
|
|
12135
|
+
completedTasks: tasks.filter((task)=>'已完成' === task.status).length,
|
|
12136
|
+
details: details.length
|
|
12137
|
+
},
|
|
12138
|
+
requirements,
|
|
12139
|
+
tasks,
|
|
12140
|
+
errors: structureErrors,
|
|
12141
|
+
warnings: []
|
|
12142
|
+
};
|
|
12143
|
+
}
|
|
12144
|
+
function readMarkdown(target) {
|
|
12145
|
+
return readFileSync(target, 'utf8');
|
|
12146
|
+
}
|
|
12147
|
+
function readIterationDoc(docsRoot, iteration, developer, source = 'local', presetRef, refName) {
|
|
12148
|
+
const safeIteration = iterations_safeSegment(iteration, '迭代目录');
|
|
12149
|
+
const safeDeveloper = iterations_safeSegment(developer, '开发者标识');
|
|
12150
|
+
if ('remote' === source) {
|
|
12151
|
+
const ref = presetRef ?? resolveRemoteRef(docsRoot, refName);
|
|
12152
|
+
const exported = exportRemoteDoc(docsRoot, ref, safeIteration, safeDeveloper);
|
|
12153
|
+
const roleInferred = inferRole(exported.markdown);
|
|
12154
|
+
const scripted = runValidator({
|
|
12155
|
+
docsRoot: exported.dir,
|
|
12156
|
+
scriptPath: exported.scriptPath,
|
|
12157
|
+
iteration: safeIteration,
|
|
12158
|
+
developer: safeDeveloper,
|
|
12159
|
+
role: roleInferred
|
|
12160
|
+
});
|
|
12161
|
+
return {
|
|
12162
|
+
iteration: safeIteration,
|
|
12163
|
+
developer: safeDeveloper,
|
|
12164
|
+
file: `${safeIteration}/${safeDeveloper}.md`,
|
|
12165
|
+
mtime: exported.mtime,
|
|
12166
|
+
roleInferred,
|
|
12167
|
+
parser: null === scripted ? 'fallback' : "script",
|
|
12168
|
+
source: 'remote',
|
|
12169
|
+
ref: {
|
|
12170
|
+
name: ref.ref,
|
|
12171
|
+
sha: ref.sha
|
|
12172
|
+
},
|
|
12173
|
+
validation: scripted ?? parseMarkdownDoc(exported.markdown, loadDocSchema(exported.dir)),
|
|
12174
|
+
details: splitDetails(exported.markdown)
|
|
12175
|
+
};
|
|
12176
|
+
}
|
|
12177
|
+
const directory = joinWithin(docsRoot, safeIteration);
|
|
12178
|
+
if (!external_node_fs_existsSync(directory)) throw new errors_CliError(`迭代目录不存在:${safeIteration}`, errors_EXIT.NOT_FOUND);
|
|
12179
|
+
const file = joinWithin(directory, `${safeDeveloper}.md`);
|
|
12180
|
+
if (!external_node_fs_existsSync(file)) throw new errors_CliError(`文档不存在:${safeIteration}/${safeDeveloper}.md`, errors_EXIT.NOT_FOUND);
|
|
12181
|
+
const markdown = readMarkdown(file);
|
|
12182
|
+
const roleInferred = inferRole(markdown);
|
|
12183
|
+
const scripted = runValidator({
|
|
12184
|
+
docsRoot,
|
|
12185
|
+
scriptPath: external_node_path_join(docsRoot, "scripts", 'validate_task_doc.py'),
|
|
12186
|
+
iteration: safeIteration,
|
|
12187
|
+
developer: safeDeveloper,
|
|
12188
|
+
role: roleInferred
|
|
12189
|
+
});
|
|
12190
|
+
const validation = scripted ?? parseMarkdownDoc(markdown, loadDocSchema(docsRoot));
|
|
12191
|
+
const parser = null === scripted ? 'fallback' : "script";
|
|
12192
|
+
return {
|
|
12193
|
+
iteration: safeIteration,
|
|
12194
|
+
developer: safeDeveloper,
|
|
12195
|
+
file,
|
|
12196
|
+
mtime: statSync(file).mtime.toISOString(),
|
|
12197
|
+
roleInferred,
|
|
12198
|
+
parser,
|
|
12199
|
+
source: 'local',
|
|
12200
|
+
ref: null,
|
|
12201
|
+
validation,
|
|
12202
|
+
details: splitDetails(markdown)
|
|
12203
|
+
};
|
|
12204
|
+
}
|
|
12205
|
+
function readIterationSummary(docsRoot, iteration, source = 'local', refName) {
|
|
12206
|
+
const safeIteration = iterations_safeSegment(iteration, '迭代目录');
|
|
12207
|
+
const remoteRef = 'remote' === source ? resolveRemoteRef(docsRoot, refName) : null;
|
|
12208
|
+
let developers;
|
|
12209
|
+
if (null === remoteRef) {
|
|
12210
|
+
const directory = joinWithin(docsRoot, safeIteration);
|
|
12211
|
+
if (!external_node_fs_existsSync(directory)) throw new errors_CliError(`迭代目录不存在:${safeIteration}`, errors_EXIT.NOT_FOUND);
|
|
12212
|
+
developers = listMarkdownFiles(directory);
|
|
12213
|
+
} else {
|
|
12214
|
+
const snapshot = listRemoteIterations(docsRoot, remoteRef);
|
|
12215
|
+
const found = snapshot.iterations.find((item)=>item.name === safeIteration);
|
|
12216
|
+
if (void 0 === found) throw new errors_CliError(`远程快照中不存在迭代:${safeIteration}`, errors_EXIT.NOT_FOUND);
|
|
12217
|
+
developers = found.developers;
|
|
12218
|
+
}
|
|
12219
|
+
const summaries = [];
|
|
12220
|
+
const blocked = [];
|
|
12221
|
+
for (const entry of developers){
|
|
12222
|
+
const doc = readIterationDoc(docsRoot, safeIteration, entry.id, source, remoteRef ?? void 0);
|
|
12223
|
+
const statusCounts = {};
|
|
12224
|
+
const selfTestCounts = {};
|
|
12225
|
+
const acceptanceCounts = {};
|
|
12226
|
+
for (const task of doc.validation.tasks){
|
|
12227
|
+
bump(statusCounts, 0 === task.status.length ? '未知' : task.status);
|
|
12228
|
+
bump(selfTestCounts, normalizeSelfTest(task.selfTest));
|
|
12229
|
+
bump(acceptanceCounts, normalizeAcceptance(task.acceptance));
|
|
12230
|
+
}
|
|
12231
|
+
const byId = new Map(doc.validation.tasks.map((task)=>[
|
|
12232
|
+
task.id,
|
|
12233
|
+
task
|
|
12234
|
+
]));
|
|
12235
|
+
for (const task of doc.validation.tasks){
|
|
12236
|
+
if ('已完成' === task.status) continue;
|
|
12237
|
+
const blocking = task.dependencies.map((dep)=>{
|
|
12238
|
+
const target = byId.get(dep);
|
|
12239
|
+
return void 0 === target ? null : {
|
|
12240
|
+
id: dep,
|
|
12241
|
+
status: target.status
|
|
12242
|
+
};
|
|
12243
|
+
}).filter((item)=>null !== item && '已完成' !== item.status);
|
|
12244
|
+
if (blocking.length > 0) blocked.push({
|
|
12245
|
+
developer: entry.id,
|
|
12246
|
+
taskId: task.id,
|
|
12247
|
+
name: task.name,
|
|
12248
|
+
dependencies: task.dependencies,
|
|
12249
|
+
blocking
|
|
12250
|
+
});
|
|
12251
|
+
}
|
|
12252
|
+
const requirementStatusCounts = {};
|
|
12253
|
+
for (const requirement of doc.validation.requirements)bump(requirementStatusCounts, 0 === requirement.status.length ? '未知' : requirement.status);
|
|
12254
|
+
summaries.push({
|
|
12255
|
+
id: entry.id,
|
|
12256
|
+
roleInferred: doc.roleInferred,
|
|
12257
|
+
parser: doc.parser,
|
|
12258
|
+
stats: doc.validation.stats,
|
|
12259
|
+
statusCounts,
|
|
12260
|
+
requirementStatusCounts,
|
|
12261
|
+
selfTestCounts,
|
|
12262
|
+
acceptanceCounts,
|
|
12263
|
+
errors: doc.validation.errors.length,
|
|
12264
|
+
warnings: doc.validation.warnings.length,
|
|
12265
|
+
mtime: doc.mtime
|
|
12266
|
+
});
|
|
12267
|
+
}
|
|
12268
|
+
const mergeCounts = (pick)=>{
|
|
12269
|
+
const merged = {};
|
|
12270
|
+
for (const item of summaries)for (const [status, count] of Object.entries(pick(item)))merged[status] = (merged[status] ?? 0) + count;
|
|
12271
|
+
return merged;
|
|
12272
|
+
};
|
|
12273
|
+
const totals = summaries.reduce((acc, item)=>({
|
|
12274
|
+
developers: acc.developers + 1,
|
|
12275
|
+
requirements: acc.requirements + item.stats.requirements,
|
|
12276
|
+
tasks: acc.tasks + item.stats.tasks,
|
|
12277
|
+
completedTasks: acc.completedTasks + item.stats.completedTasks,
|
|
12278
|
+
errors: acc.errors + item.errors,
|
|
12279
|
+
warnings: acc.warnings + item.warnings
|
|
12280
|
+
}), {
|
|
12281
|
+
developers: 0,
|
|
12282
|
+
requirements: 0,
|
|
12283
|
+
tasks: 0,
|
|
12284
|
+
completedTasks: 0,
|
|
12285
|
+
errors: 0,
|
|
12286
|
+
warnings: 0
|
|
12287
|
+
});
|
|
12288
|
+
return {
|
|
12289
|
+
iteration: safeIteration,
|
|
12290
|
+
docsRoot,
|
|
12291
|
+
source,
|
|
12292
|
+
ref: null === remoteRef ? null : {
|
|
12293
|
+
name: remoteRef.ref,
|
|
12294
|
+
sha: remoteRef.sha,
|
|
12295
|
+
committedAt: remoteRef.committedAt
|
|
12296
|
+
},
|
|
12297
|
+
totals: {
|
|
12298
|
+
...totals,
|
|
12299
|
+
progress: 0 === totals.tasks ? 0 : Math.round(totals.completedTasks / totals.tasks * 100),
|
|
12300
|
+
taskStatusCounts: mergeCounts((item)=>item.statusCounts),
|
|
12301
|
+
requirementStatusCounts: mergeCounts((item)=>item.requirementStatusCounts),
|
|
12302
|
+
selfTestCounts: mergeCounts((item)=>item.selfTestCounts),
|
|
12303
|
+
acceptanceCounts: mergeCounts((item)=>item.acceptanceCounts)
|
|
12304
|
+
},
|
|
12305
|
+
developers: summaries,
|
|
12306
|
+
blocked
|
|
12307
|
+
};
|
|
12308
|
+
}
|
|
12309
|
+
function checkDocTaskSides(options) {
|
|
12310
|
+
const file = external_node_path_join(options.docsRoot, options.iteration, `${options.developer}.md`);
|
|
12311
|
+
if (!external_node_fs_existsSync(file)) throw new errors_CliError(`文档不存在:${options.iteration}/${options.developer}.md`, errors_EXIT.NOT_FOUND);
|
|
12312
|
+
const markdown = readFileSync(file, 'utf8');
|
|
12313
|
+
const schema = loadDocSchema(options.docsRoot);
|
|
12314
|
+
const payload = parseMarkdownDoc(markdown, schema);
|
|
12315
|
+
return validateTaskSides({
|
|
12316
|
+
index: buildRepoSideIndex(options.terminals),
|
|
12317
|
+
tasks: payload.tasks.map((task)=>({
|
|
12318
|
+
id: task.id,
|
|
12319
|
+
scope: task.scope,
|
|
12320
|
+
terminal: task.terminal
|
|
12321
|
+
}))
|
|
12322
|
+
});
|
|
12323
|
+
}
|
|
12324
|
+
const taskdoc_SAFE_SEGMENT = /^[A-Za-z0-9._\-\u4e00-\u9fa5]+$/;
|
|
12325
|
+
function taskdoc_safeSegment(value, label) {
|
|
12326
|
+
const trimmed = value.trim();
|
|
12327
|
+
if (!taskdoc_SAFE_SEGMENT.test(trimmed) || '.' === trimmed || '..' === trimmed) throw new errors_CliError(`${label} 不合法:${value}`, errors_EXIT.USAGE);
|
|
12328
|
+
return trimmed;
|
|
12329
|
+
}
|
|
12330
|
+
function buildCommitMessage(iteration, action, taskIds, _action) {
|
|
12331
|
+
const meta = ACTION_META[action];
|
|
12332
|
+
return `docs(${iteration}): ${meta.label} ${taskIds.join(',')}(${meta.from}→${meta.to})`;
|
|
12333
|
+
}
|
|
12334
|
+
function nowStamp() {
|
|
12335
|
+
const now = new Date();
|
|
12336
|
+
const pad = (value)=>String(value).padStart(2, '0');
|
|
12337
|
+
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`;
|
|
12338
|
+
}
|
|
12339
|
+
const ACTION_META = {
|
|
12340
|
+
start: {
|
|
12341
|
+
label: '开始实施',
|
|
12342
|
+
from: '未开始',
|
|
12343
|
+
to: '进行中'
|
|
12344
|
+
},
|
|
12345
|
+
submit: {
|
|
12346
|
+
label: '提交验收',
|
|
12347
|
+
from: '进行中',
|
|
12348
|
+
to: '待验收'
|
|
12349
|
+
},
|
|
12350
|
+
accept: {
|
|
12351
|
+
label: '验收通过',
|
|
12352
|
+
from: '待验收',
|
|
12353
|
+
to: '已完成'
|
|
12354
|
+
},
|
|
12355
|
+
reject: {
|
|
12356
|
+
label: '验收驳回',
|
|
12357
|
+
from: '待验收',
|
|
12358
|
+
to: '进行中'
|
|
12359
|
+
}
|
|
12360
|
+
};
|
|
12361
|
+
function commitInDocsRepo(docsRoot, file, message, push) {
|
|
12362
|
+
const run = (args)=>{
|
|
12363
|
+
try {
|
|
12364
|
+
const output = execFileSync('git', args, {
|
|
12365
|
+
cwd: docsRoot,
|
|
12366
|
+
encoding: 'utf8',
|
|
12367
|
+
stdio: [
|
|
12368
|
+
'ignore',
|
|
12369
|
+
'pipe',
|
|
12370
|
+
'pipe'
|
|
12371
|
+
]
|
|
12372
|
+
});
|
|
12373
|
+
return {
|
|
12374
|
+
ok: true,
|
|
12375
|
+
output
|
|
12376
|
+
};
|
|
12377
|
+
} catch (error) {
|
|
12378
|
+
const stderr = error.stderr ?? '';
|
|
12379
|
+
return {
|
|
12380
|
+
ok: false,
|
|
12381
|
+
output: stderr.trim() || String(error)
|
|
12382
|
+
};
|
|
12383
|
+
}
|
|
12384
|
+
};
|
|
12385
|
+
const inside = run([
|
|
12386
|
+
'rev-parse',
|
|
12387
|
+
'--is-inside-work-tree'
|
|
12388
|
+
]);
|
|
12389
|
+
if (!inside.ok || 'true' !== inside.output.trim()) return {
|
|
12390
|
+
committed: false,
|
|
12391
|
+
pushed: false,
|
|
12392
|
+
message: '文档仓库不是 git 仓库,已跳过提交'
|
|
12393
|
+
};
|
|
12394
|
+
let realRoot = docsRoot;
|
|
12395
|
+
try {
|
|
12396
|
+
realRoot = realpathSync(docsRoot);
|
|
12397
|
+
} catch {}
|
|
12398
|
+
const targets = Array.isArray(file) ? file : [
|
|
12399
|
+
file
|
|
12400
|
+
];
|
|
12401
|
+
const relativePaths = [];
|
|
12402
|
+
for (const item of targets){
|
|
12403
|
+
let realFile = item;
|
|
12404
|
+
try {
|
|
12405
|
+
realFile = realpathSync(item);
|
|
12406
|
+
} catch {}
|
|
12407
|
+
const relativePath = external_node_path_relative(realRoot, realFile);
|
|
12408
|
+
if (relativePath.startsWith('..') || isAbsolute(relativePath)) return {
|
|
12409
|
+
committed: false,
|
|
12410
|
+
pushed: false,
|
|
12411
|
+
message: '目标文件不在文档仓库内,已跳过提交'
|
|
12412
|
+
};
|
|
12413
|
+
relativePaths.push(relativePath);
|
|
12414
|
+
}
|
|
12415
|
+
const added = run([
|
|
12416
|
+
'add',
|
|
12417
|
+
'--',
|
|
12418
|
+
...relativePaths
|
|
12419
|
+
]);
|
|
12420
|
+
if (!added.ok) return {
|
|
12421
|
+
committed: false,
|
|
12422
|
+
pushed: false,
|
|
12423
|
+
message: `git add 失败:${added.output.split('\n')[0] ?? ''}`
|
|
12424
|
+
};
|
|
12425
|
+
const committed = run([
|
|
12426
|
+
'commit',
|
|
12427
|
+
'-m',
|
|
12428
|
+
message,
|
|
12429
|
+
'--',
|
|
12430
|
+
...relativePaths
|
|
12431
|
+
]);
|
|
12432
|
+
if (!committed.ok) {
|
|
12433
|
+
const firstLine = committed.output.split('\n')[0] ?? '';
|
|
12434
|
+
return {
|
|
12435
|
+
committed: false,
|
|
12436
|
+
pushed: false,
|
|
12437
|
+
message: `提交未完成:${firstLine}`
|
|
12438
|
+
};
|
|
12439
|
+
}
|
|
12440
|
+
if (!push) return {
|
|
12441
|
+
committed: true,
|
|
12442
|
+
pushed: false,
|
|
12443
|
+
message: '已提交(未推送)'
|
|
12444
|
+
};
|
|
12445
|
+
const pushed = run([
|
|
12446
|
+
'push'
|
|
12447
|
+
]);
|
|
12448
|
+
if (!pushed.ok) return {
|
|
12449
|
+
committed: true,
|
|
12450
|
+
pushed: false,
|
|
12451
|
+
message: `已提交但推送失败,请手动处理:${pushed.output.split('\n')[0] ?? ''}`
|
|
12452
|
+
};
|
|
12453
|
+
return {
|
|
12454
|
+
committed: true,
|
|
12455
|
+
pushed: true,
|
|
12456
|
+
message: '已提交并推送'
|
|
12457
|
+
};
|
|
12458
|
+
}
|
|
12459
|
+
function appendHistory(entry) {
|
|
12460
|
+
try {
|
|
12461
|
+
const target = historyPath();
|
|
12462
|
+
mkdirSync(external_node_path_dirname(target), {
|
|
12463
|
+
recursive: true
|
|
12464
|
+
});
|
|
12465
|
+
appendFileSync(target, `${JSON.stringify({
|
|
12466
|
+
at: new Date().toISOString(),
|
|
12467
|
+
...entry
|
|
12468
|
+
})}\n`, 'utf8');
|
|
12469
|
+
} catch {}
|
|
12470
|
+
}
|
|
12471
|
+
function readTaskHistory(options) {
|
|
12472
|
+
const target = historyPath();
|
|
12473
|
+
if (!external_node_fs_existsSync(target)) return [];
|
|
12474
|
+
const limit = options.limit ?? 5;
|
|
12475
|
+
const lines = readFileSync(target, 'utf8').trim().split('\n').filter((line)=>line.length > 0);
|
|
12476
|
+
const entries = [];
|
|
12477
|
+
for(let index = lines.length - 1; index >= 0 && entries.length < limit; index -= 1){
|
|
12478
|
+
const line = lines[index];
|
|
12479
|
+
if (void 0 !== line) try {
|
|
12480
|
+
const parsed = JSON.parse(line);
|
|
12481
|
+
if (parsed.iteration.toLowerCase() !== options.iteration.toLowerCase()) continue;
|
|
12482
|
+
if (parsed.developer !== options.developer) continue;
|
|
12483
|
+
if (void 0 !== options.taskId && parsed.taskId !== options.taskId) continue;
|
|
12484
|
+
entries.push(parsed);
|
|
12485
|
+
} catch {
|
|
12486
|
+
continue;
|
|
12487
|
+
}
|
|
12488
|
+
}
|
|
12489
|
+
return entries;
|
|
12490
|
+
}
|
|
12491
|
+
function buildKeys(schema) {
|
|
12492
|
+
const t = schema.taskKeys;
|
|
12493
|
+
const r = schema.requirementKeys;
|
|
12494
|
+
const pick = (keys, semantic)=>{
|
|
12495
|
+
const value = keys[semantic];
|
|
12496
|
+
if (void 0 === value) throw new errors_CliError(`schema.json 缺少列语义:${semantic}`, errors_EXIT.INVALID);
|
|
12497
|
+
return value;
|
|
12498
|
+
};
|
|
12499
|
+
return {
|
|
12500
|
+
task: {
|
|
12501
|
+
id: pick(t, 'id'),
|
|
12502
|
+
requirement: pick(t, 'requirement'),
|
|
12503
|
+
selfTest: pick(t, 'selfTest'),
|
|
12504
|
+
acceptance: pick(t, 'acceptance'),
|
|
12505
|
+
status: pick(t, 'status'),
|
|
12506
|
+
updatedAt: pick(t, 'updatedAt')
|
|
12507
|
+
},
|
|
12508
|
+
requirement: {
|
|
12509
|
+
id: pick(r, 'id'),
|
|
12510
|
+
status: pick(r, 'status'),
|
|
12511
|
+
progress: pick(r, 'progress'),
|
|
12512
|
+
updatedAt: pick(r, 'updatedAt')
|
|
12513
|
+
},
|
|
12514
|
+
taskSection: `## ${schema.sections[2] ?? '三、任务清单'}`,
|
|
12515
|
+
requirementSection: `## ${schema.sections[1] ?? '二、需求清单'}`
|
|
12516
|
+
};
|
|
12517
|
+
}
|
|
12518
|
+
function columnIndex(headerCells, name) {
|
|
12519
|
+
const index = headerCells.findIndex((cell)=>cell.trim() === name);
|
|
12520
|
+
if (index < 0) throw new errors_CliError(`表格缺少列「${name}」,无法安全写入`, errors_EXIT.INVALID);
|
|
12521
|
+
return index;
|
|
12522
|
+
}
|
|
12523
|
+
function splitRow(line) {
|
|
12524
|
+
const trimmed = line.trim();
|
|
12525
|
+
const inner = trimmed.startsWith('|') ? trimmed.slice(1) : trimmed;
|
|
12526
|
+
const withoutTail = inner.endsWith('|') ? inner.slice(0, -1) : inner;
|
|
12527
|
+
return withoutTail.split('|').map((cell)=>cell.trim());
|
|
12528
|
+
}
|
|
12529
|
+
function taskdoc_joinRow(cells) {
|
|
12530
|
+
return `| ${cells.join(' | ')} |`;
|
|
12531
|
+
}
|
|
12532
|
+
function canSubmit(selfTest) {
|
|
12533
|
+
const text = selfTest.trim();
|
|
12534
|
+
return '通过' === text || text.startsWith('免测');
|
|
12535
|
+
}
|
|
12536
|
+
function sectionRange(lines, heading) {
|
|
12537
|
+
const start = lines.findIndex((line)=>line.trim() === heading);
|
|
12538
|
+
if (start < 0) throw new errors_CliError(`文档缺少章节「${heading}」,无法安全写入`, errors_EXIT.INVALID);
|
|
12539
|
+
let end = lines.length;
|
|
12540
|
+
for(let index = start + 1; index < lines.length; index += 1){
|
|
12541
|
+
const line = lines[index] ?? '';
|
|
12542
|
+
if (/^##\s+/.test(line) || /^#\s+/.test(line)) {
|
|
12543
|
+
end = index;
|
|
12544
|
+
break;
|
|
12545
|
+
}
|
|
12546
|
+
}
|
|
12547
|
+
return [
|
|
12548
|
+
start,
|
|
12549
|
+
end
|
|
12550
|
+
];
|
|
12551
|
+
}
|
|
12552
|
+
function parseTaskRows(lines, keys) {
|
|
12553
|
+
const [start, end] = sectionRange(lines, keys.taskSection);
|
|
12554
|
+
let header = null;
|
|
12555
|
+
const rows = [];
|
|
12556
|
+
for(let index = start; index < end; index += 1){
|
|
12557
|
+
const line = lines[index] ?? '';
|
|
12558
|
+
if (!line.trim().startsWith('|')) continue;
|
|
12559
|
+
const cells = splitRow(line);
|
|
12560
|
+
if (null === header) {
|
|
12561
|
+
if (cells.includes(keys.task.id)) header = cells;
|
|
12562
|
+
continue;
|
|
12563
|
+
}
|
|
12564
|
+
if (cells.every((cell)=>/^:?-{2,}:?$/.test(cell))) continue;
|
|
12565
|
+
const taskId = cells[columnIndex(header, keys.task.id)] ?? '';
|
|
12566
|
+
if (/^#\d{3,6}-T\d+$/.test(taskId)) rows.push({
|
|
12567
|
+
index,
|
|
12568
|
+
cells,
|
|
12569
|
+
taskId,
|
|
12570
|
+
status: cells[columnIndex(header, keys.task.status)] ?? '',
|
|
12571
|
+
acceptance: cells[columnIndex(header, keys.task.acceptance)] ?? '',
|
|
12572
|
+
selfTest: cells[columnIndex(header, keys.task.selfTest)] ?? '',
|
|
12573
|
+
requirementId: cells[columnIndex(header, keys.task.requirement)] ?? ''
|
|
12574
|
+
});
|
|
12575
|
+
}
|
|
12576
|
+
if (null === header) throw new errors_CliError('未找到任务清单表头,无法安全写入', errors_EXIT.INVALID);
|
|
12577
|
+
return {
|
|
12578
|
+
header,
|
|
12579
|
+
rows
|
|
12580
|
+
};
|
|
12581
|
+
}
|
|
12582
|
+
function parseRequirementRows(lines, keys) {
|
|
12583
|
+
const [start, end] = sectionRange(lines, keys.requirementSection);
|
|
12584
|
+
let header = null;
|
|
12585
|
+
const rows = [];
|
|
12586
|
+
for(let index = start; index < end; index += 1){
|
|
12587
|
+
const line = lines[index] ?? '';
|
|
12588
|
+
if (!line.trim().startsWith('|')) continue;
|
|
12589
|
+
const cells = splitRow(line);
|
|
12590
|
+
if (null === header) {
|
|
12591
|
+
if (cells.includes(keys.requirement.id)) header = cells;
|
|
12592
|
+
continue;
|
|
12593
|
+
}
|
|
12594
|
+
if (cells.every((cell)=>/^:?-{2,}:?$/.test(cell))) continue;
|
|
12595
|
+
const id = cells[columnIndex(header, keys.requirement.id)] ?? '';
|
|
12596
|
+
if (/^#\d{3,6}$/.test(id)) rows.push({
|
|
12597
|
+
index,
|
|
12598
|
+
cells,
|
|
12599
|
+
id
|
|
12600
|
+
});
|
|
12601
|
+
}
|
|
12602
|
+
if (null === header) throw new errors_CliError('未找到需求清单表头,无法安全写入', errors_EXIT.INVALID);
|
|
12603
|
+
return {
|
|
12604
|
+
header,
|
|
12605
|
+
rows
|
|
12606
|
+
};
|
|
12607
|
+
}
|
|
12608
|
+
function taskdoc_aggregateRequirementStatus(statuses) {
|
|
12609
|
+
if (0 === statuses.length) return '未开始';
|
|
12610
|
+
if (statuses.every((status)=>'未开始' === status)) return '未开始';
|
|
12611
|
+
if (statuses.every((status)=>'已完成' === status)) return '已完成';
|
|
12612
|
+
return '进行中';
|
|
12613
|
+
}
|
|
12614
|
+
function updateDetailBlock(lines, taskId, updates) {
|
|
12615
|
+
const headingIndex = lines.findIndex((line)=>line.trim().startsWith(`### [${taskId}]`));
|
|
12616
|
+
if (headingIndex < 0) throw new errors_CliError(`任务 ${taskId} 缺少第四章详情区块,无法同步状态`, errors_EXIT.INVALID);
|
|
12617
|
+
let end = lines.length;
|
|
12618
|
+
for(let index = headingIndex + 1; index < lines.length; index += 1)if (/^###\s+/.test(lines[index] ?? '') || /^##\s+/.test(lines[index] ?? '')) {
|
|
12619
|
+
end = index;
|
|
12620
|
+
break;
|
|
12621
|
+
}
|
|
12622
|
+
const next = [
|
|
12623
|
+
...lines
|
|
12624
|
+
];
|
|
12625
|
+
for(let index = headingIndex; index < end; index += 1){
|
|
12626
|
+
const line = lines[index] ?? '';
|
|
12627
|
+
const match = /^(\s*-\s+\*\*(.+?)\*\*\s*[::]\s*)(.*)$/.exec(line);
|
|
12628
|
+
if (null === match) continue;
|
|
12629
|
+
const field = match[2] ?? '';
|
|
12630
|
+
const replacement = updates[field];
|
|
12631
|
+
if (void 0 !== replacement) next[index] = `${match[1] ?? ''}${replacement}`;
|
|
12632
|
+
}
|
|
12633
|
+
return next;
|
|
12634
|
+
}
|
|
12635
|
+
function realIterationName(docsRoot, iteration) {
|
|
12636
|
+
try {
|
|
12637
|
+
const match = external_node_fs_readdirSync(docsRoot).find((entry)=>entry.toLowerCase() === iteration.toLowerCase());
|
|
12638
|
+
return match ?? iteration;
|
|
12639
|
+
} catch {
|
|
12640
|
+
return iteration;
|
|
12641
|
+
}
|
|
12642
|
+
}
|
|
12643
|
+
function loadDoc(docsRoot, iterationRaw, developerRaw) {
|
|
12644
|
+
const iteration = realIterationName(docsRoot, taskdoc_safeSegment(iterationRaw, '迭代目录'));
|
|
12645
|
+
const developer = taskdoc_safeSegment(developerRaw, '开发者标识');
|
|
12646
|
+
const file = external_node_path_join(docsRoot, iteration, `${developer}.md`);
|
|
12647
|
+
if (!external_node_fs_existsSync(file)) throw new errors_CliError(`文档不存在:${iteration}/${developer}.md`, errors_EXIT.NOT_FOUND);
|
|
12648
|
+
const mtime = statSync(file).mtimeMs;
|
|
12649
|
+
const original = readFileSync(file, 'utf8');
|
|
12650
|
+
return {
|
|
12651
|
+
file,
|
|
12652
|
+
mtime,
|
|
12653
|
+
original,
|
|
12654
|
+
lines: original.split('\n')
|
|
12655
|
+
};
|
|
12656
|
+
}
|
|
12657
|
+
function computeUpdate(lines, taskId, action, keys) {
|
|
12658
|
+
const { header, rows } = parseTaskRows(lines, keys);
|
|
12659
|
+
const target = rows.find((row)=>row.taskId === taskId);
|
|
12660
|
+
if (void 0 === target) throw new errors_CliError(`任务清单中未找到 ${taskId}`, errors_EXIT.NOT_FOUND);
|
|
12661
|
+
const statusIndex = columnIndex(header, keys.task.status);
|
|
12662
|
+
const acceptanceIndex = columnIndex(header, keys.task.acceptance);
|
|
12663
|
+
const currentStatus = target.status;
|
|
12664
|
+
const currentAcceptance = target.acceptance;
|
|
12665
|
+
const meta = ACTION_META[action];
|
|
12666
|
+
if (currentStatus !== meta.from) throw new errors_CliError(`任务 ${taskId} 当前状态为「${currentStatus}」,无法执行「${meta.label}」(要求「${meta.from}」)`, errors_EXIT.USAGE);
|
|
12667
|
+
if ('submit' === action && !canSubmit(target.selfTest)) throw new errors_CliError(`任务 ${taskId} 的 AI 自测状态为「${target.selfTest}」,未通过自测不能提交验收`, errors_EXIT.USAGE);
|
|
12668
|
+
const nextStatus = meta.to;
|
|
12669
|
+
const nextAcceptance = 'accept' === action ? '验收通过' : 'reject' === action ? '验收驳回' : currentAcceptance;
|
|
12670
|
+
const changes = [];
|
|
12671
|
+
if (nextStatus !== currentStatus) changes.push(`${taskId} 任务状态:${currentStatus} → ${nextStatus}`);
|
|
12672
|
+
if (nextAcceptance !== currentAcceptance) changes.push(`${taskId} 开发人工验收:${currentAcceptance} → ${nextAcceptance}`);
|
|
12673
|
+
const stamp = nowStamp();
|
|
12674
|
+
const updated = [
|
|
12675
|
+
...lines
|
|
12676
|
+
];
|
|
12677
|
+
const taskCells = [
|
|
12678
|
+
...target.cells
|
|
12679
|
+
];
|
|
12680
|
+
taskCells[statusIndex] = nextStatus;
|
|
12681
|
+
taskCells[acceptanceIndex] = nextAcceptance;
|
|
12682
|
+
taskCells[columnIndex(header, keys.task.updatedAt)] = stamp;
|
|
12683
|
+
updated[target.index] = taskdoc_joinRow(taskCells);
|
|
12684
|
+
const withDetail = updateDetailBlock(updated, taskId, {
|
|
12685
|
+
任务状态: nextStatus,
|
|
12686
|
+
人工验收: nextAcceptance
|
|
12687
|
+
});
|
|
12688
|
+
const requirementStatuses = rows.filter((row)=>row.requirementId === target.requirementId).map((row)=>row.taskId === taskId ? nextStatus : row.status);
|
|
12689
|
+
const requirementStatus = taskdoc_aggregateRequirementStatus(requirementStatuses);
|
|
12690
|
+
const completed = requirementStatuses.filter((status)=>'已完成' === status).length;
|
|
12691
|
+
const progress = 0 === requirementStatuses.length ? 0 : Math.round(completed / requirementStatuses.length * 100);
|
|
12692
|
+
const requirementParse = parseRequirementRows(withDetail, keys);
|
|
12693
|
+
const requirementTarget = requirementParse.rows.find((row)=>row.id === target.requirementId);
|
|
12694
|
+
if (void 0 === requirementTarget) throw new errors_CliError(`需求清单中未找到 ${target.requirementId}`, errors_EXIT.NOT_FOUND);
|
|
12695
|
+
const requirementCells = [
|
|
12696
|
+
...requirementTarget.cells
|
|
12697
|
+
];
|
|
12698
|
+
const previousStatus = requirementCells[columnIndex(requirementParse.header, keys.requirement.status)] ?? '';
|
|
12699
|
+
const previousProgress = requirementCells[columnIndex(requirementParse.header, keys.requirement.progress)] ?? '';
|
|
12700
|
+
requirementCells[columnIndex(requirementParse.header, keys.requirement.status)] = requirementStatus;
|
|
12701
|
+
requirementCells[columnIndex(requirementParse.header, keys.requirement.progress)] = String(progress);
|
|
12702
|
+
if (previousStatus !== requirementStatus || previousProgress !== String(progress)) requirementCells[columnIndex(requirementParse.header, keys.requirement.updatedAt)] = stamp;
|
|
12703
|
+
withDetail[requirementTarget.index] = taskdoc_joinRow(requirementCells);
|
|
12704
|
+
if (previousStatus !== requirementStatus) changes.push(`需求 ${target.requirementId} 开发状态:${previousStatus} → ${requirementStatus}`);
|
|
12705
|
+
if (previousProgress !== String(progress)) changes.push(`需求 ${target.requirementId} 开发进度:${previousProgress}% → ${progress}%`);
|
|
12706
|
+
return {
|
|
12707
|
+
lines: withDetail,
|
|
12708
|
+
changes
|
|
12709
|
+
};
|
|
12710
|
+
}
|
|
12711
|
+
function commit(context, lines, changes, message, iteration, developer, action, taskIds, options) {
|
|
12712
|
+
if (statSync(context.file).mtimeMs !== context.mtime) throw new errors_CliError('文件已被外部修改,请刷新后重试', errors_EXIT.INVALID);
|
|
12713
|
+
const output = lines.join('\n');
|
|
12714
|
+
if (output === context.original) return {
|
|
12715
|
+
ok: true,
|
|
12716
|
+
message: '状态未发生变化',
|
|
12717
|
+
changes: [],
|
|
12718
|
+
file: context.file
|
|
12719
|
+
};
|
|
12720
|
+
writeFileSync(context.file, output, 'utf8');
|
|
12721
|
+
const violation = validateAfterWrite(options.docsRoot, iteration, developer);
|
|
12722
|
+
if (null !== violation) {
|
|
12723
|
+
writeFileSync(context.file, context.original, 'utf8');
|
|
12724
|
+
throw new errors_CliError(`写入被校验器拒绝,已回滚:${violation}`, errors_EXIT.INVALID);
|
|
12725
|
+
}
|
|
12726
|
+
appendHistory({
|
|
12727
|
+
iteration,
|
|
12728
|
+
developer,
|
|
12729
|
+
taskId: taskIds.join(','),
|
|
12730
|
+
action,
|
|
12731
|
+
changes
|
|
12732
|
+
});
|
|
12733
|
+
const git = options.policy.commit ? commitInDocsRepo(options.docsRoot, context.file, options.commitMessage, options.policy.push) : void 0;
|
|
12734
|
+
return {
|
|
12735
|
+
ok: true,
|
|
12736
|
+
message,
|
|
12737
|
+
changes,
|
|
12738
|
+
file: context.file,
|
|
12739
|
+
git
|
|
12740
|
+
};
|
|
12741
|
+
}
|
|
12742
|
+
function applyBatchAction(options) {
|
|
12743
|
+
if (0 === options.taskIds.length) throw new errors_CliError('未选择任务', errors_EXIT.USAGE);
|
|
12744
|
+
assertWritableBranch(options.docsRoot);
|
|
12745
|
+
const keys = buildKeys(loadDocSchema(options.docsRoot));
|
|
12746
|
+
const context = loadDoc(options.docsRoot, options.iteration, options.developer);
|
|
12747
|
+
let lines = context.lines;
|
|
12748
|
+
const changes = [];
|
|
12749
|
+
for (const taskId of options.taskIds){
|
|
12750
|
+
const result = computeUpdate(lines, taskId, options.action, keys);
|
|
12751
|
+
lines = result.lines;
|
|
12752
|
+
changes.push(...result.changes);
|
|
12753
|
+
}
|
|
12754
|
+
return commit(context, lines, changes, `已对 ${options.taskIds.length} 个任务执行「${ACTION_META[options.action].label}」`, taskdoc_safeSegment(options.iteration, '迭代目录'), taskdoc_safeSegment(options.developer, '开发者标识'), options.action, options.taskIds, {
|
|
12755
|
+
docsRoot: options.docsRoot,
|
|
12756
|
+
policy: options.policy,
|
|
12757
|
+
commitMessage: buildCommitMessage(options.iteration, options.action, options.taskIds, options.action)
|
|
12758
|
+
});
|
|
12759
|
+
}
|
|
12760
|
+
function applyTaskAction(options) {
|
|
12761
|
+
assertWritableBranch(options.docsRoot);
|
|
12762
|
+
const keys = buildKeys(loadDocSchema(options.docsRoot));
|
|
12763
|
+
const context = loadDoc(options.docsRoot, options.iteration, options.developer);
|
|
12764
|
+
const result = computeUpdate(context.lines, options.taskId, options.action, keys);
|
|
12765
|
+
return commit(context, result.lines, result.changes, `已执行「${ACTION_META[options.action].label}」`, taskdoc_safeSegment(options.iteration, '迭代目录'), taskdoc_safeSegment(options.developer, '开发者标识'), options.action, [
|
|
12766
|
+
options.taskId
|
|
12767
|
+
], {
|
|
12768
|
+
docsRoot: options.docsRoot,
|
|
12769
|
+
policy: options.policy,
|
|
12770
|
+
commitMessage: buildCommitMessage(options.iteration, options.action, [
|
|
12771
|
+
options.taskId
|
|
12772
|
+
], options.action)
|
|
12773
|
+
});
|
|
12774
|
+
}
|
|
12775
|
+
function validateAfterWrite(docsRoot, iteration, developer) {
|
|
12776
|
+
const script = external_node_path_join(docsRoot, "scripts", 'validate_task_doc.py');
|
|
12777
|
+
if (!external_node_fs_existsSync(script)) return null;
|
|
12778
|
+
const targetFile = external_node_path_join(docsRoot, iteration, `${developer}.md`);
|
|
12779
|
+
let role = 'frontend';
|
|
12780
|
+
if (external_node_fs_existsSync(targetFile)) try {
|
|
12781
|
+
role = inferRole(readFileSync(targetFile, 'utf8'));
|
|
12782
|
+
} catch {
|
|
12783
|
+
role = 'frontend';
|
|
12784
|
+
}
|
|
12785
|
+
let scriptError = null;
|
|
12786
|
+
for (const bin of [
|
|
12787
|
+
'python3',
|
|
12788
|
+
'python',
|
|
12789
|
+
'py'
|
|
12790
|
+
])try {
|
|
12791
|
+
const stdout = execFileSync(bin, [
|
|
12792
|
+
script,
|
|
12793
|
+
'--docs-root',
|
|
12794
|
+
docsRoot,
|
|
12795
|
+
'--iteration',
|
|
12796
|
+
iteration,
|
|
12797
|
+
'--developer',
|
|
12798
|
+
developer,
|
|
12799
|
+
'--role',
|
|
12800
|
+
role,
|
|
12801
|
+
'--format',
|
|
12802
|
+
'json'
|
|
12803
|
+
], {
|
|
11695
12804
|
encoding: 'utf8',
|
|
11696
|
-
timeout:
|
|
12805
|
+
timeout: 15000,
|
|
11697
12806
|
maxBuffer: 16777216
|
|
11698
12807
|
});
|
|
11699
|
-
const
|
|
11700
|
-
|
|
12808
|
+
const payload = JSON.parse(stdout);
|
|
12809
|
+
const first = payload.errors?.[0];
|
|
12810
|
+
return first?.message ?? null;
|
|
11701
12811
|
} catch (error) {
|
|
11702
|
-
const stdout = error
|
|
11703
|
-
if (
|
|
11704
|
-
const
|
|
11705
|
-
|
|
11706
|
-
} catch {
|
|
12812
|
+
const { stdout, stderr, code } = error;
|
|
12813
|
+
if ((stdout ?? '').trim().length > 0) try {
|
|
12814
|
+
const payload = JSON.parse(stdout ?? '');
|
|
12815
|
+
return payload.errors?.[0]?.message ?? '校验器未通过';
|
|
12816
|
+
} catch {
|
|
12817
|
+
scriptError = '校验器输出无法解析';
|
|
12818
|
+
continue;
|
|
12819
|
+
}
|
|
12820
|
+
if ('ENOENT' === code || 127 === code) continue;
|
|
12821
|
+
const reason = (stderr ?? '').trim().split('\n')[0] ?? '';
|
|
12822
|
+
scriptError = reason.length > 0 ? `校验器执行失败:${reason}` : '校验器执行失败';
|
|
12823
|
+
continue;
|
|
11707
12824
|
}
|
|
12825
|
+
if (null !== scriptError) return scriptError;
|
|
11708
12826
|
return null;
|
|
11709
12827
|
}
|
|
11710
|
-
function
|
|
11711
|
-
|
|
11712
|
-
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
11716
|
-
|
|
11717
|
-
|
|
11718
|
-
|
|
11719
|
-
|
|
11720
|
-
|
|
11721
|
-
|
|
11722
|
-
|
|
12828
|
+
function recalcRequirements(options) {
|
|
12829
|
+
assertWritableBranch(options.docsRoot);
|
|
12830
|
+
const keys = buildKeys(loadDocSchema(options.docsRoot));
|
|
12831
|
+
const context = loadDoc(options.docsRoot, options.iteration, options.developer);
|
|
12832
|
+
const { rows: taskRows } = parseTaskRows(context.lines, keys);
|
|
12833
|
+
const requirementParse = parseRequirementRows(context.lines, keys);
|
|
12834
|
+
const lines = [
|
|
12835
|
+
...context.lines
|
|
12836
|
+
];
|
|
12837
|
+
const changes = [];
|
|
12838
|
+
for (const requirement of requirementParse.rows){
|
|
12839
|
+
const own = taskRows.filter((row)=>row.requirementId === requirement.id);
|
|
12840
|
+
const status = taskdoc_aggregateRequirementStatus(own.map((row)=>row.status));
|
|
12841
|
+
const completed = own.filter((row)=>'已完成' === row.status).length;
|
|
12842
|
+
const progress = 0 === own.length ? 0 : Math.round(completed / own.length * 100);
|
|
12843
|
+
const cells = [
|
|
12844
|
+
...requirement.cells
|
|
12845
|
+
];
|
|
12846
|
+
const previousStatus = cells[columnIndex(requirementParse.header, keys.requirement.status)] ?? '';
|
|
12847
|
+
const previousProgress = cells[columnIndex(requirementParse.header, keys.requirement.progress)] ?? '';
|
|
12848
|
+
if (previousStatus !== status || previousProgress !== String(progress)) {
|
|
12849
|
+
cells[columnIndex(requirementParse.header, keys.requirement.status)] = status;
|
|
12850
|
+
cells[columnIndex(requirementParse.header, keys.requirement.progress)] = String(progress);
|
|
12851
|
+
lines[requirement.index] = taskdoc_joinRow(cells);
|
|
12852
|
+
if (previousStatus !== status) changes.push(`${requirement.id} 开发状态:${previousStatus} → ${status}`);
|
|
12853
|
+
if (previousProgress !== String(progress)) changes.push(`${requirement.id} 开发进度:${previousProgress}% → ${progress}%`);
|
|
12854
|
+
}
|
|
11723
12855
|
}
|
|
11724
|
-
|
|
12856
|
+
if (true === options.dryRun || 0 === changes.length) return {
|
|
12857
|
+
changes,
|
|
12858
|
+
file: context.file
|
|
12859
|
+
};
|
|
12860
|
+
return {
|
|
12861
|
+
changes,
|
|
12862
|
+
file: commit(context, lines, changes, `已重算 ${requirementParse.rows.length} 个需求的状态与进度`, taskdoc_safeSegment(options.iteration, '迭代目录'), taskdoc_safeSegment(options.developer, '开发者标识'), 'start', [], {
|
|
12863
|
+
docsRoot: options.docsRoot,
|
|
12864
|
+
policy: {
|
|
12865
|
+
commit: false,
|
|
12866
|
+
push: false
|
|
12867
|
+
},
|
|
12868
|
+
commitMessage: `docs(${options.iteration}): 重算需求状态与进度`
|
|
12869
|
+
}).file
|
|
12870
|
+
};
|
|
11725
12871
|
}
|
|
11726
|
-
function
|
|
11727
|
-
const
|
|
11728
|
-
|
|
11729
|
-
const
|
|
11730
|
-
|
|
11731
|
-
|
|
11732
|
-
|
|
11733
|
-
|
|
11734
|
-
|
|
11735
|
-
const
|
|
11736
|
-
|
|
11737
|
-
|
|
11738
|
-
|
|
11739
|
-
|
|
11740
|
-
markdown: rest.join('\n').trim()
|
|
12872
|
+
function availableActions(options) {
|
|
12873
|
+
const iteration = taskdoc_safeSegment(options.iteration, '迭代目录');
|
|
12874
|
+
const developer = taskdoc_safeSegment(options.developer, '开发者标识');
|
|
12875
|
+
const file = external_node_path_join(options.docsRoot, iteration, `${developer}.md`);
|
|
12876
|
+
if (!external_node_fs_existsSync(file)) return {};
|
|
12877
|
+
const lines = readFileSync(file, 'utf8').split('\n');
|
|
12878
|
+
const { rows } = parseTaskRows(lines, buildKeys(loadDocSchema(options.docsRoot)));
|
|
12879
|
+
const result = {};
|
|
12880
|
+
for (const row of rows){
|
|
12881
|
+
const list = [];
|
|
12882
|
+
if ('未开始' === row.status) list.push({
|
|
12883
|
+
action: 'start',
|
|
12884
|
+
enabled: true,
|
|
12885
|
+
reason: ''
|
|
11741
12886
|
});
|
|
12887
|
+
if ('进行中' === row.status) {
|
|
12888
|
+
const ok = canSubmit(row.selfTest);
|
|
12889
|
+
list.push({
|
|
12890
|
+
action: 'submit',
|
|
12891
|
+
enabled: ok,
|
|
12892
|
+
reason: ok ? '' : `AI 自测为「${row.selfTest}」,需先通过自测`
|
|
12893
|
+
});
|
|
12894
|
+
}
|
|
12895
|
+
if ('待验收' === row.status) {
|
|
12896
|
+
list.push({
|
|
12897
|
+
action: 'accept',
|
|
12898
|
+
enabled: true,
|
|
12899
|
+
reason: ''
|
|
12900
|
+
});
|
|
12901
|
+
list.push({
|
|
12902
|
+
action: 'reject',
|
|
12903
|
+
enabled: true,
|
|
12904
|
+
reason: ''
|
|
12905
|
+
});
|
|
12906
|
+
}
|
|
12907
|
+
result[row.taskId] = list;
|
|
11742
12908
|
}
|
|
11743
|
-
return
|
|
12909
|
+
return result;
|
|
11744
12910
|
}
|
|
11745
|
-
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
|
|
11749
|
-
|
|
11750
|
-
|
|
11751
|
-
|
|
11752
|
-
|
|
11753
|
-
|
|
11754
|
-
|
|
11755
|
-
|
|
11756
|
-
|
|
11757
|
-
|
|
11758
|
-
|
|
11759
|
-
'开发状态',
|
|
11760
|
-
'开发进度(%)',
|
|
11761
|
-
'备注',
|
|
11762
|
-
'最后更新'
|
|
11763
|
-
]);
|
|
11764
|
-
const taskRows = readTable('## 三、任务清单', [
|
|
11765
|
-
'任务编号',
|
|
11766
|
-
'关联需求编号',
|
|
11767
|
-
'任务名称',
|
|
11768
|
-
'任务类型',
|
|
11769
|
-
'终端',
|
|
11770
|
-
'前置依赖任务编号',
|
|
11771
|
-
'AI自测状态',
|
|
11772
|
-
'开发人工验收',
|
|
11773
|
-
'任务状态',
|
|
11774
|
-
'最后更新'
|
|
11775
|
-
]);
|
|
11776
|
-
if (0 === requirementRows.length) structureErrors.push({
|
|
11777
|
-
level: 'error',
|
|
11778
|
-
code: 'REQUIREMENT_TABLE_MISMATCH',
|
|
11779
|
-
message: '需求清单表头与模板不符(需包含「最后更新」列),请按最新模板补齐'
|
|
11780
|
-
});
|
|
11781
|
-
if (0 === taskRows.length) structureErrors.push({
|
|
11782
|
-
level: 'error',
|
|
11783
|
-
code: 'TASK_TABLE_MISMATCH',
|
|
11784
|
-
message: '任务清单表头与模板不符(需包含「最后更新」列),请按最新模板补齐'
|
|
12911
|
+
const SYNC_DIRS = new Set([
|
|
12912
|
+
"scripts",
|
|
12913
|
+
'skills',
|
|
12914
|
+
'docs',
|
|
12915
|
+
'_prd',
|
|
12916
|
+
'node_modules'
|
|
12917
|
+
]);
|
|
12918
|
+
function doc_migrate_listIterations(docsRoot) {
|
|
12919
|
+
return external_node_fs_readdirSync(docsRoot).filter((name)=>!name.startsWith('.') && !SYNC_DIRS.has(name)).filter((name)=>{
|
|
12920
|
+
try {
|
|
12921
|
+
return statSync(external_node_path_join(docsRoot, name)).isDirectory();
|
|
12922
|
+
} catch {
|
|
12923
|
+
return false;
|
|
12924
|
+
}
|
|
11785
12925
|
});
|
|
11786
|
-
const requirements = requirementRows.map((row)=>({
|
|
11787
|
-
id: row[0] ?? '',
|
|
11788
|
-
title: row[1] ?? '',
|
|
11789
|
-
terminal: row[2] ?? '',
|
|
11790
|
-
status: row[3] ?? '',
|
|
11791
|
-
progress: row[4] ?? '',
|
|
11792
|
-
note: row[5] ?? '',
|
|
11793
|
-
updatedAt: row[6] ?? '',
|
|
11794
|
-
taskIds: []
|
|
11795
|
-
}));
|
|
11796
|
-
const tasks = taskRows.map((row)=>({
|
|
11797
|
-
id: row[0] ?? '',
|
|
11798
|
-
requirementId: row[1] ?? '',
|
|
11799
|
-
name: row[2] ?? '',
|
|
11800
|
-
type: row[3] ?? '',
|
|
11801
|
-
terminal: row[4] ?? '',
|
|
11802
|
-
dependencies: (row[5] ?? '').split(/[,,]/).map((item)=>item.trim()).filter((item)=>item.length > 0),
|
|
11803
|
-
selfTest: row[6] ?? '',
|
|
11804
|
-
acceptance: row[7] ?? '',
|
|
11805
|
-
status: row[8] ?? '',
|
|
11806
|
-
updatedAt: row[9] ?? ''
|
|
11807
|
-
}));
|
|
11808
|
-
for (const requirement of requirements)requirement.taskIds = tasks.filter((task)=>task.requirementId === requirement.id).map((task)=>task.id);
|
|
11809
|
-
const details = splitDetails(markdown);
|
|
11810
|
-
const infoMatch = /\|\s*迭代版本\s*\|\s*([^|]*)\|/.exec(markdown);
|
|
11811
|
-
const prdMatch = /\|\s*PRD 来源\s*\|\s*([^|]*)\|/.exec(markdown);
|
|
11812
|
-
const planMatch = /\|\s*排期计划\s*\|\s*([^|]*)\|/.exec(markdown);
|
|
11813
|
-
const ownerMatch = /\|\s*负责人\s*\|\s*([^|]*)\|/.exec(markdown);
|
|
11814
|
-
const scopeMatch = /\|\s*负责范围\s*\|\s*([^|]*)\|/.exec(markdown);
|
|
11815
|
-
const iterationInfo = {};
|
|
11816
|
-
const put = (key, match)=>{
|
|
11817
|
-
const value = match?.[1]?.trim();
|
|
11818
|
-
if (void 0 !== value && value.length > 0) iterationInfo[key] = value;
|
|
11819
|
-
};
|
|
11820
|
-
put('迭代版本', infoMatch);
|
|
11821
|
-
put('PRD 来源', prdMatch);
|
|
11822
|
-
put('排期计划', planMatch);
|
|
11823
|
-
put('负责人', ownerMatch);
|
|
11824
|
-
put('负责范围', scopeMatch);
|
|
11825
|
-
return {
|
|
11826
|
-
valid: false,
|
|
11827
|
-
iterationInfo,
|
|
11828
|
-
stats: {
|
|
11829
|
-
requirements: requirements.length,
|
|
11830
|
-
tasks: tasks.length,
|
|
11831
|
-
completedTasks: tasks.filter((task)=>'已完成' === task.status).length,
|
|
11832
|
-
details: details.length
|
|
11833
|
-
},
|
|
11834
|
-
requirements,
|
|
11835
|
-
tasks,
|
|
11836
|
-
errors: structureErrors,
|
|
11837
|
-
warnings: []
|
|
11838
|
-
};
|
|
11839
12926
|
}
|
|
11840
|
-
function
|
|
11841
|
-
|
|
12927
|
+
function doc_migrate_splitRow(line) {
|
|
12928
|
+
const trimmed = line.trim();
|
|
12929
|
+
if (!trimmed.startsWith('|')) return null;
|
|
12930
|
+
const inner = trimmed.endsWith('|') ? trimmed.slice(1, -1) : trimmed.slice(1);
|
|
12931
|
+
return inner.split('|').map((cell)=>cell.trim());
|
|
11842
12932
|
}
|
|
11843
|
-
function
|
|
11844
|
-
|
|
11845
|
-
|
|
11846
|
-
|
|
11847
|
-
|
|
11848
|
-
|
|
11849
|
-
|
|
11850
|
-
|
|
11851
|
-
|
|
11852
|
-
|
|
11853
|
-
|
|
11854
|
-
|
|
11855
|
-
|
|
11856
|
-
|
|
11857
|
-
|
|
11858
|
-
|
|
11859
|
-
|
|
11860
|
-
|
|
11861
|
-
|
|
11862
|
-
|
|
11863
|
-
|
|
11864
|
-
|
|
11865
|
-
ref: {
|
|
11866
|
-
name: ref.ref,
|
|
11867
|
-
sha: ref.sha
|
|
11868
|
-
},
|
|
11869
|
-
validation: scripted ?? parseMarkdownDoc(exported.markdown),
|
|
11870
|
-
details: splitDetails(exported.markdown)
|
|
11871
|
-
};
|
|
12933
|
+
function doc_migrate_joinRow(cells) {
|
|
12934
|
+
return `| ${cells.join(' | ')} |`;
|
|
12935
|
+
}
|
|
12936
|
+
function isSeparator(cells) {
|
|
12937
|
+
return cells.every((cell)=>/^:?-{2,}:?$/.test(cell));
|
|
12938
|
+
}
|
|
12939
|
+
function locateTaskTable(lines, schema) {
|
|
12940
|
+
const heading = `## ${schema.sections[2] ?? '三、任务清单'}`;
|
|
12941
|
+
const sectionStart = lines.findIndex((line)=>line.trim() === heading);
|
|
12942
|
+
if (sectionStart < 0) return null;
|
|
12943
|
+
let headerIndex = -1;
|
|
12944
|
+
let endIndex = lines.length;
|
|
12945
|
+
for(let index = sectionStart + 1; index < lines.length; index += 1){
|
|
12946
|
+
const line = lines[index] ?? '';
|
|
12947
|
+
if (/^##\s+/.test(line)) {
|
|
12948
|
+
endIndex = index;
|
|
12949
|
+
break;
|
|
12950
|
+
}
|
|
12951
|
+
const cells = doc_migrate_splitRow(line);
|
|
12952
|
+
if (null !== cells) {
|
|
12953
|
+
if (headerIndex < 0) headerIndex = index;
|
|
12954
|
+
}
|
|
11872
12955
|
}
|
|
11873
|
-
|
|
11874
|
-
|
|
11875
|
-
const file = joinWithin(directory, `${safeDeveloper}.md`);
|
|
11876
|
-
if (!external_node_fs_existsSync(file)) throw new errors_CliError(`文档不存在:${safeIteration}/${safeDeveloper}.md`, errors_EXIT.NOT_FOUND);
|
|
11877
|
-
const markdown = readMarkdown(file);
|
|
11878
|
-
const roleInferred = inferRole(markdown);
|
|
11879
|
-
const scripted = runValidator({
|
|
11880
|
-
docsRoot,
|
|
11881
|
-
scriptPath: external_node_path_join(docsRoot, "scripts", 'validate_task_doc.py'),
|
|
11882
|
-
iteration: safeIteration,
|
|
11883
|
-
developer: safeDeveloper,
|
|
11884
|
-
role: roleInferred
|
|
11885
|
-
});
|
|
11886
|
-
const validation = scripted ?? parseMarkdownDoc(markdown);
|
|
11887
|
-
const parser = null === scripted ? 'fallback' : "script";
|
|
12956
|
+
if (headerIndex < 0) return null;
|
|
12957
|
+
const header = doc_migrate_splitRow(lines[headerIndex] ?? '') ?? [];
|
|
11888
12958
|
return {
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
mtime: statSync(file).mtime.toISOString(),
|
|
11893
|
-
roleInferred,
|
|
11894
|
-
parser,
|
|
11895
|
-
source: 'local',
|
|
11896
|
-
ref: null,
|
|
11897
|
-
validation,
|
|
11898
|
-
details: splitDetails(markdown)
|
|
12959
|
+
start: sectionStart,
|
|
12960
|
+
end: endIndex,
|
|
12961
|
+
header
|
|
11899
12962
|
};
|
|
11900
12963
|
}
|
|
11901
|
-
function
|
|
11902
|
-
const
|
|
11903
|
-
const
|
|
11904
|
-
|
|
11905
|
-
|
|
11906
|
-
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
|
|
11910
|
-
|
|
11911
|
-
|
|
11912
|
-
|
|
11913
|
-
|
|
12964
|
+
function migrateTaskTable(options) {
|
|
12965
|
+
const { schema } = options;
|
|
12966
|
+
const table = locateTaskTable(options.lines, schema);
|
|
12967
|
+
if (null === table) return {
|
|
12968
|
+
lines: options.lines,
|
|
12969
|
+
added: 0,
|
|
12970
|
+
unresolved: []
|
|
12971
|
+
};
|
|
12972
|
+
const headerIndex = options.lines.findIndex((line, index)=>index > table.start && index < table.end && null !== doc_migrate_splitRow(line));
|
|
12973
|
+
if (headerIndex < 0) return {
|
|
12974
|
+
lines: options.lines,
|
|
12975
|
+
added: 0,
|
|
12976
|
+
unresolved: []
|
|
12977
|
+
};
|
|
12978
|
+
const header = doc_migrate_splitRow(options.lines[headerIndex] ?? '') ?? [];
|
|
12979
|
+
const missing = schema.taskHeaders.filter((name)=>!header.includes(name));
|
|
12980
|
+
if (0 === missing.length) return {
|
|
12981
|
+
lines: options.lines,
|
|
12982
|
+
added: 0,
|
|
12983
|
+
unresolved: []
|
|
12984
|
+
};
|
|
12985
|
+
const nextHeader = [
|
|
12986
|
+
...schema.taskHeaders
|
|
12987
|
+
];
|
|
12988
|
+
const lines = [
|
|
12989
|
+
...options.lines
|
|
12990
|
+
];
|
|
12991
|
+
lines[headerIndex] = doc_migrate_joinRow(nextHeader);
|
|
12992
|
+
if (headerIndex + 1 < options.lines.length) {
|
|
12993
|
+
const separator = doc_migrate_splitRow(options.lines[headerIndex + 1] ?? '');
|
|
12994
|
+
if (null !== separator && isSeparator(separator)) lines[headerIndex + 1] = doc_migrate_joinRow(nextHeader.map(()=>'---'));
|
|
12995
|
+
}
|
|
12996
|
+
const unresolved = [];
|
|
12997
|
+
let added = 0;
|
|
12998
|
+
const idIndex = header.indexOf('任务编号');
|
|
12999
|
+
const typeIndex = header.indexOf('任务类型');
|
|
13000
|
+
const terminalIndex = header.indexOf('终端');
|
|
13001
|
+
for(let index = headerIndex + 2; index < table.end; index += 1){
|
|
13002
|
+
const cells = doc_migrate_splitRow(options.lines[index] ?? '');
|
|
13003
|
+
if (null === cells || isSeparator(cells)) continue;
|
|
13004
|
+
const record = {};
|
|
13005
|
+
header.forEach((name, position)=>{
|
|
13006
|
+
record[name] = cells[position] ?? '';
|
|
13007
|
+
});
|
|
13008
|
+
for (const name of missing)if ('所属端' === name) {
|
|
13009
|
+
const taskId = cells[idIndex >= 0 ? idIndex : 0] ?? '';
|
|
13010
|
+
const type = cells[typeIndex >= 0 ? typeIndex : 0] ?? '';
|
|
13011
|
+
const terminal = cells[terminalIndex >= 0 ? terminalIndex : 0] ?? '';
|
|
13012
|
+
let value = '';
|
|
13013
|
+
if (0 === value.length) {
|
|
13014
|
+
const side = sideOfTypeName(schema, type);
|
|
13015
|
+
value = 'frontend' === side ? '前端' : 'backend' === side ? '后端' : '';
|
|
13016
|
+
}
|
|
13017
|
+
if (0 === value.length) value = options.resolveScopeFromTerminal(terminal);
|
|
13018
|
+
if (0 === value.length) unresolved.push(taskId);
|
|
13019
|
+
record[name] = value;
|
|
13020
|
+
} else record[name] = '';
|
|
13021
|
+
lines[index] = doc_migrate_joinRow(nextHeader.map((name)=>record[name] ?? ''));
|
|
13022
|
+
added += 1;
|
|
13023
|
+
}
|
|
13024
|
+
return {
|
|
13025
|
+
lines,
|
|
13026
|
+
added,
|
|
13027
|
+
unresolved
|
|
13028
|
+
};
|
|
13029
|
+
}
|
|
13030
|
+
function locateDetailBlocks(lines, schema) {
|
|
13031
|
+
const heading = `## ${schema.sections[3] ?? '四、任务详情'}`;
|
|
13032
|
+
const sectionStart = lines.findIndex((line)=>line.trim() === heading);
|
|
13033
|
+
if (sectionStart < 0) return [];
|
|
13034
|
+
const blocks = [];
|
|
13035
|
+
let current = null;
|
|
13036
|
+
for(let index = sectionStart + 1; index < lines.length; index += 1){
|
|
13037
|
+
const line = lines[index] ?? '';
|
|
13038
|
+
if (/^##\s+/.test(line)) break;
|
|
13039
|
+
const matched = /^###\s+\[(#[^\]]+)\]/.exec(line.trim());
|
|
13040
|
+
if (null !== matched) {
|
|
13041
|
+
if (null !== current) current.endIndex = index;
|
|
13042
|
+
current = {
|
|
13043
|
+
taskId: matched[1] ?? '',
|
|
13044
|
+
headingIndex: index,
|
|
13045
|
+
endIndex: lines.length
|
|
13046
|
+
};
|
|
13047
|
+
blocks.push(current);
|
|
13048
|
+
}
|
|
11914
13049
|
}
|
|
11915
|
-
|
|
11916
|
-
|
|
11917
|
-
|
|
11918
|
-
|
|
11919
|
-
|
|
11920
|
-
const
|
|
11921
|
-
const
|
|
11922
|
-
|
|
11923
|
-
|
|
11924
|
-
|
|
11925
|
-
|
|
13050
|
+
return blocks;
|
|
13051
|
+
}
|
|
13052
|
+
function fieldSpans(lines, block) {
|
|
13053
|
+
const spans = [];
|
|
13054
|
+
for(let index = block.headingIndex + 1; index < block.endIndex; index += 1){
|
|
13055
|
+
const line = lines[index] ?? '';
|
|
13056
|
+
const matched = /^\s*-\s+\*\*(.+?)\*\*\s*[::]/.exec(line);
|
|
13057
|
+
if (null !== matched) {
|
|
13058
|
+
const previous = spans[spans.length - 1];
|
|
13059
|
+
if (void 0 !== previous) previous.end = index;
|
|
13060
|
+
spans.push({
|
|
13061
|
+
name: (matched[1] ?? '').trim(),
|
|
13062
|
+
start: index,
|
|
13063
|
+
end: block.endIndex
|
|
13064
|
+
});
|
|
11926
13065
|
}
|
|
11927
|
-
|
|
11928
|
-
|
|
11929
|
-
|
|
11930
|
-
|
|
11931
|
-
|
|
11932
|
-
|
|
11933
|
-
|
|
11934
|
-
|
|
11935
|
-
|
|
11936
|
-
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
|
|
11940
|
-
|
|
11941
|
-
|
|
11942
|
-
|
|
11943
|
-
|
|
11944
|
-
|
|
11945
|
-
|
|
13066
|
+
}
|
|
13067
|
+
return spans;
|
|
13068
|
+
}
|
|
13069
|
+
function migrateDetailFields(options) {
|
|
13070
|
+
const { schema } = options;
|
|
13071
|
+
const blocks = locateDetailBlocks(options.lines, schema);
|
|
13072
|
+
let lines = [
|
|
13073
|
+
...options.lines
|
|
13074
|
+
];
|
|
13075
|
+
let added = 0;
|
|
13076
|
+
for (const block of [
|
|
13077
|
+
...blocks
|
|
13078
|
+
].reverse()){
|
|
13079
|
+
const scope = options.scopeByTaskId.get(block.taskId) ?? '';
|
|
13080
|
+
const required = scope.length > 0 ? detailFieldsOfScope(schema, scope) : [];
|
|
13081
|
+
if (0 === required.length) continue;
|
|
13082
|
+
const spans = fieldSpans(lines, block);
|
|
13083
|
+
const present = new Set(spans.map((span)=>span.name));
|
|
13084
|
+
const missing = required.filter((name)=>!present.has(name));
|
|
13085
|
+
if (0 !== missing.length) for (const name of missing){
|
|
13086
|
+
const requiredIndex = required.indexOf(name);
|
|
13087
|
+
let insertAt = block.headingIndex + 2;
|
|
13088
|
+
for(let cursor = requiredIndex - 1; cursor >= 0; cursor -= 1){
|
|
13089
|
+
const previousName = required[cursor];
|
|
13090
|
+
if (void 0 === previousName) continue;
|
|
13091
|
+
const span = spans.find((item)=>item.name === previousName);
|
|
13092
|
+
if (void 0 !== span) {
|
|
13093
|
+
insertAt = span.end;
|
|
13094
|
+
break;
|
|
13095
|
+
}
|
|
13096
|
+
}
|
|
13097
|
+
lines = [
|
|
13098
|
+
...lines.slice(0, insertAt),
|
|
13099
|
+
`- **${name}**:<待补充>`,
|
|
13100
|
+
...lines.slice(insertAt)
|
|
13101
|
+
];
|
|
13102
|
+
const refreshed = fieldSpans(lines, block);
|
|
13103
|
+
spans.length = 0;
|
|
13104
|
+
spans.push(...refreshed);
|
|
13105
|
+
added += 1;
|
|
13106
|
+
}
|
|
13107
|
+
}
|
|
13108
|
+
return {
|
|
13109
|
+
lines,
|
|
13110
|
+
added
|
|
13111
|
+
};
|
|
13112
|
+
}
|
|
13113
|
+
function makeTerminalResolver(terminals) {
|
|
13114
|
+
const index = buildRepoSideIndex(terminals);
|
|
13115
|
+
return (repoName)=>{
|
|
13116
|
+
const side = sideOfRepo(index, repoName);
|
|
13117
|
+
if ('frontend' === side) return '前端';
|
|
13118
|
+
if ('backend' === side) return '后端';
|
|
13119
|
+
return '';
|
|
13120
|
+
};
|
|
13121
|
+
}
|
|
13122
|
+
function runDocMigrate(options) {
|
|
13123
|
+
const format = parseFormat(options.format);
|
|
13124
|
+
const loaded = loadConfig(options.config);
|
|
13125
|
+
if (!loaded.exists || null === loaded.config) throw new errors_CliError(`配置未初始化:${loaded.path}\n请先运行:ylcwf init`, errors_EXIT.NOT_FOUND);
|
|
13126
|
+
const config = loaded.config;
|
|
13127
|
+
const docsRoot = config.docs.root;
|
|
13128
|
+
if (true !== options.dryRun) assertWritableBranch(docsRoot);
|
|
13129
|
+
const schema = loadDocSchema(docsRoot);
|
|
13130
|
+
const resolveScopeFromTerminal = makeTerminalResolver(config.terminals);
|
|
13131
|
+
const iterations = options.iteration?.trim() ? [
|
|
13132
|
+
options.iteration.trim()
|
|
13133
|
+
] : doc_migrate_listIterations(docsRoot);
|
|
13134
|
+
const results = [];
|
|
13135
|
+
const changedFiles = [];
|
|
13136
|
+
for (const iteration of iterations){
|
|
13137
|
+
const dir = external_node_path_join(docsRoot, iteration);
|
|
13138
|
+
if (!external_node_fs_existsSync(dir)) continue;
|
|
13139
|
+
const files = external_node_fs_readdirSync(dir).filter((name)=>name.endsWith('.md') && !name.startsWith('_'));
|
|
13140
|
+
for (const name of files){
|
|
13141
|
+
const target = external_node_path_join(dir, name);
|
|
13142
|
+
const original = readFileSync(target, 'utf8');
|
|
13143
|
+
const tableMigrated = migrateTaskTable({
|
|
13144
|
+
lines: original.split('\n'),
|
|
13145
|
+
schema,
|
|
13146
|
+
resolveScopeFromTerminal
|
|
13147
|
+
});
|
|
13148
|
+
const scopeByTaskId = collectTaskScopes(tableMigrated.lines, schema);
|
|
13149
|
+
const detailMigrated = migrateDetailFields({
|
|
13150
|
+
lines: tableMigrated.lines,
|
|
13151
|
+
schema,
|
|
13152
|
+
scopeByTaskId
|
|
13153
|
+
});
|
|
13154
|
+
const addedRows = tableMigrated.added;
|
|
13155
|
+
const addedFields = detailMigrated.added;
|
|
13156
|
+
if (0 === addedRows && 0 === addedFields) continue;
|
|
13157
|
+
const migrated = {
|
|
13158
|
+
lines: detailMigrated.lines,
|
|
13159
|
+
unresolved: tableMigrated.unresolved
|
|
13160
|
+
};
|
|
13161
|
+
results.push({
|
|
13162
|
+
file: `${iteration}/${name}`,
|
|
13163
|
+
added: addedRows,
|
|
13164
|
+
addedFields,
|
|
13165
|
+
unresolved: tableMigrated.unresolved
|
|
11946
13166
|
});
|
|
13167
|
+
if (true === options.dryRun) continue;
|
|
13168
|
+
writeFileSync(target, migrated.lines.join('\n'), 'utf8');
|
|
13169
|
+
changedFiles.push(target);
|
|
13170
|
+
if (migrated.unresolved.length > 0) continue;
|
|
13171
|
+
const developer = basename(name, '.md');
|
|
13172
|
+
const violation = validateAfterWrite(docsRoot, iteration, developer);
|
|
13173
|
+
if (null !== violation) {
|
|
13174
|
+
writeFileSync(target, original, 'utf8');
|
|
13175
|
+
throw new errors_CliError(`迁移后校验未通过,已回滚 ${iteration}/${name}:${violation}`, errors_EXIT.INVALID);
|
|
13176
|
+
}
|
|
11947
13177
|
}
|
|
11948
|
-
|
|
11949
|
-
|
|
11950
|
-
|
|
11951
|
-
|
|
11952
|
-
|
|
11953
|
-
|
|
11954
|
-
|
|
11955
|
-
|
|
11956
|
-
|
|
11957
|
-
|
|
11958
|
-
|
|
11959
|
-
|
|
11960
|
-
|
|
11961
|
-
|
|
13178
|
+
}
|
|
13179
|
+
const totalUnresolved = results.flatMap((item)=>item.unresolved);
|
|
13180
|
+
if ('json' === format) return void printJson({
|
|
13181
|
+
ok: true,
|
|
13182
|
+
dryRun: true === options.dryRun,
|
|
13183
|
+
files: results,
|
|
13184
|
+
unresolved: totalUnresolved
|
|
13185
|
+
});
|
|
13186
|
+
if (0 === results.length) return void printLine('所有文档已符合 schema 的列结构,无需迁移');
|
|
13187
|
+
printLine(true === options.dryRun ? '将迁移:' : '已迁移:');
|
|
13188
|
+
for (const item of results){
|
|
13189
|
+
const extra = item.unresolved.length > 0 ? `(待人工补 ${item.unresolved.join('、')})` : '';
|
|
13190
|
+
const parts = [];
|
|
13191
|
+
if (item.added > 0) parts.push(`${item.added} 行任务`);
|
|
13192
|
+
if (item.addedFields > 0) parts.push(`${item.addedFields} 个详情字段`);
|
|
13193
|
+
printLine(` · ${item.file} ${parts.join(' + ')}${extra}`);
|
|
13194
|
+
}
|
|
13195
|
+
if (totalUnresolved.length > 0) {
|
|
13196
|
+
printLine('\n以下任务的「所属端」无法自动判定(终端未配置或类型两端通用),请手工补齐:');
|
|
13197
|
+
printLine(` ${totalUnresolved.join('、')}`);
|
|
13198
|
+
printLine('补齐后运行校验:');
|
|
13199
|
+
printLine(" python3 <文档仓库>/scripts/validate_task_doc.py --docs-root <文档仓库> \\");
|
|
13200
|
+
printLine(' --iteration <迭代> --developer <标识> --role <frontend|backend|fullstack>');
|
|
13201
|
+
}
|
|
13202
|
+
if (true !== options.dryRun) {
|
|
13203
|
+
const policy = config.docs.git.cli;
|
|
13204
|
+
if (policy.commit) {
|
|
13205
|
+
const git = commitInDocsRepo(docsRoot, changedFiles, "docs: 迁移任务表结构(按 schema.json)", policy.push);
|
|
13206
|
+
printLine(`\n${git.message}`);
|
|
13207
|
+
}
|
|
13208
|
+
}
|
|
13209
|
+
}
|
|
13210
|
+
function collectTaskScopes(lines, schema) {
|
|
13211
|
+
const result = new Map();
|
|
13212
|
+
const table = locateTaskTable(lines, schema);
|
|
13213
|
+
if (null === table) return result;
|
|
13214
|
+
const headerIndex = lines.findIndex((line, index)=>index > table.start && index < table.end && null !== doc_migrate_splitRow(line));
|
|
13215
|
+
if (headerIndex < 0) return result;
|
|
13216
|
+
const header = doc_migrate_splitRow(lines[headerIndex] ?? '') ?? [];
|
|
13217
|
+
const idIndex = header.indexOf('任务编号');
|
|
13218
|
+
const scopeIndex = header.indexOf('所属端');
|
|
13219
|
+
if (idIndex < 0 || scopeIndex < 0) return result;
|
|
13220
|
+
for(let index = headerIndex + 2; index < table.end; index += 1){
|
|
13221
|
+
const cells = doc_migrate_splitRow(lines[index] ?? '');
|
|
13222
|
+
if (null === cells || isSeparator(cells)) continue;
|
|
13223
|
+
const id = cells[idIndex] ?? '';
|
|
13224
|
+
const scope = cells[scopeIndex] ?? '';
|
|
13225
|
+
if (id.length > 0 && scope.length > 0) result.set(id, scope);
|
|
13226
|
+
}
|
|
13227
|
+
return result;
|
|
13228
|
+
}
|
|
13229
|
+
function registerDocMigrate(doc) {
|
|
13230
|
+
doc.command('migrate').description('按 schema.json 迁移存量文档(补缺失的任务列并回填)').option('-i, --iteration <name>', '只迁移指定迭代').option('--dry-run', '只打印将要迁移的文件,不写盘').option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').action((options)=>{
|
|
13231
|
+
runDocMigrate(options);
|
|
13232
|
+
});
|
|
13233
|
+
}
|
|
13234
|
+
function doc_nowStamp() {
|
|
13235
|
+
const now = new Date();
|
|
13236
|
+
const pad = (value)=>String(value).padStart(2, '0');
|
|
13237
|
+
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`;
|
|
13238
|
+
}
|
|
13239
|
+
function readPlanFile(path) {
|
|
13240
|
+
if (!external_node_fs_existsSync(path)) throw new errors_CliError(`plan 文件不存在:${path}`, errors_EXIT.NOT_FOUND);
|
|
13241
|
+
const text = readFileSync(path, 'utf8');
|
|
13242
|
+
try {
|
|
13243
|
+
return JSON.parse(text);
|
|
13244
|
+
} catch (error) {
|
|
13245
|
+
throw new errors_CliError(`plan 文件不是合法 JSON:${error instanceof Error ? error.message : String(error)}`, errors_EXIT.INVALID);
|
|
13246
|
+
}
|
|
13247
|
+
}
|
|
13248
|
+
function doc_realIterationName(docsRoot, iteration) {
|
|
13249
|
+
const direct = external_node_path_join(docsRoot, iteration);
|
|
13250
|
+
external_node_fs_existsSync(direct);
|
|
13251
|
+
return iteration;
|
|
13252
|
+
}
|
|
13253
|
+
function runDocApply(options, mode = 'apply') {
|
|
13254
|
+
const format = parseFormat(options.format);
|
|
13255
|
+
const loaded = loadConfig(options.config);
|
|
13256
|
+
if (!loaded.exists || null === loaded.config) throw new errors_CliError(`配置未初始化:${loaded.path}\n请先运行:ylcwf init`, errors_EXIT.NOT_FOUND);
|
|
13257
|
+
const config = loaded.config;
|
|
13258
|
+
const docsRoot = config.docs.root;
|
|
13259
|
+
const developer = config.profile.developer;
|
|
13260
|
+
const role = config.profile.role;
|
|
13261
|
+
const iteration = doc_realIterationName(docsRoot, options.iteration.trim());
|
|
13262
|
+
if (0 === iteration.length) throw new errors_CliError('必须指定迭代目录:--iteration <迭代>', errors_EXIT.USAGE);
|
|
13263
|
+
const schema = loadDocSchema(docsRoot);
|
|
13264
|
+
const plan = parseDocPlan(readPlanFile(options.input), schema, role);
|
|
13265
|
+
const targetDir = external_node_path_join(docsRoot, iteration);
|
|
13266
|
+
const targetFile = external_node_path_join(targetDir, `${developer}.md`);
|
|
13267
|
+
const exists = external_node_fs_existsSync(targetFile);
|
|
13268
|
+
const original = exists ? readFileSync(targetFile, 'utf8') : null;
|
|
13269
|
+
const mtime = exists ? statSync(targetFile).mtimeMs : 0;
|
|
13270
|
+
const parsed = null === original ? {
|
|
13271
|
+
requirements: [],
|
|
13272
|
+
tasks: []
|
|
13273
|
+
} : parseMarkdownDoc(original, schema);
|
|
13274
|
+
validatePlanReferences({
|
|
13275
|
+
plan,
|
|
13276
|
+
schema,
|
|
13277
|
+
role,
|
|
13278
|
+
index: buildRepoSideIndex(config.terminals),
|
|
13279
|
+
knownTaskIds: parsed.tasks.map((task)=>task.id)
|
|
13280
|
+
});
|
|
13281
|
+
const stamp = doc_nowStamp();
|
|
13282
|
+
const rendered = renderPlan({
|
|
13283
|
+
schema,
|
|
13284
|
+
role,
|
|
13285
|
+
plan,
|
|
13286
|
+
existing: {
|
|
13287
|
+
requirements: parsed.requirements,
|
|
13288
|
+
tasks: parsed.tasks,
|
|
13289
|
+
lines: null === original ? null : original.split('\n')
|
|
13290
|
+
},
|
|
13291
|
+
stamp,
|
|
13292
|
+
developer
|
|
13293
|
+
});
|
|
13294
|
+
const sideIndex = buildRepoSideIndex(config.terminals);
|
|
13295
|
+
const sideReport = validateTaskSides({
|
|
13296
|
+
index: sideIndex,
|
|
13297
|
+
tasks: rendered.assigned.map((item)=>{
|
|
13298
|
+
const planned = plan.tasks.find((task)=>task.name === item.name);
|
|
13299
|
+
return {
|
|
13300
|
+
id: item.id,
|
|
13301
|
+
scope: planned?.scope ?? '',
|
|
13302
|
+
terminal: planned?.terminal ?? ''
|
|
13303
|
+
};
|
|
13304
|
+
})
|
|
13305
|
+
});
|
|
13306
|
+
const conflicts = sideReport.issues.filter((issue)=>'error' === issue.level);
|
|
13307
|
+
if (conflicts.length > 0) throw new errors_CliError(`任务类型与终端归属不一致,已中止:\n${conflicts.map((issue)=>` · ${issue.message}`).join('\n')}`, errors_EXIT.INVALID);
|
|
13308
|
+
const sideSkippedNote = sideReport.skipped > 0 ? `本机终端配置未覆盖 ${sideReport.skipped} 个任务,其「所属端 vs 仓库」未校验` + (0 === Object.keys(config.terminals).length ? '(terminals 为空)' : '') : null;
|
|
13309
|
+
if (0 === rendered.assigned.length && rendered.markdown === original) {
|
|
13310
|
+
if ('json' === format) printJson({
|
|
13311
|
+
ok: true,
|
|
13312
|
+
changed: false,
|
|
13313
|
+
file: targetFile,
|
|
13314
|
+
changes: [],
|
|
13315
|
+
assigned: []
|
|
11962
13316
|
});
|
|
13317
|
+
else printLine('计划中的需求与任务都已存在,未做修改');
|
|
13318
|
+
return;
|
|
11963
13319
|
}
|
|
11964
|
-
|
|
11965
|
-
|
|
11966
|
-
|
|
11967
|
-
|
|
11968
|
-
|
|
11969
|
-
|
|
11970
|
-
|
|
11971
|
-
|
|
11972
|
-
|
|
11973
|
-
|
|
11974
|
-
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
|
|
11980
|
-
|
|
11981
|
-
|
|
11982
|
-
|
|
13320
|
+
if ('diff' === mode || true === options.dryRun) {
|
|
13321
|
+
if ('json' === format) printJson({
|
|
13322
|
+
ok: true,
|
|
13323
|
+
dryRun: true,
|
|
13324
|
+
mode,
|
|
13325
|
+
file: targetFile,
|
|
13326
|
+
changes: rendered.changes,
|
|
13327
|
+
assigned: rendered.assigned,
|
|
13328
|
+
preview: rendered.markdown
|
|
13329
|
+
});
|
|
13330
|
+
else {
|
|
13331
|
+
printLine(`将写入:${targetFile}`);
|
|
13332
|
+
for (const change of rendered.changes)printLine(` · ${change}`);
|
|
13333
|
+
if (!exists) printLine('(文件不存在,将新建完整文档)');
|
|
13334
|
+
printLine('diff' === mode ? '\n(diff:未实际写入)' : '\n(--dry-run,未实际写入)');
|
|
13335
|
+
}
|
|
13336
|
+
return;
|
|
13337
|
+
}
|
|
13338
|
+
if (exists && statSync(targetFile).mtimeMs !== mtime) throw new errors_CliError('文件已被外部修改,请重试', errors_EXIT.INVALID);
|
|
13339
|
+
assertWritableBranch(docsRoot);
|
|
13340
|
+
mkdirSync(targetDir, {
|
|
13341
|
+
recursive: true
|
|
11983
13342
|
});
|
|
11984
|
-
|
|
11985
|
-
|
|
13343
|
+
writeFileSync(targetFile, rendered.markdown, 'utf8');
|
|
13344
|
+
const violation = validateAfterWrite(docsRoot, iteration, developer);
|
|
13345
|
+
if (null !== violation) {
|
|
13346
|
+
if (null === original) unlinkSync(targetFile);
|
|
13347
|
+
else writeFileSync(targetFile, original, 'utf8');
|
|
13348
|
+
throw new errors_CliError(`写入被校验器拒绝,已回滚:${violation}`, errors_EXIT.INVALID);
|
|
13349
|
+
}
|
|
13350
|
+
const remainingReport = checkDocTaskSides({
|
|
11986
13351
|
docsRoot,
|
|
11987
|
-
|
|
11988
|
-
|
|
11989
|
-
|
|
11990
|
-
|
|
11991
|
-
|
|
11992
|
-
|
|
11993
|
-
|
|
11994
|
-
|
|
11995
|
-
|
|
11996
|
-
|
|
11997
|
-
|
|
11998
|
-
|
|
11999
|
-
|
|
13352
|
+
iteration,
|
|
13353
|
+
developer,
|
|
13354
|
+
role,
|
|
13355
|
+
terminals: config.terminals
|
|
13356
|
+
});
|
|
13357
|
+
const remaining = remainingReport.issues.filter((issue)=>'error' === issue.level);
|
|
13358
|
+
const policy = config.docs.git.cli;
|
|
13359
|
+
const git = policy.commit ? commitInDocsRepo(docsRoot, targetFile, `docs: ${iteration} 新增 ${rendered.assigned.length} 个任务(${rendered.assigned.map((item)=>item.id).join('、')})`, policy.push) : void 0;
|
|
13360
|
+
if ('json' === format) printJson({
|
|
13361
|
+
ok: true,
|
|
13362
|
+
changed: true,
|
|
13363
|
+
file: targetFile,
|
|
13364
|
+
changes: rendered.changes,
|
|
13365
|
+
assigned: rendered.assigned,
|
|
13366
|
+
sideIssues: remaining.map((issue)=>issue.message),
|
|
13367
|
+
sideCheck: {
|
|
13368
|
+
checked: sideReport.checked,
|
|
13369
|
+
skipped: sideReport.skipped
|
|
12000
13370
|
},
|
|
12001
|
-
|
|
12002
|
-
|
|
12003
|
-
};
|
|
13371
|
+
sideWarning: sideSkippedNote,
|
|
13372
|
+
git
|
|
13373
|
+
});
|
|
13374
|
+
else {
|
|
13375
|
+
printLine(`已写入:${targetFile}`);
|
|
13376
|
+
for (const change of rendered.changes)printLine(` · ${change}`);
|
|
13377
|
+
if (null !== sideSkippedNote) printLine(`\n! ${sideSkippedNote}`);
|
|
13378
|
+
if (remaining.length > 0) {
|
|
13379
|
+
printLine('\n注意:以下任务的类型与终端归属不一致(请核对):');
|
|
13380
|
+
for (const issue of remaining)printLine(` · ${issue.message}`);
|
|
13381
|
+
}
|
|
13382
|
+
if (void 0 !== git) printLine(`\n${git.message}`);
|
|
13383
|
+
}
|
|
13384
|
+
}
|
|
13385
|
+
function registerDoc(program) {
|
|
13386
|
+
const doc = program.command('doc').description('按结构化计划生成/追加迭代任务文档');
|
|
13387
|
+
doc.command('diff').description('预览 plan.json 将产生的变更,不写盘').requiredOption('-i, --iteration <name>', '迭代目录名').requiredOption('--input <path>', 'plan.json 路径').option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').action((options)=>{
|
|
13388
|
+
runDocApply(options, 'diff');
|
|
13389
|
+
});
|
|
13390
|
+
doc.command('apply').description('把 plan.json 渲染进文档(新增需求与任务,已存在的不覆盖)').requiredOption('-i, --iteration <name>', '迭代目录名').requiredOption('--input <path>', 'plan.json 路径').option('--dry-run', '只打印将要发生的变更,不写盘').option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').action((options)=>{
|
|
13391
|
+
runDocApply(options);
|
|
13392
|
+
});
|
|
13393
|
+
registerDocMigrate(doc);
|
|
12004
13394
|
}
|
|
12005
13395
|
function requireQueryContext(options) {
|
|
12006
13396
|
const format = parseFormat(options.format);
|
|
@@ -12015,32 +13405,54 @@ function requireQueryContext(options) {
|
|
|
12015
13405
|
format
|
|
12016
13406
|
};
|
|
12017
13407
|
}
|
|
12018
|
-
function
|
|
13408
|
+
function resolveIteration(options, docsRoot, available, hints = {}) {
|
|
12019
13409
|
const explicit = options.iteration?.trim();
|
|
12020
13410
|
if (void 0 !== explicit && explicit.length > 0) {
|
|
12021
13411
|
const exact = available.find((item)=>item.name === explicit);
|
|
12022
|
-
if (void 0 !== exact) return
|
|
13412
|
+
if (void 0 !== exact) return {
|
|
13413
|
+
name: exact.name,
|
|
13414
|
+
source: 'explicit'
|
|
13415
|
+
};
|
|
12023
13416
|
const loose = available.find((item)=>item.name.toLowerCase() === explicit.toLowerCase());
|
|
12024
|
-
if (void 0 !== loose) return
|
|
13417
|
+
if (void 0 !== loose) return {
|
|
13418
|
+
name: loose.name,
|
|
13419
|
+
source: 'explicit'
|
|
13420
|
+
};
|
|
12025
13421
|
throw new errors_CliError(`迭代不存在:${explicit}\n可用迭代:${available.map((item)=>item.name).join('、') || '(无)'}`, errors_EXIT.NOT_FOUND);
|
|
12026
13422
|
}
|
|
13423
|
+
const key = hints.taskId ?? hints.requirementId;
|
|
13424
|
+
if (void 0 !== key) {
|
|
13425
|
+
const found = findIterationById(docsRoot, available, key);
|
|
13426
|
+
if (null !== found) return {
|
|
13427
|
+
name: found,
|
|
13428
|
+
source: 'id'
|
|
13429
|
+
};
|
|
13430
|
+
const list = available.map((item)=>item.name).join('、') || '(无)';
|
|
13431
|
+
throw new errors_CliError(`在所有迭代中都未找到 ${key}\n已检索:${list}\n请确认编号是否正确,或用 -i 指定迭代`, errors_EXIT.NOT_FOUND);
|
|
13432
|
+
}
|
|
13433
|
+
const byBranch = resolveIterationFromBranch(docsRoot, available.map((item)=>item.name));
|
|
13434
|
+
if (null !== byBranch.iteration) return {
|
|
13435
|
+
name: byBranch.iteration,
|
|
13436
|
+
source: 'branch',
|
|
13437
|
+
branch: byBranch.branch ?? void 0
|
|
13438
|
+
};
|
|
12027
13439
|
const cwd = process.cwd();
|
|
12028
13440
|
if (cwd.startsWith(docsRoot)) {
|
|
12029
13441
|
const first = cwd.slice(docsRoot.length).split('/').filter((item)=>item.length > 0)[0];
|
|
12030
13442
|
if (void 0 !== first) {
|
|
12031
13443
|
const hit = available.find((item)=>item.name.toLowerCase() === first.toLowerCase());
|
|
12032
|
-
if (void 0 !== hit) return
|
|
13444
|
+
if (void 0 !== hit) return {
|
|
13445
|
+
name: hit.name,
|
|
13446
|
+
source: 'cwd'
|
|
13447
|
+
};
|
|
12033
13448
|
}
|
|
12034
13449
|
}
|
|
12035
|
-
const key = hints.taskId ?? hints.requirementId;
|
|
12036
|
-
if (void 0 !== key) {
|
|
12037
|
-
const found = findIterationById(docsRoot, available, key);
|
|
12038
|
-
if (null !== found) return found;
|
|
12039
|
-
const list = available.map((item)=>item.name).join('、') || '(无)';
|
|
12040
|
-
throw new errors_CliError(`在所有迭代中都未找到 ${key}\n已检索:${list}\n请确认编号是否正确,或用 -i 指定迭代`, errors_EXIT.NOT_FOUND);
|
|
12041
|
-
}
|
|
12042
13450
|
const list = available.map((item)=>item.name).join('、') || '(无)';
|
|
12043
|
-
|
|
13451
|
+
const branchHint = byBranch.candidates.length > 0 ? `\n当前分支 ${byBranch.branch ?? ''} 同时匹配多个迭代:${byBranch.candidates.join('、')}` : null !== byBranch.branch ? `\n当前分支 ${byBranch.branch} 未匹配到任何迭代` : '';
|
|
13452
|
+
throw new errors_CliError(`无法确定迭代目录,请用 -i 指定。${branchHint}\n可用迭代:${list}`, errors_EXIT.NOT_FOUND);
|
|
13453
|
+
}
|
|
13454
|
+
function resolveIterationName(options, docsRoot, available, hints = {}) {
|
|
13455
|
+
return resolveIteration(options, docsRoot, available, hints).name;
|
|
12044
13456
|
}
|
|
12045
13457
|
function findIterationById(docsRoot, available, id) {
|
|
12046
13458
|
const normalized = id.trim();
|
|
@@ -12075,6 +13487,18 @@ function loadDeveloperDocs(docsRoot, iteration) {
|
|
|
12075
13487
|
doc: readIterationDoc(docsRoot, entry.name, item.id, 'local')
|
|
12076
13488
|
}));
|
|
12077
13489
|
}
|
|
13490
|
+
function describeIterationSource(resolved) {
|
|
13491
|
+
switch(resolved.source){
|
|
13492
|
+
case 'explicit':
|
|
13493
|
+
return '-i 指定';
|
|
13494
|
+
case 'id':
|
|
13495
|
+
return '编号反查';
|
|
13496
|
+
case 'branch':
|
|
13497
|
+
return `当前分支 ${resolved.branch ?? ''}`;
|
|
13498
|
+
case 'cwd':
|
|
13499
|
+
return '当前目录';
|
|
13500
|
+
}
|
|
13501
|
+
}
|
|
12078
13502
|
function evaluateReadiness(tasks) {
|
|
12079
13503
|
const byId = new Map(tasks.map((task)=>[
|
|
12080
13504
|
task.id,
|
|
@@ -12111,6 +13535,7 @@ function buildTaskRows(docs) {
|
|
|
12111
13535
|
requirementId: task.requirementId,
|
|
12112
13536
|
type: task.type,
|
|
12113
13537
|
terminal: task.terminal,
|
|
13538
|
+
scope: task.scope,
|
|
12114
13539
|
status: task.status,
|
|
12115
13540
|
selfTest: task.selfTest,
|
|
12116
13541
|
acceptance: task.acceptance,
|
|
@@ -12134,12 +13559,48 @@ function mergeRequirements(docs) {
|
|
|
12134
13559
|
note: requirement.note,
|
|
12135
13560
|
updatedAt: requirement.updatedAt,
|
|
12136
13561
|
developers: [],
|
|
12137
|
-
taskIds: []
|
|
13562
|
+
taskIds: [],
|
|
13563
|
+
sides: {
|
|
13564
|
+
frontend: {
|
|
13565
|
+
done: 0,
|
|
13566
|
+
total: 0
|
|
13567
|
+
},
|
|
13568
|
+
backend: {
|
|
13569
|
+
done: 0,
|
|
13570
|
+
total: 0
|
|
13571
|
+
}
|
|
13572
|
+
}
|
|
12138
13573
|
};
|
|
12139
13574
|
if (!entry.developers.includes(developer)) entry.developers.push(developer);
|
|
12140
13575
|
for (const taskId of requirement.taskIds)if (!entry.taskIds.includes(taskId)) entry.taskIds.push(taskId);
|
|
12141
13576
|
map.set(requirement.id, entry);
|
|
12142
13577
|
}
|
|
13578
|
+
const byTaskId = new Map();
|
|
13579
|
+
for (const row of buildTaskRows(docs))byTaskId.set(row.id, {
|
|
13580
|
+
scope: row.scope,
|
|
13581
|
+
done: '已完成' === row.status
|
|
13582
|
+
});
|
|
13583
|
+
for (const entry of map.values()){
|
|
13584
|
+
entry.sides = {
|
|
13585
|
+
frontend: {
|
|
13586
|
+
done: 0,
|
|
13587
|
+
total: 0
|
|
13588
|
+
},
|
|
13589
|
+
backend: {
|
|
13590
|
+
done: 0,
|
|
13591
|
+
total: 0
|
|
13592
|
+
}
|
|
13593
|
+
};
|
|
13594
|
+
for (const taskId of entry.taskIds){
|
|
13595
|
+
const info = byTaskId.get(taskId);
|
|
13596
|
+
if (void 0 === info) continue;
|
|
13597
|
+
const bucket = '前端' === info.scope ? entry.sides.frontend : '后端' === info.scope ? entry.sides.backend : null;
|
|
13598
|
+
if (null !== bucket) {
|
|
13599
|
+
bucket.total += 1;
|
|
13600
|
+
if (info.done) bucket.done += 1;
|
|
13601
|
+
}
|
|
13602
|
+
}
|
|
13603
|
+
}
|
|
12143
13604
|
return [
|
|
12144
13605
|
...map.values()
|
|
12145
13606
|
].sort((left, right)=>left.id.localeCompare(right.id));
|
|
@@ -12149,16 +13610,19 @@ function filterDocs(docs, developer) {
|
|
|
12149
13610
|
if (void 0 === target || 0 === target.length) return docs;
|
|
12150
13611
|
return docs.filter((item)=>item.developer === target);
|
|
12151
13612
|
}
|
|
12152
|
-
function
|
|
12153
|
-
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
|
|
13613
|
+
function collectSideIssues(options) {
|
|
13614
|
+
try {
|
|
13615
|
+
const loaded = requireConfig(options.config);
|
|
13616
|
+
return checkDocTaskSides({
|
|
13617
|
+
docsRoot: options.docsRoot,
|
|
13618
|
+
iteration: options.iteration,
|
|
13619
|
+
developer: options.developer,
|
|
13620
|
+
role: loaded.config.profile.role,
|
|
13621
|
+
terminals: loaded.config.terminals
|
|
13622
|
+
}).issues.filter((issue)=>'error' === issue.level).map((issue)=>issue.message);
|
|
13623
|
+
} catch {
|
|
13624
|
+
return [];
|
|
12160
13625
|
}
|
|
12161
|
-
throw new errors_CliError('缺少 --iteration(迭代目录名),或在文档仓库的迭代目录内执行', errors_EXIT.USAGE);
|
|
12162
13626
|
}
|
|
12163
13627
|
function resolveDeveloper(options, configured) {
|
|
12164
13628
|
const explicit = options.developer?.trim();
|
|
@@ -12187,7 +13651,7 @@ function requireWriteContext(options) {
|
|
|
12187
13651
|
}
|
|
12188
13652
|
function runAction(action, taskId, options) {
|
|
12189
13653
|
const { docsRoot, developer, policy } = requireWriteContext(options);
|
|
12190
|
-
const iteration = options.iteration?.trim() ?
|
|
13654
|
+
const iteration = options.iteration?.trim() ? resolveIterationName(options, docsRoot, loadIterations(docsRoot)) : resolveIterationName(options, docsRoot, loadIterations(docsRoot), {
|
|
12191
13655
|
taskId: taskId.trim().replace(/^#?/, '#')
|
|
12192
13656
|
});
|
|
12193
13657
|
const format = parseFormat(options.format);
|
|
@@ -12218,15 +13682,28 @@ function runAction(action, taskId, options) {
|
|
|
12218
13682
|
action,
|
|
12219
13683
|
policy
|
|
12220
13684
|
});
|
|
12221
|
-
|
|
13685
|
+
const sideIssues = collectSideIssues({
|
|
13686
|
+
docsRoot,
|
|
13687
|
+
iteration,
|
|
13688
|
+
developer,
|
|
13689
|
+
config: options.config
|
|
13690
|
+
});
|
|
13691
|
+
if ('json' === format) return void printJson({
|
|
13692
|
+
...result,
|
|
13693
|
+
sideIssues
|
|
13694
|
+
});
|
|
12222
13695
|
printLine(result.message);
|
|
12223
13696
|
for (const change of result.changes)printLine(` · ${change}`);
|
|
12224
13697
|
printLine(`文档:${result.file}`);
|
|
12225
13698
|
if (void 0 !== result.git) printLine(`git:${result.git.message}`);
|
|
13699
|
+
if (sideIssues.length > 0) {
|
|
13700
|
+
printLine('\n注意:该文档存在任务类型与终端归属不一致(可用 ylcwf doctor --docs 复查):');
|
|
13701
|
+
for (const message of sideIssues)printLine(` · ${message}`);
|
|
13702
|
+
}
|
|
12226
13703
|
}
|
|
12227
13704
|
function runActions(options) {
|
|
12228
13705
|
const { docsRoot, developer } = requireWriteContext(options);
|
|
12229
|
-
const iteration =
|
|
13706
|
+
const iteration = resolveIterationName(options, docsRoot, loadIterations(docsRoot));
|
|
12230
13707
|
const actions = availableActions({
|
|
12231
13708
|
docsRoot,
|
|
12232
13709
|
iteration,
|
|
@@ -12247,7 +13724,7 @@ function runActions(options) {
|
|
|
12247
13724
|
}
|
|
12248
13725
|
function runBatch(action, taskIds, options) {
|
|
12249
13726
|
const { docsRoot, developer, policy } = requireWriteContext(options);
|
|
12250
|
-
const iteration =
|
|
13727
|
+
const iteration = resolveIterationName(options, docsRoot, loadIterations(docsRoot));
|
|
12251
13728
|
const format = parseFormat(options.format);
|
|
12252
13729
|
const result = applyBatchAction({
|
|
12253
13730
|
docsRoot,
|
|
@@ -12264,7 +13741,7 @@ function runBatch(action, taskIds, options) {
|
|
|
12264
13741
|
}
|
|
12265
13742
|
function runHistory(taskId, options) {
|
|
12266
13743
|
const { docsRoot, developer } = requireWriteContext(options);
|
|
12267
|
-
const iteration =
|
|
13744
|
+
const iteration = resolveIterationName(options, docsRoot, loadIterations(docsRoot));
|
|
12268
13745
|
const entries = readTaskHistory({
|
|
12269
13746
|
iteration,
|
|
12270
13747
|
developer,
|
|
@@ -12280,16 +13757,19 @@ function runHistory(taskId, options) {
|
|
|
12280
13757
|
}
|
|
12281
13758
|
function runList(options) {
|
|
12282
13759
|
const ctx = requireQueryContext(options);
|
|
12283
|
-
const
|
|
13760
|
+
const resolved = resolveIteration(options, ctx.docsRoot, loadIterations(ctx.docsRoot));
|
|
13761
|
+
const iteration = resolved.name;
|
|
12284
13762
|
const docs = loadDeveloperDocs(ctx.docsRoot, iteration);
|
|
12285
13763
|
const developerFilter = options.developer?.trim();
|
|
12286
13764
|
const statusFilter = options.status?.trim();
|
|
12287
13765
|
const tasks = buildTaskRows(filterDocs(docs, developerFilter)).filter((task)=>void 0 === statusFilter ? true : task.status === statusFilter);
|
|
12288
13766
|
if ('json' === ctx.format) return void printJson({
|
|
12289
13767
|
iteration,
|
|
13768
|
+
iterationSource: describeIterationSource(resolved),
|
|
12290
13769
|
tasks
|
|
12291
13770
|
});
|
|
12292
13771
|
if (0 === tasks.length) return void printLine(`迭代 ${iteration} 没有符合条件的任务`);
|
|
13772
|
+
if ('explicit' !== resolved.source) printLine(`迭代:${iteration}(来自${describeIterationSource(resolved)})`);
|
|
12293
13773
|
const rows = tasks.map((task)=>[
|
|
12294
13774
|
task.id,
|
|
12295
13775
|
task.name,
|
|
@@ -12461,9 +13941,26 @@ function iteration_runShow(name, options) {
|
|
|
12461
13941
|
}
|
|
12462
13942
|
}
|
|
12463
13943
|
}
|
|
13944
|
+
function runCurrent(options) {
|
|
13945
|
+
const format = parseFormat(options.format);
|
|
13946
|
+
const ctx = requireQueryContext(options);
|
|
13947
|
+
const iterations = loadIterations(ctx.docsRoot).map((item)=>item.name);
|
|
13948
|
+
const result = resolveIterationFromBranch(ctx.docsRoot, iterations);
|
|
13949
|
+
if ('json' === format) return void printJson({
|
|
13950
|
+
ok: true,
|
|
13951
|
+
...result,
|
|
13952
|
+
available: iterations
|
|
13953
|
+
});
|
|
13954
|
+
printLine(`分支:${result.branch ?? '(detached HEAD)'}`);
|
|
13955
|
+
if (null !== result.iteration) return void printLine(`迭代:${result.iteration}`);
|
|
13956
|
+
if (result.candidates.length > 0) return void printLine(`分支名同时匹配多个迭代,请显式指定 -i:${result.candidates.join('、')}`);
|
|
13957
|
+
printLine('迭代:未从分支名识别出迭代目录');
|
|
13958
|
+
if (iterations.length > 0) printLine(`可用迭代:${iterations.join('、')}`);
|
|
13959
|
+
}
|
|
12464
13960
|
function registerIteration(program) {
|
|
12465
13961
|
const iteration = program.command('iteration').description('查看文档仓库中的迭代');
|
|
12466
13962
|
iteration.command('list').description('列出全部迭代(目录名即迭代名)').option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').action((options)=>iteration_runList(options));
|
|
13963
|
+
iteration.command('current').description('从文档仓库当前分支推导迭代名(团队约定:一迭代一分支)').option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').action((options)=>runCurrent(options));
|
|
12467
13964
|
iteration.command('show [name]').description('查看迭代汇总:成员进度与阻塞任务').option('-c, --config <path>', '指定配置文件路径').option('-i, --iteration <name>', '迭代目录名(也可作为位置参数)').option('--format <format>', '输出格式:human | json', 'human').action((name, options)=>iteration_runShow(name, options));
|
|
12468
13965
|
}
|
|
12469
13966
|
function runContext(options) {
|
|
@@ -12664,9 +14161,9 @@ async function fetchManifest(url) {
|
|
|
12664
14161
|
const payload = await response.json();
|
|
12665
14162
|
if ('string' != typeof payload.version || 0 === payload.version.length) return null;
|
|
12666
14163
|
return {
|
|
12667
|
-
current: "0.
|
|
14164
|
+
current: "0.5.1",
|
|
12668
14165
|
latest: payload.version,
|
|
12669
|
-
hasUpdate: isNewer(payload.version, "0.
|
|
14166
|
+
hasUpdate: isNewer(payload.version, "0.5.1"),
|
|
12670
14167
|
downloadUrl: 'string' == typeof payload.downloadUrl ? payload.downloadUrl : null,
|
|
12671
14168
|
source: 'manifest',
|
|
12672
14169
|
checkedAt: new Date().toISOString(),
|
|
@@ -12678,7 +14175,7 @@ async function fetchManifest(url) {
|
|
|
12678
14175
|
}
|
|
12679
14176
|
async function fetchNpm() {
|
|
12680
14177
|
const base = {
|
|
12681
|
-
current: "0.
|
|
14178
|
+
current: "0.5.1",
|
|
12682
14179
|
latest: null,
|
|
12683
14180
|
hasUpdate: false,
|
|
12684
14181
|
downloadUrl: null,
|
|
@@ -12705,8 +14202,8 @@ async function fetchNpm() {
|
|
|
12705
14202
|
return {
|
|
12706
14203
|
...base,
|
|
12707
14204
|
latest,
|
|
12708
|
-
hasUpdate: isNewer(latest, "0.
|
|
12709
|
-
downloadUrl:
|
|
14205
|
+
hasUpdate: isNewer(latest, "0.5.1"),
|
|
14206
|
+
downloadUrl: null
|
|
12710
14207
|
};
|
|
12711
14208
|
} catch (error) {
|
|
12712
14209
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -12796,7 +14293,7 @@ async function runUpgrade(options) {
|
|
|
12796
14293
|
const kind = detectInstallKind();
|
|
12797
14294
|
const result = await checkUpdate(true);
|
|
12798
14295
|
const target = options.to?.trim() ?? result.latest;
|
|
12799
|
-
printLine("当前版本:0.
|
|
14296
|
+
printLine("当前版本:0.5.1");
|
|
12800
14297
|
if (null !== result.error) printLine(`版本查询失败:${result.error}`);
|
|
12801
14298
|
else if (null !== result.latest) printLine(`最新版本:${result.latest}(来源:${result.source})`);
|
|
12802
14299
|
if (null === target) throw new errors_CliError('无法确定目标版本,请稍后重试或用 --to 指定', errors_EXIT.NOT_FOUND);
|
|
@@ -12951,6 +14448,49 @@ function registerResolve(program) {
|
|
|
12951
14448
|
runResolve(name, options);
|
|
12952
14449
|
});
|
|
12953
14450
|
}
|
|
14451
|
+
function checkDocsSides(config) {
|
|
14452
|
+
const messages = [];
|
|
14453
|
+
const root = config.docs.root;
|
|
14454
|
+
let iterations;
|
|
14455
|
+
try {
|
|
14456
|
+
iterations = external_node_fs_readdirSync(root).filter((name)=>!name.startsWith('.') && ![
|
|
14457
|
+
"scripts",
|
|
14458
|
+
'skills',
|
|
14459
|
+
'_prd'
|
|
14460
|
+
].includes(name)).filter((name)=>{
|
|
14461
|
+
try {
|
|
14462
|
+
return statSync(external_node_path_join(root, name)).isDirectory();
|
|
14463
|
+
} catch {
|
|
14464
|
+
return false;
|
|
14465
|
+
}
|
|
14466
|
+
});
|
|
14467
|
+
} catch {
|
|
14468
|
+
return [
|
|
14469
|
+
{
|
|
14470
|
+
level: 'warning',
|
|
14471
|
+
message: `无法读取文档仓库:${root}`
|
|
14472
|
+
}
|
|
14473
|
+
];
|
|
14474
|
+
}
|
|
14475
|
+
for (const iteration of iterations)try {
|
|
14476
|
+
const report = checkDocTaskSides({
|
|
14477
|
+
docsRoot: root,
|
|
14478
|
+
iteration,
|
|
14479
|
+
developer: config.profile.developer,
|
|
14480
|
+
role: config.profile.role,
|
|
14481
|
+
terminals: config.terminals
|
|
14482
|
+
});
|
|
14483
|
+
for (const issue of report.issues)messages.push({
|
|
14484
|
+
level: issue.level,
|
|
14485
|
+
message: `[${iteration}] ${issue.message}`
|
|
14486
|
+
});
|
|
14487
|
+
if (report.skipped > 0) messages.push({
|
|
14488
|
+
level: 'warning',
|
|
14489
|
+
message: `[${iteration}] ${report.checked} 个任务完成归属校验,${report.skipped} 个因终端未配置/歧义被跳过(跳过≠通过)`
|
|
14490
|
+
});
|
|
14491
|
+
} catch {}
|
|
14492
|
+
return messages;
|
|
14493
|
+
}
|
|
12954
14494
|
function runDoctor(options) {
|
|
12955
14495
|
const format = parseFormat(options.format);
|
|
12956
14496
|
const loaded = loadConfig(options.config);
|
|
@@ -12960,21 +14500,31 @@ function runDoctor(options) {
|
|
|
12960
14500
|
});
|
|
12961
14501
|
const errors = countIssues(checked.issues).errors;
|
|
12962
14502
|
const ok = !hasError(checked.issues);
|
|
14503
|
+
const sideIssues = [];
|
|
14504
|
+
if (true === options.docs && null !== checked.config && ok) sideIssues.push(...checkDocsSides(checked.config));
|
|
14505
|
+
const sideErrors = sideIssues.filter((item)=>'error' === item.level).length;
|
|
14506
|
+
const allOk = ok && 0 === sideErrors;
|
|
12963
14507
|
if ('json' === format) printJson({
|
|
12964
|
-
ok,
|
|
14508
|
+
ok: allOk,
|
|
12965
14509
|
configPath: loaded.path,
|
|
12966
14510
|
...countIssues(checked.issues),
|
|
12967
|
-
issues: checked.issues
|
|
14511
|
+
issues: checked.issues,
|
|
14512
|
+
docSideIssues: sideIssues.map((item)=>`[${item.level}] ${item.message}`)
|
|
12968
14513
|
});
|
|
12969
14514
|
else {
|
|
12970
14515
|
printLine(`配置文件 ${loaded.path}`);
|
|
12971
14516
|
printLine(formatIssues(checked.issues, '校验通过,未发现问题'));
|
|
12972
|
-
if (
|
|
14517
|
+
if (sideIssues.length > 0) {
|
|
14518
|
+
printLine('');
|
|
14519
|
+
printLine('文档体检:');
|
|
14520
|
+
for (const item of sideIssues)printLine(` ${'error' === item.level ? '✗' : '!'} ${item.message}`);
|
|
14521
|
+
}
|
|
14522
|
+
if (!allOk) printLine(`\n校验失败:${errors} 项配置 error${sideErrors > 0 ? `,${sideErrors} 项文档问题` : ''}`);
|
|
12973
14523
|
}
|
|
12974
|
-
if (!
|
|
14524
|
+
if (!allOk) process.exitCode = errors_EXIT.INVALID;
|
|
12975
14525
|
}
|
|
12976
14526
|
function registerDoctor(program) {
|
|
12977
|
-
program.command('doctor').description('严格校验配置(schema、路径存在性、终端唯一性)').option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').action((options)=>{
|
|
14527
|
+
program.command('doctor').description('严格校验配置(schema、路径存在性、终端唯一性)').option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').option('--docs', '同时体检文档:检查任务类型与终端归属是否一致').action((options)=>{
|
|
12978
14528
|
runDoctor(options);
|
|
12979
14529
|
});
|
|
12980
14530
|
}
|
|
@@ -13137,7 +14687,7 @@ function readState(explicitPath) {
|
|
|
13137
14687
|
issues: checked.issues,
|
|
13138
14688
|
backups: listBackups(explicitPath),
|
|
13139
14689
|
meta: {
|
|
13140
|
-
version: "0.
|
|
14690
|
+
version: "0.5.1",
|
|
13141
14691
|
features: SERVER_FEATURES
|
|
13142
14692
|
}
|
|
13143
14693
|
};
|
|
@@ -13772,7 +15322,7 @@ function registerReset(program) {
|
|
|
13772
15322
|
}
|
|
13773
15323
|
function buildProgram() {
|
|
13774
15324
|
const program = new command_Command();
|
|
13775
|
-
program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与终端仓库映射').version("0.
|
|
15325
|
+
program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与终端仓库映射').version("0.5.1", '-v, --version', '显示版本号').showHelpAfterError();
|
|
13776
15326
|
registerInit(program);
|
|
13777
15327
|
registerShow(program);
|
|
13778
15328
|
registerGet(program);
|
|
@@ -13781,6 +15331,7 @@ function buildProgram() {
|
|
|
13781
15331
|
registerIteration(program);
|
|
13782
15332
|
registerContext(program);
|
|
13783
15333
|
registerRequirement(program);
|
|
15334
|
+
registerDoc(program);
|
|
13784
15335
|
registerTask(program);
|
|
13785
15336
|
registerUpgrade(program);
|
|
13786
15337
|
registerResolve(program);
|