kld-sdd 2.7.3 → 2.7.8

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 (65) hide show
  1. package/README.md +12 -5
  2. package/USABILITY.md +84 -0
  3. package/kld-sdd-guide.html +16 -4
  4. package/lib/hook-gate-core.js +327 -0
  5. package/lib/init.js +221 -37
  6. package/lib/scale-thresholds.json +19 -0
  7. package/lib/skills-bundle.js +2 -1
  8. package/package.json +5 -3
  9. package/skywalk-sdd/context-client.cjs +50 -30
  10. package/skywalk-sdd/index.cjs +36 -16
  11. package/skywalk-sdd/kb-sync-identity.cjs +99 -451
  12. package/skywalk-sdd/kb-upload.cjs +67 -44
  13. package/skywalk-sdd/lib/usage-contract.cjs +3 -2
  14. package/skywalk-sdd/lib/usage-reporter.cjs +27 -2
  15. package/skywalk-sdd/metrics-v3.cjs +2 -2
  16. package/skywalk-sdd/ontology/active-changes.cjs +2 -1
  17. package/skywalk-sdd/ontology/archive-package.cjs +1 -1
  18. package/skywalk-sdd/ontology/artifact-parser.cjs +7 -4
  19. package/skywalk-sdd/ontology/id.cjs +5 -4
  20. package/skywalk-sdd/ontology/identity-index.cjs +4 -3
  21. package/skywalk-sdd/ontology/list-changes.cjs +1 -1
  22. package/skywalk-sdd/ontology/runtime.cjs +7 -3
  23. package/skywalk-sdd/ontology/schema.cjs +2 -0
  24. package/skywalk-sdd/ontology/traceability-validator.cjs +74 -4
  25. package/skywalk-sdd/ontology/workspace-layout.cjs +25 -5
  26. package/skywalk-sdd/reporting/change-report-model.cjs +4 -3
  27. package/templates/git-hooks/commit-msg +22 -21
  28. package/templates/git-hooks/consistency-check-core.cjs +1087 -0
  29. package/templates/git-hooks/hooks.config +20 -1
  30. package/templates/git-hooks/pre-commit +22 -21
  31. package/templates/git-hooks/pre-commit-consistency-check.cjs +29 -332
  32. package/templates/git-hooks/pre-commit-sdd-check.cjs +98 -0
  33. package/templates/git-hooks/pre-push +22 -21
  34. package/templates/git-hooks/pre-push-consistency-check.cjs +58 -406
  35. package/templates/hooks/codebuddy/hooks/sdd-tdd-rhythm-gate.cjs +1 -1
  36. package/templates/openspec/tasks.md +3 -3
  37. package/templates/skills/kld-sdd/opsx-apply/SKILL.md +43 -6
  38. package/templates/skills/kld-sdd/opsx-apply/checklist.md +1 -1
  39. package/templates/skills/kld-sdd/opsx-apply/reference.md +1 -1
  40. package/templates/skills/kld-sdd/opsx-archive/SKILL.md +9 -13
  41. package/templates/skills/kld-sdd/opsx-check/SKILL.md +54 -328
  42. package/templates/skills/kld-sdd/opsx-check/checklist.md +7 -4
  43. package/templates/skills/kld-sdd/opsx-check/reference.md +58 -0
  44. package/templates/skills/kld-sdd/opsx-check/result-template.json +52 -0
  45. package/templates/skills/kld-sdd/opsx-check/reviewer.md +100 -0
  46. package/templates/skills/kld-sdd/opsx-consistency-check/SKILL.md +82 -451
  47. package/templates/skills/kld-sdd/opsx-consistency-check/{reference.md → references/reference.md} +0 -1
  48. package/templates/skills/kld-sdd/opsx-consistency-check/scripts/scripts.cjs +517 -0
  49. package/templates/skills/kld-sdd/opsx-design/SKILL.md +10 -30
  50. package/templates/skills/kld-sdd/opsx-design/checklist.md +3 -4
  51. package/templates/skills/kld-sdd/opsx-design/reference.md +1 -1
  52. package/templates/skills/kld-sdd/opsx-kb-ingest/SKILL.md +12 -74
  53. package/templates/skills/kld-sdd/opsx-ontology-query/SKILL.md +7 -5
  54. package/templates/skills/kld-sdd/opsx-ontology-query/phase-1-prechange.md +2 -2
  55. package/templates/skills/kld-sdd/opsx-ontology-query/reference.md +1 -1
  56. package/templates/skills/kld-sdd/opsx-propose/SKILL.md +28 -73
  57. package/templates/skills/kld-sdd/opsx-propose/checklist.md +8 -8
  58. package/templates/skills/kld-sdd/opsx-propose/interaction-policy.md +28 -0
  59. package/templates/skills/kld-sdd/opsx-propose/reference.md +12 -46
  60. package/templates/skills/kld-sdd/opsx-spec/SKILL.md +14 -61
  61. package/templates/skills/kld-sdd/opsx-spec/checklist.md +3 -3
  62. package/templates/skills/kld-sdd/opsx-task/SKILL.md +38 -32
  63. package/templates/skills/kld-sdd/opsx-task/checklist.md +5 -6
  64. package/templates/skills/kld-sdd/opsx-test/SKILL.md +2 -0
  65. package/templates/skills/kld-sdd/tdd-rules/rules/tdd-strategy-selection.md +1 -1
@@ -2,435 +2,87 @@
2
2
  /**
3
3
  * pre-push-consistency-check.cjs
4
4
  *
5
- * Pre-push 轻量门禁:仅检查报告是否存在、是否过期。
6
- * 完整的置信度校验由 pre-commit 完成,push 阶段不再重复。
5
+ * Pre-push 轻量门禁:仅检查待推送范围涉及报告的存在性、是否过期。
6
+ * - diff 驱动:仅检查待推送文件与报告 coveredFiles 有交集的 change,无关 change 跳过
7
+ * - 完整的置信度校验由 pre-commit 完成,push 阶段不再重复。
8
+ * - 过期判断读取 HEAD 已提交内容(而非工作区),避免工作区未提交修改造成误判。
9
+ *
10
+ * 待推送范围采集(逐级降级):
11
+ * 1. git diff @{push}..HEAD(本地领先远程的提交)
12
+ * 2. git diff origin/HEAD..HEAD
13
+ * 3. 远程引用不存在(新分支/新仓库首次推送):git diff <空树>..HEAD,
14
+ * 语义 = 首推时 HEAD 全部文件都是新增。空树 SHA 是 git 内置常量,
15
+ * 不依赖任何远程引用,避免「首推因无远程引用被拦 → 引用永远建立不起来」的死锁
16
+ * 4. 连空树 diff 都失败(如空仓无 HEAD):返回 ok=false,由 core 拦截推送而非静默放行
7
17
  *
8
18
  * 通过环境变量控制:
9
19
  * - SDD_SKIP_CONSISTENCY_CHECK=1 → 跳过校验
10
20
  * - SDD_WARN_ONLY=1 → 仅告警不拦截
11
21
  * - 注意:两个环境变量互斥,只能启用一个
22
+ *
23
+ * 共享逻辑见同目录 consistency-check-core.cjs。
12
24
  */
13
25
  'use strict';
14
26
 
15
- const fs = require('fs');
16
- const path = require('path');
27
+ const core = require('./consistency-check-core.cjs');
28
+ const { gitDiffNameStatus } = core;
17
29
  const { execFileSync } = require('child_process');
18
30
 
19
- const readArg = (name) => {
20
- const prefix = `--${name}=`;
21
- const found = process.argv.find(a => a.startsWith(prefix));
22
- return found ? found.slice(prefix.length) : '';
23
- };
24
-
25
- // --- Spec 根路径解析 ---
26
-
27
- function resolveSpecRoot() {
28
- // .cjs 位于 <spec-root>/skywalk-sdd/git-hooks/,直接用 __dirname 推算
29
- return path.resolve(__dirname, '..', '..');
30
- }
31
-
32
- function discoverActiveChanges(specRoot) {
33
- const changesDir = path.join(specRoot, 'openspec', 'changes');
34
- if (!fs.existsSync(changesDir)) return [];
35
-
36
- return fs.readdirSync(changesDir).filter(name => {
37
- const p = path.join(changesDir, name);
38
- return fs.statSync(p).isDirectory() && !name.startsWith('.') && name !== 'archive';
39
- });
40
- }
41
-
42
- // --- Push 范围收敛 ---
31
+ // git 内置空树对象 SHA(SHA-1 仓库恒定不变)
32
+ const EMPTY_TREE_SHA = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
43
33
 
44
34
  /**
45
- * 读取 pre-push 引用范围。
46
- * 优先从 shell hook 通过环境变量 SDD_PRE_PUSH_REFS 传入(shell hook 已消费 stdin),
47
- * 降级时尝试直接读 stdin。
35
+ * 单仓待推送范围采集:本地领先远程的提交所涉及的文件。
36
+ * files=修改/新增(排除删除);deleted=删除文件。
37
+ * @returns {{files: string[], deleted: string[], ok: boolean}}
48
38
  */
49
- function readPushRefLines() {
50
- const envRefs = process.env.SDD_PRE_PUSH_REFS;
51
- if (envRefs) {
52
- // shell hook \n 字面量拼接,也可能含真实换行符
53
- return envRefs.split(/\\n|\n/).filter(Boolean);
39
+ function gitPushRangeDiff(repoRoot) {
40
+ const ranges = ['@{push}..HEAD', 'origin/HEAD..HEAD'];
41
+ for (const range of ranges) {
42
+ const r = gitDiffNameStatus(repoRoot, ['diff', range]);
43
+ if (r.ok) return r;
54
44
  }
55
-
56
- try {
57
- if (process.stdin.isTTY) return [];
58
- const buffer = fs.readFileSync(0, 'utf8'); // fd 0 = stdin
59
- return buffer.split(/\r?\n/).filter(Boolean);
60
- } catch {
61
- return [];
45
+ // 首推降级:远程引用不存在(@{push}/origin/HEAD 均无法解析)时,
46
+ // 用 git 内置空树 SHA 做 diff —— 语义为「首推 = HEAD 全部文件都是新增」。
47
+ // 空树对象不依赖任何远程引用,打破「首推被拦 远程引用永远建立不起来」的死锁。
48
+ const emptyTree = gitEmptyTreeSha(repoRoot);
49
+ if (emptyTree) {
50
+ const r = gitDiffNameStatus(repoRoot, ['diff', `${emptyTree}..HEAD`]);
51
+ if (r.ok) return r;
62
52
  }
53
+ // 连空树 diff 都失败(如空仓无 HEAD):返回失败,由 core 拦截而非静默放行
54
+ return { files: [], deleted: [], ok: false };
63
55
  }
64
56
 
65
57
  /**
66
- * pre-push stdin 行解析 commit 范围,获取本次 push 实际变更的文件列表
58
+ * 读取 git 内置空树 SHA(4b825dc642cb6eb9a060e54bf8d69288fbee4904)。
59
+ * 优先用 git mktree 动态计算(兼容 SHA-256 仓库),失败时回退内置常量。
60
+ * @param {string} repoRoot
61
+ * @returns {string|null}
67
62
  */
68
- function getPushRangeFiles(projectRoot) {
69
- const lines = readPushRefLines();
70
- if (lines.length === 0) return null;
71
-
72
- const files = new Set();
73
- for (const line of lines) {
74
- const parts = line.split(/\s+/);
75
- if (parts.length < 4) continue;
76
- const localSha = parts[1];
77
- const remoteSha = parts[3];
78
-
79
- // 删除分支:localSha 为全 0
80
- if (localSha === '0000000000000000000000000000000000000000') continue;
81
-
82
- try {
83
- let diffFiles;
84
- if (remoteSha === '0000000000000000000000000000000000000000') {
85
- // 新建分支:用 git show 获取该 commit 引入的文件
86
- diffFiles = execFileSync('git', ['show', '--name-only', '--pretty=format:', localSha], {
87
- cwd: projectRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
88
- }).split(/\r?\n/).filter(Boolean);
89
- } else {
90
- // 已有分支:用 git diff 获取范围变更
91
- diffFiles = execFileSync('git', ['diff', `${remoteSha}..${localSha}`, '--name-only'], {
92
- cwd: projectRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
93
- }).split(/\r?\n/).filter(Boolean);
94
- }
95
- for (const f of diffFiles) files.add(f.replace(/\\/g, '/'));
96
- } catch {
97
- // 单个 ref 失败不阻断,继续处理其他 ref
98
- }
99
- }
100
-
101
- return files.size > 0 ? Array.from(files) : null;
102
- }
103
-
104
- function normalizePath(filePath) {
105
- return filePath.replace(/\\/g, '/');
106
- }
107
-
108
- function getChangeNameFromPath(filePath) {
109
- const normalized = normalizePath(filePath);
110
- const match = normalized.match(/^openspec\/changes\/([^/]+)\//);
111
- return match ? match[1] : '';
112
- }
113
-
114
- /**
115
- * 从 push 的变更文件列表中提取涉及的 change name
116
- */
117
- function discoverChangesFromPushFiles(projectRoot, specRoot) {
118
- const pushFiles = getPushRangeFiles(projectRoot);
119
- if (!pushFiles) return null; // 降级信号
120
-
121
- const changes = new Set();
122
- for (const file of pushFiles) {
123
- const changeName = getChangeNameFromPath(file);
124
- if (changeName) changes.add(changeName);
125
- }
126
-
127
- if (changes.size === 0) {
128
- console.log('[SDD push-consistency-check] 本次 push 不涉及 openspec 变更,跳过');
129
- process.exit(0);
130
- }
131
-
132
- // 过滤掉已归档的 change
133
- const activeChanges = new Set(discoverActiveChanges(specRoot));
134
- return Array.from(changes).filter(cn => activeChanges.has(cn));
135
- }
136
-
137
- // --- 报告查找与解析 ---
138
-
139
- function findReport(specRoot, changeName, type) {
140
- const names = type === 'json'
141
- ? ['consistency-report-result.json', 'consistency-report-self-review-result.json']
142
- : ['consistency-report.md', 'consistency-report-self-review.md'];
143
-
144
- const found = [];
145
- for (const n of names) {
146
- const p = path.join(specRoot, 'openspec', 'changes', changeName, n);
147
- if (fs.existsSync(p)) found.push(p);
148
- }
149
-
150
- // 如果两种模式的报告都存在,返回错误标记
151
- if (found.length > 1) {
152
- return { error: 'duplicate', paths: found };
153
- }
154
-
155
- return found.length === 1 ? found[0] : null;
156
- }
157
-
158
- function parseReport(reportPath) {
159
- try {
160
- const data = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
161
- return {
162
- confidence: (data.confidence || '').toLowerCase(),
163
- reviewMode: data.reviewMode || 'independent-review',
164
- humanConfirmed: data.humanConfirmed === true,
165
- reportPath,
166
- };
167
- } catch (err) {
168
- return { confidence: '', reviewMode: '', humanConfirmed: false, reportPath, parseError: err.message };
169
- }
170
- }
171
-
172
- // --- 变更文件采集(基于配置文件精准定位) ---
173
-
174
- /**
175
- * 简易 YAML 解析器:仅提取 code_repos 列表
176
- */
177
- function parseCodeRepos(yamlPath) {
178
- try {
179
- const content = fs.readFileSync(yamlPath, 'utf8');
180
- const match = content.match(/code_repos:\s*\n((?:\s+-\s+\S+\n?)+)/);
181
- if (!match) return null;
182
- return match[1]
183
- .split('\n')
184
- .map(line => line.replace(/^\s+-\s+/, '').trim())
185
- .filter(Boolean);
186
- } catch {
187
- return null;
188
- }
189
- }
190
-
191
- function gitDiff(repoRoot) {
63
+ function gitEmptyTreeSha(repoRoot) {
192
64
  try {
193
- return execFileSync('git', ['diff', 'HEAD', '--name-only'], {
194
- cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
195
- }).split(/\r?\n/).filter(Boolean);
65
+ const sha = execFileSync('git', ['mktree'], {
66
+ cwd: repoRoot, encoding: 'utf8', input: '', stdio: ['pipe', 'pipe', 'ignore'],
67
+ }).trim();
68
+ if (/^[0-9a-f]{40,64}$/.test(sha)) return sha;
196
69
  } catch {
197
- return [];
198
- }
199
- }
200
-
201
- function getModifiedFiles(projectRoot) {
202
- // 工作区模式:读 .sdd-workspace.yaml 的 code_repos
203
- const wsYaml = path.join(projectRoot, '.sdd-workspace.yaml');
204
- if (fs.existsSync(wsYaml)) {
205
- const repos = parseCodeRepos(wsYaml);
206
- if (repos && repos.length > 0) {
207
- const files = [];
208
- for (const repo of repos) {
209
- const repoRoot = path.join(projectRoot, repo);
210
- for (const f of gitDiff(repoRoot)) {
211
- files.push(path.join(repo, f).replace(/\\/g, '/'));
212
- }
213
- }
214
- return [...new Set(files)];
215
- }
216
- }
217
-
218
- // 单仓模式 / 兜底:直接对 projectRoot 做 diff
219
- return gitDiff(projectRoot);
220
- }
221
-
222
- /**
223
- * 获取报告生成时间:优先用 JSON 中的 generatedAt,降级用文件 mtime
224
- */
225
- function getReportTime(jsonPath) {
226
- try {
227
- const data = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
228
- if (data.generatedAt) {
229
- const t = new Date(data.generatedAt).getTime();
230
- if (!isNaN(t)) return t;
231
- }
232
- } catch {}
233
- // 降级:用文件 mtime
234
- return fs.statSync(jsonPath).mtimeMs;
235
- }
236
-
237
- function isReportStale(specRoot, changeName, modifiedFiles, projectRoot) {
238
- const jsonPath = findReport(specRoot, changeName, 'json');
239
- if (!jsonPath) return false;
240
-
241
- const reportTime = getReportTime(jsonPath);
242
-
243
- // 排除报告文件本身
244
- const reportFiles = [
245
- 'consistency-report.md',
246
- 'consistency-report-self-review.md',
247
- 'consistency-report-result.json',
248
- 'consistency-report-self-review-result.json',
249
- ];
250
-
251
- return modifiedFiles.some(file => {
252
- if (reportFiles.includes(path.basename(file))) return false;
253
- const fp = path.join(projectRoot, file);
254
- return fs.existsSync(fp) && fs.statSync(fp).mtimeMs > reportTime;
255
- });
256
- }
257
-
258
- // --- 提示信息 ---
259
-
260
- function generateInstructions(missing, stale, needsConfirmation, warnOnly) {
261
- const lines = ['', '=========================================='];
262
- const needsRegenerate = [...new Set([...missing, ...stale])];
263
-
264
- if (warnOnly) {
265
- lines.push('[SDD push-consistency-check] ⚠️ 仅告警模式(SDD_WARN_ONLY=1),以下问题不会阻止推送:');
266
- } else {
267
- lines.push('[SDD push-consistency-check] 以下变更存在问题,拒绝推送:');
268
- }
269
-
270
- lines.push('');
271
-
272
- if (missing.length) {
273
- lines.push(' 缺少一致性报告:');
274
- missing.forEach(c => lines.push(` - ${c}`));
275
- }
276
-
277
- if (stale.length) {
278
- lines.push(' 报告已过期(代码在报告生成后被修改):');
279
- stale.forEach(c => lines.push(` - ${c}`));
280
- }
281
-
282
- if (needsConfirmation.length) {
283
- lines.push(' 自审模式需人工确认:');
284
- needsConfirmation.forEach(c => lines.push(` - ${c}`));
285
- }
286
-
287
- // 只有需要重新生成报告时才显示 skill 执行建议
288
- if (needsRegenerate.length > 0) {
289
- lines.push('');
290
- lines.push(warnOnly
291
- ? '建议执行 opsx-consistency-check skill 更新报告:'
292
- : '请执行 opsx-consistency-check skill 更新报告后再推送:');
293
- lines.push('');
294
-
295
- if (needsRegenerate.length === 1) {
296
- lines.push(` skill: opsx-consistency-check ${needsRegenerate[0]}`);
297
- } else {
298
- lines.push(' skill(逐个执行):');
299
- needsRegenerate.forEach(c => lines.push(` opsx-consistency-check ${c}`));
300
- }
301
-
302
- lines.push(
303
- '',
304
- ' 💡 建议:新开对话窗口执行校验,以获得独立、客观的审核结果',
305
- );
306
- }
307
-
308
- // 自审模式人工确认指引
309
- if (needsConfirmation.length > 0) {
310
- lines.push('');
311
- lines.push(' 人工确认步骤:');
312
- lines.push(' 1. 打开 consistency-report-self-review.md,找到「人工确认(自审模式)」章节');
313
- lines.push(' 2. 逐条核对断言,在「人工确认」列填写 ✅ 已确认 或 ❌ 有误');
314
- lines.push(' 3. 确认无误后,编辑 consistency-report-self-review-result.json,将 humanConfirmed 从 false 改为 true');
315
- lines.push('');
316
- lines.push(' 报告路径: openspec/changes/<change-name>/consistency-report-self-review.md');
317
- lines.push(' JSON 路径: openspec/changes/<change-name>/consistency-report-self-review-result.json');
318
- }
319
-
320
- // 如果没有需要重新生成的报告,但有其他问题,显示默认报告路径
321
- if (needsRegenerate.length > 0 && needsConfirmation.length === 0) {
322
- lines.push(
323
- '',
324
- ' 报告路径: openspec/changes/<change-name>/consistency-report.md',
325
- ' JSON 路径: openspec/changes/<change-name>/consistency-report-result.json',
326
- );
70
+ // 降级到内置常量
327
71
  }
328
-
329
- lines.push('==========================================', '');
330
-
331
- return lines.join('\n');
72
+ return /^[0-9a-f]{40}$/.test(EMPTY_TREE_SHA) ? EMPTY_TREE_SHA : null;
332
73
  }
333
74
 
334
- // --- 主流程 ---
335
-
336
- function main() {
337
- const projectRoot = path.resolve(readArg('project') || process.env.SDD_PROJECT || process.cwd());
338
-
339
- const skip = process.env.SDD_SKIP_CONSISTENCY_CHECK === '1';
340
- const warnOnly = process.env.SDD_WARN_ONLY === '1';
341
-
342
- // 互斥检查
343
- if (skip && warnOnly) {
344
- console.error('[SDD push-consistency-check] 错误:SDD_SKIP_CONSISTENCY_CHECK 与 SDD_WARN_ONLY 互斥,只能启用一个');
345
- process.exit(1);
346
- }
347
-
348
- if (skip) {
349
- console.log('[SDD push-consistency-check] 跳过校验');
350
- process.exit(0);
351
- }
352
-
353
- if (warnOnly) console.log('[SDD push-consistency-check] 仅告警模式');
354
-
355
- const specRoot = resolveSpecRoot();
356
-
357
- // 优先尝试按本次 push 范围收敛变更
358
- let changes = discoverChangesFromPushFiles(projectRoot, specRoot);
359
- let modifiedFiles = null;
360
-
361
- if (changes === null) {
362
- // 降级:stdin 读取失败,回退到现有行为
363
- console.log('[SDD push-consistency-check] 无法读取 push 范围,降级为全量检查');
364
- changes = discoverActiveChanges(specRoot);
365
- modifiedFiles = getModifiedFiles(projectRoot);
366
- } else if (changes.length === 0) {
367
- console.log('[SDD push-consistency-check] 无相关活跃变更,跳过');
368
- process.exit(0);
369
- } else {
370
- // 收敛成功:用 push 范围文件做过期判定
371
- modifiedFiles = getPushRangeFiles(projectRoot) || [];
372
- }
373
-
374
- if (!changes.length) {
375
- console.log('[SDD push-consistency-check] 无活跃变更,跳过');
376
- process.exit(0);
377
- }
378
-
379
- const missing = [];
380
- const stale = [];
381
- const needsConfirmation = [];
382
-
383
- for (const cn of changes) {
384
- const rp = findReport(specRoot, cn, 'json');
385
- if (!rp) {
386
- missing.push(cn);
387
- continue;
388
- }
389
-
390
- // 检查是否存在两种模式的报告
391
- if (rp.error === 'duplicate') {
392
- console.warn(`[SDD push-consistency-check] ⚠️ ${cn} 存在两种模式的报告,请删除其中一个:`);
393
- rp.paths.forEach(p => console.warn(` - ${p}`));
394
- missing.push(cn);
395
- continue;
396
- }
397
-
398
- const report = parseReport(rp);
399
- if (report.parseError) {
400
- console.warn(`[SDD push-consistency-check] ⚠️ ${cn}: 报告解析失败`);
401
- missing.push(cn);
402
- continue;
403
- }
404
-
405
- if (isReportStale(specRoot, cn, modifiedFiles, projectRoot)) {
406
- console.log(`[SDD push-consistency-check] ⚠️ ${cn}: 报告已过期`);
407
- stale.push(cn);
408
- continue;
409
- }
410
-
411
- // 自审模式需要人工确认
412
- if (report.reviewMode === 'self-review' && !report.humanConfirmed) {
413
- console.log(`[SDD push-consistency-check] ⚠️ ${cn}: 自审模式需人工确认`);
414
- needsConfirmation.push(cn);
415
- continue;
416
- }
417
-
418
- console.log(`[SDD push-consistency-check] ✅ ${cn}: 报告有效`);
419
- }
420
-
421
- if (missing.length || stale.length || needsConfirmation.length) {
422
- console.log(generateInstructions(missing, stale, needsConfirmation, warnOnly));
423
-
424
- if (warnOnly) {
425
- console.log('[SDD push-consistency-check] 仅告警模式,放行推送');
426
- process.exit(0);
427
- }
428
-
429
- process.exit(1);
430
- }
431
-
432
- console.log('\n[SDD push-consistency-check] ✅ 所有变更均已通过一致性校验,放行推送');
433
- process.exit(0);
75
+ // strict 模式仅 pre-commit 支持:显式提示而非静默忽略
76
+ const _mode = core.loadConsistencyMode();
77
+ if (process.env.SDD_STRICT_CONSISTENCY === '1' || _mode.strict) {
78
+ console.log('[SDD push-consistency-check] ℹ️ SDD_STRICT_CONSISTENCY 仅在 pre-commit 阶段生效,push 阶段忽略');
434
79
  }
435
80
 
436
- main();
81
+ core.runConsistencyCheck({
82
+ label: '[SDD push-consistency-check]',
83
+ actionNoun: '推送',
84
+ diffFn: gitPushRangeDiff,
85
+ checkConfidence: false, // 置信度校验由 pre-commit 完成,push 阶段不重复
86
+ includeUntracked: false, // untracked 文件不在任何 commit 中,不会被推送
87
+ staleFromHead: true, // 过期判断读 HEAD 已提交内容,避免工作区未提交修改误判
88
+ });
@@ -154,7 +154,7 @@ if (require.main === module) {
154
154
  }
155
155
 
156
156
  // G4: 批量更新检测(E1 修正:不再提前退出,模式检查继续执行)
157
- var skipPerTaskCheck = false;
157
+ let skipPerTaskCheck = false;
158
158
  if (changes.length >= 2 && hasTddTasks) {
159
159
  // 安全网 2: 全部有 task_update 遥测 → check-task 合法更新,跳过逐个检查
160
160
  const allHaveTaskUpdate = changes.every(change =>
@@ -8,7 +8,7 @@ capability-id: "CAP-<CAPABILITY>" # 必须与对应 spec/design 一致
8
8
  >
9
9
  > **⚠️ 边界声明**:本任务清单仅服务于当前 Capability,严禁跨模块任务。
10
10
  >
11
- > **【质量红线】颗粒度必须达到"AI能在5分钟内实现";且拆解的任务和验证逻辑必须 100% 覆盖 spec 和 design
11
+ > **【质量红线】任务按可验证行为或交付单元拆分,不设固定分钟数;且拆解的任务和验证逻辑必须 100% 覆盖 spec 和 design
12
12
 
13
13
  ---
14
14
 
@@ -105,7 +105,7 @@ capability-id: "CAP-<CAPABILITY>" # 必须与对应 spec/design 一致
105
105
 
106
106
  ## 3. 原子任务清单
107
107
 
108
- <!-- 【质量红线】每个任务必须能在5分钟内由AI实现 -->
108
+ <!-- 【质量红线】每个任务应有可验证结果和明确依赖,避免按字段或命令机械拆分 -->
109
109
 
110
110
  ### 3.0 任务类型说明
111
111
 
@@ -299,7 +299,7 @@ capability-id: "CAP-<CAPABILITY>" # 必须与对应 spec/design 一致
299
299
  ---
300
300
 
301
301
  > **质量红线检查清单**
302
- > - [ ] 每个任务颗粒度符合"5分钟可实现"标准
302
+ > - [ ] 每个任务对应可验证结果,粒度与真实依赖相匹配
303
303
  > - [ ] 任务清单 100% 覆盖 spec.md 定义
304
304
  > - [ ] 任务清单 100% 覆盖 design.md 定义
305
305
  > - [ ] 每个任务都有明确的验收标准
@@ -17,6 +17,8 @@ allowed-tools:
17
17
  - Agent
18
18
  ---
19
19
 
20
+ > **执行方式**:先读 [交互与执行契约](../opsx-propose/interaction-policy.md);同一会话已读则复用。用户已授权连续处理时按范围推进,不重复索要阶段口令;只请求单阶段时完成即停。
21
+
20
22
  你是一个 SDD(Specification-Driven Development)变更实施专家。激活本技能后,你将引导用户按 DAG 依赖顺序逐任务实施代码。
21
23
 
22
24
 
@@ -24,7 +26,7 @@ allowed-tools:
24
26
  >
25
27
  > - 本技能针对**单一 Capability** 执行实施
26
28
  > - **上下文**:overview.md → proposal.md → 当前 capability 的 spec/design/tasks
27
- > - ⛔ **隔离红线**:绝对禁止加载同级其他 Capability 的文档
29
+ > - ⛔ **隔离红线**:默认聚焦当前 Capability;为核对已声明依赖可读取相关 Capability 契约并注明来源,不全量加载或混写其他能力。
28
30
 
29
31
  > **🖥️ 跨平台执行规则**
30
32
  > - **写代码**:cwd 保持在 Git 根(含 `src/`);**文档 / telemetry**:`--project` 指向 SDD 包裹包(`node <spec-package>/skywalk-sdd/spec-root.cjs` 可获取)。
@@ -116,12 +118,40 @@ openspec list --json
116
118
  > - **Capability**:`<capability-name>`
117
119
  > - **任务文件**:`changes/<name>/specs/<capability>/tasks.md`"
118
120
 
119
- ### 1.2 【Check 门禁检查】验证质量门禁状态
121
+ ### 1.5 【非阻断】编译依赖预检
122
+
123
+ 读取当前 Capability 的 tasks.md 中所有 IMPL/CONTROLLER 任务的描述,提取:
124
+ 1. 使用的注解(@PreAuthorize, @Transactional, @Valid, @Mapper 等)
125
+ 2. 导入的框架类(spring-security, mybatis, validation 等)
126
+ 3. 与当前 pom.xml(或 build.gradle)已声明依赖做对比
127
+
128
+ **预检输出格式**(仅警告,不拦截 apply):
129
+ > "📋 **编译依赖预检**(非阻断)
130
+ >
131
+ > | 检查项 | 状态 | 详情 |
132
+ > |--------|------|------|
133
+ > | @PreAuthorize 依赖 | ⚠️ | spring-boot-starter-security 未在 pom.xml 中声明 |
134
+ > | @Transactional 依赖 | ✅ | spring-tx 已声明 |
135
+ > | @Mapper 依赖 | ✅ | mybatis 已声明 |
136
+ >
137
+ > 建议:若上述缺失依赖确需使用,可在 Layer 0 补充依赖配置任务,或确认现有构建文件已包含。
138
+ >
139
+ > 请选择:
140
+ > - **A. 忽略警告,继续 apply**(默认)
141
+ > - **B. 暂停,先补充依赖任务**
142
+ > - **C. 确认 pom.xml 已包含(预检误报)**"
143
+
144
+ **预检规则**:
145
+ - 只扫描 tasks.md 中任务描述文本,不扫描实际代码(apply 前代码可能尚未生成)
146
+ - 依赖映射表维护常用注解→Maven/Gradle 依赖的对应关系(见 `./reference.md`「§1.5a 注解依赖映射表」)
147
+ - 误报时用户选择 C,记录 `process_note(kind=user_decision, decision_type=ignore_dependency_warning)`
148
+
149
+ ### 1.6 【Check 门禁检查】验证质量门禁状态
120
150
 
121
151
  > **⛔ 强制门禁**:apply 阶段开始前,必须确认 check 阶段已完成。这是 SDD 流程的关键质量保障。
122
152
  > 详细检查步骤、判定与门禁体系说明见 `./checklist.md`「§1.2 Check 门禁」。未完成强制拒绝。${HOOK_GATE_DESCRIPTION}
123
153
 
124
- ### 1.5 【本地并行】Worktree 与工作区(建议性策略)
154
+ ### 1.7 【本地并行】Worktree 与工作区(建议性策略)
125
155
 
126
156
  > **目标(本质)**:在**本地仓库**加快 SDD Apply——让**解耦**的 spec/capability 可以各自实现、互不踩目录,做完再按依赖顺序合并回你**当时所在的分支**(集成分支,如 `hotfix-1`)。
127
157
  >
@@ -153,7 +183,7 @@ openspec list --json
153
183
  第 3 层:当前 Capability 四文档
154
184
  → spec.md → design.md → tasks.md
155
185
 
156
- 隔离红线:禁止加载其他 Capability 的文档!
186
+ 隔离红线:默认聚焦当前 Capability;为核对已声明依赖可读取相关 Capability 契约并注明来源,不全量加载或混写其他能力。
157
187
  ```
158
188
 
159
189
  **【可选】业务知识库检索**:
@@ -267,7 +297,14 @@ g. **继续下一个层级** — 重新检查 DAG,找出依赖已满足的下
267
297
  > - 已完成:[N/M] 任务
268
298
  > - 当前层级:Layer [X]
269
299
  > - 下一步建议:[继续实施 / 运行测试 / 归档]"
270
- >
300
+
301
+ **【已授权连续处理完成】**
302
+ 若本次为用户已授权的连续处理,完成时展示一次整体交付结果:
303
+ > "✅ **本轮连续处理完成**
304
+ > - propose → spec → design → task → check → apply 已全部执行完毕
305
+ > - 各阶段文档已生成,质量门禁已执行
306
+ > - 建议下一步:运行测试 / 归档变更"
307
+
271
308
  > **💡 代码评审提示**:
272
309
  > 建议执行 `/kld-review --local` 对本次变更的代码进行评审。
273
310
  > 该技能可在公司内部 SkillHub 下载安装。
@@ -295,7 +332,7 @@ g. **继续下一个层级** — 重新检查 DAG,找出依赖已满足的下
295
332
  > 完整 ⛔ 强制项勾选清单见 `./checklist.md`「Guardrails ⛔ 强制项」。核心红线:
296
333
 
297
334
  - **⛔ Check 门禁检查**:apply 前必须确认 check 已完成;未完成强制拒绝。${HOOK_GATE_DESCRIPTION}
298
- - **⛔ 渐进式加载 + 隔离红线**:只加载当前 Capability 的四文档链,禁止加载同级其他 Capability 的文档。
335
+ - **⛔ 渐进式加载 + 隔离红线**:只加载当前 Capability 的四文档链,默认聚焦当前 Capability;为核对已声明依赖可读取相关 Capability 契约并注明来源,不全量加载或混写其他能力。
299
336
  - **⛔ DAG 依赖拦截**:执行任务前必须检查依赖,前置未完成必须拦截。
300
337
  - **⛔ 编译检查门禁**:每完成一个任务后必须运行编译检查,编译失败禁止标记已完成。
301
338
  - **⛔ 测试执行门禁**:根据 `test-strategy` 决定(tdd=强制, impl-first=强制补跑, none=跳过);须真实执行并留 telemetry。${HOOK_GATE_DESCRIPTION}
@@ -139,7 +139,7 @@ description: opsx-apply 的阶段强制检查点与自检清单。仅在执行 a
139
139
 
140
140
  - [ ] ⛔ **Check 门禁检查**:apply 前必须确认 check 已完成;未完成强制拒绝,与 `sdd-apply-gate.cjs` Hook 形成双重保障
141
141
  - [ ] ⛔ **渐进式加载**:只加载当前 Capability 的四文档链
142
- - [ ] ⛔ **隔离红线**:绝对禁止加载同级其他 Capability 的文档
142
+ - [ ] ⛔ **隔离红线**:默认聚焦当前 Capability;为核对已声明依赖可读取相关 Capability 契约并注明来源,不全量加载或混写其他能力。
143
143
  - [ ] ⛔ **DAG 依赖拦截**:执行任务前必须检查依赖,前置未完成必须拦截
144
144
  - [ ] ⛔ **编译检查门禁**:每完成一个任务后必须运行编译检查,编译失败禁止标记已完成
145
145
  - [ ] ⛔ **测试执行门禁**:根据 `test-strategy` 决定(tdd=强制, impl-first=强制补跑, none=跳过);须真实执行并留 telemetry,`sdd-apply-test-gate` 校验非占位数据
@@ -237,7 +237,7 @@ node "$(cat .sdd-spec-root)/skywalk-sdd/log.cjs" record --type=worktree_finish \
237
237
  - **§4 依赖**(是否依赖 `<当前 capability>` 或其它 cap)
238
238
  - **涉及模块 / 数据表 / 公共配置**(若有)
239
239
 
240
- 禁止为校验而加载其它 cap 的 `design.md`、`tasks.md`(完整实施上下文仍遵守 §2 隔离红线)。
240
+ 默认聚焦当前 cap;核对真实跨能力依赖时可读取相关契约并注明来源,避免全量加载或混写。
241
241
 
242
242
  **Step D — 判定矩阵(输出给用户)**
243
243