@parallelworks/code 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +598 -113
  2. package/dist/accountApi.d.ts +31 -0
  3. package/dist/accountApi.js +182 -0
  4. package/dist/agentSwitcher.d.ts +109 -0
  5. package/dist/agentSwitcher.js +165 -0
  6. package/dist/ago.d.ts +3 -3
  7. package/dist/ago.js +10 -10
  8. package/dist/allocations.d.ts +41 -0
  9. package/dist/allocations.js +76 -0
  10. package/dist/api.d.ts +1080 -11
  11. package/dist/chatStrings.d.ts +188 -0
  12. package/dist/chatStrings.js +217 -0
  13. package/dist/claudeAccounts.d.ts +38 -1
  14. package/dist/claudeAccounts.js +98 -4
  15. package/dist/claudeApi.js +1 -1
  16. package/dist/claudeSignIn.d.ts +19 -1
  17. package/dist/claudeSignIn.js +12 -2
  18. package/dist/commandsApi.d.ts +11 -1
  19. package/dist/commandsApi.js +24 -5
  20. package/dist/createPwCodeApi.d.ts +44 -5
  21. package/dist/createPwCodeApi.js +18 -2
  22. package/dist/directories.d.ts +161 -0
  23. package/dist/directories.js +301 -0
  24. package/dist/goal.d.ts +89 -0
  25. package/dist/goal.js +164 -0
  26. package/dist/imageFit.d.ts +23 -0
  27. package/dist/imageFit.js +27 -0
  28. package/dist/images.d.ts +28 -0
  29. package/dist/images.js +38 -6
  30. package/dist/index.d.ts +27 -12
  31. package/dist/index.js +26 -12
  32. package/dist/loadError.d.ts +8 -0
  33. package/dist/loadError.js +19 -0
  34. package/dist/locales/en/agentTranscript.js +73 -12
  35. package/dist/locales/en/agents.js +71 -9
  36. package/dist/locales/en.d.ts +124 -8
  37. package/dist/locales/es/agentTranscript.js +73 -12
  38. package/dist/locales/es/agents.js +71 -9
  39. package/dist/locales/ja/agentTranscript.js +76 -15
  40. package/dist/locales/ja/agents.js +45 -120
  41. package/dist/locales/ko/agentTranscript.js +73 -12
  42. package/dist/locales/ko/agents.js +71 -9
  43. package/dist/locales/zh/agentTranscript.js +71 -10
  44. package/dist/locales/zh/agents.js +71 -9
  45. package/dist/machine.d.ts +2 -0
  46. package/dist/modelPicker.d.ts +79 -0
  47. package/dist/modelPicker.js +107 -0
  48. package/dist/notices.js +47 -19
  49. package/dist/platformDefaults.d.ts +22 -0
  50. package/dist/platformDefaults.js +30 -0
  51. package/dist/preferences.d.ts +78 -0
  52. package/dist/preferences.js +128 -0
  53. package/dist/pullRequestList.d.ts +10 -2
  54. package/dist/pullRequestList.js +41 -22
  55. package/dist/query.d.ts +6 -2
  56. package/dist/query.js +85 -10
  57. package/dist/session.d.ts +5 -2
  58. package/dist/session.js +12 -8
  59. package/dist/sessionActions.d.ts +11 -1
  60. package/dist/sessionActions.js +14 -6
  61. package/dist/sessionEvents.d.ts +8 -3
  62. package/dist/sessionEvents.js +10 -5
  63. package/dist/sessionGroups.d.ts +3 -2
  64. package/dist/sessionGroups.js +4 -3
  65. package/dist/sessionList.d.ts +57 -9
  66. package/dist/sessionList.js +74 -12
  67. package/dist/sessionScreen.d.ts +193 -0
  68. package/dist/sessionScreen.js +213 -0
  69. package/dist/sessionsApi.d.ts +13 -3
  70. package/dist/sessionsApi.js +88 -29
  71. package/dist/settingsApi.d.ts +3 -1
  72. package/dist/startPage.d.ts +153 -0
  73. package/dist/startPage.js +174 -0
  74. package/dist/startSession.d.ts +41 -7
  75. package/dist/startSession.js +26 -4
  76. package/dist/transcript.js +48 -15
  77. package/dist/types.d.ts +11 -1
  78. package/dist/useComposer.d.ts +25 -1
  79. package/dist/useComposer.js +54 -3
  80. package/dist/useComposerImages.d.ts +5 -0
  81. package/dist/useComposerImages.js +24 -1
  82. package/dist/useComposerPastes.d.ts +70 -0
  83. package/dist/useComposerPastes.js +130 -0
  84. package/dist/useConversation.d.ts +10 -1
  85. package/dist/useConversation.js +32 -5
  86. package/dist/useSubagent.d.ts +49 -3
  87. package/dist/useSubagent.js +70 -7
  88. package/dist/useTranscript.d.ts +23 -3
  89. package/dist/useTranscript.js +76 -19
  90. package/dist/wording.js +2 -2
  91. package/dist/workingDirectories.d.ts +31 -0
  92. package/dist/workingDirectories.js +25 -1
  93. package/locales/en/agentTranscript.json +67 -11
  94. package/locales/en/agents.json +68 -8
  95. package/locales/es/agentTranscript.json +67 -11
  96. package/locales/es/agents.json +68 -8
  97. package/locales/ja/agentTranscript.json +70 -14
  98. package/locales/ja/agents.json +68 -8
  99. package/locales/ko/agentTranscript.json +67 -11
  100. package/locales/ko/agents.json +68 -8
  101. package/locales/zh/agentTranscript.json +65 -9
  102. package/locales/zh/agents.json +68 -8
  103. package/package.json +6 -3
@@ -1,3 +1,4 @@
1
+ import { PREVIEWS_BY_REF } from "./images.js";
1
2
  import { isConnected } from "./machine.js";
2
3
  import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
3
4
  // src/sessionEvents.ts
@@ -5,9 +6,13 @@ var INITIAL_RETRY_MS = 1e3;
5
6
  var MAX_RETRY_MS = 3e4;
6
7
  var SOCKET_OPEN = 1;
7
8
  var SOCKET_CLOSED = 3;
8
- /** The path a session's event feed is served at, resuming after frame `after`. */
9
- function sessionEventsPath(machine, id, after) {
10
- return `/ws/code/machines/${encodeURIComponent(machine)}/sessions/${encodeURIComponent(id)}/events?after=${after}`;
9
+ /** The path a session's event feed is served at, resuming after frame `after`.
10
+ * With `previewsByRef` the images a tool read come without their previews,
11
+ * which the host loads by URL: a preview is tens of kilobytes, and over a slow
12
+ * connection what the session says next waits behind it. */
13
+ function sessionEventsPath(machine, id, after, previewsByRef = false) {
14
+ const previews = previewsByRef ? `&previews=${PREVIEWS_BY_REF}` : "";
15
+ return `/ws/code/machines/${encodeURIComponent(machine)}/sessions/${encodeURIComponent(id)}/events?after=${after}${previews}`;
11
16
  }
12
17
  /** Frames after which the list of subagents may read differently: one started
13
18
  * or ended, one asked for or got an approval, or a turn began or closed. */
@@ -114,7 +119,7 @@ function useReconnectingSocket({ open, path, connectionKey, enabled, onOpen, onM
114
119
  }, [enabled, connectionKey]);
115
120
  return connected;
116
121
  }
117
- function sessionEvents({ openSocket, hidden }) {
122
+ function sessionEvents({ openSocket, hidden, previewsByRef = false }) {
118
123
  const openFeeds = /* @__PURE__ */ new Map();
119
124
  const listeners = /* @__PURE__ */ new Set();
120
125
  let fedMachines = /* @__PURE__ */ new Set();
@@ -166,7 +171,7 @@ function sessionEvents({ openSocket, hidden }) {
166
171
  }, [key]);
167
172
  const connected = useReconnectingSocket({
168
173
  open: openSocket,
169
- path: () => sessionEventsPath(machine, id, cursor?.() ?? 0),
174
+ path: () => sessionEventsPath(machine, id, cursor?.() ?? 0, previewsByRef),
170
175
  connectionKey: key,
171
176
  enabled: cursor !== void 0,
172
177
  onOpen: () => setFeed({
@@ -14,7 +14,7 @@ export interface ListedGroup<S = PwCodeSession> {
14
14
  waiting: number;
15
15
  running: number;
16
16
  }
17
- type Grouped = Pick<PwCodeSession, 'machineId' | 'status' | 'liveHost' | 'archivedAt' | 'group'>;
17
+ type Grouped = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'liveHost' | 'archivedAt' | 'group' | 'createdAt'>;
18
18
  type Machines = ReadonlyMap<string, Pick<PwCodeMachine, 'status'>>;
19
19
  export declare function patchGroup(groups: readonly SessionGroup[], id: string, patch: Partial<Omit<SessionGroup, 'id'>>): SessionGroup[];
20
20
  /** The reader's group a session is in. One naming a group since deleted is in none. */
@@ -22,7 +22,8 @@ export declare function groupOf(groups: readonly SessionGroup[], session: Pick<P
22
22
  /** A turn is running on a machine that still answers. */
23
23
  export declare function isWorking(session: Pick<PwCodeSession, 'status'>, machine: Pick<PwCodeMachine, 'status'> | undefined): boolean;
24
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. */
25
+ * live, newest begun first, then the rest, with how many wait and how many
26
+ * are working. */
26
27
  export declare function inFlightFirst<S extends Grouped>(sessions: readonly S[], machineById: Machines): {
27
28
  sessions: S[];
28
29
  waiting: number;
@@ -1,5 +1,5 @@
1
1
  import { isMachineDown } from "./machine.js";
2
- import { isActiveSession, isArchived, needsYou } from "./session.js";
2
+ import { isActiveSession, isArchived, needsYou, newestCreatedFirst } from "./session.js";
3
3
  import { useCallback, useMemo } from "react";
4
4
  // src/sessionGroups.ts
5
5
  function patchGroup(groups, id, patch) {
@@ -17,11 +17,12 @@ function isWorking(session, machine) {
17
17
  return session.status === "running" && !isMachineDown(machine);
18
18
  }
19
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. */
20
+ * live, newest begun first, then the rest, with how many wait and how many
21
+ * are working. */
21
22
  function inFlightFirst(sessions, machineById) {
22
23
  const waiting = sessions.filter((s) => needsYou(s, machineById.get(s.machineId)));
23
24
  const rest = sessions.filter((s) => !waiting.includes(s));
24
- const live = rest.filter(isActiveSession);
25
+ const live = newestCreatedFirst(rest.filter(isActiveSession));
25
26
  return {
26
27
  sessions: [
27
28
  ...waiting,
@@ -3,13 +3,13 @@ import type { PwCodeApi } from './createPwCodeApi.js';
3
3
  import { type PwCodeMachine } from './machine.js';
4
4
  import { type PwCodeTranslator } from './messages.js';
5
5
  import { type PwCodeSession, sessionVariant } from './session.js';
6
- import { type OpenSessionRef, type SessionActions, type SessionMenuItem, type SessionRowKey } from './sessionActions.js';
6
+ import { type NamePromptWords, type OpenSessionRef, type SessionActions, type SessionMenuItem, type SessionRowKey } from './sessionActions.js';
7
7
  import { type SessionGroup, type SessionGroups } from './sessionGroups.js';
8
- import { sessionStateText } from './wording.js';
8
+ import { sessionLabel, sessionStateText } from './wording.js';
9
9
  type Session = Schemas['AgentSession'];
10
10
  type Translate = PwCodeTranslator<'agents'>;
11
11
  type Machines = ReadonlyMap<string, Pick<PwCodeMachine, 'status'>>;
12
- type Listed = Pick<PwCodeSession, 'machineId' | 'status' | 'liveHost' | 'archivedAt' | 'pinnedAt' | 'group' | 'updatedAt'>;
12
+ type Listed = Pick<PwCodeSession, 'machineId' | 'id' | 'status' | 'liveHost' | 'archivedAt' | 'pinnedAt' | 'group' | 'createdAt' | 'updatedAt'>;
13
13
  /** Where a session dropped on a section goes: with the pinned ones, into one
14
14
  * of the reader's groups or out of any, or into the archive. */
15
15
  export type SessionDropTarget = {
@@ -34,6 +34,8 @@ export interface SessionSection<S> {
34
34
  running: number;
35
35
  };
36
36
  group?: SessionGroup;
37
+ /** Set on the sessions that wait on the reader, whose heading draws the eye. */
38
+ tone?: 'attention' | undefined;
37
39
  }
38
40
  export declare const groupSectionKey: (id: string) => string;
39
41
  /** The sections a list of sessions reads in: the pinned ones, each of the
@@ -53,6 +55,26 @@ export declare function sessionSearchText(session: Pick<PwCodeSession, 'machineI
53
55
  value: string;
54
56
  keywords: string[];
55
57
  };
58
+ /** Ranks a fuzzy match of `search` in `value` and its `keywords` from 0 to 1,
59
+ * on command-score's scale, as cmdk's `defaultFilter` and the
60
+ * `command-score` package do. */
61
+ export type PwCodeSearchScorer = (value: string, search: string, keywords: string[]) => number;
62
+ /** How well `search` finds a session by its `sessionSearchText`, 0 for not at
63
+ * all: a pasted pull request link finds the sessions with that one, a number
64
+ * only text holding it as typed, and `score` ranks the rest. */
65
+ export declare function sessionSearchScore({ value, keywords }: {
66
+ value: string;
67
+ keywords: string[];
68
+ }, search: string, score: PwCodeSearchScorer): number;
69
+ /** The state a search result shows: that it is archived, or what a live one
70
+ * is doing. One at rest shows none. */
71
+ export declare function sessionSearchStatus(session: Parameters<typeof sessionStateText>[0] & Pick<PwCodeSession, 'archivedAt'>, machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate): {
72
+ kind: 'archived' | 'active';
73
+ text: string;
74
+ } | undefined;
75
+ /** What a session's mark on a collapsed list is called: its label, its
76
+ * machine and its state. */
77
+ export declare function sessionRailLabel(session: Parameters<typeof sessionLabel>[0] & Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'name' | 'status'> | undefined, t: Translate): string;
56
78
  /** A second line costs a row its height, so the state takes one only when the
57
79
  * mark cannot express it: not "idle" or "running", but "waiting on you" and a
58
80
  * dead machine. */
@@ -82,23 +104,39 @@ export interface SessionListOptions<R> {
82
104
  machineById: ReadonlyMap<string, PwCodeMachine>;
83
105
  groups: SessionGroups;
84
106
  /** 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];
107
+ * anything an older copy stored, and how it keeps new ones. A change is an
108
+ * update from the kept keys, so a store that has not loaded them yet can
109
+ * apply it to them rather than to its fallback. */
110
+ folded: readonly [unknown, (update: (previous: unknown) => string[]) => void];
87
111
  open: OpenSessionRef;
88
112
  actions: Pick<SessionActions<R>, 'menu' | 'shortcuts' | 'togglePin' | 'moveToGroup' | 'groupBlocked' | 'archiveBlocked' | 'requestArchive'>;
89
113
  newSession: () => void;
90
114
  /** Asks the reader to name a group: one just made, or one to rename. */
91
115
  promptGroupName: (group: SessionGroup) => void;
92
- /** Asks the reader before a group goes; confirming calls `deleteGroup`. */
93
- confirmGroupDelete: (group: SessionGroup) => void;
116
+ /** Asks the reader before a group goes; confirming calls `deleteGroup`.
117
+ * `fromKey` when a key pressed on its heading asked, so the next press may answer it. */
118
+ confirmGroupDelete: (group: SessionGroup, fromKey?: boolean) => void;
94
119
  /** Says why a dropped session stays where it was. */
95
120
  onBlocked: (reason: string) => void;
96
121
  }
122
+ export interface SessionGroupKey {
123
+ keys: string | readonly string[];
124
+ run: () => void;
125
+ }
126
+ /** What asking before a group goes says. */
127
+ export interface GroupDeleteWords {
128
+ title: string;
129
+ description: (group: SessionGroup) => string;
130
+ confirmLabel: string;
131
+ }
97
132
  export interface SessionList<R> {
98
133
  data: Schemas['AgentSessionsResponse'] | undefined;
99
134
  error: PwCodeApiError | undefined;
100
135
  /** The first listing has not answered yet. */
101
136
  loading: boolean;
137
+ /** Why no listing came, the error to show in the list's place. A poll that
138
+ * fails after one did keeps the last listing and says nothing. */
139
+ loadError: PwCodeApiError | undefined;
102
140
  /** The listing, with what a machine that stopped answering listed last. */
103
141
  sessions: Session[];
104
142
  sections: SessionSection<Session>[];
@@ -114,16 +152,26 @@ export interface SessionList<R> {
114
152
  toggleFold: (key: string) => void;
115
153
  /** Folded over the open session, which would otherwise have no mark. */
116
154
  holdsOpen: (section: Pick<SessionSection<Session>, 'key' | 'sessions'>) => boolean;
117
- /** `key` is the dropped session's `sessionKey`. */
155
+ /** An archived session stays with the archive, so its row is not dragged. */
156
+ canDrag: (session: Session) => boolean;
157
+ /** `key` is the dropped session's `sessionKey`. One `canDrag` refuses stays where it was. */
118
158
  dropSession: (key: string, target: SessionDropTarget) => void;
119
159
  /** Made first and named second: what joins it is in it either way. */
120
160
  newGroup: () => SessionGroup;
121
- renameGroup: (group: SessionGroup, name: string) => void;
161
+ /** Saves the name without the spaces around it. A blank one is not saved,
162
+ * and false says so, for a prompt to stay open. */
163
+ renameGroup: (group: SessionGroup, name: string) => boolean;
164
+ /** What the prompt `promptGroupName` asks for says. */
165
+ groupNameWords: NamePromptWords;
166
+ /** What the question `confirmGroupDelete` asks says. */
167
+ groupDeleteWords: GroupDeleteWords;
122
168
  /** Its sessions stay in the list, in no group. */
123
169
  deleteGroup: (group: SessionGroup) => void;
124
170
  /** The session's actions, with a choice of the reader's groups. */
125
171
  menu: (session: Session, row?: R) => SessionMenuItem[];
126
172
  groupMenu: (group: SessionGroup) => SessionMenuItem[];
173
+ /** The keys a group's heading takes while it has focus, as its menu shows them. */
174
+ groupShortcuts: (group: SessionGroup) => SessionGroupKey[];
127
175
  /** For the list's empty space. */
128
176
  listMenu: SessionMenuItem[];
129
177
  shortcuts: (session: Session) => SessionRowKey<R>[];
@@ -1,8 +1,8 @@
1
1
  import { isConnected, isMachineDown } from "./machine.js";
2
2
  import { usePwCodeTranslations } from "./messages.js";
3
- import { pullRequestLabel } from "./pullRequest.js";
4
- import { isActiveSession, isArchived, isSession, needsYou, newestFirst, sessionKey, sessionVariant, spansMachines } from "./session.js";
5
- import { menuCommand } from "./sessionActions.js";
3
+ import { pastedPullRequestLabel, pullRequestLabel } from "./pullRequest.js";
4
+ import { isActiveSession, isArchived, isSession, needsYou, newestCreatedFirst, newestFirst, sessionKey, sessionVariant, spansMachines } from "./session.js";
5
+ import { DELETE_KEYS, menuCommand, nameToSave } from "./sessionActions.js";
6
6
  import { groupOf, inFlightFirst, isWorking, listGroups } from "./sessionGroups.js";
7
7
  import { sessionLabel, sessionStateText } from "./wording.js";
8
8
  import { useEffect, useMemo, useRef } from "react";
@@ -31,13 +31,14 @@ function statusSections(sessions, waiting, t) {
31
31
  kind: "needsYou",
32
32
  label: t("sidebar.groupNeedsYou"),
33
33
  sessions: waiting,
34
- target: UNGROUPED
34
+ target: UNGROUPED,
35
+ tone: "attention"
35
36
  },
36
37
  {
37
38
  key: "active",
38
39
  kind: "active",
39
40
  label: t("sidebar.groupActive"),
40
- sessions: rest.filter(isActiveSession),
41
+ sessions: newestCreatedFirst(rest.filter(isActiveSession)),
41
42
  target: UNGROUPED
42
43
  },
43
44
  {
@@ -109,6 +110,39 @@ function sessionSearchText(session, machine, t) {
109
110
  keywords: [session.name || session.autoName || session.preview || ""]
110
111
  };
111
112
  }
113
+ var MIN_SCORE = .1;
114
+ /** How well `search` finds a session by its `sessionSearchText`, 0 for not at
115
+ * all: a pasted pull request link finds the sessions with that one, a number
116
+ * only text holding it as typed, and `score` ranks the rest. */
117
+ function sessionSearchScore({ value, keywords }, search, score) {
118
+ const text = [value, ...keywords].join(" ");
119
+ const pr = pastedPullRequestLabel(search)?.toLowerCase();
120
+ if (pr && text.toLowerCase().split(/\s+/).includes(pr)) return 1;
121
+ if (search.match(/\d+/g)?.some((number) => !text.includes(number))) return 0;
122
+ const fuzzy = score(value, search, keywords);
123
+ return fuzzy < MIN_SCORE ? 0 : fuzzy;
124
+ }
125
+ /** The state a search result shows: that it is archived, or what a live one
126
+ * is doing. One at rest shows none. */
127
+ function sessionSearchStatus(session, machine, t) {
128
+ if (isArchived(session)) return {
129
+ kind: "archived",
130
+ text: t("sidebar.groupArchived")
131
+ };
132
+ return isActiveSession(session) ? {
133
+ kind: "active",
134
+ text: sessionStateText(session, machine, t)
135
+ } : void 0;
136
+ }
137
+ /** What a session's mark on a collapsed list is called: its label, its
138
+ * machine and its state. */
139
+ function sessionRailLabel(session, machine, t) {
140
+ return [
141
+ sessionLabel(session, t),
142
+ machine?.name,
143
+ sessionStateText(session, machine, t)
144
+ ].filter(Boolean).join(" · ");
145
+ }
112
146
  /** A second line costs a row its height, so the state takes one only when the
113
147
  * mark cannot express it: not "idle" or "running", but "waiting on you" and a
114
148
  * dead machine. */
@@ -157,13 +191,16 @@ function useRetainedSessions(machines, sessions) {
157
191
  return retained.length > 0 ? [...sessions, ...retained] : sessions;
158
192
  }, [machines, sessions]);
159
193
  }
194
+ function foldedKeys(stored) {
195
+ return Array.isArray(stored) ? stored : [];
196
+ }
160
197
  /** The sessions as a list shows them, in sections, with what the reader can
161
198
  * do to a row, a group or the list. */
162
199
  function useSessionList({ api, machineById, groups, folded: [storedFolded, setFolded], open, actions, newSession, promptGroupName, confirmGroupDelete, onBlocked }) {
163
200
  const t = usePwCodeTranslations("agents");
164
201
  const { data, error, isLoading } = api.useSessions();
165
202
  const sessions = useRetainedSessions(useMemo(() => data?.machines ?? [], [data]), useMemo(() => data?.sessions ?? [], [data]));
166
- const folded = Array.isArray(storedFolded) ? storedFolded : [];
203
+ const folded = foldedKeys(storedFolded);
167
204
  const sections = sessionSections(sessions, groups.groups, machineById, t);
168
205
  const listedSessions = sections.flatMap((s) => s.sessions);
169
206
  const openSession = listedSessions.find((s) => isSession(s, open.machine, open.sessionId));
@@ -176,7 +213,7 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
176
213
  const deleteGroup = (group) => {
177
214
  groups.remove(group.id);
178
215
  const key = groupSectionKey(group.id);
179
- if (folded.includes(key)) setFolded(folded.filter((k) => k !== key));
216
+ if (folded.includes(key)) setFolded((previous) => foldedKeys(previous).filter((k) => k !== key));
180
217
  for (const s of sessions) if (s.group === group.id && !actions.groupBlocked(s)) actions.moveToGroup(s, null);
181
218
  };
182
219
  const dropOnArchive = (session) => {
@@ -187,9 +224,10 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
187
224
  }
188
225
  actions.requestArchive(session);
189
226
  };
227
+ const canDrag = (session) => !isArchived(session);
190
228
  const dropSession = (key, target) => {
191
229
  const session = sessions.find((s) => sessionKey(s) === key);
192
- if (!session) return;
230
+ if (!session || !canDrag(session)) return;
193
231
  if ("archived" in target) {
194
232
  dropOnArchive(session);
195
233
  return;
@@ -237,6 +275,7 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
237
275
  data,
238
276
  error,
239
277
  loading,
278
+ loadError: data ? void 0 : error,
240
279
  sessions,
241
280
  sections,
242
281
  searchable: loading || sections.length > 0,
@@ -244,21 +283,44 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
244
283
  openSession,
245
284
  rail: listedSessions.filter((s) => isActiveSession(s) && isConnected(machineById.get(s.machineId)) || s === openSession),
246
285
  folded,
247
- toggleFold: (key) => setFolded(folded.includes(key) ? folded.filter((k) => k !== key) : [...folded, key]),
286
+ toggleFold: (key) => setFolded((previous) => {
287
+ const keys = foldedKeys(previous);
288
+ return keys.includes(key) ? keys.filter((k) => k !== key) : [...keys, key];
289
+ }),
248
290
  holdsOpen: (section) => folded.includes(section.key) && !!openSession && section.sessions.includes(openSession),
291
+ canDrag,
249
292
  dropSession,
250
293
  newGroup,
251
- renameGroup: (group, name) => groups.patch(group.id, { name }),
294
+ renameGroup: (group, name) => {
295
+ const saved = nameToSave(name);
296
+ if (saved) groups.patch(group.id, { name: saved });
297
+ return !!saved;
298
+ },
299
+ groupNameWords: {
300
+ title: t("sidebar.renameGroupTitle"),
301
+ label: t("sidebar.groupNameLabel"),
302
+ placeholder: t("sidebar.groupNamePlaceholder"),
303
+ confirmLabel: t("sidebar.renameAction")
304
+ },
305
+ groupDeleteWords: {
306
+ title: t("sidebar.deleteGroupTitle"),
307
+ description: (group) => t("sidebar.deleteGroupBody", { name: group.name }),
308
+ confirmLabel: t("sidebar.deleteAction")
309
+ },
252
310
  deleteGroup,
253
311
  menu,
254
312
  groupMenu: (group) => [
255
313
  menuCommand("renameGroup", t("sidebar.renameGroup"), () => promptGroupName(group)),
256
314
  "divider",
257
315
  {
258
- ...menuCommand("deleteGroup", t("sidebar.deleteGroup"), () => confirmGroupDelete(group)),
316
+ ...menuCommand("deleteGroup", t("sidebar.deleteGroup"), () => confirmGroupDelete(group), void 0, DELETE_KEYS[0]),
259
317
  destructive: true
260
318
  }
261
319
  ],
320
+ groupShortcuts: (group) => [{
321
+ keys: DELETE_KEYS,
322
+ run: () => confirmGroupDelete(group, true)
323
+ }],
262
324
  listMenu: [menuCommand("newSession", t("sidebar.newSession"), newSession), ...sessions.length > 0 ? [menuCommand("newGroup", t("sidebar.newGroup"), () => {
263
325
  newGroup();
264
326
  })] : []],
@@ -268,4 +330,4 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
268
330
  }]
269
331
  };
270
332
  }
271
- export { groupSectionKey, isUngroupedTarget, searchedSessions, sessionMark, sessionRowState, sessionSearchText, sessionSections, showsPinMark, useRetainedSessions, useSessionList, withArchiveSection };
333
+ export { groupSectionKey, isUngroupedTarget, searchedSessions, sessionMark, sessionRailLabel, sessionRowState, sessionSearchScore, sessionSearchStatus, sessionSearchText, sessionSections, showsPinMark, useRetainedSessions, useSessionList, withArchiveSection };
@@ -0,0 +1,193 @@
1
+ import { type Dispatch, type SetStateAction } from 'react';
2
+ import type { Schemas } from './apiClient.js';
3
+ import { type PwCodeGoalMark } from './goal.js';
4
+ import { type PwCodeTranslator } from './messages.js';
5
+ import { type PwCodePicker } from './models.js';
6
+ import type { PwCodeSessionSettingsOptions } from './settingsApi.js';
7
+ import { type TranscriptState } from './transcript.js';
8
+ import type { PwCodeGoalStatus, PwCodeSessionState } from './types.js';
9
+ import type { PwCodeComposer } from './useComposer.js';
10
+ import type { PwCodeConversation } from './useConversation.js';
11
+ type Translate = PwCodeTranslator<'agents'>;
12
+ type Machine = Schemas['AgentMachine'];
13
+ type SessionDetail = Schemas['AgentSessionDetail'];
14
+ /** The bar above an open session's transcript while nothing new can reach it. */
15
+ export interface PwCodeSessionBanner {
16
+ /** `unreachable` asks for the machine again and reads the session again;
17
+ * `liveElsewhere` only reads the session again. */
18
+ kind: 'unreachable' | 'liveElsewhere';
19
+ /** A machine that does not answer is a fault; a session live elsewhere is news. */
20
+ tone: 'danger' | 'info';
21
+ title: string;
22
+ body: string;
23
+ action: string;
24
+ }
25
+ /** A machine that does not answer outranks a session running in pw code elsewhere. */
26
+ export declare function sessionBanner({ unreachable, liveElsewhere, machineName, staleFor, liveHost, }: {
27
+ unreachable: boolean;
28
+ liveElsewhere: boolean;
29
+ machineName: string;
30
+ /** How long ago the transcript was last read, already abbreviated. */
31
+ staleFor: string;
32
+ liveHost: string | undefined;
33
+ }, t: Translate): PwCodeSessionBanner | null;
34
+ export interface PwCodeGoalLabel extends PwCodeGoalMark {
35
+ active: boolean;
36
+ text: string;
37
+ }
38
+ /** The goal loop's state, which stands apart from the session's: a paused
39
+ * goal leaves the turn it paused in running. Null without a goal. */
40
+ export declare function goalLabel(goal: PwCodeGoalStatus | null | undefined, t: Translate): PwCodeGoalLabel | null;
41
+ export interface PwCodeAccountChip {
42
+ account: string;
43
+ label: string;
44
+ }
45
+ /** The Claude Code account a Claude model runs as, pw code's `default` until
46
+ * one is chosen; null for any other model. */
47
+ export declare function claudeAccountChip(model: string | null | undefined, account: string | null | undefined, t: Translate): PwCodeAccountChip | null;
48
+ /** The composer's draft key. By the session rather than its machine: the
49
+ * screen follows a session to another login node, and the draft goes with it. */
50
+ export declare function sessionDraftKey(sessionId: string, detail: Pick<SessionDetail, 'id'> | undefined): string;
51
+ /** The draft key of the composer that starts a session, one per reader. */
52
+ export declare function newSessionDraftKey(username: string): string;
53
+ /** How long ago the transcript was last read, abbreviated, for the composer
54
+ * and banner to say how stale it is once the machine stops answering. */
55
+ export declare function useStaleFor(detail: SessionDetail | undefined, feedOpen: boolean): string;
56
+ /** The model a session runs: the one it reports while live, else the one
57
+ * read of it. */
58
+ export declare function sessionModel(liveState: Partial<Pick<PwCodeSessionState, 'model'>> | null | undefined, detail: Pick<SessionDetail, 'model'> | undefined): string | undefined;
59
+ /** What an open session's settings pickers show and whether they can change. */
60
+ export declare function sessionSettingsOptions(machine: string, conversation: Pick<PwCodeConversation, 'liveState' | 'detail'>, composer: Pick<PwCodeComposer, 'unreachable' | 'archived' | 'status'>): Pick<PwCodeSessionSettingsOptions, 'machine' | 'sessionId' | 'model' | 'effort' | 'allocation' | 'claudeAccount' | 'locked' | 'live'>;
61
+ /** Which of the composer's pickers is open; `/model` and `/claude-code` open
62
+ * one in place of being sent, and stay out of the transcript. */
63
+ export declare function useSessionPicker(): {
64
+ picker: PwCodePicker;
65
+ setPicker: Dispatch<SetStateAction<PwCodePicker>>;
66
+ /** Closes `panel` unless another has opened since. */
67
+ close: (panel: Exclude<PwCodePicker, null>) => void;
68
+ /** For the composer's `handleLocally`. */
69
+ handleLocally: (typed: string) => boolean;
70
+ addsToTranscript: (typed: string) => boolean;
71
+ };
72
+ /** The line in place of the composer's activity while the session is busy or
73
+ * its feed is down. */
74
+ export type PwCodeSessionActivity = {
75
+ kind: 'reconnecting';
76
+ text: string;
77
+ } | {
78
+ kind: 'usageLimit';
79
+ resumeAt: string | null | undefined;
80
+ /** Another Claude Code account can take the turn over. */
81
+ offersAccounts: boolean;
82
+ } | {
83
+ kind: 'working';
84
+ startedAt: string | null;
85
+ inputTokens: number | undefined;
86
+ outputTokens: number | undefined;
87
+ /** What the turn is doing when it is more than working. */
88
+ word: string | undefined;
89
+ };
90
+ /** A turn at work: when it started and what it has used so far. */
91
+ export declare function workingActivity(transcript: Pick<TranscriptState, 'turnStartedAt'> | null, tokens: {
92
+ inputTokens?: number | undefined;
93
+ outputTokens?: number | undefined;
94
+ } | null | undefined, word?: string | undefined): Extract<PwCodeSessionActivity, {
95
+ kind: 'working';
96
+ }>;
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 place of working. */
99
+ export declare function sessionActivity({ composer, transcript, liveState, claudeModel, }: {
100
+ composer: Pick<PwCodeComposer, 'reconnecting' | 'working' | 'checkingGoal'>;
101
+ transcript: TranscriptState | null;
102
+ liveState: PwCodeSessionState | null;
103
+ /** The session runs a Claude Code model on a machine where Claude Code runs. */
104
+ claudeModel: boolean;
105
+ }, t: Translate, tTranscript: PwCodeTranslator<'agentTranscript'>): PwCodeSessionActivity | null;
106
+ /** What a machine allows of Claude Code, for its account panel and model picker. */
107
+ export declare function claudeOnMachine(machine: Machine | undefined): {
108
+ /** Claude Code is installed and its owner allows it. */
109
+ available: boolean;
110
+ installed: boolean;
111
+ allowed: boolean;
112
+ login: boolean;
113
+ accountRemove: boolean;
114
+ };
115
+ /** An open session's screen around its transcript and composer: the banner,
116
+ * the activity line, the goal, what the transcript shows when it never
117
+ * loaded, the command menu and the settings row. The host reads the session
118
+ * (`api.useSessionDetail`, `api.useMachine`) and runs the conversation,
119
+ * composer and settings it passes here. */
120
+ export declare function usePwCodeSessionScreen({ conversation, composer, read, machine, staleFor, settings, images, describeError, }: {
121
+ conversation: PwCodeConversation;
122
+ composer: PwCodeComposer;
123
+ /** The session, as `api.useSessionDetail` reads it. */
124
+ read: {
125
+ error?: unknown;
126
+ isLoading: boolean;
127
+ };
128
+ /** The session's machine, as `api.useMachine` reads it. */
129
+ machine: {
130
+ machine: Machine | undefined;
131
+ recheck: () => void;
132
+ };
133
+ /** What `useStaleFor` says, as the composer was given it. */
134
+ staleFor: string;
135
+ /** The session's own model, and whether a change to its settings is saving. */
136
+ settings: {
137
+ model: {
138
+ value?: string | null | undefined;
139
+ };
140
+ saving: boolean;
141
+ };
142
+ /** The images waiting to go with the next message. */
143
+ images: readonly unknown[];
144
+ /** Words a refusal or failure for the reader. */
145
+ describeError: (error: unknown) => string;
146
+ }): {
147
+ /** The session's state in a sentence, for a screen reader. */
148
+ statusText: string;
149
+ banner: {
150
+ /** `unreachable` asks for the machine again and reads the session again;
151
+ * `liveElsewhere` only reads the session again. */
152
+ kind: 'unreachable' | 'liveElsewhere';
153
+ /** A machine that does not answer is a fault; a session live elsewhere is news. */
154
+ tone: 'danger' | 'info';
155
+ title: string;
156
+ body: string;
157
+ action: string;
158
+ act: () => void;
159
+ } | null;
160
+ /** The transcript has yet to load for the first time. */
161
+ loading: boolean;
162
+ /** Shown in place of a transcript that never loaded: why, or undefined
163
+ * for the host's own line. */
164
+ failed: {
165
+ message: string | undefined;
166
+ } | null;
167
+ retry: () => undefined;
168
+ /** Why the workspace's own settings, skills and hooks did not load. */
169
+ untrusted: string | null;
170
+ activity: PwCodeSessionActivity | null;
171
+ goal: PwCodeGoalLabel | null;
172
+ commands: import("./command.js").PwCodeSlashCommand[];
173
+ showAuthor: boolean;
174
+ /** A message may go without text while images go with it. */
175
+ allowEmpty: boolean;
176
+ permission: {
177
+ mode: string | undefined;
178
+ ceiling: "" | "accept-edits" | "auto" | "bypass-permissions" | "plan" | "read-only" | undefined;
179
+ accepted: ("accept-edits" | "auto" | "bypass-permissions" | "plan" | "read-only")[] | undefined;
180
+ disabled: boolean;
181
+ };
182
+ claude: {
183
+ /** Claude Code is installed and its owner allows it. */
184
+ available: boolean;
185
+ installed: boolean;
186
+ allowed: boolean;
187
+ login: boolean;
188
+ accountRemove: boolean;
189
+ };
190
+ canStart: boolean;
191
+ };
192
+ export type PwCodeSessionScreen = ReturnType<typeof usePwCodeSessionScreen>;
193
+ export {};