@computesdk/just-bash
Advanced tools
+1
-10
@@ -37,13 +37,4 @@ import * as _computesdk_provider from '@computesdk/provider'; | ||
| } | ||
| /** | ||
| * Create a just-bash provider instance using the factory pattern | ||
| * | ||
| * just-bash provides local sandboxed bash execution with: | ||
| * - Virtual filesystem (in-memory) | ||
| * - 60+ built-in commands (cat, grep, sed, awk, jq, etc.) | ||
| * - Python support via pyodide | ||
| * - No external dependencies or authentication required | ||
| */ | ||
| declare const justBash: (config: JustBashConfig) => _computesdk_provider.Provider<JustBashSandbox, any, any>; | ||
| declare const justBash: (config?: JustBashConfig) => _computesdk_provider.Provider<JustBashSandbox, any, any>; | ||
| export { type JustBashConfig, type JustBashSandbox, justBash }; |
+1
-10
@@ -37,13 +37,4 @@ import * as _computesdk_provider from '@computesdk/provider'; | ||
| } | ||
| /** | ||
| * Create a just-bash provider instance using the factory pattern | ||
| * | ||
| * just-bash provides local sandboxed bash execution with: | ||
| * - Virtual filesystem (in-memory) | ||
| * - 60+ built-in commands (cat, grep, sed, awk, jq, etc.) | ||
| * - Python support via pyodide | ||
| * - No external dependencies or authentication required | ||
| */ | ||
| declare const justBash: (config: JustBashConfig) => _computesdk_provider.Provider<JustBashSandbox, any, any>; | ||
| declare const justBash: (config?: JustBashConfig) => _computesdk_provider.Provider<JustBashSandbox, any, any>; | ||
| export { type JustBashConfig, type JustBashSandbox, justBash }; |
+2
-1
@@ -29,3 +29,3 @@ "use strict"; | ||
| var activeSandboxes = /* @__PURE__ */ new Map(); | ||
| var justBash = (0, import_provider.defineProvider)({ | ||
| var _provider = (0, import_provider.defineProvider)({ | ||
| name: "just-bash", | ||
@@ -233,2 +233,3 @@ methods: { | ||
| }); | ||
| var justBash = (config = {}) => _provider(config); | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
@@ -235,0 +236,0 @@ 0 && (module.exports = { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * just-bash Provider - Factory-based Implementation\n *\n * Local sandboxed bash execution using the just-bash package.\n * Provides a virtual filesystem and bash shell environment\n * without requiring any external services or containers.\n *\n * Features:\n * - Pure TypeScript bash interpreter (no real processes)\n * - In-memory virtual filesystem\n * - Python support via pyodide (optional)\n * - Shell command execution with 60+ built-in commands\n * - No authentication required - runs entirely locally\n */\n\nimport { Bash } from 'just-bash';\nimport type { BashExecResult, BashOptions } from 'just-bash';\nimport { defineProvider } from '@computesdk/provider';\nimport type {\n CodeResult,\n CommandResult,\n SandboxInfo,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from 'computesdk';\n\n/**\n * just-bash-specific configuration options\n */\nexport interface JustBashConfig {\n /** Enable Python support via pyodide (disabled by default) */\n python?: boolean;\n /** Initial files to populate in the virtual filesystem */\n files?: BashOptions['files'];\n /** Initial environment variables */\n env?: Record<string, string>;\n /** Working directory (defaults to /home/user) */\n cwd?: string;\n /**\n * Custom filesystem implementation.\n * Defaults to InMemoryFs. Use OverlayFs for copy-on-write over a real directory,\n * ReadWriteFs for direct disk access, or MountableFs to combine multiple filesystems.\n */\n fs?: BashOptions['fs'];\n /**\n * Custom commands to register alongside built-in commands.\n * Created with `defineCommand()` from just-bash.\n */\n customCommands?: BashOptions['customCommands'];\n /** Network configuration for commands like curl */\n network?: BashOptions['network'];\n}\n\n/** Internal sandbox state */\ninterface JustBashSandbox {\n bash: Bash;\n id: string;\n createdAt: Date;\n config: JustBashConfig;\n}\n\n/** Active sandboxes registry */\nconst activeSandboxes = new Map<string, JustBashSandbox>();\n\n/**\n * Create a just-bash provider instance using the factory pattern\n *\n * just-bash provides local sandboxed bash execution with:\n * - Virtual filesystem (in-memory)\n * - 60+ built-in commands (cat, grep, sed, awk, jq, etc.)\n * - Python support via pyodide\n * - No external dependencies or authentication required\n */\nexport const justBash = defineProvider<JustBashSandbox, JustBashConfig>({\n name: 'just-bash',\n methods: {\n sandbox: {\n /**\n * Create a new just-bash sandbox\n */\n create: async (config: JustBashConfig, options?: CreateSandboxOptions) => {\n const sandboxId = options?.sandboxId || `just-bash-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n\n // Check if reconnecting to existing sandbox\n if (options?.sandboxId && activeSandboxes.has(options.sandboxId)) {\n const existing = activeSandboxes.get(options.sandboxId)!;\n return { sandbox: existing, sandboxId: existing.id };\n }\n\n const bash = new Bash({\n files: config.files,\n env: {\n ...config.env,\n ...options?.envs,\n },\n cwd: config.cwd || '/home/user',\n python: config.python ?? (options?.runtime === 'python'),\n fs: config.fs,\n customCommands: config.customCommands,\n network: config.network,\n });\n\n const sandbox: JustBashSandbox = {\n bash,\n id: sandboxId,\n createdAt: new Date(),\n config,\n };\n\n activeSandboxes.set(sandboxId, sandbox);\n return { sandbox, sandboxId };\n },\n\n /**\n * Get an existing just-bash sandbox by ID\n */\n getById: async (_config: JustBashConfig, sandboxId: string) => {\n const sandbox = activeSandboxes.get(sandboxId);\n if (!sandbox) return null;\n return { sandbox, sandboxId };\n },\n\n /**\n * List all active just-bash sandboxes\n */\n list: async (_config: JustBashConfig) => {\n return Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({\n sandbox,\n sandboxId,\n }));\n },\n\n /**\n * Destroy a just-bash sandbox\n */\n destroy: async (_config: JustBashConfig, sandboxId: string) => {\n activeSandboxes.delete(sandboxId);\n },\n\n /**\n * Execute code in the sandbox\n *\n * For Python: executes via the built-in python3 command (pyodide)\n * For Node/JS: wraps code in a bash script that evaluates it\n */\n runCode: async (sandbox: JustBashSandbox, code: string, runtime?: Runtime): Promise<CodeResult> => {\n const effectiveRuntime = runtime || (\n code.includes('print(') ||\n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n : 'node'\n );\n\n let result: BashExecResult;\n\n if (effectiveRuntime === 'python') {\n // Use python3 command (requires python: true in config)\n // Write code to a temp file and execute it to avoid quoting issues\n const tempFile = `/tmp/_computesdk_run_${Date.now()}.py`;\n await sandbox.bash.writeFile(tempFile, code);\n result = await sandbox.bash.exec(`python3 ${tempFile}`);\n } else {\n // For node/JS, execute as bash script\n // just-bash doesn't have a real Node.js runtime,\n // so we execute the code as a bash script\n const tempFile = `/tmp/_computesdk_run_${Date.now()}.sh`;\n await sandbox.bash.writeFile(tempFile, code);\n result = await sandbox.bash.exec(`bash ${tempFile}`);\n }\n\n const output = result.stderr\n ? `${result.stdout}${result.stdout && result.stderr ? '\\n' : ''}${result.stderr}`\n : result.stdout;\n\n return {\n output,\n exitCode: result.exitCode,\n language: effectiveRuntime,\n };\n },\n\n /**\n * Execute a shell command in the sandbox\n */\n runCommand: async (sandbox: JustBashSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const execOptions: { env?: Record<string, string>; cwd?: string } = {};\n\n if (options?.env && Object.keys(options.env).length > 0) {\n execOptions.env = options.env;\n }\n\n if (options?.cwd) {\n execOptions.cwd = options.cwd;\n }\n\n const result = await sandbox.bash.exec(\n command,\n Object.keys(execOptions).length > 0 ? execOptions : undefined\n );\n\n return {\n stdout: result.stdout || '',\n stderr: result.stderr || '',\n exitCode: result.exitCode,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime,\n };\n }\n },\n\n /**\n * Get sandbox information\n */\n getInfo: async (sandbox: JustBashSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'just-bash',\n runtime: sandbox.config.python ? 'python' : 'node',\n status: 'running',\n createdAt: sandbox.createdAt,\n timeout: 0, // No timeout - local execution\n metadata: {\n type: 'local',\n cwd: sandbox.bash.getCwd(),\n },\n };\n },\n\n /**\n * Get URL for a port - not supported for local execution\n */\n getUrl: async (_sandbox: JustBashSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(\n `just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`\n );\n },\n\n /**\n * Filesystem operations using the just-bash virtual filesystem\n */\n filesystem: {\n readFile: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<string> => {\n return sandbox.bash.readFile(path);\n },\n\n writeFile: async (sandbox: JustBashSandbox, path: string, content: string, _runCommand): Promise<void> => {\n // Ensure parent directory exists\n const parentDir = path.substring(0, path.lastIndexOf('/')) || '/';\n if (parentDir !== '/') {\n await sandbox.bash.exec(`mkdir -p ${parentDir}`);\n }\n await sandbox.bash.writeFile(path, content);\n },\n\n mkdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`mkdir -p ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<FileEntry[]> => {\n const result = await sandbox.bash.exec(`ls -la ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const entries: FileEntry[] = [];\n const lines = result.stdout.trim().split('\\n');\n\n for (const line of lines) {\n // Skip total line and empty lines\n if (!line || line.startsWith('total')) continue;\n\n const parts = line.split(/\\s+/);\n if (parts.length < 9) continue;\n\n const permissions = parts[0];\n const name = parts.slice(8).join(' ');\n\n // Skip . and ..\n if (name === '.' || name === '..') continue;\n\n entries.push({\n name,\n type: permissions.startsWith('d') ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4], 10) || 0,\n modified: new Date(),\n });\n }\n\n return entries;\n },\n\n exists: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<boolean> => {\n const result = await sandbox.bash.exec(`test -f ${path} || test -d ${path}`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`rm -rf ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n },\n },\n\n /**\n * Get the native JustBashSandbox instance for advanced usage\n */\n getInstance: (sandbox: JustBashSandbox): JustBashSandbox => {\n return sandbox;\n },\n },\n },\n});\n\n// Export types\nexport type { JustBashSandbox };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,uBAAqB;AAErB,sBAA+B;AA+C/B,IAAM,kBAAkB,oBAAI,IAA6B;AAWlD,IAAM,eAAW,gCAAgD;AAAA,EACtE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA;AAAA;AAAA,MAIP,QAAQ,OAAO,QAAwB,YAAmC;AACxE,cAAM,YAAY,SAAS,aAAa,aAAa,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;AAGzG,YAAI,SAAS,aAAa,gBAAgB,IAAI,QAAQ,SAAS,GAAG;AAChE,gBAAM,WAAW,gBAAgB,IAAI,QAAQ,SAAS;AACtD,iBAAO,EAAE,SAAS,UAAU,WAAW,SAAS,GAAG;AAAA,QACrD;AAEA,cAAM,OAAO,IAAI,sBAAK;AAAA,UACpB,OAAO,OAAO;AAAA,UACd,KAAK;AAAA,YACH,GAAG,OAAO;AAAA,YACV,GAAG,SAAS;AAAA,UACd;AAAA,UACA,KAAK,OAAO,OAAO;AAAA,UACnB,QAAQ,OAAO,UAAW,SAAS,YAAY;AAAA,UAC/C,IAAI,OAAO;AAAA,UACX,gBAAgB,OAAO;AAAA,UACvB,SAAS,OAAO;AAAA,QAClB,CAAC;AAED,cAAM,UAA2B;AAAA,UAC/B;AAAA,UACA,IAAI;AAAA,UACJ,WAAW,oBAAI,KAAK;AAAA,UACpB;AAAA,QACF;AAEA,wBAAgB,IAAI,WAAW,OAAO;AACtC,eAAO,EAAE,SAAS,UAAU;AAAA,MAC9B;AAAA;AAAA;AAAA;AAAA,MAKA,SAAS,OAAO,SAAyB,cAAsB;AAC7D,cA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AS,OAAO,SAAS,KAAM;AAEnC,oBAAQ,KAAK;AAAA,cACX;AAAA,cACA,MAAM,YAAY,WAAW,GAAG,IAAI,cAAuB;AAAA,cAC3D,MAAM,SAAS,MAAM,CAAC,GAAG,EAAE,KAAK;AAAA,cAChC,UAAU,oBAAI,KAAK;AAAA,YACrB,CAAC;AAAA,UACH;AAEA,iBAAO;AAAA,QACT;AAAA,QAEA,QAAQ,OAAO,SAA0B,MAAc,gBAAkC;AACvF,gBAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,WAAW,IAAI,eAAe,IAAI,EAAE;AAC3E,iBAAO,OAAO,aAAa;AAAA,QAC7B;AAAA,QAEA,QAAQ,OAAO,SAA0B,MAAc,gBAA+B;AACpF,gBAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,UAAU,IAAI,EAAE;AACvD,cAAI,OAAO,aAAa,GAAG;AACzB,kBAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,OAAO,MAAM,EAAE;AAAA,UAC9D;AAAA,QACF;AAAA,MACF;AAAA;AAAA;AAAA;AAAA,MAKA,aAAa,CAAC,YAA8C;AAC1D,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]} | ||
| {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * just-bash Provider - Factory-based Implementation\n *\n * Local sandboxed bash execution using the just-bash package.\n * Provides a virtual filesystem and bash shell environment\n * without requiring any external services or containers.\n *\n * Features:\n * - Pure TypeScript bash interpreter (no real processes)\n * - In-memory virtual filesystem\n * - Python support via pyodide (optional)\n * - Shell command execution with 60+ built-in commands\n * - No authentication required - runs entirely locally\n */\n\nimport { Bash } from 'just-bash';\nimport type { BashExecResult, BashOptions } from 'just-bash';\nimport { defineProvider } from '@computesdk/provider';\nimport type {\n CodeResult,\n CommandResult,\n SandboxInfo,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from 'computesdk';\n\n/**\n * just-bash-specific configuration options\n */\nexport interface JustBashConfig {\n /** Enable Python support via pyodide (disabled by default) */\n python?: boolean;\n /** Initial files to populate in the virtual filesystem */\n files?: BashOptions['files'];\n /** Initial environment variables */\n env?: Record<string, string>;\n /** Working directory (defaults to /home/user) */\n cwd?: string;\n /**\n * Custom filesystem implementation.\n * Defaults to InMemoryFs. Use OverlayFs for copy-on-write over a real directory,\n * ReadWriteFs for direct disk access, or MountableFs to combine multiple filesystems.\n */\n fs?: BashOptions['fs'];\n /**\n * Custom commands to register alongside built-in commands.\n * Created with `defineCommand()` from just-bash.\n */\n customCommands?: BashOptions['customCommands'];\n /** Network configuration for commands like curl */\n network?: BashOptions['network'];\n}\n\n/** Internal sandbox state */\ninterface JustBashSandbox {\n bash: Bash;\n id: string;\n createdAt: Date;\n config: JustBashConfig;\n}\n\n/** Active sandboxes registry */\nconst activeSandboxes = new Map<string, JustBashSandbox>();\n\n/**\n * Create a just-bash provider instance using the factory pattern\n *\n * just-bash provides local sandboxed bash execution with:\n * - Virtual filesystem (in-memory)\n * - 60+ built-in commands (cat, grep, sed, awk, jq, etc.)\n * - Python support via pyodide\n * - No external dependencies or authentication required\n */\nconst _provider = defineProvider<JustBashSandbox, JustBashConfig>({\n name: 'just-bash',\n methods: {\n sandbox: {\n /**\n * Create a new just-bash sandbox\n */\n create: async (config: JustBashConfig, options?: CreateSandboxOptions) => {\n const sandboxId = options?.sandboxId || `just-bash-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n\n // Check if reconnecting to existing sandbox\n if (options?.sandboxId && activeSandboxes.has(options.sandboxId)) {\n const existing = activeSandboxes.get(options.sandboxId)!;\n return { sandbox: existing, sandboxId: existing.id };\n }\n\n const bash = new Bash({\n files: config.files,\n env: {\n ...config.env,\n ...options?.envs,\n },\n cwd: config.cwd || '/home/user',\n python: config.python ?? (options?.runtime === 'python'),\n fs: config.fs,\n customCommands: config.customCommands,\n network: config.network,\n });\n\n const sandbox: JustBashSandbox = {\n bash,\n id: sandboxId,\n createdAt: new Date(),\n config,\n };\n\n activeSandboxes.set(sandboxId, sandbox);\n return { sandbox, sandboxId };\n },\n\n /**\n * Get an existing just-bash sandbox by ID\n */\n getById: async (_config: JustBashConfig, sandboxId: string) => {\n const sandbox = activeSandboxes.get(sandboxId);\n if (!sandbox) return null;\n return { sandbox, sandboxId };\n },\n\n /**\n * List all active just-bash sandboxes\n */\n list: async (_config: JustBashConfig) => {\n return Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({\n sandbox,\n sandboxId,\n }));\n },\n\n /**\n * Destroy a just-bash sandbox\n */\n destroy: async (_config: JustBashConfig, sandboxId: string) => {\n activeSandboxes.delete(sandboxId);\n },\n\n /**\n * Execute code in the sandbox\n *\n * For Python: executes via the built-in python3 command (pyodide)\n * For Node/JS: wraps code in a bash script that evaluates it\n */\n runCode: async (sandbox: JustBashSandbox, code: string, runtime?: Runtime): Promise<CodeResult> => {\n const effectiveRuntime = runtime || (\n code.includes('print(') ||\n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n : 'node'\n );\n\n let result: BashExecResult;\n\n if (effectiveRuntime === 'python') {\n // Use python3 command (requires python: true in config)\n // Write code to a temp file and execute it to avoid quoting issues\n const tempFile = `/tmp/_computesdk_run_${Date.now()}.py`;\n await sandbox.bash.writeFile(tempFile, code);\n result = await sandbox.bash.exec(`python3 ${tempFile}`);\n } else {\n // For node/JS, execute as bash script\n // just-bash doesn't have a real Node.js runtime,\n // so we execute the code as a bash script\n const tempFile = `/tmp/_computesdk_run_${Date.now()}.sh`;\n await sandbox.bash.writeFile(tempFile, code);\n result = await sandbox.bash.exec(`bash ${tempFile}`);\n }\n\n const output = result.stderr\n ? `${result.stdout}${result.stdout && result.stderr ? '\\n' : ''}${result.stderr}`\n : result.stdout;\n\n return {\n output,\n exitCode: result.exitCode,\n language: effectiveRuntime,\n };\n },\n\n /**\n * Execute a shell command in the sandbox\n */\n runCommand: async (sandbox: JustBashSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const execOptions: { env?: Record<string, string>; cwd?: string } = {};\n\n if (options?.env && Object.keys(options.env).length > 0) {\n execOptions.env = options.env;\n }\n\n if (options?.cwd) {\n execOptions.cwd = options.cwd;\n }\n\n const result = await sandbox.bash.exec(\n command,\n Object.keys(execOptions).length > 0 ? execOptions : undefined\n );\n\n return {\n stdout: result.stdout || '',\n stderr: result.stderr || '',\n exitCode: result.exitCode,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime,\n };\n }\n },\n\n /**\n * Get sandbox information\n */\n getInfo: async (sandbox: JustBashSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'just-bash',\n runtime: sandbox.config.python ? 'python' : 'node',\n status: 'running',\n createdAt: sandbox.createdAt,\n timeout: 0, // No timeout - local execution\n metadata: {\n type: 'local',\n cwd: sandbox.bash.getCwd(),\n },\n };\n },\n\n /**\n * Get URL for a port - not supported for local execution\n */\n getUrl: async (_sandbox: JustBashSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(\n `just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`\n );\n },\n\n /**\n * Filesystem operations using the just-bash virtual filesystem\n */\n filesystem: {\n readFile: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<string> => {\n return sandbox.bash.readFile(path);\n },\n\n writeFile: async (sandbox: JustBashSandbox, path: string, content: string, _runCommand): Promise<void> => {\n // Ensure parent directory exists\n const parentDir = path.substring(0, path.lastIndexOf('/')) || '/';\n if (parentDir !== '/') {\n await sandbox.bash.exec(`mkdir -p ${parentDir}`);\n }\n await sandbox.bash.writeFile(path, content);\n },\n\n mkdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`mkdir -p ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<FileEntry[]> => {\n const result = await sandbox.bash.exec(`ls -la ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const entries: FileEntry[] = [];\n const lines = result.stdout.trim().split('\\n');\n\n for (const line of lines) {\n // Skip total line and empty lines\n if (!line || line.startsWith('total')) continue;\n\n const parts = line.split(/\\s+/);\n if (parts.length < 9) continue;\n\n const permissions = parts[0];\n const name = parts.slice(8).join(' ');\n\n // Skip . and ..\n if (name === '.' || name === '..') continue;\n\n entries.push({\n name,\n type: permissions.startsWith('d') ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4], 10) || 0,\n modified: new Date(),\n });\n }\n\n return entries;\n },\n\n exists: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<boolean> => {\n const result = await sandbox.bash.exec(`test -f ${path} || test -d ${path}`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`rm -rf ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n },\n },\n\n /**\n * Get the native JustBashSandbox instance for advanced usage\n */\n getInstance: (sandbox: JustBashSandbox): JustBashSandbox => {\n return sandbox;\n },\n },\n },\n});\n\nexport const justBash = (config: JustBashConfig = {}) => _provider(config);\n\n// Export types\nexport type { JustBashSandbox };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,uBAAqB;AAErB,sBAA+B;AA+C/B,IAAM,kBAAkB,oBAAI,IAA6B;AAWzD,IAAM,gBAAY,gCAAgD;AAAA,EAChE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA;A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;AAC3E,iBAAO,OAAO,aAAa;AAAA,QAC7B;AAAA,QAEA,QAAQ,OAAO,SAA0B,MAAc,gBAA+B;AACpF,gBAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,UAAU,IAAI,EAAE;AACvD,cAAI,OAAO,aAAa,GAAG;AACzB,kBAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,OAAO,MAAM,EAAE;AAAA,UAC9D;AAAA,QACF;AAAA,MACF;AAAA;AAAA;AAAA;AAAA,MAKA,aAAa,CAAC,YAA8C;AAC1D,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAEM,IAAM,WAAW,CAAC,SAAyB,CAAC,MAAM,UAAU,MAAM;","names":[]} |
+2
-1
@@ -5,3 +5,3 @@ // src/index.ts | ||
| var activeSandboxes = /* @__PURE__ */ new Map(); | ||
| var justBash = defineProvider({ | ||
| var _provider = defineProvider({ | ||
| name: "just-bash", | ||
@@ -209,2 +209,3 @@ methods: { | ||
| }); | ||
| var justBash = (config = {}) => _provider(config); | ||
| export { | ||
@@ -211,0 +212,0 @@ justBash |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * just-bash Provider - Factory-based Implementation\n *\n * Local sandboxed bash execution using the just-bash package.\n * Provides a virtual filesystem and bash shell environment\n * without requiring any external services or containers.\n *\n * Features:\n * - Pure TypeScript bash interpreter (no real processes)\n * - In-memory virtual filesystem\n * - Python support via pyodide (optional)\n * - Shell command execution with 60+ built-in commands\n * - No authentication required - runs entirely locally\n */\n\nimport { Bash } from 'just-bash';\nimport type { BashExecResult, BashOptions } from 'just-bash';\nimport { defineProvider } from '@computesdk/provider';\nimport type {\n CodeResult,\n CommandResult,\n SandboxInfo,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from 'computesdk';\n\n/**\n * just-bash-specific configuration options\n */\nexport interface JustBashConfig {\n /** Enable Python support via pyodide (disabled by default) */\n python?: boolean;\n /** Initial files to populate in the virtual filesystem */\n files?: BashOptions['files'];\n /** Initial environment variables */\n env?: Record<string, string>;\n /** Working directory (defaults to /home/user) */\n cwd?: string;\n /**\n * Custom filesystem implementation.\n * Defaults to InMemoryFs. Use OverlayFs for copy-on-write over a real directory,\n * ReadWriteFs for direct disk access, or MountableFs to combine multiple filesystems.\n */\n fs?: BashOptions['fs'];\n /**\n * Custom commands to register alongside built-in commands.\n * Created with `defineCommand()` from just-bash.\n */\n customCommands?: BashOptions['customCommands'];\n /** Network configuration for commands like curl */\n network?: BashOptions['network'];\n}\n\n/** Internal sandbox state */\ninterface JustBashSandbox {\n bash: Bash;\n id: string;\n createdAt: Date;\n config: JustBashConfig;\n}\n\n/** Active sandboxes registry */\nconst activeSandboxes = new Map<string, JustBashSandbox>();\n\n/**\n * Create a just-bash provider instance using the factory pattern\n *\n * just-bash provides local sandboxed bash execution with:\n * - Virtual filesystem (in-memory)\n * - 60+ built-in commands (cat, grep, sed, awk, jq, etc.)\n * - Python support via pyodide\n * - No external dependencies or authentication required\n */\nexport const justBash = defineProvider<JustBashSandbox, JustBashConfig>({\n name: 'just-bash',\n methods: {\n sandbox: {\n /**\n * Create a new just-bash sandbox\n */\n create: async (config: JustBashConfig, options?: CreateSandboxOptions) => {\n const sandboxId = options?.sandboxId || `just-bash-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n\n // Check if reconnecting to existing sandbox\n if (options?.sandboxId && activeSandboxes.has(options.sandboxId)) {\n const existing = activeSandboxes.get(options.sandboxId)!;\n return { sandbox: existing, sandboxId: existing.id };\n }\n\n const bash = new Bash({\n files: config.files,\n env: {\n ...config.env,\n ...options?.envs,\n },\n cwd: config.cwd || '/home/user',\n python: config.python ?? (options?.runtime === 'python'),\n fs: config.fs,\n customCommands: config.customCommands,\n network: config.network,\n });\n\n const sandbox: JustBashSandbox = {\n bash,\n id: sandboxId,\n createdAt: new Date(),\n config,\n };\n\n activeSandboxes.set(sandboxId, sandbox);\n return { sandbox, sandboxId };\n },\n\n /**\n * Get an existing just-bash sandbox by ID\n */\n getById: async (_config: JustBashConfig, sandboxId: string) => {\n const sandbox = activeSandboxes.get(sandboxId);\n if (!sandbox) return null;\n return { sandbox, sandboxId };\n },\n\n /**\n * List all active just-bash sandboxes\n */\n list: async (_config: JustBashConfig) => {\n return Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({\n sandbox,\n sandboxId,\n }));\n },\n\n /**\n * Destroy a just-bash sandbox\n */\n destroy: async (_config: JustBashConfig, sandboxId: string) => {\n activeSandboxes.delete(sandboxId);\n },\n\n /**\n * Execute code in the sandbox\n *\n * For Python: executes via the built-in python3 command (pyodide)\n * For Node/JS: wraps code in a bash script that evaluates it\n */\n runCode: async (sandbox: JustBashSandbox, code: string, runtime?: Runtime): Promise<CodeResult> => {\n const effectiveRuntime = runtime || (\n code.includes('print(') ||\n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n : 'node'\n );\n\n let result: BashExecResult;\n\n if (effectiveRuntime === 'python') {\n // Use python3 command (requires python: true in config)\n // Write code to a temp file and execute it to avoid quoting issues\n const tempFile = `/tmp/_computesdk_run_${Date.now()}.py`;\n await sandbox.bash.writeFile(tempFile, code);\n result = await sandbox.bash.exec(`python3 ${tempFile}`);\n } else {\n // For node/JS, execute as bash script\n // just-bash doesn't have a real Node.js runtime,\n // so we execute the code as a bash script\n const tempFile = `/tmp/_computesdk_run_${Date.now()}.sh`;\n await sandbox.bash.writeFile(tempFile, code);\n result = await sandbox.bash.exec(`bash ${tempFile}`);\n }\n\n const output = result.stderr\n ? `${result.stdout}${result.stdout && result.stderr ? '\\n' : ''}${result.stderr}`\n : result.stdout;\n\n return {\n output,\n exitCode: result.exitCode,\n language: effectiveRuntime,\n };\n },\n\n /**\n * Execute a shell command in the sandbox\n */\n runCommand: async (sandbox: JustBashSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const execOptions: { env?: Record<string, string>; cwd?: string } = {};\n\n if (options?.env && Object.keys(options.env).length > 0) {\n execOptions.env = options.env;\n }\n\n if (options?.cwd) {\n execOptions.cwd = options.cwd;\n }\n\n const result = await sandbox.bash.exec(\n command,\n Object.keys(execOptions).length > 0 ? execOptions : undefined\n );\n\n return {\n stdout: result.stdout || '',\n stderr: result.stderr || '',\n exitCode: result.exitCode,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime,\n };\n }\n },\n\n /**\n * Get sandbox information\n */\n getInfo: async (sandbox: JustBashSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'just-bash',\n runtime: sandbox.config.python ? 'python' : 'node',\n status: 'running',\n createdAt: sandbox.createdAt,\n timeout: 0, // No timeout - local execution\n metadata: {\n type: 'local',\n cwd: sandbox.bash.getCwd(),\n },\n };\n },\n\n /**\n * Get URL for a port - not supported for local execution\n */\n getUrl: async (_sandbox: JustBashSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(\n `just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`\n );\n },\n\n /**\n * Filesystem operations using the just-bash virtual filesystem\n */\n filesystem: {\n readFile: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<string> => {\n return sandbox.bash.readFile(path);\n },\n\n writeFile: async (sandbox: JustBashSandbox, path: string, content: string, _runCommand): Promise<void> => {\n // Ensure parent directory exists\n const parentDir = path.substring(0, path.lastIndexOf('/')) || '/';\n if (parentDir !== '/') {\n await sandbox.bash.exec(`mkdir -p ${parentDir}`);\n }\n await sandbox.bash.writeFile(path, content);\n },\n\n mkdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`mkdir -p ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<FileEntry[]> => {\n const result = await sandbox.bash.exec(`ls -la ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const entries: FileEntry[] = [];\n const lines = result.stdout.trim().split('\\n');\n\n for (const line of lines) {\n // Skip total line and empty lines\n if (!line || line.startsWith('total')) continue;\n\n const parts = line.split(/\\s+/);\n if (parts.length < 9) continue;\n\n const permissions = parts[0];\n const name = parts.slice(8).join(' ');\n\n // Skip . and ..\n if (name === '.' || name === '..') continue;\n\n entries.push({\n name,\n type: permissions.startsWith('d') ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4], 10) || 0,\n modified: new Date(),\n });\n }\n\n return entries;\n },\n\n exists: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<boolean> => {\n const result = await sandbox.bash.exec(`test -f ${path} || test -d ${path}`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`rm -rf ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n },\n },\n\n /**\n * Get the native JustBashSandbox instance for advanced usage\n */\n getInstance: (sandbox: JustBashSandbox): JustBashSandbox => {\n return sandbox;\n },\n },\n },\n});\n\n// Export types\nexport type { JustBashSandbox };\n"],"mappings":";AAeA,SAAS,YAAY;AAErB,SAAS,sBAAsB;AA+C/B,IAAM,kBAAkB,oBAAI,IAA6B;AAWlD,IAAM,WAAW,eAAgD;AAAA,EACtE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA;AAAA;AAAA,MAIP,QAAQ,OAAO,QAAwB,YAAmC;AACxE,cAAM,YAAY,SAAS,aAAa,aAAa,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EA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IAAI,EAAE;AACvD,cAAI,OAAO,aAAa,GAAG;AACzB,kBAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,OAAO,MAAM,EAAE;AAAA,UAC9D;AAAA,QACF;AAAA,MACF;AAAA;AAAA;AAAA;AAAA,MAKA,aAAa,CAAC,YAA8C;AAC1D,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]} | ||
| {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * just-bash Provider - Factory-based Implementation\n *\n * Local sandboxed bash execution using the just-bash package.\n * Provides a virtual filesystem and bash shell environment\n * without requiring any external services or containers.\n *\n * Features:\n * - Pure TypeScript bash interpreter (no real processes)\n * - In-memory virtual filesystem\n * - Python support via pyodide (optional)\n * - Shell command execution with 60+ built-in commands\n * - No authentication required - runs entirely locally\n */\n\nimport { Bash } from 'just-bash';\nimport type { BashExecResult, BashOptions } from 'just-bash';\nimport { defineProvider } from '@computesdk/provider';\nimport type {\n CodeResult,\n CommandResult,\n SandboxInfo,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from 'computesdk';\n\n/**\n * just-bash-specific configuration options\n */\nexport interface JustBashConfig {\n /** Enable Python support via pyodide (disabled by default) */\n python?: boolean;\n /** Initial files to populate in the virtual filesystem */\n files?: BashOptions['files'];\n /** Initial environment variables */\n env?: Record<string, string>;\n /** Working directory (defaults to /home/user) */\n cwd?: string;\n /**\n * Custom filesystem implementation.\n * Defaults to InMemoryFs. Use OverlayFs for copy-on-write over a real directory,\n * ReadWriteFs for direct disk access, or MountableFs to combine multiple filesystems.\n */\n fs?: BashOptions['fs'];\n /**\n * Custom commands to register alongside built-in commands.\n * Created with `defineCommand()` from just-bash.\n */\n customCommands?: BashOptions['customCommands'];\n /** Network configuration for commands like curl */\n network?: BashOptions['network'];\n}\n\n/** Internal sandbox state */\ninterface JustBashSandbox {\n bash: Bash;\n id: string;\n createdAt: Date;\n config: JustBashConfig;\n}\n\n/** Active sandboxes registry */\nconst activeSandboxes = new Map<string, JustBashSandbox>();\n\n/**\n * Create a just-bash provider instance using the factory pattern\n *\n * just-bash provides local sandboxed bash execution with:\n * - Virtual filesystem (in-memory)\n * - 60+ built-in commands (cat, grep, sed, awk, jq, etc.)\n * - Python support via pyodide\n * - No external dependencies or authentication required\n */\nconst _provider = defineProvider<JustBashSandbox, JustBashConfig>({\n name: 'just-bash',\n methods: {\n sandbox: {\n /**\n * Create a new just-bash sandbox\n */\n create: async (config: JustBashConfig, options?: CreateSandboxOptions) => {\n const sandboxId = options?.sandboxId || `just-bash-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n\n // Check if reconnecting to existing sandbox\n if (options?.sandboxId && activeSandboxes.has(options.sandboxId)) {\n const existing = activeSandboxes.get(options.sandboxId)!;\n return { sandbox: existing, sandboxId: existing.id };\n }\n\n const bash = new Bash({\n files: config.files,\n env: {\n ...config.env,\n ...options?.envs,\n },\n cwd: config.cwd || '/home/user',\n python: config.python ?? (options?.runtime === 'python'),\n fs: config.fs,\n customCommands: config.customCommands,\n network: config.network,\n });\n\n const sandbox: JustBashSandbox = {\n bash,\n id: sandboxId,\n createdAt: new Date(),\n config,\n };\n\n activeSandboxes.set(sandboxId, sandbox);\n return { sandbox, sandboxId };\n },\n\n /**\n * Get an existing just-bash sandbox by ID\n */\n getById: async (_config: JustBashConfig, sandboxId: string) => {\n const sandbox = activeSandboxes.get(sandboxId);\n if (!sandbox) return null;\n return { sandbox, sandboxId };\n },\n\n /**\n * List all active just-bash sandboxes\n */\n list: async (_config: JustBashConfig) => {\n return Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({\n sandbox,\n sandboxId,\n }));\n },\n\n /**\n * Destroy a just-bash sandbox\n */\n destroy: async (_config: JustBashConfig, sandboxId: string) => {\n activeSandboxes.delete(sandboxId);\n },\n\n /**\n * Execute code in the sandbox\n *\n * For Python: executes via the built-in python3 command (pyodide)\n * For Node/JS: wraps code in a bash script that evaluates it\n */\n runCode: async (sandbox: JustBashSandbox, code: string, runtime?: Runtime): Promise<CodeResult> => {\n const effectiveRuntime = runtime || (\n code.includes('print(') ||\n code.includes('import ') ||\n code.includes('def ') ||\n code.includes('sys.') ||\n code.includes('json.') ||\n code.includes('__') ||\n code.includes('f\"') ||\n code.includes(\"f'\") ||\n code.includes('raise ')\n ? 'python'\n : 'node'\n );\n\n let result: BashExecResult;\n\n if (effectiveRuntime === 'python') {\n // Use python3 command (requires python: true in config)\n // Write code to a temp file and execute it to avoid quoting issues\n const tempFile = `/tmp/_computesdk_run_${Date.now()}.py`;\n await sandbox.bash.writeFile(tempFile, code);\n result = await sandbox.bash.exec(`python3 ${tempFile}`);\n } else {\n // For node/JS, execute as bash script\n // just-bash doesn't have a real Node.js runtime,\n // so we execute the code as a bash script\n const tempFile = `/tmp/_computesdk_run_${Date.now()}.sh`;\n await sandbox.bash.writeFile(tempFile, code);\n result = await sandbox.bash.exec(`bash ${tempFile}`);\n }\n\n const output = result.stderr\n ? `${result.stdout}${result.stdout && result.stderr ? '\\n' : ''}${result.stderr}`\n : result.stdout;\n\n return {\n output,\n exitCode: result.exitCode,\n language: effectiveRuntime,\n };\n },\n\n /**\n * Execute a shell command in the sandbox\n */\n runCommand: async (sandbox: JustBashSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const execOptions: { env?: Record<string, string>; cwd?: string } = {};\n\n if (options?.env && Object.keys(options.env).length > 0) {\n execOptions.env = options.env;\n }\n\n if (options?.cwd) {\n execOptions.cwd = options.cwd;\n }\n\n const result = await sandbox.bash.exec(\n command,\n Object.keys(execOptions).length > 0 ? execOptions : undefined\n );\n\n return {\n stdout: result.stdout || '',\n stderr: result.stderr || '',\n exitCode: result.exitCode,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime,\n };\n }\n },\n\n /**\n * Get sandbox information\n */\n getInfo: async (sandbox: JustBashSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'just-bash',\n runtime: sandbox.config.python ? 'python' : 'node',\n status: 'running',\n createdAt: sandbox.createdAt,\n timeout: 0, // No timeout - local execution\n metadata: {\n type: 'local',\n cwd: sandbox.bash.getCwd(),\n },\n };\n },\n\n /**\n * Get URL for a port - not supported for local execution\n */\n getUrl: async (_sandbox: JustBashSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(\n `just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`\n );\n },\n\n /**\n * Filesystem operations using the just-bash virtual filesystem\n */\n filesystem: {\n readFile: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<string> => {\n return sandbox.bash.readFile(path);\n },\n\n writeFile: async (sandbox: JustBashSandbox, path: string, content: string, _runCommand): Promise<void> => {\n // Ensure parent directory exists\n const parentDir = path.substring(0, path.lastIndexOf('/')) || '/';\n if (parentDir !== '/') {\n await sandbox.bash.exec(`mkdir -p ${parentDir}`);\n }\n await sandbox.bash.writeFile(path, content);\n },\n\n mkdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`mkdir -p ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<FileEntry[]> => {\n const result = await sandbox.bash.exec(`ls -la ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const entries: FileEntry[] = [];\n const lines = result.stdout.trim().split('\\n');\n\n for (const line of lines) {\n // Skip total line and empty lines\n if (!line || line.startsWith('total')) continue;\n\n const parts = line.split(/\\s+/);\n if (parts.length < 9) continue;\n\n const permissions = parts[0];\n const name = parts.slice(8).join(' ');\n\n // Skip . and ..\n if (name === '.' || name === '..') continue;\n\n entries.push({\n name,\n type: permissions.startsWith('d') ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4], 10) || 0,\n modified: new Date(),\n });\n }\n\n return entries;\n },\n\n exists: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<boolean> => {\n const result = await sandbox.bash.exec(`test -f ${path} || test -d ${path}`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`rm -rf ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n },\n },\n\n /**\n * Get the native JustBashSandbox instance for advanced usage\n */\n getInstance: (sandbox: JustBashSandbox): JustBashSandbox => {\n return sandbox;\n },\n },\n },\n});\n\nexport const justBash = (config: JustBashConfig = {}) => _provider(config);\n\n// Export types\nexport type { JustBashSandbox };\n"],"mappings":";AAeA,SAAS,YAAY;AAErB,SAAS,sBAAsB;AA+C/B,IAAM,kBAAkB,oBAAI,IAA6B;AAWzD,IAAM,YAAY,eAAgD;AAAA,EAChE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA;AAAA;AAAA,MAIP,QAAQ,OAAO,QAAwB,YAAmC;AACxE,cAAM,YAAY,SAAS,aAAa,aAAa,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;AAGzG,YAAI,SAAS,aAAa,gBAAgB,IAAI,QAAQ,SAAS,GAAG;AAChE,gBAAM,WAAW,gBAAgB,IAAI,QAAQ,SAAS;AACtD,iBAAO,EAAE,SAAS,UAAU,WAAW,SAAS,GAAG;AAAA,QACrD;AAEA,cAAM,OAAO,IAAI,KAAK;AAAA,UACpB,OAAO,OAAO;AAAA,UACd,KAAK;AAAA,YACH,GAAG,OAAO;AAAA,YACV,GAAG,SAAS;AAAA,UACd;AAAA,UACA,KAAK,OAAO,OAAO;AAAA,UACnB,QAAQ,OAAO,UAAW,SAAS,YAAY;AAAA,UAC/C,I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- local sandboxed bash execution with virtual filesystem", | ||
@@ -21,4 +21,4 @@ "author": "ComputeSDK", | ||
| "dependencies": { | ||
| "@computesdk/provider": "1.0.28", | ||
| "computesdk": "2.3.0" | ||
| "computesdk": "2.3.0", | ||
| "@computesdk/provider": "1.0.28" | ||
| }, | ||
@@ -25,0 +25,0 @@ "peerDependencies": { |
64100
-0.46%483
-1.43%