@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,303 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import type {
|
|
3
|
+
ArchetypeKind,
|
|
4
|
+
DomainCatalogResponse,
|
|
5
|
+
DomainConfig,
|
|
6
|
+
DomainRecord,
|
|
7
|
+
ExtractedDependency,
|
|
8
|
+
ExtractedSymbol,
|
|
9
|
+
FileRecord,
|
|
10
|
+
GetSymbolDetailsResponse,
|
|
11
|
+
GetSymbolImpactResponse,
|
|
12
|
+
InboundCaller,
|
|
13
|
+
SymbolKind,
|
|
14
|
+
SymbolRecord,
|
|
15
|
+
SymbolReference,
|
|
16
|
+
SymbolCandidate,
|
|
17
|
+
SymbolSelectionOptions,
|
|
18
|
+
VerticalSliceRecord,
|
|
19
|
+
} from "../../types/index.ts";
|
|
20
|
+
|
|
21
|
+
export type {
|
|
22
|
+
ArchetypeKind,
|
|
23
|
+
DomainCatalogResponse,
|
|
24
|
+
DomainConfig,
|
|
25
|
+
DomainRecord,
|
|
26
|
+
ExtractedDependency,
|
|
27
|
+
ExtractedSymbol,
|
|
28
|
+
FileRecord,
|
|
29
|
+
GetSymbolDetailsResponse,
|
|
30
|
+
GetSymbolImpactResponse,
|
|
31
|
+
InboundCaller,
|
|
32
|
+
SymbolKind,
|
|
33
|
+
SymbolRecord,
|
|
34
|
+
VerticalSliceRecord,
|
|
35
|
+
} from "../../types/index.ts";
|
|
36
|
+
import { DependencyRepository } from "./repositories/dependency.repository.ts";
|
|
37
|
+
import { DomainRepository } from "./repositories/domain.repository.ts";
|
|
38
|
+
import { EnvironmentRepository } from "./repositories/environment.repository.ts";
|
|
39
|
+
import { FileRepository } from "./repositories/file.repository.ts";
|
|
40
|
+
import { MetaRepository } from "./repositories/meta.repository.ts";
|
|
41
|
+
import { SymbolRepository } from "./repositories/symbol.repository.ts";
|
|
42
|
+
|
|
43
|
+
export type DatabaseRepository = SeptumRepository;
|
|
44
|
+
|
|
45
|
+
export class SeptumRepository {
|
|
46
|
+
public readonly domains: DomainRepository;
|
|
47
|
+
public readonly files: FileRepository;
|
|
48
|
+
public readonly symbols: SymbolRepository;
|
|
49
|
+
public readonly dependencies: DependencyRepository;
|
|
50
|
+
public readonly meta: MetaRepository;
|
|
51
|
+
public readonly environment: EnvironmentRepository;
|
|
52
|
+
|
|
53
|
+
constructor(private db: Database) {
|
|
54
|
+
this.domains = new DomainRepository(db);
|
|
55
|
+
this.files = new FileRepository(db);
|
|
56
|
+
this.symbols = new SymbolRepository(db);
|
|
57
|
+
this.dependencies = new DependencyRepository(db);
|
|
58
|
+
this.meta = new MetaRepository(db);
|
|
59
|
+
this.environment = new EnvironmentRepository(db);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public runInTransaction<T>(fn: () => T, immediate = false): T {
|
|
63
|
+
const transaction = this.db.transaction(fn);
|
|
64
|
+
return immediate ? transaction.immediate() : transaction();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public checkpoint(): void {
|
|
68
|
+
try {
|
|
69
|
+
this.db.run("PRAGMA wal_checkpoint(PASSIVE);");
|
|
70
|
+
} catch {
|
|
71
|
+
// Ignore if locked or busy
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// --- Domain Methods ---
|
|
76
|
+
public upsertDomain(name: string, config: DomainConfig): number {
|
|
77
|
+
return this.domains.upsertDomain(name, config);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public getDomainByName(name: string): DomainRecord | null {
|
|
81
|
+
return this.domains.getDomainByName(name);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public getAllDomains(): DomainRecord[] {
|
|
85
|
+
return this.domains.getAllDomains();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// --- File Methods ---
|
|
89
|
+
public getFileByPath(path: string): FileRecord | null {
|
|
90
|
+
return this.files.getFileByPath(path);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public countFiles(): number {
|
|
94
|
+
return this.files.countFiles();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public getFilesByDomain(domainId: number): FileRecord[] {
|
|
98
|
+
return this.files.getFilesByDomain(domainId);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public getAllFiles(): FileRecord[] {
|
|
102
|
+
return this.files.getAllFiles();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public upsertFile(
|
|
106
|
+
domainId: number,
|
|
107
|
+
path: string,
|
|
108
|
+
archetype: ArchetypeKind,
|
|
109
|
+
contentHash: string,
|
|
110
|
+
lineCount: number,
|
|
111
|
+
mtimeMs: number = 0,
|
|
112
|
+
sizeBytes: number = 0
|
|
113
|
+
): number {
|
|
114
|
+
return this.files.upsertFile(
|
|
115
|
+
domainId,
|
|
116
|
+
path,
|
|
117
|
+
archetype,
|
|
118
|
+
contentHash,
|
|
119
|
+
lineCount,
|
|
120
|
+
mtimeMs,
|
|
121
|
+
sizeBytes
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public updateFileMetadataOnly(id: number, mtimeMs: number, sizeBytes: number): void {
|
|
126
|
+
this.files.updateFileMetadataOnly(id, mtimeMs, sizeBytes);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public deleteFilesNotInPaths(domainId: number, validPaths: string[]): number {
|
|
130
|
+
return this.files.deleteFilesNotInPaths(domainId, validPaths);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public deleteFile(path: string): void {
|
|
134
|
+
this.files.deleteFile(path);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public deleteFileByPath(path: string): void {
|
|
138
|
+
this.files.deleteFileByPath(path);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public getDomainCatalog(
|
|
142
|
+
domainName: string,
|
|
143
|
+
archetypeFilter?: string,
|
|
144
|
+
options?: { detailLevel?: "compact" | "full"; fileFilter?: string; workspaceRoot?: string }
|
|
145
|
+
): DomainCatalogResponse | null {
|
|
146
|
+
return this.domains.getDomainCatalog(domainName, archetypeFilter, options);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// --- Symbol Methods ---
|
|
150
|
+
public replaceFileSymbols(fileId: number, symbols: ExtractedSymbol[]): void {
|
|
151
|
+
this.symbols.replaceFileSymbols(fileId, symbols);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public getSymbolsByFileId(fileId: number): SymbolRecord[] {
|
|
155
|
+
return this.symbols.getSymbolsByFileId(fileId);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public findSymbolsByName(
|
|
159
|
+
name: string,
|
|
160
|
+
options: SymbolSelectionOptions = {}
|
|
161
|
+
): SymbolCandidate[] {
|
|
162
|
+
return this.symbols.findSymbolsByName(name, options);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public findContainers(
|
|
166
|
+
containerName: string
|
|
167
|
+
): Array<{ file: FileRecord; symbol?: SymbolRecord }> {
|
|
168
|
+
return this.symbols.findContainers(containerName);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public getAllSymbolsWithFiles(): Array<SymbolRecord & { file_path: string }> {
|
|
172
|
+
return this.symbols.getAllSymbolsWithFiles();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// --- Dependency & Slice Methods ---
|
|
176
|
+
public replaceFileDependencies(fileId: number, deps: ExtractedDependency[]): void {
|
|
177
|
+
this.dependencies.replaceFileDependencies(fileId, deps);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public upsertVerticalSlice(
|
|
181
|
+
slice: Omit<VerticalSliceRecord, "id" | "created_at">
|
|
182
|
+
): void {
|
|
183
|
+
this.dependencies.upsertVerticalSlice(slice);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public findVerticalSlices(searchTerm: string): VerticalSliceRecord[] {
|
|
187
|
+
return this.dependencies.findVerticalSlices(searchTerm);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public getAllVerticalSlices(): VerticalSliceRecord[] {
|
|
191
|
+
return this.dependencies.getAllVerticalSlices();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public countVerticalSlices(): number {
|
|
195
|
+
return this.dependencies.countVerticalSlices();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public clearVerticalSlices(domainId?: number): void {
|
|
199
|
+
this.dependencies.clearVerticalSlices(domainId);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public getImportRelationships(workspaceRoot?: string) {
|
|
203
|
+
return this.dependencies.getImportRelationships(workspaceRoot);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public getDomainFileConnections(domainId?: number, workspaceRoot?: string) {
|
|
207
|
+
return this.dependencies.getDomainFileConnections(domainId,workspaceRoot);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public getFileConnections(filePath: string, workspaceRoot?: string) {
|
|
211
|
+
return this.dependencies.getFileConnections(filePath,workspaceRoot);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public getAllDependenciesWithDomains(): Array<{
|
|
215
|
+
source_file: string;
|
|
216
|
+
source_domain: string;
|
|
217
|
+
line_number: number;
|
|
218
|
+
target: string;
|
|
219
|
+
statement: string;
|
|
220
|
+
is_external: boolean;
|
|
221
|
+
}> {
|
|
222
|
+
return this.dependencies.getAllDependenciesWithDomains();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public findSymbolWithDomain(
|
|
226
|
+
symbolName: string
|
|
227
|
+
): {
|
|
228
|
+
symbol_name: string;
|
|
229
|
+
kind: string;
|
|
230
|
+
file_path: string;
|
|
231
|
+
domain_name: string;
|
|
232
|
+
} | null {
|
|
233
|
+
return this.symbols.findSymbolWithDomain(symbolName);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public findSymbolWithMembers(symbolName: string): {
|
|
237
|
+
symbol_name: string;
|
|
238
|
+
kind: string;
|
|
239
|
+
signature: string;
|
|
240
|
+
file_path: string;
|
|
241
|
+
domain_name: string;
|
|
242
|
+
methods: string[];
|
|
243
|
+
properties: string[];
|
|
244
|
+
} | null {
|
|
245
|
+
return this.symbols.findSymbolWithMembers(symbolName);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public getFileWithDomain(filePath: string): {
|
|
249
|
+
file_id: number;
|
|
250
|
+
file_path: string;
|
|
251
|
+
domain_name: string;
|
|
252
|
+
} | null {
|
|
253
|
+
return this.symbols.getFileWithDomain(filePath);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public getHotspotSymbols(options: {
|
|
257
|
+
minLines?: number;
|
|
258
|
+
minNesting?: number;
|
|
259
|
+
kind?: SymbolKind;
|
|
260
|
+
domain?: string;
|
|
261
|
+
limit?: number;
|
|
262
|
+
sortBy?: "lines" | "nesting" | "risk_score";
|
|
263
|
+
} = {}): Array<SymbolRecord & { file_path: string; domain_name: string; risk_score: number }> {
|
|
264
|
+
return this.symbols.getHotspotSymbols(options);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
public getSymbolDetails(
|
|
268
|
+
symbolQuery: string,
|
|
269
|
+
options: SymbolSelectionOptions & { includeDependencies?: boolean; workspaceRoot?: string } = {}
|
|
270
|
+
): GetSymbolDetailsResponse | null {
|
|
271
|
+
return this.symbols.getSymbolDetails(symbolQuery, options);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
public getSymbolImpact(
|
|
275
|
+
symbolName: string,
|
|
276
|
+
options: { domain?: string; workspaceRoot?: string; filePath?: string; reference?: SymbolReference } = {}
|
|
277
|
+
): GetSymbolImpactResponse {
|
|
278
|
+
return this.dependencies.getSymbolImpact(symbolName, options);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
public getFileInboundImpact(filePath: string): {
|
|
282
|
+
direct_dependents_count: number;
|
|
283
|
+
top_consumers: string[];
|
|
284
|
+
symbols_count: number;
|
|
285
|
+
risk_level: "low" | "medium" | "high";
|
|
286
|
+
} {
|
|
287
|
+
return this.dependencies.getFileInboundImpact(filePath);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// --- Metadata Methods ---
|
|
291
|
+
public getMeta(key: string): string | null {
|
|
292
|
+
return this.meta.getMeta(key);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public setMeta(key: string, value: string): void {
|
|
296
|
+
this.meta.setMeta(key, value);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
public getAllMeta(): Record<string, string> {
|
|
300
|
+
return this.meta.getAllMeta();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
|
|
3
|
+
export const CURRENT_SCHEMA_VERSION = 4;
|
|
4
|
+
|
|
5
|
+
export const TABLE_STATEMENTS = [
|
|
6
|
+
`CREATE TABLE IF NOT EXISTS domains (
|
|
7
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
8
|
+
name TEXT NOT NULL UNIQUE COLLATE NOCASE,
|
|
9
|
+
root_path TEXT NOT NULL,
|
|
10
|
+
allowed_deps_json TEXT NOT NULL DEFAULT '[]',
|
|
11
|
+
forbidden_deps_json TEXT NOT NULL DEFAULT '[]',
|
|
12
|
+
archetypes_json TEXT NOT NULL DEFAULT '{}',
|
|
13
|
+
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
14
|
+
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
15
|
+
);`,
|
|
16
|
+
|
|
17
|
+
`CREATE TABLE IF NOT EXISTS files (
|
|
18
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
19
|
+
domain_id INTEGER NOT NULL,
|
|
20
|
+
path TEXT NOT NULL UNIQUE,
|
|
21
|
+
archetype TEXT NOT NULL DEFAULT 'unknown',
|
|
22
|
+
content_hash TEXT NOT NULL,
|
|
23
|
+
line_count INTEGER NOT NULL DEFAULT 0,
|
|
24
|
+
mtime_ms INTEGER NOT NULL DEFAULT 0,
|
|
25
|
+
size_bytes INTEGER NOT NULL DEFAULT 0,
|
|
26
|
+
last_scanned_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
27
|
+
FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE CASCADE
|
|
28
|
+
);`,
|
|
29
|
+
|
|
30
|
+
`CREATE TABLE IF NOT EXISTS symbols (
|
|
31
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
32
|
+
file_id INTEGER NOT NULL,
|
|
33
|
+
name TEXT NOT NULL,
|
|
34
|
+
kind TEXT NOT NULL,
|
|
35
|
+
signature TEXT NOT NULL,
|
|
36
|
+
visibility TEXT NOT NULL DEFAULT 'public',
|
|
37
|
+
line_start INTEGER NOT NULL DEFAULT 0,
|
|
38
|
+
line_end INTEGER NOT NULL DEFAULT 0,
|
|
39
|
+
line_count INTEGER NOT NULL DEFAULT 1,
|
|
40
|
+
nesting_depth INTEGER NOT NULL DEFAULT 1,
|
|
41
|
+
FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
42
|
+
);`,
|
|
43
|
+
|
|
44
|
+
`CREATE TABLE IF NOT EXISTS dependencies (
|
|
45
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
46
|
+
source_file_id INTEGER NOT NULL,
|
|
47
|
+
target_symbol_or_path TEXT NOT NULL,
|
|
48
|
+
import_statement TEXT NOT NULL,
|
|
49
|
+
line_number INTEGER NOT NULL DEFAULT 0,
|
|
50
|
+
is_external BOOLEAN NOT NULL DEFAULT 0,
|
|
51
|
+
FOREIGN KEY (source_file_id) REFERENCES files(id) ON DELETE CASCADE
|
|
52
|
+
);`,
|
|
53
|
+
|
|
54
|
+
`CREATE TABLE IF NOT EXISTS vertical_slices (
|
|
55
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
56
|
+
domain_id INTEGER,
|
|
57
|
+
feature_key TEXT,
|
|
58
|
+
http_method TEXT NOT NULL,
|
|
59
|
+
route_uri TEXT NOT NULL,
|
|
60
|
+
route_name TEXT,
|
|
61
|
+
controller_class TEXT NOT NULL,
|
|
62
|
+
action_name TEXT NOT NULL,
|
|
63
|
+
controller_file TEXT,
|
|
64
|
+
controller_line INTEGER DEFAULT 0,
|
|
65
|
+
architecture_style TEXT NOT NULL DEFAULT 'clean',
|
|
66
|
+
entry_kind TEXT NOT NULL DEFAULT 'http_route',
|
|
67
|
+
execution_chain_json TEXT NOT NULL,
|
|
68
|
+
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
69
|
+
FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE CASCADE
|
|
70
|
+
);`,
|
|
71
|
+
|
|
72
|
+
`CREATE TABLE IF NOT EXISTS repo_meta (
|
|
73
|
+
key TEXT PRIMARY KEY,
|
|
74
|
+
value TEXT NOT NULL,
|
|
75
|
+
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
76
|
+
);`,
|
|
77
|
+
|
|
78
|
+
`CREATE TABLE IF NOT EXISTS environment_topology (
|
|
79
|
+
layer TEXT PRIMARY KEY,
|
|
80
|
+
platform TEXT,
|
|
81
|
+
status TEXT NOT NULL,
|
|
82
|
+
detected_from_json TEXT NOT NULL DEFAULT '[]',
|
|
83
|
+
constraints_json TEXT NOT NULL DEFAULT '[]',
|
|
84
|
+
unresolved_inquiry TEXT,
|
|
85
|
+
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
86
|
+
);`,
|
|
87
|
+
|
|
88
|
+
`CREATE TABLE IF NOT EXISTS environment_nodes (
|
|
89
|
+
id TEXT PRIMARY KEY,
|
|
90
|
+
layer TEXT NOT NULL,
|
|
91
|
+
name TEXT NOT NULL,
|
|
92
|
+
platform TEXT NOT NULL,
|
|
93
|
+
canonical_tag TEXT NOT NULL DEFAULT 'unspecified',
|
|
94
|
+
domain_or_ip TEXT,
|
|
95
|
+
role TEXT,
|
|
96
|
+
status TEXT NOT NULL,
|
|
97
|
+
detected_from_json TEXT NOT NULL DEFAULT '[]',
|
|
98
|
+
constraints_json TEXT NOT NULL DEFAULT '[]',
|
|
99
|
+
connected_to_json TEXT NOT NULL DEFAULT '[]',
|
|
100
|
+
unresolved_inquiry TEXT,
|
|
101
|
+
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
102
|
+
);`,
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
export const INDEX_STATEMENTS = [
|
|
106
|
+
"CREATE INDEX IF NOT EXISTS idx_domains_name ON domains(name);",
|
|
107
|
+
"CREATE INDEX IF NOT EXISTS idx_files_domain_id ON files(domain_id, id);",
|
|
108
|
+
"CREATE INDEX IF NOT EXISTS idx_files_path ON files(path);",
|
|
109
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_file_id ON symbols(file_id);",
|
|
110
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_file_lines ON symbols(file_id, line_start, line_end);",
|
|
111
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);",
|
|
112
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_kind ON symbols(kind);",
|
|
113
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_line_count ON symbols(kind, line_count DESC);",
|
|
114
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_nesting_depth ON symbols(nesting_depth DESC);",
|
|
115
|
+
"CREATE INDEX IF NOT EXISTS idx_dependencies_source ON dependencies(source_file_id);",
|
|
116
|
+
"CREATE INDEX IF NOT EXISTS idx_dependencies_target ON dependencies(target_symbol_or_path);",
|
|
117
|
+
"CREATE INDEX IF NOT EXISTS idx_slices_route_uri ON vertical_slices(route_uri);",
|
|
118
|
+
"CREATE INDEX IF NOT EXISTS idx_slices_route_name ON vertical_slices(route_name);",
|
|
119
|
+
"CREATE INDEX IF NOT EXISTS idx_slices_controller ON vertical_slices(controller_class, action_name);",
|
|
120
|
+
"CREATE INDEX IF NOT EXISTS idx_env_topology_status ON environment_topology(status);",
|
|
121
|
+
"CREATE INDEX IF NOT EXISTS idx_env_nodes_layer ON environment_nodes(layer, id);",
|
|
122
|
+
"CREATE INDEX IF NOT EXISTS idx_env_nodes_status ON environment_nodes(status);",
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
const DROP_ALL_TABLES = `
|
|
126
|
+
DROP TABLE IF EXISTS environment_nodes;
|
|
127
|
+
DROP TABLE IF EXISTS environment_topology;
|
|
128
|
+
DROP TABLE IF EXISTS repo_meta;
|
|
129
|
+
DROP TABLE IF EXISTS vertical_slices;
|
|
130
|
+
DROP TABLE IF EXISTS dependencies;
|
|
131
|
+
DROP TABLE IF EXISTS symbols;
|
|
132
|
+
DROP TABLE IF EXISTS files;
|
|
133
|
+
DROP TABLE IF EXISTS domains;
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
export function initializeDatabaseSchema(db: Database): void {
|
|
137
|
+
const versionRow = db.query<{ user_version: number }, []>("PRAGMA user_version;").get();
|
|
138
|
+
const userVersion = versionRow?.user_version ?? 0;
|
|
139
|
+
|
|
140
|
+
if (userVersion !== 0 && userVersion !== CURRENT_SCHEMA_VERSION) {
|
|
141
|
+
// Zero-kludge cache invalidation: outdated schema versions are cleanly dropped and recreated
|
|
142
|
+
db.run(DROP_ALL_TABLES);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
for (const tableSql of TABLE_STATEMENTS) {
|
|
146
|
+
db.run(tableSql);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
for (const indexSql of INDEX_STATEMENTS) {
|
|
150
|
+
db.run(indexSql);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
db.run(`PRAGMA user_version = ${CURRENT_SCHEMA_VERSION};`);
|
|
154
|
+
}
|