@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.
- package/README.md +46 -28
- package/package.json +4 -4
- package/src/cli/commands/check.ts +27 -16
- package/src/cli/commands/hook.ts +38 -101
- package/src/cli/commands/init.ts +26 -9
- package/src/cli/commands/sync.ts +4 -6
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +9 -52
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +49 -14
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +39 -35
- package/src/core/boundary/evaluator.ts +67 -83
- package/src/core/boundary/staged-auditor.ts +102 -40
- package/src/core/config/domain-ownership.ts +45 -0
- package/src/core/config/loader.ts +81 -29
- package/src/core/config/schema.ts +0 -10
- package/src/core/database/repositories/dependency.repository.ts +169 -148
- package/src/core/database/repositories/domain.repository.ts +46 -3
- package/src/core/database/repositories/symbol.repository.ts +226 -87
- package/src/core/database/repository.ts +73 -18
- package/src/core/database/schema.ts +2 -33
- package/src/core/discovery/navigation.ts +105 -0
- package/src/core/discovery/topology-detector.ts +60 -2
- package/src/core/ingestion/pipeline.ts +96 -129
- package/src/core/parser/behavioral-analyzer.ts +26 -22
- package/src/core/parser/boundary-tracker.ts +15 -0
- package/src/core/parser/extractors/base.ts +7 -3
- package/src/core/parser/extractors/csharp.ts +7 -3
- package/src/core/parser/extractors/django-semantic.ts +4 -36
- package/src/core/parser/extractors/elysia-semantic.ts +3 -24
- package/src/core/parser/extractors/express-semantic.ts +3 -18
- package/src/core/parser/extractors/fastapi-semantic.ts +19 -53
- package/src/core/parser/extractors/fastify-semantic.ts +3 -18
- package/src/core/parser/extractors/flask-semantic.ts +22 -55
- package/src/core/parser/extractors/go-semantic.ts +92 -33
- package/src/core/parser/extractors/hono-semantic.ts +3 -24
- package/src/core/parser/extractors/java.ts +5 -3
- package/src/core/parser/extractors/laravel-semantic.ts +44 -16
- package/src/core/parser/extractors/mcp-cli-semantic.ts +6 -7
- package/src/core/parser/extractors/nestjs-semantic.ts +3 -19
- package/src/core/parser/extractors/php.ts +16 -0
- package/src/core/parser/extractors/python.ts +9 -4
- package/src/core/parser/extractors/registry.ts +26 -5
- package/src/core/parser/extractors/ruby.ts +8 -5
- package/src/core/parser/extractors/rust.ts +31 -13
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-semantic.ts +4 -37
- package/src/core/parser/extractors/typescript.ts +14 -1
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +23 -7
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +73 -50
- package/src/core/parser/schema/schema-provider-registry.ts +1 -3
- package/src/core/parser/schema/schema-provider.interface.ts +2 -1
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- package/src/core/resolver/call-graph-tracer.ts +337 -28
- package/src/core/resolver/import-resolver.ts +107 -179
- package/src/core/resolver/interpretation-inputs.ts +7 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +115 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +71 -0
- package/src/core/resolver/module-resolver.ts +8 -4
- package/src/core/resolver/slice-catalog.ts +79 -0
- package/src/core/resolver/slice-format.ts +9 -0
- package/src/core/resolver/symbol-impact.ts +381 -0
- package/src/core/resolver/vertical-slice-tracer.ts +93 -115
- package/src/core/resources/ignore.ts +22 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/retrieval/context-page.ts +109 -0
- package/src/core/retrieval/context.ts +320 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +262 -0
- package/src/core/telemetry/telemetry.ts +54 -9
- package/src/index.ts +0 -3
- package/src/mcp/schemas.ts +61 -420
- package/src/mcp/server.ts +116 -290
- package/src/mcp/tools/boundary.ts +2 -2
- package/src/mcp/tools/check-boundary.ts +55 -60
- package/src/mcp/tools/get-domain-catalog.ts +32 -219
- package/src/mcp/tools/get-symbol-impact.ts +45 -5
- package/src/mcp/tools/get-symbol.ts +227 -3
- package/src/mcp/tools/locate-symbol.ts +54 -14
- package/src/mcp/tools/{domain.ts → map.ts} +4 -18
- package/src/mcp/tools/register-domain.ts +41 -3
- package/src/mcp/tools/symbol.ts +23 -21
- package/src/mcp/tools/trace-vertical-slice.ts +36 -10
- package/src/mcp/workspace-manager.ts +15 -4
- package/src/mcp/workspace-watcher.ts +8 -8
- package/src/types/index.ts +35 -53
- package/src/cli/commands/topology.ts +0 -161
- package/src/core/database/repositories/environment.repository.ts +0 -207
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
- package/src/core/session/session-manager.ts +0 -107
- package/src/core/topology/environment-detector.ts +0 -973
- package/src/core/topology/types.ts +0 -83
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-environment-topology.ts +0 -138
- package/src/mcp/tools/get-feature-context.ts +0 -224
- package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
- package/src/mcp/tools/register-feature.ts +0 -110
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { join, relative, resolve } from "node:path";
|
|
5
|
-
import { collectSourceSkips } from "../resources/source-files.ts";
|
|
1
|
+
import { rebuildSliceCatalog, sliceInputsCurrent } from "./slice-catalog.ts";
|
|
2
|
+
import { scanSourceFiles } from "../resources/source-inventory.ts";
|
|
3
|
+
import { relative } from "node:path";
|
|
6
4
|
import type {
|
|
7
5
|
ExecutionChainNode,
|
|
8
6
|
VerticalSliceRecord,
|
|
@@ -10,74 +8,30 @@ import type {
|
|
|
10
8
|
} from "../../types/index.ts";
|
|
11
9
|
import type { SeptumRepository } from "../database/repository.ts";
|
|
12
10
|
import { CallGraphTracer } from "./call-graph-tracer.ts";
|
|
13
|
-
import {
|
|
14
|
-
import { TopologyDetector } from "../discovery/topology-detector.ts";
|
|
15
|
-
import { readdirSync } from "node:fs";
|
|
16
|
-
import { ASTParserEngine } from "../parser/tree-sitter.ts";
|
|
17
|
-
import { shouldIgnoreSourcePath } from "../resources/ignore.ts";
|
|
11
|
+
import { formatSliceNode, SLICE_RELATIONSHIP_LIMITS } from "./slice-format.ts";
|
|
18
12
|
|
|
19
13
|
export class VerticalSliceTracer {
|
|
20
14
|
constructor(private repo: SeptumRepository, private projectRoot: string = process.cwd(), private ignorePatterns: string[] = [], private verifyMembership = true) {}
|
|
21
15
|
|
|
22
|
-
public async traceAsync(rawQuery: string, maxDepth = 5, signal?: AbortSignal): Promise<VerticalSliceTraceResponse> {
|
|
16
|
+
public async traceAsync(rawQuery: string, maxDepth = 5, signal?: AbortSignal, controllerFile?: string): Promise<VerticalSliceTraceResponse> {
|
|
23
17
|
signal?.throwIfAborted();
|
|
24
18
|
if (this.repo.getMeta("sync_state") === "error" || this.repo.getMeta("sync_state") === "running") {
|
|
25
19
|
return { query: rawQuery, found: false, coverage: "partial", diagnostics: ["index_incomplete"], message: "Workspace synchronization is incomplete." };
|
|
26
20
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
inputsChanged = inputs.some(input => {
|
|
32
|
-
signal?.throwIfAborted();
|
|
33
|
-
assertPathContained(input.path,this.projectRoot,"Semantic source");
|
|
34
|
-
return computeContentHash(readSourceFile(resolve(this.projectRoot,input.path))) !== input.hash;
|
|
35
|
-
});
|
|
36
|
-
if (this.verifyMembership) {
|
|
37
|
-
const files = this.listSourceFiles(this.projectRoot);
|
|
38
|
-
membershipChanged = JSON.stringify(files) !== (this.repo.getMeta("semantic_catalog_files") || "[]");
|
|
39
|
-
}
|
|
40
|
-
} catch { signal?.throwIfAborted(); inputsChanged = true; }
|
|
41
|
-
if (inputsChanged || membershipChanged || this.repo.getAllVerticalSlices().length === 0 || this.repo.getMeta("slices_dirty") === "1") {
|
|
21
|
+
const inventory = this.verifyMembership ? scanSourceFiles(this.projectRoot, { ignorePatterns: this.ignorePatterns, signal }) : undefined;
|
|
22
|
+
const files = inventory?.files.map(file => relative(this.projectRoot, file).replace(/\\/g, "/"));
|
|
23
|
+
const membershipChanged = files !== undefined && JSON.stringify(files) !== this.repo.getMeta("semantic_catalog_files");
|
|
24
|
+
if (membershipChanged || !sliceInputsCurrent(this.repo, this.projectRoot, signal) || this.repo.getMeta("slices_dirty") === "1") {
|
|
42
25
|
try {
|
|
43
|
-
|
|
44
|
-
const extracted = await collectSourceSkips(this.projectRoot, async () => {
|
|
45
|
-
const slices = await SemanticSliceExtractorRegistry.extractAllSlices(this.projectRoot,topology.framework,undefined,signal);
|
|
46
|
-
return slices.length ? slices : new CallGraphTracer(this.repo,this.projectRoot).traceAllSlices(maxDepth);
|
|
47
|
-
});
|
|
48
|
-
signal?.throwIfAborted();
|
|
49
|
-
if (extracted.skipped.length) throw new Error("Semantic source exceeds read limits; catalog is incomplete.");
|
|
50
|
-
this.repo.runInTransaction(() => {
|
|
51
|
-
signal?.throwIfAborted();
|
|
52
|
-
this.repo.clearVerticalSlices();
|
|
53
|
-
for (const slice of extracted.value) this.repo.upsertVerticalSlice(slice);
|
|
54
|
-
this.repo.setMeta("slices_dirty", "");
|
|
55
|
-
this.repo.setMeta("semantic_inputs", JSON.stringify(extracted.inputs));
|
|
56
|
-
if (this.verifyMembership) this.repo.setMeta("semantic_catalog_files", JSON.stringify(this.listSourceFiles(this.projectRoot)));
|
|
57
|
-
});
|
|
26
|
+
await rebuildSliceCatalog(this.repo, this.projectRoot, { ignorePatterns: this.ignorePatterns, signal });
|
|
58
27
|
} catch (error) {
|
|
59
28
|
signal?.throwIfAborted();
|
|
60
|
-
this.repo.setMeta("slices_dirty", "1");
|
|
61
29
|
return { query: rawQuery, found: false, coverage: "partial", diagnostics: [error instanceof Error ? error.message : String(error)], message: "Semantic extraction failed; no complete catalog was published." };
|
|
62
30
|
}
|
|
63
31
|
}
|
|
64
|
-
return this.trace(rawQuery,maxDepth);
|
|
32
|
+
return this.trace(rawQuery,maxDepth,controllerFile);
|
|
65
33
|
}
|
|
66
34
|
|
|
67
|
-
private listSourceFiles(root: string): string[] {
|
|
68
|
-
const files: string[] = [];
|
|
69
|
-
const walk = (dir: string) => {
|
|
70
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
71
|
-
const fullPath = join(dir, entry.name);
|
|
72
|
-
const relPath = relative(root, fullPath).replace(/\\/g, "/");
|
|
73
|
-
if (shouldIgnoreSourcePath(relPath, this.ignorePatterns)) continue;
|
|
74
|
-
if (entry.isDirectory()) walk(fullPath);
|
|
75
|
-
else if (entry.isFile() && ASTParserEngine.isSourceFile(fullPath)) files.push(relPath);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
walk(root);
|
|
79
|
-
return files.sort();
|
|
80
|
-
}
|
|
81
35
|
|
|
82
36
|
/**
|
|
83
37
|
* Trace an end-to-end vertical slice from route/action/intent query.
|
|
@@ -91,18 +45,19 @@ export class VerticalSliceTracer {
|
|
|
91
45
|
* - "Ubah status order di dashboard"
|
|
92
46
|
*/
|
|
93
47
|
// Synchronous compatibility API reads persisted slices only; use traceAsync for on-demand extraction.
|
|
94
|
-
public trace(rawQuery: string, maxDepth: number = 5): VerticalSliceTraceResponse {
|
|
48
|
+
public trace(rawQuery: string, maxDepth: number = 5, controllerFile?: string): VerticalSliceTraceResponse {
|
|
95
49
|
const effectiveMaxDepth = Math.min(Math.max(Math.trunc(maxDepth || 5), 1), 8);
|
|
96
50
|
const trimmed = rawQuery.trim();
|
|
97
51
|
const lowerTrimmed = trimmed.toLowerCase();
|
|
98
|
-
|
|
52
|
+
const allSlices = this.repo.getAllVerticalSlices().filter(slice => !controllerFile || slice.controller_file === controllerFile);
|
|
99
53
|
|
|
100
54
|
if (allSlices.length === 0) {
|
|
101
55
|
return {
|
|
102
56
|
query: trimmed,
|
|
103
57
|
found: false,
|
|
58
|
+
coverage: "partial",
|
|
104
59
|
max_depth_applied: effectiveMaxDepth,
|
|
105
|
-
message: "No vertical slices cataloged. Run 'septum sync' to extract framework routes and MVC slices.",
|
|
60
|
+
message: controllerFile ? "No catalog target matches controller_file. Copy an exact file from the candidates or omit the filter." : "No vertical slices cataloged. Run 'septum sync' to extract framework routes and MVC slices.",
|
|
106
61
|
};
|
|
107
62
|
}
|
|
108
63
|
|
|
@@ -117,12 +72,12 @@ export class VerticalSliceTracer {
|
|
|
117
72
|
return this.formatSuccessResponse(trimmed, literal[0], "exact", undefined, effectiveMaxDepth);
|
|
118
73
|
}
|
|
119
74
|
if (literal.length > 1 || candidates.length > 1) {
|
|
120
|
-
return this.
|
|
75
|
+
return this.ambiguousResponse(trimmed, literal.length ? literal : candidates, effectiveMaxDepth);
|
|
121
76
|
}
|
|
122
77
|
if (candidates.length === 1) {
|
|
123
78
|
return this.formatSuccessResponse(trimmed, candidates[0], "inferred", undefined, effectiveMaxDepth);
|
|
124
79
|
}
|
|
125
|
-
return { query: trimmed, found: false, max_depth_applied: effectiveMaxDepth, message: `No vertical slice found matching query '${trimmed}'.` };
|
|
80
|
+
return { query: trimmed, found: false, coverage: "partial", max_depth_applied: effectiveMaxDepth, message: `No vertical slice found matching query '${trimmed}'.` };
|
|
126
81
|
}
|
|
127
82
|
|
|
128
83
|
// 2. URI-only match: "/orders" or "orders/{id}"
|
|
@@ -133,16 +88,16 @@ export class VerticalSliceTracer {
|
|
|
133
88
|
if (uriMatches.length === 1) {
|
|
134
89
|
return this.formatSuccessResponse(trimmed, uriMatches[0], confidence, undefined, effectiveMaxDepth);
|
|
135
90
|
}
|
|
136
|
-
|
|
137
|
-
return this.formatSuccessResponse(trimmed, uriMatches[0], confidence, uriMatches.slice(1), effectiveMaxDepth);
|
|
91
|
+
return this.ambiguousResponse(trimmed, uriMatches, effectiveMaxDepth);
|
|
138
92
|
}
|
|
139
93
|
|
|
140
94
|
// 3. Named Route match: "orders.status.update" or "admin.users.index"
|
|
141
|
-
const
|
|
95
|
+
const nameMatches = allSlices.filter(
|
|
142
96
|
(s) => s.route_name && s.route_name.toLowerCase() === lowerTrimmed
|
|
143
97
|
);
|
|
144
|
-
if (
|
|
145
|
-
return this.
|
|
98
|
+
if (nameMatches.length) {
|
|
99
|
+
return nameMatches.length > 1 ? this.ambiguousResponse(trimmed, nameMatches, effectiveMaxDepth)
|
|
100
|
+
: this.formatSuccessResponse(trimmed, nameMatches[0], "exact", undefined, effectiveMaxDepth);
|
|
146
101
|
}
|
|
147
102
|
|
|
148
103
|
// 3b. Omni-Trigger Match: "JOB ProcessOrderJob", "job:ProcessOrderJob", "CLI order:cleanup", "EVENT OrderPlacedListener"
|
|
@@ -150,15 +105,16 @@ export class VerticalSliceTracer {
|
|
|
150
105
|
if (omniTriggerMatch) {
|
|
151
106
|
const triggerKind = omniTriggerMatch[1].toUpperCase();
|
|
152
107
|
const targetName = omniTriggerMatch[2].toLowerCase();
|
|
153
|
-
const exact = allSlices.
|
|
108
|
+
const exact = allSlices.filter(
|
|
154
109
|
(s) =>
|
|
155
110
|
s.http_method.toUpperCase() === triggerKind &&
|
|
156
111
|
(s.controller_class.toLowerCase() === targetName ||
|
|
157
112
|
s.route_uri.toLowerCase() === targetName ||
|
|
158
113
|
s.route_uri.toLowerCase() === `${triggerKind.toLowerCase()}:${targetName}`)
|
|
159
114
|
);
|
|
160
|
-
if (exact) {
|
|
161
|
-
return this.
|
|
115
|
+
if (exact.length) {
|
|
116
|
+
return exact.length > 1 ? this.ambiguousResponse(trimmed, exact, effectiveMaxDepth)
|
|
117
|
+
: this.formatSuccessResponse(trimmed, exact[0], "exact", undefined, effectiveMaxDepth);
|
|
162
118
|
}
|
|
163
119
|
}
|
|
164
120
|
|
|
@@ -170,7 +126,7 @@ export class VerticalSliceTracer {
|
|
|
170
126
|
const lowerCtrl = ctrl.toLowerCase();
|
|
171
127
|
const lowerAct = act ? act.toLowerCase() : undefined;
|
|
172
128
|
|
|
173
|
-
const exact = allSlices.
|
|
129
|
+
const exact = allSlices.filter((s) => {
|
|
174
130
|
const sCtrlLower = s.controller_class.toLowerCase();
|
|
175
131
|
const ctrlMatch =
|
|
176
132
|
sCtrlLower === lowerCtrl ||
|
|
@@ -183,18 +139,20 @@ export class VerticalSliceTracer {
|
|
|
183
139
|
}
|
|
184
140
|
return true;
|
|
185
141
|
});
|
|
186
|
-
if (exact) {
|
|
187
|
-
return this.
|
|
142
|
+
if (exact.length) {
|
|
143
|
+
return exact.length > 1 ? this.ambiguousResponse(trimmed, exact, effectiveMaxDepth)
|
|
144
|
+
: this.formatSuccessResponse(trimmed, exact[0], "exact", undefined, effectiveMaxDepth);
|
|
188
145
|
}
|
|
189
146
|
}
|
|
190
147
|
|
|
191
148
|
// 5. Symbol Match in Execution Chain or Action Name (e.g. "createOrder", "CreateOrderUseCase", "OrderController")
|
|
192
|
-
|
|
149
|
+
let invalidChains = false;
|
|
150
|
+
const symbolMatches = allSlices.filter((s) => {
|
|
193
151
|
if (s.action_name.toLowerCase() === lowerTrimmed) return true;
|
|
194
152
|
if (s.controller_class.toLowerCase() === lowerTrimmed) return true;
|
|
195
153
|
if (s.execution_chain_json) {
|
|
196
154
|
try {
|
|
197
|
-
const chain
|
|
155
|
+
const chain = this.parseChain(s.execution_chain_json);
|
|
198
156
|
return chain.some(
|
|
199
157
|
(node) =>
|
|
200
158
|
node.symbol.toLowerCase() === lowerTrimmed ||
|
|
@@ -202,13 +160,15 @@ export class VerticalSliceTracer {
|
|
|
202
160
|
(node.file && node.file.toLowerCase().includes(lowerTrimmed))
|
|
203
161
|
);
|
|
204
162
|
} catch {
|
|
163
|
+
invalidChains = true;
|
|
205
164
|
return false;
|
|
206
165
|
}
|
|
207
166
|
}
|
|
208
167
|
return false;
|
|
209
168
|
});
|
|
210
|
-
if (
|
|
211
|
-
return this.
|
|
169
|
+
if (symbolMatches.length) {
|
|
170
|
+
return symbolMatches.length > 1 ? this.ambiguousResponse(trimmed, symbolMatches, effectiveMaxDepth)
|
|
171
|
+
: this.formatSuccessResponse(trimmed, symbolMatches[0], "inferred", undefined, effectiveMaxDepth);
|
|
212
172
|
}
|
|
213
173
|
|
|
214
174
|
// 6. Semantic / Token Scoring for Natural Language (e.g. "Ubah status order di dashboard")
|
|
@@ -237,6 +197,8 @@ export class VerticalSliceTracer {
|
|
|
237
197
|
.sort((a, b) => b.score - a.score);
|
|
238
198
|
|
|
239
199
|
if (scoredSlices.length > 0) {
|
|
200
|
+
const tied = scoredSlices.filter(item => item.score === scoredSlices[0].score);
|
|
201
|
+
if (tied.length > 1) return this.ambiguousResponse(trimmed, tied.map(item => item.slice), effectiveMaxDepth);
|
|
240
202
|
const primary = scoredSlices[0].slice;
|
|
241
203
|
const alternatives = scoredSlices.slice(1, 4).map((item) => item.slice);
|
|
242
204
|
return this.formatSuccessResponse(trimmed, primary, "inferred", alternatives, effectiveMaxDepth);
|
|
@@ -245,6 +207,9 @@ export class VerticalSliceTracer {
|
|
|
245
207
|
return {
|
|
246
208
|
query: trimmed,
|
|
247
209
|
found: false,
|
|
210
|
+
coverage: "partial",
|
|
211
|
+
diagnostics: invalidChains ? ["invalid_execution_chain"] : undefined,
|
|
212
|
+
next: invalidChains ? ["Run septum sync to rebuild the catalog before relying on a negative symbol search."] : undefined,
|
|
248
213
|
max_depth_applied: effectiveMaxDepth,
|
|
249
214
|
alternatives: allSlices.slice(0, 5).map((s) => ({
|
|
250
215
|
method: s.http_method,
|
|
@@ -256,6 +221,30 @@ export class VerticalSliceTracer {
|
|
|
256
221
|
};
|
|
257
222
|
}
|
|
258
223
|
|
|
224
|
+
private ambiguousResponse(query: string, candidates: VerticalSliceRecord[], maxDepth: number): VerticalSliceTraceResponse {
|
|
225
|
+
const alternatives = candidates.map(candidate => ({ method: candidate.http_method, uri: candidate.route_uri,
|
|
226
|
+
controller: candidate.controller_class, action: candidate.action_name, file: candidate.controller_file,
|
|
227
|
+
line: candidate.controller_line })).sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
|
|
228
|
+
return { query, found: false, coverage: "partial", diagnostics: ["ambiguous_target"],
|
|
229
|
+
max_depth_applied: maxDepth, alternatives: alternatives.slice(0, 20),
|
|
230
|
+
candidate_count: alternatives.length, alternatives_omitted: Math.max(0, alternatives.length - 20),
|
|
231
|
+
next: ["Narrow the query to METHOD /route or Controller@action and controller_file copied from a candidate. If candidates remain identical, inspect their source declarations."],
|
|
232
|
+
message: "Multiple catalog targets match; no entrypoint or chain was selected." };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private parseChain(serialized: string): ExecutionChainNode[] {
|
|
236
|
+
const chain: unknown = JSON.parse(serialized);
|
|
237
|
+
if (!Array.isArray(chain) || chain.some(node => !node || typeof node !== "object" ||
|
|
238
|
+
typeof node.stage !== "string" || typeof node.symbol !== "string" ||
|
|
239
|
+
(node.file !== undefined && typeof node.file !== "string") ||
|
|
240
|
+
(node.description !== undefined && typeof node.description !== "string") ||
|
|
241
|
+
["guards", "mutations", "emits", "dispatches"].some(key => node[key] !== undefined &&
|
|
242
|
+
(!Array.isArray(node[key]) || node[key].some((value: unknown) => typeof value !== "string"))))) {
|
|
243
|
+
throw new Error("Invalid execution chain shape");
|
|
244
|
+
}
|
|
245
|
+
return chain;
|
|
246
|
+
}
|
|
247
|
+
|
|
259
248
|
private urisMatch(uriA: string, uriB: string): boolean {
|
|
260
249
|
const normA = uriA
|
|
261
250
|
.replace(/\{[^}]+\}/g, ":param")
|
|
@@ -283,62 +272,51 @@ export class VerticalSliceTracer {
|
|
|
283
272
|
effectiveMaxDepth: number = 5
|
|
284
273
|
): VerticalSliceTraceResponse {
|
|
285
274
|
let chain: ExecutionChainNode[] = [];
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
console.error(`[Septum Slice Error] Corrupted execution chain JSON for slice ${record.id}: ${msg}`);
|
|
292
|
-
}
|
|
275
|
+
const diagnostics: string[] = [];
|
|
276
|
+
try {
|
|
277
|
+
chain = this.parseChain(record.execution_chain_json);
|
|
278
|
+
} catch {
|
|
279
|
+
diagnostics.push("invalid_execution_chain");
|
|
293
280
|
}
|
|
294
281
|
|
|
295
282
|
// Import expansion is derived per request, so cached depth cannot override the requested hop limit.
|
|
296
283
|
chain = chain.filter(node => node.relationship?.kind !== "imports" && !node.description?.includes("(dependency)"));
|
|
284
|
+
// Go imports resolve whole packages; expanding them injects unrelated handlers/services.
|
|
297
285
|
if (
|
|
298
|
-
record.controller_file &&
|
|
286
|
+
record.architecture_style !== "go-http" && !diagnostics.length && record.controller_file &&
|
|
299
287
|
typeof (this.repo as any).getAllFiles === "function"
|
|
300
288
|
) {
|
|
301
289
|
try {
|
|
302
290
|
const callGraphTracer = new CallGraphTracer(this.repo, this.projectRoot);
|
|
303
|
-
chain =
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
291
|
+
chain = record.action_name
|
|
292
|
+
? callGraphTracer.expandChainFromMethod(
|
|
293
|
+
record.controller_file,
|
|
294
|
+
record.action_name,
|
|
295
|
+
chain,
|
|
296
|
+
effectiveMaxDepth
|
|
297
|
+
)
|
|
298
|
+
: callGraphTracer.expandChainFromFile(
|
|
299
|
+
record.controller_file,
|
|
300
|
+
chain,
|
|
301
|
+
effectiveMaxDepth
|
|
302
|
+
);
|
|
308
303
|
} catch {
|
|
309
|
-
|
|
304
|
+
diagnostics.push("dependency_expansion_failed");
|
|
310
305
|
}
|
|
311
306
|
}
|
|
312
307
|
|
|
313
|
-
let message = `Vertical slice
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
const stageLabel = `[${node.stage.toUpperCase()}]`.padEnd(14, " ");
|
|
317
|
-
const loc = node.file ? ` (${node.file}${node.line ? `:${node.line}` : ""})` : "";
|
|
318
|
-
let extra = "";
|
|
319
|
-
if (node.table) {
|
|
320
|
-
extra += ` [table: ${node.table}]`;
|
|
321
|
-
}
|
|
322
|
-
if (node.columns_summary) {
|
|
323
|
-
extra += ` {${node.columns_summary}}`;
|
|
324
|
-
}
|
|
325
|
-
if (node.guards && node.guards.length > 0 && node.stage !== "guard") {
|
|
326
|
-
extra += ` [guards: ${node.guards.join(", ")}]`;
|
|
327
|
-
}
|
|
328
|
-
if (node.mutations && node.mutations.length > 0 && node.stage !== "side_effect") {
|
|
329
|
-
extra += ` [mutates: ${node.mutations.join(", ")}]`;
|
|
330
|
-
}
|
|
331
|
-
if (node.transactions && node.stage !== "transaction") {
|
|
332
|
-
extra += ` [tx: active]`;
|
|
333
|
-
}
|
|
334
|
-
return `${stageLabel} ${node.symbol}${loc}${extra}`;
|
|
335
|
-
});
|
|
336
|
-
message = `=== VERTICAL SLICE TRACE (${confidence.toUpperCase()}) ===\n` + stageLines.join("\n");
|
|
308
|
+
let message = `Vertical slice target match (${confidence}): ${record.http_method} ${record.route_uri} -> ${record.controller_class}@${record.action_name} (${chain.length} node(s)).`;
|
|
309
|
+
if (record.architecture_style === "go-http") {
|
|
310
|
+
message += " Go package import expansion is omitted; extracted handler/service relationships remain lexical and partial.";
|
|
337
311
|
}
|
|
312
|
+
if (diagnostics.length) message += ` Analysis incomplete: ${diagnostics.join(", ")}. Run septum sync and retry; inspect source if it persists.`;
|
|
338
313
|
|
|
339
314
|
return {
|
|
340
315
|
query,
|
|
341
316
|
found: true,
|
|
317
|
+
coverage: "partial",
|
|
318
|
+
diagnostics: diagnostics.length ? diagnostics : undefined,
|
|
319
|
+
next: diagnostics.length ? ["Run septum sync to rebuild analysis; retry the query. Inspect source directly if the diagnostic persists."] : undefined,
|
|
342
320
|
confidence,
|
|
343
321
|
is_exact_match: confidence === "exact",
|
|
344
322
|
architecture_style: record.architecture_style,
|
|
@@ -4,10 +4,22 @@ export const DEFAULT_IGNORED_DIRECTORIES: ReadonlySet<string> = new Set([
|
|
|
4
4
|
"vendor",
|
|
5
5
|
"bower_components",
|
|
6
6
|
"jspm_packages",
|
|
7
|
+
"deps",
|
|
8
|
+
"packages",
|
|
9
|
+
".bundle",
|
|
10
|
+
".cargo",
|
|
11
|
+
".gradle",
|
|
12
|
+
".m2",
|
|
13
|
+
".mvn",
|
|
14
|
+
".nuget",
|
|
15
|
+
".dart_tool",
|
|
16
|
+
".pub-cache",
|
|
17
|
+
".pub",
|
|
7
18
|
|
|
8
19
|
// Build, bundle & compilation outputs (visible & hidden)
|
|
9
20
|
"dist",
|
|
10
21
|
"build",
|
|
22
|
+
"_build",
|
|
11
23
|
"out",
|
|
12
24
|
"output",
|
|
13
25
|
".output",
|
|
@@ -15,6 +27,8 @@ export const DEFAULT_IGNORED_DIRECTORIES: ReadonlySet<string> = new Set([
|
|
|
15
27
|
"obj",
|
|
16
28
|
"bin",
|
|
17
29
|
"scripts",
|
|
30
|
+
"zig-out",
|
|
31
|
+
".zig-cache",
|
|
18
32
|
".next",
|
|
19
33
|
".nuxt",
|
|
20
34
|
".turbo",
|
|
@@ -23,7 +37,7 @@ export const DEFAULT_IGNORED_DIRECTORIES: ReadonlySet<string> = new Set([
|
|
|
23
37
|
".astro",
|
|
24
38
|
".docusaurus",
|
|
25
39
|
|
|
26
|
-
// Python virtual environments and bytecode caches
|
|
40
|
+
// Python virtual environments, packaging and bytecode caches
|
|
27
41
|
".venv",
|
|
28
42
|
"venv",
|
|
29
43
|
"env",
|
|
@@ -34,6 +48,8 @@ export const DEFAULT_IGNORED_DIRECTORIES: ReadonlySet<string> = new Set([
|
|
|
34
48
|
".mypy_cache",
|
|
35
49
|
".ruff_cache",
|
|
36
50
|
".tox",
|
|
51
|
+
".nox",
|
|
52
|
+
".eggs",
|
|
37
53
|
|
|
38
54
|
// Test coverage
|
|
39
55
|
"coverage",
|
|
@@ -64,11 +80,16 @@ export const DEFAULT_IGNORED_DIRECTORIES: ReadonlySet<string> = new Set([
|
|
|
64
80
|
".antigravity",
|
|
65
81
|
".cline",
|
|
66
82
|
".roo",
|
|
83
|
+
".toolbench",
|
|
67
84
|
".windsurf",
|
|
68
85
|
".continue",
|
|
69
86
|
".copilot",
|
|
70
87
|
".chat",
|
|
71
88
|
|
|
89
|
+
// Framework storage & uploads
|
|
90
|
+
"storage",
|
|
91
|
+
"public/storage",
|
|
92
|
+
|
|
72
93
|
// Cache & Temp
|
|
73
94
|
".cache",
|
|
74
95
|
"tmp",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { closeSync, fstatSync, openSync, readSync, statSync } from 'node:fs';
|
|
3
|
-
import { relative } from 'node:path';
|
|
2
|
+
import { closeSync, fstatSync, openSync, readSync, statSync, realpathSync, readdirSync, type Dirent } from 'node:fs';
|
|
3
|
+
import { relative, resolve } from 'node:path';
|
|
4
4
|
import { computeContentHash } from "../ingestion/hasher.ts";
|
|
5
5
|
import { RESOURCE_LIMITS } from './limits.ts';
|
|
6
6
|
|
|
@@ -9,21 +9,120 @@ export class SourceFileLimitError extends Error {
|
|
|
9
9
|
constructor(public readonly filePath: string) { super(`Source file exceeds ${RESOURCE_LIMITS.sourceBytes} bytes: ${filePath}`); }
|
|
10
10
|
}
|
|
11
11
|
export interface SourceReadFingerprint { path: string; hash: string; size: number; mtime: number }
|
|
12
|
-
const
|
|
12
|
+
export const SOURCE_READ_REVISION = "4";
|
|
13
|
+
type SourcePathKind = 'missing' | 'file' | 'directory' | 'other';
|
|
14
|
+
export interface SourcePathObservation { path: string; kind: SourcePathKind; real_path?: string }
|
|
15
|
+
export interface SourceDirectoryObservation { path: string; entries: string[] }
|
|
16
|
+
export interface SourceObservations { paths: SourcePathObservation[]; directories: SourceDirectoryObservation[] }
|
|
17
|
+
type SourceCollector = {
|
|
18
|
+
skipped: Map<string, SkippedSourceFile>;
|
|
19
|
+
inputs: Map<string, SourceReadFingerprint>;
|
|
20
|
+
conflicts: Set<string>;
|
|
21
|
+
paths: Map<string, SourcePathObservation>;
|
|
22
|
+
directories: Map<string, SourceDirectoryObservation>;
|
|
23
|
+
};
|
|
24
|
+
const reads = new AsyncLocalStorage<SourceCollector>();
|
|
25
|
+
|
|
26
|
+
function pathObservation(filePath: string): SourcePathObservation {
|
|
27
|
+
const path = resolve(filePath);
|
|
28
|
+
try {
|
|
29
|
+
const stat = statSync(path);
|
|
30
|
+
return { path, kind: stat.isFile() ? 'file' : stat.isDirectory() ? 'directory' : 'other', real_path: realpathSync(path) };
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (['ENOENT', 'ENOTDIR'].includes((error as NodeJS.ErrnoException).code ?? '')) return { path, kind: 'missing' };
|
|
33
|
+
throw error; // Permission/read errors are not negative resolution evidence.
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Track existence/type and symlink destination, including negative lookups. */
|
|
38
|
+
export function probeSourcePath(filePath: string): SourcePathKind {
|
|
39
|
+
const observation = pathObservation(filePath);
|
|
40
|
+
const collector = reads.getStore();
|
|
41
|
+
if (collector) {
|
|
42
|
+
const prior = collector.paths.get(observation.path);
|
|
43
|
+
if (prior && JSON.stringify(prior) !== JSON.stringify(observation)) collector.conflicts.add(observation.path);
|
|
44
|
+
if (!prior) collector.paths.set(observation.path, observation);
|
|
45
|
+
}
|
|
46
|
+
return observation.kind;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function directoryEntries(entries: Dirent[]): string[] {
|
|
50
|
+
return entries.map(entry => `${entry.isDirectory() ? 'directory' : entry.isFile() ? 'file' : entry.isSymbolicLink() ? 'symlink' : 'other'}:${entry.name}`).sort();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Track the membership actually enumerated, not just a directory's mtime. */
|
|
54
|
+
export function readSourceDirectory(directory: string): Dirent[] {
|
|
55
|
+
probeSourcePath(directory);
|
|
56
|
+
const entries = readdirSync(directory, { withFileTypes: true });
|
|
57
|
+
const collector = reads.getStore();
|
|
58
|
+
if (collector) {
|
|
59
|
+
const path = resolve(directory);
|
|
60
|
+
const observation = { path, entries: directoryEntries(entries) };
|
|
61
|
+
const prior = collector.directories.get(path);
|
|
62
|
+
if (prior && JSON.stringify(prior.entries) !== JSON.stringify(observation.entries)) collector.conflicts.add(path);
|
|
63
|
+
if (!prior) collector.directories.set(path, observation);
|
|
64
|
+
}
|
|
65
|
+
return entries;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Revalidate a persisted manifest without collecting these validation reads. */
|
|
69
|
+
export function sourceObservationsCurrent(root: string, observations: SourceObservations): boolean {
|
|
70
|
+
try {
|
|
71
|
+
for (const observation of observations.paths) {
|
|
72
|
+
const path = resolve(root, observation.path);
|
|
73
|
+
const current = pathObservation(path);
|
|
74
|
+
if (current.kind !== observation.kind || current.real_path !== observation.real_path) return false;
|
|
75
|
+
}
|
|
76
|
+
for (const observation of observations.directories) {
|
|
77
|
+
const entries = directoryEntries(readdirSync(resolve(root, observation.path), { withFileTypes: true }));
|
|
78
|
+
if (JSON.stringify(entries) !== JSON.stringify(observation.entries)) return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
} catch { return false; }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function recordInput(filePath: string, hash: string, size: number, mtime: number): void {
|
|
85
|
+
const collector = reads.getStore();
|
|
86
|
+
if (!collector) return;
|
|
87
|
+
const path = resolve(filePath);
|
|
88
|
+
const prior = collector.inputs.get(path);
|
|
89
|
+
if (prior && prior.hash !== hash) collector.conflicts.add(path);
|
|
90
|
+
// Keep the first version: a subsequent read must not hide already-derived facts.
|
|
91
|
+
if (!prior) collector.inputs.set(path, { path, hash, size, mtime });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function recordSkippedInput(filePath: string, size: number, mtime: number): void {
|
|
95
|
+
const collector = reads.getStore();
|
|
96
|
+
if (!collector) return;
|
|
97
|
+
collector.skipped.set(resolve(filePath), { path: resolve(filePath), reason: 'file_too_large' });
|
|
98
|
+
recordInput(filePath, 'file_too_large', size, mtime);
|
|
99
|
+
}
|
|
13
100
|
|
|
14
101
|
// Read at most the admission limit, even if the file grows after stat.
|
|
15
102
|
export function readSourceFile(filePath: string, _encoding?: string): string {
|
|
16
103
|
const fd = openSync(filePath, 'r');
|
|
17
104
|
try {
|
|
18
|
-
const
|
|
19
|
-
|
|
105
|
+
const stat = fstatSync(fd);
|
|
106
|
+
const size = stat.size;
|
|
107
|
+
if (size > RESOURCE_LIMITS.sourceBytes) {
|
|
108
|
+
recordSkippedInput(filePath, size, stat.mtimeMs);
|
|
109
|
+
throw new SourceFileLimitError(filePath);
|
|
110
|
+
}
|
|
20
111
|
let buffer = Buffer.allocUnsafe(Math.min(Math.max(size + 1, 4096), RESOURCE_LIMITS.sourceBytes + 1));
|
|
21
112
|
let count = 0;
|
|
22
113
|
while (true) {
|
|
23
114
|
const read = readSync(fd, buffer, count, buffer.length - count, null);
|
|
24
|
-
if (!read)
|
|
115
|
+
if (!read) {
|
|
116
|
+
const content = buffer.toString('utf8', 0, count);
|
|
117
|
+
if (reads.getStore()) recordInput(filePath, computeContentHash(content), size, stat.mtimeMs);
|
|
118
|
+
return content;
|
|
119
|
+
}
|
|
25
120
|
count += read;
|
|
26
|
-
if (count > RESOURCE_LIMITS.sourceBytes)
|
|
121
|
+
if (count > RESOURCE_LIMITS.sourceBytes) {
|
|
122
|
+
const current = fstatSync(fd);
|
|
123
|
+
recordSkippedInput(filePath, current.size, current.mtimeMs);
|
|
124
|
+
throw new SourceFileLimitError(filePath);
|
|
125
|
+
}
|
|
27
126
|
if (count === buffer.length) {
|
|
28
127
|
const expanded = Buffer.allocUnsafe(Math.min(buffer.length * 2, RESOURCE_LIMITS.sourceBytes + 1));
|
|
29
128
|
buffer.copy(expanded, 0, 0, count);
|
|
@@ -35,28 +134,52 @@ export function readSourceFile(filePath: string, _encoding?: string): string {
|
|
|
35
134
|
|
|
36
135
|
export function readOptionalSourceFile(filePath: string, encoding?: string): string {
|
|
37
136
|
try {
|
|
38
|
-
|
|
39
|
-
const collector = reads.getStore();
|
|
40
|
-
if (collector) {
|
|
41
|
-
const stat = statSync(filePath);
|
|
42
|
-
collector.inputs.set(filePath, {path:filePath,hash:computeContentHash(content),size:stat.size,mtime:stat.mtimeMs});
|
|
43
|
-
}
|
|
44
|
-
return content;
|
|
137
|
+
return readSourceFile(filePath, encoding);
|
|
45
138
|
}
|
|
46
139
|
catch (error) {
|
|
47
140
|
if (!(error instanceof SourceFileLimitError)) throw error;
|
|
48
141
|
const collector = reads.getStore();
|
|
49
142
|
if (!collector) throw error;
|
|
50
|
-
collector.skipped.set(filePath, { path: filePath, reason: 'file_too_large' });
|
|
51
143
|
const stat = statSync(filePath);
|
|
52
|
-
|
|
144
|
+
recordSkippedInput(filePath, stat.size, stat.mtimeMs);
|
|
53
145
|
return '';
|
|
54
146
|
}
|
|
55
147
|
}
|
|
56
148
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
149
|
+
function createSourceCollector(): SourceCollector {
|
|
150
|
+
return { skipped: new Map(), inputs: new Map(), conflicts: new Set(), paths: new Map(), directories: new Map() };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function finalizeSourceCollection<T>(root: string, collector: SourceCollector, value: T) {
|
|
154
|
+
for (const input of collector.inputs.values()) {
|
|
155
|
+
let changed = collector.conflicts.has(input.path);
|
|
156
|
+
try {
|
|
157
|
+
if (input.hash === 'file_too_large') {
|
|
158
|
+
const stat = statSync(input.path);
|
|
159
|
+
changed ||= stat.size !== input.size || stat.mtimeMs !== input.mtime || stat.size <= RESOURCE_LIMITS.sourceBytes;
|
|
160
|
+
} else {
|
|
161
|
+
changed ||= computeContentHash(readSourceFile(input.path)) !== input.hash;
|
|
162
|
+
}
|
|
163
|
+
} catch { changed = true; }
|
|
164
|
+
if (changed) throw new Error(`Source changed during synchronization: ${relative(root, input.path)} changed during analysis. Retry against stable inputs.`);
|
|
165
|
+
}
|
|
166
|
+
if (collector.conflicts.size || !sourceObservationsCurrent(root, { paths: [...collector.paths.values()], directories: [...collector.directories.values()] })) {
|
|
167
|
+
throw new Error('Source changed during synchronization: resolution path or directory observations changed during analysis. Retry against stable inputs.');
|
|
168
|
+
}
|
|
60
169
|
const rel = (file: {path:string}) => relative(root, file.path).replace(/\\/g, '/');
|
|
61
|
-
return {value, skipped:[...collector.skipped.values()].map(file => ({...file,path:rel(file)})), inputs:[...collector.inputs.values()].map(file => ({...file,path:rel(file)}))
|
|
170
|
+
return {value, skipped:[...collector.skipped.values()].map(file => ({...file,path:rel(file)})).sort((a,b)=>a.path.localeCompare(b.path)), inputs:[...collector.inputs.values()].map(file => ({...file,path:rel(file)})).sort((a,b)=>a.path.localeCompare(b.path)),
|
|
171
|
+
observations: {
|
|
172
|
+
paths: [...collector.paths.values()].map(item => ({ ...item, path: rel(item) })).sort((a,b)=>a.path.localeCompare(b.path)),
|
|
173
|
+
directories: [...collector.directories.values()].map(item => ({ ...item, path: rel(item) })).sort((a,b)=>a.path.localeCompare(b.path)),
|
|
174
|
+
} };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function collectSourceSkipsSync<T>(root: string, read: () => T) {
|
|
178
|
+
const collector = createSourceCollector();
|
|
179
|
+
return finalizeSourceCollection(root, collector, reads.run(collector, read));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export async function collectSourceSkips<T>(root: string, read: () => Promise<T>) {
|
|
183
|
+
const collector = createSourceCollector();
|
|
184
|
+
return finalizeSourceCollection(root, collector, await reads.run(collector, read));
|
|
62
185
|
}
|