@dimassetoid/septum-mcp 0.3.0 → 0.5.1

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.
Files changed (129) hide show
  1. package/README.md +38 -55
  2. package/package.json +7 -5
  3. package/src/cli/commands/check.ts +14 -10
  4. package/src/cli/commands/hook.ts +41 -6
  5. package/src/cli/commands/init.ts +10 -1
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +32 -4
  9. package/src/cli/index.ts +7 -0
  10. package/src/cli/templates/hooks.ts +3 -14
  11. package/src/cli/templates/skill.ts +17 -10
  12. package/src/core/boundary/audit.ts +383 -0
  13. package/src/core/boundary/evaluator.ts +251 -114
  14. package/src/core/boundary/staged-auditor.ts +147 -55
  15. package/src/core/config/domain-ownership.ts +6 -4
  16. package/src/core/config/domain-registration.ts +141 -0
  17. package/src/core/config/loader.ts +1 -25
  18. package/src/core/config/schema.ts +24 -36
  19. package/src/core/database/client.ts +2 -0
  20. package/src/core/database/repositories/dependency.repository.ts +334 -572
  21. package/src/core/database/repositories/domain.repository.ts +2 -1
  22. package/src/core/database/repositories/file.repository.ts +10 -0
  23. package/src/core/database/repositories/symbol.repository.ts +97 -398
  24. package/src/core/database/repository.ts +68 -9
  25. package/src/core/database/schema.ts +26 -0
  26. package/src/core/discovery/declarative-routes.ts +69 -0
  27. package/src/core/discovery/framework-detector.ts +149 -0
  28. package/src/core/discovery/navigation.ts +222 -58
  29. package/src/core/discovery/topology-detector.ts +93 -168
  30. package/src/core/errors.ts +19 -0
  31. package/src/core/ingestion/pipeline.ts +287 -88
  32. package/src/core/parser/extractors/base.ts +11 -3
  33. package/src/core/parser/extractors/csharp.ts +2 -2
  34. package/src/core/parser/extractors/django-routing.ts +163 -0
  35. package/src/core/parser/extractors/django-semantic.ts +397 -481
  36. package/src/core/parser/extractors/elysia-semantic.ts +172 -475
  37. package/src/core/parser/extractors/express-semantic.ts +195 -383
  38. package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
  39. package/src/core/parser/extractors/fastify-semantic.ts +216 -717
  40. package/src/core/parser/extractors/flask-semantic.ts +89 -352
  41. package/src/core/parser/extractors/go-routing.ts +344 -0
  42. package/src/core/parser/extractors/go-semantic.ts +205 -562
  43. package/src/core/parser/extractors/go.ts +6 -3
  44. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  45. package/src/core/parser/extractors/hono-semantic.ts +132 -509
  46. package/src/core/parser/extractors/java.ts +2 -2
  47. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  48. package/src/core/parser/extractors/laravel-semantic.ts +143 -335
  49. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  50. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  51. package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
  52. package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
  53. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  54. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  55. package/src/core/parser/extractors/php.ts +1 -1
  56. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  57. package/src/core/parser/extractors/python.ts +5 -9
  58. package/src/core/parser/extractors/registry.ts +2 -0
  59. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  60. package/src/core/parser/extractors/ruby.ts +2 -2
  61. package/src/core/parser/extractors/rust.ts +4 -4
  62. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  63. package/src/core/parser/extractors/symfony-semantic.ts +72 -226
  64. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  65. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  66. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  67. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  68. package/src/core/parser/extractors/typescript.ts +23 -216
  69. package/src/core/parser/language-capabilities.ts +1 -1
  70. package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
  71. package/src/core/parser/wasm-loader.ts +6 -2
  72. package/src/core/resolver/ast-method-tracer.ts +230 -0
  73. package/src/core/resolver/call-graph-helpers.ts +72 -0
  74. package/src/core/resolver/call-graph-tracer.ts +169 -414
  75. package/src/core/resolver/dependency-analysis.ts +593 -0
  76. package/src/core/resolver/import-candidates.ts +120 -0
  77. package/src/core/resolver/import-evidence.ts +88 -0
  78. package/src/core/resolver/import-resolver.ts +60 -7
  79. package/src/core/resolver/interpretation-inputs.ts +60 -2
  80. package/src/core/resolver/languages/python.ts +31 -13
  81. package/src/core/resolver/languages/shared.ts +4 -1
  82. package/src/core/resolver/module-resolver.ts +10 -3
  83. package/src/core/resolver/path-resolver.ts +6 -3
  84. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  85. package/src/core/resolver/slice-catalog.ts +21 -6
  86. package/src/core/resolver/slice-format.ts +13 -0
  87. package/src/core/resolver/slice-selection.ts +237 -0
  88. package/src/core/resolver/symbol-impact.ts +104 -8
  89. package/src/core/resolver/symbol-locator.ts +82 -15
  90. package/src/core/resolver/vertical-slice-tracer.ts +31 -230
  91. package/src/core/resources/ignore.ts +0 -1
  92. package/src/core/resources/limits.ts +2 -1
  93. package/src/core/resources/work-queue.ts +167 -4
  94. package/src/core/retrieval/context-page.ts +11 -4
  95. package/src/core/retrieval/context.ts +363 -226
  96. package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
  97. package/src/core/retrieval/symbol-details.ts +453 -0
  98. package/src/core/retrieval/symbol-evidence.ts +3 -3
  99. package/src/core/retrieval/typescript-references.ts +38 -7
  100. package/src/core/retrieval/universal-context.ts +182 -0
  101. package/src/core/telemetry/summary.ts +114 -0
  102. package/src/core/telemetry/telemetry.ts +192 -49
  103. package/src/mcp/formatters/compact-text.ts +439 -0
  104. package/src/mcp/resources-and-prompts.ts +255 -0
  105. package/src/mcp/schemas/boundary.ts +145 -0
  106. package/src/mcp/schemas/map.ts +250 -0
  107. package/src/mcp/schemas/shared.ts +52 -0
  108. package/src/mcp/schemas/slice.ts +60 -0
  109. package/src/mcp/schemas/symbol.ts +268 -0
  110. package/src/mcp/schemas.ts +5 -746
  111. package/src/mcp/server.ts +269 -429
  112. package/src/mcp/tool-catalog.ts +331 -0
  113. package/src/mcp/tools/boundary.ts +68 -3
  114. package/src/mcp/tools/map.ts +104 -4
  115. package/src/mcp/tools/slice.ts +101 -3
  116. package/src/mcp/tools/symbol.ts +469 -17
  117. package/src/mcp/ui/app-client.ts +899 -0
  118. package/src/mcp/ui/app.html +478 -0
  119. package/src/mcp/workflow-playbooks.ts +181 -0
  120. package/src/mcp/workspace-boundary.ts +50 -0
  121. package/src/mcp/workspace-manager.ts +88 -15
  122. package/src/mcp/workspace-watcher.ts +30 -11
  123. package/src/types/index.ts +12 -0
  124. package/src/mcp/tools/check-boundary.ts +0 -382
  125. package/src/mcp/tools/get-domain-catalog.ts +0 -39
  126. package/src/mcp/tools/get-symbol-impact.ts +0 -104
  127. package/src/mcp/tools/locate-symbol.ts +0 -236
  128. package/src/mcp/tools/register-domain.ts +0 -113
  129. package/src/mcp/tools/trace-vertical-slice.ts +0 -106
@@ -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
+ }
@@ -32,10 +32,19 @@ const PHP_STDLIB = new Set([
32
32
  "BadFunctionCallException", "BadMethodCallException", "Attribute"
33
33
  ]);
34
34
 
35
- /** Static, workspace-contained resolution. No manifest scripts, downloads or retained cache. */
35
+ /** Static, workspace-contained resolution. No manifest scripts, downloads or retained cache across calls. */
36
36
  export class ImportResolver {
37
37
  private root: string;
38
- constructor(root: string, private packageRoots: string[] = []) { this.root = path.resolve(root); }
38
+ private readonly batchCache: boolean;
39
+ private readonly batchReads = new Map<string, { text: string; hash: string } | null>();
40
+ private readonly batchProbes = new Map<string, ReturnType<typeof probeSourcePath>>();
41
+ private readonly batchJson = new Map<string, any>();
42
+ private readonly batchDerived = new Map<string, unknown>();
43
+
44
+ constructor(root: string, private packageRoots: string[] = [], options: { batchCache?: boolean } = {}) {
45
+ this.root = path.resolve(root);
46
+ this.batchCache = Boolean(options.batchCache);
47
+ }
39
48
 
40
49
  public resolve(target: string, sourceFile: string, statement?: string): ImportResolution {
41
50
  const manifests: Record<string, string> = {};
@@ -49,22 +58,52 @@ export class ImportResolver {
49
58
  ...result, status, reason, targets,
50
59
  config_revision: computeContentHash(JSON.stringify({ root: this.root, revision: RESOLVER_REVISION, manifests })),
51
60
  });
61
+ const probeCached = (file: string): ReturnType<typeof probeSourcePath> => {
62
+ if (this.batchCache) {
63
+ const cached = this.batchProbes.get(file);
64
+ if (cached !== undefined) return cached;
65
+ const kind = probeSourcePath(file);
66
+ this.batchProbes.set(file, kind);
67
+ return kind;
68
+ }
69
+ return probeSourcePath(file);
70
+ };
52
71
  const read = (file: string): string | undefined => {
53
72
  this.assertContained(file);
54
73
  if (contents.has(file)) return contents.get(file);
55
- if (probeSourcePath(file) === "missing") { manifests[path.relative(this.root, file)] = "missing"; return undefined; }
74
+ if (this.batchCache && this.batchReads.has(file)) {
75
+ const cached = this.batchReads.get(file);
76
+ if (cached === null || cached === undefined) {
77
+ manifests[path.relative(this.root, file)] = "missing";
78
+ contents.set(file, undefined);
79
+ return undefined;
80
+ }
81
+ contents.set(file, cached.text);
82
+ manifests[path.relative(this.root, file)] = cached.hash;
83
+ return cached.text;
84
+ }
85
+ if (probeCached(file) === "missing") {
86
+ manifests[path.relative(this.root, file)] = "missing";
87
+ if (this.batchCache) this.batchReads.set(file, null);
88
+ return undefined;
89
+ }
56
90
  const text = readSourceFile(file);
57
91
  bytesRead += Buffer.byteLength(text, "utf8");
58
92
  if (bytesRead > 16 * 1024 * 1024) throw new Error("resolution_source_byte_limit");
93
+ const hash = computeContentHash(text);
59
94
  contents.set(file, text);
60
- manifests[path.relative(this.root, file)] = computeContentHash(text); return text;
95
+ if (this.batchCache) this.batchReads.set(file, { text, hash });
96
+ manifests[path.relative(this.root, file)] = hash;
97
+ return text;
61
98
  };
62
99
  const json = (file: string): any => {
63
100
  const raw = read(file); if (raw === undefined) return {};
101
+ if (this.batchCache && this.batchJson.has(file)) return this.batchJson.get(file);
64
102
  const clean = raw.replace(/"(?:\\.|[^"\\])*"|\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g, token => token.startsWith('"') ? token : " ")
65
103
  .replace(/"(?:\\.|[^"\\])*"|,\s*[}\]]/g, token => token.startsWith('"') ? token : token.slice(1));
66
104
  const parsed = JSON.parse(clean);
67
105
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("malformed_manifest");
106
+ if (this.batchCache) this.batchJson.set(file, parsed);
68
107
  return parsed;
69
108
  };
70
109
  const filesAt = (base: string, extensions: string[]): string[] => {
@@ -86,7 +125,7 @@ export class ImportResolver {
86
125
  const candidates = [base, ...extraCandidates, ...extensions.map(ext => base + ext), ...extensions.map(ext => path.join(base, "index" + ext))];
87
126
  return [...new Set(candidates.filter(file => {
88
127
  this.assertContained(file);
89
- return probeSourcePath(file) === "file";
128
+ return probeCached(file) === "file";
90
129
  }).map(file => path.relative(this.root, file).replace(/\\/g, "/")))];
91
130
  };
92
131
  const resolvedFiles = (files: string[], reason: string) => {
@@ -98,7 +137,14 @@ export class ImportResolver {
98
137
  if (target.startsWith("dynamic:")) return finish("unresolved", "dynamic_target");
99
138
  const source = path.resolve(this.root, sourceFile); this.assertContained(source);
100
139
  const ext = path.extname(source).toLowerCase();
101
- const io: ResolutionIO = { root: this.root, read, check: file => this.assertContained(file), finish };
140
+ const io: ResolutionIO = {
141
+ root: this.root,
142
+ read,
143
+ probe: probeCached,
144
+ cache: this.batchCache ? this.batchDerived : undefined,
145
+ check: file => this.assertContained(file),
146
+ finish,
147
+ };
102
148
  if (ext === ".go") return resolveGo(io, target, sourceFile, GO_STDLIB);
103
149
  if (ext === ".py") return resolvePython(io, target, sourceFile, this.packageRoots, PYTHON_STDLIB);
104
150
  if (ext === ".rb") return resolveRuby(io, target, sourceFile, statement);
@@ -243,6 +289,7 @@ export class ImportResolver {
243
289
  if (foundTsConfig && foundPkg) break;
244
290
  if (dir === this.root) break;
245
291
  }
292
+ let extendsMissing = false;
246
293
  const loadTsConfig = (configPath: string, visited = new Set<string>()): any => {
247
294
  if (visited.has(configPath)) throw new Error("circular_tsconfig_extends");
248
295
  visited.add(configPath);
@@ -261,7 +308,10 @@ export class ImportResolver {
261
308
  parentPath = path.resolve(base, typeof pkg.tsconfig === "string" ? pkg.tsconfig : "tsconfig.json");
262
309
  }
263
310
  this.assertContained(parentPath);
264
- if (probeSourcePath(parentPath) === "missing") throw new Error("tsconfig_extends_not_found");
311
+ if (probeSourcePath(parentPath) === "missing") {
312
+ extendsMissing = true;
313
+ continue;
314
+ }
265
315
  options = { ...options, ...loadTsConfig(parentPath, visited) };
266
316
  }
267
317
  const own = cfg.compilerOptions ?? {};
@@ -349,6 +399,9 @@ export class ImportResolver {
349
399
  pkg.dependencies, pkg.devDependencies, pkg.peerDependencies, pkg.optionalDependencies,
350
400
  ];
351
401
  if (depMaps.some(deps => deps && Object.hasOwn(deps, name))) return finish("external", "package_manifest_dependency");
402
+ if (extendsMissing) {
403
+ return finish("unsupported", "manifest_or_source_error: tsconfig_extends_not_found");
404
+ }
352
405
  return finish("unresolved", "package_not_declared");
353
406
  } catch (error) {
354
407
  return finish("unsupported", error instanceof Error && error.message.includes("outside_workspace") ? "outside_workspace" : `manifest_or_source_error: ${error instanceof Error ? error.message : String(error)}`);
@@ -1,7 +1,65 @@
1
1
  import { basename } from "node:path";
2
2
 
3
+ const RESOLUTION_INPUT_BASENAMES = new Set([
4
+ "package.json",
5
+ "package-lock.json",
6
+ "pnpm-lock.yaml",
7
+ "pnpm-workspace.yaml",
8
+ "yarn.lock",
9
+ "bun.lock",
10
+ "bun.lockb",
11
+ "nest-cli.json",
12
+ "nx.json",
13
+ "turbo.json",
14
+ "lerna.json",
15
+ "pyproject.toml",
16
+ "setup.py",
17
+ "setup.cfg",
18
+ "pipfile",
19
+ "pipfile.lock",
20
+ "poetry.lock",
21
+ "uv.lock",
22
+ "pdm.lock",
23
+ "mypy.ini",
24
+ "pyrightconfig.json",
25
+ "go.mod",
26
+ "go.work",
27
+ "go.sum",
28
+ "cargo.toml",
29
+ "cargo.lock",
30
+ "composer.json",
31
+ "composer.lock",
32
+ "artisan",
33
+ "gemfile",
34
+ "gemfile.lock",
35
+ "pom.xml",
36
+ "build.gradle",
37
+ "build.gradle.kts",
38
+ "settings.gradle",
39
+ "settings.gradle.kts",
40
+ "gradle.properties",
41
+ "directory.build.props",
42
+ "directory.build.targets",
43
+ "packages.config",
44
+ ]);
45
+
3
46
  /** Files whose staged bytes and watcher events can change import interpretation. */
4
47
  export function isResolutionInput(file: string): boolean {
5
- return /\.(?:json|jsonc|toml|ya?ml|xml|csproj|props|targets|gradle|gradle\.kts|gemspec|lock|txt|in)$/i.test(file) ||
6
- /^(?:Gemfile|Pipfile|go\.mod|go\.work|artisan|nest-cli\.json)$/.test(basename(file));
48
+ const norm = file.replace(/\\/g, "/");
49
+ const base = basename(norm).toLowerCase();
50
+ if (RESOLUTION_INPUT_BASENAMES.has(base)) return true;
51
+ if (/^(?:tsconfig|jsconfig)(?:\.[^/]+)?\.jsonc?$/i.test(base)) return true;
52
+ if (/^requirements(?:[-_.][^/]*)?\.(?:txt|in)$/i.test(base) || /(?:^|\/)requirements\/[^/]+\.(?:txt|in)$/i.test(norm)) {
53
+ return true;
54
+ }
55
+ if (/\.(?:csproj|fsproj|vbproj|props|targets|gemspec|gradle|gradle\.kts)$/i.test(base)) return true;
56
+ // Inherited tsconfig/jsconfig or custom workspace JSON configs (e.g. configs/base.json),
57
+ // while excluding test fixtures/cassettes/locales.
58
+ if (
59
+ /\.(?:json|jsonc)$/i.test(base) &&
60
+ !/(?:^|\/)(?:tests?|__tests__|cassettes|fixtures?|__fixtures__|locales?|i18n|translations?)\//i.test(norm)
61
+ ) {
62
+ return true;
63
+ }
64
+ return false;
7
65
  }
@@ -6,6 +6,7 @@ const DIST_MODULES: Record<string, string[]> = {
6
6
  beautifulsoup4: ["bs4"], opencv_python: ["cv2"], protobuf: ["google"], typing_extensions: ["typing_extensions"],
7
7
  pyjwt: ["jwt"], python_jose: ["jose"], python_dateutil: ["dateutil"], django_rest_framework: ["rest_framework"],
8
8
  djangorestframework: ["rest_framework"], psycopg2_binary: ["psycopg2"], opencv_python_headless: ["cv2"],
9
+ graphql_core: ["graphql"], graphql: ["graphql"], graphene: ["graphene"], strawberry_graphql: ["strawberry"],
9
10
  };
10
11
  const manifests = ["requirements.txt", "pyproject.toml", "Pipfile", "poetry.lock", "uv.lock", "Pipfile.lock"];
11
12
  const normalize = (name: string) => name.toLowerCase().replace(/[-_.]+/g, "_");
@@ -15,13 +16,25 @@ function distribution(value: string): string | undefined {
15
16
  }
16
17
 
17
18
  function declaredDependencies(io: ResolutionIO, owner: string): { packages: Set<string>; local: Map<string, string> } {
19
+ const cacheKey = `py_deps:${owner}`;
20
+ const cached = io.cache?.get(cacheKey) as { packages: Set<string>; local: Map<string, string>; files: string[] } | undefined;
21
+ if (cached) {
22
+ // Still touch manifests via io.read so config_revision reflects all observed manifests
23
+ for (const file of cached.files) io.read(file);
24
+ return cached;
25
+ }
26
+ const observedFiles: string[] = [];
27
+ const readManifest = (file: string): string | undefined => {
28
+ observedFiles.push(file);
29
+ return io.read(file);
30
+ };
18
31
  const packages = new Set<string>();
19
32
  const local = new Map<string, string>();
20
33
  const add = (name: string) => { packages.add(normalize(name)); };
21
34
  const requirementFile = (file: string, visited = new Set<string>()): void => {
22
35
  if (visited.has(file) || visited.size >= 64) throw new Error("python_requirements_cycle_or_limit");
23
36
  visited.add(file);
24
- const text = io.read(file);
37
+ const text = readManifest(file);
25
38
  if (text === undefined) throw new Error("python_requirements_include_missing");
26
39
  for (const raw of text.replace(/\\\r?\n/g, " ").split(/\r?\n/)) {
27
40
  const line = raw.replace(/\s+#.*$/, "").trim();
@@ -33,8 +46,8 @@ function declaredDependencies(io: ResolutionIO, owner: string): { packages: Set<
33
46
  const name = distribution(line); if (name) add(name);
34
47
  }
35
48
  };
36
- if (io.read(path.join(owner, "requirements.txt")) !== undefined) requirementFile(path.join(owner, "requirements.txt"));
37
- const projectText = io.read(path.join(owner, "pyproject.toml"));
49
+ if (readManifest(path.join(owner, "requirements.txt")) !== undefined) requirementFile(path.join(owner, "requirements.txt"));
50
+ const projectText = readManifest(path.join(owner, "pyproject.toml"));
38
51
  if (projectText !== undefined) {
39
52
  const project = toml(projectText);
40
53
  const arrays = [project.project?.dependencies, ...Object.values(project.project?.["optional-dependencies"] ?? {}),
@@ -53,7 +66,7 @@ function declaredDependencies(io: ResolutionIO, owner: string): { packages: Set<
53
66
  }
54
67
  }
55
68
  }
56
- const pipfile = io.read(path.join(owner, "Pipfile"));
69
+ const pipfile = readManifest(path.join(owner, "Pipfile"));
57
70
  if (pipfile !== undefined) {
58
71
  const parsed = toml(pipfile);
59
72
  for (const group of [parsed.packages, parsed["dev-packages"]]) for (const [name, value] of Object.entries(group ?? {})) {
@@ -61,7 +74,7 @@ function declaredDependencies(io: ResolutionIO, owner: string): { packages: Set<
61
74
  }
62
75
  }
63
76
  for (const name of ["poetry.lock", "uv.lock"]) {
64
- const text = io.read(path.join(owner, name));
77
+ const text = readManifest(path.join(owner, name));
65
78
  if (text === undefined) continue;
66
79
  const locked = toml(text).package;
67
80
  if (!Array.isArray(locked)) throw new Error("malformed_python_lockfile");
@@ -72,14 +85,16 @@ function declaredDependencies(io: ResolutionIO, owner: string): { packages: Set<
72
85
  if (typeof location === "string") local.set(normalize(pkg.name), path.resolve(owner, location));
73
86
  }
74
87
  }
75
- const piplock = io.read(path.join(owner, "Pipfile.lock"));
88
+ const piplock = readManifest(path.join(owner, "Pipfile.lock"));
76
89
  if (piplock !== undefined) {
77
90
  const parsed = JSON.parse(piplock);
78
91
  for (const group of [parsed.default, parsed.develop]) for (const [name, value] of Object.entries(group ?? {})) {
79
92
  add(name); if (typeof (value as any)?.path === "string") local.set(normalize(name), path.resolve(owner, (value as any).path));
80
93
  }
81
94
  }
82
- return { packages, local };
95
+ const result = { packages, local, files: [...new Set(observedFiles)] };
96
+ io.cache?.set(cacheKey, result);
97
+ return result;
83
98
  }
84
99
 
85
100
  export function resolvePython(io: ResolutionIO, target: string, source: string, roots: string[], stdlib: ReadonlySet<string>) {
@@ -96,20 +111,23 @@ export function resolvePython(io: ResolutionIO, target: string, source: string,
96
111
  const present = manifests.map(file => io.read(path.join(dir, file)) !== undefined);
97
112
  if (present.some(Boolean)) { owner = dir; break; }
98
113
  }
99
- const search = [...new Set([path.join(owner, "src"), owner, dirs[0]!, ...roots.map(root => path.resolve(io.root, root))])];
100
- const subpath = target.replace(/\./g, path.sep);
101
- const local = existingFiles(io, search.flatMap(root => [path.join(root, subpath + ".py"), path.join(root, subpath, "__init__.py")]));
102
- if (local.length) return fileResult(io, local, local.length === 1 ? "python_local_module" : "multiple_python_candidates");
103
114
  const top = target.split(".")[0]!;
104
115
  if (stdlib.has(top)) return io.finish("external", "python_standard_library");
105
116
  const { packages, local: dependencyPaths } = declaredDependencies(io, owner);
106
117
  const normalized = normalize(top);
107
118
  for (const [name, directory] of dependencyPaths) {
108
119
  if (name !== normalized && !DIST_MODULES[name]?.includes(normalized)) continue;
120
+ const subpath = target.replace(/\./g, path.sep);
109
121
  return fileResult(io, existingFiles(io, [directory, path.join(directory, "src")].flatMap(base =>
110
122
  [path.join(base, subpath + ".py"), path.join(base, subpath, "__init__.py")])), "python_local_path_dependency");
111
123
  }
112
- if (packages.has(normalized) || Object.entries(DIST_MODULES).some(([dist, modules]) => packages.has(dist) && modules.includes(normalized)))
113
- return io.finish("external", "python_manifest_dependency");
124
+ const isManifestDep = packages.has(normalized) || Object.entries(DIST_MODULES).some(([dist, modules]) => packages.has(dist) && modules.includes(normalized));
125
+ if (isManifestDep) return io.finish("external", "python_manifest_dependency");
126
+
127
+ const search = [...new Set([path.join(owner, "src"), owner, dirs[0]!, ...roots.map(root => path.resolve(io.root, root))])];
128
+ const subpath = target.replace(/\./g, path.sep);
129
+ const local = existingFiles(io, search.flatMap(root => [path.join(root, subpath + ".py"), path.join(root, subpath, "__init__.py")]));
130
+ if (local.length) return fileResult(io, local, local.length === 1 ? "python_local_module" : "multiple_python_candidates");
131
+
114
132
  return io.finish("unresolved", "python_module_not_declared");
115
133
  }
@@ -5,6 +5,8 @@ import { probeSourcePath, readSourceDirectory } from "../../resources/source-fil
5
5
  export interface ResolutionIO {
6
6
  root: string;
7
7
  read(file: string): string | undefined;
8
+ probe?(file: string): ReturnType<typeof probeSourcePath>;
9
+ cache?: Map<string, unknown>;
8
10
  check(file: string): void;
9
11
  finish(status: ImportResolution["status"], reason: string, targets?: ImportResolution["targets"]): ImportResolution;
10
12
  }
@@ -21,9 +23,10 @@ export function ancestors(io: ResolutionIO, source: string): string[] {
21
23
  }
22
24
 
23
25
  export function existingFiles(io: ResolutionIO, candidates: string[]): string[] {
26
+ const probe = io.probe ?? probeSourcePath;
24
27
  return [...new Set(candidates.filter(file => {
25
28
  io.check(file);
26
- return probeSourcePath(file) === "file";
29
+ return probe(file) === "file";
27
30
  }).map(file => path.relative(io.root, file).replace(/\\/g, "/")))].sort();
28
31
  }
29
32
 
@@ -1,6 +1,7 @@
1
1
  import { ImportResolver } from "./import-resolver.ts";
2
2
  import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
+ import type { ImportResolution } from "../../types/index.ts";
4
5
  import type { ValidatedSeptumConfig } from "../config/schema.ts";
5
6
  import type { SeptumRepository } from "../database/repository.ts";
6
7
  import { assertUniqueDomainRoots } from "../config/domain-ownership.ts";
@@ -119,9 +120,7 @@ export class ModuleResolver {
119
120
  assertUniqueDomainRoots(config.domains, this.projectRoot);
120
121
  if (sourceFilePath && (fs.existsSync(path.resolve(this.projectRoot,sourceFilePath)) || this.repo?.getMeta?.("workspace_root"))) {
121
122
  const resolution = this.resolveImport(targetStatement,sourceFilePath,statement);
122
- if (resolution.status !== "resolved" || resolution.coverage === "conditional") return null;
123
- const domains = [...new Set(resolution.targets.flatMap(target => target.files.map(file => this.matchDomainByPath(file,config))).filter((d): d is string => !!d))];
124
- return domains.length === 1 ? domains[0]! : null;
123
+ return this.resolveDomainFromEvidence(resolution, config);
125
124
  }
126
125
  // Legacy index-only/path-policy callers have no physical source evidence.
127
126
  this.ensureConfigLoaded();
@@ -244,6 +243,14 @@ export class ModuleResolver {
244
243
  return null;
245
244
  }
246
245
 
246
+ public resolveDomainFromEvidence(resolution: ImportResolution, config: ValidatedSeptumConfig): string | null {
247
+ if (resolution.status !== "resolved" || resolution.coverage === "conditional") return null;
248
+ const domains = new Set(resolution.targets.flatMap(target => target.files.map(file => this.matchDomainByPath(file, config))).filter(
249
+ (domain): domain is string => domain !== null,
250
+ ));
251
+ return domains.size === 1 ? [...domains][0]! : null;
252
+ }
253
+
247
254
  private matchDomainByPath(targetPath: string, config: ValidatedSeptumConfig): string | null {
248
255
  const absTargetPath = this.toAbsolutePath(targetPath);
249
256
 
@@ -117,9 +117,12 @@ export function findProjectRoot(fromPath: string): string {
117
117
  */
118
118
  export function resolveWorkspaceRoot(pathHint?: string): string {
119
119
  if (pathHint && typeof pathHint === "string" && pathHint.trim()) {
120
- const trimmed = pathHint.trim().replace(/^['"]|['"]$/g, "");
121
- const absHint = resolve(trimmed);
122
- const candidate = existsSync(absHint) && statSync(absHint).isDirectory() ? canonicalizePath(absHint) : findProjectRoot(trimmed);
120
+ const trimmed = pathHint.trim();
121
+ const unquoted = trimmed.replace(/^['"]|['"]$/g, "");
122
+ const literalPath = resolve(trimmed);
123
+ // Keep an existing literal path before accepting shell-style quoting.
124
+ const absHint = unquoted !== trimmed && !existsSync(literalPath) ? resolve(unquoted) : literalPath;
125
+ const candidate = existsSync(absHint) && statSync(absHint).isDirectory() ? canonicalizePath(absHint) : findProjectRoot(absHint);
123
126
  if (candidate && existsSync(candidate) && !isAppHostDirectory(candidate)) {
124
127
  setLastKnownProjectRoot(candidate);
125
128
  return candidate;