#!/bin/bash # # patch-roo-code.sh # # Roo Code (rooveterinaryinc.roo-cline) looks for a bundled ripgrep binary and # throws "Could not find ripgrep binary" inside remote/dev containers. This # script patches the remote extension.js so it uses the system-installed # ripgrep instead. # # Usage: # patch-roo-code.sh One-shot patch (idempotent, safe to re-run) # patch-roo-code.sh --watch Keep watching for (re)installs/updates of the # extension and patch automatically # # Environment overrides: # RG_PATH ripgrep binary to inject (default: /usr/bin/rg) # EXT_ROOT VS Code server extensions dir (default: $HOME/.vscode-server/extensions) # PATCH_ROO_INTERVAL poll interval in seconds for --watch (default: 30) set -u RG_PATH="${RG_PATH:-/usr/bin/rg}" EXT_ROOT="${EXT_ROOT:-$HOME/.vscode-server/extensions}" # Returns: 0 = patched, 1 = already patched / string not found, 2 = extension not found patch_once() { local roo_remote_js roo_remote_js=$(ls -d "$EXT_ROOT"/rooveterinaryinc.roo-cline-*/dist/extension.js 2>/dev/null | tail -n1) if [ -z "$roo_remote_js" ]; then echo "Roo Code extensie niet gevonden in $EXT_ROOT." return 2 fi if ! grep -q 'Could not find ripgrep binary' "$roo_remote_js"; then echo "String al aangepast of niet gevonden." return 1 fi if command -v python3 >/dev/null 2>&1; then python3 - "$roo_remote_js" "$RG_PATH" <<'PYEOF' import sys path, rg_path = sys.argv[1], sys.argv[2] with open(path, 'r') as f: code = f.read() patched = code.replace( 'throw new Error("Could not find ripgrep binary")', 'return "%s"' % rg_path, ) with open(path, 'w') as f: f.write(patched) PYEOF else sed -i "s|throw new Error(\"Could not find ripgrep binary\")|return \"$RG_PATH\"|g" "$roo_remote_js" fi echo "Remote Roo Code succesvol gepatcht op de server! ($roo_remote_js)" return 0 } if [ "${1:-}" = "--watch" ]; then # The extension is installed/updated at runtime (when VS Code connects), so # poll periodically and only log when an actual patch was applied. while true; do if patch_once >/dev/null 2>&1; then echo "[$(date '+%Y-%m-%d %H:%M:%S')] Remote Roo Code succesvol gepatcht op de server!" fi sleep "${PATCH_ROO_INTERVAL:-30}" done fi patch_once