Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(docker): support OpenCode in native wrapper (#3547)

AxelRayd90dadf2668a
diff --git a/scripts/install.sh b/scripts/install.sh
index b8125bb45..b3f43cc6a 100644
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -84,6 +84,7 @@ require_cmd() {
ensure_host_dirs() {
mkdir -p \
+ "${HEADROOM_HOST_HOME}/.config/opencode" \
"${HEADROOM_HOST_HOME}/.headroom" \
"${HEADROOM_HOST_HOME}/.claude" \
"${HEADROOM_HOST_HOME}/.codex" \
@@ -119,6 +120,7 @@ append_common_container_args() {
ref+=(-v "${HEADROOM_HOST_HOME}/.claude:${HEADROOM_CONTAINER_HOME}/.claude")
ref+=(-v "${HEADROOM_HOST_HOME}/.codex:${HEADROOM_CONTAINER_HOME}/.codex")
ref+=(-v "${HEADROOM_HOST_HOME}/.gemini:${HEADROOM_CONTAINER_HOME}/.gemini")
+ ref+=(-v "${HEADROOM_HOST_HOME}/.config/opencode:${HEADROOM_CONTAINER_HOME}/.config/opencode")
if command -v id >/dev/null 2>&1; then
ref+=(--user "$(id -u):$(id -g)")
@@ -616,6 +618,7 @@ Supported commands:
aider
cursor
openclaw
+ opencode
Notes:
- GitHub Copilot CLI wrapping is not supported by the Docker-native wrapper.
@@ -1471,11 +1474,13 @@ main() {
proxy_args+=(--region "${region}")
fi
- local container_name=""
+ # Keep this in the wrapper's global scope so the EXIT trap can still
+ # stop the proxy after main returns.
+ container_name=""
if [[ "${no_proxy}" -eq 0 ]]; then
container_name="$(start_proxy_container "${port}" "${proxy_args[@]}")"
fi
- trap 'stop_proxy_container "${container_name}"' EXIT INT TERM
+ trap 'stop_proxy_container "${container_name:-}"' EXIT INT TERM
local prep_args=("${known_args[@]}")
if [[ "${no_proxy}" -eq 0 ]]; then
@@ -1508,6 +1513,15 @@ EOF
sleep 1
done
;;
+ opencode)
+ local opencode_config_file="${HEADROOM_HOST_HOME}/.config/opencode/opencode.json"
+ if [[ -f "${opencode_config_file}" ]]; then
+ OPENCODE_CONFIG_CONTENT="$(<"${opencode_config_file}")" \
+ run_host_tool opencode "${host_args[@]}"
+ else
+ run_host_tool opencode "${host_args[@]}"
+ fi
+ ;;
esac
;;
unwrap)
diff --git a/tests/test_install/test_native_installers.py b/tests/test_install/test_native_installers.py
index e6b3e5242..5ad549574 100644
--- a/tests/test_install/test_native_installers.py
+++ b/tests/test_install/test_native_installers.py
@@ -210,6 +210,19 @@ def _write_fake_docker_shims(tmp_path: Path) -> Path:
openclaw_sh.write_text("#!/usr/bin/env bash\nexit 0\n", encoding="utf-8")
openclaw_sh.chmod(0o755)
+ opencode_sh = shim_dir / "opencode"
+ opencode_sh.write_text(
+ "#!/usr/bin/env bash\n"
+ "{\n"
+ " printf 'CONFIG=%s\\n' \"${OPENCODE_CONFIG_CONTENT-}\"\n"
+ " printf 'ARGS='\n"
+ " printf '%q ' \"$@\"\n"
+ " printf '\\n'\n"
+ '} > "${FAKE_OPENCODE_LOG}"\n',
+ encoding="utf-8",
+ )
+ opencode_sh.chmod(0o755)
+
openclaw_cmd = shim_dir / "openclaw.cmd"
openclaw_cmd.write_text("@echo off\r\nexit /b 0\r\n", encoding="utf-8")
@@ -556,6 +569,53 @@ def test_bash_native_installer_supports_persistent_docker_lifecycle(tmp_path: Pa
_cleanup_fake_docker(env)
+ os.name == "nt" or shutil.which("bash") is None or not _bash_supports_4_3(),
+ reason="installer requires bash >= 4.3 (macOS system bash is 3.2)",
+)
+def test_bash_native_wrapper_supports_opencode(tmp_path: Path) -> None:
+ home = tmp_path / "home"
+ (home / ".local").mkdir(parents=True)
+ env = _build_env(home, tmp_path)
+ env["HEADROOM_DOCKER_IMAGE"] = "headroom:test-image"
+ env["FAKE_OPENCODE_LOG"] = str(tmp_path / "opencode.log")
+
+ try:
+ _run(["bash", str(REPO_ROOT / "scripts" / "install.sh")], env=env, cwd=REPO_ROOT)
+ wrapper = home / ".local" / "bin" / "headroom"
+
+ config_file = home / ".config" / "opencode" / "opencode.json"
+ config_file.parent.mkdir(parents=True)
+ config_content = (
+ '{"provider":{"headroom":{"options":{"baseURL":"http://127.0.0.1:8787/v1"}}}}'
+ )
+ config_file.write_text(config_content, encoding="utf-8")
+
+ port = _free_port()
+ result = _run(
+ [str(wrapper), "wrap", "opencode", "--port", str(port), "--", "--help"],
+ env=env,
+ )
+ assert result.stderr == ""
+
+ docker_calls = _read_fake_docker_log(env)
+ prepare_call = next(
+ call
+ for call in docker_calls
+ if call[:2] == ["run", "--rm"] and "--prepare-only" in call and "opencode" in call
+ )
+ assert f"{home}/.config/opencode:/tmp/headroom-home/.config/opencode" in prepare_call
+ assert f"{home}/.config:/tmp/headroom-home/.config" not in prepare_call
+
+ opencode_output = Path(env["FAKE_OPENCODE_LOG"]).read_text(encoding="utf-8")
+ assert f"CONFIG={config_content}" in opencode_output
+ assert "ARGS=--help" in opencode_output
+ docker_state = json.loads(Path(env["FAKE_DOCKER_STATE"]).read_text(encoding="utf-8"))
+ assert docker_state["containers"] == {}
+ finally:
+ _cleanup_fake_docker(env)
+
+
def _powershell_executable() -> str | None:
return shutil.which("pwsh") or shutil.which("powershell") or shutil.which("powershell.exe")