codesearch-mcp 0.2.2-alpha → 0.3.0-alpha
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 +65 -1
- package/README.md +60 -33
- package/dist/app.js +46 -22
- package/dist/src/chunking/AstChunker.d.ts +12 -0
- package/dist/src/chunking/AstChunker.js +30 -0
- package/dist/src/chunking/CharacterChunkStrategy.d.ts +8 -0
- package/dist/src/chunking/CharacterChunkStrategy.js +15 -0
- package/dist/src/chunking/DeclarationChunkStrategy.d.ts +15 -0
- package/dist/src/chunking/DeclarationChunkStrategy.js +87 -0
- package/dist/src/chunking/FragmentMerger.d.ts +11 -0
- package/dist/src/chunking/FragmentMerger.js +61 -0
- package/dist/src/chunking/ImportOnlyFilter.d.ts +5 -0
- package/dist/src/chunking/ImportOnlyFilter.js +14 -0
- package/dist/src/chunking/LangchainTextSplitter.d.ts +21 -0
- package/dist/src/chunking/LangchainTextSplitter.js +133 -0
- package/dist/src/chunking/MinSizeSplitPolicy.d.ts +9 -0
- package/dist/src/chunking/MinSizeSplitPolicy.js +18 -0
- package/dist/src/chunking/RunPacker.d.ts +12 -0
- package/dist/src/chunking/RunPacker.js +84 -0
- package/dist/src/chunking/create-chunker.d.ts +3 -0
- package/dist/src/chunking/create-chunker.js +15 -0
- package/dist/src/chunking/interfaces.d.ts +27 -0
- package/dist/src/chunking/interfaces.js +2 -0
- package/dist/src/commands/ConfigCommand.js +1 -9
- package/dist/src/commands/EvalCommand.d.ts +11 -0
- package/dist/src/commands/EvalCommand.js +264 -0
- package/dist/src/commands/IndexCommand.js +70 -66
- package/dist/src/commands/McpCommand.js +2 -8
- package/dist/src/commands/WebCommand.js +2 -5
- package/dist/src/config-error.d.ts +0 -4
- package/dist/src/config-error.js +0 -4
- package/dist/src/config-store.d.ts +1 -54
- package/dist/src/config-store.js +8 -69
- package/dist/src/config.d.ts +8 -17
- package/dist/src/config.js +35 -34
- package/dist/src/constants.d.ts +2 -28
- package/dist/src/constants.js +6 -28
- package/dist/src/container.d.ts +6 -0
- package/dist/src/container.js +12 -3
- package/dist/src/db/index.d.ts +1 -1
- package/dist/src/db/index.js +1 -2
- package/dist/src/db/schema.d.ts +22 -29
- package/dist/src/db/schema.js +3 -14
- package/dist/src/declarations/DeclarationTree.d.ts +19 -0
- package/dist/src/declarations/DeclarationTree.js +66 -0
- package/dist/src/declarations/DeclarationTreeBuilder.d.ts +22 -0
- package/dist/src/declarations/DeclarationTreeBuilder.js +179 -0
- package/dist/src/declarations/SourceLines.d.ts +37 -0
- package/dist/src/declarations/SourceLines.js +415 -0
- package/dist/src/dependency-traversal.d.ts +10 -0
- package/dist/src/dependency-traversal.js +39 -0
- package/dist/src/enriched-prompt.d.ts +0 -5
- package/dist/src/enriched-prompt.js +0 -5
- package/dist/src/error-record.d.ts +12 -0
- package/dist/src/error-record.js +248 -0
- package/dist/src/eval-corpus.d.ts +16 -0
- package/dist/src/eval-corpus.js +169 -0
- package/dist/src/eval-results.d.ts +15 -0
- package/dist/src/eval-results.js +397 -0
- package/dist/src/file-utils.d.ts +10 -0
- package/dist/src/file-utils.js +19 -1
- package/dist/src/graph.d.ts +0 -25
- package/dist/src/graph.js +0 -28
- package/dist/src/help.js +4 -1
- package/dist/src/hnsw-settings.d.ts +3 -0
- package/dist/src/hnsw-settings.js +24 -0
- package/dist/src/interfaces/IAstParser.d.ts +5 -30
- package/dist/src/interfaces/IChunker.d.ts +3 -12
- package/dist/src/interfaces/ICorpusInspector.d.ts +7 -0
- package/dist/src/interfaces/ICorpusInspector.js +2 -0
- package/dist/src/interfaces/IDatabase.d.ts +2 -36
- package/dist/src/interfaces/IEmbedder.d.ts +0 -9
- package/dist/src/interfaces/ILogger.d.ts +1 -11
- package/dist/src/interfaces/IMcpToolHandler.d.ts +0 -5
- package/dist/src/interfaces/IMonorepoResolver.d.ts +0 -22
- package/dist/src/interfaces/IProjectDiscovery.d.ts +0 -17
- package/dist/src/interfaces/IRetrievalEvaluator.d.ts +216 -0
- package/dist/src/interfaces/IRetrievalEvaluator.js +2 -0
- package/dist/src/interfaces/ISearcher.d.ts +26 -20
- package/dist/src/interfaces/index.d.ts +1 -0
- package/dist/src/interrupt.js +0 -2
- package/dist/src/owner-path.d.ts +9 -10
- package/dist/src/owner-path.js +11 -23
- package/dist/src/project-scope.d.ts +7 -0
- package/dist/src/project-scope.js +37 -0
- package/dist/src/project-selector.d.ts +1 -0
- package/dist/src/project-selector.js +13 -6
- package/dist/src/retrieval-eval.d.ts +24 -0
- package/dist/src/retrieval-eval.js +500 -0
- package/dist/src/search/result-shaping.d.ts +4 -0
- package/dist/src/search/result-shaping.js +19 -0
- package/dist/src/services/AstParserService.d.ts +28 -23
- package/dist/src/services/AstParserService.js +391 -98
- package/dist/src/services/DatabaseService.d.ts +2 -19
- package/dist/src/services/DatabaseService.js +44 -81
- package/dist/src/services/EmbedderFactory.d.ts +0 -4
- package/dist/src/services/EmbedderFactory.js +0 -5
- package/dist/src/services/IndexerService.d.ts +2 -10
- package/dist/src/services/IndexerService.js +29 -45
- package/dist/src/services/InfinityEmbedder.d.ts +0 -21
- package/dist/src/services/InfinityEmbedder.js +0 -15
- package/dist/src/services/LoggerService.d.ts +7 -5
- package/dist/src/services/LoggerService.js +37 -41
- package/dist/src/services/McpServer.d.ts +25 -10
- package/dist/src/services/McpServer.js +101 -64
- package/dist/src/services/MonorepoAwareDiscoveryService.d.ts +1 -45
- package/dist/src/services/MonorepoAwareDiscoveryService.js +1 -51
- package/dist/src/services/NxMonorepoResolver.d.ts +0 -29
- package/dist/src/services/NxMonorepoResolver.js +5 -56
- package/dist/src/services/OpenAICompatibleEmbedder.d.ts +0 -6
- package/dist/src/services/OpenAICompatibleEmbedder.js +1 -14
- package/dist/src/services/ProjectDiscoveryService.d.ts +0 -4
- package/dist/src/services/ProjectDiscoveryService.js +0 -4
- package/dist/src/services/SearcherService.d.ts +127 -70
- package/dist/src/services/SearcherService.js +526 -305
- package/dist/src/services/VoyageEmbedder.d.ts +0 -6
- package/dist/src/services/VoyageEmbedder.js +0 -6
- package/dist/src/services/WebServerService.d.ts +1 -53
- package/dist/src/services/WebServerService.js +11 -57
- package/dist/src/services/http-retry.d.ts +0 -7
- package/dist/src/services/http-retry.js +1 -10
- package/dist/src/services/infinity-provisioning.d.ts +0 -74
- package/dist/src/services/infinity-provisioning.js +5 -88
- package/dist/src/services/legacy-ollama-index.d.ts +0 -16
- package/dist/src/services/legacy-ollama-index.js +0 -23
- package/dist/src/services/reranker.d.ts +0 -9
- package/dist/src/services/reranker.js +46 -12
- package/dist/src/setup.d.ts +11 -23
- package/dist/src/setup.js +98 -71
- package/dist/src/symbol-name.d.ts +0 -12
- package/dist/src/symbol-name.js +0 -13
- package/dist/src/symbol-rows.d.ts +2 -11
- package/dist/src/symbol-rows.js +5 -13
- package/dist/src/tool-call-log.d.ts +2 -0
- package/dist/src/tool-call-log.js +24 -0
- package/dist/src/tools/FindSymbolTool.js +14 -5
- package/dist/src/tools/GetCallersTool.d.ts +3 -1
- package/dist/src/tools/GetCallersTool.js +16 -6
- package/dist/src/tools/GetDependenciesTool.d.ts +3 -1
- package/dist/src/tools/GetDependenciesTool.js +15 -8
- package/dist/src/tools/GetDependentsTool.d.ts +3 -1
- package/dist/src/tools/GetDependentsTool.js +31 -16
- package/dist/src/tools/ListFilesTool.d.ts +3 -1
- package/dist/src/tools/ListFilesTool.js +14 -12
- package/dist/src/tools/ListProjectsTool.js +5 -1
- package/dist/src/tools/ReadFileRangeTool.d.ts +3 -1
- package/dist/src/tools/ReadFileRangeTool.js +12 -11
- package/dist/src/tools/ReadFileTool.d.ts +3 -1
- package/dist/src/tools/ReadFileTool.js +12 -10
- package/dist/src/tools/SearchCodebaseTool.js +7 -2
- package/dist/src/tools/format-helpers.d.ts +10 -1
- package/dist/src/tools/format-helpers.js +145 -8
- package/dist/src/web/dashboard.d.ts +0 -8
- package/dist/src/web/dashboard.js +7 -10
- package/package.json +10 -9
- package/dist/src/services/AstChunker.d.ts +0 -42
- package/dist/src/services/AstChunker.js +0 -158
- package/docs/web-dashboard.md +0 -206
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SourceLines = void 0;
|
|
4
|
+
const PUNCTUATION_ONLY = /^[}\)\];,]+$/;
|
|
5
|
+
const DIRECTIVE = /^(['"])use [\w -]+\1;?$/;
|
|
6
|
+
const IMPORT_START = /^(import(?=\s*['"{*]|\s+[\w$])|export\s+(\*|type\s+[{*]|\{|import\s+[A-Za-z_$]))/;
|
|
7
|
+
const BARE_IMPORT_NEXT = /^([*{'"]|type\s|[A-Za-z_$][\w$]*\s*(,|from\b|=))/;
|
|
8
|
+
const BARE_IMPORT_LIST = /^[A-Za-z_$][\w$]*\s*,/;
|
|
9
|
+
const MODULE_REFERENCE = /\bfrom\s*(['"]|$)|\brequire\s*\(/;
|
|
10
|
+
const STATEMENT_END = /(['"]|\}|\))\s*;?$|;$|^(export\s+)?import\s+[A-Za-z_$][\w$]*\s*=\s*[A-Za-z_$][\w$.]*$/;
|
|
11
|
+
const DISQUALIFY = /^export\s+(default|async\b|function\b|const\b|let\b|var\b|class\b|abstract\b|interface\b|enum\b|namespace\b|declare\b|type\s+[A-Za-z_$])/;
|
|
12
|
+
const SPECIFIER = String.raw `['"][^'"]+['"]`;
|
|
13
|
+
const NAME = String.raw `(type\s+)?([A-Za-z_$][\w$]*|${SPECIFIER})(\s+as\s+([A-Za-z_$][\w$]*|${SPECIFIER}))?`;
|
|
14
|
+
const ATTRIBUTES = String.raw `(\s+(with|assert)\s*\{[^}]*\}?)?`;
|
|
15
|
+
const CONTINUATION = new RegExp([
|
|
16
|
+
String.raw `^(\{?\s*${NAME}(\s*,\s*${NAME})*\s*,?\s*)?(\}\s*)?(from(\s+${SPECIFIER}${ATTRIBUTES})?)?\s*;?$`,
|
|
17
|
+
String.raw `^['"][^'"]*['"]${ATTRIBUTES}\s*;?$`,
|
|
18
|
+
String.raw `^\)\s*;?$`,
|
|
19
|
+
String.raw `^\*\s+as\s+[A-Za-z_$][\w$]*(\s+from(\s+${SPECIFIER}${ATTRIBUTES})?)?\s*;?$`,
|
|
20
|
+
String.raw `^(${SPECIFIER}|[A-Za-z_$][\w$]*)\s*:\s*${SPECIFIER}\s*,?$`,
|
|
21
|
+
].join('|'));
|
|
22
|
+
const MAX_IMPORT_LINE = 100_000;
|
|
23
|
+
const REGEX_PRECEDER = /(^|[(,=:[!&|?{};+\-*%<>~^]|(^|\.\.\.|[^\w$.])(return|typeof|instanceof|in|of|new|delete|void|throw|case|do|else|yield|await))$/;
|
|
24
|
+
const CONDITION_KEYWORDS = new Set(['if', 'while', 'for', 'with']);
|
|
25
|
+
const JSX_OPEN = /^<(>|(?!(const\s+)?[A-Za-z_$][\w$]*\s*(,|extends\b|=|>\s*\())[A-Za-z_$][\w$.:-]*[\s/>{<])/;
|
|
26
|
+
const TYPE_PARAMS_OR_TAG = /^<([A-Za-z_$][\w$]*)\s*>\s*\(/;
|
|
27
|
+
class SourceLines {
|
|
28
|
+
text;
|
|
29
|
+
lines;
|
|
30
|
+
stripped;
|
|
31
|
+
code;
|
|
32
|
+
startsInCode;
|
|
33
|
+
importLines;
|
|
34
|
+
constructor(text, { jsx = false } = {}) {
|
|
35
|
+
this.text = text;
|
|
36
|
+
this.lines = text.split('\n');
|
|
37
|
+
({ stripped: this.stripped, startsInCode: this.startsInCode } = SourceLines.scanCode(text, this.lines.length, jsx));
|
|
38
|
+
this.code = this.stripped.map(l => l.replace(/\s+/g, ''));
|
|
39
|
+
}
|
|
40
|
+
get count() {
|
|
41
|
+
return this.lines.length;
|
|
42
|
+
}
|
|
43
|
+
line(n) {
|
|
44
|
+
return this.lines[n - 1] ?? '';
|
|
45
|
+
}
|
|
46
|
+
slice(start, end) {
|
|
47
|
+
return this.lines.slice(start - 1, end).join('\n');
|
|
48
|
+
}
|
|
49
|
+
length(start, end) {
|
|
50
|
+
return this.slice(start, end).length;
|
|
51
|
+
}
|
|
52
|
+
isBlank(n) {
|
|
53
|
+
return this.line(n).trim() === '';
|
|
54
|
+
}
|
|
55
|
+
isCommentOnly(n) {
|
|
56
|
+
return !this.isBlank(n) && this.code[n - 1] === '';
|
|
57
|
+
}
|
|
58
|
+
isDirective(n) {
|
|
59
|
+
return DIRECTIVE.test(this.stripped[n - 1]?.trim() ?? '');
|
|
60
|
+
}
|
|
61
|
+
isPunctuationOnly(n) {
|
|
62
|
+
return PUNCTUATION_ONLY.test(this.code[n - 1] ?? '');
|
|
63
|
+
}
|
|
64
|
+
isSignificant(n) {
|
|
65
|
+
const code = this.code[n - 1] ?? '';
|
|
66
|
+
return code !== '' && !PUNCTUATION_ONLY.test(code);
|
|
67
|
+
}
|
|
68
|
+
significantLength(start, end) {
|
|
69
|
+
let n = 0;
|
|
70
|
+
for (let i = start; i <= end; i++)
|
|
71
|
+
n += (this.code[i - 1] ?? '').length;
|
|
72
|
+
return n;
|
|
73
|
+
}
|
|
74
|
+
importRegions(start, end) {
|
|
75
|
+
const regions = [];
|
|
76
|
+
let i = start;
|
|
77
|
+
while (i <= end) {
|
|
78
|
+
const stmtEnd = this.importStatementEnd(i, end);
|
|
79
|
+
if (stmtEnd === null) {
|
|
80
|
+
i++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
let regionEnd = stmtEnd;
|
|
84
|
+
let k = stmtEnd + 1;
|
|
85
|
+
while (k <= end) {
|
|
86
|
+
if (this.isBlank(k) || this.isCommentOnly(k)) {
|
|
87
|
+
k++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const next = this.importStatementEnd(k, end);
|
|
91
|
+
if (next === null)
|
|
92
|
+
break;
|
|
93
|
+
regionEnd = next;
|
|
94
|
+
k = next + 1;
|
|
95
|
+
}
|
|
96
|
+
regions.push({ start: i, end: regionEnd });
|
|
97
|
+
i = regionEnd + 1;
|
|
98
|
+
}
|
|
99
|
+
return regions;
|
|
100
|
+
}
|
|
101
|
+
importStatementEnd(n, limit) {
|
|
102
|
+
if (!this.startsInCode[n - 1] || !this.startsImport(n, limit))
|
|
103
|
+
return null;
|
|
104
|
+
let needsModule = this.stripped[n - 1].trim() === 'import' && BARE_IMPORT_LIST.test(this.nextCode(n, limit));
|
|
105
|
+
let depth = 0;
|
|
106
|
+
for (let j = n; j <= limit; j++) {
|
|
107
|
+
const line = this.stripped[j - 1].trim();
|
|
108
|
+
if (line === '')
|
|
109
|
+
continue;
|
|
110
|
+
if (!SourceLines.isImportLine(line))
|
|
111
|
+
return null;
|
|
112
|
+
depth += SourceLines.bracketDepth(line);
|
|
113
|
+
if (MODULE_REFERENCE.test(line))
|
|
114
|
+
needsModule = false;
|
|
115
|
+
if (depth > 0 || !STATEMENT_END.test(line))
|
|
116
|
+
continue;
|
|
117
|
+
if (line.endsWith('}') && /^from\b/.test(this.nextCode(j, limit)))
|
|
118
|
+
continue;
|
|
119
|
+
return needsModule ? null : j;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
startsImport(n, limit) {
|
|
124
|
+
const line = this.stripped[n - 1].trim();
|
|
125
|
+
return IMPORT_START.test(line) || (line === 'import' && BARE_IMPORT_NEXT.test(this.nextCode(n, limit)));
|
|
126
|
+
}
|
|
127
|
+
nextCode(n, limit) {
|
|
128
|
+
for (let j = n + 1; j <= limit; j++) {
|
|
129
|
+
const line = this.stripped[j - 1].trim();
|
|
130
|
+
if (line !== '')
|
|
131
|
+
return line;
|
|
132
|
+
}
|
|
133
|
+
return '';
|
|
134
|
+
}
|
|
135
|
+
static bracketDepth(line) {
|
|
136
|
+
let depth = 0;
|
|
137
|
+
let quote = '';
|
|
138
|
+
for (let i = 0; i < line.length; i++) {
|
|
139
|
+
const ch = line[i];
|
|
140
|
+
if (quote) {
|
|
141
|
+
if (ch === '\\')
|
|
142
|
+
i++;
|
|
143
|
+
else if (ch === quote)
|
|
144
|
+
quote = '';
|
|
145
|
+
}
|
|
146
|
+
else if (ch === '\'' || ch === '"' || ch === '`')
|
|
147
|
+
quote = ch;
|
|
148
|
+
else if (ch === '{' || ch === '(')
|
|
149
|
+
depth++;
|
|
150
|
+
else if (ch === '}' || ch === ')')
|
|
151
|
+
depth--;
|
|
152
|
+
}
|
|
153
|
+
return depth;
|
|
154
|
+
}
|
|
155
|
+
static isImportOrReexportOnly(content) {
|
|
156
|
+
const src = new SourceLines(content);
|
|
157
|
+
return src.isImportOnly(1, src.count);
|
|
158
|
+
}
|
|
159
|
+
isImportOnly(start, end) {
|
|
160
|
+
const member = this.importStatementLines();
|
|
161
|
+
let any = false;
|
|
162
|
+
for (let n = start; n <= end; n++) {
|
|
163
|
+
if ((this.code[n - 1] ?? '') === '')
|
|
164
|
+
continue;
|
|
165
|
+
if (!member[n - 1])
|
|
166
|
+
return false;
|
|
167
|
+
any = true;
|
|
168
|
+
}
|
|
169
|
+
return any;
|
|
170
|
+
}
|
|
171
|
+
importStatementLines() {
|
|
172
|
+
if (this.importLines)
|
|
173
|
+
return this.importLines;
|
|
174
|
+
const member = Array.from({ length: this.count }, () => false);
|
|
175
|
+
for (let n = 1; n <= this.count;) {
|
|
176
|
+
const end = this.importStatementEnd(n, this.count);
|
|
177
|
+
if (end === null) {
|
|
178
|
+
n++;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
for (let k = n; k <= end; k++)
|
|
182
|
+
member[k - 1] = true;
|
|
183
|
+
n = end + 1;
|
|
184
|
+
}
|
|
185
|
+
return (this.importLines = member);
|
|
186
|
+
}
|
|
187
|
+
static isImportLine(line) {
|
|
188
|
+
if (line.length > MAX_IMPORT_LINE)
|
|
189
|
+
return false;
|
|
190
|
+
for (const [i, statement] of SourceLines.statements(line).entries()) {
|
|
191
|
+
if (DISQUALIFY.test(statement))
|
|
192
|
+
return false;
|
|
193
|
+
if (IMPORT_START.test(statement))
|
|
194
|
+
continue;
|
|
195
|
+
if (i === 0 && CONTINUATION.test(statement))
|
|
196
|
+
continue;
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
static statements(line) {
|
|
202
|
+
const out = [];
|
|
203
|
+
let from = 0;
|
|
204
|
+
let quote = '';
|
|
205
|
+
for (let i = 0; i < line.length; i++) {
|
|
206
|
+
const ch = line[i];
|
|
207
|
+
if (quote) {
|
|
208
|
+
if (ch === '\\')
|
|
209
|
+
i++;
|
|
210
|
+
else if (ch === quote)
|
|
211
|
+
quote = '';
|
|
212
|
+
}
|
|
213
|
+
else if (ch === '\'' || ch === '"' || ch === '`')
|
|
214
|
+
quote = ch;
|
|
215
|
+
else if (ch === ';') {
|
|
216
|
+
out.push(line.slice(from, i + 1));
|
|
217
|
+
from = i + 1;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
out.push(line.slice(from));
|
|
221
|
+
return out.map(t => t.trim()).filter(t => t !== '' && t !== ';');
|
|
222
|
+
}
|
|
223
|
+
static opensElement(text, i) {
|
|
224
|
+
const head = text.slice(i, i + 64);
|
|
225
|
+
if (JSX_OPEN.test(head))
|
|
226
|
+
return true;
|
|
227
|
+
const name = TYPE_PARAMS_OR_TAG.exec(head)?.[1];
|
|
228
|
+
return name !== undefined && text.includes(`</${name}>`, i);
|
|
229
|
+
}
|
|
230
|
+
static scanCode(text, lineCount, jsx) {
|
|
231
|
+
const stripped = Array.from({ length: lineCount }, () => '');
|
|
232
|
+
const startsInCode = Array.from({ length: lineCount }, () => true);
|
|
233
|
+
let line = 0;
|
|
234
|
+
let state = 'code';
|
|
235
|
+
const frames = [{ kind: 'code', braces: 0 }];
|
|
236
|
+
const parens = [];
|
|
237
|
+
let afterCondition = false;
|
|
238
|
+
let word = '';
|
|
239
|
+
let jsxString = false;
|
|
240
|
+
let continued = false;
|
|
241
|
+
let inClass = false;
|
|
242
|
+
let tail = '';
|
|
243
|
+
const emit = (chars) => {
|
|
244
|
+
stripped[line] += chars;
|
|
245
|
+
tail = (tail + chars.replace(/\s+/g, '')).slice(-16);
|
|
246
|
+
};
|
|
247
|
+
for (let i = 0; i < text.length; i++) {
|
|
248
|
+
const ch = text[i];
|
|
249
|
+
const next = text[i + 1];
|
|
250
|
+
const frame = frames[frames.length - 1];
|
|
251
|
+
if (ch === '\n') {
|
|
252
|
+
line++;
|
|
253
|
+
if (state === 'line' || state === 'regex')
|
|
254
|
+
state = 'code';
|
|
255
|
+
if ((state === '\'' || state === '"') && !jsxString && !continued)
|
|
256
|
+
state = 'code';
|
|
257
|
+
continued = false;
|
|
258
|
+
if (line < lineCount)
|
|
259
|
+
startsInCode[line] = state === 'code' && frame.kind === 'code';
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
switch (state) {
|
|
263
|
+
case 'line':
|
|
264
|
+
continue;
|
|
265
|
+
case 'block':
|
|
266
|
+
if (ch === '*' && next === '/') {
|
|
267
|
+
state = 'code';
|
|
268
|
+
i++;
|
|
269
|
+
}
|
|
270
|
+
continue;
|
|
271
|
+
case '\'':
|
|
272
|
+
case '"':
|
|
273
|
+
if (!jsxString && ch === '\\' && next !== undefined) {
|
|
274
|
+
continued = next === '\n' || (next === '\r' && text[i + 2] === '\n');
|
|
275
|
+
if (next === '\n') {
|
|
276
|
+
emit(ch);
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
emit(ch + next);
|
|
280
|
+
i++;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (ch === state)
|
|
284
|
+
state = 'code';
|
|
285
|
+
emit(ch);
|
|
286
|
+
continue;
|
|
287
|
+
case 'regex':
|
|
288
|
+
if (ch === '\\' && next !== undefined && next !== '\n') {
|
|
289
|
+
emit(ch + next);
|
|
290
|
+
i++;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (inClass) {
|
|
294
|
+
if (ch === ']')
|
|
295
|
+
inClass = false;
|
|
296
|
+
}
|
|
297
|
+
else if (ch === '[')
|
|
298
|
+
inClass = true;
|
|
299
|
+
else if (ch === '/')
|
|
300
|
+
state = 'code';
|
|
301
|
+
emit(ch);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
switch (frame.kind) {
|
|
305
|
+
case 'template':
|
|
306
|
+
if (ch === '\\' && next !== undefined && next !== '\n') {
|
|
307
|
+
emit(ch + next);
|
|
308
|
+
i++;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (ch === '`')
|
|
312
|
+
frames.pop();
|
|
313
|
+
else if (ch === '$' && next === '{') {
|
|
314
|
+
frames.push({ kind: 'code', braces: 0 });
|
|
315
|
+
emit('${');
|
|
316
|
+
i++;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
emit(ch);
|
|
320
|
+
continue;
|
|
321
|
+
case 'children':
|
|
322
|
+
if (ch === '{')
|
|
323
|
+
frames.push({ kind: 'code', braces: 0 });
|
|
324
|
+
else if (ch === '<' && next === '/') {
|
|
325
|
+
frames.push({ kind: 'tag', closing: true, angles: 0 });
|
|
326
|
+
emit('</');
|
|
327
|
+
i++;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
else if (ch === '<')
|
|
331
|
+
frames.push({ kind: 'tag', closing: false, angles: 0 });
|
|
332
|
+
emit(ch);
|
|
333
|
+
continue;
|
|
334
|
+
case 'tag':
|
|
335
|
+
if (ch === '/' && next === '/') {
|
|
336
|
+
state = 'line';
|
|
337
|
+
i++;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (ch === '/' && next === '*') {
|
|
341
|
+
state = 'block';
|
|
342
|
+
emit(' ');
|
|
343
|
+
i++;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (ch === '/' && next === '>') {
|
|
347
|
+
frames.pop();
|
|
348
|
+
emit('/>');
|
|
349
|
+
i++;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (ch === '\'' || ch === '"') {
|
|
353
|
+
state = ch;
|
|
354
|
+
jsxString = true;
|
|
355
|
+
}
|
|
356
|
+
else if (ch === '{')
|
|
357
|
+
frames.push({ kind: 'code', braces: 0 });
|
|
358
|
+
else if (ch === '<')
|
|
359
|
+
frame.angles++;
|
|
360
|
+
else if (ch === '>' && frame.angles > 0)
|
|
361
|
+
frame.angles--;
|
|
362
|
+
else if (ch === '>') {
|
|
363
|
+
frames.pop();
|
|
364
|
+
if (frame.closing)
|
|
365
|
+
frames.pop();
|
|
366
|
+
else
|
|
367
|
+
frames.push({ kind: 'children' });
|
|
368
|
+
}
|
|
369
|
+
emit(ch);
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (ch === '/' && next === '/') {
|
|
373
|
+
state = 'line';
|
|
374
|
+
i++;
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (ch === '/' && next === '*') {
|
|
378
|
+
state = 'block';
|
|
379
|
+
emit(' ');
|
|
380
|
+
i++;
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
if (ch === '/' && (afterCondition || REGEX_PRECEDER.test(tail))) {
|
|
384
|
+
state = 'regex';
|
|
385
|
+
inClass = false;
|
|
386
|
+
}
|
|
387
|
+
else if (ch === '\'' || ch === '"') {
|
|
388
|
+
state = ch;
|
|
389
|
+
jsxString = false;
|
|
390
|
+
}
|
|
391
|
+
else if (ch === '`')
|
|
392
|
+
frames.push({ kind: 'template' });
|
|
393
|
+
else if (ch === '{')
|
|
394
|
+
frame.braces++;
|
|
395
|
+
else if (ch === '}' && frame.braces > 0)
|
|
396
|
+
frame.braces--;
|
|
397
|
+
else if (ch === '}' && frames.length > 1)
|
|
398
|
+
frames.pop();
|
|
399
|
+
else if (ch === '(')
|
|
400
|
+
parens.push(CONDITION_KEYWORDS.has(word));
|
|
401
|
+
else if (jsx && ch === '<' && !tail.endsWith('<') && REGEX_PRECEDER.test(tail) && SourceLines.opensElement(text, i)) {
|
|
402
|
+
frames.push({ kind: 'tag', closing: false, angles: 0 });
|
|
403
|
+
}
|
|
404
|
+
if (/[\w$]/.test(ch))
|
|
405
|
+
word = /[\w$]/.test(text[i - 1] ?? '') ? word + ch : ch;
|
|
406
|
+
else if (!/\s/.test(ch))
|
|
407
|
+
word = '';
|
|
408
|
+
if (!/\s/.test(ch))
|
|
409
|
+
afterCondition = ch === ')' && (parens.pop() ?? false);
|
|
410
|
+
emit(ch);
|
|
411
|
+
}
|
|
412
|
+
return { stripped, startsInCode };
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
exports.SourceLines = SourceLines;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Edge {
|
|
2
|
+
from: string;
|
|
3
|
+
to: string;
|
|
4
|
+
}
|
|
5
|
+
export interface IndirectRow {
|
|
6
|
+
file: string;
|
|
7
|
+
depth: number;
|
|
8
|
+
via: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function traverse(root: string, neighbours: (frontier: string[]) => Promise<Edge[]>, maxDepth?: number): Promise<IndirectRow[]>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traverse = traverse;
|
|
4
|
+
function byteCompare(a, b) {
|
|
5
|
+
return Buffer.compare(Buffer.from(a, 'utf8'), Buffer.from(b, 'utf8'));
|
|
6
|
+
}
|
|
7
|
+
async function traverse(root, neighbours, maxDepth = 20) {
|
|
8
|
+
const visited = new Map();
|
|
9
|
+
visited.set(root, 0);
|
|
10
|
+
const via = new Map();
|
|
11
|
+
let frontier = [root];
|
|
12
|
+
let depth = 1;
|
|
13
|
+
while (frontier.length > 0 && depth <= maxDepth) {
|
|
14
|
+
const edges = await neighbours(frontier);
|
|
15
|
+
const bestVia = new Map();
|
|
16
|
+
for (const edge of edges) {
|
|
17
|
+
if (visited.has(edge.to))
|
|
18
|
+
continue;
|
|
19
|
+
const current = bestVia.get(edge.to);
|
|
20
|
+
if (current === undefined || byteCompare(edge.from, current) < 0)
|
|
21
|
+
bestVia.set(edge.to, edge.from);
|
|
22
|
+
}
|
|
23
|
+
const next = [];
|
|
24
|
+
for (const [to, from] of bestVia) {
|
|
25
|
+
visited.set(to, depth);
|
|
26
|
+
via.set(to, from);
|
|
27
|
+
next.push(to);
|
|
28
|
+
}
|
|
29
|
+
frontier = next;
|
|
30
|
+
depth += 1;
|
|
31
|
+
}
|
|
32
|
+
const rows = [];
|
|
33
|
+
for (const [file, d] of visited) {
|
|
34
|
+
if (d >= 2)
|
|
35
|
+
rows.push({ file, depth: d, via: via.get(file) });
|
|
36
|
+
}
|
|
37
|
+
rows.sort((a, b) => a.depth - b.depth || byteCompare(a.file, b.file));
|
|
38
|
+
return rows;
|
|
39
|
+
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import type { ChunkPiece } from './interfaces/IChunker';
|
|
2
2
|
import type { DepEdge, SymbolEntry } from './interfaces/IAstParser';
|
|
3
|
-
/**
|
|
4
|
-
* Build the embedding-input prompt for one chunk. `symbols` is the file's
|
|
5
|
-
* top-level declarations only (never members) — the prompt is unaffected by
|
|
6
|
-
* this change (see the `symbol-index-members` non-goal).
|
|
7
|
-
*/
|
|
8
3
|
export declare function getEnrichedPrompt(piece: ChunkPiece, relPath: string, serviceName: string, edges: DepEdge[], symbols: SymbolEntry[]): string;
|
|
@@ -59,11 +59,6 @@ function inferRole(relPath) {
|
|
|
59
59
|
return 'Utility';
|
|
60
60
|
return null;
|
|
61
61
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Build the embedding-input prompt for one chunk. `symbols` is the file's
|
|
64
|
-
* top-level declarations only (never members) — the prompt is unaffected by
|
|
65
|
-
* this change (see the `symbol-index-members` non-goal).
|
|
66
|
-
*/
|
|
67
62
|
function getEnrichedPrompt(piece, relPath, serviceName, edges, symbols) {
|
|
68
63
|
const chunkStart = piece.startLine;
|
|
69
64
|
const chunkEnd = piece.endLine;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const MAX_CAUSES = 5;
|
|
2
|
+
export declare const MAX_FRAMES = 30;
|
|
3
|
+
export declare const MAX_QUERY_CHARS = 500;
|
|
4
|
+
export declare const MAX_PARAMS = 30;
|
|
5
|
+
export declare const MAX_PARAM_CHARS = 120;
|
|
6
|
+
export declare const MAX_AGGREGATED = 10;
|
|
7
|
+
export declare function serializeError(value: unknown): unknown;
|
|
8
|
+
export declare function rootCauseMessage(value: unknown): string;
|
|
9
|
+
export declare function errorMessage(value: unknown): string;
|
|
10
|
+
export declare const LOG_SERIALIZERS: {
|
|
11
|
+
err: typeof serializeError;
|
|
12
|
+
};
|