ylcwf 0.2.0 → 0.3.0

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 CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## 0.3.0
6
+
7
+ - 迭代文档的需求清单与任务清单增加「最后更新」列(`YYYY-MM-DD HH:mm`,必填),状态变化时自动刷新
8
+ - `ylcwf task` 支持 `--commit` / `--push` 覆盖,`docs.git.cli` 与 `docs.git.ui` 分别控制 CLI 与界面的提交策略(默认提交不推送,仅作用于文档仓库)
9
+ - 看板任务表与需求表展示最后更新时间
10
+ - 设置页新增 CLI / 界面两组「自动提交 / 提交后推送」开关
11
+ - 降级解析遇到旧模板(缺「最后更新」列)时给出明确提示,不再静默返回空数据
12
+ - 修复:迭代目录名大小写与磁盘不一致时 git pathspec 失败(改为按真实目录名解析)
13
+
5
14
  ## 0.2.0
6
15
 
7
16
  - 发布脚本自动清理历史安装包,只保留最近两个版本(`pnpm release --prune-only`)
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Command } from "commander";
2
- import { appendFileSync, chmodSync, closeSync, copyFileSync, existsSync as external_node_fs_existsSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
2
+ import { appendFileSync, chmodSync, closeSync, copyFileSync, existsSync as external_node_fs_existsSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
3
3
  import { execFileSync, spawn } from "node:child_process";
4
- import { basename, dirname, extname, isAbsolute, join as external_node_path_join, resolve, sep } from "node:path";
4
+ import { basename, dirname, extname, isAbsolute, join as external_node_path_join, relative as external_node_path_relative, resolve, sep } from "node:path";
5
5
  import { isMap, isSeq, parseDocument } from "yaml";
6
6
  import { homedir, tmpdir as external_node_os_tmpdir } from "node:os";
7
7
  import picocolors from "picocolors";
@@ -115,8 +115,21 @@ const PROFILE_KEYS = new Set([
115
115
  ]);
116
116
  const DOCS_KEYS = new Set([
117
117
  'root',
118
- 'remote'
118
+ 'remote',
119
+ 'git'
119
120
  ]);
121
+ const GIT_KEYS = new Set([
122
+ 'cli',
123
+ 'ui'
124
+ ]);
125
+ const POLICY_KEYS = new Set([
126
+ 'commit',
127
+ 'push'
128
+ ]);
129
+ const DEFAULT_GIT_POLICY = {
130
+ commit: true,
131
+ push: false
132
+ };
120
133
  const TERMINAL_KEYS = new Set([
121
134
  'aliases',
122
135
  'repos'
@@ -249,9 +262,58 @@ function parseDocs(raw, options, issues) {
249
262
  }
250
263
  remote = trimmed;
251
264
  }
265
+ const git = parseGitPolicy(raw['git'], issues);
266
+ if (null === git) return null;
252
267
  return {
253
268
  root,
254
- remote
269
+ remote,
270
+ git
271
+ };
272
+ }
273
+ function parseGitPolicy(raw, issues) {
274
+ if (null == raw) return {
275
+ cli: {
276
+ ...DEFAULT_GIT_POLICY
277
+ },
278
+ ui: {
279
+ ...DEFAULT_GIT_POLICY
280
+ }
281
+ };
282
+ if (!utils_isRecord(raw)) {
283
+ issues.push(schema_error('GIT_POLICY_INVALID', 'docs.git 必须是对象', 'docs.git'));
284
+ return null;
285
+ }
286
+ issues.push(...unknownKeys(raw, GIT_KEYS, 'docs.git'));
287
+ const read = (key)=>{
288
+ const value = raw[key];
289
+ if (null == value) return {
290
+ ...DEFAULT_GIT_POLICY
291
+ };
292
+ if (!utils_isRecord(value)) {
293
+ issues.push(schema_error('GIT_POLICY_INVALID', `docs.git.${key} 必须是对象`, `docs.git.${key}`));
294
+ return null;
295
+ }
296
+ issues.push(...unknownKeys(value, POLICY_KEYS, `docs.git.${key}`));
297
+ const pick = (field, fallback)=>{
298
+ const item = value[field];
299
+ if (void 0 === item) return fallback;
300
+ if ('boolean' != typeof item) {
301
+ issues.push(schema_error('GIT_POLICY_INVALID', `docs.git.${key}.${field} 必须是布尔值`, `docs.git.${key}.${field}`));
302
+ return fallback;
303
+ }
304
+ return item;
305
+ };
306
+ return {
307
+ commit: pick('commit', DEFAULT_GIT_POLICY.commit),
308
+ push: pick('push', DEFAULT_GIT_POLICY.push)
309
+ };
310
+ };
311
+ const cli = read('cli');
312
+ const ui = read('ui');
313
+ if (null === cli || null === ui) return null;
314
+ return {
315
+ cli,
316
+ ui
255
317
  };
256
318
  }
257
319
  function parseRepos(raw, where, issues) {
@@ -533,6 +595,9 @@ profile:
533
595
 
534
596
  docs:
535
597
  root: ''
598
+ git:
599
+ cli: { commit: true, push: false }
600
+ ui: { commit: true, push: false }
536
601
 
537
602
  terminals: {}
538
603
  `;
@@ -1061,10 +1126,11 @@ const SIDE_SET = new Set(SIDES);
1061
1126
  function assertSettable(path) {
1062
1127
  const [first, second, third, fourth] = path;
1063
1128
  if (2 === path.length && 'docs' === first && ('root' === second || 'remote' === second)) return;
1129
+ if (4 === path.length && 'docs' === first && 'git' === second && ('cli' === third || 'ui' === third) && ('commit' === fourth || 'push' === fourth)) return;
1064
1130
  if (2 === path.length && 'profile' === first && ('developer' === second || 'role' === second || 'mode' === second)) return;
1065
1131
  if (4 === path.length && 'terminals' === first && void 0 !== second && 'repos' === third && void 0 !== fourth && SIDE_SET.has(fourth)) return;
1066
1132
  if (3 === path.length && 'terminals' === first && void 0 !== second && 'aliases' === third) return;
1067
- throw new errors_CliError(`不支持通过 set 修改该路径:${path.join('.')}\n允许:docs.root / docs.remote / profile.developer / profile.role / profile.mode / terminals.<终端>.aliases / terminals.<终端>.repos.frontend|backend\n终端的新增与删除请用:ylcwf terminal add | rm`, errors_EXIT.USAGE);
1133
+ throw new errors_CliError(`不支持通过 set 修改该路径:${path.join('.')}\n允许:docs.root / docs.remote / docs.git.<cli|ui>.<commit|push> / profile.developer / profile.role / profile.mode / terminals.<终端>.aliases / terminals.<终端>.repos.frontend|backend\n终端的新增与删除请用:ylcwf terminal add | rm`, errors_EXIT.USAGE);
1068
1134
  }
1069
1135
  function coerceValue(path, raw) {
1070
1136
  const key = path[path.length - 1];
@@ -1453,6 +1519,15 @@ function safeSegment(value, label) {
1453
1519
  if (!SAFE_SEGMENT.test(trimmed) || '.' === trimmed || '..' === trimmed) throw new errors_CliError(`${label} 不合法:${value}`, errors_EXIT.USAGE);
1454
1520
  return trimmed;
1455
1521
  }
1522
+ function buildCommitMessage(iteration, action, taskIds, _action) {
1523
+ const meta = ACTION_META[action];
1524
+ return `docs(${iteration}): ${meta.label} ${taskIds.join(',')}(${meta.from}→${meta.to})`;
1525
+ }
1526
+ function nowStamp() {
1527
+ const now = new Date();
1528
+ const pad = (value)=>String(value).padStart(2, '0');
1529
+ return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`;
1530
+ }
1456
1531
  const ACTION_META = {
1457
1532
  start: {
1458
1533
  label: '开始实施',
@@ -1475,6 +1550,95 @@ const ACTION_META = {
1475
1550
  to: '进行中'
1476
1551
  }
1477
1552
  };
1553
+ function commitInDocsRepo(docsRoot, file, message, push) {
1554
+ const run = (args)=>{
1555
+ try {
1556
+ const output = execFileSync('git', args, {
1557
+ cwd: docsRoot,
1558
+ encoding: 'utf8',
1559
+ stdio: [
1560
+ 'ignore',
1561
+ 'pipe',
1562
+ 'pipe'
1563
+ ]
1564
+ });
1565
+ return {
1566
+ ok: true,
1567
+ output
1568
+ };
1569
+ } catch (error) {
1570
+ const stderr = error.stderr ?? '';
1571
+ return {
1572
+ ok: false,
1573
+ output: stderr.trim() || String(error)
1574
+ };
1575
+ }
1576
+ };
1577
+ const inside = run([
1578
+ 'rev-parse',
1579
+ '--is-inside-work-tree'
1580
+ ]);
1581
+ if (!inside.ok || 'true' !== inside.output.trim()) return {
1582
+ committed: false,
1583
+ pushed: false,
1584
+ message: '文档仓库不是 git 仓库,已跳过提交'
1585
+ };
1586
+ let realRoot = docsRoot;
1587
+ let realFile = file;
1588
+ try {
1589
+ realRoot = realpathSync(docsRoot);
1590
+ realFile = realpathSync(file);
1591
+ } catch {}
1592
+ const relativePath = external_node_path_relative(realRoot, realFile);
1593
+ if (relativePath.startsWith('..') || isAbsolute(relativePath)) return {
1594
+ committed: false,
1595
+ pushed: false,
1596
+ message: '目标文件不在文档仓库内,已跳过提交'
1597
+ };
1598
+ const added = run([
1599
+ 'add',
1600
+ '--',
1601
+ relativePath
1602
+ ]);
1603
+ if (!added.ok) return {
1604
+ committed: false,
1605
+ pushed: false,
1606
+ message: `git add 失败:${added.output.split('\n')[0] ?? ''}`
1607
+ };
1608
+ const committed = run([
1609
+ 'commit',
1610
+ '-m',
1611
+ message,
1612
+ '--',
1613
+ relativePath
1614
+ ]);
1615
+ if (!committed.ok) {
1616
+ const firstLine = committed.output.split('\n')[0] ?? '';
1617
+ return {
1618
+ committed: false,
1619
+ pushed: false,
1620
+ message: `提交未完成:${firstLine}`
1621
+ };
1622
+ }
1623
+ if (!push) return {
1624
+ committed: true,
1625
+ pushed: false,
1626
+ message: '已提交(未推送)'
1627
+ };
1628
+ const pushed = run([
1629
+ 'push'
1630
+ ]);
1631
+ if (!pushed.ok) return {
1632
+ committed: true,
1633
+ pushed: false,
1634
+ message: `已提交但推送失败,请手动处理:${pushed.output.split('\n')[0] ?? ''}`
1635
+ };
1636
+ return {
1637
+ committed: true,
1638
+ pushed: true,
1639
+ message: '已提交并推送'
1640
+ };
1641
+ }
1478
1642
  function appendHistory(entry) {
1479
1643
  try {
1480
1644
  const target = historyPath();
@@ -1512,12 +1676,14 @@ const TASK_HEADERS = {
1512
1676
  requirement: '关联需求编号',
1513
1677
  selfTest: 'AI自测状态',
1514
1678
  acceptance: '开发人工验收',
1515
- status: '任务状态'
1679
+ status: '任务状态',
1680
+ updatedAt: '最后更新'
1516
1681
  };
1517
1682
  const REQUIREMENT_HEADERS = {
1518
1683
  id: '需求编号',
1519
1684
  status: '开发状态',
1520
- progress: '开发进度(%)'
1685
+ progress: '开发进度(%)',
1686
+ updatedAt: '最后更新'
1521
1687
  };
1522
1688
  function columnIndex(headerCells, name) {
1523
1689
  const index = headerCells.findIndex((cell)=>cell.trim() === name);
@@ -1636,8 +1802,16 @@ function updateDetailBlock(lines, taskId, updates) {
1636
1802
  }
1637
1803
  return next;
1638
1804
  }
1805
+ function realIterationName(docsRoot, iteration) {
1806
+ try {
1807
+ const match = readdirSync(docsRoot).find((entry)=>entry.toLowerCase() === iteration.toLowerCase());
1808
+ return match ?? iteration;
1809
+ } catch {
1810
+ return iteration;
1811
+ }
1812
+ }
1639
1813
  function loadDoc(docsRoot, iterationRaw, developerRaw) {
1640
- const iteration = safeSegment(iterationRaw, '迭代目录');
1814
+ const iteration = realIterationName(docsRoot, safeSegment(iterationRaw, '迭代目录'));
1641
1815
  const developer = safeSegment(developerRaw, '开发者标识');
1642
1816
  const file = external_node_path_join(docsRoot, iteration, `${developer}.md`);
1643
1817
  if (!external_node_fs_existsSync(file)) throw new errors_CliError(`文档不存在:${iteration}/${developer}.md`, errors_EXIT.NOT_FOUND);
@@ -1666,6 +1840,7 @@ function computeUpdate(lines, taskId, action) {
1666
1840
  const changes = [];
1667
1841
  if (nextStatus !== currentStatus) changes.push(`${taskId} 任务状态:${currentStatus} → ${nextStatus}`);
1668
1842
  if (nextAcceptance !== currentAcceptance) changes.push(`${taskId} 开发人工验收:${currentAcceptance} → ${nextAcceptance}`);
1843
+ const stamp = nowStamp();
1669
1844
  const updated = [
1670
1845
  ...lines
1671
1846
  ];
@@ -1674,6 +1849,7 @@ function computeUpdate(lines, taskId, action) {
1674
1849
  ];
1675
1850
  taskCells[statusIndex] = nextStatus;
1676
1851
  taskCells[acceptanceIndex] = nextAcceptance;
1852
+ taskCells[columnIndex(header, TASK_HEADERS.updatedAt)] = stamp;
1677
1853
  updated[target.index] = joinRow(taskCells);
1678
1854
  const withDetail = updateDetailBlock(updated, taskId, {
1679
1855
  任务状态: nextStatus,
@@ -1693,6 +1869,7 @@ function computeUpdate(lines, taskId, action) {
1693
1869
  const previousProgress = requirementCells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.progress)] ?? '';
1694
1870
  requirementCells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.status)] = requirementStatus;
1695
1871
  requirementCells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.progress)] = String(progress);
1872
+ if (previousStatus !== requirementStatus || previousProgress !== String(progress)) requirementCells[columnIndex(requirementParse.header, REQUIREMENT_HEADERS.updatedAt)] = stamp;
1696
1873
  withDetail[requirementTarget.index] = joinRow(requirementCells);
1697
1874
  if (previousStatus !== requirementStatus) changes.push(`需求 ${target.requirementId} 开发状态:${previousStatus} → ${requirementStatus}`);
1698
1875
  if (previousProgress !== String(progress)) changes.push(`需求 ${target.requirementId} 开发进度:${previousProgress}% → ${progress}%`);
@@ -1701,7 +1878,7 @@ function computeUpdate(lines, taskId, action) {
1701
1878
  changes
1702
1879
  };
1703
1880
  }
1704
- function commit(context, lines, changes, message, iteration, developer, action, taskIds) {
1881
+ function commit(context, lines, changes, message, iteration, developer, action, taskIds, options) {
1705
1882
  if (statSync(context.file).mtimeMs !== context.mtime) throw new errors_CliError('文件已被外部修改,请刷新后重试', errors_EXIT.INVALID);
1706
1883
  const output = lines.join('\n');
1707
1884
  if (output === context.original) return {
@@ -1723,11 +1900,13 @@ function commit(context, lines, changes, message, iteration, developer, action,
1723
1900
  action,
1724
1901
  changes
1725
1902
  });
1903
+ const git = options.policy.commit ? commitInDocsRepo(options.docsRoot, context.file, options.commitMessage, options.policy.push) : void 0;
1726
1904
  return {
1727
1905
  ok: true,
1728
1906
  message,
1729
1907
  changes,
1730
- file: context.file
1908
+ file: context.file,
1909
+ git
1731
1910
  };
1732
1911
  }
1733
1912
  function applyBatchAction(options) {
@@ -1740,14 +1919,24 @@ function applyBatchAction(options) {
1740
1919
  lines = result.lines;
1741
1920
  changes.push(...result.changes);
1742
1921
  }
1743
- return commit(context, lines, changes, `已对 ${options.taskIds.length} 个任务执行「${ACTION_META[options.action].label}」`, safeSegment(options.iteration, '迭代目录'), safeSegment(options.developer, '开发者标识'), options.action, options.taskIds);
1922
+ return commit(context, lines, changes, `已对 ${options.taskIds.length} 个任务执行「${ACTION_META[options.action].label}」`, safeSegment(options.iteration, '迭代目录'), safeSegment(options.developer, '开发者标识'), options.action, options.taskIds, {
1923
+ docsRoot: options.docsRoot,
1924
+ policy: options.policy,
1925
+ commitMessage: buildCommitMessage(options.iteration, options.action, options.taskIds, options.action)
1926
+ });
1744
1927
  }
1745
1928
  function applyTaskAction(options) {
1746
1929
  const context = loadDoc(options.docsRoot, options.iteration, options.developer);
1747
1930
  const result = computeUpdate(context.lines, options.taskId, options.action);
1748
1931
  return commit(context, result.lines, result.changes, `已执行「${ACTION_META[options.action].label}」`, safeSegment(options.iteration, '迭代目录'), safeSegment(options.developer, '开发者标识'), options.action, [
1749
1932
  options.taskId
1750
- ]);
1933
+ ], {
1934
+ docsRoot: options.docsRoot,
1935
+ policy: options.policy,
1936
+ commitMessage: buildCommitMessage(options.iteration, options.action, [
1937
+ options.taskId
1938
+ ], options.action)
1939
+ });
1751
1940
  }
1752
1941
  function validateAfterWrite(docsRoot, iteration, developer) {
1753
1942
  const script = external_node_path_join(docsRoot, "scripts", 'validate_task_doc.py');
@@ -1814,7 +2003,14 @@ function recalcRequirements(options) {
1814
2003
  };
1815
2004
  return {
1816
2005
  changes,
1817
- file: commit(context, lines, changes, `已重算 ${requirementParse.rows.length} 个需求的状态与进度`, safeSegment(options.iteration, '迭代目录'), safeSegment(options.developer, '开发者标识'), 'start', []).file
2006
+ file: commit(context, lines, changes, `已重算 ${requirementParse.rows.length} 个需求的状态与进度`, safeSegment(options.iteration, '迭代目录'), safeSegment(options.developer, '开发者标识'), 'start', [], {
2007
+ docsRoot: options.docsRoot,
2008
+ policy: {
2009
+ commit: false,
2010
+ push: false
2011
+ },
2012
+ commitMessage: `docs(${options.iteration}): 重算需求状态与进度`
2013
+ }).file
1818
2014
  };
1819
2015
  }
1820
2016
  function availableActions(options) {
@@ -1878,13 +2074,23 @@ function requireWriteContext(options) {
1878
2074
  const config = ready.config;
1879
2075
  if ('developer' !== config.profile.mode) throw new errors_CliError('干系人模式不支持修改任务状态', errors_EXIT.USAGE);
1880
2076
  if (0 === config.docs.root.trim().length) throw new errors_CliError('未配置文档仓库:请先设置 docs.root', errors_EXIT.NOT_FOUND);
2077
+ const base = config.docs.git?.cli ?? {
2078
+ commit: true,
2079
+ push: false
2080
+ };
2081
+ const policy = {
2082
+ commit: options.commit ?? base.commit,
2083
+ push: options.push ?? base.push
2084
+ };
2085
+ if (policy.push) policy.commit = true;
1881
2086
  return {
1882
2087
  docsRoot: config.docs.root,
1883
- developer: resolveDeveloper(options, config.profile.developer)
2088
+ developer: resolveDeveloper(options, config.profile.developer),
2089
+ policy
1884
2090
  };
1885
2091
  }
1886
2092
  function runAction(action, taskId, options) {
1887
- const { docsRoot, developer } = requireWriteContext(options);
2093
+ const { docsRoot, developer, policy } = requireWriteContext(options);
1888
2094
  const iteration = resolveIteration(options, docsRoot);
1889
2095
  const format = parseFormat(options.format);
1890
2096
  if (true === options.dryRun) {
@@ -1911,12 +2117,14 @@ function runAction(action, taskId, options) {
1911
2117
  iteration,
1912
2118
  developer,
1913
2119
  taskId,
1914
- action
2120
+ action,
2121
+ policy
1915
2122
  });
1916
2123
  if ('json' === format) return void printJson(result);
1917
2124
  printLine(result.message);
1918
2125
  for (const change of result.changes)printLine(` · ${change}`);
1919
2126
  printLine(`文档:${result.file}`);
2127
+ if (void 0 !== result.git) printLine(`git:${result.git.message}`);
1920
2128
  }
1921
2129
  function runActions(options) {
1922
2130
  const { docsRoot, developer } = requireWriteContext(options);
@@ -1940,7 +2148,7 @@ function runActions(options) {
1940
2148
  }
1941
2149
  }
1942
2150
  function runBatch(action, taskIds, options) {
1943
- const { docsRoot, developer } = requireWriteContext(options);
2151
+ const { docsRoot, developer, policy } = requireWriteContext(options);
1944
2152
  const iteration = resolveIteration(options, docsRoot);
1945
2153
  const format = parseFormat(options.format);
1946
2154
  const result = applyBatchAction({
@@ -1948,11 +2156,13 @@ function runBatch(action, taskIds, options) {
1948
2156
  iteration,
1949
2157
  developer,
1950
2158
  taskIds,
1951
- action
2159
+ action,
2160
+ policy
1952
2161
  });
1953
2162
  if ('json' === format) return void printJson(result);
1954
2163
  printLine(result.message);
1955
2164
  for (const change of result.changes)printLine(` · ${change}`);
2165
+ if (void 0 !== result.git) printLine(`git:${result.git.message}`);
1956
2166
  }
1957
2167
  function runHistory(taskId, options) {
1958
2168
  const { docsRoot, developer } = requireWriteContext(options);
@@ -1998,7 +2208,7 @@ function registerTask(program) {
1998
2208
  'submit',
1999
2209
  'accept',
2000
2210
  'reject'
2001
- ])commonOptions(task.command(`${action} <taskId>`)).description(`执行「${ACTION_META[action].label}」:${ACTION_META[action].from} → ${ACTION_META[action].to}`).option('--dry-run', '只校验是否允许,不写入').action((taskId, options)=>runAction(action, taskId, options));
2211
+ ])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));
2002
2212
  commonOptions(task.command('batch <action> <taskIds...>')).description('批量执行同一动作,例如: ylcwf task batch accept "#2755-T1" "#2755-T2"').action((action, taskIds, options)=>{
2003
2213
  if (!(action in ACTION_META)) throw new errors_CliError(`未知动作:${action}(可选 ${Object.keys(ACTION_META).join(' / ')})`, errors_EXIT.USAGE);
2004
2214
  runBatch(action, taskIds, options);
@@ -2213,6 +2423,23 @@ function syncDocument(doc, next) {
2213
2423
  'docs',
2214
2424
  'remote'
2215
2425
  ], next.docs.remote);
2426
+ for (const side of [
2427
+ 'cli',
2428
+ 'ui'
2429
+ ]){
2430
+ doc.setIn([
2431
+ 'docs',
2432
+ 'git',
2433
+ side,
2434
+ 'commit'
2435
+ ], next.docs.git[side].commit);
2436
+ doc.setIn([
2437
+ 'docs',
2438
+ 'git',
2439
+ side,
2440
+ 'push'
2441
+ ], next.docs.git[side].push);
2442
+ }
2216
2443
  const current = doc.toJS();
2217
2444
  const currentTerminals = utils_isRecord(current) && utils_isRecord(current['terminals']) ? Object.keys(current['terminals']) : [];
2218
2445
  for (const key of currentTerminals)if (!Object.hasOwn(next.terminals, key)) doc.deleteIn([
@@ -2316,7 +2543,7 @@ function readState(explicitPath) {
2316
2543
  issues: checked.issues,
2317
2544
  backups: listBackups(explicitPath),
2318
2545
  meta: {
2319
- version: "0.2.0",
2546
+ version: "0.3.0",
2320
2547
  features: SERVER_FEATURES
2321
2548
  }
2322
2549
  };
@@ -2416,7 +2643,7 @@ const RESERVED_PREFIXES = [
2416
2643
  '_prd/'
2417
2644
  ];
2418
2645
  const git_SAFE_SEGMENT = /^[A-Za-z0-9._\-\u4e00-\u9fa5]+$/;
2419
- function git(docsRoot, args, timeoutMs = 15000) {
2646
+ function git_git(docsRoot, args, timeoutMs = 15000) {
2420
2647
  return execFileSync('git', [
2421
2648
  '-C',
2422
2649
  docsRoot,
@@ -2434,7 +2661,7 @@ function git(docsRoot, args, timeoutMs = 15000) {
2434
2661
  }
2435
2662
  function tryGit(docsRoot, args, timeoutMs) {
2436
2663
  try {
2437
- return git(docsRoot, args, timeoutMs);
2664
+ return git_git(docsRoot, args, timeoutMs);
2438
2665
  } catch {
2439
2666
  return null;
2440
2667
  }
@@ -2524,7 +2751,7 @@ function getGitStatus(docsRoot) {
2524
2751
  }
2525
2752
  function fetchRemote(docsRoot) {
2526
2753
  try {
2527
- git(docsRoot, [
2754
+ git_git(docsRoot, [
2528
2755
  'fetch',
2529
2756
  '--prune',
2530
2757
  'origin'
@@ -2840,7 +3067,7 @@ function ensureManagedClone(remote) {
2840
3067
  }
2841
3068
  function syncManagedRepo(dir) {
2842
3069
  try {
2843
- git(dir, [
3070
+ git_git(dir, [
2844
3071
  'fetch',
2845
3072
  '--prune',
2846
3073
  '--all'
@@ -2852,7 +3079,7 @@ function syncManagedRepo(dir) {
2852
3079
  '@{u}'
2853
3080
  ]);
2854
3081
  if (null !== upstream) {
2855
- git(dir, [
3082
+ git_git(dir, [
2856
3083
  'reset',
2857
3084
  '--hard',
2858
3085
  upstream
@@ -3048,6 +3275,7 @@ function coerceRequirement(value) {
3048
3275
  status: 'string' == typeof value['status'] ? value['status'] : '',
3049
3276
  progress: String(value['progress'] ?? ''),
3050
3277
  note: 'string' == typeof value['note'] ? value['note'] : '',
3278
+ updatedAt: 'string' == typeof value['updatedAt'] ? value['updatedAt'] : '',
3051
3279
  taskIds: isStringArray(value['taskIds']) ? value['taskIds'] : []
3052
3280
  };
3053
3281
  }
@@ -3064,7 +3292,8 @@ function coerceTask(value) {
3064
3292
  dependencies: isStringArray(value['dependencies']) ? value['dependencies'] : [],
3065
3293
  selfTest: 'string' == typeof value['selfTest'] ? value['selfTest'] : '',
3066
3294
  acceptance: 'string' == typeof value['acceptance'] ? value['acceptance'] : '',
3067
- status: 'string' == typeof value['status'] ? value['status'] : ''
3295
+ status: 'string' == typeof value['status'] ? value['status'] : '',
3296
+ updatedAt: 'string' == typeof value['updatedAt'] ? value['updatedAt'] : ''
3068
3297
  };
3069
3298
  }
3070
3299
  function coerceInfo(value) {
@@ -3168,6 +3397,7 @@ function splitDetails(markdown) {
3168
3397
  return blocks;
3169
3398
  }
3170
3399
  function parseMarkdownDoc(markdown) {
3400
+ const structureErrors = [];
3171
3401
  const readTable = (sectionHeading, headers)=>{
3172
3402
  const section = extractSection(markdown, sectionHeading);
3173
3403
  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));
@@ -3182,7 +3412,8 @@ function parseMarkdownDoc(markdown) {
3182
3412
  '终端',
3183
3413
  '开发状态',
3184
3414
  '开发进度(%)',
3185
- '备注'
3415
+ '备注',
3416
+ '最后更新'
3186
3417
  ]);
3187
3418
  const taskRows = readTable('## 三、任务清单', [
3188
3419
  '任务编号',
@@ -3193,8 +3424,19 @@ function parseMarkdownDoc(markdown) {
3193
3424
  '前置依赖任务编号',
3194
3425
  'AI自测状态',
3195
3426
  '开发人工验收',
3196
- '任务状态'
3427
+ '任务状态',
3428
+ '最后更新'
3197
3429
  ]);
3430
+ if (0 === requirementRows.length) structureErrors.push({
3431
+ level: 'error',
3432
+ code: 'REQUIREMENT_TABLE_MISMATCH',
3433
+ message: '需求清单表头与模板不符(需包含「最后更新」列),请按最新模板补齐'
3434
+ });
3435
+ if (0 === taskRows.length) structureErrors.push({
3436
+ level: 'error',
3437
+ code: 'TASK_TABLE_MISMATCH',
3438
+ message: '任务清单表头与模板不符(需包含「最后更新」列),请按最新模板补齐'
3439
+ });
3198
3440
  const requirements = requirementRows.map((row)=>({
3199
3441
  id: row[0] ?? '',
3200
3442
  title: row[1] ?? '',
@@ -3202,6 +3444,7 @@ function parseMarkdownDoc(markdown) {
3202
3444
  status: row[3] ?? '',
3203
3445
  progress: row[4] ?? '',
3204
3446
  note: row[5] ?? '',
3447
+ updatedAt: row[6] ?? '',
3205
3448
  taskIds: []
3206
3449
  }));
3207
3450
  const tasks = taskRows.map((row)=>({
@@ -3213,7 +3456,8 @@ function parseMarkdownDoc(markdown) {
3213
3456
  dependencies: (row[5] ?? '').split(/[,,]/).map((item)=>item.trim()).filter((item)=>item.length > 0),
3214
3457
  selfTest: row[6] ?? '',
3215
3458
  acceptance: row[7] ?? '',
3216
- status: row[8] ?? ''
3459
+ status: row[8] ?? '',
3460
+ updatedAt: row[9] ?? ''
3217
3461
  }));
3218
3462
  for (const requirement of requirements)requirement.taskIds = tasks.filter((task)=>task.requirementId === requirement.id).map((task)=>task.id);
3219
3463
  const details = splitDetails(markdown);
@@ -3243,7 +3487,7 @@ function parseMarkdownDoc(markdown) {
3243
3487
  },
3244
3488
  requirements,
3245
3489
  tasks,
3246
- errors: [],
3490
+ errors: structureErrors,
3247
3491
  warnings: []
3248
3492
  };
3249
3493
  }
@@ -3521,7 +3765,8 @@ function prepareManagedDocs(configPath) {
3521
3765
  ...loaded.config,
3522
3766
  docs: {
3523
3767
  root: clone.dir,
3524
- remote
3768
+ remote,
3769
+ git: loaded.config.docs.git
3525
3770
  }
3526
3771
  };
3527
3772
  saveConfig(next, configPath);
@@ -3549,7 +3794,8 @@ function completeOnboarding(draftRaw, configPath) {
3549
3794
  ...draft,
3550
3795
  docs: {
3551
3796
  root,
3552
- remote
3797
+ remote,
3798
+ git: draft.docs.git
3553
3799
  }
3554
3800
  }, configPath);
3555
3801
  return inspectOnboarding(configPath);
@@ -3631,9 +3877,9 @@ async function fetchManifest(url) {
3631
3877
  const payload = await response.json();
3632
3878
  if ('string' != typeof payload.version || 0 === payload.version.length) return null;
3633
3879
  return {
3634
- current: "0.2.0",
3880
+ current: "0.3.0",
3635
3881
  latest: payload.version,
3636
- hasUpdate: isNewer(payload.version, "0.2.0"),
3882
+ hasUpdate: isNewer(payload.version, "0.3.0"),
3637
3883
  downloadUrl: 'string' == typeof payload.downloadUrl ? payload.downloadUrl : null,
3638
3884
  source: 'manifest',
3639
3885
  checkedAt: new Date().toISOString(),
@@ -3645,7 +3891,7 @@ async function fetchManifest(url) {
3645
3891
  }
3646
3892
  async function fetchNpm() {
3647
3893
  const base = {
3648
- current: "0.2.0",
3894
+ current: "0.3.0",
3649
3895
  latest: null,
3650
3896
  hasUpdate: false,
3651
3897
  downloadUrl: null,
@@ -3672,7 +3918,7 @@ async function fetchNpm() {
3672
3918
  return {
3673
3919
  ...base,
3674
3920
  latest,
3675
- hasUpdate: isNewer(latest, "0.2.0"),
3921
+ hasUpdate: isNewer(latest, "0.3.0"),
3676
3922
  downloadUrl: 'https://www.npmjs.com/package/ylcwf'
3677
3923
  };
3678
3924
  } catch (error) {
@@ -3915,7 +4161,11 @@ async function startServer(options) {
3915
4161
  iteration: pickString(body, 'iteration'),
3916
4162
  developer,
3917
4163
  taskId: pickString(body, 'taskId'),
3918
- action: action
4164
+ action: action,
4165
+ policy: loaded.config.docs.git?.ui ?? {
4166
+ commit: true,
4167
+ push: false
4168
+ }
3919
4169
  }));
3920
4170
  return;
3921
4171
  }
@@ -3955,7 +4205,11 @@ async function startServer(options) {
3955
4205
  iteration: pickString(body, 'iteration'),
3956
4206
  developer,
3957
4207
  taskIds,
3958
- action: action
4208
+ action: action,
4209
+ policy: loaded.config.docs.git?.ui ?? {
4210
+ commit: true,
4211
+ push: false
4212
+ }
3959
4213
  }));
3960
4214
  return;
3961
4215
  }
@@ -4140,7 +4394,7 @@ function registerReset(program) {
4140
4394
  }
4141
4395
  function buildProgram() {
4142
4396
  const program = new Command();
4143
- program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与终端仓库映射').version("0.2.0", '-v, --version', '显示版本号').showHelpAfterError();
4397
+ program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与终端仓库映射').version("0.3.0", '-v, --version', '显示版本号').showHelpAfterError();
4144
4398
  registerInit(program);
4145
4399
  registerShow(program);
4146
4400
  registerGet(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ylcwf",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "研发工作流配置 CLI:文档仓库、开发者标识、默认角色与 PRD 终端 → 本地仓库映射",
5
5
  "type": "module",
6
6
  "bin": {