/** * Command tuple type - [command, ...args] */ type Command = [string, ...string[]]; /** * Options for shell wrapping */ interface ShellOptions { /** Working directory - wraps command with `cd "cwd" && ...` */ cwd?: string; /** Run in background - wraps command with `nohup ... > /dev/null 2>&1 &` */ background?: boolean; } /** * Escape a string for safe use in shell commands using single quotes. * This is the safest method as single quotes preserve all characters literally, * except for single quotes themselves which must be handled specially. * * @example shellEscape("hello world") // "'hello world'" * @example shellEscape("it's here") // "'it'\\''s here'" * @example shellEscape("$HOME") // "'$HOME'" (no variable expansion) */ declare function shellEscape(s: string): string; /** * Escape a string for use inside double quotes. * * This is a legacy helper kept for backward compatibility; for new code, * prefer {@link shellEscape} which uses single-quoted, safer shell escaping. * * @example esc('path with "quotes"') // 'path with \\"quotes\\"' * @deprecated Use {@link shellEscape} for safer escaping. This function only escapes * double quotes and may not be safe for all shell contexts. Migration: replace * `esc(str)` with `shellEscape(str)`. */ declare function esc(s: string): string; /** * Escape each argument in a command array and join them with spaces. * Arguments that are safe (alphanumeric, dash, underscore, dot, slash, colon, equals) * are left unquoted for readability. * * @example escapeArgs(['npm', 'install', 'express']) // 'npm install express' * @example escapeArgs(['echo', 'hello world']) // "echo 'hello world'" * @example escapeArgs(['cp', 'file with spaces.txt', '/dest']) // "cp 'file with spaces.txt' /dest" */ declare function escapeArgs(args: string[]): string; /** * Internal helper to build shell command with proper escaping */ declare function buildShellCommand(shellBin: string, command: Command, options?: ShellOptions): Command; /** * Shell wrapper - callable function with shell-specific methods * * @example * // Default (sh) * shell(cmd.npm.install(), { cwd: '/app' }) * // => ['sh', '-c', 'cd "/app" && npm install'] * * @example * // Shell-specific * shell.bash(cmd.node('server.js'), { background: true }) * // => ['bash', '-c', 'nohup node server.js > /dev/null 2>&1 &'] * * @example * shell.zsh(cmd.npm.run('dev'), { cwd: '/app' }) * // => ['zsh', '-c', 'cd "/app" && npm run dev'] */ declare const shell: ((command: Command, options?: ShellOptions) => Command) & { /** Wrap with sh (POSIX shell) */ sh: (command: Command, options?: ShellOptions) => Command; /** Wrap with bash */ bash: (command: Command, options?: ShellOptions) => Command; /** Wrap with zsh */ zsh: (command: Command, options?: ShellOptions) => Command; }; declare const sh: (command: Command, options?: ShellOptions) => Command; declare const bash: (command: Command, options?: ShellOptions) => Command; declare const zsh: (command: Command, options?: ShellOptions) => Command; /** * @computesdk/cmd - Type-safe shell command builders * * Build shell commands as tuples for use with sandbox.runCommand() * * @example * ```typescript * import { cmd, npm, node } from '@computesdk/cmd'; * * await sandbox.runCommand(npm.install('express')); * await sandbox.runCommand(cmd.mkdir('/app/src')); * await sandbox.runCommand(node('server.js'), { background: true }); * ``` */ /** * Command builders for common shell operations * * Namespace containing command builder functions for filesystem operations, * package managers, git, network utilities, and more. * * For shell wrapping with cwd/background options, use `shell()` instead. * * @example * // Command builders * cmd.npm.install('express') * // => ['npm', 'install', 'express'] * * cmd.mkdir('/app/src') * // => ['mkdir', '-p', '/app/src'] * * @example * // For shell wrapping, use shell() instead * import { shell, npm } from '@computesdk/cmd'; * shell(npm.install(), { cwd: '/app' }) * // => ['sh', '-c', 'cd '/app' && npm install'] */ declare const cmd: { install: (options?: { apiKey?: string; version?: string; silent?: boolean; interactive?: boolean; }) => Command; isInstalled: () => Command; version: () => Command; start: (options?: { apiKey?: string; accessToken?: string; port?: number; logLevel?: "debug" | "info" | "warn" | "error"; wait?: boolean; waitTimeout?: number; }) => Command; stop: () => Command; health: (options?: { host?: string; port?: number; }) => Command; isSetup: (options?: { host?: string; port?: number; }) => Command; setup: (options?: { apiKey?: string; accessToken?: string; port?: number; version?: string; silent?: boolean; interactive?: boolean; wait?: boolean; waitTimeout?: number; }) => Command; compute: { install: (options?: { apiKey?: string; version?: string; silent?: boolean; interactive?: boolean; }) => Command; isInstalled: () => Command; version: () => Command; start: (options?: { apiKey?: string; accessToken?: string; port?: number; logLevel?: "debug" | "info" | "warn" | "error"; wait?: boolean; waitTimeout?: number; }) => Command; stop: () => Command; health: (options?: { host?: string; port?: number; }) => Command; setup: (options?: { apiKey?: string; accessToken?: string; port?: number; version?: string; silent?: boolean; interactive?: boolean; wait?: boolean; waitTimeout?: number; }) => Command; isSetup: (options?: { host?: string; port?: number; }) => Command; }; echo: (text: string) => Command; env: () => Command; printenv: (name?: string) => Command; which: (command: string) => Command; whoami: () => Command; uname: (options?: { all?: boolean; }) => Command; hostname: () => Command; df: (path?: string, options?: { human?: boolean; }) => Command; du: (path: string, options?: { human?: boolean; summarize?: boolean; }) => Command; sleep: (seconds: number) => Command; date: (format?: string) => Command; find: (path: string, options?: { name?: string; type?: "f" | "d"; }) => Command; tee: (file: string, options?: { append?: boolean; }) => Command; diff: (file1: string, file2: string, options?: { unified?: boolean; brief?: boolean; }) => Command; parallel: (commands: string[], options?: { killOthers?: boolean; }) => Command; raw: (command: string, args?: string[]) => Command; base64: { encode: (file?: string) => Command; decode: (file?: string) => Command; }; md5sum: (file: string, options?: { check?: boolean; }) => Command; sha256sum: (file: string, options?: { check?: boolean; }) => Command; sha1sum: (file: string, options?: { check?: boolean; }) => Command; tar: { extract: (file: string, options?: { dir?: string; }) => Command; create: (output: string, source: string) => Command; }; unzip: (file: string, options?: { dir?: string; }) => Command; grep: (pattern: string, file?: string, options?: { recursive?: boolean; ignoreCase?: boolean; lineNumber?: boolean; }) => Command; sed: (expression: string, file: string, options?: { inPlace?: boolean; }) => Command; head: (file: string, lines?: number) => Command; tail: (file: string, lines?: number, options?: { follow?: boolean; }) => Command; wc: (file: string, options?: { lines?: boolean; words?: boolean; chars?: boolean; }) => Command; sort: (// Compute file: string, options?: { reverse?: boolean; numeric?: boolean; unique?: boolean; }) => Command; uniq: (file: string, options?: { count?: boolean; }) => Command; jq: (filter: string, file?: string, options?: { raw?: boolean; compact?: boolean; }) => Command; xargs: (command: string, args?: string[], options?: { parallel?: number; nullDelimited?: boolean; }) => Command; awk: (program: string, file?: string, options?: { fieldSeparator?: string; }) => Command; cut: (file: string, options: { fields?: string; delimiter?: string; characters?: string; }) => Command; tr: (set1: string, set2?: string, options?: { delete?: string; squeeze?: boolean; }) => Command; curl: (url: string, options?: { output?: string; silent?: boolean; }) => Command; wget: (url: string, options?: { output?: string; quiet?: boolean; }) => Command; port: { find: (p: number) => Command; kill: (p: number) => Command; isUsed: (p: number) => Command; list: () => Command; waitFor: (p: number, timeoutSeconds?: number) => Command; }; net: { ping: (host: string, count?: number) => Command; check: (host: string, p: number) => Command; publicIp: () => Command; interfaces: () => Command; }; git: { clone: (url: string, options?: { depth?: number; branch?: string; dir?: string; }) => Command; pull: () => Command; checkout: (branch: string, options?: { create?: boolean; }) => Command; status: () => Command; add: (path: string, options?: { all?: boolean; }) => Command; commit: (message: string, options?: { all?: boolean; }) => Command; push: (options?: { remote?: string; branch?: string; setUpstream?: boolean; force?: boolean; }) => Command; branch: (name?: string, options?: { all?: boolean; delete?: boolean; create?: boolean; }) => Command; diff: (options?: { staged?: boolean; file?: string; }) => Command; log: (options?: { oneline?: boolean; count?: number; }) => Command; stash: (options?: { pop?: boolean; list?: boolean; drop?: boolean; message?: string; }) => Command; fetch: (options?: { remote?: string; all?: boolean; prune?: boolean; }) => Command; reset: (options?: { hard?: boolean; soft?: boolean; ref?: string; }) => Command; init: () => Command; }; npm: { install: (pkg?: string, options?: { dev?: boolean; global?: boolean; }) => Command; run: (script: string, args?: string[]) => Command; init: () => Command; uninstall: (pkg: string) => Command; }; pnpm: { install: (pkg?: string, options?: { dev?: boolean; }) => Command; run: (script: string, args?: string[]) => Command; }; yarn: { install: () => Command; add: (pkg: string, options?: { dev?: boolean; }) => Command; run: (script: string) => Command; }; pip: { install: (pkg: string) => Command; uninstall: (pkg: string) => Command; }; bun: { install: (pkg?: string, options?: { dev?: boolean; }) => Command; run: (script: string, args?: string[]) => Command; exec: (file: string, args?: string[]) => Command; }; deno: { run: (file: string, options?: { allow?: string[]; }) => Command; install: (url: string, options?: { name?: string; }) => Command; }; npx: ((pkg: string, args?: string[]) => Command) & { concurrently: (commands: string[], options?: { names?: string[]; killOthers?: boolean; }) => Command; }; bunx: ((pkg: string, args?: string[]) => Command) & { concurrently: (commands: string[], options?: { names?: string[]; killOthers?: boolean; }) => Command; }; uv: { install: (pkg: string) => Command; run: (script: string, args?: string[]) => Command; sync: () => Command; venv: (path?: string) => Command; }; poetry: { install: (options?: { noRoot?: boolean; }) => Command; add: (pkg: string, options?: { dev?: boolean; }) => Command; run: (command: string, args?: string[]) => Command; build: () => Command; }; pipx: { install: (pkg: string) => Command; run: (pkg: string, args?: string[]) => Command; uninstall: (pkg: string) => Command; upgrade: (pkg: string) => Command; }; node: (script: string, args?: string[]) => Command; python: (script: string, args?: string[]) => Command; kill: (pid: number, // Import all commands for assembly signal?: number) => Command; pkill: (name: string, options?: { signal?: number; }) => Command; ps: (options?: { all?: boolean; }) => Command; timeout: (seconds: number, command: string, args?: string[]) => Command; mkdir: (path: string, options?: { recursive?: boolean; }) => Command; rm: ((path: string, options?: { recursive?: boolean; force?: boolean; }) => Command) & { rf: (path: string) => Command; auto: (path: string) => Command; }; cp: (src: string, dest: string, options?: { recursive?: boolean; }) => Command; mv: (src: string, dest: string) => Command; ls: (path?: string, options?: { all?: boolean; long?: boolean; }) => Command; pwd: () => Command; cd: (path: string) => Command; chmod: (mode: string, path: string, options?: { recursive?: boolean; }) => Command; chown: (owner: string, path: string, options?: { recursive?: boolean; }) => Command; touch: (path: string) => Command; cat: (path: string) => Command; ln: (target: string, link: string, options?: { symbolic?: boolean; force?: boolean; }) => Command; readlink: (path: string, options?: { canonical?: boolean; }) => Command; test: { exists: (path: string) => Command; isFile: (path: string) => Command; isDir: (path: string) => Command; isReadable: (path: string) => Command; isWritable: (path: string) => Command; isExecutable: (path: string) => Command; notEmpty: (path: string) => Command; isSymlink: (path: string) => Command; }; rsync: (src: string, dest: string, options?: { archive?: boolean; verbose?: boolean; compress?: boolean; delete?: boolean; dryRun?: boolean; exclude?: string[]; }) => Command; }; declare const mkdir: (path: string, options?: { recursive?: boolean; }) => Command; declare const rm: ((path: string, options?: { recursive?: boolean; force?: boolean; }) => Command) & { rf: (path: string) => Command; auto: (path: string) => Command; }; declare const cp: (src: string, dest: string, options?: { recursive?: boolean; }) => Command; declare const mv: (src: string, dest: string) => Command; declare const ls: (path?: string, options?: { all?: boolean; long?: boolean; }) => Command; declare const pwd: () => Command; declare const chmod: (mode: string, path: string, options?: { recursive?: boolean; }) => Command; declare const chown: (owner: string, path: string, options?: { recursive?: boolean; }) => Command; declare const touch: (path: string) => Command; declare const cat: (path: string) => Command; declare const ln: (target: string, link: string, options?: { symbolic?: boolean; force?: boolean; }) => Command; declare const readlink: (path: string, options?: { canonical?: boolean; }) => Command; declare const test: { exists: (path: string) => Command; isFile: (path: string) => Command; isDir: (path: string) => Command; isReadable: (path: string) => Command; isWritable: (path: string) => Command; isExecutable: (path: string) => Command; notEmpty: (path: string) => Command; isSymlink: (path: string) => Command; }; declare const rsync: (src: string, dest: string, options?: { archive?: boolean; verbose?: boolean; compress?: boolean; delete?: boolean; dryRun?: boolean; exclude?: string[]; }) => Command; declare const node: (script: string, args?: string[]) => Command; declare const python: (script: string, args?: string[]) => Command; declare const kill: (pid: number, signal?: number) => Command; declare const pkill: (name: string, options?: { signal?: number; }) => Command; declare const ps: (options?: { all?: boolean; }) => Command; declare const timeout: (seconds: number, command: string, args?: string[]) => Command; declare const npm: { install: (pkg?: string, options?: { dev?: boolean; global?: boolean; }) => Command; run: (script: string, args?: string[]) => Command; init: () => Command; uninstall: (pkg: string) => Command; }; declare const pnpm: { install: (pkg?: string, options?: { dev?: boolean; }) => Command; run: (script: string, args?: string[]) => Command; }; declare const yarn: { install: () => Command; add: (pkg: string, options?: { dev?: boolean; }) => Command; run: (script: string) => Command; }; declare const pip: { install: (pkg: string) => Command; uninstall: (pkg: string) => Command; }; declare const bun: { install: (pkg?: string, options?: { dev?: boolean; }) => Command; run: (script: string, args?: string[]) => Command; exec: (file: string, args?: string[]) => Command; }; declare const deno: { run: (file: string, options?: { allow?: string[]; }) => Command; install: (url: string, options?: { name?: string; }) => Command; }; declare const npx: ((pkg: string, args?: string[]) => Command) & { concurrently: (commands: string[], options?: { names?: string[]; killOthers?: boolean; }) => Command; }; declare const bunx: ((pkg: string, args?: string[]) => Command) & { concurrently: (commands: string[], options?: { names?: string[]; killOthers?: boolean; }) => Command; }; declare const uv: { install: (pkg: string) => Command; run: (script: string, args?: string[]) => Command; sync: () => Command; venv: (path?: string) => Command; }; declare const poetry: { install: (options?: { noRoot?: boolean; }) => Command; add: (pkg: string, options?: { dev?: boolean; }) => Command; run: (command: string, args?: string[]) => Command; build: () => Command; }; declare const pipx: { install: (pkg: string) => Command; run: (pkg: string, args?: string[]) => Command; uninstall: (pkg: string) => Command; upgrade: (pkg: string) => Command; }; declare const git: { clone: (url: string, options?: { depth?: number; branch?: string; dir?: string; }) => Command; pull: () => Command; checkout: (branch: string, options?: { create?: boolean; }) => Command; status: () => Command; add: (path: string, options?: { all?: boolean; }) => Command; commit: (message: string, options?: { all?: boolean; }) => Command; push: (options?: { remote?: string; branch?: string; setUpstream?: boolean; force?: boolean; }) => Command; branch: (name?: string, options?: { all?: boolean; delete?: boolean; create?: boolean; }) => Command; diff: (options?: { staged?: boolean; file?: string; }) => Command; log: (options?: { oneline?: boolean; count?: number; }) => Command; stash: (options?: { pop?: boolean; list?: boolean; drop?: boolean; message?: string; }) => Command; fetch: (options?: { remote?: string; all?: boolean; prune?: boolean; }) => Command; reset: (options?: { hard?: boolean; soft?: boolean; ref?: string; }) => Command; init: () => Command; }; declare const curl: (url: string, options?: { output?: string; silent?: boolean; }) => Command; declare const wget: (url: string, options?: { output?: string; quiet?: boolean; }) => Command; declare const port: { find: (p: number) => Command; kill: (p: number) => Command; isUsed: (p: number) => Command; list: () => Command; waitFor: (p: number, timeoutSeconds?: number) => Command; }; declare const net: { ping: (host: string, count?: number) => Command; check: (host: string, p: number) => Command; publicIp: () => Command; interfaces: () => Command; }; declare const grep: (pattern: string, file?: string, options?: { recursive?: boolean; ignoreCase?: boolean; lineNumber?: boolean; }) => Command; declare const sed: (expression: string, file: string, options?: { inPlace?: boolean; }) => Command; declare const head: (file: string, lines?: number) => Command; declare const tail: (file: string, lines?: number, options?: { follow?: boolean; }) => Command; declare const wc: (file: string, options?: { lines?: boolean; words?: boolean; chars?: boolean; }) => Command; declare const sort: (file: string, options?: { reverse?: boolean; numeric?: boolean; unique?: boolean; }) => Command; declare const uniq: (file: string, options?: { count?: boolean; }) => Command; declare const jq: (filter: string, file?: string, options?: { raw?: boolean; compact?: boolean; }) => Command; declare const xargs: (command: string, args?: string[], options?: { parallel?: number; nullDelimited?: boolean; }) => Command; declare const awk: (program: string, file?: string, options?: { fieldSeparator?: string; }) => Command; declare const cut: (file: string, options: { fields?: string; delimiter?: string; characters?: string; }) => Command; declare const tr: (set1: string, set2?: string, options?: { delete?: string; squeeze?: boolean; }) => Command; declare const tar: { extract: (file: string, options?: { dir?: string; }) => Command; create: (output: string, source: string) => Command; }; declare const unzip: (file: string, options?: { dir?: string; }) => Command; declare const echo: (text: string) => Command; declare const env: () => Command; declare const printenv: (name?: string) => Command; declare const which: (command: string) => Command; declare const whoami: () => Command; declare const uname: (options?: { all?: boolean; }) => Command; declare const hostname: () => Command; declare const df: (path?: string, options?: { human?: boolean; }) => Command; declare const du: (path: string, options?: { human?: boolean; summarize?: boolean; }) => Command; declare const sleep: (seconds: number) => Command; declare const date: (format?: string) => Command; declare const find: (path: string, options?: { name?: string; type?: "f" | "d"; }) => Command; declare const tee: (file: string, options?: { append?: boolean; }) => Command; declare const diff: (file1: string, file2: string, options?: { unified?: boolean; brief?: boolean; }) => Command; declare const parallel: (commands: string[], options?: { killOthers?: boolean; }) => Command; declare const raw: (command: string, args?: string[]) => Command; declare const base64: { encode: (file?: string) => Command; decode: (file?: string) => Command; }; declare const md5sum: (file: string, options?: { check?: boolean; }) => Command; declare const sha256sum: (file: string, options?: { check?: boolean; }) => Command; declare const sha1sum: (file: string, options?: { check?: boolean; }) => Command; declare const compute: { install: (options?: { apiKey?: string; version?: string; silent?: boolean; interactive?: boolean; }) => Command; isInstalled: () => Command; version: () => Command; start: (options?: { apiKey?: string; accessToken?: string; port?: number; logLevel?: "debug" | "info" | "warn" | "error"; wait?: boolean; waitTimeout?: number; }) => Command; stop: () => Command; health: (options?: { host?: string; port?: number; }) => Command; setup: (options?: { apiKey?: string; accessToken?: string; port?: number; version?: string; silent?: boolean; interactive?: boolean; wait?: boolean; waitTimeout?: number; }) => Command; isSetup: (options?: { host?: string; port?: number; }) => Command; }; export { type Command, type ShellOptions, awk, base64, bash, buildShellCommand, bun, bunx, cat, chmod, chown, cmd, compute, cp, curl, cut, date, cmd as default, deno, df, diff, du, echo, env, esc, escapeArgs, find, git, grep, head, hostname, jq, kill, ln, ls, md5sum, mkdir, mv, net, node, npm, npx, parallel, pip, pipx, pkill, pnpm, poetry, port, printenv, ps, pwd, python, raw, readlink, rm, rsync, sed, sh, sha1sum, sha256sum, shell, shellEscape, sleep, sort, tail, tar, tee, test, timeout, touch, tr, uname, uniq, unzip, uv, wc, wget, which, whoami, xargs, yarn, zsh };