@dimassetoid/septum-mcp 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +46 -28
  2. package/package.json +4 -4
  3. package/src/cli/commands/check.ts +27 -16
  4. package/src/cli/commands/hook.ts +38 -101
  5. package/src/cli/commands/init.ts +26 -9
  6. package/src/cli/commands/sync.ts +4 -6
  7. package/src/cli/hook-payload.ts +43 -0
  8. package/src/cli/index.ts +9 -52
  9. package/src/cli/scaffold/harness-config.ts +48 -8
  10. package/src/cli/templates/hooks.ts +49 -14
  11. package/src/cli/templates/rules.ts +34 -49
  12. package/src/cli/templates/skill.ts +39 -35
  13. package/src/core/boundary/evaluator.ts +67 -83
  14. package/src/core/boundary/staged-auditor.ts +102 -40
  15. package/src/core/config/domain-ownership.ts +45 -0
  16. package/src/core/config/loader.ts +81 -29
  17. package/src/core/config/schema.ts +0 -10
  18. package/src/core/database/repositories/dependency.repository.ts +169 -148
  19. package/src/core/database/repositories/domain.repository.ts +46 -3
  20. package/src/core/database/repositories/symbol.repository.ts +226 -87
  21. package/src/core/database/repository.ts +73 -18
  22. package/src/core/database/schema.ts +2 -33
  23. package/src/core/discovery/navigation.ts +105 -0
  24. package/src/core/discovery/topology-detector.ts +60 -2
  25. package/src/core/ingestion/pipeline.ts +96 -129
  26. package/src/core/parser/behavioral-analyzer.ts +26 -22
  27. package/src/core/parser/boundary-tracker.ts +15 -0
  28. package/src/core/parser/extractors/base.ts +7 -3
  29. package/src/core/parser/extractors/csharp.ts +7 -3
  30. package/src/core/parser/extractors/django-semantic.ts +4 -36
  31. package/src/core/parser/extractors/elysia-semantic.ts +3 -24
  32. package/src/core/parser/extractors/express-semantic.ts +3 -18
  33. package/src/core/parser/extractors/fastapi-semantic.ts +19 -53
  34. package/src/core/parser/extractors/fastify-semantic.ts +3 -18
  35. package/src/core/parser/extractors/flask-semantic.ts +22 -55
  36. package/src/core/parser/extractors/go-semantic.ts +92 -33
  37. package/src/core/parser/extractors/hono-semantic.ts +3 -24
  38. package/src/core/parser/extractors/java.ts +5 -3
  39. package/src/core/parser/extractors/laravel-semantic.ts +44 -16
  40. package/src/core/parser/extractors/mcp-cli-semantic.ts +6 -7
  41. package/src/core/parser/extractors/nestjs-semantic.ts +3 -19
  42. package/src/core/parser/extractors/php.ts +16 -0
  43. package/src/core/parser/extractors/python.ts +9 -4
  44. package/src/core/parser/extractors/registry.ts +26 -5
  45. package/src/core/parser/extractors/ruby.ts +8 -5
  46. package/src/core/parser/extractors/rust.ts +31 -13
  47. package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
  48. package/src/core/parser/extractors/symfony-semantic.ts +4 -37
  49. package/src/core/parser/extractors/typescript.ts +14 -1
  50. package/src/core/parser/implementation-fingerprint.ts +97 -0
  51. package/src/core/parser/language-capabilities.ts +23 -7
  52. package/src/core/parser/schema/providers/laravel-migration-provider.ts +73 -50
  53. package/src/core/parser/schema/schema-provider-registry.ts +1 -3
  54. package/src/core/parser/schema/schema-provider.interface.ts +2 -1
  55. package/src/core/parser/semantic-revision.ts +3 -0
  56. package/src/core/parser/static-string.ts +51 -0
  57. package/src/core/resolver/call-graph-tracer.ts +337 -28
  58. package/src/core/resolver/import-resolver.ts +107 -179
  59. package/src/core/resolver/interpretation-inputs.ts +7 -0
  60. package/src/core/resolver/languages/go.ts +103 -0
  61. package/src/core/resolver/languages/managed.ts +200 -0
  62. package/src/core/resolver/languages/python.ts +115 -0
  63. package/src/core/resolver/languages/ruby.ts +40 -0
  64. package/src/core/resolver/languages/rust.ts +127 -0
  65. package/src/core/resolver/languages/shared.ts +71 -0
  66. package/src/core/resolver/module-resolver.ts +8 -4
  67. package/src/core/resolver/slice-catalog.ts +79 -0
  68. package/src/core/resolver/slice-format.ts +9 -0
  69. package/src/core/resolver/symbol-impact.ts +381 -0
  70. package/src/core/resolver/vertical-slice-tracer.ts +93 -115
  71. package/src/core/resources/ignore.ts +22 -1
  72. package/src/core/resources/source-files.ts +143 -20
  73. package/src/core/resources/source-inventory.ts +55 -0
  74. package/src/core/retrieval/context-page.ts +109 -0
  75. package/src/core/retrieval/context.ts +320 -0
  76. package/src/core/retrieval/resolution-warnings.ts +21 -0
  77. package/src/core/retrieval/symbol-evidence.ts +97 -0
  78. package/src/core/retrieval/typescript-references.ts +262 -0
  79. package/src/core/telemetry/telemetry.ts +54 -9
  80. package/src/index.ts +0 -3
  81. package/src/mcp/schemas.ts +61 -420
  82. package/src/mcp/server.ts +116 -290
  83. package/src/mcp/tools/boundary.ts +2 -2
  84. package/src/mcp/tools/check-boundary.ts +55 -60
  85. package/src/mcp/tools/get-domain-catalog.ts +32 -219
  86. package/src/mcp/tools/get-symbol-impact.ts +45 -5
  87. package/src/mcp/tools/get-symbol.ts +227 -3
  88. package/src/mcp/tools/locate-symbol.ts +54 -14
  89. package/src/mcp/tools/{domain.ts → map.ts} +4 -18
  90. package/src/mcp/tools/register-domain.ts +41 -3
  91. package/src/mcp/tools/symbol.ts +23 -21
  92. package/src/mcp/tools/trace-vertical-slice.ts +36 -10
  93. package/src/mcp/workspace-manager.ts +15 -4
  94. package/src/mcp/workspace-watcher.ts +8 -8
  95. package/src/types/index.ts +35 -53
  96. package/src/cli/commands/topology.ts +0 -161
  97. package/src/core/database/repositories/environment.repository.ts +0 -207
  98. package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
  99. package/src/core/session/session-manager.ts +0 -107
  100. package/src/core/topology/environment-detector.ts +0 -973
  101. package/src/core/topology/types.ts +0 -83
  102. package/src/mcp/tools/feature.ts +0 -67
  103. package/src/mcp/tools/get-environment-topology.ts +0 -138
  104. package/src/mcp/tools/get-feature-context.ts +0 -224
  105. package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
  106. package/src/mcp/tools/register-feature.ts +0 -110
@@ -2,7 +2,7 @@ import type { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
2
2
  import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
3
3
  import type { SeptumRepository } from "../../core/database/repository.ts";
4
4
  import type { BoundaryToolArgs } from "../schemas.ts";
5
- import { handleCheckBoundary } from "./check-boundary.ts";
5
+ import { evaluateBoundary } from "./check-boundary.ts";
6
6
 
7
7
  export type { BoundaryToolArgs };
8
8
 
@@ -13,5 +13,5 @@ export async function handleBoundaryTool(
13
13
  repo?: SeptumRepository,
14
14
  workspaceRoot?: string
15
15
  ) {
16
- return await handleCheckBoundary(evaluator, config, args as any, repo, workspaceRoot);
16
+ return await evaluateBoundary(evaluator, config, args, repo, workspaceRoot);
17
17
  }
@@ -6,7 +6,6 @@ import { auditStagedFiles } from "../../core/boundary/staged-auditor.ts";
6
6
  import type { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
7
7
  import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
8
8
  import type { SeptumRepository } from "../../core/database/repository.ts";
9
- import { SessionManager } from "../../core/session/session-manager.ts";
10
9
  import type { BoundaryViolation } from "../../types/index.ts";
11
10
  import { CheckBoundarySchema, type CheckBoundaryArgs } from "../schemas.ts";
12
11
 
@@ -15,41 +14,32 @@ export type { CheckBoundaryArgs } from "../schemas.ts";
15
14
  export async function handleCheckBoundary(
16
15
  evaluator: BoundaryEvaluator,
17
16
  config: ValidatedSeptumConfig,
18
- rawArgs: CheckBoundaryArgs & Record<string, unknown>,
17
+ rawArgs: unknown,
18
+ repo?: SeptumRepository,
19
+ workspaceRoot?: string
20
+ ) {
21
+ return evaluateBoundary(evaluator, config, CheckBoundarySchema.parse(rawArgs ?? {}), repo, workspaceRoot);
22
+ }
23
+
24
+ export async function evaluateBoundary(
25
+ evaluator: BoundaryEvaluator,
26
+ config: ValidatedSeptumConfig,
27
+ args: CheckBoundaryArgs,
19
28
  repo?: SeptumRepository,
20
29
  workspaceRoot?: string
21
30
  ) {
22
- const args = CheckBoundarySchema.parse(rawArgs ?? {});
23
31
  if (args.domain) {
24
- const domain = Object.keys(config.domains || {}).find(name => name.toLowerCase() === args.domain!.toLowerCase());
32
+ const knownDomains = new Set([
33
+ ...Object.keys(config.domains || {}),
34
+ ...(repo?.getAllDomains?.().map((d) => d.name) ?? []),
35
+ ]);
36
+ const domain = [...knownDomains].find(name => name.toLowerCase() === args.domain!.toLowerCase());
25
37
  if (!domain) throw new Error(`Unknown boundary domain '${args.domain}'. Choose a registered domain.`);
26
38
  args.domain = domain;
27
39
  }
28
40
  const root = workspaceRoot || args.workspace_path || process.cwd();
29
41
  const proposedImports = args.proposed_imports ?? [];
30
-
31
- const activeSession = SessionManager.getActiveSession(root);
32
-
33
- let effectiveFeatureKey = args.feature_key;
34
- if (activeSession) {
35
- if (args.feature_key && args.feature_key !== activeSession.feature_key) {
36
- throw new Error(
37
- `Active feature lock is '${activeSession.feature_key}' (owner: ${activeSession.owner_id}). Cannot check boundaries for different feature '${args.feature_key}' while another feature is locked.`
38
- );
39
- }
40
- effectiveFeatureKey = activeSession.feature_key;
41
- if (!config.features) config.features = {};
42
- if (!config.features[activeSession.feature_key]) {
43
- config.features[activeSession.feature_key] = {
44
- domain: activeSession.domain,
45
- description: `Active session: ${activeSession.feature_key}`,
46
- allowed_touchpoints: activeSession.touchpoints,
47
- reuse_symbols: [],
48
- input_contract: {},
49
- output_contract: {},
50
- };
51
- }
52
- }
42
+ const evaluatedScope = { mode: "proposal", proposed_imports_supplied: args.proposed_imports_supplied, existing_imports_checked: false, omissions: ["Existing file imports are not certified by proposal approval."] };
53
43
 
54
44
  const syncState = repo?.getMeta("sync_state");
55
45
  const syncError = repo?.getMeta("sync_error");
@@ -95,14 +85,24 @@ export async function handleCheckBoundary(
95
85
  }).map(file => file.path) : [];
96
86
  const relationships = repo.getImportRelationships(root).filter(edge => relevant(edge.source.file));
97
87
  const incomplete = relationships.filter(edge => edge.index_coverage === "partial" || edge.freshness !== "current" || !["resolved","external"].includes(edge.resolution.status) || edge.resolution.coverage === "conditional" || edge.target_domains.length > 1);
98
- const proposed = requested.flatMap(file => proposedImports.map(target => evaluator.getResolver().resolveImport(target,file)))
99
- .filter(result => !["resolved","external"].includes(result.status) || result.coverage === "conditional");
88
+ const allProposed = requested.flatMap(file => proposedImports.map(target => evaluator.getResolver().resolveImport(target, file)));
89
+ const proposed = allProposed.filter(result => !["resolved", "external"].includes(result.status) || result.coverage === "conditional");
100
90
  if (incomplete.length || proposed.length || staleFiles.length) {
101
91
  const known = evaluator.auditCodebase(config).filter(violation => relevant(violation.file));
102
- known.push(...requested.flatMap(file => evaluator.evaluate(file,proposedImports,effectiveFeatureKey,config)));
92
+ known.push(...requested.flatMap(file => evaluator.evaluate(file, proposedImports, config)));
103
93
  return { content: [{ type: "text" as const, text: JSON.stringify({
104
94
  status: known.length ? "rejected" : "unknown", violations: known, total_violations: known.length,
105
- circular_dependencies: known.filter(v => v.rule === "circular_dependency"), circular_dependencies_count: known.filter(v => v.rule === "circular_dependency").length, relationships: incomplete, proposed_resolutions: proposed,
95
+ circular_dependencies: known.filter(v => v.rule === "circular_dependency"), circular_dependencies_count: known.filter(v => v.rule === "circular_dependency").length,
96
+ relationships: incomplete.slice(0, 10), proposed_resolutions: allProposed,
97
+ diagnostic_accounting: { total: incomplete.length, returned: Math.min(10, incomplete.length), omitted: Math.max(0, incomplete.length - 10) },
98
+ incomplete_reasons: {
99
+ target_not_fully_indexed: incomplete.filter(edge => edge.index_coverage === "partial").length,
100
+ stale_source: incomplete.filter(edge => edge.freshness !== "current").length,
101
+ unresolved_or_unsupported: incomplete.filter(edge => !["resolved", "external"].includes(edge.resolution.status)).length,
102
+ conditional_resolution: incomplete.filter(edge => edge.resolution.coverage === "conditional").length,
103
+ multiple_domains: incomplete.filter(edge => edge.target_domains.length > 1).length,
104
+ },
105
+ next: ["Inspect the listed source imports; register/index uncovered target roots or narrow scope to a file/domain. Unknown is not approval."],
106
106
  stale_files: staleFiles,
107
107
  message: "Relevant import resolution is incomplete; an empty graph cannot prove boundary approval.",
108
108
  }) }] };
@@ -126,7 +126,7 @@ export async function handleCheckBoundary(
126
126
  args.scope ?? (args.staged ? "staged" : args.domain ? "domain" : "all");
127
127
 
128
128
  if (effectiveScope === "staged") {
129
- const { files: stagedFiles, violations: stagedViolations, resolution_issues: resolutionIssues } = await auditStagedFiles(evaluator, config, root, effectiveFeatureKey, repo);
129
+ const { files: stagedFiles, violations: stagedViolations, resolution_issues: resolutionIssues } = await auditStagedFiles(evaluator, config, root, repo);
130
130
 
131
131
  if (stagedFiles.length === 0 && stagedViolations.length === 0) {
132
132
  return {
@@ -196,25 +196,6 @@ export async function handleCheckBoundary(
196
196
  }
197
197
 
198
198
  // Scope: "all" or "domain"
199
- if (args.feature_key) {
200
- return {
201
- content: [
202
- {
203
- type: "text" as const,
204
- text: JSON.stringify(
205
- {
206
- status: "rejected",
207
- scope: effectiveScope,
208
- message: `Scope '${effectiveScope}' is an architectural audit across domains and does not support feature touchpoint validation ('feature_key'). Feature scopes only apply to 'file', 'batch', or 'staged'.`,
209
- },
210
- null,
211
- 2
212
- ),
213
- },
214
- ],
215
- };
216
- }
217
-
218
199
  let violations = evaluator.auditCodebase(config);
219
200
  if (args.domain) {
220
201
  const targetDom = args.domain.toLowerCase();
@@ -234,6 +215,11 @@ export async function handleCheckBoundary(
234
215
 
235
216
  const hasViolations = violations.length > 0;
236
217
  const domainCount = Object.keys(config?.domains || {}).length;
218
+ const allIndexedFiles = repo && typeof repo.getAllFiles === "function" ? repo.getAllFiles() : [];
219
+ const domainFileCount = args.domain && allIndexedFiles.length > 0
220
+ ? allIndexedFiles.filter((f) => evaluator.resolveSourceDomain(f.path, config) === args.domain).length
221
+ : null;
222
+ const emptyScopedDomain = Boolean(args.domain && domainFileCount === 0);
237
223
 
238
224
  return {
239
225
  content: [
@@ -241,7 +227,7 @@ export async function handleCheckBoundary(
241
227
  type: "text" as const,
242
228
  text: JSON.stringify(
243
229
  {
244
- status: hasViolations ? "rejected" : "approved",
230
+ status: hasViolations ? "rejected" : emptyScopedDomain ? "unknown" : "approved",
245
231
  scope: args.domain ? "domain" : "all",
246
232
  ...(args.domain ? { domain: args.domain } : {}),
247
233
  total_domains_checked: domainCount,
@@ -254,8 +240,10 @@ export async function handleCheckBoundary(
254
240
  ? `${violations.length} boundary violation(s) (${circularDependencies.length} circular) detected${
255
241
  args.domain ? ` in domain '${args.domain}'` : " across codebase"
256
242
  }.`
243
+ : emptyScopedDomain
244
+ ? `Boundary check is incomplete: domain '${args.domain}' has 0 indexed files (it may be unindexed or shadowed by a parent domain).`
257
245
  : domainCount === 0
258
- ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_domain' with action='register' to initialize bounded contexts.]"
246
+ ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]"
259
247
  : `All domain boundaries are clean${
260
248
  args.domain ? ` for domain '${args.domain}'` : ""
261
249
  }. Zero cross-domain leaks or circular dependencies detected.`,
@@ -271,10 +259,11 @@ export async function handleCheckBoundary(
271
259
  // Multi-file batch evaluation
272
260
  if (filesToCheck.length > 1) {
273
261
  const results = filesToCheck.map((filePath) => {
274
- const violations = evaluator.evaluate(filePath, proposedImports, effectiveFeatureKey, config);
262
+ const violations = evaluator.evaluate(filePath, proposedImports, config);
275
263
  const impact = repo?.getFileInboundImpact(filePath);
276
264
  return {
277
265
  file: filePath,
266
+ evaluated_scope: evaluatedScope,
278
267
  status: violations.length > 0 ? "rejected" : "approved",
279
268
  violations,
280
269
  impact_summary: impact
@@ -304,7 +293,7 @@ export async function handleCheckBoundary(
304
293
  message: hasViolations
305
294
  ? `${totalViolations} boundary violation(s) detected across ${filesToCheck.length} file(s).`
306
295
  : Object.keys(config?.domains || {}).length === 0
307
- ? `All ${filesToCheck.length} file(s) approved. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_domain' with action='register' to initialize bounded contexts.]`
296
+ ? `All ${filesToCheck.length} file(s) approved. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]`
308
297
  : `All ${filesToCheck.length} file(s) approved. No boundary violations detected.`,
309
298
  },
310
299
  null,
@@ -317,8 +306,9 @@ export async function handleCheckBoundary(
317
306
 
318
307
  // Single file evaluation (backward-compatible output)
319
308
  const singleFile = filesToCheck[0];
320
- const violations = evaluator.evaluate(singleFile, proposedImports, effectiveFeatureKey, config);
309
+ const violations = evaluator.evaluate(singleFile, proposedImports, config);
321
310
  const impact = repo?.getFileInboundImpact(singleFile);
311
+ const enforcementMode = config?.settings?.enforcement ?? "strict";
322
312
 
323
313
  if (violations.length > 0) {
324
314
  return {
@@ -328,7 +318,9 @@ export async function handleCheckBoundary(
328
318
  text: JSON.stringify(
329
319
  {
330
320
  status: "rejected",
321
+ enforcement_mode: enforcementMode,
331
322
  file: singleFile,
323
+ evaluated_scope: evaluatedScope,
332
324
  violations_count: violations.length,
333
325
  violations,
334
326
  impact_summary: impact
@@ -341,7 +333,7 @@ export async function handleCheckBoundary(
341
333
  : undefined,
342
334
  message:
343
335
  Object.keys(config?.domains || {}).length === 0
344
- ? "Boundary integrity check failed: Domain catalog is currently unindexed. Run 'septum_domain' with action='register' to initialize bounded contexts."
336
+ ? "Boundary integrity check failed: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts."
345
337
  : violations.some((v) => v.rule === "unmapped_domain")
346
338
  ? "Boundary integrity check failed: File does not belong to any declared bounded context."
347
339
  : "Boundary violation detected. Proposed imports violate bounded context architecture.",
@@ -361,7 +353,9 @@ export async function handleCheckBoundary(
361
353
  text: JSON.stringify(
362
354
  {
363
355
  status: "approved",
356
+ enforcement_mode: enforcementMode,
364
357
  file: singleFile,
358
+ evaluated_scope: evaluatedScope,
365
359
  impact_summary: impact
366
360
  ? {
367
361
  direct_dependents: impact.direct_dependents_count,
@@ -372,10 +366,12 @@ export async function handleCheckBoundary(
372
366
  : undefined,
373
367
  message:
374
368
  Object.keys(config?.domains || {}).length === 0
375
- ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_domain' with action='register' to initialize bounded contexts.]"
369
+ ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_map' with action='register' to initialize bounded contexts.]"
370
+ : enforcementMode === "warn"
371
+ ? "Approved under 'warn' enforcement (unlisted allowed_dependencies are not blocked; only explicit forbidden_dependencies are rejected)."
376
372
  : impact && impact.direct_dependents_count > 0
377
373
  ? `No boundary violations detected. Caution: ${impact.direct_dependents_count} dependent file(s) consume this file.`
378
- : "No boundary violations detected. Proposed imports are permissible.",
374
+ : "Proposal approved. Existing file imports were not audited.",
379
375
  },
380
376
  null,
381
377
  2
@@ -384,4 +380,3 @@ export async function handleCheckBoundary(
384
380
  ],
385
381
  };
386
382
  }
387
-
@@ -1,226 +1,39 @@
1
- import { RESOLVER_REVISION } from "../../core/resolver/import-resolver.ts";
2
- import { getParserCapabilities } from "../../core/parser/language-capabilities.ts";
3
- import { SemanticSliceExtractorRegistry } from "../../core/parser/extractors/registry.ts";
4
- import * as fs from "node:fs";
5
- import * as path from "node:path";
6
- import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
7
- import type { SeptumRepository } from "../../core/database/repository.ts";
8
- import type { DomainCatalogResponse } from "../../types/index.ts";
9
- import type { GetDomainCatalogArgs } from "../schemas.ts";
10
- import { checkRuntimeVersion, getCachedRuntimeVersion } from "../../utils/version-check.ts";
11
-
12
- export type { GetDomainCatalogArgs } from "../schemas.ts";
13
-
14
- export function handleGetDomainCatalog(
15
- repo: SeptumRepository,
16
- config: ValidatedSeptumConfig,
17
- args: GetDomainCatalogArgs,
18
- workspaceRoot?: string
19
- ) {
20
- const targetRoot = args.workspace_path || workspaceRoot || (repo as any)?.projectRoot || process.cwd();
21
- const domainName = args.domain ?? args.name;
22
- const runtimeVersion = getCachedRuntimeVersion();
23
- // Non-blocking background version refresh if needed
24
- void checkRuntimeVersion().catch(() => {});
25
- const parserCapabilities = {
26
- ...getParserCapabilities(args.detail_level === "full"),
27
- analysis_contracts: { foundation_revision: "1", resolver_revision: RESOLVER_REVISION, relationships: "imports-v1", semantic_lifecycle: "async-v1" },
28
- semantic_adapters: args.detail_level === "full"
29
- ? SemanticSliceExtractorRegistry.getCapabilities()
30
- : SemanticSliceExtractorRegistry.getCapabilities().map(adapter => adapter.id),
31
- semantic_limits: "Registered adapters cover selected static patterns; registration does not prove applicability, AST backing, complete routes or runtime calls.",
32
- };
33
- const isDirty = repo.getMeta("slices_dirty") === "1";
34
- const indexStatus = {
35
- runtime_version: runtimeVersion,
36
- unsupported_files: JSON.parse(repo.getMeta("unsupported_files") || "[]"),
37
- watcher_mode: repo.getMeta("watcher_mode") || "manual",
38
- sync_state: repo.getMeta("sync_state") || "unknown",
39
- sync_needed: isDirty,
40
- skipped_files: JSON.parse(repo.getMeta("skipped_files") || "[]"),
41
- };
42
-
43
- if (!domainName) {
44
- const allDomains = repo.getAllDomains();
45
- if (allDomains.length === 0) {
46
- const root = targetRoot;
47
- let agentGuidance =
48
- "Panggil tool 'septum_domain(action: \"register\", name: \"core\", root: \"src\", ingest_now: true)' untuk mendaftarkan dan mengindeks domain utama secara otomatis, atau jalankan 'septum init' di terminal workspace.";
49
- if (runtimeVersion.update_available) {
50
- agentGuidance += ` Update available: v${runtimeVersion.server_version} -> v${runtimeVersion.latest_version}. Recommend running '${runtimeVersion.upgrade_command}' and reloading the MCP server if schema/features differ.`;
51
- }
52
- const diagnostic = {
53
- status: "NOT_INDEXED",
54
- parser_capabilities: parserCapabilities,
55
- total_domains: 0,
56
- runtime_version: runtimeVersion,
57
- message: `Workspace '${root}' belum memiliki domain terdaftar dalam Septum catalog.`,
58
- suggested_action: {
59
- tool: "septum_domain",
60
- params: {
61
- action: "register",
62
- name: "core",
63
- root: "src",
64
- ingest_now: true,
65
- },
66
- },
67
- agent_guidance: agentGuidance,
68
- ...(runtimeVersion.update_available
69
- ? {
70
- agent_instruction: `Update available: v${runtimeVersion.server_version} -> v${runtimeVersion.latest_version}. Recommend running '${runtimeVersion.upgrade_command}' and reloading the MCP server if schema/features differ.`,
71
- }
72
- : {}),
73
- };
74
- return {
75
- content: [
76
- {
77
- type: "text" as const,
78
- text: JSON.stringify(diagnostic, null, 2),
79
- },
80
- ],
81
- metadata: diagnostic,
82
- runtime_version: runtimeVersion,
83
- };
84
- }
85
-
86
- const projectType = repo.getMeta("project_type") || "generic";
87
- const framework = repo.getMeta("framework") || "unknown";
88
- const archStyle = repo.getMeta("architecture_style") || "modular";
89
- const totalSlices =
90
- typeof (repo as any).countVerticalSlices === "function"
91
- ? (repo as any).countVerticalSlices()
92
- : repo.getAllVerticalSlices().length;
93
-
94
- let agentInstruction =
95
- "Macro semantic map loaded from SQLite SSOT. Use 'septum_domain' with domain='<name>' for granular file/symbol catalogs, or 'septum_slice' with query='<route|command|intent>' for end-to-end execution flow.";
96
- if (isDirty) {
97
- agentInstruction += " Notice: Index has pending or unsynchronized file changes. Run 'septum sync' to ensure all symbol coordinates and call graphs are fully refreshed.";
98
- }
99
- if (runtimeVersion.update_available) {
100
- agentInstruction += ` Update available: v${runtimeVersion.server_version} -> v${runtimeVersion.latest_version}. Recommend running '${runtimeVersion.upgrade_command}' and reloading the MCP server if schema/features differ.`;
101
- }
102
-
103
- const macroMap = {
104
- parser_capabilities: parserCapabilities,
105
- runtime_version: runtimeVersion,
106
- index_status: indexStatus,
107
- telescope_view: {
108
- project_type: projectType,
109
- framework,
110
- architecture_style: archStyle,
111
- total_domains: allDomains.length,
112
- total_vertical_slices: totalSlices,
113
- scanned_folders: JSON.parse(repo.getMeta("scanned_folders") || "[]"),
114
- ignored_folders: JSON.parse(repo.getMeta("ignored_folders") || "[]"),
115
- },
116
- domains: allDomains.map((d) => ({
117
- name: d.name,
118
- root: d.root_path,
119
- archetypes: Object.keys(JSON.parse(d.archetypes_json || "{}")),
120
- allowed_dependencies: JSON.parse(d.allowed_deps_json || "[]"),
121
- forbidden_dependencies: JSON.parse(d.forbidden_deps_json || "[]"),
122
- })),
123
- agent_instruction: agentInstruction,
124
- };
125
-
126
- return {
127
- content: [
128
- {
129
- type: "text" as const,
130
- text: JSON.stringify(macroMap, null, 2),
131
- },
132
- ],
133
- metadata: { runtime_version: runtimeVersion },
134
- runtime_version: runtimeVersion,
135
- };
1
+ import { buildNavigation, NAVIGATION_SCHEMA } from '../../core/discovery/navigation.ts';
2
+ import { getParserCapabilities } from '../../core/parser/language-capabilities.ts';
3
+ import { SemanticSliceExtractorRegistry } from '../../core/parser/extractors/registry.ts';
4
+ import type { ValidatedSeptumConfig } from '../../core/config/schema.ts';
5
+ import type { SeptumRepository } from '../../core/database/repository.ts';
6
+ import type { GetDomainCatalogArgs } from '../schemas.ts';
7
+ import { getCachedRuntimeVersion, type RuntimeVersionMeta } from '../../utils/version-check.ts';
8
+
9
+ export type { GetDomainCatalogArgs };
10
+
11
+ export function buildDomainCatalog(repo: SeptumRepository, _config: ValidatedSeptumConfig, args: GetDomainCatalogArgs,
12
+ workspaceRoot?: string, runtimeVersion: RuntimeVersionMeta = getCachedRuntimeVersion()) {
13
+ const root = workspaceRoot ?? args.workspace_path ?? repo.getMeta('workspace_root') ?? process.cwd();
14
+ const navigation = buildNavigation(repo, args, root);
15
+ if (args.include_evidence && (!args.file_filter || !('files' in navigation) || navigation.files.length !== 1 || navigation.accounting.matching_files !== 1)) {
16
+ throw new Error('include_evidence requires file_filter matching exactly one indexed file.');
136
17
  }
137
-
138
- const archetypeFilter = args.archetype_filter ?? args.archetype;
139
- const detailLevel = args.detail_level ?? "compact";
140
- const fileFilter = args.file_filter;
141
-
142
- const catalog: DomainCatalogResponse | null = (repo.getDomainCatalog as any)(
143
- domainName,
144
- archetypeFilter,
145
- { detailLevel, fileFilter, workspaceRoot: targetRoot }
146
- );
147
- if (!catalog) {
148
- const available = Object.keys(config.domains || {});
149
- const suggestions = available.filter((d) =>
150
- d.toLowerCase().includes(domainName.toLowerCase()) ||
151
- domainName.toLowerCase().includes(d.toLowerCase())
152
- );
153
- const notFoundPayload: Record<string, any> = {
154
- status: "not_found",
155
- parser_capabilities: parserCapabilities,
156
- found: false,
157
- domain: domainName,
158
- runtime_version: runtimeVersion,
159
- message: `Domain '${domainName}' not found in Septum catalog.`,
160
- available_domains: available,
161
- suggestions: suggestions.length > 0 ? suggestions : available,
162
- suggested_action: {
163
- tool: "septum_domain",
164
- params: { action: "register", domain: domainName, root: `src/domains/${domainName}` },
165
- },
166
- };
167
- if (runtimeVersion.update_available) {
168
- notFoundPayload.agent_instruction = `Update available: v${runtimeVersion.server_version} -> v${runtimeVersion.latest_version}. Recommend running '${runtimeVersion.upgrade_command}' and reloading the MCP server if schema/features differ.`;
169
- }
170
- return {
171
- content: [
172
- {
173
- type: "text" as const,
174
- text: JSON.stringify(notFoundPayload, null, 2),
175
- },
176
- ],
177
- metadata: notFoundPayload,
178
- runtime_version: runtimeVersion,
179
- };
180
- }
181
-
182
- // Record access log for Gate 3 (Mandatory Catalog Consultation)
183
- recordCatalogAccess(domainName, targetRoot);
184
-
185
- const catalogPayload: Record<string, any> = {
186
- ...catalog,
187
- ...(args.detail_level === "full" ? { relationships: repo.getImportRelationships(targetRoot).filter(edge => catalog.files.some(file => file.path === edge.source.file)) } : {}),
188
- parser_capabilities: parserCapabilities,
18
+ const evidence = args.include_evidence && 'files' in navigation
19
+ ? repo.getImportRelationships(root, navigation.files[0]!.path) : [];
20
+ return { ...navigation,
21
+ ...(args.include_capabilities ? { parser_capabilities: { ...getParserCapabilities(args.detail_level === 'full'), semantic_adapters: SemanticSliceExtractorRegistry.getCapabilities() } } : {}),
22
+ ...(args.include_evidence ? { evidence: evidence.slice(0, 20), evidence_accounting: { total: evidence.length, returned: Math.min(20, evidence.length), omitted: Math.max(0, evidence.length - 20) } } : {}),
189
23
  runtime_version: runtimeVersion,
190
- index_status: indexStatus,
24
+ ...(runtimeVersion.update_available ? { update_notice: `Update available: ${runtimeVersion.latest_version}; ${runtimeVersion.upgrade_command}. Reload after updating.` } : {}),
191
25
  };
192
- if (runtimeVersion.update_available) {
193
- catalogPayload.agent_instruction = `Update available: v${runtimeVersion.server_version} -> v${runtimeVersion.latest_version}. Recommend running '${runtimeVersion.upgrade_command}' and reloading the MCP server if schema/features differ.`;
194
- }
26
+ }
195
27
 
196
- // Compact catalogs omit per-language capability details.
197
- return {
198
- content: [
199
- {
200
- type: "text" as const,
201
- text: JSON.stringify(catalogPayload, null, 2),
202
- },
203
- ],
204
- metadata: { runtime_version: runtimeVersion },
205
- runtime_version: runtimeVersion,
206
- };
28
+ export function handleGetDomainCatalog(repo: SeptumRepository, config: ValidatedSeptumConfig, args: GetDomainCatalogArgs, workspaceRoot?: string) {
29
+ const payload = buildDomainCatalog(repo, config, args, workspaceRoot);
30
+ return { content: [{ type: 'text' as const, text: JSON.stringify(payload) }], metadata: { schema: payload.schema, status: payload.status }, runtime_version: payload.runtime_version };
207
31
  }
208
32
 
209
- function recordCatalogAccess(domain: string, projectRoot: string = process.cwd()): void {
210
- try {
211
- const septumDir = path.resolve(projectRoot, ".septum");
212
- if (!fs.existsSync(septumDir)) {
213
- return;
214
- }
215
- const logPath = path.join(septumDir, "catalog_access.json");
216
- let log: { domains?: Record<string, string>; features?: Record<string, string> } = {};
217
- if (fs.existsSync(logPath)) {
218
- try {
219
- log = JSON.parse(fs.readFileSync(logPath, "utf-8"));
220
- } catch {}
221
- }
222
- log.domains = log.domains || {};
223
- log.domains[domain] = new Date().toISOString();
224
- fs.writeFileSync(logPath, JSON.stringify(log, null, 2), "utf-8");
225
- } catch {}
33
+ export function buildUnindexedCatalog(root: string, runtimeVersion: RuntimeVersionMeta) {
34
+ return { schema: NAVIGATION_SCHEMA, status: 'NOT_INDEXED', total_domains: 0, runtime_version: runtimeVersion,
35
+ message: `Workspace '${root}' belum diinisialisasi. Register a domain or run septum init.`,
36
+ suggested_action: { tool: 'septum_map', params: { action: 'register', name: 'core', root: 'src', ingest_now: true } },
37
+ next: [{ tool: 'septum_map', args: { action: 'register', name: 'core', root: 'src', ingest_now: true } }],
38
+ };
226
39
  }
@@ -1,8 +1,21 @@
1
1
  import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
2
2
  import type { SeptumRepository } from "../../core/database/repository.ts";
3
3
  import type { GetSymbolImpactArgs } from "../../types/index.ts";
4
+ import { partitionResolutionWarnings } from "../../core/retrieval/resolution-warnings.ts";
5
+ import { symbolWorkspace, withSymbolEvidence } from "../../core/retrieval/symbol-evidence.ts";
4
6
 
5
7
  export function handleGetSymbolImpact(
8
+ repo: SeptumRepository,
9
+ config: ValidatedSeptumConfig,
10
+ args: GetSymbolImpactArgs,
11
+ workspaceRoot?: string
12
+ ) {
13
+ const root = symbolWorkspace(repo, workspaceRoot || args.workspace_path);
14
+ return withSymbolEvidence(repo, root, { operation: "impact", requested: args.symbol_ref },
15
+ () => inspectImpact(repo, config, args, root));
16
+ }
17
+
18
+ function inspectImpact(
6
19
  repo: SeptumRepository,
7
20
  _config: ValidatedSeptumConfig,
8
21
  args: GetSymbolImpactArgs,
@@ -48,16 +61,43 @@ export function handleGetSymbolImpact(
48
61
  const relationships = repo.getImportRelationships(workspaceRoot || args.workspace_path);
49
62
  const targetFiles = candidates.map(candidate => candidate.file_path);
50
63
  const importDependents = relationships.filter(edge => edge.resolution.status === "resolved" && edge.resolution.targets.some(target => target.files.some(file => targetFiles.includes(file))));
51
- const payload = { ...impact, coverage: "partial", inbound_callers_complete: false,
52
- relationship_limits: "Legacy inbound caller hints are inferred; import dependencies are reported separately and do not prove executed calls.",
53
- import_dependents: importDependents,
54
- resolution_warnings: relationships.filter(edge => !["resolved","external"].includes(edge.resolution.status) || edge.resolution.coverage === "conditional"),
64
+ const warnings = partitionResolutionWarnings(relationships, targetFiles);
65
+ const callSites = impact.inbound_callers.filter(
66
+ caller => caller.kind === "call" || caller.kind === "instantiation" || caller.kind === "heritage"
67
+ );
68
+ const firstResolution = importDependents[0]?.resolution;
69
+ const compactImportDependents = importDependents.map(edge => ({
70
+ source: {
71
+ file: edge.source.file,
72
+ line: edge.source.line,
73
+ statement: edge.source.statement,
74
+ },
75
+ target_domains: edge.target_domains,
76
+ resolution: {
77
+ status: edge.resolution.status,
78
+ reason: edge.resolution.reason,
79
+ targets: edge.resolution.targets,
80
+ },
81
+ }));
82
+ const payload = { ...impact, symbol_ref: selectedCandidate?.symbol_ref, coverage: "partial", inbound_callers_complete: false,
83
+ call_sites: callSites,
84
+ risk_scope: "advisory; incomplete static consumer evidence, not a refactoring safety verdict",
85
+ relationship_limits: "Imports do not prove executed calls. Import-bound function call sites are static evidence; legacy hints remain inferred. Static calls do not prove runtime execution or a complete caller set.",
86
+ ...(firstResolution ? { resolution_metadata: { resolver_revision: firstResolution.resolver_revision, config_revision: firstResolution.config_revision } } : {}),
87
+ import_dependents: compactImportDependents,
88
+ resolution_warnings: warnings.relevant,
89
+ workspace_resolution_diagnostics: {
90
+ count: warnings.workspace.length, returned_details: 0, omitted_details: warnings.workspace.length,
91
+ reason: "Current resolved imports to unrelated indexed files are summarized separately; unresolved, ambiguous, unsupported and stale relationships remain conservatively in resolution_warnings.",
92
+ },
93
+ diagnostic_accounting: { total: warnings.relevant.length + warnings.workspace.length,
94
+ target_or_possible_target: warnings.relevant.length, unrelated_workspace: warnings.workspace.length },
55
95
  };
56
96
  return {
57
97
  content: [
58
98
  {
59
99
  type: "text" as const,
60
- text: JSON.stringify(payload, null, 2),
100
+ text: JSON.stringify(payload),
61
101
  },
62
102
  ],
63
103
  };