eval: gobang as a Track B native agent

gobang, the Aji-native harness, joins Codex, Claude Code and OpenCode in
ajieval native. Like them it is an agent product: its runs are never
evidence for H4. Model ids choose the provider: claude-* the Anthropic
API, any other GLM via z.ai, fixture:PATH a scenario without network
(self-tests).

gobang reaches the model over its API, so the key's variable is passed
into the sandbox environment; NativeAgent.env supplies it, its value
never enters the run record, and a missing key stops the run before
anything is created. Tool processes run in gobang's own networkless
bubblewrap sandbox, so no shell wrapper is used. The transcript is
gobang's journal: usage, tool calls and the model come from its events,
the repair metrics from its toolchain tools (aji_check, aji_run,
run_tests with aji's exit codes), and its documentation tools count as
reads of /docs files.

Checked end to end on dev-echo (aji_source) with a fixture model: the
dev evaluator accepts the solution, the workspace holds only the
solution, and the first-check and first-test metrics are exact. With a
fake key the run reaches z.ai from the sandbox and ends INFRA_FAILED
(auth) without the key in any file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
devandClaude Opus 5.5 committed 2026-10-08 15:00:36 +03:00
1 parent 762c5abe7b
commit 0e98638bc6
4 files changed
+246 -2

No files matched your search

+16
View File
@@ -205,6 +205,7 @@ Per agent:
| `codex` | `codex exec --json`; `approval_policy=never`; web search off; product features off (multi-agent, apps, browser, computer use, plugins, skills, goals, hooks…) | off (Codex `workspace-write` sandbox) |
| `claude` | `claude -p --output-format stream-json`; tools limited to `Bash`, `Read`, `Edit` and `Write`; `--strict-mcp-config`; slash commands off | off (networkless shell wrapper) |
| `opencode` | `opencode run --pure --format json`; no MCP; `webfetch`, `websearch` and `task` off; no LSP downloads | off (networkless shell wrapper) |
| `gobang` | `gobang run --json-events --in-place /work`; configuration written to the fresh HOME; documentation at `/docs` | off (gobang's own bubblewrap sandbox; the model has no shell) |
**Networkless shell.** Inside the sandbox, the real shell binaries (`/usr/bin/bash`; `sh` follows its symlink) are replaced by wrappers. Each wrapper runs the command in a nested bubblewrap with a fresh, empty network namespace and without the resolver socket. The CLI process keeps the network to reach its backend. Every process a tool starts through a shell, `python3` sockets included, has neither network nor DNS. The live check is the dev task [`dev-netprobe`](dev-tasks/dev-netprobe/), which all three agents pass.
@@ -230,6 +231,21 @@ Per agent:
A first-generation snapshot is not available in Track B. There is no cost in dollars either: on subscriptions there is no honest cost per solution, so Track B reports success, time, tool calls and context. Economics stays with Track A.
### gobang
gobang (a sibling repository) is an Aji-native harness: the model works through typed tools bound to the toolchain instead of a shell, and gobang's own verification gate decides when it is done. It is another agent product in Track B, so its runs are never evidence for H4 either; what it measures is the harness, against the other agents, ideally on the same model.
```sh
PATH=/path/to/gobang/zig-out/bin:$PATH ZAI_API_KEY=… python3 -m ajieval native --task DIR --language aji_source \
--agent gobang --model glm-5.3-flash --evaluator CMD --out runs/
```
- **Model ids.** `claude-*` uses the Anthropic API (`ANTHROPIC_API_KEY`); any other id uses GLM via z.ai (`ZAI_API_KEY`); `fixture:PATH` replays a gobang scenario file without a network, for harness self-tests.
- **Key.** Unlike the other agents, gobang has no credential file: the key's variable is passed into the sandbox with `--setenv` and named, never valued, in the configuration. Its value appears in no record. It is visible to the user's own processes in the bubblewrap command line while the run lasts. A missing key stops the run before anything is created.
- **Isolation.** gobang runs aji and test commands in a nested bubblewrap sandbox with every namespace unshared, so tool processes have no network even though the sandbox shares it for the model API; there is no shell wrapper.
- **Transcript.** `transcript.jsonl` is gobang's journal (`--json-events`). Tool calls, token usage (input including cached, cached, output) and the model come from its events. The repair metrics come from gobang's toolchain tools, not from guessed shell commands: `aji_check` and `aji_run` count as `aji check` and `aji run` with aji's exit code for their outcome, `run_tests` as the configured test commands. The documentation tools are presented as reads of `/docs/<file>`, so the documentation metrics count them like a file read.
- **State.** gobang keeps its session state under `/tmp/gobang` inside the sandbox, so the evaluated repository contains only the solution. `metrics.agent_facts` carries `gobang_state` and `gobang_reason` (COMPLETED, FAILED, BLOCKED, INFRA_FAILED …) and the hash of gobang's prompts.
## Agent and evaluation status (Track B, `metrics`)
How the agent's session ended and what the evaluator says about the repository are recorded separately, so that a transport problem after a finished solution is not read as a failure of the solution, and a cut-off reply is not read as a normal exit.
+24
View File
@@ -99,6 +99,30 @@ def tool_events_native(agent_name, transcript_path):
if e.get("type") == "tool_use":
st = part.get("state") or {}
out.append((json.dumps(st.get("input")), st.get("output") or ""))
if agent_name == "gobang":
out += _gobang_tool_events(transcript_path)
return out
def _gobang_tool_events(transcript_path):
"""gobang's documentation tools name sections and files relative to the
bundle; they are presented as /docs paths, and their numbered text as
the output, so the documentation metrics count them like a file read."""
from .native import gobang_events
out = []
results, _ = gobang_events(transcript_path)
for tool, args, output in results:
try:
a = json.loads(args) if args else {}
o = json.loads(output)
except json.JSONDecodeError:
continue
if tool in ("docs_read", "docs_search", "docs_index"):
target = a.get("path") or (a.get("section") or "").split("#")[0]
text = o.get("text") or json.dumps(o.get("sections") or "")
out.append(("/docs/" + target if target else "/docs", text))
else:
out.append((args, output))
return out
+140 -2
View File
@@ -71,6 +71,11 @@ class NativeAgent:
"""Writes the agent's minimal configuration into the fresh HOME."""
return {}
def env(self, model):
"""Environment variables the agent needs inside the sandbox (an API
key). Their values are never written to the run record."""
return {}
def argv(self, model, effort, prompt):
raise NotImplementedError
@@ -234,7 +239,118 @@ class OpenCode(NativeAgent):
return facts
AGENTS = {a.name: a for a in (Codex(), Claude(), OpenCode())}
GOBANG_ZAI_URL = "https://api.z.ai/api/coding/paas/v4"
class Gobang(NativeAgent):
"""gobang, the Aji-native harness (a sibling repository). The
scaffold is the agent product here too, so these runs
are never evidence for H4 (protocol §39b); they measure the harness
against the other agents on the same model where possible.
The model gives no shell commands: gobang runs aji and test commands
itself, in its own networkless bubblewrap sandbox nested in this one,
so no shell wrapper is needed. It reaches the model over its API, so
the key is passed as an environment variable; the configuration names
only the variable.
Model ids: `claude-*` uses the Anthropic API (ANTHROPIC_API_KEY); any
other id uses GLM via z.ai (ZAI_API_KEY); `fixture:PATH` replays a
gobang scenario file without a network (harness self-tests)."""
name = "gobang"
binary = "gobang"
credentials = []
command_network = "disabled (gobang's own bubblewrap sandbox; the model has no shell)"
netless_shell = False
def _provider(self, model):
if model.startswith("fixture:"):
return "fixture", None, None
if model.startswith("claude"):
return "anthropic", "ANTHROPIC_API_KEY", None
return "openai", "ZAI_API_KEY", GOBANG_ZAI_URL
def account_mode(self):
return "API key from the environment (ZAI_API_KEY or ANTHROPIC_API_KEY)"
def configure(self, home, model, effort):
provider, key_env, base = self._provider(model)
d = os.path.join(home, ".config", "gobang")
os.makedirs(d, exist_ok=True)
lines = ["version = 1", "", "[toolchain]", 'aji = "aji"', "", "[model]", f'provider = "{provider}"']
if provider == "fixture":
shutil.copyfile(model[len("fixture:"):], os.path.join(d, "scenario.jsonl"))
lines.append('fixture = "scenario.jsonl"')
else:
lines += [f'model = "{model}"', f'key_env = "{key_env}"']
if base:
lines.append(f'base_url = "{base}"')
if effort:
lines.append(f'extra = {{ reasoning_effort = "{effort}" }}')
lines += ["", "[sandbox]", 'mode = "required"', "", "[context]", 'docs = "/docs"', ""]
cfg = "\n".join(lines)
with open(os.path.join(d, "gobang.toml"), "w") as f:
f.write(cfg)
return {".config/gobang/gobang.toml": cfg}
def env(self, model):
_, key_env, _ = self._provider(model)
if key_env is None:
return {}
key = os.environ.get(key_env)
if not key:
raise SystemExit(f"gobang: {key_env} is not set")
return {key_env: key}
def argv(self, model, effort, prompt):
return [self.binary, "run", "--json-events", "--in-place", "/work", "--state-dir", "/tmp/gobang",
"--config", "/home/agent/.config/gobang/gobang.toml", "--task", prompt]
def parse(self, path):
facts = {"tool_calls": 0, "usage": {"input_tokens": 0, "cached_input_tokens": 0, "output_tokens": 0}}
for e in _jsonl(path):
t, d = e.get("type"), e.get("data") or {}
if t == "TOOL_REQUESTED":
facts["tool_calls"] += 1
elif t == "MODEL_RESPONDED":
r = d.get("response") or {}
u = r.get("usage") or {}
facts["usage"]["input_tokens"] += u.get("input", 0)
facts["usage"]["cached_input_tokens"] += u.get("cache_read", 0)
facts["usage"]["output_tokens"] += u.get("output", 0)
if r.get("model_reported"):
facts["model"] = r["model_reported"]
elif t == "SESSION_CREATED":
facts["prompt_sha256"] = d.get("prompt_sha256")
elif t == "SESSION_FINISHED":
facts["gobang_state"] = d.get("state")
facts["gobang_reason"] = d.get("reason")
return facts
# aji exit codes for gobang's run outcomes (AGENTS.md of the aji repository).
_GOBANG_OUTCOME_CODE = {"accepted": 0, "returned": 0, "rejected": 1, "trapped": 4, "limit_exceeded": 5, "not_instantiated": 6, "blocked": 7}
def gobang_events(transcript_path):
"""(tool, arguments, result) for every tool call in a gobang transcript,
and the test commands of the session."""
calls, results, tests = {}, [], []
for e in _jsonl(transcript_path):
t, d = e.get("type"), e.get("data") or {}
if t == "CONFIG_RESOLVED":
tests = d.get("test_command_argv") or []
elif t == "TOOL_REQUESTED":
calls[d.get("call_id")] = (d.get("tool"), d.get("arguments") or "")
elif t == "TOOL_COMPLETED" and d.get("call_id") in calls:
tool, args = calls.pop(d.get("call_id"))
results.append((tool, args, d.get("output") or ""))
return results, tests
AGENTS = {a.name: a for a in (Codex(), Claude(), OpenCode(), Gobang())}
def available():
@@ -317,12 +433,31 @@ def command_events(agent_name, transcript_path):
m = re.match(r"Exit code (\d+)", text)
code = int(m.group(1)) if m else (1 if b.get("is_error") else 0)
out.append((pending.pop(b.get("tool_use_id")), code, text))
elif agent_name == "gobang":
continue # handled below from whole tool calls
elif agent_name == "opencode":
part = e.get("part") or {}
if e.get("type") == "tool_use" and part.get("tool") == "bash":
st = part.get("state") or {}
meta = st.get("metadata") or {}
out.append(((st.get("input") or {}).get("command", ""), meta.get("exit"), st.get("output") or meta.get("output") or ""))
if agent_name == "gobang":
# gobang's model gives no shell commands; its toolchain tools stand
# for the commands they run, with aji's exit code for their outcome.
results, tests = gobang_events(transcript_path)
for tool, _, output in results:
try:
o = json.loads(output)
except json.JSONDecodeError:
continue
outcome = o.get("outcome")
if tool == "aji_check":
out.append(("aji check", _GOBANG_OUTCOME_CODE.get(outcome, 2), output))
elif tool == "aji_run":
out.append(("aji run", _GOBANG_OUTCOME_CODE.get(outcome, 2), output))
elif tool == "run_tests" and o.get("ok"):
bad = (o.get("failed") or 0) + (o.get("errors") or 0)
out.append(("aji run; " + "; ".join(tests), 0 if bad == 0 else 1, output))
return out
@@ -427,6 +562,7 @@ def run_native(task_dir, lang_name, agent_name, model, out_dir, effort=None, see
if shutil.which("bwrap") is None:
raise SystemExit("native runs need bubblewrap")
ag = AGENTS[agent_name]
agent_env = ag.env(model) # fails before anything is created when a key is missing
task = task_mod.Task(task_dir)
profile = languages.load(lang_name)
lang = task.language(lang_name)
@@ -467,7 +603,9 @@ def run_native(task_dir, lang_name, agent_name, model, out_dir, effort=None, see
message = PREAMBLE.format(language=profile["instructions"]) + agent.task_message(task, workspace)
argv = ag.argv(model, effort, message)
sb = sandbox_argv(workspace, home, binds, path_dirs, docs, profile.get("env", {}))
env = dict(profile.get("env", {}))
env.update(agent_env) # values never enter the run record
sb = sandbox_argv(workspace, home, binds, path_dirs, docs, env)
for src, dst in cred_binds:
sb[sb.index("--chdir"):sb.index("--chdir")] = ["--bind", src, dst]
if ag.netless_shell:
+66
View File
@@ -257,6 +257,72 @@ class NativeTest(unittest.TestCase):
oc = native.AGENTS["opencode"].configure(home, "p/m", None)[".config/opencode/opencode.json"]
self.assertFalse(oc["tools"]["webfetch"] or oc["tools"]["task"])
def test_gobang_adapter(self):
"""gobang: configuration by model id, the key only in the
environment, and the facts and toolchain commands of its journal."""
from ajieval import context, native
g = native.AGENTS["gobang"]
home = tempfile.mkdtemp()
cfg = g.configure(home, "glm-5.3-flash", "high")[".config/gobang/gobang.toml"]
self.assertIn('provider = "openai"', cfg)
self.assertIn('key_env = "ZAI_API_KEY"', cfg)
self.assertIn('mode = "required"', cfg)
self.assertIn('docs = "/docs"', cfg)
self.assertIn('reasoning_effort = "high"', cfg)
self.assertIn('key_env = "ANTHROPIC_API_KEY"', g.configure(home, "claude-opus-5-5", None)[".config/gobang/gobang.toml"])
scenario = os.path.join(home, "s.jsonl")
open(scenario, "w").write("{}\n")
self.assertIn('provider = "fixture"', g.configure(home, "fixture:" + scenario, None)[".config/gobang/gobang.toml"])
self.assertTrue(os.path.exists(os.path.join(home, ".config", "gobang", "scenario.jsonl")))
self.assertEqual(g.env("fixture:" + scenario), {})
old = os.environ.pop("ZAI_API_KEY", None)
try:
with self.assertRaises(SystemExit):
g.env("glm-5.3-flash")
os.environ["ZAI_API_KEY"] = "zk-test"
self.assertEqual(g.env("glm-5.3-flash"), {"ZAI_API_KEY": "zk-test"})
self.assertNotIn("zk-test", json.dumps(g.configure(home, "glm-5.3-flash", None)))
finally:
os.environ.pop("ZAI_API_KEY", None)
if old is not None:
os.environ["ZAI_API_KEY"] = old
argv = g.argv("m", None, "PROMPT")
self.assertEqual(argv[:3], ["gobang", "run", "--json-events"])
self.assertEqual(argv[-2:], ["--task", "PROMPT"])
self.assertFalse(g.netless_shell)
def ev(seq, t, data):
return json.dumps({"v": 1, "session": "g", "seq": seq, "ts": "", "state": "S", "type": t, "data": data})
# gobang writes compact JSON, as aji does.
check_rejected = json.dumps({"ok": True, "outcome": "rejected", "groups": [{"code": "E3101", "severity": "error"}]}, separators=(",", ":"))
lines = [
ev(1, "SESSION_CREATED", {"prompt_sha256": "sha256:p"}),
ev(2, "CONFIG_RESOLVED", {"test_command_argv": ["sh test.sh"]}),
ev(3, "MODEL_RESPONDED", {"response": {"model_reported": "glm-5.3-flash", "finish_reason": "tool_use", "usage": {"input": 1000, "output": 50, "cache_read": 600}}}),
ev(4, "TOOL_REQUESTED", {"call_id": "c1", "tool": "aji_check", "arguments": "{}"}),
ev(5, "TOOL_COMPLETED", {"call_id": "c1", "tool": "aji_check", "output": check_rejected}),
ev(6, "TOOL_REQUESTED", {"call_id": "c2", "tool": "docs_read", "arguments": "{\"section\":\"QUICK.md#1-skeleton\"}"}),
ev(7, "TOOL_COMPLETED", {"call_id": "c2", "tool": "docs_read", "output": json.dumps({"ok": True, "text": "3\tEvery function lists its effects.\n"})}),
ev(8, "TOOL_REQUESTED", {"call_id": "c3", "tool": "run_tests", "arguments": "{}"}),
ev(9, "TOOL_COMPLETED", {"call_id": "c3", "tool": "run_tests", "output": json.dumps({"ok": True, "passed": 0, "failed": 1, "errors": 0})}),
ev(10, "MODEL_RESPONDED", {"response": {"finish_reason": "stop", "usage": {"input": 1200, "output": 10, "cache_read": 1000}}}),
ev(11, "SESSION_FINISHED", {"state": "FAILED", "reason": "verification_failed"}),
]
tr = os.path.join(home, "transcript.jsonl")
open(tr, "w").write("\n".join(lines) + "\n")
facts = g.parse(tr)
self.assertEqual(facts["tool_calls"], 3)
self.assertEqual(facts["model"], "glm-5.3-flash")
self.assertEqual(facts["gobang_state"], "FAILED")
self.assertEqual(native.normalize_usage(facts["usage"]), {"input": 2200, "output": 60, "cached_input": 1600})
cmds = native.command_events("gobang", tr)
self.assertEqual([(c, code) for c, code, _ in cmds], [("aji check", 1), ("aji run; sh test.sh", 1)])
prof = {"diagnostic_pattern": '"severity":"error"', "classify": {"check": ["aji check"], "test": ["aji run"]}}
m = native.cycles(prof, "sh test.sh", cmds)
self.assertEqual((m["first_check_accepted"], m["first_public_test_passed"], m["failed_verifier_cycles"], m["failed_test_cycles"]), (False, False, 1, 1))
events = context.tool_events_native("gobang", tr)
self.assertIn(("/docs/QUICK.md", "3\tEvery function lists its effects.\n"), events)
def test_usage_normalization(self):
from ajieval import native
self.assertEqual(native.normalize_usage({"input_tokens": 100, "cached_input_tokens": 60, "output_tokens": 5}), {"input": 100, "output": 5, "cached_input": 60})