@madarco/agentbox 0.23.5 → 0.24.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 (180) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -2
  4. package/dist/{_cloud-attach-D4OQO5AJ.js → _cloud-attach-T6GPR6LJ.js} +5 -5
  5. package/dist/{chunk-KY32JO6J.js → chunk-5KHEH47T.js} +91 -79
  6. package/dist/chunk-5KHEH47T.js.map +1 -0
  7. package/dist/{chunk-YRTM3KNT.js → chunk-6U2S6QWD.js} +219 -18
  8. package/dist/chunk-6U2S6QWD.js.map +1 -0
  9. package/dist/{chunk-JYEZ6Q5M.js → chunk-DEDTPG2D.js} +874 -146
  10. package/dist/chunk-DEDTPG2D.js.map +1 -0
  11. package/dist/chunk-G3H2L3O2.js +0 -0
  12. package/dist/{chunk-JNY5GPIM.js → chunk-I654PBHA.js} +290 -330
  13. package/dist/chunk-I654PBHA.js.map +1 -0
  14. package/dist/{chunk-6KOQRSHH.js → chunk-K2EDQGZP.js} +18 -4
  15. package/dist/chunk-K2EDQGZP.js.map +1 -0
  16. package/dist/{chunk-KZWJMNLP.js → chunk-LC4E2EIZ.js} +3 -3
  17. package/dist/{chunk-KZWJMNLP.js.map → chunk-LC4E2EIZ.js.map} +1 -1
  18. package/dist/{chunk-DADOEMXP.js → chunk-NACA6AM7.js} +183 -49
  19. package/dist/chunk-NACA6AM7.js.map +1 -0
  20. package/dist/{chunk-FX32NZD4.js → chunk-RYQLFKCP.js} +20 -10
  21. package/dist/chunk-RYQLFKCP.js.map +1 -0
  22. package/dist/{chunk-QT3SHMLY.js → chunk-UIRBYL4G.js} +43 -12
  23. package/dist/chunk-UIRBYL4G.js.map +1 -0
  24. package/dist/chunk-WJFZJZIM.js +0 -0
  25. package/dist/chunk-WLHJZPFJ.js +845 -0
  26. package/dist/chunk-WLHJZPFJ.js.map +1 -0
  27. package/dist/cloud-poller-SUNA6ZQC-7M5LJHHE.js +0 -0
  28. package/dist/dist-3KIJ2KQ2.js +1437 -0
  29. package/dist/dist-3KIJ2KQ2.js.map +1 -0
  30. package/dist/{dist-564EDHFF.js → dist-7OUOHQPA.js} +196 -151
  31. package/dist/dist-7OUOHQPA.js.map +1 -0
  32. package/dist/{dist-CAT2TN75.js → dist-B7TNWGVG.js} +8 -4
  33. package/dist/{dist-UDQMBWYW.js → dist-KYV3LEHG.js} +10 -6
  34. package/dist/{dist-EAR4BLL2.js → dist-PHYCFYKH.js} +37 -17
  35. package/dist/dist-PHYCFYKH.js.map +1 -0
  36. package/dist/{dist-2BTJQUJS.js → dist-T5MXBZGP.js} +2 -2
  37. package/dist/{dist-O5Y4X4C5.js → dist-Z7KEPQC7.js} +6 -6
  38. package/dist/index.js +2560 -1108
  39. package/dist/index.js.map +1 -1
  40. package/dist/{prepared-state-BUO75YLZ-PW64VQMT.js → prepared-state-BUO75YLZ-RQRFFBJW.js} +2 -2
  41. package/package.json +28 -28
  42. package/runtime/_shared/agentbox-checkpoint-cleanup +0 -0
  43. package/runtime/_shared/agentbox-codex-hooks.json +1 -1
  44. package/runtime/_shared/agentbox-dockerd-start +0 -0
  45. package/runtime/_shared/agentbox-open +0 -0
  46. package/runtime/_shared/agentbox-portless-trust +0 -0
  47. package/runtime/_shared/agentbox-vnc-start +0 -0
  48. package/runtime/_shared/ctl.cjs +468 -97
  49. package/runtime/_shared/gh-shim +0 -0
  50. package/runtime/_shared/git-shim +53 -3
  51. package/runtime/_shared/linear-shim +0 -0
  52. package/runtime/_shared/ntn-shim +0 -0
  53. package/runtime/daytona/custom-system-CLAUDE.md +1 -1
  54. package/runtime/digitalocean/agentbox-checkpoint-cleanup +55 -0
  55. package/runtime/digitalocean/agentbox-codex-hooks.json +68 -0
  56. package/runtime/digitalocean/agentbox-dockerd-start +145 -0
  57. package/runtime/digitalocean/agentbox-open +28 -0
  58. package/runtime/digitalocean/agentbox-portless-trust +82 -0
  59. package/runtime/digitalocean/agentbox-setup-skill.md +317 -0
  60. package/runtime/digitalocean/agentbox-vnc-start +102 -0
  61. package/runtime/digitalocean/claude-managed-settings.json +116 -0
  62. package/runtime/digitalocean/ctl.cjs +27852 -0
  63. package/runtime/digitalocean/custom-system-CLAUDE.md +39 -0
  64. package/runtime/digitalocean/gh-shim +344 -0
  65. package/runtime/digitalocean/git-shim +181 -0
  66. package/runtime/digitalocean/linear-shim +181 -0
  67. package/runtime/digitalocean/ntn-shim +95 -0
  68. package/runtime/digitalocean/opencode-agentbox-plugin.js +76 -0
  69. package/runtime/digitalocean/scripts/install-box.sh +462 -0
  70. package/runtime/docker/Dockerfile.box +5 -0
  71. package/runtime/docker/packages/ctl/dist/bin.cjs +468 -97
  72. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-checkpoint-cleanup +0 -0
  73. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-codex-hooks.json +1 -1
  74. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-dockerd-start +0 -0
  75. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-open +0 -0
  76. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-portless-trust +0 -0
  77. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-sshd-start +0 -0
  78. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-vnc-start +0 -0
  79. package/runtime/docker/packages/sandbox-docker/scripts/chromium-resolver +0 -0
  80. package/runtime/docker/packages/sandbox-docker/scripts/custom-system-CLAUDE.md +2 -1
  81. package/runtime/docker/packages/sandbox-docker/scripts/gh-shim +0 -0
  82. package/runtime/docker/packages/sandbox-docker/scripts/git-shim +53 -3
  83. package/runtime/docker/packages/sandbox-docker/scripts/linear-shim +0 -0
  84. package/runtime/docker/packages/sandbox-docker/scripts/ntn-shim +0 -0
  85. package/runtime/e2b/agentbox-checkpoint-cleanup +0 -0
  86. package/runtime/e2b/agentbox-codex-hooks.json +1 -1
  87. package/runtime/e2b/agentbox-dockerd-start +0 -0
  88. package/runtime/e2b/agentbox-open +0 -0
  89. package/runtime/e2b/agentbox-vnc-start +0 -0
  90. package/runtime/e2b/ctl.cjs +468 -97
  91. package/runtime/e2b/custom-system-CLAUDE.md +6 -3
  92. package/runtime/e2b/gh-shim +0 -0
  93. package/runtime/e2b/git-shim +53 -3
  94. package/runtime/e2b/linear-shim +0 -0
  95. package/runtime/e2b/ntn-shim +0 -0
  96. package/runtime/e2b/scripts/build-template.sh +16 -0
  97. package/runtime/hetzner/agentbox-checkpoint-cleanup +0 -0
  98. package/runtime/hetzner/agentbox-codex-hooks.json +1 -1
  99. package/runtime/hetzner/agentbox-dockerd-start +0 -0
  100. package/runtime/hetzner/agentbox-open +0 -0
  101. package/runtime/hetzner/agentbox-portless-trust +0 -0
  102. package/runtime/hetzner/agentbox-vnc-start +0 -0
  103. package/runtime/hetzner/ctl.cjs +468 -97
  104. package/runtime/hetzner/custom-system-CLAUDE.md +1 -1
  105. package/runtime/hetzner/gh-shim +0 -0
  106. package/runtime/hetzner/git-shim +53 -3
  107. package/runtime/hetzner/linear-shim +0 -0
  108. package/runtime/hetzner/ntn-shim +0 -0
  109. package/runtime/hetzner/scripts/install-box.sh +5 -0
  110. package/runtime/hub/apps/hub/.next/BUILD_ID +1 -1
  111. package/runtime/hub/apps/hub/.next/build-manifest.json +3 -3
  112. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/settings/page_client-reference-manifest.js +1 -1
  113. package/runtime/hub/apps/hub/.next/server/app/_global-error.html +1 -1
  114. package/runtime/hub/apps/hub/.next/server/app/_global-error.rsc +1 -1
  115. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  116. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  117. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  118. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  119. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  120. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0d1lmiq._.js +12 -12
  121. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0keu6we._.js +1 -1
  122. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1bqbkd5._.js +1 -1
  123. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1qa4a0v._.js +1 -1
  124. package/runtime/hub/apps/hub/.next/server/chunks/_0760z6y._.js +8 -8
  125. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0ro6vh6._.js +1 -1
  126. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub_0b_hsjl._.js +1 -1
  127. package/runtime/hub/apps/hub/.next/server/middleware-build-manifest.js +3 -3
  128. package/runtime/hub/apps/hub/.next/server/pages/500.html +1 -1
  129. package/runtime/hub/apps/hub/.next/static/chunks/380qcmusmigzz.js +1 -0
  130. package/runtime/hub/apps/hub/{auth-675P3LQS.js → auth-Q447765C.js} +2 -2
  131. package/runtime/hub/apps/hub/{auth-config-AOBEKRZQ.js → auth-config-SIL635ZD.js} +2 -2
  132. package/runtime/hub/apps/hub/{chunk-FSEPYTQ6.js → chunk-3VE7AYVK.js} +594 -145
  133. package/runtime/hub/apps/hub/{chunk-EXQCBM5Q.js → chunk-64WEKO34.js} +42 -11
  134. package/runtime/hub/apps/hub/{chunk-56YQBVN2.js → chunk-DZPQB2JZ.js} +1 -1
  135. package/runtime/hub/apps/hub/{chunk-7M6FXZIO.js → chunk-FGBXEXUV.js} +350 -292
  136. package/runtime/hub/apps/hub/{chunk-Z7ZAL24C.js → chunk-YVELHPNY.js} +218 -17
  137. package/runtime/hub/apps/hub/{dist-EKQHCXWE.js → dist-33ZNVTC6.js} +183 -49
  138. package/runtime/hub/apps/hub/{dist-V4TJ44MT.js → dist-4SXAJBOC.js} +195 -150
  139. package/runtime/hub/apps/hub/{dist-QIXUPGPP.js → dist-EPJFN2J3.js} +116 -86
  140. package/runtime/hub/apps/hub/{dist-STQK5XM6.js → dist-GF5EBRNG.js} +1 -1
  141. package/runtime/hub/apps/hub/{dist-JGZ55OIJ.js → dist-UJVIROA4.js} +19 -5
  142. package/runtime/hub/apps/hub/dist-XULFTIMT.js +2212 -0
  143. package/runtime/hub/apps/hub/{dist-GGWYKXJE.js → dist-YM5J25H6.js} +7 -3
  144. package/runtime/hub/apps/hub/{hub-token-2BZFBBW3.js → hub-token-UITZEWVP.js} +2 -2
  145. package/runtime/hub/apps/hub/package.json +1 -0
  146. package/runtime/hub/apps/hub/{prepared-state-BUO75YLZ-UICXTY25.js → prepared-state-BUO75YLZ-O4GZMDRF.js} +1 -1
  147. package/runtime/hub/apps/hub/server.js +17 -15
  148. package/runtime/relay/bin.cjs +275 -59
  149. package/runtime/vercel/agentbox-checkpoint-cleanup +0 -0
  150. package/runtime/vercel/agentbox-codex-hooks.json +1 -1
  151. package/runtime/vercel/agentbox-dockerd-start +0 -0
  152. package/runtime/vercel/agentbox-open +0 -0
  153. package/runtime/vercel/agentbox-vnc-start +0 -0
  154. package/runtime/vercel/ctl.cjs +468 -97
  155. package/runtime/vercel/custom-system-CLAUDE.md +3 -2
  156. package/runtime/vercel/gh-shim +0 -0
  157. package/runtime/vercel/git-shim +53 -3
  158. package/runtime/vercel/linear-shim +0 -0
  159. package/runtime/vercel/ntn-shim +0 -0
  160. package/runtime/vercel/scripts/provision.sh +16 -0
  161. package/dist/chunk-6KOQRSHH.js.map +0 -1
  162. package/dist/chunk-DADOEMXP.js.map +0 -1
  163. package/dist/chunk-FX32NZD4.js.map +0 -1
  164. package/dist/chunk-JNY5GPIM.js.map +0 -1
  165. package/dist/chunk-JYEZ6Q5M.js.map +0 -1
  166. package/dist/chunk-KY32JO6J.js.map +0 -1
  167. package/dist/chunk-QT3SHMLY.js.map +0 -1
  168. package/dist/chunk-YRTM3KNT.js.map +0 -1
  169. package/dist/dist-564EDHFF.js.map +0 -1
  170. package/dist/dist-EAR4BLL2.js.map +0 -1
  171. package/runtime/hub/apps/hub/.next/static/chunks/0joh_xsiowfc4.js +0 -1
  172. /package/dist/{_cloud-attach-D4OQO5AJ.js.map → _cloud-attach-T6GPR6LJ.js.map} +0 -0
  173. /package/dist/{dist-2BTJQUJS.js.map → dist-B7TNWGVG.js.map} +0 -0
  174. /package/dist/{dist-CAT2TN75.js.map → dist-KYV3LEHG.js.map} +0 -0
  175. /package/dist/{dist-O5Y4X4C5.js.map → dist-T5MXBZGP.js.map} +0 -0
  176. /package/dist/{dist-UDQMBWYW.js.map → dist-Z7KEPQC7.js.map} +0 -0
  177. /package/dist/{prepared-state-BUO75YLZ-PW64VQMT.js.map → prepared-state-BUO75YLZ-RQRFFBJW.js.map} +0 -0
  178. /package/runtime/hub/apps/hub/.next/static/{lOi70Di6lcnEBsUUHKrQ5 → XtIjHGqvY4mQsOY2-m1Jy}/_buildManifest.js +0 -0
  179. /package/runtime/hub/apps/hub/.next/static/{lOi70Di6lcnEBsUUHKrQ5 → XtIjHGqvY4mQsOY2-m1Jy}/_clientMiddlewareManifest.js +0 -0
  180. /package/runtime/hub/apps/hub/.next/static/{lOi70Di6lcnEBsUUHKrQ5 → XtIjHGqvY4mQsOY2-m1Jy}/_ssgManifest.js +0 -0
@@ -0,0 +1,39 @@
1
+ # AgentBox sandbox (digitalocean provider)
2
+
3
+ You are running inside an AgentBox sandbox: a dedicated Linux VPS (Ubuntu) — a
4
+ DigitalOcean Droplet 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.
8
+
9
+ You can save the current filesystem state to be reused by future boxes by
10
+ running `agentbox-ctl checkpoint --set-default`. This doesn't need to be confirmed by the user.
11
+
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).
30
+
31
+ For ad-hoc file transfers between this box and the host, use
32
+ `agentbox-ctl cp toHost <boxPath> <hostPath>` and
33
+ `agentbox-ctl cp fromHost <hostPath> <boxPath>` or `agentbox-ctl download claude` / `download env` /
34
+ `download config`. They RPC to the host and
35
+ ask the user for confirmation on the wrapper that runs `agentbox claude`;
36
+ deny returns exit 10 (`denied by user`).
37
+ Don't put any timeout on the command, it will run forever and the user will be notified through multiple channels.
38
+
39
+ Box identity: /etc/agentbox/box.env and the AGENTBOX_* env vars.
@@ -0,0 +1,344 @@
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, diff, checks, 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
+ diff)
113
+ strict_flags "gh pr diff" "--color|--name-only|--patch" "$@"
114
+ if [ -z "$(first_positional "--color" "$@")" ] && [ -n "$branch" ]; then
115
+ set -- "$branch" "$@"
116
+ fi
117
+ exec "$CTL" gh pr diff -- "$@"
118
+ ;;
119
+ checks)
120
+ strict_flags "gh pr checks" "--json|--required" "$@"
121
+ if [ -z "$(first_positional "--json" "$@")" ] && [ -n "$branch" ]; then
122
+ set -- "$branch" "$@"
123
+ fi
124
+ exec "$CTL" gh pr checks -- "$@"
125
+ ;;
126
+ create)
127
+ strict_flags "gh pr create" "--fill|--draft|--title|--body|--base" "$@"
128
+ if ! needle_present "--head" "$@" && [ -n "$branch" ]; then
129
+ set -- "$@" "--head" "$branch"
130
+ fi
131
+ exec "$CTL" gh pr create -- "$@"
132
+ ;;
133
+ comment)
134
+ strict_flags "gh pr comment" "--body" "$@"
135
+ if [ -z "$(first_positional "--body" "$@")" ] && [ -n "$branch" ]; then
136
+ set -- "$branch" "$@"
137
+ fi
138
+ exec "$CTL" gh pr comment -- "$@"
139
+ ;;
140
+ review)
141
+ strict_flags "gh pr review" "--approve|--request-changes|--comment|--body" "$@"
142
+ if [ -z "$(first_positional "--body" "$@")" ] && [ -n "$branch" ]; then
143
+ set -- "$branch" "$@"
144
+ fi
145
+ exec "$CTL" gh pr review -- "$@"
146
+ ;;
147
+ merge)
148
+ strict_flags "gh pr merge" "--squash|--merge|--rebase|--delete-branch" "$@"
149
+ if [ -z "$(first_positional "" "$@")" ] && [ -n "$branch" ]; then
150
+ set -- "$branch" "$@"
151
+ fi
152
+ exec "$CTL" gh pr merge -- "$@"
153
+ ;;
154
+ close)
155
+ strict_flags "gh pr close" "--delete-branch" "$@"
156
+ if [ -z "$(first_positional "" "$@")" ] && [ -n "$branch" ]; then
157
+ set -- "$branch" "$@"
158
+ fi
159
+ exec "$CTL" gh pr close -- "$@"
160
+ ;;
161
+ reopen)
162
+ strict_flags "gh pr reopen" "" "$@"
163
+ if [ -z "$(first_positional "" "$@")" ] && [ -n "$branch" ]; then
164
+ set -- "$branch" "$@"
165
+ fi
166
+ exec "$CTL" gh pr reopen -- "$@"
167
+ ;;
168
+ checkout)
169
+ # gh pr checkout takes a required ref (number / URL / branch). No
170
+ # auto-inject — the relay also refuses checkout by default
171
+ # (AGENTBOX_GH_PR_CHECKOUT=allow opt-in).
172
+ strict_flags "gh pr checkout" "" "$@"
173
+ if [ -z "$(first_positional "" "$@")" ]; then
174
+ die "'gh pr checkout' requires a positional ref (PR number, URL, or branch)"
175
+ fi
176
+ exec "$CTL" gh pr checkout -- "$@"
177
+ ;;
178
+ *)
179
+ die "'gh pr $op' is not proxied (supported: view, list, diff, checks, create, comment, review, merge, checkout, close, reopen)"
180
+ ;;
181
+ esac
182
+ }
183
+
184
+ handle_run() {
185
+ local op="${1-}"; shift || true
186
+ if [ -z "$op" ]; then
187
+ die "missing subcommand for 'gh run'. Supported: list, view, rerun"
188
+ fi
189
+ case "$op" in
190
+ list)
191
+ strict_flags "gh run list" "--json|--limit|-L|--workflow|-w|--branch|-b|--status|--user" "$@"
192
+ exec "$CTL" gh run list -- "$@"
193
+ ;;
194
+ view)
195
+ strict_flags "gh run view" "--json|--log|--log-failed|--job" "$@"
196
+ # gh run view needs a run-id OR a --job <id>; refuse when neither is
197
+ # present (host-side gh would otherwise try an interactive picker and
198
+ # fail without a TTY).
199
+ if [ -z "$(first_positional "--json|--job" "$@")" ] && ! needle_present "--job" "$@"; then
200
+ die "'gh run view' requires a positional <run-id> (or --job <job-id>)"
201
+ fi
202
+ exec "$CTL" gh run view -- "$@"
203
+ ;;
204
+ rerun)
205
+ strict_flags "gh run rerun" "--failed|--job" "$@"
206
+ if [ -z "$(first_positional "--job" "$@")" ] && ! needle_present "--job" "$@"; then
207
+ die "'gh run rerun' requires a positional <run-id> (or --job <job-id>)"
208
+ fi
209
+ exec "$CTL" gh run rerun -- "$@"
210
+ ;;
211
+ watch)
212
+ die "'gh run watch' is not proxied (it blocks until CI finishes). Poll status with 'gh run view <run-id>' instead."
213
+ ;;
214
+ *)
215
+ die "'gh run $op' is not proxied (supported: list, view, rerun)"
216
+ ;;
217
+ esac
218
+ }
219
+
220
+ handle_api() {
221
+ local endpoint="${1-}"
222
+ if [ -z "$endpoint" ] || [ "${endpoint:0:1}" = "-" ]; then
223
+ die "'gh api' requires a positional <endpoint> (e.g. repos/:owner/:repo/pulls/:number/comments)"
224
+ fi
225
+ shift
226
+ # GET reads are proxied for any allowlisted endpoint; POST is proxied only to
227
+ # the PR review-comment endpoints (the relay enforces the endpoint + method
228
+ # policy). `--input` (stdin/file body) can't cross the relay — the host `gh`
229
+ # runs with stdin ignored — so reject it locally and point at -f/-F fields.
230
+ local arg
231
+ for arg in "$@"; do
232
+ case "$arg" in
233
+ --input|--input=*)
234
+ die "'gh api --input' (stdin/file body) isn't supported through the relay; use -f/-F fields"
235
+ ;;
236
+ esac
237
+ done
238
+ strict_flags "gh api" \
239
+ "--method|-X|-f|-F|--field|--raw-field|--jq|-q|--paginate|--cache|--hostname|-H|--header" "$@"
240
+ exec "$CTL" gh api "$endpoint" -- "$@"
241
+ }
242
+
243
+ handle_repo() {
244
+ local op="${1-}"; shift || true
245
+ if [ "$op" != "clone" ]; then
246
+ die "'gh repo $op' is not proxied (supported: clone)"
247
+ fi
248
+ # gh repo clone <repo> [<dir>] [--branch <n>] [--depth <n>]
249
+ strict_flags "gh repo clone" "--branch|--depth" "$@"
250
+ # Split argv into (repo, dir, flags). Pass positionals BEFORE options to the
251
+ # ctl so commander parses --branch/--depth as real options; using a `--`
252
+ # separator would force commander to treat them as extra positionals (the
253
+ # ctl `gh repo clone` command doesn't allowExcessArguments).
254
+ local repo='' dir=''
255
+ local -a flags=()
256
+ local pos=0
257
+ local skip_value=0
258
+ local arg
259
+ for arg in "$@"; do
260
+ if [ "$skip_value" = "1" ]; then
261
+ flags+=("$arg")
262
+ skip_value=0
263
+ continue
264
+ fi
265
+ case "$arg" in
266
+ --branch|--depth)
267
+ flags+=("$arg")
268
+ skip_value=1
269
+ ;;
270
+ -*)
271
+ flags+=("$arg")
272
+ ;;
273
+ *)
274
+ if [ $pos -eq 0 ]; then repo="$arg"
275
+ elif [ $pos -eq 1 ]; then dir="$arg"
276
+ else die "too many positionals for 'gh repo clone' (got '$arg' after repo + dir)"
277
+ fi
278
+ pos=$((pos+1))
279
+ ;;
280
+ esac
281
+ done
282
+ if [ -z "$repo" ]; then
283
+ die "'gh repo clone' requires a positional <repo> (owner/name or full URL)"
284
+ fi
285
+ if [ -n "$dir" ]; then
286
+ exec "$CTL" gh repo clone "$repo" "$dir" ${flags[@]+"${flags[@]}"}
287
+ else
288
+ exec "$CTL" gh repo clone "$repo" ${flags[@]+"${flags[@]}"}
289
+ fi
290
+ }
291
+
292
+ # Top-level dispatch.
293
+ if [ $# -eq 0 ]; then
294
+ die "no subcommand. Supported: pr {view,list,diff,checks,create,comment,review,merge,checkout,close,reopen}, run {list,view,rerun}, api <endpoint>, repo clone, auth status, --version"
295
+ fi
296
+
297
+ case "$1" in
298
+ --version|-v)
299
+ # Real gh prints something like:
300
+ # gh version 2.40.0 (2023-10-26)
301
+ # https://github.com/cli/cli/releases/tag/v2.40.0
302
+ # Tools that sniff "gh version" succeed with our shim line too.
303
+ printf 'gh version 2.0.0 (agentbox-shim)\n'
304
+ printf 'https://github.com/cli/cli\n'
305
+ ;;
306
+ --help|-h)
307
+ printf 'agentbox gh shim — strict subset.\n' >&2
308
+ printf 'Supported: pr {view,list,diff,checks,create,comment,review,merge,checkout,close,reopen}, run {list,view,rerun}, api <endpoint>, repo clone, auth status, --version\n' >&2
309
+ printf 'Anything else is rejected. Run host `gh --help` for full upstream docs.\n' >&2
310
+ ;;
311
+ auth)
312
+ shift
313
+ case "${1-}" in
314
+ status)
315
+ # Real auth state is verified host-side on the next real RPC (relay's
316
+ # assertGhReady returns exit 4 if the host is logged out). We don't
317
+ # round-trip on every refresh-driven poll Claude Code does.
318
+ printf 'agentbox gh shim: logged in to github.com (via agentbox host relay)\n' >&2
319
+ ;;
320
+ *)
321
+ die "'gh auth ${1-}' is not proxied (supported: status)"
322
+ ;;
323
+ esac
324
+ ;;
325
+ pr)
326
+ shift
327
+ handle_pr "$@"
328
+ ;;
329
+ run)
330
+ shift
331
+ handle_run "$@"
332
+ ;;
333
+ api)
334
+ shift
335
+ handle_api "$@"
336
+ ;;
337
+ repo)
338
+ shift
339
+ handle_repo "$@"
340
+ ;;
341
+ *)
342
+ die "'gh $1' is not proxied (supported: pr {…}, run {…}, api <endpoint>, repo clone, auth status, --version)"
343
+ ;;
344
+ esac
@@ -0,0 +1,181 @@
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
+ # INVARIANT: every push/pull/fetch flag on a whitelist must be VALUE-LESS.
12
+ # A flag that takes a value can't be expressed anyway — the glued form
13
+ # (`--depth=1`) fails strict_flags' exact-match regex and the split form
14
+ # (`--depth 1`) has its value caught by refuse_positionals — which is what
15
+ # keeps `--upload-pack=`, `--receive-pack=`, `--exec=` and `-o` out for free.
16
+ # Allowing one would break that. (`clone` is the exception: it parses values
17
+ # explicitly, below.)
18
+ #
19
+ # Deliberately still refused, don't "helpfully" add them: `--delete`/`-d` and
20
+ # `--mirror` (destructive on the remote), `push --prune` (deletes remote refs),
21
+ # `push --force` (use `--force-with-lease`), and `--all` — the relay always
22
+ # passes a positional remote+branch, which `git fetch --all` rejects outright.
23
+
24
+ set -euo pipefail
25
+
26
+ # Paths are constants in production; env overrides exist purely to let unit
27
+ # tests substitute a stub `agentbox-ctl` on PATH without rewriting the shim.
28
+ # NEVER `exec git` — would loop on this shim. Always exec the resolved $REAL_GIT.
29
+ CTL="${AGENTBOX_CTL_PATH:-/usr/local/bin/agentbox-ctl}"
30
+ REAL_GIT="${AGENTBOX_REAL_GIT_PATH:-/usr/bin/git}"
31
+
32
+ # Output-verbosity flags: value-less, no side effects, accepted by all three
33
+ # network ops. Scripts run under `set -e` reach for these first.
34
+ COMMON_QUIET="--quiet|-q|--verbose|-v|--progress|--no-progress"
35
+
36
+ die() {
37
+ printf 'agentbox git shim: %s\n' "$*" >&2
38
+ exit 2
39
+ }
40
+
41
+ # Walk argv: any arg matching `-*` must be in $allowed (regex alternation).
42
+ # Doesn't validate flag _values_ (e.g. `--branch main`); that's git's job.
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
+ # Network ops (push/pull/fetch): refuse positional remote/branch. The ctl
61
+ # rebuilds them from the registered worktree; re-passing them as positionals
62
+ # makes git treat them as refspecs and fail with
63
+ # `refs/remotes/origin/HEAD cannot be resolved to branch` (documented at
64
+ # packages/ctl/src/commands/git.ts:131).
65
+ refuse_positionals() {
66
+ local subcmd="$1"; shift
67
+ local arg
68
+ for arg in "$@"; do
69
+ case "$arg" in
70
+ --) ;;
71
+ -*) ;;
72
+ *)
73
+ die "positional '$arg' not allowed for '$subcmd' (the box's remote and branch are taken from the registered worktree)"
74
+ ;;
75
+ esac
76
+ done
77
+ }
78
+
79
+ if [ $# -eq 0 ]; then
80
+ exec "$REAL_GIT"
81
+ fi
82
+
83
+ case "$1" in
84
+ push)
85
+ shift
86
+ strict_flags "git push" "--force-with-lease|--tags|--dry-run|$COMMON_QUIET" "$@"
87
+ refuse_positionals "git push" "$@"
88
+ exec "$CTL" git push -- "$@"
89
+ ;;
90
+ pull)
91
+ shift
92
+ strict_flags "git pull" "--ff-only|--prune|-p|--tags|--no-tags|$COMMON_QUIET" "$@"
93
+ refuse_positionals "git pull" "$@"
94
+ exec "$CTL" git pull -- "$@"
95
+ ;;
96
+ fetch)
97
+ shift
98
+ strict_flags "git fetch" "--prune|-p|--prune-tags|--tags|--no-tags|--force|-f|--dry-run|$COMMON_QUIET" "$@"
99
+ refuse_positionals "git fetch" "$@"
100
+ exec "$CTL" git fetch -- "$@"
101
+ ;;
102
+ clone)
103
+ shift
104
+ # A clone whose source is a filesystem path or `file://` URL needs no host
105
+ # credentials, and `agentbox-ctl git clone` only speaks github — so relaying
106
+ # it would be wrong, not merely strict. Fall through to the real git before
107
+ # the flag gate. agentbox's own cloud workspace seeding does exactly this
108
+ # (`git clone --no-checkout --quiet file:///workspace <tmp>`), which is how
109
+ # `agentbox create --provider <cloud>` runs from inside a box.
110
+ #
111
+ # Do NOT try to find "the repo positional" by skipping known flag values:
112
+ # options we don't model take a value too (`--reference <path>`,
113
+ # `--separate-git-dir <path>`, `--upload-pack <cmd>`), and that path would
114
+ # then read as the source — handing the real git a REMOTE clone and slipping
115
+ # both the relay and the whitelist. Instead classify EVERY non-flag token
116
+ # (values included) and only fall through when something is unmistakably
117
+ # local and nothing looks remote. Unknown/ambiguous ⇒ no fall-through ⇒ the
118
+ # strict gate below rejects it loudly. Fail-closed by default.
119
+ clone_local=0
120
+ clone_remote=0
121
+ for arg in "$@"; do
122
+ case "$arg" in
123
+ -*) continue ;;
124
+ esac
125
+ case "$arg" in
126
+ # file:// first: it also matches the `*://*` remote pattern below.
127
+ file://*|/*|./*|../*|~/*) clone_local=1 ;;
128
+ # scheme://, scp-style host:path / user@host:path, and the bare
129
+ # `owner/name` github shorthand that `agentbox-ctl git clone` accepts.
130
+ *://*|*:*|*/*) clone_remote=1 ;;
131
+ esac
132
+ done
133
+ if [ "$clone_local" = "1" ] && [ "$clone_remote" = "0" ]; then
134
+ exec "$REAL_GIT" clone "$@"
135
+ fi
136
+
137
+ strict_flags "git clone" "--branch|--depth" "$@"
138
+ # Walk argv: split into (url, dir, flags) so we can hand them to ctl
139
+ # in commander's expected shape (positionals first, then options).
140
+ url=''
141
+ dir=''
142
+ flags=()
143
+ pos=0
144
+ skip_value=0
145
+ for arg in "$@"; do
146
+ if [ "$skip_value" = "1" ]; then
147
+ flags+=("$arg")
148
+ skip_value=0
149
+ continue
150
+ fi
151
+ case "$arg" in
152
+ --branch|--depth)
153
+ flags+=("$arg")
154
+ skip_value=1
155
+ ;;
156
+ -*)
157
+ flags+=("$arg")
158
+ ;;
159
+ *)
160
+ if [ $pos -eq 0 ]; then url="$arg"
161
+ elif [ $pos -eq 1 ]; then dir="$arg"
162
+ else die "too many positionals for 'git clone' (got '$arg' after url + dir)"
163
+ fi
164
+ pos=$((pos+1))
165
+ ;;
166
+ esac
167
+ done
168
+ if [ -z "$url" ]; then
169
+ die "'git clone' requires a positional <url> (github URL or owner/name shorthand)"
170
+ fi
171
+ # `set -u` + empty array: use the ${arr[@]+"${arr[@]}"} guard.
172
+ if [ -n "$dir" ]; then
173
+ exec "$CTL" git clone "$url" "$dir" ${flags[@]+"${flags[@]}"}
174
+ else
175
+ exec "$CTL" git clone "$url" ${flags[@]+"${flags[@]}"}
176
+ fi
177
+ ;;
178
+ *)
179
+ exec "$REAL_GIT" "$@"
180
+ ;;
181
+ esac