pi-landstrip 0.16.2 → 0.16.4
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/index.ts +26 -29
- package/package.json +2 -2
package/index.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (C) Jarkko Sakkinen 2026
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
AgentToolResult,
|
|
6
|
-
AgentToolUpdateCallback,
|
|
7
|
-
BashToolDetails,
|
|
8
|
-
BashToolInput,
|
|
9
|
-
ExtensionAPI,
|
|
10
|
-
ExtensionContext,
|
|
11
|
-
Theme,
|
|
12
|
-
} from '@earendil-works/pi-coding-agent';
|
|
13
|
-
|
|
14
|
-
import { binaryPath } from '@landstrip/landstrip';
|
|
15
|
-
|
|
16
4
|
import { spawn, spawnSync } from 'node:child_process';
|
|
5
|
+
import { randomBytes } from 'node:crypto';
|
|
17
6
|
import {
|
|
18
7
|
existsSync,
|
|
19
8
|
mkdirSync,
|
|
@@ -34,6 +23,16 @@ import { homedir, tmpdir } from 'node:os';
|
|
|
34
23
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
35
24
|
import { URL } from 'node:url';
|
|
36
25
|
|
|
26
|
+
import type {
|
|
27
|
+
AgentToolResult,
|
|
28
|
+
AgentToolUpdateCallback,
|
|
29
|
+
BashToolDetails,
|
|
30
|
+
BashToolInput,
|
|
31
|
+
ExtensionAPI,
|
|
32
|
+
ExtensionContext,
|
|
33
|
+
Theme,
|
|
34
|
+
} from '@earendil-works/pi-coding-agent';
|
|
35
|
+
|
|
37
36
|
import {
|
|
38
37
|
type BashOperations,
|
|
39
38
|
createBashToolDefinition,
|
|
@@ -44,7 +43,7 @@ import {
|
|
|
44
43
|
withFileMutationQueue,
|
|
45
44
|
} from '@earendil-works/pi-coding-agent';
|
|
46
45
|
import { Key, matchesKey, truncateToWidth, visibleWidth } from '@earendil-works/pi-tui';
|
|
47
|
-
import {
|
|
46
|
+
import { binaryPath } from '@landstrip/landstrip';
|
|
48
47
|
|
|
49
48
|
interface SandboxFilesystemConfig {
|
|
50
49
|
denyRead: string[];
|
|
@@ -328,12 +327,8 @@ function allowsAllDomains(allowedDomains: string[]): boolean {
|
|
|
328
327
|
return allowedDomains.includes('*');
|
|
329
328
|
}
|
|
330
329
|
|
|
331
|
-
function shouldPromptForWrite(
|
|
332
|
-
path
|
|
333
|
-
allowWrite: string[],
|
|
334
|
-
patternMatcher: (path: string, patterns: string[]) => boolean,
|
|
335
|
-
): boolean {
|
|
336
|
-
return allowWrite.length === 0 || !patternMatcher(path, allowWrite);
|
|
330
|
+
function shouldPromptForWrite(path: string, allowWrite: string[]): boolean {
|
|
331
|
+
return allowWrite.length === 0 || !matchesPattern(path, allowWrite);
|
|
337
332
|
}
|
|
338
333
|
|
|
339
334
|
function expandPath(filePath: string): string {
|
|
@@ -1004,12 +999,15 @@ export function createLandstripIntegration(
|
|
|
1004
999
|
return { dir, path };
|
|
1005
1000
|
}
|
|
1006
1001
|
|
|
1007
|
-
function startProxy(
|
|
1008
|
-
ctx: ExtensionContext,
|
|
1009
|
-
cwd: string,
|
|
1010
|
-
): Promise<{ port: number; stop: () => Promise<void> }> {
|
|
1002
|
+
function startProxy(cwd: string): Promise<{ port: number; stop: () => Promise<void> }> {
|
|
1011
1003
|
const sockets = new Set<Socket>();
|
|
1012
1004
|
|
|
1005
|
+
function domainAllowed(domain: string): boolean {
|
|
1006
|
+
const config = loadConfig(cwd);
|
|
1007
|
+
if (domainMatchesAny(domain, config.network.deniedDomains)) return false;
|
|
1008
|
+
return domainMatchesAny(domain, getEffectiveAllowedDomains(config));
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1013
1011
|
async function handleConnect(client: Socket, target: string, rest: Buffer): Promise<void> {
|
|
1014
1012
|
const endpoint = splitHostPort(target, 443);
|
|
1015
1013
|
if (!endpoint || !Number.isFinite(endpoint.port)) {
|
|
@@ -1017,7 +1015,7 @@ export function createLandstripIntegration(
|
|
|
1017
1015
|
return;
|
|
1018
1016
|
}
|
|
1019
1017
|
|
|
1020
|
-
if (!(
|
|
1018
|
+
if (!domainAllowed(endpoint.host)) {
|
|
1021
1019
|
denyProxyRequest(client);
|
|
1022
1020
|
return;
|
|
1023
1021
|
}
|
|
@@ -1065,7 +1063,7 @@ export function createLandstripIntegration(
|
|
|
1065
1063
|
}
|
|
1066
1064
|
}
|
|
1067
1065
|
|
|
1068
|
-
if (!(
|
|
1066
|
+
if (!domainAllowed(url.hostname)) {
|
|
1069
1067
|
denyProxyRequest(client);
|
|
1070
1068
|
return;
|
|
1071
1069
|
}
|
|
@@ -1187,7 +1185,7 @@ export function createLandstripIntegration(
|
|
|
1187
1185
|
const { shell, args } = getShellConfig(SettingsManager.create(cwd).getShellPath());
|
|
1188
1186
|
const config = loadConfig(cwd);
|
|
1189
1187
|
const allowNetwork = config.network.allowNetwork;
|
|
1190
|
-
const proxy = allowNetwork ? null : await startProxy(
|
|
1188
|
+
const proxy = allowNetwork ? null : await startProxy(cwd);
|
|
1191
1189
|
const policy = writePolicyFile(cwd, proxy?.port ?? null);
|
|
1192
1190
|
const landstripArgs = ['--trap-fd', '3', '-p', policy.path, shell, ...args, command];
|
|
1193
1191
|
|
|
@@ -1289,7 +1287,6 @@ export function createLandstripIntegration(
|
|
|
1289
1287
|
const isWriteAllowed = !shouldPromptForWrite(
|
|
1290
1288
|
blockedPath,
|
|
1291
1289
|
getEffectiveAllowWrite(config),
|
|
1292
|
-
matchesPattern,
|
|
1293
1290
|
);
|
|
1294
1291
|
|
|
1295
1292
|
if (blockedWritePath === blockedPath && !isWriteAllowed) {
|
|
@@ -1361,7 +1358,7 @@ export function createLandstripIntegration(
|
|
|
1361
1358
|
return null;
|
|
1362
1359
|
}
|
|
1363
1360
|
|
|
1364
|
-
if (shouldPromptForWrite(blockedPath, getEffectiveAllowWrite(config)
|
|
1361
|
+
if (shouldPromptForWrite(blockedPath, getEffectiveAllowWrite(config))) {
|
|
1365
1362
|
const choice = await promptWriteBlock(ctx, blockedPath);
|
|
1366
1363
|
if (choice === 'abort') return null;
|
|
1367
1364
|
await applyWriteChoice(choice, blockedPath, ctx.cwd);
|
|
@@ -1677,7 +1674,7 @@ export function createLandstripIntegration(
|
|
|
1677
1674
|
};
|
|
1678
1675
|
}
|
|
1679
1676
|
|
|
1680
|
-
if (shouldPromptForWrite(filePath, getEffectiveAllowWrite(config)
|
|
1677
|
+
if (shouldPromptForWrite(filePath, getEffectiveAllowWrite(config))) {
|
|
1681
1678
|
const choice = await promptWriteBlock(ctx, filePath);
|
|
1682
1679
|
if (choice === 'abort') {
|
|
1683
1680
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-landstrip",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
4
|
"description": "Landlock-based sandboxing for pi with interactive permission prompts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"landstrip",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@earendil-works/pi-tui": "^0.78.0",
|
|
34
|
-
"@landstrip/landstrip": "^0.16.
|
|
34
|
+
"@landstrip/landstrip": "^0.16.8"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@earendil-works/pi-coding-agent": "^0.74.2",
|