opencode

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package opencode provides an agent provider for opencode sessions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageData

type MessageData struct {
	ID        string `json:"id"`
	SessionID string `json:"sessionID"`
	Role      string `json:"role"`
	Time      struct {
		Created int64 `json:"created"` // Unix timestamp in milliseconds
	} `json:"time"`
	Summary struct {
		Title string `json:"title"`
	} `json:"summary"`
	Agent string `json:"agent,omitempty"`
	Model struct {
		ProviderID string `json:"providerID"`
		ModelID    string `json:"modelID"`
	} `json:"model,omitempty"`
}

MessageData represents a message in the session

type OpenCodeAgent

type OpenCodeAgent struct {
	// contains filtered or unexported fields
}

OpenCodeAgent implements the Agent interface for opencode sessions

func NewOpenCodeAgent

func NewOpenCodeAgent(storagePath, sessionFilePath string) (*OpenCodeAgent, error)

NewOpenCodeAgent creates a new OpenCodeAgent from a session JSON file

func (*OpenCodeAgent) CurrentTask

func (a *OpenCodeAgent) CurrentTask() string

CurrentTask returns the current task description

func (*OpenCodeAgent) Directory

func (a *OpenCodeAgent) Directory() string

Directory returns the working directory

func (*OpenCodeAgent) ID

func (a *OpenCodeAgent) ID() string

ID returns the agent's unique identifier

func (*OpenCodeAgent) IsBackground

func (a *OpenCodeAgent) IsBackground() bool

func (*OpenCodeAgent) LastActivity

func (a *OpenCodeAgent) LastActivity() time.Time

LastActivity returns the last activity time

func (*OpenCodeAgent) LastError

func (a *OpenCodeAgent) LastError() error

LastError returns the last error

func (*OpenCodeAgent) LoadFullHistory

func (a *OpenCodeAgent) LoadFullHistory()

func (*OpenCodeAgent) Metrics

func (a *OpenCodeAgent) Metrics() agent.Metrics

Metrics returns the agent's metrics

func (*OpenCodeAgent) Name

func (a *OpenCodeAgent) Name() string

Name returns the agent's display name

func (*OpenCodeAgent) Output

func (a *OpenCodeAgent) Output() io.Reader

Output returns the output stream (lazy-loads history on first access)

func (*OpenCodeAgent) ParentID

func (a *OpenCodeAgent) ParentID() string

func (*OpenCodeAgent) Pause

func (a *OpenCodeAgent) Pause() error

Pause pauses the agent (not supported)

func (*OpenCodeAgent) ProjectID

func (a *OpenCodeAgent) ProjectID() string

ProjectID returns the project identifier

func (*OpenCodeAgent) Refresh

func (a *OpenCodeAgent) Refresh() error

Refresh refreshes the agent's state from disk

func (*OpenCodeAgent) Resume

func (a *OpenCodeAgent) Resume() error

Resume resumes the agent (not supported)

func (*OpenCodeAgent) SendInput

func (a *OpenCodeAgent) SendInput(input string) error

SendInput sends input to the agent by appending to the session via CLI

func (*OpenCodeAgent) StartTime

func (a *OpenCodeAgent) StartTime() time.Time

StartTime returns when the agent started

func (*OpenCodeAgent) Status

func (a *OpenCodeAgent) Status() agent.Status

Status returns the current status

func (*OpenCodeAgent) Terminate

func (a *OpenCodeAgent) Terminate() error

Terminate terminates the agent

func (*OpenCodeAgent) Type

func (a *OpenCodeAgent) Type() string

Type returns the agent type

type PartData

type PartData struct {
	ID        string `json:"id"`
	MessageID string `json:"messageID"`
	SessionID string `json:"sessionID"`
	Type      string `json:"type"` // "text", "tool-invocation", etc.
	Time      struct {
		Created int64 `json:"created"`
	} `json:"time"`
	Text       string `json:"text,omitempty"`
	ToolName   string `json:"toolName,omitempty"`
	ToolCallID string `json:"toolCallId,omitempty"`
	State      string `json:"state,omitempty"` // "running", "success", "error"
}

PartData represents a message part (content, tool calls, etc.)

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements the agent.Provider interface for opencode

func NewProvider

func NewProvider(storagePath string, watchInterval time.Duration, maxAge time.Duration) *Provider

NewProvider creates a new opencode provider

func (*Provider) ChildCount

func (p *Provider) ChildCount(parentID string) int

ChildCount returns the number of child agents for a given parent ID

func (*Provider) Discover

func (p *Provider) Discover(ctx context.Context) ([]agent.Agent, error)

Discover discovers all opencode sessions

func (*Provider) Get

func (p *Provider) Get(id string) (agent.Agent, error)

Get returns an agent by ID

func (*Provider) GetChildren

func (p *Provider) GetChildren(parentID string) []agent.Agent

GetChildren returns all child agents for a given parent ID

func (*Provider) List

func (p *Provider) List() []agent.Agent

List returns all agents

func (*Provider) ListPrimary

func (p *Provider) ListPrimary() []agent.Agent

ListPrimary returns only primary agents (agents without a parent)

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name

func (*Provider) SendInput

func (p *Provider) SendInput(id string, input string) error

SendInput sends input to an agent

func (*Provider) Spawn

func (p *Provider) Spawn(ctx context.Context, config agent.SpawnConfig) (agent.Agent, error)

Spawn spawns a new opencode session

func (*Provider) Terminate

func (p *Provider) Terminate(id string) error

Terminate terminates an agent

func (*Provider) Type

func (p *Provider) Type() string

Type returns the provider type

func (*Provider) Watch

func (p *Provider) Watch(ctx context.Context) (<-chan agent.Event, error)

Watch watches for changes in opencode sessions

type SessionData

type SessionData struct {
	ID        string `json:"id"`
	Version   string `json:"version"`
	ProjectID string `json:"projectID"`
	Directory string `json:"directory"`
	ParentID  string `json:"parentID,omitempty"`
	Title     string `json:"title"`
	Time      struct {
		Created int64 `json:"created"` // Unix timestamp in milliseconds
		Updated int64 `json:"updated"` // Unix timestamp in milliseconds
	} `json:"time"`
	Summary struct {
		Additions int `json:"additions"`
		Deletions int `json:"deletions"`
		Files     int `json:"files"`
	} `json:"summary"`
}

SessionData represents the opencode session.json structure

Jump to

Keyboard shortcuts

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