Fallback for existing sandbox and name collision
This commit is contained in:
parent
962002aec1
commit
1cc8dddc30
2 changed files with 46 additions and 4 deletions
28
README.md
28
README.md
|
|
@ -67,12 +67,34 @@ two things, both idempotent — safe to re-run:
|
|||
|
||||
```sh
|
||||
#!/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
|
||||
```
|
||||
|
||||
`-t localhost/opencode-v2:local` points at the template `make build`
|
||||
registers (see below); `opencode` is the agent name; `"$@"` forwards any
|
||||
extra args (e.g. `opencode-sandbox --model claude-sonnet-5`). Being a real
|
||||
registers (see below), passed only when `--name` names a sandbox that
|
||||
doesn't exist yet (sbx rejects a template when re-attaching); `opencode`
|
||||
is the agent name; `"$@"` forwards any extra args
|
||||
(e.g. `opencode-sandbox --model claude-sonnet-5`). Being a real
|
||||
executable on `PATH` rather than a shell function means it works
|
||||
identically under bash, zsh, fish, or anything else.
|
||||
|
||||
|
|
|
|||
22
install.sh
22
install.sh
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue