@dimassetoid/septum-mcp 0.3.0 → 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 +38 -55
- package/package.json +7 -5
- package/src/cli/commands/check.ts +14 -10
- package/src/cli/commands/hook.ts +41 -6
- package/src/cli/commands/init.ts +10 -1
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +32 -4
- package/src/cli/index.ts +7 -0
- package/src/cli/templates/hooks.ts +3 -14
- package/src/cli/templates/skill.ts +17 -10
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +251 -114
- package/src/core/boundary/staged-auditor.ts +147 -55
- package/src/core/config/domain-ownership.ts +6 -4
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +1 -25
- package/src/core/config/schema.ts +24 -36
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +334 -572
- package/src/core/database/repositories/domain.repository.ts +2 -1
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -398
- package/src/core/database/repository.ts +68 -9
- package/src/core/database/schema.ts +26 -0
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +222 -58
- package/src/core/discovery/topology-detector.ts +93 -168
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +287 -88
- package/src/core/parser/extractors/base.ts +11 -3
- package/src/core/parser/extractors/csharp.ts +2 -2
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +397 -481
- package/src/core/parser/extractors/elysia-semantic.ts +172 -475
- package/src/core/parser/extractors/express-semantic.ts +195 -383
- package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
- package/src/core/parser/extractors/fastify-semantic.ts +216 -717
- package/src/core/parser/extractors/flask-semantic.ts +89 -352
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +205 -562
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -509
- package/src/core/parser/extractors/java.ts +2 -2
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +143 -335
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +1 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +5 -9
- package/src/core/parser/extractors/registry.ts +2 -0
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +2 -2
- package/src/core/parser/extractors/rust.ts +4 -4
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +72 -226
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +23 -216
- package/src/core/parser/language-capabilities.ts +1 -1
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +169 -414
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +60 -7
- package/src/core/resolver/interpretation-inputs.ts +60 -2
- package/src/core/resolver/languages/python.ts +31 -13
- package/src/core/resolver/languages/shared.ts +4 -1
- package/src/core/resolver/module-resolver.ts +10 -3
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +21 -6
- package/src/core/resolver/slice-format.ts +13 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +104 -8
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +31 -230
- package/src/core/resources/ignore.ts +0 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +11 -4
- package/src/core/retrieval/context.ts +363 -226
- package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +3 -3
- package/src/core/retrieval/typescript-references.ts +38 -7
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +192 -49
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +253 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -746
- package/src/mcp/server.ts +269 -429
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +68 -3
- package/src/mcp/tools/map.ts +104 -4
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +469 -17
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +88 -15
- package/src/mcp/workspace-watcher.ts +30 -11
- package/src/types/index.ts +12 -0
- package/src/mcp/tools/check-boundary.ts +0 -382
- package/src/mcp/tools/get-domain-catalog.ts +0 -39
- package/src/mcp/tools/get-symbol-impact.ts +0 -104
- package/src/mcp/tools/locate-symbol.ts +0 -236
- package/src/mcp/tools/register-domain.ts +0 -113
- package/src/mcp/tools/trace-vertical-slice.ts +0 -106
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
SymbolRecord,
|
|
10
10
|
} from "../../../types/index.ts";
|
|
11
11
|
import { DependencyRepository } from "./dependency.repository.ts";
|
|
12
|
+
import { buildDomainFileConnections } from "../../resolver/dependency-analysis.ts";
|
|
12
13
|
import { domainNameKey, domainRootIdentity, DomainRootConflictError } from "../../config/domain-ownership.ts";
|
|
13
14
|
|
|
14
15
|
const CONTAINER_KINDS = new Set<SymbolKind>([
|
|
@@ -223,7 +224,7 @@ export class DomainRepository {
|
|
|
223
224
|
|
|
224
225
|
// Batch compute file connections for the domain (zero N+1)
|
|
225
226
|
const depRepo = new DependencyRepository(this.db);
|
|
226
|
-
const connectionsByPath = depRepo
|
|
227
|
+
const connectionsByPath = buildDomainFileConnections(depRepo, domain.id, options?.workspaceRoot);
|
|
227
228
|
|
|
228
229
|
for (const file of files) {
|
|
229
230
|
const symbols = symbolsByFileId.get(file.id) ?? [];
|
|
@@ -114,4 +114,14 @@ export class FileRepository {
|
|
|
114
114
|
|
|
115
115
|
return { file, domain };
|
|
116
116
|
}
|
|
117
|
+
|
|
118
|
+
public rebindFilesToDomain(rootPrefix: string, domainId: number): number {
|
|
119
|
+
const normalized = rootPrefix.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, "");
|
|
120
|
+
if (!normalized || normalized === ".") return 0;
|
|
121
|
+
const result = this.db.run(
|
|
122
|
+
"UPDATE files SET domain_id = ? WHERE (path = ? OR path LIKE ? || '/%')",
|
|
123
|
+
[domainId, normalized, normalized]
|
|
124
|
+
);
|
|
125
|
+
return result.changes;
|
|
126
|
+
}
|
|
117
127
|
}
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { symbolReference, matchesSymbolName, matchesSymbolReference } from "../../resolver/symbol-reference.ts";
|
|
2
|
-
import * as path from "node:path";
|
|
3
2
|
import type { Database } from "bun:sqlite";
|
|
4
3
|
import type {
|
|
5
|
-
DomainRecord,
|
|
6
4
|
ExtractedSymbol,
|
|
7
5
|
FileRecord,
|
|
8
|
-
GetSymbolDetailsResponse,
|
|
9
|
-
FileConnectionsSummary,
|
|
10
|
-
ResolvedOutboundCall,
|
|
11
|
-
SymbolComplexitySmell,
|
|
12
6
|
SymbolKind,
|
|
13
7
|
SymbolRecord,
|
|
14
8
|
SymbolCandidate,
|
|
15
9
|
SymbolSelectionOptions,
|
|
16
10
|
} from "../../../types/index.ts";
|
|
17
|
-
import { DependencyRepository } from "./dependency.repository.ts";
|
|
18
|
-
import { probeSourcePath, readSourceFile } from "../../resources/source-files.ts";
|
|
19
|
-
import { assertPathContained } from "../../resolver/path-resolver.ts";
|
|
20
11
|
|
|
21
12
|
const SQL_KEYWORD_BLACKLIST = new Set([
|
|
22
13
|
"VALUES",
|
|
@@ -37,6 +28,11 @@ function stripCommentsAndStrings(source: string): string {
|
|
|
37
28
|
.replace(/'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`/g, '""');
|
|
38
29
|
}
|
|
39
30
|
|
|
31
|
+
export function computeSymbolLeafName(name: string): string {
|
|
32
|
+
const trimmed = name.trim().replace(/\(\)$/, "");
|
|
33
|
+
return trimmed.split(/::|->|[.#/\\]/).pop() ?? trimmed;
|
|
34
|
+
}
|
|
35
|
+
|
|
40
36
|
export class SymbolRepository {
|
|
41
37
|
constructor(private db: Database) {}
|
|
42
38
|
|
|
@@ -45,8 +41,8 @@ export class SymbolRepository {
|
|
|
45
41
|
if (symbols.length === 0) return;
|
|
46
42
|
|
|
47
43
|
const stmt = this.db.query(
|
|
48
|
-
`INSERT INTO symbols (file_id, name, kind, signature, visibility, line_start, line_end, line_count, nesting_depth)
|
|
49
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
44
|
+
`INSERT INTO symbols (file_id, name, leaf_name, kind, signature, visibility, line_start, line_end, line_count, nesting_depth)
|
|
45
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
50
46
|
);
|
|
51
47
|
|
|
52
48
|
for (const sym of symbols) {
|
|
@@ -55,6 +51,7 @@ export class SymbolRepository {
|
|
|
55
51
|
stmt.run(
|
|
56
52
|
fileId,
|
|
57
53
|
sym.name,
|
|
54
|
+
computeSymbolLeafName(sym.name),
|
|
58
55
|
sym.kind,
|
|
59
56
|
sym.signature,
|
|
60
57
|
sym.visibility,
|
|
@@ -79,11 +76,12 @@ export class SymbolRepository {
|
|
|
79
76
|
options: SymbolSelectionOptions = {}
|
|
80
77
|
): SymbolCandidate[] {
|
|
81
78
|
const target = name.trim().replace(/\(\)$/, "");
|
|
82
|
-
|
|
79
|
+
if (!target) return [];
|
|
80
|
+
const leaf = computeSymbolLeafName(target);
|
|
83
81
|
let query = `SELECT s.*, f.path AS file_path, f.content_hash AS indexed_content_hash, d.name AS domain_name
|
|
84
82
|
FROM symbols s JOIN files f ON s.file_id = f.id JOIN domains d ON f.domain_id = d.id
|
|
85
|
-
WHERE (s.name = ? OR
|
|
86
|
-
const params: string[] = [target, leaf
|
|
83
|
+
WHERE (s.name = ? OR s.leaf_name = ?)`;
|
|
84
|
+
const params: string[] = [target, leaf];
|
|
87
85
|
if (options.domain) { query += " AND d.name = ?"; params.push(options.domain); }
|
|
88
86
|
const filePath = options.filePath ?? options.reference?.file_path;
|
|
89
87
|
if (filePath) { query += " AND f.path = ?"; params.push(filePath); }
|
|
@@ -152,15 +150,76 @@ export class SymbolRepository {
|
|
|
152
150
|
return files.map((file) => ({ file }));
|
|
153
151
|
}
|
|
154
152
|
|
|
155
|
-
public
|
|
153
|
+
public findFuzzySymbolCandidates(
|
|
154
|
+
queryStr: string,
|
|
155
|
+
options?: { domainId?: number; filePath?: string; limit?: number }
|
|
156
|
+
): Array<SymbolRecord & { file_path: string }> {
|
|
157
|
+
const targetLeaf = computeSymbolLeafName(queryStr);
|
|
158
|
+
const clauses = [
|
|
159
|
+
"s.kind IN ('class', 'interface', 'trait', 'struct', 'enum', 'type', 'method', 'function', 'constant')",
|
|
160
|
+
];
|
|
161
|
+
const params: Array<string | number> = [];
|
|
162
|
+
if (options?.filePath) {
|
|
163
|
+
clauses.push("f.path = ?");
|
|
164
|
+
params.push(options.filePath);
|
|
165
|
+
}
|
|
166
|
+
if (options?.domainId !== undefined) {
|
|
167
|
+
clauses.push("f.domain_id = ?");
|
|
168
|
+
params.push(options.domainId);
|
|
169
|
+
}
|
|
170
|
+
if (targetLeaf.length >= 2) {
|
|
171
|
+
const minLen = Math.max(1, Math.floor(targetLeaf.length * 0.4));
|
|
172
|
+
const maxLen = Math.max(targetLeaf.length + 12, Math.ceil(targetLeaf.length * 2.5));
|
|
173
|
+
clauses.push("length(s.leaf_name) BETWEEN ? AND ?");
|
|
174
|
+
params.push(minLen, maxLen);
|
|
175
|
+
}
|
|
176
|
+
if (targetLeaf.length >= 4) {
|
|
177
|
+
const lower = targetLeaf.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
178
|
+
const distinct: string[] = [];
|
|
179
|
+
for (const ch of lower) {
|
|
180
|
+
if (!distinct.includes(ch)) {
|
|
181
|
+
distinct.push(ch);
|
|
182
|
+
if (distinct.length >= 4) break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (distinct.length > 0) {
|
|
186
|
+
const charClauses = distinct.map(() => "instr(lower(s.leaf_name), ?) > 0");
|
|
187
|
+
clauses.push(`(${charClauses.join(" OR ")})`);
|
|
188
|
+
params.push(...distinct);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const limit = Math.max(1, options?.limit ?? 500);
|
|
192
|
+
params.push(targetLeaf.length, limit);
|
|
193
|
+
const query = `
|
|
194
|
+
SELECT s.*, f.path AS file_path
|
|
195
|
+
FROM symbols s
|
|
196
|
+
JOIN files f ON s.file_id = f.id
|
|
197
|
+
WHERE ${clauses.join(" AND ")}
|
|
198
|
+
ORDER BY abs(length(s.leaf_name) - ?) ASC, s.line_start ASC
|
|
199
|
+
LIMIT ?
|
|
200
|
+
`;
|
|
201
|
+
return this.db.query<SymbolRecord & { file_path: string }, Array<string | number>>(query).all(...params);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public getAllSymbolsWithFiles(filter?: { domainId?: number; filePath?: string }): Array<SymbolRecord & { file_path: string }> {
|
|
205
|
+
const clauses = ["s.kind IN ('class', 'interface', 'trait', 'struct', 'enum', 'type', 'method', 'function', 'constant')"];
|
|
206
|
+
const params: Array<string | number> = [];
|
|
207
|
+
if (filter?.filePath) {
|
|
208
|
+
clauses.push("f.path = ?");
|
|
209
|
+
params.push(filter.filePath);
|
|
210
|
+
}
|
|
211
|
+
if (filter?.domainId !== undefined) {
|
|
212
|
+
clauses.push("f.domain_id = ?");
|
|
213
|
+
params.push(filter.domainId);
|
|
214
|
+
}
|
|
156
215
|
const query = `
|
|
157
216
|
SELECT s.*, f.path AS file_path
|
|
158
217
|
FROM symbols s
|
|
159
218
|
JOIN files f ON s.file_id = f.id
|
|
160
|
-
WHERE
|
|
219
|
+
WHERE ${clauses.join(" AND ")}
|
|
161
220
|
ORDER BY s.line_start ASC, s.name ASC
|
|
162
221
|
`;
|
|
163
|
-
return this.db.query<SymbolRecord & { file_path: string },
|
|
222
|
+
return this.db.query<SymbolRecord & { file_path: string }, Array<string | number>>(query).all(...params);
|
|
164
223
|
}
|
|
165
224
|
|
|
166
225
|
public findSymbolWithDomain(symbolName: string): {
|
|
@@ -261,387 +320,27 @@ export class SymbolRepository {
|
|
|
261
320
|
return this.db.query<any, [string]>(query).get(filePath) ?? null;
|
|
262
321
|
}
|
|
263
322
|
|
|
264
|
-
public
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const containerName = row.symbol_ref.container ?? "";
|
|
278
|
-
const owner = ["class", "interface", "trait", "struct", "enum"].includes(row.kind) ? row.name
|
|
279
|
-
: row.kind === "method" ? containerName : "";
|
|
280
|
-
let siblingMethods: string[] = owner ? this.getSymbolsByFileId(row.file_id)
|
|
281
|
-
.filter(s => s.kind === "method" && s.id !== row.id)
|
|
282
|
-
.filter(s => symbolReference({ ...s, file_path: row.file_path, indexed_content_hash: row.indexed_content_hash }).container === owner)
|
|
283
|
-
.map(s => s.name.split(/::|[.#]/).pop()!) : [];
|
|
284
|
-
|
|
285
|
-
siblingMethods = Array.from(new Set(siblingMethods)).filter(
|
|
286
|
-
(m) => !SQL_KEYWORD_BLACKLIST.has(m.toUpperCase())
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
// 2. Dependencies Injected (from signature type-hints and constructor)
|
|
290
|
-
const dependenciesInjected = new Set<string>();
|
|
291
|
-
const outboundCalls = new Set<string>();
|
|
292
|
-
const resolvedOutboundCalls: ResolvedOutboundCall[] = [];
|
|
293
|
-
let connectedFiles: FileConnectionsSummary = { imports_from: [], imported_by_count: 0 };
|
|
294
|
-
|
|
295
|
-
const shouldIncludeDeps = options.includeDependencies !== false;
|
|
296
|
-
|
|
297
|
-
if (shouldIncludeDeps) {
|
|
298
|
-
const varTypes = new Map<string, string>();
|
|
299
|
-
const primitiveTypes = new Set([
|
|
300
|
-
"int", "string", "str", "bool", "boolean", "float", "double", "decimal",
|
|
301
|
-
"number", "bigint", "symbol", "array", "list", "dict", "tuple", "set",
|
|
302
|
-
"iterable", "callable", "function", "void", "mixed", "object", "null",
|
|
303
|
-
"undefined", "never", "any", "unknown", "true", "false", "record",
|
|
304
|
-
"partial", "omit", "pick", "readonly", "required", "promise", "map",
|
|
305
|
-
"weakmap", "weakset", "date", "error", "regexp", "buffer", "abortsignal",
|
|
306
|
-
"uint8array", "self", "cls",
|
|
307
|
-
]);
|
|
308
|
-
const modifierWords = new Set([
|
|
309
|
-
"public", "private", "protected", "readonly", "final", "var", "val",
|
|
310
|
-
"mut", "ref", "in", "out", "params", "async",
|
|
311
|
-
]);
|
|
312
|
-
|
|
313
|
-
const splitTopLevel = (input: string, delimiter: string): string[] => {
|
|
314
|
-
const result: string[] = [];
|
|
315
|
-
let current = "";
|
|
316
|
-
let depth = 0;
|
|
317
|
-
for (let i = 0; i < input.length; i++) {
|
|
318
|
-
const ch = input[i];
|
|
319
|
-
if (ch === "(" || ch === "<" || ch === "[" || ch === "{") depth++;
|
|
320
|
-
else if (ch === ")" || ch === ">" || ch === "]" || ch === "}") depth = Math.max(0, depth - 1);
|
|
321
|
-
if (depth === 0 && input.startsWith(delimiter, i)) {
|
|
322
|
-
result.push(current);
|
|
323
|
-
current = "";
|
|
324
|
-
i += delimiter.length - 1;
|
|
325
|
-
} else {
|
|
326
|
-
current += ch;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
if (current.trim()) result.push(current);
|
|
330
|
-
return result;
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
const registerTypeToken = (rawToken: string, paramName?: string) => {
|
|
334
|
-
let token = rawToken.trim()
|
|
335
|
-
.replace(/^\?+/, "")
|
|
336
|
-
.replace(/^&+/, "")
|
|
337
|
-
.replace(/^\*+/, "")
|
|
338
|
-
.replace(/\[\]$/, "")
|
|
339
|
-
.replace(/<.*>$/s, "")
|
|
340
|
-
.replace(/^[\\$]/, "")
|
|
341
|
-
.trim();
|
|
342
|
-
if (token.includes("\\")) token = token.split("\\").pop() || token;
|
|
343
|
-
if (token.includes(".")) token = token.split(".").pop() || token;
|
|
344
|
-
if (!token || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(token)) return;
|
|
345
|
-
if (primitiveTypes.has(token.toLowerCase()) || modifierWords.has(token.toLowerCase())) return;
|
|
346
|
-
dependenciesInjected.add(token);
|
|
347
|
-
if (paramName && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(paramName) && !varTypes.has(paramName)) {
|
|
348
|
-
varTypes.set(paramName, token);
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
const extractTypeHints = (sig: string) => {
|
|
353
|
-
const openIdx = sig.indexOf("(");
|
|
354
|
-
if (openIdx === -1) return;
|
|
355
|
-
let closeIdx = -1;
|
|
356
|
-
let depth = 0;
|
|
357
|
-
for (let i = openIdx; i < sig.length; i++) {
|
|
358
|
-
if (sig[i] === "(") depth++;
|
|
359
|
-
else if (sig[i] === ")") {
|
|
360
|
-
depth--;
|
|
361
|
-
if (depth === 0) {
|
|
362
|
-
closeIdx = i;
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
if (closeIdx <= openIdx + 1) return;
|
|
368
|
-
const paramBlock = sig.slice(openIdx + 1, closeIdx);
|
|
369
|
-
const params = splitTopLevel(paramBlock, ",");
|
|
370
|
-
const isGo = /\.go$/i.test(row.file_path);
|
|
371
|
-
|
|
372
|
-
for (const rawParam of params) {
|
|
373
|
-
let p = rawParam.trim();
|
|
374
|
-
if (!p) continue;
|
|
375
|
-
// Strip top-level default value `= ...` (ignoring `=>` in arrow types)
|
|
376
|
-
let eqDepth = 0;
|
|
377
|
-
for (let i = 0; i < p.length; i++) {
|
|
378
|
-
const ch = p[i];
|
|
379
|
-
if (ch === "(" || ch === "<" || ch === "[" || ch === "{") eqDepth++;
|
|
380
|
-
else if (ch === ")" || ch === ">" || ch === "]" || ch === "}") eqDepth = Math.max(0, eqDepth - 1);
|
|
381
|
-
else if (eqDepth === 0 && ch === "=" && p[i + 1] !== ">" && p[i - 1] !== "!" && p[i - 1] !== "=" && p[i - 1] !== "<" && p[i - 1] !== ">") {
|
|
382
|
-
p = p.slice(0, i).trim();
|
|
383
|
-
break;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
// Check for top-level colon `param: Type` (TypeScript, Python, etc.)
|
|
387
|
-
let colonIdx = -1;
|
|
388
|
-
let colDepth = 0;
|
|
389
|
-
for (let i = 0; i < p.length; i++) {
|
|
390
|
-
const ch = p[i];
|
|
391
|
-
if (ch === "(" || ch === "<" || ch === "[" || ch === "{") colDepth++;
|
|
392
|
-
else if (ch === ")" || ch === ">" || ch === "]" || ch === "}") colDepth = Math.max(0, colDepth - 1);
|
|
393
|
-
else if (colDepth === 0 && ch === ":" && p[i + 1] !== ":" && p[i - 1] !== ":") {
|
|
394
|
-
colonIdx = i;
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
if (colonIdx !== -1) {
|
|
400
|
-
const leftTokens = p.slice(0, colonIdx).trim().replace(/^\.{3}/, "").split(/\s+/)
|
|
401
|
-
.filter(t => !modifierWords.has(t.toLowerCase()));
|
|
402
|
-
const rawParamName = (leftTokens.pop() || "").replace(/\?$/, "").replace(/^\$/, "");
|
|
403
|
-
const typeExpr = p.slice(colonIdx + 1).trim();
|
|
404
|
-
if (typeExpr.startsWith("{") || typeExpr.startsWith("(") || typeExpr.startsWith("[")) continue;
|
|
405
|
-
// Support generic wrappers like Promise<Type> or Array<Type> or union TypeA | TypeB
|
|
406
|
-
for (const branch of splitTopLevel(typeExpr, "|")) {
|
|
407
|
-
const trimmedBranch = branch.trim();
|
|
408
|
-
const wrapperMatch = /^(?:Promise|Array|ReadonlyArray|Partial|Required|Readonly)\s*<(.+)>$/s.exec(trimmedBranch);
|
|
409
|
-
registerTypeToken(wrapperMatch ? wrapperMatch[1] : trimmedBranch, rawParamName);
|
|
410
|
-
}
|
|
411
|
-
} else {
|
|
412
|
-
const parts = p.replace(/^\.{3}/, "").split(/\s+/).filter(t => !modifierWords.has(t.toLowerCase()));
|
|
413
|
-
if (parts.length >= 2) {
|
|
414
|
-
if (isGo) {
|
|
415
|
-
const rawParamName = parts[0];
|
|
416
|
-
const rawType = parts[parts.length - 1];
|
|
417
|
-
registerTypeToken(rawType, rawParamName);
|
|
418
|
-
} else {
|
|
419
|
-
const rawType = parts[0];
|
|
420
|
-
const rawParamName = parts[1].replace(/^[$&]+/, "");
|
|
421
|
-
registerTypeToken(rawType, rawParamName);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
// Rust parameter types do not establish a dependency injection binding.
|
|
429
|
-
if (!isRust) extractTypeHints(row.signature);
|
|
430
|
-
|
|
431
|
-
// Also check constructor injection if this is a method or class
|
|
432
|
-
const classOwner = containerName || (row.kind === "class" ? row.name : "");
|
|
433
|
-
if (classOwner && !isRust) {
|
|
434
|
-
const ctor = this.db
|
|
435
|
-
.query<{ signature: string }, [number, string, string, string, string]>(
|
|
436
|
-
"SELECT signature FROM symbols WHERE file_id = ? AND (name = ? OR name = ? OR name = ? OR name LIKE ?) LIMIT 1"
|
|
437
|
-
)
|
|
438
|
-
.get(
|
|
439
|
-
row.file_id,
|
|
440
|
-
`${classOwner}::__construct`,
|
|
441
|
-
`${classOwner}::constructor`,
|
|
442
|
-
`${classOwner}::__init__`,
|
|
443
|
-
`%::__construct`
|
|
444
|
-
);
|
|
445
|
-
if (ctor) {
|
|
446
|
-
extractTypeHints(ctor.signature);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// 3. Outbound Calls (inspected from physical source file lines if accessible)
|
|
451
|
-
try {
|
|
452
|
-
const fullPath = options.workspaceRoot
|
|
453
|
-
? path.resolve(options.workspaceRoot, row.file_path)
|
|
454
|
-
: row.file_path;
|
|
455
|
-
// Public handlers provide a workspace; the legacy rootless repository API also accepts absolute paths.
|
|
456
|
-
if (options.workspaceRoot) assertPathContained(fullPath, options.workspaceRoot, "Outbound call source");
|
|
457
|
-
if (probeSourcePath(fullPath) === "file") {
|
|
458
|
-
const fileContent = readSourceFile(fullPath);
|
|
459
|
-
const lines = fileContent.split(/\r?\n/);
|
|
460
|
-
const start = Math.max(0, row.line_start - 1);
|
|
461
|
-
const end = Math.min(lines.length, row.line_end);
|
|
462
|
-
const rawSlice = lines.slice(start, end).join("\n");
|
|
463
|
-
const sanitizedSlice = stripCommentsAndStrings(rawSlice);
|
|
464
|
-
|
|
465
|
-
// Track local `new ClassName(...)` assignments inside the symbol slice
|
|
466
|
-
for (const m of sanitizedSlice.matchAll(/(?:const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*new\s+([A-Z][a-zA-Z0-9_]*)\s*\(/g)) {
|
|
467
|
-
varTypes.set(m[1], m[2]);
|
|
468
|
-
}
|
|
469
|
-
for (const m of sanitizedSlice.matchAll(/\$([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*new\s+([A-Z][a-zA-Z0-9_]*)\s*\(/g)) {
|
|
470
|
-
varTypes.set(m[1], m[2]);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// Match Static invocations: ClassName::methodName(
|
|
474
|
-
const staticCalls = sanitizedSlice.matchAll(/([A-Z][a-zA-Z0-9_]+)::([a-zA-Z0-9_]+)\s*\(/g);
|
|
475
|
-
for (const m of staticCalls) {
|
|
476
|
-
if (m[1] !== "self" && m[1] !== "parent" && m[1] !== "static") {
|
|
477
|
-
outboundCalls.add(`${m[1]}::${m[2]}`);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// Match PHP property calls: $this->property->method(
|
|
482
|
-
const propCalls = sanitizedSlice.matchAll(/\$this->([a-zA-Z0-9_]+)->([a-zA-Z0-9_]+)\s*\(/g);
|
|
483
|
-
for (const m of propCalls) {
|
|
484
|
-
const propName = m[1];
|
|
485
|
-
const methodName = m[2];
|
|
486
|
-
const mappedType = varTypes.get(propName);
|
|
487
|
-
const inferredClass = mappedType || (propName.charAt(0).toUpperCase() + propName.slice(1));
|
|
488
|
-
outboundCalls.add(`${inferredClass}::${methodName}`);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// Match TS/JS property calls: this.property.method(
|
|
492
|
-
const tsPropCalls = sanitizedSlice.matchAll(/\bthis\.([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)\s*\(/g);
|
|
493
|
-
for (const m of tsPropCalls) {
|
|
494
|
-
const propName = m[1];
|
|
495
|
-
const methodName = m[2];
|
|
496
|
-
if (propName !== "db") {
|
|
497
|
-
const mappedType = varTypes.get(propName);
|
|
498
|
-
const inferredClass = mappedType || (propName.charAt(0).toUpperCase() + propName.slice(1));
|
|
499
|
-
outboundCalls.add(`${inferredClass}::${methodName}`);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// Collect same-file symbols and explicitly imported symbols for high-precision direct & receiver call detection
|
|
504
|
-
const sameFileSymbols = this.getSymbolsByFileId(row.file_id);
|
|
505
|
-
const knownDirectCallables = new Set<string>();
|
|
506
|
-
const knownStaticReceivers = new Set<string>();
|
|
507
|
-
for (const s of sameFileSymbols) {
|
|
508
|
-
if (s.id === row.id) continue;
|
|
509
|
-
if (s.kind === "function") knownDirectCallables.add(s.name);
|
|
510
|
-
else if (s.kind === "class") knownStaticReceivers.add(s.name);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
const fileDeps = this.db
|
|
514
|
-
.query<{ import_statement: string }, [number]>(
|
|
515
|
-
"SELECT import_statement FROM dependencies WHERE source_file_id = ? AND is_external = 0"
|
|
516
|
-
)
|
|
517
|
-
.all(row.file_id);
|
|
518
|
-
for (const dep of fileDeps) {
|
|
519
|
-
const stmt = dep.import_statement || "";
|
|
520
|
-
if (/^\s*import\s+type\b/.test(stmt)) continue;
|
|
521
|
-
const braceMatch = stmt.match(/\{([^}]+)\}/);
|
|
522
|
-
if (braceMatch) {
|
|
523
|
-
for (const spec of braceMatch[1].split(",")) {
|
|
524
|
-
const trimmedSpec = spec.trim();
|
|
525
|
-
if (/^type\s+/.test(trimmedSpec)) continue;
|
|
526
|
-
const aliasParts = trimmedSpec.split(/\s+as\s+/);
|
|
527
|
-
const localName = (aliasParts[1] || aliasParts[0] || "").trim();
|
|
528
|
-
if (/^[a-z_$][a-zA-Z0-9_$]*$/.test(localName)) knownDirectCallables.add(localName);
|
|
529
|
-
else if (/^[A-Z][a-zA-Z0-9_$]*$/.test(localName)) knownStaticReceivers.add(localName);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
const defaultMatch = stmt.match(/^\s*import\s+([A-Za-z_$][A-Za-z0-9_$]*)\s+from\b/);
|
|
533
|
-
if (defaultMatch) {
|
|
534
|
-
const localName = defaultMatch[1];
|
|
535
|
-
if (/^[a-z_$]/.test(localName)) knownDirectCallables.add(localName);
|
|
536
|
-
else knownStaticReceivers.add(localName);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
// Match calls on typed parameters / local instances (`repo.findSymbolsByName(` or `TopologyDetector.detect(`)
|
|
541
|
-
for (const m of sanitizedSlice.matchAll(/\b([a-zA-Z_$][a-zA-Z0-9_$]*)\.([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g)) {
|
|
542
|
-
const receiver = m[1];
|
|
543
|
-
const method = m[2];
|
|
544
|
-
if (receiver === "this" || receiver === "super" || receiver === "console" || receiver === "process" || receiver === "Math" || receiver === "JSON" || receiver === "Object" || receiver === "Array" || receiver === "Buffer" || receiver === "Promise" || receiver === "Number" || receiver === "String") continue;
|
|
545
|
-
const mappedType = varTypes.get(receiver);
|
|
546
|
-
if (mappedType) {
|
|
547
|
-
outboundCalls.add(`${mappedType}::${method}`);
|
|
548
|
-
} else if (knownStaticReceivers.has(receiver)) {
|
|
549
|
-
outboundCalls.add(`${receiver}::${method}`);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
for (const m of sanitizedSlice.matchAll(/\$([a-zA-Z_][a-zA-Z0-9_]*)\s*->\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\(/g)) {
|
|
553
|
-
const receiver = m[1];
|
|
554
|
-
const method = m[2];
|
|
555
|
-
if (receiver === "this") continue;
|
|
556
|
-
const mappedType = varTypes.get(receiver);
|
|
557
|
-
if (mappedType) {
|
|
558
|
-
outboundCalls.add(`${mappedType}::${method}`);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// Match direct function calls inside symbol body (after opening `{`)
|
|
563
|
-
const bodyStartIdx = sanitizedSlice.indexOf("{");
|
|
564
|
-
const bodySlice = bodyStartIdx !== -1 ? sanitizedSlice.slice(bodyStartIdx + 1) : "";
|
|
565
|
-
if (bodySlice && knownDirectCallables.size > 0) {
|
|
566
|
-
for (const m of bodySlice.matchAll(/(?:^|[^.\w$:])([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g)) {
|
|
567
|
-
const fnName = m[1];
|
|
568
|
-
if (fnName !== row.name && knownDirectCallables.has(fnName)) {
|
|
569
|
-
outboundCalls.add(fnName);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
} catch {
|
|
575
|
-
// Graceful fallback if file not physically accessible
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const depRepo = new DependencyRepository(this.db);
|
|
579
|
-
connectedFiles = depRepo.getFileConnections(row.file_path,options.workspaceRoot);
|
|
580
|
-
|
|
581
|
-
// 4. Resolve Outbound Calls to target symbol line ranges
|
|
582
|
-
for (const call of outboundCalls) {
|
|
583
|
-
try {
|
|
584
|
-
const matches = this.findSymbolsByName(call);
|
|
585
|
-
const target = matches.length === 1 ? matches[0] : undefined;
|
|
586
|
-
if (target) {
|
|
587
|
-
resolvedOutboundCalls.push({
|
|
588
|
-
symbol: call,
|
|
589
|
-
target_file: target.file_path,
|
|
590
|
-
target_range: {
|
|
591
|
-
start_line: target.line_start,
|
|
592
|
-
end_line: target.line_end,
|
|
593
|
-
total_lines: target.line_count,
|
|
594
|
-
},
|
|
595
|
-
domain: target.domain_name,
|
|
596
|
-
is_resolved: true,
|
|
597
|
-
});
|
|
598
|
-
} else {
|
|
599
|
-
resolvedOutboundCalls.push({
|
|
600
|
-
symbol: call,
|
|
601
|
-
is_resolved: false,
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
} catch {
|
|
605
|
-
resolvedOutboundCalls.push({
|
|
606
|
-
symbol: call,
|
|
607
|
-
is_resolved: false,
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
const complexitySmell: SymbolComplexitySmell | undefined =
|
|
614
|
-
row.line_count > 300
|
|
615
|
-
? {
|
|
616
|
-
is_high_complexity: true,
|
|
617
|
-
threshold: 300,
|
|
618
|
-
total_lines: row.line_count,
|
|
619
|
-
warning: `Symbol '${row.name}' spans ${row.line_count} lines (exceeds 300-line threshold). Candidate for decomposition/refactoring.`,
|
|
620
|
-
}
|
|
621
|
-
: undefined;
|
|
622
|
-
|
|
623
|
-
return {
|
|
624
|
-
symbol_ref: row.symbol_ref,
|
|
625
|
-
visibility_semantics: "legacy_normalized",
|
|
626
|
-
symbol: row.name,
|
|
627
|
-
kind: row.kind,
|
|
628
|
-
file_path: row.file_path,
|
|
629
|
-
domain: row.domain_name,
|
|
630
|
-
exact_range: {
|
|
631
|
-
start_line: row.line_start,
|
|
632
|
-
end_line: row.line_end,
|
|
633
|
-
total_lines: row.line_count,
|
|
634
|
-
},
|
|
635
|
-
signature: row.signature,
|
|
636
|
-
visibility: row.visibility,
|
|
637
|
-
dependencies_injected: Array.from(dependenciesInjected),
|
|
638
|
-
outbound_calls: Array.from(outboundCalls),
|
|
639
|
-
resolved_outbound_calls: resolvedOutboundCalls.length > 0 ? resolvedOutboundCalls.map(call => ({ ...call, derivation: "inferred" as const })) : undefined,
|
|
640
|
-
complexity_smell: complexitySmell,
|
|
641
|
-
sibling_methods: siblingMethods.length > 0 ? siblingMethods : undefined,
|
|
642
|
-
connected_files: connectedFiles,
|
|
643
|
-
...(options.includeDependencies === true ? { relationships: new DependencyRepository(this.db).getImportRelationships(options.workspaceRoot).filter(edge => edge.source.file === row.file_path) } : {}),
|
|
644
|
-
};
|
|
323
|
+
public findConstructorSignature(fileId: number, classOwner: string): string | null {
|
|
324
|
+
const ctor = this.db
|
|
325
|
+
.query<{ signature: string }, [number, string, string, string, string]>(
|
|
326
|
+
"SELECT signature FROM symbols WHERE file_id = ? AND (name = ? OR name = ? OR name = ? OR name LIKE ?) LIMIT 1"
|
|
327
|
+
)
|
|
328
|
+
.get(
|
|
329
|
+
fileId,
|
|
330
|
+
`${classOwner}::__construct`,
|
|
331
|
+
`${classOwner}::constructor`,
|
|
332
|
+
`${classOwner}::__init__`,
|
|
333
|
+
`%::__construct`
|
|
334
|
+
);
|
|
335
|
+
return ctor?.signature ?? null;
|
|
645
336
|
}
|
|
646
337
|
|
|
338
|
+
public getInternalImportStatements(fileId: number): string[] {
|
|
339
|
+
return this.db
|
|
340
|
+
.query<{ import_statement: string }, [number]>(
|
|
341
|
+
"SELECT import_statement FROM dependencies WHERE source_file_id = ? AND is_external = 0"
|
|
342
|
+
)
|
|
343
|
+
.all(fileId)
|
|
344
|
+
.map((dep) => dep.import_statement || "");
|
|
345
|
+
}
|
|
647
346
|
}
|