@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.
- package/dist/assets/{AgentsSurface-BmHImX8m.js → AgentsSurface-wsW9VCRp.js} +1 -1
- package/dist/assets/{ChoicesArtifact-C71fGOm2.js → ChoicesArtifact-EwCf4Yxu.js} +1 -1
- package/dist/assets/{DiagramView-BZQxoiZu.js → DiagramView-BX6N99cQ.js} +1 -1
- package/dist/assets/{DiffView-C70pbgk-.js → DiffView-CI0eSnPP.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-Cu8c3gBV.js → FileSaveConflictDialog-GLj2W7VE.js} +1 -1
- package/dist/assets/{FilesView-nFJYEdRw.js → FilesView-CI0tfZQL.js} +1 -1
- package/dist/assets/{GitHubDetailScaffold-Jvv_tgbl.js → GitHubDetailScaffold-B85tZ9m7.js} +1 -1
- package/dist/assets/{GitHubLinkPicker-BXD2ODRi.js → GitHubLinkPicker-Y6AuNiGl.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-BWI706F0.js → GitHubListPrimitives-BJHBud6i.js} +1 -1
- package/dist/assets/{GitView-MIDG5RYW.js → GitView-DueE69kW.js} +5 -5
- package/dist/assets/{IssuesSurface-uNlozeu0.js → IssuesSurface-Cg-xkdIu.js} +3 -3
- package/dist/assets/{JsonTreeView-CSLsTriz.js → JsonTreeView-Cvg6lc40.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cs-7BfWi.js → MarkdownRendererImpl-DExPx-QM.js} +1 -1
- package/dist/assets/{PatchDiff-axbsnbTJ.js → PatchDiff-_c3HZ34I.js} +1 -1
- package/dist/assets/{PierreDiffViewer-lwn6w_5w.js → PierreDiffViewer-CZnaqO-_.js} +1 -1
- package/dist/assets/{PullRequestsSurface-o_AXDjbO.js → PullRequestsSurface-C9AYPiwo.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-C4CMlcbv.js → SessionSwitcherContent-DOpnN-8S.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-DCBVuCoo.js → SessionSwitcherDropdown-CmHMPZ69.js} +2 -2
- package/dist/assets/{SessionUnreadDot-DyeIrsro.js → SessionUnreadDot-CZCQ4t1J.js} +1 -1
- package/dist/assets/SettingsView-D5PO5M3z.js +11 -0
- package/dist/assets/{SettingsWindow-Cb4st5y5.js → SettingsWindow-DXV5UOE8.js} +1 -1
- package/dist/assets/{SubagentsArtifact-BzeMEoFP.js → SubagentsArtifact-CO1ZiI1x.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BP2mOWdV.js → ToolOutputDialog-GOwNLj-y.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-D49XBR9b.js → ToolPartDiffPreview-BoaiZji6.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-CLgDONEQ.js → VirtualizedFileDiff-Chq1X8nw.js} +1 -1
- package/dist/assets/VisualFrame-u7aRcX7O.js +22 -0
- package/dist/assets/VisualsArtifact-D9vPjihW.js +1 -0
- package/dist/assets/{collapsible-BeyKtQGB.js → collapsible-BjpDEohv.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DmO6H8u6.js → computeVirtualFileMetrics-DmPCxbok.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DOK251YW.js → contextFileOpenGuard-CukNcUeY.js} +1 -1
- package/dist/assets/{fileTreeStatus-CnzR7kxA.js → fileTreeStatus-CDyfNPYO.js} +1 -1
- package/dist/assets/{gitStatusPredicates-4kPg2t6j.js → gitStatusPredicates-uI7Y7L5k.js} +1 -1
- package/dist/assets/{githubLink-QvaLfNNT.js → githubLink-B9Mxac4R.js} +1 -1
- package/dist/assets/{index-DMX9wT1Z.js → index-BWq2ibCw.js} +1 -1
- package/dist/assets/index-BxKPJ9uG.js +11 -0
- package/dist/assets/index-C5JgjS20.css +1 -0
- package/dist/assets/{main-BirYxac2.js → main-CWfC-9xT.js} +4 -4
- package/dist/assets/{main-BW9J3Y72.js → main-ckQ0ciIN.js} +2 -2
- package/dist/assets/{markdownCore-CxmcPur8.js → markdownCore-p2q2Kxwo.js} +1 -1
- package/dist/assets/{miniChat-BRB11eEs.js → miniChat-x2TrwRYA.js} +2 -2
- package/dist/assets/{mobile-DJZYYCuB.js → mobile-B0x2G8h1.js} +2 -2
- package/dist/assets/{nativeFileSave-B6QpoPRn.js → nativeFileSave-D542OJlG.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-PWoh3LNA.js → pi-session-focus-preference-Q_RZUCnt.js} +1 -1
- package/dist/assets/{renderDiffWithHighlighter-C48T6YFJ.js → renderDiffWithHighlighter-CSFGSknx.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-N-BQdJl0.js → renderElectronMiniChatApp-CFIdesZT.js} +2 -2
- package/dist/assets/{renderFileWithHighlighter-8Kt2MyTN.js → renderFileWithHighlighter-C5JE0mRX.js} +1 -1
- package/dist/assets/renderMobileApp-B1ybjcGM.js +11 -0
- package/dist/assets/runtimeEndpointReset-DyZSKCYM.js +66 -0
- package/dist/assets/{runtimeSurface-kIEoYsPP.js → runtimeSurface-BR_dhe7_.js} +1 -1
- package/dist/assets/{selection-BTEdLRVK.js → selection-CfOpW4rA.js} +1 -1
- package/dist/assets/useAppFontEffects-COMvkffC.js +226 -0
- package/dist/assets/{useGitHubRemoteSearch-DIBHNu8r.js → useGitHubRemoteSearch-M1AE2YuX.js} +1 -1
- package/dist/assets/{useSwitcherItems-DfLbfX37.js → useSwitcherItems-D0i2BYYP.js} +1 -1
- package/dist/assets/{web-components-C_DsTJis.js → web-components-wOQkOurQ.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 +8 -5
- package/plugins/visuals/package.json +1 -1
- package/server/index.js +90 -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 +90 -3
- 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/server/lib/wallpaper/DOCUMENTATION.md +25 -0
- package/server/lib/wallpaper/routes.js +63 -0
- package/server/lib/wallpaper/routes.test.js +109 -0
- package/server/lib/wallpaper/store.js +87 -0
- 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
|
@@ -4,6 +4,7 @@ import { dirname, join } from 'node:path';
|
|
|
4
4
|
import { writeFileAtomic } from '../fs/atomic-write.js';
|
|
5
5
|
import { resolvePiChamberDataDir } from '../pichamber-data-dir.js';
|
|
6
6
|
import { withCrossProcessLock } from '../server/cross-process-lock.js';
|
|
7
|
+
import { mergeProjectSandboxSetting, mergeSandboxDefaults, ProjectSandboxSettingError, readSandboxDefaults } from './sandbox/project-sandbox-setting.js';
|
|
7
8
|
|
|
8
9
|
const MAX_SETTINGS_BYTES = 2 * 1024 * 1024;
|
|
9
10
|
const PORTABLE_SETTINGS_MARKER = '__pichamberSettingsScope';
|
|
@@ -48,7 +49,8 @@ const PORTABLE_FIELDS = new Set([
|
|
|
48
49
|
'recentAgents', 'recentEfforts', 'diffLayoutPreference', 'gitChangesViewMode',
|
|
49
50
|
'filesViewShowGitignored', 'messageLimit',
|
|
50
51
|
'responseStyleEnabled', 'responseStylePreset', 'responseStyleCustomInstructions',
|
|
51
|
-
'draftStarters', 'draftStartersVisible', 'draftStartersScheduleTaskAdded',
|
|
52
|
+
'draftStarters', 'draftStartersVisible', 'draftStartersScheduleTaskAdded', 'draftWallpaper', 'draftWallpaperMotion',
|
|
53
|
+
'draftWallpaperPicture', 'draftWallpaperInSessions', 'draftWallpaperImageVersion',
|
|
52
54
|
'autoCreateWorktree', 'globalBehaviorPrompt', 'skillCatalogs', 'messageStreamTransport',
|
|
53
55
|
]);
|
|
54
56
|
|
|
@@ -56,7 +58,7 @@ const PORTABLE_FIELDS = new Set([
|
|
|
56
58
|
// still be consumed by the existing authenticated API without entering the
|
|
57
59
|
// portable file.
|
|
58
60
|
const LOCAL_FIELDS = new Set([
|
|
59
|
-
'lastDirectory', 'homeDirectory', 'projects', 'activeProjectId',
|
|
61
|
+
'lastDirectory', 'homeDirectory', 'projects', 'activeProjectId', 'sandboxDefaults',
|
|
60
62
|
'securityScopedBookmarks', 'pinnedDirectories', 'openInAppId',
|
|
61
63
|
'terminalShell', 'terminalLoginShells', 'desktopLanAccessEnabled',
|
|
62
64
|
'desktopKeepAwakeEnabled', 'desktopProcessPerformanceRecordingEnabled',
|
|
@@ -156,6 +158,28 @@ export const createDockerInitialLocalSettings = () => {
|
|
|
156
158
|
};
|
|
157
159
|
};
|
|
158
160
|
|
|
161
|
+
// A project's `sandbox` setting changes only through `setProjectSandbox`.
|
|
162
|
+
// Clients write the whole project list back and drop fields they do not
|
|
163
|
+
// know, so the stored setting is carried over by project id and any value a
|
|
164
|
+
// client sends is ignored. Without this an older client could turn a
|
|
165
|
+
// project's sandbox off just by reordering projects.
|
|
166
|
+
const withoutSandbox = (project) => {
|
|
167
|
+
if (!isRecord(project) || !Object.hasOwn(project, 'sandbox')) return project;
|
|
168
|
+
const { sandbox: _ignored, ...rest } = project;
|
|
169
|
+
return rest;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const carrySandboxSettings = (incoming, current) => {
|
|
173
|
+
if (!Array.isArray(incoming)) return incoming;
|
|
174
|
+
const stored = new Map((Array.isArray(current) ? current : [])
|
|
175
|
+
.filter((project) => isRecord(project) && typeof project.id === 'string' && Object.hasOwn(project, 'sandbox'))
|
|
176
|
+
.map((project) => [project.id, project.sandbox]));
|
|
177
|
+
return incoming.map((project) => {
|
|
178
|
+
const next = withoutSandbox(project);
|
|
179
|
+
return isRecord(next) && stored.has(next.id) ? { ...next, sandbox: stored.get(next.id) } : next;
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
|
|
159
183
|
const writeRecord = async (file, value, fs) => {
|
|
160
184
|
const serialized = `${JSON.stringify(value, null, 2)}\n`;
|
|
161
185
|
if (Buffer.byteLength(serialized) > MAX_SETTINGS_BYTES) throw new Error('UI_SETTINGS_INVALID');
|
|
@@ -185,6 +209,13 @@ export const createPiUiSettingsStore = ({
|
|
|
185
209
|
...selectFields(runtimeRoot, LOCAL_FIELDS),
|
|
186
210
|
...selectFields(portableRoot, LOCAL_FIELDS),
|
|
187
211
|
};
|
|
212
|
+
// A legacy flat settings.json may have come from another machine; a
|
|
213
|
+
// sandbox setting is only ever made on this host.
|
|
214
|
+
delete migratedRuntime.sandboxDefaults;
|
|
215
|
+
if (Object.hasOwn(runtimeRoot, 'sandboxDefaults')) migratedRuntime.sandboxDefaults = runtimeRoot.sandboxDefaults;
|
|
216
|
+
if (Object.hasOwn(selectFields(portableRoot, LOCAL_FIELDS), 'projects')) {
|
|
217
|
+
migratedRuntime.projects = carrySandboxSettings(portableRoot.projects, runtimeRoot.projects);
|
|
218
|
+
}
|
|
188
219
|
const migratedPortable = {
|
|
189
220
|
[PORTABLE_SETTINGS_MARKER]: PORTABLE_SETTINGS_VERSION,
|
|
190
221
|
...selectFields(portableRoot, PORTABLE_FIELDS),
|
|
@@ -239,6 +270,12 @@ export const createPiUiSettingsStore = ({
|
|
|
239
270
|
const current = await readLocked();
|
|
240
271
|
const portableChanges = selectFields(changes, PORTABLE_FIELDS);
|
|
241
272
|
const localChanges = selectFields(changes, LOCAL_FIELDS);
|
|
273
|
+
if (Object.hasOwn(localChanges, 'projects')) {
|
|
274
|
+
localChanges.projects = carrySandboxSettings(localChanges.projects, current.projects);
|
|
275
|
+
}
|
|
276
|
+
// Like a project's setting, the sandbox default changes only through
|
|
277
|
+
// `setSandboxDefaults`.
|
|
278
|
+
delete localChanges.sandboxDefaults;
|
|
242
279
|
const nextPortable = {
|
|
243
280
|
[PORTABLE_SETTINGS_MARKER]: PORTABLE_SETTINGS_VERSION,
|
|
244
281
|
...selectFields(current, PORTABLE_FIELDS),
|
|
@@ -254,5 +291,55 @@ export const createPiUiSettingsStore = ({
|
|
|
254
291
|
});
|
|
255
292
|
};
|
|
256
293
|
|
|
257
|
-
|
|
294
|
+
/**
|
|
295
|
+
* Save one project's sandbox setting (host-local only). `patch` holds
|
|
296
|
+
* `mode`, `allowHosts`, `allowLocalPorts`, `extraFolders`, or several; a
|
|
297
|
+
* field it leaves out keeps the stored value. The merge happens under the
|
|
298
|
+
* store lock, so a device that only adds a host cannot turn off a sandbox
|
|
299
|
+
* another device just turned on.
|
|
300
|
+
*/
|
|
301
|
+
const setProjectSandbox = async (projectId, patch) => {
|
|
302
|
+
// Refuse a malformed patch before taking the lock.
|
|
303
|
+
mergeProjectSandboxSetting(null, patch);
|
|
304
|
+
return runMutation(async () => {
|
|
305
|
+
const current = await readLocked();
|
|
306
|
+
const projects = Array.isArray(current.projects) ? current.projects : [];
|
|
307
|
+
const stored = typeof projectId === 'string'
|
|
308
|
+
? projects.find((project) => isRecord(project) && project.id === projectId)
|
|
309
|
+
: undefined;
|
|
310
|
+
if (!stored) throw new ProjectSandboxSettingError(undefined, 'PROJECT_NOT_FOUND');
|
|
311
|
+
const sandbox = mergeProjectSandboxSetting(stored, patch);
|
|
312
|
+
const nextRuntime = {
|
|
313
|
+
...selectFields(current, LOCAL_FIELDS),
|
|
314
|
+
projects: projects.map((project) => (isRecord(project) && project.id === projectId ? { ...project, sandbox } : project)),
|
|
315
|
+
};
|
|
316
|
+
await writeRecord(runtimeFile, nextRuntime, fs);
|
|
317
|
+
return { ...selectFields(current, PORTABLE_FIELDS), ...selectFields(nextRuntime, LOCAL_FIELDS) };
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Save the host's sandbox default (host-local only). `patch` holds `mode`,
|
|
323
|
+
* `allowHosts`, or both; a field it leaves out keeps the stored value. The
|
|
324
|
+
* merge happens under the store lock, so a device that only adds a host
|
|
325
|
+
* cannot undo a mode another device just set.
|
|
326
|
+
*/
|
|
327
|
+
const setSandboxDefaults = async (patch) => {
|
|
328
|
+
// Refuse a malformed patch before taking the lock.
|
|
329
|
+
mergeSandboxDefaults(readSandboxDefaults({}).defaults, patch);
|
|
330
|
+
return runMutation(async () => {
|
|
331
|
+
const current = await readLocked();
|
|
332
|
+
const stored = readSandboxDefaults(current);
|
|
333
|
+
// The mode of an unreadable stored default is a placeholder (off),
|
|
334
|
+
// while projects that follow it stay closed. A patch without a mode
|
|
335
|
+
// would store that placeholder and run them unsandboxed.
|
|
336
|
+
if (stored.invalid && patch.mode === undefined) throw new ProjectSandboxSettingError('MODE');
|
|
337
|
+
const sandboxDefaults = mergeSandboxDefaults(stored.defaults, patch);
|
|
338
|
+
const nextRuntime = { ...selectFields(current, LOCAL_FIELDS), sandboxDefaults };
|
|
339
|
+
await writeRecord(runtimeFile, nextRuntime, fs);
|
|
340
|
+
return { ...selectFields(current, PORTABLE_FIELDS), ...selectFields(nextRuntime, LOCAL_FIELDS) };
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
return { file, runtimeFile, read, write, setProjectSandbox, setSandboxDefaults };
|
|
258
345
|
};
|
|
@@ -407,4 +407,122 @@ describe('Pi UI settings store', () => {
|
|
|
407
407
|
expect(await readlink(file)).toBe('../dotfiles/settings.json');
|
|
408
408
|
expect(await readJson(target)).toMatchObject({ themeId: 'new' });
|
|
409
409
|
});
|
|
410
|
+
|
|
411
|
+
describe('project sandbox setting', () => {
|
|
412
|
+
const nono = { mode: 'nono', allowHosts: ['registry.npmjs.org'], allowLocalPorts: [8080], extraFolders: [{ path: '/srv/docs', access: 'read' }] };
|
|
413
|
+
|
|
414
|
+
it('stores the setting with the project in host-local state and survives a restart', async () => {
|
|
415
|
+
const { file, runtimeFile, store } = await makeStore();
|
|
416
|
+
await store.write({ projects: [{ id: 'one', path: '/work/one' }, { id: 'two', path: '/work/two' }] });
|
|
417
|
+
|
|
418
|
+
await store.setProjectSandbox('one', nono);
|
|
419
|
+
|
|
420
|
+
const restarted = createPiUiSettingsStore({ file, runtimeFile });
|
|
421
|
+
await expect(restarted.read()).resolves.toMatchObject({
|
|
422
|
+
projects: [{ id: 'one', path: '/work/one', sandbox: nono }, { id: 'two', path: '/work/two' }],
|
|
423
|
+
});
|
|
424
|
+
expect((await readJson(runtimeFile)).projects[0].sandbox).toEqual(nono);
|
|
425
|
+
// The portable file, the one copied between machines, never holds it.
|
|
426
|
+
expect(JSON.stringify(await readJson(file))).not.toContain('sandbox');
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('keeps the setting when a client rewrites the project list without it, and ignores one a client sends', async () => {
|
|
430
|
+
const { store } = await makeStore();
|
|
431
|
+
await store.write({ projects: [{ id: 'one', path: '/work/one' }, { id: 'two', path: '/work/two' }] });
|
|
432
|
+
await store.setProjectSandbox('one', nono);
|
|
433
|
+
|
|
434
|
+
// Clients send the whole list back (for example after a reorder) and
|
|
435
|
+
// drop fields they do not know. Neither path may change the setting.
|
|
436
|
+
await store.write({
|
|
437
|
+
projects: [
|
|
438
|
+
{ id: 'two', path: '/work/two', sandbox: { mode: 'nono', allowHosts: [], allowLocalPorts: [], extraFolders: [] } },
|
|
439
|
+
{ id: 'one', path: '/work/one', label: 'One' },
|
|
440
|
+
],
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
await expect(store.read()).resolves.toMatchObject({
|
|
444
|
+
projects: [{ id: 'two', path: '/work/two' }, { id: 'one', path: '/work/one', label: 'One', sandbox: nono }],
|
|
445
|
+
});
|
|
446
|
+
expect((await store.read()).projects[0].sandbox).toBeUndefined();
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it('turns the setting off, and refuses an unknown project or an invalid setting', async () => {
|
|
450
|
+
const { store } = await makeStore();
|
|
451
|
+
await store.write({ projects: [{ id: 'one', path: '/work/one' }] });
|
|
452
|
+
await store.setProjectSandbox('one', nono);
|
|
453
|
+
await store.setProjectSandbox('one', { ...nono, mode: 'off' });
|
|
454
|
+
await expect(store.read()).resolves.toMatchObject({ projects: [{ id: 'one', sandbox: { ...nono, mode: 'off' } }] });
|
|
455
|
+
|
|
456
|
+
await expect(store.setProjectSandbox('missing', nono)).rejects.toMatchObject({ code: 'PROJECT_NOT_FOUND' });
|
|
457
|
+
for (const [invalid, reason] of [
|
|
458
|
+
[{ mode: 'docker' }, undefined],
|
|
459
|
+
[{ mode: 'nono', allowHosts: ['https://x'] }, 'HOSTS'],
|
|
460
|
+
[{ mode: 'nono', allowLocalPorts: [443] }, 'REFUSED_PORT'],
|
|
461
|
+
[{ mode: 'nono', allowLocalPorts: [70000] }, 'PORTS'],
|
|
462
|
+
[{ mode: 'nono', extraFolders: [{ path: 'relative', access: 'read' }] }, 'FOLDERS'],
|
|
463
|
+
[{ mode: 'nono', extraFolders: [{ path: '/srv', access: 'write' }] }, 'FOLDERS'],
|
|
464
|
+
]) {
|
|
465
|
+
const refused = await store.setProjectSandbox('one', invalid).catch((error) => error);
|
|
466
|
+
expect(refused).toMatchObject({ code: 'INVALID_SANDBOX_SETTING' });
|
|
467
|
+
expect(refused.reason).toBe(reason);
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it('merges the fields a project update names, so a stale copy cannot turn a sandbox off', async () => {
|
|
472
|
+
const { store, runtimeFile } = await makeStore();
|
|
473
|
+
await store.write({ projects: [{ id: 'one', path: '/work/one' }] });
|
|
474
|
+
// A project with no setting starts from the default with empty lists.
|
|
475
|
+
await store.setProjectSandbox('one', { allowHosts: ['github.com'] });
|
|
476
|
+
await expect(store.read()).resolves.toMatchObject({
|
|
477
|
+
projects: [{ id: 'one', sandbox: { mode: 'default', allowHosts: ['github.com'], allowLocalPorts: [], extraFolders: [] } }],
|
|
478
|
+
});
|
|
479
|
+
// One device turns it on; another, still showing Off, adds a port.
|
|
480
|
+
await store.setProjectSandbox('one', { mode: 'nono' });
|
|
481
|
+
await store.setProjectSandbox('one', { allowLocalPorts: [8080] });
|
|
482
|
+
await expect(store.read()).resolves.toMatchObject({
|
|
483
|
+
projects: [{ id: 'one', sandbox: { mode: 'nono', allowHosts: ['github.com'], allowLocalPorts: [8080], extraFolders: [] } }],
|
|
484
|
+
});
|
|
485
|
+
// No field at all is refused.
|
|
486
|
+
await expect(store.setProjectSandbox('one', {})).rejects.toMatchObject({ code: 'INVALID_SANDBOX_SETTING' });
|
|
487
|
+
|
|
488
|
+
// An unreadable stored setting runs sandboxed, so that is what a
|
|
489
|
+
// partial update starts from.
|
|
490
|
+
const state = JSON.parse(await readFile(runtimeFile, 'utf8'));
|
|
491
|
+
state.projects[0].sandbox = { mode: 'sometimes' };
|
|
492
|
+
await writeFile(runtimeFile, JSON.stringify(state));
|
|
493
|
+
await store.setProjectSandbox('one', { allowHosts: ['npmjs.org'] });
|
|
494
|
+
await expect(store.read()).resolves.toMatchObject({
|
|
495
|
+
projects: [{ id: 'one', sandbox: { mode: 'nono', allowHosts: ['npmjs.org'], allowLocalPorts: [], extraFolders: [] } }],
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it('does not store the placeholder mode of an unreadable default: an update must name a mode', async () => {
|
|
500
|
+
const { store, runtimeFile } = await makeStore();
|
|
501
|
+
await store.write({ projects: [{ id: 'one', path: '/work/one' }] });
|
|
502
|
+
const state = JSON.parse(await readFile(runtimeFile, 'utf8'));
|
|
503
|
+
await writeFile(runtimeFile, JSON.stringify({ ...state, sandboxDefaults: { mode: 'sometimes' } }));
|
|
504
|
+
for (const patch of [{ acceptedLimits: [] }, { allowHosts: ['github.com'] }]) {
|
|
505
|
+
const refused = await store.setSandboxDefaults(patch).catch((error) => error);
|
|
506
|
+
expect(refused).toMatchObject({ code: 'INVALID_SANDBOX_SETTING', reason: 'MODE' });
|
|
507
|
+
}
|
|
508
|
+
expect(JSON.parse(await readFile(runtimeFile, 'utf8')).sandboxDefaults).toEqual({ mode: 'sometimes' });
|
|
509
|
+
await store.setSandboxDefaults({ mode: 'nono', allowHosts: ['github.com'] });
|
|
510
|
+
expect((await store.read()).sandboxDefaults).toEqual({ mode: 'nono', allowHosts: ['github.com'], acceptedLimits: [] });
|
|
511
|
+
// Readable again: a later update may leave the mode out.
|
|
512
|
+
await store.setSandboxDefaults({ allowHosts: [] });
|
|
513
|
+
expect((await store.read()).sandboxDefaults.mode).toBe('nono');
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it('never takes a sandbox setting from a settings file copied from another machine', async () => {
|
|
517
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-ui-settings-'));
|
|
518
|
+
const file = join(root, 'settings.json');
|
|
519
|
+
const runtimeFile = join(root, 'runtime-state.json');
|
|
520
|
+
// A legacy flat file still carries projects; its local fields migrate,
|
|
521
|
+
// but a sandbox setting is only ever made on this host.
|
|
522
|
+
await writeFile(file, JSON.stringify({ projects: [{ id: 'one', path: '/work/one', sandbox: nono }] }));
|
|
523
|
+
const store = createPiUiSettingsStore({ file, runtimeFile });
|
|
524
|
+
const read = await store.read();
|
|
525
|
+
expect(read.projects).toEqual([{ id: 'one', path: '/work/one' }]);
|
|
526
|
+
});
|
|
527
|
+
});
|
|
410
528
|
});
|
|
@@ -24,7 +24,10 @@ disabled, and a disabled plugin loads no agent code.
|
|
|
24
24
|
bound to a boolean key; optional), `contributes.settings` (ordered keys,
|
|
25
25
|
never a key a composer toggle sets), and
|
|
26
26
|
`contributes.ui` (native UI id). The agent half must be a `.js`/`.mjs`
|
|
27
|
-
module inside the package. The package `version` is the plugin version
|
|
27
|
+
module inside the package. The package `version` is the plugin version,
|
|
28
|
+
its `name` is `packageName`, and its `keywords` (lowercased, at most 16,
|
|
29
|
+
without the listing keywords `pi-package` and `pichamber-plugin`) are
|
|
30
|
+
`keywords`, which the marketplace matches a search against.
|
|
28
31
|
- `registry.js` reads `packages/web/plugins/registry.json`
|
|
29
32
|
(`{ version: 1, plugins: [id] }`) and loads each listed folder. An invalid
|
|
30
33
|
plugin is skipped with a logged reason; the others still load. A missing or
|
|
@@ -90,9 +93,13 @@ disabled, and a disabled plugin loads no agent code.
|
|
|
90
93
|
- Errors: 404 `{ error: { code: 'PLUGIN_NOT_FOUND' } }`, 400
|
|
91
94
|
`INVALID_PLUGIN_REQUEST`, 500 `PLUGINS_UNREADABLE`.
|
|
92
95
|
|
|
93
|
-
`PluginView` is `{ id, name, description, icon, version,
|
|
94
|
-
state, stateSchema, contributes, impact, impactError? }`. It never
|
|
95
|
-
module paths.
|
|
96
|
+
`PluginView` is `{ id, name, description, icon, version, keywords, bundled,
|
|
97
|
+
enabled, state, stateSchema, contributes, impact, impactError? }`. It never
|
|
98
|
+
carries module paths.
|
|
99
|
+
|
|
100
|
+
`service.bundledPackageNames()` lists the npm names of the bundled plugins.
|
|
101
|
+
The marketplace (`../marketplace/`) leaves them out of every answer, since
|
|
102
|
+
PiChamber already ships them.
|
|
96
103
|
|
|
97
104
|
## Daemon push
|
|
98
105
|
|
|
@@ -128,6 +135,11 @@ When it pushes (`daemon-sync.js`):
|
|
|
128
135
|
- The last 32 epochs are remembered, so a daemon pool is configured per
|
|
129
136
|
daemon as each is reached. A change probes the profile daemon only; others
|
|
130
137
|
pick it up on their next request.
|
|
138
|
+
- A sandboxed project's daemon gets its hook from
|
|
139
|
+
`onDaemonReadyFor({ roots })`, the folders it owns. Its config is
|
|
140
|
+
`daemonConfig({ roots })`: `projects` keeps only folders at or below those
|
|
141
|
+
roots, so sandboxed code never learns where other projects live.
|
|
142
|
+
`sessions` holds opaque ids and values and is sent whole.
|
|
131
143
|
|
|
132
144
|
## Bundled plugins
|
|
133
145
|
|
|
@@ -183,4 +195,4 @@ state push leaves a tool list the user edited as it is.
|
|
|
183
195
|
|
|
184
196
|
## Replaced plugins
|
|
185
197
|
|
|
186
|
-
Pi leaves a `replaceable` extension out when another extension registers the same tool, command, or flag. Bundled plugins load as replaceable inline factories, so a plugin can be on in Settings and still not loaded (the user's own `subagent` extension replaces Sub-agents, for example). The server does nothing about this itself. The daemon reports it in the `replaced` field of the extension config answers (see `extension-replacements.js` and `plugin-host.js` in `../pi/session-daemon/DOCUMENTATION.md`), and the public routes `GET /api/pi/extensions/config`, `PUT /api/pi/extensions/config/:id`, and `DELETE /api/pi/extensions/packages/:id` pass it through `projectExtensionConfig` in `../pi/routes.js`. That projection keeps only `kind` (`plugin` or `builtin`), `id`, and the optional `registers` and `by`. It drops an entry with a bad kind or id, leaves out a malformed optional part, and copies nothing else. The field is absent when no live runtime answered, which means unknown, not "nothing replaced".
|
|
198
|
+
Pi leaves a `replaceable` extension out when another extension registers the same tool, command, or flag. Bundled plugins load as replaceable inline factories, so a plugin can be on in Settings and still not loaded (the user's own `subagent` extension replaces Sub-agents, for example). The server does nothing about this itself. The daemon reports it in the `replaced` field of the extension config answers (see `extension-replacements.js` and `plugin-host.js` in `../pi/session-daemon/DOCUMENTATION.md`), and the public routes `GET /api/pi/extensions/config`, `PUT /api/pi/extensions/config/:id`, `POST /api/pi/extensions/packages`, `POST /api/pi/extensions/packages/:id/update`, and `DELETE /api/pi/extensions/packages/:id` pass it through `projectExtensionConfig` in `../pi/routes.js`. That projection keeps only `kind` (`plugin` or `builtin`), `id`, and the optional `registers` and `by`. It drops an entry with a bad kind or id, leaves out a malformed optional part, and copies nothing else. The field is absent when no live runtime answered, which means unknown, not "nothing replaced".
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
// - again on a later request when a push failed (at most every `retryDelayMs`).
|
|
11
11
|
// A failed push only logs. The request it precedes still runs; a daemon that
|
|
12
12
|
// was never configured runs with every plugin off.
|
|
13
|
+
//
|
|
14
|
+
// A sandboxed project's daemon gets its own hook from `onDaemonReadyFor`,
|
|
15
|
+
// whose scope (`{ roots }`) reaches `buildConfig`, so the config it receives
|
|
16
|
+
// can leave out other projects.
|
|
13
17
|
|
|
14
18
|
const MAX_TRACKED_DAEMONS = 32;
|
|
15
19
|
|
|
@@ -32,7 +36,7 @@ export const createPluginDaemonSync = ({
|
|
|
32
36
|
while (configured.size > MAX_TRACKED_DAEMONS) configured.delete(configured.keys().next().value);
|
|
33
37
|
};
|
|
34
38
|
|
|
35
|
-
const push = (epoch, target, request) => {
|
|
39
|
+
const push = (epoch, target, request, scope) => {
|
|
36
40
|
const key = `${epoch}:${target}`;
|
|
37
41
|
const existing = inflight.get(key);
|
|
38
42
|
if (existing) return existing;
|
|
@@ -42,7 +46,7 @@ export const createPluginDaemonSync = ({
|
|
|
42
46
|
if (configured.get(epoch) === revision) return;
|
|
43
47
|
const pushing = revision;
|
|
44
48
|
try {
|
|
45
|
-
await request('plugins.configure', await buildConfig());
|
|
49
|
+
await request('plugins.configure', await buildConfig(scope));
|
|
46
50
|
remember(epoch, pushing);
|
|
47
51
|
lastFailure = null;
|
|
48
52
|
} catch (error) {
|
|
@@ -55,16 +59,22 @@ export const createPluginDaemonSync = ({
|
|
|
55
59
|
return task;
|
|
56
60
|
};
|
|
57
61
|
|
|
58
|
-
/**
|
|
59
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Supervisor hook for a daemon whose config is built with `scope`: runs
|
|
64
|
+
* after every successful health probe. Never throws.
|
|
65
|
+
*/
|
|
66
|
+
const onDaemonReadyFor = (scope) => async ({ health, request }) => {
|
|
60
67
|
const epoch = health?.streamEpoch;
|
|
61
68
|
if (typeof epoch !== 'string' || epoch.length === 0 || typeof request !== 'function') return;
|
|
62
69
|
if (configured.get(epoch) === revision) return;
|
|
63
70
|
if (lastFailure && lastFailure.epoch === epoch && lastFailure.revision === revision
|
|
64
71
|
&& now() - lastFailure.at < retryDelayMs) return;
|
|
65
|
-
await push(epoch, revision, request);
|
|
72
|
+
await push(epoch, revision, request, scope);
|
|
66
73
|
};
|
|
67
74
|
|
|
75
|
+
/** The main daemon's hook: its config covers every project. */
|
|
76
|
+
const onDaemonReady = onDaemonReadyFor(undefined);
|
|
77
|
+
|
|
68
78
|
/** Call after a committed change; pushes in the background. */
|
|
69
79
|
const changed = () => {
|
|
70
80
|
revision += 1;
|
|
@@ -74,5 +84,5 @@ export const createPluginDaemonSync = ({
|
|
|
74
84
|
});
|
|
75
85
|
};
|
|
76
86
|
|
|
77
|
-
return { onDaemonReady, changed };
|
|
87
|
+
return { onDaemonReady, onDaemonReadyFor, changed };
|
|
78
88
|
};
|
|
@@ -31,6 +31,18 @@ describe('plugin daemon sync', () => {
|
|
|
31
31
|
expect(request).toHaveBeenLastCalledWith('plugins.configure', config);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
+
it('builds a scoped hook\'s config with its scope', async () => {
|
|
35
|
+
const buildConfig = vi.fn(async (scope) => ({ plugins: [], scope: scope ?? null }));
|
|
36
|
+
const sync = createPluginDaemonSync({ buildConfig, logger: { warn: vi.fn() } });
|
|
37
|
+
const request = vi.fn(async () => ({}));
|
|
38
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'main' }, request });
|
|
39
|
+
await sync.onDaemonReadyFor({ roots: ['/work/night'] })({ health: { streamEpoch: 'sandbox' }, request });
|
|
40
|
+
expect(request.mock.calls).toEqual([
|
|
41
|
+
['plugins.configure', { plugins: [], scope: null }],
|
|
42
|
+
['plugins.configure', { plugins: [], scope: { roots: ['/work/night'] } }],
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
|
|
34
46
|
it('shares one push between concurrent requests', async () => {
|
|
35
47
|
const gate = deferred();
|
|
36
48
|
const sync = createPluginDaemonSync({ buildConfig: async () => ({ plugins: [] }) });
|
|
@@ -65,7 +65,8 @@ describe('plugin impact', () => {
|
|
|
65
65
|
{ name: 'render_html', exposure: 'direct', tokens: expect.any(Number) },
|
|
66
66
|
{ name: 'render_choices', exposure: 'direct', tokens: expect.any(Number) },
|
|
67
67
|
]);
|
|
68
|
-
|
|
68
|
+
// Includes the layout, text-size and colour rules that keep pages in the chat's look.
|
|
69
|
+
expect(impact.tools[0].tokens).toBeLessThan(330);
|
|
69
70
|
expect(impact.tools[1].tokens).toBeLessThan(400);
|
|
70
71
|
expect(impact.hooks).toEqual([]);
|
|
71
72
|
expect(impact.commands).toEqual([]);
|
|
@@ -18,6 +18,11 @@ const MAX_STATE_KEYS = 32;
|
|
|
18
18
|
const MAX_ENUM_OPTIONS = 32;
|
|
19
19
|
const MAX_TOGGLES = 4;
|
|
20
20
|
const FORBIDDEN_KEYS = new Set(['__proto__', 'prototype', 'constructor']);
|
|
21
|
+
// Discovery keywords every Pi package or PiChamber plugin carries; they say
|
|
22
|
+
// nothing about what one plugin does, so they are left out of its keywords.
|
|
23
|
+
const DISCOVERY_KEYWORDS = new Set(['pi-package', 'pichamber-plugin']);
|
|
24
|
+
const MAX_KEYWORDS = 16;
|
|
25
|
+
const MAX_KEYWORD_LENGTH = 40;
|
|
21
26
|
|
|
22
27
|
class PluginManifestError extends Error {
|
|
23
28
|
constructor(reason) {
|
|
@@ -149,6 +154,24 @@ const parseEntry = (packageJson, packageDir) => {
|
|
|
149
154
|
return absolute;
|
|
150
155
|
};
|
|
151
156
|
|
|
157
|
+
/**
|
|
158
|
+
* What the plugin is about, for matching a marketplace search to it: the
|
|
159
|
+
* package keywords without the discovery ones. Bad entries are skipped, not
|
|
160
|
+
* fatal, since they only help search.
|
|
161
|
+
*/
|
|
162
|
+
const parseKeywords = (value) => {
|
|
163
|
+
if (!Array.isArray(value)) return [];
|
|
164
|
+
const keywords = [];
|
|
165
|
+
for (const entry of value) {
|
|
166
|
+
if (typeof entry !== 'string') continue;
|
|
167
|
+
const keyword = entry.trim().toLowerCase();
|
|
168
|
+
if (keyword.length === 0 || keyword.length > MAX_KEYWORD_LENGTH || DISCOVERY_KEYWORDS.has(keyword) || keywords.includes(keyword)) continue;
|
|
169
|
+
keywords.push(keyword);
|
|
170
|
+
if (keywords.length === MAX_KEYWORDS) break;
|
|
171
|
+
}
|
|
172
|
+
return keywords;
|
|
173
|
+
};
|
|
174
|
+
|
|
152
175
|
/**
|
|
153
176
|
* Parse one plugin package. `packageDir` must be absolute. Returns the
|
|
154
177
|
* normalized manifest or throws `PluginManifestError`.
|
|
@@ -172,6 +195,8 @@ export const parsePluginPackage = (packageJson, { packageDir, bundled = false })
|
|
|
172
195
|
description: text(block.description, MAX_DESCRIPTION, 'pichamber.description'),
|
|
173
196
|
icon: icon(block.icon, 'pichamber.icon'),
|
|
174
197
|
version: packageJson.version,
|
|
198
|
+
...(typeof packageJson.name === 'string' && packageJson.name.length > 0 ? { packageName: packageJson.name } : {}),
|
|
199
|
+
keywords: parseKeywords(packageJson.keywords),
|
|
175
200
|
bundled,
|
|
176
201
|
defaultEnabled,
|
|
177
202
|
replaceable: block.replaceable === true,
|
|
@@ -80,6 +80,15 @@ describe('parsePluginPackage', () => {
|
|
|
80
80
|
expect(manifest.contributes.settings).toEqual(['allowNetwork']);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
+
it('keeps package keywords that say what it does', () => {
|
|
84
|
+
const manifest = parsePluginPackage(validPackage({}, {
|
|
85
|
+
keywords: ['pi-package', 'PiChamber-Plugin', 'Chart', 'chart', '', 7, 'x'.repeat(41), 'diagram'],
|
|
86
|
+
}), { packageDir });
|
|
87
|
+
expect(manifest.packageName).toBe('demo');
|
|
88
|
+
expect(manifest.keywords).toEqual(['chart', 'diagram']);
|
|
89
|
+
expect(parsePluginPackage(validPackage(), { packageDir }).keywords).toEqual([]);
|
|
90
|
+
});
|
|
91
|
+
|
|
83
92
|
it('fails closed on invalid fields', () => {
|
|
84
93
|
expect(reason(validPackage({ apiVersion: 2 }))).toMatch(/apiVersion/);
|
|
85
94
|
expect(reason(validPackage({ id: 'Bad_Id' }))).toMatch(/id/);
|
|
@@ -160,6 +160,15 @@ describe('plugin routes', () => {
|
|
|
160
160
|
expect(onChange).not.toHaveBeenCalled();
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
+
it('names the npm packages of the bundled plugins', async () => {
|
|
164
|
+
const file = join(await mkdtemp(join(tmpdir(), 'pichamber-plugin-config-')), 'plugins.json');
|
|
165
|
+
const service = createPluginService({ store: createPluginStore({ file }) });
|
|
166
|
+
expect((await service.bundledPackageNames()).sort()).toEqual([
|
|
167
|
+
'@pi-chamber/plugin-subagents',
|
|
168
|
+
'@pi-chamber/plugin-visuals',
|
|
169
|
+
]);
|
|
170
|
+
});
|
|
171
|
+
|
|
163
172
|
it('builds the daemon config from enabled plugins only', async () => {
|
|
164
173
|
const file = join(await mkdtemp(join(tmpdir(), 'pichamber-plugin-config-')), 'plugins.json');
|
|
165
174
|
const service = createPluginService({ store: createPluginStore({ file }) });
|
|
@@ -176,6 +185,25 @@ describe('plugin routes', () => {
|
|
|
176
185
|
});
|
|
177
186
|
});
|
|
178
187
|
|
|
188
|
+
it('leaves other projects out of a sandboxed daemon\'s config', async () => {
|
|
189
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-plugin-config-fixture-'));
|
|
190
|
+
await writePlugin(root, 'scoped', {
|
|
191
|
+
state: { mode: { type: 'enum', scope: 'project', default: 'a', label: 'Mode', options: [{ value: 'a', label: 'A' }, { value: 'b', label: 'B' }] } },
|
|
192
|
+
});
|
|
193
|
+
await writeFile(join(root, 'registry.json'), JSON.stringify({ version: 1, plugins: ['scoped'] }));
|
|
194
|
+
const file = join(await mkdtemp(join(tmpdir(), 'pichamber-plugin-config-')), 'plugins.json');
|
|
195
|
+
const service = createPluginService({ store: createPluginStore({ file }), loadPlugins: () => loadBundledPlugins({ pluginsDir: root }) });
|
|
196
|
+
await service.setEnabled('scoped', true);
|
|
197
|
+
for (const directory of ['/work/night', '/work/night/app', '/work/nightly', '/work/other', '/data/worktree/abc/feature']) {
|
|
198
|
+
await service.setState('scoped', { key: 'mode', value: 'b', directory });
|
|
199
|
+
}
|
|
200
|
+
const projectsFor = async (scope) => Object.keys((await service.daemonConfig(scope)).plugins[0].state.projects).sort();
|
|
201
|
+
expect(await projectsFor()).toEqual(['/data/worktree/abc/feature', '/work/night', '/work/night/app', '/work/nightly', '/work/other']);
|
|
202
|
+
expect(await projectsFor({ roots: ['/work/night', '/data/worktree/abc'] }))
|
|
203
|
+
.toEqual(['/data/worktree/abc/feature', '/work/night', '/work/night/app']);
|
|
204
|
+
expect(await projectsFor({ roots: [] })).toEqual([]);
|
|
205
|
+
});
|
|
206
|
+
|
|
179
207
|
it('keeps a composer switch to one session and leaves the settings alone', async () => {
|
|
180
208
|
const { call, onChange } = await setup();
|
|
181
209
|
await call('PUT', '/api/pi/plugins/subagents', { enabled: true });
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
1
3
|
import { createImpactCache } from './impact.js';
|
|
2
4
|
import { loadBundledPlugins } from './registry.js';
|
|
3
5
|
import {
|
|
@@ -10,6 +12,11 @@ import {
|
|
|
10
12
|
resolveSessionOverrides,
|
|
11
13
|
} from './store.js';
|
|
12
14
|
|
|
15
|
+
const isAtOrBelow = (directory, root) => {
|
|
16
|
+
const relative = path.relative(root, directory);
|
|
17
|
+
return relative === '' || (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
|
|
18
|
+
};
|
|
19
|
+
|
|
13
20
|
const pluginNotFound = () => new PluginStoreError('PLUGIN_NOT_FOUND', 'No plugin has that id.');
|
|
14
21
|
|
|
15
22
|
/**
|
|
@@ -48,6 +55,7 @@ export const createPluginService = ({
|
|
|
48
55
|
description: manifest.description,
|
|
49
56
|
icon: manifest.icon,
|
|
50
57
|
version: manifest.version,
|
|
58
|
+
keywords: manifest.keywords ?? [],
|
|
51
59
|
bundled: manifest.bundled,
|
|
52
60
|
enabled: isPluginEnabled(manifest, snapshot),
|
|
53
61
|
state: resolvePluginState(manifest, snapshot, directory),
|
|
@@ -127,8 +135,16 @@ export const createPluginService = ({
|
|
|
127
135
|
* filled in), `projects[dir]` only the project-scoped values that differ,
|
|
128
136
|
* `sessions[sessionId]` a session's own values. The daemon resolves
|
|
129
137
|
* `{ ...global, ...projects[dir], ...sessions[sessionId] }`.
|
|
138
|
+
*
|
|
139
|
+
* With `roots` (a sandboxed project's daemon), `projects` keeps only the
|
|
140
|
+
* folders at or below one of them, so that daemon never learns where other
|
|
141
|
+
* projects live. `sessions` holds opaque ids and values only and is sent
|
|
142
|
+
* whole.
|
|
130
143
|
*/
|
|
131
|
-
const daemonConfig = async () => {
|
|
144
|
+
const daemonConfig = async ({ roots } = {}) => {
|
|
145
|
+
const keep = Array.isArray(roots)
|
|
146
|
+
? (directory) => roots.some((root) => isAtOrBelow(path.resolve(directory), path.resolve(root)))
|
|
147
|
+
: () => true;
|
|
132
148
|
const [manifests, snapshot] = await Promise.all([plugins(), store.read()]);
|
|
133
149
|
const configured = [];
|
|
134
150
|
for (const manifest of manifests.values()) {
|
|
@@ -136,6 +152,7 @@ export const createPluginService = ({
|
|
|
136
152
|
const global = resolvePluginState(manifest, snapshot, null);
|
|
137
153
|
const projects = {};
|
|
138
154
|
for (const directory of Object.keys(snapshot.state[manifest.id]?.projects ?? {})) {
|
|
155
|
+
if (!keep(directory)) continue;
|
|
139
156
|
const resolved = resolvePluginState(manifest, snapshot, directory);
|
|
140
157
|
const projectValues = Object.fromEntries(Object.entries(manifest.stateSchema)
|
|
141
158
|
.filter(([key, field]) => field.scope === 'project' && resolved[key] !== global[key])
|
|
@@ -157,5 +174,10 @@ export const createPluginService = ({
|
|
|
157
174
|
return { plugins: configured };
|
|
158
175
|
};
|
|
159
176
|
|
|
160
|
-
|
|
177
|
+
/** npm names of the bundled plugins, so the marketplace never lists them. */
|
|
178
|
+
const bundledPackageNames = async () => [...(await plugins()).values()]
|
|
179
|
+
.filter((manifest) => manifest.bundled && manifest.packageName)
|
|
180
|
+
.map((manifest) => manifest.packageName);
|
|
181
|
+
|
|
182
|
+
return { list, setEnabled, setState, sessionState, setSessionState, forgetSession, daemonConfig, bundledPackageNames };
|
|
161
183
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { mkdir, open, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { dirname } from 'node:path';
|
|
4
5
|
|
|
5
6
|
const RETRYABLE_CODES = new Set(['EEXIST', 'EPERM', 'EACCES', 'EBUSY', 'EAGAIN']);
|
|
@@ -23,9 +24,33 @@ const isPidAlive = (processLike, pid) => {
|
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
|
|
27
|
+
const SMALL_FILE_MAX_BYTES = 8192;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Read a small file other processes write, without trusting what sits at the
|
|
31
|
+
* path. A lock or lease folder can be writable by code that is not trusted
|
|
32
|
+
* (a sandboxed daemon shares the session lease folder), so the read never
|
|
33
|
+
* follows a symlink, never waits on a FIFO or device, and never reads more
|
|
34
|
+
* than a claim can hold. Anything else there throws `ENOTREGULAR`.
|
|
35
|
+
*/
|
|
36
|
+
export const readSmallRegularFile = async (file, maxBytes = SMALL_FILE_MAX_BYTES) => {
|
|
37
|
+
const handle = await open(file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
38
|
+
try {
|
|
39
|
+
const info = await handle.stat();
|
|
40
|
+
if (!info.isFile() || info.size > maxBytes) {
|
|
41
|
+
throw Object.assign(new Error('Not a small regular file.'), { code: 'ENOTREGULAR' });
|
|
42
|
+
}
|
|
43
|
+
const buffer = Buffer.alloc(maxBytes);
|
|
44
|
+
const { bytesRead } = await handle.read(buffer, 0, maxBytes, 0);
|
|
45
|
+
return buffer.subarray(0, bytesRead).toString('utf8');
|
|
46
|
+
} finally {
|
|
47
|
+
await handle.close();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
26
51
|
const readClaim = async (lockFile) => {
|
|
27
52
|
try {
|
|
28
|
-
const claim = JSON.parse(await
|
|
53
|
+
const claim = JSON.parse(await readSmallRegularFile(lockFile));
|
|
29
54
|
if (Number.isInteger(claim?.pid) && claim.pid > 0 && typeof claim.nonce === 'string' && claim.nonce.length > 0) {
|
|
30
55
|
return { claim };
|
|
31
56
|
}
|
|
@@ -100,7 +125,7 @@ export const withCrossProcessLock = async (
|
|
|
100
125
|
return await operation();
|
|
101
126
|
} finally {
|
|
102
127
|
try {
|
|
103
|
-
const current = JSON.parse(await
|
|
128
|
+
const current = JSON.parse(await readSmallRegularFile(lockFile));
|
|
104
129
|
if (current?.pid === processLike.pid && current?.nonce === nonce) {
|
|
105
130
|
await rm(lockFile, { force: true });
|
|
106
131
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Wallpaper picture
|
|
2
|
+
|
|
3
|
+
Holds the one picture a server shows behind the new-session screen. Whether
|
|
4
|
+
it shows (`draftWallpaperPicture`, under whichever `draftWallpaper` pattern is
|
|
5
|
+
chosen, which then takes its colours) and which picture the clients expect
|
|
6
|
+
(`draftWallpaperImageVersion`) are UI settings; this module only stores bytes.
|
|
7
|
+
|
|
8
|
+
## Files
|
|
9
|
+
|
|
10
|
+
- `store.js`: `<dataDir>/wallpaper/image` and `image.json` (`{ version, type }`).
|
|
11
|
+
- `routes.js`: `GET`, `PUT` and `DELETE /api/wallpaper-image`, behind the
|
|
12
|
+
global `/api` auth gate.
|
|
13
|
+
|
|
14
|
+
## Invariants
|
|
15
|
+
|
|
16
|
+
- The type comes from the file's first bytes. Only PNG, JPEG and WebP are
|
|
17
|
+
accepted (no SVG: it can carry script). Responses send `nosniff`.
|
|
18
|
+
- `version` is the first 16 hex characters of the bytes' SHA-256. A record
|
|
19
|
+
whose version does not match the stored picture reads as no picture, so a
|
|
20
|
+
crash between the two writes never serves a picture under the wrong name.
|
|
21
|
+
- A refused upload (too large, unknown type) leaves the previous picture.
|
|
22
|
+
- The size cap (8 MB) only stops abuse: the UI scales pictures to at most
|
|
23
|
+
2560 px on the long side and re-encodes them before sending.
|
|
24
|
+
- `GET` answers `private, no-cache` with an ETag; clients key their copy by
|
|
25
|
+
version and fetch again only when the setting names a new one.
|