@pi-chamber/web 1.0.8-rc.2 → 1.0.8-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentsSurface-CcWBqAWV.js → AgentsSurface-wsW9VCRp.js} +1 -1
- package/dist/assets/{ChoicesArtifact-Kk-qvrSB.js → ChoicesArtifact-EwCf4Yxu.js} +1 -1
- package/dist/assets/{DiagramView-DZUBo1uP.js → DiagramView-BX6N99cQ.js} +1 -1
- package/dist/assets/{DiffView-CiZy4jFA.js → DiffView-CI0eSnPP.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-DZ9NDwOO.js → FileSaveConflictDialog-GLj2W7VE.js} +1 -1
- package/dist/assets/{FilesView-DqiZ9kw9.js → FilesView-CI0tfZQL.js} +1 -1
- package/dist/assets/{GitHubDetailScaffold-DM2DH7o8.js → GitHubDetailScaffold-B85tZ9m7.js} +1 -1
- package/dist/assets/{GitHubLinkPicker-ChB8NZ1h.js → GitHubLinkPicker-Y6AuNiGl.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-CibDiJGq.js → GitHubListPrimitives-BJHBud6i.js} +1 -1
- package/dist/assets/{GitView--EaZQrBr.js → GitView-DueE69kW.js} +3 -3
- package/dist/assets/{IssuesSurface-CySTpaD1.js → IssuesSurface-Cg-xkdIu.js} +2 -2
- package/dist/assets/{JsonTreeView-_yMHKKQZ.js → JsonTreeView-Cvg6lc40.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-D_-2fQw0.js → MarkdownRendererImpl-DExPx-QM.js} +1 -1
- package/dist/assets/{PatchDiff-bHObDlhD.js → PatchDiff-_c3HZ34I.js} +1 -1
- package/dist/assets/{PierreDiffViewer-UY7Cse-s.js → PierreDiffViewer-CZnaqO-_.js} +1 -1
- package/dist/assets/{PullRequestsSurface-iXy6chwc.js → PullRequestsSurface-C9AYPiwo.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-DJGCa_wN.js → SessionSwitcherContent-DOpnN-8S.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-CDOX-5Y2.js → SessionSwitcherDropdown-CmHMPZ69.js} +2 -2
- package/dist/assets/{SessionUnreadDot-Dwc3MdvA.js → SessionUnreadDot-CZCQ4t1J.js} +1 -1
- package/dist/assets/SettingsView-D5PO5M3z.js +11 -0
- package/dist/assets/{SettingsWindow-CUg49Mfh.js → SettingsWindow-DXV5UOE8.js} +1 -1
- package/dist/assets/{SubagentsArtifact-DUZX9tDe.js → SubagentsArtifact-CO1ZiI1x.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BuZZaRw4.js → ToolOutputDialog-GOwNLj-y.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-CKncG6i2.js → ToolPartDiffPreview-BoaiZji6.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-BGZiLPe_.js → VirtualizedFileDiff-Chq1X8nw.js} +1 -1
- package/dist/assets/VisualFrame-u7aRcX7O.js +22 -0
- package/dist/assets/{VisualsArtifact-Bq0vMO-i.js → VisualsArtifact-D9vPjihW.js} +1 -1
- package/dist/assets/{collapsible-Bro9KrfM.js → collapsible-BjpDEohv.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DJQqK49u.js → computeVirtualFileMetrics-DmPCxbok.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-ByWK3Sru.js → contextFileOpenGuard-CukNcUeY.js} +1 -1
- package/dist/assets/{fileTreeStatus-CyJ3TOYD.js → fileTreeStatus-CDyfNPYO.js} +1 -1
- package/dist/assets/{gitStatusPredicates-BsXrwngT.js → gitStatusPredicates-uI7Y7L5k.js} +1 -1
- package/dist/assets/{githubLink-g2bmC0qi.js → githubLink-B9Mxac4R.js} +1 -1
- package/dist/assets/{index-C9rUUQ_Y.js → index-BWq2ibCw.js} +1 -1
- package/dist/assets/{index-CKKWVoND.js → index-BxKPJ9uG.js} +9 -9
- package/dist/assets/index-C5JgjS20.css +1 -0
- package/dist/assets/{main-DsLMU9CT.js → main-CWfC-9xT.js} +4 -4
- package/dist/assets/{main-DT-4_fhe.js → main-ckQ0ciIN.js} +2 -2
- package/dist/assets/{markdownCore-QmM_aOnZ.js → markdownCore-p2q2Kxwo.js} +1 -1
- package/dist/assets/{miniChat-BqGslD2z.js → miniChat-x2TrwRYA.js} +2 -2
- package/dist/assets/{mobile-C5JOcDIC.js → mobile-B0x2G8h1.js} +2 -2
- package/dist/assets/{nativeFileSave-DSMsJqXM.js → nativeFileSave-D542OJlG.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-Cc_S4zi1.js → pi-session-focus-preference-Q_RZUCnt.js} +1 -1
- package/dist/assets/{renderDiffWithHighlighter-BXhnIAHg.js → renderDiffWithHighlighter-CSFGSknx.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-CiSkecEE.js → renderElectronMiniChatApp-CFIdesZT.js} +2 -2
- package/dist/assets/{renderFileWithHighlighter-CK29YZtC.js → renderFileWithHighlighter-C5JE0mRX.js} +1 -1
- package/dist/assets/{renderMobileApp-C4JuoxsZ.js → renderMobileApp-B1ybjcGM.js} +3 -3
- package/dist/assets/{runtimeEndpointReset-Dwj-jCDS.js → runtimeEndpointReset-DyZSKCYM.js} +7 -7
- package/dist/assets/{runtimeSurface-0K7vuUpd.js → runtimeSurface-BR_dhe7_.js} +1 -1
- package/dist/assets/{selection-CnYkEsu_.js → selection-CfOpW4rA.js} +1 -1
- package/dist/assets/{useAppFontEffects-CV5UyTRw.js → useAppFontEffects-COMvkffC.js} +97 -97
- package/dist/assets/{useGitHubRemoteSearch-CgP-zEBj.js → useGitHubRemoteSearch-M1AE2YuX.js} +1 -1
- package/dist/assets/{useSwitcherItems-C8G5F0hs.js → useSwitcherItems-D0i2BYYP.js} +1 -1
- package/dist/assets/{web-components-BpncHjnV.js → web-components-wOQkOurQ.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/plugins/visuals/extension.js +2 -2
- package/server/index.js +4 -0
- package/server/lib/pi/ui-settings-store.js +2 -1
- package/server/lib/wallpaper/DOCUMENTATION.md +25 -0
- package/server/lib/wallpaper/routes.js +63 -0
- package/server/lib/wallpaper/routes.test.js +109 -0
- package/server/lib/wallpaper/store.js +87 -0
- package/dist/assets/SettingsView-DA-U9lsj.js +0 -11
- package/dist/assets/VisualFrame-DBZkHFnG.js +0 -22
- package/dist/assets/index-B_L9GVYw.css +0 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { registerWallpaperRoutes } from './routes.js';
|
|
9
|
+
import { MAX_WALLPAPER_IMAGE_BYTES, createWallpaperImageStore, sniffImageType } from './store.js';
|
|
10
|
+
|
|
11
|
+
const PNG = Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), Buffer.from('rest of a png')]);
|
|
12
|
+
const JPEG = Buffer.concat([Buffer.from([0xff, 0xd8, 0xff, 0xe0]), Buffer.from('jpeg body')]);
|
|
13
|
+
const WEBP = Buffer.concat([Buffer.from('RIFF'), Buffer.from([0, 0, 0, 0]), Buffer.from('WEBPVP8 ')]);
|
|
14
|
+
|
|
15
|
+
const listen = (app) => new Promise((resolve, reject) => {
|
|
16
|
+
const server = app.listen(0, '127.0.0.1', () => resolve(server));
|
|
17
|
+
server.once('error', reject);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('wallpaper image', () => {
|
|
21
|
+
let server;
|
|
22
|
+
let dataDir;
|
|
23
|
+
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
await new Promise((resolve) => (server ? server.close(resolve) : resolve()));
|
|
26
|
+
server = undefined;
|
|
27
|
+
if (dataDir) await rm(dataDir, { recursive: true, force: true });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const setup = async () => {
|
|
31
|
+
dataDir = await mkdtemp(join(tmpdir(), 'pc-wallpaper-'));
|
|
32
|
+
const app = express();
|
|
33
|
+
// The server parses JSON bodies for every route; an image must pass through.
|
|
34
|
+
app.use(express.json());
|
|
35
|
+
const store = createWallpaperImageStore({ dataDir });
|
|
36
|
+
registerWallpaperRoutes(app, { express, store });
|
|
37
|
+
server = await listen(app);
|
|
38
|
+
const base = `http://127.0.0.1:${server.address().port}/api/wallpaper-image`;
|
|
39
|
+
return { base, store };
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
it('knows PNG, JPEG and WebP by their bytes only', () => {
|
|
43
|
+
expect(sniffImageType(PNG)).toBe('image/png');
|
|
44
|
+
expect(sniffImageType(JPEG)).toBe('image/jpeg');
|
|
45
|
+
expect(sniffImageType(WEBP)).toBe('image/webp');
|
|
46
|
+
expect(sniffImageType(Buffer.from('<svg xmlns="http://www.w3.org/2000/svg"/>'))).toBeNull();
|
|
47
|
+
expect(sniffImageType(Buffer.from('GIF89a'))).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('has no picture until one is saved, then serves it with its version', async () => {
|
|
51
|
+
const { base } = await setup();
|
|
52
|
+
expect((await fetch(base)).status).toBe(404);
|
|
53
|
+
|
|
54
|
+
const put = await fetch(base, { method: 'PUT', headers: { 'content-type': 'image/webp' }, body: WEBP });
|
|
55
|
+
expect(put.status).toBe(200);
|
|
56
|
+
const saved = await put.json();
|
|
57
|
+
expect(saved.type).toBe('image/webp');
|
|
58
|
+
expect(saved.version).toMatch(/^[0-9a-f]{16}$/);
|
|
59
|
+
|
|
60
|
+
const get = await fetch(base);
|
|
61
|
+
expect(get.status).toBe(200);
|
|
62
|
+
expect(get.headers.get('content-type')).toBe('image/webp');
|
|
63
|
+
expect(get.headers.get('x-wallpaper-version')).toBe(saved.version);
|
|
64
|
+
expect(get.headers.get('x-content-type-options')).toBe('nosniff');
|
|
65
|
+
expect(Buffer.from(await get.arrayBuffer()).equals(WEBP)).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('types the picture by its bytes, not the request header', async () => {
|
|
69
|
+
const { base } = await setup();
|
|
70
|
+
const put = await fetch(base, { method: 'PUT', headers: { 'content-type': 'text/html' }, body: PNG });
|
|
71
|
+
expect((await put.json()).type).toBe('image/png');
|
|
72
|
+
expect((await fetch(base)).headers.get('content-type')).toBe('image/png');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('refuses other files and keeps the picture it had', async () => {
|
|
76
|
+
const { base } = await setup();
|
|
77
|
+
await fetch(base, { method: 'PUT', body: JPEG });
|
|
78
|
+
const svg = await fetch(base, { method: 'PUT', headers: { 'content-type': 'image/svg+xml' }, body: '<svg onload="alert(1)"/>' });
|
|
79
|
+
expect(svg.status).toBe(415);
|
|
80
|
+
const empty = await fetch(base, { method: 'PUT', headers: { 'content-type': 'image/png' }, body: '' });
|
|
81
|
+
expect(empty.status).toBe(415);
|
|
82
|
+
expect((await fetch(base)).headers.get('content-type')).toBe('image/jpeg');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('refuses pictures over the size limit', async () => {
|
|
86
|
+
const { base } = await setup();
|
|
87
|
+
const big = Buffer.concat([PNG, Buffer.alloc(MAX_WALLPAPER_IMAGE_BYTES)]);
|
|
88
|
+
const put = await fetch(base, { method: 'PUT', headers: { 'content-type': 'image/png' }, body: big });
|
|
89
|
+
expect(put.status).toBe(413);
|
|
90
|
+
expect((await fetch(base)).status).toBe(404);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('removes the picture', async () => {
|
|
94
|
+
const { base } = await setup();
|
|
95
|
+
await fetch(base, { method: 'PUT', body: PNG });
|
|
96
|
+
expect((await fetch(base, { method: 'DELETE' })).status).toBe(204);
|
|
97
|
+
expect((await fetch(base)).status).toBe(404);
|
|
98
|
+
expect((await fetch(base, { method: 'DELETE' })).status).toBe(204);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('reads a damaged or mismatched record as no picture', async () => {
|
|
102
|
+
const { base, store } = await setup();
|
|
103
|
+
await store.write(PNG);
|
|
104
|
+
await writeFile(join(dataDir, 'wallpaper', 'image'), JPEG);
|
|
105
|
+
expect((await fetch(base)).status).toBe(404);
|
|
106
|
+
await writeFile(join(dataDir, 'wallpaper', 'image.json'), '{not json');
|
|
107
|
+
expect(await store.read()).toBeNull();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, rm } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { writeFileAtomic } from '../fs/atomic-write.js';
|
|
6
|
+
|
|
7
|
+
/** The UI scales pictures down before sending, so this only stops abuse. */
|
|
8
|
+
export const MAX_WALLPAPER_IMAGE_BYTES = 8 * 1024 * 1024;
|
|
9
|
+
|
|
10
|
+
const IMAGE_FILE = 'image';
|
|
11
|
+
const META_FILE = 'image.json';
|
|
12
|
+
|
|
13
|
+
const wallpaperError = (code, message) => Object.assign(new Error(message), { code });
|
|
14
|
+
|
|
15
|
+
/** Image type from the file's first bytes; the client's Content-Type is not trusted. */
|
|
16
|
+
export const sniffImageType = (buffer) => {
|
|
17
|
+
if (buffer.length >= 8 && buffer.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))) return 'image/png';
|
|
18
|
+
if (buffer.length >= 3 && buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff) return 'image/jpeg';
|
|
19
|
+
if (buffer.length >= 12 && buffer.toString('ascii', 0, 4) === 'RIFF' && buffer.toString('ascii', 8, 12) === 'WEBP') return 'image/webp';
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const isMeta = (value) => value !== null
|
|
24
|
+
&& typeof value === 'object'
|
|
25
|
+
&& typeof value.version === 'string'
|
|
26
|
+
&& /^[0-9a-f]{16}$/.test(value.version)
|
|
27
|
+
&& ['image/png', 'image/jpeg', 'image/webp'].includes(value.type);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The server's one wallpaper picture, in `<dataDir>/wallpaper/`. Every
|
|
31
|
+
* client of the server shows the same one. `version` is a hash of the bytes,
|
|
32
|
+
* so clients can tell a new picture from a cached one.
|
|
33
|
+
*/
|
|
34
|
+
export const createWallpaperImageStore = ({ dataDir }) => {
|
|
35
|
+
const dir = join(dataDir, 'wallpaper');
|
|
36
|
+
const imagePath = join(dir, IMAGE_FILE);
|
|
37
|
+
const metaPath = join(dir, META_FILE);
|
|
38
|
+
|
|
39
|
+
const readMeta = async () => {
|
|
40
|
+
try {
|
|
41
|
+
const meta = JSON.parse(await readFile(metaPath, 'utf8'));
|
|
42
|
+
return isMeta(meta) ? { version: meta.version, type: meta.type } : null;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (error?.code === 'ENOENT') return null;
|
|
45
|
+
// A torn or hand-edited file reads as no picture rather than failing every request.
|
|
46
|
+
if (error instanceof SyntaxError) return null;
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
/** `{ version, type, buffer }`, or null when there is no picture. */
|
|
53
|
+
async read() {
|
|
54
|
+
const meta = await readMeta();
|
|
55
|
+
if (!meta) return null;
|
|
56
|
+
try {
|
|
57
|
+
const buffer = await readFile(imagePath);
|
|
58
|
+
// The picture was replaced between the two reads; the newer write wins next time.
|
|
59
|
+
if (createHash('sha256').update(buffer).digest('hex').slice(0, 16) !== meta.version) return null;
|
|
60
|
+
return { ...meta, buffer };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error?.code === 'ENOENT') return null;
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
/** Saves `buffer` as the picture and returns its `{ version, type }`. */
|
|
68
|
+
async write(buffer) {
|
|
69
|
+
if (!Buffer.isBuffer(buffer) || buffer.length === 0) throw wallpaperError('WALLPAPER_IMAGE_UNSUPPORTED', 'Empty image');
|
|
70
|
+
if (buffer.length > MAX_WALLPAPER_IMAGE_BYTES) throw wallpaperError('WALLPAPER_IMAGE_TOO_LARGE', 'Image is too large');
|
|
71
|
+
const type = sniffImageType(buffer);
|
|
72
|
+
if (!type) throw wallpaperError('WALLPAPER_IMAGE_UNSUPPORTED', 'Only PNG, JPEG and WebP images are accepted');
|
|
73
|
+
const version = createHash('sha256').update(buffer).digest('hex').slice(0, 16);
|
|
74
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
75
|
+
// Picture first, then the record naming it: a crash between the two
|
|
76
|
+
// leaves the old record, which no longer matches and reads as none.
|
|
77
|
+
await writeFileAtomic(imagePath, buffer);
|
|
78
|
+
await writeFileAtomic(metaPath, `${JSON.stringify({ version, type })}\n`);
|
|
79
|
+
return { version, type };
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
async remove() {
|
|
83
|
+
await rm(metaPath, { force: true });
|
|
84
|
+
await rm(imagePath, { force: true });
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
};
|