@pi-chamber/web 1.0.4 → 1.0.5-rc.1
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/README.md +1 -1
- package/bin/cli.js +21 -2
- package/bin/cli.test.js +164 -4
- package/bin/lib/DOCUMENTATION.md +3 -3
- package/bin/lib/cli-args.js +96 -13
- package/bin/lib/commands-connect-url-tailscale.test.js +136 -0
- package/bin/lib/commands-connect-url.js +146 -39
- package/bin/lib/commands-connect-url.test.js +126 -0
- package/bin/lib/commands-serve.js +45 -2
- package/bin/lib/commands-status.js +28 -5
- package/bin/lib/commands-status.test.js +107 -0
- package/bin/lib/commands-tunnel.js +36 -10
- package/dist/assets/{DiagramView-BpG1c3Hi.js → DiagramView-D-OSWTbO.js} +1 -1
- package/dist/assets/DiffView-BKT-MIH4.js +18 -0
- package/dist/assets/{FileSaveConflictDialog-DP7k9a-i.js → FileSaveConflictDialog-DBkVFssC.js} +2 -2
- package/dist/assets/FilesView-B7GIuRlh.js +6 -0
- package/dist/assets/{GitHubDetailScaffold-UxLAMAOl.js → GitHubDetailScaffold-C9rCZMUT.js} +2 -2
- package/dist/assets/{GitHubLinkPicker-Bh9RO1yK.js → GitHubLinkPicker-Bm09hvhJ.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-DQyhT5wG.js → GitHubListPrimitives-DlhAlxI6.js} +1 -1
- package/dist/assets/{GitView-XBBheKRM.js → GitView-BgqdMb0m.js} +4 -4
- package/dist/assets/{IssuesSurface-BA1kpvAJ.js → IssuesSurface-BZXAvt49.js} +3 -3
- package/dist/assets/{JsonTreeView-BAaEPL4O.js → JsonTreeView-BKgCQjh_.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DzgDmUsL.js → MarkdownRendererImpl-BdcyMPw-.js} +1 -1
- package/dist/assets/{PatchDiff-BMEUsgXH.js → PatchDiff-2MmWXcGe.js} +1 -1
- package/dist/assets/PierreDiffViewer-D1F2WvD0.js +135 -0
- package/dist/assets/PullRequestsSurface-CN2z3DFv.js +2 -0
- package/dist/assets/SessionSwitcherContent-CCljxAZb.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-DtNt3qw4.js +2 -0
- package/dist/assets/SessionUnreadDot-B9bHMy5q.js +1 -0
- package/dist/assets/SettingsView-DaZVCInW.js +6 -0
- package/dist/assets/{SettingsWindow-j0e99YI0.js → SettingsWindow-C-ydfopH.js} +1 -1
- package/dist/assets/StickyHorizontalScrollbar-BMITjK4e.js +8 -0
- package/dist/assets/{ToolOutputDialog-VlS12Xyq.js → ToolOutputDialog-DJUAx_Oj.js} +4 -4
- package/dist/assets/{ToolPartDiffPreview-DdSneZws.js → ToolPartDiffPreview-DFyuJM4c.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-BqiXjvP6.js → VirtualizedFileDiff-BS-af6rn.js} +4 -4
- package/dist/assets/{Virtualizer-Cp_cJWbI.js → Virtualizer-DP6HbEeC.js} +1 -1
- package/dist/assets/{collapsible-C7oyikVm.js → collapsible-BOcd0lzY.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-BJjC-tXV.js → computeVirtualFileMetrics-BI6wORhM.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-BBzqKGei.js → contextFileOpenGuard-DUMSGR4M.js} +1 -1
- package/dist/assets/{gitStatusPredicates-Dq-E5DaH.js → gitStatusPredicates-FdKYDZe3.js} +1 -1
- package/dist/assets/{githubLink-Cryd7GkG.js → githubLink-B3-BaGpb.js} +5 -5
- package/dist/assets/index-DWSrsQWl.js +11 -0
- package/dist/assets/{index-BbhXFTId.js → index-Df-vmvzu.js} +1 -1
- package/dist/assets/index-DsQIBAWK.css +1 -0
- package/dist/assets/main-61_cd7S7.js +2 -0
- package/dist/assets/main-q43jqZ2I.js +136 -0
- package/dist/assets/{markdownCore-B9AuEyYi.js → markdownCore-CqHYlXi_.js} +2 -2
- package/dist/assets/{miniChat-CgOaJfD8.js → miniChat-vOuWN5pV.js} +2 -2
- package/dist/assets/mobile-mrXWV5ky.js +2 -0
- package/dist/assets/{nativeFileSave-BzhtrDoD.js → nativeFileSave-CFuugNKV.js} +1 -1
- package/dist/assets/pi-session-focus-preference-BEufpwC6.js +9 -0
- package/dist/assets/{renderDiffWithHighlighter-CVLsdtQ5.js → renderDiffWithHighlighter-BD9CAhZU.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-QQFXkY5Y.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-DJ9mk2bZ.js → renderFileWithHighlighter-KiEWMtzI.js} +1 -1
- package/dist/assets/renderMobileApp-DIZYvrhi.js +11 -0
- package/dist/assets/runtimeEndpointReset-BA2uP2rj.js +62 -0
- package/dist/assets/{runtimeSurface-DBiUWYK2.js → runtimeSurface-Der4qUnI.js} +1 -1
- package/dist/assets/useAppFontEffects-Bfw_d5eB.js +212 -0
- package/dist/assets/{useFilesViewSearch-D2Au5Xgt.js → useFilesViewSearch-Budwejnx.js} +3 -3
- package/dist/assets/useGitHubRemoteSearch-gUdylYy3.js +1 -0
- package/dist/assets/{useSwitcherItems-Dej8BzXI.js → useSwitcherItems-yHSMduoo.js} +1 -1
- package/dist/assets/{vendor-aparajita-capacitor-secure-storage-BYohCVY0.js → vendor-aparajita-capacitor-secure-storage-BDrMx_CE.js} +1 -1
- package/dist/assets/{vendor-base-ui-BscvGUFt.js → vendor-base-ui-CKRUCG-f.js} +1 -1
- package/dist/assets/{vendor-boot-Dgb9NVFe.js → vendor-boot-EC6IyLt1.js} +13 -13
- package/dist/assets/{vendor-capacitor-app-BjdQVib9.js → vendor-capacitor-app-BaupizkW.js} +1 -1
- package/dist/assets/{vendor-capacitor-keyboard-eTtI5go3.js → vendor-capacitor-keyboard-9BVxykO7.js} +1 -1
- package/dist/assets/{vendor-capacitor-status-bar-9rNIGxlO.js → vendor-capacitor-status-bar-BsrUwiaA.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-DxS3jwvE.js → vendor-codemirror-autocomplete-CGpAsPWp.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-DdjXl9e2.js → vendor-codemirror-lang-angular-CDJoHJSY.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp--aMr7NVt.js → vendor-codemirror-lang-cpp-BmHofQls.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-CZ_qxZY9.js → vendor-codemirror-lang-css-RM2HqXZ0.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-Ca-y2Alu.js → vendor-codemirror-lang-go-Crwca_X7.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-COZ0L5wT.js → vendor-codemirror-lang-html-CHSHUpwq.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-D3Rf3QNJ.js → vendor-codemirror-lang-java-lhQXgWu0.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-DwJ-IvCs.js → vendor-codemirror-lang-javascript-Dw4kFO4e.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-D_5lod6k.js → vendor-codemirror-lang-jinja-_pAC3UTN.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-BG8C7OpC.js → vendor-codemirror-lang-json-B-b1vAv-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-CVEkoaTw.js → vendor-codemirror-lang-less-xIgOi1ze.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-U9vj0m8w.js → vendor-codemirror-lang-liquid-CP49m5dB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-DqlYH9gY.js → vendor-codemirror-lang-markdown-BTht2ATe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-BFEiEVA1.js → vendor-codemirror-lang-php-BguZDhaO.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-Cz1dQXQd.js → vendor-codemirror-lang-python-CH6_em9L.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_CoD9mj.js → vendor-codemirror-lang-rust-EG_DtGyi.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-BuR0aKh5.js → vendor-codemirror-lang-sass-BknY5Qpo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-DggNUjdM.js → vendor-codemirror-lang-sql-B0f-qCZo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DFZHi2J3.js → vendor-codemirror-lang-vue-CyGn9snv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-zuTN3SHT.js → vendor-codemirror-lang-wast-CsFfSyyB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrcvhI-k.js → vendor-codemirror-lang-xml-Cdan_Jp1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-DcVWsakb.js → vendor-codemirror-lang-yaml-COI5hck8.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-CCLITgCF.js → vendor-codemirror-language-data-CqU7kHmg.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-H7NOEdbX.js → vendor-codemirror-search-DUfSCF9S.js} +1 -1
- package/dist/assets/{vendor-lezer-cpp-C8aD2KAr.js → vendor-lezer-cpp-DMZOJzBa.js} +1 -1
- package/dist/assets/{vendor-lezer-css-2lbTJF-Y.js → vendor-lezer-css-DUkkbMp7.js} +1 -1
- package/dist/assets/{vendor-lezer-go-Bw6LFTrZ.js → vendor-lezer-go-CHIhCNY6.js} +1 -1
- package/dist/assets/{vendor-lezer-html-D7ym2z7S.js → vendor-lezer-html-B3h0MOrG.js} +1 -1
- package/dist/assets/{vendor-lezer-java-CZhK7w21.js → vendor-lezer-java-tMazV_6X.js} +1 -1
- package/dist/assets/{vendor-lezer-javascript-rpKeTHZp.js → vendor-lezer-javascript-ctwLWf4v.js} +1 -1
- package/dist/assets/{vendor-lezer-json-C7jwsd2G.js → vendor-lezer-json-BP_UAzLL.js} +1 -1
- package/dist/assets/{vendor-lezer-lr-DR-ylqNN.js → vendor-lezer-lr-B8TQctNw.js} +1 -1
- package/dist/assets/{vendor-lezer-markdown-Bir0m5nB.js → vendor-lezer-markdown-aGLZf_3h.js} +1 -1
- package/dist/assets/{vendor-lezer-php-y0hIEfo1.js → vendor-lezer-php-D5zCNzlt.js} +1 -1
- package/dist/assets/{vendor-lezer-python-D64A9lNV.js → vendor-lezer-python-EJ4Im4y2.js} +1 -1
- package/dist/assets/{vendor-lezer-rust-E3ZA9T2L.js → vendor-lezer-rust-DO5c7OtA.js} +1 -1
- package/dist/assets/{vendor-lezer-sass-C5UFI9SP.js → vendor-lezer-sass-CMi6zfXI.js} +1 -1
- package/dist/assets/{vendor-lezer-xml-DOy7FzCR.js → vendor-lezer-xml-0MHMeZDp.js} +1 -1
- package/dist/assets/{vendor-lezer-yaml-kEjaSCvZ.js → vendor-lezer-yaml-BE2EFjpA.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-BLfh0LPy.js → vendor-replit-codemirror-vim-AnOuN8yJ.js} +1 -1
- package/dist/assets/{web-components-C7CmoFxi.js → web-components-CeHLxvED.js} +3 -3
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/dist/sw.js +1 -1
- package/package.json +1 -2
- package/server/index.js +69 -30
- package/server/lib/client-auth/DOCUMENTATION.md +15 -1
- package/server/lib/client-auth/pairing.js +2 -12
- package/server/lib/client-auth/remote-clients.js +2 -12
- package/server/lib/cloudflare-tunnel.js +0 -132
- package/server/lib/fs/DOCUMENTATION.md +8 -0
- package/server/lib/fs/atomic-write.js +111 -0
- package/server/lib/fs/atomic-write.test.js +133 -0
- package/server/lib/notifications/DOCUMENTATION.md +43 -32
- package/server/lib/notifications/pi-notification-watcher.js +8 -7
- package/server/lib/notifications/pi-notification-watcher.test.js +88 -2
- package/server/lib/pi/routes-extension-events.test.js +231 -0
- package/server/lib/pi/routes.js +137 -4
- package/server/lib/pi/routes.test.js +248 -2
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +17 -4
- package/server/lib/pi/session-daemon/daemon-process.js +2 -0
- package/server/lib/pi/session-daemon/engines/index.js +6 -0
- package/server/lib/pi/session-daemon/extension-bridge-draft.test.js +1 -1
- package/server/lib/pi/session-daemon/extension-bridge.js +24 -0
- package/server/lib/pi/session-daemon/extension-message-render.js +74 -0
- package/server/lib/pi/session-daemon/extension-message-render.test.js +164 -0
- package/server/lib/pi/session-daemon/extension-tool-render.js +13 -6
- package/server/lib/pi/session-daemon/pending-input.js +188 -0
- package/server/lib/pi/session-daemon/pending-input.test.js +202 -0
- package/server/lib/pi/session-daemon/session-daemon-engines.test.js +828 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +296 -6
- package/server/lib/pi/session-daemon/session-daemon-turn.e2e.test.js +9 -0
- package/server/lib/pi/session-daemon/session-daemon.js +219 -19
- package/server/lib/pi/session-daemon/session-daemon.test.js +30 -2
- package/server/lib/pi/session-daemon/session-engine-router.js +390 -0
- package/server/lib/pi/session-daemon/session-engine-router.test.js +515 -0
- package/server/lib/pi/session-daemon/session-engines.js +467 -0
- package/server/lib/pi/session-daemon/session-engines.test.js +383 -0
- package/server/lib/pi/snippets-store.js +8 -17
- package/server/lib/pi/ui-settings-store.js +6 -10
- package/server/lib/pi/ui-settings-store.test.js +37 -1
- package/server/lib/relay/DOCUMENTATION.md +6 -4
- package/server/lib/relay/identity-store.js +116 -0
- package/server/lib/relay/identity-store.test.js +169 -0
- package/server/lib/relay/identity.js +6 -4
- package/server/lib/relay/server-id.js +63 -0
- package/server/lib/relay/server-id.test.js +132 -0
- package/server/lib/relay/signing-key.js +14 -11
- package/server/lib/security/bind-host.js +6 -2
- package/server/lib/security/bind-host.test.js +17 -0
- package/server/lib/server/core-routes.js +27 -1
- package/server/lib/server/lan-addresses.js +18 -6
- package/server/lib/server/lan-addresses.test.js +28 -0
- package/server/lib/server/tunnel-auth.js +47 -7
- package/server/lib/server/tunnel-auth.rate-limit.test.js +164 -0
- package/server/lib/server/tunnel-service.DOCUMENTATION.md +3 -4
- package/server/lib/server/tunnel-service.js +23 -20
- package/server/lib/server/tunnel-service.test.js +19 -2
- package/server/lib/stt/config-store.js +5 -15
- package/server/lib/tailscale/DOCUMENTATION.md +264 -0
- package/server/lib/tailscale/routes.js +45 -0
- package/server/lib/tailscale/service.js +959 -0
- package/server/lib/tailscale/tailscale.js +302 -0
- package/server/lib/tailscale/tailscale.test.js +1861 -0
- package/server/lib/tunnels/DOCUMENTATION.md +3 -4
- package/server/lib/tunnels/providers/cloudflare.js +1 -22
- package/server/lib/tunnels/types.js +0 -2
- package/server/lib/ui-auth/DOCUMENTATION.md +31 -0
- package/server/lib/ui-auth/ui-auth.js +80 -6
- package/server/lib/ui-auth/ui-auth.test.js +136 -0
- package/server/lib/ui-auth/ui-passkeys.js +2 -13
- package/server/lib/update-job-store.js +4 -6
- package/dist/assets/DiffView-BxwoRCYx.js +0 -18
- package/dist/assets/FilesView-D_2QcdUt.js +0 -6
- package/dist/assets/PierreDiffViewer-BW8MO-O6.js +0 -134
- package/dist/assets/PullRequestsSurface-B3ictm4I.js +0 -2
- package/dist/assets/SessionSwitcherContent-rLoyVqgs.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-CfySKnUu.js +0 -2
- package/dist/assets/SessionUnreadDot-CmEF9sxM.js +0 -1
- package/dist/assets/SettingsView-BiwlwnTK.js +0 -6
- package/dist/assets/index-BnZVqcki.js +0 -11
- package/dist/assets/index-BnieExes.css +0 -1
- package/dist/assets/main-9O5IAtT_.js +0 -136
- package/dist/assets/main-DWGwALIw.js +0 -2
- package/dist/assets/mobile-BbJcYVym.js +0 -2
- package/dist/assets/pi-session-focus-preference-Bmk1iOvn.js +0 -10
- package/dist/assets/renderElectronMiniChatApp-R5o9NwFC.js +0 -2
- package/dist/assets/renderMobileApp-CQ9tWYIj.js +0 -11
- package/dist/assets/runtimeEndpointReset-CtK4C_5h.js +0 -62
- package/dist/assets/useAppFontEffects-DviRbaCJ.js +0 -212
- package/dist/assets/useGitHubRemoteSearch-D-K7aolk.js +0 -1
- package/dist/assets/vendor-capacitor-push-notifications-CBKq2Arn.js +0 -1
- package/server/lib/notifications/delivery-runtime.js +0 -314
- package/server/lib/notifications/delivery-runtime.test.js +0 -85
- package/server/lib/notifications/routes.js +0 -74
- package/server/lib/relay/service.js +0 -9
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import fsPromises, { lstat, mkdir, mkdtemp, readdir, readFile, readlink, rm, stat, symlink, writeFile } from 'node:fs/promises';
|
|
3
|
+
import fsSync from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
import { writeFileAtomic, writeFileAtomicSync } from './atomic-write.js';
|
|
8
|
+
|
|
9
|
+
const directories = [];
|
|
10
|
+
|
|
11
|
+
const makeRoot = async () => {
|
|
12
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-atomic-write-'));
|
|
13
|
+
directories.push(root);
|
|
14
|
+
return root;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
afterEach(async () => {
|
|
18
|
+
await Promise.all(directories.splice(0).map((directory) => rm(directory, { recursive: true, force: true })));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const variants = [
|
|
22
|
+
['writeFileAtomic', (file, data, options) => writeFileAtomic(file, data, options), fsPromises],
|
|
23
|
+
['writeFileAtomicSync', async (file, data, options) => writeFileAtomicSync(file, data, options), fsSync],
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
describe.each(variants)('%s', (_name, write, defaultFs) => {
|
|
27
|
+
it('replaces a regular file with mode 0600', async () => {
|
|
28
|
+
const root = await makeRoot();
|
|
29
|
+
const file = join(root, 'settings.json');
|
|
30
|
+
await writeFile(file, 'old', { mode: 0o644 });
|
|
31
|
+
|
|
32
|
+
await expect(write(file, 'new')).resolves.toBe(file);
|
|
33
|
+
|
|
34
|
+
expect(await readFile(file, 'utf8')).toBe('new');
|
|
35
|
+
expect((await lstat(file)).isFile()).toBe(true);
|
|
36
|
+
if (process.platform !== 'win32') expect((await stat(file)).mode & 0o777).toBe(0o600);
|
|
37
|
+
expect(await readdir(root)).toEqual(['settings.json']);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('writes through an absolute symlink and keeps the link', async () => {
|
|
41
|
+
const root = await makeRoot();
|
|
42
|
+
const dotfiles = join(root, 'dotfiles');
|
|
43
|
+
const config = join(root, 'config');
|
|
44
|
+
await mkdir(dotfiles);
|
|
45
|
+
await mkdir(config);
|
|
46
|
+
const target = join(dotfiles, 'settings.json');
|
|
47
|
+
const link = join(config, 'settings.json');
|
|
48
|
+
await writeFile(target, 'old');
|
|
49
|
+
await symlink(target, link);
|
|
50
|
+
|
|
51
|
+
await expect(write(link, 'new')).resolves.toBe(await fsPromises.realpath(target));
|
|
52
|
+
|
|
53
|
+
expect((await lstat(link)).isSymbolicLink()).toBe(true);
|
|
54
|
+
expect(await readlink(link)).toBe(target);
|
|
55
|
+
expect(await readFile(target, 'utf8')).toBe('new');
|
|
56
|
+
if (process.platform !== 'win32') expect((await stat(target)).mode & 0o777).toBe(0o600);
|
|
57
|
+
expect(await readdir(config)).toEqual(['settings.json']);
|
|
58
|
+
expect(await readdir(dotfiles)).toEqual(['settings.json']);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('writes through a relative symlink and keeps the link', async () => {
|
|
62
|
+
const root = await makeRoot();
|
|
63
|
+
await mkdir(join(root, 'dotfiles', 'pi'), { recursive: true });
|
|
64
|
+
await mkdir(join(root, 'config', 'pi'), { recursive: true });
|
|
65
|
+
const target = join(root, 'dotfiles', 'pi', 'snippets.json');
|
|
66
|
+
const link = join(root, 'config', 'pi', 'snippets.json');
|
|
67
|
+
await writeFile(target, 'old');
|
|
68
|
+
await symlink('../../dotfiles/pi/snippets.json', link);
|
|
69
|
+
|
|
70
|
+
await write(link, 'new');
|
|
71
|
+
|
|
72
|
+
expect(await readlink(link)).toBe('../../dotfiles/pi/snippets.json');
|
|
73
|
+
expect(await readFile(target, 'utf8')).toBe('new');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('writes to the target of a dangling symlink instead of replacing the link', async () => {
|
|
77
|
+
const root = await makeRoot();
|
|
78
|
+
await mkdir(join(root, 'config'));
|
|
79
|
+
const link = join(root, 'config', 'config.json');
|
|
80
|
+
const target = join(root, 'dotfiles', 'stt', 'config.json');
|
|
81
|
+
await symlink('../dotfiles/stt/config.json', link);
|
|
82
|
+
|
|
83
|
+
await expect(write(link, 'new')).resolves.toBe(target);
|
|
84
|
+
|
|
85
|
+
expect((await lstat(link)).isSymbolicLink()).toBe(true);
|
|
86
|
+
expect(await readFile(target, 'utf8')).toBe('new');
|
|
87
|
+
expect(await readFile(link, 'utf8')).toBe('new');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('creates a missing file and its parent directory', async () => {
|
|
91
|
+
const root = await makeRoot();
|
|
92
|
+
const file = join(root, 'nested', 'settings.json');
|
|
93
|
+
|
|
94
|
+
await expect(write(file, 'new')).resolves.toBe(file);
|
|
95
|
+
|
|
96
|
+
expect(await readFile(file, 'utf8')).toBe('new');
|
|
97
|
+
expect((await lstat(file)).isFile()).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('removes the temporary file and keeps the previous content when rename fails', async () => {
|
|
101
|
+
const root = await makeRoot();
|
|
102
|
+
const file = join(root, 'settings.json');
|
|
103
|
+
await writeFile(file, 'old');
|
|
104
|
+
const renameFailure = Object.assign(new Error('rename failed'), { code: 'EXDEV' });
|
|
105
|
+
const failingFs = {
|
|
106
|
+
...defaultFs,
|
|
107
|
+
rename: async () => { throw renameFailure; },
|
|
108
|
+
renameSync: () => { throw renameFailure; },
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
await expect(write(file, 'new', { fs: failingFs })).rejects.toBe(renameFailure);
|
|
112
|
+
|
|
113
|
+
expect(await readFile(file, 'utf8')).toBe('old');
|
|
114
|
+
expect(await readdir(root)).toEqual(['settings.json']);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('resolves with the new content in place when the final chmod fails', async () => {
|
|
118
|
+
const root = await makeRoot();
|
|
119
|
+
const file = join(root, 'settings.json');
|
|
120
|
+
await writeFile(file, 'old');
|
|
121
|
+
const chmodFailure = Object.assign(new Error('chmod failed'), { code: 'EPERM' });
|
|
122
|
+
const failingFs = {
|
|
123
|
+
...defaultFs,
|
|
124
|
+
chmod: async () => { throw chmodFailure; },
|
|
125
|
+
chmodSync: () => { throw chmodFailure; },
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
await expect(write(file, 'new', { fs: failingFs })).resolves.toBe(file);
|
|
129
|
+
|
|
130
|
+
expect(await readFile(file, 'utf8')).toBe('new');
|
|
131
|
+
expect(await readdir(root)).toEqual(['settings.json']);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -2,38 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
## Ownership
|
|
4
4
|
|
|
5
|
-
This module owns
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
5
|
+
This module owns local session completion/error notifications. It does not
|
|
6
|
+
model OpenCode questions, permissions, subagents, or tool completion, and it
|
|
7
|
+
sends nothing off the machine: there is no push delivery, no registered
|
|
8
|
+
routes, and no hosted relay.
|
|
9
|
+
|
|
10
|
+
`pi-notification-watcher.js` maintains one server-owned subscription to the Pi
|
|
11
|
+
session daemon. A live `busy` or `retry` lifecycle, or an assistant start,
|
|
12
|
+
opens a turn. The first terminal `idle` emits a completion notification and
|
|
13
|
+
the first `session.error` or terminal `error` emits an error notification.
|
|
14
|
+
Duplicate terminal boundaries do nothing. Bootstrap snapshots seed activity but
|
|
15
|
+
never notify for old settled work. User interruption settles without
|
|
16
|
+
notifying.
|
|
17
|
+
|
|
18
|
+
The watcher reads `/api/pi/ui-settings` storage before delivery.
|
|
19
|
+
Notifications require `nativeNotificationsEnabled`; `notifyOnCompletion` and
|
|
20
|
+
`notifyOnError` gate their respective events.
|
|
21
|
+
|
|
22
|
+
## Local delivery
|
|
23
|
+
|
|
24
|
+
The watcher takes a plain `notify(payload)` callback instead of a delivery
|
|
25
|
+
runtime. `startWebUiServer` only creates and starts the watcher when
|
|
26
|
+
`options.onDesktopNotification` is a function — in practice supplied by
|
|
27
|
+
Electron, which shows the OS notification (`maybeShowNativeNotification`).
|
|
28
|
+
Web and CLI servers pass no callback, so the watcher never runs there.
|
|
29
|
+
|
|
30
|
+
Payloads contain a fixed completion/error title, the session title when known,
|
|
31
|
+
an opaque session ID for navigation, a stable event tag, and the desktop
|
|
32
|
+
hints (`kind`, `sessionId`, `directory`, `requireHidden`) the callback
|
|
33
|
+
received before. They never contain prompts, assistant output, tool
|
|
34
|
+
input/output, provider credentials, or error details. Callback failures and
|
|
35
|
+
timeouts are caught and logged; they never break the watcher.
|
|
36
|
+
|
|
37
|
+
## Retired push surface
|
|
38
|
+
|
|
39
|
+
The push-only routes (`GET /api/push/vapid-public-key`, `POST`/`DELETE
|
|
40
|
+
/api/push/subscribe`, `POST`/`DELETE /api/push/apns-token`, `POST
|
|
41
|
+
/api/push/visibility`) and the push delivery runtime (VAPID keys, browser
|
|
42
|
+
subscriptions, native tokens, relay signing, `PICHAMBER_PUSH_RELAY_URL`,
|
|
43
|
+
`PICHAMBER_PUSH_RELAY_DISABLED`) were removed. Existing
|
|
44
|
+
`<dataDir>/notifications.json` files are simply no longer read; they are left
|
|
45
|
+
in place and no migration runs.
|
|
36
46
|
|
|
37
47
|
## Failure behavior
|
|
38
48
|
|
|
39
|
-
|
|
49
|
+
The watcher reconnects to the daemon with its sequence and stream epoch, so
|
|
50
|
+
replayed terminal events remain deduplicated by the active-turn state.
|
|
@@ -69,32 +69,33 @@ export const createPiNotificationTracker = ({ emit }) => {
|
|
|
69
69
|
export const createPiNotificationWatcher = ({
|
|
70
70
|
supervisor,
|
|
71
71
|
uiSettingsStore,
|
|
72
|
-
|
|
72
|
+
notify,
|
|
73
73
|
retryMs = 1_000,
|
|
74
|
-
|
|
74
|
+
notifyTimeoutMs = 15_000,
|
|
75
75
|
}) => {
|
|
76
76
|
let stopped = false;
|
|
77
77
|
let closeSubscription = null;
|
|
78
78
|
let retryTimer = null;
|
|
79
79
|
let fromSequence;
|
|
80
80
|
let streamEpoch;
|
|
81
|
-
let
|
|
81
|
+
let notifyChain = Promise.resolve();
|
|
82
82
|
|
|
83
83
|
const tracker = createPiNotificationTracker({
|
|
84
84
|
emit: (payload) => {
|
|
85
|
-
|
|
85
|
+
if (typeof notify !== 'function') return;
|
|
86
|
+
notifyChain = notifyChain.then(async () => {
|
|
86
87
|
const settings = await uiSettingsStore.read();
|
|
87
88
|
if (settings.nativeNotificationsEnabled !== true) return;
|
|
88
89
|
if (payload.data.type === 'completion' && settings.notifyOnCompletion === false) return;
|
|
89
90
|
if (payload.data.type === 'error' && settings.notifyOnError === false) return;
|
|
90
91
|
let timeoutId;
|
|
91
92
|
const timeout = new Promise((_, reject) => {
|
|
92
|
-
timeoutId = setTimeout(() => reject(new Error('Notification delivery timed out')),
|
|
93
|
+
timeoutId = setTimeout(() => reject(new Error('Notification delivery timed out')), notifyTimeoutMs);
|
|
93
94
|
timeoutId.unref?.();
|
|
94
95
|
});
|
|
95
96
|
try {
|
|
96
97
|
await Promise.race([
|
|
97
|
-
|
|
98
|
+
notify({
|
|
98
99
|
...payload,
|
|
99
100
|
kind: payload.data.type,
|
|
100
101
|
sessionId: payload.data.sessionId,
|
|
@@ -148,7 +149,7 @@ export const createPiNotificationWatcher = ({
|
|
|
148
149
|
retryTimer = null;
|
|
149
150
|
closeSubscription?.();
|
|
150
151
|
closeSubscription = null;
|
|
151
|
-
await
|
|
152
|
+
await notifyChain;
|
|
152
153
|
},
|
|
153
154
|
};
|
|
154
155
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import { createPiNotificationTracker, createPiNotificationWatcher } from './pi-notification-watcher.js';
|
|
4
4
|
|
|
@@ -69,7 +69,7 @@ describe('Pi notification tracker', () => {
|
|
|
69
69
|
const watcher = createPiNotificationWatcher({
|
|
70
70
|
supervisor,
|
|
71
71
|
uiSettingsStore: { read: async () => ({}) },
|
|
72
|
-
|
|
72
|
+
notify: async () => undefined,
|
|
73
73
|
retryMs: 1,
|
|
74
74
|
});
|
|
75
75
|
|
|
@@ -81,4 +81,90 @@ describe('Pi notification tracker', () => {
|
|
|
81
81
|
expect(closes).toEqual([1]);
|
|
82
82
|
await watcher.stop();
|
|
83
83
|
});
|
|
84
|
+
|
|
85
|
+
it('delivers terminal completions to the desktop callback with the desktop payload', async () => {
|
|
86
|
+
const seen = [];
|
|
87
|
+
let onEvent;
|
|
88
|
+
const supervisor = {
|
|
89
|
+
subscribe: async (options) => {
|
|
90
|
+
onEvent = options.onEvent;
|
|
91
|
+
return () => {};
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
const watcher = createPiNotificationWatcher({
|
|
95
|
+
supervisor,
|
|
96
|
+
uiSettingsStore: { read: async () => ({ nativeNotificationsEnabled: true }) },
|
|
97
|
+
notify: async (payload) => { seen.push(payload); },
|
|
98
|
+
retryMs: 1,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await watcher.start();
|
|
102
|
+
onEvent(event('session.lifecycle', 1, { state: 'busy' }));
|
|
103
|
+
onEvent(event('session.lifecycle', 2, { state: 'idle' }));
|
|
104
|
+
await watcher.stop();
|
|
105
|
+
|
|
106
|
+
expect(seen).toHaveLength(1);
|
|
107
|
+
expect(seen[0]).toMatchObject({
|
|
108
|
+
title: 'Work completed',
|
|
109
|
+
kind: 'completion',
|
|
110
|
+
sessionId: 'session-1',
|
|
111
|
+
requireHidden: true,
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('gates desktop delivery on the notification settings', async () => {
|
|
116
|
+
for (const settings of [
|
|
117
|
+
{ nativeNotificationsEnabled: false },
|
|
118
|
+
{ nativeNotificationsEnabled: true, notifyOnCompletion: false },
|
|
119
|
+
]) {
|
|
120
|
+
const seen = [];
|
|
121
|
+
let onEvent;
|
|
122
|
+
const supervisor = {
|
|
123
|
+
subscribe: async (options) => {
|
|
124
|
+
onEvent = options.onEvent;
|
|
125
|
+
return () => {};
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
const watcher = createPiNotificationWatcher({
|
|
129
|
+
supervisor,
|
|
130
|
+
uiSettingsStore: { read: async () => settings },
|
|
131
|
+
notify: async (payload) => { seen.push(payload); },
|
|
132
|
+
retryMs: 1,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
await watcher.start();
|
|
136
|
+
onEvent(event('session.lifecycle', 1, { state: 'busy' }));
|
|
137
|
+
onEvent(event('session.lifecycle', 2, { state: 'idle' }));
|
|
138
|
+
await watcher.stop();
|
|
139
|
+
|
|
140
|
+
expect(seen).toEqual([]);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('catches desktop callback failures instead of breaking the watcher', async () => {
|
|
145
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
146
|
+
let onEvent;
|
|
147
|
+
const supervisor = {
|
|
148
|
+
subscribe: async (options) => {
|
|
149
|
+
onEvent = options.onEvent;
|
|
150
|
+
return () => {};
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
const watcher = createPiNotificationWatcher({
|
|
154
|
+
supervisor,
|
|
155
|
+
uiSettingsStore: { read: async () => ({ nativeNotificationsEnabled: true }) },
|
|
156
|
+
notify: async () => { throw new Error('native bridge exploded'); },
|
|
157
|
+
retryMs: 1,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
await watcher.start();
|
|
162
|
+
onEvent(event('session.lifecycle', 1, { state: 'busy' }));
|
|
163
|
+
onEvent(event('session.lifecycle', 2, { state: 'idle' }));
|
|
164
|
+
await watcher.stop();
|
|
165
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('[Notifications] delivery failed'));
|
|
166
|
+
} finally {
|
|
167
|
+
warn.mockRestore();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
84
170
|
});
|
|
@@ -4,6 +4,7 @@ import express from 'express';
|
|
|
4
4
|
import {
|
|
5
5
|
projectEventFrame,
|
|
6
6
|
projectExtensionList,
|
|
7
|
+
projectMessageRender,
|
|
7
8
|
projectToolRender,
|
|
8
9
|
registerPiRuntimeRoutes,
|
|
9
10
|
} from './routes.js';
|
|
@@ -200,8 +201,104 @@ describe('extension public projections', () => {
|
|
|
200
201
|
}));
|
|
201
202
|
expect(projectedUntracked?.payload.snapshot.extensionDraftTracked).toBeUndefined();
|
|
202
203
|
});
|
|
204
|
+
|
|
205
|
+
it('projects session.input frames and drops malformed pending summaries', () => {
|
|
206
|
+
expect(projectEventFrame(frame('session.input', { pending: { count: 2, kind: 'approval', since: 50 } })))
|
|
207
|
+
.toMatchObject({
|
|
208
|
+
name: 'session.input',
|
|
209
|
+
sessionId: 'sess-1',
|
|
210
|
+
directory: '/work',
|
|
211
|
+
payload: { pending: { count: 2, kind: 'approval', since: 50 } },
|
|
212
|
+
});
|
|
213
|
+
expect(projectEventFrame(frame('session.input', { pending: null }))?.payload).toEqual({ pending: null });
|
|
214
|
+
// Unknown kinds normalize; extra keys never cross the boundary.
|
|
215
|
+
expect(projectEventFrame(frame('session.input', {
|
|
216
|
+
pending: { count: 150, kind: 'question', since: 7, sessionId: 'sneaky' },
|
|
217
|
+
}))?.payload).toEqual({ pending: { count: 99, kind: 'input', since: 7 } });
|
|
218
|
+
expect(projectEventFrame(frame('session.input', { pending: { count: 'many' } }))).toBeNull();
|
|
219
|
+
expect(projectEventFrame(frame('session.input', {}))).toBeNull();
|
|
220
|
+
expect(projectEventFrame(frame('session.input', { pending: { count: 1, kind: 'input' } }))).toBeNull();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('projects session.input serverNow when finite and omits it otherwise', () => {
|
|
224
|
+
expect(projectEventFrame(frame('session.input', {
|
|
225
|
+
pending: { count: 1, kind: 'input', since: 9 },
|
|
226
|
+
serverNow: 12345,
|
|
227
|
+
}))?.payload).toEqual({ pending: { count: 1, kind: 'input', since: 9 }, serverNow: 12345 });
|
|
228
|
+
// Old payloads without serverNow project as before.
|
|
229
|
+
expect(projectEventFrame(frame('session.input', {
|
|
230
|
+
pending: { count: 1, kind: 'input', since: 9 },
|
|
231
|
+
}))?.payload).toEqual({ pending: { count: 1, kind: 'input', since: 9 } });
|
|
232
|
+
for (const serverNow of [undefined, Number.NaN, Number.POSITIVE_INFINITY, '123', null]) {
|
|
233
|
+
expect(projectEventFrame(frame('session.input', {
|
|
234
|
+
pending: { count: 1, kind: 'input', since: 9 },
|
|
235
|
+
serverNow,
|
|
236
|
+
}))?.payload).toEqual({ pending: { count: 1, kind: 'input', since: 9 } });
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('projects snapshot inputState and omits malformed values', () => {
|
|
241
|
+
const projected = projectEventFrame(frame('session.snapshot', {
|
|
242
|
+
isStreaming: false,
|
|
243
|
+
lifecycle: 'idle',
|
|
244
|
+
queue: { steering: 0, followUp: 0 },
|
|
245
|
+
lastSequence: 5,
|
|
246
|
+
inputState: { pending: { count: 1, kind: 'input', since: 9 } },
|
|
247
|
+
}));
|
|
248
|
+
expect(projected?.payload.snapshot.inputState).toEqual({ pending: { count: 1, kind: 'input', since: 9 } });
|
|
249
|
+
|
|
250
|
+
const cleared = projectEventFrame(frame('session.snapshot', {
|
|
251
|
+
isStreaming: false,
|
|
252
|
+
lifecycle: 'idle',
|
|
253
|
+
queue: { steering: 0, followUp: 0 },
|
|
254
|
+
lastSequence: 5,
|
|
255
|
+
inputState: { pending: null },
|
|
256
|
+
}));
|
|
257
|
+
expect(cleared?.payload.snapshot.inputState).toEqual({ pending: null });
|
|
258
|
+
|
|
259
|
+
const malformed = projectEventFrame(frame('session.snapshot', {
|
|
260
|
+
isStreaming: false,
|
|
261
|
+
lifecycle: 'idle',
|
|
262
|
+
queue: { steering: 0, followUp: 0 },
|
|
263
|
+
lastSequence: 5,
|
|
264
|
+
inputState: { pending: { count: 1 } },
|
|
265
|
+
}));
|
|
266
|
+
expect(malformed?.payload.snapshot.inputState).toBeUndefined();
|
|
267
|
+
|
|
268
|
+
const unknown = projectEventFrame(frame('session.snapshot', {
|
|
269
|
+
isStreaming: false,
|
|
270
|
+
lifecycle: 'idle',
|
|
271
|
+
queue: { steering: 0, followUp: 0 },
|
|
272
|
+
lastSequence: 5,
|
|
273
|
+
}));
|
|
274
|
+
expect(unknown?.payload.snapshot.inputState).toBeUndefined();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('projects live-only extension.notify frames', () => {
|
|
278
|
+
expect(projectEventFrame(frame('extension.notify', {
|
|
279
|
+
message: 'Indexed 12 files',
|
|
280
|
+
level: 'warning',
|
|
281
|
+
}))?.payload).toEqual({
|
|
282
|
+
message: 'Indexed 12 files',
|
|
283
|
+
level: 'warning',
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// Unknown levels still default to info; overlong messages stay capped.
|
|
287
|
+
expect(projectEventFrame(frame('extension.notify', {
|
|
288
|
+
message: 'x'.repeat(2500),
|
|
289
|
+
level: 'urgent',
|
|
290
|
+
}))?.payload).toEqual({
|
|
291
|
+
message: 'x'.repeat(2000),
|
|
292
|
+
level: 'info',
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
// Empty messages never project, as before.
|
|
296
|
+
expect(projectEventFrame(frame('extension.notify', { message: '' }))).toBeNull();
|
|
297
|
+
});
|
|
298
|
+
|
|
203
299
|
});
|
|
204
300
|
|
|
301
|
+
|
|
205
302
|
describe('POST /api/pi/sessions/:sessionId/editor-draft', () => {
|
|
206
303
|
let server;
|
|
207
304
|
|
|
@@ -414,3 +511,137 @@ describe('projectToolRender and tool render route passthrough', () => {
|
|
|
414
511
|
});
|
|
415
512
|
});
|
|
416
513
|
|
|
514
|
+
describe('projectMessageRender and message render route passthrough', () => {
|
|
515
|
+
it('sanitizes message render shapes and bounds lines', () => {
|
|
516
|
+
expect(projectMessageRender(null)).toBeUndefined();
|
|
517
|
+
expect(projectMessageRender('not-an-object')).toBeUndefined();
|
|
518
|
+
expect(projectMessageRender([])).toBeUndefined();
|
|
519
|
+
expect(projectMessageRender({})).toBeUndefined();
|
|
520
|
+
expect(projectMessageRender({ message: [] })).toBeUndefined();
|
|
521
|
+
// An expanded slot without a collapsed slot is dropped.
|
|
522
|
+
expect(projectMessageRender({ messageExpanded: ['only expanded'] })).toBeUndefined();
|
|
523
|
+
expect(projectMessageRender({ message: 'not-an-array', messageExpanded: ['expanded'] })).toBeUndefined();
|
|
524
|
+
|
|
525
|
+
expect(projectMessageRender({ message: ['collapsed'] })).toEqual({ message: ['collapsed'] });
|
|
526
|
+
expect(projectMessageRender({ message: ['collapsed'], messageExpanded: ['expanded'] })).toEqual({
|
|
527
|
+
message: ['collapsed'],
|
|
528
|
+
messageExpanded: ['expanded'],
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
const longLine = 'a'.repeat(2500);
|
|
532
|
+
const manyLines = Array.from({ length: 250 }, (_, i) => `line-${i}`);
|
|
533
|
+
const sanitized = projectMessageRender({ message: [longLine, 123, null, 'valid'], messageExpanded: manyLines });
|
|
534
|
+
expect(sanitized.message).toHaveLength(2);
|
|
535
|
+
expect(sanitized.message[0]).toHaveLength(2000);
|
|
536
|
+
expect(sanitized.message[1]).toBe('valid');
|
|
537
|
+
expect(sanitized.messageExpanded).toHaveLength(200);
|
|
538
|
+
// Tool render keys never leak into message renders.
|
|
539
|
+
expect(projectMessageRender({ message: ['ok'], call: ['tool'] })).toEqual({ message: ['ok'] });
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it('leaves projectToolRender behavior unchanged', () => {
|
|
543
|
+
expect(projectToolRender({ call: ['c'], result: ['r'], resultExpanded: ['e'] })).toEqual({
|
|
544
|
+
call: ['c'],
|
|
545
|
+
result: ['r'],
|
|
546
|
+
resultExpanded: ['e'],
|
|
547
|
+
});
|
|
548
|
+
// Message render keys never leak into tool renders.
|
|
549
|
+
expect(projectToolRender({ call: ['c'], message: ['m'] })).toEqual({ call: ['c'] });
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it('projects extension.message frames with sanitized render and drops malformed shapes', () => {
|
|
553
|
+
const rendered = projectEventFrame(frame('extension.message', {
|
|
554
|
+
id: 'm1',
|
|
555
|
+
customType: 'my-extension',
|
|
556
|
+
text: 'hi',
|
|
557
|
+
createdAt: 1000,
|
|
558
|
+
render: { message: ['collapsed'], messageExpanded: ['expanded'] },
|
|
559
|
+
}));
|
|
560
|
+
expect(rendered?.payload.render).toEqual({ message: ['collapsed'], messageExpanded: ['expanded'] });
|
|
561
|
+
|
|
562
|
+
const manyLines = Array.from({ length: 250 }, (_, i) => `line-${i}`);
|
|
563
|
+
const capped = projectEventFrame(frame('extension.message', {
|
|
564
|
+
id: 'm1',
|
|
565
|
+
customType: 'my-extension',
|
|
566
|
+
text: 'hi',
|
|
567
|
+
createdAt: 1000,
|
|
568
|
+
render: { message: manyLines },
|
|
569
|
+
}));
|
|
570
|
+
expect(capped?.payload.render.message).toHaveLength(200);
|
|
571
|
+
|
|
572
|
+
// Invalid render shapes are dropped, not protocol errors.
|
|
573
|
+
for (const render of [{ message: 'not-an-array' }, { messageExpanded: ['orphan'] }, 'nope', 42]) {
|
|
574
|
+
const dropped = projectEventFrame(frame('extension.message', {
|
|
575
|
+
id: 'm1',
|
|
576
|
+
customType: 'my-extension',
|
|
577
|
+
text: 'hi',
|
|
578
|
+
createdAt: 1000,
|
|
579
|
+
render,
|
|
580
|
+
}));
|
|
581
|
+
expect(dropped).not.toBeNull();
|
|
582
|
+
expect('render' in dropped.payload).toBe(false);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
const plain = projectEventFrame(frame('extension.message', {
|
|
586
|
+
id: 'm1',
|
|
587
|
+
customType: 'my-extension',
|
|
588
|
+
text: 'hi',
|
|
589
|
+
createdAt: 1000,
|
|
590
|
+
}));
|
|
591
|
+
expect(plain).not.toBeNull();
|
|
592
|
+
expect('render' in plain.payload).toBe(false);
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it('passes sanitized render on session detail extension messages and drops malformed shapes', async () => {
|
|
596
|
+
const runtime = {
|
|
597
|
+
request: async (command) => {
|
|
598
|
+
if (command === 'sessions.open') {
|
|
599
|
+
return {
|
|
600
|
+
session: { id: 'sess-ext', directory: '/work', createdAt: 1000, updatedAt: 1000 },
|
|
601
|
+
messages: [
|
|
602
|
+
{
|
|
603
|
+
message: {
|
|
604
|
+
id: 'm1', sessionId: 'sess-ext', directory: '/work', role: 'extension',
|
|
605
|
+
customType: 'my-extension', text: 'hi', createdAt: 1000,
|
|
606
|
+
render: { message: ['collapsed'], messageExpanded: ['expanded'] },
|
|
607
|
+
},
|
|
608
|
+
parts: [],
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
message: {
|
|
612
|
+
id: 'm2', sessionId: 'sess-ext', directory: '/work', role: 'extension',
|
|
613
|
+
customType: 'my-extension', text: 'hi', createdAt: 1000,
|
|
614
|
+
render: { messageExpanded: ['orphan'] },
|
|
615
|
+
},
|
|
616
|
+
parts: [],
|
|
617
|
+
},
|
|
618
|
+
],
|
|
619
|
+
lastSequence: 1,
|
|
620
|
+
isStreaming: false,
|
|
621
|
+
lifecycle: 'idle',
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
throw new Error(`Unexpected command ${command}`);
|
|
625
|
+
},
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
const app = express();
|
|
629
|
+
app.use(express.json());
|
|
630
|
+
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime });
|
|
631
|
+
const server = await new Promise((resolve, reject) => {
|
|
632
|
+
const s = app.listen(0, '127.0.0.1', () => resolve(s));
|
|
633
|
+
s.once('error', reject);
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
try {
|
|
637
|
+
const res = await fetch(`http://127.0.0.1:${server.address().port}/api/pi/sessions/sess-ext?directory=%2Fwork`);
|
|
638
|
+
expect(res.status).toBe(200);
|
|
639
|
+
const data = await res.json();
|
|
640
|
+
expect(data.messages[0].message.render).toEqual({ message: ['collapsed'], messageExpanded: ['expanded'] });
|
|
641
|
+
expect('render' in data.messages[1].message).toBe(false);
|
|
642
|
+
} finally {
|
|
643
|
+
await new Promise((resolve) => server.close(resolve));
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
|