Skip to main content

Module provider

Module provider 

Source
Expand description

Implementation of toolpath-convo traits for opencode sessions.

Unlike Codex’s streaming event model, opencode’s parts are self-contained: each crate::types::ToolPart already carries both the tool input and the tool output/error in its ToolState. So the mapping is mostly a direct translation per part, with minimal cross-part assembly:

  1. For each user Message, emit a Turn with role: User whose text is the concatenation of the message’s text parts.
  2. For each assistant Message, emit a Turn with role: Assistant:
    • text ← concatenation of its text parts.
    • thinking ← concatenation of its reasoning parts.
    • tool_uses ← one ToolInvocation per tool part.
    • token_usage ← summed across all step-finish parts (each is a per-step delta). Falls back to the message-level tokens field if no step-finish parts exist.
    • extra["opencode"]["snapshots"] ← ordered list of snapshot SHAs from step-start/step-finish/snapshot parts, used by the derive layer to fetch file diffs.
    • extra["opencode"]["patches"] ← any patch parts (their {hash, files} records).
  3. Non-turn parts land in ConversationView.events: compaction, retry, unknown types.
  4. subtask parts are captured on the turn’s delegations (empty-turn list — the sub-agent’s own session lives under its own id, linked by session.parent_id).

Structs§

OpencodeConvo
Provider for opencode sessions.

Functions§

native_name
Reverse of tool_category: pick opencode’s native tool name for a given category, disambiguating by args shape where needed (e.g. edit vs write, glob vs grep).
to_view
Convert a parsed opencode Session to the provider-agnostic ConversationView shape. File mutations from the snapshot git repo are not populated; use to_view_with_resolver when you have one.
to_view_with_resolver
Like to_view but opens opencode’s snapshot git repository via the resolver and pre-resolves each turn’s file mutations against the snapshot pair. Falls back silently when the repo isn’t present.
tool_category
Map an opencode tool name to toolpath’s category ontology.