cli-jaw 2.17.63 → 2.17.64

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 (52) hide show
  1. package/dist/src/code-mode/store.js +35 -6
  2. package/dist/src/code-mode/store.js.map +1 -1
  3. package/dist/src/routes/code-native.js +11 -2
  4. package/dist/src/routes/code-native.js.map +1 -1
  5. package/package.json +1 -1
  6. package/public/dist/.vite/manifest.json +21 -9
  7. package/public/dist/assets/CodeCanvas-c_omHvtV.js +3 -0
  8. package/public/dist/assets/FolderPanel-DOLT_syh.js +3 -0
  9. package/public/dist/assets/{FolderPanel-BHEYcjea.css → FolderPanel-DgoqN1cX.css} +1 -1
  10. package/public/dist/assets/icons-QgChTDzZ.js +1 -0
  11. package/public/dist/assets/manager-Bq8-tr-M.js +5 -0
  12. package/public/dist/assets/manager-C6UJc985.css +1 -0
  13. package/public/dist/manager/index.html +2 -2
  14. package/public/manager/src/App.tsx +3 -3
  15. package/public/manager/src/AppChrome.tsx +1 -1
  16. package/public/manager/src/background-tasks/BackgroundTaskMonitorPanel.tsx +41 -7
  17. package/public/manager/src/background-tasks/background-task-monitor.css +1 -4
  18. package/public/manager/src/code/CodeSessionList.tsx +95 -35
  19. package/public/manager/src/code/code-controller-runtime.ts +66 -8
  20. package/public/manager/src/code/code-controller-types.ts +4 -0
  21. package/public/manager/src/code/code-session-client.ts +1 -1
  22. package/public/manager/src/code/code-session-sidebar.css +32 -0
  23. package/public/manager/src/code/code.css +2 -4
  24. package/public/manager/src/code/session-order.ts +9 -0
  25. package/public/manager/src/components/CommandBar.tsx +0 -10
  26. package/public/manager/src/components/InstanceGroups.tsx +2 -0
  27. package/public/manager/src/components/InstanceListContent.tsx +2 -0
  28. package/public/manager/src/components/InstanceRow.tsx +146 -89
  29. package/public/manager/src/components/SidebarRail.tsx +6 -5
  30. package/public/manager/src/components/ThemeSwitch.tsx +46 -22
  31. package/public/manager/src/components/context-menu/ContextMenu.tsx +207 -0
  32. package/public/manager/src/components/context-menu/context-menu.css +111 -0
  33. package/public/manager/src/components/context-menu/icons.tsx +48 -0
  34. package/public/manager/src/folder-panel/FolderContextMenu.tsx +43 -17
  35. package/public/manager/src/folder-panel/FolderPanel.tsx +9 -1
  36. package/public/manager/src/folder-panel/FolderPanelOverlays.tsx +2 -0
  37. package/public/manager/src/folder-panel/FolderTreeRows.tsx +6 -1
  38. package/public/manager/src/folder-panel/folder-panel.css +0 -33
  39. package/public/manager/src/folder-panel/use-folder-context-menu.ts +6 -19
  40. package/public/manager/src/hooks/useDashboardRegistry.ts +24 -1
  41. package/public/manager/src/jaw-ceo/JawCeoConsolePanels.tsx +71 -9
  42. package/public/manager/src/jaw-ceo/jaw-ceo-console.css +5 -7
  43. package/public/manager/src/main.tsx +2 -0
  44. package/public/manager/src/manager-components.css +1 -34
  45. package/public/manager/src/manager-desktop-titlebar.css +117 -0
  46. package/public/manager/src/manager-layout.css +0 -1
  47. package/public/manager/src/manager-p0-1-1.css +0 -42
  48. package/public/manager/src/manager-polish.css +0 -88
  49. package/public/dist/assets/CodeCanvas-CVbdp0S-.js +0 -3
  50. package/public/dist/assets/FolderPanel-CJvwRwIV.js +0 -3
  51. package/public/dist/assets/manager-CCXm5Yfe.js +0 -5
  52. package/public/dist/assets/manager-D9rhKFKc.css +0 -1
@@ -0,0 +1,117 @@
1
+ /* Desktop (Electron): only the sidebar toggle shares the titlebar row with the window controls
2
+ (macOS lights at x=16, 3 x 12px + 2 x 8px gaps; Windows/Linux controls sit on the right);
3
+ workspace buttons stay in a fixed left column, like Codex. */
4
+ @media (min-width: 1024px) {
5
+ :root[data-cli-jaw-desktop="true"] {
6
+ --desktop-traffic-light-reserve: 12px;
7
+ --desktop-titlebar-control: 26px;
8
+ --desktop-rail-width: 44px;
9
+ --desktop-rail-button: 32px;
10
+ }
11
+
12
+ :root[data-cli-jaw-desktop="true"][data-cli-jaw-platform="darwin"] {
13
+ --desktop-traffic-light-reserve: calc(76px / var(--desktop-zoom, 1));
14
+ }
15
+
16
+ :root[data-cli-jaw-desktop="true"][data-window-fullscreen="true"] {
17
+ --desktop-traffic-light-reserve: 8px;
18
+ }
19
+
20
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell .manager-sidebar {
21
+ padding-left: var(--desktop-rail-width);
22
+ }
23
+
24
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell.is-sidebar-collapsed .manager-sidebar {
25
+ padding-left: 0;
26
+ }
27
+
28
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell .sidebar-rail,
29
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell:not(.is-sidebar-collapsed) .sidebar-rail {
30
+ position: absolute;
31
+ top: 0;
32
+ bottom: 0;
33
+ left: 0;
34
+ box-sizing: border-box;
35
+ width: var(--desktop-rail-width);
36
+ height: auto;
37
+ min-height: 0;
38
+ flex-direction: column;
39
+ flex-wrap: nowrap;
40
+ align-items: center;
41
+ justify-content: flex-start;
42
+ gap: 4px;
43
+ overflow: visible;
44
+ border-bottom: 0;
45
+ border-right: 1px solid var(--border-subtle);
46
+ padding: 8px 0;
47
+ }
48
+
49
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell.is-sidebar-collapsed .sidebar-rail {
50
+ border-right: 0;
51
+ }
52
+
53
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell .sidebar-rail .rail-button,
54
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell:not(.is-sidebar-collapsed) .sidebar-rail .rail-button {
55
+ width: var(--desktop-rail-button);
56
+ min-width: var(--desktop-rail-button);
57
+ height: var(--desktop-rail-button);
58
+ min-height: var(--desktop-rail-button);
59
+ margin: 0;
60
+ padding: 0;
61
+ }
62
+
63
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell .sidebar-rail .rail-spacer,
64
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell:not(.is-sidebar-collapsed) .sidebar-rail .rail-spacer {
65
+ flex: 1 1 auto;
66
+ min-width: 0;
67
+ min-height: 4px;
68
+ }
69
+
70
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell .sidebar-rail .rail-status-dot,
71
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell:not(.is-sidebar-collapsed) .sidebar-rail .rail-status-dot {
72
+ margin: 4px 0 2px;
73
+ }
74
+
75
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell .rail-collapse-button,
76
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell:not(.is-sidebar-collapsed) .rail-collapse-button {
77
+ position: fixed;
78
+ top: calc((var(--workspace-topbar-height) - var(--desktop-titlebar-control)) / 2);
79
+ left: var(--desktop-traffic-light-reserve);
80
+ z-index: 30;
81
+ width: var(--desktop-titlebar-control);
82
+ min-width: var(--desktop-titlebar-control);
83
+ height: var(--desktop-titlebar-control);
84
+ min-height: var(--desktop-titlebar-control);
85
+ margin: 0;
86
+ -webkit-app-region: no-drag;
87
+ }
88
+
89
+ :root[data-cli-jaw-desktop="true"] .dashboard-shell.manager-shell .command-center.command-bar {
90
+ --electron-titlebar-left-reserve: calc(var(--desktop-traffic-light-reserve) + var(--desktop-titlebar-control) + 12px);
91
+ }
92
+
93
+ :root[data-cli-jaw-desktop="true"] .command-center.command-bar :is(.command-primary, .command-actions, .command-panel-controls) {
94
+ align-items: center;
95
+ }
96
+
97
+ :root[data-cli-jaw-desktop="true"] .command-center.command-bar .manager-brand-heading {
98
+ align-items: center;
99
+ height: var(--desktop-titlebar-control);
100
+ }
101
+
102
+ :root[data-cli-jaw-desktop="true"] .command-center.command-bar :is(.manager-brand-wordmark, .manager-brand-dash) {
103
+ line-height: 1;
104
+ }
105
+
106
+ :root[data-cli-jaw-desktop="true"] .command-center.command-bar :is(.search-input-wrapper, .search-input-wrapper input, .command-panel-toggle, .command-icon-button, .desktop-open-button) {
107
+ box-sizing: border-box;
108
+ height: var(--desktop-titlebar-control);
109
+ min-height: var(--desktop-titlebar-control);
110
+ }
111
+
112
+ :root[data-cli-jaw-desktop="true"] .command-center.command-bar :is(.command-panel-toggle, .command-icon-button) {
113
+ width: var(--desktop-titlebar-control);
114
+ min-width: var(--desktop-titlebar-control);
115
+ }
116
+
117
+ }
@@ -286,7 +286,6 @@
286
286
  }
287
287
  .workbench-header .workbench-mode-tabs button { flex: 1 0 auto; }
288
288
  .overview-grid { grid-template-columns: 1fr; }
289
- .instance-actions { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
290
289
  .workbench-preview .preview-panel {
291
290
  gap: 8px;
292
291
  padding: 8px 10px;
@@ -164,12 +164,6 @@
164
164
  padding: 0 8px 0 32px;
165
165
  font-size: 12px;
166
166
  }
167
- .command-palette-trigger {
168
- height: 28px;
169
- min-height: 28px;
170
- border-radius: var(--control-radius);
171
- }
172
-
173
167
  .workbench-preview .workbench-header {
174
168
  padding: 4px 8px;
175
169
  }
@@ -341,17 +335,6 @@
341
335
  white-space: nowrap;
342
336
  }
343
337
 
344
- .manager-sidebar .instance-label-edit-button {
345
- top: 6px;
346
- right: 6px;
347
- opacity: 0;
348
- }
349
-
350
- .manager-sidebar .instance-row:hover .instance-label-edit-button,
351
- .manager-sidebar .instance-row:focus-within .instance-label-edit-button {
352
- opacity: 1;
353
- }
354
-
355
338
  .manager-sidebar .instance-label-edit-form {
356
339
  grid-template-columns: minmax(0, 1fr) auto auto;
357
340
  gap: 4px;
@@ -402,31 +385,6 @@
402
385
  display: none;
403
386
  }
404
387
 
405
- .manager-sidebar .instance-actions {
406
- display: none;
407
- }
408
-
409
- .manager-sidebar .instance-row.priority-active .instance-actions,
410
- .manager-sidebar .instance-row:not(.priority-active):hover .instance-actions,
411
- .manager-sidebar .instance-row:not(.priority-active):focus-within .instance-actions {
412
- display: grid;
413
- grid-auto-flow: column;
414
- grid-auto-columns: minmax(0, 1fr);
415
- gap: 4px;
416
- }
417
-
418
- .manager-sidebar .instance-row:not(.priority-active):hover .instance-row-meta,
419
- .manager-sidebar .instance-row:not(.priority-active):focus-within .instance-row-meta {
420
- display: none;
421
- }
422
-
423
- .manager-sidebar .instance-actions button,
424
- .manager-sidebar .instance-actions .open-link {
425
- min-height: 24px;
426
- padding-inline: 5px;
427
- font-size: 10.5px;
428
- }
429
-
430
388
  .manager-sidebar .profile-instance-groups.is-profile-merged .profile-empty {
431
389
  display: grid;
432
390
  gap: 2px;
@@ -182,17 +182,6 @@
182
182
  line-height: 1.4;
183
183
  }
184
184
 
185
- .manager-sidebar .instance-label-edit-button {
186
- top: 6px;
187
- right: 6px;
188
- opacity: 0;
189
- }
190
-
191
- .manager-sidebar .instance-row:hover .instance-label-edit-button,
192
- .manager-sidebar .instance-row:focus-within .instance-label-edit-button {
193
- opacity: 1;
194
- }
195
-
196
185
  .manager-sidebar .instance-label-edit-form {
197
186
  grid-template-columns: minmax(0, 1fr) auto auto;
198
187
  gap: 4px;
@@ -211,32 +200,6 @@
211
200
  display: none;
212
201
  }
213
202
 
214
- .manager-sidebar .instance-actions {
215
- display: none;
216
- }
217
-
218
- .manager-sidebar .instance-row.priority-active .instance-actions,
219
- .manager-sidebar .instance-row:not(.priority-active):hover .instance-actions,
220
- .manager-sidebar .instance-row:not(.priority-active):focus-within .instance-actions {
221
- display: grid;
222
- grid-auto-flow: column;
223
- grid-auto-columns: minmax(0, 1fr);
224
- gap: 4px;
225
- }
226
-
227
- .manager-sidebar .instance-row:not(.priority-active):hover .instance-row-meta,
228
- .manager-sidebar .instance-row:not(.priority-active):focus-within .instance-row-meta {
229
- display: none;
230
- }
231
-
232
- .manager-sidebar .instance-actions button,
233
- .manager-sidebar .instance-actions .open-link {
234
- min-height: 24px;
235
- border-radius: var(--control-radius);
236
- padding-inline: 5px;
237
- font-size: 10.5px;
238
- }
239
-
240
203
  .launch-home-control input.home-input {
241
204
  width: 180px;
242
205
  }
@@ -444,57 +407,6 @@
444
407
  color: var(--accent);
445
408
  }
446
409
 
447
- .theme-switch {
448
- display: inline-flex;
449
- background: var(--segment-track);
450
- border: 1px solid var(--segment-border);
451
- border-radius: 7px;
452
- padding: 2px;
453
- gap: 2px;
454
- }
455
-
456
- .theme-switch button {
457
- min-height: 26px;
458
- padding: 0 9px;
459
- border: 0;
460
- background: transparent;
461
- color: var(--text-secondary);
462
- font-size: 11px;
463
- font-weight: 500;
464
- border-radius: 5px;
465
- transition: background 160ms ease, color 160ms ease;
466
- }
467
-
468
- .theme-switch button:hover:not(:disabled) {
469
- background: var(--segment-hover);
470
- color: var(--text-primary);
471
- border-color: transparent;
472
- }
473
-
474
- .theme-switch button.is-active {
475
- background: var(--accent-soft);
476
- color: var(--accent);
477
- }
478
-
479
- /* 10.6.10 — Command palette trigger button (⌘K hint) */
480
- .command-palette-trigger {
481
- min-height: 26px;
482
- min-width: 32px;
483
- padding: 0 8px;
484
- border: 1px solid var(--border-subtle);
485
- background: var(--surface-raised);
486
- color: var(--ink-secondary);
487
- border-radius: 6px;
488
- font-family: "Geist Mono", "JetBrains Mono", monospace;
489
- font-size: 11px;
490
- font-weight: 500;
491
- }
492
- .command-palette-trigger:hover:not(:disabled) {
493
- background: var(--segment-hover);
494
- border-color: var(--border-strong);
495
- color: var(--ink-primary);
496
- }
497
-
498
410
  /* 10.6.10 — Command palette modal */
499
411
  .command-palette-backdrop {
500
412
  position: fixed;
@@ -1,3 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-render-DSSkXCir.css"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./preload-helper-CfbQpVni.js";import{a as n,i as r,n as i,r as a,t as o}from"./esm-Q6VOkDbn.js";import{a as s,c,i as l,n as u,o as d,r as f,s as p,t as m}from"./tool-input-DI7uu8Ah.js";import{n as h,t as g}from"./jsx-runtime-CkEUZM6i.js";import{t as _}from"./react-dom-URBLzV3w.js";import{i as v,t as y}from"./manager-shortcuts-Cqmr0mEq.js";import{t as b}from"./copy-text-WsUHYigB.js";var x=e(h(),1),S=_(),C={session_busy:`This session is busy. Wait for it to finish or stop the current turn.`,request_not_current:`This approval is no longer current. Refreshing its status.`,invalid_option:`This approval option is no longer available. Refreshing its status.`,revision_conflict:`Session settings changed elsewhere. Review the updated values and try again.`,invalid_sequence:`Conversation history needs to be refreshed.`,snapshot_limit:`This conversation exceeds the snapshot limit. Stop and recovery controls remain available.`,transcript_limit:`The conversation has reached its storage limit.`,event_too_large:`A conversation update exceeds the supported size.`,provider_unavailable:`This runtime is unavailable. Check its installation and authentication.`,unsupported_model:`This model is not available for the selected runtime.`,unsupported_effort:`This effort is not supported by the selected runtime.`,unsupported_policy:`This permission mode is not supported by the selected runtime.`,unsupported_capability:`This runtime does not support this action.`,session_not_steerable:`This turn cannot take a follow-up right now. Your text is kept.`,steer_queue_full:`This turn already has its follow-up. Send this after the turn finishes.`,steer_in_flight:`This follow-up is still being delivered.`,steer_key_spent:`This follow-up was not delivered. Your text is kept; send it again when ready.`,steer_outcome_unknown:`Follow-up delivery not confirmed. It was not resent.`,steer_command_unsupported:`A slash command cannot be sent as a follow-up. Send it after this turn finishes.`,session_not_found:`This session is no longer available. Its local draft is retained.`,rollback_unavailable:`Rollback is unavailable after this conversation was compacted, or while its history cannot be read.`,rollback_boundary_unavailable:`This turn can't be a rollback point: it or a later turn never reached Claude, or the conversation was compacted.`,rollback_noop:`This is already the latest turn, so there is nothing to roll back.`,rollback_target_not_found:`This message is no longer in the conversation. Refreshing the session.`,cleanup_pending:`The previous runtime is still closing. Try again in a moment.`,unauthorized:`Authentication is required to access this instance.`},w=class extends Error{code;status;session;constructor(e,t,n){super(C[e]??`The request could not be completed. Refresh the session and try again.`),this.code=e,this.status=t,this.session=n,this.name=`CodeClientError`}};function T(e){return typeof window<`u`&&window.location.port===String(e)?window.location.origin:`http://127.0.0.1:${e}`}function E(e){let t=T(e);async function n(e,n,r,i){let a=await fetch(`${t}/api/code${n}`,{method:e,...i===void 0?{}:{signal:i},...r===void 0?{}:{headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}}),o=await a.json();if(!a.ok||o.ok!==!0)throw new w(typeof o.error==`string`?o.error:`code_request_failed`,a.status,o.session);return o}let r=e=>`/sessions/${encodeURIComponent(e)}`,i=async(e,t,r)=>(await n(e,t,r)).session;return{listSessions(e={},t){let r=new URLSearchParams;for(let[t,n]of Object.entries(e))n!==void 0&&r.set(t,String(n));return n(`GET`,`/sessions?${r}`,void 0,t)},listModelOptions:e=>n(`GET`,`/models`,void 0,e),snapshot:(e,t)=>n(`GET`,r(e),void 0,t),events:(e,t,i)=>n(`GET`,`${r(e)}/events?afterSequence=${t}&limit=500`,void 0,i),history:(e,t,i)=>n(`GET`,`${r(e)}/items?beforeSequence=${t}&limit=200`,void 0,i),createSession:e=>i(`POST`,`/sessions`,e),patchSession:(e,t)=>i(`PATCH`,r(e),t),sendPrompt:(e,t)=>n(`POST`,`${r(e)}/prompt`,t),steerSession:(e,t)=>n(`POST`,`${r(e)}/steer`,t),cancelPrompt:(e,t)=>i(`POST`,`${r(e)}/cancel`,t),attachSession:e=>i(`POST`,`${r(e)}/attach`,{}),rollbackSession:(e,t)=>i(`POST`,`${r(e)}/rollback`,t),visitSession:e=>i(`POST`,`${r(e)}/visit`,{}),async answerPermission(e,t){await n(`POST`,`/permissions/${encodeURIComponent(e)}`,t)},getGitInfo:(e,t)=>n(`GET`,`/git-info?cwd=${encodeURIComponent(e)}`,void 0,t),pickWorkspace:()=>n(`POST`,`/workspace/pick`)}}var D=512,O=2097152,k=2e3,A=16777216;function j(e){return{sessionId:e,session:null,items:[],permissions:[],cursor:0,hydrated:!1,hydrating:!1,synced:!1,needsSnapshot:!1,buffered:[],hasOlder:!1,beforeSequence:null,error:null}}function M(e){return!!e&&[`starting`,`streaming`,`stopping`].includes(e.status)}var N=e=>e.sort((e,t)=>(e.firstSequence??0)-(t.firstSequence??0)),P=e=>e.reduce((e,t)=>e+JSON.stringify(t).length,0);function ee(e){let t=e.items,n=P(t);if(t.length<=k&&n<=A)return e;for(t=[...t];t.length>k||n>A;){let r=t.findIndex(t=>!e.session?.turnId||t.turnId!==e.session.turnId);if(r<0)return{...e,items:[],synced:!1,needsSnapshot:!0,error:`Conversation exceeds the display capacity.`};n-=JSON.stringify(t[r]).length,t.splice(r,1)}return{...e,items:t,hasOlder:!0,beforeSequence:t[0]?.firstSequence??null}}function te(e,t){let{items:n,session:r,permissions:i}=e;if(t.event===`code_session`){if(!t.session||t.session.sessionId!==e.sessionId||(t.session.historyGeneration??0)>(e.session?.historyGeneration??0))return{...e,needsSnapshot:!0,synced:!1};r=t.session.contextUsage===void 0&&r?.contextUsage!==void 0?{...t.session,contextUsage:r.contextUsage}:t.session,i=i.filter(e=>e.epoch===r.epoch&&e.turnId===r.turnId)}else{let a=t.item?.itemId??t.update?.itemId,o=n.find(e=>e.itemId===a),s;if(t.event===`code_item`&&t.item)s={...t.item,firstSequence:o?.firstSequence??t.item.firstSequence??t.sequence};else if(t.event===`code_item_update`&&t.update&&o&&o.turnId===t.update.turnId){let n=t.update;if(n.appendToolOutput!==void 0&&!o.tool)return{...e,needsSnapshot:!0,synced:!1};s={...o,updatedAt:n.updatedAt,...n.appendText===void 0?{}:{text:(o.text??``)+n.appendText},...n.appendToolOutput===void 0?{}:{tool:{...o.tool,output:(o.tool.output??``)+n.appendToolOutput}},...n.status===void 0?{}:{status:n.status},...n.phase===void 0?{}:{phase:n.phase}}}else return{...e,needsSnapshot:!0,synced:!1};n=N([...n.filter(e=>e.itemId!==s.itemId),s]),s.permission&&(i=i.filter(e=>e.permissionId!==s.permission.permissionId),s.status===`pending`&&s.permission.epoch===r?.epoch&&s.permission.turnId===r?.turnId&&(i=[...i,s.permission]))}return ee({...e,items:n,session:r,permissions:i,cursor:t.sequence})}function ne(e){let t=e;if(!t.hydrated||t.hydrating||t.needsSnapshot)return t;let n=t.buffered.filter(e=>e.sequence>t.cursor);for(;n[0]?.sequence===t.cursor+1;){let e=n[0];if(t=te(t,e),t.needsSnapshot)break;n.shift()}return{...t,buffered:n,synced:t.synced&&!n.length&&!t.needsSnapshot}}function re(e,t){if(t.sessionId!==e.sessionId||t.sequence<=e.cursor||e.buffered.some(e=>e.sequence===t.sequence))return e;let n=[...e.buffered,t].sort((e,t)=>e.sequence-t.sequence);return n.length>D||JSON.stringify(n).length>O?{...e,buffered:[],synced:!1,needsSnapshot:!0,error:`Live updates exceeded the buffer. Refreshing history.`}:ne({...e,buffered:n})}function F(e,t){switch(t.type){case`stale`:return{...e,synced:!1};case`error`:return{...e,hydrating:!1,synced:!1,error:t.error};case`snapshot-start`:return{...e,hydrating:!0,synced:!1,error:null};case`event`:return re(e,t.event);case`snapshot`:{let n=t.snapshot;if(n.session.sessionId!==e.sessionId||n.sequence<e.cursor)return{...e,hydrating:!1,synced:!1,needsSnapshot:!0};let r=N([...n.items]);return ne(ee({...e,session:n.session,items:r,permissions:n.pendingPermissions,cursor:n.sequence,hydrated:!0,hydrating:!1,synced:!0,needsSnapshot:!1,hasOlder:n.truncated,beforeSequence:r[0]?.firstSequence??null,error:null}))}case`page`:{let n=e;for(let e of t.page.events)n=re(n,e);let r=n.cursor>=t.page.throughSequence&&!n.buffered.length&&!n.needsSnapshot;return{...n,synced:r,error:r?null:n.error}}case`history`:{let n=new Set(e.items.map(e=>e.itemId)),r=N([...e.items,...t.page.items.filter(e=>!n.has(e.itemId))]);return r.length>k||P(r)>A?{...e,error:`Older history exceeds the display capacity. Reload to return to recent items.`}:{...e,items:r,hasOlder:t.page.hasMore,beforeSequence:t.page.beforeSequence}}}}var ie=`cli-jaw:code-drafts:v1`,ae=`cli-jaw:code-draft-warnings:v1`,I=1,oe=4,se=32,ce=262144,le=1048576,ue=2097152,de=`Draft recovery is unavailable in this tab. Your current text remains in memory.`,fe=`Draft recovery is incomplete: some recent text or request state was not saved for reload. Check your draft before sending.`,L=`Draft recovery is incomplete: some text was not saved for reload because this tab reached its recovery limit.`,R=e=>!!e&&typeof e==`object`&&!Array.isArray(e),z=(e,t)=>typeof e==`string`&&e.length<=t,B=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=0;function pe(e){if(!R(e)||!z(e.input,ce)||!B(e.edit)||!B(e.selectionEdit)||typeof e.creating!=`boolean`)return null;let t=e.selection;if(!R(t)||![`codex-app`,`claude`,`cursor`,`grok`].includes(String(t.provider))||!z(t.cwd,4096)||!z(t.model,1024)||!(t.effort===null||z(t.effort,80))||![`ask`,`auto`,`read-only`,`plan`,`accept-edits`,`dont-ask`,`auto-review`].includes(String(t.permissionMode))||t.thinking!==void 0&&typeof t.thinking!=`boolean`)return null;let n=e.retry,r=e.stop;return n!==null&&(!R(n)||!z(n.text,ce)||!z(n.key,240)||!n.key||!B(n.edit)||n.edit>e.edit)||r!==null&&(!R(r)||!z(r.turnId,240)||!r.turnId||!B(r.epoch))?null:{input:e.input,edit:e.edit,selectionEdit:e.selectionEdit,creating:e.creating,selection:{provider:t.provider,cwd:t.cwd,model:t.model,effort:t.effort,permissionMode:t.permissionMode,...typeof t.thinking==`boolean`?{thinking:t.thinking}:{}},retry:n===null?null:{text:n.text,key:n.key,edit:n.edit,...n.resend===!0?{resend:!0}:{},...n.resend===!0&&n.resendReason===`rolled-back`?{resendReason:`rolled-back`}:{}},stop:r===null?null:{turnId:r.turnId,epoch:r.epoch}}}function me(e){if(e===null)return{version:I,endpoints:[]};if(e.length>ue)return null;let t;try{t=JSON.parse(e)}catch{return null}if(!R(t)||t.version!==I||!Array.isArray(t.endpoints)||t.endpoints.length>oe)return null;let n=[];for(let e of t.endpoints){if(!R(e)||!z(e.endpoint,2048)||!(e.selectedId===null||z(e.selectedId,240))||!Array.isArray(e.sessions)||e.sessions.length>se)return null;let t=pe(e.fresh);if(!t||t.retry||t.stop)return null;let r=[];for(let t of e.sessions){if(!R(t)||!z(t.id,240)||!t.id)return null;let e=pe(t.draft);if(!e||e.creating||r.some(e=>e.id===t.id))return null;r.push({id:t.id,draft:e})}if(e.selectedId!==null&&!r.some(t=>t.id===e.selectedId)||n.some(t=>t.endpoint===e.endpoint)||JSON.stringify(e).length>le)return null;n.push({endpoint:e.endpoint,selectedId:e.selectedId,fresh:t,sessions:r})}return{version:I,endpoints:n}}function he(e){let t=e.getItem(ae);if(!t||t.length>16384)return[];try{let e=JSON.parse(t);return Array.isArray(e)&&e.length<=oe&&e.every(e=>z(e,2048))?e:[]}catch{return[]}}function V(e,t,n){try{let r=he(e).filter(e=>e!==t);n&&r.push(t),r.length?e.setItem(ae,JSON.stringify(r.slice(-4))):e.removeItem(ae)}catch{}}function ge(){if(typeof window>`u`)return{storage:null,warning:null};try{return{storage:window.sessionStorage,warning:null}}catch{return{storage:null,warning:de}}}function _e(e,t){try{let n=me(e.getItem(ie));if(!n)return{data:null,warning:`Saved Code drafts could not be read. No saved requests were sent.`};let r=n.endpoints.find(e=>e.endpoint===t)??null,i=he(e);return{data:r,warning:i.includes(t)||!r&&i.length>0?fe:null}}catch{return{data:null,warning:de}}}function ve(e){let{provider:t,cwd:n,model:r,effort:i,permissionMode:a,thinking:o}=e.selection;return pe({input:e.input,edit:e.edit,selection:{provider:t,cwd:n,model:r,effort:i,permissionMode:a,...o===void 0?{}:{thinking:o}},selectionEdit:e.selectionEdit,creating:e.createUnknown||e.operation.kind===`creating`,retry:e.retry?{text:e.retry.text,key:e.retry.key,edit:e.retry.edit,...e.retry.resend?{resend:!0}:{},...e.retry.resend&&e.retry.resendReason?{resendReason:e.retry.resendReason}:{}}:null,stop:e.stopTarget?{turnId:e.stopTarget.turnId,epoch:e.stopTarget.epoch}:null})}function ye(e,t,n){try{let r=ve(n.fresh);if(!r)return V(e,t,!0),L;let i={endpoint:t,selectedId:null,fresh:r,sessions:[]},a=!1,o=[...n.sessions].sort(([e],[t])=>Number(t===n.selectedId)-Number(e===n.selectedId));for(let[r,s]of o){if(r!==n.selectedId&&!s.input&&!s.retry&&!s.stopTarget)continue;let o=ve(s);if(!o)return V(e,t,!0),L;if(i.sessions.length>=se){a=!0;continue}let c={...i,selectedId:r===n.selectedId?r:i.selectedId,sessions:[...i.sessions,{id:r,draft:o}]};if(JSON.stringify(c).length>le){a=!0;continue}i.sessions=c.sessions,i.selectedId=c.selectedId}if(n.selectedId!==null&&i.selectedId===null||JSON.stringify(i).length>le)return V(e,t,!0),L;let s=e.getItem(ie),c=[...(me(s)??{version:I,endpoints:[]}).endpoints.filter(e=>e.endpoint!==t),i],l=JSON.stringify({version:I,endpoints:c});for(;c.length>oe||l.length>ue;){let t=c.shift();t&&V(e,t.endpoint,!0),l=JSON.stringify({version:I,endpoints:c})}return l!==s&&e.setItem(ie,l),V(e,t,a||n.recoveryWarning!==null),a?L:null}catch{return V(e,t,!0),de}}var H={"codex-app":`Codex`,claude:`Claude`,cursor:`Cursor`,grok:`Grok`},be={ask:`Ask first`,auto:`Auto (YOLO)`,"read-only":`Read only`,plan:`Plan`,"accept-edits":`Accept edits`,"dont-ask":`Don't ask`,"auto-review":`Auto review`},xe={ask:`Review native permission requests before allowing actions.`,auto:`The native runtime may execute actions without asking for approval.`,"read-only":`The native runtime restricts actions to read-only access.`,plan:`Claude plans without applying edits.`,"accept-edits":`File edits proceed; other actions still ask.`,"dont-ask":`Actions not already allowed for this session are denied without asking.`,"auto-review":`A classifier approves or denies each action; unsure calls still ask.`},Se={idle:`Ready`,starting:`Starting`,streaming:`Running`,stopping:`Stopping`,suspended:`Suspended`,failed:`Runtime failed`};function Ce(e){return e.status===`starting`||e.status===`streaming`||e.status===`stopping`}function U(e){return e===`rolled-back`?{heading:`Turn rolled back`,detail:`This message's turn was removed by a rollback. Files it changed were not reverted. Retry sends it as a new message.`,error:`This message's turn was removed by a rollback. The message was not resent; Retry will submit it as a new message.`}:{heading:`Send did not start`,detail:`The original attempt ended on the server without running. Retry sends this as a new message.`,error:`The original attempt ended on the server without running. The message was not resent; Retry will submit it as a new message.`}}function W(e){return e.archivedAt===null&&e.capabilities.resume&&e.resume.available&&(e.status===`suspended`||e.status===`failed`&&e.error?.recoverable===!0)}function we(e,t,n){return!!e&&e.rollback?.available===!0&&e.archivedAt===null&&t&&n&&(e.status===`idle`||e.status===`failed`)}function Te(e,t){let n=new Set;if(t==null)return n;let r=new Set(e.filter(e=>e.kind===`turn_completed`||e.kind===`turn_failed`||e.kind===`turn_cancelled`).map(e=>e.turnId)),i=e.filter(e=>e.kind===`user_message`&&e.turnId!==null&&e.itemId===`${e.turnId}:user`&&e.firstSequence!==void 0),a=Math.max(...i.map(e=>e.firstSequence));for(let e of i)e.firstSequence>=t&&e.firstSequence<a&&r.has(e.turnId)&&n.add(e.itemId);return n}function Ee(e){return e.kind===`turn_cancelled`||e.status===`cancelled`?`Stopped`:e.kind===`turn_failed`||e.status===`error`?`Failed`:e.kind===`turn_completed`?`Completed`:{pending:`Pending`,running:`Running`,done:`Done`,error:`Failed`,cancelled:`Stopped`}[e.status]}var De=new Map,Oe=new WeakMap;function G(e){return{input:``,edit:0,selection:{...e},selectionEdit:0,operation:{kind:`idle`,error:null},retry:null,createUnknown:!1,requiredSequence:0,stopTarget:null,permissionOperations:{},awaitingTurn:null,steer:null}}function ke(e){let t=G(e.selection);return t.input=e.input,t.edit=e.edit,t.selectionEdit=e.selectionEdit,t.createUnknown=e.creating,t.retry=e.retry,e.creating&&(t.operation={kind:`creating`,error:`Creation was interrupted by reload. The original session may exist; no request has been retried.`}),e.retry&&(t.operation={kind:`unknown-send`,error:e.retry.resend?U(e.retry.resendReason).error:`The original message has not been reconciled after reload. It will not be sent automatically.`}),e.stop&&(t.stopTarget={...e.stop,outcome:`unknown`},t.operation={kind:`stopping`,error:`Checking the captured Stop after reload. No cancellation has been resent.`}),t}function Ae(e,t){let n=ge(),r=n.storage?Oe.get(n.storage):De;r||(r=new Map,Oe.set(n.storage,r));let i=r.get(e);if(!i){let a=n.storage?_e(n.storage,e):{data:null,warning:n.warning};i={endpoint:e,storage:n.storage,storageWarning:n.warning,recoveryWarning:a.warning,selectedId:a.data?.selectedId??null,navigation:0,fresh:a.data?ke(a.data.fresh):G({provider:`codex-app`,cwd:t,model:``,effort:null,permissionMode:`ask`}),sessions:new Map(a.data?.sessions.map(e=>[e.id,ke(e.draft)])??[]),listeners:new Set},r.set(e,i)}return i}function je(e){e.storage&&(e.storageWarning=ye(e.storage,e.endpoint,e))}function Me(e){return{provider:e.provider,cwd:e.cwd,model:e.model,effort:e.effort,permissionMode:e.permissionMode,...e.thinking===null?{}:{thinking:e.thinking}}}function Ne(e,t,n=!1){let r=e.providers.find(e=>e.id===t.provider);if(!r)return t;let i=r.capabilities,{thinking:a,...o}=t;return{...o,...r.id===`claude`&&a!==void 0?{thinking:a}:{},model:!n&&r.models.includes(t.model)?t.model:r.defaultModel,effort:!n&&t.effort!==null&&i.efforts.includes(t.effort)?t.effort:null,permissionMode:i.permissions?!n&&i.permissionModes.includes(t.permissionMode)?t.permissionMode:i.permissions&&i.permissionModes.includes(`ask`)?`ask`:i.permissionModes.includes(`auto`)?`auto`:`read-only`:`auto`}}function Pe(e,t){e.steer?.key===t&&(e.edit===e.steer.edit&&(e.input=``,e.edit++),e.steer=null)}function Fe(e,t){e.retry?.key===t&&(e.edit===e.retry.edit&&(e.input=``,e.edit++),e.retry=null,(e.operation.kind===`sending`||e.operation.kind===`unknown-send`)&&(e.operation={kind:`idle`,error:null}))}var Ie=`pending:user`;function Le(e,t,n=Date.now()){let r=e.retry;if(!r||r.resend||t.some(e=>e.kind===`user_message`&&e.clientTurnKey===r.key))return null;let i=e.operation.kind===`unknown-send`;return{itemId:Ie,turnId:null,kind:`user_message`,status:`pending`,text:r.text,clientTurnKey:r.key,firstSequence:2**53-1,createdAt:n,updatedAt:n,...i?{phase:`unknown`}:{}}}function Re(e,t,n=Date.now()){let r=Le(e,t,n);return r?[...t,r]:t}var ze=6,K=1e3,Be=100,Ve=32,He=150,q=e=>e instanceof w?e.message:`Connection lost. Refresh to check the current state.`,J=e=>e instanceof w&&e.status>=400&&e.status<500,Ue=`Follow-up delivery not confirmed. It was not resent; it appears in the conversation if Claude received it.`,We=`Follow-up delivery not confirmed. Claude may have received it, but it will not appear in the conversation. It was not resent.`,Ge=`The conversation changed since you chose this point. Review it and try again.`,Ke=`The conversation was rolled back elsewhere; this message was not sent.`,qe=(e,t)=>!t||e.epoch>t.epoch||e.epoch===t.epoch&&(e.sequence>t.sequence||e.sequence===t.sequence&&e.revision>=t.revision),Je=e=>e===`failed`||e===`cancelled`;function Ye(e,t){let n=e?.items.find(e=>e.kind===`user_message`&&e.clientTurnKey===t);return n?e.items.some(e=>e.turnId===n.turnId&&(e.kind===`turn_failed`||e.kind===`turn_cancelled`)):!1}var Xe=class{client;book;details=new Map;summaries=new Map;attention=new Map;rows=[];catalog=null;catalogError=null;transport=`disconnected`;filter={scope:`all`,archived:!1};workingDir;gitInfo=null;gitError=null;gitGeneration=0;pickerGeneration=0;workspacePicking=!1;indexGeneration=0;catalogGeneration=0;lifetime=0;active=!1;abort=new AbortController;syncing=new Map;detailReads=new Map;historyLoading=new Set;indexLoading=!1;moreSessions=!1;cursor=null;fetched=0;indexError=null;timer;listeners=new Set;model;draftSyncQueued=!1;constructor(e){this.client=E(e.port),this.workingDir=e.workingDir,this.book=Ae(T(e.port),e.workingDir),this.model=this.makeModel()}getModel=()=>this.model;subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));changed=()=>{this.model=this.makeModel();for(let e of this.listeners)e();let e=this.book.selectedId,t=e?this.details.get(e):void 0;this.active&&e&&!t?.error&&(!t||this.draft(e).requiredSequence>t.cursor)&&!this.draftSyncQueued&&(this.draftSyncQueued=!0,queueMicrotask(()=>{this.draftSyncQueued=!1,this.active&&this.book.selectedId===e&&!this.syncing.has(e)&&this.sync(e)}))};notify(){je(this.book),this.changed();for(let e of this.book.listeners)e!==this.changed&&e()}mount=()=>(this.active=!0,this.lifetime++,this.abort=new AbortController,this.book.listeners.add(this.changed),this.refresh(),()=>{je(this.book),this.active=!1,this.lifetime++,this.abort.abort(),this.syncing.clear();for(let e of this.detailReads.values())e.abort();this.detailReads.clear(),this.timer!==void 0&&clearTimeout(this.timer),this.timer=void 0,this.book.listeners.delete(this.changed),this.details.clear(),this.summaries.clear(),this.attention.clear(),this.rows=[],this.cursor=null,this.fetched=0,this.gitGeneration++,this.pickerGeneration++});setWorkingDir(e){if(e===this.workingDir)return;this.workingDir=e;let t=this.book.fresh;!t.selectionEdit&&!t.input&&t.operation.kind===`idle`&&!t.createUnknown&&(t.selection={...t.selection,cwd:e}),this.filter.scope===`cwd`&&this.readIndex(),this.readGit(),this.notify()}draft(e=this.book.selectedId){if(e===null)return this.book.fresh;let t=this.book.sessions.get(e);if(!t){let n=this.info(e);t=G(n?Me(n):this.book.fresh.selection),this.book.sessions.set(e,t)}return t}info(e){if(!e)return null;let t=this.details.get(e)?.session,n=this.summaries.get(e);return n&&qe(n,t)?n:t??n??null}observe(e){let t=this.attention.get(e.sessionId);(!t||qe(e,{...e,epoch:t.epoch,sequence:t.sequence,revision:t.revision}))&&this.attention.set(e.sessionId,{epoch:e.epoch,sequence:e.sequence,revision:e.revision,...e.pendingPermissionCount===void 0?{}:{pendingPermissionCount:e.pendingPermissionCount},...e.contextUsage===void 0?{}:{contextUsage:e.contextUsage}})}resolve(e,t){let n=this.attention.get(e),{contextUsage:r,pendingPermissionCount:i,...a}=t;return{...a,...n?.pendingPermissionCount===void 0?{}:{pendingPermissionCount:n.pendingPermissionCount},...n?.contextUsage===void 0?{}:{contextUsage:n.contextUsage}}}accept(e){if(!this.active)return;let t=this.info(e.sessionId);if(!qe(e,t))return;e.sessionId===this.book.selectedId&&t&&(e.lastTurnCompletedAt??0)>(t.lastTurnCompletedAt??0)&&this.markVisited(e.sessionId);let{contextUsage:n,pendingPermissionCount:r,...i}=e;if(this.summaries.set(i.sessionId,i),this.summaries.size>1006){let e=[...this.summaries.keys()].find(e=>e!==this.book.selectedId&&!this.details.has(e)&&!this.rows.includes(e));e&&(this.summaries.delete(e),this.attention.delete(e))}let a=this.book.sessions.get(i.sessionId);a?.awaitingTurn&&M(i)&&(a.awaitingTurn=null),a?.stopTarget&&(i.turnId!==a.stopTarget.turnId||i.epoch!==a.stopTarget.epoch||!M(i))&&(a.stopTarget=null,a.operation.kind===`stopping`&&(a.operation=a.retry?{kind:`unknown-send`,error:`The original message still needs reconciliation.`}:{kind:`idle`,error:null}))}state(e){let t=this.details.get(e);return t||(t=j(e),this.details.set(e,t),this.trimDetails()),t}trimDetails(){for(let e of this.details.keys()){if(this.details.size<=ze)break;e!==this.book.selectedId&&(this.details.delete(e),this.detailReads.get(e)?.abort(),this.detailReads.delete(e),this.syncing.delete(e))}}update(e,t){let n=this.details.get(e)?.session??this.summaries.get(e);this.details.set(e,t),t.session&&this.accept(t.session);let r=this.book.sessions.get(e);if(r&&t.session&&t.hydrated&&!t.needsSnapshot){let e=t.session.historyGeneration??0;n&&e>(n.historyGeneration??0)&&this.rolledBack(r,t);let i=r.steer;e>0&&i?.state===`unknown`&&!t.items.some(e=>e.turnId===i.turnId)&&(r.steer=null)}if(r?.retry&&t.items.some(e=>e.kind===`user_message`&&e.clientTurnKey===r.retry.key)&&(Ye(t,r.retry.key)?this.requireNewKey(r):Fe(r,r.retry.key)),r?.steer&&t.items.some(e=>e.kind===`user_message`&&e.clientTurnKey===r.steer.key)&&Pe(r,r.steer.key),r?.awaitingTurn){let e=t.items.find(e=>e.kind===`user_message`&&e.clientTurnKey===r.awaitingTurn)?.turnId;e&&t.items.some(t=>t.turnId===e&&(t.kind===`turn_completed`||t.kind===`turn_failed`||t.kind===`turn_cancelled`))&&(r.awaitingTurn=null)}if(r&&t.synced){let e=new Set(t.permissions.map(e=>e.permissionId));for(let t of Object.keys(r.permissionOperations))!e.has(t)&&!r.permissionOperations[t].pending&&delete r.permissionOperations[t]}this.notify()}requireNewKey(e,t){if(!e.retry)return;let{resendReason:n,...r}=e.retry;e.retry={...r,key:crypto.randomUUID(),resend:!0,...t?{resendReason:t}:{}},e.operation={kind:`unknown-send`,error:U(t).error}}rolledBack(e,t){let n=e=>t.items.some(t=>t.kind===`user_message`&&t.clientTurnKey===e);e.awaitingTurn&&!n(e.awaitingTurn)&&(e.awaitingTurn=null),e.retry&&!e.retry.resend&&!n(e.retry.key)&&(e.operation.kind===`idle`||e.operation.kind===`unknown-send`)&&(e.operation={kind:`unknown-send`,error:Ke})}removedByRollback(e,t){let n=this.details.get(e);return t.status===`cancelled`&&!!n?.hydrated&&(n.session?.historyGeneration??0)>0&&t.sequence<=n.cursor&&(!n.hasOlder||(n.beforeSequence??1/0)<=t.sequence)&&!n.items.some(e=>e.turnId===t.turnId)}makeModel(){let e=this.book.selectedId,t=this.info(e),n=this.draft(e),r=e?this.details.get(e):void 0,i=(e,t)=>{let n=this.resolve(e.sessionId,e);return t?.synced?{...n,pendingPermissionCount:t.permissions.length}:n},a=t&&i(t,r),o=n.operation,s=this.book.storageWarning??this.book.recoveryWarning,c=[`creating`,`sending`,`stopping`,`resuming`,`patching`,`rolling-back`].includes(o.kind)&&!o.error,l=e===null?!!this.catalog:!!r?.synced&&(!a||a.sequence<=r.cursor)&&n.requiredSequence<=(r?.cursor??0),u=!!a&&l&&a.provider===`claude`&&a.status===`streaming`&&!!a.turnId&&a.archivedAt===null,d=u&&!!a&&(r?.items??[]).some(e=>e.kind===`user_message`&&e.itemId.startsWith(`${a.turnId}:steer:`)),f=n.steer?.state===`unknown`?n.steer.unrecorded?We:Ue:null;return{catalog:this.catalog,sessions:this.rows.map(e=>{let t=this.info(e),n=this.details.get(e);return t&&i(t,n)}).filter(e=>!!e),selectedId:e,session:a,items:Re(n,r?.items??[]),hasUnsentDraft:!!this.book.fresh.input.trim()||this.book.fresh.createUnknown||!!this.book.fresh.retry,permissions:r?.permissions??[],input:n.input,selection:a?Me(a):n.selection,gitInfo:this.gitInfo,loading:this.indexLoading||!!r?.hydrating||!!e&&!r?.hydrated&&!r?.error,pending:c,busy:M(a),working:!!n.awaitingTurn||M(a),workingIds:new Set(this.rows.filter(e=>{let t=this.info(e);return!!this.book.sessions.get(e)?.awaitingTurn||!!t&&M(t)})),followUp:u,followUpSent:d,steering:n.steer?.state===`sending`,synced:l,transport:this.transport,workspacePicking:this.workspacePicking,error:[o.error??f??r?.error??this.indexError??this.catalogError??this.gitError??a?.error?.message,s].filter(Boolean).join(` `)||null,operation:{...o,error:o.error&&s?`${o.error} ${s}`:o.error},retryText:n.retry?.text??null,canRetrySameSend:!!e&&o.kind===`unknown-send`&&!!n.retry&&l&&a?.archivedAt===null,resendRequired:!!n.retry?.resend,resendReason:n.retry?.resend?n.retry.resendReason??null:null,permissionOperations:{...n.permissionOperations},hasMoreSessions:this.moreSessions,hasOlderHistory:r?.hasOlder??!1,filter:this.filter,creationUnknown:e===null&&n.createUnknown,startAnotherSession:this.startAnotherSession,newSession:this.newSession,selectSession:this.selectSession,setInput:this.setInput,setSelection:this.setSelection,pickWorkspace:this.pickWorkspace,send:this.send,retrySameSend:this.retrySameSend,stop:this.stop,resume:this.resume,rollbackSession:this.rollbackSession,rename:this.rename,archive:this.archive,answer:this.answer,refresh:this.refresh,loadMoreSessions:this.loadMoreSessions,loadOlderHistory:this.loadOlderHistory,setFilter:this.setFilter,clearError:this.clearError}}async readCatalog(){let e=++this.catalogGeneration,t=this.lifetime;try{let n=await this.client.listModelOptions(this.abort.signal);if(!this.active||t!==this.lifetime||e!==this.catalogGeneration)return;this.catalog=n,this.catalogError=null;let r=this.book.fresh;!r.selection.model&&!r.selectionEdit&&r.operation.kind===`idle`&&(r.selection=Ne(n,{...r.selection,provider:n.defaultProvider})),this.notify()}catch(n){this.active&&t===this.lifetime&&e===this.catalogGeneration&&(this.catalogError=q(n),this.notify())}}async readIndex(e=!1){let t=++this.indexGeneration,n=this.lifetime,r=e?this.cursor:null,i=e?Be:Math.min(K,Math.max(Be,this.fetched));this.indexLoading=!0,this.notify();try{let a=await this.client.listSessions({...this.filter,limit:i,...r===null?{}:{cursor:r},...this.filter.scope===`cwd`?{cwd:this.workingDir}:{}},this.abort.signal);if(!this.active||n!==this.lifetime||t!==this.indexGeneration)return;for(let e of a.sessions){this.observe(e),this.accept(e);let t=this.details.get(e.sessionId);t?.hydrated&&!t.hydrating&&e.sequence>t.cursor&&(this.details.set(e.sessionId,F(t,{type:`stale`})),this.sync(e.sessionId))}this.rows=[...new Set([...e?this.rows:[],...a.sessions.map(e=>e.sessionId)])].slice(0,K),this.cursor=a.nextCursor,this.fetched=(e?this.fetched:0)+a.sessions.length,this.moreSessions=a.hasMore&&this.rows.length<K,this.indexError=null;let o=new Set([...this.rows,...this.details.keys(),...this.book.selectedId?[this.book.selectedId]:[]]);for(let e of this.summaries.keys())o.has(e)||(this.summaries.delete(e),this.attention.delete(e))}catch(e){this.active&&n===this.lifetime&&t===this.indexGeneration&&(this.indexError=q(e))}finally{this.active&&n===this.lifetime&&t===this.indexGeneration&&(this.indexLoading=!1,this.notify())}}scheduleIndex(){this.active&&this.timer===void 0&&(this.timer=setTimeout(()=>{this.timer=void 0,this.readIndex()},He))}sync(e,t=!1){let n=this.syncing.get(e);if(n)return n;let r=this.lifetime,i=new AbortController;this.detailReads.set(e,i),this.state(e);let a=()=>this.active&&r===this.lifetime&&this.detailReads.get(e)===i&&this.details.has(e),o=(async()=>{let n=0,r=null;try{for(let o=0;o<Ve&&a();o++){let o=this.state(e);if(t||!o.hydrated||o.needsSnapshot){if(++n>2)throw Error(`snapshot did not cover live updates`);t=!1,this.update(e,F(o,{type:`snapshot-start`}));let s=this.book.sessions.get(e)?.stopTarget,c=s?.outcome===`unknown`?s:null,l=await this.client.snapshot(e,i.signal);if(!a())return;r=c,this.observe(l.session),this.update(e,F(this.state(e),{type:`snapshot`,snapshot:l}))}if(o=this.state(e),o.needsSnapshot)continue;let s=o.cursor,c=await this.client.events(e,s,i.signal);if(!a())return;let l=F(this.state(e),{type:`page`,page:c});if(this.update(e,l),!l.needsSnapshot){if(l.synced&&l.cursor>=(this.book.sessions.get(e)?.requiredSequence??0)){this.reconcileStop(e,r);return}if(l.cursor<=s){t=!0;continue}}}a()&&this.update(e,F(this.state(e),{type:`error`,error:`History is still catching up. Refresh to continue.`}))}catch(t){if(!a())return;if(t instanceof w&&t.code===`invalid_sequence`&&n<2){let t=await this.client.snapshot(e,i.signal).catch(()=>null);if(!a())return;if(t){this.update(e,F(this.state(e),{type:`snapshot`,snapshot:t}));return}}this.update(e,F(this.state(e),{type:`error`,error:q(t)})),t instanceof w&&t.code===`session_not_found`&&this.scheduleIndex()}})().finally(()=>{this.syncing.get(e)===o&&this.syncing.delete(e),this.detailReads.get(e)===i&&this.detailReads.delete(e),this.trimDetails()});return this.syncing.set(e,o),o}onEvent=e=>{if(!this.active)return;e.session?.sessionId===e.sessionId&&this.accept(e.session),(e.event===`code_session`||e.item?.kind===`permission_request`||e.update?.status)&&this.scheduleIndex();let t=this.book.sessions.get(e.sessionId);e.item?.kind===`user_message`&&e.item.clientTurnKey&&t?.steer?.key===e.item.clientTurnKey&&(t.requiredSequence=Math.max(t.requiredSequence,e.sequence),Pe(t,e.item.clientTurnKey)),e.item?.kind===`user_message`&&e.item.clientTurnKey&&t?.retry?.key===e.item.clientTurnKey&&(t.requiredSequence=Math.max(t.requiredSequence,e.sequence),Ye(this.details.get(e.sessionId),e.item.clientTurnKey)?this.requireNewKey(t):Fe(t,e.item.clientTurnKey));let n=this.details.get(e.sessionId);if(!n){this.notify();return}let r=F(n,{type:`event`,event:e});this.update(e.sessionId,r),!r.synced&&!r.hydrating&&this.sync(e.sessionId)};onTransport=e=>{this.transport=e;for(let[e,t]of this.details)this.details.set(e,F(t,{type:`stale`}));if(this.notify(),e===`connected`&&this.active){this.readIndex();for(let e of this.details.keys())this.sync(e,!0)}};refresh=async()=>{let e=this.book.selectedId;await Promise.all([this.readCatalog(),this.readIndex(),e?this.sync(e,!0):Promise.resolve(),this.readGit()])};loadMoreSessions=async()=>{this.moreSessions&&!this.indexLoading&&await this.readIndex(!0)};setFilter=e=>{this.filter={...e},this.cursor=null,this.fetched=0,this.rows=[],this.moreSessions=!1,this.notify(),this.readIndex()};startAnotherSession=()=>{let e=this.book.fresh;if(this.book.selectedId!==null||!e.createUnknown)return;let t=G(e.selection);t.input=e.input,t.edit=e.edit,t.selectionEdit=e.selectionEdit,t.operation.error=`The original session may still exist. Your text is preserved; Send will create another session.`,this.book.fresh=t,this.book.navigation++,this.pickerGeneration++,this.notify()};newSession=()=>{this.book.selectedId=null,this.book.navigation++,this.gitInfo=null,this.notify(),this.readGit()};selectSession=async e=>{this.book.selectedId=e,this.book.navigation++,this.draft(e),this.state(e),this.gitInfo=null,this.notify(),await this.sync(e,!0),this.book.selectedId===e&&this.markVisited(e),this.book.selectedId===e&&await this.readGit()};async markVisited(e){try{this.accept(await this.client.visitSession(e)),this.notify()}catch{}}setInput=e=>{let t=this.draft();t.input=e,t.edit++,this.notify()};clearError=()=>{let e=this.draft();e.operation.kind===`idle`&&(e.operation={kind:`idle`,error:null}),e.steer?.state===`unknown`&&(e.steer=null),this.indexError=null,this.book.recoveryWarning=null,this.notify()};async readGit(){let e=++this.gitGeneration,t=this.lifetime,n=this.book.selectedId,r=this.info(n)?.cwd??(n===null?this.book.fresh.selection.cwd:``);if(this.gitInfo=null,this.gitError=null,r&&this.active)try{let i=await this.client.getGitInfo(r,this.abort.signal);this.active&&t===this.lifetime&&e===this.gitGeneration&&n===this.book.selectedId&&(this.gitInfo=i,this.notify())}catch(r){this.active&&t===this.lifetime&&e===this.gitGeneration&&n===this.book.selectedId&&(this.gitError=q(r),this.notify())}}pickWorkspace=async()=>{let e=this.book.fresh;if(this.book.selectedId!==null||e.operation.kind!==`idle`||e.createUnknown||this.workspacePicking)return;let t=this.book.navigation,n=e.selectionEdit,r=++this.pickerGeneration;this.workspacePicking=!0,this.notify();try{let i=await this.client.pickWorkspace();if(!this.active||r!==this.pickerGeneration||t!==this.book.navigation||n!==e.selectionEdit||e!==this.book.fresh||e.operation.kind!==`idle`)return;!i.cancelled&&i.path&&(e.selection={...e.selection,cwd:i.path},e.selectionEdit++,this.notify(),await this.readGit())}catch(i){this.active&&r===this.pickerGeneration&&t===this.book.navigation&&n===e.selectionEdit&&e===this.book.fresh&&e.operation.kind===`idle`&&(e.operation.error=q(i),this.notify())}finally{this.workspacePicking=!1,this.notify()}};setSelection=async e=>{let t=this.book.selectedId,n=this.info(t);if(n&&e.provider&&e.provider!==n.provider){this.newSession(),await this.setSelection({...e,cwd:n.cwd});return}let r=this.draft();if(r.operation.kind!==`idle`||r.createUnknown)return;if(n&&t){if(e.cwd!==void 0&&e.cwd!==n.cwd||e.provider&&e.provider!==n.provider){r.operation.error=`Runtime and workspace are fixed for this session. Create a new session to change them.`,this.notify();return}if(n.status!==`idle`||!this.model.synced||n.archivedAt!==null){r.operation.error=`Wait for this session to be idle and synchronized before changing settings.`,this.notify();return}await this.patch(t,{model:e.model??n.model,effort:e.effort===void 0?n.effort:e.effort,permissionMode:e.permissionMode??n.permissionMode,...n.provider===`claude`?{thinking:e.thinking??n.thinking??!0}:{}});return}if(t)return;let i=e.provider!==void 0&&e.provider!==r.selection.provider,a={...r.selection,...e};this.catalog&&i&&(a=Ne(this.catalog,a,!0));let o=this.catalog?.providers.find(e=>e.id===a.provider);a.effort!==null&&o&&!o.capabilities.efforts.includes(a.effort)&&(a.effort=null),r.selection=a,r.selectionEdit++,this.notify(),e.cwd!==void 0&&await this.readGit()};async patch(e,t,n=!1){let r=this.draft(e),i=this.info(e);if(!i||r.operation.kind!==`idle`||M(i)){let e=Error(i?`Wait for the current session action to finish before changing it.`:`Refresh this session before changing it.`);if(r.operation.error=e.message,this.notify(),n)throw e;return}let a=null;r.operation={kind:`patching`,error:null},this.notify();try{this.accept(await this.client.patchSession(e,{...t,expectedRevision:i.revision})),r.operation={kind:`idle`,error:null}}catch(t){t instanceof w&&t.session?.sessionId===e&&(this.observe(t.session),this.accept(t.session)),a=t instanceof w?t:Error(q(t)),r.operation={kind:`idle`,error:a.message}}if(this.notify(),this.scheduleIndex(),this.active&&await this.sync(e,!0),n&&a)throw a}rename=async(e,t)=>{await this.patch(e,{title:t},!0)};archive=async(e,t)=>{await this.patch(e,{archived:t},!0)};send=async()=>{let e=this.book.selectedId,t=this.draft(e);if(t.operation.kind!==`idle`||t.createUnknown||!t.input.trim()||t.steer?.state===`sending`)return;let n=this.info(e);if(e&&n&&this.model.followUp){this.model.followUpSent||await this.steer(e,t,n);return}if(t.steer?.state===`unknown`&&(t.steer=null),e&&n&&W(n)&&this.model.synced){t.operation={kind:`resuming`,error:null},this.notify();try{this.accept(await this.client.attachSession(e)),t.operation={kind:`idle`,error:null}}catch(e){t.operation={kind:`idle`,error:q(e)},this.notify(),this.scheduleIndex();return}this.notify(),this.scheduleIndex(),this.active&&await this.sync(e,!0),n=this.info(e)}if(e&&(!n||n.status!==`idle`||n.archivedAt!==null||!this.model.synced)){t.operation.error=`Wait for the session to be idle and synchronized before sending.`,this.notify();return}let r={text:t.input,edit:t.edit,key:crypto.randomUUID()},i=this.book.navigation;if(!e){let n={...t.selection},r=this.catalog?.providers.find(e=>e.id===n.provider);if(!r?.available||!n.cwd.trim()||!r.models.includes(n.model)||!r.capabilities.permissionModes.includes(n.permissionMode)||n.effort!==null&&!r.capabilities.efforts.includes(n.effort)){t.operation.error=`Choose an available runtime, workspace, model and supported settings before sending.`,this.notify();return}t.operation={kind:`creating`,error:null},this.notify();try{let r=await this.client.createSession(n);e=r.sessionId,this.book.sessions.set(e,t),this.book.fresh===t&&(this.book.fresh=G(n)),this.book.navigation===i&&this.book.selectedId===null&&(this.book.selectedId=e,this.book.navigation++),this.accept(r),this.active&&this.state(e),this.scheduleIndex()}catch(e){t.createUnknown=!J(e),t.operation={kind:t.createUnknown?`creating`:`idle`,error:t.createUnknown?`Session creation could not be confirmed. The original session may exist. Refresh the list, or choose Start another session to keep this text in a new draft.`:q(e)},this.notify(),this.scheduleIndex();return}}t=this.draft(e),t.retry=r,await this.submit(e,t)};async submit(e,t){let n=t.retry;if(n){t.operation={kind:`sending`,error:null},t.awaitingTurn=n.key,this.notify();try{let r=await this.client.sendPrompt(e,{text:n.text,clientTurnKey:n.key});if(r.clientTurnKey!==n.key)throw Error(`Mismatched prompt receipt`);t.requiredSequence=Math.max(t.requiredSequence,r.sequence);let i=this.details.get(e);i&&this.details.set(e,F(i,{type:`stale`})),Je(r.status)?(this.requireNewKey(t,this.removedByRollback(e,r)?`rolled-back`:void 0),t.awaitingTurn=null):Fe(t,n.key)}catch(e){t.retry?.key===n.key&&(t.operation={kind:J(e)?`idle`:`unknown-send`,error:J(e)?q(e):`Message acceptance is unknown. Refresh, or explicitly retry the original message with the same key.`},J(e)&&(t.retry=null,t.awaitingTurn=null))}this.notify(),this.scheduleIndex(),this.active&&await this.sync(e,!0)}}async steer(e,t,n){if(!n.turnId||t.stopTarget&&t.stopTarget.outcome!==`retryable`)return;let r={key:crypto.randomUUID(),text:t.input,edit:t.edit,turnId:n.turnId,epoch:n.epoch,state:`sending`};t.steer=r,t.operation.error&&(t.operation={...t.operation,error:null}),this.notify();try{let n=await this.client.steerSession(e,{text:r.text,clientTurnKey:r.key,turnId:r.turnId,epoch:r.epoch});if(n.clientTurnKey!==r.key)throw Error(`Mismatched follow-up receipt`);t.requiredSequence=Math.max(t.requiredSequence,n.sequence);let i=this.details.get(e);i&&this.details.set(e,F(i,{type:`stale`})),Pe(t,r.key)}catch(e){t.steer===r&&(J(e)?(t.steer=null,t.operation.kind===`idle`&&(t.operation={kind:`idle`,error:q(e)})):(r.state=`unknown`,r.unrecorded=e instanceof w&&e.code===`steer_outcome_unknown`))}this.notify(),this.scheduleIndex(),this.active&&await this.sync(e,!0)}retrySameSend=async()=>{let e=this.book.selectedId,t=this.draft(e);e&&this.model.canRetrySameSend&&t.operation.kind===`unknown-send`&&await this.submit(e,t)};reconcileStop(e,t){let n=this.book.sessions.get(e),r=this.details.get(e),i=this.info(e);!t||t.outcome!==`unknown`||n?.stopTarget!==t||!r?.synced||!i||i.sequence>r.cursor||i.turnId!==t.turnId||i.epoch!==t.epoch||(i.status===`starting`||i.status===`streaming`?(t.outcome=`retryable`,n.operation={kind:n.retry?`unknown-send`:`idle`,error:`Stop could not be confirmed. The same turn is still running. Press Stop to retry for this turn.`}):i.status===`stopping`&&(t.outcome=`accepted`,n.operation={kind:`stopping`,error:null}),this.notify())}stop=async()=>{let e=this.book.selectedId,t=this.info(e);if(!e||!t?.turnId||!M(t)||!t.capabilities.interrupt||t.status===`stopping`)return;let n=this.draft(e),r=n.stopTarget;if(r&&(r.outcome!==`retryable`||!this.model.synced||r.turnId!==t.turnId||r.epoch!==t.epoch))return;let i=r??{turnId:t.turnId,epoch:t.epoch,outcome:`pending`};i.outcome=`pending`,n.stopTarget=i,n.operation={kind:`stopping`,error:null},this.notify();try{let t=await this.client.cancelPrompt(e,{turnId:i.turnId,epoch:i.epoch});n.stopTarget===i&&(i.outcome=`accepted`),this.accept(t)}catch(e){n.stopTarget===i&&(i.outcome=`unknown`,n.operation={kind:`stopping`,error:q(e)},J(e)&&(n.stopTarget=null,n.operation.kind=`idle`))}this.notify(),this.scheduleIndex(),this.active&&(i.outcome===`unknown`&&await this.syncing.get(e),this.active&&await this.sync(e,!0))};resume=async()=>{let e=this.book.selectedId,t=this.info(e),n=this.draft(e);if(e&&t&&this.model.synced&&n.operation.kind===`idle`&&t.archivedAt===null&&[`suspended`,`failed`].includes(t.status)&&t.capabilities.resume&&t.resume.available&&(t.status!==`failed`||t.error?.recoverable)){n.operation={kind:`resuming`,error:null},this.notify();try{this.accept(await this.client.attachSession(e)),n.operation={kind:`idle`,error:null}}catch(e){n.operation={kind:`idle`,error:q(e)}}this.notify(),this.scheduleIndex(),this.active&&await this.sync(e,!0)}};rollbackSession=async e=>{let t=this.book.selectedId,n=this.info(t),r=this.draft(t);if(t&&n&&we(n,this.model.synced,r.operation.kind===`idle`&&r.steer?.state!==`sending`)){r.operation={kind:`rolling-back`,error:null},this.notify();try{this.accept(await this.client.rollbackSession(t,{expectedRevision:n.revision,expectedEpoch:n.epoch,upToItemId:e})),r.operation={kind:`idle`,error:null}}catch(e){e instanceof w&&e.session?.sessionId===t&&(this.observe(e.session),this.accept(e.session)),r.operation={kind:`idle`,error:e instanceof w&&e.code===`revision_conflict`?Ge:q(e)}}this.notify(),this.scheduleIndex(),this.active&&await this.sync(t,!0)}};answer=async(e,t)=>{let n=e.sessionId,r=this.details.get(n),i=this.info(n),a=this.draft(n);if(a.permissionOperations[e.permissionId]?.pending)return;let o=r?.permissions.find(t=>t.permissionId===e.permissionId);if(!r?.synced||!i||i.sequence>r.cursor||!o||o.turnId!==e.turnId||o.epoch!==e.epoch||i.turnId!==e.turnId||i.epoch!==e.epoch||!o.options.some(e=>e.optionId===t)){a.permissionOperations[e.permissionId]={pending:!1,error:`This approval is no longer current. Refresh its status.`},this.notify(),this.active&&await this.sync(n,!0);return}a.permissionOperations[e.permissionId]={pending:!0,error:null},this.notify();try{await this.client.answerPermission(e.permissionId,{sessionId:n,turnId:e.turnId,epoch:e.epoch,optionId:t}),a.permissionOperations[e.permissionId]={pending:!0,error:null}}catch(t){a.permissionOperations[e.permissionId]={pending:!0,error:q(t)}}this.notify(),this.scheduleIndex(),this.active&&await this.sync(n,!0);let s=this.details.get(n),c=!s?.synced||s.permissions.some(t=>t.permissionId===e.permissionId),l=a.permissionOperations[e.permissionId];c&&l?a.permissionOperations[e.permissionId]={pending:!1,error:l.error}:delete a.permissionOperations[e.permissionId],this.notify()};loadOlderHistory=async()=>{let e=this.book.selectedId;if(!e||this.historyLoading.has(e))return;let t=this.details.get(e);if(!t?.hydrated||!t.hasOlder||t.beforeSequence===null)return;let n=this.lifetime;this.historyLoading.add(e);try{let r=await this.client.history(e,t.beforeSequence,this.abort.signal);this.active&&n===this.lifetime&&this.details.get(e)?.beforeSequence===t.beforeSequence&&this.update(e,F(this.state(e),{type:`history`,page:r}))}catch(t){this.active&&n===this.lifetime&&(this.draft(e).operation.error=q(t),this.notify())}finally{this.historyLoading.delete(e)}}};function Ze({port:e,onEvent:t,onTransport:n}){let r=(0,x.useRef)({onEvent:t,onTransport:n});r.current={onEvent:t,onTransport:n},(0,x.useEffect)(()=>{if(!e)return;let t=!0,n=new EventSource(`${T(e)}/api/events`);return n.onopen=()=>{t&&r.current.onTransport?.(`connected`)},n.onmessage=e=>{if(!t)return;let n;try{n=JSON.parse(e.data)}catch{return}n?.topic!==`code`||typeof n.sessionId!=`string`||!Number.isSafeInteger(n.sequence)||n.sequence<1||!Number.isSafeInteger(n.epoch)||(n.event===`code_item`||n.event===`code_item_update`||n.event===`code_session`)&&r.current.onEvent(n)},n.onerror=()=>{t&&r.current.onTransport?.(n.readyState===EventSource.CLOSED?`disconnected`:`reconnecting`)},()=>{t=!1,n.close()}},[e])}function Qe({port:e,workingDir:t}){let n=T(e),r=(0,x.useMemo)(()=>new Xe({port:e,workingDir:t}),[n,e]);return(0,x.useEffect)(()=>r.mount(),[r]),(0,x.useEffect)(()=>r.setWorkingDir(t),[r,t]),Ze({port:e,onEvent:r.onEvent,onTransport:r.onTransport}),(0,x.useSyncExternalStore)(r.subscribe,r.getModel,r.getModel)}function $e(e){return e.archivedAt===null?`active`:`archived`}function et(e,t){return t.createdAt-e.createdAt||e.sessionId.localeCompare(t.sessionId)}function tt(e){let t=e.filter(e=>$e(e)===`active`).sort(et),n=e.filter(e=>$e(e)===`archived`).sort((e,t)=>(t.archivedAt??t.createdAt)-(e.archivedAt??e.createdAt)||e.sessionId.localeCompare(t.sessionId)),r=[];return t.length&&r.push({section:`active`,sessions:t}),n.length&&r.push({section:`archived`,sessions:n}),r}function nt(e){return e===void 0?{kind:`unknown`}:e>0?{kind:`approvals`,count:e}:{kind:`none`}}function rt(e){return e.kind===`unknown`?`Approval status unknown`:e.kind===`none`?`No pending approvals`:`${e.count} pending approval${e.count===1?``:`s`}`}function it(e){if(e.archivedAt!==null)return!1;let t=e.lastTurnCompletedAt,n=e.lastVisitedAt;return t===null||n===null?!1:t>n}function at(e){let t=new Map;for(let n of[...e].sort(et)){let e=t.get(n.cwd)??[];e.push(n),t.set(n.cwd,e)}return[...t].map(([e,t])=>({cwd:e,sessions:t}))}var ot=[`priority`,`today`,`yesterday`,`earlier`],st={priority:`Priority`,today:`Today`,yesterday:`Yesterday`,earlier:`Earlier`};function ct(e){let t=new Date(e);return t.setHours(0,0,0,0),t.getTime()}function lt(e,t=Date.now(),n=null){let r=ct(t),i=ct(r-1),a=new Map;for(let t of e){let e=t.sessionId!==n&&it(t)?`priority`:t.lastUsedAt>=r?`today`:t.lastUsedAt>=i?`yesterday`:`earlier`,o=a.get(e)??[];o.push(t),a.set(e,o)}let o=(e,t)=>e===`priority`?t.lastTurnCompletedAt??t.lastUsedAt:t.lastUsedAt;return ot.filter(e=>a.has(e)).map(e=>({bucket:e,sessions:a.get(e).sort((t,n)=>o(e,n)-o(e,t)||t.sessionId.localeCompare(n.sessionId))}))}function ut(e){return e.replace(/[\\/]+$/,``).split(/[\\/]/).pop()||e}var Y=g(),dt=y.newCodeSession,ft=`jaw.code.sidebarView`;function pt(){try{return localStorage.getItem(ft)===`activity`?`activity`:`projects`}catch{return`projects`}}function mt(){return(0,Y.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`15`,height:`15`,"aria-hidden":`true`,focusable:`false`,children:(0,Y.jsx)(`path`,{d:`M8 2.5a3.5 3.5 0 0 0-3.5 3.5v2.3L3.3 10.6h9.4L11.5 8.3V6A3.5 3.5 0 0 0 8 2.5Z M6.6 12.4a1.5 1.5 0 0 0 2.8 0`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinejoin:`round`,strokeLinecap:`round`})})}function ht(){return(0,Y.jsxs)(`svg`,{viewBox:`0 0 16 16`,width:`15`,height:`15`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsx)(`circle`,{cx:`7`,cy:`7`,r:`4.25`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`}),(0,Y.jsx)(`path`,{d:`M10.2 10.2 13.5 13.5`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`})]})}function gt(){return(0,Y.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":`true`,focusable:`false`,children:(0,Y.jsx)(`path`,{d:`M8 3.5v9M3.5 8h9`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`})})}function _t({session:e,controller:t,view:n}){let[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(e.title??``),[s,c]=(0,x.useState)(!1),[l,u]=(0,x.useState)(null),d=(0,x.useRef)(!1),f=(0,x.useRef)(null),p=(0,x.useId)(),m=t.selectedId===e.sessionId,h=Ce(e),g=nt(m&&t.synced?t.permissions.length:e.pendingPermissionCount),_=!m&&it(e),v=t.workingIds?.has(e.sessionId)??!1,y=v&&e.status===`idle`;async function b(e,t){if(!d.current){d.current=!0,c(!0),u(null);try{await e(),t?.()}catch(e){u(e instanceof Error?e.message:String(e))}finally{d.current=!1,c(!1)}}}function S(){i(!1),f.current?.focus()}return(0,Y.jsxs)(`li`,{className:`code-session-row`,children:[(0,Y.jsxs)(`button`,{ref:f,type:`button`,className:`code-session-item${m?` active`:``}`,"aria-current":m?`true`:void 0,onClick:()=>void b(()=>t.selectSession(e.sessionId)),children:[(0,Y.jsxs)(`span`,{className:`code-session-cwd`,children:[_&&(0,Y.jsx)(`span`,{className:`code-session-unread-dot`,role:`img`,"aria-label":`Unread`}),e.title||`Untitled session`]}),(0,Y.jsx)(`span`,{className:`code-session-meta`,title:e.cwd,children:n===`activity`?`${ut(e.cwd)} · ${H[e.provider]}`:H[e.provider]}),(0,Y.jsxs)(`span`,{className:`code-session-status code-session-status-${y?`starting`:e.status}`,"data-quiet":e.status===`idle`&&!v?`true`:void 0,children:[v&&(0,Y.jsx)(`span`,{className:`code-session-spinner`,"aria-hidden":`true`}),y?Se.starting:Se[e.status]]}),(0,Y.jsx)(`span`,{className:`code-session-attention code-session-attention-${g.kind}`,"data-quiet":g.kind===`none`?`true`:void 0,children:rt(g)})]}),r?(0,Y.jsxs)(`form`,{className:`code-session-rename`,onSubmit:n=>{n.preventDefault(),a.trim()&&b(()=>t.rename(e.sessionId,a.trim()),S)},children:[(0,Y.jsx)(`input`,{autoFocus:!0,"aria-label":`Session title`,"aria-describedby":l?p:void 0,value:a,disabled:s,onChange:e=>o(e.target.value),onKeyDown:t=>{t.key===`Escape`&&!s&&(t.preventDefault(),o(e.title??``),S())}}),(0,Y.jsx)(`button`,{type:`submit`,disabled:s||!a.trim(),children:`Save`}),(0,Y.jsx)(`button`,{type:`button`,disabled:s,onClick:S,children:`Cancel`})]}):(0,Y.jsxs)(`details`,{className:`code-session-actions`,children:[(0,Y.jsx)(`summary`,{"aria-label":`Actions for ${e.title||`Untitled session`}`,children:`Actions`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`button`,{type:`button`,disabled:s||h,onClick:()=>{o(e.title??``),i(!0)},children:`Rename`}),(0,Y.jsx)(`button`,{type:`button`,disabled:s||h,title:h?`Stop before archiving`:void 0,onClick:()=>void b(()=>t.archive(e.sessionId,e.archivedAt===null)),children:e.archivedAt===null?`Archive`:`Restore`}),W(e)&&(0,Y.jsx)(`button`,{type:`button`,disabled:s||!m||!t.synced||t.pending,title:m?`Resume without resending a prompt`:`Select this session to resume it`,onClick:()=>void b(t.resume),children:`Resume`}),h&&(0,Y.jsx)(`small`,{children:`Stop before changing session metadata.`})]})]},`${t.selectedId}:${e.sessionId}`),s&&(0,Y.jsx)(`span`,{className:`code-session-view-hint`,role:`status`,children:`Updating session…`}),l&&(0,Y.jsx)(`div`,{id:p,className:`code-session-list-error`,role:`alert`,children:l})]})}function vt({controller:e,newSessionShortcut:t=dt}){let[n,r]=(0,x.useState)(``),[i,a]=(0,x.useState)(!1),o=(0,x.useRef)(null);function s(){if(i){a(!1),r(``);return}a(!0),queueMicrotask(()=>o.current?.focus())}let c=(0,x.useId)(),[l,u]=(0,x.useState)(pt);function d(e){u(e);try{localStorage.setItem(ft,e)}catch{}}let[f,p]=(0,x.useState)(null),[m,h]=(0,x.useState)(!1),g=(0,x.useRef)(!1),_=e.sessions.filter(e=>`${e.title??``} ${e.cwd} ${H[e.provider]}`.toLowerCase().includes(n.toLowerCase())),y=e.sessions.some(t=>t.sessionId!==e.selectedId&&it(t)),b=_.filter(e=>e.archivedAt===null),S=_.filter(e=>e.archivedAt!==null),C=l===`activity`?lt(b,Date.now(),e.selectedId).map(e=>({key:e.bucket,title:st[e.bucket],cwd:null,sessions:e.sessions})):at(b).map(e=>({key:e.cwd,title:e.cwd,cwd:e.cwd,sessions:e.sessions}));S.length&&C.push({key:`archived`,title:`Archived`,cwd:null,sessions:tt(S).flatMap(e=>e.sessions)});let w=e.newSession;(0,x.useEffect)(()=>{function e(e){e.detail===`newCodeSession`&&w()}return document.addEventListener(`jaw:shortcut-action`,e),()=>document.removeEventListener(`jaw:shortcut-action`,e)},[w]);async function T(t){if(e.newSession(),e.hasUnsentDraft){p(`Send or clear the current draft before choosing another workspace.`);return}if(e.selectedId===null&&e.pending){p(`Wait for the current change to finish before choosing another workspace.`);return}p(null);try{await e.setSelection({cwd:t})}catch(e){p(e instanceof Error?e.message:String(e))}}async function E(){if(!g.current){g.current=!0,h(!0),p(null);try{await e.loadMoreSessions()}catch(e){p(e instanceof Error?e.message:String(e))}finally{g.current=!1,h(!1)}}}return(0,Y.jsxs)(`nav`,{className:`code-session-list`,"aria-label":`Code sessions`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`code-session-new-primary${e.selectedId===null?` active`:``}`,"aria-current":e.selectedId===null?`true`:void 0,"aria-label":`New Code session`,"aria-describedby":e.hasUnsentDraft?c:void 0,title:`Start a new session (${v(t)})`,onClick:e.newSession,children:[(0,Y.jsx)(gt,{}),(0,Y.jsx)(`span`,{className:`code-session-new-label`,children:`New session`}),e.hasUnsentDraft&&(0,Y.jsx)(`span`,{id:c,className:`code-session-draft-badge`,children:`Draft`}),(0,Y.jsx)(`kbd`,{className:`code-session-new-hint`,"aria-hidden":`true`,children:v(t)})]}),(0,Y.jsxs)(`div`,{className:`code-session-list-header`,children:[(0,Y.jsx)(`span`,{className:`code-session-list-title`,children:l===`activity`?`Recent activity`:`Projects`}),(0,Y.jsxs)(`span`,{className:`code-session-header-actions`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`code-session-header-btn code-session-search-btn${i?` active`:``}`,"aria-pressed":i,"aria-label":`Search sessions`,title:`Search sessions`,onClick:s,children:(0,Y.jsx)(ht,{})}),(0,Y.jsxs)(`button`,{type:`button`,className:`code-session-header-btn code-session-bell${l===`activity`?` active`:``}`,"aria-pressed":l===`activity`,"aria-label":y?`Recent activity (unread sessions)`:`Recent activity`,title:l===`activity`?`Back to projects`:`Recent activity`,onClick:()=>d(l===`activity`?`projects`:`activity`),children:[(0,Y.jsx)(mt,{}),y&&(0,Y.jsx)(`span`,{className:`code-session-unread-dot`,"aria-hidden":`true`})]})]})]}),i&&(0,Y.jsxs)(`div`,{className:`code-session-search-row`,children:[(0,Y.jsx)(`input`,{ref:o,className:`code-session-search`,type:`search`,"aria-label":`Search loaded sessions`,placeholder:`Search sessions…`,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),s())}}),(0,Y.jsx)(`button`,{type:`button`,className:`code-session-archived-btn${e.filter.archived?` active`:``}`,"aria-pressed":e.filter.archived,title:`Include archived sessions`,onClick:()=>e.setFilter({...e.filter,archived:!e.filter.archived}),children:`Archived`})]}),e.loading&&(0,Y.jsx)(`div`,{className:`code-session-list-loading`,role:`status`,children:`Loading sessions…`}),C.map(t=>(0,Y.jsxs)(`section`,{className:`code-session-group`,children:[t.title&&(0,Y.jsxs)(`h3`,{className:`code-session-group-title${t.key===`priority`?` code-session-group-priority`:``}`,title:t.title,children:[(0,Y.jsx)(`span`,{children:t.cwd===null?t.title:ut(t.cwd)}),t.cwd!==null&&(0,Y.jsx)(`button`,{type:`button`,className:`code-session-group-new`,"aria-label":`New session in ${t.cwd}`,title:`New session in ${t.cwd}`,onClick:()=>void T(t.cwd),children:`+`})]}),(0,Y.jsx)(`ul`,{className:`code-session-list-items`,children:t.sessions.map(t=>(0,Y.jsx)(_t,{session:t,controller:e,view:l},t.sessionId))})]},t.key)),!e.loading&&!_.length&&(0,Y.jsx)(`p`,{className:`code-session-list-empty`,children:n?`No loaded sessions match. Clear search or load more.`:`No sessions here. Start a new session above.`}),e.hasMoreSessions&&(0,Y.jsx)(`button`,{type:`button`,className:`code-inline-action`,disabled:m,onClick:()=>void E(),children:m?`Loading…`:`Load more sessions`}),(0,Y.jsx)(`button`,{type:`button`,className:`code-inline-action`,onClick:()=>{p(null),e.refresh().catch(e=>p(e instanceof Error?e.message:String(e)))},children:`Refresh sessions`}),f&&(0,Y.jsx)(`div`,{className:`code-session-list-error`,role:`alert`,children:f})]})}var yt={"codex-app":{viewBox:`0 0 24 24`,rule:`evenodd`,d:`M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z`},claude:{viewBox:`0 0 24 24`,rule:`evenodd`,d:`M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z`},cursor:{viewBox:`675 357 250 286`,d:`M920.015 424.958L805.919 359.086C802.256 356.97 797.735 356.97 794.071 359.086L679.981 424.958C676.901 426.736 675 430.025 675 433.587V566.419C675 569.981 676.901 573.269 679.981 575.048L794.077 640.92C797.74 643.036 802.261 643.036 805.925 640.92L920.02 575.048C923.1 573.269 925.001 569.981 925.001 566.419V433.587C925.001 430.025 923.1 426.736 920.02 424.958H920.015ZM912.848 438.911L802.706 629.682C801.961 630.968 799.995 630.443 799.995 628.954V504.039C799.995 501.543 798.662 499.234 796.498 497.981L688.321 435.526C687.036 434.781 687.561 432.816 689.05 432.816H909.334C912.462 432.816 914.417 436.206 912.853 438.917H912.848V438.911Z`},grok:{viewBox:`0 0 24 24`,rule:`evenodd`,d:`M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815`}};function bt({provider:e}){let t=yt[e];return(0,Y.jsx)(`svg`,{className:`code-provider-glyph`,viewBox:t.viewBox,width:`16`,height:`16`,"aria-hidden":`true`,focusable:`false`,fill:`currentColor`,...t.rule?{fillRule:`evenodd`,clipRule:`evenodd`}:{},children:(0,Y.jsx)(`path`,{d:t.d})})}function xt(){return(0,Y.jsx)(`svg`,{viewBox:`0 0 20 20`,width:`16`,height:`16`,"aria-hidden":`true`,focusable:`false`,children:(0,Y.jsx)(`path`,{d:`M10 16V4.6M5.2 9.4 10 4.4l4.8 5`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`,strokeLinejoin:`round`})})}function St(){return(0,Y.jsx)(`svg`,{viewBox:`0 0 20 20`,width:`16`,height:`16`,"aria-hidden":`true`,focusable:`false`,children:(0,Y.jsx)(`rect`,{x:`6`,y:`6`,width:`8`,height:`8`,rx:`1.6`,fill:`currentColor`})})}function Ct({muted:e}){return(0,Y.jsxs)(`svg`,{viewBox:`0 0 20 20`,width:`16`,height:`16`,"aria-hidden":`true`,focusable:`false`,children:[(0,Y.jsx)(`path`,{d:`M10 3.6a2 2 0 0 1 2 2v4.2a2 2 0 0 1-4 0V5.6a2 2 0 0 1 2-2ZM5.4 9.6a4.6 4.6 0 0 0 9.2 0M10 14.4V16.4`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`}),e&&(0,Y.jsx)(`path`,{d:`M4.6 4.6 15.4 15.4`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`})]})}function wt(){return(0,Y.jsx)(`svg`,{className:`code-footer-check`,viewBox:`0 0 20 20`,width:`16`,height:`16`,"aria-hidden":`true`,focusable:`false`,children:(0,Y.jsx)(`path`,{d:`m4.8 10.4 3.3 3.3 7.1-7.4`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`})})}function Tt(){if(typeof MediaRecorder>`u`)return``;for(let e of[`audio/webm;codecs=opus`,`audio/mp4`,`audio/ogg;codecs=opus`])if(MediaRecorder.isTypeSupported(e))return e;return``}function Et(e){return e.includes(`mp4`)?`.mp4`:e.includes(`ogg`)?`.ogg`:`.webm`}function X(e){let t=e?.name;return t===`NotAllowedError`?`Microphone access was denied.`:t===`NotFoundError`?`No microphone was found.`:t===`NotReadableError`||t===`AbortError`?`The microphone is in use by another application.`:e instanceof Error?e.message:`Dictation failed.`}function Dt(e,t){let[n,r]=(0,x.useState)(`unsupported`),[i,a]=(0,x.useState)(null),o=(0,x.useRef)(null),s=(0,x.useRef)(null),c=(0,x.useRef)([]),l=(0,x.useRef)(!0);(0,x.useEffect)(()=>{let e=typeof MediaRecorder<`u`&&typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia;return r(e?`idle`:`unsupported`),()=>{l.current=!1,o.current?.state===`recording`&&o.current.stop(),s.current?.getTracks().forEach(e=>e.stop())}},[]);let u=(0,x.useCallback)(async(t,n)=>{r(`transcribing`);try{let r=await fetch(`/api/voice`,{method:`POST`,headers:{"Content-Type":n||`audio/webm`,"X-Voice-Ext":Et(n),"X-Stt-Only":`true`},body:t}),i=await r.json().catch(()=>null);if(!r.ok)throw Error(i?.error||`Transcription failed (${r.status}).`);let o=i?.text?.trim();if(!l.current)return;o?e(o):a(`Nothing was transcribed.`)}catch(e){l.current&&a(X(e))}finally{l.current&&r(`idle`)}},[e]),d=(0,x.useCallback)(()=>{if(!(n===`unsupported`||n===`transcribing`||t)){if(n===`recording`){o.current?.stop();return}a(null),(async()=>{let e;try{e=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){a(X(e));return}if(!l.current){e.getTracks().forEach(e=>e.stop());return}s.current=e;let t=Tt(),n;try{n=new MediaRecorder(e,t?{mimeType:t}:{})}catch(t){e.getTracks().forEach(e=>e.stop()),a(X(t));return}o.current=n,c.current=[],n.ondataavailable=e=>{e.data.size>0&&c.current.push(e.data)},n.onerror=()=>{a(`Recording failed.`)},n.onstop=()=>{e.getTracks().forEach(e=>e.stop()),s.current=null,o.current=null;let n=new Blob(c.current,{type:t||`audio/webm`});if(c.current=[],l.current){if(n.size===0){r(`idle`),a(`Nothing was recorded.`);return}u(n,t)}},n.start(),r(`recording`)})()}},[t,n,u]);return{status:n,reason:n===`unsupported`?`Dictation needs microphone access, which this browser context does not provide.`:n===`recording`?`Stop dictation`:n===`transcribing`?`Transcribing…`:`Dictation`,error:i,toggle:d}}function Ot(e){let t=(0,x.useRef)(!1),n=(0,x.useRef)(!1),r=(0,x.useRef)(!1),[i,a]=(0,x.useState)(null),o=Dt((0,x.useCallback)(t=>{let n=e.inputText;e.onInputChange(n?`${n.replace(/\s+$/,``)} ${t}`:t)},[e.inputText,e.onInputChange]),e.readOnly);async function s(){if(e.canSend&&e.inputText.trim()&&!n.current){n.current=!0,a(null);try{await e.onSubmit()}catch(e){a(e instanceof Error?e.message:String(e))}finally{n.current=!1}}}async function c(){if(e.canStop&&!r.current){r.current=!0,a(null);try{await e.onStop()}catch(e){a(e instanceof Error?e.message:String(e))}finally{r.current=!1}}}function l(e){e.nativeEvent.isComposing||t.current||e.nativeEvent.keyCode===229||e.key===`Enter`&&!e.shiftKey&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&(e.preventDefault(),s())}return(0,Y.jsxs)(`div`,{className:`code-composer`,children:[(0,Y.jsxs)(`div`,{className:`code-composer-input-shell`,children:[(0,Y.jsx)(`textarea`,{className:`code-composer-input`,"aria-label":`Code prompt`,value:e.inputText,autoFocus:e.autoFocus,onChange:t=>e.onInputChange(t.target.value),onKeyDown:l,onCompositionStart:()=>{t.current=!0},onCompositionEnd:()=>{t.current=!1},placeholder:e.followUpSent?`This turn already has its follow-up. Draft the next message…`:e.followUp?`Send a follow-up while this turn runs…`:e.busy?`Draft a follow-up while this turn runs…`:`Describe a task or ask a question…`,rows:2,readOnly:e.readOnly}),(0,Y.jsx)(`span`,{className:`code-composer-hint`,children:`Enter to send · Shift+Enter for a new line`})]}),(0,Y.jsxs)(`div`,{className:`code-composer-actions`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`code-composer-icon-button${o.status===`recording`?` is-recording`:``}`,"aria-label":o.status===`recording`?`Stop dictation`:`Dictation`,"aria-pressed":o.status===`recording`,disabled:o.status===`unsupported`||o.status===`transcribing`||e.readOnly,title:o.reason,onClick:o.toggle,children:(0,Y.jsx)(Ct,{muted:o.status===`unsupported`})}),e.busy&&(0,Y.jsx)(`button`,{type:`button`,className:`code-composer-send code-composer-stop`,"aria-label":`Stop current turn`,title:e.stopping?`Stopping`:`Stop current turn`,disabled:!e.canStop||e.stopping,onClick:()=>void c(),children:(0,Y.jsx)(St,{})}),(!e.busy||e.followUp)&&(0,Y.jsx)(`button`,{type:`button`,className:`code-composer-send`,"aria-label":e.busy?`Send follow-up`:`Send prompt`,title:e.steering?`Sending follow-up`:e.pending?`Sending`:e.busy?`Send follow-up`:`Send prompt`,disabled:!e.canSend||!e.inputText.trim(),onClick:()=>void s(),children:(0,Y.jsx)(xt,{})})]}),(e.stopping||e.steering||e.pending||o.status===`recording`||o.status===`transcribing`)&&(0,Y.jsx)(`span`,{className:`code-composer-status`,role:`status`,children:e.stopping?`Stopping…`:e.steering?`Sending follow-up…`:e.pending?e.pendingLabel??`Sending…`:o.status===`recording`?`Recording…`:`Transcribing…`}),(i||o.error)&&(0,Y.jsx)(`div`,{className:`code-action-error`,role:`alert`,children:i??o.error})]})}function kt(e){if(!e||!Number.isFinite(e.totalTokens)||e.totalTokens<0)return{state:`hidden`};let t=e.modelContextWindow;if(t===null||!Number.isFinite(t)||t<=0)return{state:`counted`,usedTokens:e.totalTokens};let n=Math.round(e.totalTokens/t*100);return{state:`measured`,usedTokens:e.totalTokens,maxTokens:t,percent:Math.min(100,n),over:n>100}}function At(e,t){let n=e/t;return n<10?n.toFixed(1):String(Math.round(n))}function Z(e){if(!Number.isFinite(e)||e<0)return`—`;let t=Math.round(e);if(t<1e3)return String(t);let n=At(t,1e3);return Number(n)<1e3?`${n}k`:`${At(t,1e6)}M`}function jt(e){return e===null||!Number.isFinite(e)||e<0?`—`:e.toLocaleString(`en-US`)}function Q(e){return e===null?`—`:Z(e)}function Mt(e){return e>=90?`critical`:e>=75?`high`:`normal`}function Nt(e){return e.state===`hidden`?``:e.state===`counted`?`Context: ${Z(e.usedTokens)} tokens used, window unknown`:e.over?`Context: over the window, ${Z(e.usedTokens)} of ${Z(e.maxTokens)} tokens`:`Context: ${e.percent}% used, ${Z(e.usedTokens)} of ${Z(e.maxTokens)} tokens`}function Pt({usage:e}){let t=kt(e),[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(!1),o=n||i,s=(0,x.useId)();if(t.state===`hidden`)return null;let c=Nt(t),l=t.state===`measured`?t.over?`critical`:Mt(t.percent):`normal`,u=2*Math.PI*7,d=t.state===`measured`?t.percent/100*u:0;return(0,Y.jsxs)(`div`,{className:`code-context-usage`,onPointerEnter:()=>r(!0),onPointerLeave:()=>r(!1),children:[(0,Y.jsxs)(`button`,{type:`button`,className:`code-context-trigger is-${l}`,"aria-label":c,"aria-describedby":o?s:void 0,onFocus:()=>a(!0),onBlur:()=>a(!1),children:[t.state===`measured`?(0,Y.jsxs)(`svg`,{className:`code-context-ring`,viewBox:`0 0 18 18`,"aria-hidden":`true`,children:[(0,Y.jsx)(`circle`,{className:`code-context-ring-track`,cx:`9`,cy:`9`,r:`7`}),(0,Y.jsx)(`circle`,{className:`code-context-ring-fill`,cx:`9`,cy:`9`,r:`7`,strokeDasharray:`${d} ${u}`})]}):null,(0,Y.jsx)(`span`,{className:`code-context-value`,children:t.state===`measured`?t.over?`over`:`${t.percent}%`:Z(t.usedTokens)})]}),o&&(0,Y.jsxs)(`div`,{id:s,className:`code-context-detail`,role:`note`,children:[(0,Y.jsx)(`p`,{className:`code-context-detail-total`,children:t.state===`measured`?`${Z(t.usedTokens)} of ${Z(t.maxTokens)} tokens`:`${Z(t.usedTokens)} tokens used`}),t.state===`measured`&&t.over&&(0,Y.jsx)(`p`,{className:`code-context-detail-note`,children:`Past the window the runtime last reported.`}),t.state===`counted`&&(0,Y.jsx)(`p`,{className:`code-context-detail-note`,children:`This runtime did not report a context window.`}),(0,Y.jsxs)(`dl`,{className:`code-context-breakdown`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{children:`Used`}),(0,Y.jsx)(`dd`,{children:jt(e?.totalTokens??null)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{children:`Input`}),(0,Y.jsx)(`dd`,{children:Q(e?.inputTokens??null)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{children:`Cached`}),(0,Y.jsx)(`dd`,{children:Q(e?.cachedInputTokens??null)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{children:`Output`}),(0,Y.jsx)(`dd`,{children:Q(e?.outputTokens??null)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`dt`,{children:`Reasoning`}),(0,Y.jsx)(`dd`,{children:Q(e?.reasoningOutputTokens??null)})]})]}),e?.processedTokens!=null&&(0,Y.jsxs)(`p`,{className:`code-context-detail-note`,children:[`Processed across the conversation: `,Z(e.processedTokens)]})]})]})}function $({label:e,value:t,options:n,disabled:r,onChange:i,displayValue:a,triggerContent:o,filterable:s,filterPlaceholder:c,className:l,title:u}){let d=(0,x.useId)(),f=(0,x.useRef)(null),p=(0,x.useRef)(null),m=(0,x.useRef)(null),[h,g]=(0,x.useState)(null),[_,v]=(0,x.useState)(``),y=n.find(e=>e.value===t),b=(0,x.useMemo)(()=>{let e=_.trim().toLowerCase();return!s||!e?n:n.filter(t=>t.value.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))},[s,n,_]);function C(e=!0){g(null),v(``),e&&f.current?.focus()}function w(){let e=f.current?.getBoundingClientRect();if(!e||r)return;let t=Math.max(192,Math.min(s?340:260,window.innerWidth-28)),n=Math.max(0,e.top-16),i=Math.max(0,window.innerHeight-e.bottom-16),a={left:Math.max(14,Math.min(e.left,window.innerWidth-t-14)),width:t};g(n>=i?{...a,bottom:window.innerHeight-e.top+8,maxHeight:Math.min(288,n)}:{...a,bottom:`auto`,top:e.bottom+8,maxHeight:Math.min(288,i)})}(0,x.useEffect)(()=>{if(!h)return;if(s)m.current?.focus();else{let e=p.current?.querySelectorAll(`button:not(:disabled)`);([...e??[]].find(e=>e.getAttribute(`aria-selected`)===`true`)??e?.[0])?.focus()}let e=e=>{!p.current?.contains(e.target)&&!f.current?.contains(e.target)&&C(!1)},t=()=>C(!1);return document.addEventListener(`pointerdown`,e),window.addEventListener(`resize`,t),()=>{document.removeEventListener(`pointerdown`,e),window.removeEventListener(`resize`,t)}},[h,s]),(0,x.useEffect)(()=>{r&&(g(null),v(``))},[r]);function T(e){if(e.key===`Escape`){e.preventDefault(),C();return}if(e.key===`Tab`){C(!1);return}let t=[...p.current?.querySelectorAll(`button:not(:disabled)`)??[]];if(t.length===0)return;let n=t.findIndex(e=>e===document.activeElement),r;if(e.key===`ArrowDown`)r=(n+1)%t.length;else if(e.key===`ArrowUp`)r=(n-1+t.length)%t.length;else if(e.key===`Home`)r=0;else if(e.key===`End`)r=t.length-1;else return;e.preventDefault(),t[r]?.focus()}let E=`${e}: ${y?.label??a??(t||`not selected`)}`;return(0,Y.jsxs)(`div`,{className:`code-footer-menu${l?` ${l}`:``}`,children:[(0,Y.jsx)(`button`,{ref:f,type:`button`,className:`code-footer-menu-trigger${o?` is-icon`:``}`,"aria-label":E,"aria-haspopup":`listbox`,"aria-expanded":!!h,"aria-controls":h?d:void 0,disabled:r,title:u??y?.detail??E,onClick:()=>h?C():w(),onKeyDown:e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),w())},children:o??(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`code-footer-label`,children:e}),(0,Y.jsx)(`strong`,{children:y?.label??a??(t||`Not selected`)})]})}),h&&(0,S.createPortal)((0,Y.jsxs)(`div`,{ref:p,id:d,role:`listbox`,"aria-label":e,className:`code-footer-dropup code-footer-floating`,style:h,onKeyDown:T,children:[s&&(0,Y.jsx)(`input`,{ref:m,type:`text`,className:`code-footer-filter`,value:_,"aria-label":`Filter ${e.toLowerCase()}`,placeholder:c??`Filter…`,onChange:e=>v(e.target.value)}),(0,Y.jsxs)(`div`,{className:`code-footer-dropup-list`,children:[b.map(e=>(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":e.value===t,disabled:e.disabled,className:`code-footer-dropup-option`,title:e.detail??e.label,onClick:()=>{i(e.value),C()},children:[e.icon&&(0,Y.jsx)(`span`,{className:`code-footer-option-icon`,children:e.icon}),(0,Y.jsxs)(`span`,{className:`code-footer-option-text`,children:[(0,Y.jsx)(`strong`,{children:e.label}),e.detail&&(0,Y.jsx)(`small`,{children:e.detail})]}),e.value===t&&(0,Y.jsx)(wt,{})]},e.value)),b.length===0&&(0,Y.jsxs)(`p`,{className:`code-footer-dropup-empty`,role:`note`,children:[`No match for “`,_.trim(),`”.`]})]})]}),document.body)]})}function Ft({controller:e,onNotice:t}){let n=e.selection,r=e.catalog?.providers.find(e=>e.id===n.provider),i=e.session?.capabilities??r?.capabilities,a=(n.provider===`claude`?r?.capabilities:i)?.permissionModes??[],o=e.selectedId!==null,s=e.pending||e.busy||e.creationUnknown||e.operation.kind!==`idle`||o&&(!e.synced||e.session?.status!==`idle`||e.session?.archivedAt!==null),[c,l]=(0,x.useState)(!1),[u,d]=(0,x.useState)(null),f=(0,x.useRef)(!1),p=(0,x.useRef)(t);p.current=t,(0,x.useEffect)(()=>{if(n.permissionMode!==`auto`){p.current?.({id:`code:permission-mode`,clear:!0});return}p.current?.({id:`code:permission-mode`,variant:`warning`,message:`Auto (YOLO): actions may run without approval.`,durationMs:1/0})},[n.permissionMode]);async function m(t){if(!(s||f.current)){f.current=!0,l(!0),d(null);try{await e.setSelection(t)}catch(e){d(e instanceof Error?e.message:String(e))}finally{f.current=!1,l(!1)}}}let h=s||c,g=r?.effortsByModel?.[n.model]??i?.efforts??[],_=e.session?.capabilities.efforts,v=_?g.filter(e=>_.includes(e)):g,y=r?.models??[];return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`code-composer-footer`,children:[(0,Y.jsx)($,{label:`Runtime`,value:n.provider,className:`code-footer-runtime`,disabled:o?!e.catalog:h||!e.catalog,triggerContent:(0,Y.jsx)(bt,{provider:n.provider}),title:H[n.provider],options:Object.keys(H).map(t=>{let r=e.catalog?.providers.find(e=>e.id===t);return{value:t,label:o&&t!==n.provider?`New ${H[t]} session`:H[t],disabled:!r?.available||o&&t===n.provider,icon:(0,Y.jsx)(bt,{provider:t}),detail:r?.reason??(r?.available?void 0:`Availability unknown`)}}),onChange:t=>{o?e.setSelection({provider:t}).catch(e=>d(e instanceof Error?e.message:String(e))):m({provider:t})}}),(0,Y.jsx)($,{label:`Permission`,value:n.permissionMode,displayValue:be[n.permissionMode],disabled:h||!i?.permissions,options:a.map(e=>({value:e,label:be[e],detail:xe[e]})),onChange:e=>void m({permissionMode:e})}),(0,Y.jsx)(`span`,{className:`code-composer-footer-spacer`,"aria-hidden":`true`}),(0,Y.jsx)(Pt,{usage:e.session?.contextUsage}),(0,Y.jsx)($,{label:`Model`,value:n.model,className:`code-footer-model`,disabled:h||y.length===0,filterable:!0,filterPlaceholder:`Filter models…`,displayValue:n.model||`Select model`,options:y.map(e=>({value:e,label:e})),onChange:e=>void m({model:e})}),v.length>0&&(0,Y.jsx)($,{label:`Effort`,value:n.effort??``,className:`code-footer-effort`,displayValue:n.effort??`Default`,options:[{value:``,label:`Native default`},...v.map(e=>({value:e,label:e}))],disabled:h,onChange:e=>void m({effort:e||null})}),n.provider===`claude`&&(0,Y.jsx)($,{label:`Thinking`,value:n.thinking===!1?`off`:`on`,className:`code-footer-thinking`,options:[{value:`on`,label:`Thinking on`,detail:`Adaptive thinking with summaries`},{value:`off`,label:`Thinking off`,detail:`Answer without extended thinking`}],disabled:h,onChange:e=>void m({thinking:e===`on`})}),o&&(0,Y.jsx)(`button`,{type:`button`,className:`code-inline-action`,onClick:e.newSession,children:`New session`})]}),y.length===0&&r?.available&&(0,Y.jsxs)(`div`,{className:`code-selection-notice`,children:[`This runtime published no models.`,(0,Y.jsx)(`button`,{type:`button`,className:`code-inline-action`,onClick:()=>{e.refresh().catch(e=>d(e instanceof Error?e.message:String(e)))},children:`Refresh catalog`})]}),!r?.available&&(0,Y.jsxs)(`div`,{className:`code-selection-notice`,children:[r?.reason??`Runtime availability has not been confirmed.`,(0,Y.jsx)(`button`,{type:`button`,className:`code-inline-action`,onClick:()=>{e.refresh().catch(e=>d(e instanceof Error?e.message:String(e)))},children:`Refresh availability`})]}),(c||e.operation.kind===`patching`)&&(0,Y.jsx)(`span`,{role:`status`,children:`Saving settings…`}),u&&(0,Y.jsx)(`div`,{className:`code-action-error`,role:`alert`,children:u})]})}function It(e,t=5){let n=new Set,r=[],i=[...e].sort((e,t)=>t.lastUsedAt-e.lastUsedAt||t.createdAt-e.createdAt||e.sessionId.localeCompare(t.sessionId));for(let e of i){let i=e.cwd;if(i.trim()&&!n.has(i)&&(n.add(i),r.push(i),r.length>=t))break}return r}var Lt=[`Explain this codebase`,`Find and fix a bug`,`Write tests for the module I name`,`Review uncommitted changes`];function Rt(){document.querySelector(`textarea[aria-label="Code prompt"]`)?.focus()}function zt({controller:e}){let t=e.selection.cwd,n=e.selectedId!==null||e.pending||e.creationUnknown||e.operation.kind!==`idle`,r=e.workspacePicking,i=It(e.sessions.filter(e=>e.cwd!==t));function a(){n||r||e.pickWorkspace()}function o(t){n||(e.setSelection({cwd:t}),Rt())}return(0,Y.jsxs)(`section`,{className:`code-draft-empty`,"aria-label":`New session draft`,children:[(0,Y.jsx)(`h2`,{className:`code-draft-empty-title`,children:`New session`}),n?(0,Y.jsx)(`span`,{className:`code-workspace-chip`,title:t,children:t||`Workspace not set`}):(0,Y.jsx)(`button`,{type:`button`,className:`code-workspace-picker code-draft-empty-picker`,"aria-label":`Choose workspace for the new session`,disabled:r,title:t||`Choose a folder`,onClick:a,children:(0,Y.jsx)(`span`,{className:`code-workspace-picker-label`,children:r?`Choosing folder…`:t||`Choose workspace`})}),(0,Y.jsxs)(`p`,{className:`code-draft-empty-selection`,children:[H[e.selection.provider],` · `,e.selection.model||`No model selected`]}),i.length>0&&(0,Y.jsxs)(`div`,{className:`code-draft-recents`,children:[(0,Y.jsx)(`span`,{className:`code-draft-recents-label`,children:`Recent workspaces`}),i.map(e=>(0,Y.jsx)(`button`,{type:`button`,className:`code-draft-recent`,title:e,disabled:n,onClick:()=>o(e),children:e},e))]}),!e.input.trim()&&(0,Y.jsx)(`div`,{className:`code-draft-prompts`,children:Lt.map(t=>(0,Y.jsx)(`button`,{type:`button`,className:`code-draft-prompt`,disabled:n,onClick:()=>{e.setInput(t),Rt()},children:t},t))})]})}function Bt({permission:e,operation:t,eligible:n,onAnswer:r}){let i=(0,x.useRef)(!1),[a,o]=(0,x.useState)(!1),[s,c]=(0,x.useState)(null);async function l(a){if(!(!n||i.current||t?.pending)){i.current=!0,o(!0),c(null);try{await r(e,a)}catch(e){c(e instanceof Error?e.message:String(e))}finally{i.current=!1,o(!1)}}}return(0,Y.jsxs)(`section`,{className:`code-permission-card`,"aria-label":e.title,children:[(0,Y.jsxs)(`div`,{className:`code-permission-title`,children:[(0,Y.jsx)(`strong`,{children:e.title}),(0,Y.jsx)(`p`,{children:e.detail}),!n&&(0,Y.jsx)(`small`,{children:`Updating permission availability…`}),(a||t?.pending)&&(0,Y.jsx)(`small`,{role:`status`,children:`Checking decision…`}),(t?.error||s)&&(0,Y.jsx)(`div`,{className:`code-action-error`,role:`alert`,children:t?.error||s})]}),(0,Y.jsxs)(`div`,{className:`code-permission-actions`,children:[e.options.map(e=>(0,Y.jsx)(`button`,{type:`button`,className:`code-permission-btn`,disabled:!n||a||t?.pending,onClick:()=>void l(e.optionId),children:e.label},e.optionId)),e.options.length===0&&(0,Y.jsx)(`span`,{children:`No native actions available. Refresh this session.`})]})]})}function Vt({permissions:e,operations:t,session:n,synced:r,onAnswer:i}){return e.length?(0,Y.jsxs)(`aside`,{className:`code-permissions`,"aria-label":`Pending permissions`,tabIndex:-1,id:`code-pending-permissions`,children:[(0,Y.jsxs)(`div`,{className:`code-permissions-heading`,role:`status`,children:[e.length,` pending · `,n?H[n.provider]:`Session updating`]}),e.map(e=>(0,Y.jsx)(Bt,{permission:e,operation:t[e.permissionId],eligible:r&&n!==null&&n.archivedAt===null&&n.sessionId===e.sessionId&&n.turnId===e.turnId&&n.epoch===e.epoch&&(n.status===`starting`||n.status===`streaming`),onAnswer:i},`${e.sessionId}:${e.permissionId}`))]}):null}var Ht=92,Ut=6;function Wt(e){let[{virtualItems:t,totalSize:s},c]=(0,x.useState)({virtualItems:[],totalSize:0}),l=(0,x.useRef)(null);l.current||=new o({count:e.count,getScrollElement:()=>e.scrollElementRef.current,estimateSize:e.estimateSize||(()=>Ht),overscan:Ut,getItemKey:e.getItemKey,indexAttribute:`data-code-transcript-idx`,useAnimationFrameWithResizeObserver:!0,observeElementRect:n,observeElementOffset:r,scrollToFn:i,measureElement:a,onChange:e=>{c({virtualItems:e.getVirtualItems(),totalSize:e.getTotalSize()})}});let u=l.current;return(0,x.useEffect)(()=>u._didMount(),[u]),(0,x.useEffect)(()=>{u.measure()},[u,e.resetKey]),(0,x.useEffect)(()=>()=>{l.current=null},[]),(0,x.useLayoutEffect)(()=>{u.setOptions({...u.options,count:e.count,getItemKey:e.getItemKey,estimateSize:e.estimateSize||(()=>Ht)}),u._willUpdate(),c({virtualItems:u.getVirtualItems(),totalSize:u.getTotalSize()})},[e.count,e.estimateSize,e.getItemKey,u]),{restoreAnchor:(e,t)=>{let n=u.getOffsetForIndex(e,`start`);n&&u.scrollToOffset(n[0]+t,{behavior:`auto`})},measureElement:e=>{e&&u.measureElement(e)},virtualItems:t,totalSize:s}}var Gt=64,Kt=64;function qt({items:e,sessionKey:t,transcriptRef:n,virtual:r}){let i=(0,x.useRef)(new Map),a=(0,x.useRef)(!0),[o,s]=(0,x.useState)(!1),c=(0,x.useRef)({sessionKey:``,firstId:``}),l=(0,x.useRef)({items:e,virtual:r,sessionKey:t});l.current={items:e,virtual:r,sessionKey:t};let u=(0,x.useCallback)(()=>{a.current=!0,s(!1);let e=n.current;e&&(e.scrollTop=e.scrollHeight)},[n]);return(0,x.useLayoutEffect)(()=>{let e=n.current;if(!e)return;let t=()=>{let t=l.current,n=t.virtual.virtualItems.find(t=>t.end>e.scrollTop),r={itemId:n?t.items[n.index]?.itemId??null:null,offset:n?e.scrollTop-n.start:0,following:a.current};if(i.current.delete(t.sessionKey),i.current.set(t.sessionKey,r),i.current.size>Gt){let e=i.current.keys().next().value;e!==void 0&&i.current.delete(e)}},r=()=>{l.current.items.length&&(a.current=e.scrollHeight-e.scrollTop-e.clientHeight<=Kt,s(!a.current),t())};return e.addEventListener(`scroll`,r,{passive:!0}),()=>e.removeEventListener(`scroll`,r)},[n]),(0,x.useLayoutEffect)(()=>{let o=n.current;if(!o)return;let l=e[0]?.itemId??``,u=c.current.sessionKey!==t,d=!u&&c.current.firstId!==l;c.current={sessionKey:t,firstId:l};let f=i.current.get(t);if(u&&(a.current=f?.following??!0,s(!a.current)),a.current){o.scrollTop=o.scrollHeight;return}if((u||d)&&f?.itemId){let t=e.findIndex(e=>e.itemId===f.itemId);t>=0&&r.restoreAnchor(t,f.offset)}},[e,t,n,r.totalSize]),{showJump:o,jumpToLatest:u}}var Jt=2e3,Yt=80,Xt=400;function Zt(e){return e<=Jt?Yt:Math.min(Xt,Math.round(Yt*e/Jt))}function Qt(e,t=!1,n=``){let[r,i]=(0,x.useState)({text:e,identity:n}),a=(0,x.useRef)(0),o=t||r.identity!==n||!e.startsWith(r.text);return(0,x.useEffect)(()=>{if(r.text===e&&r.identity===n)return;let t=()=>{a.current=Date.now(),i({text:e,identity:n})},s=Zt(e.length)-(Date.now()-a.current);if(o||s<=0){t();return}let c=window.setTimeout(t,s);return()=>window.clearTimeout(c)},[e,n,o,r]),o?e:r.text}var $t=[[/^(read|read_file|get_file|open_file|view|cat)$/i,`Read`,`Reading`],[/^(write|write_file|create_file|edit|edit_file|apply_patch|str_replace\w*|update_file)$/i,`Edit`,`Editing`],[/^(bash|shell|exec|exec_command|run|run_command|terminal)$/i,`Bash`,`Running`],[/^(search|grep|rg|ripgrep|glob|find|codebase_search)$/i,`Search`,`Searching`],[/^(fetch|browser\w*|web_\w*|open_url|http)$/i,`Open`,`Opening`],[/^(list|ls|list_dir|list_files)$/i,`List`,`Listing`]];function en(e){return e===`running`||e===`pending`}function tn(e,t){let n=e.trim();if(t&&n.startsWith(t)){let e=n.slice(t.length).replace(/^[\\/]+/,``);if(e)return e}if(n.length<=64)return n;let r=n.split(/[\\/]/).filter(Boolean);return r.length>2?`…/${r.slice(-2).join(`/`)}`:`…${n.slice(-60)}`}function nn(e){let t=(e.split(/\r?\n/).find(e=>e.trim())??``).replace(/\s+/g,` `).trim();return t.length>96?`${t.slice(0,95)}…`:t}function rn(e,t){if(!e)return``;let n=e.trim();if(!n)return``;let r=d(n);if(r){for(let e of f){let n=s(r,[e]);if(n!==null)return e===`path`||e===`file`||e===`file_path`?tn(n,t):nn(n)}return``}return n.includes(`/`)&&!n.includes(` `)?tn(n,t):nn(n)}function an(e){let t=p(e).description;return t===null?``:l(t)}function on(e){if(e===void 0)return null;let t=p(e),n=null;if(t.object&&t.field===`command`){let e=new Set([...u.command,...m]),r=Object.fromEntries(Object.entries(t.object).filter(([t])=>!e.has(t)));Object.keys(r).length&&(n=JSON.stringify(r,null,2))}let r=t.field===`command`&&t.value!==null;return{content:r?t.value:t.object?c(e):t.value??e,command:r,parameters:n,description:t.description}}function sn(e,t){let n=en(e.status);if(e.kind===`file_change`){let r=rn(e.tool?.input,t)||e.tool?.detail||``;return r?`${n?`Editing`:`Edit`} ${r}`:`File change`}let r=e.tool?.name?.trim()||`Tool`,i=$t.find(([e])=>e.test(r)),a=i?n?i[2]:i[1]:void 0,o=rn(e.tool?.input,t);return a?o?`${a} ${o}`:a:o?`${r} ${o}`:r}function cn(e){return e.kind===`turn_cancelled`||e.status===`cancelled`?`Stopped`:e.kind===`turn_failed`||e.status===`error`?`Failed`:e.status===`running`?`Running`:e.status===`pending`?`Pending`:null}var ln=(0,x.lazy)(()=>t(()=>import(`./MarkdownRenderer-Cc3DeHvm.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0]))),un=new Set([`turn_started`,`turn_completed`]),dn=44,fn=480,pn=64;function mn(e){return e.length>1400||e.split(`
3
- `).length>14}function hn(e,t,n){let r=e.get(`${t}:${n.itemId}`);return r===void 0?n.status===`error`&&n.kind!==`reasoning`:r}function gn({item:e,identity:t,onOpenLocalFile:n}){let r=Qt(e.text??``,e.status!==`running`&&e.status!==`pending`,t);return r.trim()?(0,Y.jsx)(x.Suspense,{fallback:(0,Y.jsx)(`span`,{className:`code-plain-text`,children:r}),children:(0,Y.jsx)(ln,{markdown:r,tableMode:`linear`,onLocalFileOpen:n})}):(0,Y.jsx)(`span`,{className:`code-plain-text`,children:r})}function _n({item:e,provider:t,sessionKey:n,workingDir:r=``,onOpenLocalFile:i,expanded:a,onExpandedChange:o,onRollback:s}){let c=e.kind===`tool_call`||e.kind===`file_change`,l=e.kind===`reasoning`,u=e.kind===`assistant_message`,d=e.kind===`user_message`,f=Ee(e),p=cn(e),m=e.itemId===Ie,h=a??(e.status===`error`&&e.kind!==`reasoning`),g=e.status===`running`||e.status===`pending`,_=g?null:p,v=c?an(e.tool?.input):``,y=c?on(e.tool?.input):null,S=[];c&&(y&&S.push({key:`input`,label:`Input`,content:y.content,className:`code-tool-args`,copyable:!0}),y?.parameters&&S.push({key:`params`,label:`Parameters`,content:y.parameters,className:`code-tool-json`,copyable:!1}),y?.description&&S.push({key:`description`,label:`Description`,content:y.description,className:`code-tool-text`,copyable:!1}),e.tool?.output!==void 0&&S.push({key:`output`,label:`Output`,content:e.tool.output,className:`code-tool-output`,copyable:!1}));let C=S.some(e=>mn(e.content))||e.tool?.detail!==void 0&&mn(e.tool.detail)||e.text!==void 0&&mn(e.text),[w,T]=(0,x.useState)(!1),E=(0,x.useRef)(null),[D,O]=(0,x.useState)(null);(0,x.useEffect)(()=>{O(null)},[C]),(0,x.useEffect)(()=>{if(!h||w)return;let e=E.current?.querySelectorAll(`pre, .code-tool-body > .code-tool-text`);if(!e||e.length===0){O(null);return}let t=[...e],n=t.some(e=>e.scrollHeight>e.clientHeight+2);O(n||t.every(e=>e.scrollHeight===0)&&C)},[h,w,C]);let k=D??C;(0,x.useEffect)(()=>{k||T(!1)},[k]);let[A,j]=(0,x.useState)(!1),M=(0,x.useRef)(null);(0,x.useEffect)(()=>()=>{M.current!==null&&window.clearTimeout(M.current)},[]);let N=(0,x.useCallback)(()=>{j(!0),M.current!==null&&window.clearTimeout(M.current),M.current=window.setTimeout(()=>{M.current=null,j(!1)},1200)},[]),P=d?`You`:u?H[t]:l?`Reasoning`:e.kind===`turn_started`?`Turn started`:e.kind===`session_runtime`?`Runtime`:e.kind===`permission_request`?`Permission record`:e.kind===`notice`?`Notice`:f;return(0,Y.jsxs)(`article`,{className:`code-message code-message-${c?`tool`:u?`assistant`:d?`user`:`system`} is-${e.status}${m?` is-unsent`:``}`,"data-code-item-id":e.itemId,"aria-label":`${P} · ${f}`,children:[c?(0,Y.jsxs)(`details`,{className:`code-tool-card code-tool-${e.status}`,open:h,onToggle:t=>o?.(e.itemId,t.currentTarget.open),children:[(0,Y.jsxs)(`summary`,{className:`code-tool-summary`,children:[(0,Y.jsx)(`span`,{className:`code-tool-chevron`,"aria-hidden":`true`,children:`›`}),(0,Y.jsxs)(`span`,{className:`code-tool-summary-text`,children:[(0,Y.jsx)(`span`,{className:`code-tool-name${g?` code-tool-name-running`:``}`,children:sn(e,r)}),v!==``&&(0,Y.jsx)(`span`,{className:`code-tool-desc`,children:v})]}),_&&(0,Y.jsx)(`span`,{className:`code-tool-status`,children:_})]}),h&&(0,Y.jsxs)(`div`,{ref:E,className:`code-tool-body`,"data-expanded":w,children:[e.tool?.detail!==void 0&&(0,Y.jsx)(`p`,{className:`code-tool-text`,children:e.tool.detail}),S.map(e=>(0,Y.jsxs)(`section`,{className:`code-tool-section`,children:[(0,Y.jsxs)(`div`,{className:`code-tool-section-head`,children:[(0,Y.jsx)(`span`,{className:`code-tool-section-label`,children:e.label}),e.copyable&&(0,Y.jsx)(`button`,{type:`button`,className:`code-tool-copy${A?` copied`:``}`,"aria-label":`Copy ${e.label.toLowerCase()}`,onClick:()=>void b(e.content).then(e=>{e.ok&&N()}),children:A?`Copied`:`Copy`})]}),(0,Y.jsx)(`pre`,{className:e.className,children:e.content})]},e.key)),e.text!==void 0&&(0,Y.jsx)(`pre`,{className:`code-tool-text`,children:e.text}),g&&e.tool?.output===void 0&&e.tool?.detail===void 0&&(0,Y.jsx)(`p`,{className:`code-tool-waiting`,children:`Waiting for output…`}),k&&(0,Y.jsx)(`button`,{type:`button`,className:`code-tool-toggle`,"aria-expanded":w,onClick:()=>T(e=>!e),children:w?`Show less`:`Show all`})]})]}):l?(0,Y.jsxs)(`details`,{className:`code-thinking`,open:h,onToggle:t=>o?.(e.itemId,t.currentTarget.open),children:[(0,Y.jsx)(`summary`,{className:`code-thinking-summary${e.status===`running`?` code-tool-name-running`:``}`,children:e.status===`running`?`Thinking…`:`Reasoning`}),h&&(0,Y.jsx)(`div`,{className:`code-thinking-text`,children:e.text})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`code-message-role`,children:[P,u&&e.phase===`commentary`?` · Commentary`:``,p&&` · ${m?`Sending`:p}`,d&&!m&&e.phase===`unknown`&&` · Delivery not confirmed`]}),(0,Y.jsx)(`div`,{className:`code-message-text`,children:u?(0,Y.jsx)(gn,{item:e,identity:`${n}:${e.itemId}`,onOpenLocalFile:i}):(0,Y.jsx)(`span`,{className:`code-plain-text`,children:e.text??e.permission?.title??``})}),e.permission?.detail&&(0,Y.jsx)(`p`,{className:`code-plain-text`,children:e.permission.detail}),s&&d&&!m&&(0,Y.jsx)(`button`,{type:`button`,className:`code-message-rollback`,onClick:()=>{window.confirm(`Later turns are removed from this conversation. Workspace files are not changed. No prompt is sent.`)&&s(e.itemId)},children:`Roll back conversation to here`})]}),(u||l)&&(e.status===`cancelled`||e.status===`error`)&&(0,Y.jsxs)(`span`,{className:`code-partial-label`,children:[`Partial output · `,f]}),e.truncation&&(0,Y.jsxs)(`p`,{className:`code-truncation`,role:`note`,children:[`Output truncated: `,e.truncation.storedChars.toLocaleString(),` of `,e.truncation.sourceChars.toLocaleString(),` characters retained.`]})]})}function vn({items:e,provider:t,sessionKey:n,workingDir:r,loading:i,hasOlderHistory:a,loadOlderHistory:o,permissionCount:s,onOpenLocalFile:c,working:l=!1,rollbackRows:u,onRollback:d}){let f=(0,x.useRef)(null),p=(0,x.useMemo)(()=>e.filter(e=>!un.has(e.kind)),[e]),m=(0,x.useRef)(p);m.current=p;let[h,g]=(0,x.useState)(()=>new Map),_=(0,x.useRef)(h);_.current=h;let[v,y]=(0,x.useState)(!1),[b,S]=(0,x.useState)(null),C=(0,x.useRef)(!1),w=p[0]?.itemId,T=(0,x.useCallback)(e=>{let t=m.current[e];return t?`${n}:${t.itemId}${hn(_.current,n,t)?`:open`:``}`:`${n}:${e}`},[n,w,h]),E=(0,x.useCallback)(e=>{let t=m.current[e];return t?.kind!==`tool_call`&&t?.kind!==`file_change`&&t?.kind!==`reasoning`?64+Math.min(420,(t?.text?.length??0)/6):t&&hn(h,n,t)?fn:dn},[h,n]),D=Wt({count:p.length,resetKey:n,scrollElementRef:f,getItemKey:T,estimateSize:E}),{showJump:O,jumpToLatest:k}=qt({items:p,sessionKey:n,transcriptRef:f,virtual:D}),A=(0,x.useCallback)((e,t)=>{let r=`${n}:${e}`;g(e=>{if(e.get(r)===t)return e;let n=new Map(e);if(n.delete(r),n.set(r,t),n.size>pn){let e=n.keys().next().value;e!==void 0&&n.delete(e)}return n})},[n]);async function j(){if(!C.current){C.current=!0,y(!0),S(null);try{await o()}catch(e){S({sessionKey:n,message:e instanceof Error?e.message:String(e)})}finally{C.current=!1,y(!1)}}}function M(e){if(e.target!==e.currentTarget||e.altKey||e.ctrlKey||e.metaKey)return;let t=f.current;if(!t)return;let n=Math.max(160,t.clientHeight*.78);[`j`,`d`,`PageDown`].includes(e.key)?(e.preventDefault(),t.scrollBy({top:n,behavior:`auto`})):[`k`,`u`,`PageUp`].includes(e.key)?(e.preventDefault(),t.scrollBy({top:-n,behavior:`auto`})):e.key===`End`?(e.preventDefault(),k()):e.key===`Home`&&(e.preventDefault(),t.scrollTo({top:0,behavior:`auto`}))}return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`code-transcript-controls`,children:[a&&(0,Y.jsx)(`button`,{type:`button`,disabled:v||i,onClick:()=>void j(),children:v?`Loading history…`:`Load older history`}),O&&(0,Y.jsx)(`button`,{type:`button`,onClick:k,children:`Jump to latest`}),s>0&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>document.getElementById(`code-pending-permissions`)?.focus(),children:[`Jump to permissions (`,s,`)`]}),b?.sessionKey===n&&(0,Y.jsx)(`span`,{className:`code-action-error`,role:`alert`,children:b.message})]}),(0,Y.jsxs)(`div`,{ref:f,className:`code-transcript`,role:`log`,"aria-label":`Code transcript`,"aria-live":`off`,tabIndex:0,onKeyDown:M,children:[p.length?(0,Y.jsx)(`div`,{className:`code-transcript-virtual-spacer`,style:{height:D.totalSize},children:D.virtualItems.map(e=>{let i=p[e.index];return i?(0,Y.jsx)(`div`,{ref:D.measureElement,className:`code-transcript-virtual-row`,"data-code-transcript-idx":e.index,style:{transform:`translateY(${e.start}px)`},children:(0,Y.jsx)(_n,{item:i,provider:t,sessionKey:n,workingDir:r,onOpenLocalFile:c,expanded:hn(h,n,i),onExpandedChange:A,onRollback:u?.has(i.itemId)?d:void 0})},e.key):null})}):(0,Y.jsxs)(`div`,{className:`code-transcript-empty`,children:[(0,Y.jsx)(`p`,{children:i?`Loading conversation…`:`Type a prompt below to start this conversation.`}),(0,Y.jsxs)(`p`,{className:`code-transcript-cwd`,children:[`Workspace: `,r||`not set`]})]}),l&&p[p.length-1]?.status!==`running`&&(0,Y.jsxs)(`div`,{className:`code-transcript-working`,role:`status`,"aria-live":`polite`,children:[(0,Y.jsx)(`span`,{className:`code-session-spinner`,"aria-hidden":`true`}),`Working…`]})]})]})}function yn(e){return Number.isFinite(e.durationMs)&&e.durationMs>0}function bn(e,t){let n=e.find(e=>e.id===t.id),r=e.filter(e=>e.id!==t.id);return r.push({...t,revision:(n?.revision??0)+1}),r.slice(Math.max(0,r.length-3))}function xn(e,t){let n=e.filter(e=>e.id!==t);return n.length===e.length?e:n}function Sn(e,t){return`clear`in t?xn(e,t.id):bn(e,{id:t.id,message:t.message,variant:t.variant,durationMs:t.durationMs??4e3})}function Cn({toast:e,onDismiss:t}){let[n,r]=(0,x.useState)(!1),i=(0,x.useRef)(null);return(0,x.useEffect)(()=>{if(n||!yn(e))return;let r=setTimeout(()=>t(e.id),e.durationMs);return()=>clearTimeout(r)},[e.id,e.revision,e.durationMs,t,n]),(0,Y.jsxs)(`div`,{ref:i,className:`code-toast code-toast-${e.variant}`,onPointerEnter:()=>r(!0),onPointerLeave:()=>r(!1),onFocusCapture:()=>r(!0),onBlurCapture:e=>{i.current?.contains(e.relatedTarget)||r(!1)},children:[(0,Y.jsx)(`span`,{className:`code-toast-message`,children:e.message}),(0,Y.jsx)(`button`,{type:`button`,className:`code-toast-dismiss`,"aria-label":`Dismiss notice`,onClick:()=>t(e.id),children:`×`})]})}function wn({toasts:e,onDismiss:t}){return(0,Y.jsx)(`div`,{className:`code-toast-host`,children:(0,Y.jsx)(`div`,{className:`code-toast-region`,role:`status`,children:e.map(e=>(0,Y.jsx)(Cn,{toast:e,onDismiss:t},e.id))})})}function Tn({controller:e}){let t=e.session?.cwd??e.selection.cwd,n=e.selectedId!==null||e.pending||e.creationUnknown||e.operation.kind!==`idle`,r=e.workspacePicking;function i(){n||r||e.pickWorkspace()}return(0,Y.jsxs)(`header`,{className:`code-workspace-header`,children:[(0,Y.jsxs)(`div`,{className:`code-session-header`,children:[(0,Y.jsx)(`span`,{className:`code-session-title`,children:e.session?.title||(e.selectedId?`Untitled session`:`New session draft`)}),(0,Y.jsx)(`span`,{children:H[e.session?.provider??e.selection.provider]}),(0,Y.jsxs)(`span`,{role:`status`,children:[e.session?Se[e.session.status]:e.creationUnknown?`Creation unconfirmed`:e.operation.kind===`creating`?`Creating session`:`Draft`,e.session?.archivedAt!==null&&e.session?` · Archived`:``]})]}),(0,Y.jsxs)(`div`,{className:`code-workspace-primary`,children:[n?(0,Y.jsx)(`span`,{className:`code-workspace-chip`,title:t,children:t||`Workspace not set`}):(0,Y.jsx)(`button`,{type:`button`,className:`code-workspace-picker`,"aria-label":`Choose Code workspace`,disabled:r,title:t||`Choose a folder`,onClick:i,children:(0,Y.jsx)(`span`,{className:`code-workspace-picker-label`,children:r?`Choosing folder…`:t||`Choose workspace`})}),e.gitInfo?.isRepo&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`code-workspace-pill`,children:[e.gitInfo.branch??`detached`,e.gitInfo.head?` · ${e.gitInfo.head}`:``]}),e.gitInfo.status&&(0,Y.jsx)(`span`,{className:`code-workspace-pill${e.gitInfo.status.dirty?` is-dirty`:``}`,children:e.gitInfo.status.dirty?`${e.gitInfo.status.changed} changed · ${e.gitInfo.status.untracked} untracked`:`clean`})]})]})]})}function En({controller:e,endpointKey:t,onOpenLocalFile:n}){let r=`${t}:${e.selectedId??`new`}`,[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(null),c=(0,x.useRef)(new Set),[l,u]=(0,x.useState)([]),d=(0,x.useCallback)(e=>{u(t=>Sn(t,e))},[]),f=(0,x.useCallback)(e=>u(t=>xn(t,e)),[]),p=e.session?.archivedAt!=null,m=e.session?.status===`stopping`||e.operation.kind===`stopping`,h=e.busy||e.working||m||e.session?.status===`starting`||e.session?.status===`streaming`,g=e.catalog?.providers.find(t=>t.id===e.selection.provider),_=e.operation.kind===`unknown-send`,v=!e.steering&&(e.followUp?!e.followUpSent&&!m&&!e.pending&&!p&&e.operation.kind===`idle`:!h&&!e.pending&&!e.creationUnknown&&!p&&e.operation.kind===`idle`&&!!g?.available&&!!e.selection.cwd.trim()&&!!e.selection.model.trim()&&(e.selectedId===null||e.synced&&(e.session?.status===`idle`||!!e.session&&W(e.session)))),y=!!e.session?.turnId&&e.session.capabilities.interrupt&&h&&!m,b=!!e.session&&W(e.session)&&e.synced&&!e.pending&&!_,S=e.operation.error||e.error||(i?.key===r?i.message:null),C=we(e.session,e.synced,e.operation.kind===`idle`&&!e.steering)?Te(e.items,e.session?.rollback?.sinceSequence):void 0,w=[...e.items].reverse().find(e=>e.kind===`turn_cancelled`||e.kind===`turn_failed`||e.kind===`turn_completed`),T=w&&w.kind!==`turn_completed`?e.items.find(e=>e.kind===`user_message`&&e.turnId===w.turnId)?.text:void 0;function E(e){a(null),e().catch(e=>a({key:r,message:e instanceof Error?e.message:String(e)}))}async function D(){if(e.canRetrySameSend&&!c.current.has(r)){c.current.add(r),s(r),a(null);try{await e.retrySameSend()}catch(e){a({key:r,message:e instanceof Error?e.message:String(e)})}finally{c.current.delete(r),s(e=>e===r?null:e)}}}return(0,Y.jsxs)(`div`,{className:`code-canvas-main`,children:[(0,Y.jsx)(Tn,{controller:e},r),(e.transport!==`connected`||e.selectedId!==null&&!e.synced)&&(0,Y.jsxs)(`section`,{className:`code-transport-status is-${e.transport}`,role:`status`,children:[e.transport===`reconnecting`?`Live updates reconnecting. History may be out of date.`:e.transport===`disconnected`?`Live updates disconnected. History may be out of date.`:`Updating conversation…`,(0,Y.jsx)(`button`,{type:`button`,onClick:()=>E(e.refresh),children:`Refresh`})]}),S&&(0,Y.jsxs)(`section`,{className:`code-recovery-strip`,role:`alert`,children:[(0,Y.jsx)(`p`,{children:S}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>E(e.refresh),children:`Refresh session`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{e.clearError(),a(null)},children:`Dismiss`})]}),e.creationUnknown&&(0,Y.jsxs)(`section`,{className:`code-recovery-strip`,"aria-label":`Unconfirmed session creation`,children:[(0,Y.jsx)(`strong`,{children:`Session creation not confirmed`}),(0,Y.jsx)(`p`,{children:`The original session may still exist.`}),(0,Y.jsx)(`p`,{children:`Your draft and choices are kept. Press Send when you are ready to create another session.`}),(0,Y.jsx)(`button`,{type:`button`,onClick:e.startAnotherSession,children:`Start another session`})]}),_&&(0,Y.jsxs)(`section`,{className:`code-recovery-strip`,"aria-label":e.resendRequired?e.resendReason===`rolled-back`?`Send rolled back`:`Send not started`:`Unconfirmed send`,children:[(0,Y.jsx)(`strong`,{children:e.resendRequired?U(e.resendReason??void 0).heading:`Send outcome not confirmed`}),(0,Y.jsx)(`p`,{children:e.resendRequired?U(e.resendReason??void 0).detail:`Retry uses the original request. It may submit it if the server has not already accepted it.`}),(0,Y.jsx)(`pre`,{className:`code-retry-preview`,"aria-label":`Original prompt`,children:e.retryText}),(0,Y.jsx)(`button`,{type:`button`,disabled:!e.canRetrySameSend||o===r,onClick:()=>void D(),children:o===r?e.resendRequired?`Sending as a new message…`:`Retrying original send…`:e.resendRequired?`Send as a new message`:`Retry same send`})]}),p?(0,Y.jsxs)(`section`,{className:`code-recovery-strip`,children:[(0,Y.jsx)(`span`,{children:`Archived · Read-only history`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!e.synced||e.pending,onClick:()=>{let t=e.selectedId;t&&E(()=>e.archive(t,!1))},children:`Restore session`})]}):e.session&&(e.session.status===`failed`||e.session.status===`suspended`)&&(0,Y.jsxs)(`section`,{className:`code-recovery-strip`,role:`status`,children:[(0,Y.jsx)(`p`,{children:e.session.error?.message??`Native session suspended.`}),b?(0,Y.jsx)(`button`,{type:`button`,onClick:()=>E(e.resume),children:`Resume session`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{children:e.session.resume.reason??`Resume is not currently available.`}),(0,Y.jsx)(`button`,{type:`button`,onClick:e.newSession,children:`New session`})]})]}),(0,Y.jsx)(wn,{toasts:l,onDismiss:f}),e.selectedId===null&&e.items.length===0?(0,Y.jsx)(zt,{controller:e}):(0,Y.jsx)(vn,{items:e.items,provider:e.session?.provider??e.selection.provider,sessionKey:r,workingDir:e.session?.cwd??e.selection.cwd,loading:e.loading,hasOlderHistory:e.hasOlderHistory,loadOlderHistory:e.loadOlderHistory,permissionCount:e.permissions.length,onOpenLocalFile:n,working:e.working,rollbackRows:C,onRollback:t=>E(()=>e.rollbackSession(t))}),(0,Y.jsx)(Vt,{permissions:e.permissions,operations:e.permissionOperations,session:e.session,synced:e.synced,onAnswer:e.answer}),(0,Y.jsxs)(`div`,{className:`code-composer-dock`,children:[T!==void 0&&!h&&!p&&(0,Y.jsxs)(`div`,{className:`code-input-recovery`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:!!e.input||_,title:e.input?`Keep or clear your current draft before restoring the submitted prompt`:void 0,onClick:()=>e.setInput(T),children:`Restore submitted prompt`}),(0,Y.jsx)(`span`,{children:`Restores text for editing without sending.`})]}),(0,Y.jsxs)(`div`,{className:`code-composer-surface`,"aria-label":`Code composer controls`,children:[(0,Y.jsx)(Ot,{inputText:e.input,canSend:v,busy:h,canStop:y,stopping:m,pending:e.pending,followUp:e.followUp,followUpSent:e.followUpSent,steering:e.steering,readOnly:p,autoFocus:e.selectedId===null,onInputChange:e.setInput,onSubmit:e.send,onStop:e.stop,...e.operation.kind===`rolling-back`?{pendingLabel:`Rolling back conversation…`}:{}},`composer:${r}`),(0,Y.jsx)(Ft,{controller:e,onNotice:d},`footer:${r}`)]})]})]})}function Dn({port:e,workingDir:t,onWorkingDirChange:n,onOpenLocalFile:r,newSessionShortcut:i}){let a=Qe({port:e,workingDir:t}),[o,s]=(0,x.useState)(null),c=(0,x.useRef)({port:e,id:a.selectedId,cwd:a.selection.cwd});(0,x.useEffect)(()=>{s(document.getElementById(`code-session-sidebar-host`))},[]),(0,x.useEffect)(()=>{let t=c.current,r={port:e,id:a.selectedId,cwd:a.selection.cwd};c.current=r,t.port===e&&t.id===null&&r.id===null&&t.cwd!==r.cwd&&n?.(r.cwd||null)},[e,a.selectedId,a.selection.cwd,n]);let l=(0,Y.jsx)(vt,{controller:a,newSessionShortcut:i},e),u=(0,Y.jsx)(En,{controller:a,endpointKey:String(e),onOpenLocalFile:r},e);return o?(0,Y.jsxs)(Y.Fragment,{children:[(0,S.createPortal)((0,Y.jsx)(`div`,{className:`code-manager-session-navigator-content`,children:l}),o),(0,Y.jsx)(`div`,{className:`code-canvas code-canvas-workbench`,children:u})]}):(0,Y.jsxs)(`div`,{className:`code-canvas`,children:[(0,Y.jsx)(`div`,{className:`code-canvas-sidebar`,children:l}),u]})}export{Dn as CodeCanvas};