@madarco/agentbox 0.7.0 → 0.8.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 (60) hide show
  1. package/dist/_cloud-attach-T727ZPRV.js +13 -0
  2. package/dist/{chunk-NW5NYTQM.js → chunk-67N47KUS.js} +359 -85
  3. package/dist/chunk-67N47KUS.js.map +1 -0
  4. package/dist/{chunk-NAVL4R34.js → chunk-6OZDFNBF.js} +1084 -516
  5. package/dist/chunk-6OZDFNBF.js.map +1 -0
  6. package/dist/chunk-BGK32PZE.js +455 -0
  7. package/dist/chunk-BGK32PZE.js.map +1 -0
  8. package/dist/{chunk-7KOEFGN2.js → chunk-FODMEHD3.js} +52 -14
  9. package/dist/chunk-FODMEHD3.js.map +1 -0
  10. package/dist/{chunk-UK72UQ5U.js → chunk-G3H2L3O2.js} +55 -4
  11. package/dist/chunk-G3H2L3O2.js.map +1 -0
  12. package/dist/{chunk-V5KZGB5V.js → chunk-LEV3KICD.js} +18 -2
  13. package/dist/chunk-LEV3KICD.js.map +1 -0
  14. package/dist/{cloud-poller-ZIWSADJB-JXFRJUEM.js → cloud-poller-SUNA6ZQC-2RG5WPRN.js} +2 -2
  15. package/dist/{dist-R67WMLCF.js → dist-L4LCG5SJ.js} +120 -10
  16. package/dist/dist-L4LCG5SJ.js.map +1 -0
  17. package/dist/{dist-ETCFRVPA.js → dist-LOZBWMBF.js} +44 -20
  18. package/dist/{dist-QZGJIBT5.js → dist-ZODPD2I6.js} +142 -74
  19. package/dist/dist-ZODPD2I6.js.map +1 -0
  20. package/dist/index.js +3563 -845
  21. package/dist/index.js.map +1 -1
  22. package/dist/prepared-state-CL4CWXQA-ME4HSKDE.js +18 -0
  23. package/dist/prepared-state-CL4CWXQA-ME4HSKDE.js.map +1 -0
  24. package/package.json +4 -4
  25. package/runtime/daytona/custom-system-CLAUDE.md +39 -0
  26. package/runtime/docker/Dockerfile.box +22 -0
  27. package/runtime/docker/apps/cli/share/agentbox-setup/SKILL.md +1 -1
  28. package/runtime/docker/packages/ctl/dist/bin.cjs +1118 -71
  29. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-codex-hooks.json +66 -35
  30. package/runtime/docker/packages/sandbox-docker/scripts/claude-managed-settings.json +62 -1
  31. package/runtime/docker/packages/sandbox-docker/scripts/custom-system-CLAUDE.md +15 -4
  32. package/runtime/docker/packages/sandbox-docker/scripts/gh-shim +263 -0
  33. package/runtime/docker/packages/sandbox-docker/scripts/git-shim +131 -0
  34. package/runtime/docker/packages/sandbox-docker/scripts/opencode-agentbox-plugin.js +76 -0
  35. package/runtime/hetzner/agentbox-codex-hooks.json +66 -35
  36. package/runtime/hetzner/agentbox-setup-skill.md +1 -1
  37. package/runtime/hetzner/claude-managed-settings.json +62 -1
  38. package/runtime/hetzner/ctl.cjs +1118 -71
  39. package/runtime/hetzner/custom-system-CLAUDE.md +26 -14
  40. package/runtime/hetzner/gh-shim +263 -0
  41. package/runtime/hetzner/git-shim +131 -0
  42. package/runtime/hetzner/opencode-agentbox-plugin.js +76 -0
  43. package/runtime/hetzner/scripts/install-box.sh +11 -2
  44. package/runtime/relay/bin.cjs +927 -36
  45. package/share/agentbox-setup/SKILL.md +1 -1
  46. package/share/host-skills/agentbox/SKILL.md +29 -0
  47. package/share/host-skills/agentbox-info/SKILL.md +211 -0
  48. package/share/host-skills/codex/agentbox.md +35 -0
  49. package/share/host-skills/opencode/agentbox.md +26 -0
  50. package/dist/_cloud-attach-DMVH6GWO.js +0 -12
  51. package/dist/chunk-7KOEFGN2.js.map +0 -1
  52. package/dist/chunk-NAVL4R34.js.map +0 -1
  53. package/dist/chunk-NW5NYTQM.js.map +0 -1
  54. package/dist/chunk-UK72UQ5U.js.map +0 -1
  55. package/dist/chunk-V5KZGB5V.js.map +0 -1
  56. package/dist/dist-QZGJIBT5.js.map +0 -1
  57. package/dist/dist-R67WMLCF.js.map +0 -1
  58. /package/dist/{_cloud-attach-DMVH6GWO.js.map → _cloud-attach-T727ZPRV.js.map} +0 -0
  59. /package/dist/{cloud-poller-ZIWSADJB-JXFRJUEM.js.map → cloud-poller-SUNA6ZQC-2RG5WPRN.js.map} +0 -0
  60. /package/dist/{dist-ETCFRVPA.js.map → dist-LOZBWMBF.js.map} +0 -0
@@ -1,27 +1,39 @@
1
- # AgentBox sandbox
1
+ # AgentBox sandbox (hetzner provider)
2
2
 
3
- You are running inside an AgentBox sandbox: a Linux Docker container with
4
- docker-in-docker (run `docker` directly, no sudo).
5
- Your user is `vscode` and you can use passwordless **sudo** to run commands as root.
6
- `/workspace` is your own per-box git worktree on branch `agentbox/<box-name>`:
7
- writes there stay in the container's writable layer and don't touch the host's working
8
- tree.
3
+ You are running inside an AgentBox sandbox: a dedicated Linux VPS (Ubuntu) on
4
+ Hetzner Cloud provisioned just for this box. Docker-in-docker is available
5
+ (run `docker` directly, no sudo). Your user is `vscode` and you can use
6
+ passwordless **sudo** to run commands as root. The whole VPS is yours — the
7
+ user's host filesystem is not visible from here and nothing is bind-mounted.
9
8
 
10
- You can save the current filesystem state to be reused by future boxes by
9
+ You can save the current filesystem state to be reused by future boxes by
11
10
  running `agentbox-ctl checkpoint --set-default`. This doesn't need to be confirmed by the user.
12
11
 
13
- The main `.git/` is bind-mounted at the same absolute path as on
14
- the host, so local commits show up in the host's `git log` immediately.
15
- No SSH creds, no host gitconfig identity. For ops that need the user
16
- (push, fetch from private remotes), use `agentbox-ctl git push|fetch|pull
17
- -- <args>` it RPCs to the host, which runs git with the real SSH agent.
12
+ `/workspace` is a normal git checkout seeded from the host repo at create
13
+ time. Because there is no host bind-mount, plain `git` inside the box only
14
+ affects this box-local repo commits do **not** appear in the user's host
15
+ `git log` until you hand them off. For any operation that must reach the host
16
+ repo or its remotes (push, fetch, pull, picking up host-side changes), use
17
+ `agentbox-ctl git push|fetch|pull -- <args>` — it RPCs to the host, which
18
+ runs git with the real SSH agent and writes back into the host's worktree
19
+ state. The wrapper already builds `git push <remote> <branch>` host-side from
20
+ the registered worktree; the `-- <args>` slot is for extra flags only (e.g.
21
+ `--force-with-lease`, `--tags`). Re-passing the remote or branch makes git
22
+ treat them as refspecs and fails with `refs/remotes/origin/HEAD cannot be
23
+ resolved to branch`.
24
+
25
+ For GitHub PR work, use `agentbox-ctl git pr <op> [args...]` — same model,
26
+ relay shells to host `gh`. Ops: `create`, `view`, `list`, `comment`,
27
+ `review`, `merge`, `close`, `reopen`, `checkout`. `view` / `list` are
28
+ read-only and run silently; everything else asks the user to confirm in
29
+ the host wrapper (deny → exit 10).
18
30
 
19
31
  For ad-hoc file transfers between this box and the host, use
20
32
  `agentbox-ctl cp toHost <boxPath> <hostPath>` and
21
33
  `agentbox-ctl cp fromHost <hostPath> <boxPath>` or `agentbox-ctl download claude` / `download env` /
22
34
  `download config`. They RPC to the host and
23
35
  ask the user for confirmation on the wrapper that runs `agentbox claude`;
24
- deny returns exit 10 (`denied by user`).
36
+ deny returns exit 10 (`denied by user`).
25
37
  Don't put any timeout on the command, it will run forever and the user will be notified through multiple channels.
26
38
 
27
39
  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
@@ -0,0 +1,76 @@
1
+ // AgentBox state-reporting plugin for OpenCode (sst/opencode).
2
+ //
3
+ // Subscribes to OpenCode's plugin event bus and reports each lifecycle
4
+ // transition to `agentbox-ctl opencode-state <state>`. The ctl daemon then
5
+ // publishes the state to the host relay's status.json, which is what
6
+ // `agentbox agent state` / `agent wait-for` consume on the host side.
7
+ //
8
+ // Fire-and-forget — a missing/late `agentbox-ctl` must never disturb the
9
+ // OpenCode session. The spawned process is detached + unrefed so a slow
10
+ // ctl response never blocks an event handler.
11
+ //
12
+ // Seeded by `seedOpencodePlugin` (packages/sandbox-docker/src/opencode.ts)
13
+ // from the image-baked copy at /usr/local/share/agentbox/opencode-plugin/
14
+ // into the box's `$OPENCODE_CONFIG_DIR/plugins/agentbox-state.js` on every
15
+ // create / start. Idempotent overwrite.
16
+ //
17
+ // Event coverage (mirrors the Claude / Codex state machine):
18
+ // working — agent is generating. Driven by `message.part.delta` (streamed
19
+ // tokens) — these fire only DURING active generation, never after
20
+ // the turn ends, so they don't fight the `session.idle` end
21
+ // signal. (Empirically `tool.execute.before` does NOT reach the
22
+ // plugin event bus in opencode 1.15, and `message.updated` fires
23
+ // once AFTER `session.idle` — so neither is safe to map to
24
+ // working.)
25
+ // idle — turn complete / ready for input (`session.idle`, plus
26
+ // `session.created` as a baseline at session start).
27
+ // waiting — user input required (`permission.asked`).
28
+ // error — `session.error`.
29
+ // compacting — opencode has no PreCompact event; `session.compacted` fires
30
+ // AFTER compaction completes, so it maps to `working` (the next
31
+ // event supersedes) rather than `compacting`.
32
+ //
33
+ // The plugin shape comes from https://opencode.ai/docs/plugins/ — `event` is
34
+ // a single handler that receives `{ event }` with a `type` field. Multiple
35
+ // exports = multiple plugin functions; we ship one.
36
+
37
+ import { spawn } from 'node:child_process';
38
+
39
+ const EVENT_TO_STATE = {
40
+ 'session.created': 'idle',
41
+ 'session.idle': 'idle',
42
+ 'session.error': 'error',
43
+ 'session.compacted': 'working',
44
+ 'permission.asked': 'waiting',
45
+ 'permission.replied': 'working',
46
+ 'message.part.delta': 'working',
47
+ // tool.execute.before kept as a defensive mapping — harmless if a future
48
+ // opencode build starts surfacing it (it doesn't today).
49
+ 'tool.execute.before': 'working',
50
+ };
51
+
52
+ // Dedupe: `message.part.delta` fires dozens of times per streamed turn. Only
53
+ // spawn agentbox-ctl when the mapped state actually changes, so a turn costs
54
+ // ~2 spawns (working on the first delta, idle on session.idle) instead of ~50.
55
+ let lastState = null;
56
+
57
+ function pushState(state) {
58
+ if (!state || state === lastState) return;
59
+ lastState = state;
60
+ try {
61
+ const p = spawn('agentbox-ctl', ['opencode-state', state], {
62
+ stdio: 'ignore',
63
+ detached: true,
64
+ });
65
+ p.unref();
66
+ } catch {
67
+ // Fire-and-forget. A missing agentbox-ctl bin (test env, older box image)
68
+ // must not throw out of this handler.
69
+ }
70
+ }
71
+
72
+ export const AgentboxStatePlugin = async () => ({
73
+ event: async ({ event }) => {
74
+ pushState(EVENT_TO_STATE[event?.type]);
75
+ },
76
+ });
@@ -13,6 +13,8 @@
13
13
  # /tmp/agentbox-dockerd-start -- DinD startup helper
14
14
  # /tmp/agentbox-checkpoint-cleanup -- pre-snapshot cleanup helper
15
15
  # /tmp/agentbox-open -- in-box xdg-open shim
16
+ # /tmp/agentbox-gh-shim -- in-box `gh` shim (routes to host gh via relay)
17
+ # /tmp/agentbox-git-shim -- in-box `git` shim (routes push/pull/fetch/clone via relay)
16
18
  # /tmp/agentbox-custom-CLAUDE.md -- /etc/claude-code/CLAUDE.md content
17
19
  # /tmp/agentbox-managed-settings.json -- /etc/claude-code/managed-settings.json
18
20
  # /tmp/agentbox-codex-hooks.json -- /usr/local/share/agentbox/codex-hooks.json
@@ -159,13 +161,19 @@ done_ "agentbox-ctl install"
159
161
  # *before* Chromium sidesteps the issue and keeps the snapshot complete.
160
162
  # Tracked as Phase-7 follow-up in docs/hertzner_backlog.md.
161
163
 
162
- step "baked helper scripts (vnc / dockerd / cleanup / xdg-open shim)"
164
+ step "baked helper scripts (vnc / dockerd / cleanup / xdg-open / gh + git shims)"
163
165
  install -m 0755 /tmp/agentbox-vnc-start /usr/local/bin/agentbox-vnc-start
164
166
  install -m 0755 /tmp/agentbox-dockerd-start /usr/local/bin/agentbox-dockerd-start
165
167
  install -m 0755 /tmp/agentbox-checkpoint-cleanup /usr/local/bin/agentbox-checkpoint-cleanup
166
168
  install -m 0755 /tmp/agentbox-open /usr/local/bin/agentbox-open
167
169
  ln -sf /usr/local/bin/agentbox-open /usr/local/bin/xdg-open
168
- done_ "baked helper scripts (vnc / dockerd / cleanup / xdg-open shim)"
170
+ # gh + git shims same files baked by Dockerfile.box for the docker provider.
171
+ # The shim wins on PATH (default /usr/local/bin precedes /usr/bin) so any agent
172
+ # call to `gh ...` / `git push|pull|fetch|clone` routes through the relay; the
173
+ # git shim execs /usr/bin/git for everything else, no overhead.
174
+ install -m 0755 /tmp/agentbox-gh-shim /usr/local/bin/gh
175
+ install -m 0755 /tmp/agentbox-git-shim /usr/local/bin/git
176
+ done_ "baked helper scripts (vnc / dockerd / cleanup / xdg-open / gh + git shims)"
169
177
 
170
178
  step "baked config files (claude / codex / setup guide / tmux.conf)"
171
179
  install -m 0644 /tmp/agentbox-custom-CLAUDE.md /etc/claude-code/CLAUDE.md
@@ -356,6 +364,7 @@ step "trim /tmp/agentbox-*"
356
364
  # re-read which lines actually executed against which source.
357
365
  rm -f /tmp/agentbox-ctl /tmp/agentbox-vnc-start /tmp/agentbox-dockerd-start \
358
366
  /tmp/agentbox-checkpoint-cleanup /tmp/agentbox-open \
367
+ /tmp/agentbox-gh-shim /tmp/agentbox-git-shim \
359
368
  /tmp/agentbox-custom-CLAUDE.md /tmp/agentbox-managed-settings.json \
360
369
  /tmp/agentbox-codex-hooks.json /tmp/agentbox-setup-skill.md
361
370
  # Move install-box.sh into the persistent location for diagnostics.