Skip to content

fix(hooks): replace zx shell with Node child_process in OpenCode plugin - #3837

Closed
amnesiaof wants to merge 1 commit into
rtk-ai:developfrom
amnesiaof:fix/opencode-plugin-node-child-process
Closed

amnesiaof wants to merge 1 commit into
rtk-ai:developfrom
amnesiaof:fix/opencode-plugin-node-child-process

Conversation

@amnesiaof

Copy link
Copy Markdown

Summary

  • replace the Bun-only $ shell helper and Unix-only which probe with Node execFile in the OpenCode plugin
  • pass rewrite commands as literal subprocess arguments, no shell involved
  • keep successful rewrite stdout even when rtk rewrite exits non-zero (exit 3 = permission-gated rewrite)
  • update the three doc references to the zx library
  • add a regression test for the embedded plugin template

Why

The current plugin fails silently in two environments:

  1. OpenCode Desktop / Node runtime: $ is undefined in the plugin context, so $`which rtk` throws TypeError: $ is not a function, the plugin factory crashes, and no hooks are registered — nothing is surfaced to the user.
  2. Windows CLI: which does not exist.

A third subtlety: rtk rewrite uses non-zero exit codes as status signals (exit 3 with valid stdout such as rtk git status), so stdout must be resolved regardless of the exit code.

Test plan

  • cargo fmt --all --check
  • cargo clippy --all-targets
  • cargo test — test_opencode_plugin* pass (3/3). Note: 18 pre-existing failures in core::stream::tests on Windows ("program not found" — tests spawn Unix utils like cat/echo), present on a clean develop tree as well, unrelated to this change.
  • Functional test of the plugin under Bun (@opencode-ai/plugin contract): "git status" → "rtk git status", PowerShell commands pass through unchanged, already-prefixed rtk ... commands are not double-prefixed
  • Live verification on Windows 11 + OpenCode CLI: hook fires, rtk gain tracks savings

Closes #3326
Related: #1993, #3330 (independent fix, same root causes; this PR targets current develop)

Important: All PRs must target the develop branch (not master).
See CONTRIBUTING.md for details.

The OpenCode plugin used the Bun-only \$ shell helper and a Unix-only
'which' probe, which made it silently fail in two environments:

- OpenCode Desktop and any Node runtime: \$ is undefined in the plugin
  context, so \\$\\\which rtk\\\\ throws TypeError, the factory crashes,
  and no hooks are registered (no error surfaced to the user)
- Windows CLI: 'which' does not exist

Replace both with node:child_process execFile:

- probe with 'rtk --version' (also verifies rewrite support)
- pass arguments as a literal array, no shell involved
- windowsHide: true to avoid console window flashes on Windows
- resolve stdout regardless of exit code, because 'rtk rewrite' uses
  non-zero exit codes as status signals (exit 3 = permission-gated
  rewrite) while still emitting the rewrite on stdout

Also update the three doc references to the zx library and add a
regression test asserting the embedded plugin template no longer
references \$ or 'which rtk'.

Verified on Windows 11 + OpenCode CLI: hooks fire, git commands are
rewritten to rtk git, PowerShell commands pass through unchanged,
double-prefixing of already-rewritten commands is avoided.

Closes #3326
Related: #1993, #3330

Signed-off-by: amnesiaof <dolombovskyyalexs@gmail.com>
@CLAassistant

CLAassistant commented Sep 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@KuSh

KuSh commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Closing in favour of #3330, which makes the same execFile change to the OpenCode plugin and has a green CI run across the Linux, macOS and Windows test matrix. #3330 still needs a rebase onto current develop, which is the work done on this branch, so a note there pointing at it would be useful. Review and comments are welcome on #3330.

@KuSh KuSh closed this Sep 6, 2026
@KuSh KuSh added the duplicate This issue or pull request already exists label Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk init --opencode plugin silently does nothing on Desktop ($ is not a function) and on Windows (which not found)

3 participants