Skip to content

fix(agents): verify opencode 2.3.0 adapter against real CLI (#116) - #207

Open
Falguni-105 wants to merge 4 commits into
secfoo-com:mainfrom
Falguni-105:verify/opencode-cli-116
Open

Falguni-105 wants to merge 4 commits into
secfoo-com:mainfrom
Falguni-105:verify/opencode-cli-116

Conversation

@Falguni-105

Copy link
Copy Markdown

Covers one adapter for #116 (the issue notes one well-verified adapter is a complete PR).

Verified against @opencode/cli 2.3.0 (Windows x64, 2026-11-28) with a new scripts/record_agent.py that captures real stdout/stderr/exit code and refuses to save a transcript containing a key-shaped value.

What the recordings found and this PR fixes

  • Flag drift: v2 rejects --pure and --dir (flag_drift.json records the CLI's Unrecognized flag errors). The argv now uses --standalone, with the working directory supplied by Popen(cwd=...).
  • Security regression: v2 ignores the old OPENCODE_CONFIG_CONTENT / OPENCODE_PERMISSION env vars. With those alone, a write tool actually created proof.txt. The PR ships a v2 permissions array (read/glob/grep only) via OPENCODE_CONFIG; permission_denied.json records the same write being refused.
  • Auth failures are JSON events on stdout with empty stderr in v2; describe_failure() now surfaces the CLI's message.

Recordings (tests/fixtures/agents/opencode/2.3.0/, replayed by tests): success (secret-scanning --depth quick on examples/, 46675 input / 3382 output tokens, cost 0), auth_failure, timeout, permission_denied, flag_drift.

Docs: added the opencode row and a verification matrix with CLI version, date, verifier, install/auth/run/timeout/cost checks.

Test note: on this machine tests/test_agents/test_api.py has 15 pre-existing failures because langgraph is not installed. All new/affected tests and tests/test_docs_consistency.py pass.

@Falguni-105
Falguni-105 requested a review from vsn411 as a code owner November 27, 2026 18:36

@vsn411 vsn411 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, and welcome! This is the kind of verification #116 was written for. Real recordings turned up real drift:

  • --pure and --dir are rejected;
  • the v1 permission env vars are ignored, so a write actually happened;
  • auth errors arrive on stdout.

Each fix comes with a recording that proves it. The recorder's refuse-to-save check and the replay tests are great, and the verification matrix is the format we want for every adapter.

Two things before we merge, both about users who aren't on 2.3.0:

  1. opencode v1 is still the default install for many users. On npm, opencode-ai (the package most guides install) is still on the v1 line, with 1.19.6 as latest. @opencode/cli is the v2 line, with 2.4.2 as latest. This PR removes OPENCODE_CONFIG_CONTENT / OPENCODE_PERMISSION and switches the argv to v2-only flags. On a v1 binary, the run would either fail on --standalone or, if v1 ignores the unknown flag, run without the read-only policy. That's the same write-allowed state your recording caught for v2. Please make it fail closed. Either of these works:

    • Detect the version (opencode --version, once per run). Use the v1 argv and env vars for 1.x and the v2 ones for 2.x, and refuse with a clear message for an unknown major. Keep the v1 env vars set in both cases: v2 ignores them, so it costs nothing.
    • Support v2 only: check the version and return failed with "secfoo needs opencode 2.x (npm install -g @opencode/cli)" for 1.x.

    A recording against [email protected] would prove whichever you choose. Your recorder makes that easy.

  2. Local paths in the fixtures. The recordings contain the recording machine's home directory (C:\Users\<name>\...) about 200 times. That's personal data in a public repo, and it ties the fixtures to one machine. Could record_agent.py replace the home directory (Path.home(), in both \ and \\-escaped forms) with ~ before the secret check? Then re-record, or rewrite the five files with the same function. src/secfoo/report/evidence.py's _HOST_PATHS does the same thing for reports.

Small things:

  • The matrix credits "Shruti Singh" as the verifier, and the PR is from @Falguni-105. If you worked on it together, that's fine; please just confirm the credit is what you both want.
  • The opencode.py docstring says 2026-11-27, and the docs say 2026-11-28.

CI hasn't run yet because this is your first PR here. A maintainer will approve the workflow run.

@vsn411

vsn411 commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

A quick follow-up, since #214 (Copilot, still open) also adds its own scripts/record_agent.py. Its recorder drives the real secfoo adapter, so it checks the argv secfoo actually builds. We'd like to keep a single recorder, and suggest that one.

When you pick this up again, could you re-record opencode with it? Together with the two points above (fail closed on opencode 1.x, and ~ instead of the home path in the fixtures), that's all this needs. If you're working with @Shruti070107, you could coordinate directly.

The recorder now replaces the operator's home directory with ~ in raw, JSON-escaped, and nested-JSONL forms before writing and before the credential check. Rewrite the four Copilot 1.0.117 recordings so public fixtures no longer contain the recording machine's username.
Shruti070107 and others added 2 commits November 29, 2026 16:02
Check the installed opencode major once per run and launch only 2.x, with a clear install hint for 1.x or unreadable versions. Rewrite the five 2.3.0 recordings with the shared recorder's home scrub so local paths and usernames are not published, drop the duplicate recorder from this PR, credit Falguni-105 as verifier, and align the doc and adapter dates on 2026-11-28.
@Falguni-105
Falguni-105 force-pushed the verify/opencode-cli-116 branch from ed49f42 to 8fc3692 Compare November 29, 2026 10:52
@Falguni-105

Copy link
Copy Markdown
Author

Addressed the requested changes:

  1. Fail closed on opencode 1.x. OpenCodeAdapter.run() now checks opencode --version once per run and launches only major 2. A 1.x binary, a future unknown major, or an unreadable version returns failed with secfoo needs opencode 2.x (npm install -g @opencode/cli) before any process is started. Added coverage for 1.x, 3.x and unreadable versions, plus a test that parses the npm version banner. I chose the v2-only option; I don't have [email protected] installed here, so I did not add a v1 CLI recording.

  2. Local paths and one recorder. Removed this PR's duplicate scripts/record_agent.py and based the branch on the shared recorder from fix(agents): scrub home paths from recorded fixtures #217. Rewrote all five opencode 2.3.0 recordings with that recorder's scrub_home(), so no home paths remain, and added a regression test that checks the fixtures.

  3. Credit and date. The verifier in the matrix and in all five recordings is now Falguni-105; the adapter docstring and the matrix both say 2026-11-28. I also merged the duplicated verification matrices into one table and updated the troubleshooting note to describe the v2-only check.

Verification: pytest -q tests/test_agents/test_opencode.py tests/test_agents/test_opencode_recordings.py tests/test_agents/test_record_agent.py → 21 passed; ruff check . clean; git diff --check clean.

I can't request a re-review through the API from a fork, so this is the nudge — please take another look when you have a moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants