#!/bin/bash # # Purpose : Find the AI agents' real commands, outside the sandbox's own # (sandbox/bin), and the sandbox runtime. Sourced by configure and # sandbox/agent. Needs CONNECTOR. SANDBOX_BIN="$CONNECTOR/sandbox/bin" FC_TOOLS="$HOME/.local/share/federated-connector" # Where the agents' installers put them, in case your shell's PATH doesn't # have them yet (e.g. right after installing) AGENT_DIRS="$HOME/.local/bin:$HOME/.opencode/bin:$HOME/.hermes/bin:/usr/local/bin:/usr/bin" # The real command for an agent: the first on PATH, or in AGENT_DIRS, that # isn't in sandbox/bin agent_path() { local dir bin_dir IFS=: bin_dir="$(realpath "$SANDBOX_BIN" 2> /dev/null)" for dir in $PATH:$AGENT_DIRS; do [ -n "$dir" ] && [ -d "$dir" ] || continue [ "$(realpath "$dir")" = "$bin_dir" ] && continue if [ -x "$dir/$1" ] && [ ! -d "$dir/$1" ]; then echo "$dir/$1" return 0 fi done return 1 } agent_installed() { agent_path "$1" > /dev/null } # Run an agent's real command rather than its sandboxed one: setting an agent # up writes outside its sandbox unsandboxed() { local agent="$1" real shift real="$(agent_path "$agent")" || { echo "$agent isn't installed."; return 127; } "$real" "$@" } # srt, and the Node.js it runs with: Federated Connector's own, or one # already installed srt_path() { PATH="$FC_TOOLS/srt/bin:$FC_TOOLS/node/bin:$PATH" command -v srt }