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.

fix(runner): opencode.json must not be a deliverable

richard-epsilla58957aaeb987
diff --git a/runner/server.py b/runner/server.py
index 45d503a4..e7b1517c 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -2219,7 +2219,14 @@ def _opencode_config(auth: Auth, model: str, cwd: str, mcp_servers: list[dict] |
# set. Shape is {paths, urls} per the published schema; the source tree's bare array is a
# newer form the released binary rejects outright ("Expected object | undefined").
cfg["skills"] = {"paths": [skills_dir]}
- pathlib.Path(cwd, "opencode.json").write_text(json.dumps(cfg, indent=2))
+ # Into .harness/, NOT the workspace root. Produced files are `git status` of the workspace,
+ # and a root-level opencode.json showed up as a deliverable on every turn — internal config
+ # (relay URL, key env name, /data paths) handed to the user as if the agent had made it.
+ # The binary honours OPENCODE_CONFIG (verified on 1.18.23: a config at this path is loaded
+ # and reaches the provider); the env var is set in _build_opencode below.
+ hdir = pathlib.Path(cwd, ".harness")
+ hdir.mkdir(exist_ok=True)
+ (hdir / "opencode.json").write_text(json.dumps(cfg, indent=2))
return f"hr/{model}"
@@ -2232,6 +2239,7 @@ def _build_opencode(provider: str, auth: Auth, model: str, prompt: str, cwd: str
if auth.api_key:
env[_OPENCODE_KEY_ENV] = auth.api_key
qualified = _opencode_config(auth, model, cwd, mcp_servers, skills_dir, tools_disabled, pr)
+ env["OPENCODE_CONFIG"] = os.path.join(cwd, ".harness", "opencode.json")
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
diff --git a/runner/tests/test_opencode_normalize.py b/runner/tests/test_opencode_normalize.py
index 092fe80e..bf210ee1 100644
--- a/runner/tests/test_opencode_normalize.py
+++ b/runner/tests/test_opencode_normalize.py
@@ -105,7 +105,7 @@ def test_mcp_is_a_flat_name_to_server_map_not_nested_under_servers():
d = tempfile.mkdtemp()
_opencode_config(Auth(api_key="k", base_url="https://relay.example/v1"), "gpt-5.4", d,
[{"name": "docs", "url": "https://mcp.example/sse"}], None, None, "openai-api")
- cfg = _json.loads(open(f"{d}/opencode.json").read())
+ cfg = _json.loads(open(f"{d}/.harness/opencode.json").read())
assert "servers" not in cfg["mcp"]
assert cfg["mcp"]["docs"]["type"] == "remote"
@@ -116,7 +116,7 @@ def test_skills_is_an_object_with_paths_not_a_bare_array():
d = tempfile.mkdtemp()
_opencode_config(Auth(api_key="k", base_url="https://relay.example/v1"), "gpt-5.4", d, None,
"/ws/.harness/skills", None, "openai-api")
- cfg = _json.loads(open(f"{d}/opencode.json").read())
+ cfg = _json.loads(open(f"{d}/.harness/opencode.json").read())
assert cfg["skills"] == {"paths": ["/ws/.harness/skills"]}
@@ -205,9 +205,9 @@ def test_resume_passes_the_session_id():
def test_key_goes_to_the_environment_and_never_into_the_config_file():
cmd, d, env = _argv()
assert env["HR_OPENCODE_KEY"] == "sk-test"
- cfg = _json.loads(open(f"{d}/opencode.json").read())
+ cfg = _json.loads(open(f"{d}/.harness/opencode.json").read())
assert cfg["provider"]["hr"]["options"]["apiKey"] == "{env:HR_OPENCODE_KEY}"
- assert "sk-test" not in open(f"{d}/opencode.json").read()
+ assert "sk-test" not in open(f"{d}/.harness/opencode.json").read()
assert cfg["provider"]["hr"]["options"]["baseURL"] == "https://relay.example/v1"
@@ -235,7 +235,7 @@ def _npm_for(model, provider):
d = tempfile.mkdtemp()
_opencode_config(Auth(api_key="k", base_url="https://relay.example/v1"), model, d, None, None,
None, provider)
- return _json.loads(open(f"{d}/opencode.json").read())["provider"]["hr"]["npm"]
+ return _json.loads(open(f"{d}/.harness/opencode.json").read())["provider"]["hr"]["npm"]
def test_claude_on_an_anthropic_connection_uses_the_messages_package():
@@ -305,3 +305,18 @@ def test_a_bare_nonzero_exit_says_so_instead_of_going_blank():
def test_a_failing_tool_is_quoted_when_the_process_dies_without_an_error_event():
ev = _opencode_eof({"final": "", "_oc_tool_errors": ["bash: boom"]}, 1)[0]
assert "bash: boom" in ev["result"]
+
+
+def test_config_lives_under_harness_not_the_workspace_root():
+ """Produced files are `git status` of the workspace. A root-level opencode.json was collected
+ as a deliverable on every turn, handing the user internal config (relay URL, key env name,
+ data-volume paths). .harness/ is excluded from collection; OPENCODE_CONFIG points the binary
+ at it (verified on 1.18.23)."""
+ import os
+ d = tempfile.mkdtemp()
+ env: dict = {}
+ _build_opencode("openai-api", Auth(api_key="k", base_url="https://relay.example/v1"),
+ "gpt-5.4", "hi", d, env)
+ assert not os.path.exists(f"{d}/opencode.json")
+ assert os.path.exists(f"{d}/.harness/opencode.json")
+ assert env["OPENCODE_CONFIG"] == f"{d}/.harness/opencode.json"