just-bash 2.6.0 → 2.7.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/README.md CHANGED
@@ -283,7 +283,7 @@ pnpm shell --no-network
283
283
 
284
284
  ### Data Processing
285
285
 
286
- `jq` (JSON), `sqlite3` (SQLite), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
286
+ `jq` (JSON), `python3`/`python` (Python via Pyodide), `sqlite3` (SQLite), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
287
287
 
288
288
  ### Compression & Archives
289
289
 
package/dist/AGENTS.md CHANGED
@@ -66,7 +66,7 @@ const result = await bash.exec("cat input.txt | grep pattern");
66
66
 
67
67
  **Text processing**: `awk`, `cat`, `column`, `comm`, `cut`, `egrep`, `expand`, `fgrep`, `fold`, `grep`, `head`, `join`, `nl`, `paste`, `rev`, `rg`, `sed`, `sort`, `strings`, `tac`, `tail`, `tr`, `unexpand`, `uniq`, `wc`, `xargs`
68
68
 
69
- **Data processing**: `jq` (JSON), `sqlite3` (SQLite), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
69
+ **Data processing**: `jq` (JSON), `python3`/`python` (Python via Pyodide), `sqlite3` (SQLite), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
70
70
 
71
71
  **File operations**: `basename`, `chmod`, `cp`, `dirname`, `du`, `file`, `find`, `ln`, `ls`, `mkdir`, `mv`, `od`, `pwd`, `readlink`, `rm`, `rmdir`, `split`, `stat`, `touch`, `tree`
72
72
 
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import{a as y,b as D}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";import{fileURLToPath as x}from"node:url";import{Worker as L}from"node:worker_threads";var a={NOOP:0,READ_FILE:1,WRITE_FILE:2,STAT:3,READDIR:4,MKDIR:5,RM:6,EXISTS:7,APPEND_FILE:8,SYMLINK:9,READLINK:10,LSTAT:11,CHMOD:12,REALPATH:13,WRITE_STDOUT:100,WRITE_STDERR:101,EXIT:102,HTTP_REQUEST:200},n={PENDING:0,READY:1,SUCCESS:2,ERROR:3},u={NONE:0,NOT_FOUND:1,IS_DIRECTORY:2,NOT_DIRECTORY:3,EXISTS:4,PERMISSION_DENIED:5,INVALID_PATH:6,IO_ERROR:7,TIMEOUT:8,NETWORK_ERROR:9,NETWORK_NOT_CONFIGURED:10},i={OP_CODE:0,STATUS:4,PATH_LENGTH:8,DATA_LENGTH:12,RESULT_LENGTH:16,ERROR_CODE:20,FLAGS:24,MODE:28,PATH_BUFFER:32,DATA_BUFFER:4128},p={CONTROL_REGION:32,PATH_BUFFER:4096,DATA_BUFFER:1048576,TOTAL:1052704},R={NONE:0,RECURSIVE:1,FORCE:2,MKDIR_RECURSIVE:1},h={IS_FILE:0,IS_DIRECTORY:1,IS_SYMLINK:2,MODE:4,SIZE:8,MTIME:16,TOTAL:24};function C(){return new SharedArrayBuffer(p.TOTAL)}var w=class{int32View;uint8View;dataView;constructor(t){this.int32View=new Int32Array(t),this.uint8View=new Uint8Array(t),this.dataView=new DataView(t)}getOpCode(){return Atomics.load(this.int32View,i.OP_CODE/4)}setOpCode(t){Atomics.store(this.int32View,i.OP_CODE/4,t)}getStatus(){return Atomics.load(this.int32View,i.STATUS/4)}setStatus(t){Atomics.store(this.int32View,i.STATUS/4,t)}getPathLength(){return Atomics.load(this.int32View,i.PATH_LENGTH/4)}setPathLength(t){Atomics.store(this.int32View,i.PATH_LENGTH/4,t)}getDataLength(){return Atomics.load(this.int32View,i.DATA_LENGTH/4)}setDataLength(t){Atomics.store(this.int32View,i.DATA_LENGTH/4,t)}getResultLength(){return Atomics.load(this.int32View,i.RESULT_LENGTH/4)}setResultLength(t){Atomics.store(this.int32View,i.RESULT_LENGTH/4,t)}getErrorCode(){return Atomics.load(this.int32View,i.ERROR_CODE/4)}setErrorCode(t){Atomics.store(this.int32View,i.ERROR_CODE/4,t)}getFlags(){return Atomics.load(this.int32View,i.FLAGS/4)}setFlags(t){Atomics.store(this.int32View,i.FLAGS/4,t)}getMode(){return Atomics.load(this.int32View,i.MODE/4)}setMode(t){Atomics.store(this.int32View,i.MODE/4,t)}getPath(){let t=this.getPathLength(),e=this.uint8View.slice(i.PATH_BUFFER,i.PATH_BUFFER+t);return new TextDecoder().decode(e)}setPath(t){let e=new TextEncoder().encode(t);if(e.length>p.PATH_BUFFER)throw new Error(`Path too long: ${e.length} > ${p.PATH_BUFFER}`);this.uint8View.set(e,i.PATH_BUFFER),this.setPathLength(e.length)}getData(){let t=this.getDataLength();return this.uint8View.slice(i.DATA_BUFFER,i.DATA_BUFFER+t)}setData(t){if(t.length>p.DATA_BUFFER)throw new Error(`Data too large: ${t.length} > ${p.DATA_BUFFER}`);this.uint8View.set(t,i.DATA_BUFFER),this.setDataLength(t.length)}getDataAsString(){let t=this.getData();return new TextDecoder().decode(t)}setDataFromString(t){let e=new TextEncoder().encode(t);this.setData(e)}getResult(){let t=this.getResultLength();return this.uint8View.slice(i.DATA_BUFFER,i.DATA_BUFFER+t)}setResult(t){if(t.length>p.DATA_BUFFER)throw new Error(`Result too large: ${t.length} > ${p.DATA_BUFFER}`);this.uint8View.set(t,i.DATA_BUFFER),this.setResultLength(t.length)}getResultAsString(){let t=this.getResult();return new TextDecoder().decode(t)}setResultFromString(t){let e=new TextEncoder().encode(t);this.setResult(e)}encodeStat(t){this.uint8View[i.DATA_BUFFER+h.IS_FILE]=t.isFile?1:0,this.uint8View[i.DATA_BUFFER+h.IS_DIRECTORY]=t.isDirectory?1:0,this.uint8View[i.DATA_BUFFER+h.IS_SYMLINK]=t.isSymbolicLink?1:0,this.dataView.setInt32(i.DATA_BUFFER+h.MODE,t.mode,!0);let e=Math.min(t.size,Number.MAX_SAFE_INTEGER);this.dataView.setFloat64(i.DATA_BUFFER+h.SIZE,e,!0),this.dataView.setFloat64(i.DATA_BUFFER+h.MTIME,t.mtime.getTime(),!0),this.setResultLength(h.TOTAL)}decodeStat(){return{isFile:this.uint8View[i.DATA_BUFFER+h.IS_FILE]===1,isDirectory:this.uint8View[i.DATA_BUFFER+h.IS_DIRECTORY]===1,isSymbolicLink:this.uint8View[i.DATA_BUFFER+h.IS_SYMLINK]===1,mode:this.dataView.getInt32(i.DATA_BUFFER+h.MODE,!0),size:this.dataView.getFloat64(i.DATA_BUFFER+h.SIZE,!0),mtime:new Date(this.dataView.getFloat64(i.DATA_BUFFER+h.MTIME,!0))}}waitForReady(t){return Atomics.wait(this.int32View,i.STATUS/4,n.PENDING,t)}waitForReadyAsync(t){return Atomics.waitAsync(this.int32View,i.STATUS/4,n.PENDING,t)}async waitUntilReady(t){let e=Date.now();for(;;){let s=this.getStatus();if(s===n.READY)return!0;let o=Date.now()-e;if(o>=t)return!1;let l=t-o,d=Atomics.waitAsync(this.int32View,i.STATUS/4,s,l);if(d.async&&await d.value==="timed-out")return!1}}waitForResult(t){return Atomics.wait(this.int32View,i.STATUS/4,n.READY,t)}notify(){return Atomics.notify(this.int32View,i.STATUS/4)}reset(){this.setOpCode(a.NOOP),this.setStatus(n.PENDING),this.setPathLength(0),this.setDataLength(0),this.setResultLength(0),this.setErrorCode(u.NONE),this.setFlags(R.NONE),this.setMode(0)}};var A=class{fs;cwd;secureFetch;protocol;running=!1;output={stdout:"",stderr:"",exitCode:0};constructor(t,e,s,o=void 0){this.fs=e,this.cwd=s,this.secureFetch=o,this.protocol=new w(t)}async run(t){this.running=!0;let e=Date.now();for(;this.running;){let s=Date.now()-e;if(s>=t){this.output.stderr+=`
3
+ python3: execution timeout exceeded
4
+ `,this.output.exitCode=124;break}let o=t-s;if(!await this.protocol.waitUntilReady(o)){this.output.stderr+=`
5
+ python3: execution timeout exceeded
6
+ `,this.output.exitCode=124;break}let d=this.protocol.getOpCode();await this.handleOperation(d),this.protocol.notify()}return this.output}stop(){this.running=!1}async handleOperation(t){try{switch(t){case a.READ_FILE:await this.handleReadFile();break;case a.WRITE_FILE:await this.handleWriteFile();break;case a.STAT:await this.handleStat();break;case a.LSTAT:await this.handleLstat();break;case a.READDIR:await this.handleReaddir();break;case a.MKDIR:await this.handleMkdir();break;case a.RM:await this.handleRm();break;case a.EXISTS:await this.handleExists();break;case a.APPEND_FILE:await this.handleAppendFile();break;case a.SYMLINK:await this.handleSymlink();break;case a.READLINK:await this.handleReadlink();break;case a.CHMOD:await this.handleChmod();break;case a.REALPATH:await this.handleRealpath();break;case a.WRITE_STDOUT:this.handleWriteStdout();break;case a.WRITE_STDERR:this.handleWriteStderr();break;case a.EXIT:this.handleExit();break;case a.HTTP_REQUEST:await this.handleHttpRequest();break;default:this.protocol.setErrorCode(u.IO_ERROR),this.protocol.setStatus(n.ERROR)}}catch(e){this.setErrorFromException(e)}}resolvePath(t){return t.startsWith("/mnt/host/")?t.slice(9):t.startsWith("/mnt/host")?t.slice(9)||"/":this.fs.resolvePath(this.cwd,t)}async handleReadFile(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readFileBuffer(t);this.protocol.setResult(e),this.protocol.setStatus(n.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleWriteFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.writeFile(t,e),this.protocol.setStatus(n.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleStat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.stat(t);this.protocol.encodeStat(e),this.protocol.setStatus(n.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleLstat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.lstat(t);this.protocol.encodeStat(e),this.protocol.setStatus(n.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleReaddir(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readdir(t);this.protocol.setResultFromString(JSON.stringify(e)),this.protocol.setStatus(n.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleMkdir(){let t=this.resolvePath(this.protocol.getPath()),s=(this.protocol.getFlags()&R.MKDIR_RECURSIVE)!==0;try{await this.fs.mkdir(t,{recursive:s}),this.protocol.setStatus(n.SUCCESS)}catch(o){this.setErrorFromException(o)}}async handleRm(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),s=(e&R.RECURSIVE)!==0,o=(e&R.FORCE)!==0;try{await this.fs.rm(t,{recursive:s,force:o}),this.protocol.setStatus(n.SUCCESS)}catch(l){this.setErrorFromException(l)}}async handleExists(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.exists(t);this.protocol.setResult(new Uint8Array([e?1:0])),this.protocol.setStatus(n.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleAppendFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.appendFile(t,e),this.protocol.setStatus(n.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleSymlink(){let t=this.protocol.getPath(),e=this.protocol.getDataAsString(),s=this.resolvePath(t);try{await this.fs.symlink(e,s),this.protocol.setStatus(n.SUCCESS)}catch(o){this.setErrorFromException(o)}}async handleReadlink(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readlink(t);this.protocol.setResultFromString(e),this.protocol.setStatus(n.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleChmod(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getMode();try{await this.fs.chmod(t,e),this.protocol.setStatus(n.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleRealpath(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.realpath(t);this.protocol.setResultFromString(e),this.protocol.setStatus(n.SUCCESS)}catch(e){this.setErrorFromException(e)}}handleWriteStdout(){let t=this.protocol.getDataAsString();this.output.stdout+=t,this.protocol.setStatus(n.SUCCESS)}handleWriteStderr(){let t=this.protocol.getDataAsString();this.output.stderr+=t,this.protocol.setStatus(n.SUCCESS)}handleExit(){let t=this.protocol.getFlags();this.output.exitCode=t,this.protocol.setStatus(n.SUCCESS),this.running=!1}async handleHttpRequest(){if(!this.secureFetch){this.protocol.setErrorCode(u.NETWORK_NOT_CONFIGURED),this.protocol.setResultFromString("Network access not configured. Enable network in Bash options."),this.protocol.setStatus(n.ERROR);return}let t=this.protocol.getPath(),e=this.protocol.getDataAsString();try{let s=e?JSON.parse(e):{},o=await this.secureFetch(t,{method:s.method,headers:s.headers,body:s.body}),l=JSON.stringify({status:o.status,statusText:o.statusText,headers:o.headers,body:o.body,url:o.url});this.protocol.setResultFromString(l),this.protocol.setStatus(n.SUCCESS)}catch(s){let o=s instanceof Error?s.message:String(s);this.protocol.setErrorCode(u.NETWORK_ERROR),this.protocol.setResultFromString(o),this.protocol.setStatus(n.ERROR)}}setErrorFromException(t){let e=t instanceof Error?t.message:String(t),s=u.IO_ERROR,o=e.toLowerCase();o.includes("no such file")||o.includes("not found")||o.includes("enoent")?s=u.NOT_FOUND:o.includes("is a directory")||o.includes("eisdir")?s=u.IS_DIRECTORY:o.includes("not a directory")||o.includes("enotdir")?s=u.NOT_DIRECTORY:o.includes("already exists")||o.includes("eexist")?s=u.EXISTS:(o.includes("permission")||o.includes("eperm")||o.includes("eacces"))&&(s=u.PERMISSION_DENIED),this.protocol.setErrorCode(s),this.protocol.setResultFromString(e),this.protocol.setStatus(n.ERROR)}};var N=3e4,V={name:"python3",summary:"Execute Python code via Pyodide",usage:"python3 [OPTIONS] [-c CODE | -m MODULE | FILE] [ARGS...]",description:["Execute Python code using Pyodide (Python compiled to WebAssembly).","","This command runs Python in a sandboxed environment with access to","the virtual filesystem. Only Pyodide-bundled packages are available."],options:["-c CODE Execute CODE as Python script","-m MODULE Run library module as a script","--version Show Python version","--help Show this help"],examples:['python3 -c "print(1 + 2)"','python3 -c "import sys; print(sys.version)"',"python3 script.py","python3 script.py arg1 arg2",`echo 'print("hello")' | python3`],notes:["Pyodide runs in WebAssembly, so execution may be slower than native Python.","Only packages bundled with Pyodide are available (no pip install).","First execution loads Pyodide (~30MB), subsequent calls are faster.","Maximum execution time is 30 seconds by default."]};function k(r){let t={code:null,module:null,scriptFile:null,showVersion:!1,scriptArgs:[]};if(r.length===0)return t;let e=r.findIndex(s=>!s.startsWith("-")||s==="-"||s==="--");for(let s=0;s<(e===-1?r.length:e);s++){let o=r[s];if(o==="-c")return s+1>=r.length?{stdout:"",stderr:`python3: option requires an argument -- 'c'
7
+ `,exitCode:2}:(t.code=r[s+1],t.scriptArgs=r.slice(s+2),t);if(o==="-m")return s+1>=r.length?{stdout:"",stderr:`python3: option requires an argument -- 'm'
8
+ `,exitCode:2}:(t.module=r[s+1],t.scriptArgs=r.slice(s+2),t);if(o==="--version"||o==="-V")return t.showVersion=!0,t;if(o.startsWith("-")&&o!=="-")return{stdout:"",stderr:`python3: unrecognized option '${o}'
9
+ `,exitCode:2}}if(e!==-1){let s=r[e];s==="--"?e+1<r.length&&(t.scriptFile=r[e+1],t.scriptArgs=r.slice(e+2)):(t.scriptFile=s,t.scriptArgs=r.slice(e+1))}return t}var c=null,F=null,S=[],E=null,M=x(new URL("./worker.js",import.meta.url));function O(){if(E||S.length===0)return;let r=S.shift();if(!r)return;E=r,b().postMessage(E.input)}function b(){return F&&(clearTimeout(F),F=null),c||(c=new L(M),c.on("message",r=>{E&&(E.resolve(r),E=null),S.length>0?O():B()}),c.on("error",r=>{E&&(E.resolve({success:!1,error:r.message}),E=null);for(let t of S)t.resolve({success:!1,error:"Worker crashed"});S.length=0,c=null}),c.on("exit",()=>{c=null}),c)}function B(){F=setTimeout(()=>{c&&!E&&S.length===0&&(c.terminate(),c=null)},5e3)}async function v(r,t,e,s=[]){let o=C(),l=new A(o,t.fs,t.cwd,t.fetch),d=t.limits?.maxPythonTimeoutMs??N,f={sharedBuffer:o,pythonCode:r,cwd:t.cwd,env:t.env,args:s,scriptPath:e},_=new Promise(T=>{let P=setTimeout(()=>{T({success:!1,error:`Execution timeout: exceeded ${d}ms limit`})},d),I=U=>{clearTimeout(P),T(U)};S.push({input:f,resolve:I}),O()}),[m,g]=await Promise.all([l.run(d),_.catch(T=>({success:!1,error:T.message}))]);return!g.success&&g.error?{stdout:m.stdout,stderr:`${m.stderr}python3: ${g.error}
10
+ `,exitCode:m.exitCode||1}:m}var H={name:"python3",async execute(r,t){if(D(r))return y(V);let e=k(r);if("exitCode"in e)return e;if(e.showVersion)return{stdout:`Python 3.12.1 (Pyodide)
11
+ `,stderr:"",exitCode:0};let s,o;if(e.code!==null)s=e.code,o="-c";else if(e.module!==null)s=`import runpy; runpy.run_module('${e.module}', run_name='__main__')`,o=e.module;else if(e.scriptFile!==null){let l=t.fs.resolvePath(t.cwd,e.scriptFile);if(!await t.fs.exists(l))return{stdout:"",stderr:`python3: can't open file '${e.scriptFile}': [Errno 2] No such file or directory
12
+ `,exitCode:2};try{s=await t.fs.readFile(l),o=e.scriptFile}catch(d){return{stdout:"",stderr:`python3: can't open file '${e.scriptFile}': ${d.message}
13
+ `,exitCode:2}}}else if(t.stdin.trim())s=t.stdin,o="<stdin>";else return{stdout:"",stderr:`python3: no input provided (use -c CODE, -m MODULE, or provide a script file)
14
+ `,exitCode:2};return v(s,t,o,e.scriptArgs)}},J={name:"python",async execute(r,t){return H.execute(r,t)}};export{H as python3Command,J as pythonCommand};