just-bash 2.13.1 → 2.15.0-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.
Files changed (119) hide show
  1. package/README.md +2 -0
  2. package/dist/AGENTS.md +2 -0
  3. package/dist/Bash.d.ts +86 -0
  4. package/dist/bin/chunks/{chunk-OQV5J23L.js → chunk-7G3MC56B.js} +1 -1
  5. package/dist/bin/chunks/{chunk-YX7OOTPO.js → chunk-AZ3RUDR2.js} +1 -1
  6. package/dist/bin/chunks/{chunk-UPUMZYZE.js → chunk-CM4532DS.js} +18 -18
  7. package/dist/bin/{shell/chunks/chunk-R2LDP472.js → chunks/chunk-EPPBDXOG.js} +1 -1
  8. package/dist/bin/{shell/chunks/chunk-LGF54XJQ.js → chunks/chunk-L2JBII6Z.js} +1 -1
  9. package/dist/bin/chunks/chunk-MNMRGJJM.js +11 -0
  10. package/dist/bin/{shell/chunks/chunk-SYL34GE7.js → chunks/chunk-NAX7MTAR.js} +1 -1
  11. package/dist/bin/chunks/{chunk-EZS766DD.js → chunk-NLBRLRWD.js} +1 -1
  12. package/dist/bin/chunks/chunk-RLNOQILG.js +2 -0
  13. package/dist/bin/chunks/{chunk-VVFGRIJZ.js → chunk-RMQC3GS7.js} +1 -1
  14. package/dist/bin/{shell/chunks/chunk-GR23MPTT.js → chunks/chunk-VHUYNUT7.js} +1 -1
  15. package/dist/bin/{shell/chunks/chunk-FBJJY4ZV.js → chunks/chunk-WXMBDX4P.js} +1 -1
  16. package/dist/bin/chunks/expr-4CJYC4LY.js +2 -0
  17. package/dist/bin/{shell/chunks/flag-coverage-A4G6STMS.js → chunks/flag-coverage-LBMWMYOO.js} +1 -1
  18. package/dist/bin/{shell/chunks/jq-V7FYGIKO.js → chunks/jq-FIV5Q5T4.js} +1 -1
  19. package/dist/bin/chunks/{js-exec-JORCTVUT.js → js-exec-6UJKEL4G.js} +9 -9
  20. package/dist/bin/chunks/js-exec-worker.js +233 -1
  21. package/dist/bin/chunks/{ln-VAOSD4HK.js → ln-EGC4HRXZ.js} +1 -1
  22. package/dist/bin/{shell/chunks/mkdir-CH7JGW4N.js → chunks/mkdir-Z47OISSR.js} +1 -1
  23. package/dist/bin/chunks/python3-QOJU2POC.js +12 -0
  24. package/dist/bin/chunks/{rm-GWYJO4W7.js → rm-L3NZOLLG.js} +1 -1
  25. package/dist/bin/chunks/{sed-3C6IBX5L.js → sed-HALRQZKY.js} +1 -1
  26. package/dist/bin/chunks/{sqlite3-TZEE4O7U.js → sqlite3-CVNFMP3Z.js} +1 -1
  27. package/dist/bin/chunks/time-5R4QWCYF.js +2 -0
  28. package/dist/bin/{shell/chunks/tr-LZF57GYP.js → chunks/tr-4FPGAEVB.js} +1 -1
  29. package/dist/bin/chunks/worker.js +34 -8
  30. package/dist/bin/chunks/{yq-JJLSDDST.js → yq-Q47JUWL6.js} +1 -1
  31. package/dist/bin/just-bash.js +245 -245
  32. package/dist/bin/shell/chunks/{chunk-OQV5J23L.js → chunk-7G3MC56B.js} +1 -1
  33. package/dist/bin/shell/chunks/{chunk-YX7OOTPO.js → chunk-AZ3RUDR2.js} +1 -1
  34. package/dist/bin/shell/chunks/{chunk-UPUMZYZE.js → chunk-CM4532DS.js} +18 -18
  35. package/dist/bin/{chunks/chunk-R2LDP472.js → shell/chunks/chunk-EPPBDXOG.js} +1 -1
  36. package/dist/bin/{chunks/chunk-LGF54XJQ.js → shell/chunks/chunk-L2JBII6Z.js} +1 -1
  37. package/dist/bin/shell/chunks/chunk-MNMRGJJM.js +11 -0
  38. package/dist/bin/{chunks/chunk-SYL34GE7.js → shell/chunks/chunk-NAX7MTAR.js} +1 -1
  39. package/dist/bin/shell/chunks/{chunk-EZS766DD.js → chunk-NLBRLRWD.js} +1 -1
  40. package/dist/bin/shell/chunks/chunk-RLNOQILG.js +2 -0
  41. package/dist/bin/shell/chunks/{chunk-VVFGRIJZ.js → chunk-RMQC3GS7.js} +1 -1
  42. package/dist/bin/{chunks/chunk-GR23MPTT.js → shell/chunks/chunk-VHUYNUT7.js} +1 -1
  43. package/dist/bin/{chunks/chunk-FBJJY4ZV.js → shell/chunks/chunk-WXMBDX4P.js} +1 -1
  44. package/dist/bin/shell/chunks/expr-4CJYC4LY.js +2 -0
  45. package/dist/bin/{chunks/flag-coverage-A4G6STMS.js → shell/chunks/flag-coverage-LBMWMYOO.js} +1 -1
  46. package/dist/bin/{chunks/jq-V7FYGIKO.js → shell/chunks/jq-FIV5Q5T4.js} +1 -1
  47. package/dist/bin/shell/chunks/{js-exec-B6QNYHUL.js → js-exec-H26D5H6V.js} +9 -9
  48. package/dist/bin/shell/chunks/{ln-VAOSD4HK.js → ln-EGC4HRXZ.js} +1 -1
  49. package/dist/bin/{chunks/mkdir-CH7JGW4N.js → shell/chunks/mkdir-Z47OISSR.js} +1 -1
  50. package/dist/bin/shell/chunks/python3-O4VTP6TD.js +12 -0
  51. package/dist/bin/shell/chunks/{rm-GWYJO4W7.js → rm-L3NZOLLG.js} +1 -1
  52. package/dist/bin/shell/chunks/{sed-3C6IBX5L.js → sed-HALRQZKY.js} +1 -1
  53. package/dist/bin/shell/chunks/{sqlite3-TZEE4O7U.js → sqlite3-CVNFMP3Z.js} +1 -1
  54. package/dist/bin/shell/chunks/time-5R4QWCYF.js +2 -0
  55. package/dist/bin/{chunks/tr-LZF57GYP.js → shell/chunks/tr-4FPGAEVB.js} +1 -1
  56. package/dist/bin/shell/chunks/{yq-JJLSDDST.js → yq-Q47JUWL6.js} +1 -1
  57. package/dist/bin/shell/shell.js +127 -127
  58. package/dist/bundle/browser.js +250 -250
  59. package/dist/bundle/chunks/chunk-3THT3N7L.js +1 -0
  60. package/dist/bundle/chunks/{chunk-XXZ46GOX.js → chunk-62RKD26F.js} +1 -1
  61. package/dist/bundle/chunks/chunk-B6O2PIY4.js +10 -0
  62. package/dist/bundle/chunks/{chunk-IUWCBQII.js → chunk-HWBSOZZR.js} +18 -18
  63. package/dist/bundle/chunks/{chunk-64CW2LGZ.js → chunk-MDDMCKUK.js} +1 -1
  64. package/dist/bundle/chunks/{chunk-IP7G3BNA.js → chunk-MIZPJHVH.js} +1 -1
  65. package/dist/bundle/chunks/{chunk-V3IEYMEA.js → chunk-OL3S66CO.js} +1 -1
  66. package/dist/bundle/chunks/{chunk-FGALERPA.js → chunk-PBXLG62G.js} +1 -1
  67. package/dist/bundle/chunks/{chunk-O2DBFL6Z.js → chunk-XORM457F.js} +1 -1
  68. package/dist/bundle/chunks/{chunk-RUF7WQ7U.js → chunk-YCFVLTST.js} +1 -1
  69. package/dist/bundle/chunks/{chunk-RVT3MU3A.js → chunk-YFG2CMIF.js} +1 -1
  70. package/dist/bundle/chunks/{chunk-F5CMUULS.js → chunk-Z6LRHWXI.js} +1 -1
  71. package/dist/bundle/chunks/expr-5T3UU5KE.js +1 -0
  72. package/dist/bundle/chunks/{flag-coverage-G2R7PMYU.js → flag-coverage-LMTH7T5F.js} +1 -1
  73. package/dist/bundle/chunks/{jq-DIRZBOTX.js → jq-ODXZBPLY.js} +1 -1
  74. package/dist/bundle/chunks/{js-exec-YJSMH5AG.js → js-exec-OOPTBRNB.js} +9 -9
  75. package/dist/bundle/chunks/js-exec-worker.js +233 -1
  76. package/dist/bundle/chunks/{ln-UJ6YJVBK.js → ln-4TRFBYAT.js} +1 -1
  77. package/dist/bundle/chunks/{mkdir-F6XHPXZC.js → mkdir-TDEMSB6C.js} +1 -1
  78. package/dist/bundle/chunks/python3-5F2XPEW4.js +11 -0
  79. package/dist/bundle/chunks/{rm-FYNVTQIU.js → rm-RTZG23RL.js} +1 -1
  80. package/dist/bundle/chunks/{sed-DISNI47D.js → sed-VFTTATXJ.js} +1 -1
  81. package/dist/bundle/chunks/{sqlite3-7F22DOIP.js → sqlite3-56UMWEY3.js} +1 -1
  82. package/dist/bundle/chunks/time-DEUO3QV2.js +1 -0
  83. package/dist/bundle/chunks/{tr-GVTWMRZB.js → tr-2HXZRDSW.js} +1 -1
  84. package/dist/bundle/chunks/worker.js +34 -8
  85. package/dist/bundle/chunks/{yq-XMVSIL6Z.js → yq-MJMAR36V.js} +1 -1
  86. package/dist/bundle/index.cjs +745 -745
  87. package/dist/bundle/index.js +159 -159
  88. package/dist/commands/js-exec/executor-adapter.d.ts +66 -0
  89. package/dist/commands/js-exec/js-exec.d.ts +19 -1
  90. package/dist/commands/js-exec/worker.d.ts +8 -0
  91. package/dist/commands/worker-bridge/bridge-handler.d.ts +3 -1
  92. package/dist/commands/worker-bridge/protocol.d.ts +1 -0
  93. package/dist/commands/worker-bridge/sync-backend.d.ts +5 -0
  94. package/dist/executor-init.d.ts +10 -0
  95. package/dist/fs/sanitize-error.d.ts +9 -6
  96. package/dist/interpreter/interpreter.d.ts +2 -0
  97. package/dist/interpreter/types.d.ts +5 -0
  98. package/dist/network/allow-list.d.ts +3 -2
  99. package/dist/network/types.d.ts +3 -0
  100. package/dist/types.d.ts +6 -0
  101. package/package.json +37 -34
  102. package/vendor/cpython-emscripten/python.wasm +0 -0
  103. package/vendor/executor/executor-sdk-bundle.d.mts +18 -0
  104. package/vendor/executor/executor-sdk-bundle.mjs +972 -0
  105. package/dist/bin/chunks/chunk-SYG3IW7P.js +0 -2
  106. package/dist/bin/chunks/chunk-TKTKRRAL.js +0 -11
  107. package/dist/bin/chunks/expr-VEFRBJT4.js +0 -2
  108. package/dist/bin/chunks/python3-PF7AHNQM.js +0 -12
  109. package/dist/bin/chunks/time-DDS6JJ23.js +0 -2
  110. package/dist/bin/shell/chunks/chunk-SYG3IW7P.js +0 -2
  111. package/dist/bin/shell/chunks/chunk-TKTKRRAL.js +0 -11
  112. package/dist/bin/shell/chunks/expr-VEFRBJT4.js +0 -2
  113. package/dist/bin/shell/chunks/python3-J7DP4JBQ.js +0 -12
  114. package/dist/bin/shell/chunks/time-DDS6JJ23.js +0 -2
  115. package/dist/bundle/chunks/chunk-CCNMISUL.js +0 -1
  116. package/dist/bundle/chunks/chunk-H2WXJGD7.js +0 -10
  117. package/dist/bundle/chunks/expr-74QHYJL5.js +0 -1
  118. package/dist/bundle/chunks/python3-6HF56IYI.js +0 -11
  119. package/dist/bundle/chunks/time-YG5BMRIQ.js +0 -1
@@ -1530,7 +1530,9 @@ var OpCode = {
1530
1530
  // HTTP operations
1531
1531
  HTTP_REQUEST: 200,
1532
1532
  // Sub-shell execution
1533
- EXEC_COMMAND: 300
1533
+ EXEC_COMMAND: 300,
1534
+ // Tool invocation (executor mode)
1535
+ INVOKE_TOOL: 400
1534
1536
  };
1535
1537
  var Status = {
1536
1538
  PENDING: 0,
@@ -2003,6 +2005,18 @@ var SyncBackend = class {
2003
2005
  const responseJson = new TextDecoder().decode(result.result);
2004
2006
  return JSON.parse(responseJson);
2005
2007
  }
2008
+ /**
2009
+ * Invoke a tool through the main thread's tool invoker (executor mode).
2010
+ * Returns the JSON-serialized result.
2011
+ */
2012
+ invokeTool(path, argsJson) {
2013
+ const requestData = argsJson ? new TextEncoder().encode(argsJson) : void 0;
2014
+ const result = this.execSync(OpCode.INVOKE_TOOL, path, requestData);
2015
+ if (!result.success) {
2016
+ throw new Error(result.error || "Tool invocation failed");
2017
+ }
2018
+ return new TextDecoder().decode(result.result);
2019
+ }
2006
2020
  };
2007
2021
 
2008
2022
  // src/commands/js-exec/fetch-polyfill.ts
@@ -3813,6 +3827,26 @@ function setupContext(context, backend, input) {
3813
3827
  );
3814
3828
  context.setProp(context.global, "__execArgs", execArgsFn);
3815
3829
  execArgsFn.dispose();
3830
+ if (input.hasExecutorTools || input.executorMode) {
3831
+ const invokeToolFn = context.newFunction(
3832
+ "__invokeTool",
3833
+ (pathHandle, argsHandle) => {
3834
+ const path = context.getString(pathHandle);
3835
+ const argsJson = context.getString(argsHandle);
3836
+ try {
3837
+ const resultJson = backend.invokeTool(path, argsJson);
3838
+ return context.newString(resultJson);
3839
+ } catch (e) {
3840
+ return throwError(
3841
+ context,
3842
+ e.message || "tool invocation failed"
3843
+ );
3844
+ }
3845
+ }
3846
+ );
3847
+ context.setProp(context.global, "__invokeTool", invokeToolFn);
3848
+ invokeToolFn.dispose();
3849
+ }
3816
3850
  const envObj = jsToHandle(context, input.env);
3817
3851
  context.setProp(context.global, "env", envObj);
3818
3852
  envObj.dispose();
@@ -4070,6 +4104,78 @@ async function initializeWithDefense() {
4070
4104
  ]
4071
4105
  });
4072
4106
  }
4107
+ var TOOLS_ONLY_SETUP_SOURCE = `(function() {
4108
+ globalThis.tools = (function makeProxy(path) {
4109
+ return new Proxy(function(){}, {
4110
+ get: function(_t, prop) {
4111
+ if (prop === 'then' || typeof prop === 'symbol') return undefined;
4112
+ return makeProxy(path.concat([String(prop)]));
4113
+ },
4114
+ apply: function(_t, _this, args) {
4115
+ var toolPath = path.join('.');
4116
+ if (!toolPath) throw new Error('Tool path missing in invocation');
4117
+ var argsJson = args[0] !== undefined ? JSON.stringify(args[0]) : '{}';
4118
+ var resultJson = globalThis.__invokeTool(toolPath, argsJson);
4119
+ return resultJson !== undefined && resultJson !== '' ? JSON.parse(resultJson) : undefined;
4120
+ }
4121
+ });
4122
+ })([]);
4123
+ })();`;
4124
+ var EXECUTOR_SETUP_SOURCE = `(function() {
4125
+ var __logs = [];
4126
+ globalThis[Symbol.for('jb:executorLogs')] = __logs;
4127
+
4128
+ var _fmt = function(v) {
4129
+ if (typeof v === 'string') return v;
4130
+ try { return JSON.stringify(v); }
4131
+ catch(e) { return String(v); }
4132
+ };
4133
+
4134
+ globalThis.console = {
4135
+ log: function() { var a = []; for(var i=0;i<arguments.length;i++) a.push(_fmt(arguments[i])); __logs.push('[log] ' + a.join(' ')); },
4136
+ error: function() { var a = []; for(var i=0;i<arguments.length;i++) a.push(_fmt(arguments[i])); __logs.push('[error] ' + a.join(' ')); },
4137
+ warn: function() { var a = []; for(var i=0;i<arguments.length;i++) a.push(_fmt(arguments[i])); __logs.push('[warn] ' + a.join(' ')); },
4138
+ info: function() { var a = []; for(var i=0;i<arguments.length;i++) a.push(_fmt(arguments[i])); __logs.push('[info] ' + a.join(' ')); },
4139
+ debug: function() { var a = []; for(var i=0;i<arguments.length;i++) a.push(_fmt(arguments[i])); __logs.push('[debug] ' + a.join(' ')); },
4140
+ };
4141
+
4142
+ globalThis.tools = (function makeProxy(path) {
4143
+ return new Proxy(function(){}, {
4144
+ get: function(_t, prop) {
4145
+ if (prop === 'then' || typeof prop === 'symbol') return undefined;
4146
+ return makeProxy(path.concat([String(prop)]));
4147
+ },
4148
+ apply: function(_t, _this, args) {
4149
+ var toolPath = path.join('.');
4150
+ if (!toolPath) throw new Error('Tool path missing in invocation');
4151
+ var argsJson = args[0] !== undefined ? JSON.stringify(args[0]) : '{}';
4152
+ var resultJson = globalThis.__invokeTool(toolPath, argsJson);
4153
+ return resultJson !== undefined && resultJson !== '' ? JSON.parse(resultJson) : undefined;
4154
+ }
4155
+ });
4156
+ })([]);
4157
+ })();`;
4158
+ function readExecutorLogs(context) {
4159
+ const logsResult = context.evalCode(
4160
+ `globalThis[Symbol.for('jb:executorLogs')]`,
4161
+ "<read-logs>"
4162
+ );
4163
+ if (logsResult.error) {
4164
+ logsResult.error.dispose();
4165
+ return [];
4166
+ }
4167
+ const logs = context.dump(logsResult.value);
4168
+ logsResult.value.dispose();
4169
+ return Array.isArray(logs) ? logs : [];
4170
+ }
4171
+ function readPropDump(context, handle, key) {
4172
+ const prop = context.getProp(handle, key);
4173
+ try {
4174
+ return context.dump(prop);
4175
+ } finally {
4176
+ prop.dispose();
4177
+ }
4178
+ }
4073
4179
  async function executeCode(input) {
4074
4180
  const qjs = await getQuickJSModule();
4075
4181
  const backend = new SyncBackend(input.sharedBuffer, input.timeoutMs);
@@ -4277,6 +4383,132 @@ async function executeCode(input) {
4277
4383
  }
4278
4384
  bootstrapResult.value.dispose();
4279
4385
  }
4386
+ if (input.hasExecutorTools && !input.executorMode) {
4387
+ const toolsSetupResult = context.evalCode(
4388
+ TOOLS_ONLY_SETUP_SOURCE,
4389
+ "<tools-setup>"
4390
+ );
4391
+ if (toolsSetupResult.error) {
4392
+ toolsSetupResult.error.dispose();
4393
+ } else {
4394
+ toolsSetupResult.value.dispose();
4395
+ }
4396
+ }
4397
+ if (input.executorMode) {
4398
+ const executorSetupResult = context.evalCode(
4399
+ EXECUTOR_SETUP_SOURCE,
4400
+ "<executor-setup>"
4401
+ );
4402
+ if (executorSetupResult.error) {
4403
+ const errVal = context.dump(executorSetupResult.error);
4404
+ executorSetupResult.error.dispose();
4405
+ backend.exit(1);
4406
+ return {
4407
+ success: true,
4408
+ error: formatError(errVal),
4409
+ executorLogs: []
4410
+ };
4411
+ }
4412
+ executorSetupResult.value.dispose();
4413
+ const wrappedCode = `(async () => {
4414
+ ${input.jsCode}
4415
+ })()`;
4416
+ const evalResult = context.evalCode(wrappedCode, "<executor>");
4417
+ if (evalResult.error) {
4418
+ const errorVal = context.dump(evalResult.error);
4419
+ evalResult.error.dispose();
4420
+ const errorMsg = formatError(errorVal);
4421
+ backend.exit(1);
4422
+ return {
4423
+ success: true,
4424
+ executorLogs: readExecutorLogs(context),
4425
+ error: errorMsg
4426
+ };
4427
+ }
4428
+ context.setProp(context.global, "__executorPromise", evalResult.value);
4429
+ evalResult.value.dispose();
4430
+ const stateResult = context.evalCode(
4431
+ [
4432
+ "(function(p){",
4433
+ " var s = { v: void 0, e: void 0, settled: false };",
4434
+ " var fmtErr = function(e) {",
4435
+ " if (e && typeof e === 'object') {",
4436
+ " var m = typeof e.message === 'string' ? e.message : '';",
4437
+ " var st = typeof e.stack === 'string' ? e.stack : '';",
4438
+ " if (m && st) return st.indexOf(m) === -1 ? m + '\\n' + st : st;",
4439
+ " if (m) return m; if (st) return st;",
4440
+ " }",
4441
+ " return String(e);",
4442
+ " };",
4443
+ " p.then(",
4444
+ " function(v){ s.v = v; s.settled = true; },",
4445
+ " function(e){ s.e = fmtErr(e); s.settled = true; }",
4446
+ " );",
4447
+ " return s;",
4448
+ "})(__executorPromise)"
4449
+ ].join("\n"),
4450
+ "<state-tracker>"
4451
+ );
4452
+ if (stateResult.error) {
4453
+ const errorVal = context.dump(stateResult.error);
4454
+ stateResult.error.dispose();
4455
+ backend.exit(1);
4456
+ return {
4457
+ success: true,
4458
+ executorLogs: readExecutorLogs(context),
4459
+ error: formatError(errorVal)
4460
+ };
4461
+ }
4462
+ const stateHandle = stateResult.value;
4463
+ const pendingResult = runtime.executePendingJobs();
4464
+ if ("error" in pendingResult && pendingResult.error) {
4465
+ const errorVal = context.dump(pendingResult.error);
4466
+ pendingResult.error.dispose();
4467
+ const rawMsg = typeof errorVal === "object" && errorVal !== null && "message" in errorVal ? errorVal.message : String(errorVal);
4468
+ if (rawMsg !== "__EXIT__") {
4469
+ stateHandle.dispose();
4470
+ backend.exit(1);
4471
+ return {
4472
+ success: true,
4473
+ executorLogs: readExecutorLogs(context),
4474
+ error: formatError(errorVal)
4475
+ };
4476
+ }
4477
+ }
4478
+ const settled = readPropDump(context, stateHandle, "settled");
4479
+ const value = readPropDump(context, stateHandle, "v");
4480
+ const stateError = readPropDump(context, stateHandle, "e");
4481
+ stateHandle.dispose();
4482
+ const logs = readExecutorLogs(context);
4483
+ if (!settled) {
4484
+ backend.exit(0);
4485
+ return {
4486
+ success: true,
4487
+ executorLogs: logs,
4488
+ error: "Execution did not settle"
4489
+ };
4490
+ }
4491
+ if (typeof stateError !== "undefined") {
4492
+ backend.exit(0);
4493
+ return {
4494
+ success: true,
4495
+ executorLogs: logs,
4496
+ error: String(stateError)
4497
+ };
4498
+ }
4499
+ let resultJson;
4500
+ try {
4501
+ resultJson = value !== void 0 ? JSON.stringify(value) : void 0;
4502
+ } catch {
4503
+ resultJson = void 0;
4504
+ }
4505
+ backend.exit(0);
4506
+ return {
4507
+ success: true,
4508
+ executorResult: resultJson,
4509
+ executorLogs: logs
4510
+ };
4511
+ }
4280
4512
  const filename = input.scriptPath || "<eval>";
4281
4513
  let jsCode = input.jsCode;
4282
4514
  if (input.stripTypes) {
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a,b}from"./chunk-YX7OOTPO.js";import"./chunk-SYG3IW7P.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as lnCommand};
2
+ import{a,b}from"./chunk-AZ3RUDR2.js";import"./chunk-RLNOQILG.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as lnCommand};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a,b}from"./chunk-OQV5J23L.js";import"./chunk-SYG3IW7P.js";import"./chunk-JBABAK44.js";import"./chunk-4VDEBYW7.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as mkdirCommand};
2
+ import{a,b}from"./chunk-7G3MC56B.js";import"./chunk-RLNOQILG.js";import"./chunk-JBABAK44.js";import"./chunk-4VDEBYW7.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as mkdirCommand};
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import{a as _,b as O}from"./chunk-MNMRGJJM.js";import"./chunk-4OALHZXB.js";import"./chunk-MY5PY2PL.js";import"./chunk-LIYVQA3X.js";import{a as v,b as T}from"./chunk-OOJCYVYF.js";import{a as D}from"./chunk-4PRVMER6.js";import{c as y}from"./chunk-MO4RPBN2.js";import{b as C}from"./chunk-YU6OGPZR.js";import{a as M,b as c}from"./chunk-RLNOQILG.js";import{a as E}from"./chunk-4VDEBYW7.js";import{a as b,b as P}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";import{randomBytes as $}from"node:crypto";import{fileURLToPath as Q}from"node:url";import{Worker as R}from"node:worker_threads";var U=1e4,H=6e4,I={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 L(r){let e={code:null,module:null,scriptFile:null,showVersion:!1,scriptArgs:[]};if(r.length===0)return e;let t=r.findIndex(o=>!o.startsWith("-")||o==="-"||o==="--");for(let o=0;o<(t===-1?r.length:t);o++){let s=r[o];if(s==="-c")return o+1>=r.length?{stdout:"",stderr:`python3: option requires an argument -- 'c'
3
+ `,exitCode:2}:(e.code=r[o+1],e.scriptArgs=r.slice(o+2),e);if(s==="-m")return o+1>=r.length?{stdout:"",stderr:`python3: option requires an argument -- 'm'
4
+ `,exitCode:2}:(e.module=r[o+1],e.scriptArgs=r.slice(o+2),e);if(s==="--version"||s==="-V")return e.showVersion=!0,e;if(s.startsWith("-")&&s!=="-")return{stdout:"",stderr:`python3: unrecognized option '${s}'
5
+ `,exitCode:2}}if(t!==-1){let o=r[t];o==="--"?t+1<r.length&&(e.scriptFile=r[t+1],e.scriptArgs=r.slice(t+2)):(e.scriptFile=o,e.scriptArgs=r.slice(t+1))}return e}var k=new WeakMap;function z(r){let e=k.get(r);return e||(e={executionQueue:[],isExecuting:!1},k.set(r,e)),e}function ie(){k=new WeakMap}var N=Q(new URL("./worker.js",import.meta.url));function B(){return $(16).toString("hex")}function V(r,e){if(!r||typeof r!="object")return{success:!1,error:"Malformed worker response"};let t=r;return typeof t.protocolToken!="string"||t.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}:t.type==="security-violation"?{success:!1,error:`Security violation: ${typeof t.violation?.type=="string"?t.violation.type:"unknown"}`}:typeof t.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:t.success?{success:!0}:{success:!1,error:typeof t.error=="string"&&t.error.length>0?t.error:"Worker execution failed"}}function a(r){if(r.isExecuting||r.executionQueue.length===0)return;for(;r.executionQueue.length>0&&r.executionQueue[0].canceled;)r.executionQueue.shift();if(r.executionQueue.length===0)return;let e=r.executionQueue.shift();if(!e)return;r.isExecuting=!0;let t;try{t=C.runTrusted(()=>new R(N,{workerData:e.input}))}catch(n){let i=n instanceof Error?n.message:String(n);e.resolve({success:!1,error:c(i)}),r.isExecuting=!1,a(r);return}e.workerRef&&(e.workerRef.current=t);let o=y(e.requireDefenseContext,"python3","worker message callback",n=>{e.resolve(V(n,e.input.protocolToken)),r.isExecuting=!1,t.terminate(),a(r)}),s=y(e.requireDefenseContext,"python3","worker error callback",n=>{let i=c(E(n));e.resolve({success:!1,error:i}),r.isExecuting=!1,a(r)}),p=y(e.requireDefenseContext,"python3","worker exit callback",()=>{r.isExecuting&&(e.resolve({success:!1,error:"Worker exited unexpectedly"}),r.isExecuting=!1,a(r))}),f=n=>{try{o(n)}catch(i){let m=i instanceof Error?i.message:String(i);e.resolve({success:!1,error:c(m)}),r.isExecuting=!1,t.terminate(),a(r)}},l=n=>{try{s(n)}catch(i){let m=i instanceof Error?i.message:String(i);e.resolve({success:!1,error:c(m)}),r.isExecuting=!1,a(r)}},g=()=>{try{p()}catch(n){let i=n instanceof Error?n.message:String(n);e.resolve({success:!1,error:c(i)}),r.isExecuting=!1,a(r)}};t.on("message",f),t.on("error",l),t.on("exit",g)}async function j(r,e,t,o=[]){let s=_(),p=new O(s,e.fs,e.cwd,"python3",e.fetch,e.limits?.maxOutputSize??0),f=e.limits?.maxPythonTimeoutMs??U,l=e.fetch?Math.max(f,H):f,g=z(e.fs),n={protocolToken:B(),sharedBuffer:s,pythonCode:r,cwd:e.cwd,env:D(e.env),args:o,scriptPath:t,timeoutMs:l},i={current:null},m=new Promise(u=>{let d={input:n,resolve:()=>{},workerRef:i,requireDefenseContext:e.requireDefenseContext},A=y(e.requireDefenseContext,"python3","worker timeout callback",()=>{i.current?i.current.terminate():d.canceled=!0,u({success:!1,error:`Execution timeout: exceeded ${l}ms limit`})}),F=v(()=>{try{A()}catch(h){let W=h instanceof Error?h.message:String(h);u({success:!1,error:c(W)})}},l);d.resolve=h=>{T(F),u(h)},g.executionQueue.push(d),a(g)}),[x,w]=await Promise.all([p.run(l).catch(u=>({stdout:"",stderr:`python3: bridge error: ${c(E(u))}
6
+ `,exitCode:1})),m.catch(u=>({success:!1,error:c(E(u))}))]);if(!w.success&&w.error){let u=c(w.error);return{stdout:x.stdout,stderr:`${x.stderr}python3: ${u}
7
+ `,exitCode:x.exitCode||1}}return x}var Y={name:"python3",async execute(r,e){if(P(r))return b(I);let t=L(r);if("exitCode"in t)return t;if(t.showVersion)return{stdout:`Python 3.13.2 (Emscripten)
8
+ `,stderr:"",exitCode:0};let o,s;if(t.code!==null)o=t.code,s="-c";else if(t.module!==null){if(!/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(t.module))return{stdout:"",stderr:`python3: No module named '${t.module.slice(0,200)}'
9
+ `,exitCode:1};o=`import runpy; runpy.run_module('${t.module}', run_name='__main__')`,s=t.module}else if(t.scriptFile!==null){let p=e.fs.resolvePath(e.cwd,t.scriptFile);if(!await e.fs.exists(p))return{stdout:"",stderr:`python3: can't open file '${t.scriptFile}': [Errno 2] No such file or directory
10
+ `,exitCode:2};try{o=await e.fs.readFile(p),s=t.scriptFile}catch(f){let l=M(f.message);return{stdout:"",stderr:`python3: can't open file '${t.scriptFile}': ${l}
11
+ `,exitCode:2}}}else if(e.stdin.trim())o=e.stdin,s="<stdin>";else return{stdout:"",stderr:`python3: no input provided (use -c CODE, -m MODULE, or provide a script file)
12
+ `,exitCode:2};return j(o,e,s,t.scriptArgs)}},ce={name:"python",async execute(r,e){return Y.execute(r,e)}};export{ie as _resetExecutionQueue,Y as python3Command,ce as pythonCommand};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a,b}from"./chunk-R2LDP472.js";import"./chunk-SYG3IW7P.js";import"./chunk-JBABAK44.js";import"./chunk-4VDEBYW7.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as rmCommand};
2
+ import{a,b}from"./chunk-EPPBDXOG.js";import"./chunk-RLNOQILG.js";import"./chunk-JBABAK44.js";import"./chunk-4VDEBYW7.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as rmCommand};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a,b}from"./chunk-VVFGRIJZ.js";import"./chunk-MO4RPBN2.js";import"./chunk-YU6OGPZR.js";import"./chunk-SE4C7FJY.js";import"./chunk-6KZRLMG3.js";import"./chunk-SYG3IW7P.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as sedCommand};
2
+ import{a,b}from"./chunk-RMQC3GS7.js";import"./chunk-MO4RPBN2.js";import"./chunk-YU6OGPZR.js";import"./chunk-SE4C7FJY.js";import"./chunk-6KZRLMG3.js";import"./chunk-RLNOQILG.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as sedCommand};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a,b,c}from"./chunk-UPUMZYZE.js";import"./chunk-OOJCYVYF.js";import"./chunk-MO4RPBN2.js";import"./chunk-YU6OGPZR.js";import"./chunk-SYG3IW7P.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{a as _internals,c as flagsForFuzzing,b as sqlite3Command};
2
+ import{a,b,c}from"./chunk-CM4532DS.js";import"./chunk-OOJCYVYF.js";import"./chunk-MO4RPBN2.js";import"./chunk-YU6OGPZR.js";import"./chunk-RLNOQILG.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{a as _internals,c as flagsForFuzzing,b as sqlite3Command};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{a,b}from"./chunk-WXMBDX4P.js";import"./chunk-4OALHZXB.js";import"./chunk-LIYVQA3X.js";import"./chunk-4PRVMER6.js";import"./chunk-RLNOQILG.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as timeCommand};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a,b}from"./chunk-SYL34GE7.js";import"./chunk-SYG3IW7P.js";import"./chunk-JBABAK44.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as trCommand};
2
+ import{a,b}from"./chunk-NAX7MTAR.js";import"./chunk-RLNOQILG.js";import"./chunk-JBABAK44.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as trCommand};
@@ -11,17 +11,29 @@ import { dirname } from "node:path";
11
11
  import { parentPort, workerData } from "node:worker_threads";
12
12
 
13
13
  // src/fs/sanitize-error.ts
14
- function sanitizeErrorMessage(message) {
14
+ function sanitizeWithUnixPrefixes(message, includeHostRuntimePrefixes, includeFileUrls) {
15
15
  if (!message) return message;
16
16
  let sanitized = message.replace(/\n\s+at\s.*/g, "");
17
+ if (includeFileUrls) {
18
+ sanitized = sanitized.replace(/\bfile:\/\/\/?[^\s'",)}\]:]+/g, "<path>");
19
+ }
17
20
  sanitized = sanitized.replace(
18
- /(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap))\b[^\s'",)}\]:]*/g,
21
+ includeHostRuntimePrefixes ? /(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap|workspace|root|srv|mnt|app))\b[^\s'",)}\]:]*/g : /(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap))\b[^\s'",)}\]:]*/g,
19
22
  "<path>"
20
23
  );
21
24
  sanitized = sanitized.replace(/node:internal\/[^\s'",)}\]:]+/g, "<internal>");
22
25
  sanitized = sanitized.replace(/[A-Z]:\\[^\s'",)}\]:]+/g, "<path>");
26
+ if (includeFileUrls) {
27
+ sanitized = sanitized.replace(/\\\\[^\s\\]+\\[^\s'",)}\]:]+/g, "<path>");
28
+ }
23
29
  return sanitized;
24
30
  }
31
+ function sanitizeErrorMessage(message) {
32
+ return sanitizeWithUnixPrefixes(message, false, false);
33
+ }
34
+ function sanitizeHostErrorMessage(message) {
35
+ return sanitizeWithUnixPrefixes(message, true, true);
36
+ }
25
37
 
26
38
  // src/security/blocked-globals.ts
27
39
  function getBlockedGlobals() {
@@ -1557,7 +1569,9 @@ var OpCode = {
1557
1569
  // HTTP operations
1558
1570
  HTTP_REQUEST: 200,
1559
1571
  // Sub-shell execution
1560
- EXEC_COMMAND: 300
1572
+ EXEC_COMMAND: 300,
1573
+ // Tool invocation (executor mode)
1574
+ INVOKE_TOOL: 400
1561
1575
  };
1562
1576
  var Status = {
1563
1577
  PENDING: 0,
@@ -2030,6 +2044,18 @@ var SyncBackend = class {
2030
2044
  const responseJson = new TextDecoder().decode(result.result);
2031
2045
  return JSON.parse(responseJson);
2032
2046
  }
2047
+ /**
2048
+ * Invoke a tool through the main thread's tool invoker (executor mode).
2049
+ * Returns the JSON-serialized result.
2050
+ */
2051
+ invokeTool(path, argsJson) {
2052
+ const requestData = argsJson ? new TextEncoder().encode(argsJson) : void 0;
2053
+ const result = this.execSync(OpCode.INVOKE_TOOL, path, requestData);
2054
+ if (!result.success) {
2055
+ throw new Error(result.error || "Tool invocation failed");
2056
+ }
2057
+ return new TextDecoder().decode(result.result);
2058
+ }
2033
2059
  };
2034
2060
 
2035
2061
  // src/commands/python3/worker.ts
@@ -2760,7 +2786,7 @@ function createHTTPFS(backend, FS) {
2760
2786
  });
2761
2787
  lastResponse = encoder.encode(JSON.stringify(result));
2762
2788
  } catch (e) {
2763
- const message = sanitizeErrorMessage(e.message);
2789
+ const message = sanitizeHostErrorMessage(e.message);
2764
2790
  lastResponse = encoder.encode(JSON.stringify({ error: message }));
2765
2791
  }
2766
2792
  }
@@ -2973,7 +2999,7 @@ async function runPython(input) {
2973
2999
  printErr: onPrintErr
2974
3000
  });
2975
3001
  } catch (e) {
2976
- const message = sanitizeErrorMessage(e.message);
3002
+ const message = sanitizeHostErrorMessage(e.message);
2977
3003
  return {
2978
3004
  success: false,
2979
3005
  error: `Failed to load CPython: ${message}`
@@ -2988,7 +3014,7 @@ async function runPython(input) {
2988
3014
  Module.FS.mkdir("/host");
2989
3015
  Module.FS.mount(HOSTFS, { root: "/" }, "/host");
2990
3016
  } catch (e) {
2991
- const message = sanitizeErrorMessage(e.message);
3017
+ const message = sanitizeHostErrorMessage(e.message);
2992
3018
  return {
2993
3019
  success: false,
2994
3020
  error: `Failed to mount HOSTFS: ${message}`
@@ -2999,7 +3025,7 @@ async function runPython(input) {
2999
3025
  Module.FS.mkdir("/_jb_http");
3000
3026
  Module.FS.mount(HTTPFS, { root: "/" }, "/_jb_http");
3001
3027
  } catch (e) {
3002
- const message = sanitizeErrorMessage(e.message);
3028
+ const message = sanitizeHostErrorMessage(e.message);
3003
3029
  return {
3004
3030
  success: false,
3005
3031
  error: `Failed to mount HTTPFS: ${message}`
@@ -3079,7 +3105,7 @@ process.on("uncaughtException", (e) => {
3079
3105
  if (!activeProtocolToken) {
3080
3106
  return;
3081
3107
  }
3082
- const message = sanitizeErrorMessage(e.message);
3108
+ const message = sanitizeHostErrorMessage(e.message);
3083
3109
  postWorkerMessage(activeProtocolToken, {
3084
3110
  success: false,
3085
3111
  error: `Worker uncaught exception: ${message}`
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a,b}from"./chunk-LGF54XJQ.js";import"./chunk-QSDVMMYI.js";import"./chunk-ZO5PSLKR.js";import"./chunk-V7ZOPVQS.js";import"./chunk-4PRVMER6.js";import"./chunk-MO4RPBN2.js";import"./chunk-YU6OGPZR.js";import"./chunk-SE4C7FJY.js";import"./chunk-6KZRLMG3.js";import"./chunk-SYG3IW7P.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as yqCommand};
2
+ import{a,b}from"./chunk-L2JBII6Z.js";import"./chunk-QSDVMMYI.js";import"./chunk-ZO5PSLKR.js";import"./chunk-V7ZOPVQS.js";import"./chunk-4PRVMER6.js";import"./chunk-MO4RPBN2.js";import"./chunk-YU6OGPZR.js";import"./chunk-SE4C7FJY.js";import"./chunk-6KZRLMG3.js";import"./chunk-RLNOQILG.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{b as flagsForFuzzing,a as yqCommand};