@kabmo-labs/kabmo 0.26.0 → 0.27.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 (71) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +164 -164
  3. package/dist/client/static/js/index-32rpkj6b.css +1 -0
  4. package/dist/client/static/js/{index-95b3n20k.js → index-e3qh2yps.js} +668 -668
  5. package/package.json +1 -1
  6. package/src/client/components/common/Toast.test.tsx +28 -2
  7. package/src/client/components/common/Toast.tsx +21 -9
  8. package/src/client/components/layout/desktop-layout/LeftColumn.tsx +2 -1
  9. package/src/client/components/layout/session-sidebar/CategoryItem.tsx +2 -1
  10. package/src/client/components/layout/session-sidebar/SessionList.tsx +2 -1
  11. package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +3 -2
  12. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +2 -1
  13. package/src/client/components/layout/session-sidebar/modern/RevealRow.tsx +56 -0
  14. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +10 -28
  15. package/src/client/components/layout/session-sidebar/modern/reveal-row.test.tsx +104 -0
  16. package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -1
  17. package/src/client/components/layout/session-sidebar/variant-props.ts +2 -1
  18. package/src/client/components/mobile/SessionSidebar.tsx +2 -1
  19. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +2 -1
  20. package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +2 -1
  21. package/src/client/components/mobile/mobile-session-sidebar/List.tsx +2 -1
  22. package/src/client/components/settings/Modal.tsx +1 -1
  23. package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
  24. package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +39 -19
  25. package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +1 -0
  26. package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +94 -0
  27. package/src/client/components/settings/categories/usage-settings/limit-groups.ts +118 -0
  28. package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +118 -0
  29. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +58 -54
  30. package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +11 -1
  31. package/src/client/components/workspace/chat-timeline/PendingTranscript.tsx +130 -0
  32. package/src/client/components/workspace/chat-timeline/fork-preview.test.tsx +141 -0
  33. package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
  34. package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +2 -1
  35. package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +5 -4
  36. package/src/client/components/workspace/git-panel/index.tsx +2 -2
  37. package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +8 -5
  38. package/src/client/components/workspace/terminal-panel/index.tsx +3 -0
  39. package/src/client/hooks/chat/omp/session-list.tsx +5 -0
  40. package/src/client/hooks/chat/omp/sidebar-reload.test.ts +85 -0
  41. package/src/client/hooks/chat/omp/sidebar-reload.ts +30 -0
  42. package/src/client/hooks/chat/timeline/fork-preview.test.ts +148 -0
  43. package/src/client/hooks/chat/timeline/fork-preview.ts +104 -0
  44. package/src/client/hooks/chat/timeline/fork-send.test.ts +139 -0
  45. package/src/client/hooks/chat/timeline/pending-branch.ts +9 -0
  46. package/src/client/hooks/chat/timeline/pending-dispatch.ts +49 -0
  47. package/src/client/hooks/chat/timeline/stop-with-queue.ts +1 -1
  48. package/src/client/hooks/chat/waiting/cancel.ts +2 -1
  49. package/src/client/hooks/chat/waiting/dispatch.ts +5 -4
  50. package/src/client/hooks/chat/waiting/held.ts +2 -1
  51. package/src/client/hooks/settings/providers/actions.ts +3 -2
  52. package/src/client/hooks/settings/providers/messages.ts +9 -7
  53. package/src/client/hooks/settings/providers/model-actions.ts +2 -1
  54. package/src/client/hooks/ui/editor-error-toast.ts +2 -1
  55. package/src/client/hooks/workspace/batch-archive.test.ts +2 -2
  56. package/src/client/hooks/workspace/batch-archive.ts +4 -2
  57. package/src/client/hooks/workspace/git-action-outcome.ts +4 -3
  58. package/src/client/hooks/workspace/navbar-session-actions.ts +2 -1
  59. package/src/client/hooks/workspace/session-actions.test.ts +2 -1
  60. package/src/client/hooks/workspace/session-actions.ts +2 -1
  61. package/src/client/hooks/workspace/terminal/connection.test.ts +63 -0
  62. package/src/client/hooks/workspace/terminal/connection.ts +47 -0
  63. package/src/client/hooks/workspace/terminal/index.ts +35 -4
  64. package/src/client/hooks/workspace/workspace-folder-actions.ts +2 -1
  65. package/src/server/lib/usage/report.server.ts +57 -0
  66. package/src/shared/lib/chat/timeline/fork-preview.test.ts +62 -0
  67. package/src/shared/lib/chat/timeline/fork-preview.ts +36 -0
  68. package/src/shared/lib/ui/toast-duration.test.ts +25 -1
  69. package/src/shared/lib/ui/toast-duration.ts +22 -4
  70. package/src/shared/lib/workspace/session-state/store.ts +4 -0
  71. package/dist/client/static/js/index-p2yw9ywf.css +0 -1
@@ -24,11 +24,12 @@
24
24
 
25
25
  import { useKabmoEvent } from '@/client/hooks/ui/window-event';
26
26
  import { EDITOR_ERROR_EVENT } from '@/client/lib/editor-errors';
27
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
27
28
 
28
29
  /** What `pushToast` accepts, named so this hook does not import the toast host. */
29
30
  type PushToast = (
30
31
  message: string,
31
- type?: 'success' | 'error',
32
+ type?: ToastTone,
32
33
  options?: { duration?: number | null },
33
34
  ) => void;
34
35
 
@@ -34,14 +34,14 @@ describe('archiveOutcomeMessage', () => {
34
34
  .toEqual({ message: 'Archived 1 session.', tone: 'success' });
35
35
  });
36
36
 
37
- test('a partial refusal names both counts and is not dressed as success', () => {
37
+ test('a partial refusal names both counts and is dressed as a warning', () => {
38
38
  const report = archiveOutcomeMessage(outcome({
39
39
  archived: ['a', 'b'],
40
40
  refused: [{ id: 'new-1', error: 'This chat has not been created yet.' }],
41
41
  }));
42
42
  expect(report?.message).toContain('Archived 2 sessions');
43
43
  expect(report?.message).toContain('1 refused');
44
- expect(report?.tone).toBe('error');
44
+ expect(report?.tone).toBe('warning');
45
45
  });
46
46
 
47
47
  test('an all-refused run is an error and names the refusal count', () => {
@@ -14,6 +14,8 @@
14
14
  * against the list.
15
15
  */
16
16
 
17
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
18
+
17
19
  export interface BatchArchiveRefusal {
18
20
  id: string;
19
21
  error: string;
@@ -60,7 +62,7 @@ export function archiveSessionsBatch(ids: readonly string[]): Promise<BatchArchi
60
62
  */
61
63
  export function archiveOutcomeMessage(
62
64
  outcome: BatchArchiveOutcome,
63
- ): { message: string; tone: 'success' | 'error' } | null {
65
+ ): { message: string; tone: ToastTone } | null {
64
66
  if (outcome.error) return { message: outcome.error, tone: 'error' };
65
67
  const archived = outcome.archived.length;
66
68
  const refused = outcome.refused.length;
@@ -73,6 +75,6 @@ export function archiveOutcomeMessage(
73
75
  }
74
76
  return {
75
77
  message: `Archived ${archived} ${archived === 1 ? 'session' : 'sessions'}; ${refused} refused.`,
76
- tone: 'error',
78
+ tone: 'warning',
77
79
  };
78
80
  }
@@ -28,6 +28,7 @@ import { useEffect, useRef } from 'preact/hooks';
28
28
  import type { CommitHistoryPage } from '@/shared/types';
29
29
  import type { GitActionFetcher } from '@/client/hooks/workspace/git-actions';
30
30
  import { gitActionSuccessMessage } from '@/client/lib/git/action-message';
31
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
31
32
 
32
33
  export interface GitActionOutcomeOptions {
33
34
  /** The mutation channel, with the action its payload answers. */
@@ -36,8 +37,8 @@ export interface GitActionOutcomeOptions {
36
37
  onPage: (page: CommitHistoryPage) => void;
37
38
  /** An accepted mutation landed: re-read the working tree. */
38
39
  onReload: () => void;
39
- /** An accepted mutation, in the sentence the user reads. */
40
- onSuccess: (message: string) => void;
40
+ /** An accepted mutation, in the sentence the user reads and the tone it earns. */
41
+ onSuccess: (message: string, tone: ToastTone) => void;
41
42
  /** The server's refusal, or a transport failure. */
42
43
  onError: (message: string) => void;
43
44
  }
@@ -81,6 +82,6 @@ export function useGitActionOutcome(options: GitActionOutcomeOptions): void {
81
82
  const message = dispatched
82
83
  ? gitActionSuccessMessage({ ...dispatched, stopped: payload.stopped })
83
84
  : null;
84
- if (message) handlers.onSuccess(message);
85
+ if (message) handlers.onSuccess(message, payload.stopped ? 'warning' : 'success');
85
86
  }, [fetcher.state, fetcher.data, fetcher.lastAction]);
86
87
  }
@@ -23,6 +23,7 @@ import { useSidebarData } from '@/client/hooks/chat/omp/session-list';
23
23
  import { useSessionActions } from '@/client/hooks/workspace/session-actions';
24
24
  import { useSessionDelete, type SessionDeleteActions } from '@/client/hooks/workspace/session-delete';
25
25
  import type { WorkspaceFolderData } from '@/shared/types';
26
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
26
27
 
27
28
  /** What `TopNavbar` needs to draw its title menu. */
28
29
  export interface NavbarSessionMenu {
@@ -42,7 +43,7 @@ export interface NavbarSessionActions {
42
43
  export function useNavbarSessionActions(
43
44
  folders: WorkspaceFolderData[],
44
45
  sessionId: string | null,
45
- report: (message: string, tone?: 'success' | 'error') => void,
46
+ report: (message: string, tone?: ToastTone) => void,
46
47
  ): NavbarSessionActions {
47
48
  const sidebar = useSidebarData();
48
49
  const actions = useSessionActions(sidebar.refresh, report);
@@ -27,6 +27,7 @@ import { act } from 'preact/test-utils';
27
27
  import { useSessionActions, type SessionActions } from '@/client/hooks/workspace/session-actions';
28
28
  import { isSessionRenaming, setSessionRenaming } from '@/client/hooks/workspace/renaming-sessions';
29
29
  import type { SessionItemData } from '@/shared/types';
30
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
30
31
 
31
32
  const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
32
33
  /** The runner's own globals, restored on teardown — deleting them would strip natives (Event/CustomEvent) every later file needs. */
@@ -65,7 +66,7 @@ const session: SessionItemData = { id: 's1', folder_id: 1, title: 'old name' };
65
66
 
66
67
  interface Reported {
67
68
  message: string;
68
- tone: 'success' | 'error' | undefined;
69
+ tone: ToastTone | undefined;
69
70
  }
70
71
 
71
72
  interface Harness {
@@ -18,9 +18,10 @@ import { publishClientSignal } from '@/client/lib/signals';
18
18
  import { useFetcher } from '@/client/lib/router/fetcher';
19
19
  import { isSessionRenaming, setSessionRenaming } from '@/client/hooks/workspace/renaming-sessions';
20
20
  import type { SessionItemData } from '@/shared/types';
21
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
21
22
 
22
23
  /** Surfaces an outcome to the user; omitted callers stay silent. */
23
- export type ReportSessionOutcome = (message: string, tone?: 'success' | 'error') => void;
24
+ export type ReportSessionOutcome = (message: string, tone?: ToastTone) => void;
24
25
 
25
26
  export interface SessionActions {
26
27
  handleArchive: (session: SessionItemData) => void;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * When a terminal may hold a PTY.
8
+ *
9
+ * The bug these pin: the terminal panel is mounted while hidden, so an attach
10
+ * on mount spawned one idle shell per session the user visited. The other half
11
+ * is just as load-bearing — once opened, a session keeps its shell when the
12
+ * view is hidden or the page reloads.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+
17
+ import { terminalConnection } from '@/client/hooks/workspace/terminal/connection';
18
+
19
+ describe('terminalConnection', () => {
20
+ test('a mounted but never-opened session connects nothing', () => {
21
+ expect(terminalConnection({ visible: false, ready: true, opened: false })).toEqual({
22
+ connect: false,
23
+ persist: false,
24
+ });
25
+ });
26
+
27
+ test('a never-opened session whose blob has not loaded still connects nothing', () => {
28
+ expect(terminalConnection({ visible: false, ready: false, opened: false })).toEqual({
29
+ connect: false,
30
+ persist: false,
31
+ });
32
+ });
33
+
34
+ test('the first on-screen render connects and records the opening', () => {
35
+ expect(terminalConnection({ visible: true, ready: true, opened: false })).toEqual({
36
+ connect: true,
37
+ persist: true,
38
+ });
39
+ });
40
+
41
+ test('an on-screen terminal does not record the opening before the blob loads', () => {
42
+ // The write is deferred: the blob may already say opened, and overwriting a
43
+ // restored session's own value with a fresh "true" is not needed.
44
+ expect(terminalConnection({ visible: true, ready: false, opened: false })).toEqual({
45
+ connect: true,
46
+ persist: false,
47
+ });
48
+ });
49
+
50
+ test('an opened session keeps its socket while the view is hidden', () => {
51
+ expect(terminalConnection({ visible: false, ready: true, opened: true })).toEqual({
52
+ connect: true,
53
+ persist: false,
54
+ });
55
+ });
56
+
57
+ test('an opened session on screen writes nothing', () => {
58
+ expect(terminalConnection({ visible: true, ready: true, opened: true })).toEqual({
59
+ connect: true,
60
+ persist: false,
61
+ });
62
+ });
63
+ });
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Whether this session's terminal should hold a socket — and therefore a PTY.
8
+ *
9
+ * Mounting is NOT opening. The desktop stack keeps every built-in panel mounted
10
+ * and hides it with CSS (`WorkspacePanels.tsx`), which is what preserves a
11
+ * tree's expansion, a search's results and a terminal's buffer across a switch;
12
+ * the terminal is additionally `liveWhileHidden` so it keeps reading while the
13
+ * user looks at Files. Starting the shell on mount therefore started one for
14
+ * every session the user merely VISITED: measured on a live server, 18 idle
15
+ * `zsh -i -l` children of the Kabmo pid, with a burst of seven inside two
16
+ * minutes, none of them opened by the user.
17
+ *
18
+ * So the shell starts on the first render where the panel is genuinely on
19
+ * screen, and from then on the session OWNS it: `terminal.opened` is persisted
20
+ * per session, so switching to another view, collapsing the column or reloading
21
+ * the page reattaches instead of letting the idle reaper collect a shell the
22
+ * user opened. `ready` gates only the WRITE — a blob that has not loaded yet
23
+ * cannot say whether this session was already opened.
24
+ */
25
+
26
+ export interface TerminalConnectionState {
27
+ /** The panel is on screen AND has a workspace to open the shell in. */
28
+ visible: boolean;
29
+ /** The session's state blob (with `terminal.opened`) has loaded. */
30
+ ready: boolean;
31
+ /** The persisted `terminal.opened` of this session. */
32
+ opened: boolean;
33
+ }
34
+
35
+ export interface TerminalConnection {
36
+ /** Hold a socket for this session. */
37
+ connect: boolean;
38
+ /** This is the first opening; the caller persists it. */
39
+ persist: boolean;
40
+ }
41
+
42
+ export function terminalConnection(state: TerminalConnectionState): TerminalConnection {
43
+ return {
44
+ connect: state.visible || state.opened,
45
+ persist: state.ready && state.visible && !state.opened,
46
+ };
47
+ }
@@ -22,11 +22,22 @@ import { useSessionState } from '@/client/hooks/workspace/session-state';
22
22
  import { useSessionStateContext } from '@/client/hooks/workspace/session-state/context';
23
23
  import { getSessionValue } from '@/shared/lib/workspace/session-state/store';
24
24
  import { connectTerminal, type TerminalSocket } from '@/client/hooks/workspace/terminal/socket';
25
+ import { terminalConnection } from '@/client/hooks/workspace/terminal/connection';
25
26
  import { newTerminalId, type TerminalReadyFrame } from '@/shared/lib/workspace/terminal/protocol';
26
27
 
27
28
  export type TerminalStatus = 'connecting' | 'running' | 'exited' | 'error';
28
29
 
29
30
  export interface UseTerminalOptions {
31
+ /**
32
+ * True while the panel is actually on screen — selected AND its column open
33
+ * — and there is a workspace to launch the shell in.
34
+ *
35
+ * The desktop keeps every built-in view mounted while hidden, so a socket
36
+ * opened on mount started a PTY for every session the user merely visited.
37
+ * The shell starts on the first visible render instead, and stays for the
38
+ * rest of the session (see `connection.ts`).
39
+ */
40
+ visible?: boolean;
30
41
  root?: string;
31
42
  repo?: string;
32
43
  theme?: 'light' | 'dark';
@@ -59,6 +70,15 @@ export interface UseTerminalResult {
59
70
  export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult {
60
71
  const { sessionId, ready } = useSessionStateContext();
61
72
  const [terminalId, setTerminalId] = useSessionState<string>('terminal.id', '');
73
+ // Set the first time the panel is genuinely on screen for this session; read
74
+ // on every later mount so a reload or a view switch reattaches to the shell
75
+ // instead of waiting for the user to open the panel again.
76
+ const [storedOpened, setStoredOpened] = useSessionState<boolean>('terminal.opened', false);
77
+ const connection = terminalConnection({
78
+ visible: options.visible === true,
79
+ ready,
80
+ opened: storedOpened,
81
+ });
62
82
  const [status, setStatus] = useState<TerminalStatus>('connecting');
63
83
  const [shell, setShell] = useState('');
64
84
  const [exitCode, setExitCode] = useState<number | null>(null);
@@ -87,19 +107,30 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
87
107
  /** Last `root\0repo` the shell was launched for; null until the first. */
88
108
  const scopeRef = useRef<string | null>(null);
89
109
 
110
+ // The first render where the panel is on screen is the opening; from then on
111
+ // the session owns its shell, because the persisted flag — not the current
112
+ // visibility — is what the socket effect below reads.
113
+ useEffect(() => {
114
+ if (!connection.persist) return;
115
+ setStoredOpened(true);
116
+ }, [connection.persist]);
117
+
90
118
  // One id per Kabmo session. The check reads the store, not the hook's local
91
119
  // value: on the render where the blob first becomes ready, `useSessionState`
92
120
  // still reports the fallback (its restore effect has not run yet), so
93
121
  // deciding from the local value would mint a second id and overwrite the
94
122
  // stored one — orphaning the live shell and its scrollback.
123
+ //
124
+ // Minted only for a session that may connect: an id for a panel nobody opened
125
+ // is state no shell will ever use.
95
126
  useEffect(() => {
96
- if (!ready) return;
127
+ if (!connection.connect || !ready) return;
97
128
  if (getSessionValue<string>(sessionId, 'terminal.id')) return;
98
129
  setIdRef.current(newTerminalId());
99
- }, [ready, sessionId]);
130
+ }, [connection.connect, ready, sessionId]);
100
131
 
101
132
  useEffect(() => {
102
- if (!ready || !terminalId) return;
133
+ if (!connection.connect || !ready || !terminalId) return;
103
134
 
104
135
  setStatus('connecting');
105
136
  setError(null);
@@ -141,7 +172,7 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
141
172
  socket.release();
142
173
  socketRef.current = null;
143
174
  };
144
- }, [ready, terminalId, generation]);
175
+ }, [connection.connect, ready, terminalId, generation]);
145
176
 
146
177
  const restart = useCallback(() => {
147
178
  // Kill the old shell before minting a new id: leaving it to the idle
@@ -23,6 +23,7 @@ import { useState } from 'preact/hooks';
23
23
  import { useFetcher } from '@/client/lib/router/fetcher';
24
24
  import { useSessionActions } from '@/client/hooks/workspace/session-actions';
25
25
  import type { SessionItemData } from '@/shared/types';
26
+ import type { ToastTone } from '@/shared/lib/ui/toast-duration';
26
27
 
27
28
  /** Minimal folder shape the actions touch — avoids coupling to a full row. */
28
29
  export interface WorkspaceFolderLike {
@@ -64,7 +65,7 @@ export interface WorkspaceFolderActions {
64
65
  * same channel ("Renamed to …"), while a folder's own failures are the error
65
66
  * tone their callers already assume.
66
67
  */
67
- export type ReportFolderOutcome = (message: string, tone?: 'success' | 'error') => void;
68
+ export type ReportFolderOutcome = (message: string, tone?: ToastTone) => void;
68
69
 
69
70
  export function useWorkspaceFolderActions(
70
71
  folder: WorkspaceFolderLike,
@@ -122,6 +122,63 @@ export function mockUsageReport(): UsageReport {
122
122
  status: 'ok',
123
123
  resetsAt: Date.now() + 6 * 60 * 60 * 1000,
124
124
  },
125
+ {
126
+ id: 'anthropic:extra',
127
+ label: 'Claude Extra Usage',
128
+ windowLabel: 'extra',
129
+ used: 4.2,
130
+ limit: 25,
131
+ remaining: 20.8,
132
+ usedFraction: 0.168,
133
+ unit: 'usd',
134
+ status: 'ok',
135
+ },
136
+ ],
137
+ },
138
+ {
139
+ // Same shape omp's Antigravity adapter reports: one bucket per model
140
+ // family, and `anthropic:`/`openai:` are the SAME shared bucket.
141
+ id: 'google-antigravity',
142
+ name: 'Google Antigravity',
143
+ credentialSources: ['agent.db'],
144
+ tracked: true,
145
+ limits: [
146
+ {
147
+ id: 'google-antigravity:google:default:weekly',
148
+ label: 'Gemini',
149
+ windowLabel: 'weekly',
150
+ used: 42,
151
+ limit: 100,
152
+ remaining: 58,
153
+ usedFraction: 0.42,
154
+ unit: 'percent',
155
+ status: 'ok',
156
+ resetsAt: Date.now() + 4 * 24 * 60 * 60 * 1000,
157
+ },
158
+ {
159
+ id: 'google-antigravity:anthropic:default:5h',
160
+ label: 'Claude & GPT (shared)',
161
+ windowLabel: '5h',
162
+ used: 71,
163
+ limit: 100,
164
+ remaining: 29,
165
+ usedFraction: 0.71,
166
+ unit: 'percent',
167
+ status: 'ok',
168
+ resetsAt: Date.now() + 3 * 60 * 60 * 1000,
169
+ },
170
+ {
171
+ id: 'google-antigravity:openai:default:5h',
172
+ label: 'Claude & GPT (shared)',
173
+ windowLabel: '5h',
174
+ used: 71,
175
+ limit: 100,
176
+ remaining: 29,
177
+ usedFraction: 0.71,
178
+ unit: 'percent',
179
+ status: 'ok',
180
+ resetsAt: Date.now() + 3 * 60 * 60 * 1000,
181
+ },
125
182
  ],
126
183
  },
127
184
  {
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The slice a fork preview shows.
8
+ *
9
+ * It mirrors the server cut (`cutIndexFor` in `fork.server.ts`), because a
10
+ * preview that ends on a different row than the branch file does is a promise
11
+ * the first send breaks.
12
+ */
13
+
14
+ import { describe, expect, test } from 'bun:test';
15
+ import { forkPreviewMessages } from '@/shared/lib/chat/timeline/fork-preview';
16
+ import type { ChatMessageData } from '@/shared/types';
17
+
18
+ const row = (id: string, role: ChatMessageData['role']): ChatMessageData => ({ id, role, content: id });
19
+
20
+ // u1 a1 u2 a2 u3 a3 — a turn is a user row plus everything after it.
21
+ const transcript: ChatMessageData[] = [
22
+ row('u1', 'user'),
23
+ row('a1', 'ai'),
24
+ row('u2', 'user'),
25
+ row('a2', 'ai'),
26
+ row('u3', 'user'),
27
+ row('a3', 'ai'),
28
+ ];
29
+
30
+ describe('forkPreviewMessages', () => {
31
+ test('no anchor is the tip: the whole transcript', () => {
32
+ expect(forkPreviewMessages(transcript, null).map((m) => m.id)).toEqual([
33
+ 'u1', 'a1', 'u2', 'a2', 'u3', 'a3',
34
+ ]);
35
+ });
36
+
37
+ test('an anchor the transcript does not carry falls back to the tip', () => {
38
+ // A reload can outlive a message the source no longer has; the fork then
39
+ // branches at the tip, so the preview must not claim otherwise.
40
+ expect(forkPreviewMessages(transcript, 'gone').map((m) => m.id)).toEqual([
41
+ 'u1', 'a1', 'u2', 'a2', 'u3', 'a3',
42
+ ]);
43
+ });
44
+
45
+ test('a user anchor branches BEFORE that turn', () => {
46
+ expect(forkPreviewMessages(transcript, 'u2').map((m) => m.id)).toEqual(['u1', 'a1']);
47
+ });
48
+
49
+ test('an assistant anchor keeps the turn that contains it', () => {
50
+ expect(forkPreviewMessages(transcript, 'a2').map((m) => m.id)).toEqual([
51
+ 'u1', 'a1', 'u2', 'a2',
52
+ ]);
53
+ });
54
+
55
+ test('the first user turn forks to an empty transcript', () => {
56
+ expect(forkPreviewMessages(transcript, 'u1')).toEqual([]);
57
+ });
58
+
59
+ test('an anchor on the last turn keeps the whole transcript', () => {
60
+ expect(forkPreviewMessages(transcript, 'a3')).toHaveLength(6);
61
+ });
62
+ });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The source transcript a fork will carry, for the pending composer's preview.
8
+ *
9
+ * A fork is composed as an EMPTY chat today, so the operator picks the first
10
+ * turn without seeing the history that turn continues. This slices the source's
11
+ * rows the way the server slices its JSONL (`cutIndexFor` in
12
+ * `fork.server.ts`), so what the preview shows is exactly what the branch file
13
+ * will hold:
14
+ *
15
+ * - an anchor on a USER turn branches BEFORE it — that message is the one
16
+ * being replaced, so it is not part of the fork;
17
+ * - an anchor anywhere else (an assistant reply, a tool row) branches AFTER
18
+ * the turn that contains it — the reply the user pointed at is kept;
19
+ * - no anchor, or an id the transcript does not carry, is the tip: everything.
20
+ */
21
+
22
+ import type { ChatMessageData } from '@/shared/types';
23
+
24
+ export function forkPreviewMessages(
25
+ messages: ChatMessageData[],
26
+ anchorEntryId: string | null | undefined,
27
+ ): ChatMessageData[] {
28
+ if (!anchorEntryId) return messages;
29
+ const anchorIndex = messages.findIndex((message) => message.id === anchorEntryId);
30
+ if (anchorIndex === -1) return messages;
31
+ if (messages[anchorIndex]?.role === 'user') return messages.slice(0, anchorIndex);
32
+ const nextTurn = messages.findIndex(
33
+ (message, index) => index > anchorIndex && message.role === 'user',
34
+ );
35
+ return messages.slice(0, nextTurn === -1 ? messages.length : nextTurn);
36
+ }
@@ -14,7 +14,7 @@
14
14
  */
15
15
 
16
16
  import { describe, expect, test } from 'bun:test';
17
- import { TOAST_EXIT_MS, toastDurationMs } from '@/shared/lib/ui/toast-duration';
17
+ import { TOAST_EXIT_MS, toastDurationMs, updateOutcomeTone } from '@/shared/lib/ui/toast-duration';
18
18
 
19
19
  describe('toastDurationMs', () => {
20
20
  test('a short confirmation gets the success floor, not a flicker', () => {
@@ -67,8 +67,32 @@ describe('toastDurationMs', () => {
67
67
  );
68
68
  });
69
69
 
70
+ test('a warning outlasts a confirmation and gives way to a failure', () => {
71
+ const message = 'Merging feature stopped on a conflict; resolve it above.';
72
+ expect(toastDurationMs({ tone: 'warning', message })).toBeGreaterThan(
73
+ toastDurationMs({ tone: 'success', message })!,
74
+ );
75
+ expect(toastDurationMs({ tone: 'warning', message })).toBeLessThan(
76
+ toastDurationMs({ tone: 'error', message })!,
77
+ );
78
+ });
79
+
70
80
  test('the exit animation is a real duration, short enough to read as a fade', () => {
71
81
  expect(TOAST_EXIT_MS).toBeGreaterThan(0);
72
82
  expect(TOAST_EXIT_MS).toBeLessThan(400);
73
83
  });
74
84
  });
85
+
86
+ describe('updateOutcomeTone', () => {
87
+ test('a run that finished is a success', () => {
88
+ expect(updateOutcomeTone({ success: true, manual: false })).toBe('success');
89
+ });
90
+
91
+ test('a run the environment cannot perform is a warning: the user still has to act', () => {
92
+ expect(updateOutcomeTone({ success: true, manual: true })).toBe('warning');
93
+ });
94
+
95
+ test('a failed run is an error, even when it also names a manual command', () => {
96
+ expect(updateOutcomeTone({ success: false, manual: true })).toBe('error');
97
+ });
98
+ });
@@ -23,20 +23,25 @@
23
23
  * caller overriding it does so in one place.
24
24
  */
25
25
 
26
- export type ToastTone = 'success' | 'error';
26
+ export type ToastTone = 'success' | 'error' | 'warning';
27
27
 
28
28
  /** How long the fade-out runs. The timer and the class that animates agree here. */
29
29
  export const TOAST_EXIT_MS = 180;
30
30
 
31
- /** Notice-me base, per tone. */
32
- const BASE_MS: Record<ToastTone, number> = { success: 2500, error: 4000 };
31
+ /**
32
+ * Notice-me base, per tone. A warning sits between the two: it did not fail, but
33
+ * it names something the reader has to decide on (a stopped operation, a manual
34
+ * command), so it is noticed like a failure and skimmed like a confirmation.
35
+ */
36
+ const BASE_MS: Record<ToastTone, number> = { success: 2500, warning: 3200, error: 4000 };
33
37
 
34
38
  /** Reading rate per tone: an error is re-read, a confirmation is skimmed. */
35
- const PER_CHAR_MS: Record<ToastTone, number> = { success: 45, error: 55 };
39
+ const PER_CHAR_MS: Record<ToastTone, number> = { success: 45, warning: 50, error: 55 };
36
40
 
37
41
  /** Floor and ceiling per tone: nothing flickers, nothing sits for a minute. */
38
42
  const BOUNDS_MS: Record<ToastTone, { min: number; max: number }> = {
39
43
  success: { min: 3000, max: 8000 },
44
+ warning: { min: 4000, max: 10000 },
40
45
  error: { min: 5000, max: 12000 },
41
46
  };
42
47
 
@@ -68,3 +73,16 @@ export function toastDurationMs({ tone, message, explicit, sticky }: ToastDurati
68
73
  const byLength = BASE_MS[tone] + PER_CHAR_MS[tone] * message.trim().length;
69
74
  return Math.round(Math.min(max, Math.max(min, byLength)));
70
75
  }
76
+
77
+ /**
78
+ * The tone an update run's answer deserves.
79
+ *
80
+ * A failed run is an error. A run the environment could not perform for itself
81
+ * (`manual`) reports the command to run: the update is still waiting on the
82
+ * user, so it is neither a success nor a failure. Every shell that applies an
83
+ * update reads this, so the three of them cannot disagree about the same answer.
84
+ */
85
+ export function updateOutcomeTone(result: { success: boolean; manual: boolean }): ToastTone {
86
+ if (!result.success) return 'error';
87
+ return result.manual ? 'warning' : 'success';
88
+ }
@@ -45,6 +45,10 @@
45
45
  * - userBrowser.viewportMode string
46
46
  * - userBrowser.zoomLevel number
47
47
  * - terminal.id string (server-side PTY id; reattached on reload)
48
+ * - terminal.opened boolean — the session has had its terminal panel on
49
+ * screen, so its shell belongs to the session. A PTY
50
+ * is never started merely because the (hidden) panel
51
+ * mounted; see `hooks/workspace/terminal/connection.ts`
48
52
  * - git.viewMode 'flat' | 'tree'
49
53
  * - git.commitDraft string
50
54
  * - git.stagedExpanded boolean