@parallelworks/code 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +625 -113
- package/dist/accountApi.d.ts +31 -0
- package/dist/accountApi.js +182 -0
- package/dist/agentSwitcher.d.ts +120 -0
- package/dist/agentSwitcher.js +187 -0
- package/dist/ago.d.ts +1 -3
- package/dist/ago.js +8 -10
- package/dist/allocations.d.ts +41 -0
- package/dist/allocations.js +76 -0
- package/dist/api.d.ts +1319 -50
- package/dist/chatStrings.d.ts +189 -0
- package/dist/chatStrings.js +218 -0
- package/dist/claudeAccounts.d.ts +57 -2
- package/dist/claudeAccounts.js +144 -6
- package/dist/claudeApi.d.ts +2 -1
- package/dist/claudeApi.js +50 -4
- package/dist/claudeSignIn.d.ts +19 -1
- package/dist/claudeSignIn.js +12 -2
- package/dist/command.d.ts +5 -1
- package/dist/command.js +6 -1
- package/dist/commandsApi.d.ts +11 -1
- package/dist/commandsApi.js +24 -5
- package/dist/createPwCodeApi.d.ts +114 -6
- package/dist/createPwCodeApi.js +21 -3
- package/dist/directories.d.ts +161 -0
- package/dist/directories.js +301 -0
- package/dist/goal.d.ts +89 -0
- package/dist/goal.js +164 -0
- package/dist/imageFit.d.ts +23 -0
- package/dist/imageFit.js +27 -0
- package/dist/images.d.ts +28 -0
- package/dist/images.js +38 -6
- package/dist/index.d.ts +31 -15
- package/dist/index.js +29 -14
- package/dist/loadError.d.ts +8 -0
- package/dist/loadError.js +19 -0
- package/dist/locales/en/agentTranscript.js +74 -12
- package/dist/locales/en/agents.js +86 -11
- package/dist/locales/en.d.ts +137 -8
- package/dist/locales/es/agentTranscript.js +74 -12
- package/dist/locales/es/agents.js +86 -11
- package/dist/locales/ja/agentTranscript.js +77 -15
- package/dist/locales/ja/agents.js +60 -122
- package/dist/locales/ko/agentTranscript.js +74 -12
- package/dist/locales/ko/agents.js +86 -11
- package/dist/locales/zh/agentTranscript.js +72 -10
- package/dist/locales/zh/agents.js +86 -11
- package/dist/machine.d.ts +2 -0
- package/dist/modelPicker.d.ts +79 -0
- package/dist/modelPicker.js +107 -0
- package/dist/notices.d.ts +2 -0
- package/dist/notices.js +67 -32
- package/dist/platformDefaults.d.ts +22 -0
- package/dist/platformDefaults.js +30 -0
- package/dist/preferences.d.ts +78 -0
- package/dist/preferences.js +128 -0
- package/dist/pullRequestList.d.ts +10 -2
- package/dist/pullRequestList.js +41 -22
- package/dist/query.d.ts +9 -2
- package/dist/query.js +91 -10
- package/dist/session.d.ts +11 -2
- package/dist/session.js +16 -8
- package/dist/sessionActions.d.ts +11 -1
- package/dist/sessionActions.js +14 -6
- package/dist/sessionEvents.d.ts +37 -5
- package/dist/sessionEvents.js +196 -77
- package/dist/sessionGroups.d.ts +5 -4
- package/dist/sessionGroups.js +6 -5
- package/dist/sessionHeader.js +6 -2
- package/dist/sessionList.d.ts +68 -15
- package/dist/sessionList.js +91 -19
- package/dist/sessionScreen.d.ts +197 -0
- package/dist/sessionScreen.js +218 -0
- package/dist/sessionsApi.d.ts +29 -3
- package/dist/sessionsApi.js +180 -33
- package/dist/sessionsFeed.d.ts +22 -0
- package/dist/sessionsFeed.js +125 -0
- package/dist/settingsApi.d.ts +3 -1
- package/dist/startPage.d.ts +153 -0
- package/dist/startPage.js +174 -0
- package/dist/startSession.d.ts +41 -7
- package/dist/startSession.js +26 -4
- package/dist/todos.d.ts +42 -0
- package/dist/todos.js +104 -0
- package/dist/transcript.d.ts +1 -2
- package/dist/transcript.js +111 -117
- package/dist/transcriptRead.d.ts +56 -0
- package/dist/transcriptRead.js +121 -0
- package/dist/types.d.ts +11 -1
- package/dist/useComposer.d.ts +39 -6
- package/dist/useComposer.js +73 -9
- package/dist/useComposerImages.d.ts +5 -0
- package/dist/useComposerImages.js +27 -5
- package/dist/useComposerPastes.d.ts +70 -0
- package/dist/useComposerPastes.js +125 -0
- package/dist/useConversation.d.ts +16 -1
- package/dist/useConversation.js +104 -10
- package/dist/useMounted.d.ts +3 -0
- package/dist/useMounted.js +14 -0
- package/dist/useSubagent.d.ts +51 -3
- package/dist/useSubagent.js +72 -7
- package/dist/useTranscript.d.ts +23 -3
- package/dist/useTranscript.js +76 -19
- package/dist/wording.d.ts +5 -2
- package/dist/wording.js +8 -6
- package/dist/workingDirectories.d.ts +31 -0
- package/dist/workingDirectories.js +25 -1
- package/locales/en/agentTranscript.json +68 -11
- package/locales/en/agents.json +82 -10
- package/locales/es/agentTranscript.json +68 -11
- package/locales/es/agents.json +82 -10
- package/locales/ja/agentTranscript.json +71 -14
- package/locales/ja/agents.json +82 -10
- package/locales/ko/agentTranscript.json +68 -11
- package/locales/ko/agents.json +82 -10
- package/locales/zh/agentTranscript.json +66 -9
- package/locales/zh/agents.json +82 -10
- package/package.json +6 -3
package/dist/todos.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { usePwCodeTranslations } from "./messages.js";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
// src/todos.ts
|
|
4
|
+
var TODO_STATUSES = /* @__PURE__ */ new Set([
|
|
5
|
+
"pending",
|
|
6
|
+
"in_progress",
|
|
7
|
+
"completed"
|
|
8
|
+
]);
|
|
9
|
+
/** TodoWrite's whole list, which its arguments carry; null when they hold none. */
|
|
10
|
+
function todosFromArgs(argsJSON) {
|
|
11
|
+
let args;
|
|
12
|
+
try {
|
|
13
|
+
args = JSON.parse(argsJSON);
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const raw = args && typeof args === "object" ? args["todos"] : void 0;
|
|
18
|
+
if (!Array.isArray(raw)) return null;
|
|
19
|
+
return raw.flatMap((t) => {
|
|
20
|
+
const { content, status, activeForm } = t && typeof t === "object" ? t : {};
|
|
21
|
+
if (typeof content !== "string" || typeof status !== "string" || !TODO_STATUSES.has(status)) return [];
|
|
22
|
+
return [{
|
|
23
|
+
content,
|
|
24
|
+
status,
|
|
25
|
+
...typeof activeForm === "string" ? { activeForm } : {}
|
|
26
|
+
}];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** The list a TodoWrite call pins above the composer: empty once every task
|
|
30
|
+
* is done, as the terminal drops it, and null for arguments that hold no
|
|
31
|
+
* list, which leave the pinned one as it was. */
|
|
32
|
+
function pinnedTodos(argsJSON) {
|
|
33
|
+
const todos = todosFromArgs(argsJSON);
|
|
34
|
+
if (!todos) return null;
|
|
35
|
+
return todos.some((t) => t.status !== "completed") ? todos : [];
|
|
36
|
+
}
|
|
37
|
+
/** The list a conversation's history leaves pinned: its last TodoWrite's. */
|
|
38
|
+
function todosFromHistory(history) {
|
|
39
|
+
let pinned = [];
|
|
40
|
+
for (const item of history) if (item.kind === "tool_call" && item.toolName === "TodoWrite") pinned = pinnedTodos(item.toolArgs ?? "") ?? pinned;
|
|
41
|
+
return pinned;
|
|
42
|
+
}
|
|
43
|
+
/** What a task reads as: what it is doing while it runs, otherwise what it is. */
|
|
44
|
+
function todoLabel(todo) {
|
|
45
|
+
return todo.status === "in_progress" && todo.activeForm ? todo.activeForm : todo.content;
|
|
46
|
+
}
|
|
47
|
+
/** At most `limit` tasks, from the one before the running one, and how many
|
|
48
|
+
* are left out by whether they are done, since the tail can hide pending ones. */
|
|
49
|
+
function todoWindow(todos, limit) {
|
|
50
|
+
const size = Math.max(limit, 1);
|
|
51
|
+
if (todos.length <= size) return {
|
|
52
|
+
visible: todos,
|
|
53
|
+
hiddenDone: 0,
|
|
54
|
+
hiddenOther: 0
|
|
55
|
+
};
|
|
56
|
+
const running = todos.findIndex((t) => t.status === "in_progress");
|
|
57
|
+
const start = Math.min(Math.max(running - 1, 0), todos.length - size);
|
|
58
|
+
const visible = todos.slice(start, start + size);
|
|
59
|
+
const hidden = [...todos.slice(0, start), ...todos.slice(start + size)];
|
|
60
|
+
const hiddenDone = hidden.filter((t) => t.status === "completed").length;
|
|
61
|
+
return {
|
|
62
|
+
visible,
|
|
63
|
+
hiddenDone,
|
|
64
|
+
hiddenOther: hidden.length - hiddenDone
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
var PANEL_ROWS = 6;
|
|
68
|
+
/** The pinned task list as the terminal's panel shows it: a few rows from the
|
|
69
|
+
* one before the running task, and a control for the rest. */
|
|
70
|
+
function useTodoPanel(todos) {
|
|
71
|
+
const t = usePwCodeTranslations("agents");
|
|
72
|
+
const words = usePwCodeTranslations("agentTranscript");
|
|
73
|
+
const [all, setAll] = useState(false);
|
|
74
|
+
const { visible, hiddenDone, hiddenOther } = all ? {
|
|
75
|
+
visible: todos,
|
|
76
|
+
hiddenDone: 0,
|
|
77
|
+
hiddenOther: 0
|
|
78
|
+
} : todoWindow(todos, PANEL_ROWS);
|
|
79
|
+
const running = todos.find((todo) => todo.status === "in_progress");
|
|
80
|
+
const statusWord = {
|
|
81
|
+
completed: words("transcript.todoCompleted"),
|
|
82
|
+
in_progress: words("transcript.todoInProgress"),
|
|
83
|
+
pending: words("transcript.todoPending")
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
title: words("transcript.tasks"),
|
|
87
|
+
progress: t("tasks.progress", {
|
|
88
|
+
done: todos.filter((todo) => todo.status === "completed").length,
|
|
89
|
+
total: todos.length
|
|
90
|
+
}),
|
|
91
|
+
running: running ? todoLabel(running) : null,
|
|
92
|
+
rows: visible.map((todo) => ({
|
|
93
|
+
todo,
|
|
94
|
+
label: todoLabel(todo),
|
|
95
|
+
statusWord: statusWord[todo.status]
|
|
96
|
+
})),
|
|
97
|
+
more: todos.length > PANEL_ROWS ? {
|
|
98
|
+
label: all ? t("tasks.fewer") : hiddenOther > 0 ? t("tasks.more", { count: hiddenDone + hiddenOther }) : t("tasks.moreCompleted", { count: hiddenDone }),
|
|
99
|
+
all,
|
|
100
|
+
toggle: () => setAll((shown) => !shown)
|
|
101
|
+
} : null
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export { pinnedTodos, todoLabel, todoWindow, todosFromArgs, todosFromHistory, useTodoPanel };
|
package/dist/transcript.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface TranscriptState {
|
|
|
22
22
|
reviews?: Record<string, string[]>;
|
|
23
23
|
decided?: string[];
|
|
24
24
|
turnEndSeq?: number;
|
|
25
|
+
todos?: TodoItem[];
|
|
25
26
|
}
|
|
26
27
|
export type StreamEffect = {
|
|
27
28
|
type: 'refetch';
|
|
@@ -101,8 +102,6 @@ export declare function turnRunning(state: TranscriptState | null): boolean;
|
|
|
101
102
|
export declare function bashRunning(state: TranscriptState | null): boolean;
|
|
102
103
|
/** What the agent records for a call a stop cut off (serverapi.UserInterruptedTool), so a stopped call reads live as it replays. */
|
|
103
104
|
export declare function userInterruptedTool(name: string): string;
|
|
104
|
-
/** TodoWrite's whole list, which its arguments carry; null when they hold none. */
|
|
105
|
-
export declare function todosFromArgs(argsJSON: string): TodoItem[] | null;
|
|
106
105
|
/** How a /goal loop step reads, in the reader's language. */
|
|
107
106
|
export type GoalNotice = (progress: PwCodeGoalProgress) => string;
|
|
108
107
|
/** How a compaction's line reads, in the reader's language; its summary opens under it. */
|
package/dist/transcript.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runsInBackgroundTool } from "./commandsApi.js";
|
|
2
|
+
import { sessionImagePreviewUrl } from "./images.js";
|
|
3
|
+
import { pinnedTodos, todosFromHistory } from "./todos.js";
|
|
2
4
|
import { INTERRUPTED_NOTICE, applyPartDelta, askQuestionsFromArgs, classifyPseudoUserMessage, finalizeParts, firstNonEmptyLine, hiddenTranscriptTool, interruptionNotice, parseSubagentNotice, planFromArgs, resultFailed, subagentDeliveryLine, taskCallFromArgs } from "@parallelworks/ui/ai/headless";
|
|
5
|
+
import { DateTime } from "luxon";
|
|
3
6
|
// src/transcript.ts
|
|
4
7
|
function mainConversationAuthor(words) {
|
|
5
8
|
return {
|
|
6
9
|
id: "main",
|
|
7
10
|
username: "main session",
|
|
8
|
-
name: words?.mainConversation ?? "Main conversation"
|
|
11
|
+
name: words?.mainConversation ?? "Main conversation",
|
|
12
|
+
kind: "agent"
|
|
9
13
|
};
|
|
10
14
|
}
|
|
11
15
|
var synthCounter = 0;
|
|
@@ -28,19 +32,28 @@ function userMessage(text, author, id, pastes, images, imageUrl) {
|
|
|
28
32
|
}
|
|
29
33
|
/** The daemon sends a preview of each image inline; one whose original it
|
|
30
34
|
* names opens at full size from the host, any other from its preview. */
|
|
35
|
+
/** The preview's size, which holds its place in the page until it has loaded. */
|
|
36
|
+
function previewBox(image) {
|
|
37
|
+
return image.width && image.height ? {
|
|
38
|
+
previewWidth: image.width,
|
|
39
|
+
previewHeight: image.height
|
|
40
|
+
} : {};
|
|
41
|
+
}
|
|
31
42
|
function imageAttachments(images, imageUrl) {
|
|
32
|
-
return (images ?? []).filter((image) => image.mime.startsWith("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);
|
|
43
|
+
return (images ?? []).filter((image) => image.mime.startsWith("image/")).flatMap((image) => {
|
|
35
44
|
const original = image.ref && imageUrl ? imageUrl(image.ref) : void 0;
|
|
36
|
-
|
|
45
|
+
const preview = image.data ? `data:${image.mime};base64,${image.data}` : original && sessionImagePreviewUrl(original);
|
|
46
|
+
if (!preview) return [];
|
|
47
|
+
const previewSize = Math.floor(image.data.length * 3 / 4) - (image.data.match(/=*$/)?.[0].length ?? 0);
|
|
48
|
+
return [{
|
|
37
49
|
id: original ?? preview,
|
|
38
50
|
previewUrl: preview,
|
|
39
51
|
filename: "",
|
|
40
52
|
contentType: original && image.originalMime || image.mime,
|
|
41
53
|
size: original ? image.originalSize ?? 0 : previewSize,
|
|
42
|
-
uploadedAt: ""
|
|
43
|
-
|
|
54
|
+
uploadedAt: "",
|
|
55
|
+
...previewBox(image)
|
|
56
|
+
}];
|
|
44
57
|
});
|
|
45
58
|
}
|
|
46
59
|
function assistantMessage(parts = [], id) {
|
|
@@ -84,20 +97,10 @@ function appendShellRun(state, command, output) {
|
|
|
84
97
|
messages: [...state.messages, assistantMessage([shellRunPart(command, output)])]
|
|
85
98
|
};
|
|
86
99
|
}
|
|
87
|
-
/** The daemon pairs results to calls positionally; the wire carries no ids. */
|
|
88
|
-
function completeOldestRunning(parts, result) {
|
|
89
|
-
const idx = parts.findIndex((p) => p.kind === "tool_call" && p.status === "running");
|
|
90
|
-
if (idx === -1) return parts;
|
|
91
|
-
return parts.map((p, i) => i === idx && p.kind === "tool_call" ? {
|
|
92
|
-
...p,
|
|
93
|
-
status: resultFailed(p.name, result) ? "error" : "ok",
|
|
94
|
-
result
|
|
95
|
-
} : p);
|
|
96
|
-
}
|
|
97
100
|
function approvalSubject(req) {
|
|
98
101
|
if (req.reason === "file is outside the workspace") return "path";
|
|
99
102
|
if (req.tool === "NotebookRun" || req.reason === "code in the notebook kernel") return "code";
|
|
100
|
-
if (req.tool !== void 0 && req.tool !== "Bash") return "call";
|
|
103
|
+
if (req.tool !== void 0 && req.tool !== "Bash" && req.tool !== "Monitor") return "call";
|
|
101
104
|
return "command";
|
|
102
105
|
}
|
|
103
106
|
function approvalToPart(req, words) {
|
|
@@ -176,26 +179,29 @@ function historyToMessages(history, options = {}) {
|
|
|
176
179
|
const lastSettledTurnEnd = history.findLastIndex((item) => item.kind === "turn_end" && !item.turnEnd?.pendingAgents);
|
|
177
180
|
const messages = [];
|
|
178
181
|
let current = null;
|
|
182
|
+
let parts = [];
|
|
183
|
+
const running = [];
|
|
184
|
+
const cards = /* @__PURE__ */ new Map();
|
|
179
185
|
const flush = (finalize) => {
|
|
180
186
|
if (current) {
|
|
181
|
-
|
|
187
|
+
messages.push({
|
|
182
188
|
...current,
|
|
183
|
-
parts: finalizeParts(
|
|
184
|
-
};
|
|
185
|
-
messages.push(current);
|
|
189
|
+
parts: finalize ? finalizeParts(parts) : parts
|
|
190
|
+
});
|
|
186
191
|
current = null;
|
|
187
192
|
}
|
|
188
193
|
};
|
|
189
194
|
const open = (index) => {
|
|
190
|
-
if (!current)
|
|
191
|
-
|
|
195
|
+
if (!current) {
|
|
196
|
+
current = assistantMessage([], `h-a-${index}`);
|
|
197
|
+
parts = [];
|
|
198
|
+
running.length = 0;
|
|
199
|
+
cards.clear();
|
|
200
|
+
}
|
|
192
201
|
};
|
|
193
202
|
const append = (part, index) => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
...message,
|
|
197
|
-
parts: [...message.parts ?? [], part]
|
|
198
|
-
};
|
|
203
|
+
open(index);
|
|
204
|
+
return parts.push(part) - 1;
|
|
199
205
|
};
|
|
200
206
|
const ranCommand = (command, index, answer) => {
|
|
201
207
|
if (!command) {
|
|
@@ -217,18 +223,14 @@ function historyToMessages(history, options = {}) {
|
|
|
217
223
|
};
|
|
218
224
|
const pending = [];
|
|
219
225
|
const settle = (call, result) => {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
};
|
|
226
|
+
open(-1);
|
|
227
|
+
const at = call.kind === "tool" ? running.shift() : call.kind === "hidden" ? void 0 : cards.get(call.id);
|
|
228
|
+
const part = at === void 0 ? void 0 : parts[at];
|
|
229
|
+
if (at !== void 0 && part) parts[at] = settledPart(part, result);
|
|
225
230
|
};
|
|
226
231
|
const dropWaitingAsks = () => {
|
|
227
232
|
const waiting = new Set(pending.flatMap((call) => call.kind === "ask" ? [call.id] : []));
|
|
228
|
-
if (current && waiting.size > 0)
|
|
229
|
-
...current,
|
|
230
|
-
parts: (current.parts ?? []).filter((p) => !(p.kind === "approval" && waiting.has(p.id)))
|
|
231
|
-
};
|
|
233
|
+
if (current && waiting.size > 0) parts = parts.filter((p) => !(p.kind === "approval" && waiting.has(p.id)));
|
|
232
234
|
};
|
|
233
235
|
history.forEach((item, index) => {
|
|
234
236
|
switch (item.kind) {
|
|
@@ -256,7 +258,8 @@ function historyToMessages(history, options = {}) {
|
|
|
256
258
|
case "thinking":
|
|
257
259
|
append({
|
|
258
260
|
kind: "reasoning",
|
|
259
|
-
text: item.text ?? ""
|
|
261
|
+
text: item.text ?? "",
|
|
262
|
+
...item.durationMs ? { durationMs: item.durationMs } : {}
|
|
260
263
|
}, index);
|
|
261
264
|
return;
|
|
262
265
|
case "tool_call": {
|
|
@@ -265,13 +268,13 @@ function historyToMessages(history, options = {}) {
|
|
|
265
268
|
const id = `h-${index}`;
|
|
266
269
|
if (name === "Task") {
|
|
267
270
|
const { description, agentType } = taskCallFromArgs(args);
|
|
268
|
-
append({
|
|
271
|
+
cards.set(id, append({
|
|
269
272
|
kind: "subagent",
|
|
270
273
|
id,
|
|
271
274
|
status: "running",
|
|
272
275
|
description,
|
|
273
276
|
...agentType ? { agentType } : {}
|
|
274
|
-
}, index);
|
|
277
|
+
}, index));
|
|
275
278
|
pending.push({
|
|
276
279
|
kind: "subagent",
|
|
277
280
|
id
|
|
@@ -280,7 +283,7 @@ function historyToMessages(history, options = {}) {
|
|
|
280
283
|
}
|
|
281
284
|
if (name === "AskUserQuestion") {
|
|
282
285
|
const [card, call] = askCard(id, args, item.decision);
|
|
283
|
-
append(card, index);
|
|
286
|
+
cards.set(id, append(card, index));
|
|
284
287
|
pending.push(call);
|
|
285
288
|
return;
|
|
286
289
|
}
|
|
@@ -292,25 +295,12 @@ function historyToMessages(history, options = {}) {
|
|
|
292
295
|
pending.push({ kind: "hidden" });
|
|
293
296
|
return;
|
|
294
297
|
}
|
|
295
|
-
const todos = name === "TodoWrite" ? todosFromArgs(args) : null;
|
|
296
|
-
if (todos?.length) {
|
|
297
|
-
const message = open(index);
|
|
298
|
-
current = {
|
|
299
|
-
...message,
|
|
300
|
-
parts: applyPartDelta(message.parts ?? [], {
|
|
301
|
-
type: "todo_snapshot",
|
|
302
|
-
todos
|
|
303
|
-
})
|
|
304
|
-
};
|
|
305
|
-
pending.push({ kind: "hidden" });
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
298
|
if (hiddenTranscriptTool(name)) {
|
|
309
299
|
pending.push({ kind: "hidden" });
|
|
310
300
|
return;
|
|
311
301
|
}
|
|
312
302
|
const decision = item.decision && toolDecision(item.decision);
|
|
313
|
-
append({
|
|
303
|
+
running.push(append({
|
|
314
304
|
kind: "tool_call",
|
|
315
305
|
id: item.callId || id,
|
|
316
306
|
name,
|
|
@@ -319,7 +309,7 @@ function historyToMessages(history, options = {}) {
|
|
|
319
309
|
...item.startLine ? { startLine: item.startLine } : {},
|
|
320
310
|
...planFileEdit(name, args) ? { foldDiff: true } : {},
|
|
321
311
|
...decision ? { decision } : {}
|
|
322
|
-
}, index);
|
|
312
|
+
}, index));
|
|
323
313
|
pending.push({ kind: "tool" });
|
|
324
314
|
return;
|
|
325
315
|
}
|
|
@@ -343,12 +333,13 @@ function historyToMessages(history, options = {}) {
|
|
|
343
333
|
}
|
|
344
334
|
case "notice": {
|
|
345
335
|
const text = item.text ?? "";
|
|
346
|
-
const delivery =
|
|
336
|
+
const delivery = readDelivery(text);
|
|
347
337
|
if (delivery?.silent) return;
|
|
338
|
+
const detail = delivery ? deliveryDetail(delivery) : void 0;
|
|
348
339
|
append(delivery ? {
|
|
349
340
|
kind: "notice",
|
|
350
341
|
text: deliveryLine(delivery, words),
|
|
351
|
-
...
|
|
342
|
+
...detail ? { detail } : {}
|
|
352
343
|
} : {
|
|
353
344
|
kind: "notice",
|
|
354
345
|
text: text.trim()
|
|
@@ -435,27 +426,30 @@ function askCard(id, args, d) {
|
|
|
435
426
|
}, { kind: "hidden" }];
|
|
436
427
|
}
|
|
437
428
|
var BACKGROUND_STARTED_PREFIX = "Started background subagent";
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
case "
|
|
442
|
-
|
|
429
|
+
/** The block a call drew, as its result leaves it. */
|
|
430
|
+
function settledPart(part, result) {
|
|
431
|
+
switch (part.kind) {
|
|
432
|
+
case "tool_call": return {
|
|
433
|
+
...part,
|
|
434
|
+
status: resultFailed(part.name, result) ? "error" : "ok",
|
|
435
|
+
result
|
|
436
|
+
};
|
|
437
|
+
case "subagent":
|
|
443
438
|
if (result.startsWith(BACKGROUND_STARTED_PREFIX)) return {
|
|
444
|
-
...
|
|
439
|
+
...part,
|
|
445
440
|
background: true
|
|
446
441
|
};
|
|
447
442
|
return {
|
|
448
|
-
...
|
|
443
|
+
...part,
|
|
449
444
|
status: resultFailed("Task", result) ? "failed" : "done",
|
|
450
445
|
summary: firstNonEmptyLine(result, 60)
|
|
451
446
|
};
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
...p,
|
|
447
|
+
case "approval": return {
|
|
448
|
+
...part,
|
|
455
449
|
resolved: true,
|
|
456
450
|
answer: result.trim()
|
|
457
|
-
}
|
|
458
|
-
default: return
|
|
451
|
+
};
|
|
452
|
+
default: return part;
|
|
459
453
|
}
|
|
460
454
|
}
|
|
461
455
|
/** A session with no history resumes from the start: the daemon stamps a seq
|
|
@@ -500,7 +494,8 @@ function initialTranscript(detail, options = {}) {
|
|
|
500
494
|
turnStartedAt: running ? detail.turnStartedAt ?? null : null,
|
|
501
495
|
waitingForUsageLimit: running && !!detail.waitingForUsageLimit,
|
|
502
496
|
usageLimitResumeAt: running && detail.waitingForUsageLimit ? detail.usageLimitResumeAt ?? null : null,
|
|
503
|
-
seededSeq: detail.lastSeq ?? 0
|
|
497
|
+
seededSeq: detail.lastSeq ?? 0,
|
|
498
|
+
todos: todosFromHistory(detail.history ?? [])
|
|
504
499
|
};
|
|
505
500
|
}
|
|
506
501
|
/** A subagent's detail as the session detail its transcript seeds from. Its run
|
|
@@ -659,7 +654,7 @@ function turnRunning(state) {
|
|
|
659
654
|
}
|
|
660
655
|
/** Whether the turn waits on a Bash call, which the machine can move to the background. */
|
|
661
656
|
function bashRunning(state) {
|
|
662
|
-
return (state?.streaming?.parts ?? []).some((p) => p.kind === "tool_call" && p
|
|
657
|
+
return (state?.streaming?.parts ?? []).some((p) => p.kind === "tool_call" && runsInBackgroundTool(p));
|
|
663
658
|
}
|
|
664
659
|
/** Daemons before the interrupted flag close a stopped turn with the
|
|
665
660
|
* cancelled context's error. */
|
|
@@ -678,31 +673,6 @@ function interruptRunningCalls(parts) {
|
|
|
678
673
|
isError: false
|
|
679
674
|
}) : settled, parts);
|
|
680
675
|
}
|
|
681
|
-
var TODO_STATUSES = /* @__PURE__ */ new Set([
|
|
682
|
-
"pending",
|
|
683
|
-
"in_progress",
|
|
684
|
-
"completed"
|
|
685
|
-
]);
|
|
686
|
-
/** TodoWrite's whole list, which its arguments carry; null when they hold none. */
|
|
687
|
-
function todosFromArgs(argsJSON) {
|
|
688
|
-
let args;
|
|
689
|
-
try {
|
|
690
|
-
args = JSON.parse(argsJSON);
|
|
691
|
-
} catch {
|
|
692
|
-
return null;
|
|
693
|
-
}
|
|
694
|
-
const raw = args && typeof args === "object" ? args["todos"] : void 0;
|
|
695
|
-
if (!Array.isArray(raw)) return null;
|
|
696
|
-
return raw.flatMap((t) => {
|
|
697
|
-
const { content, status, activeForm } = t && typeof t === "object" ? t : {};
|
|
698
|
-
if (typeof content !== "string" || typeof status !== "string" || !TODO_STATUSES.has(status)) return [];
|
|
699
|
-
return [{
|
|
700
|
-
content,
|
|
701
|
-
status,
|
|
702
|
-
...typeof activeForm === "string" ? { activeForm } : {}
|
|
703
|
-
}];
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
676
|
function applyPartEvent(parts, ev, imageUrl, words) {
|
|
707
677
|
switch (ev.type) {
|
|
708
678
|
case "chunk": return applyPartDelta(parts, {
|
|
@@ -715,11 +685,6 @@ function applyPartEvent(parts, ev, imageUrl, words) {
|
|
|
715
685
|
});
|
|
716
686
|
case "retract": return applyPartDelta(parts, { type: "retract" });
|
|
717
687
|
case "tool_start": {
|
|
718
|
-
const todos = ev.name === "TodoWrite" ? todosFromArgs(ev.args ?? "") : null;
|
|
719
|
-
if (todos?.length) return applyPartDelta(parts, {
|
|
720
|
-
type: "todo_snapshot",
|
|
721
|
-
todos
|
|
722
|
-
});
|
|
723
688
|
if (hiddenTranscriptTool(ev.name ?? "")) return parts;
|
|
724
689
|
const id = ev.callId || String(ev.seq);
|
|
725
690
|
const started = applyPartDelta(parts, {
|
|
@@ -761,14 +726,21 @@ function applyPartEvent(parts, ev, imageUrl, words) {
|
|
|
761
726
|
images
|
|
762
727
|
}] : parts;
|
|
763
728
|
}
|
|
764
|
-
case "subagent_start":
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
729
|
+
case "subagent_start": {
|
|
730
|
+
const id = ev.id ?? String(ev.seq);
|
|
731
|
+
const started = applyPartDelta(parts, {
|
|
732
|
+
type: "subagent_start",
|
|
733
|
+
id,
|
|
734
|
+
...ev.agentType !== void 0 ? { agentType: ev.agentType } : {},
|
|
735
|
+
...ev.color !== void 0 ? { color: ev.color } : {},
|
|
736
|
+
...ev.background !== void 0 ? { background: ev.background } : {},
|
|
737
|
+
...ev.name !== void 0 ? { description: ev.name } : {}
|
|
738
|
+
});
|
|
739
|
+
return ev.turnId ? started : started.map((p) => p.kind === "subagent" && p.id === id ? {
|
|
740
|
+
...p,
|
|
741
|
+
detached: true
|
|
742
|
+
} : p);
|
|
743
|
+
}
|
|
772
744
|
case "subagent_action": return applyPartDelta(parts, {
|
|
773
745
|
type: "subagent_action",
|
|
774
746
|
id: ev.id ?? "",
|
|
@@ -843,6 +815,25 @@ var TURN_VERBS = [
|
|
|
843
815
|
function deliveryLine(n, words) {
|
|
844
816
|
return words ? words.deliveryLine(n) : subagentDeliveryLine(n);
|
|
845
817
|
}
|
|
818
|
+
var REPORT_SCAN_HEADER = "[pw code: subagent report matched";
|
|
819
|
+
/** A delivered notice, with a monitor event's line taken from what its script printed rather than the scanner's header above it. */
|
|
820
|
+
function readDelivery(text) {
|
|
821
|
+
const n = parseSubagentNotice(text);
|
|
822
|
+
if (!n?.monitor || !n.body.startsWith(REPORT_SCAN_HEADER)) return n;
|
|
823
|
+
const nl = n.body.indexOf("\n");
|
|
824
|
+
return {
|
|
825
|
+
...n,
|
|
826
|
+
preview: nl === -1 ? "" : firstNonEmptyLine(n.body.slice(nl + 1), 100)
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
/** 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. */
|
|
830
|
+
function deliveryDetail(n) {
|
|
831
|
+
if (!n.body) return;
|
|
832
|
+
if (!n.monitor) return n.body;
|
|
833
|
+
const longest = Math.max(0, ...(n.body.match(/`+/g) ?? []).map((run) => run.length));
|
|
834
|
+
const fence = "`".repeat(Math.max(3, longest + 1));
|
|
835
|
+
return `${fence}\n${n.body}\n${fence}`;
|
|
836
|
+
}
|
|
846
837
|
function isPlanFile(path) {
|
|
847
838
|
const slashed = path.replaceAll("\\", "/");
|
|
848
839
|
const base = slashed.slice(slashed.lastIndexOf("/") + 1).toLowerCase();
|
|
@@ -1147,7 +1138,8 @@ function applyStreamEvent(state, ev, options = {}) {
|
|
|
1147
1138
|
turnStartedAt: null,
|
|
1148
1139
|
waitingForUsageLimit: false,
|
|
1149
1140
|
usageLimitResumeAt: null,
|
|
1150
|
-
cursor: ev.seq
|
|
1141
|
+
cursor: ev.seq,
|
|
1142
|
+
todos: []
|
|
1151
1143
|
},
|
|
1152
1144
|
effects: []
|
|
1153
1145
|
};
|
|
@@ -1184,10 +1176,12 @@ function applyStreamEvent(state, ev, options = {}) {
|
|
|
1184
1176
|
},
|
|
1185
1177
|
effects: []
|
|
1186
1178
|
};
|
|
1179
|
+
const todos = ev.type === "tool_start" && ev.name === "TodoWrite" ? pinnedTodos(ev.args ?? "") : null;
|
|
1187
1180
|
let next = {
|
|
1188
1181
|
...state,
|
|
1189
1182
|
cursor: ev.seq,
|
|
1190
|
-
...ev.turnEnd ? { turnEndSeq: ev.seq } : {}
|
|
1183
|
+
...ev.turnEnd ? { turnEndSeq: ev.seq } : {},
|
|
1184
|
+
...todos ? { todos } : {}
|
|
1191
1185
|
};
|
|
1192
1186
|
if (next.notes.length > 0 && speaks(ev)) next = placeNotes(next);
|
|
1193
1187
|
if (ev.type === "notice" && DISCARDED_QUEUE.test(ev.content ?? "")) next = {
|
|
@@ -1282,8 +1276,8 @@ function applyStreamEvent(state, ev, options = {}) {
|
|
|
1282
1276
|
};
|
|
1283
1277
|
break;
|
|
1284
1278
|
case "subagent_delivered": {
|
|
1285
|
-
const delivery =
|
|
1286
|
-
if (delivery && !delivery.silent) next = appendNotice(next, deliveryLine(delivery, options.words), delivery
|
|
1279
|
+
const delivery = readDelivery(ev.notice ?? "");
|
|
1280
|
+
if (delivery && !delivery.silent) next = appendNotice(next, deliveryLine(delivery, options.words), deliveryDetail(delivery));
|
|
1287
1281
|
break;
|
|
1288
1282
|
}
|
|
1289
1283
|
case "done": {
|
|
@@ -1315,4 +1309,4 @@ function applyStreamEvent(state, ev, options = {}) {
|
|
|
1315
1309
|
effects: controlEffects(ev)
|
|
1316
1310
|
};
|
|
1317
1311
|
}
|
|
1318
|
-
export { TURN_VERBS, appendOwnMessage, appendShellRun, appendSteeredMessage, appendTurnMessage, applyStreamEvent, approvalAnswerBody, approvalToPart, bashRunning, dropMessage, historyToMessages, initialTranscript, liveSessionStatus, markQueued, pendingApprovals, pendingMessages, resolveApprovalEverywhere, resumeCursor, reviewingCount, subagentFrame, subagentSessionDetail,
|
|
1312
|
+
export { TURN_VERBS, appendOwnMessage, appendShellRun, appendSteeredMessage, appendTurnMessage, applyStreamEvent, approvalAnswerBody, approvalToPart, bashRunning, dropMessage, historyToMessages, initialTranscript, liveSessionStatus, markQueued, pendingApprovals, pendingMessages, resolveApprovalEverywhere, resumeCursor, reviewingCount, subagentFrame, subagentSessionDetail, toolDecision, turnRunning, turnVerb, userInterruptedTool };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { PwCodeClient, Schemas } from './apiClient.js';
|
|
2
|
+
type SessionDetail = Schemas['AgentSessionDetail'];
|
|
3
|
+
/** Reads a transcript answered tail first and resolves to its text. `onTail` is
|
|
4
|
+
* handed the tail once it has arrived, if the rest is still on its way a
|
|
5
|
+
* moment later. */
|
|
6
|
+
export declare function readTailFirst(stream: ReadableStream<Uint8Array>, onTail: (tail: SessionDetail) => void): Promise<string>;
|
|
7
|
+
/** Reads sessions' transcripts so the end of one can be shown while the rest
|
|
8
|
+
* of it arrives, which over a slow connection is most of the wait. */
|
|
9
|
+
export declare function createTranscriptReads(client: PwCodeClient, previewsByRef: boolean): {
|
|
10
|
+
/** The end of the transcript being read under `name`, until the read ends. */
|
|
11
|
+
tail: (name: string) => {
|
|
12
|
+
addDirs?: import("./api.js").components["schemas"]["AddedDirectory"][] | null;
|
|
13
|
+
allocation?: string;
|
|
14
|
+
allowedDirs?: import("./api.js").components["schemas"]["AllowedDirectory"][] | null;
|
|
15
|
+
approvals?: import("./api.js").components["schemas"]["ApprovalRequest"][] | null;
|
|
16
|
+
archivedAt?: string;
|
|
17
|
+
autoName?: string;
|
|
18
|
+
branch?: string;
|
|
19
|
+
claudeAccount?: string;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
effort?: string;
|
|
22
|
+
goal?: import("./api.js").components["schemas"]["GoalStatus"];
|
|
23
|
+
group?: string;
|
|
24
|
+
history: import("./api.js").components["schemas"]["HistoryItem"][] | null;
|
|
25
|
+
id: string;
|
|
26
|
+
inputTokens?: number;
|
|
27
|
+
lastError?: string;
|
|
28
|
+
lastSeq?: number;
|
|
29
|
+
liveHost?: string;
|
|
30
|
+
machineId: string;
|
|
31
|
+
messages: number;
|
|
32
|
+
model: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
outputTokens?: number;
|
|
35
|
+
permissionMode?: string;
|
|
36
|
+
pinnedAt?: string;
|
|
37
|
+
preview: string;
|
|
38
|
+
pullRequestStates?: {
|
|
39
|
+
[key: string]: string;
|
|
40
|
+
};
|
|
41
|
+
pullRequests?: string[] | null;
|
|
42
|
+
remoteControl?: boolean;
|
|
43
|
+
status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
|
|
44
|
+
turnId?: string;
|
|
45
|
+
turnStartedAt?: string;
|
|
46
|
+
updatedAt: string;
|
|
47
|
+
usageLimitResumeAt?: string;
|
|
48
|
+
waitingForUsageLimit?: boolean;
|
|
49
|
+
workspace: string;
|
|
50
|
+
workspaceUntrusted?: boolean;
|
|
51
|
+
} | undefined;
|
|
52
|
+
subscribe: (listener: () => void) => () => void;
|
|
53
|
+
/** The session, whole. `name` is what its end is kept under meanwhile. */
|
|
54
|
+
read(machine: string, id: string, name: string, signal: AbortSignal | undefined): Promise<SessionDetail>;
|
|
55
|
+
};
|
|
56
|
+
export {};
|