just-bash 3.2.0 → 3.3.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +47 -0
  3. package/dist/ast/types.d.ts +4 -1
  4. package/dist/bin/chunks/{chunk-QF7PPON7.js → chunk-5SR55TXB.js} +10 -10
  5. package/dist/bin/{shell/chunks/chunk-TL4JI2SL.js → chunks/chunk-6UK23ZFT.js} +17 -18
  6. package/dist/bin/chunks/{chunk-XBB73LFB.js → chunk-CMTQFWZK.js} +2 -2
  7. package/dist/bin/chunks/{chunk-YMELOXDK.js → chunk-D5G3L4PR.js} +8 -8
  8. package/dist/bin/chunks/{chunk-PRKSLEHG.js → chunk-DKIOFM35.js} +1 -1
  9. package/dist/bin/chunks/chunk-IJIJAQBT.js +12 -0
  10. package/dist/bin/{shell/chunks/chunk-NQQ3X7MZ.js → chunks/chunk-KXWWWQZK.js} +1 -1
  11. package/dist/bin/chunks/{chunk-3HUI54BW.js → chunk-TROO33BG.js} +1 -1
  12. package/dist/bin/chunks/chunk-USMDLXMM.js +21 -0
  13. package/dist/bin/{shell/chunks/chunk-JQER3HUP.js → chunks/chunk-XAVWLYZR.js} +1 -1
  14. package/dist/bin/chunks/{echo-4OUEL7QB.js → echo-NYDCCFWB.js} +1 -1
  15. package/dist/bin/chunks/{flag-coverage-WGSE667D.js → flag-coverage-EB3DK32J.js} +1 -1
  16. package/dist/bin/chunks/{grep-CMT2H2S7.js → grep-73YHJEX4.js} +1 -1
  17. package/dist/bin/{shell/chunks/jq-ACCMBTSD.js → chunks/jq-AO5GTPN4.js} +1 -1
  18. package/dist/bin/chunks/js-exec-worker.js +56 -20
  19. package/dist/bin/{shell/chunks/printf-F2KOCULO.js → chunks/printf-CNXNRQ3I.js} +1 -1
  20. package/dist/bin/chunks/python3-N252MJV6.js +14 -0
  21. package/dist/bin/{shell/chunks/rg-JRKJ6I4X.js → chunks/rg-OGGL3RIE.js} +1 -1
  22. package/dist/bin/chunks/{sqlite3-ZXF6BGDW.js → sqlite3-FEUFATVW.js} +1 -1
  23. package/dist/bin/chunks/worker.js +17 -1
  24. package/dist/bin/chunks/{xan-D6US4ZGL.js → xan-Q52EBQYW.js} +1 -1
  25. package/dist/bin/chunks/{yq-EYV7HLKK.js → yq-UA5NX5RT.js} +1 -1
  26. package/dist/bin/just-bash.js +391 -389
  27. package/dist/bin/shell/chunks/{chunk-QF7PPON7.js → chunk-5SR55TXB.js} +10 -10
  28. package/dist/bin/{chunks/chunk-TL4JI2SL.js → shell/chunks/chunk-6UK23ZFT.js} +17 -18
  29. package/dist/bin/shell/chunks/{chunk-XBB73LFB.js → chunk-CMTQFWZK.js} +2 -2
  30. package/dist/bin/shell/chunks/{chunk-YMELOXDK.js → chunk-D5G3L4PR.js} +8 -8
  31. package/dist/bin/shell/chunks/{chunk-PRKSLEHG.js → chunk-DKIOFM35.js} +1 -1
  32. package/dist/bin/shell/chunks/chunk-IJIJAQBT.js +12 -0
  33. package/dist/bin/{chunks/chunk-NQQ3X7MZ.js → shell/chunks/chunk-KXWWWQZK.js} +1 -1
  34. package/dist/bin/shell/chunks/{chunk-3HUI54BW.js → chunk-TROO33BG.js} +1 -1
  35. package/dist/bin/shell/chunks/chunk-USMDLXMM.js +21 -0
  36. package/dist/bin/{chunks/chunk-JQER3HUP.js → shell/chunks/chunk-XAVWLYZR.js} +1 -1
  37. package/dist/bin/shell/chunks/{echo-4OUEL7QB.js → echo-NYDCCFWB.js} +1 -1
  38. package/dist/bin/shell/chunks/{flag-coverage-WGSE667D.js → flag-coverage-EB3DK32J.js} +1 -1
  39. package/dist/bin/shell/chunks/{grep-CMT2H2S7.js → grep-73YHJEX4.js} +1 -1
  40. package/dist/bin/{chunks/jq-ACCMBTSD.js → shell/chunks/jq-AO5GTPN4.js} +1 -1
  41. package/dist/bin/{chunks/printf-F2KOCULO.js → shell/chunks/printf-CNXNRQ3I.js} +1 -1
  42. package/dist/bin/shell/chunks/python3-N252MJV6.js +14 -0
  43. package/dist/bin/{chunks/rg-JRKJ6I4X.js → shell/chunks/rg-OGGL3RIE.js} +1 -1
  44. package/dist/bin/shell/chunks/{sqlite3-ZXF6BGDW.js → sqlite3-FEUFATVW.js} +1 -1
  45. package/dist/bin/shell/chunks/{xan-D6US4ZGL.js → xan-Q52EBQYW.js} +1 -1
  46. package/dist/bin/shell/chunks/{yq-EYV7HLKK.js → yq-UA5NX5RT.js} +1 -1
  47. package/dist/bin/shell/shell.js +396 -394
  48. package/dist/bundle/browser.js +836 -823
  49. package/dist/bundle/chunks/{chunk-RAHPENCM.js → chunk-3ZBJCAAR.js} +1 -1
  50. package/dist/bundle/chunks/{chunk-AMLHAS2N.js → chunk-4AKAIZPW.js} +9 -9
  51. package/dist/bundle/chunks/{chunk-6SHYIICL.js → chunk-AGH5UJJI.js} +2 -2
  52. package/dist/bundle/chunks/{chunk-NOPXHH6G.js → chunk-EZDB7TGH.js} +1 -1
  53. package/dist/bundle/chunks/chunk-FC5NW7U4.js +11 -0
  54. package/dist/bundle/chunks/{chunk-5KGKXQF6.js → chunk-FHFPWM4W.js} +1 -1
  55. package/dist/bundle/chunks/chunk-H3PXMIY3.js +20 -0
  56. package/dist/bundle/chunks/{chunk-EWWPEE2G.js → chunk-IHGFM3FN.js} +17 -18
  57. package/dist/bundle/chunks/{chunk-65Z4QURM.js → chunk-J5G3ZBEK.js} +8 -8
  58. package/dist/bundle/chunks/{chunk-WENIVVEE.js → chunk-LTCWFMCI.js} +1 -1
  59. package/dist/bundle/chunks/{echo-HZOVZAPR.js → echo-PLLZYM2L.js} +1 -1
  60. package/dist/bundle/chunks/{flag-coverage-THYQHOT3.js → flag-coverage-UV7GI2DF.js} +1 -1
  61. package/dist/bundle/chunks/{grep-S6SNTIHZ.js → grep-UDCQDUQK.js} +1 -1
  62. package/dist/bundle/chunks/{jq-D6N4QCAJ.js → jq-B5324QOX.js} +1 -1
  63. package/dist/bundle/chunks/js-exec-worker.js +56 -20
  64. package/dist/bundle/chunks/{printf-QHD2JRWQ.js → printf-V42QCPHL.js} +1 -1
  65. package/dist/bundle/chunks/python3-ETPBGJP3.js +13 -0
  66. package/dist/bundle/chunks/{rg-OUJZ5DH6.js → rg-XCX2J2RF.js} +1 -1
  67. package/dist/bundle/chunks/{sqlite3-WWZJZW37.js → sqlite3-ZTQJIC3G.js} +1 -1
  68. package/dist/bundle/chunks/worker.js +17 -1
  69. package/dist/bundle/chunks/{xan-KKPV2TJ3.js → xan-EGU5VRRP.js} +1 -1
  70. package/dist/bundle/chunks/{yq-ZGB3W46S.js → yq-FMWLA3S2.js} +1 -1
  71. package/dist/bundle/index.cjs +1026 -1014
  72. package/dist/bundle/index.js +391 -389
  73. package/dist/commands/python3/worker.d.ts +1 -0
  74. package/dist/commands/query-engine/evaluator.d.ts +8 -0
  75. package/dist/fs/read-write-fs/read-write-fs.d.ts +42 -1
  76. package/dist/interpreter/builtin-dispatch.d.ts +9 -2
  77. package/dist/interpreter/builtins/eval.d.ts +7 -1
  78. package/dist/interpreter/control-flow.d.ts +1 -1
  79. package/dist/interpreter/fd-table.d.ts +130 -0
  80. package/dist/interpreter/functions.d.ts +3 -1
  81. package/dist/interpreter/helpers/word-matching.d.ts +0 -10
  82. package/dist/interpreter/interpreter.d.ts +7 -0
  83. package/dist/interpreter/numeric-fd-redirects.d.ts +8 -0
  84. package/dist/interpreter/process-substitution.d.ts +62 -0
  85. package/dist/interpreter/redirections.d.ts +33 -37
  86. package/dist/interpreter/subshell-group.d.ts +10 -2
  87. package/dist/interpreter/types.d.ts +38 -1
  88. package/dist/network/dns-pin.d.ts +11 -0
  89. package/dist/parser/expansion-parser.d.ts +3 -1
  90. package/dist/parser/lexer.d.ts +7 -9
  91. package/dist/parser/parser-substitution.d.ts +13 -4
  92. package/dist/parser/parser.d.ts +18 -4
  93. package/dist/parser/types.d.ts +6 -0
  94. package/dist/parser/word-parser.d.ts +2 -0
  95. package/dist/types.d.ts +6 -0
  96. package/package.json +1 -1
  97. package/dist/bin/chunks/chunk-P6NPCASY.js +0 -11
  98. package/dist/bin/chunks/chunk-WYTPLN2M.js +0 -11
  99. package/dist/bin/chunks/python3-AYUQQRCR.js +0 -14
  100. package/dist/bin/shell/chunks/chunk-P6NPCASY.js +0 -11
  101. package/dist/bin/shell/chunks/chunk-WYTPLN2M.js +0 -11
  102. package/dist/bin/shell/chunks/python3-AYUQQRCR.js +0 -14
  103. package/dist/bundle/chunks/chunk-VECGTAPW.js +0 -10
  104. package/dist/bundle/chunks/chunk-YOUUMJLJ.js +0 -10
  105. package/dist/bundle/chunks/python3-QDNG2UXX.js +0 -13
@@ -7,6 +7,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
 
8
8
  // src/commands/js-exec/js-exec-worker.ts
9
9
  import { stripTypeScriptTypes } from "node:module";
10
+ import { setTimeout } from "node:timers/promises";
10
11
  import { parentPort } from "node:worker_threads";
11
12
  import {
12
13
  getQuickJS
@@ -3495,6 +3496,7 @@ async function getQuickJSModule() {
3495
3496
  }
3496
3497
  var MEMORY_LIMIT = 64 * 1024 * 1024;
3497
3498
  var INTERRUPT_CYCLES = 1e5;
3499
+ var PROCESS_EXIT_MARKER = "__just_bash_process_exit_marker__";
3498
3500
  function formatError(errorVal) {
3499
3501
  if (typeof errorVal === "object" && errorVal !== null && "message" in errorVal) {
3500
3502
  const err = errorVal;
@@ -3516,6 +3518,12 @@ function formatError(errorVal) {
3516
3518
  function throwError(context, message) {
3517
3519
  return { error: context.newError(message) };
3518
3520
  }
3521
+ function isProcessExit(context, error, processExitMarker) {
3522
+ const marker = context.getProp(error, PROCESS_EXIT_MARKER);
3523
+ const isExit = context.sameValue(marker, processExitMarker);
3524
+ marker.dispose();
3525
+ return isExit;
3526
+ }
3519
3527
  function jsToHandle(context, value) {
3520
3528
  if (value === null || value === void 0) {
3521
3529
  return context.undefined;
@@ -3741,7 +3749,7 @@ var VIRTUAL_MODULES = Object.assign(
3741
3749
  for (const [name, hint] of Object.entries(UNSUPPORTED_MODULES)) {
3742
3750
  VIRTUAL_MODULES[name] = `throw new Error("Module '${name}' is not available in the js-exec sandbox. ${hint} Run 'js-exec --help' for available modules.");`;
3743
3751
  }
3744
- function setupContext(context, backend, input) {
3752
+ function setupContext(context, backend, input, processExitMarker) {
3745
3753
  const consoleObj = context.newObject();
3746
3754
  const logFn = context.newFunction("log", (...args) => {
3747
3755
  const parts = args.map((a) => {
@@ -4145,7 +4153,9 @@ function setupContext(context, backend, input) {
4145
4153
  code = typeof val === "number" ? val : 0;
4146
4154
  }
4147
4155
  backend.exit(code);
4148
- return throwError(context, "__EXIT__");
4156
+ const exitError = context.newError("process.exit()");
4157
+ context.setProp(exitError, PROCESS_EXIT_MARKER, processExitMarker);
4158
+ return { error: exitError };
4149
4159
  });
4150
4160
  context.setProp(processObj, "exit", exitFn);
4151
4161
  exitFn.dispose();
@@ -4367,7 +4377,7 @@ async function initializeWithDefense() {
4367
4377
  stripTypeScriptTypes("const x = 1;");
4368
4378
  } catch {
4369
4379
  }
4370
- await new Promise((r) => setTimeout(r, 0));
4380
+ await setTimeout(0);
4371
4381
  defense = new WorkerDefenseInDepth({
4372
4382
  excludeViolationTypes: [
4373
4383
  // SharedArrayBuffer/Atomics: Used by sync-backend for synchronous
@@ -4405,6 +4415,7 @@ async function executeCode(input) {
4405
4415
  const backend = new SyncBackend(input.sharedBuffer, input.timeoutMs);
4406
4416
  let runtime;
4407
4417
  let context;
4418
+ let processExitMarker;
4408
4419
  try {
4409
4420
  runtime = qjs.newRuntime();
4410
4421
  runtime.setMemoryLimit(MEMORY_LIMIT);
@@ -4414,7 +4425,8 @@ async function executeCode(input) {
4414
4425
  return interruptCount > INTERRUPT_CYCLES;
4415
4426
  });
4416
4427
  context = runtime.newContext();
4417
- setupContext(context, backend, input);
4428
+ processExitMarker = context.newObject();
4429
+ setupContext(context, backend, input, processExitMarker);
4418
4430
  {
4419
4431
  const initResult = context.evalCode(
4420
4432
  `{
@@ -4625,12 +4637,12 @@ async function executeCode(input) {
4625
4637
  }
4626
4638
  const result = input.isModule ? context.evalCode(jsCode, filename, { type: "module" }) : context.evalCode(jsCode, filename);
4627
4639
  if (result.error) {
4628
- const errorVal = context.dump(result.error);
4629
- result.error.dispose();
4630
- const rawMsg = typeof errorVal === "object" && errorVal !== null && "message" in errorVal ? errorVal.message : String(errorVal);
4631
- if (rawMsg === "__EXIT__") {
4640
+ if (isProcessExit(context, result.error, processExitMarker)) {
4641
+ result.error.dispose();
4632
4642
  return { success: true };
4633
4643
  }
4644
+ const errorVal = context.dump(result.error);
4645
+ result.error.dispose();
4634
4646
  const errorMsg = formatError(errorVal);
4635
4647
  try {
4636
4648
  backend.writeStderr(`${errorMsg}
@@ -4640,24 +4652,47 @@ async function executeCode(input) {
4640
4652
  backend.exit(1);
4641
4653
  return { success: true };
4642
4654
  }
4643
- {
4644
- const pendingResult = runtime.executePendingJobs();
4645
- if ("error" in pendingResult && pendingResult.error) {
4646
- const errorVal = context.dump(pendingResult.error);
4655
+ const moduleCompletion = input.isModule ? context.resolvePromise(result.value) : void 0;
4656
+ const pendingResult = runtime.executePendingJobs();
4657
+ if ("error" in pendingResult && pendingResult.error) {
4658
+ if (isProcessExit(context, pendingResult.error, processExitMarker)) {
4647
4659
  pendingResult.error.dispose();
4648
- const rawPendingMsg = typeof errorVal === "object" && errorVal !== null && "message" in errorVal ? errorVal.message : String(errorVal);
4649
- if (rawPendingMsg !== "__EXIT__") {
4650
- const errorMsg = formatError(errorVal);
4651
- try {
4652
- backend.writeStderr(`${errorMsg}
4660
+ result.value.dispose();
4661
+ return { success: true };
4662
+ }
4663
+ const errorVal = context.dump(pendingResult.error);
4664
+ pendingResult.error.dispose();
4665
+ result.value.dispose();
4666
+ const errorMsg = formatError(errorVal);
4667
+ try {
4668
+ backend.writeStderr(`${errorMsg}
4653
4669
  `);
4654
- } catch {
4655
- }
4656
- backend.exit(1);
4670
+ } catch {
4671
+ }
4672
+ backend.exit(1);
4673
+ return { success: true };
4674
+ }
4675
+ if (moduleCompletion) {
4676
+ const moduleResult = await moduleCompletion;
4677
+ if (moduleResult.error) {
4678
+ if (isProcessExit(context, moduleResult.error, processExitMarker)) {
4679
+ moduleResult.error.dispose();
4680
+ result.value.dispose();
4657
4681
  return { success: true };
4658
4682
  }
4683
+ const errorVal = context.dump(moduleResult.error);
4684
+ moduleResult.error.dispose();
4685
+ result.value.dispose();
4686
+ const errorMsg = formatError(errorVal);
4687
+ try {
4688
+ backend.writeStderr(`${errorMsg}
4689
+ `);
4690
+ } catch {
4691
+ }
4692
+ backend.exit(1);
4659
4693
  return { success: true };
4660
4694
  }
4695
+ moduleResult.value.dispose();
4661
4696
  }
4662
4697
  result.value.dispose();
4663
4698
  backend.exit(0);
@@ -4679,6 +4714,7 @@ async function executeCode(input) {
4679
4714
  }
4680
4715
  return { success: true };
4681
4716
  } finally {
4717
+ processExitMarker?.dispose();
4682
4718
  context?.dispose();
4683
4719
  runtime?.dispose();
4684
4720
  }
@@ -1,2 +1,2 @@
1
1
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{a,b}from"./chunk-AMLHAS2N.js";import"./chunk-UHHCL65P.js";import"./chunk-6D3WD6YU.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-W5DWRFSU.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{b as flagsForFuzzing,a as printfCommand};
2
+ import{a,b}from"./chunk-4AKAIZPW.js";import"./chunk-UHHCL65P.js";import"./chunk-6D3WD6YU.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-W5DWRFSU.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{b as flagsForFuzzing,a as printfCommand};
@@ -0,0 +1,13 @@
1
+ import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
+ import{a as Q,b as W}from"./chunk-CN3HTJTZ.js";import{a as I}from"./chunk-UK4BO5W3.js";import"./chunk-WNH3HOQA.js";import"./chunk-KIGPB52X.js";import"./chunk-K3XJ2WT4.js";import"./chunk-L2UW7DWF.js";import{a as F}from"./chunk-DLL7UR66.js";import{c as w}from"./chunk-AI5LSBJC.js";import{b as M}from"./chunk-UBTKJ6MG.js";import{d as C}from"./chunk-GN6CQ3J4.js";import{a as A,b as d}from"./chunk-FOCWZZDE.js";import{a as E}from"./chunk-W5DWRFSU.js";import{a as P,b as D}from"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";import{fileURLToPath as B}from"node:url";import{Worker as L}from"node:worker_threads";var z={name:"python3",summary:"Execute Python code via CPython Emscripten",usage:"python3 [OPTIONS] [-c CODE | -m MODULE | FILE] [ARGS...]",description:["Execute Python code using CPython compiled to WebAssembly via Emscripten.","","This command runs Python in an isolated environment with access to","the virtual filesystem. Standard library modules 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:["CPython runs in WebAssembly, so execution may be slower than native Python.","Standard library modules are available (no pip install).","Maximum execution time is 30 seconds by default."]};function _(t){let e={code:null,module:null,scriptFile:null,showVersion:!1,scriptArgs:[]};if(t.length===0)return e;let r=t.findIndex(n=>!n.startsWith("-")||n==="-"||n==="--");for(let n=0;n<(r===-1?t.length:r);n++){let i=t[n];if(i==="-c")return n+1>=t.length?{stdout:"",stderr:`python3: option requires an argument -- 'c'
3
+ `,exitCode:2}:(e.code=t[n+1],e.scriptArgs=t.slice(n+2),e);if(i==="-m")return n+1>=t.length?{stdout:"",stderr:`python3: option requires an argument -- 'm'
4
+ `,exitCode:2}:(e.module=t[n+1],e.scriptArgs=t.slice(n+2),e);if(i==="--version"||i==="-V")return e.showVersion=!0,e;if(i.startsWith("-")&&i!=="-")return{stdout:"",stderr:`python3: unrecognized option '${i}'
5
+ `,exitCode:2}}if(r!==-1){let n=t[r];n==="--"?r+1<t.length&&(e.scriptFile=t[r+1],e.scriptArgs=t.slice(r+2)):(e.scriptFile=n,e.scriptArgs=t.slice(r+1))}return e}var b=new WeakMap;function R(t){let e=b.get(t);return e||(e={executionQueue:[],activeExecution:null,poisonedError:null},b.set(t,e)),e}function ne(){b=new WeakMap}var H=B(new URL("./worker.js",import.meta.url));function U(t,e){if(!t||typeof t!="object")return{success:!1,error:"Malformed worker response"};let r=t;return typeof r.protocolToken!="string"||r.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}:r.type==="security-violation"?{success:!1,error:`Security violation: ${typeof r.violation?.type=="string"?r.violation.type:"unknown"}`}:typeof r.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:r.success?{success:!0}:{success:!1,error:typeof r.error=="string"&&r.error.length>0?r.error:"Worker execution failed"}}function k(t){if(t.poisonedError!==null){for(let o of t.executionQueue.splice(0))o.state==="queued"&&(o.state="settled",o.stopBridge(),o.settle({success:!1,error:t.poisonedError}));return}if(t.activeExecution!==null||t.executionQueue.length===0)return;for(;t.executionQueue.length>0&&t.executionQueue[0]?.state!=="queued";)t.executionQueue.shift();if(t.executionQueue.length===0)return;let e=t.executionQueue.shift();if(!e)return;e.state="running",t.activeExecution=e;let r;try{r=M.runTrusted(()=>new L(H,{workerData:e.input}))}catch(o){let s=o instanceof Error?o.message:String(o);e.state="settled",e.settle({success:!1,error:d(s)}),t.activeExecution===e&&(t.activeExecution=null,k(t));return}e.worker=r;let n=!0,i=()=>{n&&(n=!1,r.removeListener("message",u),r.removeListener("error",g),r.removeListener("exit",v))},c=async(o,s)=>{if(!(t.activeExecution?.executionId!==e.executionId||e.state!=="running")){if(e.state="terminating",i(),e.settle(o),s&&!await e.controller.terminate(r)){let f="Worker termination was not acknowledged";e.worker=null,e.state="settled",t.poisonedError=f,t.activeExecution?.executionId===e.executionId&&(t.activeExecution=null),k(t);return}e.worker=null,e.state="settled",t.activeExecution?.executionId===e.executionId&&(t.activeExecution=null,k(t))}};e.cancel=o=>{c(o,!0)};let p=w(e.requireDefenseContext,"python3","worker message callback",o=>{try{e.controller.assertMessageSize(o,"response")}catch(s){c({success:!1,error:d(E(s))},!0);return}c(U(o,e.input.protocolToken),!0)}),h=w(e.requireDefenseContext,"python3","worker error callback",o=>{let s=d(E(o));c({success:!1,error:s},!0)}),a=w(e.requireDefenseContext,"python3","worker exit callback",()=>{c({success:!1,error:"Worker exited unexpectedly"},!1)}),u=o=>{try{p(o)}catch(s){let l=s instanceof Error?s.message:String(s);c({success:!1,error:d(l)},!0)}},g=o=>{try{h(o)}catch(s){let l=s instanceof Error?s.message:String(s);c({success:!1,error:d(l)},!0)}},v=()=>{try{a()}catch(o){let s=o instanceof Error?o.message:String(o);c({success:!1,error:d(s)},!0)}};r.on("message",u),r.on("error",g),r.on("exit",v)}async function N(t,e,r,n,i=[]){let c=Q(),p=new W(c,r.fs,r.cwd,"python3",r.fetch,r.limits.maxOutputSize),h=r.limits.maxPythonTimeoutMs,a=R(r.fs);if(a.poisonedError!==null)return{stdout:"",stderr:`python3: ${a.poisonedError}
6
+ `,exitCode:1};let u=new I({commandName:"python3",timeoutMs:h,signal:r.signal,maxMessageBytes:r.limits.maxWorkerMessageBytes}),g={protocolToken:u.protocolToken,sharedBuffer:c,pythonCode:t,stdin:e,cwd:r.cwd,env:F(r.env),args:i,scriptPath:n,timeoutMs:h,maxFileSize:r.limits.maxStringLength};u.assertMessageSize({...g,sharedBuffer:void 0},"request");let v=new Promise(l=>{let f=!1,m={executionId:Symbol("python3 execution"),input:g,settle:y=>{f||(f=!0,u.close(),l(y))},requireDefenseContext:r.requireDefenseContext,state:"queued",worker:null,controller:u,stopBridge:()=>p.stop?.(),cancel:()=>{}};m.cancel=y=>{if(m.state!=="queued")return;m.state="settled";let x=a.executionQueue.indexOf(m);x!==-1&&a.executionQueue.splice(x,1),m.settle(y),k(a)};let O=w(r.requireDefenseContext,"python3","worker cancellation callback",y=>{p.stop?.(),m.cancel({success:!1,error:y==="abort"?u.abortMessage():u.timeoutMessage()})}),T=y=>{try{O(y)}catch(x){let $=x instanceof Error?x.message:String(x);m.cancel({success:!1,error:d($)})}};u.arm(T),u.isCanceled||(a.executionQueue.push(m),k(a))}),[o,s]=await Promise.all([p.run(h).catch(l=>({stdout:"",stderr:`python3: bridge error: ${d(E(l))}
7
+ `,exitCode:1})),v.catch(l=>({success:!1,error:d(E(l))}))]);if(!s.success&&s.error){let l=d(s.error),f=s.error===u.timeoutMessage()||s.error===u.abortMessage();return{stdout:o.stdout,stderr:`${o.stderr}python3: ${l}
8
+ `,exitCode:o.exitCode||(f?124:1)}}return{...o}}var V={name:"python3",async execute(t,e){if(D(t))return P(z);let r=_(t);if("exitCode"in r)return r;if(r.showVersion)return{stdout:`Python 3.13.2 (Emscripten)
9
+ `,stderr:"",exitCode:0};let n,i,c=e.stdin;if(r.code!==null)n=r.code,i="-c";else if(r.module!==null){if(!/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(r.module))return{stdout:"",stderr:`python3: No module named '${r.module.slice(0,200)}'
10
+ `,exitCode:1};n=`import runpy; runpy.run_module('${r.module}', run_name='__main__')`,i=r.module}else if(r.scriptFile==="-")n=C(e.stdin),c="",i="-";else if(r.scriptFile!==null){let p=e.fs.resolvePath(e.cwd,r.scriptFile);if(!await e.fs.exists(p))return{stdout:"",stderr:`python3: can't open file '${r.scriptFile}': [Errno 2] No such file or directory
11
+ `,exitCode:2};try{n=await e.fs.readFile(p),i=r.scriptFile}catch(h){let a=A(h.message);return{stdout:"",stderr:`python3: can't open file '${r.scriptFile}': ${a}
12
+ `,exitCode:2}}}else if(C(e.stdin).trim())n=C(e.stdin),c="",i="<stdin>";else return{stdout:"",stderr:`python3: no input provided (use -c CODE, -m MODULE, or provide a script file)
13
+ `,exitCode:2};return N(n,c,e,i,r.scriptArgs)}},se={name:"python",async execute(t,e){return V.execute(t,e)}};export{ne as _resetExecutionQueue,V as python3Command,se as pythonCommand};
@@ -1,2 +1,2 @@
1
1
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{a,b}from"./chunk-RAHPENCM.js";import"./chunk-FIMO5HLX.js";import"./chunk-WENIVVEE.js";import"./chunk-L2UW7DWF.js";import"./chunk-XVL654YD.js";import"./chunk-LJRVJXUI.js";import"./chunk-UBTKJ6MG.js";import"./chunk-AH7VTVWU.js";import"./chunk-IBRT3OJS.js";import"./chunk-YUSFCOM7.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-FOCWZZDE.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{b as flagsForFuzzing,a as rgCommand};
2
+ import{a,b}from"./chunk-3ZBJCAAR.js";import"./chunk-FIMO5HLX.js";import"./chunk-LTCWFMCI.js";import"./chunk-L2UW7DWF.js";import"./chunk-XVL654YD.js";import"./chunk-LJRVJXUI.js";import"./chunk-UBTKJ6MG.js";import"./chunk-AH7VTVWU.js";import"./chunk-IBRT3OJS.js";import"./chunk-YUSFCOM7.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-FOCWZZDE.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{b as flagsForFuzzing,a as rgCommand};
@@ -1,2 +1,2 @@
1
1
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{a,b,c}from"./chunk-EWWPEE2G.js";import"./chunk-UK4BO5W3.js";import"./chunk-K3XJ2WT4.js";import"./chunk-AI5LSBJC.js";import"./chunk-UBTKJ6MG.js";import"./chunk-IBRT3OJS.js";import"./chunk-YUSFCOM7.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-FOCWZZDE.js";import"./chunk-W5DWRFSU.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{a as _internals,c as flagsForFuzzing,b as sqlite3Command};
2
+ import{a,b,c}from"./chunk-IHGFM3FN.js";import"./chunk-UK4BO5W3.js";import"./chunk-K3XJ2WT4.js";import"./chunk-AI5LSBJC.js";import"./chunk-UBTKJ6MG.js";import"./chunk-IBRT3OJS.js";import"./chunk-YUSFCOM7.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-FOCWZZDE.js";import"./chunk-W5DWRFSU.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{a as _internals,c as flagsForFuzzing,b as sqlite3Command};
@@ -2661,10 +2661,19 @@ def _redir_scandir(path='.'):
2661
2661
  return _orig_scandir(path)
2662
2662
  os.scandir = _redir_scandir
2663
2663
 
2664
- # io.open
2664
+ # io.open and io.open_code
2665
2665
  import io as _io_module
2666
2666
  _io_module.open = builtins.open
2667
2667
 
2668
+ # runpy uses io.open_code rather than builtins.open/io.open. Redirect it
2669
+ # separately so code loading keeps the logical path in __file__ and argv.
2670
+ _orig_open_code = _io_module.open_code
2671
+ def _redir_open_code(path):
2672
+ if _should_redirect(path):
2673
+ path = '/host' + path
2674
+ return _orig_open_code(path)
2675
+ _io_module.open_code = _redir_open_code
2676
+
2668
2677
  # shutil
2669
2678
  import shutil as _shutil_module
2670
2679
 
@@ -3068,10 +3077,17 @@ async function runPython(input) {
3068
3077
  const pendingStderr = [];
3069
3078
  let Module;
3070
3079
  try {
3080
+ let stdinOffset = 0;
3081
+ const readStdin = wrapWasmCallback(
3082
+ "python3-worker",
3083
+ "stdin",
3084
+ () => stdinOffset < input.stdin.length ? input.stdin.charCodeAt(stdinOffset++) : null
3085
+ );
3071
3086
  const onPreRun = wrapWasmCallback(
3072
3087
  "python3-worker",
3073
3088
  "preRun",
3074
3089
  (mod) => {
3090
+ mod.FS.init(readStdin);
3075
3091
  mod.FS.mkdirTree("/lib");
3076
3092
  mod.FS.writeFile("/lib/python313.zip", cachedStdlibZip);
3077
3093
  mod.ENV.PYTHONHOME = "/";
@@ -1,2 +1,2 @@
1
1
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{a,b}from"./chunk-5KGKXQF6.js";import"./chunk-3DHFIWMM.js";import"./chunk-Y3DGIAIG.js";import"./chunk-65Z4QURM.js";import"./chunk-FIMO5HLX.js";import"./chunk-DLL7UR66.js";import"./chunk-AI5LSBJC.js";import"./chunk-XVL654YD.js";import"./chunk-CHHWTPDH.js";import"./chunk-LJRVJXUI.js";import"./chunk-UBTKJ6MG.js";import"./chunk-6D3WD6YU.js";import"./chunk-AH7VTVWU.js";import"./chunk-STHBFACM.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{b as flagsForFuzzing,a as xanCommand};
2
+ import{a,b}from"./chunk-FHFPWM4W.js";import"./chunk-3DHFIWMM.js";import"./chunk-Y3DGIAIG.js";import"./chunk-J5G3ZBEK.js";import"./chunk-FIMO5HLX.js";import"./chunk-DLL7UR66.js";import"./chunk-AI5LSBJC.js";import"./chunk-XVL654YD.js";import"./chunk-CHHWTPDH.js";import"./chunk-LJRVJXUI.js";import"./chunk-UBTKJ6MG.js";import"./chunk-6D3WD6YU.js";import"./chunk-AH7VTVWU.js";import"./chunk-STHBFACM.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{b as flagsForFuzzing,a as xanCommand};
@@ -1,2 +1,2 @@
1
1
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{a,b}from"./chunk-NOPXHH6G.js";import"./chunk-Y3DGIAIG.js";import"./chunk-65Z4QURM.js";import"./chunk-FIMO5HLX.js";import"./chunk-DLL7UR66.js";import"./chunk-AI5LSBJC.js";import"./chunk-XVL654YD.js";import"./chunk-UBTKJ6MG.js";import"./chunk-6D3WD6YU.js";import"./chunk-AH7VTVWU.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-FOCWZZDE.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{b as flagsForFuzzing,a as yqCommand};
2
+ import{a,b}from"./chunk-EZDB7TGH.js";import"./chunk-Y3DGIAIG.js";import"./chunk-J5G3ZBEK.js";import"./chunk-FIMO5HLX.js";import"./chunk-DLL7UR66.js";import"./chunk-AI5LSBJC.js";import"./chunk-XVL654YD.js";import"./chunk-UBTKJ6MG.js";import"./chunk-6D3WD6YU.js";import"./chunk-AH7VTVWU.js";import"./chunk-EFORKKSH.js";import"./chunk-GN6CQ3J4.js";import"./chunk-FOCWZZDE.js";import"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";export{b as flagsForFuzzing,a as yqCommand};