opencode

package
v1.118.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "opencode"

Name is the provider identifier emitted to evidence and used as the key in SessionRecord.Provider. Kept as an exported constant so CLI wiring can refer to it without instantiating the provider.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct{}

Provider implements trace.Provider for opencode sessions.

func New

func New() *Provider

New creates a new opencode provider.

func (*Provider) AnnouncePromptSubmit added in v1.116.0

func (p *Provider) AnnouncePromptSubmit(reminder string) error

AnnouncePromptSubmit writes the prompt-submit response that the Chainloop plugin reads, in the same shape as the session-start one. The plugin posts the reminder to the session as a context-only message.

func (*Provider) AnnounceSessionStart added in v1.114.0

func (p *Provider) AnnounceSessionStart(msg trace.SessionStartMessage) error

AnnounceSessionStart writes the session-start response that the Chainloop plugin reads. The plugin posts the instruction to the session as a context-only message (no model reply), which is how the model receives it. opencode has no channel that shows a message to the user, so the banner is dropped.

A message with no instruction writes nothing, and the plugin posts nothing.

func (*Provider) AnnounceToUser added in v1.109.1

func (p *Provider) AnnounceToUser(_ string) error

AnnounceToUser is unsupported for OpenCode until its plugin's response shape for surfacing a message is verified against a live session, the way Claude Code's was. The hook after a shell command already fires, so wiring this up later is a change to this method alone.

func (*Provider) CaptureFileSnapshot

func (p *Provider) CaptureFileSnapshot(store *state.Store, input *trace.HookInput) error

CaptureFileSnapshot reads the file at input.FilePath and stores its content under the store's snapshots/ directory so the post-tool-use handler can compute line-range diffs after the edit. A missing file (e.g. write creating a new file) is treated as a non-error.

func (*Provider) CleanupAfterEdit

func (p *Provider) CleanupAfterEdit(store *state.Store, input *trace.HookInput)

CleanupAfterEdit removes the per-edit snapshot.

func (*Provider) CopySessionData

func (p *Provider) CopySessionData(store *state.Store, loc trace.SessionLocation) error

CopySessionData runs the opencode export command for the session (see exportArgs) and streams the JSON output directly to the store's raw/<sanitized-id>.jsonl so pre-push can parse it independently of opencode's own storage. stdout is redirected to the destination file rather than a pipe: opencode (Node.js) doesn't reliably flush stdout to pipes, causing truncation at pipe buffer boundaries, but a regular file destination is safe. Fails gracefully (returns nil) when the opencode binary is missing or the export fails — the session is skipped rather than blocking the push, and any partially-written file is removed.

func (*Provider) HooksInstalled added in v1.118.0

func (p *Provider) HooksInstalled(repoRoot string) (bool, error)

HooksInstalled reports whether the plugin file is present. The file is entirely chainloop-owned, so its presence is the installation.

func (*Provider) InstallHooks

func (p *Provider) InstallHooks(repoRoot string) error

InstallHooks writes the opencode plugin file with all hooks including session.deleted.

func (*Provider) InstallHooksForTraceRun

func (p *Provider) InstallHooksForTraceRun(repoRoot string) error

InstallHooksForTraceRun writes the plugin file without the session.deleted handler; trace run drives end-of-session itself.

func (*Provider) IsCommandTool

func (p *Provider) IsCommandTool(toolName string) bool

IsCommandTool returns true if the named tool runs a shell command.

func (*Provider) IsFileWritingTool

func (p *Provider) IsFileWritingTool(toolName string) bool

IsFileWritingTool returns true if the named tool modifies files on disk.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the agent identifier.

func (*Provider) NewSkillLoads added in v1.118.0

func (p *Provider) NewSkillLoads(_ *state.Store, input *trace.HookInput) []string

NewSkillLoads returns the skill folder that the plugin put in the payload of the hook after a skill tool call. OpenCode tells the folder in the tool result, so no transcript is read.

func (*Provider) ParseSession

func (p *Provider) ParseSession(_ context.Context, opts *trace.ParseOpts) (*aicodingsession.Evidence, error)

ParseSession reads the copied export JSON for sessionID and returns structured evidence.

func (*Provider) ReadHookInput

func (p *Provider) ReadHookInput(r io.Reader) (*trace.HookInput, error)

ReadHookInput reads and parses the opencode hook JSON from the given reader. The plugin pipes JSON to stdin with fields: session_id, hook_event_name, tool_name, file_path. A relative file_path is resolved against the working directory.

func (*Provider) ResolveBeforeContent

func (p *Provider) ResolveBeforeContent(store *state.Store, input *trace.HookInput, _ []byte) []byte

ResolveBeforeContent returns the snapshot saved by CaptureFileSnapshot.

func (*Provider) SessionSkills added in v1.118.0

func (p *Provider) SessionSkills(opts *trace.ParseOpts) ([]trace.SkillUse, []string, error)

SessionSkills returns the skills that the session used, from the copied export. A model start is a completed call to the skill tool. OpenCode has no slash command that starts a skill, so the user count stays at zero. A subagent runs in a child session, which has its own export, so the count of subagent uses stays at zero too.

func (*Provider) SettingsFile

func (p *Provider) SettingsFile(repoRoot string) string

SettingsFile returns the absolute path to the plugin file for the given repo.

func (*Provider) SkillRoots added in v1.118.0

func (p *Provider) SkillRoots(repoRoot string) skill.Roots

SkillRoots returns the OpenCode folders that tell where a skill came from. OpenCode reads project skills from .opencode/skills, .claude/skills and .agents/skills in the repository, and user skills from the same folders in the user's configuration.

func (*Provider) SupportsPromptReminder added in v1.116.0

func (p *Provider) SupportsPromptReminder() bool

SupportsPromptReminder is true for opencode: the plugin posts the reminder to the session at each user message.

func (*Provider) SupportsSessionStartBanner added in v1.114.0

func (p *Provider) SupportsSessionStartBanner() bool

SupportsSessionStartBanner is false for opencode: the plugin has no channel to the user.

func (*Provider) SupportsSessionStartInstruction added in v1.114.0

func (p *Provider) SupportsSessionStartInstruction() bool

SupportsSessionStartInstruction is true for opencode: the plugin posts the instruction to the session.

func (*Provider) UninstallHooks

func (p *Provider) UninstallHooks(repoRoot string) error

UninstallHooks removes the plugin file. The plugin file is entirely chainloop-owned, so we remove it without preserving content.

Jump to

Keyboard shortcuts

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