pi-landstrip 0.20.20 → 0.20.22

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 (2) hide show
  1. package/dist/index.ts +286 -267
  2. package/package.json +6 -2
package/dist/index.ts CHANGED
@@ -12,13 +12,13 @@ import {
12
12
  } from "node:fs";
13
13
  import { createServer, Socket as NetSocket } from "node:net";
14
14
  import { tmpdir as tmpdir2 } from "node:os";
15
- import { dirname as dirname5, isAbsolute as isAbsolute4, join as join8, parse, resolve as resolve4 } from "node:path";
15
+ import { dirname as dirname5, isAbsolute as isAbsolute4, join as join8, parse as parse2, resolve as resolve4 } from "node:path";
16
16
  import { StringDecoder as StringDecoder3 } from "node:string_decoder";
17
17
  import { fileURLToPath as fileURLToPath2 } from "node:url";
18
+ import { quote as quoteShell } from "shell-quote";
18
19
  import {
19
20
  createBashToolDefinition,
20
21
  createLocalBashOperations,
21
- getAgentDir as getAgentDir5,
22
22
  getShellConfig,
23
23
  SettingsManager as SettingsManager2,
24
24
  withFileMutationQueue as withFileMutationQueue3
@@ -248,6 +248,7 @@ import {
248
248
  import { homedir as homedir3, tmpdir } from "node:os";
249
249
  import { basename as basename2, dirname as dirname4, isAbsolute as isAbsolute3, join as join7, relative as relative3, resolve as resolve3, sep as sep4 } from "node:path";
250
250
  import { fileURLToPath } from "node:url";
251
+ import { gte, parse, valid } from "semver";
251
252
  import {
252
253
  getAgentDir as getAgentDir4,
253
254
  keyHint,
@@ -438,22 +439,10 @@ class AsyncQueue {
438
439
  }
439
440
  function combineAbortSignals(...sources) {
440
441
  const signals = sources.filter((source) => source !== undefined);
441
- const only = signals[0];
442
- if (signals.length === 1 && only)
443
- return { signal: only, dispose: () => {
444
- return;
445
- } };
446
- const controller = new AbortController;
447
- const abort = () => controller.abort();
448
- for (const signal of signals)
449
- signal.addEventListener("abort", abort, { once: true });
450
- if (signals.some((signal) => signal.aborted))
451
- controller.abort();
452
442
  return {
453
- signal: controller.signal,
443
+ signal: signals.length === 1 ? signals[0] : AbortSignal.any(signals),
454
444
  dispose: () => {
455
- for (const signal of signals)
456
- signal.removeEventListener("abort", abort);
445
+ return;
457
446
  }
458
447
  };
459
448
  }
@@ -2545,22 +2534,15 @@ var AGENTS_HELP_ROWS = [
2545
2534
  ["Backspace", "Open parent task"]
2546
2535
  ];
2547
2536
  var INHERIT = "inherit";
2548
- var MIN_SUPPORTED_PI_VERSION = [0, 82, 0];
2537
+ var MIN_SUPPORTED_PI_VERSION = "0.82.0";
2549
2538
  var cachedPiPackage;
2550
2539
  var piPackageResolved = false;
2551
2540
  function isSupportedPiVersion(version) {
2552
2541
  if (version.length !== 3 || !version.every((part) => Number.isInteger(part) && part >= 0)) {
2553
2542
  return false;
2554
2543
  }
2555
- for (let i = 0;i < 3; i++) {
2556
- const part = version[i];
2557
- const min = MIN_SUPPORTED_PI_VERSION[i];
2558
- if (part > min)
2559
- return true;
2560
- if (part < min)
2561
- return false;
2562
- }
2563
- return true;
2544
+ const parsed = valid(version.join("."));
2545
+ return parsed !== null && gte(parsed, MIN_SUPPORTED_PI_VERSION);
2564
2546
  }
2565
2547
  function findPiPackage(entry) {
2566
2548
  let dir = dirname4(realpathSync2(entry));
@@ -2601,8 +2583,8 @@ function readPiPackage(pkgPath) {
2601
2583
  if (!isRecord2(value) || value.name !== "@earendil-works/pi-coding-agent" || typeof value.version !== "string") {
2602
2584
  return;
2603
2585
  }
2604
- const parts = value.version.split(".").map(Number);
2605
- if (parts.length < 3 || !parts.slice(0, 3).every((n) => Number.isInteger(n)))
2586
+ const version = parse(value.version);
2587
+ if (!version || version.prerelease.length > 0)
2606
2588
  return;
2607
2589
  const binFile = typeof value.bin === "string" ? value.bin : isRecord2(value.bin) && typeof value.bin.pi === "string" ? value.bin.pi : undefined;
2608
2590
  if (!binFile)
@@ -2610,7 +2592,7 @@ function readPiPackage(pkgPath) {
2610
2592
  const cliEntry = join7(dirname4(pkgPath), binFile);
2611
2593
  if (!existsSync5(cliEntry))
2612
2594
  return;
2613
- cachedPiPackage = { cliEntry, version: parts.slice(0, 3) };
2595
+ cachedPiPackage = { cliEntry, version: [version.major, version.minor, version.patch] };
2614
2596
  return cachedPiPackage;
2615
2597
  } catch {
2616
2598
  return;
@@ -6273,22 +6255,201 @@ var NETWORK_PERMISSION_OPTIONS = [
6273
6255
  { label: "Allow for this session", action: "session" },
6274
6256
  { label: "Keep blocked", action: "abort" }
6275
6257
  ];
6276
- function loadSandboxConfig(cwd, includeProject) {
6277
- const projectConfigPath = join8(cwd, ".pi", "sandbox.json");
6278
- const globalConfigPath = join8(getAgentDir5(), "sandbox.json");
6279
- if (!existsSync6(globalConfigPath)) {
6280
- mkdirSync4(dirname5(globalConfigPath), { recursive: true });
6281
- writeFileSync4(globalConfigPath, `{}
6258
+
6259
+ class SandboxConfigStore {
6260
+ globalPath;
6261
+ projectPath;
6262
+ constructor(cwd) {
6263
+ const { globalPath, projectPath } = getPiConfigPaths(cwd, "sandbox.json");
6264
+ this.globalPath = globalPath;
6265
+ this.projectPath = projectPath;
6266
+ }
6267
+ static readOrEmpty(configPath) {
6268
+ if (!existsSync6(configPath))
6269
+ return {};
6270
+ try {
6271
+ return parseSandboxConfig(JSON.parse(readFileSync7(configPath, "utf-8")));
6272
+ } catch (error) {
6273
+ throw new Error(`${configPath}: ${formatError(error)}`);
6274
+ }
6275
+ }
6276
+ static write(configPath, config) {
6277
+ mkdirSync4(dirname5(configPath), { recursive: true });
6278
+ writeFileSync4(configPath, `${JSON.stringify(config, null, 2)}
6282
6279
  `, "utf-8");
6283
6280
  }
6284
- const globalOverrides = readOrEmptyConfig(globalConfigPath);
6285
- const projectOverrides = includeProject ? readOrEmptyConfig(projectConfigPath) : {};
6286
- const globalConfig = deepMerge(JSON.parse(readFileSync7(join8(packageDir2, "sandbox.json"), "utf-8")), globalOverrides);
6287
- return {
6288
- ...deepMerge(globalConfig, projectOverrides),
6289
- explicitDenyRead: mergeArray(globalOverrides.filesystem?.denyRead ?? [], projectOverrides.filesystem?.denyRead),
6290
- explicitAllowRead: mergeArray(globalOverrides.filesystem?.allowRead ?? [], projectOverrides.filesystem?.allowRead)
6291
- };
6281
+ static appendGrant(config, field, value) {
6282
+ switch (field) {
6283
+ case "allowedDomains": {
6284
+ const existing = config.network?.allowedDomains ?? [];
6285
+ if (existing.includes(value))
6286
+ return false;
6287
+ config.network = {
6288
+ ...config.network,
6289
+ allowedDomains: [...existing, value],
6290
+ deniedDomains: config.network?.deniedDomains ?? []
6291
+ };
6292
+ return true;
6293
+ }
6294
+ case "allowUnixSockets": {
6295
+ const existing = config.network?.allowUnixSockets ?? [];
6296
+ if (existing.includes(value))
6297
+ return false;
6298
+ config.network = { ...config.network, allowUnixSockets: [...existing, value] };
6299
+ return true;
6300
+ }
6301
+ case "allowRead": {
6302
+ const existing = config.filesystem?.allowRead ?? [];
6303
+ if (existing.includes(value))
6304
+ return false;
6305
+ config.filesystem = { ...config.filesystem, allowRead: [...existing, value] };
6306
+ return true;
6307
+ }
6308
+ case "allowWrite": {
6309
+ const existing = config.filesystem?.allowWrite ?? [];
6310
+ if (existing.includes(value))
6311
+ return false;
6312
+ config.filesystem = { ...config.filesystem, allowWrite: [...existing, value] };
6313
+ return true;
6314
+ }
6315
+ }
6316
+ }
6317
+ changeScope(includeProject) {
6318
+ return includeProject ? "project" : "global";
6319
+ }
6320
+ load(includeProject) {
6321
+ if (!existsSync6(this.globalPath)) {
6322
+ mkdirSync4(dirname5(this.globalPath), { recursive: true });
6323
+ writeFileSync4(this.globalPath, `{}
6324
+ `, "utf-8");
6325
+ }
6326
+ const globalOverrides = SandboxConfigStore.readOrEmpty(this.globalPath);
6327
+ const projectOverrides = includeProject ? SandboxConfigStore.readOrEmpty(this.projectPath) : {};
6328
+ const globalConfig = deepMerge(JSON.parse(readFileSync7(join8(packageDir2, "sandbox.json"), "utf-8")), globalOverrides);
6329
+ return {
6330
+ ...deepMerge(globalConfig, projectOverrides),
6331
+ explicitDenyRead: mergeArray(globalOverrides.filesystem?.denyRead ?? [], projectOverrides.filesystem?.denyRead),
6332
+ explicitAllowRead: mergeArray(globalOverrides.filesystem?.allowRead ?? [], projectOverrides.filesystem?.allowRead)
6333
+ };
6334
+ }
6335
+ enabledSettings(includeProject) {
6336
+ const global = this.load(false).enabled;
6337
+ if (!includeProject || !existsSync6(this.projectPath))
6338
+ return { global };
6339
+ const project = SandboxConfigStore.readOrEmpty(this.projectPath).enabled;
6340
+ return { global, project };
6341
+ }
6342
+ async setEnabled(scope, enabled) {
6343
+ const path = scope === "project" ? this.projectPath : this.globalPath;
6344
+ await withFileMutationQueue3(path, async () => {
6345
+ const config = SandboxConfigStore.readOrEmpty(path);
6346
+ if (enabled === undefined)
6347
+ delete config.enabled;
6348
+ else
6349
+ config.enabled = enabled;
6350
+ SandboxConfigStore.write(path, config);
6351
+ });
6352
+ }
6353
+ async persistGrant(choice, includeProject, field, values) {
6354
+ const configPath = choice === "global" ? this.globalPath : choice === "project" && includeProject ? this.projectPath : undefined;
6355
+ if (!configPath)
6356
+ return;
6357
+ for (const value of values) {
6358
+ await withFileMutationQueue3(configPath, async () => {
6359
+ const config = SandboxConfigStore.readOrEmpty(configPath);
6360
+ if (!SandboxConfigStore.appendGrant(config, field, value))
6361
+ return;
6362
+ SandboxConfigStore.write(configPath, config);
6363
+ });
6364
+ }
6365
+ }
6366
+ }
6367
+
6368
+ class SessionGrants {
6369
+ domains = [];
6370
+ readPaths = [];
6371
+ writePaths = [];
6372
+ unixSockets = [];
6373
+ targets = [];
6374
+ static addUnique(target, value) {
6375
+ if (target && !target.includes(value))
6376
+ target.push(value);
6377
+ }
6378
+ reset() {
6379
+ this.domains.length = 0;
6380
+ this.readPaths.length = 0;
6381
+ this.writePaths.length = 0;
6382
+ this.unixSockets.length = 0;
6383
+ this.targets.length = 0;
6384
+ }
6385
+ overview() {
6386
+ return {
6387
+ sessionDomains: [...this.domains],
6388
+ sessionReadPaths: [...this.readPaths],
6389
+ sessionWritePaths: [...this.writePaths]
6390
+ };
6391
+ }
6392
+ domainOverrides(allowances) {
6393
+ return [...new Set([...this.domains, ...allowances?.domains ?? []])];
6394
+ }
6395
+ effectiveUnixSockets(base) {
6396
+ return [...new Set([...base, ...this.unixSockets])];
6397
+ }
6398
+ effectiveAllowRead(config, cwd, allowances) {
6399
+ const paths = [
6400
+ ...new Set([
6401
+ ...config.filesystem.allowRead,
6402
+ ...this.readPaths,
6403
+ ...allowances?.readPaths ?? []
6404
+ ])
6405
+ ];
6406
+ if (process.platform !== "win32")
6407
+ return paths;
6408
+ return paths.filter((path) => !path.startsWith("/") && (path.includes("*") || existsSync6(expandPath(path, cwd))));
6409
+ }
6410
+ effectiveAllowWrite(config, allowances) {
6411
+ const paths = [
6412
+ ...new Set([
6413
+ ...config.filesystem.allowWrite,
6414
+ ...this.writePaths,
6415
+ ...allowances?.writePaths ?? []
6416
+ ])
6417
+ ];
6418
+ return process.platform === "win32" ? paths.filter((path) => !path.startsWith("/")) : paths;
6419
+ }
6420
+ explicitAllowRead(base, approvedPaths) {
6421
+ return mergeArray(base, [...this.readPaths, ...approvedPaths]);
6422
+ }
6423
+ hasTarget(key, allowances) {
6424
+ return this.targets.includes(key) || allowances.targets.includes(key);
6425
+ }
6426
+ grantDomain(choice, domain, allowances) {
6427
+ SessionGrants.addUnique(choice === "once" ? allowances?.domains : this.domains, domain);
6428
+ }
6429
+ grantTarget(choice, key, allowances) {
6430
+ SessionGrants.addUnique(choice === "once" ? allowances.targets : this.targets, key);
6431
+ }
6432
+ grantUnixSocket(choice, socketPath, key, allowances) {
6433
+ if (choice === "once") {
6434
+ SessionGrants.addUnique(allowances?.targets, key);
6435
+ return;
6436
+ }
6437
+ SessionGrants.addUnique(this.unixSockets, socketPath);
6438
+ SessionGrants.addUnique(this.targets, key);
6439
+ }
6440
+ grantRead(choice, scopes, allowances) {
6441
+ const target = choice === "once" ? allowances?.readPaths : this.readPaths;
6442
+ for (const entry of scopes) {
6443
+ SessionGrants.addUnique(target, entry);
6444
+ SessionGrants.addUnique(allowances?.explicitDenyRead?.approvedPaths, entry);
6445
+ }
6446
+ }
6447
+ grantWrite(choice, scopes, allowances) {
6448
+ const target = choice === "once" ? allowances?.writePaths : this.writePaths;
6449
+ for (const entry of scopes) {
6450
+ SessionGrants.addUnique(target, entry);
6451
+ }
6452
+ }
6292
6453
  }
6293
6454
  function windowsStatus() {
6294
6455
  const result = spawnSync(binaryPath(), ["windows", "status"], {
@@ -6324,57 +6485,6 @@ function restrictedUserProxyPortRange() {
6324
6485
  }
6325
6486
  return { low: status.proxyPortLow, high: status.proxyPortHigh };
6326
6487
  }
6327
- function readOrEmptyConfig(configPath) {
6328
- if (!existsSync6(configPath))
6329
- return {};
6330
- try {
6331
- return parseSandboxConfig(JSON.parse(readFileSync7(configPath, "utf-8")));
6332
- } catch (error) {
6333
- throw new Error(`${configPath}: ${formatError(error)}`);
6334
- }
6335
- }
6336
- function writeConfigFile(configPath, config) {
6337
- mkdirSync4(dirname5(configPath), { recursive: true });
6338
- writeFileSync4(configPath, `${JSON.stringify(config, null, 2)}
6339
- `, "utf-8");
6340
- }
6341
- function getSandboxConfigWriteTarget(cwd, includeProject = true) {
6342
- const { globalPath, projectPath } = getPiConfigPaths(cwd, "sandbox.json");
6343
- return includeProject ? { scope: "project", path: projectPath } : { scope: "global", path: globalPath };
6344
- }
6345
- async function writeSandboxConfigEnabled(cwd, enabled, scope) {
6346
- const paths = getPiConfigPaths(cwd, "sandbox.json");
6347
- const path = scope === "project" ? paths.projectPath : paths.globalPath;
6348
- await withFileMutationQueue3(path, async () => {
6349
- const config = readOrEmptyConfig(path);
6350
- if (enabled === undefined)
6351
- delete config.enabled;
6352
- else
6353
- config.enabled = enabled;
6354
- writeConfigFile(path, config);
6355
- });
6356
- }
6357
- function loadSandboxEnabledSettings(cwd, includeProject) {
6358
- const { projectPath } = getPiConfigPaths(cwd, "sandbox.json");
6359
- const global = loadSandboxConfig(cwd, false).enabled;
6360
- if (!includeProject || !existsSync6(projectPath))
6361
- return { global };
6362
- const project = readOrEmptyConfig(projectPath).enabled;
6363
- return { global, project };
6364
- }
6365
- async function addConfigValue(configPath, value, readValues, writeValues) {
6366
- await withFileMutationQueue3(configPath, async () => {
6367
- const config = readOrEmptyConfig(configPath);
6368
- const existing = readValues(config);
6369
- if (existing.includes(value))
6370
- return;
6371
- writeValues(config, [...existing, value]);
6372
- writeConfigFile(configPath, config);
6373
- });
6374
- }
6375
- function mergeAllowances(base, session, execution) {
6376
- return [...base, ...session, ...execution ?? []];
6377
- }
6378
6488
  function matchesPattern(filePath, patterns, cwd, explicitDenyGlobRoots) {
6379
6489
  if (!explicitDenyGlobRoots) {
6380
6490
  return matchesPathPattern(filePath, patterns, cwd);
@@ -6541,12 +6651,9 @@ ${option.hint ?? "This changes persisted sandbox policy."}`, { signal });
6541
6651
  }
6542
6652
  return option.action;
6543
6653
  }
6544
- function promptReadBlock(ctx, filePath, reason, signal, label) {
6545
- const title = reason ? `Read blocked: "${filePath}" is in denyRead (${reason})` : `Read blocked: "${filePath}" is not in allowRead`;
6546
- return showPermissionPrompt(ctx, title, permissionOptionsFor(ctx), signal, label);
6547
- }
6548
- function promptWriteBlock(ctx, filePath, reason, signal, label) {
6549
- const title = reason ? `Write blocked: "${filePath}" is in denyWrite (${reason})` : `Write blocked: "${filePath}" is not in allowWrite`;
6654
+ function promptFilesystemBlock(ctx, operation, filePath, reason, signal, label) {
6655
+ const [verb, denyField, allowField] = operation === "read" ? ["Read", "denyRead", "allowRead"] : ["Write", "denyWrite", "allowWrite"];
6656
+ const title = reason ? `${verb} blocked: "${filePath}" is in ${denyField} (${reason})` : `${verb} blocked: "${filePath}" is not in ${allowField}`;
6550
6657
  return showPermissionPrompt(ctx, title, permissionOptionsFor(ctx), signal, label);
6551
6658
  }
6552
6659
  function writeEnvFile(env, proxyPort, proxyToken) {
@@ -6556,13 +6663,14 @@ function writeEnvFile(env, proxyPort, proxyToken) {
6556
6663
  continue;
6557
6664
  if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))
6558
6665
  continue;
6559
- const escaped = value.replace(/'/g, "'\\''");
6560
- lines.push(`export ${key}='${escaped}'`);
6666
+ lines.push(`export ${key}=${quoteShell([value])}`);
6561
6667
  }
6562
6668
  if (proxyPort !== null) {
6563
6669
  const proxyVars = createProxyEnvironment(proxyPort, { token: proxyToken });
6564
6670
  for (const [name, value] of Object.entries(proxyVars)) {
6565
- lines.push(`export ${name}='${value}'`);
6671
+ if (value === undefined)
6672
+ continue;
6673
+ lines.push(`export ${name}=${quoteShell([value])}`);
6566
6674
  }
6567
6675
  }
6568
6676
  const dir = mkdtempSync2(join8(tmpdir2(), "pi-landstrip-env-"));
@@ -6583,7 +6691,7 @@ function createPosixShellProvider() {
6583
6691
  let disposed = false;
6584
6692
  return {
6585
6693
  executable: shell,
6586
- args: [...args, `source '${envFile.path}' && ${options.command}`],
6694
+ args: [...args, `source ${quoteShell([envFile.path])} && ${options.command}`],
6587
6695
  launcherEnv: { PATH: process.env.PATH, HOME: process.env.HOME },
6588
6696
  readPaths: [envFile.path],
6589
6697
  dispose() {
@@ -6648,7 +6756,7 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
6648
6756
  return ctx ? isProjectTrusted(ctx) : projectConfigTrusted;
6649
6757
  }
6650
6758
  function loadConfig(cwd, ctx = activeContext) {
6651
- return loadSandboxConfig(cwd, isProjectConfigTrusted(ctx));
6759
+ return new SandboxConfigStore(cwd).load(isProjectConfigTrusted(ctx));
6652
6760
  }
6653
6761
  let sandboxEnabled = false;
6654
6762
  let sandboxReady = false;
@@ -6661,11 +6769,7 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
6661
6769
  let externalPermissionAskProvider;
6662
6770
  const eventHandlers = new Set;
6663
6771
  const workerExtensions = new Map;
6664
- const sessionAllowedDomains = [];
6665
- const sessionAllowedReadPaths = [];
6666
- const sessionAllowedWritePaths = [];
6667
- const sessionAllowedUnixSockets = [];
6668
- const sessionAllowedTargets = [];
6772
+ const sessionGrants = new SessionGrants;
6669
6773
  function getContext(ctx = activeContext) {
6670
6774
  return {
6671
6775
  version: LANDSTRIP_RUNTIME_VERSION,
@@ -6786,20 +6890,10 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
6786
6890
  function getWorkerExtensions() {
6787
6891
  return [...workerExtensions].map(([id, extension]) => ({ id, entry: extension.entry }));
6788
6892
  }
6789
- function getEffectiveAllowRead(config, cwd, allowances) {
6790
- const paths = mergeAllowances(config.filesystem.allowRead, sessionAllowedReadPaths, allowances?.readPaths);
6791
- if (process.platform !== "win32")
6792
- return paths;
6793
- return paths.filter((path) => !path.startsWith("/") && (path.includes("*") || existsSync6(expandPath(path, cwd))));
6794
- }
6795
- function getEffectiveAllowWrite(config, allowances) {
6796
- const paths = mergeAllowances(config.filesystem.allowWrite, sessionAllowedWritePaths, allowances?.writePaths);
6797
- return process.platform === "win32" ? paths.filter((path) => !path.startsWith("/")) : paths;
6798
- }
6799
6893
  function getEffectiveDenyRead(config, cwd) {
6800
6894
  if (process.platform !== "win32")
6801
6895
  return config.filesystem.denyRead;
6802
- const volumeRoot = parse(resolve4(cwd)).root;
6896
+ const volumeRoot = parse2(resolve4(cwd)).root;
6803
6897
  return createWindowsDenyRead(config.filesystem.denyRead, volumeRoot);
6804
6898
  }
6805
6899
  function hasBaselineWindowsApplicationAccess(filePath) {
@@ -6826,47 +6920,13 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
6826
6920
  readPaths: [...new Set([...allowances.readPaths, ...executablePaths, ...additionalPaths])]
6827
6921
  };
6828
6922
  }
6829
- function resolvePersistedConfigPath(cwd, choice, ctx = activeContext) {
6830
- const { globalPath, projectPath } = getPiConfigPaths(cwd, "sandbox.json");
6831
- if (choice === "project") {
6832
- return isProjectConfigTrusted(ctx) ? projectPath : undefined;
6833
- }
6834
- if (choice === "global")
6835
- return globalPath;
6836
- return;
6837
- }
6838
6923
  async function applyDomainChoice(ctx, choice, domain, cwd, allowances) {
6839
- const configPath = resolvePersistedConfigPath(cwd, choice, ctx);
6840
- if (configPath) {
6841
- await addConfigValue(configPath, domain, (config) => config.network?.allowedDomains ?? [], (config, allowedDomains) => {
6842
- config.network = {
6843
- ...config.network,
6844
- allowedDomains,
6845
- deniedDomains: config.network?.deniedDomains ?? []
6846
- };
6847
- });
6848
- }
6849
- const target = choice === "once" ? allowances?.domains : sessionAllowedDomains;
6850
- if (target && !target.includes(domain))
6851
- target.push(domain);
6924
+ await new SandboxConfigStore(cwd).persistGrant(choice, isProjectConfigTrusted(ctx), "allowedDomains", [domain]);
6925
+ sessionGrants.grantDomain(choice, domain, allowances);
6852
6926
  }
6853
6927
  async function applyUnixSocketChoice(ctx, choice, socketPath, key, cwd, allowances) {
6854
- const configPath = resolvePersistedConfigPath(cwd, choice, ctx);
6855
- if (configPath) {
6856
- await addConfigValue(configPath, socketPath, (config) => config.network?.allowUnixSockets ?? [], (config, allowUnixSockets) => {
6857
- config.network = { ...config.network, allowUnixSockets };
6858
- });
6859
- }
6860
- if (choice === "once") {
6861
- if (allowances && !allowances.targets.includes(key))
6862
- allowances.targets.push(key);
6863
- } else {
6864
- if (!sessionAllowedUnixSockets.includes(socketPath)) {
6865
- sessionAllowedUnixSockets.push(socketPath);
6866
- }
6867
- if (!sessionAllowedTargets.includes(key))
6868
- sessionAllowedTargets.push(key);
6869
- }
6928
+ await new SandboxConfigStore(cwd).persistGrant(choice, isProjectConfigTrusted(ctx), "allowUnixSockets", [socketPath]);
6929
+ sessionGrants.grantUnixSocket(choice, socketPath, key, allowances);
6870
6930
  }
6871
6931
  function noteScope(ctx, verb, choice, filePath, scopes) {
6872
6932
  if (scopes.length !== 1 || scopes[0] !== filePath) {
@@ -6879,39 +6939,16 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
6879
6939
  ...allowances.explicitDenyRead.patterns,
6880
6940
  ...[...allowances.explicitDenyRead.globRoots.values()].flat()
6881
6941
  ]) : config.filesystem.denyRead;
6882
- const scopes = readGrantScopesFor(filePath, getEffectiveAllowRead(config, cwd, allowances), effectiveDenyRead, cwd, scope);
6883
- const configPath = resolvePersistedConfigPath(cwd, choice, ctx);
6884
- if (configPath) {
6885
- for (const entry of scopes) {
6886
- await addConfigValue(configPath, entry, (cfg) => cfg.filesystem?.allowRead ?? [], (cfg, allowRead) => {
6887
- cfg.filesystem = { ...cfg.filesystem, allowRead };
6888
- });
6889
- }
6890
- }
6891
- const target = choice === "once" ? allowances?.readPaths : sessionAllowedReadPaths;
6892
- for (const entry of scopes) {
6893
- if (target && !target.includes(entry))
6894
- target.push(entry);
6895
- allowances?.explicitDenyRead?.approvedPaths.push(entry);
6896
- }
6942
+ const scopes = readGrantScopesFor(filePath, sessionGrants.effectiveAllowRead(config, cwd, allowances), effectiveDenyRead, cwd, scope);
6943
+ await new SandboxConfigStore(cwd).persistGrant(choice, isProjectConfigTrusted(ctx), "allowRead", scopes);
6944
+ sessionGrants.grantRead(choice, scopes, allowances);
6897
6945
  noteScope(ctx, "Read", choice, filePath, scopes);
6898
6946
  }
6899
6947
  async function applyWriteChoice(ctx, choice, filePath, cwd, allowances) {
6900
6948
  const config = loadConfig(cwd, ctx);
6901
- const scopes = writeGrantScopesFor(filePath, getEffectiveAllowWrite(config, allowances), config.filesystem.denyWrite, cwd);
6902
- const configPath = resolvePersistedConfigPath(cwd, choice, ctx);
6903
- if (configPath) {
6904
- for (const entry of scopes) {
6905
- await addConfigValue(configPath, entry, (cfg) => cfg.filesystem?.allowWrite ?? [], (cfg, allowWrite) => {
6906
- cfg.filesystem = { ...cfg.filesystem, allowWrite };
6907
- });
6908
- }
6909
- }
6910
- const target = choice === "once" ? allowances?.writePaths : sessionAllowedWritePaths;
6911
- for (const entry of scopes) {
6912
- if (target && !target.includes(entry))
6913
- target.push(entry);
6914
- }
6949
+ const scopes = writeGrantScopesFor(filePath, sessionGrants.effectiveAllowWrite(config, allowances), config.filesystem.denyWrite, cwd);
6950
+ await new SandboxConfigStore(cwd).persistGrant(choice, isProjectConfigTrusted(ctx), "allowWrite", scopes);
6951
+ sessionGrants.grantWrite(choice, scopes, allowances);
6915
6952
  noteScope(ctx, "Write", choice, filePath, scopes);
6916
6953
  }
6917
6954
  async function authorizeFilesystemToolAccess(ctx, accesses, options = {}) {
@@ -6925,14 +6962,14 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
6925
6962
  return { allowed: true, prompted: false };
6926
6963
  const blockedAccesses = (config) => {
6927
6964
  const enforceReads = enforcesShellReadPolicy(config.shell.readAccess);
6928
- return normalized.filter((access) => access.operation === "read" ? enforceReads && !readAllowed(access.path, getEffectiveAllowRead(config, ctx.cwd), getEffectiveDenyRead(config, ctx.cwd), ctx.cwd) : shouldPromptForWrite(access.path, getEffectiveAllowWrite(config), config.filesystem.denyWrite, ctx.cwd));
6965
+ return normalized.filter((access) => access.operation === "read" ? enforceReads && !readAllowed(access.path, sessionGrants.effectiveAllowRead(config, ctx.cwd), getEffectiveDenyRead(config, ctx.cwd), ctx.cwd) : shouldPromptForWrite(access.path, sessionGrants.effectiveAllowWrite(config), config.filesystem.denyWrite, ctx.cwd));
6929
6966
  };
6930
6967
  const current = () => {
6931
6968
  const config = loadConfig(ctx.cwd, ctx);
6932
6969
  if (!config.enabled)
6933
6970
  return { allowed: true, prompted: false };
6934
6971
  for (const access of normalized) {
6935
- const denied = access.operation === "read" ? matchesPattern(access.path, config.filesystem.denyReadAlways, ctx.cwd) : matchesWriteDenyPattern(access.path, config.filesystem.denyWriteAlways, ctx.cwd, getEffectiveAllowWrite(config));
6972
+ const denied = access.operation === "read" ? matchesPattern(access.path, config.filesystem.denyReadAlways, ctx.cwd) : matchesWriteDenyPattern(access.path, config.filesystem.denyWriteAlways, ctx.cwd, sessionGrants.effectiveAllowWrite(config));
6936
6973
  if (denied) {
6937
6974
  return {
6938
6975
  allowed: false,
@@ -6943,11 +6980,12 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
6943
6980
  }
6944
6981
  return blockedAccesses(config).length === 0 ? { allowed: true, prompted: false } : undefined;
6945
6982
  };
6946
- const existing = current();
6947
- if (existing)
6948
- return existing;
6949
6983
  if (!ctx.hasUI) {
6950
- return { allowed: false, prompted: false, reason: "Filesystem access requires approval" };
6984
+ return current() ?? {
6985
+ allowed: false,
6986
+ prompted: false,
6987
+ reason: "Filesystem access requires approval"
6988
+ };
6951
6989
  }
6952
6990
  return permissionPrompts.resolve(current, async (promptSignal) => {
6953
6991
  const blocked = blockedAccesses(loadConfig(ctx.cwd, ctx));
@@ -6975,7 +7013,7 @@ ${paths}${note}`, permissionOptionsFor(ctx), promptSignal);
6975
7013
  const current = () => {
6976
7014
  const config = loadConfig(cwd, ctx);
6977
7015
  const decision = evaluateDomainAccess(domain, config.network, {
6978
- allowedDomainsOverrides: [...sessionAllowedDomains, ...allowances?.domains ?? []]
7016
+ allowedDomainsOverrides: sessionGrants.domainOverrides(allowances)
6979
7017
  });
6980
7018
  if (decision === "deny")
6981
7019
  return false;
@@ -6998,16 +7036,16 @@ ${paths}${note}`, permissionOptionsFor(ctx), promptSignal);
6998
7036
  const readPolicy = resolveProcessReadPolicy(audience, config.shell.readAccess, mergeArray(getEffectiveDenyRead(config, cwd), [
6999
7037
  ...allowances?.explicitDenyRead?.patterns ?? [],
7000
7038
  ...[...allowances?.explicitDenyRead?.globRoots.values() ?? []].flat()
7001
- ]), getEffectiveAllowRead(config, cwd, allowances));
7039
+ ]), sessionGrants.effectiveAllowRead(config, cwd, allowances));
7002
7040
  return assembleLandstripPolicy({
7003
7041
  network: {
7004
7042
  ...config.network,
7005
- allowUnixSockets: mergeAllowances(config.network.allowUnixSockets, sessionAllowedUnixSockets)
7043
+ allowUnixSockets: sessionGrants.effectiveUnixSockets(config.network.allowUnixSockets)
7006
7044
  },
7007
7045
  filesystem: {
7008
7046
  ...readPolicy,
7009
7047
  denyReadAlways: mergeArray(config.filesystem.denyReadAlways, allowances?.protectedPaths),
7010
- allowWrite: getEffectiveAllowWrite(config, allowances),
7048
+ allowWrite: sessionGrants.effectiveAllowWrite(config, allowances),
7011
7049
  denyWrite: mergeArray(config.filesystem.denyWrite, allowances?.protectedPaths),
7012
7050
  denyWriteAlways: mergeArray(config.filesystem.denyWriteAlways, allowances?.protectedPaths)
7013
7051
  },
@@ -7058,22 +7096,20 @@ ${paths}${note}`, permissionOptionsFor(ctx), promptSignal);
7058
7096
  const isUnixSocket = isAbsolute4(trap.target);
7059
7097
  const socketPath = isUnixSocket ? normalizeBlockedPath(trap.target, cwd) : trap.target;
7060
7098
  const current = () => {
7061
- if (sessionAllowedTargets.includes(key) || allowances.targets.includes(key)) {
7099
+ if (sessionGrants.hasTarget(key, allowances)) {
7062
7100
  return { action: "allow" };
7063
7101
  }
7064
7102
  if (isUnixSocket) {
7065
7103
  const config = loadConfig(cwd, ctx);
7066
- if (config.network.allowAllUnixSockets || matchesPattern(socketPath, mergeAllowances(config.network.allowUnixSockets, sessionAllowedUnixSockets), cwd)) {
7104
+ if (config.network.allowAllUnixSockets || matchesPattern(socketPath, sessionGrants.effectiveUnixSockets(config.network.allowUnixSockets), cwd)) {
7067
7105
  return { action: "allow" };
7068
7106
  }
7069
7107
  }
7070
7108
  return;
7071
7109
  };
7072
- const existing = current();
7073
- if (existing)
7074
- return existing;
7075
- if (!ctx.hasUI || !promptOnBlock)
7076
- return { action: "deny", reason: "unprompted" };
7110
+ if (!ctx.hasUI || !promptOnBlock) {
7111
+ return current() ?? { action: "deny", reason: "unprompted" };
7112
+ }
7077
7113
  return permissionPrompts.resolve(current, async (promptSignal) => {
7078
7114
  const choice = await showPermissionPrompt(ctx, isUnixSocket ? `Unix socket blocked: ${trap.operation} "${socketPath}"` : `Network blocked: ${trap.operation} "${trap.target}"`, isUnixSocket ? permissionOptionsFor(ctx) : NETWORK_PERMISSION_OPTIONS, promptSignal, allowances.permissionPromptLabel);
7079
7115
  if (choice === "abort" || promptSignal.aborted)
@@ -7081,15 +7117,16 @@ ${paths}${note}`, permissionOptionsFor(ctx), promptSignal);
7081
7117
  if (isUnixSocket) {
7082
7118
  await applyUnixSocketChoice(ctx, choice, socketPath, key, cwd, allowances);
7083
7119
  } else {
7084
- const targets = choice === "once" ? allowances.targets : sessionAllowedTargets;
7085
- if (!targets.includes(key))
7086
- targets.push(key);
7120
+ sessionGrants.grantTarget(choice, key, allowances);
7087
7121
  }
7088
7122
  return { action: "allow" };
7089
7123
  }, signal);
7090
7124
  }
7091
7125
  const path = normalizeBlockedPath(trap.path, cwd);
7126
+ let initialCheck = true;
7092
7127
  const current = () => {
7128
+ const granted = !initialCheck;
7129
+ initialCheck = false;
7093
7130
  if (matchesPattern(path, allowances.protectedPaths ?? [], cwd)) {
7094
7131
  return { action: "deny", reason: "hard-deny" };
7095
7132
  }
@@ -7098,28 +7135,24 @@ ${paths}${note}`, permissionOptionsFor(ctx), promptSignal);
7098
7135
  return { action: "deny", reason: "hard-deny" };
7099
7136
  }
7100
7137
  if (trap.operation === "read" && allowances.explicitDenyRead && matchesPattern(path, mergeArray(allowances.explicitDenyRead.patterns, config.explicitDenyRead), cwd, allowances.explicitDenyRead.globRoots)) {
7101
- return isPathReadAllowed(path, mergeArray(config.explicitAllowRead, [
7102
- ...sessionAllowedReadPaths,
7103
- ...allowances.explicitDenyRead.approvedPaths
7104
- ]), mergeArray(config.explicitDenyRead, [
7138
+ return isPathReadAllowed(path, sessionGrants.explicitAllowRead(config.explicitAllowRead, allowances.explicitDenyRead.approvedPaths), mergeArray(config.explicitDenyRead, [
7105
7139
  ...allowances.explicitDenyRead.patterns,
7106
7140
  ...[...allowances.explicitDenyRead.globRoots.values()].flat()
7107
- ]), cwd, { requireAllowMatch: true }) ? { action: "allow" } : undefined;
7141
+ ]), cwd, { requireAllowMatch: true }) ? { action: "allow", granted } : undefined;
7108
7142
  }
7109
- if (trap.operation === "write" && matchesWriteDenyPattern(path, config.filesystem.denyWriteAlways, cwd, getEffectiveAllowWrite(config, allowances))) {
7143
+ if (trap.operation === "write" && matchesWriteDenyPattern(path, config.filesystem.denyWriteAlways, cwd, sessionGrants.effectiveAllowWrite(config, allowances))) {
7110
7144
  return { action: "deny", reason: "hard-deny" };
7111
7145
  }
7112
- const allowed = trap.operation === "read" ? readAllowed(path, getEffectiveAllowRead(config, cwd, allowances), getEffectiveDenyRead(config, cwd), cwd) : !shouldPromptForWrite(path, getEffectiveAllowWrite(config, allowances), config.filesystem.denyWrite, cwd);
7113
- return allowed ? { action: "allow" } : undefined;
7146
+ const allowed = trap.operation === "read" ? readAllowed(path, sessionGrants.effectiveAllowRead(config, cwd, allowances), getEffectiveDenyRead(config, cwd), cwd) : !shouldPromptForWrite(path, sessionGrants.effectiveAllowWrite(config, allowances), config.filesystem.denyWrite, cwd);
7147
+ return allowed ? { action: "allow", granted } : undefined;
7114
7148
  };
7115
- const existing = current();
7116
- if (existing)
7117
- return existing;
7118
- if (!ctx.hasUI || !promptOnBlock)
7119
- return { action: "deny", reason: "unprompted" };
7149
+ if (!ctx.hasUI || !promptOnBlock) {
7150
+ return current() ?? { action: "deny", reason: "unprompted" };
7151
+ }
7120
7152
  return permissionPrompts.resolve(current, async (promptSignal) => {
7121
7153
  const config = loadConfig(cwd, ctx);
7122
- const choice = trap.operation === "read" ? await promptReadBlock(ctx, path, matchesPattern(path, config.filesystem.denyRead, cwd) ? "granting allowRead will override it" : undefined, promptSignal, allowances.permissionPromptLabel) : await promptWriteBlock(ctx, path, matchesWriteDenyPattern(path, config.filesystem.denyWrite, cwd, getEffectiveAllowWrite(config, allowances)) ? "granting allowWrite will override it" : undefined, promptSignal, allowances.permissionPromptLabel);
7154
+ const reason = trap.operation === "read" ? matchesPattern(path, config.filesystem.denyRead, cwd) ? "granting allowRead will override it" : undefined : matchesWriteDenyPattern(path, config.filesystem.denyWrite, cwd, sessionGrants.effectiveAllowWrite(config, allowances)) ? "granting allowWrite will override it" : undefined;
7155
+ const choice = await promptFilesystemBlock(ctx, trap.operation, path, reason, promptSignal, allowances.permissionPromptLabel);
7123
7156
  if (choice === "abort" || promptSignal.aborted)
7124
7157
  return { action: "deny", reason: "rejected" };
7125
7158
  if (trap.operation === "read") {
@@ -7127,7 +7160,7 @@ ${paths}${note}`, permissionOptionsFor(ctx), promptSignal);
7127
7160
  } else {
7128
7161
  await applyWriteChoice(ctx, choice, path, cwd, allowances);
7129
7162
  }
7130
- return { action: "allow" };
7163
+ return { action: "allow", granted: true };
7131
7164
  }, signal);
7132
7165
  }
7133
7166
  function attachWorkerTrap(socket, ctx, cwd, allowances, signal) {
@@ -7786,48 +7819,40 @@ ${paths}${note}`, permissionOptionsFor(ctx), promptSignal);
7786
7819
  const trappedPath = extractTrapBlockedPath(landstripErrorOutput, ctx.cwd, "read");
7787
7820
  if (trappedPath)
7788
7821
  return trappedPath;
7789
- return extractRetryableNativeReadDeniedPath(nativeOutput, ctx.cwd, getEffectiveAllowRead(config, ctx.cwd, allowances), getEffectiveDenyRead(config, ctx.cwd));
7822
+ return extractRetryableNativeReadDeniedPath(nativeOutput, ctx.cwd, sessionGrants.effectiveAllowRead(config, ctx.cwd, allowances), getEffectiveDenyRead(config, ctx.cwd));
7790
7823
  };
7791
7824
  const retryWithAccess = async (operation, blockedPath) => {
7792
- if (!ctx.hasUI || rejectedPaths[operation].has(blockedPath))
7825
+ if (!ctx.hasUI || signal?.aborted || rejectedPaths[operation].has(blockedPath))
7793
7826
  return null;
7794
- const { globalPath, projectPath } = getPiConfigPaths(ctx.cwd, "sandbox.json");
7795
- const isWriteDeniedAlways = (config) => matchesWriteDenyPattern(blockedPath, config.filesystem.denyWriteAlways, ctx.cwd, getEffectiveAllowWrite(config, allowances));
7796
- const current = () => {
7797
- const config = loadConfig(ctx.cwd, ctx);
7798
- if (operation === "read" ? matchesPattern(blockedPath, config.filesystem.denyReadAlways, ctx.cwd) : isWriteDeniedAlways(config)) {
7799
- return false;
7800
- }
7801
- const needsPrompt = operation === "read" ? !readAllowed(blockedPath, getEffectiveAllowRead(config, ctx.cwd, allowances), getEffectiveDenyRead(config, ctx.cwd), ctx.cwd) : shouldPromptForWrite(blockedPath, getEffectiveAllowWrite(config, allowances), config.filesystem.denyWrite, ctx.cwd);
7802
- return needsPrompt ? undefined : true;
7803
- };
7804
- const access = await permissionPrompts.resolve(current, async (promptSignal) => {
7805
- const config = loadConfig(ctx.cwd, ctx);
7806
- const choice = operation === "read" ? await promptReadBlock(ctx, blockedPath, matchesPattern(blockedPath, config.filesystem.denyRead, ctx.cwd) ? "granting allowRead will override it" : undefined, promptSignal) : await promptWriteBlock(ctx, blockedPath, matchesWriteDenyPattern(blockedPath, config.filesystem.denyWrite, ctx.cwd, getEffectiveAllowWrite(config, allowances)) ? "granting allowWrite will override it" : undefined, promptSignal);
7807
- if (choice === "abort" || promptSignal.aborted)
7808
- return false;
7809
- if (operation === "read") {
7810
- await applyReadChoice(ctx, choice, blockedPath, ctx.cwd, allowances);
7811
- } else {
7812
- await applyWriteChoice(ctx, choice, blockedPath, ctx.cwd, allowances);
7827
+ let access;
7828
+ try {
7829
+ access = await resolveTrapQuery({ kind: "filesystem", operation, path: blockedPath }, ctx, ctx.cwd, allowances, true, signal);
7830
+ } catch (error) {
7831
+ if (signal?.aborted || error instanceof Error && error.message === "Permission request cancelled") {
7832
+ return null;
7813
7833
  }
7814
- return true;
7815
- }, signal);
7816
- if (!access) {
7817
- const config = loadConfig(ctx.cwd, ctx);
7818
- if (operation === "write" && isWriteDeniedAlways(config)) {
7834
+ throw error;
7835
+ }
7836
+ if (access.action !== "allow") {
7837
+ if (operation === "write" && access.reason === "hard-deny") {
7838
+ const { globalPath, projectPath } = new SandboxConfigStore(ctx.cwd);
7819
7839
  notify(ctx, `"${blockedPath}" is blocked by denyWriteAlways. Check:
7820
7840
  ${projectPath}
7821
7841
  ${globalPath}`, "warning");
7822
7842
  }
7823
7843
  return null;
7824
7844
  }
7825
- const config = loadConfig(ctx.cwd, ctx);
7826
- if (operation === "write" && isWriteDeniedAlways(config)) {
7827
- notify(ctx, `"${blockedPath}" was added to allowWrite, but denyWriteAlways still blocks it. Check:
7845
+ if (!access.granted)
7846
+ return null;
7847
+ if (operation === "write") {
7848
+ const config = loadConfig(ctx.cwd, ctx);
7849
+ if (matchesWriteDenyPattern(blockedPath, config.filesystem.denyWriteAlways, ctx.cwd, sessionGrants.effectiveAllowWrite(config, allowances))) {
7850
+ const { globalPath, projectPath } = new SandboxConfigStore(ctx.cwd);
7851
+ notify(ctx, `"${blockedPath}" was added to allowWrite, but denyWriteAlways still blocks it. Check:
7828
7852
  ${projectPath}
7829
7853
  ${globalPath}`, "warning");
7830
- return null;
7854
+ return null;
7855
+ }
7831
7856
  }
7832
7857
  onUpdate?.({
7833
7858
  content: [
@@ -8088,11 +8113,7 @@ ${trapMessage}
8088
8113
  pi.on("session_start", async (_event, ctx) => {
8089
8114
  activeContext = ctx;
8090
8115
  permissionPrompts.reset();
8091
- sessionAllowedDomains.length = 0;
8092
- sessionAllowedReadPaths.length = 0;
8093
- sessionAllowedWritePaths.length = 0;
8094
- sessionAllowedUnixSockets.length = 0;
8095
- sessionAllowedTargets.length = 0;
8116
+ sessionGrants.reset();
8096
8117
  unsandboxedWorkerWarningShown = false;
8097
8118
  projectConfigTrusted = isProjectTrusted(ctx);
8098
8119
  if (getNoSandboxFlag()) {
@@ -8122,7 +8143,7 @@ ${trapMessage}
8122
8143
  });
8123
8144
  }
8124
8145
  async function applySandboxSetting(ctx, enabled, scope) {
8125
- await writeSandboxConfigEnabled(ctx.cwd, enabled, scope);
8146
+ await new SandboxConfigStore(ctx.cwd).setEnabled(scope, enabled);
8126
8147
  const effectiveEnabled = loadConfig(ctx.cwd, ctx).enabled;
8127
8148
  if (!effectiveEnabled) {
8128
8149
  disableSandbox(ctx);
@@ -8131,8 +8152,8 @@ ${trapMessage}
8131
8152
  }
8132
8153
  }
8133
8154
  function sandboxOverview(cwd, includeProject) {
8134
- const config = loadSandboxConfig(cwd, includeProject);
8135
- const { globalPath, projectPath } = getPiConfigPaths(cwd, "sandbox.json");
8155
+ const store = new SandboxConfigStore(cwd);
8156
+ const config = store.load(includeProject);
8136
8157
  const windowsImplementation = process.platform === "win32" ? windowsStatus().active : undefined;
8137
8158
  return {
8138
8159
  enabled: config.enabled,
@@ -8142,16 +8163,14 @@ ${trapMessage}
8142
8163
  shellReadMode: process.platform === "win32" ? "policy" : config.shell.readAccess,
8143
8164
  readRuleScope: enforcesShellReadPolicy(config.shell.readAccess) ? "Workers and shell" : "Workers only",
8144
8165
  windowsMode: windowsImplementation === undefined ? undefined : windowsImplementation === "restrictedUser" ? "Restricted user" : `AppContainer (${config.windows.appContainerMode})`,
8145
- changeScope: getSandboxConfigWriteTarget(cwd, includeProject).scope,
8146
- paths: { global: globalPath, project: projectPath, binary: binaryPath() },
8166
+ changeScope: store.changeScope(includeProject),
8167
+ paths: { global: store.globalPath, project: store.projectPath, binary: binaryPath() },
8147
8168
  config,
8148
- sessionDomains: [...sessionAllowedDomains],
8149
- sessionReadPaths: [...sessionAllowedReadPaths],
8150
- sessionWritePaths: [...sessionAllowedWritePaths]
8169
+ ...sessionGrants.overview()
8151
8170
  };
8152
8171
  }
8153
8172
  const sandboxCallbacks = {
8154
- load: loadSandboxEnabledSettings,
8173
+ load: (cwd, includeProject) => new SandboxConfigStore(cwd).enabledSettings(includeProject),
8155
8174
  setEnabled: (ctx, enabled, scope) => applySandboxSetting(ctx, enabled, scope),
8156
8175
  clearProject: (ctx) => applySandboxSetting(ctx, undefined, "project"),
8157
8176
  overview: sandboxOverview
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-landstrip",
3
- "version": "0.20.20",
3
+ "version": "0.20.22",
4
4
  "description": "Sandboxed Bash and process-backed agents for Pi",
5
5
  "keywords": [
6
6
  "landstrip",
@@ -39,9 +39,11 @@
39
39
  "ci:test": "npm run test"
40
40
  },
41
41
  "dependencies": {
42
- "@landstrip/landstrip-api": "^0.20.20",
42
+ "@landstrip/landstrip-api": "^0.20.22",
43
43
  "jsonc-parser": "^3.3.1",
44
44
  "minimatch": "^10.2.5",
45
+ "semver": "^7.8.6",
46
+ "shell-quote": "^1.12.0",
45
47
  "undici": "^8.9.0",
46
48
  "yaml": "^2.9.0"
47
49
  },
@@ -50,6 +52,8 @@
50
52
  "@earendil-works/pi-coding-agent": "^1.0.4",
51
53
  "@earendil-works/pi-tui": "^1.0.4",
52
54
  "@types/node": "^26.4.1",
55
+ "@types/semver": "^7.8.0",
56
+ "@types/shell-quote": "^1.7.5",
53
57
  "oxfmt": "^0.75.0",
54
58
  "oxlint": "^1.68.0",
55
59
  "typebox": "^1.3.6",