* Extract code from a node's source file
(node: Node)
| 1420 | * Extract code from a node's source file |
| 1421 | */ |
| 1422 | private async extractNodeCode(node: Node): Promise<string | null> { |
| 1423 | // SECURITY (#383): a config-leaf node's on-disk line is `key = <secret>`. |
| 1424 | // Return the KEY only — never read the value off disk. This closes the |
| 1425 | // includeCode / buildContext code-block path, mirroring the explore source |
| 1426 | // renderer; an agent that genuinely needs a value can read the file itself. |
| 1427 | if (isConfigLeafNode(node)) { |
| 1428 | return node.signature || node.qualifiedName || node.name; |
| 1429 | } |
| 1430 | |
| 1431 | const filePath = validatePathWithinRoot(this.projectRoot, node.filePath); |
| 1432 | |
| 1433 | if (!filePath || !fs.existsSync(filePath)) { |
| 1434 | return null; |
| 1435 | } |
| 1436 | |
| 1437 | try { |
| 1438 | const content = fs.readFileSync(filePath, 'utf-8'); |
| 1439 | const lines = content.split('\n'); |
| 1440 | |
| 1441 | // Extract lines (1-indexed to 0-indexed) |
| 1442 | const startIdx = Math.max(0, node.startLine - 1); |
| 1443 | const endIdx = Math.min(lines.length, node.endLine); |
| 1444 | |
| 1445 | return lines.slice(startIdx, endIdx).join('\n'); |
| 1446 | } catch (error) { |
| 1447 | logDebug('Failed to extract code from node', { nodeId: node.id, filePath: node.filePath, error: String(error) }); |
| 1448 | return null; |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | /** |
| 1453 | * Get entry points from a subgraph (the root nodes) |
no test coverage detected