@milo4jo/contextkit 0.1.2 → 0.5.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/README.md +269 -72
- package/dist/commands/index-cmd.d.ts.map +1 -1
- package/dist/commands/index-cmd.js +10 -2
- package/dist/commands/index-cmd.js.map +1 -1
- package/dist/commands/mcp.d.ts +8 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +23 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/select.d.ts.map +1 -1
- package/dist/commands/select.js +15 -9
- package/dist/commands/select.js.map +1 -1
- package/dist/commands/watch.d.ts +8 -0
- package/dist/commands/watch.d.ts.map +1 -0
- package/dist/commands/watch.js +171 -0
- package/dist/commands/watch.js.map +1 -0
- package/dist/config/index.d.ts +11 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +11 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/validation.d.ts +33 -0
- package/dist/config/validation.d.ts.map +1 -0
- package/dist/config/validation.js +241 -0
- package/dist/config/validation.js.map +1 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +11 -2
- package/dist/db/index.js.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/indexer/discovery.d.ts +7 -0
- package/dist/indexer/discovery.d.ts.map +1 -1
- package/dist/indexer/discovery.js +9 -0
- package/dist/indexer/discovery.js.map +1 -1
- package/dist/indexer/index.d.ts +17 -3
- package/dist/indexer/index.d.ts.map +1 -1
- package/dist/indexer/index.js +135 -24
- package/dist/indexer/index.js.map +1 -1
- package/dist/mcp/index.d.ts +7 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +7 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +20 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +252 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp-server.d.ts +18 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +22 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/retrieval/imports.d.ts +76 -0
- package/dist/retrieval/imports.d.ts.map +1 -0
- package/dist/retrieval/imports.js +258 -0
- package/dist/retrieval/imports.js.map +1 -0
- package/dist/selector/budget.d.ts +2 -0
- package/dist/selector/budget.d.ts.map +1 -1
- package/dist/selector/budget.js +19 -6
- package/dist/selector/budget.js.map +1 -1
- package/dist/selector/formatter.d.ts +15 -0
- package/dist/selector/formatter.d.ts.map +1 -1
- package/dist/selector/formatter.js +139 -5
- package/dist/selector/formatter.js.map +1 -1
- package/dist/selector/index.d.ts +11 -4
- package/dist/selector/index.d.ts.map +1 -1
- package/dist/selector/index.js +67 -12
- package/dist/selector/index.js.map +1 -1
- package/dist/selector/scoring.d.ts +35 -5
- package/dist/selector/scoring.d.ts.map +1 -1
- package/dist/selector/scoring.js +290 -23
- package/dist/selector/scoring.js.map +1 -1
- package/dist/utils/streams.d.ts +4 -0
- package/dist/utils/streams.d.ts.map +1 -1
- package/dist/utils/streams.js +7 -0
- package/dist/utils/streams.js.map +1 -1
- package/package.json +18 -6
- package/dist/commands/source.d.ts +0 -3
- package/dist/commands/source.d.ts.map +0 -1
- package/dist/commands/source.js +0 -153
- package/dist/commands/source.js.map +0 -1
- package/dist/utils/output.d.ts +0 -42
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/output.js +0 -62
- package/dist/utils/output.js.map +0 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Output Formatter Module
|
|
3
3
|
*
|
|
4
4
|
* Formats selected chunks for display.
|
|
5
|
+
* Supports multiple output formats: markdown, xml, json, plain
|
|
5
6
|
*/
|
|
6
7
|
/**
|
|
7
8
|
* Format selection results for output
|
|
@@ -98,12 +99,14 @@ export function formatWithExplanation(query, result, totalConsidered, timeMs) {
|
|
|
98
99
|
const base = formatOutput(query, result, totalConsidered, timeMs);
|
|
99
100
|
// Add explanation section
|
|
100
101
|
const explanations = result.chunks.map((chunk) => {
|
|
101
|
-
const { similarity,
|
|
102
|
+
const { similarity, pathMatch, contentMatch, symbolMatch, fileTypeBoost } = chunk.scoreBreakdown;
|
|
102
103
|
return ` ${chunk.filePath}:${chunk.startLine}
|
|
103
|
-
similarity:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
similarity: ${(similarity * 100).toFixed(1)}%
|
|
105
|
+
path_match: ${(pathMatch * 100).toFixed(1)}%
|
|
106
|
+
content_match: ${(contentMatch * 100).toFixed(1)}%
|
|
107
|
+
symbol_match: ${(symbolMatch * 100).toFixed(1)}%
|
|
108
|
+
file_type: ${(fileTypeBoost * 100).toFixed(1)}%
|
|
109
|
+
→ score: ${(chunk.score * 100).toFixed(1)}%`;
|
|
107
110
|
});
|
|
108
111
|
const explainSection = '\n\n## Scoring Details\n\n' + explanations.join('\n\n');
|
|
109
112
|
return {
|
|
@@ -111,4 +114,135 @@ export function formatWithExplanation(query, result, totalConsidered, timeMs) {
|
|
|
111
114
|
data: base.data,
|
|
112
115
|
};
|
|
113
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Format output as XML (Claude prefers XML for structured content)
|
|
119
|
+
*/
|
|
120
|
+
export function formatAsXml(query, result, totalConsidered, timeMs) {
|
|
121
|
+
const { chunks, totalTokens } = result;
|
|
122
|
+
// Group chunks by file
|
|
123
|
+
const fileGroups = new Map();
|
|
124
|
+
for (const chunk of chunks) {
|
|
125
|
+
const existing = fileGroups.get(chunk.filePath) || [];
|
|
126
|
+
existing.push(chunk);
|
|
127
|
+
fileGroups.set(chunk.filePath, existing);
|
|
128
|
+
}
|
|
129
|
+
// Build XML output
|
|
130
|
+
const xmlParts = ['<context>'];
|
|
131
|
+
xmlParts.push(` <query>${escapeXml(query)}</query>`);
|
|
132
|
+
xmlParts.push(' <files>');
|
|
133
|
+
for (const [filePath, fileChunks] of fileGroups) {
|
|
134
|
+
// Sort chunks by line number within file
|
|
135
|
+
fileChunks.sort((a, b) => a.startLine - b.startLine);
|
|
136
|
+
xmlParts.push(` <file path="${escapeXml(filePath)}">`);
|
|
137
|
+
for (const chunk of fileChunks) {
|
|
138
|
+
xmlParts.push(` <chunk lines="${chunk.startLine}-${chunk.endLine}" tokens="${chunk.tokens}">`);
|
|
139
|
+
xmlParts.push(`<![CDATA[${chunk.content}]]>`);
|
|
140
|
+
xmlParts.push(' </chunk>');
|
|
141
|
+
}
|
|
142
|
+
xmlParts.push(' </file>');
|
|
143
|
+
}
|
|
144
|
+
xmlParts.push(' </files>');
|
|
145
|
+
xmlParts.push(` <stats tokens="${totalTokens}" chunks="${chunks.length}" files="${fileGroups.size}" time_ms="${timeMs}" />`);
|
|
146
|
+
xmlParts.push('</context>');
|
|
147
|
+
const text = xmlParts.join('\n');
|
|
148
|
+
// Build structured data (same as markdown)
|
|
149
|
+
const chunkInfos = chunks.map((c) => ({
|
|
150
|
+
file: c.filePath,
|
|
151
|
+
lines: [c.startLine, c.endLine],
|
|
152
|
+
tokens: c.tokens,
|
|
153
|
+
score: Math.round(c.score * 1000) / 1000,
|
|
154
|
+
}));
|
|
155
|
+
const data = {
|
|
156
|
+
query,
|
|
157
|
+
context: text,
|
|
158
|
+
chunks: chunkInfos,
|
|
159
|
+
stats: {
|
|
160
|
+
totalTokens,
|
|
161
|
+
chunksConsidered: totalConsidered,
|
|
162
|
+
chunksIncluded: chunks.length,
|
|
163
|
+
filesIncluded: fileGroups.size,
|
|
164
|
+
timeMs,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
return { text, data };
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Format output as plain text (optimized for clipboard/pasting)
|
|
171
|
+
*/
|
|
172
|
+
export function formatAsPlain(query, result, totalConsidered, timeMs) {
|
|
173
|
+
const { chunks, totalTokens } = result;
|
|
174
|
+
// Group chunks by file
|
|
175
|
+
const fileGroups = new Map();
|
|
176
|
+
for (const chunk of chunks) {
|
|
177
|
+
const existing = fileGroups.get(chunk.filePath) || [];
|
|
178
|
+
existing.push(chunk);
|
|
179
|
+
fileGroups.set(chunk.filePath, existing);
|
|
180
|
+
}
|
|
181
|
+
// Build plain text output (no markdown formatting)
|
|
182
|
+
const textParts = [];
|
|
183
|
+
for (const [filePath, fileChunks] of fileGroups) {
|
|
184
|
+
// Sort chunks by line number within file
|
|
185
|
+
fileChunks.sort((a, b) => a.startLine - b.startLine);
|
|
186
|
+
for (const chunk of fileChunks) {
|
|
187
|
+
const header = `// ${filePath} (lines ${chunk.startLine}-${chunk.endLine})`;
|
|
188
|
+
textParts.push(`${header}\n${chunk.content}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const text = textParts.join('\n\n');
|
|
192
|
+
// Build structured data
|
|
193
|
+
const chunkInfos = chunks.map((c) => ({
|
|
194
|
+
file: c.filePath,
|
|
195
|
+
lines: [c.startLine, c.endLine],
|
|
196
|
+
tokens: c.tokens,
|
|
197
|
+
score: Math.round(c.score * 1000) / 1000,
|
|
198
|
+
}));
|
|
199
|
+
const data = {
|
|
200
|
+
query,
|
|
201
|
+
context: text,
|
|
202
|
+
chunks: chunkInfos,
|
|
203
|
+
stats: {
|
|
204
|
+
totalTokens,
|
|
205
|
+
chunksConsidered: totalConsidered,
|
|
206
|
+
chunksIncluded: chunks.length,
|
|
207
|
+
filesIncluded: fileGroups.size,
|
|
208
|
+
timeMs,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
return { text, data };
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Format output in specified format
|
|
215
|
+
*/
|
|
216
|
+
export function formatInFormat(format, query, result, totalConsidered, timeMs, explain = false) {
|
|
217
|
+
switch (format) {
|
|
218
|
+
case 'xml':
|
|
219
|
+
return formatAsXml(query, result, totalConsidered, timeMs);
|
|
220
|
+
case 'json': {
|
|
221
|
+
// JSON format returns the data structure directly
|
|
222
|
+
const base = formatOutput(query, result, totalConsidered, timeMs);
|
|
223
|
+
return {
|
|
224
|
+
text: JSON.stringify(base.data, null, 2),
|
|
225
|
+
data: base.data,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
case 'plain':
|
|
229
|
+
return formatAsPlain(query, result, totalConsidered, timeMs);
|
|
230
|
+
case 'markdown':
|
|
231
|
+
default:
|
|
232
|
+
return explain
|
|
233
|
+
? formatWithExplanation(query, result, totalConsidered, timeMs)
|
|
234
|
+
: formatOutput(query, result, totalConsidered, timeMs);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Escape XML special characters
|
|
239
|
+
*/
|
|
240
|
+
function escapeXml(str) {
|
|
241
|
+
return str
|
|
242
|
+
.replace(/&/g, '&')
|
|
243
|
+
.replace(/</g, '<')
|
|
244
|
+
.replace(/>/g, '>')
|
|
245
|
+
.replace(/"/g, '"')
|
|
246
|
+
.replace(/'/g, ''');
|
|
247
|
+
}
|
|
114
248
|
//# sourceMappingURL=formatter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/selector/formatter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/selector/formatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyCH;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAa,EACb,MAAoB,EACpB,eAAuB,EACvB,MAAc;IAEd,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAEvC,uBAAuB;IACvB,MAAM,UAAU,GAAG,IAAI,GAAG,EAAyB,CAAC;IACpD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtD,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,UAAU,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AAM,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,GAAW;IAC5B,OAAO,GAAG;SACP,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/selector/index.d.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Orchestrates the selection pipeline:
|
|
5
5
|
* 1. Search for similar chunks
|
|
6
|
-
* 2. Score and rank
|
|
6
|
+
* 2. Score and rank (with optional import boosting)
|
|
7
7
|
* 3. Fit to budget
|
|
8
8
|
* 4. Format output
|
|
9
9
|
*/
|
|
10
10
|
import Database from 'better-sqlite3';
|
|
11
|
-
import { type FormattedOutput } from './formatter.js';
|
|
11
|
+
import { type FormattedOutput, type OutputFormat } from './formatter.js';
|
|
12
12
|
/** Selection options */
|
|
13
13
|
export interface SelectOptions {
|
|
14
14
|
/** Query to find context for */
|
|
@@ -19,6 +19,12 @@ export interface SelectOptions {
|
|
|
19
19
|
sources?: string[];
|
|
20
20
|
/** Show scoring explanation */
|
|
21
21
|
explain?: boolean;
|
|
22
|
+
/** Output format */
|
|
23
|
+
format?: OutputFormat;
|
|
24
|
+
/** Include imported files in selection */
|
|
25
|
+
includeImports?: boolean;
|
|
26
|
+
/** Base path for resolving imports */
|
|
27
|
+
basePath?: string;
|
|
22
28
|
}
|
|
23
29
|
/** Selection result */
|
|
24
30
|
export interface SelectResult {
|
|
@@ -31,7 +37,8 @@ export interface SelectResult {
|
|
|
31
37
|
* Select optimal context for a query
|
|
32
38
|
*/
|
|
33
39
|
export declare function selectContext(db: Database.Database, options: SelectOptions): Promise<SelectResult>;
|
|
34
|
-
export type { FormattedOutput, SelectionData, SelectionStats, ChunkInfo } from './formatter.js';
|
|
40
|
+
export type { FormattedOutput, SelectionData, SelectionStats, ChunkInfo, OutputFormat } from './formatter.js';
|
|
35
41
|
export type { ScoredChunk } from './search.js';
|
|
36
|
-
export type { RankedChunk } from './scoring.js';
|
|
42
|
+
export type { RankedChunk, ImportGraph, ScoringOptions } from './scoring.js';
|
|
43
|
+
export { buildImportGraph, getRelatedImports } from './scoring.js';
|
|
37
44
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/selector/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAItC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/selector/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAItC,OAAO,EAAkB,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGzF,wBAAwB;AACxB,MAAM,WAAW,aAAa;IAC5B,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oBAAoB;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,0CAA0C;IAC1C,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,uBAAuB;AACvB,MAAM,WAAW,YAAY;IAC3B,uBAAuB;IACvB,MAAM,EAAE,eAAe,CAAC;IACxB,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CA+FvB;AAwCD,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9G,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/selector/index.js
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Orchestrates the selection pipeline:
|
|
5
5
|
* 1. Search for similar chunks
|
|
6
|
-
* 2. Score and rank
|
|
6
|
+
* 2. Score and rank (with optional import boosting)
|
|
7
7
|
* 3. Fit to budget
|
|
8
8
|
* 4. Format output
|
|
9
9
|
*/
|
|
10
10
|
import { searchSimilar } from './search.js';
|
|
11
|
-
import { rankChunks } from './scoring.js';
|
|
11
|
+
import { rankChunks, buildImportGraph, getRelatedImports } from './scoring.js';
|
|
12
12
|
import { fitToBudget, mergeAdjacentChunks } from './budget.js';
|
|
13
|
-
import {
|
|
13
|
+
import { formatInFormat } from './formatter.js';
|
|
14
|
+
import { parseImportsWithResolution, isJsTsFile } from '../retrieval/imports.js';
|
|
14
15
|
/**
|
|
15
16
|
* Select optimal context for a query
|
|
16
17
|
*/
|
|
@@ -44,24 +45,78 @@ export async function selectContext(db, options) {
|
|
|
44
45
|
sources: options.sources,
|
|
45
46
|
};
|
|
46
47
|
const similarChunks = await searchSimilar(db, options.query, searchOpts);
|
|
47
|
-
// Step 2:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
// Step 2: Build import graph if needed
|
|
49
|
+
let importGraph;
|
|
50
|
+
if (options.includeImports) {
|
|
51
|
+
importGraph = buildImportGraphFromChunks(db, options.basePath || process.cwd());
|
|
52
|
+
}
|
|
53
|
+
// Step 3: Score and rank (with import boost if graph provided)
|
|
54
|
+
const rankedChunks = rankChunks(similarChunks, options.query, { importGraph });
|
|
55
|
+
// Step 4: Fit to budget
|
|
56
|
+
let budgetResult = fitToBudget(rankedChunks, options.budget);
|
|
57
|
+
// Step 5: Include related imports if requested
|
|
58
|
+
if (options.includeImports && importGraph) {
|
|
59
|
+
const selectedFiles = [...new Set(budgetResult.chunks.map(c => c.filePath))];
|
|
60
|
+
const relatedFiles = getRelatedImports(selectedFiles, importGraph);
|
|
61
|
+
// Find chunks from related files that aren't already included
|
|
62
|
+
const includedFiles = new Set(budgetResult.chunks.map(c => c.filePath));
|
|
63
|
+
const relatedChunks = similarChunks.filter(c => relatedFiles.includes(c.filePath) && !includedFiles.has(c.filePath));
|
|
64
|
+
if (relatedChunks.length > 0) {
|
|
65
|
+
// Score and add related chunks with remaining budget
|
|
66
|
+
const relatedRanked = rankChunks(relatedChunks, options.query, { importGraph });
|
|
67
|
+
const remainingBudget = options.budget - budgetResult.totalTokens;
|
|
68
|
+
if (remainingBudget > 0) {
|
|
69
|
+
const relatedBudget = fitToBudget(relatedRanked, remainingBudget);
|
|
70
|
+
budgetResult = {
|
|
71
|
+
chunks: [...budgetResult.chunks, ...relatedBudget.chunks],
|
|
72
|
+
totalTokens: budgetResult.totalTokens + relatedBudget.totalTokens,
|
|
73
|
+
excluded: budgetResult.excluded + relatedBudget.excluded,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Step 6: Merge adjacent chunks for cleaner output
|
|
52
79
|
const mergedChunks = mergeAdjacentChunks(budgetResult.chunks);
|
|
53
80
|
const mergedResult = {
|
|
54
81
|
...budgetResult,
|
|
55
82
|
chunks: mergedChunks,
|
|
56
83
|
};
|
|
57
|
-
// Step
|
|
84
|
+
// Step 7: Format output
|
|
58
85
|
const timeMs = Date.now() - startTime;
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
: formatOutput(options.query, mergedResult, similarChunks.length, timeMs);
|
|
86
|
+
const format = options.format || 'markdown';
|
|
87
|
+
const output = formatInFormat(format, options.query, mergedResult, similarChunks.length, timeMs, options.explain);
|
|
62
88
|
return {
|
|
63
89
|
output,
|
|
64
90
|
isEmpty: false,
|
|
65
91
|
};
|
|
66
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Build import graph from all indexed chunks
|
|
95
|
+
*/
|
|
96
|
+
function buildImportGraphFromChunks(db, basePath) {
|
|
97
|
+
// Get all unique files and their content
|
|
98
|
+
const rows = db.prepare(`
|
|
99
|
+
SELECT DISTINCT file_path, content
|
|
100
|
+
FROM chunks
|
|
101
|
+
ORDER BY file_path, start_line
|
|
102
|
+
`).all();
|
|
103
|
+
// Group content by file (combine chunks)
|
|
104
|
+
const fileContents = new Map();
|
|
105
|
+
for (const row of rows) {
|
|
106
|
+
const existing = fileContents.get(row.file_path) || '';
|
|
107
|
+
fileContents.set(row.file_path, existing + row.content);
|
|
108
|
+
}
|
|
109
|
+
// Parse imports for each JS/TS file
|
|
110
|
+
const dependencyMap = new Map();
|
|
111
|
+
for (const [filePath, content] of fileContents) {
|
|
112
|
+
if (!isJsTsFile(filePath)) {
|
|
113
|
+
dependencyMap.set(filePath, []);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const { relatedFiles } = parseImportsWithResolution(content, filePath, basePath);
|
|
117
|
+
dependencyMap.set(filePath, relatedFiles);
|
|
118
|
+
}
|
|
119
|
+
return buildImportGraph(dependencyMap);
|
|
120
|
+
}
|
|
121
|
+
export { buildImportGraph, getRelatedImports } from './scoring.js';
|
|
67
122
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/selector/index.ts"],"names":[],"mappings":"AAAA;;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,OAAO,CAAC;;;;GAIvB,CAAC,CAAC,GAAG,EAAmD,CAAC;IAE1D,yCAAyC;IACzC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC/C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACvD,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,oCAAoC;IACpC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAoB,CAAC;IAElD,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,YAAY,EAAE,CAAC;QAC/C,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAChC,SAAS;QACX,CAAC;QAED,MAAM,EAAE,YAAY,EAAE,GAAG,0BAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACjF,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,gBAAgB,CAAC,aAAa,CAAC,CAAC;AACzC,CAAC;AAMD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Calculates final scores for chunks based on multiple signals.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Multi-factor scoring:
|
|
7
|
+
* - Semantic similarity (embeddings)
|
|
8
|
+
* - Path relevance (query keywords in file path)
|
|
9
|
+
* - Content keyword matching (exact word matches)
|
|
10
|
+
* - Code symbol matching (function/class names)
|
|
11
|
+
* - File type boost (implementation files > tests)
|
|
9
12
|
*/
|
|
10
13
|
import type { ScoredChunk } from './search.js';
|
|
11
14
|
/** Chunk with final score */
|
|
@@ -15,12 +18,39 @@ export interface RankedChunk extends ScoredChunk {
|
|
|
15
18
|
/** Individual score components for --explain */
|
|
16
19
|
scoreBreakdown: {
|
|
17
20
|
similarity: number;
|
|
18
|
-
recency: number;
|
|
19
21
|
pathMatch: number;
|
|
22
|
+
contentMatch: number;
|
|
23
|
+
symbolMatch: number;
|
|
24
|
+
fileTypeBoost: number;
|
|
25
|
+
importBoost: number;
|
|
20
26
|
};
|
|
21
27
|
}
|
|
28
|
+
/** Import relationship data for scoring */
|
|
29
|
+
export interface ImportGraph {
|
|
30
|
+
/** Map of file path -> files it imports */
|
|
31
|
+
imports: Map<string, string[]>;
|
|
32
|
+
/** Map of file path -> files that import it */
|
|
33
|
+
importedBy: Map<string, string[]>;
|
|
34
|
+
}
|
|
35
|
+
/** Options for scoring */
|
|
36
|
+
export interface ScoringOptions {
|
|
37
|
+
/** Apply diversity penalty (reduce score for many chunks from same file) */
|
|
38
|
+
diversityPenalty?: boolean;
|
|
39
|
+
/** Import relationships for boosting related files */
|
|
40
|
+
importGraph?: ImportGraph;
|
|
41
|
+
}
|
|
22
42
|
/**
|
|
23
43
|
* Calculate scores and rank chunks
|
|
24
44
|
*/
|
|
25
|
-
export declare function rankChunks(chunks: ScoredChunk[], query: string): RankedChunk[];
|
|
45
|
+
export declare function rankChunks(chunks: ScoredChunk[], query: string, options?: ScoringOptions): RankedChunk[];
|
|
46
|
+
/**
|
|
47
|
+
* Build an import graph from a dependency map
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildImportGraph(dependencyMap: Map<string, string[]>): ImportGraph;
|
|
50
|
+
/**
|
|
51
|
+
* Get files that should be included based on imports from selected files
|
|
52
|
+
*/
|
|
53
|
+
export declare function getRelatedImports(selectedFiles: string[], importGraph: ImportGraph, options?: {
|
|
54
|
+
maxDepth?: number;
|
|
55
|
+
}): string[];
|
|
26
56
|
//# sourceMappingURL=scoring.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoring.d.ts","sourceRoot":"","sources":["../../src/selector/scoring.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scoring.d.ts","sourceRoot":"","sources":["../../src/selector/scoring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,6BAA6B;AAC7B,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,cAAc,EAAE;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAYD,2CAA2C;AAC3C,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/B,+CAA+C;IAC/C,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACnC;AAED,0BAA0B;AAC1B,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,sDAAsD;IACtD,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EAAE,EACrB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,cAAmB,GAC3B,WAAW,EAAE,CAyEf;AAySD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,M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