@parallelworks/code 0.3.0 → 0.4.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 (103) hide show
  1. package/README.md +598 -113
  2. package/dist/accountApi.d.ts +31 -0
  3. package/dist/accountApi.js +182 -0
  4. package/dist/agentSwitcher.d.ts +109 -0
  5. package/dist/agentSwitcher.js +165 -0
  6. package/dist/ago.d.ts +3 -3
  7. package/dist/ago.js +10 -10
  8. package/dist/allocations.d.ts +41 -0
  9. package/dist/allocations.js +76 -0
  10. package/dist/api.d.ts +1080 -11
  11. package/dist/chatStrings.d.ts +188 -0
  12. package/dist/chatStrings.js +217 -0
  13. package/dist/claudeAccounts.d.ts +38 -1
  14. package/dist/claudeAccounts.js +98 -4
  15. package/dist/claudeApi.js +1 -1
  16. package/dist/claudeSignIn.d.ts +19 -1
  17. package/dist/claudeSignIn.js +12 -2
  18. package/dist/commandsApi.d.ts +11 -1
  19. package/dist/commandsApi.js +24 -5
  20. package/dist/createPwCodeApi.d.ts +44 -5
  21. package/dist/createPwCodeApi.js +18 -2
  22. package/dist/directories.d.ts +161 -0
  23. package/dist/directories.js +301 -0
  24. package/dist/goal.d.ts +89 -0
  25. package/dist/goal.js +164 -0
  26. package/dist/imageFit.d.ts +23 -0
  27. package/dist/imageFit.js +27 -0
  28. package/dist/images.d.ts +28 -0
  29. package/dist/images.js +38 -6
  30. package/dist/index.d.ts +27 -12
  31. package/dist/index.js +26 -12
  32. package/dist/loadError.d.ts +8 -0
  33. package/dist/loadError.js +19 -0
  34. package/dist/locales/en/agentTranscript.js +73 -12
  35. package/dist/locales/en/agents.js +71 -9
  36. package/dist/locales/en.d.ts +124 -8
  37. package/dist/locales/es/agentTranscript.js +73 -12
  38. package/dist/locales/es/agents.js +71 -9
  39. package/dist/locales/ja/agentTranscript.js +76 -15
  40. package/dist/locales/ja/agents.js +45 -120
  41. package/dist/locales/ko/agentTranscript.js +73 -12
  42. package/dist/locales/ko/agents.js +71 -9
  43. package/dist/locales/zh/agentTranscript.js +71 -10
  44. package/dist/locales/zh/agents.js +71 -9
  45. package/dist/machine.d.ts +2 -0
  46. package/dist/modelPicker.d.ts +79 -0
  47. package/dist/modelPicker.js +107 -0
  48. package/dist/notices.js +47 -19
  49. package/dist/platformDefaults.d.ts +22 -0
  50. package/dist/platformDefaults.js +30 -0
  51. package/dist/preferences.d.ts +78 -0
  52. package/dist/preferences.js +128 -0
  53. package/dist/pullRequestList.d.ts +10 -2
  54. package/dist/pullRequestList.js +41 -22
  55. package/dist/query.d.ts +6 -2
  56. package/dist/query.js +85 -10
  57. package/dist/session.d.ts +5 -2
  58. package/dist/session.js +12 -8
  59. package/dist/sessionActions.d.ts +11 -1
  60. package/dist/sessionActions.js +14 -6
  61. package/dist/sessionEvents.d.ts +8 -3
  62. package/dist/sessionEvents.js +10 -5
  63. package/dist/sessionGroups.d.ts +3 -2
  64. package/dist/sessionGroups.js +4 -3
  65. package/dist/sessionList.d.ts +57 -9
  66. package/dist/sessionList.js +74 -12
  67. package/dist/sessionScreen.d.ts +193 -0
  68. package/dist/sessionScreen.js +213 -0
  69. package/dist/sessionsApi.d.ts +13 -3
  70. package/dist/sessionsApi.js +88 -29
  71. package/dist/settingsApi.d.ts +3 -1
  72. package/dist/startPage.d.ts +153 -0
  73. package/dist/startPage.js +174 -0
  74. package/dist/startSession.d.ts +41 -7
  75. package/dist/startSession.js +26 -4
  76. package/dist/transcript.js +48 -15
  77. package/dist/types.d.ts +11 -1
  78. package/dist/useComposer.d.ts +25 -1
  79. package/dist/useComposer.js +54 -3
  80. package/dist/useComposerImages.d.ts +5 -0
  81. package/dist/useComposerImages.js +24 -1
  82. package/dist/useComposerPastes.d.ts +70 -0
  83. package/dist/useComposerPastes.js +130 -0
  84. package/dist/useConversation.d.ts +10 -1
  85. package/dist/useConversation.js +32 -5
  86. package/dist/useSubagent.d.ts +49 -3
  87. package/dist/useSubagent.js +70 -7
  88. package/dist/useTranscript.d.ts +23 -3
  89. package/dist/useTranscript.js +76 -19
  90. package/dist/wording.js +2 -2
  91. package/dist/workingDirectories.d.ts +31 -0
  92. package/dist/workingDirectories.js +25 -1
  93. package/locales/en/agentTranscript.json +67 -11
  94. package/locales/en/agents.json +68 -8
  95. package/locales/es/agentTranscript.json +67 -11
  96. package/locales/es/agents.json +68 -8
  97. package/locales/ja/agentTranscript.json +70 -14
  98. package/locales/ja/agents.json +68 -8
  99. package/locales/ko/agentTranscript.json +67 -11
  100. package/locales/ko/agents.json +68 -8
  101. package/locales/zh/agentTranscript.json +65 -9
  102. package/locales/zh/agents.json +68 -8
  103. package/package.json +6 -3
@@ -0,0 +1,174 @@
1
+ import { chatHandoffPrompt } from "./chatHandoff.js";
2
+ import { paletteOptions } from "./command.js";
3
+ import { loadErrorMessage } from "./loadError.js";
4
+ import { isComputer } from "./machine.js";
5
+ import { runsClaude } from "./models.js";
6
+ import { isActiveSession } from "./session.js";
7
+ import { approvalToPart } from "./transcript.js";
8
+ import { machineHint, sessionStateText } from "./wording.js";
9
+ import { useCallback, useEffect, useRef } from "react";
10
+ // src/startPage.ts
11
+ /** As many sessions as a new chat offers starters, so the page fits. */
12
+ var START_SHORTLIST = 4;
13
+ /** The sessions a start page offers to pick back up: the live ones, then the
14
+ * idle ones, each newest first as `triageSessions` orders them. */
15
+ function startShortlist(triage, size = 4) {
16
+ return [...triage.active, ...triage.idle].slice(0, size);
17
+ }
18
+ /** A shortlisted session that is live shows a mark named by its state, which
19
+ * nothing else on its row spells out; one at rest shows none. */
20
+ function shortlistMark(session, machine, t) {
21
+ return isActiveSession(session) ? { label: sessionStateText(session, machine, t) } : null;
22
+ }
23
+ /** When a session began waiting on the reader: its first pending question,
24
+ * else its last change. */
25
+ function waitingSince(s) {
26
+ return s.approvals?.[0]?.createdAt ?? s.updatedAt;
27
+ }
28
+ /** What a session waiting on the reader asks, answerable where it is listed,
29
+ * or, when the listing carries none of its questions, `inSession`: a line
30
+ * sending the reader into the session to answer. */
31
+ function waitingQuestions(s, words, t) {
32
+ const questions = (s.approvals ?? []).map((req) => approvalToPart(req, words));
33
+ return {
34
+ questions,
35
+ inSession: questions.length > 0 ? null : t("dash.answerInSession")
36
+ };
37
+ }
38
+ function useStartScreen(api, { location, describeError }) {
39
+ const { data, error, mutate } = api.useSessions();
40
+ const answer = useCallback(async (session, approvalId, value) => {
41
+ const refusal = await api.answerApproval(session.machineId, session.id, approvalId, value);
42
+ if (refusal) return describeError(refusal);
43
+ mutate();
44
+ return null;
45
+ }, [
46
+ api,
47
+ describeError,
48
+ mutate
49
+ ]);
50
+ const loading = data === void 0;
51
+ return {
52
+ loading,
53
+ failed: error && !data ? { message: loadErrorMessage(error, describeError) } : null,
54
+ showComposer: loading || location.startable.length > 0 || location.down.length > 0,
55
+ explainEmpty: !loading && (data.sessions ?? []).length === 0,
56
+ answer
57
+ };
58
+ }
59
+ /** The start page's parameters from its parsed query; any that is not a
60
+ * single string is left out. */
61
+ function startSearch(search) {
62
+ const text = (value) => typeof value === "string" ? value : void 0;
63
+ return {
64
+ session: text(search["session"]),
65
+ fromChat: text(search["fromChat"])
66
+ };
67
+ }
68
+ /** Follows a link that names only a session, since the machine listed with
69
+ * it is not known where the link was printed: once the listing names the
70
+ * session, `open` takes it to the session. */
71
+ function useSessionLink(session, listing, open) {
72
+ const found = session ? listing.sessions.find((s) => s.id === session) : void 0;
73
+ const latest = useRef(open);
74
+ latest.current = open;
75
+ useEffect(() => {
76
+ if (found) latest.current(found);
77
+ }, [found]);
78
+ if (!session) return null;
79
+ return found || listing.loading ? "resolving" : "missing";
80
+ }
81
+ /** The card over the composer while a link to a session is followed: news
82
+ * while it is looked for, a warning once the listing lacks it. Null without
83
+ * a link. */
84
+ function sessionLinkNotice(state, session, t) {
85
+ if (state === null) return null;
86
+ const missing = state === "missing";
87
+ const values = { id: session ?? "" };
88
+ return {
89
+ text: missing ? t("start.linkMissing", values) : t("start.linkResolving", values),
90
+ tone: missing ? "warning" : "neutral"
91
+ };
92
+ }
93
+ /** The commands a new session's composer offers: the directory's palette,
94
+ * led by the Claude Code account choice on a machine where Claude Code
95
+ * runs. Archiving needs a session, so it is not offered. */
96
+ function startCommands(palette, machine, t) {
97
+ return paletteOptions(palette, runsClaude(machine) ? t("claude.choose") : void 0);
98
+ }
99
+ function machineMenu(location, t) {
100
+ const picked = location.machine?.id;
101
+ const startable = location.startable.map((m) => ({
102
+ id: m.id,
103
+ label: m.name,
104
+ description: isComputer(m) ? t("machine.computer") : t("machine.resource"),
105
+ checked: m.id === picked,
106
+ disabled: false
107
+ }));
108
+ const down = location.down.map((m) => ({
109
+ id: m.id,
110
+ label: m.name,
111
+ description: machineHint(m, t)?.text,
112
+ checked: false,
113
+ disabled: true
114
+ }));
115
+ return {
116
+ startable,
117
+ down,
118
+ downLabel: startable.length > 0 && down.length > 0 ? t("start.notAnswering", { count: down.length }) : void 0,
119
+ pick: (id) => {
120
+ if (id !== picked) location.pickMachine(id);
121
+ }
122
+ };
123
+ }
124
+ /** The chip naming the machine a session starts on, which opens the
125
+ * `machineMenu`: the machine's name after a dot in the `success` tone, since
126
+ * only a machine that answers can be chosen, or, until one is, a call to
127
+ * choose one and no dot. While the machines are still being listed
128
+ * (`finding`), it says so and opens nothing. `label` names the chip's action. */
129
+ function machineChip(machine, t, finding = false) {
130
+ if (finding) {
131
+ const text = t("start.findingMachines");
132
+ return {
133
+ text,
134
+ label: text,
135
+ dot: null
136
+ };
137
+ }
138
+ const choose = t("start.chooseMachine");
139
+ return machine ? {
140
+ text: machine.name,
141
+ label: choose,
142
+ dot: "success"
143
+ } : {
144
+ text: choose,
145
+ label: choose,
146
+ dot: null
147
+ };
148
+ }
149
+ /** How a start carries a chat handed to it: it waits until the chat has
150
+ * arrived, since starting sooner would quietly leave it behind, then sends
151
+ * the chat after what was typed. A chat that failed to load holds nothing
152
+ * back. */
153
+ function chatHandoffStart(handoff, t, describeError) {
154
+ const conversation = handoff?.conversation;
155
+ return {
156
+ waiting: !!handoff && !conversation && !handoff.error,
157
+ firstPrompt: conversation ? (typed) => chatHandoffPrompt(conversation, typed, t) : void 0,
158
+ placeholder: conversation ? t("start.handoffPlaceholder") : t("start.composerPlaceholder"),
159
+ notice: handoff ? handoffNotice(handoff, t, describeError) : null
160
+ };
161
+ }
162
+ function handoffNotice({ conversation, error }, t, describeError) {
163
+ if (error) return {
164
+ text: describeError(error),
165
+ failed: true,
166
+ tone: "warning"
167
+ };
168
+ return {
169
+ text: conversation ? t("start.handoffCard", { title: conversation.title || t("start.handoffUntitled") }) : t("start.handoffLoading"),
170
+ failed: false,
171
+ tone: "neutral"
172
+ };
173
+ }
174
+ export { START_SHORTLIST, chatHandoffStart, machineChip, machineMenu, sessionLinkNotice, shortlistMark, startCommands, startSearch, startShortlist, useSessionLink, useStartScreen, waitingQuestions, waitingSince };
@@ -29,7 +29,7 @@ export interface PwCodeStartLocation<M> {
29
29
  startable: M[];
30
30
  /** The machines listed but not answering, computers first, so a missing one can be traced. */
31
31
  down: M[];
32
- /** The machine picked, or the only one a session can start on. */
32
+ /** The machine picked, else the one picked last time, or the only one a session can start on. */
33
33
  machine: M | undefined;
34
34
  pickMachine: (id: string) => void;
35
35
  /** The directories the machine's sessions worked in, newest first. */
@@ -43,17 +43,49 @@ export interface PwCodeStartLocation<M> {
43
43
  /** Turns to typing a directory, keeping what was typed so far. */
44
44
  typeOtherDirectory: () => void;
45
45
  }
46
- export declare function useStartLocation<M extends PwCodeStartMachine>(machines: readonly M[], sessions: readonly Pick<PwCodeSession, 'machineId' | 'workspace' | 'updatedAt'>[]): PwCodeStartLocation<M>;
46
+ export declare function useStartLocation<M extends PwCodeStartMachine>(machines: readonly M[], sessions: readonly Pick<PwCodeSession, 'machineId' | 'workspace' | 'updatedAt'>[],
47
+ /** The machine the host saved the last pick of. */
48
+ preference?: {
49
+ saved: string | undefined;
50
+ remember: (id: string) => void;
51
+ }): PwCodeStartLocation<M>;
52
+ export interface PwCodeStartPermission {
53
+ mode: PermissionMode;
54
+ pick: (mode: PermissionMode) => void;
55
+ /** The widest mode the machine lets a picker offer, for `permissionModesUpTo`. */
56
+ ceiling: string | undefined;
57
+ /** The modes the machine's pw code takes, for `permissionModesUpTo`. */
58
+ accepted: readonly string[] | undefined;
59
+ }
47
60
  /** The mode a session starts in: the one saved, or one picked on this visit,
48
61
  * within what the machine allows. A pick holds until the visit ends, so one
49
62
  * the host declines to save, such as bypass, still applies to this start. */
50
63
  export declare function useStartPermissionMode(preference: {
51
64
  saved: PermissionMode;
52
65
  remember: (mode: PermissionMode) => void;
53
- }, machine: Pick<PwCodeStartMachine, 'remoteMaxPermissionMode' | 'permissionModes'> | undefined): {
54
- mode: PermissionMode;
55
- pick: (mode: PermissionMode) => void;
56
- };
66
+ }, machine: Pick<PwCodeStartMachine, 'remoteMaxPermissionMode' | 'permissionModes'> | undefined): PwCodeStartPermission;
67
+ /** Which of a start's controls can change, each disabled while true. */
68
+ export interface PwCodeStartControls {
69
+ disabled: {
70
+ model: boolean;
71
+ effort: boolean;
72
+ allocation: boolean;
73
+ /** The account, as its panel and the model picker change it. */
74
+ account: boolean;
75
+ /** The chip naming the account, which opens its panel. */
76
+ accountChip: boolean;
77
+ /** Removing an image waiting to go with the first prompt. */
78
+ images: boolean;
79
+ };
80
+ /** A session can start on the machine, so the model picker reads its Claude
81
+ * models before it opens. */
82
+ canStart: boolean;
83
+ }
84
+ /** The model, effort, allocation, account and images hold while a session
85
+ * starts. The permission mode, machine and directory are not held, and a pick
86
+ * there reaches only the next start. Until a machine is chosen, its model,
87
+ * effort and account chip wait for one too. */
88
+ export declare function startControls(machine: Pick<PwCodeStartMachine, 'status' | 'remoteStart'> | undefined, starting: boolean): PwCodeStartControls;
57
89
  type ClaudeMachine = Pick<PwCodeStartMachine, 'id' | 'claudeInstalled' | 'claudeCodeAllowed'>;
58
90
  type StartApi = Pick<PwCodeApi, 'useClaudeModels' | 'useClaudeAccountNames' | 'createSession' | 'sendMessage' | 'useSessions'>;
59
91
  /** A model last picked for a session, and the allocation that billed it. */
@@ -79,12 +111,14 @@ export interface PwCodeStartModel {
79
111
  * machine where the machine still lists it. */
80
112
  export declare function useStartModel(api: Pick<StartApi, 'useClaudeModels' | 'useClaudeAccountNames'>, { machine, platform, last, account: accountPreference, handedOff, }: {
81
113
  machine: ClaudeMachine | undefined;
114
+ /** The platform's models and the host's selected model and allocation,
115
+ * such as its chat's; `usePlatformDefaults` gives all three to a host
116
+ * without one. */
82
117
  platform: {
83
118
  /** The platform's models: undefined while they load, or when they failed to. */
84
119
  models: readonly {
85
120
  id: string;
86
121
  }[] | undefined;
87
- /** The host's selected model and allocation. */
88
122
  model: string | null | undefined;
89
123
  allocation: string | null | undefined;
90
124
  };
@@ -25,10 +25,11 @@ function startingMode(mode, machine) {
25
25
  const accepted = machine?.permissionModes ?? void 0;
26
26
  return clampPermissionMode(clampPermissionMode(mode, mode, accepted), machine?.remoteMaxPermissionMode, accepted);
27
27
  }
28
- function useStartLocation(machines, sessions) {
28
+ function useStartLocation(machines, sessions, preference) {
29
29
  const { startable, down } = useMemo(() => startMachines(machines), [machines]);
30
30
  const [machineId, setMachineId] = useState("");
31
- const machine = startable.find((m) => m.id === machineId) ?? (startable.length === 1 ? startable[0] : void 0);
31
+ const wanted = machineId || preference?.saved;
32
+ const machine = startable.find((m) => m.id === wanted) ?? (startable.length === 1 ? startable[0] : void 0);
32
33
  const directories = useMemo(() => recentDirectories(sessions, machine?.id), [sessions, machine]);
33
34
  const [dir, setDir] = useState("");
34
35
  const [typing, setTyping] = useState(false);
@@ -50,6 +51,7 @@ function useStartLocation(machines, sessions) {
50
51
  machine,
51
52
  pickMachine: (id) => {
52
53
  setMachineId(id);
54
+ preference?.remember(id);
53
55
  setDir("");
54
56
  setTyping(false);
55
57
  },
@@ -74,7 +76,27 @@ function useStartPermissionMode(preference, machine) {
74
76
  pick: (mode) => {
75
77
  setPicked(mode);
76
78
  preference.remember(mode);
77
- }
79
+ },
80
+ ceiling: machine?.remoteMaxPermissionMode,
81
+ accepted: machine?.permissionModes ?? void 0
82
+ };
83
+ }
84
+ /** The model, effort, allocation, account and images hold while a session
85
+ * starts. The permission mode, machine and directory are not held, and a pick
86
+ * there reaches only the next start. Until a machine is chosen, its model,
87
+ * effort and account chip wait for one too. */
88
+ function startControls(machine, starting) {
89
+ const none = !machine;
90
+ return {
91
+ disabled: {
92
+ model: starting || none,
93
+ effort: starting || none,
94
+ allocation: starting,
95
+ account: starting,
96
+ accountChip: none,
97
+ images: starting
98
+ },
99
+ canStart: !!machine && canStartHere(machine)
78
100
  };
79
101
  }
80
102
  function useRememberedAccount(api, machine, saved) {
@@ -231,4 +253,4 @@ function useStartSession(api, options) {
231
253
  start
232
254
  };
233
255
  }
234
- export { startMachines, startingMode, useStartLocation, useStartModel, useStartPermissionMode, useStartSession };
256
+ export { startControls, startMachines, startingMode, useStartLocation, useStartModel, useStartPermissionMode, useStartSession };
@@ -1,11 +1,14 @@
1
- import { DateTime } from "luxon";
1
+ import { runsInBackgroundTool } from "./commandsApi.js";
2
+ import { sessionImagePreviewUrl } from "./images.js";
2
3
  import { INTERRUPTED_NOTICE, applyPartDelta, askQuestionsFromArgs, classifyPseudoUserMessage, finalizeParts, firstNonEmptyLine, hiddenTranscriptTool, interruptionNotice, parseSubagentNotice, planFromArgs, resultFailed, subagentDeliveryLine, taskCallFromArgs } from "@parallelworks/ui/ai/headless";
4
+ import { DateTime } from "luxon";
3
5
  // src/transcript.ts
4
6
  function mainConversationAuthor(words) {
5
7
  return {
6
8
  id: "main",
7
9
  username: "main session",
8
- name: words?.mainConversation ?? "Main conversation"
10
+ name: words?.mainConversation ?? "Main conversation",
11
+ kind: "agent"
9
12
  };
10
13
  }
11
14
  var synthCounter = 0;
@@ -28,19 +31,28 @@ function userMessage(text, author, id, pastes, images, imageUrl) {
28
31
  }
29
32
  /** The daemon sends a preview of each image inline; one whose original it
30
33
  * names opens at full size from the host, any other from its preview. */
34
+ /** The preview's size, which holds its place in the page until it has loaded. */
35
+ function previewBox(image) {
36
+ return image.width && image.height ? {
37
+ previewWidth: image.width,
38
+ previewHeight: image.height
39
+ } : {};
40
+ }
31
41
  function imageAttachments(images, imageUrl) {
32
- return (images ?? []).filter((image) => image.mime.startsWith("image/")).map((image) => {
33
- const preview = `data:${image.mime};base64,${image.data}`;
34
- const previewSize = Math.floor(image.data.length * 3 / 4) - (image.data.match(/=*$/)?.[0].length ?? 0);
42
+ return (images ?? []).filter((image) => image.mime.startsWith("image/")).flatMap((image) => {
35
43
  const original = image.ref && imageUrl ? imageUrl(image.ref) : void 0;
36
- return {
44
+ const preview = image.data ? `data:${image.mime};base64,${image.data}` : original && sessionImagePreviewUrl(original);
45
+ if (!preview) return [];
46
+ const previewSize = Math.floor(image.data.length * 3 / 4) - (image.data.match(/=*$/)?.[0].length ?? 0);
47
+ return [{
37
48
  id: original ?? preview,
38
49
  previewUrl: preview,
39
50
  filename: "",
40
51
  contentType: original && image.originalMime || image.mime,
41
52
  size: original ? image.originalSize ?? 0 : previewSize,
42
- uploadedAt: ""
43
- };
53
+ uploadedAt: "",
54
+ ...previewBox(image)
55
+ }];
44
56
  });
45
57
  }
46
58
  function assistantMessage(parts = [], id) {
@@ -97,7 +109,7 @@ function completeOldestRunning(parts, result) {
97
109
  function approvalSubject(req) {
98
110
  if (req.reason === "file is outside the workspace") return "path";
99
111
  if (req.tool === "NotebookRun" || req.reason === "code in the notebook kernel") return "code";
100
- if (req.tool !== void 0 && req.tool !== "Bash") return "call";
112
+ if (req.tool !== void 0 && req.tool !== "Bash" && req.tool !== "Monitor") return "call";
101
113
  return "command";
102
114
  }
103
115
  function approvalToPart(req, words) {
@@ -256,7 +268,8 @@ function historyToMessages(history, options = {}) {
256
268
  case "thinking":
257
269
  append({
258
270
  kind: "reasoning",
259
- text: item.text ?? ""
271
+ text: item.text ?? "",
272
+ ...item.durationMs ? { durationMs: item.durationMs } : {}
260
273
  }, index);
261
274
  return;
262
275
  case "tool_call": {
@@ -343,12 +356,13 @@ function historyToMessages(history, options = {}) {
343
356
  }
344
357
  case "notice": {
345
358
  const text = item.text ?? "";
346
- const delivery = parseSubagentNotice(text);
359
+ const delivery = readDelivery(text);
347
360
  if (delivery?.silent) return;
361
+ const detail = delivery ? deliveryDetail(delivery) : void 0;
348
362
  append(delivery ? {
349
363
  kind: "notice",
350
364
  text: deliveryLine(delivery, words),
351
- ...delivery.body ? { detail: delivery.body } : {}
365
+ ...detail ? { detail } : {}
352
366
  } : {
353
367
  kind: "notice",
354
368
  text: text.trim()
@@ -659,7 +673,7 @@ function turnRunning(state) {
659
673
  }
660
674
  /** Whether the turn waits on a Bash call, which the machine can move to the background. */
661
675
  function bashRunning(state) {
662
- return (state?.streaming?.parts ?? []).some((p) => p.kind === "tool_call" && p.name === "Bash" && p.status === "running");
676
+ return (state?.streaming?.parts ?? []).some((p) => p.kind === "tool_call" && runsInBackgroundTool(p));
663
677
  }
664
678
  /** Daemons before the interrupted flag close a stopped turn with the
665
679
  * cancelled context's error. */
@@ -843,6 +857,25 @@ var TURN_VERBS = [
843
857
  function deliveryLine(n, words) {
844
858
  return words ? words.deliveryLine(n) : subagentDeliveryLine(n);
845
859
  }
860
+ var REPORT_SCAN_HEADER = "[pw code: subagent report matched";
861
+ /** A delivered notice, with a monitor event's line taken from what its script printed rather than the scanner's header above it. */
862
+ function readDelivery(text) {
863
+ const n = parseSubagentNotice(text);
864
+ if (!n?.monitor || !n.body.startsWith(REPORT_SCAN_HEADER)) return n;
865
+ const nl = n.body.indexOf("\n");
866
+ return {
867
+ ...n,
868
+ preview: nl === -1 ? "" : firstNonEmptyLine(n.body.slice(nl + 1), 100)
869
+ };
870
+ }
871
+ /** What a delivery's line opens to. A monitor's lines are a script's output, which Markdown would run together, so they go in a code block. */
872
+ function deliveryDetail(n) {
873
+ if (!n.body) return;
874
+ if (!n.monitor) return n.body;
875
+ const longest = Math.max(0, ...(n.body.match(/`+/g) ?? []).map((run) => run.length));
876
+ const fence = "`".repeat(Math.max(3, longest + 1));
877
+ return `${fence}\n${n.body}\n${fence}`;
878
+ }
846
879
  function isPlanFile(path) {
847
880
  const slashed = path.replaceAll("\\", "/");
848
881
  const base = slashed.slice(slashed.lastIndexOf("/") + 1).toLowerCase();
@@ -1282,8 +1315,8 @@ function applyStreamEvent(state, ev, options = {}) {
1282
1315
  };
1283
1316
  break;
1284
1317
  case "subagent_delivered": {
1285
- const delivery = parseSubagentNotice(ev.notice ?? "");
1286
- if (delivery && !delivery.silent) next = appendNotice(next, deliveryLine(delivery, options.words), delivery.body || void 0);
1318
+ const delivery = readDelivery(ev.notice ?? "");
1319
+ if (delivery && !delivery.silent) next = appendNotice(next, deliveryLine(delivery, options.words), deliveryDetail(delivery));
1287
1320
  break;
1288
1321
  }
1289
1322
  case "done": {
package/dist/types.d.ts CHANGED
@@ -43,16 +43,22 @@ export interface PwCodeHistoryItem {
43
43
  turnEnd?: PwCodeTurnEnd;
44
44
  /** On an EditFile call: the line its hunk begins on, as a live tool_start carries it. */
45
45
  startLine?: number;
46
+ /** On a thinking item: how long the thought took, when the session recorded it. */
47
+ durationMs?: number;
46
48
  }
47
49
  /** A preview of an image a message carried, base64-encoded; ref names the
48
50
  * full-size image when the daemon can serve it, and originalMime and
49
- * originalSize describe that image. */
51
+ * originalSize describe that image. Data is empty where the transcript was
52
+ * read with its previews left to their refs. */
50
53
  export interface PwCodeImage {
51
54
  mime: string;
52
55
  data: string;
53
56
  ref?: string;
54
57
  originalMime?: string;
55
58
  originalSize?: number;
59
+ /** The preview's size in pixels. */
60
+ width?: number;
61
+ height?: number;
56
62
  }
57
63
  /** An image the session saved, sent with the message that names its placeholder. */
58
64
  export interface PwCodeImageRef {
@@ -141,6 +147,8 @@ export interface PwCodeGoalStatus {
141
147
  paused?: boolean;
142
148
  /** An evaluation is in flight, which spends tokens with no turn to show. */
143
149
  checking?: boolean;
150
+ /** Time spent working toward it when the snapshot was taken; a pause stops it. */
151
+ elapsedMs?: number;
144
152
  }
145
153
  /** One step of a /goal loop, as the daemon files and announces it. */
146
154
  export interface PwCodeGoalProgress {
@@ -151,6 +159,8 @@ export interface PwCodeGoalProgress {
151
159
  err?: string;
152
160
  /** Set when a usage limit stopped the check; the goal is checked again then. */
153
161
  resumeAt?: string;
162
+ /** Set on a check-in: how long the check has waited on background work still running. */
163
+ waitedMs?: number;
154
164
  elapsedMs?: number;
155
165
  tokens?: number;
156
166
  }
@@ -2,7 +2,7 @@ import type { MessagePaste } from '@parallelworks/ui/ai/headless';
2
2
  import type { Schemas } from './apiClient.js';
3
3
  import type { PwCodeApi } from './createPwCodeApi.js';
4
4
  import type { PwCodeConversation } from './useConversation.js';
5
- import type { PwCodeTakenImages } from './useComposerImages.js';
5
+ import { type PwCodeSavedImage, type PwCodeTakenImages } from './useComposerImages.js';
6
6
  /** The composer's history of sent prompts, as `@parallelworks/ui/ai`'s
7
7
  * `ComposerHistory` takes it. */
8
8
  export interface PwCodeComposerHistory {
@@ -49,6 +49,7 @@ export declare function usePwCodeComposer({ api, machine, sessionId, conversatio
49
49
  /** The images waiting to go with the next message, as `useComposerImages` holds them. */
50
50
  images?: {
51
51
  take: () => Promise<PwCodeTakenImages>;
52
+ restore: (saved: readonly PwCodeSavedImage[]) => void;
52
53
  taking: boolean;
53
54
  } | undefined;
54
55
  /** Typed text the host acts on itself, such as a command that opens one of
@@ -74,6 +75,14 @@ export declare function usePwCodeComposer({ api, machine, sessionId, conversatio
74
75
  locked: boolean;
75
76
  disabled: boolean;
76
77
  };
78
+ /** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
79
+ recall: {
80
+ available: boolean;
81
+ take: () => Promise<{
82
+ text: string;
83
+ pastes: MessagePaste[] | undefined;
84
+ }[]>;
85
+ };
77
86
  /** Why nothing can be sent to the session at all, which a subagent's composer shows too. */
78
87
  sessionLock: {
79
88
  placeholder: string;
@@ -119,3 +128,18 @@ export declare function usePwCodeComposer({ api, machine, sessionId, conversatio
119
128
  };
120
129
  };
121
130
  export type PwCodeComposer = ReturnType<typeof usePwCodeComposer>;
131
+ /** Stops a composer's turn as `@parallelworks/ui/ai`'s session view does,
132
+ * for a host that draws its own composer: while what waits can come back
133
+ * (`recall.available`), `takeBack`, the composer's own take-back into its
134
+ * box, runs first, so none of it starts a turn once this one stops; then
135
+ * the turn stops, even when taking back failed. Resolves to what taking
136
+ * back threw, which the session view only logs.
137
+ * Takes `usePwCodeComposer`'s or `usePwCodeSubagent`'s result. */
138
+ export declare function stopTurn(composer: {
139
+ recall: {
140
+ available: boolean;
141
+ };
142
+ turn: {
143
+ stop: () => Promise<void>;
144
+ };
145
+ }, takeBack: () => Promise<unknown>): Promise<unknown>;
@@ -2,6 +2,7 @@ import { shellCommand } from "./command.js";
2
2
  import { isMachineDown } from "./machine.js";
3
3
  import { usePwCodeTranslations } from "./messages.js";
4
4
  import { bashRunning, liveSessionStatus, pendingApprovals, turnRunning } from "./transcript.js";
5
+ import { withoutAppendedImages } from "./useComposerImages.js";
5
6
  import { composerState, sessionLabel } from "./wording.js";
6
7
  import { useCallback, useEffect, useRef, useState } from "react";
7
8
  // src/useComposer.ts
@@ -13,6 +14,13 @@ function promptHistory(username) {
13
14
  skip: (text) => /^\/auth(\s|$)/.test(text)
14
15
  };
15
16
  }
17
+ /** Typed text steers a running turn; what a command resolved to runs as a turn of its own, and comes back as typed. */
18
+ function resolvedDelivery(text, typed) {
19
+ return text === typed ? { steer: true } : {
20
+ steer: false,
21
+ typed
22
+ };
23
+ }
16
24
  function useCommandOutputs() {
17
25
  const [outputs, setOutputs] = useState([]);
18
26
  const seq = useRef(0);
@@ -38,7 +46,7 @@ function useCommandOutputs() {
38
46
  * elsewhere, or it waits on an approval. */
39
47
  function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo, feed, staleFor, images, handleLocally, notify, onCleared, onArchived }) {
40
48
  const t = usePwCodeTranslations("agents");
41
- const { session, detail, transcript, goal, sending, refetch, warn, showError, reached, deliver, noteShellRun } = conversation;
49
+ const { session, detail, transcript, goal, sending, refetch, warn, showError, reached, deliver, noteShellRun, queued, canRemoveQueued, takeBackPending } = conversation;
42
50
  const [shellRun, setShellRun] = useState(null);
43
51
  const delivering = useRef(null);
44
52
  const { palette, loading: paletteLoading, load: loadPalette } = api.usePalette(machine, sessionId);
@@ -123,7 +131,7 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
123
131
  const refs = saved.map((i) => i.ref);
124
132
  const message = [text, ...refs.map((i) => i.placeholder).filter((p) => !text.includes(p))].filter(Boolean).join(" ");
125
133
  const delivery = deliver(message, {
126
- steer: text === typed,
134
+ ...resolvedDelivery(text, typed),
127
135
  pastes,
128
136
  images: refs,
129
137
  previews: saved.map((i) => i.preview)
@@ -170,6 +178,27 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
170
178
  session,
171
179
  stopSession
172
180
  ]);
181
+ const restoreImages = images?.restore;
182
+ /** Takes back what waits into the composer, as ↑ does in the terminal; one the model read meanwhile stays sent. */
183
+ const takeBack = useCallback(async () => {
184
+ const { taken, refusal } = await takeBackPending();
185
+ if (refusal) warn(refusal);
186
+ restoreImages?.(taken.flatMap(({ images = [], previews = [] }) => images.flatMap((ref, i) => {
187
+ const preview = previews[i];
188
+ return preview ? [{
189
+ ref,
190
+ preview
191
+ }] : [];
192
+ })));
193
+ return taken.map((m) => ({
194
+ text: withoutAppendedImages(m.text, m.images),
195
+ pastes: m.pastes
196
+ }));
197
+ }, [
198
+ restoreImages,
199
+ takeBackPending,
200
+ warn
201
+ ]);
173
202
  const status = detail ? liveSessionStatus(detail.status, transcript, goal) : null;
174
203
  const approvals = transcript ? pendingApprovals(transcript).map((p) => ({ kind: p.approvalKind })) : detail?.approvals;
175
204
  const unreachable = isMachineDown(machineInfo) && !feed.connected;
@@ -214,6 +243,11 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
214
243
  ...state,
215
244
  disabled: sending || !!images?.taking || state.locked
216
245
  },
246
+ /** The composer's `recall`: ↑ in it, or Edit under the queue, takes back what waits. */
247
+ recall: {
248
+ available: queued.some((m) => canRemoveQueued(m.id)),
249
+ take: takeBack
250
+ },
217
251
  /** Why nothing can be sent to the session at all, which a subagent's composer shows too. */
218
252
  sessionLock: unreachable || archived || liveElsewhere ? state : null,
219
253
  shellRun,
@@ -241,4 +275,21 @@ function usePwCodeComposer({ api, machine, sessionId, conversation, machineInfo,
241
275
  background
242
276
  };
243
277
  }
244
- export { promptHistory, useCommandOutputs, usePwCodeComposer };
278
+ /** Stops a composer's turn as `@parallelworks/ui/ai`'s session view does,
279
+ * for a host that draws its own composer: while what waits can come back
280
+ * (`recall.available`), `takeBack`, the composer's own take-back into its
281
+ * box, runs first, so none of it starts a turn once this one stops; then
282
+ * the turn stops, even when taking back failed. Resolves to what taking
283
+ * back threw, which the session view only logs.
284
+ * Takes `usePwCodeComposer`'s or `usePwCodeSubagent`'s result. */
285
+ async function stopTurn(composer, takeBack) {
286
+ let failure;
287
+ if (composer.recall.available) try {
288
+ await takeBack();
289
+ } catch (error) {
290
+ failure = error;
291
+ }
292
+ await composer.turn.stop();
293
+ return failure;
294
+ }
295
+ export { promptHistory, stopTurn, useCommandOutputs, usePwCodeComposer };
@@ -31,6 +31,9 @@ export interface PwCodeTakenImages {
31
31
  }
32
32
  /** Numbers past every placeholder the texts name, as the terminal does. */
33
33
  export declare function nextImageSeq(texts: Iterable<string | null | undefined> | undefined, after: number): number;
34
+ /** The send appends the placeholders of images its text left out; a message
35
+ * taken back gives them back as images, so they leave its text. */
36
+ export declare function withoutAppendedImages(text: string, images: readonly PwCodeImageRef[] | undefined): string;
34
37
  /** Images stay with the reader until there is a session to save them with. */
35
38
  export declare function useComposerImages<F extends PwCodeImageFile>({ api, machine, sessionId, messages, onError, describeError, encode, preview, release, }: {
36
39
  api: Pick<PwCodeApi, 'saveImage'>;
@@ -61,6 +64,8 @@ export declare function useComposerImages<F extends PwCodeImageFile>({ api, mach
61
64
  remove: (key: string) => void;
62
65
  /** Empties the composer and resolves to the saved images; settling with false puts them back. */
63
66
  take: () => Promise<PwCodeTakenImages>;
67
+ /** Puts back the images a message taken back was sent with, already saved with the session. */
68
+ restore: (saved: readonly PwCodeSavedImage[]) => void;
64
69
  /** Saves the images added before there was a session; null once one failed, which `onError` was told. */
65
70
  saveTo: (machine: string, sessionId: string) => Promise<PwCodeImageRef[] | null>;
66
71
  };