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.
- package/LICENSE +21 -21
- package/README.md +105 -105
- package/bin/septum.ts +4 -4
- package/package.json +63 -63
- package/src/cli/commands/check.ts +161 -161
- package/src/cli/commands/hook.ts +216 -188
- package/src/cli/commands/ingest.ts +29 -29
- package/src/cli/commands/init.ts +213 -211
- package/src/cli/commands/locate.ts +61 -61
- package/src/cli/commands/query.ts +104 -64
- package/src/cli/commands/serve.ts +5 -5
- package/src/cli/commands/slice.ts +50 -48
- package/src/cli/commands/sync.ts +31 -31
- package/src/cli/index.ts +220 -210
- package/src/cli/templates/hooks.ts +75 -75
- package/src/cli/templates/rules.ts +50 -38
- package/src/cli/templates/skill.ts +65 -69
- package/src/core/boundary/evaluator.ts +429 -210
- package/src/core/config/loader.ts +117 -97
- package/src/core/config/schema.ts +39 -39
- package/src/core/database/client.ts +44 -44
- package/src/core/database/repositories/dependency.repository.ts +552 -349
- package/src/core/database/repositories/domain.repository.ts +275 -198
- package/src/core/database/repositories/file.repository.ts +117 -106
- package/src/core/database/repositories/meta.repository.ts +33 -33
- package/src/core/database/repositories/symbol.repository.ts +482 -443
- package/src/core/database/repository.ts +281 -260
- package/src/core/database/schema.ts +154 -153
- package/src/core/discovery/topology-detector.ts +486 -486
- package/src/core/ingestion/hasher.ts +5 -5
- package/src/core/ingestion/pipeline.ts +606 -535
- package/src/core/parser/boundary-tracker.ts +433 -288
- package/src/core/parser/extractors/base.ts +62 -62
- package/src/core/parser/extractors/blade.ts +158 -158
- package/src/core/parser/extractors/frontend.ts +147 -194
- package/src/core/parser/extractors/go.ts +408 -180
- package/src/core/parser/extractors/laravel-semantic.ts +1045 -901
- package/src/core/parser/extractors/mcp-cli-semantic.ts +328 -199
- package/src/core/parser/extractors/nestjs-semantic.ts +134 -119
- package/src/core/parser/extractors/php.ts +415 -153
- package/src/core/parser/extractors/python.ts +460 -228
- package/src/core/parser/extractors/registry.ts +70 -70
- package/src/core/parser/extractors/semantic-extractor.interface.ts +21 -21
- package/src/core/parser/extractors/typescript.ts +668 -181
- package/src/core/parser/tree-sitter.ts +41 -41
- package/src/core/parser/wasm-loader.ts +271 -0
- package/src/core/resolver/call-graph-tracer.ts +698 -668
- package/src/core/resolver/module-resolver.ts +479 -342
- package/src/core/resolver/path-resolver.ts +147 -147
- package/src/core/resolver/symbol-locator.ts +543 -543
- package/src/core/resolver/vertical-slice-tracer.ts +323 -285
- package/src/core/session/session-manager.ts +56 -56
- package/src/core/telemetry/telemetry.ts +86 -86
- package/src/core/topology/environment-detector.ts +109 -6
- package/src/index.ts +21 -21
- package/src/mcp/schemas.ts +695 -286
- package/src/mcp/server.ts +927 -716
- package/src/mcp/tools/check-boundary.ts +307 -152
- package/src/mcp/tools/get-domain-catalog.ts +155 -121
- package/src/mcp/tools/get-environment-topology.ts +3 -6
- package/src/mcp/tools/get-feature-context.ts +227 -116
- package/src/mcp/tools/get-symbol-hotspots.ts +54 -59
- package/src/mcp/tools/get-symbol-impact.ts +28 -26
- package/src/mcp/tools/get-symbol.ts +65 -63
- package/src/mcp/tools/locate-symbol.ts +169 -190
- package/src/mcp/tools/register-domain.ts +59 -64
- package/src/mcp/tools/register-feature.ts +91 -0
- package/src/mcp/tools/trace-vertical-slice.ts +74 -48
- package/src/types/index.ts +366 -315
- 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
workspaceRoot
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
|
4
|
+
import type { EnvironmentLayer } from "../../core/topology/types.ts";
|
|
5
|
+
import type { GetEnvironmentTopologyArgs } from "../schemas.ts";
|
|
5
6
|
|
|
6
|
-
export
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
|