@pi-chamber/web 0.9.5 → 0.9.6

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.
Files changed (72) hide show
  1. package/dist/assets/DiagramView-0Iq1ak1I.js +1 -0
  2. package/dist/assets/{DiffView-BmIVvheE.js → DiffView-DD1AFRi3.js} +1 -1
  3. package/dist/assets/FileSaveConflictDialog-CoKwDovb.js +3 -0
  4. package/dist/assets/FilesView-B_BF39ef.js +6 -0
  5. package/dist/assets/{GitView-BNkzec7G.js → GitView-LFEpCasf.js} +3 -3
  6. package/dist/assets/{JsonTreeView-C1Kzaybf.js → JsonTreeView-Cwjgvh4g.js} +1 -1
  7. package/dist/assets/{MarkdownRendererImpl-qmKiFVpO.js → MarkdownRendererImpl-_7kV1yNw.js} +2 -2
  8. package/dist/assets/{PatchDiff-D9JesZL1.js → PatchDiff-DG43C1HW.js} +1 -1
  9. package/dist/assets/{SessionSwitcherContent-DplV_ApH.js → SessionSwitcherContent-DCFXPY3d.js} +1 -1
  10. package/dist/assets/{SessionSwitcherDropdown-DdgDKT6K.js → SessionSwitcherDropdown-QY7FKuEQ.js} +2 -2
  11. package/dist/assets/{SessionUnreadDot-BdSDgvhC.js → SessionUnreadDot-DGT31A3z.js} +1 -1
  12. package/dist/assets/{SettingsView-z8uf0XyM.js → SettingsView-eG-wN-yY.js} +2 -2
  13. package/dist/assets/{SettingsWindow-CPDmgNg2.js → SettingsWindow-Dvnp8YrA.js} +1 -1
  14. package/dist/assets/{ToolOutputDialog-DaF1xcM0.js → ToolOutputDialog-IlCrS6BR.js} +1 -1
  15. package/dist/assets/{ToolPartDiffPreview-Di6Uo0Dt.js → ToolPartDiffPreview-D68JV0rR.js} +1 -1
  16. package/dist/assets/{VirtualizedFileDiff-wqcrY0yr.js → VirtualizedFileDiff-Bl-rAYeh.js} +1 -1
  17. package/dist/assets/{collapsible-DBQnXTNm.js → collapsible-BjniCdZ5.js} +1 -1
  18. package/dist/assets/{computeVirtualFileMetrics-Cr3jh0d6.js → computeVirtualFileMetrics-FSOm2VrW.js} +2 -2
  19. package/dist/assets/{contextFileOpenGuard-C_AOTYQD.js → contextFileOpenGuard-Bxb6AIPa.js} +1 -1
  20. package/dist/assets/{gitStatusPredicates-BvPOjeOy.js → gitStatusPredicates-DxolDpMd.js} +1 -1
  21. package/dist/assets/index-BpmGBboM.css +1 -0
  22. package/dist/assets/index-DZnzXhTs.js +8 -0
  23. package/dist/assets/{index-B8Wt2aN3.js → index-Dh58uD3I.js} +1 -1
  24. package/dist/assets/{isDiffPlainText-L9uvgz2F.js → isDiffPlainText-D3_04XCh.js} +1 -1
  25. package/dist/assets/{isFilePlainText-C4yk5BOo.js → isFilePlainText-CHouYQhH.js} +1 -1
  26. package/dist/assets/{main-DCK6lLCo.js → main-CH3EqGJI.js} +2 -2
  27. package/dist/assets/{main-C1OSzD-E.js → main-HzTrVvbB.js} +3 -3
  28. package/dist/assets/{markdownCore-Czb_lINQ.js → markdownCore-DJU4KvHP.js} +1 -1
  29. package/dist/assets/{miniChat-CXiSlptL.js → miniChat-Ca3TpaaA.js} +2 -2
  30. package/dist/assets/{mobile-D0HVxiyJ.js → mobile-lj4gpGsO.js} +2 -2
  31. package/dist/assets/{renderElectronMiniChatApp-BcG209a4.js → renderElectronMiniChatApp-rUFfaD-T.js} +2 -2
  32. package/dist/assets/{renderMobileApp-B5x_PWlc.js → renderMobileApp-CcWQ1sCf.js} +3 -3
  33. package/dist/assets/{runtimeEndpointReset-CUiPe6dQ.js → runtimeEndpointReset-D2MmSbDk.js} +8 -8
  34. package/dist/assets/{runtimeSurface-vilE4xyj.js → runtimeSurface-CE_VNjdH.js} +1 -1
  35. package/dist/assets/{useAppFontEffects-BP07Vl6M.js → useAppFontEffects-BvFAP9zG.js} +86 -86
  36. package/dist/assets/useFilesViewSearch-BD79p3A2.js +7 -0
  37. package/dist/assets/{usePushVisibilityBeacon-CChMvoTL.js → usePushVisibilityBeacon-CWg0j-Wg.js} +1 -1
  38. package/dist/assets/{useSwitcherItems-_RSo3F-A.js → useSwitcherItems-CazJ6Yox.js} +1 -1
  39. package/dist/assets/{vendor-codemirror-language-data-BJrrV83E.js → vendor-codemirror-language-data-CP3j3-xu.js} +2 -2
  40. package/dist/assets/{web-components-B5sMa_kC.js → web-components-DWuadqra.js} +1 -1
  41. package/dist/index.html +4 -4
  42. package/dist/mini-chat.html +3 -3
  43. package/dist/mobile.html +3 -3
  44. package/package.json +1 -1
  45. package/server/lib/fs/DOCUMENTATION.md +15 -3
  46. package/server/lib/fs/routes.js +369 -51
  47. package/server/lib/fs/routes.test.js +565 -3
  48. package/server/lib/fs/search.js +74 -29
  49. package/server/lib/pi/routes.js +56 -3
  50. package/server/lib/pi/routes.test.js +165 -0
  51. package/server/lib/pi/session-daemon/DOCUMENTATION.md +3 -2
  52. package/server/lib/pi/session-daemon/prompt-operations.test.js +9 -3
  53. package/server/lib/pi/session-daemon/prompt-preflight.test.js +556 -0
  54. package/server/lib/pi/session-daemon/send-operation-dedup.test.js +331 -0
  55. package/server/lib/pi/session-daemon/send-operation-registry.js +264 -0
  56. package/server/lib/pi/session-daemon/send-operation-registry.test.js +205 -0
  57. package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +16 -5
  58. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +3 -1
  59. package/server/lib/pi/session-daemon/session-daemon.js +284 -31
  60. package/server/lib/pi/session-daemon/session-daemon.test.js +37 -13
  61. package/server/lib/pi/session-daemon/session-idle-residency.test.js +8 -1
  62. package/server/lib/pi/session-daemon/session-replay.test.js +3 -1
  63. package/server/lib/server/cors.js +6 -0
  64. package/server/lib/server/cors.test.js +3 -0
  65. package/server/lib/workspace/host.js +6 -2
  66. package/server/lib/workspace/host.test.js +15 -0
  67. package/dist/assets/DiagramEditor-BPDkGHsj.js +0 -1
  68. package/dist/assets/DiagramView-D_EfDz2d.js +0 -1
  69. package/dist/assets/FilesView-CJytSUAX.js +0 -6
  70. package/dist/assets/index-DIF8b4bh.css +0 -1
  71. package/dist/assets/index-jrfQYSvP.js +0 -8
  72. package/dist/assets/useFilesViewSearch-oxIKk-ea.js +0 -7
@@ -0,0 +1,205 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import {
4
+ createSendOperationRegistry,
5
+ isValidSendOperationId,
6
+ stableFingerprint,
7
+ } from './send-operation-registry.js';
8
+
9
+ describe('send operation registry', () => {
10
+ const baseClaim = {
11
+ kind: 'prompt',
12
+ sessionId: 'sess-1',
13
+ operationId: 'op-1',
14
+ fingerprint: '{"text":"hello"}',
15
+ };
16
+
17
+ it('accepts a new claim and settles the acceptance receipt', () => {
18
+ const registry = createSendOperationRegistry();
19
+ const claim = registry.claim(baseClaim);
20
+ expect(claim.outcome).toBe('new');
21
+ claim.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'msg-1' } });
22
+ const retry = registry.claim(baseClaim);
23
+ expect(retry.outcome).toBe('accepted');
24
+ expect(retry.receipt).toEqual({ accepted: true, messageId: 'msg-1' });
25
+ expect(retry.deduplicated).toBe(true);
26
+ });
27
+
28
+ it('shares the original receipt with a concurrent pending duplicate', async () => {
29
+ const registry = createSendOperationRegistry();
30
+ const first = registry.claim(baseClaim);
31
+ expect(first.outcome).toBe('new');
32
+
33
+ const duplicate = registry.claim(baseClaim);
34
+ expect(duplicate.outcome).toBe('pending');
35
+
36
+ const duplicateResult = duplicate.settled.then((result) => result);
37
+ first.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'msg-original' } });
38
+ await expect(duplicateResult).resolves.toEqual({
39
+ accepted: true,
40
+ receipt: { accepted: true, messageId: 'msg-original' },
41
+ });
42
+ // The late duplicate resolves against the retained receipt afterwards.
43
+ expect(registry.claim(baseClaim).outcome).toBe('accepted');
44
+ });
45
+
46
+ it('shares the original rejection with a concurrent pending duplicate and frees the id', async () => {
47
+ const registry = createSendOperationRegistry();
48
+ const first = registry.claim(baseClaim);
49
+ const duplicate = registry.claim(baseClaim);
50
+ expect(duplicate.outcome).toBe('pending');
51
+
52
+ first.entry.settle({ accepted: false, error: new Error('busy') });
53
+ await expect(duplicate.settled).rejects.toThrow('busy');
54
+ // A rejection happened before Pi ran, so the id is free for a retry.
55
+ expect(registry.claim(baseClaim).outcome).toBe('new');
56
+ });
57
+
58
+ it('rejects a payload mismatch for the same id', () => {
59
+ const registry = createSendOperationRegistry();
60
+ const first = registry.claim(baseClaim);
61
+ first.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'msg-1' } });
62
+ expect(registry.claim({ ...baseClaim, fingerprint: '{"text":"different"}' }).outcome).toBe('mismatch');
63
+ expect(registry.claim({ ...baseClaim, kind: 'steer' }).outcome).toBe('new');
64
+ expect(registry.claim({ ...baseClaim, sessionId: 'sess-2' }).outcome).toBe('new');
65
+ });
66
+
67
+ it('expires accepted receipts after the ttl so the same id can never auto-replay', () => {
68
+ let time = 1_000;
69
+ const registry = createSendOperationRegistry({ now: () => time, ttlMs: 50 });
70
+ const claim = registry.claim(baseClaim);
71
+ claim.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'msg-1' } });
72
+ expect(registry.claim(baseClaim).outcome).toBe('accepted');
73
+
74
+ time += 49;
75
+ expect(registry.claim(baseClaim).outcome).toBe('accepted');
76
+ time += 2;
77
+ // Retention gone: the same id is rejected as expired (never a silent
78
+ // re-execution). Callers must use a new operation id after expiry.
79
+ expect(registry.claim(baseClaim).outcome).toBe('expired');
80
+ expect(registry.query({ kind: 'prompt', sessionId: 'sess-1', operationId: 'op-1' }).status).toBe('expired');
81
+ // A distinct id is still a distinct intent and executes.
82
+ expect(registry.claim({ ...baseClaim, operationId: 'op-2' }).outcome).toBe('new');
83
+ });
84
+
85
+ it('bounds retention by evicting the oldest accepted receipts', () => {
86
+ const registry = createSendOperationRegistry({ maxEntries: 2 });
87
+ const one = registry.claim({ ...baseClaim, operationId: 'op-1' });
88
+ one.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'm1' } });
89
+ const two = registry.claim({ ...baseClaim, operationId: 'op-2' });
90
+ two.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'm2' } });
91
+ const three = registry.claim({ ...baseClaim, operationId: 'op-3' });
92
+ three.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'm3' } });
93
+
94
+ // Evicted acceptances leave an expired tombstone: never a false
95
+ // acceptance and never an automatic re-execution with the same id.
96
+ expect(registry.claim({ ...baseClaim, operationId: 'op-1' }).outcome).toBe('expired');
97
+ expect(registry.claim({ ...baseClaim, operationId: 'op-2' }).outcome).toBe('accepted');
98
+ expect(registry.claim({ ...baseClaim, operationId: 'op-3' }).outcome).toBe('accepted');
99
+ });
100
+
101
+ it('never evicts a pending claim so concurrent duplicates keep sharing the outcome', () => {
102
+ const registry = createSendOperationRegistry({ maxEntries: 2 });
103
+ const pending = registry.claim({ ...baseClaim, operationId: 'op-pending' });
104
+ expect(pending.outcome).toBe('new');
105
+ for (let index = 0; index < 5; index += 1) {
106
+ const claim = registry.claim({ ...baseClaim, operationId: `op-fill-${index}` });
107
+ claim.entry.settle({ accepted: true, receipt: { accepted: true, messageId: `m-${index}` } });
108
+ }
109
+ const duplicate = registry.claim({ ...baseClaim, operationId: 'op-pending' });
110
+ expect(duplicate.outcome).toBe('pending');
111
+ });
112
+
113
+ it('produces order-independent stable fingerprints', () => {
114
+ expect(stableFingerprint({ a: 1, b: 'x' })).toBe(stableFingerprint({ b: 'x', a: 1 }));
115
+ expect(stableFingerprint({ a: 1 })).not.toBe(stableFingerprint({ a: 2 }));
116
+ expect(stableFingerprint({ a: undefined })).toBe(stableFingerprint({}));
117
+ expect(stableFingerprint(['x', 1])).toBe(stableFingerprint(['x', 1]));
118
+ expect(stableFingerprint(null)).toBe('null');
119
+ });
120
+
121
+ it('validates operation ids without wildcard or control characters', () => {
122
+ expect(isValidSendOperationId('op_1')).toBe(true);
123
+ expect(isValidSendOperationId('qm:abc.def-2')).toBe(true);
124
+ expect(isValidSendOperationId('')).toBe(false);
125
+ expect(isValidSendOperationId('-leading-symbol')).toBe(false);
126
+ expect(isValidSendOperationId('has spaces')).toBe(false);
127
+ expect(isValidSendOperationId(`x${'y'.repeat(128)}`)).toBe(false);
128
+ expect(isValidSendOperationId(undefined)).toBe(false);
129
+ });
130
+
131
+ it('query() distinguishes pending, accepted, unknown, and expired with no false acceptance', () => {
132
+ let time = 1_000;
133
+ const registry = createSendOperationRegistry({ now: () => time, ttlMs: 50, maxEntries: 10 });
134
+ const key = { kind: 'prompt', sessionId: 'sess-1', operationId: 'op-q' };
135
+ expect(registry.query(key).status).toBe('unknown');
136
+
137
+ const fresh = registry.claim({ kind: 'prompt', sessionId: 'sess-1', operationId: 'op-q', fingerprint: baseClaim.fingerprint });
138
+ expect(fresh.outcome).toBe('new');
139
+ expect(registry.query(key).status).toBe('pending');
140
+
141
+ fresh.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'm1' } });
142
+ expect(registry.query(key)).toMatchObject({ status: 'accepted', receipt: { accepted: true, messageId: 'm1' } });
143
+
144
+ // Exact identity: wrong kind/session/operation is unknown, never accepted.
145
+ expect(registry.query({ ...key, kind: 'steer' }).status).toBe('unknown');
146
+ expect(registry.query({ ...key, sessionId: 'sess-2' }).status).toBe('unknown');
147
+ expect(registry.query({ ...key, operationId: 'op-other' }).status).toBe('unknown');
148
+
149
+ time += 51;
150
+ // After TTL the receipt is gone: expired, never a stale acceptance.
151
+ expect(registry.query(key).status).toBe('expired');
152
+ expect(registry.query(key).receipt).toBeUndefined();
153
+ // A retry after expiry is rejected as expired — it must not
154
+ // automatically re-execute. The caller needs a new operation id.
155
+ const retry = registry.claim({ kind: 'prompt', sessionId: 'sess-1', operationId: 'op-q', fingerprint: baseClaim.fingerprint });
156
+ expect(retry.outcome).toBe('expired');
157
+ expect(registry.query(key).status).toBe('expired');
158
+ expect(registry.query(key).receipt).toBeUndefined();
159
+ });
160
+
161
+ it('rejections before Pi leave no tombstone while evicted acceptances expire', () => {
162
+ const registry = createSendOperationRegistry({ maxEntries: 2 });
163
+ const rejected = registry.claim({ ...baseClaim, operationId: 'op-reject' });
164
+ rejected.entry.settle({ accepted: false, error: new Error('busy') });
165
+ // Nothing executed: unknown (reusable), not expired.
166
+ expect(registry.query({ kind: 'prompt', sessionId: 'sess-1', operationId: 'op-reject' }).status).toBe('unknown');
167
+
168
+ const one = registry.claim({ ...baseClaim, operationId: 'op-1' });
169
+ one.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'm1' } });
170
+ const two = registry.claim({ ...baseClaim, operationId: 'op-2' });
171
+ two.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'm2' } });
172
+ const three = registry.claim({ ...baseClaim, operationId: 'op-3' });
173
+ three.entry.settle({ accepted: true, receipt: { accepted: true, messageId: 'm3' } });
174
+ // Oldest acceptance evicted: expired tombstone, never a false acceptance.
175
+ expect(registry.query({ kind: 'prompt', sessionId: 'sess-1', operationId: 'op-1' }).status).toBe('expired');
176
+ expect(registry.query({ kind: 'prompt', sessionId: 'sess-1', operationId: 'op-2' }).status).toBe('accepted');
177
+ });
178
+
179
+ it('never expires an active pending claim so duplicates cannot double-execute', async () => {
180
+ let time = 1_000;
181
+ const registry = createSendOperationRegistry({ now: () => time, pendingTtlMs: 20, maxEntries: 4, maxPending: 2 });
182
+ const first = registry.claim({ ...baseClaim, operationId: 'op-leak-1' });
183
+ const second = registry.claim({ ...baseClaim, operationId: 'op-leak-2' });
184
+ expect(first.outcome).toBe('new');
185
+ expect(second.outcome).toBe('new');
186
+ // Pending bound: a third distinct pending claim is overloaded, never executed.
187
+ expect(registry.claim({ ...baseClaim, operationId: 'op-leak-3' }).outcome).toBe('overloaded');
188
+ time += 21;
189
+ // Active ownership survives past pendingTtlMs: expiring here would let a
190
+ // duplicate re-execute the same operation, so duplicates still share.
191
+ expect(registry.claim({ ...baseClaim, operationId: 'op-leak-1' }).outcome).toBe('pending');
192
+ expect(registry.query({ kind: 'prompt', sessionId: 'sess-1', operationId: 'op-leak-1' }).status).toBe('pending');
193
+ expect(registry.claim({ ...baseClaim, operationId: 'op-after' }).outcome).toBe('overloaded');
194
+ // Settling frees the slot: a busy rejection shares with its duplicate
195
+ // and leaves the id reusable (nothing executed).
196
+ const duplicate = registry.claim({ ...baseClaim, operationId: 'op-leak-1' });
197
+ expect(duplicate.outcome).toBe('pending');
198
+ first.entry.settle({ accepted: false, error: Object.assign(new Error('busy'), { code: 'SESSION_BUSY' }) });
199
+ await expect(duplicate.settled).rejects.toMatchObject({ code: 'SESSION_BUSY' });
200
+ expect(registry.query({ kind: 'prompt', sessionId: 'sess-1', operationId: 'op-leak-1' }).status).toBe('unknown');
201
+ expect(registry.claim({ ...baseClaim, operationId: 'op-leak-1' }).outcome).toBe('new');
202
+ expect(registry.pendingSize).toBeLessThanOrEqual(2);
203
+ expect(registry.expiredSize).toBeLessThanOrEqual(4);
204
+ });
205
+ });
@@ -149,7 +149,11 @@ describe('pi extensions end-to-end through the real SDK', () => {
149
149
  expect(list.result.commands.map((command) => command.name)).toContain('demo-dialog');
150
150
 
151
151
  // Invoke the extension command: it blocks on a dialog over the stream.
152
- await client.request('sessions.prompt', {
152
+ // True preflight acceptance for extension commands fires after the command
153
+ // handler completes (post-dialog), so the prompt request stays open while
154
+ // the dialog is answered on a separate connection — matching production
155
+ // where each HTTP route uses its own daemon socket.
156
+ const dialogPrompt = client.request('sessions.prompt', {
153
157
  sessionId: created.result.session.id,
154
158
  text: '/demo-dialog',
155
159
  });
@@ -160,10 +164,17 @@ describe('pi extensions end-to-end through the real SDK', () => {
160
164
  const settled = client.next((message) => message.kind === 'event'
161
165
  && message.event === 'session.lifecycle'
162
166
  && message.payload.state === 'idle');
163
- await client.request('extensions.respond', {
164
- requestId: dialog.payload.requestId,
165
- confirmed: true,
166
- });
167
+ const respondClient = connectClient(endpoint);
168
+ await respondClient.authenticate();
169
+ try {
170
+ await respondClient.request('extensions.respond', {
171
+ requestId: dialog.payload.requestId,
172
+ confirmed: true,
173
+ });
174
+ } finally {
175
+ await respondClient.close().catch(() => {});
176
+ }
177
+ await dialogPrompt;
167
178
 
168
179
  // Extension saw the answer and emitted its GUI card + custom message.
169
180
  const card = await client.next((message) => message.kind === 'event' && message.event === 'extension.entry');
@@ -55,7 +55,9 @@ class ExtensibleFakeSession {
55
55
  this.reloadCount += 1;
56
56
  }
57
57
 
58
- async prompt() {}
58
+ async prompt(text, options) {
59
+ options?.preflightResult?.(true);
60
+ }
59
61
 
60
62
  async navigateTree() {
61
63
  return { cancelled: false };