@pi-chamber/web 1.0.8-rc.1 → 1.0.8-rc.3

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 (146) hide show
  1. package/dist/assets/{AgentsSurface-BmHImX8m.js → AgentsSurface-wsW9VCRp.js} +1 -1
  2. package/dist/assets/{ChoicesArtifact-C71fGOm2.js → ChoicesArtifact-EwCf4Yxu.js} +1 -1
  3. package/dist/assets/{DiagramView-BZQxoiZu.js → DiagramView-BX6N99cQ.js} +1 -1
  4. package/dist/assets/{DiffView-C70pbgk-.js → DiffView-CI0eSnPP.js} +1 -1
  5. package/dist/assets/{FileSaveConflictDialog-Cu8c3gBV.js → FileSaveConflictDialog-GLj2W7VE.js} +1 -1
  6. package/dist/assets/{FilesView-nFJYEdRw.js → FilesView-CI0tfZQL.js} +1 -1
  7. package/dist/assets/{GitHubDetailScaffold-Jvv_tgbl.js → GitHubDetailScaffold-B85tZ9m7.js} +1 -1
  8. package/dist/assets/{GitHubLinkPicker-BXD2ODRi.js → GitHubLinkPicker-Y6AuNiGl.js} +1 -1
  9. package/dist/assets/{GitHubListPrimitives-BWI706F0.js → GitHubListPrimitives-BJHBud6i.js} +1 -1
  10. package/dist/assets/{GitView-MIDG5RYW.js → GitView-DueE69kW.js} +5 -5
  11. package/dist/assets/{IssuesSurface-uNlozeu0.js → IssuesSurface-Cg-xkdIu.js} +3 -3
  12. package/dist/assets/{JsonTreeView-CSLsTriz.js → JsonTreeView-Cvg6lc40.js} +1 -1
  13. package/dist/assets/{MarkdownRendererImpl-Cs-7BfWi.js → MarkdownRendererImpl-DExPx-QM.js} +1 -1
  14. package/dist/assets/{PatchDiff-axbsnbTJ.js → PatchDiff-_c3HZ34I.js} +1 -1
  15. package/dist/assets/{PierreDiffViewer-lwn6w_5w.js → PierreDiffViewer-CZnaqO-_.js} +1 -1
  16. package/dist/assets/{PullRequestsSurface-o_AXDjbO.js → PullRequestsSurface-C9AYPiwo.js} +2 -2
  17. package/dist/assets/{SessionSwitcherContent-C4CMlcbv.js → SessionSwitcherContent-DOpnN-8S.js} +1 -1
  18. package/dist/assets/{SessionSwitcherDropdown-DCBVuCoo.js → SessionSwitcherDropdown-CmHMPZ69.js} +2 -2
  19. package/dist/assets/{SessionUnreadDot-DyeIrsro.js → SessionUnreadDot-CZCQ4t1J.js} +1 -1
  20. package/dist/assets/SettingsView-D5PO5M3z.js +11 -0
  21. package/dist/assets/{SettingsWindow-Cb4st5y5.js → SettingsWindow-DXV5UOE8.js} +1 -1
  22. package/dist/assets/{SubagentsArtifact-BzeMEoFP.js → SubagentsArtifact-CO1ZiI1x.js} +1 -1
  23. package/dist/assets/{ToolOutputDialog-BP2mOWdV.js → ToolOutputDialog-GOwNLj-y.js} +1 -1
  24. package/dist/assets/{ToolPartDiffPreview-D49XBR9b.js → ToolPartDiffPreview-BoaiZji6.js} +1 -1
  25. package/dist/assets/{VirtualizedFileDiff-CLgDONEQ.js → VirtualizedFileDiff-Chq1X8nw.js} +1 -1
  26. package/dist/assets/VisualFrame-u7aRcX7O.js +22 -0
  27. package/dist/assets/VisualsArtifact-D9vPjihW.js +1 -0
  28. package/dist/assets/{collapsible-BeyKtQGB.js → collapsible-BjpDEohv.js} +1 -1
  29. package/dist/assets/{computeVirtualFileMetrics-DmO6H8u6.js → computeVirtualFileMetrics-DmPCxbok.js} +1 -1
  30. package/dist/assets/{contextFileOpenGuard-DOK251YW.js → contextFileOpenGuard-CukNcUeY.js} +1 -1
  31. package/dist/assets/{fileTreeStatus-CnzR7kxA.js → fileTreeStatus-CDyfNPYO.js} +1 -1
  32. package/dist/assets/{gitStatusPredicates-4kPg2t6j.js → gitStatusPredicates-uI7Y7L5k.js} +1 -1
  33. package/dist/assets/{githubLink-QvaLfNNT.js → githubLink-B9Mxac4R.js} +1 -1
  34. package/dist/assets/{index-DMX9wT1Z.js → index-BWq2ibCw.js} +1 -1
  35. package/dist/assets/index-BxKPJ9uG.js +11 -0
  36. package/dist/assets/index-C5JgjS20.css +1 -0
  37. package/dist/assets/{main-BirYxac2.js → main-CWfC-9xT.js} +4 -4
  38. package/dist/assets/{main-BW9J3Y72.js → main-ckQ0ciIN.js} +2 -2
  39. package/dist/assets/{markdownCore-CxmcPur8.js → markdownCore-p2q2Kxwo.js} +1 -1
  40. package/dist/assets/{miniChat-BRB11eEs.js → miniChat-x2TrwRYA.js} +2 -2
  41. package/dist/assets/{mobile-DJZYYCuB.js → mobile-B0x2G8h1.js} +2 -2
  42. package/dist/assets/{nativeFileSave-B6QpoPRn.js → nativeFileSave-D542OJlG.js} +1 -1
  43. package/dist/assets/{pi-session-focus-preference-PWoh3LNA.js → pi-session-focus-preference-Q_RZUCnt.js} +1 -1
  44. package/dist/assets/{renderDiffWithHighlighter-C48T6YFJ.js → renderDiffWithHighlighter-CSFGSknx.js} +1 -1
  45. package/dist/assets/{renderElectronMiniChatApp-N-BQdJl0.js → renderElectronMiniChatApp-CFIdesZT.js} +2 -2
  46. package/dist/assets/{renderFileWithHighlighter-8Kt2MyTN.js → renderFileWithHighlighter-C5JE0mRX.js} +1 -1
  47. package/dist/assets/renderMobileApp-B1ybjcGM.js +11 -0
  48. package/dist/assets/runtimeEndpointReset-DyZSKCYM.js +66 -0
  49. package/dist/assets/{runtimeSurface-kIEoYsPP.js → runtimeSurface-BR_dhe7_.js} +1 -1
  50. package/dist/assets/{selection-BTEdLRVK.js → selection-CfOpW4rA.js} +1 -1
  51. package/dist/assets/useAppFontEffects-COMvkffC.js +226 -0
  52. package/dist/assets/{useGitHubRemoteSearch-DIBHNu8r.js → useGitHubRemoteSearch-M1AE2YuX.js} +1 -1
  53. package/dist/assets/{useSwitcherItems-DfLbfX37.js → useSwitcherItems-D0i2BYYP.js} +1 -1
  54. package/dist/assets/{web-components-C_DsTJis.js → web-components-wOQkOurQ.js} +1 -1
  55. package/dist/index.html +4 -4
  56. package/dist/mini-chat.html +3 -3
  57. package/dist/mobile.html +3 -3
  58. package/package.json +1 -1
  59. package/plugins/featured.json +12 -0
  60. package/plugins/subagents/package.json +1 -1
  61. package/plugins/visuals/extension.js +8 -5
  62. package/plugins/visuals/package.json +1 -1
  63. package/server/index.js +90 -27
  64. package/server/lib/git/DOCUMENTATION.md +4 -0
  65. package/server/lib/git/service.js +70 -5
  66. package/server/lib/git/service.test.js +179 -0
  67. package/server/lib/github/DOCUMENTATION.md +2 -0
  68. package/server/lib/marketplace/DOCUMENTATION.md +95 -0
  69. package/server/lib/marketplace/featured.js +176 -0
  70. package/server/lib/marketplace/featured.test.js +207 -0
  71. package/server/lib/marketplace/npm-registry.js +255 -0
  72. package/server/lib/marketplace/npm-registry.test.js +227 -0
  73. package/server/lib/marketplace/routes.js +64 -0
  74. package/server/lib/marketplace/routes.test.js +119 -0
  75. package/server/lib/marketplace/service.js +225 -0
  76. package/server/lib/marketplace/service.test.js +174 -0
  77. package/server/lib/notifications/DOCUMENTATION.md +10 -4
  78. package/server/lib/notifications/pi-notification-watcher.js +92 -33
  79. package/server/lib/notifications/pi-notification-watcher.test.js +79 -0
  80. package/server/lib/open-url/DOCUMENTATION.md +1 -0
  81. package/server/lib/pi/merged-event-stream.js +316 -0
  82. package/server/lib/pi/merged-event-stream.test.js +95 -0
  83. package/server/lib/pi/routes-daemon-pool.test.js +348 -0
  84. package/server/lib/pi/routes-merged-events.test.js +327 -0
  85. package/server/lib/pi/routes-sandbox.test.js +1684 -0
  86. package/server/lib/pi/routes.js +491 -90
  87. package/server/lib/pi/routes.test.js +87 -2
  88. package/server/lib/pi/sandbox/DOCUMENTATION.md +68 -0
  89. package/server/lib/pi/sandbox/launcher.js +122 -0
  90. package/server/lib/pi/sandbox/launcher.test.js +91 -0
  91. package/server/lib/pi/sandbox/nono-launcher.js +455 -0
  92. package/server/lib/pi/sandbox/nono-launcher.test.js +371 -0
  93. package/server/lib/pi/sandbox/nono-profile-macos.json +20 -0
  94. package/server/lib/pi/sandbox/nono-profile-wsl2.json +21 -0
  95. package/server/lib/pi/sandbox/nono-profile.json +22 -0
  96. package/server/lib/pi/sandbox/project-sandbox-manager.js +1461 -0
  97. package/server/lib/pi/sandbox/project-sandbox-setting.js +166 -0
  98. package/server/lib/pi/sandbox/project-sandbox.js +207 -0
  99. package/server/lib/pi/sandbox/sandbox-routes.js +110 -0
  100. package/server/lib/pi/sandbox/sandboxed-folders.js +100 -0
  101. package/server/lib/pi/sandbox/sandboxed-folders.test.js +65 -0
  102. package/server/lib/pi/sandbox/trust-ask.js +135 -0
  103. package/server/lib/pi/sandbox/trust-ask.test.js +54 -0
  104. package/server/lib/pi/sandbox/worktree-ids.js +96 -0
  105. package/server/lib/pi/sandbox/worktree-ids.test.js +73 -0
  106. package/server/lib/pi/session-daemon/DOCUMENTATION.md +26 -6
  107. package/server/lib/pi/session-daemon/daemon-pool.js +157 -0
  108. package/server/lib/pi/session-daemon/daemon-process.js +10 -1
  109. package/server/lib/pi/session-daemon/extension-config.js +206 -23
  110. package/server/lib/pi/session-daemon/extension-config.test.js +180 -0
  111. package/server/lib/pi/session-daemon/session-daemon-read-persisted.test.js +167 -0
  112. package/server/lib/pi/session-daemon/session-daemon.js +368 -56
  113. package/server/lib/pi/session-daemon/session-daemon.test.js +227 -0
  114. package/server/lib/pi/session-daemon/session-idle-residency.test.js +98 -1
  115. package/server/lib/pi/session-daemon/session-jsonl.js +49 -10
  116. package/server/lib/pi/session-daemon/session-jsonl.test.js +11 -0
  117. package/server/lib/pi/session-daemon/session-lease.js +93 -15
  118. package/server/lib/pi/session-daemon/session-lease.test.js +107 -1
  119. package/server/lib/pi/session-daemon/supervisor-launcher-stop.test.js +295 -0
  120. package/server/lib/pi/session-daemon/supervisor-sandbox-nono.e2e.test.js +301 -0
  121. package/server/lib/pi/session-daemon/supervisor-sandbox.test.js +444 -0
  122. package/server/lib/pi/session-daemon/supervisor.js +386 -35
  123. package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
  124. package/server/lib/pi/ui-settings-store.js +90 -3
  125. package/server/lib/pi/ui-settings-store.test.js +118 -0
  126. package/server/lib/plugins/DOCUMENTATION.md +17 -5
  127. package/server/lib/plugins/daemon-sync.js +16 -6
  128. package/server/lib/plugins/daemon-sync.test.js +12 -0
  129. package/server/lib/plugins/impact.test.js +2 -1
  130. package/server/lib/plugins/manifest.js +25 -0
  131. package/server/lib/plugins/manifest.test.js +9 -0
  132. package/server/lib/plugins/routes.test.js +28 -0
  133. package/server/lib/plugins/service.js +24 -2
  134. package/server/lib/server/cross-process-lock.js +28 -3
  135. package/server/lib/wallpaper/DOCUMENTATION.md +25 -0
  136. package/server/lib/wallpaper/routes.js +63 -0
  137. package/server/lib/wallpaper/routes.test.js +109 -0
  138. package/server/lib/wallpaper/store.js +87 -0
  139. package/dist/assets/SettingsView-BHBpt2Um.js +0 -7
  140. package/dist/assets/VisualFrame-CJrAvWSo.js +0 -22
  141. package/dist/assets/VisualsArtifact-DqLGgU-Q.js +0 -1
  142. package/dist/assets/index-B2v0_mez.js +0 -11
  143. package/dist/assets/index-D3F4JrPN.css +0 -1
  144. package/dist/assets/renderMobileApp-B7cT7m5b.js +0 -11
  145. package/dist/assets/runtimeEndpointReset-BC6yGnxN.js +0 -62
  146. package/dist/assets/useAppFontEffects-EcTZ_I_I.js +0 -225
@@ -0,0 +1,371 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { chmod, mkdir, mkdtemp, readdir, readFile, stat, symlink, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+
6
+ import { createNonoLauncher, NONO_PROFILE_FILE, NONO_PROFILE_FILES } from './nono-launcher.js';
7
+
8
+ // A fake `nono` that answers `--version` and `setup --check-only` the way the
9
+ // real binary does (output captured from nono 0.82.0 on a Landlock V6 kernel
10
+ // and on this repo's no-Landlock development container).
11
+ const writeFakeNono = async ({ version = 'nono 0.82.0', versionCode = 0, setupOutput, setupCode = 0 }) => {
12
+ const dir = await mkdtemp(join(tmpdir(), 'pichamber-fake-nono-'));
13
+ const file = join(dir, 'nono');
14
+ await writeFile(file, [
15
+ '#!/bin/sh',
16
+ 'if [ "$1" = "--version" ]; then',
17
+ ` printf '%s\\n' '${version}'`,
18
+ ` exit ${versionCode}`,
19
+ 'fi',
20
+ 'if [ "$1" = "setup" ] && [ "$2" = "--check-only" ]; then',
21
+ ` printf '%s\\n' '${setupOutput.replace(/'/g, '')}'`,
22
+ ` exit ${setupCode}`,
23
+ 'fi',
24
+ 'exit 64',
25
+ '',
26
+ ].join('\n'));
27
+ await chmod(file, 0o755);
28
+ return file;
29
+ };
30
+
31
+ const LANDLOCK_OK = [
32
+ '[2/4] Testing sandbox support...',
33
+ ' * Landlock enabled (syscall probe)',
34
+ ' * Landlock V6',
35
+ ].join('\n');
36
+
37
+ const NO_LANDLOCK = 'nono: Setup error: Landlock is not available: Sandbox initialization failed: No supported Landlock ABI detected';
38
+
39
+ describe('nono launcher probe', () => {
40
+ it('reports an installed nono on a Landlock kernel as available with its version and ABI', async () => {
41
+ const command = await writeFakeNono({ setupOutput: LANDLOCK_OK });
42
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => 'Linux version 6.12.0' });
43
+ await expect(launcher.probe()).resolves.toEqual({
44
+ available: true,
45
+ version: '0.82.0',
46
+ capabilities: ['landlock-abi-6'],
47
+ });
48
+ });
49
+
50
+ it('maps a missing binary to NOT_INSTALLED', async () => {
51
+ const launcher = createNonoLauncher({ command: join(tmpdir(), 'pichamber-no-such-nono', 'nono'), platform: 'linux', readProcVersion: async () => '' });
52
+ await expect(launcher.probe()).resolves.toEqual({ available: false, code: 'NOT_INSTALLED' });
53
+ });
54
+
55
+ it('maps a version below 0.82.0 to TOO_OLD', async () => {
56
+ const command = await writeFakeNono({ version: 'nono 0.81.9', setupOutput: LANDLOCK_OK });
57
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => '' });
58
+ await expect(launcher.probe()).resolves.toEqual({ available: false, code: 'TOO_OLD' });
59
+ });
60
+
61
+ it('maps a kernel without Landlock to NO_LANDLOCK', async () => {
62
+ const command = await writeFakeNono({ setupOutput: NO_LANDLOCK, setupCode: 1 });
63
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => '' });
64
+ await expect(launcher.probe()).resolves.toEqual({ available: false, code: 'NO_LANDLOCK' });
65
+ });
66
+
67
+ it('maps any other failed setup check to SETUP_CHECK_FAILED', async () => {
68
+ const command = await writeFakeNono({ setupOutput: 'nono: something else went wrong', setupCode: 2 });
69
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => '' });
70
+ await expect(launcher.probe()).resolves.toEqual({ available: false, code: 'SETUP_CHECK_FAILED' });
71
+ });
72
+
73
+ it('maps unreadable version output to VERSION_UNKNOWN', async () => {
74
+ const command = await writeFakeNono({ version: 'garbage', setupOutput: LANDLOCK_OK });
75
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => '' });
76
+ await expect(launcher.probe()).resolves.toEqual({ available: false, code: 'VERSION_UNKNOWN' });
77
+ });
78
+
79
+ it('reports Windows as UNSUPPORTED_PLATFORM without running nono', async () => {
80
+ const command = await writeFakeNono({ setupOutput: LANDLOCK_OK });
81
+ const launcher = createNonoLauncher({ command, platform: 'win32', readProcVersion: async () => '' });
82
+ await expect(launcher.probe()).resolves.toEqual({ available: false, code: 'UNSUPPORTED_PLATFORM' });
83
+ });
84
+ });
85
+
86
+ const WSL_KERNEL = 'Linux version 6.18.33.2-microsoft-standard-WSL2';
87
+ // The lines nono 0.82.0 prints on macOS (`test_macos_seatbelt` in its setup.rs).
88
+ const SEATBELT_OK = [
89
+ '[2/4] Testing sandbox support...',
90
+ ' * macOS version: 15.5',
91
+ ' * Seatbelt sandbox support verified',
92
+ ' * File access restrictions: OK',
93
+ ].join('\n');
94
+
95
+ const profileArg = async (launcher) => {
96
+ const { args } = await launcher.prepare({ argv: ['node'], grants: [], network: { mode: 'none' }, tmpDir: '/tmp/x' });
97
+ return args[args.indexOf('--profile') + 1];
98
+ };
99
+
100
+ describe('nono launcher on WSL2', () => {
101
+ it('runs with the WSL2 profile and reports its Unix socket and proxy port limits', async () => {
102
+ const command = await writeFakeNono({ setupOutput: LANDLOCK_OK });
103
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => WSL_KERNEL });
104
+ await expect(launcher.probe()).resolves.toEqual({
105
+ available: true,
106
+ version: '0.82.0',
107
+ capabilities: ['landlock-abi-6'],
108
+ limits: ['UNIX_SOCKETS', 'PROXY_PORT'],
109
+ });
110
+ await expect(profileArg(launcher)).resolves.toBe(NONO_PROFILE_FILES.wsl2);
111
+ });
112
+
113
+ it('maps a WSL2 kernel without Landlock TCP rules (below V4) to WSL_KERNEL_TOO_OLD', async () => {
114
+ const command = await writeFakeNono({ setupOutput: ' * Landlock enabled (syscall probe)\n * Landlock V3' });
115
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => 'Linux version 6.6.87.2-microsoft-standard-WSL2' });
116
+ await expect(launcher.probe()).resolves.toEqual({ available: false, code: 'WSL_KERNEL_TOO_OLD' });
117
+ });
118
+
119
+ it('keeps AF_UNIX mediation in the Linux profile and leaves it out only for WSL2', async () => {
120
+ const linux = JSON.parse(await readFile(NONO_PROFILE_FILES.linux, 'utf8'));
121
+ const wsl2 = JSON.parse(await readFile(NONO_PROFILE_FILES.wsl2, 'utf8'));
122
+ expect(linux.linux).toEqual({ af_unix_mediation: 'pathname' });
123
+ const { linux: _mediation, ...linuxWithoutMediation } = linux;
124
+ expect(wsl2).toEqual(linuxWithoutMediation);
125
+ });
126
+ });
127
+
128
+ describe('nono launcher on macOS', () => {
129
+ it('reports a verified Seatbelt sandbox as available and runs with the macOS profile', async () => {
130
+ const command = await writeFakeNono({ setupOutput: SEATBELT_OK });
131
+ const launcher = createNonoLauncher({ command, platform: 'darwin' });
132
+ await expect(launcher.probe()).resolves.toEqual({ available: true, version: '0.82.0', capabilities: ['seatbelt'] });
133
+ await expect(profileArg(launcher)).resolves.toBe(NONO_PROFILE_FILES.macos);
134
+ });
135
+
136
+ it('maps a failed or unverified Seatbelt check to SETUP_CHECK_FAILED', async () => {
137
+ for (const run of [
138
+ { setupOutput: 'Seatbelt sandbox test failed. This may indicate a system configuration issue.', setupCode: 1 },
139
+ { setupOutput: ' * macOS version: 15.5', setupCode: 0 },
140
+ ]) {
141
+ const launcher = createNonoLauncher({ command: await writeFakeNono(run), platform: 'darwin' });
142
+ await expect(launcher.probe()).resolves.toEqual({ available: false, code: 'SETUP_CHECK_FAILED' });
143
+ }
144
+ });
145
+
146
+ it('keeps temp folders out of the macOS profile, as the Linux one does', async () => {
147
+ const macos = JSON.parse(await readFile(NONO_PROFILE_FILES.macos, 'utf8'));
148
+ // system_write_macos would grant all of /tmp and /var/folders.
149
+ expect(macos.groups.exclude).toEqual(['system_write_macos']);
150
+ expect(macos.workdir).toEqual({ access: 'none' });
151
+ expect(macos.security).toEqual({ signal_mode: 'isolated', capability_elevation: false });
152
+ });
153
+
154
+ it('grants local ports with --open-port, since nono refuses --allow-connect-port on macOS', async () => {
155
+ const launcher = createNonoLauncher({ command: await writeFakeNono({ setupOutput: SEATBELT_OK }), platform: 'darwin' });
156
+ await launcher.probe();
157
+ const networkArgs = async (network) => {
158
+ const { args } = await launcher.prepare({ argv: ['node'], grants: [], network, tmpDir: '/tmp/x' });
159
+ return args.slice(args.indexOf('--no-diagnostics') + 1, args.indexOf('--'));
160
+ };
161
+ await expect(networkArgs({ mode: 'proxy', allowHosts: ['github.com'], allowLocalPorts: [8080] }))
162
+ .resolves.toEqual(['--allow-domain', 'github.com', '--open-port', '8080']);
163
+ // Blocked mode keeps the localhost port rules, so ports alone stay blocked otherwise.
164
+ await expect(networkArgs({ mode: 'proxy', allowHosts: [], allowLocalPorts: [8080] }))
165
+ .resolves.toEqual(['--block-net', '--open-port', '8080']);
166
+ await expect(networkArgs({ mode: 'proxy', allowHosts: [], allowLocalPorts: [] })).resolves.toEqual(['--block-net']);
167
+ await expect(networkArgs({ mode: 'proxy', allowHosts: [], allowLocalPorts: [443] })).rejects.toMatchObject({ code: 'SANDBOX_PORT_REFUSED' });
168
+ });
169
+
170
+ it('gives the same request a different identity on each host kind', async () => {
171
+ const request = { grants: [], network: { mode: 'none' } };
172
+ const linux = createNonoLauncher({ command: await writeFakeNono({ setupOutput: LANDLOCK_OK }), platform: 'linux', readProcVersion: async () => '' });
173
+ const macos = createNonoLauncher({ command: await writeFakeNono({ setupOutput: SEATBELT_OK }), platform: 'darwin' });
174
+ await linux.probe();
175
+ await macos.probe();
176
+ expect(linux.identity(request)).not.toBe(macos.identity(request));
177
+ });
178
+ });
179
+
180
+ describe('nono launcher profile file', () => {
181
+ // A packaged desktop app keeps the server package inside app.asar. Electron
182
+ // reads files there, but nono is a separate binary and cannot, so the
183
+ // profile is copied to a real file before launch.
184
+ it('copies a profile that sits inside an asar archive to a real file nono can read', async () => {
185
+ const root = await mkdtemp(join(tmpdir(), 'pichamber-nono-asar-'));
186
+ const packaged = join(root, 'resources', 'app.asar', 'node_modules', '@pi-chamber', 'web', 'server', 'lib', 'pi', 'sandbox');
187
+ await mkdir(packaged, { recursive: true });
188
+ const profileFile = join(packaged, 'nono-profile.json');
189
+ const policy = await readFile(NONO_PROFILE_FILE, 'utf8');
190
+ await writeFile(profileFile, policy);
191
+ const stageDir = join(root, 'data', 'pi', 'sandbox');
192
+ const command = await writeFakeNono({ setupOutput: LANDLOCK_OK });
193
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => '', profileFile, stageDir });
194
+ await launcher.probe();
195
+
196
+ const { args } = await launcher.prepare({ argv: ['node', 'daemon.js'], grants: [], network: { mode: 'none' }, tmpDir: '/tmp/x' });
197
+ const staged = args[args.indexOf('--profile') + 1];
198
+ expect(staged.startsWith(`${stageDir}/`)).toBe(true);
199
+ expect(staged).not.toMatch(/\.asar/);
200
+ await expect(readFile(staged, 'utf8')).resolves.toBe(policy);
201
+ expect((await stat(staged)).mode & 0o777).toBe(0o600);
202
+ });
203
+
204
+ it('passes a profile outside any archive unchanged', async () => {
205
+ const command = await writeFakeNono({ setupOutput: LANDLOCK_OK });
206
+ const stageDir = join(await mkdtemp(join(tmpdir(), 'pichamber-nono-stage-')), 'sandbox');
207
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => '', stageDir });
208
+ await launcher.probe();
209
+ const { args } = await launcher.prepare({ argv: ['node'], grants: [], network: { mode: 'none' }, tmpDir: '/tmp/x' });
210
+ expect(args[args.indexOf('--profile') + 1]).toBe(NONO_PROFILE_FILE);
211
+ });
212
+ it('points tool caches at the sandbox cache folder, over anything inherited', async () => {
213
+ const command = await writeFakeNono({ setupOutput: LANDLOCK_OK });
214
+ const stageDir = join(await mkdtemp(join(tmpdir(), 'pichamber-nono-stage-')), 'sandbox');
215
+ const launcher = createNonoLauncher({ command, platform: 'linux', readProcVersion: async () => '', stageDir });
216
+ await launcher.probe();
217
+ const { env } = await launcher.prepare({
218
+ argv: ['node'],
219
+ env: { XDG_CACHE_HOME: '/home/u/.cache', npm_config_cache: '/home/u/.npm', KEEP: '1' },
220
+ grants: [],
221
+ network: { mode: 'none' },
222
+ tmpDir: '/data/sandbox/k/tmp',
223
+ cacheDir: '/data/sandbox/k/cache',
224
+ });
225
+ expect(env).toMatchObject({
226
+ KEEP: '1',
227
+ TMPDIR: '/data/sandbox/k/tmp',
228
+ XDG_CACHE_HOME: '/data/sandbox/k/cache',
229
+ npm_config_cache: '/data/sandbox/k/cache/npm',
230
+ PIP_CACHE_DIR: '/data/sandbox/k/cache/pip',
231
+ UV_CACHE_DIR: '/data/sandbox/k/cache/uv',
232
+ PLAYWRIGHT_BROWSERS_PATH: '/data/sandbox/k/cache/ms-playwright',
233
+ });
234
+ await expect(launcher.prepare({ argv: ['node'], grants: [], network: { mode: 'none' }, tmpDir: '/tmp/x', cacheDir: 'cache' }))
235
+ .rejects.toMatchObject({ code: 'SANDBOX_INVALID_GRANT' });
236
+ });
237
+
238
+ // What is cached in the user's cache folders is run later by tools outside
239
+ // the sandbox, and a pseudo-terminal the sandbox can write belongs to
240
+ // someone's shell. No profile may grant either.
241
+ it('grants no user cache folder and no writable pseudo-terminals in any profile', async () => {
242
+ for (const file of Object.values(NONO_PROFILE_FILES)) {
243
+ const profile = JSON.parse(await readFile(file, 'utf8'));
244
+ const groups = profile.groups.include.map((group) => (typeof group === 'string' ? group : group.name));
245
+ expect(groups.filter((name) => /cache/i.test(name))).toEqual([]);
246
+ const paths = [...(profile.filesystem.allow ?? []), ...(profile.filesystem.allow_file ?? [])];
247
+ expect(paths.filter((path) => /^\/dev\/(pts|ptmx)/.test(path) || /cache/i.test(path))).toEqual([]);
248
+ }
249
+ });
250
+ });
251
+
252
+ // A fake `nono` that also answers `profile validate --json <file>` the way
253
+ // nono 0.82.0 does: a JSON report on stdout, exit 1 when not valid. A profile
254
+ // naming `nope_group` is the invalid one.
255
+ const writeValidatingNono = async () => {
256
+ const dir = await mkdtemp(join(tmpdir(), 'pichamber-fake-nono-'));
257
+ const file = join(dir, 'nono');
258
+ await writeFile(file, [
259
+ '#!/bin/sh',
260
+ 'if [ "$1" = "--version" ]; then echo "nono 0.82.0"; exit 0; fi',
261
+ 'if [ "$1" = "setup" ]; then echo " * Landlock V6"; exit 0; fi',
262
+ 'if [ "$1" = "profile" ] && [ "$2" = "validate" ]; then',
263
+ ' if grep -q nope_group "$4"; then',
264
+ ' printf \'{"file":"%s","valid":false,"errors":["Group nope_group not found in %s"],"warnings":[]}\\n\' "$4" "$4"',
265
+ ' echo "nono: Profile parse error: validation failed" >&2',
266
+ ' exit 1',
267
+ ' fi',
268
+ ' printf \'{"file":"%s","valid":true,"errors":[],"warnings":[]}\\n\' "$4"',
269
+ ' exit 0',
270
+ 'fi',
271
+ 'exit 64',
272
+ '',
273
+ ].join('\n'));
274
+ await chmod(file, 0o755);
275
+ return file;
276
+ };
277
+
278
+ describe('nono launcher custom profile', () => {
279
+ const request = { grants: [], network: { mode: 'none' } };
280
+ const prepareArgs = { argv: ['node'], grants: [], network: { mode: 'none' }, tmpDir: '/tmp/x' };
281
+ const build = async ({ command } = {}) => {
282
+ const dir = await mkdtemp(join(tmpdir(), 'pichamber-nono-custom-'));
283
+ const customProfileFile = join(dir, 'sandbox', 'nono-profile.custom.json');
284
+ const launcher = createNonoLauncher({
285
+ command: command ?? await writeValidatingNono(),
286
+ platform: 'linux',
287
+ readProcVersion: async () => 'Linux version 6.12.0',
288
+ customProfileFile,
289
+ });
290
+ return { dir, customProfileFile, launcher };
291
+ };
292
+
293
+ it('reports the built-in profile of this host kind until a custom one is saved', async () => {
294
+ const { launcher, customProfileFile } = await build();
295
+ const profile = await launcher.profile();
296
+ expect(profile).toMatchObject({ hostKind: 'linux', custom: false, path: NONO_PROFILE_FILE, builtInPath: NONO_PROFILE_FILE, customPath: customProfileFile });
297
+ expect(profile.content).toBe(await readFile(NONO_PROFILE_FILE, 'utf8'));
298
+ });
299
+
300
+ it('has no profile on a platform nono does not run on', async () => {
301
+ const launcher = createNonoLauncher({ platform: 'win32', customProfileFile: '/nowhere/custom.json' });
302
+ expect(await launcher.profile()).toBeNull();
303
+ });
304
+
305
+ it('uses a saved custom profile for launches, with its own identity, and the built-in one again after a reset', async () => {
306
+ const { launcher, customProfileFile, dir } = await build();
307
+ await launcher.probe();
308
+ const builtIn = launcher.identity(request);
309
+ const content = await readFile(NONO_PROFILE_FILE, 'utf8');
310
+ const saved = await launcher.saveProfile(content);
311
+ expect(saved).toMatchObject({ custom: true, path: customProfileFile, content });
312
+ expect((await stat(customProfileFile)).mode & 0o777).toBe(0o600);
313
+ expect(await readdir(join(dir, 'sandbox'))).toEqual(['nono-profile.custom.json']);
314
+ // The same text as the built-in profile is still a different identity:
315
+ // a daemon started under one never passes for the other.
316
+ expect(launcher.identity(request)).not.toBe(builtIn);
317
+ const { args } = await launcher.prepare(prepareArgs);
318
+ expect(args[args.indexOf('--profile') + 1]).toBe(customProfileFile);
319
+
320
+ expect(await launcher.resetProfile()).toMatchObject({ custom: false, path: NONO_PROFILE_FILE });
321
+ expect(launcher.identity(request)).toBe(builtIn);
322
+ const again = await launcher.prepare(prepareArgs);
323
+ expect(again.args[again.args.indexOf('--profile') + 1]).toBe(NONO_PROFILE_FILE);
324
+ });
325
+
326
+ it('refuses text that is not a JSON object or that nono does not accept, and keeps the profile it had', async () => {
327
+ const { launcher, customProfileFile, dir } = await build();
328
+ await expect(launcher.saveProfile('')).rejects.toMatchObject({ code: 'INVALID_SANDBOX_PROFILE' });
329
+ await expect(launcher.saveProfile('{ nope')).rejects.toMatchObject({ code: 'INVALID_SANDBOX_PROFILE' });
330
+ await expect(launcher.saveProfile('[]')).rejects.toMatchObject({ code: 'INVALID_SANDBOX_PROFILE', messages: ['The profile must be a JSON object.'] });
331
+ await expect(launcher.saveProfile(JSON.stringify({ pad: 'x'.repeat(70 * 1024) }))).rejects.toMatchObject({ code: 'INVALID_SANDBOX_PROFILE' });
332
+ await launcher.saveProfile('{"extends":"default"}');
333
+ const refused = await launcher.saveProfile('{"groups":{"include":["nope_group"]}}').catch((error) => error);
334
+ expect(refused).toMatchObject({ code: 'INVALID_SANDBOX_PROFILE' });
335
+ // nono's message, without the temporary file it checked.
336
+ expect(refused.messages).toEqual(['Group nope_group not found in the profile']);
337
+ expect(await readFile(customProfileFile, 'utf8')).toBe('{"extends":"default"}');
338
+ expect(await readdir(join(dir, 'sandbox'))).toEqual(['nono-profile.custom.json']);
339
+ });
340
+
341
+ it('saves on a JSON check alone when nono is not installed', async () => {
342
+ const { launcher, customProfileFile } = await build({ command: join(tmpdir(), 'pichamber-no-such-nono', 'nono') });
343
+ await launcher.saveProfile('{"groups":{"include":["nope_group"]}}');
344
+ expect(await readFile(customProfileFile, 'utf8')).toContain('nope_group');
345
+ });
346
+
347
+ it('fails a launch closed when a custom profile edited on disk is not one nono accepts', async () => {
348
+ const { launcher, customProfileFile } = await build();
349
+ await launcher.probe();
350
+ await mkdir(join(customProfileFile, '..'), { recursive: true });
351
+ await writeFile(customProfileFile, '{"groups":{"include":["nope_group"]}}');
352
+ await expect(launcher.prepare(prepareArgs)).rejects.toMatchObject({ code: 'SANDBOX_PROFILE_INVALID' });
353
+ await writeFile(customProfileFile, 'not json');
354
+ await expect(launcher.prepare(prepareArgs)).rejects.toMatchObject({ code: 'SANDBOX_PROFILE_INVALID' });
355
+ await writeFile(customProfileFile, '{"extends":"default"}');
356
+ const { args } = await launcher.prepare(prepareArgs);
357
+ expect(args[args.indexOf('--profile') + 1]).toBe(customProfileFile);
358
+ });
359
+
360
+ it('never follows a symlink at the custom profile, and does not fall back to the built-in one', async () => {
361
+ const { launcher, customProfileFile } = await build();
362
+ await launcher.probe();
363
+ await mkdir(join(customProfileFile, '..'), { recursive: true });
364
+ await symlink(NONO_PROFILE_FILE, customProfileFile);
365
+ expect(() => launcher.identity(request)).toThrow(expect.objectContaining({ code: 'SANDBOX_PROFILE_INVALID' }));
366
+ await expect(launcher.prepare(prepareArgs)).rejects.toMatchObject({ code: 'SANDBOX_PROFILE_INVALID' });
367
+ expect(await launcher.profile()).toMatchObject({ custom: true, unreadable: true, content: '' });
368
+ expect(await launcher.resetProfile()).toMatchObject({ custom: false });
369
+ expect(await readFile(NONO_PROFILE_FILE, 'utf8')).toContain('pichamber');
370
+ });
371
+ });
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "default",
3
+ "meta": { "name": "pichamber" },
4
+ "groups": {
5
+ "include": [
6
+ "node_runtime",
7
+ "rust_runtime",
8
+ "python_runtime",
9
+ "nix_runtime",
10
+ "git_config"
11
+ ],
12
+ "exclude": ["system_write_macos"]
13
+ },
14
+ "security": { "signal_mode": "isolated", "capability_elevation": false },
15
+ "workdir": { "access": "none" },
16
+ "filesystem": {
17
+ "allow_file": ["/dev/null", "/dev/zero", "/dev/tty"],
18
+ "allow": ["/dev/fd"]
19
+ }
20
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": "default",
3
+ "meta": { "name": "pichamber" },
4
+ "groups": {
5
+ "include": [
6
+ "node_runtime",
7
+ "rust_runtime",
8
+ "python_runtime",
9
+ "nix_runtime",
10
+ "git_config",
11
+ { "name": "linux_sysfs_read", "when": "linux" }
12
+ ],
13
+ "exclude": ["system_write_linux"]
14
+ },
15
+ "security": { "signal_mode": "isolated", "capability_elevation": false },
16
+ "workdir": { "access": "none" },
17
+ "filesystem": {
18
+ "allow_file": ["/dev/null", "/dev/zero", "/dev/full", "/dev/tty"],
19
+ "allow": ["/proc/self/fd", "/dev/fd"]
20
+ }
21
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "default",
3
+ "meta": { "name": "pichamber" },
4
+ "groups": {
5
+ "include": [
6
+ "node_runtime",
7
+ "rust_runtime",
8
+ "python_runtime",
9
+ "nix_runtime",
10
+ "git_config",
11
+ { "name": "linux_sysfs_read", "when": "linux" }
12
+ ],
13
+ "exclude": ["system_write_linux"]
14
+ },
15
+ "security": { "signal_mode": "isolated", "capability_elevation": false },
16
+ "linux": { "af_unix_mediation": "pathname" },
17
+ "workdir": { "access": "none" },
18
+ "filesystem": {
19
+ "allow_file": ["/dev/null", "/dev/zero", "/dev/full", "/dev/tty"],
20
+ "allow": ["/proc/self/fd", "/dev/fd"]
21
+ }
22
+ }