@dimassetoid/septum-mcp 0.3.0 → 0.5.1
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 +38 -55
- package/package.json +7 -5
- package/src/cli/commands/check.ts +14 -10
- package/src/cli/commands/hook.ts +41 -6
- package/src/cli/commands/init.ts +10 -1
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +32 -4
- package/src/cli/index.ts +7 -0
- package/src/cli/templates/hooks.ts +3 -14
- package/src/cli/templates/skill.ts +17 -10
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +251 -114
- package/src/core/boundary/staged-auditor.ts +147 -55
- package/src/core/config/domain-ownership.ts +6 -4
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +1 -25
- package/src/core/config/schema.ts +24 -36
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +334 -572
- package/src/core/database/repositories/domain.repository.ts +2 -1
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -398
- package/src/core/database/repository.ts +68 -9
- package/src/core/database/schema.ts +26 -0
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +222 -58
- package/src/core/discovery/topology-detector.ts +93 -168
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +287 -88
- package/src/core/parser/extractors/base.ts +11 -3
- package/src/core/parser/extractors/csharp.ts +2 -2
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +397 -481
- package/src/core/parser/extractors/elysia-semantic.ts +172 -475
- package/src/core/parser/extractors/express-semantic.ts +195 -383
- package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
- package/src/core/parser/extractors/fastify-semantic.ts +216 -717
- package/src/core/parser/extractors/flask-semantic.ts +89 -352
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +205 -562
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -509
- package/src/core/parser/extractors/java.ts +2 -2
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +143 -335
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +1 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +5 -9
- package/src/core/parser/extractors/registry.ts +2 -0
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +2 -2
- package/src/core/parser/extractors/rust.ts +4 -4
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +72 -226
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +23 -216
- package/src/core/parser/language-capabilities.ts +1 -1
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +169 -414
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +60 -7
- package/src/core/resolver/interpretation-inputs.ts +60 -2
- package/src/core/resolver/languages/python.ts +31 -13
- package/src/core/resolver/languages/shared.ts +4 -1
- package/src/core/resolver/module-resolver.ts +10 -3
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +21 -6
- package/src/core/resolver/slice-format.ts +13 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +104 -8
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +31 -230
- package/src/core/resources/ignore.ts +0 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +11 -4
- package/src/core/retrieval/context.ts +363 -226
- package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +3 -3
- package/src/core/retrieval/typescript-references.ts +38 -7
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +192 -49
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +255 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -746
- package/src/mcp/server.ts +269 -429
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +68 -3
- package/src/mcp/tools/map.ts +104 -4
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +469 -17
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +88 -15
- package/src/mcp/workspace-watcher.ts +30 -11
- package/src/types/index.ts +12 -0
- package/src/mcp/tools/check-boundary.ts +0 -382
- package/src/mcp/tools/get-domain-catalog.ts +0 -39
- package/src/mcp/tools/get-symbol-impact.ts +0 -104
- package/src/mcp/tools/locate-symbol.ts +0 -236
- package/src/mcp/tools/register-domain.ts +0 -113
- package/src/mcp/tools/trace-vertical-slice.ts +0 -106
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import type {
|
|
3
|
+
FileConnectionsSummary,
|
|
4
|
+
GetSymbolDetailsResponse,
|
|
5
|
+
ImportRelationship,
|
|
6
|
+
ResolvedOutboundCall,
|
|
7
|
+
SymbolCandidate,
|
|
8
|
+
SymbolComplexitySmell,
|
|
9
|
+
SymbolRecord,
|
|
10
|
+
SymbolSelectionOptions,
|
|
11
|
+
} from "../../types/index.ts";
|
|
12
|
+
import { assertPathContained } from "../resolver/path-resolver.ts";
|
|
13
|
+
import { symbolReference } from "../resolver/symbol-reference.ts";
|
|
14
|
+
import { probeSourcePath, readSourceFile } from "../resources/source-files.ts";
|
|
15
|
+
|
|
16
|
+
const SQL_KEYWORD_BLACKLIST = new Set([
|
|
17
|
+
"VALUES",
|
|
18
|
+
"WHERE",
|
|
19
|
+
"SELECT",
|
|
20
|
+
"FROM",
|
|
21
|
+
"JOIN",
|
|
22
|
+
"LIKE",
|
|
23
|
+
"INSERT",
|
|
24
|
+
"UPDATE",
|
|
25
|
+
"DELETE",
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
function stripCommentsAndStrings(source: string): string {
|
|
29
|
+
return source
|
|
30
|
+
.replace(/\/\*[\s\S]*?\*\//g, " ")
|
|
31
|
+
.replace(/\/\/.*$/gm, " ")
|
|
32
|
+
.replace(/'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`])*`/g, '""');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SymbolDetailsStore {
|
|
36
|
+
findSymbolsByName(name: string, options?: SymbolSelectionOptions): SymbolCandidate[];
|
|
37
|
+
getSymbolsByFileId(fileId: number): SymbolRecord[];
|
|
38
|
+
findConstructorSignature(fileId: number, classOwner: string): string | null;
|
|
39
|
+
getInternalImportStatements(fileId: number): string[];
|
|
40
|
+
getFileConnections(filePath: string, workspaceRoot?: string): FileConnectionsSummary;
|
|
41
|
+
getImportRelationships(workspaceRoot?: string, sourceFile?: string): ImportRelationship[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function buildSymbolDetails(
|
|
45
|
+
store: SymbolDetailsStore,
|
|
46
|
+
symbolQuery: string,
|
|
47
|
+
options: SymbolSelectionOptions & { includeDependencies?: boolean; workspaceRoot?: string } = {}
|
|
48
|
+
): GetSymbolDetailsResponse | null {
|
|
49
|
+
const trimmed = symbolQuery.trim();
|
|
50
|
+
if (!trimmed) return null;
|
|
51
|
+
|
|
52
|
+
const candidates = store.findSymbolsByName(trimmed, options);
|
|
53
|
+
if (candidates.length !== 1) return null;
|
|
54
|
+
const row = candidates[0]!;
|
|
55
|
+
|
|
56
|
+
// 1. Sibling methods
|
|
57
|
+
const isRust = /\.rs$/i.test(row.file_path);
|
|
58
|
+
const containerName = row.symbol_ref.container ?? "";
|
|
59
|
+
const owner = ["class", "interface", "trait", "struct", "enum"].includes(row.kind)
|
|
60
|
+
? row.name
|
|
61
|
+
: row.kind === "method"
|
|
62
|
+
? containerName
|
|
63
|
+
: "";
|
|
64
|
+
let siblingMethods: string[] = owner
|
|
65
|
+
? store
|
|
66
|
+
.getSymbolsByFileId(row.file_id)
|
|
67
|
+
.filter((s) => s.kind === "method" && s.id !== row.id)
|
|
68
|
+
.filter(
|
|
69
|
+
(s) =>
|
|
70
|
+
symbolReference({
|
|
71
|
+
...s,
|
|
72
|
+
file_path: row.file_path,
|
|
73
|
+
indexed_content_hash: row.indexed_content_hash,
|
|
74
|
+
}).container === owner
|
|
75
|
+
)
|
|
76
|
+
.map((s) => s.name.split(/::|[.#]/).pop()!)
|
|
77
|
+
: [];
|
|
78
|
+
|
|
79
|
+
siblingMethods = Array.from(new Set(siblingMethods)).filter(
|
|
80
|
+
(m) => !SQL_KEYWORD_BLACKLIST.has(m.toUpperCase())
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// 2. Dependencies Injected (from signature type-hints and constructor)
|
|
84
|
+
const dependenciesInjected = new Set<string>();
|
|
85
|
+
const outboundCalls = new Set<string>();
|
|
86
|
+
const resolvedOutboundCalls: ResolvedOutboundCall[] = [];
|
|
87
|
+
let connectedFiles: FileConnectionsSummary = { imports_from: [], imported_by_count: 0 };
|
|
88
|
+
|
|
89
|
+
const shouldIncludeDeps = options.includeDependencies !== false;
|
|
90
|
+
|
|
91
|
+
if (shouldIncludeDeps) {
|
|
92
|
+
const varTypes = new Map<string, string>();
|
|
93
|
+
const primitiveTypes = new Set([
|
|
94
|
+
"int", "string", "str", "bool", "boolean", "float", "double", "decimal",
|
|
95
|
+
"number", "bigint", "symbol", "array", "list", "dict", "tuple", "set",
|
|
96
|
+
"iterable", "callable", "function", "void", "mixed", "object", "null",
|
|
97
|
+
"undefined", "never", "any", "unknown", "true", "false", "record",
|
|
98
|
+
"partial", "omit", "pick", "readonly", "required", "promise", "map",
|
|
99
|
+
"weakmap", "weakset", "date", "error", "regexp", "buffer", "abortsignal",
|
|
100
|
+
"uint8array", "self", "cls",
|
|
101
|
+
]);
|
|
102
|
+
const modifierWords = new Set([
|
|
103
|
+
"public", "private", "protected", "readonly", "final", "var", "val",
|
|
104
|
+
"mut", "ref", "in", "out", "params", "async",
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
const splitTopLevel = (input: string, delimiter: string): string[] => {
|
|
108
|
+
const result: string[] = [];
|
|
109
|
+
let current = "";
|
|
110
|
+
let depth = 0;
|
|
111
|
+
for (let i = 0; i < input.length; i++) {
|
|
112
|
+
const ch = input[i];
|
|
113
|
+
if (ch === "(" || ch === "<" || ch === "[" || ch === "{") depth++;
|
|
114
|
+
else if (ch === ")" || ch === ">" || ch === "]" || ch === "}") depth = Math.max(0, depth - 1);
|
|
115
|
+
if (depth === 0 && input.startsWith(delimiter, i)) {
|
|
116
|
+
result.push(current);
|
|
117
|
+
current = "";
|
|
118
|
+
i += delimiter.length - 1;
|
|
119
|
+
} else {
|
|
120
|
+
current += ch;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (current.trim()) result.push(current);
|
|
124
|
+
return result;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const registerTypeToken = (rawToken: string, paramName?: string) => {
|
|
128
|
+
let token = rawToken
|
|
129
|
+
.trim()
|
|
130
|
+
.replace(/^\?+/, "")
|
|
131
|
+
.replace(/^&+/, "")
|
|
132
|
+
.replace(/^\*+/, "")
|
|
133
|
+
.replace(/\[\]$/, "")
|
|
134
|
+
.replace(/<.*>$/s, "")
|
|
135
|
+
.replace(/^[\\$]/, "")
|
|
136
|
+
.trim();
|
|
137
|
+
if (token.includes("\\")) token = token.split("\\").pop() || token;
|
|
138
|
+
if (token.includes(".")) token = token.split(".").pop() || token;
|
|
139
|
+
if (!token || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(token)) return;
|
|
140
|
+
if (primitiveTypes.has(token.toLowerCase()) || modifierWords.has(token.toLowerCase())) return;
|
|
141
|
+
dependenciesInjected.add(token);
|
|
142
|
+
if (paramName && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(paramName) && !varTypes.has(paramName)) {
|
|
143
|
+
varTypes.set(paramName, token);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const extractTypeHints = (sig: string) => {
|
|
148
|
+
const openIdx = sig.indexOf("(");
|
|
149
|
+
if (openIdx === -1) return;
|
|
150
|
+
let closeIdx = -1;
|
|
151
|
+
let depth = 0;
|
|
152
|
+
for (let i = openIdx; i < sig.length; i++) {
|
|
153
|
+
if (sig[i] === "(") depth++;
|
|
154
|
+
else if (sig[i] === ")") {
|
|
155
|
+
depth--;
|
|
156
|
+
if (depth === 0) {
|
|
157
|
+
closeIdx = i;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (closeIdx <= openIdx + 1) return;
|
|
163
|
+
const paramBlock = sig.slice(openIdx + 1, closeIdx);
|
|
164
|
+
const params = splitTopLevel(paramBlock, ",");
|
|
165
|
+
const isGo = /\.go$/i.test(row.file_path);
|
|
166
|
+
|
|
167
|
+
for (const rawParam of params) {
|
|
168
|
+
let p = rawParam.trim();
|
|
169
|
+
if (!p) continue;
|
|
170
|
+
let eqDepth = 0;
|
|
171
|
+
for (let i = 0; i < p.length; i++) {
|
|
172
|
+
const ch = p[i];
|
|
173
|
+
if (ch === "(" || ch === "<" || ch === "[" || ch === "{") eqDepth++;
|
|
174
|
+
else if (ch === ")" || ch === ">" || ch === "]" || ch === "}") eqDepth = Math.max(0, eqDepth - 1);
|
|
175
|
+
else if (eqDepth === 0 && ch === "=" && p[i + 1] !== ">" && p[i - 1] !== "!" && p[i - 1] !== "=" && p[i - 1] !== "<" && p[i - 1] !== ">") {
|
|
176
|
+
p = p.slice(0, i).trim();
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
let colonIdx = -1;
|
|
181
|
+
let colDepth = 0;
|
|
182
|
+
for (let i = 0; i < p.length; i++) {
|
|
183
|
+
const ch = p[i];
|
|
184
|
+
if (ch === "(" || ch === "<" || ch === "[" || ch === "{") colDepth++;
|
|
185
|
+
else if (ch === ")" || ch === ">" || ch === "]" || ch === "}") colDepth = Math.max(0, colDepth - 1);
|
|
186
|
+
else if (colDepth === 0 && ch === ":" && p[i + 1] !== ":" && p[i - 1] !== ":") {
|
|
187
|
+
colonIdx = i;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (colonIdx !== -1) {
|
|
193
|
+
const leftTokens = p
|
|
194
|
+
.slice(0, colonIdx)
|
|
195
|
+
.trim()
|
|
196
|
+
.replace(/^\.{3}/, "")
|
|
197
|
+
.split(/\s+/)
|
|
198
|
+
.filter((t) => !modifierWords.has(t.toLowerCase()));
|
|
199
|
+
const rawParamName = (leftTokens.pop() || "").replace(/\?$/, "").replace(/^\$/, "");
|
|
200
|
+
const typeExpr = p.slice(colonIdx + 1).trim();
|
|
201
|
+
if (typeExpr.startsWith("{") || typeExpr.startsWith("(") || typeExpr.startsWith("[")) continue;
|
|
202
|
+
for (const branch of splitTopLevel(typeExpr, "|")) {
|
|
203
|
+
const trimmedBranch = branch.trim();
|
|
204
|
+
const wrapperMatch = /^(?:Promise|Array|ReadonlyArray|Partial|Required|Readonly)\s*<(.+)>$/s.exec(trimmedBranch);
|
|
205
|
+
registerTypeToken(wrapperMatch ? wrapperMatch[1] : trimmedBranch, rawParamName);
|
|
206
|
+
}
|
|
207
|
+
} else {
|
|
208
|
+
const parts = p
|
|
209
|
+
.replace(/^\.{3}/, "")
|
|
210
|
+
.split(/\s+/)
|
|
211
|
+
.filter((t) => !modifierWords.has(t.toLowerCase()));
|
|
212
|
+
if (parts.length >= 2) {
|
|
213
|
+
if (isGo) {
|
|
214
|
+
registerTypeToken(parts[parts.length - 1], parts[0]);
|
|
215
|
+
} else {
|
|
216
|
+
registerTypeToken(parts[0], parts[1].replace(/^[$&]+/, ""));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
if (!isRust) extractTypeHints(row.signature);
|
|
224
|
+
|
|
225
|
+
const classOwner = containerName || (row.kind === "class" ? row.name : "");
|
|
226
|
+
if (classOwner && !isRust) {
|
|
227
|
+
const ctorSig = store.findConstructorSignature(row.file_id, classOwner);
|
|
228
|
+
if (ctorSig) {
|
|
229
|
+
extractTypeHints(ctorSig);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// 3. Outbound Calls (inspected from physical source file lines if accessible)
|
|
234
|
+
try {
|
|
235
|
+
const fullPath = options.workspaceRoot ? path.resolve(options.workspaceRoot, row.file_path) : row.file_path;
|
|
236
|
+
if (options.workspaceRoot) assertPathContained(fullPath, options.workspaceRoot, "Outbound call source");
|
|
237
|
+
if (probeSourcePath(fullPath) === "file") {
|
|
238
|
+
const fileContent = readSourceFile(fullPath);
|
|
239
|
+
const lines = fileContent.split(/\r?\n/);
|
|
240
|
+
const start = Math.max(0, row.line_start - 1);
|
|
241
|
+
const end = Math.min(lines.length, row.line_end);
|
|
242
|
+
const rawSlice = lines.slice(start, end).join("\n");
|
|
243
|
+
const sanitizedSlice = stripCommentsAndStrings(rawSlice);
|
|
244
|
+
|
|
245
|
+
for (const m of sanitizedSlice.matchAll(/(?:const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*new\s+([A-Z][a-zA-Z0-9_]*)\s*\(/g)) {
|
|
246
|
+
varTypes.set(m[1], m[2]);
|
|
247
|
+
}
|
|
248
|
+
for (const m of sanitizedSlice.matchAll(/\$([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*new\s+([A-Z][a-zA-Z0-9_]*)\s*\(/g)) {
|
|
249
|
+
varTypes.set(m[1], m[2]);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
for (const m of sanitizedSlice.matchAll(/([A-Z][a-zA-Z0-9_]+)::([a-zA-Z0-9_]+)\s*\(/g)) {
|
|
253
|
+
if (m[1] !== "self" && m[1] !== "parent" && m[1] !== "static") {
|
|
254
|
+
outboundCalls.add(`${m[1]}::${m[2]}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
for (const m of sanitizedSlice.matchAll(/\$this->([a-zA-Z0-9_]+)->([a-zA-Z0-9_]+)\s*\(/g)) {
|
|
259
|
+
const propName = m[1];
|
|
260
|
+
const methodName = m[2];
|
|
261
|
+
const mappedType = varTypes.get(propName);
|
|
262
|
+
const inferredClass = mappedType || propName.charAt(0).toUpperCase() + propName.slice(1);
|
|
263
|
+
outboundCalls.add(`${inferredClass}::${methodName}`);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
for (const m of sanitizedSlice.matchAll(/\bthis\.([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)\s*\(/g)) {
|
|
267
|
+
const propName = m[1];
|
|
268
|
+
const methodName = m[2];
|
|
269
|
+
if (propName !== "db") {
|
|
270
|
+
const mappedType = varTypes.get(propName);
|
|
271
|
+
const inferredClass = mappedType || propName.charAt(0).toUpperCase() + propName.slice(1);
|
|
272
|
+
outboundCalls.add(`${inferredClass}::${methodName}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const isPython = row.file_path.endsWith(".py");
|
|
277
|
+
const className = row.name.includes("::") ? row.name.split("::")[0] : undefined;
|
|
278
|
+
|
|
279
|
+
if (isPython) {
|
|
280
|
+
for (const m of sanitizedSlice.matchAll(/\bself\.([a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)\s*\(/g)) {
|
|
281
|
+
const propName = m[1];
|
|
282
|
+
const methodName = m[2];
|
|
283
|
+
const mappedType = varTypes.get(propName) || propName.charAt(0).toUpperCase() + propName.slice(1);
|
|
284
|
+
outboundCalls.add(`${mappedType}::${methodName}`);
|
|
285
|
+
}
|
|
286
|
+
for (const m of sanitizedSlice.matchAll(/\bself\.([a-zA-Z_][a-zA-Z0-9_]*)\s*\(/g)) {
|
|
287
|
+
const methodName = m[1];
|
|
288
|
+
if (className) {
|
|
289
|
+
outboundCalls.add(`${className}::${methodName}`);
|
|
290
|
+
} else {
|
|
291
|
+
outboundCalls.add(methodName);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const sameFileSymbols = store.getSymbolsByFileId(row.file_id);
|
|
297
|
+
const knownDirectCallables = new Set<string>();
|
|
298
|
+
const knownStaticReceivers = new Set<string>();
|
|
299
|
+
for (const s of sameFileSymbols) {
|
|
300
|
+
if (s.id === row.id) continue;
|
|
301
|
+
if (s.kind === "function") knownDirectCallables.add(s.name);
|
|
302
|
+
else if (s.kind === "class") knownStaticReceivers.add(s.name);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
for (const stmt of store.getInternalImportStatements(row.file_id)) {
|
|
306
|
+
if (/^\s*import\s+type\b/.test(stmt)) continue;
|
|
307
|
+
const braceMatch = stmt.match(/\{([^}]+)\}/);
|
|
308
|
+
if (braceMatch) {
|
|
309
|
+
for (const spec of braceMatch[1].split(",")) {
|
|
310
|
+
const trimmedSpec = spec.trim();
|
|
311
|
+
if (/^type\s+/.test(trimmedSpec)) continue;
|
|
312
|
+
const aliasParts = trimmedSpec.split(/\s+as\s+/);
|
|
313
|
+
const localName = (aliasParts[1] || aliasParts[0] || "").trim();
|
|
314
|
+
if (/^[a-z_$][a-zA-Z0-9_$]*$/.test(localName)) knownDirectCallables.add(localName);
|
|
315
|
+
else if (/^[A-Z][a-zA-Z0-9_$]*$/.test(localName)) knownStaticReceivers.add(localName);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const defaultMatch = stmt.match(/^\s*import\s+([A-Za-z_$][A-Za-z0-9_$]*)\s+from\b/);
|
|
319
|
+
if (defaultMatch) {
|
|
320
|
+
const localName = defaultMatch[1];
|
|
321
|
+
if (/^[a-z_$]/.test(localName)) knownDirectCallables.add(localName);
|
|
322
|
+
else knownStaticReceivers.add(localName);
|
|
323
|
+
}
|
|
324
|
+
// Python: from x import a, B as C
|
|
325
|
+
const pyFromMatch = stmt.match(/^\s*from\s+[\w.]+\s+import\s+(.+)$/);
|
|
326
|
+
if (pyFromMatch) {
|
|
327
|
+
for (const item of pyFromMatch[1].replace(/[()]/g, "").split(",")) {
|
|
328
|
+
const trimmed = item.trim();
|
|
329
|
+
if (!trimmed) continue;
|
|
330
|
+
const aliasParts = trimmed.split(/\s+as\s+/);
|
|
331
|
+
const localName = (aliasParts[1] || aliasParts[0] || "").trim();
|
|
332
|
+
if (/^[a-z_][a-zA-Z0-9_]*$/.test(localName)) knownDirectCallables.add(localName);
|
|
333
|
+
else if (/^[A-Z][a-zA-Z0-9_]*$/.test(localName)) knownStaticReceivers.add(localName);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// Python: import foo as bar
|
|
337
|
+
const pyImportMatch = stmt.match(/^\s*import\s+([\w.]+)(?:\s+as\s+(\w+))?/);
|
|
338
|
+
if (pyImportMatch) {
|
|
339
|
+
const localName = pyImportMatch[2] || pyImportMatch[1].split(".").pop() || "";
|
|
340
|
+
if (/^[a-z_][a-zA-Z0-9_]*$/.test(localName)) knownDirectCallables.add(localName);
|
|
341
|
+
else if (/^[A-Z][a-zA-Z0-9_]*$/.test(localName)) knownStaticReceivers.add(localName);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
for (const m of sanitizedSlice.matchAll(/\b([a-zA-Z_$][a-zA-Z0-9_$]*)\.([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g)) {
|
|
346
|
+
const receiver = m[1];
|
|
347
|
+
const method = m[2];
|
|
348
|
+
if (
|
|
349
|
+
receiver === "this" || receiver === "super" || receiver === "console" || receiver === "process" ||
|
|
350
|
+
receiver === "Math" || receiver === "JSON" || receiver === "Object" || receiver === "Array" ||
|
|
351
|
+
receiver === "Buffer" || receiver === "Promise" || receiver === "Number" || receiver === "String"
|
|
352
|
+
) continue;
|
|
353
|
+
const mappedType = varTypes.get(receiver);
|
|
354
|
+
if (mappedType) outboundCalls.add(`${mappedType}::${method}`);
|
|
355
|
+
else if (knownStaticReceivers.has(receiver)) outboundCalls.add(`${receiver}::${method}`);
|
|
356
|
+
}
|
|
357
|
+
for (const m of sanitizedSlice.matchAll(/\$([a-zA-Z_][a-zA-Z0-9_]*)\s*->\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\(/g)) {
|
|
358
|
+
const receiver = m[1];
|
|
359
|
+
if (receiver === "this") continue;
|
|
360
|
+
const mappedType = varTypes.get(receiver);
|
|
361
|
+
if (mappedType) outboundCalls.add(`${mappedType}::${m[2]}`);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
let bodySlice = "";
|
|
365
|
+
if (isPython) {
|
|
366
|
+
const colonIdx = sanitizedSlice.indexOf(":");
|
|
367
|
+
bodySlice = colonIdx !== -1 ? sanitizedSlice.slice(colonIdx + 1) : sanitizedSlice;
|
|
368
|
+
} else {
|
|
369
|
+
const bodyStartIdx = sanitizedSlice.indexOf("{");
|
|
370
|
+
bodySlice = bodyStartIdx !== -1 ? sanitizedSlice.slice(bodyStartIdx + 1) : "";
|
|
371
|
+
}
|
|
372
|
+
if (bodySlice && knownDirectCallables.size > 0) {
|
|
373
|
+
for (const m of bodySlice.matchAll(/(?:^|[^.\w$:])([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g)) {
|
|
374
|
+
const fnName = m[1];
|
|
375
|
+
if (fnName !== row.name && knownDirectCallables.has(fnName)) {
|
|
376
|
+
outboundCalls.add(fnName);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
} catch {
|
|
382
|
+
// Graceful fallback if file not physically accessible
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
connectedFiles = store.getFileConnections(row.file_path, options.workspaceRoot);
|
|
386
|
+
|
|
387
|
+
for (const call of outboundCalls) {
|
|
388
|
+
try {
|
|
389
|
+
const matches = store.findSymbolsByName(call);
|
|
390
|
+
const target = matches.length === 1 ? matches[0] : undefined;
|
|
391
|
+
if (target) {
|
|
392
|
+
resolvedOutboundCalls.push({
|
|
393
|
+
symbol: call,
|
|
394
|
+
target_file: target.file_path,
|
|
395
|
+
target_range: {
|
|
396
|
+
start_line: target.line_start,
|
|
397
|
+
end_line: target.line_end,
|
|
398
|
+
total_lines: target.line_count,
|
|
399
|
+
},
|
|
400
|
+
domain: target.domain_name,
|
|
401
|
+
is_resolved: true,
|
|
402
|
+
});
|
|
403
|
+
} else {
|
|
404
|
+
resolvedOutboundCalls.push({ symbol: call, is_resolved: false });
|
|
405
|
+
}
|
|
406
|
+
} catch {
|
|
407
|
+
resolvedOutboundCalls.push({ symbol: call, is_resolved: false });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const complexitySmell: SymbolComplexitySmell | undefined =
|
|
413
|
+
row.line_count > 300
|
|
414
|
+
? {
|
|
415
|
+
is_high_complexity: true,
|
|
416
|
+
threshold: 300,
|
|
417
|
+
total_lines: row.line_count,
|
|
418
|
+
warning: `Symbol '${row.name}' spans ${row.line_count} lines (exceeds 300-line threshold). Candidate for decomposition/refactoring.`,
|
|
419
|
+
}
|
|
420
|
+
: undefined;
|
|
421
|
+
|
|
422
|
+
return {
|
|
423
|
+
symbol_ref: row.symbol_ref,
|
|
424
|
+
visibility_semantics: "legacy_normalized",
|
|
425
|
+
symbol: row.name,
|
|
426
|
+
kind: row.kind,
|
|
427
|
+
file_path: row.file_path,
|
|
428
|
+
domain: row.domain_name,
|
|
429
|
+
exact_range: {
|
|
430
|
+
start_line: row.line_start,
|
|
431
|
+
end_line: row.line_end,
|
|
432
|
+
total_lines: row.line_count,
|
|
433
|
+
},
|
|
434
|
+
signature: row.signature,
|
|
435
|
+
visibility: row.visibility,
|
|
436
|
+
dependencies_injected: Array.from(dependenciesInjected),
|
|
437
|
+
outbound_calls: Array.from(outboundCalls),
|
|
438
|
+
resolved_outbound_calls:
|
|
439
|
+
resolvedOutboundCalls.length > 0
|
|
440
|
+
? resolvedOutboundCalls.map((call) => ({ ...call, derivation: "inferred" as const }))
|
|
441
|
+
: undefined,
|
|
442
|
+
complexity_smell: complexitySmell,
|
|
443
|
+
sibling_methods: siblingMethods.length > 0 ? siblingMethods : undefined,
|
|
444
|
+
connected_files: connectedFiles,
|
|
445
|
+
...(options.includeDependencies === true
|
|
446
|
+
? {
|
|
447
|
+
relationships: store
|
|
448
|
+
.getImportRelationships(options.workspaceRoot, row.file_path)
|
|
449
|
+
.filter((edge) => edge.source.file === row.file_path),
|
|
450
|
+
}
|
|
451
|
+
: {}),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
@@ -17,7 +17,7 @@ export function symbolWorkspace(repo: SeptumRepository, explicit?: string): stri
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
type TextResult = { content: Array<{ type: string; text: string }>; metadata?: unknown };
|
|
20
|
-
type EvidenceQuery = { operation: "locate" | "inspect" | "impact"; requested?: SymbolReference; diagnostics?: string[] };
|
|
20
|
+
type EvidenceQuery = { operation: "locate" | "inspect" | "impact"; requested?: SymbolReference; diagnostics?: string[]; includeCapabilities?: boolean };
|
|
21
21
|
|
|
22
22
|
/** Checks the selected source and observed reads, without certifying a legacy caller/dependency closure. */
|
|
23
23
|
export function withSymbolEvidence<T extends TextResult>(repo: SeptumRepository, root: string, query: EvidenceQuery, build: () => T): T {
|
|
@@ -88,10 +88,10 @@ export function withSymbolEvidence<T extends TextResult>(repo: SeptumRepository,
|
|
|
88
88
|
payload.summary = `${payload.summary} | ${note}`;
|
|
89
89
|
payload.message = `${payload.message} | ${note}`;
|
|
90
90
|
}
|
|
91
|
-
const enriched = { ...payload, ...(target ? { capabilities: getOperationCapabilities(target.file_path) } : {}), retrieval: leanRetrieval };
|
|
91
|
+
const enriched = { ...payload, ...(target && query.includeCapabilities ? { capabilities: getOperationCapabilities(target.file_path) } : {}), retrieval: leanRetrieval };
|
|
92
92
|
return {
|
|
93
93
|
...result,
|
|
94
|
-
content: [{ ...result.content[0]!, text: JSON.stringify(enriched
|
|
94
|
+
content: [{ ...result.content[0]!, text: JSON.stringify(enriched) }, ...result.content.slice(1)],
|
|
95
95
|
...("metadata" in result ? { metadata: enriched } : { metadata: enriched }),
|
|
96
96
|
} as T;
|
|
97
97
|
}
|
|
@@ -16,7 +16,7 @@ export function bindContextFile(path: string, text: string) {
|
|
|
16
16
|
readFile: name => name === path ? text : undefined, getCanonicalFileName: name => name,
|
|
17
17
|
useCaseSensitiveFileNames: () => true, getNewLine: () => "\n",
|
|
18
18
|
};
|
|
19
|
-
const program = ts.createProgram([path], { noLib: true, noResolve: true }, host);
|
|
19
|
+
const program = ts.createProgram([path], { allowJs: true, noLib: true, noResolve: true, jsx: ts.JsxEmit.Preserve }, host);
|
|
20
20
|
const checker = program.getTypeChecker();
|
|
21
21
|
function top(node: ts.Node): ts.Node {
|
|
22
22
|
while (node.parent && node.parent !== source) node = node.parent;
|
|
@@ -24,10 +24,19 @@ export function bindContextFile(path: string, text: string) {
|
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
26
|
source,
|
|
27
|
+
checker,
|
|
27
28
|
hasErrors: program.getSyntacticDiagnostics(source).length > 0,
|
|
28
29
|
declaration(start: number, end: number) {
|
|
29
|
-
|
|
30
|
+
const stmt = source.statements.find(node => source.getLineAndCharacterOfPosition(node.getStart()).line + 1 <= start &&
|
|
30
31
|
source.getLineAndCharacterOfPosition(node.end).line + 1 >= end);
|
|
32
|
+
if (stmt && ts.isClassDeclaration(stmt)) {
|
|
33
|
+
const member = stmt.members.find(m =>
|
|
34
|
+
source.getLineAndCharacterOfPosition(m.getStart()).line + 1 <= start &&
|
|
35
|
+
source.getLineAndCharacterOfPosition(m.end).line + 1 >= end
|
|
36
|
+
);
|
|
37
|
+
if (member) return member;
|
|
38
|
+
}
|
|
39
|
+
return stmt;
|
|
31
40
|
},
|
|
32
41
|
contract(node: ts.ClassDeclaration) {
|
|
33
42
|
const printer = ts.createPrinter();
|
|
@@ -198,16 +207,38 @@ export function bindContextFile(path: string, text: string) {
|
|
|
198
207
|
}
|
|
199
208
|
}
|
|
200
209
|
if (!signatureNodes && ts.isCallExpression(child)) {
|
|
210
|
+
const effectful = (arg: ts.Node): boolean => ts.isCallExpression(arg) || ts.isNewExpression(arg) ||
|
|
211
|
+
ts.isAwaitExpression(arg) || ts.isDeleteExpression(arg) ||
|
|
212
|
+
ts.isBinaryExpression(arg) && arg.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && arg.operatorToken.kind <= ts.SyntaxKind.LastAssignment ||
|
|
213
|
+
ts.isPostfixUnaryExpression(arg) || ts.forEachChild(arg, n => effectful(n) || undefined) === true;
|
|
214
|
+
const callArgs = () => child.arguments.length <= 16
|
|
215
|
+
? child.arguments.map(arg => child.arguments.some(effectful) ? unknown : evaluate(arg))
|
|
216
|
+
: Array(16).fill(unknown);
|
|
217
|
+
|
|
201
218
|
if (ts.isIdentifier(child.expression)) {
|
|
202
|
-
const effectful = (arg: ts.Node): boolean => ts.isCallExpression(arg) || ts.isNewExpression(arg) ||
|
|
203
|
-
ts.isAwaitExpression(arg) || ts.isDeleteExpression(arg) ||
|
|
204
|
-
ts.isBinaryExpression(arg) && arg.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && arg.operatorToken.kind <= ts.SyntaxKind.LastAssignment ||
|
|
205
|
-
ts.isPostfixUnaryExpression(arg) || ts.forEachChild(arg, n => effectful(n) || undefined) === true;
|
|
206
219
|
for (const declaration of checker.getSymbolAtLocation(child.expression)?.declarations ?? []) {
|
|
207
220
|
calls.push({ target: top(declaration),
|
|
208
221
|
name: ts.isImportSpecifier(declaration) ? (declaration.propertyName ?? declaration.name).text :
|
|
209
222
|
ts.isImportClause(declaration) ? "default" : undefined,
|
|
210
|
-
arguments:
|
|
223
|
+
arguments: callArgs() });
|
|
224
|
+
}
|
|
225
|
+
} else if (
|
|
226
|
+
ts.isPropertyAccessExpression(child.expression) &&
|
|
227
|
+
child.expression.expression.kind === ts.SyntaxKind.ThisKeyword &&
|
|
228
|
+
ts.isClassDeclaration(node.parent)
|
|
229
|
+
) {
|
|
230
|
+
const memberName = child.expression.name.text;
|
|
231
|
+
const sibling = node.parent.members.find(
|
|
232
|
+
(m) =>
|
|
233
|
+
m !== node &&
|
|
234
|
+
(ts.isMethodDeclaration(m) || ts.isGetAccessorDeclaration(m)) &&
|
|
235
|
+
m.name &&
|
|
236
|
+
(ts.isIdentifier(m.name) || ts.isStringLiteral(m.name)) &&
|
|
237
|
+
m.name.text === memberName
|
|
238
|
+
);
|
|
239
|
+
if (sibling) {
|
|
240
|
+
locals.add(sibling);
|
|
241
|
+
calls.push({ target: sibling, arguments: callArgs() });
|
|
211
242
|
}
|
|
212
243
|
}
|
|
213
244
|
ts.forEachChild(child, visit);
|