kld-sdd 2.6.16 → 2.6.21

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 (70) hide show
  1. package/bin/kld-sdd-init.js +10 -0
  2. package/kld-sdd-guide.html +22 -0
  3. package/lib/device-auth-cli.js +130 -0
  4. package/lib/device-auth.js +345 -0
  5. package/lib/init-account-binding.js +108 -0
  6. package/lib/init.js +238 -55
  7. package/lib/skills-bundle.js +20 -1
  8. package/lib/tool-profiles.js +8 -0
  9. package/package.json +7 -3
  10. package/skywalk-sdd/apply-worktree-finish.cjs +2 -23
  11. package/skywalk-sdd/context-client.cjs +38 -87
  12. package/skywalk-sdd/index.cjs +860 -132
  13. package/skywalk-sdd/kb-sync-identity.cjs +780 -0
  14. package/skywalk-sdd/kb-upload.cjs +505 -0
  15. package/skywalk-sdd/lib/shared.cjs +811 -0
  16. package/skywalk-sdd/lib/usage-contract.cjs +276 -0
  17. package/skywalk-sdd/lib/usage-reporter.cjs +354 -0
  18. package/skywalk-sdd/lib/user-config.cjs +157 -0
  19. package/skywalk-sdd/metrics-v3.cjs +138 -8
  20. package/skywalk-sdd/ontology/archive-package.cjs +19 -34
  21. package/skywalk-sdd/ontology/change-lock.cjs +3 -7
  22. package/skywalk-sdd/ontology/external-key.cjs +18 -4
  23. package/skywalk-sdd/ontology/id.cjs +26 -5
  24. package/skywalk-sdd/ontology/identity-index.cjs +3 -7
  25. package/skywalk-sdd/ontology/resolve-spec-root.cjs +20 -6
  26. package/skywalk-sdd/ontology/runtime.cjs +16 -12
  27. package/skywalk-sdd/ontology/traceability-validator.cjs +7 -4
  28. package/skywalk-sdd/reporting/change-report-markdown.cjs +137 -19
  29. package/skywalk-sdd/reporting/change-report-model.cjs +993 -14
  30. package/skywalk-sdd/reporting/change-report-renderer.cjs +106 -41
  31. package/skywalk-sdd/reporting/change-report-view-model.cjs +272 -43
  32. package/skywalk-sdd/reporting/core-metric-definitions.cjs +192 -0
  33. package/skywalk-sdd/spec-root.cjs +31 -0
  34. package/templates/git-hooks/pre-commit-consistency-check.cjs +271 -116
  35. package/templates/git-hooks/pre-push-consistency-check.cjs +252 -123
  36. package/templates/hooks/codebuddy/hooks/hook-gate-core.cjs +327 -0
  37. package/templates/hooks/codebuddy/hooks/sdd-apply-test-gate.cjs +54 -9
  38. package/templates/hooks/codebuddy/hooks/sdd-mid-checkpoint.cjs +63 -6
  39. package/templates/hooks/codebuddy/hooks/sdd-tdd-rhythm-gate.cjs +113 -65
  40. package/templates/openspec/proposal.md +7 -3
  41. package/templates/openspec/spec.md +3 -3
  42. package/templates/skills/kld-sdd/opsx-apply/SKILL.md +8 -6
  43. package/templates/skills/kld-sdd/opsx-apply/checklist.md +2 -0
  44. package/templates/skills/kld-sdd/opsx-apply/reference.md +29 -7
  45. package/templates/skills/kld-sdd/opsx-archive/SKILL.md +6 -5
  46. package/templates/skills/kld-sdd/opsx-check/SKILL.md +49 -17
  47. package/templates/skills/kld-sdd/opsx-check/checklist.md +4 -2
  48. package/templates/skills/kld-sdd/opsx-consistency-check/SKILL.md +187 -257
  49. package/templates/skills/kld-sdd/opsx-consistency-check/reference.md +129 -0
  50. package/templates/skills/kld-sdd/opsx-design/SKILL.md +2 -2
  51. package/templates/skills/kld-sdd/opsx-explore/SKILL.md +2 -2
  52. package/templates/skills/kld-sdd/opsx-kb-config/SKILL.md +185 -0
  53. package/templates/skills/kld-sdd/opsx-kb-config/reference.md +127 -0
  54. package/templates/skills/kld-sdd/opsx-kb-ingest/SKILL.md +218 -53
  55. package/templates/skills/kld-sdd/opsx-kb-ingest/reference.md +51 -9
  56. package/templates/skills/kld-sdd/opsx-ontology-query/SKILL.md +12 -50
  57. package/templates/skills/kld-sdd/opsx-ontology-query/phase-3-postchange.md +2 -2
  58. package/templates/skills/kld-sdd/opsx-ontology-query/reference.md +1 -1
  59. package/templates/skills/kld-sdd/opsx-propose/SKILL.md +35 -23
  60. package/templates/skills/kld-sdd/opsx-propose/checklist.md +2 -0
  61. package/templates/skills/kld-sdd/opsx-propose/reference.md +22 -17
  62. package/templates/skills/kld-sdd/opsx-rules/SKILL.md +2 -2
  63. package/templates/skills/kld-sdd/opsx-spec/SKILL.md +19 -15
  64. package/templates/skills/kld-sdd/opsx-spec/checklist.md +2 -0
  65. package/templates/skills/kld-sdd/opsx-task/SKILL.md +2 -4
  66. package/templates/skills/kld-sdd/opsx-test/SKILL.md +2 -2
  67. package/templates/skills/kld-sdd/tdd-core/reference.md +1 -1
  68. package/templates/skills/kld-sdd/tdd-rules/rules/test-skeleton-telemetry.md +1 -1
  69. package/templates/skills/kld-sdd/opsx-kb-ingest/state.example.json +0 -7
  70. package/templates/skills/kld-sdd/opsx-ontology-query/state.example.json +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kld-sdd",
3
- "version": "2.6.16",
3
+ "version": "2.6.21",
4
4
  "description": "KLD SDD OpenSpec 项目初始化工具 - 一键部署 SDD skills",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -8,7 +8,7 @@
8
8
  "kld-sdd-init": "bin/kld-sdd-init.js"
9
9
  },
10
10
  "scripts": {
11
- "test": "node test/external-key.cjs && node test/change-key.cjs && node test/modules-and-sdd-config.cjs && node test/active-changes.cjs && node test/hook-layouts.cjs && node test/spec-package-init.cjs && node test/workspace-layout.cjs && node test/ontology-release-blockers.cjs && node test/ontology-semantic-core.cjs && node test/ontology-identity-versioning.cjs && node test/ontology-identity-continuity.cjs && node test/ontology-state-transaction.cjs && node test/ontology-process-concurrency.cjs && node test/ontology-observer-convergence.cjs && node test/ontology-working-runtime.cjs && node test/ontology-stage-materialization.cjs && node test/ontology-template-contract.cjs && node test/ontology-cli-archive.cjs && node test/archive-package-producer.cjs && node --test test/evidence-integrity-oracle.cjs test/evidence-integrity-wiring.cjs test/change-report-correctness.cjs test/report-metrics-correctness.cjs test/change-report-model-ui.cjs && node test/validate-skills-bundle.cjs && node test/tool-profiles.cjs && node test/settings-merge.cjs && node test/command-bridge.cjs && node test/codebuddy-hooks.cjs && node test/skill-content-contract.cjs && node test/init-agent-profiles.cjs && node test/init-report-runtime.cjs"
11
+ "test": "node test/external-key.cjs && node test/change-key.cjs && node test/modules-and-sdd-config.cjs && node test/active-changes.cjs && node test/hook-layouts.cjs && node test/spec-package-init.cjs && node test/workspace-layout.cjs && node test/ontology-release-blockers.cjs && node test/ontology-semantic-core.cjs && node test/ontology-identity-versioning.cjs && node test/ontology-identity-continuity.cjs && node test/ontology-state-transaction.cjs && node test/ontology-process-concurrency.cjs && node test/ontology-observer-convergence.cjs && node test/ontology-working-runtime.cjs && node test/ontology-stage-materialization.cjs && node test/ontology-template-contract.cjs && node test/ontology-cli-archive.cjs && node test/archive-package-producer.cjs && node --test test/evidence-integrity-oracle.cjs test/evidence-integrity-wiring.cjs test/change-report-correctness.cjs test/report-metrics-correctness.cjs test/change-report-model-ui.cjs && node test/validate-skills-bundle.cjs && node test/tool-profiles.cjs && node test/settings-merge.cjs && node test/command-bridge.cjs && node test/codebuddy-hooks.cjs && node test/skill-content-contract.cjs && node test/init-agent-profiles.cjs && node test/init-report-runtime.cjs && node test/init-output-verbosity.cjs && node test/init-account-binding.cjs && node --test test/usage-contract.test.cjs test/user-config.test.cjs test/device-auth.test.cjs test/usage-runtime-removal.test.cjs skywalk-sdd/usage-reporter.test.cjs skywalk-sdd/usage-reporting.test.cjs && node test/progress-package-artifact.test.cjs"
12
12
  },
13
13
  "keywords": [
14
14
  "kld",
@@ -24,7 +24,7 @@
24
24
  "author": "KLD Team",
25
25
  "license": "MIT",
26
26
  "engines": {
27
- "node": ">=14.0.0"
27
+ "node": ">=14.18.0"
28
28
  },
29
29
  "files": [
30
30
  "bin/",
@@ -39,6 +39,10 @@
39
39
  "skywalk-sdd/openspec-shim.cjs",
40
40
  "skywalk-sdd/ontology/",
41
41
  "skywalk-sdd/apply-worktree-finish.cjs",
42
+ "skywalk-sdd/spec-root.cjs",
43
+ "skywalk-sdd/lib/",
44
+ "skywalk-sdd/kb-upload.cjs",
45
+ "skywalk-sdd/kb-sync-identity.cjs",
42
46
  "README.md"
43
47
  ]
44
48
  }
@@ -11,32 +11,11 @@
11
11
  const fs = require('fs');
12
12
  const path = require('path');
13
13
  const { execFileSync } = require('child_process');
14
+ const { parseArgs } = require('./lib/shared.cjs');
14
15
 
15
16
  const TEMP_DIR_NAMES = ['node_modules', 'dist', '.turbo', '.next', 'coverage', 'build'];
16
17
 
17
- function parseArgs(argv) {
18
- const args = {};
19
- for (let i = 2; i < argv.length; i++) {
20
- const token = argv[i];
21
- if (token === '--') continue;
22
- if (token.startsWith('--')) {
23
- const eq = token.indexOf('=');
24
- if (eq !== -1) {
25
- args[token.slice(2, eq)] = token.slice(eq + 1);
26
- } else {
27
- const key = token.slice(2);
28
- const next = argv[i + 1];
29
- if (next && !next.startsWith('--')) {
30
- args[key] = next;
31
- i++;
32
- } else {
33
- args[key] = true;
34
- }
35
- }
36
- }
37
- }
38
- return args;
39
- }
18
+ // parseArgs 已迁移至 lib/shared.cjs
40
19
 
41
20
  function git(cwd, gitArgs, opts = {}) {
42
21
  return execFileSync('git', gitArgs, {
@@ -6,17 +6,18 @@ const http = require('http');
6
6
  const https = require('https');
7
7
  const { URL } = require('url');
8
8
  const path = require('path');
9
+ const {
10
+ parseArgs,
11
+ requestJson: sharedRequestJson,
12
+ loadKbState,
13
+ resolveKbParams,
14
+ stripBom,
15
+ } = require('./lib/shared.cjs');
9
16
 
10
- function parseArgs(argv) {
11
- const args = {};
12
- for (const item of argv.slice(2)) {
13
- if (!item.startsWith('--')) continue;
14
- const equal = item.indexOf('=');
15
- if (equal < 0) args[item.slice(2)] = true;
16
- else args[item.slice(2, equal)] = item.slice(equal + 1);
17
- }
18
- return args;
19
- }
17
+ // Re-export requestJson for external callers (API compatibility)
18
+ const requestJson = sharedRequestJson;
19
+
20
+ // parseArgs 已迁移至 lib/shared.cjs(统一 5 份实现)
20
21
 
21
22
  function queryFromArgs(args) {
22
23
  if (typeof args.query === 'string' && args.query.trim()) {
@@ -38,60 +39,8 @@ function buildEndpoint(apiBase, spaceId, kbId, mode) {
38
39
  return `${base}/v1/spaces/${space}/knowledge-bases/${kb}/context/match-requirement`;
39
40
  }
40
41
 
41
- function requestJson(url, payload, token, timeoutMs) {
42
- return new Promise((resolve, reject) => {
43
- const target = new URL(url);
44
- const transport = target.protocol === 'https:' ? https : http;
45
- const body = JSON.stringify(payload);
46
- const headers = {
47
- Accept: 'application/json',
48
- 'Content-Type': 'application/json',
49
- 'Content-Length': Buffer.byteLength(body),
50
- };
51
- if (token) headers.Authorization = `Bearer ${token}`;
52
-
53
- const request = transport.request(
54
- {
55
- hostname: target.hostname,
56
- port: target.port || (target.protocol === 'https:' ? 443 : 80),
57
- path: target.pathname + target.search,
58
- method: 'POST',
59
- headers,
60
- timeout: timeoutMs,
61
- },
62
- (response) => {
63
- let responseBody = '';
64
- response.on('data', (chunk) => {
65
- responseBody += chunk;
66
- });
67
- response.on('end', () => {
68
- let parsed;
69
- try {
70
- parsed = responseBody ? JSON.parse(responseBody) : null;
71
- } catch {
72
- reject(new Error(`knowledge base returned invalid JSON (HTTP ${response.statusCode})`));
73
- return;
74
- }
75
- if (response.statusCode >= 400) {
76
- reject(new Error(parsed?.message || `knowledge base HTTP ${response.statusCode}`));
77
- return;
78
- }
79
- // code 字段仅当存在且不为 0 时才视为业务错误(health/ingest 等管理 API 返回 code,
80
- // 但 resolve/search 等 context API 直接返回 data,不包含 code 字段)
81
- if (parsed?.code != null && parsed.code !== 0) {
82
- reject(new Error(parsed?.message || `knowledge base error code ${parsed.code}`));
83
- return;
84
- }
85
- resolve(parsed.data);
86
- });
87
- },
88
- );
89
- request.on('timeout', () => request.destroy(new Error(`knowledge base timeout after ${timeoutMs}ms`)));
90
- request.on('error', reject);
91
- request.write(body);
92
- request.end();
93
- });
94
- }
42
+ // requestJson 已迁移至 lib/shared.cjs(统一 HTTP 请求逻辑)
43
+ // 保留 const requestJson = sharedRequestJson 以维持 API 兼容
95
44
 
96
45
  function compactContext(data, includeCandidates, mode = 'match') {
97
46
  if (includeCandidates) return data;
@@ -157,33 +106,35 @@ function buildPayload(args, mode) {
157
106
 
158
107
  async function retrieveContext(args = parseArgs(process.argv), env = process.env) {
159
108
  // 优先从共享 state 文件读取配置(与 opsx-ontology-query / opsx-kb-ingest 共用)
160
- // 搜索多个可能的 IDE skills 目录(.codebuddy / .claude / .cursor 等)
161
109
  let stateConfig = {};
162
110
  const stateFile = args['state-file'] || env.SDD_KB_STATE_FILE;
163
- const candidatePaths = [];
164
- if (stateFile) candidatePaths.push(stateFile);
165
- // 从 skywalk-sdd 目录向上查找 skills/.shared/kb-state.json
166
- const ideDirs = ['.codebuddy', '.claude', '.cursor', '.vscode'];
167
- for (const ide of ideDirs) {
168
- candidatePaths.push(path.join(__dirname, '..', ide, 'skills', '.shared', 'kb-state.json'));
169
- }
170
- // 也检查 skywalk-sdd 同级的 .shared
171
- candidatePaths.push(path.join(__dirname, '.shared', 'kb-state.json'));
172
- for (const p of candidatePaths) {
111
+
112
+ if (stateFile) {
113
+ // 显式指定路径,直接读取
173
114
  try {
174
- if (fs.existsSync(p)) {
175
- stateConfig = JSON.parse(fs.readFileSync(p, 'utf8'));
176
- break;
115
+ if (fs.existsSync(stateFile)) {
116
+ let raw = fs.readFileSync(stateFile, 'utf8');
117
+ raw = stripBom(raw);
118
+ stateConfig = JSON.parse(raw);
177
119
  }
178
- } catch (_) { /* try next */ }
120
+ } catch (e) {
121
+ console.error(`⚠️ kb-state.json 解析失败 (${stateFile}): ${e.message}`);
122
+ }
123
+ } else {
124
+ // 从 __dirname 逐层向上搜索(复用 shared.cjs 的 loadKbState)
125
+ const { config, warnings } = loadKbState(__dirname, env);
126
+ if (warnings.length > 0) {
127
+ for (const w of warnings) console.error(`⚠️ ${w}`);
128
+ }
129
+ stateConfig = config || {};
179
130
  }
180
131
 
181
- const apiBase = args['api-base'] || stateConfig.api || env.ENGINEERING_KB_API || 'http://localhost:8090/api';
182
- const token = args.token || stateConfig.apiKey || env.ENGINEERING_KB_TOKEN || '';
183
- const spaceId = args['space-id'] || env.ENGINEERING_KB_SPACE_ID ||
184
- (stateConfig.targets && stateConfig.targets.length > 0 ? stateConfig.targets[0].spaceId : '');
185
- const kbId = args['kb-id'] || env.ENGINEERING_KB_KB_ID ||
186
- (stateConfig.targets && stateConfig.targets.length > 0 ? stateConfig.targets[0].kbId : '');
132
+ const { apiBase: kbApiBase, token: kbToken, spaceId: kbSpaceId, kbId: kbKbId, targets: kbTargets } = resolveKbParams(stateConfig, env);
133
+
134
+ const apiBase = args['api-base'] || kbApiBase;
135
+ const token = args.token || kbToken;
136
+ const spaceId = args['space-id'] || kbSpaceId;
137
+ const kbId = args['kb-id'] || kbKbId;
187
138
 
188
139
  // --check-only: 只检查 KB 配置是否就绪,不发起 API 请求
189
140
  // 用于 SDD 各阶段(propose/spec/design/task/check)统一检测 KB 可用性,消除相对路径歧义
@@ -197,13 +148,13 @@ async function retrieveContext(args = parseArgs(process.argv), env = process.env
197
148
  available: false,
198
149
  reason: 'engineering_kb_not_configured',
199
150
  missing,
200
- hint: 'Run opsx-ontology-query Session startup to configure .shared/kb-state.json',
151
+ hint: 'Run /opsx-kb-config to configure kb-state.json (in spec root)',
201
152
  };
202
153
  }
203
154
  return {
204
155
  available: true,
205
156
  api: apiBase,
206
- targets: stateConfig.targets || [],
157
+ targets: kbTargets,
207
158
  };
208
159
  }
209
160