@dimassetoid/septum-mcp 0.2.1 → 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 +46 -45
- package/package.json +8 -6
- package/src/cli/commands/check.ts +41 -26
- package/src/cli/commands/hook.ts +77 -105
- package/src/cli/commands/init.ts +35 -9
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +35 -9
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +15 -51
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +51 -27
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +46 -35
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +299 -178
- package/src/core/boundary/staged-auditor.ts +188 -34
- package/src/core/config/domain-ownership.ts +47 -0
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +82 -54
- package/src/core/config/schema.ts +24 -46
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +326 -543
- package/src/core/database/repositories/domain.repository.ts +48 -4
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -259
- package/src/core/database/repository.ts +138 -24
- package/src/core/database/schema.ts +28 -33
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +269 -0
- package/src/core/discovery/topology-detector.ts +153 -170
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +378 -212
- 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 +16 -4
- package/src/core/parser/extractors/csharp.ts +9 -5
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +400 -516
- package/src/core/parser/extractors/elysia-semantic.ts +172 -496
- package/src/core/parser/extractors/express-semantic.ts +195 -398
- package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
- package/src/core/parser/extractors/fastify-semantic.ts +216 -732
- package/src/core/parser/extractors/flask-semantic.ts +92 -388
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +210 -508
- 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 -530
- package/src/core/parser/extractors/java.ts +7 -5
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +169 -333
- 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 +84 -336
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
- 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 +17 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +9 -8
- package/src/core/parser/extractors/registry.ts +28 -5
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +10 -7
- package/src/core/parser/extractors/rust.ts +35 -17
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +75 -262
- 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 +36 -216
- 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 +77 -51
- 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/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 +375 -311
- 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 +162 -181
- package/src/core/resolver/interpretation-inputs.ts +65 -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 +133 -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 +74 -0
- package/src/core/resolver/module-resolver.ts +18 -7
- 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 +94 -0
- package/src/core/resolver/slice-format.ts +22 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +477 -0
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +57 -278
- package/src/core/resources/ignore.ts +21 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +116 -0
- package/src/core/retrieval/context.ts +457 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/source-context.ts +448 -0
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +293 -0
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +225 -37
- package/src/index.ts +0 -3
- 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 -1105
- package/src/mcp/server.ts +263 -597
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +69 -4
- package/src/mcp/tools/map.ts +126 -0
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +480 -26
- 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 +102 -18
- package/src/mcp/workspace-watcher.ts +38 -19
- package/src/types/index.ts +47 -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/check-boundary.ts +0 -387
- package/src/mcp/tools/domain.ts +0 -40
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-domain-catalog.ts +0 -226
- 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/get-symbol-impact.ts +0 -64
- package/src/mcp/tools/get-symbol.ts +0 -175
- package/src/mcp/tools/locate-symbol.ts +0 -196
- package/src/mcp/tools/register-domain.ts +0 -75
- package/src/mcp/tools/register-feature.ts +0 -110
- package/src/mcp/tools/trace-vertical-slice.ts +0 -80
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { dirname, join, normalize } from "node:path";
|
|
2
|
+
import type { FileRecord, ImportRelationship } from "../../types/index.ts";
|
|
3
|
+
import type { SeptumRepository } from "../database/repository.ts";
|
|
4
|
+
import { ImportResolver } from "./import-resolver.ts";
|
|
5
|
+
|
|
6
|
+
export class ImportCandidateResolver {
|
|
7
|
+
private hasWorkspaceEvidence = false;
|
|
8
|
+
private evidenceByFile = new Map<string, Map<string, ImportRelationship>>();
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly repo: SeptumRepository,
|
|
12
|
+
private readonly projectRoot: string,
|
|
13
|
+
private readonly indexedFiles: ReadonlyMap<string, FileRecord>,
|
|
14
|
+
private readonly findFile: (path: string) => FileRecord | undefined,
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
reset(): void {
|
|
18
|
+
this.evidenceByFile.clear();
|
|
19
|
+
this.hasWorkspaceEvidence = false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private indexEvidence(relationships: ImportRelationship[]): void {
|
|
23
|
+
for (const edge of relationships) {
|
|
24
|
+
const byTarget = this.evidenceByFile.get(edge.source.file) ?? new Map<string, ImportRelationship>();
|
|
25
|
+
this.evidenceByFile.set(edge.source.file, byTarget);
|
|
26
|
+
const target = edge.resolution.source.target;
|
|
27
|
+
if (!byTarget.has(target)) byTarget.set(target, edge);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Resolve an import target path (relative or alias) to a FileRecord in the catalog.
|
|
33
|
+
*/
|
|
34
|
+
public resolveImportTargets(sourceFilePath: string, importTarget: string): FileRecord[] {
|
|
35
|
+
if (!this.hasWorkspaceEvidence && !this.evidenceByFile.has(sourceFilePath)) {
|
|
36
|
+
this.evidenceByFile.set(sourceFilePath, new Map());
|
|
37
|
+
this.indexEvidence(this.repo.getImportRelationships(this.projectRoot, sourceFilePath));
|
|
38
|
+
}
|
|
39
|
+
const evidence = this.evidenceByFile.get(sourceFilePath)?.get(importTarget);
|
|
40
|
+
if (evidence && (evidence.freshness !== "current" || evidence.index_coverage !== "complete")) return [];
|
|
41
|
+
const result = evidence?.resolution ?? new ImportResolver(this.projectRoot, this.repo.getAllDomains?.().map(domain => domain.root_path) ?? []).resolve(importTarget, sourceFilePath);
|
|
42
|
+
if (result.status !== "resolved" || result.coverage === "conditional") {
|
|
43
|
+
// Fallback: check symbols in repository (e.g. PHP namespace classes, Go packages, Python modules)
|
|
44
|
+
const matching = this.repo.findSymbolsByName(importTarget);
|
|
45
|
+
if (matching.length === 1) {
|
|
46
|
+
const file = this.findFile(matching[0].file_path);
|
|
47
|
+
if (file) return [file];
|
|
48
|
+
}
|
|
49
|
+
const shortName = importTarget.split(/[\/\\]/).pop();
|
|
50
|
+
if (shortName && shortName !== importTarget) {
|
|
51
|
+
const shortMatches = this.repo.findSymbolsByName(shortName);
|
|
52
|
+
if (shortMatches.length === 1) {
|
|
53
|
+
const file = this.findFile(shortMatches[0].file_path);
|
|
54
|
+
if (file) return [file];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return result.targets.flatMap(target => target.files).flatMap(file => {
|
|
60
|
+
const indexed = this.findFile(file);
|
|
61
|
+
return indexed ? [indexed] : [];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public resolveImportToFile(sourceFilePath: string, importTarget: string): FileRecord | undefined {
|
|
66
|
+
if (this.repo.getMeta?.("workspace_root")) {
|
|
67
|
+
const targets = this.resolveImportTargets(sourceFilePath, importTarget);
|
|
68
|
+
return targets.length === 1 ? targets[0] : undefined;
|
|
69
|
+
}
|
|
70
|
+
// 1. Relative import (./ or ../)
|
|
71
|
+
if (importTarget.startsWith(".")) {
|
|
72
|
+
const sourceDir = dirname(sourceFilePath);
|
|
73
|
+
const combined = normalize(join(sourceDir, importTarget)).replace(/\\/g, "/");
|
|
74
|
+
|
|
75
|
+
const candidates = [
|
|
76
|
+
combined,
|
|
77
|
+
`${combined}.ts`,
|
|
78
|
+
`${combined}.tsx`,
|
|
79
|
+
`${combined}.js`,
|
|
80
|
+
`${combined}.jsx`,
|
|
81
|
+
`${combined}/index.ts`,
|
|
82
|
+
`${combined}/index.js`,
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
for (const cand of candidates) {
|
|
86
|
+
const found = this.findFile(cand);
|
|
87
|
+
if (found) return found;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 2. Alias import (@/... or src/...)
|
|
92
|
+
const cleanAlias = importTarget.replace(/^@\//, "src/");
|
|
93
|
+
const aliasCandidates = [
|
|
94
|
+
cleanAlias,
|
|
95
|
+
`${cleanAlias}.ts`,
|
|
96
|
+
`${cleanAlias}.tsx`,
|
|
97
|
+
`${cleanAlias}.js`,
|
|
98
|
+
`${cleanAlias}.jsx`,
|
|
99
|
+
`${cleanAlias}/index.ts`,
|
|
100
|
+
`${cleanAlias}/index.js`,
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
for (const cand of aliasCandidates) {
|
|
104
|
+
const found = this.findFile(cand);
|
|
105
|
+
if (found) return found;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 3. Basename search fallback
|
|
109
|
+
const baseTarget = importTarget.split("/").pop()?.replace(/\.[^.]+$/, "");
|
|
110
|
+
if (baseTarget && baseTarget.length > 3) {
|
|
111
|
+
for (const [norm, file] of this.indexedFiles.entries()) {
|
|
112
|
+
if (norm.includes(`/${baseTarget.toLowerCase()}.`) || norm.endsWith(`/${baseTarget.toLowerCase()}`)) {
|
|
113
|
+
return file;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { resolve, sep } from "node:path";
|
|
2
|
+
import type { ImportRelationship } from "../../types/index.ts";
|
|
3
|
+
import { computeContentHash } from "../ingestion/hasher.ts";
|
|
4
|
+
import { getLanguageCapability } from "../parser/language-capabilities.ts";
|
|
5
|
+
import { readSourceFile } from "../resources/source-files.ts";
|
|
6
|
+
import { ImportResolver } from "./import-resolver.ts";
|
|
7
|
+
import { assertPathContained } from "./path-resolver.ts";
|
|
8
|
+
|
|
9
|
+
export interface IndexedDependency {
|
|
10
|
+
source_file: string;
|
|
11
|
+
source_domain: string;
|
|
12
|
+
line_number: number;
|
|
13
|
+
target: string;
|
|
14
|
+
statement: string;
|
|
15
|
+
is_external: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ImportEvidence {
|
|
19
|
+
dependencies: IndexedDependency[];
|
|
20
|
+
relationships: ImportRelationship[];
|
|
21
|
+
staleFiles: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function collectImportEvidence({
|
|
25
|
+
root, files, domains, dependencies, hasAdditionalIndexedFile = () => false, verifyFile,
|
|
26
|
+
}: {
|
|
27
|
+
root: string;
|
|
28
|
+
files: { path: string; content_hash: string }[];
|
|
29
|
+
domains: { name: string; root_path: string }[];
|
|
30
|
+
dependencies: IndexedDependency[];
|
|
31
|
+
hasAdditionalIndexedFile?: (file: string) => boolean;
|
|
32
|
+
verifyFile?: (file: string) => boolean;
|
|
33
|
+
}): ImportEvidence {
|
|
34
|
+
const resolver = new ImportResolver(root, domains.map(domain => domain.root_path), { batchCache: true });
|
|
35
|
+
const resolvedDomains = domains
|
|
36
|
+
.map(domain => {
|
|
37
|
+
const domainPath = resolve(root, domain.root_path);
|
|
38
|
+
return { name: domain.name, path: domainPath, prefix: domainPath.endsWith(sep) ? domainPath : domainPath + sep };
|
|
39
|
+
})
|
|
40
|
+
.sort((a, b) => b.path.length - a.path.length);
|
|
41
|
+
const freshness = new Map<string, ImportRelationship["freshness"]>();
|
|
42
|
+
const hashes = new Map(files.map(file => [file.path, file.content_hash]));
|
|
43
|
+
const verifyFreshness = (file: string): ImportRelationship["freshness"] => {
|
|
44
|
+
const cached = freshness.get(file);
|
|
45
|
+
if (cached) return cached;
|
|
46
|
+
let status: ImportRelationship["freshness"];
|
|
47
|
+
try {
|
|
48
|
+
assertPathContained(file, root, "Import source");
|
|
49
|
+
status = computeContentHash(readSourceFile(resolve(root, file))) === hashes.get(file) ? "current" : "stale";
|
|
50
|
+
} catch {
|
|
51
|
+
status = "unavailable";
|
|
52
|
+
}
|
|
53
|
+
freshness.set(file, status);
|
|
54
|
+
return status;
|
|
55
|
+
};
|
|
56
|
+
const relationships = dependencies.map((dep): ImportRelationship => {
|
|
57
|
+
const current = verifyFreshness(dep.source_file);
|
|
58
|
+
const resolution = resolver.resolve(dep.target, dep.source_file, dep.statement);
|
|
59
|
+
if (current !== "current") {
|
|
60
|
+
resolution.status = "unresolved";
|
|
61
|
+
resolution.reason = `source_${current}`;
|
|
62
|
+
resolution.targets = [];
|
|
63
|
+
}
|
|
64
|
+
const targetDomains = resolution.targets.flatMap(target => target.files.map(file => {
|
|
65
|
+
const targetPath = resolve(root, file);
|
|
66
|
+
return resolvedDomains.find(domain => targetPath === domain.path || targetPath.startsWith(domain.prefix))?.name;
|
|
67
|
+
}).filter((name): name is string => !!name));
|
|
68
|
+
return {
|
|
69
|
+
kind: "imports", derivation: "source",
|
|
70
|
+
source: { file: dep.source_file, line: dep.line_number, statement: dep.statement, indexed_content_hash: hashes.get(dep.source_file) ?? "" },
|
|
71
|
+
resolution, target_domains: [...new Set(targetDomains)], freshness: current,
|
|
72
|
+
index_coverage: resolution.targets.every(target => target.files.every(file => hashes.has(file) ||
|
|
73
|
+
hasAdditionalIndexedFile(file) || !getLanguageCapability(file))) ? "complete" : "partial",
|
|
74
|
+
...(dep.source_file.endsWith(".go") ? { import_binding: (() => {
|
|
75
|
+
const alias = dep.statement.replace(/^\s*import\s+/, "").match(/^\s*([A-Za-z_]\w*|\.)\s+["`]/)?.[1];
|
|
76
|
+
return { kind: alias === "_" ? "blank" : alias === "." ? "dot" : alias ? "named" : "default", alias };
|
|
77
|
+
})() } : {}),
|
|
78
|
+
...(dep.source_file.endsWith(".py") ? { import_binding: (() => {
|
|
79
|
+
if (/^\s*from\s+.*\s+import\s+\*/.test(dep.statement)) return { kind: "star" };
|
|
80
|
+
const asMatch = dep.statement.match(/\bas\s+([A-Za-z_]\w*)\s*$/);
|
|
81
|
+
return { kind: asMatch ? "named" : "default", alias: asMatch?.[1] };
|
|
82
|
+
})() } : {}),
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const staleFiles = verifyFile ? files.filter(file => verifyFile(file.path) && verifyFreshness(file.path) !== "current").map(file => file.path) : [];
|
|
87
|
+
return { dependencies, relationships, staleFiles };
|
|
88
|
+
}
|