@pi-chamber/web 0.9.5 → 0.9.7

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 (104) hide show
  1. package/dist/assets/DiagramView-BvrCkm_z.js +1 -0
  2. package/dist/assets/{DiffView-BmIVvheE.js → DiffView-DMvRLRN1.js} +1 -1
  3. package/dist/assets/FileSaveConflictDialog-DGa9u43J.js +3 -0
  4. package/dist/assets/FilesView-CNHu4RnC.js +6 -0
  5. package/dist/assets/{GitView-BNkzec7G.js → GitView-Cbepz-bR.js} +3 -3
  6. package/dist/assets/{JsonTreeView-C1Kzaybf.js → JsonTreeView-C2X5oXQm.js} +1 -1
  7. package/dist/assets/{MarkdownRendererImpl-qmKiFVpO.js → MarkdownRendererImpl-BanSCkPy.js} +2 -2
  8. package/dist/assets/{PatchDiff-D9JesZL1.js → PatchDiff-i_9BIlgo.js} +1 -1
  9. package/dist/assets/{SessionSwitcherContent-DplV_ApH.js → SessionSwitcherContent-DxS_rFuS.js} +1 -1
  10. package/dist/assets/{SessionSwitcherDropdown-DdgDKT6K.js → SessionSwitcherDropdown-AVghToww.js} +2 -2
  11. package/dist/assets/{SessionUnreadDot-BdSDgvhC.js → SessionUnreadDot-CDRZswx-.js} +1 -1
  12. package/dist/assets/SettingsView-hyAGp836.js +2 -0
  13. package/dist/assets/SettingsWindow-BfPUzBbq.js +1 -0
  14. package/dist/assets/{ToolOutputDialog-DaF1xcM0.js → ToolOutputDialog-CJ87b80H.js} +5 -5
  15. package/dist/assets/{ToolPartDiffPreview-Di6Uo0Dt.js → ToolPartDiffPreview-bF486Lz1.js} +1 -1
  16. package/dist/assets/{VirtualizedFileDiff-wqcrY0yr.js → VirtualizedFileDiff-CFpvcZ1g.js} +1 -1
  17. package/dist/assets/{collapsible-DBQnXTNm.js → collapsible-DesjbW8a.js} +1 -1
  18. package/dist/assets/{computeVirtualFileMetrics-Cr3jh0d6.js → computeVirtualFileMetrics-CsAu9rOt.js} +2 -2
  19. package/dist/assets/{contextFileOpenGuard-C_AOTYQD.js → contextFileOpenGuard-rILslsBJ.js} +1 -1
  20. package/dist/assets/{gitStatusPredicates-BvPOjeOy.js → gitStatusPredicates-D_31YElh.js} +1 -1
  21. package/dist/assets/index-BXgR2dKM.css +1 -0
  22. package/dist/assets/index-BZpvAhrX.js +8 -0
  23. package/dist/assets/{index-B8Wt2aN3.js → index-CXLVW_GG.js} +1 -1
  24. package/dist/assets/{isDiffPlainText-L9uvgz2F.js → isDiffPlainText-BX609Lau.js} +1 -1
  25. package/dist/assets/{isFilePlainText-C4yk5BOo.js → isFilePlainText-FgBWqu9b.js} +1 -1
  26. package/dist/assets/{main-DCK6lLCo.js → main-C_pL2r_k.js} +2 -2
  27. package/dist/assets/{main-C1OSzD-E.js → main-tv2uysSs.js} +7 -7
  28. package/dist/assets/{markdownCore-Czb_lINQ.js → markdownCore-D3Ibaffd.js} +1 -1
  29. package/dist/assets/{miniChat-CXiSlptL.js → miniChat-B0xQlBzZ.js} +2 -2
  30. package/dist/assets/{mobile-D0HVxiyJ.js → mobile-BmSlVuhn.js} +2 -2
  31. package/dist/assets/renderElectronMiniChatApp-C4xZzAnn.js +2 -0
  32. package/dist/assets/renderMobileApp-Bi8wTGd5.js +11 -0
  33. package/dist/assets/runtimeEndpointReset-B6_gFvBD.js +53 -0
  34. package/dist/assets/{runtimeSurface-vilE4xyj.js → runtimeSurface-egSD9pqj.js} +1 -1
  35. package/dist/assets/{useAppFontEffects-BP07Vl6M.js → useAppFontEffects-C9QQrBIx.js} +104 -104
  36. package/dist/assets/useFilesViewSearch-BTZutbn-.js +7 -0
  37. package/dist/assets/{usePushVisibilityBeacon-CChMvoTL.js → usePushVisibilityBeacon-BZcHxSo-.js} +1 -1
  38. package/dist/assets/useSwitcherItems-Dw5tHQh8.js +1 -0
  39. package/dist/assets/{vendor-codemirror-language-data-BJrrV83E.js → vendor-codemirror-language-data-0f_rLdj_.js} +2 -2
  40. package/dist/assets/{web-components-B5sMa_kC.js → web-components-CYngz9Ml.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/index.js +17 -3
  46. package/server/lib/client-auth/DOCUMENTATION.md +184 -0
  47. package/server/lib/client-auth/live-revocation.test.js +567 -0
  48. package/server/lib/client-auth/principal-tracker.js +383 -0
  49. package/server/lib/client-auth/principal-tracker.test.js +321 -0
  50. package/server/lib/client-auth/remote-clients.js +31 -0
  51. package/server/lib/client-auth/remote-clients.test.js +44 -0
  52. package/server/lib/fs/DOCUMENTATION.md +15 -3
  53. package/server/lib/fs/routes.js +369 -51
  54. package/server/lib/fs/routes.test.js +565 -3
  55. package/server/lib/fs/search.js +74 -29
  56. package/server/lib/pi/event-stream.js +269 -0
  57. package/server/lib/pi/event-stream.test.js +776 -0
  58. package/server/lib/pi/routes.js +132 -28
  59. package/server/lib/pi/routes.test.js +213 -4
  60. package/server/lib/pi/session-daemon/DOCUMENTATION.md +6 -4
  61. package/server/lib/pi/session-daemon/ipc-client.js +19 -15
  62. package/server/lib/pi/session-daemon/ipc-client.test.js +113 -1
  63. package/server/lib/pi/session-daemon/prompt-operations.test.js +9 -3
  64. package/server/lib/pi/session-daemon/prompt-preflight.test.js +556 -0
  65. package/server/lib/pi/session-daemon/send-operation-dedup.test.js +331 -0
  66. package/server/lib/pi/session-daemon/send-operation-registry.js +264 -0
  67. package/server/lib/pi/session-daemon/send-operation-registry.test.js +205 -0
  68. package/server/lib/pi/session-daemon/session-daemon-epoch.test.js +349 -0
  69. package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +16 -5
  70. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +3 -1
  71. package/server/lib/pi/session-daemon/session-daemon.js +339 -37
  72. package/server/lib/pi/session-daemon/session-daemon.test.js +47 -17
  73. package/server/lib/pi/session-daemon/session-idle-residency.test.js +8 -1
  74. package/server/lib/pi/session-daemon/session-replay.test.js +11 -4
  75. package/server/lib/pi/session-daemon/supervisor.js +30 -5
  76. package/server/lib/pi/session-daemon/supervisor.test.js +4 -3
  77. package/server/lib/pi/ui-settings-store.js +1 -1
  78. package/server/lib/pi/ui-settings-store.test.js +3 -1
  79. package/server/lib/server/core-routes.js +11 -1
  80. package/server/lib/server/cors.js +6 -0
  81. package/server/lib/server/cors.test.js +3 -0
  82. package/server/lib/stt/DOCUMENTATION.md +2 -0
  83. package/server/lib/stt/runtime.js +39 -2
  84. package/server/lib/stt/runtime.test.js +53 -0
  85. package/server/lib/terminal/DOCUMENTATION.md +2 -0
  86. package/server/lib/terminal/runtime.js +48 -2
  87. package/server/lib/terminal/runtime.test.js +35 -0
  88. package/server/lib/ui-auth/DOCUMENTATION.md +13 -4
  89. package/server/lib/ui-auth/ui-auth.js +98 -0
  90. package/server/lib/ui-auth/ui-auth.test.js +249 -0
  91. package/server/lib/workspace/host.js +9 -3
  92. package/server/lib/workspace/host.test.js +15 -0
  93. package/dist/assets/DiagramEditor-BPDkGHsj.js +0 -1
  94. package/dist/assets/DiagramView-D_EfDz2d.js +0 -1
  95. package/dist/assets/FilesView-CJytSUAX.js +0 -6
  96. package/dist/assets/SettingsView-z8uf0XyM.js +0 -2
  97. package/dist/assets/SettingsWindow-CPDmgNg2.js +0 -1
  98. package/dist/assets/index-DIF8b4bh.css +0 -1
  99. package/dist/assets/index-jrfQYSvP.js +0 -8
  100. package/dist/assets/renderElectronMiniChatApp-BcG209a4.js +0 -2
  101. package/dist/assets/renderMobileApp-B5x_PWlc.js +0 -11
  102. package/dist/assets/runtimeEndpointReset-CUiPe6dQ.js +0 -53
  103. package/dist/assets/useFilesViewSearch-oxIKk-ea.js +0 -7
  104. package/dist/assets/useSwitcherItems-_RSo3F-A.js +0 -1
@@ -0,0 +1,321 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import {
3
+ MAX_LIVE_CONNECTIONS_GLOBAL,
4
+ MAX_LIVE_CONNECTIONS_PER_PRINCIPAL,
5
+ MAX_REMEMBERED_REVOKED_CLIENTS,
6
+ createPrincipalTracker,
7
+ createRevocationCoordinator,
8
+ } from './principal-tracker.js';
9
+
10
+ describe('principal tracker', () => {
11
+ it('closes only the revoked principal connections and reports the count', () => {
12
+ const tracker = createPrincipalTracker();
13
+ const closedA = [];
14
+ const closedB = [];
15
+ tracker.track({ principal: 'client:a', close: (reason) => closedA.push(reason) });
16
+ tracker.track({ principal: 'client:a', close: (reason) => closedA.push(reason) });
17
+ tracker.track({ principal: 'client:b', close: (reason) => closedB.push(reason) });
18
+
19
+ expect(tracker.size).toBe(3);
20
+ expect(tracker.countPrincipal('client:a')).toBe(2);
21
+ expect(tracker.closePrincipal('client:a', 'credential-revoked')).toBe(2);
22
+
23
+ expect(closedA).toEqual(['credential-revoked', 'credential-revoked']);
24
+ expect(closedB).toEqual([]);
25
+ expect(tracker.size).toBe(1);
26
+ expect(tracker.closePrincipal('client:a', 'credential-revoked')).toBe(0);
27
+ expect(tracker.closePrincipal('client:missing')).toBe(0);
28
+ });
29
+
30
+ it('detaches entries when connections end naturally and keeps revoke idempotent', () => {
31
+ const tracker = createPrincipalTracker();
32
+ const closed = [];
33
+ const entry = tracker.track({ principal: 'client:a', close: (reason) => closed.push(reason) });
34
+
35
+ entry.end();
36
+ expect(tracker.countPrincipal('client:a')).toBe(0);
37
+ expect(entry.revoke('late')).toBe(false);
38
+ expect(closed).toEqual([]);
39
+
40
+ const revoked = tracker.track({ principal: 'client:b', close: () => {} });
41
+ expect(revoked.revoke('credential-revoked')).toBe(true);
42
+ expect(revoked.revoke('credential-revoked')).toBe(false);
43
+ expect(revoked.end()).toBeUndefined();
44
+ expect(tracker.size).toBe(0);
45
+ });
46
+
47
+ it('isolates a failing close so other principals still close', () => {
48
+ const errors = [];
49
+ const tracker = createPrincipalTracker({ onCloseError: ({ error }) => errors.push(error) });
50
+ const closed = [];
51
+ tracker.track({ principal: 'client:bad', close: () => { throw new Error('destroy failed'); } });
52
+ tracker.track({ principal: 'client:good', close: (reason) => closed.push(reason) });
53
+
54
+ expect(tracker.closeAll('shutdown')).toBe(2);
55
+ expect(closed).toEqual(['shutdown']);
56
+ expect(errors).toHaveLength(1);
57
+ expect(errors[0]).toBeInstanceOf(Error);
58
+ expect(tracker.size).toBe(0);
59
+ });
60
+
61
+ it('closeAll reports every tracked principal and empties the index', () => {
62
+ const tracker = createPrincipalTracker();
63
+ tracker.track({ principal: 'client:a', close: () => {} });
64
+ tracker.track({ principal: 'client:b', close: () => {} });
65
+ tracker.track({ principal: 'session-jwt-1', close: () => {} });
66
+ expect([...tracker.principals()].sort()).toEqual(['client:a', 'client:b', 'session-jwt-1']);
67
+ expect(tracker.closeAll('signout-everywhere')).toBe(3);
68
+ expect(tracker.size).toBe(0);
69
+ });
70
+
71
+ it('rejects tracking without a principal or close callback', () => {
72
+ const tracker = createPrincipalTracker();
73
+ expect(() => tracker.track({ principal: '', close: () => {} })).toThrow();
74
+ expect(() => tracker.track({ principal: 'client:a' })).toThrow();
75
+ });
76
+ });
77
+
78
+ describe('revocation coordinator', () => {
79
+ it('closes the revoked principal connections immediately on the in-process path', () => {
80
+ const closed = [];
81
+ const coordinator = createRevocationCoordinator({ listRevokedClientIds: async () => [] });
82
+ coordinator.trackLiveConnection({ principal: 'client:dev-1', close: (reason) => closed.push(reason) });
83
+ coordinator.trackLiveConnection({ principal: 'client:dev-2', close: () => closed.push('other') });
84
+
85
+ expect(coordinator.clientRevoked('dev-1')).toBe(1);
86
+ expect(coordinator.clientRevoked('unknown-device')).toBe(0);
87
+ expect(closed).toEqual(['credential-revoked']);
88
+ expect(coordinator.liveConnectionCount).toBe(1);
89
+ });
90
+
91
+ it('converges with cross-process revocations through the bounded poll', async () => {
92
+ let revokedIds = [];
93
+ const polls = { count: 0 };
94
+ const coordinator = createRevocationCoordinator({
95
+ listRevokedClientIds: async () => {
96
+ polls.count += 1;
97
+ return revokedIds;
98
+ },
99
+ pollIntervalMs: 5,
100
+ setIntervalFn: (fn, ms) => setInterval(fn, ms),
101
+ clearIntervalFn: (handle) => clearInterval(handle),
102
+ });
103
+ const closed = [];
104
+ coordinator.trackLiveConnection({ principal: 'client:dev-1', close: (reason) => closed.push(reason) });
105
+ coordinator.start();
106
+
107
+ // Simulate a revocation committed by another process sharing the store.
108
+ revokedIds = ['dev-1'];
109
+ await new Promise((resolve) => setTimeout(resolve, 40));
110
+
111
+ expect(polls.count).toBeGreaterThan(0);
112
+ expect(closed).toEqual(['credential-revoked']);
113
+ await coordinator.dispose();
114
+ });
115
+
116
+ it('keeps previous state when a poll fails and recovers on the next tick', async () => {
117
+ let shouldFail = false;
118
+ let revokedIds = [];
119
+ const coordinator = createRevocationCoordinator({
120
+ listRevokedClientIds: async () => {
121
+ if (shouldFail) throw new Error('store read failed');
122
+ return revokedIds;
123
+ },
124
+ pollIntervalMs: 5,
125
+ setIntervalFn: (fn, ms) => setInterval(fn, ms),
126
+ clearIntervalFn: (handle) => clearInterval(handle),
127
+ });
128
+ const closed = [];
129
+ coordinator.trackLiveConnection({ principal: 'client:dev-1', close: (reason) => closed.push(reason) });
130
+ coordinator.start();
131
+
132
+ shouldFail = true;
133
+ await new Promise((resolve) => setTimeout(resolve, 25));
134
+ expect(closed).toEqual([]);
135
+
136
+ shouldFail = false;
137
+ revokedIds = ['dev-1'];
138
+ await new Promise((resolve) => setTimeout(resolve, 25));
139
+ expect(closed).toEqual(['credential-revoked']);
140
+ await coordinator.dispose();
141
+ });
142
+
143
+ it('dispose stops polling and closes remaining connections synchronously', async () => {
144
+ let polls = 0;
145
+ const coordinator = createRevocationCoordinator({
146
+ listRevokedClientIds: async () => {
147
+ polls += 1;
148
+ return [];
149
+ },
150
+ pollIntervalMs: 5,
151
+ setIntervalFn: (fn, ms) => setInterval(fn, ms),
152
+ clearIntervalFn: (handle) => clearInterval(handle),
153
+ });
154
+ coordinator.trackLiveConnection({ principal: 'client:dev-1', close: () => {} });
155
+ coordinator.start();
156
+ await new Promise((resolve) => setTimeout(resolve, 20));
157
+ expect(coordinator.dispose({ closeConnections: true })).toBe(1);
158
+ expect(coordinator.liveConnectionCount).toBe(0);
159
+
160
+ const pollsAfterDispose = polls;
161
+ await new Promise((resolve) => setTimeout(resolve, 20));
162
+ expect(polls).toBe(pollsAfterDispose);
163
+ });
164
+
165
+ it('dispose without closeConnections leaves tracked connections in place', () => {
166
+ const coordinator = createRevocationCoordinator({ listRevokedClientIds: async () => [] });
167
+ coordinator.trackLiveConnection({ principal: 'client:dev-1', close: () => {} });
168
+ coordinator.dispose({ closeConnections: false });
169
+ expect(coordinator.liveConnectionCount).toBe(1);
170
+ });
171
+
172
+ it('requires a listRevokedClientIds implementation', () => {
173
+ expect(() => createRevocationCoordinator({})).toThrow();
174
+ });
175
+ });
176
+
177
+ describe('principal tracker resource bounds', () => {
178
+ it('reject-closes a new connection beyond the per-principal bound without evicting unrelated entries', () => {
179
+ const tracker = createPrincipalTracker({ maxPerPrincipal: 2, maxTotal: 10 });
180
+ const closedA = [];
181
+ const closedB = [];
182
+ tracker.track({ principal: 'client:a', close: () => {} });
183
+ tracker.track({ principal: 'client:a', close: () => {} });
184
+ tracker.track({ principal: 'client:b', close: (reason) => closedB.push(reason) });
185
+
186
+ const rejected = tracker.track({ principal: 'client:a', close: (reason) => closedA.push(reason) });
187
+ expect(rejected.active).toBe(false);
188
+ expect(closedA).toEqual(['over-limit']);
189
+ expect(rejected.revoke('late')).toBe(false);
190
+ rejected.end();
191
+ // Unrelated entries are untouched: A keeps 2, B keeps 1.
192
+ expect(tracker.countPrincipal('client:a')).toBe(2);
193
+ expect(tracker.countPrincipal('client:b')).toBe(1);
194
+ expect(tracker.size).toBe(3);
195
+ expect(closedB).toEqual([]);
196
+ });
197
+
198
+ it('reject-closes a new connection beyond the global bound without evicting unrelated entries', () => {
199
+ const tracker = createPrincipalTracker({ maxPerPrincipal: 10, maxTotal: 2 });
200
+ tracker.track({ principal: 'client:a', close: () => {} });
201
+ tracker.track({ principal: 'client:b', close: () => {} });
202
+ const closed = [];
203
+ const rejected = tracker.track({ principal: 'client:c', close: (reason) => closed.push(reason) });
204
+ expect(rejected.active).toBe(false);
205
+ expect(closed).toEqual(['over-limit']);
206
+ expect(tracker.size).toBe(2);
207
+ expect(tracker.countPrincipal('client:a')).toBe(1);
208
+ expect(tracker.countPrincipal('client:b')).toBe(1);
209
+ });
210
+
211
+ it('exposes the configured bounds and defaults', () => {
212
+ const tracker = createPrincipalTracker();
213
+ expect(tracker.maxPerPrincipal).toBe(MAX_LIVE_CONNECTIONS_PER_PRINCIPAL);
214
+ expect(tracker.maxTotal).toBe(MAX_LIVE_CONNECTIONS_GLOBAL);
215
+ const coordinator = createRevocationCoordinator({ listRevokedClientIds: async () => [] });
216
+ expect(coordinator.maxRevoked).toBe(MAX_REMEMBERED_REVOKED_CLIENTS);
217
+ coordinator.dispose({ closeConnections: false });
218
+ });
219
+
220
+ it('disposed tracker reject-closes new registrations', () => {
221
+ const tracker = createPrincipalTracker();
222
+ tracker.track({ principal: 'client:a', close: () => {} });
223
+ expect(tracker.dispose('shutdown')).toBe(1);
224
+ expect(tracker.disposed).toBe(true);
225
+ const closed = [];
226
+ const rejected = tracker.track({ principal: 'client:b', close: (reason) => closed.push(reason) });
227
+ expect(rejected.active).toBe(false);
228
+ expect(closed).toEqual(['shutdown']);
229
+ expect(tracker.size).toBe(0);
230
+ });
231
+ });
232
+
233
+ describe('revocation coordinator verify-registration barrier', () => {
234
+ it('rejects a late client registration that races revocation (no poll involved)', () => {
235
+ const coordinator = createRevocationCoordinator({ listRevokedClientIds: async () => [] });
236
+ // Verification passed, then the revoke commits+closes before track.
237
+ expect(coordinator.clientRevoked('dev-1')).toBe(0);
238
+ expect(coordinator.isClientRevoked('dev-1')).toBe(true);
239
+ const closed = [];
240
+ const late = coordinator.trackLiveConnection({
241
+ principal: 'client:dev-1',
242
+ close: (reason) => closed.push(reason),
243
+ });
244
+ expect(late.active).toBe(false);
245
+ expect(closed).toEqual(['credential-revoked']);
246
+ expect(coordinator.liveConnectionCount).toBe(0);
247
+ expect(late.revoke('late')).toBe(false);
248
+ coordinator.dispose({ closeConnections: false });
249
+ });
250
+
251
+ it('rejects a stale-generation registration after global invalidation without trusting the principal', () => {
252
+ const coordinator = createRevocationCoordinator({ listRevokedClientIds: async () => [] });
253
+ const generation = coordinator.getGeneration();
254
+ // A global sign-out commits between verify and track.
255
+ expect(coordinator.revokeAllLive('signout-everywhere')).toBe(0);
256
+ const closed = [];
257
+ const late = coordinator.trackLiveConnection({
258
+ principal: 'session-jwt-old',
259
+ close: (reason) => closed.push(reason),
260
+ generation,
261
+ });
262
+ expect(late.active).toBe(false);
263
+ expect(closed).toEqual(['global-invalidation']);
264
+ // A registration verified AFTER the invalidation carries the new
265
+ // generation and is tracked normally.
266
+ const fresh = coordinator.trackLiveConnection({
267
+ principal: 'session-jwt-new',
268
+ close: () => {},
269
+ generation: coordinator.getGeneration(),
270
+ });
271
+ expect(fresh.active).toBe(true);
272
+ expect(coordinator.liveConnectionCount).toBe(1);
273
+ coordinator.dispose();
274
+ });
275
+
276
+ it('reject-closes beyond coordinator bounds without evicting unrelated principals', () => {
277
+ const coordinator = createRevocationCoordinator({
278
+ listRevokedClientIds: async () => [],
279
+ maxPerPrincipal: 1,
280
+ maxTotal: 10,
281
+ });
282
+ coordinator.trackLiveConnection({ principal: 'client:a', close: () => {} });
283
+ const closed = [];
284
+ const rejected = coordinator.trackLiveConnection({
285
+ principal: 'client:a',
286
+ close: (reason) => closed.push(reason),
287
+ });
288
+ expect(rejected.active).toBe(false);
289
+ expect(closed).toEqual(['over-limit']);
290
+ expect(coordinator.countPrincipal('client:a')).toBe(1);
291
+ coordinator.dispose();
292
+ });
293
+
294
+ it('disposed coordinator reject-closes new registrations', () => {
295
+ const coordinator = createRevocationCoordinator({ listRevokedClientIds: async () => [] });
296
+ coordinator.dispose({ closeConnections: false });
297
+ const closed = [];
298
+ const rejected = coordinator.trackLiveConnection({
299
+ principal: 'client:a',
300
+ close: (reason) => closed.push(reason),
301
+ });
302
+ expect(rejected.active).toBe(false);
303
+ expect(closed).toEqual(['shutdown']);
304
+ });
305
+
306
+ it('bounds remembered revoked IDs with FIFO eviction', () => {
307
+ const coordinator = createRevocationCoordinator({
308
+ listRevokedClientIds: async () => [],
309
+ maxRevoked: 2,
310
+ });
311
+ coordinator.clientRevoked('a');
312
+ coordinator.clientRevoked('b');
313
+ expect(coordinator.getRevokedCount()).toBe(2);
314
+ coordinator.clientRevoked('c');
315
+ expect(coordinator.getRevokedCount()).toBe(2);
316
+ expect(coordinator.isClientRevoked('a')).toBe(false);
317
+ expect(coordinator.isClientRevoked('b')).toBe(true);
318
+ expect(coordinator.isClientRevoked('c')).toBe(true);
319
+ coordinator.dispose({ closeConnections: false });
320
+ });
321
+ });
@@ -245,6 +245,35 @@ export const createRemoteClientAuthRuntime = ({ fsPromises, path, crypto, storeP
245
245
  });
246
246
  };
247
247
 
248
+ // Establishment-time principal validation for credentials that cannot be
249
+ // re-checked from their bearer form — the encrypted URL token embeds the
250
+ // principal, so revocation must be re-checked against the store whenever
251
+ // such a token is used to establish a connection. This closes the
252
+ // mint/open race: a URL token minted moments before revocation is denied
253
+ // at open time even though its 60-second TTL has not elapsed.
254
+ const isClientValid = async (id) => {
255
+ if (typeof id !== 'string' || id.trim().length === 0) return false;
256
+ return withStoreMutation(async () => {
257
+ const store = await readStore();
258
+ const client = store.clients.find((entry) => entry.id === id);
259
+ if (!client || client.revokedAt) return false;
260
+ const expires = Date.parse(client.expiresAt || '');
261
+ return !Number.isFinite(expires) || expires > Date.now();
262
+ });
263
+ };
264
+
265
+ // Cross-process revocation propagation surface: the credential store is a
266
+ // file shared with other processes (pairing CLI), so a second process
267
+ // cannot emit revocations here. The live-revocation coordinator polls this
268
+ // bounded list and closes affected connections; a failed read must be
269
+ // retried by the caller, not treated as an authoritative empty result.
270
+ const listRevokedClientIds = async () => {
271
+ return withStoreMutation(async () => {
272
+ const store = await readStore();
273
+ return store.clients.filter((entry) => entry.revokedAt).map((entry) => entry.id);
274
+ });
275
+ };
276
+
248
277
  const authenticateBearerToken = async (token, req) => {
249
278
  if (typeof token !== 'string' || !token.startsWith(TOKEN_PREFIX)) {
250
279
  return null;
@@ -287,5 +316,7 @@ export const createRemoteClientAuthRuntime = ({ fsPromises, path, crypto, storeP
287
316
  hasActiveRelayClients,
288
317
  purgeRevokedClients,
289
318
  revokeClient,
319
+ isClientValid,
320
+ listRevokedClientIds,
290
321
  };
291
322
  };
@@ -155,4 +155,48 @@ describe('remote client auth runtime', () => {
155
155
  await fs.rm(dir, { recursive: true, force: true });
156
156
  }
157
157
  });
158
+
159
+ it('validates client principals for URL-token establishment after revocation or expiry', async () => {
160
+ const { dir, runtime } = await createRuntime();
161
+ try {
162
+ const created = await runtime.createClient({ label: 'Phone' });
163
+ expect(await runtime.isClientValid(created.client.id)).toBe(true);
164
+
165
+ // Revoked principals are denied even though a URL token minted before
166
+ // revocation still decrypts (the mint/open race).
167
+ await runtime.revokeClient(created.client.id);
168
+ expect(await runtime.isClientValid(created.client.id)).toBe(false);
169
+
170
+ // Expired principals are establishment-denied as well.
171
+ const expired = await runtime.createClient({ label: 'Old', expiresAt: '2000-01-01T00:00:00.000Z' });
172
+ expect(await runtime.isClientValid(expired.client.id)).toBe(false);
173
+
174
+ expect(await runtime.isClientValid('missing-id')).toBe(false);
175
+ expect(await runtime.isClientValid('')).toBe(false);
176
+ expect(await runtime.isClientValid(undefined)).toBe(false);
177
+ } finally {
178
+ await fs.rm(dir, { recursive: true, force: true });
179
+ }
180
+ });
181
+
182
+ it('lists revoked client ids for cross-process revocation propagation', async () => {
183
+ const { dir, runtime } = await createRuntime();
184
+ try {
185
+ const first = await runtime.createClient({ label: 'Phone' });
186
+ const second = await runtime.createClient({ label: 'Tablet' });
187
+ expect(await runtime.listRevokedClientIds()).toEqual([]);
188
+
189
+ await runtime.revokeClient(first.client.id);
190
+ expect(await runtime.listRevokedClientIds()).toEqual([first.client.id]);
191
+
192
+ await runtime.revokeClient(second.client.id);
193
+ expect((await runtime.listRevokedClientIds()).sort()).toEqual([first.client.id, second.client.id].sort());
194
+
195
+ // Purge removes the entries; the list stays bounded by the store.
196
+ await runtime.purgeRevokedClients();
197
+ expect(await runtime.listRevokedClientIds()).toEqual([]);
198
+ } finally {
199
+ await fs.rm(dir, { recursive: true, force: true });
200
+ }
201
+ });
158
202
  });
@@ -5,7 +5,7 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
5
5
 
6
6
  ## Entrypoints and structure
7
7
  - `packages/web/server/lib/fs/routes.js`: route registration and runtime-owned state for `/api/fs/*` endpoints.
8
- - `packages/web/server/lib/fs/search.js`: fuzzy filesystem search runtime used by non-FS routes (for example project icon discovery).
8
+ - `packages/web/server/lib/fs/search.js`: bounded-concurrency fuzzy filesystem search runtime used by `GET /api/fs/find`.
9
9
 
10
10
  ## Public exports
11
11
  - `registerFsRoutes(app, dependencies)` from `routes.js`
@@ -14,6 +14,7 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
14
14
  - `POST /api/fs/mkdir`
15
15
  - `POST /api/fs/clone`
16
16
  - `GET /api/fs/read`
17
+ - `GET /api/fs/stat`
17
18
  - `GET /api/fs/raw`
18
19
  - `GET /api/fs/serve/:path(*)`
19
20
  - `POST /api/fs/write`
@@ -23,11 +24,22 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
23
24
  - `POST /api/fs/exec`
24
25
  - `GET /api/fs/exec/:jobId`
25
26
  - `GET /api/fs/list`
27
+ - `GET /api/fs/find`
26
28
  - Owns exec job queue state (`execJobs`) and lifecycle/TTL pruning.
27
29
  - Enforces workspace boundary checks with active project + worktree fallback support. An explicit `directory` query is authoritative over a stale runtime directory header, which lets user-confirmed directory-browser operations and project-local optional configuration probes scope themselves to the selected directory. `optional=true` converts only a missing file to an empty success; it never bypasses workspace policy.
28
- - `createFsSearchRuntime({ fsPromises, path, spawn, resolveGitBinaryForSpawn })` from `search.js`
30
+ - `createFsSearchRuntime({ fsPromises, path, spawn, resolveGitBinaryForSpawn, gitCheckIgnoreTimeoutMs })` from `search.js`
29
31
  - Returns `{ searchFilesystemFiles(rootPath, options) }`.
30
- - Supports fuzzy matching, hidden-file handling, and optional `git check-ignore` filtering.
32
+ - Supports fuzzy file and directory matching, hidden-file handling, fixed build-output exclusions, and optional `git check-ignore` filtering.
33
+ - Git-ignore checks use bounded directory concurrency and a positive configurable timeout (`PICHAMBER_GIT_CHECK_IGNORE_TIMEOUT_MS`, default 2500 ms). Concurrent searches share identical in-flight checks. A failed or timed-out check fails the search instead of returning files that may be ignored.
34
+ - Search reads through canonical paths for boundary enforcement, but result paths stay in the caller's requested path space so symlinked workspaces remain navigable.
35
+
36
+ ## File-save revisions (finding #8)
37
+ - Revisions are opaque exact strings (`v1:<size>:<mtimeMs>[:<sha256>]`, 5 MiB hash ceiling). `null` means missing at read time; `undefined` means legacy/unknown and never guards a save.
38
+ - `GET /api/fs/read` returns `x-pichamber-file-revision` plus `Cache-Control: no-store`; optional missing reads also return `x-pichamber-file-exists: false`. The server CORS policy exposes both headers so HMR, packaged desktop, and Capacitor clients retain revision authority across origins.
39
+ - `GET /api/fs/stat` returns `{ revision, exists }` and accepts `?knownRevision=` to echo the client revision when size+mtime (and hash-ceiling category) match, skipping read+hash.
40
+ - `POST /api/fs/write` accepts `{ expectedRevision, overwrite }`. Omitting `expectedRevision` keeps legacy unconditional writes. `expectedRevision: null` (or `'missing'`) is create-only. `overwrite: true` is the explicit force path. Mismatches return HTTP 409 `{ reason: 'file-revision-conflict', currentRevision, exists, path }`. Identical content is an idempotent `{ noop: true }` success without rewrite. Writes serialize per canonical (realpath) file with re-keying for create/re-point races, preserve mode across atomic temp+rename, and never normalize line endings.
41
+ - External writers that bypass the protocol are non-cooperating: last writer wins on disk, and the next cooperating save conflicts instead of silently overwriting.
42
+ - The exact `~` global-session sentinel resolves to the server user's home directory before workspace validation. Other relative paths keep normal server-cwd resolution.
31
43
 
32
44
  ## Composition contract with `index.js`
33
45
  - `index.js` provides composition-time dependencies only (platform primitives + callbacks such as `resolveProjectDirectory`, `normalizeDirectoryPath`, and `buildAugmentedPath`).