Repository navigation
Merged
Merged
Conversation
origin/main adds mini-swe-agent as a CLI Base Agent (Infini-AI-Lab#49), ASPIRE (Infini-AI-Lab#74), the macOS process stop (Infini-AI-Lab#88) and the wire meter stop (Infini-AI-Lab#87). Every conflict was both sides adding a fifth CLI to the same lists and docs: both are kept (mini-swe-agent, then opencode). The "takes no login" checks read one list, login.NO_LOGIN = ("pi", "mini-swe-agent", "opencode"), where main had ("pi", "mini-swe-agent") inline. The docs lists that name the CLI agents and deployment hosts now name both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…paction usage - The adapter's tools reach an OpenCode acting agent through the Base Agent's tool server: OpenCode 2.2 waits at most 2 s for an MCP server it starts (STARTUP_GRACE_MS) and the adapter's takes ~3 s, so the first request often went without them. hosts/opencode.prepare takes serve_tools; docs say so. - The prompt is OpenCode's stdin, not an argument (E2BIG past 128 KiB). - A binding's extra_body becomes the OpenCode model's options; the effort setting outranks its reasoning_effort. - Usage counts compactions' model calls, which `run --format json` never streams: this call's share of the session's totals in OpenCode's database (read-only, immutable, nothing followed out of the home), a resumed session's earlier totals taken off (_this_call, now with `fields`). - parse_log reads OpenCode's stream by its name. - The AHE Evolver's texts name OpenCode's stream (agent-opencode.jsonl) as they name Pi's and mini-swe-agent's (Infini-AI-Lab#91). - The deployer's docstring gives AGENTS.md discovery's real boundary. Tests: the first request offers the adapter's tools (real binary); a prompt past ARG_MAX; extra_body and effort; compaction usage from a stand-in database and from the real binary (mid-run compaction, then a resume). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
There was a problem hiding this comment.
Thanks for the PR. We reviewed it in two rounds (our own read plus an independent Codex review each round) and checked every finding against the OpenCode 2.2.6 binary or its source. The fixes are pushed to this branch as one commit, 80e04b1, after a merge of current main (52c0011). Each code fix has a test that fails without it.
Three-layer abstraction
It follows docs/framework/agent-layers.md:
- Layer 2. OpenCode is a Base Agent: a
CliAgentsubclass inCLIS, with its stream reader inrecords.pyandtrajectory.py. - Layer 1. Its model binding is
Binding.opencode_provider()inbackends.py. - Layer 3. The workspace Acting Agent is reused, and the
opencodeEvolver is a method directory. - Shared runner.
OpenCodeuses only hooks that already exist.
As with mini-swe-agent, _deploy in acting/workspace.py branches on the backend to choose who serves the adapter's tools. The fix below adds opencode to that branch.
What we patched (80e04b1)
| Before | After | |
|---|---|---|
| Adapter tools on the first request | The deployment's opencode.json named a local MCP server that OpenCode starts itself. OpenCode 2.2 waits at most 2 s for a starting server (STARTUP_GRACE_MS, hard-coded), and the adapter's server takes about 3 s. So the first request often went without the adapter's tools: in 5 of 8 runs with 1 s of model latency, and the PR's own integration test failed about 1 run in 3. |
The acting agent serves the adapter's tools through the Base Agent's tool server, which runs before OpenCode starts, as it already does for containers and mini-swe-agent. hosts/opencode.prepare takes serve_tools. commands.md notes the limit for a standalone hermit deploy --host opencode that runs opencode run right away. |
| Long prompts | The prompt was a command-line argument, so a prompt past 128 KiB failed with E2BIG before OpenCode started. |
The prompt goes on stdin, which opencode run reads to its end. |
extra_body |
opencode_provider() dropped the binding's extra_body (for example chat_template_kwargs). |
It becomes the OpenCode model's options, which reach the request body (checked with the binary). An explicit effort outranks its reasoning_effort. |
| Compaction usage | Only step_finish events were counted. OpenCode's compaction calls, and the summaries it writes ahead of one, are never streamed by run --format json, so tokens and cost were undercounted for long or resumed sessions. |
After each run, this call's share of the session's totals is read from OpenCode's database in the session's home
8000
. Earlier totals of a resumed session are taken off through the existing _this_call ledger, which now takes fields. Each field is the larger of the stream's count and the database's. The database is opened read-only as an immutable file, and nothing is followed out of the home. If it cannot be read, the stream's usage is kept and a warning is printed once. |
| AHE texts (#91, from the main merge) | #91 names each acting agent's own event stream in the AHE Evolver's texts. This PR adds agent-opencode.jsonl to STREAMS but not to STREAM_TEXTS, so its test failed, and an OpenCode stream would have been described as agent-codex.jsonl. |
STREAM_TEXTS names OpenCode's stream as it does Pi's and mini-swe-agent's (the OpenCode event stream, `opencode run --format json` event stream). The AHE template still refuses an OpenCode workspace, so this keeps the texts consistent. |
parse_log |
The generic reader fell through to Claude Code's parser for opencode and returned (None, []). |
It dispatches to parse_opencode. |
| Docs | The deployer's docstring put the end of AGENTS.md discovery at the Git root. |
It gives OpenCode's actual boundary. |
Tests:
- New: the first request offers the adapter's tools (real binary); a prompt past
ARG_MAX;extra_bodywitheffort; compaction usage from a stand-in database; compaction usage from the real binary, with a mid-run compaction and then a resume. pytest --changed --base origin/mainselected every group, since the PR touches shared code. Run with mini-swe-agent installed and OpenCode 2.2.6 on PATH: 1270 passed and 70 skipped. One test failed: the AHE stream-naming test, which arrived with #91 in the main merge. It is fixed by the AHE row above, and the AHE tests then give 230 passed and 6 skipped.
Left for follow-ups (not blocking)
- Redeploy keeps removed skills.
copy_skillsmerges into the skills directory and never removes anything. This holds for every workspace host, so it is filed as #96. - Inherited MCP servers. A parent folder's
opencode.jsoncan add MCP servers when the sandbox is off. The PR already lists this as a known limit. - Compaction call count. A compaction counts as one call. A retry inside it, such as OpenCode's reminder when a summary misses the template, shows only in its tokens.
- Database schema. The usage read depends on OpenCode 2.2's
session_v2andsession_messagetables. A later version that changes them falls back to the stream's usage, with the warning.
Minor, recorded only:
last_messagefalls back to an earlier message's text when the last one has none.effortis passed to the model unchanged, as for Pi.
🤖 Generated with Claude Code
6 of 7 tasks
10 of 12 tasks
iamziyuzhao
added a commit
that referenced
this pull request
Nov 10, 2026
main gained #91 (the AHE Evolver's texts name a Pi or mini-swe-agent acting agent's stream), #94 (OpenCode as a CLI Base Agent), #97 (hermit deploy retires skills the adapter no longer exports) and #99 (agent skills for this repository). #94 adds OpenCode at the places this branch adds dsh, so 36 files conflicted. Each conflict keeps both sides, OpenCode before dsh: - CLIS, the readers (records.parse_log, trajectory's STREAM_HOSTS, READERS and MARKS, the AHE debugger's STREAM_TEXTS) and every list of CLIs name both, dsh last; cli.py's Dsh part follows OpenCode's; - main's NO_LOGIN replaces this branch's tuples in login.py, isolate.py and acting/workspace.py, and gains "dsh"; - a comment that no longer fits 120 columns with both names is on its own line; - docs: both names in each list. docs/methods/agent.md's dsh learner now "signs in as the pi learner does", since OpenCode's sentence stands between them; in docs/methods/ahe_adapter.md, #91's general wording ("the one its CLI wrote") replaces this branch's list of streams. dsh does not call #97's check_skills and retire_skills yet; the next commit does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
10 of 11 tasks
19 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
Adds OpenCode (
opencode, v2.2.6) as a CLI Base Agent besidecodex,claude,piandmini-swe-agent, as oneCliAgentsubclass. It can act (agent.base: opencode) and learn (the newopencodeEvolver). It follows Pi's pattern: a modelreference only (no login), no roles, no web search.
hermit/agent/model/backends.py): a<backend>/<model>reference becomes OpenCode's config providerhermit(Binding.opencode_provider): its OpenAI-compatible package (@ai-sdk/openai-compatible, shipped in thebinary), the backend's URL, the key written as
{env:VARIABLE}(never the value) and the context window. OpenCodeis bound for chat completions only (
NEEDS["opencode"] = "chat"), sohermit checkandtrainrefuse a backendwithout them.
hermit/agent/base/cli.py,class OpenCode): runsopencode run --standalone --format jsonin aprivate home (
HOMEand the four XDG folders), with update and catalog requests and Claude Code's files(
~/.claude,.claude/) switched off (OPENCODE_DISABLE_AUTOUPDATE,_MODELS_FETCH,_CLAUDE_CODE).OPENCODE_CONFIG_CONTENT), which outranks aworkspace's
opencode.json: the provider,enabled_providers: [hermit], the permissions, no sharing, nosnapshots, and the system instructions' file. The call's tools are the home's config (
OPENCODE_CONFIG) as anMCP server with
codemode: false, so the model is offered them directly rather than through code mode, with a1800 s timeout.
question(no one answers),subagent(no roles),execute(code mode),webfetchandwebsearch(they reach the network past the sandbox),opencode_*. The same permissions are given to the agentthe session runs (
default_agent: build,agent.build.permission): an agent-level permission in a workspace'sor a parent folder's
opencode.jsonwould otherwise outrank the inline top-level ones.skills, which the acting agent sets fromdeployed["skills"]; none for theEvolver):
permission.skilldenies every other, so a parent folder's.agents/skills(OpenCode 2.2 looks up to/, and reads no variable that stops it) offers nothing.outcome()reads the finalerrorevent:provider.rate-limit,provider.internal,provider.transportandprovider.timeout(or a 429/5xx status)set
unavailable, so the acting agent runs the task again;provider.auth,provider.quota(a 402),provider.invalid-request,provider.content-filterandprovider.unsupported-operation(or 400/401/403/404)set
rejected. Other types (provider.invalid-output,provider.unknown) leave the sessionfailedonly. Nothing isread from the error's wording, and the shared
UNAVAILABLEregex is not used._sign_inrefuses aloginand a run without a bound provider before OpenCode starts,so no file of the user's OpenCode data folder is ever copied. Roles, web search and container isolation are
refused with
Unsupported.background service, which would mix sessions across homes and parallel tasks: every session passes
--standalone(a private server). And OpenCode works in the directory its inheritedPWDnames, not the one itis started in:
dropped_env()dropsPWD(and every inheritedOPENCODE_*), so it works in the workspace.--title hermitsaves a title-generation request;--thinkingkeeps reasoning in the stream; resume passes--session <id>; effort becomes the model'sreasoningEffort; usage and trajectory are read from the events(
records.parse_opencode,trajectory.opencode_steps,agent-opencode.jsonl); a bound model's cost follows itsprice, as Pi's does.
hermit/hosts/opencode.py(hermit deploy --host opencode):AGENTS.md, the project'sopencode.json(the adapter's tools as a local MCP server,codemode: false, 120 s timeout) and.opencode/skills/; roles and hooks are named inAGENTS.md, as for Pi. OpenCode loads these with no trust step.hermit/agent/acting/workspace.py,agent.py),AgentEvolver, the config(
hermit/config.py,defaults.yaml) acceptopencode. Newhermit/agent/evolver/methods/opencode/Evolver(prompts as Pi's;
home: [],web_search: false).workspace._check,isolate.py's config check,login.evolver_problems), which main writes as("pi", "mini-swe-agent")inline, now read one list,login.NO_LOGIN = ("pi", "mini-swe-agent", "opencode"); Pi's and mini-swe-agent's messages are unchanged.CLI_KINDS,CLI_AGENTS,NEEDS,STREAM_HOSTS,READERS,MARKSandCLISgainopencode(aftermini-swe-agent). No sandbox behaviour changes: the onlyisolate.pyline changed is that config check.origin/main(962a604, after mini-swe-agent: a Base Agent, an acting agent and a deployment host #49 mini-swe-agent, Add ASPIRE: the aspire template and Evolver, with a Robosuite example #74 ASPIRE, Stop the wire meters a launcher starts once its runs end #87, Stop a CLI session's processes on macOS too #88; thenee27441, after GPUs in the sandbox (environment.gpu); ASPIRE's simulator confined with them #93GPUs in the sandbox, with no conflict): every conflict was both sides adding a CLI to the same lists and docs; both
are kept. GPUs in the sandbox (environment.gpu); ASPIRE's simulator confined with them #93's
environment.gpuapplies to an OpenCode acting agent's task sandbox as to any other; it is offunless set and needs nothing of OpenCode's.
agent-layers.md,task.md,evolver.md,custom-evolver.md,methods/agent.md,model-backends.md,config-fields.md,configuration.md,compatibility.md,installation.md,commands.md,adapter.md(anOpenCode column in the deploy mapping and an OpenCode workspace tree),
ahe_adapter.md,what-is-a-harness-adapter.md,faq.md,docs/web/index.html, CHANGELOG. Two lines that main's mini-swe-agent: a Base Agent, an acting agent and a deployment host #49 left namingno mini-swe-agent (
commands.md's--hostlist,adapter.md's rewritten files) name it too.maintenance release v1.19.5; the deprecated 1.x config keys this uses (
provider,permission) work in 2.2.6,but 1.x itself is not tested.
Validation
Run on Linux with bubblewrap 0.9.0, Python 3.12.9, OpenCode 2.2.6 (release binary, checked against the release's
sha256 digest) and Pi 1.5.0. No real provider was used: a local scripted chat-completions server stands in for
the model.
python -m pytest --integration(full suite;--changedselects every group for this change), on the headee27441tests/core/test_opencode_agent.py --integration(18 tests: 15 offline, most replaying a recorded stream; 3 with the realopencode)962a604: OpenCode, mini-swe-agent, Pi, CLI agent, isolate, deploy, selection, backends, the installed-CLI sandbox test, with--integrationmini-swe-agentextra, not installed here; CI installs it)ee27441:test_opencode_agent.py,test_sandbox.py,test_isolate.py, with--integrationtest_inside_the_sandbox_the_hidden_paths_are_empty, the.venv-in-checkout failure below)PWDkept (revertingdropped_env),test_opencode_runs_in_its_home_…and the unsandboxed integration test fail; without the agent-level permissions and the skill allowlist, the unsandboxed integration test fails (questionandwebfetchoffered)hermit check/train/eval, sandbox enforced, OpenCode acting and learning, on the docs' toy task (first_trainingdata,prompt-only@1.0), on962a604(before #93, which changes nothing it uses: noenvironment.gpu)check_spec(passed); test split: untrained (--adapter root) 0.0, trained (--adapter final) 1.0docs/_examples/first_training: check, train, eval final), before the mergedocs/build.shequivalent (sphinx-build -W --keep-going), onee27441Failures: the same 4 as without this change: 3 in
examples/clbench_database(golden parity; they also failon a clean extract of
origin/main) andtest_inside_the_sandbox_the_hidden_paths_are_empty, which fails becausethis checkout keeps
.venvinside the repository.Fixtures (
tests/fixtures/opencode/) are OpenCode's output unchanged (they hold no host path), recorded throughmake("opencode").run: success, resume, 500, 429, a refused connection, 401 and 402.Sandbox records of the toy run on
962a604:learner-1.json / rollout-1.json (excerpt)
(
CODEX_HOMEis in the sandbox'sALWAYSlist and was set in the shell; unrelated to this change.)Not verified: reaching a real provider, directly or through the sandbox's allowlist proxy (OpenCode honours
HTTPS_PROXYper its documentation, not from a run); macOS; OpenCode 1.x.Known limits:
opencode_worktree_removeis offered and runs althoughopencode_*is denied (no permission or 1.xtoolsswitch reaches it in 2.2.6); it acts only on worktrees of the session's own project.
AGENTS.md,opencode.json(instructions, MCP servers, agents) and.opencode/(as Codex readsAGENTS.mdto that root);the permissions and the skills stay held. Inside the run's sandbox no parent folder is shown.
--sessionid makes OpenCode start a new session under that id rather than fail.stdinis not used): a prompt over the system's argument limit fails to start.hermit convert --targetis not extended; AHE's middleware refuses a copy deployed into an OpenCode workspace.Review
agent.base: opencode,evolver.base: opencode,agent.name: opencode, anopencode:settings section,hermit deploy --host opencode.the inline config holds the key's variable name, never its value.
NO_LOGINlist (three checks, one of them inisolate.py's config validation,no sandbox behaviour); the registries listed under Change.
unavailableand retried by theacting agent, then an error (
test_the_acting_agent_runs_a_task_again_…); a 401 isrejected; a session withoutan answer is
failedand becomes an error record, never a wrong answer.make("opencode").run, the acting agent'srun,hermit deploy,hermit trainandhermit eval. Stand-ins only at the edges (the CLI, the model).tests/core/; the fixtures are registered intests/selection.py(CORE) andtests/README.md;test_selection.py'sBUILT_INgainsopencode;test_an_installed_cli_starts_with_only_its_own_pathsgains it.outside
integrationtests, which skip withoutopencode.PWDat a directory of its own, so a regression fails it rather thanwriting outside
tmp_path.CliAgentinside the task and evolver sandboxes; all of itsvariables come from
home_env(); see the records above.isolate.py's config check now readsNO_LOGIN; no change to what asandbox shows or allows. Please confirm this counts as no sandbox change.
separate agent (Opus 5.5, high effort) reviewed commit
b36e198against the general, test and sandbox checklists, reproduced the validation numbers and probed the real binary.
Findings and resolution:
opencode.jsoncould give the build agent its own permissions(
webfetch,questionback), and.agents/skillsfrom parent folders reached the model; two of the variables(
OPENCODE_DISABLE_EXTERNAL_SKILLS,_LSP_DOWNLOAD) do not exist in 2.2.6. Fixed: the permissions on theagent, the skill allowlist, the two variables removed; the integration test adds such a parent folder.
opencode_*does not stopopencode_worktree_remove. Not fixable from config in 2.2.6; documented.provider.quotaadded torejected(recorded 402 fixture); the reststay
failed.against the real binary;
hermit deploy --host opencodehas a test. Docs:adapter.md(rewritten files, anOpenCode workspace tree),
commands.md(--host),ahe_adapter.md. Fixed.ff65173) and the merges withorigin/main(962a604,ee27441).Both are covered by the tests and checks above, run by the author.
🤖 Generated with Claude Code