Help us shape the future of Go! Take the 2026 Go Developer Survey

opencode

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package opencode implements the OpenCode adapter for agentsync.

Package opencode implements the OpenCode adapter for agentsync.

settings.go: JSONC-aware merge for opencode.json. Uses tailscale/hujson to PARSE JSONC (comments + trailing commas) so a hand-edited opencode.json is not rejected. NOTE: the merged result is re-emitted as plain JSON — comments and trailing commas are NOT preserved (see MergeJSONC). Foreign keys/values are preserved; only the formatting/comments are lost. Comment-preserving mutation is deferred to v1.x (matches the README "Known limits").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IngestMCPSpec

func IngestMCPSpec(raw map[string]any) source.MCPServerSpec

IngestMCPSpec translates one OpenCode-native MCP server spec — the value under opencode.json `/mcp/<id>` — into the canonical MCPServerSpec. It is the exact inverse of opencodeMCPSpec (Render). Exported so reconcile's key-level write-back reconstructs an opencode MCP server through the SAME translation the adapter uses, rather than assuming the dest shape matches the canonical model (it doesn't: command is an array, env is `environment`, type is local/remote).

func MergeJSONC

func MergeJSONC(existing []byte, ours map[string]any, ownedPointers []string) ([]byte, error)

MergeJSONC merges ours into existing JSONC content, removing ownedPointers no longer present in ours. Foreign keys and values are preserved.

Strategy: parse existing JSONC (hujson, tolerating comments + trailing commas) -> Standardize to strict JSON -> MergeKeys -> emit via json.MarshalIndent. v1 trade-off: this Standardize+marshal path discards ALL comments and trailing-comma formatting (not just touched sections). The file is never corrupted and no data keys are lost; only JSONC formatting is. Comment-preserving mutation is deferred to v1.x.

Types

type Adapter

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

Adapter implements adapter.Adapter for OpenCode.

func New

func New(opts Options) *Adapter

New constructs an OpenCode adapter.

func (*Adapter) Apply

func (a *Adapter) Apply(ops []adapter.FileOp, w adapter.DestWriter) error

Apply routes every destination write through the supplied DestWriter rather than calling iox.AtomicWrite directly. This is the contract that keeps the foreign-collision backup guarantee honest — see the doc on adapter.DestWriter.

func (*Adapter) Capabilities

func (a *Adapter) Capabilities() adapter.Capability

func (*Adapter) Detect

func (a *Adapter) Detect() (bool, error)

func (*Adapter) Ingest

func (a *Adapter) Ingest(scope adapter.Scope, project string) (source.Canonical, error)

Ingest reads OpenCode's native config files and returns a partial source.Canonical. It is the inverse of Render.

Round-trip note: subagents lose the Claude-side `tools` and `color` fields (they were dropped on render because OpenCode has no equivalent). Ingest can only reconstruct what is present on disk — `description`, `model`, and the `mode` key (which is dropped during ingest because it is an OpenCode-specific artifact, not part of canonical).

func (*Adapter) KeyMergeStrategy

func (a *Adapter) KeyMergeStrategy() string

KeyMergeStrategy is opencode's single key-merge strategy: JSONC (opencode.json), which MUST be merged via hujson, not strict JSON.

func (*Adapter) Name

func (a *Adapter) Name() string

func (*Adapter) Render

func (a *Adapter) Render(r secrets.Resolved, scope adapter.Scope, project string) ([]adapter.FileOp, []adapter.Skip, error)

Render converts the resolved canonical into FileOps for OpenCode.

func (*Adapter) SetStderr

func (a *Adapter) SetStderr(w io.Writer)

SetStderr replaces the warning sink the adapter writes Ingest warnings to, so a CLI command can route adapter warnings through the same styled writer it uses for its own output. See claude.Adapter.SetStderr for the contract.

type Options

type Options struct {
	TargetRoot string // honors AGENTSYNC_TARGET_ROOT (real "/Users/x" in production)
	// LookPath overrides exec.LookPath for testing. nil means use exec.LookPath.
	LookPath func(file string) (string, error)
	// Stderr receives Ingest warnings (lenient-YAML notices, dropped components).
	// nil means os.Stderr.
	Stderr io.Writer
}

Options configure the adapter at construction.

type Paths

type Paths struct {
	ConfigDir       string // ~/.config/opencode
	Settings        string // ~/.config/opencode/opencode.json (user) or <proj>/opencode.json (project)
	AgentsDir       string // ~/.config/opencode/agents (user) or .opencode/agents (project)
	CommandsDir     string // ~/.config/opencode/commands (user) or .opencode/commands (project)
	ClaudeSkillsDir string // ~/.claude/skills (shared with Claude!)
	Memory          string // AGENTS.md path
}

Paths resolves the destination paths for a given (scope, project, target-root).

func ResolvePaths

func ResolvePaths(targetRoot, project string, projectScope bool) Paths

ResolvePaths returns the Paths for the given target root and optional project. projectScope=true + non-empty project uses project-local .opencode/ dirs.

Jump to

Keyboard shortcuts

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