convert

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package convert converts OpenCode's sessions into the Agent Session Format: a data directory's storage files, its database's V1 tables and its V2 tables, each session converted once, from the copy that holds the most of what its model saw. docs/formats/opencode.md is the mapping and lists every finding code it reports.

Index

Constants

View Source
const Harness = "opencode"

Harness is the harness name the sessions carry.

View Source
const Source = "opencode"

Source is the format name and the namespace of every extension member and custom entry this converter writes.

View Source
const Unit = "records"

Unit names what a report's tally counts: a storage file or a database row, each a session, a message, a part or a V2 message.

Variables

This section is empty.

Functions

func Convert

func Convert(opts Options, stores ...opencode.Store) (*agentimport.Result, error)

Convert converts every session the stores hold: a data directory's storage tree and its database, or either alone. A session held in more than one copy is converted from one, and each other copy is reported. Each session that is no sub-agent of another is converted with its sub-agents after it. One report covers them all. Only a failure to read a store fails the conversion: a session that cannot be converted is a finding.

func ConvertFile

func ConvertFile(path string, opts Options) (*agentimport.Result, error)

ConvertFile converts every session of the OpenCode store path names: a data directory, such as ~/.local/share/opencode, with its storage/ tree and its opencode.db, a file in one, or a database file. The database is read once, from one copy, removed when the conversion returns.

Types

type Options

type Options struct {
	// Slim drops what the model never saw and the session format has
	// no member for, rather than keeping it in namespaced members: the
	// session record, the members of messages and parts the conversion
	// does not map, snapshots and patches, OpenCode 2's queued input.
	// Each drop is still reported.
	Slim bool
	// Derive writes the entries the module's derivation rules infer
	// from the converted path, each marked agentimport:derived: what a
	// shell call published and the revision a commit printed
	// (docs/plans/agentimport.md).
	Derive bool
	// Alone converts each session without its sub-agents, which are
	// otherwise converted with the session that ran them.
	Alone bool
	// OpenDatabase opens an OpenCode database for ConvertFile:
	// opencode/sqlite's OpenStore, which this package does not import,
	// so that it builds without a database driver. ConvertFile refuses
	// a store holding a database when it is nil.
	OpenDatabase func(path string) (opencode.Database, error)
}

Options tune a conversion. The zero value keeps everything.

type Stores

type Stores struct {
	Root   string
	Stores []opencode.Store
	// DB is the database, when there is one.
	DB opencode.Database
}

Stores are the stores of one OpenCode store path: a data directory's storage tree and database, or a database alone.

func OpenStores

func OpenStores(path string, opts Options) (*Stores, error)

OpenStores opens the stores path names, its database through opts.OpenDatabase. Close releases them.

func (*Stores) Close

func (st *Stores) Close() error

Close closes the database, removing its copy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL