@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,17 +1,16 @@
|
|
|
1
|
+
import { analyzeSymbolImpact } from "../../resolver/symbol-impact.ts";
|
|
1
2
|
import { assertPathContained } from "../../resolver/path-resolver.ts";
|
|
2
3
|
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
3
4
|
import { readSourceFile } from "../../resources/source-files.ts";
|
|
4
5
|
import { computeContentHash } from "../../ingestion/hasher.ts";
|
|
5
6
|
import { getLanguageCapability } from "../../parser/language-capabilities.ts";
|
|
6
7
|
import type { ImportRelationship } from "../../../types/index.ts";
|
|
7
|
-
import
|
|
8
|
-
import { dirname, join, posix, resolve, sep } from "node:path";
|
|
8
|
+
import { posix, resolve, sep } from "node:path";
|
|
9
9
|
import type { Database } from "bun:sqlite";
|
|
10
10
|
import type {
|
|
11
11
|
ExtractedDependency,
|
|
12
12
|
FileConnectionsSummary,
|
|
13
13
|
GetSymbolImpactResponse,
|
|
14
|
-
InboundCaller,
|
|
15
14
|
SymbolReference,
|
|
16
15
|
VerticalSliceRecord,
|
|
17
16
|
} from "../../../types/index.ts";
|
|
@@ -41,10 +40,12 @@ export class DependencyRepository {
|
|
|
41
40
|
slice: Omit<VerticalSliceRecord, "id" | "created_at">
|
|
42
41
|
): void {
|
|
43
42
|
const existing = this.db
|
|
44
|
-
.query<VerticalSliceRecord, [string, string]>(
|
|
45
|
-
|
|
43
|
+
.query<VerticalSliceRecord, [string, string, number | null, string | null, string, string, string]>(
|
|
44
|
+
`SELECT id FROM vertical_slices WHERE http_method = ? AND route_uri = ?
|
|
45
|
+
AND domain_id IS ? AND controller_file IS ? AND controller_class = ? AND action_name = ? AND entry_kind = ?`
|
|
46
46
|
)
|
|
47
|
-
.get(slice.http_method, slice.route_uri
|
|
47
|
+
.get(slice.http_method, slice.route_uri, slice.domain_id, slice.controller_file,
|
|
48
|
+
slice.controller_class, slice.action_name, slice.entry_kind ?? "http_route");
|
|
48
49
|
|
|
49
50
|
if (existing) {
|
|
50
51
|
this.db
|
|
@@ -131,7 +132,7 @@ export class DependencyRepository {
|
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
public getAllDependenciesWithDomains(): Array<{
|
|
135
|
+
public getAllDependenciesWithDomains(sourceFile?: string): Array<{
|
|
135
136
|
source_file: string;
|
|
136
137
|
source_domain: string;
|
|
137
138
|
line_number: number;
|
|
@@ -150,25 +151,28 @@ export class DependencyRepository {
|
|
|
150
151
|
FROM dependencies dep
|
|
151
152
|
JOIN files f ON dep.source_file_id = f.id
|
|
152
153
|
JOIN domains d ON f.domain_id = d.id
|
|
154
|
+
${sourceFile === undefined ? "" : "WHERE f.path = ?"}
|
|
153
155
|
ORDER BY d.name, f.path, dep.line_number
|
|
154
156
|
`;
|
|
155
|
-
return this.db.query<any, []>(query).all();
|
|
157
|
+
return this.db.query<any, string[]>(query).all(...(sourceFile === undefined ? [] : [sourceFile]));
|
|
156
158
|
}
|
|
157
159
|
|
|
158
|
-
public getImportRelationships(workspaceRoot?: string): ImportRelationship[] {
|
|
160
|
+
public getImportRelationships(workspaceRoot?: string, sourceFile?: string): ImportRelationship[] {
|
|
159
161
|
const root = workspaceRoot ?? this.db.query<{ value: string }, [string]>("SELECT value FROM repo_meta WHERE key = ?").get("workspace_root")?.value;
|
|
160
162
|
if (!root) return [];
|
|
161
|
-
const files = this.db.query<{ path: string; content_hash: string; domain_id: number }, []>(
|
|
163
|
+
const files = this.db.query<{ path: string; content_hash: string; domain_id: number }, string[]>(
|
|
164
|
+
`SELECT path, content_hash, domain_id FROM files ${sourceFile === undefined ? "" : "WHERE path = ?"}`
|
|
165
|
+
).all(...(sourceFile === undefined ? [] : [sourceFile]));
|
|
162
166
|
const domains = this.db.query<{ name: string; root_path: string }, []>("SELECT name, root_path FROM domains").all().sort((a,b)=>b.root_path.length-a.root_path.length);
|
|
163
167
|
const resolver = new ImportResolver(root, domains.map(domain => domain.root_path));
|
|
164
168
|
const freshness = new Map<string, ImportRelationship["freshness"]>();
|
|
165
169
|
const hashes = new Map(files.map(f => [f.path, f.content_hash]));
|
|
166
|
-
return this.getAllDependenciesWithDomains().map(dep => {
|
|
170
|
+
return this.getAllDependenciesWithDomains(sourceFile).map(dep => {
|
|
167
171
|
if (!freshness.has(dep.source_file)) {
|
|
168
172
|
try { assertPathContained(dep.source_file, root, "Import source"); freshness.set(dep.source_file, computeContentHash(readSourceFile(resolve(root,dep.source_file))) === hashes.get(dep.source_file) ? "current" : "stale"); }
|
|
169
173
|
catch { freshness.set(dep.source_file,"unavailable"); }
|
|
170
174
|
}
|
|
171
|
-
const resolution = resolver.resolve(dep.target,dep.source_file);
|
|
175
|
+
const resolution = resolver.resolve(dep.target,dep.source_file,dep.statement);
|
|
172
176
|
const current = freshness.get(dep.source_file)!;
|
|
173
177
|
if (current !== "current") { resolution.status = "unresolved"; resolution.reason = `source_${current}`; resolution.targets = []; }
|
|
174
178
|
const targetDomains = resolution.targets.flatMap(target => target.files.map(file => domains.find(domain => {
|
|
@@ -179,7 +183,8 @@ export class DependencyRepository {
|
|
|
179
183
|
kind: "imports", derivation: "source",
|
|
180
184
|
source: { file: dep.source_file, line: dep.line_number, statement: dep.statement, indexed_content_hash: hashes.get(dep.source_file) ?? "" },
|
|
181
185
|
resolution, target_domains: [...new Set(targetDomains)], freshness: current,
|
|
182
|
-
index_coverage: resolution.targets.every(target => target.files.every(file => hashes.has(file) ||
|
|
186
|
+
index_coverage: resolution.targets.every(target => target.files.every(file => hashes.has(file) ||
|
|
187
|
+
(sourceFile !== undefined && !!this.db.query("SELECT 1 FROM files WHERE path = ?").get(file)) || !getLanguageCapability(file))) ? "complete" : "partial",
|
|
183
188
|
...(dep.source_file.endsWith(".go") ? { import_binding: (() => {
|
|
184
189
|
const alias = dep.statement.replace(/^\s*import\s+/, "").match(/^\s*([A-Za-z_]\w*|\.)\s+["`]/)?.[1];
|
|
185
190
|
return { kind: alias === "_" ? "blank" : alias === "." ? "dot" : alias ? "named" : "default", alias };
|
|
@@ -336,23 +341,44 @@ export class DependencyRepository {
|
|
|
336
341
|
}
|
|
337
342
|
|
|
338
343
|
// 1. Look up target symbol in symbols joined with files and optionally domains
|
|
339
|
-
let targetSymRows: Array<{
|
|
344
|
+
let targetSymRows: Array<{
|
|
345
|
+
name: string;
|
|
346
|
+
kind: string;
|
|
347
|
+
line_start: number;
|
|
348
|
+
line_end: number;
|
|
349
|
+
file_path: string;
|
|
350
|
+
domain_name?: string | null;
|
|
351
|
+
}>;
|
|
340
352
|
if (targetMethod) {
|
|
341
353
|
let methodSql = `
|
|
342
|
-
SELECT s.name, s.signature, f.path AS file_path
|
|
354
|
+
SELECT s.name, s.kind, s.signature, s.line_start, s.line_end, f.path AS file_path, dom.name AS domain_name
|
|
343
355
|
FROM symbols s
|
|
344
356
|
JOIN files f ON s.file_id = f.id
|
|
357
|
+
LEFT JOIN domains dom ON f.domain_id = dom.id
|
|
345
358
|
`;
|
|
346
359
|
const methodParams: any[] = [];
|
|
347
360
|
if (options.domain) {
|
|
348
|
-
methodSql += `
|
|
361
|
+
methodSql += ` WHERE LOWER(dom.name) = LOWER(?) AND `;
|
|
349
362
|
methodParams.push(options.domain);
|
|
350
363
|
} else {
|
|
351
364
|
methodSql += ` WHERE `;
|
|
352
365
|
}
|
|
353
366
|
methodSql += ` (s.name = ? OR s.name = ? OR (s.name = ? AND s.kind = 'method')) `;
|
|
354
367
|
methodParams.push(trimmed, `${targetContainer}::${targetMethod}`, targetMethod);
|
|
355
|
-
targetSymRows = this.db
|
|
368
|
+
targetSymRows = this.db
|
|
369
|
+
.query<
|
|
370
|
+
{
|
|
371
|
+
name: string;
|
|
372
|
+
kind: string;
|
|
373
|
+
signature: string;
|
|
374
|
+
line_start: number;
|
|
375
|
+
line_end: number;
|
|
376
|
+
file_path: string;
|
|
377
|
+
domain_name?: string | null;
|
|
378
|
+
},
|
|
379
|
+
any[]
|
|
380
|
+
>(methodSql)
|
|
381
|
+
.all(...methodParams)
|
|
356
382
|
.filter(row => {
|
|
357
383
|
if (row.name !== targetMethod) return true;
|
|
358
384
|
// Go indexes bare method names; the receiver in its signature proves identity.
|
|
@@ -375,20 +401,33 @@ export class DependencyRepository {
|
|
|
375
401
|
}
|
|
376
402
|
} else {
|
|
377
403
|
let containerSql = `
|
|
378
|
-
SELECT s.name, f.path AS file_path
|
|
404
|
+
SELECT s.name, s.kind, s.line_start, s.line_end, f.path AS file_path, dom.name AS domain_name
|
|
379
405
|
FROM symbols s
|
|
380
406
|
JOIN files f ON s.file_id = f.id
|
|
407
|
+
LEFT JOIN domains dom ON f.domain_id = dom.id
|
|
381
408
|
`;
|
|
382
409
|
const containerParams: any[] = [];
|
|
383
410
|
if (options.domain) {
|
|
384
|
-
containerSql += `
|
|
411
|
+
containerSql += ` WHERE LOWER(dom.name) = LOWER(?) AND `;
|
|
385
412
|
containerParams.push(options.domain);
|
|
386
413
|
} else {
|
|
387
414
|
containerSql += ` WHERE `;
|
|
388
415
|
}
|
|
389
416
|
containerSql += ` (s.name = ? OR s.name = ? OR s.name LIKE ? OR s.name LIKE ?) `;
|
|
390
417
|
containerParams.push(trimmed, targetContainer, `${targetContainer}::%`, `%::${targetContainer}`);
|
|
391
|
-
targetSymRows = this.db
|
|
418
|
+
targetSymRows = this.db
|
|
419
|
+
.query<
|
|
420
|
+
{
|
|
421
|
+
name: string;
|
|
422
|
+
kind: string;
|
|
423
|
+
line_start: number;
|
|
424
|
+
line_end: number;
|
|
425
|
+
file_path: string;
|
|
426
|
+
domain_name?: string | null;
|
|
427
|
+
},
|
|
428
|
+
any[]
|
|
429
|
+
>(containerSql)
|
|
430
|
+
.all(...containerParams);
|
|
392
431
|
|
|
393
432
|
if (targetSymRows.length === 0) {
|
|
394
433
|
return {
|
|
@@ -426,6 +465,9 @@ export class DependencyRepository {
|
|
|
426
465
|
const definingFiles = new Set<string>(
|
|
427
466
|
targetSymRows.map((r) => r.file_path.replace(/\\/g, "/"))
|
|
428
467
|
);
|
|
468
|
+
const domainByFile = new Map<string, string>();
|
|
469
|
+
for (const row of targetSymRows) if (row.domain_name) domainByFile.set(row.file_path.replace(/\\/g, "/"), row.domain_name);
|
|
470
|
+
|
|
429
471
|
const definingFileStems = Array.from(
|
|
430
472
|
new Set(
|
|
431
473
|
Array.from(definingFiles)
|
|
@@ -486,6 +528,7 @@ export class DependencyRepository {
|
|
|
486
528
|
const containerWordRegex = new RegExp(`\\b${escapeRegExp(targetContainer)}\\b`);
|
|
487
529
|
const depRows = rawDepRows.filter((row) => {
|
|
488
530
|
const normCallerFile = String(row.file).replace(/\\/g, "/");
|
|
531
|
+
if (row.domain_name) domainByFile.set(normCallerFile, String(row.domain_name));
|
|
489
532
|
if (definingFiles.has(normCallerFile)) return false;
|
|
490
533
|
|
|
491
534
|
const stmt = String(row.import_statement || "");
|
|
@@ -514,27 +557,67 @@ export class DependencyRepository {
|
|
|
514
557
|
return false;
|
|
515
558
|
});
|
|
516
559
|
|
|
560
|
+
// 2b. Discover same-directory / same-package files for languages with implicit package/namespace resolution (.go, .php, .java, .cs)
|
|
561
|
+
const implicitPackageFiles = new Set<string>();
|
|
562
|
+
const implicitLangDirs = new Set<string>();
|
|
563
|
+
for (const df of definingFiles) {
|
|
564
|
+
if (/\.(go|php|java|cs)$/i.test(df)) {
|
|
565
|
+
const dir = posix.dirname(df);
|
|
566
|
+
implicitLangDirs.add(dir === "." ? "" : dir);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (implicitLangDirs.size > 0) {
|
|
570
|
+
const dirClauses: string[] = [];
|
|
571
|
+
const dirParams: string[] = [];
|
|
572
|
+
for (const dir of implicitLangDirs) {
|
|
573
|
+
if (dir === "") {
|
|
574
|
+
dirClauses.push("f.path NOT LIKE '%/%'");
|
|
575
|
+
} else {
|
|
576
|
+
dirClauses.push("(f.path LIKE ? AND SUBSTR(f.path, LENGTH(?) + 2) NOT LIKE '%/%')");
|
|
577
|
+
dirParams.push(`${dir}/%`, dir);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
const pkgRows = this.db
|
|
581
|
+
.query<{ path: string; domain_name: string | null }, string[]>(
|
|
582
|
+
`SELECT f.path, dom.name AS domain_name
|
|
583
|
+
FROM files f
|
|
584
|
+
LEFT JOIN domains dom ON f.domain_id = dom.id
|
|
585
|
+
WHERE ${dirClauses.join(" OR ")}`
|
|
586
|
+
)
|
|
587
|
+
.all(...dirParams);
|
|
588
|
+
for (const r of pkgRows) {
|
|
589
|
+
const norm = r.path.replace(/\\/g, "/");
|
|
590
|
+
if (r.domain_name) domainByFile.set(norm, r.domain_name);
|
|
591
|
+
if (!definingFiles.has(norm) && /\.(go|php|java|cs)$/i.test(norm)) {
|
|
592
|
+
implicitPackageFiles.add(norm);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
517
597
|
// 3. Batch-load all symbols for candidate caller files in ONE query (zero N+1)
|
|
518
598
|
const uniqueCallerFiles = Array.from(new Set(depRows.map((r) => String(r.file))));
|
|
599
|
+
const allSymbolLookupFiles = Array.from(
|
|
600
|
+
new Set([...uniqueCallerFiles, ...definingFiles, ...implicitPackageFiles])
|
|
601
|
+
);
|
|
519
602
|
const callerSymbolsByFile = new Map<
|
|
520
603
|
string,
|
|
521
|
-
Array<{ name: string; kind: string; line_start: number; line_end: number }>
|
|
604
|
+
Array<{ name: string; kind: string; signature: string; line_start: number; line_end: number }>
|
|
522
605
|
>();
|
|
523
606
|
|
|
524
|
-
if (
|
|
525
|
-
const placeholders =
|
|
607
|
+
if (allSymbolLookupFiles.length > 0) {
|
|
608
|
+
const placeholders = allSymbolLookupFiles.map(() => "?").join(",");
|
|
526
609
|
const allCallerSyms = this.db
|
|
527
610
|
.query<
|
|
528
|
-
{ name: string; kind: string; line_start: number; line_end: number; path: string },
|
|
611
|
+
{ name: string; kind: string; signature: string; line_start: number; line_end: number; path: string },
|
|
529
612
|
string[]
|
|
530
613
|
>(
|
|
531
|
-
`SELECT s.name, s.kind, s.line_start, s.line_end, f.path
|
|
614
|
+
`SELECT s.name, s.kind, s.signature, s.line_start, s.line_end, f.path
|
|
532
615
|
FROM symbols s
|
|
533
616
|
JOIN files f ON s.file_id = f.id
|
|
534
617
|
WHERE f.path IN (${placeholders})
|
|
535
618
|
ORDER BY (s.line_end - s.line_start) ASC`
|
|
536
619
|
)
|
|
537
|
-
.all(...
|
|
620
|
+
.all(...allSymbolLookupFiles);
|
|
538
621
|
|
|
539
622
|
for (const sym of allCallerSyms) {
|
|
540
623
|
const list = callerSymbolsByFile.get(sym.path) || [];
|
|
@@ -543,99 +626,11 @@ export class DependencyRepository {
|
|
|
543
626
|
}
|
|
544
627
|
}
|
|
545
628
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
if (!syms) return undefined;
|
|
552
|
-
return syms.find((s) => lineNum >= s.line_start && lineNum <= s.line_end);
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
const callersMap = new Map<string, InboundCaller>();
|
|
556
|
-
|
|
557
|
-
for (const row of depRows) {
|
|
558
|
-
const enclosing = findEnclosingSymbol(row.file, row.line_number);
|
|
559
|
-
const callerName = enclosing ? enclosing.name : `${row.file}:${row.line_number}`;
|
|
560
|
-
const key = `${row.file}:${row.line_number}:${callerName}`;
|
|
561
|
-
|
|
562
|
-
if (!callersMap.has(key)) {
|
|
563
|
-
callersMap.set(key, {
|
|
564
|
-
file: row.file,
|
|
565
|
-
caller: callerName,
|
|
566
|
-
line: row.line_number,
|
|
567
|
-
kind: enclosing?.kind || "import",
|
|
568
|
-
domain: row.domain_name ?? undefined,
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// 4. Scan file content of callers for exact method calls if targetMethod specified
|
|
574
|
-
if (targetMethod) {
|
|
575
|
-
for (const filePath of uniqueCallerFiles) {
|
|
576
|
-
try {
|
|
577
|
-
const fullPath = options.workspaceRoot ? resolve(options.workspaceRoot, filePath) : filePath;
|
|
578
|
-
if (fs.existsSync(fullPath)) {
|
|
579
|
-
const content = fs.readFileSync(fullPath, "utf-8");
|
|
580
|
-
const lines = content.split(/\r?\n/);
|
|
581
|
-
for (let i = 0; i < lines.length; i++) {
|
|
582
|
-
const line = lines[i];
|
|
583
|
-
if (
|
|
584
|
-
line.includes(`->${targetMethod}(`) ||
|
|
585
|
-
line.includes(`::${targetMethod}(`) ||
|
|
586
|
-
line.includes(`.${targetMethod}(`)
|
|
587
|
-
) {
|
|
588
|
-
const lineNum = i + 1;
|
|
589
|
-
const enclosing = findEnclosingSymbol(filePath, lineNum);
|
|
590
|
-
const callerName = enclosing ? enclosing.name : `${filePath}:${lineNum}`;
|
|
591
|
-
const key = `${filePath}:${lineNum}:${callerName}`;
|
|
592
|
-
if (!callersMap.has(key)) {
|
|
593
|
-
callersMap.set(key, {
|
|
594
|
-
file: filePath,
|
|
595
|
-
caller: callerName,
|
|
596
|
-
line: lineNum,
|
|
597
|
-
kind: enclosing?.kind || "call",
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
} catch {
|
|
604
|
-
// Ignore read errors
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
const inboundCallers = Array.from(callersMap.values());
|
|
610
|
-
const affectedFiles = new Set(inboundCallers.map((c) => c.file));
|
|
611
|
-
const distinctDomains = new Set(
|
|
612
|
-
inboundCallers.map((c) => c.domain).filter(Boolean)
|
|
613
|
-
);
|
|
614
|
-
|
|
615
|
-
let riskLevel: "low" | "medium" | "high" = "low";
|
|
616
|
-
if (affectedFiles.size > 5 || distinctDomains.size > 2) {
|
|
617
|
-
riskLevel = "high";
|
|
618
|
-
} else if (affectedFiles.size >= 2 || distinctDomains.size >= 2) {
|
|
619
|
-
riskLevel = "medium";
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
// 5. Determine if symbol exists in index
|
|
623
|
-
const foundInIndex = targetSymRows.length > 0 || depRows.length > 0;
|
|
624
|
-
const warning = foundInIndex
|
|
625
|
-
? undefined
|
|
626
|
-
: `Symbol '${trimmed}' was not found in Septum index (neither in declared symbols nor tracked dependencies). Risk cannot be assessed without index evidence.`;
|
|
627
|
-
|
|
628
|
-
return {
|
|
629
|
-
target_symbol: trimmed,
|
|
630
|
-
found_in_index: foundInIndex,
|
|
631
|
-
warning,
|
|
632
|
-
impact_summary: {
|
|
633
|
-
total_dependents: inboundCallers.length,
|
|
634
|
-
risk_level: foundInIndex ? riskLevel : "unknown",
|
|
635
|
-
affected_files_count: affectedFiles.size,
|
|
636
|
-
},
|
|
637
|
-
inbound_callers: inboundCallers,
|
|
638
|
-
};
|
|
629
|
+
return analyzeSymbolImpact({
|
|
630
|
+
query: trimmed, container: targetContainer, method: targetMethod,
|
|
631
|
+
targets: targetSymRows, dependencies: depRows, samePackageFiles: implicitPackageFiles,
|
|
632
|
+
symbolsByFile: callerSymbolsByFile, domainsByFile: domainByFile, workspaceRoot: options.workspaceRoot,
|
|
633
|
+
});
|
|
639
634
|
}
|
|
640
635
|
|
|
641
636
|
public getFileInboundImpact(filePath: string): {
|
|
@@ -657,40 +652,66 @@ export class DependencyRepository {
|
|
|
657
652
|
.all(cleanPath, `%${cleanPath}`);
|
|
658
653
|
|
|
659
654
|
const matchedFiles = new Set<string>();
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
655
|
+
const relationships = this.getImportRelationships();
|
|
656
|
+
if (relationships.length > 0) {
|
|
657
|
+
for (const edge of relationships) {
|
|
658
|
+
if (edge.freshness !== "current" || edge.resolution.status !== "resolved") continue;
|
|
659
|
+
if (edge.source.file === cleanPath) continue;
|
|
660
|
+
if (edge.resolution.targets.some((t) => t.files.includes(cleanPath))) {
|
|
661
|
+
matchedFiles.add(edge.source.file);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
} else {
|
|
665
|
+
const orConditions: string[] = [];
|
|
666
|
+
const params: string[] = [];
|
|
669
667
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
668
|
+
if (baseName.length >= 3) {
|
|
669
|
+
orConditions.push("d.target_symbol_or_path LIKE ?");
|
|
670
|
+
params.push(`%${cleanPath}%`);
|
|
673
671
|
orConditions.push("d.target_symbol_or_path LIKE ?");
|
|
674
|
-
params.push(`%${
|
|
675
|
-
orConditions.push("d.import_statement LIKE ?");
|
|
676
|
-
params.push(`%${symName}%`);
|
|
672
|
+
params.push(`%${baseName}%`);
|
|
677
673
|
}
|
|
678
|
-
}
|
|
679
674
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
)
|
|
690
|
-
.all(...params);
|
|
675
|
+
for (const sym of symbols.slice(0, 8)) {
|
|
676
|
+
const symName = sym.name.split("::").pop() || sym.name;
|
|
677
|
+
if (symName.length >= 4) {
|
|
678
|
+
orConditions.push("d.target_symbol_or_path LIKE ?");
|
|
679
|
+
params.push(`%${symName}%`);
|
|
680
|
+
orConditions.push("d.import_statement LIKE ?");
|
|
681
|
+
params.push(`%${symName}%`);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
691
684
|
|
|
692
|
-
|
|
693
|
-
|
|
685
|
+
if (orConditions.length > 0) {
|
|
686
|
+
params.push(`%${cleanPath}`);
|
|
687
|
+
const depRows = this.db
|
|
688
|
+
.query<{ file: string; target: string; stmt: string }, string[]>(
|
|
689
|
+
`SELECT DISTINCT f.path AS file, d.target_symbol_or_path AS target, d.import_statement AS stmt
|
|
690
|
+
FROM dependencies d
|
|
691
|
+
JOIN files f ON d.source_file_id = f.id
|
|
692
|
+
WHERE (${orConditions.join(" OR ")})
|
|
693
|
+
AND f.path NOT LIKE ?`
|
|
694
|
+
)
|
|
695
|
+
.all(...params);
|
|
696
|
+
|
|
697
|
+
const baseBoundary = baseName.length >= 3
|
|
698
|
+
? new RegExp(`(?:^|[\\/\\\\.])${escapeRegExp(baseName)}(?:\\.[^.\\/\\\\]+)?$`, "i")
|
|
699
|
+
: null;
|
|
700
|
+
const symNames = symbols
|
|
701
|
+
.slice(0, 8)
|
|
702
|
+
.map((s) => s.name.split("::").pop() || s.name)
|
|
703
|
+
.filter((n) => n.length >= 4)
|
|
704
|
+
.map((n) => new RegExp(`\\b${escapeRegExp(n)}\\b`));
|
|
705
|
+
|
|
706
|
+
for (const row of depRows) {
|
|
707
|
+
const targetMatches =
|
|
708
|
+
row.target.includes(cleanPath) ||
|
|
709
|
+
(baseBoundary !== null && baseBoundary.test(row.target)) ||
|
|
710
|
+
symNames.some((re) => re.test(row.target) || re.test(row.stmt));
|
|
711
|
+
if (targetMatches) {
|
|
712
|
+
matchedFiles.add(row.file);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
694
715
|
}
|
|
695
716
|
}
|
|
696
717
|
|
|
@@ -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 { domainNameKey, domainRootIdentity, DomainRootConflictError } from "../../config/domain-ownership.ts";
|
|
12
13
|
|
|
13
14
|
const CONTAINER_KINDS = new Set<SymbolKind>([
|
|
14
15
|
"class",
|
|
@@ -21,9 +22,19 @@ const CONTAINER_KINDS = new Set<SymbolKind>([
|
|
|
21
22
|
export class DomainRepository {
|
|
22
23
|
constructor(private db: Database) {}
|
|
23
24
|
|
|
24
|
-
public upsertDomain(name: string, config: DomainConfig): number {
|
|
25
|
+
public upsertDomain(name: string, config: DomainConfig, workspaceRoot?: string): number {
|
|
25
26
|
return this.db.transaction(() => {
|
|
26
27
|
const normalizedName = name.trim();
|
|
28
|
+
const root = workspaceRoot ?? this.db.query<{ value: string }, []>("SELECT value FROM repo_meta WHERE key='workspace_root'").get()?.value ?? process.cwd();
|
|
29
|
+
const claims = Object.fromEntries(this.getAllDomains()
|
|
30
|
+
.filter(domain => domainNameKey(domain.name) !== domainNameKey(normalizedName))
|
|
31
|
+
.map(domain => [domain.name, { root: domain.root_path }]));
|
|
32
|
+
// Validate the proposed root inside the same immediate transaction as the write.
|
|
33
|
+
// Unrelated legacy conflicts can be repaired one domain at a time.
|
|
34
|
+
const proposed = domainRootIdentity(config.root, root);
|
|
35
|
+
for (const [owner, claim] of Object.entries(claims)) {
|
|
36
|
+
if (domainRootIdentity(claim.root, root) === proposed) throw new DomainRootConflictError(owner, normalizedName, proposed);
|
|
37
|
+
}
|
|
27
38
|
let existing = this.getDomainByName(normalizedName);
|
|
28
39
|
|
|
29
40
|
// MCP-13: If duplicates exist with different casing, consolidate into canonical primary row
|
|
@@ -131,6 +142,27 @@ export class DomainRepository {
|
|
|
131
142
|
return this.db.query<DomainRecord, []>("SELECT * FROM domains ORDER BY name ASC").all();
|
|
132
143
|
}
|
|
133
144
|
|
|
145
|
+
/** Delete domains not present in activeNames (case-insensitive) and return removed counts. */
|
|
146
|
+
public pruneDomainsNotIn(activeNames: string[]): { prunedDomains: number; removedFiles: number } {
|
|
147
|
+
const activeSet = new Set(activeNames.map((n) => n.trim().toLowerCase()));
|
|
148
|
+
return this.db.transaction(() => {
|
|
149
|
+
const existing = this.getAllDomains();
|
|
150
|
+
const stale = existing.filter((d) => !activeSet.has(d.name.trim().toLowerCase()));
|
|
151
|
+
if (stale.length === 0) return { prunedDomains: 0, removedFiles: 0 };
|
|
152
|
+
|
|
153
|
+
let removedFiles = 0;
|
|
154
|
+
const countFilesStmt = this.db.query<{ cnt: number }, [number]>(
|
|
155
|
+
"SELECT COUNT(*) AS cnt FROM files WHERE domain_id = ?"
|
|
156
|
+
);
|
|
157
|
+
const deleteDomainStmt = this.db.query("DELETE FROM domains WHERE id = ?");
|
|
158
|
+
for (const domain of stale) {
|
|
159
|
+
removedFiles += countFilesStmt.get(domain.id)?.cnt ?? 0;
|
|
160
|
+
deleteDomainStmt.run(domain.id);
|
|
161
|
+
}
|
|
162
|
+
return { prunedDomains: stale.length, removedFiles };
|
|
163
|
+
}).immediate();
|
|
164
|
+
}
|
|
165
|
+
|
|
134
166
|
public getDomainCatalog(
|
|
135
167
|
domainName: string,
|
|
136
168
|
archetypeFilter?: string,
|
|
@@ -282,13 +314,24 @@ export class DomainRepository {
|
|
|
282
314
|
imported_by_count: rawConn?.imported_by_count ?? 0,
|
|
283
315
|
};
|
|
284
316
|
|
|
317
|
+
const allMappedSymbols = Array.from(symbolMap.values());
|
|
318
|
+
const isCompact = detailLevel === "compact";
|
|
319
|
+
const MAX_COMPACT_SYMBOLS = 25;
|
|
320
|
+
const symbolsToDisplay = isCompact && allMappedSymbols.length > MAX_COMPACT_SYMBOLS
|
|
321
|
+
? allMappedSymbols.slice(0, MAX_COMPACT_SYMBOLS)
|
|
322
|
+
: allMappedSymbols;
|
|
323
|
+
const symbolsOmitted = isCompact && allMappedSymbols.length > MAX_COMPACT_SYMBOLS
|
|
324
|
+
? allMappedSymbols.length - MAX_COMPACT_SYMBOLS
|
|
325
|
+
: undefined;
|
|
326
|
+
|
|
285
327
|
catalogFiles.push({
|
|
286
328
|
...(detailLevel === "full" ? { declarations: symbols.map(sym => symbolReference({ ...sym, file_path: file.path, indexed_content_hash: file.content_hash })) } : {}),
|
|
287
329
|
path: file.path,
|
|
288
330
|
archetype: file.archetype,
|
|
289
331
|
line_count: file.line_count,
|
|
290
332
|
connections: fileConnections,
|
|
291
|
-
|
|
333
|
+
...(symbolsOmitted !== undefined ? { symbols_omitted: symbolsOmitted } : {}),
|
|
334
|
+
symbols: symbolsToDisplay.map((s) => {
|
|
292
335
|
if (detailLevel === "compact") {
|
|
293
336
|
return {
|
|
294
337
|
name: s.name,
|
|
@@ -323,7 +366,7 @@ export class DomainRepository {
|
|
|
323
366
|
files: catalogFiles,
|
|
324
367
|
agent_hint:
|
|
325
368
|
detailLevel === "compact"
|
|
326
|
-
? "Compact
|
|
369
|
+
? "Compact declaration catalog. Use septum_symbol({ action: 'context', query: symbol, file_path: '<path>' }) for declaration details. septum_map provides navigation rather than member inventories."
|
|
327
370
|
: undefined,
|
|
328
371
|
};
|
|
329
372
|
}
|