@wherever-dev/client 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +63 -0
  3. package/dist/client.js +2 -0
  4. package/dist/client.js.map +1 -1
  5. package/dist/types.d.ts +1 -0
  6. package/dist/types.js.map +1 -1
  7. package/package.json +23 -3
  8. package/src/client.ts +2 -0
  9. package/src/types.ts +3 -0
  10. package/test/agent-pending.test.ts +0 -107
  11. package/test/chunked-upload.test.ts +0 -483
  12. package/test/conversation-mode-flag.test.ts +0 -111
  13. package/test/creating-session-watchdog.test.ts +0 -82
  14. package/test/folder-conflict-read-only.test.ts +0 -145
  15. package/test/folder-missing-read-only.test.ts +0 -114
  16. package/test/harness.ts +0 -133
  17. package/test/hydration-seam.test.ts +0 -400
  18. package/test/liveness-probe.test.ts +0 -183
  19. package/test/message-delivery-confirmation.test.ts +0 -320
  20. package/test/mid-stream-steer.test.ts +0 -91
  21. package/test/new-session-clone-progress.test.ts +0 -263
  22. package/test/optimistic-force-command.test.ts +0 -127
  23. package/test/queued-steer-restored.test.ts +0 -175
  24. package/test/reconnect-rejoins-session.test.ts +0 -136
  25. package/test/restore-panel.test.ts +0 -324
  26. package/test/resume-keeps-session.test.ts +0 -118
  27. package/test/session-load-by-id.test.ts +0 -100
  28. package/test/session-reload.test.ts +0 -82
  29. package/test/skills-autocomplete.test.ts +0 -113
  30. package/test/steer-queue-cancel.test.ts +0 -130
  31. package/test/superseded-connection-key.test.ts +0 -70
  32. package/test/superseded-session-load.test.ts +0 -180
  33. package/test/tool-aborted-render.test.ts +0 -170
  34. package/test/tool-duration-history.test.ts +0 -93
  35. package/test/tool-duration.test.ts +0 -86
  36. package/test/tool-interrupted-history.test.ts +0 -294
  37. package/test/upload-survives-reconnect.test.ts +0 -482
  38. package/tsconfig.json +0 -16
@@ -1,93 +0,0 @@
1
- import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
2
- import {get} from 'sveltore';
3
- import {WhereverClient} from '../src/client.js';
4
- import type {WhereverState} from '../src/types.js';
5
- import {makeWSFactory} from './harness.js';
6
-
7
- // A tool call reconstructed from LOADED history must carry the same duration as
8
- // a live-streamed one, so "Took N.Ns" survives a reload. The server sends the
9
- // tool_call and tool_result as separate HistoryMessages, each with its own
10
- // timestamp; the client pairs them and computes startedAt/endedAt.
11
-
12
- describe('tool duration from loaded history', () => {
13
- let ws: ReturnType<typeof makeWSFactory>;
14
- let client: WhereverClient;
15
- const state = () => get<WhereverState>(client.stateStore);
16
-
17
- beforeEach(() => {
18
- vi.useFakeTimers();
19
- ws = makeWSFactory();
20
- client = new WhereverClient({
21
- host: 'localhost',
22
- port: 1234,
23
- secure: false,
24
- WebSocketCtor: ws.ctor,
25
- });
26
- client.connect();
27
- ws.last().open();
28
- client.joinSession('/tmp/project/session.jsonl');
29
- ws.last().receive({
30
- type: 'session_created',
31
- sessionId: 'sid-1',
32
- sessionFile: '/tmp/project/session.jsonl',
33
- cwd: '/tmp/project',
34
- model: 'fake:model',
35
- isStreaming: false,
36
- });
37
- });
38
-
39
- afterEach(() => {
40
- client.disconnect(true);
41
- vi.useRealTimers();
42
- });
43
-
44
- it('pairs a tool_call + tool_result into a duration', () => {
45
- ws.last().receive({
46
- type: 'message_history',
47
- sessionId: 'sid-1',
48
- messages: [
49
- {role: 'user', content: 'go', timestamp: 1_000},
50
- {
51
- role: 'tool_call',
52
- content: '{"command":"ls"}',
53
- timestamp: 10_000,
54
- toolName: 'bash',
55
- },
56
- {
57
- role: 'tool_result',
58
- content: 'a\nb',
59
- timestamp: 13_400,
60
- toolName: 'bash',
61
- isError: false,
62
- },
63
- ],
64
- totalCount: 3,
65
- offset: 0,
66
- });
67
-
68
- const tool = state().messages.find((m) => m.role === 'tool')!;
69
- expect(tool.startedAt).toBe(10_000);
70
- expect(tool.endedAt).toBe(13_400);
71
- expect(((tool.endedAt! - tool.startedAt!) / 1000).toFixed(1)).toBe('3.4');
72
- });
73
-
74
- it('leaves duration unset for an unmatched (result-less) tool_call', () => {
75
- ws.last().receive({
76
- type: 'message_history',
77
- sessionId: 'sid-1',
78
- messages: [
79
- {
80
- role: 'tool_call',
81
- content: '{}',
82
- timestamp: 10_000,
83
- toolName: 'bash',
84
- },
85
- ],
86
- totalCount: 1,
87
- offset: 0,
88
- });
89
- const tool = state().messages.find((m) => m.role === 'tool')!;
90
- expect(tool.startedAt).toBe(10_000);
91
- expect(tool.endedAt).toBeUndefined();
92
- });
93
- });
@@ -1,86 +0,0 @@
1
- import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
2
- import {get} from 'sveltore';
3
- import {WhereverClient} from '../src/client.js';
4
- import type {WhereverState} from '../src/types.js';
5
-
6
- // The tool-call timing the UI needs to show "Elapsed N.Ns" (running) and
7
- // "Took N.Ns" (done), like the pi CLI: tool_start stamps startedAt, tool_end
8
- // stamps endedAt, and a turn that ends without a tool_end freezes the running
9
- // tool's endedAt so its duration stops ticking.
10
-
11
- function makeClient() {
12
- const c = new WhereverClient({host: 'x', port: 1, secure: false});
13
- const feed = (msg: unknown) =>
14
- (c as unknown as {handleMessage(m: unknown): void}).handleMessage(msg);
15
- const state = () => get<WhereverState>(c.stateStore);
16
- const lastTool = () =>
17
- [...state().messages].reverse().find((m) => m.role === 'tool');
18
- return {feed, state, lastTool};
19
- }
20
-
21
- const SESSION = 'sess-1';
22
-
23
- beforeEach(() => vi.useFakeTimers());
24
- afterEach(() => {
25
- vi.clearAllTimers();
26
- vi.useRealTimers();
27
- });
28
-
29
- describe('tool call timing', () => {
30
- it('stamps startedAt on tool_start and endedAt on tool_end', () => {
31
- const {feed, lastTool} = makeClient();
32
- feed({type: 'agent_start', sessionId: SESSION});
33
-
34
- vi.setSystemTime(1_000);
35
- feed({
36
- type: 'tool_start',
37
- sessionId: SESSION,
38
- toolName: 'bash',
39
- args: {command: 'ls'},
40
- });
41
- const running = lastTool()!;
42
- expect(running.startedAt).toBe(1_000);
43
- expect(running.endedAt).toBeUndefined();
44
- expect(running.isStreaming).toBe(true);
45
-
46
- vi.setSystemTime(3_500);
47
- feed({type: 'tool_end', sessionId: SESSION, toolName: 'bash', result: 'a\nb'});
48
- const done = lastTool()!;
49
- expect(done.startedAt).toBe(1_000);
50
- expect(done.endedAt).toBe(3_500);
51
- expect(done.isStreaming).toBe(false);
52
- // 2.5s took.
53
- expect(((done.endedAt! - done.startedAt!) / 1000).toFixed(1)).toBe('2.5');
54
- });
55
-
56
- it('freezes a running tool endedAt when the turn ends without tool_end', () => {
57
- const {feed, lastTool} = makeClient();
58
- feed({type: 'agent_start', sessionId: SESSION});
59
- vi.setSystemTime(1_000);
60
- feed({type: 'tool_start', sessionId: SESSION, toolName: 'bash', args: {}});
61
- expect(lastTool()!.endedAt).toBeUndefined();
62
-
63
- // Turn ends between steps with no tool_end for the running tool.
64
- vi.setSystemTime(2_000);
65
- feed({type: 'agent_end', sessionId: SESSION});
66
- // The 300ms agent_end debounce fires; fake time advances to 2_300 and the
67
- // callback stamps endedAt = Date.now() at that point.
68
- vi.advanceTimersByTime(300);
69
-
70
- const frozen = lastTool()!;
71
- expect(frozen.isStreaming).toBe(false);
72
- expect(frozen.endedAt).toBe(2_300);
73
- });
74
-
75
- it('freezes a running tool endedAt on abort', () => {
76
- const {feed, lastTool} = makeClient();
77
- feed({type: 'agent_start', sessionId: SESSION});
78
- vi.setSystemTime(1_000);
79
- feed({type: 'tool_start', sessionId: SESSION, toolName: 'bash', args: {}});
80
- vi.setSystemTime(5_000);
81
- feed({type: 'aborted', sessionId: SESSION});
82
- const frozen = lastTool()!;
83
- expect(frozen.isStreaming).toBe(false);
84
- expect(frozen.endedAt).toBe(5_000);
85
- });
86
- });
@@ -1,294 +0,0 @@
1
- import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
2
- import {get} from 'sveltore';
3
- import {WhereverClient} from '../src/client.js';
4
- import type {WhereverState} from '../src/types.js';
5
- import {makeWSFactory} from './harness.js';
6
-
7
- // A tool call with NO matching tool_result in loaded history is ambiguous:
8
- // - if the session is streaming (live tail), the tool is STILL RUNNING;
9
- // - otherwise the call is FROZEN with no result, i.e. it was interrupted
10
- // (e.g. a CLI took over the session and killed the running tool).
11
- // The frozen case must be flagged `interrupted` so the UI shows a neutral
12
- // "no result" state instead of a bogus green success tick.
13
-
14
- function makeClient(ws: ReturnType<typeof makeWSFactory>) {
15
- const client = new WhereverClient({
16
- host: 'localhost',
17
- port: 1234,
18
- secure: false,
19
- WebSocketCtor: ws.ctor,
20
- });
21
- client.connect();
22
- ws.last().open();
23
- client.joinSession('/tmp/project/session.jsonl');
24
- return client;
25
- }
26
-
27
- describe('interrupted (result-less) tool call from loaded history', () => {
28
- let ws: ReturnType<typeof makeWSFactory>;
29
- let client: WhereverClient;
30
- const state = () => get<WhereverState>(client.stateStore);
31
-
32
- beforeEach(() => {
33
- vi.useFakeTimers();
34
- ws = makeWSFactory();
35
- client = makeClient(ws);
36
- });
37
-
38
- afterEach(() => {
39
- client.disconnect(true);
40
- vi.useRealTimers();
41
- });
42
-
43
- it('marks a dangling tool_call as interrupted when the session is NOT streaming', () => {
44
- ws.last().receive({
45
- type: 'session_created',
46
- sessionId: 'sid-1',
47
- sessionFile: '/tmp/project/session.jsonl',
48
- cwd: '/tmp/project',
49
- model: 'fake:model',
50
- isStreaming: false,
51
- });
52
- ws.last().receive({
53
- type: 'message_history',
54
- sessionId: 'sid-1',
55
- messages: [
56
- {role: 'user', content: 'go', timestamp: 1_000},
57
- {
58
- role: 'tool_call',
59
- content: '{"command":"sleep 10"}',
60
- timestamp: 10_000,
61
- toolName: 'bash',
62
- },
63
- ],
64
- totalCount: 2,
65
- offset: 0,
66
- });
67
-
68
- const tool = state().messages.find((m) => m.role === 'tool')!;
69
- expect(tool.interrupted).toBe(true);
70
- expect(tool.isStreaming).toBe(false);
71
- expect(tool.isError).toBeFalsy();
72
- // No result: outcome unknown, so no end timestamp either.
73
- expect(tool.endedAt).toBeUndefined();
74
- });
75
-
76
- it('does NOT mark it interrupted when the session IS streaming (still running)', () => {
77
- ws.last().receive({
78
- type: 'session_created',
79
- sessionId: 'sid-1',
80
- sessionFile: '/tmp/project/session.jsonl',
81
- cwd: '/tmp/project',
82
- model: 'fake:model',
83
- isStreaming: true,
84
- });
85
- ws.last().receive({
86
- type: 'message_history',
87
- sessionId: 'sid-1',
88
- messages: [
89
- {role: 'user', content: 'go', timestamp: 1_000},
90
- {
91
- role: 'tool_call',
92
- content: '{"command":"sleep 10"}',
93
- timestamp: 10_000,
94
- toolName: 'bash',
95
- },
96
- ],
97
- totalCount: 2,
98
- offset: 0,
99
- });
100
-
101
- const tool = state().messages.find((m) => m.role === 'tool')!;
102
- expect(tool.interrupted).toBeFalsy();
103
- expect(tool.isStreaming).toBe(true);
104
- });
105
-
106
- it('renders a dangling mid-conversation tool_call IN PLACE, not hoisted to the end', () => {
107
- // Recoverability case: an interrupted long-running bash call, superseded by
108
- // a new user turn and later assistant replies. The dangling call must stay
109
- // where it was issued (between "start it" and "never mind"), NOT be moved
110
- // below the final reply as a phantom trailing "aborted tool call".
111
- ws.last().receive({
112
- type: 'session_created',
113
- sessionId: 'sid-1',
114
- sessionFile: '/tmp/project/session.jsonl',
115
- cwd: '/tmp/project',
116
- model: 'fake:model',
117
- isStreaming: false,
118
- });
119
- ws.last().receive({
120
- type: 'message_history',
121
- sessionId: 'sid-1',
122
- messages: [
123
- {role: 'user', content: 'start it', timestamp: 1_000},
124
- {
125
- role: 'tool_call',
126
- content: '{"command":"sleep 300"}',
127
- timestamp: 2_000,
128
- toolName: 'bash',
129
- },
130
- {role: 'user', content: 'never mind', timestamp: 3_000},
131
- {role: 'assistant', content: 'ok, stopped', timestamp: 4_000},
132
- {role: 'user', content: 'hello', timestamp: 5_000},
133
- {role: 'assistant', content: 'hi there', timestamp: 6_000},
134
- ],
135
- totalCount: 6,
136
- offset: 0,
137
- });
138
-
139
- const roles = state().messages.map((m) => m.role);
140
- // The tool sits at index 1 (right after the first user message), not last.
141
- expect(roles).toEqual([
142
- 'user',
143
- 'tool',
144
- 'user',
145
- 'assistant',
146
- 'user',
147
- 'assistant',
148
- ]);
149
- const tool = state().messages[1];
150
- expect(tool.interrupted).toBe(true);
151
- expect(tool.isStreaming).toBe(false);
152
- // The final message is the assistant reply, NOT a trailing tool call.
153
- expect(state().messages[state().messages.length - 1].role).toBe(
154
- 'assistant',
155
- );
156
- });
157
-
158
- it('with multiple dangling calls, only the newest streams on the live tail; earlier ones are interrupted in place', () => {
159
- ws.last().receive({
160
- type: 'session_created',
161
- sessionId: 'sid-1',
162
- sessionFile: '/tmp/project/session.jsonl',
163
- cwd: '/tmp/project',
164
- model: 'fake:model',
165
- isStreaming: true,
166
- });
167
- ws.last().receive({
168
- type: 'message_history',
169
- sessionId: 'sid-1',
170
- messages: [
171
- {
172
- role: 'tool_call',
173
- content: '{"command":"sleep 1"}',
174
- timestamp: 1_000,
175
- toolName: 'bash',
176
- },
177
- {role: 'user', content: 'again', timestamp: 2_000},
178
- {
179
- role: 'tool_call',
180
- content: '{"command":"sleep 2"}',
181
- timestamp: 3_000,
182
- toolName: 'bash',
183
- },
184
- ],
185
- totalCount: 3,
186
- offset: 0,
187
- });
188
-
189
- const tools = state().messages.filter((m) => m.role === 'tool');
190
- expect(tools).toHaveLength(2);
191
- // First (older) dangling call: interrupted, not streaming.
192
- expect(tools[0].interrupted).toBe(true);
193
- expect(tools[0].isStreaming).toBe(false);
194
- // Newest dangling call: still running on the live tail.
195
- expect(tools[1].interrupted).toBeFalsy();
196
- expect(tools[1].isStreaming).toBe(true);
197
- });
198
-
199
- it('pairs a tool_result to its exact call by id, leaving the correct earlier same-named call dangling', () => {
200
- // Two bash calls issued back-to-back; only the SECOND gets a result. With
201
- // tool-call ids the result must resolve call #2 (by id), leaving call #1
202
- // dangling/interrupted. Name-FIFO alone would wrongly resolve call #1 and
203
- // leave call #2 dangling.
204
- ws.last().receive({
205
- type: 'session_created',
206
- sessionId: 'sid-1',
207
- sessionFile: '/tmp/project/session.jsonl',
208
- cwd: '/tmp/project',
209
- model: 'fake:model',
210
- isStreaming: false,
211
- });
212
- ws.last().receive({
213
- type: 'message_history',
214
- sessionId: 'sid-1',
215
- messages: [
216
- {
217
- role: 'tool_call',
218
- content: '{"command":"sleep 300"}',
219
- timestamp: 1_000,
220
- toolName: 'bash',
221
- toolCallId: 'call-A',
222
- },
223
- {
224
- role: 'tool_call',
225
- content: '{"command":"echo hi"}',
226
- timestamp: 1_100,
227
- toolName: 'bash',
228
- toolCallId: 'call-B',
229
- },
230
- {
231
- role: 'tool_result',
232
- content: 'hi',
233
- timestamp: 1_200,
234
- toolName: 'bash',
235
- toolCallId: 'call-B',
236
- isError: false,
237
- },
238
- ],
239
- totalCount: 3,
240
- offset: 0,
241
- });
242
-
243
- const tools = state().messages.filter((m) => m.role === 'tool');
244
- expect(tools).toHaveLength(2);
245
- // Call A (sleep 300) is the dangling/interrupted one.
246
- const callA = tools.find((t) => t.toolArgs?.includes('sleep 300'))!;
247
- const callB = tools.find((t) => t.toolArgs?.includes('echo hi'))!;
248
- expect(callA.interrupted).toBe(true);
249
- expect(callA.toolOutput).toBe('');
250
- // Call B got its result.
251
- expect(callB.interrupted).toBeFalsy();
252
- expect(callB.toolOutput).toBe('hi');
253
- // Order in the transcript is preserved (A before B).
254
- expect(state().messages.indexOf(callA)).toBeLessThan(
255
- state().messages.indexOf(callB),
256
- );
257
- });
258
-
259
- it('a matched tool_call + tool_result is NOT interrupted', () => {
260
- ws.last().receive({
261
- type: 'session_created',
262
- sessionId: 'sid-1',
263
- sessionFile: '/tmp/project/session.jsonl',
264
- cwd: '/tmp/project',
265
- model: 'fake:model',
266
- isStreaming: false,
267
- });
268
- ws.last().receive({
269
- type: 'message_history',
270
- sessionId: 'sid-1',
271
- messages: [
272
- {
273
- role: 'tool_call',
274
- content: '{"command":"ls"}',
275
- timestamp: 10_000,
276
- toolName: 'bash',
277
- },
278
- {
279
- role: 'tool_result',
280
- content: 'a\nb',
281
- timestamp: 11_000,
282
- toolName: 'bash',
283
- isError: false,
284
- },
285
- ],
286
- totalCount: 2,
287
- offset: 0,
288
- });
289
-
290
- const tool = state().messages.find((m) => m.role === 'tool')!;
291
- expect(tool.interrupted).toBeFalsy();
292
- expect(tool.isError).toBe(false);
293
- });
294
- });