@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,13 +1,26 @@
|
|
|
1
1
|
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
2
2
|
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
3
4
|
import { resolve } from "node:path";
|
|
4
5
|
import { computeContentHash } from "../../core/ingestion/hasher.ts";
|
|
5
6
|
import { isPathContained } from "../../core/resolver/path-resolver.ts";
|
|
6
7
|
import { readSourceFile } from "../../core/resources/source-files.ts";
|
|
7
8
|
import { SymbolLocator } from "../../core/resolver/symbol-locator.ts";
|
|
8
9
|
import type { GetSymbolArgs } from "../../types/index.ts";
|
|
10
|
+
import { symbolWorkspace, withSymbolEvidence } from "../../core/retrieval/symbol-evidence.ts";
|
|
9
11
|
|
|
10
12
|
export function handleGetSymbol(
|
|
13
|
+
repo: SeptumRepository,
|
|
14
|
+
config: ValidatedSeptumConfig,
|
|
15
|
+
args: GetSymbolArgs,
|
|
16
|
+
workspaceRoot?: string
|
|
17
|
+
) {
|
|
18
|
+
const root = symbolWorkspace(repo, workspaceRoot || args.workspace_path);
|
|
19
|
+
return withSymbolEvidence(repo, root, { operation: "inspect", requested: args.symbol_ref },
|
|
20
|
+
() => inspectSymbol(repo, config, args, root));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function inspectSymbol(
|
|
11
24
|
repo: SeptumRepository,
|
|
12
25
|
_config: ValidatedSeptumConfig,
|
|
13
26
|
args: GetSymbolArgs,
|
|
@@ -55,7 +68,29 @@ export function handleGetSymbol(
|
|
|
55
68
|
});
|
|
56
69
|
|
|
57
70
|
if (details) {
|
|
58
|
-
const payload: Record<string, unknown> = { ...details };
|
|
71
|
+
const payload: Record<string, unknown> = { ...details, context_mode: "source" };
|
|
72
|
+
if (args.include_source === false) {
|
|
73
|
+
if (Array.isArray(payload.relationships)) {
|
|
74
|
+
const allRels = payload.relationships as Array<any>;
|
|
75
|
+
const maxRels = 20;
|
|
76
|
+
payload.relationships = allRels.slice(0, maxRels).map((edge) => ({
|
|
77
|
+
target: edge?.resolution?.source?.target ?? edge?.target,
|
|
78
|
+
line: edge?.source?.line ?? edge?.line,
|
|
79
|
+
status: edge?.resolution?.status,
|
|
80
|
+
reason: edge?.resolution?.reason,
|
|
81
|
+
resolved_files: Array.isArray(edge?.resolution?.targets)
|
|
82
|
+
? edge.resolution.targets.flatMap((t: any) => t.files ?? [])
|
|
83
|
+
: [],
|
|
84
|
+
}));
|
|
85
|
+
if (allRels.length > maxRels) {
|
|
86
|
+
payload.relationships_omitted = allRels.length - maxRels;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(payload.connected_files) && payload.connected_files.length > 20) {
|
|
90
|
+
payload.connected_files_omitted = payload.connected_files.length - 20;
|
|
91
|
+
payload.connected_files = payload.connected_files.slice(0, 20);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
59
94
|
if (args.include_source) {
|
|
60
95
|
delete payload.dependencies_injected;
|
|
61
96
|
delete payload.outbound_calls;
|
|
@@ -106,6 +141,28 @@ export function handleGetSymbol(
|
|
|
106
141
|
} else {
|
|
107
142
|
const endLine = Math.min(details.exact_range.end_line, startLine + limit - 1, lineStarts.length);
|
|
108
143
|
const truncated = endLine < details.exact_range.end_line;
|
|
144
|
+
const sliceText = source.slice(lineStarts[startLine - 1], lineEnds[endLine - 1]);
|
|
145
|
+
const lineCount = endLine - startLine + 1;
|
|
146
|
+
|
|
147
|
+
// 1-hop Transitive Delegator Expansion (Hollow Slicing Prevention)
|
|
148
|
+
let delegatedImpl: {
|
|
149
|
+
symbol: string;
|
|
150
|
+
file_path: string;
|
|
151
|
+
start_line: number;
|
|
152
|
+
end_line: number;
|
|
153
|
+
text: string;
|
|
154
|
+
} | undefined;
|
|
155
|
+
|
|
156
|
+
if (lineCount <= 15 || args.semantic_depth === 2) {
|
|
157
|
+
delegatedImpl = resolveDelegatorImplementation(
|
|
158
|
+
repo,
|
|
159
|
+
root,
|
|
160
|
+
source,
|
|
161
|
+
sliceText,
|
|
162
|
+
details
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
109
166
|
payload.source_slice = {
|
|
110
167
|
status: "current",
|
|
111
168
|
file_path: details.file_path,
|
|
@@ -113,9 +170,10 @@ export function handleGetSymbol(
|
|
|
113
170
|
current_content_hash: currentHash,
|
|
114
171
|
start_line: startLine,
|
|
115
172
|
end_line: endLine,
|
|
116
|
-
text:
|
|
173
|
+
text: sliceText,
|
|
117
174
|
truncated,
|
|
118
|
-
related_dependency_analysis: "omitted_to_keep_source_read_bounded",
|
|
175
|
+
related_dependency_analysis: delegatedImpl ? "delegated_implementation_expanded" : "omitted_to_keep_source_read_bounded",
|
|
176
|
+
...(delegatedImpl ? { delegated_implementation: delegatedImpl } : {}),
|
|
119
177
|
...(truncated ? { next_start_line: endLine + 1 } : {}),
|
|
120
178
|
};
|
|
121
179
|
}
|
|
@@ -173,3 +231,169 @@ export function handleGetSymbol(
|
|
|
173
231
|
],
|
|
174
232
|
};
|
|
175
233
|
}
|
|
234
|
+
|
|
235
|
+
function toPascalCase(identifier: string): string {
|
|
236
|
+
return identifier
|
|
237
|
+
.split("_")
|
|
238
|
+
.filter(Boolean)
|
|
239
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
240
|
+
.join("");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function resolveDelegatorImplementation(
|
|
244
|
+
repo: SeptumRepository,
|
|
245
|
+
root: string,
|
|
246
|
+
sourceCode: string,
|
|
247
|
+
sliceText: string,
|
|
248
|
+
details: any
|
|
249
|
+
): { symbol: string; file_path: string; start_line: number; end_line: number; text: string } | undefined {
|
|
250
|
+
// 1. Check for PHP/TS/Python/Go delegator call patterns:
|
|
251
|
+
// $this->property->execute(...) or ->handle(...)
|
|
252
|
+
// this.property.execute(...) or .handle(...)
|
|
253
|
+
// self.property.execute(...) (Python)
|
|
254
|
+
// receiver.property.Execute(...) (Go)
|
|
255
|
+
// ClassName::execute(...) or ClassName::handle(...)
|
|
256
|
+
const phpPropMatch = /\$this->([a-zA-Z0-9_]+)\s*->\s*([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
|
|
257
|
+
const tsPropMatch = /\bthis\.([a-zA-Z0-9_]+)\s*\.\s*([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
|
|
258
|
+
const pySelfMatch = /\bself\.([a-zA-Z0-9_]+)\s*\.\s*([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
|
|
259
|
+
const staticMatch = /([A-Z][a-zA-Z0-9_]*(?:Action|Service|Handler|UseCase))::([a-zA-Z0-9_]+)\s*\(/i.exec(sliceText);
|
|
260
|
+
const goRecvSigMatch = /^func\s*\(\s*([a-zA-Z_]\w*)\s+\*?([A-Za-z_]\w*)(?:\[[^\]]+\])?\s*\)/m.exec(
|
|
261
|
+
details?.signature || sliceText
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
let targetClassName: string | undefined;
|
|
265
|
+
let targetMethodName: string | undefined;
|
|
266
|
+
|
|
267
|
+
if (phpPropMatch) {
|
|
268
|
+
const propName = phpPropMatch[1];
|
|
269
|
+
targetMethodName = phpPropMatch[2];
|
|
270
|
+
|
|
271
|
+
const ctorPropRegex = new RegExp(
|
|
272
|
+
`(?:protected|private|public)\\s+(?:readonly\\s+)?(?:\\\\?[A-Za-z0-9_\\\\]+\\\\)?([A-Z][A-Za-z0-9_]*)\\s+\\\$${propName}\\b`,
|
|
273
|
+
"i"
|
|
274
|
+
);
|
|
275
|
+
const ctorMatch = ctorPropRegex.exec(sourceCode);
|
|
276
|
+
if (ctorMatch) {
|
|
277
|
+
targetClassName = ctorMatch[1];
|
|
278
|
+
} else {
|
|
279
|
+
targetClassName = toPascalCase(propName);
|
|
280
|
+
}
|
|
281
|
+
} else if (tsPropMatch) {
|
|
282
|
+
const propName = tsPropMatch[1];
|
|
283
|
+
targetMethodName = tsPropMatch[2];
|
|
284
|
+
const tsPropRegex = new RegExp(`(?:private|protected|public|readonly)\\s+${propName}\\s*:\\s*([A-Z][A-Za-z0-9_]*)`, "i");
|
|
285
|
+
const tsMatch = tsPropRegex.exec(sourceCode);
|
|
286
|
+
if (tsMatch) {
|
|
287
|
+
targetClassName = tsMatch[1];
|
|
288
|
+
} else {
|
|
289
|
+
targetClassName = toPascalCase(propName);
|
|
290
|
+
}
|
|
291
|
+
} else if (pySelfMatch) {
|
|
292
|
+
const propName = pySelfMatch[1];
|
|
293
|
+
targetMethodName = pySelfMatch[2];
|
|
294
|
+
// Check `self.prop = param` in `__init__` or direct `prop: TypeName` type annotation
|
|
295
|
+
const assignMatch = new RegExp(`\\bself\\.${propName}\\s*=\\s*([a-zA-Z_][a-zA-Z0-9_]*)\\b`).exec(sourceCode);
|
|
296
|
+
const paramName = assignMatch ? assignMatch[1] : propName;
|
|
297
|
+
const typeHintRegex = new RegExp(`\\b(?:self\\.)?${paramName}\\s*:\\s*(?:[a-zA-Z0-9_]+\\.)?([A-Z][A-Za-z0-9_]*)\\b`);
|
|
298
|
+
const pyMatch = typeHintRegex.exec(sourceCode);
|
|
299
|
+
if (pyMatch) {
|
|
300
|
+
targetClassName = pyMatch[1];
|
|
301
|
+
} else {
|
|
302
|
+
targetClassName = toPascalCase(propName);
|
|
303
|
+
}
|
|
304
|
+
} else if (goRecvSigMatch) {
|
|
305
|
+
const recvVar = goRecvSigMatch[1];
|
|
306
|
+
const goPropRegex = new RegExp(`\\b${recvVar}\\.([a-zA-Z_]\\w*)\\s*\\.\\s*([a-zA-Z_]\\w*)\\s*\\(`);
|
|
307
|
+
const goCallMatch = goPropRegex.exec(sliceText);
|
|
308
|
+
if (goCallMatch) {
|
|
309
|
+
const propName = goCallMatch[1];
|
|
310
|
+
targetMethodName = goCallMatch[2];
|
|
311
|
+
const fieldTypeRegex = new RegExp(`\\b${propName}\\s+\\*?(?:[a-zA-Z0-9_]+\\.)?([A-Z][A-Za-z0-9_]*)\\b`);
|
|
312
|
+
const fieldMatch = fieldTypeRegex.exec(sourceCode);
|
|
313
|
+
if (fieldMatch) {
|
|
314
|
+
targetClassName = fieldMatch[1];
|
|
315
|
+
} else {
|
|
316
|
+
targetClassName = toPascalCase(propName);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} else if (staticMatch) {
|
|
320
|
+
targetClassName = staticMatch[1];
|
|
321
|
+
targetMethodName = staticMatch[2];
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (!targetClassName || !targetMethodName) return undefined;
|
|
325
|
+
|
|
326
|
+
const candidateQueries = [
|
|
327
|
+
`${targetClassName}::${targetMethodName}`,
|
|
328
|
+
`${targetClassName}@${targetMethodName}`,
|
|
329
|
+
targetMethodName,
|
|
330
|
+
];
|
|
331
|
+
|
|
332
|
+
let targetSymbol: any = undefined;
|
|
333
|
+
for (const q of candidateQueries) {
|
|
334
|
+
const matches = repo.findSymbolsByName(q);
|
|
335
|
+
const exact = matches.find(
|
|
336
|
+
(m) =>
|
|
337
|
+
(m.name.includes(targetClassName!) ||
|
|
338
|
+
m.symbol_ref?.container === targetClassName ||
|
|
339
|
+
m.symbol_ref?.receiver === targetClassName) &&
|
|
340
|
+
(m.name.endsWith(`::${targetMethodName}`) ||
|
|
341
|
+
m.name.endsWith(`@${targetMethodName}`) ||
|
|
342
|
+
m.name === targetMethodName)
|
|
343
|
+
);
|
|
344
|
+
if (exact) {
|
|
345
|
+
targetSymbol = exact;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
if (q !== targetMethodName && matches.length === 1) {
|
|
349
|
+
targetSymbol = matches[0];
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (!targetSymbol) {
|
|
355
|
+
const classMatches = repo.findSymbolsByName(targetClassName);
|
|
356
|
+
if (classMatches.length >= 1) {
|
|
357
|
+
const cls = classMatches[0];
|
|
358
|
+
const fileSymbols = repo.getSymbolsByFileId(cls.file_id);
|
|
359
|
+
const methodSym = fileSymbols.find(s => s.kind === "method" && (s.name.endsWith(`::${targetMethodName}`) || s.name.endsWith(`@${targetMethodName}`) || s.name === targetMethodName));
|
|
360
|
+
if (methodSym) {
|
|
361
|
+
targetSymbol = { ...methodSym, file_path: cls.file_path };
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (!targetSymbol || !targetSymbol.file_path) return undefined;
|
|
367
|
+
|
|
368
|
+
if (targetSymbol.file_path === details.file_path && targetSymbol.line_start === details.exact_range.start_line) {
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
try {
|
|
373
|
+
const targetFullPath = resolve(root, targetSymbol.file_path);
|
|
374
|
+
if (!existsSync(targetFullPath)) return undefined;
|
|
375
|
+
const targetSource = readSourceFile(targetFullPath);
|
|
376
|
+
const targetStarts = [0];
|
|
377
|
+
const targetEnds: number[] = [];
|
|
378
|
+
for (const match of targetSource.matchAll(/\r\n|\n|\r/g)) {
|
|
379
|
+
targetEnds.push(match.index!);
|
|
380
|
+
targetStarts.push(match.index! + match[0].length);
|
|
381
|
+
}
|
|
382
|
+
targetEnds.push(targetSource.length);
|
|
383
|
+
|
|
384
|
+
const tStart = targetSymbol.line_start;
|
|
385
|
+
const tEnd = Math.min(targetSymbol.line_end, targetStarts.length);
|
|
386
|
+
if (tStart > targetStarts.length || tEnd < tStart) return undefined;
|
|
387
|
+
|
|
388
|
+
const targetText = targetSource.slice(targetStarts[tStart - 1], targetEnds[tEnd - 1]);
|
|
389
|
+
return {
|
|
390
|
+
symbol: targetSymbol.name,
|
|
391
|
+
file_path: targetSymbol.file_path,
|
|
392
|
+
start_line: tStart,
|
|
393
|
+
end_line: tEnd,
|
|
394
|
+
text: targetText,
|
|
395
|
+
};
|
|
396
|
+
} catch {
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type SymbolLocationResult,
|
|
10
10
|
} from "../../core/resolver/symbol-locator.ts";
|
|
11
11
|
import type { LocateSymbolArgs } from "../schemas.ts";
|
|
12
|
+
import { symbolWorkspace, withSymbolEvidence } from "../../core/retrieval/symbol-evidence.ts";
|
|
12
13
|
|
|
13
14
|
export type { LocateSymbolArgs } from "../schemas.ts";
|
|
14
15
|
|
|
@@ -20,21 +21,51 @@ export async function handleLocateSymbol(
|
|
|
20
21
|
workspaceRoot?: string
|
|
21
22
|
) {
|
|
22
23
|
const query = (args.query || args.symbol || args.symbol_ref?.name || "").toString().trim();
|
|
24
|
+
const root = symbolWorkspace(repo, workspaceRoot || args.workspace_path);
|
|
25
|
+
const diagnostics: string[] = [];
|
|
26
|
+
const limit = args.limit ?? 10;
|
|
27
|
+
|
|
23
28
|
if (!query) {
|
|
29
|
+
if (args.file_path) {
|
|
30
|
+
const normalizedPath = args.file_path.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
31
|
+
const file = repo.getFileByPath(normalizedPath);
|
|
32
|
+
const allSymbols = file ? repo.getSymbolsByFileId(file.id) : [];
|
|
33
|
+
const sliced = allSymbols.slice(0, limit).map((s) => ({
|
|
34
|
+
name: s.name,
|
|
35
|
+
file_path: normalizedPath,
|
|
36
|
+
kind: s.kind,
|
|
37
|
+
signature: s.signature,
|
|
38
|
+
start_line: s.line_start,
|
|
39
|
+
end_line: s.line_end,
|
|
40
|
+
}));
|
|
41
|
+
const filePayload = {
|
|
42
|
+
status: sliced.length > 0 ? "success" : "not_found",
|
|
43
|
+
found: sliced.length > 0,
|
|
44
|
+
query: null,
|
|
45
|
+
file_path: normalizedPath,
|
|
46
|
+
candidates: sliced,
|
|
47
|
+
total_candidates: allSymbols.length,
|
|
48
|
+
omitted_candidates: Math.max(0, allSymbols.length - sliced.length),
|
|
49
|
+
summary: sliced.length > 0
|
|
50
|
+
? `[FOUND] Listed ${sliced.length} of ${allSymbols.length} declarations in ${normalizedPath}.`
|
|
51
|
+
: `[NOT FOUND] No indexed declarations found in '${normalizedPath}'.`,
|
|
52
|
+
};
|
|
53
|
+
return withSymbolEvidence(repo, root, { operation: "locate", requested: args.symbol_ref, diagnostics }, () => ({
|
|
54
|
+
content: [{ type: "text" as const, text: JSON.stringify(filePayload, null, 2) }],
|
|
55
|
+
metadata: filePayload,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
24
58
|
throw new Error(
|
|
25
59
|
"Missing required argument: 'query' (e.g. 'OrderController::calculateTotal' or error log snippet)"
|
|
26
60
|
);
|
|
27
61
|
}
|
|
28
62
|
|
|
29
|
-
const root = workspaceRoot || args.workspace_path || process.cwd();
|
|
30
|
-
const limit = args.limit ?? 10;
|
|
31
|
-
|
|
32
63
|
// 1. Guarded Lazy Ingestion on Empty Catalog / Cold Start
|
|
33
64
|
if (repo.countFiles() === 0 && pipeline) {
|
|
34
65
|
try {
|
|
35
66
|
await pipeline.run(config);
|
|
36
67
|
} catch {
|
|
37
|
-
|
|
68
|
+
diagnostics.push("initial_index_refresh_failed");
|
|
38
69
|
}
|
|
39
70
|
|
|
40
71
|
if (repo.countFiles() === 0) {
|
|
@@ -44,14 +75,14 @@ export async function handleLocateSymbol(
|
|
|
44
75
|
query,
|
|
45
76
|
message: `Workspace '${root}' belum terindeks dalam Septum catalog.`,
|
|
46
77
|
suggested_action: {
|
|
47
|
-
tool: "
|
|
78
|
+
tool: "septum_map",
|
|
48
79
|
params: { action: "register", name: "core", root: "src", ingest_now: true },
|
|
49
80
|
},
|
|
50
81
|
agent_guidance:
|
|
51
|
-
"Panggil tool '
|
|
82
|
+
"Panggil tool 'septum_map(action: \"register\", name: \"core\", root: \"src\", ingest_now: true)' untuk mendaftarkan dan mengindeks codebase ini, atau jalankan 'septum init' di terminal workspace.",
|
|
52
83
|
};
|
|
53
84
|
|
|
54
|
-
return {
|
|
85
|
+
return withSymbolEvidence(repo, root, { operation: "locate", requested: args.symbol_ref, diagnostics }, () => ({
|
|
55
86
|
content: [
|
|
56
87
|
{
|
|
57
88
|
type: "text",
|
|
@@ -59,7 +90,7 @@ export async function handleLocateSymbol(
|
|
|
59
90
|
},
|
|
60
91
|
],
|
|
61
92
|
metadata: diagnostic,
|
|
62
|
-
};
|
|
93
|
+
}));
|
|
63
94
|
}
|
|
64
95
|
}
|
|
65
96
|
|
|
@@ -77,7 +108,7 @@ export async function handleLocateSymbol(
|
|
|
77
108
|
result = locator.locate(query, args.domain, { filePath: args.file_path, reference: args.symbol_ref });
|
|
78
109
|
}
|
|
79
110
|
} catch {
|
|
80
|
-
|
|
111
|
+
diagnostics.push("target_index_refresh_failed");
|
|
81
112
|
}
|
|
82
113
|
}
|
|
83
114
|
|
|
@@ -97,7 +128,7 @@ export async function handleLocateSymbol(
|
|
|
97
128
|
}
|
|
98
129
|
}
|
|
99
130
|
} catch {
|
|
100
|
-
|
|
131
|
+
diagnostics.push("candidate_refresh_failed");
|
|
101
132
|
}
|
|
102
133
|
}
|
|
103
134
|
|
|
@@ -115,7 +146,11 @@ export async function handleLocateSymbol(
|
|
|
115
146
|
: undefined;
|
|
116
147
|
|
|
117
148
|
const suggestions = (result.suggestions || []).slice(0, limit);
|
|
118
|
-
let summary = result.
|
|
149
|
+
let summary = result.status === "ambiguous"
|
|
150
|
+
? `[AMBIGUOUS] Multiple declarations match '${query}'; select a candidate with symbol_ref or file_path.`
|
|
151
|
+
: result.status === "stale_reference"
|
|
152
|
+
? `[STALE REFERENCE] Locate '${query}' again before using its indexed coordinates.`
|
|
153
|
+
: result.found
|
|
119
154
|
? `[FOUND] ${result.exact_symbol?.name || query} in ${result.file_path} (lines ${result.exact_symbol?.line_start}-${result.exact_symbol?.line_end})`
|
|
120
155
|
: `[NOT FOUND] Symbol '${query}' not found. ${suggestions.length > 0 ? `Top suggestions: ${suggestions.map((s) => s.name).slice(0, 3).join(", ")}` : "No close suggestions."}`;
|
|
121
156
|
|
|
@@ -123,9 +158,14 @@ export async function handleLocateSymbol(
|
|
|
123
158
|
summary += ` | ⚠️ High-Complexity Smell: spans ${exactLineCount} lines (> 300L)`;
|
|
124
159
|
}
|
|
125
160
|
|
|
161
|
+
const allCandidates = result.candidates || [];
|
|
162
|
+
const boundedCandidates = allCandidates.slice(0, limit);
|
|
126
163
|
const payload = {
|
|
127
164
|
status: result.status ?? (result.found ? "success" : "not_found"),
|
|
128
|
-
candidates: result.candidates,
|
|
165
|
+
candidates: result.candidates ? boundedCandidates : undefined,
|
|
166
|
+
...(allCandidates.length > boundedCandidates.length
|
|
167
|
+
? { total_candidates: allCandidates.length, omitted_candidates: allCandidates.length - boundedCandidates.length }
|
|
168
|
+
: {}),
|
|
129
169
|
symbol_ref: result.symbol_ref,
|
|
130
170
|
visibility_semantics: "legacy_normalized",
|
|
131
171
|
found: result.found,
|
|
@@ -145,7 +185,7 @@ export async function handleLocateSymbol(
|
|
|
145
185
|
message: result.message || summary,
|
|
146
186
|
};
|
|
147
187
|
|
|
148
|
-
return {
|
|
188
|
+
return withSymbolEvidence(repo, root, { operation: "locate", requested: args.symbol_ref, diagnostics }, () => ({
|
|
149
189
|
content: [
|
|
150
190
|
{
|
|
151
191
|
type: "text" as const,
|
|
@@ -153,7 +193,7 @@ export async function handleLocateSymbol(
|
|
|
153
193
|
},
|
|
154
194
|
],
|
|
155
195
|
metadata: payload,
|
|
156
|
-
};
|
|
196
|
+
}));
|
|
157
197
|
}
|
|
158
198
|
|
|
159
199
|
/**
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
2
2
|
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { MapToolArgs } from "../schemas.ts";
|
|
4
4
|
import { handleGetDomainCatalog } from "./get-domain-catalog.ts";
|
|
5
5
|
import { handleRegisterDomain } from "./register-domain.ts";
|
|
6
|
-
import { handleGetEnvironmentTopology } from "./get-environment-topology.ts";
|
|
7
6
|
|
|
8
|
-
export type {
|
|
7
|
+
export type { MapToolArgs };
|
|
9
8
|
|
|
10
|
-
export async function
|
|
9
|
+
export async function handleMapTool(
|
|
11
10
|
repo: SeptumRepository,
|
|
12
11
|
config: ValidatedSeptumConfig,
|
|
13
|
-
args:
|
|
12
|
+
args: MapToolArgs,
|
|
14
13
|
workspaceRoot?: string,
|
|
15
14
|
signal?: AbortSignal
|
|
16
15
|
) {
|
|
@@ -20,19 +19,6 @@ export async function handleDomainTool(
|
|
|
20
19
|
case "register":
|
|
21
20
|
return await handleRegisterDomain(repo, config, args, workspaceRoot, signal);
|
|
22
21
|
|
|
23
|
-
case "topology":
|
|
24
|
-
return handleGetEnvironmentTopology(
|
|
25
|
-
repo,
|
|
26
|
-
config,
|
|
27
|
-
{
|
|
28
|
-
resolve: args.resolve,
|
|
29
|
-
resolveNode: args.resolve_node,
|
|
30
|
-
refresh: args.refresh,
|
|
31
|
-
workspace_path: args.workspace_path,
|
|
32
|
-
},
|
|
33
|
-
workspaceRoot || args.workspace_path || process.cwd()
|
|
34
|
-
);
|
|
35
|
-
|
|
36
22
|
case "catalog":
|
|
37
23
|
default:
|
|
38
24
|
return handleGetDomainCatalog(repo, config, args, workspaceRoot);
|
|
@@ -2,7 +2,12 @@ import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
|
2
2
|
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
3
3
|
import { IngestionPipeline, type IngestionMetrics } from "../../core/ingestion/pipeline.ts";
|
|
4
4
|
import { assertPathContained } from "../../core/resolver/path-resolver.ts";
|
|
5
|
+
import { assertUniqueDomainRoots, domainNameKey, domainRootIdentity } from "../../core/config/domain-ownership.ts";
|
|
5
6
|
import type { RegisterDomainArgs } from "../schemas.ts";
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { ConfigLoader } from "../../core/config/loader.ts";
|
|
10
|
+
import { SeptumConfigSchema } from "../../core/config/schema.ts";
|
|
6
11
|
|
|
7
12
|
export type { RegisterDomainArgs } from "../schemas.ts";
|
|
8
13
|
|
|
@@ -31,7 +36,35 @@ export async function handleRegisterDomain(
|
|
|
31
36
|
archetypes: args.archetypes,
|
|
32
37
|
};
|
|
33
38
|
|
|
34
|
-
const
|
|
39
|
+
const proposed = domainRootIdentity(args.root, workspaceRoot);
|
|
40
|
+
const claims = Object.fromEntries(Object.entries(config.domains).filter(([name, claim]) =>
|
|
41
|
+
domainNameKey(name) !== domainNameKey(domainName) && domainRootIdentity(claim.root, workspaceRoot) === proposed));
|
|
42
|
+
assertUniqueDomainRoots({ ...claims, [domainName]: domainConfig }, workspaceRoot);
|
|
43
|
+
|
|
44
|
+
const policyFile = join(workspaceRoot, "septum.config.json");
|
|
45
|
+
const policySource = existsSync(policyFile) ? readFileSync(policyFile, "utf8") : undefined;
|
|
46
|
+
if (policySource !== undefined) {
|
|
47
|
+
const policy = SeptumConfigSchema.parse(JSON.parse(policySource));
|
|
48
|
+
const existing = Object.entries(policy.domains).find(([name]) => domainNameKey(name) === domainNameKey(domainName))?.[1];
|
|
49
|
+
domainConfig.allowed_dependencies ??= existing?.allowed_dependencies ?? [];
|
|
50
|
+
domainConfig.forbidden_dependencies ??= existing?.forbidden_dependencies ?? [];
|
|
51
|
+
domainConfig.archetypes ??= existing?.archetypes ?? {};
|
|
52
|
+
domainConfig.description = args.description ?? existing?.description ?? domainConfig.description;
|
|
53
|
+
const claims = Object.fromEntries(Object.entries(policy.domains).filter(([name, claim]) =>
|
|
54
|
+
domainNameKey(name) !== domainNameKey(domainName) && domainRootIdentity(claim.root, workspaceRoot) === proposed));
|
|
55
|
+
assertUniqueDomainRoots({ ...claims, [domainName]: domainConfig }, workspaceRoot);
|
|
56
|
+
}
|
|
57
|
+
const domainId = repo.runInTransaction(() => {
|
|
58
|
+
const id = repo.domains.upsertDomain(domainName, domainConfig, workspaceRoot);
|
|
59
|
+
const stored = repo.domains.getDomainByName(domainName)!;
|
|
60
|
+
if (policySource !== undefined) ConfigLoader.writeDomain(workspaceRoot, stored.name, {
|
|
61
|
+
...domainConfig,
|
|
62
|
+
allowed_dependencies: JSON.parse(stored.allowed_deps_json),
|
|
63
|
+
forbidden_dependencies: JSON.parse(stored.forbidden_deps_json),
|
|
64
|
+
archetypes: JSON.parse(stored.archetypes_json),
|
|
65
|
+
}, policySource);
|
|
66
|
+
return id;
|
|
67
|
+
}, true);
|
|
35
68
|
const stored = repo.domains.getDomainByName(domainName);
|
|
36
69
|
const canonicalName = stored?.name || domainName;
|
|
37
70
|
const finalConfig = {
|
|
@@ -47,7 +80,7 @@ export async function handleRegisterDomain(
|
|
|
47
80
|
let ingestionMetrics: IngestionMetrics | null = null;
|
|
48
81
|
if (args.ingest_now) {
|
|
49
82
|
const pipeline = new IngestionPipeline(repo, workspaceRoot);
|
|
50
|
-
ingestionMetrics = await pipeline.run(config);
|
|
83
|
+
ingestionMetrics = await pipeline.run(config, { signal });
|
|
51
84
|
}
|
|
52
85
|
|
|
53
86
|
return {
|
|
@@ -57,13 +90,18 @@ export async function handleRegisterDomain(
|
|
|
57
90
|
text: JSON.stringify(
|
|
58
91
|
{
|
|
59
92
|
status: "success",
|
|
60
|
-
|
|
93
|
+
policy_owner: policySource === undefined ? "database" : "file",
|
|
94
|
+
message: `Domain '${canonicalName}' successfully registered in ${policySource === undefined ? "SQLite" : "septum.config.json"}.${
|
|
61
95
|
args.ingest_now ? " Initial ingestion completed." : ""
|
|
62
96
|
}`,
|
|
63
97
|
domain_id: domainId,
|
|
64
98
|
domain: canonicalName,
|
|
65
99
|
name: canonicalName,
|
|
66
100
|
config: finalConfig,
|
|
101
|
+
...(repo.getMeta("sync_error_code") === "DOMAIN_ROOT_CONFLICT" ? {
|
|
102
|
+
index_status: { sync_state: "error", code: "DOMAIN_ROOT_CONFLICT" },
|
|
103
|
+
next: ["Resolve any remaining duplicate roots, then sync before using indexed facts. Registration success only records this policy change."],
|
|
104
|
+
} : {}),
|
|
67
105
|
...(ingestionMetrics ? { ingestion_metrics: ingestionMetrics } : {}),
|
|
68
106
|
},
|
|
69
107
|
null,
|
package/src/mcp/tools/symbol.ts
CHANGED
|
@@ -5,7 +5,8 @@ import type { SymbolToolArgs } from "../schemas.ts";
|
|
|
5
5
|
import { handleLocateSymbol } from "./locate-symbol.ts";
|
|
6
6
|
import { handleGetSymbol } from "./get-symbol.ts";
|
|
7
7
|
import { handleGetSymbolImpact } from "./get-symbol-impact.ts";
|
|
8
|
-
import {
|
|
8
|
+
import { retrieveContext } from "../../core/retrieval/context.ts";
|
|
9
|
+
import { symbolWorkspace } from "../../core/retrieval/symbol-evidence.ts";
|
|
9
10
|
|
|
10
11
|
export type { SymbolToolArgs };
|
|
11
12
|
|
|
@@ -14,13 +15,29 @@ export async function handleSymbolTool(
|
|
|
14
15
|
config: ValidatedSeptumConfig,
|
|
15
16
|
args: SymbolToolArgs,
|
|
16
17
|
pipeline?: IngestionPipeline,
|
|
17
|
-
workspaceRoot?: string
|
|
18
|
+
workspaceRoot?: string,
|
|
19
|
+
signal?: AbortSignal
|
|
18
20
|
) {
|
|
19
21
|
const action = args.action || "locate";
|
|
20
22
|
|
|
21
23
|
switch (action) {
|
|
24
|
+
case "context":
|
|
22
25
|
case "inspect": {
|
|
23
|
-
const symbol = args.symbol || args.query || "";
|
|
26
|
+
const symbol = args.symbol_ref?.name || args.symbol || args.query || "";
|
|
27
|
+
const candidates = repo.findSymbolsByName(symbol, {
|
|
28
|
+
domain: args.domain, filePath: args.file_path, reference: args.symbol_ref,
|
|
29
|
+
});
|
|
30
|
+
const targetPath = candidates.length === 1 ? candidates[0]!.file_path : args.symbol_ref?.file_path || args.file_path;
|
|
31
|
+
const bounded = args.context_mode === "source" || args.include_source !== undefined || args.source_start_line !== undefined || args.source_line_limit !== undefined;
|
|
32
|
+
if (args.context_mode === "deep" || !bounded && (!targetPath || /\.(?:ts|mts|cts)$/.test(targetPath))) {
|
|
33
|
+
return retrieveContext(repo, config, args, symbolWorkspace(repo, workspaceRoot || args.workspace_path), signal);
|
|
34
|
+
}
|
|
35
|
+
if (args.continuation !== undefined || args.budget_bytes !== undefined) {
|
|
36
|
+
return { content: [{ type: "text" as const, text: JSON.stringify({
|
|
37
|
+
status: "invalid_context_options",
|
|
38
|
+
message: "budget_bytes and continuation apply to deep TypeScript context. For bounded source use source_start_line and source_line_limit.",
|
|
39
|
+
}) }] };
|
|
40
|
+
}
|
|
24
41
|
return handleGetSymbol(
|
|
25
42
|
repo,
|
|
26
43
|
config,
|
|
@@ -31,9 +48,10 @@ export async function handleSymbolTool(
|
|
|
31
48
|
file_path: args.file_path,
|
|
32
49
|
symbol_ref: args.symbol_ref,
|
|
33
50
|
include_dependencies: args.include_dependencies,
|
|
34
|
-
include_source: args.include_source,
|
|
51
|
+
include_source: args.include_source ?? true,
|
|
35
52
|
source_start_line: args.source_start_line,
|
|
36
53
|
source_line_limit: args.source_line_limit,
|
|
54
|
+
semantic_depth: args.semantic_depth,
|
|
37
55
|
workspace_path: args.workspace_path,
|
|
38
56
|
},
|
|
39
57
|
workspaceRoot
|
|
@@ -41,7 +59,7 @@ export async function handleSymbolTool(
|
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
case "impact": {
|
|
44
|
-
const symbol = args.symbol || args.query || "";
|
|
62
|
+
const symbol = args.symbol || args.query || args.symbol_ref?.name || "";
|
|
45
63
|
return handleGetSymbolImpact(
|
|
46
64
|
repo,
|
|
47
65
|
config,
|
|
@@ -57,22 +75,6 @@ export async function handleSymbolTool(
|
|
|
57
75
|
);
|
|
58
76
|
}
|
|
59
77
|
|
|
60
|
-
case "hotspots":
|
|
61
|
-
return handleGetSymbolHotspots(
|
|
62
|
-
repo,
|
|
63
|
-
config,
|
|
64
|
-
{
|
|
65
|
-
min_lines: args.min_lines,
|
|
66
|
-
min_nesting: args.min_nesting,
|
|
67
|
-
kind: args.kind,
|
|
68
|
-
domain: args.domain,
|
|
69
|
-
limit: args.limit ?? 30,
|
|
70
|
-
sort_by: (args.sort_by === "line_count" ? "lines" : args.sort_by) as any,
|
|
71
|
-
workspace_path: args.workspace_path,
|
|
72
|
-
},
|
|
73
|
-
workspaceRoot
|
|
74
|
-
);
|
|
75
|
-
|
|
76
78
|
case "locate":
|
|
77
79
|
default:
|
|
78
80
|
return await handleLocateSymbol(
|