@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/startSession.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ export interface PwCodeStartMachine extends PwCodeMachine {
|
|
|
13
13
|
claudeCodeAllowed?: boolean | undefined;
|
|
14
14
|
}
|
|
15
15
|
/** The machines a session can start on, then those listed but not answering,
|
|
16
|
-
* each with computers
|
|
17
|
-
* one the reader has not touched, so it is not
|
|
16
|
+
* each with the workspace first, then computers, then resources. A resource
|
|
17
|
+
* with no agent on it is one the reader has not touched, so it is not
|
|
18
|
+
* counted as down. */
|
|
18
19
|
export declare function startMachines<M extends PwCodeStartMachine>(machines: readonly M[]): {
|
|
19
20
|
startable: M[];
|
|
20
21
|
down: M[];
|
|
@@ -25,16 +26,18 @@ export declare function startMachines<M extends PwCodeStartMachine>(machines: re
|
|
|
25
26
|
export declare function startingMode(mode: PermissionMode, machine: Pick<PwCodeStartMachine, 'remoteMaxPermissionMode' | 'permissionModes'> | undefined): PermissionMode;
|
|
26
27
|
/** Where a session starts: the machine, and the directory on it. */
|
|
27
28
|
export interface PwCodeStartLocation<M> {
|
|
28
|
-
/** The machines a session can start on, computers first. */
|
|
29
|
+
/** The machines a session can start on, the workspace then computers first. */
|
|
29
30
|
startable: M[];
|
|
30
|
-
/** The machines listed but not answering, computers first, so a missing one can be traced. */
|
|
31
|
+
/** The machines listed but not answering, the workspace then computers first, so a missing one can be traced. */
|
|
31
32
|
down: M[];
|
|
32
|
-
/** The machine picked, else the one picked last time, or the only one a session can start on. */
|
|
33
|
+
/** The machine picked, else the one picked last time, else the workspace or the only one a session can start on. */
|
|
33
34
|
machine: M | undefined;
|
|
35
|
+
/** The workspace a start waits for while it starts, when it is the machine the start would be on. */
|
|
36
|
+
pending: M | undefined;
|
|
34
37
|
pickMachine: (id: string) => void;
|
|
35
38
|
/** The directories the machine's sessions worked in, newest first. */
|
|
36
39
|
directories: RecentDirectory[];
|
|
37
|
-
/** The directory picked or typed,
|
|
40
|
+
/** The directory picked or typed, else the newest one, else the machine's home. */
|
|
38
41
|
directory: string;
|
|
39
42
|
/** The directory is typed rather than picked from the recent ones. */
|
|
40
43
|
typing: boolean;
|
|
@@ -87,7 +90,7 @@ export interface PwCodeStartControls {
|
|
|
87
90
|
* effort and account chip wait for one too. */
|
|
88
91
|
export declare function startControls(machine: Pick<PwCodeStartMachine, 'status' | 'remoteStart'> | undefined, starting: boolean): PwCodeStartControls;
|
|
89
92
|
type ClaudeMachine = Pick<PwCodeStartMachine, 'id' | 'claudeInstalled' | 'claudeCodeAllowed'>;
|
|
90
|
-
type StartApi = Pick<PwCodeApi, 'useClaudeModels' | 'useClaudeAccountNames' | 'createSession' | 'sendMessage' | 'useSessions'>;
|
|
93
|
+
type StartApi = Pick<PwCodeApi, 'useClaudeModels' | 'useClaudeAccountNames' | 'createSession' | 'sendMessage' | 'runSlashAction' | 'useSessions' | 'useSessionMutations'>;
|
|
91
94
|
/** A model last picked for a session, and the allocation that billed it. */
|
|
92
95
|
export interface PwCodeLastModel {
|
|
93
96
|
model?: string | undefined;
|
|
@@ -144,15 +147,26 @@ export interface PwCodeStartSession {
|
|
|
144
147
|
starting: boolean;
|
|
145
148
|
/** Why the last start failed: the machine's refusal, or what was thrown. */
|
|
146
149
|
error: unknown;
|
|
150
|
+
/** Why the last start was not tried, worded for the reader. */
|
|
151
|
+
blocked: string | null;
|
|
147
152
|
/** Starts the session with `prompt` as its first message. False hands the
|
|
148
153
|
* prompt back to the composer. */
|
|
149
154
|
start: (prompt: string) => Promise<boolean>;
|
|
155
|
+
/** A prompt can be held for the machine a start waits for. */
|
|
156
|
+
canHold: boolean;
|
|
157
|
+
/** The prompt held until that machine answers, if one is. */
|
|
158
|
+
held: string | null;
|
|
159
|
+
/** A held prompt whose start failed, which the composer takes back. */
|
|
160
|
+
heldFailed: boolean;
|
|
161
|
+
/** Takes the held prompt back, so it is not sent. */
|
|
162
|
+
takeHeld: () => string | null;
|
|
150
163
|
}
|
|
151
164
|
/** Starts a session, reads the listing again so it shows there, and hands it
|
|
152
|
-
* to `onStarted` once its first prompt is sent. With images,
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
|
|
165
|
+
* to `onStarted` once its first prompt is sent. With images, or for a typed
|
|
166
|
+
* `/goal` or `/plan`, the session is created empty first, then the images go
|
|
167
|
+
* with the prompt or the command runs; a session whose start fails after that
|
|
168
|
+
* is deleted, so nothing is left behind and a retry starts afresh. */
|
|
169
|
+
export declare function useStartSession(api: Pick<StartApi, 'createSession' | 'sendMessage' | 'runSlashAction' | 'useSessions' | 'useSessionMutations'>, options: {
|
|
156
170
|
machine: Pick<PwCodeStartMachine, 'id' | 'claudeCodeAllowed'> | undefined;
|
|
157
171
|
directory: string;
|
|
158
172
|
mode: PermissionMode;
|
|
@@ -166,6 +180,12 @@ export declare function useStartSession(api: Pick<StartApi, 'createSession' | 's
|
|
|
166
180
|
firstPrompt?: ((typed: string) => string) | undefined;
|
|
167
181
|
/** Something the first message needs has not arrived yet. */
|
|
168
182
|
waiting?: boolean | undefined;
|
|
183
|
+
/** The machine the start waits for while it is on its way, so a prompt sent now is held until it answers. */
|
|
184
|
+
pending?: string | undefined;
|
|
185
|
+
/** One of the reader's groups to put the session in. */
|
|
186
|
+
group?: string | undefined;
|
|
187
|
+
/** The session started, but its machine refused to put it in the group. */
|
|
188
|
+
onGroupRefused?: ((refusal: unknown) => void) | undefined;
|
|
169
189
|
/** The host opens the session. */
|
|
170
190
|
onStarted: (machine: string, sessionId: string) => void;
|
|
171
191
|
}): PwCodeStartSession;
|
package/dist/startSession.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { slashAction } from "./command.js";
|
|
2
|
+
import { canStartHere, isMachineDown, isStarting, isWorkspace, splitMachines } from "./machine.js";
|
|
3
|
+
import { usePwCodeTranslations } from "./messages.js";
|
|
2
4
|
import { canRunModel, isClaudeModel, runsClaude } from "./models.js";
|
|
3
5
|
import { recentDirectories } from "./session.js";
|
|
6
|
+
import { withImagePlaceholders } from "./useComposerImages.js";
|
|
4
7
|
import { rememberSentPrompt } from "./wording.js";
|
|
5
8
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
6
9
|
import { clampPermissionMode } from "@parallelworks/ui/ai/headless";
|
|
7
10
|
// src/startSession.ts
|
|
8
11
|
/** The machines a session can start on, then those listed but not answering,
|
|
9
|
-
* each with computers
|
|
10
|
-
* one the reader has not touched, so it is not
|
|
12
|
+
* each with the workspace first, then computers, then resources. A resource
|
|
13
|
+
* with no agent on it is one the reader has not touched, so it is not
|
|
14
|
+
* counted as down. */
|
|
11
15
|
function startMachines(machines) {
|
|
12
16
|
const ordered = (list) => {
|
|
13
17
|
const { computers, resources } = splitMachines(list);
|
|
14
|
-
return [
|
|
18
|
+
return [
|
|
19
|
+
...resources.filter(isWorkspace),
|
|
20
|
+
...computers,
|
|
21
|
+
...resources.filter((m) => !isWorkspace(m))
|
|
22
|
+
];
|
|
15
23
|
};
|
|
16
24
|
return {
|
|
17
25
|
startable: ordered(machines.filter(canStartHere)),
|
|
@@ -29,7 +37,10 @@ function useStartLocation(machines, sessions, preference) {
|
|
|
29
37
|
const { startable, down } = useMemo(() => startMachines(machines), [machines]);
|
|
30
38
|
const [machineId, setMachineId] = useState("");
|
|
31
39
|
const wanted = machineId || preference?.saved;
|
|
32
|
-
const
|
|
40
|
+
const chosen = startable.find((m) => m.id === wanted);
|
|
41
|
+
const starting = down.find((m) => isWorkspace(m) && isStarting(m));
|
|
42
|
+
const pending = chosen ? void 0 : starting;
|
|
43
|
+
const machine = chosen ?? (pending ? void 0 : startable.find(isWorkspace) ?? (startable.length === 1 ? startable[0] : void 0));
|
|
33
44
|
const directories = useMemo(() => recentDirectories(sessions, machine?.id), [sessions, machine]);
|
|
34
45
|
const [dir, setDir] = useState("");
|
|
35
46
|
const [typing, setTyping] = useState(false);
|
|
@@ -40,7 +51,7 @@ function useStartLocation(machines, sessions, preference) {
|
|
|
40
51
|
setDir("");
|
|
41
52
|
setTyping(false);
|
|
42
53
|
}, [machine?.id]);
|
|
43
|
-
const directory = typing ? dir : dir || directories[0]?.path || "";
|
|
54
|
+
const directory = typing ? dir : dir || directories[0]?.path || machine?.home || "";
|
|
44
55
|
const typeDirectory = (path) => {
|
|
45
56
|
setTyping(true);
|
|
46
57
|
setDir(path);
|
|
@@ -48,6 +59,7 @@ function useStartLocation(machines, sessions, preference) {
|
|
|
48
59
|
return {
|
|
49
60
|
startable,
|
|
50
61
|
down,
|
|
62
|
+
pending,
|
|
51
63
|
machine,
|
|
52
64
|
pickMachine: (id) => {
|
|
53
65
|
setMachineId(id);
|
|
@@ -159,32 +171,36 @@ function sessionBody(machine, { directory, mode, model, effort, allocation, acco
|
|
|
159
171
|
...prompt ? { prompt } : {}
|
|
160
172
|
};
|
|
161
173
|
}
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
|
|
174
|
+
/** `/goal` or `/plan` typed as the first prompt. The machine refuses either as
|
|
175
|
+
* a message, since each has a route of its own, as typed in an open session. */
|
|
176
|
+
function startCommand(typed) {
|
|
177
|
+
const action = slashAction(typed, {});
|
|
178
|
+
return action.kind === "goal" || action.kind === "plan" ? action : null;
|
|
165
179
|
}
|
|
166
180
|
/** Starts a session, reads the listing again so it shows there, and hands it
|
|
167
|
-
* to `onStarted` once its first prompt is sent. With images,
|
|
168
|
-
*
|
|
169
|
-
*
|
|
181
|
+
* to `onStarted` once its first prompt is sent. With images, or for a typed
|
|
182
|
+
* `/goal` or `/plan`, the session is created empty first, then the images go
|
|
183
|
+
* with the prompt or the command runs; a session whose start fails after that
|
|
184
|
+
* is deleted, so nothing is left behind and a retry starts afresh. */
|
|
170
185
|
function useStartSession(api, options) {
|
|
171
186
|
const { machine, directory, images, firstPrompt, onStarted } = options;
|
|
187
|
+
const t = usePwCodeTranslations("agents");
|
|
172
188
|
const { mutate } = api.useSessions();
|
|
189
|
+
const { deleteSession, groupSession } = api.useSessionMutations();
|
|
173
190
|
const [starting, setStarting] = useState(false);
|
|
174
191
|
const [error, setError] = useState(null);
|
|
175
|
-
const
|
|
176
|
-
const config = JSON.stringify([
|
|
177
|
-
machine?.id,
|
|
178
|
-
directory,
|
|
179
|
-
options.mode,
|
|
180
|
-
options.model,
|
|
181
|
-
options.effort,
|
|
182
|
-
options.allocation,
|
|
183
|
-
options.account
|
|
184
|
-
]);
|
|
192
|
+
const [blocked, setBlocked] = useState(null);
|
|
185
193
|
const ready = !!machine && directory.startsWith("/") && !starting && !options.waiting;
|
|
186
|
-
const started = (machineId, id, text) => {
|
|
194
|
+
const started = async (machineId, id, text) => {
|
|
187
195
|
rememberSentPrompt(machineId, id, text);
|
|
196
|
+
const { group, onGroupRefused } = options;
|
|
197
|
+
if (group) {
|
|
198
|
+
const refusal = await groupSession({
|
|
199
|
+
machineId,
|
|
200
|
+
id
|
|
201
|
+
}, group).catch((thrown) => thrown);
|
|
202
|
+
if (refusal) onGroupRefused?.(refusal);
|
|
203
|
+
}
|
|
188
204
|
mutate();
|
|
189
205
|
onStarted(machineId, id);
|
|
190
206
|
};
|
|
@@ -200,7 +216,7 @@ function useStartSession(api, options) {
|
|
|
200
216
|
const send = async (on, id, first) => {
|
|
201
217
|
const saved = images ? await images.saveTo(on.id, id) : [];
|
|
202
218
|
if (saved === null) return false;
|
|
203
|
-
const text =
|
|
219
|
+
const text = withImagePlaceholders(first, saved);
|
|
204
220
|
const { error: failed } = await api.sendMessage(on.id, id, {
|
|
205
221
|
text,
|
|
206
222
|
images: saved
|
|
@@ -209,36 +225,55 @@ function useStartSession(api, options) {
|
|
|
209
225
|
setError(failed);
|
|
210
226
|
return false;
|
|
211
227
|
}
|
|
212
|
-
started(on.id, id, text);
|
|
228
|
+
await started(on.id, id, text);
|
|
229
|
+
return true;
|
|
230
|
+
};
|
|
231
|
+
/** Runs the command, as typed in an open session, and sends the task `/plan`
|
|
232
|
+
* hands back as the first message. False once its refusal is kept. */
|
|
233
|
+
const run = async (on, id, typed, command) => {
|
|
234
|
+
const outcome = await api.runSlashAction(on.id, id, command, (path) => t("detail.planOnMachine", { path }));
|
|
235
|
+
if (outcome.kind === "refused") {
|
|
236
|
+
setError(outcome.error);
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
if (outcome.kind === "send") return send(on, id, outcome.text);
|
|
240
|
+
await started(on.id, id, command.kind === "goal" ? typed : "");
|
|
213
241
|
return true;
|
|
214
242
|
};
|
|
243
|
+
const filled = async (on, id, fill) => {
|
|
244
|
+
let done = false;
|
|
245
|
+
try {
|
|
246
|
+
done = await fill();
|
|
247
|
+
} finally {
|
|
248
|
+
if (!done) await deleteSession({
|
|
249
|
+
machineId: on.id,
|
|
250
|
+
id
|
|
251
|
+
}).catch(() => {});
|
|
252
|
+
}
|
|
253
|
+
return done;
|
|
254
|
+
};
|
|
215
255
|
const attempt = async (on, prompt) => {
|
|
216
|
-
const
|
|
256
|
+
const command = startCommand(prompt);
|
|
257
|
+
if (command && (images?.count || firstPrompt)) {
|
|
258
|
+
setBlocked(t("start.commandAlone", { command: `/${command.kind}` }));
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
217
261
|
const first = firstPrompt ? firstPrompt(prompt) : prompt;
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
id: pending,
|
|
221
|
-
config
|
|
222
|
-
};
|
|
223
|
-
if (pending) return send(on, pending, first);
|
|
224
|
-
const id = await create(on, withImages ? "" : first);
|
|
262
|
+
const createsEmpty = !!images?.count || command !== null;
|
|
263
|
+
const id = await create(on, createsEmpty ? "" : first);
|
|
225
264
|
if (!id) return false;
|
|
226
|
-
if (!
|
|
227
|
-
started(on.id, id, first);
|
|
265
|
+
if (!createsEmpty) {
|
|
266
|
+
await started(on.id, id, first);
|
|
228
267
|
return true;
|
|
229
268
|
}
|
|
230
|
-
|
|
231
|
-
id,
|
|
232
|
-
config
|
|
233
|
-
};
|
|
234
|
-
return send(on, id, first);
|
|
269
|
+
return filled(on, id, () => command ? run(on, id, prompt, command) : send(on, id, first));
|
|
235
270
|
};
|
|
236
|
-
const
|
|
237
|
-
if (!ready || !machine) return false;
|
|
271
|
+
const begin = async (on, prompt) => {
|
|
238
272
|
setStarting(true);
|
|
239
273
|
setError(null);
|
|
274
|
+
setBlocked(null);
|
|
240
275
|
try {
|
|
241
|
-
return await attempt(
|
|
276
|
+
return await attempt(on, prompt);
|
|
242
277
|
} catch (thrown) {
|
|
243
278
|
setError(thrown);
|
|
244
279
|
return false;
|
|
@@ -246,11 +281,58 @@ function useStartSession(api, options) {
|
|
|
246
281
|
setStarting(false);
|
|
247
282
|
}
|
|
248
283
|
};
|
|
284
|
+
const [held, setHeld] = useState(null);
|
|
285
|
+
const canHold = !machine && !!options.pending && !held && !starting && !options.waiting;
|
|
286
|
+
const start = async (prompt) => {
|
|
287
|
+
if (ready && machine) return begin(machine, prompt);
|
|
288
|
+
if (canHold && options.pending) {
|
|
289
|
+
setHeld({
|
|
290
|
+
text: prompt,
|
|
291
|
+
on: options.pending,
|
|
292
|
+
state: "waiting"
|
|
293
|
+
});
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
return false;
|
|
297
|
+
};
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
if (held?.state !== "waiting") return;
|
|
300
|
+
if (machine ? machine.id !== held.on : !options.pending) {
|
|
301
|
+
setHeld({
|
|
302
|
+
...held,
|
|
303
|
+
state: "failed"
|
|
304
|
+
});
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (!ready || !machine) return;
|
|
308
|
+
setHeld({
|
|
309
|
+
...held,
|
|
310
|
+
state: "sending"
|
|
311
|
+
});
|
|
312
|
+
begin(machine, held.text).then((done) => setHeld(done ? null : {
|
|
313
|
+
...held,
|
|
314
|
+
state: "failed"
|
|
315
|
+
}));
|
|
316
|
+
}, [
|
|
317
|
+
held,
|
|
318
|
+
ready,
|
|
319
|
+
machine,
|
|
320
|
+
options.pending
|
|
321
|
+
]);
|
|
249
322
|
return {
|
|
250
323
|
ready,
|
|
251
324
|
starting,
|
|
252
325
|
error,
|
|
253
|
-
|
|
326
|
+
blocked,
|
|
327
|
+
start,
|
|
328
|
+
canHold,
|
|
329
|
+
held: held && held.state !== "failed" ? held.text : null,
|
|
330
|
+
heldFailed: held?.state === "failed",
|
|
331
|
+
takeHeld: () => {
|
|
332
|
+
if (!held || held.state === "sending") return null;
|
|
333
|
+
setHeld(null);
|
|
334
|
+
return held.text;
|
|
335
|
+
}
|
|
254
336
|
};
|
|
255
337
|
}
|
|
256
338
|
export { startControls, startMachines, startingMode, useStartLocation, useStartModel, useStartPermissionMode, useStartSession };
|
|
@@ -15,12 +15,19 @@ function terminalHandoffPanel(listing, machine, sessionId, username, t) {
|
|
|
15
15
|
return {
|
|
16
16
|
status: "ready",
|
|
17
17
|
handoff,
|
|
18
|
-
body: handoff
|
|
18
|
+
body: handoffBody(handoff, found, t),
|
|
19
19
|
commandLabel: t("terminal.commandLabel"),
|
|
20
20
|
anyTerminal: handoff.on === "resource" ? t("terminal.anyTerminal") : void 0,
|
|
21
21
|
archived: session && isArchived(session) ? t("terminal.archived") : void 0
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
function handoffBody(handoff, machine, t) {
|
|
25
|
+
switch (handoff.on) {
|
|
26
|
+
case "resource": return t("terminal.resourceBody", { machine: machine.name });
|
|
27
|
+
case "workspace": return t("terminal.workspaceBody");
|
|
28
|
+
case "computer": return t("terminal.computerBody", { host: handoff.host });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
24
31
|
/** A handoff command split before the session it names, which a narrow
|
|
25
32
|
* panel keeps whole rather than breaking at a hyphen in its id. */
|
|
26
33
|
function handoffCommandParts(command) {
|
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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ApprovalAnswerValue, type ApprovalPart, type ChatMessage, type MessagePart, type MessagePaste, type SubagentNotice, type TodoItem, type ToolDecision } from '@parallelworks/ui/ai/headless';
|
|
2
|
-
import type { PwCodeAllowedDirectory, PwCodeApprovalAnswer, PwCodeApprovalRequest, PwCodeGoalStatus, PwCodeHistoryItem, PwCodeImage, PwCodeSessionDetail, PwCodeSessionState, PwCodeSessionStatus, PwCodeGoalProgress, PwCodeStreamEvent, PwCodeSubagentDetail, PwCodeToolDecision, PwCodeTurnEnd } from './types.js';
|
|
2
|
+
import type { PwCodeAllowedDirectory, PwCodeApprovalAnswer, PwCodeApprovalRequest, PwCodeGoalStatus, PwCodeHistoryItem, PwCodeImage, PwCodeSessionDetail, PwCodeSessionState, PwCodeSessionStatus, PwCodeGoalProgress, PwCodeScheduledRun, PwCodeStreamEvent, PwCodeSubagentDetail, PwCodeToolDecision, PwCodeTurnEnd } from './types.js';
|
|
3
3
|
export interface TranscriptState {
|
|
4
4
|
messages: ChatMessage[];
|
|
5
5
|
streaming: ChatMessage | null;
|
|
@@ -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';
|
|
@@ -44,10 +45,12 @@ export declare function approvalToPart(req: PwCodeApprovalRequest, words?: Pick<
|
|
|
44
45
|
export declare function approvalAnswerBody(answer: ApprovalAnswerValue): PwCodeApprovalAnswer;
|
|
45
46
|
/** A review still under way, or one the turn cut short, settled nothing. */
|
|
46
47
|
export declare function toolDecision(d: PwCodeToolDecision): ToolDecision | null;
|
|
47
|
-
/** Ids come from
|
|
48
|
-
*
|
|
48
|
+
/** Ids come from each item's position in the session's whole history, which
|
|
49
|
+
* `historyStart` says this part of it begins at: the end of a transcript drawn
|
|
50
|
+
* early and every read after it name a message alike, so React keeps its row. */
|
|
49
51
|
export declare function historyToMessages(history: PwCodeHistoryItem[], options?: {
|
|
50
52
|
finalizeOpen?: boolean;
|
|
53
|
+
historyStart?: number | undefined;
|
|
51
54
|
goalNotice?: GoalNotice | undefined;
|
|
52
55
|
compactionNotice?: CompactionNotice | undefined;
|
|
53
56
|
recapNotice?: RecapNotice | undefined;
|
|
@@ -82,11 +85,15 @@ export declare function resolveApprovalEverywhere(state: TranscriptState, id: st
|
|
|
82
85
|
* short, so the page must not close the turn either: its open tool calls
|
|
83
86
|
* would read as interrupted while they are still running. */
|
|
84
87
|
export declare function appendOwnMessage(state: TranscriptState, text: string, id?: string, pastes?: MessagePaste[], previews?: PwCodeImage[]): TranscriptState;
|
|
88
|
+
/** Waits for its own turn, which its echo begins. */
|
|
89
|
+
export declare function queueOwnMessage(state: TranscriptState, text: string, id?: string, pastes?: MessagePaste[], previews?: PwCodeImage[]): TranscriptState;
|
|
85
90
|
/** A subagent runs one turn at a time, so a message sent to it starts its next:
|
|
86
91
|
* a turn the transcript still shows running has ended. */
|
|
87
92
|
export declare function appendTurnMessage(state: TranscriptState, text: string, id?: string, pastes?: MessagePaste[], previews?: PwCodeImage[]): TranscriptState;
|
|
88
93
|
/** Held apart until the daemon reports the model was handed it. */
|
|
89
94
|
export declare function appendSteeredMessage(state: TranscriptState, text: string, id?: string, pastes?: MessagePaste[], previews?: PwCodeImage[]): TranscriptState;
|
|
95
|
+
/** A command the machine is running, as it was typed; it opens no turn. */
|
|
96
|
+
export declare function appendCommand(state: TranscriptState, command: string, id: string): TranscriptState;
|
|
90
97
|
/** The daemon queued a message this page had shown as sent, because the turn
|
|
91
98
|
* ahead of it had not reached the page yet. */
|
|
92
99
|
export declare function markQueued(state: TranscriptState, id: string): TranscriptState;
|
|
@@ -99,10 +106,11 @@ export declare function pendingMessages(state: TranscriptState): ChatMessage[];
|
|
|
99
106
|
export declare function turnRunning(state: TranscriptState | null): boolean;
|
|
100
107
|
/** Whether the turn waits on a Bash call, which the machine can move to the background. */
|
|
101
108
|
export declare function bashRunning(state: TranscriptState | null): boolean;
|
|
109
|
+
/** Daemons before the interrupted flag close a stopped turn with the
|
|
110
|
+
* cancelled context's error. */
|
|
111
|
+
export declare function stoppedTurn(ev: PwCodeStreamEvent): boolean;
|
|
102
112
|
/** What the agent records for a call a stop cut off (serverapi.UserInterruptedTool), so a stopped call reads live as it replays. */
|
|
103
113
|
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
114
|
/** How a /goal loop step reads, in the reader's language. */
|
|
107
115
|
export type GoalNotice = (progress: PwCodeGoalProgress) => string;
|
|
108
116
|
/** How a compaction's line reads, in the reader's language; its summary opens under it. */
|
|
@@ -128,6 +136,20 @@ export interface TranscriptWords {
|
|
|
128
136
|
allowDirectory: (dir: PwCodeAllowedDirectory) => string;
|
|
129
137
|
/** Who wrote a subagent's prompt: the conversation that started it. */
|
|
130
138
|
mainConversation: string;
|
|
139
|
+
/** What a skill's /name answers, under the person's message. */
|
|
140
|
+
skillActivated: (activation: SkillActivation) => string;
|
|
141
|
+
/** The line a turn a scheduled task started opens with, in place of the person's message. */
|
|
142
|
+
scheduledRun: (run: PwCodeScheduledRun) => string;
|
|
143
|
+
}
|
|
144
|
+
/** A skill the person started with /name, as the session announces it. */
|
|
145
|
+
export interface SkillActivation {
|
|
146
|
+
name: string;
|
|
147
|
+
/** Where the skill was found; null when the session couldn't say. */
|
|
148
|
+
source: 'project' | 'user' | 'built-in' | null;
|
|
149
|
+
/** Its shell commands and allowed tools stay off until /skills trust. */
|
|
150
|
+
untrusted: boolean;
|
|
151
|
+
/** The line as the session wrote it. */
|
|
152
|
+
line: string;
|
|
131
153
|
}
|
|
132
154
|
/** The verb the terminal picks for a turn, so the same turn reads the same in both. */
|
|
133
155
|
export declare function turnVerb(endedAt: string): TurnVerb;
|