Skip to content

fix(opencode): regenerate shared status plugin for OPENCODE_CONFIG_DIR - #22768

Closed
leilei3167 wants to merge 2 commits into
stablyai:mainfrom
leilei3167:fix/issue-22764-shared-status-plugin
Closed

leilei3167 wants to merge 2 commits into
stablyai:mainfrom
leilei3167:fix/issue-22764-shared-status-plugin

Conversation

@leilei3167

Copy link
Copy Markdown
Contributor

ELI5

Orca can still point OpenCode at an old shared config folder under its own user data. That folder kept an outdated status plugin that OpenCode 2 refuses to load. This change rewrites that shared copy whenever Orca installs the current plugin, so the folder OpenCode actually reads matches the fixed template.

What Changed

  • Before: in the managed / shared OPENCODE_CONFIG_DIR branch, buildPtyEnv only wrote orca-opencode-status.js into the user's global OpenCode config (~/.config/opencode). A leftover userData/opencode-hooks/shared copy with a pre-setup() server:-only default stayed on disk, and any shell that still exported that shared path kept failing with Missing key at ["default"]["setup"].
  • After: the same branch also materializes the current plugin into getSharedConfigDir() (userData/opencode-hooks/shared), so the path OpenCode loads and the path Orca refreshes stay aligned. Global discovery still returns {} (no new OPENCODE_CONFIG_DIR override).
  • Added a regression that seeds a stale server:-only shared plugin, calls buildPtyEnv with that shared dir, and asserts both the shared and global plugin files get the current template.

Why

#20407 / #22234 / #22440 fixed the generated template and duplicate-id install into the global plugins dir, but they did not refresh the legacy shared directory that older installs and inherited env still hand to OpenCode via OPENCODE_CONFIG_DIR. Rewriting that shared copy is the smallest fix that matches the load path without changing overlay behavior or re-introducing a forced config-dir override. Alternatives considered: stop exporting the shared dir and rely only on ~/.config/opencode (larger spawn/env cleanup, risks breaking shells that still inherit the shared path), or migrate users off the shared dir in place (out of scope for this residual load failure).

Linked Issue

Fixes #22764

Visual Proof

N/A — plugin file materialization on disk only; no UI or interaction change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Regression: pnpm exec vitest run --config config/vitest.config.ts src/main/opencode/hook-service.test.ts

  • Old red: with the shared rewrite removed, regenerates a stale shared legacy plugin when OPENCODE_CONFIG_DIR points at it left the shared file as server:-only.
  • New green: the same test passes; full hook-service.test.ts suite 35/35.
  • Platforms: pure filesystem materialization (macOS / Linux / Windows / SSH share the same buildPtyEnv path); no Electron UI run for this PR.

AI Disclosure

Review

  • Confirmed the managed branch still returns {} so global OpenCode discovery is not overridden.
  • Shared + global plugin files both get the current template when OPENCODE_CONFIG_DIR points at the legacy shared dir.
  • Line counts stay under ratchet caps (hook-service.ts 291/300, test 661/800).
  • Diff limited to hook-service.ts + its test; no overlay / spawn / shell-wrapper changes.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Linux is the reported failure site; the rewrite runs on every platform that uses OpenCodeHookService.buildPtyEnv. Overlay mode (user-set config dir ≠ shared) is unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

When OPENCODE_CONFIG_DIR still points at userData/opencode-hooks/shared,
also rewrite that copy so OpenCode does not keep loading a pre-setup()
template. Fixes stablyai#22764.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Shared-dir plugin refresh — OpenCodeHookService.buildPtyEnv now also writes the current template into <userData>/<legacyHooksDir>/shared in the managed branch, so an inherited OPENCODE_CONFIG_DIR that still points at opencode-hooks/shared no longer loads the stale pre-setup() server:-only module. The branch still returns {}, so no new OPENCODE_CONFIG_DIR override is introduced.
  • Regression test — seeds a stale server:-only shared plugin, calls buildPtyEnv(id, sharedDir), and asserts both the shared and global plugin files equal the current template. This genuinely fails without the added write.

Verification: pnpm exec vitest run --config config/vitest.config.ts src/main/opencode/hook-service.test.ts → 35/35 pass. The overlay branch (user-set config dir) is untouched, and the SSH/relay path uses a separate PluginOverlayManager, so neither is affected.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 62607de4-1dfd-49cc-acdc-9103c3bab7c2

📥 Commits

Reviewing files that changed from the base of the PR and between 13530b1 and d3e048d.

📒 Files selected for processing (2)
  • src/main/opencode/hook-service.test.ts
  • src/main/opencode/hook-service.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/opencode/hook-service.ts
  • src/main/opencode/hook-service.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

In the no-existing-config or managed-config branch, buildPtyEnv now attempts to write the plugin template to the resolved OpenCode config directory and the managed config directory independently. A failure in either write does not prevent the other attempt. Tests cover refreshing a stale shared plugin and handling a failed resolved-directory write.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to d3e04

The shared plugin is refreshed even if the global config write fails. No merge-blocking issue was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 13530

The change should repair stale plugins in the legacy directory without changing how the config directory is selected. The additional file write warrants review because an existing filesystem link could redirect it, and an interrupted update could leave the two copies different.

Retained concerns

  • Low · security · inferred: The new managed-directory write follows pre-existing symlinks. If a less-trusted actor can alter that directory, the write could be redirected outside the intended plugin location; that access prerequisite has not been established.
Security review details

Security Blast Radius

  • inferred — The additional write affects local userData plugin directories for OpenCode or OpenCode2. Evidence does not establish another tenant, service, or privileged deployment target.

Security Findings and Attack Paths

  • inferred — A planted symlink in the newly written shared path could redirect the plugin write. Exploitability depends on unverified access to the app's userData tree; this is not a verified privilege-escalation finding.

Trust Boundaries and Controls

  • observed — The equality check prevents an arbitrary inherited config-directory value from redirecting the new managed write. Unlike overlay installation, the managed write does not remove a pre-existing plugin-file link before writing.

Resilience and Maintainability Implications

  • inferred — The catch returns an empty environment even if the second write fails, so it does not signal that a legacy shared copy remains out of date. Successful repetition provides a recovery path.

Hardening Proposals

  • proposed — If the shared directory can be modified by less-trusted code, verify ownership and prevent symlink-following writes there. Staged replacement and explicit failure reporting could also reduce inconsistent-copy states.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: regenerating the shared OpenCode status plugin when OPENCODE_CONFIG_DIR uses the shared path.
Description check ✅ Passed The description is complete and aligned with the template. It explains the user impact, mechanism, rationale, linked issue, testing, platform considerations, and checklist status. It also states that …
Linked Issues check ✅ Passed PASS. The PR addresses issue #22764. In buildPtyEnv, the managed userData/opencode-hooks/shared directory is refreshed when OPENCODE_CONFIG_DIR is absent or points to that managed directory. The…
Out of Scope Changes check ✅ Passed PASS. The PR changes only buildPtyEnv and its tests. The independent write attempts and failure-path test directly support issue #22764. No unrelated behavior or files are changed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: cb553950-6bd6-48c8-9801-e6d8f50c05fa

📥 Commits

Reviewing files that changed from the base of the PR and between a0e2490 and 13530b1.

📒 Files selected for processing (2)
  • src/main/opencode/hook-service.test.ts
  • src/main/opencode/hook-service.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment thread src/main/opencode/hook-service.ts Resolved
Keep the managed OPENCODE_CONFIG_DIR write independent of the resolved
config-dir write so a failure on one path cannot leave a stale shared
plugin loaded.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Independent plugin writes — In the managed buildPtyEnv branch, the global ~/.config/opencode write and the shared <userData>/<legacyHooksDir>/shared write now run in separate best-effort try blocks, so the shared copy refreshes even when the global write throws. Addresses the CodeRabbit finding on hook-service.ts:141.
  • Failure-path regression test — New test blocks <resolved>/plugins with a file so the resolved-dir write throws, then asserts the shared plugin still receives the current template.

Verified hook-service.test.ts 36/36 pass and oxlint reports 0 warnings/errors on both changed files. The prior Pullfrog review had no findings or open threads; the CodeRabbit thread is resolved.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

nwparker commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded by merged #23500 and #24610 after reproducing #22764 with installed OpenCode 2.0.16 and reviewing this PR's complete two-file scope. Both shared and global copies refresh without adding a config-directory override, and shared refresh survives a blocked global installation. A real turn using the repaired shared directory reports Working → Done.

The current implementation refreshes existing legacy copies and inherited overlays; it avoids recreating an absent legacy directory. This is behavior coverage, not a claim that this branch was merged. Actual execution was on macOS; the original Ubuntu installation was not tested. Thanks @leilei3167 for the repair and regression intent, and @santiagofn for the report. Detailed reproduction is recorded on #22764.

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

Labels

None yet

Projects

None yet

2 participants