@darkrymit/crunes-cli 0.14.3 → 0.14.4

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.
@@ -73610,13 +73610,15 @@ function resolveRuneExecCwd(projectDir, cwdOpt, checkPermission) {
73610
73610
  async function injectUtils(isolate, context, utils2, _runeCallback, vars, projectDir, checkPermission, sections, onEvent, runeContext, memoryMb) {
73611
73611
  const currentRuneKey = runeContext?.key ?? null;
73612
73612
  const jail = context.global;
73613
+ const setOps = [];
73614
+ const setGlobal = (k, v) => setOps.push(jail.set(k, v));
73613
73615
  const asyncRef = (fn) => new ivm2.Reference((...args) => {
73614
73616
  const p2 = fn(...args);
73615
73617
  if (p2 && typeof p2.catch === "function") p2.catch(() => {
73616
73618
  });
73617
73619
  return p2;
73618
73620
  });
73619
- await jail.set("$__utils_fs_read", new ivm2.Reference(async (relPath, opts) => {
73621
+ setGlobal("$__utils_fs_read", new ivm2.Reference(async (relPath, opts) => {
73620
73622
  const content = await utils2.fs.read(relPath, opts);
73621
73623
  const limit = memoryMb * 1024 * 1024;
73622
73624
  if (content && content.length * 2 > limit && (content.length > limit || /[^\u0000-\u00ff]/.test(content))) {
@@ -73624,60 +73626,60 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73624
73626
  }
73625
73627
  return content;
73626
73628
  }));
73627
- await jail.set("$__utils_fs_resolve", new ivm2.Reference(async (relPath) => {
73629
+ setGlobal("$__utils_fs_resolve", new ivm2.Reference(async (relPath) => {
73628
73630
  return utils2.fs.resolve(relPath);
73629
73631
  }));
73630
- await jail.set("$__utils_fs_exists", new ivm2.Reference(async (relPath) => {
73632
+ setGlobal("$__utils_fs_exists", new ivm2.Reference(async (relPath) => {
73631
73633
  return utils2.fs.exists(relPath);
73632
73634
  }));
73633
- await jail.set("$__utils_fs_glob", new ivm2.Reference(async (pattern, opts) => {
73635
+ setGlobal("$__utils_fs_glob", new ivm2.Reference(async (pattern, opts) => {
73634
73636
  return utils2.fs.glob(pattern, opts);
73635
73637
  }));
73636
- await jail.set("$__utils_fs_write", new ivm2.Reference(async (relPath, content) => {
73638
+ setGlobal("$__utils_fs_write", new ivm2.Reference(async (relPath, content) => {
73637
73639
  return utils2.fs.write(relPath, content);
73638
73640
  }));
73639
- await jail.set("$__utils_fs_copy", new ivm2.Reference(async (src, dest) => {
73641
+ setGlobal("$__utils_fs_copy", new ivm2.Reference(async (src, dest) => {
73640
73642
  await utils2.fs.copy(src, dest);
73641
73643
  }));
73642
- await jail.set("$__utils_fs_remove", new ivm2.Reference(async (relPath, opts) => {
73644
+ setGlobal("$__utils_fs_remove", new ivm2.Reference(async (relPath, opts) => {
73643
73645
  return utils2.fs.remove(relPath, opts);
73644
73646
  }));
73645
- await jail.set("$__utils_fs_move", new ivm2.Reference(async (src, dest) => {
73647
+ setGlobal("$__utils_fs_move", new ivm2.Reference(async (src, dest) => {
73646
73648
  return utils2.fs.move(src, dest);
73647
73649
  }));
73648
- await jail.set("$__utils_fs_stat", new ivm2.Reference(async (relPath) => {
73650
+ setGlobal("$__utils_fs_stat", new ivm2.Reference(async (relPath) => {
73649
73651
  return utils2.fs.stat(relPath);
73650
73652
  }));
73651
- await jail.set("$__utils_fs_mkdir", new ivm2.Reference(async (relPath) => {
73653
+ setGlobal("$__utils_fs_mkdir", new ivm2.Reference(async (relPath) => {
73652
73654
  return utils2.fs.mkdir(relPath);
73653
73655
  }));
73654
- await jail.set("$__utils_fs_read_bytes", new ivm2.Reference(async (relPath, opts) => {
73656
+ setGlobal("$__utils_fs_read_bytes", new ivm2.Reference(async (relPath, opts) => {
73655
73657
  const bytes = await utils2.fs.readBytes(relPath, opts);
73656
73658
  if (!bytes) return null;
73657
73659
  const copy = new Uint8Array(bytes.length);
73658
73660
  copy.set(bytes);
73659
73661
  return copy.buffer;
73660
73662
  }));
73661
- await jail.set("$__utils_fs_write_bytes", new ivm2.Reference(async (relPath, arrayBuffer, byteOffset, byteLength) => {
73663
+ setGlobal("$__utils_fs_write_bytes", new ivm2.Reference(async (relPath, arrayBuffer, byteOffset, byteLength) => {
73662
73664
  const bytes = new Uint8Array(arrayBuffer, byteOffset ?? 0, byteLength ?? arrayBuffer.byteLength);
73663
73665
  return utils2.fs.writeBytes(relPath, bytes);
73664
73666
  }));
73665
- await jail.set("$__utils_fs_append", new ivm2.Reference(async (relPath, content) => {
73667
+ setGlobal("$__utils_fs_append", new ivm2.Reference(async (relPath, content) => {
73666
73668
  return utils2.fs.append(relPath, content);
73667
73669
  }));
73668
- await jail.set("$__utils_fs_append_bytes", new ivm2.Reference(async (relPath, arrayBuffer, byteOffset, byteLength) => {
73670
+ setGlobal("$__utils_fs_append_bytes", new ivm2.Reference(async (relPath, arrayBuffer, byteOffset, byteLength) => {
73669
73671
  const bytes = new Uint8Array(arrayBuffer, byteOffset ?? 0, byteLength ?? arrayBuffer.byteLength);
73670
73672
  return utils2.fs.appendBytes(relPath, bytes);
73671
73673
  }));
73672
- await jail.set("$__utils_fs_chmod", new ivm2.Reference(async (relPath, mode) => {
73674
+ setGlobal("$__utils_fs_chmod", new ivm2.Reference(async (relPath, mode) => {
73673
73675
  return utils2.fs.chmod(relPath, mode);
73674
73676
  }));
73675
- await jail.set("$__utils_fs_prepend", new ivm2.Reference(async (relPath, content) => {
73677
+ setGlobal("$__utils_fs_prepend", new ivm2.Reference(async (relPath, content) => {
73676
73678
  return utils2.fs.prepend(relPath, content);
73677
73679
  }));
73678
73680
  const watchers = /* @__PURE__ */ new Map();
73679
73681
  let nextWatcherId = 1;
73680
- await jail.set("$__utils_fs_watch", new ivm2.Reference((patternRef, callbackRef, optsRef) => {
73682
+ setGlobal("$__utils_fs_watch", new ivm2.Reference((patternRef, callbackRef, optsRef) => {
73681
73683
  const pattern = typeof patternRef === "object" && patternRef.copySync ? patternRef.copySync() : patternRef;
73682
73684
  const opts = typeof optsRef === "object" && optsRef.copySync ? optsRef.copySync() : optsRef ?? {};
73683
73685
  const id = nextWatcherId++;
@@ -73688,7 +73690,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73688
73690
  watchers.set(id, handle);
73689
73691
  return id;
73690
73692
  }));
73691
- await jail.set("$__utils_fs_watch_stop", new ivm2.Reference((id) => {
73693
+ setGlobal("$__utils_fs_watch_stop", new ivm2.Reference((id) => {
73692
73694
  const handle = watchers.get(id);
73693
73695
  if (handle) {
73694
73696
  handle.stop();
@@ -73697,13 +73699,13 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73697
73699
  }));
73698
73700
  const streams = /* @__PURE__ */ new Map();
73699
73701
  let nextStreamId = 1;
73700
- await jail.set("$__utils_fs_readStream", new ivm2.Reference(async (relPath) => {
73702
+ setGlobal("$__utils_fs_readStream", new ivm2.Reference(async (relPath) => {
73701
73703
  const iter = utils2.fs.readStreamIter(relPath)[Symbol.asyncIterator]();
73702
73704
  const id = nextStreamId++;
73703
73705
  streams.set(id, iter);
73704
73706
  return id;
73705
73707
  }));
73706
- await jail.set("$__utils_fs_readStream_next", new ivm2.Reference(async (id) => {
73708
+ setGlobal("$__utils_fs_readStream_next", new ivm2.Reference(async (id) => {
73707
73709
  const iter = streams.get(id);
73708
73710
  if (!iter) throw new Error(`Invalid read stream ID: ${id}`);
73709
73711
  const { value, done } = await iter.next();
@@ -73715,13 +73717,13 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73715
73717
  copy.set(value);
73716
73718
  return copy.buffer;
73717
73719
  }));
73718
- await jail.set("$__utils_fs_readLines", asyncRef(async (relPath, opts) => {
73720
+ setGlobal("$__utils_fs_readLines", asyncRef(async (relPath, opts) => {
73719
73721
  const iter = utils2.fs.readLinesIter(relPath, opts);
73720
73722
  const id = nextStreamId++;
73721
73723
  streams.set(id, iter);
73722
73724
  return id;
73723
73725
  }));
73724
- await jail.set("$__utils_fs_readLines_next", asyncRef(async (id) => {
73726
+ setGlobal("$__utils_fs_readLines_next", asyncRef(async (id) => {
73725
73727
  const iter = streams.get(id);
73726
73728
  if (!iter) throw new Error(`Invalid line stream ID: ${id}`);
73727
73729
  const { value, done } = await iter.next();
@@ -73731,30 +73733,30 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73731
73733
  }
73732
73734
  return value;
73733
73735
  }));
73734
- await jail.set("$__utils_fs_readLines_cancel", asyncRef(async (id) => {
73736
+ setGlobal("$__utils_fs_readLines_cancel", asyncRef(async (id) => {
73735
73737
  const iter = streams.get(id);
73736
73738
  streams.delete(id);
73737
73739
  await iter?.return();
73738
73740
  }));
73739
- await jail.set("$__utils_fs_writeStream", new ivm2.Reference(async (relPath) => {
73741
+ setGlobal("$__utils_fs_writeStream", new ivm2.Reference(async (relPath) => {
73740
73742
  const ref = await utils2.fs.writeStreamRef(relPath);
73741
73743
  const id = nextStreamId++;
73742
73744
  streams.set(id, ref);
73743
73745
  return id;
73744
73746
  }));
73745
- await jail.set("$__utils_fs_appendStream", new ivm2.Reference(async (relPath) => {
73747
+ setGlobal("$__utils_fs_appendStream", new ivm2.Reference(async (relPath) => {
73746
73748
  const ref = await utils2.fs.appendStreamRef(relPath);
73747
73749
  const id = nextStreamId++;
73748
73750
  streams.set(id, ref);
73749
73751
  return id;
73750
73752
  }));
73751
- await jail.set("$__utils_fs_writeStream_write", new ivm2.Reference(async (id, arrayBuffer, byteOffset, byteLength) => {
73753
+ setGlobal("$__utils_fs_writeStream_write", new ivm2.Reference(async (id, arrayBuffer, byteOffset, byteLength) => {
73752
73754
  const ref = streams.get(id);
73753
73755
  if (!ref) throw new Error(`Invalid write stream ID: ${id}`);
73754
73756
  const bytes = new Uint8Array(arrayBuffer, byteOffset ?? 0, byteLength ?? arrayBuffer.byteLength);
73755
73757
  await ref.write(bytes);
73756
73758
  }));
73757
- await jail.set("$__utils_fs_writeStream_close", new ivm2.Reference(async (id) => {
73759
+ setGlobal("$__utils_fs_writeStream_close", new ivm2.Reference(async (id) => {
73758
73760
  const ref = streams.get(id);
73759
73761
  if (!ref) throw new Error(`Invalid write stream ID: ${id}`);
73760
73762
  await ref.close();
@@ -73762,7 +73764,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73762
73764
  }));
73763
73765
  const shellHandles = /* @__PURE__ */ new Map();
73764
73766
  let nextShellHandle = 0;
73765
- await jail.set("$__utils_shell_exec", asyncRef(async (cmd, opts, stdinStreamId) => {
73767
+ setGlobal("$__utils_shell_exec", asyncRef(async (cmd, opts, stdinStreamId) => {
73766
73768
  let stdinStream;
73767
73769
  if (stdinStreamId !== void 0 && stdinStreamId !== null) {
73768
73770
  const { PassThrough: PassThrough3 } = await import("node:stream");
@@ -73822,17 +73824,17 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73822
73824
  }
73823
73825
  return res;
73824
73826
  }));
73825
- await jail.set("$__utils_shell_spawn_open", new ivm2.Reference((cmd, opts) => {
73827
+ setGlobal("$__utils_shell_spawn_open", new ivm2.Reference((cmd, opts) => {
73826
73828
  const session = utils2.shell.spawn(cmd, opts);
73827
73829
  const id = String(nextShellHandle++);
73828
73830
  shellHandles.set(id, session);
73829
73831
  return id;
73830
73832
  }));
73831
- await jail.set("$__utils_shell_spawn_start", new ivm2.Reference((id) => {
73833
+ setGlobal("$__utils_shell_spawn_start", new ivm2.Reference((id) => {
73832
73834
  const handle = shellHandles.get(id);
73833
73835
  if (handle) handle.open();
73834
73836
  }));
73835
- await jail.set("$__utils_shell_spawn_write", new ivm2.Reference((idRef, chunkRef) => {
73837
+ setGlobal("$__utils_shell_spawn_write", new ivm2.Reference((idRef, chunkRef) => {
73836
73838
  const id = typeof idRef === "object" && idRef.copySync ? idRef.copySync() : idRef;
73837
73839
  const chunk = typeof chunkRef === "object" && chunkRef.copySync ? chunkRef.copySync() : chunkRef;
73838
73840
  const handle = shellHandles.get(id);
@@ -73844,13 +73846,13 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73844
73846
  }
73845
73847
  }
73846
73848
  }));
73847
- await jail.set("$__utils_shell_spawn_end", new ivm2.Reference((id) => {
73849
+ setGlobal("$__utils_shell_spawn_end", new ivm2.Reference((id) => {
73848
73850
  const handle = shellHandles.get(id);
73849
73851
  if (handle) {
73850
73852
  handle.proc.stdin.end();
73851
73853
  }
73852
73854
  }));
73853
- await jail.set("$__utils_shell_spawn_on", new ivm2.Reference((idRef, typeRef, eventRef, callbackRef) => {
73855
+ setGlobal("$__utils_shell_spawn_on", new ivm2.Reference((idRef, typeRef, eventRef, callbackRef) => {
73854
73856
  const id = typeof idRef === "object" && idRef.copySync ? idRef.copySync() : idRef;
73855
73857
  const type = typeof typeRef === "object" && typeRef.copySync ? typeRef.copySync() : typeRef;
73856
73858
  const event = typeof eventRef === "object" && eventRef.copySync ? eventRef.copySync() : eventRef;
@@ -73859,14 +73861,14 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73859
73861
  handle.setHandler(type, event, callbackRef);
73860
73862
  }
73861
73863
  }));
73862
- await jail.set("$__utils_shell_spawn_kill", new ivm2.Reference((id, signal) => {
73864
+ setGlobal("$__utils_shell_spawn_kill", new ivm2.Reference((id, signal) => {
73863
73865
  const handle = shellHandles.get(id);
73864
73866
  if (handle) {
73865
73867
  handle.kill(signal ?? void 0);
73866
73868
  shellHandles.delete(id);
73867
73869
  }
73868
73870
  }));
73869
- await jail.set("$__utils_shell_job_start", asyncRef(async (cmd, opts) => {
73871
+ setGlobal("$__utils_shell_job_start", asyncRef(async (cmd, opts) => {
73870
73872
  checkPermission("shell.job.start", cmd);
73871
73873
  return utils2.shell.createShellJob(cmd, opts, {
73872
73874
  createJob,
@@ -73879,21 +73881,21 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73879
73881
  projectDir
73880
73882
  });
73881
73883
  }));
73882
- await jail.set("$__utils_shell_job_write", asyncRef(async (id, text) => {
73884
+ setGlobal("$__utils_shell_job_write", asyncRef(async (id, text) => {
73883
73885
  checkPermission("shell.job.write", null);
73884
73886
  const record = await getJob(projectDir, id);
73885
73887
  if (!record) throw new Error(`Unknown job: ${id}`);
73886
73888
  const logPath = jobStdinPath(projectDir, id);
73887
73889
  await fsSync.promises.appendFile(logPath, text + "\n", "utf8");
73888
73890
  }));
73889
- await jail.set("$__utils_shell_job_write_eof", asyncRef(async (id) => {
73891
+ setGlobal("$__utils_shell_job_write_eof", asyncRef(async (id) => {
73890
73892
  checkPermission("shell.job.write", null);
73891
73893
  const record = await getJob(projectDir, id);
73892
73894
  if (!record) throw new Error(`Unknown job: ${id}`);
73893
73895
  const logPath = jobStdinPath(projectDir, id);
73894
73896
  await fsSync.promises.appendFile(logPath, EOF_SENTINEL + "\n", "utf8");
73895
73897
  }));
73896
- await jail.set("$__utils_shell_job_kill", asyncRef(async (id, signal) => {
73898
+ setGlobal("$__utils_shell_job_kill", asyncRef(async (id, signal) => {
73897
73899
  checkPermission("shell.job.kill", null);
73898
73900
  const sig = signal ?? "SIGTERM";
73899
73901
  if (!VALID_SIGNALS.has(sig)) throw new Error(`Invalid signal: ${sig}`);
@@ -73908,7 +73910,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73908
73910
  }
73909
73911
  }
73910
73912
  }));
73911
- await jail.set("$__utils_shell_job_exists", asyncRef(async (id) => {
73913
+ setGlobal("$__utils_shell_job_exists", asyncRef(async (id) => {
73912
73914
  checkPermission("shell.job.exists", null);
73913
73915
  const record = await getJob(projectDir, id);
73914
73916
  if (!record) return false;
@@ -73919,7 +73921,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73919
73921
  return false;
73920
73922
  }
73921
73923
  }));
73922
- await jail.set("$__utils_shell_job_stdout", asyncRef(async (id) => {
73924
+ setGlobal("$__utils_shell_job_stdout", asyncRef(async (id) => {
73923
73925
  checkPermission("shell.job.read", null);
73924
73926
  const record = await getJob(projectDir, id);
73925
73927
  if (!record) throw new Error(`Unknown job: ${id}`);
@@ -73927,7 +73929,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73927
73929
  if (!fsSync.existsSync(logPath)) return "";
73928
73930
  return fsSync.promises.readFile(logPath, "utf8");
73929
73931
  }));
73930
- await jail.set("$__utils_shell_job_stderr", asyncRef(async (id) => {
73932
+ setGlobal("$__utils_shell_job_stderr", asyncRef(async (id) => {
73931
73933
  checkPermission("shell.job.read", null);
73932
73934
  const record = await getJob(projectDir, id);
73933
73935
  if (!record) throw new Error(`Unknown job: ${id}`);
@@ -73935,23 +73937,23 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73935
73937
  if (!fsSync.existsSync(logPath)) return "";
73936
73938
  return fsSync.promises.readFile(logPath, "utf8");
73937
73939
  }));
73938
- await jail.set("$__utils_section_emit", new ivm2.Reference((sectionOrArray) => {
73940
+ setGlobal("$__utils_section_emit", new ivm2.Reference((sectionOrArray) => {
73939
73941
  const items = Array.isArray(sectionOrArray) ? sectionOrArray : [sectionOrArray];
73940
73942
  for (const section of items) {
73941
73943
  if (sections) sections.push(section);
73942
73944
  if (onEvent) onEvent({ type: "section", section });
73943
73945
  }
73944
73946
  }));
73945
- await jail.set("$__utils_section_create", new ivm2.Reference((name, data, opts) => {
73947
+ setGlobal("$__utils_section_create", new ivm2.Reference((name, data, opts) => {
73946
73948
  return utils2.section.create(name, data, opts);
73947
73949
  }));
73948
- await jail.set("$__utils_section_match", new ivm2.Reference((sectionName, patterns) => {
73950
+ setGlobal("$__utils_section_match", new ivm2.Reference((sectionName, patterns) => {
73949
73951
  return utils2.section.match(sectionName, patterns);
73950
73952
  }));
73951
- await jail.set("$__utils_section_selected", new ivm2.Reference(() => {
73953
+ setGlobal("$__utils_section_selected", new ivm2.Reference(() => {
73952
73954
  return utils2.section.selected() ?? void 0;
73953
73955
  }));
73954
- await jail.set("$__utils_rune_exec", asyncRef(async (runeKey, args, opts) => {
73956
+ setGlobal("$__utils_rune_exec", asyncRef(async (runeKey, args, opts) => {
73955
73957
  const repl = opts?.repl === true;
73956
73958
  if (repl) {
73957
73959
  checkPermission("rune.repl", runeKey);
@@ -73998,7 +74000,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
73998
74000
  }
73999
74001
  return { sections: sections2, stdout, stderr, exitCode, ok: exitCode === 0 };
74000
74002
  }));
74001
- await jail.set("$__utils_rune_spawn_open", new ivm2.Reference((runeKey, args, opts) => {
74003
+ setGlobal("$__utils_rune_spawn_open", new ivm2.Reference((runeKey, args, opts) => {
74002
74004
  const repl = opts?.repl === true;
74003
74005
  if (repl) {
74004
74006
  checkPermission("rune.repl", runeKey);
@@ -74011,45 +74013,45 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74011
74013
  shellHandles.set(id, session);
74012
74014
  return id;
74013
74015
  }));
74014
- await jail.set("$__utils_rune_spawn_start", new ivm2.Reference((id) => {
74016
+ setGlobal("$__utils_rune_spawn_start", new ivm2.Reference((id) => {
74015
74017
  const handle = shellHandles.get(id);
74016
74018
  if (handle) handle.open();
74017
74019
  }));
74018
- await jail.set("$__utils_rune_spawn_on", new ivm2.Reference((idRef, typeRef, eventRef, callbackRef) => {
74020
+ setGlobal("$__utils_rune_spawn_on", new ivm2.Reference((idRef, typeRef, eventRef, callbackRef) => {
74019
74021
  const id = typeof idRef === "object" && idRef.copySync ? idRef.copySync() : idRef;
74020
74022
  const type = typeof typeRef === "object" && typeRef.copySync ? typeRef.copySync() : typeRef;
74021
74023
  const event = typeof eventRef === "object" && eventRef.copySync ? eventRef.copySync() : eventRef;
74022
74024
  const handle = shellHandles.get(id);
74023
74025
  if (handle) handle.setHandler(type, event, callbackRef);
74024
74026
  }));
74025
- await jail.set("$__utils_rune_spawn_kill", new ivm2.Reference((id, signal) => {
74027
+ setGlobal("$__utils_rune_spawn_kill", new ivm2.Reference((id, signal) => {
74026
74028
  const handle = shellHandles.get(id);
74027
74029
  if (handle) {
74028
74030
  handle.kill(signal ?? void 0);
74029
74031
  shellHandles.delete(id);
74030
74032
  }
74031
74033
  }));
74032
- await jail.set("$__utils_rune_spawn_write", new ivm2.Reference((id, text) => {
74034
+ setGlobal("$__utils_rune_spawn_write", new ivm2.Reference((id, text) => {
74033
74035
  const handle = shellHandles.get(id);
74034
74036
  if (handle) handle.write(text);
74035
74037
  }));
74036
- await jail.set("$__utils_rune_spawn_write_command", new ivm2.Reference((id, nameOrText, args) => {
74038
+ setGlobal("$__utils_rune_spawn_write_command", new ivm2.Reference((id, nameOrText, args) => {
74037
74039
  const handle = shellHandles.get(id);
74038
74040
  if (handle) handle.writeCommand(nameOrText, args ?? void 0);
74039
74041
  }));
74040
- await jail.set("$__utils_rune_spawn_write_eof", new ivm2.Reference((id) => {
74042
+ setGlobal("$__utils_rune_spawn_write_eof", new ivm2.Reference((id) => {
74041
74043
  const handle = shellHandles.get(id);
74042
74044
  if (handle) handle.writeEof();
74043
74045
  }));
74044
- await jail.set("$__utils_rune_spawn_write_interrupt", new ivm2.Reference((id) => {
74046
+ setGlobal("$__utils_rune_spawn_write_interrupt", new ivm2.Reference((id) => {
74045
74047
  const handle = shellHandles.get(id);
74046
74048
  if (handle) handle.writeInterrupt();
74047
74049
  }));
74048
- await jail.set("$__utils_rune_spawn_stdin_write", new ivm2.Reference((id, chunk) => {
74050
+ setGlobal("$__utils_rune_spawn_stdin_write", new ivm2.Reference((id, chunk) => {
74049
74051
  const handle = shellHandles.get(id);
74050
74052
  if (handle) handle.stdin.write(chunk);
74051
74053
  }));
74052
- await jail.set("$__utils_rune_job_start", asyncRef(async (runeKey, args, opts) => {
74054
+ setGlobal("$__utils_rune_job_start", asyncRef(async (runeKey, args, opts) => {
74053
74055
  const repl = opts?.repl ?? false;
74054
74056
  checkPermission(repl ? "rune.repl" : "rune.job.start", runeKey);
74055
74057
  const cliPath = process.argv[1];
@@ -74069,7 +74071,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74069
74071
  await updateJobPid(projectDir, id, pid);
74070
74072
  return { id };
74071
74073
  }));
74072
- await jail.set("$__utils_rune_job_kill", asyncRef(async (id, signal) => {
74074
+ setGlobal("$__utils_rune_job_kill", asyncRef(async (id, signal) => {
74073
74075
  const sig = signal ?? "SIGTERM";
74074
74076
  if (!VALID_SIGNALS.has(sig)) throw new Error(`Invalid signal: ${sig}`);
74075
74077
  checkPermission("rune.job.kill", null);
@@ -74080,7 +74082,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74080
74082
  } catch {
74081
74083
  }
74082
74084
  }));
74083
- await jail.set("$__utils_rune_job_exists", asyncRef(async (id) => {
74085
+ setGlobal("$__utils_rune_job_exists", asyncRef(async (id) => {
74084
74086
  checkPermission("rune.job.exists", null);
74085
74087
  const record = await getJob(projectDir, id);
74086
74088
  if (!record) return false;
@@ -74091,7 +74093,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74091
74093
  return false;
74092
74094
  }
74093
74095
  }));
74094
- await jail.set("$__utils_rune_job_stdout", asyncRef(async (id) => {
74096
+ setGlobal("$__utils_rune_job_stdout", asyncRef(async (id) => {
74095
74097
  checkPermission("rune.job.read", null);
74096
74098
  const record = await getJob(projectDir, id);
74097
74099
  if (!record) throw new Error(`Unknown job: ${id}`);
@@ -74099,7 +74101,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74099
74101
  if (!fsSync.existsSync(logPath)) return "";
74100
74102
  return fsSync.promises.readFile(logPath, "utf8");
74101
74103
  }));
74102
- await jail.set("$__utils_rune_job_stderr", asyncRef(async (id) => {
74104
+ setGlobal("$__utils_rune_job_stderr", asyncRef(async (id) => {
74103
74105
  checkPermission("rune.job.read", null);
74104
74106
  const record = await getJob(projectDir, id);
74105
74107
  if (!record) throw new Error(`Unknown job: ${id}`);
@@ -74107,7 +74109,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74107
74109
  if (!fsSync.existsSync(logPath)) return "";
74108
74110
  return fsSync.promises.readFile(logPath, "utf8");
74109
74111
  }));
74110
- await jail.set("$__utils_rune_job_sections", asyncRef(async (id) => {
74112
+ setGlobal("$__utils_rune_job_sections", asyncRef(async (id) => {
74111
74113
  checkPermission("rune.job.read", null);
74112
74114
  const record = await getJob(projectDir, id);
74113
74115
  if (!record) throw new Error(`Unknown job: ${id}`);
@@ -74125,14 +74127,14 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74125
74127
  }
74126
74128
  return sections2;
74127
74129
  }));
74128
- await jail.set("$__utils_rune_job_write", asyncRef(async (id, text) => {
74130
+ setGlobal("$__utils_rune_job_write", asyncRef(async (id, text) => {
74129
74131
  checkPermission("rune.job.write", null);
74130
74132
  const record = await getJob(projectDir, id);
74131
74133
  if (!record) throw new Error(`Unknown job: ${id}`);
74132
74134
  const logPath = jobStdinPath(projectDir, id);
74133
74135
  await fsSync.promises.appendFile(logPath, JSON.stringify({ type: "line", text }) + "\n", "utf8");
74134
74136
  }));
74135
- await jail.set("$__utils_rune_job_write_command", asyncRef(async (id, nameOrText, args) => {
74137
+ setGlobal("$__utils_rune_job_write_command", asyncRef(async (id, nameOrText, args) => {
74136
74138
  checkPermission("rune.job.write", null);
74137
74139
  const record = await getJob(projectDir, id);
74138
74140
  if (!record) throw new Error(`Unknown job: ${id}`);
@@ -74150,20 +74152,20 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74150
74152
  }
74151
74153
  await fsSync.promises.appendFile(logPath, JSON.stringify(payload) + "\n", "utf8");
74152
74154
  }));
74153
- await jail.set("$__utils_rune_job_write_eof", asyncRef(async (id) => {
74155
+ setGlobal("$__utils_rune_job_write_eof", asyncRef(async (id) => {
74154
74156
  checkPermission("rune.job.write", null);
74155
74157
  const record = await getJob(projectDir, id);
74156
74158
  if (!record) throw new Error(`Unknown job: ${id}`);
74157
74159
  const logPath = jobStdinPath(projectDir, id);
74158
74160
  await fsSync.promises.appendFile(logPath, JSON.stringify({ type: "eof", text: "" }) + "\n", "utf8");
74159
74161
  }));
74160
- await jail.set("$__utils_time_after", new ivm2.Reference((ms) => {
74162
+ setGlobal("$__utils_time_after", new ivm2.Reference((ms) => {
74161
74163
  return new Promise((resolve6) => setTimeout(resolve6, ms).unref());
74162
74164
  }));
74163
- await jail.set("$__utils_time_after_ref", new ivm2.Reference((ms) => {
74165
+ setGlobal("$__utils_time_after_ref", new ivm2.Reference((ms) => {
74164
74166
  return new Promise((resolve6) => setTimeout(resolve6, ms));
74165
74167
  }));
74166
- await jail.set("$__utils_notify_send", new ivm2.Reference(async (title, message, opts) => {
74168
+ setGlobal("$__utils_notify_send", new ivm2.Reference(async (title, message, opts) => {
74167
74169
  return utils2.notify.send(title, message, opts);
74168
74170
  }));
74169
74171
  const cryptoKeyHandles = /* @__PURE__ */ new Map();
@@ -74180,171 +74182,171 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74180
74182
  if (!key) throw new Error(`Unknown CryptoKey handle: ${handle.__cryptoKeyHandle}`);
74181
74183
  return key;
74182
74184
  }
74183
- await jail.set("$__webcrypto_random_uuid", new ivm2.Reference(() => globalThis.crypto.randomUUID()));
74184
- await jail.set("$__webcrypto_get_random_values", new ivm2.Reference((arrayBuffer) => {
74185
+ setGlobal("$__webcrypto_random_uuid", new ivm2.Reference(() => globalThis.crypto.randomUUID()));
74186
+ setGlobal("$__webcrypto_get_random_values", new ivm2.Reference((arrayBuffer) => {
74185
74187
  const arr = new Uint8Array(arrayBuffer);
74186
74188
  globalThis.crypto.getRandomValues(arr);
74187
74189
  return arr.buffer;
74188
74190
  }));
74189
- await jail.set("$__webcrypto_subtle_digest", new ivm2.Reference(async (algorithm, data) => {
74191
+ setGlobal("$__webcrypto_subtle_digest", new ivm2.Reference(async (algorithm, data) => {
74190
74192
  return subtle.digest(algorithm, data);
74191
74193
  }));
74192
- await jail.set("$__webcrypto_subtle_sign", new ivm2.Reference(async (algorithm, keyHandle, data) => {
74194
+ setGlobal("$__webcrypto_subtle_sign", new ivm2.Reference(async (algorithm, keyHandle, data) => {
74193
74195
  const key = resolveKey(keyHandle);
74194
74196
  return subtle.sign(algorithm, key, data);
74195
74197
  }));
74196
- await jail.set("$__webcrypto_subtle_verify", new ivm2.Reference(async (algorithm, keyHandle, signature, data) => {
74198
+ setGlobal("$__webcrypto_subtle_verify", new ivm2.Reference(async (algorithm, keyHandle, signature, data) => {
74197
74199
  const key = resolveKey(keyHandle);
74198
74200
  return subtle.verify(algorithm, key, signature, data);
74199
74201
  }));
74200
- await jail.set("$__webcrypto_subtle_encrypt", new ivm2.Reference(async (algorithm, keyHandle, data) => {
74202
+ setGlobal("$__webcrypto_subtle_encrypt", new ivm2.Reference(async (algorithm, keyHandle, data) => {
74201
74203
  const key = resolveKey(keyHandle);
74202
74204
  return subtle.encrypt(algorithm, key, data);
74203
74205
  }));
74204
- await jail.set("$__webcrypto_subtle_decrypt", new ivm2.Reference(async (algorithm, keyHandle, data) => {
74206
+ setGlobal("$__webcrypto_subtle_decrypt", new ivm2.Reference(async (algorithm, keyHandle, data) => {
74205
74207
  const key = resolveKey(keyHandle);
74206
74208
  return subtle.decrypt(algorithm, key, data);
74207
74209
  }));
74208
- await jail.set("$__webcrypto_subtle_generate_key", new ivm2.Reference(async (algorithm, extractable, usages) => {
74210
+ setGlobal("$__webcrypto_subtle_generate_key", new ivm2.Reference(async (algorithm, extractable, usages) => {
74209
74211
  const result = await subtle.generateKey(algorithm, extractable, usages);
74210
74212
  if (result.privateKey) {
74211
74213
  return { privateKey: storeCryptoKey(result.privateKey), publicKey: storeCryptoKey(result.publicKey) };
74212
74214
  }
74213
74215
  return storeCryptoKey(result);
74214
74216
  }));
74215
- await jail.set("$__webcrypto_subtle_import_key", new ivm2.Reference(async (format2, keyData, algorithm, extractable, usages) => {
74217
+ setGlobal("$__webcrypto_subtle_import_key", new ivm2.Reference(async (format2, keyData, algorithm, extractable, usages) => {
74216
74218
  const key = await subtle.importKey(format2, keyData, algorithm, extractable, usages);
74217
74219
  return storeCryptoKey(key);
74218
74220
  }));
74219
- await jail.set("$__webcrypto_subtle_export_key", new ivm2.Reference(async (format2, keyHandle) => {
74221
+ setGlobal("$__webcrypto_subtle_export_key", new ivm2.Reference(async (format2, keyHandle) => {
74220
74222
  const key = resolveKey(keyHandle);
74221
74223
  return subtle.exportKey(format2, key);
74222
74224
  }));
74223
- await jail.set("$__webcrypto_subtle_derive_key", new ivm2.Reference(async (algorithm, baseKeyHandle, derivedKeyAlg, extractable, usages) => {
74225
+ setGlobal("$__webcrypto_subtle_derive_key", new ivm2.Reference(async (algorithm, baseKeyHandle, derivedKeyAlg, extractable, usages) => {
74224
74226
  const baseKey = resolveKey(baseKeyHandle);
74225
74227
  const key = await subtle.deriveKey(algorithm, baseKey, derivedKeyAlg, extractable, usages);
74226
74228
  return storeCryptoKey(key);
74227
74229
  }));
74228
- await jail.set("$__webcrypto_subtle_derive_bits", new ivm2.Reference(async (algorithm, baseKeyHandle, length) => {
74230
+ setGlobal("$__webcrypto_subtle_derive_bits", new ivm2.Reference(async (algorithm, baseKeyHandle, length) => {
74229
74231
  const baseKey = resolveKey(baseKeyHandle);
74230
74232
  return subtle.deriveBits(algorithm, baseKey, length);
74231
74233
  }));
74232
- await jail.set("$__webcrypto_subtle_wrap_key", new ivm2.Reference(async (format2, keyHandle, wrappingKeyHandle, wrapAlgorithm) => {
74234
+ setGlobal("$__webcrypto_subtle_wrap_key", new ivm2.Reference(async (format2, keyHandle, wrappingKeyHandle, wrapAlgorithm) => {
74233
74235
  const key = resolveKey(keyHandle);
74234
74236
  const wrappingKey = resolveKey(wrappingKeyHandle);
74235
74237
  return subtle.wrapKey(format2, key, wrappingKey, wrapAlgorithm);
74236
74238
  }));
74237
- await jail.set("$__webcrypto_subtle_unwrap_key", new ivm2.Reference(async (format2, wrappedData, unwrappingKeyHandle, unwrapAlg, unwrappedAlg, extractable, usages) => {
74239
+ setGlobal("$__webcrypto_subtle_unwrap_key", new ivm2.Reference(async (format2, wrappedData, unwrappingKeyHandle, unwrapAlg, unwrappedAlg, extractable, usages) => {
74238
74240
  const unwrappingKey = resolveKey(unwrappingKeyHandle);
74239
74241
  const key = await subtle.unwrapKey(format2, wrappedData, unwrappingKey, unwrapAlg, unwrappedAlg, extractable, usages);
74240
74242
  return storeCryptoKey(key);
74241
74243
  }));
74242
- await jail.set("$__utils_json_read", new ivm2.Reference(async (relPath, opts) => {
74244
+ setGlobal("$__utils_json_read", new ivm2.Reference(async (relPath, opts) => {
74243
74245
  return utils2.json.read(relPath, opts);
74244
74246
  }));
74245
- await jail.set("$__utils_json_readPath", new ivm2.Reference(async (relPath, jsonPath, fallback, opts) => {
74247
+ setGlobal("$__utils_json_readPath", new ivm2.Reference(async (relPath, jsonPath, fallback, opts) => {
74246
74248
  return utils2.json.readPath(relPath, jsonPath, fallback, opts);
74247
74249
  }));
74248
- await jail.set("$__utils_json_readPathAll", new ivm2.Reference(async (relPath, jsonPath, fallback, opts) => {
74250
+ setGlobal("$__utils_json_readPathAll", new ivm2.Reference(async (relPath, jsonPath, fallback, opts) => {
74249
74251
  return utils2.json.readPathAll(relPath, jsonPath, fallback, opts);
74250
74252
  }));
74251
- await jail.set("$__utils_json_write", new ivm2.Reference(async (relPath, data, opts) => {
74253
+ setGlobal("$__utils_json_write", new ivm2.Reference(async (relPath, data, opts) => {
74252
74254
  await utils2.json.write(relPath, data, opts);
74253
74255
  }));
74254
- await jail.set("$__utils_json_writePath", new ivm2.Reference(async (relPath, jsonPath, value, opts) => {
74256
+ setGlobal("$__utils_json_writePath", new ivm2.Reference(async (relPath, jsonPath, value, opts) => {
74255
74257
  await utils2.json.writePath(relPath, jsonPath, value, opts);
74256
74258
  }));
74257
- await jail.set("$__utils_json_parse", new ivm2.Reference((text, opts) => {
74259
+ setGlobal("$__utils_json_parse", new ivm2.Reference((text, opts) => {
74258
74260
  return utils2.json.parse(text, opts);
74259
74261
  }));
74260
- await jail.set("$__utils_json_stringify", new ivm2.Reference((data, opts) => {
74262
+ setGlobal("$__utils_json_stringify", new ivm2.Reference((data, opts) => {
74261
74263
  return utils2.json.stringify(data, opts);
74262
74264
  }));
74263
- await jail.set("$__utils_yaml_read", new ivm2.Reference(async (relPath, opts) => {
74265
+ setGlobal("$__utils_yaml_read", new ivm2.Reference(async (relPath, opts) => {
74264
74266
  return utils2.yaml.read(relPath, opts);
74265
74267
  }));
74266
- await jail.set("$__utils_yaml_write", new ivm2.Reference(async (relPath, data, opts) => {
74268
+ setGlobal("$__utils_yaml_write", new ivm2.Reference(async (relPath, data, opts) => {
74267
74269
  await utils2.yaml.write(relPath, data, opts);
74268
74270
  }));
74269
- await jail.set("$__utils_yaml_parse", new ivm2.Reference((text) => {
74271
+ setGlobal("$__utils_yaml_parse", new ivm2.Reference((text) => {
74270
74272
  return utils2.yaml.parse(text);
74271
74273
  }));
74272
- await jail.set("$__utils_yaml_stringify", new ivm2.Reference((data, opts) => {
74274
+ setGlobal("$__utils_yaml_stringify", new ivm2.Reference((data, opts) => {
74273
74275
  return utils2.yaml.stringify(data, opts);
74274
74276
  }));
74275
- await jail.set("$__utils_yaml_readPath", new ivm2.Reference(async (relPath, jsonPath, fallback) => {
74277
+ setGlobal("$__utils_yaml_readPath", new ivm2.Reference(async (relPath, jsonPath, fallback) => {
74276
74278
  return utils2.yaml.readPath(relPath, jsonPath, fallback);
74277
74279
  }));
74278
- await jail.set("$__utils_yaml_readPathAll", new ivm2.Reference(async (relPath, jsonPath, fallback) => {
74280
+ setGlobal("$__utils_yaml_readPathAll", new ivm2.Reference(async (relPath, jsonPath, fallback) => {
74279
74281
  return utils2.yaml.readPathAll(relPath, jsonPath, fallback);
74280
74282
  }));
74281
- await jail.set("$__utils_yaml_writePath", new ivm2.Reference(async (relPath, jsonPath, value, opts) => {
74283
+ setGlobal("$__utils_yaml_writePath", new ivm2.Reference(async (relPath, jsonPath, value, opts) => {
74282
74284
  await utils2.yaml.writePath(relPath, jsonPath, value, opts);
74283
74285
  }));
74284
- await jail.set("$__utils_xml_read", new ivm2.Reference(async (relPath, opts) => {
74286
+ setGlobal("$__utils_xml_read", new ivm2.Reference(async (relPath, opts) => {
74285
74287
  return utils2.xml.read(relPath, opts);
74286
74288
  }));
74287
- await jail.set("$__utils_xml_write", new ivm2.Reference(async (relPath, data, opts) => {
74289
+ setGlobal("$__utils_xml_write", new ivm2.Reference(async (relPath, data, opts) => {
74288
74290
  await utils2.xml.write(relPath, data, opts);
74289
74291
  }));
74290
- await jail.set("$__utils_xml_parse", new ivm2.Reference((text) => {
74292
+ setGlobal("$__utils_xml_parse", new ivm2.Reference((text) => {
74291
74293
  return utils2.xml.parse(text);
74292
74294
  }));
74293
- await jail.set("$__utils_xml_stringify", new ivm2.Reference((data, opts) => {
74295
+ setGlobal("$__utils_xml_stringify", new ivm2.Reference((data, opts) => {
74294
74296
  return utils2.xml.stringify(data, opts);
74295
74297
  }));
74296
- await jail.set("$__utils_xml_readPath", new ivm2.Reference(async (relPath, jsonPath, fallback) => {
74298
+ setGlobal("$__utils_xml_readPath", new ivm2.Reference(async (relPath, jsonPath, fallback) => {
74297
74299
  return utils2.xml.readPath(relPath, jsonPath, fallback);
74298
74300
  }));
74299
- await jail.set("$__utils_xml_readPathAll", new ivm2.Reference(async (relPath, jsonPath, fallback) => {
74301
+ setGlobal("$__utils_xml_readPathAll", new ivm2.Reference(async (relPath, jsonPath, fallback) => {
74300
74302
  return utils2.xml.readPathAll(relPath, jsonPath, fallback);
74301
74303
  }));
74302
- await jail.set("$__utils_xml_writePath", new ivm2.Reference(async (relPath, jsonPath, value, opts) => {
74304
+ setGlobal("$__utils_xml_writePath", new ivm2.Reference(async (relPath, jsonPath, value, opts) => {
74303
74305
  await utils2.xml.writePath(relPath, jsonPath, value, opts);
74304
74306
  }));
74305
- await jail.set("$__utils_csv_read", new ivm2.Reference(async (relPath, opts) => {
74307
+ setGlobal("$__utils_csv_read", new ivm2.Reference(async (relPath, opts) => {
74306
74308
  return utils2.csv.read(relPath, opts);
74307
74309
  }));
74308
- await jail.set("$__utils_csv_read_objects", new ivm2.Reference(async (relPath, opts) => {
74310
+ setGlobal("$__utils_csv_read_objects", new ivm2.Reference(async (relPath, opts) => {
74309
74311
  return utils2.csv.readObjects(relPath, opts);
74310
74312
  }));
74311
- await jail.set("$__utils_csv_write", new ivm2.Reference(async (relPath, rows, opts) => {
74313
+ setGlobal("$__utils_csv_write", new ivm2.Reference(async (relPath, rows, opts) => {
74312
74314
  await utils2.csv.write(relPath, rows, opts);
74313
74315
  }));
74314
- await jail.set("$__utils_csv_write_objects", new ivm2.Reference(async (relPath, data, opts) => {
74316
+ setGlobal("$__utils_csv_write_objects", new ivm2.Reference(async (relPath, data, opts) => {
74315
74317
  await utils2.csv.writeObjects(relPath, data, opts);
74316
74318
  }));
74317
- await jail.set("$__utils_csv_headers", new ivm2.Reference(async (relPath, opts) => {
74319
+ setGlobal("$__utils_csv_headers", new ivm2.Reference(async (relPath, opts) => {
74318
74320
  return utils2.csv.headers(relPath, opts);
74319
74321
  }));
74320
- await jail.set("$__utils_csv_count", new ivm2.Reference(async (relPath, opts) => {
74322
+ setGlobal("$__utils_csv_count", new ivm2.Reference(async (relPath, opts) => {
74321
74323
  return utils2.csv.count(relPath, opts);
74322
74324
  }));
74323
- await jail.set("$__utils_csv_append", new ivm2.Reference(async (relPath, rows, opts) => {
74325
+ setGlobal("$__utils_csv_append", new ivm2.Reference(async (relPath, rows, opts) => {
74324
74326
  await utils2.csv.append(relPath, rows, opts);
74325
74327
  }));
74326
- await jail.set("$__utils_csv_append_objects", new ivm2.Reference(async (relPath, data, opts) => {
74328
+ setGlobal("$__utils_csv_append_objects", new ivm2.Reference(async (relPath, data, opts) => {
74327
74329
  await utils2.csv.appendObjects(relPath, data, opts);
74328
74330
  }));
74329
- await jail.set("$__utils_csv_parse", new ivm2.Reference((content, opts) => {
74331
+ setGlobal("$__utils_csv_parse", new ivm2.Reference((content, opts) => {
74330
74332
  return utils2.csv.parse(content, opts);
74331
74333
  }));
74332
- await jail.set("$__utils_csv_parse_objects", new ivm2.Reference((content, opts) => {
74334
+ setGlobal("$__utils_csv_parse_objects", new ivm2.Reference((content, opts) => {
74333
74335
  return utils2.csv.parseObjects(content, opts);
74334
74336
  }));
74335
- await jail.set("$__utils_csv_stringify", new ivm2.Reference((rows, opts) => {
74337
+ setGlobal("$__utils_csv_stringify", new ivm2.Reference((rows, opts) => {
74336
74338
  return utils2.csv.stringify(rows, opts);
74337
74339
  }));
74338
- await jail.set("$__utils_csv_stringify_objects", new ivm2.Reference((data, opts) => {
74340
+ setGlobal("$__utils_csv_stringify_objects", new ivm2.Reference((data, opts) => {
74339
74341
  return utils2.csv.stringifyObjects(data, opts);
74340
74342
  }));
74341
- await jail.set("$__utils_csv_readStream", new ivm2.Reference(async (relPath, opts) => {
74343
+ setGlobal("$__utils_csv_readStream", new ivm2.Reference(async (relPath, opts) => {
74342
74344
  const iter = utils2.csv.readStreamIter(relPath, opts)[Symbol.asyncIterator]();
74343
74345
  const id = nextStreamId++;
74344
74346
  streams.set(id, iter);
74345
74347
  return id;
74346
74348
  }));
74347
- await jail.set("$__utils_csv_readStream_next", new ivm2.Reference(async (id) => {
74349
+ setGlobal("$__utils_csv_readStream_next", new ivm2.Reference(async (id) => {
74348
74350
  const iter = streams.get(id);
74349
74351
  if (!iter) throw new Error(`Invalid csv read stream ID: ${id}`);
74350
74352
  const { value, done } = await iter.next();
@@ -74354,20 +74356,20 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74354
74356
  }
74355
74357
  return value;
74356
74358
  }));
74357
- await jail.set("$__utils_csv_readObjectsStream", new ivm2.Reference(async (relPath, opts) => {
74359
+ setGlobal("$__utils_csv_readObjectsStream", new ivm2.Reference(async (relPath, opts) => {
74358
74360
  const { columns, aliases, rows } = utils2.csv.readObjectsStreamIter(relPath, opts);
74359
74361
  const id = nextStreamId++;
74360
74362
  const iter = rows[Symbol.asyncIterator]();
74361
74363
  streams.set(id, { iter, columns, aliases });
74362
74364
  return id;
74363
74365
  }));
74364
- await jail.set("$__utils_csv_readObjectsStream_meta", new ivm2.Reference(async (id) => {
74366
+ setGlobal("$__utils_csv_readObjectsStream_meta", new ivm2.Reference(async (id) => {
74365
74367
  const entry = streams.get(id);
74366
74368
  if (!entry) throw new Error(`Invalid csv read objects stream ID: ${id}`);
74367
74369
  const [columns, aliases] = await Promise.all([entry.columns, entry.aliases]);
74368
74370
  return { columns, aliases };
74369
74371
  }));
74370
- await jail.set("$__utils_csv_readObjectsStream_next", new ivm2.Reference(async (id) => {
74372
+ setGlobal("$__utils_csv_readObjectsStream_next", new ivm2.Reference(async (id) => {
74371
74373
  const entry = streams.get(id);
74372
74374
  if (!entry) throw new Error(`Invalid csv read objects stream ID: ${id}`);
74373
74375
  const { value, done } = await entry.iter.next();
@@ -74377,41 +74379,41 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74377
74379
  }
74378
74380
  return value;
74379
74381
  }));
74380
- await jail.set("$__utils_csv_writeStream", new ivm2.Reference(async (relPath, opts) => {
74382
+ setGlobal("$__utils_csv_writeStream", new ivm2.Reference(async (relPath, opts) => {
74381
74383
  const ref = utils2.csv.writeStreamRef(relPath, opts);
74382
74384
  const id = nextStreamId++;
74383
74385
  streams.set(id, ref);
74384
74386
  return id;
74385
74387
  }));
74386
- await jail.set("$__utils_csv_writeStream_write", new ivm2.Reference(async (id, row) => {
74388
+ setGlobal("$__utils_csv_writeStream_write", new ivm2.Reference(async (id, row) => {
74387
74389
  const ref = streams.get(id);
74388
74390
  if (!ref) throw new Error(`Invalid csv write stream ID: ${id}`);
74389
74391
  await ref.write(row);
74390
74392
  }));
74391
- await jail.set("$__utils_csv_writeStream_close", new ivm2.Reference(async (id) => {
74393
+ setGlobal("$__utils_csv_writeStream_close", new ivm2.Reference(async (id) => {
74392
74394
  const ref = streams.get(id);
74393
74395
  if (!ref) throw new Error(`Invalid csv write stream ID: ${id}`);
74394
74396
  await ref.close();
74395
74397
  streams.delete(id);
74396
74398
  }));
74397
- await jail.set("$__utils_csv_writeObjectsStream", new ivm2.Reference(async (relPath, opts) => {
74399
+ setGlobal("$__utils_csv_writeObjectsStream", new ivm2.Reference(async (relPath, opts) => {
74398
74400
  const ref = utils2.csv.writeObjectsStreamRef(relPath, opts);
74399
74401
  const id = nextStreamId++;
74400
74402
  streams.set(id, ref);
74401
74403
  return id;
74402
74404
  }));
74403
- await jail.set("$__utils_csv_writeObjectsStream_write", new ivm2.Reference(async (id, record) => {
74405
+ setGlobal("$__utils_csv_writeObjectsStream_write", new ivm2.Reference(async (id, record) => {
74404
74406
  const ref = streams.get(id);
74405
74407
  if (!ref) throw new Error(`Invalid csv write objects stream ID: ${id}`);
74406
74408
  await ref.write(record);
74407
74409
  }));
74408
- await jail.set("$__utils_csv_writeObjectsStream_close", new ivm2.Reference(async (id) => {
74410
+ setGlobal("$__utils_csv_writeObjectsStream_close", new ivm2.Reference(async (id) => {
74409
74411
  const ref = streams.get(id);
74410
74412
  if (!ref) throw new Error(`Invalid csv write objects stream ID: ${id}`);
74411
74413
  await ref.close();
74412
74414
  streams.delete(id);
74413
74415
  }));
74414
- await jail.set("$__utils_http_fetch", new ivm2.Reference(async (urlRef, optsRef, onChunk, onEnd, onError, signalListenerRef) => {
74416
+ setGlobal("$__utils_http_fetch", new ivm2.Reference(async (urlRef, optsRef, onChunk, onEnd, onError, signalListenerRef) => {
74415
74417
  const url = urlRef.copySync();
74416
74418
  const opts = optsRef.copySync();
74417
74419
  let body = opts?.body;
@@ -74458,7 +74460,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74458
74460
  await onError.apply(void 0, [err.message], { arguments: { copy: true }, result: { promise: true } });
74459
74461
  }
74460
74462
  }));
74461
- await jail.set("$__utils_http_body_reader", new ivm2.Reference(async (urlRef, optsRef, pullChunk, onChunk, onEnd, onError) => {
74463
+ setGlobal("$__utils_http_body_reader", new ivm2.Reference(async (urlRef, optsRef, pullChunk, onChunk, onEnd, onError) => {
74462
74464
  const url = typeof urlRef === "object" && urlRef.copySync ? urlRef.copySync() : urlRef;
74463
74465
  const opts = typeof optsRef === "object" && optsRef.copySync ? optsRef.copySync() : optsRef;
74464
74466
  const { Readable: Readable3 } = await import("node:stream");
@@ -74497,68 +74499,68 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74497
74499
  await onError.apply(void 0, [err.message], { arguments: { copy: true }, result: { promise: true } });
74498
74500
  }
74499
74501
  }));
74500
- await jail.set("$__utils_env_read", new ivm2.Reference(async (key, fallback) => {
74502
+ setGlobal("$__utils_env_read", new ivm2.Reference(async (key, fallback) => {
74501
74503
  const result = utils2.env.read(key, fallback);
74502
74504
  return result !== void 0 ? result : null;
74503
74505
  }));
74504
- await jail.set("$__utils_env_has", new ivm2.Reference(async (key) => {
74506
+ setGlobal("$__utils_env_has", new ivm2.Reference(async (key) => {
74505
74507
  return utils2.env.has(key);
74506
74508
  }));
74507
- await jail.set("$__utils_archive_unzip", new ivm2.Reference(async (source, dest) => {
74509
+ setGlobal("$__utils_archive_unzip", new ivm2.Reference(async (source, dest) => {
74508
74510
  await utils2.archive.unzip(source, dest);
74509
74511
  }));
74510
- await jail.set("$__utils_archive_zip", new ivm2.Reference(async (source, dest) => {
74512
+ setGlobal("$__utils_archive_zip", new ivm2.Reference(async (source, dest) => {
74511
74513
  await utils2.archive.zip(source, dest);
74512
74514
  }));
74513
- await jail.set("$__utils_archive_untar", new ivm2.Reference(async (source, dest, opts) => {
74515
+ setGlobal("$__utils_archive_untar", new ivm2.Reference(async (source, dest, opts) => {
74514
74516
  await utils2.archive.untar(source, dest, opts);
74515
74517
  }));
74516
- await jail.set("$__utils_archive_tar", new ivm2.Reference(async (source, dest, opts) => {
74518
+ setGlobal("$__utils_archive_tar", new ivm2.Reference(async (source, dest, opts) => {
74517
74519
  await utils2.archive.tar(source, dest, opts);
74518
74520
  }));
74519
74521
  const cacheHandles = /* @__PURE__ */ new Map();
74520
74522
  let nextCacheHandle = 0;
74521
- await jail.set("$__utils_cache_open", new ivm2.Reference(async (location, name) => {
74523
+ setGlobal("$__utils_cache_open", new ivm2.Reference(async (location, name) => {
74522
74524
  const handle = await utils2.cache.openHandle(location, name ?? "default");
74523
74525
  const id = String(nextCacheHandle++);
74524
74526
  cacheHandles.set(id, handle);
74525
74527
  return id;
74526
74528
  }));
74527
- await jail.set("$__utils_cache_set", new ivm2.Reference(async (id, key, value, ttl) => {
74529
+ setGlobal("$__utils_cache_set", new ivm2.Reference(async (id, key, value, ttl) => {
74528
74530
  const handle = cacheHandles.get(id);
74529
74531
  if (!handle) throw new Error(`Invalid cache handle: ${id}`);
74530
74532
  await handle.set(key, value, ttl !== null ? Number(ttl) : null);
74531
74533
  }));
74532
- await jail.set("$__utils_cache_get", new ivm2.Reference(async (id, key) => {
74534
+ setGlobal("$__utils_cache_get", new ivm2.Reference(async (id, key) => {
74533
74535
  const handle = cacheHandles.get(id);
74534
74536
  if (!handle) throw new Error(`Invalid cache handle: ${id}`);
74535
74537
  const value = await handle.get(key);
74536
74538
  return value !== null ? value : null;
74537
74539
  }));
74538
- await jail.set("$__utils_cache_delete", new ivm2.Reference(async (id, key) => {
74540
+ setGlobal("$__utils_cache_delete", new ivm2.Reference(async (id, key) => {
74539
74541
  const handle = cacheHandles.get(id);
74540
74542
  if (!handle) throw new Error(`Invalid cache handle: ${id}`);
74541
74543
  await handle.delete(key);
74542
74544
  }));
74543
- await jail.set("$__utils_cache_clear", new ivm2.Reference(async (id) => {
74545
+ setGlobal("$__utils_cache_clear", new ivm2.Reference(async (id) => {
74544
74546
  const handle = cacheHandles.get(id);
74545
74547
  if (!handle) throw new Error(`Invalid cache handle: ${id}`);
74546
74548
  await handle.clear();
74547
74549
  }));
74548
- await jail.set("$__utils_cache_has", new ivm2.Reference(async (id, key) => {
74550
+ setGlobal("$__utils_cache_has", new ivm2.Reference(async (id, key) => {
74549
74551
  const handle = cacheHandles.get(id);
74550
74552
  if (!handle) throw new Error(`Invalid cache handle: ${id}`);
74551
74553
  return handle.has(key);
74552
74554
  }));
74553
74555
  const sqliteHandles = /* @__PURE__ */ new Map();
74554
74556
  let nextSqliteHandle = 0;
74555
- await jail.set("$__utils_sqlite_open", asyncRef(async (location, name) => {
74557
+ setGlobal("$__utils_sqlite_open", asyncRef(async (location, name) => {
74556
74558
  const handle = await utils2.sqlite.openHandle(location, name ?? "default");
74557
74559
  const id = String(nextSqliteHandle++);
74558
74560
  sqliteHandles.set(id, handle);
74559
74561
  return id;
74560
74562
  }));
74561
- await jail.set("$__utils_sqlite_query", new ivm2.Reference(async (id, sql, params) => {
74563
+ setGlobal("$__utils_sqlite_query", new ivm2.Reference(async (id, sql, params) => {
74562
74564
  const handle = sqliteHandles.get(id);
74563
74565
  if (!handle) throw new Error(`Invalid sqlite handle: ${id}`);
74564
74566
  try {
@@ -74567,7 +74569,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74567
74569
  return Promise.reject(e);
74568
74570
  }
74569
74571
  }));
74570
- await jail.set("$__utils_sqlite_get", new ivm2.Reference(async (id, sql, params) => {
74572
+ setGlobal("$__utils_sqlite_get", new ivm2.Reference(async (id, sql, params) => {
74571
74573
  const handle = sqliteHandles.get(id);
74572
74574
  if (!handle) throw new Error(`Invalid sqlite handle: ${id}`);
74573
74575
  try {
@@ -74577,7 +74579,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74577
74579
  return Promise.reject(e);
74578
74580
  }
74579
74581
  }));
74580
- await jail.set("$__utils_sqlite_exec", new ivm2.Reference(async (id, sql, params) => {
74582
+ setGlobal("$__utils_sqlite_exec", new ivm2.Reference(async (id, sql, params) => {
74581
74583
  const handle = sqliteHandles.get(id);
74582
74584
  if (!handle) throw new Error(`Invalid sqlite handle: ${id}`);
74583
74585
  try {
@@ -74586,7 +74588,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74586
74588
  return Promise.reject(e);
74587
74589
  }
74588
74590
  }));
74589
- await jail.set("$__utils_sqlite_run", new ivm2.Reference(async (id, sql) => {
74591
+ setGlobal("$__utils_sqlite_run", new ivm2.Reference(async (id, sql) => {
74590
74592
  const handle = sqliteHandles.get(id);
74591
74593
  if (!handle) throw new Error(`Invalid sqlite handle: ${id}`);
74592
74594
  try {
@@ -74595,56 +74597,56 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74595
74597
  return Promise.reject(e);
74596
74598
  }
74597
74599
  }));
74598
- await jail.set("$__utils_sqlite_close", new ivm2.Reference(async (id) => {
74600
+ setGlobal("$__utils_sqlite_close", new ivm2.Reference(async (id) => {
74599
74601
  const handle = sqliteHandles.get(id);
74600
74602
  if (!handle) return;
74601
74603
  handle.close();
74602
74604
  sqliteHandles.delete(id);
74603
74605
  }));
74604
- await jail.set("$__utils_ws_client", new ivm2.Reference((url, options) => {
74606
+ setGlobal("$__utils_ws_client", new ivm2.Reference((url, options) => {
74605
74607
  return utils2.ws.client(url, options);
74606
74608
  }));
74607
- await jail.set("$__utils_ws_on", new ivm2.Reference((sessionIdRef, eventRef, callbackRef) => {
74609
+ setGlobal("$__utils_ws_on", new ivm2.Reference((sessionIdRef, eventRef, callbackRef) => {
74608
74610
  const sessionId = sessionIdRef.copySync();
74609
74611
  const event = eventRef.copySync();
74610
74612
  utils2.ws._getSession(sessionId).setHandler(event, callbackRef);
74611
74613
  }));
74612
- await jail.set("$__utils_ws_open", new ivm2.Reference(async (sessionId) => {
74614
+ setGlobal("$__utils_ws_open", new ivm2.Reference(async (sessionId) => {
74613
74615
  await utils2.ws._getSession(sessionId).open();
74614
74616
  }));
74615
- await jail.set("$__utils_ws_send_text", new ivm2.Reference(async (sessionId, message) => {
74617
+ setGlobal("$__utils_ws_send_text", new ivm2.Reference(async (sessionId, message) => {
74616
74618
  await utils2.ws._getSession(sessionId).sendText(message);
74617
74619
  }));
74618
- await jail.set("$__utils_ws_send_binary", new ivm2.Reference(async (sessionId, arrayBuffer, byteOffset, byteLength) => {
74620
+ setGlobal("$__utils_ws_send_binary", new ivm2.Reference(async (sessionId, arrayBuffer, byteOffset, byteLength) => {
74619
74621
  await utils2.ws._getSession(sessionId).sendBinary(arrayBuffer, byteOffset, byteLength);
74620
74622
  }));
74621
- await jail.set("$__utils_ws_close", new ivm2.Reference(async (sessionId) => {
74623
+ setGlobal("$__utils_ws_close", new ivm2.Reference(async (sessionId) => {
74622
74624
  return utils2.ws._getSession(sessionId).close();
74623
74625
  }));
74624
- await jail.set("$__utils_ws_closed", new ivm2.Reference(async (sessionId) => {
74626
+ setGlobal("$__utils_ws_closed", new ivm2.Reference(async (sessionId) => {
74625
74627
  return utils2.ws._getSession(sessionId).closedPromise;
74626
74628
  }));
74627
- await jail.set("$__utils_http_server_create", new ivm2.Reference((port, opts) => {
74629
+ setGlobal("$__utils_http_server_create", new ivm2.Reference((port, opts) => {
74628
74630
  return utils2.http.server(port, opts);
74629
74631
  }));
74630
- await jail.set("$__utils_http_server_set_handler", new ivm2.Reference(async (idRef, handlerRef) => {
74632
+ setGlobal("$__utils_http_server_set_handler", new ivm2.Reference(async (idRef, handlerRef) => {
74631
74633
  const id = typeof idRef === "object" && idRef !== null && typeof idRef.copySync === "function" ? idRef.copySync() : idRef;
74632
74634
  utils2.http._getServerSession(id).setHandler(handlerRef);
74633
74635
  }));
74634
- await jail.set("$__utils_http_server_open", new ivm2.Reference(async (idRef) => {
74636
+ setGlobal("$__utils_http_server_open", new ivm2.Reference(async (idRef) => {
74635
74637
  const id = typeof idRef === "object" && idRef !== null && typeof idRef.copySync === "function" ? idRef.copySync() : idRef;
74636
74638
  await utils2.http._getServerSession(id).open();
74637
74639
  return utils2.http._getServerSession(id).port;
74638
74640
  }));
74639
- await jail.set("$__utils_http_server_close", new ivm2.Reference(async (idRef) => {
74641
+ setGlobal("$__utils_http_server_close", new ivm2.Reference(async (idRef) => {
74640
74642
  const id = typeof idRef === "object" && idRef !== null && typeof idRef.copySync === "function" ? idRef.copySync() : idRef;
74641
74643
  await utils2.http._getServerSession(id).close();
74642
74644
  }));
74643
- await jail.set("$__utils_http_server_closed", new ivm2.Reference(async (idRef) => {
74645
+ setGlobal("$__utils_http_server_closed", new ivm2.Reference(async (idRef) => {
74644
74646
  const id = typeof idRef === "object" && idRef !== null && typeof idRef.copySync === "function" ? idRef.copySync() : idRef;
74645
74647
  await utils2.http._getServerSession(id).closed();
74646
74648
  }));
74647
- await jail.set("$__utils_http_server_request_closed", new ivm2.Reference(async (idRef, reqIdRef) => {
74649
+ setGlobal("$__utils_http_server_request_closed", new ivm2.Reference(async (idRef, reqIdRef) => {
74648
74650
  const id = typeof idRef === "object" && idRef !== null && typeof idRef.copySync === "function" ? idRef.copySync() : idRef;
74649
74651
  const reqId = typeof reqIdRef === "object" && reqIdRef !== null && typeof reqIdRef.copySync === "function" ? reqIdRef.copySync() : reqIdRef;
74650
74652
  const session = utils2.http._getServerSession(id);
@@ -74652,120 +74654,120 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74652
74654
  if (!abort) return;
74653
74655
  return new Promise((resolve6) => abort.signal.addEventListener("abort", resolve6));
74654
74656
  }));
74655
- await jail.set("$__utils_ws_server_create", new ivm2.Reference((portOrHttpId, opts, isHttpSession) => {
74657
+ setGlobal("$__utils_ws_server_create", new ivm2.Reference((portOrHttpId, opts, isHttpSession) => {
74656
74658
  const portOrSession = isHttpSession ? utils2.http._getServerSession(portOrHttpId) : portOrHttpId;
74657
74659
  return utils2.ws.server(portOrSession, opts);
74658
74660
  }));
74659
- await jail.set("$__utils_ws_server_set_connection_handler", new ivm2.Reference(async (idRef, handlerRef) => {
74661
+ setGlobal("$__utils_ws_server_set_connection_handler", new ivm2.Reference(async (idRef, handlerRef) => {
74660
74662
  const id = typeof idRef === "object" && idRef !== null && typeof idRef.copySync === "function" ? idRef.copySync() : idRef;
74661
74663
  utils2.ws._getWsServerSession(id).setConnectionHandler(handlerRef);
74662
74664
  }));
74663
- await jail.set("$__utils_ws_server_set_error_handler", new ivm2.Reference(async (idRef, handlerRef) => {
74665
+ setGlobal("$__utils_ws_server_set_error_handler", new ivm2.Reference(async (idRef, handlerRef) => {
74664
74666
  const id = typeof idRef === "object" && idRef !== null && typeof idRef.copySync === "function" ? idRef.copySync() : idRef;
74665
74667
  utils2.ws._getWsServerSession(id).setErrorHandler(handlerRef);
74666
74668
  }));
74667
- await jail.set("$__utils_ws_server_open", new ivm2.Reference(async (id) => {
74669
+ setGlobal("$__utils_ws_server_open", new ivm2.Reference(async (id) => {
74668
74670
  await utils2.ws._getWsServerSession(id).open();
74669
74671
  return utils2.ws._getWsServerSession(id).port;
74670
74672
  }));
74671
- await jail.set("$__utils_ws_server_close", new ivm2.Reference(async (id) => {
74673
+ setGlobal("$__utils_ws_server_close", new ivm2.Reference(async (id) => {
74672
74674
  await utils2.ws._getWsServerSession(id).close();
74673
74675
  }));
74674
- await jail.set("$__utils_ws_server_closed", new ivm2.Reference(async (id) => {
74676
+ setGlobal("$__utils_ws_server_closed", new ivm2.Reference(async (id) => {
74675
74677
  await utils2.ws._getWsServerSession(id).closed();
74676
74678
  }));
74677
- await jail.set("$__utils_ws_server_conn_on", new ivm2.Reference(async (connIdRef, eventRef, handlerRef) => {
74679
+ setGlobal("$__utils_ws_server_conn_on", new ivm2.Reference(async (connIdRef, eventRef, handlerRef) => {
74678
74680
  const connId = typeof connIdRef === "object" && connIdRef !== null && typeof connIdRef.copySync === "function" ? connIdRef.copySync() : connIdRef;
74679
74681
  const event = typeof eventRef === "object" && eventRef !== null && typeof eventRef.copySync === "function" ? eventRef.copySync() : eventRef;
74680
74682
  utils2.ws._getWsServerConn(connId).setHandler(event, handlerRef);
74681
74683
  }));
74682
- await jail.set("$__utils_ws_server_conn_send_text", new ivm2.Reference(async (connId, msg) => {
74684
+ setGlobal("$__utils_ws_server_conn_send_text", new ivm2.Reference(async (connId, msg) => {
74683
74685
  await utils2.ws._getWsServerConn(connId).sendText(msg);
74684
74686
  }));
74685
- await jail.set("$__utils_ws_server_conn_send_binary", new ivm2.Reference(async (connId, ab, byteOffset, byteLength) => {
74687
+ setGlobal("$__utils_ws_server_conn_send_binary", new ivm2.Reference(async (connId, ab, byteOffset, byteLength) => {
74686
74688
  await utils2.ws._getWsServerConn(connId).sendBinary(ab, byteOffset, byteLength);
74687
74689
  }));
74688
- await jail.set("$__utils_ws_server_conn_close", new ivm2.Reference(async (connId, code2, reason) => {
74690
+ setGlobal("$__utils_ws_server_conn_close", new ivm2.Reference(async (connId, code2, reason) => {
74689
74691
  return utils2.ws._getWsServerConn(connId).close(code2, reason);
74690
74692
  }));
74691
- await jail.set("$__utils_ws_server_conn_closed", new ivm2.Reference(async (connId) => {
74693
+ setGlobal("$__utils_ws_server_conn_closed", new ivm2.Reference(async (connId) => {
74692
74694
  return utils2.ws._getWsServerConn(connId).closed();
74693
74695
  }));
74694
74696
  const dbHandles = /* @__PURE__ */ new Map();
74695
74697
  let nextDbHandle = 0;
74696
- await jail.set("$__utils_db_connect", new ivm2.Reference(async (connectionString) => {
74698
+ setGlobal("$__utils_db_connect", new ivm2.Reference(async (connectionString) => {
74697
74699
  const handle = await utils2.db.connect(connectionString);
74698
74700
  const id = String(nextDbHandle++);
74699
74701
  dbHandles.set(id, handle);
74700
74702
  return id;
74701
74703
  }));
74702
- await jail.set("$__utils_db_query", new ivm2.Reference(async (id, sql, params) => {
74704
+ setGlobal("$__utils_db_query", new ivm2.Reference(async (id, sql, params) => {
74703
74705
  const handle = dbHandles.get(id);
74704
74706
  if (!handle) throw new Error(`Invalid db handle: ${id}`);
74705
74707
  return handle.query(sql, params || []);
74706
74708
  }));
74707
- await jail.set("$__utils_db_get", new ivm2.Reference(async (id, sql, params) => {
74709
+ setGlobal("$__utils_db_get", new ivm2.Reference(async (id, sql, params) => {
74708
74710
  const handle = dbHandles.get(id);
74709
74711
  if (!handle) throw new Error(`Invalid db handle: ${id}`);
74710
74712
  const row = await handle.get(sql, params || []);
74711
74713
  return row !== null ? row : null;
74712
74714
  }));
74713
- await jail.set("$__utils_db_exec", new ivm2.Reference(async (id, sql, params) => {
74715
+ setGlobal("$__utils_db_exec", new ivm2.Reference(async (id, sql, params) => {
74714
74716
  const handle = dbHandles.get(id);
74715
74717
  if (!handle) throw new Error(`Invalid db handle: ${id}`);
74716
74718
  return handle.exec(sql, params || []);
74717
74719
  }));
74718
- await jail.set("$__utils_db_close", new ivm2.Reference(async (id) => {
74720
+ setGlobal("$__utils_db_close", new ivm2.Reference(async (id) => {
74719
74721
  const handle = dbHandles.get(id);
74720
74722
  if (!handle) return;
74721
74723
  await handle.close();
74722
74724
  dbHandles.delete(id);
74723
74725
  }));
74724
- await jail.set("$__utils_crypt_hash", new ivm2.Reference((algorithm, data) => {
74726
+ setGlobal("$__utils_crypt_hash", new ivm2.Reference((algorithm, data) => {
74725
74727
  return hash(algorithm, data);
74726
74728
  }));
74727
- await jail.set("$__utils_crypt_hash_hex", new ivm2.Reference((algorithm, data) => {
74729
+ setGlobal("$__utils_crypt_hash_hex", new ivm2.Reference((algorithm, data) => {
74728
74730
  return hashAsHex(algorithm, data);
74729
74731
  }));
74730
- await jail.set("$__utils_crypt_hash_base64", new ivm2.Reference((algorithm, data) => {
74732
+ setGlobal("$__utils_crypt_hash_base64", new ivm2.Reference((algorithm, data) => {
74731
74733
  return hashAsBase64(algorithm, data);
74732
74734
  }));
74733
- await jail.set("$__utils_crypt_uuid", new ivm2.Reference(uuid));
74734
- await jail.set("$__utils_crypt_random_hex", new ivm2.Reference(randomHex));
74735
- await jail.set("$__utils_crypt_random_base64", new ivm2.Reference(randomBase64));
74736
- await jail.set("$__utils_crypt_random_bytes", new ivm2.Reference((size) => {
74735
+ setGlobal("$__utils_crypt_uuid", new ivm2.Reference(uuid));
74736
+ setGlobal("$__utils_crypt_random_hex", new ivm2.Reference(randomHex));
74737
+ setGlobal("$__utils_crypt_random_base64", new ivm2.Reference(randomBase64));
74738
+ setGlobal("$__utils_crypt_random_bytes", new ivm2.Reference((size) => {
74737
74739
  return randomBytesFn(size);
74738
74740
  }));
74739
- await jail.set("$__utils_crypt_hmac", new ivm2.Reference((algorithm, key, data) => {
74741
+ setGlobal("$__utils_crypt_hmac", new ivm2.Reference((algorithm, key, data) => {
74740
74742
  return hmac(algorithm, key, data);
74741
74743
  }));
74742
- await jail.set("$__utils_crypt_hmac_hex", new ivm2.Reference((algorithm, key, data) => {
74744
+ setGlobal("$__utils_crypt_hmac_hex", new ivm2.Reference((algorithm, key, data) => {
74743
74745
  return hmacAsHex(algorithm, key, data);
74744
74746
  }));
74745
- await jail.set("$__utils_crypt_hmac_base64", new ivm2.Reference((algorithm, key, data) => {
74747
+ setGlobal("$__utils_crypt_hmac_base64", new ivm2.Reference((algorithm, key, data) => {
74746
74748
  return hmacAsBase64(algorithm, key, data);
74747
74749
  }));
74748
- await jail.set("$__utils_crypt_encrypt", new ivm2.Reference((algorithm, key, iv, data) => {
74750
+ setGlobal("$__utils_crypt_encrypt", new ivm2.Reference((algorithm, key, iv, data) => {
74749
74751
  return encrypt(algorithm, key, iv, data);
74750
74752
  }));
74751
- await jail.set("$__utils_crypt_decrypt", new ivm2.Reference((algorithm, key, iv, ciphertext) => {
74753
+ setGlobal("$__utils_crypt_decrypt", new ivm2.Reference((algorithm, key, iv, ciphertext) => {
74752
74754
  return decrypt(algorithm, key, iv, ciphertext);
74753
74755
  }));
74754
74756
  const hashStates = /* @__PURE__ */ new Map();
74755
74757
  let nextHashId = 1;
74756
- await jail.set("$__utils_crypt_hash_init", new ivm2.Reference(async (algorithm) => {
74758
+ setGlobal("$__utils_crypt_hash_init", new ivm2.Reference(async (algorithm) => {
74757
74759
  const { createHash: createHash2 } = await import("node:crypto");
74758
74760
  const h = createHash2(algorithm);
74759
74761
  const id = nextHashId++;
74760
74762
  hashStates.set(id, h);
74761
74763
  return id;
74762
74764
  }));
74763
- await jail.set("$__utils_crypt_hash_update", new ivm2.Reference((id, arrayBuffer) => {
74765
+ setGlobal("$__utils_crypt_hash_update", new ivm2.Reference((id, arrayBuffer) => {
74764
74766
  const h = hashStates.get(id);
74765
74767
  if (!h) throw new Error(`Invalid hash stream ID: ${id}`);
74766
74768
  h.update(Buffer.from(arrayBuffer));
74767
74769
  }));
74768
- await jail.set("$__utils_crypt_hash_digest", new ivm2.Reference((id) => {
74770
+ setGlobal("$__utils_crypt_hash_digest", new ivm2.Reference((id) => {
74769
74771
  const h = hashStates.get(id);
74770
74772
  if (!h) throw new Error(`Invalid hash stream ID: ${id}`);
74771
74773
  const digest = h.digest();
@@ -74776,7 +74778,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74776
74778
  }));
74777
74779
  const cipherStates = /* @__PURE__ */ new Map();
74778
74780
  let nextCipherId = 1;
74779
- await jail.set("$__utils_crypt_cipher_init", new ivm2.Reference(async (algorithm, keyRef, ivRef, isEncrypt) => {
74781
+ setGlobal("$__utils_crypt_cipher_init", new ivm2.Reference(async (algorithm, keyRef, ivRef, isEncrypt) => {
74780
74782
  const { createCipheriv: createCipheriv2, createDecipheriv: createDecipheriv2 } = await import("node:crypto");
74781
74783
  const key = Buffer.from(keyRef);
74782
74784
  const iv = Buffer.from(ivRef);
@@ -74792,7 +74794,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74792
74794
  cipherStates.set(id, state);
74793
74795
  return id;
74794
74796
  }));
74795
- await jail.set("$__utils_crypt_cipher_update", new ivm2.Reference((id, arrayBuffer) => {
74797
+ setGlobal("$__utils_crypt_cipher_update", new ivm2.Reference((id, arrayBuffer) => {
74796
74798
  const state = cipherStates.get(id);
74797
74799
  if (!state) throw new Error(`Invalid cipher stream ID: ${id}`);
74798
74800
  const chunk = Buffer.from(arrayBuffer);
@@ -74825,7 +74827,7 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74825
74827
  }
74826
74828
  }
74827
74829
  }));
74828
- await jail.set("$__utils_crypt_cipher_final", new ivm2.Reference((id) => {
74830
+ setGlobal("$__utils_crypt_cipher_final", new ivm2.Reference((id) => {
74829
74831
  const state = cipherStates.get(id);
74830
74832
  if (!state) throw new Error(`Invalid cipher stream ID: ${id}`);
74831
74833
  let finalParts = [];
@@ -74846,14 +74848,14 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74846
74848
  copy.set(merged);
74847
74849
  return copy.buffer;
74848
74850
  }));
74849
- await jail.set("$__utils_archive_zipStream", new ivm2.Reference(async (source) => {
74851
+ setGlobal("$__utils_archive_zipStream", new ivm2.Reference(async (source) => {
74850
74852
  const stream = utils2.archive.zipStream(source);
74851
74853
  const iter = stream[Symbol.asyncIterator]();
74852
74854
  const id = nextStreamId++;
74853
74855
  streams.set(id, iter);
74854
74856
  return id;
74855
74857
  }));
74856
- await jail.set("$__utils_archive_tarStream", new ivm2.Reference(async (source, optsRef) => {
74858
+ setGlobal("$__utils_archive_tarStream", new ivm2.Reference(async (source, optsRef) => {
74857
74859
  const opts = optsRef ? optsRef.copySync() : void 0;
74858
74860
  const stream = await utils2.archive.tarStream(source, opts);
74859
74861
  const iter = stream[Symbol.asyncIterator]();
@@ -74861,36 +74863,37 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74861
74863
  streams.set(id, iter);
74862
74864
  return id;
74863
74865
  }));
74864
- await jail.set("$__utils_archive_unzipStream", new ivm2.Reference(async (dest) => {
74866
+ setGlobal("$__utils_archive_unzipStream", new ivm2.Reference(async (dest) => {
74865
74867
  const writeStream = utils2.archive.unzipStream(dest);
74866
74868
  const id = nextStreamId++;
74867
74869
  streams.set(id, writeStream);
74868
74870
  return id;
74869
74871
  }));
74870
- await jail.set("$__utils_archive_untarStream", new ivm2.Reference(async (dest, optsRef) => {
74872
+ setGlobal("$__utils_archive_untarStream", new ivm2.Reference(async (dest, optsRef) => {
74871
74873
  const opts = optsRef ? optsRef.copySync() : void 0;
74872
74874
  const writeStream = await utils2.archive.untarStream(dest, opts);
74873
74875
  const id = nextStreamId++;
74874
74876
  streams.set(id, writeStream);
74875
74877
  return id;
74876
74878
  }));
74877
- await jail.set("$__performance_now", new ivm2.Reference(() => performance.now()));
74878
- await jail.set("$__vars", JSON.stringify(vars));
74879
- await jail.set("$__os", JSON.stringify(createOsInfo()));
74880
- await jail.set("$__stdin_is_tty", Boolean(utils2.stdin?.isTTY));
74881
- await jail.set("$__utils_stdin_read_bytes", new ivm2.Reference(async (opts) => {
74879
+ setGlobal("$__performance_now", new ivm2.Reference(() => performance.now()));
74880
+ setGlobal("$__vars", JSON.stringify(vars));
74881
+ setGlobal("$__os", JSON.stringify(createOsInfo()));
74882
+ setGlobal("$__stdin_is_tty", Boolean(utils2.stdin?.isTTY));
74883
+ setGlobal("$__utils_stdin_read_bytes", new ivm2.Reference(async (opts) => {
74882
74884
  const bytes = await utils2.stdin.readBytes(opts);
74883
74885
  if (!bytes) return null;
74884
74886
  const copy = new Uint8Array(bytes.length);
74885
74887
  copy.set(bytes);
74886
74888
  return copy.buffer;
74887
74889
  }));
74888
- await jail.set("$__projectDir", projectDir);
74889
- await jail.set("$__rune_key", runeContext?.key ?? null);
74890
- await jail.set("$__rune_lifecycle", runeContext?.lifecycle ?? "run");
74891
- await jail.set("$__rune_args_schema", JSON.stringify(runeContext?.argsSchema ?? null));
74892
- await jail.set("$__rune_commands_schema", JSON.stringify(runeContext?.commandsSchema ?? null));
74893
- const [mdMod, treeMod, utilsMod] = await Promise.all([
74890
+ setGlobal("$__projectDir", projectDir);
74891
+ setGlobal("$__rune_key", runeContext?.key ?? null);
74892
+ setGlobal("$__rune_lifecycle", runeContext?.lifecycle ?? "run");
74893
+ setGlobal("$__rune_args_schema", JSON.stringify(runeContext?.argsSchema ?? null));
74894
+ setGlobal("$__rune_commands_schema", JSON.stringify(runeContext?.commandsSchema ?? null));
74895
+ const [, mdMod, treeMod, utilsMod] = await Promise.all([
74896
+ Promise.all(setOps),
74894
74897
  compileStaticModule(isolate, "md"),
74895
74898
  compileStaticModule(isolate, "tree"),
74896
74899
  compileStaticModule(isolate, "utils")
@@ -74912,23 +74915,26 @@ async function injectUtils(isolate, context, utils2, _runeCallback, vars, projec
74912
74915
  }
74913
74916
  async function injectConsole(isolate, context, onEvent) {
74914
74917
  const jail = context.global;
74915
- if (onEvent) {
74916
- await jail.set("$__utils_console_emit", new ivm2.Reference((level, ...args) => {
74918
+ const consoleOps = onEvent ? [
74919
+ jail.set("$__utils_console_emit", new ivm2.Reference((level, ...args) => {
74917
74920
  onEvent({ type: "log", level, message: args.join(" ") });
74918
- }));
74919
- await jail.set("$__utils_logger_emit", new ivm2.Reference((level, message, meta) => {
74921
+ })),
74922
+ jail.set("$__utils_logger_emit", new ivm2.Reference((level, message, meta) => {
74920
74923
  onEvent({ type: "log", level, message, ...meta != null ? { meta } : {} });
74921
- }));
74922
- } else {
74923
- await jail.set("$__utils_console_emit", new ivm2.Reference((level, ...args) => {
74924
+ }))
74925
+ ] : [
74926
+ jail.set("$__utils_console_emit", new ivm2.Reference((level, ...args) => {
74924
74927
  process.stderr.write(args.join(" ") + "\n");
74925
- }));
74926
- await jail.set("$__utils_logger_emit", new ivm2.Reference((level, message) => {
74928
+ })),
74929
+ jail.set("$__utils_logger_emit", new ivm2.Reference((level, message) => {
74927
74930
  process.stderr.write(`[${level}] ${message}
74928
74931
  `);
74929
- }));
74930
- }
74931
- const consoleMod = await compileStaticModule(isolate, "console");
74932
+ }))
74933
+ ];
74934
+ const [, consoleMod] = await Promise.all([
74935
+ Promise.all(consoleOps),
74936
+ compileStaticModule(isolate, "console")
74937
+ ]);
74932
74938
  await consoleMod.instantiate(context, (spec) => {
74933
74939
  throw new Error(`Unexpected import in console-bootstrap: ${spec}`);
74934
74940
  });
@@ -74981,12 +74987,12 @@ async function runRuneInIsolate(runeFile, effective, args, projectDir, {
74981
74987
  } catch {
74982
74988
  }
74983
74989
  }
74984
- const utilsMod = await injectUtils(isolate, context, utils2, runeCallback, vars, projectDir, checkPermission, sections, wrappedOnEvent, runeContext, isolateMemoryMb);
74985
- await injectConsole(isolate, context, wrappedOnEvent);
74986
- if (pluginDir != null) {
74987
- await context.global.set("CRUNES_PLUGIN_ROOT", pluginDir);
74988
- }
74989
- const runeSrc = await fs6.readFile(runeFile, "utf8");
74990
+ const [utilsMod, , , runeSrc] = await Promise.all([
74991
+ injectUtils(isolate, context, utils2, runeCallback, vars, projectDir, checkPermission, sections, wrappedOnEvent, runeContext, isolateMemoryMb),
74992
+ injectConsole(isolate, context, wrappedOnEvent),
74993
+ pluginDir != null ? context.global.set("CRUNES_PLUGIN_ROOT", pluginDir) : Promise.resolve(),
74994
+ fs6.readFile(runeFile, "utf8")
74995
+ ]);
74990
74996
  assertNoDynamicImport(runeSrc, runeFile);
74991
74997
  const exportBinding = `
74992
74998
  if (typeof ${lifecycle} !== "undefined") globalThis.__crunes_target = ${lifecycle};