@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.
Files changed (93) hide show
  1. package/README.md +92 -24
  2. package/dist/agentSwitcher.d.ts +13 -2
  3. package/dist/agentSwitcher.js +28 -6
  4. package/dist/ago.d.ts +1 -3
  5. package/dist/ago.js +1 -3
  6. package/dist/api.d.ts +267 -5
  7. package/dist/chatStrings.d.ts +4 -0
  8. package/dist/chatStrings.js +5 -1
  9. package/dist/claudeAccounts.d.ts +20 -2
  10. package/dist/claudeAccounts.js +51 -7
  11. package/dist/claudeApi.d.ts +2 -1
  12. package/dist/claudeApi.js +49 -3
  13. package/dist/command.d.ts +7 -1
  14. package/dist/command.js +11 -2
  15. package/dist/commandsApi.d.ts +8 -3
  16. package/dist/commandsApi.js +25 -4
  17. package/dist/createPwCodeApi.d.ts +92 -58
  18. package/dist/createPwCodeApi.js +4 -2
  19. package/dist/index.d.ts +11 -9
  20. package/dist/index.js +7 -5
  21. package/dist/locales/en/agentTranscript.js +6 -2
  22. package/dist/locales/en/agents.js +50 -6
  23. package/dist/locales/en.d.ts +46 -0
  24. package/dist/locales/es/agentTranscript.js +6 -2
  25. package/dist/locales/es/agents.js +50 -6
  26. package/dist/locales/ja/agentTranscript.js +6 -2
  27. package/dist/locales/ja/agents.js +45 -6
  28. package/dist/locales/ko/agentTranscript.js +6 -2
  29. package/dist/locales/ko/agents.js +50 -6
  30. package/dist/locales/zh/agentTranscript.js +6 -2
  31. package/dist/locales/zh/agents.js +50 -6
  32. package/dist/machine.d.ts +27 -2
  33. package/dist/machine.js +23 -2
  34. package/dist/notices.d.ts +2 -0
  35. package/dist/notices.js +29 -14
  36. package/dist/pwUpdate.d.ts +52 -0
  37. package/dist/pwUpdate.js +115 -0
  38. package/dist/query.d.ts +4 -1
  39. package/dist/query.js +9 -3
  40. package/dist/session.d.ts +7 -1
  41. package/dist/session.js +6 -2
  42. package/dist/sessionActions.js +5 -2
  43. package/dist/sessionEvents.d.ts +39 -5
  44. package/dist/sessionEvents.js +213 -83
  45. package/dist/sessionGroups.d.ts +3 -3
  46. package/dist/sessionGroups.js +3 -3
  47. package/dist/sessionHeader.js +6 -2
  48. package/dist/sessionList.d.ts +13 -8
  49. package/dist/sessionList.js +20 -10
  50. package/dist/sessionScreen.d.ts +8 -3
  51. package/dist/sessionScreen.js +20 -9
  52. package/dist/sessionsApi.d.ts +27 -5
  53. package/dist/sessionsApi.js +128 -17
  54. package/dist/sessionsFeed.d.ts +22 -0
  55. package/dist/sessionsFeed.js +125 -0
  56. package/dist/startPage.d.ts +6 -3
  57. package/dist/startPage.js +34 -12
  58. package/dist/startSession.d.ts +31 -11
  59. package/dist/startSession.js +126 -44
  60. package/dist/terminalHandoffPanel.js +8 -1
  61. package/dist/todos.d.ts +42 -0
  62. package/dist/todos.js +104 -0
  63. package/dist/transcript.d.ts +27 -5
  64. package/dist/transcript.js +148 -112
  65. package/dist/transcriptRead.d.ts +57 -0
  66. package/dist/transcriptRead.js +122 -0
  67. package/dist/types.d.ts +13 -1
  68. package/dist/useComposer.d.ts +36 -15
  69. package/dist/useComposer.js +94 -31
  70. package/dist/useComposerImages.d.ts +38 -1
  71. package/dist/useComposerImages.js +62 -8
  72. package/dist/useComposerPastes.js +3 -8
  73. package/dist/useConversation.d.ts +16 -0
  74. package/dist/useConversation.js +78 -8
  75. package/dist/useMounted.d.ts +3 -0
  76. package/dist/useMounted.js +14 -0
  77. package/dist/useSubagent.d.ts +22 -5
  78. package/dist/useSubagent.js +41 -17
  79. package/dist/useTranscript.d.ts +27 -1
  80. package/dist/useTranscript.js +217 -45
  81. package/dist/wording.d.ts +6 -3
  82. package/dist/wording.js +20 -6
  83. package/locales/en/agentTranscript.json +6 -2
  84. package/locales/en/agents.json +46 -4
  85. package/locales/es/agentTranscript.json +6 -2
  86. package/locales/es/agents.json +46 -4
  87. package/locales/ja/agentTranscript.json +6 -2
  88. package/locales/ja/agents.json +46 -4
  89. package/locales/ko/agentTranscript.json +6 -2
  90. package/locales/ko/agents.json +46 -4
  91. package/locales/zh/agentTranscript.json +6 -2
  92. package/locales/zh/agents.json +46 -4
  93. package/package.json +3 -3
@@ -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 before resources. A resource with no agent on it is
17
- * one the reader has not touched, so it is not counted as down. */
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, or else the newest one. */
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, the session is
153
- * created first and they are saved with it; a retry after they fail reuses
154
- * that session while nothing it started with has changed. */
155
- export declare function useStartSession(api: Pick<StartApi, 'createSession' | 'sendMessage' | 'useSessions'>, options: {
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;
@@ -1,17 +1,25 @@
1
- import { canStartHere, isMachineDown, splitMachines } from "./machine.js";
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 before resources. A resource with no agent on it is
10
- * one the reader has not touched, so it is not counted as down. */
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 [...computers, ...resources];
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 machine = startable.find((m) => m.id === wanted) ?? (startable.length === 1 ? startable[0] : void 0);
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
- /** The prompt, then each image it does not name already. */
163
- function withPlaceholders(prompt, images) {
164
- return [prompt, ...images.map((image) => image.placeholder).filter((placeholder) => !prompt.includes(placeholder))].filter(Boolean).join(" ");
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, the session is
168
- * created first and they are saved with it; a retry after they fail reuses
169
- * that session while nothing it started with has changed. */
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 pendingSession = useRef(null);
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 = withPlaceholders(first, saved);
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 pending = pendingSession.current?.config === config ? pendingSession.current.id : "";
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 withImages = !!images?.count;
219
- if (withImages) pendingSession.current = {
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 (!withImages) {
227
- started(on.id, id, first);
265
+ if (!createsEmpty) {
266
+ await started(on.id, id, first);
228
267
  return true;
229
268
  }
230
- pendingSession.current = {
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 start = async (prompt) => {
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(machine, prompt);
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
- start
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.on === "resource" ? t("terminal.resourceBody", { machine: found.name }) : t("terminal.computerBody", { host: handoff.host }),
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) {
@@ -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 };
@@ -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 the item's position, so a refetch keeps message identity and
48
- * React does not remount (and collapse) the whole transcript. */
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;