( args: Record<string, unknown>, ctx: ToolContext )
| 24 | }; |
| 25 | |
| 26 | export async function handle( |
| 27 | args: Record<string, unknown>, |
| 28 | ctx: ToolContext |
| 29 | ): Promise<ToolResponse> { |
| 30 | const { scope } = args as { scope?: string }; |
| 31 | |
| 32 | try { |
| 33 | // Try relationships sidecar first (preferred), then intelligence |
| 34 | let graphDataSource: { |
| 35 | imports?: Record<string, string[]>; |
| 36 | exports?: Record<string, FileExport[]>; |
| 37 | } | null = null; |
| 38 | let graphStats: unknown = null; |
| 39 | |
| 40 | const relationshipsPath = path.join( |
| 41 | path.dirname(ctx.paths.intelligence), |
| 42 | RELATIONSHIPS_FILENAME |
| 43 | ); |
| 44 | try { |
| 45 | const relationshipsContent = await fs.readFile(relationshipsPath, 'utf-8'); |
| 46 | const relationships = JSON.parse(relationshipsContent); |
| 47 | if (relationships?.graph) { |
| 48 | graphDataSource = relationships.graph; |
| 49 | graphStats = relationships.stats; |
| 50 | } |
| 51 | } catch { |
| 52 | // Relationships sidecar not available, try intelligence |
| 53 | } |
| 54 | |
| 55 | if (!graphDataSource) { |
| 56 | const intelligencePath = ctx.paths.intelligence; |
| 57 | const content = await fs.readFile(intelligencePath, 'utf-8'); |
| 58 | const intelligence = JSON.parse(content); |
| 59 | if (intelligence.internalFileGraph) { |
| 60 | graphDataSource = intelligence.internalFileGraph; |
| 61 | graphStats = intelligence.internalFileGraph.stats; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if (!graphDataSource) { |
| 66 | return { |
| 67 | content: [ |
| 68 | { |
| 69 | type: 'text', |
| 70 | text: JSON.stringify( |
| 71 | { |
| 72 | status: 'error', |
| 73 | message: |
| 74 | 'Internal file graph not found. Please run refresh_index to rebuild the index with cycle detection support.' |
| 75 | }, |
| 76 | null, |
| 77 | 2 |
| 78 | ) |
| 79 | } |
| 80 | ] |
| 81 | }; |
| 82 | } |
| 83 |
nothing calls this directly
no test coverage detected