@fabersep/atlas 0.0.0-stage → 0.1.1
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.
- package/CHANGELOG.md +49 -0
- package/LICENSE +202 -0
- package/README.md +175 -2
- package/dist/packs/csharp/calls.d.ts +4 -0
- package/dist/packs/csharp/calls.js +167 -0
- package/dist/packs/csharp/declarations.d.ts +4 -0
- package/dist/packs/csharp/declarations.js +142 -0
- package/dist/packs/csharp/pack.d.ts +2 -0
- package/dist/packs/csharp/pack.js +39 -0
- package/dist/packs/csharp/resolve.d.ts +2 -0
- package/dist/packs/csharp/resolve.js +35 -0
- package/dist/packs/csharp/signals.d.ts +7 -0
- package/dist/packs/csharp/signals.js +143 -0
- package/dist/packs/dart/calls.d.ts +4 -0
- package/dist/packs/dart/calls.js +130 -0
- package/dist/packs/dart/declarations.d.ts +11 -0
- package/dist/packs/dart/declarations.js +79 -0
- package/dist/packs/dart/members.d.ts +4 -0
- package/dist/packs/dart/members.js +62 -0
- package/dist/packs/dart/pack.d.ts +2 -0
- package/dist/packs/dart/pack.js +37 -0
- package/dist/packs/dart/resolve.d.ts +2 -0
- package/dist/packs/dart/resolve.js +32 -0
- package/dist/packs/index.d.ts +3 -0
- package/dist/packs/index.js +8 -0
- package/dist/packs/json/pack.d.ts +2 -0
- package/dist/packs/json/pack.js +27 -0
- package/dist/packs/msbuild/pack.d.ts +2 -0
- package/dist/packs/msbuild/pack.js +75 -0
- package/dist/packs/msbuild/xml.d.ts +16 -0
- package/dist/packs/msbuild/xml.js +123 -0
- package/dist/packs/typescript/calls.d.ts +4 -0
- package/dist/packs/typescript/calls.js +208 -0
- package/dist/packs/typescript/declarations.d.ts +9 -0
- package/dist/packs/typescript/declarations.js +74 -0
- package/dist/packs/typescript/members.d.ts +4 -0
- package/dist/packs/typescript/members.js +92 -0
- package/dist/packs/typescript/pack.d.ts +2 -0
- package/dist/packs/typescript/pack.js +53 -0
- package/dist/packs/typescript/resolve.d.ts +2 -0
- package/dist/packs/typescript/resolve.js +68 -0
- package/dist/packs/typescript/signals.d.ts +7 -0
- package/dist/packs/typescript/signals.js +310 -0
- package/dist/packs/yaml/pack.d.ts +2 -0
- package/dist/packs/yaml/pack.js +35 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +477 -0
- package/dist/src/context/pre-grep.d.ts +15 -0
- package/dist/src/context/pre-grep.js +79 -0
- package/dist/src/context/pre-invoke.d.ts +20 -0
- package/dist/src/context/pre-invoke.js +127 -0
- package/dist/src/context/pre-prompt.d.ts +16 -0
- package/dist/src/context/pre-prompt.js +66 -0
- package/dist/src/context/session.d.ts +17 -0
- package/dist/src/context/session.js +57 -0
- package/dist/src/graph/build.d.ts +17 -0
- package/dist/src/graph/build.js +41 -0
- package/dist/src/graph/metrics.d.ts +12 -0
- package/dist/src/graph/metrics.js +75 -0
- package/dist/src/graph/topology.d.ts +5 -0
- package/dist/src/graph/topology.js +54 -0
- package/dist/src/health/compare.d.ts +2 -0
- package/dist/src/health/compare.js +38 -0
- package/dist/src/health/duplicates.d.ts +11 -0
- package/dist/src/health/duplicates.js +66 -0
- package/dist/src/health/health.d.ts +12 -0
- package/dist/src/health/health.js +94 -0
- package/dist/src/health/types.d.ts +101 -0
- package/dist/src/health/types.js +5 -0
- package/dist/src/index.d.ts +25 -0
- package/dist/src/index.js +22 -0
- package/dist/src/init/init.d.ts +104 -0
- package/dist/src/init/init.js +499 -0
- package/dist/src/init/scout.d.ts +45 -0
- package/dist/src/init/scout.js +217 -0
- package/dist/src/jsonc.d.ts +5 -0
- package/dist/src/jsonc.js +34 -0
- package/dist/src/mcp/server.d.ts +398 -0
- package/dist/src/mcp/server.js +543 -0
- package/dist/src/metrics/doctor.d.ts +15 -0
- package/dist/src/metrics/doctor.js +125 -0
- package/dist/src/metrics/log.d.ts +43 -0
- package/dist/src/metrics/log.js +101 -0
- package/dist/src/metrics/stats.d.ts +43 -0
- package/dist/src/metrics/stats.js +172 -0
- package/dist/src/model.d.ts +178 -0
- package/dist/src/model.js +2 -0
- package/dist/src/outputs.d.ts +16 -0
- package/dist/src/outputs.js +48 -0
- package/dist/src/packs/calls.d.ts +9 -0
- package/dist/src/packs/calls.js +119 -0
- package/dist/src/packs/dataShape.d.ts +6 -0
- package/dist/src/packs/dataShape.js +54 -0
- package/dist/src/packs/pack.d.ts +51 -0
- package/dist/src/packs/pack.js +3 -0
- package/dist/src/packs/packFiles.d.ts +5 -0
- package/dist/src/packs/packFiles.js +12 -0
- package/dist/src/packs/symbols.d.ts +39 -0
- package/dist/src/packs/symbols.js +98 -0
- package/dist/src/packs/treeSitter.d.ts +8 -0
- package/dist/src/packs/treeSitter.js +107 -0
- package/dist/src/queries/flow.d.ts +42 -0
- package/dist/src/queries/flow.js +398 -0
- package/dist/src/queries/investigate.d.ts +43 -0
- package/dist/src/queries/investigate.js +216 -0
- package/dist/src/queries/map.d.ts +28 -0
- package/dist/src/queries/map.js +102 -0
- package/dist/src/queries/neighborhood.d.ts +35 -0
- package/dist/src/queries/neighborhood.js +60 -0
- package/dist/src/queries/search.d.ts +37 -0
- package/dist/src/queries/search.js +279 -0
- package/dist/src/scan/audit.d.ts +2 -0
- package/dist/src/scan/audit.js +41 -0
- package/dist/src/scan/records.d.ts +12 -0
- package/dist/src/scan/records.js +42 -0
- package/dist/src/scan/resolveImports.d.ts +3 -0
- package/dist/src/scan/resolveImports.js +47 -0
- package/dist/src/scan/roles.d.ts +5 -0
- package/dist/src/scan/roles.js +87 -0
- package/dist/src/scan/scan.d.ts +24 -0
- package/dist/src/scan/scan.js +72 -0
- package/dist/src/text/briefs.d.ts +13 -0
- package/dist/src/text/briefs.js +43 -0
- package/dist/src/text/collapse.d.ts +10 -0
- package/dist/src/text/collapse.js +58 -0
- package/dist/src/text/declarations.d.ts +12 -0
- package/dist/src/text/declarations.js +120 -0
- package/dist/src/text/structure.d.ts +2 -0
- package/dist/src/text/structure.js +15 -0
- package/dist/src/text/tree.d.ts +20 -0
- package/dist/src/text/tree.js +49 -0
- package/dist/src/tokens.d.ts +4 -0
- package/dist/src/tokens.js +9 -0
- package/dist/src/version.d.ts +10 -0
- package/dist/src/version.js +11 -0
- package/dist/src/walk/ignoreRules.d.ts +17 -0
- package/dist/src/walk/ignoreRules.js +72 -0
- package/dist/src/walk/walk.d.ts +11 -0
- package/dist/src/walk/walk.js +29 -0
- package/grammars/LICENSE-tree-sitter-dart +20 -0
- package/grammars/README.md +11 -0
- package/grammars/tree-sitter-dart.wasm +0 -0
- package/package.json +68 -4
- package/packs/csharp/README.md +9 -0
- package/packs/csharp/imports.scm +3 -0
- package/packs/csharp/symbols.scm +17 -0
- package/packs/dart/imports.scm +5 -0
- package/packs/dart/symbols.scm +13 -0
- package/packs/msbuild/README.md +11 -0
- package/packs/typescript/exports.scm +16 -0
- package/packs/typescript/imports.scm +9 -0
- package/packs/typescript/symbols.scm +19 -0
- package/schema/ast_code_map.schema.json +144 -0
- package/schema/schema-lock.json +7 -0
- package/schema/topology.schema.json +87 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { ROLE_TAGS } from '../scan/roles.js';
|
|
3
|
+
import { byName } from '../text/collapse.js';
|
|
4
|
+
import { fullBlock, mapSummary, mapSummaryZoom1 } from '../text/declarations.js';
|
|
5
|
+
import { renderTree } from '../text/tree.js';
|
|
6
|
+
import { UnknownFileError } from './neighborhood.js';
|
|
7
|
+
const TEST_DIR = /(^|\/)(test|tests|__tests__|__mocks__|e2e)\//i;
|
|
8
|
+
const TEST_FILE = /(\.(spec|test|e2e-spec|e2e-test)\.[^.]+$|_test\.dart$|(Tests?|Specs?)\.cs$)/i;
|
|
9
|
+
/** Whether a project-relative path looks like a test or spec file. */
|
|
10
|
+
export function isTestFile(filePath) {
|
|
11
|
+
return TEST_DIR.test(filePath) || TEST_FILE.test(path.posix.basename(filePath));
|
|
12
|
+
}
|
|
13
|
+
function renderFile(record, options) {
|
|
14
|
+
if (options.full)
|
|
15
|
+
return fullBlock(record).join('\n');
|
|
16
|
+
if (options.zoom === 1)
|
|
17
|
+
return mapSummaryZoom1(record) ?? '';
|
|
18
|
+
return mapSummary(record, options.fields === true) ?? '';
|
|
19
|
+
}
|
|
20
|
+
function createZoom0Folder(name) {
|
|
21
|
+
return { name, folders: new Map(), ownFiles: 0, totalFiles: 0, roles: new Map() };
|
|
22
|
+
}
|
|
23
|
+
function dominantRoles(counts, limit = 4) {
|
|
24
|
+
return [...counts.entries()]
|
|
25
|
+
.sort((a, b) => b[1] - a[1] || ROLE_TAGS.indexOf(a[0]) - ROLE_TAGS.indexOf(b[0]))
|
|
26
|
+
.slice(0, limit)
|
|
27
|
+
.map(([role]) => role);
|
|
28
|
+
}
|
|
29
|
+
function formatZoom0Suffix(totalFiles, roles) {
|
|
30
|
+
const count = `(${totalFiles} ${totalFiles === 1 ? 'file' : 'files'})`;
|
|
31
|
+
const dom = dominantRoles(roles);
|
|
32
|
+
return dom.length ? `${count} [${dom.join(', ')}]` : count;
|
|
33
|
+
}
|
|
34
|
+
function renderZoom0(rootName, records, maxDepth) {
|
|
35
|
+
const root = createZoom0Folder(rootName);
|
|
36
|
+
for (const [relPath, record] of records) {
|
|
37
|
+
const parts = relPath.split('/');
|
|
38
|
+
let cur = root;
|
|
39
|
+
const chain = [cur];
|
|
40
|
+
for (const part of parts.slice(0, -1)) {
|
|
41
|
+
if (!cur.folders.has(part))
|
|
42
|
+
cur.folders.set(part, createZoom0Folder(part));
|
|
43
|
+
cur = cur.folders.get(part);
|
|
44
|
+
chain.push(cur);
|
|
45
|
+
}
|
|
46
|
+
cur.ownFiles++;
|
|
47
|
+
for (const f of chain) {
|
|
48
|
+
f.totalFiles++;
|
|
49
|
+
for (const role of record.roles ?? [])
|
|
50
|
+
f.roles.set(role, (f.roles.get(role) ?? 0) + 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const lines = [`${rootName}/ ${formatZoom0Suffix(root.totalFiles, root.roles)}`];
|
|
54
|
+
if (records.length === 0) {
|
|
55
|
+
lines.push(' (no files)');
|
|
56
|
+
return lines.join('\n');
|
|
57
|
+
}
|
|
58
|
+
const walk = (folder, depth, prefix) => {
|
|
59
|
+
if (maxDepth !== undefined && depth > maxDepth)
|
|
60
|
+
return;
|
|
61
|
+
const subs = [...folder.folders.values()].sort((a, b) => byName(a.name, b.name));
|
|
62
|
+
for (const sub of subs) {
|
|
63
|
+
lines.push(`${prefix}${sub.name}/ ${formatZoom0Suffix(sub.totalFiles, sub.roles)}`);
|
|
64
|
+
walk(sub, depth + 1, `${prefix} `);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
walk(root, 0, ' ');
|
|
68
|
+
return lines.join('\n');
|
|
69
|
+
}
|
|
70
|
+
export function renderMap(map, options = {}) {
|
|
71
|
+
const zoom = options.zoom ?? 2;
|
|
72
|
+
const folder = (options.folder ?? '').replace(/^\.?\/+|\/+$/g, '');
|
|
73
|
+
const file = map.files.find((f) => f.path === folder);
|
|
74
|
+
if (file)
|
|
75
|
+
return renderFile(file, options);
|
|
76
|
+
const inFolder = map.files.filter((f) => f.language !== 'other' && (!folder || f.path.startsWith(`${folder}/`)));
|
|
77
|
+
if (folder && inFolder.length === 0 && !map.files.some((f) => f.path.startsWith(`${folder}/`))) {
|
|
78
|
+
throw new UnknownFileError(`Not in the code map: ${folder}`);
|
|
79
|
+
}
|
|
80
|
+
const excludeTests = (zoom === 0 || zoom === 1) && !options.includeTests;
|
|
81
|
+
const records = excludeTests ? inFolder.filter((f) => !isTestFile(f.path)) : inFolder;
|
|
82
|
+
const rootName = folder ? path.posix.basename(folder) : map.rootName;
|
|
83
|
+
const entries = records.map((r) => [folder ? r.path.slice(folder.length + 1) : r.path, r]);
|
|
84
|
+
if (zoom === 0)
|
|
85
|
+
return renderZoom0(rootName, entries, options.depth);
|
|
86
|
+
const byPath = new Map(entries);
|
|
87
|
+
return renderTree([...byPath.keys()], {
|
|
88
|
+
rootName,
|
|
89
|
+
maxDepth: options.depth,
|
|
90
|
+
foldersOnly: options.foldersOnly,
|
|
91
|
+
describe: (p) => {
|
|
92
|
+
const record = byPath.get(p);
|
|
93
|
+
if (options.full) {
|
|
94
|
+
const block = fullBlock(record);
|
|
95
|
+
return block.length ? { block } : {};
|
|
96
|
+
}
|
|
97
|
+
if (zoom === 1)
|
|
98
|
+
return { inline: mapSummaryZoom1(record) };
|
|
99
|
+
return { inline: mapSummary(record, options.fields === true) };
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CodeMap, Topology } from '../model.js';
|
|
2
|
+
/**
|
|
3
|
+
* The files around a change (CIN-08): the targets, their direct imports and importers (tier 2), then what those
|
|
4
|
+
* import (tier 1). Each file comes with its brief (its skeleton), or is counted at its full size when the caller reads
|
|
5
|
+
* contents instead. Without a budget every tier-2 file is taken and tier 1 is only counted; with one, files are taken
|
|
6
|
+
* tier by tier, most central first, while they fit.
|
|
7
|
+
*/
|
|
8
|
+
export interface NeighborhoodEntry {
|
|
9
|
+
path: string;
|
|
10
|
+
tier: 1 | 2 | 3;
|
|
11
|
+
reason: string;
|
|
12
|
+
/** Brief tokens, or raw tokens when contents were asked for. */
|
|
13
|
+
tokens: number;
|
|
14
|
+
/** The file's brief; absent when contents were asked for. */
|
|
15
|
+
brief?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface NeighborhoodOptions {
|
|
18
|
+
/** The most tokens the related files may take; absent: every direct import and importer, and no tier 1. */
|
|
19
|
+
budget?: number;
|
|
20
|
+
/** Count files at their full size, for a caller that reads their contents instead of their briefs. */
|
|
21
|
+
contents?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface Neighborhood {
|
|
24
|
+
targets: NeighborhoodEntry[];
|
|
25
|
+
selected: NeighborhoodEntry[];
|
|
26
|
+
budget?: number;
|
|
27
|
+
selectedTokens: number;
|
|
28
|
+
omitted: {
|
|
29
|
+
files: number;
|
|
30
|
+
tokens: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export declare class UnknownFileError extends Error {
|
|
34
|
+
}
|
|
35
|
+
export declare function neighborhood(map: CodeMap, topology: Topology, targetPaths: string[], options?: NeighborhoodOptions): Neighborhood;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { fileId } from '../graph/build.js';
|
|
2
|
+
export class UnknownFileError extends Error {
|
|
3
|
+
}
|
|
4
|
+
function adjacency(topology) {
|
|
5
|
+
const out = new Map();
|
|
6
|
+
const into = new Map();
|
|
7
|
+
for (const e of topology.edges.filter((e) => e.type === 'imports')) {
|
|
8
|
+
out.set(e.source, [...(out.get(e.source) ?? []), e.target]);
|
|
9
|
+
into.set(e.target, [...(into.get(e.target) ?? []), e.source]);
|
|
10
|
+
}
|
|
11
|
+
const strip = (ids) => (ids ?? []).map((id) => id.slice('file:'.length)).sort();
|
|
12
|
+
return { imports: (p) => strip(out.get(fileId(p))), importers: (p) => strip(into.get(fileId(p))) };
|
|
13
|
+
}
|
|
14
|
+
function candidates(targets, topology) {
|
|
15
|
+
const graph = adjacency(topology);
|
|
16
|
+
const seen = new Map(targets.map((t) => [t, { path: t, tier: 2, reason: 'target' }]));
|
|
17
|
+
const add = (path, tier, reason) => seen.has(path) || seen.set(path, { path, tier, reason });
|
|
18
|
+
for (const t of targets) {
|
|
19
|
+
graph.imports(t).forEach((p) => add(p, 2, `imported by ${t}`));
|
|
20
|
+
graph.importers(t).forEach((p) => add(p, 2, `imports ${t}`));
|
|
21
|
+
}
|
|
22
|
+
const ring = [...seen.values()].filter((c) => c.tier === 2 && c.reason !== 'target');
|
|
23
|
+
for (const c of ring)
|
|
24
|
+
graph.imports(c.path).forEach((p) => add(p, 1, `imported by ${c.path}`));
|
|
25
|
+
return [...seen.values()].filter((c) => c.reason !== 'target');
|
|
26
|
+
}
|
|
27
|
+
function entryOf(record, candidate, contents) {
|
|
28
|
+
if (contents)
|
|
29
|
+
return { ...candidate, tokens: record.rawTokens };
|
|
30
|
+
return { ...candidate, tokens: record.skeletonTokens, brief: record.skeleton };
|
|
31
|
+
}
|
|
32
|
+
export function neighborhood(map, topology, targetPaths, options = {}) {
|
|
33
|
+
const records = new Map(map.files.map((f) => [f.path, f]));
|
|
34
|
+
const targets = targetPaths.map((p) => p.replace(/^\.\//, ''));
|
|
35
|
+
const unknown = targets.filter((t) => !records.has(t));
|
|
36
|
+
if (unknown.length)
|
|
37
|
+
throw new UnknownFileError(`Not in the code map: ${unknown.join(', ')}`);
|
|
38
|
+
const { budget, contents = false } = options;
|
|
39
|
+
const nodes = new Map(topology.nodes.filter((n) => n.type === 'file').map((n) => [n.path, n]));
|
|
40
|
+
const score = (p) => nodes.get(p)?.centralityScore ?? 0;
|
|
41
|
+
const ordered = candidates(targets, topology).sort((a, b) => b.tier - a.tier || score(b.path) - score(a.path) || (a.path < b.path ? -1 : 1));
|
|
42
|
+
const selected = [];
|
|
43
|
+
let used = 0;
|
|
44
|
+
let omittedTokens = 0;
|
|
45
|
+
for (const c of ordered) {
|
|
46
|
+
const entry = entryOf(records.get(c.path), c, contents);
|
|
47
|
+
const fits = budget === undefined ? c.tier === 2 : used + entry.tokens <= budget;
|
|
48
|
+
if (fits) {
|
|
49
|
+
selected.push(entry);
|
|
50
|
+
used += entry.tokens;
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
omittedTokens += entry.tokens;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
targets: targets.map((t) => entryOf(records.get(t), { path: t, tier: 3, reason: 'target' }, contents)),
|
|
57
|
+
selected, ...(budget === undefined ? {} : { budget }), selectedTokens: used,
|
|
58
|
+
omitted: { files: ordered.length - selected.length, tokens: omittedTokens },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CodeMap } from '../model.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fast structural search across symbols, files, entrypoints, and call/event/job references.
|
|
4
|
+
* Gives an agent a 1-turn replacement for Grep when it does not know the exact symbol or file name yet.
|
|
5
|
+
*/
|
|
6
|
+
export interface SearchOptions {
|
|
7
|
+
/** Maximum number of hits to return (default: 12). */
|
|
8
|
+
limit?: number;
|
|
9
|
+
/** Include test/spec files (default: false). */
|
|
10
|
+
includeTests?: boolean;
|
|
11
|
+
/** Restrict search to files under this folder prefix. */
|
|
12
|
+
folder?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface SearchHit {
|
|
15
|
+
score: number;
|
|
16
|
+
kind: string;
|
|
17
|
+
label: string;
|
|
18
|
+
file: string;
|
|
19
|
+
lineStart: number;
|
|
20
|
+
lineEnd: number;
|
|
21
|
+
signature: string;
|
|
22
|
+
entrypoints?: string[];
|
|
23
|
+
roles?: string[];
|
|
24
|
+
emits?: string[];
|
|
25
|
+
queues?: string[];
|
|
26
|
+
sends?: string[];
|
|
27
|
+
calls?: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface SearchResult {
|
|
30
|
+
query: string;
|
|
31
|
+
totalMatches: number;
|
|
32
|
+
hits: SearchHit[];
|
|
33
|
+
}
|
|
34
|
+
/** Splits camelCase, PascalCase, snake_case, kebab-case, and regex/punctuation into lowercase terms. */
|
|
35
|
+
export declare function tokenize(text: string): string[];
|
|
36
|
+
export declare function search(map: CodeMap, query: string, options?: SearchOptions): SearchResult;
|
|
37
|
+
export declare function renderSearch(result: SearchResult): string;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { isTestFile } from './map.js';
|
|
2
|
+
/** Splits camelCase, PascalCase, snake_case, kebab-case, and regex/punctuation into lowercase terms. */
|
|
3
|
+
export function tokenize(text) {
|
|
4
|
+
const spaced = text
|
|
5
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
6
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
|
7
|
+
.toLowerCase();
|
|
8
|
+
const raw = spaced.split(/[^a-z0-9]+/).filter((t) => t.length >= 2);
|
|
9
|
+
return [...new Set(raw)];
|
|
10
|
+
}
|
|
11
|
+
/** Strips common regex metacharacters when a query comes from a Grep pattern. */
|
|
12
|
+
function cleanQuery(q) {
|
|
13
|
+
return q.replace(/[\\^$*+?()[\]{}|]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
14
|
+
}
|
|
15
|
+
function summarizeCalls(sym) {
|
|
16
|
+
if (!sym.calls?.length)
|
|
17
|
+
return {};
|
|
18
|
+
const emits = new Set();
|
|
19
|
+
const queues = new Set();
|
|
20
|
+
const sends = new Set();
|
|
21
|
+
const calls = new Set();
|
|
22
|
+
for (const c of sym.calls) {
|
|
23
|
+
if (c.kind === 'emits' && c.targetKey)
|
|
24
|
+
emits.add(c.targetKey);
|
|
25
|
+
else if (c.kind === 'queues' && c.targetKey)
|
|
26
|
+
queues.add(c.targetKey);
|
|
27
|
+
else if (c.kind === 'sends' && c.targetKey)
|
|
28
|
+
sends.add(c.targetKey);
|
|
29
|
+
else if (c.callee)
|
|
30
|
+
calls.add(c.callee.replace(/^this\./, ''));
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
emits: emits.size ? [...emits] : undefined,
|
|
34
|
+
queues: queues.size ? [...queues] : undefined,
|
|
35
|
+
sends: sends.size ? [...sends] : undefined,
|
|
36
|
+
calls: calls.size ? [...calls].slice(0, 6) : undefined,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Extracts code-identifier-like words (camelCase, snake_case, dot.names) from a cleaned query. */
|
|
40
|
+
function extractIdentifiers(cleaned) {
|
|
41
|
+
const words = cleaned.split(/\s+/).filter(Boolean);
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const w of words) {
|
|
44
|
+
if (/[a-z][A-Z]|_|\./.test(w) && w.length >= 4) {
|
|
45
|
+
out.push(w.toLowerCase());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [...new Set(out)];
|
|
49
|
+
}
|
|
50
|
+
function scoreEntry(rawLower, terms, identifiers, label, name, file, signature, entrypoints, calls) {
|
|
51
|
+
const labelLower = label.toLowerCase();
|
|
52
|
+
const nameLower = name.toLowerCase();
|
|
53
|
+
const fileLower = file.toLowerCase();
|
|
54
|
+
const sigLower = signature.toLowerCase();
|
|
55
|
+
const epLower = (entrypoints ?? []).join(' ').toLowerCase();
|
|
56
|
+
const targetKeysLower = (calls ?? [])
|
|
57
|
+
.map((c) => c.targetKey ?? '')
|
|
58
|
+
.filter(Boolean)
|
|
59
|
+
.join(' ')
|
|
60
|
+
.toLowerCase();
|
|
61
|
+
const callList = calls ?? [];
|
|
62
|
+
const callKeysLower = callList
|
|
63
|
+
.map((c) => `${c.callee} ${c.method}`)
|
|
64
|
+
.join(' ')
|
|
65
|
+
.toLowerCase();
|
|
66
|
+
let score = 0;
|
|
67
|
+
// Exact or substring matches on primary identifiers
|
|
68
|
+
if (rawLower.length >= 2) {
|
|
69
|
+
if (nameLower === rawLower || labelLower === rawLower)
|
|
70
|
+
score += 220;
|
|
71
|
+
else if (nameLower.includes(rawLower) || labelLower.includes(rawLower))
|
|
72
|
+
score += 110;
|
|
73
|
+
if (epLower.includes(rawLower))
|
|
74
|
+
score += 95;
|
|
75
|
+
if (targetKeysLower.includes(rawLower))
|
|
76
|
+
score += 85;
|
|
77
|
+
else if (callKeysLower.includes(rawLower))
|
|
78
|
+
score += callList.length > 20 ? 30 : 75;
|
|
79
|
+
if (fileLower.includes(rawLower))
|
|
80
|
+
score += 55;
|
|
81
|
+
if (sigLower.includes(rawLower))
|
|
82
|
+
score += 35;
|
|
83
|
+
}
|
|
84
|
+
// Exact identifier word matches inside multi-word queries (e.g. "what breaks if staticErrorWorkflowId changes")
|
|
85
|
+
if (identifiers.length > 0 && rawLower.includes(' ')) {
|
|
86
|
+
for (const id of identifiers) {
|
|
87
|
+
if (nameLower === id || labelLower === id)
|
|
88
|
+
score += 200;
|
|
89
|
+
else if (id.length >= 6 && (nameLower.includes(id) || labelLower.includes(id)))
|
|
90
|
+
score += 95;
|
|
91
|
+
if (epLower.includes(id))
|
|
92
|
+
score += 80;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Token-level scoring across all structural fields
|
|
96
|
+
if (terms.length > 0) {
|
|
97
|
+
const nameTokens = new Set(tokenize(label));
|
|
98
|
+
const fileTokens = new Set(tokenize(file));
|
|
99
|
+
const epTokens = new Set(tokenize(epLower));
|
|
100
|
+
const targetTokens = new Set(tokenize(targetKeysLower));
|
|
101
|
+
const callTokens = new Set(tokenize(callKeysLower));
|
|
102
|
+
const sigTokens = new Set(tokenize(signature));
|
|
103
|
+
// Scale down generic call-list weight for very large "god functions" (100+ calls)
|
|
104
|
+
// so they do not match every multi-word query solely via their callee list.
|
|
105
|
+
const callWeight = callList.length <= 15 ? 26 : Math.max(6, Math.round((26 * 15) / callList.length));
|
|
106
|
+
let matched = 0;
|
|
107
|
+
let primaryMatched = 0;
|
|
108
|
+
for (const t of terms) {
|
|
109
|
+
let termBest = 0;
|
|
110
|
+
let hitPrimary = false;
|
|
111
|
+
if (nameTokens.has(t)) {
|
|
112
|
+
termBest = Math.max(termBest, 40);
|
|
113
|
+
hitPrimary = true;
|
|
114
|
+
}
|
|
115
|
+
else if (nameLower.includes(t)) {
|
|
116
|
+
termBest = Math.max(termBest, 28);
|
|
117
|
+
hitPrimary = true;
|
|
118
|
+
}
|
|
119
|
+
if (epTokens.has(t) || epLower.includes(t)) {
|
|
120
|
+
termBest = Math.max(termBest, 35);
|
|
121
|
+
hitPrimary = true;
|
|
122
|
+
}
|
|
123
|
+
if (targetTokens.has(t) || targetKeysLower.includes(t)) {
|
|
124
|
+
termBest = Math.max(termBest, 30);
|
|
125
|
+
hitPrimary = true;
|
|
126
|
+
}
|
|
127
|
+
if (callTokens.has(t) || callKeysLower.includes(t)) {
|
|
128
|
+
termBest = Math.max(termBest, callWeight);
|
|
129
|
+
}
|
|
130
|
+
if (fileTokens.has(t) || fileLower.includes(t)) {
|
|
131
|
+
termBest = Math.max(termBest, 22);
|
|
132
|
+
hitPrimary = true;
|
|
133
|
+
}
|
|
134
|
+
if (sigTokens.has(t) || sigLower.includes(t)) {
|
|
135
|
+
termBest = Math.max(termBest, 15);
|
|
136
|
+
}
|
|
137
|
+
if (termBest > 0) {
|
|
138
|
+
matched++;
|
|
139
|
+
if (hitPrimary)
|
|
140
|
+
primaryMatched++;
|
|
141
|
+
score += termBest;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (matched === 0)
|
|
145
|
+
return 0;
|
|
146
|
+
// Strong bonus when every query term is represented (require at least one primary match on large functions)
|
|
147
|
+
if (matched === terms.length && terms.length > 1) {
|
|
148
|
+
if (callList.length <= 20 || primaryMatched > 0)
|
|
149
|
+
score += 50;
|
|
150
|
+
}
|
|
151
|
+
else if (terms.length > 1) {
|
|
152
|
+
score = Math.round(score * (matched / terms.length));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return score;
|
|
156
|
+
}
|
|
157
|
+
export function search(map, query, options = {}) {
|
|
158
|
+
const limit = Math.max(1, Math.min(options.limit ?? 12, 50));
|
|
159
|
+
const cleaned = cleanQuery(query);
|
|
160
|
+
const rawLower = cleaned.toLowerCase();
|
|
161
|
+
const terms = tokenize(cleaned);
|
|
162
|
+
const identifiers = extractIdentifiers(cleaned);
|
|
163
|
+
if (!rawLower && terms.length === 0) {
|
|
164
|
+
return { query, totalMatches: 0, hits: [] };
|
|
165
|
+
}
|
|
166
|
+
const folderPrefix = options.folder ? options.folder.replace(/^\/+|\/+$/g, '') : undefined;
|
|
167
|
+
const includeTests = options.includeTests === true || /\b(test|spec)\b/i.test(query);
|
|
168
|
+
const hits = [];
|
|
169
|
+
for (const record of map.files) {
|
|
170
|
+
const testFile = isTestFile(record.path);
|
|
171
|
+
if (testFile && !includeTests)
|
|
172
|
+
continue;
|
|
173
|
+
if (folderPrefix && record.path !== folderPrefix && !record.path.startsWith(`${folderPrefix}/`))
|
|
174
|
+
continue;
|
|
175
|
+
let fileBest = 0;
|
|
176
|
+
const visit = (sym, owner) => {
|
|
177
|
+
const label = owner ? `${owner}.${sym.name}` : sym.name;
|
|
178
|
+
const s = scoreEntry(rawLower, terms, identifiers, label, sym.name, record.path, sym.signature, sym.entrypoints, sym.calls);
|
|
179
|
+
if (s > 0) {
|
|
180
|
+
const penalty = testFile ? 0.7 : 1;
|
|
181
|
+
const kindBoost = sym.kind === 'method' || sym.kind === 'function' ? 1.08 : 1;
|
|
182
|
+
const finalScore = Math.round(s * penalty * kindBoost);
|
|
183
|
+
fileBest = Math.max(fileBest, finalScore);
|
|
184
|
+
hits.push({
|
|
185
|
+
score: finalScore,
|
|
186
|
+
kind: sym.kind,
|
|
187
|
+
label,
|
|
188
|
+
file: record.path,
|
|
189
|
+
lineStart: sym.lineStart,
|
|
190
|
+
lineEnd: sym.lineEnd,
|
|
191
|
+
signature: sym.signature,
|
|
192
|
+
entrypoints: sym.entrypoints,
|
|
193
|
+
roles: record.roles,
|
|
194
|
+
...summarizeCalls(sym),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
for (const m of sym.members ?? []) {
|
|
198
|
+
visit(m, owner ? `${owner}.${sym.name}` : sym.name);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
for (const sym of record.symbols) {
|
|
202
|
+
visit(sym);
|
|
203
|
+
}
|
|
204
|
+
// If no symbol in this file scored well, check file path itself
|
|
205
|
+
if (fileBest < 40) {
|
|
206
|
+
const fsScore = scoreEntry(rawLower, terms, identifiers, pathBasename(record.path), pathBasename(record.path), record.path, '', undefined, undefined);
|
|
207
|
+
if (fsScore > 0) {
|
|
208
|
+
hits.push({
|
|
209
|
+
score: Math.round(fsScore * (testFile ? 0.6 : 0.85)),
|
|
210
|
+
kind: 'file',
|
|
211
|
+
label: record.path,
|
|
212
|
+
file: record.path,
|
|
213
|
+
lineStart: 1,
|
|
214
|
+
lineEnd: 1,
|
|
215
|
+
signature: record.roles?.length ? `[${record.roles.join(', ')}]` : '(file)',
|
|
216
|
+
roles: record.roles,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
hits.sort((a, b) => b.score - a.score || a.file.localeCompare(b.file) || a.lineStart - b.lineStart);
|
|
222
|
+
return {
|
|
223
|
+
query,
|
|
224
|
+
totalMatches: hits.length,
|
|
225
|
+
hits: hits.slice(0, limit),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function pathBasename(p) {
|
|
229
|
+
const idx = p.lastIndexOf('/');
|
|
230
|
+
return idx >= 0 ? p.slice(idx + 1) : p;
|
|
231
|
+
}
|
|
232
|
+
function formatEntrypoints(entrypoints, query, maxShow = 5) {
|
|
233
|
+
if (!entrypoints?.length)
|
|
234
|
+
return '';
|
|
235
|
+
if (entrypoints.length <= maxShow)
|
|
236
|
+
return ` [${entrypoints.join(', ')}]`;
|
|
237
|
+
const qLower = cleanQuery(query).toLowerCase();
|
|
238
|
+
const qTerms = tokenize(qLower);
|
|
239
|
+
const scored = entrypoints.map((ep, idx) => {
|
|
240
|
+
const lower = ep.toLowerCase();
|
|
241
|
+
let s = 0;
|
|
242
|
+
if (qLower.length >= 2 && lower.includes(qLower))
|
|
243
|
+
s += 100;
|
|
244
|
+
for (const t of qTerms)
|
|
245
|
+
if (lower.includes(t))
|
|
246
|
+
s += 10;
|
|
247
|
+
return { ep, s, idx };
|
|
248
|
+
});
|
|
249
|
+
scored.sort((a, b) => b.s - a.s || a.idx - b.idx);
|
|
250
|
+
const shown = scored.slice(0, maxShow).map((x) => x.ep);
|
|
251
|
+
const rest = entrypoints.length - shown.length;
|
|
252
|
+
return ` [${shown.join(', ')}, +${rest} more]`;
|
|
253
|
+
}
|
|
254
|
+
export function renderSearch(result) {
|
|
255
|
+
if (result.hits.length === 0) {
|
|
256
|
+
return `No structural matches for "${result.query}". Try broader keywords, map(zoom=0), or Read/Grep for literal text.`;
|
|
257
|
+
}
|
|
258
|
+
const lines = [
|
|
259
|
+
`Atlas search "${result.query}" (${result.hits.length} of ${result.totalMatches} matches):`,
|
|
260
|
+
];
|
|
261
|
+
for (const h of result.hits) {
|
|
262
|
+
const loc = h.kind === 'file' ? h.file : `${h.file}:${h.lineStart}-${h.lineEnd}`;
|
|
263
|
+
const ep = formatEntrypoints(h.entrypoints, result.query);
|
|
264
|
+
const sig = h.signature ? ` — ${h.signature}` : '';
|
|
265
|
+
lines.push(`- ${h.label} (${loc})${ep}${sig}`);
|
|
266
|
+
const meta = [];
|
|
267
|
+
if (h.emits?.length)
|
|
268
|
+
meta.push(`emits: ${h.emits.join(', ')}`);
|
|
269
|
+
if (h.queues?.length)
|
|
270
|
+
meta.push(`queues: ${h.queues.join(', ')}`);
|
|
271
|
+
if (h.sends?.length)
|
|
272
|
+
meta.push(`sends: ${h.sends.join(', ')}`);
|
|
273
|
+
if (h.calls?.length)
|
|
274
|
+
meta.push(`calls: ${h.calls.join(', ')}`);
|
|
275
|
+
if (meta.length)
|
|
276
|
+
lines.push(` ${meta.join(' | ')}`);
|
|
277
|
+
}
|
|
278
|
+
return lines.join('\n');
|
|
279
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* The dependency audit (CIN-09): every dependency a manifest declares, with the files under the manifest's folder
|
|
4
|
+
* that import it. A runtime dependency nothing imports is dormant. Development tools, type packages (`@types/...`)
|
|
5
|
+
* and SDK dependencies are used without an import, so they are never dormant.
|
|
6
|
+
*/
|
|
7
|
+
function folderOf(manifest) {
|
|
8
|
+
const dir = path.posix.dirname(manifest);
|
|
9
|
+
return dir === '.' ? '' : dir;
|
|
10
|
+
}
|
|
11
|
+
/** Whether `file` belongs to the manifest: under its folder and not under a nested manifest of the same name. */
|
|
12
|
+
function belongsTo(file, manifest, sameName) {
|
|
13
|
+
const dir = folderOf(manifest);
|
|
14
|
+
const inside = (d) => d === '' || file.startsWith(`${d}/`);
|
|
15
|
+
if (!inside(dir))
|
|
16
|
+
return false;
|
|
17
|
+
return !sameName.some((other) => other !== manifest && folderOf(other).length > dir.length && inside(folderOf(other)));
|
|
18
|
+
}
|
|
19
|
+
/** The packages each file imports. */
|
|
20
|
+
function usage(records) {
|
|
21
|
+
const byFile = new Map();
|
|
22
|
+
for (const r of records) {
|
|
23
|
+
const packages = r.imports.filter((i) => i.kind === 'package' && i.package).map((i) => i.package);
|
|
24
|
+
if (packages.length)
|
|
25
|
+
byFile.set(r.path, new Set(packages));
|
|
26
|
+
}
|
|
27
|
+
return byFile;
|
|
28
|
+
}
|
|
29
|
+
export function dependencyAudit(records) {
|
|
30
|
+
const manifests = records.filter((r) => r.declares?.length);
|
|
31
|
+
const imports = usage(records);
|
|
32
|
+
return manifests.flatMap((m) => {
|
|
33
|
+
const sameName = manifests.filter((o) => path.posix.basename(o.path) === path.posix.basename(m.path)).map((o) => o.path);
|
|
34
|
+
const files = [...imports.keys()].filter((f) => belongsTo(f, m.path, sameName));
|
|
35
|
+
return m.declares.map((dep) => {
|
|
36
|
+
const using = files.filter((f) => imports.get(f).has(dep.name)).sort();
|
|
37
|
+
const usedImplicitly = dep.dev || dep.sdk || dep.name.startsWith('@types/');
|
|
38
|
+
return { name: dep.name, manifest: m.path, version: dep.version, dev: dep.dev, dormant: !usedImplicitly && using.length === 0, importCount: using.length, files: using };
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FileRecord } from '../model.js';
|
|
2
|
+
import { type LanguagePack } from '../packs/pack.js';
|
|
3
|
+
import type { WalkedFile } from '../walk/walk.js';
|
|
4
|
+
/** One file's record: parsed by its pack, or listed without symbols when no pack claims it or it is too large. */
|
|
5
|
+
export declare const DEFAULT_MAX_FILE_BYTES = 200000;
|
|
6
|
+
/** Data files (JSON, YAML) are only shaped, so much larger ones are read. */
|
|
7
|
+
export declare const DEFAULT_MAX_DATA_FILE_BYTES = 20000000;
|
|
8
|
+
export declare function packFor(file: string, packs: LanguagePack[]): LanguagePack | undefined;
|
|
9
|
+
/** A file no pack claims: listed as `other`, never read, never guessed at (CIN-05). */
|
|
10
|
+
export declare function unsupportedRecord(file: WalkedFile): FileRecord;
|
|
11
|
+
/** Parses one file with its pack. A ParseError is recorded on the file (CIN-04); any other error is a bug and propagates. */
|
|
12
|
+
export declare function parsedRecord(root: string, file: WalkedFile, pack: LanguagePack, maxBytes: number): Promise<FileRecord>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { ParseError } from '../packs/pack.js';
|
|
4
|
+
import { skeletonOf } from '../text/declarations.js';
|
|
5
|
+
import { estimateTokens } from '../tokens.js';
|
|
6
|
+
/** One file's record: parsed by its pack, or listed without symbols when no pack claims it or it is too large. */
|
|
7
|
+
export const DEFAULT_MAX_FILE_BYTES = 200_000;
|
|
8
|
+
/** Data files (JSON, YAML) are only shaped, so much larger ones are read. */
|
|
9
|
+
export const DEFAULT_MAX_DATA_FILE_BYTES = 20_000_000;
|
|
10
|
+
export function packFor(file, packs) {
|
|
11
|
+
return packs.find((p) => p.claims(file));
|
|
12
|
+
}
|
|
13
|
+
function base(file, language) {
|
|
14
|
+
return { path: file.path, language, sizeBytes: file.sizeBytes, mtimeMs: file.mtimeMs, symbols: [], imports: [], skeleton: '', rawTokens: 0, skeletonTokens: 0 };
|
|
15
|
+
}
|
|
16
|
+
/** A file no pack claims: listed as `other`, never read, never guessed at (CIN-05). */
|
|
17
|
+
export function unsupportedRecord(file) {
|
|
18
|
+
return base(file, 'other');
|
|
19
|
+
}
|
|
20
|
+
/** Parses one file with its pack. A ParseError is recorded on the file (CIN-04); any other error is a bug and propagates. */
|
|
21
|
+
export async function parsedRecord(root, file, pack, maxBytes) {
|
|
22
|
+
const record = base(file, pack.id);
|
|
23
|
+
if (file.sizeBytes > maxBytes)
|
|
24
|
+
return { ...record, skipped: `larger than ${Math.round(maxBytes / 1000)} KB` };
|
|
25
|
+
const content = fs.readFileSync(path.join(root, file.path), 'utf8');
|
|
26
|
+
record.rawTokens = estimateTokens(content);
|
|
27
|
+
try {
|
|
28
|
+
const parsed = await pack.parse({ path: file.path, content });
|
|
29
|
+
const skeleton = parsed.skeleton ?? skeletonOf(parsed.symbols, content);
|
|
30
|
+
return {
|
|
31
|
+
...record, symbols: parsed.symbols, skeleton, skeletonTokens: estimateTokens(skeleton),
|
|
32
|
+
imports: parsed.imports.map((i) => ({ ...i, kind: 'unresolved' })),
|
|
33
|
+
...(parsed.declares ? { declares: parsed.declares } : {}),
|
|
34
|
+
...(parsed.roles?.length ? { roles: parsed.roles } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (err instanceof ParseError)
|
|
39
|
+
return { ...record, error: err.message };
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { packFor } from './records.js';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves every import of every record against the files of this scan. It runs on every scan, also for files that
|
|
6
|
+
* were not parsed again, so an import of an unchanged file follows a file that was added or removed.
|
|
7
|
+
*/
|
|
8
|
+
function projectView(root, records) {
|
|
9
|
+
const paths = new Set(records.map((r) => r.path));
|
|
10
|
+
const sorted = [...paths].sort();
|
|
11
|
+
const texts = new Map();
|
|
12
|
+
return {
|
|
13
|
+
has: (p) => paths.has(p),
|
|
14
|
+
paths: () => sorted,
|
|
15
|
+
read: (p) => {
|
|
16
|
+
if (!texts.has(p))
|
|
17
|
+
texts.set(p, paths.has(p) ? fs.readFileSync(path.join(root, p), 'utf8') : undefined);
|
|
18
|
+
return texts.get(p);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** A reused record holds resolved imports, one per target; each import statement is resolved once again. */
|
|
23
|
+
function rawImports(imports) {
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
return imports.filter((i) => {
|
|
26
|
+
const key = `${i.line}\u0000${i.specifier}`;
|
|
27
|
+
if (seen.has(key))
|
|
28
|
+
return false;
|
|
29
|
+
seen.add(key);
|
|
30
|
+
return true;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** One import, or one per target when it points at several files. */
|
|
34
|
+
function resolved(imp, from, pack, project) {
|
|
35
|
+
const { specifier, line, typeOnly } = imp;
|
|
36
|
+
const resolution = pack?.resolve?.({ from, raw: { specifier, line, typeOnly }, project }) ?? { kind: 'unresolved' };
|
|
37
|
+
return (Array.isArray(resolution) ? resolution : [resolution]).map((r) => ({ specifier, line, ...(typeOnly ? { typeOnly } : {}), ...r }));
|
|
38
|
+
}
|
|
39
|
+
export function resolveImports(root, records, packs) {
|
|
40
|
+
const project = projectView(root, records);
|
|
41
|
+
return records.map((r) => {
|
|
42
|
+
if (r.imports.length === 0)
|
|
43
|
+
return r;
|
|
44
|
+
const pack = packFor(r.path, packs);
|
|
45
|
+
return { ...r, imports: rawImports(r.imports).flatMap((i) => resolved(i, r.path, pack, project)) };
|
|
46
|
+
});
|
|
47
|
+
}
|