@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
package/server/index.js
CHANGED
|
@@ -17,15 +17,23 @@ import { createTailscaleService } from './lib/tailscale/service.js';
|
|
|
17
17
|
import { createServerIdResolver } from './lib/relay/server-id.js';
|
|
18
18
|
import { registerTailscaleRoutes } from './lib/tailscale/routes.js';
|
|
19
19
|
import { registerPiRuntimeRoutes } from './lib/pi/routes.js';
|
|
20
|
+
import { createPiDaemonPool } from './lib/pi/session-daemon/daemon-pool.js';
|
|
20
21
|
import { createPluginService } from './lib/plugins/service.js';
|
|
21
22
|
import { createPluginDaemonSync } from './lib/plugins/daemon-sync.js';
|
|
22
23
|
import { registerPluginRoutes } from './lib/plugins/routes.js';
|
|
24
|
+
import { createFeaturedSource, DEFAULT_FEATURED_URL } from './lib/marketplace/featured.js';
|
|
25
|
+
import { createNpmRegistry } from './lib/marketplace/npm-registry.js';
|
|
26
|
+
import { registerMarketplaceRoutes } from './lib/marketplace/routes.js';
|
|
27
|
+
import { createMarketplaceService } from './lib/marketplace/service.js';
|
|
23
28
|
import { createDockerInitialLocalSettings, createPiUiSettingsStore } from './lib/pi/ui-settings-store.js';
|
|
24
29
|
import { detectLinuxDistribution } from './lib/server/linux-distribution.js';
|
|
25
30
|
import { createPiNotificationWatcher } from './lib/notifications/pi-notification-watcher.js';
|
|
26
31
|
import { registerWorkspaceIntegrations } from './lib/workspace/host.js';
|
|
27
32
|
import { createPiSessionDaemonSupervisor } from './lib/pi/session-daemon/supervisor.js';
|
|
28
33
|
import { createOpenUrlIntake } from './lib/open-url/intake.js';
|
|
34
|
+
import { createNonoLauncher } from './lib/pi/sandbox/nono-launcher.js';
|
|
35
|
+
import { createProjectSandboxManager } from './lib/pi/sandbox/project-sandbox-manager.js';
|
|
36
|
+
import { createTrustAskStore } from './lib/pi/sandbox/trust-ask.js';
|
|
29
37
|
import {
|
|
30
38
|
getUnauthenticatedLanErrorMessage,
|
|
31
39
|
isNetworkExposedBindHost,
|
|
@@ -134,6 +142,11 @@ export async function startWebUiServer(options = {}) {
|
|
|
134
142
|
const apiOnly = options.apiOnly === true || isEnvFlagEnabled(process.env.PICHAMBER_API_ONLY);
|
|
135
143
|
const app = express();
|
|
136
144
|
const server = http.createServer(app);
|
|
145
|
+
// The port the server is listening on, or null before it binds.
|
|
146
|
+
const boundPort = () => {
|
|
147
|
+
const address = server.address();
|
|
148
|
+
return typeof address === 'object' && address ? address.port : null;
|
|
149
|
+
};
|
|
137
150
|
const serverStartedAt = new Date().toISOString();
|
|
138
151
|
const dataPath = (name) => path.join(PICHAMBER_DATA_DIR, name);
|
|
139
152
|
const remoteClientAuthRuntime = createRemoteClientAuthRuntime({ fsPromises: fs.promises, path, crypto: await import('node:crypto'), storePath: dataPath('remote-clients.json') });
|
|
@@ -160,10 +173,7 @@ export async function startWebUiServer(options = {}) {
|
|
|
160
173
|
});
|
|
161
174
|
const tunnelService = createTunnelService({
|
|
162
175
|
dataDir: PICHAMBER_DATA_DIR,
|
|
163
|
-
getPort:
|
|
164
|
-
const address = server.address();
|
|
165
|
-
return typeof address === 'object' && address ? address.port : null;
|
|
166
|
-
},
|
|
176
|
+
getPort: boundPort,
|
|
167
177
|
tunnelAuthController,
|
|
168
178
|
getServerLabel: () => os.hostname() || 'PiChamber',
|
|
169
179
|
});
|
|
@@ -185,10 +195,7 @@ export async function startWebUiServer(options = {}) {
|
|
|
185
195
|
const tailscaleService = createTailscaleService({
|
|
186
196
|
dataDir: PICHAMBER_DATA_DIR,
|
|
187
197
|
getServerId: serverIdResolver.getServerId,
|
|
188
|
-
getPort:
|
|
189
|
-
const address = server.address();
|
|
190
|
-
return typeof address === 'object' && address ? address.port : null;
|
|
191
|
-
},
|
|
198
|
+
getPort: boundPort,
|
|
192
199
|
isUiAuthEnabled: hasUiPasswordConfigured,
|
|
193
200
|
isUnsafeUnauthenticatedLanAllowed: () => isUnsafeUnauthenticatedLanAllowed(process.env),
|
|
194
201
|
});
|
|
@@ -198,10 +205,7 @@ export async function startWebUiServer(options = {}) {
|
|
|
198
205
|
console.warn(`[tailscale] Failed to load persisted config: ${error?.message || error}`);
|
|
199
206
|
}
|
|
200
207
|
const pairingTransports = createPairingTransportResolvers({
|
|
201
|
-
getPort:
|
|
202
|
-
const address = server.address();
|
|
203
|
-
return typeof address === 'object' && address ? address.port : null;
|
|
204
|
-
},
|
|
208
|
+
getPort: boundPort,
|
|
205
209
|
bindHost: host,
|
|
206
210
|
getTailscaleCandidate: () => tailscaleService.getPairingCandidate(),
|
|
207
211
|
});
|
|
@@ -239,10 +243,7 @@ export async function startWebUiServer(options = {}) {
|
|
|
239
243
|
serverStartedAt,
|
|
240
244
|
gracefulShutdown,
|
|
241
245
|
getHealthSnapshot: () => ({ pi: { state: 'ready' }, apiOnly }),
|
|
242
|
-
getServerPort:
|
|
243
|
-
const address = server.address();
|
|
244
|
-
return typeof address === 'object' && address ? address.port : null;
|
|
245
|
-
},
|
|
246
|
+
getServerPort: boundPort,
|
|
246
247
|
getTunnelUrl: () => null,
|
|
247
248
|
getServerId: serverIdResolver.getServerId,
|
|
248
249
|
tunnelAuthController,
|
|
@@ -265,21 +266,74 @@ export async function startWebUiServer(options = {}) {
|
|
|
265
266
|
getServerLabel: () => os.hostname() || 'PiChamber',
|
|
266
267
|
});
|
|
267
268
|
// Plugins: the server owns manifests and state and pushes the enabled set
|
|
268
|
-
// to
|
|
269
|
-
// supervisor's onDaemonReady hook, which pushes.
|
|
269
|
+
// to every daemon (lib/plugins/DOCUMENTATION.md). A health probe runs the
|
|
270
|
+
// supervisor's onDaemonReady hook, which pushes. A sandboxed project's
|
|
271
|
+
// daemon gets a config trimmed to its own folders.
|
|
270
272
|
const pluginService = createPluginService();
|
|
271
273
|
const pluginDaemonSync = createPluginDaemonSync({
|
|
272
|
-
buildConfig: () => pluginService.daemonConfig(),
|
|
274
|
+
buildConfig: (scope) => pluginService.daemonConfig(scope),
|
|
273
275
|
refresh: () => piSessionDaemonRuntime?.health(),
|
|
274
276
|
});
|
|
275
|
-
|
|
276
|
-
|
|
277
|
+
// The main daemon is today's supervisor; project daemons register here.
|
|
278
|
+
const piDaemonPool = createPiDaemonPool({ getMainRuntime: () => piSessionDaemonRuntime });
|
|
279
|
+
// Sandboxed projects get their own daemon, started through nono on first
|
|
280
|
+
// use. With no sandboxed project this registers nothing and probes nothing.
|
|
281
|
+
let piRuntimeRoutes = null;
|
|
282
|
+
// Folders whose Pi trust stays "ask" after their sandbox was turned off;
|
|
283
|
+
// the daemons read the same file (sandbox/trust-ask.js).
|
|
284
|
+
const piTrustAsk = createTrustAskStore({ dataDir: PICHAMBER_DATA_DIR });
|
|
285
|
+
const piSandboxManager = createProjectSandboxManager({
|
|
286
|
+
daemonPool: piDaemonPool,
|
|
287
|
+
trustAsk: piTrustAsk,
|
|
288
|
+
uiSettingsStore,
|
|
289
|
+
launcher: createNonoLauncher({
|
|
290
|
+
stageDir: path.join(PICHAMBER_DATA_DIR, 'pi', 'sandbox'),
|
|
291
|
+
customProfileFile: path.join(PICHAMBER_DATA_DIR, 'pi', 'sandbox', 'nono-profile.custom.json'),
|
|
292
|
+
}),
|
|
293
|
+
dataDir: PICHAMBER_DATA_DIR,
|
|
294
|
+
agentDir: async () => {
|
|
295
|
+
const configured = typeof process.env.PICHAMBER_PI_AGENT_DIR === 'string' ? process.env.PICHAMBER_PI_AGENT_DIR.trim() : '';
|
|
296
|
+
if (configured) return configured;
|
|
297
|
+
return (await import('@earendil-works/pi-coding-agent')).getAgentDir();
|
|
298
|
+
},
|
|
299
|
+
getServerPort: boundPort,
|
|
300
|
+
hasConnectedDevices: () => piRuntimeRoutes?.hasLiveEventStreams() ?? false,
|
|
301
|
+
// The same port and version as the main daemon, so sandbox profile keys
|
|
302
|
+
// extend the main daemon's.
|
|
303
|
+
supervisorOptions: ({ roots } = {}) => ({
|
|
304
|
+
port: boundPort() ?? port,
|
|
305
|
+
version: PICHAMBER_VERSION,
|
|
306
|
+
onDaemonReady: pluginDaemonSync.onDaemonReadyFor({ roots }),
|
|
307
|
+
}),
|
|
308
|
+
});
|
|
309
|
+
piRuntimeRoutes = registerPiRuntimeRoutes(app, {
|
|
310
|
+
daemonPool: piDaemonPool,
|
|
311
|
+
sandboxManager: piSandboxManager,
|
|
312
|
+
trustAsk: piTrustAsk,
|
|
277
313
|
uiSettingsStore,
|
|
278
314
|
onSessionDeleted: async (sessionId) => {
|
|
279
315
|
if (await pluginService.forgetSession(sessionId)) pluginDaemonSync.changed();
|
|
280
316
|
},
|
|
281
317
|
});
|
|
282
318
|
registerPluginRoutes(app, { service: pluginService, onChange: pluginDaemonSync.changed });
|
|
319
|
+
// Marketplace: npm search and the featured list (lib/marketplace/DOCUMENTATION.md).
|
|
320
|
+
// PICHAMBER_NPM_REGISTRY_URL / PICHAMBER_NPM_DOWNLOADS_URL point it at a
|
|
321
|
+
// mirror or a test fixture; PICHAMBER_FEATURED_URL=off stops refreshing the
|
|
322
|
+
// featured list from the repository.
|
|
323
|
+
const featuredUrlSetting = process.env.PICHAMBER_FEATURED_URL;
|
|
324
|
+
registerMarketplaceRoutes(app, {
|
|
325
|
+
service: createMarketplaceService({
|
|
326
|
+
registry: createNpmRegistry({
|
|
327
|
+
...(process.env.PICHAMBER_NPM_REGISTRY_URL ? { registryUrl: process.env.PICHAMBER_NPM_REGISTRY_URL } : {}),
|
|
328
|
+
...(process.env.PICHAMBER_NPM_DOWNLOADS_URL ? { downloadsUrl: process.env.PICHAMBER_NPM_DOWNLOADS_URL } : {}),
|
|
329
|
+
}),
|
|
330
|
+
featuredSource: createFeaturedSource({
|
|
331
|
+
cachePath: dataPath(path.join('pi', 'featured.json')),
|
|
332
|
+
remoteUrl: featuredUrlSetting === 'off' ? null : featuredUrlSetting || DEFAULT_FEATURED_URL,
|
|
333
|
+
}),
|
|
334
|
+
bundledPackageNames: () => pluginService.bundledPackageNames(),
|
|
335
|
+
}),
|
|
336
|
+
});
|
|
283
337
|
// Cloudflare Tunnel external access (managed-remote and managed-local modes).
|
|
284
338
|
const requireTunnelAuth = (req, res, next) => uiAuthController.requireAuth(req, res, next);
|
|
285
339
|
app.get('/api/pichamber/tunnel/status', requireTunnelAuth, async (_req, res) => {
|
|
@@ -318,7 +372,7 @@ export async function startWebUiServer(options = {}) {
|
|
|
318
372
|
void tailscaleService.reconcile().catch((error) => {
|
|
319
373
|
console.warn(`[tailscale] Failed to apply mapping on startup: ${error?.message || error}`);
|
|
320
374
|
});
|
|
321
|
-
const resolvedPort =
|
|
375
|
+
const resolvedPort = boundPort();
|
|
322
376
|
piSessionDaemonRuntime = createPiSessionDaemonSupervisor({
|
|
323
377
|
dataDir: PICHAMBER_DATA_DIR,
|
|
324
378
|
port: typeof resolvedPort === 'number' ? resolvedPort : port,
|
|
@@ -339,7 +393,7 @@ export async function startWebUiServer(options = {}) {
|
|
|
339
393
|
// supplies its native notification callback.
|
|
340
394
|
if (typeof options.onDesktopNotification === 'function') {
|
|
341
395
|
notificationWatcher = createPiNotificationWatcher({
|
|
342
|
-
|
|
396
|
+
daemonPool: piDaemonPool,
|
|
343
397
|
uiSettingsStore,
|
|
344
398
|
notify: options.onDesktopNotification,
|
|
345
399
|
});
|
|
@@ -356,6 +410,13 @@ export async function startWebUiServer(options = {}) {
|
|
|
356
410
|
} catch (error) {
|
|
357
411
|
console.warn(`[open-url] Intake unavailable: ${error?.code ?? 'UNKNOWN'}`);
|
|
358
412
|
}
|
|
413
|
+
// Register sandboxed projects before any request can route; a failure
|
|
414
|
+
// leaves those projects unregistered, so log it loudly.
|
|
415
|
+
try {
|
|
416
|
+
await piSandboxManager.reconcile();
|
|
417
|
+
} catch (error) {
|
|
418
|
+
console.warn(`[pi-sandbox] Could not load project sandbox settings: ${error?.code ?? error?.message ?? 'UNKNOWN'}`);
|
|
419
|
+
}
|
|
359
420
|
void piSessionDaemonRuntime.start()
|
|
360
421
|
.then(() => {
|
|
361
422
|
// Configure plugins on the started daemon; later requests re-check.
|
|
@@ -370,10 +431,7 @@ export async function startWebUiServer(options = {}) {
|
|
|
370
431
|
const controller = {
|
|
371
432
|
expressApp: app,
|
|
372
433
|
httpServer: server,
|
|
373
|
-
getPort:
|
|
374
|
-
const address = server.address();
|
|
375
|
-
return typeof address === 'object' && address ? address.port : null;
|
|
376
|
-
},
|
|
434
|
+
getPort: boundPort,
|
|
377
435
|
getTunnelUrl: () => null,
|
|
378
436
|
getDaemonProfileKey: () => piSessionDaemonRuntime?.paths?.profileKey ?? null,
|
|
379
437
|
getTailscaleStatus: () => tailscaleService.getStatus(),
|
|
@@ -390,6 +448,7 @@ export async function startWebUiServer(options = {}) {
|
|
|
390
448
|
await Promise.allSettled([
|
|
391
449
|
notificationWatcher?.stop(),
|
|
392
450
|
openUrlIntake.stop(),
|
|
451
|
+
piSandboxManager.stop(),
|
|
393
452
|
workspaceRuntime.shutdown(),
|
|
394
453
|
piSessionDaemonRuntime ? piSessionDaemonRuntime.stop() : Promise.resolve(),
|
|
395
454
|
tailscaleService.shutdown(),
|
|
@@ -24,6 +24,10 @@ This module provides Git repository operations for the web server runtime, inclu
|
|
|
24
24
|
any git config previously written into repositories are left untouched on
|
|
25
25
|
disk.
|
|
26
26
|
|
|
27
|
+
## Sandbox
|
|
28
|
+
|
|
29
|
+
Only Pi session daemons (the agent) run in the sandbox. PiChamber's own Git panel, terminal, browser and GitHub features, and worktree hooks and start commands, run outside it with the user's access, so git config, hooks or filters an agent writes into the repo can run when the user or the Git panel runs git. This is a known, accepted trade-off. Git runs the same for every folder, sandboxed project or not. One exception is the worktree folder id: for a project the sandbox manager has remembered an id for (`../pi/sandbox/worktree-ids.js`), new worktrees are filed under that id, not the one in `.git/pichamber`, which the sandboxed agent can rewrite; an unreadable record fails the worktree operation. A project nothing is remembered for is kept out of folders remembered for other projects: when its id (a second clone of the same repository has the same one) is remembered for another root, its worktrees are filed under an id of its own (`ownWorktreeId`), so they never land in a folder a sandbox is granted.
|
|
30
|
+
|
|
27
31
|
## Public API
|
|
28
32
|
|
|
29
33
|
The following functions are exported and used by the web server:
|
|
@@ -2,10 +2,12 @@ import simpleGit from 'simple-git';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import os from 'os';
|
|
5
|
+
import crypto from 'crypto';
|
|
5
6
|
import { execFile } from 'child_process';
|
|
6
7
|
import { promisify } from 'util';
|
|
7
8
|
import { createRequire } from 'module';
|
|
8
9
|
import { resolvePiChamberDataPath } from '../pichamber-data-dir.js';
|
|
10
|
+
import { createWorktreeIdStore, ownWorktreeId } from '../pi/sandbox/worktree-ids.js';
|
|
9
11
|
|
|
10
12
|
const fsp = fs.promises;
|
|
11
13
|
const require = createRequire(import.meta.url);
|
|
@@ -1506,12 +1508,75 @@ export async function continueIntegrate(stateInput = {}) {
|
|
|
1506
1508
|
return { kind: 'success', moved: state.remainingCommits.length };
|
|
1507
1509
|
}
|
|
1508
1510
|
|
|
1511
|
+
const PICHAMBER_ID_FILE_MAX_BYTES = 256;
|
|
1512
|
+
|
|
1513
|
+
// Sandboxed code can write `.git`, so the id file is never followed through a
|
|
1514
|
+
// symlink: it is read only as a small regular file, and replaced by renaming a
|
|
1515
|
+
// new file over it (rename swaps a symlink itself, it does not follow it).
|
|
1516
|
+
const readPiChamberIdFile = async (idFile) => {
|
|
1517
|
+
const info = await fsp.lstat(idFile).catch(() => null);
|
|
1518
|
+
if (!info?.isFile() || info.size > PICHAMBER_ID_FILE_MAX_BYTES) return '';
|
|
1519
|
+
const handle = await fsp.open(idFile, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0)).catch(() => null);
|
|
1520
|
+
if (!handle) return '';
|
|
1521
|
+
try {
|
|
1522
|
+
const buffer = Buffer.alloc(PICHAMBER_ID_FILE_MAX_BYTES + 1);
|
|
1523
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
1524
|
+
return bytesRead > PICHAMBER_ID_FILE_MAX_BYTES ? '' : buffer.toString('utf8', 0, bytesRead).trim();
|
|
1525
|
+
} catch {
|
|
1526
|
+
return '';
|
|
1527
|
+
} finally {
|
|
1528
|
+
await handle.close().catch(() => undefined);
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
|
|
1532
|
+
const writePiChamberIdFile = async (idFile, projectId) => {
|
|
1533
|
+
const info = await fsp.lstat(idFile).catch((error) => (error?.code === 'ENOENT' ? null : undefined));
|
|
1534
|
+
// A symlink is replaced itself by the rename below; anything else that is
|
|
1535
|
+
// not a regular file (a directory, a device) is left alone.
|
|
1536
|
+
if (info === undefined || (info && !info.isFile() && !info.isSymbolicLink())) return;
|
|
1537
|
+
const temp = `${idFile}.${process.pid}.${crypto.randomBytes(8).toString('hex')}.tmp`;
|
|
1538
|
+
try {
|
|
1539
|
+
await fsp.writeFile(temp, projectId, { encoding: 'utf8', flag: 'wx', mode: 0o644 });
|
|
1540
|
+
await fsp.rename(temp, idFile);
|
|
1541
|
+
} catch {
|
|
1542
|
+
await fsp.rm(temp, { force: true }).catch(() => undefined);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
// The id a sandboxed project was first seen with. Its sandbox owns and is
|
|
1547
|
+
// granted `worktree/<that id>` only, and the sandboxed agent can rewrite the
|
|
1548
|
+
// id file, so a remembered id stands whatever the file says: a worktree
|
|
1549
|
+
// created under another id would be outside the sandbox, or inside another
|
|
1550
|
+
// project's. An unreadable record throws rather than trust the file.
|
|
1551
|
+
const rememberedPiChamberProjectIds = async (primaryWorktree) => {
|
|
1552
|
+
const ids = await createWorktreeIdStore({ file: resolvePiChamberDataPath(['pi', 'sandbox', 'worktree-ids.json']) }).read();
|
|
1553
|
+
const root = path.resolve(primaryWorktree);
|
|
1554
|
+
const real = await fsp.realpath(root).catch(() => root);
|
|
1555
|
+
return {
|
|
1556
|
+
own: ids.get(root) ?? ids.get(real) ?? null,
|
|
1557
|
+
// Ids remembered for other projects: their sandboxes are granted those
|
|
1558
|
+
// folders, so this project's worktrees must not be filed there.
|
|
1559
|
+
others: new Set([...ids].filter(([other]) => other !== root && other !== real).map(([, id]) => id)),
|
|
1560
|
+
};
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
// The worktree folder id of a project nothing is remembered for. A clone of
|
|
1564
|
+
// a repository whose folder a sandboxed project holds gets its own instead.
|
|
1565
|
+
const unsharedPiChamberProjectId = (primaryWorktree, id, others) => (
|
|
1566
|
+
others.has(id) ? ownWorktreeId(primaryWorktree) : id
|
|
1567
|
+
);
|
|
1568
|
+
|
|
1509
1569
|
const ensurePiChamberProjectId = async (primaryWorktree) => {
|
|
1570
|
+
const { own: remembered, others } = await rememberedPiChamberProjectIds(primaryWorktree);
|
|
1571
|
+
if (remembered) return remembered;
|
|
1510
1572
|
const gitDir = path.join(primaryWorktree, '.git');
|
|
1511
1573
|
const idFile = path.join(gitDir, 'pichamber');
|
|
1512
|
-
const existing = await
|
|
1513
|
-
|
|
1514
|
-
|
|
1574
|
+
const existing = await readPiChamberIdFile(idFile);
|
|
1575
|
+
// The id names a folder under the data directory, and an agent working in
|
|
1576
|
+
// the repository can write this file: only a commit hash is taken from it.
|
|
1577
|
+
// Anything else is replaced by the id derived below.
|
|
1578
|
+
if (/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(existing)) {
|
|
1579
|
+
return unsharedPiChamberProjectId(primaryWorktree, existing, others);
|
|
1515
1580
|
}
|
|
1516
1581
|
|
|
1517
1582
|
const rootsResult = await runGitCommandOrThrow(
|
|
@@ -1532,9 +1597,9 @@ const ensurePiChamberProjectId = async (primaryWorktree) => {
|
|
|
1532
1597
|
}
|
|
1533
1598
|
|
|
1534
1599
|
await fsp.mkdir(gitDir, { recursive: true }).catch(() => undefined);
|
|
1535
|
-
await
|
|
1600
|
+
await writePiChamberIdFile(idFile, projectId);
|
|
1536
1601
|
|
|
1537
|
-
return projectId;
|
|
1602
|
+
return unsharedPiChamberProjectId(primaryWorktree, projectId, others);
|
|
1538
1603
|
};
|
|
1539
1604
|
|
|
1540
1605
|
const resolveWorktreeProjectContext = async (directory) => {
|
|
@@ -622,6 +622,185 @@ describe('worktree root resolution', () => {
|
|
|
622
622
|
// ---------------------------------------------------------------------------
|
|
623
623
|
|
|
624
624
|
describe('createWorktree', () => {
|
|
625
|
+
it('takes only a commit hash from the repository id file, so worktrees stay under the data folder', async () => {
|
|
626
|
+
if (!canRunGit()) return;
|
|
627
|
+
|
|
628
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
629
|
+
const dataHome = createTempDir();
|
|
630
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
631
|
+
try {
|
|
632
|
+
const repo = createTempDir();
|
|
633
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
634
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
635
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
636
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
637
|
+
runGit(repo, ['add', 'README.md']);
|
|
638
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
639
|
+
const rootCommit = runGit(repo, ['rev-list', '--max-parents=0', 'HEAD']).trim();
|
|
640
|
+
// Something working in the repository pointed the id out of the data folder.
|
|
641
|
+
const idFile = path.join(repo, '.git', 'pichamber');
|
|
642
|
+
fs.writeFileSync(idFile, '../../escape');
|
|
643
|
+
|
|
644
|
+
const created = await createWorktree(repo, {
|
|
645
|
+
mode: 'new',
|
|
646
|
+
branchName: 'feature/id-check',
|
|
647
|
+
worktreeName: 'id-check',
|
|
648
|
+
returnAfterDirectoryCreated: true,
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
const worktreeRoot = path.join(fs.realpathSync(dataHome), 'worktree', rootCommit);
|
|
652
|
+
expect(fs.realpathSync(created.path).startsWith(`${worktreeRoot}${path.sep}`)).toBe(true);
|
|
653
|
+
expect(fs.existsSync(path.join(dataHome, 'escape'))).toBe(false);
|
|
654
|
+
expect(fs.readFileSync(idFile, 'utf8')).toBe(rootCommit);
|
|
655
|
+
await expect.poll(
|
|
656
|
+
async () => (await getWorktreeBootstrapStatus(created.path)).phase,
|
|
657
|
+
{ timeout: 5_000 },
|
|
658
|
+
).toBe('setup-ready');
|
|
659
|
+
} finally {
|
|
660
|
+
if (previousPiChamberDataDir === undefined) {
|
|
661
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
662
|
+
} else {
|
|
663
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
it('keeps a project\'s worktrees out of a folder remembered for another (sandboxed) project', async () => {
|
|
669
|
+
if (!canRunGit()) return;
|
|
670
|
+
|
|
671
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
672
|
+
const dataHome = createTempDir();
|
|
673
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
674
|
+
try {
|
|
675
|
+
const repo = createTempDir();
|
|
676
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
677
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
678
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
679
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
680
|
+
runGit(repo, ['add', 'README.md']);
|
|
681
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
682
|
+
// Another clone of this repository is sandboxed and holds the folder
|
|
683
|
+
// named by the repository's root commit.
|
|
684
|
+
const shared = runGit(repo, ['rev-list', '--max-parents=0', 'HEAD']).trim();
|
|
685
|
+
const record = path.join(dataHome, 'pi', 'sandbox', 'worktree-ids.json');
|
|
686
|
+
fs.mkdirSync(path.dirname(record), { recursive: true });
|
|
687
|
+
fs.writeFileSync(record, JSON.stringify({ version: 1, projects: { '/code/other-clone': shared } }));
|
|
688
|
+
|
|
689
|
+
const created = await createWorktree(repo, {
|
|
690
|
+
mode: 'new',
|
|
691
|
+
branchName: 'feature/own-folder',
|
|
692
|
+
worktreeName: 'own-folder',
|
|
693
|
+
returnAfterDirectoryCreated: true,
|
|
694
|
+
});
|
|
695
|
+
expect(fs.existsSync(path.join(dataHome, 'worktree', shared))).toBe(false);
|
|
696
|
+
expect(fs.realpathSync(created.path).startsWith(`${path.join(fs.realpathSync(dataHome), 'worktree')}${path.sep}`)).toBe(true);
|
|
697
|
+
await expect.poll(
|
|
698
|
+
async () => (await getWorktreeBootstrapStatus(created.path)).phase,
|
|
699
|
+
{ timeout: 5_000 },
|
|
700
|
+
).toBe('setup-ready');
|
|
701
|
+
} finally {
|
|
702
|
+
if (previousPiChamberDataDir === undefined) {
|
|
703
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
704
|
+
} else {
|
|
705
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
it('files worktrees under the id remembered for a sandboxed project, whatever its id file says', async () => {
|
|
711
|
+
if (!canRunGit()) return;
|
|
712
|
+
|
|
713
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
714
|
+
const dataHome = createTempDir();
|
|
715
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
716
|
+
try {
|
|
717
|
+
const repo = createTempDir();
|
|
718
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
719
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
720
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
721
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
722
|
+
runGit(repo, ['add', 'README.md']);
|
|
723
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
724
|
+
const remembered = 'c'.repeat(40);
|
|
725
|
+
const record = path.join(dataHome, 'pi', 'sandbox', 'worktree-ids.json');
|
|
726
|
+
fs.mkdirSync(path.dirname(record), { recursive: true });
|
|
727
|
+
fs.writeFileSync(record, JSON.stringify({ version: 1, projects: { [path.resolve(repo)]: remembered } }));
|
|
728
|
+
// The sandboxed agent named another project's worktree folder.
|
|
729
|
+
const idFile = path.join(repo, '.git', 'pichamber');
|
|
730
|
+
fs.writeFileSync(idFile, 'd'.repeat(40));
|
|
731
|
+
|
|
732
|
+
const created = await createWorktree(repo, {
|
|
733
|
+
mode: 'new',
|
|
734
|
+
branchName: 'feature/remembered',
|
|
735
|
+
worktreeName: 'remembered',
|
|
736
|
+
returnAfterDirectoryCreated: true,
|
|
737
|
+
});
|
|
738
|
+
const worktreeRoot = path.join(fs.realpathSync(dataHome), 'worktree', remembered);
|
|
739
|
+
expect(fs.realpathSync(created.path).startsWith(`${worktreeRoot}${path.sep}`)).toBe(true);
|
|
740
|
+
expect(fs.existsSync(path.join(dataHome, 'worktree', 'd'.repeat(40)))).toBe(false);
|
|
741
|
+
await expect.poll(
|
|
742
|
+
async () => (await getWorktreeBootstrapStatus(created.path)).phase,
|
|
743
|
+
{ timeout: 5_000 },
|
|
744
|
+
).toBe('setup-ready');
|
|
745
|
+
|
|
746
|
+
// A record that cannot be read is not answered from the file.
|
|
747
|
+
fs.writeFileSync(record, '{');
|
|
748
|
+
await expect(createWorktree(repo, {
|
|
749
|
+
mode: 'new',
|
|
750
|
+
branchName: 'feature/unreadable',
|
|
751
|
+
worktreeName: 'unreadable',
|
|
752
|
+
returnAfterDirectoryCreated: true,
|
|
753
|
+
})).rejects.toThrow();
|
|
754
|
+
expect(fs.existsSync(path.join(dataHome, 'worktree', 'd'.repeat(40)))).toBe(false);
|
|
755
|
+
} finally {
|
|
756
|
+
if (previousPiChamberDataDir === undefined) {
|
|
757
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
758
|
+
} else {
|
|
759
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
it('does not follow a symlink planted at the repository id file', async () => {
|
|
765
|
+
if (!canRunGit()) return;
|
|
766
|
+
|
|
767
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
768
|
+
const dataHome = createTempDir();
|
|
769
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
770
|
+
try {
|
|
771
|
+
const repo = createTempDir();
|
|
772
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
773
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
774
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
775
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
776
|
+
runGit(repo, ['add', 'README.md']);
|
|
777
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
778
|
+
const rootCommit = runGit(repo, ['rev-list', '--max-parents=0', 'HEAD']).trim();
|
|
779
|
+
const victim = path.join(createTempDir(), 'victim.txt');
|
|
780
|
+
fs.writeFileSync(victim, 'untouched');
|
|
781
|
+
const idFile = path.join(repo, '.git', 'pichamber');
|
|
782
|
+
fs.symlinkSync(victim, idFile);
|
|
783
|
+
|
|
784
|
+
await createWorktree(repo, {
|
|
785
|
+
mode: 'new',
|
|
786
|
+
branchName: 'feature/link-check',
|
|
787
|
+
worktreeName: 'link-check',
|
|
788
|
+
returnAfterDirectoryCreated: true,
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
expect(fs.readFileSync(victim, 'utf8')).toBe('untouched');
|
|
792
|
+
expect(fs.lstatSync(idFile).isSymbolicLink()).toBe(false);
|
|
793
|
+
expect(fs.readFileSync(idFile, 'utf8')).toBe(rootCommit);
|
|
794
|
+
expect(fs.readdirSync(path.join(repo, '.git')).filter((name) => name.endsWith('.tmp'))).toEqual([]);
|
|
795
|
+
} finally {
|
|
796
|
+
if (previousPiChamberDataDir === undefined) {
|
|
797
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
798
|
+
} else {
|
|
799
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
|
|
625
804
|
it('returns ready/setup-ready when no bootstrap state is recorded', async () => {
|
|
626
805
|
const directory = path.join(createTempDir(), 'missing-worktree');
|
|
627
806
|
|
|
@@ -7,6 +7,8 @@ server runtime. Every GitHub call runs here; the shared UI talks to
|
|
|
7
7
|
`/api/github/*` through `RuntimeAPIs.github`, so web, desktop, hosted
|
|
8
8
|
mobile, and Capacitor share one code path. Tokens never reach a client.
|
|
9
9
|
|
|
10
|
+
Sandboxing: Only Pi session daemons (the agent) run in the sandbox. PiChamber's own Git panel, terminal, browser and GitHub features, and worktree hooks and start commands, run outside it with the user's access, so git config, hooks or filters an agent writes into the repo can run when the user or the Git panel runs git. This is a known, accepted trade-off. The GitHub module's git calls run unsandboxed for every folder.
|
|
11
|
+
|
|
10
12
|
## Entrypoints and structure
|
|
11
13
|
|
|
12
14
|
- `packages/web/server/lib/github/`: module directory.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Marketplace (server)
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Lets Settings find and install Pi packages without a registry of our own.
|
|
6
|
+
Pi packages are npm packages with the `pi-package` keyword, the same list
|
|
7
|
+
pi.dev's package gallery shows. This module reads npm's public search and
|
|
8
|
+
package endpoints, adds a curated featured list from the PiChamber repo, and
|
|
9
|
+
answers the UI through `/api/pi/marketplace/*`. Installing is not here: it
|
|
10
|
+
is a Pi package-manager write owned by the session daemon
|
|
11
|
+
(`../pi/session-daemon/extension-config.js`, `POST /api/pi/extensions/packages`).
|
|
12
|
+
|
|
13
|
+
## Entrypoints
|
|
14
|
+
|
|
15
|
+
- `npm-registry.js` is the only code that talks to npm.
|
|
16
|
+
`createNpmRegistry({ fetchImpl, registryUrl, downloadsUrl, timeoutMs })`
|
|
17
|
+
returns `searchRaw`, `latest(name)` and `weeklyDownloads(name)`. Responses
|
|
18
|
+
are size-capped (search 2 MB, manifest 512 KB) and time out after 8 s.
|
|
19
|
+
Failures are `MarketplaceError` with code `MARKETPLACE_UNAVAILABLE` or
|
|
20
|
+
`MARKETPLACE_PACKAGE_NOT_FOUND`. `summarizePackage` and `summarizeManifest`
|
|
21
|
+
reduce npm's answers to the fields the UI shows. Links pass `safeLink`
|
|
22
|
+
(http/https only). Requests carry the generic user agent `PiChamber` and
|
|
23
|
+
nothing about the user.
|
|
24
|
+
- `featured.js` owns the featured list. The built-in copy is
|
|
25
|
+
`packages/web/plugins/featured.json`; the remote copy is the same file on
|
|
26
|
+
the repo's `main` branch (`DEFAULT_FEATURED_URL`), refreshed at most every
|
|
27
|
+
6 hours (10 minutes after a failure), capped at 64 KB, and cached at
|
|
28
|
+
`<dataDir>/pi/featured.json` as `{ fetchedAt, list }`. `get()` never waits
|
|
29
|
+
on the network: it answers with the newer of the cached and built-in lists
|
|
30
|
+
(by `updated`; on the same date the cached copy wins) and starts a refresh
|
|
31
|
+
in the background when one is due.
|
|
32
|
+
- `service.js` combines them with in-memory TTL caches (search 5 minutes,
|
|
33
|
+
package and downloads 10 minutes, 300 entries, shared in-flight requests,
|
|
34
|
+
failures not kept).
|
|
35
|
+
- `routes.js` registers the routes below. `server/index.js` builds the
|
|
36
|
+
registry, featured source and service.
|
|
37
|
+
|
|
38
|
+
## List format
|
|
39
|
+
|
|
40
|
+
`featured.json`: `{ version: 1, updated: 'YYYY-MM-DD', featured: [{ name,
|
|
41
|
+
note? }], hidden: [name] }`. At most 24 featured entries with notes of at
|
|
42
|
+
most 120 characters, and 500 hidden names. Invalid names are dropped.
|
|
43
|
+
`hidden` is moderation: a hidden package is left out of search, featured and
|
|
44
|
+
package answers. Editing the file on `main` reaches every server within 6
|
|
45
|
+
hours; a release carries the file as the fallback.
|
|
46
|
+
|
|
47
|
+
## Routes
|
|
48
|
+
|
|
49
|
+
- `GET /api/pi/marketplace/search?q=&from=&pichamber=1` →
|
|
50
|
+
`{ packages, total?, nextFrom }`. Pages of 20. `total` only without a
|
|
51
|
+
query (npm's count for the keyword).
|
|
52
|
+
- `GET /api/pi/marketplace/featured` → `{ packages, updated, source }`, in
|
|
53
|
+
the list's order. An entry npm cannot answer for comes back as
|
|
54
|
+
`{ name, note, unavailable: true }` rather than failing the list.
|
|
55
|
+
- `GET /api/pi/marketplace/package?name=` → the package summary plus
|
|
56
|
+
`license?`, `contains` (from its `pi` block), `pichamber` (its manifest
|
|
57
|
+
declares a `pichamber` block with a numeric `apiVersion`) and `isPiPackage`.
|
|
58
|
+
- `GET /api/pi/marketplace/versions?names=a,b` → `{ versions: { name:
|
|
59
|
+
version } }` for at most 50 names. Names npm cannot answer for are left out.
|
|
60
|
+
- Errors: 400 `INVALID_MARKETPLACE_REQUEST`, 404
|
|
61
|
+
`MARKETPLACE_PACKAGE_NOT_FOUND`, 502 `MARKETPLACE_UNAVAILABLE`. A failed
|
|
62
|
+
npm call is an error, never an empty list.
|
|
63
|
+
|
|
64
|
+
## Invariants
|
|
65
|
+
|
|
66
|
+
- npm search text only ranks; it does not filter. A query for nonsense
|
|
67
|
+
returns popular packages that match nothing. The service keeps only hits
|
|
68
|
+
where a query word appears in the name, description or keywords, and stops
|
|
69
|
+
paging at the first page that has an unrelated hit, so the tail of
|
|
70
|
+
unrelated packages never shows.
|
|
71
|
+
- npm treats two keywords loosely, so the service asks for one
|
|
72
|
+
(`pichamber-plugin` with `pichamber=1`, otherwise `pi-package`) and checks
|
|
73
|
+
both itself.
|
|
74
|
+
- The `pichamber-plugin` keyword is a claim by the author: it marks a list
|
|
75
|
+
row. The package page reads the manifest and calls it a PiChamber plugin only
|
|
76
|
+
when the `pichamber` block is really there. A third-party package with
|
|
77
|
+
that block installs and runs as a plain Pi package; PiChamber does not load
|
|
78
|
+
its UI half.
|
|
79
|
+
- The bundled plugins (`pluginService.bundledPackageNames()`) and hidden
|
|
80
|
+
names never appear in an answer. The UI suggests the bundled plugin
|
|
81
|
+
instead when a search matches it.
|
|
82
|
+
- No README, images or other package content are fetched: only npm's
|
|
83
|
+
metadata, which is shown as text.
|
|
84
|
+
|
|
85
|
+
## Configuration
|
|
86
|
+
|
|
87
|
+
- `PICHAMBER_NPM_REGISTRY_URL` and `PICHAMBER_NPM_DOWNLOADS_URL` point at
|
|
88
|
+
another registry (tests, mirrors).
|
|
89
|
+
- `PICHAMBER_FEATURED_URL` replaces the remote featured list; `off` turns the
|
|
90
|
+
refresh off so only the built-in copy is used.
|
|
91
|
+
|
|
92
|
+
## Tests
|
|
93
|
+
|
|
94
|
+
`*.test.js` beside each file (vitest), with a fake `fetchImpl`; nothing
|
|
95
|
+
reaches the network.
|