@dommaker/harness 4.0.1 → 5.0.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.
Files changed (117) hide show
  1. package/README.md +7 -8
  2. package/dist/bootstrap/bootstrap.d.ts +15 -0
  3. package/dist/bootstrap/bootstrap.js +18 -1
  4. package/dist/bootstrap/index.d.ts +2 -2
  5. package/dist/bootstrap/index.js +3 -2
  6. package/dist/cli/commands/acceptance.d.ts +8 -0
  7. package/dist/cli/commands/acceptance.js +45 -24
  8. package/dist/cli/commands/check.d.ts +2 -0
  9. package/dist/cli/commands/check.js +36 -5
  10. package/dist/cli/commands/command.js +1 -1
  11. package/dist/cli/commands/definitions.js +4 -1
  12. package/dist/cli/commands/release.d.ts +11 -3
  13. package/dist/cli/commands/release.js +159 -52
  14. package/dist/cli/commands/report.d.ts +2 -0
  15. package/dist/cli/commands/report.js +54 -6
  16. package/dist/cli/commands/security.d.ts +3 -3
  17. package/dist/cli/commands/security.js +3 -2
  18. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +3 -40
  19. package/dist/cli/commands/sync-docs/capabilities-syncer.js +5 -159
  20. package/dist/cli/commands/sync-docs/compact.js +2 -2
  21. package/dist/cli/commands/sync-docs/context-syncer.d.ts +4 -36
  22. package/dist/cli/commands/sync-docs/context-syncer.js +4 -221
  23. package/dist/cli/commands/sync-docs/index.d.ts +8 -8
  24. package/dist/cli/commands/sync-docs/index.js +8 -8
  25. package/dist/cli/commands/sync-docs/main-flow.d.ts +5 -4
  26. package/dist/cli/commands/sync-docs/main-flow.js +6 -5
  27. package/dist/cli/commands/sync-docs/sync-output.d.ts +1 -1
  28. package/dist/cli/commands/sync-docs/sync-output.js +4 -0
  29. package/dist/cli/commands/sync-docs/sync-writes.d.ts +1 -1
  30. package/dist/cli/commands/validate.d.ts +2 -0
  31. package/dist/cli/commands/validate.js +40 -1
  32. package/dist/core/command-execution-policy.d.ts +59 -0
  33. package/dist/core/command-execution-policy.js +167 -0
  34. package/dist/core/config-files.d.ts +8 -0
  35. package/dist/core/config-files.js +62 -0
  36. package/dist/core/constraints/capabilities-parser.d.ts +2 -1
  37. package/dist/core/constraints/capabilities-parser.js +2 -1
  38. package/dist/core/constraints/checker.d.ts +18 -6
  39. package/dist/core/constraints/checker.js +21 -11
  40. package/dist/core/constraints/checkers/no-hardcoded-credentials.js +14 -15
  41. package/dist/core/constraints/checkers/no-test-simplification.js +8 -6
  42. package/dist/core/constraints/checkers/templated/exec.d.ts +4 -0
  43. package/dist/core/constraints/checkers/templated/exec.js +11 -48
  44. package/dist/core/constraints/checkers/templated/file-exists.js +7 -4
  45. package/dist/core/constraints/checkers/templated/regex-scan.js +11 -15
  46. package/dist/core/constraints/checkers/types.d.ts +13 -2
  47. package/dist/core/constraints/checkers/types.js +5 -2
  48. package/dist/core/constraints/construction-sites.d.ts +1 -1
  49. package/dist/core/constraints/construction-sites.js +1 -1
  50. package/dist/core/constraints/definitions.d.ts +2 -2
  51. package/dist/core/constraints/definitions.js +2 -2
  52. package/dist/core/constraints/injection-writer.d.ts +1 -1
  53. package/dist/core/constraints/injection-writer.js +1 -1
  54. package/dist/core/constraints/project-snapshot.d.ts +43 -0
  55. package/dist/core/constraints/project-snapshot.js +103 -0
  56. package/dist/core/constraints/run-env.d.ts +35 -0
  57. package/dist/core/constraints/run-env.js +36 -0
  58. package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.d.ts +2 -0
  59. package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.js +5 -3
  60. package/dist/core/docs-sync/capabilities-table.d.ts +46 -0
  61. package/dist/core/docs-sync/capabilities-table.js +200 -0
  62. package/dist/core/docs-sync/context-collector.d.ts +40 -0
  63. package/dist/core/docs-sync/context-collector.js +227 -0
  64. package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.d.ts +5 -1
  65. package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.js +10 -6
  66. package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.d.ts +15 -9
  67. package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.js +26 -29
  68. package/dist/core/effective-constraints.d.ts +1 -1
  69. package/dist/core/effective-constraints.js +1 -1
  70. package/dist/core/validators/check-handlers/command.js +22 -0
  71. package/dist/core/validators/check-handlers/output.js +26 -3
  72. package/dist/core/validators/checkpoint.d.ts +4 -0
  73. package/dist/core/validators/checkpoint.js +10 -2
  74. package/dist/gates/acceptance.d.ts +8 -4
  75. package/dist/gates/acceptance.js +76 -14
  76. package/dist/gates/command.d.ts +3 -4
  77. package/dist/gates/command.js +2 -3
  78. package/dist/gates/contract.d.ts +3 -4
  79. package/dist/gates/contract.js +0 -1
  80. package/dist/gates/definitions.d.ts +2 -4
  81. package/dist/gates/definitions.js +2 -8
  82. package/dist/gates/performance.d.ts +10 -4
  83. package/dist/gates/performance.js +49 -5
  84. package/dist/gates/review.d.ts +3 -4
  85. package/dist/gates/review.js +0 -1
  86. package/dist/gates/security.d.ts +3 -4
  87. package/dist/gates/security.js +26 -19
  88. package/dist/gates/types.d.ts +46 -19
  89. package/dist/index.d.ts +5 -4
  90. package/dist/index.js +9 -6
  91. package/dist/knowledge/index.d.ts +1 -1
  92. package/dist/knowledge/index.js +1 -2
  93. package/dist/knowledge/ingest.d.ts +32 -17
  94. package/dist/knowledge/ingest.js +188 -90
  95. package/dist/knowledge/lifecycle.d.ts +15 -0
  96. package/dist/knowledge/lifecycle.js +62 -0
  97. package/dist/knowledge/query.d.ts +11 -1
  98. package/dist/knowledge/query.js +61 -9
  99. package/dist/knowledge/store.d.ts +56 -3
  100. package/dist/knowledge/store.js +108 -30
  101. package/dist/monitoring/index.d.ts +2 -1
  102. package/dist/monitoring/index.js +3 -1
  103. package/dist/monitoring/traces.d.ts +12 -0
  104. package/dist/monitoring/traces.js +26 -4
  105. package/dist/types/checkpoint.d.ts +28 -1
  106. package/dist/types/command-execution-policy.d.ts +73 -0
  107. package/dist/types/command-execution-policy.js +16 -0
  108. package/dist/types/constraint.d.ts +0 -12
  109. package/dist/utils/exec.d.ts +7 -1
  110. package/dist/utils/exec.js +7 -1
  111. package/package.json +1 -1
  112. package/dist/core/constraints/check-cache.d.ts +0 -43
  113. package/dist/core/constraints/check-cache.js +0 -77
  114. package/dist/core/constraints/checkers/templated/glob.d.ts +0 -8
  115. package/dist/core/constraints/checkers/templated/glob.js +0 -14
  116. /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.d.ts +0 -0
  117. /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.js +0 -0
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  /**
3
- * CAPABILITIES.md 文件表格同步器(工单 22)
3
+ * CAPABILITIES.md 写侧(工单 22 / harness#171;P2.8 拆段:文本判定正本下沉
4
+ * core/docs-sync/capabilities-table.ts,本文件只剩落盘维护)
4
5
  *
5
6
  * 只负责文件表格格式:模块/文件/说明三列表格,增删行维护。
6
7
  * 能力清单格式(计数行)的解析与计数已收敛到 core/constraints/capabilities-parser(H2 O10-R3)。
@@ -39,35 +40,12 @@ var __importStar = (this && this.__importStar) || (function () {
39
40
  };
40
41
  })();
41
42
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.parseCapabilitiesFiles = parseCapabilitiesFiles;
43
43
  exports.updateCapabilitiesFile = updateCapabilitiesFile;
44
- exports.normalizeCapabilitiesTableLayout = normalizeCapabilitiesTableLayout;
45
- exports.compactCapabilitiesContent = compactCapabilitiesContent;
46
44
  const fs = __importStar(require("fs/promises"));
47
45
  const fs_1 = require("fs");
48
46
  const path = __importStar(require("path"));
49
- const capabilities_parser_1 = require("../../../core/constraints/capabilities-parser");
50
47
  const text_1 = require("../../../utils/text");
51
- /**
52
- * 解析 CAPABILITIES.md 中的文件路径
53
- *
54
- * 提取所有表格行中提到的 .ts/.tsx/.js/.jsx 文件名(不含路径前缀)
55
- * 用于模糊匹配:只要文档中提到了该文件名就算已记录
56
- */
57
- async function parseCapabilitiesFiles(capabilitiesPath) {
58
- // 工单 19-B:解析收敛到 core/constraints/capabilities-parser;
59
- // 此处保持原语义——文件条目取 basename,目录条目(以 / 结尾)原样保留
60
- const entries = (0, capabilities_parser_1.readCapabilitiesEntries)(capabilitiesPath, { includeDirs: true });
61
- const files = [];
62
- for (const entry of entries) {
63
- // split('/') 恒产出 ≥1 段,末段索引恒有值
64
- const segments = entry.split('/');
65
- const value = entry.endsWith('/') ? entry : segments[segments.length - 1];
66
- if (!files.includes(value))
67
- files.push(value);
68
- }
69
- return files;
70
- }
48
+ const capabilities_table_1 = require("../../../core/docs-sync/capabilities-table");
71
49
  /**
72
50
  * 更新 CAPABILITIES.md 文件
73
51
  *
@@ -87,7 +65,7 @@ async function updateCapabilitiesFile(capabilitiesPath, currentModules, existing
87
65
  if (existingFiles.length > 0) {
88
66
  // 移除已删除文件的行(整行连行尾一起删——只清行内容会留一个空行,
89
67
  // CommonMark 据此把一张表切成若干小表,harness#171)。
90
- // 这里**不**豁免围栏代码块,与下方排版收拢刻意不同口径:登记条目由
68
+ // 这里**不**豁免围栏代码块,与排版收拢刻意不同口径:登记条目由
91
69
  // capabilities-parser 全文扫描得出(ADR-0009),围栏内的行同样算登记项;
92
70
  // 只让删除认围栏而条目不认,块内示例行会一直被解析成幽灵条目,`--check`
93
71
  // 从此每轮都报同一个已删文件且永远修不掉。豁免要生效得连登记面一起改。
@@ -122,7 +100,7 @@ async function updateCapabilitiesFile(capabilitiesPath, currentModules, existing
122
100
  content += '\n\n' + (mode === 'module' ? generateDirTable(currentModules) : generateModuleTable(currentModules));
123
101
  }
124
102
  // 表格排版收拢放在增删之后:有新行的表不会被误判为空表(#171)
125
- content = normalizeCapabilitiesTableLayout(content).content;
103
+ content = (0, capabilities_table_1.normalizeCapabilitiesTableLayout)(content).content;
126
104
  // 多余空行的清理收在收拢之后一处:收拢本身会新产出连续空行
127
105
  // (收掉一张夹在两段散文之间的空表就留下 `\n\n\n`,#171)
128
106
  content = content.replace(/\n{3,}/g, '\n\n');
@@ -131,97 +109,6 @@ async function updateCapabilitiesFile(capabilitiesPath, currentModules, existing
131
109
  content = content.replace(/最后更新[::].*/, `最后更新: ${now}`);
132
110
  await fs.writeFile(capabilitiesPath, content, 'utf-8');
133
111
  }
134
- /** 表格行:以 `|` 起始(表头、分隔行、数据行都算) */
135
- const TABLE_ROW_REGEX = /^\s*\|/;
136
- /** 表格分隔行(|------|------|) */
137
- const TABLE_SEPARATOR_REGEX = /^\s*\|[\s:|-]+\|\s*$/;
138
- /** 围栏代码块的起止行(``` / ~~~,允许缩进与信息串) */
139
- const FENCE_LINE_REGEX = /^\s*(?:```|~~~)/;
140
- /**
141
- * 按行切开并标出围栏代码块(``` / ~~~)内的行
142
- *
143
- * 只服务排版收拢:CAPABILITIES.md 是手写文档,块内长得像表格的示例行不是排版脏行,
144
- * 收它就是删用户正文(harness#171)。登记条目面不在此列——见 `updateCapabilitiesFile`
145
- * 里「幽灵行删除不豁免围栏」的取舍注释。
146
- */
147
- function parseLayoutLines(content) {
148
- const parsed = [];
149
- let inFence = false;
150
- for (const text of content.split('\n')) {
151
- if (FENCE_LINE_REGEX.test(text)) {
152
- parsed.push({ text, fenced: true });
153
- inFence = !inFence;
154
- continue;
155
- }
156
- parsed.push({ text, fenced: inFence });
157
- }
158
- return parsed;
159
- }
160
- const isTableRow = (line) => line !== undefined && !line.fenced && TABLE_ROW_REGEX.test(line.text);
161
- const isTableSeparator = (line) => line !== undefined && !line.fenced && TABLE_SEPARATOR_REGEX.test(line.text);
162
- /** 走一遍两条收拢规则(不迭代) */
163
- function collapseTableLayoutOnce(content) {
164
- const parsed = parseLayoutLines(content);
165
- // ① 收拢表格内空行:一段连续空行,两侧最近非空行都是表格行 → 整段丢弃
166
- const kept = [];
167
- let blankLines = 0;
168
- for (let i = 0; i < parsed.length;) {
169
- if (parsed[i].text.trim() !== '') {
170
- kept.push(parsed[i]);
171
- i++;
172
- continue;
173
- }
174
- let end = i;
175
- while (end < parsed.length && parsed[end].text.trim() === '')
176
- end++;
177
- if (isTableRow(kept[kept.length - 1]) && isTableRow(parsed[end])) {
178
- blankLines += end - i;
179
- }
180
- else {
181
- kept.push(...parsed.slice(i, end));
182
- }
183
- i = end;
184
- }
185
- // ② 收掉空表:表头 + 分隔行后面没有数据行
186
- const out = [];
187
- let emptyTables = 0;
188
- for (let i = 0; i < kept.length; i++) {
189
- if (isTableRow(kept[i]) && isTableSeparator(kept[i + 1]) && !isTableRow(kept[i + 2])) {
190
- emptyTables++;
191
- i++;
192
- continue;
193
- }
194
- out.push(kept[i].text);
195
- }
196
- return { content: out.join('\n'), blankLines, emptyTables };
197
- }
198
- /**
199
- * 收拢 CAPABILITIES.md 的表格排版(harness#171)
200
- *
201
- * 两条规则:① 删掉夹在两个表格行之间的空行(CommonMark 会在此切断表格);
202
- * ② 收掉没有数据行的表头+分隔行。表格外的空行(段落分隔)不动;围栏代码块内的行整体豁免。
203
- *
204
- * 规则互相制造对方的触发点(①把两张空表之间的那个空行吃掉后,②一轮只收得掉后一张),
205
- * 所以跑到不动点:**一次 `sync-docs` 必须把 `--check` 报出来的东西全清掉**,
206
- * 否则下游 CI 修完还是红的。计数 = 各轮合计(每轮只删当轮存在的行,不会重计)。
207
- *
208
- * 幂等,且 `--check` 与写模式共用此正本——判定面就是「返回内容与入参是否不同」,
209
- * 因此不存在「check 报了 fix 修不掉」的不收敛(ADR-0009 口径)。
210
- */
211
- function normalizeCapabilitiesTableLayout(content) {
212
- let current = content;
213
- let blankLines = 0;
214
- let emptyTables = 0;
215
- for (;;) {
216
- const pass = collapseTableLayoutOnce(current);
217
- if (pass.blankLines === 0 && pass.emptyTables === 0) {
218
- return { content: current, blankLines, emptyTables };
219
- }
220
- blankLines += pass.blankLines;
221
- emptyTables += pass.emptyTables;
222
- current = pass.content;
223
- }
224
- }
225
112
  /**
226
113
  * 生成 CAPABILITIES.md 内容
227
114
  */
@@ -267,44 +154,3 @@ function generateDirTable(modules) {
267
154
  }).join('\n');
268
155
  return `| 模块 | 文件 | 说明 |\n|------|------|------|\n${rows}`;
269
156
  }
270
- /**
271
- * 将 CAPABILITIES.md 文件表格折叠为目录条目(--compact 一次性迁移)
272
- *
273
- * 按文件条目(第二列)的 dirname 分组:同组 ≥2 个文件条目折叠为一行目录条目
274
- * (替换组内第一行、删除其余行,说明取组内第一行,为空则用目录名);
275
- * 单独成组的文件行、表头、非表格文本、PRESERVE 块原样保留。
276
- * 已折叠的目录条目行不再匹配文件条目,故幂等。
277
- */
278
- function compactCapabilitiesContent(content) {
279
- const lines = content.split('\n');
280
- const fileEntryRegex = /\.(?:ts|tsx|js|jsx)$/;
281
- const rowRegex = /^\|[^|]+\|[^|]+\|[^|]+\|\s*$/;
282
- // 收集文件条目行,按 dirname 分组(无目录前缀的条目不参与折叠)
283
- const groups = new Map();
284
- for (let i = 0; i < lines.length; i++) {
285
- if (!rowRegex.test(lines[i]))
286
- continue;
287
- const cells = lines[i].split('|').map(c => c.trim());
288
- const file = cells[2] ?? '';
289
- if (!fileEntryRegex.test(file))
290
- continue;
291
- const dir = path.posix.dirname(file);
292
- if (dir === '.')
293
- continue;
294
- const group = groups.get(dir) ?? [];
295
- group.push({ lineIndex: i, file, desc: cells[3] ?? '' });
296
- groups.set(dir, group);
297
- }
298
- const deleteLines = new Set();
299
- for (const [dir, rows] of groups) {
300
- if (rows.length < 2)
301
- continue;
302
- const name = path.posix.basename(dir);
303
- const desc = rows[0].desc || name;
304
- lines[rows[0].lineIndex] = `| ${name} | ${dir}/ | ${desc} |`;
305
- for (const row of rows.slice(1)) {
306
- deleteLines.add(row.lineIndex);
307
- }
308
- }
309
- return lines.filter((_, i) => !deleteLines.has(i)).join('\n');
310
- }
@@ -47,7 +47,7 @@ const chalk_1 = __importDefault(require("chalk"));
47
47
  const fs_1 = require("fs");
48
48
  const fs = __importStar(require("fs/promises"));
49
49
  const path = __importStar(require("path"));
50
- const capabilities_syncer_1 = require("./capabilities-syncer");
50
+ const capabilities_table_1 = require("../../../core/docs-sync/capabilities-table");
51
51
  const command_contract_1 = require("../../command-contract");
52
52
  async function runCompactSync(projectPath, isJson, drift, io) {
53
53
  const capsPath = path.join(projectPath, 'CAPABILITIES.md');
@@ -58,7 +58,7 @@ async function runCompactSync(projectPath, isJson, drift, io) {
58
58
  return drift('CAPABILITIES.md 不存在,无法折叠');
59
59
  }
60
60
  const content = await fs.readFile(capsPath, 'utf-8');
61
- const compacted = (0, capabilities_syncer_1.compactCapabilitiesContent)(content);
61
+ const compacted = (0, capabilities_table_1.compactCapabilitiesContent)(content);
62
62
  if (compacted !== content) {
63
63
  await fs.writeFile(capsPath, compacted, 'utf-8');
64
64
  if (!isJson)
@@ -1,7 +1,8 @@
1
1
  /**
2
- * CONTEXT.md 同步器(工单 22):缺失模板生成 + 既有文件发现 + 过时判定
3
- * + 目录导出面采集(harness#142,供 context-reconcile 的内容判定喂数)
4
- * + 构造点计数采集(harness#202,供 construction-sites 的标记判定喂数)
2
+ * CONTEXT.md 写侧落点(工单 22 / harness#150):缺失模板生成走 scaffold 正本站点。
3
+ *
4
+ * P2.8 采集侧(发现/mtime/导出面/构造点计数)已下沉 core/docs-sync/context-collector.ts,
5
+ * 本文件只剩写入。判定本体在 core/constraints/ 的纯函数。
5
6
  */
6
7
  import type { CommandIO } from '../../command-contract';
7
8
  import { type ScaffoldFileSystem, type ScaffoldOutcome } from '../scaffold';
@@ -13,36 +14,3 @@ import { type ScaffoldFileSystem, type ScaffoldOutcome } from '../scaffold';
13
14
  * 说明 sync-docs 的缺失判定与 scaffold 的在场判定口径不一致(不静默兜,交由调用方感知)。
14
15
  */
15
16
  export declare function createContextMd(projectPath: string, dir: string, io: CommandIO, scaffoldFs?: ScaffoldFileSystem): Promise<ScaffoldOutcome>;
16
- /**
17
- * 自动发现已有 CONTEXT.md 文件的目录(相对于 projectPath)
18
- */
19
- export declare function findExistingContextFiles(projectPath: string, srcDirs: string[]): Promise<string[]>;
20
- /**
21
- * 获取目录下最新 .ts 文件的修改时间
22
- * 返回 null 如果目录不存在或没有 .ts 文件
23
- */
24
- export declare function getLatestTsMtime(dirPath: string): Promise<number | null>;
25
- /** 目录导出面采集结果(harness#142) */
26
- export interface ContextExportSurface {
27
- /** 目录内所有 .ts 导出的符号名(值 + 类型,含 barrel 再导出) */
28
- surface: string[];
29
- /** `index.ts` barrel 再导出的**值**符号(类型-only 已剔除);无 index.ts → 空 */
30
- barrelExports: string[];
31
- }
32
- /**
33
- * 采集目录导出面(内容判定的代码侧):目录内 .ts(排 `__tests__/`、`.d.ts`)的导出符号全集,
34
- * 以及 barrel(`index.ts`)再导出的值符号清单。fs IO 全在此,判定不在(ADR-0025)。
35
- */
36
- export declare function collectContextExportSurface(dirPath: string, projectPath: string): Promise<ContextExportSurface>;
37
- /**
38
- * 构造点计数器(harness#202 / ADR-0039):(类名, 是否计测试目录) → 全仓
39
- * `new X(` 直构造出现次数。fs 采集全在此,计数口径正本是 core 侧
40
- * `tallyConstructionSites`(逐文件调用后累加)。
41
- *
42
- * 排除口径沿用 DEFAULT_SKIP_DIRS(node_modules/__tests__/dist);
43
- * includeTests 时把 `__tests__` 从跳过名单放出。两种口径各自懒采集一次
44
- * (全仓走一遍不便宜),结果按口径 memo——一次 sync-docs 运行里同口径
45
- * 的多个标记共用同一份计数。
46
- */
47
- export type ConstructionSiteCounter = (className: string, includeTests: boolean) => number;
48
- export declare function createConstructionSiteCounter(projectPath: string): ConstructionSiteCounter;
@@ -1,54 +1,12 @@
1
1
  "use strict";
2
2
  /**
3
- * CONTEXT.md 同步器(工单 22):缺失模板生成 + 既有文件发现 + 过时判定
4
- * + 目录导出面采集(harness#142,供 context-reconcile 的内容判定喂数)
5
- * + 构造点计数采集(harness#202,供 construction-sites 的标记判定喂数)
3
+ * CONTEXT.md 写侧落点(工单 22 / harness#150):缺失模板生成走 scaffold 正本站点。
4
+ *
5
+ * P2.8 采集侧(发现/mtime/导出面/构造点计数)已下沉 core/docs-sync/context-collector.ts,
6
+ * 本文件只剩写入。判定本体在 core/constraints/ 的纯函数。
6
7
  */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
8
  Object.defineProperty(exports, "__esModule", { value: true });
41
9
  exports.createContextMd = createContextMd;
42
- exports.findExistingContextFiles = findExistingContextFiles;
43
- exports.getLatestTsMtime = getLatestTsMtime;
44
- exports.collectContextExportSurface = collectContextExportSurface;
45
- exports.createConstructionSiteCounter = createConstructionSiteCounter;
46
- const fs = __importStar(require("fs/promises"));
47
- const fs_1 = require("fs");
48
- const path = __importStar(require("path"));
49
- const file_walk_1 = require("../../../utils/file-walk");
50
- const context_reconcile_1 = require("../../../core/constraints/context-reconcile");
51
- const construction_sites_1 = require("../../../core/constraints/construction-sites");
52
10
  const scaffold_1 = require("../scaffold");
53
11
  /**
54
12
  * 创建 CONTEXT.md 模板:走 scaffold 正本站点(contextDocFile + runPlan),
@@ -61,178 +19,3 @@ async function createContextMd(projectPath, dir, io, scaffoldFs = scaffold_1.nod
61
19
  const [outcome] = await (0, scaffold_1.runPlan)([(0, scaffold_1.contextDocFile)(projectPath, dir)], io, scaffoldFs);
62
20
  return outcome;
63
21
  }
64
- /**
65
- * 自动发现已有 CONTEXT.md 文件的目录(相对于 projectPath)
66
- */
67
- async function findExistingContextFiles(projectPath, srcDirs) {
68
- const dirs = [];
69
- async function scan(dir) {
70
- // fail-fast:目录不可读直接抛,不静默漏掉整棵子树的 CONTEXT.md
71
- const entries = await fs.readdir(dir);
72
- for (const entry of entries) {
73
- if (file_walk_1.DEFAULT_SKIP_DIRS.includes(entry))
74
- continue;
75
- const entryPath = path.join(dir, entry);
76
- const stat = await fs.stat(entryPath);
77
- if (stat.isDirectory()) {
78
- // 检查该目录是否有 CONTEXT.md
79
- if ((0, fs_1.existsSync)(path.join(entryPath, 'CONTEXT.md'))) {
80
- dirs.push(path.relative(projectPath, entryPath));
81
- }
82
- await scan(entryPath);
83
- }
84
- }
85
- }
86
- for (const srcDir of srcDirs) {
87
- // 源码根不在场 = 无可发现(缺失判定归调用方 4a 的 contextMissing),不扫
88
- const root = path.join(projectPath, srcDir);
89
- if ((0, fs_1.existsSync)(root))
90
- await scan(root);
91
- }
92
- return dirs;
93
- }
94
- /**
95
- * 获取目录下最新 .ts 文件的修改时间
96
- * 返回 null 如果目录不存在或没有 .ts 文件
97
- */
98
- async function getLatestTsMtime(dirPath) {
99
- let latest = null;
100
- async function scan(dir) {
101
- // fail-fast:目录不可读直接抛(理由同 findExistingContextFiles)
102
- const entries = await fs.readdir(dir);
103
- for (const entry of entries) {
104
- if (file_walk_1.DEFAULT_SKIP_DIRS.includes(entry))
105
- continue;
106
- const entryPath = path.join(dir, entry);
107
- const stat = await fs.stat(entryPath);
108
- if (stat.isDirectory()) {
109
- await scan(entryPath);
110
- }
111
- else if (entry.endsWith('.ts') && !entry.endsWith('.d.ts')) {
112
- if (latest === null || stat.mtimeMs > latest) {
113
- latest = stat.mtimeMs;
114
- }
115
- }
116
- }
117
- }
118
- // 目录不存在 → null(函数契约);存在但扫不出 → 抛(fail-fast)
119
- if (!(0, fs_1.existsSync)(dirPath))
120
- return null;
121
- await scan(dirPath);
122
- return latest;
123
- }
124
- /**
125
- * 把相对 spec 解析为仓内可读的 .ts 文件(`./x` → `x.ts` 或 `x/index.ts`);
126
- * 非相对 spec、越出项目根、命中 `.d.ts`/`node_modules`/跳过目录一律 null(不并入导出面)。
127
- */
128
- function resolveTsTarget(fromFile, spec, projectPath) {
129
- if (!spec.startsWith('.'))
130
- return null;
131
- const base = path.resolve(path.dirname(fromFile), spec);
132
- for (const candidate of [`${base}.ts`, path.join(base, 'index.ts')]) {
133
- if (candidate.endsWith('.d.ts'))
134
- continue;
135
- const rel = path.relative(projectPath, candidate);
136
- if (!rel || rel.startsWith('..') || rel.includes('node_modules'))
137
- continue;
138
- if (rel.split(path.sep).some((segment) => file_walk_1.DEFAULT_SKIP_DIRS.includes(segment)))
139
- continue;
140
- if ((0, fs_1.existsSync)(candidate))
141
- return candidate;
142
- }
143
- return null;
144
- }
145
- /**
146
- * 单文件导出表(含再导出与 `export *` 展开),memo 化 + 在途集合破环。
147
- *
148
- * 递归只沿 `export *` 与具名再导出的来源走,读到的都是仓内 .ts;
149
- * 环上(A `export * from './b'`、B `export * from './a'`)在途文件交空表,
150
- * 与 tsc 的星号环语义一致(不因此丢名字——真实名字总有非环上的一条声明路径)。
151
- */
152
- async function collectFileExports(file, projectPath, cache, inProgress) {
153
- const cached = cache.get(file);
154
- if (cached)
155
- return cached;
156
- if (inProgress.has(file))
157
- return new Map();
158
- inProgress.add(file);
159
- const out = new Map();
160
- // fail-fast:文件来自导出面扫描/相对导入解析,读失败 = 真 IO 故障。
161
- // 曾经 catch 成空表并写进 cache——把「读不了」伪装成「没有导出」,幽灵判定就此失真
162
- const source = await fs.readFile(file, 'utf-8');
163
- const { symbols, starFrom } = (0, context_reconcile_1.parseExportStatements)(source);
164
- for (const symbol of symbols) {
165
- let typeOnly = symbol.typeOnly;
166
- if (symbol.from) {
167
- const origin = resolveTsTarget(file, symbol.from, projectPath);
168
- // 环上(origin 在途)时交回的是空表,那是「不知道」不是「没有」→ 不做虚判
169
- if (origin && !inProgress.has(origin)) {
170
- const originExports = await collectFileExports(origin, projectPath, cache, inProgress);
171
- // 正本没有这个本名 → 这条再导出是虚的(改名未跟上的 barrel),不计入导出面,
172
- // 否则文档里的幽灵会被 barrel 自己洗白(harness#142 反证撞出的口径漏洞)
173
- if (!originExports.has(symbol.localName))
174
- continue;
175
- if (!typeOnly && originExports.get(symbol.localName) === true)
176
- typeOnly = true;
177
- }
178
- }
179
- out.set(symbol.name, typeOnly);
180
- }
181
- for (const spec of starFrom) {
182
- const target = resolveTsTarget(file, spec, projectPath);
183
- if (!target)
184
- continue;
185
- const targetExports = await collectFileExports(target, projectPath, cache, inProgress);
186
- for (const [name, typeOnly] of targetExports)
187
- if (!out.has(name))
188
- out.set(name, typeOnly);
189
- }
190
- inProgress.delete(file);
191
- cache.set(file, out);
192
- return out;
193
- }
194
- /**
195
- * 采集目录导出面(内容判定的代码侧):目录内 .ts(排 `__tests__/`、`.d.ts`)的导出符号全集,
196
- * 以及 barrel(`index.ts`)再导出的值符号清单。fs IO 全在此,判定不在(ADR-0025)。
197
- */
198
- async function collectContextExportSurface(dirPath, projectPath) {
199
- const files = (0, file_walk_1.findTsSourceFiles)(dirPath);
200
- const cache = new Map();
201
- const surface = new Set();
202
- for (const file of files) {
203
- const fileExports = await collectFileExports(file, projectPath, cache, new Set());
204
- for (const name of fileExports.keys())
205
- surface.add(name);
206
- }
207
- const barrelExports = [];
208
- const barrelFile = path.join(dirPath, 'index.ts');
209
- if (files.includes(barrelFile)) {
210
- const barrel = await collectFileExports(barrelFile, projectPath, cache, new Set());
211
- for (const [name, typeOnly] of barrel)
212
- if (!typeOnly)
213
- barrelExports.push(name);
214
- }
215
- return { surface: [...surface], barrelExports };
216
- }
217
- function createConstructionSiteCounter(projectPath) {
218
- const tallies = new Map();
219
- const tallyFor = (includeTests) => {
220
- let tally = tallies.get(includeTests);
221
- if (tally)
222
- return tally;
223
- tally = new Map();
224
- const skipDirs = includeTests
225
- ? file_walk_1.DEFAULT_SKIP_DIRS.filter((d) => d !== '__tests__')
226
- : file_walk_1.DEFAULT_SKIP_DIRS;
227
- for (const file of (0, file_walk_1.findTsSourceFiles)(projectPath, { skipDirs })) {
228
- // fail-fast:文件来自 walk 结果,读失败直接抛,不静默漏计构造点
229
- const source = (0, fs_1.readFileSync)(file, 'utf-8');
230
- for (const [name, count] of (0, construction_sites_1.tallyConstructionSites)(source)) {
231
- tally.set(name, (tally.get(name) ?? 0) + count);
232
- }
233
- }
234
- tallies.set(includeTests, tally);
235
- return tally;
236
- };
237
- return (className, includeTests) => tallyFor(includeTests).get(className) ?? 0;
238
- }
@@ -4,16 +4,16 @@
4
4
  * 自动同步项目文档:CAPABILITIES.md、CONTEXT.md 检查、CHANGELOG 辅助
5
5
  * --check 模式输出结构化信息,供 LLM 或 CI 消费
6
6
  *
7
- * 实现拆分(Phase 3:原 index.ts 611 行单函数按三互斥形态拆开):
7
+ * 实现拆分(Phase 3:原 index.ts 611 行单函数按三互斥形态拆开;P2.8 起
8
+ * 采集与判定下沉 core/docs-sync/,本目录只剩入口/编排/输出/写侧/gate/compact):
8
9
  * - index.ts(本文件) 入口装配:--gate 前置校验 → --compact 分派 → 主流程
9
- * - main-flow.ts 主流程(扫描/判定/json 与人读报告/写入自愈)+ SyncDocsOptions + 计数源装配
10
+ * - main-flow.ts 主流程编排(采集/判定调 core/docs-sync/sync-state)+ 计数源装配
11
+ * - sync-output.ts JSON/人读报告出口(含「未找到 srcDir」提示打印)
12
+ * - sync-writes.ts 写入自愈编排(CAPABILITIES/CONTEXT/AGENTS 落盘)
13
+ * - capabilities-syncer.ts CAPABILITIES.md 写侧(增删行/生成模板;解析与排版判定正本在 core/docs-sync/capabilities-table)
14
+ * - context-syncer.ts CONTEXT.md 写侧落点(createContextMd 走 scaffold 正本;采集在 core/docs-sync/context-collector)
10
15
  * - gate.ts --gate 形态:前置用法校验 + vs HEAD 漂移判定尾部(harness#189)
11
- * - compact.ts --compact 形态:CAPABILITIES.md 文件表格折叠为目录条目
12
- * - project-reader.ts 项目信息读取(package.json/config.yml/源码扫描)
13
- * - capabilities-syncer.ts CAPABILITIES.md 文件表格格式的对比与维护(能力清单格式解析/计数走 core/constraints/capabilities-parser)
14
- * - context-syncer.ts CONTEXT.md 模板生成/发现/过时判定 + 目录导出面采集(harness#142)+ 构造点计数采集(harness#202)
15
- * - agents-syncer.ts AGENTS.md 生成
16
- * - preserve-block.ts PRESERVE 标记块提取与组合
16
+ * - compact.ts --compact 形态:CAPABILITIES.md 文件表格折叠为目录条目(折叠正本在 core/docs-sync/capabilities-table)
17
17
  * - head-gate.ts --gate 的 vs HEAD 漂移判定(harness#189)
18
18
  */
19
19
  import { type CommandIO, type CommandResult } from '../../command-contract';
@@ -5,16 +5,16 @@
5
5
  * 自动同步项目文档:CAPABILITIES.md、CONTEXT.md 检查、CHANGELOG 辅助
6
6
  * --check 模式输出结构化信息,供 LLM 或 CI 消费
7
7
  *
8
- * 实现拆分(Phase 3:原 index.ts 611 行单函数按三互斥形态拆开):
8
+ * 实现拆分(Phase 3:原 index.ts 611 行单函数按三互斥形态拆开;P2.8 起
9
+ * 采集与判定下沉 core/docs-sync/,本目录只剩入口/编排/输出/写侧/gate/compact):
9
10
  * - index.ts(本文件) 入口装配:--gate 前置校验 → --compact 分派 → 主流程
10
- * - main-flow.ts 主流程(扫描/判定/json 与人读报告/写入自愈)+ SyncDocsOptions + 计数源装配
11
+ * - main-flow.ts 主流程编排(采集/判定调 core/docs-sync/sync-state)+ 计数源装配
12
+ * - sync-output.ts JSON/人读报告出口(含「未找到 srcDir」提示打印)
13
+ * - sync-writes.ts 写入自愈编排(CAPABILITIES/CONTEXT/AGENTS 落盘)
14
+ * - capabilities-syncer.ts CAPABILITIES.md 写侧(增删行/生成模板;解析与排版判定正本在 core/docs-sync/capabilities-table)
15
+ * - context-syncer.ts CONTEXT.md 写侧落点(createContextMd 走 scaffold 正本;采集在 core/docs-sync/context-collector)
11
16
  * - gate.ts --gate 形态:前置用法校验 + vs HEAD 漂移判定尾部(harness#189)
12
- * - compact.ts --compact 形态:CAPABILITIES.md 文件表格折叠为目录条目
13
- * - project-reader.ts 项目信息读取(package.json/config.yml/源码扫描)
14
- * - capabilities-syncer.ts CAPABILITIES.md 文件表格格式的对比与维护(能力清单格式解析/计数走 core/constraints/capabilities-parser)
15
- * - context-syncer.ts CONTEXT.md 模板生成/发现/过时判定 + 目录导出面采集(harness#142)+ 构造点计数采集(harness#202)
16
- * - agents-syncer.ts AGENTS.md 生成
17
- * - preserve-block.ts PRESERVE 标记块提取与组合
17
+ * - compact.ts --compact 形态:CAPABILITIES.md 文件表格折叠为目录条目(折叠正本在 core/docs-sync/capabilities-table)
18
18
  * - head-gate.ts --gate 的 vs HEAD 漂移判定(harness#189)
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,13 +3,14 @@
3
3
  *
4
4
  * 默认形态:扫描源码模块 → CAPABILITIES.md 两种格式判定 → CONTEXT.md 缺失/漂移
5
5
  * → AGENTS.md(--agents)→ json/人读报告 → 写入模式自愈。本文件只剩编排:
6
- * 采集与判定住 sync-state.ts,JSON/人读出口住 sync-output.ts,写入自愈住
7
- * sync-writes.ts;--gate 的收尾判定经 `gate.ts` 的 runHeadGateVerdict;
6
+ * 采集与判定住 core/docs-sync/sync-state.ts(P2.8 收口),JSON/人读出口住
7
+ * sync-output.ts,写入自愈住 sync-writes.ts(含 capabilities-syncer/context-syncer
8
+ * 两个写侧残余);--gate 的收尾判定经 `gate.ts` 的 runHeadGateVerdict;
8
9
  * --compact 形态不经过本文件(见 compact.ts)。
9
10
  */
10
- import { type SyncDocsOptions } from './sync-state';
11
+ import { type SyncDocsOptions } from '../../../core/docs-sync/sync-state';
11
12
  import { type CommandIO, type CommandResult } from '../../command-contract';
12
- export type { SyncDocsOptions } from './sync-state';
13
+ export type { SyncDocsOptions } from '../../../core/docs-sync/sync-state';
13
14
  /**
14
15
  * 漂移译成 kind:--check 下判定失败;写入模式下漂移已被修掉 → 退出码面不变(历史行为)
15
16
  */
@@ -4,8 +4,9 @@
4
4
  *
5
5
  * 默认形态:扫描源码模块 → CAPABILITIES.md 两种格式判定 → CONTEXT.md 缺失/漂移
6
6
  * → AGENTS.md(--agents)→ json/人读报告 → 写入模式自愈。本文件只剩编排:
7
- * 采集与判定住 sync-state.ts,JSON/人读出口住 sync-output.ts,写入自愈住
8
- * sync-writes.ts;--gate 的收尾判定经 `gate.ts` 的 runHeadGateVerdict;
7
+ * 采集与判定住 core/docs-sync/sync-state.ts(P2.8 收口),JSON/人读出口住
8
+ * sync-output.ts,写入自愈住 sync-writes.ts(含 capabilities-syncer/context-syncer
9
+ * 两个写侧残余);--gate 的收尾判定经 `gate.ts` 的 runHeadGateVerdict;
9
10
  * --compact 形态不经过本文件(见 compact.ts)。
10
11
  */
11
12
  var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -17,7 +18,7 @@ exports.runMainSyncFlow = runMainSyncFlow;
17
18
  const chalk_1 = __importDefault(require("chalk"));
18
19
  const definitions_1 = require("../definitions");
19
20
  const definitions_2 = require("../../../gates/definitions");
20
- const sync_state_1 = require("./sync-state");
21
+ const sync_state_1 = require("../../../core/docs-sync/sync-state");
21
22
  const sync_output_1 = require("./sync-output");
22
23
  const sync_writes_1 = require("./sync-writes");
23
24
  const gate_1 = require("./gate");
@@ -54,8 +55,8 @@ async function runMainSyncFlow(options, io = command_contract_1.processIO) {
54
55
  (0, command_contract_1.log)(io, chalk_1.default.blue('📝 同步文档...'));
55
56
  }
56
57
  }
57
- // 采集 → 判定
58
- const state = await (0, sync_state_1.collectSyncState)(projectPath, options, io, CAPABILITY_DEFINITIONS);
58
+ // 采集 → 判定(住 core/docs-sync/sync-state.ts;本文件只剩编排与出口)
59
+ const state = await (0, sync_state_1.collectSyncState)(projectPath, options, CAPABILITY_DEFINITIONS);
59
60
  const verdict = (0, sync_state_1.judgeSyncState)(state, options);
60
61
  // JSON 出口:结构化输出供 LLM 消费
61
62
  if (isJson) {
@@ -2,7 +2,7 @@
2
2
  * sync-docs 主流程的报告出口(ADR-0040 Phase 3 自 main-flow.ts 拆段,纯移位):
3
3
  * --json 结构化输出(供 LLM 消费)与人读输出,两枚各吃采集态 + 判定旗标。
4
4
  */
5
- import type { SyncDocsOptions, SyncState, SyncVerdict } from './sync-state';
5
+ import type { SyncDocsOptions, SyncState, SyncVerdict } from '../../../core/docs-sync/sync-state';
6
6
  import { type CommandIO } from '../../command-contract';
7
7
  /**
8
8
  * JSON 出口:结构化输出供 LLM 消费;返回是否 hasIssues(退出码由调用方译)
@@ -168,6 +168,10 @@ function emitJsonReport(io, state, verdict, options) {
168
168
  * 人读出口:逐项问题打印(无判定、无返回)
169
169
  */
170
170
  function emitHumanReport(io, state, verdict) {
171
+ // 采集期跳过的源码根:提示属输出职责(原 collectSyncState 内联 log 移到此,stdout 序不变)
172
+ for (const srcDir of state.missingSrcDirs) {
173
+ (0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ 未找到 ${srcDir} 目录,跳过`));
174
+ }
171
175
  if (state.capsIsCapabilityListing && verdict.hasCapIssues) {
172
176
  (0, command_contract_1.log)(io, chalk_1.default.yellow(`\n📊 CAPABILITIES.md 计数不一致:`));
173
177
  state.capCountMismatches.forEach(m => (0, command_contract_1.log)(io, chalk_1.default.gray(` - ${m}`)));
@@ -3,7 +3,7 @@
3
3
  * CAPABILITIES.md(计数 / 条目与排版)→ CONTEXT.md 缺失创建 → AGENTS.md 写入。
4
4
  */
5
5
  import { type CapabilityDefinitionSource } from '../../../core/constraints/capabilities-parser';
6
- import type { SyncState, SyncVerdict } from './sync-state';
6
+ import type { SyncState, SyncVerdict } from '../../../core/docs-sync/sync-state';
7
7
  import { type CommandIO } from '../../command-contract';
8
8
  /**
9
9
  * 写入段:按判定旗标自愈被管理文档(只在写入模式被调用)
@@ -9,6 +9,8 @@ export interface ValidateOptions {
9
9
  file?: string;
10
10
  /** 项目路径 */
11
11
  projectPath?: string;
12
+ /** 只读模式(CLI --read-only;D3 P0.5 Phase 1):跳过检查点声明的命令执行 */
13
+ readOnly?: boolean;
12
14
  }
13
15
  /**
14
16
  * 执行检查点验证