@krisada-m/ksd-intelligence 0.0.0-stage → 1.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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -2
  3. package/dist/adapters/agy/skills.js +252 -0
  4. package/dist/adapters/cli/check-changed.js +3 -0
  5. package/dist/adapters/cli/main.js +1002 -0
  6. package/dist/adapters/cli/policy-bin.js +10 -0
  7. package/dist/adapters/cli/review-verdict.js +3 -0
  8. package/dist/adapters/omp/extension.js +893 -0
  9. package/dist/adapters/omp/skills.js +130 -0
  10. package/dist/adapters/ui/hud.js +318 -0
  11. package/dist/adapters/ui/tree.js +460 -0
  12. package/dist/core/audit/index.js +2 -0
  13. package/dist/core/audit/log.js +505 -0
  14. package/dist/core/audit/summary.js +188 -0
  15. package/dist/core/changes/changes.js +591 -0
  16. package/dist/core/changes/git.js +266 -0
  17. package/dist/core/changes/plan.js +109 -0
  18. package/dist/core/changes/render.js +356 -0
  19. package/dist/core/engine/build.js +178 -0
  20. package/dist/core/engine/child.js +389 -0
  21. package/dist/core/engine/host.js +206 -0
  22. package/dist/core/engine/lock.js +133 -0
  23. package/dist/core/engine/protocol.js +43 -0
  24. package/dist/core/engine/runtime.js +44 -0
  25. package/dist/core/engine/status.js +381 -0
  26. package/dist/core/engine/typescript.js +194 -0
  27. package/dist/core/engine/workspace.js +72 -0
  28. package/dist/core/graph/graph.js +127 -0
  29. package/dist/core/graph/limits.js +16 -0
  30. package/dist/core/impact/query.js +1292 -0
  31. package/dist/core/impact/render.js +590 -0
  32. package/dist/core/impact/session.js +694 -0
  33. package/dist/core/indexing/declarations.js +455 -0
  34. package/dist/core/indexing/differential.js +345 -0
  35. package/dist/core/indexing/doctor.js +120 -0
  36. package/dist/core/indexing/indexer.js +792 -0
  37. package/dist/core/indexing/keys.js +451 -0
  38. package/dist/core/indexing/lexical.js +212 -0
  39. package/dist/core/indexing/packages.js +57 -0
  40. package/dist/core/indexing/program.js +171 -0
  41. package/dist/core/indexing/resolve.js +1004 -0
  42. package/dist/core/indexing/stamp.js +52 -0
  43. package/dist/core/indexing/surface.js +335 -0
  44. package/dist/core/indexing/ui-progress.js +37 -0
  45. package/dist/core/indexing/verify.js +76 -0
  46. package/dist/core/kernel/config.js +383 -0
  47. package/dist/core/kernel/glob.js +105 -0
  48. package/dist/core/kernel/guards.js +4 -0
  49. package/dist/core/kernel/types.js +3 -0
  50. package/dist/core/kernel/verdict.js +142 -0
  51. package/dist/core/knowledge/anchors.js +139 -0
  52. package/dist/core/knowledge/knowledge.js +95 -0
  53. package/dist/core/knowledge/learning.js +102 -0
  54. package/dist/core/knowledge/render.js +76 -0
  55. package/dist/core/knowledge/store.js +109 -0
  56. package/dist/core/knowledge/yaml.js +87 -0
  57. package/dist/core/search/lexical.js +382 -0
  58. package/dist/core/search/render.js +98 -0
  59. package/dist/core/search/segments.js +118 -0
  60. package/dist/core/verify/parse.js +127 -0
  61. package/dist/core/verify/render.js +67 -0
  62. package/dist/core/verify/report.js +40 -0
  63. package/dist/core/verify/revision.js +79 -0
  64. package/dist/core/verify/run.js +117 -0
  65. package/dist/core/verify/store.js +66 -0
  66. package/dist/core/verify/verify.js +173 -0
  67. package/dist/core/workspace/init.js +267 -0
  68. package/dist/core/workspace/probe.js +56 -0
  69. package/dist/core/workspace/scan.js +420 -0
  70. package/dist/index.js +20 -0
  71. package/dist/policy/change-scope.js +500 -0
  72. package/dist/policy/check-changed.js +40 -0
  73. package/dist/policy/config.js +106 -0
  74. package/dist/policy/dist/policy.d.ts +17 -0
  75. package/dist/policy/dist/policy.js +147 -0
  76. package/dist/policy/dist/runtime.d.ts +40 -0
  77. package/dist/policy/dist/runtime.js +75 -0
  78. package/dist/policy/dist/sdlc.d.ts +7 -0
  79. package/dist/policy/dist/sdlc.js +27 -0
  80. package/dist/policy/eslint-rules/index.js +107 -0
  81. package/dist/policy/index.d.ts +2 -0
  82. package/dist/policy/index.js +241 -0
  83. package/dist/policy/package.json +33 -0
  84. package/dist/policy/policy.d.ts +2 -0
  85. package/dist/policy/policy.js +2 -0
  86. package/dist/policy/review-verdict.js +262 -0
  87. package/dist/policy/sdlc.js +2 -0
  88. package/dist/storage/records.js +245 -0
  89. package/dist/storage/sqlite.js +314 -0
  90. package/dist/workflow/catalog.js +69 -0
  91. package/dist/workflow/classify.js +55 -0
  92. package/dist/workflow/loader.js +140 -0
  93. package/dist/workflow/packs.js +469 -0
  94. package/dist/workflow/registry.js +359 -0
  95. package/dist/workflow/render.js +61 -0
  96. package/dist/workflow/router.js +141 -0
  97. package/dist/workflow/sources.js +229 -0
  98. package/dist/workflow/types.js +44 -0
  99. package/dist/workflow/updates.js +532 -0
  100. package/package.json +74 -4
  101. package/scripts/agy-mcp.mjs +27 -0
  102. package/scripts/mcp/stdio.mjs +304 -0
  103. package/scripts/mcp/tools.mjs +451 -0
  104. package/skills/ksd-intelligence/SKILL.md +54 -0
  105. package/skills/matt-sdlc/SKILL.md +42 -0
  106. package/skills/osmani-quality/SKILL.md +38 -0
  107. package/skills/poteto-mode/SKILL.md +40 -0
  108. package/skills/pstack-analysis/SKILL.md +36 -0
  109. package/skills.lock.json +71 -0
  110. package/skills.registry.json +181 -0
@@ -0,0 +1,455 @@
1
+ import { createHash } from 'node:crypto';
2
+ export const MODULE_NAME = '<module>';
3
+ // Pairs TypeScript itself merges into one symbol (ADR 0002: overloads and merged declarations).
4
+ const MERGEABLE = new Set([
5
+ 'function+function',
6
+ 'method+method',
7
+ 'accessor+accessor',
8
+ 'interface+interface',
9
+ 'class+interface',
10
+ 'interface+class',
11
+ 'namespace+namespace',
12
+ 'namespace+function',
13
+ 'function+namespace',
14
+ 'namespace+class',
15
+ 'class+namespace',
16
+ 'namespace+enum',
17
+ 'enum+namespace',
18
+ 'enum+enum',
19
+ 'var+var',
20
+ ]);
21
+ const MAX_OBJECT_DEPTH = 3;
22
+ function lineOf(sf, pos) {
23
+ return sf.getLineAndCharacterOfPosition(pos).line + 1;
24
+ }
25
+ export function spanOf(ts, sf, node) {
26
+ return [lineOf(sf, node.getStart(sf)), lineOf(sf, node.getEnd())];
27
+ }
28
+ /** The text of a member or property name, or null for a computed name that is not a literal. */
29
+ function nameText(ts, name) {
30
+ if (name === undefined)
31
+ return null;
32
+ if (ts.isIdentifier(name) || ts.isPrivateIdentifier(name))
33
+ return name.text;
34
+ if (ts.isStringLiteralLike(name) || ts.isNumericLiteral(name))
35
+ return name.text;
36
+ if (ts.isComputedPropertyName(name)) {
37
+ const expr = name.expression;
38
+ if (ts.isStringLiteralLike(expr) || ts.isNumericLiteral(expr))
39
+ return expr.text;
40
+ }
41
+ return null;
42
+ }
43
+ function hasModifier(ts, node, kind) {
44
+ return ts.canHaveModifiers(node) && (ts.getModifiers(node) ?? []).some((m) => m.kind === kind);
45
+ }
46
+ function unwrap(ts, expr) {
47
+ let current = expr;
48
+ while (ts.isParenthesizedExpression(current) ||
49
+ ts.isAsExpression(current) ||
50
+ ts.isSatisfiesExpression(current) ||
51
+ ts.isTypeAssertionExpression(current) ||
52
+ ts.isNonNullExpression(current)) {
53
+ current = current.expression;
54
+ }
55
+ return current;
56
+ }
57
+ /** `exports.x`, `module.exports.x` → `x`; `module.exports` → ''; anything else → null. */
58
+ function cjsExportName(ts, target) {
59
+ if (!ts.isPropertyAccessExpression(target))
60
+ return null;
61
+ const object = target.expression;
62
+ if (ts.isIdentifier(object) && object.text === 'exports')
63
+ return target.name.text;
64
+ if (ts.isIdentifier(object) && object.text === 'module' && target.name.text === 'exports') {
65
+ return '';
66
+ }
67
+ const viaModuleExports = ts.isPropertyAccessExpression(object) &&
68
+ ts.isIdentifier(object.expression) &&
69
+ object.expression.text === 'module' &&
70
+ object.name.text === 'exports';
71
+ return viaModuleExports ? target.name.text : null;
72
+ }
73
+ function isFunctionValue(ts, expr) {
74
+ return expr !== undefined && (ts.isArrowFunction(expr) || ts.isFunctionExpression(expr));
75
+ }
76
+ /** Signature text without bodies: what callers depend on syntactically. */
77
+ export function signatureText(ts, sf, node) {
78
+ const text = sf.text;
79
+ const start = node.getStart(sf);
80
+ if (ts.isClassDeclaration(node))
81
+ return text.slice(start, node.members.pos);
82
+ if (ts.isModuleDeclaration(node))
83
+ return text.slice(start, node.name.getEnd());
84
+ if (ts.isFunctionLike(node) && 'body' in node && node.body !== undefined) {
85
+ return text.slice(start, node.body.getStart(sf));
86
+ }
87
+ let value;
88
+ if (ts.isVariableDeclaration(node) || ts.isPropertyAssignment(node)) {
89
+ value = node.initializer && unwrap(ts, node.initializer);
90
+ }
91
+ else if (ts.isBinaryExpression(node)) {
92
+ value = unwrap(ts, node.right);
93
+ }
94
+ if (isFunctionValue(ts, value))
95
+ return text.slice(start, value.body.getStart(sf));
96
+ if (value !== undefined && ts.isObjectLiteralExpression(value)) {
97
+ return text.slice(start, value.getStart(sf));
98
+ }
99
+ return text.slice(start, node.getEnd());
100
+ }
101
+ function variableKind(ts, init) {
102
+ if (isFunctionValue(ts, init))
103
+ return 'function';
104
+ if (init !== undefined && ts.isClassExpression(init))
105
+ return 'class';
106
+ return 'variable';
107
+ }
108
+ function mergeKindOf(ts, node) {
109
+ if (ts.isFunctionDeclaration(node))
110
+ return 'function';
111
+ if (ts.isMethodDeclaration(node) || ts.isMethodSignature(node))
112
+ return 'method';
113
+ if (ts.isGetAccessorDeclaration(node) || ts.isSetAccessorDeclaration(node)) {
114
+ return 'accessor';
115
+ }
116
+ if (ts.isInterfaceDeclaration(node))
117
+ return 'interface';
118
+ if (ts.isClassDeclaration(node))
119
+ return 'class';
120
+ if (ts.isModuleDeclaration(node))
121
+ return 'namespace';
122
+ if (ts.isEnumDeclaration(node))
123
+ return 'enum';
124
+ if (ts.isVariableDeclaration(node) &&
125
+ ts.isVariableDeclarationList(node.parent) &&
126
+ (node.parent.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const)) === 0) {
127
+ return 'var';
128
+ }
129
+ return 'other';
130
+ }
131
+ /**
132
+ * The indexed declarations of one file with their stable keys (ADR 0002, ADR 0003). Pure: depends
133
+ * on the file's syntax tree only, so the extract-local cache can key it by content hash.
134
+ */
135
+ export function fileDeclarations(ts, sf, file) {
136
+ const entries = [];
137
+ const exportedNames = new Set();
138
+ const add = (name, kind, node, exported, aliases = []) => {
139
+ const hasBody = 'body' in node && node.body !== undefined;
140
+ entries.push({ name, kind, merge: mergeKindOf(ts, node), node, aliases, exported, hasBody });
141
+ };
142
+ const objectMembers = (literal, owner, depth, exported) => {
143
+ for (const property of literal.properties) {
144
+ const name = nameText(ts, property.name);
145
+ if (name === null)
146
+ continue;
147
+ const qualified = `${owner}.${name}`;
148
+ if (ts.isPropertyAssignment(property)) {
149
+ const init = unwrap(ts, property.initializer);
150
+ add(qualified, isFunctionValue(ts, init) ? 'method' : 'property', property, exported);
151
+ if (ts.isObjectLiteralExpression(init) && depth < MAX_OBJECT_DEPTH) {
152
+ objectMembers(init, qualified, depth + 1, exported);
153
+ }
154
+ }
155
+ else if (ts.isShorthandPropertyAssignment(property)) {
156
+ add(qualified, 'property', property, exported);
157
+ }
158
+ else if (ts.isMethodDeclaration(property)) {
159
+ add(qualified, 'method', property, exported);
160
+ }
161
+ else if (ts.isGetAccessorDeclaration(property) || ts.isSetAccessorDeclaration(property)) {
162
+ add(qualified, 'accessor', property, exported);
163
+ }
164
+ }
165
+ };
166
+ const classMembers = (members, owner, exported) => {
167
+ const instanceNames = new Set();
168
+ for (const member of members) {
169
+ const name = nameText(ts, member.name);
170
+ if (name !== null && !hasModifier(ts, member, ts.SyntaxKind.StaticKeyword)) {
171
+ instanceNames.add(name);
172
+ }
173
+ }
174
+ for (const member of members) {
175
+ if (ts.isConstructorDeclaration(member)) {
176
+ for (const parameter of member.parameters) {
177
+ const isProperty = ts.canHaveModifiers(parameter) &&
178
+ (ts.getModifiers(parameter) ?? []).some((m) => m.kind === ts.SyntaxKind.PublicKeyword ||
179
+ m.kind === ts.SyntaxKind.PrivateKeyword ||
180
+ m.kind === ts.SyntaxKind.ProtectedKeyword ||
181
+ m.kind === ts.SyntaxKind.ReadonlyKeyword);
182
+ if (isProperty && ts.isIdentifier(parameter.name)) {
183
+ add(`${owner}.${parameter.name.text}`, 'property', parameter, exported);
184
+ }
185
+ }
186
+ continue;
187
+ }
188
+ const name = nameText(ts, member.name);
189
+ if (name === null)
190
+ continue;
191
+ const isStatic = hasModifier(ts, member, ts.SyntaxKind.StaticKeyword);
192
+ const qualified = isStatic && instanceNames.has(name) ? `${owner}.static:${name}` : `${owner}.${name}`;
193
+ if (ts.isMethodDeclaration(member))
194
+ add(qualified, 'method', member, exported);
195
+ else if (ts.isPropertyDeclaration(member))
196
+ add(qualified, 'property', member, exported);
197
+ else if (ts.isGetAccessorDeclaration(member) || ts.isSetAccessorDeclaration(member)) {
198
+ add(qualified, 'accessor', member, exported);
199
+ }
200
+ }
201
+ };
202
+ const typeMembers = (members, owner, exported) => {
203
+ for (const member of members) {
204
+ const name = nameText(ts, member.name);
205
+ if (name === null)
206
+ continue;
207
+ const qualified = `${owner}.${name}`;
208
+ if (ts.isMethodSignature(member))
209
+ add(qualified, 'method', member, exported);
210
+ else if (ts.isPropertySignature(member))
211
+ add(qualified, 'property', member, exported);
212
+ else if (ts.isGetAccessorDeclaration(member) || ts.isSetAccessorDeclaration(member)) {
213
+ add(qualified, 'accessor', member, exported);
214
+ }
215
+ }
216
+ };
217
+ const bindingNames = (name, prefix, exported) => {
218
+ if (ts.isIdentifier(name))
219
+ return;
220
+ for (const element of name.elements) {
221
+ if (ts.isOmittedExpression(element))
222
+ continue;
223
+ if (ts.isIdentifier(element.name))
224
+ add(prefix + element.name.text, 'variable', element, exported);
225
+ else
226
+ bindingNames(element.name, prefix, exported);
227
+ }
228
+ };
229
+ const statements = (list, prefix, inExported) => {
230
+ for (const statement of list) {
231
+ const exportModifier = hasModifier(ts, statement, ts.SyntaxKind.ExportKeyword);
232
+ const exported = prefix === '' ? exportModifier : inExported && exportModifier;
233
+ const isDefault = hasModifier(ts, statement, ts.SyntaxKind.DefaultKeyword);
234
+ if (ts.isFunctionDeclaration(statement)) {
235
+ const name = statement.name?.text ?? (isDefault ? 'default' : null);
236
+ if (name !== null)
237
+ add(prefix + name, 'function', statement, exported);
238
+ }
239
+ else if (ts.isClassDeclaration(statement)) {
240
+ const name = statement.name?.text ?? (isDefault ? 'default' : null);
241
+ if (name === null)
242
+ continue;
243
+ add(prefix + name, 'class', statement, exported);
244
+ classMembers(statement.members, prefix + name, exported);
245
+ }
246
+ else if (ts.isInterfaceDeclaration(statement)) {
247
+ add(prefix + statement.name.text, 'interface', statement, exported);
248
+ typeMembers(statement.members, prefix + statement.name.text, exported);
249
+ }
250
+ else if (ts.isTypeAliasDeclaration(statement)) {
251
+ add(prefix + statement.name.text, 'type', statement, exported);
252
+ }
253
+ else if (ts.isEnumDeclaration(statement)) {
254
+ const owner = prefix + statement.name.text;
255
+ add(owner, 'enum', statement, exported);
256
+ for (const member of statement.members) {
257
+ const name = nameText(ts, member.name);
258
+ if (name !== null)
259
+ add(`${owner}.${name}`, 'enum-member', member, exported);
260
+ }
261
+ }
262
+ else if (ts.isModuleDeclaration(statement)) {
263
+ moduleDeclaration(statement, prefix, exported);
264
+ }
265
+ else if (ts.isVariableStatement(statement)) {
266
+ for (const declaration of statement.declarationList.declarations) {
267
+ if (!ts.isIdentifier(declaration.name)) {
268
+ bindingNames(declaration.name, prefix, exported);
269
+ continue;
270
+ }
271
+ const name = prefix + declaration.name.text;
272
+ const init = declaration.initializer && unwrap(ts, declaration.initializer);
273
+ add(name, variableKind(ts, init), declaration, exported);
274
+ if (init !== undefined && ts.isObjectLiteralExpression(init)) {
275
+ objectMembers(init, name, 1, exported);
276
+ }
277
+ if (init !== undefined && ts.isClassExpression(init)) {
278
+ classMembers(init.members, name, exported);
279
+ }
280
+ }
281
+ }
282
+ else if (ts.isExportAssignment(statement) && prefix === '') {
283
+ const expr = unwrap(ts, statement.expression);
284
+ if (ts.isIdentifier(expr))
285
+ exportedNames.add(expr.text);
286
+ else
287
+ add('default', 'default', statement, true);
288
+ }
289
+ else if (ts.isExportDeclaration(statement) && statement.moduleSpecifier === undefined) {
290
+ const clause = statement.exportClause;
291
+ if (clause !== undefined && ts.isNamedExports(clause)) {
292
+ for (const element of clause.elements) {
293
+ exportedNames.add((element.propertyName ?? element.name).text);
294
+ }
295
+ }
296
+ }
297
+ else if (ts.isExpressionStatement(statement) && prefix === '') {
298
+ commonJs(statement.expression);
299
+ }
300
+ }
301
+ };
302
+ const commonJs = (expression) => {
303
+ if (!ts.isBinaryExpression(expression))
304
+ return;
305
+ if (expression.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
306
+ return;
307
+ const name = cjsExportName(ts, expression.left);
308
+ if (name === null)
309
+ return;
310
+ const value = unwrap(ts, expression.right);
311
+ if (name !== '') {
312
+ if (ts.isIdentifier(value) && value.text === name) {
313
+ exportedNames.add(name);
314
+ return;
315
+ }
316
+ add(name, variableKind(ts, value), expression, true, [expression.left]);
317
+ if (ts.isObjectLiteralExpression(value))
318
+ objectMembers(value, name, 1, true);
319
+ return;
320
+ }
321
+ // module.exports = …
322
+ if (ts.isIdentifier(value)) {
323
+ exportedNames.add(value.text);
324
+ return;
325
+ }
326
+ if (!ts.isObjectLiteralExpression(value)) {
327
+ add('default', 'default', expression, true);
328
+ return;
329
+ }
330
+ for (const property of value.properties) {
331
+ const memberName = nameText(ts, property.name);
332
+ if (memberName === null)
333
+ continue;
334
+ if (ts.isShorthandPropertyAssignment(property)) {
335
+ exportedNames.add(memberName);
336
+ continue;
337
+ }
338
+ if (ts.isPropertyAssignment(property)) {
339
+ const init = unwrap(ts, property.initializer);
340
+ if (ts.isIdentifier(init) && init.text === memberName) {
341
+ exportedNames.add(memberName);
342
+ continue;
343
+ }
344
+ add(memberName, variableKind(ts, init), property, true);
345
+ }
346
+ else if (ts.isMethodDeclaration(property)) {
347
+ add(memberName, 'function', property, true);
348
+ }
349
+ }
350
+ };
351
+ const moduleDeclaration = (statement, prefix, exported) => {
352
+ if (!ts.isIdentifier(statement.name)) {
353
+ // `declare global { … }`: its declarations are this file's; `declare module "x"` is ambient.
354
+ const isGlobal = (statement.flags & ts.NodeFlags.GlobalAugmentation) !== 0;
355
+ if (isGlobal && statement.body !== undefined && ts.isModuleBlock(statement.body)) {
356
+ statements(statement.body.statements, '', true);
357
+ }
358
+ return;
359
+ }
360
+ const name = prefix + statement.name.text;
361
+ add(name, 'namespace', statement, exported);
362
+ const body = statement.body;
363
+ if (body === undefined)
364
+ return;
365
+ if (ts.isModuleBlock(body))
366
+ statements(body.statements, `${name}.`, exported);
367
+ else if (ts.isModuleDeclaration(body))
368
+ moduleDeclaration(body, `${name}.`, exported);
369
+ };
370
+ statements(sf.statements, '', true);
371
+ // Group same-name entries TypeScript merges; other repeats get `~2`, `~3` in source order.
372
+ const groups = [];
373
+ const byName = new Map();
374
+ for (const entry of entries) {
375
+ const existing = byName.get(entry.name) ?? [];
376
+ const target = existing.find((group) => group.entries.every((other) => MERGEABLE.has(`${other.merge}+${entry.merge}`)));
377
+ if (target !== undefined) {
378
+ target.entries.push(entry);
379
+ continue;
380
+ }
381
+ const suffixed = existing.length === 0 ? entry.name : `${entry.name}~${existing.length + 1}`;
382
+ const group = { name: suffixed, entries: [entry] };
383
+ existing.push(group);
384
+ byName.set(entry.name, existing);
385
+ groups.push(group);
386
+ }
387
+ const keyOf = new Map();
388
+ const nodesOf = new Map();
389
+ const moduleKey = `${file}#${MODULE_NAME}`;
390
+ const [, lastLine] = spanOf(ts, sf, sf);
391
+ const declarations = [
392
+ {
393
+ key: moduleKey,
394
+ file,
395
+ name: MODULE_NAME,
396
+ simple: MODULE_NAME,
397
+ kind: 'module',
398
+ exported: false,
399
+ startLine: 1,
400
+ endLine: Math.max(1, lastLine),
401
+ otherSpans: [],
402
+ sigHash: '',
403
+ },
404
+ ];
405
+ for (const group of groups) {
406
+ const key = `${file}#${group.name}`;
407
+ // An overload set's span is its implementation; any other merge's span is its first declaration.
408
+ const overloads = group.entries.every((e) => e.merge === 'function' || e.merge === 'method');
409
+ const primary = (overloads ? group.entries.find((entry) => entry.hasBody) : undefined) ?? group.entries[0];
410
+ if (primary === undefined)
411
+ continue;
412
+ const [startLine, endLine] = spanOf(ts, sf, primary.node);
413
+ const otherSpans = group.entries
414
+ .filter((entry) => entry !== primary)
415
+ .map((entry) => spanOf(ts, sf, entry.node).join('-'));
416
+ const signature = group.entries
417
+ .map((entry) => signatureText(ts, sf, entry.node).replace(/\s+/g, ' ').trim())
418
+ .join('\n');
419
+ const segments = group.name.split('.');
420
+ const last = segments[segments.length - 1] ?? group.name;
421
+ declarations.push({
422
+ key,
423
+ file,
424
+ name: group.name,
425
+ simple: last.replace(/^static:/, '').replace(/~\d+$/, ''),
426
+ kind: primary.kind,
427
+ exported: group.entries.some((entry) => entry.exported) || exportedNames.has(group.name),
428
+ startLine,
429
+ endLine,
430
+ otherSpans,
431
+ sigHash: createHash('sha256')
432
+ .update(`${primary.kind}\n${signature}`)
433
+ .digest('hex')
434
+ .slice(0, 16),
435
+ });
436
+ nodesOf.set(key, group.entries.map((entry) => entry.node));
437
+ for (const entry of group.entries) {
438
+ keyOf.set(entry.node, key);
439
+ for (const alias of entry.aliases)
440
+ keyOf.set(alias, key);
441
+ }
442
+ }
443
+ return { declarations, keyOf, nodesOf, moduleKey };
444
+ }
445
+ /** The key of the nearest enclosing indexed declaration of a use site (ADR 0002). */
446
+ export function enclosingKey(node, declarations) {
447
+ let current = node.parent;
448
+ while (current !== undefined) {
449
+ const key = declarations.keyOf.get(current);
450
+ if (key !== undefined)
451
+ return key;
452
+ current = current.parent;
453
+ }
454
+ return declarations.moduleKey;
455
+ }