@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
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
import { assertPathContained } from "../../resolver/path-resolver.ts";
|
|
2
|
-
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
3
|
-
import { readSourceFile } from "../../resources/source-files.ts";
|
|
4
|
-
import { computeContentHash } from "../../ingestion/hasher.ts";
|
|
5
|
-
import { getLanguageCapability } from "../../parser/language-capabilities.ts";
|
|
6
|
-
import type { ImportRelationship } from "../../../types/index.ts";
|
|
7
|
-
import * as fs from "node:fs";
|
|
8
|
-
import { dirname, join, posix, resolve, sep } from "node:path";
|
|
9
1
|
import type { Database } from "bun:sqlite";
|
|
2
|
+
import type { DependencyQueryStore } from "../../resolver/dependency-analysis.ts";
|
|
3
|
+
import type { IndexedDependency } from "../../resolver/import-evidence.ts";
|
|
10
4
|
import type {
|
|
11
5
|
ExtractedDependency,
|
|
12
|
-
FileConnectionsSummary,
|
|
13
|
-
GetSymbolImpactResponse,
|
|
14
|
-
InboundCaller,
|
|
15
|
-
SymbolReference,
|
|
16
6
|
VerticalSliceRecord,
|
|
17
7
|
} from "../../../types/index.ts";
|
|
18
8
|
|
|
19
|
-
|
|
20
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class DependencyRepository {
|
|
9
|
+
export class DependencyRepository implements DependencyQueryStore {
|
|
24
10
|
constructor(private db: Database) {}
|
|
25
11
|
|
|
26
12
|
public replaceFileDependencies(fileId: number, deps: ExtractedDependency[]): void {
|
|
@@ -41,10 +27,12 @@ export class DependencyRepository {
|
|
|
41
27
|
slice: Omit<VerticalSliceRecord, "id" | "created_at">
|
|
42
28
|
): void {
|
|
43
29
|
const existing = this.db
|
|
44
|
-
.query<VerticalSliceRecord, [string, string]>(
|
|
45
|
-
|
|
30
|
+
.query<VerticalSliceRecord, [string, string, number | null, string | null, string, string, string]>(
|
|
31
|
+
`SELECT id FROM vertical_slices WHERE http_method = ? AND route_uri = ?
|
|
32
|
+
AND domain_id IS ? AND controller_file IS ? AND controller_class = ? AND action_name = ? AND entry_kind = ?`
|
|
46
33
|
)
|
|
47
|
-
.get(slice.http_method, slice.route_uri
|
|
34
|
+
.get(slice.http_method, slice.route_uri, slice.domain_id, slice.controller_file,
|
|
35
|
+
slice.controller_class, slice.action_name, slice.entry_kind ?? "http_route");
|
|
48
36
|
|
|
49
37
|
if (existing) {
|
|
50
38
|
this.db
|
|
@@ -69,53 +57,128 @@ export class DependencyRepository {
|
|
|
69
57
|
existing.id
|
|
70
58
|
);
|
|
71
59
|
} else {
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
60
|
+
this.insertVerticalSlice(slice);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public insertVerticalSlice(slice: Omit<VerticalSliceRecord, "id" | "created_at">): void {
|
|
65
|
+
this.insertVerticalSlices([slice]);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public insertVerticalSlices(slices: ReadonlyArray<Omit<VerticalSliceRecord, "id" | "created_at">>): void {
|
|
69
|
+
if (slices.length === 0) return;
|
|
70
|
+
const stmt = this.db.query(
|
|
71
|
+
`INSERT INTO vertical_slices (
|
|
72
|
+
domain_id, feature_key, http_method, route_uri, route_name,
|
|
73
|
+
controller_class, action_name, controller_file, controller_line,
|
|
74
|
+
architecture_style, entry_kind, execution_chain_json
|
|
75
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
76
|
+
);
|
|
77
|
+
for (const slice of slices) {
|
|
78
|
+
stmt.run(
|
|
79
|
+
slice.domain_id,
|
|
80
|
+
slice.feature_key,
|
|
81
|
+
slice.http_method,
|
|
82
|
+
slice.route_uri,
|
|
83
|
+
slice.route_name,
|
|
84
|
+
slice.controller_class,
|
|
85
|
+
slice.action_name,
|
|
86
|
+
slice.controller_file,
|
|
87
|
+
slice.controller_line,
|
|
88
|
+
slice.architecture_style ?? "clean",
|
|
89
|
+
slice.entry_kind ?? "http_route",
|
|
90
|
+
slice.execution_chain_json
|
|
91
|
+
);
|
|
94
92
|
}
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
public findVerticalSlices(searchTerm: string): VerticalSliceRecord[] {
|
|
98
96
|
const term = searchTerm.trim();
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
97
|
+
const runQuery = (candidate: string) => {
|
|
98
|
+
const wild = `%${candidate}%`;
|
|
99
|
+
const metadataQuery = `
|
|
100
|
+
SELECT * FROM vertical_slices
|
|
101
|
+
WHERE route_uri LIKE ?
|
|
102
|
+
OR route_name LIKE ?
|
|
103
|
+
OR controller_class LIKE ?
|
|
104
|
+
OR action_name LIKE ?
|
|
105
|
+
OR feature_key LIKE ?
|
|
106
|
+
ORDER BY id ASC
|
|
107
|
+
`;
|
|
108
|
+
const metaRows = this.db
|
|
109
|
+
.query<VerticalSliceRecord, [string, string, string, string, string]>(metadataQuery)
|
|
110
|
+
.all(wild, wild, wild, wild, wild);
|
|
111
|
+
if (metaRows.length > 0) return metaRows;
|
|
112
|
+
|
|
113
|
+
const chainQuery = `
|
|
114
|
+
SELECT * FROM vertical_slices
|
|
115
|
+
WHERE execution_chain_json LIKE ?
|
|
116
|
+
ORDER BY id ASC
|
|
117
|
+
`;
|
|
118
|
+
return this.db.query<VerticalSliceRecord, [string]>(chainQuery).all(wild);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const direct = runQuery(term);
|
|
122
|
+
if (direct.length > 0 || !term || term.includes("_")) return direct;
|
|
123
|
+
|
|
124
|
+
// Normalize PascalCase / camelCase queries (e.g. AppSetActive -> app_set_active)
|
|
125
|
+
const snake = term
|
|
126
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
127
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
128
|
+
.toLowerCase();
|
|
129
|
+
if (snake !== term.toLowerCase()) {
|
|
130
|
+
return runQuery(snake);
|
|
131
|
+
}
|
|
132
|
+
return direct;
|
|
113
133
|
}
|
|
114
134
|
|
|
115
135
|
public getAllVerticalSlices(): VerticalSliceRecord[] {
|
|
116
136
|
return this.db.query<VerticalSliceRecord, []>("SELECT * FROM vertical_slices ORDER BY id ASC").all();
|
|
117
137
|
}
|
|
118
138
|
|
|
139
|
+
public findExactVerticalSlices(rawQuery: string, controllerFile?: string): VerticalSliceRecord[] {
|
|
140
|
+
const trimmed = rawQuery.trim();
|
|
141
|
+
if (!trimmed) return [];
|
|
142
|
+
const fileFilter = controllerFile ? " AND controller_file = ?" : "";
|
|
143
|
+
const fileParams = controllerFile ? [controllerFile] : [];
|
|
144
|
+
|
|
145
|
+
const methodUri = trimmed.match(/^([A-Z][A-Z0-9-]*)\s+(\/[^\s]*)$/i);
|
|
146
|
+
if (methodUri) {
|
|
147
|
+
const httpMethod = methodUri[1]!.toUpperCase();
|
|
148
|
+
const uri = methodUri[2]!;
|
|
149
|
+
return this.db
|
|
150
|
+
.query<VerticalSliceRecord, string[]>(
|
|
151
|
+
`SELECT * FROM vertical_slices
|
|
152
|
+
WHERE route_uri = ? AND (UPPER(http_method) = ? OR UPPER(http_method) = 'ANY')${fileFilter}
|
|
153
|
+
ORDER BY id ASC`
|
|
154
|
+
)
|
|
155
|
+
.all(uri, httpMethod, ...fileParams);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (trimmed.startsWith("/")) {
|
|
159
|
+
return this.db
|
|
160
|
+
.query<VerticalSliceRecord, string[]>(
|
|
161
|
+
`SELECT * FROM vertical_slices WHERE route_uri = ?${fileFilter} ORDER BY id ASC`
|
|
162
|
+
)
|
|
163
|
+
.all(trimmed, ...fileParams);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const ctrlAction = trimmed.match(/^([A-Za-z0-9_\\]+)(?:@|::)([A-Za-z0-9_]+)$/);
|
|
167
|
+
if (ctrlAction) {
|
|
168
|
+
return this.db
|
|
169
|
+
.query<VerticalSliceRecord, string[]>(
|
|
170
|
+
`SELECT * FROM vertical_slices WHERE controller_class = ? AND action_name = ?${fileFilter} ORDER BY id ASC`
|
|
171
|
+
)
|
|
172
|
+
.all(ctrlAction[1]!, ctrlAction[2]!, ...fileParams);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return this.db
|
|
176
|
+
.query<VerticalSliceRecord, string[]>(
|
|
177
|
+
`SELECT * FROM vertical_slices WHERE route_name = ?${fileFilter} ORDER BY id ASC`
|
|
178
|
+
)
|
|
179
|
+
.all(trimmed, ...fileParams);
|
|
180
|
+
}
|
|
181
|
+
|
|
119
182
|
public countVerticalSlices(): number {
|
|
120
183
|
const row = this.db
|
|
121
184
|
.query<{ cnt: number }, []>("SELECT COUNT(*) as cnt FROM vertical_slices")
|
|
@@ -131,14 +194,7 @@ export class DependencyRepository {
|
|
|
131
194
|
}
|
|
132
195
|
}
|
|
133
196
|
|
|
134
|
-
public getAllDependenciesWithDomains(): Array<{
|
|
135
|
-
source_file: string;
|
|
136
|
-
source_domain: string;
|
|
137
|
-
line_number: number;
|
|
138
|
-
target: string;
|
|
139
|
-
statement: string;
|
|
140
|
-
is_external: boolean;
|
|
141
|
-
}> {
|
|
197
|
+
public getAllDependenciesWithDomains(sourceFile?: string): Array<IndexedDependency & { resolved_target_file?: string | null }> {
|
|
142
198
|
const query = `
|
|
143
199
|
SELECT
|
|
144
200
|
f.path AS source_file,
|
|
@@ -146,307 +202,181 @@ export class DependencyRepository {
|
|
|
146
202
|
dep.line_number,
|
|
147
203
|
dep.target_symbol_or_path AS target,
|
|
148
204
|
dep.import_statement AS statement,
|
|
149
|
-
dep.is_external
|
|
205
|
+
dep.is_external,
|
|
206
|
+
dep.resolved_target_file
|
|
150
207
|
FROM dependencies dep
|
|
151
208
|
JOIN files f ON dep.source_file_id = f.id
|
|
152
209
|
JOIN domains d ON f.domain_id = d.id
|
|
210
|
+
${sourceFile === undefined ? "" : "WHERE f.path = ?"}
|
|
153
211
|
ORDER BY d.name, f.path, dep.line_number
|
|
154
212
|
`;
|
|
155
|
-
return this.db
|
|
213
|
+
return this.db
|
|
214
|
+
.query<IndexedDependency & { resolved_target_file?: string | null }, string[]>(query)
|
|
215
|
+
.all(...(sourceFile === undefined ? [] : [sourceFile]));
|
|
156
216
|
}
|
|
157
217
|
|
|
158
|
-
public
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
resolution, target_domains: [...new Set(targetDomains)], freshness: current,
|
|
182
|
-
index_coverage: resolution.targets.every(target => target.files.every(file => hashes.has(file) || !getLanguageCapability(file))) ? "complete" : "partial",
|
|
183
|
-
...(dep.source_file.endsWith(".go") ? { import_binding: (() => {
|
|
184
|
-
const alias = dep.statement.replace(/^\s*import\s+/, "").match(/^\s*([A-Za-z_]\w*|\.)\s+["`]/)?.[1];
|
|
185
|
-
return { kind: alias === "_" ? "blank" : alias === "." ? "dot" : alias ? "named" : "default", alias };
|
|
186
|
-
})() } : {}),
|
|
187
|
-
...(dep.source_file.endsWith(".py") ? { import_binding: (() => {
|
|
188
|
-
if (/^\s*from\s+.*\s+import\s+\*/.test(dep.statement)) return { kind: "star" };
|
|
189
|
-
const asMatch = dep.statement.match(/\bas\s+([A-Za-z_]\w*)\s*$/);
|
|
190
|
-
return { kind: asMatch ? "named" : "default", alias: asMatch?.[1] };
|
|
191
|
-
})() } : {}),
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
public getDomainFileConnections(domainId?: number, workspaceRoot?: string): Map<string, FileConnectionsSummary> {
|
|
197
|
-
const root = workspaceRoot ?? this.db.query<{ value: string }, [string]>("SELECT value FROM repo_meta WHERE key = ?").get("workspace_root")?.value;
|
|
198
|
-
if (root) {
|
|
199
|
-
const files = this.db.query<{ path: string; domain_id: number }, []>("SELECT path, domain_id FROM files").all();
|
|
200
|
-
const edges = this.getImportRelationships(root);
|
|
201
|
-
return new Map(files.filter(f => domainId === undefined || f.domain_id === domainId).map(file => {
|
|
202
|
-
const imports = edges.filter(edge => edge.source.file === file.path && edge.resolution.status === "resolved").flatMap(edge => edge.resolution.targets.flatMap(target => target.files));
|
|
203
|
-
const inbound = edges.filter(edge => edge.resolution.status === "resolved" && edge.resolution.targets.some(target => target.files.includes(file.path))).map(edge => edge.source.file);
|
|
204
|
-
return [file.path, { imports_from: [...new Set(imports)].sort(), imported_by: [...new Set(inbound)].sort(), imported_by_count: new Set(inbound).size }];
|
|
205
|
-
}));
|
|
218
|
+
public getDependenciesForFiles(filePaths: string[]): IndexedDependency[] {
|
|
219
|
+
if (filePaths.length === 0) return [];
|
|
220
|
+
const results: IndexedDependency[] = [];
|
|
221
|
+
for (let i = 0; i < filePaths.length; i += 400) {
|
|
222
|
+
const chunk = filePaths.slice(i, i + 400);
|
|
223
|
+
const placeholders = chunk.map(() => "?").join(",");
|
|
224
|
+
const rows = this.db
|
|
225
|
+
.query<IndexedDependency, string[]>(
|
|
226
|
+
`SELECT
|
|
227
|
+
f.path AS source_file,
|
|
228
|
+
d.name AS source_domain,
|
|
229
|
+
dep.line_number,
|
|
230
|
+
dep.target_symbol_or_path AS target,
|
|
231
|
+
dep.import_statement AS statement,
|
|
232
|
+
dep.is_external
|
|
233
|
+
FROM dependencies dep
|
|
234
|
+
JOIN files f ON dep.source_file_id = f.id
|
|
235
|
+
JOIN domains d ON f.domain_id = d.id
|
|
236
|
+
WHERE f.path IN (${placeholders})
|
|
237
|
+
ORDER BY d.name, f.path, dep.line_number`
|
|
238
|
+
)
|
|
239
|
+
.all(...chunk);
|
|
240
|
+
results.push(...rows);
|
|
206
241
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
"SELECT id, domain_id, path FROM files ORDER BY path ASC"
|
|
210
|
-
)
|
|
211
|
-
.all();
|
|
242
|
+
return results;
|
|
243
|
+
}
|
|
212
244
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
245
|
+
public getIndexedFilesByPaths(filePaths: string[]): Array<{ path: string; content_hash: string; domain_id: number }> {
|
|
246
|
+
if (filePaths.length === 0) return [];
|
|
247
|
+
const results: Array<{ path: string; content_hash: string; domain_id: number }> = [];
|
|
248
|
+
for (let i = 0; i < filePaths.length; i += 400) {
|
|
249
|
+
const chunk = filePaths.slice(i, i + 400);
|
|
250
|
+
const placeholders = chunk.map(() => "?").join(",");
|
|
251
|
+
const rows = this.db
|
|
252
|
+
.query<{ path: string; content_hash: string; domain_id: number }, string[]>(
|
|
253
|
+
`SELECT path, content_hash, domain_id FROM files WHERE path IN (${placeholders}) ORDER BY path ASC`
|
|
254
|
+
)
|
|
255
|
+
.all(...chunk);
|
|
256
|
+
results.push(...rows);
|
|
226
257
|
}
|
|
258
|
+
return results;
|
|
259
|
+
}
|
|
227
260
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
261
|
+
public getWorkspaceRootMeta(): string | undefined {
|
|
262
|
+
return this.db.query<{ value: string }, [string]>("SELECT value FROM repo_meta WHERE key = ?").get("workspace_root")?.value;
|
|
263
|
+
}
|
|
231
264
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
265
|
+
public getIndexedFilesForEvidence(sourceFile?: string): Array<{ path: string; content_hash: string; domain_id: number }> {
|
|
266
|
+
return this.db
|
|
267
|
+
.query<{ path: string; content_hash: string; domain_id: number }, string[]>(
|
|
268
|
+
`SELECT path, content_hash, domain_id FROM files ${sourceFile === undefined ? "" : "WHERE path = ?"} ORDER BY path ASC`
|
|
269
|
+
)
|
|
270
|
+
.all(...(sourceFile === undefined ? [] : [sourceFile]));
|
|
271
|
+
}
|
|
239
272
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (byAlias) return byAlias;
|
|
273
|
+
public getDomainsForEvidence(): Array<{ name: string; root_path: string }> {
|
|
274
|
+
return this.db.query<{ name: string; root_path: string }, []>("SELECT name, root_path FROM domains").all();
|
|
275
|
+
}
|
|
244
276
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return null;
|
|
251
|
-
};
|
|
277
|
+
public hasIndexedFile(path: string): boolean {
|
|
278
|
+
return Boolean(this.db.query("SELECT 1 FROM files WHERE path = ?").get(path));
|
|
279
|
+
}
|
|
252
280
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
281
|
+
public getAllFileSummaries(): Array<{ id: number; domain_id: number; path: string }> {
|
|
282
|
+
return this.db
|
|
283
|
+
.query<{ id: number; domain_id: number; path: string }, []>("SELECT id, domain_id, path FROM files ORDER BY path ASC")
|
|
284
|
+
.all();
|
|
285
|
+
}
|
|
259
286
|
|
|
260
|
-
|
|
287
|
+
public getAllInternalDependencyTargets(): Array<{ source_file_id: number; target_symbol_or_path: string }> {
|
|
288
|
+
return this.db
|
|
261
289
|
.query<{ source_file_id: number; target_symbol_or_path: string }, []>(
|
|
262
290
|
"SELECT source_file_id, target_symbol_or_path FROM dependencies WHERE is_external = 0"
|
|
263
291
|
)
|
|
264
292
|
.all();
|
|
265
|
-
|
|
266
|
-
for (const dep of allInternalDeps) {
|
|
267
|
-
const srcFile = fileById.get(dep.source_file_id);
|
|
268
|
-
if (!srcFile) continue;
|
|
269
|
-
const resolvedTarget = resolveInternalTarget(srcFile.path, dep.target_symbol_or_path);
|
|
270
|
-
if (resolvedTarget && resolvedTarget !== srcFile.path) {
|
|
271
|
-
importsFromMap.get(srcFile.path)?.add(resolvedTarget);
|
|
272
|
-
if (!importedByMap.has(resolvedTarget)) {
|
|
273
|
-
importedByMap.set(resolvedTarget, new Set());
|
|
274
|
-
}
|
|
275
|
-
importedByMap.get(resolvedTarget)?.add(srcFile.path);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const result = new Map<string, FileConnectionsSummary>();
|
|
280
|
-
for (const f of allFiles) {
|
|
281
|
-
if (domainId !== undefined && f.domain_id !== domainId) continue;
|
|
282
|
-
const importsFrom = Array.from(importsFromMap.get(f.path) ?? []).sort();
|
|
283
|
-
const importedBy = Array.from(importedByMap.get(f.path) ?? []).sort();
|
|
284
|
-
result.set(f.path, {
|
|
285
|
-
imports_from: importsFrom,
|
|
286
|
-
imported_by_count: importedBy.length,
|
|
287
|
-
imported_by: importedBy,
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return result;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
public getFileConnections(filePath: string, workspaceRoot?: string): FileConnectionsSummary {
|
|
295
|
-
const clean = filePath.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
296
|
-
const allConns = this.getDomainFileConnections(undefined,workspaceRoot);
|
|
297
|
-
return (
|
|
298
|
-
allConns.get(clean) ??
|
|
299
|
-
allConns.get(filePath) ?? {
|
|
300
|
-
imports_from: [],
|
|
301
|
-
imported_by_count: 0,
|
|
302
|
-
imported_by: [],
|
|
303
|
-
}
|
|
304
|
-
);
|
|
305
293
|
}
|
|
306
294
|
|
|
307
|
-
public
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
targetMethod = parts[1];
|
|
332
|
-
} else if (trimmed.includes("@")) {
|
|
333
|
-
const parts = trimmed.split("@");
|
|
334
|
-
targetContainer = parts[0];
|
|
335
|
-
targetMethod = parts[1];
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// 1. Look up target symbol in symbols joined with files and optionally domains
|
|
339
|
-
let targetSymRows: Array<{ name: string; file_path: string }>;
|
|
340
|
-
if (targetMethod) {
|
|
341
|
-
let methodSql = `
|
|
342
|
-
SELECT s.name, s.signature, f.path AS file_path
|
|
343
|
-
FROM symbols s
|
|
344
|
-
JOIN files f ON s.file_id = f.id
|
|
345
|
-
`;
|
|
346
|
-
const methodParams: any[] = [];
|
|
347
|
-
if (options.domain) {
|
|
348
|
-
methodSql += ` JOIN domains dom ON f.domain_id = dom.id WHERE LOWER(dom.name) = LOWER(?) AND `;
|
|
349
|
-
methodParams.push(options.domain);
|
|
350
|
-
} else {
|
|
351
|
-
methodSql += ` WHERE `;
|
|
352
|
-
}
|
|
353
|
-
methodSql += ` (s.name = ? OR s.name = ? OR (s.name = ? AND s.kind = 'method')) `;
|
|
354
|
-
methodParams.push(trimmed, `${targetContainer}::${targetMethod}`, targetMethod);
|
|
355
|
-
targetSymRows = this.db.query<{ name: string; signature: string; file_path: string }, any[]>(methodSql).all(...methodParams)
|
|
356
|
-
.filter(row => {
|
|
357
|
-
if (row.name !== targetMethod) return true;
|
|
358
|
-
// Go indexes bare method names; the receiver in its signature proves identity.
|
|
359
|
-
const receiver = row.signature.match(/^func\s*\(\s*(?:[A-Za-z_]\w*\s+)?\*?([A-Za-z_]\w*)(?:\[[^\]]+\])?\s*\)/);
|
|
360
|
-
return receiver?.[1] === targetContainer;
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
if (targetSymRows.length === 0) {
|
|
364
|
-
return {
|
|
365
|
-
target_symbol: trimmed,
|
|
366
|
-
found_in_index: false,
|
|
367
|
-
warning: `Symbol '${trimmed}' was not found in Septum index${options.domain ? ` for domain '${options.domain}'` : ""}. Method does not exist.`,
|
|
368
|
-
impact_summary: {
|
|
369
|
-
total_dependents: 0,
|
|
370
|
-
risk_level: "unknown",
|
|
371
|
-
affected_files_count: 0,
|
|
372
|
-
},
|
|
373
|
-
inbound_callers: [],
|
|
374
|
-
};
|
|
375
|
-
}
|
|
295
|
+
public findImpactMethodCandidates(
|
|
296
|
+
trimmed: string,
|
|
297
|
+
container: string,
|
|
298
|
+
method: string,
|
|
299
|
+
domain?: string
|
|
300
|
+
): Array<{
|
|
301
|
+
name: string;
|
|
302
|
+
kind: string;
|
|
303
|
+
signature: string;
|
|
304
|
+
line_start: number;
|
|
305
|
+
line_end: number;
|
|
306
|
+
file_path: string;
|
|
307
|
+
domain_name?: string | null;
|
|
308
|
+
}> {
|
|
309
|
+
let sql = `
|
|
310
|
+
SELECT s.name, s.kind, s.signature, s.line_start, s.line_end, f.path AS file_path, dom.name AS domain_name
|
|
311
|
+
FROM symbols s
|
|
312
|
+
JOIN files f ON s.file_id = f.id
|
|
313
|
+
LEFT JOIN domains dom ON f.domain_id = dom.id
|
|
314
|
+
`;
|
|
315
|
+
const params: any[] = [];
|
|
316
|
+
if (domain) {
|
|
317
|
+
sql += ` WHERE LOWER(dom.name) = LOWER(?) AND `;
|
|
318
|
+
params.push(domain);
|
|
376
319
|
} else {
|
|
377
|
-
|
|
378
|
-
SELECT s.name, f.path AS file_path
|
|
379
|
-
FROM symbols s
|
|
380
|
-
JOIN files f ON s.file_id = f.id
|
|
381
|
-
`;
|
|
382
|
-
const containerParams: any[] = [];
|
|
383
|
-
if (options.domain) {
|
|
384
|
-
containerSql += ` JOIN domains dom ON f.domain_id = dom.id WHERE LOWER(dom.name) = LOWER(?) AND `;
|
|
385
|
-
containerParams.push(options.domain);
|
|
386
|
-
} else {
|
|
387
|
-
containerSql += ` WHERE `;
|
|
388
|
-
}
|
|
389
|
-
containerSql += ` (s.name = ? OR s.name = ? OR s.name LIKE ? OR s.name LIKE ?) `;
|
|
390
|
-
containerParams.push(trimmed, targetContainer, `${targetContainer}::%`, `%::${targetContainer}`);
|
|
391
|
-
targetSymRows = this.db.query<{ name: string; file_path: string }, any[]>(containerSql).all(...containerParams);
|
|
392
|
-
|
|
393
|
-
if (targetSymRows.length === 0) {
|
|
394
|
-
return {
|
|
395
|
-
target_symbol: trimmed,
|
|
396
|
-
found_in_index: false,
|
|
397
|
-
warning: `Symbol '${trimmed}' was not found in Septum index${options.domain ? ` for domain '${options.domain}'` : ""}.`,
|
|
398
|
-
impact_summary: {
|
|
399
|
-
total_dependents: 0,
|
|
400
|
-
risk_level: "unknown",
|
|
401
|
-
affected_files_count: 0,
|
|
402
|
-
},
|
|
403
|
-
inbound_callers: [],
|
|
404
|
-
};
|
|
405
|
-
}
|
|
320
|
+
sql += ` WHERE `;
|
|
406
321
|
}
|
|
322
|
+
sql += ` (s.name = ? OR s.name = ? OR (s.name = ? AND s.kind = 'method')) `;
|
|
323
|
+
params.push(trimmed, `${container}::${method}`, method);
|
|
324
|
+
return this.db.query<any, any[]>(sql).all(...params);
|
|
325
|
+
}
|
|
407
326
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
327
|
+
public findImpactContainerCandidates(
|
|
328
|
+
trimmed: string,
|
|
329
|
+
container: string,
|
|
330
|
+
domain?: string
|
|
331
|
+
): Array<{
|
|
332
|
+
name: string;
|
|
333
|
+
kind: string;
|
|
334
|
+
line_start: number;
|
|
335
|
+
line_end: number;
|
|
336
|
+
file_path: string;
|
|
337
|
+
domain_name?: string | null;
|
|
338
|
+
}> {
|
|
339
|
+
let sql = `
|
|
340
|
+
SELECT s.name, s.kind, s.line_start, s.line_end, f.path AS file_path, dom.name AS domain_name
|
|
341
|
+
FROM symbols s
|
|
342
|
+
JOIN files f ON s.file_id = f.id
|
|
343
|
+
LEFT JOIN domains dom ON f.domain_id = dom.id
|
|
344
|
+
`;
|
|
345
|
+
const params: any[] = [];
|
|
346
|
+
if (domain) {
|
|
347
|
+
sql += ` WHERE LOWER(dom.name) = LOWER(?) AND `;
|
|
348
|
+
params.push(domain);
|
|
349
|
+
} else {
|
|
350
|
+
sql += ` WHERE `;
|
|
424
351
|
}
|
|
352
|
+
sql += ` (s.name = ? OR s.name = ? OR s.name LIKE ? OR s.name LIKE ?) `;
|
|
353
|
+
params.push(trimmed, container, `${container}::%`, `%::${container}`);
|
|
354
|
+
return this.db.query<any, any[]>(sql).all(...params);
|
|
355
|
+
}
|
|
425
356
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
// 2. Query dependencies matching targetContainer, trimmed, import_statement, or defining file stem
|
|
357
|
+
public queryDependenciesForImpact(patterns: {
|
|
358
|
+
container: string;
|
|
359
|
+
trimmed: string;
|
|
360
|
+
stems: string[];
|
|
361
|
+
}): Array<{
|
|
362
|
+
file: string;
|
|
363
|
+
line_number: number;
|
|
364
|
+
target_symbol_or_path: string;
|
|
365
|
+
import_statement: string;
|
|
366
|
+
domain_name?: string | null;
|
|
367
|
+
}> {
|
|
438
368
|
const whereClauses: string[] = [
|
|
439
369
|
"d.target_symbol_or_path LIKE ?",
|
|
440
370
|
"d.import_statement LIKE ?",
|
|
441
371
|
"d.target_symbol_or_path LIKE ?",
|
|
442
372
|
];
|
|
443
373
|
const queryParams: string[] = [
|
|
444
|
-
`%${
|
|
445
|
-
`%${
|
|
446
|
-
`%${trimmed}%`,
|
|
374
|
+
`%${patterns.container}%`,
|
|
375
|
+
`%${patterns.container}%`,
|
|
376
|
+
`%${patterns.trimmed}%`,
|
|
447
377
|
];
|
|
448
378
|
|
|
449
|
-
for (const stem of
|
|
379
|
+
for (const stem of patterns.stems) {
|
|
450
380
|
whereClauses.push("d.target_symbol_or_path LIKE ?");
|
|
451
381
|
queryParams.push(`%${stem}%`);
|
|
452
382
|
}
|
|
@@ -464,199 +394,72 @@ export class DependencyRepository {
|
|
|
464
394
|
WHERE ${whereClauses.join(" OR ")}
|
|
465
395
|
ORDER BY f.path ASC, d.line_number ASC
|
|
466
396
|
`;
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const isTargetedFile = Boolean(targetFilePath);
|
|
470
|
-
const matchesDefiningFile = (df: string, stmt: string, target: string): boolean => {
|
|
471
|
-
const normStmt = stmt.replace(/\\/g, "/");
|
|
472
|
-
const normTarget = target.replace(/\\/g, "/");
|
|
473
|
-
const clean = df.replace(/\.[^.]+$/, "");
|
|
474
|
-
const parts = clean.split("/");
|
|
475
|
-
const suffixes: string[] = [];
|
|
476
|
-
for (let i = 0; i < parts.length; i++) {
|
|
477
|
-
suffixes.push(parts.slice(i).join("/"));
|
|
478
|
-
}
|
|
479
|
-
return suffixes.some((s) => {
|
|
480
|
-
const escaped = escapeRegExp(s);
|
|
481
|
-
const r = new RegExp(`(?:^|[\\\\/\"\x27.@:])(?:${escaped})(?:$|[\\\\/\"\x27;:.()\\s]|\\.[^\\\\/]+)`, "i");
|
|
482
|
-
return r.test(normStmt) || r.test(normTarget);
|
|
483
|
-
});
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
const containerWordRegex = new RegExp(`\\b${escapeRegExp(targetContainer)}\\b`);
|
|
487
|
-
const depRows = rawDepRows.filter((row) => {
|
|
488
|
-
const normCallerFile = String(row.file).replace(/\\/g, "/");
|
|
489
|
-
if (definingFiles.has(normCallerFile)) return false;
|
|
490
|
-
|
|
491
|
-
const stmt = String(row.import_statement || "");
|
|
492
|
-
const target = String(row.target_symbol_or_path || "");
|
|
493
|
-
|
|
494
|
-
if (containerWordRegex.test(stmt) || containerWordRegex.test(target)) {
|
|
495
|
-
if (isTargetedFile) {
|
|
496
|
-
const matchesDefining = Array.from(definingFiles).some((df) => matchesDefiningFile(df, stmt, target));
|
|
497
|
-
if (!matchesDefining) {
|
|
498
|
-
return false;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
return true;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// If no named specifier braces are present, accept path match against defining file stem
|
|
505
|
-
if (!stmt.includes("{")) {
|
|
506
|
-
for (const stem of definingFileStems) {
|
|
507
|
-
const stemRegex = new RegExp(`(?:^|[\\\\/])${escapeRegExp(stem)}(?:\\.[^\\\\/]+)?$`);
|
|
508
|
-
if (stemRegex.test(target)) {
|
|
509
|
-
return true;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
return false;
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
// 3. Batch-load all symbols for candidate caller files in ONE query (zero N+1)
|
|
518
|
-
const uniqueCallerFiles = Array.from(new Set(depRows.map((r) => String(r.file))));
|
|
519
|
-
const callerSymbolsByFile = new Map<
|
|
520
|
-
string,
|
|
521
|
-
Array<{ name: string; kind: string; line_start: number; line_end: number }>
|
|
522
|
-
>();
|
|
523
|
-
|
|
524
|
-
if (uniqueCallerFiles.length > 0) {
|
|
525
|
-
const placeholders = uniqueCallerFiles.map(() => "?").join(",");
|
|
526
|
-
const allCallerSyms = this.db
|
|
527
|
-
.query<
|
|
528
|
-
{ name: string; kind: string; line_start: number; line_end: number; path: string },
|
|
529
|
-
string[]
|
|
530
|
-
>(
|
|
531
|
-
`SELECT s.name, s.kind, s.line_start, s.line_end, f.path
|
|
532
|
-
FROM symbols s
|
|
533
|
-
JOIN files f ON s.file_id = f.id
|
|
534
|
-
WHERE f.path IN (${placeholders})
|
|
535
|
-
ORDER BY (s.line_end - s.line_start) ASC`
|
|
536
|
-
)
|
|
537
|
-
.all(...uniqueCallerFiles);
|
|
538
|
-
|
|
539
|
-
for (const sym of allCallerSyms) {
|
|
540
|
-
const list = callerSymbolsByFile.get(sym.path) || [];
|
|
541
|
-
list.push(sym);
|
|
542
|
-
callerSymbolsByFile.set(sym.path, list);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
const findEnclosingSymbol = (
|
|
547
|
-
filePath: string,
|
|
548
|
-
lineNum: number
|
|
549
|
-
): { name: string; kind: string } | undefined => {
|
|
550
|
-
const syms = callerSymbolsByFile.get(filePath);
|
|
551
|
-
if (!syms) return undefined;
|
|
552
|
-
return syms.find((s) => lineNum >= s.line_start && lineNum <= s.line_end);
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
const callersMap = new Map<string, InboundCaller>();
|
|
556
|
-
|
|
557
|
-
for (const row of depRows) {
|
|
558
|
-
const enclosing = findEnclosingSymbol(row.file, row.line_number);
|
|
559
|
-
const callerName = enclosing ? enclosing.name : `${row.file}:${row.line_number}`;
|
|
560
|
-
const key = `${row.file}:${row.line_number}:${callerName}`;
|
|
561
|
-
|
|
562
|
-
if (!callersMap.has(key)) {
|
|
563
|
-
callersMap.set(key, {
|
|
564
|
-
file: row.file,
|
|
565
|
-
caller: callerName,
|
|
566
|
-
line: row.line_number,
|
|
567
|
-
kind: enclosing?.kind || "import",
|
|
568
|
-
domain: row.domain_name ?? undefined,
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
}
|
|
397
|
+
return this.db.query<any, string[]>(depSql).all(...queryParams);
|
|
398
|
+
}
|
|
572
399
|
|
|
573
|
-
|
|
574
|
-
if (
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if (
|
|
584
|
-
line.includes(`->${targetMethod}(`) ||
|
|
585
|
-
line.includes(`::${targetMethod}(`) ||
|
|
586
|
-
line.includes(`.${targetMethod}(`)
|
|
587
|
-
) {
|
|
588
|
-
const lineNum = i + 1;
|
|
589
|
-
const enclosing = findEnclosingSymbol(filePath, lineNum);
|
|
590
|
-
const callerName = enclosing ? enclosing.name : `${filePath}:${lineNum}`;
|
|
591
|
-
const key = `${filePath}:${lineNum}:${callerName}`;
|
|
592
|
-
if (!callersMap.has(key)) {
|
|
593
|
-
callersMap.set(key, {
|
|
594
|
-
file: filePath,
|
|
595
|
-
caller: callerName,
|
|
596
|
-
line: lineNum,
|
|
597
|
-
kind: enclosing?.kind || "call",
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
} catch {
|
|
604
|
-
// Ignore read errors
|
|
605
|
-
}
|
|
400
|
+
public findSameDirectoryPackageFiles(dirs: string[]): Array<{ path: string; domain_name: string | null }> {
|
|
401
|
+
if (dirs.length === 0) return [];
|
|
402
|
+
const dirClauses: string[] = [];
|
|
403
|
+
const dirParams: string[] = [];
|
|
404
|
+
for (const dir of dirs) {
|
|
405
|
+
if (dir === "") {
|
|
406
|
+
dirClauses.push("f.path NOT LIKE '%/%'");
|
|
407
|
+
} else {
|
|
408
|
+
dirClauses.push("(f.path LIKE ? AND SUBSTR(f.path, LENGTH(?) + 2) NOT LIKE '%/%')");
|
|
409
|
+
dirParams.push(`${dir}/%`, dir);
|
|
606
410
|
}
|
|
607
411
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
if (affectedFiles.size > 5 || distinctDomains.size > 2) {
|
|
617
|
-
riskLevel = "high";
|
|
618
|
-
} else if (affectedFiles.size >= 2 || distinctDomains.size >= 2) {
|
|
619
|
-
riskLevel = "medium";
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
// 5. Determine if symbol exists in index
|
|
623
|
-
const foundInIndex = targetSymRows.length > 0 || depRows.length > 0;
|
|
624
|
-
const warning = foundInIndex
|
|
625
|
-
? undefined
|
|
626
|
-
: `Symbol '${trimmed}' was not found in Septum index (neither in declared symbols nor tracked dependencies). Risk cannot be assessed without index evidence.`;
|
|
627
|
-
|
|
628
|
-
return {
|
|
629
|
-
target_symbol: trimmed,
|
|
630
|
-
found_in_index: foundInIndex,
|
|
631
|
-
warning,
|
|
632
|
-
impact_summary: {
|
|
633
|
-
total_dependents: inboundCallers.length,
|
|
634
|
-
risk_level: foundInIndex ? riskLevel : "unknown",
|
|
635
|
-
affected_files_count: affectedFiles.size,
|
|
636
|
-
},
|
|
637
|
-
inbound_callers: inboundCallers,
|
|
638
|
-
};
|
|
412
|
+
return this.db
|
|
413
|
+
.query<{ path: string; domain_name: string | null }, string[]>(
|
|
414
|
+
`SELECT f.path, dom.name AS domain_name
|
|
415
|
+
FROM files f
|
|
416
|
+
LEFT JOIN domains dom ON f.domain_id = dom.id
|
|
417
|
+
WHERE ${dirClauses.join(" OR ")}`
|
|
418
|
+
)
|
|
419
|
+
.all(...dirParams);
|
|
639
420
|
}
|
|
640
421
|
|
|
641
|
-
public
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
422
|
+
public findSymbolsForFiles(filePaths: string[]): Array<{
|
|
423
|
+
name: string;
|
|
424
|
+
kind: string;
|
|
425
|
+
signature: string;
|
|
426
|
+
line_start: number;
|
|
427
|
+
line_end: number;
|
|
428
|
+
path: string;
|
|
429
|
+
}> {
|
|
430
|
+
if (filePaths.length === 0) return [];
|
|
431
|
+
const placeholders = filePaths.map(() => "?").join(",");
|
|
432
|
+
return this.db
|
|
433
|
+
.query<
|
|
434
|
+
{ name: string; kind: string; signature: string; line_start: number; line_end: number; path: string },
|
|
435
|
+
string[]
|
|
436
|
+
>(
|
|
437
|
+
`SELECT s.name, s.kind, s.signature, s.line_start, s.line_end, f.path
|
|
438
|
+
FROM symbols s
|
|
439
|
+
JOIN files f ON s.file_id = f.id
|
|
440
|
+
WHERE f.path IN (${placeholders})
|
|
441
|
+
ORDER BY (s.line_end - s.line_start) ASC`
|
|
442
|
+
)
|
|
443
|
+
.all(...filePaths);
|
|
444
|
+
}
|
|
649
445
|
|
|
650
|
-
|
|
446
|
+
public findFileSymbolNames(cleanPath: string): string[] {
|
|
447
|
+
return this.db
|
|
651
448
|
.query<{ name: string }, [string, string]>(
|
|
652
449
|
`SELECT s.name
|
|
653
450
|
FROM symbols s
|
|
654
451
|
JOIN files f ON s.file_id = f.id
|
|
655
452
|
WHERE f.path = ? OR f.path LIKE ?`
|
|
656
453
|
)
|
|
657
|
-
.all(cleanPath, `%${cleanPath}`)
|
|
454
|
+
.all(cleanPath, `%${cleanPath}`)
|
|
455
|
+
.map((s) => s.name);
|
|
456
|
+
}
|
|
658
457
|
|
|
659
|
-
|
|
458
|
+
public queryDependenciesForFileInbound(
|
|
459
|
+
cleanPath: string,
|
|
460
|
+
baseName: string,
|
|
461
|
+
symbolNames: string[]
|
|
462
|
+
): Array<{ file: string; target: string; stmt: string }> {
|
|
660
463
|
const orConditions: string[] = [];
|
|
661
464
|
const params: string[] = [];
|
|
662
465
|
|
|
@@ -667,8 +470,8 @@ export class DependencyRepository {
|
|
|
667
470
|
params.push(`%${baseName}%`);
|
|
668
471
|
}
|
|
669
472
|
|
|
670
|
-
for (const sym of
|
|
671
|
-
const symName = sym.
|
|
473
|
+
for (const sym of symbolNames.slice(0, 8)) {
|
|
474
|
+
const symName = sym.split("::").pop() || sym;
|
|
672
475
|
if (symName.length >= 4) {
|
|
673
476
|
orConditions.push("d.target_symbol_or_path LIKE ?");
|
|
674
477
|
params.push(`%${symName}%`);
|
|
@@ -677,36 +480,16 @@ export class DependencyRepository {
|
|
|
677
480
|
}
|
|
678
481
|
}
|
|
679
482
|
|
|
680
|
-
if (orConditions.length
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
for (const row of depRows) {
|
|
693
|
-
matchedFiles.add(row.file);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
const consumerList = Array.from(matchedFiles);
|
|
698
|
-
let riskLevel: "low" | "medium" | "high" = "low";
|
|
699
|
-
if (consumerList.length >= 5) {
|
|
700
|
-
riskLevel = "high";
|
|
701
|
-
} else if (consumerList.length >= 2) {
|
|
702
|
-
riskLevel = "medium";
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
return {
|
|
706
|
-
direct_dependents_count: consumerList.length,
|
|
707
|
-
top_consumers: consumerList.slice(0, 5),
|
|
708
|
-
symbols_count: symbols.length,
|
|
709
|
-
risk_level: riskLevel,
|
|
710
|
-
};
|
|
483
|
+
if (orConditions.length === 0) return [];
|
|
484
|
+
params.push(`%${cleanPath}`);
|
|
485
|
+
return this.db
|
|
486
|
+
.query<{ file: string; target: string; stmt: string }, string[]>(
|
|
487
|
+
`SELECT DISTINCT f.path AS file, d.target_symbol_or_path AS target, d.import_statement AS stmt
|
|
488
|
+
FROM dependencies d
|
|
489
|
+
JOIN files f ON d.source_file_id = f.id
|
|
490
|
+
WHERE (${orConditions.join(" OR ")})
|
|
491
|
+
AND f.path NOT LIKE ?`
|
|
492
|
+
)
|
|
493
|
+
.all(...params);
|
|
711
494
|
}
|
|
712
495
|
}
|