@pi-chamber/web 0.3.3 → 0.5.0
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 -0
- package/bin/lib/cli-startup.js +1 -0
- package/dist/assets/CommitSection-Cz-ACBaD.js +1 -0
- package/dist/assets/DiagramEditor-BNUOrd9m.js +1 -0
- package/dist/assets/DiagramView-D4YR9YRt.js +1 -0
- package/dist/assets/{DiffView-DGD9DMS7.js → DiffView-DPW8dcg_.js} +3 -3
- package/dist/assets/FilesView-BFGIdY6b.js +14 -0
- package/dist/assets/GitView-CKtiKOfJ.js +6 -0
- package/dist/assets/JsonTreeView-c-UJUw3D.js +1 -0
- package/dist/assets/{MarkdownRendererImpl-V1HMFCjr.js → MarkdownRendererImpl-CvC9eXoa.js} +2 -2
- package/dist/assets/PatchDiff-YGHsZUIR.js +1 -0
- package/dist/assets/PierreDiffViewer-CoXa-JJK.js +136 -0
- package/dist/assets/SessionSwitcherContent-B7eep3dO.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-CZOFeJHH.js +2 -0
- package/dist/assets/SessionUnreadDot-ClpeYFPz.js +1 -0
- package/dist/assets/SettingsView-CPmHHDbQ.js +4 -0
- package/dist/assets/SettingsWindow-2CBpoJ8H.js +1 -0
- package/dist/assets/{ToolOutputDialog-2zKUdGYL.js → ToolOutputDialog-HMW-Kh19.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-C3nbNbxk.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-UMgLcO4Q.js → VirtualizedFileDiff-DEX83nQ0.js} +3 -3
- package/dist/assets/{SessionSwitcherDropdown-o1RjhCfF.js → WindowsWindowControls-PPk5H89-.js} +172 -118
- package/dist/assets/collapsible-Dux-9hAC.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-Cy0nxMJB.js +3 -0
- package/dist/assets/contextFileOpenGuard-Dn_38hd9.js +1 -0
- package/dist/assets/index--zDkVFU6.css +1 -0
- package/dist/assets/index-DU2OBBy5.js +8 -0
- package/dist/assets/index-EN7MioVf.js +1 -0
- package/dist/assets/isDiffPlainText-DSWRVq-W.js +1 -0
- package/dist/assets/isFilePlainText-7RAjjrQ5.js +1 -0
- package/dist/assets/{main-CmkRaMOR.js → main-BGKjg-qW.js} +8 -8
- package/dist/assets/main-DGHrBx_u.js +2 -0
- package/dist/assets/markdownCore-BYPqQtbE.js +3 -0
- package/dist/assets/miniChat-DW2PVX49.js +2 -0
- package/dist/assets/mobile-0Gxc02iO.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-C-qpqp1i.js +2 -0
- package/dist/assets/renderMobileApp-UB9bhC1x.js +14 -0
- package/dist/assets/{runtimeSurface-CkHYYg0E.js → runtimeSurface-DefD-2Iv.js} +1 -1
- package/dist/assets/{useInlineCommentController-DD31jQNC.js → useInlineCommentController-B8p2XwXA.js} +2 -2
- package/dist/assets/usePanelSlide-CbqVf-y8.js +56 -0
- package/dist/assets/usePushVisibilityBeacon-CvjN-47R.js +10 -0
- package/dist/assets/useSwitcherItems-B6_F-J-z.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-Dp_Z-0GD.js → vendor-codemirror-language-data-BhBdEPsJ.js} +2 -2
- package/dist/assets/{vendor-katex-CHD9BdDO.js → vendor-katex-CNckGUMB.js} +1 -1
- package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
- package/dist/assets/{web-components-Cct1r-wn.js → web-components-C9yVPsWN.js} +2 -2
- package/dist/index.html +8 -5
- package/dist/mini-chat.html +7 -4
- package/dist/mobile.html +7 -4
- package/dist/sw.js +1 -1
- package/package.json +1 -1
- package/server/index.js +27 -5
- package/server/lib/fs/routes.js +0 -21
- package/server/lib/git/DOCUMENTATION.md +15 -5
- package/server/lib/git/issue-2746-longpaths.test.js +11 -11
- package/server/lib/git/routes.js +80 -4
- package/server/lib/git/routes.test.js +135 -0
- package/server/lib/git/service.js +144 -82
- package/server/lib/git/service.test.js +182 -36
- package/server/lib/pi/extension-protocol.js +62 -0
- package/server/lib/pi/extension-protocol.test.js +34 -0
- package/server/lib/pi/fixtures/pichamber-gui-demo.ts +251 -0
- package/server/lib/pi/routes-extension-events.test.js +152 -0
- package/server/lib/pi/routes.js +345 -7
- package/server/lib/pi/routes.test.js +43 -28
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +8 -5
- package/server/lib/pi/session-daemon/extension-bridge.js +488 -0
- package/server/lib/pi/session-daemon/message-entry-aliases.js +53 -13
- package/server/lib/pi/session-daemon/message-entry-aliases.test.js +110 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +215 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +559 -0
- package/server/lib/pi/session-daemon/session-daemon.js +483 -54
- package/server/lib/pi/session-daemon/session-daemon.test.js +212 -4
- package/server/lib/pi/session-daemon/session-retry-limits.js +55 -0
- package/server/lib/pi/session-daemon/session-retry-limits.test.js +53 -0
- package/server/lib/pi/session-daemon/skill-read-classifier.js +39 -0
- package/server/lib/pi/session-daemon/skill-read-classifier.test.js +41 -0
- package/server/lib/pi/session-daemon/supervisor.js +3 -0
- package/server/lib/pi/small-model-generation.js +104 -0
- package/server/lib/pi/small-model-generation.test.js +66 -0
- package/server/lib/preview/proxy-runtime.js +11 -1
- package/server/lib/preview/proxy-runtime.test.js +3 -0
- package/server/lib/relay/tunnel-host.js +1 -0
- package/server/lib/server/cors.js +0 -2
- package/server/lib/server/cors.test.js +4 -4
- package/server/lib/stt/DOCUMENTATION.md +38 -0
- package/server/lib/stt/audio.js +47 -0
- package/server/lib/stt/config-store.js +81 -0
- package/server/lib/stt/config-store.test.js +36 -0
- package/server/lib/stt/local/model-catalog.js +57 -0
- package/server/lib/stt/local/model-downloader.js +127 -0
- package/server/lib/stt/local/recognizer.js +64 -0
- package/server/lib/stt/local/sherpa-loader.js +43 -0
- package/server/lib/stt/local/worker-client.js +115 -0
- package/server/lib/stt/local/worker-process.js +64 -0
- package/server/lib/stt/protocol.js +38 -0
- package/server/lib/stt/protocol.test.js +17 -0
- package/server/lib/stt/providers/local-worker-provider.js +11 -0
- package/server/lib/stt/providers/openai-compatible-provider.js +31 -0
- package/server/lib/stt/providers/openai-compatible-provider.test.js +31 -0
- package/server/lib/stt/runtime.js +111 -0
- package/server/lib/stt/service.js +106 -0
- package/server/lib/stt/stream-manager.js +188 -0
- package/server/lib/stt/stream-manager.test.js +64 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +1 -1
- package/server/lib/ui-auth/ui-auth.js +8 -3
- package/server/lib/ui-auth/ui-auth.test.js +8 -0
- package/server/lib/workspace/host.js +19 -3
- package/dist/assets/CommitSection-BAYzLtBf.js +0 -1
- package/dist/assets/DiagramEditor-D1yc4joK.js +0 -1
- package/dist/assets/DiagramView-CAlJiG11.js +0 -1
- package/dist/assets/FilesView-DB5VI7EN.js +0 -14
- package/dist/assets/GitView-CFlPcSn9.js +0 -6
- package/dist/assets/JsonTreeView-CoX1ZscV.js +0 -1
- package/dist/assets/PatchDiff-D6Gs7K5B.js +0 -1
- package/dist/assets/PierreDiffViewer-COYd5Qr-.js +0 -136
- package/dist/assets/SettingsView-BYqvfMTS.js +0 -4
- package/dist/assets/SettingsWindow-CtNS0tQn.js +0 -1
- package/dist/assets/ToolPartDiffPreview-CBFC9min.js +0 -8
- package/dist/assets/collapsible-Kx4bmsQM.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-DdOCbMyK.js +0 -3
- package/dist/assets/contextFileOpenGuard-BRldMp0d.js +0 -1
- package/dist/assets/index-BAqpUCjs.js +0 -8
- package/dist/assets/index-CuSNEV7s.js +0 -1
- package/dist/assets/index-riABQmQ_.css +0 -1
- package/dist/assets/isDiffPlainText-CGIf0q8p.js +0 -1
- package/dist/assets/isFilePlainText-D4hgTRxT.js +0 -1
- package/dist/assets/main-By_pvk90.js +0 -2
- package/dist/assets/markdownCore-CAVCyFnI.js +0 -2
- package/dist/assets/miniChat-_XK2gGZE.js +0 -2
- package/dist/assets/mobile-B4E4JqAf.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-Ca4hZgIz.js +0 -1
- package/dist/assets/renderMobileApp-ClA5Cnmw.js +0 -14
- package/dist/assets/usePanelSlide-a4c67FIY.js +0 -56
- package/dist/assets/useWindowTitle-DoHrUC5r.js +0 -10
- package/server/lib/pi/legacy-ui-model-defaults.js +0 -57
- package/server/lib/pi/legacy-ui-model-defaults.test.js +0 -65
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference pi extension that works in plain pi CLI via normal pi APIs and
|
|
3
|
+
* optionally renders rich UI in PiChamber.
|
|
4
|
+
*
|
|
5
|
+
* Drop this file into `~/.pi/agent/extensions/pichamber-gui-demo.ts` to try it:
|
|
6
|
+
*
|
|
7
|
+
* pi -e ./pichamber-gui-demo.ts
|
|
8
|
+
*
|
|
9
|
+
* Or place it under `.pi/extensions/` for a single project.
|
|
10
|
+
*
|
|
11
|
+
* PiChamber detection is optional and never required: the tool, commands,
|
|
12
|
+
* and hooks work without PiChamber, and the `pichamber.ui` card degrades to a
|
|
13
|
+
* generic JSON card in the CLI transcript.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
17
|
+
import { Type } from 'typebox';
|
|
18
|
+
|
|
19
|
+
// Inline helpers keep the extension independent of PiChamber packages. Copy
|
|
20
|
+
// the same detection and descriptor shape into extensions that opt into the GUI.
|
|
21
|
+
const isPiChamber = (ctx: { mode: string; hasUI: boolean }): boolean => {
|
|
22
|
+
const marker = (globalThis as unknown as Record<string, unknown>).__PICHAMBER__ as
|
|
23
|
+
| { version?: number }
|
|
24
|
+
| undefined;
|
|
25
|
+
if (marker?.version) return true;
|
|
26
|
+
try {
|
|
27
|
+
if (typeof process !== 'undefined' && (process as unknown as { env?: Record<string, string> }).env?.PICHAMBER === '1') return true;
|
|
28
|
+
} catch {}
|
|
29
|
+
return ctx.mode === 'rpc' && ctx.hasUI === true;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const publishUi = (
|
|
33
|
+
pi: Pick<ExtensionAPI, 'appendEntry'>,
|
|
34
|
+
payload: Record<string, unknown>,
|
|
35
|
+
) => {
|
|
36
|
+
pi.appendEntry('pichamber.ui', {
|
|
37
|
+
protocol: 'pichamber-extension-ui',
|
|
38
|
+
version: 1,
|
|
39
|
+
...payload,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const publishApp = (
|
|
44
|
+
pi: Pick<ExtensionAPI, 'appendEntry'>,
|
|
45
|
+
payload: Record<string, unknown>,
|
|
46
|
+
) => {
|
|
47
|
+
pi.appendEntry('pichamber.app', {
|
|
48
|
+
protocol: 'pichamber-extension-ui',
|
|
49
|
+
version: 1,
|
|
50
|
+
...payload,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type SubagentRecord = {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
status: 'running' | 'done' | 'error';
|
|
58
|
+
task: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default function (pi: ExtensionAPI): void {
|
|
62
|
+
// In-memory state owned by the extension. PiChamber mirrors the `subagents`
|
|
63
|
+
// snapshot as a server-side normalized map (statuses/widgets) so a phone
|
|
64
|
+
// that connects later sees the current list without the extension resending.
|
|
65
|
+
const subagents = new Map<string, SubagentRecord>();
|
|
66
|
+
let appVisible = false;
|
|
67
|
+
|
|
68
|
+
const renderSubagents = () => {
|
|
69
|
+
const agents = [...subagents.values()];
|
|
70
|
+
if (agents.length === 0) {
|
|
71
|
+
publishUi(pi, {
|
|
72
|
+
id: 'pichamber-demo-subagents',
|
|
73
|
+
title: 'Sub-agents',
|
|
74
|
+
component: 'markdown',
|
|
75
|
+
props: { body: '_No sub-agents running._' },
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
publishUi(pi, {
|
|
81
|
+
id: 'pichamber-demo-subagents',
|
|
82
|
+
title: 'Sub-agents',
|
|
83
|
+
component: 'table',
|
|
84
|
+
props: {
|
|
85
|
+
columns: ['Agent', 'Status', 'Task'],
|
|
86
|
+
rows: agents.map((agent) => [agent.name, agent.status, agent.task]),
|
|
87
|
+
},
|
|
88
|
+
actions: [
|
|
89
|
+
{ label: 'Clear finished', command: 'pichamber-demo-clear', variant: 'ghost' as const },
|
|
90
|
+
{ label: 'Spawn…', command: 'pichamber-demo-spawn', promptForArgs: { label: 'Agent name' } },
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Standard pi tool: callable by the model from any host.
|
|
96
|
+
pi.registerTool({
|
|
97
|
+
name: 'pichamber_demo_spawn',
|
|
98
|
+
label: 'Demo: spawn sub-agent',
|
|
99
|
+
description: 'Demo tool that pretends to spawn a sub-agent and publishes PiChamber GUI state.',
|
|
100
|
+
parameters: Type.Object({
|
|
101
|
+
name: Type.String({ description: 'Sub-agent name' }),
|
|
102
|
+
task: Type.String({ description: 'Task description' }),
|
|
103
|
+
}),
|
|
104
|
+
async execute(_toolCallId, params) {
|
|
105
|
+
const id = `agent-${Date.now().toString(36)}`;
|
|
106
|
+
subagents.set(id, { id, name: params.name, status: 'running', task: params.task });
|
|
107
|
+
|
|
108
|
+
// Optional PiChamber enhancement: publish a table that updates in place
|
|
109
|
+
// (same `id` replaces the previous card; transcript history stays as fallback).
|
|
110
|
+
renderSubagents();
|
|
111
|
+
|
|
112
|
+
// Simulate async completion without actually spawning work, so the demo
|
|
113
|
+
// remains useful without credentials or side effects.
|
|
114
|
+
setTimeout(() => {
|
|
115
|
+
const existing = subagents.get(id);
|
|
116
|
+
if (existing) {
|
|
117
|
+
existing.status = 'done';
|
|
118
|
+
renderSubagents();
|
|
119
|
+
}
|
|
120
|
+
}, 800).unref?.();
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
content: [{ type: 'text', text: `Spawned demo sub-agent "${params.name}" (${id}) for: ${params.task}` }],
|
|
124
|
+
details: { subagentId: id, name: params.name, task: params.task },
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Standard slash commands: discoverable via `extensions.list` and invokable
|
|
130
|
+
// through PiChamber's prompt path (action buttons also use this path).
|
|
131
|
+
pi.registerCommand('pichamber-demo-subagents', {
|
|
132
|
+
description: 'Show demo sub-agents',
|
|
133
|
+
handler: async (_args, ctx) => {
|
|
134
|
+
if (isPiChamber(ctx)) {
|
|
135
|
+
renderSubagents();
|
|
136
|
+
ctx.ui.notify(`Demo sub-agents: ${subagents.size} tracked`, 'info');
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// CLI fallback: plain notification, no PiChamber card needed.
|
|
140
|
+
ctx.ui.notify(`Demo sub-agents (${subagents.size}): ${[...subagents.values()].map((agent) => `${agent.name}:${agent.status}`).join(', ') || 'none'}`, 'info');
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
pi.registerCommand('pichamber-demo-clear', {
|
|
145
|
+
description: 'Clear finished demo sub-agents',
|
|
146
|
+
handler: async (_args, ctx) => {
|
|
147
|
+
for (const [id, agent] of subagents) {
|
|
148
|
+
if (agent.status === 'done') subagents.delete(id);
|
|
149
|
+
}
|
|
150
|
+
if (isPiChamber(ctx)) renderSubagents();
|
|
151
|
+
ctx.ui.notify('Cleared finished demo sub-agents', 'info');
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
pi.registerCommand('pichamber-demo-progress', {
|
|
156
|
+
description: 'Show a progress demo card',
|
|
157
|
+
handler: async (args) => {
|
|
158
|
+
const value = Math.max(0, Math.min(100, Number(args) || 40));
|
|
159
|
+
publishUi(pi, {
|
|
160
|
+
id: 'pichamber-demo-progress',
|
|
161
|
+
title: 'Demo progress',
|
|
162
|
+
component: 'progress',
|
|
163
|
+
props: { label: 'Indexing', value, max: 100 },
|
|
164
|
+
actions: [{ label: 'Reset', command: 'pichamber-demo-progress', args: '0' }],
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Structured multi-input dialog. PiChamber renders a native form and
|
|
170
|
+
// resolves with a values object; plain pi falls back to sequential prompts.
|
|
171
|
+
type FormCtx = Parameters<NonNullable<Parameters<ExtensionAPI['registerCommand']>[1]['handler']>>[1];
|
|
172
|
+
const askAgent = async (ctx: FormCtx): Promise<{ name: string; task: string } | undefined> => {
|
|
173
|
+
if (isPiChamber(ctx)) {
|
|
174
|
+
const uiWithForm = ctx.ui as typeof ctx.ui & {
|
|
175
|
+
form?: (title: string, fields: Array<Record<string, unknown>>, opts?: Record<string, unknown>) => Promise<Record<string, string> | undefined>;
|
|
176
|
+
};
|
|
177
|
+
if (typeof uiWithForm.form === 'function') {
|
|
178
|
+
const values = await uiWithForm.form('Spawn sub-agent', [
|
|
179
|
+
{ id: 'name', label: 'Name', type: 'text', required: true, placeholder: 'research' },
|
|
180
|
+
{ id: 'task', label: 'Task', type: 'textarea', required: true },
|
|
181
|
+
{ id: 'priority', label: 'Priority', type: 'select', options: ['low', 'normal', 'high'], initial: 'normal' },
|
|
182
|
+
]);
|
|
183
|
+
if (!values?.name || !values.task) return undefined;
|
|
184
|
+
return { name: values.name, task: values.task };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const name = await ctx.ui.input('Sub-agent name');
|
|
188
|
+
if (!name) return undefined;
|
|
189
|
+
const task = await ctx.ui.input('Task description');
|
|
190
|
+
if (!task) return undefined;
|
|
191
|
+
return { name, task };
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
pi.registerCommand('pichamber-demo-spawn', {
|
|
195
|
+
description: 'Spawn a demo sub-agent interactively (form dialog in PiChamber)',
|
|
196
|
+
handler: async (args, ctx) => {
|
|
197
|
+
let name = args?.trim() ?? '';
|
|
198
|
+
let task = name ? `demo task for ${name}` : '';
|
|
199
|
+
if (!name) {
|
|
200
|
+
const answers = await askAgent(ctx);
|
|
201
|
+
if (!answers) return;
|
|
202
|
+
({ name, task } = answers);
|
|
203
|
+
}
|
|
204
|
+
const id = `agent-${Date.now().toString(36)}`;
|
|
205
|
+
subagents.set(id, { id, name, status: 'running', task });
|
|
206
|
+
renderSubagents();
|
|
207
|
+
ctx.ui.notify(`Spawned ${name}`, 'info');
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Sandboxed app surface: self-contained HTML rendered in an iframe that can
|
|
212
|
+
// only invoke registered commands through data-pichamber-command buttons.
|
|
213
|
+
pi.registerCommand('pichamber-demo-app', {
|
|
214
|
+
description: 'Toggle a sandboxed demo app surface (PiChamber only)',
|
|
215
|
+
handler: async (_args, ctx) => {
|
|
216
|
+
if (!isPiChamber(ctx)) {
|
|
217
|
+
ctx.ui.notify('App surfaces are a PiChamber feature', 'warning');
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (appVisible) {
|
|
221
|
+
publishApp(pi, { appId: 'demo-board', removed: true });
|
|
222
|
+
appVisible = false;
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
publishApp(pi, {
|
|
226
|
+
appId: 'demo-board',
|
|
227
|
+
title: 'Demo board',
|
|
228
|
+
html: `<!doctype html><html><body style="font-family:system-ui;padding:12px">
|
|
229
|
+
<h3 style="margin:0 0 8px">Demo board</h3>
|
|
230
|
+
<button data-pichamber-command="pichamber-demo-subagents">Refresh panel</button>
|
|
231
|
+
<button data-pichamber-command="pichamber-demo-clear">Clear finished</button>
|
|
232
|
+
<p style="color:#666">Buttons fire slash commands through PiChamber's authenticated prompt path.</p>
|
|
233
|
+
</body></html>`,
|
|
234
|
+
});
|
|
235
|
+
appVisible = true;
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// Lifecycle hooks run identically inside PiChamber and plain pi. They do not
|
|
240
|
+
// need PiChamber-specific branching, but can optionally publish UI when that
|
|
241
|
+
// capability is present.
|
|
242
|
+
pi.on('session_start', async (_event, ctx) => {
|
|
243
|
+
if (isPiChamber(ctx)) {
|
|
244
|
+
ctx.ui.setStatus('pichamber-demo', 'Demo extension active');
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
pi.on('session_shutdown', async () => {
|
|
249
|
+
subagents.clear();
|
|
250
|
+
});
|
|
251
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { projectEventFrame, projectExtensionList } from './routes.js';
|
|
4
|
+
|
|
5
|
+
const frame = (event, payload, sequence = 1) => ({
|
|
6
|
+
protocolVersion: 1,
|
|
7
|
+
kind: 'event',
|
|
8
|
+
event,
|
|
9
|
+
sequence,
|
|
10
|
+
payload: { sessionId: 'sess-1', directory: '/work', ...payload },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('extension public projections', () => {
|
|
14
|
+
it('whitelists extension list fields and rejects path-shaped identities', () => {
|
|
15
|
+
expect(projectExtensionList({
|
|
16
|
+
directory: '/work',
|
|
17
|
+
extensions: [{ id: '0123456789abcdef', name: 'economy', path: '/secret/economy.ts' }],
|
|
18
|
+
commands: [{ name: 'balance', description: 'Switch mode', source: 'daemon-value', scope: 'global', path: '/secret' }],
|
|
19
|
+
})).toEqual({
|
|
20
|
+
directory: '/work',
|
|
21
|
+
extensions: [{ id: '0123456789abcdef', name: 'economy' }],
|
|
22
|
+
commands: [{ name: 'balance', description: 'Switch mode', source: 'extension', scope: 'global' }],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(() => projectExtensionList({
|
|
26
|
+
directory: '/work',
|
|
27
|
+
extensions: [{ id: '/secret/extension.ts', name: 'extension' }],
|
|
28
|
+
commands: [],
|
|
29
|
+
})).toThrow();
|
|
30
|
+
expect(() => projectExtensionList({
|
|
31
|
+
directory: '/work',
|
|
32
|
+
extensions: [{ id: '0123456789abcdef', name: '../extension' }],
|
|
33
|
+
commands: [],
|
|
34
|
+
})).toThrow();
|
|
35
|
+
});
|
|
36
|
+
it('projects extension.ui panels with caps and removals', () => {
|
|
37
|
+
const projected = projectEventFrame(frame('extension.ui', {
|
|
38
|
+
id: 'subagents',
|
|
39
|
+
title: 'Sub-agents',
|
|
40
|
+
component: 'table',
|
|
41
|
+
props: { columns: ['Agent'], rows: [['research']] },
|
|
42
|
+
actions: [{ label: 'Clear', command: 'agents-clear' }],
|
|
43
|
+
}));
|
|
44
|
+
expect(projected).toMatchObject({
|
|
45
|
+
name: 'extension.ui',
|
|
46
|
+
payload: { id: 'subagents', title: 'Sub-agents', component: 'table' },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Missing component and title is treated as an unregister.
|
|
50
|
+
expect(projectEventFrame(frame('extension.ui', { id: 'gone' }))).toMatchObject({
|
|
51
|
+
payload: { id: 'gone', removed: true },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Invalid ids are dropped entirely.
|
|
55
|
+
expect(projectEventFrame(frame('extension.ui', { id: '' }))).toBeNull();
|
|
56
|
+
expect(projectEventFrame(frame('extension.ui', { id: `${'x'.repeat(200)}` }))).toBeNull();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('projects extension.app payloads and rejects oversized html', () => {
|
|
60
|
+
const projected = projectEventFrame(frame('extension.app', {
|
|
61
|
+
appId: 'board',
|
|
62
|
+
title: 'Board',
|
|
63
|
+
html: '<button data-pichamber-command="run">Run</button>',
|
|
64
|
+
}));
|
|
65
|
+
expect(projected?.payload).toMatchObject({ appId: 'board', title: 'Board' });
|
|
66
|
+
expect(projected?.payload.html).toContain('data-pichamber-command');
|
|
67
|
+
|
|
68
|
+
expect(projectEventFrame(frame('extension.app', {
|
|
69
|
+
appId: 'big',
|
|
70
|
+
html: `${'<a>'.repeat(70_000)}`,
|
|
71
|
+
}))).toBeNull();
|
|
72
|
+
|
|
73
|
+
expect(projectEventFrame(frame('extension.app', { appId: 'gone', removed: true }))?.payload).toMatchObject({
|
|
74
|
+
appId: 'gone',
|
|
75
|
+
removed: true,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('projects bounded editor/title/catalog and tree invalidation events', () => {
|
|
80
|
+
expect(projectEventFrame(frame('extension.editor', { text: 'draft' }))).toMatchObject({
|
|
81
|
+
name: 'extension.editor', payload: { text: 'draft' },
|
|
82
|
+
});
|
|
83
|
+
expect(projectEventFrame(frame('extension.editor', { text: 'x'.repeat(100_001) }))).toBeNull();
|
|
84
|
+
expect(projectEventFrame(frame('extension.title', { title: 'Mode\u0000 Picker' }))).toMatchObject({
|
|
85
|
+
payload: { title: 'Mode Picker' },
|
|
86
|
+
});
|
|
87
|
+
expect(projectEventFrame(frame('extension.title', {}))).toMatchObject({ payload: {} });
|
|
88
|
+
expect(projectEventFrame(frame('extension.catalog', { providers: true, resources: true }))).toMatchObject({
|
|
89
|
+
payload: { providers: true, resources: true },
|
|
90
|
+
});
|
|
91
|
+
expect(projectEventFrame(frame('extension.catalog', {}))).toBeNull();
|
|
92
|
+
expect(projectEventFrame(frame('session.tree.updated', {}))).toMatchObject({ payload: {} });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('projects form dialogs with sanitized fields', () => {
|
|
96
|
+
const projected = projectEventFrame(frame('extension.dialog', {
|
|
97
|
+
requestId: 'form-1',
|
|
98
|
+
method: 'form',
|
|
99
|
+
title: 'Spawn agent',
|
|
100
|
+
fields: [
|
|
101
|
+
{ id: 'name', label: 'Name', type: 'text', required: true },
|
|
102
|
+
{ id: 'level', label: 'Level', type: 'select', options: ['low', 'high'], initial: 'high' },
|
|
103
|
+
{ id: 'bad' },
|
|
104
|
+
null,
|
|
105
|
+
],
|
|
106
|
+
}));
|
|
107
|
+
expect(projected?.payload.method).toBe('form');
|
|
108
|
+
expect(projected?.payload.fields).toHaveLength(2);
|
|
109
|
+
expect(projected?.payload.fields[0]).toMatchObject({ id: 'name', type: 'text', required: true });
|
|
110
|
+
expect(projected?.payload.fields[1]).toMatchObject({ id: 'level', initial: 'high', options: ['low', 'high'] });
|
|
111
|
+
|
|
112
|
+
expect(projectEventFrame(frame('extension.dialog.dismiss', {
|
|
113
|
+
requestId: 'form-1',
|
|
114
|
+
reason: 'timeout',
|
|
115
|
+
}))?.payload).toEqual({ requestId: 'form-1', reason: 'timeout' });
|
|
116
|
+
expect(projectEventFrame(frame('extension.dialog.dismiss', {
|
|
117
|
+
requestId: 'form-1',
|
|
118
|
+
reason: 'invented',
|
|
119
|
+
}))).toBeNull();
|
|
120
|
+
|
|
121
|
+
// Unknown dialog methods fail closed: the frame is dropped.
|
|
122
|
+
expect(projectEventFrame(frame('extension.dialog', {
|
|
123
|
+
requestId: 'r1',
|
|
124
|
+
method: 'hologram',
|
|
125
|
+
title: '?',
|
|
126
|
+
}))).toBeNull();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('projects snapshot extensionPanels/extensionApps for reconnect', () => {
|
|
130
|
+
const projected = projectEventFrame(frame('session.snapshot', {
|
|
131
|
+
isStreaming: false,
|
|
132
|
+
lifecycle: 'idle',
|
|
133
|
+
queue: { steering: 0, followUp: 0 },
|
|
134
|
+
lastSequence: 5,
|
|
135
|
+
extensionStatuses: [{ key: 'mode', text: 'economy' }],
|
|
136
|
+
extensionPanels: [{ id: 'panel-1', component: 'progress', props: { value: 50 } }],
|
|
137
|
+
extensionApps: [{ appId: 'app-1', html: '<p>x</p>' }],
|
|
138
|
+
extensionTitle: 'Build mode',
|
|
139
|
+
extensionDialogs: [{
|
|
140
|
+
requestId: 'form-1',
|
|
141
|
+
method: 'form',
|
|
142
|
+
title: 'Form',
|
|
143
|
+
fields: [{ id: 'a', label: 'A', type: 'text' }],
|
|
144
|
+
}],
|
|
145
|
+
}));
|
|
146
|
+
const snapshot = projected?.payload.snapshot;
|
|
147
|
+
expect(snapshot.extensionPanels).toHaveLength(1);
|
|
148
|
+
expect(snapshot.extensionApps).toHaveLength(1);
|
|
149
|
+
expect(snapshot.extensionDialogs[0].fields).toHaveLength(1);
|
|
150
|
+
expect(snapshot.extensionTitle).toBe('Build mode');
|
|
151
|
+
});
|
|
152
|
+
});
|