@fabersep/atlas 0.0.0-stage → 0.1.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 (143) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +202 -0
  3. package/README.md +139 -2
  4. package/dist/packs/csharp/calls.d.ts +4 -0
  5. package/dist/packs/csharp/calls.js +167 -0
  6. package/dist/packs/csharp/declarations.d.ts +4 -0
  7. package/dist/packs/csharp/declarations.js +142 -0
  8. package/dist/packs/csharp/pack.d.ts +2 -0
  9. package/dist/packs/csharp/pack.js +39 -0
  10. package/dist/packs/csharp/resolve.d.ts +2 -0
  11. package/dist/packs/csharp/resolve.js +35 -0
  12. package/dist/packs/csharp/signals.d.ts +7 -0
  13. package/dist/packs/csharp/signals.js +143 -0
  14. package/dist/packs/dart/calls.d.ts +4 -0
  15. package/dist/packs/dart/calls.js +130 -0
  16. package/dist/packs/dart/declarations.d.ts +11 -0
  17. package/dist/packs/dart/declarations.js +79 -0
  18. package/dist/packs/dart/members.d.ts +4 -0
  19. package/dist/packs/dart/members.js +62 -0
  20. package/dist/packs/dart/pack.d.ts +2 -0
  21. package/dist/packs/dart/pack.js +37 -0
  22. package/dist/packs/dart/resolve.d.ts +2 -0
  23. package/dist/packs/dart/resolve.js +32 -0
  24. package/dist/packs/index.d.ts +3 -0
  25. package/dist/packs/index.js +8 -0
  26. package/dist/packs/json/pack.d.ts +2 -0
  27. package/dist/packs/json/pack.js +27 -0
  28. package/dist/packs/msbuild/pack.d.ts +2 -0
  29. package/dist/packs/msbuild/pack.js +75 -0
  30. package/dist/packs/msbuild/xml.d.ts +16 -0
  31. package/dist/packs/msbuild/xml.js +123 -0
  32. package/dist/packs/typescript/calls.d.ts +4 -0
  33. package/dist/packs/typescript/calls.js +201 -0
  34. package/dist/packs/typescript/declarations.d.ts +9 -0
  35. package/dist/packs/typescript/declarations.js +74 -0
  36. package/dist/packs/typescript/members.d.ts +4 -0
  37. package/dist/packs/typescript/members.js +92 -0
  38. package/dist/packs/typescript/pack.d.ts +2 -0
  39. package/dist/packs/typescript/pack.js +53 -0
  40. package/dist/packs/typescript/resolve.d.ts +2 -0
  41. package/dist/packs/typescript/resolve.js +68 -0
  42. package/dist/packs/typescript/signals.d.ts +7 -0
  43. package/dist/packs/typescript/signals.js +186 -0
  44. package/dist/packs/yaml/pack.d.ts +2 -0
  45. package/dist/packs/yaml/pack.js +35 -0
  46. package/dist/src/cli.d.ts +2 -0
  47. package/dist/src/cli.js +371 -0
  48. package/dist/src/graph/build.d.ts +17 -0
  49. package/dist/src/graph/build.js +41 -0
  50. package/dist/src/graph/metrics.d.ts +12 -0
  51. package/dist/src/graph/metrics.js +75 -0
  52. package/dist/src/graph/topology.d.ts +5 -0
  53. package/dist/src/graph/topology.js +54 -0
  54. package/dist/src/health/compare.d.ts +2 -0
  55. package/dist/src/health/compare.js +38 -0
  56. package/dist/src/health/duplicates.d.ts +11 -0
  57. package/dist/src/health/duplicates.js +66 -0
  58. package/dist/src/health/health.d.ts +12 -0
  59. package/dist/src/health/health.js +94 -0
  60. package/dist/src/health/types.d.ts +101 -0
  61. package/dist/src/health/types.js +5 -0
  62. package/dist/src/index.d.ts +23 -0
  63. package/dist/src/index.js +20 -0
  64. package/dist/src/init/init.d.ts +73 -0
  65. package/dist/src/init/init.js +305 -0
  66. package/dist/src/init/scout.d.ts +45 -0
  67. package/dist/src/init/scout.js +208 -0
  68. package/dist/src/jsonc.d.ts +5 -0
  69. package/dist/src/jsonc.js +34 -0
  70. package/dist/src/mcp/server.d.ts +266 -0
  71. package/dist/src/mcp/server.js +414 -0
  72. package/dist/src/metrics/doctor.d.ts +15 -0
  73. package/dist/src/metrics/doctor.js +125 -0
  74. package/dist/src/metrics/log.d.ts +43 -0
  75. package/dist/src/metrics/log.js +101 -0
  76. package/dist/src/metrics/stats.d.ts +43 -0
  77. package/dist/src/metrics/stats.js +172 -0
  78. package/dist/src/model.d.ts +178 -0
  79. package/dist/src/model.js +2 -0
  80. package/dist/src/outputs.d.ts +16 -0
  81. package/dist/src/outputs.js +48 -0
  82. package/dist/src/packs/calls.d.ts +9 -0
  83. package/dist/src/packs/calls.js +119 -0
  84. package/dist/src/packs/dataShape.d.ts +6 -0
  85. package/dist/src/packs/dataShape.js +54 -0
  86. package/dist/src/packs/pack.d.ts +51 -0
  87. package/dist/src/packs/pack.js +3 -0
  88. package/dist/src/packs/packFiles.d.ts +5 -0
  89. package/dist/src/packs/packFiles.js +12 -0
  90. package/dist/src/packs/symbols.d.ts +39 -0
  91. package/dist/src/packs/symbols.js +98 -0
  92. package/dist/src/packs/treeSitter.d.ts +8 -0
  93. package/dist/src/packs/treeSitter.js +107 -0
  94. package/dist/src/queries/flow.d.ts +42 -0
  95. package/dist/src/queries/flow.js +391 -0
  96. package/dist/src/queries/map.d.ts +28 -0
  97. package/dist/src/queries/map.js +102 -0
  98. package/dist/src/queries/neighborhood.d.ts +35 -0
  99. package/dist/src/queries/neighborhood.js +60 -0
  100. package/dist/src/scan/audit.d.ts +2 -0
  101. package/dist/src/scan/audit.js +41 -0
  102. package/dist/src/scan/records.d.ts +12 -0
  103. package/dist/src/scan/records.js +42 -0
  104. package/dist/src/scan/resolveImports.d.ts +3 -0
  105. package/dist/src/scan/resolveImports.js +47 -0
  106. package/dist/src/scan/roles.d.ts +5 -0
  107. package/dist/src/scan/roles.js +87 -0
  108. package/dist/src/scan/scan.d.ts +24 -0
  109. package/dist/src/scan/scan.js +72 -0
  110. package/dist/src/text/briefs.d.ts +13 -0
  111. package/dist/src/text/briefs.js +43 -0
  112. package/dist/src/text/collapse.d.ts +10 -0
  113. package/dist/src/text/collapse.js +58 -0
  114. package/dist/src/text/declarations.d.ts +12 -0
  115. package/dist/src/text/declarations.js +120 -0
  116. package/dist/src/text/structure.d.ts +2 -0
  117. package/dist/src/text/structure.js +15 -0
  118. package/dist/src/text/tree.d.ts +20 -0
  119. package/dist/src/text/tree.js +49 -0
  120. package/dist/src/tokens.d.ts +4 -0
  121. package/dist/src/tokens.js +9 -0
  122. package/dist/src/version.d.ts +10 -0
  123. package/dist/src/version.js +11 -0
  124. package/dist/src/walk/ignoreRules.d.ts +17 -0
  125. package/dist/src/walk/ignoreRules.js +72 -0
  126. package/dist/src/walk/walk.d.ts +11 -0
  127. package/dist/src/walk/walk.js +29 -0
  128. package/grammars/LICENSE-tree-sitter-dart +20 -0
  129. package/grammars/README.md +11 -0
  130. package/grammars/tree-sitter-dart.wasm +0 -0
  131. package/package.json +68 -4
  132. package/packs/csharp/README.md +9 -0
  133. package/packs/csharp/imports.scm +3 -0
  134. package/packs/csharp/symbols.scm +17 -0
  135. package/packs/dart/imports.scm +5 -0
  136. package/packs/dart/symbols.scm +13 -0
  137. package/packs/msbuild/README.md +11 -0
  138. package/packs/typescript/exports.scm +16 -0
  139. package/packs/typescript/imports.scm +9 -0
  140. package/packs/typescript/symbols.scm +19 -0
  141. package/schema/ast_code_map.schema.json +144 -0
  142. package/schema/schema-lock.json +7 -0
  143. package/schema/topology.schema.json +87 -0
@@ -0,0 +1,62 @@
1
+ import { oneLine } from '../../src/tokens.js';
2
+ import { childOfType, declared, hasToken } from '../../src/packs/symbols.js';
3
+ import { MODIFIERS, nameFields, signatureFields, withBody } from './declarations.js';
4
+ /** Members of Dart classes, mixins, extensions and enums. */
5
+ /** Flutter framework callbacks. */
6
+ const LIFECYCLE = new Set([
7
+ 'build', 'initState', 'dispose', 'didUpdateWidget', 'didChangeDependencies', 'createState', 'deactivate',
8
+ 'activate', 'reassemble', 'debugFillProperties', 'createElement', 'createRenderObject', 'updateRenderObject',
9
+ ]);
10
+ const CONSTRUCTORS = new Set([
11
+ 'constructor_signature', 'constant_constructor_signature', 'factory_constructor_signature',
12
+ 'redirecting_factory_constructor_signature',
13
+ ]);
14
+ const SIGNATURE_KIND = {
15
+ function_signature: 'method', getter_signature: 'getter', setter_signature: 'setter', operator_signature: 'method',
16
+ };
17
+ function flags(wrapper, name) {
18
+ return { ...(hasToken(wrapper, 'static') ? { static: true } : {}), ...(LIFECYCLE.has(name) ? { lifecycle: true } : {}) };
19
+ }
20
+ /** `Product.fromJson(...)` is the constructor `Product.fromJson`; `SettingsService._()` is private. */
21
+ function constructor(wrapper, sig) {
22
+ const name = sig.children.filter((c) => c?.type === 'identifier').map((c) => c.text).join('.');
23
+ return declared(wrapper, { kind: 'constructor', signature: oneLine(wrapper.text.slice(0, sig.endIndex - wrapper.startIndex)), ...nameFields(name) }, withBody(wrapper));
24
+ }
25
+ function operator(wrapper, sig) {
26
+ const symbol = childOfType(sig, 'binary_operator', 'unary_operator')?.text ?? '';
27
+ return declared(wrapper, { kind: 'method', signature: oneLine(wrapper.text), name: `operator ${symbol}`, exported: true, visibility: 'public' }, withBody(wrapper));
28
+ }
29
+ /** A method, getter, setter or operator (with a body when the wrapper is a `method_signature`). */
30
+ function callable(wrapper, sig, source) {
31
+ if (sig.type === 'operator_signature')
32
+ return operator(wrapper, sig);
33
+ const fields = signatureFields(sig, source);
34
+ return declared(wrapper, { kind: SIGNATURE_KIND[sig.type], ...fields, signature: oneLine(wrapper.text), ...flags(wrapper, fields.name) }, withBody(wrapper));
35
+ }
36
+ /** `final String a, b = 'x';` gives the fields `a` and `b`, each with the declaration's modifiers and type. */
37
+ function fields(declaration, list, source) {
38
+ const prefix = oneLine(source.slice(declaration.startIndex, list.startIndex));
39
+ const type = prefix.replace(MODIFIERS, '').replace(/^(final|const|late|var)$/, '').trim();
40
+ return list.namedChildren
41
+ .filter((n) => !!n && (n.type === 'initialized_identifier' || n.type === 'static_final_declaration'))
42
+ .map((n) => {
43
+ const name = childOfType(n, 'identifier')?.text ?? '';
44
+ return declared(n, { kind: 'field', signature: `${prefix} ${name}`, ...(type ? { type } : {}), ...nameFields(name), ...flags(declaration, name) });
45
+ });
46
+ }
47
+ function enumConstant(node) {
48
+ const name = childOfType(node, 'identifier')?.text ?? node.text;
49
+ return declared(node, { kind: 'enumMember', signature: oneLine(node.text), name, exported: true, visibility: 'public' });
50
+ }
51
+ /** A member declaration (a `declaration` or `method_signature` wrapper, or an enum constant). */
52
+ export function describeMember(node, source) {
53
+ if (node.type === 'enum_constant')
54
+ return [enumConstant(node)];
55
+ const list = childOfType(node, 'initialized_identifier_list', 'static_final_declaration_list');
56
+ if (list)
57
+ return fields(node, list, source);
58
+ const sig = node.namedChildren.find((c) => !!c && (CONSTRUCTORS.has(c.type) || c.type in SIGNATURE_KIND));
59
+ if (!sig)
60
+ return [];
61
+ return [CONSTRUCTORS.has(sig.type) ? constructor(node, sig) : callable(node, sig, source)];
62
+ }
@@ -0,0 +1,2 @@
1
+ import type { LanguagePack } from '../../src/packs/pack.js';
2
+ export declare const dartPack: LanguagePack;
@@ -0,0 +1,37 @@
1
+ import { nest, withNesting } from '../../src/packs/symbols.js';
2
+ import { query, withTree } from '../../src/packs/treeSitter.js';
3
+ import { readPackFile } from '../../src/packs/packFiles.js';
4
+ import { withDartCalls } from './calls.js';
5
+ import { describeTopLevel } from './declarations.js';
6
+ import { describeMember } from './members.js';
7
+ import { resolveDart } from './resolve.js';
8
+ /** Dart and Flutter (Tree-sitter grammar `dart`). */
9
+ const QUERIES = { symbols: readPackFile(import.meta.url, 'symbols.scm'), imports: readPackFile(import.meta.url, 'imports.scm') };
10
+ /** The statements and expressions that open a nesting level (code health, FR-07). */
11
+ const BLOCKS = new Set(['if_statement', 'for_statement', 'while_statement', 'do_statement', 'switch_statement', 'switch_expression', 'try_statement']);
12
+ const MEMBER_PARENTS = new Set(['class_body', 'extension_body', 'enum_body']);
13
+ function captured(language, key, root) {
14
+ return query(language, `dart-${key}`, QUERIES[key]).captures(root).filter((c) => !c.name.startsWith('_')).map((c) => c.node);
15
+ }
16
+ function imports(language, root) {
17
+ return captured(language, 'imports', root).map((node) => ({ specifier: node.text.replace(/^r?(['"]{1,3})|(['"]{1,3})$/g, ''), line: node.startPosition.row + 1 }));
18
+ }
19
+ function symbols(language, root, source) {
20
+ const found = [];
21
+ for (const node of captured(language, 'symbols', root)) {
22
+ if (MEMBER_PARENTS.has(node.parent?.type ?? ''))
23
+ found.push(...describeMember(node, source));
24
+ else {
25
+ const top = describeTopLevel(node, source);
26
+ if (top)
27
+ found.push(top);
28
+ }
29
+ }
30
+ return nest(withDartCalls(withNesting(found, root, BLOCKS), root));
31
+ }
32
+ export const dartPack = {
33
+ id: 'dart',
34
+ claims: (file) => file.endsWith('.dart'),
35
+ parse: ({ content }) => withTree('dart', content, (root, language) => ({ symbols: symbols(language, root, content), imports: imports(language, root) })),
36
+ resolve: resolveDart,
37
+ };
@@ -0,0 +1,2 @@
1
+ import type { Resolution, ResolveInput } from '../../src/packs/pack.js';
2
+ export declare function resolveDart({ from, raw, project }: ResolveInput): Resolution;
@@ -0,0 +1,32 @@
1
+ import path from 'node:path';
2
+ import YAML from 'yaml';
3
+ /** Resolves a Dart URI: `dart:` libraries, the project's own `package:` URIs (its `lib/` folder), other packages, relative files. */
4
+ const ownNames = new WeakMap();
5
+ /** The `name` of the scan root's pubspec.yaml; an unreadable pubspec gives no name. */
6
+ function ownPackage(project) {
7
+ if (!ownNames.has(project)) {
8
+ const text = project.read('pubspec.yaml');
9
+ let name;
10
+ try {
11
+ name = text ? YAML.parse(text)?.name : undefined;
12
+ }
13
+ catch {
14
+ name = undefined; // The pubspec's own parse error is recorded against pubspec.yaml by the YAML pack.
15
+ }
16
+ ownNames.set(project, typeof name === 'string' ? name : undefined);
17
+ }
18
+ return ownNames.get(project);
19
+ }
20
+ function file(target, project) {
21
+ const clean = path.posix.normalize(target);
22
+ return !clean.startsWith('..') && project.has(clean) ? { kind: 'file', target: clean } : { kind: 'unresolved' };
23
+ }
24
+ export function resolveDart({ from, raw, project }) {
25
+ const uri = raw.specifier;
26
+ if (uri.startsWith('dart:'))
27
+ return { kind: 'builtin' };
28
+ const pkg = /^package:([^/]+)\/(.+)$/.exec(uri);
29
+ if (pkg)
30
+ return pkg[1] === ownPackage(project) ? file(`lib/${pkg[2]}`, project) : { kind: 'package', package: pkg[1] };
31
+ return file(path.posix.join(path.posix.dirname(from), uri), project);
32
+ }
@@ -0,0 +1,3 @@
1
+ import type { LanguagePack } from '../src/packs/pack.js';
2
+ /** The language packs of this release. Adding a language adds its folder and one entry here (CIN-11). */
3
+ export declare const PACKS: LanguagePack[];
@@ -0,0 +1,8 @@
1
+ import { csharpPack } from './csharp/pack.js';
2
+ import { dartPack } from './dart/pack.js';
3
+ import { jsonPack } from './json/pack.js';
4
+ import { msbuildPack } from './msbuild/pack.js';
5
+ import { typescriptPack } from './typescript/pack.js';
6
+ import { yamlPack } from './yaml/pack.js';
7
+ /** The language packs of this release. Adding a language adds its folder and one entry here (CIN-11). */
8
+ export const PACKS = [typescriptPack, dartPack, csharpPack, jsonPack, yamlPack, msbuildPack];
@@ -0,0 +1,2 @@
1
+ import { type LanguagePack } from '../../src/packs/pack.js';
2
+ export declare const jsonPack: LanguagePack;
@@ -0,0 +1,27 @@
1
+ import path from 'node:path';
2
+ import { parseJsonc } from '../../src/jsonc.js';
3
+ import { dataSkeleton } from '../../src/packs/dataShape.js';
4
+ import { ParseError } from '../../src/packs/pack.js';
5
+ /** JSON files (comments and trailing commas allowed, as in tsconfig.json), and the dependencies a package.json declares. */
6
+ const SECTIONS = [['dependencies', false], ['peerDependencies', false], ['optionalDependencies', false], ['devDependencies', true]];
7
+ function packageDependencies(json) {
8
+ return SECTIONS.flatMap(([section, dev]) => Object.entries((json?.[section] ?? {})).map(([name, version]) => ({ name, version: String(version), dev })));
9
+ }
10
+ export const jsonPack = {
11
+ id: 'json',
12
+ data: true,
13
+ claims: (file) => file.endsWith('.json'),
14
+ parse: async ({ path: file, content }) => {
15
+ let parsed;
16
+ try {
17
+ parsed = parseJsonc(content);
18
+ }
19
+ catch (err) {
20
+ // Node 24 and later append "(line N column M)"; drop it so outputs match on every Node version.
21
+ const message = err.message.replace(/ \(line \d+ column \d+\)$/, '');
22
+ throw new ParseError(`Invalid JSON: ${message}`);
23
+ }
24
+ const declares = path.posix.basename(file) === 'package.json' ? packageDependencies(parsed) : undefined;
25
+ return { symbols: [], imports: [], skeleton: dataSkeleton('JSON', parsed), ...(declares ? { declares } : {}) };
26
+ },
27
+ };
@@ -0,0 +1,2 @@
1
+ import { type LanguagePack } from '../../src/packs/pack.js';
2
+ export declare const msbuildPack: LanguagePack;
@@ -0,0 +1,75 @@
1
+ import path from 'node:path';
2
+ import { ParseError } from '../../src/packs/pack.js';
3
+ import { descendants, parseXml } from './xml.js';
4
+ /**
5
+ * .NET manifests: a `.csproj` (and a shared `.props` or `.targets` file such as Directory.Build.props) declares its
6
+ * `PackageReference` entries as dependencies and its `ProjectReference` entries as imports of the referenced project
7
+ * files; a solution (`.sln`, `.slnx`) imports the projects it holds. The imports make project references edges of the graph.
8
+ */
9
+ const SOLUTION_PROJECT = /^Project\("\{[0-9A-Fa-f-]+\}"\)\s*=\s*"[^"]*",\s*"([^"]+)"/;
10
+ const PROJECT_FILE = /\.(cs|fs|vb)proj$/i;
11
+ const attribute = (element, name) => Object.entries(element.attributes).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
12
+ /** A version is an attribute or a child element; with central package management it is in Directory.Packages.props instead. */
13
+ function versionOf(reference) {
14
+ return attribute(reference, 'Version') ?? reference.children.find((c) => c.name === 'Version')?.text ?? '';
15
+ }
16
+ /** A package with `PrivateAssets="all"` (analyzers, build tools) is not shipped with the project. */
17
+ function dependency(reference) {
18
+ const name = attribute(reference, 'Include');
19
+ if (!name)
20
+ return undefined;
21
+ const privateAssets = attribute(reference, 'PrivateAssets') ?? reference.children.find((c) => c.name === 'PrivateAssets')?.text;
22
+ return { name, version: versionOf(reference), dev: privateAssets?.toLowerCase() === 'all' };
23
+ }
24
+ function project(content) {
25
+ const root = parseXml(content);
26
+ if (root.name !== 'Project')
27
+ throw new ParseError(`The root element is <${root.name}>, not <Project>`);
28
+ const declares = descendants(root, 'PackageReference').map(dependency).filter((d) => !!d);
29
+ const imports = descendants(root, 'ProjectReference').flatMap((r) => {
30
+ const include = attribute(r, 'Include');
31
+ return include ? [{ specifier: include, line: r.line }] : [];
32
+ });
33
+ const sdk = attribute(root, 'Sdk');
34
+ const skeleton = [
35
+ `// .NET project${sdk ? ` (${sdk})` : ''}`,
36
+ ...declares.map((d) => `PackageReference ${d.name} ${d.version}`.trimEnd()),
37
+ ...imports.map((i) => `ProjectReference ${i.specifier}`),
38
+ ].join('\n');
39
+ return { symbols: [], imports, skeleton, ...(declares.length ? { declares } : {}) };
40
+ }
41
+ function solution(content) {
42
+ const imports = content.split('\n').flatMap((text, i) => {
43
+ const match = SOLUTION_PROJECT.exec(text.trim());
44
+ return match && PROJECT_FILE.test(match[1]) ? [{ specifier: match[1], line: i + 1 }] : [];
45
+ });
46
+ if (!/Microsoft Visual Studio Solution File/.test(content))
47
+ throw new ParseError('Not a Visual Studio solution file');
48
+ return { symbols: [], imports, skeleton: ['// Solution', ...imports.map((i) => `Project ${i.specifier}`)].join('\n') };
49
+ }
50
+ function xmlSolution(content) {
51
+ const root = parseXml(content);
52
+ if (root.name !== 'Solution')
53
+ throw new ParseError(`The root element is <${root.name}>, not <Solution>`);
54
+ const imports = descendants(root, 'Project').flatMap((p) => {
55
+ const file = attribute(p, 'Path');
56
+ return file ? [{ specifier: file, line: p.line }] : [];
57
+ });
58
+ return { symbols: [], imports, skeleton: ['// Solution', ...imports.map((i) => `Project ${i.specifier}`)].join('\n') };
59
+ }
60
+ /** A project path is relative to the manifest's folder and may use backslashes. */
61
+ function resolveProject({ from, raw, project: view }) {
62
+ const target = path.posix.normalize(path.posix.join(path.posix.dirname(from), raw.specifier.replace(/\\/g, '/')));
63
+ return !target.startsWith('..') && view.has(target) ? { kind: 'file', target } : { kind: 'unresolved' };
64
+ }
65
+ export const msbuildPack = {
66
+ id: 'msbuild',
67
+ data: true,
68
+ claims: (file) => /\.(csproj|props|targets|sln|slnx)$/.test(file),
69
+ parse: async ({ path: file, content }) => {
70
+ if (file.endsWith('.sln'))
71
+ return solution(content);
72
+ return file.endsWith('.slnx') ? xmlSolution(content) : project(content);
73
+ },
74
+ resolve: resolveProject,
75
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A small, strict XML reader for MSBuild files (Tree-sitter has no XML grammar in the pinned set). It reads elements,
3
+ * attributes and text; it skips the declaration, comments and processing instructions; and anything not well formed is
4
+ * a ParseError with its line, so the file is recorded with its error (CIN-04).
5
+ */
6
+ export interface XmlElement {
7
+ name: string;
8
+ attributes: Record<string, string>;
9
+ children: XmlElement[];
10
+ text: string;
11
+ line: number;
12
+ }
13
+ /** The document's root element; text before or after it, or a second root, is an error. */
14
+ export declare function parseXml(text: string): XmlElement;
15
+ /** Every element named `name` below `root`, in document order. */
16
+ export declare function descendants(root: XmlElement, name: string): XmlElement[];
@@ -0,0 +1,123 @@
1
+ import { ParseError } from '../../src/packs/pack.js';
2
+ const NAME = /[A-Za-z_][\w.:-]*/y;
3
+ const ATTRIBUTE = /\s+([A-Za-z_][\w.:-]*)\s*=\s*("([^"<]*)"|'([^'<]*)')/y;
4
+ const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
5
+ function decode(text) {
6
+ return text.replace(/&(#x[0-9a-fA-F]+|#\d+|\w+);/g, (whole, ref) => {
7
+ if (ref.startsWith('#x'))
8
+ return String.fromCodePoint(parseInt(ref.slice(2), 16));
9
+ if (ref.startsWith('#'))
10
+ return String.fromCodePoint(parseInt(ref.slice(1), 10));
11
+ return ENTITIES[ref] ?? whole;
12
+ });
13
+ }
14
+ class Reader {
15
+ text;
16
+ at = 0;
17
+ constructor(text) {
18
+ this.text = text;
19
+ }
20
+ line(index = this.at) {
21
+ return this.text.slice(0, index).split('\n').length;
22
+ }
23
+ fail(message, index = this.at) {
24
+ throw new ParseError(`Invalid XML at line ${this.line(index)}: ${message}`);
25
+ }
26
+ /** Skips whitespace, comments, processing instructions and the XML declaration. */
27
+ skipMisc() {
28
+ for (;;) {
29
+ const rest = this.text.slice(this.at);
30
+ const space = /^\s+/.exec(rest);
31
+ if (space) {
32
+ this.at += space[0].length;
33
+ continue;
34
+ }
35
+ const close = rest.startsWith('<!--') ? '-->' : rest.startsWith('<?') ? '?>' : undefined;
36
+ if (!close)
37
+ return;
38
+ const end = this.text.indexOf(close, this.at);
39
+ if (end < 0)
40
+ this.fail('unterminated comment or declaration');
41
+ this.at = end + close.length;
42
+ }
43
+ }
44
+ name() {
45
+ NAME.lastIndex = this.at;
46
+ const match = NAME.exec(this.text);
47
+ if (!match)
48
+ this.fail('expected a name');
49
+ this.at += match[0].length;
50
+ return match[0];
51
+ }
52
+ attributes() {
53
+ const found = {};
54
+ for (;;) {
55
+ ATTRIBUTE.lastIndex = this.at;
56
+ const match = ATTRIBUTE.exec(this.text);
57
+ if (!match)
58
+ return found;
59
+ if (match[1] in found)
60
+ this.fail(`duplicate attribute ${match[1]}`);
61
+ found[match[1]] = decode(match[3] ?? match[4]);
62
+ this.at += match[0].length;
63
+ }
64
+ }
65
+ /** One element and everything inside it, starting at its `<`. */
66
+ element() {
67
+ const start = this.at;
68
+ if (this.text[this.at] !== '<')
69
+ this.fail('expected an element');
70
+ this.at++;
71
+ const element = { name: this.name(), attributes: this.attributes(), children: [], text: '', line: this.line(start) };
72
+ const rest = this.text.slice(this.at);
73
+ const end = /^\s*(\/?)>/.exec(rest);
74
+ if (!end)
75
+ this.fail(`malformed start tag <${element.name}>`);
76
+ this.at += end[0].length;
77
+ if (end[1] === '/')
78
+ return element;
79
+ this.content(element);
80
+ return element;
81
+ }
82
+ content(element) {
83
+ for (;;) {
84
+ const next = this.text.indexOf('<', this.at);
85
+ if (next < 0)
86
+ this.fail(`<${element.name}> is not closed`, this.text.length);
87
+ element.text += decode(this.text.slice(this.at, next));
88
+ this.at = next;
89
+ if (this.text.startsWith('</', this.at)) {
90
+ this.at += 2;
91
+ const name = this.name();
92
+ if (name !== element.name)
93
+ this.fail(`</${name}> closes <${element.name}>`);
94
+ if (!/^\s*>/.test(this.text.slice(this.at)))
95
+ this.fail(`malformed end tag </${name}>`);
96
+ this.at = this.text.indexOf('>', this.at) + 1;
97
+ element.text = element.text.trim();
98
+ return;
99
+ }
100
+ if (this.text.startsWith('<!--', this.at) || this.text.startsWith('<?', this.at))
101
+ this.skipMisc();
102
+ else
103
+ element.children.push(this.element());
104
+ }
105
+ }
106
+ done() {
107
+ return this.at >= this.text.length;
108
+ }
109
+ }
110
+ /** The document's root element; text before or after it, or a second root, is an error. */
111
+ export function parseXml(text) {
112
+ const reader = new Reader(text.replace(/^/, ''));
113
+ reader.skipMisc();
114
+ const root = reader.element();
115
+ reader.skipMisc();
116
+ if (!reader.done())
117
+ reader.fail('content after the root element');
118
+ return root;
119
+ }
120
+ /** Every element named `name` below `root`, in document order. */
121
+ export function descendants(root, name) {
122
+ return root.children.flatMap((c) => [...(c.name === name ? [c] : []), ...descendants(c, name)]);
123
+ }
@@ -0,0 +1,4 @@
1
+ import type { Node } from 'web-tree-sitter';
2
+ import { type Declared } from '../../src/packs/symbols.js';
3
+ /** Attaches static `calls` sites to callable TypeScript declarations. */
4
+ export declare function withTypeScriptCalls(items: Declared[], root: Node): Declared[];
@@ -0,0 +1,201 @@
1
+ import { cleanTypeName, dedupeCalls, detectBoundary, isNoiseCall } from '../../src/packs/calls.js';
2
+ import { CONTAINER_KINDS, FUNCTION_KINDS } from '../../src/packs/symbols.js';
3
+ /** Static call and async/indirect wiring extraction for TypeScript/JavaScript. */
4
+ const EVENT_METHODS = new Set(['emit', 'emitAsync', 'dispatch', 'publish']);
5
+ const QUEUE_METHODS = new Set(['queue', 'queueAll', 'enqueue', 'add', 'addBulk', 'schedule']);
6
+ function unquote(text) {
7
+ return text.replace(/^['"`]|['"`]$/g, '').trim();
8
+ }
9
+ function extractKeyArg(argsNode) {
10
+ const args = argsNode?.namedChildren ?? [];
11
+ const first = args[0];
12
+ if (!first)
13
+ return undefined;
14
+ if (first.type === 'string' || first.type === 'template_string')
15
+ return unquote(first.text);
16
+ if (first.type === 'identifier' || first.type === 'member_expression')
17
+ return first.text;
18
+ if (first.type === 'object') {
19
+ for (const pair of first.namedChildren) {
20
+ if (pair?.type !== 'pair')
21
+ continue;
22
+ const key = pair.childForFieldName('key')?.text;
23
+ if (key === 'name' || key === 'event' || key === 'job' || key === 'queue') {
24
+ const val = pair.childForFieldName('value');
25
+ if (val)
26
+ return unquote(val.text);
27
+ }
28
+ }
29
+ }
30
+ if (first.type === 'array' && first.namedChildren[0]?.type === 'object') {
31
+ for (const pair of first.namedChildren[0].namedChildren) {
32
+ if (pair?.type !== 'pair')
33
+ continue;
34
+ const key = pair.childForFieldName('key')?.text;
35
+ if (key === 'name' || key === 'job') {
36
+ const val = pair.childForFieldName('value');
37
+ if (val)
38
+ return unquote(val.text);
39
+ }
40
+ }
41
+ }
42
+ return undefined;
43
+ }
44
+ /** Collects `fieldName -> TypeName` from class fields/constructor parameter properties and `new Foo()` initializers. */
45
+ function buildOwnerFieldTypes(items, root) {
46
+ const result = new Map();
47
+ const containers = items.filter((d) => CONTAINER_KINDS.has(d.kind));
48
+ for (const c of containers) {
49
+ const types = new Map();
50
+ for (const m of items) {
51
+ if (m.start > c.start && m.end <= c.end && (m.kind === 'field' || m.kind === 'getter')) {
52
+ const t = cleanTypeName(m.type);
53
+ if (t)
54
+ types.set(m.name, t);
55
+ }
56
+ }
57
+ result.set(`${c.start}:${c.end}`, types);
58
+ }
59
+ // Also infer `field = new Foo()` from public_field_definition nodes
60
+ const walk = (node) => {
61
+ if (node.type === 'public_field_definition') {
62
+ const name = node.childForFieldName('name')?.text;
63
+ const val = node.childForFieldName('value');
64
+ if (name && val?.type === 'new_expression') {
65
+ const ctor = val.childForFieldName('constructor')?.text;
66
+ const clean = cleanTypeName(ctor);
67
+ if (clean) {
68
+ for (const c of containers) {
69
+ if (node.startIndex > c.start && node.endIndex <= c.end) {
70
+ const map = result.get(`${c.start}:${c.end}`);
71
+ if (!map.has(name))
72
+ map.set(name, clean);
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+ for (const ch of node.children)
79
+ if (ch)
80
+ walk(ch);
81
+ };
82
+ walk(root);
83
+ return result;
84
+ }
85
+ function enclosingContainer(item, containers) {
86
+ let best;
87
+ for (const c of containers) {
88
+ if (item.start > c.start && item.end <= c.end) {
89
+ if (!best || c.start > best.start)
90
+ best = c;
91
+ }
92
+ }
93
+ return best;
94
+ }
95
+ function extractCallsInRange(root, start, end, ownerName, fieldTypes) {
96
+ const sites = [];
97
+ const walk = (node) => {
98
+ if (node.endIndex <= start || node.startIndex >= end)
99
+ return;
100
+ if (node.type === 'call_expression' && node.startIndex >= start && node.endIndex <= end) {
101
+ const fn = node.childForFieldName('function');
102
+ const args = node.childForFieldName('arguments');
103
+ const line = node.startPosition.row + 1;
104
+ if (fn?.type === 'member_expression') {
105
+ const method = fn.childForFieldName('property')?.text ?? '';
106
+ const obj = fn.childForFieldName('object');
107
+ if (method && obj) {
108
+ let receiver;
109
+ let receiverType;
110
+ let isThisMember = false;
111
+ let callee = `${obj.text}.${method}`;
112
+ if (obj.type === 'this') {
113
+ receiver = 'this';
114
+ receiverType = ownerName;
115
+ isThisMember = true;
116
+ }
117
+ else if (obj.type === 'member_expression' && obj.childForFieldName('object')?.type === 'this') {
118
+ receiver = obj.childForFieldName('property')?.text;
119
+ receiverType = receiver ? fieldTypes.get(receiver) : undefined;
120
+ isThisMember = true;
121
+ }
122
+ else if (obj.type === 'identifier') {
123
+ receiver = obj.text;
124
+ receiverType = fieldTypes.get(receiver);
125
+ }
126
+ else if (obj.type === 'member_expression') {
127
+ receiver = obj.childForFieldName('property')?.text;
128
+ callee = `${obj.text}.${method}`;
129
+ }
130
+ if (receiver && !isNoiseCall(receiver, receiverType, method, isThisMember)) {
131
+ let kind = 'calls';
132
+ let targetKey;
133
+ if (EVENT_METHODS.has(method) && /event|bus|emitter/i.test(receiverType ?? receiver)) {
134
+ const key = extractKeyArg(args);
135
+ if (key) {
136
+ kind = 'emits';
137
+ targetKey = key;
138
+ }
139
+ }
140
+ else if (EVENT_METHODS.has(method) && method === 'emit') {
141
+ const key = extractKeyArg(args);
142
+ if (key) {
143
+ kind = 'emits';
144
+ targetKey = key;
145
+ }
146
+ }
147
+ else if (QUEUE_METHODS.has(method) && /job|queue|bull|worker/i.test(receiverType ?? receiver)) {
148
+ const key = extractKeyArg(args);
149
+ if (key) {
150
+ kind = 'queues';
151
+ targetKey = key;
152
+ }
153
+ }
154
+ const boundary = detectBoundary(kind, receiver, receiverType, method);
155
+ sites.push({
156
+ callee,
157
+ receiver,
158
+ ...(receiverType ? { receiverType } : {}),
159
+ method,
160
+ line,
161
+ kind,
162
+ ...(targetKey ? { targetKey } : {}),
163
+ ...(boundary ? { boundary } : {}),
164
+ });
165
+ }
166
+ }
167
+ }
168
+ else if (fn?.type === 'identifier') {
169
+ const method = fn.text;
170
+ if (!isNoiseCall(undefined, undefined, method, false)) {
171
+ const boundary = detectBoundary('calls', undefined, undefined, method);
172
+ sites.push({
173
+ callee: method,
174
+ method,
175
+ line,
176
+ kind: 'calls',
177
+ ...(boundary ? { boundary } : {}),
178
+ });
179
+ }
180
+ }
181
+ }
182
+ for (const c of node.children)
183
+ if (c)
184
+ walk(c);
185
+ };
186
+ walk(root);
187
+ return dedupeCalls(sites);
188
+ }
189
+ /** Attaches static `calls` sites to callable TypeScript declarations. */
190
+ export function withTypeScriptCalls(items, root) {
191
+ const containers = items.filter((d) => CONTAINER_KINDS.has(d.kind));
192
+ const fieldTypeMaps = buildOwnerFieldTypes(items, root);
193
+ return items.map((item) => {
194
+ if (!FUNCTION_KINDS.has(item.kind))
195
+ return item;
196
+ const owner = enclosingContainer(item, containers);
197
+ const fieldTypes = owner ? (fieldTypeMaps.get(`${owner.start}:${owner.end}`) ?? new Map()) : new Map();
198
+ const calls = extractCallsInRange(root, item.start, item.end, owner?.name, fieldTypes);
199
+ return calls.length ? { ...item, calls } : item;
200
+ });
201
+ }
@@ -0,0 +1,9 @@
1
+ import type { Node } from 'web-tree-sitter';
2
+ import { type Declared } from '../../src/packs/symbols.js';
3
+ export interface FileContext {
4
+ source: string;
5
+ /** Names exported by an export list, `export default <name>` or CommonJS. */
6
+ exportedNames: Set<string>;
7
+ }
8
+ /** A top-level declaration, or undefined for a node this module does not handle. */
9
+ export declare function describeTopLevel(node: Node, ctx: FileContext): Declared | undefined;