diff --git a/src/agent_env/agents/README.md b/src/agent_env/agents/README.md index 4258f5888..5abe0f237 100644 --- a/src/agent_env/agents/README.md +++ b/src/agent_env/agents/README.md @@ -115,7 +115,7 @@ framework: each turn is one `opencode run --format json` run, resumed in the con MCP servers go to the run's own inline config, and its JSON events are the turn's trajectory. Name it as `opencode`, its alias, or by its id, `@local/agentenv-framework/agents/opencode`. It calls the `[model]` endpoint as an OpenAI-compatible one, `/v1/chat/completions`, and takes its model from the prompt, else -`anthropic/claude-sonnet-4-6`. It declares `install/v1` too, into a container or onto a `vm` sandbox's Linux host, +`anthropic/claude-sonnet-5-5`. It declares `install/v1` too, into a container or onto a `vm` sandbox's Linux host, with glibc. Its folder's `README.md` covers the extensions it implements. `agents/letta-code/` runs [Letta Code](https://github.com/letta-ai/letta-code) behind the protocol's A2A agent diff --git a/src/agent_env/agents/agents/opencode/README.md b/src/agent_env/agents/agents/opencode/README.md index 6a9584cb3..858eaffd2 100644 --- a/src/agent_env/agents/agents/opencode/README.md +++ b/src/agent_env/agents/agents/opencode/README.md @@ -27,7 +27,7 @@ disk: subagent's session's, compaction's, the session title's and an answered retry's. The task's `Usage` is their sum, `input_tokens` counting the cache; a call answered without usage is counted in `unreported_calls`, and a refused one counts nothing. -- the model: the task's, else `OPENCODE_MODEL`, else `anthropic/claude-sonnet-4-6`; +- the model: the task's, else `OPENCODE_MODEL`, else `anthropic/claude-sonnet-5-5`; - every registered MCP server, the task's `peer_agents` tools included, as a remote server. Its `AgentEnv-Role` header is the role its registration names, unless the task has a role of its own; - every tool allowed, and the one that asks the user a question denied. diff --git a/src/agent_env/agents/agents/opencode/install.sh b/src/agent_env/agents/agents/opencode/install.sh index f4906aa40..f083a4156 100755 --- a/src/agent_env/agents/agents/opencode/install.sh +++ b/src/agent_env/agents/agents/opencode/install.sh @@ -106,6 +106,15 @@ chmod 0755 "$stage/uv-$uv_cpu-unknown-linux-musl/uv" printf '#!/bin/sh\nexec %s "$@"\n' "$(quoted "$root/npm/node_modules/opencode-ai/bin/opencode.exe")" > "$stage/opencode" chmod 0755 "$stage/opencode" +# The CLI's model calls go through the turn's model relay, in the agent's Python, which reads the system's CA +# certificates, and a bare image has none: such a target's agent trusts certifi's, from that Python, unless the trust +# lines name a bundle. +certifi=$root/venv/lib/python$PYTHON_VERSION/site-packages/certifi/cacert.pem +needs_cas= +on 'for f in /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /etc/ssl/ca-bundle.pem /etc/ssl/cert.pem + do [ -s "$f" ] && exit 0; done; exit 1' || needs_cas=1 +case ${AGENT_TRUST_ENV:-} in *SSL_CERT_FILE=*) needs_cas= ;; esac + # The model endpoint and CA, as the agent's environment, readable by its user only. { for name in LITELLM_API_KEY LITELLM_BASE_URL LITELLM_EXTRA_HEADERS; do @@ -113,6 +122,7 @@ chmod 0755 "$stage/opencode" done [ -z "${AGENT_TRUST_ENV:-}" ] || printf '%s\n' "$AGENT_TRUST_ENV" [ -z "${AGENTENV_CONTROL_TOKEN:-}" ] || printf 'AGENTENV_CONTROL_TOKEN=%s\n' "$(quoted "$AGENTENV_CONTROL_TOKEN")" + [ -z "$needs_cas" ] || printf 'SSL_CERT_FILE=%s\n' "$(quoted "$certifi")" # OpenCode's state, its sessions and skills, as the image keeps it under /data. printf 'A2A_PORT=%s\nOPENCODE_WORKSPACE_DIR=%s\nHOME=%s\n' \ "$(quoted "$port")" "$(quoted "$workspace")" "$(quoted "$root/data")" @@ -149,7 +159,7 @@ on "cd $r/npm && export PATH=$r/node/bin:\$PATH npm_config_cache=$r/cache/npm np && cd $r && export UV_PYTHON_PREFERENCE=only-managed UV_PYTHON_INSTALL_DIR=$r/python \ UV_CACHE_DIR=$r/cache/uv && bin/uv venv --quiet --clear --python $PYTHON_VERSION venv \ && bin/uv pip install --quiet --python venv/bin/python -r app/requirements.txt \ - && rm -rf $r/cache" + && rm -rf $r/cache && [ -s $(quoted "$certifi") ]" if [ "$mode" = container ]; then docker exec -d -u 0 "$target" sh -c "exec $r/app/run.sh $r > $r/agent.log 2>&1" diff --git a/src/agent_env/agents/agents/opencode/opencode_bridge.py b/src/agent_env/agents/agents/opencode/opencode_bridge.py index dbd71aa1e..816d5e28b 100644 --- a/src/agent_env/agents/agents/opencode/opencode_bridge.py +++ b/src/agent_env/agents/agents/opencode/opencode_bridge.py @@ -42,7 +42,7 @@ # The model a run uses when neither the task nor the agent-config names one; the # @ai-sdk/openai-compatible provider forwards it verbatim as the chat model. -DEFAULT_MODEL = os.environ.get("OPENCODE_MODEL", "anthropic/claude-sonnet-4-6") +DEFAULT_MODEL = os.environ.get("OPENCODE_MODEL", "anthropic/claude-sonnet-5-5") ERROR_MESSAGE_LIMIT = 4000 ROLE_HEADER = "AgentEnv-Role" # What agent-env gives an agent for [model.headers]: a JSON object of header names to values. diff --git a/src/agent_env/agents/agents/opencode/requirements.txt b/src/agent_env/agents/agents/opencode/requirements.txt index 494d4ed4e..c2b9f23d1 100644 --- a/src/agent_env/agents/agents/opencode/requirements.txt +++ b/src/agent_env/agents/agents/opencode/requirements.txt @@ -5,3 +5,5 @@ agentenv-framework-protocol[agent]>=0.1.643 jsonschema>=4.18,<5 # The model relay's server and client (model_relay.py). aiohttp>=3.9,<4 +# The CA bundle the relay trusts on an install target that has none of its own (install.sh). +certifi diff --git a/tst/unit/agents/opencode/test_image_contract.py b/tst/unit/agents/opencode/test_image_contract.py index 312715c54..06756cf19 100644 --- a/tst/unit/agents/opencode/test_image_contract.py +++ b/tst/unit/agents/opencode/test_image_contract.py @@ -70,11 +70,12 @@ def test_the_image_and_an_install_carry_every_module_the_server_imports(): assert needed <= set(_copied()) and needed <= installed, (needed, installed) -def test_the_requirements_are_the_protocol_floor_the_output_format_validator_and_the_relays_http(): +def test_the_requirements_are_the_protocol_floor_the_output_format_validator_the_relays_http_and_the_ca_bundle(): requirements = [line for line in (AGENT_DIR / "requirements.txt").read_text().splitlines() if line and not line.startswith("#")] - assert requirements == ["agentenv-framework-protocol[agent]>=0.1.643", "jsonschema>=4.18,<5", "aiohttp>=3.9,<4"] + assert requirements == ["agentenv-framework-protocol[agent]>=0.1.643", "jsonschema>=4.18,<5", "aiohttp>=3.9,<4", + "certifi"] def test_node_is_pinned_by_version_and_checksum_for_the_image_and_an_install(): diff --git a/tst/unit/agents/opencode/test_install.py b/tst/unit/agents/opencode/test_install.py index 32c5084c9..e51626a85 100644 --- a/tst/unit/agents/opencode/test_install.py +++ b/tst/unit/agents/opencode/test_install.py @@ -79,6 +79,43 @@ def test_an_installed_agent_runs_its_own_cli_and_its_node_and_python_only_where_ assert "node_modules/opencode-ai/bin/opencode.exe" in install_sh +CERTIFI = "SSL_CERT_FILE='/opt/agent/venv/lib/python3.12/site-packages/certifi/cacert.pem'\n" + + +@pytest.mark.parametrize("bundle, content, trust, written", [ + (None, "", "", CERTIFI), + ("etc/ssl/certs/ca-certificates.crt", "PEM", "", ""), + ("etc/pki/tls/certs/ca-bundle.crt", "PEM", "", ""), + ("etc/ssl/cert.pem", "PEM", "", ""), + ("etc/ssl/certs/ca-certificates.crt", "", "", CERTIFI), + (None, "", "SSL_CERT_FILE='/trust/ca-bundle.pem'", ""), +], ids=["no-bundle", "debian-bundle", "rhel-bundle", "alpine-bundle", "an-empty-bundle", "trust-lines-name-one"]) +def test_an_installed_agent_trusts_certifis_cas_only_on_a_target_with_none_and_no_bundle_named( + tmp_path, bundle, content, trust, written): + """The relay reads the system's CA certificates: the agent's environment names certifi's only where the target has + no bundle and the trust lines name none.""" + if bundle: + (tmp_path / bundle).parent.mkdir(parents=True) + (tmp_path / bundle).write_text(content) + + assert _ca_line(tmp_path, trust) == written + + +def _ca_line(target: Path, trust: str) -> str: + """What install.sh writes to the agent's environment for its CA bundle, its decision run against a target whose + ``/etc`` is ``target``'s.""" + install_sh = (AGENT_DIR / "install.sh").read_text() + lines = install_sh.splitlines() + quoted = next(line for line in lines if line.startswith("quoted() {")) + decision = install_sh[install_sh.index("certifi=$root/venv"):] + decision = decision[:decision.index("needs_cas= ;; esac") + len("needs_cas= ;; esac")] + written = next(line.strip() for line in lines if '"$needs_cas" ] || printf' in line) + on = f'on() {{ sh -c "$(printf %s "$1" | sed "s#/etc/#{target}/etc/#g")"; }}' + script = "\n".join([quoted, on, "root=/opt/agent PYTHON_VERSION=3.12", decision, written]) + return subprocess.run(["bash", "-c", script], env={"PATH": "/usr/bin:/bin", "AGENT_TRUST_ENV": trust}, + capture_output=True, text=True, check=True).stdout + + def test_an_installed_agent_keeps_opencodes_state_and_its_workspace_where_the_install_says(): install_sh = (AGENT_DIR / "install.sh").read_text()