@poe-platform/safe-js 0.1.745 → 0.1.747

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -460,7 +460,7 @@ For one-shot use, `run(source, { extensions, grants, ... })` accepts the same re
460
460
 
461
461
  `JSON.parse` checks both parse paths before building native objects: input work counts toward steps and deadlines, array lengths and object member counts use `arrayLength`, and nesting uses `maxCallDepth` only when explicitly configured. Parsing requires room for a conservative temporary allocation bound of `16 * text.length + 8` data units alongside existing data; whitespace and duplicate keys count toward this bound.
462
462
 
463
- There are no runtime environment variables to set. `makeEnvModule({ allow, values? })` grants reads of names in `allow`; `values` supplies an explicit string map instead of reading the host's `process.env`. Disallowed reads throw `EnvAccessError`; allowed but unset names return `undefined`. Agent and MCP integrations may require their own credentials.
463
+ There are no runtime environment variables to set. `makeEnvModule({ allow, values? })` grants reads of names in `allow`; `values` supplies an explicit string map instead of reading the host's `process.env`. Hosts without `process.env` have no ambient values; pass Worker bindings through `values`. Disallowed reads throw `EnvAccessError`; allowed but unset names return `undefined`. Agent and MCP integrations may require their own credentials.
464
464
 
465
465
  <details>
466
466
  <summary>Linting, parsing, and value conversion</summary>
@@ -540,7 +540,7 @@ Factories return exports to register in `modules`; calling a factory alone does
540
540
  | `makeFsModule(options?)` | Node-backed `{ root?, fs? }`, or shared-filesystem `{ adapter, root?, cwd?, signal? }`; do not combine `fs` and `adapter`. Pass safe-fs instances through `adapter`; supplying one as `fs` throws at construction. Named methods, default imports and `promises` imports expose the same asynchronous filesystem operations, including `fs.promises.readFile(...)` on default imports and `promises.default.readFile(...)` on named imports. Node access without `root` is unconfined. Rooted calls sharing the same adapter or Node implementation are serialized through path checks and backend completion to prevent guest namespace races. External host mutations or distinct adapters over the same storage require independent backend confinement. With an adapter, `root` confines access and `cwd` selects the virtual relative-path base; without `root`, explicit `cwd` also confines access. Omitting both uses virtual `/`. Adapter text reads pass a byte cap derived conservatively from the guest string and remaining data limits to the backend before decoding. Optional `readFileMaxBytes` and `hostReadMemoryLimit` default to `Infinity` and accept explicit `Infinity`. A finite host allowance reserves ten bytes per input byte for collection, copies, encoding expansion and admission across concurrent reads from that module; reservations release after the underlying read settles and decoding finishes, including when cancellation rejects the caller earlier. Native Node/injected `fs` implementations retain their own read behavior. Read text with `readFile(path, "utf8")`; see the [module methods](src/modules/fs.ts) and [filesystem package](../safe-fs/README.md). |
541
541
  | `makeEnvModule(namesOrOptions)` | Allowed-name array or `{ allow, values? }`; exposes `get(name)`. `parseEnvConfig(json)` accepts the object form. |
542
542
  | `makeTimeModule(options?)` | `now`, `random`, `seed`, `signal`; exposes `now`, `random`, `sleep`, `uuid`. Defaults to host time/randomness; `seed` makes the random generator deterministic, and explicit `random` takes precedence. |
543
- | `makeLogModule(sink)` | Sends timestamped `info`, `error`, and `event` entries to your callback. |
543
+ | `makeLogModule(sink)` | Sends timestamped `info`, `error`, and `event` entries to your callback; defaults to JSON lines on stdout, or console JSON when stdout is unavailable. |
544
544
  | `makeMetricModule(npmRunner)` | Runs `metric:<name>` through your callback; reads the final nonempty stdout line as a finite numeric score. |
545
545
  | `makeHarnessModule(frontmatter, meta)` | `meta` is `{ kind, version, filepath }`. Exposes `tasks`, `agents`, `meta`, and `applyConstraints`; prompt constraints come from frontmatter `principles` and `constraints`. |
546
546
  | `makeFailModule()` | Exposes a default function that throws a harness failure. No options. |
@@ -16,7 +16,8 @@ import {
16
16
  splitSourceLines
17
17
  } from "./chunk-5WP5IRMP.js";
18
18
  import {
19
- AsyncLocalStorage
19
+ AsyncLocalStorage,
20
+ hostCwd
20
21
  } from "./chunk-JCHJGIQA.js";
21
22
 
22
23
  // packages/safe-js/src/error/format.ts
@@ -1856,7 +1857,7 @@ function runObservedSpawn(moduleSink, input, operation) {
1856
1857
  }
1857
1858
  function readCurrentWorkingDirectory() {
1858
1859
  try {
1859
- return process.cwd();
1860
+ return hostCwd();
1860
1861
  } catch (error) {
1861
1862
  throw new Error(`Unable to resolve current working directory: ${formatSpawnError(error)}`);
1862
1863
  }
@@ -2542,7 +2543,7 @@ function makeEnvModule(input) {
2542
2543
  get(name) {
2543
2544
  const variable = readEnvName(name, "Environment variable name");
2544
2545
  if (!allowedNames.has(variable)) throw new EnvAccessError(variable);
2545
- return readEnvValue(values ?? process.env, variable);
2546
+ return readEnvValue(values ?? (typeof process !== "undefined" ? process.env ?? {} : {}), variable);
2546
2547
  }
2547
2548
  };
2548
2549
  }
@@ -2707,7 +2708,10 @@ function makeLogModule(sink = createJsonlStdoutSink()) {
2707
2708
  };
2708
2709
  }
2709
2710
  function createJsonlStdoutSink() {
2710
- const stream = process.stdout;
2711
+ const stream = typeof process !== "undefined" ? process.stdout : void 0;
2712
+ if (stream === void 0) {
2713
+ return (entry) => console.log(JSON.stringify(toJsonValue(entry, /* @__PURE__ */ new WeakSet())));
2714
+ }
2711
2715
  const existing = stdoutSinks.get(stream);
2712
2716
  if (existing) return existing;
2713
2717
  const brokenPipe = createBrokenPipeState();
@@ -12,7 +12,7 @@ import {
12
12
  parseFsConfig,
13
13
  resolveFsConfig,
14
14
  splitFrontmatter
15
- } from "./chunk-MKY3MQUB.js";
15
+ } from "./chunk-MZZ4GGSY.js";
16
16
  import {
17
17
  parseMcpConfig
18
18
  } from "./chunk-L3MIVH3T.js";
@@ -13,7 +13,7 @@ import path from "node:path";
13
13
  import { fileURLToPath } from "node:url";
14
14
  async function runCli(argv, options = {}) {
15
15
  if (!argv.includes("--help") && !argv.includes("-h")) {
16
- const runtime = await import("./chunks/cli-runtime-BGB24HNE.js");
16
+ const runtime = await import("./chunks/cli-runtime-5DZW4OP4.js");
17
17
  return runtime.runCli(argv, options, createUsage());
18
18
  }
19
19
  const brokenPipe = createBrokenPipeState();
@@ -32,7 +32,7 @@ async function runCli(argv, options = {}) {
32
32
  stderr.write(`${error instanceof Error ? error.message : String(error)}
33
33
  `);
34
34
  if (brokenPipe.closed) return 0;
35
- const { exitCodeForError } = await import("./chunks/cli-runtime-BGB24HNE.js");
35
+ const { exitCodeForError } = await import("./chunks/cli-runtime-5DZW4OP4.js");
36
36
  return exitCodeForError(error);
37
37
  }
38
38
  }
@@ -32,7 +32,7 @@ import {
32
32
  runWithSpawnUsageAccumulator,
33
33
  splitFrontmatter,
34
34
  supportsSpawnMode
35
- } from "./chunks/chunk-MKY3MQUB.js";
35
+ } from "./chunks/chunk-MZZ4GGSY.js";
36
36
  import {
37
37
  parseMcpConfig
38
38
  } from "./chunks/chunk-L3MIVH3T.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-js",
3
- "version": "0.1.745",
3
+ "version": "0.1.747",
4
4
  "description": "Budgeted JavaScript interpreter with explicit host capabilities and resumable execution",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@poe-platform/safe-fs": "0.1.745",
61
+ "@poe-platform/safe-fs": "0.1.747",
62
62
  "@petamoriken/float16": "^3.9.3",
63
63
  "@noble/hashes": "2.4.0",
64
64
  "@formatjs/intl-localematcher": "0.8.13",