Repository navigation
Conversation
Signed-off-by: Loi Nguyen <vanloi999@gmail.com>
348b6ce to
af7691f
Compare
Independent confirmation (Windows 11, OpenCode CLI, rtk 0.47.0)I reproduced the silent failure from #3326 on OpenCode CLI on Windows — two stacked bugs:
After working around both, I hit a third subtlety that this PR already handles correctly: I independently arrived at the same approach as this PR (Node My working plugin, matching this PR's approach: import { execFileSync } from "node:child_process"
import type { Plugin } from "@opencode-ai/plugin"
const run = (args: string[], timeout = 5000): string | null => {
try {
return execFileSync("rtk", args, { encoding: "utf8", timeout, windowsHide: true })
} catch (e) {
// rtk uses non-zero exit codes as status signals; stdout may still be valid
const out = (e as { stdout?: string | Buffer }).stdout
return typeof out === "string" || Buffer.isBuffer(out) ? String(out) : null
}
}
export const RtkOpenCodePlugin: Plugin = async () => {
if (run(["--version"]) === null) return {}
return {
"tool.execute.before": async (input, output) => {
const tool = String(input?.tool ?? "").toLowerCase()
if (tool !== "bash" && tool !== "shell") return
const args = output?.args
if (!args || typeof args !== "object") return
const command = (args as Record<string, unknown>).command
if (typeof command !== "string" || !command) return
const rewritten = run(["rewrite", command])
if (rewritten === null) return
const trimmed = rewritten.trim()
if (trimmed && trimmed !== command) {
;(args as Record<string, unknown>).command = trimmed
}
},
}
}Notes:
Would be great to see this merged so |
|
I opened #3837 targeting current |
|
Closing this in favour of #4187, which covers both the default export the OpenCode loader needs (#2516) and the move from Bun's |
Summary
$helper and Unix-onlywhichprobe with NodeexecFileCloses #3326
Test plan
cargo fmt --all --checkcargo clippy --all-targetscargo testrtkbinary, verifying literal command arguments and nonzero-exit stdout handling