@madarco/agentbox 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/{_cloud-attach-T727ZPRV.js → _cloud-attach-ZXBCNWJX.js} +4 -4
  2. package/dist/{chunk-67N47KUS.js → chunk-BXQMIEHC.js} +106 -31
  3. package/dist/chunk-BXQMIEHC.js.map +1 -0
  4. package/dist/{chunk-FODMEHD3.js → chunk-GU5LW4B5.js} +341 -25
  5. package/dist/chunk-GU5LW4B5.js.map +1 -0
  6. package/dist/{chunk-BGK32PZE.js → chunk-KL36BRN4.js} +2 -2
  7. package/dist/chunk-KL36BRN4.js.map +1 -0
  8. package/dist/chunk-MTVI44DW.js +662 -0
  9. package/dist/chunk-MTVI44DW.js.map +1 -0
  10. package/dist/{chunk-6OZDFNBF.js → chunk-NCJP5MTN.js} +201 -44
  11. package/dist/chunk-NCJP5MTN.js.map +1 -0
  12. package/dist/{dist-LOZBWMBF.js → dist-32EZBYG4.js} +9 -3
  13. package/dist/{dist-L4LCG5SJ.js → dist-CX5CGVEB.js} +4 -4
  14. package/dist/{dist-ZODPD2I6.js → dist-GDHP34ZK.js} +8 -10
  15. package/dist/dist-GDHP34ZK.js.map +1 -0
  16. package/dist/dist-XML54CNB.js +849 -0
  17. package/dist/dist-XML54CNB.js.map +1 -0
  18. package/dist/index.js +636 -340
  19. package/dist/index.js.map +1 -1
  20. package/dist/{prepared-state-CL4CWXQA-ME4HSKDE.js → prepared-state-CL4CWXQA-H5THETIM.js} +2 -2
  21. package/package.json +7 -5
  22. package/runtime/docker/packages/ctl/dist/bin.cjs +98 -29
  23. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-vnc-start +15 -1
  24. package/runtime/hetzner/agentbox-vnc-start +15 -1
  25. package/runtime/hetzner/ctl.cjs +98 -29
  26. package/runtime/relay/bin.cjs +229 -37
  27. package/runtime/vercel/agentbox-checkpoint-cleanup +52 -0
  28. package/runtime/vercel/agentbox-codex-hooks.json +68 -0
  29. package/runtime/vercel/agentbox-open +28 -0
  30. package/runtime/vercel/agentbox-setup-skill.md +196 -0
  31. package/runtime/vercel/agentbox-vnc-start +91 -0
  32. package/runtime/vercel/claude-managed-settings.json +115 -0
  33. package/runtime/vercel/ctl.cjs +23466 -0
  34. package/runtime/vercel/custom-system-CLAUDE.md +50 -0
  35. package/runtime/vercel/gh-shim +263 -0
  36. package/runtime/vercel/git-shim +131 -0
  37. package/runtime/vercel/scripts/provision.sh +274 -0
  38. package/dist/chunk-67N47KUS.js.map +0 -1
  39. package/dist/chunk-6OZDFNBF.js.map +0 -1
  40. package/dist/chunk-BGK32PZE.js.map +0 -1
  41. package/dist/chunk-FODMEHD3.js.map +0 -1
  42. package/dist/dist-ZODPD2I6.js.map +0 -1
  43. /package/dist/{_cloud-attach-T727ZPRV.js.map → _cloud-attach-ZXBCNWJX.js.map} +0 -0
  44. /package/dist/{dist-LOZBWMBF.js.map → dist-32EZBYG4.js.map} +0 -0
  45. /package/dist/{dist-L4LCG5SJ.js.map → dist-CX5CGVEB.js.map} +0 -0
  46. /package/dist/{prepared-state-CL4CWXQA-ME4HSKDE.js.map → prepared-state-CL4CWXQA-H5THETIM.js.map} +0 -0
@@ -0,0 +1,50 @@
1
+ # AgentBox sandbox (vercel provider)
2
+
3
+ You are running inside an AgentBox sandbox: a Vercel Sandbox (a Firecracker
4
+ microVM on Amazon Linux 2023) provisioned just for this box. Your user is
5
+ `vscode` and you can use passwordless **sudo** to run commands as root. The
6
+ whole microVM is yours — the user's host filesystem is not visible from here
7
+ and nothing is bind-mounted.
8
+
9
+ **No containers.** Vercel Sandbox blocks the namespace syscalls a container
10
+ runtime needs (no `CAP_SYS_ADMIN`, seccomp-filtered `clone`/`unshare`), so
11
+ `docker` / `podman` cannot run here — not even rootless. Don't try to start a
12
+ container engine; run build/test/dev processes directly on the microVM instead.
13
+
14
+ This box is **persistent**: stopping it captures a snapshot and resuming
15
+ restarts from that snapshot, so the filesystem survives a pause. You can also
16
+ save the current filesystem state for future boxes with
17
+ `agentbox-ctl checkpoint --set-default`, but a checkpoint/snapshot STOPS the
18
+ box, so use it only at the end of the setup wizard — otherwise rely on
19
+ idempotent tasks in `agentbox.yaml`. NB: this `agentbox-ctl` command normally
20
+ doesn't need user confirmation, but since it stops the box, ask for
21
+ confirmation before running it.
22
+
23
+ `/workspace` is a normal git checkout seeded from the host repo at create time.
24
+ Because there is no host bind-mount, plain `git` inside the box only affects
25
+ this box-local repo — commits do **not** appear in the user's host `git log`
26
+ until you hand them off. For any operation that must reach the host repo or its
27
+ remotes (push, fetch, pull, picking up host-side changes), use
28
+ `agentbox-ctl git push|fetch|pull -- <args>` — it RPCs to the host, which runs
29
+ git with the real SSH agent and writes back into the host's worktree state. The
30
+ wrapper already builds `git push <remote> <branch>` host-side from the
31
+ registered worktree; the `-- <args>` slot is for extra flags only (e.g.
32
+ `--force-with-lease`, `--tags`). Re-passing the remote or branch makes git treat
33
+ them as refspecs and fails with `refs/remotes/origin/HEAD cannot be resolved to
34
+ branch`.
35
+
36
+ For GitHub PR work, use `agentbox-ctl git pr <op> [args...]` — same model, relay
37
+ shells to host `gh`. Ops: `create`, `view`, `list`, `comment`, `review`,
38
+ `merge`, `close`, `reopen`, `checkout`. `view` / `list` are read-only and run
39
+ silently; everything else asks the user to confirm in the host wrapper (deny →
40
+ exit 10).
41
+
42
+ For ad-hoc file transfers between this box and the host, use
43
+ `agentbox-ctl cp toHost <boxPath> <hostPath>` and
44
+ `agentbox-ctl cp fromHost <hostPath> <boxPath>` or `agentbox-ctl download claude` /
45
+ `download env` / `download config`. They RPC to the host and ask the user for
46
+ confirmation on the wrapper that runs `agentbox claude`; deny returns exit 10
47
+ (`denied by user`). Don't put any timeout on the command, it will run forever
48
+ and the user will be notified through multiple channels.
49
+
50
+ Box identity: /etc/agentbox/box.env and the AGENTBOX_* env vars.
@@ -0,0 +1,263 @@
1
+ #!/usr/bin/env bash
2
+ # agentbox `gh` shim — translates a strict subset of `gh` subcommands into
3
+ # `agentbox-ctl gh ...` so the host's authenticated `gh` runs the operation
4
+ # and only the result crosses back into the box. The in-box agent never sees
5
+ # a GitHub token.
6
+ #
7
+ # This shim ships only what Claude Code's PR badge and our documented agent
8
+ # flows need. Anything outside the subset below is rejected with a clear
9
+ # error — better safe than compatible. Add ops deliberately, not by default.
10
+
11
+ set -euo pipefail
12
+
13
+ # Paths are constants in production; env overrides exist purely to let unit
14
+ # tests substitute a stub `agentbox-ctl` on PATH without rewriting the shim.
15
+ CTL="${AGENTBOX_CTL_PATH:-/usr/local/bin/agentbox-ctl}"
16
+ REAL_GIT="${AGENTBOX_REAL_GIT_PATH:-/usr/bin/git}"
17
+
18
+ die() {
19
+ printf 'agentbox gh shim: %s\n' "$*" >&2
20
+ exit 2
21
+ }
22
+
23
+ # Resolve the in-box current branch once. Used to inject the right ref into
24
+ # `gh pr` commands so the host's `gh` (which runs in the host main repo, not
25
+ # the box's worktree) doesn't fall back to the host's HEAD.
26
+ box_branch() {
27
+ "$REAL_GIT" -C "$PWD" rev-parse --abbrev-ref HEAD 2>/dev/null || true
28
+ }
29
+
30
+ # Returns 0 if any element of "$@" equals "$1" (the needle).
31
+ needle_present() {
32
+ local needle="$1"; shift
33
+ local arg
34
+ for arg in "$@"; do
35
+ if [ "$arg" = "$needle" ]; then return 0; fi
36
+ done
37
+ return 1
38
+ }
39
+
40
+ # Walk argv: if any arg starts with `-` and isn't in the allowed set, die.
41
+ # Doesn't try to validate flag _values_ (e.g. `--json number,url`); that's
42
+ # real gh's job — we only block flags we don't expect to see.
43
+ strict_flags() {
44
+ local subcmd="$1"; shift
45
+ local allowed="$1"; shift
46
+ local re="^(${allowed})$"
47
+ local arg
48
+ for arg in "$@"; do
49
+ case "$arg" in
50
+ --) ;;
51
+ -*)
52
+ if ! [[ "$arg" =~ $re ]]; then
53
+ die "unsupported flag '$arg' for '$subcmd'. Allowed: ${allowed//|/, }"
54
+ fi
55
+ ;;
56
+ esac
57
+ done
58
+ }
59
+
60
+ # Returns the first true positional arg of "$@" (skipping flags AND their
61
+ # values), or '' if none. $1 is a `|`-separated list of value-taking flags
62
+ # for the current subcommand — e.g. "--json|--title|--body|--base" means the
63
+ # token after any of those flags is a value, not a positional. Without this
64
+ # we'd treat `--json number,url`'s field list as the positional and miss
65
+ # branch injection (real bug: PR-badge lookups returned "no PR for main"
66
+ # because the JSON field list looked positional).
67
+ first_positional() {
68
+ local value_taking="$1"; shift
69
+ local re="^(${value_taking})$"
70
+ local arg
71
+ local skip_value=0
72
+ for arg in "$@"; do
73
+ if [ "$skip_value" = "1" ]; then
74
+ skip_value=0
75
+ continue
76
+ fi
77
+ case "$arg" in
78
+ --) ;;
79
+ -*)
80
+ if [[ -n "$value_taking" && "$arg" =~ $re ]]; then
81
+ skip_value=1
82
+ fi
83
+ ;;
84
+ *) printf '%s\n' "$arg"; return 0 ;;
85
+ esac
86
+ done
87
+ }
88
+
89
+ handle_pr() {
90
+ local op="${1-}"; shift || true
91
+ if [ -z "$op" ]; then
92
+ die "missing subcommand for 'gh pr'. Supported: view, list, create, comment, review, merge, checkout, close, reopen"
93
+ fi
94
+ local branch
95
+ branch="$(box_branch)"
96
+
97
+ case "$op" in
98
+ view)
99
+ strict_flags "gh pr view" "--json" "$@"
100
+ if [ -z "$(first_positional "--json" "$@")" ] && [ -n "$branch" ]; then
101
+ set -- "$branch" "$@"
102
+ fi
103
+ exec "$CTL" gh pr view -- "$@"
104
+ ;;
105
+ list)
106
+ strict_flags "gh pr list" "--json|--state" "$@"
107
+ if ! needle_present "--head" "$@" && [ -n "$branch" ]; then
108
+ set -- "$@" "--head" "$branch"
109
+ fi
110
+ exec "$CTL" gh pr list -- "$@"
111
+ ;;
112
+ create)
113
+ strict_flags "gh pr create" "--fill|--draft|--title|--body|--base" "$@"
114
+ if ! needle_present "--head" "$@" && [ -n "$branch" ]; then
115
+ set -- "$@" "--head" "$branch"
116
+ fi
117
+ exec "$CTL" gh pr create -- "$@"
118
+ ;;
119
+ comment)
120
+ strict_flags "gh pr comment" "--body" "$@"
121
+ if [ -z "$(first_positional "--body" "$@")" ] && [ -n "$branch" ]; then
122
+ set -- "$branch" "$@"
123
+ fi
124
+ exec "$CTL" gh pr comment -- "$@"
125
+ ;;
126
+ review)
127
+ strict_flags "gh pr review" "--approve|--request-changes|--comment|--body" "$@"
128
+ if [ -z "$(first_positional "--body" "$@")" ] && [ -n "$branch" ]; then
129
+ set -- "$branch" "$@"
130
+ fi
131
+ exec "$CTL" gh pr review -- "$@"
132
+ ;;
133
+ merge)
134
+ strict_flags "gh pr merge" "--squash|--merge|--rebase|--delete-branch" "$@"
135
+ if [ -z "$(first_positional "" "$@")" ] && [ -n "$branch" ]; then
136
+ set -- "$branch" "$@"
137
+ fi
138
+ exec "$CTL" gh pr merge -- "$@"
139
+ ;;
140
+ close)
141
+ strict_flags "gh pr close" "--delete-branch" "$@"
142
+ if [ -z "$(first_positional "" "$@")" ] && [ -n "$branch" ]; then
143
+ set -- "$branch" "$@"
144
+ fi
145
+ exec "$CTL" gh pr close -- "$@"
146
+ ;;
147
+ reopen)
148
+ strict_flags "gh pr reopen" "" "$@"
149
+ if [ -z "$(first_positional "" "$@")" ] && [ -n "$branch" ]; then
150
+ set -- "$branch" "$@"
151
+ fi
152
+ exec "$CTL" gh pr reopen -- "$@"
153
+ ;;
154
+ checkout)
155
+ # gh pr checkout takes a required ref (number / URL / branch). No
156
+ # auto-inject — the relay also refuses checkout by default
157
+ # (AGENTBOX_GH_PR_CHECKOUT=allow opt-in).
158
+ strict_flags "gh pr checkout" "" "$@"
159
+ if [ -z "$(first_positional "" "$@")" ]; then
160
+ die "'gh pr checkout' requires a positional ref (PR number, URL, or branch)"
161
+ fi
162
+ exec "$CTL" gh pr checkout -- "$@"
163
+ ;;
164
+ *)
165
+ die "'gh pr $op' is not proxied (supported: view, list, create, comment, review, merge, checkout, close, reopen)"
166
+ ;;
167
+ esac
168
+ }
169
+
170
+ handle_repo() {
171
+ local op="${1-}"; shift || true
172
+ if [ "$op" != "clone" ]; then
173
+ die "'gh repo $op' is not proxied (supported: clone)"
174
+ fi
175
+ # gh repo clone <repo> [<dir>] [--branch <n>] [--depth <n>]
176
+ strict_flags "gh repo clone" "--branch|--depth" "$@"
177
+ # Split argv into (repo, dir, flags). Pass positionals BEFORE options to the
178
+ # ctl so commander parses --branch/--depth as real options; using a `--`
179
+ # separator would force commander to treat them as extra positionals (the
180
+ # ctl `gh repo clone` command doesn't allowExcessArguments).
181
+ local repo='' dir=''
182
+ local -a flags=()
183
+ local pos=0
184
+ local skip_value=0
185
+ local arg
186
+ for arg in "$@"; do
187
+ if [ "$skip_value" = "1" ]; then
188
+ flags+=("$arg")
189
+ skip_value=0
190
+ continue
191
+ fi
192
+ case "$arg" in
193
+ --branch|--depth)
194
+ flags+=("$arg")
195
+ skip_value=1
196
+ ;;
197
+ -*)
198
+ flags+=("$arg")
199
+ ;;
200
+ *)
201
+ if [ $pos -eq 0 ]; then repo="$arg"
202
+ elif [ $pos -eq 1 ]; then dir="$arg"
203
+ else die "too many positionals for 'gh repo clone' (got '$arg' after repo + dir)"
204
+ fi
205
+ pos=$((pos+1))
206
+ ;;
207
+ esac
208
+ done
209
+ if [ -z "$repo" ]; then
210
+ die "'gh repo clone' requires a positional <repo> (owner/name or full URL)"
211
+ fi
212
+ if [ -n "$dir" ]; then
213
+ exec "$CTL" gh repo clone "$repo" "$dir" ${flags[@]+"${flags[@]}"}
214
+ else
215
+ exec "$CTL" gh repo clone "$repo" ${flags[@]+"${flags[@]}"}
216
+ fi
217
+ }
218
+
219
+ # Top-level dispatch.
220
+ if [ $# -eq 0 ]; then
221
+ die "no subcommand. Supported: pr {view,list,create,comment,review,merge,checkout,close,reopen}, repo clone, auth status, --version"
222
+ fi
223
+
224
+ case "$1" in
225
+ --version|-v)
226
+ # Real gh prints something like:
227
+ # gh version 2.40.0 (2023-10-26)
228
+ # https://github.com/cli/cli/releases/tag/v2.40.0
229
+ # Tools that sniff "gh version" succeed with our shim line too.
230
+ printf 'gh version 2.0.0 (agentbox-shim)\n'
231
+ printf 'https://github.com/cli/cli\n'
232
+ ;;
233
+ --help|-h)
234
+ printf 'agentbox gh shim — strict subset.\n' >&2
235
+ printf 'Supported: pr {view,list,create,comment,review,merge,checkout,close,reopen}, repo clone, auth status, --version\n' >&2
236
+ printf 'Anything else is rejected. Run host `gh --help` for full upstream docs.\n' >&2
237
+ ;;
238
+ auth)
239
+ shift
240
+ case "${1-}" in
241
+ status)
242
+ # Real auth state is verified host-side on the next real RPC (relay's
243
+ # assertGhReady returns exit 4 if the host is logged out). We don't
244
+ # round-trip on every refresh-driven poll Claude Code does.
245
+ printf 'agentbox gh shim: logged in to github.com (via agentbox host relay)\n' >&2
246
+ ;;
247
+ *)
248
+ die "'gh auth ${1-}' is not proxied (supported: status)"
249
+ ;;
250
+ esac
251
+ ;;
252
+ pr)
253
+ shift
254
+ handle_pr "$@"
255
+ ;;
256
+ repo)
257
+ shift
258
+ handle_repo "$@"
259
+ ;;
260
+ *)
261
+ die "'gh $1' is not proxied (supported: pr {…}, repo clone, auth status, --version)"
262
+ ;;
263
+ esac
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env bash
2
+ # agentbox `git` shim — intercepts the four network ops (`push`, `pull`,
3
+ # `fetch`, `clone`) and routes them through `agentbox-ctl git ...` so the
4
+ # host runs the credential-touching part. Everything else (commit, status,
5
+ # log, diff, add, checkout, branch, ...) falls through to the real
6
+ # `/usr/bin/git` with zero overhead and zero shim output.
7
+ #
8
+ # Strict per-op flag whitelist — better safe than compatible. Adding a flag
9
+ # is a deliberate decision, not a default.
10
+
11
+ set -euo pipefail
12
+
13
+ # Paths are constants in production; env overrides exist purely to let unit
14
+ # tests substitute a stub `agentbox-ctl` on PATH without rewriting the shim.
15
+ # NEVER `exec git` — would loop on this shim. Always exec the resolved $REAL_GIT.
16
+ CTL="${AGENTBOX_CTL_PATH:-/usr/local/bin/agentbox-ctl}"
17
+ REAL_GIT="${AGENTBOX_REAL_GIT_PATH:-/usr/bin/git}"
18
+
19
+ die() {
20
+ printf 'agentbox git shim: %s\n' "$*" >&2
21
+ exit 2
22
+ }
23
+
24
+ # Walk argv: any arg matching `-*` must be in $allowed (regex alternation).
25
+ # Doesn't validate flag _values_ (e.g. `--branch main`); that's git's job.
26
+ strict_flags() {
27
+ local subcmd="$1"; shift
28
+ local allowed="$1"; shift
29
+ local re="^(${allowed})$"
30
+ local arg
31
+ for arg in "$@"; do
32
+ case "$arg" in
33
+ --) ;;
34
+ -*)
35
+ if ! [[ "$arg" =~ $re ]]; then
36
+ die "unsupported flag '$arg' for '$subcmd'. Allowed: ${allowed//|/, }"
37
+ fi
38
+ ;;
39
+ esac
40
+ done
41
+ }
42
+
43
+ # Network ops (push/pull/fetch): refuse positional remote/branch. The ctl
44
+ # rebuilds them from the registered worktree; re-passing them as positionals
45
+ # makes git treat them as refspecs and fail with
46
+ # `refs/remotes/origin/HEAD cannot be resolved to branch` (documented at
47
+ # packages/ctl/src/commands/git.ts:131).
48
+ refuse_positionals() {
49
+ local subcmd="$1"; shift
50
+ local arg
51
+ for arg in "$@"; do
52
+ case "$arg" in
53
+ --) ;;
54
+ -*) ;;
55
+ *)
56
+ die "positional '$arg' not allowed for '$subcmd' (the box's remote and branch are taken from the registered worktree)"
57
+ ;;
58
+ esac
59
+ done
60
+ }
61
+
62
+ if [ $# -eq 0 ]; then
63
+ exec "$REAL_GIT"
64
+ fi
65
+
66
+ case "$1" in
67
+ push)
68
+ shift
69
+ strict_flags "git push" "--force-with-lease" "$@"
70
+ refuse_positionals "git push" "$@"
71
+ exec "$CTL" git push -- "$@"
72
+ ;;
73
+ pull)
74
+ shift
75
+ strict_flags "git pull" "--ff-only" "$@"
76
+ refuse_positionals "git pull" "$@"
77
+ exec "$CTL" git pull -- "$@"
78
+ ;;
79
+ fetch)
80
+ shift
81
+ strict_flags "git fetch" "--prune" "$@"
82
+ refuse_positionals "git fetch" "$@"
83
+ exec "$CTL" git fetch -- "$@"
84
+ ;;
85
+ clone)
86
+ shift
87
+ strict_flags "git clone" "--branch|--depth" "$@"
88
+ # Walk argv: split into (url, dir, flags) so we can hand them to ctl
89
+ # in commander's expected shape (positionals first, then options).
90
+ url=''
91
+ dir=''
92
+ flags=()
93
+ pos=0
94
+ skip_value=0
95
+ for arg in "$@"; do
96
+ if [ "$skip_value" = "1" ]; then
97
+ flags+=("$arg")
98
+ skip_value=0
99
+ continue
100
+ fi
101
+ case "$arg" in
102
+ --branch|--depth)
103
+ flags+=("$arg")
104
+ skip_value=1
105
+ ;;
106
+ -*)
107
+ flags+=("$arg")
108
+ ;;
109
+ *)
110
+ if [ $pos -eq 0 ]; then url="$arg"
111
+ elif [ $pos -eq 1 ]; then dir="$arg"
112
+ else die "too many positionals for 'git clone' (got '$arg' after url + dir)"
113
+ fi
114
+ pos=$((pos+1))
115
+ ;;
116
+ esac
117
+ done
118
+ if [ -z "$url" ]; then
119
+ die "'git clone' requires a positional <url> (github URL or owner/name shorthand)"
120
+ fi
121
+ # `set -u` + empty array: use the ${arr[@]+"${arr[@]}"} guard.
122
+ if [ -n "$dir" ]; then
123
+ exec "$CTL" git clone "$url" "$dir" ${flags[@]+"${flags[@]}"}
124
+ else
125
+ exec "$CTL" git clone "$url" ${flags[@]+"${flags[@]}"}
126
+ fi
127
+ ;;
128
+ *)
129
+ exec "$REAL_GIT" "$@"
130
+ ;;
131
+ esac