@parallelworks/code 0.2.0 → 0.3.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 +43 -10
- package/dist/ago.d.ts +8 -0
- package/dist/ago.js +26 -0
- package/dist/api.d.ts +78 -0
- package/dist/base64.d.ts +3 -0
- package/dist/base64.js +15 -0
- package/dist/chatHandoff.d.ts +12 -0
- package/dist/chatHandoff.js +27 -0
- package/dist/claudeAccounts.d.ts +112 -0
- package/dist/claudeAccounts.js +234 -0
- package/dist/claudeSignIn.d.ts +62 -0
- package/dist/claudeSignIn.js +239 -0
- package/dist/contextRow.d.ts +25 -0
- package/dist/contextRow.js +16 -0
- package/dist/createPwCodeApi.d.ts +8 -0
- package/dist/createPwCodeApi.js +2 -0
- package/dist/howSessionsAppear.d.ts +12 -0
- package/dist/howSessionsAppear.js +24 -0
- package/dist/index.d.ts +24 -1
- package/dist/index.js +24 -2
- package/dist/locales/en/agentTranscript.js +2 -10
- package/dist/locales/en/agents.js +5 -5
- package/dist/locales/en.d.ts +5 -13
- package/dist/locales/es/agentTranscript.js +2 -10
- package/dist/locales/es/agents.js +5 -5
- package/dist/locales/ja/agentTranscript.js +2 -10
- package/dist/locales/ja/agents.js +5 -5
- package/dist/locales/ko/agentTranscript.js +2 -10
- package/dist/locales/ko/agents.js +5 -5
- package/dist/locales/zh/agentTranscript.js +2 -10
- package/dist/locales/zh/agents.js +5 -5
- package/dist/machine.d.ts +2 -0
- package/dist/models.d.ts +47 -0
- package/dist/models.js +49 -0
- package/dist/notices.d.ts +2 -1
- package/dist/notices.js +29 -3
- package/dist/pullRequestList.d.ts +52 -0
- package/dist/pullRequestList.js +106 -0
- package/dist/session.d.ts +5 -0
- package/dist/sessionActions.d.ts +105 -0
- package/dist/sessionActions.js +178 -0
- package/dist/sessionGroups.d.ts +49 -0
- package/dist/sessionGroups.js +72 -0
- package/dist/sessionHeader.d.ts +14 -0
- package/dist/sessionHeader.js +16 -0
- package/dist/sessionList.d.ts +134 -0
- package/dist/sessionList.js +271 -0
- package/dist/sessionsApi.js +2 -4
- package/dist/settingsApi.d.ts +36 -0
- package/dist/settingsApi.js +151 -0
- package/dist/startSession.d.ts +138 -0
- package/dist/startSession.js +234 -0
- package/dist/terminalHandoffPanel.d.ts +30 -0
- package/dist/terminalHandoffPanel.js +33 -0
- package/dist/transcript.d.ts +2 -0
- package/dist/transcript.js +15 -12
- package/dist/usageLimit.d.ts +8 -0
- package/dist/usageLimit.js +13 -0
- package/dist/useAwayRecap.d.ts +30 -0
- package/dist/useAwayRecap.js +75 -0
- package/dist/useComposer.d.ts +121 -0
- package/dist/useComposer.js +244 -0
- package/dist/useComposerImages.d.ts +66 -0
- package/dist/useComposerImages.js +195 -0
- package/dist/useConversation.d.ts +190 -0
- package/dist/useConversation.js +287 -0
- package/dist/useSubagent.d.ts +58 -0
- package/dist/useSubagent.js +149 -0
- package/dist/workingDirectories.d.ts +32 -0
- package/dist/workingDirectories.js +71 -0
- package/dist/worktreeChoice.d.ts +31 -0
- package/dist/worktreeChoice.js +38 -0
- package/locales/en/agentTranscript.json +2 -10
- package/locales/en/agents.json +5 -5
- package/locales/es/agentTranscript.json +2 -10
- package/locales/es/agents.json +5 -5
- package/locales/ja/agentTranscript.json +2 -10
- package/locales/ja/agents.json +5 -5
- package/locales/ko/agentTranscript.json +2 -10
- package/locales/ko/agents.json +5 -5
- package/locales/zh/agentTranscript.json +2 -10
- package/locales/zh/agents.json +5 -5
- package/package.json +3 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Schemas } from './apiClient.js';
|
|
2
|
+
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
3
|
+
import { type PwCodeMachine } from './machine.js';
|
|
4
|
+
import type { PwCodeWorktreeRef } from './sessionHeader.js';
|
|
5
|
+
type Session = Schemas['AgentSession'];
|
|
6
|
+
/** The session the reader has open, if any. */
|
|
7
|
+
export interface OpenSessionRef {
|
|
8
|
+
machine?: string | undefined;
|
|
9
|
+
sessionId?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
/** What a menu entry does, so a host can give it an icon of its own. */
|
|
12
|
+
export type SessionMenuAction = 'rename' | 'restore' | 'pin' | 'unpin' | 'fork' | 'leaveWorktree' | 'stop' | 'archive' | 'delete' | 'moveToGroup' | 'joinGroup' | 'moveToNewGroup' | 'renameGroup' | 'deleteGroup' | 'newSession' | 'newGroup';
|
|
13
|
+
export interface SessionMenuCommand {
|
|
14
|
+
action: SessionMenuAction;
|
|
15
|
+
label: string;
|
|
16
|
+
run: () => void;
|
|
17
|
+
/** Why it can't be chosen now, for a host that shows it disabled. */
|
|
18
|
+
disabledReason?: string | undefined;
|
|
19
|
+
/** The key a focused row takes for it, as `shortcuts` binds it. */
|
|
20
|
+
shortcut?: string | undefined;
|
|
21
|
+
destructive?: boolean | undefined;
|
|
22
|
+
/** An on/off choice, on while true. */
|
|
23
|
+
checked?: boolean | undefined;
|
|
24
|
+
}
|
|
25
|
+
export interface SessionSubmenu {
|
|
26
|
+
action: SessionMenuAction;
|
|
27
|
+
label: string;
|
|
28
|
+
disabledReason?: string | undefined;
|
|
29
|
+
items: SessionMenuItem[];
|
|
30
|
+
}
|
|
31
|
+
/** A menu as data, which a host draws with its own components. */
|
|
32
|
+
export type SessionMenuItem = SessionMenuCommand | SessionSubmenu | 'divider';
|
|
33
|
+
/** A key that acts on a session's row while it has focus. */
|
|
34
|
+
export interface SessionRowKey<R> {
|
|
35
|
+
keys: string | readonly string[];
|
|
36
|
+
run: (row: R) => void;
|
|
37
|
+
}
|
|
38
|
+
/** What the host asks the reader before an action. */
|
|
39
|
+
export interface SessionConfirmation<R> {
|
|
40
|
+
action: 'delete' | 'archive' | 'leaveWorktree';
|
|
41
|
+
session: Session;
|
|
42
|
+
title: string;
|
|
43
|
+
description: string;
|
|
44
|
+
confirmLabel: string;
|
|
45
|
+
destructive: boolean;
|
|
46
|
+
/** The host offers to remove the session's worktree too, and passes the
|
|
47
|
+
* root of the one the reader chose to remove to `onConfirm`. */
|
|
48
|
+
offersWorktreeRemoval: boolean;
|
|
49
|
+
/** The row the action takes out of the list, as the host passed it in. */
|
|
50
|
+
removes?: R | undefined;
|
|
51
|
+
/** Asked with a key pressed on the row, so the next press may answer it. */
|
|
52
|
+
fromKey?: boolean | undefined;
|
|
53
|
+
/** Rejects with the machine's refusal, for the host to show while it still asks. */
|
|
54
|
+
onConfirm: (removeWorktree?: string) => Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/** The session being renamed while the host's prompt for its name is up. */
|
|
57
|
+
export interface SessionRename {
|
|
58
|
+
session: Session | null;
|
|
59
|
+
name: string;
|
|
60
|
+
setName: (name: string) => void;
|
|
61
|
+
/** Saves the trimmed name and closes; a refusal goes to `onRefusal` and leaves it open. */
|
|
62
|
+
confirm: () => Promise<void>;
|
|
63
|
+
close: () => void;
|
|
64
|
+
}
|
|
65
|
+
export interface SessionActionsOptions<R> {
|
|
66
|
+
api: Pick<PwCodeApi, 'useSessionMutations' | 'leaveWorktree'>;
|
|
67
|
+
machineById: ReadonlyMap<string, PwCodeMachine>;
|
|
68
|
+
open: OpenSessionRef;
|
|
69
|
+
confirm: (request: SessionConfirmation<R>) => void;
|
|
70
|
+
/** A refusal of an action taken without asking, or what was thrown when the request failed. */
|
|
71
|
+
onRefusal: (refusal: unknown) => void;
|
|
72
|
+
onWarning: (message: string) => void;
|
|
73
|
+
/** Leaves the open session once it is deleted or archived. */
|
|
74
|
+
showStart: () => void;
|
|
75
|
+
/** Opens a session, as forking does with the copy. */
|
|
76
|
+
showSession: (session: Pick<Session, 'machineId' | 'id'>) => void;
|
|
77
|
+
}
|
|
78
|
+
export interface SessionActions<R> {
|
|
79
|
+
/** Given its row, a delete or archive names the row it removes, and the
|
|
80
|
+
* entries show the keys the row takes. Given its worktree, it offers to leave it. */
|
|
81
|
+
menu: (session: Session, row?: R, worktree?: PwCodeWorktreeRef) => SessionMenuItem[];
|
|
82
|
+
/** The keys skip what the menu disables, as choosing a disabled entry does. */
|
|
83
|
+
shortcuts: (session: Session) => SessionRowKey<R>[];
|
|
84
|
+
rename: SessionRename;
|
|
85
|
+
requestRename: (session: Session) => void;
|
|
86
|
+
requestDelete: (session: Session, row?: R, fromKey?: boolean) => void;
|
|
87
|
+
requestArchive: (session: Session, row?: R) => void;
|
|
88
|
+
requestLeaveWorktree: (session: Session, worktree: PwCodeWorktreeRef) => void;
|
|
89
|
+
restore: (session: Session) => void;
|
|
90
|
+
stop: (session: Session) => void;
|
|
91
|
+
togglePin: (session: Session) => void;
|
|
92
|
+
fork: (session: Session) => void;
|
|
93
|
+
/** `group` null takes the session out of its group. */
|
|
94
|
+
moveToGroup: (session: Session, group: string | null) => void;
|
|
95
|
+
/** Why the session's machine cannot record a group, if it cannot. */
|
|
96
|
+
groupBlocked: (session: Session) => string | undefined;
|
|
97
|
+
/** Why the session cannot be archived, if it cannot. */
|
|
98
|
+
archiveBlocked: (session: Session) => string | undefined;
|
|
99
|
+
}
|
|
100
|
+
export declare function menuCommand(action: SessionMenuAction, label: string, run: () => void, disabledReason?: string | undefined, shortcut?: string | undefined): SessionMenuCommand;
|
|
101
|
+
/** A session's actions and the flows behind them: the list is patched as
|
|
102
|
+
* soon as the daemon agrees, and deleting or archiving the open session
|
|
103
|
+
* shows the start rather than a transcript that is gone or shut down. */
|
|
104
|
+
export declare function useSessionActions<R = unknown>({ api, machineById, open, confirm, onRefusal, onWarning, showStart, showSession, }: SessionActionsOptions<R>): SessionActions<R>;
|
|
105
|
+
export {};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { isMachineDown } from "./machine.js";
|
|
2
|
+
import { usePwCodeTranslations } from "./messages.js";
|
|
3
|
+
import { isArchived, isMidTurn, isSession } from "./session.js";
|
|
4
|
+
import { machineHint, sessionLabel, sessionStatusText } from "./wording.js";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
// src/sessionActions.ts
|
|
7
|
+
var DELETE_KEYS = ["Backspace", "Delete"];
|
|
8
|
+
var ARCHIVE_KEY = "A";
|
|
9
|
+
function machineBlocked(machine, t) {
|
|
10
|
+
return isMachineDown(machine) ? machineHint(machine, t)?.text : void 0;
|
|
11
|
+
}
|
|
12
|
+
/** The daemon refuses these for a session another host holds. */
|
|
13
|
+
function sessionActionBlocked(session, machine, t) {
|
|
14
|
+
if (isMachineDown(machine)) return machineBlocked(machine, t);
|
|
15
|
+
if (session.status === "live_elsewhere") return sessionStatusText(session, t);
|
|
16
|
+
}
|
|
17
|
+
function menuCommand(action, label, run, disabledReason, shortcut) {
|
|
18
|
+
return {
|
|
19
|
+
action,
|
|
20
|
+
label,
|
|
21
|
+
run,
|
|
22
|
+
...disabledReason ? { disabledReason } : {},
|
|
23
|
+
...shortcut ? { shortcut } : {}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** A session's actions and the flows behind them: the list is patched as
|
|
27
|
+
* soon as the daemon agrees, and deleting or archiving the open session
|
|
28
|
+
* shows the start rather than a transcript that is gone or shut down. */
|
|
29
|
+
function useSessionActions({ api, machineById, open, confirm, onRefusal, onWarning, showStart, showSession }) {
|
|
30
|
+
const t = usePwCodeTranslations("agents");
|
|
31
|
+
const { archiveSession, deleteSession, forkSession, groupSession, pinSession, renameSession, restoreSession, stopSession } = api.useSessionMutations();
|
|
32
|
+
const [toRename, setToRename] = useState(null);
|
|
33
|
+
const [name, setName] = useState("");
|
|
34
|
+
const closeRename = () => {
|
|
35
|
+
setToRename(null);
|
|
36
|
+
setName("");
|
|
37
|
+
};
|
|
38
|
+
const confirmRename = async () => {
|
|
39
|
+
const trimmed = name.trim();
|
|
40
|
+
if (toRename === null || !trimmed) return;
|
|
41
|
+
const refusal = await renameSession(toRename, trimmed).catch((thrown) => thrown);
|
|
42
|
+
if (refusal) {
|
|
43
|
+
onRefusal(refusal);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
closeRename();
|
|
47
|
+
};
|
|
48
|
+
const isOpen = (s) => isSession(s, open.machine, open.sessionId);
|
|
49
|
+
const report = (refusal) => {
|
|
50
|
+
if (refusal) onRefusal(refusal);
|
|
51
|
+
};
|
|
52
|
+
const settle = (action) => void action.then(report, report);
|
|
53
|
+
const requestRename = (s) => {
|
|
54
|
+
setName(s.name || s.autoName || "");
|
|
55
|
+
setToRename(s);
|
|
56
|
+
};
|
|
57
|
+
const requestDelete = (s, row, fromKey = false) => confirm({
|
|
58
|
+
action: "delete",
|
|
59
|
+
session: s,
|
|
60
|
+
title: t("sidebar.deleteTitle"),
|
|
61
|
+
description: t("sidebar.deleteBody", {
|
|
62
|
+
name: sessionLabel(s, t),
|
|
63
|
+
machine: machineById.get(s.machineId)?.name ?? ""
|
|
64
|
+
}),
|
|
65
|
+
confirmLabel: t("sidebar.deleteAction"),
|
|
66
|
+
destructive: true,
|
|
67
|
+
offersWorktreeRemoval: true,
|
|
68
|
+
removes: row,
|
|
69
|
+
fromKey,
|
|
70
|
+
onConfirm: async (removeWorktree) => {
|
|
71
|
+
const refusal = await deleteSession(s, removeWorktree);
|
|
72
|
+
if (refusal) throw refusal;
|
|
73
|
+
if (isOpen(s)) showStart();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const requestArchive = (s, row) => confirm({
|
|
77
|
+
action: "archive",
|
|
78
|
+
session: s,
|
|
79
|
+
title: t("sidebar.archiveTitle", { name: sessionLabel(s, t) }),
|
|
80
|
+
description: t("sidebar.archiveBody"),
|
|
81
|
+
confirmLabel: t("sidebar.archive"),
|
|
82
|
+
destructive: false,
|
|
83
|
+
offersWorktreeRemoval: false,
|
|
84
|
+
removes: row,
|
|
85
|
+
onConfirm: async () => {
|
|
86
|
+
const refusal = await archiveSession(s);
|
|
87
|
+
if (refusal) throw refusal;
|
|
88
|
+
if (isOpen(s)) showStart();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const requestLeaveWorktree = (s, worktree) => confirm({
|
|
92
|
+
action: "leaveWorktree",
|
|
93
|
+
session: s,
|
|
94
|
+
title: t("sidebar.leaveWorktreeTitle"),
|
|
95
|
+
description: t("sidebar.leaveWorktreeBody", { workspace: s.workspace }),
|
|
96
|
+
confirmLabel: t("sidebar.leaveWorktree"),
|
|
97
|
+
destructive: false,
|
|
98
|
+
offersWorktreeRemoval: true,
|
|
99
|
+
onConfirm: async (removeWorktree) => {
|
|
100
|
+
const { left, refusal } = await api.leaveWorktree(s, removeWorktree);
|
|
101
|
+
if (refusal) throw refusal;
|
|
102
|
+
worktree.refresh();
|
|
103
|
+
if (left?.outcome === "remove_failed") onWarning(t("sidebar.leaveWorktreeKept"));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const restore = (s) => settle(restoreSession(s));
|
|
107
|
+
const stop = (s) => settle(stopSession(s));
|
|
108
|
+
const togglePin = (s) => settle(pinSession(s, !s.pinnedAt));
|
|
109
|
+
const moveToGroup = (s, group) => settle(groupSession(s, group));
|
|
110
|
+
const fork = (s) => settle(forkSession(s).then(({ forked, refusal }) => {
|
|
111
|
+
if (forked) showSession(forked);
|
|
112
|
+
return refusal;
|
|
113
|
+
}));
|
|
114
|
+
const menu = (session, row, worktree) => {
|
|
115
|
+
const machine = machineById.get(session.machineId);
|
|
116
|
+
const disabledReason = sessionActionBlocked(session, machine, t);
|
|
117
|
+
const machineDown = machineBlocked(machine, t);
|
|
118
|
+
const rowKey = (key) => row === void 0 ? void 0 : key;
|
|
119
|
+
const rename = menuCommand("rename", t("sidebar.renameAction"), () => requestRename(session), disabledReason);
|
|
120
|
+
const remove = {
|
|
121
|
+
...menuCommand("delete", t("sidebar.deleteAction"), () => requestDelete(session, row), disabledReason, rowKey(DELETE_KEYS[0])),
|
|
122
|
+
destructive: true
|
|
123
|
+
};
|
|
124
|
+
if (isArchived(session)) return [
|
|
125
|
+
menuCommand("restore", t("sidebar.restore"), () => restore(session), machineDown),
|
|
126
|
+
rename,
|
|
127
|
+
"divider",
|
|
128
|
+
remove
|
|
129
|
+
];
|
|
130
|
+
const midTurn = isMidTurn(session) ? t("sidebar.forkMidTurn") : void 0;
|
|
131
|
+
return [
|
|
132
|
+
rename,
|
|
133
|
+
menuCommand(session.pinnedAt ? "unpin" : "pin", t(session.pinnedAt ? "sidebar.unpin" : "sidebar.pin"), () => togglePin(session), machineDown),
|
|
134
|
+
menuCommand("fork", t("sidebar.fork"), () => fork(session), disabledReason ?? midTurn),
|
|
135
|
+
...worktree ? [menuCommand("leaveWorktree", t("sidebar.leaveWorktree"), () => requestLeaveWorktree(session, worktree), disabledReason ?? midTurn)] : [],
|
|
136
|
+
...isMidTurn(session) ? [menuCommand("stop", t("sidebar.stop"), () => stop(session), machineDown)] : [],
|
|
137
|
+
menuCommand("archive", t("sidebar.archive"), () => requestArchive(session, row), disabledReason, rowKey(ARCHIVE_KEY)),
|
|
138
|
+
"divider",
|
|
139
|
+
remove
|
|
140
|
+
];
|
|
141
|
+
};
|
|
142
|
+
const shortcuts = (session) => {
|
|
143
|
+
if (sessionActionBlocked(session, machineById.get(session.machineId), t)) return [];
|
|
144
|
+
return [{
|
|
145
|
+
keys: DELETE_KEYS,
|
|
146
|
+
run: (row) => requestDelete(session, row, true)
|
|
147
|
+
}, ...isArchived(session) ? [] : [{
|
|
148
|
+
keys: ARCHIVE_KEY,
|
|
149
|
+
run: (row) => requestArchive(session, row)
|
|
150
|
+
}]];
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
menu,
|
|
154
|
+
shortcuts,
|
|
155
|
+
rename: {
|
|
156
|
+
session: toRename,
|
|
157
|
+
name,
|
|
158
|
+
setName,
|
|
159
|
+
confirm: confirmRename,
|
|
160
|
+
close: closeRename
|
|
161
|
+
},
|
|
162
|
+
requestRename,
|
|
163
|
+
requestDelete,
|
|
164
|
+
requestArchive,
|
|
165
|
+
requestLeaveWorktree,
|
|
166
|
+
restore,
|
|
167
|
+
stop,
|
|
168
|
+
togglePin,
|
|
169
|
+
fork,
|
|
170
|
+
moveToGroup,
|
|
171
|
+
groupBlocked: (session) => {
|
|
172
|
+
const machine = machineById.get(session.machineId);
|
|
173
|
+
return machineBlocked(machine, t) ?? (machine?.sessionGroups ? void 0 : t("sidebar.groupsNeedUpdate", { machine: machine?.name ?? "" }));
|
|
174
|
+
},
|
|
175
|
+
archiveBlocked: (session) => sessionActionBlocked(session, machineById.get(session.machineId), t)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export { menuCommand, useSessionActions };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Dispatch, type SetStateAction } from 'react';
|
|
2
|
+
import { type PwCodeMachine } from './machine.js';
|
|
3
|
+
import { type PwCodeSession } from './session.js';
|
|
4
|
+
/** A group the reader made. Its name is theirs, so the host keeps it with
|
|
5
|
+
* their preferences; which group a session is in is on the session, kept by
|
|
6
|
+
* its machine's daemon. */
|
|
7
|
+
export interface SessionGroup {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ListedGroup<S = PwCodeSession> {
|
|
12
|
+
group: SessionGroup;
|
|
13
|
+
sessions: S[];
|
|
14
|
+
waiting: number;
|
|
15
|
+
running: number;
|
|
16
|
+
}
|
|
17
|
+
type Grouped = Pick<PwCodeSession, 'machineId' | 'status' | 'liveHost' | 'archivedAt' | 'group'>;
|
|
18
|
+
type Machines = ReadonlyMap<string, Pick<PwCodeMachine, 'status'>>;
|
|
19
|
+
export declare function patchGroup(groups: readonly SessionGroup[], id: string, patch: Partial<Omit<SessionGroup, 'id'>>): SessionGroup[];
|
|
20
|
+
/** The reader's group a session is in. One naming a group since deleted is in none. */
|
|
21
|
+
export declare function groupOf(groups: readonly SessionGroup[], session: Pick<PwCodeSession, 'group'>): SessionGroup | undefined;
|
|
22
|
+
/** A turn is running on a machine that still answers. */
|
|
23
|
+
export declare function isWorking(session: Pick<PwCodeSession, 'status'>, machine: Pick<PwCodeMachine, 'status'> | undefined): boolean;
|
|
24
|
+
/** Sessions as a group lists them: what waits on the reader, then what is
|
|
25
|
+
* live, then the rest, with how many wait and how many are working. */
|
|
26
|
+
export declare function inFlightFirst<S extends Grouped>(sessions: readonly S[], machineById: Machines): {
|
|
27
|
+
sessions: S[];
|
|
28
|
+
waiting: number;
|
|
29
|
+
running: number;
|
|
30
|
+
};
|
|
31
|
+
/** Each group's sessions, and the ones in none. Archived sessions stay with
|
|
32
|
+
* the archive. */
|
|
33
|
+
export declare function listGroups<S extends Grouped>(groups: readonly SessionGroup[], sessions: readonly S[], machineById: Machines): {
|
|
34
|
+
listed: ListedGroup<S>[];
|
|
35
|
+
ungrouped: S[];
|
|
36
|
+
};
|
|
37
|
+
export interface SessionGroups {
|
|
38
|
+
groups: SessionGroup[];
|
|
39
|
+
create: (name: string) => SessionGroup;
|
|
40
|
+
patch: (id: string, change: Partial<Omit<SessionGroup, 'id'>>) => void;
|
|
41
|
+
remove: (id: string) => void;
|
|
42
|
+
}
|
|
43
|
+
/** The reader's groups, over state the host keeps for them, as `useState`
|
|
44
|
+
* returns it. `newId` names a group as it is made. */
|
|
45
|
+
export declare function useSessionGroups([groups, setGroups]: readonly [
|
|
46
|
+
SessionGroup[],
|
|
47
|
+
Dispatch<SetStateAction<SessionGroup[]>>
|
|
48
|
+
], newId: () => string): SessionGroups;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isMachineDown } from "./machine.js";
|
|
2
|
+
import { isActiveSession, isArchived, needsYou } from "./session.js";
|
|
3
|
+
import { useCallback, useMemo } from "react";
|
|
4
|
+
// src/sessionGroups.ts
|
|
5
|
+
function patchGroup(groups, id, patch) {
|
|
6
|
+
return groups.map((g) => g.id === id ? {
|
|
7
|
+
...g,
|
|
8
|
+
...patch
|
|
9
|
+
} : g);
|
|
10
|
+
}
|
|
11
|
+
/** The reader's group a session is in. One naming a group since deleted is in none. */
|
|
12
|
+
function groupOf(groups, session) {
|
|
13
|
+
return session.group ? groups.find((g) => g.id === session.group) : void 0;
|
|
14
|
+
}
|
|
15
|
+
/** A turn is running on a machine that still answers. */
|
|
16
|
+
function isWorking(session, machine) {
|
|
17
|
+
return session.status === "running" && !isMachineDown(machine);
|
|
18
|
+
}
|
|
19
|
+
/** Sessions as a group lists them: what waits on the reader, then what is
|
|
20
|
+
* live, then the rest, with how many wait and how many are working. */
|
|
21
|
+
function inFlightFirst(sessions, machineById) {
|
|
22
|
+
const waiting = sessions.filter((s) => needsYou(s, machineById.get(s.machineId)));
|
|
23
|
+
const rest = sessions.filter((s) => !waiting.includes(s));
|
|
24
|
+
const live = rest.filter(isActiveSession);
|
|
25
|
+
return {
|
|
26
|
+
sessions: [
|
|
27
|
+
...waiting,
|
|
28
|
+
...live,
|
|
29
|
+
...rest.filter((s) => !isActiveSession(s))
|
|
30
|
+
],
|
|
31
|
+
waiting: waiting.length,
|
|
32
|
+
running: live.filter((s) => isWorking(s, machineById.get(s.machineId))).length
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Each group's sessions, and the ones in none. Archived sessions stay with
|
|
36
|
+
* the archive. */
|
|
37
|
+
function listGroups(groups, sessions, machineById) {
|
|
38
|
+
const grouped = (s) => isArchived(s) ? void 0 : groupOf(groups, s);
|
|
39
|
+
return {
|
|
40
|
+
listed: groups.map((group) => ({
|
|
41
|
+
group,
|
|
42
|
+
...inFlightFirst(sessions.filter((s) => grouped(s) === group), machineById)
|
|
43
|
+
})),
|
|
44
|
+
ungrouped: sessions.filter((s) => !grouped(s))
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** The reader's groups, over state the host keeps for them, as `useState`
|
|
48
|
+
* returns it. `newId` names a group as it is made. */
|
|
49
|
+
function useSessionGroups([groups, setGroups], newId) {
|
|
50
|
+
const create = useCallback((name) => {
|
|
51
|
+
const group = {
|
|
52
|
+
id: newId(),
|
|
53
|
+
name
|
|
54
|
+
};
|
|
55
|
+
setGroups((current) => [...current, group]);
|
|
56
|
+
return group;
|
|
57
|
+
}, [setGroups, newId]);
|
|
58
|
+
const patch = useCallback((id, change) => setGroups((current) => patchGroup(current, id, change)), [setGroups]);
|
|
59
|
+
const remove = useCallback((id) => setGroups((current) => current.filter((g) => g.id !== id)), [setGroups]);
|
|
60
|
+
return useMemo(() => ({
|
|
61
|
+
groups,
|
|
62
|
+
create,
|
|
63
|
+
patch,
|
|
64
|
+
remove
|
|
65
|
+
}), [
|
|
66
|
+
groups,
|
|
67
|
+
create,
|
|
68
|
+
patch,
|
|
69
|
+
remove
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
export { groupOf, inFlightFirst, isWorking, listGroups, patchGroup, useSessionGroups };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The worktree a session works in, as its actions take it, and a way to read it again. */
|
|
2
|
+
export type PwCodeWorktreeRef = {
|
|
3
|
+
root: string;
|
|
4
|
+
refresh: () => void;
|
|
5
|
+
};
|
|
6
|
+
/** The worktree `useSessionWorktree` read, read again whenever the live
|
|
7
|
+
* session reports it moved; undefined while the session works where it
|
|
8
|
+
* launched. */
|
|
9
|
+
export declare function useFollowedWorktree(worktree: {
|
|
10
|
+
data?: {
|
|
11
|
+
root?: string | undefined;
|
|
12
|
+
} | undefined;
|
|
13
|
+
mutate: () => Promise<unknown>;
|
|
14
|
+
}, liveWorktree: string | undefined): PwCodeWorktreeRef | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
// src/sessionHeader.ts
|
|
3
|
+
/** The worktree `useSessionWorktree` read, read again whenever the live
|
|
4
|
+
* session reports it moved; undefined while the session works where it
|
|
5
|
+
* launched. */
|
|
6
|
+
function useFollowedWorktree(worktree, liveWorktree) {
|
|
7
|
+
const { data, mutate } = worktree;
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
mutate();
|
|
10
|
+
}, [liveWorktree, mutate]);
|
|
11
|
+
return data?.root ? {
|
|
12
|
+
root: data.root,
|
|
13
|
+
refresh: () => void mutate()
|
|
14
|
+
} : void 0;
|
|
15
|
+
}
|
|
16
|
+
export { useFollowedWorktree };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { PwCodeApiError, Schemas } from './apiClient.js';
|
|
2
|
+
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
3
|
+
import { type PwCodeMachine } from './machine.js';
|
|
4
|
+
import { type PwCodeTranslator } from './messages.js';
|
|
5
|
+
import { type PwCodeSession, sessionVariant } from './session.js';
|
|
6
|
+
import { type OpenSessionRef, type SessionActions, type SessionMenuItem, type SessionRowKey } from './sessionActions.js';
|
|
7
|
+
import { type SessionGroup, type SessionGroups } from './sessionGroups.js';
|
|
8
|
+
import { sessionStateText } from './wording.js';
|
|
9
|
+
type Session = Schemas['AgentSession'];
|
|
10
|
+
type Translate = PwCodeTranslator<'agents'>;
|
|
11
|
+
type Machines = ReadonlyMap<string, Pick<PwCodeMachine, 'status'>>;
|
|
12
|
+
type Listed = Pick<PwCodeSession, 'machineId' | 'status' | 'liveHost' | 'archivedAt' | 'pinnedAt' | 'group' | 'updatedAt'>;
|
|
13
|
+
/** Where a session dropped on a section goes: with the pinned ones, into one
|
|
14
|
+
* of the reader's groups or out of any, or into the archive. */
|
|
15
|
+
export type SessionDropTarget = {
|
|
16
|
+
pinned: true;
|
|
17
|
+
} | {
|
|
18
|
+
groupId: string | null;
|
|
19
|
+
} | {
|
|
20
|
+
archived: true;
|
|
21
|
+
};
|
|
22
|
+
export type SessionSectionKind = 'pinned' | 'group' | 'needsYou' | 'active' | 'inactive' | 'archived';
|
|
23
|
+
export interface SessionSection<S> {
|
|
24
|
+
/** The same on every visit, so a host can keep which sections are folded by it. */
|
|
25
|
+
key: string;
|
|
26
|
+
kind: SessionSectionKind;
|
|
27
|
+
label: string;
|
|
28
|
+
sessions: S[];
|
|
29
|
+
target: SessionDropTarget;
|
|
30
|
+
/** How many of its sessions wait on the reader and how many are working,
|
|
31
|
+
* for the pinned ones and the reader's groups, whose headings count them. */
|
|
32
|
+
rollup?: {
|
|
33
|
+
waiting: number;
|
|
34
|
+
running: number;
|
|
35
|
+
};
|
|
36
|
+
group?: SessionGroup;
|
|
37
|
+
}
|
|
38
|
+
export declare const groupSectionKey: (id: string) => string;
|
|
39
|
+
/** The sections a list of sessions reads in: the pinned ones, each of the
|
|
40
|
+
* reader's groups, then the rest by whether they need the reader, are live,
|
|
41
|
+
* are at rest or are archived. A pinned session is listed with the pinned
|
|
42
|
+
* ones alone; it keeps its group and goes back to it once it is unpinned. */
|
|
43
|
+
export declare function sessionSections<S extends Listed>(sessions: S[], groups: readonly SessionGroup[], machineById: Machines, t: Translate): SessionSection<S>[];
|
|
44
|
+
/** The archive is listed only while it holds a session, so a dragged one
|
|
45
|
+
* would otherwise have nowhere to be dropped until the first is archived. */
|
|
46
|
+
export declare function withArchiveSection<S>(sections: SessionSection<S>[], t: Translate): SessionSection<S>[];
|
|
47
|
+
export declare function isUngroupedTarget(target: SessionDropTarget): boolean;
|
|
48
|
+
/** The sessions a search lists: archived ones stay out until a search reaches for them. */
|
|
49
|
+
export declare function searchedSessions<S extends Pick<PwCodeSession, 'archivedAt'>>(sessions: readonly S[], search: string): S[];
|
|
50
|
+
/** What a search finds a session by: `value` its label, machine, directory,
|
|
51
|
+
* id and pull requests, and `keywords` the name it was given or gave itself. */
|
|
52
|
+
export declare function sessionSearchText(session: Pick<PwCodeSession, 'machineId' | 'id' | 'name' | 'autoName' | 'preview' | 'workspace' | 'pullRequests'>, machine: Pick<PwCodeMachine, 'name'> | undefined, t: Translate): {
|
|
53
|
+
value: string;
|
|
54
|
+
keywords: string[];
|
|
55
|
+
};
|
|
56
|
+
/** A second line costs a row its height, so the state takes one only when the
|
|
57
|
+
* mark cannot express it: not "idle" or "running", but "waiting on you" and a
|
|
58
|
+
* dead machine. */
|
|
59
|
+
export declare function sessionRowState(session: Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate): {
|
|
60
|
+
stateText: string;
|
|
61
|
+
showSecondLine: boolean;
|
|
62
|
+
live: boolean;
|
|
63
|
+
};
|
|
64
|
+
/** A pinned session is under the pinned ones' heading, which says so; only an
|
|
65
|
+
* archived one, listed with the archive, needs the mark. */
|
|
66
|
+
export declare function showsPinMark(session: Pick<PwCodeSession, 'pinnedAt' | 'archivedAt'>): boolean;
|
|
67
|
+
/** A session at work shows a turning mark, which tells it from one resting
|
|
68
|
+
* between turns by its shape and so holds with reduced motion. Any other
|
|
69
|
+
* shows a dot in its state's tone, pulsing while it waits on the reader. */
|
|
70
|
+
export declare function sessionMark(session: Pick<PwCodeSession, 'status'>, machine: Pick<PwCodeMachine, 'status'> | undefined): {
|
|
71
|
+
working: true;
|
|
72
|
+
} | {
|
|
73
|
+
working: false;
|
|
74
|
+
tone: ReturnType<typeof sessionVariant<'success'>>;
|
|
75
|
+
pulse: boolean;
|
|
76
|
+
};
|
|
77
|
+
/** The server stores nothing, so a dropped machine contributes no sessions to
|
|
78
|
+
* the next poll; without this its sessions vanish instead of explaining themselves. */
|
|
79
|
+
export declare function useRetainedSessions<S extends Pick<PwCodeSession, 'machineId'>>(machines: readonly Pick<PwCodeMachine, 'id' | 'status'>[], sessions: S[]): S[];
|
|
80
|
+
export interface SessionListOptions<R> {
|
|
81
|
+
api: Pick<PwCodeApi, 'useSessions'>;
|
|
82
|
+
machineById: ReadonlyMap<string, PwCodeMachine>;
|
|
83
|
+
groups: SessionGroups;
|
|
84
|
+
/** The keys of the folded sections as the host keeps them, which may hold
|
|
85
|
+
* anything an older copy stored, and how it keeps new ones. */
|
|
86
|
+
folded: readonly [unknown, (keys: string[]) => void];
|
|
87
|
+
open: OpenSessionRef;
|
|
88
|
+
actions: Pick<SessionActions<R>, 'menu' | 'shortcuts' | 'togglePin' | 'moveToGroup' | 'groupBlocked' | 'archiveBlocked' | 'requestArchive'>;
|
|
89
|
+
newSession: () => void;
|
|
90
|
+
/** Asks the reader to name a group: one just made, or one to rename. */
|
|
91
|
+
promptGroupName: (group: SessionGroup) => void;
|
|
92
|
+
/** Asks the reader before a group goes; confirming calls `deleteGroup`. */
|
|
93
|
+
confirmGroupDelete: (group: SessionGroup) => void;
|
|
94
|
+
/** Says why a dropped session stays where it was. */
|
|
95
|
+
onBlocked: (reason: string) => void;
|
|
96
|
+
}
|
|
97
|
+
export interface SessionList<R> {
|
|
98
|
+
data: Schemas['AgentSessionsResponse'] | undefined;
|
|
99
|
+
error: PwCodeApiError | undefined;
|
|
100
|
+
/** The first listing has not answered yet. */
|
|
101
|
+
loading: boolean;
|
|
102
|
+
/** The listing, with what a machine that stopped answering listed last. */
|
|
103
|
+
sessions: Session[];
|
|
104
|
+
sections: SessionSection<Session>[];
|
|
105
|
+
/** There is something to search for, or soon may be. */
|
|
106
|
+
searchable: boolean;
|
|
107
|
+
/** The sessions span machines, so each one's names its machine. */
|
|
108
|
+
multiMachine: boolean;
|
|
109
|
+
openSession: Session | undefined;
|
|
110
|
+
/** What a collapsed list shows: what is live, and the open session so it
|
|
111
|
+
* keeps a place while it is idle. */
|
|
112
|
+
rail: Session[];
|
|
113
|
+
folded: string[];
|
|
114
|
+
toggleFold: (key: string) => void;
|
|
115
|
+
/** Folded over the open session, which would otherwise have no mark. */
|
|
116
|
+
holdsOpen: (section: Pick<SessionSection<Session>, 'key' | 'sessions'>) => boolean;
|
|
117
|
+
/** `key` is the dropped session's `sessionKey`. */
|
|
118
|
+
dropSession: (key: string, target: SessionDropTarget) => void;
|
|
119
|
+
/** Made first and named second: what joins it is in it either way. */
|
|
120
|
+
newGroup: () => SessionGroup;
|
|
121
|
+
renameGroup: (group: SessionGroup, name: string) => void;
|
|
122
|
+
/** Its sessions stay in the list, in no group. */
|
|
123
|
+
deleteGroup: (group: SessionGroup) => void;
|
|
124
|
+
/** The session's actions, with a choice of the reader's groups. */
|
|
125
|
+
menu: (session: Session, row?: R) => SessionMenuItem[];
|
|
126
|
+
groupMenu: (group: SessionGroup) => SessionMenuItem[];
|
|
127
|
+
/** For the list's empty space. */
|
|
128
|
+
listMenu: SessionMenuItem[];
|
|
129
|
+
shortcuts: (session: Session) => SessionRowKey<R>[];
|
|
130
|
+
}
|
|
131
|
+
/** The sessions as a list shows them, in sections, with what the reader can
|
|
132
|
+
* do to a row, a group or the list. */
|
|
133
|
+
export declare function useSessionList<R = unknown>({ api, machineById, groups, folded: [storedFolded, setFolded], open, actions, newSession, promptGroupName, confirmGroupDelete, onBlocked, }: SessionListOptions<R>): SessionList<R>;
|
|
134
|
+
export {};
|