contextdiet-cli 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.
- package/LICENSE +21 -0
- package/README.md +206 -0
- package/bin/contextdiet.js +4 -0
- package/dist/cli/index.d.ts +11 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +104 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/bundler/index.d.ts +49 -0
- package/dist/core/bundler/index.d.ts.map +1 -0
- package/dist/core/bundler/index.js +57 -0
- package/dist/core/bundler/index.js.map +1 -0
- package/dist/core/graph/index.d.ts +29 -0
- package/dist/core/graph/index.d.ts.map +1 -0
- package/dist/core/graph/index.js +195 -0
- package/dist/core/graph/index.js.map +1 -0
- package/dist/core/graph/selector.d.ts +29 -0
- package/dist/core/graph/selector.d.ts.map +1 -0
- package/dist/core/graph/selector.js +49 -0
- package/dist/core/graph/selector.js.map +1 -0
- package/dist/core/graph/symbol-selector.d.ts +31 -0
- package/dist/core/graph/symbol-selector.d.ts.map +1 -0
- package/dist/core/graph/symbol-selector.js +0 -0
- package/dist/core/graph/symbol-selector.js.map +1 -0
- package/dist/core/graph/types.d.ts +58 -0
- package/dist/core/graph/types.d.ts.map +1 -0
- package/dist/core/graph/types.js +11 -0
- package/dist/core/graph/types.js.map +1 -0
- package/dist/core/metrics/index.d.ts +51 -0
- package/dist/core/metrics/index.d.ts.map +1 -0
- package/dist/core/metrics/index.js +91 -0
- package/dist/core/metrics/index.js.map +1 -0
- package/dist/core/parser/index.d.ts +32 -0
- package/dist/core/parser/index.d.ts.map +1 -0
- package/dist/core/parser/index.js +274 -0
- package/dist/core/parser/index.js.map +1 -0
- package/dist/core/parser/types.d.ts +127 -0
- package/dist/core/parser/types.d.ts.map +1 -0
- package/dist/core/parser/types.js +24 -0
- package/dist/core/parser/types.js.map +1 -0
- package/dist/core/pipeline.d.ts +38 -0
- package/dist/core/pipeline.d.ts.map +1 -0
- package/dist/core/pipeline.js +69 -0
- package/dist/core/pipeline.js.map +1 -0
- package/dist/core/pruner/index.d.ts +25 -0
- package/dist/core/pruner/index.d.ts.map +1 -0
- package/dist/core/pruner/index.js +56 -0
- package/dist/core/pruner/index.js.map +1 -0
- package/dist/core/pruner/types.d.ts +18 -0
- package/dist/core/pruner/types.d.ts.map +1 -0
- package/dist/core/pruner/types.js +2 -0
- package/dist/core/pruner/types.js.map +1 -0
- package/dist/core/ranker/index.d.ts +26 -0
- package/dist/core/ranker/index.d.ts.map +1 -0
- package/dist/core/ranker/index.js +149 -0
- package/dist/core/ranker/index.js.map +1 -0
- package/dist/core/ranker/types.d.ts +61 -0
- package/dist/core/ranker/types.d.ts.map +1 -0
- package/dist/core/ranker/types.js +12 -0
- package/dist/core/ranker/types.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ast-grep–backed implementation of the {@link Parser} contract (Task 1.0).
|
|
3
|
+
*
|
|
4
|
+
* Uses `@ast-grep/napi` to parse TypeScript into a concrete syntax tree, then
|
|
5
|
+
* walks it to extract import bindings and top-level symbols. All node access is
|
|
6
|
+
* defensive: tree-sitter is error-tolerant, so we validate the tree for ERROR
|
|
7
|
+
* nodes up front and translate failures into {@link ParseError}.
|
|
8
|
+
*/
|
|
9
|
+
import { parse, Lang } from '@ast-grep/napi';
|
|
10
|
+
import { ParseError } from './types.js';
|
|
11
|
+
/** tree-sitter kinds for the declarations we surface, mapped to our SymbolKind. */
|
|
12
|
+
const DECLARATION_KINDS = new Map([
|
|
13
|
+
['class_declaration', 'class'],
|
|
14
|
+
['abstract_class_declaration', 'class'],
|
|
15
|
+
['function_declaration', 'function'],
|
|
16
|
+
['generator_function_declaration', 'function'],
|
|
17
|
+
['interface_declaration', 'interface'],
|
|
18
|
+
['type_alias_declaration', 'type'],
|
|
19
|
+
['enum_declaration', 'enum'],
|
|
20
|
+
]);
|
|
21
|
+
/** Declaration kinds that bind one-or-more names via `variable_declarator` children. */
|
|
22
|
+
const VARIABLE_DECLARATION_KINDS = new Set([
|
|
23
|
+
'lexical_declaration',
|
|
24
|
+
'variable_declaration',
|
|
25
|
+
]);
|
|
26
|
+
export class AstGrepperParser {
|
|
27
|
+
async extractImports(source, filePath) {
|
|
28
|
+
const root = this.parseOrThrow(source, filePath);
|
|
29
|
+
const imports = [];
|
|
30
|
+
for (const statement of root.findAll({ rule: { kind: 'import_statement' } })) {
|
|
31
|
+
const sourceNode = statement.field('source');
|
|
32
|
+
if (sourceNode === null)
|
|
33
|
+
continue; // defensive: malformed-but-tolerated import
|
|
34
|
+
const moduleSource = stripQuotes(sourceNode.text());
|
|
35
|
+
const clause = statement.children().find((c) => c.kind() === 'import_clause');
|
|
36
|
+
if (clause === undefined)
|
|
37
|
+
continue; // side-effect import: `import './x'` — no bindings
|
|
38
|
+
for (const child of clause.children()) {
|
|
39
|
+
this.collectClauseBindings(child, moduleSource, filePath, imports);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return sortByStart(imports);
|
|
43
|
+
}
|
|
44
|
+
async extractSymbols(source, filePath) {
|
|
45
|
+
const root = this.parseOrThrow(source, filePath);
|
|
46
|
+
const symbols = [];
|
|
47
|
+
// Only TOP-LEVEL declarations are addressable symbols: we walk the program's
|
|
48
|
+
// direct statements rather than `findAll`, so nested locals (loop variables,
|
|
49
|
+
// inner functions, block-scoped consts) are never mistaken for module symbols.
|
|
50
|
+
for (const statement of root.children()) {
|
|
51
|
+
if (statement.kind() === 'export_statement') {
|
|
52
|
+
for (const declaration of statement.children()) {
|
|
53
|
+
this.collectDeclaration(declaration, filePath, symbols, true, statement);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.collectDeclaration(statement, filePath, symbols, false, null);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return sortByStart(symbols);
|
|
61
|
+
}
|
|
62
|
+
async extractDependencies(source, filePath) {
|
|
63
|
+
const root = this.parseOrThrow(source, filePath);
|
|
64
|
+
const deps = [];
|
|
65
|
+
// `import … from 'x'` — every import_statement carries a `source` field
|
|
66
|
+
// (including side-effect imports `import 'x'`).
|
|
67
|
+
for (const statement of root.findAll({ rule: { kind: 'import_statement' } })) {
|
|
68
|
+
const sourceNode = statement.field('source');
|
|
69
|
+
if (sourceNode === null)
|
|
70
|
+
continue;
|
|
71
|
+
deps.push({
|
|
72
|
+
kind: 'import',
|
|
73
|
+
source: stripQuotes(sourceNode.text()),
|
|
74
|
+
filePath,
|
|
75
|
+
range: toRange(statement.range()),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// Re-exports: `export … from 'x'`, `export * from 'x'`, `export * as ns from 'x'`.
|
|
79
|
+
// A plain `export const …` has no `source` field and is NOT a dependency.
|
|
80
|
+
for (const statement of root.findAll({ rule: { kind: 'export_statement' } })) {
|
|
81
|
+
const sourceNode = statement.field('source');
|
|
82
|
+
if (sourceNode === null)
|
|
83
|
+
continue;
|
|
84
|
+
deps.push({
|
|
85
|
+
kind: 're-export',
|
|
86
|
+
source: stripQuotes(sourceNode.text()),
|
|
87
|
+
filePath,
|
|
88
|
+
range: toRange(statement.range()),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return sortByStart(deps);
|
|
92
|
+
}
|
|
93
|
+
async extractImportStatements(source, filePath) {
|
|
94
|
+
const root = this.parseOrThrow(source, filePath);
|
|
95
|
+
const statements = [];
|
|
96
|
+
for (const statement of root.findAll({ rule: { kind: 'import_statement' } })) {
|
|
97
|
+
const sourceNode = statement.field('source');
|
|
98
|
+
if (sourceNode === null)
|
|
99
|
+
continue;
|
|
100
|
+
const clause = statement.children().find((c) => c.kind() === 'import_clause');
|
|
101
|
+
statements.push({
|
|
102
|
+
source: stripQuotes(sourceNode.text()),
|
|
103
|
+
localNames: clause === undefined ? [] : collectLocalNames(clause),
|
|
104
|
+
filePath,
|
|
105
|
+
range: toRange(statement.range()),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return sortByStart(statements);
|
|
109
|
+
}
|
|
110
|
+
async collectReferences(source, filePath, ranges) {
|
|
111
|
+
const used = new Set();
|
|
112
|
+
if (ranges.length === 0)
|
|
113
|
+
return used;
|
|
114
|
+
const root = this.parseOrThrow(source, filePath);
|
|
115
|
+
// Value references are `identifier`; type references (for type-only imports)
|
|
116
|
+
// are `type_identifier`. Property names (`obj.prop`) are `property_identifier`
|
|
117
|
+
// and intentionally excluded — they are not import bindings.
|
|
118
|
+
const identifiers = [
|
|
119
|
+
...root.findAll({ rule: { kind: 'identifier' } }),
|
|
120
|
+
...root.findAll({ rule: { kind: 'type_identifier' } }),
|
|
121
|
+
];
|
|
122
|
+
for (const node of identifiers) {
|
|
123
|
+
const start = node.range().start.index;
|
|
124
|
+
for (const range of ranges) {
|
|
125
|
+
if (start >= range.start.index && start < range.end.index) {
|
|
126
|
+
used.add(node.text());
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return used;
|
|
132
|
+
}
|
|
133
|
+
sliceNode(source, range) {
|
|
134
|
+
return source.slice(range.start.index, range.end.index);
|
|
135
|
+
}
|
|
136
|
+
// --- internals ----------------------------------------------------------
|
|
137
|
+
/** Parse to a root node, translating any syntax error into a {@link ParseError}. */
|
|
138
|
+
parseOrThrow(source, filePath) {
|
|
139
|
+
let root;
|
|
140
|
+
try {
|
|
141
|
+
root = parse(Lang.TypeScript, source).root();
|
|
142
|
+
}
|
|
143
|
+
catch (cause) {
|
|
144
|
+
throw new ParseError(`Failed to parse ${filePath}`, filePath, { cause });
|
|
145
|
+
}
|
|
146
|
+
if (hasErrorNode(root)) {
|
|
147
|
+
throw new ParseError(`Malformed syntax in ${filePath}`, filePath);
|
|
148
|
+
}
|
|
149
|
+
return root;
|
|
150
|
+
}
|
|
151
|
+
/** Translate one child of an `import_clause` into zero or more bindings. */
|
|
152
|
+
collectClauseBindings(child, source, filePath, out) {
|
|
153
|
+
switch (child.kind()) {
|
|
154
|
+
case 'identifier': {
|
|
155
|
+
// `import path from '...'`
|
|
156
|
+
const name = child.text();
|
|
157
|
+
out.push(this.makeImport('default', name, name, source, filePath, child.range()));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
case 'namespace_import': {
|
|
161
|
+
// `import * as os from '...'`
|
|
162
|
+
const id = child.children().find((n) => n.kind() === 'identifier');
|
|
163
|
+
if (id === undefined)
|
|
164
|
+
return;
|
|
165
|
+
out.push(this.makeImport('namespace', id.text(), '*', source, filePath, child.range()));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
case 'named_imports': {
|
|
169
|
+
// `import { a, b as c } from '...'`
|
|
170
|
+
for (const spec of child.children().filter((n) => n.kind() === 'import_specifier')) {
|
|
171
|
+
const nameNode = spec.field('name');
|
|
172
|
+
if (nameNode === null)
|
|
173
|
+
continue;
|
|
174
|
+
const importedName = nameNode.text();
|
|
175
|
+
const aliasNode = spec.field('alias');
|
|
176
|
+
const localName = aliasNode === null ? importedName : aliasNode.text();
|
|
177
|
+
out.push(this.makeImport('named', localName, importedName, source, filePath, spec.range()));
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
default:
|
|
182
|
+
return; // `import`/`from`/`,`/`type` keyword tokens — nothing to bind
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
makeImport(kind, localName, importedName, source, filePath, range) {
|
|
186
|
+
return { kind, localName, importedName, source, filePath, range: toRange(range) };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Turn one top-level declaration into zero or more symbols.
|
|
190
|
+
*
|
|
191
|
+
* `exported` and `exportStatement` come from the caller's position in the tree
|
|
192
|
+
* (whether this declaration sat inside an `export_statement`). For exported
|
|
193
|
+
* declarations the range widens to the whole `export …` statement so a slice
|
|
194
|
+
* reproduces a self-contained, re-emittable chunk (with the `export` keyword).
|
|
195
|
+
*/
|
|
196
|
+
collectDeclaration(node, filePath, out, exported, exportStatement) {
|
|
197
|
+
const nodeKind = String(node.kind());
|
|
198
|
+
const range = toRange(exported && exportStatement !== null ? exportStatement.range() : node.range());
|
|
199
|
+
const mapped = DECLARATION_KINDS.get(nodeKind);
|
|
200
|
+
if (mapped !== undefined) {
|
|
201
|
+
const nameNode = node.field('name');
|
|
202
|
+
if (nameNode === null)
|
|
203
|
+
return; // anonymous default export — no addressable symbol
|
|
204
|
+
out.push({ name: nameNode.text(), kind: mapped, exported, filePath, range });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (VARIABLE_DECLARATION_KINDS.has(nodeKind)) {
|
|
208
|
+
// `const`/`let`/`var` may bind several names in one statement.
|
|
209
|
+
for (const declarator of node.children().filter((c) => c.kind() === 'variable_declarator')) {
|
|
210
|
+
const nameNode = declarator.field('name');
|
|
211
|
+
if (nameNode === null)
|
|
212
|
+
continue; // destructuring pattern — out of scope for Task 1.0
|
|
213
|
+
out.push({ name: nameNode.text(), kind: 'variable', exported, filePath, range });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// --- module-private helpers -----------------------------------------------
|
|
219
|
+
/** Collect every local binding name introduced by an `import_clause`. */
|
|
220
|
+
function collectLocalNames(clause) {
|
|
221
|
+
const names = [];
|
|
222
|
+
for (const child of clause.children()) {
|
|
223
|
+
switch (child.kind()) {
|
|
224
|
+
case 'identifier': // default import
|
|
225
|
+
names.push(child.text());
|
|
226
|
+
break;
|
|
227
|
+
case 'namespace_import': {
|
|
228
|
+
const id = child.children().find((n) => n.kind() === 'identifier');
|
|
229
|
+
if (id !== undefined)
|
|
230
|
+
names.push(id.text());
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case 'named_imports':
|
|
234
|
+
for (const spec of child.children().filter((n) => n.kind() === 'import_specifier')) {
|
|
235
|
+
const local = spec.field('alias') ?? spec.field('name');
|
|
236
|
+
if (local !== null)
|
|
237
|
+
names.push(local.text());
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
default:
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return names;
|
|
245
|
+
}
|
|
246
|
+
/** Depth-first scan for tree-sitter ERROR nodes (the signal of malformed syntax). */
|
|
247
|
+
function hasErrorNode(node) {
|
|
248
|
+
if (node.kind() === 'ERROR')
|
|
249
|
+
return true;
|
|
250
|
+
return node.children().some(hasErrorNode);
|
|
251
|
+
}
|
|
252
|
+
/** Strip a single matching pair of surrounding quotes (single, double, or backtick). */
|
|
253
|
+
function stripQuotes(text) {
|
|
254
|
+
if (text.length >= 2) {
|
|
255
|
+
const first = text[0];
|
|
256
|
+
const last = text[text.length - 1];
|
|
257
|
+
if (first === last && (first === "'" || first === '"' || first === '`')) {
|
|
258
|
+
return text.slice(1, -1);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return text;
|
|
262
|
+
}
|
|
263
|
+
/** Normalize a native range into our plain, structurally-cloned {@link Range}. */
|
|
264
|
+
function toRange(range) {
|
|
265
|
+
return {
|
|
266
|
+
start: { line: range.start.line, column: range.start.column, index: range.start.index },
|
|
267
|
+
end: { line: range.end.line, column: range.end.column, index: range.end.index },
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/** Stable source-order sort by start offset. */
|
|
271
|
+
function sortByStart(items) {
|
|
272
|
+
return items.sort((a, b) => a.range.start.index - b.range.start.index);
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/parser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAe,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAYxC,mFAAmF;AACnF,MAAM,iBAAiB,GAAoC,IAAI,GAAG,CAAC;IACjE,CAAC,mBAAmB,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QACvF,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE;KAChF,CAAC;AACJ,CAAC;AAED,gDAAgD;AAChD,SAAS,WAAW,CAA6B,KAAU;IACzD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core parsing contracts for ContextDiet.
|
|
3
|
+
*
|
|
4
|
+
* The rest of the engine (graph resolver, ranker, pruner, bundler) depends only
|
|
5
|
+
* on these interfaces — never on a concrete parser. That indirection is what lets
|
|
6
|
+
* us swap the AST backend (ast-grep today, tree-sitter/SWC later) without a rewrite.
|
|
7
|
+
*/
|
|
8
|
+
/** A single point in a source file, mirroring ast-grep's position triple. */
|
|
9
|
+
export interface Position {
|
|
10
|
+
/** Zero-based line number. */
|
|
11
|
+
readonly line: number;
|
|
12
|
+
/** Zero-based column (in UTF-8 code units). */
|
|
13
|
+
readonly column: number;
|
|
14
|
+
/** Absolute offset from the start of the source. */
|
|
15
|
+
readonly index: number;
|
|
16
|
+
}
|
|
17
|
+
/** A half-open `[start, end)` span within a source file. */
|
|
18
|
+
export interface Range {
|
|
19
|
+
readonly start: Position;
|
|
20
|
+
readonly end: Position;
|
|
21
|
+
}
|
|
22
|
+
/** How a binding was brought into scope. */
|
|
23
|
+
export type ImportKind = 'named' | 'default' | 'namespace';
|
|
24
|
+
/**
|
|
25
|
+
* A resolved import binding.
|
|
26
|
+
*
|
|
27
|
+
* `localName` is the identifier usable in this file; `importedName` is the name
|
|
28
|
+
* as exported by the source module. They differ only for aliased named imports
|
|
29
|
+
* (`import { Foo as Bar }` → importedName `Foo`, localName `Bar`). For default
|
|
30
|
+
* imports both equal the local name; for namespace imports `importedName` is `*`.
|
|
31
|
+
*/
|
|
32
|
+
export interface ImportNode {
|
|
33
|
+
readonly kind: ImportKind;
|
|
34
|
+
readonly localName: string;
|
|
35
|
+
readonly importedName: string;
|
|
36
|
+
/** The module specifier, unquoted (e.g. `node:fs/promises`, `./foo`). */
|
|
37
|
+
readonly source: string;
|
|
38
|
+
/** The file this import was found in. */
|
|
39
|
+
readonly filePath: string;
|
|
40
|
+
/** Span of the specific binding (specifier / identifier), not the whole statement. */
|
|
41
|
+
readonly range: Range;
|
|
42
|
+
}
|
|
43
|
+
/** Whether an outward module reference came from an `import` or a re-`export`. */
|
|
44
|
+
export type DependencyRefKind = 'import' | 're-export';
|
|
45
|
+
/**
|
|
46
|
+
* A file-level outward module reference — the raw specifier a file points at,
|
|
47
|
+
* before disk resolution. Covers both `import … from 'x'` and
|
|
48
|
+
* `export … from 'x'` (re-exports), since both create a dependency edge.
|
|
49
|
+
*
|
|
50
|
+
* This is deliberately coarser than {@link ImportNode}: the graph resolver only
|
|
51
|
+
* needs "which modules does this file reach", not per-binding detail.
|
|
52
|
+
*/
|
|
53
|
+
export interface DependencyRef {
|
|
54
|
+
readonly kind: DependencyRefKind;
|
|
55
|
+
/** The module specifier, unquoted (e.g. `./b`, `node:fs`). */
|
|
56
|
+
readonly source: string;
|
|
57
|
+
readonly filePath: string;
|
|
58
|
+
readonly range: Range;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A whole `import … from 'x'` statement, at statement granularity.
|
|
62
|
+
*
|
|
63
|
+
* The pruner needs the FULL statement span (`range`) to re-emit a syntactically
|
|
64
|
+
* valid import, plus every local binding it introduces (`localNames`) to decide
|
|
65
|
+
* whether any kept symbol still references it. This complements {@link ImportNode}
|
|
66
|
+
* (which is per-binding and finer-grained).
|
|
67
|
+
*/
|
|
68
|
+
export interface ImportStatement {
|
|
69
|
+
/** The module specifier, unquoted. */
|
|
70
|
+
readonly source: string;
|
|
71
|
+
/** Every local binding introduced (default, namespace, and named/aliased). */
|
|
72
|
+
readonly localNames: readonly string[];
|
|
73
|
+
readonly filePath: string;
|
|
74
|
+
/** Span of the entire import statement. */
|
|
75
|
+
readonly range: Range;
|
|
76
|
+
}
|
|
77
|
+
/** The kind of a top-level declaration the pruner can keep or drop. */
|
|
78
|
+
export type SymbolKind = 'class' | 'function' | 'variable' | 'interface' | 'type' | 'enum';
|
|
79
|
+
/**
|
|
80
|
+
* A top-level declaration.
|
|
81
|
+
*
|
|
82
|
+
* For exported declarations `range` spans the entire `export …` statement, so
|
|
83
|
+
* that {@link Parser.sliceNode} reproduces a self-contained, re-emittable chunk.
|
|
84
|
+
* For internal declarations `range` spans the declaration itself.
|
|
85
|
+
*/
|
|
86
|
+
export interface SymbolNode {
|
|
87
|
+
readonly name: string;
|
|
88
|
+
readonly kind: SymbolKind;
|
|
89
|
+
readonly exported: boolean;
|
|
90
|
+
readonly filePath: string;
|
|
91
|
+
readonly range: Range;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The AST backend contract. Every method is source-in / data-out and holds no
|
|
95
|
+
* cross-call state, so implementations are trivially parallelizable per file.
|
|
96
|
+
*/
|
|
97
|
+
export interface Parser {
|
|
98
|
+
extractImports(source: string, filePath: string): Promise<ImportNode[]>;
|
|
99
|
+
extractSymbols(source: string, filePath: string): Promise<SymbolNode[]>;
|
|
100
|
+
/** File-level outward module references (imports + re-exports) for graph edges. */
|
|
101
|
+
extractDependencies(source: string, filePath: string): Promise<DependencyRef[]>;
|
|
102
|
+
/** Whole import statements (span + local bindings) for dead-import elimination. */
|
|
103
|
+
extractImportStatements(source: string, filePath: string): Promise<ImportStatement[]>;
|
|
104
|
+
/**
|
|
105
|
+
* The set of identifier names referenced anywhere inside the given ranges.
|
|
106
|
+
* Used by the pruner to keep only the imports that surviving symbols still use.
|
|
107
|
+
*/
|
|
108
|
+
collectReferences(source: string, filePath: string, ranges: readonly Range[]): Promise<Set<string>>;
|
|
109
|
+
/** Reproduce the exact source text covered by `range`. */
|
|
110
|
+
sliceNode(source: string, range: Range): string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Raised when a source file cannot be parsed into a clean tree (syntax errors).
|
|
114
|
+
*
|
|
115
|
+
* The parser NEVER throws a raw/native error at callers: tree-sitter is
|
|
116
|
+
* error-tolerant and would otherwise return a partial, silently-wrong tree.
|
|
117
|
+
* We detect ERROR nodes and surface this explicit, catchable domain error
|
|
118
|
+
* instead so the pipeline can skip the file rather than crash.
|
|
119
|
+
*/
|
|
120
|
+
export declare class ParseError extends Error {
|
|
121
|
+
readonly name = "ParseError";
|
|
122
|
+
readonly filePath: string;
|
|
123
|
+
constructor(message: string, filePath: string, options?: {
|
|
124
|
+
cause?: unknown;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/parser/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,6EAA6E;AAC7E,MAAM,WAAW,QAAQ;IACvB,8BAA8B;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,4DAA4D;AAC5D,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC;CACxB;AAED,4CAA4C;AAC5C,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,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B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACxE,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACxE,mFAAmF;IACnF,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAChF,mFAAmF;IACnF,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IACtF;;;OAGG;IACH,iBAAiB,CACf,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS,KAAK,EAAE,GACvB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACxB,0DAA0D;IAC1D,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;CACjD;AAED;;;;;;;GAOG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAkB,IAAI,gBAAgB;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,YAAY,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAG3E;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core parsing contracts for ContextDiet.
|
|
3
|
+
*
|
|
4
|
+
* The rest of the engine (graph resolver, ranker, pruner, bundler) depends only
|
|
5
|
+
* on these interfaces — never on a concrete parser. That indirection is what lets
|
|
6
|
+
* us swap the AST backend (ast-grep today, tree-sitter/SWC later) without a rewrite.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Raised when a source file cannot be parsed into a clean tree (syntax errors).
|
|
10
|
+
*
|
|
11
|
+
* The parser NEVER throws a raw/native error at callers: tree-sitter is
|
|
12
|
+
* error-tolerant and would otherwise return a partial, silently-wrong tree.
|
|
13
|
+
* We detect ERROR nodes and surface this explicit, catchable domain error
|
|
14
|
+
* instead so the pipeline can skip the file rather than crash.
|
|
15
|
+
*/
|
|
16
|
+
export class ParseError extends Error {
|
|
17
|
+
name = 'ParseError';
|
|
18
|
+
filePath;
|
|
19
|
+
constructor(message, filePath, options) {
|
|
20
|
+
super(message, options);
|
|
21
|
+
this.filePath = filePath;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/parser/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA8HH;;;;;;;GAOG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjB,IAAI,GAAG,YAAY,CAAC;IAC7B,QAAQ,CAAS;IAE1B,YAAY,OAAe,EAAE,QAAgB,EAAE,OAA6B;QAC1E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline orchestrator (Task 4 — assembly).
|
|
3
|
+
*
|
|
4
|
+
* The single high-level entry point that ties every stage together:
|
|
5
|
+
*
|
|
6
|
+
* Graph Resolution → Lexical Ranking → Selection → AST Pruning
|
|
7
|
+
* → Markdown Bundling → Metrics Compilation
|
|
8
|
+
*
|
|
9
|
+
* It depends only on the module contracts, so any stage (parser backend, ranker
|
|
10
|
+
* strategy) can be swapped without touching this file.
|
|
11
|
+
*/
|
|
12
|
+
import type { ReductionMetrics } from './metrics/index.js';
|
|
13
|
+
export interface TrimOptions {
|
|
14
|
+
/** Dependency-graph traversal depth from each seed file. Default `2`. */
|
|
15
|
+
readonly hops?: number;
|
|
16
|
+
/** Optional cap on the number of ranked seeds. */
|
|
17
|
+
readonly seedLimit?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface TrimResult {
|
|
20
|
+
readonly rootDir: string;
|
|
21
|
+
readonly focus: string;
|
|
22
|
+
/** The final dense Markdown stream. */
|
|
23
|
+
readonly bundle: string;
|
|
24
|
+
readonly metrics: ReductionMetrics;
|
|
25
|
+
/** Total source files discovered under the root. */
|
|
26
|
+
readonly totalFiles: number;
|
|
27
|
+
/** Repo-relative paths of the files that survived, sorted. */
|
|
28
|
+
readonly keptFiles: readonly string[];
|
|
29
|
+
/** How many seed symbols the ranker matched for the focus. */
|
|
30
|
+
readonly seedCount: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Trim a codebase to just the code relevant to `focus`, returning the dense
|
|
34
|
+
* bundle plus efficiency metrics. Pure w.r.t. the filesystem except for reading
|
|
35
|
+
* the source files under `rootDir` (never writes).
|
|
36
|
+
*/
|
|
37
|
+
export declare function trim(rootDir: string, focus: string, options?: TrimOptions): Promise<TrimResult>;
|
|
38
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/core/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,WAAW,WAAW;IAC1B,yEAAyE;IACzE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,kDAAkD;IAClD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;IACnC,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAsB,IAAI,CACxB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,UAAU,CAAC,CAkDrB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline orchestrator (Task 4 — assembly).
|
|
3
|
+
*
|
|
4
|
+
* The single high-level entry point that ties every stage together:
|
|
5
|
+
*
|
|
6
|
+
* Graph Resolution → Lexical Ranking → Selection → AST Pruning
|
|
7
|
+
* → Markdown Bundling → Metrics Compilation
|
|
8
|
+
*
|
|
9
|
+
* It depends only on the module contracts, so any stage (parser backend, ranker
|
|
10
|
+
* strategy) can be swapped without touching this file.
|
|
11
|
+
*/
|
|
12
|
+
import { promises as fs } from 'node:fs';
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
import { DependencyGraphResolver } from './graph/index.js';
|
|
15
|
+
import { ReferenceClosureSelector } from './graph/symbol-selector.js';
|
|
16
|
+
import { AstPruner } from './pruner/index.js';
|
|
17
|
+
import { MarkdownBundler } from './bundler/index.js';
|
|
18
|
+
import { LexicalRanker } from './ranker/index.js';
|
|
19
|
+
import { computeReduction } from './metrics/index.js';
|
|
20
|
+
/**
|
|
21
|
+
* Trim a codebase to just the code relevant to `focus`, returning the dense
|
|
22
|
+
* bundle plus efficiency metrics. Pure w.r.t. the filesystem except for reading
|
|
23
|
+
* the source files under `rootDir` (never writes).
|
|
24
|
+
*/
|
|
25
|
+
export async function trim(rootDir, focus, options = {}) {
|
|
26
|
+
const root = path.resolve(rootDir);
|
|
27
|
+
// 1. Graph resolution.
|
|
28
|
+
const graph = await new DependencyGraphResolver().buildGraph(root);
|
|
29
|
+
// Read every discovered file once: the baseline for metrics AND the source of
|
|
30
|
+
// truth the pruner slices from.
|
|
31
|
+
const sources = new Map();
|
|
32
|
+
for (const filePath of graph.nodes.keys()) {
|
|
33
|
+
sources.set(filePath, await fs.readFile(filePath, 'utf8'));
|
|
34
|
+
}
|
|
35
|
+
const baseline = [...sources.values()].join('\n');
|
|
36
|
+
// 2. Lexical ranking.
|
|
37
|
+
const allSymbols = [...graph.nodes.values()].flatMap((node) => node.symbols);
|
|
38
|
+
const ranker = new LexicalRanker(options.seedLimit === undefined ? {} : { limit: options.seedLimit });
|
|
39
|
+
const seeds = ranker.determineSeeds(focus, allSymbols);
|
|
40
|
+
// 3. Selection (symbol-level reference closure — ADR-016).
|
|
41
|
+
const selection = await new ReferenceClosureSelector().select(seeds, graph, sources, {
|
|
42
|
+
hops: options.hops ?? 2,
|
|
43
|
+
});
|
|
44
|
+
// 4. AST pruning (one bundle file per surviving source file).
|
|
45
|
+
const pruner = new AstPruner();
|
|
46
|
+
const bundleFiles = [];
|
|
47
|
+
for (const [filePath, keep] of selection) {
|
|
48
|
+
const source = sources.get(filePath);
|
|
49
|
+
if (source === undefined)
|
|
50
|
+
continue;
|
|
51
|
+
const pruned = await pruner.prune(source, filePath, keep);
|
|
52
|
+
if (pruned.trim().length === 0)
|
|
53
|
+
continue;
|
|
54
|
+
bundleFiles.push({ path: path.relative(root, filePath), content: pruned });
|
|
55
|
+
}
|
|
56
|
+
// 5. Bundling + 6. Metrics.
|
|
57
|
+
const bundle = new MarkdownBundler({ sortByPath: true }).bundle(bundleFiles);
|
|
58
|
+
const metrics = computeReduction(baseline, bundle);
|
|
59
|
+
return {
|
|
60
|
+
rootDir: root,
|
|
61
|
+
focus,
|
|
62
|
+
bundle,
|
|
63
|
+
metrics,
|
|
64
|
+
totalFiles: graph.nodes.size,
|
|
65
|
+
keptFiles: bundleFiles.map((file) => file.path).sort(),
|
|
66
|
+
seedCount: seeds.length,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/core/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAyBtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,OAAe,EACf,KAAa,EACb,OAAO,GAAgB,EAAE;IAEzB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnC,uBAAuB;IACvB,MAAM,KAAK,GAAG,MAAM,IAAI,uBAAuB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAEnE,8EAA8E;IAC9E,gCAAgC;IAChC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,EAA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QAC1D,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QACzC,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,4BAA4B;IAC5B,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7E,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAEnD,OAAO;QACL,OAAO,EAAE,IAAI;QACb,KAAK;QACL,MAAM;QACN,OAAO;QACP,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI;QAC5B,SAAS,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE;QACtD,SAAS,EAAE,KAAK,CAAC,MAAM;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AstPruner (Task 3.5).
|
|
3
|
+
*
|
|
4
|
+
* Reconstructs a file down to just the symbols the Selector kept, plus the
|
|
5
|
+
* imports those symbols still reference. Strategy:
|
|
6
|
+
*
|
|
7
|
+
* 1. Parse top-level symbols and whole import statements.
|
|
8
|
+
* 2. Keep the symbols whose names are in the keep-set.
|
|
9
|
+
* 3. Find which identifiers the kept symbols reference, and keep only the
|
|
10
|
+
* import statements that introduce at least one referenced binding
|
|
11
|
+
* (dead-import elimination).
|
|
12
|
+
* 4. Re-emit kept imports + kept symbols in original source order, each sliced
|
|
13
|
+
* verbatim via `Parser.sliceNode`.
|
|
14
|
+
*
|
|
15
|
+
* Because it only ever *omits* whole declarations and re-emits kept ones
|
|
16
|
+
* unchanged, the pruner cannot introduce a syntax error into what it emits.
|
|
17
|
+
*/
|
|
18
|
+
import type { Parser } from '../parser/types.js';
|
|
19
|
+
import type { Pruner } from './types.js';
|
|
20
|
+
export declare class AstPruner implements Pruner {
|
|
21
|
+
private readonly parser;
|
|
22
|
+
constructor(parser?: Parser);
|
|
23
|
+
prune(source: string, filePath: string, keep: ReadonlySet<string>): Promise<string>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/pruner/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAS,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,qBAAa,SAAU,YAAW,MAAM;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC,YAAY,MAAM,GAAE,MAA+B,EAElD;IAEK,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAyBxF;CACF"}
|