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,3 @@
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{c as v,h as y,l as b,m as x,o as S,r as C,t as w,u as T}from"./icons-QgChTDzZ.js";import{t as E}from"./copy-text-WsUHYigB.js";import{i as D,t as O}from"./manager-shortcuts-Cqmr0mEq.js";var k=e(h(),1),A=_(),j={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.`},M=class extends Error{code;status;session;constructor(e,t,n){super(j[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 N(e){return typeof window<`u`&&window.location.port===String(e)?window.location.origin:`http://127.0.0.1:${e}`}function P(e){let t=N(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 M(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 F=512,ee=2097152,I=2e3,L=16777216;function te(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 R(e){return!!e&&[`starting`,`streaming`,`stopping`].includes(e.status)}var ne=e=>e.sort((e,t)=>(e.firstSequence??0)-(t.firstSequence??0)),re=e=>e.reduce((e,t)=>e+JSON.stringify(t).length,0);function ie(e){let t=e.items,n=re(t);if(t.length<=I&&n<=L)return e;for(t=[...t];t.length>I||n>L;){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 ae(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=ne([...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 ie({...e,items:n,session:r,permissions:i,cursor:t.sequence})}function oe(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=ae(t,e),t.needsSnapshot)break;n.shift()}return{...t,buffered:n,synced:t.synced&&!n.length&&!t.needsSnapshot}}function se(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>F||JSON.stringify(n).length>ee?{...e,buffered:[],synced:!1,needsSnapshot:!0,error:`Live updates exceeded the buffer. Refreshing history.`}:oe({...e,buffered:n})}function z(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 se(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=ne([...n.items]);return oe(ie({...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=se(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=ne([...e.items,...t.page.items.filter(e=>!n.has(e.itemId))]);return r.length>I||re(r)>L?{...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 ce=`cli-jaw:code-drafts:v1`,le=`cli-jaw:code-draft-warnings:v1`,B=1,ue=4,de=32,fe=262144,pe=1048576,me=2097152,he=`Draft recovery is unavailable in this tab. Your current text remains in memory.`,ge=`Draft recovery is incomplete: some recent text or request state was not saved for reload. Check your draft before sending.`,_e=`Draft recovery is incomplete: some text was not saved for reload because this tab reached its recovery limit.`,V=e=>!!e&&typeof e==`object`&&!Array.isArray(e),H=(e,t)=>typeof e==`string`&&e.length<=t,ve=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=0;function ye(e){if(!V(e)||!H(e.input,fe)||!ve(e.edit)||!ve(e.selectionEdit)||typeof e.creating!=`boolean`)return null;let t=e.selection;if(!V(t)||![`codex-app`,`claude`,`cursor`,`grok`].includes(String(t.provider))||!H(t.cwd,4096)||!H(t.model,1024)||!(t.effort===null||H(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&&(!V(n)||!H(n.text,fe)||!H(n.key,240)||!n.key||!ve(n.edit)||n.edit>e.edit)||r!==null&&(!V(r)||!H(r.turnId,240)||!r.turnId||!ve(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 be(e){if(e===null)return{version:B,endpoints:[]};if(e.length>me)return null;let t;try{t=JSON.parse(e)}catch{return null}if(!V(t)||t.version!==B||!Array.isArray(t.endpoints)||t.endpoints.length>ue)return null;let n=[];for(let e of t.endpoints){if(!V(e)||!H(e.endpoint,2048)||!(e.selectedId===null||H(e.selectedId,240))||!Array.isArray(e.sessions)||e.sessions.length>de)return null;let t=ye(e.fresh);if(!t||t.retry||t.stop)return null;let r=[];for(let t of e.sessions){if(!V(t)||!H(t.id,240)||!t.id)return null;let e=ye(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>pe)return null;n.push({endpoint:e.endpoint,selectedId:e.selectedId,fresh:t,sessions:r})}return{version:B,endpoints:n}}function xe(e){let t=e.getItem(le);if(!t||t.length>16384)return[];try{let e=JSON.parse(t);return Array.isArray(e)&&e.length<=ue&&e.every(e=>H(e,2048))?e:[]}catch{return[]}}function U(e,t,n){try{let r=xe(e).filter(e=>e!==t);n&&r.push(t),r.length?e.setItem(le,JSON.stringify(r.slice(-4))):e.removeItem(le)}catch{}}function Se(){if(typeof window>`u`)return{storage:null,warning:null};try{return{storage:window.sessionStorage,warning:null}}catch{return{storage:null,warning:he}}}function Ce(e,t){try{let n=be(e.getItem(ce));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=xe(e);return{data:r,warning:i.includes(t)||!r&&i.length>0?ge:null}}catch{return{data:null,warning:he}}}function we(e){let{provider:t,cwd:n,model:r,effort:i,permissionMode:a,thinking:o}=e.selection;return ye({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 Te(e,t,n){try{let r=we(n.fresh);if(!r)return U(e,t,!0),_e;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=we(s);if(!o)return U(e,t,!0),_e;if(i.sessions.length>=de){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>pe){a=!0;continue}i.sessions=c.sessions,i.selectedId=c.selectedId}if(n.selectedId!==null&&i.selectedId===null||JSON.stringify(i).length>pe)return U(e,t,!0),_e;let s=e.getItem(ce),c=[...(be(s)??{version:B,endpoints:[]}).endpoints.filter(e=>e.endpoint!==t),i],l=JSON.stringify({version:B,endpoints:c});for(;c.length>ue||l.length>me;){let t=c.shift();t&&U(e,t.endpoint,!0),l=JSON.stringify({version:B,endpoints:c})}return l!==s&&e.setItem(ce,l),U(e,t,a||n.recoveryWarning!==null),a?_e:null}catch{return U(e,t,!0),he}}var W={"codex-app":`Codex`,claude:`Claude`,cursor:`Cursor`,grok:`Grok`},Ee={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`},De={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.`},Oe={idle:`Ready`,starting:`Starting`,streaming:`Running`,stopping:`Stopping`,suspended:`Suspended`,failed:`Runtime failed`};function ke(e){return e.status===`starting`||e.status===`streaming`||e.status===`stopping`}function G(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 K(e){return e.archivedAt===null&&e.capabilities.resume&&e.resume.available&&(e.status===`suspended`||e.status===`failed`&&e.error?.recoverable===!0)}function Ae(e,t,n){return!!e&&e.rollback?.available===!0&&e.archivedAt===null&&t&&n&&(e.status===`idle`||e.status===`failed`)}function je(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 Me(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 Ne=new Map,Pe=new WeakMap;function q(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 Fe(e){let t=q(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?G(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 Ie(e,t){let n=Se(),r=n.storage?Pe.get(n.storage):Ne;r||(r=new Map,Pe.set(n.storage,r));let i=r.get(e);if(!i){let a=n.storage?Ce(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?Fe(a.data.fresh):q({provider:`codex-app`,cwd:t,model:``,effort:null,permissionMode:`ask`}),sessions:new Map(a.data?.sessions.map(e=>[e.id,Fe(e.draft)])??[]),listeners:new Set},r.set(e,i)}return i}function Le(e){e.storage&&(e.storageWarning=Te(e.storage,e.endpoint,e))}function Re(e){return{provider:e.provider,cwd:e.cwd,model:e.model,effort:e.effort,permissionMode:e.permissionMode,...e.thinking===null?{}:{thinking:e.thinking}}}function ze(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 Be(e,t){e.steer?.key===t&&(e.edit===e.steer.edit&&(e.input=``,e.edit++),e.steer=null)}function Ve(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 He=`pending:user`;function Ue(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:He,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 We(e,t,n=Date.now()){let r=Ue(e,t,n);return r?[...t,r]:t}var Ge=6,J=1e3,Ke=100,qe=32,Je=150,Y=e=>e instanceof M?e.message:`Connection lost. Refresh to check the current state.`,X=e=>e instanceof M&&e.status>=400&&e.status<500,Ye=`Follow-up delivery not confirmed. It was not resent; it appears in the conversation if Claude received it.`,Xe=`Follow-up delivery not confirmed. Claude may have received it, but it will not appear in the conversation. It was not resent.`,Ze=`The conversation changed since you chose this point. Review it and try again.`,Qe=`The conversation was rolled back elsewhere; this message was not sent.`,$e=(e,t)=>!t||e.epoch>t.epoch||e.epoch===t.epoch&&(e.sequence>t.sequence||e.sequence===t.sequence&&e.revision>=t.revision),et=e=>e===`failed`||e===`cancelled`;function tt(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 nt=class{client;book;details=new Map;summaries=new Map;pinnedOverlay=[];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=P(e.port),this.workingDir=e.workingDir,this.book=Ie(N(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(){Le(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(),()=>{Le(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.pinnedOverlay=[],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=q(n?Re(n):this.book.fresh.selection),this.book.sessions.set(e,t)}return t}info(e){return e?[this.details.get(e)?.session,this.summaries.get(e),this.pinnedOverlay.find(t=>t.sessionId===e)].reduce((e,t)=>t&&$e(t,e)?t:e,null):null}observe(e){let t=this.attention.get(e.sessionId);(!t||$e(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(!$e(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,a=this.pinnedOverlay.findIndex(e=>e.sessionId===i.sessionId);if(a!==-1&&(i.pinnedAt===null||i.archivedAt!==null?this.pinnedOverlay.splice(a,1):this.pinnedOverlay[a]=i),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)&&!this.pinnedOverlay.some(t=>t.sessionId===e));e&&(this.summaries.delete(e),this.attention.delete(e))}let o=this.book.sessions.get(i.sessionId);o?.awaitingTurn&&R(i)&&(o.awaitingTurn=null),o?.stopTarget&&(i.turnId!==o.stopTarget.turnId||i.epoch!==o.stopTarget.epoch||!R(i))&&(o.stopTarget=null,o.operation.kind===`stopping`&&(o.operation=o.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=te(e),this.details.set(e,t),this.trimDetails()),t}trimDetails(){for(let e of this.details.keys()){if(this.details.size<=Ge)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)&&(tt(t,r.retry.key)?this.requireNewKey(r):Ve(r,r.retry.key)),r?.steer&&t.items.some(e=>e.kind===`user_message`&&e.clientTurnKey===r.steer.key)&&Be(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:G(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:Qe})}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?Xe:Ye:null;return{catalog:this.catalog,sessions:[...this.rows,...this.pinnedOverlay.map(e=>e.sessionId).filter(e=>!this.rows.includes(e))].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:We(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?Re(a):n.selection,gitInfo:this.gitInfo,loading:this.indexLoading||!!r?.hydrating||!!e&&!r?.hydrated&&!r?.error,pending:c,busy:R(a),working:!!n.awaitingTurn||R(a),workingIds:new Set([...this.rows,...this.pinnedOverlay.map(e=>e.sessionId)].filter(e=>{let t=this.info(e);return!!this.book.sessions.get(e)?.awaitingTurn||!!t&&R(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,pin:this.pin,markUnread:this.markUnread,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=ze(n,{...r.selection,provider:n.defaultProvider})),this.notify()}catch(n){this.active&&t===this.lifetime&&e===this.catalogGeneration&&(this.catalogError=Y(n),this.notify())}}async readIndex(e=!1){let t=++this.indexGeneration,n=this.lifetime,r=e?this.cursor:null,i=e?Ke:Math.min(J,Math.max(Ke,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),o=e||this.filter.archived?null:await this.client.listSessions({...this.filter.scope===`cwd`?{cwd:this.workingDir}:{},archived:!1,pinned:!0,limit:J},this.abort.signal).catch(()=>null);if(!this.active||n!==this.lifetime||t!==this.indexGeneration)return;!e&&!o&&(this.pinnedOverlay=[]),this.rows=[...new Set([...e?this.rows:[],...a.sessions.map(e=>e.sessionId)])].slice(0,J);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,z(t,{type:`stale`})),this.sync(e.sessionId))}if(o){let e=[];for(let t of o.sessions){let n=this.info(t.sessionId),r=n&&!$e(t,n)?n:t;r.pinnedAt!==null&&r.archivedAt===null&&(e.push(r),r===t&&(this.observe(r),this.accept(r)))}this.pinnedOverlay=e}this.cursor=a.nextCursor,this.fetched=(e?this.fetched:0)+a.sessions.length,this.moreSessions=a.hasMore&&this.rows.length<J,this.indexError=null;let s=new Set([...this.rows,...this.pinnedOverlay.map(e=>e.sessionId),...this.details.keys(),...this.book.selectedId?[this.book.selectedId]:[]]);for(let e of this.summaries.keys())s.has(e)||(this.summaries.delete(e),this.attention.delete(e))}catch(e){this.active&&n===this.lifetime&&t===this.indexGeneration&&(this.indexError=Y(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()},Je))}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<qe&&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,z(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,z(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=z(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,z(this.state(e),{type:`error`,error:`History is still catching up. Refresh to continue.`}))}catch(t){if(!a())return;if(t instanceof M&&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,z(this.state(e),{type:`snapshot`,snapshot:t}));return}}this.update(e,z(this.state(e),{type:`error`,error:Y(t)})),t instanceof M&&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),Be(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),tt(this.details.get(e.sessionId),e.item.clientTurnKey)?this.requireNewKey(t):Ve(t,e.item.clientTurnKey));let n=this.details.get(e.sessionId);if(!n){this.notify();return}let r=z(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,z(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.pinnedOverlay=[],this.moreSessions=!1,this.notify(),this.readIndex()};startAnotherSession=()=>{let e=this.book.fresh;if(this.book.selectedId!==null||!e.createUnknown)return;let t=q(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=Y(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=Y(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=ze(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`||R(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 M&&t.session?.sessionId===e&&(this.observe(t.session),this.accept(t.session)),a=t instanceof M?t:Error(Y(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)};async sidebarPatch(e,t){let n=this.draft(e),r=this.info(e);if(!r||n.operation.kind!==`idle`){let e=Error(r?`Wait for the current session action to finish before changing it.`:`Refresh this session before changing it.`);throw n.operation.error=e.message,this.notify(),e}let i=null;n.operation={kind:`patching`,error:null},this.notify();try{this.accept(await this.client.patchSession(e,{...t,expectedRevision:r.revision})),n.operation={kind:`idle`,error:null}}catch(t){t instanceof M&&t.session?.sessionId===e&&(this.observe(t.session),this.accept(t.session)),i=t instanceof M?t:Error(Y(t)),n.operation={kind:`idle`,error:i.message}}if(this.notify(),this.scheduleIndex(),i)throw i}pin=async(e,t)=>{await this.sidebarPatch(e,{pinned:t})};markUnread=async(e,t)=>{await this.sidebarPatch(e,{unread:t})};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&&K(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:Y(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=q(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=!X(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.`:Y(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,z(i,{type:`stale`})),et(r.status)?(this.requireNewKey(t,this.removedByRollback(e,r)?`rolled-back`:void 0),t.awaitingTurn=null):Ve(t,n.key)}catch(e){t.retry?.key===n.key&&(t.operation={kind:X(e)?`idle`:`unknown-send`,error:X(e)?Y(e):`Message acceptance is unknown. Refresh, or explicitly retry the original message with the same key.`},X(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,z(i,{type:`stale`})),Be(t,r.key)}catch(e){t.steer===r&&(X(e)?(t.steer=null,t.operation.kind===`idle`&&(t.operation={kind:`idle`,error:Y(e)})):(r.state=`unknown`,r.unrecorded=e instanceof M&&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||!R(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:Y(e)},X(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:Y(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&&Ae(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 M&&e.session?.sessionId===t&&(this.observe(e.session),this.accept(e.session)),r.operation={kind:`idle`,error:e instanceof M&&e.code===`revision_conflict`?Ze:Y(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:Y(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,z(this.state(e),{type:`history`,page:r}))}catch(t){this.active&&n===this.lifetime&&(this.draft(e).operation.error=Y(t),this.notify())}finally{this.historyLoading.delete(e)}}};function rt({port:e,onEvent:t,onTransport:n}){let r=(0,k.useRef)({onEvent:t,onTransport:n});r.current={onEvent:t,onTransport:n},(0,k.useEffect)(()=>{if(!e)return;let t=!0,n=new EventSource(`${N(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 it({port:e,workingDir:t}){let n=N(e),r=(0,k.useMemo)(()=>new nt({port:e,workingDir:t}),[n,e]);return(0,k.useEffect)(()=>r.mount(),[r]),(0,k.useEffect)(()=>r.setWorkingDir(t),[r,t]),rt({port:e,onEvent:r.onEvent,onTransport:r.onTransport}),(0,k.useSyncExternalStore)(r.subscribe,r.getModel,r.getModel)}function at(e){return e.archivedAt===null?`active`:`archived`}function ot(e,t){return t.createdAt-e.createdAt||e.sessionId.localeCompare(t.sessionId)}function st(e,t){return(t.pinnedAt??0)-(e.pinnedAt??0)||ot(e,t)}function ct(e){let t=e.filter(e=>at(e)===`active`).sort(ot),n=e.filter(e=>at(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 lt(e){return e===void 0?{kind:`unknown`}:e>0?{kind:`approvals`,count:e}:{kind:`none`}}function ut(e){return e.kind===`unknown`?`Approval status unknown`:e.kind===`none`?`No pending approvals`:`${e.count} pending approval${e.count===1?``:`s`}`}function dt(e){if(e.archivedAt!==null)return!1;if(e.markedUnread)return!0;let t=e.lastTurnCompletedAt,n=e.lastVisitedAt;return t===null||n===null?!1:t>n}function ft(e){let t=new Map;for(let n of[...e].sort(ot)){let e=t.get(n.cwd)??[];e.push(n),t.set(n.cwd,e)}return[...t].map(([e,t])=>({cwd:e,sessions:t}))}var pt=[`priority`,`today`,`yesterday`,`earlier`],mt={priority:`Priority`,today:`Today`,yesterday:`Yesterday`,earlier:`Earlier`};function ht(e){let t=new Date(e);return t.setHours(0,0,0,0),t.getTime()}function gt(e,t=Date.now(),n=null){let r=ht(t),i=ht(r-1),a=new Map;for(let t of e){let e=t.sessionId!==n&&dt(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 pt.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 _t(e){return e.replace(/[\\/]+$/,``).split(/[\\/]/).pop()||e}var Z=g(),vt=O.newCodeSession,yt=`jaw.code.sidebarView`;function bt(){try{return localStorage.getItem(yt)===`activity`?`activity`:`projects`}catch{return`projects`}}function xt(){return(0,Z.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`15`,height:`15`,"aria-hidden":`true`,focusable:`false`,children:(0,Z.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 St(){return(0,Z.jsxs)(`svg`,{viewBox:`0 0 16 16`,width:`15`,height:`15`,"aria-hidden":`true`,focusable:`false`,children:[(0,Z.jsx)(`circle`,{cx:`7`,cy:`7`,r:`4.25`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`}),(0,Z.jsx)(`path`,{d:`M10.2 10.2 13.5 13.5`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`})]})}function Ct(){return(0,Z.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":`true`,focusable:`false`,children:(0,Z.jsx)(`path`,{d:`M8 3.5v9M3.5 8h9`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.7`,strokeLinecap:`round`})})}function wt({session:e,controller:t,view:n}){let[r,i]=(0,k.useState)(!1),[a,o]=(0,k.useState)(e.title??``),[s,c]=(0,k.useState)(!1),[l,u]=(0,k.useState)(null),d=y(),f=(0,k.useRef)(!1),p=(0,k.useRef)(null),m=(0,k.useId)(),h=t.selectedId===e.sessionId,g=ke(e),_=e.archivedAt!==null,D=e.pinnedAt!==null,O=lt(h&&t.synced?t.permissions.length:e.pendingPermissionCount),A=!h&&(e.markedUnread||dt(e)),j=t.workingIds?.has(e.sessionId)??!1,M=j&&e.status===`idle`,N=e.title||`Untitled session`;async function P(e,t){if(!f.current){f.current=!0,c(!0),u(null);try{await e(),t?.()}catch(e){u(e instanceof Error?e.message:String(e))}finally{f.current=!1,c(!1)}}}function F(){i(!1),p.current?.focus()}async function ee(e){let t=await E(e);if(!t.ok)throw Error(t.error??`Copy failed.`)}let I=[{id:`rename`,label:`Rename`,icon:(0,Z.jsx)(v,{}),disabled:s||g,...g?{title:`Stop before renaming`}:{},onSelect:()=>{o(e.title??``),i(!0)}},{id:`pin`,label:D?`Unpin`:`Pin`,icon:(0,Z.jsx)(b,{}),disabled:s,onSelect:()=>void P(()=>t.pin(e.sessionId,!D))},{id:`unread`,label:A?`Mark as read`:`Mark as unread`,icon:(0,Z.jsx)(S,{}),disabled:s||h,...h?{title:`The open session is already read`}:{},onSelect:()=>void P(()=>t.markUnread(e.sessionId,!A))},{id:`archive`,label:_?`Restore`:`Archive`,icon:(0,Z.jsx)(w,{}),disabled:s||g,...g?{title:`Stop before archiving`}:{},onSelect:()=>void P(()=>t.archive(e.sessionId,!_))},...K(e)?[{kind:`separator`,id:`resume-sep`},{id:`resume`,label:`Resume`,icon:(0,Z.jsx)(T,{}),disabled:s||!h||!t.synced||t.pending,title:h?`Resume without resending a prompt`:`Select this session to resume it`,onSelect:()=>void P(t.resume)}]:[],{kind:`separator`,id:`copy-sep`},{id:`copy-id`,label:`Copy session ID`,icon:(0,Z.jsx)(C,{}),onSelect:()=>void P(()=>ee(e.sessionId))},{id:`copy-cwd`,label:`Copy working directory`,icon:(0,Z.jsx)(C,{}),onSelect:()=>void P(()=>ee(e.cwd))}];function L(e){(e.key===`ContextMenu`||e.shiftKey&&e.key===`F10`)&&d.openAt(e)}return(0,Z.jsxs)(`li`,{className:`code-session-row`,onContextMenu:e=>{e.target.closest(`.code-session-rename`)||d.openAt(e)},children:[(0,Z.jsxs)(`div`,{className:`code-session-item-wrap`,onKeyDown:L,children:[(0,Z.jsxs)(`button`,{ref:p,type:`button`,className:`code-session-item${h?` active`:``}`,"aria-current":h?`true`:void 0,onClick:()=>void P(()=>t.selectSession(e.sessionId)),children:[(0,Z.jsxs)(`span`,{className:`code-session-cwd`,children:[A&&(0,Z.jsx)(`span`,{className:`code-session-unread-dot`,role:`img`,"aria-label":`Unread`}),N]}),(0,Z.jsx)(`span`,{className:`code-session-meta`,title:e.cwd,children:n===`activity`?`${_t(e.cwd)} · ${W[e.provider]}`:W[e.provider]}),(0,Z.jsxs)(`span`,{className:`code-session-status code-session-status-${M?`starting`:e.status}`,"data-quiet":e.status===`idle`&&!j?`true`:void 0,children:[j&&(0,Z.jsx)(`span`,{className:`code-session-spinner`,"aria-hidden":`true`}),M?Oe.starting:Oe[e.status]]}),(0,Z.jsx)(`span`,{className:`code-session-attention code-session-attention-${O.kind}`,"data-quiet":O.kind===`none`?`true`:void 0,children:ut(O)})]}),(0,Z.jsxs)(`span`,{className:`code-session-hover-actions`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`code-session-hover-btn${D?` is-on`:``}`,"aria-label":D?`Unpin ${N}`:`Pin ${N}`,"aria-pressed":D,title:D?`Unpin`:`Pin`,disabled:s,onClick:n=>{n.stopPropagation(),P(()=>t.pin(e.sessionId,!D))},children:(0,Z.jsx)(b,{})}),(0,Z.jsx)(`button`,{type:`button`,className:`code-session-hover-btn`,"aria-label":_?`Restore ${N}`:`Archive ${N}`,title:g?`Stop before archiving`:_?`Restore`:`Archive`,disabled:s||g,onClick:n=>{n.stopPropagation(),P(()=>t.archive(e.sessionId,!_))},children:(0,Z.jsx)(w,{})}),(0,Z.jsx)(`button`,{type:`button`,className:`code-session-hover-btn`,"aria-label":`More actions for ${N}`,"aria-haspopup":`menu`,title:`More actions`,onClick:e=>{e.stopPropagation(),d.openAtElement(e.currentTarget)},children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:`⋯`})})]})]}),r&&(0,Z.jsxs)(`form`,{className:`code-session-rename`,onSubmit:n=>{n.preventDefault(),a.trim()&&P(()=>t.rename(e.sessionId,a.trim()),F)},children:[(0,Z.jsx)(`input`,{autoFocus:!0,"aria-label":`Session title`,"aria-describedby":l?m:void 0,value:a,disabled:s,onChange:e=>o(e.target.value),onKeyDown:t=>{t.key===`Escape`&&!s&&(t.preventDefault(),o(e.title??``),F())}}),(0,Z.jsx)(`button`,{type:`submit`,disabled:s||!a.trim(),children:`Save`}),(0,Z.jsx)(`button`,{type:`button`,disabled:s,onClick:F,children:`Cancel`})]}),(0,Z.jsx)(x,{state:d.state,entries:I,label:`Actions for ${N}`,onClose:d.close}),s&&(0,Z.jsx)(`span`,{className:`code-session-view-hint`,role:`status`,children:`Updating session…`}),l&&(0,Z.jsx)(`div`,{id:m,className:`code-session-list-error`,role:`alert`,children:l})]})}function Tt({controller:e,newSessionShortcut:t=vt}){let[n,r]=(0,k.useState)(``),[i,a]=(0,k.useState)(!1),o=(0,k.useRef)(null);function s(){if(i){a(!1),r(``);return}a(!0),queueMicrotask(()=>o.current?.focus())}let c=(0,k.useId)(),[l,u]=(0,k.useState)(bt);function d(e){u(e);try{localStorage.setItem(yt,e)}catch{}}let[f,p]=(0,k.useState)(null),[m,h]=(0,k.useState)(!1),g=(0,k.useRef)(!1),_=e.sessions.filter(e=>`${e.title??``} ${e.cwd} ${W[e.provider]}`.toLowerCase().includes(n.toLowerCase())),v=e.sessions.some(t=>t.sessionId!==e.selectedId&&dt(t)),y=_.filter(e=>e.archivedAt===null&&e.pinnedAt!==null).sort(st),b=_.filter(e=>e.archivedAt===null&&e.pinnedAt===null),x=_.filter(e=>e.archivedAt!==null),S=l===`activity`?gt(b,Date.now(),e.selectedId).map(e=>({key:e.bucket,title:mt[e.bucket],cwd:null,sessions:e.sessions})):ft(b).map(e=>({key:e.cwd,title:e.cwd,cwd:e.cwd,sessions:e.sessions}));y.length&&S.unshift({key:`pinned`,title:`Pinned`,cwd:null,sessions:y}),x.length&&S.push({key:`archived`,title:`Archived`,cwd:null,sessions:ct(x).flatMap(e=>e.sessions)});let C=e.newSession;(0,k.useEffect)(()=>{function e(e){e.detail===`newCodeSession`&&C()}return document.addEventListener(`jaw:shortcut-action`,e),()=>document.removeEventListener(`jaw:shortcut-action`,e)},[C]);async function w(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 T(){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,Z.jsxs)(`nav`,{className:`code-session-list`,"aria-label":`Code sessions`,children:[(0,Z.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 (${D(t)})`,onClick:e.newSession,children:[(0,Z.jsx)(Ct,{}),(0,Z.jsx)(`span`,{className:`code-session-new-label`,children:`New session`}),e.hasUnsentDraft&&(0,Z.jsx)(`span`,{id:c,className:`code-session-draft-badge`,children:`Draft`}),(0,Z.jsx)(`kbd`,{className:`code-session-new-hint`,"aria-hidden":`true`,children:D(t)})]}),(0,Z.jsxs)(`div`,{className:`code-session-list-header`,children:[(0,Z.jsx)(`span`,{className:`code-session-list-title`,children:l===`activity`?`Recent activity`:`Projects`}),(0,Z.jsxs)(`span`,{className:`code-session-header-actions`,children:[(0,Z.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,Z.jsx)(St,{})}),(0,Z.jsxs)(`button`,{type:`button`,className:`code-session-header-btn code-session-bell${l===`activity`?` active`:``}`,"aria-pressed":l===`activity`,"aria-label":v?`Recent activity (unread sessions)`:`Recent activity`,title:l===`activity`?`Back to projects`:`Recent activity`,onClick:()=>d(l===`activity`?`projects`:`activity`),children:[(0,Z.jsx)(xt,{}),v&&(0,Z.jsx)(`span`,{className:`code-session-unread-dot`,"aria-hidden":`true`})]})]})]}),i&&(0,Z.jsxs)(`div`,{className:`code-session-search-row`,children:[(0,Z.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,Z.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,Z.jsx)(`div`,{className:`code-session-list-loading`,role:`status`,children:`Loading sessions…`}),S.map(t=>(0,Z.jsxs)(`section`,{className:`code-session-group`,children:[t.title&&(0,Z.jsxs)(`h3`,{className:`code-session-group-title${t.key===`priority`?` code-session-group-priority`:``}`,title:t.title,children:[(0,Z.jsx)(`span`,{children:t.cwd===null?t.title:_t(t.cwd)}),t.cwd!==null&&(0,Z.jsx)(`button`,{type:`button`,className:`code-session-group-new`,"aria-label":`New session in ${t.cwd}`,title:`New session in ${t.cwd}`,onClick:()=>void w(t.cwd),children:`+`})]}),(0,Z.jsx)(`ul`,{className:`code-session-list-items`,children:t.sessions.map(t=>(0,Z.jsx)(wt,{session:t,controller:e,view:l},t.sessionId))})]},t.key)),!e.loading&&!_.length&&(0,Z.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,Z.jsx)(`button`,{type:`button`,className:`code-inline-action`,disabled:m,onClick:()=>void T(),children:m?`Loading…`:`Load more sessions`}),(0,Z.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,Z.jsx)(`div`,{className:`code-session-list-error`,role:`alert`,children:f})]})}var Et={"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 Dt({provider:e}){let t=Et[e];return(0,Z.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,Z.jsx)(`path`,{d:t.d})})}function Ot(){return(0,Z.jsx)(`svg`,{viewBox:`0 0 20 20`,width:`16`,height:`16`,"aria-hidden":`true`,focusable:`false`,children:(0,Z.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 kt(){return(0,Z.jsx)(`svg`,{viewBox:`0 0 20 20`,width:`16`,height:`16`,"aria-hidden":`true`,focusable:`false`,children:(0,Z.jsx)(`rect`,{x:`6`,y:`6`,width:`8`,height:`8`,rx:`1.6`,fill:`currentColor`})})}function At({muted:e}){return(0,Z.jsxs)(`svg`,{viewBox:`0 0 20 20`,width:`16`,height:`16`,"aria-hidden":`true`,focusable:`false`,children:[(0,Z.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,Z.jsx)(`path`,{d:`M4.6 4.6 15.4 15.4`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`})]})}function jt(){return(0,Z.jsx)(`svg`,{className:`code-footer-check`,viewBox:`0 0 20 20`,width:`16`,height:`16`,"aria-hidden":`true`,focusable:`false`,children:(0,Z.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 Mt(){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 Nt(e){return e.includes(`mp4`)?`.mp4`:e.includes(`ogg`)?`.ogg`:`.webm`}function Pt(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 Ft(e,t){let[n,r]=(0,k.useState)(`unsupported`),[i,a]=(0,k.useState)(null),o=(0,k.useRef)(null),s=(0,k.useRef)(null),c=(0,k.useRef)([]),l=(0,k.useRef)(!0);(0,k.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,k.useCallback)(async(t,n)=>{r(`transcribing`);try{let r=await fetch(`/api/voice`,{method:`POST`,headers:{"Content-Type":n||`audio/webm`,"X-Voice-Ext":Nt(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(Pt(e))}finally{l.current&&r(`idle`)}},[e]),d=(0,k.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(Pt(e));return}if(!l.current){e.getTracks().forEach(e=>e.stop());return}s.current=e;let t=Mt(),n;try{n=new MediaRecorder(e,t?{mimeType:t}:{})}catch(t){e.getTracks().forEach(e=>e.stop()),a(Pt(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 It(e){let t=(0,k.useRef)(!1),n=(0,k.useRef)(!1),r=(0,k.useRef)(!1),[i,a]=(0,k.useState)(null),o=Ft((0,k.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,Z.jsxs)(`div`,{className:`code-composer`,children:[(0,Z.jsxs)(`div`,{className:`code-composer-input-shell`,children:[(0,Z.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,Z.jsx)(`span`,{className:`code-composer-hint`,children:`Enter to send · Shift+Enter for a new line`})]}),(0,Z.jsxs)(`div`,{className:`code-composer-actions`,children:[(0,Z.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,Z.jsx)(At,{muted:o.status===`unsupported`})}),e.busy&&(0,Z.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,Z.jsx)(kt,{})}),(!e.busy||e.followUp)&&(0,Z.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,Z.jsx)(Ot,{})})]}),(e.stopping||e.steering||e.pending||o.status===`recording`||o.status===`transcribing`)&&(0,Z.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,Z.jsx)(`div`,{className:`code-action-error`,role:`alert`,children:i??o.error})]})}function Lt(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 Rt(e,t){let n=e/t;return n<10?n.toFixed(1):String(Math.round(n))}function Q(e){if(!Number.isFinite(e)||e<0)return`—`;let t=Math.round(e);if(t<1e3)return String(t);let n=Rt(t,1e3);return Number(n)<1e3?`${n}k`:`${Rt(t,1e6)}M`}function zt(e){return e===null||!Number.isFinite(e)||e<0?`—`:e.toLocaleString(`en-US`)}function Bt(e){return e===null?`—`:Q(e)}function Vt(e){return e>=90?`critical`:e>=75?`high`:`normal`}function Ht(e){return e.state===`hidden`?``:e.state===`counted`?`Context: ${Q(e.usedTokens)} tokens used, window unknown`:e.over?`Context: over the window, ${Q(e.usedTokens)} of ${Q(e.maxTokens)} tokens`:`Context: ${e.percent}% used, ${Q(e.usedTokens)} of ${Q(e.maxTokens)} tokens`}function Ut({usage:e}){let t=Lt(e),[n,r]=(0,k.useState)(!1),[i,a]=(0,k.useState)(!1),o=n||i,s=(0,k.useId)();if(t.state===`hidden`)return null;let c=Ht(t),l=t.state===`measured`?t.over?`critical`:Vt(t.percent):`normal`,u=2*Math.PI*7,d=t.state===`measured`?t.percent/100*u:0;return(0,Z.jsxs)(`div`,{className:`code-context-usage`,onPointerEnter:()=>r(!0),onPointerLeave:()=>r(!1),children:[(0,Z.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,Z.jsxs)(`svg`,{className:`code-context-ring`,viewBox:`0 0 18 18`,"aria-hidden":`true`,children:[(0,Z.jsx)(`circle`,{className:`code-context-ring-track`,cx:`9`,cy:`9`,r:`7`}),(0,Z.jsx)(`circle`,{className:`code-context-ring-fill`,cx:`9`,cy:`9`,r:`7`,strokeDasharray:`${d} ${u}`})]}):null,(0,Z.jsx)(`span`,{className:`code-context-value`,children:t.state===`measured`?t.over?`over`:`${t.percent}%`:Q(t.usedTokens)})]}),o&&(0,Z.jsxs)(`div`,{id:s,className:`code-context-detail`,role:`note`,children:[(0,Z.jsx)(`p`,{className:`code-context-detail-total`,children:t.state===`measured`?`${Q(t.usedTokens)} of ${Q(t.maxTokens)} tokens`:`${Q(t.usedTokens)} tokens used`}),t.state===`measured`&&t.over&&(0,Z.jsx)(`p`,{className:`code-context-detail-note`,children:`Past the window the runtime last reported.`}),t.state===`counted`&&(0,Z.jsx)(`p`,{className:`code-context-detail-note`,children:`This runtime did not report a context window.`}),(0,Z.jsxs)(`dl`,{className:`code-context-breakdown`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`dt`,{children:`Used`}),(0,Z.jsx)(`dd`,{children:zt(e?.totalTokens??null)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`dt`,{children:`Input`}),(0,Z.jsx)(`dd`,{children:Bt(e?.inputTokens??null)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`dt`,{children:`Cached`}),(0,Z.jsx)(`dd`,{children:Bt(e?.cachedInputTokens??null)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`dt`,{children:`Output`}),(0,Z.jsx)(`dd`,{children:Bt(e?.outputTokens??null)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`dt`,{children:`Reasoning`}),(0,Z.jsx)(`dd`,{children:Bt(e?.reasoningOutputTokens??null)})]})]}),e?.processedTokens!=null&&(0,Z.jsxs)(`p`,{className:`code-context-detail-note`,children:[`Processed across the conversation: `,Q(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,k.useId)(),f=(0,k.useRef)(null),p=(0,k.useRef)(null),m=(0,k.useRef)(null),[h,g]=(0,k.useState)(null),[_,v]=(0,k.useState)(``),y=n.find(e=>e.value===t),b=(0,k.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 x(e=!0){g(null),v(``),e&&f.current?.focus()}function S(){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,k.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)&&x(!1)},t=()=>x(!1);return document.addEventListener(`pointerdown`,e),window.addEventListener(`resize`,t),()=>{document.removeEventListener(`pointerdown`,e),window.removeEventListener(`resize`,t)}},[h,s]),(0,k.useEffect)(()=>{r&&(g(null),v(``))},[r]);function C(e){if(e.key===`Escape`){e.preventDefault(),x();return}if(e.key===`Tab`){x(!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 w=`${e}: ${y?.label??a??(t||`not selected`)}`;return(0,Z.jsxs)(`div`,{className:`code-footer-menu${l?` ${l}`:``}`,children:[(0,Z.jsx)(`button`,{ref:f,type:`button`,className:`code-footer-menu-trigger${o?` is-icon`:``}`,"aria-label":w,"aria-haspopup":`listbox`,"aria-expanded":!!h,"aria-controls":h?d:void 0,disabled:r,title:u??y?.detail??w,onClick:()=>h?x():S(),onKeyDown:e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),S())},children:o??(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`code-footer-label`,children:e}),(0,Z.jsx)(`strong`,{children:y?.label??a??(t||`Not selected`)})]})}),h&&(0,A.createPortal)((0,Z.jsxs)(`div`,{ref:p,id:d,role:`listbox`,"aria-label":e,className:`code-footer-dropup code-footer-floating`,style:h,onKeyDown:C,children:[s&&(0,Z.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,Z.jsxs)(`div`,{className:`code-footer-dropup-list`,children:[b.map(e=>(0,Z.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),x()},children:[e.icon&&(0,Z.jsx)(`span`,{className:`code-footer-option-icon`,children:e.icon}),(0,Z.jsxs)(`span`,{className:`code-footer-option-text`,children:[(0,Z.jsx)(`strong`,{children:e.label}),e.detail&&(0,Z.jsx)(`small`,{children:e.detail})]}),e.value===t&&(0,Z.jsx)(jt,{})]},e.value)),b.length===0&&(0,Z.jsxs)(`p`,{className:`code-footer-dropup-empty`,role:`note`,children:[`No match for “`,_.trim(),`”.`]})]})]}),document.body)]})}function Wt({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,k.useState)(!1),[u,d]=(0,k.useState)(null),f=(0,k.useRef)(!1),p=(0,k.useRef)(t);p.current=t,(0,k.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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`code-composer-footer`,children:[(0,Z.jsx)($,{label:`Runtime`,value:n.provider,className:`code-footer-runtime`,disabled:o?!e.catalog:h||!e.catalog,triggerContent:(0,Z.jsx)(Dt,{provider:n.provider}),title:W[n.provider],options:Object.keys(W).map(t=>{let r=e.catalog?.providers.find(e=>e.id===t);return{value:t,label:o&&t!==n.provider?`New ${W[t]} session`:W[t],disabled:!r?.available||o&&t===n.provider,icon:(0,Z.jsx)(Dt,{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,Z.jsx)($,{label:`Permission`,value:n.permissionMode,displayValue:Ee[n.permissionMode],disabled:h||!i?.permissions,options:a.map(e=>({value:e,label:Ee[e],detail:De[e]})),onChange:e=>void m({permissionMode:e})}),(0,Z.jsx)(`span`,{className:`code-composer-footer-spacer`,"aria-hidden":`true`}),(0,Z.jsx)(Ut,{usage:e.session?.contextUsage}),(0,Z.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,Z.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,Z.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,Z.jsx)(`button`,{type:`button`,className:`code-inline-action`,onClick:e.newSession,children:`New session`})]}),y.length===0&&r?.available&&(0,Z.jsxs)(`div`,{className:`code-selection-notice`,children:[`This runtime published no models.`,(0,Z.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,Z.jsxs)(`div`,{className:`code-selection-notice`,children:[r?.reason??`Runtime availability has not been confirmed.`,(0,Z.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,Z.jsx)(`span`,{role:`status`,children:`Saving settings…`}),u&&(0,Z.jsx)(`div`,{className:`code-action-error`,role:`alert`,children:u})]})}function Gt(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 Kt=[`Explain this codebase`,`Find and fix a bug`,`Write tests for the module I name`,`Review uncommitted changes`];function qt(){document.querySelector(`textarea[aria-label="Code prompt"]`)?.focus()}function Jt({controller:e}){let t=e.selection.cwd,n=e.selectedId!==null||e.pending||e.creationUnknown||e.operation.kind!==`idle`,r=e.workspacePicking,i=Gt(e.sessions.filter(e=>e.cwd!==t));function a(){n||r||e.pickWorkspace()}function o(t){n||(e.setSelection({cwd:t}),qt())}return(0,Z.jsxs)(`section`,{className:`code-draft-empty`,"aria-label":`New session draft`,children:[(0,Z.jsx)(`h2`,{className:`code-draft-empty-title`,children:`New session`}),n?(0,Z.jsx)(`span`,{className:`code-workspace-chip`,title:t,children:t||`Workspace not set`}):(0,Z.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,Z.jsx)(`span`,{className:`code-workspace-picker-label`,children:r?`Choosing folder…`:t||`Choose workspace`})}),(0,Z.jsxs)(`p`,{className:`code-draft-empty-selection`,children:[W[e.selection.provider],` · `,e.selection.model||`No model selected`]}),i.length>0&&(0,Z.jsxs)(`div`,{className:`code-draft-recents`,children:[(0,Z.jsx)(`span`,{className:`code-draft-recents-label`,children:`Recent workspaces`}),i.map(e=>(0,Z.jsx)(`button`,{type:`button`,className:`code-draft-recent`,title:e,disabled:n,onClick:()=>o(e),children:e},e))]}),!e.input.trim()&&(0,Z.jsx)(`div`,{className:`code-draft-prompts`,children:Kt.map(t=>(0,Z.jsx)(`button`,{type:`button`,className:`code-draft-prompt`,disabled:n,onClick:()=>{e.setInput(t),qt()},children:t},t))})]})}function Yt({permission:e,operation:t,eligible:n,onAnswer:r}){let i=(0,k.useRef)(!1),[a,o]=(0,k.useState)(!1),[s,c]=(0,k.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,Z.jsxs)(`section`,{className:`code-permission-card`,"aria-label":e.title,children:[(0,Z.jsxs)(`div`,{className:`code-permission-title`,children:[(0,Z.jsx)(`strong`,{children:e.title}),(0,Z.jsx)(`p`,{children:e.detail}),!n&&(0,Z.jsx)(`small`,{children:`Updating permission availability…`}),(a||t?.pending)&&(0,Z.jsx)(`small`,{role:`status`,children:`Checking decision…`}),(t?.error||s)&&(0,Z.jsx)(`div`,{className:`code-action-error`,role:`alert`,children:t?.error||s})]}),(0,Z.jsxs)(`div`,{className:`code-permission-actions`,children:[e.options.map(e=>(0,Z.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,Z.jsx)(`span`,{children:`No native actions available. Refresh this session.`})]})]})}function Xt({permissions:e,operations:t,session:n,synced:r,onAnswer:i}){return e.length?(0,Z.jsxs)(`aside`,{className:`code-permissions`,"aria-label":`Pending permissions`,tabIndex:-1,id:`code-pending-permissions`,children:[(0,Z.jsxs)(`div`,{className:`code-permissions-heading`,role:`status`,children:[e.length,` pending · `,n?W[n.provider]:`Session updating`]}),e.map(e=>(0,Z.jsx)(Yt,{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 Zt=92,Qt=6;function $t(e){let[{virtualItems:t,totalSize:s},c]=(0,k.useState)({virtualItems:[],totalSize:0}),l=(0,k.useRef)(null);l.current||=new o({count:e.count,getScrollElement:()=>e.scrollElementRef.current,estimateSize:e.estimateSize||(()=>Zt),overscan:Qt,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,k.useEffect)(()=>u._didMount(),[u]),(0,k.useEffect)(()=>{u.measure()},[u,e.resetKey]),(0,k.useEffect)(()=>()=>{l.current=null},[]),(0,k.useLayoutEffect)(()=>{u.setOptions({...u.options,count:e.count,getItemKey:e.getItemKey,estimateSize:e.estimateSize||(()=>Zt)}),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 en=64,tn=64;function nn({items:e,sessionKey:t,transcriptRef:n,virtual:r}){let i=(0,k.useRef)(new Map),a=(0,k.useRef)(!0),[o,s]=(0,k.useState)(!1),c=(0,k.useRef)({sessionKey:``,firstId:``}),l=(0,k.useRef)({items:e,virtual:r,sessionKey:t});l.current={items:e,virtual:r,sessionKey:t};let u=(0,k.useCallback)(()=>{a.current=!0,s(!1);let e=n.current;e&&(e.scrollTop=e.scrollHeight)},[n]);return(0,k.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>en){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<=tn,s(!a.current),t())};return e.addEventListener(`scroll`,r,{passive:!0}),()=>e.removeEventListener(`scroll`,r)},[n]),(0,k.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 rn=2e3,an=80,on=400;function sn(e){return e<=rn?an:Math.min(on,Math.round(an*e/rn))}function cn(e,t=!1,n=``){let[r,i]=(0,k.useState)({text:e,identity:n}),a=(0,k.useRef)(0),o=t||r.identity!==n||!e.startsWith(r.text);return(0,k.useEffect)(()=>{if(r.text===e&&r.identity===n)return;let t=()=>{a.current=Date.now(),i({text:e,identity:n})},s=sn(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 ln=[[/^(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 un(e){return e===`running`||e===`pending`}function dn(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 fn(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 pn(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`?dn(n,t):fn(n)}return``}return n.includes(`/`)&&!n.includes(` `)?dn(n,t):fn(n)}function mn(e){let t=p(e).description;return t===null?``:l(t)}function hn(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 gn(e,t){let n=un(e.status);if(e.kind===`file_change`){let r=pn(e.tool?.input,t)||e.tool?.detail||``;return r?`${n?`Editing`:`Edit`} ${r}`:`File change`}let r=e.tool?.name?.trim()||`Tool`,i=ln.find(([e])=>e.test(r)),a=i?n?i[2]:i[1]:void 0,o=pn(e.tool?.input,t);return a?o?`${a} ${o}`:a:o?`${r} ${o}`:r}function _n(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 vn=(0,k.lazy)(()=>t(()=>import(`./MarkdownRenderer-Cc3DeHvm.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0]))),yn=new Set([`turn_started`,`turn_completed`]),bn=44,xn=480,Sn=64;function Cn(e){return e.length>1400||e.split(`
3
+ `).length>14}function wn(e,t,n){let r=e.get(`${t}:${n.itemId}`);return r===void 0?n.status===`error`&&n.kind!==`reasoning`:r}function Tn({item:e,identity:t,onOpenLocalFile:n}){let r=cn(e.text??``,e.status!==`running`&&e.status!==`pending`,t);return r.trim()?(0,Z.jsx)(k.Suspense,{fallback:(0,Z.jsx)(`span`,{className:`code-plain-text`,children:r}),children:(0,Z.jsx)(vn,{markdown:r,tableMode:`linear`,onLocalFileOpen:n})}):(0,Z.jsx)(`span`,{className:`code-plain-text`,children:r})}function En({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=Me(e),p=_n(e),m=e.itemId===He,h=a??(e.status===`error`&&e.kind!==`reasoning`),g=e.status===`running`||e.status===`pending`,_=g?null:p,v=c?mn(e.tool?.input):``,y=c?hn(e.tool?.input):null,b=[];c&&(y&&b.push({key:`input`,label:`Input`,content:y.content,className:`code-tool-args`,copyable:!0}),y?.parameters&&b.push({key:`params`,label:`Parameters`,content:y.parameters,className:`code-tool-json`,copyable:!1}),y?.description&&b.push({key:`description`,label:`Description`,content:y.description,className:`code-tool-text`,copyable:!1}),e.tool?.output!==void 0&&b.push({key:`output`,label:`Output`,content:e.tool.output,className:`code-tool-output`,copyable:!1}));let x=b.some(e=>Cn(e.content))||e.tool?.detail!==void 0&&Cn(e.tool.detail)||e.text!==void 0&&Cn(e.text),[S,C]=(0,k.useState)(!1),w=(0,k.useRef)(null),[T,D]=(0,k.useState)(null);(0,k.useEffect)(()=>{D(null)},[x]),(0,k.useEffect)(()=>{if(!h||S)return;let e=w.current?.querySelectorAll(`pre, .code-tool-body > .code-tool-text`);if(!e||e.length===0){D(null);return}let t=[...e],n=t.some(e=>e.scrollHeight>e.clientHeight+2);D(n||t.every(e=>e.scrollHeight===0)&&x)},[h,S,x]);let O=T??x;(0,k.useEffect)(()=>{O||C(!1)},[O]);let[A,j]=(0,k.useState)(!1),M=(0,k.useRef)(null);(0,k.useEffect)(()=>()=>{M.current!==null&&window.clearTimeout(M.current)},[]);let N=(0,k.useCallback)(()=>{j(!0),M.current!==null&&window.clearTimeout(M.current),M.current=window.setTimeout(()=>{M.current=null,j(!1)},1200)},[]),P=d?`You`:u?W[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,Z.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,Z.jsxs)(`details`,{className:`code-tool-card code-tool-${e.status}`,open:h,onToggle:t=>o?.(e.itemId,t.currentTarget.open),children:[(0,Z.jsxs)(`summary`,{className:`code-tool-summary`,children:[(0,Z.jsx)(`span`,{className:`code-tool-chevron`,"aria-hidden":`true`,children:`›`}),(0,Z.jsxs)(`span`,{className:`code-tool-summary-text`,children:[(0,Z.jsx)(`span`,{className:`code-tool-name${g?` code-tool-name-running`:``}`,children:gn(e,r)}),v!==``&&(0,Z.jsx)(`span`,{className:`code-tool-desc`,children:v})]}),_&&(0,Z.jsx)(`span`,{className:`code-tool-status`,children:_})]}),h&&(0,Z.jsxs)(`div`,{ref:w,className:`code-tool-body`,"data-expanded":S,children:[e.tool?.detail!==void 0&&(0,Z.jsx)(`p`,{className:`code-tool-text`,children:e.tool.detail}),b.map(e=>(0,Z.jsxs)(`section`,{className:`code-tool-section`,children:[(0,Z.jsxs)(`div`,{className:`code-tool-section-head`,children:[(0,Z.jsx)(`span`,{className:`code-tool-section-label`,children:e.label}),e.copyable&&(0,Z.jsx)(`button`,{type:`button`,className:`code-tool-copy${A?` copied`:``}`,"aria-label":`Copy ${e.label.toLowerCase()}`,onClick:()=>void E(e.content).then(e=>{e.ok&&N()}),children:A?`Copied`:`Copy`})]}),(0,Z.jsx)(`pre`,{className:e.className,children:e.content})]},e.key)),e.text!==void 0&&(0,Z.jsx)(`pre`,{className:`code-tool-text`,children:e.text}),g&&e.tool?.output===void 0&&e.tool?.detail===void 0&&(0,Z.jsx)(`p`,{className:`code-tool-waiting`,children:`Waiting for output…`}),O&&(0,Z.jsx)(`button`,{type:`button`,className:`code-tool-toggle`,"aria-expanded":S,onClick:()=>C(e=>!e),children:S?`Show less`:`Show all`})]})]}):l?(0,Z.jsxs)(`details`,{className:`code-thinking`,open:h,onToggle:t=>o?.(e.itemId,t.currentTarget.open),children:[(0,Z.jsx)(`summary`,{className:`code-thinking-summary${e.status===`running`?` code-tool-name-running`:``}`,children:e.status===`running`?`Thinking…`:`Reasoning`}),h&&(0,Z.jsx)(`div`,{className:`code-thinking-text`,children:e.text})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsx)(`div`,{className:`code-message-text`,children:u?(0,Z.jsx)(Tn,{item:e,identity:`${n}:${e.itemId}`,onOpenLocalFile:i}):(0,Z.jsx)(`span`,{className:`code-plain-text`,children:e.text??e.permission?.title??``})}),e.permission?.detail&&(0,Z.jsx)(`p`,{className:`code-plain-text`,children:e.permission.detail}),s&&d&&!m&&(0,Z.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,Z.jsxs)(`span`,{className:`code-partial-label`,children:[`Partial output · `,f]}),e.truncation&&(0,Z.jsxs)(`p`,{className:`code-truncation`,role:`note`,children:[`Output truncated: `,e.truncation.storedChars.toLocaleString(),` of `,e.truncation.sourceChars.toLocaleString(),` characters retained.`]})]})}function Dn({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,k.useRef)(null),p=(0,k.useMemo)(()=>e.filter(e=>!yn.has(e.kind)),[e]),m=(0,k.useRef)(p);m.current=p;let[h,g]=(0,k.useState)(()=>new Map),_=(0,k.useRef)(h);_.current=h;let[v,y]=(0,k.useState)(!1),[b,x]=(0,k.useState)(null),S=(0,k.useRef)(!1),C=p[0]?.itemId,w=(0,k.useCallback)(e=>{let t=m.current[e];return t?`${n}:${t.itemId}${wn(_.current,n,t)?`:open`:``}`:`${n}:${e}`},[n,C,h]),T=(0,k.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&&wn(h,n,t)?xn:bn},[h,n]),E=$t({count:p.length,resetKey:n,scrollElementRef:f,getItemKey:w,estimateSize:T}),{showJump:D,jumpToLatest:O}=nn({items:p,sessionKey:n,transcriptRef:f,virtual:E}),A=(0,k.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>Sn){let e=n.keys().next().value;e!==void 0&&n.delete(e)}return n})},[n]);async function j(){if(!S.current){S.current=!0,y(!0),x(null);try{await o()}catch(e){x({sessionKey:n,message:e instanceof Error?e.message:String(e)})}finally{S.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(),O()):e.key===`Home`&&(e.preventDefault(),t.scrollTo({top:0,behavior:`auto`}))}return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`code-transcript-controls`,children:[a&&(0,Z.jsx)(`button`,{type:`button`,disabled:v||i,onClick:()=>void j(),children:v?`Loading history…`:`Load older history`}),D&&(0,Z.jsx)(`button`,{type:`button`,onClick:O,children:`Jump to latest`}),s>0&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>document.getElementById(`code-pending-permissions`)?.focus(),children:[`Jump to permissions (`,s,`)`]}),b?.sessionKey===n&&(0,Z.jsx)(`span`,{className:`code-action-error`,role:`alert`,children:b.message})]}),(0,Z.jsxs)(`div`,{ref:f,className:`code-transcript`,role:`log`,"aria-label":`Code transcript`,"aria-live":`off`,tabIndex:0,onKeyDown:M,children:[p.length?(0,Z.jsx)(`div`,{className:`code-transcript-virtual-spacer`,style:{height:E.totalSize},children:E.virtualItems.map(e=>{let i=p[e.index];return i?(0,Z.jsx)(`div`,{ref:E.measureElement,className:`code-transcript-virtual-row`,"data-code-transcript-idx":e.index,style:{transform:`translateY(${e.start}px)`},children:(0,Z.jsx)(En,{item:i,provider:t,sessionKey:n,workingDir:r,onOpenLocalFile:c,expanded:wn(h,n,i),onExpandedChange:A,onRollback:u?.has(i.itemId)?d:void 0})},e.key):null})}):(0,Z.jsxs)(`div`,{className:`code-transcript-empty`,children:[(0,Z.jsx)(`p`,{children:i?`Loading conversation…`:`Type a prompt below to start this conversation.`}),(0,Z.jsxs)(`p`,{className:`code-transcript-cwd`,children:[`Workspace: `,r||`not set`]})]}),l&&p[p.length-1]?.status!==`running`&&(0,Z.jsxs)(`div`,{className:`code-transcript-working`,role:`status`,"aria-live":`polite`,children:[(0,Z.jsx)(`span`,{className:`code-session-spinner`,"aria-hidden":`true`}),`Working…`]})]})]})}function On(e){return Number.isFinite(e.durationMs)&&e.durationMs>0}function kn(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 An(e,t){let n=e.filter(e=>e.id!==t);return n.length===e.length?e:n}function jn(e,t){return`clear`in t?An(e,t.id):kn(e,{id:t.id,message:t.message,variant:t.variant,durationMs:t.durationMs??4e3})}function Mn({toast:e,onDismiss:t}){let[n,r]=(0,k.useState)(!1),i=(0,k.useRef)(null);return(0,k.useEffect)(()=>{if(n||!On(e))return;let r=setTimeout(()=>t(e.id),e.durationMs);return()=>clearTimeout(r)},[e.id,e.revision,e.durationMs,t,n]),(0,Z.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,Z.jsx)(`span`,{className:`code-toast-message`,children:e.message}),(0,Z.jsx)(`button`,{type:`button`,className:`code-toast-dismiss`,"aria-label":`Dismiss notice`,onClick:()=>t(e.id),children:`×`})]})}function Nn({toasts:e,onDismiss:t}){return(0,Z.jsx)(`div`,{className:`code-toast-host`,children:(0,Z.jsx)(`div`,{className:`code-toast-region`,role:`status`,children:e.map(e=>(0,Z.jsx)(Mn,{toast:e,onDismiss:t},e.id))})})}function Pn({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,Z.jsxs)(`header`,{className:`code-workspace-header`,children:[(0,Z.jsxs)(`div`,{className:`code-session-header`,children:[(0,Z.jsx)(`span`,{className:`code-session-title`,children:e.session?.title||(e.selectedId?`Untitled session`:`New session draft`)}),(0,Z.jsx)(`span`,{children:W[e.session?.provider??e.selection.provider]}),(0,Z.jsxs)(`span`,{role:`status`,children:[e.session?Oe[e.session.status]:e.creationUnknown?`Creation unconfirmed`:e.operation.kind===`creating`?`Creating session`:`Draft`,e.session?.archivedAt!==null&&e.session?` · Archived`:``]})]}),(0,Z.jsxs)(`div`,{className:`code-workspace-primary`,children:[n?(0,Z.jsx)(`span`,{className:`code-workspace-chip`,title:t,children:t||`Workspace not set`}):(0,Z.jsx)(`button`,{type:`button`,className:`code-workspace-picker`,"aria-label":`Choose Code workspace`,disabled:r,title:t||`Choose a folder`,onClick:i,children:(0,Z.jsx)(`span`,{className:`code-workspace-picker-label`,children:r?`Choosing folder…`:t||`Choose workspace`})}),e.gitInfo?.isRepo&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{className:`code-workspace-pill`,children:[e.gitInfo.branch??`detached`,e.gitInfo.head?` · ${e.gitInfo.head}`:``]}),e.gitInfo.status&&(0,Z.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 Fn({controller:e,endpointKey:t,onOpenLocalFile:n}){let r=`${t}:${e.selectedId??`new`}`,[i,a]=(0,k.useState)(null),[o,s]=(0,k.useState)(null),c=(0,k.useRef)(new Set),[l,u]=(0,k.useState)([]),d=(0,k.useCallback)(e=>{u(t=>jn(t,e))},[]),f=(0,k.useCallback)(e=>u(t=>An(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&&K(e.session)))),y=!!e.session?.turnId&&e.session.capabilities.interrupt&&h&&!m,b=!!e.session&&K(e.session)&&e.synced&&!e.pending&&!_,x=e.operation.error||e.error||(i?.key===r?i.message:null),S=Ae(e.session,e.synced,e.operation.kind===`idle`&&!e.steering)?je(e.items,e.session?.rollback?.sinceSequence):void 0,C=[...e.items].reverse().find(e=>e.kind===`turn_cancelled`||e.kind===`turn_failed`||e.kind===`turn_completed`),w=C&&C.kind!==`turn_completed`?e.items.find(e=>e.kind===`user_message`&&e.turnId===C.turnId)?.text:void 0;function T(e){a(null),e().catch(e=>a({key:r,message:e instanceof Error?e.message:String(e)}))}async function E(){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,Z.jsxs)(`div`,{className:`code-canvas-main`,children:[(0,Z.jsx)(Pn,{controller:e},r),(e.transport!==`connected`||e.selectedId!==null&&!e.synced)&&(0,Z.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,Z.jsx)(`button`,{type:`button`,onClick:()=>T(e.refresh),children:`Refresh`})]}),x&&(0,Z.jsxs)(`section`,{className:`code-recovery-strip`,role:`alert`,children:[(0,Z.jsx)(`p`,{children:x}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>T(e.refresh),children:`Refresh session`}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{e.clearError(),a(null)},children:`Dismiss`})]}),e.creationUnknown&&(0,Z.jsxs)(`section`,{className:`code-recovery-strip`,"aria-label":`Unconfirmed session creation`,children:[(0,Z.jsx)(`strong`,{children:`Session creation not confirmed`}),(0,Z.jsx)(`p`,{children:`The original session may still exist.`}),(0,Z.jsx)(`p`,{children:`Your draft and choices are kept. Press Send when you are ready to create another session.`}),(0,Z.jsx)(`button`,{type:`button`,onClick:e.startAnotherSession,children:`Start another session`})]}),_&&(0,Z.jsxs)(`section`,{className:`code-recovery-strip`,"aria-label":e.resendRequired?e.resendReason===`rolled-back`?`Send rolled back`:`Send not started`:`Unconfirmed send`,children:[(0,Z.jsx)(`strong`,{children:e.resendRequired?G(e.resendReason??void 0).heading:`Send outcome not confirmed`}),(0,Z.jsx)(`p`,{children:e.resendRequired?G(e.resendReason??void 0).detail:`Retry uses the original request. It may submit it if the server has not already accepted it.`}),(0,Z.jsx)(`pre`,{className:`code-retry-preview`,"aria-label":`Original prompt`,children:e.retryText}),(0,Z.jsx)(`button`,{type:`button`,disabled:!e.canRetrySameSend||o===r,onClick:()=>void E(),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,Z.jsxs)(`section`,{className:`code-recovery-strip`,children:[(0,Z.jsx)(`span`,{children:`Archived · Read-only history`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!e.synced||e.pending,onClick:()=>{let t=e.selectedId;t&&T(()=>e.archive(t,!1))},children:`Restore session`})]}):e.session&&(e.session.status===`failed`||e.session.status===`suspended`)&&(0,Z.jsxs)(`section`,{className:`code-recovery-strip`,role:`status`,children:[(0,Z.jsx)(`p`,{children:e.session.error?.message??`Native session suspended.`}),b?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>T(e.resume),children:`Resume session`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{children:e.session.resume.reason??`Resume is not currently available.`}),(0,Z.jsx)(`button`,{type:`button`,onClick:e.newSession,children:`New session`})]})]}),(0,Z.jsx)(Nn,{toasts:l,onDismiss:f}),e.selectedId===null&&e.items.length===0?(0,Z.jsx)(Jt,{controller:e}):(0,Z.jsx)(Dn,{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:S,onRollback:t=>T(()=>e.rollbackSession(t))}),(0,Z.jsx)(Xt,{permissions:e.permissions,operations:e.permissionOperations,session:e.session,synced:e.synced,onAnswer:e.answer}),(0,Z.jsxs)(`div`,{className:`code-composer-dock`,children:[w!==void 0&&!h&&!p&&(0,Z.jsxs)(`div`,{className:`code-input-recovery`,children:[(0,Z.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(w),children:`Restore submitted prompt`}),(0,Z.jsx)(`span`,{children:`Restores text for editing without sending.`})]}),(0,Z.jsxs)(`div`,{className:`code-composer-surface`,"aria-label":`Code composer controls`,children:[(0,Z.jsx)(It,{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,Z.jsx)(Wt,{controller:e,onNotice:d},`footer:${r}`)]})]})]})}function In({port:e,workingDir:t,onWorkingDirChange:n,onOpenLocalFile:r,newSessionShortcut:i}){let a=it({port:e,workingDir:t}),[o,s]=(0,k.useState)(null),c=(0,k.useRef)({port:e,id:a.selectedId,cwd:a.selection.cwd});(0,k.useEffect)(()=>{s(document.getElementById(`code-session-sidebar-host`))},[]),(0,k.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,Z.jsx)(Tt,{controller:a,newSessionShortcut:i},e),u=(0,Z.jsx)(Fn,{controller:a,endpointKey:String(e),onOpenLocalFile:r},e);return o?(0,Z.jsxs)(Z.Fragment,{children:[(0,A.createPortal)((0,Z.jsx)(`div`,{className:`code-manager-session-navigator-content`,children:l}),o),(0,Z.jsx)(`div`,{className:`code-canvas code-canvas-workbench`,children:u})]}):(0,Z.jsxs)(`div`,{className:`code-canvas`,children:[(0,Z.jsx)(`div`,{className:`code-canvas-sidebar`,children:l}),u]})}export{In as CodeCanvas};
@@ -0,0 +1,3 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-CkEUZM6i.js";import{c as r}from"./api-B9RiiOMM.js";import{c as i,d as a,i as o,m as s,r as c,s as l}from"./icons-QgChTDzZ.js";import{t as u}from"./desktop-bridge-DbRfkg8l.js";import{t as d}from"./copy-text-WsUHYigB.js";import{n as f,t as p}from"./client-platform-WO8m6kPQ.js";import{n as m,t as h}from"./folder-drag-payload-BhV9yzhH.js";var g=e(t(),1);function _(e){return{name:e.name,path:e.path,kind:e.kind===`folder`?`directory`:`file`,size:e.size}}function v(e,t){for(let n of e){if(n.path===t)return n;let e=v(n.children??[],t);if(e)return e}return null}function y(e){return{kind:`electron-folder`,label:`Folder`,canPickRoot:!0,getInitialRoot:async()=>null,pickRoot:async()=>{let t=await e.pickFolder();if(!t.ok&&t.error===`cancelled`)return null;if(!t.ok)throw Error(t.error??`Failed to pick folder`);return t.path??null},registerGitWorktreeRoot:async(t,n,r)=>{let i=await e.registerGitWorktreeRoot?.(t,n,r);if(!i?.ok)throw Error(i?.error??`Failed to register worktree root`)},authorizeRoot:async t=>{let n=await e.authorizeRoot?.(t);if(!n?.ok)throw Error(n?.error??`Failed to authorize folder root`);return n.path??t},listDir:async t=>{let n=await e.listDir(t);if(!n.ok||!n.entries)throw Error(n.error??`Failed to list directory`);return n.entries},readFile:async t=>{let n=await e.readFile(t);if(!n.ok||n.content===void 0)throw Error(n.error??`Failed to read file`);return{content:n.content,...n.binary===void 0?{}:{binary:n.binary}}},movePath:async(t,n)=>{let r=await e.movePath(t,n);if(!r.ok)throw Error(r.error??`Failed to move path`);return r},createFile:async(t,n)=>{let r=await e.createFile(t,n);if(!r.ok)throw Error(r.error??`Failed to create file`);return r},createFolder:async(t,n)=>{let r=await e.createFolder(t,n);if(!r.ok)throw Error(r.error??`Failed to create folder`);return r},renamePath:async(t,n)=>{let r=await e.renamePath(t,n);if(!r.ok)throw Error(r.error??`Failed to rename path`);return r},revealPath:async t=>{let n=await e.revealPath(t);if(!n.ok)throw Error(n.error??`Failed to reveal path`)},watchDir:t=>e.watchDir(t),unwatchDir:t=>e.unwatchDir(t),onDirChange:t=>e.onDirChange(t)}}function b(e,t){return{kind:`notes-vault`,label:t?`Notes: ${t.split(`/`).pop()||t}`:`Notes vault`,canPickRoot:!1,getInitialRoot:async()=>``,listDir:async t=>{if(!t)return e.map(_);let n=v(e,t);return!n||n.kind!==`folder`?[]:(n.children??[]).map(_)},readFile:async e=>({content:(await r(e)).content,binary:!1})}}var x=n();function S(e){return(0,x.jsxs)(`div`,{className:`folder-action-row`,"aria-label":`Folder actions`,children:[(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.hasSelection,onClick:e.onCopyPath,children:`Copy`}),(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.hasSelection,onClick:e.onCopyRelativePath,children:`Relative`}),(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.hasSelection||!e.canReveal,onClick:e.onReveal,children:`Finder`}),(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.canMutate,onClick:e.onCreateFile,children:`New File`}),(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.canMutate,onClick:e.onCreateFolder,children:`New Folder`}),(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:!e.hasSelection||!e.canMutate,onClick:e.onRename,children:`Rename`})]})}function C(e){let t=f(),n=(0,g.useMemo)(()=>({x:e.x,y:e.y}),[e.x,e.y]),r=[{id:`copy-path`,label:`Copy Path`,icon:(0,x.jsx)(c,{}),shortcut:t?`⇧⌘C`:`Ctrl+Shift+C`,onSelect:e.onCopyPath},{id:`copy-relative-path`,label:`Copy Relative Path`,icon:(0,x.jsx)(c,{}),shortcut:t?`⌘C`:`Ctrl+C`,onSelect:e.onCopyRelativePath},{kind:`separator`,id:`sep-reveal`},{id:`reveal`,label:e.entry.kind===`directory`?`Open Folder`:w(t),icon:(0,x.jsx)(l,{}),shortcut:t?`⌥⌘R`:`Ctrl+Alt+R`,disabled:!e.canReveal,onSelect:e.onReveal},{kind:`separator`,id:`sep-create`},{id:`new-file`,label:`New File`,icon:(0,x.jsx)(o,{}),disabled:!e.canMutate,onSelect:e.onCreateFile},{id:`new-folder`,label:`New Folder`,icon:(0,x.jsx)(l,{}),disabled:!e.canMutate,onSelect:e.onCreateFolder},{kind:`separator`,id:`sep-rename`},{id:`rename`,label:`Rename`,icon:(0,x.jsx)(i,{}),disabled:!e.canMutate,onSelect:e.onRename}];return e.canRefresh&&r.push({kind:`separator`,id:`sep-refresh`},{id:`refresh`,label:`Refresh`,icon:(0,x.jsx)(a,{}),onSelect:e.onRefresh}),(0,x.jsx)(s,{state:n,entries:r,label:`Folder actions for ${e.entry.name}`,onClose:e.onClose})}function w(e){return e?`Reveal in Finder`:/win/i.test(p())?`Show in Explorer`:`Show in File Manager`}function ee(e){return(0,x.jsxs)(`div`,{className:`folder-move-confirm`,role:`dialog`,"aria-label":`Confirm folder move`,children:[(0,x.jsxs)(`div`,{className:`folder-move-confirm__title`,children:[`Move "`,e.source.name,`" into "`,e.target.name,`"?`]}),(0,x.jsxs)(`label`,{className:`folder-move-confirm__option`,children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:e.skipChecked,onChange:t=>e.onSkipCheckedChange(t.target.checked)}),`Don't ask again for internal moves this session`]}),(0,x.jsxs)(`div`,{className:`folder-move-confirm__actions`,children:[(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,disabled:e.busy,onClick:e.onCancel,children:`Cancel`}),(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn is-primary`,disabled:e.busy,onClick:e.onConfirm,children:e.busy?`Moving...`:`Move`})]})]})}function T(e){return(0,x.jsxs)(x.Fragment,{children:[e.pendingMove&&(0,x.jsx)(ee,{source:e.pendingMove.source,target:e.pendingMove.target,busy:e.isMoving,skipChecked:e.skipMoveConfirmChecked,onSkipCheckedChange:e.onSkipMoveConfirmCheckedChange,onCancel:e.onCancelMove,onConfirm:e.onConfirmMove}),e.contextMenu&&(0,x.jsx)(C,{entry:e.contextMenu.entry,x:e.contextMenu.x,y:e.contextMenu.y,canReveal:e.canReveal,canRefresh:e.canRefresh,canMutate:e.canMutate,onClose:e.onContextMenuClose,onCopyPath:e.onCopyContextPath,onCopyRelativePath:e.onCopyContextRelativePath,onReveal:e.onRevealContextPath,onRefresh:e.onRefreshContext,onCreateFile:e.onCreateContextFile,onCreateFolder:e.onCreateContextFolder,onRename:e.onRenameContextPath})]})}function E(e){return e===null?`Open Folder`:e.split(`/`).pop()||e}function te(e){return e.split(`/`).filter(Boolean).pop()||e}function ne(e){return e.branch?e.branch:e.detached?e.head?`detached ${e.head}`:`detached`:e.head??`worktree`}function re(e){let[t,n]=(0,g.useState)(!1),r=e.gitSummary?.loading?`Git ...`:e.gitSummary?.available?`${e.gitSummary.branch??e.gitSummary.head??`detached`} / ${e.gitSummary.dirty?`dirty`:`clean`}`:e.gitSummary?.error?`Git unavailable`:null,i=e.worktreeSummary?.worktrees??[],a=e.rootPath!==null&&(e.worktreeSummary?.loading||e.worktreeSummary?.error||i.length>0),o=e.worktreeSummary?.loading?`Worktrees ...`:i.length>0?`Worktrees ${i.length}`:`Worktrees`;return(0,x.jsxs)(`div`,{className:`folder-toolbar`,children:[(0,x.jsx)(`button`,{type:`button`,className:`folder-pick-btn`,onClick:e.onPickFolder,disabled:!e.canPickRoot,children:e.canPickRoot?E(e.rootPath):e.label}),r&&(0,x.jsx)(`span`,{className:e.gitSummary?.error?`folder-git-summary is-error`:`folder-git-summary`,title:e.gitSummary?.error??void 0,children:r}),a&&(0,x.jsxs)(`div`,{className:`folder-worktree`,children:[(0,x.jsx)(`button`,{type:`button`,className:`folder-worktree-btn`,onClick:()=>n(e=>!e),disabled:e.worktreeSummary?.loading||i.length===0,title:e.worktreeSummary?.error??void 0,children:o}),t&&i.length>0&&(0,x.jsx)(`div`,{className:`folder-worktree-menu`,role:`menu`,"aria-label":`Git worktrees`,children:i.map(t=>(0,x.jsxs)(`div`,{className:`folder-worktree-row`,role:`group`,"aria-label":t.path,children:[(0,x.jsxs)(`button`,{type:`button`,className:`folder-worktree-open`,onClick:()=>{n(!1),e.onOpenWorktree?.(t.path)},children:[(0,x.jsxs)(`span`,{className:`folder-worktree-title`,children:[te(t.path),t.current&&(0,x.jsx)(`span`,{className:`folder-worktree-current`,children:`Current`})]}),(0,x.jsxs)(`span`,{className:`folder-worktree-meta`,children:[ne(t),` · `,t.path]})]}),(0,x.jsxs)(`span`,{className:`folder-worktree-actions`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:()=>e.onCopyWorktreePath?.(t.path),children:`Copy`}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>e.onRevealWorktreePath?.(t.path),children:`Finder`})]})]},t.path))})]}),e.rootPath!==null&&e.gitSummary?.available&&e.onOpenWorktreeOps&&(0,x.jsx)(`button`,{type:`button`,className:`folder-worktree-btn`,onClick:e.onOpenWorktreeOps,children:`Ops`}),e.rootPath!==null&&(0,x.jsx)(`button`,{type:`button`,className:`folder-refresh`,onClick:e.onRefresh,"aria-label":`Refresh folder`,children:`↻`})]})}async function ie(e,t){return await(await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})).json()}async function ae(e){let t=e.repoRoot??void 0;try{let n=u()?.git,r=n?await n.previewWorktreeOperation(e.folderPanelRoot,t,e.operation):null,i=r?.ok?r:await ie(`/api/dashboard/git/worktree-operation-preview`,{folderPanelRoot:e.folderPanelRoot,...t?{repoRoot:t}:{},operation:e.operation});return{ok:i.ok,preview:i.preview??null,error:i.ok?null:i.error??`Failed to preview git operation`}}catch(e){return{ok:!1,preview:null,error:e instanceof Error?e.message:`Failed to preview git operation`}}}async function D(e){let t=e.repoRoot??void 0;try{let n=u()?.git,r=n?await n.runWorktreeOperation(e.folderPanelRoot,t,e.operation,e.confirmed):null,i=r?.ok?r:await ie(`/api/dashboard/git/worktree-operation`,{folderPanelRoot:e.folderPanelRoot,...t?{repoRoot:t}:{},operation:e.operation,confirmed:e.confirmed});return{ok:i.ok,repoRoot:i.repoRoot??null,preview:i.preview??null,stdout:i.stdout??``,worktrees:i.worktrees??[],error:i.ok?null:i.error??`Git operation failed`}}catch(e){return{ok:!1,repoRoot:null,preview:null,stdout:``,worktrees:[],error:e instanceof Error?e.message:`Git operation failed`}}}function O(e){return e.length>0?e.join(` `):`Command unavailable`}function oe(e){return e.status===`running`?`Running`:e.status===`succeeded`?`Done`:e.status===`blocked`?`Blocked`:e.status===`cancelled`?`Cancelled`:`Failed`}function se(e){return e.history.length===0?null:(0,x.jsxs)(`div`,{className:`folder-worktree-history`,"aria-label":`Git worktree operation history`,children:[(0,x.jsx)(`div`,{className:`folder-worktree-history__title`,children:`Recent operations`}),e.history.map(t=>(0,x.jsxs)(`div`,{className:`folder-worktree-history__item is-${t.status}`,children:[(0,x.jsxs)(`div`,{className:`folder-worktree-history__main`,children:[(0,x.jsx)(`span`,{className:`folder-worktree-history__label`,children:t.operationLabel}),(0,x.jsx)(`span`,{className:`folder-worktree-history__status`,children:oe(t)})]}),(0,x.jsx)(`div`,{className:`folder-worktree-history__command`,title:O(t.commandPreview),children:O(t.commandPreview)}),t.stdout&&(0,x.jsx)(`pre`,{className:`folder-worktree-history__output`,children:t.stdout}),t.stderr&&(0,x.jsx)(`pre`,{className:`folder-worktree-history__output is-error`,children:t.stderr}),t.error&&(0,x.jsx)(`div`,{className:`folder-worktree-history__error`,children:t.error}),(0,x.jsx)(`button`,{type:`button`,className:`folder-worktree-history__retry`,disabled:e.busy||t.status===`running`,onClick:()=>e.onRetry(t.operation),children:`Retry with confirmation`})]},t.id))]})}function ce(e){return e.split(`/`).filter(Boolean).pop()||e}function le(e){return e?e.command.join(` `):`Preview unavailable`}function ue(e){let[t,n]=(0,g.useState)(`worktree-add`),[r,i]=(0,g.useState)(``),[a,o]=(0,g.useState)(``),[s,c]=(0,g.useState)(!1),[l,u]=(0,g.useState)(e.worktrees.find(e=>!e.current)?.path??e.worktrees[0]?.path??``),[d,f]=(0,g.useState)(!1),[p,m]=(0,g.useState)(!1),[h,_]=(0,g.useState)(!1),[v,y]=(0,g.useState)(null),[b,S]=(0,g.useState)(null),C=(0,g.useCallback)(e=>{n(e.type),m(!1),e.type===`worktree-add`&&(i(e.path),o(e.branch),c(e.createBranch)),e.type===`worktree-remove`&&(u(e.path),f(e.force))},[]),w=(0,g.useMemo)(()=>t===`worktree-add`?{type:t,path:r,branch:a,createBranch:s}:t===`worktree-remove`?{type:t,path:l,force:d}:{type:t},[a,s,d,t,l,r]);(0,g.useEffect)(()=>{let t=!1;return m(!1),_(!0),y(null),S(null),(async()=>{let n=await ae({folderPanelRoot:e.folderPanelRoot,repoRoot:e.repoRoot,operation:w});t||(_(!1),S(n.preview),y(n.error))})(),()=>{t=!0}},[w,e.folderPanelRoot,e.repoRoot]);let ee=p&&b!==null&&!v&&!h&&!e.busy,T=t===`worktree-remove`;return(0,x.jsx)(`div`,{className:`folder-worktree-ops`,role:`dialog`,"aria-label":`Git worktree operations`,children:(0,x.jsxs)(`div`,{className:`folder-worktree-ops__panel`,children:[(0,x.jsxs)(`div`,{className:`folder-worktree-ops__header`,children:[(0,x.jsx)(`span`,{children:`Worktree Ops`}),(0,x.jsx)(`button`,{type:`button`,onClick:e.onClose,disabled:e.busy,children:`Close`})]}),(0,x.jsx)(`div`,{className:`folder-worktree-ops__row`,children:(0,x.jsxs)(`label`,{children:[`Operation`,(0,x.jsxs)(`select`,{value:t,onChange:e=>n(e.target.value),disabled:e.busy,children:[(0,x.jsx)(`option`,{value:`worktree-add`,children:`Add worktree`}),(0,x.jsx)(`option`,{value:`worktree-remove`,children:`Remove worktree`}),(0,x.jsx)(`option`,{value:`worktree-prune`,children:`Prune stale worktrees`})]})]})}),t===`worktree-add`&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`folder-worktree-ops__row`,children:(0,x.jsxs)(`label`,{children:[`Path`,(0,x.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`/Users/jun/...`,disabled:e.busy})]})}),(0,x.jsxs)(`div`,{className:`folder-worktree-ops__row`,children:[(0,x.jsxs)(`label`,{children:[`Branch / ref`,(0,x.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:`feature/name`,disabled:e.busy})]}),(0,x.jsxs)(`label`,{className:`folder-worktree-ops__check`,children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:e.busy}),`Create branch`]})]})]}),T&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`folder-worktree-ops__row`,children:(0,x.jsxs)(`label`,{children:[`Worktree`,(0,x.jsx)(`select`,{value:l,onChange:e=>u(e.target.value),disabled:e.busy,children:e.worktrees.map(e=>(0,x.jsxs)(`option`,{value:e.path,children:[ce(e.path),` - `,e.path]},e.path))})]})}),(0,x.jsxs)(`label`,{className:`folder-worktree-ops__warning`,children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),disabled:e.busy}),`Force remove dirty worktree`]})]}),(0,x.jsx)(`div`,{className:`folder-worktree-ops__preview`,"aria-busy":h,children:h?`Previewing command...`:le(b)}),v&&(0,x.jsx)(`div`,{className:`folder-worktree-ops__warning`,children:v}),T&&!d&&(0,x.jsx)(`div`,{className:`folder-worktree-ops__hint`,children:`Dirty worktrees are blocked unless force remove is explicitly checked.`}),T&&d&&(0,x.jsx)(`div`,{className:`folder-worktree-ops__hint`,children:`Preview changes to git worktree remove --force for this target.`}),(0,x.jsxs)(`label`,{className:`folder-worktree-ops__check`,children:[(0,x.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),disabled:b===null||!!v||e.busy}),`I understand this will run the previewed git command.`]}),(0,x.jsxs)(`div`,{className:`folder-worktree-ops__actions`,children:[(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,onClick:e.onClose,disabled:e.busy,children:`Cancel`}),(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn is-primary`,disabled:!ee,onClick:()=>e.onRun(w,b),children:e.busy?`Running...`:`Run`})]}),(0,x.jsx)(se,{history:e.history,busy:e.busy,onRetry:C})]})})}function de(e){let t=e.lastIndexOf(`/`);return t>0?e.slice(0,t):`/`}function fe(e,t){return t===e||t.startsWith(`${e}/`)}function pe(e,t){if(!e)return t;let n=e.endsWith(`/`)?e:`${e}/`;return t.startsWith(n)?t.slice(n.length):t}function me(e,t){let n=new Map(e);for(let e of t)n.delete(e);return n}function he(e){let t=(0,g.useRef)(null);return(0,g.useEffect)(()=>{let e=t.current;e&&(e.focus(),e.select())},[e.initialName]),(0,x.jsx)(`form`,{className:`folder-inline-editor`,"aria-label":e.label,onSubmit:n=>{n.preventDefault();let r=t.current?.value.trim()??``;r&&e.onSubmit(r)},children:(0,x.jsx)(`input`,{ref:t,className:`folder-inline-editor__input`,defaultValue:e.initialName,disabled:e.busy,onBlur:()=>{e.busy||e.onCancel()},onKeyDown:t=>{t.key===`Escape`&&(t.preventDefault(),e.onCancel()),t.stopPropagation()}})})}function ge(){return p()}function _e(e){if(typeof HTMLElement>`u`||!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;let t=e.tagName.toLowerCase();return t===`input`||t===`textarea`||t===`select`||!!e.closest(`[contenteditable="true"], .cm-editor, .ProseMirror, [data-milkdown-root], [role="textbox"]`)}function k(e,t=ge()){return f(t)?e.metaKey:e.ctrlKey}function ve(e,t){if(_e(e.target??null))return null;let n=e.key.toLowerCase(),r=e.code??``,i=f(t.platform??ge())?e.metaKey:e.ctrlKey,a=i&&e.altKey&&!e.shiftKey;return t.chordActive?n===`escape`?`cancel-chord`:i||e.altKey||e.shiftKey?null:n===`p`||r===`KeyP`?`copy-path`:n===`r`||r===`KeyR`?`reveal-path`:`cancel-chord`:i&&!e.altKey&&!e.shiftKey&&(n===`k`||r===`KeyK`)?`start-chord`:a&&(n===`c`||r===`KeyC`)?`copy-path`:a&&(n===`r`||r===`KeyR`)?`reveal-path`:i&&!e.altKey&&n===`c`?e.shiftKey?`copy-path`:`copy-relative-path`:null}function A(e){window.dispatchEvent(new CustomEvent(`jaw-folder-panel-drag`,{detail:{active:e}}))}function j(e){let t=e.inlineMutation&&e.inlineMutation.kind!==`rename`&&e.inlineMutation.parentDirectory===e.parentPath?e.inlineMutation:null;return(0,x.jsxs)(x.Fragment,{children:[t&&(0,x.jsxs)(`div`,{className:`folder-entry folder-entry-inline`,children:[e.depth>0&&(0,x.jsx)(`span`,{className:`folder-indent`,"aria-hidden":`true`,children:Array.from({length:e.depth},(e,t)=>(0,x.jsx)(`span`,{className:`folder-indent-guide`},t))}),(0,x.jsx)(`span`,{className:`folder-entry-disclosure is-placeholder`,"aria-hidden":`true`,children:`·`}),(0,x.jsx)(he,{initialName:t.initialName,busy:e.isMutating,label:t.kind===`file`?`New file name`:`New folder name`,onSubmit:e.submitInlineMutation,onCancel:e.cancelInlineMutation})]}),e.entries.map(t=>(0,x.jsxs)(`div`,{children:[(()=>{let n=e.decorationsByPath.get(t.path),r=e.inlineMutation?.kind===`rename`&&e.inlineMutation.targetPath===t.path?e.inlineMutation:null;return(0,x.jsxs)(`div`,{className:[`folder-entry`,`folder-entry-${t.kind}`,n?.className??``,e.selectedPaths.has(t.path)?`is-selected`:``,e.focusedPath===t.path?`is-focused`:``,e.dropTargetPath===t.path?`is-drop-target`:``,e.dragSelection?.primaryEntry.path===t.path?`is-dragging`:``].filter(Boolean).join(` `),role:`treeitem`,"aria-selected":e.selectedPaths.has(t.path),draggable:e.canUseNativeActions,onDragStart:n=>{if(!e.canUseNativeActions)return;let r=e.getDragSelectionFor(t);e.setDragSelection(r),A(!0),n.dataTransfer.effectAllowed=`copyMove`,n.dataTransfer.setData(h,m(r)),n.dataTransfer.setData(`text/plain`,r.entries.map(e=>e.path).join(`
2
+ `))},onDragEnd:()=>{A(!1),e.setDragSelection(null),e.setDropTargetPath(null)},onDragOver:n=>{let r=e.dragSelection?.primaryEntry;r&&t.kind===`directory`&&r.path!==t.path&&(r.kind===`directory`&&fe(r.path,t.path)||(n.preventDefault(),n.dataTransfer.dropEffect=`move`,e.setDropTargetPath(t.path)))},onDragLeave:()=>{e.dropTargetPath===t.path&&e.setDropTargetPath(null)},onDrop:n=>{e.dragSelection&&t.kind===`directory`&&(n.preventDefault(),A(!1),e.setDropTargetPath(null),e.requestMove(e.dragSelection.primaryEntry,t))},children:[e.depth>0&&(0,x.jsx)(`span`,{className:`folder-indent`,"aria-hidden":`true`,children:Array.from({length:e.depth},(e,t)=>(0,x.jsx)(`span`,{className:`folder-indent-guide`},t))}),(0,x.jsx)(`button`,{type:`button`,className:t.kind===`directory`?`folder-entry-disclosure`:`folder-entry-disclosure is-placeholder`,"aria-label":t.kind===`directory`?e.expanded.has(t.path)?`Collapse ${t.name}`:`Expand ${t.name}`:void 0,"aria-expanded":t.kind===`directory`?e.expanded.has(t.path):void 0,tabIndex:t.kind===`directory`?0:-1,disabled:t.kind!==`directory`,onClick:n=>{n.stopPropagation(),t.kind===`directory`&&e.toggleEntryExpansion(t)},children:t.kind===`directory`?e.expanded.has(t.path)?`▾`:`▸`:`·`}),r?(0,x.jsx)(he,{initialName:r.initialName,busy:e.isMutating,label:`Rename`,onSubmit:e.submitInlineMutation,onCancel:e.cancelInlineMutation}):(0,x.jsxs)(`button`,{type:`button`,className:`folder-entry-btn`,"data-folder-path":t.path,onKeyDown:n=>e.handleEntryKeyDown(n,t),onContextMenu:n=>{if(n.preventDefault(),n.clientX!==0||n.clientY!==0){e.openContextMenu(t,n.clientX,n.clientY);return}let r=n.currentTarget.getBoundingClientRect();e.openContextMenu(t,r.left+8,r.bottom)},onClick:n=>e.selectEntry(t,{range:n.shiftKey,toggle:k(n),preview:!1}),onDoubleClick:()=>{t.kind===`directory`?e.toggleEntryExpansion(t):e.openFileEntry(t)},children:[(0,x.jsx)(`span`,{className:`folder-entry-name`,children:t.name}),n?.label&&(0,x.jsx)(`span`,{className:`folder-entry-git-badge`,title:n.title,"aria-label":n.title??n.label,children:n.label})]})]})})(),t.kind===`directory`&&e.expanded.has(t.path)&&e.childrenCache.has(t.path)&&(0,x.jsx)(j,{...e,entries:e.childrenCache.get(t.path),parentPath:t.path,depth:e.depth+1})]},t.path))]})}function ye(e){return(0,x.jsxs)(`div`,{className:`folder-unavailable`,children:[(0,x.jsx)(`div`,{className:`folder-unavailable__title`,children:`Folder unavailable`}),(0,x.jsx)(`div`,{className:`folder-unavailable__path`,title:e.path,children:e.path}),(0,x.jsx)(`div`,{className:`folder-unavailable__error`,children:e.error}),(0,x.jsxs)(`div`,{className:`folder-unavailable__actions`,children:[(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,onClick:e.onOpenFolder,children:`Open Folder`}),(0,x.jsx)(`button`,{type:`button`,className:`folder-action-btn`,onClick:e.onClear,children:`Clear`})]})]})}function be(e){return(0,x.jsxs)(`div`,{ref:e.treeRef,className:e.rootPath===null?`folder-tree folder-empty-root`:`folder-tree`,role:`tree`,"aria-multiselectable":`true`,children:[(0,x.jsx)(j,{entries:e.entries,parentPath:e.rootPath,depth:0,expanded:e.expanded,childrenCache:e.childrenCache,selectedPaths:e.folderSelection.selectedPaths,focusedPath:e.folderSelection.selection.focusedPath,decorationsByPath:e.decorationsByPath,dropTargetPath:e.dropTargetPath,dragSelection:e.dragSelection,inlineMutation:e.inlineMutation,isMutating:e.isMutating,canUseNativeActions:e.canUseNativeActions,setDragSelection:e.setDragSelection,setDropTargetPath:e.setDropTargetPath,getDragSelectionFor:e.folderSelection.getDragSelectionFor,requestMove:e.requestMove,handleEntryKeyDown:e.handleEntryKeyDown,selectEntry:e.selectEntry,toggleEntryExpansion:e.toggleEntryExpansion,openFileEntry:e.openFileEntry,openContextMenu:e.openContextMenu,submitInlineMutation:e.submitInlineMutation,cancelInlineMutation:e.cancelInlineMutation}),e.rootPath===null&&!e.error&&(0,x.jsx)(`div`,{className:`folder-empty-root__content`,children:`Choose a folder to browse files.`}),e.unavailableRoot&&(0,x.jsx)(ye,{path:e.unavailableRoot.path,error:e.unavailableRoot.error,onOpenFolder:e.onPickFolder,onClear:e.onClearUnavailableRoot}),e.entries.length===0&&!e.inlineMutation&&!e.error&&!e.unavailableRoot&&e.rootPath!==null&&(0,x.jsx)(`div`,{className:`folder-empty`,children:e.sourceKind===`notes-vault`?`No notes in vault`:`Empty directory`})]})}var M={selectedPaths:[],focusedPath:null,anchorPath:null};function N(e,t,n){let r=[],i=e=>{for(let a of e)r.push(a),a.kind===`directory`&&n.has(a.path)&&i(t.get(a.path)??[])};return i(e),r}function P(e,t){let n=new Set(t),r=e.selectedPaths.filter(e=>n.has(e)),i=e.focusedPath&&n.has(e.focusedPath)?e.focusedPath:r[0]??null;return{selectedPaths:r,focusedPath:i,anchorPath:e.anchorPath&&n.has(e.anchorPath)?e.anchorPath:i}}function xe(e,t,n,r={}){if(!n.includes(t))return e;if(r.range&&e.anchorPath&&n.includes(e.anchorPath))return{selectedPaths:Ce(n,e.anchorPath,t),focusedPath:t,anchorPath:e.anchorPath};if(r.toggle){let r=new Set(e.selectedPaths);return r.has(t)?r.delete(t):r.add(t),r.size===0&&r.add(t),{selectedPaths:n.filter(e=>r.has(e)),focusedPath:t,anchorPath:t}}return{selectedPaths:[t],focusedPath:t,anchorPath:t}}function F(e,t,n,r){if(t.length===0)return M;let i=e.focusedPath&&t.includes(e.focusedPath)?e.focusedPath:e.selectedPaths.find(e=>t.includes(e))??t[0],a=t.indexOf(i),o=t[Math.max(0,Math.min(t.length-1,a+(n===`down`?1:-1)))];if(r){let n=e.anchorPath&&t.includes(e.anchorPath)?e.anchorPath:i;return{selectedPaths:Ce(t,n,o),focusedPath:o,anchorPath:n}}return{selectedPaths:[o],focusedPath:o,anchorPath:o}}function Se(e,t){return e.filter(e=>t.has(e.path))}function Ce(e,t,n){let r=e.indexOf(t),i=e.indexOf(n);if(r<0||i<0)return[n];let a=Math.min(r,i),o=Math.max(r,i);return e.slice(a,o+1)}function I(e){return Array.from(e.entries())}function we(e){return new Map(e)}function Te(e,t){return!e||t&&e.rootPath!==t?null:e}function Ee(e){return{rootPath:e.rootPath,entries:e.entries,expandedPaths:Array.from(e.expanded),childrenCache:I(e.childrenCache),selection:e.selection}}function L(e){return/not a git repository/i.test(e)}async function R(e,t){return await(await fetch(`/api/dashboard/git/status-map`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({folderPanelRoot:e,...t.repoRoot?{repoRoot:t.repoRoot}:{},options:{includeIgnored:t.includeIgnored!==!1,includeUntracked:t.includeUntracked!==!1}})})).json()}async function z(e,t={}){let n=u()?.git,r=n?await n.getStatusMap(e,t.repoRoot,{includeIgnored:t.includeIgnored!==!1,includeUntracked:t.includeUntracked!==!1}):null,i=r?.ok?r:await R(e,t);if(i.ok&&i.status)return{ok:!0,status:i.status};let a=i.error??`Failed to load git status`;return{ok:!1,quiet:L(a),error:a}}var B={available:!1,loading:!1,error:null,repoRoot:null,branch:null,head:null,dirty:!1,decorationsByPath:new Map},V={modified:`M`,added:`A`,deleted:`D`,renamed:`R`,untracked:`?`,ignored:`·`,conflict:`U`,submodule:`S`};function H(e){return{className:`git-${e.kind}`,label:V[e.kind],title:[e.kind,e.staged?`staged`:``,e.unstaged?`unstaged`:``].filter(Boolean).join(` · `)}}function De(e){let t=e.kinds[0]??`modified`;return{className:`git-${t}`,label:`${V[t]}${e.changedCount>1?e.changedCount:``}`,title:`${e.changedCount} changed item${e.changedCount===1?``:`s`}`}}function U(e){let t=new Map;for(let n of e.files)t.set(n.path,H(n));for(let n of e.directories)t.set(n.path,De(n));return{available:!0,loading:!1,error:null,repoRoot:e.repoRoot,branch:e.branch,head:e.head,dirty:e.dirty,decorationsByPath:t}}function Oe(e){let{rootPath:t,repoRoot:n,enabled:r,refreshToken:i}=e,[a,o]=(0,g.useState)(B);return(0,g.useEffect)(()=>{if(!r||t===null){o(B);return}let e=!1,i=window.setTimeout(()=>{o(e=>({...e,loading:!0,error:null})),(async()=>{let r=await z(t,{...n?{repoRoot:n}:{},includeIgnored:!0,includeUntracked:!0});if(!e){if(r.ok){o(U(r.status));return}if(n&&/repo root mismatch/i.test(r.error)){let n=await z(t,{includeIgnored:!0,includeUntracked:!0});if(e)return;if(n.ok){o(U(n.status));return}o(n.quiet?B:{...B,error:n.error});return}o(r.quiet?B:{...B,error:r.error})}})()},250);return()=>{e=!0,window.clearTimeout(i)}},[r,i,n,t]),a}function W(e){return/not a git repository/i.test(e)}async function ke(e,t){return await(await fetch(`/api/dashboard/git/worktrees`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({folderPanelRoot:e,...t?{repoRoot:t}:{}})})).json()}async function G(e,t){let n=t??void 0;try{let t=u()?.git,r=t?await t.getWorktrees(e,n):null,i=r?.ok?r:await ke(e,n);if(i.ok)return{ok:!0,repoRoot:i.repoRoot??n??null,worktrees:i.worktrees??[],error:null};let a=i.error??`Failed to load git worktrees`;return{ok:!1,repoRoot:null,worktrees:[],error:W(a)?null:a}}catch(e){let t=e instanceof Error?e.message:`Failed to load git worktrees`;return{ok:!1,repoRoot:null,worktrees:[],error:W(t)?null:t}}}var K={available:!1,loading:!1,error:null,repoRoot:null,worktrees:[]};function Ae(e){let{folderPanelRoot:t,repoRoot:n,enabled:r,refreshToken:i}=e,[a,o]=(0,g.useState)(0),[s,c]=(0,g.useState)(K),l=(0,g.useCallback)(()=>o(e=>e+1),[]);return(0,g.useEffect)(()=>{if(!r||t===null){c(K);return}let e=!1;return c(e=>({...e,loading:!0,error:null})),(async()=>{let r=await G(t,n??void 0);e||c({available:r.ok&&r.worktrees.length>0,loading:!1,error:r.error,repoRoot:r.repoRoot,worktrees:r.worktrees})})(),()=>{e=!0}},[r,t,a,i,n]),(0,g.useMemo)(()=>({...s,refresh:l}),[l,s])}function je(e=1600){let[t,n]=(0,g.useState)(!1),r=(0,g.useRef)(null),i=(0,g.useCallback)(()=>{r.current!==null&&window.clearTimeout(r.current),r.current=null,n(!1)},[]),a=(0,g.useCallback)(()=>{r.current!==null&&window.clearTimeout(r.current),n(!0),r.current=window.setTimeout(()=>{r.current=null,n(!1)},e)},[e]);return(0,g.useEffect)(()=>()=>i(),[i]),{folderChordActive:t,startFolderChord:a,cancelFolderChord:i}}function Me(e){let t=e.onPreviewFile,[n,r]=(0,g.useState)(()=>e.initialSelection??M),i=(0,g.useMemo)(()=>N(e.entries,e.childrenCache,e.expanded),[e.childrenCache,e.entries,e.expanded]),a=(0,g.useMemo)(()=>i.map(e=>e.path),[i]),o=(0,g.useMemo)(()=>new Set(n.selectedPaths),[n.selectedPaths]),s=(0,g.useMemo)(()=>Se(i,o),[o,i]),c=n.focusedPath??s[0]?.path??null,l=i.find(e=>e.path===c)??s[0]??null;return(0,g.useEffect)(()=>{r(e=>P(e,a))},[a]),{selection:n,visibleEntries:i,visiblePaths:a,selectedPaths:o,selectedPath:c,selectedEntries:s,selectedEntry:l,selectEntry:(0,g.useCallback)((e,n={})=>{r(t=>xe(t,e.path,a,n)),e.kind===`file`&&n.preview!==!1&&t?.(e.path)},[t,a]),selectOnlyPath:(0,g.useCallback)(e=>{r(e&&a.includes(e)?{selectedPaths:[e],focusedPath:e,anchorPath:e}:M)},[a]),resetSelection:(0,g.useCallback)(()=>{r(M)},[]),moveKeyboardSelection:(0,g.useCallback)((e,t)=>{r(n=>F(n,a,e,t))},[a]),getDragSelectionFor:(0,g.useCallback)(e=>o.has(e.path)?{primaryEntry:e,entries:s}:{primaryEntry:e,entries:[e]},[s,o])}}var q=120,J=80;function Y(e){return e===`watch`?`Updated from file changes`:e===`move`?`Updated after move`:e===`mutation`?`Updated after file change`:e===`git-operation`?`Updated after git operation`:e===`worktree-switch`?`Updated worktree`:e===`root`?`Updated folder root`:`Updated folder`}function Ne(e){let{rootPath:t,expanded:n,source:r,loadDir:i,loadChildren:a,bumpGitRefresh:o,onGitRefresh:s,refreshWorktrees:c}=e,[l,u]=(0,g.useState)(null),[d,f]=(0,g.useState)(null),[p,m]=(0,g.useState)(!1),h=(0,g.useRef)(!1),_=(0,g.useRef)(null),v=(0,g.useRef)(null),y=(0,g.useRef)(async()=>void 0),b=(0,g.useRef)(!0);(0,g.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let x=(0,g.useCallback)(()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)},[]),S=(0,g.useCallback)(async(e,r={})=>{if(t!==null){if(h.current){let t=_.current;_.current=t?{reason:e,options:{extraPaths:Array.from(new Set([...t.options.extraPaths??[],...r.extraPaths??[]]))}}:{reason:e,options:r};return}h.current=!0,b.current&&(m(!0),u(e===`watch`?`Refreshing changed files...`:`Refreshing folder...`));try{let l=Array.from(new Set([...Array.from(n),...r.extraPaths??[]])).slice(0,J);await i(t);for(let e of l)await a(e,{force:!0});if(o(),s?.(),c(),!b.current)return;let d=Math.max(0,n.size-l.length);u(d>0?`${Y(e)}; ${d} collapsed/overflow branches skipped`:Y(e))}finally{h.current=!1,b.current&&m(!1);let e=_.current;_.current=null,e&&b.current&&y.current(e.reason,e.options)}}},[o,n,a,i,s,c,t]),C=(0,g.useCallback)(async(e=`manual`,t={})=>{await S(e,t)},[S]);(0,g.useEffect)(()=>{y.current=S},[S]);let w=(0,g.useCallback)(()=>{x(),v.current=window.setTimeout(()=>{v.current=null,y.current(`watch`)},q)},[x]);return(0,g.useEffect)(()=>{if(!r.watchDir||!r.onDirChange||t===null)return;let e=!1;(async()=>{let n=await r.watchDir?.(t);e||(n&&!n.ok?f(`Watch disabled: ${n.error??`failed to watch directory`}`):f(null))})();let n=r.onDirChange(()=>{w()});return()=>{e=!0,x(),n(),r.unwatchDir?.(t)}},[x,t,w,r]),{isRefreshing:p,refreshStatus:l,watchStatus:d,refreshVisibleTree:C}}function Pe(e){let{selectedFilePath:t,rootPath:n,selectedPath:r,visiblePaths:i,selectOnlyPath:a}=e,o=(0,g.useRef)(null);(0,g.useEffect)(()=>{let e=t??null,s=e!==o.current;s&&(o.current=e),(s||!r)&&e&&n&&fe(n,e)&&e!==r&&i.includes(e)&&a(e)},[n,a,t,r,i])}var Fe=8,Ie=0;function Le(){return Ie+=1,`folder-git-op-${Date.now()}-${Ie}`}function Re(e){return/dirty|uncommitted|confirmation required|not registered|outside home|symlink/i.test(e)}function ze(e,t){return{id:Le(),operation:e,startedAt:new Date().toISOString(),finishedAt:null,operationLabel:t?.label??e.type,commandPreview:t?.command??[],status:`running`,stdout:``,stderr:``,error:null}}function Be(e,t){return[t,...e].slice(0,Fe)}function X(e,t,n){return e.map(e=>e.id===t?n.ok?{...e,finishedAt:new Date().toISOString(),status:`succeeded`,stdout:n.stdout,error:null}:{...e,finishedAt:new Date().toISOString(),status:Re(n.error)?`blocked`:`failed`,error:n.error}:e)}function Ve(e){let{rootPath:t,source:n,worktreeState:r,openFolderRoot:i,refreshVisibleTree:a,bumpGitRefresh:o,setActionStatus:s,setError:c}=e,[l,u]=(0,g.useState)(!1),[f,p]=(0,g.useState)(!1),[m,h]=(0,g.useState)([]);return{open:l,setOpen:u,busy:f,history:m,openWorktreeRoot:(0,g.useCallback)(async e=>{await i(e,{registerGitWorktree:!0,repoRoot:r.repoRoot})},[i,r.repoRoot]),copyWorktreePath:(0,g.useCallback)(async e=>{let t=await d(e);t.ok?(s(`Copied worktree path`),c(null)):c(t.error??`Failed to copy worktree path`)},[s,c]),revealWorktreePath:(0,g.useCallback)(async e=>{if(t&&n.registerGitWorktreeRoot&&n.revealPath)try{await n.registerGitWorktreeRoot(t,r.repoRoot??void 0,e),await n.revealPath(e),s(`Opened worktree in Finder`),c(null)}catch(e){c(e.message)}},[t,s,c,n,r.repoRoot]),runWorktreeOperation:(0,g.useCallback)(async(e,n)=>{if(!t)return;let i=ze(e,n),l=!1;h(e=>Be(e,i)),p(!0);try{let n=await D({folderPanelRoot:t,repoRoot:r.repoRoot,operation:e,confirmed:!0});if(!n.ok){let e=n.error??`Git operation failed`;throw h(t=>X(t,i.id,{ok:!1,error:e})),l=!0,Error(e)}h(e=>X(e,i.id,{ok:!0,stdout:n.stdout})),l=!0,s(n.preview?.label??`Git worktree operation completed`),c(null),u(!1),r.refresh(),o(),await a(`git-operation`)}catch(e){let t=e.message;l||h(e=>X(e,i.id,{ok:!1,error:t})),c(t)}finally{p(!1)}},[o,a,t,s,c,r])}}function He(e){let[t,n]=(0,g.useState)(null),[r,i]=(0,g.useState)(!1),a=(0,g.useCallback)(()=>e.rootPath?e.selectedEntry?e.selectedEntry.kind===`directory`?e.selectedEntry.path:de(e.selectedEntry.path):e.rootPath:null,[e.rootPath,e.selectedEntry]),o=(0,g.useCallback)(t=>{let r=a();r&&(t!==`file`||e.source.createFile)&&(t!==`directory`||e.source.createFolder)&&(e.setExpanded(e=>new Set(e).add(r)),n({kind:t,parentDirectory:r,initialName:t===`file`?`untitled.txt`:`untitled`}),e.closeContextMenu())},[e,a]),s=(0,g.useCallback)(async(t,r,a)=>{let o=t===`file`?e.source.createFile:e.source.createFolder;if(!o)return;let s=t===`file`?`New file name`:`New folder name`;if(!a.trim()){e.setError(`${s} required`);return}i(!0);try{let i=(await o(r,a.trim())).entry;t===`directory`&&e.selectedEntry?.path===r&&e.setExpanded(e=>new Set(e).add(r)),e.setActionStatus(t===`file`?`Created file`:`Created folder`),e.setError(null),n(null),await e.refreshAfterMutation(r,i?.path??null)}catch(t){e.setError(t.message)}finally{i(!1)}},[e]),c=(0,g.useCallback)(()=>{e.selectedEntry&&e.source.renamePath&&(n({kind:`rename`,parentDirectory:de(e.selectedEntry.path),targetPath:e.selectedEntry.path,initialName:e.selectedEntry.name}),e.closeContextMenu())},[e]),l=(0,g.useCallback)(async(t,r)=>{if(!t.targetPath||!e.source.renamePath)return;let a=r.trim();if(!a||a===t.initialName){n(null);return}i(!0);try{let r=await e.source.renamePath(t.targetPath,a),i=t.parentDirectory,o=r.entry?.path??null,s=o?e.renamedPreviewPath(e.selectedFilePath,t.targetPath,o):null;e.setActionStatus(`Renamed`),e.setError(null),n(null),await e.refreshAfterMutation(i,o,[t.targetPath]),s&&e.onPreviewFile?.(s)}catch(t){e.setError(t.message)}finally{i(!1)}},[e]);return{inlineMutation:t,isMutating:r,requestCreateEntry:o,requestRenameSelectedEntry:c,submitInlineMutation:(0,g.useCallback)(e=>{t&&(t.kind===`rename`?l(t,e):s(t.kind,t.parentDirectory,e))},[t,s,l]),cancelInlineMutation:()=>n(null)}}function Ue(e){let[t,n]=(0,g.useState)(null);return{contextMenu:t,closeContextMenu:(0,g.useCallback)(()=>n(null),[]),openContextMenu:(0,g.useCallback)((t,r,i)=>{e.selectedPaths.has(t.path)||e.selectOnlyPath(t.path),n({entry:t,x:r,y:i})},[e])}}function We(){return u()?.folder??null}function Ge(e,t,n){return!e||!fe(t,e)?null:e===t?n:`${n}${e.slice(t.length)}`}function Z(e){let t=We(),n=e.repoRootPath??null,r=e.gitRefreshVersion??0,i=e.onGitRefresh,a=e.onRepoRootChange,o=(0,g.useRef)(!1),s=(0,g.useMemo)(()=>t?y(t):b(e.notesTree??[],e.notesRoot??null),[t,e.notesRoot,e.notesTree]),c=(0,g.useMemo)(()=>Te(e.sessionState??null,e.externalRootPath??null),[e.externalRootPath,e.sessionState]),[l,u]=(0,g.useState)(()=>c?.rootPath??null),[f,p]=(0,g.useState)(()=>c?.entries??[]),[m,h]=(0,g.useState)(()=>new Set(c?.expandedPaths??[])),[_,v]=(0,g.useState)(()=>c?we(c.childrenCache):new Map),[C,w]=(0,g.useState)(null),[ee,E]=(0,g.useState)(null),[te,ne]=(0,g.useState)(null),[ie,ae]=(0,g.useState)(null),[D,O]=(0,g.useState)(null),[oe,se]=(0,g.useState)(!1),[ce,le]=(0,g.useState)(!1),[he,ge]=(0,g.useState)(!1),[_e,k]=(0,g.useState)(null),[A,j]=(0,g.useState)(0),ye=(0,g.useRef)(null),M=(0,g.useRef)(!1),N=(0,g.useRef)(null),{folderChordActive:P,startFolderChord:xe,cancelFolderChord:F}=je(),Se=e.onPreviewFile,Ce=e.selectedFilePath,I=Me({entries:f,childrenCache:_,expanded:m,initialSelection:c?.selection,onPreviewFile:Se}),L=I.selectedEntry,R=I.selectedEntries,z=Ue({selectedPaths:I.selectedPaths,selectOnlyPath:I.selectOnlyPath});Pe({selectedFilePath:e.selectedFilePath,rootPath:l,selectedPath:I.selectedPath,visiblePaths:I.visiblePaths,selectOnlyPath:I.selectOnlyPath}),(0,g.useEffect)(()=>{e.onSessionStateChange?.(Ee({rootPath:l,entries:f,expanded:m,childrenCache:_,selection:I.selection}))},[_,f,m,I.selection,e.onSessionStateChange,l]);let B=(0,g.useCallback)(async e=>{try{let t=await s.listDir(e);return p(t),w(null),E(t=>t?.path===e?null:t),{ok:!0}}catch(e){let t=e.message;return w(t),{ok:!1,error:t}}},[s]),V=(0,g.useCallback)(async(t,n={})=>{try{let r=t;if(n.registerGitWorktree){if(!l)throw Error(`Current folder root required`);await s.registerGitWorktreeRoot?.(l,n.repoRoot??void 0,t)}else s.authorizeRoot&&(r=await s.authorizeRoot(t));l&&s.unwatchDir&&s.unwatchDir(l),e.onRootChange?.(r),u(r),h(new Set),v(new Map),p([]),I.resetSelection(),w(null),E(null);let i=await B(r);i.ok||E({path:r,error:i.error}),j(e=>e+1)}catch(e){w(e.message)}},[I,B,e,l,s]),H=(0,g.useCallback)(async(e,t={})=>{if(t.force||!_.has(e))try{let t=await s.listDir(e);v(n=>new Map(n).set(e,t))}catch(e){w(e.message)}},[_,s]),De=(0,g.useCallback)(()=>{j(e=>e+1)},[]),U=(0,g.useCallback)(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),H(e)),n})},[H]),W=(0,g.useCallback)(async()=>{if(s.pickRoot)try{let e=await s.pickRoot();e&&await V(e)}catch(e){w(e.message)}},[V,s]),ke=(0,g.useCallback)(()=>{e.onRootChange?.(null),u(null),p([]),I.resetSelection(),E(null),w(null)},[I,e]);(0,g.useEffect)(()=>{if(o.current||l!==null||e.externalRootPath)return;let t=!1;return(async()=>{let e=await s.getInitialRoot();t||(o.current=!0,u(e),e!==null&&await B(e))})(),()=>{t=!0}},[B,e.externalRootPath,l,s]),(0,g.useEffect)(()=>{let t=e.externalRootPath;if(t){if(t===l){if(f.length>0||N.current===t)return;N.current=t}else N.current=null;V(t)}},[f.length,V,e.externalRootPath,l]);let G=Oe({rootPath:l,enabled:s.kind===`electron-folder`,refreshToken:A+r}),K=Ae({folderPanelRoot:l,repoRoot:G.repoRoot??n,enabled:s.kind===`electron-folder`&&G.available,refreshToken:A+r}),q=Ne({rootPath:l,expanded:m,source:s,loadDir:B,loadChildren:H,bumpGitRefresh:De,onGitRefresh:i,refreshWorktrees:K.refresh}),J=q.refreshVisibleTree,Y=Ve({rootPath:l,source:s,worktreeState:K,openFolderRoot:V,refreshVisibleTree:J,bumpGitRefresh:De,setActionStatus:k,setError:w});(0,g.useEffect)(()=>{G.repoRoot&&G.repoRoot!==n&&a?.(G.repoRoot)},[G.repoRoot,a,n]);let Fe=s.kind===`electron-folder`,Ie=!!(s.createFile&&s.createFolder&&s.renamePath),Le=(0,g.useCallback)(async(e,t)=>{if(!l)return;let n=de(e);v(e=>me(e,[n,t])),await J(`move`,{extraPaths:[n,t]})},[J,l]),Re=(0,g.useCallback)(async(e,t,n=[])=>{l&&(v(t=>me(t,[e,...n])),await J(`mutation`,{extraPaths:[e]}),t&&I.selectOnlyPath(t))},[I,J,l]),ze=(0,g.useCallback)(async e=>{if(s.movePath){se(!0);try{let t=(await s.movePath(e.source.path,e.target.path)).moved?.to??e.source.path;I.selectOnlyPath(t),k(`Moved ${e.source.name}`),O(null),await Le(e.source.path,e.target.path)}catch(e){w(e.message)}finally{se(!1)}}},[I,Le,s]),Be=(0,g.useCallback)((e,t)=>{if(!s.movePath||e.path===t.path||e.kind===`directory`&&fe(e.path,t.path))return;let n={source:e,target:t};if(ce){ze(n);return}ge(!1),O(n)},[ze,ce,s.movePath]),X=He({rootPath:l,selectedEntry:L,selectedFilePath:Ce,source:s,folderSelection:I,refreshAfterMutation:Re,renamedPreviewPath:Ge,onPreviewFile:Se,closeContextMenu:z.closeContextMenu,setExpanded:h,setActionStatus:k,setError:w}),Z=(0,g.useCallback)((e,t)=>{I.selectEntry(e,t),z.closeContextMenu()},[z,I]),Ke=(0,g.useCallback)(e=>{e.kind===`file`&&Z(e)},[Z]),Q=(0,g.useCallback)(e=>{I.selectEntry(e,{preview:!1}),z.closeContextMenu(),e.kind===`directory`&&U(e.path)},[z,I,U]),qe=(0,g.useCallback)(async(e,t)=>{let n=t===`relative`?pe(l,e.path):e.path,r=await d(n);r.ok?(I.selectOnlyPath(e.path),k(t===`relative`?`Copied relative path`:`Copied path`),w(null)):w(r.error??`Failed to copy path`)},[I,l]),Je=(0,g.useCallback)(async e=>{if(s.revealPath)try{await s.revealPath(e.path),I.selectOnlyPath(e.path),k(e.kind===`directory`?`Opened folder in Finder`:`Revealed file in Finder`),w(null)}catch(e){w(e.message)}},[I,s]),$=(0,g.useCallback)(async e=>{if(R.length===0)return;let t=R.map(t=>e===`relative`?pe(l,t.path):t.path).join(`
3
+ `),n=await d(t);n.ok?(k(e===`relative`?`Copied relative paths`:`Copied paths`),w(null)):w(n.error??`Failed to copy paths`)},[l,R]),Ye=(0,g.useCallback)(async()=>{L&&await Je(L)},[Je,L]),Xe=(0,g.useCallback)((e,t)=>{if(e.key===`ArrowUp`||e.key===`ArrowDown`){e.preventDefault(),e.stopPropagation(),I.moveKeyboardSelection(e.key===`ArrowDown`?`down`:`up`,e.shiftKey);return}if(e.key===`ArrowRight`){e.preventDefault(),t.kind===`directory`&&!m.has(t.path)&&Q(t);return}if(e.key===`ArrowLeft`){e.preventDefault(),t.kind===`directory`&&m.has(t.path)&&Q(t);return}let n=ve(e,{chordActive:P});if(n){e.preventDefault(),e.stopPropagation(),n===`start-chord`&&xe(),n===`cancel-chord`&&F();let r=I.selectedPaths.has(t.path);n===`copy-path`&&(F(),r?$(`absolute`):qe(t,`absolute`)),n===`copy-relative-path`&&(F(),r?$(`relative`):qe(t,`relative`)),n===`reveal-path`&&(F(),r?Ye():Je(t));return}if(e.key===`Enter`){e.preventDefault(),t.kind===`directory`?Q(t):Z(t);return}e.key===` `&&(e.preventDefault(),Z(t))},[F,qe,$,m,P,I,Je,Ye,Z,xe,Q]);return(0,g.useEffect)(()=>{let e=z.contextMenu!==null,t=M.current&&!e;if(M.current=e,e||t&&document.activeElement!==document.body&&!document.activeElement?.matches(`.folder-entry-btn[data-folder-path]`))return;let n=I.selection.focusedPath;if(!n)return;let r=ye.current?.querySelectorAll(`.folder-entry-btn[data-folder-path]`);Array.from(r??[]).find(e=>e.dataset.folderPath===n)?.focus()},[I.selection.focusedPath,z.contextMenu]),(0,x.jsxs)(`div`,{className:`folder-panel`,children:[(0,x.jsx)(re,{canPickRoot:s.canPickRoot,label:s.label,rootPath:l,onPickFolder:()=>void W(),onRefresh:()=>{l!==null&&J(`manual`)},gitSummary:s.kind===`electron-folder`?G:void 0,worktreeSummary:s.kind===`electron-folder`?K:void 0,onOpenWorktree:e=>void Y.openWorktreeRoot(e),onCopyWorktreePath:e=>void Y.copyWorktreePath(e),onRevealWorktreePath:e=>void Y.revealWorktreePath(e),onOpenWorktreeOps:()=>Y.setOpen(!0)}),l!==null&&(0,x.jsx)(S,{hasSelection:!!L,canReveal:!!s.revealPath,onCopyPath:()=>void $(`absolute`),onCopyRelativePath:()=>void $(`relative`),onReveal:()=>void Ye(),canMutate:Ie,onCreateFile:()=>X.requestCreateEntry(`file`),onCreateFolder:()=>X.requestCreateEntry(`directory`),onRename:()=>X.requestRenameSelectedEntry()}),C&&(0,x.jsx)(`div`,{className:`folder-error`,children:C}),q.watchStatus&&!C&&(0,x.jsx)(`div`,{className:`folder-status`,children:q.watchStatus}),q.refreshStatus&&!C&&!q.watchStatus&&(0,x.jsx)(`div`,{className:`folder-status`,children:q.refreshStatus}),_e&&!C&&!q.refreshStatus&&!q.watchStatus&&(0,x.jsx)(`div`,{className:`folder-status`,children:_e}),P&&(0,x.jsx)(`div`,{className:`folder-shortcut-hint`,children:`Folder shortcut: press P to copy path or R to reveal`}),Y.open&&l!==null&&(0,x.jsx)(ue,{folderPanelRoot:l,repoRoot:K.repoRoot,worktrees:K.worktrees,busy:Y.busy,history:Y.history,onRun:(e,t)=>void Y.runWorktreeOperation(e,t),onClose:()=>Y.setOpen(!1)}),(0,x.jsx)(be,{treeRef:ye,rootPath:l,error:C,entries:f,expanded:m,childrenCache:_,folderSelection:I,decorationsByPath:G.decorationsByPath,dropTargetPath:ie,dragSelection:te,inlineMutation:X.inlineMutation,isMutating:X.isMutating,canUseNativeActions:Fe,sourceKind:s.kind,unavailableRoot:ee,setDragSelection:ne,setDropTargetPath:ae,requestMove:Be,handleEntryKeyDown:Xe,selectEntry:Z,toggleEntryExpansion:Q,openFileEntry:Ke,openContextMenu:z.openContextMenu,submitInlineMutation:X.submitInlineMutation,cancelInlineMutation:X.cancelInlineMutation,onPickFolder:()=>void W(),onClearUnavailableRoot:ke}),(0,x.jsx)(T,{pendingMove:D,contextMenu:z.contextMenu,isMoving:oe,skipMoveConfirmChecked:he,canReveal:!!s.revealPath,canRefresh:!!l,canMutate:Ie,onSkipMoveConfirmCheckedChange:ge,onCancelMove:()=>O(null),onConfirmMove:()=>{D&&(he&&le(!0),ze(D))},onContextMenuClose:z.closeContextMenu,onCopyContextPath:()=>{z.closeContextMenu(),$(`absolute`)},onCopyContextRelativePath:()=>{z.closeContextMenu(),$(`relative`)},onRevealContextPath:()=>{z.closeContextMenu(),Ye()},onRefreshContext:()=>{z.closeContextMenu(),J(`manual`)},onCreateContextFile:()=>X.requestCreateEntry(`file`),onCreateContextFolder:()=>X.requestCreateEntry(`directory`),onRenameContextPath:()=>X.requestRenameSelectedEntry()})]})}export{Z as FolderPanel};
@@ -1 +1 @@
1
- .folder-panel{flex-direction:column;min-width:0;height:100%;min-height:0;font-size:12px;display:flex;overflow:hidden}.folder-unavailable{width:100%;max-width:320px;color:var(--text-dim);text-align:left;gap:7px;padding:14px;display:grid}.folder-unavailable__title{color:var(--text-base);font-size:12px;font-weight:600}.folder-unavailable__path,.folder-unavailable__error{text-overflow:ellipsis;white-space:nowrap;min-width:0;font-size:11px;overflow:hidden}.folder-unavailable__error{color:var(--status-error)}.folder-unavailable__actions{gap:6px;display:flex}.folder-toolbar{border-bottom:1px solid var(--border-subtle);flex-shrink:0;align-items:center;gap:6px;padding:6px 10px;display:flex}.folder-pick-btn{all:unset;cursor:pointer;color:var(--text-base);background:var(--bg-hover);text-overflow:ellipsis;white-space:nowrap;border-radius:4px;max-width:200px;padding:3px 8px;font-size:11px;overflow:hidden}.folder-pick-btn:hover{background:var(--bg-active)}.folder-git-summary{text-overflow:ellipsis;white-space:nowrap;min-width:0;max-width:140px;color:var(--text-dim);font-size:11px;overflow:hidden}.folder-git-summary.is-error{color:var(--status-error)}.folder-worktree{flex:none;position:relative}.folder-worktree-btn{all:unset;box-sizing:border-box;cursor:pointer;color:var(--text-dim);background:var(--bg-hover);white-space:nowrap;border-radius:3px;padding:2px 6px;font-size:11px}.folder-worktree-btn:hover:not(:disabled){color:var(--text-base);background:var(--bg-active)}.folder-worktree-btn:disabled{cursor:default;opacity:.55}.folder-worktree-menu{z-index:70;border:1px solid var(--border-subtle);background:var(--bg-elevated);border-radius:5px;width:min(320px,100vw - 24px);max-width:calc(100vw - 24px);max-height:min(320px,100vh - 120px);padding:5px;position:absolute;top:calc(100% + 5px);left:0;overflow:auto;box-shadow:0 12px 28px #00000047}.folder-worktree-row{border-radius:4px;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:6px;padding:4px;display:grid}.folder-worktree-row:hover{background:var(--bg-hover)}.folder-worktree-open{all:unset;cursor:pointer;min-width:0}.folder-worktree-title{min-width:0;color:var(--text-base);align-items:center;gap:6px;font-size:12px;line-height:1.25;display:flex}.folder-worktree-current{color:var(--accent-primary);background:color-mix(in srgb, var(--accent-primary) 11%, transparent);border-radius:3px;flex:none;padding:1px 4px;font-size:10px}.folder-worktree-meta{text-overflow:ellipsis;white-space:nowrap;color:var(--text-dim);margin-top:2px;font-size:10px;line-height:1.25;display:block;overflow:hidden}.folder-worktree-actions{gap:4px;display:inline-flex}.folder-worktree-actions button{all:unset;box-sizing:border-box;cursor:pointer;color:var(--text-dim);background:var(--bg-hover);border-radius:3px;padding:2px 5px;font-size:10px}.folder-worktree-actions button:hover,.folder-worktree-actions button:focus-visible{color:var(--text-base);background:var(--bg-active)}.folder-refresh{all:unset;cursor:pointer;color:var(--text-dim);border-radius:3px;padding:2px 6px}.folder-refresh:hover{background:var(--bg-hover);color:var(--text-base)}.folder-action-row{border-bottom:1px solid var(--border-subtle);flex-shrink:0;align-items:center;gap:4px;padding:5px 10px;display:flex}.folder-action-btn{all:unset;box-sizing:border-box;cursor:pointer;color:var(--text-dim);background:var(--bg-hover);border-radius:3px;padding:2px 6px;font-size:11px}.folder-action-btn:hover:not(:disabled){color:var(--text-base);background:var(--bg-active)}.folder-action-btn:disabled{cursor:default;opacity:.45}.folder-action-btn.is-primary{color:var(--accent-primary)}.folder-error{color:var(--status-error);padding:8px 10px;font-size:11px}.folder-status{color:var(--text-dim);padding:6px 10px;font-size:11px}.folder-shortcut-hint{border-bottom:1px solid var(--border-subtle);color:var(--accent-primary);background:color-mix(in srgb, var(--accent-primary) 9%, transparent);padding:5px 10px;font-size:11px}.folder-worktree-ops{border-bottom:1px solid var(--border-subtle);background:var(--bg-elevated);padding:6px 10px}.folder-worktree-ops__panel{border:1px solid var(--border-subtle);background:var(--bg-base);border-radius:5px;gap:7px;padding:7px;display:grid}.folder-worktree-ops__header,.folder-worktree-ops__actions{justify-content:space-between;align-items:center;gap:8px;display:flex}.folder-worktree-ops__header{color:var(--text-base);font-size:12px;font-weight:600}.folder-worktree-ops__header button{all:unset;cursor:pointer;color:var(--text-dim);font-size:10px}.folder-worktree-ops__row{grid-template-columns:minmax(0,1fr);gap:6px;display:grid}.folder-worktree-ops__row label,.folder-worktree-ops__check{min-width:0;color:var(--text-dim);gap:3px;font-size:10px;display:grid}.folder-worktree-ops__check{align-items:center;display:flex}.folder-worktree-ops input,.folder-worktree-ops select{box-sizing:border-box;border:1px solid var(--border-subtle);width:100%;min-width:0;color:var(--text-base);background:var(--bg-elevated);border-radius:4px;padding:4px 6px;font-size:11px}.folder-worktree-ops input[type=checkbox]{width:auto}.folder-worktree-ops__preview{color:var(--text-base);background:var(--bg-hover);font-family:var(--font-mono,ui-monospace, SFMono-Regular, Menlo, monospace);text-overflow:ellipsis;white-space:nowrap;border-radius:4px;padding:5px 6px;font-size:10px;overflow:hidden}.folder-worktree-ops__warning{color:var(--status-error);align-items:center;gap:5px;font-size:10px;display:flex}.folder-worktree-ops__hint{color:var(--text-dim);font-size:10px}.folder-worktree-history{gap:6px;max-height:220px;padding-top:2px;display:grid;overflow:auto}.folder-worktree-history__title{color:var(--text-dim);font-size:10px;font-weight:600}.folder-worktree-history__item{border:1px solid var(--border-subtle);background:var(--bg-elevated);border-radius:4px;gap:4px;padding:6px;display:grid}.folder-worktree-history__main{justify-content:space-between;align-items:center;gap:8px;min-width:0;display:flex}.folder-worktree-history__label,.folder-worktree-history__command{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.folder-worktree-history__label{color:var(--text-base);font-size:11px;font-weight:600}.folder-worktree-history__status{color:var(--text-dim);flex:none;font-size:10px}.folder-worktree-history__item.is-succeeded .folder-worktree-history__status{color:#15803d}.folder-worktree-history__item.is-failed .folder-worktree-history__status,.folder-worktree-history__item.is-blocked .folder-worktree-history__status{color:var(--status-error)}.folder-worktree-history__command,.folder-worktree-history__output{font-family:var(--font-mono,ui-monospace, SFMono-Regular, Menlo, monospace);font-size:10px}.folder-worktree-history__command{color:var(--text-dim)}.folder-worktree-history__output{max-height:84px;color:var(--text-base);background:var(--bg-hover);white-space:pre-wrap;border-radius:4px;margin:0;padding:5px;overflow:auto}.folder-worktree-history__output.is-error,.folder-worktree-history__error{color:var(--status-error)}.folder-worktree-history__error{font-size:10px}.folder-worktree-history__retry{all:unset;box-sizing:border-box;cursor:pointer;color:var(--text-dim);background:var(--bg-hover);border-radius:3px;justify-self:start;padding:2px 6px;font-size:10px}.folder-worktree-history__retry:hover:not(:disabled),.folder-worktree-history__retry:focus-visible{color:var(--text-base);background:var(--bg-active)}.folder-worktree-history__retry:disabled{cursor:default;opacity:.45}.folder-mutation-dialog{z-index:20;background:color-mix(in srgb, var(--bg-base) 38%, transparent);justify-content:center;align-items:flex-start;padding-top:48px;display:flex;position:absolute;inset:0}.folder-mutation-dialog__panel{border:1px solid var(--border-subtle);background:var(--bg-elevated);border-radius:6px;gap:8px;width:min(260px,100% - 24px);padding:10px;display:grid;box-shadow:0 14px 40px #00000052}.folder-mutation-dialog__title{color:var(--text-base);font-size:12px;font-weight:600}.folder-mutation-dialog__input{box-sizing:border-box;border:1px solid var(--border-subtle);width:100%;color:var(--text-base);background:var(--bg-base);border-radius:4px;padding:6px 7px;font-size:12px}.folder-mutation-dialog__actions{justify-content:flex-end;gap:6px;display:flex}.folder-mutation-dialog__actions button{border:1px solid var(--border-subtle);color:var(--text-base);background:var(--bg-hover);border-radius:4px;padding:4px 8px;font-size:11px}.folder-tree{flex:1;min-height:0;padding:4px 0;overflow-y:auto}.folder-empty-root{justify-content:center;align-items:center;display:flex}.folder-empty-root__content{color:var(--text-dim);text-align:center;padding:12px;font-size:11px;line-height:1.4}.folder-entry{align-items:stretch;padding-left:8px;display:flex}.folder-entry:hover{background:var(--bg-hover)}.folder-entry.is-selected{background:color-mix(in srgb, var(--accent-primary) 8%, transparent)}.folder-entry.is-focused{box-shadow:inset 2px 0 0 color-mix(in srgb, var(--accent-primary) 64%, transparent)}.folder-entry.is-selected.is-focused{background:color-mix(in srgb, var(--accent-primary) 13%, transparent)}.folder-entry.is-drop-target{background:color-mix(in srgb, var(--accent-primary) 16%, transparent);outline:1px solid color-mix(in srgb, var(--accent-primary) 44%, transparent);outline-offset:-1px}.folder-entry.is-dragging{opacity:.58}.folder-entry-inline{background:color-mix(in srgb, var(--accent-primary) 7%, transparent)}.folder-indent{flex-shrink:0;display:flex}.folder-indent-guide{border-left:1px solid var(--border-subtle);width:8px}.folder-entry-btn{all:unset;cursor:pointer;box-sizing:border-box;min-width:0;color:var(--text-base);flex:1;align-items:center;gap:4px;padding:2px 10px 2px 4px;font-size:12px;display:flex}.folder-entry-btn:focus-visible{outline:1px solid color-mix(in srgb, var(--accent-primary) 56%, transparent);outline-offset:-1px;background:color-mix(in srgb, var(--accent-primary) 10%, transparent)}.folder-entry[aria-selected=true]{background:color-mix(in srgb, var(--accent-primary) 12%, transparent)}.folder-entry[aria-selected=true] .folder-entry-btn{color:var(--accent-primary)}.folder-entry-disclosure{all:unset;box-sizing:border-box;cursor:pointer;width:18px;height:22px;color:var(--text-base);flex:0 0 18px;justify-content:center;align-items:center;font-size:14px;font-weight:700;line-height:1;display:inline-flex}.folder-entry-disclosure:hover:not(:disabled),.folder-entry-disclosure:focus-visible{background:color-mix(in srgb, var(--accent-primary) 12%, transparent);outline:1px solid color-mix(in srgb, var(--accent-primary) 42%, transparent);outline-offset:-1px}.folder-entry-disclosure.is-placeholder{cursor:default;color:var(--text-dim);opacity:.58}.folder-entry-name{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.folder-entry-directory .folder-entry-name{font-weight:500}.folder-inline-editor{box-sizing:border-box;flex:1;align-items:center;min-width:0;height:22px;padding:1px 10px 1px 4px;display:flex}.folder-inline-editor__input{box-sizing:border-box;border:1px solid color-mix(in srgb, var(--accent-primary) 48%, var(--border-subtle));width:100%;min-width:0;height:20px;color:var(--text-base);background:var(--bg-base);font:inherit;border-radius:3px;outline:none;padding:1px 5px}.folder-inline-editor__input:focus{box-shadow:0 0 0 1px color-mix(in srgb, var(--accent-primary) 38%, transparent)}.folder-entry-git-badge{min-width:16px;max-width:28px;height:16px;color:var(--text-dim);background:0 0;border-radius:3px;flex:none;justify-content:center;align-items:center;margin-left:auto;padding:0 3px;font-size:10px;line-height:1;display:inline-flex}.folder-entry.git-modified .folder-entry-git-badge{color:#b7791f;background:#b7791f1f}.folder-entry.git-added .folder-entry-git-badge,.folder-entry.git-untracked .folder-entry-git-badge{color:#15803d;background:#15803d1f}.folder-entry.git-deleted .folder-entry-git-badge,.folder-entry.git-conflict .folder-entry-git-badge{color:#dc2626;background:#dc26261f}.folder-entry.git-renamed .folder-entry-git-badge{color:#0f766e;background:#0f766e1f}.folder-entry.git-ignored .folder-entry-git-badge{color:var(--text-dim);opacity:.62}.folder-entry.git-submodule .folder-entry-git-badge{color:#4f46e5;background:#4f46e51f}.folder-move-confirm{border-top:1px solid var(--border-subtle);background:var(--bg-elevated);padding:8px 10px;box-shadow:0 -8px 18px #0000002e}.folder-move-confirm__title{color:var(--text-base);margin-bottom:7px;font-size:12px;line-height:1.35}.folder-move-confirm__option{color:var(--text-dim);align-items:center;gap:6px;margin-bottom:8px;font-size:11px;display:flex}.folder-move-confirm__actions{justify-content:flex-end;gap:6px;display:flex}.folder-context-menu{z-index:80;border:1px solid var(--border-subtle);background:var(--bg-elevated);border-radius:5px;min-width:156px;max-width:min(240px,100vw - 16px);padding:4px;position:fixed;box-shadow:0 10px 24px #00000042}.folder-context-menu button{all:unset;box-sizing:border-box;width:100%;color:var(--text-base);text-overflow:ellipsis;white-space:nowrap;border-radius:3px;padding:5px 8px;font-size:12px;line-height:1.2;display:block;overflow:hidden}.folder-context-menu button:hover:not(:disabled),.folder-context-menu button:focus-visible{background:var(--bg-hover)}.folder-context-menu button:disabled{color:var(--text-dim);opacity:.45}.folder-empty{color:var(--text-dim);text-align:center;padding:12px;font-size:11px}
1
+ .folder-panel{flex-direction:column;min-width:0;height:100%;min-height:0;font-size:12px;display:flex;overflow:hidden}.folder-unavailable{width:100%;max-width:320px;color:var(--text-dim);text-align:left;gap:7px;padding:14px;display:grid}.folder-unavailable__title{color:var(--text-base);font-size:12px;font-weight:600}.folder-unavailable__path,.folder-unavailable__error{text-overflow:ellipsis;white-space:nowrap;min-width:0;font-size:11px;overflow:hidden}.folder-unavailable__error{color:var(--status-error)}.folder-unavailable__actions{gap:6px;display:flex}.folder-toolbar{border-bottom:1px solid var(--border-subtle);flex-shrink:0;align-items:center;gap:6px;padding:6px 10px;display:flex}.folder-pick-btn{all:unset;cursor:pointer;color:var(--text-base);background:var(--bg-hover);text-overflow:ellipsis;white-space:nowrap;border-radius:4px;max-width:200px;padding:3px 8px;font-size:11px;overflow:hidden}.folder-pick-btn:hover{background:var(--bg-active)}.folder-git-summary{text-overflow:ellipsis;white-space:nowrap;min-width:0;max-width:140px;color:var(--text-dim);font-size:11px;overflow:hidden}.folder-git-summary.is-error{color:var(--status-error)}.folder-worktree{flex:none;position:relative}.folder-worktree-btn{all:unset;box-sizing:border-box;cursor:pointer;color:var(--text-dim);background:var(--bg-hover);white-space:nowrap;border-radius:3px;padding:2px 6px;font-size:11px}.folder-worktree-btn:hover:not(:disabled){color:var(--text-base);background:var(--bg-active)}.folder-worktree-btn:disabled{cursor:default;opacity:.55}.folder-worktree-menu{z-index:70;border:1px solid var(--border-subtle);background:var(--bg-elevated);border-radius:5px;width:min(320px,100vw - 24px);max-width:calc(100vw - 24px);max-height:min(320px,100vh - 120px);padding:5px;position:absolute;top:calc(100% + 5px);left:0;overflow:auto;box-shadow:0 12px 28px #00000047}.folder-worktree-row{border-radius:4px;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:6px;padding:4px;display:grid}.folder-worktree-row:hover{background:var(--bg-hover)}.folder-worktree-open{all:unset;cursor:pointer;min-width:0}.folder-worktree-title{min-width:0;color:var(--text-base);align-items:center;gap:6px;font-size:12px;line-height:1.25;display:flex}.folder-worktree-current{color:var(--accent-primary);background:color-mix(in srgb, var(--accent-primary) 11%, transparent);border-radius:3px;flex:none;padding:1px 4px;font-size:10px}.folder-worktree-meta{text-overflow:ellipsis;white-space:nowrap;color:var(--text-dim);margin-top:2px;font-size:10px;line-height:1.25;display:block;overflow:hidden}.folder-worktree-actions{gap:4px;display:inline-flex}.folder-worktree-actions button{all:unset;box-sizing:border-box;cursor:pointer;color:var(--text-dim);background:var(--bg-hover);border-radius:3px;padding:2px 5px;font-size:10px}.folder-worktree-actions button:hover,.folder-worktree-actions button:focus-visible{color:var(--text-base);background:var(--bg-active)}.folder-refresh{all:unset;cursor:pointer;color:var(--text-dim);border-radius:3px;padding:2px 6px}.folder-refresh:hover{background:var(--bg-hover);color:var(--text-base)}.folder-action-row{border-bottom:1px solid var(--border-subtle);flex-shrink:0;align-items:center;gap:4px;padding:5px 10px;display:flex}.folder-action-btn{all:unset;box-sizing:border-box;cursor:pointer;color:var(--text-dim);background:var(--bg-hover);border-radius:3px;padding:2px 6px;font-size:11px}.folder-action-btn:hover:not(:disabled){color:var(--text-base);background:var(--bg-active)}.folder-action-btn:disabled{cursor:default;opacity:.45}.folder-action-btn.is-primary{color:var(--accent-primary)}.folder-error{color:var(--status-error);padding:8px 10px;font-size:11px}.folder-status{color:var(--text-dim);padding:6px 10px;font-size:11px}.folder-shortcut-hint{border-bottom:1px solid var(--border-subtle);color:var(--accent-primary);background:color-mix(in srgb, var(--accent-primary) 9%, transparent);padding:5px 10px;font-size:11px}.folder-worktree-ops{border-bottom:1px solid var(--border-subtle);background:var(--bg-elevated);padding:6px 10px}.folder-worktree-ops__panel{border:1px solid var(--border-subtle);background:var(--bg-base);border-radius:5px;gap:7px;padding:7px;display:grid}.folder-worktree-ops__header,.folder-worktree-ops__actions{justify-content:space-between;align-items:center;gap:8px;display:flex}.folder-worktree-ops__header{color:var(--text-base);font-size:12px;font-weight:600}.folder-worktree-ops__header button{all:unset;cursor:pointer;color:var(--text-dim);font-size:10px}.folder-worktree-ops__row{grid-template-columns:minmax(0,1fr);gap:6px;display:grid}.folder-worktree-ops__row label,.folder-worktree-ops__check{min-width:0;color:var(--text-dim);gap:3px;font-size:10px;display:grid}.folder-worktree-ops__check{align-items:center;display:flex}.folder-worktree-ops input,.folder-worktree-ops select{box-sizing:border-box;border:1px solid var(--border-subtle);width:100%;min-width:0;color:var(--text-base);background:var(--bg-elevated);border-radius:4px;padding:4px 6px;font-size:11px}.folder-worktree-ops input[type=checkbox]{width:auto}.folder-worktree-ops__preview{color:var(--text-base);background:var(--bg-hover);font-family:var(--font-mono,ui-monospace, SFMono-Regular, Menlo, monospace);text-overflow:ellipsis;white-space:nowrap;border-radius:4px;padding:5px 6px;font-size:10px;overflow:hidden}.folder-worktree-ops__warning{color:var(--status-error);align-items:center;gap:5px;font-size:10px;display:flex}.folder-worktree-ops__hint{color:var(--text-dim);font-size:10px}.folder-worktree-history{gap:6px;max-height:220px;padding-top:2px;display:grid;overflow:auto}.folder-worktree-history__title{color:var(--text-dim);font-size:10px;font-weight:600}.folder-worktree-history__item{border:1px solid var(--border-subtle);background:var(--bg-elevated);border-radius:4px;gap:4px;padding:6px;display:grid}.folder-worktree-history__main{justify-content:space-between;align-items:center;gap:8px;min-width:0;display:flex}.folder-worktree-history__label,.folder-worktree-history__command{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.folder-worktree-history__label{color:var(--text-base);font-size:11px;font-weight:600}.folder-worktree-history__status{color:var(--text-dim);flex:none;font-size:10px}.folder-worktree-history__item.is-succeeded .folder-worktree-history__status{color:#15803d}.folder-worktree-history__item.is-failed .folder-worktree-history__status,.folder-worktree-history__item.is-blocked .folder-worktree-history__status{color:var(--status-error)}.folder-worktree-history__command,.folder-worktree-history__output{font-family:var(--font-mono,ui-monospace, SFMono-Regular, Menlo, monospace);font-size:10px}.folder-worktree-history__command{color:var(--text-dim)}.folder-worktree-history__output{max-height:84px;color:var(--text-base);background:var(--bg-hover);white-space:pre-wrap;border-radius:4px;margin:0;padding:5px;overflow:auto}.folder-worktree-history__output.is-error,.folder-worktree-history__error{color:var(--status-error)}.folder-worktree-history__error{font-size:10px}.folder-worktree-history__retry{all:unset;box-sizing:border-box;cursor:pointer;color:var(--text-dim);background:var(--bg-hover);border-radius:3px;justify-self:start;padding:2px 6px;font-size:10px}.folder-worktree-history__retry:hover:not(:disabled),.folder-worktree-history__retry:focus-visible{color:var(--text-base);background:var(--bg-active)}.folder-worktree-history__retry:disabled{cursor:default;opacity:.45}.folder-mutation-dialog{z-index:20;background:color-mix(in srgb, var(--bg-base) 38%, transparent);justify-content:center;align-items:flex-start;padding-top:48px;display:flex;position:absolute;inset:0}.folder-mutation-dialog__panel{border:1px solid var(--border-subtle);background:var(--bg-elevated);border-radius:6px;gap:8px;width:min(260px,100% - 24px);padding:10px;display:grid;box-shadow:0 14px 40px #00000052}.folder-mutation-dialog__title{color:var(--text-base);font-size:12px;font-weight:600}.folder-mutation-dialog__input{box-sizing:border-box;border:1px solid var(--border-subtle);width:100%;color:var(--text-base);background:var(--bg-base);border-radius:4px;padding:6px 7px;font-size:12px}.folder-mutation-dialog__actions{justify-content:flex-end;gap:6px;display:flex}.folder-mutation-dialog__actions button{border:1px solid var(--border-subtle);color:var(--text-base);background:var(--bg-hover);border-radius:4px;padding:4px 8px;font-size:11px}.folder-tree{flex:1;min-height:0;padding:4px 0;overflow-y:auto}.folder-empty-root{justify-content:center;align-items:center;display:flex}.folder-empty-root__content{color:var(--text-dim);text-align:center;padding:12px;font-size:11px;line-height:1.4}.folder-entry{align-items:stretch;padding-left:8px;display:flex}.folder-entry:hover{background:var(--bg-hover)}.folder-entry.is-selected{background:color-mix(in srgb, var(--accent-primary) 8%, transparent)}.folder-entry.is-focused{box-shadow:inset 2px 0 0 color-mix(in srgb, var(--accent-primary) 64%, transparent)}.folder-entry.is-selected.is-focused{background:color-mix(in srgb, var(--accent-primary) 13%, transparent)}.folder-entry.is-drop-target{background:color-mix(in srgb, var(--accent-primary) 16%, transparent);outline:1px solid color-mix(in srgb, var(--accent-primary) 44%, transparent);outline-offset:-1px}.folder-entry.is-dragging{opacity:.58}.folder-entry-inline{background:color-mix(in srgb, var(--accent-primary) 7%, transparent)}.folder-indent{flex-shrink:0;display:flex}.folder-indent-guide{border-left:1px solid var(--border-subtle);width:8px}.folder-entry-btn{all:unset;cursor:pointer;box-sizing:border-box;min-width:0;color:var(--text-base);flex:1;align-items:center;gap:4px;padding:2px 10px 2px 4px;font-size:12px;display:flex}.folder-entry-btn:focus-visible{outline:1px solid color-mix(in srgb, var(--accent-primary) 56%, transparent);outline-offset:-1px;background:color-mix(in srgb, var(--accent-primary) 10%, transparent)}.folder-entry[aria-selected=true]{background:color-mix(in srgb, var(--accent-primary) 12%, transparent)}.folder-entry[aria-selected=true] .folder-entry-btn{color:var(--accent-primary)}.folder-entry-disclosure{all:unset;box-sizing:border-box;cursor:pointer;width:18px;height:22px;color:var(--text-base);flex:0 0 18px;justify-content:center;align-items:center;font-size:14px;font-weight:700;line-height:1;display:inline-flex}.folder-entry-disclosure:hover:not(:disabled),.folder-entry-disclosure:focus-visible{background:color-mix(in srgb, var(--accent-primary) 12%, transparent);outline:1px solid color-mix(in srgb, var(--accent-primary) 42%, transparent);outline-offset:-1px}.folder-entry-disclosure.is-placeholder{cursor:default;color:var(--text-dim);opacity:.58}.folder-entry-name{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.folder-entry-directory .folder-entry-name{font-weight:500}.folder-inline-editor{box-sizing:border-box;flex:1;align-items:center;min-width:0;height:22px;padding:1px 10px 1px 4px;display:flex}.folder-inline-editor__input{box-sizing:border-box;border:1px solid color-mix(in srgb, var(--accent-primary) 48%, var(--border-subtle));width:100%;min-width:0;height:20px;color:var(--text-base);background:var(--bg-base);font:inherit;border-radius:3px;outline:none;padding:1px 5px}.folder-inline-editor__input:focus{box-shadow:0 0 0 1px color-mix(in srgb, var(--accent-primary) 38%, transparent)}.folder-entry-git-badge{min-width:16px;max-width:28px;height:16px;color:var(--text-dim);background:0 0;border-radius:3px;flex:none;justify-content:center;align-items:center;margin-left:auto;padding:0 3px;font-size:10px;line-height:1;display:inline-flex}.folder-entry.git-modified .folder-entry-git-badge{color:#b7791f;background:#b7791f1f}.folder-entry.git-added .folder-entry-git-badge,.folder-entry.git-untracked .folder-entry-git-badge{color:#15803d;background:#15803d1f}.folder-entry.git-deleted .folder-entry-git-badge,.folder-entry.git-conflict .folder-entry-git-badge{color:#dc2626;background:#dc26261f}.folder-entry.git-renamed .folder-entry-git-badge{color:#0f766e;background:#0f766e1f}.folder-entry.git-ignored .folder-entry-git-badge{color:var(--text-dim);opacity:.62}.folder-entry.git-submodule .folder-entry-git-badge{color:#4f46e5;background:#4f46e51f}.folder-move-confirm{border-top:1px solid var(--border-subtle);background:var(--bg-elevated);padding:8px 10px;box-shadow:0 -8px 18px #0000002e}.folder-move-confirm__title{color:var(--text-base);margin-bottom:7px;font-size:12px;line-height:1.35}.folder-move-confirm__option{color:var(--text-dim);align-items:center;gap:6px;margin-bottom:8px;font-size:11px;display:flex}.folder-move-confirm__actions{justify-content:flex-end;gap:6px;display:flex}.folder-empty{color:var(--text-dim);text-align:center;padding:12px;font-size:11px}
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-CkEUZM6i.js";import{t as r}from"./react-dom-URBLzV3w.js";var i=e(t(),1),a=r(),o=n(),s=8;function c(e){return e.kind!==`separator`}function l(e){if(e.matches(`:disabled`)||e.closest(`[hidden], [inert]`))return!1;for(let t=e;t;t=t.parentElement){let e=window.getComputedStyle(t);if(e.display===`none`||e.visibility===`hidden`||e.visibility===`collapse`)return!1}return e.tabIndex>=0||e.hasAttribute(`tabindex`)||e.isContentEditable}function u(e){return e.tabIndex>=0&&l(e)}function d(e,t,n){if(!(e instanceof HTMLElement))return null;let r=Array.from(document.querySelectorAll(`*`)).filter(e=>!t?.contains(e)&&u(e)),i=r.indexOf(e);return i<0||r.length<2?null:r[(i+n+r.length)%r.length]??null}function f(){let[e,t]=(0,i.useState)(null),n=(0,i.useCallback)(()=>t(null),[]),r=(0,i.useCallback)(e=>{e.preventDefault(),e.stopPropagation();let n=e.currentTarget,r=document.activeElement,i=r&&n.contains(r)?r:l(n)?n:Array.from(n.querySelectorAll(`*`)).find(l)??r;if(`clientX`in e&&(e.clientX!==0||e.clientY!==0)){t({x:e.clientX,y:e.clientY,opener:i});return}let a=n.getBoundingClientRect();t({x:a.left+8,y:a.bottom,opener:i})},[]),a=(0,i.useCallback)(e=>{let n=e.getBoundingClientRect();t({x:n.left,y:n.bottom+2,opener:e})},[]);return{state:e,open:e!==null,openAt:r,openAtElement:a,close:n}}function p({state:e,entries:t,label:n,onClose:r,className:l}){let u=(0,i.useRef)(null),f=(0,i.useRef)(!0),p=(0,i.useRef)(null),m=(0,i.useCallback)(()=>{p.current!==null&&(window.cancelAnimationFrame(p.current),p.current=null)},[]),[h,g]=(0,i.useState)(null),_=(0,i.useRef)(r);_.current=r;let v=e?.x,y=e?.y,b=e?.opener;if((0,i.useEffect)(()=>m,[m]),(0,i.useLayoutEffect)(()=>{if(v===void 0||y===void 0){g(null);return}let e=u.current,t=e?.offsetWidth??0,n=e?.offsetHeight??0,r=window.innerWidth-t-s,i=window.innerHeight-n-s;g({x:Math.max(s,Math.min(v,r)),y:Math.max(s,Math.min(y>i?y-n:y,i))})},[v,y]),(0,i.useEffect)(()=>{if(v===void 0||y===void 0)return;m();let e=()=>_.current();f.current=!0,(u.current?.querySelector(`:is([role="menuitem"], [role="menuitemradio"]):not(:disabled)`))?.focus({preventScroll:!0});let t=t=>{u.current&&t.target instanceof Node&&u.current.contains(t.target)||e()},n=t=>{t.key===`Escape`&&(t.preventDefault(),e())},r=()=>e(),i=t=>{u.current&&t.target instanceof Node&&u.current.contains(t.target)||e()};return window.addEventListener(`pointerdown`,t,!0),window.addEventListener(`keydown`,n),window.addEventListener(`blur`,r),window.addEventListener(`resize`,r),window.addEventListener(`scroll`,i,!0),()=>{window.removeEventListener(`pointerdown`,t,!0),window.removeEventListener(`keydown`,n),window.removeEventListener(`blur`,r),window.removeEventListener(`resize`,r),window.removeEventListener(`scroll`,i,!0),f.current&&b instanceof HTMLElement&&b.isConnected&&b.focus({preventScroll:!0})}},[v,y,b,m]),!e)return null;function x(e){let t=Array.from(u.current?.querySelectorAll(`:is([role="menuitem"], [role="menuitemradio"]):not(:disabled)`)??[]);if(!t.length)return;let n=t.indexOf(document.activeElement);t[e===`first`?0:e===`last`?t.length-1:(n+e+t.length)%t.length]?.focus({preventScroll:!0})}function S(e){let t={ArrowDown:1,ArrowUp:-1,Home:`first`,End:`last`}[e.key];if(t!==void 0)e.preventDefault(),x(t);else if(e.key===`Escape`)e.preventDefault(),r();else if(e.key===`Tab`){e.preventDefault();let t=d(b??null,u.current,e.shiftKey?-1:1);f.current=!1,r(),t?.focus({preventScroll:!0})}e.stopPropagation()}let C=h??e;return(0,a.createPortal)((0,o.jsx)(`div`,{ref:u,className:`jaw-context-menu${l?` ${l}`:``}`,role:`menu`,"aria-label":n,style:{left:C.x,top:C.y,visibility:h?`visible`:`hidden`},onKeyDown:S,onContextMenu:e=>e.preventDefault(),children:t.map(t=>c(t)?(0,o.jsxs)(`button`,{type:`button`,role:t.checked===void 0?`menuitem`:`menuitemradio`,"aria-checked":t.checked,disabled:t.disabled,title:t.title,className:`jaw-context-menu-item${t.danger?` is-danger`:``}`,onClick:()=>{let n=u.current,i=e.opener;f.current=!1,r(),t.onSelect(),m(),p.current=window.requestAnimationFrame(()=>{p.current=null;let e=document.activeElement;(!e||e===document.body||!e.isConnected||(n?.contains(e)??!1))&&i instanceof HTMLElement&&i.isConnected&&i.focus({preventScroll:!0})})},children:[(0,o.jsx)(`span`,{className:`jaw-context-menu-icon`,"aria-hidden":`true`,children:t.icon}),(0,o.jsx)(`span`,{className:`jaw-context-menu-label`,children:t.label}),t.shortcut&&(0,o.jsx)(`kbd`,{className:`jaw-context-menu-shortcut`,"aria-hidden":`true`,children:t.shortcut})]},t.id):(0,o.jsx)(`div`,{className:`jaw-context-menu-separator`,role:`separator`},t.id))}),document.body)}var m={viewBox:`0 0 16 16`,width:15,height:15,fill:`none`,stroke:`currentColor`,strokeWidth:1.4,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,focusable:!1};function h(){return(0,o.jsx)(`svg`,{...m,children:(0,o.jsx)(`path`,{d:`M10.8 2.7a1.6 1.6 0 0 1 2.3 2.3L5.6 12.5l-3 .8.8-3Z`})})}function g(){return(0,o.jsx)(`svg`,{...m,children:(0,o.jsx)(`path`,{d:`M9.7 2.3 13.7 6.3M10.6 3.2 6.9 6.1l-2.5-.3-1 1 5.8 5.8 1-1-.3-2.5 2.9-3.7M5.9 10.1 2.5 13.5`})})}function _(){return(0,o.jsxs)(`svg`,{...m,children:[(0,o.jsx)(`rect`,{x:`2.3`,y:`3`,width:`11.4`,height:`3`,rx:`0.8`}),(0,o.jsx)(`path`,{d:`M3.3 6v6.2a.8.8 0 0 0 .8.8h7.8a.8.8 0 0 0 .8-.8V6M6.5 8.8h3`})]})}function v(){return(0,o.jsxs)(`svg`,{...m,children:[(0,o.jsx)(`path`,{d:`M1.8 8S4 3.8 8 3.8 14.2 8 14.2 8 12 12.2 8 12.2 1.8 8 1.8 8Z`}),(0,o.jsx)(`circle`,{cx:`8`,cy:`8`,r:`1.8`})]})}function y(){return(0,o.jsxs)(`svg`,{...m,children:[(0,o.jsx)(`rect`,{x:`5.3`,y:`5.3`,width:`8`,height:`8`,rx:`1.2`}),(0,o.jsx)(`path`,{d:`M10.7 5.3V3.5a.8.8 0 0 0-.8-.8H3.5a.8.8 0 0 0-.8.8v6.4a.8.8 0 0 0 .8.8h1.8`})]})}function b(){return(0,o.jsx)(`svg`,{...m,children:(0,o.jsx)(`path`,{d:`M2.3 4.3a1 1 0 0 1 1-1h3l1.4 1.5h5a1 1 0 0 1 1 1v6.4a1 1 0 0 1-1 1H3.3a1 1 0 0 1-1-1Z`})})}function x(){return(0,o.jsx)(`svg`,{...m,children:(0,o.jsx)(`path`,{d:`M6 3H3.5a.8.8 0 0 0-.8.8v8.7a.8.8 0 0 0 .8.8h8.7a.8.8 0 0 0 .8-.8V10M9 2.7h4.3V7M13.3 2.7 7.5 8.5`})})}function S(){return(0,o.jsx)(`svg`,{...m,children:(0,o.jsx)(`path`,{d:`M4.5 3v10l8-5Z`})})}function C(){return(0,o.jsx)(`svg`,{...m,children:(0,o.jsx)(`rect`,{x:`3.5`,y:`3.5`,width:`9`,height:`9`,rx:`1.4`})})}function w(){return(0,o.jsx)(`svg`,{...m,children:(0,o.jsx)(`path`,{d:`M13 8a5 5 0 1 1-1.5-3.6M13 2.5v3h-3`})})}function T(){return(0,o.jsx)(`svg`,{...m,children:(0,o.jsx)(`path`,{d:`M3 8.8l3.2 3.2L13 5.2`})})}function E(){return(0,o.jsxs)(`svg`,{...m,children:[(0,o.jsx)(`path`,{d:`M8.7 3.2 5.3 6H3v4h2.3l3.4 2.8Z`}),(0,o.jsx)(`path`,{d:`M11 6a3 3 0 0 1 0 4M12.9 4a5.4 5.4 0 0 1 0 8`})]})}function D(){return(0,o.jsxs)(`svg`,{...m,children:[(0,o.jsx)(`path`,{d:`M4.3 2.5H9l2.7 2.7v8.3H4.3Z`}),(0,o.jsx)(`path`,{d:`M9 2.5v2.7h2.7M6.2 8.6h3.6M6.2 10.8h2.6`})]})}export{x as a,h as c,w as d,E as f,f as h,D as i,g as l,p as m,T as n,v as o,C as p,y as r,b as s,_ as t,S as u};