pi-landstrip 0.20.15 → 0.20.16
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/dist/index.ts +186 -93
- package/package.json +3 -3
package/dist/index.ts
CHANGED
|
@@ -33,17 +33,16 @@ import {
|
|
|
33
33
|
deepMergeSandboxConfig as deepMerge,
|
|
34
34
|
domainMatchesAny,
|
|
35
35
|
evaluateDomainAccess,
|
|
36
|
-
formatLandstripTraps,
|
|
36
|
+
formatLandstripTraps as formatLandstripTraps2,
|
|
37
37
|
isDenialTrap,
|
|
38
38
|
isFilesystemTrap,
|
|
39
39
|
isPathReadAllowed,
|
|
40
|
-
isPathWriteAllowed,
|
|
41
40
|
isRecord as isRecord3,
|
|
42
41
|
isQueryTrap,
|
|
43
42
|
matchesPathPattern,
|
|
44
43
|
matchesWriteDenyPattern,
|
|
45
44
|
mergeArray,
|
|
46
|
-
parseLandstripTraps,
|
|
45
|
+
parseLandstripTraps as parseLandstripTraps2,
|
|
47
46
|
parseSandboxConfig,
|
|
48
47
|
canonicalizeGlobPattern,
|
|
49
48
|
canonicalizePath as canonicalizePath2,
|
|
@@ -55,6 +54,8 @@ import {
|
|
|
55
54
|
sessionScopeFor,
|
|
56
55
|
writeLandstripPolicyFile,
|
|
57
56
|
shouldPromptForWrite,
|
|
57
|
+
writeGrantScopesFor,
|
|
58
|
+
readGrantScopesFor,
|
|
58
59
|
normalizeBlockedPath,
|
|
59
60
|
extractNativeDeniedPath,
|
|
60
61
|
extractNativeWriteDeniedPath,
|
|
@@ -262,7 +263,12 @@ import {
|
|
|
262
263
|
visibleWidth,
|
|
263
264
|
wrapTextWithAnsi
|
|
264
265
|
} from "@earendil-works/pi-tui";
|
|
265
|
-
import {
|
|
266
|
+
import {
|
|
267
|
+
canonicalizeHost as canonicalizeHost2,
|
|
268
|
+
canonicalizePath,
|
|
269
|
+
formatLandstripTraps,
|
|
270
|
+
parseLandstripTraps
|
|
271
|
+
} from "@landstrip/landstrip-api/shared";
|
|
266
272
|
import { Type } from "typebox";
|
|
267
273
|
|
|
268
274
|
// agents.ts
|
|
@@ -2880,7 +2886,8 @@ function taskProgress(task) {
|
|
|
2880
2886
|
return progress;
|
|
2881
2887
|
}
|
|
2882
2888
|
function workerDialogTitle(task, title) {
|
|
2883
|
-
const
|
|
2889
|
+
const actor = task.kind === "command" || task.agent === "bash" ? "$ bash" : `@${task.agent}`;
|
|
2890
|
+
const label = `${actor} · ${task.description} · ${task.id.slice(0, 8)}`;
|
|
2884
2891
|
return title === undefined ? label : `${label}
|
|
2885
2892
|
${title}`;
|
|
2886
2893
|
}
|
|
@@ -4868,10 +4875,15 @@ ${outputText}` }
|
|
|
4868
4875
|
this.controllers.set(taskId, controller);
|
|
4869
4876
|
const runPromise = (async () => {
|
|
4870
4877
|
try {
|
|
4878
|
+
let trapBuffer = "";
|
|
4871
4879
|
const result = await this.integration.runSandboxedCommand(params.command, ctx.cwd, {
|
|
4872
4880
|
timeout: params.timeout,
|
|
4873
4881
|
signal: controller.signal,
|
|
4874
|
-
promptOnBlock:
|
|
4882
|
+
promptOnBlock: ctx.hasUI,
|
|
4883
|
+
permissionPromptLabel: workerDialogTitle(task),
|
|
4884
|
+
onErrorFd: (chunk) => {
|
|
4885
|
+
trapBuffer += chunk.toString("utf8");
|
|
4886
|
+
},
|
|
4875
4887
|
onData: (chunk) => {
|
|
4876
4888
|
try {
|
|
4877
4889
|
writeSync(outputFd, chunk);
|
|
@@ -4879,6 +4891,17 @@ ${outputText}` }
|
|
|
4879
4891
|
this.notifyTaskUpdate();
|
|
4880
4892
|
}
|
|
4881
4893
|
}, ctx);
|
|
4894
|
+
const traps = parseLandstripTraps(trapBuffer);
|
|
4895
|
+
if (traps.length > 0) {
|
|
4896
|
+
const formatted = [...new Set(formatLandstripTraps(traps).split(`
|
|
4897
|
+
`))].join(`
|
|
4898
|
+
`);
|
|
4899
|
+
try {
|
|
4900
|
+
writeSync(outputFd, Buffer.from(`${formatted}
|
|
4901
|
+
`, "utf8"));
|
|
4902
|
+
} catch {}
|
|
4903
|
+
this.notifyTaskUpdate();
|
|
4904
|
+
}
|
|
4882
4905
|
task.exitCode = result.exitCode;
|
|
4883
4906
|
if (task.state !== "cancelled") {
|
|
4884
4907
|
task.state = result.exitCode === 0 ? "completed" : "error";
|
|
@@ -6179,23 +6202,27 @@ function resolveProcessReadPolicy(audience, shellReadAccess, denyRead, allowRead
|
|
|
6179
6202
|
var SUPPORTED_PLATFORMS = new Set(["linux", "darwin", "win32"]);
|
|
6180
6203
|
var EXIT_STDIO_GRACE_MS = 100;
|
|
6181
6204
|
var packageDir2 = dirname5(fileURLToPath2(import.meta.url));
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6205
|
+
function permissionOptionsFor(ctx) {
|
|
6206
|
+
const options = [
|
|
6207
|
+
{ label: "Allow once", action: "once" },
|
|
6208
|
+
{ label: "Allow for this session", action: "session" }
|
|
6209
|
+
];
|
|
6210
|
+
if (isProjectTrusted(ctx)) {
|
|
6211
|
+
options.push({
|
|
6212
|
+
label: "Allow for this project",
|
|
6213
|
+
action: "project",
|
|
6214
|
+
confirm: true,
|
|
6215
|
+
hint: "save to .pi/sandbox.json"
|
|
6216
|
+
});
|
|
6217
|
+
}
|
|
6218
|
+
options.push({
|
|
6192
6219
|
label: "Allow for all projects",
|
|
6193
6220
|
action: "global",
|
|
6194
6221
|
confirm: true,
|
|
6195
6222
|
hint: "save to ~/.pi/agent/sandbox.json"
|
|
6196
|
-
},
|
|
6197
|
-
|
|
6198
|
-
|
|
6223
|
+
}, { label: "Keep blocked", action: "abort" });
|
|
6224
|
+
return options;
|
|
6225
|
+
}
|
|
6199
6226
|
var NETWORK_PERMISSION_OPTIONS = [
|
|
6200
6227
|
{ label: "Allow once", action: "once" },
|
|
6201
6228
|
{ label: "Allow for this session", action: "session" },
|
|
@@ -6471,11 +6498,11 @@ ${option.hint ?? "This changes persisted sandbox policy."}`, { signal });
|
|
|
6471
6498
|
}
|
|
6472
6499
|
function promptReadBlock(ctx, filePath, reason, signal, label) {
|
|
6473
6500
|
const title = reason ? `Read blocked: "${filePath}" is in denyRead (${reason})` : `Read blocked: "${filePath}" is not in allowRead`;
|
|
6474
|
-
return showPermissionPrompt(ctx, title,
|
|
6501
|
+
return showPermissionPrompt(ctx, title, permissionOptionsFor(ctx), signal, label);
|
|
6475
6502
|
}
|
|
6476
6503
|
function promptWriteBlock(ctx, filePath, reason, signal, label) {
|
|
6477
6504
|
const title = reason ? `Write blocked: "${filePath}" is in denyWrite (${reason})` : `Write blocked: "${filePath}" is not in allowWrite`;
|
|
6478
|
-
return showPermissionPrompt(ctx, title,
|
|
6505
|
+
return showPermissionPrompt(ctx, title, permissionOptionsFor(ctx), signal, label);
|
|
6479
6506
|
}
|
|
6480
6507
|
function writeEnvFile(env, proxyPort, proxyToken) {
|
|
6481
6508
|
const lines = [];
|
|
@@ -6572,8 +6599,11 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
|
|
|
6572
6599
|
const localCwd = options.cwd ?? process.cwd();
|
|
6573
6600
|
let subagentRuntime = options.subagentRuntime;
|
|
6574
6601
|
let projectConfigTrusted = false;
|
|
6575
|
-
function
|
|
6576
|
-
return
|
|
6602
|
+
function isProjectConfigTrusted(ctx = activeContext) {
|
|
6603
|
+
return ctx ? isProjectTrusted(ctx) : projectConfigTrusted;
|
|
6604
|
+
}
|
|
6605
|
+
function loadConfig(cwd, ctx = activeContext) {
|
|
6606
|
+
return loadSandboxConfig(cwd, isProjectConfigTrusted(ctx));
|
|
6577
6607
|
}
|
|
6578
6608
|
let sandboxEnabled = false;
|
|
6579
6609
|
let sandboxReady = false;
|
|
@@ -6589,6 +6619,7 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
|
|
|
6589
6619
|
const sessionAllowedDomains = [];
|
|
6590
6620
|
const sessionAllowedReadPaths = [];
|
|
6591
6621
|
const sessionAllowedWritePaths = [];
|
|
6622
|
+
const sessionAllowedUnixSockets = [];
|
|
6592
6623
|
const sessionAllowedTargets = [];
|
|
6593
6624
|
function getContext(ctx = activeContext) {
|
|
6594
6625
|
return {
|
|
@@ -6750,9 +6781,17 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
|
|
|
6750
6781
|
readPaths: [...new Set([...allowances.readPaths, ...executablePaths, ...additionalPaths])]
|
|
6751
6782
|
};
|
|
6752
6783
|
}
|
|
6753
|
-
|
|
6784
|
+
function resolvePersistedConfigPath(cwd, choice, ctx = activeContext) {
|
|
6754
6785
|
const { globalPath, projectPath } = getPiConfigPaths(cwd, "sandbox.json");
|
|
6755
|
-
|
|
6786
|
+
if (choice === "project") {
|
|
6787
|
+
return isProjectConfigTrusted(ctx) ? projectPath : undefined;
|
|
6788
|
+
}
|
|
6789
|
+
if (choice === "global")
|
|
6790
|
+
return globalPath;
|
|
6791
|
+
return;
|
|
6792
|
+
}
|
|
6793
|
+
async function applyDomainChoice(ctx, choice, domain, cwd, allowances) {
|
|
6794
|
+
const configPath = resolvePersistedConfigPath(cwd, choice, ctx);
|
|
6756
6795
|
if (configPath) {
|
|
6757
6796
|
await addConfigValue(configPath, domain, (config) => config.network?.allowedDomains ?? [], (config, allowedDomains) => {
|
|
6758
6797
|
config.network = {
|
|
@@ -6766,45 +6805,69 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
|
|
|
6766
6805
|
if (target && !target.includes(domain))
|
|
6767
6806
|
target.push(domain);
|
|
6768
6807
|
}
|
|
6769
|
-
function
|
|
6770
|
-
|
|
6771
|
-
|
|
6808
|
+
async function applyUnixSocketChoice(ctx, choice, socketPath, key, cwd, allowances) {
|
|
6809
|
+
const configPath = resolvePersistedConfigPath(cwd, choice, ctx);
|
|
6810
|
+
if (configPath) {
|
|
6811
|
+
await addConfigValue(configPath, socketPath, (config) => config.network?.allowUnixSockets ?? [], (config, allowUnixSockets) => {
|
|
6812
|
+
config.network = { ...config.network, allowUnixSockets };
|
|
6813
|
+
});
|
|
6814
|
+
}
|
|
6815
|
+
if (choice === "once") {
|
|
6816
|
+
if (allowances && !allowances.targets.includes(key))
|
|
6817
|
+
allowances.targets.push(key);
|
|
6818
|
+
} else {
|
|
6819
|
+
if (!sessionAllowedUnixSockets.includes(socketPath)) {
|
|
6820
|
+
sessionAllowedUnixSockets.push(socketPath);
|
|
6821
|
+
}
|
|
6822
|
+
if (!sessionAllowedTargets.includes(key))
|
|
6823
|
+
sessionAllowedTargets.push(key);
|
|
6824
|
+
}
|
|
6825
|
+
}
|
|
6826
|
+
function noteScope(ctx, verb, choice, filePath, scopes) {
|
|
6827
|
+
if (scopes.length !== 1 || scopes[0] !== filePath) {
|
|
6828
|
+
notify(ctx, `${verb} allowed (${choice}): ${scopes.join(", ")}`, "info");
|
|
6829
|
+
}
|
|
6772
6830
|
}
|
|
6773
6831
|
async function applyReadChoice(ctx, choice, filePath, cwd, allowances, scope = sessionScopeFor(filePath, cwd)) {
|
|
6774
|
-
const
|
|
6775
|
-
|
|
6832
|
+
const config = loadConfig(cwd, ctx);
|
|
6833
|
+
const effectiveDenyRead = allowances?.explicitDenyRead ? mergeArray(config.filesystem.denyRead, [
|
|
6776
6834
|
...allowances.explicitDenyRead.patterns,
|
|
6777
6835
|
...[...allowances.explicitDenyRead.globRoots.values()].flat()
|
|
6778
|
-
])
|
|
6779
|
-
|
|
6780
|
-
const configPath =
|
|
6836
|
+
]) : config.filesystem.denyRead;
|
|
6837
|
+
const scopes = readGrantScopesFor(filePath, getEffectiveAllowRead(config, cwd, allowances), effectiveDenyRead, cwd, scope);
|
|
6838
|
+
const configPath = resolvePersistedConfigPath(cwd, choice, ctx);
|
|
6781
6839
|
if (configPath) {
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6840
|
+
for (const entry of scopes) {
|
|
6841
|
+
await addConfigValue(configPath, entry, (cfg) => cfg.filesystem?.allowRead ?? [], (cfg, allowRead) => {
|
|
6842
|
+
cfg.filesystem = { ...cfg.filesystem, allowRead };
|
|
6843
|
+
});
|
|
6844
|
+
}
|
|
6785
6845
|
}
|
|
6786
6846
|
const target = choice === "once" ? allowances?.readPaths : sessionAllowedReadPaths;
|
|
6787
|
-
|
|
6788
|
-
target.
|
|
6789
|
-
|
|
6790
|
-
|
|
6847
|
+
for (const entry of scopes) {
|
|
6848
|
+
if (target && !target.includes(entry))
|
|
6849
|
+
target.push(entry);
|
|
6850
|
+
allowances?.explicitDenyRead?.approvedPaths.push(entry);
|
|
6851
|
+
}
|
|
6852
|
+
noteScope(ctx, "Read", choice, filePath, scopes);
|
|
6791
6853
|
}
|
|
6792
6854
|
async function applyWriteChoice(ctx, choice, filePath, cwd, allowances) {
|
|
6793
|
-
const
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
scope = filePath;
|
|
6797
|
-
}
|
|
6798
|
-
const configPath = choice === "project" ? projectPath : choice === "global" ? globalPath : undefined;
|
|
6855
|
+
const config = loadConfig(cwd, ctx);
|
|
6856
|
+
const scopes = writeGrantScopesFor(filePath, getEffectiveAllowWrite(config, allowances), config.filesystem.denyWrite, cwd);
|
|
6857
|
+
const configPath = resolvePersistedConfigPath(cwd, choice, ctx);
|
|
6799
6858
|
if (configPath) {
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6859
|
+
for (const entry of scopes) {
|
|
6860
|
+
await addConfigValue(configPath, entry, (cfg) => cfg.filesystem?.allowWrite ?? [], (cfg, allowWrite) => {
|
|
6861
|
+
cfg.filesystem = { ...cfg.filesystem, allowWrite };
|
|
6862
|
+
});
|
|
6863
|
+
}
|
|
6803
6864
|
}
|
|
6804
6865
|
const target = choice === "once" ? allowances?.writePaths : sessionAllowedWritePaths;
|
|
6805
|
-
|
|
6806
|
-
target.
|
|
6807
|
-
|
|
6866
|
+
for (const entry of scopes) {
|
|
6867
|
+
if (target && !target.includes(entry))
|
|
6868
|
+
target.push(entry);
|
|
6869
|
+
}
|
|
6870
|
+
noteScope(ctx, "Write", choice, filePath, scopes);
|
|
6808
6871
|
}
|
|
6809
6872
|
async function authorizeFilesystemToolAccess(ctx, accesses, options = {}) {
|
|
6810
6873
|
const normalized = [
|
|
@@ -6820,7 +6883,7 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
|
|
|
6820
6883
|
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));
|
|
6821
6884
|
};
|
|
6822
6885
|
const current = () => {
|
|
6823
|
-
const config = loadConfig(ctx.cwd);
|
|
6886
|
+
const config = loadConfig(ctx.cwd, ctx);
|
|
6824
6887
|
if (!config.enabled)
|
|
6825
6888
|
return { allowed: true, prompted: false };
|
|
6826
6889
|
for (const access of normalized) {
|
|
@@ -6842,14 +6905,14 @@ function createLandstripIntegrationWithPrompts(options, permissionPrompts) {
|
|
|
6842
6905
|
return { allowed: false, prompted: false, reason: "Filesystem access requires approval" };
|
|
6843
6906
|
}
|
|
6844
6907
|
return permissionPrompts.resolve(current, async (promptSignal) => {
|
|
6845
|
-
const blocked = blockedAccesses(loadConfig(ctx.cwd));
|
|
6908
|
+
const blocked = blockedAccesses(loadConfig(ctx.cwd, ctx));
|
|
6846
6909
|
const paths = blocked.map(({ operation, path }) => `${operation}: ${path}`).join(`
|
|
6847
6910
|
`);
|
|
6848
6911
|
const note = options.authorizationNote ? `
|
|
6849
6912
|
|
|
6850
6913
|
${options.authorizationNote}` : "";
|
|
6851
6914
|
const choice = await showPermissionPrompt(ctx, `Filesystem policy blocked this tool call:
|
|
6852
|
-
${paths}${note}`,
|
|
6915
|
+
${paths}${note}`, permissionOptionsFor(ctx), promptSignal);
|
|
6853
6916
|
if (choice === "abort" || promptSignal.aborted) {
|
|
6854
6917
|
return { allowed: false, prompted: true, reason: "Filesystem access denied" };
|
|
6855
6918
|
}
|
|
@@ -6865,7 +6928,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
6865
6928
|
}
|
|
6866
6929
|
async function ensureDomainAllowed(ctx, domain, cwd, allowances, signal) {
|
|
6867
6930
|
const current = () => {
|
|
6868
|
-
const config = loadConfig(cwd);
|
|
6931
|
+
const config = loadConfig(cwd, ctx);
|
|
6869
6932
|
const decision = evaluateDomainAccess(domain, config.network, {
|
|
6870
6933
|
allowedDomainsOverrides: [...sessionAllowedDomains, ...allowances?.domains ?? []]
|
|
6871
6934
|
});
|
|
@@ -6878,21 +6941,24 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
6878
6941
|
if (!ctx.hasUI)
|
|
6879
6942
|
return current() ?? false;
|
|
6880
6943
|
return permissionPrompts.resolve(current, async (promptSignal) => {
|
|
6881
|
-
const choice = await showPermissionPrompt(ctx, `Network blocked: "${domain}" is not in the allowed domains list`,
|
|
6944
|
+
const choice = await showPermissionPrompt(ctx, `Network blocked: "${domain}" is not in the allowed domains list`, permissionOptionsFor(ctx), promptSignal, allowances?.permissionPromptLabel);
|
|
6882
6945
|
if (choice === "abort" || promptSignal.aborted)
|
|
6883
6946
|
return false;
|
|
6884
|
-
await applyDomainChoice(choice, domain, cwd, allowances);
|
|
6947
|
+
await applyDomainChoice(ctx, choice, domain, cwd, allowances);
|
|
6885
6948
|
return true;
|
|
6886
6949
|
}, signal);
|
|
6887
6950
|
}
|
|
6888
|
-
function buildLandstripPolicy(cwd, proxyPort, audience, allowances) {
|
|
6889
|
-
const config = loadConfig(cwd);
|
|
6951
|
+
function buildLandstripPolicy(cwd, proxyPort, audience, allowances, ctx = activeContext) {
|
|
6952
|
+
const config = loadConfig(cwd, ctx);
|
|
6890
6953
|
const readPolicy = resolveProcessReadPolicy(audience, config.shell.readAccess, mergeArray(getEffectiveDenyRead(config, cwd), [
|
|
6891
6954
|
...allowances?.explicitDenyRead?.patterns ?? [],
|
|
6892
6955
|
...[...allowances?.explicitDenyRead?.globRoots.values() ?? []].flat()
|
|
6893
6956
|
]), getEffectiveAllowRead(config, cwd, allowances));
|
|
6894
6957
|
return assembleLandstripPolicy({
|
|
6895
|
-
network:
|
|
6958
|
+
network: {
|
|
6959
|
+
...config.network,
|
|
6960
|
+
allowUnixSockets: mergeAllowances(config.network.allowUnixSockets, sessionAllowedUnixSockets)
|
|
6961
|
+
},
|
|
6896
6962
|
filesystem: {
|
|
6897
6963
|
...readPolicy,
|
|
6898
6964
|
denyReadAlways: mergeArray(config.filesystem.denyReadAlways, allowances?.protectedPaths),
|
|
@@ -6905,13 +6971,13 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
6905
6971
|
httpProxyPort: proxyPort
|
|
6906
6972
|
});
|
|
6907
6973
|
}
|
|
6908
|
-
function writePolicyFile(cwd, proxyPort, audience, allowances) {
|
|
6909
|
-
return writeLandstripPolicyFile(buildLandstripPolicy(cwd, proxyPort, audience, allowances), "pi-landstrip-");
|
|
6974
|
+
function writePolicyFile(cwd, proxyPort, audience, allowances, ctx = activeContext) {
|
|
6975
|
+
return writeLandstripPolicyFile(buildLandstripPolicy(cwd, proxyPort, audience, allowances, ctx), "pi-landstrip-");
|
|
6910
6976
|
}
|
|
6911
6977
|
function startProxy(ctx, cwd, allowances, signal, authorization, portRange) {
|
|
6912
6978
|
return startFilterProxy({
|
|
6913
6979
|
isDomainAllowed: async (domain) => {
|
|
6914
|
-
const config = loadConfig(cwd);
|
|
6980
|
+
const config = loadConfig(cwd, ctx);
|
|
6915
6981
|
if (domainMatchesAny(domain, config.network.deniedDomains))
|
|
6916
6982
|
return false;
|
|
6917
6983
|
return ensureDomainAllowed(ctx, domain, cwd, allowances, signal);
|
|
@@ -6944,19 +7010,36 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
6944
7010
|
async function resolveTrapQuery(trap, ctx, cwd, allowances, promptOnBlock, signal, readScope) {
|
|
6945
7011
|
if (trap.kind !== "filesystem") {
|
|
6946
7012
|
const key = `${trap.operation}\x00${trap.target}`;
|
|
6947
|
-
const
|
|
7013
|
+
const isUnixSocket = isAbsolute4(trap.target);
|
|
7014
|
+
const socketPath = isUnixSocket ? normalizeBlockedPath(trap.target, cwd) : trap.target;
|
|
7015
|
+
const current = () => {
|
|
7016
|
+
if (sessionAllowedTargets.includes(key) || allowances.targets.includes(key)) {
|
|
7017
|
+
return { action: "allow" };
|
|
7018
|
+
}
|
|
7019
|
+
if (isUnixSocket) {
|
|
7020
|
+
const config = loadConfig(cwd, ctx);
|
|
7021
|
+
if (config.network.allowAllUnixSockets || matchesPattern(socketPath, mergeAllowances(config.network.allowUnixSockets, sessionAllowedUnixSockets), cwd)) {
|
|
7022
|
+
return { action: "allow" };
|
|
7023
|
+
}
|
|
7024
|
+
}
|
|
7025
|
+
return;
|
|
7026
|
+
};
|
|
6948
7027
|
const existing = current();
|
|
6949
7028
|
if (existing)
|
|
6950
7029
|
return existing;
|
|
6951
7030
|
if (!ctx.hasUI || !promptOnBlock)
|
|
6952
7031
|
return { action: "deny", reason: "unprompted" };
|
|
6953
7032
|
return permissionPrompts.resolve(current, async (promptSignal) => {
|
|
6954
|
-
const choice = await showPermissionPrompt(ctx, `Network blocked: ${trap.operation} "${trap.target}"`, NETWORK_PERMISSION_OPTIONS, promptSignal, allowances.permissionPromptLabel);
|
|
7033
|
+
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);
|
|
6955
7034
|
if (choice === "abort" || promptSignal.aborted)
|
|
6956
7035
|
return { action: "deny", reason: "rejected" };
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
7036
|
+
if (isUnixSocket) {
|
|
7037
|
+
await applyUnixSocketChoice(ctx, choice, socketPath, key, cwd, allowances);
|
|
7038
|
+
} else {
|
|
7039
|
+
const targets = choice === "once" ? allowances.targets : sessionAllowedTargets;
|
|
7040
|
+
if (!targets.includes(key))
|
|
7041
|
+
targets.push(key);
|
|
7042
|
+
}
|
|
6960
7043
|
return { action: "allow" };
|
|
6961
7044
|
}, signal);
|
|
6962
7045
|
}
|
|
@@ -6965,7 +7048,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
6965
7048
|
if (matchesPattern(path, allowances.protectedPaths ?? [], cwd)) {
|
|
6966
7049
|
return { action: "deny", reason: "hard-deny" };
|
|
6967
7050
|
}
|
|
6968
|
-
const config = loadConfig(cwd);
|
|
7051
|
+
const config = loadConfig(cwd, ctx);
|
|
6969
7052
|
if (trap.operation === "read" && matchesPattern(path, config.filesystem.denyReadAlways, cwd)) {
|
|
6970
7053
|
return { action: "deny", reason: "hard-deny" };
|
|
6971
7054
|
}
|
|
@@ -6990,7 +7073,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
6990
7073
|
if (!ctx.hasUI || !promptOnBlock)
|
|
6991
7074
|
return { action: "deny", reason: "unprompted" };
|
|
6992
7075
|
return permissionPrompts.resolve(current, async (promptSignal) => {
|
|
6993
|
-
const config = loadConfig(cwd);
|
|
7076
|
+
const config = loadConfig(cwd, ctx);
|
|
6994
7077
|
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);
|
|
6995
7078
|
if (choice === "abort" || promptSignal.aborted)
|
|
6996
7079
|
return { action: "deny", reason: "rejected" };
|
|
@@ -7044,7 +7127,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7044
7127
|
if (isFilesystemTrap(trap) && trap.operation === "read" && matchesPattern(normalizeBlockedPath(trap.path, cwd), allowances.protectedPaths ?? [], cwd)) {
|
|
7045
7128
|
continue;
|
|
7046
7129
|
}
|
|
7047
|
-
reportTrapError(
|
|
7130
|
+
reportTrapError(formatLandstripTraps2([trap]));
|
|
7048
7131
|
continue;
|
|
7049
7132
|
}
|
|
7050
7133
|
handleQuery(trap);
|
|
@@ -7116,7 +7199,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7116
7199
|
]
|
|
7117
7200
|
};
|
|
7118
7201
|
const processAllowances = withWindowsProcessReadAccess(allowances, options.command, options.cwd);
|
|
7119
|
-
const config = loadConfig(options.cwd);
|
|
7202
|
+
const config = loadConfig(options.cwd, options.ctx);
|
|
7120
7203
|
const explicitDenyGlobRoots = new Map;
|
|
7121
7204
|
processAllowances.explicitDenyRead = {
|
|
7122
7205
|
patterns: config.explicitDenyRead,
|
|
@@ -7253,7 +7336,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7253
7336
|
};
|
|
7254
7337
|
}
|
|
7255
7338
|
async function prepareProcess(options) {
|
|
7256
|
-
if (process.platform === "win32" && (getNoSandboxFlag() || !loadConfig(options.cwd).enabled)) {
|
|
7339
|
+
if (process.platform === "win32" && (getNoSandboxFlag() || !loadConfig(options.cwd, options.ctx).enabled)) {
|
|
7257
7340
|
throw new Error("Generic process preparation requires sandboxing on Windows");
|
|
7258
7341
|
}
|
|
7259
7342
|
return prepareManagedProcess({
|
|
@@ -7381,7 +7464,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7381
7464
|
if (!existsSync6(cwd))
|
|
7382
7465
|
throw new Error(`Working directory does not exist: ${cwd}`);
|
|
7383
7466
|
const provider = activeShellProvider();
|
|
7384
|
-
const config = loadConfig(cwd);
|
|
7467
|
+
const config = loadConfig(cwd, ctx);
|
|
7385
7468
|
const { token: proxyToken, authorization: proxyAuthorization } = createProxyCredentials();
|
|
7386
7469
|
const proxy = shouldStartProxy(config) ? await startProxy(ctx, cwd, allowances, signal, proxyAuthorization, restrictedUserProxyPortRange()) : null;
|
|
7387
7470
|
let policy;
|
|
@@ -7419,7 +7502,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7419
7502
|
readPaths: [...allowances.readPaths, ...invocation.readPaths ?? []]
|
|
7420
7503
|
};
|
|
7421
7504
|
processAllowances = withWindowsProcessReadAccess(processAllowances, invocation.executable, cwd);
|
|
7422
|
-
policy = writePolicyFile(cwd, proxy?.port ?? null, "shell", processAllowances);
|
|
7505
|
+
policy = writePolicyFile(cwd, proxy?.port ?? null, "shell", processAllowances, ctx);
|
|
7423
7506
|
landstripArgs = ["run", "-p", policy.path];
|
|
7424
7507
|
if (process.platform !== "win32")
|
|
7425
7508
|
landstripArgs.push("--trap", "3");
|
|
@@ -7505,15 +7588,15 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7505
7588
|
}
|
|
7506
7589
|
const blockedPath = extractTrapBlockedPath(errorFdAcc, cwd) ?? extractNativeDeniedPath(stderrAcc, cwd);
|
|
7507
7590
|
if (!blockedPath && ctx.hasUI) {
|
|
7508
|
-
const traps =
|
|
7591
|
+
const traps = parseLandstripTraps2(errorFdAcc);
|
|
7509
7592
|
const denials = traps.filter(isDenialTrap);
|
|
7510
7593
|
if (denials.length > 0) {
|
|
7511
|
-
const formatted =
|
|
7594
|
+
const formatted = formatLandstripTraps2(denials);
|
|
7512
7595
|
notify(ctx, `Sandbox blocked an operation: ${formatted}`, "warning");
|
|
7513
7596
|
}
|
|
7514
7597
|
const failures = traps.filter((trap) => !isDenialTrap(trap));
|
|
7515
7598
|
if (failures.length > 0) {
|
|
7516
|
-
notify(ctx, `Sandbox failed: ${
|
|
7599
|
+
notify(ctx, `Sandbox failed: ${formatLandstripTraps2(failures)}`, "error");
|
|
7517
7600
|
}
|
|
7518
7601
|
}
|
|
7519
7602
|
resolvePromise({ exitCode: code });
|
|
@@ -7642,15 +7725,15 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7642
7725
|
});
|
|
7643
7726
|
const run = () => sandboxedBash.execute(id, params, signal, onUpdate, ctx);
|
|
7644
7727
|
const formatTrapErrors = () => {
|
|
7645
|
-
const landstripErrors =
|
|
7728
|
+
const landstripErrors = parseLandstripTraps2(landstripErrorOutput);
|
|
7646
7729
|
if (landstripErrors.length === 0)
|
|
7647
7730
|
return null;
|
|
7648
|
-
return [...new Set(
|
|
7731
|
+
return [...new Set(formatLandstripTraps2(landstripErrors).split(`
|
|
7649
7732
|
`))].join(`
|
|
7650
7733
|
`);
|
|
7651
7734
|
};
|
|
7652
7735
|
const blockedReadPathForRetry = (nativeOutput) => {
|
|
7653
|
-
const config = loadConfig(ctx.cwd);
|
|
7736
|
+
const config = loadConfig(ctx.cwd, ctx);
|
|
7654
7737
|
if (!enforcesShellReadPolicy(config.shell.readAccess))
|
|
7655
7738
|
return null;
|
|
7656
7739
|
const trappedPath = extractTrapBlockedPath(landstripErrorOutput, ctx.cwd, "read");
|
|
@@ -7664,7 +7747,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7664
7747
|
const { globalPath, projectPath } = getPiConfigPaths(ctx.cwd, "sandbox.json");
|
|
7665
7748
|
const isWriteDeniedAlways = (config) => matchesWriteDenyPattern(blockedPath, config.filesystem.denyWriteAlways, ctx.cwd, getEffectiveAllowWrite(config, allowances));
|
|
7666
7749
|
const current = () => {
|
|
7667
|
-
const config = loadConfig(ctx.cwd);
|
|
7750
|
+
const config = loadConfig(ctx.cwd, ctx);
|
|
7668
7751
|
if (operation === "read" ? matchesPattern(blockedPath, config.filesystem.denyReadAlways, ctx.cwd) : isWriteDeniedAlways(config)) {
|
|
7669
7752
|
return false;
|
|
7670
7753
|
}
|
|
@@ -7672,7 +7755,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7672
7755
|
return needsPrompt ? undefined : true;
|
|
7673
7756
|
};
|
|
7674
7757
|
const access = await permissionPrompts.resolve(current, async (promptSignal) => {
|
|
7675
|
-
const config = loadConfig(ctx.cwd);
|
|
7758
|
+
const config = loadConfig(ctx.cwd, ctx);
|
|
7676
7759
|
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);
|
|
7677
7760
|
if (choice === "abort" || promptSignal.aborted)
|
|
7678
7761
|
return false;
|
|
@@ -7684,7 +7767,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7684
7767
|
return true;
|
|
7685
7768
|
}, signal);
|
|
7686
7769
|
if (!access) {
|
|
7687
|
-
const config = loadConfig(ctx.cwd);
|
|
7770
|
+
const config = loadConfig(ctx.cwd, ctx);
|
|
7688
7771
|
if (operation === "write" && isWriteDeniedAlways(config)) {
|
|
7689
7772
|
notify(ctx, `"${blockedPath}" is blocked by denyWriteAlways. Check:
|
|
7690
7773
|
${projectPath}
|
|
@@ -7692,7 +7775,7 @@ ${paths}${note}`, PERMISSION_OPTIONS, promptSignal);
|
|
|
7692
7775
|
}
|
|
7693
7776
|
return null;
|
|
7694
7777
|
}
|
|
7695
|
-
const config = loadConfig(ctx.cwd);
|
|
7778
|
+
const config = loadConfig(ctx.cwd, ctx);
|
|
7696
7779
|
if (operation === "write" && isWriteDeniedAlways(config)) {
|
|
7697
7780
|
notify(ctx, `"${blockedPath}" was added to allowWrite, but denyWriteAlways still blocks it. Check:
|
|
7698
7781
|
${projectPath}
|
|
@@ -7829,7 +7912,7 @@ ${trapMessage}
|
|
|
7829
7912
|
}
|
|
7830
7913
|
}
|
|
7831
7914
|
function enableSandbox(ctx) {
|
|
7832
|
-
const config = loadConfig(ctx.cwd);
|
|
7915
|
+
const config = loadConfig(ctx.cwd, ctx);
|
|
7833
7916
|
if (!SUPPORTED_PLATFORMS.has(process.platform)) {
|
|
7834
7917
|
sandboxEnabled = false;
|
|
7835
7918
|
sandboxReady = false;
|
|
@@ -7858,7 +7941,7 @@ ${trapMessage}
|
|
|
7858
7941
|
disableSandbox(ctx);
|
|
7859
7942
|
return false;
|
|
7860
7943
|
}
|
|
7861
|
-
const config = loadConfig(ctx.cwd);
|
|
7944
|
+
const config = loadConfig(ctx.cwd, ctx);
|
|
7862
7945
|
if (!config.enabled) {
|
|
7863
7946
|
disableSandbox(ctx);
|
|
7864
7947
|
return false;
|
|
@@ -7961,10 +8044,10 @@ ${trapMessage}
|
|
|
7961
8044
|
sessionAllowedDomains.length = 0;
|
|
7962
8045
|
sessionAllowedReadPaths.length = 0;
|
|
7963
8046
|
sessionAllowedWritePaths.length = 0;
|
|
8047
|
+
sessionAllowedUnixSockets.length = 0;
|
|
7964
8048
|
sessionAllowedTargets.length = 0;
|
|
7965
8049
|
unsandboxedWorkerWarningShown = false;
|
|
7966
|
-
|
|
7967
|
-
projectConfigTrusted = trustContext.isProjectTrusted?.() ?? false;
|
|
8050
|
+
projectConfigTrusted = isProjectTrusted(ctx);
|
|
7968
8051
|
if (getNoSandboxFlag()) {
|
|
7969
8052
|
disableSandbox(ctx);
|
|
7970
8053
|
notify(ctx, "Sandbox disabled via --no-sandbox", "warning");
|
|
@@ -7972,7 +8055,7 @@ ${trapMessage}
|
|
|
7972
8055
|
unpublishRuntime = publishLandstripRuntime(pi, integration);
|
|
7973
8056
|
return;
|
|
7974
8057
|
}
|
|
7975
|
-
const config = loadConfig(ctx.cwd);
|
|
8058
|
+
const config = loadConfig(ctx.cwd, ctx);
|
|
7976
8059
|
if (!config.enabled) {
|
|
7977
8060
|
disableSandbox(ctx);
|
|
7978
8061
|
notify(ctx, "Sandbox disabled via config", "info");
|
|
@@ -7993,7 +8076,7 @@ ${trapMessage}
|
|
|
7993
8076
|
}
|
|
7994
8077
|
async function applySandboxSetting(ctx, enabled, scope) {
|
|
7995
8078
|
await writeSandboxConfigEnabled(ctx.cwd, enabled, scope);
|
|
7996
|
-
const effectiveEnabled = loadConfig(ctx.cwd).enabled;
|
|
8079
|
+
const effectiveEnabled = loadConfig(ctx.cwd, ctx).enabled;
|
|
7997
8080
|
if (!effectiveEnabled) {
|
|
7998
8081
|
disableSandbox(ctx);
|
|
7999
8082
|
} else if (!getNoSandboxFlag()) {
|
|
@@ -8042,7 +8125,17 @@ ${trapMessage}
|
|
|
8042
8125
|
register,
|
|
8043
8126
|
emit: emitEvent,
|
|
8044
8127
|
runSandboxedCommand(command, cwd, execOptions, ctx) {
|
|
8045
|
-
const
|
|
8128
|
+
const allowances = {
|
|
8129
|
+
permissionPromptLabel: execOptions.permissionPromptLabel,
|
|
8130
|
+
domains: [],
|
|
8131
|
+
readPaths: [],
|
|
8132
|
+
writePaths: [],
|
|
8133
|
+
targets: []
|
|
8134
|
+
};
|
|
8135
|
+
const ops = ensureSandboxState(ctx) ? createLandstripBashOps(ctx, {
|
|
8136
|
+
promptOnBlock: execOptions.promptOnBlock ?? false,
|
|
8137
|
+
onErrorFd: execOptions.onErrorFd
|
|
8138
|
+
}, allowances) : externalShellProvider !== undefined ? createProviderBashOps() : createLocalBashOperations();
|
|
8046
8139
|
return ops.exec(command, cwd, {
|
|
8047
8140
|
onData: execOptions.onData ?? (() => {}),
|
|
8048
8141
|
signal: execOptions.signal,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-landstrip",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.16",
|
|
4
4
|
"description": "Sandboxed Bash and process-backed agents for Pi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"landstrip",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"ci:test": "npm run test"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@landstrip/landstrip-api": "^0.20.
|
|
42
|
+
"@landstrip/landstrip-api": "^0.20.16",
|
|
43
43
|
"jsonc-parser": "^3.3.1",
|
|
44
44
|
"minimatch": "^10.2.5",
|
|
45
45
|
"undici": "^8.9.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@earendil-works/pi-coding-agent": "^1.0.4",
|
|
51
51
|
"@earendil-works/pi-tui": "^1.0.4",
|
|
52
52
|
"@types/node": "^26.4.1",
|
|
53
|
-
"oxfmt": "^0.
|
|
53
|
+
"oxfmt": "^0.75.0",
|
|
54
54
|
"oxlint": "^1.68.0",
|
|
55
55
|
"typebox": "^1.3.6",
|
|
56
56
|
"typescript": "^5.0.0",
|