MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / enrich_opencode_turn

Method enrich_opencode_turn

atomic-agent/src/turn/orchestrator/provenance.rs:615–763  ·  view source on GitHub ↗

OpenCode: recover transcript, reasoning, and response from OpenCode's local SQLite store and fold them into the session and the stop payload before recording. OpenCode writes no transcript file, so its sessions never carry a `transcript_path`, and thin plugin versions forward only session/model metadata. Without this step an OpenCode turn could never carry `agent_turn` data, reasoning, or an `llm

(
        &self,
        session: &mut AgentSession,
        event: &mut TurnEvent,
    )

Source from the content-addressed store, hash-verified

613 /// Best-effort: any failure leaves the turn recording what the plugin
614 /// sent.
615 pub(crate) fn enrich_opencode_turn(
616 &self,
617 session: &mut AgentSession,
618 event: &mut TurnEvent,
619 ) -> AgentResult<()> {
620 if session.agent_name != "opencode" {
621 return Ok(());
622 }
623
624 let Some(data) = transcript::opencode::read_turn(&session.session_id, &self.repo_root)
625 else {
626 return Ok(());
627 };
628
629 // 1. Transcript file → transcript_path (unblocks agent_turn).
630 // Rewritten on every turn (whole-session record); a plugin-supplied
631 // transcript path is never clobbered.
632 if !data.transcript_jsonl.is_empty() {
633 let dir = self.session_graph_dir(&session.session_id);
634 let synthesized = dir.join("opencode-transcript.jsonl");
635 let ours = session.transcript_path.is_none()
636 || session.transcript_path.as_deref() == Some(synthesized.as_path());
637 if ours {
638 let _ = std::fs::create_dir_all(&dir);
639 match std::fs::write(&synthesized, &data.transcript_jsonl) {
640 Ok(()) => session.set_transcript_path(&synthesized),
641 Err(e) => log::warn!(
642 "Failed to write opencode transcript for session {}: {}",
643 session.session_id,
644 e
645 ),
646 }
647 }
648 }
649
650 // 2. Stop-payload fields the plugin didn't send.
651 let Some(raw) = event.raw_json.as_mut() else {
652 return Ok(());
653 };
654 let Some(obj) = raw.as_object_mut() else {
655 return Ok(());
656 };
657
658 if !obj.contains_key("reasoning_blocks")
659 && !obj.contains_key("reasoning_text")
660 && !data.reasoning_blocks.is_empty()
661 {
662 let blocks: Vec<serde_json::Value> = data
663 .reasoning_blocks
664 .iter()
665 .map(|b| {
666 serde_json::json!({
667 "text": b.text,
668 "duration_ms": b.duration_ms,
669 })
670 })
671 .collect();
672 obj.insert(

Callers 1

handle_turn_endMethod · 0.80

Calls 14

read_turnFunction · 0.85
stable_journal_idFunction · 0.85
session_graph_dirMethod · 0.80
is_noneMethod · 0.80
set_transcript_pathMethod · 0.80
contains_keyMethod · 0.80
timestamp_millisMethod · 0.80
commit_journal_draftsMethod · 0.80
writeFunction · 0.50
is_emptyMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected