@dimassetoid/septum-mcp 0.2.1 → 0.3.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 +46 -28
- package/package.json +4 -4
- package/src/cli/commands/check.ts +27 -16
- package/src/cli/commands/hook.ts +38 -101
- package/src/cli/commands/init.ts +26 -9
- package/src/cli/commands/sync.ts +4 -6
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +9 -52
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +49 -14
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +39 -35
- package/src/core/boundary/evaluator.ts +67 -83
- package/src/core/boundary/staged-auditor.ts +102 -40
- package/src/core/config/domain-ownership.ts +45 -0
- package/src/core/config/loader.ts +81 -29
- package/src/core/config/schema.ts +0 -10
- package/src/core/database/repositories/dependency.repository.ts +169 -148
- package/src/core/database/repositories/domain.repository.ts +46 -3
- package/src/core/database/repositories/symbol.repository.ts +226 -87
- package/src/core/database/repository.ts +73 -18
- package/src/core/database/schema.ts +2 -33
- package/src/core/discovery/navigation.ts +105 -0
- package/src/core/discovery/topology-detector.ts +60 -2
- package/src/core/ingestion/pipeline.ts +96 -129
- package/src/core/parser/behavioral-analyzer.ts +26 -22
- package/src/core/parser/boundary-tracker.ts +15 -0
- package/src/core/parser/extractors/base.ts +7 -3
- package/src/core/parser/extractors/csharp.ts +7 -3
- package/src/core/parser/extractors/django-semantic.ts +4 -36
- package/src/core/parser/extractors/elysia-semantic.ts +3 -24
- package/src/core/parser/extractors/express-semantic.ts +3 -18
- package/src/core/parser/extractors/fastapi-semantic.ts +19 -53
- package/src/core/parser/extractors/fastify-semantic.ts +3 -18
- package/src/core/parser/extractors/flask-semantic.ts +22 -55
- package/src/core/parser/extractors/go-semantic.ts +92 -33
- package/src/core/parser/extractors/hono-semantic.ts +3 -24
- package/src/core/parser/extractors/java.ts +5 -3
- package/src/core/parser/extractors/laravel-semantic.ts +44 -16
- package/src/core/parser/extractors/mcp-cli-semantic.ts +6 -7
- package/src/core/parser/extractors/nestjs-semantic.ts +3 -19
- package/src/core/parser/extractors/php.ts +16 -0
- package/src/core/parser/extractors/python.ts +9 -4
- package/src/core/parser/extractors/registry.ts +26 -5
- package/src/core/parser/extractors/ruby.ts +8 -5
- package/src/core/parser/extractors/rust.ts +31 -13
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-semantic.ts +4 -37
- package/src/core/parser/extractors/typescript.ts +14 -1
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +23 -7
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +73 -50
- package/src/core/parser/schema/schema-provider-registry.ts +1 -3
- package/src/core/parser/schema/schema-provider.interface.ts +2 -1
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- package/src/core/resolver/call-graph-tracer.ts +337 -28
- package/src/core/resolver/import-resolver.ts +107 -179
- package/src/core/resolver/interpretation-inputs.ts +7 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +115 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +71 -0
- package/src/core/resolver/module-resolver.ts +8 -4
- package/src/core/resolver/slice-catalog.ts +79 -0
- package/src/core/resolver/slice-format.ts +9 -0
- package/src/core/resolver/symbol-impact.ts +381 -0
- package/src/core/resolver/vertical-slice-tracer.ts +93 -115
- package/src/core/resources/ignore.ts +22 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/retrieval/context-page.ts +109 -0
- package/src/core/retrieval/context.ts +320 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +262 -0
- package/src/core/telemetry/telemetry.ts +54 -9
- package/src/index.ts +0 -3
- package/src/mcp/schemas.ts +61 -420
- package/src/mcp/server.ts +116 -290
- package/src/mcp/tools/boundary.ts +2 -2
- package/src/mcp/tools/check-boundary.ts +55 -60
- package/src/mcp/tools/get-domain-catalog.ts +32 -219
- package/src/mcp/tools/get-symbol-impact.ts +45 -5
- package/src/mcp/tools/get-symbol.ts +227 -3
- package/src/mcp/tools/locate-symbol.ts +54 -14
- package/src/mcp/tools/{domain.ts → map.ts} +4 -18
- package/src/mcp/tools/register-domain.ts +41 -3
- package/src/mcp/tools/symbol.ts +23 -21
- package/src/mcp/tools/trace-vertical-slice.ts +36 -10
- package/src/mcp/workspace-manager.ts +15 -4
- package/src/mcp/workspace-watcher.ts +8 -8
- package/src/types/index.ts +35 -53
- package/src/cli/commands/topology.ts +0 -161
- package/src/core/database/repositories/environment.repository.ts +0 -207
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
- package/src/core/session/session-manager.ts +0 -107
- package/src/core/topology/environment-detector.ts +0 -973
- package/src/core/topology/types.ts +0 -83
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-environment-topology.ts +0 -138
- package/src/mcp/tools/get-feature-context.ts +0 -224
- package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
- package/src/mcp/tools/register-feature.ts +0 -110
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { symbolReference, matchesSymbolName, matchesSymbolReference } from "../../resolver/symbol-reference.ts";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
2
|
import * as path from "node:path";
|
|
4
3
|
import type { Database } from "bun:sqlite";
|
|
5
4
|
import type {
|
|
@@ -16,6 +15,8 @@ import type {
|
|
|
16
15
|
SymbolSelectionOptions,
|
|
17
16
|
} from "../../../types/index.ts";
|
|
18
17
|
import { DependencyRepository } from "./dependency.repository.ts";
|
|
18
|
+
import { probeSourcePath, readSourceFile } from "../../resources/source-files.ts";
|
|
19
|
+
import { assertPathContained } from "../../resolver/path-resolver.ts";
|
|
19
20
|
|
|
20
21
|
const SQL_KEYWORD_BLACKLIST = new Set([
|
|
21
22
|
"VALUES",
|
|
@@ -156,8 +157,8 @@ export class SymbolRepository {
|
|
|
156
157
|
SELECT s.*, f.path AS file_path
|
|
157
158
|
FROM symbols s
|
|
158
159
|
JOIN files f ON s.file_id = f.id
|
|
159
|
-
WHERE s.kind IN ('class', 'method', 'function')
|
|
160
|
-
ORDER BY s.name ASC
|
|
160
|
+
WHERE s.kind IN ('class', 'interface', 'trait', 'struct', 'enum', 'type', 'method', 'function', 'constant')
|
|
161
|
+
ORDER BY s.line_start ASC, s.name ASC
|
|
161
162
|
`;
|
|
162
163
|
return this.db.query<SymbolRecord & { file_path: string }, []>(query).all();
|
|
163
164
|
}
|
|
@@ -260,68 +261,6 @@ export class SymbolRepository {
|
|
|
260
261
|
return this.db.query<any, [string]>(query).get(filePath) ?? null;
|
|
261
262
|
}
|
|
262
263
|
|
|
263
|
-
public getHotspotSymbols(options: {
|
|
264
|
-
minLines?: number;
|
|
265
|
-
minNesting?: number;
|
|
266
|
-
kind?: SymbolKind;
|
|
267
|
-
domain?: string;
|
|
268
|
-
limit?: number;
|
|
269
|
-
sortBy?: "lines" | "nesting" | "risk_score";
|
|
270
|
-
} = {}): Array<SymbolRecord & { file_path: string; domain_name: string; risk_score: number }> {
|
|
271
|
-
const minLines = options.minLines ?? 0;
|
|
272
|
-
const minNesting = options.minNesting ?? 1;
|
|
273
|
-
const limit = options.limit ?? 50;
|
|
274
|
-
const sortBy = options.sortBy ?? "risk_score";
|
|
275
|
-
|
|
276
|
-
let sql = `
|
|
277
|
-
SELECT
|
|
278
|
-
s.id,
|
|
279
|
-
s.file_id,
|
|
280
|
-
s.name,
|
|
281
|
-
s.kind,
|
|
282
|
-
s.signature,
|
|
283
|
-
s.visibility,
|
|
284
|
-
s.line_start,
|
|
285
|
-
s.line_end,
|
|
286
|
-
s.line_count,
|
|
287
|
-
s.nesting_depth,
|
|
288
|
-
f.path AS file_path,
|
|
289
|
-
d.name AS domain_name
|
|
290
|
-
FROM symbols s
|
|
291
|
-
JOIN files f ON s.file_id = f.id
|
|
292
|
-
JOIN domains d ON f.domain_id = d.id
|
|
293
|
-
WHERE s.line_count >= ? AND s.nesting_depth >= ?
|
|
294
|
-
`;
|
|
295
|
-
|
|
296
|
-
const params: any[] = [minLines, minNesting];
|
|
297
|
-
|
|
298
|
-
if (options.kind) {
|
|
299
|
-
sql += " AND s.kind = ?";
|
|
300
|
-
params.push(options.kind);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (options.domain) {
|
|
304
|
-
sql += " AND d.name = ?";
|
|
305
|
-
params.push(options.domain);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (sortBy === "nesting") {
|
|
309
|
-
sql += " ORDER BY s.nesting_depth DESC, s.line_count DESC, s.name ASC LIMIT ?";
|
|
310
|
-
} else if (sortBy === "lines") {
|
|
311
|
-
sql += " ORDER BY s.line_count DESC, s.nesting_depth DESC, s.name ASC LIMIT ?";
|
|
312
|
-
} else {
|
|
313
|
-
sql += " ORDER BY (s.line_count * (1.0 + s.nesting_depth * 0.3)) DESC, s.nesting_depth DESC, s.name ASC LIMIT ?";
|
|
314
|
-
}
|
|
315
|
-
params.push(limit);
|
|
316
|
-
|
|
317
|
-
const rows = this.db.query<any, any[]>(sql).all(...params);
|
|
318
|
-
return rows.map((r) => ({
|
|
319
|
-
...r,
|
|
320
|
-
nesting_depth: r.nesting_depth ?? 1,
|
|
321
|
-
risk_score: Math.round((r.line_count ?? 1) * (1.0 + (r.nesting_depth ?? 1) * 0.3)),
|
|
322
|
-
}));
|
|
323
|
-
}
|
|
324
|
-
|
|
325
264
|
public getSymbolDetails(
|
|
326
265
|
symbolQuery: string,
|
|
327
266
|
options: SymbolSelectionOptions & { includeDependencies?: boolean; workspaceRoot?: string } = {}
|
|
@@ -356,20 +295,130 @@ export class SymbolRepository {
|
|
|
356
295
|
const shouldIncludeDeps = options.includeDependencies !== false;
|
|
357
296
|
|
|
358
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
|
+
|
|
359
352
|
const extractTypeHints = (sig: string) => {
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
])
|
|
367
|
-
|
|
368
|
-
|
|
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()));
|
|
369
413
|
if (parts.length >= 2) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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);
|
|
373
422
|
}
|
|
374
423
|
}
|
|
375
424
|
}
|
|
@@ -379,13 +428,20 @@ export class SymbolRepository {
|
|
|
379
428
|
// Rust parameter types do not establish a dependency injection binding.
|
|
380
429
|
if (!isRust) extractTypeHints(row.signature);
|
|
381
430
|
|
|
382
|
-
// Also check constructor injection if this is a method
|
|
383
|
-
|
|
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) {
|
|
384
434
|
const ctor = this.db
|
|
385
|
-
.query<{ signature: string }, [number, string, string]>(
|
|
386
|
-
"SELECT signature FROM symbols WHERE file_id = ? AND (name = ? OR name LIKE ?) LIMIT 1"
|
|
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"
|
|
387
437
|
)
|
|
388
|
-
.get(
|
|
438
|
+
.get(
|
|
439
|
+
row.file_id,
|
|
440
|
+
`${classOwner}::__construct`,
|
|
441
|
+
`${classOwner}::constructor`,
|
|
442
|
+
`${classOwner}::__init__`,
|
|
443
|
+
`%::__construct`
|
|
444
|
+
);
|
|
389
445
|
if (ctor) {
|
|
390
446
|
extractTypeHints(ctor.signature);
|
|
391
447
|
}
|
|
@@ -396,14 +452,24 @@ export class SymbolRepository {
|
|
|
396
452
|
const fullPath = options.workspaceRoot
|
|
397
453
|
? path.resolve(options.workspaceRoot, row.file_path)
|
|
398
454
|
: row.file_path;
|
|
399
|
-
|
|
400
|
-
|
|
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);
|
|
401
459
|
const lines = fileContent.split(/\r?\n/);
|
|
402
460
|
const start = Math.max(0, row.line_start - 1);
|
|
403
461
|
const end = Math.min(lines.length, row.line_end);
|
|
404
462
|
const rawSlice = lines.slice(start, end).join("\n");
|
|
405
463
|
const sanitizedSlice = stripCommentsAndStrings(rawSlice);
|
|
406
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
|
+
|
|
407
473
|
// Match Static invocations: ClassName::methodName(
|
|
408
474
|
const staticCalls = sanitizedSlice.matchAll(/([A-Z][a-zA-Z0-9_]+)::([a-zA-Z0-9_]+)\s*\(/g);
|
|
409
475
|
for (const m of staticCalls) {
|
|
@@ -417,7 +483,8 @@ export class SymbolRepository {
|
|
|
417
483
|
for (const m of propCalls) {
|
|
418
484
|
const propName = m[1];
|
|
419
485
|
const methodName = m[2];
|
|
420
|
-
const
|
|
486
|
+
const mappedType = varTypes.get(propName);
|
|
487
|
+
const inferredClass = mappedType || (propName.charAt(0).toUpperCase() + propName.slice(1));
|
|
421
488
|
outboundCalls.add(`${inferredClass}::${methodName}`);
|
|
422
489
|
}
|
|
423
490
|
|
|
@@ -427,10 +494,82 @@ export class SymbolRepository {
|
|
|
427
494
|
const propName = m[1];
|
|
428
495
|
const methodName = m[2];
|
|
429
496
|
if (propName !== "db") {
|
|
430
|
-
const
|
|
497
|
+
const mappedType = varTypes.get(propName);
|
|
498
|
+
const inferredClass = mappedType || (propName.charAt(0).toUpperCase() + propName.slice(1));
|
|
431
499
|
outboundCalls.add(`${inferredClass}::${methodName}`);
|
|
432
500
|
}
|
|
433
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
|
+
}
|
|
434
573
|
}
|
|
435
574
|
} catch {
|
|
436
575
|
// Graceful fallback if file not physically accessible
|
|
@@ -501,7 +640,7 @@ export class SymbolRepository {
|
|
|
501
640
|
complexity_smell: complexitySmell,
|
|
502
641
|
sibling_methods: siblingMethods.length > 0 ? siblingMethods : undefined,
|
|
503
642
|
connected_files: connectedFiles,
|
|
504
|
-
...(
|
|
643
|
+
...(options.includeDependencies === true ? { relationships: new DependencyRepository(this.db).getImportRelationships(options.workspaceRoot).filter(edge => edge.source.file === row.file_path) } : {}),
|
|
505
644
|
};
|
|
506
645
|
}
|
|
507
646
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import type {
|
|
3
4
|
ArchetypeKind,
|
|
4
5
|
DomainCatalogResponse,
|
|
5
6
|
DomainConfig,
|
|
6
7
|
DomainRecord,
|
|
8
|
+
NavigationFile,
|
|
9
|
+
NavigationEntrypoint,
|
|
7
10
|
ExtractedDependency,
|
|
8
11
|
ExtractedSymbol,
|
|
9
12
|
FileRecord,
|
|
@@ -35,7 +38,6 @@ export type {
|
|
|
35
38
|
} from "../../types/index.ts";
|
|
36
39
|
import { DependencyRepository } from "./repositories/dependency.repository.ts";
|
|
37
40
|
import { DomainRepository } from "./repositories/domain.repository.ts";
|
|
38
|
-
import { EnvironmentRepository } from "./repositories/environment.repository.ts";
|
|
39
41
|
import { FileRepository } from "./repositories/file.repository.ts";
|
|
40
42
|
import { MetaRepository } from "./repositories/meta.repository.ts";
|
|
41
43
|
import { SymbolRepository } from "./repositories/symbol.repository.ts";
|
|
@@ -43,12 +45,12 @@ import { SymbolRepository } from "./repositories/symbol.repository.ts";
|
|
|
43
45
|
export type DatabaseRepository = SeptumRepository;
|
|
44
46
|
|
|
45
47
|
export class SeptumRepository {
|
|
48
|
+
private indexIdentityCache?: { stamp: string; digest: string };
|
|
46
49
|
public readonly domains: DomainRepository;
|
|
47
50
|
public readonly files: FileRepository;
|
|
48
51
|
public readonly symbols: SymbolRepository;
|
|
49
52
|
public readonly dependencies: DependencyRepository;
|
|
50
53
|
public readonly meta: MetaRepository;
|
|
51
|
-
public readonly environment: EnvironmentRepository;
|
|
52
54
|
|
|
53
55
|
constructor(private db: Database) {
|
|
54
56
|
this.domains = new DomainRepository(db);
|
|
@@ -56,7 +58,6 @@ export class SeptumRepository {
|
|
|
56
58
|
this.symbols = new SymbolRepository(db);
|
|
57
59
|
this.dependencies = new DependencyRepository(db);
|
|
58
60
|
this.meta = new MetaRepository(db);
|
|
59
|
-
this.environment = new EnvironmentRepository(db);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
public runInTransaction<T>(fn: () => T, immediate = false): T {
|
|
@@ -72,9 +73,63 @@ export class SeptumRepository {
|
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
public getNavigationFiles(): NavigationFile[] {
|
|
77
|
+
return this.db.query<NavigationFile, []>(`
|
|
78
|
+
SELECT f.path, d.name AS domain, f.archetype, COUNT(s.id) AS symbol_count,
|
|
79
|
+
(SELECT name FROM symbols WHERE file_id = f.id AND kind IN ('function','class','struct','interface') ORDER BY line_start, name LIMIT 1) AS anchor
|
|
80
|
+
FROM files f JOIN domains d ON d.id = f.domain_id
|
|
81
|
+
LEFT JOIN symbols s ON s.file_id = f.id
|
|
82
|
+
GROUP BY f.id ORDER BY f.path
|
|
83
|
+
`).all();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public getNavigationEntrypoints(): NavigationEntrypoint[] {
|
|
87
|
+
return this.db.query<NavigationEntrypoint, []>(`
|
|
88
|
+
SELECT DISTINCT http_method AS method, route_uri AS target,
|
|
89
|
+
controller_file AS file, action_name AS handler
|
|
90
|
+
FROM vertical_slices ORDER BY controller_file, http_method, route_uri, action_name
|
|
91
|
+
`).all();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Stable content identity without materializing/sorting the index in JS.
|
|
95
|
+
* SQLite counters invalidate the cache for local writes and other connections;
|
|
96
|
+
* the digest excludes insertion IDs and operational timestamps.
|
|
97
|
+
*/
|
|
98
|
+
public getIndexIdentity(): string {
|
|
99
|
+
// total_changes does not rewind on rollback. Never publish a digest of
|
|
100
|
+
// uncommitted facts into the connection cache.
|
|
101
|
+
const cacheable = !this.db.inTransaction;
|
|
102
|
+
return this.runInTransaction(() => {
|
|
103
|
+
const stamp = JSON.stringify([
|
|
104
|
+
this.db.query("PRAGMA data_version").get(),
|
|
105
|
+
this.db.query("SELECT total_changes() AS changes").get(),
|
|
106
|
+
this.db.query("PRAGMA schema_version").get(),
|
|
107
|
+
]);
|
|
108
|
+
if (cacheable && this.indexIdentityCache?.stamp === stamp) return this.indexIdentityCache.digest;
|
|
109
|
+
const hash = createHash("sha256");
|
|
110
|
+
for (const sql of [
|
|
111
|
+
`SELECT json_array(name, root_path, allowed_deps_json, forbidden_deps_json, archetypes_json) AS fact
|
|
112
|
+
FROM domains ORDER BY fact`,
|
|
113
|
+
`SELECT json_array(f.path, f.content_hash, d.name) AS fact
|
|
114
|
+
FROM files f JOIN domains d ON d.id = f.domain_id ORDER BY fact`,
|
|
115
|
+
`SELECT json_array(f.path, s.name, s.kind, s.signature, s.visibility, s.line_start, s.line_end, s.line_count, s.nesting_depth) AS fact
|
|
116
|
+
FROM symbols s JOIN files f ON f.id = s.file_id ORDER BY fact`,
|
|
117
|
+
`SELECT json_array(f.path, d.name, dep.target_symbol_or_path, dep.import_statement, dep.line_number, dep.is_external) AS fact
|
|
118
|
+
FROM dependencies dep JOIN files f ON f.id = dep.source_file_id JOIN domains d ON d.id = f.domain_id ORDER BY fact`,
|
|
119
|
+
`SELECT json_array(key, value) AS fact FROM repo_meta WHERE key IN ('sync_state', 'parser_revision') ORDER BY key`,
|
|
120
|
+
]) {
|
|
121
|
+
hash.update("\0");
|
|
122
|
+
for (const { fact } of this.db.query<{ fact: string }, []>(sql).iterate()) hash.update(fact + "\n");
|
|
123
|
+
}
|
|
124
|
+
const digest = hash.digest("hex");
|
|
125
|
+
if (cacheable) this.indexIdentityCache = { stamp, digest };
|
|
126
|
+
return digest;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
75
130
|
// --- Domain Methods ---
|
|
76
|
-
public upsertDomain(name: string, config: DomainConfig): number {
|
|
77
|
-
return this.domains.upsertDomain(name, config);
|
|
131
|
+
public upsertDomain(name: string, config: DomainConfig, workspaceRoot?: string): number {
|
|
132
|
+
return this.domains.upsertDomain(name, config, workspaceRoot);
|
|
78
133
|
}
|
|
79
134
|
|
|
80
135
|
public getDomainByName(name: string): DomainRecord | null {
|
|
@@ -85,6 +140,10 @@ export class SeptumRepository {
|
|
|
85
140
|
return this.domains.getAllDomains();
|
|
86
141
|
}
|
|
87
142
|
|
|
143
|
+
public pruneDomainsNotIn(activeNames: string[]): { prunedDomains: number; removedFiles: number } {
|
|
144
|
+
return this.domains.pruneDomainsNotIn(activeNames);
|
|
145
|
+
}
|
|
146
|
+
|
|
88
147
|
// --- File Methods ---
|
|
89
148
|
public getFileByPath(path: string): FileRecord | null {
|
|
90
149
|
return this.files.getFileByPath(path);
|
|
@@ -147,6 +206,13 @@ export class SeptumRepository {
|
|
|
147
206
|
}
|
|
148
207
|
|
|
149
208
|
// --- Symbol Methods ---
|
|
209
|
+
public getDependenciesByFileId(fileId: number): ExtractedDependency[] {
|
|
210
|
+
return this.db.query<ExtractedDependency, [number]>(`
|
|
211
|
+
SELECT target_symbol_or_path AS target, import_statement AS statement,
|
|
212
|
+
line_number, is_external FROM dependencies WHERE source_file_id = ? ORDER BY id
|
|
213
|
+
`).all(fileId);
|
|
214
|
+
}
|
|
215
|
+
|
|
150
216
|
public replaceFileSymbols(fileId: number, symbols: ExtractedSymbol[]): void {
|
|
151
217
|
this.symbols.replaceFileSymbols(fileId, symbols);
|
|
152
218
|
}
|
|
@@ -199,8 +265,8 @@ export class SeptumRepository {
|
|
|
199
265
|
this.dependencies.clearVerticalSlices(domainId);
|
|
200
266
|
}
|
|
201
267
|
|
|
202
|
-
public getImportRelationships(workspaceRoot?: string) {
|
|
203
|
-
return this.dependencies.getImportRelationships(workspaceRoot);
|
|
268
|
+
public getImportRelationships(workspaceRoot?: string, sourceFile?: string) {
|
|
269
|
+
return this.dependencies.getImportRelationships(workspaceRoot, sourceFile);
|
|
204
270
|
}
|
|
205
271
|
|
|
206
272
|
public getDomainFileConnections(domainId?: number, workspaceRoot?: string) {
|
|
@@ -253,17 +319,6 @@ export class SeptumRepository {
|
|
|
253
319
|
return this.symbols.getFileWithDomain(filePath);
|
|
254
320
|
}
|
|
255
321
|
|
|
256
|
-
public getHotspotSymbols(options: {
|
|
257
|
-
minLines?: number;
|
|
258
|
-
minNesting?: number;
|
|
259
|
-
kind?: SymbolKind;
|
|
260
|
-
domain?: string;
|
|
261
|
-
limit?: number;
|
|
262
|
-
sortBy?: "lines" | "nesting" | "risk_score";
|
|
263
|
-
} = {}): Array<SymbolRecord & { file_path: string; domain_name: string; risk_score: number }> {
|
|
264
|
-
return this.symbols.getHotspotSymbols(options);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
322
|
public getSymbolDetails(
|
|
268
323
|
symbolQuery: string,
|
|
269
324
|
options: SymbolSelectionOptions & { includeDependencies?: boolean; workspaceRoot?: string } = {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Database } from "bun:sqlite";
|
|
2
2
|
|
|
3
|
-
export const CURRENT_SCHEMA_VERSION =
|
|
3
|
+
export const CURRENT_SCHEMA_VERSION = 5;
|
|
4
4
|
|
|
5
5
|
export const TABLE_STATEMENTS = [
|
|
6
6
|
`CREATE TABLE IF NOT EXISTS domains (
|
|
@@ -74,32 +74,6 @@ export const TABLE_STATEMENTS = [
|
|
|
74
74
|
value TEXT NOT NULL,
|
|
75
75
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
76
76
|
);`,
|
|
77
|
-
|
|
78
|
-
`CREATE TABLE IF NOT EXISTS environment_topology (
|
|
79
|
-
layer TEXT PRIMARY KEY,
|
|
80
|
-
platform TEXT,
|
|
81
|
-
status TEXT NOT NULL,
|
|
82
|
-
detected_from_json TEXT NOT NULL DEFAULT '[]',
|
|
83
|
-
constraints_json TEXT NOT NULL DEFAULT '[]',
|
|
84
|
-
unresolved_inquiry TEXT,
|
|
85
|
-
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
86
|
-
);`,
|
|
87
|
-
|
|
88
|
-
`CREATE TABLE IF NOT EXISTS environment_nodes (
|
|
89
|
-
id TEXT PRIMARY KEY,
|
|
90
|
-
layer TEXT NOT NULL,
|
|
91
|
-
name TEXT NOT NULL,
|
|
92
|
-
platform TEXT NOT NULL,
|
|
93
|
-
canonical_tag TEXT NOT NULL DEFAULT 'unspecified',
|
|
94
|
-
domain_or_ip TEXT,
|
|
95
|
-
role TEXT,
|
|
96
|
-
status TEXT NOT NULL,
|
|
97
|
-
detected_from_json TEXT NOT NULL DEFAULT '[]',
|
|
98
|
-
constraints_json TEXT NOT NULL DEFAULT '[]',
|
|
99
|
-
connected_to_json TEXT NOT NULL DEFAULT '[]',
|
|
100
|
-
unresolved_inquiry TEXT,
|
|
101
|
-
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
102
|
-
);`,
|
|
103
77
|
];
|
|
104
78
|
|
|
105
79
|
export const INDEX_STATEMENTS = [
|
|
@@ -110,16 +84,11 @@ export const INDEX_STATEMENTS = [
|
|
|
110
84
|
"CREATE INDEX IF NOT EXISTS idx_symbols_file_lines ON symbols(file_id, line_start, line_end);",
|
|
111
85
|
"CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);",
|
|
112
86
|
"CREATE INDEX IF NOT EXISTS idx_symbols_kind ON symbols(kind);",
|
|
113
|
-
"CREATE INDEX IF NOT EXISTS idx_symbols_line_count ON symbols(kind, line_count DESC);",
|
|
114
|
-
"CREATE INDEX IF NOT EXISTS idx_symbols_nesting_depth ON symbols(nesting_depth DESC);",
|
|
115
87
|
"CREATE INDEX IF NOT EXISTS idx_dependencies_source ON dependencies(source_file_id);",
|
|
116
88
|
"CREATE INDEX IF NOT EXISTS idx_dependencies_target ON dependencies(target_symbol_or_path);",
|
|
117
89
|
"CREATE INDEX IF NOT EXISTS idx_slices_route_uri ON vertical_slices(route_uri);",
|
|
118
90
|
"CREATE INDEX IF NOT EXISTS idx_slices_route_name ON vertical_slices(route_name);",
|
|
119
91
|
"CREATE INDEX IF NOT EXISTS idx_slices_controller ON vertical_slices(controller_class, action_name);",
|
|
120
|
-
"CREATE INDEX IF NOT EXISTS idx_env_topology_status ON environment_topology(status);",
|
|
121
|
-
"CREATE INDEX IF NOT EXISTS idx_env_nodes_layer ON environment_nodes(layer, id);",
|
|
122
|
-
"CREATE INDEX IF NOT EXISTS idx_env_nodes_status ON environment_nodes(status);",
|
|
123
92
|
];
|
|
124
93
|
|
|
125
94
|
const DROP_ALL_TABLES = `
|
|
@@ -138,7 +107,7 @@ export function initializeDatabaseSchema(db: Database): void {
|
|
|
138
107
|
const userVersion = versionRow?.user_version ?? 0;
|
|
139
108
|
|
|
140
109
|
if (userVersion !== 0 && userVersion !== CURRENT_SCHEMA_VERSION) {
|
|
141
|
-
//
|
|
110
|
+
// Outdated schema versions are cleanly dropped and recreated
|
|
142
111
|
db.run(DROP_ALL_TABLES);
|
|
143
112
|
}
|
|
144
113
|
|