Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

feat(runner,docker): opencode hard tool permissions + install path

richard-epsillae4183ed51949
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index 02299eee..92620b39 100644
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -185,9 +185,35 @@ backend_bin() {
hermes) echo "$TOOLS/venv/bin/hermes" ;;
pi) echo "$TOOLS/bin/pi" ;;
dsh) echo "$TOOLS/dsh-venv/bin/dsh-ready" ;;
+ opencode) echo "$TOOLS/bin/opencode" ;;
esac
}
+# opencode ships prebuilt binaries on GitHub releases rather than npm, so fetch the asset directly.
+# NOT the vendor's install script: it hardcodes INSTALL_DIR=$HOME/.opencode/bin with no override, so
+# it cannot be pointed at the data volume, and piping a remote script into a shell inside an
+# entrypoint is a supply-chain surface this product does not need. Pin with HR_OPENCODE_VERSION.
+install_opencode() {
+ case "$(uname -m)" in
+ x86_64) oc_arch="x64" ;;
+ aarch64|arm64) oc_arch="arm64" ;;
+ *) echo "unsupported architecture $(uname -m) for opencode"; return 1 ;;
+ esac
+ oc_ref="${HR_OPENCODE_VERSION:-latest}"
+ if [ "$oc_ref" = "latest" ]; then
+ oc_url="https://github.com/anomalyco/opencode/releases/latest/download/opencode-linux-$oc_arch.tar.gz"
+ else
+ oc_url="https://github.com/anomalyco/opencode/releases/download/v${oc_ref#v}/opencode-linux-$oc_arch.tar.gz"
+ fi
+ oc_tmp="$(mktemp -d)"
+ curl -fsSL "$oc_url" -o "$oc_tmp/opencode.tar.gz" || { rm -rf "$oc_tmp"; return 1; }
+ tar -xzf "$oc_tmp/opencode.tar.gz" -C "$oc_tmp" || { rm -rf "$oc_tmp"; return 1; }
+ [ -f "$oc_tmp/opencode" ] || { echo "release archive contained no opencode binary"; rm -rf "$oc_tmp"; return 1; }
+ mkdir -p "$TOOLS/bin" && mv "$oc_tmp/opencode" "$TOOLS/bin/opencode" && chmod 755 "$TOOLS/bin/opencode" \
+ || { rm -rf "$oc_tmp"; return 1; }
+ rm -rf "$oc_tmp"
+}
+
# Run an install and, if it fails, SAY WHY.
#
# This was `>/dev/null 2>&1 || true`, and the silence cost a day of someone's life: a root-owned
@@ -215,6 +241,15 @@ install_backends() {
try_install "Claude Code" npm install -g --prefix "$TOOLS" --no-audit --no-fund @anthropic-ai/claude-code || true
fi
+ # opencode is MIT, so unlike Claude Code and hermes it COULD be baked into the image. It is
+ # installed here anyway to keep one install path for every backend, and it is deliberately not in
+ # the default HR_BACKENDS: the gateway has no model catalogue for it yet (that needs a real probed
+ # turn), so installing it by default would ship a CLI nothing can route to. Opt in explicitly.
+ if wanted opencode && [ ! -x "$(backend_bin opencode)" ]; then
+ echo "[harnessrouter] installing opencode (MIT)…"
+ try_install "opencode" install_opencode || true
+ fi
+
if wanted codex && [ ! -x "$(backend_bin codex)" ]; then
echo "[harnessrouter] installing Codex (Apache-2.0)…"
try_install "Codex" npm install -g --prefix "$TOOLS" --no-audit --no-fund @openai/codex || true
diff --git a/runner/server.py b/runner/server.py
index 9b493aa3..2bd03bf6 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -2095,6 +2095,23 @@ OPENCODE_PROVIDERS = {"anthropic", "openai", "azure", "openai-api", "tokenrouter
# itself never lands on disk in the session workspace.
_OPENCODE_KEY_ENV = "HR_OPENCODE_KEY"
+# The permission keys opencode actually understands (core/src/v1/config/permission.ts). Enforcement
+# is HARD here: the action set is ask|allow|deny, so a denied tool is genuinely absent rather than
+# merely discouraged. A key outside this set would be accepted by the record-with-rest schema and
+# then silently match no tool, so unknown names are dropped rather than written.
+_OPENCODE_PERMS = {"read", "edit", "glob", "grep", "list", "bash", "task", "external_directory",
+ "todowrite", "question", "webfetch", "websearch", "lsp", "doom_loop", "skill"}
+
+
+def _opencode_denies(tools_disabled: list[str] | None) -> dict:
+ """Harness tool ids -> {<key>: "deny"}. Catalog labels arrive "bash (Shell)"-style; keep the id."""
+ out: dict = {}
+ for raw in tools_disabled or []:
+ name = (raw or "").split(" (")[0].strip().lower()
+ if name in _OPENCODE_PERMS:
+ out[name] = "deny"
+ return out
+
def _opencode_mcp(servers: list[dict] | None) -> dict:
"""opencode `mcp.servers.<name>`: a tagged union on `type` (packages/core/src/config/mcp.ts).
@@ -2126,7 +2143,7 @@ def _opencode_mcp(servers: list[dict] | None) -> dict:
def _opencode_config(auth: Auth, model: str, cwd: str, mcp_servers: list[dict] | None,
- skills_dir: str | None) -> str:
+ skills_dir: str | None, tools_disabled: list[str] | None = None) -> str:
"""Write <cwd>/opencode.json and return the provider-qualified model id for --model."""
if not auth.base_url:
raise HTTPException(400, "opencode needs a base_url (none configured)")
@@ -2146,6 +2163,9 @@ def _opencode_config(auth: Auth, model: str, cwd: str, mcp_servers: list[dict] |
mcp = _opencode_mcp(mcp_servers)
if mcp:
cfg["mcp"] = {"servers": mcp}
+ denies = _opencode_denies(tools_disabled)
+ if denies:
+ cfg["permission"] = denies
if skills_dir:
# `skills` takes arbitrary paths, so the directory _write_skills already produced is named
# here directly. No mirroring into a per-CLI home, which is the trap codex and hermes set.
@@ -2156,13 +2176,13 @@ def _opencode_config(auth: Auth, model: str, cwd: str, mcp_servers: list[dict] |
def _build_opencode(provider: str, auth: Auth, model: str, prompt: str, cwd: str, env: dict,
resume_session_id: str | None = None, mcp_servers: list[dict] | None = None,
- skills_dir: str | None = None) -> list[str]:
+ skills_dir: str | None = None, tools_disabled: list[str] | None = None) -> list[str]:
pr = provider or "openai-api"
if pr not in OPENCODE_PROVIDERS:
raise HTTPException(400, f"unknown opencode provider '{pr}' (one of {sorted(OPENCODE_PROVIDERS)})")
if auth.api_key:
env[_OPENCODE_KEY_ENV] = auth.api_key
- qualified = _opencode_config(auth, model, cwd, mcp_servers, skills_dir)
+ qualified = _opencode_config(auth, model, cwd, mcp_servers, skills_dir, tools_disabled)
cmd = ["opencode", "run", "--format", "json", "--model", qualified,
# The sandbox is the trust boundary, so permissions are granted up front: nobody is
# attached to answer a prompt. Same rationale as pi --approve and claude
@@ -3213,7 +3233,7 @@ def turn(req: TurnReq, identifier: str = "") -> dict:
skills_dir = os.path.join(cwd, ".harness", "skills") if installed_skills else None
cmd = _build_opencode(req.provider, auth, model, req.prompt, cwd, env,
resume_session_id=req.resume_session_id, mcp_servers=req.mcp_servers,
- skills_dir=skills_dir)
+ skills_dir=skills_dir, tools_disabled=req.tools_disabled)
else:
mcp_config = _write_mcp_config_claude(cwd, req.mcp_servers)
plugin_dirs = _write_plugins(cwd, req.plugins)
diff --git a/runner/tests/test_opencode_normalize.py b/runner/tests/test_opencode_normalize.py
index cd043c60..e99eaee0 100644
--- a/runner/tests/test_opencode_normalize.py
+++ b/runner/tests/test_opencode_normalize.py
@@ -116,3 +116,25 @@ def test_mcp_local_builds_command_and_env():
def test_mcp_skips_entries_with_neither_url_nor_command():
assert _opencode_mcp([{"name": "empty"}]) == {}
+
+
+# ── permissions: opencode enforces deny HARD, unlike codex/hermes ────────────────────
+from server import _opencode_denies # noqa: E402
+
+
+def test_disabled_tools_become_deny_rules():
+ assert _opencode_denies(["bash", "webfetch"]) == {"bash": "deny", "webfetch": "deny"}
+
+
+def test_catalog_label_suffix_is_stripped_to_the_real_key():
+ """Labels arrive "bash (Shell)"-style; a label written verbatim would match no tool and
+ silently disable nothing — the failure mode the claude notes call out."""
+ assert _opencode_denies(["bash (Shell)", "Read"]) == {"bash": "deny", "read": "deny"}
+
+
+def test_unknown_tool_names_are_dropped_not_written():
+ """The config schema accepts arbitrary extra keys, so an unknown name would be stored and then
+ match nothing. Dropping it keeps the written config honest about what is enforced."""
+ assert _opencode_denies(["not_a_tool", "bash"]) == {"bash": "deny"}
+ assert _opencode_denies([]) == {}
+ assert _opencode_denies(None) == {}