(context: TaskContext)
| 103 | * Returns a structured JSON representation suitable for programmatic use. |
| 104 | */ |
| 105 | export function formatContextAsJson(context: TaskContext): string { |
| 106 | // Convert Map to array for JSON serialization |
| 107 | const serializable = { |
| 108 | query: context.query, |
| 109 | summary: context.summary, |
| 110 | entryPoints: context.entryPoints.map(serializeNode), |
| 111 | nodes: Array.from(context.subgraph.nodes.values()).map(serializeNode), |
| 112 | edges: context.subgraph.edges.map(serializeEdge), |
| 113 | codeBlocks: context.codeBlocks.map((block) => ({ |
| 114 | filePath: block.filePath, |
| 115 | startLine: block.startLine, |
| 116 | endLine: block.endLine, |
| 117 | language: block.language, |
| 118 | content: block.content, |
| 119 | nodeName: block.node?.name, |
| 120 | nodeKind: block.node?.kind, |
| 121 | })), |
| 122 | relatedFiles: context.relatedFiles, |
| 123 | stats: context.stats, |
| 124 | }; |
| 125 | |
| 126 | return JSON.stringify(serializable, null, 2); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Format a subgraph as an ASCII tree structure |
no test coverage detected