(layout: GraphData | undefined, selected: GraphNode, project: string, snapshotId: string)
| 12 | |
| 13 | /** Keep selected hierarchy evidence usable when its symbol is outside the loaded layout. */ |
| 14 | export function selectedGraphContext(layout: GraphData | undefined, selected: GraphNode, project: string, snapshotId: string): BrowserChatContext { |
| 15 | const canonical = layoutNodeForSelection(layout, selected); |
| 16 | if (canonical) { |
| 17 | const context = galaxyNodeContext(layout, canonical.id, project, snapshotId); |
| 18 | if (context) return context; |
| 19 | } |
| 20 | const truncatedFields: string[] = []; |
| 21 | const field = (value: string | undefined, name: string) => { |
| 22 | if (value === undefined || value.length <= 256) return value; |
| 23 | truncatedFields.push(name); |
| 24 | return `${value.slice(0, 256)}…`; |
| 25 | }; |
| 26 | const selectedNode = { |
| 27 | name: field(selected.name, 'name'), |
| 28 | qualifiedName: field(selected.qualified_name, 'qualifiedName'), |
| 29 | filePath: field(selected.file_path, 'filePath'), |
| 30 | startLine: selected.start_line, |
| 31 | endLine: selected.end_line, |
| 32 | kind: field(selected.label, 'kind'), |
| 33 | }; |
| 34 | return { |
| 35 | id: snapshotId, |
| 36 | label: `Graph node · ${graphNodeName(selected).slice(0, 60)}`, |
| 37 | text: JSON.stringify({ |
| 38 | kind: 'graph-selection-snapshot', |
| 39 | source: 'selected-graph-node', |
| 40 | project: field(project, 'project'), |
| 41 | selectedNode, |
| 42 | loadedLayout: 'This symbol is outside the loaded layout; its displayed identity and source location are retained.', |
| 43 | relationships: { state: 'unavailable', reason: 'The loaded layout does not contain this selected symbol.' }, |
| 44 | indexCoverage: { state: 'unavailable' }, |
| 45 | generation: { state: 'unavailable' }, |
| 46 | truncatedFields, |
| 47 | limitations: 'Selection metadata only. No source code or relationships were fetched. Render IDs are omitted because they are not index identities. Absence from the loaded layout does not imply absent code or calls.', |
| 48 | }, null, 2), |
| 49 | }; |
| 50 | } |
no test coverage detected