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 ¶
- func IngestMCPSpec(raw map[string]any) source.MCPServerSpec
- func MergeJSONC(existing []byte, ours map[string]any, ownedPointers []string) ([]byte, error)
- type Adapter
- func (a *Adapter) Apply(ops []adapter.FileOp, w adapter.DestWriter) error
- func (a *Adapter) Capabilities() adapter.Capability
- func (a *Adapter) Detect() (bool, error)
- func (a *Adapter) Ingest(scope adapter.Scope, project string) (source.Canonical, error)
- func (a *Adapter) KeyMergeStrategy() string
- func (a *Adapter) Name() string
- func (a *Adapter) Render(r secrets.Resolved, scope adapter.Scope, project string) ([]adapter.FileOp, []adapter.Skip, error)
- func (a *Adapter) SetStderr(w io.Writer)
- type Options
- type Paths
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 ¶
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 (*Adapter) Apply ¶
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) Ingest ¶
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 ¶
KeyMergeStrategy is opencode's single key-merge strategy: JSONC (opencode.json), which MUST be merged via hujson, not strict JSON.
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 ¶
ResolvePaths returns the Paths for the given target root and optional project. projectScope=true + non-empty project uses project-local .opencode/ dirs.