just-bash 2.15.0-executor.0 → 2.15.1-executor.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Bash.d.ts CHANGED
@@ -294,6 +294,8 @@ export declare class Bash {
294
294
  private executorApproval?;
295
295
  private executorSDK?;
296
296
  private executorInitPromise?;
297
+ /** When SDK setup is configured, js-exec routes execution through this */
298
+ private executorExecFn?;
297
299
  private transformPlugins;
298
300
  private state;
299
301
  constructor(options?: BashOptions);
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ import{a as F,b as W}from"./chunk-MNMRGJJM.js";import"./chunk-4OALHZXB.js";import"./chunk-MY5PY2PL.js";import"./chunk-LIYVQA3X.js";import{a as T,b as E}from"./chunk-OOJCYVYF.js";import{a as M}from"./chunk-4PRVMER6.js";import{b as L}from"./chunk-YU6OGPZR.js";import{a as O,b as k}from"./chunk-RLNOQILG.js";import{a as j}from"./chunk-4VDEBYW7.js";import{b as B}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";import{AsyncLocalStorage as H}from"node:async_hooks";import{randomBytes as q}from"node:crypto";import{fileURLToPath as N}from"node:url";import{Worker as D}from"node:worker_threads";var _=1e4,I=6e4,R=new H,J=`js-exec - Sandboxed JavaScript/TypeScript runtime with Node.js-compatible APIs
3
+
4
+ Usage: js-exec [OPTIONS] [-c CODE | FILE] [ARGS...]
5
+
6
+ Options:
7
+ -c CODE Execute inline code
8
+ -m, --module Enable ES module mode (import/export)
9
+ --strip-types Strip TypeScript type annotations
10
+ --version, -V Show version
11
+ --help Show this help
12
+
13
+ Examples:
14
+ js-exec -c "console.log(1 + 2)"
15
+ js-exec script.js
16
+ js-exec app.ts
17
+ echo 'console.log("hello")' | js-exec
18
+
19
+ File Extension Auto-Detection:
20
+ .js script mode (module mode if top-level await detected)
21
+ .mjs ES module mode
22
+ .ts, .mts ES module mode + TypeScript stripping
23
+
24
+ Node.js Compatibility:
25
+ Code written for Node.js largely works here. Both require and import
26
+ are supported, the node: prefix works, and standard globals like process,
27
+ console, and fetch are available. All I/O is synchronous.
28
+
29
+ Available modules:
30
+ fs, path, child_process, process, console,
31
+ os, url, assert, util, events, buffer, stream,
32
+ string_decoder, querystring
33
+
34
+ fs (global, require('fs'), or import from 'node:fs'):
35
+ readFileSync, writeFileSync, appendFileSync, copyFileSync, renameSync
36
+ readdirSync, mkdirSync, rmSync, unlinkSync, rmdirSync
37
+ statSync, lstatSync, existsSync, realpathSync, chmodSync
38
+ symlinkSync, readlinkSync, readFileBuffer
39
+ fs.promises.readFile, fs.promises.writeFile, fs.promises.access, ...
40
+
41
+ path: join, resolve, dirname, basename, extname, normalize,
42
+ relative, isAbsolute, parse, format, sep, delimiter
43
+
44
+ child_process:
45
+ execSync(cmd) throws on non-zero exit, returns stdout
46
+ spawnSync(cmd, args) returns { stdout, stderr, status }
47
+
48
+ process (also global): argv, cwd(), exit(), env, platform, arch,
49
+ version, versions
50
+
51
+ os: platform(), arch(), homedir(), tmpdir(), type(), hostname(),
52
+ EOL, cpus(), endianness()
53
+
54
+ url: URL, URLSearchParams, parse(), format()
55
+
56
+ assert: ok(), equal(), strictEqual(), deepEqual(), throws(),
57
+ doesNotThrow(), fail()
58
+
59
+ util: format(), inspect(), promisify(), types, inherits()
60
+
61
+ events: EventEmitter (on, once, emit, off, removeListener, ...)
62
+
63
+ buffer: Buffer.from(), Buffer.alloc(), Buffer.concat(),
64
+ Buffer.isBuffer(), toString(), slice(), equals()
65
+
66
+ stream: Readable, Writable, Duplex, Transform, PassThrough, pipeline
67
+
68
+ string_decoder: StringDecoder (write, end)
69
+
70
+ querystring: parse(), stringify(), escape(), unescape()
71
+
72
+ Other Globals:
73
+ console log (stdout), error/warn (stderr)
74
+ fetch(url, opts) HTTP; returns Promise<Response> (Web Fetch API)
75
+ URL, URLSearchParams, Headers, Request, Response
76
+ Buffer Buffer.from(), Buffer.alloc(), etc.
77
+
78
+ Not Available:
79
+ http, https, net, tls, crypto, zlib, dns, cluster, worker_threads,
80
+ vm, v8, readline, and other Node.js built-in modules that require
81
+ native bindings. Use fetch() for HTTP requests.
82
+
83
+ Limits:
84
+ Memory: 64 MB per execution
85
+ Timeout: 10 s (60 s with network; configurable via maxJsTimeoutMs)
86
+ Engine: QuickJS (compiled to WebAssembly)
87
+ `;function z(t){let e={code:null,scriptFile:null,showVersion:!1,scriptArgs:[],isModule:!1,stripTypes:!1};if(t.length===0)return e;for(let r=0;r<t.length;r++){let o=t[r];if(o==="-m"||o==="--module"){e.isModule=!0;continue}if(o==="--strip-types"){e.stripTypes=!0;continue}if(o==="-c")return r+1>=t.length?{stdout:"",stderr:`js-exec: option requires an argument -- 'c'
88
+ `,exitCode:2}:(e.code=t[r+1],e.scriptArgs=t.slice(r+2),e);if(o==="--version"||o==="-V")return e.showVersion=!0,e;if(o.startsWith("-")&&o!=="-"&&o!=="--")return{stdout:"",stderr:`js-exec: unrecognized option '${o}'
89
+ `,exitCode:2};if(o==="--")return r+1<t.length&&(e.scriptFile=t[r+1],e.scriptArgs=t.slice(r+2)),e;if(!o.startsWith("-"))return e.scriptFile=o,e.scriptArgs=t.slice(r+1),e}return e}var i=null,b=null,a=[],n=null,V=N(new URL("./worker.js",import.meta.url));function w(){for(;a.length>0&&a[0].canceled;)a.shift();if(n||a.length===0)return;let t=a.shift();if(!t)return;n=t,G().postMessage(n.input)}function Q(t,e){if(!t||typeof t!="object")return{success:!1,error:"Malformed worker response"};let r=t;if(typeof r.protocolToken!="string"||r.protocolToken!==e)return{success:!1,error:"Malformed worker response: invalid protocol token"};if(typeof r.success!="boolean")return{success:!1,error:"Malformed worker response: missing success flag"};if(r.success){let o={success:!0},s=t;return typeof s.executorResult=="string"&&(o.executorResult=s.executorResult),Array.isArray(s.executorLogs)&&(o.executorLogs=s.executorLogs),o}return{success:!1,error:typeof r.error=="string"&&r.error.length>0?r.error:"Worker execution failed"}}function G(){if(b&&(E(b),b=null),i)return i;let t=L.runTrusted(()=>new D(V));return i=t,t.on("message",e=>{if(i===t){if(n){let r=Q(e,n.input.protocolToken);n.resolve(r),n=null}a.length>0?w():K()}}),t.on("error",e=>{if(i===t){if(n){let r=k(j(e));n.resolve({success:!1,error:r}),n=null}for(let r of a)r.resolve({success:!1,error:"Worker crashed"});a.length=0,i=null}}),t.on("exit",()=>{i===t&&(i=null,n&&(n.resolve({success:!1,error:"Worker exited unexpectedly"}),n=null),a.length>0&&w())}),t}function K(){b=T(()=>{i&&!n&&a.length===0&&(i.terminate(),i=null)},5e3)}async function X(t,e,r,o=[],s,d,f){return R.getStore()?{stdout:"",stderr:`js-exec: recursive invocation is not supported
90
+ `,exitCode:1}:Y(t,e,r,o,s,d,f)}async function Y(t,e,r,o=[],s,d,f){let y=F(),u=e.exec,h=u?(m,P)=>R.run(!0,()=>u(m,P)):void 0,l=new W(y,e.fs,e.cwd,"js-exec",e.fetch,e.limits?.maxOutputSize??0,h,e.executorInvokeTool),x=e.limits?.maxJsTimeoutMs??_,g=e.fetch?Math.max(x,I):x,c={protocolToken:q(16).toString("hex"),sharedBuffer:y,jsCode:t,cwd:e.cwd,env:M(e.env),args:o,scriptPath:r,bootstrapCode:s,isModule:d,stripTypes:f,timeoutMs:g,hasExecutorTools:e.executorInvokeTool!==void 0},A,U=new Promise(m=>{A=m}),S={input:c,resolve:()=>{}},$=T(()=>{if(n===S){let m=i;m&&(i=null,m.terminate()),n=null,w()}else S.canceled=!0,n||w();S.resolve({success:!1,error:`Execution timeout: exceeded ${g}ms limit`})},g);S.resolve=m=>{E($),A(m)},a.push(S),w();let[v,C]=await Promise.all([l.run(g),U.catch(m=>({success:!1,error:k(j(m))}))]);return!C.success&&C.error?{stdout:v.stdout,stderr:`${v.stderr}js-exec: ${k(C.error)}
91
+ `,exitCode:v.exitCode||1}:v}async function de(t,e,r){if(R.getStore())return{result:null,error:"js-exec: recursive invocation is not supported"};let o=F(),s=new W(o,e.fs,e.cwd,"js-exec",e.fetch,e.limits?.maxOutputSize??0,void 0,r),d=e.limits?.maxJsTimeoutMs??_,f=e.fetch?Math.max(d,I):d,u={protocolToken:q(16).toString("hex"),sharedBuffer:o,jsCode:t,cwd:e.cwd,env:M(e.env),args:[],executorMode:!0,timeoutMs:f},h,l=new Promise(c=>{h=c}),x={input:u,resolve:()=>{}},g=T(()=>{if(n===x){let c=i;c&&(i=null,c.terminate()),n=null,w()}else x.canceled=!0,n||w();x.resolve({success:!1,error:`Execution timeout: exceeded ${f}ms limit`})},f);x.resolve=c=>{E(g),h(c)},a.push(x),w();let[,p]=await Promise.all([s.run(f),l.catch(c=>({success:!1,error:k(j(c))}))]);if("executorLogs"in p||"executorResult"in p){if(p.error)return{result:null,error:p.error,logs:p.executorLogs};let c;if(p.executorResult!==void 0)try{c=JSON.parse(p.executorResult)}catch{c=p.executorResult}return{result:c??null,logs:p.executorLogs}}return{result:null,error:p.error||"Unknown execution error"}}var fe={name:"js-exec",async execute(t,e){if(B(t))return{stdout:J,stderr:"",exitCode:0};let r=z(t);if("exitCode"in r)return r;if(r.showVersion)return{stdout:`QuickJS (quickjs-emscripten)
92
+ `,stderr:"",exitCode:0};let o,s;if(r.code!==null)o=r.code,s="-c";else if(r.scriptFile!==null){let u=e.fs.resolvePath(e.cwd,r.scriptFile);if(!await e.fs.exists(u))return{stdout:"",stderr:`js-exec: can't open file '${r.scriptFile}': No such file or directory
93
+ `,exitCode:2};try{o=await e.fs.readFile(u),s=u}catch(h){return{stdout:"",stderr:`js-exec: can't open file '${r.scriptFile}': ${O(h.message)}
94
+ `,exitCode:2}}}else if(e.stdin.trim())o=e.stdin,s="<stdin>";else return{stdout:"",stderr:`js-exec: no input provided (use -c CODE or provide a script file)
95
+ `,exitCode:2};let d=r.isModule,f=r.stripTypes;if(s&&s!=="-c"&&s!=="<stdin>"&&((s.endsWith(".mjs")||s.endsWith(".mts")||s.endsWith(".ts"))&&(d=!0),(s.endsWith(".ts")||s.endsWith(".mts"))&&(f=!0)),!d&&/\bawait\s+[\w([`]/.test(o)&&(d=!0),e.executorExecFn){let u=await e.executorExecFn(o),h=u.logs??[];return{stdout:h.filter(l=>!l.startsWith("[error]")&&!l.startsWith("[warn]")).map(l=>`${l.replace(/^\[(log|info|debug)\] /,"")}
96
+ `).join(""),stderr:u.error?`${u.error}
97
+ `:h.filter(l=>l.startsWith("[error]")||l.startsWith("[warn]")).map(l=>`${l.replace(/^\[(error|warn)\] /,"")}
98
+ `).join(""),exitCode:u.error?1:0}}let y=e.jsBootstrapCode;return X(o,e,s,r.scriptArgs,y,d,f)}},pe={name:"node",async execute(){return{stdout:"",stderr:`node: this sandbox uses js-exec instead of node
99
+
100
+ ${J}`,exitCode:1}}};export{de as executeForExecutor,fe as jsExecCommand,pe as nodeStubCommand};