Fallback for existing sandbox and name collision

This commit is contained in:
Jarek Rozanski 2026-10-11 10:50:14 +02:00
commit 1cc8dddc30
No known key found for this signature in database
2 changed files with 46 additions and 4 deletions

View file

@ -22,7 +22,27 @@ mkdir -p "$BIN_DIR"
cat > "$SHIM" <<'EOF'
#!/bin/sh
exec sbx run -t localhost/opencode-v2:local "$@" opencode
# sbx run accepts -t/--template only at sandbox creation time; re-running
# against an existing sandbox with a template fails. So pass the template
# only when the named sandbox doesn't exist yet.
TEMPLATE=localhost/opencode-v2:local
# Extract --name VALUE / --name=VALUE from the arguments, if given.
name=
prev=
for arg in "$@"; do
[ "$prev" = --name ] && name=$arg
case "$arg" in
--name=*) name=${arg#--name=} ;;
esac
prev=$arg
done
if [ -n "$name" ] && sbx ls -q 2>/dev/null | grep -Fxq -- "$name"; then
exec sbx run "$@" opencode
fi
exec sbx run -t "$TEMPLATE" "$@" opencode
EOF
chmod +x "$SHIM"
echo "==> Installed shim: $SHIM"