@parallelworks/code 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +625 -113
  2. package/dist/accountApi.d.ts +31 -0
  3. package/dist/accountApi.js +182 -0
  4. package/dist/agentSwitcher.d.ts +120 -0
  5. package/dist/agentSwitcher.js +187 -0
  6. package/dist/ago.d.ts +1 -3
  7. package/dist/ago.js +8 -10
  8. package/dist/allocations.d.ts +41 -0
  9. package/dist/allocations.js +76 -0
  10. package/dist/api.d.ts +1319 -50
  11. package/dist/chatStrings.d.ts +189 -0
  12. package/dist/chatStrings.js +218 -0
  13. package/dist/claudeAccounts.d.ts +57 -2
  14. package/dist/claudeAccounts.js +144 -6
  15. package/dist/claudeApi.d.ts +2 -1
  16. package/dist/claudeApi.js +50 -4
  17. package/dist/claudeSignIn.d.ts +19 -1
  18. package/dist/claudeSignIn.js +12 -2
  19. package/dist/command.d.ts +5 -1
  20. package/dist/command.js +6 -1
  21. package/dist/commandsApi.d.ts +11 -1
  22. package/dist/commandsApi.js +24 -5
  23. package/dist/createPwCodeApi.d.ts +114 -6
  24. package/dist/createPwCodeApi.js +21 -3
  25. package/dist/directories.d.ts +161 -0
  26. package/dist/directories.js +301 -0
  27. package/dist/goal.d.ts +89 -0
  28. package/dist/goal.js +164 -0
  29. package/dist/imageFit.d.ts +23 -0
  30. package/dist/imageFit.js +27 -0
  31. package/dist/images.d.ts +28 -0
  32. package/dist/images.js +38 -6
  33. package/dist/index.d.ts +31 -15
  34. package/dist/index.js +29 -14
  35. package/dist/loadError.d.ts +8 -0
  36. package/dist/loadError.js +19 -0
  37. package/dist/locales/en/agentTranscript.js +74 -12
  38. package/dist/locales/en/agents.js +86 -11
  39. package/dist/locales/en.d.ts +137 -8
  40. package/dist/locales/es/agentTranscript.js +74 -12
  41. package/dist/locales/es/agents.js +86 -11
  42. package/dist/locales/ja/agentTranscript.js +77 -15
  43. package/dist/locales/ja/agents.js +60 -122
  44. package/dist/locales/ko/agentTranscript.js +74 -12
  45. package/dist/locales/ko/agents.js +86 -11
  46. package/dist/locales/zh/agentTranscript.js +72 -10
  47. package/dist/locales/zh/agents.js +86 -11
  48. package/dist/machine.d.ts +2 -0
  49. package/dist/modelPicker.d.ts +79 -0
  50. package/dist/modelPicker.js +107 -0
  51. package/dist/notices.d.ts +2 -0
  52. package/dist/notices.js +67 -32
  53. package/dist/platformDefaults.d.ts +22 -0
  54. package/dist/platformDefaults.js +30 -0
  55. package/dist/preferences.d.ts +78 -0
  56. package/dist/preferences.js +128 -0
  57. package/dist/pullRequestList.d.ts +10 -2
  58. package/dist/pullRequestList.js +41 -22
  59. package/dist/query.d.ts +9 -2
  60. package/dist/query.js +91 -10
  61. package/dist/session.d.ts +11 -2
  62. package/dist/session.js +16 -8
  63. package/dist/sessionActions.d.ts +11 -1
  64. package/dist/sessionActions.js +14 -6
  65. package/dist/sessionEvents.d.ts +37 -5
  66. package/dist/sessionEvents.js +196 -77
  67. package/dist/sessionGroups.d.ts +5 -4
  68. package/dist/sessionGroups.js +6 -5
  69. package/dist/sessionHeader.js +6 -2
  70. package/dist/sessionList.d.ts +68 -15
  71. package/dist/sessionList.js +91 -19
  72. package/dist/sessionScreen.d.ts +197 -0
  73. package/dist/sessionScreen.js +218 -0
  74. package/dist/sessionsApi.d.ts +29 -3
  75. package/dist/sessionsApi.js +180 -33
  76. package/dist/sessionsFeed.d.ts +22 -0
  77. package/dist/sessionsFeed.js +125 -0
  78. package/dist/settingsApi.d.ts +3 -1
  79. package/dist/startPage.d.ts +153 -0
  80. package/dist/startPage.js +174 -0
  81. package/dist/startSession.d.ts +41 -7
  82. package/dist/startSession.js +26 -4
  83. package/dist/todos.d.ts +42 -0
  84. package/dist/todos.js +104 -0
  85. package/dist/transcript.d.ts +1 -2
  86. package/dist/transcript.js +111 -117
  87. package/dist/transcriptRead.d.ts +56 -0
  88. package/dist/transcriptRead.js +121 -0
  89. package/dist/types.d.ts +11 -1
  90. package/dist/useComposer.d.ts +39 -6
  91. package/dist/useComposer.js +73 -9
  92. package/dist/useComposerImages.d.ts +5 -0
  93. package/dist/useComposerImages.js +27 -5
  94. package/dist/useComposerPastes.d.ts +70 -0
  95. package/dist/useComposerPastes.js +125 -0
  96. package/dist/useConversation.d.ts +16 -1
  97. package/dist/useConversation.js +104 -10
  98. package/dist/useMounted.d.ts +3 -0
  99. package/dist/useMounted.js +14 -0
  100. package/dist/useSubagent.d.ts +51 -3
  101. package/dist/useSubagent.js +72 -7
  102. package/dist/useTranscript.d.ts +23 -3
  103. package/dist/useTranscript.js +76 -19
  104. package/dist/wording.d.ts +5 -2
  105. package/dist/wording.js +8 -6
  106. package/dist/workingDirectories.d.ts +31 -0
  107. package/dist/workingDirectories.js +25 -1
  108. package/locales/en/agentTranscript.json +68 -11
  109. package/locales/en/agents.json +82 -10
  110. package/locales/es/agentTranscript.json +68 -11
  111. package/locales/es/agents.json +82 -10
  112. package/locales/ja/agentTranscript.json +71 -14
  113. package/locales/ja/agents.json +82 -10
  114. package/locales/ko/agentTranscript.json +68 -11
  115. package/locales/ko/agents.json +82 -10
  116. package/locales/zh/agentTranscript.json +66 -9
  117. package/locales/zh/agents.json +82 -10
  118. package/package.json +6 -3
@@ -14,15 +14,16 @@ 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' | 'waitingForUsageLimit' | '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. */
21
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;
22
+ /** A turn is running on a machine that still answers, and not held by a usage limit. */
23
+ export declare function isWorking(session: Pick<PwCodeSession, 'status' | 'waitingForUsageLimit'>, 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, waitsOnUsageLimit } from "./session.js";
3
3
  import { useCallback, useMemo } from "react";
4
4
  // src/sessionGroups.ts
5
5
  function patchGroup(groups, id, patch) {
@@ -12,16 +12,17 @@ function patchGroup(groups, id, patch) {
12
12
  function groupOf(groups, session) {
13
13
  return session.group ? groups.find((g) => g.id === session.group) : void 0;
14
14
  }
15
- /** A turn is running on a machine that still answers. */
15
+ /** A turn is running on a machine that still answers, and not held by a usage limit. */
16
16
  function isWorking(session, machine) {
17
- return session.status === "running" && !isMachineDown(machine);
17
+ return session.status === "running" && !waitsOnUsageLimit(session) && !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,
@@ -1,12 +1,16 @@
1
- import { useEffect } from "react";
1
+ import { useEffect, useRef } from "react";
2
2
  // src/sessionHeader.ts
3
3
  /** The worktree `useSessionWorktree` read, read again whenever the live
4
4
  * session reports it moved; undefined while the session works where it
5
5
  * launched. */
6
6
  function useFollowedWorktree(worktree, liveWorktree) {
7
7
  const { data, mutate } = worktree;
8
+ const followed = useRef(liveWorktree);
8
9
  useEffect(() => {
9
- mutate();
10
+ if (followed.current !== liveWorktree) {
11
+ followed.current = liveWorktree;
12
+ mutate();
13
+ }
10
14
  }, [liveWorktree, mutate]);
11
15
  return data?.root ? {
12
16
  root: data.root,
@@ -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' | 'waitingForUsageLimit' | '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,11 +55,33 @@ 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, resumeClock?: (at: string) => string): string;
56
78
  /** 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): {
79
+ * mark cannot express it: not "idle" or "running", but "waiting on you", a
80
+ * usage limit and when it resets, and a dead machine. */
81
+ export declare function sessionRowState(session: Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate, resumeClock?: (at: string) => string): {
60
82
  stateText: string;
83
+ /** The tone the state's words read in. */
84
+ tone: ReturnType<typeof sessionVariant<'muted'>>;
61
85
  showSecondLine: boolean;
62
86
  live: boolean;
63
87
  };
@@ -65,12 +89,15 @@ export declare function sessionRowState(session: Parameters<typeof sessionStateT
65
89
  * archived one, listed with the archive, needs the mark. */
66
90
  export declare function showsPinMark(session: Pick<PwCodeSession, 'pinnedAt' | 'archivedAt'>): boolean;
67
91
  /** 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): {
92
+ * between turns by its shape and so holds with reduced motion. One held by a
93
+ * usage limit is still, and keeps a dot's tone for a host that draws only
94
+ * dots. Any other shows a dot in its state's tone, pulsing while it waits on
95
+ * the reader. */
96
+ export declare function sessionMark(session: Pick<PwCodeSession, 'status' | 'waitingForUsageLimit'>, machine: Pick<PwCodeMachine, 'status'> | undefined): {
71
97
  working: true;
72
98
  } | {
73
99
  working: false;
100
+ usageLimit?: boolean;
74
101
  tone: ReturnType<typeof sessionVariant<'success'>>;
75
102
  pulse: boolean;
76
103
  };
@@ -82,23 +109,39 @@ export interface SessionListOptions<R> {
82
109
  machineById: ReadonlyMap<string, PwCodeMachine>;
83
110
  groups: SessionGroups;
84
111
  /** 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];
112
+ * anything an older copy stored, and how it keeps new ones. A change is an
113
+ * update from the kept keys, so a store that has not loaded them yet can
114
+ * apply it to them rather than to its fallback. */
115
+ folded: readonly [unknown, (update: (previous: unknown) => string[]) => void];
87
116
  open: OpenSessionRef;
88
117
  actions: Pick<SessionActions<R>, 'menu' | 'shortcuts' | 'togglePin' | 'moveToGroup' | 'groupBlocked' | 'archiveBlocked' | 'requestArchive'>;
89
118
  newSession: () => void;
90
119
  /** Asks the reader to name a group: one just made, or one to rename. */
91
120
  promptGroupName: (group: SessionGroup) => void;
92
- /** Asks the reader before a group goes; confirming calls `deleteGroup`. */
93
- confirmGroupDelete: (group: SessionGroup) => void;
121
+ /** Asks the reader before a group goes; confirming calls `deleteGroup`.
122
+ * `fromKey` when a key pressed on its heading asked, so the next press may answer it. */
123
+ confirmGroupDelete: (group: SessionGroup, fromKey?: boolean) => void;
94
124
  /** Says why a dropped session stays where it was. */
95
125
  onBlocked: (reason: string) => void;
96
126
  }
127
+ export interface SessionGroupKey {
128
+ keys: string | readonly string[];
129
+ run: () => void;
130
+ }
131
+ /** What asking before a group goes says. */
132
+ export interface GroupDeleteWords {
133
+ title: string;
134
+ description: (group: SessionGroup) => string;
135
+ confirmLabel: string;
136
+ }
97
137
  export interface SessionList<R> {
98
138
  data: Schemas['AgentSessionsResponse'] | undefined;
99
139
  error: PwCodeApiError | undefined;
100
140
  /** The first listing has not answered yet. */
101
141
  loading: boolean;
142
+ /** Why no listing came, the error to show in the list's place. A poll that
143
+ * fails after one did keeps the last listing and says nothing. */
144
+ loadError: PwCodeApiError | undefined;
102
145
  /** The listing, with what a machine that stopped answering listed last. */
103
146
  sessions: Session[];
104
147
  sections: SessionSection<Session>[];
@@ -114,16 +157,26 @@ export interface SessionList<R> {
114
157
  toggleFold: (key: string) => void;
115
158
  /** Folded over the open session, which would otherwise have no mark. */
116
159
  holdsOpen: (section: Pick<SessionSection<Session>, 'key' | 'sessions'>) => boolean;
117
- /** `key` is the dropped session's `sessionKey`. */
160
+ /** An archived session stays with the archive, so its row is not dragged. */
161
+ canDrag: (session: Session) => boolean;
162
+ /** `key` is the dropped session's `sessionKey`. One `canDrag` refuses stays where it was. */
118
163
  dropSession: (key: string, target: SessionDropTarget) => void;
119
164
  /** Made first and named second: what joins it is in it either way. */
120
165
  newGroup: () => SessionGroup;
121
- renameGroup: (group: SessionGroup, name: string) => void;
166
+ /** Saves the name without the spaces around it. A blank one is not saved,
167
+ * and false says so, for a prompt to stay open. */
168
+ renameGroup: (group: SessionGroup, name: string) => boolean;
169
+ /** What the prompt `promptGroupName` asks for says. */
170
+ groupNameWords: NamePromptWords;
171
+ /** What the question `confirmGroupDelete` asks says. */
172
+ groupDeleteWords: GroupDeleteWords;
122
173
  /** Its sessions stay in the list, in no group. */
123
174
  deleteGroup: (group: SessionGroup) => void;
124
175
  /** The session's actions, with a choice of the reader's groups. */
125
176
  menu: (session: Session, row?: R) => SessionMenuItem[];
126
177
  groupMenu: (group: SessionGroup) => SessionMenuItem[];
178
+ /** The keys a group's heading takes while it has focus, as its menu shows them. */
179
+ groupShortcuts: (group: SessionGroup) => SessionGroupKey[];
127
180
  /** For the list's empty space. */
128
181
  listMenu: SessionMenuItem[];
129
182
  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, waitsOnUsageLimit } 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,14 +110,49 @@ 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, resumeClock) {
140
+ return [
141
+ sessionLabel(session, t),
142
+ machine?.name,
143
+ sessionStateText(session, machine, t, resumeClock)
144
+ ].filter(Boolean).join(" · ");
145
+ }
112
146
  /** A second line costs a row its height, so the state takes one only when the
113
- * mark cannot express it: not "idle" or "running", but "waiting on you" and a
114
- * dead machine. */
115
- function sessionRowState(session, machine, t) {
147
+ * mark cannot express it: not "idle" or "running", but "waiting on you", a
148
+ * usage limit and when it resets, and a dead machine. */
149
+ function sessionRowState(session, machine, t, resumeClock) {
116
150
  const degraded = isMachineDown(machine);
151
+ const held = waitsOnUsageLimit(session);
117
152
  return {
118
- stateText: sessionStateText(session, machine, t),
119
- showSecondLine: degraded || session.status !== "idle" && session.status !== "running",
153
+ stateText: sessionStateText(session, machine, t, resumeClock),
154
+ tone: held && !degraded ? "warning" : sessionVariant(session.status, machine, "muted"),
155
+ showSecondLine: degraded || held || session.status !== "idle" && session.status !== "running",
120
156
  live: isActiveSession(session) && !degraded
121
157
  };
122
158
  }
@@ -126,10 +162,18 @@ function showsPinMark(session) {
126
162
  return !!session.pinnedAt && isArchived(session);
127
163
  }
128
164
  /** A session at work shows a turning mark, which tells it from one resting
129
- * between turns by its shape and so holds with reduced motion. Any other
130
- * shows a dot in its state's tone, pulsing while it waits on the reader. */
165
+ * between turns by its shape and so holds with reduced motion. One held by a
166
+ * usage limit is still, and keeps a dot's tone for a host that draws only
167
+ * dots. Any other shows a dot in its state's tone, pulsing while it waits on
168
+ * the reader. */
131
169
  function sessionMark(session, machine) {
132
170
  if (isWorking(session, machine)) return { working: true };
171
+ if (waitsOnUsageLimit(session) && !isMachineDown(machine)) return {
172
+ working: false,
173
+ usageLimit: true,
174
+ tone: "warning",
175
+ pulse: false
176
+ };
133
177
  return {
134
178
  working: false,
135
179
  tone: sessionVariant(session.status, machine, "success"),
@@ -157,13 +201,16 @@ function useRetainedSessions(machines, sessions) {
157
201
  return retained.length > 0 ? [...sessions, ...retained] : sessions;
158
202
  }, [machines, sessions]);
159
203
  }
204
+ function foldedKeys(stored) {
205
+ return Array.isArray(stored) ? stored : [];
206
+ }
160
207
  /** The sessions as a list shows them, in sections, with what the reader can
161
208
  * do to a row, a group or the list. */
162
209
  function useSessionList({ api, machineById, groups, folded: [storedFolded, setFolded], open, actions, newSession, promptGroupName, confirmGroupDelete, onBlocked }) {
163
210
  const t = usePwCodeTranslations("agents");
164
211
  const { data, error, isLoading } = api.useSessions();
165
212
  const sessions = useRetainedSessions(useMemo(() => data?.machines ?? [], [data]), useMemo(() => data?.sessions ?? [], [data]));
166
- const folded = Array.isArray(storedFolded) ? storedFolded : [];
213
+ const folded = foldedKeys(storedFolded);
167
214
  const sections = sessionSections(sessions, groups.groups, machineById, t);
168
215
  const listedSessions = sections.flatMap((s) => s.sessions);
169
216
  const openSession = listedSessions.find((s) => isSession(s, open.machine, open.sessionId));
@@ -176,7 +223,7 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
176
223
  const deleteGroup = (group) => {
177
224
  groups.remove(group.id);
178
225
  const key = groupSectionKey(group.id);
179
- if (folded.includes(key)) setFolded(folded.filter((k) => k !== key));
226
+ if (folded.includes(key)) setFolded((previous) => foldedKeys(previous).filter((k) => k !== key));
180
227
  for (const s of sessions) if (s.group === group.id && !actions.groupBlocked(s)) actions.moveToGroup(s, null);
181
228
  };
182
229
  const dropOnArchive = (session) => {
@@ -187,9 +234,10 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
187
234
  }
188
235
  actions.requestArchive(session);
189
236
  };
237
+ const canDrag = (session) => !isArchived(session);
190
238
  const dropSession = (key, target) => {
191
239
  const session = sessions.find((s) => sessionKey(s) === key);
192
- if (!session) return;
240
+ if (!session || !canDrag(session)) return;
193
241
  if ("archived" in target) {
194
242
  dropOnArchive(session);
195
243
  return;
@@ -237,6 +285,7 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
237
285
  data,
238
286
  error,
239
287
  loading,
288
+ loadError: data ? void 0 : error,
240
289
  sessions,
241
290
  sections,
242
291
  searchable: loading || sections.length > 0,
@@ -244,21 +293,44 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
244
293
  openSession,
245
294
  rail: listedSessions.filter((s) => isActiveSession(s) && isConnected(machineById.get(s.machineId)) || s === openSession),
246
295
  folded,
247
- toggleFold: (key) => setFolded(folded.includes(key) ? folded.filter((k) => k !== key) : [...folded, key]),
296
+ toggleFold: (key) => setFolded((previous) => {
297
+ const keys = foldedKeys(previous);
298
+ return keys.includes(key) ? keys.filter((k) => k !== key) : [...keys, key];
299
+ }),
248
300
  holdsOpen: (section) => folded.includes(section.key) && !!openSession && section.sessions.includes(openSession),
301
+ canDrag,
249
302
  dropSession,
250
303
  newGroup,
251
- renameGroup: (group, name) => groups.patch(group.id, { name }),
304
+ renameGroup: (group, name) => {
305
+ const saved = nameToSave(name);
306
+ if (saved) groups.patch(group.id, { name: saved });
307
+ return !!saved;
308
+ },
309
+ groupNameWords: {
310
+ title: t("sidebar.renameGroupTitle"),
311
+ label: t("sidebar.groupNameLabel"),
312
+ placeholder: t("sidebar.groupNamePlaceholder"),
313
+ confirmLabel: t("sidebar.renameAction")
314
+ },
315
+ groupDeleteWords: {
316
+ title: t("sidebar.deleteGroupTitle"),
317
+ description: (group) => t("sidebar.deleteGroupBody", { name: group.name }),
318
+ confirmLabel: t("sidebar.deleteAction")
319
+ },
252
320
  deleteGroup,
253
321
  menu,
254
322
  groupMenu: (group) => [
255
323
  menuCommand("renameGroup", t("sidebar.renameGroup"), () => promptGroupName(group)),
256
324
  "divider",
257
325
  {
258
- ...menuCommand("deleteGroup", t("sidebar.deleteGroup"), () => confirmGroupDelete(group)),
326
+ ...menuCommand("deleteGroup", t("sidebar.deleteGroup"), () => confirmGroupDelete(group), void 0, DELETE_KEYS[0]),
259
327
  destructive: true
260
328
  }
261
329
  ],
330
+ groupShortcuts: (group) => [{
331
+ keys: DELETE_KEYS,
332
+ run: () => confirmGroupDelete(group, true)
333
+ }],
262
334
  listMenu: [menuCommand("newSession", t("sidebar.newSession"), newSession), ...sessions.length > 0 ? [menuCommand("newGroup", t("sidebar.newGroup"), () => {
263
335
  newGroup();
264
336
  })] : []],
@@ -268,4 +340,4 @@ function useSessionList({ api, machineById, groups, folded: [storedFolded, setFo
268
340
  }]
269
341
  };
270
342
  }
271
- export { groupSectionKey, isUngroupedTarget, searchedSessions, sessionMark, sessionRowState, sessionSearchText, sessionSections, showsPinMark, useRetainedSessions, useSessionList, withArchiveSection };
343
+ export { groupSectionKey, isUngroupedTarget, searchedSessions, sessionMark, sessionRailLabel, sessionRowState, sessionSearchScore, sessionSearchStatus, sessionSearchText, sessionSections, showsPinMark, useRetainedSessions, useSessionList, withArchiveSection };
@@ -0,0 +1,197 @@
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
+ /** The turn waits at its account's usage limit, as the activity line
172
+ * says; not while the feed reconnects, which that line says instead. For
173
+ * `useClaudeAccountPanel`'s `waitingAtLimit`. */
174
+ waitingAtLimit: boolean;
175
+ goal: PwCodeGoalLabel | null;
176
+ commands: import("./command.js").PwCodePaletteOption[];
177
+ showAuthor: boolean;
178
+ /** A message may go without text while images go with it. */
179
+ allowEmpty: boolean;
180
+ permission: {
181
+ mode: string | undefined;
182
+ ceiling: "" | "accept-edits" | "auto" | "bypass-permissions" | "plan" | "read-only" | undefined;
183
+ accepted: ("accept-edits" | "auto" | "bypass-permissions" | "plan" | "read-only")[] | undefined;
184
+ disabled: boolean;
185
+ };
186
+ claude: {
187
+ /** Claude Code is installed and its owner allows it. */
188
+ available: boolean;
189
+ installed: boolean;
190
+ allowed: boolean;
191
+ login: boolean;
192
+ accountRemove: boolean;
193
+ };
194
+ canStart: boolean;
195
+ };
196
+ export type PwCodeSessionScreen = ReturnType<typeof usePwCodeSessionScreen>;
197
+ export {};