fascicle 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.4.0 — 2026-05-07
4
+
5
+ ### Fixed
6
+ - `claude_cli` adapter: `build_env` now seeds the standard process-env keys (`PATH`, `HOME`, `SHELL`, `USER`, `LOGNAME`, `LANG`, `TMPDIR`) under every `auth_mode` (was: only inherited under `oauth`). Sandbox-enabled runs under `auto`/`api_key` previously spawned with an empty `PATH` and failed with `ENOENT` looking up `greywall`/`bwrap`. Set `inherit_env: false` to opt out of the standard-key seeding.
7
+ - `claude_cli` adapter: greywall sandbox plan now writes a temp settings JSON (`{ network: { allowHosts }, filesystem: { allowWrite } }`) and forwards `--settings <path>` instead of the removed `--allow-host`/`--rw` flags. greywall 0.3.0+ rejected the old flags as unknown and exited 1. Consumers managing their own settings file can pass `sandbox.settings_path` to skip the temp-file generation.
8
+ - `fascicle-viewer` CLI: replaced the fragile `argv[1].endsWith('/cli.ts'|'/cli.js')` self-execution guard with an `import.meta.url`-based check. The umbrella bundles `cli.ts` into `dist/index.js`, so any consumer whose entry script was named `cli.js` was accidentally hijacked into running the viewer at import time.
9
+
3
10
  ## v0.3.8 — 2026-05-06
4
11
 
5
12
  ### Fixed
package/dist/index.d.ts CHANGED
@@ -325,7 +325,7 @@ type CustomTrajectoryEvent = z.infer<typeof custom_event_schema>;
325
325
  type ParsedTrajectoryEvent = z.infer<typeof trajectory_event_schema>;
326
326
  //#endregion
327
327
  //#region packages/core/src/version.d.ts
328
- declare const version = "0.3.8";
328
+ declare const version = "0.4.0";
329
329
  //#endregion
330
330
  //#region packages/core/src/index.d.ts
331
331
  declare const flow_schema: {
@@ -977,7 +977,7 @@ declare function read_baseline(path: string): Promise<BenchReport>;
977
977
  declare function write_baseline(path: string, report: BenchReport): Promise<void>;
978
978
  //#endregion
979
979
  //#region packages/engine/src/version.d.ts
980
- declare const version$1 = "0.3.8";
980
+ declare const version$1 = "0.4.0";
981
981
  //#endregion
982
982
  //#region packages/engine/src/providers/claude_cli/types.d.ts
983
983
  /**
@@ -997,16 +997,26 @@ type SandboxProviderConfig = {
997
997
  readonly kind: 'greywall';
998
998
  readonly network_allowlist?: ReadonlyArray<string>;
999
999
  readonly additional_write_paths?: ReadonlyArray<string>;
1000
+ /**
1001
+ * greywall 0.3+ takes filesystem/network policy from a JSON settings
1002
+ * file. By default the adapter writes a temp settings file derived
1003
+ * from `network_allowlist`/`additional_write_paths`. Set to forward
1004
+ * a caller-managed settings file directly via `--settings` instead.
1005
+ * The temp-file path is then skipped entirely.
1006
+ */
1007
+ readonly settings_path?: string;
1000
1008
  };
1001
1009
  type ClaudeCliProviderConfig = {
1002
1010
  readonly binary?: string;
1003
1011
  readonly auth_mode?: AuthMode;
1004
1012
  readonly api_key?: string;
1005
1013
  /**
1006
- * Under `auth_mode: 'oauth'` the subprocess env seeds from `process.env`
1007
- * by default so it can reach the logged-in `claude` session. Set to
1008
- * `false` to opt out and start from an empty env (the api_key-mode
1009
- * default). Ignored outside oauth mode.
1014
+ * The subprocess env seeds the standard process-env keys
1015
+ * (PATH/HOME/SHELL/USER/LOGNAME/LANG/TMPDIR) by default under every
1016
+ * auth mode so the spawn target (sandbox wrapper or the claude binary)
1017
+ * can be resolved on PATH. Under `auth_mode: 'oauth'` the *full*
1018
+ * `process.env` is inherited so the CLI can reach the logged-in OAuth
1019
+ * session. Set to `false` to opt out and start from an empty env.
1010
1020
  */
1011
1021
  readonly inherit_env?: boolean;
1012
1022
  readonly default_cwd?: string;
package/dist/index.js CHANGED
@@ -2,7 +2,8 @@ import { createHash, randomUUID } from "node:crypto";
2
2
  import { z } from "zod";
3
3
  import { mkdir, open, readFile, readdir, stat, writeFile } from "node:fs/promises";
4
4
  import { dirname, join, resolve } from "node:path";
5
- import { appendFileSync, createReadStream, existsSync, mkdirSync, statSync, watch } from "node:fs";
5
+ import { appendFileSync, createReadStream, existsSync, mkdirSync, mkdtempSync, statSync, watch, writeFileSync } from "node:fs";
6
+ import { tmpdir } from "node:os";
6
7
  import { spawn } from "node:child_process";
7
8
  import { generateText, stepCountIs, streamText, tool } from "ai";
8
9
  import { createServer } from "node:http";
@@ -1949,7 +1950,7 @@ const trajectory_event_schema = z.union([
1949
1950
  ]);
1950
1951
  //#endregion
1951
1952
  //#region packages/core/src/version.ts
1952
- const version = "0.3.8";
1953
+ const version = "0.4.0";
1953
1954
  //#endregion
1954
1955
  //#region packages/core/src/index.ts
1955
1956
  /**
@@ -3204,7 +3205,7 @@ function validate_report(value, path) {
3204
3205
  }
3205
3206
  //#endregion
3206
3207
  //#region packages/engine/src/version.ts
3207
- const version$1 = "0.3.8";
3208
+ const version$1 = "0.4.0";
3208
3209
  //#endregion
3209
3210
  //#region packages/engine/src/errors.ts
3210
3211
  var rate_limit_error = class extends Error {
@@ -4053,17 +4054,38 @@ const DEFAULT_SETTING_SOURCES = Object.freeze(["project", "local"]);
4053
4054
  * Authentication enforcement for the claude_cli adapter (spec §4, §6.1).
4054
4055
  *
4055
4056
  * - build_env composes the subprocess env from config + caller overrides.
4056
- * Under `auth_mode: 'oauth'` it seeds from `process.env` (the CLI needs
4057
- * HOME/PATH to reach the logged-in session) unless `config.inherit_env`
4058
- * is explicitly `false`. Under 'api_key' and 'auto' it starts empty and
4059
- * only copies caller-supplied keys. Auth-mode scrub runs last on the
4060
- * merged result so nothing — caller env, inherited env, or config —
4061
- * can re-introduce ANTHROPIC_API_KEY under 'oauth'.
4057
+ * Regardless of auth_mode, it seeds the standard process-env keys
4058
+ * (PATH, HOME, SHELL, USER, LOGNAME, LANG, TMPDIR) so the spawned
4059
+ * subprocess can locate the sandbox wrapper (greywall/bwrap) and the
4060
+ * claude binary on PATH. Set `inherit_env: false` to opt out and start
4061
+ * from an empty env. Under oauth mode the *full* process.env is also
4062
+ * inherited (the CLI needs HOME/etc plus session-specific vars to reach
4063
+ * the logged-in OAuth session). Auth-mode scrub runs last on the merged
4064
+ * result so nothing — caller env, inherited env, or config — can
4065
+ * re-introduce ANTHROPIC_API_KEY under 'oauth'.
4062
4066
  * - validate_auth_config throws engine_config_error synchronously when
4063
4067
  * auth_mode === 'api_key' without a non-empty api_key.
4064
4068
  * - stderr_is_auth_failure matches captured stderr against the frozen
4065
4069
  * CLI_AUTH_ERROR_PATTERNS list, case-insensitively.
4066
4070
  */
4071
+ /**
4072
+ * Standard env keys forwarded from process.env so the spawn target
4073
+ * (greywall/bwrap on PATH, then `claude`) can be resolved and run.
4074
+ *
4075
+ * Mirrors `STANDARD_KEYS` in
4076
+ * packages/fascicle/src/forward_standard_env.ts. Keep the two lists in
4077
+ * sync; engine cannot import from fascicle (the umbrella depends on
4078
+ * engine, not the other way).
4079
+ */
4080
+ const STANDARD_ENV_KEYS = [
4081
+ "PATH",
4082
+ "HOME",
4083
+ "SHELL",
4084
+ "USER",
4085
+ "LOGNAME",
4086
+ "LANG",
4087
+ "TMPDIR"
4088
+ ];
4067
4089
  function validate_auth_config(config) {
4068
4090
  if ((config.auth_mode ?? "auto") === "api_key") {
4069
4091
  if ((typeof config.api_key === "string" ? config.api_key : "").length === 0) throw new engine_config_error("api_key is required for auth_mode: api_key", "claude_cli");
@@ -4071,8 +4093,11 @@ function validate_auth_config(config) {
4071
4093
  }
4072
4094
  function build_env(config, caller_env, auth_mode) {
4073
4095
  const env = {};
4074
- if (auth_mode === "oauth" && config.inherit_env !== false) {
4096
+ if (config.inherit_env !== false) if (auth_mode === "oauth") {
4075
4097
  for (const [k, v] of Object.entries(process.env)) if (typeof v === "string") env[k] = v;
4098
+ } else for (const key of STANDARD_ENV_KEYS) {
4099
+ const v = process.env[key];
4100
+ if (typeof v === "string") env[key] = v;
4076
4101
  }
4077
4102
  if (caller_env !== void 0) {
4078
4103
  for (const [k, v] of Object.entries(caller_env)) if (typeof v === "string") env[k] = v;
@@ -4135,6 +4160,31 @@ function merge_allowed_tools(call_allowlist, tool_names) {
4135
4160
  }
4136
4161
  //#endregion
4137
4162
  //#region packages/engine/src/providers/claude_cli/sandbox.ts
4163
+ /**
4164
+ * Sandbox wrapper for the claude_cli adapter (spec §5.1, F30).
4165
+ *
4166
+ * Builds the `{ spawn_cmd, prefix_args }` pair for bwrap and greywall. When no
4167
+ * sandbox is configured, returns { spawn_cmd: binary, prefix_args: [] } — the
4168
+ * caller then concatenates prefix_args before the CLI argv.
4169
+ *
4170
+ * Both wrappers allow the binary to execute while restricting network reach
4171
+ * to the allowlist and write access to additional paths on top of the
4172
+ * sandbox's default-read-only filesystem.
4173
+ *
4174
+ * greywall 0.3+ removed the `--allow-host` and `--rw` flags; policy now
4175
+ * lives in a JSON settings file passed via `--settings <path>`. Schema is
4176
+ * documented in `greywall --help`:
4177
+ *
4178
+ * {
4179
+ * "network": { "allowHosts": [...] },
4180
+ * "filesystem": { "allowWrite": [...] }
4181
+ * }
4182
+ *
4183
+ * `filesystem.allowWrite` is honored directly; `network.allowHosts` is
4184
+ * preserved for documentation/forward-compat (greywall ignores unknown
4185
+ * fields and host-level allowlisting is currently enforced at the
4186
+ * greyproxy layer).
4187
+ */
4138
4188
  function build_sandbox_plan(binary, sandbox) {
4139
4189
  if (sandbox === void 0) return {
4140
4190
  spawn_cmd: binary,
@@ -4177,14 +4227,21 @@ function build_bwrap_args(binary, sandbox) {
4177
4227
  return args;
4178
4228
  }
4179
4229
  function build_greywall_args(binary, sandbox) {
4180
- const args = [];
4181
- const allowlist = sandbox.network_allowlist ?? [];
4182
- for (const host of allowlist) args.push("--allow-host", host);
4183
- const write_paths = sandbox.additional_write_paths ?? [];
4184
- for (const p of write_paths) args.push("--rw", p);
4185
- args.push("--");
4186
- args.push(binary);
4187
- return args;
4230
+ return [
4231
+ "--settings",
4232
+ sandbox.settings_path ?? write_greywall_settings(sandbox),
4233
+ "--",
4234
+ binary
4235
+ ];
4236
+ }
4237
+ function write_greywall_settings(sandbox) {
4238
+ const path = join(mkdtempSync(join(tmpdir(), `fascicle-greywall-${process.pid}-`)), "greywall.json");
4239
+ const payload = {
4240
+ network: { allowHosts: [...sandbox.network_allowlist ?? []] },
4241
+ filesystem: { allowWrite: [...sandbox.additional_write_paths ?? []] }
4242
+ };
4243
+ writeFileSync(path, JSON.stringify(payload, null, 2), "utf8");
4244
+ return path;
4188
4245
  }
4189
4246
  //#endregion
4190
4247
  //#region packages/engine/src/providers/claude_cli/spawn.ts
@@ -7192,7 +7249,7 @@ function describe_error(err) {
7192
7249
  return String(err);
7193
7250
  }
7194
7251
  }
7195
- if (typeof process.argv[1] === "string" && (process.argv[1].endsWith("/cli.ts") || process.argv[1].endsWith("/cli.js"))) run_viewer_cli(process.argv.slice(2)).catch((err) => {
7252
+ if (process.argv[1] !== void 0 && process.argv[1] === fileURLToPath(import.meta.url)) run_viewer_cli(process.argv.slice(2)).catch((err) => {
7196
7253
  process.stderr.write(`fascicle-viewer: ${describe_error(err)}\n`);
7197
7254
  process.exit(1);
7198
7255
  });