Skip to content

OpenCode Harness Guide ​

Audience: Users — Operators configuring or troubleshooting the OpenCode harness.

hpilot uses the current OpenCode V2 HTTP server as the existing opencode harness. Each stage owns an authenticated loopback server and a native session; it does not attach to your interactive OpenCode server. Compatible newer CLIs are accepted by capability checks, not an exact version pin. V1 HTTP compatibility and automatic migration of user configuration or plugins are not provided.

The OpenCode V2 verification report records the real-provider checks for execution, permissions, continuation, cancellation, and native history.

Setup ​

  1. Install a current OpenCode CLI and configure a working provider using OpenCode's own setup. Provider authentication is separate from hpilot's verifier credentials.
  2. Install uv so uvx is on PATH. hpilot launches uvx mcp-yieldshell; missing, disabled, or failed yieldshell readiness stops the stage before model work. A genuinely pending cold startup has a bounded 120-second allowance and remains cancellable.
  3. Check the required native surfaces:
bash
opencode --version
opencode serve --help
opencode debug config --standalone >/dev/null
uvx --version
hpilot use opencode
hpilot doctor

The CLI must support native ordered permissions, authenticated /api/* session APIs, and standalone client commands. serve itself is standalone: do not add --standalone to opencode serve. That flag belongs to client commands such as debug config and session list.

hpilot doctor checks configured verifier and harness prerequisites; successful doctor output is not a completed agent run. Contract-only stages do not need verifier credentials; non-contract agent stages also need llm.api_key in the active hpilot configuration.

Model and effort ​

Use a provider-qualified native model, optionally with a variant: provider/model#variant. A stage override takes precedence over the configured OpenCode default. hpilot reads global/XDG, explicit OPENCODE_CONFIG, project JSON/JSONC, and inline settings without rewriting the original files. With no configured model, OpenCode's server default is resolved explicitly; an interactive TUI's last-used model is not a server configuration default.

yaml
# Active .hpilot/config.yaml or ~/.hpilot/config.yaml
harness: opencode
stage_overrides:
  Implement:
    model: your-provider/your-model
    effort: your-advertised-variant

Replace the placeholder values with a model and variant advertised by your provider. Effort maps to the native model variant on every turn, including verifier corrections and resumed retries. When both a #variant suffix on model and effort are configured, effort takes precedence. An effort-only override resolves the configured or server-default base model first. Models without advertised variants cannot accept an arbitrary effort value. Unknown models, providers, variants, malformed configuration, and a different effective model fail explicitly; hpilot does not silently keep another model or inject legacy reasoningEffort options.

The runtime overlay is process-local, stored in a private temporary file and mirrored in OPENCODE_CONFIG_CONTENT. User configuration bytes remain unchanged on success, failure, and cancellation. Automatic context instructions are cleared, project/rule discovery is disabled for the child, and legacy fileContext/contextPaths keys are omitted from the overlay, while legacy options, temperature, or top_p keys inside agent/agents entries fail configuration validation explicitly; explicitly merged project model/provider settings are still available.

Unattended permissions and tools ​

hpilot generates native ordered permissions for the root, agents, and session. Autonomous allows and inherited ask-to-allow normalizations come before user denies and mandatory denies, so normalization never erases a deny.

  • Built-in shell and question are denied; yieldshell provides managed-process tools instead of the built-in shell.
  • disallowed_tools aliases and read_only_paths produce native deny rules. OpenCode does not use hpilot's detect-after-write Git guard.
  • Native MCP file-write permissions do not contain the destination path. Known MCP file_write/file_edit requests are checked against the actual path and native edit permissions before an allow-once or reject reply. Protected writes are rejected while permitted writes still work.
  • Unknown permission requests reject autonomously with an explanatory message rather than waiting for a person or triggering fake cancellation; it is never treated as approval. Unexpected native execution interrupts fail the stage attempt cleanly instead of masquerading as user pipeline cancellation.
  • Conflicting provider/tool/MCP policies fail explicitly. Do not remove protections to hide a policy conflict.

This is tool/path enforcement, not a security boundary. Arbitrary commands available through yieldshell can write files; use filesystem-level isolation when that must be prevented.

Execution, progress, and recovery ​

Completed replies, reasoning, and tool calls use hpilot's normal readable log format. Duplicate tool events are suppressed. Global heartbeats and events belonging to this session or its known children maintain the idle timer; unrelated session events do not. Raw stage events are credential-redacted before logging.

A fully silent stream fails after the default 600-second idle window. Both clean EOF and stream errors trigger bounded observation recovery (up to three reconnects per turn), rather than pretending EOF is successful completion or waiting out the idle window. An accepted prompt is never resubmitted by transport recovery. If admission status cannot be established after transport loss, the stage reports uncertainty; inspect native history before retrying work with side effects.

Cancellation uses the active task interface (hpilot cancel <task-id>) or Ctrl+C on an owned foreground run. hpilot interrupts the native turn, bypasses verifier/usage waits and failure keep-alive, and stops the server plus its verified descendants, including detached MCP children. It does not scan for other OpenCode sessions or stop your interactive server.

Retry and explicit resume ​

Verifier corrections continue the same session. Recoverable stage retries reuse the live owned server when possible; after server death or a new invocation, a new owned server loads the persisted session from OpenCode's own store.

bash
hpilot run "continue the task" --start-from Implement --resume
# Or, for a daemon task:
hpilot submit "continue the task" --start-from Implement --resume

Keep the same workspace, identity, XDG roots, stage, model, effort, and goal mode. hpilot checks .hpilot/latest-session.json and reports confirmed continuation or the reason for a fresh fallback. --start-from without --resume starts fresh. Missing native sessions fall back explicitly; authentication and transport failures do not silently discard history. Fresh explicit-resume fallback preserves the original metadata target. See resumed-stage continuation for shared match checks.

Usage and native history ​

Usage is the per-attempt change in native cumulative root/child counters, not a sum of repeated stream events. OpenCode reasoning is included in canonical output; cache reads/writes remain separate. Missing values remain unavailable, including cancelled-turn usage. Native USD estimates are emitted with per-turn usage in the stage JSONL; they are not a provider invoice or a new cost column in hpilot usage.

After the owned server stops, use the same environment to discover or export its exact identifier:

bash
opencode session list --standalone --format json
opencode session export --standalone <session-id> > /private/path/session.json

Exports contain transcript content. Keep them private. Native history resides in ${XDG_DATA_HOME:-$HOME/.local/share}/opencode/opencode.db with SQLite sidecars. Use the same account and XDG settings to discover and resume those sessions.

Troubleshooting ​

  • Missing CLI or capabilities: Check the setup commands and upgrade OpenCode. An HTML response is not API readiness, even with HTTP 200. Do not substitute V1 routes or add --standalone to serve.
  • Cold startup deadline: Capability commands have a 60-second bound each; owned-server readiness and subsequent cold location initialization each allow 120 seconds. Temporary location-not-ready responses are retried without resubmitting an agent prompt. Inspect the redacted startup diagnostic and check package/network access on slow hosts. A readiness timeout is reported separately from a server that exited before cleanup.
  • Owned-server authentication failure: hpilot generates its own per-process password. Inherited old server username/password variables are ignored. Check for an incompatible CLI or a conflicting listener; do not paste passwords into logs.
  • Provider/model/variant rejected: Check OpenCode's provider authentication, enabled model catalog, and advertised variants. Correct the configuration and start a later run; deterministic configuration rejections are not retried repeatedly.
  • Yieldshell unavailable or policy conflict: Verify uvx and package/network access, and inspect your native tool/MCP policies. The stage stops rather than running without its required shell replacement.
  • Lost stream or idle failure: Inspect the last redacted events and sse_transport_reconnected / idle_timeout_failed entries under .hpilot/logs/stages/. Observation recovery never sends a recovery prompt.
  • History missing: Check the exact identifier and state-root environment with the standalone commands above. A new server alone is not a reason for fresh fallback. Missing listing/export evidence is unverified, not success inferred from hpilot metadata.