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.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
runner: opencode's output is the visible text; add the reasoning it keeps apart (#216)
Hao Lude145b6dd111
diff --git a/runner/server.py b/runner/server.pyindex e89753e3..2a437514 100644--- a/runner/server.py+++ b/runner/server.py@@ -4846,13 +4846,22 @@ def _build_opencode(provider: str, auth: Auth, model: str, prompt: str, cwd: strdef _opencode_usage_add(state: dict, tk: dict | None) -> None:"""step-finish carries Session.getUsage()'s `tokens`:{total, input, output, reasoning, cache:{read,write}}. `input` is ALREADY cache-exclusive- (opencode subtracts read+write itself), which is the canonical contract — no adjustment."""+ (opencode subtracts read+write itself), which is the canonical contract — no adjustment.+ `output` is the visible text ONLY: getUsage (session/session.ts) sets+ `output: outputTokens - reasoningTokens` and carries the reasoning beside it, and bills both+ at the output rate. The contract here is output_tokens = everything the model generated,+ thinking included (pi's `output` is completion_tokens, "already includes reasoning_tokens";+ cline's and dsh's outputTokens are completion_tokens too), so the two are added back+ together. Measured on 1.18.31 against deepseek-flash, one task of 22 requests: opencode's+ rows summed output 7445 / reasoning 10582; the turn record said 7445, and beside pi's 11530+ for the same task the harness read as the cheapest by a factor it had not earned."""if not isinstance(tk, dict):returntot = state.setdefault("_oc_usage", {"input_tokens": 0, "output_tokens": 0,"cache_read_tokens": 0, "cache_write_tokens": 0})cache = tk.get("cache") if isinstance(tk.get("cache"), dict) else {}for v, dst in ((tk.get("input"), "input_tokens"), (tk.get("output"), "output_tokens"),+ (tk.get("reasoning"), "output_tokens"),(cache.get("read"), "cache_read_tokens"), (cache.get("write"), "cache_write_tokens")):if isinstance(v, (int, float)):tot[dst] += int(v)diff --git a/runner/tests/test_opencode_normalize.py b/runner/tests/test_opencode_normalize.pyindex 6fabcb4e..5c772925 100644--- a/runner/tests/test_opencode_normalize.py+++ b/runner/tests/test_opencode_normalize.py@@ -87,10 +87,28 @@ def test_usage_input_is_taken_as_cache_exclusive():_opencode_usage_add(state, {"total": 130, "input": 100, "output": 20, "reasoning": 5,"cache": {"read": 7, "write": 3}})_opencode_usage_add(state, {"input": 1, "output": 2, "cache": {"read": 3, "write": 4}})- assert state["_oc_usage"] == {"input_tokens": 101, "output_tokens": 22,+ assert state["_oc_usage"] == {"input_tokens": 101, "output_tokens": 27,"cache_read_tokens": 10, "cache_write_tokens": 7}+def test_usage_output_counts_the_reasoning_opencode_keeps_apart():+ """opencode's `output` is the visible text only — getUsage subtracts reasoningTokens and+ carries them as `reasoning`. Every other backend's output is the model's whole generation+ (pi: completion_tokens; cline, dsh: outputTokens), so the two are added back together.+ Measured on 1.18.31 / deepseek-flash: 22 requests, output 7445 + reasoning 10582, and the+ turn record reported 7445 — 41% of what was generated and billed."""+ state = {}+ for tk in ({"input": 7290, "output": 87, "reasoning": 11, "cache": {"read": 1664, "write": 0}},+ {"input": 350, "output": 78, "reasoning": 11, "cache": {"read": 8960, "write": 0}},+ {"input": 234, "output": 223, "reasoning": 0, "cache": {"read": 9216, "write": 0}}):+ _opencode_usage_add(state, tk)+ assert state["_oc_usage"]["output_tokens"] == 87 + 11 + 78 + 11 + 223+ # a step whose reasoning is absent or malformed still counts its text+ _opencode_usage_add(state, {"output": 5, "reasoning": None})+ _opencode_usage_add(state, {"output": 6, "reasoning": "many"})+ assert state["_oc_usage"]["output_tokens"] == 410 + 11++def test_usage_ignores_a_missing_or_malformed_payload():state = {}_opencode_usage_add(state, None)