MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / formatContextAsJson

Function formatContextAsJson

src/context/formatter.ts:105–127  ·  view source on GitHub ↗
(context: TaskContext)

Source from the content-addressed store, hash-verified

103 * Returns a structured JSON representation suitable for programmatic use.
104 */
105export 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

Callers 1

buildContextMethod · 0.90

Calls 2

mapMethod · 0.80
fromMethod · 0.80

Tested by

no test coverage detected