Skip to content

fix(opencode): keep version probes from leaving folders in home - #1892

Closed
tridev-tej wants to merge 1 commit into
Tencent:mainfrom
tridev-tej:fix-issue-1888
Closed

tridev-tej wants to merge 1 commit into
Tencent:mainfrom
tridev-tej:fix-issue-1888

Conversation

@tridev-tej

Copy link
Copy Markdown

opencode makes its data, cache and state folders on every start, --version included, so the confined judge probes and opencodeMajorVersion left ~/.local/share/opencode, ~/.local/state/opencode and ~/.cache/opencode in home. new probeVersion moves those xdg homes into a temp dir it removes. session adapter probe unchanged: it only runs before an opencode session command. real cli, opencode 1.19.5, teamai doctor in a world: main leaves the three folders, this none. ledger 1 leak (~/.teamai/team-hooks), same on main.

Fixes #1888

… home

opencode makes its data, cache and state folders on every start, --version included. probe the version with those xdg homes in a temp dir that gets removed, for the confined judge probes and opencodeMajorVersion.
@github-actions

Copy link
Copy Markdown

No findings in the specified diff.

The PR description satisfies the real-CLI verification requirement: it records teamai doctor in a world with OpenCode 1.19.5, compares main against the fix, and identifies the remaining ledger leak as unchanged on main.

Review was read-only; no PR code was run, built, or installed.

@SaulMoro SaulMoro 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.

This was generated by AI during triage.

Approving at 3c8e6db.

What I checked

  • Red on main, green here. With main's exec.ts, confined.ts, opencode-version.ts and confined-launch.ts, the two new cases fail: "leaves nothing in the member's home…" and "probes a judge tool's version without leaving OpenCode's folders…". With this head, opencode-version.test.ts and tool-launch-confined.test.ts pass (31 tests), and typecheck passes.
  • Real CLI on POSIX, as a pair, with OpenCode on the world's PATH. Each fresh world ran teamai init --agent opencode, teamai pull and teamai doctor:
    • main (d1b2528): FAILED. ~/.cache/opencode, ~/.local/share/opencode and ~/.local/state/opencode were left in the world's HOME.
    • this head (3c8e6db): VERIFIED. None of the three exist afterwards. Doctor's OpenCode checks are the same on both builds ("installed", "skills directory is usable", "reads the skills teamai writes"), so the version still reads.
    • Uninstall check. The only thing left behind is home/.teamai/team-hooks, and main's world leaves the same, as you say.
  • Cleanup. The temp directory is removed in a finally, so a failing probe doesn't leave it either. The probe adds no process, only a mkdtemp/rm pair.

[P2 non-blocking]

  • Moving the XDG homes can break a probe through a version-manager shim. probeVersion now points XDG_DATA_HOME, XDG_CACHE_HOME and XDG_STATE_HOME at a temp directory, for every confined tool's probe and for opencodeMajorVersion. A tool installed through a shim that keeps its installs under $XDG_DATA_HOME won't find them there. mise, for example, defaults its data directory to $XDG_DATA_HOME/mise. The probe then returns an empty version, and teamai falls back to the assumed OpenCode major and best-effort isolation. Two ways to avoid it:

    • leave the environment alone, note which of OpenCode's three folders are missing before the probe, and remove only those afterwards;
    • redirect only for the opencode family, the one that creates them.

    I couldn't run a shim install here, so this is from mise's documented defaults, not a run.

CI review. No findings. We agree, apart from the P2 above.

Merge risk. Low. Only the version probe's environment changes, and the probe's output is read as before.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Thanks for this. A correction to my approval: #1888 names four sites that read OpenCode's version, and this PR covers three. The OpenCode session adapter's cli() (packages/tool-opencode/src/session-adapter.ts:479) still probes through Processes.probe, which is probeBinary with the member's environment, so it still leaves the folders behind.

#1895 adds the same helper and covers all four, so it is the one that should land for #1888. Once it merges, this PR is superseded and can be closed.

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.

Reading OpenCode's version leaves its data, cache and state folders in the member's home

3 participants