-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcodeact
More file actions
executable file
·85 lines (78 loc) · 2.3 KB
/
Copy pathcodeact
File metadata and controls
executable file
·85 lines (78 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
# codeact — thin dispatcher to backend-specific codeact.py
# Subcommands:
# --code '<python>' Run sandboxed code
# --discover [--backend X] Emit tools JSON manifest
# --instructions [--backend X] Emit LLM-ready tool reference
# All other flags forwarded to backend codeact.py
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PLUGIN_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
# Extract --backend from args (if present), otherwise auto-detect
BACKEND=""
REMAINING_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
--backend)
BACKEND="$2"
shift 2
;;
--backend=*)
BACKEND="${1#--backend=}"
shift
;;
*)
REMAINING_ARGS+=("$1")
shift
;;
esac
done
if [[ -z "$BACKEND" ]]; then
# Prefer the backend selected at install time over re-running detection,
# so runtime always matches the syntax baked into the instructions file.
if [[ -f "$PLUGIN_DIR/.codeact-backend" ]]; then
BACKEND=$(<"$PLUGIN_DIR/.codeact-backend")
else
BACKEND=$(bash "$SCRIPT_DIR/detect-backend.sh")
fi
fi
BACKEND_SCRIPT="$PLUGIN_DIR/skills/${BACKEND}-codeact/scripts/codeact.py"
if [[ ! -f "$BACKEND_SCRIPT" ]]; then
echo "Error: Backend script not found: $BACKEND_SCRIPT" >&2
echo "Available backends:" >&2
ls "$PLUGIN_DIR/skills/" 2>/dev/null | grep -oP '(.+)-codeact' | sed 's/-codeact//' >&2
exit 1
fi
# Check if uv is available for auto-install
HAS_UV=false
if command -v uv >/dev/null 2>&1; then
HAS_UV=true
fi
# Build uv run prefix based on backend
case "$BACKEND" in
monty)
if [[ "$HAS_UV" == "true" ]]; then
exec uv run --quiet --with pydantic-monty python3 "$BACKEND_SCRIPT" "${REMAINING_ARGS[@]}"
else
exec python3 "$BACKEND_SCRIPT" "${REMAINING_ARGS[@]}"
fi
;;
hyperlight)
if [[ "$HAS_UV" == "true" ]]; then
PY_MINOR=$(python3 -c 'import sys; print(sys.version_info.minor)')
UV_EXTRA=()
if (( PY_MINOR > 13 )); then
UV_EXTRA=(--python 3.13)
fi
exec uv run --quiet "${UV_EXTRA[@]}" \
--with 'hyperlight-sandbox[wasm,python_guest]>=0.3.0' \
python3 "$BACKEND_SCRIPT" "${REMAINING_ARGS[@]}"
else
exec python3 "$BACKEND_SCRIPT" "${REMAINING_ARGS[@]}"
fi
;;
*)
echo "Error: Unknown backend '$BACKEND'" >&2
exit 1
;;
esac