@madarco/agentbox 0.19.0 → 0.20.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.
- package/CHANGELOG.md +62 -0
- package/dist/{_cloud-attach-YM2KOWHO.js → _cloud-attach-THTN4CFZ.js} +7 -5
- package/dist/{chunk-A5OFRJDI.js → chunk-3VFY3N4A.js} +76 -22
- package/dist/chunk-3VFY3N4A.js.map +1 -0
- package/dist/{chunk-Y6PUCLOE.js → chunk-52LKNUY7.js} +5 -2
- package/dist/chunk-52LKNUY7.js.map +1 -0
- package/dist/{chunk-JK5V4OLT.js → chunk-7RWFYLF3.js} +194 -34
- package/dist/chunk-7RWFYLF3.js.map +1 -0
- package/dist/{chunk-SPUUOEW2.js → chunk-ZX6DTA4X.js} +5 -4
- package/dist/chunk-ZX6DTA4X.js.map +1 -0
- package/dist/{dist-EKSNZHDY.js → dist-3PLT2EK2.js} +6 -2
- package/dist/{dist-VQSZVBT3.js → dist-3WFNXXPE.js} +3 -3
- package/dist/{dist-U2BHTWG4.js → dist-7ELDXBAG.js} +6 -5
- package/dist/dist-7ELDXBAG.js.map +1 -0
- package/dist/{dist-PRDYMXCX.js → dist-C3YRC3PP.js} +3 -3
- package/dist/{dist-FTCDWRAL.js → dist-CZ6CRADC.js} +3 -3
- package/dist/index.js +789 -291
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/runtime/docker/packages/ctl/dist/bin.cjs +122 -62
- package/runtime/docker/packages/sandbox-docker/scripts/claude-managed-settings.json +4 -4
- package/runtime/e2b/agentbox-dockerd-start +145 -0
- package/runtime/e2b/attach-helper.cjs +23 -2
- package/runtime/e2b/claude-managed-settings.json +4 -4
- package/runtime/e2b/ctl.cjs +122 -62
- package/runtime/e2b/scripts/build-template.sh +22 -5
- package/runtime/hetzner/claude-managed-settings.json +4 -4
- package/runtime/hetzner/ctl.cjs +122 -62
- package/runtime/relay/bin.cjs +6 -0
- package/runtime/vercel/claude-managed-settings.json +4 -4
- package/runtime/vercel/ctl.cjs +122 -62
- package/share/host-skills/agentbox/SKILL.md +2 -2
- package/share/host-skills/agentbox-info/SKILL.md +6 -6
- package/share/host-skills/codex/agentbox.md +2 -2
- package/share/host-skills/opencode/agentbox.md +2 -2
- package/dist/chunk-A5OFRJDI.js.map +0 -1
- package/dist/chunk-JK5V4OLT.js.map +0 -1
- package/dist/chunk-SPUUOEW2.js.map +0 -1
- package/dist/chunk-Y6PUCLOE.js.map +0 -1
- package/dist/dist-U2BHTWG4.js.map +0 -1
- /package/dist/{_cloud-attach-YM2KOWHO.js.map → _cloud-attach-THTN4CFZ.js.map} +0 -0
- /package/dist/{dist-EKSNZHDY.js.map → dist-3PLT2EK2.js.map} +0 -0
- /package/dist/{dist-VQSZVBT3.js.map → dist-3WFNXXPE.js.map} +0 -0
- /package/dist/{dist-PRDYMXCX.js.map → dist-C3YRC3PP.js.map} +0 -0
- /package/dist/{dist-FTCDWRAL.js.map → dist-CZ6CRADC.js.map} +0 -0
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
writePreparedStateRaw
|
|
9
9
|
} from "./chunk-7K2A3NLE.js";
|
|
10
10
|
|
|
11
|
-
// ../../packages/sandbox-e2b/dist/chunk-
|
|
11
|
+
// ../../packages/sandbox-e2b/dist/chunk-X7N6LNAQ.js
|
|
12
12
|
import { existsSync, readFileSync } from "fs";
|
|
13
13
|
import { homedir } from "os";
|
|
14
14
|
import { resolve } from "path";
|
|
@@ -206,6 +206,7 @@ function findStagedCliRuntimeRoot() {
|
|
|
206
206
|
var RUNTIME_ASSETS = [
|
|
207
207
|
{ name: "build-template.sh", remotePath: "/tmp/agentbox-build-template.sh", remoteMode: 493 },
|
|
208
208
|
{ name: "agentbox-ctl", remotePath: "/tmp/agentbox-ctl", remoteMode: 493 },
|
|
209
|
+
{ name: "agentbox-dockerd-start", remotePath: "/tmp/agentbox-dockerd-start", remoteMode: 493 },
|
|
209
210
|
{ name: "agentbox-vnc-start", remotePath: "/tmp/agentbox-vnc-start", remoteMode: 493 },
|
|
210
211
|
{ name: "agentbox-checkpoint-cleanup", remotePath: "/tmp/agentbox-checkpoint-cleanup", remoteMode: 493 },
|
|
211
212
|
{ name: "agentbox-open", remotePath: "/tmp/agentbox-open", remoteMode: 493 },
|
|
@@ -224,6 +225,7 @@ function candidatesFor(name, opts = {}) {
|
|
|
224
225
|
const monorepoRelative = {
|
|
225
226
|
"build-template.sh": ["packages/sandbox-e2b/scripts/build-template.sh"],
|
|
226
227
|
"agentbox-ctl": ["packages/ctl/dist/bin.cjs"],
|
|
228
|
+
"agentbox-dockerd-start": ["packages/sandbox-docker/scripts/agentbox-dockerd-start"],
|
|
227
229
|
"agentbox-vnc-start": ["packages/sandbox-docker/scripts/agentbox-vnc-start"],
|
|
228
230
|
"agentbox-checkpoint-cleanup": ["packages/sandbox-docker/scripts/agentbox-checkpoint-cleanup"],
|
|
229
231
|
"agentbox-open": ["packages/sandbox-docker/scripts/agentbox-open"],
|
|
@@ -239,6 +241,7 @@ function candidatesFor(name, opts = {}) {
|
|
|
239
241
|
const cliRelative = {
|
|
240
242
|
"build-template.sh": ["e2b/scripts/build-template.sh"],
|
|
241
243
|
"agentbox-ctl": ["e2b/ctl.cjs"],
|
|
244
|
+
"agentbox-dockerd-start": ["e2b/agentbox-dockerd-start", "docker/packages/sandbox-docker/scripts/agentbox-dockerd-start"],
|
|
242
245
|
"agentbox-vnc-start": ["e2b/agentbox-vnc-start", "docker/packages/sandbox-docker/scripts/agentbox-vnc-start"],
|
|
243
246
|
"agentbox-checkpoint-cleanup": ["e2b/agentbox-checkpoint-cleanup", "docker/packages/sandbox-docker/scripts/agentbox-checkpoint-cleanup"],
|
|
244
247
|
"agentbox-open": ["e2b/agentbox-open", "docker/packages/sandbox-docker/scripts/agentbox-open"],
|
|
@@ -351,4 +354,4 @@ export {
|
|
|
351
354
|
currentE2bBaseFingerprintLive,
|
|
352
355
|
ensureE2bBaseTemplate
|
|
353
356
|
};
|
|
354
|
-
//# sourceMappingURL=chunk-
|
|
357
|
+
//# sourceMappingURL=chunk-52LKNUY7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../packages/sandbox-e2b/src/env-loader.ts","../../../packages/sandbox-e2b/src/sdk.ts","../../../packages/sandbox-e2b/src/credentials.ts","../../../packages/sandbox-e2b/src/runtime-assets.ts","../../../packages/sandbox-e2b/src/prepared-state.ts"],"sourcesContent":["/**\n * E2B env auto-loader. The `e2b` SDK reads `E2B_API_KEY` (and optionally\n * `E2B_DOMAIN` for non-default deployments) from `process.env`. We seed those\n * from `~/.agentbox/secrets.env` (written by `agentbox e2b login`) so the SDK\n * Just Works after a one-time login — same pattern as the daytona / hetzner /\n * vercel env-loaders.\n *\n * Lookup order (first wins; process.env is never overwritten):\n * 1. `process.env` (already set in the shell).\n * 2. `~/.agentbox/secrets.env` — written by `agentbox e2b login`.\n *\n * Project-level `.env` / `.env.local` are intentionally NOT consulted: those\n * files belong to the app code being developed. Put host credentials in\n * `~/.agentbox/secrets.env` (or the shell env).\n *\n * Only E2B-prefixed keys are imported; the rest of the file is left alone.\n * Idempotent and side-effect-free after the first call.\n */\n\nimport { existsSync, readFileSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { resolve } from 'node:path';\n\nconst E2B_KEYS = ['E2B_API_KEY', 'E2B_DOMAIN'] as const;\n\nlet loaded = false;\n\nexport function ensureE2bEnvLoaded(): void {\n if (loaded) return;\n loaded = true;\n importE2bFromFile(resolve(homedir(), '.agentbox', 'secrets.env'), E2B_KEYS);\n}\n\n/**\n * Force a re-read of `~/.agentbox/secrets.env`. Used by the interactive\n * `agentbox e2b login` flow after it persists the API key, so the same process\n * can pick it up without a restart.\n */\nexport function reloadE2bEnv(): void {\n loaded = false;\n ensureE2bEnvLoaded();\n}\n\nfunction importE2bFromFile(path: string, keys: readonly string[]): void {\n if (!existsSync(path)) return;\n let body: string;\n try {\n body = readFileSync(path, 'utf8');\n } catch {\n return;\n }\n const parsed = parseEnvFile(body);\n for (const key of keys) {\n if (process.env[key] !== undefined) continue;\n const value = parsed[key];\n if (typeof value === 'string') {\n process.env[key] = value;\n }\n }\n}\n\n/**\n * Minimal `.env` parser: handles `KEY=value`, `KEY=\"value\"`, `KEY='value'`,\n * `export KEY=value`, blank lines, and `#` comments. No variable interpolation\n * — predictable over feature-complete (matches the daytona / vercel loaders).\n */\nexport function parseEnvFile(body: string): Record<string, string> {\n const out: Record<string, string> = {};\n for (const rawLine of body.split(/\\r?\\n/)) {\n const line = rawLine.trim();\n if (line.length === 0 || line.startsWith('#')) continue;\n const stripped = line.startsWith('export ') ? line.slice('export '.length) : line;\n const eq = stripped.indexOf('=');\n if (eq <= 0) continue;\n const key = stripped.slice(0, eq).trim();\n let value = stripped.slice(eq + 1).trim();\n if (\n value.length >= 2 &&\n ((value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\")))\n ) {\n value = value.slice(1, -1);\n }\n out[key] = value;\n }\n return out;\n}\n","/**\n * Thin wrapper around the `e2b` SDK. Resolves the API key once and re-exports\n * the SDK surface the rest of the package uses from a single place (so tests\n * can mock `./sdk.js` instead of the package).\n *\n * E2B only ships one auth mode for first-party use: a single API key. The SDK\n * already reads `process.env.E2B_API_KEY` on each call, but we still expose\n * `resolveApiKey()` so callers can fail loud with an actionable error before\n * the SDK throws a generic \"401 unauthorized\" deep inside an op.\n */\n\nimport { Sandbox, Template } from 'e2b';\nimport { ensureE2bEnvLoaded } from './env-loader.js';\n\nexport { Sandbox, Template };\nexport type { SandboxOpts, SandboxInfo, SandboxState, SandboxListOpts, LogEntry, BuildInfo } from 'e2b';\n\n/**\n * Return the configured E2B API key. Throws an actionable error when nothing\n * is configured. Idempotent — env-loader caches itself after first call.\n */\nexport function resolveApiKey(): string {\n ensureE2bEnvLoaded();\n const k = process.env.E2B_API_KEY;\n if (!k) {\n throw new Error(\n 'E2B credentials not configured.\\n' +\n 'Run `agentbox e2b login` to paste your API key (from https://e2b.dev/dashboard?tab=keys), ' +\n 'or set E2B_API_KEY in the environment / ~/.agentbox/secrets.env.',\n );\n }\n return k;\n}\n\n/** True when an API key is configured. Used by the credential gate. */\nexport function hasUsableCredentials(): boolean {\n ensureE2bEnvLoaded();\n return Boolean(process.env.E2B_API_KEY);\n}\n","/**\n * Interactive E2B credential setup. Single mode — paste an API key from\n * https://e2b.dev/dashboard?tab=keys — much simpler than vercel's three-mode\n * flow. Persists to `~/.agentbox/secrets.env` (the canonical store, matching\n * daytona / hetzner / vercel).\n *\n * Non-interactive callers (no TTY): silent no-op, so scripted/CI runs surface\n * the SDK's own \"not configured\" error instead of hanging on a prompt.\n */\n\nimport {\n chmodSync,\n existsSync,\n mkdirSync,\n readFileSync,\n renameSync,\n writeFileSync,\n} from 'node:fs';\nimport { homedir } from 'node:os';\nimport { dirname, resolve } from 'node:path';\nimport { hostOpenCommand } from '@agentbox/sandbox-core';\nimport {\n cancel,\n confirm,\n intro,\n isCancel,\n log,\n note,\n outro,\n password,\n} from '@clack/prompts';\nimport { ensureE2bEnvLoaded, reloadE2bEnv } from './env-loader.js';\nimport { hasUsableCredentials } from './sdk.js';\n\n// Ctrl+C at a prompt resolves with the cancel symbol; turn that into a real\n// quit so the command never silently continues as if the user answered \"No\".\nfunction exitOnCancel<T>(v: T | symbol): T {\n if (isCancel(v)) {\n cancel('Cancelled.');\n process.exit(130);\n }\n return v as T;\n}\n\nconst DASHBOARD_KEYS_URL = 'https://e2b.dev/dashboard?tab=keys';\n\n/**\n * Keys we manage in `~/.agentbox/secrets.env`. On reconfigure we strip prior\n * values for these before appending so the file never accumulates duplicates.\n */\nconst MANAGED_KEYS = ['E2B_API_KEY'] as const;\n\nexport interface EnsureE2bCredentialsOptions {\n /** Re-prompt even when valid credentials are already present (`agentbox e2b login`). */\n force?: boolean;\n}\n\nexport async function ensureE2bCredentials(\n opts: EnsureE2bCredentialsOptions = {},\n): Promise<void> {\n ensureE2bEnvLoaded();\n\n if (!opts.force && hasUsableCredentials()) return;\n if (!process.stdin.isTTY) return;\n\n intro('E2B setup');\n note(\n `AgentBox needs an E2B API key to provision sandboxes.\\n` +\n `Get one from ${DASHBOARD_KEYS_URL} (free tier available), then paste it below.\\n` +\n `The key is stored in \\`~/.agentbox/secrets.env\\` (mode 0600) — no .env.local harvesting.`,\n 'Credentials required',\n );\n\n const openIt = exitOnCancel(\n await confirm({\n message: `Open ${DASHBOARD_KEYS_URL} to create a key?`,\n initialValue: true,\n }),\n );\n if (openIt) openDashboard();\n\n const key = exitOnCancel(\n await password({\n message: 'Paste your E2B API key',\n validate: (v) => (v && v.trim().length > 0 ? undefined : 'Cannot be empty'),\n }),\n );\n\n persistCredentials({ apiKey: key.trim() });\n reloadE2bEnv();\n log.success(`E2B credentials saved to ${secretsPath()}`);\n outro('Setup complete.');\n}\n\nfunction persistCredentials(creds: { apiKey: string }): void {\n writeManaged({ E2B_API_KEY: creds.apiKey });\n}\n\n/**\n * Atomically rewrite the managed E2B keys in `~/.agentbox/secrets.env`:\n * strip every prior value for a `MANAGED_KEYS` entry, then append exactly the\n * keys in `record` (mode 0600, temp-file + rename). Also mirrors the record\n * into `process.env` so the current run uses the new values immediately.\n */\nfunction writeManaged(record: Record<string, string>): void {\n for (const k of MANAGED_KEYS) delete process.env[k];\n for (const [k, v] of Object.entries(record)) process.env[k] = v;\n\n const path = secretsPath();\n mkdirSync(dirname(path), { recursive: true });\n\n let existing = '';\n if (existsSync(path)) {\n try {\n existing = readFileSync(path, 'utf8');\n } catch {\n existing = '';\n }\n }\n const kept = existing\n .split(/\\r?\\n/)\n .filter((line) => {\n const stripped = line.startsWith('export ') ? line.slice('export '.length) : line;\n const eq = stripped.indexOf('=');\n if (eq <= 0) return true;\n const key = stripped.slice(0, eq).trim();\n return !(MANAGED_KEYS as readonly string[]).includes(key);\n })\n .join('\\n')\n .replace(/\\s+$/u, '');\n\n const lines = Object.entries(record).map(([k, v]) => `${k}=${v}`);\n const body = (kept ? `${kept}\\n` : '') + lines.join('\\n') + '\\n';\n\n const tmp = `${path}.tmp`;\n writeFileSync(tmp, body, { mode: 0o600 });\n try {\n chmodSync(tmp, 0o600);\n } catch {\n // chmod best-effort; writeFileSync mode already covers most filesystems.\n }\n renameSync(tmp, path);\n try {\n chmodSync(path, 0o600);\n } catch {\n // ignore — already attempted above\n }\n}\n\nfunction openDashboard(): void {\n import('node:child_process')\n .then(({ spawnSync }) => {\n const r = spawnSync(hostOpenCommand(), [DASHBOARD_KEYS_URL], { stdio: 'ignore' });\n if (r.status !== 0) {\n log.warn(`Could not auto-open the browser — visit ${DASHBOARD_KEYS_URL} manually.`);\n }\n })\n .catch(() => {\n log.warn(`Could not auto-open the browser — visit ${DASHBOARD_KEYS_URL} manually.`);\n });\n}\n\nexport function secretsPath(): string {\n return resolve(homedir(), '.agentbox', 'secrets.env');\n}\n\nexport interface E2bCredStatus {\n auth: 'key' | 'none';\n token?: string;\n source: 'env' | 'secrets.env' | 'none';\n}\n\nexport function readE2bCredStatus(): E2bCredStatus {\n const shellHad = process.env.E2B_API_KEY !== undefined;\n ensureE2bEnvLoaded();\n const key = process.env.E2B_API_KEY;\n if (!key) return { auth: 'none', source: 'none' };\n return { auth: 'key', token: key, source: shellHad ? 'env' : 'secrets.env' };\n}\n\nexport function maskKey(value: string): string {\n if (value.length <= 8) return '*'.repeat(value.length);\n return `${value.slice(0, 4)}…${'*'.repeat(8)}${value.slice(-4)}`;\n}\n","/**\n * Resolver for the runtime payload baked into the E2B base template during\n * `prepareE2b()`. Same idea as the vercel resolver: a flat list of files to\n * `template.copy` into the build context, each resolved from either the\n * staged CLI runtime tree or the monorepo source tree.\n *\n * Lookup order per file:\n * 1. The CLI's staged runtime tree: `<cliRoot>/e2b/...`.\n * 2. The monorepo source tree (dev fallback) under `packages/`.\n *\n * Any missing file throws a clear error naming the paths tried. Includes the\n * shared dockerd launch helper — E2B microVMs DO support nested containers, so\n * the base template bakes the docker engine (in-box DinD).\n */\n\nimport { existsSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst SELF = dirname(fileURLToPath(import.meta.url));\n\nexport function findStagedCliRuntimeRoot(): string | undefined {\n const candidates = [resolve(SELF, '..', 'runtime'), resolve(SELF, '..', '..', 'runtime')];\n for (const c of candidates) {\n if (existsSync(resolve(c, 'e2b', 'scripts', 'build-template.sh'))) return c;\n }\n return undefined;\n}\n\nexport interface RuntimeAsset {\n /** Logical name (used in error messages + log lines). */\n name: string;\n /** Absolute path inside the template's build filesystem (Template.copy target). */\n remotePath: string;\n /** File mode to apply after upload. */\n remoteMode: number;\n}\n\n/**\n * Where each asset lands inside the sandbox during template build. build-template.sh\n * reads them from these fixed paths. The agent/runtime helpers go straight to\n * /usr/local/bin via the script; baked config files to /tmp for the script to\n * `install` into place.\n */\nexport const RUNTIME_ASSETS: readonly RuntimeAsset[] = [\n { name: 'build-template.sh', remotePath: '/tmp/agentbox-build-template.sh', remoteMode: 0o755 },\n { name: 'agentbox-ctl', remotePath: '/tmp/agentbox-ctl', remoteMode: 0o755 },\n { name: 'agentbox-dockerd-start', remotePath: '/tmp/agentbox-dockerd-start', remoteMode: 0o755 },\n { name: 'agentbox-vnc-start', remotePath: '/tmp/agentbox-vnc-start', remoteMode: 0o755 },\n { name: 'agentbox-checkpoint-cleanup', remotePath: '/tmp/agentbox-checkpoint-cleanup', remoteMode: 0o755 },\n { name: 'agentbox-open', remotePath: '/tmp/agentbox-open', remoteMode: 0o755 },\n { name: 'gh-shim', remotePath: '/tmp/agentbox-gh-shim', remoteMode: 0o755 },\n { name: 'git-shim', remotePath: '/tmp/agentbox-git-shim', remoteMode: 0o755 },\n { name: 'ntn-shim', remotePath: '/tmp/agentbox-ntn-shim', remoteMode: 0o755 },\n { name: 'linear-shim', remotePath: '/tmp/agentbox-linear-shim', remoteMode: 0o755 },\n { name: 'custom-system-CLAUDE.md', remotePath: '/tmp/agentbox-custom-CLAUDE.md', remoteMode: 0o644 },\n { name: 'claude-managed-settings.json', remotePath: '/tmp/agentbox-managed-settings.json', remoteMode: 0o644 },\n { name: 'agentbox-codex-hooks.json', remotePath: '/tmp/agentbox-codex-hooks.json', remoteMode: 0o644 },\n { name: 'agentbox-setup-skill.md', remotePath: '/tmp/agentbox-setup-skill.md', remoteMode: 0o644 },\n] as const;\n\nexport interface ResolvedAsset extends RuntimeAsset {\n localPath: string;\n}\n\nexport function candidatesFor(\n name: string,\n opts: { cliRuntimeRoot?: string; repoRoot?: string } = {},\n): string[] {\n const cliRoot = opts.cliRuntimeRoot;\n const monorepo = opts.repoRoot ?? guessRepoRoot();\n\n const monorepoRelative: Record<string, string[]> = {\n 'build-template.sh': ['packages/sandbox-e2b/scripts/build-template.sh'],\n 'agentbox-ctl': ['packages/ctl/dist/bin.cjs'],\n 'agentbox-dockerd-start': ['packages/sandbox-docker/scripts/agentbox-dockerd-start'],\n 'agentbox-vnc-start': ['packages/sandbox-docker/scripts/agentbox-vnc-start'],\n 'agentbox-checkpoint-cleanup': ['packages/sandbox-docker/scripts/agentbox-checkpoint-cleanup'],\n 'agentbox-open': ['packages/sandbox-docker/scripts/agentbox-open'],\n 'gh-shim': ['packages/sandbox-docker/scripts/gh-shim'],\n 'git-shim': ['packages/sandbox-docker/scripts/git-shim'],\n 'ntn-shim': ['packages/sandbox-docker/scripts/ntn-shim'],\n 'linear-shim': ['packages/sandbox-docker/scripts/linear-shim'],\n 'custom-system-CLAUDE.md': ['packages/sandbox-e2b/scripts/custom-system-CLAUDE.md'],\n 'claude-managed-settings.json': ['packages/sandbox-docker/scripts/claude-managed-settings.json'],\n 'agentbox-codex-hooks.json': ['packages/sandbox-docker/scripts/agentbox-codex-hooks.json'],\n 'agentbox-setup-skill.md': ['apps/cli/share/agentbox-setup/SKILL.md'],\n };\n\n const cliRelative: Record<string, string[]> = {\n 'build-template.sh': ['e2b/scripts/build-template.sh'],\n 'agentbox-ctl': ['e2b/ctl.cjs'],\n 'agentbox-dockerd-start': ['e2b/agentbox-dockerd-start', 'docker/packages/sandbox-docker/scripts/agentbox-dockerd-start'],\n 'agentbox-vnc-start': ['e2b/agentbox-vnc-start', 'docker/packages/sandbox-docker/scripts/agentbox-vnc-start'],\n 'agentbox-checkpoint-cleanup': ['e2b/agentbox-checkpoint-cleanup', 'docker/packages/sandbox-docker/scripts/agentbox-checkpoint-cleanup'],\n 'agentbox-open': ['e2b/agentbox-open', 'docker/packages/sandbox-docker/scripts/agentbox-open'],\n 'gh-shim': ['e2b/gh-shim', 'docker/packages/sandbox-docker/scripts/gh-shim'],\n 'git-shim': ['e2b/git-shim', 'docker/packages/sandbox-docker/scripts/git-shim'],\n 'ntn-shim': ['e2b/ntn-shim', 'docker/packages/sandbox-docker/scripts/ntn-shim'],\n 'linear-shim': ['e2b/linear-shim', 'docker/packages/sandbox-docker/scripts/linear-shim'],\n 'custom-system-CLAUDE.md': ['e2b/custom-system-CLAUDE.md'],\n 'claude-managed-settings.json': ['e2b/claude-managed-settings.json', 'docker/packages/sandbox-docker/scripts/claude-managed-settings.json'],\n 'agentbox-codex-hooks.json': ['e2b/agentbox-codex-hooks.json', 'docker/packages/sandbox-docker/scripts/agentbox-codex-hooks.json'],\n 'agentbox-setup-skill.md': ['e2b/agentbox-setup-skill.md', 'docker/apps/cli/share/agentbox-setup/SKILL.md'],\n };\n\n const out: string[] = [];\n if (cliRoot) {\n for (const rel of cliRelative[name] ?? []) out.push(resolve(cliRoot, rel));\n }\n for (const rel of monorepoRelative[name] ?? []) out.push(resolve(monorepo, rel));\n return out;\n}\n\nexport function resolveRuntimeAssets(\n opts: { cliRuntimeRoot?: string; repoRoot?: string } = {},\n): ResolvedAsset[] {\n const out: ResolvedAsset[] = [];\n const missing: Array<{ name: string; tried: string[] }> = [];\n for (const asset of RUNTIME_ASSETS) {\n const cands = candidatesFor(asset.name, opts);\n const hit = cands.find((p) => existsSync(p));\n if (!hit) {\n missing.push({ name: asset.name, tried: cands });\n continue;\n }\n out.push({ ...asset, localPath: hit });\n }\n if (missing.length > 0) {\n const lines = missing.flatMap((m) => [` - ${m.name}: tried`, ...m.tried.map((p) => ` ${p}`)]);\n throw new Error(\n `e2b: could not resolve runtime assets needed to bake the base template:\\n` +\n lines.join('\\n') +\n `\\n\\nIf running from the monorepo, ensure \\`pnpm -w build\\` has run so packages/ctl/dist/bin.cjs exists.`,\n );\n }\n return out;\n}\n\nfunction guessRepoRoot(): string {\n let cur = SELF;\n for (let i = 0; i < 8; i++) {\n if (existsSync(resolve(cur, 'pnpm-workspace.yaml'))) return cur;\n const parent = dirname(cur);\n if (parent === cur) break;\n cur = parent;\n }\n return SELF;\n}\n","/**\n * Persisted record of what `agentbox prepare --provider e2b` has built.\n * Lives at `~/.agentbox/e2b-prepared.json` so the auto-prepare gate\n * (`ensureE2bBaseTemplate()`) and `backend.provision` can resolve the base\n * template every box boots from.\n *\n * Single tier for now — the shared base template (Debian + agentbox-ctl +\n * agents). Templates on E2B are id+tag-addressed reusable resources, so unlike\n * Vercel snapshots we don't worry about per-box snapshot eviction; one template\n * is reused for every create.\n *\n * Schema versioned so future shape changes can migrate; only `schema: 1` is\n * accepted today.\n */\n\nimport { computeContextSha256, readPreparedStateRaw, writePreparedStateRaw, preparedStatePathFor } from '@agentbox/sandbox-core';\nimport { UserFacingError } from '@agentbox/core';\nimport { findStagedCliRuntimeRoot, resolveRuntimeAssets } from './runtime-assets.js';\n\nconst SCHEMA = 1 as const;\n\nexport interface PreparedE2bBase {\n /** Opaque E2B template id (e.g. `tmpl_xxxx` or `name:tag`). Sandbox.create({ template }) boots from this. */\n templateId: string;\n /** Human-friendly template name passed to Template.build (e.g. `agentbox-base:latest`). */\n templateName?: string;\n /** Deterministic SHA-256 of the build context (build script + assets). */\n contextSha256?: string;\n /** CLI version that produced this template (informational). */\n cliVersion?: string;\n /** Git short SHA of the CLI build (informational). */\n cliCommit?: string;\n /** ISO timestamp of bake completion. */\n createdAt: string;\n}\n\nexport interface PreparedE2bState {\n schema: typeof SCHEMA;\n /** The shared base template. Absent until first `agentbox prepare`. */\n base?: PreparedE2bBase;\n}\n\nexport function preparedStatePath(): string {\n return preparedStatePathFor('e2b');\n}\n\nexport function readPreparedState(): PreparedE2bState {\n const raw = readPreparedStateRaw('e2b');\n if (raw === null || typeof raw !== 'object') return { schema: SCHEMA };\n const parsed = raw as Partial<PreparedE2bState>;\n if (parsed.schema !== SCHEMA) {\n // Unknown/missing schema: refuse to read — the next prepare overwrites it.\n return { schema: SCHEMA };\n }\n return { schema: SCHEMA, base: parsed.base };\n}\n\nexport function writePreparedState(state: PreparedE2bState): void {\n writePreparedStateRaw('e2b', state);\n}\n\n/** Update one field of the state without forcing callers to read/merge/write. */\nexport function updatePreparedState(mutate: (s: PreparedE2bState) => void): void {\n const s = readPreparedState();\n mutate(s);\n writePreparedState(s);\n}\n\n/**\n * Compute the CURRENT build-context fingerprint for the e2b base template\n * (the SHA over every file `prepare` would copy into the Template build).\n * Side-effect-free — never builds. Returns `undefined` when the runtime\n * assets can't be resolved (dev tree without `pnpm -w build`) so the CLI\n * can degrade to \"can't tell, don't nag\" rather than flag a false stale.\n *\n * Used by `evaluateBaseFreshness` to compare against the stored value in\n * `e2b-prepared.json.base.contextSha256`. Must produce a byte-identical\n * hash to the one `prepare` writes — both go through the same\n * `resolveRuntimeAssets` + `computeContextSha256` chain.\n */\nexport async function currentE2bBaseFingerprintLive(): Promise<string | undefined> {\n try {\n const assets = resolveRuntimeAssets({ cliRuntimeRoot: findStagedCliRuntimeRoot() });\n return await computeContextSha256(\n assets.map((a) => ({ rel: a.name, abs: a.localPath })),\n );\n } catch {\n return undefined;\n }\n}\n\n/**\n * First-use gate. If no base template is recorded, throw an actionable error\n * pointing at `agentbox prepare --provider e2b`. Called by `backend.provision`\n * (so `create` / `claude` trip it but `prepare` itself does not — same shape\n * as the hetzner/vercel gates).\n */\nexport function ensureE2bBaseTemplate(): void {\n const state = readPreparedState();\n if (state.base !== undefined) return;\n throw new UserFacingError(\n 'no E2B base template found.\\n' +\n 'Run `agentbox prepare --provider e2b` first — it bakes a custom template ' +\n 'with the agentbox runtime (agentbox-ctl, vscode user, claude/codex/opencode, tmux) ' +\n 'so per-box `create` boots ready in seconds.',\n );\n}\n"],"mappings":";;;;;;;;;;;AAmBA,SAAS,YAAY,oBAAoB;AACzC,SAAS,eAAe;AACxB,SAAS,eAAe;ACVxB,SAAS,SAAS,gBAAgB;ACDlC;EACE;EACA,cAAAA;EACA;EACA,gBAAAC;EACA;EACA;OACK;AACP,SAAS,WAAAC,gBAAe;AACxB,SAAS,SAAS,WAAAC,gBAAe;AAEjC;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;OACK;ACfP,SAAS,cAAAC,mBAAkB;AAC3B,SAAS,WAAAC,UAAS,WAAAC,gBAAe;AACjC,SAAS,qBAAqB;AHM9B,IAAM,WAAW,CAAC,eAAe,YAAY;AAE7C,IAAI,SAAS;AAEN,SAAS,qBAA2B;AACzC,MAAI,OAAQ;AACZ,WAAS;AACT,oBAAkB,QAAQ,QAAQ,GAAG,aAAa,aAAa,GAAG,QAAQ;AAC5E;AAOO,SAAS,eAAqB;AACnC,WAAS;AACT,qBAAmB;AACrB;AAEA,SAAS,kBAAkB,MAAc,MAA+B;AACtE,MAAI,CAAC,WAAW,IAAI,EAAG;AACvB,MAAI;AACJ,MAAI;AACF,WAAO,aAAa,MAAM,MAAM;EAClC,QAAQ;AACN;EACF;AACA,QAAM,SAAS,aAAa,IAAI;AAChC,aAAW,OAAO,MAAM;AACtB,QAAI,QAAQ,IAAI,GAAG,MAAM,OAAW;AACpC,UAAM,QAAQ,OAAO,GAAG;AACxB,QAAI,OAAO,UAAU,UAAU;AAC7B,cAAQ,IAAI,GAAG,IAAI;IACrB;EACF;AACF;AAOO,SAAS,aAAa,MAAsC;AACjE,QAAM,MAA8B,CAAC;AACrC,aAAW,WAAW,KAAK,MAAM,OAAO,GAAG;AACzC,UAAM,OAAO,QAAQ,KAAK;AAC1B,QAAI,KAAK,WAAW,KAAK,KAAK,WAAW,GAAG,EAAG;AAC/C,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;AAQO,SAAS,wBAA8B;AAC5C,QAAM,QAAQ,kBAAkB;AAChC,MAAI,MAAM,SAAS,OAAW;AAC9B,QAAM,IAAI;IACR;EAIF;AACF;","names":["existsSync","readFileSync","homedir","resolve","existsSync","dirname","resolve","existsSync","readFileSync","resolve","homedir","dirname"]}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
DEFAULT_RELAY_PORT,
|
|
4
4
|
loadEffectiveConfig,
|
|
5
|
-
readBoxStatus
|
|
6
|
-
|
|
5
|
+
readBoxStatus,
|
|
6
|
+
startClaudeSession,
|
|
7
|
+
startCodexSession
|
|
8
|
+
} from "./chunk-3VFY3N4A.js";
|
|
7
9
|
|
|
8
10
|
// src/commands/_cloud-attach.ts
|
|
9
11
|
import { spawn as spawn4 } from "child_process";
|
|
@@ -12,6 +14,89 @@ import { homedir } from "os";
|
|
|
12
14
|
import { join as join2 } from "path";
|
|
13
15
|
import { spinner } from "@clack/prompts";
|
|
14
16
|
|
|
17
|
+
// src/lib/skip-permissions.ts
|
|
18
|
+
var CLAUDE_SKIP_PERMISSIONS_FLAG = "--dangerously-skip-permissions";
|
|
19
|
+
var CODEX_SKIP_PERMISSIONS_FLAG = "--dangerously-bypass-approvals-and-sandbox";
|
|
20
|
+
var CLAUDE_CONFLICTING = /* @__PURE__ */ new Set([CLAUDE_SKIP_PERMISSIONS_FLAG, "--permission-mode"]);
|
|
21
|
+
var CODEX_CONFLICTING = /* @__PURE__ */ new Set([
|
|
22
|
+
CODEX_SKIP_PERMISSIONS_FLAG,
|
|
23
|
+
"--yolo",
|
|
24
|
+
"--full-auto",
|
|
25
|
+
"-a",
|
|
26
|
+
"--ask-for-approval",
|
|
27
|
+
"-s",
|
|
28
|
+
"--sandbox"
|
|
29
|
+
]);
|
|
30
|
+
function inject(args, flag, conflicting) {
|
|
31
|
+
const hasConflict = args.some((a) => {
|
|
32
|
+
const eq = a.indexOf("=");
|
|
33
|
+
return conflicting.has(eq === -1 ? a : a.slice(0, eq));
|
|
34
|
+
});
|
|
35
|
+
if (hasConflict) return args;
|
|
36
|
+
return [flag, ...args];
|
|
37
|
+
}
|
|
38
|
+
function applyClaudeSkipPermissions(args, cfg) {
|
|
39
|
+
if (!cfg.claude.dangerouslySkipPermissions) return args;
|
|
40
|
+
return inject(args, CLAUDE_SKIP_PERMISSIONS_FLAG, CLAUDE_CONFLICTING);
|
|
41
|
+
}
|
|
42
|
+
function applyCodexSkipPermissions(args, cfg) {
|
|
43
|
+
if (!cfg.codex.dangerouslySkipPermissions) return args;
|
|
44
|
+
return inject(args, CODEX_SKIP_PERMISSIONS_FLAG, CODEX_CONFLICTING);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/agent-sessions.ts
|
|
48
|
+
var POINTER_DIR = '"$HOME/.local/state/agentbox"';
|
|
49
|
+
var CLAUDE_POINTER = `${POINTER_DIR}/claude-session`;
|
|
50
|
+
var CODEX_MARKER = `${POINTER_DIR}/codex-active`;
|
|
51
|
+
async function execRead(provider, box, script) {
|
|
52
|
+
try {
|
|
53
|
+
const r = await provider.exec(box, ["bash", "-lc", script], { user: "vscode" });
|
|
54
|
+
return r.exitCode === 0 ? r.stdout.trim() : "";
|
|
55
|
+
} catch {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function tmuxAlive(provider, box, sessionName) {
|
|
60
|
+
const q = `'${sessionName.replace(/'/g, `'\\''`)}'`;
|
|
61
|
+
return await execRead(provider, box, `tmux has-session -t ${q} 2>/dev/null && echo y`) === "y";
|
|
62
|
+
}
|
|
63
|
+
async function agentResumeArgs(provider, box, kind) {
|
|
64
|
+
if (kind === "claude") {
|
|
65
|
+
const id = await execRead(provider, box, `cat ${CLAUDE_POINTER} 2>/dev/null`);
|
|
66
|
+
return /^[0-9a-fA-F][0-9a-fA-F-]{7,}$/.test(id) ? ["--resume", id] : null;
|
|
67
|
+
}
|
|
68
|
+
const ran = await execRead(provider, box, `test -f ${CODEX_MARKER} && echo y`);
|
|
69
|
+
return ran === "y" ? ["resume", "--last"] : null;
|
|
70
|
+
}
|
|
71
|
+
async function restoreAgentSessions(box, provider, opts = {}) {
|
|
72
|
+
const cfg = await loadEffectiveConfig(box.workspacePath).catch(() => null);
|
|
73
|
+
const isDocker = (box.provider ?? "docker") === "docker";
|
|
74
|
+
const kinds = [
|
|
75
|
+
{ kind: "claude", sessionName: cfg?.effective.claude.sessionName ?? "claude" },
|
|
76
|
+
{ kind: "codex", sessionName: cfg?.effective.codex.sessionName ?? "codex" }
|
|
77
|
+
];
|
|
78
|
+
for (const { kind, sessionName } of kinds) {
|
|
79
|
+
if (await tmuxAlive(provider, box, sessionName)) continue;
|
|
80
|
+
const resume = await agentResumeArgs(provider, box, kind);
|
|
81
|
+
if (!resume) continue;
|
|
82
|
+
const args = kind === "claude" ? cfg ? applyClaudeSkipPermissions(resume, cfg.effective) : resume : cfg ? applyCodexSkipPermissions(resume, cfg.effective) : resume;
|
|
83
|
+
try {
|
|
84
|
+
if (isDocker) {
|
|
85
|
+
if (kind === "claude") {
|
|
86
|
+
await startClaudeSession({ container: box.container, claudeArgs: args, sessionName });
|
|
87
|
+
} else {
|
|
88
|
+
await startCodexSession({ container: box.container, codexArgs: args, sessionName });
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
await cloudAgentStartDetached({ box, binary: kind, sessionName, extraArgs: args });
|
|
92
|
+
}
|
|
93
|
+
opts.onLog?.(`resumed ${kind} session`);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
opts.onLog?.(`could not resume ${kind} session: ${err.message}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
15
100
|
// src/provider/registry.ts
|
|
16
101
|
var KNOWN = ["docker", "daytona", "hetzner", "vercel", "e2b"];
|
|
17
102
|
function isKnownProvider(name) {
|
|
@@ -20,26 +105,26 @@ function isKnownProvider(name) {
|
|
|
20
105
|
async function getProvider(name) {
|
|
21
106
|
switch (name) {
|
|
22
107
|
case "docker": {
|
|
23
|
-
const mod = await import("./dist-
|
|
108
|
+
const mod = await import("./dist-3PLT2EK2.js");
|
|
24
109
|
return mod.dockerProvider;
|
|
25
110
|
}
|
|
26
111
|
case "daytona": {
|
|
27
|
-
const mod = await import("./dist-
|
|
112
|
+
const mod = await import("./dist-CZ6CRADC.js");
|
|
28
113
|
await mod.ensureDaytonaCredentials();
|
|
29
114
|
return mod.daytonaProvider;
|
|
30
115
|
}
|
|
31
116
|
case "hetzner": {
|
|
32
|
-
const mod = await import("./dist-
|
|
117
|
+
const mod = await import("./dist-C3YRC3PP.js");
|
|
33
118
|
await mod.ensureHetznerCredentials();
|
|
34
119
|
return mod.hetznerProvider;
|
|
35
120
|
}
|
|
36
121
|
case "vercel": {
|
|
37
|
-
const mod = await import("./dist-
|
|
122
|
+
const mod = await import("./dist-3WFNXXPE.js");
|
|
38
123
|
await mod.ensureVercelCredentials();
|
|
39
124
|
return mod.vercelProvider;
|
|
40
125
|
}
|
|
41
126
|
case "e2b": {
|
|
42
|
-
const mod = await import("./dist-
|
|
127
|
+
const mod = await import("./dist-7ELDXBAG.js");
|
|
43
128
|
await mod.ensureE2bCredentials();
|
|
44
129
|
return mod.e2bProvider;
|
|
45
130
|
}
|
|
@@ -136,11 +221,13 @@ function herdrSend(method, params, env = process.env) {
|
|
|
136
221
|
function herdrRequest(method, params, env = process.env, timeoutMs = 2e3) {
|
|
137
222
|
const sock = herdrSocketPath(env);
|
|
138
223
|
if (!sock) return Promise.resolve(null);
|
|
224
|
+
const id = nextId();
|
|
139
225
|
return new Promise((resolve) => {
|
|
140
226
|
let settled = false;
|
|
141
227
|
const done = (value) => {
|
|
142
228
|
if (settled) return;
|
|
143
229
|
settled = true;
|
|
230
|
+
clearTimeout(timer);
|
|
144
231
|
try {
|
|
145
232
|
client.destroy();
|
|
146
233
|
} catch {
|
|
@@ -161,7 +248,7 @@ function herdrRequest(method, params, env = process.env, timeoutMs = 2e3) {
|
|
|
161
248
|
client.on("close", () => done(null));
|
|
162
249
|
client.on("connect", () => {
|
|
163
250
|
try {
|
|
164
|
-
client.write(`${JSON.stringify({ id
|
|
251
|
+
client.write(`${JSON.stringify({ id, method, params })}
|
|
165
252
|
`);
|
|
166
253
|
} catch {
|
|
167
254
|
done(null);
|
|
@@ -169,19 +256,25 @@ function herdrRequest(method, params, env = process.env, timeoutMs = 2e3) {
|
|
|
169
256
|
});
|
|
170
257
|
client.on("data", (chunk) => {
|
|
171
258
|
buf += chunk.toString("utf8");
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
259
|
+
let nl;
|
|
260
|
+
while ((nl = buf.indexOf("\n")) !== -1) {
|
|
261
|
+
const line = buf.slice(0, nl);
|
|
262
|
+
buf = buf.slice(nl + 1);
|
|
263
|
+
if (line.trim().length === 0) continue;
|
|
264
|
+
let msg;
|
|
265
|
+
try {
|
|
266
|
+
msg = JSON.parse(line);
|
|
267
|
+
} catch {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (!("result" in msg) && !("error" in msg)) continue;
|
|
271
|
+
if (msg.id !== void 0 && msg.id !== id) continue;
|
|
177
272
|
if (msg.error || typeof msg.result !== "object" || msg.result === null) {
|
|
178
273
|
done(null);
|
|
179
274
|
} else {
|
|
180
|
-
clearTimeout(timer);
|
|
181
275
|
done(msg.result);
|
|
182
276
|
}
|
|
183
|
-
|
|
184
|
-
done(null);
|
|
277
|
+
return;
|
|
185
278
|
}
|
|
186
279
|
});
|
|
187
280
|
});
|
|
@@ -336,30 +429,36 @@ function herdrField(result, parent, key) {
|
|
|
336
429
|
function extractHerdrPaneId(result) {
|
|
337
430
|
if (!result) return void 0;
|
|
338
431
|
const direct = result["pane_id"];
|
|
339
|
-
if (typeof direct === "string" && /:p
|
|
432
|
+
if (typeof direct === "string" && /:p[0-9A-Za-z]+$/.test(direct)) return direct;
|
|
340
433
|
for (const parent of ["pane", "root_pane"]) {
|
|
341
434
|
const id = herdrField(result, parent, "pane_id");
|
|
342
|
-
if (id && /:p
|
|
435
|
+
if (id && /:p[0-9A-Za-z]+$/.test(id)) return id;
|
|
343
436
|
}
|
|
344
|
-
const m = JSON.stringify(result).match(/"([^"]*:p
|
|
437
|
+
const m = JSON.stringify(result).match(/"([^"]*:p[0-9A-Za-z]+)"/);
|
|
345
438
|
return m ? m[1] : void 0;
|
|
346
439
|
}
|
|
347
440
|
async function spawnInHerdr(args) {
|
|
348
441
|
const env = args.env;
|
|
442
|
+
const CREATE_TIMEOUT_MS = 6e3;
|
|
349
443
|
let result;
|
|
350
444
|
let noteKind;
|
|
351
445
|
if (args.mode === "split") {
|
|
352
446
|
const params = { direction: "right", ratio: 0.5 };
|
|
353
447
|
if (args.herdrTargetPane) params["pane_id"] = args.herdrTargetPane;
|
|
354
|
-
result = await herdrRequest("pane.split", params, env);
|
|
448
|
+
result = await herdrRequest("pane.split", params, env, CREATE_TIMEOUT_MS);
|
|
355
449
|
noteKind = "Herdr split";
|
|
356
450
|
} else if (args.mode === "tab") {
|
|
357
451
|
const params = {};
|
|
358
452
|
if (args.herdrTargetWorkspace) params["workspace_id"] = args.herdrTargetWorkspace;
|
|
359
|
-
result = await herdrRequest("tab.create", params, env);
|
|
453
|
+
result = await herdrRequest("tab.create", params, env, CREATE_TIMEOUT_MS);
|
|
360
454
|
noteKind = "Herdr tab";
|
|
361
455
|
} else {
|
|
362
|
-
result = await herdrRequest(
|
|
456
|
+
result = await herdrRequest(
|
|
457
|
+
"workspace.create",
|
|
458
|
+
{ cwd: args.cwd, label: args.title },
|
|
459
|
+
env,
|
|
460
|
+
CREATE_TIMEOUT_MS
|
|
461
|
+
);
|
|
363
462
|
noteKind = "Herdr workspace";
|
|
364
463
|
}
|
|
365
464
|
const paneId = extractHerdrPaneId(result);
|
|
@@ -2345,8 +2444,11 @@ function buildCloudAttachInnerCommand(binary, extraArgs) {
|
|
|
2345
2444
|
if (!extraArgs || extraArgs.length === 0) {
|
|
2346
2445
|
return `bash -lc '${agentStartBanner(binary)}exec ${binary}'`;
|
|
2347
2446
|
}
|
|
2348
|
-
const blob = Buffer.from(
|
|
2349
|
-
|
|
2447
|
+
const blob = Buffer.from(
|
|
2448
|
+
extraArgs.map((a) => Buffer.from(a, "utf8").toString("base64")).join("\n"),
|
|
2449
|
+
"utf8"
|
|
2450
|
+
).toString("base64");
|
|
2451
|
+
return `bash -lc '${agentStartBanner(binary)}A=(); while IFS= read -r t; do A+=("$(printf %s "$t" | base64 -d)"); done <<< "$(echo ${blob} | base64 -d)"; exec ${binary} "\${A[@]}"'`;
|
|
2350
2452
|
}
|
|
2351
2453
|
async function cloudAgentAttach(args) {
|
|
2352
2454
|
const provider = await providerForBox(args.box);
|
|
@@ -2365,9 +2467,14 @@ async function cloudAgentAttach(args) {
|
|
|
2365
2467
|
box = await provider.start(box);
|
|
2366
2468
|
s.stop("box running");
|
|
2367
2469
|
}
|
|
2368
|
-
|
|
2470
|
+
let extraArgs = args.extraArgs;
|
|
2471
|
+
if ((!extraArgs || extraArgs.length === 0) && (args.mode === "claude" || args.mode === "codex")) {
|
|
2472
|
+
const resume = await agentResumeArgs(provider, box, args.mode);
|
|
2473
|
+
if (resume) extraArgs = resume;
|
|
2474
|
+
}
|
|
2475
|
+
const command = buildCloudAttachInnerCommand(args.binary, extraArgs);
|
|
2369
2476
|
const safeOpenIn = box.provider === "daytona" ? "same" : args.openIn;
|
|
2370
|
-
if (safeOpenIn && safeOpenIn !== "same" &&
|
|
2477
|
+
if (safeOpenIn && safeOpenIn !== "same" && extraArgs && extraArgs.length > 0) {
|
|
2371
2478
|
await startDetachedSession(provider, box, args.sessionName, command);
|
|
2372
2479
|
}
|
|
2373
2480
|
let spec = await provider.buildAttach(box, "agent", {
|
|
@@ -2441,11 +2548,43 @@ async function startDetachedSession(provider, box, sessionName, command) {
|
|
|
2441
2548
|
detached: true
|
|
2442
2549
|
});
|
|
2443
2550
|
try {
|
|
2444
|
-
await runDetached(spec.argv, spec.env);
|
|
2551
|
+
return await runDetached(spec.argv, spec.env);
|
|
2445
2552
|
} finally {
|
|
2446
2553
|
if (spec.cleanup) await spec.cleanup();
|
|
2447
2554
|
}
|
|
2448
2555
|
}
|
|
2556
|
+
var AGENT_AUTH_FAILURE = /Please run \/login|Invalid authentication credentials|API Error: 401|Invalid API key|\bUnauthorized\b/i;
|
|
2557
|
+
function sleep(ms) {
|
|
2558
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2559
|
+
}
|
|
2560
|
+
async function verifyDetachedSession(provider, box, sessionName, binary, opts = {}) {
|
|
2561
|
+
const windowMs = opts.windowMs ?? 1e4;
|
|
2562
|
+
const pollMs = opts.pollMs ?? 2e3;
|
|
2563
|
+
const q = `'${sessionName.replace(/'/g, `'\\''`)}'`;
|
|
2564
|
+
const probe = `tmux has-session -t ${q} 2>/dev/null || exit 7; tmux capture-pane -p -t ${q} 2>/dev/null`;
|
|
2565
|
+
const deadline = Date.now() + windowMs;
|
|
2566
|
+
for (; ; ) {
|
|
2567
|
+
let pane = "";
|
|
2568
|
+
try {
|
|
2569
|
+
const r = await provider.exec(box, ["bash", "-lc", probe], { user: "vscode" });
|
|
2570
|
+
if (r.exitCode === 7) {
|
|
2571
|
+
throw new Error(
|
|
2572
|
+
`agent '${binary}' exited immediately after launch in box ${box.name} \u2014 the session did not stay up. Attach to inspect: agentbox ${binary} attach ${box.name}`
|
|
2573
|
+
);
|
|
2574
|
+
}
|
|
2575
|
+
pane = r.stdout;
|
|
2576
|
+
} catch (err) {
|
|
2577
|
+
if (err instanceof Error && err.message.startsWith(`agent '${binary}'`)) throw err;
|
|
2578
|
+
}
|
|
2579
|
+
if (AGENT_AUTH_FAILURE.test(pane)) {
|
|
2580
|
+
throw new Error(
|
|
2581
|
+
`box ${binary} credentials were rejected \u2014 the agent launched but printed an auth error, so no work will run. Refresh them with \`agentbox ${binary} login\`, then re-run.`
|
|
2582
|
+
);
|
|
2583
|
+
}
|
|
2584
|
+
if (Date.now() >= deadline) break;
|
|
2585
|
+
await sleep(pollMs);
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2449
2588
|
async function cloudAgentStartDetached(args) {
|
|
2450
2589
|
const provider = await providerForBox(args.box);
|
|
2451
2590
|
let box = args.box;
|
|
@@ -2457,16 +2596,32 @@ async function cloudAgentStartDetached(args) {
|
|
|
2457
2596
|
box = await provider.start(box);
|
|
2458
2597
|
}
|
|
2459
2598
|
const command = buildCloudAttachInnerCommand(args.binary, args.extraArgs);
|
|
2460
|
-
|
|
2599
|
+
const { exitCode, stderr } = await startDetachedSession(
|
|
2600
|
+
provider,
|
|
2601
|
+
box,
|
|
2602
|
+
args.sessionName,
|
|
2603
|
+
command
|
|
2604
|
+
);
|
|
2605
|
+
if (exitCode !== 0) {
|
|
2606
|
+
const detail = stderr.trim().slice(0, 500);
|
|
2607
|
+
throw new Error(
|
|
2608
|
+
`failed to start the ${args.binary} session in box ${box.name} (exit ${String(exitCode)})` + (detail ? `: ${detail}` : "")
|
|
2609
|
+
);
|
|
2610
|
+
}
|
|
2611
|
+
await verifyDetachedSession(provider, box, args.sessionName, args.binary);
|
|
2461
2612
|
}
|
|
2462
2613
|
function runDetached(argv, env) {
|
|
2463
2614
|
return new Promise((resolve) => {
|
|
2464
2615
|
const child = spawn4(argv[0], argv.slice(1), {
|
|
2465
|
-
stdio: "ignore",
|
|
2616
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
2466
2617
|
env: env ? { ...process.env, ...env } : process.env
|
|
2467
2618
|
});
|
|
2468
|
-
|
|
2469
|
-
child.on("
|
|
2619
|
+
let stderr = "";
|
|
2620
|
+
child.stderr?.on("data", (c) => {
|
|
2621
|
+
stderr += c.toString("utf8");
|
|
2622
|
+
});
|
|
2623
|
+
child.on("error", (err) => resolve({ exitCode: 1, stderr: stderr + String(err.message ?? err) }));
|
|
2624
|
+
child.on("exit", (code) => resolve({ exitCode: code ?? 0, stderr }));
|
|
2470
2625
|
});
|
|
2471
2626
|
}
|
|
2472
2627
|
|
|
@@ -2475,12 +2630,12 @@ export {
|
|
|
2475
2630
|
getProvider,
|
|
2476
2631
|
providerForBox,
|
|
2477
2632
|
providerForCreate,
|
|
2633
|
+
loadPtyBackend,
|
|
2478
2634
|
herdrSend,
|
|
2479
2635
|
hostAwareOpenIn,
|
|
2480
2636
|
detectHostTerminal,
|
|
2481
2637
|
cmuxBinary,
|
|
2482
2638
|
spawnInNewTerminal,
|
|
2483
|
-
loadPtyBackend,
|
|
2484
2639
|
setTerminalTitle,
|
|
2485
2640
|
pushTerminalTitle,
|
|
2486
2641
|
popTerminalTitle,
|
|
@@ -2504,6 +2659,11 @@ export {
|
|
|
2504
2659
|
pasteHostClipboardImage,
|
|
2505
2660
|
buildCloudAttachInnerCommand,
|
|
2506
2661
|
cloudAgentAttach,
|
|
2507
|
-
|
|
2662
|
+
verifyDetachedSession,
|
|
2663
|
+
cloudAgentStartDetached,
|
|
2664
|
+
applyClaudeSkipPermissions,
|
|
2665
|
+
applyCodexSkipPermissions,
|
|
2666
|
+
agentResumeArgs,
|
|
2667
|
+
restoreAgentSessions
|
|
2508
2668
|
};
|
|
2509
|
-
//# sourceMappingURL=chunk-
|
|
2669
|
+
//# sourceMappingURL=chunk-7RWFYLF3.js.map
|