@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.
Files changed (161) hide show
  1. package/README.md +46 -45
  2. package/package.json +8 -6
  3. package/src/cli/commands/check.ts +41 -26
  4. package/src/cli/commands/hook.ts +77 -105
  5. package/src/cli/commands/init.ts +35 -9
  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 +35 -9
  9. package/src/cli/hook-payload.ts +43 -0
  10. package/src/cli/index.ts +15 -51
  11. package/src/cli/scaffold/harness-config.ts +48 -8
  12. package/src/cli/templates/hooks.ts +51 -27
  13. package/src/cli/templates/rules.ts +34 -49
  14. package/src/cli/templates/skill.ts +46 -35
  15. package/src/core/boundary/audit.ts +383 -0
  16. package/src/core/boundary/evaluator.ts +299 -178
  17. package/src/core/boundary/staged-auditor.ts +188 -34
  18. package/src/core/config/domain-ownership.ts +47 -0
  19. package/src/core/config/domain-registration.ts +141 -0
  20. package/src/core/config/loader.ts +82 -54
  21. package/src/core/config/schema.ts +24 -46
  22. package/src/core/database/client.ts +2 -0
  23. package/src/core/database/repositories/dependency.repository.ts +326 -543
  24. package/src/core/database/repositories/domain.repository.ts +48 -4
  25. package/src/core/database/repositories/file.repository.ts +10 -0
  26. package/src/core/database/repositories/symbol.repository.ts +97 -259
  27. package/src/core/database/repository.ts +138 -24
  28. package/src/core/database/schema.ts +28 -33
  29. package/src/core/discovery/declarative-routes.ts +69 -0
  30. package/src/core/discovery/framework-detector.ts +149 -0
  31. package/src/core/discovery/navigation.ts +269 -0
  32. package/src/core/discovery/topology-detector.ts +153 -170
  33. package/src/core/errors.ts +19 -0
  34. package/src/core/ingestion/pipeline.ts +378 -212
  35. package/src/core/parser/behavioral-analyzer.ts +26 -22
  36. package/src/core/parser/boundary-tracker.ts +15 -0
  37. package/src/core/parser/extractors/base.ts +16 -4
  38. package/src/core/parser/extractors/csharp.ts +9 -5
  39. package/src/core/parser/extractors/django-routing.ts +163 -0
  40. package/src/core/parser/extractors/django-semantic.ts +400 -516
  41. package/src/core/parser/extractors/elysia-semantic.ts +172 -496
  42. package/src/core/parser/extractors/express-semantic.ts +195 -398
  43. package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
  44. package/src/core/parser/extractors/fastify-semantic.ts +216 -732
  45. package/src/core/parser/extractors/flask-semantic.ts +92 -388
  46. package/src/core/parser/extractors/go-routing.ts +344 -0
  47. package/src/core/parser/extractors/go-semantic.ts +210 -508
  48. package/src/core/parser/extractors/go.ts +6 -3
  49. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  50. package/src/core/parser/extractors/hono-semantic.ts +132 -530
  51. package/src/core/parser/extractors/java.ts +7 -5
  52. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  53. package/src/core/parser/extractors/laravel-semantic.ts +169 -333
  54. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  55. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  56. package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
  57. package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
  58. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  59. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  60. package/src/core/parser/extractors/php.ts +17 -1
  61. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  62. package/src/core/parser/extractors/python.ts +9 -8
  63. package/src/core/parser/extractors/registry.ts +28 -5
  64. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  65. package/src/core/parser/extractors/ruby.ts +10 -7
  66. package/src/core/parser/extractors/rust.ts +35 -17
  67. package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
  68. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  69. package/src/core/parser/extractors/symfony-semantic.ts +75 -262
  70. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  71. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  72. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  73. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  74. package/src/core/parser/extractors/typescript.ts +36 -216
  75. package/src/core/parser/implementation-fingerprint.ts +97 -0
  76. package/src/core/parser/language-capabilities.ts +23 -7
  77. package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
  78. package/src/core/parser/schema/schema-provider-registry.ts +1 -3
  79. package/src/core/parser/schema/schema-provider.interface.ts +2 -1
  80. package/src/core/parser/semantic-revision.ts +3 -0
  81. package/src/core/parser/static-string.ts +51 -0
  82. package/src/core/parser/wasm-loader.ts +6 -2
  83. package/src/core/resolver/ast-method-tracer.ts +230 -0
  84. package/src/core/resolver/call-graph-helpers.ts +72 -0
  85. package/src/core/resolver/call-graph-tracer.ts +375 -311
  86. package/src/core/resolver/dependency-analysis.ts +593 -0
  87. package/src/core/resolver/import-candidates.ts +120 -0
  88. package/src/core/resolver/import-evidence.ts +88 -0
  89. package/src/core/resolver/import-resolver.ts +162 -181
  90. package/src/core/resolver/interpretation-inputs.ts +65 -0
  91. package/src/core/resolver/languages/go.ts +103 -0
  92. package/src/core/resolver/languages/managed.ts +200 -0
  93. package/src/core/resolver/languages/python.ts +133 -0
  94. package/src/core/resolver/languages/ruby.ts +40 -0
  95. package/src/core/resolver/languages/rust.ts +127 -0
  96. package/src/core/resolver/languages/shared.ts +74 -0
  97. package/src/core/resolver/module-resolver.ts +18 -7
  98. package/src/core/resolver/path-resolver.ts +6 -3
  99. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  100. package/src/core/resolver/slice-catalog.ts +94 -0
  101. package/src/core/resolver/slice-format.ts +22 -0
  102. package/src/core/resolver/slice-selection.ts +237 -0
  103. package/src/core/resolver/symbol-impact.ts +477 -0
  104. package/src/core/resolver/symbol-locator.ts +82 -15
  105. package/src/core/resolver/vertical-slice-tracer.ts +57 -278
  106. package/src/core/resources/ignore.ts +21 -1
  107. package/src/core/resources/limits.ts +2 -1
  108. package/src/core/resources/source-files.ts +143 -20
  109. package/src/core/resources/source-inventory.ts +55 -0
  110. package/src/core/resources/work-queue.ts +167 -4
  111. package/src/core/retrieval/context-page.ts +116 -0
  112. package/src/core/retrieval/context.ts +457 -0
  113. package/src/core/retrieval/resolution-warnings.ts +21 -0
  114. package/src/core/retrieval/source-context.ts +448 -0
  115. package/src/core/retrieval/symbol-details.ts +453 -0
  116. package/src/core/retrieval/symbol-evidence.ts +97 -0
  117. package/src/core/retrieval/typescript-references.ts +293 -0
  118. package/src/core/retrieval/universal-context.ts +182 -0
  119. package/src/core/telemetry/summary.ts +114 -0
  120. package/src/core/telemetry/telemetry.ts +225 -37
  121. package/src/index.ts +0 -3
  122. package/src/mcp/formatters/compact-text.ts +439 -0
  123. package/src/mcp/resources-and-prompts.ts +253 -0
  124. package/src/mcp/schemas/boundary.ts +145 -0
  125. package/src/mcp/schemas/map.ts +250 -0
  126. package/src/mcp/schemas/shared.ts +52 -0
  127. package/src/mcp/schemas/slice.ts +60 -0
  128. package/src/mcp/schemas/symbol.ts +268 -0
  129. package/src/mcp/schemas.ts +5 -1105
  130. package/src/mcp/server.ts +263 -597
  131. package/src/mcp/tool-catalog.ts +331 -0
  132. package/src/mcp/tools/boundary.ts +69 -4
  133. package/src/mcp/tools/map.ts +126 -0
  134. package/src/mcp/tools/slice.ts +101 -3
  135. package/src/mcp/tools/symbol.ts +480 -26
  136. package/src/mcp/ui/app-client.ts +899 -0
  137. package/src/mcp/ui/app.html +478 -0
  138. package/src/mcp/workflow-playbooks.ts +181 -0
  139. package/src/mcp/workspace-boundary.ts +50 -0
  140. package/src/mcp/workspace-manager.ts +102 -18
  141. package/src/mcp/workspace-watcher.ts +38 -19
  142. package/src/types/index.ts +47 -53
  143. package/src/cli/commands/topology.ts +0 -161
  144. package/src/core/database/repositories/environment.repository.ts +0 -207
  145. package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
  146. package/src/core/session/session-manager.ts +0 -107
  147. package/src/core/topology/environment-detector.ts +0 -973
  148. package/src/core/topology/types.ts +0 -83
  149. package/src/mcp/tools/check-boundary.ts +0 -387
  150. package/src/mcp/tools/domain.ts +0 -40
  151. package/src/mcp/tools/feature.ts +0 -67
  152. package/src/mcp/tools/get-domain-catalog.ts +0 -226
  153. package/src/mcp/tools/get-environment-topology.ts +0 -138
  154. package/src/mcp/tools/get-feature-context.ts +0 -224
  155. package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
  156. package/src/mcp/tools/get-symbol-impact.ts +0 -64
  157. package/src/mcp/tools/get-symbol.ts +0 -175
  158. package/src/mcp/tools/locate-symbol.ts +0 -196
  159. package/src/mcp/tools/register-domain.ts +0 -75
  160. package/src/mcp/tools/register-feature.ts +0 -110
  161. package/src/mcp/tools/trace-vertical-slice.ts +0 -80
@@ -3,12 +3,10 @@ import type {
3
3
  StackSchemaProvider,
4
4
  } from "./schema-provider.interface.ts";
5
5
  import { LaravelMigrationSchemaProvider } from "./providers/laravel-migration-provider.ts";
6
- import { PrismaSchemaProvider } from "./providers/prisma-schema-provider.ts";
7
6
 
8
7
  export class SchemaProviderRegistry {
9
8
  private static providers: StackSchemaProvider[] = [
10
9
  new LaravelMigrationSchemaProvider(),
11
- new PrismaSchemaProvider(),
12
10
  ];
13
11
 
14
12
  /**
@@ -30,7 +28,7 @@ export class SchemaProviderRegistry {
30
28
  if (provider.canHandle(projectRoot)) {
31
29
  try {
32
30
  const res = provider.resolveEntitySchema(projectRoot, entitySymbol, entityFilePath);
33
- if (res && !(res instanceof Promise)) {
31
+ if (res) {
34
32
  return res;
35
33
  }
36
34
  } catch {
@@ -7,6 +7,7 @@ export interface SchemaFieldSummary {
7
7
  }
8
8
 
9
9
  export interface SchemaMetadata {
10
+ interpretation?: "static_migration_summary";
10
11
  entityName: string;
11
12
  tableName: string;
12
13
  schemaSourceFile: string;
@@ -29,5 +30,5 @@ export interface StackSchemaProvider {
29
30
  projectRoot: string,
30
31
  entitySymbol: string,
31
32
  entityFilePath?: string
32
- ): Promise<SchemaMetadata | null> | SchemaMetadata | null;
33
+ ): SchemaMetadata | null;
33
34
  }
@@ -0,0 +1,3 @@
1
+ import { ANALYSIS_FINGERPRINT } from "./implementation-fingerprint.ts";
2
+
3
+ export const SEMANTIC_FINGERPRINT = ANALYSIS_FINGERPRINT;
@@ -0,0 +1,51 @@
1
+ import type Parser from "web-tree-sitter";
2
+
3
+ // Decode literal values without executing source. Unsupported evaluation stays unresolved.
4
+ export function readPythonStaticString(node: Parser.SyntaxNode | null | undefined): string | undefined {
5
+ if (!node) return undefined;
6
+ if (node.type === "concatenated_string") {
7
+ let value = "";
8
+ for (const child of node.namedChildren) {
9
+ if (child.type === "comment") continue;
10
+ const part = readPythonStaticString(child);
11
+ if (part === undefined) return undefined;
12
+ value += part;
13
+ }
14
+ return value;
15
+ }
16
+ if (node.type !== "string") return undefined;
17
+ const match = /^([rRuU]*)("""|'''|"|')([\s\S]*)\2$/.exec(node.text);
18
+ if (!match || node.namedChildren.some(child => child.type === "interpolation")) return undefined;
19
+ const body = match[3];
20
+ if (match[1].toLowerCase().includes("r")) return body;
21
+
22
+ let value = "";
23
+ const escapes: Record<string, string> = { "\\": "\\", "'": "'", '"': '"', a: "\x07", b: "\b", f: "\f", n: "\n", r: "\r", t: "\t", v: "\v" };
24
+ for (let i = 0; i < body.length; i++) {
25
+ if (body[i] !== "\\") { value += body[i]; continue; }
26
+ const escaped = body[++i];
27
+ if (escaped === undefined) return undefined;
28
+ if (escaped === "\n") continue;
29
+ if (escaped === "\r" && body[i + 1] === "\n") { i++; continue; }
30
+ if (escapes[escaped] !== undefined) { value += escapes[escaped]; continue; }
31
+ if (/[0-7]/.test(escaped)) {
32
+ const octal = body.slice(i).match(/^[0-7]{1,3}/)![0];
33
+ value += String.fromCodePoint(parseInt(octal, 8));
34
+ i += octal.length - 1;
35
+ continue;
36
+ }
37
+ const digits = escaped === "x" ? 2 : escaped === "u" ? 4 : escaped === "U" ? 8 : 0;
38
+ if (digits) {
39
+ const hex = body.slice(i + 1, i + 1 + digits);
40
+ if (hex.length !== digits || !/^[0-9a-f]+$/i.test(hex)) return undefined;
41
+ const point = parseInt(hex, 16);
42
+ if (point > 0x10ffff || point >= 0xd800 && point <= 0xdfff) return undefined;
43
+ value += String.fromCodePoint(point);
44
+ i += digits;
45
+ continue;
46
+ }
47
+ if (escaped === "N") return undefined; // Unicode names require a Unicode database.
48
+ value += `\\${escaped}`;
49
+ }
50
+ return value;
51
+ }
@@ -233,9 +233,13 @@ export async function parseSourceWithTreeSitter(
233
233
  };
234
234
  }
235
235
 
236
- export function getNodeHeader(node: Parser.SyntaxNode): string {
236
+ export function getNodeHeader(node: Parser.SyntaxNode, content?: string): string {
237
237
  const body = node.childForFieldName("body");
238
238
  const end = body ?? node.children.findLast(child => child.type === "end");
239
+ if (content !== undefined) {
240
+ const endOffset = end ? end.startIndex : node.endIndex;
241
+ return content.slice(node.startIndex, endOffset).trim().replace(/;$/, "");
242
+ }
239
243
  return (end ? node.text.slice(0, end.startIndex - node.startIndex) : node.text)
240
244
  .trim().replace(/;$/, "");
241
245
  }
@@ -264,7 +268,7 @@ export function calculateAstControlFlowNesting(
264
268
  }
265
269
  }
266
270
 
267
- for (const child of node.namedChildren) {
271
+ for (let child = node.firstNamedChild; child; child = child.nextNamedSibling) {
268
272
  walk(child, nextDepth, false);
269
273
  }
270
274
  }
@@ -0,0 +1,230 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import ts from "typescript";
4
+ import type { ExecutionChainNode, FileRecord, SymbolRecord } from "../../types/index.ts";
5
+ import { bindContextFile } from "../retrieval/typescript-references.ts";
6
+
7
+ export type BoundUnit = ReturnType<typeof bindContextFile>;
8
+ export type TracerDependency = { target: string; statement: string; line_number: number; is_external: boolean };
9
+
10
+ export interface AstMethodTracerContext {
11
+ projectRoot: string;
12
+ maxChainNodes: number;
13
+ hasWorkspaceRoot: boolean;
14
+ fileSymbols: (fileId: number) => SymbolRecord[];
15
+ fileDependencies: (fileId: number) => TracerDependency[];
16
+ resolveImportTargets: (fromPath: string, moduleSpec: string) => FileRecord[];
17
+ resolveImportToFile: (fromPath: string, moduleSpec: string) => FileRecord | undefined;
18
+ resolveExecutableSymbol: (symbols: SymbolRecord[], preferredNames: string[]) => SymbolRecord | undefined;
19
+ isExecutableSymbol: (symbol: SymbolRecord) => boolean;
20
+ detectStage: (filePath: string, archetype: string) => string;
21
+ }
22
+
23
+ /** Locate the narrowest AST node covering a symbol's indexed line span. */
24
+ export function findAstNodeForSymbol(unit: BoundUnit, sym: SymbolRecord): ts.Node | undefined {
25
+ let best: ts.Node | undefined;
26
+ const visit = (node: ts.Node) => {
27
+ const sLine = unit.source.getLineAndCharacterOfPosition(node.getStart()).line + 1;
28
+ const eLine = unit.source.getLineAndCharacterOfPosition(node.end).line + 1;
29
+ if (sLine <= sym.line_start && eLine >= sym.line_end) {
30
+ if (ts.isFunctionLike(node) || ts.isVariableDeclaration(node) || ts.isClassDeclaration(node)) {
31
+ best = node;
32
+ }
33
+ ts.forEachChild(node, visit);
34
+ }
35
+ };
36
+ ts.forEachChild(unit.source, visit);
37
+ return best ?? unit.declaration(sym.line_start, sym.line_end);
38
+ }
39
+
40
+ /** Collect non-type-only AST import declarations and their referenced symbol names. */
41
+ export function collectActiveAstImports(importDecl: ts.ImportDeclaration, importedNames: Set<string>): string[] {
42
+ if (importDecl.importClause?.isTypeOnly) return [];
43
+ const named = importDecl.importClause?.namedBindings;
44
+ return [...importedNames].filter((name) => {
45
+ if (named && ts.isNamedImports(named)) {
46
+ const el = named.elements.find((e) => (e.propertyName ?? e.name).text === name);
47
+ if (el?.isTypeOnly) return false;
48
+ }
49
+ return name !== "*";
50
+ });
51
+ }
52
+
53
+ function resolveAstTargetSymbol(
54
+ ctx: AstMethodTracerContext,
55
+ resolvedFile: FileRecord,
56
+ symName: string,
57
+ loadBound: (filePath: string) => BoundUnit | null
58
+ ): SymbolRecord | undefined {
59
+ const fileSymbols = ctx.fileSymbols(resolvedFile.id);
60
+ const direct = ctx.resolveExecutableSymbol(fileSymbols, [symName]);
61
+ if (direct || !/\.[cm]?[jt]sx?$/i.test(resolvedFile.path)) return direct;
62
+
63
+ const targetUnit = loadBound(resolvedFile.path);
64
+ const exportedNode = targetUnit?.exported(symName);
65
+ if (!targetUnit || !exportedNode) return undefined;
66
+
67
+ const sLine = targetUnit.source.getLineAndCharacterOfPosition(exportedNode.getStart()).line + 1;
68
+ const eLine = targetUnit.source.getLineAndCharacterOfPosition(exportedNode.end).line + 1;
69
+ return fileSymbols.find((s) => s.line_start >= sLine && s.line_end <= eLine && ctx.isExecutableSymbol(s));
70
+ }
71
+
72
+ /**
73
+ * AST-verified BFS traversal for TypeScript/JavaScript methods.
74
+ * Expands same-file local helper calls without consuming import hop budget,
75
+ * and follows bound imported callees/references up to effectiveMaxDepth.
76
+ */
77
+ export function traverseAstMethodGraph(
78
+ ctx: AstMethodTracerContext,
79
+ startFile: FileRecord,
80
+ startSymbol: SymbolRecord,
81
+ chain: ExecutionChainNode[],
82
+ effectiveMaxDepth: number
83
+ ): void {
84
+ const boundCache = new Map<string, BoundUnit | null>();
85
+ const loadBound = (filePath: string): BoundUnit | null => {
86
+ if (boundCache.has(filePath)) return boundCache.get(filePath)!;
87
+ const fullPath = resolve(ctx.projectRoot, filePath);
88
+ const source = existsSync(fullPath) ? readFileSync(fullPath, "utf-8") : "";
89
+ const unit = source ? bindContextFile(filePath, source) : null;
90
+ boundCache.set(filePath, unit);
91
+ return unit;
92
+ };
93
+
94
+ const visitedNodes = new Set<string>([`${startFile.path}:${startSymbol.name}:${startSymbol.line_start}`]);
95
+ const queue: Array<{ file: FileRecord; symbol: SymbolRecord; depth: number; visualDepth: number }> = [
96
+ { file: startFile, symbol: startSymbol, depth: 1, visualDepth: 1 },
97
+ ];
98
+
99
+ while (queue.length > 0 && chain.length < ctx.maxChainNodes) {
100
+ const current = queue.shift()!;
101
+ if (current.depth > effectiveMaxDepth || !/\.[cm]?[jt]sx?$/i.test(current.file.path)) continue;
102
+
103
+ const unit = loadBound(current.file.path);
104
+ const declNode = unit ? findAstNodeForSymbol(unit, current.symbol) : undefined;
105
+ if (!unit || !declNode) continue;
106
+
107
+ const refs = unit.references(declNode);
108
+ // Bridge same-file local helper calls (e.g. thin entrypoint wrappers delegating to local functions).
109
+ const currentSymbols = ctx.fileSymbols(current.file.id);
110
+ for (const localNode of refs.locals) {
111
+ if (chain.length >= ctx.maxChainNodes) break;
112
+ const isLocalCall = refs.calls.some((c) => c.target === localNode);
113
+ if (!isLocalCall) continue;
114
+ const localStart = unit.source.getLineAndCharacterOfPosition(localNode.getStart()).line + 1;
115
+ const localEnd = unit.source.getLineAndCharacterOfPosition(localNode.end).line + 1;
116
+ const localSymbol = currentSymbols.find(
117
+ (s) =>
118
+ ctx.isExecutableSymbol(s) &&
119
+ (s.line_start === localStart || (s.line_start >= localStart && s.line_end <= localEnd))
120
+ );
121
+ if (!localSymbol) continue;
122
+ const localVisitKey = `${current.file.path}:${localSymbol.name}:${localSymbol.line_start}`;
123
+ if (!chain.some((c) => c.file === current.file.path && c.symbol === localSymbol.name)) {
124
+ const stage = ctx.detectStage(current.file.path, current.file.archetype);
125
+ chain.push({
126
+ stage,
127
+ symbol: localSymbol.name,
128
+ parent_symbol: current.symbol.name,
129
+ depth: current.visualDepth,
130
+ file: current.file.path,
131
+ line: localSymbol.line_start || 1,
132
+ description: `${stage.toUpperCase()} (AST local call): ${localSymbol.name}`,
133
+ relationship: {
134
+ kind: "calls",
135
+ derivation: "source",
136
+ source: { file: current.file.path, line: current.symbol.line_start || 1 },
137
+ reason: "ast_local_call_site",
138
+ },
139
+ });
140
+ }
141
+ if (!visitedNodes.has(localVisitKey)) {
142
+ visitedNodes.add(localVisitKey);
143
+ queue.push({ file: current.file, symbol: localSymbol, depth: current.depth, visualDepth: current.visualDepth + 1 });
144
+ }
145
+ }
146
+
147
+ const importEntries = new Map<ts.ImportDeclaration, Set<string>>(refs.imports);
148
+ if (ts.isMethodDeclaration(declNode) && ts.isClassDeclaration(declNode.parent)) {
149
+ const usedProps = new Set<string>();
150
+ const walkProps = (n: ts.Node) => {
151
+ if (ts.isPropertyAccessExpression(n) && n.expression.kind === ts.SyntaxKind.ThisKeyword) {
152
+ usedProps.add(n.name.text);
153
+ }
154
+ ts.forEachChild(n, walkProps);
155
+ };
156
+ walkProps(declNode);
157
+ if (usedProps.size > 0) {
158
+ for (const member of declNode.parent.members) {
159
+ const propNames = ts.isPropertyDeclaration(member) && ts.isIdentifier(member.name)
160
+ ? [{ name: member.name.text, typeNode: member.type }]
161
+ : ts.isConstructorDeclaration(member)
162
+ ? member.parameters.filter(p => ts.isIdentifier(p.name)).map(p => ({ name: (p.name as ts.Identifier).text, typeNode: p.type }))
163
+ : [];
164
+ for (const p of propNames) {
165
+ if (!usedProps.has(p.name) || !p.typeNode) continue;
166
+ const typeRefs = unit.references(p.typeNode);
167
+ for (const [imp, names] of typeRefs.imports) {
168
+ const existing = importEntries.get(imp) ?? new Set<string>();
169
+ for (const name of names) existing.add(name);
170
+ importEntries.set(imp, existing);
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ const deps = ctx.fileDependencies(current.file.id);
178
+
179
+ for (const [importDecl, importedNames] of importEntries) {
180
+ if (chain.length >= ctx.maxChainNodes) break;
181
+ const activeNames = collectActiveAstImports(importDecl, importedNames);
182
+ const moduleSpec = ts.isStringLiteral(importDecl.moduleSpecifier) ? importDecl.moduleSpecifier.text : "";
183
+ if (activeNames.length === 0 || !moduleSpec) continue;
184
+
185
+ const importLine = unit.source.getLineAndCharacterOfPosition(importDecl.getStart()).line + 1;
186
+ const dep = deps.find((d) => d.target === moduleSpec || d.line_number === importLine);
187
+ if (dep?.is_external) continue;
188
+
189
+ const resolvedFiles = ctx.hasWorkspaceRoot
190
+ ? ctx.resolveImportTargets(current.file.path, moduleSpec)
191
+ : [ctx.resolveImportToFile(current.file.path, moduleSpec)].filter((f): f is FileRecord => !!f);
192
+
193
+ for (const resolvedFile of resolvedFiles) {
194
+ for (const symName of activeNames) {
195
+ if (chain.length >= ctx.maxChainNodes) break;
196
+ const mainSymbol = resolveAstTargetSymbol(ctx, resolvedFile, symName, loadBound);
197
+ if (!mainSymbol) continue;
198
+
199
+ const isCall = !refs.escapes.has(importDecl) &&
200
+ refs.calls.some((c) => c.target === importDecl && (!c.name || c.name === symName));
201
+ const stage = ctx.detectStage(resolvedFile.path, resolvedFile.archetype);
202
+
203
+ if (!chain.some((c) => c.file === resolvedFile.path && c.symbol === mainSymbol.name)) {
204
+ chain.push({
205
+ stage,
206
+ symbol: mainSymbol.name,
207
+ parent_symbol: current.symbol.name,
208
+ depth: current.visualDepth,
209
+ file: resolvedFile.path,
210
+ line: mainSymbol.line_start || 1,
211
+ description: `${stage.toUpperCase()} (${isCall ? "AST call" : "AST import"}): ${mainSymbol.name}`,
212
+ relationship: {
213
+ kind: isCall ? "calls" : "imports",
214
+ derivation: "source",
215
+ source: { file: current.file.path, line: importLine, statement: dep?.statement ?? importDecl.getText(unit.source) },
216
+ reason: isCall ? "ast_call_site" : "ast_referenced_import",
217
+ },
218
+ });
219
+ }
220
+
221
+ const visitKey = `${resolvedFile.path}:${mainSymbol.name}:${mainSymbol.line_start}`;
222
+ if (!visitedNodes.has(visitKey) && current.depth < effectiveMaxDepth) {
223
+ visitedNodes.add(visitKey);
224
+ queue.push({ file: resolvedFile, symbol: mainSymbol, depth: current.depth + 1, visualDepth: current.visualDepth + 1 });
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }
230
+ }
@@ -0,0 +1,72 @@
1
+ export function extractImportedSymbolNames(statement: string): string[] {
2
+ if (!statement) return [];
3
+ const names = new Set<string>();
4
+ const braceMatch = statement.match(/\{([^}]+)\}/);
5
+ if (braceMatch) {
6
+ for (const spec of braceMatch[1].split(",")) {
7
+ const cleaned = spec.trim().replace(/^type\s+/, "");
8
+ const parts = cleaned.split(/\s+as\s+/);
9
+ for (const p of parts) {
10
+ const id = p.trim();
11
+ if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(id)) names.add(id);
12
+ }
13
+ }
14
+ }
15
+ const defaultMatch = statement.match(/^\s*import\s+(?:type\s+)?([A-Za-z_$][A-Za-z0-9_$]*)\s+from\b/);
16
+ if (defaultMatch) names.add(defaultMatch[1]);
17
+ const pyMatch = statement.match(/\bfrom\s+[^\s]+\s+import\s+([^;(\n]+)/);
18
+ if (pyMatch) {
19
+ for (const spec of pyMatch[1].split(",")) {
20
+ const parts = spec.trim().split(/\s+as\s+/);
21
+ const id = (parts[0] || "").trim();
22
+ if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(id)) names.add(id);
23
+ }
24
+ }
25
+ const phpMatch = statement.match(/^\s*use\s+(?:function\s+|const\s+)?[A-Za-z0-9_\\]+\\([A-Za-z0-9_]+)/);
26
+ if (phpMatch) names.add(phpMatch[1]);
27
+ return Array.from(names);
28
+ }
29
+
30
+ /**
31
+ * Detect generic pipeline stage from file path and archetype.
32
+ */
33
+ export function detectPipelineStage(filePath: string, archetype: string): string {
34
+ const norm = filePath.toLowerCase();
35
+
36
+ if (
37
+ archetype === "validation" ||
38
+ archetype === "dto" ||
39
+ /validation|middleware|dto|request|schema/i.test(norm)
40
+ ) {
41
+ return "validation";
42
+ }
43
+
44
+ if (archetype === "controller" || /controller|handler/i.test(norm)) {
45
+ return "controller";
46
+ }
47
+
48
+ if (
49
+ archetype === "service" ||
50
+ archetype === "use_case" ||
51
+ /use-?cases?|interactor|application|workflow/i.test(norm)
52
+ ) {
53
+ return "use_case";
54
+ }
55
+
56
+ if (
57
+ archetype === "model" ||
58
+ archetype === "entity" ||
59
+ /domain|entities|entity|aggregate/i.test(norm)
60
+ ) {
61
+ return "entity";
62
+ }
63
+
64
+ if (
65
+ archetype === "repository" ||
66
+ /repositories|repository|database|persistence|egress|adapter/i.test(norm)
67
+ ) {
68
+ return "repository";
69
+ }
70
+
71
+ return "service";
72
+ }