ylcwf 0.5.1 → 0.5.2
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 +92 -3
- package/README.md +40 -6
- package/dist/index.js +1137 -276
- package/package.json +1 -1
- package/ui-dist/assets/index-B4CSJ3eM.js +80 -0
- package/ui-dist/assets/index-BO9VmR92.css +2 -0
- package/ui-dist/index.html +2 -2
- package/ui-dist/assets/index-B_FY7yA5.js +0 -80
- package/ui-dist/assets/index-CFsU6qYJ.css +0 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
|
-
import node_child_process, { execFileSync, spawn } from "node:child_process";
|
|
3
|
-
import node_path, { basename, dirname as external_node_path_dirname, extname, isAbsolute, join as external_node_path_join, relative as external_node_path_relative, resolve, sep } from "node:path";
|
|
2
|
+
import node_child_process, { execFile, execFileSync, spawn } from "node:child_process";
|
|
3
|
+
import node_path, { basename, dirname as external_node_path_dirname, extname, isAbsolute, join as external_node_path_join, relative as external_node_path_relative, resolve as external_node_path_resolve, sep } from "node:path";
|
|
4
4
|
import node_fs, { appendFileSync, chmodSync, closeSync, copyFileSync, existsSync as external_node_fs_existsSync, mkdirSync, openSync, readFileSync, readdirSync as external_node_fs_readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
5
5
|
import node_process, { stdin as external_node_process_stdin, stdout as external_node_process_stdout } from "node:process";
|
|
6
6
|
import { stripVTControlCharacters as external_node_util_stripVTControlCharacters, styleText as external_node_util_styleText } from "node:util";
|
|
@@ -9234,9 +9234,9 @@ const CONFIG_DIR = external_node_path_join(homedir(), '.ylcwf');
|
|
|
9234
9234
|
const DEFAULT_CONFIG_PATH = external_node_path_join(CONFIG_DIR, 'config.yaml');
|
|
9235
9235
|
function paths_resolveConfigPath(explicit) {
|
|
9236
9236
|
const fromFlag = explicit?.trim();
|
|
9237
|
-
if (void 0 !== fromFlag && fromFlag.length > 0) return isAbsolute(fromFlag) ? fromFlag :
|
|
9237
|
+
if (void 0 !== fromFlag && fromFlag.length > 0) return isAbsolute(fromFlag) ? fromFlag : external_node_path_resolve(process.cwd(), fromFlag);
|
|
9238
9238
|
const fromEnv = process.env['YLCWF_CONFIG']?.trim();
|
|
9239
|
-
if (void 0 !== fromEnv && fromEnv.length > 0) return isAbsolute(fromEnv) ? fromEnv :
|
|
9239
|
+
if (void 0 !== fromEnv && fromEnv.length > 0) return isAbsolute(fromEnv) ? fromEnv : external_node_path_resolve(process.cwd(), fromEnv);
|
|
9240
9240
|
return DEFAULT_CONFIG_PATH;
|
|
9241
9241
|
}
|
|
9242
9242
|
function serveTokenPath() {
|
|
@@ -9286,6 +9286,24 @@ function parsePathList(input) {
|
|
|
9286
9286
|
function escapeRegExp(input) {
|
|
9287
9287
|
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
9288
9288
|
}
|
|
9289
|
+
function roundProgressPercent(done, total) {
|
|
9290
|
+
if (total <= 0) return 0;
|
|
9291
|
+
return roundHalfEven(done / total * 100);
|
|
9292
|
+
}
|
|
9293
|
+
function roundHalfEven(value) {
|
|
9294
|
+
const floor = Math.floor(value);
|
|
9295
|
+
const diff = value - floor;
|
|
9296
|
+
if (diff > 0.5) return floor + 1;
|
|
9297
|
+
if (diff < 0.5) return floor;
|
|
9298
|
+
return floor % 2 === 0 ? floor : floor + 1;
|
|
9299
|
+
}
|
|
9300
|
+
function isAbsolutePath(value) {
|
|
9301
|
+
const input = value.trim();
|
|
9302
|
+
if (0 === input.length) return false;
|
|
9303
|
+
if (/^[a-zA-Z]:[\\/]/.test(input)) return true;
|
|
9304
|
+
if (/^[\\/]{2}[^\\/]/.test(input)) return true;
|
|
9305
|
+
return input.startsWith('/');
|
|
9306
|
+
}
|
|
9289
9307
|
const ROLES = [
|
|
9290
9308
|
'frontend',
|
|
9291
9309
|
'backend',
|
|
@@ -9306,7 +9324,11 @@ const PROFILE_KEYS = new Set([
|
|
|
9306
9324
|
]);
|
|
9307
9325
|
const DOCS_KEYS = new Set([
|
|
9308
9326
|
'root',
|
|
9309
|
-
'git'
|
|
9327
|
+
'git',
|
|
9328
|
+
'validator'
|
|
9329
|
+
]);
|
|
9330
|
+
const VALIDATOR_KEYS = new Set([
|
|
9331
|
+
'requireScript'
|
|
9310
9332
|
]);
|
|
9311
9333
|
const GIT_KEYS = new Set([
|
|
9312
9334
|
'cli',
|
|
@@ -9320,6 +9342,9 @@ const DEFAULT_GIT_POLICY = {
|
|
|
9320
9342
|
commit: true,
|
|
9321
9343
|
push: false
|
|
9322
9344
|
};
|
|
9345
|
+
const DEFAULT_VALIDATOR_POLICY = {
|
|
9346
|
+
requireScript: true
|
|
9347
|
+
};
|
|
9323
9348
|
const TERMINAL_KEYS = new Set([
|
|
9324
9349
|
'aliases',
|
|
9325
9350
|
'repos'
|
|
@@ -9363,7 +9388,7 @@ function checkAbsolutePath(value, where, issues, required) {
|
|
|
9363
9388
|
issues.push(schema_error('FIELD_TYPE', '必须是绝对路径字符串', where));
|
|
9364
9389
|
return null;
|
|
9365
9390
|
}
|
|
9366
|
-
if (!
|
|
9391
|
+
if (!isAbsolutePath(value)) {
|
|
9367
9392
|
issues.push(schema_error('PATH_NOT_ABSOLUTE', `必须是绝对路径:${value}`, where));
|
|
9368
9393
|
return null;
|
|
9369
9394
|
}
|
|
@@ -9427,9 +9452,33 @@ function parseDocs(raw, options, issues) {
|
|
|
9427
9452
|
}
|
|
9428
9453
|
const git = parseGitPolicy(raw['git'], issues);
|
|
9429
9454
|
if (null === git) return null;
|
|
9455
|
+
const validator = parseValidatorPolicy(raw['validator'], issues);
|
|
9456
|
+
if (null === validator) return null;
|
|
9430
9457
|
return {
|
|
9431
9458
|
root,
|
|
9432
|
-
git
|
|
9459
|
+
git,
|
|
9460
|
+
validator
|
|
9461
|
+
};
|
|
9462
|
+
}
|
|
9463
|
+
function parseValidatorPolicy(raw, issues) {
|
|
9464
|
+
if (null == raw) return {
|
|
9465
|
+
...DEFAULT_VALIDATOR_POLICY
|
|
9466
|
+
};
|
|
9467
|
+
if (!utils_isRecord(raw)) {
|
|
9468
|
+
issues.push(schema_error('VALIDATOR_POLICY_INVALID', 'docs.validator 必须是对象', 'docs.validator'));
|
|
9469
|
+
return null;
|
|
9470
|
+
}
|
|
9471
|
+
issues.push(...unknownKeys(raw, VALIDATOR_KEYS, 'docs.validator'));
|
|
9472
|
+
const value = raw['requireScript'];
|
|
9473
|
+
if (void 0 === value) return {
|
|
9474
|
+
...DEFAULT_VALIDATOR_POLICY
|
|
9475
|
+
};
|
|
9476
|
+
if ('boolean' != typeof value) {
|
|
9477
|
+
issues.push(schema_error('VALIDATOR_POLICY_INVALID', 'docs.validator.requireScript 必须是布尔值', 'docs.validator.requireScript'));
|
|
9478
|
+
return null;
|
|
9479
|
+
}
|
|
9480
|
+
return {
|
|
9481
|
+
requireScript: value
|
|
9433
9482
|
};
|
|
9434
9483
|
}
|
|
9435
9484
|
function parseGitPolicy(raw, issues) {
|
|
@@ -9505,7 +9554,7 @@ function parseRepos(raw, where, issues) {
|
|
|
9505
9554
|
valid = false;
|
|
9506
9555
|
continue;
|
|
9507
9556
|
}
|
|
9508
|
-
if (!
|
|
9557
|
+
if (!isAbsolutePath(item)) {
|
|
9509
9558
|
issues.push(schema_error('PATH_NOT_ABSOLUTE', `仓库路径必须是绝对路径:${item}`, whereSide));
|
|
9510
9559
|
valid = false;
|
|
9511
9560
|
continue;
|
|
@@ -10144,6 +10193,10 @@ function renderHuman(path, config, issues) {
|
|
|
10144
10193
|
[
|
|
10145
10194
|
'默认角色',
|
|
10146
10195
|
ROLE_LABEL[config.profile.role]
|
|
10196
|
+
],
|
|
10197
|
+
[
|
|
10198
|
+
'文档校验',
|
|
10199
|
+
config.docs.validator.requireScript ? '强制由文档仓库脚本裁决(缺脚本或 python 时拒绝写入)' : '宽松:脚本不可用时仅告警'
|
|
10147
10200
|
]
|
|
10148
10201
|
]).join('\n'));
|
|
10149
10202
|
const names = Object.keys(config.terminals);
|
|
@@ -10392,7 +10445,7 @@ const terminal_SIDE_LABEL = {
|
|
|
10392
10445
|
frontend: '前端',
|
|
10393
10446
|
backend: '后端'
|
|
10394
10447
|
};
|
|
10395
|
-
function
|
|
10448
|
+
function terminal_collect(value, previous) {
|
|
10396
10449
|
return [
|
|
10397
10450
|
...previous,
|
|
10398
10451
|
value
|
|
@@ -10592,7 +10645,7 @@ function registerTerminal(program) {
|
|
|
10592
10645
|
terminal.command('list').description('列出全部终端').option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').action((options)=>{
|
|
10593
10646
|
runTerminalList(options);
|
|
10594
10647
|
});
|
|
10595
|
-
terminal.command('add <key>').description('新增终端(终端名用 PRD 中的取值,可为中文)').option('-c, --config <path>', '指定配置文件路径').option('--frontend <path>', '前端仓库绝对路径,可重复',
|
|
10648
|
+
terminal.command('add <key>').description('新增终端(终端名用 PRD 中的取值,可为中文)').option('-c, --config <path>', '指定配置文件路径').option('--frontend <path>', '前端仓库绝对路径,可重复', terminal_collect, []).option('--backend <path>', '后端仓库绝对路径,可重复', terminal_collect, []).option('--alias <name>', '别名,可重复', terminal_collect, []).action((key, options)=>{
|
|
10596
10649
|
runTerminalAdd(key, options);
|
|
10597
10650
|
});
|
|
10598
10651
|
terminal.command('set <key>').description('修改终端别名(仓库增删用 terminal repo)').option('-c, --config <path>', '指定配置文件路径').option('--aliases <list>', '别名,逗号分隔(整体替换)').action((key, options)=>{
|
|
@@ -10612,6 +10665,78 @@ function registerTerminal(program) {
|
|
|
10612
10665
|
runTerminalRepoRemove(key, options);
|
|
10613
10666
|
});
|
|
10614
10667
|
}
|
|
10668
|
+
function aggregateRequirement(statuses) {
|
|
10669
|
+
if (0 === statuses.length) return {
|
|
10670
|
+
status: '未开始',
|
|
10671
|
+
progress: 0
|
|
10672
|
+
};
|
|
10673
|
+
if (statuses.every((status)=>'未开始' === status)) return {
|
|
10674
|
+
status: '未开始',
|
|
10675
|
+
progress: 0
|
|
10676
|
+
};
|
|
10677
|
+
if (statuses.every((status)=>'已完成' === status)) return {
|
|
10678
|
+
status: '已完成',
|
|
10679
|
+
progress: 100
|
|
10680
|
+
};
|
|
10681
|
+
const done = statuses.filter((status)=>'已完成' === status).length;
|
|
10682
|
+
return {
|
|
10683
|
+
status: '进行中',
|
|
10684
|
+
progress: roundProgressPercent(done, statuses.length)
|
|
10685
|
+
};
|
|
10686
|
+
}
|
|
10687
|
+
function resolveAggregates(docsRoot, lists) {
|
|
10688
|
+
const fallback = ()=>{
|
|
10689
|
+
const result = new Map();
|
|
10690
|
+
for (const [requirementId, statuses] of lists)result.set(requirementId, aggregateRequirement(statuses));
|
|
10691
|
+
return result;
|
|
10692
|
+
};
|
|
10693
|
+
if (0 === lists.size) return new Map();
|
|
10694
|
+
const remote = aggregateViaPython(docsRoot, lists);
|
|
10695
|
+
if (null !== remote) return remote;
|
|
10696
|
+
process.stderr.write("警告:未调用文档仓库 validate_task_doc.py --aggregate,需求状态与进度由本地实现计算;请确认文档仓库脚本已更新且本机具备 python3\n");
|
|
10697
|
+
return fallback();
|
|
10698
|
+
}
|
|
10699
|
+
function aggregateViaPython(docsRoot, lists) {
|
|
10700
|
+
const script = external_node_path_join(docsRoot, "scripts", 'validate_task_doc.py');
|
|
10701
|
+
if (!external_node_fs_existsSync(script)) return null;
|
|
10702
|
+
const payload = {};
|
|
10703
|
+
for (const [requirementId, statuses] of lists)payload[requirementId] = statuses;
|
|
10704
|
+
const input = JSON.stringify(payload);
|
|
10705
|
+
for (const bin of [
|
|
10706
|
+
'python3',
|
|
10707
|
+
'python',
|
|
10708
|
+
'py'
|
|
10709
|
+
])try {
|
|
10710
|
+
const stdout = execFileSync(bin, [
|
|
10711
|
+
script,
|
|
10712
|
+
'--aggregate'
|
|
10713
|
+
], {
|
|
10714
|
+
input,
|
|
10715
|
+
encoding: 'utf8',
|
|
10716
|
+
timeout: 10000,
|
|
10717
|
+
maxBuffer: 4194304,
|
|
10718
|
+
stdio: [
|
|
10719
|
+
'pipe',
|
|
10720
|
+
'pipe',
|
|
10721
|
+
'pipe'
|
|
10722
|
+
]
|
|
10723
|
+
});
|
|
10724
|
+
const parsed = JSON.parse(stdout);
|
|
10725
|
+
if (true !== parsed.ok || void 0 === parsed.data) return null;
|
|
10726
|
+
const result = new Map();
|
|
10727
|
+
for (const [requirementId, value] of Object.entries(parsed.data)){
|
|
10728
|
+
if ('string' != typeof value.status || 'number' != typeof value.progress) return null;
|
|
10729
|
+
result.set(requirementId, {
|
|
10730
|
+
status: value.status,
|
|
10731
|
+
progress: value.progress
|
|
10732
|
+
});
|
|
10733
|
+
}
|
|
10734
|
+
return result;
|
|
10735
|
+
} catch {
|
|
10736
|
+
continue;
|
|
10737
|
+
}
|
|
10738
|
+
return null;
|
|
10739
|
+
}
|
|
10615
10740
|
function normalizeIterationKey(value) {
|
|
10616
10741
|
return value.trim().toLowerCase().replace(/[-_.\s]+/g, '-');
|
|
10617
10742
|
}
|
|
@@ -10747,6 +10872,12 @@ function parseDocSchema(raw, docsRoot) {
|
|
|
10747
10872
|
if (!headers.includes(value)) fail(docsRoot, `${where}.keys.${semantic} 指向的列「${value}」不在 headers 中`);
|
|
10748
10873
|
result[semantic] = value;
|
|
10749
10874
|
}
|
|
10875
|
+
for (const [semantic, value] of Object.entries(record))if (void 0 === result[semantic]) {
|
|
10876
|
+
if ('string' == typeof value && 0 !== value.trim().length) {
|
|
10877
|
+
if (!headers.includes(value)) fail(docsRoot, `${where}.keys.${semantic} 指向的列「${value}」不在 headers 中`);
|
|
10878
|
+
result[semantic] = value;
|
|
10879
|
+
}
|
|
10880
|
+
}
|
|
10750
10881
|
return result;
|
|
10751
10882
|
};
|
|
10752
10883
|
const progressRaw = requirementTable.progressRange;
|
|
@@ -11096,8 +11227,9 @@ function validatePlanReferences(options) {
|
|
|
11096
11227
|
const knownRepos = new Set();
|
|
11097
11228
|
for (const [name] of options.index.byName)knownRepos.add(name);
|
|
11098
11229
|
const requirementCodes = new Set(options.plan.requirements.map((item)=>item.code));
|
|
11230
|
+
const knownRequirements = new Set(options.knownRequirements ?? []);
|
|
11099
11231
|
for (const task of options.plan.tasks){
|
|
11100
|
-
if (!requirementCodes.has(task.requirement)) docplan_fail(`任务「${task.name}」关联的需求 ${task.requirement}
|
|
11232
|
+
if (!requirementCodes.has(task.requirement) && !knownRequirements.has(task.requirement)) docplan_fail(`任务「${task.name}」关联的需求 ${task.requirement} 既不在 requirements 中,也不在文档现有需求里`);
|
|
11101
11233
|
if (knownRepos.size > 0 && !isKnownRepo(options.index, task.terminal)) process.stderr.write(`提示:任务「${task.name}」的终端「${task.terminal}」不在本机终端配置中,跳过归属校验\n`);
|
|
11102
11234
|
for (const dependency of task.dependsOn ?? []){
|
|
11103
11235
|
const normalized = dependency.startsWith('#') ? dependency : `#${dependency}`;
|
|
@@ -11138,16 +11270,78 @@ function nextSequence(existingTasks) {
|
|
|
11138
11270
|
}
|
|
11139
11271
|
return counters;
|
|
11140
11272
|
}
|
|
11141
|
-
function
|
|
11142
|
-
|
|
11143
|
-
if (
|
|
11144
|
-
|
|
11145
|
-
|
|
11273
|
+
function resolveExistingRequirement(requirements, code) {
|
|
11274
|
+
const found = requirements.find((item)=>item.id === code);
|
|
11275
|
+
if (void 0 === found) return;
|
|
11276
|
+
return {
|
|
11277
|
+
code: found.id,
|
|
11278
|
+
name: found.title,
|
|
11279
|
+
terminal: found.terminal,
|
|
11280
|
+
note: found.note
|
|
11281
|
+
};
|
|
11282
|
+
}
|
|
11283
|
+
function splitRow(line) {
|
|
11284
|
+
return line.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map((cell)=>cell.trim());
|
|
11146
11285
|
}
|
|
11147
|
-
function
|
|
11148
|
-
|
|
11149
|
-
const
|
|
11150
|
-
|
|
11286
|
+
function refreshRequirementRows(options) {
|
|
11287
|
+
const { schema, statusesByCode, codes, stamp, aggregate } = options;
|
|
11288
|
+
const lines = [
|
|
11289
|
+
...options.lines
|
|
11290
|
+
];
|
|
11291
|
+
const changes = [];
|
|
11292
|
+
const header = schema.requirementHeaders;
|
|
11293
|
+
const idKey = schema.requirementKeys.id;
|
|
11294
|
+
const statusKey = schema.requirementKeys.status;
|
|
11295
|
+
const progressKey = schema.requirementKeys.progress;
|
|
11296
|
+
const updatedAtKey = schema.requirementKeys.updatedAt;
|
|
11297
|
+
if (void 0 === idKey || void 0 === statusKey || void 0 === progressKey) return {
|
|
11298
|
+
lines,
|
|
11299
|
+
changes
|
|
11300
|
+
};
|
|
11301
|
+
const idIndex = header.indexOf(idKey);
|
|
11302
|
+
const statusIndex = header.indexOf(statusKey);
|
|
11303
|
+
const progressIndex = header.indexOf(progressKey);
|
|
11304
|
+
const updatedAtIndex = void 0 === updatedAtKey ? -1 : header.indexOf(updatedAtKey);
|
|
11305
|
+
if (idIndex < 0 || statusIndex < 0 || progressIndex < 0) return {
|
|
11306
|
+
lines,
|
|
11307
|
+
changes
|
|
11308
|
+
};
|
|
11309
|
+
const headerLine = `| ${header.join(' | ')} |`;
|
|
11310
|
+
let inTable = false;
|
|
11311
|
+
for(let index = 0; index < lines.length; index++){
|
|
11312
|
+
const line = lines[index] ?? '';
|
|
11313
|
+
const trimmed = line.trim();
|
|
11314
|
+
if (trimmed === headerLine) {
|
|
11315
|
+
inTable = true;
|
|
11316
|
+
continue;
|
|
11317
|
+
}
|
|
11318
|
+
if (!inTable) continue;
|
|
11319
|
+
if (!trimmed.startsWith('|')) {
|
|
11320
|
+
inTable = false;
|
|
11321
|
+
continue;
|
|
11322
|
+
}
|
|
11323
|
+
if (/^\|[\s:|-]+\|$/.test(trimmed)) continue;
|
|
11324
|
+
const cells = splitRow(trimmed);
|
|
11325
|
+
const code = cells[idIndex] ?? '';
|
|
11326
|
+
if (!codes.has(code)) continue;
|
|
11327
|
+
const statuses = statusesByCode.get(code) ?? [];
|
|
11328
|
+
const result = aggregate(statuses);
|
|
11329
|
+
const nextStatus = result.status;
|
|
11330
|
+
const nextProgress = String(result.progress);
|
|
11331
|
+
if (cells[statusIndex] === nextStatus && cells[progressIndex] === nextProgress) continue;
|
|
11332
|
+
const updated = [
|
|
11333
|
+
...cells
|
|
11334
|
+
];
|
|
11335
|
+
updated[statusIndex] = nextStatus;
|
|
11336
|
+
updated[progressIndex] = nextProgress;
|
|
11337
|
+
if (updatedAtIndex >= 0) updated[updatedAtIndex] = stamp;
|
|
11338
|
+
lines[index] = joinRow(updated);
|
|
11339
|
+
changes.push(`更新需求:${code} 开发状态 ${cells[statusIndex] ?? ''} → ${nextStatus},进度 ${cells[progressIndex] ?? ''}% → ${nextProgress}%`);
|
|
11340
|
+
}
|
|
11341
|
+
return {
|
|
11342
|
+
lines,
|
|
11343
|
+
changes
|
|
11344
|
+
};
|
|
11151
11345
|
}
|
|
11152
11346
|
function renderDetail(options) {
|
|
11153
11347
|
const { taskId, task, requirement } = options;
|
|
@@ -11325,6 +11519,7 @@ function buildSkeleton(options) {
|
|
|
11325
11519
|
}
|
|
11326
11520
|
function renderPlan(options) {
|
|
11327
11521
|
const { schema, role, plan, existing, stamp, developer } = options;
|
|
11522
|
+
const aggregate = options.aggregate ?? aggregateRequirement;
|
|
11328
11523
|
const changes = [];
|
|
11329
11524
|
const assigned = [];
|
|
11330
11525
|
const existingRequirementIds = new Set(existing.requirements.map((item)=>item.id));
|
|
@@ -11341,7 +11536,7 @@ function renderPlan(options) {
|
|
|
11341
11536
|
const next = (counters.get(task.requirement) ?? 0) + 1;
|
|
11342
11537
|
counters.set(task.requirement, next);
|
|
11343
11538
|
const id = `${task.requirement}-T${next}`;
|
|
11344
|
-
const requirement = plan.requirements.find((item)=>item.code === task.requirement);
|
|
11539
|
+
const requirement = plan.requirements.find((item)=>item.code === task.requirement) ?? resolveExistingRequirement(existing.requirements, task.requirement);
|
|
11345
11540
|
if (void 0 !== requirement) {
|
|
11346
11541
|
taskIdsByPlanName.set(task.name, id);
|
|
11347
11542
|
newTasks.push({
|
|
@@ -11379,8 +11574,8 @@ function renderPlan(options) {
|
|
|
11379
11574
|
requirement.code,
|
|
11380
11575
|
requirement.name,
|
|
11381
11576
|
requirement.terminal,
|
|
11382
|
-
|
|
11383
|
-
String(
|
|
11577
|
+
aggregate(statuses).status,
|
|
11578
|
+
String(aggregate(statuses).progress),
|
|
11384
11579
|
requirement.note ?? '',
|
|
11385
11580
|
stamp
|
|
11386
11581
|
];
|
|
@@ -11415,6 +11610,22 @@ function renderPlan(options) {
|
|
|
11415
11610
|
}) : [
|
|
11416
11611
|
...existing.lines
|
|
11417
11612
|
];
|
|
11613
|
+
const refreshedCodes = new Set([
|
|
11614
|
+
...plan.requirements.filter((requirement)=>existingRequirementIds.has(requirement.code)).map((requirement)=>requirement.code),
|
|
11615
|
+
...newTasks.map((entry)=>entry.task.requirement).filter((code)=>existingRequirementIds.has(code))
|
|
11616
|
+
]);
|
|
11617
|
+
if (refreshedCodes.size > 0) {
|
|
11618
|
+
const refreshed = refreshRequirementRows({
|
|
11619
|
+
lines,
|
|
11620
|
+
schema,
|
|
11621
|
+
statusesByCode: requirementStatuses,
|
|
11622
|
+
codes: refreshedCodes,
|
|
11623
|
+
stamp,
|
|
11624
|
+
aggregate
|
|
11625
|
+
});
|
|
11626
|
+
lines = refreshed.lines;
|
|
11627
|
+
changes.push(...refreshed.changes);
|
|
11628
|
+
}
|
|
11418
11629
|
lines = appendTableRows({
|
|
11419
11630
|
lines,
|
|
11420
11631
|
sectionHeading: head.requirement,
|
|
@@ -11713,6 +11924,27 @@ function materializeRemote(docsRoot, ref) {
|
|
|
11713
11924
|
});
|
|
11714
11925
|
return dir;
|
|
11715
11926
|
}
|
|
11927
|
+
function materializeScripts(docsRoot, ref, dir) {
|
|
11928
|
+
const listed = tryGit(docsRoot, [
|
|
11929
|
+
'ls-tree',
|
|
11930
|
+
'-r',
|
|
11931
|
+
'--name-only',
|
|
11932
|
+
ref.sha,
|
|
11933
|
+
"scripts/"
|
|
11934
|
+
]);
|
|
11935
|
+
if (null === listed) return;
|
|
11936
|
+
for (const path of listed.split('\n').map((line)=>line.trim())){
|
|
11937
|
+
if (0 === path.length) continue;
|
|
11938
|
+
const target = external_node_path_join(dir, path);
|
|
11939
|
+
const content = gitShow(docsRoot, ref.sha, path);
|
|
11940
|
+
if (null !== content) {
|
|
11941
|
+
mkdirSync(external_node_path_dirname(target), {
|
|
11942
|
+
recursive: true
|
|
11943
|
+
});
|
|
11944
|
+
writeFileSync(target, content, 'utf8');
|
|
11945
|
+
}
|
|
11946
|
+
}
|
|
11947
|
+
}
|
|
11716
11948
|
function exportRemoteDoc(docsRoot, ref, iteration, developer) {
|
|
11717
11949
|
const safeIteration = safeSegment(iteration, '迭代目录');
|
|
11718
11950
|
const safeDeveloper = safeSegment(developer, '开发者标识');
|
|
@@ -11725,16 +11957,13 @@ function exportRemoteDoc(docsRoot, ref, iteration, developer) {
|
|
|
11725
11957
|
recursive: true
|
|
11726
11958
|
});
|
|
11727
11959
|
writeFileSync(target, markdown, 'utf8');
|
|
11728
|
-
|
|
11729
|
-
if (!external_node_fs_existsSync(scriptPath)) {
|
|
11730
|
-
const script = gitShow(docsRoot, ref.sha, "scripts/validate_task_doc.py");
|
|
11731
|
-
if (null !== script) writeFileSync(scriptPath, script, 'utf8');
|
|
11732
|
-
}
|
|
11960
|
+
materializeScripts(docsRoot, ref, dir);
|
|
11733
11961
|
const schemaPath = external_node_path_join(dir, 'schema.json');
|
|
11734
11962
|
if (!external_node_fs_existsSync(schemaPath)) {
|
|
11735
11963
|
const schemaText = gitShow(docsRoot, ref.sha, 'schema.json');
|
|
11736
11964
|
if (null !== schemaText) writeFileSync(schemaPath, schemaText, 'utf8');
|
|
11737
11965
|
}
|
|
11966
|
+
const scriptPath = external_node_path_join(dir, "scripts", 'validate_task_doc.py');
|
|
11738
11967
|
return {
|
|
11739
11968
|
dir,
|
|
11740
11969
|
markdown,
|
|
@@ -11757,52 +11986,52 @@ function isGitAvailable() {
|
|
|
11757
11986
|
}
|
|
11758
11987
|
function normalizeSelfTest(value) {
|
|
11759
11988
|
const text = value.trim();
|
|
11760
|
-
if (0 === text.length) return
|
|
11761
|
-
if (text.startsWith(
|
|
11989
|
+
if (0 === text.length) return "未执行";
|
|
11990
|
+
if (text.startsWith("免测")) return "免测";
|
|
11762
11991
|
return text;
|
|
11763
11992
|
}
|
|
11764
11993
|
function normalizeAcceptance(value) {
|
|
11765
11994
|
const text = value.trim();
|
|
11766
|
-
return 0 === text.length ?
|
|
11995
|
+
return 0 === text.length ? "待验收" : text;
|
|
11767
11996
|
}
|
|
11768
11997
|
function bump(target, key) {
|
|
11769
11998
|
target[key] = (target[key] ?? 0) + 1;
|
|
11770
11999
|
}
|
|
11771
12000
|
const RESERVED_DIRS = new Set([
|
|
11772
|
-
|
|
12001
|
+
"_prd",
|
|
11773
12002
|
"scripts",
|
|
11774
|
-
|
|
11775
|
-
|
|
11776
|
-
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
12003
|
+
"skills",
|
|
12004
|
+
"docs",
|
|
12005
|
+
"node_modules",
|
|
12006
|
+
".git",
|
|
12007
|
+
".idea",
|
|
12008
|
+
".vscode"
|
|
11780
12009
|
]);
|
|
11781
12010
|
const iterations_RESERVED_FILES = new Set([
|
|
11782
|
-
|
|
11783
|
-
|
|
11784
|
-
|
|
12011
|
+
"README.md",
|
|
12012
|
+
"AGENTS.md",
|
|
12013
|
+
"CLAUDE.md"
|
|
11785
12014
|
]);
|
|
11786
12015
|
const iterations_SAFE_SEGMENT = /^[A-Za-z0-9._\-\u4e00-\u9fa5]+$/;
|
|
11787
12016
|
function iterations_safeSegment(value, label) {
|
|
11788
12017
|
const trimmed = value.trim();
|
|
11789
|
-
if (!iterations_SAFE_SEGMENT.test(trimmed) ||
|
|
12018
|
+
if (!iterations_SAFE_SEGMENT.test(trimmed) || "." === trimmed || ".." === trimmed) throw new errors_CliError(`${label} 不合法:${value}`, errors_EXIT.USAGE);
|
|
11790
12019
|
return trimmed;
|
|
11791
12020
|
}
|
|
11792
12021
|
function joinWithin(root, ...segments) {
|
|
11793
|
-
const target =
|
|
11794
|
-
const base =
|
|
12022
|
+
const target = external_node_path_resolve(root, ...segments);
|
|
12023
|
+
const base = external_node_path_resolve(root) + sep;
|
|
11795
12024
|
if (!target.startsWith(base)) throw new errors_CliError(`路径越界:${target}`, errors_EXIT.USAGE);
|
|
11796
12025
|
return target;
|
|
11797
12026
|
}
|
|
11798
12027
|
function inferRole(markdown) {
|
|
11799
12028
|
const match = /\|\s*负责范围\s*\|\s*([^|]*)\|/.exec(markdown);
|
|
11800
|
-
const scope = match?.[1]?.trim() ??
|
|
11801
|
-
const hasFrontend = scope.includes(
|
|
11802
|
-
const hasBackend = scope.includes(
|
|
11803
|
-
if (hasFrontend && hasBackend) return
|
|
11804
|
-
if (hasBackend) return
|
|
11805
|
-
return
|
|
12029
|
+
const scope = match?.[1]?.trim() ?? "";
|
|
12030
|
+
const hasFrontend = scope.includes("前端");
|
|
12031
|
+
const hasBackend = scope.includes("后端");
|
|
12032
|
+
if (hasFrontend && hasBackend) return "fullstack";
|
|
12033
|
+
if (hasBackend) return "backend";
|
|
12034
|
+
return "frontend";
|
|
11806
12035
|
}
|
|
11807
12036
|
function listMarkdownFiles(directory) {
|
|
11808
12037
|
let entries;
|
|
@@ -11811,11 +12040,11 @@ function listMarkdownFiles(directory) {
|
|
|
11811
12040
|
} catch {
|
|
11812
12041
|
return [];
|
|
11813
12042
|
}
|
|
11814
|
-
return entries.filter((name)=>name.endsWith(
|
|
12043
|
+
return entries.filter((name)=>name.endsWith(".md") && !iterations_RESERVED_FILES.has(name)).map((name)=>{
|
|
11815
12044
|
const full = external_node_path_join(directory, name);
|
|
11816
12045
|
const info = statSync(full);
|
|
11817
12046
|
return {
|
|
11818
|
-
id: name.replace(/\.md$/,
|
|
12047
|
+
id: name.replace(/\.md$/, ""),
|
|
11819
12048
|
file: name,
|
|
11820
12049
|
mtime: info.mtime.toISOString(),
|
|
11821
12050
|
size: info.size
|
|
@@ -11824,12 +12053,12 @@ function listMarkdownFiles(directory) {
|
|
|
11824
12053
|
}
|
|
11825
12054
|
function accessReason(error) {
|
|
11826
12055
|
const code = error.code;
|
|
11827
|
-
if (
|
|
11828
|
-
if (
|
|
12056
|
+
if ("EACCES" === code || "EPERM" === code) return "没有访问权限,请联系管理员开通文档仓库访问权限";
|
|
12057
|
+
if ("ENOENT" === code) return "文档仓库路径不存在";
|
|
11829
12058
|
if (error instanceof Error) return error.message;
|
|
11830
12059
|
return String(error);
|
|
11831
12060
|
}
|
|
11832
|
-
function listIterations(docsRoot, source =
|
|
12061
|
+
function listIterations(docsRoot, source = "local", refName) {
|
|
11833
12062
|
const base = {
|
|
11834
12063
|
docsRoot,
|
|
11835
12064
|
configured: docsRoot.trim().length > 0,
|
|
@@ -11841,7 +12070,7 @@ function listIterations(docsRoot, source = 'local', refName) {
|
|
|
11841
12070
|
};
|
|
11842
12071
|
if (!base.configured) return {
|
|
11843
12072
|
...base,
|
|
11844
|
-
reason:
|
|
12073
|
+
reason: "尚未配置文档仓库"
|
|
11845
12074
|
};
|
|
11846
12075
|
if (!external_node_fs_existsSync(docsRoot)) return {
|
|
11847
12076
|
...base,
|
|
@@ -11865,7 +12094,7 @@ function listIterations(docsRoot, source = 'local', refName) {
|
|
|
11865
12094
|
}
|
|
11866
12095
|
}
|
|
11867
12096
|
function buildIterationList(docsRoot, source, base, refName) {
|
|
11868
|
-
if (
|
|
12097
|
+
if ("remote" === source) {
|
|
11869
12098
|
const ref = resolveRemoteRef(docsRoot, refName);
|
|
11870
12099
|
const snapshot = listRemoteIterations(docsRoot, ref);
|
|
11871
12100
|
return {
|
|
@@ -11881,7 +12110,7 @@ function buildIterationList(docsRoot, source, base, refName) {
|
|
|
11881
12110
|
}
|
|
11882
12111
|
const entries = external_node_fs_readdirSync(docsRoot, {
|
|
11883
12112
|
withFileTypes: true
|
|
11884
|
-
}).filter((entry)=>entry.isDirectory() && !RESERVED_DIRS.has(entry.name) && !entry.name.startsWith(
|
|
12113
|
+
}).filter((entry)=>entry.isDirectory() && !RESERVED_DIRS.has(entry.name) && !entry.name.startsWith(".")).map((entry)=>{
|
|
11885
12114
|
const directory = external_node_path_join(docsRoot, entry.name);
|
|
11886
12115
|
const developers = listMarkdownFiles(directory);
|
|
11887
12116
|
const info = statSync(directory);
|
|
@@ -11889,7 +12118,7 @@ function buildIterationList(docsRoot, source, base, refName) {
|
|
|
11889
12118
|
name: entry.name,
|
|
11890
12119
|
mtime: info.mtime.toISOString(),
|
|
11891
12120
|
developers,
|
|
11892
|
-
hasPrd: external_node_fs_existsSync(external_node_path_join(directory,
|
|
12121
|
+
hasPrd: external_node_fs_existsSync(external_node_path_join(directory, "_prd", "meta.json"))
|
|
11893
12122
|
};
|
|
11894
12123
|
}).filter((entry)=>entry.developers.length > 0).sort((left, right)=>right.mtime.localeCompare(left.mtime));
|
|
11895
12124
|
return {
|
|
@@ -11901,10 +12130,10 @@ function buildIterationList(docsRoot, source, base, refName) {
|
|
|
11901
12130
|
}
|
|
11902
12131
|
function coerceIssue(value) {
|
|
11903
12132
|
if (!utils_isRecord(value)) return null;
|
|
11904
|
-
const level =
|
|
11905
|
-
const code =
|
|
11906
|
-
const message =
|
|
11907
|
-
const ref =
|
|
12133
|
+
const level = "warning" === value["level"] ? "warning" : "error";
|
|
12134
|
+
const code = "string" == typeof value["code"] ? value["code"] : "UNKNOWN";
|
|
12135
|
+
const message = "string" == typeof value["message"] ? value["message"] : "";
|
|
12136
|
+
const ref = "string" == typeof value["ref"] ? value["ref"] : void 0;
|
|
11908
12137
|
return void 0 === ref ? {
|
|
11909
12138
|
level,
|
|
11910
12139
|
code,
|
|
@@ -11918,59 +12147,59 @@ function coerceIssue(value) {
|
|
|
11918
12147
|
}
|
|
11919
12148
|
function coerceRequirement(value) {
|
|
11920
12149
|
if (!utils_isRecord(value)) return null;
|
|
11921
|
-
const id =
|
|
12150
|
+
const id = "string" == typeof value["id"] ? value["id"] : "";
|
|
11922
12151
|
if (0 === id.length) return null;
|
|
11923
12152
|
return {
|
|
11924
12153
|
id,
|
|
11925
|
-
title:
|
|
11926
|
-
terminal:
|
|
11927
|
-
status:
|
|
11928
|
-
progress: String(value[
|
|
11929
|
-
note:
|
|
11930
|
-
updatedAt:
|
|
11931
|
-
taskIds: isStringArray(value[
|
|
12154
|
+
title: "string" == typeof value["title"] ? value["title"] : "",
|
|
12155
|
+
terminal: "string" == typeof value["terminal"] ? value["terminal"] : "",
|
|
12156
|
+
status: "string" == typeof value["status"] ? value["status"] : "",
|
|
12157
|
+
progress: String(value["progress"] ?? ""),
|
|
12158
|
+
note: "string" == typeof value["note"] ? value["note"] : "",
|
|
12159
|
+
updatedAt: "string" == typeof value["updatedAt"] ? value["updatedAt"] : "",
|
|
12160
|
+
taskIds: isStringArray(value["taskIds"]) ? value["taskIds"] : []
|
|
11932
12161
|
};
|
|
11933
12162
|
}
|
|
11934
12163
|
function coerceTask(value) {
|
|
11935
12164
|
if (!utils_isRecord(value)) return null;
|
|
11936
|
-
const id =
|
|
12165
|
+
const id = "string" == typeof value["id"] ? value["id"] : "";
|
|
11937
12166
|
if (0 === id.length) return null;
|
|
11938
12167
|
return {
|
|
11939
12168
|
id,
|
|
11940
|
-
requirementId:
|
|
11941
|
-
name:
|
|
11942
|
-
type:
|
|
11943
|
-
scope:
|
|
11944
|
-
terminal:
|
|
11945
|
-
dependencies: isStringArray(value[
|
|
11946
|
-
selfTest:
|
|
11947
|
-
acceptance:
|
|
11948
|
-
status:
|
|
11949
|
-
updatedAt:
|
|
12169
|
+
requirementId: "string" == typeof value["requirementId"] ? value["requirementId"] : "",
|
|
12170
|
+
name: "string" == typeof value["name"] ? value["name"] : "",
|
|
12171
|
+
type: "string" == typeof value["type"] ? value["type"] : "",
|
|
12172
|
+
scope: "string" == typeof value["scope"] ? value["scope"] : "",
|
|
12173
|
+
terminal: "string" == typeof value["terminal"] ? value["terminal"] : "",
|
|
12174
|
+
dependencies: isStringArray(value["dependencies"]) ? value["dependencies"] : [],
|
|
12175
|
+
selfTest: "string" == typeof value["selfTest"] ? value["selfTest"] : "",
|
|
12176
|
+
acceptance: "string" == typeof value["acceptance"] ? value["acceptance"] : "",
|
|
12177
|
+
status: "string" == typeof value["status"] ? value["status"] : "",
|
|
12178
|
+
updatedAt: "string" == typeof value["updatedAt"] ? value["updatedAt"] : ""
|
|
11950
12179
|
};
|
|
11951
12180
|
}
|
|
11952
12181
|
function coerceInfo(value) {
|
|
11953
12182
|
if (!utils_isRecord(value)) return {};
|
|
11954
12183
|
const info = {};
|
|
11955
|
-
for (const [key, item] of Object.entries(value))if (
|
|
12184
|
+
for (const [key, item] of Object.entries(value))if ("string" == typeof item) info[key] = item;
|
|
11956
12185
|
return info;
|
|
11957
12186
|
}
|
|
11958
12187
|
function coercePayload(raw) {
|
|
11959
12188
|
if (!utils_isRecord(raw)) return null;
|
|
11960
|
-
const stats = utils_isRecord(raw[
|
|
11961
|
-
const requirements = Array.isArray(raw[
|
|
11962
|
-
const tasks = Array.isArray(raw[
|
|
11963
|
-
const errors = Array.isArray(raw[
|
|
11964
|
-
const warnings = Array.isArray(raw[
|
|
11965
|
-
const asNumber = (value, fallback)=>
|
|
12189
|
+
const stats = utils_isRecord(raw["stats"]) ? raw["stats"] : {};
|
|
12190
|
+
const requirements = Array.isArray(raw["requirements"]) ? raw["requirements"].map(coerceRequirement).filter((item)=>null !== item) : [];
|
|
12191
|
+
const tasks = Array.isArray(raw["tasks"]) ? raw["tasks"].map(coerceTask).filter((item)=>null !== item) : [];
|
|
12192
|
+
const errors = Array.isArray(raw["errors"]) ? raw["errors"].map(coerceIssue).filter((item)=>null !== item) : [];
|
|
12193
|
+
const warnings = Array.isArray(raw["warnings"]) ? raw["warnings"].map(coerceIssue).filter((item)=>null !== item) : [];
|
|
12194
|
+
const asNumber = (value, fallback)=>"number" == typeof value ? value : fallback;
|
|
11966
12195
|
return {
|
|
11967
|
-
valid: true === raw[
|
|
11968
|
-
iterationInfo: coerceInfo(raw[
|
|
12196
|
+
valid: true === raw["valid"],
|
|
12197
|
+
iterationInfo: coerceInfo(raw["iterationInfo"]),
|
|
11969
12198
|
stats: {
|
|
11970
|
-
requirements: asNumber(stats[
|
|
11971
|
-
tasks: asNumber(stats[
|
|
11972
|
-
completedTasks: asNumber(stats[
|
|
11973
|
-
details: asNumber(stats[
|
|
12199
|
+
requirements: asNumber(stats["requirements"], requirements.length),
|
|
12200
|
+
tasks: asNumber(stats["tasks"], tasks.length),
|
|
12201
|
+
completedTasks: asNumber(stats["completedTasks"], tasks.filter((task)=>"已完成" === task.status).length),
|
|
12202
|
+
details: asNumber(stats["details"], 0)
|
|
11974
12203
|
},
|
|
11975
12204
|
requirements,
|
|
11976
12205
|
tasks,
|
|
@@ -11978,74 +12207,119 @@ function coercePayload(raw) {
|
|
|
11978
12207
|
warnings
|
|
11979
12208
|
};
|
|
11980
12209
|
}
|
|
12210
|
+
const validatorFailureCache = new Map();
|
|
12211
|
+
const warnedValidatorFailures = new Set();
|
|
12212
|
+
function warnValidatorFailureOnce(key, reason) {
|
|
12213
|
+
if (warnedValidatorFailures.has(key)) return;
|
|
12214
|
+
warnedValidatorFailures.add(key);
|
|
12215
|
+
process.stderr.write(`警告:文档校验器未运行(${reason}),已改用降级解析\n`);
|
|
12216
|
+
}
|
|
11981
12217
|
function runValidator(input) {
|
|
11982
12218
|
const script = input.scriptPath;
|
|
11983
|
-
if (null === script || !external_node_fs_existsSync(script))
|
|
12219
|
+
if (null === script || !external_node_fs_existsSync(script)) {
|
|
12220
|
+
const missing = "文档仓库缺少 scripts/validate_task_doc.py";
|
|
12221
|
+
warnValidatorFailureOnce(`missing|${input.docsRoot}`, missing);
|
|
12222
|
+
return {
|
|
12223
|
+
payload: null,
|
|
12224
|
+
error: missing
|
|
12225
|
+
};
|
|
12226
|
+
}
|
|
12227
|
+
const cacheKey = `${script}|${input.docsRoot}|${input.iteration}|${input.developer}|${input.role}`;
|
|
12228
|
+
const cachedFailure = validatorFailureCache.get(cacheKey);
|
|
12229
|
+
if (void 0 !== cachedFailure) return {
|
|
12230
|
+
payload: null,
|
|
12231
|
+
error: cachedFailure
|
|
12232
|
+
};
|
|
11984
12233
|
const args = [
|
|
11985
12234
|
script,
|
|
11986
|
-
|
|
12235
|
+
"--docs-root",
|
|
11987
12236
|
input.docsRoot,
|
|
11988
|
-
|
|
12237
|
+
"--iteration",
|
|
11989
12238
|
input.iteration,
|
|
11990
|
-
|
|
12239
|
+
"--developer",
|
|
11991
12240
|
input.developer,
|
|
11992
|
-
|
|
12241
|
+
"--role",
|
|
11993
12242
|
input.role,
|
|
11994
|
-
|
|
11995
|
-
|
|
12243
|
+
"--format",
|
|
12244
|
+
"json"
|
|
11996
12245
|
];
|
|
12246
|
+
let lastError = null;
|
|
12247
|
+
let interpreterMissing = true;
|
|
11997
12248
|
for (const bin of [
|
|
11998
|
-
|
|
11999
|
-
|
|
12000
|
-
|
|
12249
|
+
"python3",
|
|
12250
|
+
"python",
|
|
12251
|
+
"py"
|
|
12001
12252
|
])try {
|
|
12002
12253
|
const stdout = execFileSync(bin, args, {
|
|
12003
|
-
encoding:
|
|
12254
|
+
encoding: "utf8",
|
|
12004
12255
|
timeout: 10000,
|
|
12005
|
-
maxBuffer: 16777216
|
|
12256
|
+
maxBuffer: 16777216,
|
|
12257
|
+
stdio: [
|
|
12258
|
+
"ignore",
|
|
12259
|
+
"pipe",
|
|
12260
|
+
"pipe"
|
|
12261
|
+
]
|
|
12006
12262
|
});
|
|
12007
12263
|
const parsed = coercePayload(JSON.parse(stdout));
|
|
12008
|
-
if (null !== parsed) return
|
|
12264
|
+
if (null !== parsed) return {
|
|
12265
|
+
payload: parsed,
|
|
12266
|
+
error: null
|
|
12267
|
+
};
|
|
12009
12268
|
} catch (error) {
|
|
12010
|
-
const
|
|
12011
|
-
|
|
12269
|
+
const failure = error;
|
|
12270
|
+
const stdout = failure.stdout;
|
|
12271
|
+
if ("string" == typeof stdout && stdout.trim().length > 0) try {
|
|
12012
12272
|
const parsed = coercePayload(JSON.parse(stdout));
|
|
12013
|
-
if (null !== parsed) return
|
|
12273
|
+
if (null !== parsed) return {
|
|
12274
|
+
payload: parsed,
|
|
12275
|
+
error: null
|
|
12276
|
+
};
|
|
12014
12277
|
} catch {}
|
|
12015
|
-
|
|
12016
|
-
|
|
12278
|
+
if ("ENOENT" === failure.code || 127 === failure.code) continue;
|
|
12279
|
+
interpreterMissing = false;
|
|
12280
|
+
const stderr = "string" == typeof failure.stderr ? failure.stderr.trim().split("\n") : [];
|
|
12281
|
+
lastError = stderr.length > 0 ? (stderr[stderr.length - 1] ?? "").slice(0, 200) : "校验器执行失败";
|
|
12282
|
+
}
|
|
12283
|
+
const reason = interpreterMissing ? "未找到 python 解释器(需 python3 / python / py)" : lastError;
|
|
12284
|
+
const failure = reason ?? "校验器执行失败";
|
|
12285
|
+
validatorFailureCache.set(cacheKey, failure);
|
|
12286
|
+
warnValidatorFailureOnce(failure, failure);
|
|
12287
|
+
return {
|
|
12288
|
+
payload: null,
|
|
12289
|
+
error: failure
|
|
12290
|
+
};
|
|
12017
12291
|
}
|
|
12018
12292
|
function extractSection(markdown, heading) {
|
|
12019
12293
|
const lines = markdown.split(/\r?\n/);
|
|
12020
12294
|
let start = -1;
|
|
12021
|
-
for(let index = 0; index < lines.length; index += 1)if ((lines[index] ??
|
|
12295
|
+
for(let index = 0; index < lines.length; index += 1)if ((lines[index] ?? "").trim() === heading) {
|
|
12022
12296
|
start = index + 1;
|
|
12023
12297
|
break;
|
|
12024
12298
|
}
|
|
12025
|
-
if (start < 0) return
|
|
12299
|
+
if (start < 0) return "";
|
|
12026
12300
|
const collected = [];
|
|
12027
12301
|
for(let index = start; index < lines.length; index += 1){
|
|
12028
|
-
const line = lines[index] ??
|
|
12302
|
+
const line = lines[index] ?? "";
|
|
12029
12303
|
if (/^##\s+/.test(line)) break;
|
|
12030
12304
|
collected.push(line);
|
|
12031
12305
|
}
|
|
12032
|
-
return collected.join(
|
|
12306
|
+
return collected.join("\n").trim();
|
|
12033
12307
|
}
|
|
12034
12308
|
function splitDetails(markdown) {
|
|
12035
|
-
const section = extractSection(markdown,
|
|
12309
|
+
const section = extractSection(markdown, "## 四、任务详情");
|
|
12036
12310
|
if (0 === section.length) return [];
|
|
12037
12311
|
const blocks = [];
|
|
12038
12312
|
const parts = section.split(/^###\s+/m).slice(1);
|
|
12039
12313
|
for (const part of parts){
|
|
12040
12314
|
const [firstLine, ...rest] = part.split(/\r?\n/);
|
|
12041
|
-
const heading = (firstLine ??
|
|
12315
|
+
const heading = (firstLine ?? "").trim();
|
|
12042
12316
|
const match = /^\[?([#\w\-\u4e00-\u9fa5]+)\]?\s*(.*)$/.exec(heading);
|
|
12043
12317
|
const id = match?.[1] ?? heading;
|
|
12044
|
-
const name = match?.[2]?.trim() ??
|
|
12318
|
+
const name = match?.[2]?.trim() ?? "";
|
|
12045
12319
|
blocks.push({
|
|
12046
12320
|
id,
|
|
12047
12321
|
name,
|
|
12048
|
-
markdown: rest.join(
|
|
12322
|
+
markdown: rest.join("\n").trim()
|
|
12049
12323
|
});
|
|
12050
12324
|
}
|
|
12051
12325
|
return blocks;
|
|
@@ -12054,7 +12328,7 @@ function parseMarkdownDoc(markdown, schema) {
|
|
|
12054
12328
|
const structureErrors = [];
|
|
12055
12329
|
const readTable = (sectionHeading, required)=>{
|
|
12056
12330
|
const section = extractSection(markdown, sectionHeading);
|
|
12057
|
-
const rows = section.split(/\r?\n/).map((line)=>line.trim()).filter((line)=>line.startsWith(
|
|
12331
|
+
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
12332
|
const [header, ...body] = rows;
|
|
12059
12333
|
if (void 0 === header) return {
|
|
12060
12334
|
records: [],
|
|
@@ -12070,7 +12344,7 @@ function parseMarkdownDoc(markdown, schema) {
|
|
|
12070
12344
|
const records = body.map((cells)=>{
|
|
12071
12345
|
const record = {};
|
|
12072
12346
|
header.forEach((name, index)=>{
|
|
12073
|
-
record[name] = cells[index] ??
|
|
12347
|
+
record[name] = cells[index] ?? "";
|
|
12074
12348
|
});
|
|
12075
12349
|
return record;
|
|
12076
12350
|
});
|
|
@@ -12080,43 +12354,43 @@ function parseMarkdownDoc(markdown, schema) {
|
|
|
12080
12354
|
};
|
|
12081
12355
|
};
|
|
12082
12356
|
const heading = (index, fallback)=>`## ${schema.sections[index] ?? fallback}`;
|
|
12083
|
-
const requirementRead = readTable(heading(1,
|
|
12084
|
-
const taskRead = readTable(heading(2,
|
|
12357
|
+
const requirementRead = readTable(heading(1, "二、需求清单"), schema.requirementHeaders);
|
|
12358
|
+
const taskRead = readTable(heading(2, "三、任务清单"), schema.taskHeaders);
|
|
12085
12359
|
if (requirementRead.missing.length > 0) structureErrors.push({
|
|
12086
|
-
level:
|
|
12087
|
-
code:
|
|
12088
|
-
message: `需求清单表头缺少列:${requirementRead.missing.join(
|
|
12360
|
+
level: "error",
|
|
12361
|
+
code: "REQUIREMENT_TABLE_MISMATCH",
|
|
12362
|
+
message: `需求清单表头缺少列:${requirementRead.missing.join("、")},请按最新模板补齐`
|
|
12089
12363
|
});
|
|
12090
12364
|
if (taskRead.missing.length > 0) structureErrors.push({
|
|
12091
|
-
level:
|
|
12092
|
-
code:
|
|
12093
|
-
message: `任务清单表头缺少列:${taskRead.missing.join(
|
|
12365
|
+
level: "error",
|
|
12366
|
+
code: "TASK_TABLE_MISMATCH",
|
|
12367
|
+
message: `任务清单表头缺少列:${taskRead.missing.join("、")},请按最新模板补齐`
|
|
12094
12368
|
});
|
|
12095
12369
|
const rk = schema.requirementKeys;
|
|
12096
|
-
const at = (record, keys, semantic)=>record[keys[semantic] ??
|
|
12370
|
+
const at = (record, keys, semantic)=>record[keys[semantic] ?? ""] ?? "";
|
|
12097
12371
|
const requirements = requirementRead.records.map((record)=>({
|
|
12098
|
-
id: at(record, rk,
|
|
12099
|
-
title: at(record, rk,
|
|
12100
|
-
terminal: at(record, rk,
|
|
12101
|
-
status: at(record, rk,
|
|
12102
|
-
progress: at(record, rk,
|
|
12103
|
-
note: at(record, rk,
|
|
12104
|
-
updatedAt: at(record, rk,
|
|
12372
|
+
id: at(record, rk, "id"),
|
|
12373
|
+
title: at(record, rk, "title"),
|
|
12374
|
+
terminal: at(record, rk, "terminal"),
|
|
12375
|
+
status: at(record, rk, "status"),
|
|
12376
|
+
progress: at(record, rk, "progress"),
|
|
12377
|
+
note: at(record, rk, "note"),
|
|
12378
|
+
updatedAt: at(record, rk, "updatedAt"),
|
|
12105
12379
|
taskIds: []
|
|
12106
12380
|
}));
|
|
12107
12381
|
const tk = schema.taskKeys;
|
|
12108
12382
|
const tasks = taskRead.records.map((record)=>({
|
|
12109
|
-
id: at(record, tk,
|
|
12110
|
-
requirementId: at(record, tk,
|
|
12111
|
-
name: at(record, tk,
|
|
12112
|
-
type: at(record, tk,
|
|
12113
|
-
scope: at(record, tk,
|
|
12114
|
-
terminal: at(record, tk,
|
|
12115
|
-
dependencies: at(record, tk,
|
|
12116
|
-
selfTest: at(record, tk,
|
|
12117
|
-
acceptance: at(record, tk,
|
|
12118
|
-
status: at(record, tk,
|
|
12119
|
-
updatedAt: at(record, tk,
|
|
12383
|
+
id: at(record, tk, "id"),
|
|
12384
|
+
requirementId: at(record, tk, "requirement"),
|
|
12385
|
+
name: at(record, tk, "name"),
|
|
12386
|
+
type: at(record, tk, "type"),
|
|
12387
|
+
scope: at(record, tk, "scope"),
|
|
12388
|
+
terminal: at(record, tk, "terminal"),
|
|
12389
|
+
dependencies: at(record, tk, "dependencies").split(/[,,]/).map((item)=>item.trim()).filter((item)=>item.length > 0),
|
|
12390
|
+
selfTest: at(record, tk, "selfTest"),
|
|
12391
|
+
acceptance: at(record, tk, "acceptance"),
|
|
12392
|
+
status: at(record, tk, "status"),
|
|
12393
|
+
updatedAt: at(record, tk, "updatedAt")
|
|
12120
12394
|
}));
|
|
12121
12395
|
for (const requirement of requirements)requirement.taskIds = tasks.filter((task)=>task.requirementId === requirement.id).map((task)=>task.id);
|
|
12122
12396
|
const details = splitDetails(markdown);
|
|
@@ -12132,7 +12406,7 @@ function parseMarkdownDoc(markdown, schema) {
|
|
|
12132
12406
|
stats: {
|
|
12133
12407
|
requirements: requirements.length,
|
|
12134
12408
|
tasks: tasks.length,
|
|
12135
|
-
completedTasks: tasks.filter((task)=>
|
|
12409
|
+
completedTasks: tasks.filter((task)=>"已完成" === task.status).length,
|
|
12136
12410
|
details: details.length
|
|
12137
12411
|
},
|
|
12138
12412
|
requirements,
|
|
@@ -12142,12 +12416,12 @@ function parseMarkdownDoc(markdown, schema) {
|
|
|
12142
12416
|
};
|
|
12143
12417
|
}
|
|
12144
12418
|
function readMarkdown(target) {
|
|
12145
|
-
return readFileSync(target,
|
|
12419
|
+
return readFileSync(target, "utf8");
|
|
12146
12420
|
}
|
|
12147
|
-
function readIterationDoc(docsRoot, iteration, developer, source =
|
|
12148
|
-
const safeIteration = iterations_safeSegment(iteration,
|
|
12149
|
-
const safeDeveloper = iterations_safeSegment(developer,
|
|
12150
|
-
if (
|
|
12421
|
+
function readIterationDoc(docsRoot, iteration, developer, source = "local", presetRef, refName) {
|
|
12422
|
+
const safeIteration = iterations_safeSegment(iteration, "迭代目录");
|
|
12423
|
+
const safeDeveloper = iterations_safeSegment(developer, "开发者标识");
|
|
12424
|
+
if ("remote" === source) {
|
|
12151
12425
|
const ref = presetRef ?? resolveRemoteRef(docsRoot, refName);
|
|
12152
12426
|
const exported = exportRemoteDoc(docsRoot, ref, safeIteration, safeDeveloper);
|
|
12153
12427
|
const roleInferred = inferRole(exported.markdown);
|
|
@@ -12164,13 +12438,14 @@ function readIterationDoc(docsRoot, iteration, developer, source = 'local', pres
|
|
|
12164
12438
|
file: `${safeIteration}/${safeDeveloper}.md`,
|
|
12165
12439
|
mtime: exported.mtime,
|
|
12166
12440
|
roleInferred,
|
|
12167
|
-
parser: null === scripted ?
|
|
12168
|
-
|
|
12441
|
+
parser: null === scripted.payload ? "fallback" : "script",
|
|
12442
|
+
parserError: scripted.error,
|
|
12443
|
+
source: "remote",
|
|
12169
12444
|
ref: {
|
|
12170
12445
|
name: ref.ref,
|
|
12171
12446
|
sha: ref.sha
|
|
12172
12447
|
},
|
|
12173
|
-
validation: scripted ?? parseMarkdownDoc(exported.markdown, loadDocSchema(exported.dir)),
|
|
12448
|
+
validation: scripted.payload ?? parseMarkdownDoc(exported.markdown, loadDocSchema(exported.dir)),
|
|
12174
12449
|
details: splitDetails(exported.markdown)
|
|
12175
12450
|
};
|
|
12176
12451
|
}
|
|
@@ -12182,13 +12457,13 @@ function readIterationDoc(docsRoot, iteration, developer, source = 'local', pres
|
|
|
12182
12457
|
const roleInferred = inferRole(markdown);
|
|
12183
12458
|
const scripted = runValidator({
|
|
12184
12459
|
docsRoot,
|
|
12185
|
-
scriptPath: external_node_path_join(docsRoot, "scripts",
|
|
12460
|
+
scriptPath: external_node_path_join(docsRoot, "scripts", "validate_task_doc.py"),
|
|
12186
12461
|
iteration: safeIteration,
|
|
12187
12462
|
developer: safeDeveloper,
|
|
12188
12463
|
role: roleInferred
|
|
12189
12464
|
});
|
|
12190
|
-
const validation = scripted ?? parseMarkdownDoc(markdown, loadDocSchema(docsRoot));
|
|
12191
|
-
const parser = null === scripted ?
|
|
12465
|
+
const validation = scripted.payload ?? parseMarkdownDoc(markdown, loadDocSchema(docsRoot));
|
|
12466
|
+
const parser = null === scripted.payload ? "fallback" : "script";
|
|
12192
12467
|
return {
|
|
12193
12468
|
iteration: safeIteration,
|
|
12194
12469
|
developer: safeDeveloper,
|
|
@@ -12196,15 +12471,16 @@ function readIterationDoc(docsRoot, iteration, developer, source = 'local', pres
|
|
|
12196
12471
|
mtime: statSync(file).mtime.toISOString(),
|
|
12197
12472
|
roleInferred,
|
|
12198
12473
|
parser,
|
|
12199
|
-
|
|
12474
|
+
parserError: scripted.error,
|
|
12475
|
+
source: "local",
|
|
12200
12476
|
ref: null,
|
|
12201
12477
|
validation,
|
|
12202
12478
|
details: splitDetails(markdown)
|
|
12203
12479
|
};
|
|
12204
12480
|
}
|
|
12205
|
-
function readIterationSummary(docsRoot, iteration, source =
|
|
12206
|
-
const safeIteration = iterations_safeSegment(iteration,
|
|
12207
|
-
const remoteRef =
|
|
12481
|
+
function readIterationSummary(docsRoot, iteration, source = "local", refName) {
|
|
12482
|
+
const safeIteration = iterations_safeSegment(iteration, "迭代目录");
|
|
12483
|
+
const remoteRef = "remote" === source ? resolveRemoteRef(docsRoot, refName) : null;
|
|
12208
12484
|
let developers;
|
|
12209
12485
|
if (null === remoteRef) {
|
|
12210
12486
|
const directory = joinWithin(docsRoot, safeIteration);
|
|
@@ -12224,7 +12500,7 @@ function readIterationSummary(docsRoot, iteration, source = 'local', refName) {
|
|
|
12224
12500
|
const selfTestCounts = {};
|
|
12225
12501
|
const acceptanceCounts = {};
|
|
12226
12502
|
for (const task of doc.validation.tasks){
|
|
12227
|
-
bump(statusCounts, 0 === task.status.length ?
|
|
12503
|
+
bump(statusCounts, 0 === task.status.length ? "未知" : task.status);
|
|
12228
12504
|
bump(selfTestCounts, normalizeSelfTest(task.selfTest));
|
|
12229
12505
|
bump(acceptanceCounts, normalizeAcceptance(task.acceptance));
|
|
12230
12506
|
}
|
|
@@ -12233,14 +12509,14 @@ function readIterationSummary(docsRoot, iteration, source = 'local', refName) {
|
|
|
12233
12509
|
task
|
|
12234
12510
|
]));
|
|
12235
12511
|
for (const task of doc.validation.tasks){
|
|
12236
|
-
if (
|
|
12512
|
+
if ("已完成" === task.status) continue;
|
|
12237
12513
|
const blocking = task.dependencies.map((dep)=>{
|
|
12238
12514
|
const target = byId.get(dep);
|
|
12239
12515
|
return void 0 === target ? null : {
|
|
12240
12516
|
id: dep,
|
|
12241
12517
|
status: target.status
|
|
12242
12518
|
};
|
|
12243
|
-
}).filter((item)=>null !== item &&
|
|
12519
|
+
}).filter((item)=>null !== item && "已完成" !== item.status);
|
|
12244
12520
|
if (blocking.length > 0) blocked.push({
|
|
12245
12521
|
developer: entry.id,
|
|
12246
12522
|
taskId: task.id,
|
|
@@ -12250,7 +12526,7 @@ function readIterationSummary(docsRoot, iteration, source = 'local', refName) {
|
|
|
12250
12526
|
});
|
|
12251
12527
|
}
|
|
12252
12528
|
const requirementStatusCounts = {};
|
|
12253
|
-
for (const requirement of doc.validation.requirements)bump(requirementStatusCounts, 0 === requirement.status.length ?
|
|
12529
|
+
for (const requirement of doc.validation.requirements)bump(requirementStatusCounts, 0 === requirement.status.length ? "未知" : requirement.status);
|
|
12254
12530
|
summaries.push({
|
|
12255
12531
|
id: entry.id,
|
|
12256
12532
|
roleInferred: doc.roleInferred,
|
|
@@ -12296,7 +12572,7 @@ function readIterationSummary(docsRoot, iteration, source = 'local', refName) {
|
|
|
12296
12572
|
},
|
|
12297
12573
|
totals: {
|
|
12298
12574
|
...totals,
|
|
12299
|
-
progress:
|
|
12575
|
+
progress: roundProgressPercent(totals.completedTasks, totals.tasks),
|
|
12300
12576
|
taskStatusCounts: mergeCounts((item)=>item.statusCounts),
|
|
12301
12577
|
requirementStatusCounts: mergeCounts((item)=>item.requirementStatusCounts),
|
|
12302
12578
|
selfTestCounts: mergeCounts((item)=>item.selfTestCounts),
|
|
@@ -12500,6 +12776,7 @@ function buildKeys(schema) {
|
|
|
12500
12776
|
task: {
|
|
12501
12777
|
id: pick(t, 'id'),
|
|
12502
12778
|
requirement: pick(t, 'requirement'),
|
|
12779
|
+
scope: pick(t, 'scope'),
|
|
12503
12780
|
selfTest: pick(t, 'selfTest'),
|
|
12504
12781
|
acceptance: pick(t, 'acceptance'),
|
|
12505
12782
|
status: pick(t, 'status'),
|
|
@@ -12509,6 +12786,7 @@ function buildKeys(schema) {
|
|
|
12509
12786
|
id: pick(r, 'id'),
|
|
12510
12787
|
status: pick(r, 'status'),
|
|
12511
12788
|
progress: pick(r, 'progress'),
|
|
12789
|
+
note: r['note'] ?? '',
|
|
12512
12790
|
updatedAt: pick(r, 'updatedAt')
|
|
12513
12791
|
},
|
|
12514
12792
|
taskSection: `## ${schema.sections[2] ?? '三、任务清单'}`,
|
|
@@ -12520,7 +12798,7 @@ function columnIndex(headerCells, name) {
|
|
|
12520
12798
|
if (index < 0) throw new errors_CliError(`表格缺少列「${name}」,无法安全写入`, errors_EXIT.INVALID);
|
|
12521
12799
|
return index;
|
|
12522
12800
|
}
|
|
12523
|
-
function
|
|
12801
|
+
function taskdoc_splitRow(line) {
|
|
12524
12802
|
const trimmed = line.trim();
|
|
12525
12803
|
const inner = trimmed.startsWith('|') ? trimmed.slice(1) : trimmed;
|
|
12526
12804
|
const withoutTail = inner.endsWith('|') ? inner.slice(0, -1) : inner;
|
|
@@ -12556,7 +12834,7 @@ function parseTaskRows(lines, keys) {
|
|
|
12556
12834
|
for(let index = start; index < end; index += 1){
|
|
12557
12835
|
const line = lines[index] ?? '';
|
|
12558
12836
|
if (!line.trim().startsWith('|')) continue;
|
|
12559
|
-
const cells =
|
|
12837
|
+
const cells = taskdoc_splitRow(line);
|
|
12560
12838
|
if (null === header) {
|
|
12561
12839
|
if (cells.includes(keys.task.id)) header = cells;
|
|
12562
12840
|
continue;
|
|
@@ -12586,7 +12864,7 @@ function parseRequirementRows(lines, keys) {
|
|
|
12586
12864
|
for(let index = start; index < end; index += 1){
|
|
12587
12865
|
const line = lines[index] ?? '';
|
|
12588
12866
|
if (!line.trim().startsWith('|')) continue;
|
|
12589
|
-
const cells =
|
|
12867
|
+
const cells = taskdoc_splitRow(line);
|
|
12590
12868
|
if (null === header) {
|
|
12591
12869
|
if (cells.includes(keys.requirement.id)) header = cells;
|
|
12592
12870
|
continue;
|
|
@@ -12605,12 +12883,6 @@ function parseRequirementRows(lines, keys) {
|
|
|
12605
12883
|
rows
|
|
12606
12884
|
};
|
|
12607
12885
|
}
|
|
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
12886
|
function updateDetailBlock(lines, taskId, updates) {
|
|
12615
12887
|
const headingIndex = lines.findIndex((line)=>line.trim().startsWith(`### [${taskId}]`));
|
|
12616
12888
|
if (headingIndex < 0) throw new errors_CliError(`任务 ${taskId} 缺少第四章详情区块,无法同步状态`, errors_EXIT.INVALID);
|
|
@@ -12654,7 +12926,7 @@ function loadDoc(docsRoot, iterationRaw, developerRaw) {
|
|
|
12654
12926
|
lines: original.split('\n')
|
|
12655
12927
|
};
|
|
12656
12928
|
}
|
|
12657
|
-
function computeUpdate(lines, taskId, action, keys) {
|
|
12929
|
+
function computeUpdate(lines, taskId, action, keys, docsRoot) {
|
|
12658
12930
|
const { header, rows } = parseTaskRows(lines, keys);
|
|
12659
12931
|
const target = rows.find((row)=>row.taskId === taskId);
|
|
12660
12932
|
if (void 0 === target) throw new errors_CliError(`任务清单中未找到 ${taskId}`, errors_EXIT.NOT_FOUND);
|
|
@@ -12686,9 +12958,14 @@ function computeUpdate(lines, taskId, action, keys) {
|
|
|
12686
12958
|
人工验收: nextAcceptance
|
|
12687
12959
|
});
|
|
12688
12960
|
const requirementStatuses = rows.filter((row)=>row.requirementId === target.requirementId).map((row)=>row.taskId === taskId ? nextStatus : row.status);
|
|
12689
|
-
const
|
|
12690
|
-
|
|
12691
|
-
|
|
12961
|
+
const aggregate = resolveAggregates(docsRoot, new Map([
|
|
12962
|
+
[
|
|
12963
|
+
target.requirementId,
|
|
12964
|
+
requirementStatuses
|
|
12965
|
+
]
|
|
12966
|
+
])).get(target.requirementId) ?? aggregateRequirement(requirementStatuses);
|
|
12967
|
+
const requirementStatus = aggregate.status;
|
|
12968
|
+
const progress = aggregate.progress;
|
|
12692
12969
|
const requirementParse = parseRequirementRows(withDetail, keys);
|
|
12693
12970
|
const requirementTarget = requirementParse.rows.find((row)=>row.id === target.requirementId);
|
|
12694
12971
|
if (void 0 === requirementTarget) throw new errors_CliError(`需求清单中未找到 ${target.requirementId}`, errors_EXIT.NOT_FOUND);
|
|
@@ -12718,10 +12995,15 @@ function commit(context, lines, changes, message, iteration, developer, action,
|
|
|
12718
12995
|
file: context.file
|
|
12719
12996
|
};
|
|
12720
12997
|
writeFileSync(context.file, output, 'utf8');
|
|
12721
|
-
const
|
|
12722
|
-
if (
|
|
12998
|
+
const outcome = validateAfterWrite(options.docsRoot, iteration, developer);
|
|
12999
|
+
if ('violation' === outcome.kind) {
|
|
13000
|
+
writeFileSync(context.file, context.original, 'utf8');
|
|
13001
|
+
throw new errors_CliError(`写入被校验器拒绝,已回滚:${outcome.message}`, errors_EXIT.INVALID);
|
|
13002
|
+
}
|
|
13003
|
+
if ('unavailable' === outcome.kind) {
|
|
12723
13004
|
writeFileSync(context.file, context.original, 'utf8');
|
|
12724
|
-
throw new errors_CliError(
|
|
13005
|
+
if (requireValidatorScript()) throw new errors_CliError(`未执行文档校验,已回滚:${outcome.reason}\n文档校验必须由文档仓库 scripts/validate_task_doc.py 裁决;如确需跳过(不推荐),可配置 docs.validator.requireScript: false`, errors_EXIT.INVALID);
|
|
13006
|
+
process.stderr.write(`警告:${outcome.reason};本次写入未做文档校验(docs.validator.requireScript=false)\n`);
|
|
12725
13007
|
}
|
|
12726
13008
|
appendHistory({
|
|
12727
13009
|
iteration,
|
|
@@ -12739,6 +13021,163 @@ function commit(context, lines, changes, message, iteration, developer, action,
|
|
|
12739
13021
|
git
|
|
12740
13022
|
};
|
|
12741
13023
|
}
|
|
13024
|
+
function normalizeDetailField(name) {
|
|
13025
|
+
return name.replace(/[((][^))]*[))]/g, '').replace(/\s+/g, '').trim();
|
|
13026
|
+
}
|
|
13027
|
+
const DETAIL_FIELDS_LOCKED = new Set([
|
|
13028
|
+
'任务状态',
|
|
13029
|
+
'人工验收',
|
|
13030
|
+
'自测状态'
|
|
13031
|
+
]);
|
|
13032
|
+
function readDetailField(lines, taskId, field) {
|
|
13033
|
+
const headingIndex = lines.findIndex((line)=>line.trim().startsWith(`### [${taskId}]`));
|
|
13034
|
+
if (headingIndex < 0) return null;
|
|
13035
|
+
let end = lines.length;
|
|
13036
|
+
for(let index = headingIndex + 1; index < lines.length; index += 1)if (/^###\s+/.test(lines[index] ?? '') || /^##\s+/.test(lines[index] ?? '')) {
|
|
13037
|
+
end = index;
|
|
13038
|
+
break;
|
|
13039
|
+
}
|
|
13040
|
+
const wanted = normalizeDetailField(field);
|
|
13041
|
+
for(let index = headingIndex + 1; index < end; index += 1){
|
|
13042
|
+
const match = /^(\s*-\s+\*\*(.+?)\*\*\s*[::])\s*(.*)$/.exec(lines[index] ?? '');
|
|
13043
|
+
if (null === match) continue;
|
|
13044
|
+
if (normalizeDetailField(match[2] ?? '') !== wanted) continue;
|
|
13045
|
+
const items = [];
|
|
13046
|
+
const inline = (match[3] ?? '').trim();
|
|
13047
|
+
if (inline.length > 0) items.push(inline);
|
|
13048
|
+
let cursor = index + 1;
|
|
13049
|
+
while(cursor < end && /^\s{2,}-\s+/.test(lines[cursor] ?? '')){
|
|
13050
|
+
items.push((lines[cursor] ?? '').replace(/^\s{2,}-\s+/, '').trim());
|
|
13051
|
+
cursor += 1;
|
|
13052
|
+
}
|
|
13053
|
+
return {
|
|
13054
|
+
index,
|
|
13055
|
+
prefix: match[1] ?? '',
|
|
13056
|
+
items: items.filter((item)=>item.length > 0 && '<待补充>' !== item),
|
|
13057
|
+
list: cursor > index + 1
|
|
13058
|
+
};
|
|
13059
|
+
}
|
|
13060
|
+
return null;
|
|
13061
|
+
}
|
|
13062
|
+
function applyTaskDetail(options) {
|
|
13063
|
+
if (0 === options.updates.length) throw new errors_CliError('未提供要更新的字段(--set / --append)', errors_EXIT.USAGE);
|
|
13064
|
+
assertWritableBranch(options.docsRoot);
|
|
13065
|
+
const schema = loadDocSchema(options.docsRoot);
|
|
13066
|
+
const keys = buildKeys(schema);
|
|
13067
|
+
const context = loadDoc(options.docsRoot, options.iteration, options.developer);
|
|
13068
|
+
const { header, rows } = parseTaskRows(context.lines, keys);
|
|
13069
|
+
const target = rows.find((row)=>row.taskId === options.taskId);
|
|
13070
|
+
if (void 0 === target) throw new errors_CliError(`任务清单中未找到 ${options.taskId}`, errors_EXIT.NOT_FOUND);
|
|
13071
|
+
const scope = target.cells[columnIndex(header, keys.task.scope)] ?? '';
|
|
13072
|
+
const allowedFields = detailFieldsOfScope(schema, scope);
|
|
13073
|
+
const allowed = new Map(allowedFields.map((field)=>[
|
|
13074
|
+
normalizeDetailField(field),
|
|
13075
|
+
field
|
|
13076
|
+
]));
|
|
13077
|
+
const stamp = nowStamp();
|
|
13078
|
+
let lines = [
|
|
13079
|
+
...context.lines
|
|
13080
|
+
];
|
|
13081
|
+
const changes = [];
|
|
13082
|
+
const touched = [];
|
|
13083
|
+
for (const update of options.updates){
|
|
13084
|
+
const fieldName = allowed.get(normalizeDetailField(update.field));
|
|
13085
|
+
if (void 0 === fieldName) throw new errors_CliError(`字段「${update.field}」不可编辑(可改:${allowedFields.join(' / ')})`, errors_EXIT.USAGE);
|
|
13086
|
+
if (DETAIL_FIELDS_LOCKED.has(fieldName)) throw new errors_CliError(`字段「${fieldName}」由状态流转命令维护,请使用 task start/submit/accept/reject 或 task selftest`, errors_EXIT.USAGE);
|
|
13087
|
+
const parsed = readDetailField(lines, options.taskId, fieldName);
|
|
13088
|
+
if (null === parsed) throw new errors_CliError(`任务 ${options.taskId} 的详情区块缺少字段「${fieldName}」`, errors_EXIT.INVALID);
|
|
13089
|
+
const incoming = update.value.split('\n').map((item)=>item.trim()).filter((item)=>item.length > 0);
|
|
13090
|
+
const nextItems = update.append ? [
|
|
13091
|
+
...parsed.items,
|
|
13092
|
+
...incoming
|
|
13093
|
+
] : incoming;
|
|
13094
|
+
if (0 === nextItems.length) throw new errors_CliError(`字段「${fieldName}」的新值不能为空`, errors_EXIT.USAGE);
|
|
13095
|
+
if (nextItems.join('\n') === parsed.items.join('\n')) continue;
|
|
13096
|
+
const removeCount = 1 + (parsed.list ? parsed.items.length : 0);
|
|
13097
|
+
const replacement = 1 === nextItems.length ? [
|
|
13098
|
+
`${parsed.prefix}${nextItems[0]}`
|
|
13099
|
+
] : [
|
|
13100
|
+
`${parsed.prefix}`,
|
|
13101
|
+
...nextItems.map((item)=>` - ${item}`)
|
|
13102
|
+
];
|
|
13103
|
+
lines = [
|
|
13104
|
+
...lines.slice(0, parsed.index),
|
|
13105
|
+
...replacement,
|
|
13106
|
+
...lines.slice(parsed.index + removeCount)
|
|
13107
|
+
];
|
|
13108
|
+
touched.push(fieldName);
|
|
13109
|
+
changes.push(`${options.taskId} ${fieldName}:${parsed.items.length} 条 → ${nextItems.length} 条`);
|
|
13110
|
+
}
|
|
13111
|
+
if (0 === changes.length) return {
|
|
13112
|
+
ok: true,
|
|
13113
|
+
message: '详情内容未发生变化',
|
|
13114
|
+
changes: [],
|
|
13115
|
+
file: context.file
|
|
13116
|
+
};
|
|
13117
|
+
const { rows: refreshedRows } = parseTaskRows(lines, keys);
|
|
13118
|
+
const refreshed = refreshedRows.find((row)=>row.taskId === options.taskId);
|
|
13119
|
+
if (void 0 !== refreshed) {
|
|
13120
|
+
const cells = [
|
|
13121
|
+
...refreshed.cells
|
|
13122
|
+
];
|
|
13123
|
+
cells[columnIndex(header, keys.task.updatedAt)] = stamp;
|
|
13124
|
+
lines[refreshed.index] = taskdoc_joinRow(cells);
|
|
13125
|
+
}
|
|
13126
|
+
return commit(context, lines, changes, `已更新「${options.taskId}」详情:${touched.join('、')}`, taskdoc_safeSegment(options.iteration, '迭代目录'), taskdoc_safeSegment(options.developer, '开发者标识'), 'detail', [
|
|
13127
|
+
options.taskId
|
|
13128
|
+
], {
|
|
13129
|
+
docsRoot: options.docsRoot,
|
|
13130
|
+
policy: options.policy,
|
|
13131
|
+
commitMessage: `docs(${options.iteration}): 更新任务详情 ${options.taskId}(${touched.join('、')})`
|
|
13132
|
+
});
|
|
13133
|
+
}
|
|
13134
|
+
function applySelfTest(options) {
|
|
13135
|
+
assertWritableBranch(options.docsRoot);
|
|
13136
|
+
const schema = loadDocSchema(options.docsRoot);
|
|
13137
|
+
const keys = buildKeys(schema);
|
|
13138
|
+
const context = loadDoc(options.docsRoot, options.iteration, options.developer);
|
|
13139
|
+
const { header, rows } = parseTaskRows(context.lines, keys);
|
|
13140
|
+
const target = rows.find((row)=>row.taskId === options.taskId);
|
|
13141
|
+
if (void 0 === target) throw new errors_CliError(`任务清单中未找到 ${options.taskId}`, errors_EXIT.NOT_FOUND);
|
|
13142
|
+
if ('已完成' === target.status) throw new errors_CliError(`任务 ${options.taskId} 已验收完成,不允许改写自测证据;如需重测请先验收驳回`, errors_EXIT.USAGE);
|
|
13143
|
+
const reason = (options.reason ?? '').trim();
|
|
13144
|
+
if ('免测' === options.result && 0 === reason.length) throw new errors_CliError('「免测」必须通过 --reason 说明免测理由', errors_EXIT.USAGE);
|
|
13145
|
+
if ('免测' !== options.result && reason.length > 0) throw new errors_CliError('只有「免测」需要 --reason;通过/失败请勿传理由', errors_EXIT.USAGE);
|
|
13146
|
+
const allowed = [
|
|
13147
|
+
...schema.enums.selfTest,
|
|
13148
|
+
'免测'
|
|
13149
|
+
];
|
|
13150
|
+
if (!allowed.includes(options.result)) throw new errors_CliError(`自测结果「${options.result}」不在允许值内(${allowed.join(' / ')})`, errors_EXIT.USAGE);
|
|
13151
|
+
const value = '免测' === options.result ? `免测 (${reason})` : options.result;
|
|
13152
|
+
if (target.selfTest === value) return {
|
|
13153
|
+
ok: true,
|
|
13154
|
+
message: '自测状态未发生变化',
|
|
13155
|
+
changes: [],
|
|
13156
|
+
file: context.file
|
|
13157
|
+
};
|
|
13158
|
+
const stamp = nowStamp();
|
|
13159
|
+
const updated = [
|
|
13160
|
+
...context.lines
|
|
13161
|
+
];
|
|
13162
|
+
const cells = [
|
|
13163
|
+
...target.cells
|
|
13164
|
+
];
|
|
13165
|
+
cells[columnIndex(header, keys.task.selfTest)] = value;
|
|
13166
|
+
cells[columnIndex(header, keys.task.updatedAt)] = stamp;
|
|
13167
|
+
updated[target.index] = taskdoc_joinRow(cells);
|
|
13168
|
+
const withDetail = updateDetailBlock(updated, options.taskId, {
|
|
13169
|
+
自测状态: value
|
|
13170
|
+
});
|
|
13171
|
+
return commit(context, withDetail, [
|
|
13172
|
+
`${options.taskId} AI 自测状态:${target.selfTest || '未执行'} → ${value}`
|
|
13173
|
+
], `已记录「${options.taskId}」AI 自测:${value}`, taskdoc_safeSegment(options.iteration, '迭代目录'), taskdoc_safeSegment(options.developer, '开发者标识'), 'selftest', [
|
|
13174
|
+
options.taskId
|
|
13175
|
+
], {
|
|
13176
|
+
docsRoot: options.docsRoot,
|
|
13177
|
+
policy: options.policy,
|
|
13178
|
+
commitMessage: `docs(${options.iteration}): 记录自测 ${options.taskId}(${value})`
|
|
13179
|
+
});
|
|
13180
|
+
}
|
|
12742
13181
|
function applyBatchAction(options) {
|
|
12743
13182
|
if (0 === options.taskIds.length) throw new errors_CliError('未选择任务', errors_EXIT.USAGE);
|
|
12744
13183
|
assertWritableBranch(options.docsRoot);
|
|
@@ -12747,7 +13186,7 @@ function applyBatchAction(options) {
|
|
|
12747
13186
|
let lines = context.lines;
|
|
12748
13187
|
const changes = [];
|
|
12749
13188
|
for (const taskId of options.taskIds){
|
|
12750
|
-
const result = computeUpdate(lines, taskId, options.action, keys);
|
|
13189
|
+
const result = computeUpdate(lines, taskId, options.action, keys, options.docsRoot);
|
|
12751
13190
|
lines = result.lines;
|
|
12752
13191
|
changes.push(...result.changes);
|
|
12753
13192
|
}
|
|
@@ -12761,7 +13200,7 @@ function applyTaskAction(options) {
|
|
|
12761
13200
|
assertWritableBranch(options.docsRoot);
|
|
12762
13201
|
const keys = buildKeys(loadDocSchema(options.docsRoot));
|
|
12763
13202
|
const context = loadDoc(options.docsRoot, options.iteration, options.developer);
|
|
12764
|
-
const result = computeUpdate(context.lines, options.taskId, options.action, keys);
|
|
13203
|
+
const result = computeUpdate(context.lines, options.taskId, options.action, keys, options.docsRoot);
|
|
12765
13204
|
return commit(context, result.lines, result.changes, `已执行「${ACTION_META[options.action].label}」`, taskdoc_safeSegment(options.iteration, '迭代目录'), taskdoc_safeSegment(options.developer, '开发者标识'), options.action, [
|
|
12766
13205
|
options.taskId
|
|
12767
13206
|
], {
|
|
@@ -12774,7 +13213,10 @@ function applyTaskAction(options) {
|
|
|
12774
13213
|
}
|
|
12775
13214
|
function validateAfterWrite(docsRoot, iteration, developer) {
|
|
12776
13215
|
const script = external_node_path_join(docsRoot, "scripts", 'validate_task_doc.py');
|
|
12777
|
-
if (!external_node_fs_existsSync(script)) return
|
|
13216
|
+
if (!external_node_fs_existsSync(script)) return {
|
|
13217
|
+
kind: 'unavailable',
|
|
13218
|
+
reason: `文档仓库缺少校验脚本 ${script}`
|
|
13219
|
+
};
|
|
12778
13220
|
const targetFile = external_node_path_join(docsRoot, iteration, `${developer}.md`);
|
|
12779
13221
|
let role = 'frontend';
|
|
12780
13222
|
if (external_node_fs_existsSync(targetFile)) try {
|
|
@@ -12782,48 +13224,121 @@ function validateAfterWrite(docsRoot, iteration, developer) {
|
|
|
12782
13224
|
} catch {
|
|
12783
13225
|
role = 'frontend';
|
|
12784
13226
|
}
|
|
13227
|
+
const args = [
|
|
13228
|
+
script,
|
|
13229
|
+
'--docs-root',
|
|
13230
|
+
docsRoot,
|
|
13231
|
+
'--iteration',
|
|
13232
|
+
iteration,
|
|
13233
|
+
'--developer',
|
|
13234
|
+
developer,
|
|
13235
|
+
'--role',
|
|
13236
|
+
role,
|
|
13237
|
+
'--format',
|
|
13238
|
+
'json'
|
|
13239
|
+
];
|
|
13240
|
+
let interpreterMissing = true;
|
|
12785
13241
|
let scriptError = null;
|
|
12786
13242
|
for (const bin of [
|
|
12787
13243
|
'python3',
|
|
12788
13244
|
'python',
|
|
12789
13245
|
'py'
|
|
12790
13246
|
])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
|
-
], {
|
|
13247
|
+
const stdout = execFileSync(bin, args, {
|
|
12804
13248
|
encoding: 'utf8',
|
|
12805
13249
|
timeout: 15000,
|
|
12806
|
-
maxBuffer: 16777216
|
|
13250
|
+
maxBuffer: 16777216,
|
|
13251
|
+
stdio: [
|
|
13252
|
+
'ignore',
|
|
13253
|
+
'pipe',
|
|
13254
|
+
'pipe'
|
|
13255
|
+
]
|
|
12807
13256
|
});
|
|
12808
13257
|
const payload = JSON.parse(stdout);
|
|
12809
13258
|
const first = payload.errors?.[0];
|
|
12810
|
-
return first
|
|
13259
|
+
return void 0 === first ? {
|
|
13260
|
+
kind: 'passed'
|
|
13261
|
+
} : {
|
|
13262
|
+
kind: 'violation',
|
|
13263
|
+
message: first.message ?? '校验器未通过'
|
|
13264
|
+
};
|
|
12811
13265
|
} catch (error) {
|
|
12812
13266
|
const { stdout, stderr, code } = error;
|
|
13267
|
+
if ('ENOENT' === code || 127 === code) continue;
|
|
13268
|
+
interpreterMissing = false;
|
|
12813
13269
|
if ((stdout ?? '').trim().length > 0) try {
|
|
12814
13270
|
const payload = JSON.parse(stdout ?? '');
|
|
12815
|
-
return
|
|
13271
|
+
return {
|
|
13272
|
+
kind: 'violation',
|
|
13273
|
+
message: payload.errors?.[0]?.message ?? '校验器未通过'
|
|
13274
|
+
};
|
|
12816
13275
|
} catch {
|
|
12817
13276
|
scriptError = '校验器输出无法解析';
|
|
12818
13277
|
continue;
|
|
12819
13278
|
}
|
|
12820
|
-
if ('ENOENT' === code || 127 === code) continue;
|
|
12821
13279
|
const reason = (stderr ?? '').trim().split('\n')[0] ?? '';
|
|
12822
13280
|
scriptError = reason.length > 0 ? `校验器执行失败:${reason}` : '校验器执行失败';
|
|
12823
13281
|
continue;
|
|
12824
13282
|
}
|
|
12825
|
-
if (null !== scriptError) return
|
|
12826
|
-
|
|
13283
|
+
if (null !== scriptError) return {
|
|
13284
|
+
kind: 'unavailable',
|
|
13285
|
+
reason: scriptError
|
|
13286
|
+
};
|
|
13287
|
+
if (interpreterMissing) return {
|
|
13288
|
+
kind: 'unavailable',
|
|
13289
|
+
reason: '未找到 python 解释器(需 python3 / python / py)'
|
|
13290
|
+
};
|
|
13291
|
+
return {
|
|
13292
|
+
kind: 'unavailable',
|
|
13293
|
+
reason: '校验器无法执行'
|
|
13294
|
+
};
|
|
13295
|
+
}
|
|
13296
|
+
function requireValidatorScript() {
|
|
13297
|
+
try {
|
|
13298
|
+
const config = loadConfig().config;
|
|
13299
|
+
if (null === config) return true;
|
|
13300
|
+
return config.docs.validator.requireScript;
|
|
13301
|
+
} catch {
|
|
13302
|
+
return true;
|
|
13303
|
+
}
|
|
13304
|
+
}
|
|
13305
|
+
function applyRequirementNote(options) {
|
|
13306
|
+
assertWritableBranch(options.docsRoot);
|
|
13307
|
+
const keys = buildKeys(loadDocSchema(options.docsRoot));
|
|
13308
|
+
const context = loadDoc(options.docsRoot, options.iteration, options.developer);
|
|
13309
|
+
const requirementId = options.requirementId.trim().replace(/^#?/, '#');
|
|
13310
|
+
const requirementParse = parseRequirementRows(context.lines, keys);
|
|
13311
|
+
const target = requirementParse.rows.find((row)=>row.id === requirementId);
|
|
13312
|
+
if (void 0 === target) throw new errors_CliError(`需求清单中未找到 ${requirementId}`, errors_EXIT.NOT_FOUND);
|
|
13313
|
+
const note = options.note.trim();
|
|
13314
|
+
if (0 === note.length) throw new errors_CliError('备注不能为空;如需清空请写成「无」', errors_EXIT.USAGE);
|
|
13315
|
+
if (0 === keys.requirement.note.length) throw new errors_CliError('schema.json 未声明需求备注列语义(requirementTable.keys.note)', errors_EXIT.INVALID);
|
|
13316
|
+
const noteIndex = columnIndex(requirementParse.header, keys.requirement.note);
|
|
13317
|
+
const previous = target.cells[noteIndex] ?? '';
|
|
13318
|
+
if (previous === note) return {
|
|
13319
|
+
ok: true,
|
|
13320
|
+
message: '备注未发生变化',
|
|
13321
|
+
changes: [],
|
|
13322
|
+
file: context.file
|
|
13323
|
+
};
|
|
13324
|
+
const lines = [
|
|
13325
|
+
...context.lines
|
|
13326
|
+
];
|
|
13327
|
+
const cells = [
|
|
13328
|
+
...target.cells
|
|
13329
|
+
];
|
|
13330
|
+
cells[noteIndex] = note;
|
|
13331
|
+
cells[columnIndex(requirementParse.header, keys.requirement.updatedAt)] = nowStamp();
|
|
13332
|
+
lines[target.index] = taskdoc_joinRow(cells);
|
|
13333
|
+
return commit(context, lines, [
|
|
13334
|
+
`${requirementId} 备注:${previous || '(空)'} → ${note}`
|
|
13335
|
+
], `已更新需求 ${requirementId} 的备注`, taskdoc_safeSegment(options.iteration, '迭代目录'), taskdoc_safeSegment(options.developer, '开发者标识'), 'detail', [
|
|
13336
|
+
requirementId
|
|
13337
|
+
], {
|
|
13338
|
+
docsRoot: options.docsRoot,
|
|
13339
|
+
policy: options.policy,
|
|
13340
|
+
commitMessage: `docs(${options.iteration}): 更新需求备注 ${requirementId}`
|
|
13341
|
+
});
|
|
12827
13342
|
}
|
|
12828
13343
|
function recalcRequirements(options) {
|
|
12829
13344
|
assertWritableBranch(options.docsRoot);
|
|
@@ -12835,11 +13350,17 @@ function recalcRequirements(options) {
|
|
|
12835
13350
|
...context.lines
|
|
12836
13351
|
];
|
|
12837
13352
|
const changes = [];
|
|
13353
|
+
const aggregates = resolveAggregates(options.docsRoot, new Map(requirementParse.rows.map((requirement)=>[
|
|
13354
|
+
requirement.id,
|
|
13355
|
+
taskRows.filter((row)=>row.requirementId === requirement.id).map((row)=>row.status)
|
|
13356
|
+
])));
|
|
12838
13357
|
for (const requirement of requirementParse.rows){
|
|
12839
|
-
const
|
|
12840
|
-
|
|
12841
|
-
|
|
12842
|
-
|
|
13358
|
+
const aggregate = aggregates.get(requirement.id) ?? {
|
|
13359
|
+
status: '未开始',
|
|
13360
|
+
progress: 0
|
|
13361
|
+
};
|
|
13362
|
+
const status = aggregate.status;
|
|
13363
|
+
const progress = aggregate.progress;
|
|
12843
13364
|
const cells = [
|
|
12844
13365
|
...requirement.cells
|
|
12845
13366
|
];
|
|
@@ -13169,10 +13690,15 @@ function runDocMigrate(options) {
|
|
|
13169
13690
|
changedFiles.push(target);
|
|
13170
13691
|
if (migrated.unresolved.length > 0) continue;
|
|
13171
13692
|
const developer = basename(name, '.md');
|
|
13172
|
-
const
|
|
13173
|
-
if (
|
|
13693
|
+
const outcome = validateAfterWrite(docsRoot, iteration, developer);
|
|
13694
|
+
if ('passed' !== outcome.kind) {
|
|
13174
13695
|
writeFileSync(target, original, 'utf8');
|
|
13175
|
-
|
|
13696
|
+
const reason = 'violation' === outcome.kind ? outcome.message : outcome.reason;
|
|
13697
|
+
if ('unavailable' === outcome.kind && !requireValidatorScript()) {
|
|
13698
|
+
process.stderr.write(`警告:${outcome.reason};${iteration}/${name} 未做迁移后校验(docs.validator.requireScript=false)\n`);
|
|
13699
|
+
continue;
|
|
13700
|
+
}
|
|
13701
|
+
throw new errors_CliError(`迁移后校验未通过,已回滚 ${iteration}/${name}:${reason}`, errors_EXIT.INVALID);
|
|
13176
13702
|
}
|
|
13177
13703
|
}
|
|
13178
13704
|
}
|
|
@@ -13276,8 +13802,30 @@ function runDocApply(options, mode = 'apply') {
|
|
|
13276
13802
|
schema,
|
|
13277
13803
|
role,
|
|
13278
13804
|
index: buildRepoSideIndex(config.terminals),
|
|
13279
|
-
knownTaskIds: parsed.tasks.map((task)=>task.id)
|
|
13805
|
+
knownTaskIds: parsed.tasks.map((task)=>task.id),
|
|
13806
|
+
knownRequirements: parsed.requirements.map((item)=>item.id)
|
|
13280
13807
|
});
|
|
13808
|
+
const statusesByRequirement = new Map();
|
|
13809
|
+
for (const item of parsed.tasks){
|
|
13810
|
+
const list = statusesByRequirement.get(item.requirementId) ?? [];
|
|
13811
|
+
statusesByRequirement.set(item.requirementId, [
|
|
13812
|
+
...list,
|
|
13813
|
+
item.status
|
|
13814
|
+
]);
|
|
13815
|
+
}
|
|
13816
|
+
for (const task of plan.tasks){
|
|
13817
|
+
const list = statusesByRequirement.get(task.requirement) ?? [];
|
|
13818
|
+
statusesByRequirement.set(task.requirement, [
|
|
13819
|
+
...list,
|
|
13820
|
+
'未开始'
|
|
13821
|
+
]);
|
|
13822
|
+
}
|
|
13823
|
+
const aggregates = resolveAggregates(docsRoot, statusesByRequirement);
|
|
13824
|
+
const aggregateByStatuses = new Map();
|
|
13825
|
+
for (const [requirementId, statuses] of statusesByRequirement){
|
|
13826
|
+
const value = aggregates.get(requirementId);
|
|
13827
|
+
if (void 0 !== value) aggregateByStatuses.set(statuses.join('\u0000'), value);
|
|
13828
|
+
}
|
|
13281
13829
|
const stamp = doc_nowStamp();
|
|
13282
13830
|
const rendered = renderPlan({
|
|
13283
13831
|
schema,
|
|
@@ -13289,7 +13837,8 @@ function runDocApply(options, mode = 'apply') {
|
|
|
13289
13837
|
lines: null === original ? null : original.split('\n')
|
|
13290
13838
|
},
|
|
13291
13839
|
stamp,
|
|
13292
|
-
developer
|
|
13840
|
+
developer,
|
|
13841
|
+
aggregate: (statuses)=>aggregateByStatuses.get(statuses.join('\u0000')) ?? aggregateRequirement(statuses)
|
|
13293
13842
|
});
|
|
13294
13843
|
const sideIndex = buildRepoSideIndex(config.terminals);
|
|
13295
13844
|
const sideReport = validateTaskSides({
|
|
@@ -13341,11 +13890,16 @@ function runDocApply(options, mode = 'apply') {
|
|
|
13341
13890
|
recursive: true
|
|
13342
13891
|
});
|
|
13343
13892
|
writeFileSync(targetFile, rendered.markdown, 'utf8');
|
|
13344
|
-
const
|
|
13345
|
-
|
|
13893
|
+
const outcome = validateAfterWrite(docsRoot, iteration, developer);
|
|
13894
|
+
const rollback = (message)=>{
|
|
13346
13895
|
if (null === original) unlinkSync(targetFile);
|
|
13347
13896
|
else writeFileSync(targetFile, original, 'utf8');
|
|
13348
|
-
throw new errors_CliError(
|
|
13897
|
+
throw new errors_CliError(message, errors_EXIT.INVALID);
|
|
13898
|
+
};
|
|
13899
|
+
if ('violation' === outcome.kind) rollback(`写入被校验器拒绝,已回滚:${outcome.message}`);
|
|
13900
|
+
if ('unavailable' === outcome.kind) {
|
|
13901
|
+
if (requireValidatorScript()) rollback(`未执行文档校验,已回滚:${outcome.reason}\n文档校验必须由文档仓库 scripts/validate_task_doc.py 裁决;如确需跳过(不推荐),可配置 docs.validator.requireScript: false`);
|
|
13902
|
+
process.stderr.write(`警告:${outcome.reason};本次写入未做文档校验(docs.validator.requireScript=false)\n`);
|
|
13349
13903
|
}
|
|
13350
13904
|
const remainingReport = checkDocTaskSides({
|
|
13351
13905
|
docsRoot,
|
|
@@ -13392,6 +13946,31 @@ function registerDoc(program) {
|
|
|
13392
13946
|
});
|
|
13393
13947
|
registerDocMigrate(doc);
|
|
13394
13948
|
}
|
|
13949
|
+
function resolveDeveloper(options, configured) {
|
|
13950
|
+
const explicit = options.developer?.trim();
|
|
13951
|
+
const target = void 0 !== explicit && explicit.length > 0 ? explicit : configured;
|
|
13952
|
+
if (target !== configured) throw new errors_CliError(`只能修改自己的任务文档(当前身份:${configured})`, errors_EXIT.USAGE);
|
|
13953
|
+
return target;
|
|
13954
|
+
}
|
|
13955
|
+
function requireWriteContext(options) {
|
|
13956
|
+
const ready = requireConfig(options.config);
|
|
13957
|
+
const config = ready.config;
|
|
13958
|
+
if (0 === config.docs.root.trim().length) throw new errors_CliError('未配置文档仓库:请先设置 docs.root', errors_EXIT.NOT_FOUND);
|
|
13959
|
+
const base = config.docs.git?.cli ?? {
|
|
13960
|
+
commit: true,
|
|
13961
|
+
push: false
|
|
13962
|
+
};
|
|
13963
|
+
const policy = {
|
|
13964
|
+
commit: options.commit ?? base.commit,
|
|
13965
|
+
push: options.push ?? base.push
|
|
13966
|
+
};
|
|
13967
|
+
if (policy.push) policy.commit = true;
|
|
13968
|
+
return {
|
|
13969
|
+
docsRoot: config.docs.root,
|
|
13970
|
+
developer: resolveDeveloper(options, config.profile.developer),
|
|
13971
|
+
policy
|
|
13972
|
+
};
|
|
13973
|
+
}
|
|
13395
13974
|
function requireQueryContext(options) {
|
|
13396
13975
|
const format = parseFormat(options.format);
|
|
13397
13976
|
enableJsonErrors('json' === format);
|
|
@@ -13460,7 +14039,7 @@ function findIterationById(docsRoot, available, id) {
|
|
|
13460
14039
|
const pattern = new RegExp(`^\\|\\s*${normalized.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*\\|`, 'm');
|
|
13461
14040
|
const hits = [];
|
|
13462
14041
|
for (const entry of available)for (const developer of entry.developers){
|
|
13463
|
-
const target =
|
|
14042
|
+
const target = external_node_path_resolve(docsRoot, entry.name, developer.file);
|
|
13464
14043
|
try {
|
|
13465
14044
|
if (pattern.test(readFileSync(target, 'utf8'))) {
|
|
13466
14045
|
hits.push(entry.name);
|
|
@@ -13610,6 +14189,11 @@ function filterDocs(docs, developer) {
|
|
|
13610
14189
|
if (void 0 === target || 0 === target.length) return docs;
|
|
13611
14190
|
return docs.filter((item)=>item.developer === target);
|
|
13612
14191
|
}
|
|
14192
|
+
function switchActionLabel(action) {
|
|
14193
|
+
if ('selftest' === action) return '记录自测';
|
|
14194
|
+
if ('detail' === action) return '更新详情';
|
|
14195
|
+
return ACTION_META[action].label;
|
|
14196
|
+
}
|
|
13613
14197
|
function collectSideIssues(options) {
|
|
13614
14198
|
try {
|
|
13615
14199
|
const loaded = requireConfig(options.config);
|
|
@@ -13624,31 +14208,6 @@ function collectSideIssues(options) {
|
|
|
13624
14208
|
return [];
|
|
13625
14209
|
}
|
|
13626
14210
|
}
|
|
13627
|
-
function resolveDeveloper(options, configured) {
|
|
13628
|
-
const explicit = options.developer?.trim();
|
|
13629
|
-
const target = void 0 !== explicit && explicit.length > 0 ? explicit : configured;
|
|
13630
|
-
if (target !== configured) throw new errors_CliError(`只能修改自己的任务文档(当前身份:${configured})`, errors_EXIT.USAGE);
|
|
13631
|
-
return target;
|
|
13632
|
-
}
|
|
13633
|
-
function requireWriteContext(options) {
|
|
13634
|
-
const ready = requireConfig(options.config);
|
|
13635
|
-
const config = ready.config;
|
|
13636
|
-
if (0 === config.docs.root.trim().length) throw new errors_CliError('未配置文档仓库:请先设置 docs.root', errors_EXIT.NOT_FOUND);
|
|
13637
|
-
const base = config.docs.git?.cli ?? {
|
|
13638
|
-
commit: true,
|
|
13639
|
-
push: false
|
|
13640
|
-
};
|
|
13641
|
-
const policy = {
|
|
13642
|
-
commit: options.commit ?? base.commit,
|
|
13643
|
-
push: options.push ?? base.push
|
|
13644
|
-
};
|
|
13645
|
-
if (policy.push) policy.commit = true;
|
|
13646
|
-
return {
|
|
13647
|
-
docsRoot: config.docs.root,
|
|
13648
|
-
developer: resolveDeveloper(options, config.profile.developer),
|
|
13649
|
-
policy
|
|
13650
|
-
};
|
|
13651
|
-
}
|
|
13652
14211
|
function runAction(action, taskId, options) {
|
|
13653
14212
|
const { docsRoot, developer, policy } = requireWriteContext(options);
|
|
13654
14213
|
const iteration = options.iteration?.trim() ? resolveIterationName(options, docsRoot, loadIterations(docsRoot)) : resolveIterationName(options, docsRoot, loadIterations(docsRoot), {
|
|
@@ -13701,6 +14260,75 @@ function runAction(action, taskId, options) {
|
|
|
13701
14260
|
for (const message of sideIssues)printLine(` · ${message}`);
|
|
13702
14261
|
}
|
|
13703
14262
|
}
|
|
14263
|
+
function parseDetailUpdates(sets, appends) {
|
|
14264
|
+
const updates = [];
|
|
14265
|
+
const collect = (values, append)=>{
|
|
14266
|
+
for (const raw of values ?? []){
|
|
14267
|
+
const separator = raw.indexOf('=');
|
|
14268
|
+
if (separator <= 0) throw new errors_CliError(`字段更新需写成「字段=值」:${raw}`, errors_EXIT.USAGE);
|
|
14269
|
+
const field = raw.slice(0, separator).trim();
|
|
14270
|
+
const value = raw.slice(separator + 1).trim();
|
|
14271
|
+
if (0 === field.length || 0 === value.length) throw new errors_CliError(`字段更新需写成「字段=值」:${raw}`, errors_EXIT.USAGE);
|
|
14272
|
+
updates.push({
|
|
14273
|
+
field,
|
|
14274
|
+
value,
|
|
14275
|
+
append
|
|
14276
|
+
});
|
|
14277
|
+
}
|
|
14278
|
+
};
|
|
14279
|
+
collect(sets, false);
|
|
14280
|
+
collect(appends, true);
|
|
14281
|
+
return updates;
|
|
14282
|
+
}
|
|
14283
|
+
function runDetail(taskId, options) {
|
|
14284
|
+
const { docsRoot, developer, policy } = requireWriteContext(options);
|
|
14285
|
+
const iteration = options.iteration?.trim() ? resolveIterationName(options, docsRoot, loadIterations(docsRoot)) : resolveIterationName(options, docsRoot, loadIterations(docsRoot), {
|
|
14286
|
+
taskId: taskId.trim().replace(/^#?/, '#')
|
|
14287
|
+
});
|
|
14288
|
+
const format = parseFormat(options.format);
|
|
14289
|
+
const updates = parseDetailUpdates(options.set, options.append);
|
|
14290
|
+
const applied = applyTaskDetail({
|
|
14291
|
+
docsRoot,
|
|
14292
|
+
iteration,
|
|
14293
|
+
developer,
|
|
14294
|
+
taskId: taskId.trim().replace(/^#?/, '#'),
|
|
14295
|
+
updates,
|
|
14296
|
+
policy
|
|
14297
|
+
});
|
|
14298
|
+
if ('json' === format) return void printJson({
|
|
14299
|
+
...applied,
|
|
14300
|
+
iteration
|
|
14301
|
+
});
|
|
14302
|
+
printLine(applied.message);
|
|
14303
|
+
for (const change of applied.changes)printLine(` · ${change}`);
|
|
14304
|
+
printLine(`文档:${applied.file}`);
|
|
14305
|
+
if (void 0 !== applied.git) printLine(`git:${applied.git.message}`);
|
|
14306
|
+
}
|
|
14307
|
+
function runSelfTest(taskId, options) {
|
|
14308
|
+
const { docsRoot, developer, policy } = requireWriteContext(options);
|
|
14309
|
+
const iteration = options.iteration?.trim() ? resolveIterationName(options, docsRoot, loadIterations(docsRoot)) : resolveIterationName(options, docsRoot, loadIterations(docsRoot), {
|
|
14310
|
+
taskId: taskId.trim().replace(/^#?/, '#')
|
|
14311
|
+
});
|
|
14312
|
+
const format = parseFormat(options.format);
|
|
14313
|
+
const result = options.result.trim();
|
|
14314
|
+
const applied = applySelfTest({
|
|
14315
|
+
docsRoot,
|
|
14316
|
+
iteration,
|
|
14317
|
+
developer,
|
|
14318
|
+
taskId: taskId.trim().replace(/^#?/, '#'),
|
|
14319
|
+
result,
|
|
14320
|
+
reason: options.reason,
|
|
14321
|
+
policy
|
|
14322
|
+
});
|
|
14323
|
+
if ('json' === format) return void printJson({
|
|
14324
|
+
...applied,
|
|
14325
|
+
iteration
|
|
14326
|
+
});
|
|
14327
|
+
printLine(applied.message);
|
|
14328
|
+
for (const change of applied.changes)printLine(` · ${change}`);
|
|
14329
|
+
printLine(`文档:${applied.file}`);
|
|
14330
|
+
if (void 0 !== applied.git) printLine(`git:${applied.git.message}`);
|
|
14331
|
+
}
|
|
13704
14332
|
function runActions(options) {
|
|
13705
14333
|
const { docsRoot, developer } = requireWriteContext(options);
|
|
13706
14334
|
const iteration = resolveIterationName(options, docsRoot, loadIterations(docsRoot));
|
|
@@ -13751,7 +14379,8 @@ function runHistory(taskId, options) {
|
|
|
13751
14379
|
if ('json' === parseFormat(options.format)) return void printJson(entries);
|
|
13752
14380
|
if (0 === entries.length) return void printLine('暂无变更记录');
|
|
13753
14381
|
for (const entry of entries){
|
|
13754
|
-
|
|
14382
|
+
const label = switchActionLabel(entry.action);
|
|
14383
|
+
printLine(`${new Date(entry.at).toLocaleString('zh-CN')} ${label}`);
|
|
13755
14384
|
for (const change of entry.changes)printLine(` · ${change}`);
|
|
13756
14385
|
}
|
|
13757
14386
|
}
|
|
@@ -13849,6 +14478,8 @@ function registerTask(program) {
|
|
|
13849
14478
|
'accept',
|
|
13850
14479
|
'reject'
|
|
13851
14480
|
])commonOptions(task.command(`${action} <taskId>`)).description(`执行「${ACTION_META[action].label}」:${ACTION_META[action].from} → ${ACTION_META[action].to}`).option('--dry-run', '只校验是否允许,不写入').option('--commit', '本次变更后提交(覆盖 docs.git.cli.commit)').option('--no-commit', '本次变更后不提交').option('--push', '提交后推送(隐含 --commit)').option('--no-push', '不推送').action((taskId, options)=>runAction(action, taskId, options));
|
|
14481
|
+
commonOptions(task.command('selftest <taskId>')).description('记录 AI 自测结果:通过 / 失败 / 免测(免测需 --reason)').requiredOption('--result <result>', '自测结果:通过 | 失败 | 免测').option('--reason <reason>', '免测理由(仅 --result 免测 时需要)').option('--commit', '本次变更后提交(覆盖 docs.git.cli.commit)').option('--no-commit', '本次变更后不提交').option('--push', '提交后推送(隐含 --commit)').option('--no-push', '不推送').action((taskId, options)=>runSelfTest(taskId, options));
|
|
14482
|
+
commonOptions(task.command('detail <taskId>')).description('局部更新任务详情字段:--set 替换、--append 追加,值内换行写成多条').option('--set <fieldValue...>', '替换字段内容,格式「字段=值」').option('--append <fieldValue...>', '追加到字段条目末尾,格式「字段=值」').option('--commit', '本次变更后提交(覆盖 docs.git.cli.commit)').option('--no-commit', '本次变更后不提交').option('--push', '提交后推送(隐含 --commit)').option('--no-push', '不推送').action((taskId, options)=>runDetail(taskId, options));
|
|
13852
14483
|
commonOptions(task.command('batch <action> <taskIds...>')).description('批量执行同一动作,例如: ylcwf task batch accept "#2755-T1" "#2755-T2"').action((action, taskIds, options)=>{
|
|
13853
14484
|
if (!(action in ACTION_META)) throw new errors_CliError(`未知动作:${action}(可选 ${Object.keys(ACTION_META).join(' / ')})`, errors_EXIT.USAGE);
|
|
13854
14485
|
runBatch(action, taskIds, options);
|
|
@@ -13914,7 +14545,7 @@ function iteration_runShow(name, options) {
|
|
|
13914
14545
|
printLine(`汇总:开发者 ${summary.totals.developers} 需求 ${summary.totals.requirements} 任务 ${summary.totals.tasks}(已完成 ${summary.totals.completedTasks}) 进度 ${summary.totals.progress}%`);
|
|
13915
14546
|
printLine('');
|
|
13916
14547
|
const rows = summary.developers.map((item)=>{
|
|
13917
|
-
const progress =
|
|
14548
|
+
const progress = roundProgressPercent(item.stats.completedTasks, item.stats.tasks);
|
|
13918
14549
|
return [
|
|
13919
14550
|
item.id,
|
|
13920
14551
|
item.roleInferred,
|
|
@@ -13985,7 +14616,7 @@ function runContext(options) {
|
|
|
13985
14616
|
requirements: requirements.length,
|
|
13986
14617
|
tasks: tasks.length,
|
|
13987
14618
|
completedTasks,
|
|
13988
|
-
progress:
|
|
14619
|
+
progress: roundProgressPercent(completedTasks, tasks.length)
|
|
13989
14620
|
},
|
|
13990
14621
|
requirements,
|
|
13991
14622
|
tasks,
|
|
@@ -14133,11 +14764,36 @@ function runRecalc(options) {
|
|
|
14133
14764
|
for (const change of result.changes)printLine(` · ${change}`);
|
|
14134
14765
|
if (true !== options.dryRun) printLine(`文档:${result.file}`);
|
|
14135
14766
|
}
|
|
14767
|
+
function runNote(requirementId, options) {
|
|
14768
|
+
const { docsRoot, developer, policy } = requireWriteContext(options);
|
|
14769
|
+
const iteration = options.iteration?.trim() ? resolveIterationName(options, docsRoot, loadIterations(docsRoot)) : resolveIterationName(options, docsRoot, loadIterations(docsRoot), {
|
|
14770
|
+
requirementId: requirementId.trim().replace(/^#?/, '#')
|
|
14771
|
+
});
|
|
14772
|
+
const note = (options.set ?? '').trim();
|
|
14773
|
+
if (0 === note.length) throw new errors_CliError('请用 --set 提供备注内容', errors_EXIT.USAGE);
|
|
14774
|
+
const applied = applyRequirementNote({
|
|
14775
|
+
docsRoot,
|
|
14776
|
+
iteration,
|
|
14777
|
+
developer,
|
|
14778
|
+
requirementId,
|
|
14779
|
+
note,
|
|
14780
|
+
policy
|
|
14781
|
+
});
|
|
14782
|
+
if ('json' === options.format) return void printJson({
|
|
14783
|
+
...applied,
|
|
14784
|
+
iteration
|
|
14785
|
+
});
|
|
14786
|
+
printLine(applied.message);
|
|
14787
|
+
for (const change of applied.changes)printLine(` · ${change}`);
|
|
14788
|
+
printLine(`文档:${applied.file}`);
|
|
14789
|
+
if (void 0 !== applied.git) printLine(`git:${applied.git.message}`);
|
|
14790
|
+
}
|
|
14136
14791
|
function registerRequirement(program) {
|
|
14137
14792
|
const requirement = program.command('requirement').description('查看需求与关联任务,并重算需求状态');
|
|
14138
14793
|
const common = (command)=>command.option('-c, --config <path>', '指定配置文件路径').option('-i, --iteration <name>', '迭代目录名(可省略:在迭代目录内执行时自动推断)').option('-d, --developer <name>', '只看某位成员的需求').option('--format <format>', '输出格式:human | json', 'human');
|
|
14139
14794
|
common(requirement.command('list')).description('列出迭代下的需求清单').action((options)=>requirement_runList(options));
|
|
14140
14795
|
common(requirement.command('show <requirementId>')).description('查看需求详情与关联任务').action((requirementId, options)=>requirement_runShow(requirementId, options));
|
|
14796
|
+
common(requirement.command('note <requirementId>')).description('更新需求备注(只改本人文档)').option('--set <note>', '备注内容,例如 "19 个任务均已实现,待人工验收"').option('--commit', '本次变更后提交(覆盖 docs.git.cli.commit)').option('--no-commit', '本次变更后不提交').option('--push', '提交后推送(隐含 --commit)').option('--no-push', '不推送').action((requirementId, options)=>runNote(requirementId, options));
|
|
14141
14797
|
common(requirement.command('recalc')).description('按任务状态重算需求开发状态与进度').option('--dry-run', '只输出差异,不写入').action((options)=>runRecalc(options));
|
|
14142
14798
|
}
|
|
14143
14799
|
let cache = null;
|
|
@@ -14161,9 +14817,9 @@ async function fetchManifest(url) {
|
|
|
14161
14817
|
const payload = await response.json();
|
|
14162
14818
|
if ('string' != typeof payload.version || 0 === payload.version.length) return null;
|
|
14163
14819
|
return {
|
|
14164
|
-
current: "0.5.
|
|
14820
|
+
current: "0.5.2",
|
|
14165
14821
|
latest: payload.version,
|
|
14166
|
-
hasUpdate: isNewer(payload.version, "0.5.
|
|
14822
|
+
hasUpdate: isNewer(payload.version, "0.5.2"),
|
|
14167
14823
|
downloadUrl: 'string' == typeof payload.downloadUrl ? payload.downloadUrl : null,
|
|
14168
14824
|
source: 'manifest',
|
|
14169
14825
|
checkedAt: new Date().toISOString(),
|
|
@@ -14175,7 +14831,7 @@ async function fetchManifest(url) {
|
|
|
14175
14831
|
}
|
|
14176
14832
|
async function fetchNpm() {
|
|
14177
14833
|
const base = {
|
|
14178
|
-
current: "0.5.
|
|
14834
|
+
current: "0.5.2",
|
|
14179
14835
|
latest: null,
|
|
14180
14836
|
hasUpdate: false,
|
|
14181
14837
|
downloadUrl: null,
|
|
@@ -14202,7 +14858,7 @@ async function fetchNpm() {
|
|
|
14202
14858
|
return {
|
|
14203
14859
|
...base,
|
|
14204
14860
|
latest,
|
|
14205
|
-
hasUpdate: isNewer(latest, "0.5.
|
|
14861
|
+
hasUpdate: isNewer(latest, "0.5.2"),
|
|
14206
14862
|
downloadUrl: null
|
|
14207
14863
|
};
|
|
14208
14864
|
} catch (error) {
|
|
@@ -14293,7 +14949,7 @@ async function runUpgrade(options) {
|
|
|
14293
14949
|
const kind = detectInstallKind();
|
|
14294
14950
|
const result = await checkUpdate(true);
|
|
14295
14951
|
const target = options.to?.trim() ?? result.latest;
|
|
14296
|
-
printLine("当前版本:0.5.
|
|
14952
|
+
printLine("当前版本:0.5.2");
|
|
14297
14953
|
if (null !== result.error) printLine(`版本查询失败:${result.error}`);
|
|
14298
14954
|
else if (null !== result.latest) printLine(`最新版本:${result.latest}(来源:${result.source})`);
|
|
14299
14955
|
if (null === target) throw new errors_CliError('无法确定目标版本,请稍后重试或用 --to 指定', errors_EXIT.NOT_FOUND);
|
|
@@ -14589,6 +15245,11 @@ function syncDocument(doc, next) {
|
|
|
14589
15245
|
'push'
|
|
14590
15246
|
], next.docs.git[side].push);
|
|
14591
15247
|
}
|
|
15248
|
+
doc.setIn([
|
|
15249
|
+
'docs',
|
|
15250
|
+
'validator',
|
|
15251
|
+
'requireScript'
|
|
15252
|
+
], next.docs.validator.requireScript);
|
|
14592
15253
|
const current = doc.toJS();
|
|
14593
15254
|
const currentTerminals = utils_isRecord(current) && utils_isRecord(current['terminals']) ? Object.keys(current['terminals']) : [];
|
|
14594
15255
|
for (const key of currentTerminals)if (!Object.hasOwn(next.terminals, key)) doc.deleteIn([
|
|
@@ -14687,7 +15348,7 @@ function readState(explicitPath) {
|
|
|
14687
15348
|
issues: checked.issues,
|
|
14688
15349
|
backups: listBackups(explicitPath),
|
|
14689
15350
|
meta: {
|
|
14690
|
-
version: "0.5.
|
|
15351
|
+
version: "0.5.2",
|
|
14691
15352
|
features: SERVER_FEATURES
|
|
14692
15353
|
}
|
|
14693
15354
|
};
|
|
@@ -14837,7 +15498,7 @@ function completeOnboarding(draftRaw, configPath) {
|
|
|
14837
15498
|
return inspectOnboarding(configPath);
|
|
14838
15499
|
}
|
|
14839
15500
|
function assertDirectory(target) {
|
|
14840
|
-
const absolute = isAbsolute(target) ?
|
|
15501
|
+
const absolute = isAbsolute(target) ? external_node_path_resolve(target) : external_node_path_resolve(homedir(), target);
|
|
14841
15502
|
if (!external_node_fs_existsSync(absolute)) throw new errors_CliError(`目录不存在:${absolute}`, errors_EXIT.NOT_FOUND);
|
|
14842
15503
|
if (!statSync(absolute).isDirectory()) throw new errors_CliError(`不是目录:${absolute}`, errors_EXIT.USAGE);
|
|
14843
15504
|
return absolute;
|
|
@@ -14870,28 +15531,218 @@ function listDirectories(target) {
|
|
|
14870
15531
|
entries
|
|
14871
15532
|
};
|
|
14872
15533
|
}
|
|
14873
|
-
function
|
|
14874
|
-
|
|
14875
|
-
|
|
14876
|
-
|
|
14877
|
-
|
|
14878
|
-
|
|
14879
|
-
|
|
15534
|
+
function revealCommand(target) {
|
|
15535
|
+
switch(process.platform){
|
|
15536
|
+
case 'win32':
|
|
15537
|
+
return {
|
|
15538
|
+
command: 'cmd.exe',
|
|
15539
|
+
args: [
|
|
15540
|
+
'/c',
|
|
15541
|
+
'start',
|
|
15542
|
+
'',
|
|
15543
|
+
'explorer.exe',
|
|
15544
|
+
target
|
|
15545
|
+
]
|
|
15546
|
+
};
|
|
15547
|
+
case 'darwin':
|
|
15548
|
+
return {
|
|
15549
|
+
command: 'open',
|
|
15550
|
+
args: [
|
|
15551
|
+
target
|
|
15552
|
+
]
|
|
15553
|
+
};
|
|
15554
|
+
default:
|
|
15555
|
+
return {
|
|
15556
|
+
command: 'xdg-open',
|
|
15557
|
+
args: [
|
|
15558
|
+
target
|
|
15559
|
+
]
|
|
15560
|
+
};
|
|
15561
|
+
}
|
|
15562
|
+
}
|
|
15563
|
+
function spawnDetached(command, args) {
|
|
15564
|
+
return new Promise((resolve, reject)=>{
|
|
15565
|
+
const child = spawn(command, args, {
|
|
14880
15566
|
detached: true,
|
|
14881
15567
|
stdio: 'ignore'
|
|
14882
|
-
})
|
|
15568
|
+
});
|
|
15569
|
+
child.once('error', reject);
|
|
15570
|
+
child.once('spawn', ()=>{
|
|
15571
|
+
child.unref();
|
|
15572
|
+
resolve();
|
|
15573
|
+
});
|
|
15574
|
+
});
|
|
15575
|
+
}
|
|
15576
|
+
async function openInFileManager(target) {
|
|
15577
|
+
try {
|
|
15578
|
+
const absolute = assertDirectory(target);
|
|
15579
|
+
const { command, args } = revealCommand(absolute);
|
|
15580
|
+
await spawnDetached(command, args);
|
|
14883
15581
|
return {
|
|
14884
15582
|
ok: true,
|
|
14885
|
-
message:
|
|
15583
|
+
message: `已在文件管理器中打开 ${absolute}`
|
|
14886
15584
|
};
|
|
14887
15585
|
} catch (error) {
|
|
14888
15586
|
const message = error instanceof errors_CliError ? error.message : String(error);
|
|
14889
15587
|
return {
|
|
14890
15588
|
ok: false,
|
|
14891
|
-
message
|
|
15589
|
+
message: `打开目录失败:${message}`
|
|
14892
15590
|
};
|
|
14893
15591
|
}
|
|
14894
15592
|
}
|
|
15593
|
+
const PICK_TIMEOUT_MS = 300000;
|
|
15594
|
+
function runCapture(command, args) {
|
|
15595
|
+
return new Promise((resolve)=>{
|
|
15596
|
+
execFile(command, args, {
|
|
15597
|
+
timeout: PICK_TIMEOUT_MS,
|
|
15598
|
+
maxBuffer: 4194304,
|
|
15599
|
+
windowsHide: false
|
|
15600
|
+
}, (error, stdout, stderr)=>{
|
|
15601
|
+
const code = null === error ? 0 : error.code;
|
|
15602
|
+
resolve({
|
|
15603
|
+
code: 'number' == typeof code ? code : 1,
|
|
15604
|
+
stdout: String(stdout ?? ''),
|
|
15605
|
+
stderr: String(stderr ?? '')
|
|
15606
|
+
});
|
|
15607
|
+
});
|
|
15608
|
+
});
|
|
15609
|
+
}
|
|
15610
|
+
function escapeAppleScript(value) {
|
|
15611
|
+
return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
15612
|
+
}
|
|
15613
|
+
function escapePowerShell(value) {
|
|
15614
|
+
return value.replace(/'/g, "''");
|
|
15615
|
+
}
|
|
15616
|
+
async function pickOnMac(title, defaultPath) {
|
|
15617
|
+
const prompt = escapeAppleScript(title);
|
|
15618
|
+
const location = null === defaultPath || 0 === defaultPath.length ? '' : ` default location POSIX file "${escapeAppleScript(defaultPath)}"`;
|
|
15619
|
+
const script = [
|
|
15620
|
+
'try',
|
|
15621
|
+
` set theFolder to choose folder with prompt "${prompt}"${location}`,
|
|
15622
|
+
' return POSIX path of theFolder',
|
|
15623
|
+
'on error number -128',
|
|
15624
|
+
' return ""',
|
|
15625
|
+
'end try'
|
|
15626
|
+
].join('\n');
|
|
15627
|
+
const result = await runCapture("osascript", [
|
|
15628
|
+
'-e',
|
|
15629
|
+
script
|
|
15630
|
+
]);
|
|
15631
|
+
if (0 !== result.code) return {
|
|
15632
|
+
ok: false,
|
|
15633
|
+
path: null,
|
|
15634
|
+
cancelled: false,
|
|
15635
|
+
message: (result.stderr.trim().split('\n').pop() ?? "osascript 执行失败").slice(0, 200)
|
|
15636
|
+
};
|
|
15637
|
+
const picked = result.stdout.trim();
|
|
15638
|
+
if (0 === picked.length) return {
|
|
15639
|
+
ok: true,
|
|
15640
|
+
path: null,
|
|
15641
|
+
cancelled: true,
|
|
15642
|
+
message: '已取消'
|
|
15643
|
+
};
|
|
15644
|
+
return {
|
|
15645
|
+
ok: true,
|
|
15646
|
+
path: picked.length > 1 ? picked.replace(/\/+$/, '') : picked,
|
|
15647
|
+
cancelled: false,
|
|
15648
|
+
message: picked
|
|
15649
|
+
};
|
|
15650
|
+
}
|
|
15651
|
+
async function pickOnWindows(title, defaultPath) {
|
|
15652
|
+
const description = escapePowerShell(title);
|
|
15653
|
+
const initial = null === defaultPath || 0 === defaultPath.length ? '' : `$dialog.SelectedPath = '${escapePowerShell(defaultPath)}';`;
|
|
15654
|
+
const script = [
|
|
15655
|
+
'Add-Type -AssemblyName System.Windows.Forms',
|
|
15656
|
+
'$dialog = New-Object System.Windows.Forms.FolderBrowserDialog',
|
|
15657
|
+
`$dialog.Description = '${description}'`,
|
|
15658
|
+
'$dialog.ShowNewFolderButton = $true',
|
|
15659
|
+
initial,
|
|
15660
|
+
"if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {",
|
|
15661
|
+
' Write-Output $dialog.SelectedPath',
|
|
15662
|
+
'} else {',
|
|
15663
|
+
" Write-Output ''",
|
|
15664
|
+
'}'
|
|
15665
|
+
].filter((line)=>line.length > 0).join('; ');
|
|
15666
|
+
for (const shell of [
|
|
15667
|
+
'powershell.exe',
|
|
15668
|
+
'pwsh.exe'
|
|
15669
|
+
]){
|
|
15670
|
+
const result = await runCapture(shell, [
|
|
15671
|
+
'-NoProfile',
|
|
15672
|
+
'-STA',
|
|
15673
|
+
'-Command',
|
|
15674
|
+
script
|
|
15675
|
+
]);
|
|
15676
|
+
if (0 !== result.code) continue;
|
|
15677
|
+
const picked = result.stdout.trim();
|
|
15678
|
+
if (0 === picked.length) return {
|
|
15679
|
+
ok: true,
|
|
15680
|
+
path: null,
|
|
15681
|
+
cancelled: true,
|
|
15682
|
+
message: '已取消'
|
|
15683
|
+
};
|
|
15684
|
+
const trimmed = picked.replace(/\\+$/, '');
|
|
15685
|
+
const normalized = /^[a-zA-Z]:$/.test(trimmed) ? `${trimmed}\\` : trimmed;
|
|
15686
|
+
return {
|
|
15687
|
+
ok: true,
|
|
15688
|
+
path: normalized,
|
|
15689
|
+
cancelled: false,
|
|
15690
|
+
message: normalized
|
|
15691
|
+
};
|
|
15692
|
+
}
|
|
15693
|
+
return {
|
|
15694
|
+
ok: false,
|
|
15695
|
+
path: null,
|
|
15696
|
+
cancelled: false,
|
|
15697
|
+
message: '未找到可用的 PowerShell'
|
|
15698
|
+
};
|
|
15699
|
+
}
|
|
15700
|
+
async function pickOnLinux(title, defaultPath) {
|
|
15701
|
+
const args = [
|
|
15702
|
+
'--file-selection',
|
|
15703
|
+
'--directory',
|
|
15704
|
+
`--title=${title}`
|
|
15705
|
+
];
|
|
15706
|
+
if (null !== defaultPath && defaultPath.length > 0) args.push(`--filename=${defaultPath.replace(/\/?$/, '/')}`);
|
|
15707
|
+
const result = await runCapture('zenity', args);
|
|
15708
|
+
if (1 === result.code) return {
|
|
15709
|
+
ok: true,
|
|
15710
|
+
path: null,
|
|
15711
|
+
cancelled: true,
|
|
15712
|
+
message: '已取消'
|
|
15713
|
+
};
|
|
15714
|
+
if (0 !== result.code) return {
|
|
15715
|
+
ok: false,
|
|
15716
|
+
path: null,
|
|
15717
|
+
cancelled: false,
|
|
15718
|
+
message: (result.stderr.trim().split('\n').pop() ?? 'zenity 执行失败').slice(0, 200)
|
|
15719
|
+
};
|
|
15720
|
+
const picked = result.stdout.trim();
|
|
15721
|
+
if (0 === picked.length) return {
|
|
15722
|
+
ok: true,
|
|
15723
|
+
path: null,
|
|
15724
|
+
cancelled: true,
|
|
15725
|
+
message: '已取消'
|
|
15726
|
+
};
|
|
15727
|
+
const trimmed = picked.replace(/\/+$/, '');
|
|
15728
|
+
const normalized = 0 === trimmed.length ? '/' : trimmed;
|
|
15729
|
+
return {
|
|
15730
|
+
ok: true,
|
|
15731
|
+
path: normalized,
|
|
15732
|
+
cancelled: false,
|
|
15733
|
+
message: normalized
|
|
15734
|
+
};
|
|
15735
|
+
}
|
|
15736
|
+
async function pickDirectoryNatively(options) {
|
|
15737
|
+
const title = options.title?.trim() ?? '';
|
|
15738
|
+
const prompt = 0 === title.length ? '选择目录' : title;
|
|
15739
|
+
let initial = options.defaultPath?.trim() ?? null;
|
|
15740
|
+
if (null !== initial && 0 === initial.length) initial = null;
|
|
15741
|
+
if (null !== initial && !external_node_fs_existsSync(initial)) initial = null;
|
|
15742
|
+
if ('darwin' === process.platform) return pickOnMac(prompt, initial);
|
|
15743
|
+
if ('win32' === process.platform) return pickOnWindows(prompt, initial);
|
|
15744
|
+
return pickOnLinux(prompt, initial);
|
|
15745
|
+
}
|
|
14895
15746
|
function requireDocsRoot(configPath) {
|
|
14896
15747
|
const loaded = loadConfig(configPath);
|
|
14897
15748
|
const root = loaded.config?.docs.root ?? '';
|
|
@@ -14965,8 +15816,8 @@ async function readJsonBody(request) {
|
|
|
14965
15816
|
}
|
|
14966
15817
|
function resolveStaticPath(uiDir, pathname) {
|
|
14967
15818
|
const decoded = decodeURIComponent(pathname);
|
|
14968
|
-
const target =
|
|
14969
|
-
const root =
|
|
15819
|
+
const target = external_node_path_resolve(uiDir, `.${'/' === decoded ? '/index.html' : decoded}`);
|
|
15820
|
+
const root = external_node_path_resolve(uiDir) + sep;
|
|
14970
15821
|
return target.startsWith(root) ? target : null;
|
|
14971
15822
|
}
|
|
14972
15823
|
function serveStatic(response, uiDir, pathname) {
|
|
@@ -15044,10 +15895,20 @@ async function startServer(options) {
|
|
|
15044
15895
|
if ('GET' === request.method && '/api/fs/list' === url.pathname) return void sendJson(response, 200, listDirectories(url.searchParams.get('path') ?? void 0));
|
|
15045
15896
|
if ('POST' === request.method && '/api/fs/open' === url.pathname) {
|
|
15046
15897
|
const body = await readJsonBody(request);
|
|
15047
|
-
sendJson(response, 200, openInFileManager(pickString(body, 'path')));
|
|
15898
|
+
sendJson(response, 200, await openInFileManager(pickString(body, 'path')));
|
|
15899
|
+
return;
|
|
15900
|
+
}
|
|
15901
|
+
if ('POST' === request.method && '/api/fs/pick' === url.pathname) {
|
|
15902
|
+
const body = await readJsonBody(request);
|
|
15903
|
+
const title = pickString(body, 'title');
|
|
15904
|
+
const defaultPath = pickString(body, 'defaultPath');
|
|
15905
|
+
sendJson(response, 200, await pickDirectoryNatively({
|
|
15906
|
+
title: title.length > 0 ? title : void 0,
|
|
15907
|
+
defaultPath: defaultPath.length > 0 ? defaultPath : null
|
|
15908
|
+
}));
|
|
15048
15909
|
return;
|
|
15049
15910
|
}
|
|
15050
|
-
if ('POST' === request.method && '/api/reveal' === url.pathname) return void sendJson(response, 200, openInFileManager(external_node_path_dirname(paths_resolveConfigPath(options.configPath))));
|
|
15911
|
+
if ('POST' === request.method && '/api/reveal' === url.pathname) return void sendJson(response, 200, await openInFileManager(external_node_path_dirname(paths_resolveConfigPath(options.configPath))));
|
|
15051
15912
|
if ('GET' === request.method && '/api/task-actions' === url.pathname) {
|
|
15052
15913
|
const loaded = loadConfig(options.configPath);
|
|
15053
15914
|
const developer = url.searchParams.get('developer') ?? '';
|
|
@@ -15209,9 +16070,9 @@ function assertUiBuilt(uiDir) {
|
|
|
15209
16070
|
function defaultUiDir() {
|
|
15210
16071
|
const here = external_node_path_dirname(fileURLToPath(import.meta.url));
|
|
15211
16072
|
const candidates = [
|
|
15212
|
-
|
|
15213
|
-
|
|
15214
|
-
|
|
16073
|
+
external_node_path_resolve(here, '..', 'ui-dist'),
|
|
16074
|
+
external_node_path_resolve(here, '..', '..', 'ui-dist'),
|
|
16075
|
+
external_node_path_resolve(process.cwd(), 'ui-dist')
|
|
15215
16076
|
];
|
|
15216
16077
|
return candidates.find((dir)=>external_node_fs_existsSync(external_node_path_join(dir, 'index.html'))) ?? candidates[0] ?? 'ui-dist';
|
|
15217
16078
|
}
|
|
@@ -15267,7 +16128,7 @@ async function findAvailablePort(desired, attempts = 20) {
|
|
|
15267
16128
|
throw new errors_CliError(`端口 ${desired}–${desired + attempts - 1} 均被占用,请用 --port 指定其他端口`, errors_EXIT.USAGE);
|
|
15268
16129
|
}
|
|
15269
16130
|
async function runServe(options) {
|
|
15270
|
-
const uiDir = void 0 !== options.uiDir ?
|
|
16131
|
+
const uiDir = void 0 !== options.uiDir ? external_node_path_resolve(options.uiDir) : defaultUiDir();
|
|
15271
16132
|
assertUiBuilt(uiDir);
|
|
15272
16133
|
const port = void 0 === options.port ? 4317 : Number.parseInt(options.port, 10);
|
|
15273
16134
|
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new errors_CliError(`--port 不是合法端口:${options.port ?? ''}`, errors_EXIT.USAGE);
|
|
@@ -15322,7 +16183,7 @@ function registerReset(program) {
|
|
|
15322
16183
|
}
|
|
15323
16184
|
function buildProgram() {
|
|
15324
16185
|
const program = new command_Command();
|
|
15325
|
-
program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与终端仓库映射').version("0.5.
|
|
16186
|
+
program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与终端仓库映射').version("0.5.2", '-v, --version', '显示版本号').showHelpAfterError();
|
|
15326
16187
|
registerInit(program);
|
|
15327
16188
|
registerShow(program);
|
|
15328
16189
|
registerGet(program);
|