septum 0.1.4 → 0.1.6

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 (70) 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 +216 -188
  7. package/src/cli/commands/ingest.ts +29 -29
  8. package/src/cli/commands/init.ts +213 -211
  9. package/src/cli/commands/locate.ts +61 -61
  10. package/src/cli/commands/query.ts +104 -64
  11. package/src/cli/commands/serve.ts +5 -5
  12. package/src/cli/commands/slice.ts +50 -48
  13. package/src/cli/commands/sync.ts +31 -31
  14. package/src/cli/index.ts +220 -210
  15. package/src/cli/templates/hooks.ts +75 -75
  16. package/src/cli/templates/rules.ts +50 -38
  17. package/src/cli/templates/skill.ts +65 -69
  18. package/src/core/boundary/evaluator.ts +429 -210
  19. package/src/core/config/loader.ts +117 -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 +552 -349
  23. package/src/core/database/repositories/domain.repository.ts +275 -198
  24. package/src/core/database/repositories/file.repository.ts +117 -106
  25. package/src/core/database/repositories/meta.repository.ts +33 -33
  26. package/src/core/database/repositories/symbol.repository.ts +482 -443
  27. package/src/core/database/repository.ts +281 -260
  28. package/src/core/database/schema.ts +154 -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 +606 -535
  32. package/src/core/parser/boundary-tracker.ts +433 -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 +147 -194
  36. package/src/core/parser/extractors/go.ts +408 -180
  37. package/src/core/parser/extractors/laravel-semantic.ts +1045 -901
  38. package/src/core/parser/extractors/mcp-cli-semantic.ts +328 -199
  39. package/src/core/parser/extractors/nestjs-semantic.ts +134 -119
  40. package/src/core/parser/extractors/php.ts +415 -153
  41. package/src/core/parser/extractors/python.ts +460 -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 +668 -181
  45. package/src/core/parser/tree-sitter.ts +41 -41
  46. package/src/core/parser/wasm-loader.ts +271 -0
  47. package/src/core/resolver/call-graph-tracer.ts +698 -668
  48. package/src/core/resolver/module-resolver.ts +479 -342
  49. package/src/core/resolver/path-resolver.ts +147 -147
  50. package/src/core/resolver/symbol-locator.ts +543 -543
  51. package/src/core/resolver/vertical-slice-tracer.ts +323 -285
  52. package/src/core/session/session-manager.ts +56 -56
  53. package/src/core/telemetry/telemetry.ts +86 -86
  54. package/src/core/topology/environment-detector.ts +109 -6
  55. package/src/index.ts +21 -21
  56. package/src/mcp/schemas.ts +695 -286
  57. package/src/mcp/server.ts +927 -716
  58. package/src/mcp/tools/check-boundary.ts +307 -152
  59. package/src/mcp/tools/get-domain-catalog.ts +155 -121
  60. package/src/mcp/tools/get-environment-topology.ts +3 -6
  61. package/src/mcp/tools/get-feature-context.ts +227 -116
  62. package/src/mcp/tools/get-symbol-hotspots.ts +54 -59
  63. package/src/mcp/tools/get-symbol-impact.ts +28 -26
  64. package/src/mcp/tools/get-symbol.ts +65 -63
  65. package/src/mcp/tools/locate-symbol.ts +169 -190
  66. package/src/mcp/tools/register-domain.ts +59 -64
  67. package/src/mcp/tools/register-feature.ts +91 -0
  68. package/src/mcp/tools/trace-vertical-slice.ts +74 -48
  69. package/src/types/index.ts +366 -315
  70. package/src/version.ts +3 -3
@@ -1,121 +1,155 @@
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
+ import type { DomainCatalogResponse } from "../../types/index.ts";
6
+ import type { GetDomainCatalogArgs } from "../schemas.ts";
7
+
8
+ export type { GetDomainCatalogArgs } from "../schemas.ts";
9
+
10
+ export function handleGetDomainCatalog(
11
+ repo: SeptumRepository,
12
+ config: ValidatedSeptumConfig,
13
+ args: GetDomainCatalogArgs,
14
+ workspaceRoot?: string
15
+ ) {
16
+ const targetRoot = args.workspace_path || workspaceRoot || (repo as any)?.projectRoot || process.cwd();
17
+ const domainName = args.domain ?? args.name;
18
+
19
+ if (!domainName) {
20
+ const allDomains = repo.getAllDomains();
21
+ if (allDomains.length === 0) {
22
+ const root = targetRoot;
23
+ const diagnostic = {
24
+ status: "NOT_INDEXED",
25
+ total_domains: 0,
26
+ message: `Workspace '${root}' belum memiliki domain terdaftar dalam Septum catalog.`,
27
+ suggested_action: {
28
+ tool: "septum_register_domain",
29
+ params: {
30
+ name: "core",
31
+ root: "src",
32
+ ingest_now: true,
33
+ },
34
+ },
35
+ agent_guidance:
36
+ "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.",
37
+ };
38
+ return {
39
+ content: [
40
+ {
41
+ type: "text" as const,
42
+ text: JSON.stringify(diagnostic, null, 2),
43
+ },
44
+ ],
45
+ metadata: diagnostic,
46
+ };
47
+ }
48
+
49
+ const projectType = repo.getMeta("project_type") || "generic";
50
+ const framework = repo.getMeta("framework") || "unknown";
51
+ const archStyle = repo.getMeta("architecture_style") || "modular";
52
+ const totalSlices =
53
+ typeof (repo as any).countVerticalSlices === "function"
54
+ ? (repo as any).countVerticalSlices()
55
+ : repo.getAllVerticalSlices().length;
56
+
57
+ const macroMap = {
58
+ telescope_view: {
59
+ project_type: projectType,
60
+ framework,
61
+ architecture_style: archStyle,
62
+ total_domains: allDomains.length,
63
+ total_vertical_slices: totalSlices,
64
+ },
65
+ domains: allDomains.map((d) => ({
66
+ name: d.name,
67
+ root: d.root_path,
68
+ archetypes: Object.keys(JSON.parse(d.archetypes_json || "{}")),
69
+ allowed_dependencies: JSON.parse(d.allowed_deps_json || "[]"),
70
+ forbidden_dependencies: JSON.parse(d.forbidden_deps_json || "[]"),
71
+ })),
72
+ agent_instruction:
73
+ "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.",
74
+ };
75
+
76
+ return {
77
+ content: [
78
+ {
79
+ type: "text" as const,
80
+ text: JSON.stringify(macroMap, null, 2),
81
+ },
82
+ ],
83
+ };
84
+ }
85
+
86
+ const archetypeFilter = args.archetype_filter ?? args.archetype;
87
+ const detailLevel = args.detail_level ?? "compact";
88
+ const fileFilter = args.file_filter;
89
+
90
+ const catalog: DomainCatalogResponse | null = (repo.getDomainCatalog as any)(
91
+ domainName,
92
+ archetypeFilter,
93
+ { detailLevel, fileFilter }
94
+ );
95
+ if (!catalog) {
96
+ const available = Object.keys(config.domains || {});
97
+ const suggestions = available.filter((d) =>
98
+ d.toLowerCase().includes(domainName.toLowerCase()) ||
99
+ domainName.toLowerCase().includes(d.toLowerCase())
100
+ );
101
+ const notFoundPayload = {
102
+ status: "not_found",
103
+ found: false,
104
+ domain: domainName,
105
+ message: `Domain '${domainName}' not found in Septum catalog.`,
106
+ available_domains: available,
107
+ suggestions: suggestions.length > 0 ? suggestions : available,
108
+ suggested_action: {
109
+ tool: "septum_register_domain",
110
+ params: { domain: domainName, root: `src/domains/${domainName}` },
111
+ },
112
+ };
113
+ return {
114
+ content: [
115
+ {
116
+ type: "text" as const,
117
+ text: JSON.stringify(notFoundPayload, null, 2),
118
+ },
119
+ ],
120
+ metadata: notFoundPayload,
121
+ };
122
+ }
123
+
124
+ // Record access log for Gate 3 (Mandatory Catalog Consultation)
125
+ recordCatalogAccess(domainName, targetRoot);
126
+
127
+ // Token-efficient serialization: keep payload dense and under 500 tokens
128
+ return {
129
+ content: [
130
+ {
131
+ type: "text" as const,
132
+ text: JSON.stringify(catalog, null, 2),
133
+ },
134
+ ],
135
+ };
136
+ }
137
+
138
+ function recordCatalogAccess(domain: string, projectRoot: string = process.cwd()): void {
139
+ try {
140
+ const septumDir = path.resolve(projectRoot, ".septum");
141
+ if (!fs.existsSync(septumDir)) {
142
+ fs.mkdirSync(septumDir, { recursive: true });
143
+ }
144
+ const logPath = path.join(septumDir, "catalog_access.json");
145
+ let log: { domains?: Record<string, string>; features?: Record<string, string> } = {};
146
+ if (fs.existsSync(logPath)) {
147
+ try {
148
+ log = JSON.parse(fs.readFileSync(logPath, "utf-8"));
149
+ } catch {}
150
+ }
151
+ log.domains = log.domains || {};
152
+ log.domains[domain] = new Date().toISOString();
153
+ fs.writeFileSync(logPath, JSON.stringify(log, null, 2), "utf-8");
154
+ } catch {}
155
+ }
@@ -1,13 +1,10 @@
1
1
  import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
2
2
  import type { SeptumRepository } from "../../core/database/repository.ts";
3
3
  import { EnvironmentDetector } from "../../core/topology/environment-detector.ts";
4
- import type { EnvironmentLayer, ResolveLayerInput, ResolveNodeInput } from "../../core/topology/types.ts";
4
+ import type { EnvironmentLayer } from "../../core/topology/types.ts";
5
+ import type { GetEnvironmentTopologyArgs } from "../schemas.ts";
5
6
 
6
- export interface GetEnvironmentTopologyArgs {
7
- resolve?: ResolveLayerInput;
8
- resolveNode?: ResolveNodeInput;
9
- refresh?: boolean;
10
- }
7
+ export type { GetEnvironmentTopologyArgs } from "../schemas.ts";
11
8
 
12
9
  export function handleGetEnvironmentTopology(
13
10
  repo: SeptumRepository,
@@ -1,116 +1,227 @@
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
- import { SessionManager } from "../../core/session/session-manager.ts";
6
- import type { FeatureContextResponse } from "../../types/index.ts";
7
-
8
- export interface GetFeatureContextArgs {
9
- feature: string;
10
- }
11
-
12
- export function handleClearFeatureContext(workspaceRoot: string = process.cwd()): boolean {
13
- return SessionManager.clearActiveSession(workspaceRoot);
14
- }
15
-
16
- export function handleGetFeatureContext(
17
- repo: SeptumRepository,
18
- config: ValidatedSeptumConfig,
19
- args: GetFeatureContextArgs
20
- ) {
21
- if (!args.feature) {
22
- throw new Error("Missing required argument: 'feature'");
23
- }
24
-
25
- const features = config.features ?? {};
26
- const featureConfig = features[args.feature];
27
-
28
- if (!featureConfig) {
29
- const available = Object.keys(features).join(", ") || "none";
30
- throw new Error(
31
- `Feature '${args.feature}' not found in configuration. Available features: [${available}]`
32
- );
33
- }
34
-
35
- // Record Active Feature Session Lease (.septum/session.json)
36
- SessionManager.saveActiveSession(process.cwd(), {
37
- feature_key: args.feature,
38
- domain: featureConfig.domain,
39
- touchpoints: featureConfig.allowed_touchpoints ?? [],
40
- locked_at: new Date().toISOString(),
41
- });
42
-
43
- // Deterministically fetch signatures, methods, and properties for reuse_symbols from SQLite
44
- const reuseSymbolsWithMeta: FeatureContextResponse["reuse_symbols"] = [];
45
- const requestedSymbols = featureConfig.reuse_symbols ?? [];
46
-
47
- for (const symName of requestedSymbols) {
48
- const record = repo.findSymbolWithMembers(symName);
49
- if (record) {
50
- reuseSymbolsWithMeta.push({
51
- name: record.symbol_name,
52
- kind: record.kind,
53
- signature: record.signature,
54
- methods: record.methods.length > 0 ? record.methods : undefined,
55
- properties: record.properties.length > 0 ? record.properties : undefined,
56
- file_path: record.file_path,
57
- domain: record.domain_name,
58
- });
59
- } else {
60
- reuseSymbolsWithMeta.push({
61
- name: symName,
62
- kind: "unknown",
63
- domain: featureConfig.domain,
64
- });
65
- }
66
- }
67
-
68
- const response: FeatureContextResponse = {
69
- feature: args.feature,
70
- domain: featureConfig.domain,
71
- description: featureConfig.description,
72
- allowed_touchpoints: featureConfig.allowed_touchpoints,
73
- reuse_symbols: reuseSymbolsWithMeta,
74
- input_contract: (featureConfig.input_contract as Record<string, unknown>) ?? {},
75
- output_contract: (featureConfig.output_contract as Record<string, unknown>) ?? {},
76
- governance_directives: [
77
- "DO NOT modify or edit any files outside allowed_touchpoints.",
78
- "DO NOT create duplicate helpers/services; reuse the existing symbols and methods declared in reuse_symbols.",
79
- "DO NOT emit or expect phantom payload fields outside input_contract and output_contract.",
80
- "DO NOT import cross-domain modules without declared allowed_dependencies in Septum domain boundaries.",
81
- ],
82
- };
83
-
84
- recordFeatureAccess(featureConfig.domain, args.feature);
85
-
86
- return {
87
- content: [
88
- {
89
- type: "text" as const,
90
- text: JSON.stringify(response, null, 2),
91
- },
92
- ],
93
- };
94
- }
95
-
96
- function recordFeatureAccess(domain: string, feature: string): void {
97
- try {
98
- const septumDir = path.resolve(process.cwd(), ".septum");
99
- if (!fs.existsSync(septumDir)) {
100
- fs.mkdirSync(septumDir, { recursive: true });
101
- }
102
- const logPath = path.join(septumDir, "catalog_access.json");
103
- let log: { domains?: Record<string, string>; features?: Record<string, string> } = {};
104
- if (fs.existsSync(logPath)) {
105
- try {
106
- log = JSON.parse(fs.readFileSync(logPath, "utf-8"));
107
- } catch {}
108
- }
109
- log.domains = log.domains || {};
110
- log.features = log.features || {};
111
- const now = new Date().toISOString();
112
- log.domains[domain] = now;
113
- log.features[feature] = now;
114
- fs.writeFileSync(logPath, JSON.stringify(log, null, 2), "utf-8");
115
- } catch {}
116
- }
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
+ import { SessionManager } from "../../core/session/session-manager.ts";
6
+ import type { FeatureContextResponse } from "../../types/index.ts";
7
+ import type { GetFeatureContextArgs } from "../schemas.ts";
8
+
9
+ export type { GetFeatureContextArgs } from "../schemas.ts";
10
+
11
+ export function handleClearFeatureContext(workspaceRoot: string = process.cwd()): boolean {
12
+ return SessionManager.clearActiveSession(workspaceRoot);
13
+ }
14
+
15
+ export function handleGetFeatureContext(
16
+ repo: SeptumRepository,
17
+ config: ValidatedSeptumConfig,
18
+ args: GetFeatureContextArgs,
19
+ workspaceRoot: string = process.cwd()
20
+ ) {
21
+ const featureKey = (args.feature_key || args.feature || "").trim();
22
+ const features = { ...(config.features ?? {}) };
23
+ if (typeof repo?.getMeta === "function") {
24
+ try {
25
+ const metaFeaturesRaw = repo.getMeta("features_json");
26
+ if (metaFeaturesRaw) {
27
+ Object.assign(features, JSON.parse(metaFeaturesRaw));
28
+ }
29
+ } catch {}
30
+ }
31
+
32
+ // ZERO-ARGUMENT GRACEFUL FALLBACK: Guide the agent instead of throwing validation errors
33
+ if (!featureKey) {
34
+ const available = Object.keys(features);
35
+ return {
36
+ content: [
37
+ {
38
+ type: "text" as const,
39
+ text: JSON.stringify(
40
+ {
41
+ status: "prompt",
42
+ message: "No feature specified. Please specify 'feature_key' from the registered features below or trace routes.",
43
+ available_features: available.length > 0 ? available : [],
44
+ instructions: "Call 'septum_get_feature_context({ feature_key: \"<name>\" })' or register a new feature with 'septum_register_feature'.",
45
+ },
46
+ null,
47
+ 2
48
+ ),
49
+ },
50
+ ],
51
+ };
52
+ }
53
+
54
+ let featureConfig = features[featureKey];
55
+ let isInferred = false;
56
+
57
+ if (!featureConfig) {
58
+ // Attempt auto-derive from vertical slices or domain symbols
59
+ const searchTerm = featureKey.toLowerCase();
60
+ const allSlices = typeof repo.getAllVerticalSlices === "function" ? repo.getAllVerticalSlices() : [];
61
+ const fromRepoSearch = typeof repo.findVerticalSlices === "function" ? repo.findVerticalSlices(searchTerm) : [];
62
+ const matchingSlices = [
63
+ ...fromRepoSearch,
64
+ ...allSlices.filter(
65
+ (s) =>
66
+ s.route_uri.toLowerCase().includes(searchTerm) ||
67
+ (s.route_name && s.route_name.toLowerCase().includes(searchTerm)) ||
68
+ s.controller_class.toLowerCase().includes(searchTerm) ||
69
+ (s.feature_key && s.feature_key.toLowerCase().includes(searchTerm))
70
+ ),
71
+ ];
72
+
73
+ const uniqueSlices = Array.from(
74
+ new Map(matchingSlices.map((s) => [`${s.http_method}:${s.route_uri}`, s])).values()
75
+ );
76
+
77
+ if (uniqueSlices.length > 0) {
78
+ isInferred = true;
79
+ const candidateTouchpoints = new Set<string>();
80
+ const candidateSymbols = new Set<string>();
81
+ let detectedDomain = "app";
82
+
83
+ if (config.domains && config.domains[featureKey]) {
84
+ detectedDomain = featureKey;
85
+ }
86
+
87
+ for (const slice of uniqueSlices) {
88
+ if (slice.controller_file) {
89
+ candidateTouchpoints.add(slice.controller_file);
90
+ }
91
+ candidateSymbols.add(slice.controller_class);
92
+ if (slice.action_name) {
93
+ candidateSymbols.add(`${slice.controller_class}@${slice.action_name}`);
94
+ }
95
+
96
+ if (slice.execution_chain_json) {
97
+ try {
98
+ const chain = JSON.parse(slice.execution_chain_json);
99
+ if (Array.isArray(chain)) {
100
+ for (const node of chain) {
101
+ if (node.file) candidateTouchpoints.add(node.file);
102
+ if (node.symbol) candidateSymbols.add(node.symbol);
103
+ }
104
+ }
105
+ } catch {}
106
+ }
107
+ }
108
+
109
+ featureConfig = {
110
+ domain: detectedDomain,
111
+ description: `[Auto-Derived] Feature context inferred from ${uniqueSlices.length} vertical slices matching '${featureKey}'`,
112
+ allowed_touchpoints: Array.from(candidateTouchpoints),
113
+ reuse_symbols: Array.from(candidateSymbols).slice(0, 10),
114
+ input_contract: {},
115
+ output_contract: {},
116
+ };
117
+ } else {
118
+ const available = Object.keys(features);
119
+ const availableStr = available.length > 0 ? available.join(", ") : "none";
120
+ return {
121
+ content: [
122
+ {
123
+ type: "text" as const,
124
+ text: JSON.stringify(
125
+ {
126
+ status: "not_found",
127
+ feature_key: featureKey,
128
+ message: `Feature '${featureKey}' not found in configuration or vertical slices. Available features: [${availableStr}].`,
129
+ recovery_options: [
130
+ `septum_register_feature({ feature_key: "${featureKey}", domain: "<domain_name>", allowed_touchpoints: ["path/to/file"] })`,
131
+ `septum_trace_vertical_slice({ entry_file: "routes/web.php" })`,
132
+ ],
133
+ },
134
+ null,
135
+ 2
136
+ ),
137
+ },
138
+ ],
139
+ };
140
+ }
141
+ }
142
+
143
+ // Record Active Feature Session Lease (.septum/session.json)
144
+ SessionManager.saveActiveSession(workspaceRoot, {
145
+ feature_key: featureKey,
146
+ domain: featureConfig.domain,
147
+ touchpoints: featureConfig.allowed_touchpoints ?? [],
148
+ locked_at: new Date().toISOString(),
149
+ });
150
+
151
+ // Deterministically fetch signatures, methods, and properties for reuse_symbols from SQLite
152
+ const reuseSymbolsWithMeta: FeatureContextResponse["reuse_symbols"] = [];
153
+ const requestedSymbols = featureConfig.reuse_symbols ?? [];
154
+
155
+ for (const symName of requestedSymbols) {
156
+ const record = repo.findSymbolWithMembers(symName);
157
+ if (record) {
158
+ reuseSymbolsWithMeta.push({
159
+ name: record.symbol_name,
160
+ kind: record.kind,
161
+ signature: record.signature,
162
+ methods: record.methods.length > 0 ? record.methods : undefined,
163
+ properties: record.properties.length > 0 ? record.properties : undefined,
164
+ file_path: record.file_path,
165
+ domain: record.domain_name,
166
+ });
167
+ } else {
168
+ reuseSymbolsWithMeta.push({
169
+ name: symName,
170
+ kind: "unknown",
171
+ domain: featureConfig.domain,
172
+ });
173
+ }
174
+ }
175
+
176
+ const response: FeatureContextResponse = {
177
+ feature_key: featureKey,
178
+ feature: featureKey,
179
+ domain: featureConfig.domain,
180
+ description: featureConfig.description,
181
+ allowed_touchpoints: featureConfig.allowed_touchpoints,
182
+ reuse_symbols: reuseSymbolsWithMeta,
183
+ input_contract: (featureConfig.input_contract as Record<string, unknown>) ?? {},
184
+ output_contract: (featureConfig.output_contract as Record<string, unknown>) ?? {},
185
+ governance_directives: [
186
+ "DO NOT modify or edit any files outside allowed_touchpoints.",
187
+ "DO NOT create duplicate helpers/services; reuse the existing symbols and methods declared in reuse_symbols.",
188
+ "DO NOT emit or expect phantom payload fields outside input_contract and output_contract.",
189
+ "DO NOT import cross-domain modules without declared allowed_dependencies in Septum domain boundaries.",
190
+ ],
191
+ ...(isInferred ? { is_inferred: true } : {}),
192
+ };
193
+
194
+ recordFeatureAccess(featureConfig.domain, featureKey, workspaceRoot);
195
+
196
+ return {
197
+ content: [
198
+ {
199
+ type: "text" as const,
200
+ text: JSON.stringify(response, null, 2),
201
+ },
202
+ ],
203
+ };
204
+ }
205
+
206
+ function recordFeatureAccess(domain: string, feature: string, workspaceRoot: string = process.cwd()): void {
207
+ try {
208
+ const septumDir = path.resolve(workspaceRoot, ".septum");
209
+ if (!fs.existsSync(septumDir)) {
210
+ fs.mkdirSync(septumDir, { recursive: true });
211
+ }
212
+ const logPath = path.join(septumDir, "catalog_access.json");
213
+ let log: { domains?: Record<string, string>; features?: Record<string, string> } = {};
214
+ if (fs.existsSync(logPath)) {
215
+ try {
216
+ log = JSON.parse(fs.readFileSync(logPath, "utf-8"));
217
+ } catch {}
218
+ }
219
+ log.domains = log.domains || {};
220
+ log.features = log.features || {};
221
+ const now = new Date().toISOString();
222
+ log.domains[domain] = now;
223
+ log.features[feature] = now;
224
+ fs.writeFileSync(logPath, JSON.stringify(log, null, 2), "utf-8");
225
+ } catch {}
226
+ }
227
+