@wherever-dev/client 0.5.3 → 0.6.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/CHANGELOG.md +37 -0
- package/dist/client.d.ts +54 -2
- package/dist/client.js +388 -13
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +48 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +449 -13
- package/src/types.ts +118 -0
- package/test/conversation-mode-flag.test.ts +111 -0
- package/test/folder-conflict-read-only.test.ts +145 -0
- package/test/folder-missing-read-only.test.ts +114 -0
- package/test/new-session-clone-progress.test.ts +263 -0
- package/test/queued-steer-restored.test.ts +175 -0
- package/test/restore-panel.test.ts +324 -0
- package/test/session-load-by-id.test.ts +100 -0
- package/test/skills-autocomplete.test.ts +113 -0
- package/test/superseded-connection-key.test.ts +70 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
|
|
2
|
+
import {get} from 'sveltore';
|
|
3
|
+
import {WhereverClient} from '../src/client.js';
|
|
4
|
+
import {makeWSFactory} from './harness.js';
|
|
5
|
+
|
|
6
|
+
// The CLIENT half of "create a session in a folder that has to be cloned
|
|
7
|
+
// first". The server runs that clone as an ordinary path-keyed restore job, so
|
|
8
|
+
// the frames here are the panel's frames -- what differs is the ENDING, and the
|
|
9
|
+
// watchdog.
|
|
10
|
+
//
|
|
11
|
+
// The watchdog is the whole point: `createSession` arms a 25s timer so a lost
|
|
12
|
+
// reply can never strand the blocking "Creating session..." overlay, and a
|
|
13
|
+
// clone of any real repository outruns it. So a create that becomes a WATCHED
|
|
14
|
+
// job must disarm it (a job reporting progress is not something to time out),
|
|
15
|
+
// then re-arm it for the last, ordinary step the server performs by itself once
|
|
16
|
+
// the clone is done. There is no Reload here, unlike the restore panel: the
|
|
17
|
+
// session does not exist until the clone lands.
|
|
18
|
+
|
|
19
|
+
const TARGET = '/home/u/dev/github/owner/repo';
|
|
20
|
+
|
|
21
|
+
function cloneJob(overrides: Record<string, unknown> = {}) {
|
|
22
|
+
return {
|
|
23
|
+
id: 3,
|
|
24
|
+
kind: 'clone',
|
|
25
|
+
targetPath: TARGET,
|
|
26
|
+
url: 'git@github.com:owner/repo.git',
|
|
27
|
+
state: 'running',
|
|
28
|
+
progress: {
|
|
29
|
+
phase: 'receiving',
|
|
30
|
+
scope: 'repository',
|
|
31
|
+
percent: 12,
|
|
32
|
+
indeterminate: false,
|
|
33
|
+
text: 'Receiving objects: 12% (12/100)',
|
|
34
|
+
at: 1,
|
|
35
|
+
},
|
|
36
|
+
startedAt: 1,
|
|
37
|
+
...overrides,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('new-session clone progress', () => {
|
|
42
|
+
let ws: ReturnType<typeof makeWSFactory>;
|
|
43
|
+
let client: WhereverClient;
|
|
44
|
+
|
|
45
|
+
/** What the dashboard's "Clone Repository" answer sends. */
|
|
46
|
+
function createWithClone() {
|
|
47
|
+
client.createSession(TARGET, undefined, false, false, undefined, true);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
vi.useFakeTimers();
|
|
52
|
+
ws = makeWSFactory();
|
|
53
|
+
client = new WhereverClient({
|
|
54
|
+
host: 'localhost',
|
|
55
|
+
port: 1234,
|
|
56
|
+
secure: false,
|
|
57
|
+
WebSocketCtor: ws.ctor,
|
|
58
|
+
});
|
|
59
|
+
client.connect();
|
|
60
|
+
ws.last().open();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
client.disconnect(true);
|
|
65
|
+
vi.useRealTimers();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('adopts the clone job as the create, dropping the blocking overlay', () => {
|
|
69
|
+
createWithClone();
|
|
70
|
+
expect(get(client.stateStore).creatingSession).toBe(true);
|
|
71
|
+
|
|
72
|
+
ws.last().receive({
|
|
73
|
+
type: 'restore_started',
|
|
74
|
+
targetPath: TARGET,
|
|
75
|
+
outcome: 'started',
|
|
76
|
+
job: cloneJob(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const s = get(client.stateStore);
|
|
80
|
+
// The overlay gives way to the same progress display the panel renders...
|
|
81
|
+
expect(s.creatingSession).toBe(false);
|
|
82
|
+
expect(s.restore).toEqual({
|
|
83
|
+
targetPath: TARGET,
|
|
84
|
+
job: cloneJob(),
|
|
85
|
+
joined: false,
|
|
86
|
+
rejection: null,
|
|
87
|
+
// ...marked as a create's first step, because it ends differently:
|
|
88
|
+
// the server continues into creation instead of offering a Reload.
|
|
89
|
+
forSessionCreate: true,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('does not time out a clone that outruns the 25s create watchdog', () => {
|
|
94
|
+
createWithClone();
|
|
95
|
+
ws.last().receive({
|
|
96
|
+
type: 'restore_started',
|
|
97
|
+
targetPath: TARGET,
|
|
98
|
+
outcome: 'started',
|
|
99
|
+
job: cloneJob(),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// A large repository: minutes of real progress, and the watchdog would
|
|
103
|
+
// have fired four times over. This is exactly what the old synchronous
|
|
104
|
+
// clone could not survive.
|
|
105
|
+
for (const percent of [30, 60, 90]) {
|
|
106
|
+
vi.advanceTimersByTime(60_000);
|
|
107
|
+
ws.last().receive({
|
|
108
|
+
type: 'restore_progress',
|
|
109
|
+
targetPath: TARGET,
|
|
110
|
+
job: cloneJob({progress: {...cloneJob().progress, percent}}),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const s = get(client.stateStore);
|
|
115
|
+
expect(s.sessionError).toBeFalsy();
|
|
116
|
+
expect(s.creatingSession).toBe(false);
|
|
117
|
+
expect(s.restore?.job?.progress?.percent).toBe(90);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('hands the screen back to the create when the clone is done', () => {
|
|
121
|
+
createWithClone();
|
|
122
|
+
ws.last().receive({
|
|
123
|
+
type: 'restore_started',
|
|
124
|
+
targetPath: TARGET,
|
|
125
|
+
outcome: 'started',
|
|
126
|
+
job: cloneJob(),
|
|
127
|
+
});
|
|
128
|
+
ws.last().receive({
|
|
129
|
+
type: 'restore_complete',
|
|
130
|
+
targetPath: TARGET,
|
|
131
|
+
job: cloneJob({state: 'done'}),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// No Reload offer, no lingering panel: the server is already creating the
|
|
135
|
+
// session, so the ordinary overlay (and its watchdog) covers that step.
|
|
136
|
+
let s = get(client.stateStore);
|
|
137
|
+
expect(s.restore).toBeNull();
|
|
138
|
+
expect(s.creatingSession).toBe(true);
|
|
139
|
+
expect(s.sessionError).toBeFalsy();
|
|
140
|
+
|
|
141
|
+
ws.last().receive({
|
|
142
|
+
type: 'session_created',
|
|
143
|
+
sessionId: 'sid-1',
|
|
144
|
+
sessionFile: `${TARGET}/session.jsonl`,
|
|
145
|
+
cwd: TARGET,
|
|
146
|
+
model: 'fake:model',
|
|
147
|
+
isStreaming: false,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
s = get(client.stateStore);
|
|
151
|
+
expect(s.creatingSession).toBe(false);
|
|
152
|
+
expect(s.activeSessionFile).toBe(`${TARGET}/session.jsonl`);
|
|
153
|
+
|
|
154
|
+
// The re-armed watchdog was disarmed again by the reply.
|
|
155
|
+
vi.advanceTimersByTime(30_000);
|
|
156
|
+
expect(get(client.stateStore).sessionError).toBeFalsy();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('re-arms the watchdog for the creation step the server still owes', () => {
|
|
160
|
+
createWithClone();
|
|
161
|
+
ws.last().receive({
|
|
162
|
+
type: 'restore_started',
|
|
163
|
+
targetPath: TARGET,
|
|
164
|
+
outcome: 'started',
|
|
165
|
+
job: cloneJob(),
|
|
166
|
+
});
|
|
167
|
+
ws.last().receive({
|
|
168
|
+
type: 'restore_complete',
|
|
169
|
+
targetPath: TARGET,
|
|
170
|
+
job: cloneJob({state: 'done'}),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// The clone landed but the create reply never comes: the safety net the
|
|
174
|
+
// clone suspended is back, so the overlay still cannot hang forever.
|
|
175
|
+
vi.advanceTimersByTime(30_000);
|
|
176
|
+
const s = get(client.stateStore);
|
|
177
|
+
expect(s.creatingSession).toBe(false);
|
|
178
|
+
expect(s.sessionError).toBeTruthy();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('ends the create when the clone fails, letting session_error speak', () => {
|
|
182
|
+
createWithClone();
|
|
183
|
+
ws.last().receive({
|
|
184
|
+
type: 'restore_started',
|
|
185
|
+
targetPath: TARGET,
|
|
186
|
+
outcome: 'started',
|
|
187
|
+
job: cloneJob(),
|
|
188
|
+
});
|
|
189
|
+
ws.last().receive({
|
|
190
|
+
type: 'restore_complete',
|
|
191
|
+
targetPath: TARGET,
|
|
192
|
+
job: cloneJob({
|
|
193
|
+
state: 'failed',
|
|
194
|
+
failure: {
|
|
195
|
+
cause: 'not-found',
|
|
196
|
+
message: 'Repository not found.',
|
|
197
|
+
stderr: 'fatal: repository not found',
|
|
198
|
+
},
|
|
199
|
+
}),
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// The panel would stay on screen in its failed state; a create has no
|
|
203
|
+
// panel to stay in, so the mapped cause arrives on the create's own
|
|
204
|
+
// channel and the restore state goes away with the create.
|
|
205
|
+
let s = get(client.stateStore);
|
|
206
|
+
expect(s.restore).toBeNull();
|
|
207
|
+
expect(s.creatingSession).toBe(false);
|
|
208
|
+
|
|
209
|
+
ws.last().receive({
|
|
210
|
+
type: 'session_error',
|
|
211
|
+
error: 'Repository not found.',
|
|
212
|
+
});
|
|
213
|
+
s = get(client.stateStore);
|
|
214
|
+
expect(s.sessionError).toBe('Repository not found.');
|
|
215
|
+
|
|
216
|
+
// And no watchdog is left armed to speak over it.
|
|
217
|
+
vi.advanceTimersByTime(30_000);
|
|
218
|
+
expect(get(client.stateStore).sessionError).toBe('Repository not found.');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('leaves the restore PANEL path alone: no create, no adoption', () => {
|
|
222
|
+
// A loaded session whose folder is missing: same frame, but there IS a
|
|
223
|
+
// session, the panel owns the outcome, and the ending is a Reload.
|
|
224
|
+
const sessionFile = `${TARGET}/session.jsonl`;
|
|
225
|
+
client.joinSession(sessionFile);
|
|
226
|
+
ws.last().receive({
|
|
227
|
+
type: 'session_created',
|
|
228
|
+
sessionId: 'sid-1',
|
|
229
|
+
sessionFile,
|
|
230
|
+
cwd: TARGET,
|
|
231
|
+
model: 'fake:model',
|
|
232
|
+
readOnly: true,
|
|
233
|
+
folderMissing: true,
|
|
234
|
+
pending: true,
|
|
235
|
+
});
|
|
236
|
+
ws.last().receive({
|
|
237
|
+
type: 'folder_missing',
|
|
238
|
+
sessionId: 'sid-1',
|
|
239
|
+
cwd: TARGET,
|
|
240
|
+
});
|
|
241
|
+
ws.last().receive({
|
|
242
|
+
type: 'restore_started',
|
|
243
|
+
targetPath: TARGET,
|
|
244
|
+
outcome: 'started',
|
|
245
|
+
job: cloneJob(),
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
let s = get(client.stateStore);
|
|
249
|
+
expect(s.restore?.forSessionCreate).toBeUndefined();
|
|
250
|
+
expect(s.restore?.job?.id).toBe(3);
|
|
251
|
+
|
|
252
|
+
// Completion keeps the panel, which offers the Reload; it does not hand
|
|
253
|
+
// back to a create that never existed.
|
|
254
|
+
ws.last().receive({
|
|
255
|
+
type: 'restore_complete',
|
|
256
|
+
targetPath: TARGET,
|
|
257
|
+
job: cloneJob({state: 'done'}),
|
|
258
|
+
});
|
|
259
|
+
s = get(client.stateStore);
|
|
260
|
+
expect(s.restore?.job?.state).toBe('done');
|
|
261
|
+
expect(s.creatingSession).toBe(false);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
|
|
2
|
+
import {get} from 'sveltore';
|
|
3
|
+
import {WhereverClient} from '../src/client.js';
|
|
4
|
+
import {makeWSFactory} from './harness.js';
|
|
5
|
+
|
|
6
|
+
// Bug: after a reload, a message queued mid-stream (a STEER) was invisible. The
|
|
7
|
+
// server now snapshots pi's queue on attach (queue_update), but the queued text
|
|
8
|
+
// is NOT in the session file yet, so message_history cannot contain it: with
|
|
9
|
+
// only `pendingSteering` set and no matching message, the UI had nothing to
|
|
10
|
+
// badge and the user's text simply vanished until pi injected it at the next
|
|
11
|
+
// step.
|
|
12
|
+
//
|
|
13
|
+
// Fix: queue_update re-materializes any queued text with no matching user
|
|
14
|
+
// message, so a reloaded client shows the queued messages (badged "Queued") and
|
|
15
|
+
// can still cancel them.
|
|
16
|
+
|
|
17
|
+
function newClient(ws: ReturnType<typeof makeWSFactory>) {
|
|
18
|
+
const client = new WhereverClient({
|
|
19
|
+
host: 'localhost',
|
|
20
|
+
port: 1234,
|
|
21
|
+
secure: false,
|
|
22
|
+
WebSocketCtor: ws.ctor,
|
|
23
|
+
});
|
|
24
|
+
client.connect();
|
|
25
|
+
ws.last().open();
|
|
26
|
+
return client;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function attach(ws: ReturnType<typeof makeWSFactory>, client: WhereverClient) {
|
|
30
|
+
client.joinSession('/tmp/project/session.jsonl');
|
|
31
|
+
ws.last().receive({
|
|
32
|
+
type: 'session_created',
|
|
33
|
+
sessionId: 'sid-1',
|
|
34
|
+
sessionFile: '/tmp/project/session.jsonl',
|
|
35
|
+
cwd: '/tmp/project',
|
|
36
|
+
model: 'fake:model',
|
|
37
|
+
});
|
|
38
|
+
ws.last().receive({
|
|
39
|
+
type: 'message_history',
|
|
40
|
+
sessionId: 'sid-1',
|
|
41
|
+
messages: [{role: 'user', content: 'do the first thing', timestamp: 1}],
|
|
42
|
+
totalCount: 1,
|
|
43
|
+
offset: 0,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('a queued steer is restored into the conversation on reload', () => {
|
|
48
|
+
let ws: ReturnType<typeof makeWSFactory>;
|
|
49
|
+
let client: WhereverClient;
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
vi.useFakeTimers();
|
|
53
|
+
ws = makeWSFactory();
|
|
54
|
+
client = newClient(ws);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
client.disconnect(true);
|
|
59
|
+
vi.useRealTimers();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders a queued message the freshly-loaded history does not contain', () => {
|
|
63
|
+
attach(ws, client);
|
|
64
|
+
|
|
65
|
+
ws.last().receive({
|
|
66
|
+
type: 'queue_update',
|
|
67
|
+
sessionId: 'sid-1',
|
|
68
|
+
steering: ['actually do X instead'],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const s = get(client.stateStore);
|
|
72
|
+
expect(s.pendingSteering).toEqual(['actually do X instead']);
|
|
73
|
+
const restored = s.messages.filter(
|
|
74
|
+
(m) => m.role === 'user' && m.content === 'actually do X instead',
|
|
75
|
+
);
|
|
76
|
+
expect(restored).toHaveLength(1);
|
|
77
|
+
// It is server-side queued, not an unconfirmed local send: no retry banner.
|
|
78
|
+
expect(restored[0].delivery).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('does not duplicate a queued message we sent ourselves this session', () => {
|
|
82
|
+
attach(ws, client);
|
|
83
|
+
client.sendMessage('actually do X instead');
|
|
84
|
+
|
|
85
|
+
ws.last().receive({
|
|
86
|
+
type: 'queue_update',
|
|
87
|
+
sessionId: 'sid-1',
|
|
88
|
+
steering: ['actually do X instead'],
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const s = get(client.stateStore);
|
|
92
|
+
expect(
|
|
93
|
+
s.messages.filter((m) => m.content === 'actually do X instead'),
|
|
94
|
+
).toHaveLength(1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('does not duplicate when the queued message is finally delivered', () => {
|
|
98
|
+
attach(ws, client);
|
|
99
|
+
ws.last().receive({
|
|
100
|
+
type: 'queue_update',
|
|
101
|
+
sessionId: 'sid-1',
|
|
102
|
+
steering: ['actually do X instead'],
|
|
103
|
+
});
|
|
104
|
+
// pi injects it: the queue empties and the server echoes the user message.
|
|
105
|
+
ws.last().receive({type: 'queue_update', sessionId: 'sid-1', steering: []});
|
|
106
|
+
ws.last().receive({
|
|
107
|
+
type: 'message_end',
|
|
108
|
+
sessionId: 'sid-1',
|
|
109
|
+
role: 'user',
|
|
110
|
+
content: 'actually do X instead',
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const s = get(client.stateStore);
|
|
114
|
+
expect(s.pendingSteering).toEqual([]);
|
|
115
|
+
expect(
|
|
116
|
+
s.messages.filter((m) => m.content === 'actually do X instead'),
|
|
117
|
+
).toHaveLength(1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('restores every queued message, including repeats of the same text', () => {
|
|
121
|
+
attach(ws, client);
|
|
122
|
+
ws.last().receive({
|
|
123
|
+
type: 'queue_update',
|
|
124
|
+
sessionId: 'sid-1',
|
|
125
|
+
steering: ['ping', 'ping'],
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const s = get(client.stateStore);
|
|
129
|
+
expect(s.messages.filter((m) => m.content === 'ping')).toHaveLength(2);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('does not duplicate when the OLDER of two queued messages is delivered', () => {
|
|
133
|
+
attach(ws, client);
|
|
134
|
+
ws.last().receive({
|
|
135
|
+
type: 'queue_update',
|
|
136
|
+
sessionId: 'sid-1',
|
|
137
|
+
steering: ['first queued', 'second queued'],
|
|
138
|
+
});
|
|
139
|
+
// pi injects the oldest: the queue drops it and the server echoes it. The
|
|
140
|
+
// echoed message is NOT the last user bubble ('second queued' is), so a
|
|
141
|
+
// naive last-message dedupe would append a duplicate.
|
|
142
|
+
ws.last().receive({
|
|
143
|
+
type: 'queue_update',
|
|
144
|
+
sessionId: 'sid-1',
|
|
145
|
+
steering: ['second queued'],
|
|
146
|
+
});
|
|
147
|
+
ws.last().receive({
|
|
148
|
+
type: 'message_end',
|
|
149
|
+
sessionId: 'sid-1',
|
|
150
|
+
role: 'user',
|
|
151
|
+
content: 'first queued',
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const s = get(client.stateStore);
|
|
155
|
+
expect(s.messages.filter((m) => m.content === 'first queued')).toHaveLength(1);
|
|
156
|
+
expect(s.messages.filter((m) => m.content === 'second queued')).toHaveLength(1);
|
|
157
|
+
expect(s.pendingSteering).toEqual(['second queued']);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('leaves an already-restored queue alone on a repeated snapshot', () => {
|
|
161
|
+
attach(ws, client);
|
|
162
|
+
const snapshot = {
|
|
163
|
+
type: 'queue_update',
|
|
164
|
+
sessionId: 'sid-1',
|
|
165
|
+
steering: ['actually do X instead'],
|
|
166
|
+
};
|
|
167
|
+
ws.last().receive(snapshot);
|
|
168
|
+
ws.last().receive(snapshot);
|
|
169
|
+
|
|
170
|
+
const s = get(client.stateStore);
|
|
171
|
+
expect(
|
|
172
|
+
s.messages.filter((m) => m.content === 'actually do X instead'),
|
|
173
|
+
).toHaveLength(1);
|
|
174
|
+
});
|
|
175
|
+
});
|