@munitoai/cli 0.0.0-stage → 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli.ts","../src/core/workspace.ts","../src/cli/main.ts","../src/cli/commands/agent.ts","../src/cli/theme.ts","../src/cli/output.ts","../src/cli/context.ts","../src/cli/desktop.ts","../src/cli/commands/ci.ts","../src/cli/commands/auth.ts","../src/cli/commands/herdr.ts","../src/cli/commands/init.ts","../src/cli/commands/mcp.ts","../src/cli/commands/sandboxes.ts","../src/core/ssh.ts"],"sourcesContent":["#!/usr/bin/env node\n/** The `munito` binary. One place turns a failure into a line a person can act on. */\n\nimport { runMain } from \"citty\";\n\nimport { ApiError } from \"./api/client.ts\";\nimport { MissingKeyError } from \"./core/keys.ts\";\nimport { WiringError } from \"./core/providers.ts\";\nimport { WorkspaceError } from \"./core/workspace.ts\";\nimport { main } from \"./cli/main.ts\";\nimport { out } from \"./cli/output.ts\";\n\nconst CONSOLE_BILLING = \"https://console.munito.ai/billing\";\n\nfunction report(error: unknown): number {\n const channel = out(false);\n if (error instanceof MissingKeyError) {\n channel.error(error.message);\n return 2;\n }\n if (error instanceof WiringError || error instanceof WorkspaceError) {\n channel.error(error.message);\n return 2;\n }\n if (error instanceof ApiError) {\n channel.error(error.message);\n if (error.status === 401) channel.line(channel.p.dim(\" The key is not valid here. Run `munito login`.\"));\n if (error.status === 402) channel.line(channel.p.dim(` Check your plan and credits at ${CONSOLE_BILLING}`));\n if (error.status === 429) channel.line(channel.p.dim(\" Too many at once. Wait, or ask for a larger plan.\"));\n if (error.requestId) channel.line(channel.p.dim(` request ${error.requestId}`));\n return error.status === 401 || error.status === 402 ? 2 : 1;\n }\n channel.error(error instanceof Error ? error.message : String(error));\n return 1;\n}\n\nprocess.on(\"unhandledRejection\", (reason) => {\n process.exit(report(reason));\n});\n\nawait runMain(main).catch((error: unknown) => {\n process.exit(report(error));\n});\n","/** The local worktree that an agent should see, and the patch it sends back.\n\nOnly files that git already tracks or would track, so an ignored secret, a build directory and a venv never leave the\nmachine. Core code: no terminal output.\n*/\n\nimport { execFile } from \"node:child_process\";\nimport { mkdtemp, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join, resolve } from \"node:path\";\nimport { promisify } from \"node:util\";\n\nimport type { UploadFile } from \"./agents.ts\";\n\nconst run = promisify(execFile);\n\n/** Caps, so a stray directory cannot turn one command into a long upload. */\nexport const MAX_FILES = 2_000;\nexport const MAX_FILE_BYTES = 1 << 20;\nexport const MAX_TOTAL_BYTES = 16 << 20;\n\nexport class WorkspaceError extends Error {}\n\n/** The files of the git worktree at `dir`, or none when it is not a repository. */\nexport async function collect(dir?: string): Promise<UploadFile[]> {\n const root = resolve(dir ?? process.cwd());\n const listed = await listTracked(root);\n if (!listed) return [];\n\n const files: UploadFile[] = [];\n let total = 0;\n for (const relative of listed) {\n if (files.length >= MAX_FILES) break;\n const absolute = join(root, relative);\n let info;\n try {\n info = await stat(absolute);\n } catch {\n continue;\n }\n if (!info.isFile() || info.size > MAX_FILE_BYTES) continue;\n if (total + info.size > MAX_TOTAL_BYTES) break;\n const buffer = await readFile(absolute);\n if (isBinary(buffer)) continue;\n total += info.size;\n files.push({ path: relative, content: buffer.toString(\"utf8\") });\n }\n return files;\n}\n\nasync function listTracked(root: string): Promise<string[] | null> {\n try {\n // Tracked plus untracked, with .gitignore applied, so nothing ignored is ever uploaded.\n const { stdout } = await run(\"git\", [\"-C\", root, \"ls-files\", \"-co\", \"--exclude-standard\", \"-z\"], {\n maxBuffer: 32 << 20,\n });\n return stdout.split(\"\\0\").filter(Boolean);\n } catch {\n return null;\n }\n}\n\n/** A NUL byte in the first block is the same test git uses. */\nfunction isBinary(buffer: Buffer): boolean {\n return buffer.subarray(0, 8000).includes(0);\n}\n\nexport function describeUpload(files: UploadFile[]): string {\n const bytes = files.reduce((sum, file) => sum + Buffer.byteLength(file.content), 0);\n const size = bytes > 1 << 20 ? `${(bytes / (1 << 20)).toFixed(1)} MiB` : `${Math.ceil(bytes / 1024)} KiB`;\n return `${files.length} files, ${size}`;\n}\n\n/** Apply a unified diff to the worktree. Returns the files that changed, and changes nothing when it cannot. */\nexport async function applyPatch(patch: string, dir?: string): Promise<string[]> {\n const root = resolve(dir ?? process.cwd());\n if (!patch.trim()) return [];\n const file = join(await mkdtemp(join(tmpdir(), \"munito-\")), \"patch.diff\");\n await writeFile(file, patch);\n try {\n // --check first, so a patch that cannot apply leaves the worktree untouched.\n await run(\"git\", [\"-C\", root, \"apply\", \"--check\", file]);\n const { stdout } = await run(\"git\", [\"-C\", root, \"apply\", \"--numstat\", file]);\n await run(\"git\", [\"-C\", root, \"apply\", file]);\n return stdout\n .split(\"\\n\")\n .map((line) => line.split(\"\\t\").at(2))\n .filter((name): name is string => Boolean(name));\n } catch (error) {\n throw new WorkspaceError(`The patch did not apply: ${(error as Error).message}`);\n } finally {\n await rm(file, { force: true });\n }\n}\n","/** The command tree. Every command is a thin layer over core/, which does the work. */\n\nimport { defineCommand } from \"citty\";\n\nimport { agent } from \"./commands/agent.ts\";\nimport { ci } from \"./commands/ci.ts\";\nimport { login, logout, whoami } from \"./commands/auth.ts\";\nimport { herdr } from \"./commands/herdr.ts\";\nimport { init } from \"./commands/init.ts\";\nimport { mcp } from \"./commands/mcp.ts\";\nimport { create, exec, fork, ls, open, pause, resume, rm, run, ssh } from \"./commands/sandboxes.ts\";\n\n// The build replaces this with the version in package.json.\ndeclare const __MUNITO_VERSION__: string;\nconst VERSION = typeof __MUNITO_VERSION__ === \"string\" ? __MUNITO_VERSION__ : \"0.0.0-dev\";\n\nexport const main = defineCommand({\n meta: {\n name: \"munito\",\n // Without this, `munito --version` exits with \"No version specified\".\n version: VERSION,\n description: \"Run coding agents on European infrastructure, one command at a time.\",\n },\n subCommands: {\n agent,\n ci,\n herdr,\n init,\n mcp,\n login,\n logout,\n whoami,\n ls,\n create,\n run,\n exec,\n ssh,\n open,\n rm,\n pause,\n resume,\n fork,\n },\n});\n","/** `munito agent` — the one command. */\n\nimport { defineCommand } from \"citty\";\n\nimport { runAgent, type AgentEvent } from \"../../core/agents.ts\";\nimport { AGENTS, PROVIDERS, type AgentName, type AuthMode, type ProviderName } from \"../../core/providers.ts\";\nimport { applyPatch, collect, describeUpload } from \"../../core/workspace.ts\";\nimport { commonArgs, context } from \"../context.ts\";\nimport { duration } from \"../output.ts\";\nimport { openDesktop } from \"../desktop.ts\";\n\nexport const agent = defineCommand({\n meta: {\n name: \"agent\",\n description: \"Run a coding agent in a sandbox and bring its work back.\",\n },\n args: {\n ...commonArgs,\n agent: {\n type: \"positional\",\n required: false,\n description: `Which harness: ${AGENTS.join(\", \")}. The default is claude.`,\n },\n prompt: { type: \"positional\", required: false, description: \"What the agent should do.\" },\n provider: {\n type: \"string\",\n description: `Where the model comes from: ${PROVIDERS.join(\", \")}.`,\n default: \"munito\",\n },\n auth: { type: \"string\", description: \"token or subscription.\", default: \"token\" },\n model: { type: \"string\", description: \"A model id, in place of the recommended one.\" },\n repo: { type: \"string\", description: \"A directory to upload. The default is the current git worktree.\" },\n \"no-upload\": { type: \"boolean\", description: \"Send no files at all.\" },\n size: { type: \"string\", description: \"tiny, small, default or large.\", default: \"default\" },\n template: { type: \"string\", description: \"A sandbox template, in place of the agent one.\" },\n timeout: { type: \"string\", description: \"Seconds the sandbox may live. The default is 3600.\" },\n \"max-turns\": { type: \"string\", description: \"Stop the agent after this many turns.\" },\n keep: { type: \"boolean\", description: \"Leave the sandbox running when the task ends.\" },\n desktop: { type: \"boolean\", description: \"Give the agent a screen, and open the viewer. Implies --keep.\" },\n \"no-apply\": { type: \"boolean\", description: \"Do not apply the agent's patch to your worktree.\" },\n },\n async run({ args }) {\n // One positional means the prompt, and claude runs it.\n let name = (args.agent ?? \"claude\") as AgentName;\n let prompt = args.prompt as string | undefined;\n if (!AGENTS.includes(name)) {\n prompt = [args.agent, prompt].filter(Boolean).join(\" \");\n name = \"claude\";\n }\n if (!prompt) throw new Error('Give the agent something to do: munito agent \"fix the failing test\"');\n\n const ctx = await context(args);\n const { out, client } = ctx;\n\n // The parser reads `--no-x` as `x: false`, so a flag named `no-x` never arrives under its own name.\n const off = (name: string) => args[`no-${name}`] === true || args[name] === false;\n const upload = off(\"upload\") ? [] : await collect(args.repo);\n const started = Date.now();\n // A screen is only useful while the machine lives, so a desktop run keeps it.\n const desktop = Boolean(args.desktop);\n const keep = Boolean(args.keep) || desktop;\n\n out.line();\n out.line(`${out.p.badge(\"munito\")} ${out.p.bold(name)} ${out.p.dim(`on ${args.provider}`)}`);\n out.line(out.p.dim(` ${prompt}`));\n out.line();\n if (upload.length) out.step(\"workspace\", describeUpload(upload));\n\n let streamed = false;\n const onEvent = (event: AgentEvent) => {\n out.event({ ...event });\n switch (event.type) {\n case \"sandbox.creating\":\n out.step(\"sandbox\", \"starting\");\n break;\n case \"sandbox.created\":\n out.step(\"sandbox\", `${event.sandboxId} in ${duration(event.ms)}`);\n if (desktop) void openDesktop(client, event.sandboxId, out);\n break;\n case \"files.uploaded\":\n out.step(\"uploaded\", `${event.count} files`);\n break;\n case \"harness.installing\":\n out.step(\"installing\", `${event.package}, once`);\n break;\n case \"harness.installed\":\n out.step(\"installed\", duration(event.ms));\n break;\n case \"agent.started\":\n out.step(\"running\", name);\n out.line();\n break;\n case \"output\":\n // Claude Code answers with one JSON envelope, so holding it back keeps the screen clean.\n if (name !== \"claude\") {\n streamed = true;\n out.raw(event.data, event.stream);\n }\n break;\n case \"agent.finished\":\n if (streamed) out.line();\n out.step(\"finished\", `exit ${event.exitCode} in ${duration(event.ms)}`);\n break;\n case \"sandbox.kept\":\n out.step(\"kept\", `${event.sandboxId} — munito ssh ${event.sandboxId}`);\n break;\n default:\n break;\n }\n };\n\n const run = await runAgent(client, {\n agent: name,\n prompt,\n provider: args.provider as ProviderName,\n auth: args.auth as AuthMode,\n model: args.model,\n size: args.size,\n template: args.template ?? (desktop ? \"desktop\" : undefined),\n timeout: args.timeout ? Number(args.timeout) : undefined,\n maxTurns: args[\"max-turns\"] ? Number(args[\"max-turns\"]) : undefined,\n keep,\n files: upload,\n onEvent,\n });\n\n if (!streamed && run.result && out.mode !== \"json\") {\n out.line();\n out.line(run.result);\n }\n\n let changed: string[] = [];\n if (run.patch && !off(\"apply\")) {\n try {\n changed = await applyPatch(run.patch, args.repo);\n out.line();\n out.step(\"applied\", `${changed.length} files`);\n for (const file of changed) out.line(out.p.dim(` ${file}`));\n } catch (error) {\n out.warn((error as Error).message);\n out.line(out.p.dim(\" The diff is in the JSON output: rerun with --json.\"));\n }\n } else if (run.patch) {\n out.step(\"patch\", `${Buffer.byteLength(run.patch)} bytes, not applied`);\n }\n\n out.line();\n out.step(\"done\", duration(Date.now() - started));\n out.result(run.result, {\n sandbox_id: run.sandboxId,\n exit_code: run.exitCode,\n session_id: run.sessionId,\n duration_ms: run.durationMs,\n files_changed: changed,\n patch: run.patch || undefined,\n });\n if (run.exitCode !== 0) process.exitCode = run.exitCode;\n },\n});\n","/** The Munito palette in a terminal, and the rule that decides whether to use it.\n\nThe brand violet `#702cf6` is unreadable as text on a dark terminal. The design system already answers this: in dark\nmode it swaps the text violet to the cube top. A terminal is dark mode, so the primary here is `#9a68fa`.\nSource: `typescript/packages/design-system/src/styles/tokens.css`, which copies the brand kit.\n*/\n\nexport const BRAND = {\n violet: [0x70, 0x2c, 0xf6],\n cubeTop: [0x9a, 0x68, 0xfa],\n cubeSide: [0x4a, 0x1f, 0xa8],\n lime: [0xd7, 0xfa, 0x4a],\n lilac: [0xa0, 0x81, 0xde],\n paper: [0xf0, 0xee, 0xf3],\n ink: [0x21, 0x16, 0x29],\n night: [0x14, 0x10, 0x19],\n} as const satisfies Record<string, readonly [number, number, number]>;\n\nexport type Depth = 0 | 4 | 8 | 24;\n\n/** What the stream can draw, from the environment that the user and their tools set. */\nexport function colorDepth(stream: NodeJS.WriteStream = process.stdout): Depth {\n if (process.env.NO_COLOR !== undefined && process.env.NO_COLOR !== \"\") return 0;\n const forced = process.env.FORCE_COLOR;\n if (forced !== undefined) {\n if (forced === \"0\" || forced === \"false\") return 0;\n if (forced === \"1\" || forced === \"true\") return 4;\n if (forced === \"2\") return 8;\n if (forced === \"3\") return 24;\n }\n if (!stream.isTTY) return 0;\n if (process.env.TERM === \"dumb\") return 0;\n const colorterm = process.env.COLORTERM ?? \"\";\n if (colorterm === \"truecolor\" || colorterm === \"24bit\") return 24;\n if (/-256(color)?$/i.test(process.env.TERM ?? \"\")) return 8;\n return 4;\n}\n\nconst RESET = \"\\u001b[39m\";\nconst BOLD = \"\\u001b[1m\";\nconst UNBOLD = \"\\u001b[22m\";\nconst DIM = \"\\u001b[2m\";\nconst UNDIM = \"\\u001b[22m\";\n\n/** The nearest xterm-256 index of a colour, through the 6x6x6 cube. */\nfunction to256([r, g, b]: readonly [number, number, number]): number {\n const step = (value: number) => (value < 48 ? 0 : value < 115 ? 1 : Math.min(5, Math.round((value - 35) / 40)));\n return 16 + 36 * step(r) + 6 * step(g) + step(b);\n}\n\n/** The nearest of the 8 basic colours. Violet and lilac land on magenta, lime on bright yellow. */\nfunction to16([r, g, b]: readonly [number, number, number]): number {\n const bright = Math.max(r, g, b) > 0xa0;\n const bit = (value: number) => (value > 0x7f ? 1 : 0);\n const code = bit(r) + bit(g) * 2 + bit(b) * 4;\n return (bright ? 90 : 30) + code;\n}\n\nexport interface Palette {\n readonly depth: Depth;\n primary(text: string): string;\n accent(text: string): string;\n dim(text: string): string;\n text(text: string): string;\n bold(text: string): string;\n /** Paper on brand violet, the one place the true brand violet reads well. */\n badge(text: string): string;\n}\n\nexport function palette(stream: NodeJS.WriteStream = process.stdout): Palette {\n const depth = colorDepth(stream);\n const fg = (color: readonly [number, number, number]) => {\n if (depth === 0) return (text: string) => text;\n if (depth === 24) return (text: string) => `\\u001b[38;2;${color[0]};${color[1]};${color[2]}m${text}${RESET}`;\n if (depth === 8) return (text: string) => `\\u001b[38;5;${to256(color)}m${text}${RESET}`;\n return (text: string) => `\\u001b[${to16(color)}m${text}${RESET}`;\n };\n const plain = depth === 0;\n return {\n depth,\n primary: fg(BRAND.cubeTop),\n accent: fg(BRAND.lime),\n dim: plain ? (text) => text : (text) => `${DIM}${fg(BRAND.lilac)(text)}${UNDIM}`,\n text: fg(BRAND.paper),\n bold: plain ? (text) => text : (text) => `${BOLD}${text}${UNBOLD}`,\n badge: plain\n ? (text) => text\n : (text) =>\n depth === 24\n ? `\\u001b[48;2;${BRAND.violet.join(\";\")}m\\u001b[38;2;${BRAND.paper.join(\";\")}m ${text} \\u001b[49m${RESET}`\n : `\\u001b[45m\\u001b[97m ${text} \\u001b[49m${RESET}`,\n };\n}\n\n/** The cube of the brand mark, in half blocks. The wordmark is the logo and does not belong in ASCII. */\nexport function cube(p: Palette): string {\n const top = p.primary(\"▄▄▄▄▄▄\");\n const body = p.primary(\"██████\");\n return [` ${top}`, ` ${body}`, ` ${p.dim(\"▀▀▀▀▀▀\")}`].join(\"\\n\");\n}\n","/** What reaches the terminal. Rich when it is a terminal, plain lines when it is not, NDJSON with --json.\n\nOur own agents call this CLI through a pipe, so every command has to be readable without a TTY.\n*/\n\nimport { palette, type Palette } from \"./theme.ts\";\n\nexport type Mode = \"rich\" | \"plain\" | \"json\";\n\nexport interface Out {\n readonly mode: Mode;\n readonly p: Palette;\n /** One line for a person. Silent in json mode. */\n line(text?: string): void;\n /** A labelled step, such as a created sandbox. */\n step(label: string, detail?: string): void;\n /** One machine-readable event. Printed only in json mode. */\n event(body: Record<string, unknown>): void;\n /** The machine-readable end of a command. Prints in json mode only: a person's copy is the caller's job. */\n result(text: string, body?: Record<string, unknown>): void;\n warn(text: string): void;\n error(text: string): void;\n /** Raw bytes of a child process, passed through with no decoration. */\n raw(text: string, stream?: \"stdout\" | \"stderr\"): void;\n}\n\nexport function out(json: boolean, stream: NodeJS.WriteStream = process.stdout): Out {\n const p = palette(stream);\n const mode: Mode = json ? \"json\" : p.depth === 0 ? \"plain\" : \"rich\";\n const write = (text: string) => stream.write(`${text}\\n`);\n return {\n mode,\n p,\n line(text = \"\") {\n if (mode !== \"json\") write(text);\n },\n step(label, detail) {\n if (mode === \"json\") return;\n const mark = mode === \"rich\" ? p.primary(\"›\") : \">\";\n write(detail ? `${mark} ${label} ${p.dim(detail)}` : `${mark} ${label}`);\n },\n event(body) {\n if (mode === \"json\") write(JSON.stringify(body));\n },\n result(text, body) {\n if (mode === \"json\") write(JSON.stringify({ type: \"result\", ...body, result: text }));\n },\n warn(text) {\n if (mode === \"json\") {\n process.stderr.write(`${JSON.stringify({ type: \"warning\", message: text })}\\n`);\n return;\n }\n process.stderr.write(`${mode === \"rich\" ? p.accent(\"!\") : \"!\"} ${text}\\n`);\n },\n error(text) {\n if (mode === \"json\") {\n process.stderr.write(`${JSON.stringify({ type: \"error\", message: text })}\\n`);\n return;\n }\n process.stderr.write(`${mode === \"rich\" ? \"\\u001b[31m✗\\u001b[39m\" : \"x\"} ${text}\\n`);\n },\n raw(text, target = \"stdout\") {\n if (mode === \"json\") return;\n (target === \"stderr\" ? process.stderr : stream).write(text);\n },\n };\n}\n\n/** Seconds with one decimal, or milliseconds below a second. */\nexport function duration(ms: number): string {\n if (ms < 1000) return `${Math.round(ms)} ms`;\n if (ms < 60_000) return `${(ms / 1000).toFixed(1)} s`;\n const minutes = Math.floor(ms / 60_000);\n return `${minutes} min ${Math.round((ms % 60_000) / 1000)} s`;\n}\n\n/** A left-aligned table that stays readable with no colour. */\nexport function table(rows: string[][], p: Palette, heading = true): string {\n if (!rows.length) return \"\";\n const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => (row[column] ?? \"\").length)));\n return rows\n .map((row, index) => {\n const line = row\n .map((cell, column) => (cell ?? \"\").padEnd(widths[column]))\n .join(\" \")\n .trimEnd();\n return heading && index === 0 ? p.dim(line) : line;\n })\n .join(\"\\n\");\n}\n","/** What every command needs: the key, a client and an output channel. */\n\nimport { Client } from \"../api/client.ts\";\nimport * as keys from \"../core/keys.ts\";\nimport { out, type Out } from \"./output.ts\";\n\nexport interface CommonArgs {\n json?: boolean;\n region?: string;\n host?: string;\n}\n\nexport interface Context {\n client: Client;\n out: Out;\n host: string;\n source: string;\n}\n\n/** The shared flags, so every command declares them the same way. */\nexport const commonArgs = {\n json: { type: \"boolean\" as const, description: \"Print NDJSON events instead of text.\" },\n region: { type: \"string\" as const, description: \"global, eu or us. The default is global.\" },\n host: { type: \"string\" as const, description: \"A full API URL, in place of a region.\" },\n};\n\nexport async function context(args: CommonArgs): Promise<Context> {\n const channel = out(Boolean(args.json));\n const credentials = await keys.require(args.host ?? args.region);\n return {\n client: new Client({ apiKey: credentials.apiKey, baseUrl: credentials.host }),\n out: channel,\n host: credentials.host,\n source: credentials.source,\n };\n}\n\n/** An output channel before the key is known, for `login` and for failures. */\nexport function channel(args: CommonArgs): Out {\n return out(Boolean(args.json));\n}\n","/** Signing a port and handing it to a browser, shared by `munito open` and `munito agent --desktop`. */\n\nimport { spawn } from \"node:child_process\";\n\nimport type { Client } from \"../api/client.ts\";\nimport type { Out } from \"./output.ts\";\n\nexport const DESKTOP_PORT = 6080;\n\nexport function openInBrowser(url: string): void {\n const opener = process.platform === \"darwin\" ? \"open\" : process.platform === \"win32\" ? \"start\" : \"xdg-open\";\n spawn(opener, [url], { stdio: \"ignore\", detached: true }).unref();\n}\n\n/** A viewer for a running desktop sandbox. The sandbox has to be up, so a caller waits for its create first. */\nexport async function openDesktop(client: Client, sandboxId: string, out: Out, expiresIn = 3600): Promise<void> {\n try {\n const signed = await client.signPortUrl(sandboxId, DESKTOP_PORT, expiresIn);\n out.event({ type: \"url\", url: signed.url, port: DESKTOP_PORT });\n out.step(\"desktop\", signed.url);\n if (out.mode !== \"json\" && process.stdout.isTTY) openInBrowser(signed.url);\n } catch (error) {\n out.warn(`The desktop did not open: ${(error as Error).message}`);\n }\n}\n","/** `munito ci` — the warm-base CI recipe as three commands. */\n\nimport { defineCommand } from \"citty\";\n\nimport { DEFAULT_BASE_SIZE, DEFAULT_DISK_GIB, drop, findBase, job, warm, type CiEvent } from \"../../core/ci.ts\";\nimport { commonArgs, context, type CommonArgs } from \"../context.ts\";\nimport { duration } from \"../output.ts\";\n\nconst nameArg = {\n name: { type: \"string\" as const, description: \"Which warm base. The default is the repository name.\", default: \"\" },\n};\n\n/** citty loses its argument types inside subCommands, so a nested command reads them through these. */\nconst str = (value: unknown): string | undefined => (typeof value === \"string\" && value ? value : undefined);\nconst num = (value: unknown): number | undefined => (typeof value === \"string\" && value ? Number(value) : undefined);\n\n/** One base per repository unless the caller names another. */\nfunction baseName(given: string): string {\n if (given) return given;\n const repo = process.env.GITHUB_REPOSITORY ?? process.env.CI_PROJECT_PATH;\n if (repo) return repo.replaceAll(\"/\", \"-\");\n return process.cwd().split(\"/\").filter(Boolean).at(-1) ?? \"default\";\n}\n\nexport const ci = defineCommand({\n meta: { name: \"ci\", description: \"Run CI jobs on a warm sandbox that already holds your dependencies.\" },\n subCommands: {\n warm: defineCommand({\n meta: { name: \"warm\", description: \"Build the warm base and pause it.\" },\n args: {\n ...commonArgs,\n ...nameArg,\n setup: { type: \"positional\", required: true, description: \"The command that installs everything.\" },\n size: { type: \"string\", description: `The size of the base. The default is ${DEFAULT_BASE_SIZE}.` },\n disk: { type: \"string\", description: `Root disk in GiB. The default is ${DEFAULT_DISK_GIB}.` },\n template: { type: \"string\", description: \"A template. The default is ubuntu.\" },\n },\n async run({ args }) {\n const { client, out } = await context(args as CommonArgs);\n const name = baseName(str(args.name) ?? \"\");\n const result = await warm(client, {\n name,\n setup: String(args.setup),\n size: str(args.size),\n diskGib: num(args.disk),\n template: str(args.template),\n onEvent: report(out),\n });\n out.step(\"ready\", `base ${result.sandboxId} for ${name}`);\n out.line(out.p.dim(` munito ci run --name ${name} \"<your test command>\"`));\n out.result(\"\", { base: result.sandboxId, name });\n },\n }),\n\n run: defineCommand({\n meta: { name: \"run\", description: \"Fork the warm base, run one job, delete the fork.\" },\n args: {\n ...commonArgs,\n ...nameArg,\n command: { type: \"positional\", required: true, description: \"The job command.\" },\n cwd: { type: \"string\", description: \"The working directory in the sandbox.\" },\n timeout: { type: \"string\", description: \"Seconds the job may take.\" },\n keep: { type: \"boolean\", description: \"Keep the fork, to look at a failure.\" },\n },\n async run({ args }) {\n const { client, out } = await context(args as CommonArgs);\n const name = baseName(str(args.name) ?? \"\");\n const exit = await job(client, {\n name,\n command: String(args.command),\n cwd: str(args.cwd),\n timeout: num(args.timeout),\n keep: Boolean(args.keep),\n onOutput: (text, stream) => out.raw(text, stream),\n onEvent: report(out),\n });\n out.result(\"\", { exit_code: exit, name });\n if (exit !== 0) process.exitCode = exit;\n },\n }),\n\n status: defineCommand({\n meta: { name: \"status\", description: \"Show the warm base of this repository.\" },\n args: { ...commonArgs, ...nameArg },\n async run({ args }) {\n const { client, out } = await context(args as CommonArgs);\n const name = baseName(str(args.name) ?? \"\");\n const base = await findBase(client, name);\n if (!base) {\n out.line(out.p.dim(`No warm base named ${name}.`));\n out.result(\"\", { name, base: null });\n return;\n }\n out.step(name, `${base.id} ${base.status}`);\n out.result(\"\", { name, base: base.id, status: base.status });\n },\n }),\n\n drop: defineCommand({\n meta: { name: \"drop\", description: \"Delete the warm base.\" },\n args: { ...commonArgs, ...nameArg },\n async run({ args }) {\n const { client, out } = await context(args as CommonArgs);\n const name = baseName(str(args.name) ?? \"\");\n const gone = await drop(client, name, report(out));\n if (!gone) out.line(out.p.dim(`No warm base named ${name}.`));\n out.result(\"\", { name, deleted: gone });\n },\n }),\n },\n});\n\nfunction report(out: Awaited<ReturnType<typeof context>>[\"out\"]) {\n return (event: CiEvent) => {\n out.event({ ...event });\n switch (event.type) {\n case \"base.creating\":\n out.step(\"base\", `building ${event.name}`);\n break;\n case \"base.created\":\n out.step(\"base\", `${event.sandboxId} in ${duration(event.ms)}`);\n break;\n case \"base.setup\":\n out.step(\"setup\", event.command.length > 70 ? `${event.command.slice(0, 70)}…` : event.command);\n break;\n case \"base.paused\":\n out.step(\"paused\", duration(event.ms));\n break;\n case \"base.found\":\n out.step(\"base\", `${event.sandboxId} ${event.status}`);\n break;\n case \"fork.created\":\n out.step(\"fork\", `${event.sandboxId} in ${duration(event.ms)}`);\n break;\n case \"job.finished\":\n out.step(\"job\", `exit ${event.exitCode} in ${duration(event.ms)}`);\n break;\n case \"base.deleted\":\n out.step(\"deleted\", event.sandboxId);\n break;\n default:\n break;\n }\n };\n}\n","/** `munito login`, `logout` and `whoami`. */\n\nimport { defineCommand } from \"citty\";\n\nimport { Client } from \"../../api/client.ts\";\nimport * as keys from \"../../core/keys.ts\";\nimport { channel, commonArgs, context } from \"../context.ts\";\nimport { cube } from \"../theme.ts\";\n\nconst CONSOLE_KEYS = \"https://console.munito.ai/keys\";\n\nexport const login = defineCommand({\n meta: { name: \"login\", description: \"Save an API key for this machine.\" },\n args: {\n ...commonArgs,\n key: { type: \"string\", description: \"The key, when you cannot paste it at a prompt.\" },\n },\n async run({ args }) {\n const out = channel(args);\n const host = keys.resolveHost(args.host ?? args.region);\n\n let key = (args.key as string | undefined)?.trim();\n if (!key) {\n if (!process.stdin.isTTY) throw new Error(`No terminal to ask in. Pass --key, or set ${keys.ENV_KEY}.`);\n const clack = await import(\"@clack/prompts\");\n if (out.mode === \"rich\") {\n out.line();\n out.line(cube(out.p));\n }\n clack.intro(out.p.bold(\"Sign in to Munito AI\"));\n clack.note(`Create a key with the Inference permission at\\n${CONSOLE_KEYS}`, \"API key\");\n const answer = await clack.password({\n message: \"Paste your API key\",\n validate: (value) => ((value ?? \"\").trim().length < 8 ? \"That is too short for a key.\" : undefined),\n });\n if (clack.isCancel(answer)) {\n clack.cancel(\"Nothing saved.\");\n process.exitCode = 1;\n return;\n }\n key = String(answer).trim();\n }\n\n // Check the key before it is written, so a typo fails here and not in the next command.\n const probe = new Client({ apiKey: key, baseUrl: host, attempts: 1 });\n await probe.listSandboxes();\n\n const path = await keys.save(key, host);\n out.step(\"saved\", `${keys.mask(key)} for ${host}`);\n out.line(out.p.dim(` ${path}, readable by you only`));\n out.result(\"\", { saved: true, host });\n },\n});\n\nexport const logout = defineCommand({\n meta: { name: \"logout\", description: \"Remove the saved API key.\" },\n args: commonArgs,\n async run({ args }) {\n await keys.clear();\n channel(args).step(\"removed\", keys.authPath());\n },\n});\n\nexport const whoami = defineCommand({\n meta: { name: \"whoami\", description: \"Show which key and host this machine uses.\" },\n args: commonArgs,\n async run({ args }) {\n const ctx = await context(args);\n const sandboxes = await ctx.client.listSandboxes();\n const running = sandboxes.filter((box) => box.status === \"running\").length;\n ctx.out.step(\"host\", ctx.host);\n ctx.out.step(\"key\", `${ctx.source}`);\n ctx.out.step(\"sandboxes\", `${running} running, ${sandboxes.length} known`);\n ctx.out.result(\"\", { host: ctx.host, source: ctx.source, running, total: sandboxes.length });\n },\n});\n","/** `munito herdr add` — give herdr a Munito sandbox to run a coding agent on.\n\nherdr holds no compute: you bring machines and it reaches them over SSH. Our SSH is a plain byte pipe, so herdr's own\n`--install` copies its Linux build in with no helper, where Vercel Sandbox needs one. This command is the whole of\nthat recipe: make a persistent sandbox, mint a key for it, and hand herdr the connection.\n*/\n\nimport { spawn, spawnSync } from \"node:child_process\";\n\nimport { defineCommand } from \"citty\";\n\nimport { AGENT_TEMPLATE } from \"../../core/agents.ts\";\nimport { commonArgs, context } from \"../context.ts\";\n\nexport const herdr = defineCommand({\n meta: {\n name: \"herdr\",\n description: \"Run coding agents on Munito sandboxes from herdr.\",\n },\n subCommands: {\n add: defineCommand({\n meta: { name: \"add\", description: \"Create a sandbox and add it to herdr as a machine.\" },\n args: {\n ...commonArgs,\n name: { type: \"string\", description: \"The machine name in herdr. The default is the sandbox id.\" },\n template: { type: \"string\", description: \"A template. The default is the agent one.\" },\n size: { type: \"string\", description: \"tiny, small, default or large.\", default: \"default\" },\n timeout: { type: \"string\", description: \"Seconds the sandbox may live before it pauses.\" },\n print: { type: \"boolean\", description: \"Print the herdr command instead of running it.\" },\n },\n async run({ args }) {\n const { client, out } = await context(args as never);\n\n // Persistent, so a pause keeps the agent's terminal and conversation, and a resume brings them back.\n const box = await client.createSandbox({\n template: (args.template as string) || AGENT_TEMPLATE,\n size: (args.size as string) || \"default\",\n internet: true,\n persistent: true,\n timeout: args.timeout ? Number(args.timeout) : 86_400,\n metadata: { \"munito.cli\": \"herdr\" },\n });\n out.step(\"sandbox\", `${box.id}, persistent`);\n\n // The credential rides in the SSH user and expires, so a long-lived machine is told to mint a new one.\n const access = await client.createSshAccess(box.id);\n const via = `ssh -o StrictHostKeyChecking=accept-new ${access.user}@${access.host}`;\n const name = (args.name as string) || box.id;\n out.step(\"ssh\", `${access.host}, minted`);\n\n const present = spawnSync(\"hc\", [\"--version\"], { stdio: \"ignore\" });\n if (args.print || present.status !== 0) {\n if (present.status !== 0) out.warn(\"herdr-core (`hc`) is not on PATH. Run this where it is:\");\n out.line(`hc machine add --name ${name} --install --via '${via}'`);\n out.result(\"\", { sandbox_id: box.id, machine: name, via });\n return;\n }\n\n out.step(\"herdr\", `adding ${name}`);\n const child = spawn(\"hc\", [\"machine\", \"add\", \"--name\", name, \"--install\", \"--via\", via], { stdio: \"inherit\" });\n const code = await new Promise<number>((done) => child.on(\"close\", (c) => done(c ?? 0)));\n if (code !== 0) {\n out.error(`hc machine add exited ${code}. The sandbox is ${box.id}.`);\n process.exitCode = code;\n return;\n }\n out.line();\n out.step(\"ready\", name);\n out.line(out.p.dim(` hc run --bg --on ${name} --cwd /workspace --name agent claude`));\n out.line(out.p.dim(` munito pause ${box.id} # keeps the terminal and the conversation`));\n out.line(out.p.dim(` the SSH credential expires; run \\`munito herdr add\\` again for a new machine`));\n out.result(\"\", { sandbox_id: box.id, machine: name });\n },\n }),\n },\n});\n","/** `munito init <agent>` — configure a harness on this machine, from the same table the sandbox uses. */\n\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname } from \"node:path\";\n\nimport { defineCommand } from \"citty\";\n\nimport {\n AGENTS,\n CLAUDE_MODEL,\n DEFAULT_MODEL,\n DEFAULT_SMALL_MODEL,\n PACKAGES,\n PLUGINS,\n PROVIDERS,\n wire,\n type AgentName,\n type AuthMode,\n type ProviderName,\n} from \"../../core/providers.ts\";\nimport { commonArgs, context } from \"../context.ts\";\n\nexport const init = defineCommand({\n meta: {\n name: \"init\",\n description: \"Point a coding agent on this machine at Munito AI.\",\n },\n args: {\n ...commonArgs,\n agent: { type: \"positional\", required: true, description: `Which harness: ${AGENTS.join(\", \")}.` },\n provider: {\n type: \"string\",\n description: `Where the model comes from: ${PROVIDERS.join(\", \")}.`,\n default: \"munito\",\n },\n auth: { type: \"string\", description: \"token or subscription.\", default: \"token\" },\n model: { type: \"string\", description: \"A model id, in place of the recommended one.\" },\n \"dry-run\": { type: \"boolean\", description: \"Show what would be written, and write nothing.\" },\n },\n async run({ args }) {\n const name = args.agent as AgentName;\n if (!AGENTS.includes(name)) throw new Error(`Unknown agent ${name}. One of: ${AGENTS.join(\", \")}`);\n\n const { client, out, host } = await context(args);\n const home = homedir();\n\n const guide = `https://docs.munito.ai/reference/agents/${name}`;\n const plugin = PLUGINS[name];\n if (plugin) {\n // The harness installs a plugin we publish, so there is no file for this tool to write.\n out.step(name, \"installs a Munito AI provider plugin\");\n out.line(`\\n ${out.p.primary(plugin)}\\n`);\n out.line(out.p.dim(` Then enter your key. See ${guide}`));\n out.result(\"\", { agent: name, plugin, guide });\n return;\n }\n\n const wiring = wire(\n name,\n args.provider as ProviderName,\n args.auth as AuthMode,\n {\n host,\n token: client.token,\n model: args.model ?? (name === \"claude\" ? CLAUDE_MODEL : DEFAULT_MODEL),\n smallModel: DEFAULT_SMALL_MODEL,\n },\n process.cwd(),\n home,\n );\n\n for (const file of wiring.files) {\n if (args[\"dry-run\"]) {\n out.step(\"would write\", file.path);\n continue;\n }\n await mkdir(dirname(file.path), { recursive: true });\n await writeFile(file.path, file.content, { mode: 0o600 });\n out.step(\"wrote\", file.path);\n }\n\n // A key never goes into a config file, so the shell has to carry it.\n const exports = Object.entries(wiring.env).filter(([, value]) => value);\n if (exports.length) {\n out.line();\n out.line(out.p.dim(\" Add these to your shell:\"));\n for (const [key, value] of exports) {\n const shown =\n key.toLowerCase().includes(\"token\") || key.toLowerCase().includes(\"key\") ? \"$MUNITO_API_KEY\" : value;\n out.line(` export ${key}=${shown}`);\n }\n }\n if (wiring.unset.length && !args[\"dry-run\"]) {\n out.line();\n out.line(out.p.dim(` Clear these if your shell sets them: ${wiring.unset.join(\", \")}`));\n }\n out.line();\n if (!PACKAGES[name]) {\n // We write its configuration, but we do not install the harness itself.\n out.line(out.p.dim(` Install ${name} itself first. See ${guide}`));\n out.line();\n }\n out.step(\"ready\", `run ${out.p.primary(name)}`);\n out.result(\"\", { agent: name, files: wiring.files.map((file) => file.path) });\n },\n});\n","/** `munito mcp` — the same commands as MCP tools, so a Claude or Codex session farms work out to our sandboxes.\n\nOne line adds it: `claude mcp add munito -- npx @munitoai/cli mcp`. The tools call `core/`, exactly as the commands do, so\nthere is no second implementation of anything.\n*/\n\nimport { defineCommand } from \"citty\";\n\nimport { runAgent } from \"../../core/agents.ts\";\nimport { AGENTS, PROVIDERS, type AgentName, type AuthMode, type ProviderName } from \"../../core/providers.ts\";\nimport { commonArgs, context, type CommonArgs } from \"../context.ts\";\n\n/** A tool answer, in the shape MCP expects. */\nfunction text(body: unknown): { content: { type: \"text\"; text: string }[]; isError?: boolean } {\n return { content: [{ type: \"text\", text: typeof body === \"string\" ? body : JSON.stringify(body, null, 2) }] };\n}\n\nfunction failed(message: string) {\n return { ...text(message), isError: true };\n}\n\ninterface RunAgentArgs {\n prompt: string;\n agent: AgentName;\n provider: ProviderName;\n model?: string;\n files?: { path: string; content: string }[];\n max_turns?: number;\n}\n\ninterface RunCommandArgs {\n command: string;\n template: string;\n internet: boolean;\n timeout: number;\n}\n\nexport const mcp = defineCommand({\n meta: {\n name: \"mcp\",\n description: \"Serve the Munito AI tools over MCP on stdio, for a coding agent to call.\",\n },\n args: commonArgs,\n async run({ args }) {\n // stdout is the protocol, so nothing else may write to it.\n const ctx = await context({ ...(args as CommonArgs), json: true });\n const { client } = ctx;\n\n const { McpServer } = await import(\"@modelcontextprotocol/sdk/server/mcp.js\");\n const { StdioServerTransport } = await import(\"@modelcontextprotocol/sdk/server/stdio.js\");\n const { z } = await import(\"zod\");\n\n const server = new McpServer({ name: \"munito\", version: \"0.1.0\" });\n // The SDK's generic inference over a zod shape blows the instantiation depth, so the shapes are registered\n // through a loose handle and each handler declares its own argument type.\n const register = server.registerTool.bind(server) as unknown as (\n name: string,\n config: Record<string, unknown>,\n handler: (args: never) => Promise<{ content: { type: \"text\"; text: string }[]; isError?: boolean }>,\n ) => void;\n\n register(\n \"run_agent\",\n {\n title: \"Run a coding agent in a sandbox\",\n description:\n \"Run a coding agent on a fresh Linux microVM and return its answer and a patch of what it changed. \" +\n \"The sandbox is deleted afterwards. Use this to do work in isolation, or to run several agents at once.\",\n inputSchema: {\n prompt: z.string().describe(\"What the agent should do.\"),\n agent: z.enum(AGENTS).default(\"claude\").describe(\"Which harness runs the task.\"),\n provider: z.enum(PROVIDERS).default(\"munito\").describe(\"Where the model comes from.\"),\n model: z.string().optional().describe(\"A model id, in place of the recommended one.\"),\n files: z\n .array(z.object({ path: z.string(), content: z.string() }))\n .optional()\n .describe(\"Files to put in /workspace before the agent starts.\"),\n max_turns: z.number().int().positive().optional(),\n },\n },\n (async ({ prompt, agent, provider, model, files, max_turns }: RunAgentArgs) => {\n try {\n const run = await runAgent(client, {\n agent: agent as AgentName,\n prompt,\n provider: provider as ProviderName,\n auth: \"token\" as AuthMode,\n model,\n files,\n maxTurns: max_turns,\n });\n return text({\n result: run.result,\n exit_code: run.exitCode,\n patch: run.patch || null,\n sandbox_id: run.sandboxId,\n duration_ms: run.durationMs,\n });\n } catch (error) {\n return failed(`The agent did not run: ${(error as Error).message}`);\n }\n }) as never,\n );\n\n register(\n \"run_command\",\n {\n title: \"Run a command in a sandbox\",\n description:\n \"Run one shell command on a fresh Linux microVM and return its output. The sandbox is deleted \" +\n \"afterwards. Use this for code you do not trust, or for a build that must start clean.\",\n inputSchema: {\n command: z.string().describe(\"The command, which runs in bash.\"),\n template: z.string().default(\"base\").describe(\"base, ubuntu, agent or desktop.\"),\n internet: z.boolean().default(false).describe(\"Allow outbound connections.\"),\n timeout: z.number().int().positive().default(120).describe(\"Seconds the command may take.\"),\n },\n },\n (async ({ command, template, internet, timeout }: RunCommandArgs) => {\n let id = \"\";\n try {\n const box = await client.createSandbox({\n template,\n size: \"small\",\n internet,\n timeout: Math.max(timeout + 60, 120),\n metadata: { \"munito.cli\": \"mcp\" },\n });\n id = box.id;\n const out = await client.exec(id, { command, timeout });\n return text({ exit_code: out.exit_code, stdout: out.stdout, stderr: out.stderr });\n } catch (error) {\n return failed(`The command did not run: ${(error as Error).message}`);\n } finally {\n if (id) await client.deleteSandbox(id).catch(() => {});\n }\n }) as never,\n );\n\n register(\n \"list_agents\",\n {\n title: \"List the coding agents and providers\",\n description: \"Which harnesses run in a sandbox, and where their model can come from.\",\n inputSchema: {},\n },\n (async () => text({ agents: AGENTS, providers: PROVIDERS, host: ctx.host })) as never,\n );\n\n await server.connect(new StdioServerTransport());\n // The transport owns the process now: it ends when the client closes stdin.\n await new Promise<void>(() => {});\n },\n});\n","/** The machines: `ls`, `run`, `exec`, `ssh`, `open`, `rm`, `pause`, `resume`. */\n\nimport { spawn } from \"node:child_process\";\n\nimport { defineCommand } from \"citty\";\n\nimport type { CommandEvent, Sandbox } from \"../../api/types.ts\";\nimport { AGENT_TEMPLATE, createAgentSandbox } from \"../../core/agents.ts\";\nimport { AGENTS, PROVIDERS, type AgentName, type AuthMode, type ProviderName } from \"../../core/providers.ts\";\nimport { forwardSpec, sshArgv } from \"../../core/ssh.ts\";\nimport { commonArgs, context } from \"../context.ts\";\nimport { DESKTOP_PORT, openInBrowser } from \"../desktop.ts\";\nimport { duration, table } from \"../output.ts\";\n\nexport const ls = defineCommand({\n meta: { name: \"ls\", description: \"List your sandboxes.\" },\n args: { ...commonArgs, all: { type: \"boolean\", alias: \"a\", description: \"Stopped ones too.\" } },\n async run({ args }) {\n const { client, out } = await context(args);\n const boxes = await client.listSandboxes();\n const shown = args.all ? boxes : boxes.filter((box) => box.status !== \"stopped\");\n for (const box of shown) out.event({ type: \"sandbox\", ...box });\n if (out.mode === \"json\") return;\n if (!shown.length) {\n out.line(out.p.dim('No sandboxes. Start one with `munito agent \"...\"`.'));\n return;\n }\n const rows = [[\"ID\", \"STATUS\", \"TEMPLATE\", \"SIZE\", \"AGE\"], ...shown.map(row)];\n out.line(table(rows, out.p));\n },\n});\n\nfunction row(box: Sandbox): string[] {\n const age = box.created_at ? duration(Date.now() - box.created_at * 1000) : \"\";\n return [box.id, box.status, box.template, `${box.vcpus}c ${Math.round(box.memory_mib / 1024)}g`, age];\n}\n\nexport const run = defineCommand({\n meta: { name: \"run\", description: \"Run one command in a throwaway sandbox.\" },\n args: {\n ...commonArgs,\n command: { type: \"positional\", required: true, description: \"The command to run.\" },\n template: { type: \"string\", description: \"A template. The default is base.\", default: \"base\" },\n size: { type: \"string\", description: \"tiny, small, default or large.\", default: \"small\" },\n internet: { type: \"boolean\", description: \"Allow outbound connections.\" },\n timeout: { type: \"string\", description: \"Seconds the command may take.\" },\n },\n async run({ args }) {\n const { client, out } = await context(args);\n const box = await client.createSandbox({\n template: args.template,\n size: args.size,\n internet: Boolean(args.internet),\n timeout: 600,\n metadata: { \"munito.cli\": \"run\" },\n });\n try {\n const exit = await stream(client, box.id, args.command as string, out, args.timeout);\n if (exit !== 0) process.exitCode = exit;\n } finally {\n await client.deleteSandbox(box.id).catch(() => {});\n }\n },\n});\n\nexport const exec = defineCommand({\n meta: { name: \"exec\", description: \"Run a command in a sandbox you already have.\" },\n args: {\n ...commonArgs,\n id: { type: \"positional\", required: true, description: \"The sandbox id.\" },\n command: { type: \"positional\", required: true, description: \"The command to run.\" },\n cwd: { type: \"string\", description: \"The working directory.\" },\n timeout: { type: \"string\", description: \"Seconds the command may take.\" },\n },\n async run({ args }) {\n const { client, out } = await context(args);\n const exit = await stream(client, args.id as string, args.command as string, out, args.timeout, args.cwd);\n if (exit !== 0) process.exitCode = exit;\n },\n});\n\nasync function stream(\n client: Awaited<ReturnType<typeof context>>[\"client\"],\n id: string,\n command: string,\n out: Awaited<ReturnType<typeof context>>[\"out\"],\n timeout?: string,\n cwd?: string,\n): Promise<number> {\n let exit = 0;\n const events = client.execStream(id, {\n command,\n cwd,\n timeout: timeout ? Number(timeout) : undefined,\n });\n for await (const event of events as AsyncGenerator<CommandEvent>) {\n if (event.type === \"stdout\") out.raw(event.data);\n else if (event.type === \"stderr\") out.raw(event.data, \"stderr\");\n else exit = event.exit_code;\n out.event({ ...event });\n }\n return exit;\n}\n\nexport const rm = defineCommand({\n meta: { name: \"rm\", description: \"Delete sandboxes.\" },\n args: { ...commonArgs, ids: { type: \"positional\", required: true, description: \"One or more sandbox ids.\" } },\n async run({ args, rawArgs }) {\n const { client, out } = await context(args);\n const ids = rawArgs.filter((value) => value.startsWith(\"sbx_\"));\n for (const id of ids.length ? ids : [args.ids as string]) {\n await client.deleteSandbox(id);\n out.step(\"deleted\", id);\n }\n },\n});\n\nexport const pause = defineCommand({\n meta: { name: \"pause\", description: \"Pause a persistent sandbox.\" },\n args: { ...commonArgs, id: { type: \"positional\", required: true, description: \"The sandbox id.\" } },\n async run({ args }) {\n const { client, out } = await context(args);\n const box = await client.pauseSandbox(args.id as string);\n out.step(\"paused\", box.id);\n },\n});\n\nexport const resume = defineCommand({\n meta: { name: \"resume\", description: \"Resume a paused sandbox.\" },\n args: { ...commonArgs, id: { type: \"positional\", required: true, description: \"The sandbox id.\" } },\n async run({ args }) {\n const { client, out } = await context(args);\n const box = await client.resumeSandbox(args.id as string);\n out.step(\"resumed\", box.id);\n },\n});\n\nexport const fork = defineCommand({\n meta: { name: \"fork\", description: \"Start new sandboxes from a persistent one, as it is now.\" },\n args: {\n ...commonArgs,\n id: { type: \"positional\", required: true, description: \"The sandbox to fork.\" },\n count: { type: \"string\", description: \"How many. The default is 1.\" },\n },\n async run({ args }) {\n const { client, out } = await context(args);\n const count = args.count ? Number(args.count) : 1;\n const started = Date.now();\n const answer = await client.forkSandbox(args.id as string, count);\n const forks = Array.isArray(answer) ? answer : (answer.data ?? []);\n out.step(\"forked\", `${forks.length} in ${duration(Date.now() - started)}`);\n for (const box of forks) out.line(out.p.dim(` ${box.id}`));\n out.result(\"\", { forks: forks.map((box) => box.id) });\n },\n});\n\nexport const ssh = defineCommand({\n meta: { name: \"ssh\", description: \"Open a shell in a sandbox.\" },\n args: {\n ...commonArgs,\n id: { type: \"positional\", required: true, description: \"The sandbox id.\" },\n forward: {\n type: \"string\",\n alias: \"L\",\n description: \"Forward a port: 3080, 3081:3080, or 3081:127.0.0.1:3080. Repeatable.\",\n },\n print: { type: \"boolean\", description: \"Print the command instead of connecting.\" },\n },\n async run({ args }) {\n const { client, out } = await context(args);\n // Checked before the request, so a typo costs no credential.\n const forwards = [args.forward ?? []].flat().filter(Boolean) as string[];\n const flags = forwards.flatMap((spec) => [\"-L\", forwardSpec(spec)]);\n // The credential rides in the SSH user and expires, so each call mints a fresh one. There is no key file.\n const access = await client.createSshAccess(args.id as string);\n if (args.print || !process.stdin.isTTY) {\n out.line(flags.length ? access.command.replace(/^ssh /, `ssh ${flags.join(\" \")} `) : access.command);\n return;\n }\n for (const spec of forwards) out.step(\"forwarding\", forwardSpec(spec));\n out.step(\"connecting\", access.host);\n const child = spawn(\"ssh\", sshArgv(access.user, access.host, forwards), {\n stdio: \"inherit\",\n });\n await new Promise<void>((done) =>\n child.on(\"close\", (code) => {\n process.exitCode = code ?? 0;\n done();\n }),\n );\n },\n});\n\nexport const open = defineCommand({\n meta: { name: \"open\", description: \"Open a sandbox port, or its desktop, in your browser.\" },\n args: {\n ...commonArgs,\n id: { type: \"positional\", required: true, description: \"The sandbox id.\" },\n port: { type: \"string\", description: `The port. The default is the desktop, ${DESKTOP_PORT}.` },\n expires: { type: \"string\", description: \"Seconds the link stays valid. The default is 3600.\" },\n print: { type: \"boolean\", description: \"Print the URL instead of opening it.\" },\n },\n async run({ args }) {\n const { client, out } = await context(args);\n const port = args.port ? Number(args.port) : DESKTOP_PORT;\n const signed = await client.signPortUrl(args.id as string, port, args.expires ? Number(args.expires) : 3600);\n out.event({ type: \"url\", url: signed.url, port });\n if (args.print || out.mode === \"json\" || !process.stdout.isTTY) {\n out.line(signed.url);\n return;\n }\n out.step(\"opening\", `port ${port}`);\n out.line(out.p.dim(` ${signed.url}`));\n openInBrowser(signed.url);\n },\n});\n\nexport const create = defineCommand({\n meta: { name: \"create\", description: \"Create a sandbox and leave it running.\" },\n args: {\n ...commonArgs,\n template: { type: \"string\", description: \"base, ubuntu, agent or desktop.\", default: AGENT_TEMPLATE },\n agent: { type: \"string\", description: `Point one harness at a provider: ${AGENTS.join(\", \")}.` },\n provider: { type: \"string\", description: `Where the model comes from: ${PROVIDERS.join(\", \")}.` },\n auth: { type: \"string\", description: \"token or subscription.\" },\n model: { type: \"string\", description: \"A model id, in place of the recommended one.\" },\n size: { type: \"string\", description: \"tiny, small, default or large.\", default: \"default\" },\n internet: { type: \"boolean\", description: \"Allow outbound connections.\", default: true },\n persistent: { type: \"boolean\", description: \"Keep files and processes across a pause.\" },\n timeout: { type: \"string\", description: \"Seconds the sandbox may live.\" },\n },\n async run({ args }) {\n const { client, out } = await context(args);\n const common = {\n template: args.template as string,\n size: args.size as string,\n internet: Boolean(args.internet),\n persistent: Boolean(args.persistent),\n timeout: args.timeout ? Number(args.timeout) : undefined,\n };\n const box = args.agent\n ? await createAgentSandbox(client, {\n ...common,\n agent: args.agent as AgentName,\n provider: args.provider as ProviderName | undefined,\n auth: args.auth as AuthMode | undefined,\n model: args.model as string | undefined,\n metadata: { \"munito.cli\": \"create\", \"munito.agent\": args.agent as string },\n })\n : await client.createSandbox({ ...common, metadata: { \"munito.cli\": \"create\" } });\n out.step(\"created\", box.id);\n out.line(out.p.dim(` munito ssh ${box.id}`));\n out.result(\"\", { sandbox_id: box.id });\n },\n});\n","/** Port forwards for an SSH connection to a sandbox. Pure: it builds argv, and runs nothing. */\n\nconst LOOPBACK = \"127.0.0.1\";\nconst PORT = /^[0-9]{1,5}$/;\n\nexport class ForwardError extends Error {}\n\nfunction port(value: string, spec: string): string {\n if (!PORT.test(value) || Number(value) < 1 || Number(value) > 65535) {\n throw new ForwardError(`\"${spec}\" is not a port forward. Use 3080, 3081:3080, or 3081:127.0.0.1:3080.`);\n }\n return value;\n}\n\n/**\n * One `-L` value from a short spec: `3080`, `3081:3080`, or a full `local:host:remote`.\n * The short forms bind the loopback of the sandbox, where a private server listens.\n */\nexport function forwardSpec(spec: string): string {\n const parts = spec.split(\":\");\n if (parts.length === 1) {\n const only = port(parts[0], spec);\n return `${only}:${LOOPBACK}:${only}`;\n }\n if (parts.length === 2) {\n return `${port(parts[0], spec)}:${LOOPBACK}:${port(parts[1], spec)}`;\n }\n if (parts.length === 3) {\n if (!parts[1]) throw new ForwardError(`\"${spec}\" names no host.`);\n return `${port(parts[0], spec)}:${parts[1]}:${port(parts[2], spec)}`;\n }\n throw new ForwardError(`\"${spec}\" is not a port forward. Use 3080, 3081:3080, or 3081:127.0.0.1:3080.`);\n}\n\n/** The argv of `ssh`, with one `-L` for each forward. */\nexport function sshArgv(user: string, host: string, forwards: readonly string[] = []): string[] {\n const argv = [\"-o\", \"StrictHostKeyChecking=accept-new\"];\n for (const spec of forwards) argv.push(\"-L\", forwardSpec(spec));\n argv.push(`${user}@${host}`);\n return argv;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,eAAe;;;ACGxB,SAAS,gBAAgB;AACzB,SAAS,SAAS,UAAU,IAAI,MAAM,iBAAiB;AACvD,SAAS,cAAc;AACvB,SAAS,MAAM,eAAe;AAC9B,SAAS,iBAAiB;AAI1B,IAAM,MAAM,UAAU,QAAQ;AAGvB,IAAM,YAAY;AAClB,IAAM,iBAAiB,KAAK;AAC5B,IAAM,kBAAkB,MAAM;AAE9B,I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,UAAW,CAAAA,SAAQ,KAAKA,SAAQ,EAAE,IAAI,aAAa,MAAM,SAAS,EAAE,CAAC;AAC/E,WAAO,MAAM,WAAW,OAAO,MAAM,WAAW,MAAM,IAAI;AAAA,EAC5D;AACA,EAAAA,SAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AACpE,SAAO;AACT;AAEA,QAAQ,GAAG,sBAAsB,CAAC,WAAW;AAC3C,UAAQ,KAAKD,QAAO,MAAM,CAAC;AAC7B,CAAC;AAED,MAAM,QAAQ,IAAI,EAAE,MAAM,CAAC,UAAmB;AAC5C,UAAQ,KAAKA,QAAO,KAAK,CAAC;AAC5B,CAAC;","names":["defineCommand","stream","text","stream","text","row","channel","require","out","out","name","run","defineCommand","defineCommand","out","text","stream","defineCommand","defineCommand","out","spawn","defineCommand","defineCommand","out","spawn","writeFile","defineCommand","defineCommand","out","writeFile","defineCommand","defineCommand","agent","run","out","spawn","defineCommand","defineCommand","out","run","rm","spawn","port","defineCommand","run","rm","report","channel"]}
@@ -0,0 +1,117 @@
1
+ /** Run one coding agent in one sandbox, end to end.
2
+
3
+ Six API requests, seven environment variables and two levels of JSON escaping become one call. Core code: it emits
4
+ events and returns a result, and it never writes to a terminal.
5
+ */
6
+ import { Client } from "../api/client.ts";
7
+ import type { Sandbox } from "../api/types.ts";
8
+ import { type AgentName, type AuthMode, type ProviderName } from "./providers.ts";
9
+ /** The template that carries the harnesses, and the one to use where a deployment does not have it yet. */
10
+ export declare const AGENT_TEMPLATE = "agent";
11
+ export declare const AGENT_TEMPLATE_FALLBACK = "ubuntu";
12
+ export declare const WORKDIR = "/workspace";
13
+ export type AgentEvent = {
14
+ type: "sandbox.creating";
15
+ } | {
16
+ type: "sandbox.created";
17
+ sandboxId: string;
18
+ ms: number;
19
+ } | {
20
+ type: "wiring.written";
21
+ files: number;
22
+ } | {
23
+ type: "files.uploaded";
24
+ count: number;
25
+ bytes: number;
26
+ } | {
27
+ type: "agent.started";
28
+ argv: string[];
29
+ } | {
30
+ type: "output";
31
+ stream: "stdout" | "stderr";
32
+ data: string;
33
+ } | {
34
+ type: "agent.finished";
35
+ exitCode: number;
36
+ ms: number;
37
+ } | {
38
+ type: "patch.ready";
39
+ bytes: number;
40
+ } | {
41
+ type: "harness.installing";
42
+ agent: string;
43
+ package: string;
44
+ } | {
45
+ type: "harness.installed";
46
+ agent: string;
47
+ ms: number;
48
+ } | {
49
+ type: "sandbox.deleted";
50
+ sandboxId: string;
51
+ } | {
52
+ type: "sandbox.kept";
53
+ sandboxId: string;
54
+ };
55
+ export interface UploadFile {
56
+ path: string;
57
+ content: string;
58
+ }
59
+ export interface RunAgentOptions {
60
+ agent: AgentName;
61
+ prompt: string;
62
+ provider?: ProviderName;
63
+ auth?: AuthMode;
64
+ model?: string;
65
+ smallModel?: string;
66
+ template?: string;
67
+ size?: string;
68
+ /** Seconds the sandbox may live. The command gets the same budget, capped by the API at 1,800. */
69
+ timeout?: number;
70
+ workdir?: string;
71
+ maxTurns?: number;
72
+ keep?: boolean;
73
+ files?: UploadFile[];
74
+ /** Bring the work back as a unified diff. On by default when files go up. */
75
+ patch?: boolean;
76
+ metadata?: Record<string, string>;
77
+ onEvent?: (event: AgentEvent) => void;
78
+ signal?: AbortSignal;
79
+ }
80
+ export interface AgentRun {
81
+ sandboxId: string;
82
+ exitCode: number;
83
+ /** The harness's own answer, unwrapped when it reports JSON. */
84
+ result: string;
85
+ stdout: string;
86
+ stderr: string;
87
+ /** A unified diff of what the agent changed, empty when nothing did. */
88
+ patch: string;
89
+ sessionId?: string;
90
+ durationMs: number;
91
+ kept: boolean;
92
+ }
93
+ export declare function runAgent(client: Client, options: RunAgentOptions): Promise<AgentRun>;
94
+ /** What a sandbox needs so one harness in it reaches one provider. */
95
+ export interface CreateAgentSandboxOptions {
96
+ agent: AgentName;
97
+ provider?: ProviderName;
98
+ auth?: AuthMode;
99
+ model?: string;
100
+ smallModel?: string;
101
+ template?: string;
102
+ size?: string;
103
+ timeout?: number;
104
+ persistent?: boolean;
105
+ internet?: boolean;
106
+ workdir?: string;
107
+ metadata?: Record<string, string>;
108
+ onEvent?: (event: AgentEvent) => void;
109
+ signal?: AbortSignal;
110
+ }
111
+ /** Create a sandbox with one harness already pointed at a provider, and leave it running. */
112
+ export declare function createAgentSandbox(client: Client, options: CreateAgentSandboxOptions): Promise<Sandbox>;
113
+ /** Claude Code reports a JSON envelope. The others print their answer. */
114
+ export declare function unwrap(agent: AgentName, stdout: string): {
115
+ result: string;
116
+ sessionId?: string;
117
+ };
@@ -0,0 +1,78 @@
1
+ /** The warm-base CI loop: build one disk, pause it, fork it for each job.
2
+
3
+ The recipe at /reference/sandboxes/ci, as three calls. A base is found by its metadata, so one CI step can build it
4
+ and another, in a different process, can use it. Core code: no terminal output.
5
+ */
6
+ import type { Client } from "../api/client.ts";
7
+ import type { CommandResult, Sandbox } from "../api/types.ts";
8
+ export declare const ROLE = "munito.ci";
9
+ export declare const NAME_KEY = "munito.ci.name";
10
+ export declare const DEFAULT_BASE_SIZE = "large";
11
+ export declare const DEFAULT_DISK_GIB = 40;
12
+ export type CiEvent = {
13
+ type: "base.creating";
14
+ name: string;
15
+ } | {
16
+ type: "base.created";
17
+ sandboxId: string;
18
+ ms: number;
19
+ } | {
20
+ type: "base.setup";
21
+ command: string;
22
+ } | {
23
+ type: "base.paused";
24
+ sandboxId: string;
25
+ ms: number;
26
+ } | {
27
+ type: "base.found";
28
+ sandboxId: string;
29
+ status: string;
30
+ } | {
31
+ type: "fork.created";
32
+ sandboxId: string;
33
+ ms: number;
34
+ } | {
35
+ type: "job.finished";
36
+ exitCode: number;
37
+ ms: number;
38
+ } | {
39
+ type: "fork.deleted";
40
+ sandboxId: string;
41
+ } | {
42
+ type: "base.deleted";
43
+ sandboxId: string;
44
+ };
45
+ export declare class CiError extends Error {
46
+ }
47
+ /** The base of this name, running or paused. */
48
+ export declare function findBase(client: Client, name: string): Promise<Sandbox | null>;
49
+ export interface WarmOptions {
50
+ name: string;
51
+ setup: string;
52
+ size?: string;
53
+ diskGib?: number;
54
+ template?: string;
55
+ timeout?: number;
56
+ onEvent?: (event: CiEvent) => void;
57
+ }
58
+ export interface WarmResult {
59
+ sandboxId: string;
60
+ setup: CommandResult;
61
+ paused: boolean;
62
+ }
63
+ /** Build the warm disk and pause it. A base of the same name is deleted first. */
64
+ export declare function warm(client: Client, options: WarmOptions): Promise<WarmResult>;
65
+ export interface JobOptions {
66
+ name: string;
67
+ command: string;
68
+ cwd?: string;
69
+ timeout?: number;
70
+ env?: Record<string, string>;
71
+ keep?: boolean;
72
+ onOutput?: (text: string, stream: "stdout" | "stderr") => void;
73
+ onEvent?: (event: CiEvent) => void;
74
+ }
75
+ /** Fork the base, run one job in the fork, delete it. */
76
+ export declare function job(client: Client, options: JobOptions): Promise<number>;
77
+ /** Delete the base of this name. */
78
+ export declare function drop(client: Client, name: string, onEvent?: (event: CiEvent) => void): Promise<boolean>;
@@ -0,0 +1,23 @@
1
+ /** Where the key comes from, and where a sign-in keeps it. Never logs or prints a key. */
2
+ export declare const ENV_KEY = "MUNITO_API_KEY";
3
+ export declare const ENV_HOST = "MUNITO_HOST";
4
+ export interface Credentials {
5
+ apiKey: string;
6
+ host: string;
7
+ /** Where the key came from, for a diagnostic that never shows the key itself. */
8
+ source: "environment" | "file";
9
+ }
10
+ export declare function configDir(): string;
11
+ export declare function authPath(): string;
12
+ /** The host for a region name, a full URL, or the default. */
13
+ export declare function resolveHost(value?: string): string;
14
+ /** The environment wins, so a scripted run never picks up a stale sign-in. */
15
+ export declare function load(hostOverride?: string): Promise<Credentials | null>;
16
+ export declare function save(apiKey: string, host: string): Promise<string>;
17
+ export declare function clear(): Promise<void>;
18
+ /** The key with its middle removed, for a line a person reads. */
19
+ export declare function mask(apiKey: string): string;
20
+ export declare class MissingKeyError extends Error {
21
+ constructor();
22
+ }
23
+ export declare function require(hostOverride?: string): Promise<Credentials>;
@@ -0,0 +1,60 @@
1
+ /** The (agent, provider, auth) table: what each harness needs to talk to a model.
2
+
3
+ This is the whole point of the package. The same table is baked into the `agent` template, so a sandbox needs no
4
+ wiring; here it wires a harness the API has not wired yet, and it configures a harness on a laptop for `munito init`.
5
+ Pure: it reads nothing and writes nothing.
6
+ */
7
+ export declare const AGENTS: readonly ["claude", "codex", "opencode", "dsh", "hermes", "pi", "openclaw", "prime"];
8
+ export type AgentName = (typeof AGENTS)[number];
9
+ export declare const PROVIDERS: readonly ["munito", "anthropic", "openai"];
10
+ export type ProviderName = (typeof PROVIDERS)[number];
11
+ export type AuthMode = "token" | "subscription";
12
+ /** The harnesses the `agent` template installs, and that `munito agent` can run headless. */
13
+ export declare const BAKED: readonly AgentName[];
14
+ /** Each harness's npm package, for the image and for an on-demand install. */
15
+ export declare const PACKAGES: Partial<Record<AgentName, string>>;
16
+ /** The provider plugins we publish. The `agent` template installs the pi and OpenClaw ones; Hermes offers only a
17
+ shell installer from its own domain, which no digest pins, so the image does not carry it. */
18
+ export declare const PLUGINS: Partial<Record<AgentName, string>>;
19
+ export interface Target {
20
+ /** The host, with no path: `https://api.eu.munito.ai`. */
21
+ host: string;
22
+ token: string;
23
+ model: string;
24
+ smallModel: string;
25
+ }
26
+ export interface WiringFile {
27
+ path: string;
28
+ content: string;
29
+ }
30
+ export interface Wiring {
31
+ /** Variables to set for every command and shell. */
32
+ env: Record<string, string>;
33
+ /** Variables to clear. A subscription sign-in breaks when a base URL of ours survives. */
34
+ unset: string[];
35
+ files: WiringFile[];
36
+ }
37
+ export declare const DEFAULT_MODEL = "zai-org/glm-5.3-flash";
38
+ export declare const DEFAULT_SMALL_MODEL = "qwen/qwen3.8-27b";
39
+ /** Claude Code reads one context window for a model, so it takes the long variant. */
40
+ export declare const CLAUDE_MODEL = "zai-org/glm-5.3-flash[1m]";
41
+ /** The guest runs its commands as root. `munito init` passes the user's own home instead. */
42
+ export declare const GUEST_HOME = "/root";
43
+ /** Claude Code stops at a welcome screen and a trust dialog on a fresh machine. Neither touches authentication. */
44
+ export declare function claudeGates(workdir: string, home?: string): WiringFile;
45
+ /** Every variable the table can set, so a switch of provider clears what the last one left. */
46
+ export declare const MANAGED_ENV: readonly string[];
47
+ export declare class WiringError extends Error {
48
+ }
49
+ /** How `agent` reaches `provider`. Throws when the pair has no answer, rather than wiring something half right. */
50
+ export declare function wire(agent: AgentName, provider: ProviderName, auth: AuthMode, target: Target, workdir?: string, home?: string): Wiring;
51
+ export interface RunOptions {
52
+ maxTurns?: number;
53
+ resume?: string;
54
+ /** The model, for a harness whose headless form names it on the command line. */
55
+ model?: string;
56
+ }
57
+ /** The argv that runs one task and exits, for each harness we install. */
58
+ export declare function headlessArgv(agent: AgentName, prompt: string, options?: RunOptions): string[];
59
+ /** The interactive binary of a harness, for a terminal session. */
60
+ export declare function shellArgv(agent: AgentName): string[];
@@ -0,0 +1,10 @@
1
+ /** Port forwards for an SSH connection to a sandbox. Pure: it builds argv, and runs nothing. */
2
+ export declare class ForwardError extends Error {
3
+ }
4
+ /**
5
+ * One `-L` value from a short spec: `3080`, `3081:3080`, or a full `local:host:remote`.
6
+ * The short forms bind the loopback of the sandbox, where a private server listens.
7
+ */
8
+ export declare function forwardSpec(spec: string): string;
9
+ /** The argv of `ssh`, with one `-L` for each forward. */
10
+ export declare function sshArgv(user: string, host: string, forwards?: readonly string[]): string[];
@@ -0,0 +1,17 @@
1
+ /** The local worktree that an agent should see, and the patch it sends back.
2
+
3
+ Only files that git already tracks or would track, so an ignored secret, a build directory and a venv never leave the
4
+ machine. Core code: no terminal output.
5
+ */
6
+ import type { UploadFile } from "./agents.ts";
7
+ /** Caps, so a stray directory cannot turn one command into a long upload. */
8
+ export declare const MAX_FILES = 2000;
9
+ export declare const MAX_FILE_BYTES: number;
10
+ export declare const MAX_TOTAL_BYTES: number;
11
+ export declare class WorkspaceError extends Error {
12
+ }
13
+ /** The files of the git worktree at `dir`, or none when it is not a repository. */
14
+ export declare function collect(dir?: string): Promise<UploadFile[]>;
15
+ export declare function describeUpload(files: UploadFile[]): string;
16
+ /** Apply a unified diff to the worktree. Returns the files that changed, and changes nothing when it cannot. */
17
+ export declare function applyPatch(patch: string, dir?: string): Promise<string[]>;
@@ -0,0 +1,55 @@
1
+ /** The SDK. `npx @munitoai/cli` and `import { Munito } from "@munitoai/cli"` run the same code.
2
+
3
+ ```ts
4
+ import { Munito } from "@munitoai/cli";
5
+
6
+ const munito = new Munito({ apiKey: process.env.MUNITO_API_KEY! });
7
+ const run = await munito.agent.run({ agent: "claude", prompt: "fix the failing test" });
8
+ console.log(run.result);
9
+ ```
10
+ */
11
+ import { Client, REGIONS, type ClientOptions } from "./api/client.ts";
12
+ import { type AgentRun, type RunAgentOptions } from "./core/agents.ts";
13
+ import { job as jobCi, warm as warmCi } from "./core/ci.ts";
14
+ import type { CreateSandbox, Sandbox } from "./api/types.ts";
15
+ export { ApiError, Client, DEFAULT_BASE_URL, REGIONS } from "./api/client.ts";
16
+ export type { ClientOptions } from "./api/client.ts";
17
+ export * from "./api/types.ts";
18
+ export { AGENT_TEMPLATE, WORKDIR, createAgentSandbox, runAgent, unwrap } from "./core/agents.ts";
19
+ export type { AgentEvent, AgentRun, CreateAgentSandboxOptions, RunAgentOptions, UploadFile } from "./core/agents.ts";
20
+ export * from "./core/providers.ts";
21
+ export { drop as dropCiBase, findBase as findCiBase, job as runCiJob, warm as warmCiBase } from "./core/ci.ts";
22
+ export type { CiEvent, JobOptions, WarmOptions, WarmResult } from "./core/ci.ts";
23
+ export interface MunitoOptions extends Omit<ClientOptions, "baseUrl"> {
24
+ /** `global`, `eu`, `us`, or a full URL. */
25
+ region?: string;
26
+ baseUrl?: string;
27
+ }
28
+ /** One object for the whole product, in the shape a reader expects from an SDK. */
29
+ export declare class Munito {
30
+ readonly client: Client;
31
+ constructor(options: MunitoOptions);
32
+ get agent(): {
33
+ run: (options: RunAgentOptions) => Promise<AgentRun>;
34
+ };
35
+ get ci(): {
36
+ warm: (options: Parameters<typeof warmCi>[1]) => Promise<import("./index.ts").WarmResult>;
37
+ job: (options: Parameters<typeof jobCi>[1]) => Promise<number>;
38
+ find: (name: string) => Promise<Sandbox | null>;
39
+ drop: (name: string) => Promise<boolean>;
40
+ };
41
+ get sandboxes(): {
42
+ create: (spec: CreateSandbox) => Promise<Sandbox>;
43
+ get: (id: string) => Promise<Sandbox>;
44
+ list: () => Promise<Sandbox[]>;
45
+ delete: (id: string) => Promise<void>;
46
+ pause: (id: string) => Promise<Sandbox>;
47
+ resume: (id: string) => Promise<Sandbox>;
48
+ exec: (id: string, spec: import("./index.ts").ExecCommand, signal?: AbortSignal) => Promise<import("./index.ts").CommandResult>;
49
+ execStream: (id: string, spec: import("./index.ts").ExecCommand, signal?: AbortSignal) => AsyncGenerator<import("./index.ts").CommandEvent>;
50
+ readFile: (id: string, path: string) => Promise<string>;
51
+ writeFile: (id: string, path: string, content: string) => Promise<void>;
52
+ signPortUrl: (id: string, port: number, expiresIn?: number) => Promise<import("./index.ts").PortUrl>;
53
+ };
54
+ }
55
+ export { REGIONS as regions };