septum 0.1.4 → 0.1.5

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 (67) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +105 -105
  3. package/bin/septum.ts +4 -4
  4. package/package.json +63 -63
  5. package/src/cli/commands/check.ts +161 -161
  6. package/src/cli/commands/hook.ts +188 -188
  7. package/src/cli/commands/ingest.ts +29 -29
  8. package/src/cli/commands/init.ts +211 -211
  9. package/src/cli/commands/locate.ts +61 -61
  10. package/src/cli/commands/query.ts +64 -64
  11. package/src/cli/commands/serve.ts +5 -5
  12. package/src/cli/commands/slice.ts +48 -48
  13. package/src/cli/commands/sync.ts +31 -31
  14. package/src/cli/index.ts +210 -210
  15. package/src/cli/templates/hooks.ts +75 -75
  16. package/src/cli/templates/rules.ts +38 -38
  17. package/src/cli/templates/skill.ts +69 -69
  18. package/src/core/boundary/evaluator.ts +232 -210
  19. package/src/core/config/loader.ts +97 -97
  20. package/src/core/config/schema.ts +39 -39
  21. package/src/core/database/client.ts +44 -44
  22. package/src/core/database/repositories/dependency.repository.ts +366 -349
  23. package/src/core/database/repositories/domain.repository.ts +218 -198
  24. package/src/core/database/repositories/file.repository.ts +116 -106
  25. package/src/core/database/repositories/meta.repository.ts +33 -33
  26. package/src/core/database/repositories/symbol.repository.ts +443 -443
  27. package/src/core/database/repository.ts +264 -260
  28. package/src/core/database/schema.ts +153 -153
  29. package/src/core/discovery/topology-detector.ts +486 -486
  30. package/src/core/ingestion/hasher.ts +5 -5
  31. package/src/core/ingestion/pipeline.ts +584 -535
  32. package/src/core/parser/boundary-tracker.ts +288 -288
  33. package/src/core/parser/extractors/base.ts +62 -62
  34. package/src/core/parser/extractors/blade.ts +158 -158
  35. package/src/core/parser/extractors/frontend.ts +194 -194
  36. package/src/core/parser/extractors/go.ts +229 -180
  37. package/src/core/parser/extractors/laravel-semantic.ts +1039 -901
  38. package/src/core/parser/extractors/mcp-cli-semantic.ts +199 -199
  39. package/src/core/parser/extractors/nestjs-semantic.ts +119 -119
  40. package/src/core/parser/extractors/php.ts +153 -153
  41. package/src/core/parser/extractors/python.ts +228 -228
  42. package/src/core/parser/extractors/registry.ts +70 -70
  43. package/src/core/parser/extractors/semantic-extractor.interface.ts +21 -21
  44. package/src/core/parser/extractors/typescript.ts +181 -181
  45. package/src/core/parser/tree-sitter.ts +41 -41
  46. package/src/core/resolver/call-graph-tracer.ts +666 -668
  47. package/src/core/resolver/module-resolver.ts +408 -342
  48. package/src/core/resolver/path-resolver.ts +147 -147
  49. package/src/core/resolver/symbol-locator.ts +543 -543
  50. package/src/core/resolver/vertical-slice-tracer.ts +301 -285
  51. package/src/core/session/session-manager.ts +56 -56
  52. package/src/core/telemetry/telemetry.ts +86 -86
  53. package/src/index.ts +21 -21
  54. package/src/mcp/schemas.ts +578 -286
  55. package/src/mcp/server.ts +875 -716
  56. package/src/mcp/tools/check-boundary.ts +171 -152
  57. package/src/mcp/tools/get-domain-catalog.ts +145 -121
  58. package/src/mcp/tools/get-feature-context.ts +212 -116
  59. package/src/mcp/tools/get-symbol-hotspots.ts +60 -59
  60. package/src/mcp/tools/get-symbol-impact.ts +28 -26
  61. package/src/mcp/tools/get-symbol.ts +65 -63
  62. package/src/mcp/tools/locate-symbol.ts +171 -190
  63. package/src/mcp/tools/register-domain.ts +68 -64
  64. package/src/mcp/tools/register-feature.ts +100 -0
  65. package/src/mcp/tools/trace-vertical-slice.ts +74 -48
  66. package/src/types/index.ts +335 -315
  67. package/src/version.ts +3 -3
@@ -1,152 +1,171 @@
1
- import type { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
2
- import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
3
- import type { SeptumRepository } from "../../core/database/repository.ts";
4
-
5
- export interface CheckBoundaryArgs {
6
- file_path?: string;
7
- filePath?: string;
8
- file?: string;
9
- path?: string;
10
- file_paths?: string[];
11
- filePaths?: string[];
12
- files?: string[];
13
- paths?: string[];
14
- proposed_imports?: string[];
15
- proposedImports?: string[];
16
- imports?: string[];
17
- feature_key?: string;
18
- featureKey?: string;
19
- feature?: string;
20
- }
21
-
22
- export function handleCheckBoundary(
23
- evaluator: BoundaryEvaluator,
24
- config: ValidatedSeptumConfig,
25
- args: CheckBoundaryArgs,
26
- repo?: SeptumRepository
27
- ) {
28
- const rawFilePaths = args.file_paths ?? args.filePaths ?? args.files ?? args.paths;
29
- const rawFilePath = args.file_path ?? args.filePath ?? args.file ?? args.path;
30
- const proposedImports = args.proposed_imports ?? args.proposedImports ?? args.imports ?? [];
31
- const featureKey = args.feature_key ?? args.featureKey ?? args.feature;
32
-
33
- const filesToCheck: string[] = [];
34
- if (rawFilePaths && Array.isArray(rawFilePaths) && rawFilePaths.length > 0) {
35
- filesToCheck.push(...rawFilePaths);
36
- } else if (rawFilePath) {
37
- if (Array.isArray(rawFilePath)) {
38
- filesToCheck.push(...rawFilePath);
39
- } else {
40
- filesToCheck.push(rawFilePath);
41
- }
42
- } else {
43
- throw new Error("Missing required argument: specify either 'file_path' or 'file_paths'");
44
- }
45
-
46
- // Multi-file batch evaluation
47
- if (filesToCheck.length > 1) {
48
- const results = filesToCheck.map((filePath) => {
49
- const violations = evaluator.evaluate(filePath, proposedImports, featureKey, config);
50
- const impact = repo?.getFileInboundImpact(filePath);
51
- return {
52
- file: filePath,
53
- status: violations.length > 0 ? "rejected" : "approved",
54
- violations,
55
- impact_summary: impact
56
- ? {
57
- direct_dependents: impact.direct_dependents_count,
58
- top_consumers: impact.top_consumers,
59
- symbols_count: impact.symbols_count,
60
- risk_level: impact.risk_level,
61
- }
62
- : undefined,
63
- };
64
- });
65
-
66
- const totalViolations = results.reduce((acc, r) => acc + r.violations.length, 0);
67
- const hasViolations = totalViolations > 0;
68
-
69
- return {
70
- content: [
71
- {
72
- type: "text" as const,
73
- text: JSON.stringify(
74
- {
75
- status: hasViolations ? "rejected" : "approved",
76
- total_checked: filesToCheck.length,
77
- total_violations: totalViolations,
78
- results,
79
- message: hasViolations
80
- ? `${totalViolations} boundary violation(s) detected across ${filesToCheck.length} file(s).`
81
- : `All ${filesToCheck.length} file(s) approved. No boundary violations detected.`,
82
- },
83
- null,
84
- 2
85
- ),
86
- },
87
- ],
88
- };
89
- }
90
-
91
- // Single file evaluation (backward-compatible output)
92
- const singleFile = filesToCheck[0];
93
- const violations = evaluator.evaluate(singleFile, proposedImports, featureKey, config);
94
- const impact = repo?.getFileInboundImpact(singleFile);
95
-
96
- if (violations.length > 0) {
97
- return {
98
- content: [
99
- {
100
- type: "text" as const,
101
- text: JSON.stringify(
102
- {
103
- status: "rejected",
104
- file: singleFile,
105
- violations_count: violations.length,
106
- violations,
107
- impact_summary: impact
108
- ? {
109
- direct_dependents: impact.direct_dependents_count,
110
- top_consumers: impact.top_consumers,
111
- symbols_count: impact.symbols_count,
112
- risk_level: impact.risk_level,
113
- }
114
- : undefined,
115
- message: "Boundary violation detected. Proposed imports violate bounded context architecture.",
116
- },
117
- null,
118
- 2
119
- ),
120
- },
121
- ],
122
- };
123
- }
124
-
125
- return {
126
- content: [
127
- {
128
- type: "text" as const,
129
- text: JSON.stringify(
130
- {
131
- status: "approved",
132
- file: singleFile,
133
- impact_summary: impact
134
- ? {
135
- direct_dependents: impact.direct_dependents_count,
136
- top_consumers: impact.top_consumers,
137
- symbols_count: impact.symbols_count,
138
- risk_level: impact.risk_level,
139
- }
140
- : undefined,
141
- message:
142
- impact && impact.direct_dependents_count > 0
143
- ? `No boundary violations detected. Caution: ${impact.direct_dependents_count} dependent file(s) consume this file.`
144
- : "No boundary violations detected. Proposed imports are permissible.",
145
- },
146
- null,
147
- 2
148
- ),
149
- },
150
- ],
151
- };
152
- }
1
+ import type { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
2
+ import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
3
+ import type { SeptumRepository } from "../../core/database/repository.ts";
4
+
5
+ export interface CheckBoundaryArgs {
6
+ file_path?: string;
7
+ filePath?: string;
8
+ file?: string;
9
+ path?: string;
10
+ from_file?: string;
11
+ fromFile?: string;
12
+ to_file?: string | string[];
13
+ toFile?: string | string[];
14
+ file_paths?: string[];
15
+ filePaths?: string[];
16
+ files?: string[];
17
+ paths?: string[];
18
+ proposed_imports?: string[];
19
+ proposedImports?: string[];
20
+ imports?: string[];
21
+ feature_key?: string;
22
+ featureKey?: string;
23
+ feature?: string;
24
+ }
25
+
26
+ export function handleCheckBoundary(
27
+ evaluator: BoundaryEvaluator,
28
+ config: ValidatedSeptumConfig,
29
+ args: CheckBoundaryArgs,
30
+ repo?: SeptumRepository,
31
+ _workspaceRoot?: string
32
+ ) {
33
+ const rawToFile = args.to_file ?? args.toFile;
34
+ const toFileImports = rawToFile ? (Array.isArray(rawToFile) ? rawToFile.map(String) : [String(rawToFile)]) : [];
35
+ const rawFilePaths = args.file_paths ?? args.filePaths ?? args.files ?? args.paths;
36
+ const rawFilePath = args.file_path ?? args.filePath ?? args.file ?? args.path ?? args.from_file ?? args.fromFile;
37
+ const proposedImports = [
38
+ ...(args.proposed_imports ?? args.proposedImports ?? args.imports ?? []),
39
+ ...toFileImports,
40
+ ];
41
+ const featureKey = args.feature_key ?? args.featureKey ?? args.feature;
42
+
43
+ const filesToCheck: string[] = [];
44
+ if (rawFilePaths && Array.isArray(rawFilePaths) && rawFilePaths.length > 0) {
45
+ filesToCheck.push(...rawFilePaths);
46
+ } else if (rawFilePath) {
47
+ if (Array.isArray(rawFilePath)) {
48
+ filesToCheck.push(...rawFilePath);
49
+ } else {
50
+ filesToCheck.push(rawFilePath);
51
+ }
52
+ } else {
53
+ throw new Error("Missing required argument: specify either 'file_path' or 'file_paths'");
54
+ }
55
+
56
+ // Multi-file batch evaluation
57
+ if (filesToCheck.length > 1) {
58
+ const results = filesToCheck.map((filePath) => {
59
+ const violations = evaluator.evaluate(filePath, proposedImports, featureKey, config);
60
+ const impact = repo?.getFileInboundImpact(filePath);
61
+ return {
62
+ file: filePath,
63
+ status: violations.length > 0 ? "rejected" : "approved",
64
+ violations,
65
+ impact_summary: impact
66
+ ? {
67
+ direct_dependents: impact.direct_dependents_count,
68
+ top_consumers: impact.top_consumers,
69
+ symbols_count: impact.symbols_count,
70
+ risk_level: impact.risk_level,
71
+ }
72
+ : undefined,
73
+ };
74
+ });
75
+
76
+ const totalViolations = results.reduce((acc, r) => acc + r.violations.length, 0);
77
+ const hasViolations = totalViolations > 0;
78
+
79
+ return {
80
+ content: [
81
+ {
82
+ type: "text" as const,
83
+ text: JSON.stringify(
84
+ {
85
+ status: hasViolations ? "rejected" : "approved",
86
+ total_checked: filesToCheck.length,
87
+ total_violations: totalViolations,
88
+ results,
89
+ message: hasViolations
90
+ ? `${totalViolations} boundary violation(s) detected across ${filesToCheck.length} file(s).`
91
+ : Object.keys(config?.domains || {}).length === 0
92
+ ? `All ${filesToCheck.length} file(s) approved. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_register_domain' to initialize bounded contexts.]`
93
+ : `All ${filesToCheck.length} file(s) approved. No boundary violations detected.`,
94
+ },
95
+ null,
96
+ 2
97
+ ),
98
+ },
99
+ ],
100
+ };
101
+ }
102
+
103
+ // Single file evaluation (backward-compatible output)
104
+ const singleFile = filesToCheck[0];
105
+ const violations = evaluator.evaluate(singleFile, proposedImports, featureKey, config);
106
+ const impact = repo?.getFileInboundImpact(singleFile);
107
+
108
+ if (violations.length > 0) {
109
+ return {
110
+ content: [
111
+ {
112
+ type: "text" as const,
113
+ text: JSON.stringify(
114
+ {
115
+ status: "rejected",
116
+ file: singleFile,
117
+ violations_count: violations.length,
118
+ violations,
119
+ impact_summary: impact
120
+ ? {
121
+ direct_dependents: impact.direct_dependents_count,
122
+ top_consumers: impact.top_consumers,
123
+ symbols_count: impact.symbols_count,
124
+ risk_level: impact.risk_level,
125
+ }
126
+ : undefined,
127
+ message:
128
+ Object.keys(config?.domains || {}).length === 0
129
+ ? "Boundary integrity check failed: Domain catalog is currently unindexed. Run 'septum_register_domain' to initialize bounded contexts."
130
+ : violations.some((v) => v.rule === "unmapped_domain")
131
+ ? "Boundary integrity check failed: File does not belong to any declared bounded context."
132
+ : "Boundary violation detected. Proposed imports violate bounded context architecture.",
133
+ },
134
+ null,
135
+ 2
136
+ ),
137
+ },
138
+ ],
139
+ };
140
+ }
141
+
142
+ return {
143
+ content: [
144
+ {
145
+ type: "text" as const,
146
+ text: JSON.stringify(
147
+ {
148
+ status: "approved",
149
+ file: singleFile,
150
+ impact_summary: impact
151
+ ? {
152
+ direct_dependents: impact.direct_dependents_count,
153
+ top_consumers: impact.top_consumers,
154
+ symbols_count: impact.symbols_count,
155
+ risk_level: impact.risk_level,
156
+ }
157
+ : undefined,
158
+ message:
159
+ Object.keys(config?.domains || {}).length === 0
160
+ ? "No boundary violations detected. [Septum Notice: Domain catalog is currently unindexed. Run 'septum_register_domain' to initialize bounded contexts.]"
161
+ : impact && impact.direct_dependents_count > 0
162
+ ? `No boundary violations detected. Caution: ${impact.direct_dependents_count} dependent file(s) consume this file.`
163
+ : "No boundary violations detected. Proposed imports are permissible.",
164
+ },
165
+ null,
166
+ 2
167
+ ),
168
+ },
169
+ ],
170
+ };
171
+ }
@@ -1,121 +1,145 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
4
- import type { SeptumRepository } from "../../core/database/repository.ts";
5
-
6
- export interface GetDomainCatalogArgs {
7
- domain?: string;
8
- archetype_filter?: string;
9
- workspace_path?: string;
10
- }
11
-
12
- export function handleGetDomainCatalog(
13
- repo: SeptumRepository,
14
- config: ValidatedSeptumConfig,
15
- args: GetDomainCatalogArgs,
16
- workspaceRoot?: string
17
- ) {
18
- if (!args.domain) {
19
- const allDomains = repo.getAllDomains();
20
- if (allDomains.length === 0) {
21
- const root = workspaceRoot || process.cwd();
22
- const diagnostic = {
23
- status: "NOT_INDEXED",
24
- total_domains: 0,
25
- message: `Workspace '${root}' belum memiliki domain terdaftar dalam Septum catalog.`,
26
- suggested_action: {
27
- tool: "septum_register_domain",
28
- params: {
29
- name: "core",
30
- root: "src",
31
- ingest_now: true,
32
- },
33
- },
34
- agent_guidance:
35
- "Panggil tool 'septum_register_domain(name: \"core\", root: \"src\", ingest_now: true)' untuk mendaftarkan dan mengindeks domain utama secara otomatis, atau jalankan 'septum init' di terminal workspace.",
36
- };
37
- return {
38
- content: [
39
- {
40
- type: "text" as const,
41
- text: JSON.stringify(diagnostic, null, 2),
42
- },
43
- ],
44
- metadata: diagnostic,
45
- };
46
- }
47
-
48
- const projectType = repo.getMeta("project_type") || "generic";
49
- const framework = repo.getMeta("framework") || "unknown";
50
- const archStyle = repo.getMeta("architecture_style") || "modular";
51
- const totalSlices = repo.getAllVerticalSlices().length;
52
-
53
- const macroMap = {
54
- telescope_view: {
55
- project_type: projectType,
56
- framework,
57
- architecture_style: archStyle,
58
- total_domains: allDomains.length,
59
- total_vertical_slices: totalSlices,
60
- },
61
- domains: allDomains.map((d) => ({
62
- name: d.name,
63
- root: d.root_path,
64
- archetypes: Object.keys(JSON.parse(d.archetypes_json || "{}")),
65
- allowed_dependencies: JSON.parse(d.allowed_deps_json || "[]"),
66
- forbidden_dependencies: JSON.parse(d.forbidden_deps_json || "[]"),
67
- })),
68
- agent_instruction:
69
- "Macro semantic map loaded from SQLite SSOT. Use 'septum_get_domain_catalog' with domain='<name>' for granular file/symbol catalogs, or 'septum_trace_vertical_slice' with query='<route|command|intent>' for end-to-end execution flow.",
70
- };
71
-
72
- return {
73
- content: [
74
- {
75
- type: "text" as const,
76
- text: JSON.stringify(macroMap, null, 2),
77
- },
78
- ],
79
- };
80
- }
81
-
82
- const catalog = repo.getDomainCatalog(args.domain, args.archetype_filter);
83
- if (!catalog) {
84
- const available = Object.keys(config.domains).join(", ");
85
- throw new Error(
86
- `Domain '${args.domain}' not found. Available domains in Septum catalog: [${available}]. Run 'septum ingest' or 'septum_register_domain' if recently added.`
87
- );
88
- }
89
-
90
- // Record access log for Gate 3 (Mandatory Catalog Consultation)
91
- recordCatalogAccess(args.domain);
92
-
93
- // Token-efficient serialization: keep payload dense and under 500 tokens
94
- return {
95
- content: [
96
- {
97
- type: "text" as const,
98
- text: JSON.stringify(catalog, null, 2),
99
- },
100
- ],
101
- };
102
- }
103
-
104
- function recordCatalogAccess(domain: string): void {
105
- try {
106
- const septumDir = path.resolve(process.cwd(), ".septum");
107
- if (!fs.existsSync(septumDir)) {
108
- fs.mkdirSync(septumDir, { recursive: true });
109
- }
110
- const logPath = path.join(septumDir, "catalog_access.json");
111
- let log: { domains?: Record<string, string>; features?: Record<string, string> } = {};
112
- if (fs.existsSync(logPath)) {
113
- try {
114
- log = JSON.parse(fs.readFileSync(logPath, "utf-8"));
115
- } catch {}
116
- }
117
- log.domains = log.domains || {};
118
- log.domains[domain] = new Date().toISOString();
119
- fs.writeFileSync(logPath, JSON.stringify(log, null, 2), "utf-8");
120
- } catch {}
121
- }
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
4
+ import type { SeptumRepository } from "../../core/database/repository.ts";
5
+
6
+ export interface GetDomainCatalogArgs {
7
+ domain?: string;
8
+ archetype_filter?: string;
9
+ workspace_path?: string;
10
+ }
11
+
12
+ export function handleGetDomainCatalog(
13
+ repo: SeptumRepository,
14
+ config: ValidatedSeptumConfig,
15
+ args: GetDomainCatalogArgs,
16
+ workspaceRoot?: string
17
+ ) {
18
+ const targetRoot = args.workspace_path || workspaceRoot || (repo as any)?.projectRoot || process.cwd();
19
+
20
+ if (!args.domain) {
21
+ const allDomains = repo.getAllDomains();
22
+ if (allDomains.length === 0) {
23
+ const root = targetRoot;
24
+ const diagnostic = {
25
+ status: "NOT_INDEXED",
26
+ total_domains: 0,
27
+ message: `Workspace '${root}' belum memiliki domain terdaftar dalam Septum catalog.`,
28
+ suggested_action: {
29
+ tool: "septum_register_domain",
30
+ params: {
31
+ name: "core",
32
+ root: "src",
33
+ ingest_now: true,
34
+ },
35
+ },
36
+ agent_guidance:
37
+ "Panggil tool 'septum_register_domain(name: \"core\", root: \"src\", ingest_now: true)' untuk mendaftarkan dan mengindeks domain utama secara otomatis, atau jalankan 'septum init' di terminal workspace.",
38
+ };
39
+ return {
40
+ content: [
41
+ {
42
+ type: "text" as const,
43
+ text: JSON.stringify(diagnostic, null, 2),
44
+ },
45
+ ],
46
+ metadata: diagnostic,
47
+ };
48
+ }
49
+
50
+ const projectType = repo.getMeta("project_type") || "generic";
51
+ const framework = repo.getMeta("framework") || "unknown";
52
+ const archStyle = repo.getMeta("architecture_style") || "modular";
53
+ const totalSlices = repo.getAllVerticalSlices().length;
54
+
55
+ const macroMap = {
56
+ telescope_view: {
57
+ project_type: projectType,
58
+ framework,
59
+ architecture_style: archStyle,
60
+ total_domains: allDomains.length,
61
+ total_vertical_slices: totalSlices,
62
+ },
63
+ domains: allDomains.map((d) => ({
64
+ name: d.name,
65
+ root: d.root_path,
66
+ archetypes: Object.keys(JSON.parse(d.archetypes_json || "{}")),
67
+ allowed_dependencies: JSON.parse(d.allowed_deps_json || "[]"),
68
+ forbidden_dependencies: JSON.parse(d.forbidden_deps_json || "[]"),
69
+ })),
70
+ agent_instruction:
71
+ "Macro semantic map loaded from SQLite SSOT. Use 'septum_get_domain_catalog' with domain='<name>' for granular file/symbol catalogs, or 'septum_trace_vertical_slice' with query='<route|command|intent>' for end-to-end execution flow.",
72
+ };
73
+
74
+ return {
75
+ content: [
76
+ {
77
+ type: "text" as const,
78
+ text: JSON.stringify(macroMap, null, 2),
79
+ },
80
+ ],
81
+ };
82
+ }
83
+
84
+ const catalog = repo.getDomainCatalog(args.domain, args.archetype_filter);
85
+ if (!catalog) {
86
+ const available = Object.keys(config.domains || {});
87
+ const suggestions = available.filter((d) =>
88
+ d.toLowerCase().includes(args.domain!.toLowerCase()) ||
89
+ args.domain!.toLowerCase().includes(d.toLowerCase())
90
+ );
91
+ const notFoundPayload = {
92
+ status: "not_found",
93
+ found: false,
94
+ domain: args.domain,
95
+ message: `Domain '${args.domain}' not found in Septum catalog.`,
96
+ available_domains: available,
97
+ suggestions: suggestions.length > 0 ? suggestions : available,
98
+ suggested_action: {
99
+ tool: "septum_register_domain",
100
+ params: { domain: args.domain, root: `src/domains/${args.domain}` },
101
+ },
102
+ };
103
+ return {
104
+ content: [
105
+ {
106
+ type: "text" as const,
107
+ text: JSON.stringify(notFoundPayload, null, 2),
108
+ },
109
+ ],
110
+ metadata: notFoundPayload,
111
+ };
112
+ }
113
+
114
+ // Record access log for Gate 3 (Mandatory Catalog Consultation)
115
+ recordCatalogAccess(args.domain, targetRoot);
116
+
117
+ // Token-efficient serialization: keep payload dense and under 500 tokens
118
+ return {
119
+ content: [
120
+ {
121
+ type: "text" as const,
122
+ text: JSON.stringify(catalog, null, 2),
123
+ },
124
+ ],
125
+ };
126
+ }
127
+
128
+ function recordCatalogAccess(domain: string, projectRoot: string = process.cwd()): void {
129
+ try {
130
+ const septumDir = path.resolve(projectRoot, ".septum");
131
+ if (!fs.existsSync(septumDir)) {
132
+ fs.mkdirSync(septumDir, { recursive: true });
133
+ }
134
+ const logPath = path.join(septumDir, "catalog_access.json");
135
+ let log: { domains?: Record<string, string>; features?: Record<string, string> } = {};
136
+ if (fs.existsSync(logPath)) {
137
+ try {
138
+ log = JSON.parse(fs.readFileSync(logPath, "utf-8"));
139
+ } catch {}
140
+ }
141
+ log.domains = log.domains || {};
142
+ log.domains[domain] = new Date().toISOString();
143
+ fs.writeFileSync(logPath, JSON.stringify(log, null, 2), "utf-8");
144
+ } catch {}
145
+ }