@poe-platform/safe-js 0.1.803 → 0.1.804

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +4 -4
  2. package/dist/safe-js/bundled-yaml/LICENSE +13 -0
  3. package/dist/safe-js/bundled-yaml/index.js +6601 -0
  4. package/dist/safe-js/chunks/{chunk-FUXGXSZC.js → chunk-36PBWSDR.js} +8 -8
  5. package/dist/safe-js/chunks/{chunk-SN4G557J.js → chunk-6AO2T2VZ.js} +1 -1
  6. package/dist/safe-js/chunks/{chunk-ZXDUALDQ.js → chunk-BKNQTNHP.js} +33 -23
  7. package/dist/safe-js/chunks/{chunk-WEPHHJMR.js → chunk-BYDDUKS3.js} +3 -3
  8. package/dist/safe-js/chunks/{chunk-6H5VC5W5.js → chunk-CKOGIOB3.js} +470 -464
  9. package/dist/safe-js/chunks/{chunk-D36FRVNN.js → chunk-CVPZFRCC.js} +3 -3
  10. package/dist/safe-js/chunks/{chunk-4KMUWNZD.js → chunk-ECMGBHAB.js} +13 -137
  11. package/dist/safe-js/chunks/{chunk-A3LXCGMJ.js → chunk-EQUBWQJN.js} +57 -34
  12. package/dist/safe-js/chunks/{chunk-ZAOSXSKI.js → chunk-JMDWLOJV.js} +26 -3
  13. package/dist/safe-js/chunks/{chunk-3NFTBEZR.js → chunk-JQ5QJV5Q.js} +2 -2
  14. package/dist/safe-js/chunks/{chunk-MMN3IESA.js → chunk-KMBCLXER.js} +1 -1
  15. package/dist/safe-js/chunks/{chunk-WRGATIKL.js → chunk-MJH73KJI.js} +2 -2
  16. package/dist/safe-js/chunks/{chunk-UQYM4GXB.js → chunk-P66QKVQC.js} +3 -3
  17. package/dist/safe-js/chunks/{chunk-HPHCQNFV.js → chunk-RPGCF4KE.js} +130 -3
  18. package/dist/safe-js/chunks/{chunk-J565YTXP.js → chunk-SIR35W6T.js} +5 -5
  19. package/dist/safe-js/chunks/{chunk-LVTYTUF5.js → chunk-SMGNJNDU.js} +1 -1
  20. package/dist/safe-js/chunks/{chunk-6NCYOKZQ.js → chunk-VLRTLEDI.js} +2 -2
  21. package/dist/safe-js/chunks/{chunk-JCHJGIQA.js → chunk-VVOPJZRG.js} +2 -0
  22. package/dist/safe-js/chunks/{cli-runtime-QIA3QMTP.js → cli-runtime-A353G7DR.js} +15 -15
  23. package/dist/safe-js/chunks/{dump-TGI6PZKL.js → dump-KQZFULX2.js} +4 -4
  24. package/dist/safe-js/chunks/harness-XT6K6X67.js +10 -0
  25. package/dist/safe-js/chunks/mcp-VWE444VD.js +11 -0
  26. package/dist/safe-js/chunks/migration-file-NSKXOMAO.js +14 -0
  27. package/dist/safe-js/chunks/restore-SHPORPY4.js +13 -0
  28. package/dist/safe-js/chunks/run-FQOSICOT.js +19 -0
  29. package/dist/safe-js/chunks/{runtime-modules-HWTUIY5J.js → runtime-modules-DBRXXRND.js} +4 -4
  30. package/dist/safe-js/chunks/{source-files-BSDM22Y2.js → source-files-A2WSOO6G.js} +3 -3
  31. package/dist/safe-js/cli.js +2 -2
  32. package/dist/safe-js/core.d.ts +19 -0
  33. package/dist/safe-js/core.js +39 -15
  34. package/dist/safe-js/error/format.d.ts +3 -0
  35. package/dist/safe-js/index.d.ts +1 -12
  36. package/dist/safe-js/index.js +30 -39
  37. package/dist/safe-js/interp/interpreter.d.ts +1 -3
  38. package/dist/safe-js/modules/fs.js +5 -5
  39. package/dist/safe-js/platform/node.d.ts +1 -0
  40. package/dist/safe-js/platform/node.js +1 -0
  41. package/dist/safe-js/platform/workerd.d.ts +1 -0
  42. package/dist/safe-js/platform/workerd.js +2 -0
  43. package/dist/safe-js/portable/chunks/{chunk-XCTU25SU.js → chunk-NLGXLZCK.js} +1 -1
  44. package/dist/safe-js/portable/chunks/{chunk-BIHLWVUU.js → chunk-SRMMDXD3.js} +124 -91
  45. package/dist/safe-js/portable/chunks/{chunk-H5X3T5VP.js → chunk-W6MZOTYR.js} +2 -0
  46. package/dist/safe-js/portable/chunks/{source-files-CVU252FB.js → source-files-AEDWESAJ.js} +2 -2
  47. package/dist/safe-js/portable/core.js +452 -246
  48. package/dist/safe-js/portable/modules/fs.js +2 -2
  49. package/dist/safe-js/workerd.js +57970 -57736
  50. package/package.json +6 -5
  51. package/dist/safe-js/chunks/harness-EE3ISLJP.js +0 -10
  52. package/dist/safe-js/chunks/mcp-F5MMOZNP.js +0 -11
  53. package/dist/safe-js/chunks/migration-file-W3HZOGXV.js +0 -14
  54. package/dist/safe-js/chunks/restore-MMM4A46M.js +0 -13
  55. package/dist/safe-js/chunks/run-TKX3IFNH.js +0 -19
  56. package/dist/safe-js/node-unavailable.d.ts +0 -1
@@ -2,7 +2,7 @@ import {
2
2
  hashParsedAst,
3
3
  hashSource,
4
4
  validateSnapshotMigration
5
- } from "./chunk-WRGATIKL.js";
5
+ } from "./chunk-MJH73KJI.js";
6
6
  import {
7
7
  SnapshotValidationError,
8
8
  assertSnapshotInactive,
@@ -11,13 +11,13 @@ import {
11
11
  validateDumpEnvelope,
12
12
  validateGuestHeapSource,
13
13
  validateRuntimeSnapshotDescriptors
14
- } from "./chunk-ZXDUALDQ.js";
14
+ } from "./chunk-BKNQTNHP.js";
15
15
  import {
16
16
  SandboxError,
17
17
  parseExecutableModule,
18
18
  parseModule,
19
19
  replaceErrorStack
20
- } from "./chunk-A3LXCGMJ.js";
20
+ } from "./chunk-EQUBWQJN.js";
21
21
 
22
22
  // packages/safe-js/src/restore.ts
23
23
  var SnapshotMismatchError = class extends Error {
@@ -1,8 +1,3 @@
1
- import {
2
- addBrokenPipeListener,
3
- createBrokenPipeState,
4
- createSafeOutputStream
5
- } from "./chunk-X3YCE3ZH.js";
6
1
  import {
7
2
  SandboxError,
8
3
  activateOtelSpan,
@@ -14,15 +9,14 @@ import {
14
9
  safeRecordException,
15
10
  safeStartSpan,
16
11
  splitSourceLines
17
- } from "./chunk-A3LXCGMJ.js";
12
+ } from "./chunk-EQUBWQJN.js";
18
13
  import {
19
14
  AsyncLocalStorage,
20
15
  hostCwd
21
- } from "./chunk-JCHJGIQA.js";
16
+ } from "./chunk-VVOPJZRG.js";
22
17
 
23
18
  // packages/safe-js/src/error/format.ts
24
- var DEFAULT_MAX_MESSAGE_LENGTH = 1e4;
25
- var MAX_CAUSE_DEPTH = 20;
19
+ var DEFAULT_MAX_MESSAGE_LENGTH = Infinity;
26
20
  function formatInterpreterError(first, second) {
27
21
  if (typeof first === "string" && isInterpreterDiagnostic(second)) {
28
22
  return formatSourceDiagnostic(first, second, {
@@ -41,6 +35,7 @@ function normalizeOptions(options) {
41
35
  filename: options?.filename ?? "<input>",
42
36
  hostCallName: options?.hostCallName ?? "",
43
37
  maxMessageLength: options?.maxMessageLength ?? DEFAULT_MAX_MESSAGE_LENGTH,
38
+ maxCauseDepth: options?.maxCauseDepth ?? Infinity,
44
39
  source: options?.source ?? ""
45
40
  };
46
41
  }
@@ -61,10 +56,10 @@ function formatTopLevelError(error, options) {
61
56
  line: error.span.start.line,
62
57
  column: error.span.start.column,
63
58
  message: error.message
64
- });
59
+ }, options);
65
60
  }
66
61
  if (isErrorLike(error)) {
67
- return formatErrorLike(error, options.maxMessageLength);
62
+ return formatErrorLike(error, options.maxMessageLength, options.maxCauseDepth);
68
63
  }
69
64
  return `Thrown value: ${truncate(describeThrownValue(error), options.maxMessageLength)}`;
70
65
  }
@@ -85,9 +80,9 @@ function formatSandboxError(error, maxMessageLength) {
85
80
  }
86
81
  return lines.join("\n");
87
82
  }
88
- function formatErrorLike(error, maxMessageLength) {
83
+ function formatErrorLike(error, maxMessageLength, maxCauseDepth) {
89
84
  const stack = formatSandboxStack(error, maxMessageLength);
90
- const causes = formatCauses(error, maxMessageLength);
85
+ const causes = formatCauses(error, maxMessageLength, maxCauseDepth);
91
86
  if (causes.length === 0) {
92
87
  return stack;
93
88
  }
@@ -112,11 +107,11 @@ function isSandboxStackFrame(line) {
112
107
  const trimmed = line.trimStart();
113
108
  return trimmed.startsWith("at ") && trimmed.includes("(line ") && trimmed.includes(", column ") && trimmed.endsWith(")");
114
109
  }
115
- function formatCauses(error, maxMessageLength) {
110
+ function formatCauses(error, maxMessageLength, maxCauseDepth) {
116
111
  const causes = [];
117
112
  const seen = /* @__PURE__ */ new Set();
118
113
  let current = readCause(error);
119
- for (let depth = 0; depth < MAX_CAUSE_DEPTH && current !== void 0; depth += 1) {
114
+ for (let depth = 0; depth < maxCauseDepth && current !== void 0; depth += 1) {
120
115
  if (seen.has(current)) {
121
116
  causes.push("Caused by: [Circular cause]");
122
117
  break;
@@ -575,7 +570,7 @@ function findLineEnd2(source, start) {
575
570
  }
576
571
 
577
572
  // packages/frontmatter/src/parse.ts
578
- import { LineCounter, parse, parseDocument } from "yaml";
573
+ import { LineCounter, parse, parseDocument } from "../bundled-yaml/index.js";
579
574
  var FrontmatterParseError = class extends Error {
580
575
  constructor(message) {
581
576
  super(message);
@@ -745,7 +740,7 @@ function isPlainRecord(value) {
745
740
  }
746
741
 
747
742
  // packages/frontmatter/src/stringify.ts
748
- import { stringify } from "yaml";
743
+ import { stringify } from "../bundled-yaml/index.js";
749
744
 
750
745
  // packages/safe-js/src/loader/frontmatter.ts
751
746
  function splitFrontmatter(markdown) {
@@ -2569,124 +2564,6 @@ async function resolveFsConfig(config, options = {}) {
2569
2564
  return { adapter, ...paths };
2570
2565
  }
2571
2566
 
2572
- // packages/safe-js/src/modules/log.ts
2573
- var stdoutSinks = /* @__PURE__ */ new WeakMap();
2574
- function makeLogModule(sink = createJsonlStdoutSink()) {
2575
- const normalizedSink = readSink(sink);
2576
- return {
2577
- info(...args) {
2578
- normalizedSink({
2579
- ts: (/* @__PURE__ */ new Date()).toISOString(),
2580
- type: "info",
2581
- args
2582
- });
2583
- },
2584
- error(...args) {
2585
- normalizedSink({
2586
- ts: (/* @__PURE__ */ new Date()).toISOString(),
2587
- type: "error",
2588
- args
2589
- });
2590
- },
2591
- event(name, payload) {
2592
- normalizedSink({
2593
- ts: (/* @__PURE__ */ new Date()).toISOString(),
2594
- type: "event",
2595
- name: readNonEmptyString2(name, "Event name"),
2596
- payload
2597
- });
2598
- }
2599
- };
2600
- }
2601
- function createJsonlStdoutSink() {
2602
- const stream = typeof process !== "undefined" ? process.stdout : void 0;
2603
- if (stream === void 0) {
2604
- return (entry) => console.log(JSON.stringify(toJsonValue(entry, /* @__PURE__ */ new WeakSet())));
2605
- }
2606
- const existing = stdoutSinks.get(stream);
2607
- if (existing) return existing;
2608
- const brokenPipe = createBrokenPipeState();
2609
- const stdout = createSafeOutputStream(stream, brokenPipe);
2610
- addBrokenPipeListener(stream, brokenPipe);
2611
- const sink = (entry) => {
2612
- stdout.write(`${JSON.stringify(toJsonValue(entry, /* @__PURE__ */ new WeakSet()))}
2613
- `);
2614
- };
2615
- stdoutSinks.set(stream, sink);
2616
- return sink;
2617
- }
2618
- function readNonEmptyString2(value, label) {
2619
- if (typeof value !== "string") {
2620
- throw new Error(`${label} must be a non-empty string.`);
2621
- }
2622
- const normalizedValue = value.trim();
2623
- if (normalizedValue.length === 0) {
2624
- throw new Error(`${label} must be a non-empty string.`);
2625
- }
2626
- return normalizedValue;
2627
- }
2628
- function readSink(value) {
2629
- if (typeof value !== "function") {
2630
- throw new Error("Log sink must be a function.");
2631
- }
2632
- return value;
2633
- }
2634
- function toJsonValue(value, seen) {
2635
- if (value === void 0) {
2636
- return null;
2637
- }
2638
- if (value === null || typeof value === "string" || typeof value === "boolean") {
2639
- return value;
2640
- }
2641
- if (typeof value === "number") {
2642
- return Number.isFinite(value) ? value : String(value);
2643
- }
2644
- if (typeof value === "bigint" || typeof value === "symbol") {
2645
- return String(value);
2646
- }
2647
- if (typeof value === "function") {
2648
- return `[Function ${value.name || "anonymous"}]`;
2649
- }
2650
- if (value instanceof Date) {
2651
- return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
2652
- }
2653
- if (value instanceof Error) {
2654
- const serializedError = {
2655
- name: value.name,
2656
- message: value.message
2657
- };
2658
- if (typeof value.stack === "string" && value.stack.length > 0) {
2659
- serializedError.stack = value.stack;
2660
- }
2661
- if (Object.prototype.hasOwnProperty.call(value, "cause")) {
2662
- serializedError.cause = toJsonValue(value.cause, seen);
2663
- }
2664
- return serializedError;
2665
- }
2666
- if (Array.isArray(value)) {
2667
- if (seen.has(value)) {
2668
- return "[Circular]";
2669
- }
2670
- seen.add(value);
2671
- const normalized = value.map((entry) => toJsonValue(entry, seen));
2672
- seen.delete(value);
2673
- return normalized;
2674
- }
2675
- if (typeof value === "object") {
2676
- if (seen.has(value)) {
2677
- return "[Circular]";
2678
- }
2679
- seen.add(value);
2680
- const normalized = /* @__PURE__ */ Object.create(null);
2681
- for (const [key, entry] of Object.entries(value)) {
2682
- normalized[key] = toJsonValue(entry, seen);
2683
- }
2684
- seen.delete(value);
2685
- return normalized;
2686
- }
2687
- return String(value);
2688
- }
2689
-
2690
2567
  export {
2691
2568
  formatInterpreterError,
2692
2569
  SPAWN_MODES,
@@ -2700,6 +2577,5 @@ export {
2700
2577
  runWithSpawnUsageAccumulator,
2701
2578
  makeAgentModule,
2702
2579
  parseFsConfig,
2703
- resolveFsConfig,
2704
- makeLogModule
2580
+ resolveFsConfig
2705
2581
  };
@@ -5172,49 +5172,72 @@ var Parser = class {
5172
5172
  }
5173
5173
  parseIfStatement() {
5174
5174
  const pending = [];
5175
- let entered = 0;
5175
+ const initialDepth = this.ifStatementDepth;
5176
+ const initialScopes = this.scopes.length;
5177
+ let result;
5176
5178
  try {
5177
5179
  for (; ; ) {
5178
- if (this.ifStatementDepth >= (this.compilation?.owner?.budget.limits.maxCallDepth ?? Infinity)) {
5179
- const token2 = this.currentToken();
5180
- throw new Error(
5181
- `If statement nesting limit exceeded at line ${token2.start.line}, column ${token2.start.column}.`
5182
- );
5180
+ if (result === void 0) {
5181
+ const token = this.currentToken();
5182
+ if (token.type === "keyword" && token.value === "if") {
5183
+ if (this.ifStatementDepth >= (this.compilation?.owner?.budget.limits.maxCallDepth ?? Infinity))
5184
+ throw new Error(`If statement nesting limit exceeded at line ${token.start.line}, column ${token.start.column}.`);
5185
+ this.ifStatementDepth++;
5186
+ this.index++;
5187
+ this.expectPunctuator("(");
5188
+ const test = this.parseExpression({ allowSequence: true }).node;
5189
+ this.expectPunctuator(")");
5190
+ pending.push({ kind: "if", token, test });
5191
+ continue;
5192
+ }
5193
+ if (token.type === "punctuator" && token.value === "{") {
5194
+ this.index++;
5195
+ this.scopes.push(/* @__PURE__ */ new Map());
5196
+ pending.push({ kind: "block", token, body: [] });
5197
+ } else {
5198
+ result = pending.at(-1)?.kind === "block" ? this.parseStatement() : this.parseIfClause();
5199
+ }
5183
5200
  }
5184
- this.ifStatementDepth++;
5185
- entered++;
5186
- const token = this.expectKeyword("if");
5187
- this.expectPunctuator("(");
5188
- const test = this.parseExpression({ allowSequence: true }).node;
5189
- this.expectPunctuator(")");
5190
- const consequent = this.parseIfClause();
5191
- const hasElse = this.consumeKeyword("else") !== void 0;
5192
- if (hasElse && this.currentToken().type === "keyword" && this.currentToken().value === "if") {
5193
- pending.push({ token, test, consequent });
5201
+ const frame = pending.at(-1);
5202
+ if (frame === void 0) return result;
5203
+ if (frame.kind === "block") {
5204
+ if (result !== void 0) {
5205
+ frame.body.push(result);
5206
+ while (result.type !== "EmptyStatement" && this.consumePunctuator(";") !== void 0) {
5207
+ }
5208
+ result = void 0;
5209
+ }
5210
+ if (this.consumePunctuator("}") === void 0) {
5211
+ if (this.currentToken().type === "eof")
5212
+ throw new Error(`Unterminated block at line ${frame.token.start.line}, column ${frame.token.start.column}.`);
5213
+ continue;
5214
+ }
5215
+ pending.pop();
5216
+ this.scopes.pop();
5217
+ result = { type: "BlockStatement", body: frame.body, span: createSpan2(frame.token.start, this.previousToken().end) };
5194
5218
  continue;
5195
5219
  }
5196
- const alternate = hasElse ? this.parseIfClause() : void 0;
5197
- let result = {
5220
+ if (frame.consequent === void 0) {
5221
+ frame.consequent = result;
5222
+ if (this.consumeKeyword("else") !== void 0) {
5223
+ result = void 0;
5224
+ continue;
5225
+ }
5226
+ result = void 0;
5227
+ }
5228
+ pending.pop();
5229
+ this.ifStatementDepth--;
5230
+ result = {
5198
5231
  type: "IfStatement",
5199
- test,
5200
- consequent,
5201
- alternate,
5202
- span: createSpan2(token.start, alternate?.span.end ?? consequent.span.end)
5232
+ test: frame.test,
5233
+ consequent: frame.consequent,
5234
+ alternate: result,
5235
+ span: createSpan2(frame.token.start, result?.span.end ?? frame.consequent.span.end)
5203
5236
  };
5204
- while (pending.length > 0) {
5205
- const parent = pending.pop();
5206
- result = {
5207
- type: "IfStatement",
5208
- test: parent.test,
5209
- consequent: parent.consequent,
5210
- alternate: result,
5211
- span: createSpan2(parent.token.start, result.span.end)
5212
- };
5213
- }
5214
- return result;
5215
5237
  }
5216
5238
  } finally {
5217
- this.ifStatementDepth -= entered;
5239
+ this.ifStatementDepth = initialDepth;
5240
+ this.scopes.length = initialScopes;
5218
5241
  }
5219
5242
  }
5220
5243
  parseSwitchStatement() {
@@ -1,6 +1,18 @@
1
1
  import {
2
- createSeededRandom
3
- } from "./chunk-ZXDUALDQ.js";
2
+ restore
3
+ } from "./chunk-CVPZFRCC.js";
4
+ import {
5
+ createSeededRandom,
6
+ deepCopyFromSandbox
7
+ } from "./chunk-BKNQTNHP.js";
8
+ import {
9
+ parse,
10
+ parseModule,
11
+ parseSourceModule
12
+ } from "./chunk-EQUBWQJN.js";
13
+
14
+ // packages/safe-js/src/parse.ts
15
+ var parse2 = parse;
4
16
 
5
17
  // packages/safe-js/src/modules/time.ts
6
18
  function makeTimeModule(options = {}) {
@@ -73,6 +85,17 @@ function createSleepAbortError() {
73
85
  return new Error("time.sleep aborted.");
74
86
  }
75
87
 
88
+ // packages/safe-js/src/core.ts
89
+ var parseModule2 = parseModule;
90
+ var parseSourceModule2 = parseSourceModule;
91
+ var restore2 = restore;
92
+ var deepCopyFromSandbox2 = deepCopyFromSandbox;
93
+
76
94
  export {
77
- makeTimeModule
95
+ parse2 as parse,
96
+ makeTimeModule,
97
+ parseModule2 as parseModule,
98
+ parseSourceModule2 as parseSourceModule,
99
+ restore2 as restore,
100
+ deepCopyFromSandbox2 as deepCopyFromSandbox
78
101
  };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  paths_default
3
- } from "./chunk-MMN3IESA.js";
3
+ } from "./chunk-KMBCLXER.js";
4
4
  import {
5
5
  constants,
6
6
  hostFs
7
- } from "./chunk-JCHJGIQA.js";
7
+ } from "./chunk-VVOPJZRG.js";
8
8
 
9
9
  // packages/safe-js/src/modules/source-files.ts
10
10
  import { resolvePath } from "@poe-platform/safe-fs/core";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  hostCwd
3
- } from "./chunk-JCHJGIQA.js";
3
+ } from "./chunk-VVOPJZRG.js";
4
4
 
5
5
  // packages/safe-js/src/modules/paths.ts
6
6
  import { basename, dirname, extname, isAbsolutePath, joinPath, relativePath, resolvePath } from "@poe-platform/safe-fs/core";
@@ -2,14 +2,14 @@ import {
2
2
  HostCallJournal,
3
3
  decodeReplayData,
4
4
  validateSnapshotData
5
- } from "./chunk-ZXDUALDQ.js";
5
+ } from "./chunk-BKNQTNHP.js";
6
6
  import {
7
7
  CompileScope,
8
8
  SandboxError,
9
9
  functionSources,
10
10
  parse,
11
11
  parseModule
12
- } from "./chunk-A3LXCGMJ.js";
12
+ } from "./chunk-EQUBWQJN.js";
13
13
 
14
14
  // packages/safe-js/src/parse/hash.ts
15
15
  var FNV_OFFSET_BASIS = 2166136261;
@@ -2,14 +2,14 @@ import {
2
2
  McpError,
3
3
  connectMcpTransport,
4
4
  normalizeMcpOptions
5
- } from "./chunk-6H5VC5W5.js";
5
+ } from "./chunk-CKOGIOB3.js";
6
6
  import {
7
7
  declareHostOperation,
8
8
  runResources
9
- } from "./chunk-ZXDUALDQ.js";
9
+ } from "./chunk-BKNQTNHP.js";
10
10
  import {
11
11
  hostErrorData
12
- } from "./chunk-A3LXCGMJ.js";
12
+ } from "./chunk-EQUBWQJN.js";
13
13
 
14
14
  // packages/safe-js/src/modules/mcp.ts
15
15
  var DEFAULT_TOOL_BATCH_CONCURRENCY = 4;
@@ -1,3 +1,8 @@
1
+ import {
2
+ addBrokenPipeListener,
3
+ createBrokenPipeState,
4
+ createSafeOutputStream
5
+ } from "./chunk-X3YCE3ZH.js";
1
6
  import {
2
7
  DisallowedSyntaxError,
3
8
  ParseError,
@@ -9,7 +14,10 @@ import {
9
14
  numericTypedArrayConstructors,
10
15
  parseModule,
11
16
  tokenize
12
- } from "./chunk-A3LXCGMJ.js";
17
+ } from "./chunk-EQUBWQJN.js";
18
+ import {
19
+ hostEnv
20
+ } from "./chunk-VVOPJZRG.js";
13
21
 
14
22
  // packages/safe-js/src/lint/rules/AS001.ts
15
23
  function AS001(source, options = {}) {
@@ -11194,7 +11202,7 @@ function makeEnvModule(input) {
11194
11202
  get(name) {
11195
11203
  const variable = readEnvName(name, "Environment variable name");
11196
11204
  if (!allowedNames.has(variable)) throw new EnvAccessError(variable);
11197
- return readEnvValue(values ?? (typeof process !== "undefined" ? process.env ?? {} : {}), variable);
11205
+ return readEnvValue(values ?? hostEnv(), variable);
11198
11206
  }
11199
11207
  };
11200
11208
  }
@@ -11321,6 +11329,124 @@ function readNonEmptyString2(value, label) {
11321
11329
  return normalizedValue;
11322
11330
  }
11323
11331
 
11332
+ // packages/safe-js/src/modules/log.ts
11333
+ var stdoutSinks = /* @__PURE__ */ new WeakMap();
11334
+ function makeLogModule(sink = createJsonlStdoutSink()) {
11335
+ const normalizedSink = readSink(sink);
11336
+ return {
11337
+ info(...args) {
11338
+ normalizedSink({
11339
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
11340
+ type: "info",
11341
+ args
11342
+ });
11343
+ },
11344
+ error(...args) {
11345
+ normalizedSink({
11346
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
11347
+ type: "error",
11348
+ args
11349
+ });
11350
+ },
11351
+ event(name, payload) {
11352
+ normalizedSink({
11353
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
11354
+ type: "event",
11355
+ name: readNonEmptyString3(name, "Event name"),
11356
+ payload
11357
+ });
11358
+ }
11359
+ };
11360
+ }
11361
+ function createJsonlStdoutSink() {
11362
+ const stream = typeof process !== "undefined" ? process.stdout : void 0;
11363
+ if (stream == null || typeof stream.write !== "function") {
11364
+ return (entry) => console.log(JSON.stringify(toJsonValue(entry, /* @__PURE__ */ new WeakSet())));
11365
+ }
11366
+ const existing = stdoutSinks.get(stream);
11367
+ if (existing) return existing;
11368
+ const brokenPipe = createBrokenPipeState();
11369
+ const stdout = createSafeOutputStream(stream, brokenPipe);
11370
+ addBrokenPipeListener(stream, brokenPipe);
11371
+ const sink = (entry) => {
11372
+ stdout.write(`${JSON.stringify(toJsonValue(entry, /* @__PURE__ */ new WeakSet()))}
11373
+ `);
11374
+ };
11375
+ stdoutSinks.set(stream, sink);
11376
+ return sink;
11377
+ }
11378
+ function readNonEmptyString3(value, label) {
11379
+ if (typeof value !== "string") {
11380
+ throw new Error(`${label} must be a non-empty string.`);
11381
+ }
11382
+ const normalizedValue = value.trim();
11383
+ if (normalizedValue.length === 0) {
11384
+ throw new Error(`${label} must be a non-empty string.`);
11385
+ }
11386
+ return normalizedValue;
11387
+ }
11388
+ function readSink(value) {
11389
+ if (typeof value !== "function") {
11390
+ throw new Error("Log sink must be a function.");
11391
+ }
11392
+ return value;
11393
+ }
11394
+ function toJsonValue(value, seen) {
11395
+ if (value === void 0) {
11396
+ return null;
11397
+ }
11398
+ if (value === null || typeof value === "string" || typeof value === "boolean") {
11399
+ return value;
11400
+ }
11401
+ if (typeof value === "number") {
11402
+ return Number.isFinite(value) ? value : String(value);
11403
+ }
11404
+ if (typeof value === "bigint" || typeof value === "symbol") {
11405
+ return String(value);
11406
+ }
11407
+ if (typeof value === "function") {
11408
+ return `[Function ${value.name || "anonymous"}]`;
11409
+ }
11410
+ if (value instanceof Date) {
11411
+ return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
11412
+ }
11413
+ if (value instanceof Error) {
11414
+ const serializedError = {
11415
+ name: value.name,
11416
+ message: value.message
11417
+ };
11418
+ if (typeof value.stack === "string" && value.stack.length > 0) {
11419
+ serializedError.stack = value.stack;
11420
+ }
11421
+ if (Object.prototype.hasOwnProperty.call(value, "cause")) {
11422
+ serializedError.cause = toJsonValue(value.cause, seen);
11423
+ }
11424
+ return serializedError;
11425
+ }
11426
+ if (Array.isArray(value)) {
11427
+ if (seen.has(value)) {
11428
+ return "[Circular]";
11429
+ }
11430
+ seen.add(value);
11431
+ const normalized = value.map((entry) => toJsonValue(entry, seen));
11432
+ seen.delete(value);
11433
+ return normalized;
11434
+ }
11435
+ if (typeof value === "object") {
11436
+ if (seen.has(value)) {
11437
+ return "[Circular]";
11438
+ }
11439
+ seen.add(value);
11440
+ const normalized = /* @__PURE__ */ Object.create(null);
11441
+ for (const [key, entry] of Object.entries(value)) {
11442
+ normalized[key] = toJsonValue(entry, seen);
11443
+ }
11444
+ seen.delete(value);
11445
+ return normalized;
11446
+ }
11447
+ return String(value);
11448
+ }
11449
+
11324
11450
  export {
11325
11451
  lint,
11326
11452
  EnvAccessError,
@@ -11328,5 +11454,6 @@ export {
11328
11454
  parseEnvConfig,
11329
11455
  HarnessFailure,
11330
11456
  makeFailModule,
11331
- makeMetricModule
11457
+ makeMetricModule,
11458
+ makeLogModule
11332
11459
  };
@@ -10,7 +10,7 @@ import {
10
10
  validateMigrationReconciliation,
11
11
  validateMigrationSemantics,
12
12
  validateSnapshotMigration
13
- } from "./chunk-WRGATIKL.js";
13
+ } from "./chunk-MJH73KJI.js";
14
14
  import {
15
15
  DUMP_FORMAT_VERSION,
16
16
  EXECUTION_SEMANTICS,
@@ -20,17 +20,17 @@ import {
20
20
  serializeSafeJSSnapshot,
21
21
  validateDumpEnvelope,
22
22
  validateSnapshotData
23
- } from "./chunk-ZXDUALDQ.js";
23
+ } from "./chunk-BKNQTNHP.js";
24
24
  import {
25
25
  parseModule
26
- } from "./chunk-A3LXCGMJ.js";
26
+ } from "./chunk-EQUBWQJN.js";
27
27
  import {
28
28
  paths_default
29
- } from "./chunk-MMN3IESA.js";
29
+ } from "./chunk-KMBCLXER.js";
30
30
  import {
31
31
  hostCwd,
32
32
  hostFs
33
- } from "./chunk-JCHJGIQA.js";
33
+ } from "./chunk-VVOPJZRG.js";
34
34
 
35
35
  // packages/safe-js/src/migration-file.ts
36
36
  import { createFsBridge } from "@poe-platform/safe-fs/core";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isSandboxClosure
3
- } from "./chunk-ZXDUALDQ.js";
3
+ } from "./chunk-BKNQTNHP.js";
4
4
 
5
5
  // packages/safe-js/src/lint/runtime-modules.ts
6
6
  var AsyncFunction = (async () => void 0).constructor;
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  SnapshotNotReadyError,
3
3
  serializeSafeJSSnapshot
4
- } from "./chunk-ZXDUALDQ.js";
4
+ } from "./chunk-BKNQTNHP.js";
5
5
  import {
6
6
  SandboxError
7
- } from "./chunk-A3LXCGMJ.js";
7
+ } from "./chunk-EQUBWQJN.js";
8
8
 
9
9
  // packages/safe-js/src/snapshot/dump.ts
10
10
  var RUN_DUMP_CONTROLLER = /* @__PURE__ */ Symbol("SafeJS.run-dump-controller");
@@ -54,6 +54,7 @@ var types2 = nodeUtil.types;
54
54
  var hostFs = nativeFsPromises;
55
55
  var hostCwd = process.cwd.bind(process);
56
56
  var hostPlatform = process.platform;
57
+ var hostEnv = () => process.env;
57
58
 
58
59
  export {
59
60
  AsyncLocalStorage,
@@ -64,6 +65,7 @@ export {
64
65
  hostFs,
65
66
  hostCwd,
66
67
  hostPlatform,
68
+ hostEnv,
67
69
  setImmediate,
68
70
  inspect,
69
71
  formatWithOptions,