@pi-chamber/web 1.0.8-rc.1 → 1.0.8-rc.2
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/assets/{AgentsSurface-BmHImX8m.js → AgentsSurface-CcWBqAWV.js} +1 -1
- package/dist/assets/{ChoicesArtifact-C71fGOm2.js → ChoicesArtifact-Kk-qvrSB.js} +1 -1
- package/dist/assets/{DiagramView-BZQxoiZu.js → DiagramView-DZUBo1uP.js} +1 -1
- package/dist/assets/{DiffView-C70pbgk-.js → DiffView-CiZy4jFA.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-Cu8c3gBV.js → FileSaveConflictDialog-DZ9NDwOO.js} +1 -1
- package/dist/assets/{FilesView-nFJYEdRw.js → FilesView-DqiZ9kw9.js} +1 -1
- package/dist/assets/{GitHubDetailScaffold-Jvv_tgbl.js → GitHubDetailScaffold-DM2DH7o8.js} +1 -1
- package/dist/assets/{GitHubLinkPicker-BXD2ODRi.js → GitHubLinkPicker-ChB8NZ1h.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-BWI706F0.js → GitHubListPrimitives-CibDiJGq.js} +1 -1
- package/dist/assets/{GitView-MIDG5RYW.js → GitView--EaZQrBr.js} +5 -5
- package/dist/assets/{IssuesSurface-uNlozeu0.js → IssuesSurface-CySTpaD1.js} +3 -3
- package/dist/assets/{JsonTreeView-CSLsTriz.js → JsonTreeView-_yMHKKQZ.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cs-7BfWi.js → MarkdownRendererImpl-D_-2fQw0.js} +1 -1
- package/dist/assets/{PatchDiff-axbsnbTJ.js → PatchDiff-bHObDlhD.js} +1 -1
- package/dist/assets/{PierreDiffViewer-lwn6w_5w.js → PierreDiffViewer-UY7Cse-s.js} +1 -1
- package/dist/assets/{PullRequestsSurface-o_AXDjbO.js → PullRequestsSurface-iXy6chwc.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-C4CMlcbv.js → SessionSwitcherContent-DJGCa_wN.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-DCBVuCoo.js → SessionSwitcherDropdown-CDOX-5Y2.js} +2 -2
- package/dist/assets/{SessionUnreadDot-DyeIrsro.js → SessionUnreadDot-Dwc3MdvA.js} +1 -1
- package/dist/assets/SettingsView-DA-U9lsj.js +11 -0
- package/dist/assets/{SettingsWindow-Cb4st5y5.js → SettingsWindow-CUg49Mfh.js} +1 -1
- package/dist/assets/{SubagentsArtifact-BzeMEoFP.js → SubagentsArtifact-DUZX9tDe.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BP2mOWdV.js → ToolOutputDialog-BuZZaRw4.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-D49XBR9b.js → ToolPartDiffPreview-CKncG6i2.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-CLgDONEQ.js → VirtualizedFileDiff-BGZiLPe_.js} +1 -1
- package/dist/assets/VisualFrame-DBZkHFnG.js +22 -0
- package/dist/assets/VisualsArtifact-Bq0vMO-i.js +1 -0
- package/dist/assets/{collapsible-BeyKtQGB.js → collapsible-Bro9KrfM.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DmO6H8u6.js → computeVirtualFileMetrics-DJQqK49u.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DOK251YW.js → contextFileOpenGuard-ByWK3Sru.js} +1 -1
- package/dist/assets/{fileTreeStatus-CnzR7kxA.js → fileTreeStatus-CyJ3TOYD.js} +1 -1
- package/dist/assets/{gitStatusPredicates-4kPg2t6j.js → gitStatusPredicates-BsXrwngT.js} +1 -1
- package/dist/assets/{githubLink-QvaLfNNT.js → githubLink-g2bmC0qi.js} +1 -1
- package/dist/assets/index-B_L9GVYw.css +1 -0
- package/dist/assets/{index-DMX9wT1Z.js → index-C9rUUQ_Y.js} +1 -1
- package/dist/assets/index-CKKWVoND.js +11 -0
- package/dist/assets/{main-BW9J3Y72.js → main-DT-4_fhe.js} +2 -2
- package/dist/assets/{main-BirYxac2.js → main-DsLMU9CT.js} +4 -4
- package/dist/assets/{markdownCore-CxmcPur8.js → markdownCore-QmM_aOnZ.js} +1 -1
- package/dist/assets/{miniChat-BRB11eEs.js → miniChat-BqGslD2z.js} +2 -2
- package/dist/assets/{mobile-DJZYYCuB.js → mobile-C5JOcDIC.js} +2 -2
- package/dist/assets/{nativeFileSave-B6QpoPRn.js → nativeFileSave-DSMsJqXM.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-PWoh3LNA.js → pi-session-focus-preference-Cc_S4zi1.js} +1 -1
- package/dist/assets/{renderDiffWithHighlighter-C48T6YFJ.js → renderDiffWithHighlighter-BXhnIAHg.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-N-BQdJl0.js → renderElectronMiniChatApp-CiSkecEE.js} +2 -2
- package/dist/assets/{renderFileWithHighlighter-8Kt2MyTN.js → renderFileWithHighlighter-CK29YZtC.js} +1 -1
- package/dist/assets/renderMobileApp-C4JuoxsZ.js +11 -0
- package/dist/assets/runtimeEndpointReset-Dwj-jCDS.js +66 -0
- package/dist/assets/{runtimeSurface-kIEoYsPP.js → runtimeSurface-0K7vuUpd.js} +1 -1
- package/dist/assets/{selection-BTEdLRVK.js → selection-CnYkEsu_.js} +1 -1
- package/dist/assets/useAppFontEffects-CV5UyTRw.js +226 -0
- package/dist/assets/{useGitHubRemoteSearch-DIBHNu8r.js → useGitHubRemoteSearch-CgP-zEBj.js} +1 -1
- package/dist/assets/{useSwitcherItems-DfLbfX37.js → useSwitcherItems-C8G5F0hs.js} +1 -1
- package/dist/assets/{web-components-C_DsTJis.js → web-components-BpncHjnV.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/plugins/featured.json +12 -0
- package/plugins/subagents/package.json +1 -1
- package/plugins/visuals/extension.js +7 -4
- package/plugins/visuals/package.json +1 -1
- package/server/index.js +86 -27
- package/server/lib/git/DOCUMENTATION.md +4 -0
- package/server/lib/git/service.js +70 -5
- package/server/lib/git/service.test.js +179 -0
- package/server/lib/github/DOCUMENTATION.md +2 -0
- package/server/lib/marketplace/DOCUMENTATION.md +95 -0
- package/server/lib/marketplace/featured.js +176 -0
- package/server/lib/marketplace/featured.test.js +207 -0
- package/server/lib/marketplace/npm-registry.js +255 -0
- package/server/lib/marketplace/npm-registry.test.js +227 -0
- package/server/lib/marketplace/routes.js +64 -0
- package/server/lib/marketplace/routes.test.js +119 -0
- package/server/lib/marketplace/service.js +225 -0
- package/server/lib/marketplace/service.test.js +174 -0
- package/server/lib/notifications/DOCUMENTATION.md +10 -4
- package/server/lib/notifications/pi-notification-watcher.js +92 -33
- package/server/lib/notifications/pi-notification-watcher.test.js +79 -0
- package/server/lib/open-url/DOCUMENTATION.md +1 -0
- package/server/lib/pi/merged-event-stream.js +316 -0
- package/server/lib/pi/merged-event-stream.test.js +95 -0
- package/server/lib/pi/routes-daemon-pool.test.js +348 -0
- package/server/lib/pi/routes-merged-events.test.js +327 -0
- package/server/lib/pi/routes-sandbox.test.js +1684 -0
- package/server/lib/pi/routes.js +491 -90
- package/server/lib/pi/routes.test.js +87 -2
- package/server/lib/pi/sandbox/DOCUMENTATION.md +68 -0
- package/server/lib/pi/sandbox/launcher.js +122 -0
- package/server/lib/pi/sandbox/launcher.test.js +91 -0
- package/server/lib/pi/sandbox/nono-launcher.js +455 -0
- package/server/lib/pi/sandbox/nono-launcher.test.js +371 -0
- package/server/lib/pi/sandbox/nono-profile-macos.json +20 -0
- package/server/lib/pi/sandbox/nono-profile-wsl2.json +21 -0
- package/server/lib/pi/sandbox/nono-profile.json +22 -0
- package/server/lib/pi/sandbox/project-sandbox-manager.js +1461 -0
- package/server/lib/pi/sandbox/project-sandbox-setting.js +166 -0
- package/server/lib/pi/sandbox/project-sandbox.js +207 -0
- package/server/lib/pi/sandbox/sandbox-routes.js +110 -0
- package/server/lib/pi/sandbox/sandboxed-folders.js +100 -0
- package/server/lib/pi/sandbox/sandboxed-folders.test.js +65 -0
- package/server/lib/pi/sandbox/trust-ask.js +135 -0
- package/server/lib/pi/sandbox/trust-ask.test.js +54 -0
- package/server/lib/pi/sandbox/worktree-ids.js +96 -0
- package/server/lib/pi/sandbox/worktree-ids.test.js +73 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +26 -6
- package/server/lib/pi/session-daemon/daemon-pool.js +157 -0
- package/server/lib/pi/session-daemon/daemon-process.js +10 -1
- package/server/lib/pi/session-daemon/extension-config.js +206 -23
- package/server/lib/pi/session-daemon/extension-config.test.js +180 -0
- package/server/lib/pi/session-daemon/session-daemon-read-persisted.test.js +167 -0
- package/server/lib/pi/session-daemon/session-daemon.js +368 -56
- package/server/lib/pi/session-daemon/session-daemon.test.js +227 -0
- package/server/lib/pi/session-daemon/session-idle-residency.test.js +98 -1
- package/server/lib/pi/session-daemon/session-jsonl.js +49 -10
- package/server/lib/pi/session-daemon/session-jsonl.test.js +11 -0
- package/server/lib/pi/session-daemon/session-lease.js +93 -15
- package/server/lib/pi/session-daemon/session-lease.test.js +107 -1
- package/server/lib/pi/session-daemon/supervisor-launcher-stop.test.js +295 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox-nono.e2e.test.js +301 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox.test.js +444 -0
- package/server/lib/pi/session-daemon/supervisor.js +386 -35
- package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
- package/server/lib/pi/ui-settings-store.js +88 -2
- package/server/lib/pi/ui-settings-store.test.js +118 -0
- package/server/lib/plugins/DOCUMENTATION.md +17 -5
- package/server/lib/plugins/daemon-sync.js +16 -6
- package/server/lib/plugins/daemon-sync.test.js +12 -0
- package/server/lib/plugins/impact.test.js +2 -1
- package/server/lib/plugins/manifest.js +25 -0
- package/server/lib/plugins/manifest.test.js +9 -0
- package/server/lib/plugins/routes.test.js +28 -0
- package/server/lib/plugins/service.js +24 -2
- package/server/lib/server/cross-process-lock.js +28 -3
- package/dist/assets/SettingsView-BHBpt2Um.js +0 -7
- package/dist/assets/VisualFrame-CJrAvWSo.js +0 -22
- package/dist/assets/VisualsArtifact-DqLGgU-Q.js +0 -1
- package/dist/assets/index-B2v0_mez.js +0 -11
- package/dist/assets/index-D3F4JrPN.css +0 -1
- package/dist/assets/renderMobileApp-B7cT7m5b.js +0 -11
- package/dist/assets/runtimeEndpointReset-BC6yGnxN.js +0 -62
- package/dist/assets/useAppFontEffects-EcTZ_I_I.js +0 -225
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { createServer as createHttpServer } from 'node:http';
|
|
4
|
+
import { createServer as createNetServer } from 'node:net';
|
|
5
|
+
import { homedir, tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
import { createOpenUrlIntake } from '../../open-url/intake.js';
|
|
9
|
+
import { createNonoLauncher } from '../sandbox/nono-launcher.js';
|
|
10
|
+
import { prepareProjectSandbox } from '../sandbox/project-sandbox.js';
|
|
11
|
+
import { getPiSessionDirectory } from './session-jsonl.js';
|
|
12
|
+
import { readSessionLeaseOwner } from './session-lease.js';
|
|
13
|
+
import { createSandboxedPiSessionDaemonSupervisor } from './supervisor.js';
|
|
14
|
+
|
|
15
|
+
// Runs only where nono can sandbox: Linux or WSL2 with Landlock, or macOS,
|
|
16
|
+
// with nono >= 0.82.0. Linux CI and the development container have no
|
|
17
|
+
// Landlock, so this skips there; the macOS CI job runs it. Run it on a
|
|
18
|
+
// Landlock machine before a release.
|
|
19
|
+
const probe = await createNonoLauncher().probe();
|
|
20
|
+
// WSL2 cannot mediate pathname Unix sockets (nono-launcher.js HOST_LIMITS).
|
|
21
|
+
const unixSocketsMediated = !probe.limits?.includes('UNIX_SOCKETS');
|
|
22
|
+
|
|
23
|
+
// Run inside the sandbox by the turn's bash tool: exits 0 when the attempt
|
|
24
|
+
// succeeds.
|
|
25
|
+
const PROBE_SCRIPT = `
|
|
26
|
+
import { connect } from 'node:net';
|
|
27
|
+
const [kind, target] = process.argv.slice(2);
|
|
28
|
+
const done = (ok) => process.exit(ok ? 0 : 1);
|
|
29
|
+
setTimeout(() => done(false), 8000);
|
|
30
|
+
const socket = kind === 'unix' ? connect(target) : connect(Number(target.split(':')[1]), target.split(':')[0]);
|
|
31
|
+
socket.on('connect', () => done(true)).on('error', () => done(false));
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const listen = (server, ...args) => new Promise((resolve) => server.listen(...args, () => resolve(server)));
|
|
35
|
+
|
|
36
|
+
// CI sets this where nono must work, so a broken probe fails instead of
|
|
37
|
+
// skipping the suite.
|
|
38
|
+
describe.runIf(process.env.PICHAMBER_REQUIRE_NONO_E2E === '1')('nono on a host that requires the e2e test', () => {
|
|
39
|
+
it('can sandbox', () => {
|
|
40
|
+
expect(probe).toMatchObject({ available: true });
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// The faux model answers the first prompt with one bash tool call carrying
|
|
45
|
+
// the prompt text as its command, then with plain text.
|
|
46
|
+
const EXTENSION = `
|
|
47
|
+
import { fauxProvider, fauxAssistantMessage, fauxToolCall } from '@earendil-works/pi-ai';
|
|
48
|
+
|
|
49
|
+
const lastUserText = (context) => {
|
|
50
|
+
const message = [...context.messages].reverse().find((entry) => entry.role === 'user');
|
|
51
|
+
if (!message) return '';
|
|
52
|
+
return typeof message.content === 'string'
|
|
53
|
+
? message.content
|
|
54
|
+
: message.content.map((part) => part.text || '').join('');
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default function (pi) {
|
|
58
|
+
const faux = fauxProvider({
|
|
59
|
+
provider: 'sandbox-mock-provider',
|
|
60
|
+
models: [{
|
|
61
|
+
id: 'sandbox-mock-model',
|
|
62
|
+
name: 'Sandbox Mock Model',
|
|
63
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
64
|
+
contextWindow: 16384,
|
|
65
|
+
maxTokens: 2048,
|
|
66
|
+
}],
|
|
67
|
+
tokensPerSecond: 1000,
|
|
68
|
+
});
|
|
69
|
+
faux.setResponses([
|
|
70
|
+
(context) => fauxAssistantMessage(
|
|
71
|
+
[fauxToolCall('bash', { command: lastUserText(context) }, { id: 'call-sandbox-1' })],
|
|
72
|
+
{ stopReason: 'toolUse' },
|
|
73
|
+
),
|
|
74
|
+
() => fauxAssistantMessage('done'),
|
|
75
|
+
]);
|
|
76
|
+
pi.registerProvider(faux.provider);
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
const waitForFile = async (path, timeoutMs = 60_000) => {
|
|
81
|
+
const deadline = Date.now() + timeoutMs;
|
|
82
|
+
while (Date.now() < deadline) {
|
|
83
|
+
try {
|
|
84
|
+
const text = await readFile(path, 'utf8');
|
|
85
|
+
if (text.includes('END')) return text;
|
|
86
|
+
} catch {
|
|
87
|
+
// not written yet
|
|
88
|
+
}
|
|
89
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Timed out waiting for ${path}`);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// The test's HOME holds nono's state folder (~/.local/state/nono), which
|
|
95
|
+
// nono refuses to start inside a folder its profile grants. macOS's temp
|
|
96
|
+
// folder sits under /private/var, which nono's macOS system group grants, so
|
|
97
|
+
// on macOS the test works under the real home, as a real home would be.
|
|
98
|
+
const testRootParent = process.platform === 'darwin' ? homedir() : tmpdir();
|
|
99
|
+
const roots = [];
|
|
100
|
+
const makeRoot = async () => {
|
|
101
|
+
const root = await mkdtemp(join(testRootParent, process.platform === 'darwin' ? '.pichamber-nono-e2e-' : 'pichamber-nono-e2e-'));
|
|
102
|
+
roots.push(root);
|
|
103
|
+
return root;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
describe.skipIf(!probe.available)('sandboxed daemon under real nono', () => {
|
|
107
|
+
let supervisor;
|
|
108
|
+
let intake;
|
|
109
|
+
|
|
110
|
+
afterEach(async () => {
|
|
111
|
+
await intake?.stop().catch(() => {});
|
|
112
|
+
intake = undefined;
|
|
113
|
+
await supervisor?.stop().catch(() => {});
|
|
114
|
+
supervisor = undefined;
|
|
115
|
+
// Kept on failure in CI, whose log step reads the daemon logs.
|
|
116
|
+
if (!process.env.CI) await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('lets a turn\'s bash tool write in the project and denies everything outside it', async () => {
|
|
120
|
+
const root = await makeRoot();
|
|
121
|
+
const home = join(root, 'home');
|
|
122
|
+
const agentDir = join(home, '.pi', 'agent');
|
|
123
|
+
const dataDir = join(root, 'data');
|
|
124
|
+
const project = join(root, 'code', 'projA');
|
|
125
|
+
const otherProject = join(root, 'code', 'projB');
|
|
126
|
+
const outside = join(root, 'outside');
|
|
127
|
+
await Promise.all([
|
|
128
|
+
mkdir(join(agentDir, 'extensions'), { recursive: true }),
|
|
129
|
+
mkdir(project, { recursive: true }),
|
|
130
|
+
mkdir(otherProject, { recursive: true }),
|
|
131
|
+
mkdir(outside, { recursive: true }),
|
|
132
|
+
]);
|
|
133
|
+
await writeFile(join(agentDir, 'extensions', 'sandbox-mock.ts'), EXTENSION);
|
|
134
|
+
const settings = JSON.stringify({ defaultProvider: 'sandbox-mock-provider', defaultModel: 'sandbox-mock-model' });
|
|
135
|
+
await writeFile(join(agentDir, 'settings.json'), settings);
|
|
136
|
+
await writeFile(join(agentDir, 'auth.json'), JSON.stringify({
|
|
137
|
+
'sandbox-mock-provider': { type: 'api_key', key: 'faux-test-key' },
|
|
138
|
+
}));
|
|
139
|
+
const otherSessions = getPiSessionDirectory({ cwd: otherProject, agentDir });
|
|
140
|
+
await mkdir(otherSessions, { recursive: true });
|
|
141
|
+
await writeFile(join(otherSessions, 'other.jsonl'), '{"type":"session"}\n');
|
|
142
|
+
// Stand-in for the main daemon's credential in the same data folder.
|
|
143
|
+
const mainCredential = join(dataDir, 'pi', 'daemons', 'web-p3000', 'session-daemon.key');
|
|
144
|
+
await mkdir(join(dataDir, 'pi', 'daemons', 'web-p3000'), { recursive: true });
|
|
145
|
+
await writeFile(mainCredential, 'main-daemon-credential\n');
|
|
146
|
+
const sharedLeases = join(agentDir, '.pichamber', 'locks', 'sessions');
|
|
147
|
+
await mkdir(sharedLeases, { recursive: true });
|
|
148
|
+
// The user's cache folders, so a refused write is the sandbox's doing.
|
|
149
|
+
await mkdir(join(home, '.cache'), { recursive: true });
|
|
150
|
+
await mkdir(join(home, 'Library', 'Caches'), { recursive: true });
|
|
151
|
+
|
|
152
|
+
const env = {
|
|
153
|
+
...process.env,
|
|
154
|
+
HOME: home,
|
|
155
|
+
PI_OFFLINE: '1',
|
|
156
|
+
PICHAMBER_DATA_DIR: dataDir,
|
|
157
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
158
|
+
// The server's own secret, which must not reach the sandbox.
|
|
159
|
+
PICHAMBER_UI_PASSWORD: 'server-ui-password',
|
|
160
|
+
// Short on purpose: the daemon socket path must fit a Unix socket address.
|
|
161
|
+
XDG_RUNTIME_DIR: await mkdtemp('/tmp/pcx-'),
|
|
162
|
+
};
|
|
163
|
+
// Local services outside the sandbox: a Unix socket (like the systemd
|
|
164
|
+
// user manager's or Docker's) and a loopback TCP server (like PiChamber's).
|
|
165
|
+
const outsideSocket = join(outside, 'service.sock');
|
|
166
|
+
const unixServer = await listen(createNetServer(), outsideSocket);
|
|
167
|
+
const tcpServer = await listen(createHttpServer((_request, response) => response.end('ok')), 0, '127.0.0.1');
|
|
168
|
+
// A local port the project allows (like a local model server).
|
|
169
|
+
const grantedServer = await listen(createHttpServer((_request, response) => response.end('ok')), 0, '127.0.0.1');
|
|
170
|
+
const grantedPort = grantedServer.address().port;
|
|
171
|
+
const probeFile = join(project, 'probe.mjs');
|
|
172
|
+
await writeFile(probeFile, PROBE_SCRIPT);
|
|
173
|
+
|
|
174
|
+
const sandbox = await prepareProjectSandbox({
|
|
175
|
+
dataDir, agentDir, projectRoot: project, serverPort: 3000, allowLocalPorts: [grantedPort],
|
|
176
|
+
});
|
|
177
|
+
supervisor = await createSandboxedPiSessionDaemonSupervisor({ env, port: 3000, launcher: createNonoLauncher(), sandbox });
|
|
178
|
+
await supervisor.start();
|
|
179
|
+
|
|
180
|
+
const results = join(project, 'results.txt');
|
|
181
|
+
const check = (name, command) => `if sh -c '${command}' >/dev/null 2>&1; then echo ${name}=allowed; else echo ${name}=denied; fi >> ${results}`;
|
|
182
|
+
const script = [
|
|
183
|
+
check('project', `echo x > ${join(project, 'inside.txt')}`),
|
|
184
|
+
check('outside', `echo x > ${join(outside, 'w.txt')}`),
|
|
185
|
+
check('otherSessionsRead', `cat ${join(otherSessions, 'other.jsonl')}`),
|
|
186
|
+
check('otherSessionsWrite', `echo x > ${join(otherSessions, 'planted.jsonl')}`),
|
|
187
|
+
check('otherProject', `ls ${otherProject}`),
|
|
188
|
+
check('piSettings', `echo pwn >> ${join(agentDir, 'settings.json')}`),
|
|
189
|
+
check('piExtensions', `mkdir ${join(agentDir, 'extensions', 'evil')}`),
|
|
190
|
+
// The session links the server makes: readable through the shadow,
|
|
191
|
+
// never changed from inside.
|
|
192
|
+
check('sessionLinks', `ln -s ${outside} ${join(dataDir, 'pi', 'sandbox', sandbox.projectKey, 'sessions', 'planted')}`),
|
|
193
|
+
check('mainCredential', `cat ${mainCredential}`),
|
|
194
|
+
// Its own credential is the server's file: readable (the daemon
|
|
195
|
+
// started on it), never writable or replaceable.
|
|
196
|
+
check('ownCredentialWrite', `echo x >> ${supervisor.paths.credentialFile}`),
|
|
197
|
+
check('ownCredentialReplace', `rm ${supervisor.paths.credentialFile}`),
|
|
198
|
+
check('serverSecret', 'test -n "$PICHAMBER_UI_PASSWORD"'),
|
|
199
|
+
// Other projects' live session leases.
|
|
200
|
+
check('sharedLeases', `ls ${sharedLeases}`),
|
|
201
|
+
// The user's cache folders are not the sandbox's; it has its own.
|
|
202
|
+
check('userCache', `echo x > "$HOME/.cache/probe" || echo x > "$HOME/Library/Caches/probe"`),
|
|
203
|
+
check('ownCache', `echo x > "$XDG_CACHE_HOME/probe"`),
|
|
204
|
+
check('unixOutside', `node ${probeFile} unix ${outsideSocket}`),
|
|
205
|
+
check('tcpLoopback', `node ${probeFile} tcp 127.0.0.1:${tcpServer.address().port}`),
|
|
206
|
+
check('tcpGranted', `node ${probeFile} tcp 127.0.0.1:${grantedPort}`),
|
|
207
|
+
`echo END >> ${results}`,
|
|
208
|
+
].join('; ');
|
|
209
|
+
|
|
210
|
+
const created = await supervisor.request('sessions.create', { cwd: project });
|
|
211
|
+
await supervisor.request('sessions.prompt', { sessionId: created.session.id, text: script });
|
|
212
|
+
const text = await waitForFile(results);
|
|
213
|
+
unixServer.close();
|
|
214
|
+
tcpServer.close();
|
|
215
|
+
grantedServer.close();
|
|
216
|
+
|
|
217
|
+
expect(text).toContain('project=allowed');
|
|
218
|
+
expect(text).toContain('outside=denied');
|
|
219
|
+
expect(text).toContain('otherSessionsRead=denied');
|
|
220
|
+
expect(text).toContain('otherSessionsWrite=denied');
|
|
221
|
+
expect(text).toContain('otherProject=denied');
|
|
222
|
+
expect(text).toContain('piSettings=denied');
|
|
223
|
+
expect(text).toContain('piExtensions=denied');
|
|
224
|
+
expect(text).toContain('sessionLinks=denied');
|
|
225
|
+
expect(text).toContain('mainCredential=denied');
|
|
226
|
+
expect(text).toContain('ownCredentialWrite=denied');
|
|
227
|
+
expect(text).toContain('ownCredentialReplace=denied');
|
|
228
|
+
expect(text).toContain('serverSecret=denied');
|
|
229
|
+
expect(text).toContain('sharedLeases=denied');
|
|
230
|
+
expect(text).toContain('userCache=denied');
|
|
231
|
+
expect(text).toContain('ownCache=allowed');
|
|
232
|
+
expect(text).toContain('tcpLoopback=denied');
|
|
233
|
+
expect(text).toContain('tcpGranted=allowed');
|
|
234
|
+
// The limit a WSL2 owner accepts: the socket is reachable there.
|
|
235
|
+
expect(text).toContain(unixSocketsMediated ? 'unixOutside=denied' : 'unixOutside=allowed');
|
|
236
|
+
await expect(readFile(join(agentDir, 'settings.json'), 'utf8')).resolves.toBe(settings);
|
|
237
|
+
// The transcript, written through the shadow's links, is in Pi's real
|
|
238
|
+
// session folder.
|
|
239
|
+
const realSessions = getPiSessionDirectory({ cwd: project, agentDir });
|
|
240
|
+
const deadline = Date.now() + 30_000;
|
|
241
|
+
let transcripts = [];
|
|
242
|
+
while (Date.now() < deadline) {
|
|
243
|
+
transcripts = (await readdir(realSessions)).filter((name) => name.endsWith('.jsonl'));
|
|
244
|
+
if (transcripts.length > 0) break;
|
|
245
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
246
|
+
}
|
|
247
|
+
expect(transcripts).toHaveLength(1);
|
|
248
|
+
}, 120_000);
|
|
249
|
+
|
|
250
|
+
it('keys its session lease on the real agent folder and reaches its own Open request intake', async () => {
|
|
251
|
+
const root = await makeRoot();
|
|
252
|
+
const home = join(root, 'home');
|
|
253
|
+
const agentDir = join(home, '.pi', 'agent');
|
|
254
|
+
const dataDir = join(root, 'data');
|
|
255
|
+
const project = join(root, 'code', 'projA');
|
|
256
|
+
await Promise.all([
|
|
257
|
+
mkdir(join(agentDir, 'extensions'), { recursive: true }),
|
|
258
|
+
mkdir(project, { recursive: true }),
|
|
259
|
+
]);
|
|
260
|
+
await writeFile(join(agentDir, 'extensions', 'sandbox-mock.ts'), EXTENSION);
|
|
261
|
+
await writeFile(join(agentDir, 'settings.json'), JSON.stringify({ defaultProvider: 'sandbox-mock-provider', defaultModel: 'sandbox-mock-model' }));
|
|
262
|
+
await writeFile(join(agentDir, 'auth.json'), JSON.stringify({
|
|
263
|
+
'sandbox-mock-provider': { type: 'api_key', key: 'faux-test-key' },
|
|
264
|
+
}));
|
|
265
|
+
const env = {
|
|
266
|
+
...process.env,
|
|
267
|
+
HOME: home,
|
|
268
|
+
PI_OFFLINE: '1',
|
|
269
|
+
PICHAMBER_DATA_DIR: dataDir,
|
|
270
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
271
|
+
XDG_RUNTIME_DIR: await mkdtemp('/tmp/pcx-'),
|
|
272
|
+
};
|
|
273
|
+
const sandbox = await prepareProjectSandbox({ dataDir, agentDir, projectRoot: project, serverPort: 3000 });
|
|
274
|
+
supervisor = await createSandboxedPiSessionDaemonSupervisor({ env, port: 3000, launcher: createNonoLauncher(), sandbox });
|
|
275
|
+
const published = [];
|
|
276
|
+
intake = createOpenUrlIntake({
|
|
277
|
+
socketPath: supervisor.paths.openUrlSocket,
|
|
278
|
+
publish: async (payload) => {
|
|
279
|
+
published.push(payload);
|
|
280
|
+
return { published: true };
|
|
281
|
+
},
|
|
282
|
+
hasConnectedDevices: () => true,
|
|
283
|
+
});
|
|
284
|
+
await intake.start();
|
|
285
|
+
await supervisor.start();
|
|
286
|
+
|
|
287
|
+
const results = join(project, 'results.txt');
|
|
288
|
+
const script = `"$BROWSER" https://example.test/from-sandbox >/dev/null 2>&1; echo END >> ${results}`;
|
|
289
|
+
const created = await supervisor.request('sessions.create', { cwd: project });
|
|
290
|
+
await supervisor.request('sessions.prompt', { sessionId: created.session.id, text: script });
|
|
291
|
+
await waitForFile(results);
|
|
292
|
+
|
|
293
|
+
// The lease sits in the project's own lease folder under the real agent
|
|
294
|
+
// folder, where a daemon outside the sandbox looks before it takes the
|
|
295
|
+
// session.
|
|
296
|
+
await expect(readSessionLeaseOwner({ agentDir, cwd: project, sessionId: created.session.id, scope: sandbox.leaseScope }))
|
|
297
|
+
.resolves.toMatchObject({ profileKey: supervisor.paths.profileKey });
|
|
298
|
+
await expect(readSessionLeaseOwner({ agentDir, cwd: project, sessionId: created.session.id })).resolves.toBeNull();
|
|
299
|
+
expect(published).toContainEqual(expect.objectContaining({ url: 'https://example.test/from-sandbox' }));
|
|
300
|
+
}, 120_000);
|
|
301
|
+
});
|