@jerryan/just-bash 3.8.0 → 3.9.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/CHANGELOG.md +14 -0
- package/README.md +5 -15
- package/dist/AGENTS.md +2 -2
- package/dist/Bash.d.ts +2 -4
- package/dist/bin/chunks/{chunk-7WBCA2BB.js → chunk-3DWQCLNP.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-MPFNZYEA.js → chunks/chunk-6JEDM6CZ.js} +1 -1
- package/dist/bin/chunks/{chunk-QFTZKD5O.js → chunk-6TUILMPB.js} +1 -1
- package/dist/bin/chunks/chunk-E54Z6VIE.js +12 -0
- package/dist/bin/chunks/chunk-GBKR5KTT.js +44 -0
- package/dist/bin/{shell/chunks/chunk-MF3GVFLC.js → chunks/chunk-L345YZ6R.js} +1 -1
- package/dist/bin/chunks/chunk-QKJAAJ7J.js +3 -0
- package/dist/bin/chunks/{diff-JSJ56EOK.js → diff-DM47S5PT.js} +1 -1
- package/dist/bin/{shell/chunks/flag-coverage-2H5CPEM6.js → chunks/flag-coverage-LLAQBVIG.js} +1 -1
- package/dist/bin/chunks/js-exec-ZAAIZQWI.js +99 -0
- package/dist/bin/chunks/js-exec-worker.js +4995 -0
- package/dist/bin/chunks/python3-TJ6DCPIA.js +14 -0
- package/dist/bin/chunks/{sleep-DVFE2GSF.js → sleep-MOJQBZMY.js} +1 -1
- package/dist/bin/{shell/chunks/sqlite3-KNN6V2W6.js → chunks/sqlite3-CXQTZRPZ.js} +1 -1
- package/dist/bin/chunks/{timeout-YGFHQJKX.js → timeout-RQOWSWYG.js} +1 -1
- package/dist/bin/just-bash.js +1 -1
- package/dist/bin/shell/chunks/{chunk-7WBCA2BB.js → chunk-3DWQCLNP.js} +1 -1
- package/dist/bin/{chunks/chunk-MPFNZYEA.js → shell/chunks/chunk-6JEDM6CZ.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-QFTZKD5O.js → chunk-6TUILMPB.js} +1 -1
- package/dist/bin/shell/chunks/chunk-E54Z6VIE.js +12 -0
- package/dist/bin/shell/chunks/chunk-GBKR5KTT.js +44 -0
- package/dist/bin/{chunks/chunk-MF3GVFLC.js → shell/chunks/chunk-L345YZ6R.js} +1 -1
- package/dist/bin/shell/chunks/chunk-QKJAAJ7J.js +3 -0
- package/dist/bin/shell/chunks/{diff-JSJ56EOK.js → diff-DM47S5PT.js} +1 -1
- package/dist/bin/{chunks/flag-coverage-2H5CPEM6.js → shell/chunks/flag-coverage-LLAQBVIG.js} +1 -1
- package/dist/bin/shell/chunks/js-exec-ZAAIZQWI.js +99 -0
- package/dist/bin/shell/chunks/python3-TJ6DCPIA.js +14 -0
- package/dist/bin/shell/chunks/{sleep-DVFE2GSF.js → sleep-MOJQBZMY.js} +1 -1
- package/dist/bin/{chunks/sqlite3-KNN6V2W6.js → shell/chunks/sqlite3-CXQTZRPZ.js} +1 -1
- package/dist/bin/shell/chunks/{timeout-YGFHQJKX.js → timeout-RQOWSWYG.js} +1 -1
- package/dist/bin/shell/shell.js +1 -1
- package/dist/bundle/browser.js +596 -579
- package/dist/bundle/chunks/{chunk-N3A4JVFJ.js → chunk-6IA4DXG2.js} +1 -1
- package/dist/bundle/chunks/chunk-BS6EJR2R.js +11 -0
- package/dist/bundle/chunks/chunk-E2F4A3CM.js +43 -0
- package/dist/bundle/chunks/{chunk-GNPLDVBD.js → chunk-H3A45X3W.js} +1 -1
- package/dist/bundle/chunks/chunk-PS2RJNZZ.js +2 -0
- package/dist/bundle/chunks/{chunk-DMWNBCXJ.js → chunk-TLPMB3FO.js} +1 -1
- package/dist/bundle/chunks/{chunk-XV2V56NQ.js → chunk-YFFU74KY.js} +1 -1
- package/dist/bundle/chunks/{diff-VDB6RXHO.js → diff-R7TXVVLN.js} +1 -1
- package/dist/bundle/chunks/{flag-coverage-UMQ3BWDP.js → flag-coverage-YQGACUSN.js} +1 -1
- package/dist/bundle/chunks/js-exec-MUZRDUJ3.js +98 -0
- package/dist/bundle/chunks/js-exec-worker.js +4995 -0
- package/dist/bundle/chunks/python3-W4UMQJAQ.js +13 -0
- package/dist/bundle/chunks/{sleep-PPRBTSVR.js → sleep-25QUPVDK.js} +1 -1
- package/dist/bundle/chunks/{sqlite3-KB3MXTTM.js → sqlite3-DQNCWDG5.js} +1 -1
- package/dist/bundle/chunks/{timeout-C6WDYPLV.js → timeout-37GM7IIL.js} +1 -1
- package/dist/bundle/index.cjs +1128 -2663
- package/dist/bundle/index.js +2 -2
- package/dist/commands/js-exec/js-exec-worker.d.ts +35 -0
- package/dist/commands/js-exec/js-exec.d.ts +14 -1
- package/dist/fs/vfs-template.d.ts +6 -0
- package/dist/interpreter/interpreter.d.ts +1 -1
- package/dist/interpreter/types.d.ts +1 -1
- package/dist/limits.d.ts +2 -2
- package/dist/timers.d.ts +9 -0
- package/dist/types.d.ts +3 -4
- package/package.json +8 -8
- package/dist/bin/chunks/chunk-2NJJXU4K.js +0 -27
- package/dist/bin/chunks/chunk-PPVF2N6C.js +0 -3
- package/dist/bin/chunks/js-exec-T3SAB2B6.js +0 -1651
- package/dist/bin/chunks/python3-3ERN3L6S.js +0 -23
- package/dist/bin/shell/chunks/chunk-2NJJXU4K.js +0 -27
- package/dist/bin/shell/chunks/chunk-PPVF2N6C.js +0 -3
- package/dist/bin/shell/chunks/js-exec-T3SAB2B6.js +0 -1651
- package/dist/bin/shell/chunks/python3-3ERN3L6S.js +0 -23
- package/dist/bundle/chunks/chunk-B6OSJB22.js +0 -26
- package/dist/bundle/chunks/chunk-WXPNKIIH.js +0 -2
- package/dist/bundle/chunks/js-exec-ZQMIYQTH.js +0 -1650
- package/dist/bundle/chunks/python3-QB7OE256.js +0 -22
- package/dist/commands/js-exec/run-runtime.d.ts +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# just-bash
|
|
2
2
|
|
|
3
|
+
## 3.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`00e40f9`](https://github.com/JerryAZR/just-bash/commit/00e40f927dfa0c6b77cadf063be094282ced2a5a) Thanks [@JerryAZR](https://github.com/JerryAZR)! - Add `diff -r` (recursive directory comparison), `diff -rq` (brief recursive), and `diff -N` (treat absent files as empty). No new dependencies.
|
|
8
|
+
|
|
9
|
+
- [`00e40f9`](https://github.com/JerryAZR/just-bash/commit/00e40f927dfa0c6b77cadf063be094282ced2a5a) Thanks [@JerryAZR](https://github.com/JerryAZR)! - Expose `maxJsMemoryBytes` in `ExecutionLimits` — the QuickJS heap limit (default 64MB) is now configurable per Bash instance. This is the only real cap on js-exec read/write sizes.
|
|
10
|
+
|
|
11
|
+
- [`00e40f9`](https://github.com/JerryAZR/just-bash/commit/00e40f927dfa0c6b77cadf063be094282ced2a5a) Thanks [@JerryAZR](https://github.com/JerryAZR)! - Add `readOnly` option to `VfsTemplateOptions` — when true, all fork overlay mounts are read-only (EROFS on writes).
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`00e40f9`](https://github.com/JerryAZR/just-bash/commit/00e40f927dfa0c6b77cadf063be094282ced2a5a) Thanks [@JerryAZR](https://github.com/JerryAZR)! - Fix a class of CI failures where js-exec guest output was lost: loop `executePendingJobs()` until all QuickJS jobs drain, not just the first batch.
|
|
16
|
+
|
|
3
17
|
## 3.8.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -493,7 +493,7 @@ await env.exec('js-exec -c "console.log(API_BASE)"');
|
|
|
493
493
|
|
|
494
494
|
`fs.readFileSync()` returns a `Buffer` by default (matching Node.js). Pass an encoding like `'utf8'` to get a string.
|
|
495
495
|
|
|
496
|
-
**Note:** The `js-exec` command only exists when `javascript` is configured. It is not available in browser environments. Execution
|
|
496
|
+
**Note:** The `js-exec` command only exists when `javascript` is configured. It is not available in browser environments. Execution runs in a QuickJS WASM sandbox with a 64 MB memory limit and configurable timeout (30 seconds in the default `normal` profile and 10 seconds in the opt-in `hardened` profile). Enabling network access does not extend the configured deadline.
|
|
497
497
|
|
|
498
498
|
#### Tool Invocation Hook
|
|
499
499
|
|
|
@@ -507,10 +507,9 @@ const bash = new Bash({
|
|
|
507
507
|
// argsJson: '{"a":1,"b":2}' (or "" for no args)
|
|
508
508
|
// return: JSON-stringified result, or "" for undefined
|
|
509
509
|
// throw: propagates as a sandbox exception
|
|
510
|
-
invokeTool: async (path, argsJson
|
|
510
|
+
invokeTool: async (path, argsJson) => {
|
|
511
511
|
const args = argsJson ? JSON.parse(argsJson) : undefined;
|
|
512
512
|
if (path === "math.add") {
|
|
513
|
-
abortSignal.throwIfAborted();
|
|
514
513
|
return JSON.stringify({ sum: args.a + args.b });
|
|
515
514
|
}
|
|
516
515
|
throw new Error(`Unknown tool: ${path}`);
|
|
@@ -521,10 +520,6 @@ const bash = new Bash({
|
|
|
521
520
|
await bash.exec(`js-exec -c 'console.log((await tools.math.add({a:3,b:4})).sum)'`);
|
|
522
521
|
```
|
|
523
522
|
|
|
524
|
-
The `abortSignal` fires when the JavaScript execution is canceled or times
|
|
525
|
-
out. Tool implementations should forward it to network requests and other
|
|
526
|
-
cancelable work so effects do not outlive the sandbox execution.
|
|
527
|
-
|
|
528
523
|
The hook is generic — wire any tool framework through it (raw maps, MCP,
|
|
529
524
|
Anthropic tool-use, etc.). For full GraphQL / OpenAPI / MCP discovery via
|
|
530
525
|
`@executor-js/sdk`, plus auto-generated bash namespace commands, use the
|
|
@@ -772,22 +767,17 @@ const env = new Bash({
|
|
|
772
767
|
All resources remain bounded by default in both profiles. Explicit values
|
|
773
768
|
override the selected profile; non-negative safe integers and the legacy
|
|
774
769
|
`Infinity` spelling are accepted. Infinite deadlines omit the corresponding
|
|
775
|
-
platform timer rather than overflowing it
|
|
776
|
-
|
|
777
|
-
values are rejected when `Bash` is constructed. Error messages identify the
|
|
778
|
-
resource that was hit.
|
|
770
|
+
platform timer rather than overflowing it. Invalid values are rejected when
|
|
771
|
+
`Bash` is constructed. Error messages identify the resource that was hit.
|
|
779
772
|
|
|
780
773
|
## Security Model
|
|
781
774
|
|
|
782
|
-
The Node.js package requires Node `>=20.
|
|
775
|
+
The Node.js package requires Node `>=20.18.1`.
|
|
783
776
|
|
|
784
777
|
- The shell only has access to the provided filesystem.
|
|
785
778
|
- All execution happens without VM isolation. This does introduce additional risk. The code base was designed to be robust against prototype-pollution attacks and other break outs to the host JS engine and filesystem.
|
|
786
779
|
- There is no network access by default. When enabled, requests are checked against URL prefix allow-lists and HTTP-method allow-lists.
|
|
787
780
|
- Python and JavaScript execution are off by default as they represent additional security surface.
|
|
788
|
-
- `js-exec` guest code runs inside the `run` package's QuickJS/WASM realm. Its
|
|
789
|
-
primary isolation boundary is QuickJS plus the validated, bounded host
|
|
790
|
-
bridge; guest JavaScript does not execute in the Node worker realm.
|
|
791
781
|
- Execution is protected against infinite loops and deep recursion with configurable limits.
|
|
792
782
|
- Host-realm defense-in-depth uses the strongest scoped controls available on
|
|
793
783
|
each supported Node runtime. Where `node:module.registerHooks()` is present,
|
package/dist/AGENTS.md
CHANGED
|
@@ -343,7 +343,7 @@ to inline these, and some of them cannot be inlined. Mark all six as external:
|
|
|
343
343
|
| `@mongodb-js/zstd` | native binding (`optionalDependencies`) |
|
|
344
344
|
| `node-liblzma` | native binding (`optionalDependencies`) |
|
|
345
345
|
| `sql.js` | ships a `.wasm` asset |
|
|
346
|
-
| `
|
|
346
|
+
| `quickjs-emscripten` | ships a `.wasm` asset |
|
|
347
347
|
| `seek-bzip` | CommonJS-only bzip2 decoder |
|
|
348
348
|
| `guarded-fetch` | imports `node:dns/promises`, `node:net`, `node:dns` |
|
|
349
349
|
|
|
@@ -363,7 +363,7 @@ const nextConfig = {
|
|
|
363
363
|
"node-liblzma",
|
|
364
364
|
"seek-bzip",
|
|
365
365
|
"sql.js",
|
|
366
|
-
"
|
|
366
|
+
"quickjs-emscripten",
|
|
367
367
|
"guarded-fetch",
|
|
368
368
|
],
|
|
369
369
|
};
|
package/dist/Bash.d.ts
CHANGED
|
@@ -33,13 +33,11 @@ export interface JavaScriptConfig {
|
|
|
33
33
|
/**
|
|
34
34
|
* Tool invocation hook. When provided, code running in `js-exec` gets a
|
|
35
35
|
* global `tools` proxy that routes calls through this callback synchronously
|
|
36
|
-
*
|
|
36
|
+
* (the worker blocks via `Atomics.wait` while the host resolves the call).
|
|
37
37
|
*
|
|
38
38
|
* - `path`: dot-separated tool path (e.g. `"math.add"`). The proxy builds
|
|
39
39
|
* it from JS property access — `tools.math.add(...)` becomes `"math.add"`.
|
|
40
40
|
* - `argsJson`: JSON-stringified args object, or empty string for no args.
|
|
41
|
-
* - `abortSignal`: aborts when js-exec is canceled or times out. Tool
|
|
42
|
-
* implementations should forward it to cancelable work.
|
|
43
41
|
* - return: JSON-stringified result, or empty string for `undefined`.
|
|
44
42
|
* - throw: propagates as a catchable exception inside the sandbox.
|
|
45
43
|
*
|
|
@@ -49,7 +47,7 @@ export interface JavaScriptConfig {
|
|
|
49
47
|
* `@just-bash/executor` produces a matching `invokeTool` + `commands` pair
|
|
50
48
|
* from inline tools and/or `@executor-js/sdk` discovery.
|
|
51
49
|
*/
|
|
52
|
-
invokeTool?: (path: string, argsJson: string
|
|
50
|
+
invokeTool?: (path: string, argsJson: string) => Promise<string>;
|
|
53
51
|
}
|
|
54
52
|
export interface BashOptions {
|
|
55
53
|
files?: InitialFiles;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{
|
|
3
|
+
import{d as l,e as u}from"./chunk-QKJAAJ7J.js";import{randomBytes as h}from"node:crypto";var d=class{options;protocolToken=h(16).toString("hex");deadline;cleanups=[];cancelHandler;canceledReason;closed=!1;constructor(t){this.options=t,this.deadline=Date.now()+t.timeoutMs}arm(t){if(this.cancelHandler)throw new Error("worker request is already armed");this.cancelHandler=t;let a=this.options.signal;if(a){let i=()=>this.cancel("abort");a.addEventListener("abort",i,{once:!0}),this.cleanups.push(()=>a.removeEventListener("abort",i)),a.aborted&&this.cancel("abort")}if(!this.canceledReason){let i=l(()=>this.cancel("timeout"),Math.max(0,this.options.timeoutMs));i!==void 0&&this.cleanups.push(()=>u(i))}}get isCanceled(){return this.canceledReason!==void 0}remainingTimeMs(){return Math.max(0,this.deadline-Date.now())}timeoutMessage(t="Execution"){return`${t} timeout: exceeded ${this.options.timeoutMs}ms limit`}abortMessage(){return"Execution aborted"}assertMessageSize(t,a){if(f(t,this.options.maxMessageBytes)>this.options.maxMessageBytes)throw new Error(`${this.options.commandName}: worker ${a} exceeds ${this.options.maxMessageBytes} byte limit`)}async terminate(t){if(!t)return!0;try{return await t.terminate(),!0}catch{return!1}}close(){if(!this.closed){this.closed=!0;for(let t=this.cleanups.length-1;t>=0;t--)this.cleanups[t]();this.cleanups.length=0,this.cancelHandler=void 0}}cancel(t){this.closed||this.canceledReason||(this.canceledReason=t,this.cancelHandler?.(t))}};function f(o,t){let a=function*(n){for(let e in n)Object.hasOwn(n,e)&&(yield[e,n[e]])},i=[{kind:"value",value:o}],c=new WeakSet,s=0;for(;i.length>0&&s<=t;){let n=i.pop();if(!n)break;if(n.kind==="array"){n.index<n.value.length&&(i.push({...n,index:n.index+1}),i.push({kind:"value",value:n.value[n.index]}));continue}if(n.kind==="object"){let r=n.iterator.next();r.done||(s+=8+Buffer.byteLength(r.value[0],"utf8"),i.push(n),i.push({kind:"value",value:r.value[1]}));continue}let e=n.value;if(e==null)s+=4;else if(typeof e=="string")s+=Buffer.byteLength(e,"utf8");else if(typeof e=="number"||typeof e=="bigint")s+=8;else if(typeof e=="boolean")s+=1;else if(typeof e=="object"){if(c.has(e))continue;if(c.add(e),ArrayBuffer.isView(e))s+=e.byteLength;else if(e instanceof ArrayBuffer||e instanceof SharedArrayBuffer)s+=e.byteLength;else if(Array.isArray(e)){if(e.length>Math.floor((t-s)/8))return t+1;s+=e.length*8,i.push({kind:"array",value:e,index:0})}else i.push({kind:"object",iterator:a(e)})}}return s}export{d as a};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a as W}from"./chunk-
|
|
3
|
+
import{a as W}from"./chunk-3DWQCLNP.js";import{c as $}from"./chunk-42AMF6EE.js";import{b as C}from"./chunk-HWI42GQO.js";import{a as V}from"./chunk-MBREBDZQ.js";import{b as I}from"./chunk-CPKBPQ2C.js";import{a as B,b}from"./chunk-PBOVSFTJ.js";import{a as x}from"./chunk-I4IRHQDW.js";import{a as N,b as R}from"./chunk-MUFNRCMY.js";import{existsSync as ce}from"node:fs";import{dirname as de,join as T,sep as Q}from"node:path";import{fileURLToPath as me}from"node:url";import{Worker as he}from"node:worker_threads";import pe from"sql.js";function K(e,t){return e==null?Buffer.byteLength(t,"utf8"):e instanceof Uint8Array||Buffer.isBuffer(e)?e.byteLength:Buffer.byteLength(String(e),"utf8")}function X(e,t,r){let n=r.maxOutputSize??Number.MAX_SAFE_INTEGER,s=Buffer.byteLength(r.separator,"utf8");s+=Buffer.byteLength(r.newline,"utf8");for(let a of e)s+=Buffer.byteLength(a,"utf8");for(let a of t){s+=a.length*16;for(let i of a)s+=K(i,r.nullValue);if(s>n)break}let o=s*8+(t.length+3)*(e.length+3)*16;if(!Number.isSafeInteger(o)||o>n)throw new Error(`formatted output exceeds ${n} byte limit`);return n}function _(e,t,r){let n=X(e,t,r),s;switch(r.mode){case"list":s=Y(e,t,r);break;case"csv":s=Z(e,t,r);break;case"json":s=te(e,t);break;case"line":s=re(e,t,r);break;case"column":s=ne(e,t,r);break;case"table":s=se(e,t,r);break;case"markdown":s=oe(e,t,r);break;case"tabs":s=ie(e,t,r);break;case"box":s=ae(e,t,r);break;case"quote":s=le(e,t,r);break;case"html":s=fe(e,t,r);break;case"ascii":s=ue(e,t,r);break}if(Buffer.byteLength(s,"utf8")>n)throw new Error(`formatted output exceeds ${n} byte limit`);return s}function m(e,t){return e==null?t:e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString("utf8"):typeof e=="number"&&!Number.isInteger(e)?e.toPrecision(17).replace(/\.?0+$/,""):String(e)}function Y(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.join(r.separator));for(let s of t)n.push(s.map(o=>m(o,r.nullValue)).join(r.separator));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function Z(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.map(v).join(","));for(let s of t)n.push(s.map(o=>v(m(o,r.nullValue))).join(","));return n.length>0?`${n.join(`
|
|
4
4
|
`)}
|
|
5
5
|
`:""}function v(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
|
|
6
6
|
`)?`"${e.replace(/"/g,'""')}"`:e}function F(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function ee(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):F(e):JSON.stringify(e)}function te(e,t){return t.length===0?"":`[${t.map(n=>`{${e.map((o,a)=>`${JSON.stringify(o)}:${ee(n[a])}`).join(",")}}`).join(`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a as w}from"./chunk-B2DRBHGQ.js";import{a as y}from"./chunk-3MRB66F4.js";import{a as b}from"./chunk-3PCPQIUD.js";import{a as h,b as A}from"./chunk-
|
|
3
|
+
import{a as w}from"./chunk-B2DRBHGQ.js";import{a as y}from"./chunk-3MRB66F4.js";import{a as b}from"./chunk-3PCPQIUD.js";import{a as h,b as A}from"./chunk-QKJAAJ7J.js";import{a as v,b as O,c as d}from"./chunk-MUFNRCMY.js";var x={name:"timeout",summary:"run a command with a time limit",usage:"timeout [OPTION] DURATION COMMAND [ARG]...",description:`Start COMMAND, and kill it if still running after DURATION.
|
|
4
4
|
|
|
5
5
|
DURATION is a number with optional suffix:
|
|
6
6
|
s - seconds (default)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
+
import{a as C}from"./chunk-3MRB66F4.js";import{b as L}from"./chunk-O2BCKSMK.js";import{a as I,b as l}from"./chunk-TW2IJRUF.js";import{d as A,e as m}from"./chunk-QKJAAJ7J.js";import{b as w}from"./chunk-HWI42GQO.js";import{a as _,b as f}from"./chunk-OHFB3M3X.js";import{a as F,b as D}from"./chunk-PBOVSFTJ.js";var h={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,RENAME:14,COPY_FILE:15,WRITE_FILE_RANGE:17,READ_RESULT_RANGE:18,WRITE_STDOUT:100,WRITE_STDERR:101,EXIT:102,HTTP_REQUEST:200,EXEC_COMMAND:300,INVOKE_TOOL:400},S={IDLE:0,REQUEST:1,CANCELLED:2},r={NONE:0,SUCCESS:1,ERROR:2},a={NONE:0,NOT_FOUND:1,IS_DIRECTORY:2,NOT_DIRECTORY:3,EXISTS:4,PERMISSION_DENIED:5,INVALID_PATH:6,IO_ERROR:7,NETWORK_ERROR:9,NETWORK_NOT_CONFIGURED:10,NOT_EMPTY:11,LOOP:12,FILE_TOO_LARGE:13,NO_SPACE:14,BUSY:15,READ_ONLY:16,CROSS_DEVICE:17},O=Object.assign(Object.create(null),{ENOENT:a.NOT_FOUND,EISDIR:a.IS_DIRECTORY,ENOTDIR:a.NOT_DIRECTORY,ENOTEMPTY:a.NOT_EMPTY,EEXIST:a.EXISTS,EPERM:a.PERMISSION_DENIED,EACCES:a.PERMISSION_DENIED,EINVAL:a.INVALID_PATH,ELOOP:a.LOOP,EFBIG:a.FILE_TOO_LARGE,ENOSPC:a.NO_SPACE,EBUSY:a.BUSY,EROFS:a.READ_ONLY,EXDEV:a.CROSS_DEVICE}),P=Object.create(null);for(let[d,t]of Object.entries(O))P[t]=d;var o={OP_CODE:0,REQUEST:4,PATH_LENGTH:8,DATA_LENGTH:12,RESULT_LENGTH:16,ERROR_CODE:20,FLAGS:24,MODE:28,RESULT_STATE:32,PATH_BUFFER:36,DATA_BUFFER:4132},R={PATH_BUFFER:4096,DATA_BUFFER:8388608,TOTAL:8392740},g={NONE:0,RECURSIVE:1,FORCE:2,MKDIR_RECURSIVE:1},u={IS_FILE:0,IS_DIRECTORY:1,IS_SYMLINK:2,MODE:4,SIZE:8,MTIME:16,TOTAL:24};function M(){return new I(R.TOTAL)}var T=class{int32View;uint8View;dataView;constructor(t){this.int32View=new Int32Array(t),this.uint8View=new Uint8Array(t),this.dataView=new DataView(t)}getOpCode(){return l.load(this.int32View,o.OP_CODE/4)}setOpCode(t){l.store(this.int32View,o.OP_CODE/4,t)}getRequest(){return l.load(this.int32View,o.REQUEST/4)}setRequest(t){l.store(this.int32View,o.REQUEST/4,t)}getResultState(){return l.load(this.int32View,o.RESULT_STATE/4)}setResultState(t){l.store(this.int32View,o.RESULT_STATE/4,t)}getPathLength(){return l.load(this.int32View,o.PATH_LENGTH/4)}setPathLength(t){l.store(this.int32View,o.PATH_LENGTH/4,t)}getDataLength(){return l.load(this.int32View,o.DATA_LENGTH/4)}setDataLength(t){l.store(this.int32View,o.DATA_LENGTH/4,t)}getResultLength(){return l.load(this.int32View,o.RESULT_LENGTH/4)}setResultLength(t){l.store(this.int32View,o.RESULT_LENGTH/4,t)}getErrorCode(){return l.load(this.int32View,o.ERROR_CODE/4)}setErrorCode(t){l.store(this.int32View,o.ERROR_CODE/4,t)}getFlags(){return l.load(this.int32View,o.FLAGS/4)}setFlags(t){l.store(this.int32View,o.FLAGS/4,t)}getMode(){return l.load(this.int32View,o.MODE/4)}setMode(t){l.store(this.int32View,o.MODE/4,t)}getPath(){let t=this.getPathLength(),e=this.uint8View.slice(o.PATH_BUFFER,o.PATH_BUFFER+t);return new TextDecoder().decode(e)}setPath(t){let e=new TextEncoder().encode(t);if(e.length>R.PATH_BUFFER)throw new Error(`Path too long: ${e.length} > ${R.PATH_BUFFER}`);this.uint8View.set(e,o.PATH_BUFFER),this.setPathLength(e.length)}getData(){let t=this.getDataLength();return this.uint8View.slice(o.DATA_BUFFER,o.DATA_BUFFER+t)}setData(t){if(t.length>R.DATA_BUFFER)throw new Error(`Data too large: ${t.length} > ${R.DATA_BUFFER}`);this.uint8View.set(t,o.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(o.DATA_BUFFER,o.DATA_BUFFER+t)}setResult(t){if(t.length>R.DATA_BUFFER)throw new Error(`Result too large: ${t.length} > ${R.DATA_BUFFER}`);this.uint8View.set(t,o.DATA_BUFFER),this.setResultLength(t.length)}setResultPrefix(t){if(t.length>2147483647)throw new Error(`Result too large: ${t.length} exceeds int32`);let e=Math.min(t.length,R.DATA_BUFFER);this.uint8View.set(t.subarray(0,e),o.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[o.DATA_BUFFER+u.IS_FILE]=t.isFile?1:0,this.uint8View[o.DATA_BUFFER+u.IS_DIRECTORY]=t.isDirectory?1:0,this.uint8View[o.DATA_BUFFER+u.IS_SYMLINK]=t.isSymbolicLink?1:0,this.dataView.setInt32(o.DATA_BUFFER+u.MODE,t.mode,!0);let e=Math.min(t.size,Number.MAX_SAFE_INTEGER);this.dataView.setFloat64(o.DATA_BUFFER+u.SIZE,e,!0),this.dataView.setFloat64(o.DATA_BUFFER+u.MTIME,t.mtime.getTime(),!0),this.setResultLength(u.TOTAL)}decodeStat(){return{isFile:this.uint8View[o.DATA_BUFFER+u.IS_FILE]===1,isDirectory:this.uint8View[o.DATA_BUFFER+u.IS_DIRECTORY]===1,isSymbolicLink:this.uint8View[o.DATA_BUFFER+u.IS_SYMLINK]===1,mode:this.dataView.getInt32(o.DATA_BUFFER+u.MODE,!0),size:this.dataView.getFloat64(o.DATA_BUFFER+u.SIZE,!0),mtime:new Date(this.dataView.getFloat64(o.DATA_BUFFER+u.MTIME,!0))}}async waitUntilReady(t){let e=Date.now();for(;;){let s=this.getRequest();if(s===S.REQUEST)return!0;if(s!==S.IDLE)return!1;let i=Date.now()-e;if(i>=t)return!1;let n=t-i,c=l.waitAsync(this.int32View,o.REQUEST/4,S.IDLE,n);if(c.async&&await c.value==="timed-out")return!1}}waitForResult(t){return l.wait(this.int32View,o.RESULT_STATE/4,r.NONE,t)}notifyRequest(){return l.notify(this.int32View,o.REQUEST/4)}notifyResult(){return l.notify(this.int32View,o.RESULT_STATE/4)}reset(){this.setOpCode(h.NOOP),this.setRequest(S.IDLE),this.setResultState(r.NONE),this.setPathLength(0),this.setDataLength(0),this.setResultLength(0),this.setErrorCode(a.NONE),this.setFlags(g.NONE),this.setMode(0)}};function U(d){return d!==void 0&&Object.hasOwn(O,d)?O[d]:a.IO_ERROR}var N=class{fs;cwd;commandName;secureFetch;maxOutputSize;exec;invokeTool;protocol;running=!1;output={stdout:"",stderr:"",exitCode:0};outputLimitExceeded=!1;startTime=0;timeoutMs=0;lastResult=null;constructor(t,e,s,i,n=void 0,c=0,E=void 0,p=void 0){this.fs=e,this.cwd=s,this.commandName=i,this.secureFetch=n,this.maxOutputSize=c,this.exec=E,this.invokeTool=p,this.protocol=new T(t)}remainingMs(){return Math.max(0,this.timeoutMs-(Date.now()-this.startTime))}raceDeadline(t){let e=this.remainingMs();if(e<=0)return this.running=!1,this.output.exitCode=124,this.output.stderr+=`
|
|
4
|
+
${this.commandName}: execution timeout exceeded
|
|
5
|
+
`,Promise.reject(new Error("Operation timed out"));let s=t();return e===Number.POSITIVE_INFINITY?s:new Promise((i,n)=>{let c=A(()=>{this.running=!1,this.output.exitCode=124,this.output.stderr+=`
|
|
6
|
+
${this.commandName}: execution timeout exceeded
|
|
7
|
+
`,n(new Error("Operation timed out"))},e);s.then(E=>{m(c),i(E)},E=>{m(c),n(E)})})}async run(t){for(this.running=!0,this.startTime=Date.now(),this.timeoutMs=t;this.running;){if(Date.now()-this.startTime>=t){this.output.stderr+=`
|
|
8
|
+
${this.commandName}: execution timeout exceeded
|
|
9
|
+
`,this.output.exitCode=124;break}let s=this.remainingMs();if(!await this.protocol.waitUntilReady(s)){if(!this.running)break;this.output.stderr+=`
|
|
10
|
+
${this.commandName}: execution timeout exceeded
|
|
11
|
+
`,this.output.exitCode=124;break}if(!this.running)break;this.protocol.setRequest(S.IDLE);let n=this.protocol.getOpCode();await this.handleOperation(n),this.protocol.notifyResult()}return this.output}stop(){this.running=!1,this.lastResult=null,this.protocol.setRequest(S.CANCELLED),this.protocol.notifyRequest()}async handleOperation(t){try{switch(t){case h.READ_FILE:await this.handleReadFile();break;case h.WRITE_FILE:await this.handleWriteFile();break;case h.STAT:await this.handleStat();break;case h.LSTAT:await this.handleLstat();break;case h.READDIR:await this.handleReaddir();break;case h.MKDIR:await this.handleMkdir();break;case h.READ_RESULT_RANGE:this.handleReadResultRange();break;case h.WRITE_FILE_RANGE:await this.handleWriteFileRange();break;case h.RM:await this.handleRm();break;case h.EXISTS:await this.handleExists();break;case h.APPEND_FILE:await this.handleAppendFile();break;case h.SYMLINK:await this.handleSymlink();break;case h.READLINK:await this.handleReadlink();break;case h.CHMOD:await this.handleChmod();break;case h.REALPATH:await this.handleRealpath();break;case h.RENAME:await this.handleRename();break;case h.COPY_FILE:await this.handleCopyFile();break;case h.WRITE_STDOUT:this.handleWriteStdout();break;case h.WRITE_STDERR:this.handleWriteStderr();break;case h.EXIT:this.handleExit();break;case h.HTTP_REQUEST:await this.handleHttpRequest();break;case h.EXEC_COMMAND:await this.handleExecCommand();break;case h.INVOKE_TOOL:await this.handleInvokeTool();break;default:this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultState(r.ERROR)}}catch(e){this.setErrorFromException(e)}}publishResult(t){let e=typeof t=="string"?new TextEncoder().encode(t):t;this.lastResult=e,this.protocol.setResultPrefix(e),this.protocol.setResultState(r.SUCCESS)}handleReadResultRange(){let t=this.protocol.getFlags(),e=this.protocol.getMode(),s=this.lastResult;if(!s||t>=s.length){this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString(`No retained result for range read (offset=${t}, length=${e}, retained=${s?.length??"none"})`),this.protocol.setResultState(r.ERROR);return}this.protocol.setResult(s.subarray(t,t+e)),this.protocol.setResultState(r.SUCCESS)}resolvePath(t){return this.fs.resolvePath(this.cwd,t)}async handleReadFile(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readFileBuffer(t);this.publishResult(e)}catch(e){this.setErrorFromException(e)}}async handleWriteFileRange(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),s=this.protocol.getData();try{if(e===0)await this.fs.writeFile(t,s);else{let i=await this.fs.stat(t);if(i.size!==e)throw new _("EIO",`non-sequential range write to '${t}': offset ${e} != size ${i.size}`);await this.fs.appendFile(t,s)}this.protocol.setResultState(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleWriteFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.writeFile(t,e),this.protocol.setResultState(r.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.setResultState(r.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.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleReaddir(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readdir(t);this.publishResult(JSON.stringify(e))}catch(e){this.setErrorFromException(e)}}async handleMkdir(){let t=this.resolvePath(this.protocol.getPath()),s=(this.protocol.getFlags()&g.MKDIR_RECURSIVE)!==0;try{await this.fs.mkdir(t,{recursive:s}),this.protocol.setResultState(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleRm(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),s=(e&g.RECURSIVE)!==0,i=(e&g.FORCE)!==0;try{await this.fs.rm(t,{recursive:s,force:i}),this.protocol.setResultState(r.SUCCESS)}catch(n){this.setErrorFromException(n)}}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.setResultState(r.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.setResultState(r.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.setResultState(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleReadlink(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readlink(t);this.protocol.setResultFromString(e),this.protocol.setResultState(r.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.setResultState(r.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.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleRename(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.mv(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleCopyFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.cp(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}handleWriteStdout(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stdout",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setResultState(r.ERROR);return}this.protocol.setResultState(r.SUCCESS)}handleWriteStderr(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stderr",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setResultState(r.ERROR);return}this.protocol.setResultState(r.SUCCESS)}handleExit(){let t=this.protocol.getFlags();this.outputLimitExceeded?this.output.exitCode===0&&(this.output.exitCode=1):this.output.exitCode=t,this.protocol.setResultState(r.SUCCESS),this.running=!1}tryAppendOutput(t,e){return this.outputLimitExceeded?!1:this.maxOutputSize<=0?(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0):this.output.stdout.length+this.output.stderr.length+e.length>this.maxOutputSize?!1:(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0)}appendOutputLimitError(){if(this.maxOutputSize<=0)return;let t=`${this.commandName}: total output size exceeded (>${this.maxOutputSize} bytes), increase executionLimits.maxOutputSize
|
|
12
|
+
`,e=t.length>this.maxOutputSize?t.slice(0,this.maxOutputSize):t;if(this.output.stderr.includes("total output size exceeded"))return;let i=this.output.stdout.length+this.output.stderr.length+e.length-this.maxOutputSize;if(i>0)if(this.output.stdout.length>=i)this.output.stdout=this.output.stdout.slice(0,this.output.stdout.length-i);else{let n=i-this.output.stdout.length;this.output.stdout="",n>=this.output.stderr.length?this.output.stderr="":this.output.stderr=this.output.stderr.slice(0,this.output.stderr.length-n)}this.output.stderr+=e}async handleHttpRequest(){let t=this.secureFetch;if(!t){this.protocol.setErrorCode(a.NETWORK_NOT_CONFIGURED),this.protocol.setResultFromString("Network access not configured. Enable network in Bash options."),this.protocol.setResultState(r.ERROR);return}let e=this.protocol.getPath(),s=this.protocol.getDataAsString();try{let i=s?JSON.parse(s):{},n=this.remainingMs(),c=await this.raceDeadline(()=>t(e,{method:i.method,headers:i.headers,body:i.body,timeoutMs:n})),E=JSON.stringify({status:c.status,statusText:c.statusText,headers:c.headers,bodyBase64:L(c.body,"base64"),url:c.url});this.publishResult(E)}catch(i){let n=F(i instanceof Error?i.message:String(i));this.protocol.setErrorCode(a.NETWORK_ERROR),this.protocol.setResultFromString(n),this.protocol.setResultState(r.ERROR)}}async handleExecCommand(){let t=this.exec;if(!t){this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Command execution not available in this context."),this.protocol.setResultState(r.ERROR);return}let e=this.protocol.getPath(),s=this.protocol.getDataAsString(),i=new AbortController;try{let n={cwd:this.cwd,signal:i.signal};if(s){let p=JSON.parse(s);p.stdin&&(n.stdin=p.stdin),p.args&&Array.isArray(p.args)&&(n.args=p.args.map(x=>String(x)),e=C([e]))}let c=await this.raceDeadline(()=>t(e,n)),E=JSON.stringify({stdout:c.stdout,stderr:c.stderr,exitCode:c.exitCode});this.publishResult(E)}catch(n){i.abort();let c=n instanceof Error?n.message:String(n);this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString(c),this.protocol.setResultState(r.ERROR)}}async handleInvokeTool(){let t=this.invokeTool;if(!t){this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Tool invocation not available in this context."),this.protocol.setResultState(r.ERROR);return}let e=this.protocol.getPath(),s=this.protocol.getDataAsString();try{let i=await this.raceDeadline(()=>w.runTrustedAsync(()=>t(e,s)));this.publishResult(i)}catch(i){let n=D(i instanceof Error?i.message:String(i));this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString(n),this.protocol.setResultState(r.ERROR)}}setErrorFromException(t){let e=t instanceof Error?t.message:String(t),s=F(e);this.protocol.setErrorCode(U(f(t))),this.protocol.setResultFromString(s),this.protocol.setResultState(r.ERROR)}};export{M as a,N as b};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
+
import{b as T}from"./chunk-CPKBPQ2C.js";import{a as R}from"./chunk-NE4R2FVV.js";import{a as _,b as k}from"./chunk-MUFNRCMY.js";var L=class{diff(t,o,e={}){let i;typeof e=="function"?(i=e,e={}):"callback"in e&&(i=e.callback);let s=this.castInput(t,e),f=this.castInput(o,e),l=this.removeEmpty(this.tokenize(s,e)),r=this.removeEmpty(this.tokenize(f,e));return this.diffWithOptionsObj(l,r,e,i)}diffWithOptionsObj(t,o,e,i){var s;let f=c=>{if(c=this.postProcess(c,e),i){setTimeout(function(){i(c)},0);return}else return c},l=o.length,r=t.length,a=1,u=l+r;e.maxEditLength!=null&&(u=Math.min(u,e.maxEditLength));let h=(s=e.timeout)!==null&&s!==void 0?s:1/0,w=Date.now()+h,C=[{oldPos:-1,lastComponent:void 0}],m=this.extractCommon(C[0],o,t,0,e);if(C[0].oldPos+1>=r&&m+1>=l)return f(this.buildValues(C[0].lastComponent,o,t));let d=-1/0,p=1/0,g=()=>{for(let c=Math.max(d,-a);c<=Math.min(p,a);c+=2){let $,P=C[c-1],y=C[c+1];P&&(C[c-1]=void 0);let v=!1;if(y){let W=y.oldPos-c;v=y&&0<=W&&W<l}let F=P&&P.oldPos+1<r;if(!v&&!F){C[c]=void 0;continue}if(!F||v&&P.oldPos<y.oldPos?$=this.addToPath(y,!0,!1,0,e):$=this.addToPath(P,!1,!0,1,e),m=this.extractCommon($,o,t,c,e),$.oldPos+1>=r&&m+1>=l)return f(this.buildValues($.lastComponent,o,t))||!0;C[c]=$,$.oldPos+1>=r&&(p=Math.min(p,c-1)),m+1>=l&&(d=Math.max(d,c+1))}a++};if(i)(function c(){setTimeout(function(){if(a>u||Date.now()>w)return i(void 0);g()||c()},0)})();else for(;a<=u&&Date.now()<=w;){let c=g();if(c)return c}}addToPath(t,o,e,i,s){let f=t.lastComponent;return f&&!s.oneChangePerToken&&f.added===o&&f.removed===e?{oldPos:t.oldPos+i,lastComponent:{count:f.count+1,added:o,removed:e,previousComponent:f.previousComponent}}:{oldPos:t.oldPos+i,lastComponent:{count:1,added:o,removed:e,previousComponent:f}}}extractCommon(t,o,e,i,s){let f=o.length,l=e.length,r=t.oldPos,a=r-i,u=0;for(;a+1<f&&r+1<l&&this.equals(e[r+1],o[a+1],s);)a++,r++,u++,s.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return u&&!s.oneChangePerToken&&(t.lastComponent={count:u,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=r,a}equals(t,o,e){return e.comparator?e.comparator(t,o):t===o||!!e.ignoreCase&&t.toLowerCase()===o.toLowerCase()}removeEmpty(t){let o=[];for(let e=0;e<t.length;e++)t[e]&&o.push(t[e]);return o}castInput(t,o){return t}tokenize(t,o){return Array.from(t)}join(t){return t.join("")}postProcess(t,o){return t}get useLongestToken(){return!1}buildValues(t,o,e){let i=[],s;for(;t;)i.push(t),s=t.previousComponent,delete t.previousComponent,t=s;i.reverse();let f=i.length,l=0,r=0,a=0;for(;l<f;l++){let u=i[l];if(u.removed)u.value=this.join(e.slice(a,a+u.count)),a+=u.count;else{if(!u.added&&this.useLongestToken){let h=o.slice(r,r+u.count);h=h.map(function(w,C){let m=e[a+C];return m.length>w.length?m:w}),u.value=this.join(h)}else u.value=this.join(o.slice(r,r+u.count));r+=u.count,u.added||(a+=u.count)}}return i}};var N=class extends L{tokenize(t){return t.slice()}join(t){return t}removeEmpty(t){return t}},z=new N;function M(n,t,o){return z.diff(n,t,o)}var ne=`\
|
|
4
|
+
`,A=3;function j(n){if(n==="")return{lines:[],noEol:!1};let t=!n.endsWith(`
|
|
5
|
+
`),o=n.split(`
|
|
6
|
+
`);return t||o.pop(),{lines:o,noEol:t}}function H(n,t){let o=n.lines.length-1;return n.lines.map((e,i)=>{let s=i===o&&n.noEol?e:`${e}
|
|
7
|
+
`;return t?s.toLowerCase():s})}function B(n,t,o){let e=M(H(n,o),H(t,o)),i=[],s=0,f=0,l=0;for(;l<e.length;){let r=e[l];if(!r.added&&!r.removed){s+=r.count??r.value.length,f+=r.count??r.value.length,l++;continue}let a={oldStart:s,oldCount:0,newStart:f,newCount:0};for(;l<e.length&&(e[l].added||e[l].removed);){let u=e[l].count??e[l].value.length;e[l].removed?(a.oldCount+=u,s+=u):(a.newCount+=u,f+=u),l++}i.push(a)}return i}function x(n){if(!/[\s"\u0000-\u001f\u007f]/.test(n))return n;let t='"';for(let o of n)o==='"'||o==="\\"?t+=`\\${o}`:o===" "?t+="\\t":o===`
|
|
8
|
+
`?t+="\\n":o==="\r"?t+="\\r":o<" "||o==="\x7F"?t+=`\\${o.charCodeAt(0).toString(8).padStart(3,"0")}`:t+=o;return`${t}"`}function D(n,t,o,e){n.push(`${e}${t.lines[o]}
|
|
9
|
+
`),t.noEol&&o===t.lines.length-1&&n.push(ne)}function q(n,t){return t===0?String(n):t===1?String(n+1):`${n+1},${n+t}`}function J(n,t,o){let e=[];for(let i of o){let s=i.oldCount===0?"a":i.newCount===0?"d":"c";e.push(`${q(i.oldStart,i.oldCount)}${s}${q(i.newStart,i.newCount)}
|
|
10
|
+
`);for(let f=0;f<i.oldCount;f++)D(e,n,i.oldStart+f,"< ");s==="c"&&e.push(`---
|
|
11
|
+
`);for(let f=0;f<i.newCount;f++)D(e,t,i.newStart+f,"> ")}return e.join("")}function Y(n,t){let o=[],e=[];for(let i of n){let s=e[e.length-1];s&&i.oldStart-(s.oldStart+s.oldCount)>2*t&&(o.push(e),e=[]),e.push(i)}return e.length>0&&o.push(e),o}function G(n,t,o,e){let i=n[0],s=n[n.length-1];return{oldFrom:Math.max(0,i.oldStart-e),oldTo:Math.min(t.lines.length,s.oldStart+s.oldCount+e),newFrom:Math.max(0,i.newStart-e),newTo:Math.min(o.lines.length,s.newStart+s.newCount+e)}}function U(n,t){let o=t-n;return o===0?`${n},0`:o===1?String(n+1):`${n+1},${o}`}function K(n,t,o,e,i,s){let f=[`--- ${x(n)}
|
|
12
|
+
`,`+++ ${x(t)}
|
|
13
|
+
`];for(let l of Y(i,s)){let r=G(l,o,e,s);f.push(`@@ -${U(r.oldFrom,r.oldTo)} +${U(r.newFrom,r.newTo)} @@
|
|
14
|
+
`);let a=r.oldFrom;for(let u of l){for(;a<u.oldStart;a++)D(f,o,a," ");for(let h=0;h<u.oldCount;h++)D(f,o,u.oldStart+h,"-");for(let h=0;h<u.newCount;h++)D(f,e,u.newStart+h,"+");a=u.oldStart+u.oldCount}for(;a<r.oldTo;a++)D(f,o,a," ")}return f.join("")}function V(n,t){let o=t-n;return o===0?String(n):o===1?String(n+1):`${n+1},${t}`}function X(n,t,o,e,i,s){if(!o.some(r=>(s?r.oldCount:r.newCount)>0))return;let l=e;for(let r of o){let a=s?r.oldStart:r.newStart,u=s?r.oldCount:r.newCount;for(;l<a;l++)D(n,t,l," ");let h=r.oldCount>0&&r.newCount>0?"! ":s?"- ":"+ ";for(let w=0;w<u;w++)D(n,t,a+w,h);l=a+u}for(;l<i;l++)D(n,t,l," ")}function Q(n,t,o,e,i,s){let f=[`*** ${x(n)}
|
|
15
|
+
`,`--- ${x(t)}
|
|
16
|
+
`];for(let l of Y(i,s)){let r=G(l,o,e,s);f.push(`***************
|
|
17
|
+
`),f.push(`*** ${V(r.oldFrom,r.oldTo)} ****
|
|
18
|
+
`),X(f,o,l,r.oldFrom,r.oldTo,!0),f.push(`--- ${V(r.newFrom,r.newTo)} ----
|
|
19
|
+
`),X(f,e,l,r.newFrom,r.newTo,!1)}return f.join("")}var re={name:"diff",summary:"compare files line by line",usage:"diff [OPTION]... FILE1 FILE2",options:[" --normal output a normal diff (default)","-u, --unified output a unified diff","-c, --context output a context diff","-q, --brief report only whether files differ","-s, --report-identical-files report when files are the same","-i, --ignore-case ignore case differences","-r, --recursive recursively compare directories","-N, --new-file treat absent files as empty"," --version output version information and exit"," --help display this help and exit"]},ie={normal:{long:"normal",type:"boolean"},unified:{short:"u",long:"unified",type:"boolean"},context:{short:"c",long:"context",type:"boolean"},brief:{short:"q",long:"brief",type:"boolean"},reportSame:{short:"s",long:"report-identical-files",type:"boolean"},ignoreCase:{short:"i",long:"ignore-case",type:"boolean"},recursive:{short:"r",long:"recursive",type:"boolean"},newFile:{short:"N",long:"new-file",type:"boolean"},version:{long:"version",type:"boolean"}},E=100;function S(n,t,o,e,i){let s=o,f=e;if(i.ignoreCase&&(s=s.toLowerCase(),f=f.toLowerCase()),s===f)return i.reportSame?{output:`Files ${n} and ${t} are identical
|
|
20
|
+
`,differs:!1}:{output:"",differs:!1};if(i.brief)return{output:`Files ${n} and ${t} differ
|
|
21
|
+
`,differs:!0};let l=j(o),r=j(e),a=B(l,r,i.ignoreCase),u;return i.unified?u=K(n,t,l,r,a,A):i.context?u=Q(n,t,l,r,a,A):u=J(l,r,a),{output:u,differs:!0}}async function b(n,t){return n.fs.readFile(n.fs.resolvePath(n.cwd,t))}async function Z(n,t){try{let o=n.fs.resolvePath(n.cwd,t),e=await n.fs.stat(o);return{isFile:e.isFile,isDirectory:e.isDirectory}}catch{return null}}async function I(n,t){if(n.fs.readdirWithFileTypes)return n.fs.readdirWithFileTypes(t);let o=await n.fs.readdir(t),e=[];for(let i of o)try{let s=await n.fs.stat(`${t}/${i}`);e.push({name:i,isFile:s.isFile,isDirectory:s.isDirectory,isSymbolicLink:s.isSymbolicLink??!1})}catch{}return e}function ee(n){return n.isDirectory?"directory":n.isSymbolicLink?"symbolic link":"regular file"}async function te(n,t,o,e,i=0){if(i>E)return{output:`diff: maximum recursion depth exceeded (${E})
|
|
22
|
+
`,differs:!0};let s=o.fs.resolvePath(o.cwd,n),f=o.fs.resolvePath(o.cwd,t),l=await I(o,s),r=await I(o,f),a=new Set(l.map(p=>p.name)),u=new Set(r.map(p=>p.name)),h=[...new Set([...a,...u])].sort(),w=new Map(l.map(p=>[p.name,p])),C=new Map(r.map(p=>[p.name,p])),m="",d=!1;for(let p of h){let g=`${n}/${p}`,c=`${t}/${p}`,$=w.get(p),P=C.get(p);if($&&P)if($.isDirectory&&P.isDirectory){let y=await te(g,c,o,e,i+1);m+=y.output,d=d||y.differs}else if($.isFile&&P.isFile)try{let y=await b(o,g),v=await b(o,c),F=S(g,c,y,v,e);F.differs&&!e.brief&&F.output&&(m+=`${e.headerPrefix} ${g} ${c}
|
|
23
|
+
`),m+=F.output,d=d||F.differs}catch{m+=`diff: ${g}: No such file or directory
|
|
24
|
+
`,d=!0}else m+=`File ${g} is a ${ee($)} while file ${c} is a ${ee(P)}
|
|
25
|
+
`,d=!0;else if($)if(e.newFile)if($.isDirectory){let y=await O(g,c,o,e,!0,i+1);m+=y.output,d=d||y.differs}else if($.isFile){let y=await b(o,g),v=S(g,c,y,"",e);v.differs&&!e.brief&&v.output&&(m+=`${e.headerPrefix} ${g} ${c}
|
|
26
|
+
`),m+=v.output,d=d||v.differs}else m+=`Only in ${n}: ${p}
|
|
27
|
+
`,d=!0;else m+=`Only in ${n}: ${p}
|
|
28
|
+
`,d=!0;else if(P)if(e.newFile)if(P.isDirectory){let y=await O(c,g,o,e,!1,i+1);m+=y.output,d=d||y.differs}else if(P.isFile){let y=await b(o,c),v=S(g,c,"",y,e);v.differs&&!e.brief&&v.output&&(m+=`${e.headerPrefix} ${g} ${c}
|
|
29
|
+
`),m+=v.output,d=d||v.differs}else m+=`Only in ${t}: ${p}
|
|
30
|
+
`,d=!0;else m+=`Only in ${t}: ${p}
|
|
31
|
+
`,d=!0}return{output:m,differs:d}}async function O(n,t,o,e,i,s=0){if(s>E)return{output:`diff: maximum recursion depth exceeded (${E})
|
|
32
|
+
`,differs:!0};let f=o.fs.resolvePath(o.cwd,n),r=[...await I(o,f)].sort((h,w)=>h.name<w.name?-1:h.name>w.name?1:0),a="",u=!1;for(let h of r){let w=`${n}/${h.name}`,C=`${t}/${h.name}`;if(h.isDirectory){let m=await O(w,C,o,e,i,s+1);a+=m.output,u=u||m.differs}else if(h.isFile){let m=await b(o,w),d=i?m:"",p=i?"":m,g=i?w:C,c=i?C:w,$=S(g,c,d,p,e);$.differs&&!e.brief&&$.output&&(a+=`${e.headerPrefix} ${g} ${c}
|
|
33
|
+
`),a+=$.output,u=u||$.differs}}return{output:a,differs:u}}var he={name:"diff",async execute(n,t){if(k(n))return _(re);let o=R("diff",n,ie);if(!o.ok)return o.error;let e=o.result.flags;if(e.version)return{stdout:`diff (just-bash)
|
|
34
|
+
`,stderr:"",exitCode:0};if(Number(e.normal)+Number(e.unified)+Number(e.context)>1)return{stdout:"",stderr:`diff: conflicting output style options
|
|
35
|
+
diff: Try 'diff --help' for more information.
|
|
36
|
+
`,exitCode:2};let s="diff -r";e.unified&&(s+="u"),e.context&&(s+="c"),e.newFile&&(s+="N"),e.ignoreCase&&(s+="i"),e.brief&&(s+="q");let f={unified:e.unified,context:e.context,brief:e.brief,reportSame:e.reportSame,ignoreCase:e.ignoreCase,newFile:e.newFile,headerPrefix:s},l=o.result.positional;if(l.length<2)return{stdout:"",stderr:`diff: missing operand
|
|
37
|
+
`,exitCode:2};let[r,a]=l;if(e.recursive){let C=await Z(t,r),m=await Z(t,a);if(C?.isFile&&m?.isDirectory){let d=`${a}/${r.split("/").pop()}`,p;try{p=await b(t,r)}catch{return{stdout:"",stderr:`diff: ${r}: No such file or directory
|
|
38
|
+
`,exitCode:2}}let g;try{g=await b(t,d)}catch{if(f.newFile)g="";else return{stdout:"",stderr:`diff: ${d}: No such file or directory
|
|
39
|
+
`,exitCode:2}}let c=S(r,d,p,g,f);return{stdout:c.output,stderr:"",exitCode:c.differs?1:0}}if(C?.isDirectory&&m?.isFile){let d=`${r}/${a.split("/").pop()}`,p;try{p=await b(t,d)}catch{if(f.newFile)p="";else return{stdout:"",stderr:`diff: ${d}: No such file or directory
|
|
40
|
+
`,exitCode:2}}let g;try{g=await b(t,a)}catch{return{stdout:"",stderr:`diff: ${a}: No such file or directory
|
|
41
|
+
`,exitCode:2}}let c=S(d,a,p,g,f);return{stdout:c.output,stderr:"",exitCode:c.differs?1:0}}if(!C||!m)return{stdout:"",stderr:`diff: ${C?a:r}: No such file or directory
|
|
42
|
+
`,exitCode:2};if(C.isDirectory&&m.isDirectory){let d=await te(r,a,t,f);return{stdout:d.output,stderr:"",exitCode:d.differs?1:0}}}let u,h;try{u=r==="-"?T(t.stdin):await b(t,r)}catch{if(f.newFile)u="";else return{stdout:"",stderr:`diff: ${r}: No such file or directory
|
|
43
|
+
`,exitCode:2}}try{h=a==="-"?T(t.stdin):await b(t,a)}catch{if(f.newFile)h="";else return{stdout:"",stderr:`diff: ${a}: No such file or directory
|
|
44
|
+
`,exitCode:2}}let w=S(r,a,u,h,f);return{stdout:w.output,stderr:"",exitCode:w.differs?1:0}}},ge={name:"diff",flags:[{flag:"--normal",type:"boolean"},{flag:"-u",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-i",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-N",type:"boolean"}],needsArgs:!0,minArgs:2};export{he as a,ge as b};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a as p}from"./chunk-B2DRBHGQ.js";import{a as n,b as l}from"./chunk-
|
|
3
|
+
import{a as p}from"./chunk-B2DRBHGQ.js";import{a as n,b as l}from"./chunk-QKJAAJ7J.js";import{a as m,b as d}from"./chunk-MUFNRCMY.js";var f={name:"sleep",summary:"delay for a specified amount of time",usage:"sleep NUMBER[SUFFIX]",description:`Pause for NUMBER seconds. SUFFIX may be:
|
|
4
4
|
s - seconds (default)
|
|
5
5
|
m - minutes
|
|
6
6
|
h - hours
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
+
import{b as a}from"./chunk-HWI42GQO.js";var r=globalThis.setTimeout.bind(globalThis),l=globalThis.clearTimeout.bind(globalThis),T=globalThis.setInterval.bind(globalThis),f=globalThis.clearInterval.bind(globalThis);function u(e){return typeof e!="function"?e:a.bindCurrentContext(e)}var b=((e,n,...i)=>r(u(e),n,...i)),d=l,I=((e,n,...i)=>r(e,n,...i)),c=2147483647;function _(e,n){if(n===Number.POSITIVE_INFINITY)return;let i=u(e),t={cleared:!1,remainingMs:Math.max(0,n),timer:void 0},o=()=>{if(t.cleared)return;let s=Math.min(t.remainingMs,c);t.timer=r(()=>{t.cleared||(t.remainingMs-=s,t.remainingMs>0?o():i())},s)};return o(),t}function g(e){e&&(e.cleared=!0,e.timer!==void 0&&l(e.timer))}export{b as a,d as b,I as c,_ as d,g as e};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a,b}from"./chunk-
|
|
3
|
+
import{a,b}from"./chunk-GBKR5KTT.js";import"./chunk-CPKBPQ2C.js";import"./chunk-NE4R2FVV.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";export{a as diffCommand,b as flagsForFuzzing};
|
package/dist/bin/{shell/chunks/flag-coverage-2H5CPEM6.js → chunks/flag-coverage-LLAQBVIG.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{b as yr}from"./chunk-M3Z5NZXT.js";import{b as Ar}from"./chunk-PRVPFKTC.js";import{b as $r}from"./chunk-ANX7U57Q.js";import"./chunk-V4U26ZWL.js";import"./chunk-KP2UH5CJ.js";import{c as Sr}from"./chunk-
|
|
3
|
+
import{b as yr}from"./chunk-M3Z5NZXT.js";import{b as Ar}from"./chunk-PRVPFKTC.js";import{b as $r}from"./chunk-ANX7U57Q.js";import"./chunk-V4U26ZWL.js";import"./chunk-KP2UH5CJ.js";import{c as Sr}from"./chunk-6JEDM6CZ.js";import"./chunk-3DWQCLNP.js";import{b as wr}from"./chunk-PQ2INDRF.js";import{b as xr}from"./chunk-DYIBFLS3.js";import{b as vr}from"./chunk-RVPTAYDS.js";import{b as kr}from"./chunk-TYBXHT6W.js";import{b as qr}from"./chunk-AJF3OBTR.js";import{b as Cr}from"./chunk-2ETT4ELS.js";import{b as br}from"./chunk-OUQKFRVR.js";import{d as Ir,e as Mr,f as jr}from"./chunk-QJWFCA7P.js";import"./chunk-QES5OSUC.js";import{b as tr}from"./chunk-6TUILMPB.js";import{b as lr}from"./chunk-CC2AQ6B7.js";import{b as ur}from"./chunk-QMPZXXEK.js";import{b as pr}from"./chunk-CNVNOT67.js";import{b as er}from"./chunk-LXFMIXGA.js";import{b as dr}from"./chunk-WFVCEB5T.js";import{b as cr}from"./chunk-KG2KXL4Y.js";import"./chunk-2YLY6FJA.js";import{b as hr}from"./chunk-H7PD6FLC.js";import{c as or,d as ar}from"./chunk-KI54R2QB.js";import{b as sr}from"./chunk-KUMHQGUR.js";import{c as ir,d as gr}from"./chunk-MYTNZ7MA.js";import{b as mr}from"./chunk-V4S4A7M6.js";import"./chunk-ONF4KUYV.js";import{b as Fr}from"./chunk-FPWHWWXO.js";import{b as zr}from"./chunk-GBKR5KTT.js";import{b as fr}from"./chunk-LJQIAFWS.js";import{b as nr}from"./chunk-L345YZ6R.js";import"./chunk-B2DRBHGQ.js";import{b as R}from"./chunk-YJ5OCPSK.js";import{b as U}from"./chunk-Q2GOPGDA.js";import{b as V}from"./chunk-PXP4YYZA.js";import{b as W}from"./chunk-DRPHNXG7.js";import{c as X,d as Y}from"./chunk-YUZRUF5F.js";import{c as Z,d as _}from"./chunk-DJAX3ZRG.js";import{b as N}from"./chunk-PZQVSQX6.js";import{b as rr}from"./chunk-SDGPS6XI.js";import{b as G}from"./chunk-SC5TEGMM.js";import{b as H}from"./chunk-5SKEZPTU.js";import{b as J}from"./chunk-OYXHOZZ4.js";import{b as K}from"./chunk-KMYJMEON.js";import{b as L}from"./chunk-N26Y42L6.js";import{b as O}from"./chunk-4JF56A3P.js";import{b as P}from"./chunk-AGKL4LDL.js";import{b as Q}from"./chunk-BB5VTPMQ.js";import{b as y}from"./chunk-FHMIEBRM.js";import{b as A}from"./chunk-7FGDUBSN.js";import{b as $}from"./chunk-GOWX7VPU.js";import{b as S}from"./chunk-B6WWC6K3.js";import{b as T}from"./chunk-MVBK66TR.js";import{b as B}from"./chunk-YIANER7Y.js";import{b as D}from"./chunk-HDWHYM2T.js";import{b as E}from"./chunk-Q3LE3Y66.js";import{b as w}from"./chunk-3FQBUEB6.js";import{b as x}from"./chunk-45DUHCXR.js";import{b as v}from"./chunk-HZGHQZSY.js";import"./chunk-BIJXTWZ4.js";import{d as k,e as q,f as C}from"./chunk-U5JLGI56.js";import"./chunk-IOKQFPM6.js";import{b}from"./chunk-VPSBWWXM.js";import"./chunk-47IFMQYS.js";import"./chunk-3MRB66F4.js";import"./chunk-QFOXSCOD.js";import{b as I}from"./chunk-PTUQEN6I.js";import{b as M}from"./chunk-ZVG47PYA.js";import{b as j}from"./chunk-FONAGXRJ.js";import{b as t}from"./chunk-F2PYTUMR.js";import{b as l}from"./chunk-6JUPBMCR.js";import{b as u}from"./chunk-RTN6X652.js";import{b as p}from"./chunk-KNTDFP7X.js";import{b as e}from"./chunk-T6OIISUC.js";import{b as d}from"./chunk-G4AUMZUY.js";import{b as c}from"./chunk-ABP4OLJV.js";import{b as h}from"./chunk-VTAMGD42.js";import"./chunk-6KHZX4HU.js";import"./chunk-3PCPQIUD.js";import"./chunk-TW2IJRUF.js";import"./chunk-QKJAAJ7J.js";import"./chunk-K27FY3ES.js";import"./chunk-MROECM42.js";import"./chunk-42AMF6EE.js";import"./chunk-YXPSX3SI.js";import{b as i}from"./chunk-CMTQFWZK.js";import{b as g}from"./chunk-NXUXZWS5.js";import"./chunk-2UV6ZFHK.js";import"./chunk-GR4ZHKXI.js";import"./chunk-HWI42GQO.js";import{b as m}from"./chunk-WAJVRK5B.js";import"./chunk-HW2VJKFH.js";import"./chunk-YERKK5B3.js";import{b as F}from"./chunk-6FGMEZZP.js";import"./chunk-I57EACSL.js";import"./chunk-7JZKVC3F.js";import{b as z}from"./chunk-CN4JKMTR.js";import{b as f}from"./chunk-3ROYEBJI.js";import"./chunk-MBREBDZQ.js";import"./chunk-HWK7KFGB.js";import"./chunk-FUT3X2GJ.js";import"./chunk-CPKBPQ2C.js";import"./chunk-OHFB3M3X.js";import"./chunk-PBOVSFTJ.js";import"./chunk-NE4R2FVV.js";import{b as n}from"./chunk-QL33F2W6.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";var Er=[i,g,m,F,z,f,n,t,l,u,p,e,d,c,h,w,x,v,k,q,C,b,I,M,j,y,A,$,S,T,B,D,E,G,H,J,K,L,O,P,Q,R,U,V,W,X,Y,Z,_,N,rr,or,ar,sr,ir,gr,mr,Fr,zr,fr,nr,tr,lr,ur,pr,er,dr,cr,hr,wr,xr,vr,kr,qr,Cr,br,Ir,Mr,jr,yr,Ar,$r,Sr];function Tr(){return Er}var Br=new Map;for(let r of Tr())Br.set(r.name,new Set(r.flags.map(o=>o.flag)));function Fa(r,o,Dr){let a=Br.get(o);if(!(!a||a.size===0))for(let s of Dr)a.has(s)&&r.hit(`cmd:flag:${o}:${s}`)}export{Fa as emitFlagCoverage};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
+
import{a as B,b as A}from"./chunk-E54Z6VIE.js";import{a as q}from"./chunk-3DWQCLNP.js";import"./chunk-3MRB66F4.js";import"./chunk-O2BCKSMK.js";import"./chunk-TW2IJRUF.js";import{b as v,c as j}from"./chunk-QKJAAJ7J.js";import{a as F}from"./chunk-MROECM42.js";import{b as C}from"./chunk-HWI42GQO.js";import{b as E}from"./chunk-CPKBPQ2C.js";import"./chunk-OHFB3M3X.js";import{a as W,b as h}from"./chunk-PBOVSFTJ.js";import{a as S}from"./chunk-I4IRHQDW.js";import{b as M}from"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";import{AsyncLocalStorage as J}from"node:async_hooks";import{fileURLToPath as H}from"node:url";import{Worker as L}from"node:worker_threads";var O=new J,P=`js-exec - Sandboxed JavaScript/TypeScript runtime with Node.js-compatible APIs
|
|
4
|
+
|
|
5
|
+
Usage: js-exec [OPTIONS] [-c CODE | FILE] [ARGS...]
|
|
6
|
+
|
|
7
|
+
Options:
|
|
8
|
+
-c CODE Execute inline code
|
|
9
|
+
-m, --module Enable ES module mode (import/export)
|
|
10
|
+
--strip-types Strip TypeScript type annotations
|
|
11
|
+
--version, -V Show version
|
|
12
|
+
--help Show this help
|
|
13
|
+
|
|
14
|
+
Examples:
|
|
15
|
+
js-exec -c "console.log(1 + 2)"
|
|
16
|
+
js-exec script.js
|
|
17
|
+
js-exec app.ts
|
|
18
|
+
echo 'console.log("hello")' | js-exec
|
|
19
|
+
|
|
20
|
+
File Extension Auto-Detection:
|
|
21
|
+
.js script mode (module mode if top-level await detected)
|
|
22
|
+
.mjs ES module mode
|
|
23
|
+
.ts, .mts ES module mode + TypeScript stripping
|
|
24
|
+
|
|
25
|
+
Node.js Compatibility:
|
|
26
|
+
Code written for Node.js largely works here. Both require and import
|
|
27
|
+
are supported, the node: prefix works, and standard globals like process,
|
|
28
|
+
console, and fetch are available. All I/O is synchronous.
|
|
29
|
+
|
|
30
|
+
Available modules:
|
|
31
|
+
fs, path, child_process, process, console,
|
|
32
|
+
os, url, assert, util, events, buffer, stream,
|
|
33
|
+
string_decoder, querystring
|
|
34
|
+
|
|
35
|
+
fs (global, require('fs'), or import from 'node:fs'):
|
|
36
|
+
readFileSync, writeFileSync, appendFileSync, copyFileSync, renameSync
|
|
37
|
+
readdirSync, mkdirSync, rmSync, unlinkSync, rmdirSync
|
|
38
|
+
statSync, lstatSync, existsSync, realpathSync, chmodSync
|
|
39
|
+
symlinkSync, readlinkSync, readFileBuffer
|
|
40
|
+
fs.promises.readFile, fs.promises.writeFile, fs.promises.access, ...
|
|
41
|
+
|
|
42
|
+
path: join, resolve, dirname, basename, extname, normalize,
|
|
43
|
+
relative, isAbsolute, parse, format, sep, delimiter
|
|
44
|
+
|
|
45
|
+
child_process:
|
|
46
|
+
execSync(cmd) throws on non-zero exit, returns stdout
|
|
47
|
+
spawnSync(cmd, args) returns { stdout, stderr, status }
|
|
48
|
+
|
|
49
|
+
process (also global): argv, cwd(), exit(), env, platform, arch,
|
|
50
|
+
version, versions
|
|
51
|
+
|
|
52
|
+
os: platform(), arch(), homedir(), tmpdir(), type(), hostname(),
|
|
53
|
+
EOL, cpus(), endianness()
|
|
54
|
+
|
|
55
|
+
url: URL, URLSearchParams, parse(), format()
|
|
56
|
+
|
|
57
|
+
assert: ok(), equal(), strictEqual(), deepEqual(), throws(),
|
|
58
|
+
doesNotThrow(), fail()
|
|
59
|
+
|
|
60
|
+
util: format(), inspect(), promisify(), types, inherits()
|
|
61
|
+
|
|
62
|
+
events: EventEmitter (on, once, emit, off, removeListener, ...)
|
|
63
|
+
|
|
64
|
+
buffer: Buffer.from(), Buffer.alloc(), Buffer.concat(),
|
|
65
|
+
Buffer.isBuffer(), toString(), slice(), equals()
|
|
66
|
+
|
|
67
|
+
stream: Readable, Writable, Duplex, Transform, PassThrough, pipeline
|
|
68
|
+
|
|
69
|
+
string_decoder: StringDecoder (write, end)
|
|
70
|
+
|
|
71
|
+
querystring: parse(), stringify(), escape(), unescape()
|
|
72
|
+
|
|
73
|
+
Other Globals:
|
|
74
|
+
console log (stdout), error/warn (stderr)
|
|
75
|
+
fetch(url, opts) HTTP; returns Promise<Response> (Web Fetch API)
|
|
76
|
+
URL, URLSearchParams, Headers, Request, Response
|
|
77
|
+
Buffer Buffer.from(), Buffer.alloc(), etc.
|
|
78
|
+
|
|
79
|
+
Not Available:
|
|
80
|
+
http, https, net, tls, crypto, zlib, dns, cluster, worker_threads,
|
|
81
|
+
vm, v8, readline, and other Node.js built-in modules that require
|
|
82
|
+
native bindings. Use fetch() for HTTP requests.
|
|
83
|
+
|
|
84
|
+
Limits:
|
|
85
|
+
Memory: 64 MB per execution
|
|
86
|
+
Timeout: 10 s by default; configurable via maxJsTimeoutMs
|
|
87
|
+
Engine: QuickJS (compiled to WebAssembly)
|
|
88
|
+
`;function N(r){let e={code:null,scriptFile:null,showVersion:!1,scriptArgs:[],isModule:!1,stripTypes:!1};if(r.length===0)return e;for(let t=0;t<r.length;t++){let s=r[t];if(s==="-m"||s==="--module"){e.isModule=!0;continue}if(s==="--strip-types"){e.stripTypes=!0;continue}if(s==="-c")return t+1>=r.length?{stdout:"",stderr:`js-exec: option requires an argument -- 'c'
|
|
89
|
+
`,exitCode:2}:(e.code=r[t+1],e.scriptArgs=r.slice(t+2),e);if(s==="--version"||s==="-V")return e.showVersion=!0,e;if(s.startsWith("-")&&s!=="-"&&s!=="--")return{stdout:"",stderr:`js-exec: unrecognized option '${s}'
|
|
90
|
+
`,exitCode:2};if(s==="--")return t+1<r.length&&(e.scriptFile=r[t+1],e.scriptArgs=r.slice(t+2)),e;if(!s.startsWith("-"))return e.scriptFile=s,e.scriptArgs=r.slice(t+1),e}return e}var l=null,y=null,c=[],n=null,x=null,U=1e3,R=5e3;function fe(r){R=r}function pe(){return l!==null}function _(r,e,t){r.controller.close();let s=!1,o=()=>{if(!s&&(s=!0,v(i),n===r)){x="worker termination was not acknowledged";for(let a of c)a.bridgeHandler.stop(),a.resolve({success:!1,error:x});c.length=0,r.resolve(t)}},u=()=>{s||(s=!0,v(i),n===r&&(r.resolve(t),n=null,g()))},i=j(()=>{o()},U);r.controller.terminate(e).then(a=>a?u():o(),o)}function me(){y&&(v(y),y=null),n?.bridgeHandler.stop(),n=null;for(let e of c)e.bridgeHandler.stop();c.length=0;let r=l;l=null,r&&r.terminate(),x=null}var D=H(new URL("./js-exec-worker.js",import.meta.url));function g(){if(n||c.length===0)return;let r=c.shift();if(!r)return;n=r;let e=null;try{e=V(),e.postMessage(r.input)}catch(t){r.bridgeHandler.stop();let s={success:!1,error:h(S(t))},o=e??l;l===o&&(l=null),o?_(r,o,s):(r.resolve(s),n===r&&(n=null),g())}}function $(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"}:typeof t.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:t.success?{success:!0}:{success:!1,type:t.type==="initialization-failure"?"initialization-failure":void 0,error:typeof t.error=="string"&&t.error.length>0?t.error:"Worker execution failed"}}function V(){if(y&&(v(y),y=null),l)return l;let r=C.runTrusted(()=>new L(D));return l=r,r.on("message",e=>{if(l===r){if(n){let t;try{n.controller.assertMessageSize(e,"response"),t=$(e,n.input.protocolToken)}catch(s){t={success:!1,error:h(S(s))}}if(t.type==="initialization-failure"){x=t.error??"Worker initialization failed",n.bridgeHandler.stop(),n.resolve(t),n=null;for(let s of c)s.bridgeHandler.stop(),s.resolve({success:!1,type:"initialization-failure",error:x});c.length=0,l=null,r.terminate();return}n.resolve(t),n=null}c.length>0?g():Q()}}),r.on("error",e=>{if(l===r){if(n){let t=h(S(e));n.resolve({success:!1,error:t}),n=null}for(let t of c)t.resolve({success:!1,error:"Worker crashed"});c.length=0,l=null}}),r.on("exit",()=>{l===r&&(l=null,n&&(n.resolve({success:!1,error:"Worker exited unexpectedly"}),n=null),c.length>0&&g())}),r}function Q(){y=j(()=>{l&&!n&&c.length===0&&(l.terminate(),l=null)},R)}async function G(r,e,t,s=[],o,u,i){return O.getStore()?{stdout:"",stderr:`js-exec: recursive invocation is not supported
|
|
91
|
+
`,exitCode:1}:Y(r,e,t,s,o,u,i)}async function K(r,e,t,s){let o,u=new Promise(d=>{o=d}),i={input:r,bridgeHandler:e,resolve:()=>{},controller:s};s.assertMessageSize({...r,sharedBuffer:void 0},"request");let a=d=>{e.stop();let f={success:!1,error:d==="abort"?i.controller.abortMessage():i.controller.timeoutMessage()};if(n===i){let p=l;l=null,p?_(i,p,f):(i.resolve(f),n=null,g())}else{let p=c.indexOf(i);p!==-1&&c.splice(p,1),i.resolve(f),n||g()}};if(i.resolve=d=>{i.controller.close(),o(d)},i.controller.arm(a),!i.controller.isCanceled){c.push(i);try{g()}catch(d){let f=c.indexOf(i);throw f!==-1&&c.splice(f,1),i.controller.close(),d}}let[m,k]=await Promise.all([e.run(t),u.catch(d=>({success:!1,error:h(S(d))}))]);return{bridgeOutput:m,workerResult:k}}function X(r){return r.limits.maxJsTimeoutMs}async function Y(r,e,t,s=[],o,u,i){if(x!==null)return{stdout:"",stderr:`js-exec: ${h(x)}
|
|
92
|
+
`,exitCode:1};let a=B(),m=e.exec,k=m?(b,I)=>O.run(!0,()=>m(b,I)):void 0,d=new A(a,e.fs,e.cwd,"js-exec",e.fetch,e.limits.maxOutputSize,k,e.invokeTool),f=X(e),p=new q({commandName:"js-exec",timeoutMs:f,signal:e.signal,maxMessageBytes:e.limits.maxWorkerMessageBytes}),z={protocolToken:p.protocolToken,sharedBuffer:a,jsCode:r,cwd:e.cwd,env:F(e.env),args:s,scriptPath:t,bootstrapCode:o,isModule:u,stripTypes:i,timeoutMs:f,memoryBytes:e.limits.maxJsMemoryBytes,hasInvokeTool:e.invokeTool!==void 0},{bridgeOutput:T,workerResult:w}=await K(z,d,f,p);if(!w.success&&w.error){let b=w.error===p.timeoutMessage()||w.error===p.abortMessage();return{stdout:T.stdout,stderr:`${T.stderr}js-exec: ${h(w.error)}
|
|
93
|
+
`,exitCode:T.exitCode||(b?124:1)}}return{...T}}var he={name:"js-exec",async execute(r,e){if(M(r))return{stdout:P,stderr:"",exitCode:0};let t=N(r);if("exitCode"in t)return t;if(t.showVersion)return{stdout:`QuickJS (quickjs-emscripten)
|
|
94
|
+
`,stderr:"",exitCode:0};let s,o;if(t.code!==null)s=t.code,o="-c";else if(t.scriptFile!==null){let m=e.fs.resolvePath(e.cwd,t.scriptFile);if(!await e.fs.exists(m))return{stdout:"",stderr:`js-exec: can't open file '${t.scriptFile}': No such file or directory
|
|
95
|
+
`,exitCode:2};try{s=await e.fs.readFile(m),o=m}catch(k){return{stdout:"",stderr:`js-exec: can't open file '${t.scriptFile}': ${W(k.message)}
|
|
96
|
+
`,exitCode:2}}}else if(E(e.stdin).trim())s=E(e.stdin),o="<stdin>";else return{stdout:"",stderr:`js-exec: no input provided (use -c CODE or provide a script file)
|
|
97
|
+
`,exitCode:2};let u=t.isModule,i=t.stripTypes;o&&o!=="-c"&&o!=="<stdin>"&&((o.endsWith(".mjs")||o.endsWith(".mts")||o.endsWith(".ts"))&&(u=!0),(o.endsWith(".ts")||o.endsWith(".mts"))&&(i=!0)),!u&&/\bawait\s+[\w([`]/.test(s)&&(u=!0);let a=e.jsBootstrapCode;return G(s,e,o,t.scriptArgs,a,u,i)}},ye={name:"node",async execute(){return{stdout:"",stderr:`node: this sandbox uses js-exec instead of node
|
|
98
|
+
|
|
99
|
+
${P}`,exitCode:1}}};export{pe as _hasSharedJsExecWorkerForTests,me as _resetJsExecWorkerForTests,fe as _setJsExecWorkerIdleTimeoutMsForTests,he as jsExecCommand,ye as nodeStubCommand};
|