@dimassetoid/septum-mcp 0.3.0 → 0.5.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.
Files changed (129) hide show
  1. package/README.md +38 -55
  2. package/package.json +7 -5
  3. package/src/cli/commands/check.ts +14 -10
  4. package/src/cli/commands/hook.ts +41 -6
  5. package/src/cli/commands/init.ts +10 -1
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +32 -4
  9. package/src/cli/index.ts +7 -0
  10. package/src/cli/templates/hooks.ts +3 -14
  11. package/src/cli/templates/skill.ts +17 -10
  12. package/src/core/boundary/audit.ts +383 -0
  13. package/src/core/boundary/evaluator.ts +251 -114
  14. package/src/core/boundary/staged-auditor.ts +147 -55
  15. package/src/core/config/domain-ownership.ts +6 -4
  16. package/src/core/config/domain-registration.ts +141 -0
  17. package/src/core/config/loader.ts +1 -25
  18. package/src/core/config/schema.ts +24 -36
  19. package/src/core/database/client.ts +2 -0
  20. package/src/core/database/repositories/dependency.repository.ts +334 -572
  21. package/src/core/database/repositories/domain.repository.ts +2 -1
  22. package/src/core/database/repositories/file.repository.ts +10 -0
  23. package/src/core/database/repositories/symbol.repository.ts +97 -398
  24. package/src/core/database/repository.ts +68 -9
  25. package/src/core/database/schema.ts +26 -0
  26. package/src/core/discovery/declarative-routes.ts +69 -0
  27. package/src/core/discovery/framework-detector.ts +149 -0
  28. package/src/core/discovery/navigation.ts +222 -58
  29. package/src/core/discovery/topology-detector.ts +93 -168
  30. package/src/core/errors.ts +19 -0
  31. package/src/core/ingestion/pipeline.ts +287 -88
  32. package/src/core/parser/extractors/base.ts +11 -3
  33. package/src/core/parser/extractors/csharp.ts +2 -2
  34. package/src/core/parser/extractors/django-routing.ts +163 -0
  35. package/src/core/parser/extractors/django-semantic.ts +397 -481
  36. package/src/core/parser/extractors/elysia-semantic.ts +172 -475
  37. package/src/core/parser/extractors/express-semantic.ts +195 -383
  38. package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
  39. package/src/core/parser/extractors/fastify-semantic.ts +216 -717
  40. package/src/core/parser/extractors/flask-semantic.ts +89 -352
  41. package/src/core/parser/extractors/go-routing.ts +344 -0
  42. package/src/core/parser/extractors/go-semantic.ts +205 -562
  43. package/src/core/parser/extractors/go.ts +6 -3
  44. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  45. package/src/core/parser/extractors/hono-semantic.ts +132 -509
  46. package/src/core/parser/extractors/java.ts +2 -2
  47. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  48. package/src/core/parser/extractors/laravel-semantic.ts +143 -335
  49. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  50. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  51. package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
  52. package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
  53. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  54. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  55. package/src/core/parser/extractors/php.ts +1 -1
  56. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  57. package/src/core/parser/extractors/python.ts +5 -9
  58. package/src/core/parser/extractors/registry.ts +2 -0
  59. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  60. package/src/core/parser/extractors/ruby.ts +2 -2
  61. package/src/core/parser/extractors/rust.ts +4 -4
  62. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  63. package/src/core/parser/extractors/symfony-semantic.ts +72 -226
  64. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  65. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  66. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  67. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  68. package/src/core/parser/extractors/typescript.ts +23 -216
  69. package/src/core/parser/language-capabilities.ts +1 -1
  70. package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
  71. package/src/core/parser/wasm-loader.ts +6 -2
  72. package/src/core/resolver/ast-method-tracer.ts +230 -0
  73. package/src/core/resolver/call-graph-helpers.ts +72 -0
  74. package/src/core/resolver/call-graph-tracer.ts +169 -414
  75. package/src/core/resolver/dependency-analysis.ts +593 -0
  76. package/src/core/resolver/import-candidates.ts +120 -0
  77. package/src/core/resolver/import-evidence.ts +88 -0
  78. package/src/core/resolver/import-resolver.ts +60 -7
  79. package/src/core/resolver/interpretation-inputs.ts +60 -2
  80. package/src/core/resolver/languages/python.ts +31 -13
  81. package/src/core/resolver/languages/shared.ts +4 -1
  82. package/src/core/resolver/module-resolver.ts +10 -3
  83. package/src/core/resolver/path-resolver.ts +6 -3
  84. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  85. package/src/core/resolver/slice-catalog.ts +21 -6
  86. package/src/core/resolver/slice-format.ts +13 -0
  87. package/src/core/resolver/slice-selection.ts +237 -0
  88. package/src/core/resolver/symbol-impact.ts +104 -8
  89. package/src/core/resolver/symbol-locator.ts +82 -15
  90. package/src/core/resolver/vertical-slice-tracer.ts +31 -230
  91. package/src/core/resources/ignore.ts +0 -1
  92. package/src/core/resources/limits.ts +2 -1
  93. package/src/core/resources/work-queue.ts +167 -4
  94. package/src/core/retrieval/context-page.ts +11 -4
  95. package/src/core/retrieval/context.ts +363 -226
  96. package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
  97. package/src/core/retrieval/symbol-details.ts +453 -0
  98. package/src/core/retrieval/symbol-evidence.ts +3 -3
  99. package/src/core/retrieval/typescript-references.ts +38 -7
  100. package/src/core/retrieval/universal-context.ts +182 -0
  101. package/src/core/telemetry/summary.ts +114 -0
  102. package/src/core/telemetry/telemetry.ts +192 -49
  103. package/src/mcp/formatters/compact-text.ts +439 -0
  104. package/src/mcp/resources-and-prompts.ts +255 -0
  105. package/src/mcp/schemas/boundary.ts +145 -0
  106. package/src/mcp/schemas/map.ts +250 -0
  107. package/src/mcp/schemas/shared.ts +52 -0
  108. package/src/mcp/schemas/slice.ts +60 -0
  109. package/src/mcp/schemas/symbol.ts +268 -0
  110. package/src/mcp/schemas.ts +5 -746
  111. package/src/mcp/server.ts +269 -429
  112. package/src/mcp/tool-catalog.ts +331 -0
  113. package/src/mcp/tools/boundary.ts +68 -3
  114. package/src/mcp/tools/map.ts +104 -4
  115. package/src/mcp/tools/slice.ts +101 -3
  116. package/src/mcp/tools/symbol.ts +469 -17
  117. package/src/mcp/ui/app-client.ts +899 -0
  118. package/src/mcp/ui/app.html +478 -0
  119. package/src/mcp/workflow-playbooks.ts +181 -0
  120. package/src/mcp/workspace-boundary.ts +50 -0
  121. package/src/mcp/workspace-manager.ts +88 -15
  122. package/src/mcp/workspace-watcher.ts +30 -11
  123. package/src/types/index.ts +12 -0
  124. package/src/mcp/tools/check-boundary.ts +0 -382
  125. package/src/mcp/tools/get-domain-catalog.ts +0 -39
  126. package/src/mcp/tools/get-symbol-impact.ts +0 -104
  127. package/src/mcp/tools/locate-symbol.ts +0 -236
  128. package/src/mcp/tools/register-domain.ts +0 -113
  129. package/src/mcp/tools/trace-vertical-slice.ts +0 -106
@@ -41,6 +41,16 @@ import { DomainRepository } from "./repositories/domain.repository.ts";
41
41
  import { FileRepository } from "./repositories/file.repository.ts";
42
42
  import { MetaRepository } from "./repositories/meta.repository.ts";
43
43
  import { SymbolRepository } from "./repositories/symbol.repository.ts";
44
+ import {
45
+ buildDomainFileConnections,
46
+ buildFileConnections,
47
+ buildFileInboundImpact,
48
+ buildImportEvidence,
49
+ buildImportRelationships,
50
+ buildScopedImportRelationships,
51
+ buildSymbolImpact,
52
+ } from "../resolver/dependency-analysis.ts";
53
+ import { buildSymbolDetails } from "../retrieval/symbol-details.ts";
44
54
 
45
55
  export type DatabaseRepository = SeptumRepository;
46
56
 
@@ -189,6 +199,10 @@ export class SeptumRepository {
189
199
  return this.files.deleteFilesNotInPaths(domainId, validPaths);
190
200
  }
191
201
 
202
+ public rebindFilesToDomain(rootPrefix: string, domainId: number): number {
203
+ return this.files.rebindFilesToDomain(rootPrefix, domainId);
204
+ }
205
+
192
206
  public deleteFile(path: string): void {
193
207
  this.files.deleteFile(path);
194
208
  }
@@ -234,8 +248,15 @@ export class SeptumRepository {
234
248
  return this.symbols.findContainers(containerName);
235
249
  }
236
250
 
237
- public getAllSymbolsWithFiles(): Array<SymbolRecord & { file_path: string }> {
238
- return this.symbols.getAllSymbolsWithFiles();
251
+ public findFuzzySymbolCandidates(
252
+ query: string,
253
+ options?: { domainId?: number; filePath?: string; limit?: number }
254
+ ): Array<SymbolRecord & { file_path: string }> {
255
+ return this.symbols.findFuzzySymbolCandidates(query, options);
256
+ }
257
+
258
+ public getAllSymbolsWithFiles(filter?: { domainId?: number; filePath?: string }): Array<SymbolRecord & { file_path: string }> {
259
+ return this.symbols.getAllSymbolsWithFiles(filter);
239
260
  }
240
261
 
241
262
  // --- Dependency & Slice Methods ---
@@ -249,6 +270,14 @@ export class SeptumRepository {
249
270
  this.dependencies.upsertVerticalSlice(slice);
250
271
  }
251
272
 
273
+ public insertVerticalSlice(slice: Omit<VerticalSliceRecord, "id" | "created_at">): void {
274
+ this.dependencies.insertVerticalSlice(slice);
275
+ }
276
+
277
+ public insertVerticalSlices(slices: ReadonlyArray<Omit<VerticalSliceRecord, "id" | "created_at">>): void {
278
+ this.dependencies.insertVerticalSlices(slices);
279
+ }
280
+
252
281
  public findVerticalSlices(searchTerm: string): VerticalSliceRecord[] {
253
282
  return this.dependencies.findVerticalSlices(searchTerm);
254
283
  }
@@ -257,6 +286,10 @@ export class SeptumRepository {
257
286
  return this.dependencies.getAllVerticalSlices();
258
287
  }
259
288
 
289
+ public findExactVerticalSlices(rawQuery: string, controllerFile?: string): VerticalSliceRecord[] {
290
+ return this.dependencies.findExactVerticalSlices(rawQuery, controllerFile);
291
+ }
292
+
260
293
  public countVerticalSlices(): number {
261
294
  return this.dependencies.countVerticalSlices();
262
295
  }
@@ -265,16 +298,31 @@ export class SeptumRepository {
265
298
  this.dependencies.clearVerticalSlices(domainId);
266
299
  }
267
300
 
301
+ public getImportEvidence(workspaceRoot: string, verifyFile?: (file: string) => boolean) {
302
+ return buildImportEvidence(this.dependencies, workspaceRoot, undefined, verifyFile);
303
+ }
304
+
268
305
  public getImportRelationships(workspaceRoot?: string, sourceFile?: string) {
269
- return this.dependencies.getImportRelationships(workspaceRoot, sourceFile);
306
+ return buildImportRelationships(this.dependencies, workspaceRoot, sourceFile);
307
+ }
308
+
309
+ public getScopedImportRelationships(
310
+ workspaceRoot?: string,
311
+ options: {
312
+ sourceFiles?: ReadonlySet<string>;
313
+ targetCandidateFiles?: ReadonlySet<string>;
314
+ sourceOrTargetPaths?: ReadonlySet<string>;
315
+ } = {}
316
+ ) {
317
+ return buildScopedImportRelationships(this.dependencies, workspaceRoot, options);
270
318
  }
271
319
 
272
320
  public getDomainFileConnections(domainId?: number, workspaceRoot?: string) {
273
- return this.dependencies.getDomainFileConnections(domainId,workspaceRoot);
321
+ return buildDomainFileConnections(this.dependencies, domainId, workspaceRoot);
274
322
  }
275
323
 
276
324
  public getFileConnections(filePath: string, workspaceRoot?: string) {
277
- return this.dependencies.getFileConnections(filePath,workspaceRoot);
325
+ return buildFileConnections(this.dependencies, filePath, workspaceRoot);
278
326
  }
279
327
 
280
328
  public getAllDependenciesWithDomains(): Array<{
@@ -319,27 +367,38 @@ export class SeptumRepository {
319
367
  return this.symbols.getFileWithDomain(filePath);
320
368
  }
321
369
 
370
+ public findConstructorSignature(fileId: number, classOwner: string): string | null {
371
+ return this.symbols.findConstructorSignature(fileId, classOwner);
372
+ }
373
+
374
+ public getInternalImportStatements(fileId: number): string[] {
375
+ return this.symbols.getInternalImportStatements(fileId);
376
+ }
377
+
322
378
  public getSymbolDetails(
323
379
  symbolQuery: string,
324
380
  options: SymbolSelectionOptions & { includeDependencies?: boolean; workspaceRoot?: string } = {}
325
381
  ): GetSymbolDetailsResponse | null {
326
- return this.symbols.getSymbolDetails(symbolQuery, options);
382
+ return buildSymbolDetails(this, symbolQuery, options);
327
383
  }
328
384
 
329
385
  public getSymbolImpact(
330
386
  symbolName: string,
331
387
  options: { domain?: string; workspaceRoot?: string; filePath?: string; reference?: SymbolReference } = {}
332
388
  ): GetSymbolImpactResponse {
333
- return this.dependencies.getSymbolImpact(symbolName, options);
389
+ return buildSymbolImpact(this.dependencies, symbolName, options);
334
390
  }
335
391
 
336
- public getFileInboundImpact(filePath: string): {
392
+ public getFileInboundImpact(
393
+ filePath: string,
394
+ precomputedRelationships?: ReturnType<SeptumRepository["getImportRelationships"]>
395
+ ): {
337
396
  direct_dependents_count: number;
338
397
  top_consumers: string[];
339
398
  symbols_count: number;
340
399
  risk_level: "low" | "medium" | "high";
341
400
  } {
342
- return this.dependencies.getFileInboundImpact(filePath);
401
+ return buildFileInboundImpact(this.dependencies, filePath, precomputedRelationships);
343
402
  }
344
403
 
345
404
  // --- Metadata Methods ---
@@ -1,4 +1,5 @@
1
1
  import type { Database } from "bun:sqlite";
2
+ import { computeSymbolLeafName } from "./repositories/symbol.repository.ts";
2
3
 
3
4
  export const CURRENT_SCHEMA_VERSION = 5;
4
5
 
@@ -31,6 +32,7 @@ export const TABLE_STATEMENTS = [
31
32
  id INTEGER PRIMARY KEY AUTOINCREMENT,
32
33
  file_id INTEGER NOT NULL,
33
34
  name TEXT NOT NULL,
35
+ leaf_name TEXT NOT NULL DEFAULT '',
34
36
  kind TEXT NOT NULL,
35
37
  signature TEXT NOT NULL,
36
38
  visibility TEXT NOT NULL DEFAULT 'public',
@@ -48,6 +50,7 @@ export const TABLE_STATEMENTS = [
48
50
  import_statement TEXT NOT NULL,
49
51
  line_number INTEGER NOT NULL DEFAULT 0,
50
52
  is_external BOOLEAN NOT NULL DEFAULT 0,
53
+ resolved_target_file TEXT,
51
54
  FOREIGN KEY (source_file_id) REFERENCES files(id) ON DELETE CASCADE
52
55
  );`,
53
56
 
@@ -83,9 +86,11 @@ export const INDEX_STATEMENTS = [
83
86
  "CREATE INDEX IF NOT EXISTS idx_symbols_file_id ON symbols(file_id);",
84
87
  "CREATE INDEX IF NOT EXISTS idx_symbols_file_lines ON symbols(file_id, line_start, line_end);",
85
88
  "CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);",
89
+ "CREATE INDEX IF NOT EXISTS idx_symbols_leaf_name ON symbols(leaf_name);",
86
90
  "CREATE INDEX IF NOT EXISTS idx_symbols_kind ON symbols(kind);",
87
91
  "CREATE INDEX IF NOT EXISTS idx_dependencies_source ON dependencies(source_file_id);",
88
92
  "CREATE INDEX IF NOT EXISTS idx_dependencies_target ON dependencies(target_symbol_or_path);",
93
+ "CREATE INDEX IF NOT EXISTS idx_dependencies_resolved_target ON dependencies(resolved_target_file);",
89
94
  "CREATE INDEX IF NOT EXISTS idx_slices_route_uri ON vertical_slices(route_uri);",
90
95
  "CREATE INDEX IF NOT EXISTS idx_slices_route_name ON vertical_slices(route_name);",
91
96
  "CREATE INDEX IF NOT EXISTS idx_slices_controller ON vertical_slices(controller_class, action_name);",
@@ -115,6 +120,27 @@ export function initializeDatabaseSchema(db: Database): void {
115
120
  db.run(tableSql);
116
121
  }
117
122
 
123
+ // Additive migration for existing v5 databases without resolved_target_file column
124
+ const depCols = db.query<{ name: string }, []>("PRAGMA table_info(dependencies);").all();
125
+ if (!depCols.some(col => col.name === "resolved_target_file")) {
126
+ db.run("ALTER TABLE dependencies ADD COLUMN resolved_target_file TEXT;");
127
+ }
128
+
129
+ // Additive migration for existing v5 databases without symbols.leaf_name column
130
+ const symCols = db.query<{ name: string }, []>("PRAGMA table_info(symbols);").all();
131
+ if (!symCols.some(col => col.name === "leaf_name")) {
132
+ db.run("ALTER TABLE symbols ADD COLUMN leaf_name TEXT NOT NULL DEFAULT '';");
133
+ const rows = db.query<{ id: number; name: string }, []>("SELECT id, name FROM symbols WHERE leaf_name = ''").all();
134
+ if (rows.length > 0) {
135
+ const updateStmt = db.query("UPDATE symbols SET leaf_name = ? WHERE id = ?");
136
+ db.transaction(() => {
137
+ for (const row of rows) {
138
+ updateStmt.run(computeSymbolLeafName(row.name), row.id);
139
+ }
140
+ })();
141
+ }
142
+ }
143
+
118
144
  for (const indexSql of INDEX_STATEMENTS) {
119
145
  db.run(indexSql);
120
146
  }
@@ -0,0 +1,69 @@
1
+ import ts from "typescript";
2
+ import { resolve } from "node:path";
3
+ import { bindContextFile } from "../retrieval/typescript-references.ts";
4
+ import { lineOf, visitRouteCalls } from "../parser/extractors/typescript-bindings.ts";
5
+ import { readOptionalSourceFile } from "../resources/source-files.ts";
6
+ import type { FileRecord } from "../../types/index.ts";
7
+
8
+ export interface DiscoveredRoute {
9
+ method: string;
10
+ uri: string;
11
+ file: string;
12
+ line: number;
13
+ middlewareSymbols: string[];
14
+ handlerSymbol?: string;
15
+ handlerClass?: string;
16
+ handlerMethod?: string;
17
+ }
18
+
19
+ /** Discover declarative ambient router calls (app/router/server/api.get/post/...) in JS/TS route modules. */
20
+ export function discoverDeclarativeRoutesFromFiles(
21
+ projectRoot: string,
22
+ filesByNormPath: ReadonlyMap<string, FileRecord>,
23
+ excluded?: ReadonlySet<string>
24
+ ): DiscoveredRoute[] {
25
+ const routes: DiscoveredRoute[] = [];
26
+ for (const [key, file] of filesByNormPath) {
27
+ if (
28
+ excluded?.has(file.path) ||
29
+ !/\.[cm]?[jt]sx?$/.test(key) ||
30
+ (file.archetype !== "route" && !/routes?|router|endpoints?/.test(key))
31
+ ) {
32
+ continue;
33
+ }
34
+ const absolute = resolve(projectRoot, file.path);
35
+ const source = readOptionalSourceFile(absolute, "utf-8");
36
+ if (!source) continue;
37
+ const unit = bindContextFile(absolute, source);
38
+ if (unit.hasErrors) continue;
39
+
40
+ visitRouteCalls(unit.source, (call) => {
41
+ const member = call.expression;
42
+ if (
43
+ !ts.isPropertyAccessExpression(member) ||
44
+ !ts.isIdentifier(member.expression) ||
45
+ !/^(app|router|server|api)$/.test(member.expression.text) ||
46
+ unit.checker.getSymbolAtLocation(member.expression) ||
47
+ !/^(get|post|put|patch|delete|options|head)$/.test(member.name.text)
48
+ ) {
49
+ return;
50
+ }
51
+ const uri = call.arguments[0];
52
+ const handler = call.arguments.at(-1);
53
+ if (!uri || !ts.isStringLiteralLike(uri) || call.arguments.length < 2 || !handler) return;
54
+ routes.push({
55
+ method: member.name.text.toUpperCase(),
56
+ uri: uri.text,
57
+ file: file.path,
58
+ line: lineOf(call),
59
+ middlewareSymbols: call.arguments.slice(1, -1).map((arg) => arg.getText()),
60
+ handlerSymbol: handler.getText(),
61
+ ...(ts.isPropertyAccessExpression(handler) && {
62
+ handlerClass: handler.expression.getText(),
63
+ handlerMethod: handler.name.text,
64
+ }),
65
+ });
66
+ });
67
+ }
68
+ return routes;
69
+ }
@@ -0,0 +1,149 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+
4
+ export type DetectedLanguage = "typescript" | "javascript" | "php" | "python" | "go" | "generic";
5
+
6
+ function warnIfUnexpectedError(context: string, err: unknown): void {
7
+ const errno = (err as NodeJS.ErrnoException | undefined)?.code;
8
+ if (errno === "ENOENT" || errno === "ENOTDIR") return;
9
+ const msg = err instanceof Error ? err.message : String(err);
10
+ console.warn(`[Septum Topology] ${context}: ${msg}`);
11
+ }
12
+
13
+ /**
14
+ * Reads compilerOptions.paths from tsconfig.json or jsconfig.json.
15
+ */
16
+ export function readTsConfigPaths(projectRoot: string): Record<string, string[]> {
17
+ for (const file of ["tsconfig.json", "jsconfig.json"]) {
18
+ const fullPath = path.join(projectRoot, file);
19
+ if (fs.existsSync(fullPath)) {
20
+ try {
21
+ const raw = fs.readFileSync(fullPath, "utf-8");
22
+ const stripped = raw.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "");
23
+ const parsed = JSON.parse(stripped);
24
+ if (parsed.compilerOptions?.paths) {
25
+ return parsed.compilerOptions.paths;
26
+ }
27
+ } catch (err: unknown) {
28
+ warnIfUnexpectedError(`Failed to parse ${fullPath}`, err);
29
+ }
30
+ }
31
+ }
32
+ return {};
33
+ }
34
+
35
+ export function detectProjectLanguage(projectRoot: string): DetectedLanguage {
36
+ if (
37
+ fs.existsSync(path.join(projectRoot, "composer.json")) ||
38
+ fs.existsSync(path.join(projectRoot, "artisan"))
39
+ ) {
40
+ return "php";
41
+ }
42
+ if (fs.existsSync(path.join(projectRoot, "go.mod"))) return "go";
43
+ if (
44
+ fs.existsSync(path.join(projectRoot, "pyproject.toml")) ||
45
+ fs.existsSync(path.join(projectRoot, "requirements.txt"))
46
+ ) {
47
+ return "python";
48
+ }
49
+ if (
50
+ fs.existsSync(path.join(projectRoot, "tsconfig.json")) ||
51
+ fs.existsSync(path.join(projectRoot, "package.json"))
52
+ ) {
53
+ return "typescript";
54
+ }
55
+ return "generic";
56
+ }
57
+
58
+ export function detectProjectFramework(
59
+ projectRoot: string,
60
+ language: DetectedLanguage
61
+ ): string {
62
+ if (language === "php") {
63
+ if (fs.existsSync(path.join(projectRoot, "artisan"))) return "laravel";
64
+ if (
65
+ fs.existsSync(path.join(projectRoot, "bin/console")) ||
66
+ fs.existsSync(path.join(projectRoot, "symfony.lock"))
67
+ ) {
68
+ return "symfony";
69
+ }
70
+ const composerJson = path.join(projectRoot, "composer.json");
71
+ if (fs.existsSync(composerJson)) {
72
+ try {
73
+ const composer = JSON.parse(fs.readFileSync(composerJson, "utf-8"));
74
+ const reqs = { ...(composer.require ?? {}), ...(composer["require-dev"] ?? {}) };
75
+ if (reqs["symfony/framework-bundle"] || reqs["symfony/symfony"]) {
76
+ return "symfony";
77
+ }
78
+ } catch (err: unknown) {
79
+ warnIfUnexpectedError(`Failed to parse ${composerJson}`, err);
80
+ }
81
+ }
82
+ return "generic-php";
83
+ }
84
+ if (language === "typescript" || language === "javascript") {
85
+ const pkgJson = path.join(projectRoot, "package.json");
86
+ try {
87
+ if (fs.existsSync(pkgJson)) {
88
+ const pkg = JSON.parse(fs.readFileSync(pkgJson, "utf-8"));
89
+ const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
90
+ if (allDeps.next) return "nextjs";
91
+ if (allDeps.nuxt) return "nuxt";
92
+ if (allDeps.astro) return "astro";
93
+ if (allDeps.vue) return "vue";
94
+ if (allDeps["@nestjs/core"]) return "nestjs";
95
+ if (allDeps.express) return "express";
96
+ if (allDeps.fastify) return "fastify";
97
+ if (allDeps.hono) return "hono";
98
+ if (allDeps.elysia) return "elysia";
99
+ if (allDeps["@modelcontextprotocol/sdk"]) return "mcp-server";
100
+ }
101
+ } catch (err: unknown) {
102
+ warnIfUnexpectedError(`Failed to inspect dependencies in ${pkgJson}`, err);
103
+ }
104
+ return "generic-node";
105
+ }
106
+ if (language === "python") {
107
+ if (
108
+ fs.existsSync(path.join(projectRoot, "manage.py")) ||
109
+ fs.existsSync(path.join(projectRoot, "wsgi.py")) ||
110
+ fs.existsSync(path.join(projectRoot, "asgi.py"))
111
+ ) {
112
+ return "django";
113
+ }
114
+ const readSafe = (p: string) => {
115
+ try {
116
+ return fs.existsSync(p) ? fs.readFileSync(p, "utf-8").toLowerCase() : "";
117
+ } catch (err: unknown) {
118
+ warnIfUnexpectedError(`Failed to read ${p}`, err);
119
+ return "";
120
+ }
121
+ };
122
+ const deps =
123
+ readSafe(path.join(projectRoot, "requirements.txt")) +
124
+ " " +
125
+ readSafe(path.join(projectRoot, "pyproject.toml")) +
126
+ " " +
127
+ readSafe(path.join(projectRoot, "Pipfile"));
128
+ if (deps.includes("fastapi")) return "fastapi";
129
+ if (deps.includes("django")) return "django";
130
+ if (deps.includes("flask")) return "flask";
131
+ return "generic-python";
132
+ }
133
+ if (language === "go") {
134
+ const goModPath = path.join(projectRoot, "go.mod");
135
+ if (fs.existsSync(goModPath)) {
136
+ try {
137
+ const modContent = fs.readFileSync(goModPath, "utf-8").toLowerCase();
138
+ if (modContent.includes("github.com/gin-gonic/gin")) return "gin";
139
+ if (modContent.includes("github.com/labstack/echo")) return "echo";
140
+ if (modContent.includes("github.com/go-chi/chi")) return "chi";
141
+ if (modContent.includes("github.com/gofiber/fiber")) return "fiber";
142
+ } catch (err: unknown) {
143
+ warnIfUnexpectedError(`Failed to inspect ${goModPath}`, err);
144
+ }
145
+ }
146
+ return "generic-go";
147
+ }
148
+ return "generic";
149
+ }