@pi-chamber/web 1.0.8-rc.1 → 1.0.8-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentsSurface-BmHImX8m.js → AgentsSurface-CcWBqAWV.js} +1 -1
- package/dist/assets/{ChoicesArtifact-C71fGOm2.js → ChoicesArtifact-Kk-qvrSB.js} +1 -1
- package/dist/assets/{DiagramView-BZQxoiZu.js → DiagramView-DZUBo1uP.js} +1 -1
- package/dist/assets/{DiffView-C70pbgk-.js → DiffView-CiZy4jFA.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-Cu8c3gBV.js → FileSaveConflictDialog-DZ9NDwOO.js} +1 -1
- package/dist/assets/{FilesView-nFJYEdRw.js → FilesView-DqiZ9kw9.js} +1 -1
- package/dist/assets/{GitHubDetailScaffold-Jvv_tgbl.js → GitHubDetailScaffold-DM2DH7o8.js} +1 -1
- package/dist/assets/{GitHubLinkPicker-BXD2ODRi.js → GitHubLinkPicker-ChB8NZ1h.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-BWI706F0.js → GitHubListPrimitives-CibDiJGq.js} +1 -1
- package/dist/assets/{GitView-MIDG5RYW.js → GitView--EaZQrBr.js} +5 -5
- package/dist/assets/{IssuesSurface-uNlozeu0.js → IssuesSurface-CySTpaD1.js} +3 -3
- package/dist/assets/{JsonTreeView-CSLsTriz.js → JsonTreeView-_yMHKKQZ.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cs-7BfWi.js → MarkdownRendererImpl-D_-2fQw0.js} +1 -1
- package/dist/assets/{PatchDiff-axbsnbTJ.js → PatchDiff-bHObDlhD.js} +1 -1
- package/dist/assets/{PierreDiffViewer-lwn6w_5w.js → PierreDiffViewer-UY7Cse-s.js} +1 -1
- package/dist/assets/{PullRequestsSurface-o_AXDjbO.js → PullRequestsSurface-iXy6chwc.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-C4CMlcbv.js → SessionSwitcherContent-DJGCa_wN.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-DCBVuCoo.js → SessionSwitcherDropdown-CDOX-5Y2.js} +2 -2
- package/dist/assets/{SessionUnreadDot-DyeIrsro.js → SessionUnreadDot-Dwc3MdvA.js} +1 -1
- package/dist/assets/SettingsView-DA-U9lsj.js +11 -0
- package/dist/assets/{SettingsWindow-Cb4st5y5.js → SettingsWindow-CUg49Mfh.js} +1 -1
- package/dist/assets/{SubagentsArtifact-BzeMEoFP.js → SubagentsArtifact-DUZX9tDe.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BP2mOWdV.js → ToolOutputDialog-BuZZaRw4.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-D49XBR9b.js → ToolPartDiffPreview-CKncG6i2.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-CLgDONEQ.js → VirtualizedFileDiff-BGZiLPe_.js} +1 -1
- package/dist/assets/VisualFrame-DBZkHFnG.js +22 -0
- package/dist/assets/VisualsArtifact-Bq0vMO-i.js +1 -0
- package/dist/assets/{collapsible-BeyKtQGB.js → collapsible-Bro9KrfM.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DmO6H8u6.js → computeVirtualFileMetrics-DJQqK49u.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DOK251YW.js → contextFileOpenGuard-ByWK3Sru.js} +1 -1
- package/dist/assets/{fileTreeStatus-CnzR7kxA.js → fileTreeStatus-CyJ3TOYD.js} +1 -1
- package/dist/assets/{gitStatusPredicates-4kPg2t6j.js → gitStatusPredicates-BsXrwngT.js} +1 -1
- package/dist/assets/{githubLink-QvaLfNNT.js → githubLink-g2bmC0qi.js} +1 -1
- package/dist/assets/index-B_L9GVYw.css +1 -0
- package/dist/assets/{index-DMX9wT1Z.js → index-C9rUUQ_Y.js} +1 -1
- package/dist/assets/index-CKKWVoND.js +11 -0
- package/dist/assets/{main-BW9J3Y72.js → main-DT-4_fhe.js} +2 -2
- package/dist/assets/{main-BirYxac2.js → main-DsLMU9CT.js} +4 -4
- package/dist/assets/{markdownCore-CxmcPur8.js → markdownCore-QmM_aOnZ.js} +1 -1
- package/dist/assets/{miniChat-BRB11eEs.js → miniChat-BqGslD2z.js} +2 -2
- package/dist/assets/{mobile-DJZYYCuB.js → mobile-C5JOcDIC.js} +2 -2
- package/dist/assets/{nativeFileSave-B6QpoPRn.js → nativeFileSave-DSMsJqXM.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-PWoh3LNA.js → pi-session-focus-preference-Cc_S4zi1.js} +1 -1
- package/dist/assets/{renderDiffWithHighlighter-C48T6YFJ.js → renderDiffWithHighlighter-BXhnIAHg.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-N-BQdJl0.js → renderElectronMiniChatApp-CiSkecEE.js} +2 -2
- package/dist/assets/{renderFileWithHighlighter-8Kt2MyTN.js → renderFileWithHighlighter-CK29YZtC.js} +1 -1
- package/dist/assets/renderMobileApp-C4JuoxsZ.js +11 -0
- package/dist/assets/runtimeEndpointReset-Dwj-jCDS.js +66 -0
- package/dist/assets/{runtimeSurface-kIEoYsPP.js → runtimeSurface-0K7vuUpd.js} +1 -1
- package/dist/assets/{selection-BTEdLRVK.js → selection-CnYkEsu_.js} +1 -1
- package/dist/assets/useAppFontEffects-CV5UyTRw.js +226 -0
- package/dist/assets/{useGitHubRemoteSearch-DIBHNu8r.js → useGitHubRemoteSearch-CgP-zEBj.js} +1 -1
- package/dist/assets/{useSwitcherItems-DfLbfX37.js → useSwitcherItems-C8G5F0hs.js} +1 -1
- package/dist/assets/{web-components-C_DsTJis.js → web-components-BpncHjnV.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/plugins/featured.json +12 -0
- package/plugins/subagents/package.json +1 -1
- package/plugins/visuals/extension.js +7 -4
- package/plugins/visuals/package.json +1 -1
- package/server/index.js +86 -27
- package/server/lib/git/DOCUMENTATION.md +4 -0
- package/server/lib/git/service.js +70 -5
- package/server/lib/git/service.test.js +179 -0
- package/server/lib/github/DOCUMENTATION.md +2 -0
- package/server/lib/marketplace/DOCUMENTATION.md +95 -0
- package/server/lib/marketplace/featured.js +176 -0
- package/server/lib/marketplace/featured.test.js +207 -0
- package/server/lib/marketplace/npm-registry.js +255 -0
- package/server/lib/marketplace/npm-registry.test.js +227 -0
- package/server/lib/marketplace/routes.js +64 -0
- package/server/lib/marketplace/routes.test.js +119 -0
- package/server/lib/marketplace/service.js +225 -0
- package/server/lib/marketplace/service.test.js +174 -0
- package/server/lib/notifications/DOCUMENTATION.md +10 -4
- package/server/lib/notifications/pi-notification-watcher.js +92 -33
- package/server/lib/notifications/pi-notification-watcher.test.js +79 -0
- package/server/lib/open-url/DOCUMENTATION.md +1 -0
- package/server/lib/pi/merged-event-stream.js +316 -0
- package/server/lib/pi/merged-event-stream.test.js +95 -0
- package/server/lib/pi/routes-daemon-pool.test.js +348 -0
- package/server/lib/pi/routes-merged-events.test.js +327 -0
- package/server/lib/pi/routes-sandbox.test.js +1684 -0
- package/server/lib/pi/routes.js +491 -90
- package/server/lib/pi/routes.test.js +87 -2
- package/server/lib/pi/sandbox/DOCUMENTATION.md +68 -0
- package/server/lib/pi/sandbox/launcher.js +122 -0
- package/server/lib/pi/sandbox/launcher.test.js +91 -0
- package/server/lib/pi/sandbox/nono-launcher.js +455 -0
- package/server/lib/pi/sandbox/nono-launcher.test.js +371 -0
- package/server/lib/pi/sandbox/nono-profile-macos.json +20 -0
- package/server/lib/pi/sandbox/nono-profile-wsl2.json +21 -0
- package/server/lib/pi/sandbox/nono-profile.json +22 -0
- package/server/lib/pi/sandbox/project-sandbox-manager.js +1461 -0
- package/server/lib/pi/sandbox/project-sandbox-setting.js +166 -0
- package/server/lib/pi/sandbox/project-sandbox.js +207 -0
- package/server/lib/pi/sandbox/sandbox-routes.js +110 -0
- package/server/lib/pi/sandbox/sandboxed-folders.js +100 -0
- package/server/lib/pi/sandbox/sandboxed-folders.test.js +65 -0
- package/server/lib/pi/sandbox/trust-ask.js +135 -0
- package/server/lib/pi/sandbox/trust-ask.test.js +54 -0
- package/server/lib/pi/sandbox/worktree-ids.js +96 -0
- package/server/lib/pi/sandbox/worktree-ids.test.js +73 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +26 -6
- package/server/lib/pi/session-daemon/daemon-pool.js +157 -0
- package/server/lib/pi/session-daemon/daemon-process.js +10 -1
- package/server/lib/pi/session-daemon/extension-config.js +206 -23
- package/server/lib/pi/session-daemon/extension-config.test.js +180 -0
- package/server/lib/pi/session-daemon/session-daemon-read-persisted.test.js +167 -0
- package/server/lib/pi/session-daemon/session-daemon.js +368 -56
- package/server/lib/pi/session-daemon/session-daemon.test.js +227 -0
- package/server/lib/pi/session-daemon/session-idle-residency.test.js +98 -1
- package/server/lib/pi/session-daemon/session-jsonl.js +49 -10
- package/server/lib/pi/session-daemon/session-jsonl.test.js +11 -0
- package/server/lib/pi/session-daemon/session-lease.js +93 -15
- package/server/lib/pi/session-daemon/session-lease.test.js +107 -1
- package/server/lib/pi/session-daemon/supervisor-launcher-stop.test.js +295 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox-nono.e2e.test.js +301 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox.test.js +444 -0
- package/server/lib/pi/session-daemon/supervisor.js +386 -35
- package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
- package/server/lib/pi/ui-settings-store.js +88 -2
- package/server/lib/pi/ui-settings-store.test.js +118 -0
- package/server/lib/plugins/DOCUMENTATION.md +17 -5
- package/server/lib/plugins/daemon-sync.js +16 -6
- package/server/lib/plugins/daemon-sync.test.js +12 -0
- package/server/lib/plugins/impact.test.js +2 -1
- package/server/lib/plugins/manifest.js +25 -0
- package/server/lib/plugins/manifest.test.js +9 -0
- package/server/lib/plugins/routes.test.js +28 -0
- package/server/lib/plugins/service.js +24 -2
- package/server/lib/server/cross-process-lock.js +28 -3
- package/dist/assets/SettingsView-BHBpt2Um.js +0 -7
- package/dist/assets/VisualFrame-CJrAvWSo.js +0 -22
- package/dist/assets/VisualsArtifact-DqLGgU-Q.js +0 -1
- package/dist/assets/index-B2v0_mez.js +0 -11
- package/dist/assets/index-D3F4JrPN.css +0 -1
- package/dist/assets/renderMobileApp-B7cT7m5b.js +0 -11
- package/dist/assets/runtimeEndpointReset-BC6yGnxN.js +0 -62
- package/dist/assets/useAppFontEffects-EcTZ_I_I.js +0 -225
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { MarketplaceError } from './npm-registry.js';
|
|
4
|
+
import { createMarketplaceService, normalizeQuery } from './service.js';
|
|
5
|
+
|
|
6
|
+
const pkg = (name, overrides = {}) => ({
|
|
7
|
+
name,
|
|
8
|
+
version: '1.0.0',
|
|
9
|
+
description: `The ${name} package`,
|
|
10
|
+
keywords: ['pi-package'],
|
|
11
|
+
...overrides,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const hit = (name, overrides = {}, downloads) => ({
|
|
15
|
+
package: pkg(name, overrides),
|
|
16
|
+
...(downloads === undefined ? {} : { downloads: { weekly: downloads } }),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const setup = ({ objects = [], total = 0, featured = { updated: '2026-01-01', featured: [], hidden: [] }, bundled = [] } = {}) => {
|
|
20
|
+
const registry = {
|
|
21
|
+
searchRaw: vi.fn(async () => ({ total, objects })),
|
|
22
|
+
latest: vi.fn(async (name) => ({ name, version: '1.0.0', keywords: ['pi-package'] })),
|
|
23
|
+
weeklyDownloads: vi.fn(async () => undefined),
|
|
24
|
+
};
|
|
25
|
+
const featuredSource = { get: vi.fn(async () => ({ ...featured, source: 'builtin' })) };
|
|
26
|
+
const service = createMarketplaceService({
|
|
27
|
+
registry,
|
|
28
|
+
featuredSource,
|
|
29
|
+
bundledPackageNames: async () => bundled,
|
|
30
|
+
});
|
|
31
|
+
return { registry, featuredSource, service };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe('normalizeQuery', () => {
|
|
35
|
+
it('strips keyword qualifiers and control chars and caps at 100 chars', () => {
|
|
36
|
+
expect(normalizeQuery('keywords:pi-package lens')).toBe('lens');
|
|
37
|
+
expect(normalizeQuery('foo:bar hello')).toBe('hello');
|
|
38
|
+
expect(normalizeQuery('a\x00b')).toBe('a b');
|
|
39
|
+
expect(normalizeQuery('x'.repeat(200)).length).toBe(100);
|
|
40
|
+
expect(normalizeQuery(undefined)).toBe('');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('search', () => {
|
|
45
|
+
it('drops results without the pi-package keyword', async () => {
|
|
46
|
+
const { service } = setup({ objects: [hit('pi-good'), hit('plain', { keywords: ['other'] })], total: 2 });
|
|
47
|
+
const result = await service.search({ query: '', from: 0 });
|
|
48
|
+
expect(result.packages.map((entry) => entry.name)).toEqual(['pi-good']);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('drops hidden and bundled names', async () => {
|
|
52
|
+
const { service } = setup({
|
|
53
|
+
objects: [hit('pi-good'), hit('evil-pkg'), hit('bundled-pkg')],
|
|
54
|
+
total: 3,
|
|
55
|
+
featured: { updated: '2026-01-01', featured: [], hidden: ['evil-pkg'] },
|
|
56
|
+
bundled: ['bundled-pkg'],
|
|
57
|
+
});
|
|
58
|
+
const result = await service.search({ query: '', from: 0 });
|
|
59
|
+
expect(result.packages.map((entry) => entry.name)).toEqual(['pi-good']);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('filters unrelated padding and clears nextFrom when any appears', async () => {
|
|
63
|
+
const objects = Array.from({ length: 20 }, (_, index) => (
|
|
64
|
+
index === 19
|
|
65
|
+
? hit('unrelated-zzz', { description: 'zzz qqq www' })
|
|
66
|
+
: hit(`pi-lens-${index}`, { description: 'lens helper' })
|
|
67
|
+
));
|
|
68
|
+
const { service } = setup({ objects, total: 100 });
|
|
69
|
+
const result = await service.search({ query: 'lens', from: 0 });
|
|
70
|
+
expect(result.packages).toHaveLength(19);
|
|
71
|
+
expect(result.nextFrom).toBeNull();
|
|
72
|
+
expect(result).not.toHaveProperty('total');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('reports total only without a query and nextFrom for a full relevant page', async () => {
|
|
76
|
+
const objects = Array.from({ length: 20 }, (_, index) => hit(`pi-pkg-${index}`));
|
|
77
|
+
const { service } = setup({ objects, total: 100 });
|
|
78
|
+
const result = await service.search({ query: '', from: 0 });
|
|
79
|
+
expect(result.total).toBe(100);
|
|
80
|
+
expect(result.nextFrom).toBe(20);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('asks npm for pichamber-plugin only and requires both keywords', async () => {
|
|
84
|
+
const { registry, service } = setup({
|
|
85
|
+
objects: [
|
|
86
|
+
hit('pi-both', { keywords: ['pi-package', 'pichamber-plugin'] }),
|
|
87
|
+
hit('pi-narrow', { keywords: ['pichamber-plugin'] }),
|
|
88
|
+
],
|
|
89
|
+
total: 2,
|
|
90
|
+
});
|
|
91
|
+
const result = await service.search({ query: '', from: 0, pichamberOnly: true });
|
|
92
|
+
expect(registry.searchRaw).toHaveBeenCalledWith(
|
|
93
|
+
expect.objectContaining({ keywords: ['pichamber-plugin'] }),
|
|
94
|
+
);
|
|
95
|
+
expect(result.packages.map((entry) => entry.name)).toEqual(['pi-both']);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('caches results but never caches a failure', async () => {
|
|
99
|
+
const { registry, service } = setup({ objects: [hit('pi-good')], total: 1 });
|
|
100
|
+
await service.search({ query: '', from: 0 });
|
|
101
|
+
await service.search({ query: '', from: 0 });
|
|
102
|
+
expect(registry.searchRaw).toHaveBeenCalledTimes(1);
|
|
103
|
+
|
|
104
|
+
registry.searchRaw.mockRejectedValueOnce(new MarketplaceError('MARKETPLACE_UNAVAILABLE'));
|
|
105
|
+
await expect(service.search({ query: 'retry', from: 0 })).rejects.toMatchObject({ code: 'MARKETPLACE_UNAVAILABLE' });
|
|
106
|
+
const calls = registry.searchRaw.mock.calls.length;
|
|
107
|
+
await service.search({ query: 'retry', from: 0 });
|
|
108
|
+
expect(registry.searchRaw.mock.calls.length).toBe(calls + 1);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('featured', () => {
|
|
113
|
+
it('keeps listed order and marks failures unavailable with their note', async () => {
|
|
114
|
+
const registry = {
|
|
115
|
+
searchRaw: vi.fn(),
|
|
116
|
+
latest: vi.fn(async (name) => {
|
|
117
|
+
if (name === 'missing-pkg') throw new MarketplaceError('MARKETPLACE_PACKAGE_NOT_FOUND');
|
|
118
|
+
return { name, version: '2.0.0', keywords: ['pi-package'], pi: { extensions: ['./e.js'] } };
|
|
119
|
+
}),
|
|
120
|
+
weeklyDownloads: vi.fn(async () => undefined),
|
|
121
|
+
};
|
|
122
|
+
const featuredSource = {
|
|
123
|
+
get: async () => ({
|
|
124
|
+
updated: '2026-01-01',
|
|
125
|
+
featured: [{ name: 'pi-first', note: 'First' }, { name: 'missing-pkg', note: 'Gone' }],
|
|
126
|
+
hidden: [],
|
|
127
|
+
source: 'builtin',
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
130
|
+
const service = createMarketplaceService({ registry, featuredSource, bundledPackageNames: async () => [] });
|
|
131
|
+
const result = await service.featured();
|
|
132
|
+
expect(result.packages.map((entry) => entry.name)).toEqual(['pi-first', 'missing-pkg']);
|
|
133
|
+
expect(result.packages[0]).toMatchObject({ version: '2.0.0', note: 'First' });
|
|
134
|
+
expect(result.packages[0]).not.toHaveProperty('unavailable');
|
|
135
|
+
expect(result.packages[1]).toMatchObject({ note: 'Gone', unavailable: true });
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('packageDetail', () => {
|
|
140
|
+
it('answers not found for hidden and bundled names', async () => {
|
|
141
|
+
const { service } = setup({
|
|
142
|
+
featured: { updated: '2026-01-01', featured: [], hidden: ['evil-pkg'] },
|
|
143
|
+
bundled: ['bundled-pkg'],
|
|
144
|
+
});
|
|
145
|
+
await expect(service.packageDetail('evil-pkg')).rejects.toMatchObject({ code: 'MARKETPLACE_PACKAGE_NOT_FOUND' });
|
|
146
|
+
await expect(service.packageDetail('bundled-pkg')).rejects.toMatchObject({ code: 'MARKETPLACE_PACKAGE_NOT_FOUND' });
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('versions', () => {
|
|
151
|
+
it('rejects more than 50 names or invalid names', async () => {
|
|
152
|
+
const { service } = setup();
|
|
153
|
+
await expect(service.versions(Array.from({ length: 51 }, (_, index) => `pi-pkg-${index}`)))
|
|
154
|
+
.rejects.toMatchObject({ code: 'INVALID_MARKETPLACE_REQUEST' });
|
|
155
|
+
await expect(service.versions(['Bad Name'])).rejects.toMatchObject({ code: 'INVALID_MARKETPLACE_REQUEST' });
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('leaves out names npm cannot answer for', async () => {
|
|
159
|
+
const registry = {
|
|
160
|
+
searchRaw: vi.fn(),
|
|
161
|
+
latest: vi.fn(async (name) => {
|
|
162
|
+
if (name === 'pi-gone') throw new MarketplaceError('MARKETPLACE_PACKAGE_NOT_FOUND');
|
|
163
|
+
return { name, version: '3.1.0', keywords: ['pi-package'] };
|
|
164
|
+
}),
|
|
165
|
+
weeklyDownloads: vi.fn(),
|
|
166
|
+
};
|
|
167
|
+
const service = createMarketplaceService({
|
|
168
|
+
registry,
|
|
169
|
+
featuredSource: { get: async () => ({ updated: null, featured: [], hidden: [], source: 'builtin' }) },
|
|
170
|
+
bundledPackageNames: async () => [],
|
|
171
|
+
});
|
|
172
|
+
await expect(service.versions(['pi-ok', 'pi-gone'])).resolves.toEqual({ versions: { 'pi-ok': '3.1.0' } });
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -7,8 +7,12 @@ model OpenCode questions, permissions, subagents, or tool completion, and it
|
|
|
7
7
|
sends nothing off the machine: there is no push delivery, no registered
|
|
8
8
|
routes, and no hosted relay.
|
|
9
9
|
|
|
10
|
-
`pi-notification-watcher.js` maintains one server-owned subscription
|
|
11
|
-
session daemon
|
|
10
|
+
`pi-notification-watcher.js` maintains one server-owned subscription per live
|
|
11
|
+
Pi session daemon in the daemon pool (`../pi/session-daemon/daemon-pool.js`).
|
|
12
|
+
It subscribes to daemons registered later, closes the subscription of a
|
|
13
|
+
daemon that is removed, and starts over with a fresh cursor when a key's
|
|
14
|
+
runtime is replaced. One tracker sees every daemon's events; session ids are
|
|
15
|
+
unique across daemons because a session is leased to one daemon at a time. A live `busy` or `retry` lifecycle, or an assistant start,
|
|
12
16
|
opens a turn. The first terminal `idle` emits a completion notification and
|
|
13
17
|
the first `session.error` or terminal `error` emits an error notification.
|
|
14
18
|
Duplicate terminal boundaries do nothing. Bootstrap snapshots seed activity but
|
|
@@ -46,5 +50,7 @@ in place and no migration runs.
|
|
|
46
50
|
|
|
47
51
|
## Failure behavior
|
|
48
52
|
|
|
49
|
-
The watcher reconnects
|
|
50
|
-
replayed terminal events remain deduplicated by the
|
|
53
|
+
The watcher reconnects each daemon with that daemon's own sequence and
|
|
54
|
+
stream epoch, so replayed terminal events remain deduplicated by the
|
|
55
|
+
active-turn state. A daemon that fails retries alone; the others keep
|
|
56
|
+
delivering.
|
|
@@ -69,18 +69,80 @@ export const createPiNotificationTracker = ({ emit }) => {
|
|
|
69
69
|
return { accept };
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
+
// One daemon's subscription: its own replay cursor (sequence and stream
|
|
73
|
+
// epoch are per daemon), retry timer, and close. A subscription that
|
|
74
|
+
// resolves after `close()` is closed at once.
|
|
75
|
+
const createDaemonConnection = ({ runtime, retryMs, onEvent }) => {
|
|
76
|
+
let closed = false;
|
|
77
|
+
let closeSubscription = null;
|
|
78
|
+
let retryTimer = null;
|
|
79
|
+
let fromSequence;
|
|
80
|
+
let streamEpoch;
|
|
81
|
+
|
|
82
|
+
const scheduleReconnect = () => {
|
|
83
|
+
if (closed || retryTimer) return;
|
|
84
|
+
closeSubscription?.();
|
|
85
|
+
closeSubscription = null;
|
|
86
|
+
retryTimer = setTimeout(() => {
|
|
87
|
+
retryTimer = null;
|
|
88
|
+
void connect();
|
|
89
|
+
}, retryMs);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const connect = async () => {
|
|
93
|
+
if (closed) return;
|
|
94
|
+
try {
|
|
95
|
+
closeSubscription?.();
|
|
96
|
+
closeSubscription = null;
|
|
97
|
+
const close = await runtime.subscribe({
|
|
98
|
+
...(Number.isSafeInteger(fromSequence) && streamEpoch ? { fromSequence, streamEpoch } : {}),
|
|
99
|
+
onEvent: (event) => {
|
|
100
|
+
if (typeof event.streamEpoch === 'string') streamEpoch = event.streamEpoch;
|
|
101
|
+
if (Number.isSafeInteger(event.sequence)) fromSequence = event.sequence;
|
|
102
|
+
onEvent(event);
|
|
103
|
+
},
|
|
104
|
+
onError: scheduleReconnect,
|
|
105
|
+
});
|
|
106
|
+
if (closed) close?.();
|
|
107
|
+
else closeSubscription = close;
|
|
108
|
+
} catch {
|
|
109
|
+
scheduleReconnect();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
runtime,
|
|
115
|
+
connect,
|
|
116
|
+
close: () => {
|
|
117
|
+
closed = true;
|
|
118
|
+
if (retryTimer) clearTimeout(retryTimer);
|
|
119
|
+
retryTimer = null;
|
|
120
|
+
closeSubscription?.();
|
|
121
|
+
closeSubscription = null;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Watches every live session daemon in `daemonPool` (or the single
|
|
128
|
+
* `supervisor`) and follows daemons as they are registered and removed.
|
|
129
|
+
* One daemon failing only retries that daemon.
|
|
130
|
+
*/
|
|
72
131
|
export const createPiNotificationWatcher = ({
|
|
73
132
|
supervisor,
|
|
133
|
+
daemonPool = {
|
|
134
|
+
live: () => (supervisor ? [{ key: 'main', runtime: supervisor }] : []),
|
|
135
|
+
onChange: () => () => {},
|
|
136
|
+
},
|
|
74
137
|
uiSettingsStore,
|
|
75
138
|
notify,
|
|
76
139
|
retryMs = 1_000,
|
|
77
140
|
notifyTimeoutMs = 15_000,
|
|
78
141
|
}) => {
|
|
79
142
|
let stopped = false;
|
|
80
|
-
let
|
|
81
|
-
let
|
|
82
|
-
|
|
83
|
-
let streamEpoch;
|
|
143
|
+
let started = false;
|
|
144
|
+
let unsubscribePool = null;
|
|
145
|
+
const connections = new Map();
|
|
84
146
|
let notifyChain = Promise.resolve();
|
|
85
147
|
|
|
86
148
|
const tracker = createPiNotificationTracker({
|
|
@@ -116,42 +178,39 @@ export const createPiNotificationWatcher = ({
|
|
|
116
178
|
},
|
|
117
179
|
});
|
|
118
180
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
closeSubscription = null;
|
|
123
|
-
retryTimer = setTimeout(() => {
|
|
124
|
-
retryTimer = null;
|
|
125
|
-
void connect();
|
|
126
|
-
}, retryMs);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const connect = async () => {
|
|
181
|
+
// Bring subscriptions in line with the pool: connect new daemons, close
|
|
182
|
+
// removed ones, and start over (fresh cursor) for a replaced runtime.
|
|
183
|
+
const sync = async () => {
|
|
130
184
|
if (stopped) return;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (typeof event.streamEpoch === 'string') streamEpoch = event.streamEpoch;
|
|
137
|
-
if (Number.isSafeInteger(event.sequence)) fromSequence = event.sequence;
|
|
138
|
-
tracker.accept(event);
|
|
139
|
-
},
|
|
140
|
-
onError: scheduleReconnect,
|
|
141
|
-
});
|
|
142
|
-
} catch {
|
|
143
|
-
scheduleReconnect();
|
|
185
|
+
const live = new Map(daemonPool.live().map(({ key, runtime }) => [key, runtime]));
|
|
186
|
+
for (const [key, connection] of connections) {
|
|
187
|
+
if (live.get(key) === connection.runtime) continue;
|
|
188
|
+
connection.close();
|
|
189
|
+
connections.delete(key);
|
|
144
190
|
}
|
|
191
|
+
const opening = [];
|
|
192
|
+
for (const [key, runtime] of live) {
|
|
193
|
+
if (connections.has(key)) continue;
|
|
194
|
+
const connection = createDaemonConnection({ runtime, retryMs, onEvent: tracker.accept });
|
|
195
|
+
connections.set(key, connection);
|
|
196
|
+
opening.push(connection.connect());
|
|
197
|
+
}
|
|
198
|
+
await Promise.all(opening);
|
|
145
199
|
};
|
|
146
200
|
|
|
147
201
|
return {
|
|
148
|
-
start:
|
|
202
|
+
start: async () => {
|
|
203
|
+
if (stopped || started) return;
|
|
204
|
+
started = true;
|
|
205
|
+
unsubscribePool = daemonPool.onChange(() => { void sync(); });
|
|
206
|
+
await sync();
|
|
207
|
+
},
|
|
149
208
|
stop: async () => {
|
|
150
209
|
stopped = true;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
210
|
+
unsubscribePool?.();
|
|
211
|
+
unsubscribePool = null;
|
|
212
|
+
for (const connection of connections.values()) connection.close();
|
|
213
|
+
connections.clear();
|
|
155
214
|
await notifyChain;
|
|
156
215
|
},
|
|
157
216
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import { createPiNotificationTracker, createPiNotificationWatcher } from './pi-notification-watcher.js';
|
|
4
|
+
import { createPiDaemonPool } from '../pi/session-daemon/daemon-pool.js';
|
|
4
5
|
|
|
5
6
|
const event = (name, sequence, payload = {}, sessionId = 'session-1') => ({
|
|
6
7
|
protocolVersion: 1,
|
|
@@ -177,4 +178,82 @@ describe('Pi notification tracker', () => {
|
|
|
177
178
|
warn.mockRestore();
|
|
178
179
|
}
|
|
179
180
|
});
|
|
181
|
+
|
|
182
|
+
it('watches every live daemon in the pool and follows daemons that come and go', async () => {
|
|
183
|
+
const seen = [];
|
|
184
|
+
const subscriptions = new Map();
|
|
185
|
+
const fakeDaemon = (name, { fail = false } = {}) => ({
|
|
186
|
+
request: async () => ({}),
|
|
187
|
+
subscribe: async (options) => {
|
|
188
|
+
if (fail) throw new Error('unavailable');
|
|
189
|
+
const entry = { options, closed: false };
|
|
190
|
+
subscriptions.set(name, [...(subscriptions.get(name) ?? []), entry]);
|
|
191
|
+
return () => { entry.closed = true; };
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
const main = fakeDaemon('main');
|
|
195
|
+
const broken = fakeDaemon('broken', { fail: true });
|
|
196
|
+
const sandbox = fakeDaemon('sandbox');
|
|
197
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
198
|
+
pool.register('project-broken', { runtime: broken, directories: ['/broken'] });
|
|
199
|
+
const watcher = createPiNotificationWatcher({
|
|
200
|
+
daemonPool: pool,
|
|
201
|
+
uiSettingsStore: { read: async () => ({ nativeNotificationsEnabled: true }) },
|
|
202
|
+
notify: async (payload) => { seen.push(payload.sessionId); },
|
|
203
|
+
retryMs: 60_000,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
await watcher.start();
|
|
207
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
208
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
209
|
+
|
|
210
|
+
const emit = (name, sessionId, sequence, state) => subscriptions.get(name).at(-1).options
|
|
211
|
+
.onEvent(event('session.lifecycle', sequence, { state }, sessionId));
|
|
212
|
+
emit('main', 'main-session', 1, 'busy');
|
|
213
|
+
emit('sandbox', 'box-session', 1, 'busy');
|
|
214
|
+
emit('sandbox', 'box-session', 2, 'idle');
|
|
215
|
+
emit('main', 'main-session', 2, 'idle');
|
|
216
|
+
|
|
217
|
+
// Each daemon resumes from its own cursor.
|
|
218
|
+
subscriptions.get('sandbox').at(-1).options.onError(new Error('gone'));
|
|
219
|
+
pool.unregister('project-a');
|
|
220
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
221
|
+
expect(subscriptions.get('sandbox').at(-1).closed).toBe(true);
|
|
222
|
+
|
|
223
|
+
await watcher.stop();
|
|
224
|
+
expect(subscriptions.get('main').at(-1).closed).toBe(true);
|
|
225
|
+
expect(seen).toEqual(['box-session', 'main-session']);
|
|
226
|
+
expect(subscriptions.get('main')).toHaveLength(1);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('reconnects each daemon with its own cursor', async () => {
|
|
230
|
+
const subscriptions = { main: [], sandbox: [] };
|
|
231
|
+
const fakeDaemon = (name) => ({
|
|
232
|
+
request: async () => ({}),
|
|
233
|
+
subscribe: async (options) => {
|
|
234
|
+
subscriptions[name].push(options);
|
|
235
|
+
return () => {};
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
const main = fakeDaemon('main');
|
|
239
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
240
|
+
pool.register('project-a', { runtime: fakeDaemon('sandbox'), directories: ['/work/a'] });
|
|
241
|
+
const watcher = createPiNotificationWatcher({
|
|
242
|
+
daemonPool: pool,
|
|
243
|
+
uiSettingsStore: { read: async () => ({}) },
|
|
244
|
+
notify: async () => undefined,
|
|
245
|
+
retryMs: 1,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
await watcher.start();
|
|
249
|
+
subscriptions.main[0].onEvent({ ...event('session.lifecycle', 30, { state: 'busy' }), streamEpoch: 'epoch-main' });
|
|
250
|
+
subscriptions.sandbox[0].onEvent({ ...event('session.lifecycle', 4, { state: 'busy' }), streamEpoch: 'epoch-box' });
|
|
251
|
+
subscriptions.sandbox[0].onError(new Error('disconnected'));
|
|
252
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
253
|
+
await watcher.stop();
|
|
254
|
+
|
|
255
|
+
expect(subscriptions.main).toHaveLength(1);
|
|
256
|
+
expect(subscriptions.sandbox).toHaveLength(2);
|
|
257
|
+
expect(subscriptions.sandbox[1]).toMatchObject({ fromSequence: 4, streamEpoch: 'epoch-box' });
|
|
258
|
+
});
|
|
180
259
|
});
|
|
@@ -9,6 +9,7 @@ When a tool on the server machine wants to show the person a URL (an extension s
|
|
|
9
9
|
1. `daemon-process.js` calls `ensureOpenUrlBrowser` (`browser-env.js`) before any session starts. It writes an owner-only launcher script and points `$BROWSER` at it, keeping the previous value in `PICHAMBER_ORIGINAL_BROWSER` and the intake path in `PICHAMBER_OPEN_URL_SOCKET`. Every bash command and in-process extension inherits that environment. A watchdog (`watchOpenUrlBrowser`) re-checks the launcher every minute for the life of the daemon.
|
|
10
10
|
2. The launcher runs `browser-handler.mjs` with the URL arguments. Each http(s) URL is posted to the intake together with `PI_SESSION_ID` when the caller is a bash command.
|
|
11
11
|
3. `intake.js`, bound by the PiChamber server (`index.js`) on `<runtimeDir>/open-url.sock`, asks the daemon to publish (`openUrl.publish`). The daemon attributes the request (`session-daemon/open-request.js`) and publishes `session.openUrl` on that session's event stream.
|
|
12
|
+
A sandboxed project's daemon (`../pi/sandbox/project-sandbox-manager.js`) gets its own intake on `<its runtime folder>/open-url.sock`, started before the daemon and stopped with it, which publishes through that daemon's `openUrl.publish`. A request from a sandboxed bash command never reaches the main daemon. Its published event reaches devices through the merged `/api/pi/events` stream, like any event from that daemon.
|
|
12
13
|
4. Devices ask the person whether to open it (`packages/ui/src/components/chat/OpenRequestAlerts.tsx`). Nothing opens without a click.
|
|
13
14
|
5. The intake answers `{ delivered }`. `delivered` is true only when a device holds a live `/api/pi/events` stream and the daemon published. Otherwise the handler falls back to the original `$BROWSER` list, then `open` (macOS) or `xdg-open`, with `$BROWSER` restored in that child's environment so it cannot loop back.
|
|
14
15
|
|