@dimassetoid/septum-mcp 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +253 -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
@@ -3,103 +3,267 @@ import type { NavigationQuery } from "../../types/index.ts";
3
3
 
4
4
  export const NAVIGATION_SCHEMA = "navigation/v1";
5
5
 
6
- /** Navigation selects indexed structure; declaration inspection belongs to symbol. */
7
- export function buildNavigation(repo: SeptumRepository, args: NavigationQuery, root: string) {
8
- const domains = repo.getAllDomains();
9
- const requested = args.domain ?? args.name;
10
- const domain = domains.find(domain => domain.name.toLowerCase() === requested?.toLowerCase());
11
- if (requested && !domain) return {
12
- schema: NAVIGATION_SCHEMA, status: "not_found", domain: requested,
13
- found: false, message: `Domain '${requested}' not found in Septum catalog.`,
14
- suggestions: domains.map(domain => domain.name),
15
- suggested_action: { tool: "septum_map", params: { action: "catalog" } },
16
- available_domains: domains.map(domain => domain.name),
17
- next: [{ tool: "septum_map", args: { action: "catalog" } }],
18
- };
19
- const files = repo.getNavigationFiles();
6
+ type NavEdge = { from: string; to: string; relation: "imports"; count: number };
7
+ type NavUnresolved = { file: string; target: string; reason: string };
8
+
9
+ /** Aggregate resolved import edges and collect unresolved/stale import diagnostics. */
10
+ function aggregateImportEdges(
11
+ repo: SeptumRepository,
12
+ root: string,
13
+ files: ReturnType<SeptumRepository["getNavigationFiles"]>,
14
+ paths: Set<string>,
15
+ workspace: boolean
16
+ ) {
20
17
  const byPath = new Map(files.map(file => [file.path, file]));
21
- const domainCounts = new Map<string, number>();
22
- for (const file of files) domainCounts.set(file.domain, (domainCounts.get(file.domain) ?? 0) + 1);
23
- const filter = args.file_filter?.replace(/\\/g, "/").toLowerCase();
24
- const matching = files.filter(file => (!domain || file.domain === domain.name) &&
25
- (!filter || file.path.toLowerCase().includes(filter)) &&
26
- (!(args.archetype_filter ?? args.archetype) || file.archetype === (args.archetype_filter ?? args.archetype)));
27
- const paths = new Set(matching.map(file => file.path));
28
- const relationships = repo.getImportRelationships(root);
29
18
  const degree = new Map<string, number>();
30
- const edges = new Map<string, { from: string; to: string; relation: "imports"; count: number }>();
31
- const unresolved: Array<{ file: string; target: string; reason: string }> = [];
32
- const workspace = !domain && !filter && !args.archetype_filter && !args.archetype;
33
- for (const edge of relationships) {
19
+ const edges = new Map<string, NavEdge>();
20
+ const unresolved: NavUnresolved[] = [];
21
+
22
+ const relationshipList = workspace
23
+ ? repo.getImportRelationships(root)
24
+ : repo.getScopedImportRelationships(root, { sourceOrTargetPaths: paths });
25
+
26
+ for (const edge of relationshipList) {
34
27
  const source = edge.source.file;
35
28
  const targets = [...new Set(edge.resolution.targets.flatMap(target => target.files))];
36
- const relevant = paths.has(source) || targets.some(target => paths.has(target));
37
- if (!relevant) continue;
38
- if (edge.freshness !== "current" || !["resolved", "external"].includes(edge.resolution.status) || edge.resolution.coverage === "conditional" || edge.index_coverage === "partial") {
39
- unresolved.push({ file: source, target: edge.resolution.source.target,
40
- reason: edge.freshness !== "current" ? `source_${edge.freshness}` : edge.index_coverage === "partial" ? "target_not_fully_indexed" : edge.resolution.reason });
29
+ if (!paths.has(source) && !targets.some(target => paths.has(target))) continue;
30
+
31
+ const isIncomplete = edge.freshness !== "current" ||
32
+ !["resolved", "external"].includes(edge.resolution.status) ||
33
+ edge.resolution.coverage === "conditional" ||
34
+ edge.index_coverage === "partial";
35
+ if (isIncomplete) {
36
+ unresolved.push({
37
+ file: source,
38
+ target: edge.resolution.source.target,
39
+ reason: edge.freshness !== "current"
40
+ ? `source_${edge.freshness}`
41
+ : edge.index_coverage === "partial"
42
+ ? "target_not_fully_indexed"
43
+ : edge.resolution.reason,
44
+ });
41
45
  }
42
46
  if (edge.freshness !== "current" || edge.resolution.status !== "resolved") continue;
47
+
43
48
  for (const target of targets) {
44
49
  degree.set(source, (degree.get(source) ?? 0) + 1);
45
50
  degree.set(target, (degree.get(target) ?? 0) + 1);
46
51
  const from = workspace ? byPath.get(source)?.domain : source;
47
52
  const to = workspace ? byPath.get(target)?.domain : target;
48
- if (!from || !to || workspace && from === to) continue;
53
+ if (!from || !to || (workspace && from === to)) continue;
49
54
  const key = JSON.stringify([from, to]);
50
55
  const prior = edges.get(key);
51
56
  if (prior) prior.count++;
52
57
  else edges.set(key, { from, to, relation: "imports", count: 1 });
53
58
  }
54
59
  }
60
+
61
+ return { byPath, degree, edges, unresolved };
62
+ }
63
+
64
+ /** Summarize index health and coverage diagnostics for the selected navigation scope. */
65
+ function computeNavigationHealth(
66
+ repo: SeptumRepository,
67
+ domainRoot: string | undefined,
68
+ unresolved: NavUnresolved[],
69
+ emptyDomainsCount: number,
70
+ totalIndexedFiles: number,
71
+ uncoveredCount: number
72
+ ) {
73
+ const sync = repo.getMeta("sync_state") ?? "unindexed";
74
+ const dirty = repo.getMeta("slices_dirty") === "1";
75
+ const prefix = domainRoot ? domainRoot.replace(/\/$/, "") + "/" : undefined;
76
+ const unsupported = (JSON.parse(repo.getMeta("unsupported_files") || "[]") as string[])
77
+ .filter(path => !prefix || path.startsWith(prefix)).length;
78
+ const skipped = (JSON.parse(repo.getMeta("skipped_files") || "[]") as Array<{ path: string }>)
79
+ .filter(file => !prefix || file.path.startsWith(prefix)).length;
80
+
81
+ const reasons = [...new Set([
82
+ ...unresolved.map(item => item.reason),
83
+ ...(unsupported > 0 ? ["unsupported_files"] : []),
84
+ ...(skipped > 0 ? ["skipped_files"] : []),
85
+ ...(emptyDomainsCount > 0 ? ["empty_domains"] : []),
86
+ ...(totalIndexedFiles === 0 ? ["no_indexed_files"] : []),
87
+ ...(!domainRoot && uncoveredCount > 0 ? ["uncovered_workspace_files"] : []),
88
+ ...(dirty ? ["slices_dirty"] : []),
89
+ ...(sync !== "complete" ? [`index_${sync}`] : []),
90
+ ])].sort().slice(0, 10);
91
+
92
+ const coverage = sync === "complete" &&
93
+ !dirty &&
94
+ unresolved.length === 0 &&
95
+ unsupported === 0 &&
96
+ skipped === 0 &&
97
+ emptyDomainsCount === 0 &&
98
+ totalIndexedFiles > 0 &&
99
+ (domainRoot !== undefined || uncoveredCount === 0)
100
+ ? "complete"
101
+ : "partial";
102
+
103
+ return {
104
+ sync,
105
+ dirty,
106
+ health: { index: sync, sync_needed: dirty, coverage, unresolved_imports: unresolved.length, unsupported_files: unsupported, skipped_files: skipped, reasons },
107
+ };
108
+ }
109
+
110
+ /** Navigation selects indexed structure; declaration inspection belongs to symbol. */
111
+ export function buildNavigation(repo: SeptumRepository, args: NavigationQuery, root: string) {
112
+ const domains = repo.getAllDomains();
113
+ const requested = args.domain ?? args.name;
114
+ const domain = domains.find(d => d.name.toLowerCase() === requested?.toLowerCase());
115
+ if (requested && !domain) return {
116
+ schema: NAVIGATION_SCHEMA, status: "not_found", domain: requested,
117
+ found: false, message: `Domain '${requested}' not found in Septum catalog.`,
118
+ suggestions: domains.map(d => d.name),
119
+ suggested_action: { tool: "septum_map", params: { action: "catalog" } },
120
+ available_domains: domains.map(d => d.name),
121
+ next: [{ tool: "septum_map", args: { action: "catalog" } }],
122
+ };
123
+
124
+ const files = repo.getNavigationFiles();
125
+ const domainCounts = new Map<string, number>();
126
+ for (const file of files) domainCounts.set(file.domain, (domainCounts.get(file.domain) ?? 0) + 1);
127
+
128
+ const filter = args.file_filter?.replace(/\\/g, "/").toLowerCase();
129
+ const archetype = args.archetype_filter ?? args.archetype;
130
+ const matching = files.filter(file =>
131
+ (!domain || file.domain === domain.name) &&
132
+ (!filter || file.path.toLowerCase().includes(filter)) &&
133
+ (!archetype || file.archetype === archetype)
134
+ );
135
+ const paths = new Set(matching.map(file => file.path));
136
+ const workspace = !domain && !filter && !archetype;
137
+
138
+ const { byPath, degree, edges, unresolved } = aggregateImportEdges(repo, root, files, paths, workspace);
55
139
  const entries = repo.getNavigationEntrypoints().filter(entry => entry.file && paths.has(entry.file));
56
140
  const entryFiles = new Set(entries.map(entry => entry.file));
57
- matching.sort((a, b) => Number(entryFiles.has(b.path)) - Number(entryFiles.has(a.path)) ||
58
- (degree.get(b.path) ?? 0) - (degree.get(a.path) ?? 0) || a.path.localeCompare(b.path));
141
+ matching.sort((a, b) =>
142
+ Number(entryFiles.has(b.path)) - Number(entryFiles.has(a.path)) ||
143
+ (degree.get(b.path) ?? 0) - (degree.get(a.path) ?? 0) ||
144
+ a.path.localeCompare(b.path)
145
+ );
146
+
147
+ const compactDomainOnly = Boolean(domain && !filter && !archetype && args.detail_level !== "full");
148
+ const useSubmoduleZoom = Boolean(
149
+ compactDomainOnly &&
150
+ domain &&
151
+ matching.length > 25 &&
152
+ args.file_offset === undefined &&
153
+ args.file_limit === undefined
154
+ );
155
+
156
+ const submodules = useSubmoduleZoom && domain ? (() => {
157
+ const rootPrefix = domain.root_path.replace(/\\/g, "/").replace(/\/+$/, "");
158
+ const groups = new Map<string, { path: string; name: string; file_count: number; top_anchors: string[] }>();
159
+ for (const file of matching) {
160
+ const norm = file.path.replace(/\\/g, "/");
161
+ const rel = norm.startsWith(`${rootPrefix}/`) ? norm.slice(rootPrefix.length + 1) : norm;
162
+ const slash = rel.indexOf("/");
163
+ const subName = slash > 0 ? rel.slice(0, slash) : "(root)";
164
+ const subPath = slash > 0 ? `${rootPrefix}/${subName}` : rootPrefix;
165
+ let group = groups.get(subPath);
166
+ if (!group) {
167
+ group = { path: subPath, name: subName, file_count: 0, top_anchors: [] };
168
+ groups.set(subPath, group);
169
+ }
170
+ group.file_count++;
171
+ if (file.anchor && group.top_anchors.length < 3 && !group.top_anchors.includes(file.anchor)) {
172
+ group.top_anchors.push(file.anchor);
173
+ }
174
+ }
175
+ return [...groups.values()].sort((a, b) => b.file_count - a.file_count || a.path.localeCompare(b.path));
176
+ })() : undefined;
177
+
59
178
  const offset = args.file_offset ?? 0;
60
- const limit = args.file_limit ?? (args.detail_level === "full" ? 100 : 40);
179
+ const limit = args.file_limit ?? (useSubmoduleZoom ? 15 : args.detail_level === "full" ? 100 : 40);
61
180
  const selected = workspace ? [] : matching.slice(offset, offset + limit);
62
181
  const selectedPaths = new Set(selected.map(file => file.path));
182
+
63
183
  const allEdges = [...edges.values()].sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to));
64
184
  const relevantEdges = workspace ? allEdges : allEdges.filter(edge => selectedPaths.has(edge.from) || selectedPaths.has(edge.to));
65
- const compactDomainOnly = Boolean(domain && !filter && !(args.archetype_filter ?? args.archetype) && args.detail_level !== "full");
66
185
  const filteredEdges = compactDomainOnly
67
186
  ? relevantEdges.filter(edge => byPath.get(edge.from)?.domain !== byPath.get(edge.to)?.domain)
68
187
  : relevantEdges;
69
- const dependencies = filteredEdges.slice(0, 100);
188
+
189
+ // When zooming out on a large domain (>25 files with submodules), aggregate cross-domain edges
190
+ // by submodule/domain instead of emitting dozens of raw file-to-file lines.
191
+ const dependencies = (() => {
192
+ if (useSubmoduleZoom && submodules && submodules.length > 1 && domain) {
193
+ const rootPrefix = domain.root_path.replace(/\\/g, "/").replace(/\/+$/, "");
194
+ const groupLabel = (filePath: string): string => {
195
+ const meta = byPath.get(filePath);
196
+ if (!meta || meta.domain !== domain.name) return meta?.domain ?? filePath;
197
+ const norm = filePath.replace(/\\/g, "/");
198
+ const rel = norm.startsWith(`${rootPrefix}/`) ? norm.slice(rootPrefix.length + 1) : norm;
199
+ const slash = rel.indexOf("/");
200
+ return slash > 0 ? `${rootPrefix}/${rel.slice(0, slash)}` : rootPrefix;
201
+ };
202
+ const grouped = new Map<string, NavEdge>();
203
+ for (const edge of allEdges) {
204
+ const fromDomain = byPath.get(edge.from)?.domain;
205
+ const toDomain = byPath.get(edge.to)?.domain;
206
+ if (fromDomain === toDomain) continue;
207
+ const from = groupLabel(edge.from);
208
+ const to = groupLabel(edge.to);
209
+ if (from === to) continue;
210
+ const key = JSON.stringify([from, to]);
211
+ const prior = grouped.get(key);
212
+ if (prior) prior.count += edge.count;
213
+ else grouped.set(key, { from, to, relation: "imports", count: edge.count });
214
+ }
215
+ return [...grouped.values()]
216
+ .sort((a, b) => b.count - a.count || a.from.localeCompare(b.from) || a.to.localeCompare(b.to))
217
+ .slice(0, 30);
218
+ }
219
+ return filteredEdges.slice(0, 100);
220
+ })();
70
221
  const entrypoints = entries.filter(entry => workspace || selectedPaths.has(entry.file!)).slice(0, 20);
71
- const sync = repo.getMeta("sync_state") ?? "unindexed";
72
- const dirty = repo.getMeta("slices_dirty") === "1";
222
+ const scopedDomains = workspace ? domains : domain ? [domain] : [];
223
+ const emptyDomainsCount = scopedDomains.filter(d => (domainCounts.get(d.name) ?? 0) === 0).length;
224
+ const uncoveredCount = (JSON.parse(repo.getMeta("uncovered_files") || "[]") as string[]).length;
225
+ const { sync, dirty, health } = computeNavigationHealth(repo, domain?.root_path, unresolved, emptyDomainsCount, files.length, uncoveredCount);
73
226
  const end = offset + selected.length;
74
- const diagnostics = {
75
- unresolved_imports: unresolved.length,
76
- unsupported_files: (JSON.parse(repo.getMeta("unsupported_files") || "[]") as string[]).filter(path => !domain || path.startsWith(domain.root_path.replace(/\/$/, "") + "/")).length,
77
- skipped_files: (JSON.parse(repo.getMeta("skipped_files") || "[]") as Array<{ path: string }>).filter(file => !domain || file.path.startsWith(domain.root_path.replace(/\/$/, "") + "/")).length,
78
- };
227
+
79
228
  return {
80
229
  schema: NAVIGATION_SCHEMA,
81
- status: requested || filter ? matching.length ? "success" : "not_found" : domains.length ? "success" : "NOT_INDEXED",
230
+ status: requested || filter ? (matching.length ? "success" : domain && !filter ? "empty_domain" : "not_found") : (domains.length ? "success" : "NOT_INDEXED"),
82
231
  scope: { level: workspace ? "workspace" : filter ? "file" : "domain", ...(domain ? { domain: domain.name } : {}), ...(filter ? { file_filter: args.file_filter } : {}) },
83
- domains: (workspace ? domains : domain ? [domain] : []).map(domain => ({ name: domain.name, root: domain.root_path,
84
- file_count: domainCounts.get(domain.name) ?? 0,
85
- allowed_dependencies: JSON.parse(domain.allowed_deps_json || "[]") as string[],
86
- forbidden_dependencies: JSON.parse(domain.forbidden_deps_json || "[]") as string[],
232
+ domains: (workspace ? domains : domain ? [domain] : []).map(d => ({
233
+ name: d.name,
234
+ root: d.root_path,
235
+ file_count: domainCounts.get(d.name) ?? 0,
236
+ allowed_dependencies: JSON.parse(d.allowed_deps_json || "[]") as string[],
237
+ forbidden_dependencies: JSON.parse(d.forbidden_deps_json || "[]") as string[],
87
238
  })),
239
+ ...(submodules && submodules.length > 1 ? { submodules } : {}),
88
240
  files: selected,
89
241
  dependencies,
90
242
  entrypoints: entrypoints.map(entry => ({ ...entry, evidence: "static_catalog", runtime_verified: false })),
91
- health: { index: sync, sync_needed: dirty, coverage: "partial", ...diagnostics,
92
- reasons: [...new Set(unresolved.map(item => item.reason))].sort().slice(0, 10) },
243
+ health,
93
244
  index_status: { sync_state: sync, sync_needed: dirty },
94
- accounting: { matching_files: matching.length, returned_files: selected.length,
245
+ accounting: {
246
+ matching_files: matching.length,
247
+ returned_files: selected.length,
95
248
  omitted_files: workspace ? 0 : Math.max(0, matching.length - selected.length),
96
- total_dependencies: allEdges.length, returned_dependencies: dependencies.length, omitted_dependencies: allEdges.length - dependencies.length,
97
- total_entrypoints: entries.length, omitted_entrypoints: entries.length - entrypoints.length },
249
+ total_dependencies: allEdges.length,
250
+ returned_dependencies: dependencies.length,
251
+ omitted_dependencies: allEdges.length - dependencies.length,
252
+ total_entrypoints: entries.length,
253
+ omitted_entrypoints: entries.length - entrypoints.length,
254
+ },
98
255
  ...(!workspace && end < matching.length ? { pagination: { next_file_offset: end, file_offset: offset } } : {}),
99
256
  ...(args.include_evidence ? { diagnostics: unresolved.slice(0, 5), diagnostics_omitted: Math.max(0, unresolved.length - 5) } : {}),
100
- next: entrypoints[0] ? [{ tool: "septum_slice", args: { query: `${entrypoints[0].method} ${entrypoints[0].target}`, controller_file: entrypoints[0].file } }]
101
- : selected[0]?.anchor ? [{ tool: "septum_symbol", args: { action: "locate", query: selected[0].anchor, file_path: selected[0].path } }]
102
- : [{ tool: "septum_map", args: { action: "catalog", ...(domains[0] ? { domain: domains[0].name } : {}) } }],
103
- relationship_limits: "Dependencies are imports, not calls or execution order. Entrypoints come from the static catalog and may be inferred. Unindexed targets remain uncertain.",
257
+ next: submodules && submodules.length > 1 && domain
258
+ ? [
259
+ { tool: "septum_map", args: { action: "catalog", domain: domain.name, file_filter: submodules[0]!.path } },
260
+ ...(selected[0]?.anchor ? [{ tool: "septum_symbol", args: { action: "locate", query: selected[0].anchor, file_path: selected[0].path } }] : []),
261
+ ]
262
+ : entrypoints[0]
263
+ ? [{ tool: "septum_slice", args: { query: `${entrypoints[0].method} ${entrypoints[0].target}`, controller_file: entrypoints[0].file } }]
264
+ : selected[0]?.anchor
265
+ ? [{ tool: "septum_symbol", args: { action: "locate", query: selected[0].anchor, file_path: selected[0].path } }]
266
+ : [{ tool: "septum_map", args: { action: "catalog", ...(domains[0] ? { domain: domains[0].name } : {}) } }],
267
+ relationship_limits: "Dependencies are static imports; entrypoints are from the static catalog.",
104
268
  };
105
269
  }
@@ -4,6 +4,12 @@ import type { DomainConfig } from "../../types/index.ts";
4
4
  import type { SeptumRepository } from "../database/repository.ts";
5
5
  import { DEFAULT_IGNORED_DIRECTORIES, isIgnoredDirectory } from "../resources/ignore.ts";
6
6
  import { assertUniqueDomainRoots, domainNameKey, domainRootIdentity } from "../config/domain-ownership.ts";
7
+ import {
8
+ detectProjectFramework,
9
+ detectProjectLanguage,
10
+ readTsConfigPaths as readTsConfigPathMappings,
11
+ type DetectedLanguage,
12
+ } from "./framework-detector.ts";
7
13
 
8
14
  export type ProjectType =
9
15
  | "monorepo"
@@ -32,6 +38,13 @@ export interface DiscoveredProjectTopology {
32
38
  }
33
39
 
34
40
  export class TopologyDetector {
41
+ private static warnIfUnexpectedError(context: string, err: unknown): void {
42
+ const errno = (err as NodeJS.ErrnoException | undefined)?.code;
43
+ if (errno === "ENOENT" || errno === "ENOTDIR") return;
44
+ const msg = err instanceof Error ? err.message : String(err);
45
+ console.warn(`[Septum Topology] ${context}: ${msg}`);
46
+ }
47
+
35
48
  private static readonly IGNORED_DIRS = new Set([
36
49
  ...DEFAULT_IGNORED_DIRECTORIES,
37
50
  "tests",
@@ -60,22 +73,7 @@ export class TopologyDetector {
60
73
  * Reads compilerOptions.paths from tsconfig.json or jsconfig.json.
61
74
  */
62
75
  public static readTsConfigPaths(projectRoot: string): Record<string, string[]> {
63
- for (const file of ["tsconfig.json", "jsconfig.json"]) {
64
- const fullPath = path.join(projectRoot, file);
65
- if (fs.existsSync(fullPath)) {
66
- try {
67
- const raw = fs.readFileSync(fullPath, "utf-8");
68
- const stripped = raw.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "");
69
- const parsed = JSON.parse(stripped);
70
- if (parsed.compilerOptions?.paths) {
71
- return parsed.compilerOptions.paths;
72
- }
73
- } catch {
74
- // Ignore tsconfig parse error
75
- }
76
- }
77
- }
78
- return {};
76
+ return readTsConfigPathMappings(projectRoot);
79
77
  }
80
78
 
81
79
  /**
@@ -190,6 +188,21 @@ export class TopologyDetector {
190
188
  archetypes: this.inferDefaultArchetypes(path.join(projectRoot, item.relRoot)),
191
189
  };
192
190
  }
191
+
192
+ // Also include top-level monorepo workspace apps (e.g. Directus api/, app/, sdk/)
193
+ for (const topApp of ["api", "app", "server", "web", "sdk"]) {
194
+ const fullTop = path.join(projectRoot, topApp);
195
+ if (!domains[topApp] && fs.existsSync(fullTop) && fs.statSync(fullTop).isDirectory() && this.hasSourceFiles(fullTop)) {
196
+ const isSdk = topApp === "sdk";
197
+ domains[topApp] = {
198
+ root: topApp,
199
+ description: `Monorepo top-level workspace: ${topApp}`,
200
+ allowed_dependencies: isSdk ? [] : packageDomains,
201
+ forbidden_dependencies: isSdk ? appDomains : [],
202
+ archetypes: this.inferDefaultArchetypes(fullTop),
203
+ };
204
+ }
205
+ }
193
206
  }
194
207
 
195
208
  // 2. Modular DDD (app/Domain, src/modules, src/domains, domains/*, etc.)
@@ -421,66 +434,75 @@ export class TopologyDetector {
421
434
  } else if (language === "go" || fs.existsSync(path.join(projectRoot, "go.mod"))) {
422
435
  architectureStyle = "clean-architecture";
423
436
  const pkgDir = path.join(projectRoot, "pkg");
424
- if (fs.existsSync(pkgDir) && this.hasSourceFiles(pkgDir)) {
437
+ const hasPkg = fs.existsSync(pkgDir) && this.hasSourceFiles(pkgDir);
438
+
439
+ const internalDir = path.join(projectRoot, "internal");
440
+ const internalSubs = fs.existsSync(internalDir)
441
+ ? this.getSubdirectories(internalDir).filter((s) => this.hasSourceFiles(path.join(internalDir, s))).sort()
442
+ : [];
443
+ const hasFlatInternal = !internalSubs.length && fs.existsSync(internalDir) && this.hasSourceFiles(internalDir);
444
+ const internalNames = internalSubs.length > 0
445
+ ? internalSubs.map((s) => s.toLowerCase())
446
+ : hasFlatInternal ? ["internal"] : [];
447
+
448
+ const cmdDir = path.join(projectRoot, "cmd");
449
+ const cmdSubs = fs.existsSync(cmdDir)
450
+ ? this.getSubdirectories(cmdDir).filter((s) => this.hasSourceFiles(path.join(cmdDir, s))).sort()
451
+ : [];
452
+ const hasFlatCmd = !cmdSubs.length && fs.existsSync(cmdDir) && this.hasSourceFiles(cmdDir);
453
+ const cmdNames = cmdSubs.length > 0
454
+ ? cmdSubs.map((s) => `cmd-${s.toLowerCase()}`)
455
+ : hasFlatCmd ? ["cmd"] : [];
456
+
457
+ if (hasPkg) {
425
458
  domains["pkg"] = {
426
459
  root: "pkg",
427
460
  description: "Go public library pkg",
428
461
  allowed_dependencies: [],
429
- forbidden_dependencies: ["internal", "cmd"],
462
+ forbidden_dependencies: [...internalNames, ...cmdNames],
430
463
  archetypes: this.inferDefaultArchetypes(pkgDir),
431
464
  };
432
465
  }
433
466
 
434
- const internalDir = path.join(projectRoot, "internal");
435
- if (fs.existsSync(internalDir)) {
436
- const internalSubs = this.getSubdirectories(internalDir).filter((s) =>
437
- this.hasSourceFiles(path.join(internalDir, s))
438
- );
439
- if (internalSubs.length > 0) {
440
- for (const sub of internalSubs) {
441
- domains[sub.toLowerCase()] = {
442
- root: path.join("internal", sub),
443
- description: `Internal ${sub} domain`,
444
- allowed_dependencies: domains["pkg"] ? ["pkg"] : [],
445
- forbidden_dependencies: ["cmd"],
446
- archetypes: this.inferDefaultArchetypes(path.join(internalDir, sub)),
447
- };
448
- }
449
- } else if (this.hasSourceFiles(internalDir)) {
450
- domains["internal"] = {
451
- root: "internal",
452
- description: "Go internal layer",
453
- allowed_dependencies: domains["pkg"] ? ["pkg"] : [],
454
- forbidden_dependencies: ["cmd"],
455
- archetypes: this.inferDefaultArchetypes(internalDir),
467
+ if (internalSubs.length > 0) {
468
+ for (const sub of internalSubs) {
469
+ domains[sub.toLowerCase()] = {
470
+ root: path.join("internal", sub),
471
+ description: `Internal ${sub} domain`,
472
+ allowed_dependencies: hasPkg ? ["pkg"] : [],
473
+ forbidden_dependencies: [...cmdNames],
474
+ archetypes: this.inferDefaultArchetypes(path.join(internalDir, sub)),
456
475
  };
457
476
  }
477
+ } else if (hasFlatInternal) {
478
+ domains["internal"] = {
479
+ root: "internal",
480
+ description: "Go internal layer",
481
+ allowed_dependencies: hasPkg ? ["pkg"] : [],
482
+ forbidden_dependencies: [...cmdNames],
483
+ archetypes: this.inferDefaultArchetypes(internalDir),
484
+ };
458
485
  }
459
486
 
460
- const cmdDir = path.join(projectRoot, "cmd");
461
- if (fs.existsSync(cmdDir)) {
462
- const cmdSubs = this.getSubdirectories(cmdDir).filter((s) =>
463
- this.hasSourceFiles(path.join(cmdDir, s))
464
- );
465
- if (cmdSubs.length > 0) {
466
- for (const sub of cmdSubs) {
467
- domains[`cmd-${sub.toLowerCase()}`] = {
468
- root: path.join("cmd", sub),
469
- description: `Go entrypoint: ${sub}`,
470
- allowed_dependencies: Object.keys(domains),
471
- forbidden_dependencies: [],
472
- archetypes: this.inferDefaultArchetypes(path.join(cmdDir, sub)),
473
- };
474
- }
475
- } else if (this.hasSourceFiles(cmdDir)) {
476
- domains["cmd"] = {
477
- root: "cmd",
478
- description: "Go entrypoint cmd",
479
- allowed_dependencies: Object.keys(domains),
487
+ const cmdAllowed = [...(hasPkg ? ["pkg"] : []), ...internalNames];
488
+ if (cmdSubs.length > 0) {
489
+ for (const sub of cmdSubs) {
490
+ domains[`cmd-${sub.toLowerCase()}`] = {
491
+ root: path.join("cmd", sub),
492
+ description: `Go entrypoint: ${sub}`,
493
+ allowed_dependencies: [...cmdAllowed],
480
494
  forbidden_dependencies: [],
481
- archetypes: this.inferDefaultArchetypes(cmdDir),
495
+ archetypes: this.inferDefaultArchetypes(path.join(cmdDir, sub)),
482
496
  };
483
497
  }
498
+ } else if (hasFlatCmd) {
499
+ domains["cmd"] = {
500
+ root: "cmd",
501
+ description: "Go entrypoint cmd",
502
+ allowed_dependencies: [...cmdAllowed],
503
+ forbidden_dependencies: [],
504
+ archetypes: this.inferDefaultArchetypes(cmdDir),
505
+ };
484
506
  }
485
507
  }
486
508
  }
@@ -524,7 +546,9 @@ export class TopologyDetector {
524
546
  }
525
547
  }
526
548
  }
527
- } catch {}
549
+ } catch (err: unknown) {
550
+ this.warnIfUnexpectedError(`Failed to scan ignored directories in ${projectRoot}`, err);
551
+ }
528
552
  ignored_folders.sort();
529
553
 
530
554
  return {
@@ -733,121 +757,22 @@ export class TopologyDetector {
733
757
  if (Object.keys(archetypes).length === 0) {
734
758
  archetypes["source"] = "**/*.*";
735
759
  }
736
- } catch {}
760
+ } catch (err: unknown) {
761
+ this.warnIfUnexpectedError(`Failed to infer archetypes in ${fullDir}`, err);
762
+ }
737
763
 
738
764
  return archetypes;
739
765
  }
740
766
 
741
- private static detectLanguage(projectRoot: string): DiscoveredProjectTopology["language"] {
742
- if (
743
- fs.existsSync(path.join(projectRoot, "composer.json")) ||
744
- fs.existsSync(path.join(projectRoot, "artisan"))
745
- ) {
746
- return "php";
747
- }
748
- if (fs.existsSync(path.join(projectRoot, "go.mod"))) return "go";
749
- if (
750
- fs.existsSync(path.join(projectRoot, "pyproject.toml")) ||
751
- fs.existsSync(path.join(projectRoot, "requirements.txt"))
752
- ) {
753
- return "python";
754
- }
755
- if (
756
- fs.existsSync(path.join(projectRoot, "tsconfig.json")) ||
757
- fs.existsSync(path.join(projectRoot, "package.json"))
758
- ) {
759
- return "typescript";
760
- }
761
- return "generic";
767
+ private static detectLanguage(projectRoot: string): DetectedLanguage {
768
+ return detectProjectLanguage(projectRoot);
762
769
  }
763
770
 
764
771
  private static detectFramework(
765
772
  projectRoot: string,
766
- language: DiscoveredProjectTopology["language"]
773
+ language: DetectedLanguage
767
774
  ): string {
768
- if (language === "php") {
769
- if (fs.existsSync(path.join(projectRoot, "artisan"))) return "laravel";
770
- if (
771
- fs.existsSync(path.join(projectRoot, "bin/console")) ||
772
- fs.existsSync(path.join(projectRoot, "symfony.lock"))
773
- ) {
774
- return "symfony";
775
- }
776
- const composerJson = path.join(projectRoot, "composer.json");
777
- if (fs.existsSync(composerJson)) {
778
- try {
779
- const composer = JSON.parse(fs.readFileSync(composerJson, "utf-8"));
780
- const reqs = { ...(composer.require ?? {}), ...(composer["require-dev"] ?? {}) };
781
- if (reqs["symfony/framework-bundle"] || reqs["symfony/symfony"]) {
782
- return "symfony";
783
- }
784
- } catch {}
785
- }
786
- return "generic-php";
787
- }
788
- if (language === "typescript" || language === "javascript") {
789
- const pkgJson = path.join(projectRoot, "package.json");
790
- try {
791
- if (fs.existsSync(pkgJson)) {
792
- const pkg = JSON.parse(fs.readFileSync(pkgJson, "utf-8"));
793
- const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
794
- if (allDeps.next) return "nextjs";
795
- if (allDeps.nuxt) return "nuxt";
796
- if (allDeps.astro) return "astro";
797
- if (allDeps.vue) return "vue";
798
- if (allDeps["@nestjs/core"]) return "nestjs";
799
- if (allDeps.express) return "express";
800
- if (allDeps.fastify) return "fastify";
801
- if (allDeps.hono) return "hono";
802
- if (allDeps.elysia) return "elysia";
803
- if (allDeps["@modelcontextprotocol/sdk"]) return "mcp-server";
804
- }
805
- } catch (err: unknown) {
806
- const msg = err instanceof Error ? err.message : String(err);
807
- console.warn(`[Septum Topology] Failed to inspect dependencies in ${pkgJson}: ${msg}`);
808
- }
809
- return "generic-node";
810
- }
811
- if (language === "python") {
812
- if (
813
- fs.existsSync(path.join(projectRoot, "manage.py")) ||
814
- fs.existsSync(path.join(projectRoot, "wsgi.py")) ||
815
- fs.existsSync(path.join(projectRoot, "asgi.py"))
816
- ) {
817
- return "django";
818
- }
819
- const readSafe = (p: string) => {
820
- try {
821
- return fs.existsSync(p) ? fs.readFileSync(p, "utf-8").toLowerCase() : "";
822
- } catch {
823
- return "";
824
- }
825
- };
826
- const deps =
827
- readSafe(path.join(projectRoot, "requirements.txt")) +
828
- " " +
829
- readSafe(path.join(projectRoot, "pyproject.toml")) +
830
- " " +
831
- readSafe(path.join(projectRoot, "Pipfile"));
832
- if (deps.includes("fastapi")) return "fastapi";
833
- if (deps.includes("django")) return "django";
834
- if (deps.includes("flask")) return "flask";
835
- return "generic-python";
836
- }
837
- if (language === "go") {
838
- const goModPath = path.join(projectRoot, "go.mod");
839
- if (fs.existsSync(goModPath)) {
840
- try {
841
- const modContent = fs.readFileSync(goModPath, "utf-8").toLowerCase();
842
- if (modContent.includes("github.com/gin-gonic/gin")) return "gin";
843
- if (modContent.includes("github.com/labstack/echo")) return "echo";
844
- if (modContent.includes("github.com/go-chi/chi")) return "chi";
845
- if (modContent.includes("github.com/gofiber/fiber")) return "fiber";
846
- } catch {}
847
- }
848
- return "generic-go";
849
- }
850
- return "generic";
775
+ return detectProjectFramework(projectRoot, language);
851
776
  }
852
777
 
853
778
  private static getSubdirectories(dir: string): string[] {