@dimassetoid/septum-mcp 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +124 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +122 -0
- package/src/cli/commands/hook.ts +268 -0
- package/src/cli/commands/init.ts +553 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +41 -0
- package/src/cli/commands/topology.ts +161 -0
- package/src/cli/index.ts +167 -0
- package/src/cli/scaffold/harness-config.ts +621 -0
- package/src/cli/templates/hooks.ts +75 -0
- package/src/cli/templates/rules.ts +50 -0
- package/src/cli/templates/skill.ts +51 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +442 -0
- package/src/core/boundary/staged-auditor.ts +58 -0
- package/src/core/config/loader.ts +122 -0
- package/src/core/config/schema.ts +69 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +712 -0
- package/src/core/database/repositories/domain.repository.ts +330 -0
- package/src/core/database/repositories/environment.repository.ts +207 -0
- package/src/core/database/repositories/file.repository.ts +117 -0
- package/src/core/database/repositories/meta.repository.ts +33 -0
- package/src/core/database/repositories/symbol.repository.ts +508 -0
- package/src/core/database/repository.ts +303 -0
- package/src/core/database/schema.ts +154 -0
- package/src/core/discovery/topology-detector.ts +805 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +623 -0
- package/src/core/parser/behavioral-analyzer.ts +119 -0
- package/src/core/parser/boundary-tracker.ts +443 -0
- package/src/core/parser/extractors/base.ts +67 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +244 -0
- package/src/core/parser/extractors/django-semantic.ts +687 -0
- package/src/core/parser/extractors/elysia-semantic.ts +538 -0
- package/src/core/parser/extractors/express-semantic.ts +444 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +736 -0
- package/src/core/parser/extractors/fastify-semantic.ts +774 -0
- package/src/core/parser/extractors/flask-semantic.ts +515 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +611 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +567 -0
- package/src/core/parser/extractors/java.ts +225 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1122 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +368 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +543 -0
- package/src/core/parser/extractors/php.ts +569 -0
- package/src/core/parser/extractors/python.ts +498 -0
- package/src/core/parser/extractors/registry.ts +78 -0
- package/src/core/parser/extractors/ruby.ts +234 -0
- package/src/core/parser/extractors/rust.ts +286 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +22 -0
- package/src/core/parser/extractors/symfony-semantic.ts +354 -0
- package/src/core/parser/extractors/typescript.ts +826 -0
- package/src/core/parser/language-capabilities.ts +71 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +216 -0
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +90 -0
- package/src/core/parser/schema/schema-provider-registry.ts +43 -0
- package/src/core/parser/schema/schema-provider.interface.ts +33 -0
- package/src/core/parser/tree-sitter.ts +63 -0
- package/src/core/parser/wasm-assets.ts +25 -0
- package/src/core/parser/wasm-loader.ts +274 -0
- package/src/core/resolver/call-graph-tracer.ts +724 -0
- package/src/core/resolver/import-resolver.ts +437 -0
- package/src/core/resolver/module-resolver.ts +482 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- package/src/core/resolver/symbol-locator.ts +276 -0
- package/src/core/resolver/symbol-reference.ts +53 -0
- package/src/core/resolver/vertical-slice-tracer.ts +366 -0
- package/src/core/resources/ignore.ts +123 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +62 -0
- package/src/core/resources/work-queue.ts +74 -0
- package/src/core/session/session-manager.ts +107 -0
- package/src/core/telemetry/telemetry.ts +97 -0
- package/src/core/topology/environment-detector.ts +973 -0
- package/src/core/topology/types.ts +83 -0
- package/src/index.ts +21 -0
- package/src/mcp/schemas.ts +1105 -0
- package/src/mcp/server.ts +774 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +387 -0
- package/src/mcp/tools/domain.ts +40 -0
- package/src/mcp/tools/feature.ts +67 -0
- package/src/mcp/tools/get-domain-catalog.ts +226 -0
- package/src/mcp/tools/get-environment-topology.ts +138 -0
- package/src/mcp/tools/get-feature-context.ts +224 -0
- package/src/mcp/tools/get-symbol-hotspots.ts +54 -0
- package/src/mcp/tools/get-symbol-impact.ts +64 -0
- package/src/mcp/tools/get-symbol.ts +175 -0
- package/src/mcp/tools/locate-symbol.ts +196 -0
- package/src/mcp/tools/register-domain.ts +75 -0
- package/src/mcp/tools/register-feature.ts +110 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +93 -0
- package/src/mcp/tools/trace-vertical-slice.ts +80 -0
- package/src/mcp/workspace-manager.ts +159 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +456 -0
- package/src/types/wasm.d.ts +4 -0
- package/src/utils/version-check.ts +209 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import { symbolReference, matchesSymbolName, matchesSymbolReference } from "../../resolver/symbol-reference.ts";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import type { Database } from "bun:sqlite";
|
|
5
|
+
import type {
|
|
6
|
+
DomainRecord,
|
|
7
|
+
ExtractedSymbol,
|
|
8
|
+
FileRecord,
|
|
9
|
+
GetSymbolDetailsResponse,
|
|
10
|
+
FileConnectionsSummary,
|
|
11
|
+
ResolvedOutboundCall,
|
|
12
|
+
SymbolComplexitySmell,
|
|
13
|
+
SymbolKind,
|
|
14
|
+
SymbolRecord,
|
|
15
|
+
SymbolCandidate,
|
|
16
|
+
SymbolSelectionOptions,
|
|
17
|
+
} from "../../../types/index.ts";
|
|
18
|
+
import { DependencyRepository } from "./dependency.repository.ts";
|
|
19
|
+
|
|
20
|
+
const SQL_KEYWORD_BLACKLIST = new Set([
|
|
21
|
+
"VALUES",
|
|
22
|
+
"WHERE",
|
|
23
|
+
"SELECT",
|
|
24
|
+
"FROM",
|
|
25
|
+
"JOIN",
|
|
26
|
+
"LIKE",
|
|
27
|
+
"INSERT",
|
|
28
|
+
"UPDATE",
|
|
29
|
+
"DELETE",
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
function stripCommentsAndStrings(source: string): string {
|
|
33
|
+
return source
|
|
34
|
+
.replace(/\/\*[\s\S]*?\*\//g, " ")
|
|
35
|
+
.replace(/\/\/.*$/gm, " ")
|
|
36
|
+
.replace(/'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`/g, '""');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class SymbolRepository {
|
|
40
|
+
constructor(private db: Database) {}
|
|
41
|
+
|
|
42
|
+
public replaceFileSymbols(fileId: number, symbols: ExtractedSymbol[]): void {
|
|
43
|
+
this.db.query("DELETE FROM symbols WHERE file_id = ?").run(fileId);
|
|
44
|
+
if (symbols.length === 0) return;
|
|
45
|
+
|
|
46
|
+
const stmt = this.db.query(
|
|
47
|
+
`INSERT INTO symbols (file_id, name, kind, signature, visibility, line_start, line_end, line_count, nesting_depth)
|
|
48
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
for (const sym of symbols) {
|
|
52
|
+
const lineCount = sym.line_count ?? Math.max(1, sym.line_end - sym.line_start + 1);
|
|
53
|
+
const nestingDepth = sym.nesting_depth ?? 1;
|
|
54
|
+
stmt.run(
|
|
55
|
+
fileId,
|
|
56
|
+
sym.name,
|
|
57
|
+
sym.kind,
|
|
58
|
+
sym.signature,
|
|
59
|
+
sym.visibility,
|
|
60
|
+
sym.line_start,
|
|
61
|
+
sym.line_end,
|
|
62
|
+
lineCount,
|
|
63
|
+
nestingDepth
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public getSymbolsByFileId(fileId: number): SymbolRecord[] {
|
|
69
|
+
return this.db
|
|
70
|
+
.query<SymbolRecord, [number]>(
|
|
71
|
+
"SELECT * FROM symbols WHERE file_id = ? ORDER BY line_start ASC"
|
|
72
|
+
)
|
|
73
|
+
.all(fileId);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public findSymbolsByName(
|
|
77
|
+
name: string,
|
|
78
|
+
options: SymbolSelectionOptions = {}
|
|
79
|
+
): SymbolCandidate[] {
|
|
80
|
+
const target = name.trim().replace(/\(\)$/, "");
|
|
81
|
+
const leaf = target.split(/::|->|[.#\\]/).pop() ?? target;
|
|
82
|
+
let query = `SELECT s.*, f.path AS file_path, f.content_hash AS indexed_content_hash, d.name AS domain_name
|
|
83
|
+
FROM symbols s JOIN files f ON s.file_id = f.id JOIN domains d ON f.domain_id = d.id
|
|
84
|
+
WHERE (s.name = ? OR substr(s.name, -length(?)) = ?)`;
|
|
85
|
+
const params: string[] = [target, leaf, leaf];
|
|
86
|
+
if (options.domain) { query += " AND d.name = ?"; params.push(options.domain); }
|
|
87
|
+
const filePath = options.filePath ?? options.reference?.file_path;
|
|
88
|
+
if (filePath) { query += " AND f.path = ?"; params.push(filePath); }
|
|
89
|
+
query += " ORDER BY f.path, s.line_start, s.line_end, s.signature, s.id";
|
|
90
|
+
return this.db.query<SymbolCandidate, string[]>(query).all(...params)
|
|
91
|
+
.filter(row => matchesSymbolName(row, target))
|
|
92
|
+
.map(row => ({ ...row, symbol_ref: symbolReference(row) }))
|
|
93
|
+
.filter(row => !options.reference || matchesSymbolReference(row.symbol_ref, options.reference));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public findContainers(
|
|
97
|
+
containerName: string
|
|
98
|
+
): Array<{ file: FileRecord; symbol?: SymbolRecord }> {
|
|
99
|
+
const symbolQuery = `
|
|
100
|
+
SELECT s.*, f.path AS file_path, f.id AS f_id, f.domain_id AS f_domain_id,
|
|
101
|
+
f.archetype AS f_archetype, f.content_hash AS f_content_hash,
|
|
102
|
+
f.line_count AS f_line_count, f.mtime_ms AS f_mtime_ms,
|
|
103
|
+
f.size_bytes AS f_size_bytes, f.last_scanned_at AS f_last_scanned_at
|
|
104
|
+
FROM symbols s
|
|
105
|
+
JOIN files f ON s.file_id = f.id
|
|
106
|
+
WHERE (s.name = ? OR s.name LIKE ? OR s.name LIKE ?)
|
|
107
|
+
AND s.kind IN ('class', 'interface', 'trait', 'enum')
|
|
108
|
+
LIMIT 10
|
|
109
|
+
`;
|
|
110
|
+
const rows = this.db
|
|
111
|
+
.query<any, [string, string, string]>(symbolQuery)
|
|
112
|
+
.all(containerName, `%\\${containerName}`, `%/${containerName}`);
|
|
113
|
+
|
|
114
|
+
if (rows.length > 0) {
|
|
115
|
+
return rows.map((r) => ({
|
|
116
|
+
file: {
|
|
117
|
+
id: r.f_id,
|
|
118
|
+
domain_id: r.f_domain_id,
|
|
119
|
+
path: r.file_path,
|
|
120
|
+
archetype: r.f_archetype,
|
|
121
|
+
content_hash: r.f_content_hash,
|
|
122
|
+
line_count: r.f_line_count,
|
|
123
|
+
mtime_ms: r.f_mtime_ms,
|
|
124
|
+
size_bytes: r.f_size_bytes,
|
|
125
|
+
last_scanned_at: r.f_last_scanned_at,
|
|
126
|
+
},
|
|
127
|
+
symbol: {
|
|
128
|
+
id: r.id,
|
|
129
|
+
file_id: r.file_id,
|
|
130
|
+
name: r.name,
|
|
131
|
+
kind: r.kind,
|
|
132
|
+
signature: r.signature,
|
|
133
|
+
visibility: r.visibility,
|
|
134
|
+
line_start: r.line_start,
|
|
135
|
+
line_end: r.line_end,
|
|
136
|
+
line_count: r.line_count ?? (r.line_end - r.line_start + 1),
|
|
137
|
+
nesting_depth: r.nesting_depth ?? 1,
|
|
138
|
+
},
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const fileQuery = `
|
|
143
|
+
SELECT * FROM files
|
|
144
|
+
WHERE path LIKE ? OR path LIKE ?
|
|
145
|
+
LIMIT 10
|
|
146
|
+
`;
|
|
147
|
+
const files = this.db
|
|
148
|
+
.query<FileRecord, [string, string]>(fileQuery)
|
|
149
|
+
.all(`%/${containerName}.%`, `%\\${containerName}.%`);
|
|
150
|
+
|
|
151
|
+
return files.map((file) => ({ file }));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public getAllSymbolsWithFiles(): Array<SymbolRecord & { file_path: string }> {
|
|
155
|
+
const query = `
|
|
156
|
+
SELECT s.*, f.path AS file_path
|
|
157
|
+
FROM symbols s
|
|
158
|
+
JOIN files f ON s.file_id = f.id
|
|
159
|
+
WHERE s.kind IN ('class', 'method', 'function')
|
|
160
|
+
ORDER BY s.name ASC
|
|
161
|
+
`;
|
|
162
|
+
return this.db.query<SymbolRecord & { file_path: string }, []>(query).all();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public findSymbolWithDomain(symbolName: string): {
|
|
166
|
+
symbol_name: string;
|
|
167
|
+
kind: string;
|
|
168
|
+
file_path: string;
|
|
169
|
+
domain_name: string;
|
|
170
|
+
} | null {
|
|
171
|
+
const query = `
|
|
172
|
+
SELECT
|
|
173
|
+
s.name AS symbol_name,
|
|
174
|
+
s.kind,
|
|
175
|
+
f.path AS file_path,
|
|
176
|
+
d.name AS domain_name
|
|
177
|
+
FROM symbols s
|
|
178
|
+
JOIN files f ON s.file_id = f.id
|
|
179
|
+
JOIN domains d ON f.domain_id = d.id
|
|
180
|
+
WHERE s.name = ?
|
|
181
|
+
LIMIT 1
|
|
182
|
+
`;
|
|
183
|
+
return this.db.query<any, [string]>(query).get(symbolName) ?? null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public findSymbolWithMembers(symbolName: string): {
|
|
187
|
+
symbol_name: string;
|
|
188
|
+
kind: string;
|
|
189
|
+
signature: string;
|
|
190
|
+
file_path: string;
|
|
191
|
+
domain_name: string;
|
|
192
|
+
methods: string[];
|
|
193
|
+
properties: string[];
|
|
194
|
+
} | null {
|
|
195
|
+
const rootQuery = `
|
|
196
|
+
SELECT
|
|
197
|
+
s.id AS symbol_id,
|
|
198
|
+
s.file_id,
|
|
199
|
+
s.name AS symbol_name,
|
|
200
|
+
s.kind,
|
|
201
|
+
s.signature,
|
|
202
|
+
f.path AS file_path,
|
|
203
|
+
d.name AS domain_name
|
|
204
|
+
FROM symbols s
|
|
205
|
+
JOIN files f ON s.file_id = f.id
|
|
206
|
+
JOIN domains d ON f.domain_id = d.id
|
|
207
|
+
WHERE s.name = ?
|
|
208
|
+
LIMIT 1
|
|
209
|
+
`;
|
|
210
|
+
const root = this.db.query<any, [string]>(rootQuery).get(symbolName);
|
|
211
|
+
if (!root) return null;
|
|
212
|
+
|
|
213
|
+
const membersQuery = `
|
|
214
|
+
SELECT name, kind, signature
|
|
215
|
+
FROM symbols
|
|
216
|
+
WHERE file_id = ? AND name LIKE ?
|
|
217
|
+
ORDER BY line_start ASC
|
|
218
|
+
`;
|
|
219
|
+
const members = this.db
|
|
220
|
+
.query<any, [number, string]>(membersQuery)
|
|
221
|
+
.all(root.file_id, `${symbolName}::%`);
|
|
222
|
+
|
|
223
|
+
const methods: string[] = [];
|
|
224
|
+
const properties: string[] = [];
|
|
225
|
+
|
|
226
|
+
for (const m of members) {
|
|
227
|
+
if (m.kind === "method") {
|
|
228
|
+
methods.push(m.signature);
|
|
229
|
+
} else if (m.kind === "property") {
|
|
230
|
+
properties.push(m.signature);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
symbol_name: root.symbol_name,
|
|
236
|
+
kind: root.kind,
|
|
237
|
+
signature: root.signature,
|
|
238
|
+
file_path: root.file_path,
|
|
239
|
+
domain_name: root.domain_name,
|
|
240
|
+
methods,
|
|
241
|
+
properties,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public getFileWithDomain(filePath: string): {
|
|
246
|
+
file_id: number;
|
|
247
|
+
file_path: string;
|
|
248
|
+
domain_name: string;
|
|
249
|
+
} | null {
|
|
250
|
+
const query = `
|
|
251
|
+
SELECT
|
|
252
|
+
f.id AS file_id,
|
|
253
|
+
f.path AS file_path,
|
|
254
|
+
d.name AS domain_name
|
|
255
|
+
FROM files f
|
|
256
|
+
JOIN domains d ON f.domain_id = d.id
|
|
257
|
+
WHERE f.path = ?
|
|
258
|
+
LIMIT 1
|
|
259
|
+
`;
|
|
260
|
+
return this.db.query<any, [string]>(query).get(filePath) ?? null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
public getHotspotSymbols(options: {
|
|
264
|
+
minLines?: number;
|
|
265
|
+
minNesting?: number;
|
|
266
|
+
kind?: SymbolKind;
|
|
267
|
+
domain?: string;
|
|
268
|
+
limit?: number;
|
|
269
|
+
sortBy?: "lines" | "nesting" | "risk_score";
|
|
270
|
+
} = {}): Array<SymbolRecord & { file_path: string; domain_name: string; risk_score: number }> {
|
|
271
|
+
const minLines = options.minLines ?? 0;
|
|
272
|
+
const minNesting = options.minNesting ?? 1;
|
|
273
|
+
const limit = options.limit ?? 50;
|
|
274
|
+
const sortBy = options.sortBy ?? "risk_score";
|
|
275
|
+
|
|
276
|
+
let sql = `
|
|
277
|
+
SELECT
|
|
278
|
+
s.id,
|
|
279
|
+
s.file_id,
|
|
280
|
+
s.name,
|
|
281
|
+
s.kind,
|
|
282
|
+
s.signature,
|
|
283
|
+
s.visibility,
|
|
284
|
+
s.line_start,
|
|
285
|
+
s.line_end,
|
|
286
|
+
s.line_count,
|
|
287
|
+
s.nesting_depth,
|
|
288
|
+
f.path AS file_path,
|
|
289
|
+
d.name AS domain_name
|
|
290
|
+
FROM symbols s
|
|
291
|
+
JOIN files f ON s.file_id = f.id
|
|
292
|
+
JOIN domains d ON f.domain_id = d.id
|
|
293
|
+
WHERE s.line_count >= ? AND s.nesting_depth >= ?
|
|
294
|
+
`;
|
|
295
|
+
|
|
296
|
+
const params: any[] = [minLines, minNesting];
|
|
297
|
+
|
|
298
|
+
if (options.kind) {
|
|
299
|
+
sql += " AND s.kind = ?";
|
|
300
|
+
params.push(options.kind);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (options.domain) {
|
|
304
|
+
sql += " AND d.name = ?";
|
|
305
|
+
params.push(options.domain);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (sortBy === "nesting") {
|
|
309
|
+
sql += " ORDER BY s.nesting_depth DESC, s.line_count DESC, s.name ASC LIMIT ?";
|
|
310
|
+
} else if (sortBy === "lines") {
|
|
311
|
+
sql += " ORDER BY s.line_count DESC, s.nesting_depth DESC, s.name ASC LIMIT ?";
|
|
312
|
+
} else {
|
|
313
|
+
sql += " ORDER BY (s.line_count * (1.0 + s.nesting_depth * 0.3)) DESC, s.nesting_depth DESC, s.name ASC LIMIT ?";
|
|
314
|
+
}
|
|
315
|
+
params.push(limit);
|
|
316
|
+
|
|
317
|
+
const rows = this.db.query<any, any[]>(sql).all(...params);
|
|
318
|
+
return rows.map((r) => ({
|
|
319
|
+
...r,
|
|
320
|
+
nesting_depth: r.nesting_depth ?? 1,
|
|
321
|
+
risk_score: Math.round((r.line_count ?? 1) * (1.0 + (r.nesting_depth ?? 1) * 0.3)),
|
|
322
|
+
}));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
public getSymbolDetails(
|
|
326
|
+
symbolQuery: string,
|
|
327
|
+
options: SymbolSelectionOptions & { includeDependencies?: boolean; workspaceRoot?: string } = {}
|
|
328
|
+
): GetSymbolDetailsResponse | null {
|
|
329
|
+
const trimmed = symbolQuery.trim();
|
|
330
|
+
if (!trimmed) return null;
|
|
331
|
+
|
|
332
|
+
const candidates = this.findSymbolsByName(trimmed, options);
|
|
333
|
+
if (candidates.length !== 1) return null;
|
|
334
|
+
const row = candidates[0]!;
|
|
335
|
+
|
|
336
|
+
// 1. Sibling methods
|
|
337
|
+
const isRust = /\.rs$/i.test(row.file_path);
|
|
338
|
+
const containerName = row.symbol_ref.container ?? "";
|
|
339
|
+
const owner = ["class", "interface", "trait", "struct", "enum"].includes(row.kind) ? row.name
|
|
340
|
+
: row.kind === "method" ? containerName : "";
|
|
341
|
+
let siblingMethods: string[] = owner ? this.getSymbolsByFileId(row.file_id)
|
|
342
|
+
.filter(s => s.kind === "method" && s.id !== row.id)
|
|
343
|
+
.filter(s => symbolReference({ ...s, file_path: row.file_path, indexed_content_hash: row.indexed_content_hash }).container === owner)
|
|
344
|
+
.map(s => s.name.split(/::|[.#]/).pop()!) : [];
|
|
345
|
+
|
|
346
|
+
siblingMethods = Array.from(new Set(siblingMethods)).filter(
|
|
347
|
+
(m) => !SQL_KEYWORD_BLACKLIST.has(m.toUpperCase())
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
// 2. Dependencies Injected (from signature type-hints and constructor)
|
|
351
|
+
const dependenciesInjected = new Set<string>();
|
|
352
|
+
const outboundCalls = new Set<string>();
|
|
353
|
+
const resolvedOutboundCalls: ResolvedOutboundCall[] = [];
|
|
354
|
+
let connectedFiles: FileConnectionsSummary = { imports_from: [], imported_by_count: 0 };
|
|
355
|
+
|
|
356
|
+
const shouldIncludeDeps = options.includeDependencies !== false;
|
|
357
|
+
|
|
358
|
+
if (shouldIncludeDeps) {
|
|
359
|
+
const extractTypeHints = (sig: string) => {
|
|
360
|
+
const paramMatch = sig.match(/\(([^)]*)\)/);
|
|
361
|
+
if (paramMatch && paramMatch[1]) {
|
|
362
|
+
const params = paramMatch[1].split(",");
|
|
363
|
+
const primitiveTypes = new Set([
|
|
364
|
+
"int", "string", "bool", "boolean", "float", "array", "iterable",
|
|
365
|
+
"callable", "void", "mixed", "object", "null", "never", "any", "number", "unknown"
|
|
366
|
+
]);
|
|
367
|
+
for (const p of params) {
|
|
368
|
+
const parts = p.trim().replace(/^\?/, "").split(/\s+/);
|
|
369
|
+
if (parts.length >= 2) {
|
|
370
|
+
const rawType = parts[0].replace(/\[\]$/, "").replace(/^[\\$]/, "");
|
|
371
|
+
if (rawType && !primitiveTypes.has(rawType.toLowerCase()) && !rawType.startsWith("$")) {
|
|
372
|
+
dependenciesInjected.add(rawType);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// Rust parameter types do not establish a dependency injection binding.
|
|
380
|
+
if (!isRust) extractTypeHints(row.signature);
|
|
381
|
+
|
|
382
|
+
// Also check constructor injection if this is a method
|
|
383
|
+
if (containerName && !isRust) {
|
|
384
|
+
const ctor = this.db
|
|
385
|
+
.query<{ signature: string }, [number, string, string]>(
|
|
386
|
+
"SELECT signature FROM symbols WHERE file_id = ? AND (name = ? OR name LIKE ?) LIMIT 1"
|
|
387
|
+
)
|
|
388
|
+
.get(row.file_id, `${containerName}::__construct`, `%::__construct`);
|
|
389
|
+
if (ctor) {
|
|
390
|
+
extractTypeHints(ctor.signature);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// 3. Outbound Calls (inspected from physical source file lines if accessible)
|
|
395
|
+
try {
|
|
396
|
+
const fullPath = options.workspaceRoot
|
|
397
|
+
? path.resolve(options.workspaceRoot, row.file_path)
|
|
398
|
+
: row.file_path;
|
|
399
|
+
if (fs.existsSync(fullPath)) {
|
|
400
|
+
const fileContent = fs.readFileSync(fullPath, "utf-8");
|
|
401
|
+
const lines = fileContent.split(/\r?\n/);
|
|
402
|
+
const start = Math.max(0, row.line_start - 1);
|
|
403
|
+
const end = Math.min(lines.length, row.line_end);
|
|
404
|
+
const rawSlice = lines.slice(start, end).join("\n");
|
|
405
|
+
const sanitizedSlice = stripCommentsAndStrings(rawSlice);
|
|
406
|
+
|
|
407
|
+
// Match Static invocations: ClassName::methodName(
|
|
408
|
+
const staticCalls = sanitizedSlice.matchAll(/([A-Z][a-zA-Z0-9_]+)::([a-zA-Z0-9_]+)\s*\(/g);
|
|
409
|
+
for (const m of staticCalls) {
|
|
410
|
+
if (m[1] !== "self" && m[1] !== "parent" && m[1] !== "static") {
|
|
411
|
+
outboundCalls.add(`${m[1]}::${m[2]}`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Match PHP property calls: $this->property->method(
|
|
416
|
+
const propCalls = sanitizedSlice.matchAll(/\$this->([a-zA-Z0-9_]+)->([a-zA-Z0-9_]+)\s*\(/g);
|
|
417
|
+
for (const m of propCalls) {
|
|
418
|
+
const propName = m[1];
|
|
419
|
+
const methodName = m[2];
|
|
420
|
+
const inferredClass = propName.charAt(0).toUpperCase() + propName.slice(1);
|
|
421
|
+
outboundCalls.add(`${inferredClass}::${methodName}`);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Match TS/JS property calls: this.property.method(
|
|
425
|
+
const tsPropCalls = sanitizedSlice.matchAll(/\bthis\.([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)\s*\(/g);
|
|
426
|
+
for (const m of tsPropCalls) {
|
|
427
|
+
const propName = m[1];
|
|
428
|
+
const methodName = m[2];
|
|
429
|
+
if (propName !== "db") {
|
|
430
|
+
const inferredClass = propName.charAt(0).toUpperCase() + propName.slice(1);
|
|
431
|
+
outboundCalls.add(`${inferredClass}::${methodName}`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
} catch {
|
|
436
|
+
// Graceful fallback if file not physically accessible
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const depRepo = new DependencyRepository(this.db);
|
|
440
|
+
connectedFiles = depRepo.getFileConnections(row.file_path,options.workspaceRoot);
|
|
441
|
+
|
|
442
|
+
// 4. Resolve Outbound Calls to target symbol line ranges
|
|
443
|
+
for (const call of outboundCalls) {
|
|
444
|
+
try {
|
|
445
|
+
const matches = this.findSymbolsByName(call);
|
|
446
|
+
const target = matches.length === 1 ? matches[0] : undefined;
|
|
447
|
+
if (target) {
|
|
448
|
+
resolvedOutboundCalls.push({
|
|
449
|
+
symbol: call,
|
|
450
|
+
target_file: target.file_path,
|
|
451
|
+
target_range: {
|
|
452
|
+
start_line: target.line_start,
|
|
453
|
+
end_line: target.line_end,
|
|
454
|
+
total_lines: target.line_count,
|
|
455
|
+
},
|
|
456
|
+
domain: target.domain_name,
|
|
457
|
+
is_resolved: true,
|
|
458
|
+
});
|
|
459
|
+
} else {
|
|
460
|
+
resolvedOutboundCalls.push({
|
|
461
|
+
symbol: call,
|
|
462
|
+
is_resolved: false,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
} catch {
|
|
466
|
+
resolvedOutboundCalls.push({
|
|
467
|
+
symbol: call,
|
|
468
|
+
is_resolved: false,
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const complexitySmell: SymbolComplexitySmell | undefined =
|
|
475
|
+
row.line_count > 300
|
|
476
|
+
? {
|
|
477
|
+
is_high_complexity: true,
|
|
478
|
+
threshold: 300,
|
|
479
|
+
total_lines: row.line_count,
|
|
480
|
+
warning: `Symbol '${row.name}' spans ${row.line_count} lines (exceeds 300-line threshold). Candidate for decomposition/refactoring.`,
|
|
481
|
+
}
|
|
482
|
+
: undefined;
|
|
483
|
+
|
|
484
|
+
return {
|
|
485
|
+
symbol_ref: row.symbol_ref,
|
|
486
|
+
visibility_semantics: "legacy_normalized",
|
|
487
|
+
symbol: row.name,
|
|
488
|
+
kind: row.kind,
|
|
489
|
+
file_path: row.file_path,
|
|
490
|
+
domain: row.domain_name,
|
|
491
|
+
exact_range: {
|
|
492
|
+
start_line: row.line_start,
|
|
493
|
+
end_line: row.line_end,
|
|
494
|
+
total_lines: row.line_count,
|
|
495
|
+
},
|
|
496
|
+
signature: row.signature,
|
|
497
|
+
visibility: row.visibility,
|
|
498
|
+
dependencies_injected: Array.from(dependenciesInjected),
|
|
499
|
+
outbound_calls: Array.from(outboundCalls),
|
|
500
|
+
resolved_outbound_calls: resolvedOutboundCalls.length > 0 ? resolvedOutboundCalls.map(call => ({ ...call, derivation: "inferred" as const })) : undefined,
|
|
501
|
+
complexity_smell: complexitySmell,
|
|
502
|
+
sibling_methods: siblingMethods.length > 0 ? siblingMethods : undefined,
|
|
503
|
+
connected_files: connectedFiles,
|
|
504
|
+
...(shouldIncludeDeps ? { relationships: new DependencyRepository(this.db).getImportRelationships(options.workspaceRoot).filter(edge => edge.source.file === row.file_path) } : {}),
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
}
|