@parallelworks/code 0.4.0 → 0.5.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 +39 -12
- 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 +200 -0
- package/dist/chatStrings.d.ts +1 -0
- package/dist/chatStrings.js +2 -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 +5 -1
- package/dist/command.js +6 -1
- package/dist/createPwCodeApi.d.ts +70 -1
- package/dist/createPwCodeApi.js +4 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -4
- package/dist/locales/en/agentTranscript.js +2 -1
- package/dist/locales/en/agents.js +16 -3
- package/dist/locales/en.d.ts +13 -0
- package/dist/locales/es/agentTranscript.js +2 -1
- package/dist/locales/es/agents.js +16 -3
- package/dist/locales/ja/agentTranscript.js +2 -1
- package/dist/locales/ja/agents.js +16 -3
- package/dist/locales/ko/agentTranscript.js +2 -1
- package/dist/locales/ko/agents.js +16 -3
- package/dist/locales/zh/agentTranscript.js +2 -1
- package/dist/locales/zh/agents.js +16 -3
- package/dist/notices.d.ts +2 -0
- package/dist/notices.js +20 -13
- package/dist/query.d.ts +4 -1
- package/dist/query.js +9 -3
- package/dist/session.d.ts +6 -0
- package/dist/session.js +5 -1
- package/dist/sessionEvents.d.ts +29 -2
- package/dist/sessionEvents.js +187 -73
- 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 +5 -1
- package/dist/sessionScreen.js +12 -7
- package/dist/sessionsApi.d.ts +19 -3
- package/dist/sessionsApi.js +100 -12
- package/dist/sessionsFeed.d.ts +22 -0
- package/dist/sessionsFeed.js +125 -0
- package/dist/todos.d.ts +42 -0
- package/dist/todos.js +104 -0
- package/dist/transcript.d.ts +1 -2
- package/dist/transcript.js +63 -102
- package/dist/transcriptRead.d.ts +56 -0
- package/dist/transcriptRead.js +121 -0
- package/dist/useComposer.d.ts +14 -5
- package/dist/useComposer.js +20 -7
- package/dist/useComposerImages.js +3 -4
- package/dist/useComposerPastes.js +3 -8
- package/dist/useConversation.d.ts +6 -0
- package/dist/useConversation.js +72 -5
- package/dist/useMounted.d.ts +3 -0
- package/dist/useMounted.js +14 -0
- package/dist/useSubagent.d.ts +2 -0
- package/dist/useSubagent.js +2 -0
- package/dist/wording.d.ts +5 -2
- package/dist/wording.js +6 -4
- package/locales/en/agentTranscript.json +2 -1
- package/locales/en/agents.json +14 -2
- package/locales/es/agentTranscript.json +2 -1
- package/locales/es/agents.json +14 -2
- package/locales/ja/agentTranscript.json +2 -1
- package/locales/ja/agents.json +14 -2
- package/locales/ko/agentTranscript.json +2 -1
- package/locales/ko/agents.json +14 -2
- package/locales/zh/agentTranscript.json +2 -1
- package/locales/zh/agents.json +14 -2
- package/package.json +2 -2
package/dist/sessionsApi.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "./apiClient.js";
|
|
1
2
|
import { bytesToBase64 } from "./base64.js";
|
|
2
3
|
import { PREVIEWS_BY_REF } from "./images.js";
|
|
3
4
|
import { createQuery } from "./query.js";
|
|
@@ -5,8 +6,11 @@ import { machinesById } from "./machine.js";
|
|
|
5
6
|
import { labeledPullRequests } from "./pullRequestList.js";
|
|
6
7
|
import { isSession, triageSessions } from "./session.js";
|
|
7
8
|
import { approvalAnswerBody } from "./transcript.js";
|
|
8
|
-
import {
|
|
9
|
+
import { createTranscriptReads } from "./transcriptRead.js";
|
|
10
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
11
|
+
import { unstable_serialize, useSWRConfig } from "swr";
|
|
9
12
|
import { DateTime } from "luxon";
|
|
13
|
+
import { toApiError } from "@parallelworks/problem";
|
|
10
14
|
// src/sessionsApi.ts
|
|
11
15
|
var SESSIONS_REFRESH_MS = 5e3;
|
|
12
16
|
var WAITING_REFRESH_MS = 3e4;
|
|
@@ -18,6 +22,7 @@ var SUBAGENTS_REFRESH_MS = 1e3;
|
|
|
18
22
|
function cachedCopyCurrent(listed, cached) {
|
|
19
23
|
return !!listed && listed.status !== "running" && listed.status === cached.status && listed.messages === cached.messages && listed.updatedAt === cached.updatedAt;
|
|
20
24
|
}
|
|
25
|
+
var SESSION_DETAIL = "/api/code/machines/{machine}/sessions/{id}";
|
|
21
26
|
var SESSION_DETAIL_READ = {
|
|
22
27
|
revalidateIfStale: false,
|
|
23
28
|
revalidateOnFocus: false,
|
|
@@ -147,15 +152,73 @@ function sessionPath(s) {
|
|
|
147
152
|
id: s.id
|
|
148
153
|
} } };
|
|
149
154
|
}
|
|
150
|
-
function sessionsApi(client, { previewsByRef = false } = {}) {
|
|
155
|
+
function sessionsApi(client, { previewsByRef = false, transcriptEndFirst = false } = {}, listed, feed) {
|
|
151
156
|
const useQuery = createQuery(client);
|
|
157
|
+
const transcripts = createTranscriptReads(client, previewsByRef);
|
|
158
|
+
const useFed = feed?.useFed ?? (() => false);
|
|
159
|
+
/** The listing, asked for again every `every` ms while no socket sends it.
|
|
160
|
+
* `live` holds that socket open. */
|
|
161
|
+
function useListing(enabled, every, live = false) {
|
|
162
|
+
const { onErrorRetry } = useSWRConfig();
|
|
163
|
+
const fed = useFed();
|
|
164
|
+
const config = useMemo(() => ({
|
|
165
|
+
refreshInterval: fed ? 0 : every,
|
|
166
|
+
onSuccess: (listing) => {
|
|
167
|
+
listed?.(listing.machines ?? []);
|
|
168
|
+
feed?.reachable();
|
|
169
|
+
},
|
|
170
|
+
onErrorRetry: (error, key, swr, revalidate, attempt) => {
|
|
171
|
+
if (toApiError(error).code === "network") {
|
|
172
|
+
setTimeout(() => void revalidate(attempt), SESSIONS_REFRESH_MS);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
onErrorRetry(error, key, swr, revalidate, attempt);
|
|
176
|
+
}
|
|
177
|
+
}), [
|
|
178
|
+
every,
|
|
179
|
+
fed,
|
|
180
|
+
onErrorRetry
|
|
181
|
+
]);
|
|
182
|
+
const response = useQuery("/api/code/sessions", enabled ? void 0 : null, config);
|
|
183
|
+
const { mutate } = response;
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (!live || !enabled || !feed) return;
|
|
186
|
+
return feed.read((listing) => void mutate(listing, { revalidate: false }));
|
|
187
|
+
}, [
|
|
188
|
+
live,
|
|
189
|
+
enabled,
|
|
190
|
+
mutate
|
|
191
|
+
]);
|
|
192
|
+
return {
|
|
193
|
+
get data() {
|
|
194
|
+
return response.data;
|
|
195
|
+
},
|
|
196
|
+
get error() {
|
|
197
|
+
return response.error;
|
|
198
|
+
},
|
|
199
|
+
get isValidating() {
|
|
200
|
+
return response.isValidating;
|
|
201
|
+
},
|
|
202
|
+
get isLoading() {
|
|
203
|
+
return response.isLoading;
|
|
204
|
+
},
|
|
205
|
+
mutate: useCallback(async (...args) => {
|
|
206
|
+
const landed = feed?.pause();
|
|
207
|
+
try {
|
|
208
|
+
return await mutate(...args);
|
|
209
|
+
} finally {
|
|
210
|
+
landed?.();
|
|
211
|
+
}
|
|
212
|
+
}, [mutate])
|
|
213
|
+
};
|
|
214
|
+
}
|
|
152
215
|
/** Every session on every machine the reader can reach, with each machine's reachability. */
|
|
153
216
|
function useSessions() {
|
|
154
|
-
return
|
|
217
|
+
return useListing(true, SESSIONS_REFRESH_MS, true);
|
|
155
218
|
}
|
|
156
219
|
/** Every listing asks each machine, so an app-wide count polls slower; the list's own poll keeps it current beside the list. */
|
|
157
220
|
function useWaitingSessionCount(enabled) {
|
|
158
|
-
const { data } =
|
|
221
|
+
const { data } = useListing(enabled, WAITING_REFRESH_MS);
|
|
159
222
|
return useMemo(() => data ? triageSessions(data.sessions ?? [], machinesById(data.machines ?? [])).blocked.length : 0, [data]);
|
|
160
223
|
}
|
|
161
224
|
/** `fresh` once this visit has fetched the session: a copy cached by an earlier
|
|
@@ -164,18 +227,30 @@ function sessionsApi(client, { previewsByRef = false } = {}) {
|
|
|
164
227
|
* A cached copy the listed row says the session has moved past stays hidden
|
|
165
228
|
* until that fetch answers, so the newer turns don't land under the reader. */
|
|
166
229
|
function useSessionDetail(machine, id, listed) {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
230
|
+
const init = useMemo(() => {
|
|
231
|
+
return { params: {
|
|
232
|
+
path: {
|
|
233
|
+
machine,
|
|
234
|
+
id
|
|
235
|
+
},
|
|
236
|
+
...previewsByRef ? { query: { previews: PREVIEWS_BY_REF } } : {}
|
|
237
|
+
} };
|
|
238
|
+
}, [machine, id]);
|
|
239
|
+
const read = useCallback((name, signal) => transcripts.read(machine, id, name, signal), [machine, id]);
|
|
240
|
+
const { data, error, isLoading, isValidating, mutate } = useQuery(SESSION_DETAIL, init, SESSION_DETAIL_READ, true, transcriptEndFirst ? read : void 0);
|
|
241
|
+
const name = useMemo(() => unstable_serialize([
|
|
242
|
+
"api",
|
|
243
|
+
SESSION_DETAIL,
|
|
244
|
+
init
|
|
245
|
+
]), [init]);
|
|
246
|
+
const tail = useSyncExternalStore(transcripts.subscribe, () => transcripts.tail(name), () => void 0);
|
|
174
247
|
const [current] = useState(() => data !== void 0 && cachedCopyCurrent(listed, data));
|
|
175
248
|
const answered = useReadThisVisit(data, isValidating, mutate);
|
|
176
249
|
const hidden = !current && !answered;
|
|
250
|
+
const shown = hidden ? void 0 : data;
|
|
177
251
|
return {
|
|
178
|
-
data:
|
|
252
|
+
data: shown,
|
|
253
|
+
preview: shown === void 0 ? tail : void 0,
|
|
179
254
|
error,
|
|
180
255
|
isLoading: isLoading || hidden,
|
|
181
256
|
mutate,
|
|
@@ -283,6 +358,18 @@ function sessionsApi(client, { previewsByRef = false } = {}) {
|
|
|
283
358
|
return thrown;
|
|
284
359
|
}
|
|
285
360
|
}
|
|
361
|
+
async function dismissSubagent(machine, id, subId) {
|
|
362
|
+
try {
|
|
363
|
+
const { error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/subagents/{subId}/dismiss", { params: { path: {
|
|
364
|
+
machine,
|
|
365
|
+
id,
|
|
366
|
+
subId
|
|
367
|
+
} } });
|
|
368
|
+
return error ?? null;
|
|
369
|
+
} catch (thrown) {
|
|
370
|
+
return thrown;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
286
373
|
async function stopAllSubagents(machine, id) {
|
|
287
374
|
try {
|
|
288
375
|
const { error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/subagents/stop-all", { params: { path: {
|
|
@@ -550,6 +637,7 @@ function sessionsApi(client, { previewsByRef = false } = {}) {
|
|
|
550
637
|
useSubagentDetail,
|
|
551
638
|
stopSubagent,
|
|
552
639
|
stopAllSubagents,
|
|
640
|
+
dismissSubagent,
|
|
553
641
|
useSessionWorktree,
|
|
554
642
|
leaveWorktree,
|
|
555
643
|
useSessionMutations,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Schemas } from './apiClient.js';
|
|
2
|
+
import { type PwCodeSocketOptions } from './sessionEvents.js';
|
|
3
|
+
type Listing = Schemas['AgentSessionsResponse'];
|
|
4
|
+
/** Where the platform sends the sessions listing as it changes. */
|
|
5
|
+
export declare const SESSIONS_FEED_PATH = "/ws/code/sessions?heartbeat=10";
|
|
6
|
+
/** The sessions listing as the platform sends it over a socket: at once, and
|
|
7
|
+
* again each time it changes. A listing that is polled for shows a change up
|
|
8
|
+
* to a poll late, and when a connection that went silent returns it waits
|
|
9
|
+
* most of a minute on the request it had out, which a fetch cannot take to
|
|
10
|
+
* another connection as a socket can. One socket serves every hook that reads
|
|
11
|
+
* the listing, open while any does and the app is in sight: out of sight the
|
|
12
|
+
* listing is not polled for either. */
|
|
13
|
+
export declare function sessionsFeed({ openSocket, hidden }: PwCodeSocketOptions,
|
|
14
|
+
/** Told each listing, once however many read it. */
|
|
15
|
+
onListing: (listing: Listing) => void): {
|
|
16
|
+
read: (reader: (listing: Listing) => void) => () => void;
|
|
17
|
+
pause: () => () => void;
|
|
18
|
+
useFed: () => boolean;
|
|
19
|
+
reachable: () => void;
|
|
20
|
+
};
|
|
21
|
+
export type SessionsFeed = ReturnType<typeof sessionsFeed>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { holdSocket, isHeartbeat } from "./sessionEvents.js";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
// src/sessionsFeed.ts
|
|
4
|
+
/** Where the platform sends the sessions listing as it changes. */
|
|
5
|
+
var SESSIONS_FEED_PATH = `/ws/code/sessions?heartbeat=10`;
|
|
6
|
+
function listingFrame(data) {
|
|
7
|
+
try {
|
|
8
|
+
const frame = JSON.parse(String(data));
|
|
9
|
+
return frame.type === "sessions" ? frame.listing : void 0;
|
|
10
|
+
} catch {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** The sessions listing as the platform sends it over a socket: at once, and
|
|
15
|
+
* again each time it changes. A listing that is polled for shows a change up
|
|
16
|
+
* to a poll late, and when a connection that went silent returns it waits
|
|
17
|
+
* most of a minute on the request it had out, which a fetch cannot take to
|
|
18
|
+
* another connection as a socket can. One socket serves every hook that reads
|
|
19
|
+
* the listing, open while any does and the app is in sight: out of sight the
|
|
20
|
+
* listing is not polled for either. */
|
|
21
|
+
function sessionsFeed({ openSocket, hidden }, onListing) {
|
|
22
|
+
const readers = /* @__PURE__ */ new Set();
|
|
23
|
+
const watchers = /* @__PURE__ */ new Set();
|
|
24
|
+
let fed = false;
|
|
25
|
+
let sent = false;
|
|
26
|
+
let stop;
|
|
27
|
+
let tryNow;
|
|
28
|
+
let writing = 0;
|
|
29
|
+
function setFed(next) {
|
|
30
|
+
if (fed !== next) {
|
|
31
|
+
fed = next;
|
|
32
|
+
for (const notify of [...watchers]) notify();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const socket = { current: {
|
|
36
|
+
open: openSocket,
|
|
37
|
+
path: () => SESSIONS_FEED_PATH,
|
|
38
|
+
onOpen: (revived) => {
|
|
39
|
+
sent &&= revived;
|
|
40
|
+
setFed(sent);
|
|
41
|
+
},
|
|
42
|
+
onClose: () => setFed(false),
|
|
43
|
+
onMessage: (data) => {
|
|
44
|
+
const listing = listingFrame(data);
|
|
45
|
+
if (!listing) return;
|
|
46
|
+
sent = true;
|
|
47
|
+
setFed(true);
|
|
48
|
+
onListing(listing);
|
|
49
|
+
for (const read of [...readers]) read(listing);
|
|
50
|
+
},
|
|
51
|
+
whenReachable: (now) => {
|
|
52
|
+
tryNow = now;
|
|
53
|
+
return () => {
|
|
54
|
+
tryNow = void 0;
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
heartbeat: (data) => {
|
|
58
|
+
if (hidden?.()) queueMicrotask(() => {
|
|
59
|
+
if (hidden()) leave();
|
|
60
|
+
});
|
|
61
|
+
return isHeartbeat(data);
|
|
62
|
+
}
|
|
63
|
+
} };
|
|
64
|
+
function open() {
|
|
65
|
+
if (!stop && openSocket && readers.size > 0 && writing === 0 && !hidden?.()) stop = holdSocket(socket, () => {});
|
|
66
|
+
}
|
|
67
|
+
function leave() {
|
|
68
|
+
if (stop) {
|
|
69
|
+
stop();
|
|
70
|
+
stop = void 0;
|
|
71
|
+
sent = false;
|
|
72
|
+
setFed(false);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Hands `reader` each listing until the returned call. */
|
|
76
|
+
function read(reader) {
|
|
77
|
+
readers.add(reader);
|
|
78
|
+
open();
|
|
79
|
+
return () => {
|
|
80
|
+
readers.delete(reader);
|
|
81
|
+
queueMicrotask(() => {
|
|
82
|
+
if (readers.size === 0) leave();
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** Leaves the socket until the returned call, while the page itself writes
|
|
87
|
+
* the listing or reads it again. A listing the platform sent before that
|
|
88
|
+
* would put back what it changed; another socket's first listing is asked
|
|
89
|
+
* for after it opened. The listing is polled for meanwhile. */
|
|
90
|
+
function pause() {
|
|
91
|
+
writing += 1;
|
|
92
|
+
leave();
|
|
93
|
+
let landed = false;
|
|
94
|
+
return () => {
|
|
95
|
+
if (!landed) {
|
|
96
|
+
landed = true;
|
|
97
|
+
writing -= 1;
|
|
98
|
+
open();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function watch(notify) {
|
|
103
|
+
watchers.add(notify);
|
|
104
|
+
return () => {
|
|
105
|
+
watchers.delete(notify);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** Whether the listing comes over the socket, so that nothing need poll for it. */
|
|
109
|
+
function useFed() {
|
|
110
|
+
return useSyncExternalStore(watch, () => fed, () => false);
|
|
111
|
+
}
|
|
112
|
+
/** The platform answered, so a socket waiting to try again tries at once,
|
|
113
|
+
* and one left while the app was out of sight opens again. */
|
|
114
|
+
function reachable() {
|
|
115
|
+
open();
|
|
116
|
+
tryNow?.();
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
read,
|
|
120
|
+
pause,
|
|
121
|
+
useFed,
|
|
122
|
+
reachable
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export { SESSIONS_FEED_PATH, sessionsFeed };
|
package/dist/todos.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { TodoItem } from '@parallelworks/ui/ai/headless';
|
|
2
|
+
import type { PwCodeHistoryItem } from './types.js';
|
|
3
|
+
/** TodoWrite's whole list, which its arguments carry; null when they hold none. */
|
|
4
|
+
export declare function todosFromArgs(argsJSON: string): TodoItem[] | null;
|
|
5
|
+
/** The list a TodoWrite call pins above the composer: empty once every task
|
|
6
|
+
* is done, as the terminal drops it, and null for arguments that hold no
|
|
7
|
+
* list, which leave the pinned one as it was. */
|
|
8
|
+
export declare function pinnedTodos(argsJSON: string): TodoItem[] | null;
|
|
9
|
+
/** The list a conversation's history leaves pinned: its last TodoWrite's. */
|
|
10
|
+
export declare function todosFromHistory(history: PwCodeHistoryItem[]): TodoItem[];
|
|
11
|
+
/** What a task reads as: what it is doing while it runs, otherwise what it is. */
|
|
12
|
+
export declare function todoLabel(todo: TodoItem): string;
|
|
13
|
+
/** At most `limit` tasks, from the one before the running one, and how many
|
|
14
|
+
* are left out by whether they are done, since the tail can hide pending ones. */
|
|
15
|
+
export declare function todoWindow(todos: TodoItem[], limit: number): {
|
|
16
|
+
visible: TodoItem[];
|
|
17
|
+
hiddenDone: number;
|
|
18
|
+
hiddenOther: number;
|
|
19
|
+
};
|
|
20
|
+
export interface PwCodeTodoRow {
|
|
21
|
+
todo: TodoItem;
|
|
22
|
+
label: string;
|
|
23
|
+
/** Its status in words, for a screen reader beside the status mark. */
|
|
24
|
+
statusWord: string;
|
|
25
|
+
}
|
|
26
|
+
export interface PwCodeTodoPanel {
|
|
27
|
+
title: string;
|
|
28
|
+
/** How far along the list is, such as "2 of 5 done". */
|
|
29
|
+
progress: string;
|
|
30
|
+
/** What the running task is doing, which a folded panel names. */
|
|
31
|
+
running: string | null;
|
|
32
|
+
rows: PwCodeTodoRow[];
|
|
33
|
+
/** The control that shows every task, or fewer again; null when every task fits. */
|
|
34
|
+
more: {
|
|
35
|
+
label: string;
|
|
36
|
+
all: boolean;
|
|
37
|
+
toggle: () => void;
|
|
38
|
+
} | null;
|
|
39
|
+
}
|
|
40
|
+
/** The pinned task list as the terminal's panel shows it: a few rows from the
|
|
41
|
+
* one before the running task, and a control for the rest. */
|
|
42
|
+
export declare function useTodoPanel(todos: TodoItem[]): PwCodeTodoPanel;
|
package/dist/todos.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { usePwCodeTranslations } from "./messages.js";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
// src/todos.ts
|
|
4
|
+
var TODO_STATUSES = /* @__PURE__ */ new Set([
|
|
5
|
+
"pending",
|
|
6
|
+
"in_progress",
|
|
7
|
+
"completed"
|
|
8
|
+
]);
|
|
9
|
+
/** TodoWrite's whole list, which its arguments carry; null when they hold none. */
|
|
10
|
+
function todosFromArgs(argsJSON) {
|
|
11
|
+
let args;
|
|
12
|
+
try {
|
|
13
|
+
args = JSON.parse(argsJSON);
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const raw = args && typeof args === "object" ? args["todos"] : void 0;
|
|
18
|
+
if (!Array.isArray(raw)) return null;
|
|
19
|
+
return raw.flatMap((t) => {
|
|
20
|
+
const { content, status, activeForm } = t && typeof t === "object" ? t : {};
|
|
21
|
+
if (typeof content !== "string" || typeof status !== "string" || !TODO_STATUSES.has(status)) return [];
|
|
22
|
+
return [{
|
|
23
|
+
content,
|
|
24
|
+
status,
|
|
25
|
+
...typeof activeForm === "string" ? { activeForm } : {}
|
|
26
|
+
}];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** The list a TodoWrite call pins above the composer: empty once every task
|
|
30
|
+
* is done, as the terminal drops it, and null for arguments that hold no
|
|
31
|
+
* list, which leave the pinned one as it was. */
|
|
32
|
+
function pinnedTodos(argsJSON) {
|
|
33
|
+
const todos = todosFromArgs(argsJSON);
|
|
34
|
+
if (!todos) return null;
|
|
35
|
+
return todos.some((t) => t.status !== "completed") ? todos : [];
|
|
36
|
+
}
|
|
37
|
+
/** The list a conversation's history leaves pinned: its last TodoWrite's. */
|
|
38
|
+
function todosFromHistory(history) {
|
|
39
|
+
let pinned = [];
|
|
40
|
+
for (const item of history) if (item.kind === "tool_call" && item.toolName === "TodoWrite") pinned = pinnedTodos(item.toolArgs ?? "") ?? pinned;
|
|
41
|
+
return pinned;
|
|
42
|
+
}
|
|
43
|
+
/** What a task reads as: what it is doing while it runs, otherwise what it is. */
|
|
44
|
+
function todoLabel(todo) {
|
|
45
|
+
return todo.status === "in_progress" && todo.activeForm ? todo.activeForm : todo.content;
|
|
46
|
+
}
|
|
47
|
+
/** At most `limit` tasks, from the one before the running one, and how many
|
|
48
|
+
* are left out by whether they are done, since the tail can hide pending ones. */
|
|
49
|
+
function todoWindow(todos, limit) {
|
|
50
|
+
const size = Math.max(limit, 1);
|
|
51
|
+
if (todos.length <= size) return {
|
|
52
|
+
visible: todos,
|
|
53
|
+
hiddenDone: 0,
|
|
54
|
+
hiddenOther: 0
|
|
55
|
+
};
|
|
56
|
+
const running = todos.findIndex((t) => t.status === "in_progress");
|
|
57
|
+
const start = Math.min(Math.max(running - 1, 0), todos.length - size);
|
|
58
|
+
const visible = todos.slice(start, start + size);
|
|
59
|
+
const hidden = [...todos.slice(0, start), ...todos.slice(start + size)];
|
|
60
|
+
const hiddenDone = hidden.filter((t) => t.status === "completed").length;
|
|
61
|
+
return {
|
|
62
|
+
visible,
|
|
63
|
+
hiddenDone,
|
|
64
|
+
hiddenOther: hidden.length - hiddenDone
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
var PANEL_ROWS = 6;
|
|
68
|
+
/** The pinned task list as the terminal's panel shows it: a few rows from the
|
|
69
|
+
* one before the running task, and a control for the rest. */
|
|
70
|
+
function useTodoPanel(todos) {
|
|
71
|
+
const t = usePwCodeTranslations("agents");
|
|
72
|
+
const words = usePwCodeTranslations("agentTranscript");
|
|
73
|
+
const [all, setAll] = useState(false);
|
|
74
|
+
const { visible, hiddenDone, hiddenOther } = all ? {
|
|
75
|
+
visible: todos,
|
|
76
|
+
hiddenDone: 0,
|
|
77
|
+
hiddenOther: 0
|
|
78
|
+
} : todoWindow(todos, PANEL_ROWS);
|
|
79
|
+
const running = todos.find((todo) => todo.status === "in_progress");
|
|
80
|
+
const statusWord = {
|
|
81
|
+
completed: words("transcript.todoCompleted"),
|
|
82
|
+
in_progress: words("transcript.todoInProgress"),
|
|
83
|
+
pending: words("transcript.todoPending")
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
title: words("transcript.tasks"),
|
|
87
|
+
progress: t("tasks.progress", {
|
|
88
|
+
done: todos.filter((todo) => todo.status === "completed").length,
|
|
89
|
+
total: todos.length
|
|
90
|
+
}),
|
|
91
|
+
running: running ? todoLabel(running) : null,
|
|
92
|
+
rows: visible.map((todo) => ({
|
|
93
|
+
todo,
|
|
94
|
+
label: todoLabel(todo),
|
|
95
|
+
statusWord: statusWord[todo.status]
|
|
96
|
+
})),
|
|
97
|
+
more: todos.length > PANEL_ROWS ? {
|
|
98
|
+
label: all ? t("tasks.fewer") : hiddenOther > 0 ? t("tasks.more", { count: hiddenDone + hiddenOther }) : t("tasks.moreCompleted", { count: hiddenDone }),
|
|
99
|
+
all,
|
|
100
|
+
toggle: () => setAll((shown) => !shown)
|
|
101
|
+
} : null
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export { pinnedTodos, todoLabel, todoWindow, todosFromArgs, todosFromHistory, useTodoPanel };
|
package/dist/transcript.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface TranscriptState {
|
|
|
22
22
|
reviews?: Record<string, string[]>;
|
|
23
23
|
decided?: string[];
|
|
24
24
|
turnEndSeq?: number;
|
|
25
|
+
todos?: TodoItem[];
|
|
25
26
|
}
|
|
26
27
|
export type StreamEffect = {
|
|
27
28
|
type: 'refetch';
|
|
@@ -101,8 +102,6 @@ export declare function turnRunning(state: TranscriptState | null): boolean;
|
|
|
101
102
|
export declare function bashRunning(state: TranscriptState | null): boolean;
|
|
102
103
|
/** What the agent records for a call a stop cut off (serverapi.UserInterruptedTool), so a stopped call reads live as it replays. */
|
|
103
104
|
export declare function userInterruptedTool(name: string): string;
|
|
104
|
-
/** TodoWrite's whole list, which its arguments carry; null when they hold none. */
|
|
105
|
-
export declare function todosFromArgs(argsJSON: string): TodoItem[] | null;
|
|
106
105
|
/** How a /goal loop step reads, in the reader's language. */
|
|
107
106
|
export type GoalNotice = (progress: PwCodeGoalProgress) => string;
|
|
108
107
|
/** How a compaction's line reads, in the reader's language; its summary opens under it. */
|