@dimassetoid/septum-mcp 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +142 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +133 -0
- package/src/cli/commands/hook.ts +205 -0
- package/src/cli/commands/init.ts +570 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +39 -0
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +124 -0
- package/src/cli/scaffold/harness-config.ts +661 -0
- package/src/cli/templates/hooks.ts +110 -0
- package/src/cli/templates/rules.ts +35 -0
- package/src/cli/templates/skill.ts +55 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +426 -0
- package/src/core/boundary/staged-auditor.ts +120 -0
- package/src/core/config/domain-ownership.ts +45 -0
- package/src/core/config/loader.ts +174 -0
- package/src/core/config/schema.ts +59 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +733 -0
- package/src/core/database/repositories/domain.repository.ts +373 -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 +647 -0
- package/src/core/database/repository.ts +358 -0
- package/src/core/database/schema.ts +123 -0
- package/src/core/discovery/navigation.ts +105 -0
- package/src/core/discovery/topology-detector.ts +863 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +590 -0
- package/src/core/parser/behavioral-analyzer.ts +123 -0
- package/src/core/parser/boundary-tracker.ts +458 -0
- package/src/core/parser/extractors/base.ts +71 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +248 -0
- package/src/core/parser/extractors/django-semantic.ts +655 -0
- package/src/core/parser/extractors/elysia-semantic.ts +517 -0
- package/src/core/parser/extractors/express-semantic.ts +429 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +702 -0
- package/src/core/parser/extractors/fastify-semantic.ts +759 -0
- package/src/core/parser/extractors/flask-semantic.ts +482 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +670 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +546 -0
- package/src/core/parser/extractors/java.ts +227 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1150 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +367 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +527 -0
- package/src/core/parser/extractors/php.ts +585 -0
- package/src/core/parser/extractors/python.ts +503 -0
- package/src/core/parser/extractors/registry.ts +99 -0
- package/src/core/parser/extractors/ruby.ts +237 -0
- package/src/core/parser/extractors/rust.ts +304 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +24 -0
- package/src/core/parser/extractors/symfony-semantic.ts +321 -0
- package/src/core/parser/extractors/typescript.ts +839 -0
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +87 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +239 -0
- package/src/core/parser/schema/schema-provider-registry.ts +41 -0
- package/src/core/parser/schema/schema-provider.interface.ts +34 -0
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -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 +1033 -0
- package/src/core/resolver/import-resolver.ts +365 -0
- package/src/core/resolver/interpretation-inputs.ts +7 -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 +115 -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 +71 -0
- package/src/core/resolver/module-resolver.ts +486 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- package/src/core/resolver/slice-catalog.ts +79 -0
- package/src/core/resolver/slice-format.ts +9 -0
- package/src/core/resolver/symbol-impact.ts +381 -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 +344 -0
- package/src/core/resources/ignore.ts +144 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +185 -0
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +74 -0
- package/src/core/retrieval/context-page.ts +109 -0
- package/src/core/retrieval/context.ts +320 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +262 -0
- package/src/core/telemetry/telemetry.ts +142 -0
- package/src/index.ts +18 -0
- package/src/mcp/schemas.ts +746 -0
- package/src/mcp/server.ts +600 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +382 -0
- package/src/mcp/tools/get-domain-catalog.ts +39 -0
- package/src/mcp/tools/get-symbol-impact.ts +104 -0
- package/src/mcp/tools/get-symbol.ts +399 -0
- package/src/mcp/tools/locate-symbol.ts +236 -0
- package/src/mcp/tools/map.ts +26 -0
- package/src/mcp/tools/register-domain.ts +113 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +95 -0
- package/src/mcp/tools/trace-vertical-slice.ts +106 -0
- package/src/mcp/workspace-manager.ts +170 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +438 -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,358 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import type {
|
|
4
|
+
ArchetypeKind,
|
|
5
|
+
DomainCatalogResponse,
|
|
6
|
+
DomainConfig,
|
|
7
|
+
DomainRecord,
|
|
8
|
+
NavigationFile,
|
|
9
|
+
NavigationEntrypoint,
|
|
10
|
+
ExtractedDependency,
|
|
11
|
+
ExtractedSymbol,
|
|
12
|
+
FileRecord,
|
|
13
|
+
GetSymbolDetailsResponse,
|
|
14
|
+
GetSymbolImpactResponse,
|
|
15
|
+
InboundCaller,
|
|
16
|
+
SymbolKind,
|
|
17
|
+
SymbolRecord,
|
|
18
|
+
SymbolReference,
|
|
19
|
+
SymbolCandidate,
|
|
20
|
+
SymbolSelectionOptions,
|
|
21
|
+
VerticalSliceRecord,
|
|
22
|
+
} from "../../types/index.ts";
|
|
23
|
+
|
|
24
|
+
export type {
|
|
25
|
+
ArchetypeKind,
|
|
26
|
+
DomainCatalogResponse,
|
|
27
|
+
DomainConfig,
|
|
28
|
+
DomainRecord,
|
|
29
|
+
ExtractedDependency,
|
|
30
|
+
ExtractedSymbol,
|
|
31
|
+
FileRecord,
|
|
32
|
+
GetSymbolDetailsResponse,
|
|
33
|
+
GetSymbolImpactResponse,
|
|
34
|
+
InboundCaller,
|
|
35
|
+
SymbolKind,
|
|
36
|
+
SymbolRecord,
|
|
37
|
+
VerticalSliceRecord,
|
|
38
|
+
} from "../../types/index.ts";
|
|
39
|
+
import { DependencyRepository } from "./repositories/dependency.repository.ts";
|
|
40
|
+
import { DomainRepository } from "./repositories/domain.repository.ts";
|
|
41
|
+
import { FileRepository } from "./repositories/file.repository.ts";
|
|
42
|
+
import { MetaRepository } from "./repositories/meta.repository.ts";
|
|
43
|
+
import { SymbolRepository } from "./repositories/symbol.repository.ts";
|
|
44
|
+
|
|
45
|
+
export type DatabaseRepository = SeptumRepository;
|
|
46
|
+
|
|
47
|
+
export class SeptumRepository {
|
|
48
|
+
private indexIdentityCache?: { stamp: string; digest: string };
|
|
49
|
+
public readonly domains: DomainRepository;
|
|
50
|
+
public readonly files: FileRepository;
|
|
51
|
+
public readonly symbols: SymbolRepository;
|
|
52
|
+
public readonly dependencies: DependencyRepository;
|
|
53
|
+
public readonly meta: MetaRepository;
|
|
54
|
+
|
|
55
|
+
constructor(private db: Database) {
|
|
56
|
+
this.domains = new DomainRepository(db);
|
|
57
|
+
this.files = new FileRepository(db);
|
|
58
|
+
this.symbols = new SymbolRepository(db);
|
|
59
|
+
this.dependencies = new DependencyRepository(db);
|
|
60
|
+
this.meta = new MetaRepository(db);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public runInTransaction<T>(fn: () => T, immediate = false): T {
|
|
64
|
+
const transaction = this.db.transaction(fn);
|
|
65
|
+
return immediate ? transaction.immediate() : transaction();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public checkpoint(): void {
|
|
69
|
+
try {
|
|
70
|
+
this.db.run("PRAGMA wal_checkpoint(PASSIVE);");
|
|
71
|
+
} catch {
|
|
72
|
+
// Ignore if locked or busy
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public getNavigationFiles(): NavigationFile[] {
|
|
77
|
+
return this.db.query<NavigationFile, []>(`
|
|
78
|
+
SELECT f.path, d.name AS domain, f.archetype, COUNT(s.id) AS symbol_count,
|
|
79
|
+
(SELECT name FROM symbols WHERE file_id = f.id AND kind IN ('function','class','struct','interface') ORDER BY line_start, name LIMIT 1) AS anchor
|
|
80
|
+
FROM files f JOIN domains d ON d.id = f.domain_id
|
|
81
|
+
LEFT JOIN symbols s ON s.file_id = f.id
|
|
82
|
+
GROUP BY f.id ORDER BY f.path
|
|
83
|
+
`).all();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public getNavigationEntrypoints(): NavigationEntrypoint[] {
|
|
87
|
+
return this.db.query<NavigationEntrypoint, []>(`
|
|
88
|
+
SELECT DISTINCT http_method AS method, route_uri AS target,
|
|
89
|
+
controller_file AS file, action_name AS handler
|
|
90
|
+
FROM vertical_slices ORDER BY controller_file, http_method, route_uri, action_name
|
|
91
|
+
`).all();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Stable content identity without materializing/sorting the index in JS.
|
|
95
|
+
* SQLite counters invalidate the cache for local writes and other connections;
|
|
96
|
+
* the digest excludes insertion IDs and operational timestamps.
|
|
97
|
+
*/
|
|
98
|
+
public getIndexIdentity(): string {
|
|
99
|
+
// total_changes does not rewind on rollback. Never publish a digest of
|
|
100
|
+
// uncommitted facts into the connection cache.
|
|
101
|
+
const cacheable = !this.db.inTransaction;
|
|
102
|
+
return this.runInTransaction(() => {
|
|
103
|
+
const stamp = JSON.stringify([
|
|
104
|
+
this.db.query("PRAGMA data_version").get(),
|
|
105
|
+
this.db.query("SELECT total_changes() AS changes").get(),
|
|
106
|
+
this.db.query("PRAGMA schema_version").get(),
|
|
107
|
+
]);
|
|
108
|
+
if (cacheable && this.indexIdentityCache?.stamp === stamp) return this.indexIdentityCache.digest;
|
|
109
|
+
const hash = createHash("sha256");
|
|
110
|
+
for (const sql of [
|
|
111
|
+
`SELECT json_array(name, root_path, allowed_deps_json, forbidden_deps_json, archetypes_json) AS fact
|
|
112
|
+
FROM domains ORDER BY fact`,
|
|
113
|
+
`SELECT json_array(f.path, f.content_hash, d.name) AS fact
|
|
114
|
+
FROM files f JOIN domains d ON d.id = f.domain_id ORDER BY fact`,
|
|
115
|
+
`SELECT json_array(f.path, s.name, s.kind, s.signature, s.visibility, s.line_start, s.line_end, s.line_count, s.nesting_depth) AS fact
|
|
116
|
+
FROM symbols s JOIN files f ON f.id = s.file_id ORDER BY fact`,
|
|
117
|
+
`SELECT json_array(f.path, d.name, dep.target_symbol_or_path, dep.import_statement, dep.line_number, dep.is_external) AS fact
|
|
118
|
+
FROM dependencies dep JOIN files f ON f.id = dep.source_file_id JOIN domains d ON d.id = f.domain_id ORDER BY fact`,
|
|
119
|
+
`SELECT json_array(key, value) AS fact FROM repo_meta WHERE key IN ('sync_state', 'parser_revision') ORDER BY key`,
|
|
120
|
+
]) {
|
|
121
|
+
hash.update("\0");
|
|
122
|
+
for (const { fact } of this.db.query<{ fact: string }, []>(sql).iterate()) hash.update(fact + "\n");
|
|
123
|
+
}
|
|
124
|
+
const digest = hash.digest("hex");
|
|
125
|
+
if (cacheable) this.indexIdentityCache = { stamp, digest };
|
|
126
|
+
return digest;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// --- Domain Methods ---
|
|
131
|
+
public upsertDomain(name: string, config: DomainConfig, workspaceRoot?: string): number {
|
|
132
|
+
return this.domains.upsertDomain(name, config, workspaceRoot);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public getDomainByName(name: string): DomainRecord | null {
|
|
136
|
+
return this.domains.getDomainByName(name);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public getAllDomains(): DomainRecord[] {
|
|
140
|
+
return this.domains.getAllDomains();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public pruneDomainsNotIn(activeNames: string[]): { prunedDomains: number; removedFiles: number } {
|
|
144
|
+
return this.domains.pruneDomainsNotIn(activeNames);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// --- File Methods ---
|
|
148
|
+
public getFileByPath(path: string): FileRecord | null {
|
|
149
|
+
return this.files.getFileByPath(path);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public countFiles(): number {
|
|
153
|
+
return this.files.countFiles();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public getFilesByDomain(domainId: number): FileRecord[] {
|
|
157
|
+
return this.files.getFilesByDomain(domainId);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public getAllFiles(): FileRecord[] {
|
|
161
|
+
return this.files.getAllFiles();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public upsertFile(
|
|
165
|
+
domainId: number,
|
|
166
|
+
path: string,
|
|
167
|
+
archetype: ArchetypeKind,
|
|
168
|
+
contentHash: string,
|
|
169
|
+
lineCount: number,
|
|
170
|
+
mtimeMs: number = 0,
|
|
171
|
+
sizeBytes: number = 0
|
|
172
|
+
): number {
|
|
173
|
+
return this.files.upsertFile(
|
|
174
|
+
domainId,
|
|
175
|
+
path,
|
|
176
|
+
archetype,
|
|
177
|
+
contentHash,
|
|
178
|
+
lineCount,
|
|
179
|
+
mtimeMs,
|
|
180
|
+
sizeBytes
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public updateFileMetadataOnly(id: number, mtimeMs: number, sizeBytes: number): void {
|
|
185
|
+
this.files.updateFileMetadataOnly(id, mtimeMs, sizeBytes);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public deleteFilesNotInPaths(domainId: number, validPaths: string[]): number {
|
|
189
|
+
return this.files.deleteFilesNotInPaths(domainId, validPaths);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public deleteFile(path: string): void {
|
|
193
|
+
this.files.deleteFile(path);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public deleteFileByPath(path: string): void {
|
|
197
|
+
this.files.deleteFileByPath(path);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
public getDomainCatalog(
|
|
201
|
+
domainName: string,
|
|
202
|
+
archetypeFilter?: string,
|
|
203
|
+
options?: { detailLevel?: "compact" | "full"; fileFilter?: string; workspaceRoot?: string }
|
|
204
|
+
): DomainCatalogResponse | null {
|
|
205
|
+
return this.domains.getDomainCatalog(domainName, archetypeFilter, options);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// --- Symbol Methods ---
|
|
209
|
+
public getDependenciesByFileId(fileId: number): ExtractedDependency[] {
|
|
210
|
+
return this.db.query<ExtractedDependency, [number]>(`
|
|
211
|
+
SELECT target_symbol_or_path AS target, import_statement AS statement,
|
|
212
|
+
line_number, is_external FROM dependencies WHERE source_file_id = ? ORDER BY id
|
|
213
|
+
`).all(fileId);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
public replaceFileSymbols(fileId: number, symbols: ExtractedSymbol[]): void {
|
|
217
|
+
this.symbols.replaceFileSymbols(fileId, symbols);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public getSymbolsByFileId(fileId: number): SymbolRecord[] {
|
|
221
|
+
return this.symbols.getSymbolsByFileId(fileId);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public findSymbolsByName(
|
|
225
|
+
name: string,
|
|
226
|
+
options: SymbolSelectionOptions = {}
|
|
227
|
+
): SymbolCandidate[] {
|
|
228
|
+
return this.symbols.findSymbolsByName(name, options);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public findContainers(
|
|
232
|
+
containerName: string
|
|
233
|
+
): Array<{ file: FileRecord; symbol?: SymbolRecord }> {
|
|
234
|
+
return this.symbols.findContainers(containerName);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public getAllSymbolsWithFiles(): Array<SymbolRecord & { file_path: string }> {
|
|
238
|
+
return this.symbols.getAllSymbolsWithFiles();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// --- Dependency & Slice Methods ---
|
|
242
|
+
public replaceFileDependencies(fileId: number, deps: ExtractedDependency[]): void {
|
|
243
|
+
this.dependencies.replaceFileDependencies(fileId, deps);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public upsertVerticalSlice(
|
|
247
|
+
slice: Omit<VerticalSliceRecord, "id" | "created_at">
|
|
248
|
+
): void {
|
|
249
|
+
this.dependencies.upsertVerticalSlice(slice);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public findVerticalSlices(searchTerm: string): VerticalSliceRecord[] {
|
|
253
|
+
return this.dependencies.findVerticalSlices(searchTerm);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public getAllVerticalSlices(): VerticalSliceRecord[] {
|
|
257
|
+
return this.dependencies.getAllVerticalSlices();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public countVerticalSlices(): number {
|
|
261
|
+
return this.dependencies.countVerticalSlices();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public clearVerticalSlices(domainId?: number): void {
|
|
265
|
+
this.dependencies.clearVerticalSlices(domainId);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public getImportRelationships(workspaceRoot?: string, sourceFile?: string) {
|
|
269
|
+
return this.dependencies.getImportRelationships(workspaceRoot, sourceFile);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
public getDomainFileConnections(domainId?: number, workspaceRoot?: string) {
|
|
273
|
+
return this.dependencies.getDomainFileConnections(domainId,workspaceRoot);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public getFileConnections(filePath: string, workspaceRoot?: string) {
|
|
277
|
+
return this.dependencies.getFileConnections(filePath,workspaceRoot);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public getAllDependenciesWithDomains(): Array<{
|
|
281
|
+
source_file: string;
|
|
282
|
+
source_domain: string;
|
|
283
|
+
line_number: number;
|
|
284
|
+
target: string;
|
|
285
|
+
statement: string;
|
|
286
|
+
is_external: boolean;
|
|
287
|
+
}> {
|
|
288
|
+
return this.dependencies.getAllDependenciesWithDomains();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
public findSymbolWithDomain(
|
|
292
|
+
symbolName: string
|
|
293
|
+
): {
|
|
294
|
+
symbol_name: string;
|
|
295
|
+
kind: string;
|
|
296
|
+
file_path: string;
|
|
297
|
+
domain_name: string;
|
|
298
|
+
} | null {
|
|
299
|
+
return this.symbols.findSymbolWithDomain(symbolName);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
public findSymbolWithMembers(symbolName: string): {
|
|
303
|
+
symbol_name: string;
|
|
304
|
+
kind: string;
|
|
305
|
+
signature: string;
|
|
306
|
+
file_path: string;
|
|
307
|
+
domain_name: string;
|
|
308
|
+
methods: string[];
|
|
309
|
+
properties: string[];
|
|
310
|
+
} | null {
|
|
311
|
+
return this.symbols.findSymbolWithMembers(symbolName);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
public getFileWithDomain(filePath: string): {
|
|
315
|
+
file_id: number;
|
|
316
|
+
file_path: string;
|
|
317
|
+
domain_name: string;
|
|
318
|
+
} | null {
|
|
319
|
+
return this.symbols.getFileWithDomain(filePath);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
public getSymbolDetails(
|
|
323
|
+
symbolQuery: string,
|
|
324
|
+
options: SymbolSelectionOptions & { includeDependencies?: boolean; workspaceRoot?: string } = {}
|
|
325
|
+
): GetSymbolDetailsResponse | null {
|
|
326
|
+
return this.symbols.getSymbolDetails(symbolQuery, options);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
public getSymbolImpact(
|
|
330
|
+
symbolName: string,
|
|
331
|
+
options: { domain?: string; workspaceRoot?: string; filePath?: string; reference?: SymbolReference } = {}
|
|
332
|
+
): GetSymbolImpactResponse {
|
|
333
|
+
return this.dependencies.getSymbolImpact(symbolName, options);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
public getFileInboundImpact(filePath: string): {
|
|
337
|
+
direct_dependents_count: number;
|
|
338
|
+
top_consumers: string[];
|
|
339
|
+
symbols_count: number;
|
|
340
|
+
risk_level: "low" | "medium" | "high";
|
|
341
|
+
} {
|
|
342
|
+
return this.dependencies.getFileInboundImpact(filePath);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// --- Metadata Methods ---
|
|
346
|
+
public getMeta(key: string): string | null {
|
|
347
|
+
return this.meta.getMeta(key);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
public setMeta(key: string, value: string): void {
|
|
351
|
+
this.meta.setMeta(key, value);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
public getAllMeta(): Record<string, string> {
|
|
355
|
+
return this.meta.getAllMeta();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
|
|
3
|
+
export const CURRENT_SCHEMA_VERSION = 5;
|
|
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
|
+
|
|
79
|
+
export const INDEX_STATEMENTS = [
|
|
80
|
+
"CREATE INDEX IF NOT EXISTS idx_domains_name ON domains(name);",
|
|
81
|
+
"CREATE INDEX IF NOT EXISTS idx_files_domain_id ON files(domain_id, id);",
|
|
82
|
+
"CREATE INDEX IF NOT EXISTS idx_files_path ON files(path);",
|
|
83
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_file_id ON symbols(file_id);",
|
|
84
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_file_lines ON symbols(file_id, line_start, line_end);",
|
|
85
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);",
|
|
86
|
+
"CREATE INDEX IF NOT EXISTS idx_symbols_kind ON symbols(kind);",
|
|
87
|
+
"CREATE INDEX IF NOT EXISTS idx_dependencies_source ON dependencies(source_file_id);",
|
|
88
|
+
"CREATE INDEX IF NOT EXISTS idx_dependencies_target ON dependencies(target_symbol_or_path);",
|
|
89
|
+
"CREATE INDEX IF NOT EXISTS idx_slices_route_uri ON vertical_slices(route_uri);",
|
|
90
|
+
"CREATE INDEX IF NOT EXISTS idx_slices_route_name ON vertical_slices(route_name);",
|
|
91
|
+
"CREATE INDEX IF NOT EXISTS idx_slices_controller ON vertical_slices(controller_class, action_name);",
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
const DROP_ALL_TABLES = `
|
|
95
|
+
DROP TABLE IF EXISTS environment_nodes;
|
|
96
|
+
DROP TABLE IF EXISTS environment_topology;
|
|
97
|
+
DROP TABLE IF EXISTS repo_meta;
|
|
98
|
+
DROP TABLE IF EXISTS vertical_slices;
|
|
99
|
+
DROP TABLE IF EXISTS dependencies;
|
|
100
|
+
DROP TABLE IF EXISTS symbols;
|
|
101
|
+
DROP TABLE IF EXISTS files;
|
|
102
|
+
DROP TABLE IF EXISTS domains;
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
export function initializeDatabaseSchema(db: Database): void {
|
|
106
|
+
const versionRow = db.query<{ user_version: number }, []>("PRAGMA user_version;").get();
|
|
107
|
+
const userVersion = versionRow?.user_version ?? 0;
|
|
108
|
+
|
|
109
|
+
if (userVersion !== 0 && userVersion !== CURRENT_SCHEMA_VERSION) {
|
|
110
|
+
// Outdated schema versions are cleanly dropped and recreated
|
|
111
|
+
db.run(DROP_ALL_TABLES);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const tableSql of TABLE_STATEMENTS) {
|
|
115
|
+
db.run(tableSql);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (const indexSql of INDEX_STATEMENTS) {
|
|
119
|
+
db.run(indexSql);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
db.run(`PRAGMA user_version = ${CURRENT_SCHEMA_VERSION};`);
|
|
123
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { SeptumRepository } from "../database/repository.ts";
|
|
2
|
+
import type { NavigationQuery } from "../../types/index.ts";
|
|
3
|
+
|
|
4
|
+
export const NAVIGATION_SCHEMA = "navigation/v1";
|
|
5
|
+
|
|
6
|
+
/** Navigation selects indexed structure; declaration inspection belongs to symbol. */
|
|
7
|
+
export function buildNavigation(repo: SeptumRepository, args: NavigationQuery, root: string) {
|
|
8
|
+
const domains = repo.getAllDomains();
|
|
9
|
+
const requested = args.domain ?? args.name;
|
|
10
|
+
const domain = domains.find(domain => domain.name.toLowerCase() === requested?.toLowerCase());
|
|
11
|
+
if (requested && !domain) return {
|
|
12
|
+
schema: NAVIGATION_SCHEMA, status: "not_found", domain: requested,
|
|
13
|
+
found: false, message: `Domain '${requested}' not found in Septum catalog.`,
|
|
14
|
+
suggestions: domains.map(domain => domain.name),
|
|
15
|
+
suggested_action: { tool: "septum_map", params: { action: "catalog" } },
|
|
16
|
+
available_domains: domains.map(domain => domain.name),
|
|
17
|
+
next: [{ tool: "septum_map", args: { action: "catalog" } }],
|
|
18
|
+
};
|
|
19
|
+
const files = repo.getNavigationFiles();
|
|
20
|
+
const byPath = new Map(files.map(file => [file.path, file]));
|
|
21
|
+
const domainCounts = new Map<string, number>();
|
|
22
|
+
for (const file of files) domainCounts.set(file.domain, (domainCounts.get(file.domain) ?? 0) + 1);
|
|
23
|
+
const filter = args.file_filter?.replace(/\\/g, "/").toLowerCase();
|
|
24
|
+
const matching = files.filter(file => (!domain || file.domain === domain.name) &&
|
|
25
|
+
(!filter || file.path.toLowerCase().includes(filter)) &&
|
|
26
|
+
(!(args.archetype_filter ?? args.archetype) || file.archetype === (args.archetype_filter ?? args.archetype)));
|
|
27
|
+
const paths = new Set(matching.map(file => file.path));
|
|
28
|
+
const relationships = repo.getImportRelationships(root);
|
|
29
|
+
const degree = new Map<string, number>();
|
|
30
|
+
const edges = new Map<string, { from: string; to: string; relation: "imports"; count: number }>();
|
|
31
|
+
const unresolved: Array<{ file: string; target: string; reason: string }> = [];
|
|
32
|
+
const workspace = !domain && !filter && !args.archetype_filter && !args.archetype;
|
|
33
|
+
for (const edge of relationships) {
|
|
34
|
+
const source = edge.source.file;
|
|
35
|
+
const targets = [...new Set(edge.resolution.targets.flatMap(target => target.files))];
|
|
36
|
+
const relevant = paths.has(source) || targets.some(target => paths.has(target));
|
|
37
|
+
if (!relevant) continue;
|
|
38
|
+
if (edge.freshness !== "current" || !["resolved", "external"].includes(edge.resolution.status) || edge.resolution.coverage === "conditional" || edge.index_coverage === "partial") {
|
|
39
|
+
unresolved.push({ file: source, target: edge.resolution.source.target,
|
|
40
|
+
reason: edge.freshness !== "current" ? `source_${edge.freshness}` : edge.index_coverage === "partial" ? "target_not_fully_indexed" : edge.resolution.reason });
|
|
41
|
+
}
|
|
42
|
+
if (edge.freshness !== "current" || edge.resolution.status !== "resolved") continue;
|
|
43
|
+
for (const target of targets) {
|
|
44
|
+
degree.set(source, (degree.get(source) ?? 0) + 1);
|
|
45
|
+
degree.set(target, (degree.get(target) ?? 0) + 1);
|
|
46
|
+
const from = workspace ? byPath.get(source)?.domain : source;
|
|
47
|
+
const to = workspace ? byPath.get(target)?.domain : target;
|
|
48
|
+
if (!from || !to || workspace && from === to) continue;
|
|
49
|
+
const key = JSON.stringify([from, to]);
|
|
50
|
+
const prior = edges.get(key);
|
|
51
|
+
if (prior) prior.count++;
|
|
52
|
+
else edges.set(key, { from, to, relation: "imports", count: 1 });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const entries = repo.getNavigationEntrypoints().filter(entry => entry.file && paths.has(entry.file));
|
|
56
|
+
const entryFiles = new Set(entries.map(entry => entry.file));
|
|
57
|
+
matching.sort((a, b) => Number(entryFiles.has(b.path)) - Number(entryFiles.has(a.path)) ||
|
|
58
|
+
(degree.get(b.path) ?? 0) - (degree.get(a.path) ?? 0) || a.path.localeCompare(b.path));
|
|
59
|
+
const offset = args.file_offset ?? 0;
|
|
60
|
+
const limit = args.file_limit ?? (args.detail_level === "full" ? 100 : 40);
|
|
61
|
+
const selected = workspace ? [] : matching.slice(offset, offset + limit);
|
|
62
|
+
const selectedPaths = new Set(selected.map(file => file.path));
|
|
63
|
+
const allEdges = [...edges.values()].sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to));
|
|
64
|
+
const relevantEdges = workspace ? allEdges : allEdges.filter(edge => selectedPaths.has(edge.from) || selectedPaths.has(edge.to));
|
|
65
|
+
const compactDomainOnly = Boolean(domain && !filter && !(args.archetype_filter ?? args.archetype) && args.detail_level !== "full");
|
|
66
|
+
const filteredEdges = compactDomainOnly
|
|
67
|
+
? relevantEdges.filter(edge => byPath.get(edge.from)?.domain !== byPath.get(edge.to)?.domain)
|
|
68
|
+
: relevantEdges;
|
|
69
|
+
const dependencies = filteredEdges.slice(0, 100);
|
|
70
|
+
const entrypoints = entries.filter(entry => workspace || selectedPaths.has(entry.file!)).slice(0, 20);
|
|
71
|
+
const sync = repo.getMeta("sync_state") ?? "unindexed";
|
|
72
|
+
const dirty = repo.getMeta("slices_dirty") === "1";
|
|
73
|
+
const end = offset + selected.length;
|
|
74
|
+
const diagnostics = {
|
|
75
|
+
unresolved_imports: unresolved.length,
|
|
76
|
+
unsupported_files: (JSON.parse(repo.getMeta("unsupported_files") || "[]") as string[]).filter(path => !domain || path.startsWith(domain.root_path.replace(/\/$/, "") + "/")).length,
|
|
77
|
+
skipped_files: (JSON.parse(repo.getMeta("skipped_files") || "[]") as Array<{ path: string }>).filter(file => !domain || file.path.startsWith(domain.root_path.replace(/\/$/, "") + "/")).length,
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
schema: NAVIGATION_SCHEMA,
|
|
81
|
+
status: requested || filter ? matching.length ? "success" : "not_found" : domains.length ? "success" : "NOT_INDEXED",
|
|
82
|
+
scope: { level: workspace ? "workspace" : filter ? "file" : "domain", ...(domain ? { domain: domain.name } : {}), ...(filter ? { file_filter: args.file_filter } : {}) },
|
|
83
|
+
domains: (workspace ? domains : domain ? [domain] : []).map(domain => ({ name: domain.name, root: domain.root_path,
|
|
84
|
+
file_count: domainCounts.get(domain.name) ?? 0,
|
|
85
|
+
allowed_dependencies: JSON.parse(domain.allowed_deps_json || "[]") as string[],
|
|
86
|
+
forbidden_dependencies: JSON.parse(domain.forbidden_deps_json || "[]") as string[],
|
|
87
|
+
})),
|
|
88
|
+
files: selected,
|
|
89
|
+
dependencies,
|
|
90
|
+
entrypoints: entrypoints.map(entry => ({ ...entry, evidence: "static_catalog", runtime_verified: false })),
|
|
91
|
+
health: { index: sync, sync_needed: dirty, coverage: "partial", ...diagnostics,
|
|
92
|
+
reasons: [...new Set(unresolved.map(item => item.reason))].sort().slice(0, 10) },
|
|
93
|
+
index_status: { sync_state: sync, sync_needed: dirty },
|
|
94
|
+
accounting: { matching_files: matching.length, returned_files: selected.length,
|
|
95
|
+
omitted_files: workspace ? 0 : Math.max(0, matching.length - selected.length),
|
|
96
|
+
total_dependencies: allEdges.length, returned_dependencies: dependencies.length, omitted_dependencies: allEdges.length - dependencies.length,
|
|
97
|
+
total_entrypoints: entries.length, omitted_entrypoints: entries.length - entrypoints.length },
|
|
98
|
+
...(!workspace && end < matching.length ? { pagination: { next_file_offset: end, file_offset: offset } } : {}),
|
|
99
|
+
...(args.include_evidence ? { diagnostics: unresolved.slice(0, 5), diagnostics_omitted: Math.max(0, unresolved.length - 5) } : {}),
|
|
100
|
+
next: entrypoints[0] ? [{ tool: "septum_slice", args: { query: `${entrypoints[0].method} ${entrypoints[0].target}`, controller_file: entrypoints[0].file } }]
|
|
101
|
+
: selected[0]?.anchor ? [{ tool: "septum_symbol", args: { action: "locate", query: selected[0].anchor, file_path: selected[0].path } }]
|
|
102
|
+
: [{ tool: "septum_map", args: { action: "catalog", ...(domains[0] ? { domain: domains[0].name } : {}) } }],
|
|
103
|
+
relationship_limits: "Dependencies are imports, not calls or execution order. Entrypoints come from the static catalog and may be inferred. Unindexed targets remain uncertain.",
|
|
104
|
+
};
|
|
105
|
+
}
|