Documentation
¶
Overview ¶
Package opencode provides an adapter for OpenCode that reads sessions with project indexing and session metadata caching.
Index ¶
- func NewWatcher(sessionDir string) (<-chan adapter.Event, io.Closer, error)
- func ToolInputString(input map[string]any) string
- func ToolOutputString(output any) string
- type Adapter
- func (a *Adapter) Capabilities() adapter.CapabilitySet
- func (a *Adapter) Detect(projectRoot string) (bool, error)
- func (a *Adapter) DiscoverRelatedProjectDirs(mainWorktreePath string) ([]string, error)
- func (a *Adapter) ID() string
- func (a *Adapter) Icon() string
- func (a *Adapter) Messages(sessionID string) ([]adapter.Message, error)
- func (a *Adapter) Name() string
- func (a *Adapter) SearchMessages(sessionID, query string, opts adapter.SearchOptions) ([]adapter.MessageMatch, error)
- func (a *Adapter) Sessions(projectRoot string) ([]adapter.Session, error)
- func (a *Adapter) Usage(sessionID string) (*adapter.UsageStats, error)
- func (a *Adapter) Watch(projectRoot string) (<-chan adapter.Event, io.Closer, error)
- type CacheInfo
- type DiffSummary
- type FileSource
- type FileSourceText
- type Icon
- type Message
- type MessageSummary
- type ModelInfo
- type Part
- type PartTime
- type PathInfo
- type Project
- type Session
- type SessionDiffEntry
- type SessionMetadata
- type SummaryDiff
- type TimeInfo
- type TokenInfo
- type ToolMetadata
- type ToolState
- type ToolTime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWatcher ¶
NewWatcher creates a watcher for OpenCode session changes.
func ToolInputString ¶
ToolInputString extracts a string representation of tool input.
func ToolOutputString ¶
ToolOutputString extracts a string representation of tool output.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements the adapter.Adapter interface for OpenCode sessions.
func (*Adapter) Capabilities ¶
func (a *Adapter) Capabilities() adapter.CapabilitySet
Capabilities returns the supported features.
func (*Adapter) DiscoverRelatedProjectDirs ¶
DiscoverRelatedProjectDirs scans OpenCode project files for worktree paths related to the given main worktree path. This finds conversations from deleted worktrees by checking if stored worktree paths share the same repository base name.
func (*Adapter) Messages ¶
Messages returns all messages for the given session. Uses batch reading to minimize file I/O overhead.
func (*Adapter) SearchMessages ¶
func (a *Adapter) SearchMessages(sessionID, query string, opts adapter.SearchOptions) ([]adapter.MessageMatch, error)
SearchMessages searches message content within a session. Implements adapter.MessageSearcher interface.
func (*Adapter) Sessions ¶
Sessions returns all sessions for the given project, sorted by update time.
type DiffSummary ¶
type DiffSummary struct {
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Files int `json:"files"`
}
DiffSummary holds aggregate diff statistics for a session.
type FileSource ¶
type FileSource struct {
Type string `json:"type"`
Path string `json:"path"`
Text *FileSourceText `json:"text,omitempty"`
}
FileSource holds file reference source information.
type FileSourceText ¶
type FileSourceText struct {
Value string `json:"value"`
Start int `json:"start"`
End int `json:"end"`
}
FileSourceText holds text range for file references.
type Icon ¶
type Icon struct {
Color string `json:"color,omitempty"`
}
Icon holds project icon settings.
type Message ¶
type Message struct {
ID string `json:"id"`
SessionID string `json:"sessionID"`
Role string `json:"role"` // "user" or "assistant"
Time TimeInfo `json:"time"`
ParentID string `json:"parentID,omitempty"`
ModelID string `json:"modelID,omitempty"`
ProviderID string `json:"providerID,omitempty"`
Mode string `json:"mode,omitempty"`
Agent string `json:"agent,omitempty"`
Path *PathInfo `json:"path,omitempty"`
Cost float64 `json:"cost,omitempty"`
Tokens *TokenInfo `json:"tokens,omitempty"`
Finish string `json:"finish,omitempty"`
Summary *MessageSummary `json:"summary,omitempty"`
Model *ModelInfo `json:"model,omitempty"` // Alternative model location for user messages
}
Message represents an OpenCode message from storage/message/{sessionID}/{messageID}.json.
type MessageSummary ¶
type MessageSummary struct {
Title string `json:"title,omitempty"`
Diffs []SummaryDiff `json:"diffs,omitempty"`
}
MessageSummary holds message summary information.
type Part ¶
type Part struct {
ID string `json:"id"`
SessionID string `json:"sessionID"`
MessageID string `json:"messageID"`
Type string `json:"type"` // text, tool, step-start, step-finish, file, patch, compaction
Time *PartTime `json:"time,omitempty"`
// Text part fields
Text string `json:"text,omitempty"`
// Tool part fields
CallID string `json:"callID,omitempty"`
Tool string `json:"tool,omitempty"`
State *ToolState `json:"state,omitempty"`
// Step part fields
Snapshot string `json:"snapshot,omitempty"`
Reason string `json:"reason,omitempty"`
Cost float64 `json:"cost,omitempty"`
Tokens *TokenInfo `json:"tokens,omitempty"`
// File part fields (type: "file")
Mime string `json:"mime,omitempty"`
Filename string `json:"filename,omitempty"`
URL string `json:"url,omitempty"`
Source *FileSource `json:"source,omitempty"`
// Patch part fields (type: "patch")
Hash string `json:"hash,omitempty"`
Files []string `json:"files,omitempty"`
}
Part represents a content part from storage/part/{messageID}/{partID}.json.
type Project ¶
type Project struct {
ID string `json:"id"`
Worktree string `json:"worktree"`
VCS string `json:"vcs,omitempty"`
Time TimeInfo `json:"time"`
Icon *Icon `json:"icon,omitempty"`
}
Project represents an OpenCode project from storage/project/{id}.json.
type Session ¶
type Session struct {
ID string `json:"id"`
Version string `json:"version,omitempty"`
ProjectID string `json:"projectID"`
Directory string `json:"directory"`
Title string `json:"title,omitempty"`
ParentID string `json:"parentID,omitempty"` // Non-empty for sub-agents
Time TimeInfo `json:"time"`
Summary *DiffSummary `json:"summary,omitempty"`
}
Session represents an OpenCode session from storage/session/{projectID}/{sessionID}.json.
type SessionDiffEntry ¶
type SessionDiffEntry struct {
File string `json:"file"`
Before string `json:"before"`
After string `json:"after"`
Additions *int `json:"additions"` // nil for binary files
Deletions *int `json:"deletions"`
}
SessionDiffEntry represents a file diff from storage/session_diff/{sessionID}.json.
type SessionMetadata ¶
type SessionMetadata struct {
Path string
SessionID string
ProjectID string
Title string
ParentID string
FirstMsg time.Time
LastMsg time.Time
MsgCount int
TotalTokens int
EstCost float64
PrimaryModel string
Additions int
Deletions int
FileCount int
FirstUserMessage string // Content of the first user message (for title fallback)
}
SessionMetadata holds aggregated metadata for adapter.Session mapping.
type SummaryDiff ¶
type SummaryDiff struct {
File string `json:"file"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
}
SummaryDiff represents a diff entry in message summary.
type TimeInfo ¶
type TimeInfo struct {
Created int64 `json:"created,omitempty"`
Updated int64 `json:"updated,omitempty"`
Completed int64 `json:"completed,omitempty"`
}
TimeInfo holds timestamp information in Unix milliseconds.
func (TimeInfo) CompletedTime ¶
CompletedTime converts completed timestamp to time.Time in local timezone.
func (TimeInfo) CreatedTime ¶
CreatedTime converts created timestamp to time.Time in local timezone.
func (TimeInfo) UpdatedTime ¶
UpdatedTime converts updated timestamp to time.Time in local timezone.
type TokenInfo ¶
type TokenInfo struct {
Input int `json:"input,omitempty"`
Output int `json:"output,omitempty"`
Reasoning int `json:"reasoning,omitempty"`
Cache *CacheInfo `json:"cache,omitempty"`
}
TokenInfo holds token usage information.
type ToolMetadata ¶
type ToolMetadata struct {
Output string `json:"output,omitempty"`
Exit int `json:"exit,omitempty"`
Description string `json:"description,omitempty"`
}
ToolMetadata holds additional tool metadata.
type ToolState ¶
type ToolState struct {
Status string `json:"status"` // "completed", "pending", etc.
Input map[string]any `json:"input,omitempty"`
Output any `json:"output,omitempty"` // Can be string or object
Title string `json:"title,omitempty"`
Metadata *ToolMetadata `json:"metadata,omitempty"`
Time *ToolTime `json:"time,omitempty"`
}
ToolState holds the state of a tool call.