Inject an LLM response node into the ProvenanceAccumulator. The agent's closing message for the turn — what it *concluded*, as opposed to the tool-derived nodes that capture what it *did*. Sources, in priority order: 1. The stop payload, when the agent sends the response there (`last_assistant_message` for codex/grok, `prompt_response` for gemini-cli, `response` for plugins that supply it). 2. T
(
&mut self,
session_id: &str,
session: &AgentSession,
event: &TurnEvent,
)
| 555 | /// |
| 556 | /// Agents with neither source available get no node. |
| 557 | pub(crate) fn inject_response_node( |
| 558 | &mut self, |
| 559 | session_id: &str, |
| 560 | session: &AgentSession, |
| 561 | event: &TurnEvent, |
| 562 | ) { |
| 563 | let raw = event.raw_json.as_ref(); |
| 564 | let from_payload = |key: &str| -> Option<String> { |
| 565 | raw.and_then(|r| r.get(key)) |
| 566 | .and_then(|v| v.as_str()) |
| 567 | .map(|s| s.trim().to_string()) |
| 568 | .filter(|s| !s.is_empty()) |
| 569 | }; |
| 570 | |
| 571 | let response = from_payload("last_assistant_message") |
| 572 | .or_else(|| from_payload("prompt_response")) |
| 573 | .or_else(|| from_payload("response")) |
| 574 | .or_else(|| { |
| 575 | let path = session.transcript_path.as_ref()?; |
| 576 | let data = std::fs::read(path).ok()?; |
| 577 | transcript::last_assistant_text( |
| 578 | &data, |
| 579 | transcript::format_for_agent(&session.agent_name), |
| 580 | ) |
| 581 | }); |
| 582 | |
| 583 | let Some(response) = response else { |
| 584 | return; |
| 585 | }; |
| 586 | |
| 587 | let timestamp = event.timestamp.timestamp_millis(); |
| 588 | self.with_accumulator(session_id, |acc| { |
| 589 | acc.append_llm_response(&response, timestamp); |
| 590 | true |
| 591 | }); |
| 592 | } |
| 593 | |
| 594 | /// OpenCode: recover transcript, reasoning, and response from |
| 595 | /// OpenCode's local SQLite store and fold them into the session and |