@parallelworks/code 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -12
- package/dist/api.d.ts +67 -5
- package/dist/chatStrings.d.ts +3 -0
- package/dist/chatStrings.js +4 -1
- package/dist/command.d.ts +2 -0
- package/dist/command.js +5 -1
- package/dist/commandsApi.d.ts +8 -3
- package/dist/commandsApi.js +25 -4
- package/dist/createPwCodeApi.d.ts +26 -61
- package/dist/index.d.ts +6 -5
- package/dist/index.js +3 -2
- package/dist/locales/en/agentTranscript.js +5 -2
- package/dist/locales/en/agents.js +35 -4
- package/dist/locales/en.d.ts +33 -0
- package/dist/locales/es/agentTranscript.js +5 -2
- package/dist/locales/es/agents.js +35 -4
- package/dist/locales/ja/agentTranscript.js +5 -2
- package/dist/locales/ja/agents.js +30 -4
- package/dist/locales/ko/agentTranscript.js +5 -2
- package/dist/locales/ko/agents.js +35 -4
- package/dist/locales/zh/agentTranscript.js +5 -2
- package/dist/locales/zh/agents.js +35 -4
- package/dist/machine.d.ts +27 -2
- package/dist/machine.js +23 -2
- package/dist/notices.js +9 -1
- package/dist/pwUpdate.d.ts +52 -0
- package/dist/pwUpdate.js +115 -0
- package/dist/session.d.ts +1 -1
- package/dist/session.js +1 -1
- package/dist/sessionActions.js +5 -2
- package/dist/sessionEvents.d.ts +10 -3
- package/dist/sessionEvents.js +27 -11
- package/dist/sessionScreen.d.ts +3 -2
- package/dist/sessionScreen.js +8 -2
- package/dist/sessionsApi.d.ts +8 -2
- package/dist/sessionsApi.js +28 -5
- package/dist/startPage.d.ts +6 -3
- package/dist/startPage.js +34 -12
- package/dist/startSession.d.ts +31 -11
- package/dist/startSession.js +126 -44
- package/dist/terminalHandoffPanel.js +8 -1
- package/dist/transcript.d.ts +26 -3
- package/dist/transcript.js +87 -12
- package/dist/transcriptRead.d.ts +1 -0
- package/dist/transcriptRead.js +2 -1
- package/dist/types.d.ts +13 -1
- package/dist/useComposer.d.ts +22 -10
- package/dist/useComposer.js +75 -25
- package/dist/useComposerImages.d.ts +38 -1
- package/dist/useComposerImages.js +59 -4
- package/dist/useConversation.d.ts +10 -0
- package/dist/useConversation.js +14 -11
- package/dist/useSubagent.d.ts +20 -5
- package/dist/useSubagent.js +39 -17
- package/dist/useTranscript.d.ts +27 -1
- package/dist/useTranscript.js +217 -45
- package/dist/wording.d.ts +1 -1
- package/dist/wording.js +14 -2
- package/locales/en/agentTranscript.json +5 -2
- package/locales/en/agents.json +32 -2
- package/locales/es/agentTranscript.json +5 -2
- package/locales/es/agents.json +32 -2
- package/locales/ja/agentTranscript.json +5 -2
- package/locales/ja/agents.json +32 -2
- package/locales/ko/agentTranscript.json +5 -2
- package/locales/ko/agents.json +32 -2
- package/locales/zh/agentTranscript.json +5 -2
- package/locales/zh/agents.json +32 -2
- package/package.json +3 -3
package/dist/pwUpdate.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { usePwCodeTranslations } from "./messages.js";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
// src/pwUpdate.ts
|
|
4
|
+
/** The pw the machine runs, named as its update is: by build on canary,
|
|
5
|
+
* whose builds share a release. */
|
|
6
|
+
function runningPw(machine) {
|
|
7
|
+
return (machine.pwUpdate?.canary === true ? machine.pwBuild : machine.pwVersion) ?? machine.pwVersion ?? "";
|
|
8
|
+
}
|
|
9
|
+
/** Null when the machine's pw is the newest, or its daemon says nothing of it. */
|
|
10
|
+
function pwUpdateNotice(machine, t) {
|
|
11
|
+
const update = machine?.pwUpdate;
|
|
12
|
+
if (!machine || !update) return null;
|
|
13
|
+
const values = {
|
|
14
|
+
version: update.version,
|
|
15
|
+
machine: machine.name,
|
|
16
|
+
running: runningPw(machine)
|
|
17
|
+
};
|
|
18
|
+
const notice = {
|
|
19
|
+
key: `${machine.id}:${update.version}:${update.error ? "failed" : update.state}`,
|
|
20
|
+
state: update.state,
|
|
21
|
+
tone: "neutral",
|
|
22
|
+
progress: void 0,
|
|
23
|
+
action: void 0
|
|
24
|
+
};
|
|
25
|
+
switch (update.state) {
|
|
26
|
+
case "installing": return {
|
|
27
|
+
...notice,
|
|
28
|
+
text: t("pwUpdate.installing", values),
|
|
29
|
+
progress: update.progress
|
|
30
|
+
};
|
|
31
|
+
case "installed": return {
|
|
32
|
+
...notice,
|
|
33
|
+
text: t("pwUpdate.installed", {
|
|
34
|
+
...values,
|
|
35
|
+
os: machine.os === "windows" ? "windows" : "other"
|
|
36
|
+
})
|
|
37
|
+
};
|
|
38
|
+
case "needs_admin": return {
|
|
39
|
+
...notice,
|
|
40
|
+
text: t("pwUpdate.needsAdmin", {
|
|
41
|
+
...values,
|
|
42
|
+
path: update.path ?? "pw"
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (!machine.pwUpgrade) return {
|
|
47
|
+
...notice,
|
|
48
|
+
text: t("pwUpdate.availableElsewhere", values)
|
|
49
|
+
};
|
|
50
|
+
if (update.error) return {
|
|
51
|
+
...notice,
|
|
52
|
+
tone: "warning",
|
|
53
|
+
text: t("pwUpdate.failed", {
|
|
54
|
+
...values,
|
|
55
|
+
error: update.error
|
|
56
|
+
}),
|
|
57
|
+
action: t("detail.retry")
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
...notice,
|
|
61
|
+
text: t("pwUpdate.available", values),
|
|
62
|
+
action: t("pwUpdate.update")
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Set aside for as long as this page stays loaded, across the sessions it opens. */
|
|
66
|
+
var setAside = /* @__PURE__ */ new Set();
|
|
67
|
+
/** The newer pw for an open session's machine, and /upgrade run on that
|
|
68
|
+
* session to install it. The host shows `notice` while it is set, and the
|
|
69
|
+
* listing it reads the machine from says how the install goes. */
|
|
70
|
+
function usePwUpdate({ upgrade, machine, sessionId, archived, notify, onError }) {
|
|
71
|
+
const t = usePwCodeTranslations("agents");
|
|
72
|
+
const { machine: info, recheck } = machine;
|
|
73
|
+
const [starting, setStarting] = useState(false);
|
|
74
|
+
const [, setDismissed] = useState(0);
|
|
75
|
+
const notice = pwUpdateNotice(info, t);
|
|
76
|
+
const id = info?.id;
|
|
77
|
+
const update = useCallback(() => {
|
|
78
|
+
if (!id || starting || archived) return;
|
|
79
|
+
setStarting(true);
|
|
80
|
+
upgrade(id, sessionId).then((outcome) => {
|
|
81
|
+
if ("error" in outcome) onError(outcome.error);
|
|
82
|
+
else notify(outcome.answer);
|
|
83
|
+
}).finally(() => {
|
|
84
|
+
setStarting(false);
|
|
85
|
+
recheck();
|
|
86
|
+
});
|
|
87
|
+
}, [
|
|
88
|
+
id,
|
|
89
|
+
starting,
|
|
90
|
+
archived,
|
|
91
|
+
upgrade,
|
|
92
|
+
sessionId,
|
|
93
|
+
onError,
|
|
94
|
+
notify,
|
|
95
|
+
recheck
|
|
96
|
+
]);
|
|
97
|
+
const key = notice?.key;
|
|
98
|
+
const dismiss = useCallback(() => {
|
|
99
|
+
if (key) {
|
|
100
|
+
setAside.add(key);
|
|
101
|
+
setDismissed((n) => n + 1);
|
|
102
|
+
}
|
|
103
|
+
}, [key]);
|
|
104
|
+
const shown = notice && !setAside.has(notice.key) ? notice : null;
|
|
105
|
+
return {
|
|
106
|
+
notice: shown && archived ? {
|
|
107
|
+
...shown,
|
|
108
|
+
action: void 0
|
|
109
|
+
} : shown,
|
|
110
|
+
starting,
|
|
111
|
+
update,
|
|
112
|
+
dismiss
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export { pwUpdateNotice, usePwUpdate };
|
package/dist/session.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare function isActiveSession(s: Pick<PwCodeSession, 'status' | 'liveH
|
|
|
55
55
|
export declare function isArchived(s: Pick<PwCodeSession, 'archivedAt'>): boolean;
|
|
56
56
|
/** The running turn is held until a usage limit resets, and goes on by itself then. */
|
|
57
57
|
export declare function waitsOnUsageLimit(s: Pick<PwCodeSession, 'status' | 'waitingForUsageLimit'>): boolean;
|
|
58
|
-
/** A turn is in flight: there is work to stop, and the
|
|
58
|
+
/** A turn is in flight: there is work to stop, and the session can't leave its worktree. */
|
|
59
59
|
export declare function isMidTurn(s: Pick<PwCodeSession, 'status'>): boolean;
|
|
60
60
|
/** A dropped machine outranks the session state: it reads as the machine's
|
|
61
61
|
* problem, not the session's. `idle` is what a resting session shows, the
|
package/dist/session.js
CHANGED
|
@@ -54,7 +54,7 @@ function isArchived(s) {
|
|
|
54
54
|
function waitsOnUsageLimit(s) {
|
|
55
55
|
return s.status === "running" && !!s.waitingForUsageLimit;
|
|
56
56
|
}
|
|
57
|
-
/** A turn is in flight: there is work to stop, and the
|
|
57
|
+
/** A turn is in flight: there is work to stop, and the session can't leave its worktree. */
|
|
58
58
|
function isMidTurn(s) {
|
|
59
59
|
return s.status === "running" || s.status === "awaiting_approval";
|
|
60
60
|
}
|
package/dist/sessionActions.js
CHANGED
|
@@ -18,6 +18,9 @@ function sessionActionBlocked(session, machine, t) {
|
|
|
18
18
|
if (isMachineDown(machine)) return machineBlocked(machine, t);
|
|
19
19
|
if (session.status === "live_elsewhere") return sessionStatusText(session, t);
|
|
20
20
|
}
|
|
21
|
+
function forkBlocked(session, machine, t) {
|
|
22
|
+
return isMidTurn(session) && !machine?.forkMidTurn ? t("sidebar.forkMidTurn") : void 0;
|
|
23
|
+
}
|
|
21
24
|
function menuCommand(action, label, run, disabledReason, shortcut) {
|
|
22
25
|
return {
|
|
23
26
|
action,
|
|
@@ -131,11 +134,11 @@ function useSessionActions({ api, machineById, open, confirm, onRefusal, onWarni
|
|
|
131
134
|
"divider",
|
|
132
135
|
remove
|
|
133
136
|
];
|
|
134
|
-
const midTurn = isMidTurn(session) ? t("sidebar.
|
|
137
|
+
const midTurn = isMidTurn(session) ? t("sidebar.leaveWorktreeMidTurn") : void 0;
|
|
135
138
|
return [
|
|
136
139
|
rename,
|
|
137
140
|
menuCommand(session.pinnedAt ? "unpin" : "pin", session.pinnedAt ? t("sidebar.unpin") : t("sidebar.pin"), () => togglePin(session), machineDown),
|
|
138
|
-
menuCommand("fork", t("sidebar.fork"), () => fork(session), disabledReason ??
|
|
141
|
+
menuCommand("fork", t("sidebar.fork"), () => fork(session), disabledReason ?? forkBlocked(session, machine, t)),
|
|
139
142
|
...worktree ? [menuCommand("leaveWorktree", t("sidebar.leaveWorktree"), () => requestLeaveWorktree(session, worktree), disabledReason ?? midTurn)] : [],
|
|
140
143
|
...isMidTurn(session) ? [menuCommand("stop", t("sidebar.stop"), () => stop(session), machineDown)] : [],
|
|
141
144
|
menuCommand("archive", t("sidebar.archive"), () => requestArchive(session, row), disabledReason, rowKey(ARCHIVE_KEY)),
|
package/dist/sessionEvents.d.ts
CHANGED
|
@@ -6,12 +6,19 @@ export interface PwCodeSocketOptions {
|
|
|
6
6
|
* client is. Resolving asynchronously lets a host fetch a token first. Each
|
|
7
7
|
* reconnect calls it again, with the path resuming after the last frame. */
|
|
8
8
|
openSocket?: ((path: string) => WebSocket | Promise<WebSocket>) | undefined;
|
|
9
|
-
/** Whether the app is out of sight, where animation frames do not run
|
|
10
|
-
*
|
|
9
|
+
/** Whether the app is out of sight, where animation frames do not run. A
|
|
10
|
+
* reply streaming there is applied about once a second, and every other
|
|
11
|
+
* frame as it arrives. */
|
|
11
12
|
hidden?: (() => boolean) | undefined;
|
|
13
|
+
/** Calls `shown` each time the app comes back into sight, until the returned
|
|
14
|
+
* call, so what streamed while it was hidden is drawn at once. */
|
|
15
|
+
whenShown?: ((shown: () => void) => () => void) | undefined;
|
|
12
16
|
}
|
|
13
17
|
/** The seconds between the heartbeats a feed asks the platform for. */
|
|
14
18
|
export declare const HEARTBEAT_S = 10;
|
|
19
|
+
/** How long a hidden app holds a streaming reply's frames: each one applied
|
|
20
|
+
* re-renders the transcript and reads its layout. */
|
|
21
|
+
export declare const HIDDEN_STREAM_MS = 1000;
|
|
15
22
|
/** The path a session's event feed is served at, resuming after frame `after`.
|
|
16
23
|
* With `previewsByRef` the images a tool read come without their previews,
|
|
17
24
|
* which the host loads by URL: a preview is tens of kilobytes, and over a slow
|
|
@@ -46,7 +53,7 @@ export interface HeldSocket {
|
|
|
46
53
|
export declare function holdSocket(latest: {
|
|
47
54
|
current: HeldSocket;
|
|
48
55
|
}, setConnected: (connected: boolean) => void): () => void;
|
|
49
|
-
export declare function sessionEvents({ openSocket, hidden, previewsByRef, }: PwCodeSocketOptions & {
|
|
56
|
+
export declare function sessionEvents({ openSocket, hidden, whenShown, previewsByRef, }: PwCodeSocketOptions & {
|
|
50
57
|
previewsByRef?: boolean | undefined;
|
|
51
58
|
}): {
|
|
52
59
|
useSessionEvents: (machine: string, id: string, cursor: (() => number) | undefined, onEvent: (event: StreamEvent) => void) => {
|
package/dist/sessionEvents.js
CHANGED
|
@@ -10,6 +10,13 @@ var SILENT_AFTER_MS = 25e3;
|
|
|
10
10
|
var OPEN_WITHIN_MS = 2e4;
|
|
11
11
|
var SOCKET_OPEN = 1;
|
|
12
12
|
var SOCKET_CLOSED = 3;
|
|
13
|
+
/** How long a hidden app holds a streaming reply's frames: each one applied
|
|
14
|
+
* re-renders the transcript and reads its layout. */
|
|
15
|
+
var HIDDEN_STREAM_MS = 1e3;
|
|
16
|
+
/** Frames a reply sends many times a second while it streams. */
|
|
17
|
+
function streams(ev) {
|
|
18
|
+
return ev.type === "chunk" || ev.type === "reasoning" || ev.type === "tool_update";
|
|
19
|
+
}
|
|
13
20
|
/** The path a session's event feed is served at, resuming after frame `after`.
|
|
14
21
|
* With `previewsByRef` the images a tool read come without their previews,
|
|
15
22
|
* which the host loads by URL: a preview is tens of kilobytes, and over a slow
|
|
@@ -215,7 +222,7 @@ function useReconnectingSocket({ open, path, connectionKey, enabled, onOpen, onM
|
|
|
215
222
|
}, [enabled, connectionKey]);
|
|
216
223
|
return connected;
|
|
217
224
|
}
|
|
218
|
-
function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
|
|
225
|
+
function sessionEvents({ openSocket, hidden, whenShown, previewsByRef = false }) {
|
|
219
226
|
const openFeeds = /* @__PURE__ */ new Map();
|
|
220
227
|
const listeners = /* @__PURE__ */ new Set();
|
|
221
228
|
let fedMachines = /* @__PURE__ */ new Set();
|
|
@@ -256,30 +263,38 @@ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
|
|
|
256
263
|
}
|
|
257
264
|
/** The transcript owns the cursor; this only reconnects from it. Frames are
|
|
258
265
|
* applied once per animation frame: the backlog a reconnect catches up on
|
|
259
|
-
* arrives in a burst, and rendering each frame of it plays the turn back.
|
|
266
|
+
* arrives in a burst, and rendering each frame of it plays the turn back.
|
|
267
|
+
* Out of sight, where none run, a streaming reply is applied about once a
|
|
268
|
+
* second and anything else at once, after it. */
|
|
260
269
|
function useSessionEvents(machine, id, cursor, onEvent) {
|
|
261
270
|
const key = `${machine}/${id}`;
|
|
262
271
|
const [feed, setFeed] = useState(null);
|
|
263
272
|
const pending = useRef([]);
|
|
264
273
|
const frame = useRef(null);
|
|
274
|
+
const held = useRef(null);
|
|
265
275
|
const onEventRef = useRef(onEvent);
|
|
266
276
|
onEventRef.current = onEvent;
|
|
267
|
-
const
|
|
277
|
+
const unschedule = useCallback(() => {
|
|
268
278
|
if (frame.current !== null) {
|
|
269
279
|
cancelAnimationFrame(frame.current);
|
|
270
280
|
frame.current = null;
|
|
271
281
|
}
|
|
282
|
+
if (held.current !== null) {
|
|
283
|
+
clearTimeout(held.current);
|
|
284
|
+
held.current = null;
|
|
285
|
+
}
|
|
286
|
+
}, []);
|
|
287
|
+
const flush = useCallback(() => {
|
|
288
|
+
unschedule();
|
|
272
289
|
const frames = pending.current;
|
|
273
290
|
pending.current = [];
|
|
274
291
|
for (const ev of frames) onEventRef.current(ev);
|
|
275
|
-
}, []);
|
|
292
|
+
}, [unschedule]);
|
|
276
293
|
useEffect(() => () => {
|
|
277
|
-
|
|
278
|
-
cancelAnimationFrame(frame.current);
|
|
279
|
-
frame.current = null;
|
|
280
|
-
}
|
|
294
|
+
unschedule();
|
|
281
295
|
pending.current = [];
|
|
282
296
|
}, [key]);
|
|
297
|
+
useEffect(() => whenShown?.(flush), [flush]);
|
|
283
298
|
const connected = useReconnectingSocket({
|
|
284
299
|
open: openSocket,
|
|
285
300
|
path: () => sessionEventsPath(machine, id, cursor?.() ?? 0, previewsByRef),
|
|
@@ -306,8 +321,9 @@ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
|
|
|
306
321
|
return;
|
|
307
322
|
}
|
|
308
323
|
pending.current.push(parsed);
|
|
309
|
-
if (hidden?.()) flush
|
|
310
|
-
else if (
|
|
324
|
+
if (!hidden?.()) frame.current ??= requestAnimationFrame(flush);
|
|
325
|
+
else if (streams(parsed)) held.current ??= setTimeout(flush, HIDDEN_STREAM_MS);
|
|
326
|
+
else flush();
|
|
311
327
|
}
|
|
312
328
|
});
|
|
313
329
|
const open = feed?.key === key ? feed.open : void 0;
|
|
@@ -328,4 +344,4 @@ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
|
|
|
328
344
|
listed
|
|
329
345
|
};
|
|
330
346
|
}
|
|
331
|
-
export { changesSubagents, holdSocket, isHeartbeat, reachedByFeed, sessionEvents, sessionEventsPath };
|
|
347
|
+
export { HIDDEN_STREAM_MS, changesSubagents, holdSocket, isHeartbeat, reachedByFeed, sessionEvents, sessionEventsPath };
|
package/dist/sessionScreen.d.ts
CHANGED
|
@@ -95,9 +95,10 @@ export declare function workingActivity(transcript: Pick<TranscriptState, 'turnS
|
|
|
95
95
|
kind: 'working';
|
|
96
96
|
}>;
|
|
97
97
|
/** What the composer's activity line says: the feed reconnecting outranks a
|
|
98
|
-
* turn, and a turn waiting on a usage limit says so in
|
|
98
|
+
* turn or a command running, and a turn waiting on a usage limit says so in
|
|
99
|
+
* place of working. Of the commands running, it names the oldest. */
|
|
99
100
|
export declare function sessionActivity({ composer, transcript, liveState, claudeModel, }: {
|
|
100
|
-
composer: Pick<PwCodeComposer, 'reconnecting' | 'working' | 'checkingGoal'
|
|
101
|
+
composer: Pick<PwCodeComposer, 'reconnecting' | 'working' | 'checkingGoal'> & Partial<Pick<PwCodeComposer, 'runningCommands'>>;
|
|
101
102
|
transcript: TranscriptState | null;
|
|
102
103
|
liveState: PwCodeSessionState | null;
|
|
103
104
|
/** The session runs a Claude Code model on a machine where Claude Code runs. */
|
package/dist/sessionScreen.js
CHANGED
|
@@ -117,12 +117,15 @@ function workingActivity(transcript, tokens, word) {
|
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
/** What the composer's activity line says: the feed reconnecting outranks a
|
|
120
|
-
* turn, and a turn waiting on a usage limit says so in
|
|
120
|
+
* turn or a command running, and a turn waiting on a usage limit says so in
|
|
121
|
+
* place of working. Of the commands running, it names the oldest. */
|
|
121
122
|
function sessionActivity({ composer, transcript, liveState, claudeModel }, t, tTranscript) {
|
|
122
123
|
if (composer.reconnecting) return {
|
|
123
124
|
kind: "reconnecting",
|
|
124
125
|
text: t("detail.reconnecting")
|
|
125
126
|
};
|
|
127
|
+
const command = composer.runningCommands?.[0];
|
|
128
|
+
if (command) return workingActivity({ turnStartedAt: command.startedAt }, null, command.word);
|
|
126
129
|
if (!composer.working) return null;
|
|
127
130
|
if (transcript?.waitingForUsageLimit) return {
|
|
128
131
|
kind: "usageLimit",
|
|
@@ -194,7 +197,10 @@ function usePwCodeSessionScreen({ conversation, composer, read, machine, staleFo
|
|
|
194
197
|
failed: loadFailure(read.error, !!detail, describeError),
|
|
195
198
|
retry,
|
|
196
199
|
/** Why the workspace's own settings, skills and hooks did not load. */
|
|
197
|
-
untrusted: detail?.workspaceUntrusted ? t("detail.untrusted"
|
|
200
|
+
untrusted: detail?.workspaceUntrusted ? t("detail.untrusted", {
|
|
201
|
+
workspace: detail.workspace,
|
|
202
|
+
machine: composer.machineName
|
|
203
|
+
}) : null,
|
|
198
204
|
activity,
|
|
199
205
|
/** The turn waits at its account's usage limit, as the activity line
|
|
200
206
|
* says; not while the feed reconnects, which that line says instead. For
|
package/dist/sessionsApi.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export type PwCodePasteUpload = {
|
|
|
38
38
|
} | {
|
|
39
39
|
unsupported: true;
|
|
40
40
|
};
|
|
41
|
+
type SessionRef = Pick<Session, 'machineId' | 'id'>;
|
|
41
42
|
export interface PwCodeSessionOptions {
|
|
42
43
|
/** Whether the host shows an image from its URL on the platform's API, signed
|
|
43
44
|
* in as the API client is, as a browser on the platform's origin does. Set,
|
|
@@ -98,7 +99,7 @@ feed?: SessionsFeed): {
|
|
|
98
99
|
}>;
|
|
99
100
|
useSessionMutations: () => {
|
|
100
101
|
/** Given the root of the worktree the session works in, removes that worktree too. */
|
|
101
|
-
deleteSession: (s:
|
|
102
|
+
deleteSession: (s: SessionRef, removeWorktree?: string) => Promise<unknown>;
|
|
102
103
|
renameSession: (s: Session, name: string) => Promise<unknown>;
|
|
103
104
|
archiveSession: (s: Session) => Promise<unknown>;
|
|
104
105
|
archiveAfterTurn: (s: Session) => Promise<{
|
|
@@ -108,7 +109,7 @@ feed?: SessionsFeed): {
|
|
|
108
109
|
restoreSession: (s: Session) => Promise<unknown>;
|
|
109
110
|
pinSession: (s: Session, pinned: boolean) => Promise<unknown>;
|
|
110
111
|
/** `group` is the id of one of the reader's groups, or null for none. */
|
|
111
|
-
groupSession: (s:
|
|
112
|
+
groupSession: (s: SessionRef, group: string | null) => Promise<unknown>;
|
|
112
113
|
stopSession: (s: Session) => Promise<unknown>;
|
|
113
114
|
forkSession: (s: Session) => Promise<{
|
|
114
115
|
forked?: Schemas['AgentSessionForked'];
|
|
@@ -126,6 +127,11 @@ feed?: SessionsFeed): {
|
|
|
126
127
|
saveImage: (machine: string, id: string, body: Schemas['AgentImageBody']) => Promise<PwCodeResult<Schemas['AgentImageSaved']>>;
|
|
127
128
|
answerApproval: (machine: string, sessionId: string, approvalId: string, answer: ApprovalAnswerValue) => Promise<unknown>;
|
|
128
129
|
removeSessionDirectory: (machine: string, sessionId: string, path: string) => Promise<unknown>;
|
|
130
|
+
upgradePw: (machine: string, sessionId: string) => Promise<{
|
|
131
|
+
answer: string;
|
|
132
|
+
} | {
|
|
133
|
+
error: unknown;
|
|
134
|
+
}>;
|
|
129
135
|
uploadPaste: (machine: string, sessionId: string, text: string, describe: (error: unknown) => string) => Promise<PwCodePasteUpload>;
|
|
130
136
|
};
|
|
131
137
|
export {};
|
package/dist/sessionsApi.js
CHANGED
|
@@ -17,6 +17,9 @@ var WAITING_REFRESH_MS = 3e4;
|
|
|
17
17
|
var PULL_REQUESTS_REFRESH_MS = 6e4;
|
|
18
18
|
var CLOSED_PULL_REQUESTS_REFRESH_MS = 36e5;
|
|
19
19
|
var SUBAGENTS_REFRESH_MS = 1e3;
|
|
20
|
+
function notLoaded(error) {
|
|
21
|
+
return !!error && toApiError(error).status === 404;
|
|
22
|
+
}
|
|
20
23
|
/** Whether a copy cached by an earlier visit still holds everything the
|
|
21
24
|
* session's listed row reports. A running session's copy trails its turn. */
|
|
22
25
|
function cachedCopyCurrent(listed, cached) {
|
|
@@ -308,18 +311,19 @@ function sessionsApi(client, { previewsByRef = false, transcriptEndFirst = false
|
|
|
308
311
|
* daemon has not loaded, or from a pw code that does not say how each stands.
|
|
309
312
|
* The feed says when to ask again, so nothing polls. */
|
|
310
313
|
function useSubagents(machine, id, enabled) {
|
|
311
|
-
const { data, mutate } = useQuery("/api/code/machines/{machine}/sessions/{id}/subagents", enabled ? { params: { path: {
|
|
314
|
+
const { data, error, mutate } = useQuery("/api/code/machines/{machine}/sessions/{id}/subagents", enabled ? { params: { path: {
|
|
312
315
|
machine,
|
|
313
316
|
id
|
|
314
317
|
} } } : null, {
|
|
315
318
|
revalidateOnFocus: false,
|
|
316
319
|
shouldRetryOnError: false
|
|
317
320
|
});
|
|
321
|
+
const gone = notLoaded(error);
|
|
318
322
|
return {
|
|
319
323
|
subagents: useMemo(() => {
|
|
320
|
-
const listed = data?.subagents ?? [];
|
|
324
|
+
const listed = gone ? [] : data?.subagents ?? [];
|
|
321
325
|
return listed.every((s) => s.status) ? listed : [];
|
|
322
|
-
}, [data]),
|
|
326
|
+
}, [data, gone]),
|
|
323
327
|
refresh: useThrottled(() => mutate(), SUBAGENTS_REFRESH_MS)
|
|
324
328
|
};
|
|
325
329
|
}
|
|
@@ -327,6 +331,7 @@ function sessionsApi(client, { previewsByRef = false, transcriptEndFirst = false
|
|
|
327
331
|
* cached trails the session's feed, and seeding from it would drop what
|
|
328
332
|
* streamed since. */
|
|
329
333
|
function useSubagentDetail(machine, id, subId) {
|
|
334
|
+
const [readHere, setReadHere] = useState(false);
|
|
330
335
|
const { data, error, isValidating, mutate } = useQuery("/api/code/machines/{machine}/sessions/{id}/subagents/{subId}", { params: { path: {
|
|
331
336
|
machine,
|
|
332
337
|
id,
|
|
@@ -335,12 +340,13 @@ function sessionsApi(client, { previewsByRef = false, transcriptEndFirst = false
|
|
|
335
340
|
revalidateIfStale: false,
|
|
336
341
|
revalidateOnFocus: false,
|
|
337
342
|
revalidateOnReconnect: false,
|
|
338
|
-
shouldRetryOnError: false
|
|
343
|
+
shouldRetryOnError: false,
|
|
344
|
+
onSuccess: () => setReadHere(true)
|
|
339
345
|
});
|
|
340
346
|
const answered = useReadThisVisit(data, isValidating, mutate);
|
|
341
347
|
const refresh = useThrottled(() => mutate(), SUBAGENTS_REFRESH_MS);
|
|
342
348
|
return {
|
|
343
|
-
data: answered ? data : void 0,
|
|
349
|
+
data: answered && (readHere || !notLoaded(error)) ? data : void 0,
|
|
344
350
|
error: answered ? error : void 0,
|
|
345
351
|
refresh
|
|
346
352
|
};
|
|
@@ -612,6 +618,22 @@ function sessionsApi(client, { previewsByRef = false, transcriptEndFirst = false
|
|
|
612
618
|
});
|
|
613
619
|
return error ?? null;
|
|
614
620
|
}
|
|
621
|
+
/** Runs /upgrade on the session, which installs the newest pw on its machine
|
|
622
|
+
* in the background; resolves to what the daemon answered, or its refusal. */
|
|
623
|
+
async function upgradePw(machine, sessionId) {
|
|
624
|
+
try {
|
|
625
|
+
const { data, error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/commands", {
|
|
626
|
+
params: { path: {
|
|
627
|
+
machine,
|
|
628
|
+
id: sessionId
|
|
629
|
+
} },
|
|
630
|
+
body: { name: "upgrade" }
|
|
631
|
+
});
|
|
632
|
+
return error ? { error } : { answer: data.output };
|
|
633
|
+
} catch (thrown) {
|
|
634
|
+
return { error: thrown };
|
|
635
|
+
}
|
|
636
|
+
}
|
|
615
637
|
/** Saves a paste with the session on its machine. A machine whose pw code
|
|
616
638
|
* predates paste uploads answers 404, and the paste stays text. */
|
|
617
639
|
async function uploadPaste(machine, sessionId, text, describe) {
|
|
@@ -652,6 +674,7 @@ function sessionsApi(client, { previewsByRef = false, transcriptEndFirst = false
|
|
|
652
674
|
saveImage,
|
|
653
675
|
answerApproval,
|
|
654
676
|
removeSessionDirectory,
|
|
677
|
+
upgradePw,
|
|
655
678
|
uploadPaste
|
|
656
679
|
};
|
|
657
680
|
}
|
package/dist/startPage.d.ts
CHANGED
|
@@ -115,16 +115,19 @@ export interface PwCodeMachineMenu {
|
|
|
115
115
|
/** Picks a machine; the one picked already stays as it is. */
|
|
116
116
|
pick: (id: string) => void;
|
|
117
117
|
}
|
|
118
|
-
export declare function machineMenu<M extends PwCodeStartMachine>(location: Pick<PwCodeStartLocation<M>, 'startable' | 'down' | 'machine' | 'pickMachine'>, t: Translate): PwCodeMachineMenu;
|
|
118
|
+
export declare function machineMenu<M extends PwCodeStartMachine>(location: Pick<PwCodeStartLocation<M>, 'startable' | 'down' | 'machine' | 'pickMachine'> & Partial<Pick<PwCodeStartLocation<M>, 'pending'>>, t: Translate): PwCodeMachineMenu;
|
|
119
119
|
/** The chip naming the machine a session starts on, which opens the
|
|
120
120
|
* `machineMenu`: the machine's name after a dot in the `success` tone, since
|
|
121
121
|
* only a machine that answers can be chosen, or, until one is, a call to
|
|
122
122
|
* choose one and no dot. While the machines are still being listed
|
|
123
|
-
* (`finding`), it says so and opens nothing
|
|
124
|
-
|
|
123
|
+
* (`finding`), it says so and opens nothing; while the workspace a start
|
|
124
|
+
* waits for starts (`pending`), it says so and still opens the menu.
|
|
125
|
+
* `label` names the chip's action. */
|
|
126
|
+
export declare function machineChip(machine: Pick<PwCodeStartMachine, 'name'> | undefined, t: Translate, finding?: boolean, pending?: boolean): {
|
|
125
127
|
text: string;
|
|
126
128
|
label: string;
|
|
127
129
|
dot: 'success' | null;
|
|
130
|
+
waiting: boolean;
|
|
128
131
|
};
|
|
129
132
|
/** A chat handed to a new session, while it loads or once it failed to. */
|
|
130
133
|
export interface PwCodeStartHandoff {
|
package/dist/startPage.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { chatHandoffPrompt } from "./chatHandoff.js";
|
|
2
2
|
import { paletteOptions } from "./command.js";
|
|
3
3
|
import { loadErrorMessage } from "./loadError.js";
|
|
4
|
-
import { isComputer } from "./machine.js";
|
|
4
|
+
import { isComputer, isWorkspace } from "./machine.js";
|
|
5
5
|
import { runsClaude } from "./models.js";
|
|
6
6
|
import { isActiveSession } from "./session.js";
|
|
7
7
|
import { approvalToPart } from "./transcript.js";
|
|
@@ -97,15 +97,16 @@ function startCommands(palette, machine, t) {
|
|
|
97
97
|
return paletteOptions(palette, runsClaude(machine) ? t("claude.choose") : void 0);
|
|
98
98
|
}
|
|
99
99
|
function machineMenu(location, t) {
|
|
100
|
-
const
|
|
101
|
-
const
|
|
100
|
+
const { pending } = location;
|
|
101
|
+
const picked = location.machine?.id ?? pending?.id;
|
|
102
|
+
const startable = [...pending ? [pending] : [], ...location.startable].map((m) => ({
|
|
102
103
|
id: m.id,
|
|
103
104
|
label: m.name,
|
|
104
|
-
description:
|
|
105
|
+
description: m === pending ? machineHint(m, t)?.text : machineDescription(m, t),
|
|
105
106
|
checked: m.id === picked,
|
|
106
107
|
disabled: false
|
|
107
108
|
}));
|
|
108
|
-
const down = location.down.map((m) => ({
|
|
109
|
+
const down = location.down.filter((m) => m !== pending).map((m) => ({
|
|
109
110
|
id: m.id,
|
|
110
111
|
label: m.name,
|
|
111
112
|
description: machineHint(m, t)?.text,
|
|
@@ -121,29 +122,50 @@ function machineMenu(location, t) {
|
|
|
121
122
|
}
|
|
122
123
|
};
|
|
123
124
|
}
|
|
125
|
+
/** What a machine is, and the pw it runs when its daemon said. */
|
|
126
|
+
function machineDescription(m, t) {
|
|
127
|
+
const kind = isWorkspace(m) ? t("machine.workspace") : isComputer(m) ? t("machine.computer") : t("machine.resource");
|
|
128
|
+
if (m.pwUpdate) return t("machine.withUpdate", { kind });
|
|
129
|
+
return m.pwVersion ? t("machine.withVersion", {
|
|
130
|
+
kind,
|
|
131
|
+
version: m.pwVersion
|
|
132
|
+
}) : kind;
|
|
133
|
+
}
|
|
124
134
|
/** The chip naming the machine a session starts on, which opens the
|
|
125
135
|
* `machineMenu`: the machine's name after a dot in the `success` tone, since
|
|
126
136
|
* only a machine that answers can be chosen, or, until one is, a call to
|
|
127
137
|
* choose one and no dot. While the machines are still being listed
|
|
128
|
-
* (`finding`), it says so and opens nothing
|
|
129
|
-
|
|
138
|
+
* (`finding`), it says so and opens nothing; while the workspace a start
|
|
139
|
+
* waits for starts (`pending`), it says so and still opens the menu.
|
|
140
|
+
* `label` names the chip's action. */
|
|
141
|
+
function machineChip(machine, t, finding = false, pending = false) {
|
|
130
142
|
if (finding) {
|
|
131
143
|
const text = t("start.findingMachines");
|
|
132
144
|
return {
|
|
133
145
|
text,
|
|
134
146
|
label: text,
|
|
135
|
-
dot: null
|
|
147
|
+
dot: null,
|
|
148
|
+
waiting: true
|
|
136
149
|
};
|
|
137
150
|
}
|
|
138
151
|
const choose = t("start.chooseMachine");
|
|
139
|
-
|
|
152
|
+
if (machine) return {
|
|
140
153
|
text: machine.name,
|
|
141
154
|
label: choose,
|
|
142
|
-
dot: "success"
|
|
143
|
-
|
|
155
|
+
dot: "success",
|
|
156
|
+
waiting: false
|
|
157
|
+
};
|
|
158
|
+
if (pending) return {
|
|
159
|
+
text: t("start.workspaceStarting"),
|
|
160
|
+
label: choose,
|
|
161
|
+
dot: null,
|
|
162
|
+
waiting: true
|
|
163
|
+
};
|
|
164
|
+
return {
|
|
144
165
|
text: choose,
|
|
145
166
|
label: choose,
|
|
146
|
-
dot: null
|
|
167
|
+
dot: null,
|
|
168
|
+
waiting: false
|
|
147
169
|
};
|
|
148
170
|
}
|
|
149
171
|
/** How a start carries a chat handed to it: it waits until the chat has
|
package/dist/startSession.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ export interface PwCodeStartMachine extends PwCodeMachine {
|
|
|
13
13
|
claudeCodeAllowed?: boolean | undefined;
|
|
14
14
|
}
|
|
15
15
|
/** The machines a session can start on, then those listed but not answering,
|
|
16
|
-
* each with computers
|
|
17
|
-
* one the reader has not touched, so it is not
|
|
16
|
+
* each with the workspace first, then computers, then resources. A resource
|
|
17
|
+
* with no agent on it is one the reader has not touched, so it is not
|
|
18
|
+
* counted as down. */
|
|
18
19
|
export declare function startMachines<M extends PwCodeStartMachine>(machines: readonly M[]): {
|
|
19
20
|
startable: M[];
|
|
20
21
|
down: M[];
|
|
@@ -25,16 +26,18 @@ export declare function startMachines<M extends PwCodeStartMachine>(machines: re
|
|
|
25
26
|
export declare function startingMode(mode: PermissionMode, machine: Pick<PwCodeStartMachine, 'remoteMaxPermissionMode' | 'permissionModes'> | undefined): PermissionMode;
|
|
26
27
|
/** Where a session starts: the machine, and the directory on it. */
|
|
27
28
|
export interface PwCodeStartLocation<M> {
|
|
28
|
-
/** The machines a session can start on, computers first. */
|
|
29
|
+
/** The machines a session can start on, the workspace then computers first. */
|
|
29
30
|
startable: M[];
|
|
30
|
-
/** The machines listed but not answering, computers first, so a missing one can be traced. */
|
|
31
|
+
/** The machines listed but not answering, the workspace then computers first, so a missing one can be traced. */
|
|
31
32
|
down: M[];
|
|
32
|
-
/** The machine picked, else the one picked last time, or the only one a session can start on. */
|
|
33
|
+
/** The machine picked, else the one picked last time, else the workspace or the only one a session can start on. */
|
|
33
34
|
machine: M | undefined;
|
|
35
|
+
/** The workspace a start waits for while it starts, when it is the machine the start would be on. */
|
|
36
|
+
pending: M | undefined;
|
|
34
37
|
pickMachine: (id: string) => void;
|
|
35
38
|
/** The directories the machine's sessions worked in, newest first. */
|
|
36
39
|
directories: RecentDirectory[];
|
|
37
|
-
/** The directory picked or typed,
|
|
40
|
+
/** The directory picked or typed, else the newest one, else the machine's home. */
|
|
38
41
|
directory: string;
|
|
39
42
|
/** The directory is typed rather than picked from the recent ones. */
|
|
40
43
|
typing: boolean;
|
|
@@ -87,7 +90,7 @@ export interface PwCodeStartControls {
|
|
|
87
90
|
* effort and account chip wait for one too. */
|
|
88
91
|
export declare function startControls(machine: Pick<PwCodeStartMachine, 'status' | 'remoteStart'> | undefined, starting: boolean): PwCodeStartControls;
|
|
89
92
|
type ClaudeMachine = Pick<PwCodeStartMachine, 'id' | 'claudeInstalled' | 'claudeCodeAllowed'>;
|
|
90
|
-
type StartApi = Pick<PwCodeApi, 'useClaudeModels' | 'useClaudeAccountNames' | 'createSession' | 'sendMessage' | 'useSessions'>;
|
|
93
|
+
type StartApi = Pick<PwCodeApi, 'useClaudeModels' | 'useClaudeAccountNames' | 'createSession' | 'sendMessage' | 'runSlashAction' | 'useSessions' | 'useSessionMutations'>;
|
|
91
94
|
/** A model last picked for a session, and the allocation that billed it. */
|
|
92
95
|
export interface PwCodeLastModel {
|
|
93
96
|
model?: string | undefined;
|
|
@@ -144,15 +147,26 @@ export interface PwCodeStartSession {
|
|
|
144
147
|
starting: boolean;
|
|
145
148
|
/** Why the last start failed: the machine's refusal, or what was thrown. */
|
|
146
149
|
error: unknown;
|
|
150
|
+
/** Why the last start was not tried, worded for the reader. */
|
|
151
|
+
blocked: string | null;
|
|
147
152
|
/** Starts the session with `prompt` as its first message. False hands the
|
|
148
153
|
* prompt back to the composer. */
|
|
149
154
|
start: (prompt: string) => Promise<boolean>;
|
|
155
|
+
/** A prompt can be held for the machine a start waits for. */
|
|
156
|
+
canHold: boolean;
|
|
157
|
+
/** The prompt held until that machine answers, if one is. */
|
|
158
|
+
held: string | null;
|
|
159
|
+
/** A held prompt whose start failed, which the composer takes back. */
|
|
160
|
+
heldFailed: boolean;
|
|
161
|
+
/** Takes the held prompt back, so it is not sent. */
|
|
162
|
+
takeHeld: () => string | null;
|
|
150
163
|
}
|
|
151
164
|
/** Starts a session, reads the listing again so it shows there, and hands it
|
|
152
|
-
* to `onStarted` once its first prompt is sent. With images,
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
|
|
165
|
+
* to `onStarted` once its first prompt is sent. With images, or for a typed
|
|
166
|
+
* `/goal` or `/plan`, the session is created empty first, then the images go
|
|
167
|
+
* with the prompt or the command runs; a session whose start fails after that
|
|
168
|
+
* is deleted, so nothing is left behind and a retry starts afresh. */
|
|
169
|
+
export declare function useStartSession(api: Pick<StartApi, 'createSession' | 'sendMessage' | 'runSlashAction' | 'useSessions' | 'useSessionMutations'>, options: {
|
|
156
170
|
machine: Pick<PwCodeStartMachine, 'id' | 'claudeCodeAllowed'> | undefined;
|
|
157
171
|
directory: string;
|
|
158
172
|
mode: PermissionMode;
|
|
@@ -166,6 +180,12 @@ export declare function useStartSession(api: Pick<StartApi, 'createSession' | 's
|
|
|
166
180
|
firstPrompt?: ((typed: string) => string) | undefined;
|
|
167
181
|
/** Something the first message needs has not arrived yet. */
|
|
168
182
|
waiting?: boolean | undefined;
|
|
183
|
+
/** The machine the start waits for while it is on its way, so a prompt sent now is held until it answers. */
|
|
184
|
+
pending?: string | undefined;
|
|
185
|
+
/** One of the reader's groups to put the session in. */
|
|
186
|
+
group?: string | undefined;
|
|
187
|
+
/** The session started, but its machine refused to put it in the group. */
|
|
188
|
+
onGroupRefused?: ((refusal: unknown) => void) | undefined;
|
|
169
189
|
/** The host opens the session. */
|
|
170
190
|
onStarted: (machine: string, sessionId: string) => void;
|
|
171
191
|
}): PwCodeStartSession;
|