@parallelworks/code 0.4.0 → 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/README.md +92 -24
- package/dist/agentSwitcher.d.ts +13 -2
- package/dist/agentSwitcher.js +28 -6
- package/dist/ago.d.ts +1 -3
- package/dist/ago.js +1 -3
- package/dist/api.d.ts +267 -5
- package/dist/chatStrings.d.ts +4 -0
- package/dist/chatStrings.js +5 -1
- package/dist/claudeAccounts.d.ts +20 -2
- package/dist/claudeAccounts.js +51 -7
- package/dist/claudeApi.d.ts +2 -1
- package/dist/claudeApi.js +49 -3
- package/dist/command.d.ts +7 -1
- package/dist/command.js +11 -2
- package/dist/commandsApi.d.ts +8 -3
- package/dist/commandsApi.js +25 -4
- package/dist/createPwCodeApi.d.ts +92 -58
- package/dist/createPwCodeApi.js +4 -2
- package/dist/index.d.ts +11 -9
- package/dist/index.js +7 -5
- package/dist/locales/en/agentTranscript.js +6 -2
- package/dist/locales/en/agents.js +50 -6
- package/dist/locales/en.d.ts +46 -0
- package/dist/locales/es/agentTranscript.js +6 -2
- package/dist/locales/es/agents.js +50 -6
- package/dist/locales/ja/agentTranscript.js +6 -2
- package/dist/locales/ja/agents.js +45 -6
- package/dist/locales/ko/agentTranscript.js +6 -2
- package/dist/locales/ko/agents.js +50 -6
- package/dist/locales/zh/agentTranscript.js +6 -2
- package/dist/locales/zh/agents.js +50 -6
- package/dist/machine.d.ts +27 -2
- package/dist/machine.js +23 -2
- package/dist/notices.d.ts +2 -0
- package/dist/notices.js +29 -14
- package/dist/pwUpdate.d.ts +52 -0
- package/dist/pwUpdate.js +115 -0
- package/dist/query.d.ts +4 -1
- package/dist/query.js +9 -3
- package/dist/session.d.ts +7 -1
- package/dist/session.js +6 -2
- package/dist/sessionActions.js +5 -2
- package/dist/sessionEvents.d.ts +39 -5
- package/dist/sessionEvents.js +213 -83
- package/dist/sessionGroups.d.ts +3 -3
- package/dist/sessionGroups.js +3 -3
- package/dist/sessionHeader.js +6 -2
- package/dist/sessionList.d.ts +13 -8
- package/dist/sessionList.js +20 -10
- package/dist/sessionScreen.d.ts +8 -3
- package/dist/sessionScreen.js +20 -9
- package/dist/sessionsApi.d.ts +27 -5
- package/dist/sessionsApi.js +128 -17
- package/dist/sessionsFeed.d.ts +22 -0
- package/dist/sessionsFeed.js +125 -0
- package/dist/startPage.d.ts +6 -3
- package/dist/startPage.js +34 -12
- package/dist/startSession.d.ts +31 -11
- package/dist/startSession.js +126 -44
- package/dist/terminalHandoffPanel.js +8 -1
- package/dist/todos.d.ts +42 -0
- package/dist/todos.js +104 -0
- package/dist/transcript.d.ts +27 -5
- package/dist/transcript.js +148 -112
- package/dist/transcriptRead.d.ts +57 -0
- package/dist/transcriptRead.js +122 -0
- package/dist/types.d.ts +13 -1
- package/dist/useComposer.d.ts +36 -15
- package/dist/useComposer.js +94 -31
- package/dist/useComposerImages.d.ts +38 -1
- package/dist/useComposerImages.js +62 -8
- package/dist/useComposerPastes.js +3 -8
- package/dist/useConversation.d.ts +16 -0
- package/dist/useConversation.js +78 -8
- package/dist/useMounted.d.ts +3 -0
- package/dist/useMounted.js +14 -0
- package/dist/useSubagent.d.ts +22 -5
- package/dist/useSubagent.js +41 -17
- package/dist/useTranscript.d.ts +27 -1
- package/dist/useTranscript.js +217 -45
- package/dist/wording.d.ts +6 -3
- package/dist/wording.js +20 -6
- package/locales/en/agentTranscript.json +6 -2
- package/locales/en/agents.json +46 -4
- package/locales/es/agentTranscript.json +6 -2
- package/locales/es/agents.json +46 -4
- package/locales/ja/agentTranscript.json +6 -2
- package/locales/ja/agents.json +46 -4
- package/locales/ko/agentTranscript.json +6 -2
- package/locales/ko/agents.json +46 -4
- package/locales/zh/agentTranscript.json +6 -2
- package/locales/zh/agents.json +46 -4
- package/package.json +3 -3
package/dist/sessionEvents.js
CHANGED
|
@@ -4,20 +4,40 @@ import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "
|
|
|
4
4
|
// src/sessionEvents.ts
|
|
5
5
|
var INITIAL_RETRY_MS = 1e3;
|
|
6
6
|
var MAX_RETRY_MS = 3e4;
|
|
7
|
+
/** How long a socket that has sent a heartbeat may say nothing: two are missed. */
|
|
8
|
+
var SILENT_AFTER_MS = 25e3;
|
|
9
|
+
/** The platform gives a machine 15 seconds to answer before it refuses a socket. */
|
|
10
|
+
var OPEN_WITHIN_MS = 2e4;
|
|
7
11
|
var SOCKET_OPEN = 1;
|
|
8
12
|
var SOCKET_CLOSED = 3;
|
|
13
|
+
/** How long a hidden app holds a streaming reply's frames: each one applied
|
|
14
|
+
* re-renders the transcript and reads its layout. */
|
|
15
|
+
var HIDDEN_STREAM_MS = 1e3;
|
|
16
|
+
/** Frames a reply sends many times a second while it streams. */
|
|
17
|
+
function streams(ev) {
|
|
18
|
+
return ev.type === "chunk" || ev.type === "reasoning" || ev.type === "tool_update";
|
|
19
|
+
}
|
|
9
20
|
/** The path a session's event feed is served at, resuming after frame `after`.
|
|
10
21
|
* With `previewsByRef` the images a tool read come without their previews,
|
|
11
22
|
* which the host loads by URL: a preview is tens of kilobytes, and over a slow
|
|
12
23
|
* connection what the session says next waits behind it. */
|
|
13
24
|
function sessionEventsPath(machine, id, after, previewsByRef = false) {
|
|
14
25
|
const previews = previewsByRef ? `&previews=${PREVIEWS_BY_REF}` : "";
|
|
15
|
-
return `/ws/code/machines/${encodeURIComponent(machine)}/sessions/${encodeURIComponent(id)}/events?after=${after}${previews}`;
|
|
26
|
+
return `/ws/code/machines/${encodeURIComponent(machine)}/sessions/${encodeURIComponent(id)}/events?after=${after}${previews}&heartbeat=10`;
|
|
27
|
+
}
|
|
28
|
+
/** Whether a frame is the heartbeat the platform sends a feed that asked for one. */
|
|
29
|
+
function isHeartbeat(data) {
|
|
30
|
+
if (typeof data !== "string" || data.length > 64) return false;
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(data).type === "heartbeat";
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
16
36
|
}
|
|
17
|
-
/** Frames after which the list of subagents may read differently: one started
|
|
18
|
-
* or
|
|
37
|
+
/** Frames after which the list of subagents may read differently: one started,
|
|
38
|
+
* ended or was dismissed, one asked for or got an approval, or a turn began or closed. */
|
|
19
39
|
function changesSubagents(ev) {
|
|
20
|
-
return ev.type === "subagent_start" || ev.type === "subagent_end" || ev.type === "approval_request" || ev.type === "approval_resolved" || ev.type === "user_message" || ev.type === "done" || ev.type === "error";
|
|
40
|
+
return ev.type === "subagent_start" || ev.type === "subagent_end" || ev.type === "subagent_dismissed" || ev.type === "approval_request" || ev.type === "approval_resolved" || ev.type === "user_message" || ev.type === "done" || ev.type === "error";
|
|
21
41
|
}
|
|
22
42
|
/** `machines` with each one in `fed` that the listing lost counted as connected. */
|
|
23
43
|
function reachedByFeed(machines, fed) {
|
|
@@ -32,94 +52,177 @@ function reachedByFeed(machines, fed) {
|
|
|
32
52
|
};
|
|
33
53
|
});
|
|
34
54
|
}
|
|
55
|
+
/** Holds one socket open until the returned call, reopening it with backoff
|
|
56
|
+
* after it drops. */
|
|
57
|
+
function holdSocket(latest, setConnected) {
|
|
58
|
+
let stopped = false;
|
|
59
|
+
let socket = null;
|
|
60
|
+
let silent = null;
|
|
61
|
+
let attempt = 0;
|
|
62
|
+
let attempts = 0;
|
|
63
|
+
let hurried = false;
|
|
64
|
+
let timer;
|
|
65
|
+
let opening;
|
|
66
|
+
let silence;
|
|
67
|
+
const retry = () => {
|
|
68
|
+
const delay = Math.min(INITIAL_RETRY_MS * 2 ** attempts, MAX_RETRY_MS);
|
|
69
|
+
attempts += 1;
|
|
70
|
+
timer = setTimeout(connect, delay);
|
|
71
|
+
};
|
|
72
|
+
const failed = () => {
|
|
73
|
+
clearTimeout(opening);
|
|
74
|
+
if (stopped) return;
|
|
75
|
+
latest.current.onClose();
|
|
76
|
+
retry();
|
|
77
|
+
};
|
|
78
|
+
const attach = (ws) => {
|
|
79
|
+
if (stopped) {
|
|
80
|
+
ws.close();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
socket = ws;
|
|
84
|
+
let beats = false;
|
|
85
|
+
const opened = () => {
|
|
86
|
+
if (socket !== ws) return;
|
|
87
|
+
clearTimeout(opening);
|
|
88
|
+
const left = silent;
|
|
89
|
+
silent = null;
|
|
90
|
+
left?.close();
|
|
91
|
+
attempts = 0;
|
|
92
|
+
hurried = false;
|
|
93
|
+
setConnected(true);
|
|
94
|
+
latest.current.onOpen(false);
|
|
95
|
+
};
|
|
96
|
+
const revived = () => {
|
|
97
|
+
silent = null;
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
timer = void 0;
|
|
100
|
+
clearTimeout(opening);
|
|
101
|
+
attempt += 1;
|
|
102
|
+
const tried = socket;
|
|
103
|
+
socket = ws;
|
|
104
|
+
tried?.close();
|
|
105
|
+
attempts = 0;
|
|
106
|
+
hurried = false;
|
|
107
|
+
setConnected(true);
|
|
108
|
+
latest.current.onOpen(true);
|
|
109
|
+
};
|
|
110
|
+
const wentSilent = () => {
|
|
111
|
+
if (socket !== ws) return;
|
|
112
|
+
silent = ws;
|
|
113
|
+
socket = null;
|
|
114
|
+
setConnected(false);
|
|
115
|
+
latest.current.onClose();
|
|
116
|
+
connect();
|
|
117
|
+
};
|
|
118
|
+
const closed = () => {
|
|
119
|
+
if (silent === ws) {
|
|
120
|
+
silent = null;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (socket !== ws) return;
|
|
124
|
+
socket = null;
|
|
125
|
+
clearTimeout(opening);
|
|
126
|
+
clearTimeout(silence);
|
|
127
|
+
setConnected(false);
|
|
128
|
+
latest.current.onClose();
|
|
129
|
+
if (!stopped) retry();
|
|
130
|
+
};
|
|
131
|
+
ws.addEventListener("open", opened);
|
|
132
|
+
const heartbeat = (data) => {
|
|
133
|
+
const beat = latest.current.heartbeat?.(data) === true;
|
|
134
|
+
beats ||= beat;
|
|
135
|
+
if (beats) {
|
|
136
|
+
clearTimeout(silence);
|
|
137
|
+
silence = setTimeout(wentSilent, SILENT_AFTER_MS);
|
|
138
|
+
}
|
|
139
|
+
return beat;
|
|
140
|
+
};
|
|
141
|
+
ws.addEventListener("message", (event) => {
|
|
142
|
+
if (silent === ws) revived();
|
|
143
|
+
if (socket === ws && !heartbeat(event.data)) latest.current.onMessage(event.data);
|
|
144
|
+
});
|
|
145
|
+
ws.addEventListener("close", closed);
|
|
146
|
+
if (ws.readyState === SOCKET_OPEN) opened();
|
|
147
|
+
else if (ws.readyState === SOCKET_CLOSED) closed();
|
|
148
|
+
};
|
|
149
|
+
function connect() {
|
|
150
|
+
timer = void 0;
|
|
151
|
+
const opener = latest.current.open;
|
|
152
|
+
if (!opener) return;
|
|
153
|
+
attempt += 1;
|
|
154
|
+
const mine = attempt;
|
|
155
|
+
opening = setTimeout(() => {
|
|
156
|
+
const ws = socket;
|
|
157
|
+
socket = null;
|
|
158
|
+
latest.current.onClose();
|
|
159
|
+
ws?.close();
|
|
160
|
+
connect();
|
|
161
|
+
}, OPEN_WITHIN_MS);
|
|
162
|
+
let made;
|
|
163
|
+
try {
|
|
164
|
+
made = opener(latest.current.path());
|
|
165
|
+
} catch {
|
|
166
|
+
failed();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if ("then" in made) made.then((ws) => mine === attempt ? attach(ws) : ws.close(), () => {
|
|
170
|
+
if (mine === attempt) failed();
|
|
171
|
+
});
|
|
172
|
+
else attach(made);
|
|
173
|
+
}
|
|
174
|
+
connect();
|
|
175
|
+
const forget = latest.current.whenReachable?.(() => {
|
|
176
|
+
if (stopped || timer === void 0 || hurried) return;
|
|
177
|
+
hurried = true;
|
|
178
|
+
clearTimeout(timer);
|
|
179
|
+
attempts = 0;
|
|
180
|
+
connect();
|
|
181
|
+
});
|
|
182
|
+
return () => {
|
|
183
|
+
stopped = true;
|
|
184
|
+
forget?.();
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
clearTimeout(opening);
|
|
187
|
+
clearTimeout(silence);
|
|
188
|
+
const ws = socket;
|
|
189
|
+
const left = silent;
|
|
190
|
+
socket = null;
|
|
191
|
+
silent = null;
|
|
192
|
+
ws?.close();
|
|
193
|
+
left?.close();
|
|
194
|
+
setConnected(false);
|
|
195
|
+
};
|
|
196
|
+
}
|
|
35
197
|
/** Holds one socket open while `enabled`, reopening it with backoff after it
|
|
36
198
|
* drops, and from scratch whenever `connectionKey` changes. */
|
|
37
|
-
function useReconnectingSocket({ open, path, connectionKey, enabled, onOpen, onMessage, onClose }) {
|
|
199
|
+
function useReconnectingSocket({ open, path, connectionKey, enabled, onOpen, onMessage, onClose, whenReachable, heartbeat }) {
|
|
38
200
|
const [connected, setConnected] = useState(false);
|
|
39
201
|
const latest = useRef({
|
|
40
202
|
open,
|
|
41
203
|
path,
|
|
42
204
|
onOpen,
|
|
43
205
|
onMessage,
|
|
44
|
-
onClose
|
|
206
|
+
onClose,
|
|
207
|
+
whenReachable,
|
|
208
|
+
heartbeat
|
|
45
209
|
});
|
|
46
210
|
latest.current = {
|
|
47
211
|
open,
|
|
48
212
|
path,
|
|
49
213
|
onOpen,
|
|
50
214
|
onMessage,
|
|
51
|
-
onClose
|
|
215
|
+
onClose,
|
|
216
|
+
whenReachable,
|
|
217
|
+
heartbeat
|
|
52
218
|
};
|
|
53
219
|
useEffect(() => {
|
|
54
220
|
if (!enabled || !latest.current.open) return;
|
|
55
|
-
|
|
56
|
-
let socket = null;
|
|
57
|
-
let attempts = 0;
|
|
58
|
-
let timer;
|
|
59
|
-
const retry = () => {
|
|
60
|
-
const delay = Math.min(INITIAL_RETRY_MS * 2 ** attempts, MAX_RETRY_MS);
|
|
61
|
-
attempts += 1;
|
|
62
|
-
timer = setTimeout(connect, delay);
|
|
63
|
-
};
|
|
64
|
-
const failed = () => {
|
|
65
|
-
if (stopped) return;
|
|
66
|
-
latest.current.onClose();
|
|
67
|
-
retry();
|
|
68
|
-
};
|
|
69
|
-
const attach = (ws) => {
|
|
70
|
-
if (stopped) {
|
|
71
|
-
ws.close();
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
socket = ws;
|
|
75
|
-
const opened = () => {
|
|
76
|
-
if (socket !== ws) return;
|
|
77
|
-
attempts = 0;
|
|
78
|
-
setConnected(true);
|
|
79
|
-
latest.current.onOpen();
|
|
80
|
-
};
|
|
81
|
-
const closed = () => {
|
|
82
|
-
if (socket !== ws) return;
|
|
83
|
-
socket = null;
|
|
84
|
-
setConnected(false);
|
|
85
|
-
latest.current.onClose();
|
|
86
|
-
if (!stopped) retry();
|
|
87
|
-
};
|
|
88
|
-
ws.addEventListener("open", opened);
|
|
89
|
-
ws.addEventListener("message", (event) => {
|
|
90
|
-
if (socket === ws) latest.current.onMessage(event.data);
|
|
91
|
-
});
|
|
92
|
-
ws.addEventListener("close", closed);
|
|
93
|
-
if (ws.readyState === SOCKET_OPEN) opened();
|
|
94
|
-
else if (ws.readyState === SOCKET_CLOSED) closed();
|
|
95
|
-
};
|
|
96
|
-
function connect() {
|
|
97
|
-
timer = void 0;
|
|
98
|
-
const opener = latest.current.open;
|
|
99
|
-
if (!opener) return;
|
|
100
|
-
let made;
|
|
101
|
-
try {
|
|
102
|
-
made = opener(latest.current.path());
|
|
103
|
-
} catch {
|
|
104
|
-
failed();
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if ("then" in made) made.then(attach, failed);
|
|
108
|
-
else attach(made);
|
|
109
|
-
}
|
|
110
|
-
connect();
|
|
111
|
-
return () => {
|
|
112
|
-
stopped = true;
|
|
113
|
-
clearTimeout(timer);
|
|
114
|
-
const ws = socket;
|
|
115
|
-
socket = null;
|
|
116
|
-
ws?.close();
|
|
117
|
-
setConnected(false);
|
|
118
|
-
};
|
|
221
|
+
return holdSocket(latest, setConnected);
|
|
119
222
|
}, [enabled, connectionKey]);
|
|
120
223
|
return connected;
|
|
121
224
|
}
|
|
122
|
-
function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
|
|
225
|
+
function sessionEvents({ openSocket, hidden, whenShown, previewsByRef = false }) {
|
|
123
226
|
const openFeeds = /* @__PURE__ */ new Map();
|
|
124
227
|
const listeners = /* @__PURE__ */ new Set();
|
|
125
228
|
let fedMachines = /* @__PURE__ */ new Set();
|
|
@@ -139,41 +242,66 @@ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
|
|
|
139
242
|
listeners.delete(notify);
|
|
140
243
|
};
|
|
141
244
|
}
|
|
245
|
+
const waiting = /* @__PURE__ */ new Map();
|
|
246
|
+
function whenListed(machine, tryNow) {
|
|
247
|
+
const feeds = waiting.get(machine) ?? /* @__PURE__ */ new Set();
|
|
248
|
+
waiting.set(machine, feeds.add(tryNow));
|
|
249
|
+
return () => {
|
|
250
|
+
feeds.delete(tryNow);
|
|
251
|
+
if (feeds.size === 0) waiting.delete(machine);
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
/** The listing answered, so the platform can be reached: a feed waiting to
|
|
255
|
+
* try a machine the listing shows connected again tries at once, once for
|
|
256
|
+
* each time it drops. */
|
|
257
|
+
function listed(machines) {
|
|
258
|
+
for (const machine of machines) if (isConnected(machine)) for (const tryNow of [...waiting.get(machine.id) ?? []]) tryNow();
|
|
259
|
+
}
|
|
142
260
|
/** The machines a session feed is open to. */
|
|
143
261
|
function useFedMachines() {
|
|
144
262
|
return useSyncExternalStore(subscribe, () => fedMachines);
|
|
145
263
|
}
|
|
146
264
|
/** The transcript owns the cursor; this only reconnects from it. Frames are
|
|
147
265
|
* applied once per animation frame: the backlog a reconnect catches up on
|
|
148
|
-
* arrives in a burst, and rendering each frame of it plays the turn back.
|
|
266
|
+
* arrives in a burst, and rendering each frame of it plays the turn back.
|
|
267
|
+
* Out of sight, where none run, a streaming reply is applied about once a
|
|
268
|
+
* second and anything else at once, after it. */
|
|
149
269
|
function useSessionEvents(machine, id, cursor, onEvent) {
|
|
150
270
|
const key = `${machine}/${id}`;
|
|
151
271
|
const [feed, setFeed] = useState(null);
|
|
152
272
|
const pending = useRef([]);
|
|
153
273
|
const frame = useRef(null);
|
|
274
|
+
const held = useRef(null);
|
|
154
275
|
const onEventRef = useRef(onEvent);
|
|
155
276
|
onEventRef.current = onEvent;
|
|
156
|
-
const
|
|
277
|
+
const unschedule = useCallback(() => {
|
|
157
278
|
if (frame.current !== null) {
|
|
158
279
|
cancelAnimationFrame(frame.current);
|
|
159
280
|
frame.current = null;
|
|
160
281
|
}
|
|
282
|
+
if (held.current !== null) {
|
|
283
|
+
clearTimeout(held.current);
|
|
284
|
+
held.current = null;
|
|
285
|
+
}
|
|
286
|
+
}, []);
|
|
287
|
+
const flush = useCallback(() => {
|
|
288
|
+
unschedule();
|
|
161
289
|
const frames = pending.current;
|
|
162
290
|
pending.current = [];
|
|
163
291
|
for (const ev of frames) onEventRef.current(ev);
|
|
164
|
-
}, []);
|
|
292
|
+
}, [unschedule]);
|
|
165
293
|
useEffect(() => () => {
|
|
166
|
-
|
|
167
|
-
cancelAnimationFrame(frame.current);
|
|
168
|
-
frame.current = null;
|
|
169
|
-
}
|
|
294
|
+
unschedule();
|
|
170
295
|
pending.current = [];
|
|
171
296
|
}, [key]);
|
|
297
|
+
useEffect(() => whenShown?.(flush), [flush]);
|
|
172
298
|
const connected = useReconnectingSocket({
|
|
173
299
|
open: openSocket,
|
|
174
300
|
path: () => sessionEventsPath(machine, id, cursor?.() ?? 0, previewsByRef),
|
|
175
301
|
connectionKey: key,
|
|
176
302
|
enabled: cursor !== void 0,
|
|
303
|
+
whenReachable: (tryNow) => whenListed(machine, tryNow),
|
|
304
|
+
heartbeat: isHeartbeat,
|
|
177
305
|
onOpen: () => setFeed({
|
|
178
306
|
key,
|
|
179
307
|
open: true
|
|
@@ -193,8 +321,9 @@ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
|
|
|
193
321
|
return;
|
|
194
322
|
}
|
|
195
323
|
pending.current.push(parsed);
|
|
196
|
-
if (hidden?.()) flush
|
|
197
|
-
else if (
|
|
324
|
+
if (!hidden?.()) frame.current ??= requestAnimationFrame(flush);
|
|
325
|
+
else if (streams(parsed)) held.current ??= setTimeout(flush, HIDDEN_STREAM_MS);
|
|
326
|
+
else flush();
|
|
198
327
|
}
|
|
199
328
|
});
|
|
200
329
|
const open = feed?.key === key ? feed.open : void 0;
|
|
@@ -211,7 +340,8 @@ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
|
|
|
211
340
|
}
|
|
212
341
|
return {
|
|
213
342
|
useSessionEvents,
|
|
214
|
-
useFedMachines
|
|
343
|
+
useFedMachines,
|
|
344
|
+
listed
|
|
215
345
|
};
|
|
216
346
|
}
|
|
217
|
-
export { changesSubagents, reachedByFeed, sessionEvents, sessionEventsPath };
|
|
347
|
+
export { HIDDEN_STREAM_MS, changesSubagents, holdSocket, isHeartbeat, reachedByFeed, sessionEvents, sessionEventsPath };
|
package/dist/sessionGroups.d.ts
CHANGED
|
@@ -14,13 +14,13 @@ export interface ListedGroup<S = PwCodeSession> {
|
|
|
14
14
|
waiting: number;
|
|
15
15
|
running: number;
|
|
16
16
|
}
|
|
17
|
-
type Grouped = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'liveHost' | 'archivedAt' | 'group' | 'createdAt'>;
|
|
17
|
+
type Grouped = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'waitingForUsageLimit' | 'liveHost' | 'archivedAt' | 'group' | 'createdAt'>;
|
|
18
18
|
type Machines = ReadonlyMap<string, Pick<PwCodeMachine, 'status'>>;
|
|
19
19
|
export declare function patchGroup(groups: readonly SessionGroup[], id: string, patch: Partial<Omit<SessionGroup, 'id'>>): SessionGroup[];
|
|
20
20
|
/** The reader's group a session is in. One naming a group since deleted is in none. */
|
|
21
21
|
export declare function groupOf(groups: readonly SessionGroup[], session: Pick<PwCodeSession, 'group'>): SessionGroup | undefined;
|
|
22
|
-
/** A turn is running on a machine that still answers. */
|
|
23
|
-
export declare function isWorking(session: Pick<PwCodeSession, 'status'>, machine: Pick<PwCodeMachine, 'status'> | undefined): boolean;
|
|
22
|
+
/** A turn is running on a machine that still answers, and not held by a usage limit. */
|
|
23
|
+
export declare function isWorking(session: Pick<PwCodeSession, 'status' | 'waitingForUsageLimit'>, machine: Pick<PwCodeMachine, 'status'> | undefined): boolean;
|
|
24
24
|
/** Sessions as a group lists them: what waits on the reader, then what is
|
|
25
25
|
* live, newest begun first, then the rest, with how many wait and how many
|
|
26
26
|
* are working. */
|
package/dist/sessionGroups.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isMachineDown } from "./machine.js";
|
|
2
|
-
import { isActiveSession, isArchived, needsYou, newestCreatedFirst } from "./session.js";
|
|
2
|
+
import { isActiveSession, isArchived, needsYou, newestCreatedFirst, waitsOnUsageLimit } from "./session.js";
|
|
3
3
|
import { useCallback, useMemo } from "react";
|
|
4
4
|
// src/sessionGroups.ts
|
|
5
5
|
function patchGroup(groups, id, patch) {
|
|
@@ -12,9 +12,9 @@ function patchGroup(groups, id, patch) {
|
|
|
12
12
|
function groupOf(groups, session) {
|
|
13
13
|
return session.group ? groups.find((g) => g.id === session.group) : void 0;
|
|
14
14
|
}
|
|
15
|
-
/** A turn is running on a machine that still answers. */
|
|
15
|
+
/** A turn is running on a machine that still answers, and not held by a usage limit. */
|
|
16
16
|
function isWorking(session, machine) {
|
|
17
|
-
return session.status === "running" && !isMachineDown(machine);
|
|
17
|
+
return session.status === "running" && !waitsOnUsageLimit(session) && !isMachineDown(machine);
|
|
18
18
|
}
|
|
19
19
|
/** Sessions as a group lists them: what waits on the reader, then what is
|
|
20
20
|
* live, newest begun first, then the rest, with how many wait and how many
|
package/dist/sessionHeader.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
2
|
// src/sessionHeader.ts
|
|
3
3
|
/** The worktree `useSessionWorktree` read, read again whenever the live
|
|
4
4
|
* session reports it moved; undefined while the session works where it
|
|
5
5
|
* launched. */
|
|
6
6
|
function useFollowedWorktree(worktree, liveWorktree) {
|
|
7
7
|
const { data, mutate } = worktree;
|
|
8
|
+
const followed = useRef(liveWorktree);
|
|
8
9
|
useEffect(() => {
|
|
9
|
-
|
|
10
|
+
if (followed.current !== liveWorktree) {
|
|
11
|
+
followed.current = liveWorktree;
|
|
12
|
+
mutate();
|
|
13
|
+
}
|
|
10
14
|
}, [liveWorktree, mutate]);
|
|
11
15
|
return data?.root ? {
|
|
12
16
|
root: data.root,
|
package/dist/sessionList.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { sessionLabel, sessionStateText } from './wording.js';
|
|
|
9
9
|
type Session = Schemas['AgentSession'];
|
|
10
10
|
type Translate = PwCodeTranslator<'agents'>;
|
|
11
11
|
type Machines = ReadonlyMap<string, Pick<PwCodeMachine, 'status'>>;
|
|
12
|
-
type Listed = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'liveHost' | 'archivedAt' | 'pinnedAt' | 'group' | 'createdAt' | 'updatedAt'>;
|
|
12
|
+
type Listed = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'waitingForUsageLimit' | 'liveHost' | 'archivedAt' | 'pinnedAt' | 'group' | 'createdAt' | 'updatedAt'>;
|
|
13
13
|
/** Where a session dropped on a section goes: with the pinned ones, into one
|
|
14
14
|
* of the reader's groups or out of any, or into the archive. */
|
|
15
15
|
export type SessionDropTarget = {
|
|
@@ -74,12 +74,14 @@ export declare function sessionSearchStatus(session: Parameters<typeof sessionSt
|
|
|
74
74
|
} | undefined;
|
|
75
75
|
/** What a session's mark on a collapsed list is called: its label, its
|
|
76
76
|
* machine and its state. */
|
|
77
|
-
export declare function sessionRailLabel(session: Parameters<typeof sessionLabel>[0] & Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'name' | 'status'> | undefined, t: Translate): string;
|
|
77
|
+
export declare function sessionRailLabel(session: Parameters<typeof sessionLabel>[0] & Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'name' | 'status'> | undefined, t: Translate, resumeClock?: (at: string) => string): string;
|
|
78
78
|
/** A second line costs a row its height, so the state takes one only when the
|
|
79
|
-
* mark cannot express it: not "idle" or "running", but "waiting on you"
|
|
80
|
-
* dead machine. */
|
|
81
|
-
export declare function sessionRowState(session: Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate): {
|
|
79
|
+
* mark cannot express it: not "idle" or "running", but "waiting on you", a
|
|
80
|
+
* usage limit and when it resets, and a dead machine. */
|
|
81
|
+
export declare function sessionRowState(session: Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate, resumeClock?: (at: string) => string): {
|
|
82
82
|
stateText: string;
|
|
83
|
+
/** The tone the state's words read in. */
|
|
84
|
+
tone: ReturnType<typeof sessionVariant<'muted'>>;
|
|
83
85
|
showSecondLine: boolean;
|
|
84
86
|
live: boolean;
|
|
85
87
|
};
|
|
@@ -87,12 +89,15 @@ export declare function sessionRowState(session: Parameters<typeof sessionStateT
|
|
|
87
89
|
* archived one, listed with the archive, needs the mark. */
|
|
88
90
|
export declare function showsPinMark(session: Pick<PwCodeSession, 'pinnedAt' | 'archivedAt'>): boolean;
|
|
89
91
|
/** A session at work shows a turning mark, which tells it from one resting
|
|
90
|
-
* between turns by its shape and so holds with reduced motion.
|
|
91
|
-
*
|
|
92
|
-
|
|
92
|
+
* between turns by its shape and so holds with reduced motion. One held by a
|
|
93
|
+
* usage limit is still, and keeps a dot's tone for a host that draws only
|
|
94
|
+
* dots. Any other shows a dot in its state's tone, pulsing while it waits on
|
|
95
|
+
* the reader. */
|
|
96
|
+
export declare function sessionMark(session: Pick<PwCodeSession, 'status' | 'waitingForUsageLimit'>, machine: Pick<PwCodeMachine, 'status'> | undefined): {
|
|
93
97
|
working: true;
|
|
94
98
|
} | {
|
|
95
99
|
working: false;
|
|
100
|
+
usageLimit?: boolean;
|
|
96
101
|
tone: ReturnType<typeof sessionVariant<'success'>>;
|
|
97
102
|
pulse: boolean;
|
|
98
103
|
};
|
package/dist/sessionList.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isConnected, isMachineDown } from "./machine.js";
|
|
2
2
|
import { usePwCodeTranslations } from "./messages.js";
|
|
3
3
|
import { pastedPullRequestLabel, pullRequestLabel } from "./pullRequest.js";
|
|
4
|
-
import { isActiveSession, isArchived, isSession, needsYou, newestCreatedFirst, newestFirst, sessionKey, sessionVariant, spansMachines } from "./session.js";
|
|
4
|
+
import { isActiveSession, isArchived, isSession, needsYou, newestCreatedFirst, newestFirst, sessionKey, sessionVariant, spansMachines, waitsOnUsageLimit } from "./session.js";
|
|
5
5
|
import { DELETE_KEYS, menuCommand, nameToSave } from "./sessionActions.js";
|
|
6
6
|
import { groupOf, inFlightFirst, isWorking, listGroups } from "./sessionGroups.js";
|
|
7
7
|
import { sessionLabel, sessionStateText } from "./wording.js";
|
|
@@ -136,21 +136,23 @@ function sessionSearchStatus(session, machine, t) {
|
|
|
136
136
|
}
|
|
137
137
|
/** What a session's mark on a collapsed list is called: its label, its
|
|
138
138
|
* machine and its state. */
|
|
139
|
-
function sessionRailLabel(session, machine, t) {
|
|
139
|
+
function sessionRailLabel(session, machine, t, resumeClock) {
|
|
140
140
|
return [
|
|
141
141
|
sessionLabel(session, t),
|
|
142
142
|
machine?.name,
|
|
143
|
-
sessionStateText(session, machine, t)
|
|
143
|
+
sessionStateText(session, machine, t, resumeClock)
|
|
144
144
|
].filter(Boolean).join(" · ");
|
|
145
145
|
}
|
|
146
146
|
/** A second line costs a row its height, so the state takes one only when the
|
|
147
|
-
* mark cannot express it: not "idle" or "running", but "waiting on you"
|
|
148
|
-
* dead machine. */
|
|
149
|
-
function sessionRowState(session, machine, t) {
|
|
147
|
+
* mark cannot express it: not "idle" or "running", but "waiting on you", a
|
|
148
|
+
* usage limit and when it resets, and a dead machine. */
|
|
149
|
+
function sessionRowState(session, machine, t, resumeClock) {
|
|
150
150
|
const degraded = isMachineDown(machine);
|
|
151
|
+
const held = waitsOnUsageLimit(session);
|
|
151
152
|
return {
|
|
152
|
-
stateText: sessionStateText(session, machine, t),
|
|
153
|
-
|
|
153
|
+
stateText: sessionStateText(session, machine, t, resumeClock),
|
|
154
|
+
tone: held && !degraded ? "warning" : sessionVariant(session.status, machine, "muted"),
|
|
155
|
+
showSecondLine: degraded || held || session.status !== "idle" && session.status !== "running",
|
|
154
156
|
live: isActiveSession(session) && !degraded
|
|
155
157
|
};
|
|
156
158
|
}
|
|
@@ -160,10 +162,18 @@ function showsPinMark(session) {
|
|
|
160
162
|
return !!session.pinnedAt && isArchived(session);
|
|
161
163
|
}
|
|
162
164
|
/** A session at work shows a turning mark, which tells it from one resting
|
|
163
|
-
* between turns by its shape and so holds with reduced motion.
|
|
164
|
-
*
|
|
165
|
+
* between turns by its shape and so holds with reduced motion. One held by a
|
|
166
|
+
* usage limit is still, and keeps a dot's tone for a host that draws only
|
|
167
|
+
* dots. Any other shows a dot in its state's tone, pulsing while it waits on
|
|
168
|
+
* the reader. */
|
|
165
169
|
function sessionMark(session, machine) {
|
|
166
170
|
if (isWorking(session, machine)) return { working: true };
|
|
171
|
+
if (waitsOnUsageLimit(session) && !isMachineDown(machine)) return {
|
|
172
|
+
working: false,
|
|
173
|
+
usageLimit: true,
|
|
174
|
+
tone: "warning",
|
|
175
|
+
pulse: false
|
|
176
|
+
};
|
|
167
177
|
return {
|
|
168
178
|
working: false,
|
|
169
179
|
tone: sessionVariant(session.status, machine, "success"),
|
package/dist/sessionScreen.d.ts
CHANGED
|
@@ -95,9 +95,10 @@ export declare function workingActivity(transcript: Pick<TranscriptState, 'turnS
|
|
|
95
95
|
kind: 'working';
|
|
96
96
|
}>;
|
|
97
97
|
/** What the composer's activity line says: the feed reconnecting outranks a
|
|
98
|
-
* turn, and a turn waiting on a usage limit says so in
|
|
98
|
+
* turn or a command running, and a turn waiting on a usage limit says so in
|
|
99
|
+
* place of working. Of the commands running, it names the oldest. */
|
|
99
100
|
export declare function sessionActivity({ composer, transcript, liveState, claudeModel, }: {
|
|
100
|
-
composer: Pick<PwCodeComposer, 'reconnecting' | 'working' | 'checkingGoal'
|
|
101
|
+
composer: Pick<PwCodeComposer, 'reconnecting' | 'working' | 'checkingGoal'> & Partial<Pick<PwCodeComposer, 'runningCommands'>>;
|
|
101
102
|
transcript: TranscriptState | null;
|
|
102
103
|
liveState: PwCodeSessionState | null;
|
|
103
104
|
/** The session runs a Claude Code model on a machine where Claude Code runs. */
|
|
@@ -168,8 +169,12 @@ export declare function usePwCodeSessionScreen({ conversation, composer, read, m
|
|
|
168
169
|
/** Why the workspace's own settings, skills and hooks did not load. */
|
|
169
170
|
untrusted: string | null;
|
|
170
171
|
activity: PwCodeSessionActivity | null;
|
|
172
|
+
/** The turn waits at its account's usage limit, as the activity line
|
|
173
|
+
* says; not while the feed reconnects, which that line says instead. For
|
|
174
|
+
* `useClaudeAccountPanel`'s `waitingAtLimit`. */
|
|
175
|
+
waitingAtLimit: boolean;
|
|
171
176
|
goal: PwCodeGoalLabel | null;
|
|
172
|
-
commands: import("./command.js").
|
|
177
|
+
commands: import("./command.js").PwCodePaletteOption[];
|
|
173
178
|
showAuthor: boolean;
|
|
174
179
|
/** A message may go without text while images go with it. */
|
|
175
180
|
allowEmpty: boolean;
|
package/dist/sessionScreen.js
CHANGED
|
@@ -117,12 +117,15 @@ function workingActivity(transcript, tokens, word) {
|
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
/** What the composer's activity line says: the feed reconnecting outranks a
|
|
120
|
-
* turn, and a turn waiting on a usage limit says so in
|
|
120
|
+
* turn or a command running, and a turn waiting on a usage limit says so in
|
|
121
|
+
* place of working. Of the commands running, it names the oldest. */
|
|
121
122
|
function sessionActivity({ composer, transcript, liveState, claudeModel }, t, tTranscript) {
|
|
122
123
|
if (composer.reconnecting) return {
|
|
123
124
|
kind: "reconnecting",
|
|
124
125
|
text: t("detail.reconnecting")
|
|
125
126
|
};
|
|
127
|
+
const command = composer.runningCommands?.[0];
|
|
128
|
+
if (command) return workingActivity({ turnStartedAt: command.startedAt }, null, command.word);
|
|
126
129
|
if (!composer.working) return null;
|
|
127
130
|
if (transcript?.waitingForUsageLimit) return {
|
|
128
131
|
kind: "usageLimit",
|
|
@@ -170,6 +173,12 @@ function usePwCodeSessionScreen({ conversation, composer, read, machine, staleFo
|
|
|
170
173
|
recheck,
|
|
171
174
|
refetch
|
|
172
175
|
]);
|
|
176
|
+
const activity = sessionActivity({
|
|
177
|
+
composer,
|
|
178
|
+
transcript,
|
|
179
|
+
liveState,
|
|
180
|
+
claudeModel: claude.available && isClaudeModel(settings.model.value)
|
|
181
|
+
}, t, tTranscript);
|
|
173
182
|
return {
|
|
174
183
|
/** The session's state in a sentence, for a screen reader. */
|
|
175
184
|
statusText: composer.status ? sessionStatusText({
|
|
@@ -182,19 +191,21 @@ function usePwCodeSessionScreen({ conversation, composer, read, machine, staleFo
|
|
|
182
191
|
act
|
|
183
192
|
},
|
|
184
193
|
/** The transcript has yet to load for the first time. */
|
|
185
|
-
loading: read.isLoading && !detail,
|
|
194
|
+
loading: read.isLoading && !detail && !conversation.endOnly,
|
|
186
195
|
/** Shown in place of a transcript that never loaded: why, or undefined
|
|
187
196
|
* for the host's own line. */
|
|
188
197
|
failed: loadFailure(read.error, !!detail, describeError),
|
|
189
198
|
retry,
|
|
190
199
|
/** Why the workspace's own settings, skills and hooks did not load. */
|
|
191
|
-
untrusted: detail?.workspaceUntrusted ? t("detail.untrusted"
|
|
192
|
-
|
|
193
|
-
composer
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
untrusted: detail?.workspaceUntrusted ? t("detail.untrusted", {
|
|
201
|
+
workspace: detail.workspace,
|
|
202
|
+
machine: composer.machineName
|
|
203
|
+
}) : null,
|
|
204
|
+
activity,
|
|
205
|
+
/** The turn waits at its account's usage limit, as the activity line
|
|
206
|
+
* says; not while the feed reconnects, which that line says instead. For
|
|
207
|
+
* `useClaudeAccountPanel`'s `waitingAtLimit`. */
|
|
208
|
+
waitingAtLimit: activity?.kind === "usageLimit",
|
|
198
209
|
goal: goalLabel(conversation.goal, t),
|
|
199
210
|
commands: paletteOptions(composer.palette, claude.available ? t("claude.choose") : void 0, t("detail.archiveCommand")),
|
|
200
211
|
showAuthor: conversation.all.some((m) => m.author),
|