@molecule/api-agent-transcript-opencode

Provider bond · agent-transcript · API (Node) · v1.0.1 · Apache-2.0

Reads OpenCode session exports (opencode export) into a normalized agent session

npm install @molecule/api-agent-transcript-opencode

npm · Source on GitHub · Implements @molecule/api-agent-transcript

How it works

@molecule/api-agent-transcript-opencode is a provider bond on the API (Node) side: it implements the agent-transcript core interface (@molecule/api-agent-transcript) with a concrete vendor or library behind it.

Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.

import { readFileSync } from 'node:fs'
import { readTranscript, setProvider } from '@molecule/api-agent-transcript'
import { provider } from '@molecule/api-agent-transcript-opencode'

setProvider(provider)
// opencode export ses_01k… > session.json
const file = 'session.json'
const session = readTranscript({ text: readFileSync(file, 'utf8'), fileName: file })
console.log(session.model, session.harnessVersion)

Works with: @molecule/api-agent-transcript

Reference

OpenCode transcript reader for @molecule/api-agent-transcript.

Reads a session exported with opencode export [sessionID] > session.json into a normalized AgentSession: what you typed, the replies with the model that wrote each, and the files the write, edit and apply_patch tools wrote.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { readFileSync } from 'node:fs'
import { readTranscript, setProvider } from '@molecule/api-agent-transcript'
import { provider } from '@molecule/api-agent-transcript-opencode'

setProvider(provider)
// opencode export ses_01k… > session.json
const file = 'session.json'
const session = readTranscript({ text: readFileSync(file, 'utf8'), fileName: file })
console.log(session.model, session.harnessVersion)

Type

provider

Installation

npm install @molecule/api-agent-transcript-opencode @molecule/api-agent-transcript

API

Functions

looksLikeOpencodeExport(text)

Whether a text is an opencode export session.

function looksLikeOpencodeExport(text: string): boolean
  • text — The file's text.

Returns: True on a positive match.

writesOfPatch(patch)

The files an apply_patch call wrote.

function writesOfPatch(patch: string): AgentFileWrite[]
  • patch — The patch text.

Returns: The writes.

readOpencodeExport(text)

Read an opencode export session.

function readOpencodeExport(text: string): AgentSession
  • text — The export's text.

Returns: The normalized session.

Constants

provider

Reads what opencode export prints.

const provider: AgentTranscriptReader

Core Interface

Implements @molecule/api-agent-transcript interface.

Bond Wiring

Setup function to register this provider with the core interface:

import { setProvider } from '@molecule/api-agent-transcript'
import { provider } from '@molecule/api-agent-transcript-opencode'

export function setupAgentTranscriptOpencode(): void {
  setProvider(provider)
}

Injection Notes

Requirements

Peer dependencies:

  • @molecule/api-agent-transcript ^1.0.0

Runtime Dependencies

  • @molecule/api-agent-transcript

  • Export with opencode export, not from the storage directory. The export is one JSON object holding the session and every message with its parts; OpenCode's on-disk storage splits them across many files.

  • --sanitize exports read the same way; only the redacted strings differ.

  • User turns leave out synthetic parts (file contents OpenCode attaches for an @file mention) and ignored parts.

  • model on each reply is its modelID; the session's model is set when every reply used the same one. harnessVersion is the session's version.

  • Files: only tool calls whose state is completed count — write is the whole file, edit its newString, apply_patch each added file whole and each update's added lines.

  • Format verified 2026-09-29 against the OpenCode source (packages/schema/src/v1/session.ts, cli/cmd/export.ts).