@dimassetoid/septum-mcp 0.2.1 → 0.5.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 -45
- package/package.json +8 -6
- package/src/cli/commands/check.ts +41 -26
- package/src/cli/commands/hook.ts +77 -105
- package/src/cli/commands/init.ts +35 -9
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +35 -9
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +15 -51
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +51 -27
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +46 -35
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +299 -178
- package/src/core/boundary/staged-auditor.ts +188 -34
- package/src/core/config/domain-ownership.ts +47 -0
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +82 -54
- package/src/core/config/schema.ts +24 -46
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +326 -543
- package/src/core/database/repositories/domain.repository.ts +48 -4
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -259
- package/src/core/database/repository.ts +138 -24
- package/src/core/database/schema.ts +28 -33
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +269 -0
- package/src/core/discovery/topology-detector.ts +153 -170
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +378 -212
- 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 +16 -4
- package/src/core/parser/extractors/csharp.ts +9 -5
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +400 -516
- package/src/core/parser/extractors/elysia-semantic.ts +172 -496
- package/src/core/parser/extractors/express-semantic.ts +195 -398
- package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
- package/src/core/parser/extractors/fastify-semantic.ts +216 -732
- package/src/core/parser/extractors/flask-semantic.ts +92 -388
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +210 -508
- 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 -530
- package/src/core/parser/extractors/java.ts +7 -5
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +169 -333
- 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 +84 -336
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
- 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 +17 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +9 -8
- package/src/core/parser/extractors/registry.ts +28 -5
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +10 -7
- package/src/core/parser/extractors/rust.ts +35 -17
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +75 -262
- 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 +36 -216
- 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 +77 -51
- 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/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 +375 -311
- 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 +162 -181
- package/src/core/resolver/interpretation-inputs.ts +65 -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 +133 -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 +74 -0
- package/src/core/resolver/module-resolver.ts +18 -7
- 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 +94 -0
- package/src/core/resolver/slice-format.ts +22 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +477 -0
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +57 -278
- package/src/core/resources/ignore.ts +21 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +116 -0
- package/src/core/retrieval/context.ts +457 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/source-context.ts +448 -0
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +293 -0
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +225 -37
- package/src/index.ts +0 -3
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +253 -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 -1105
- package/src/mcp/server.ts +263 -597
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +69 -4
- package/src/mcp/tools/map.ts +126 -0
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +480 -26
- 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 +102 -18
- package/src/mcp/workspace-watcher.ts +38 -19
- package/src/types/index.ts +47 -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/check-boundary.ts +0 -387
- package/src/mcp/tools/domain.ts +0 -40
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-domain-catalog.ts +0 -226
- 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/get-symbol-impact.ts +0 -64
- package/src/mcp/tools/get-symbol.ts +0 -175
- package/src/mcp/tools/locate-symbol.ts +0 -196
- package/src/mcp/tools/register-domain.ts +0 -75
- package/src/mcp/tools/register-feature.ts +0 -110
- package/src/mcp/tools/trace-vertical-slice.ts +0 -80
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import type { SeptumRepository } from "../database/repository.ts";
|
|
3
|
+
import type { SymbolReference } from "../../types/index.ts";
|
|
4
|
+
import { computeContentHash } from "../ingestion/hasher.ts";
|
|
5
|
+
import { collectSourceSkipsSync, probeSourcePath, readSourceFile } from "../resources/source-files.ts";
|
|
6
|
+
import { assertPathContained } from "../resolver/path-resolver.ts";
|
|
7
|
+
import { getOperationCapabilities, PARSER_FINGERPRINT } from "../parser/language-capabilities.ts";
|
|
8
|
+
|
|
9
|
+
/** Content-bound declaration identity, shared across operations; not a continuation token. */
|
|
10
|
+
export function symbolTargetId(workspace: string, ref: SymbolReference): string {
|
|
11
|
+
return computeContentHash(JSON.stringify([resolve(workspace), ref.file_path, ref.language, ref.name, ref.kind,
|
|
12
|
+
ref.signature, ref.start_line, ref.end_line, ref.indexed_content_hash, ref.container ?? null, ref.receiver ?? null]));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function symbolWorkspace(repo: SeptumRepository, explicit?: string): string {
|
|
16
|
+
return resolve(explicit || (typeof repo.getMeta === "function" ? repo.getMeta("workspace_root") : null) || process.cwd());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type TextResult = { content: Array<{ type: string; text: string }>; metadata?: unknown };
|
|
20
|
+
type EvidenceQuery = { operation: "locate" | "inspect" | "impact"; requested?: SymbolReference; diagnostics?: string[]; includeCapabilities?: boolean };
|
|
21
|
+
|
|
22
|
+
/** Checks the selected source and observed reads, without certifying a legacy caller/dependency closure. */
|
|
23
|
+
export function withSymbolEvidence<T extends TextResult>(repo: SeptumRepository, root: string, query: EvidenceQuery, build: () => T): T {
|
|
24
|
+
const meta = (key: string) => typeof repo.getMeta === "function" ? repo.getMeta(key) : null;
|
|
25
|
+
const collected = collectSourceSkipsSync(root, () => {
|
|
26
|
+
const result = build();
|
|
27
|
+
const payload = JSON.parse(result.content[0]!.text);
|
|
28
|
+
const target: SymbolReference | undefined = payload.symbol_ref;
|
|
29
|
+
const reasons = [...(query.diagnostics ?? [])];
|
|
30
|
+
let freshness: "current" | "stale" | "unavailable" = "unavailable";
|
|
31
|
+
let observedHash: string | null = null;
|
|
32
|
+
if (target) {
|
|
33
|
+
try {
|
|
34
|
+
assertPathContained(target.file_path, root, "Symbol evidence source");
|
|
35
|
+
if (probeSourcePath(resolve(root, target.file_path)) !== "file") reasons.push("target_source_unavailable");
|
|
36
|
+
else {
|
|
37
|
+
observedHash = computeContentHash(readSourceFile(resolve(root, target.file_path)));
|
|
38
|
+
const indexed = repo.getFileByPath(target.file_path);
|
|
39
|
+
if (indexed?.content_hash !== target.indexed_content_hash) reasons.push("target_index_changed");
|
|
40
|
+
else {
|
|
41
|
+
freshness = observedHash === target.indexed_content_hash ? "current" : "stale";
|
|
42
|
+
if (freshness === "stale") reasons.push("target_source_differs_from_index");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch { reasons.push("target_source_unavailable_or_out_of_scope"); }
|
|
46
|
+
} else reasons.push(payload.status === "ambiguous" ? "target_ambiguous" : payload.status === "stale_reference" ? "stale_reference" : "target_not_selected");
|
|
47
|
+
const syncState = meta("sync_state");
|
|
48
|
+
if (syncState !== "complete") reasons.push("index_completeness_unverified");
|
|
49
|
+
const parserRevision = meta("parser_revision");
|
|
50
|
+
if (parserRevision !== PARSER_FINGERPRINT) reasons.push("indexed_parser_revision_unverified");
|
|
51
|
+
return { result, payload, target, freshness, observedHash, reasons, syncState, parserRevision };
|
|
52
|
+
});
|
|
53
|
+
const { result, payload, target, freshness, observedHash, reasons, syncState, parserRevision } = collected.value;
|
|
54
|
+
const staleInputs = collected.inputs.filter(input => {
|
|
55
|
+
const indexed = repo.getFileByPath(input.path);
|
|
56
|
+
return indexed && input.hash !== "file_too_large" && indexed.content_hash !== input.hash;
|
|
57
|
+
}).length;
|
|
58
|
+
const unavailableInputs = new Set([
|
|
59
|
+
...collected.observations.paths.filter(input => input.kind !== "file" && repo.getFileByPath(input.path)).map(input => input.path),
|
|
60
|
+
...collected.skipped.filter(input => repo.getFileByPath(input.path)).map(input => input.path),
|
|
61
|
+
]).size;
|
|
62
|
+
if (staleInputs) reasons.push("observed_indexed_inputs_stale");
|
|
63
|
+
if (unavailableInputs) reasons.push("observed_indexed_inputs_unavailable");
|
|
64
|
+
if (collected.skipped.length) reasons.push("source_read_exclusions");
|
|
65
|
+
const leanRetrieval = {
|
|
66
|
+
operation: query.operation,
|
|
67
|
+
target_id: target ? symbolTargetId(root, target) : null,
|
|
68
|
+
...(query.requested ? { requested_target_id: symbolTargetId(root, query.requested) } : {}),
|
|
69
|
+
freshness,
|
|
70
|
+
freshness_scope: "selected_declaration_source_only",
|
|
71
|
+
completeness: "partial",
|
|
72
|
+
analysis_freshness: "unavailable",
|
|
73
|
+
source_version: target ? {
|
|
74
|
+
file_path: target.file_path,
|
|
75
|
+
indexed_hash: target.indexed_content_hash,
|
|
76
|
+
observed_hash: observedHash,
|
|
77
|
+
} : null,
|
|
78
|
+
...(staleInputs > 0 || unavailableInputs > 0 ? {
|
|
79
|
+
observed_inputs: {
|
|
80
|
+
stale_indexed_files: staleInputs,
|
|
81
|
+
unavailable_indexed_files: unavailableInputs,
|
|
82
|
+
},
|
|
83
|
+
} : {}),
|
|
84
|
+
reasons: [...new Set(reasons)].sort(),
|
|
85
|
+
};
|
|
86
|
+
if (query.operation === "locate" && payload.found && freshness !== "current") {
|
|
87
|
+
const note = `[SOURCE ${freshness.toUpperCase()}] Indexed coordinates are not validated against current source; synchronize before editing.`;
|
|
88
|
+
payload.summary = `${payload.summary} | ${note}`;
|
|
89
|
+
payload.message = `${payload.message} | ${note}`;
|
|
90
|
+
}
|
|
91
|
+
const enriched = { ...payload, ...(target && query.includeCapabilities ? { capabilities: getOperationCapabilities(target.file_path) } : {}), retrieval: leanRetrieval };
|
|
92
|
+
return {
|
|
93
|
+
...result,
|
|
94
|
+
content: [{ ...result.content[0]!, text: JSON.stringify(enriched) }, ...result.content.slice(1)],
|
|
95
|
+
...("metadata" in result ? { metadata: enriched } : { metadata: enriched }),
|
|
96
|
+
} as T;
|
|
97
|
+
}
|