orc-ai 0.1.43 → 0.1.45

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 (111) hide show
  1. package/README.md +70 -11
  2. package/dist/checksums.txt +5 -0
  3. package/dist/index.js +565 -531
  4. package/dist/skills/orc-platform/SKILL.md +7 -0
  5. package/dist/skills/orc-platform/references/packages.md +22 -0
  6. package/dist/skills/orc-platform/references/setup.md +62 -0
  7. package/dist/skills/orc-platform/references/work.md +6 -0
  8. package/dist/web/assets/{Agents-OioCD6VE.js → Agents-C3CfcEAZ.js} +3 -3
  9. package/dist/web/assets/Attention-i8LTSomC.js +2 -0
  10. package/dist/web/assets/Audit-B7bVtM3P.js +1 -0
  11. package/dist/web/assets/Dashboard-DHdqM-Ul.js +1 -0
  12. package/dist/web/assets/{DocumentWorkspace-CE6Jydpq.js → DocumentWorkspace-OemhbAq7.js} +1 -1
  13. package/dist/web/assets/{FileEditor-WTRFcaeP.js → FileEditor-BuxIWZTD.js} +1 -1
  14. package/dist/web/assets/{JobWebhooks-DfH2j2qa.js → JobWebhooks-CJDWzX_K.js} +1 -1
  15. package/dist/web/assets/{Jobs-CjVBkAR4.js → Jobs-dMOMwb_G.js} +1 -1
  16. package/dist/web/assets/{Knowledge-BSqXfDrV.js → Knowledge-BhEOrEBj.js} +3 -3
  17. package/dist/web/assets/PackageCatalog-DWmlmDoe.js +18 -0
  18. package/dist/web/assets/{Pager-C5Mhu4cm.js → Pager-dq5-SOf9.js} +1 -1
  19. package/dist/web/assets/{Rules-Cduh89vN.js → Rules-CcGGZEMg.js} +14 -12
  20. package/dist/web/assets/{Sessions-DB4tEeup.js → Sessions-B-x631jL.js} +3 -3
  21. package/dist/web/assets/{Settings-BS5sIo9b.js → Settings-BnqXlRqU.js} +7 -7
  22. package/dist/web/assets/Skills-fIM1KCKo.js +16 -0
  23. package/dist/web/assets/{SourceEditor-CqLe3QBX.js → SourceEditor-cbuGZiXE.js} +3 -3
  24. package/dist/web/assets/{Tasks-QVB8AH8_.js → Tasks-C_H-kV0s.js} +5 -5
  25. package/dist/web/assets/Terminals-BXiaDVJZ.js +115 -0
  26. package/dist/web/assets/{Webhooks-CgqxLH4w.js → Webhooks-HNs1oFyv.js} +1 -1
  27. package/dist/web/assets/{abnfDiagram-VCTEODGH-BwilySuK.js → abnfDiagram-VCTEODGH-YdxTGih1.js} +1 -1
  28. package/dist/web/assets/{arc-Cux6JiSb.js → arc-B3Rn2cw-.js} +1 -1
  29. package/dist/web/assets/{architectureDiagram-5GKGNRK7-D-ByBPbm.js → architectureDiagram-5GKGNRK7-BOfH_6jS.js} +2 -2
  30. package/dist/web/assets/{blockDiagram-I7D4REHJ-Din_Tp56.js → blockDiagram-I7D4REHJ-BPbMxhXM.js} +1 -1
  31. package/dist/web/assets/{c4Diagram-7LVT6UL2-DYyAYcyC.js → c4Diagram-7LVT6UL2-DXmtVjQz.js} +1 -1
  32. package/dist/web/assets/channel-CSNu1rvV.js +1 -0
  33. package/dist/web/assets/{chunk-2Q5K7J3B-CPJA6Yfg.js → chunk-2Q5K7J3B-CL0p9Umo.js} +1 -1
  34. package/dist/web/assets/{chunk-5VM5RSS4-C3SDCrL8.js → chunk-5VM5RSS4-DRjyyUPY.js} +1 -1
  35. package/dist/web/assets/{chunk-F27PBJKO-Bpn3qXzM.js → chunk-F27PBJKO-CikcnFnY.js} +1 -1
  36. package/dist/web/assets/{chunk-IMKFNOWR-CwbskBX_.js → chunk-IMKFNOWR-IuirAnQn.js} +1 -1
  37. package/dist/web/assets/{chunk-JWPE2WC7-B_tFUgaz.js → chunk-JWPE2WC7-CsIOI1ww.js} +1 -1
  38. package/dist/web/assets/{chunk-POPQ4Y6H-BHiZIox4.js → chunk-POPQ4Y6H-8DNbN3f0.js} +1 -1
  39. package/dist/web/assets/{chunk-SVP7TREG-RIsRYMql.js → chunk-SVP7TREG-Con2g7rj.js} +1 -1
  40. package/dist/web/assets/{chunk-TICWLB2K-C4WnjQ-g.js → chunk-TICWLB2K--op8MOsY.js} +1 -1
  41. package/dist/web/assets/{chunk-XXDRQBXY-B1f8rh55.js → chunk-XXDRQBXY-CWIl2oWU.js} +1 -1
  42. package/dist/web/assets/classDiagram-ZZMXUADV-BrQvwUJF.js +1 -0
  43. package/dist/web/assets/classDiagram-v2-VYDZK3BY-BrQvwUJF.js +1 -0
  44. package/dist/web/assets/{cose-bilkent-JH36ORCC-BWSBuZCN.js → cose-bilkent-JH36ORCC-B2ny9oir.js} +1 -1
  45. package/dist/web/assets/{cynefin-OW5HDTMX-DS8_-RUQ.js → cynefin-OW5HDTMX-vf6rvprI.js} +1 -1
  46. package/dist/web/assets/{cynefinDiagram-5FMLGOSQ-BXhPW2ra.js → cynefinDiagram-5FMLGOSQ-BavfeDE3.js} +1 -1
  47. package/dist/web/assets/{dagre-GXQ25YYZ-BFJpmRsY.js → dagre-GXQ25YYZ-CX1uR-kA.js} +1 -1
  48. package/dist/web/assets/{diagram-S7CK7UJ4-CtnZg8I7.js → diagram-S7CK7UJ4-CnLbI2sq.js} +1 -1
  49. package/dist/web/assets/{diagram-UQ7AKVKN-DlWc0Wil.js → diagram-UQ7AKVKN-JP6lVypL.js} +1 -1
  50. package/dist/web/assets/{diagram-VSXAHHWV-CjcupCxx.js → diagram-VSXAHHWV-D42Ibwlb.js} +1 -1
  51. package/dist/web/assets/{diagram-VX7I27RA-Cm2GC6SD.js → diagram-VX7I27RA-Cz2SDhxE.js} +1 -1
  52. package/dist/web/assets/{diagram-Z3DM3KII-CsEvtuQd.js → diagram-Z3DM3KII-CIVvimhT.js} +1 -1
  53. package/dist/web/assets/{download-BS_0-AxS.js → download-CkO5a0rx.js} +1 -1
  54. package/dist/web/assets/{ebnfDiagram-PWID7BFC-COzCi41m.js → ebnfDiagram-PWID7BFC-BzgYIDAu.js} +1 -1
  55. package/dist/web/assets/{erDiagram-RLTQ6QDP-IMxBO8ty.js → erDiagram-RLTQ6QDP-BSWyD08L.js} +1 -1
  56. package/dist/web/assets/{flowDiagram-HODETNUW-vds1bUdG.js → flowDiagram-HODETNUW-gVLhifwi.js} +1 -1
  57. package/dist/web/assets/{folder-open-Bj_73g-Y.js → folder-open-DTRlb7Jb.js} +1 -1
  58. package/dist/web/assets/{ganttDiagram-EL5Y4UJY-ClOaYIks.js → ganttDiagram-EL5Y4UJY-zqygFFqs.js} +4 -4
  59. package/dist/web/assets/{gitGraphDiagram-WWUBYQGX-BJP34EWq.js → gitGraphDiagram-WWUBYQGX-gKxHJCVW.js} +1 -1
  60. package/dist/web/assets/{highlighted-body-KPVGNVTW-D1qiXPpq.js → highlighted-body-KPVGNVTW-C4nbMo-h.js} +1 -1
  61. package/dist/web/assets/index-BhP6LomY.css +1 -0
  62. package/dist/web/assets/index-hiTCEgOL.js +466 -0
  63. package/dist/web/assets/{infoDiagram-27XIBGKW-Dy7DB3pC.js → infoDiagram-27XIBGKW-dtHgg5NF.js} +1 -1
  64. package/dist/web/assets/{ishikawaDiagram-5VMMS53U-B4sINDZb.js → ishikawaDiagram-5VMMS53U-CF1ZEQHG.js} +1 -1
  65. package/dist/web/assets/{journeyDiagram-3NMN7TZE-BnSJ3YV3.js → journeyDiagram-3NMN7TZE-BFd2MZ1g.js} +1 -1
  66. package/dist/web/assets/{kanban-definition-UXKFOSKX-eQTOsBlg.js → kanban-definition-UXKFOSKX-CqkbS1Ib.js} +1 -1
  67. package/dist/web/assets/{layout-CUd5e3nS.js → layout-BTHnsntX.js} +1 -1
  68. package/dist/web/assets/{linear-0ca0-hn8.js → linear-CIKMIn1X.js} +1 -1
  69. package/dist/web/assets/{list-TY5QvST4.js → list-B8JSuvKJ.js} +1 -1
  70. package/dist/web/assets/{mermaid-HWGCJPDP-uMQRi2iO.js → mermaid-HWGCJPDP-Bu0A6Plq.js} +65 -65
  71. package/dist/web/assets/{mindmap-definition-YA3MSWOX-DVzVYHJb.js → mindmap-definition-YA3MSWOX-C5SBxwJT.js} +1 -1
  72. package/dist/web/assets/{pegDiagram-XKGWAZYB-BJ7UWr8A.js → pegDiagram-XKGWAZYB-C2zjCPdy.js} +1 -1
  73. package/dist/web/assets/{pencil-tq07PJIK.js → pencil-LJ1Zh_yt.js} +1 -1
  74. package/dist/web/assets/{pieDiagram-E7YTZNPT-jMPBCwJE.js → pieDiagram-E7YTZNPT-B_uniAwf.js} +1 -1
  75. package/dist/web/assets/{quadrantDiagram-AXDQQJYC-CaI8P14G.js → quadrantDiagram-AXDQQJYC-CjdT9WSC.js} +1 -1
  76. package/dist/web/assets/{railroadDiagram-O6MQD6OU-Vr6XNTAL.js → railroadDiagram-O6MQD6OU-B--9uYEE.js} +1 -1
  77. package/dist/web/assets/{refresh-cw-CSpRwkJ1.js → refresh-cw-Cj3GiFz3.js} +1 -1
  78. package/dist/web/assets/{requirementDiagram-BXWQKSXE-Ct8-bR5z.js → requirementDiagram-BXWQKSXE-8B0RoLCO.js} +1 -1
  79. package/dist/web/assets/{sankeyDiagram-P5KCCOFB-CCooWN1o.js → sankeyDiagram-P5KCCOFB-DjgyErcq.js} +1 -1
  80. package/dist/web/assets/{save-wtDP4EBM.js → save-kaln3lLx.js} +1 -1
  81. package/dist/web/assets/{scroll-area-C0__dq9d.js → scroll-area-RNNOg_mC.js} +1 -1
  82. package/dist/web/assets/{sequenceDiagram-WJ2MYXX4-CJG0tpsp.js → sequenceDiagram-WJ2MYXX4-DFWfARgK.js} +1 -1
  83. package/dist/web/assets/{sizeCapture-INFHLROL-CYAGWmyp.js → sizeCapture-INFHLROL-93wuqE-G.js} +1 -1
  84. package/dist/web/assets/{stateDiagram-D77RDMKH-B6tbtiF5.js → stateDiagram-D77RDMKH-o5KJOFlZ.js} +1 -1
  85. package/dist/web/assets/stateDiagram-v2-MP3YSRHH-C65WZHpS.js +1 -0
  86. package/dist/web/assets/{swimlanes-42K2YHIH-B5YmlV2W.js → swimlanes-42K2YHIH-BbGhsg72.js} +1 -1
  87. package/dist/web/assets/swimlanesDiagram-VR7AAH4N-BaD6so14.js +8 -0
  88. package/dist/web/assets/{timeline-definition-24CTP7MA-C70UVk0W.js → timeline-definition-24CTP7MA-DZbPpila.js} +1 -1
  89. package/dist/web/assets/{upload-Bbjonx95.js → upload-DsKncyCp.js} +1 -1
  90. package/dist/web/assets/{useJobs-B65iRrUv.js → useJobs-DN-jLeaF.js} +1 -1
  91. package/dist/web/assets/{useKnowledge-BwBd_xnP.js → useKnowledge-BxN3CmKQ.js} +1 -1
  92. package/dist/web/assets/{useMemories-CA58mmx2.js → useMemories-Cgc4Y2UT.js} +1 -1
  93. package/dist/web/assets/useProjectScope-NWbe41dR.js +1 -0
  94. package/dist/web/assets/{vennDiagram-4TSXK5OY-DlQ_KIfV.js → vennDiagram-4TSXK5OY-iueMxWVS.js} +1 -1
  95. package/dist/web/assets/{wardleyDiagram-VM6X3IG4-B8kVmvQk.js → wardleyDiagram-VM6X3IG4-C_aTB61f.js} +1 -1
  96. package/dist/web/assets/{xychartDiagram-S5SC5T6Z-CmW5-A2L.js → xychartDiagram-S5SC5T6Z-7yR96WVh.js} +1 -1
  97. package/dist/web/index.html +2 -2
  98. package/package.json +1 -1
  99. package/dist/web/assets/Audit-DYXfN8Z-.js +0 -1
  100. package/dist/web/assets/Dashboard-DZipdmRC.js +0 -1
  101. package/dist/web/assets/PackageCatalog-NCTkGfB2.js +0 -18
  102. package/dist/web/assets/Skills-BoPSePtc.js +0 -16
  103. package/dist/web/assets/Terminals-DtujdvuM.js +0 -115
  104. package/dist/web/assets/channel-e1u5XNEX.js +0 -1
  105. package/dist/web/assets/classDiagram-ZZMXUADV-lJertNRH.js +0 -1
  106. package/dist/web/assets/classDiagram-v2-VYDZK3BY-lJertNRH.js +0 -1
  107. package/dist/web/assets/index-DqE2dG9P.js +0 -461
  108. package/dist/web/assets/index-sd04m1Ya.css +0 -1
  109. package/dist/web/assets/stateDiagram-v2-MP3YSRHH-DkG2Bl6V.js +0 -1
  110. package/dist/web/assets/swimlanesDiagram-VR7AAH4N-D5nGg3Kj.js +0 -8
  111. package/dist/web/assets/useProjectScope-6JtX8j4R.js +0 -1
@@ -1,5 +1,5 @@
1
- import{g as fe,h as Je,a as Ke,n as Ae,r as l,u as le,j as e,B as H,a8 as ce,U as de,W as xe,X as ue,at as me,Y as ee,Z as G,au as Oe,d as z,av as Qe,E as Ue,q as Fe,aw as We,L as Ve,ax as Ge,ay as Ye,az as Xe,o as He,aA as Ze,a2 as et,a3 as tt,a4 as st,a5 as at,z as ae,aB as he,y as ne,R as pe,aC as Be,C as nt,f as rt,a6 as it,S as ot,aD as lt,ab as ct,l as dt,aE as xt,aF as ut,af as mt,T as ht,s as pt,t as qe,v as B,w as gt,x as I,V as ft}from"./index-DqE2dG9P.js";import{P as jt}from"./pencil-tq07PJIK.js";import{R as Ie}from"./refresh-cw-CSpRwkJ1.js";import{P as vt}from"./Pager-C5Mhu4cm.js";import{u as bt}from"./useProjectScope-6JtX8j4R.js";function yt({projectId:s}){var je,ve,be,ye,Ne,we,ke,Se,Ce,_e;const[d]=fe(),u=Je(),f=Ke(),p=Ae(),[h,x]=l.useState({key:"",offset:0}),[r,i]=l.useState(null),[w,k]=l.useState(!1),[c,L]=l.useState(!1),[b,o]=l.useState(""),[m,g]=l.useState(""),[A,$]=l.useState(s),[E,T]=l.useState(""),[R,J]=l.useState(""),[O,P]=l.useState(""),[D,U]=l.useState(""),[n,v]=l.useState(0),q=d.get("q")??"",F=d.get("agent")??"",t=d.get("ended")!=="0",N=JSON.stringify([s,q,F]),_=h.key===N?h.offset:0,C=a=>x({key:N,offset:a}),y=le({queryKey:["sessions","archive",s,q,F,_],queryFn:()=>z.sessions.archive({q,...s==="all"?{}:{project_id:s},...["claude","codex"].includes(F)?{agent:F}:{},offset:_,limit:20}),enabled:t,refetchInterval:1e4}),te=le({queryKey:["sessions","archive-transcript",r==null?void 0:r.id,r==null?void 0:r.revision,n],queryFn:()=>z.sessions.archiveTranscript(r==null?void 0:r.id,{revision:r==null?void 0:r.revision,offset:n,limit:50}),enabled:!!r});async function re(a){L(!0),o(""),g("");try{await a(),await f.invalidateQueries({queryKey:["sessions"]})}catch(S){o(S instanceof Error?S.message:"Request failed")}finally{L(!1)}}async function Me(a){var Te,Le;if(!(a!=null&&a.length))return;const S=(Le=(Te=p.data)==null?void 0:Te.find(K=>K.id===A))==null?void 0:Le.name;if(!S){o("Select a project before uploading");return}await re(async()=>{var Pe,Ee,Re,De;let K=localStorage.getItem("orc_session_upload_source");K||(K=crypto.randomUUID(),localStorage.setItem("orc_session_upload_source",K));let $e=0;const Y=[];for(const se of Array.from(a))try{if(se.size>60*1024*1024)throw new Error("File exceeds 60 MiB");const X=await se.text(),ie=X.split(/\r?\n/).filter(Z=>Z.trim()).map(Z=>JSON.parse(Z)),Q=((Pe=ie[0])==null?void 0:Pe.type)==="session_meta",j=Q?ie[0].payload:ie.find(Z=>Z.sessionId),ze=await z.sessions.archiveUpload({project:S,source_id:K,agent:Q?"codex":"claude",session_id:Q?j==null?void 0:j.id:j==null?void 0:j.sessionId,title:se.name.slice(0,200),metadata:{cwd:(j==null?void 0:j.cwd)??"",subdirectory:"",...Q&&((Ee=j==null?void 0:j.git)!=null&&Ee.repository_url)?{repository:j.git.repository_url}:{},...Q&&((Re=j==null?void 0:j.git)!=null&&Re.branch)?{branch:j.git.branch}:{},...Q&&((De=j==null?void 0:j.git)!=null&&De.commit_hash)?{commit:j.git.commit_hash}:{}},bundle:{version:1,files:[{path:"session.jsonl",content:X}]}});["created","updated","unchanged","stale"].includes(ze.outcome)&&$e++}catch(X){Y.push(`${se.name}: ${X instanceof Error?X.message:"Upload failed"}`)}g(`${$e} of ${a.length} sessions synchronized${Y.length?`; ${Y.length} need attention`:""}.`),Y.length&&o(Y.join(`
2
- `))})}return t?e.jsxs("section",{className:"mt-8 space-y-3","data-testid":"session-archive",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium",children:"Archived sessions"}),e.jsx("p",{className:"text-xs text-outline",children:"Uploaded history stays available after the source computer is offline."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(H,{variant:"outline","data-testid":"archive-index",disabled:c,onClick:()=>void re(async()=>{const a=await z.sessions.archiveIndex(s==="all"||s==="unassigned"?void 0:s);g(`${a.indexed} sessions indexed; ${a.failed} failed; ${a.skipped} skipped.`)}),children:"Index discovered sessions"}),e.jsx(H,{"data-testid":"archive-upload-open",onClick:()=>{$(s),k(!0)},children:"Upload sessions"})]})]}),m&&e.jsx("p",{role:"status","data-testid":"archive-feedback",className:"text-sm",children:m}),(b||y.error)&&e.jsx("p",{role:"alert",className:"whitespace-pre-wrap text-sm text-error",children:b||((je=y.error)==null?void 0:je.message)}),((ve=y.data)==null?void 0:ve.degraded)&&e.jsx("p",{role:"status","data-testid":"archive-degraded",className:"text-xs text-outline",children:y.data.degraded}),!!((be=y.data)!=null&&be.pending_chunks)&&e.jsxs("p",{className:"text-xs text-outline",children:[y.data.pending_chunks," passages waiting for embeddings"]}),e.jsxs("div",{className:"divide-y divide-outline-variant rounded border border-outline-variant",children:[y.isLoading&&e.jsx("p",{className:"p-4 text-sm",children:"Loading archived sessions…"}),!y.isLoading&&!((ye=y.data)!=null&&ye.sessions.length)&&e.jsx("p",{className:"p-4 text-sm text-outline",children:"No archived sessions match this view."}),(Ne=y.data)==null?void 0:Ne.sessions.map(a=>e.jsxs("button",{type:"button","data-testid":"archive-session-row","data-archive-id":a.id,className:"block w-full p-3 text-left hover:bg-surface-container",onClick:()=>{i(a),v(0),T(a.metadata.repository??""),J(a.metadata.branch??""),P(a.metadata.commit??""),U(a.metadata.subdirectory)},children:[e.jsx("span",{className:"block text-sm font-medium",children:a.title}),e.jsxs("span",{className:"text-xs text-outline",children:[a.agent," · ended · ",new Date(a.updated_at).toLocaleString()," · revision"," ",a.revision," · ",a.metadata.cwd]}),a.passages.map(S=>e.jsx("span",{className:"mt-1 block text-sm text-outline",children:S.snippet},S.citation)),a.embedding_error&&e.jsx("span",{className:"block text-xs text-error",children:a.embedding_error})]},a.id))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(H,{variant:"ghost",disabled:_===0,onClick:()=>C(Math.max(0,_-20)),children:"Previous"}),e.jsx(H,{variant:"ghost",disabled:!((we=y.data)!=null&&we.has_more),onClick:()=>C(_+20),children:"Next"})]}),e.jsx(ce,{open:w,onOpenChange:k,children:e.jsxs(de,{children:[e.jsxs(xe,{children:[e.jsx(ue,{children:"Upload session histories"}),e.jsx(me,{children:"Select an existing project and native Claude/Codex JSONL files. This stores history without starting a terminal. For large collections, use the orc-platform sync script."})]}),e.jsx(ee,{htmlFor:"archive-project",children:"Project"}),e.jsxs("select",{id:"archive-project","data-testid":"archive-project",value:A,onChange:a=>$(a.target.value),className:"rounded border border-outline-variant bg-surface p-2",children:[e.jsx("option",{value:"all",children:"Select a project"}),(ke=p.data)==null?void 0:ke.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]}),e.jsx(G,{"data-testid":"archive-files",type:"file",multiple:!0,accept:".jsonl",disabled:c||!((Se=p.data)!=null&&Se.some(a=>a.id===A)),onChange:a=>void Me(a.target.files)}),c&&e.jsx("p",{role:"status",children:"Uploading…"}),m&&e.jsx("p",{role:"status","data-testid":"archive-upload-feedback",children:m}),b&&e.jsx("p",{role:"alert",className:"whitespace-pre-wrap text-sm text-error",children:b})]})}),e.jsx(ce,{open:!!r,onOpenChange:a=>{a||i(null)},children:e.jsxs(de,{className:"max-h-[90vh] max-w-3xl overflow-y-auto","data-testid":"archive-detail",children:[e.jsxs(xe,{children:[e.jsx(ue,{children:r==null?void 0:r.title}),e.jsxs(me,{children:["Archived history · revision ",r==null?void 0:r.revision,". Prepare a destination checkout to continue in a terminal."]})]}),te.error&&e.jsx("p",{role:"alert",children:te.error.message}),(Ce=te.data)==null?void 0:Ce.turns.map(a=>e.jsxs("div",{className:"border-b border-outline-variant py-2","data-testid":"archive-turn",children:[e.jsx("p",{className:"text-xs text-outline",children:a.role}),e.jsx(Oe,{plain:!0,children:a.blocks.map(S=>S.type==="tool_use"?`${S.name}
1
+ import{h as fe,i as Je,a as Ke,o as Ae,r as l,u as le,j as e,B as H,aa as ce,X as de,Y as xe,Z as ue,au as me,_ as ee,$ as W,av as Oe,d as z,aw as Qe,E as Ue,s as Fe,ax as Ge,L as Ve,ay as We,az as Ye,aA as Xe,p as He,aB as Ze,a4 as et,a5 as tt,a6 as st,a7 as at,D as ae,aC as he,A as ne,R as pe,aD as Be,C as nt,f as rt,a8 as it,S as ot,aE as lt,ad as ct,m as dt,aF as xt,aG as ut,ah as mt,t as ht,v as pt,w as qe,x as B,y as gt,z as I,V as ft}from"./index-hiTCEgOL.js";import{P as jt}from"./pencil-LJ1Zh_yt.js";import{R as Ie}from"./refresh-cw-Cj3GiFz3.js";import{P as vt}from"./Pager-dq5-SOf9.js";import{u as bt}from"./useProjectScope-NWbe41dR.js";function yt({projectId:s}){var je,ve,be,ye,Ne,we,ke,Se,Ce,_e;const[d]=fe(),u=Je(),f=Ke(),p=Ae(),[h,x]=l.useState({key:"",offset:0}),[r,i]=l.useState(null),[w,k]=l.useState(!1),[c,$]=l.useState(!1),[b,o]=l.useState(""),[m,g]=l.useState(""),[A,L]=l.useState(s),[E,T]=l.useState(""),[R,J]=l.useState(""),[O,P]=l.useState(""),[D,U]=l.useState(""),[n,v]=l.useState(0),q=d.get("q")??"",F=d.get("agent")??"",t=d.get("ended")!=="0",N=JSON.stringify([s,q,F]),_=h.key===N?h.offset:0,C=a=>x({key:N,offset:a}),y=le({queryKey:["sessions","archive",s,q,F,_],queryFn:()=>z.sessions.archive({q,...s==="all"?{}:{project_id:s},...["claude","codex"].includes(F)?{agent:F}:{},offset:_,limit:20}),enabled:t,refetchInterval:1e4}),te=le({queryKey:["sessions","archive-transcript",r==null?void 0:r.id,r==null?void 0:r.revision,n],queryFn:()=>z.sessions.archiveTranscript(r==null?void 0:r.id,{revision:r==null?void 0:r.revision,offset:n,limit:50}),enabled:!!r});async function re(a){$(!0),o(""),g("");try{await a(),await f.invalidateQueries({queryKey:["sessions"]})}catch(S){o(S instanceof Error?S.message:"Request failed")}finally{$(!1)}}async function Me(a){var Te,$e;if(!(a!=null&&a.length))return;const S=($e=(Te=p.data)==null?void 0:Te.find(K=>K.id===A))==null?void 0:$e.name;if(!S){o("Select a project before uploading");return}await re(async()=>{var Pe,Ee,Re,De;let K=localStorage.getItem("orc_session_upload_source");K||(K=crypto.randomUUID(),localStorage.setItem("orc_session_upload_source",K));let Le=0;const Y=[];for(const se of Array.from(a))try{if(se.size>60*1024*1024)throw new Error("File exceeds 60 MiB");const X=await se.text(),ie=X.split(/\r?\n/).filter(Z=>Z.trim()).map(Z=>JSON.parse(Z)),Q=((Pe=ie[0])==null?void 0:Pe.type)==="session_meta",j=Q?ie[0].payload:ie.find(Z=>Z.sessionId),ze=await z.sessions.archiveUpload({project:S,source_id:K,agent:Q?"codex":"claude",session_id:Q?j==null?void 0:j.id:j==null?void 0:j.sessionId,title:se.name.slice(0,200),metadata:{cwd:(j==null?void 0:j.cwd)??"",subdirectory:"",...Q&&((Ee=j==null?void 0:j.git)!=null&&Ee.repository_url)?{repository:j.git.repository_url}:{},...Q&&((Re=j==null?void 0:j.git)!=null&&Re.branch)?{branch:j.git.branch}:{},...Q&&((De=j==null?void 0:j.git)!=null&&De.commit_hash)?{commit:j.git.commit_hash}:{}},bundle:{version:1,files:[{path:"session.jsonl",content:X}]}});["created","updated","unchanged","stale"].includes(ze.outcome)&&Le++}catch(X){Y.push(`${se.name}: ${X instanceof Error?X.message:"Upload failed"}`)}g(`${Le} of ${a.length} sessions synchronized${Y.length?`; ${Y.length} need attention`:""}.`),Y.length&&o(Y.join(`
2
+ `))})}return t?e.jsxs("section",{className:"mt-8 space-y-3","data-testid":"session-archive",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium",children:"Archived sessions"}),e.jsx("p",{className:"text-xs text-outline",children:"Uploaded history stays available after the source computer is offline."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(H,{variant:"outline","data-testid":"archive-index",disabled:c,onClick:()=>void re(async()=>{const a=await z.sessions.archiveIndex(s==="all"||s==="unassigned"?void 0:s);g(`${a.indexed} sessions indexed; ${a.failed} failed; ${a.skipped} skipped.`)}),children:"Index discovered sessions"}),e.jsx(H,{"data-testid":"archive-upload-open",onClick:()=>{L(s),k(!0)},children:"Upload sessions"})]})]}),m&&e.jsx("p",{role:"status","data-testid":"archive-feedback",className:"text-sm",children:m}),(b||y.error)&&e.jsx("p",{role:"alert",className:"whitespace-pre-wrap text-sm text-error",children:b||((je=y.error)==null?void 0:je.message)}),((ve=y.data)==null?void 0:ve.degraded)&&e.jsx("p",{role:"status","data-testid":"archive-degraded",className:"text-xs text-outline",children:y.data.degraded}),!!((be=y.data)!=null&&be.pending_chunks)&&e.jsxs("p",{className:"text-xs text-outline",children:[y.data.pending_chunks," passages waiting for embeddings"]}),e.jsxs("div",{className:"divide-y divide-outline-variant rounded border border-outline-variant",children:[y.isLoading&&e.jsx("p",{className:"p-4 text-sm",children:"Loading archived sessions…"}),!y.isLoading&&!((ye=y.data)!=null&&ye.sessions.length)&&e.jsx("p",{className:"p-4 text-sm text-outline",children:"No archived sessions match this view."}),(Ne=y.data)==null?void 0:Ne.sessions.map(a=>e.jsxs("button",{type:"button","data-testid":"archive-session-row","data-archive-id":a.id,className:"block w-full p-3 text-left hover:bg-surface-container",onClick:()=>{i(a),v(0),T(a.metadata.repository??""),J(a.metadata.branch??""),P(a.metadata.commit??""),U(a.metadata.subdirectory)},children:[e.jsx("span",{className:"block text-sm font-medium",children:a.title}),e.jsxs("span",{className:"text-xs text-outline",children:[a.agent," · ended · ",new Date(a.updated_at).toLocaleString()," · revision"," ",a.revision," · ",a.metadata.cwd]}),a.passages.map(S=>e.jsx("span",{className:"mt-1 block text-sm text-outline",children:S.snippet},S.citation)),a.embedding_error&&e.jsx("span",{className:"block text-xs text-error",children:a.embedding_error})]},a.id))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(H,{variant:"ghost",disabled:_===0,onClick:()=>C(Math.max(0,_-20)),children:"Previous"}),e.jsx(H,{variant:"ghost",disabled:!((we=y.data)!=null&&we.has_more),onClick:()=>C(_+20),children:"Next"})]}),e.jsx(ce,{open:w,onOpenChange:k,children:e.jsxs(de,{children:[e.jsxs(xe,{children:[e.jsx(ue,{children:"Upload session histories"}),e.jsx(me,{children:"Select an existing project and native Claude/Codex JSONL files. This stores history without starting a terminal. For large collections, use the orc-platform sync script."})]}),e.jsx(ee,{htmlFor:"archive-project",children:"Project"}),e.jsxs("select",{id:"archive-project","data-testid":"archive-project",value:A,onChange:a=>L(a.target.value),className:"rounded border border-outline-variant bg-surface p-2",children:[e.jsx("option",{value:"all",children:"Select a project"}),(ke=p.data)==null?void 0:ke.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]}),e.jsx(W,{"data-testid":"archive-files",type:"file",multiple:!0,accept:".jsonl",disabled:c||!((Se=p.data)!=null&&Se.some(a=>a.id===A)),onChange:a=>void Me(a.target.files)}),c&&e.jsx("p",{role:"status",children:"Uploading…"}),m&&e.jsx("p",{role:"status","data-testid":"archive-upload-feedback",children:m}),b&&e.jsx("p",{role:"alert",className:"whitespace-pre-wrap text-sm text-error",children:b})]})}),e.jsx(ce,{open:!!r,onOpenChange:a=>{a||i(null)},children:e.jsxs(de,{className:"max-h-[90vh] max-w-3xl overflow-y-auto","data-testid":"archive-detail",children:[e.jsxs(xe,{children:[e.jsx(ue,{children:r==null?void 0:r.title}),e.jsxs(me,{children:["Archived history · revision ",r==null?void 0:r.revision,". Prepare a destination checkout to continue in a terminal."]})]}),te.error&&e.jsx("p",{role:"alert",children:te.error.message}),(Ce=te.data)==null?void 0:Ce.turns.map(a=>e.jsxs("div",{className:"border-b border-outline-variant py-2","data-testid":"archive-turn",children:[e.jsx("p",{className:"text-xs text-outline",children:a.role}),e.jsx(Oe,{plain:!0,children:a.blocks.map(S=>S.type==="tool_use"?`${S.name}
3
3
  ${S.input}
4
4
  ${S.result??""}`:S.text).join(`
5
- `)})]},a.index)),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(H,{variant:"ghost",disabled:!n,onClick:()=>v(Math.max(0,n-50)),children:"Previous messages"}),e.jsx(H,{variant:"ghost",disabled:n+50>=(((_e=te.data)==null?void 0:_e.total)??0),onClick:()=>v(n+50),children:"Next messages"})]}),e.jsxs("div",{className:"space-y-2 border-t border-outline-variant pt-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Continue on ORC"}),e.jsx("p",{className:"text-xs text-outline",children:"Use the pushed repository, branch and exact commit for the work you want to continue. The destination project must have its repository configured."}),e.jsx(ee,{htmlFor:"archive-repository",children:"Repository"}),e.jsx(G,{id:"archive-repository","data-testid":"archive-repository",value:E,onChange:a=>T(a.target.value)}),e.jsx(ee,{htmlFor:"archive-branch",children:"Branch"}),e.jsx(G,{id:"archive-branch","data-testid":"archive-branch",value:R,onChange:a=>J(a.target.value)}),e.jsx(ee,{htmlFor:"archive-commit",children:"Pushed commit"}),e.jsx(G,{id:"archive-commit","data-testid":"archive-commit",value:O,onChange:a=>P(a.target.value)}),e.jsx(ee,{htmlFor:"archive-subdirectory",children:"Repository subdirectory"}),e.jsx(G,{id:"archive-subdirectory","data-testid":"archive-subdirectory",value:D,onChange:a=>U(a.target.value),placeholder:"Repository root"}),e.jsx(H,{"data-testid":"archive-resume",disabled:c||!E||!R||!/^[a-f0-9]{40}$/i.test(O),onClick:()=>void re(async()=>{if(!r)return;const a=await z.sessions.archiveResume(r.id,{revision:r.revision,repository:E,branch:R,commit:O,subdirectory:D});if(a.status!=="ready"||!a.live_session_id)throw new Error(a.error||"Session preparation failed");const S=await z.terminals.create({kind:r.agent,live_session_id:a.live_session_id});u(`/terminals/${S.id}`)}),children:c?"Preparing…":"Prepare and resume in terminal"}),b&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:b})]})]})})]}):null}function W({text:s,query:d}){const u=d.trim();if(u.length<2)return e.jsx(e.Fragment,{children:s});const f=s.split(new RegExp(`(${Qe(u)})`,"gi"));return e.jsx(e.Fragment,{children:f.map((p,h)=>p.toLowerCase()===u.toLowerCase()?e.jsx("mark",{className:"bg-primary/30 text-on-surface rounded-sm",children:p},h):p)})}function Nt({projectId:s,pending:d,onSelect:u}){var b;const[f,p]=l.useState(""),[h,x]=l.useState(!1),[r,i]=l.useState(null),w=le({queryKey:["tasks","session-picker",s],queryFn:()=>z.tasks.list({...s?{project_id:s}:{},limit:100})});async function k(o){i(null);try{await u(o)}catch(m){i(m instanceof Error?m.message:"Could not link task")}}async function c(){x(!0),i(null);try{const o=await z.tasks.get(f.trim());await k(o.id)}catch(o){i(o instanceof Error?o.message:"Task lookup failed")}finally{x(!1)}}const L=(((b=w.data)==null?void 0:b.tasks)??[]).filter(o=>`${o.title} ${o.id}`.toLowerCase().includes(f.trim().toLowerCase()));return e.jsxs("div",{className:"space-y-3",children:[e.jsx(G,{"data-testid":"session-task-search","aria-label":"Search tasks or enter a task ID",value:f,onChange:o=>{p(o.target.value),i(null)},placeholder:"Search recent tasks or paste a task ID"}),e.jsxs("p",{className:"text-xs text-outline",children:["Up to 100 recent tasks",s?" in this project":" across projects",". Older or other-project tasks can be linked by exact ID."]}),r&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:r}),w.error?e.jsx(Ue,{message:w.error.message,onRetry:()=>w.refetch()}):w.isLoading?e.jsx("p",{role:"status",children:"Loading tasks…"}):e.jsxs("div",{className:"max-h-72 overflow-y-auto divide-y divide-border",children:[L.map(o=>e.jsxs("button",{type:"button","data-testid":"session-task-option","data-task-id":o.id,disabled:d||h,onClick:()=>void k(o.id),className:"w-full min-h-11 py-2 text-left hover:bg-surface-highest disabled:opacity-50",children:[e.jsx("span",{className:"block text-sm break-words",children:o.title}),e.jsxs("span",{className:"inline-flex items-center gap-2 text-xs text-outline",children:[e.jsx(Fe,{status:o.status,className:"px-0"}),o.id]})]},o.id)),L.length===0&&e.jsx("p",{className:"py-4 text-sm text-outline",children:"No recent task matches. Paste its exact ID to look it up."})]}),f.trim()&&e.jsx(H,{variant:"outline",disabled:d||h,onClick:()=>void c(),children:h?"Looking up…":"Link by exact ID"})]})}function ge({session:s,linkTestId:d="open-task"}){const[u]=fe(),[f,p]=l.useState(!1),h=We(),x=u.get("project")??s.project_id;async function r(i){try{await h.mutateAsync({id:s.id,taskId:i}),p(!1)}catch{}}return e.jsxs("div",{className:"min-w-0 space-y-1",children:[s.task&&e.jsxs("div",{className:"min-w-0",children:[e.jsx(Ve,{"data-testid":d,to:Ge(`/tasks/${s.task.id}`,x),className:"block max-w-64 truncate text-sm text-primary hover:underline",title:s.task.title,children:s.task.title}),e.jsx(Fe,{status:s.task.status,className:"px-0"})]}),e.jsxs(ce,{open:f,onOpenChange:i=>{p(i),i&&h.reset()},children:[e.jsx(Ye,{asChild:!0,children:e.jsxs("button",{type:"button","data-testid":"link-task",className:"inline-flex min-h-9 items-center gap-1.5 text-xs text-outline hover:text-on-surface",children:[s.task?e.jsx(jt,{size:12}):e.jsx(Xe,{size:13}),s.task?"Change task":"Link task"]})}),e.jsxs(de,{"data-testid":"session-task-dialog",className:"max-h-[85dvh] w-[calc(100%-2rem)] overflow-y-auto",children:[e.jsxs(xe,{children:[e.jsx(ue,{children:"Link a task"}),e.jsxs(me,{children:["Choose a recent task for ",s.name??"this session",", or paste an exact task ID."]})]}),h.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:h.error.message}),e.jsx(Nt,{projectId:s.project_id,pending:h.isPending,onSelect:r}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.task&&e.jsx(H,{variant:"outline","data-testid":"session-task-unlink",disabled:h.isPending,onClick:()=>void r(null),children:"Unlink task"})})]})]})]})}const oe="session-search",wt={user:"border-border/65",assistant:"border-border/65",tool:"border-border/65 bg-transparent",system:"border-border/65 bg-transparent"},kt=["command","cmd","file_path","path","pattern","query","url","description"];function St(s){try{const d=JSON.parse(s);for(const u of kt)if(typeof d[u]=="string")return d[u]}catch{}return s}function Ct(s){try{return JSON.stringify(JSON.parse(s),null,2)}catch{return s}}function _t(s,d,u){l.useEffect(()=>{const f=s.current,p=CSS.highlights,h=window.Highlight;if(!f||!p||!h)return;const x=d.trim().toLowerCase(),r=()=>{var L;if(p.delete(oe),x.length<2)return;const k=[],c=document.createTreeWalker(f,NodeFilter.SHOW_TEXT);for(let b=c.nextNode();b;b=c.nextNode()){const o=((L=b.textContent)==null?void 0:L.toLowerCase())??"";for(let m=o.indexOf(x);m>=0;m=o.indexOf(x,m+x.length)){const g=new Range;g.setStart(b,m),g.setEnd(b,m+x.length),k.push(g)}}k.length>0&&p.set(oe,new h(...k))};r();let i;const w=new MutationObserver(()=>{clearTimeout(i),i=setTimeout(r,150)});return w.observe(f,{childList:!0,subtree:!0,characterData:!0}),()=>{clearTimeout(i),w.disconnect(),p.delete(oe)}},[s,d,u])}function Tt({block:s,open:d}){const u=s.result!==void 0;return e.jsxs("details",{open:d||void 0,"data-testid":"tool-box",className:"border-l border-border bg-background",children:[e.jsxs("summary",{className:"flex cursor-pointer items-center gap-2 px-2 py-1.5 font-label text-xs font-medium text-outline hover:text-on-surface",children:[e.jsx("span",{className:"text-secondary shrink-0",children:s.name}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono normal-case tracking-normal text-on-surface-variant",children:St(s.input)}),e.jsx("span",{className:`shrink-0 ${u?"text-outline":"text-tertiary"}`,children:u?"done":"no result"})]}),e.jsxs("div",{className:"space-y-2 border-t border-border px-2 py-2",children:[e.jsx("div",{className:"font-label text-[10px] font-medium text-outline",children:"input"}),e.jsx("pre",{className:"max-h-72 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:Ct(s.input)}),u&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-label text-[10px] font-medium text-outline",children:"result"}),e.jsx("pre",{className:"max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:s.result})]})]})]})}function Lt({block:s,matched:d}){if(s.type==="text")return e.jsx(Oe,{revealContext:d,children:s.text});if(s.type==="tool_use")return e.jsx(Tt,{block:s,open:d});const u=s.type==="thinking"?"thinking":"result";return e.jsxs("details",{open:d||void 0,children:[e.jsx("summary",{className:"cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface",children:u}),s.type==="thinking"?e.jsx("div",{className:"mt-1",children:e.jsx(ct,{children:s.text})}):e.jsx("pre",{className:"mt-1 max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:s.text})]})}function $t({sessionId:s,initialQuery:d,onClose:u}){const[f,p]=l.useState(d),[h,x]=l.useState(0),{data:r}=He(!1),i=r==null?void 0:r.find(n=>n.id===s),w=i!==void 0&&i.status!=="stopped",k=f.trim().length>=2?f.trim():"",{data:c,isLoading:L,isFetching:b,error:o,refetch:m,dataUpdatedAt:g}=Ze(s,k),A=l.useRef(null),$=l.useRef(null),E=l.useRef(!0),T=l.useRef(0),[R,J]=l.useState(!0),O=l.useCallback(()=>{const n=A.current;n&&(n.scrollTo({top:n.scrollHeight}),requestAnimationFrame(()=>n.scrollTo({top:n.scrollHeight})))},[]);_t($,k,c==null?void 0:c.turns);const P=(c==null?void 0:c.matches)??[],D=P[h];l.useEffect(()=>{var n;if(c){if(D!==void 0){E.current=!1,(n=document.getElementById(`turn-${D}`))==null||n.scrollIntoView({block:"center"});return}E.current&&O()}},[D,c,O]),l.useEffect(()=>{c&&R&&(T.current=c.total)},[c,R]);const U=n=>{P.length>0&&x(v=>(v+n+P.length)%P.length)};return e.jsx(et,{open:!!s,onOpenChange:n=>!n&&u(),children:e.jsxs(tt,{side:"right",className:"w-[1100px] max-w-[95vw]","data-testid":"live-session-detail",children:[e.jsxs(st,{children:[e.jsx(at,{className:"normal-case tracking-normal text-sm pr-8",children:(i==null?void 0:i.name)??"Session"}),i&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-5 gap-y-1 font-body text-xs text-on-surface tabular-nums",children:[e.jsx("span",{className:"font-medium text-primary",children:i.agent}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${ae[i.status].dot}`}),ae[i.status].label]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-on-surface-variant",children:"tokens "}),he(i)]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-on-surface-variant",children:"active "}),ne(i.last_activity_at)]}),e.jsx(ge,{session:i,linkTestId:"detail-open-task"}),e.jsx(pe,{session:i}),e.jsx("span",{className:"truncate max-w-full text-on-surface-variant",children:i.cwd})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-[150px] flex-1",children:[e.jsx(Be,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-outline"}),e.jsx("input",{"data-testid":"transcript-search","aria-label":"Search this session",value:f,onChange:n=>{p(n.target.value),x(0)},placeholder:"Search this session",className:"w-full bg-background border border-control-border rounded-lg min-h-11 pl-7 pr-2 py-2 font-body text-xs text-on-surface"})]}),k&&e.jsx("span",{"data-testid":"transcript-match-count",className:"font-label text-xs font-medium text-outline",children:P.length===0?"no matches":`${h+1} / ${P.length}`}),e.jsx("button",{type:"button","aria-label":"Previous match",onClick:()=>U(-1),className:"min-h-11 min-w-11 p-2 text-outline hover:text-on-surface",children:e.jsx(nt,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","aria-label":"Next match",onClick:()=>U(1),className:"min-h-11 min-w-11 p-2 text-outline hover:text-on-surface",children:e.jsx(rt,{className:"h-4 w-4"})}),e.jsxs("button",{type:"button","data-testid":"transcript-refresh",onClick:()=>{E.current=!0,m()},className:"min-h-11 px-2 inline-flex items-center gap-1 font-label text-xs font-medium text-primary hover:text-on-surface",children:[e.jsx(Ie,{className:`h-3 w-3 ${b?"animate-spin":""}`}),"Refresh"]})]}),c&&e.jsxs("div",{"data-testid":"transcript-status",className:"mt-2 font-body text-xs text-on-surface-variant tabular-nums",children:[c.total," turns",w?` · live, updated ${new Date(g).toLocaleTimeString()}`:""]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e.jsx(it,{ref:A,onScroll:n=>{const v=n.currentTarget,q=v.scrollHeight-v.scrollTop-v.clientHeight<160;E.current=q,J(q)},children:L?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((n,v)=>e.jsx(ot,{className:"h-16 w-full bg-surface-highest"},v))}):o||!c?e.jsxs("div",{"data-testid":"transcript-unavailable",className:"font-body text-xs text-outline py-12 text-center",children:[o?`Could not load the conversation: ${o.message}`:"No conversation was recorded for this session.",e.jsx("p",{className:"mt-2",children:"Resume actions remain available when the native agent session exists."}),e.jsx("button",{type:"button",className:"mt-3 min-h-11 text-primary hover:underline",onClick:()=>m(),children:"Retry conversation"})]}):e.jsx("div",{ref:$,className:"space-y-3",children:c.turns.map(n=>{const v=P.includes(n.index),q=n.blocks.map((F,t)=>e.jsx(Lt,{block:F,matched:v},t));return e.jsxs("div",{id:`turn-${n.index}`,"data-testid":"transcript-turn","data-role":n.role,style:{contentVisibility:"auto",containIntrinsicSize:"auto 120px"},className:`border-b px-4 py-3 text-on-surface space-y-2 ${wt[n.role]} ${n.index===D?"ring-1 ring-primary":""}`,children:[e.jsxs("div",{className:"font-label text-xs font-medium text-outline",children:[n.role,n.time?` · ${ne(n.time)}`:""]}),n.role==="system"?e.jsxs("details",{open:v||void 0,children:[e.jsx("summary",{className:"cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface",children:"injected context"}),e.jsx("div",{className:"mt-2 space-y-2",children:q})]}):q]},n.index)})})}),c&&!R&&e.jsxs("button",{type:"button","data-testid":"jump-to-latest",onClick:()=>{E.current=!0,O()},className:"absolute bottom-4 right-6 inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 font-body text-xs text-primary shadow-lg hover:bg-surface-bright",children:[e.jsx(lt,{className:"h-3.5 w-3.5"}),"Jump to latest",c.total>T.current&&` · ${c.total-T.current} new`]})]})]})})}const Pt=["claude","codex","cursor","cursor-agent","gemini"],V=25,M="font-label text-xs font-medium text-outline";function Et({projectId:s}){var F;const d=dt("sm"),[u,f]=fe(),p=u.get("agent")??"",h=u.get("ended")!=="0",x=u.get("q")??"",r=u.get("order")==="asc"?"asc":"desc",i=u.get("session"),[w,k]=l.useState(x),[c,L]=l.useState({order:r,page:0}),b=c.order===r?c.page:0,o=l.useCallback(t=>L({order:r,page:t}),[r]),m=l.useCallback((t,N)=>{o(0),f(_=>{const C=new URLSearchParams(_);return N?C.set(t,N):C.delete(t),C},{replace:t==="q"})},[f,o]);l.useEffect(()=>k(x),[x]),l.useEffect(()=>{if(w===x)return;const t=setTimeout(()=>m("q",w.trim()||null),350);return()=>clearTimeout(t)},[w,x,m]);const g=x.trim().length>=2,A=He(!h),$=xt(g?x.trim():"",p),{data:E}=Ae(),T=ut(),R=new Map((E??[]).map(t=>[t.id,t.name])),J=g?((F=$.data)==null?void 0:F.hits)??[]:A.data??[],O=[...new Set([...Pt,...J.map(t=>t.agent)])],P=g?$.isLoading:A.isLoading,D=g?$:A,U=J.filter(t=>{var N;return(!p||t.agent===p)&&(h||t.status!=="stopped"||((N=t.handoff)==null?void 0:N.status)==="ready")}),n=U.filter(t=>s==="all"?!0:s==="unassigned"?t.project_id===null:t.project_id===s).sort((t,N)=>{const C=new Date(t.last_activity_at??t.created_at).getTime()-new Date(N.last_activity_at??N.created_at).getTime()||t.id.localeCompare(N.id);return r==="asc"?C:-C}),v=Math.min(b,Math.max(0,Math.ceil(n.length/V)-1))*V,q=s==="unassigned"?"unassigned":R.get(s)??s;return e.jsxs("section",{className:"mb-8","data-testid":"live-sessions",children:[e.jsx("p",{className:"mb-4 text-sm text-outline",children:"Discovered from your coding agents. Working sessions update automatically; waiting sessions remain available to resume."}),e.jsxs("div",{className:"mb-3 relative",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-outline"}),e.jsx("input",{"data-testid":"session-search","aria-label":"Search agent sessions",value:w,onChange:t=>k(t.target.value),placeholder:"Search agent sessions: titles, summaries and conversation text",className:"w-full bg-background border border-control-border rounded-lg pl-9 pr-3 py-2 font-body text-xs text-on-surface placeholder:text-outline"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("h2",{className:"font-label text-xs font-medium text-outline",children:[g?"Search results":"Agent sessions"," · ",n.length,n.length!==U.length&&e.jsxs("span",{"data-testid":"scope-hint",className:"normal-case tracking-normal",children:[" ","of ",U.length," · scope: ",q]}),g&&$.data&&e.jsxs("span",{"data-testid":"search-meta",className:"normal-case tracking-normal",children:[" ","· ",($.data.ms/1e3).toFixed(1),"s",$.data.rg?"":" · titles and summaries only (install ripgrep for content)"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("select",{"aria-label":"Sort sessions by date","data-testid":"session-date-sort",value:r,onChange:t=>m("order",t.target.value==="asc"?"asc":null),className:"min-h-11 rounded-md border border-control-border bg-background px-3 text-sm text-on-surface",children:[e.jsx("option",{value:"desc",children:"Last active: newest first"}),e.jsx("option",{value:"asc",children:"Last active: oldest first"})]}),e.jsxs("select",{"data-testid":"agent-filter","aria-label":"Agent",className:"bg-background border border-control-border rounded-lg min-h-11 px-3 py-2 font-label text-xs font-medium text-on-surface",value:p,onChange:t=>m("agent",t.target.value||null),children:[e.jsx("option",{value:"",children:"all agents"}),O.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("label",{className:"flex items-center gap-2 font-label text-xs font-medium text-outline cursor-pointer",children:[e.jsx("input",{type:"checkbox","data-testid":"show-ended",checked:h,onChange:t=>m("ended",t.target.checked?"1":"0")}),"Show ended"]}),e.jsxs("button",{type:"button","data-testid":"sync-sessions",disabled:T.isPending,className:"min-h-11 px-2 inline-flex items-center gap-1 font-label text-xs font-medium text-primary hover:text-on-surface disabled:opacity-50",onClick:()=>T.mutate(),children:[e.jsx(Ie,{className:`h-3 w-3 ${T.isPending?"animate-spin":""}`}),T.isPending?"Syncing":"Refresh"]})]})]}),T.error&&e.jsx("p",{role:"alert",className:"mb-3 text-sm text-error",children:T.error.message}),D.error?e.jsx(Ue,{message:D.error.message,onRetry:()=>D.refetch()}):P?e.jsx("p",{role:"status",className:"py-8 text-sm text-outline",children:"Loading sessions…"}):n.length===0?e.jsx(mt,{message:g?"No sessions match":"No active agent sessions. Enable Show ended to browse previous conversations."}):e.jsxs("div",{className:"min-w-0 overflow-hidden",children:[d?e.jsxs(ht,{children:[e.jsx(pt,{children:e.jsxs(qe,{className:"border-b border-border hover:bg-transparent",children:[e.jsx(B,{className:`${M} w-40`,children:"Status"}),e.jsx(B,{className:`${M} w-20`,children:"Agent"}),e.jsx(B,{className:M,children:"Session"}),e.jsx(B,{className:`${M} w-28`,children:"Project"}),e.jsx(B,{className:`${M} w-20 text-right`,children:"Tokens"}),e.jsx(B,{className:`${M} w-36`,children:"Last active"}),e.jsx(B,{className:`${M} w-56`,children:"Task"}),e.jsx(B,{className:`${M} w-24`})]})}),e.jsx(gt,{children:n.slice(v,v+V).map(t=>{var _,C;const N=ae[t.status];return e.jsxs(qe,{"data-testid":"live-session-row","data-session-id":t.session_id,"data-agent":t.agent,className:"border-b border-border/65 cursor-pointer hover:bg-surface-high",onClick:y=>{y.target.closest("button, a, input, [role='dialog']")||m("session",t.id)},children:[e.jsx(I,{className:"font-label text-xs text-on-surface",children:e.jsxs("span",{className:"inline-flex items-center gap-2","data-testid":"live-status",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${N.dot}`}),((_=t.handoff)==null?void 0:_.status)==="ready"?"Ready":N.label]})}),e.jsx(I,{className:"font-label text-xs font-medium text-primary",children:t.agent}),e.jsxs(I,{className:"max-w-md",children:[e.jsx("button",{type:"button",className:"block max-w-full text-left font-body text-sm font-medium text-on-surface truncate hover:text-primary",onClick:y=>{y.stopPropagation(),m("session",t.id)},children:e.jsx(W,{text:t.name??"Untitled session",query:g?x:""})}),t.summary&&t.summary!==t.name&&e.jsx("div",{className:"font-body text-xs text-outline truncate",title:t.summary,children:e.jsx(W,{text:t.summary,query:g?x:""})}),(C=t.snippets)==null?void 0:C.map(y=>e.jsx("div",{"data-testid":"search-snippet",className:"font-mono text-xs text-on-surface-variant truncate",title:y,children:e.jsx(W,{text:y,query:x})},y)),e.jsx("div",{className:"font-label text-xs text-outline truncate",title:t.cwd??void 0,children:t.cwd??""})]}),e.jsx(I,{className:"font-label text-xs text-outline",children:t.project_id&&R.get(t.project_id)||"—"}),e.jsx(I,{"data-testid":"live-tokens",className:"font-body text-xs text-on-surface-variant text-right",children:he(t)}),e.jsx(I,{className:"font-body text-xs text-on-surface-variant",children:ne(t.last_activity_at)}),e.jsx(I,{children:e.jsx(ge,{session:t})}),e.jsx(I,{className:"text-right",children:e.jsx("div",{className:"inline-flex items-center gap-3",children:e.jsx(pe,{session:t})})})]},t.id)})})]}):e.jsx("div",{className:"divide-y divide-border",children:n.slice(v,v+V).map(t=>{var N,_;return e.jsxs("article",{"data-testid":"live-session-row","data-session-id":t.session_id,"data-agent":t.agent,className:"py-4 space-y-3",children:[e.jsx("button",{type:"button",className:"text-left text-sm font-medium break-words hover:text-primary",onClick:()=>m("session",t.id),children:e.jsx(W,{text:t.name??"Untitled session",query:g?x:""})}),e.jsxs("div",{className:"flex flex-wrap gap-3 text-xs text-outline",children:[e.jsx("span",{className:"text-primary",children:t.agent}),e.jsx("span",{"data-testid":"live-status",children:((N=t.handoff)==null?void 0:N.status)==="ready"?"Ready":ae[t.status].label}),e.jsxs("span",{"data-testid":"live-tokens",children:[he(t)," tokens"]}),e.jsx("span",{children:ne(t.last_activity_at)})]}),t.summary&&e.jsx("p",{className:"text-sm text-outline break-words",children:e.jsx(W,{text:t.summary,query:g?x:""})}),(_=t.snippets)==null?void 0:_.map(C=>e.jsx("p",{"data-testid":"search-snippet",className:"text-xs break-words text-on-surface-variant",children:e.jsx(W,{text:C,query:x})},C)),e.jsxs("p",{className:"text-xs text-outline break-all",children:[t.project_id&&R.get(t.project_id)||"Unassigned",t.cwd?` · ${t.cwd}`:""]}),e.jsx(ge,{session:t}),e.jsx(pe,{session:t})]},t.id)})}),e.jsx(vt,{page:v/V,pageSize:V,total:n.length,onPage:o})]}),e.jsx($t,{sessionId:i,initialQuery:g?x.trim():"",onClose:()=>m("session",null)},i??"closed")]})}function Ut({projectId:s}){const d=bt(s);return e.jsxs("div",{children:[e.jsx(ft,{title:"Sessions"}),e.jsx(Et,{projectId:d},d),e.jsx(yt,{projectId:d},`archive-${d}`)]})}export{Ut as default};
5
+ `)})]},a.index)),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(H,{variant:"ghost",disabled:!n,onClick:()=>v(Math.max(0,n-50)),children:"Previous messages"}),e.jsx(H,{variant:"ghost",disabled:n+50>=(((_e=te.data)==null?void 0:_e.total)??0),onClick:()=>v(n+50),children:"Next messages"})]}),e.jsxs("div",{className:"space-y-2 border-t border-outline-variant pt-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Continue on ORC"}),e.jsx("p",{className:"text-xs text-outline",children:"Use the pushed repository, branch and exact commit for the work you want to continue. The destination project must have its repository configured."}),e.jsx(ee,{htmlFor:"archive-repository",children:"Repository"}),e.jsx(W,{id:"archive-repository","data-testid":"archive-repository",value:E,onChange:a=>T(a.target.value)}),e.jsx(ee,{htmlFor:"archive-branch",children:"Branch"}),e.jsx(W,{id:"archive-branch","data-testid":"archive-branch",value:R,onChange:a=>J(a.target.value)}),e.jsx(ee,{htmlFor:"archive-commit",children:"Pushed commit"}),e.jsx(W,{id:"archive-commit","data-testid":"archive-commit",value:O,onChange:a=>P(a.target.value)}),e.jsx(ee,{htmlFor:"archive-subdirectory",children:"Repository subdirectory"}),e.jsx(W,{id:"archive-subdirectory","data-testid":"archive-subdirectory",value:D,onChange:a=>U(a.target.value),placeholder:"Repository root"}),e.jsx(H,{"data-testid":"archive-resume",disabled:c||!E||!R||!/^[a-f0-9]{40}$/i.test(O),onClick:()=>void re(async()=>{if(!r)return;const a=await z.sessions.archiveResume(r.id,{revision:r.revision,repository:E,branch:R,commit:O,subdirectory:D});if(a.status!=="ready"||!a.live_session_id)throw new Error(a.error||"Session preparation failed");const S=await z.terminals.create({kind:r.agent,live_session_id:a.live_session_id});u(`/terminals/${S.id}`)}),children:c?"Preparing…":"Prepare and resume in terminal"}),b&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:b})]})]})})]}):null}function G({text:s,query:d}){const u=d.trim();if(u.length<2)return e.jsx(e.Fragment,{children:s});const f=s.split(new RegExp(`(${Qe(u)})`,"gi"));return e.jsx(e.Fragment,{children:f.map((p,h)=>p.toLowerCase()===u.toLowerCase()?e.jsx("mark",{className:"bg-primary/30 text-on-surface rounded-sm",children:p},h):p)})}function Nt({projectId:s,pending:d,onSelect:u}){var b;const[f,p]=l.useState(""),[h,x]=l.useState(!1),[r,i]=l.useState(null),w=le({queryKey:["tasks","session-picker",s],queryFn:()=>z.tasks.list({...s?{project_id:s}:{},limit:100})});async function k(o){i(null);try{await u(o)}catch(m){i(m instanceof Error?m.message:"Could not link task")}}async function c(){x(!0),i(null);try{const o=await z.tasks.get(f.trim());await k(o.id)}catch(o){i(o instanceof Error?o.message:"Task lookup failed")}finally{x(!1)}}const $=(((b=w.data)==null?void 0:b.tasks)??[]).filter(o=>`${o.title} ${o.id}`.toLowerCase().includes(f.trim().toLowerCase()));return e.jsxs("div",{className:"space-y-3",children:[e.jsx(W,{"data-testid":"session-task-search","aria-label":"Search tasks or enter a task ID",value:f,onChange:o=>{p(o.target.value),i(null)},placeholder:"Search recent tasks or paste a task ID"}),e.jsxs("p",{className:"text-xs text-outline",children:["Up to 100 recent tasks",s?" in this project":" across projects",". Older or other-project tasks can be linked by exact ID."]}),r&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:r}),w.error?e.jsx(Ue,{message:w.error.message,onRetry:()=>w.refetch()}):w.isLoading?e.jsx("p",{role:"status",children:"Loading tasks…"}):e.jsxs("div",{className:"max-h-72 overflow-y-auto divide-y divide-border",children:[$.map(o=>e.jsxs("button",{type:"button","data-testid":"session-task-option","data-task-id":o.id,disabled:d||h,onClick:()=>void k(o.id),className:"w-full min-h-11 py-2 text-left hover:bg-surface-highest disabled:opacity-50",children:[e.jsx("span",{className:"block text-sm break-words",children:o.title}),e.jsxs("span",{className:"inline-flex items-center gap-2 text-xs text-outline",children:[e.jsx(Fe,{status:o.status,className:"px-0"}),o.id]})]},o.id)),$.length===0&&e.jsx("p",{className:"py-4 text-sm text-outline",children:"No recent task matches. Paste its exact ID to look it up."})]}),f.trim()&&e.jsx(H,{variant:"outline",disabled:d||h,onClick:()=>void c(),children:h?"Looking up…":"Link by exact ID"})]})}function ge({session:s,linkTestId:d="open-task"}){const[u]=fe(),[f,p]=l.useState(!1),h=Ge(),x=u.get("project")??s.project_id;async function r(i){try{await h.mutateAsync({id:s.id,taskId:i}),p(!1)}catch{}}return e.jsxs("div",{className:"min-w-0 space-y-1",children:[s.task&&e.jsxs("div",{className:"min-w-0",children:[e.jsx(Ve,{"data-testid":d,to:We(`/tasks/${s.task.id}`,x),className:"block max-w-64 truncate text-sm text-primary hover:underline",title:s.task.title,children:s.task.title}),e.jsx(Fe,{status:s.task.status,className:"px-0"})]}),e.jsxs(ce,{open:f,onOpenChange:i=>{p(i),i&&h.reset()},children:[e.jsx(Ye,{asChild:!0,children:e.jsxs("button",{type:"button","data-testid":"link-task",className:"inline-flex min-h-9 items-center gap-1.5 text-xs text-outline hover:text-on-surface",children:[s.task?e.jsx(jt,{size:12}):e.jsx(Xe,{size:13}),s.task?"Change task":"Link task"]})}),e.jsxs(de,{"data-testid":"session-task-dialog",className:"max-h-[85dvh] w-[calc(100%-2rem)] overflow-y-auto",children:[e.jsxs(xe,{children:[e.jsx(ue,{children:"Link a task"}),e.jsxs(me,{children:["Choose a recent task for ",s.name??"this session",", or paste an exact task ID."]})]}),h.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:h.error.message}),e.jsx(Nt,{projectId:s.project_id,pending:h.isPending,onSelect:r}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.task&&e.jsx(H,{variant:"outline","data-testid":"session-task-unlink",disabled:h.isPending,onClick:()=>void r(null),children:"Unlink task"})})]})]})]})}const oe="session-search",wt={user:"border-border/65",assistant:"border-border/65",tool:"border-border/65 bg-transparent",system:"border-border/65 bg-transparent"},kt=["command","cmd","file_path","path","pattern","query","url","description"];function St(s){try{const d=JSON.parse(s);for(const u of kt)if(typeof d[u]=="string")return d[u]}catch{}return s}function Ct(s){try{return JSON.stringify(JSON.parse(s),null,2)}catch{return s}}function _t(s,d,u){l.useEffect(()=>{const f=s.current,p=CSS.highlights,h=window.Highlight;if(!f||!p||!h)return;const x=d.trim().toLowerCase(),r=()=>{var $;if(p.delete(oe),x.length<2)return;const k=[],c=document.createTreeWalker(f,NodeFilter.SHOW_TEXT);for(let b=c.nextNode();b;b=c.nextNode()){const o=(($=b.textContent)==null?void 0:$.toLowerCase())??"";for(let m=o.indexOf(x);m>=0;m=o.indexOf(x,m+x.length)){const g=new Range;g.setStart(b,m),g.setEnd(b,m+x.length),k.push(g)}}k.length>0&&p.set(oe,new h(...k))};r();let i;const w=new MutationObserver(()=>{clearTimeout(i),i=setTimeout(r,150)});return w.observe(f,{childList:!0,subtree:!0,characterData:!0}),()=>{clearTimeout(i),w.disconnect(),p.delete(oe)}},[s,d,u])}function Tt({block:s,open:d}){const u=s.result!==void 0;return e.jsxs("details",{open:d||void 0,"data-testid":"tool-box",className:"border-l border-border bg-background",children:[e.jsxs("summary",{className:"flex cursor-pointer items-center gap-2 px-2 py-1.5 font-label text-xs font-medium text-outline hover:text-on-surface",children:[e.jsx("span",{className:"text-secondary shrink-0",children:s.name}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono normal-case tracking-normal text-on-surface-variant",children:St(s.input)}),e.jsx("span",{className:`shrink-0 ${u?"text-outline":"text-tertiary"}`,children:u?"done":"no result"})]}),e.jsxs("div",{className:"space-y-2 border-t border-border px-2 py-2",children:[e.jsx("div",{className:"font-label text-[10px] font-medium text-outline",children:"input"}),e.jsx("pre",{className:"max-h-72 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:Ct(s.input)}),u&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-label text-[10px] font-medium text-outline",children:"result"}),e.jsx("pre",{className:"max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:s.result})]})]})]})}function $t({block:s,matched:d}){if(s.type==="text")return e.jsx(Oe,{revealContext:d,children:s.text});if(s.type==="tool_use")return e.jsx(Tt,{block:s,open:d});const u=s.type==="thinking"?"thinking":"result";return e.jsxs("details",{open:d||void 0,children:[e.jsx("summary",{className:"cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface",children:u}),s.type==="thinking"?e.jsx("div",{className:"mt-1",children:e.jsx(ct,{children:s.text})}):e.jsx("pre",{className:"mt-1 max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:s.text})]})}function Lt({sessionId:s,initialQuery:d,onClose:u}){const[f,p]=l.useState(d),[h,x]=l.useState(0),{data:r}=He(!1),i=r==null?void 0:r.find(n=>n.id===s),w=i!==void 0&&i.status!=="stopped",k=f.trim().length>=2?f.trim():"",{data:c,isLoading:$,isFetching:b,error:o,refetch:m,dataUpdatedAt:g}=Ze(s,k),A=l.useRef(null),L=l.useRef(null),E=l.useRef(!0),T=l.useRef(0),[R,J]=l.useState(!0),O=l.useCallback(()=>{const n=A.current;n&&(n.scrollTo({top:n.scrollHeight}),requestAnimationFrame(()=>n.scrollTo({top:n.scrollHeight})))},[]);_t(L,k,c==null?void 0:c.turns);const P=(c==null?void 0:c.matches)??[],D=P[h];l.useEffect(()=>{var n;if(c){if(D!==void 0){E.current=!1,(n=document.getElementById(`turn-${D}`))==null||n.scrollIntoView({block:"center"});return}E.current&&O()}},[D,c,O]),l.useEffect(()=>{c&&R&&(T.current=c.total)},[c,R]);const U=n=>{P.length>0&&x(v=>(v+n+P.length)%P.length)};return e.jsx(et,{open:!!s,onOpenChange:n=>!n&&u(),children:e.jsxs(tt,{side:"right",className:"w-[1100px] max-w-[95vw]","data-testid":"live-session-detail",children:[e.jsxs(st,{children:[e.jsx(at,{className:"normal-case tracking-normal text-sm pr-8",children:(i==null?void 0:i.name)??"Session"}),i&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-5 gap-y-1 font-body text-xs text-on-surface tabular-nums",children:[e.jsx("span",{className:"font-medium text-primary",children:i.agent}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${ae[i.status].dot}`}),ae[i.status].label]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-on-surface-variant",children:"tokens "}),he(i)]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-on-surface-variant",children:"active "}),ne(i.last_activity_at)]}),e.jsx(ge,{session:i,linkTestId:"detail-open-task"}),e.jsx(pe,{session:i}),e.jsx("span",{className:"truncate max-w-full text-on-surface-variant",children:i.cwd})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-[150px] flex-1",children:[e.jsx(Be,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-outline"}),e.jsx("input",{"data-testid":"transcript-search","aria-label":"Search this session",value:f,onChange:n=>{p(n.target.value),x(0)},placeholder:"Search this session",className:"w-full bg-background border border-control-border rounded-lg min-h-11 pl-7 pr-2 py-2 font-body text-xs text-on-surface"})]}),k&&e.jsx("span",{"data-testid":"transcript-match-count",className:"font-label text-xs font-medium text-outline",children:P.length===0?"no matches":`${h+1} / ${P.length}`}),e.jsx("button",{type:"button","aria-label":"Previous match",onClick:()=>U(-1),className:"min-h-11 min-w-11 p-2 text-outline hover:text-on-surface",children:e.jsx(nt,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","aria-label":"Next match",onClick:()=>U(1),className:"min-h-11 min-w-11 p-2 text-outline hover:text-on-surface",children:e.jsx(rt,{className:"h-4 w-4"})}),e.jsxs("button",{type:"button","data-testid":"transcript-refresh",onClick:()=>{E.current=!0,m()},className:"min-h-11 px-2 inline-flex items-center gap-1 font-label text-xs font-medium text-primary hover:text-on-surface",children:[e.jsx(Ie,{className:`h-3 w-3 ${b?"animate-spin":""}`}),"Refresh"]})]}),c&&e.jsxs("div",{"data-testid":"transcript-status",className:"mt-2 font-body text-xs text-on-surface-variant tabular-nums",children:[c.total," turns",w?` · live, updated ${new Date(g).toLocaleTimeString()}`:""]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e.jsx(it,{ref:A,onScroll:n=>{const v=n.currentTarget,q=v.scrollHeight-v.scrollTop-v.clientHeight<160;E.current=q,J(q)},children:$?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((n,v)=>e.jsx(ot,{className:"h-16 w-full bg-surface-highest"},v))}):o||!c?e.jsxs("div",{"data-testid":"transcript-unavailable",className:"font-body text-xs text-outline py-12 text-center",children:[o?`Could not load the conversation: ${o.message}`:"No conversation was recorded for this session.",e.jsx("p",{className:"mt-2",children:"Resume actions remain available when the native agent session exists."}),e.jsx("button",{type:"button",className:"mt-3 min-h-11 text-primary hover:underline",onClick:()=>m(),children:"Retry conversation"})]}):e.jsx("div",{ref:L,className:"space-y-3",children:c.turns.map(n=>{const v=P.includes(n.index),q=n.blocks.map((F,t)=>e.jsx($t,{block:F,matched:v},t));return e.jsxs("div",{id:`turn-${n.index}`,"data-testid":"transcript-turn","data-role":n.role,style:{contentVisibility:"auto",containIntrinsicSize:"auto 120px"},className:`border-b px-4 py-3 text-on-surface space-y-2 ${wt[n.role]} ${n.index===D?"ring-1 ring-primary":""}`,children:[e.jsxs("div",{className:"font-label text-xs font-medium text-outline",children:[n.role,n.time?` · ${ne(n.time)}`:""]}),n.role==="system"?e.jsxs("details",{open:v||void 0,children:[e.jsx("summary",{className:"cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface",children:"injected context"}),e.jsx("div",{className:"mt-2 space-y-2",children:q})]}):q]},n.index)})})}),c&&!R&&e.jsxs("button",{type:"button","data-testid":"jump-to-latest",onClick:()=>{E.current=!0,O()},className:"absolute bottom-4 right-6 inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 font-body text-xs text-primary shadow-lg hover:bg-surface-bright",children:[e.jsx(lt,{className:"h-3.5 w-3.5"}),"Jump to latest",c.total>T.current&&` · ${c.total-T.current} new`]})]})]})})}const Pt=["claude","codex","cursor","cursor-agent","gemini"],V=25,M="font-label text-xs font-medium text-outline";function Et({projectId:s}){var F;const d=dt("sm"),[u,f]=fe(),p=u.get("agent")??"",h=u.get("ended")!=="0",x=u.get("q")??"",r=u.get("order")==="asc"?"asc":"desc",i=u.get("session"),[w,k]=l.useState(x),[c,$]=l.useState({order:r,page:0}),b=c.order===r?c.page:0,o=l.useCallback(t=>$({order:r,page:t}),[r]),m=l.useCallback((t,N)=>{o(0),f(_=>{const C=new URLSearchParams(_);return N?C.set(t,N):C.delete(t),C},{replace:t==="q"})},[f,o]);l.useEffect(()=>k(x),[x]),l.useEffect(()=>{if(w===x)return;const t=setTimeout(()=>m("q",w.trim()||null),350);return()=>clearTimeout(t)},[w,x,m]);const g=x.trim().length>=2,A=He(!h),L=xt(g?x.trim():"",p),{data:E}=Ae(),T=ut(),R=new Map((E??[]).map(t=>[t.id,t.name])),J=g?((F=L.data)==null?void 0:F.hits)??[]:A.data??[],O=[...new Set([...Pt,...J.map(t=>t.agent)])],P=g?L.isLoading:A.isLoading,D=g?L:A,U=J.filter(t=>{var N;return(!p||t.agent===p)&&(h||t.status!=="stopped"||((N=t.handoff)==null?void 0:N.status)==="ready")}),n=U.filter(t=>s==="all"?!0:s==="unassigned"?t.project_id===null:t.project_id===s).sort((t,N)=>{const C=new Date(t.last_activity_at??t.created_at).getTime()-new Date(N.last_activity_at??N.created_at).getTime()||t.id.localeCompare(N.id);return r==="asc"?C:-C}),v=Math.min(b,Math.max(0,Math.ceil(n.length/V)-1))*V,q=s==="unassigned"?"unassigned":R.get(s)??s;return e.jsxs("section",{className:"mb-8","data-testid":"live-sessions",children:[e.jsx("p",{className:"mb-4 text-sm text-outline",children:"Discovered from your coding agents. Working sessions update automatically; waiting sessions remain available to resume."}),e.jsxs("div",{className:"mb-3 relative",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-outline"}),e.jsx("input",{"data-testid":"session-search","aria-label":"Search agent sessions",value:w,onChange:t=>k(t.target.value),placeholder:"Search agent sessions: titles, summaries and conversation text",className:"w-full bg-background border border-control-border rounded-lg pl-9 pr-3 py-2 font-body text-xs text-on-surface placeholder:text-outline"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("h2",{className:"font-label text-xs font-medium text-outline",children:[g?"Search results":"Agent sessions"," · ",n.length,n.length!==U.length&&e.jsxs("span",{"data-testid":"scope-hint",className:"normal-case tracking-normal",children:[" ","of ",U.length," · scope: ",q]}),g&&L.data&&e.jsxs("span",{"data-testid":"search-meta",className:"normal-case tracking-normal",children:[" ","· ",(L.data.ms/1e3).toFixed(1),"s",L.data.rg?"":" · titles and summaries only (install ripgrep for content)"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("select",{"aria-label":"Sort sessions by date","data-testid":"session-date-sort",value:r,onChange:t=>m("order",t.target.value==="asc"?"asc":null),className:"min-h-11 rounded-md border border-control-border bg-background px-3 text-sm text-on-surface",children:[e.jsx("option",{value:"desc",children:"Last active: newest first"}),e.jsx("option",{value:"asc",children:"Last active: oldest first"})]}),e.jsxs("select",{"data-testid":"agent-filter","aria-label":"Agent",className:"bg-background border border-control-border rounded-lg min-h-11 px-3 py-2 font-label text-xs font-medium text-on-surface",value:p,onChange:t=>m("agent",t.target.value||null),children:[e.jsx("option",{value:"",children:"all agents"}),O.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("label",{className:"flex items-center gap-2 font-label text-xs font-medium text-outline cursor-pointer",children:[e.jsx("input",{type:"checkbox","data-testid":"show-ended",checked:h,onChange:t=>m("ended",t.target.checked?"1":"0")}),"Show ended"]}),e.jsxs("button",{type:"button","data-testid":"sync-sessions",disabled:T.isPending,className:"min-h-11 px-2 inline-flex items-center gap-1 font-label text-xs font-medium text-primary hover:text-on-surface disabled:opacity-50",onClick:()=>T.mutate(),children:[e.jsx(Ie,{className:`h-3 w-3 ${T.isPending?"animate-spin":""}`}),T.isPending?"Syncing":"Refresh"]})]})]}),T.error&&e.jsx("p",{role:"alert",className:"mb-3 text-sm text-error",children:T.error.message}),D.error?e.jsx(Ue,{message:D.error.message,onRetry:()=>D.refetch()}):P?e.jsx("p",{role:"status",className:"py-8 text-sm text-outline",children:"Loading sessions…"}):n.length===0?e.jsx(mt,{message:g?"No sessions match":"No active agent sessions. Enable Show ended to browse previous conversations."}):e.jsxs("div",{className:"min-w-0 overflow-hidden",children:[d?e.jsxs(ht,{children:[e.jsx(pt,{children:e.jsxs(qe,{className:"border-b border-border hover:bg-transparent",children:[e.jsx(B,{className:`${M} w-40`,children:"Status"}),e.jsx(B,{className:`${M} w-20`,children:"Agent"}),e.jsx(B,{className:M,children:"Session"}),e.jsx(B,{className:`${M} w-28`,children:"Project"}),e.jsx(B,{className:`${M} w-20 text-right`,children:"Tokens"}),e.jsx(B,{className:`${M} w-36`,children:"Last active"}),e.jsx(B,{className:`${M} w-56`,children:"Task"}),e.jsx(B,{className:`${M} w-24`})]})}),e.jsx(gt,{children:n.slice(v,v+V).map(t=>{var _,C;const N=ae[t.status];return e.jsxs(qe,{"data-testid":"live-session-row","data-session-id":t.session_id,"data-agent":t.agent,className:"border-b border-border/65 cursor-pointer hover:bg-surface-high",onClick:y=>{y.target.closest("button, a, input, [role='dialog']")||m("session",t.id)},children:[e.jsx(I,{className:"font-label text-xs text-on-surface",children:e.jsxs("span",{className:"inline-flex items-center gap-2","data-testid":"live-status",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${N.dot}`}),((_=t.handoff)==null?void 0:_.status)==="ready"?"Ready":N.label]})}),e.jsx(I,{className:"font-label text-xs font-medium text-primary",children:t.agent}),e.jsxs(I,{className:"max-w-md",children:[e.jsx("button",{type:"button",className:"block max-w-full text-left font-body text-sm font-medium text-on-surface truncate hover:text-primary",onClick:y=>{y.stopPropagation(),m("session",t.id)},children:e.jsx(G,{text:t.name??"Untitled session",query:g?x:""})}),t.summary&&t.summary!==t.name&&e.jsx("div",{className:"font-body text-xs text-outline truncate",title:t.summary,children:e.jsx(G,{text:t.summary,query:g?x:""})}),(C=t.snippets)==null?void 0:C.map(y=>e.jsx("div",{"data-testid":"search-snippet",className:"font-mono text-xs text-on-surface-variant truncate",title:y,children:e.jsx(G,{text:y,query:x})},y)),e.jsx("div",{className:"font-label text-xs text-outline truncate",title:t.cwd??void 0,children:t.cwd??""})]}),e.jsx(I,{className:"font-label text-xs text-outline",children:t.project_id&&R.get(t.project_id)||"—"}),e.jsx(I,{"data-testid":"live-tokens",className:"font-body text-xs text-on-surface-variant text-right",children:he(t)}),e.jsx(I,{className:"font-body text-xs text-on-surface-variant",children:ne(t.last_activity_at)}),e.jsx(I,{children:e.jsx(ge,{session:t})}),e.jsx(I,{className:"text-right",children:e.jsx("div",{className:"inline-flex items-center gap-3",children:e.jsx(pe,{session:t})})})]},t.id)})})]}):e.jsx("div",{className:"divide-y divide-border",children:n.slice(v,v+V).map(t=>{var N,_;return e.jsxs("article",{"data-testid":"live-session-row","data-session-id":t.session_id,"data-agent":t.agent,className:"py-4 space-y-3",children:[e.jsx("button",{type:"button",className:"text-left text-sm font-medium break-words hover:text-primary",onClick:()=>m("session",t.id),children:e.jsx(G,{text:t.name??"Untitled session",query:g?x:""})}),e.jsxs("div",{className:"flex flex-wrap gap-3 text-xs text-outline",children:[e.jsx("span",{className:"text-primary",children:t.agent}),e.jsx("span",{"data-testid":"live-status",children:((N=t.handoff)==null?void 0:N.status)==="ready"?"Ready":ae[t.status].label}),e.jsxs("span",{"data-testid":"live-tokens",children:[he(t)," tokens"]}),e.jsx("span",{children:ne(t.last_activity_at)})]}),t.summary&&e.jsx("p",{className:"text-sm text-outline break-words",children:e.jsx(G,{text:t.summary,query:g?x:""})}),(_=t.snippets)==null?void 0:_.map(C=>e.jsx("p",{"data-testid":"search-snippet",className:"text-xs break-words text-on-surface-variant",children:e.jsx(G,{text:C,query:x})},C)),e.jsxs("p",{className:"text-xs text-outline break-all",children:[t.project_id&&R.get(t.project_id)||"Unassigned",t.cwd?` · ${t.cwd}`:""]}),e.jsx(ge,{session:t}),e.jsx(pe,{session:t})]},t.id)})}),e.jsx(vt,{page:v/V,pageSize:V,total:n.length,onPage:o})]}),e.jsx(Lt,{sessionId:i,initialQuery:g?x.trim():"",onClose:()=>m("session",null)},i??"closed")]})}function Ut({projectId:s}){const d=bt(s);return e.jsxs("div",{children:[e.jsx(ft,{title:"Sessions"}),e.jsx(Et,{projectId:d},d),e.jsx(yt,{projectId:d},`archive-${d}`)]})}export{Ut as default};
@@ -1,20 +1,20 @@
1
- import{r as m,j as e,G as re,c as M,d as _,c0 as V,Y as g,Z as y,ah as K,B as w,Q as ie,am as oe,an as A,ao as F,ap as D,aq as T,ar as C,a7 as de,a as J,b as le,c1 as ce,c2 as me,c3 as he,ag as ue,c4 as xe,c5 as ge,E as pe,bD as fe,a9 as G,c6 as O,V as be,c7 as Y,c8 as q}from"./index-DqE2dG9P.js";import{u as ve,a as je,b as ye,c as Ne}from"./useKnowledge-BwBd_xnP.js";import{D as ke}from"./download-BS_0-AxS.js";import{S as X}from"./save-wtDP4EBM.js";var _e=Object.defineProperty,ee=(t,n)=>_e(t,"name",{value:n,configurable:!0}),z={Horizontal:"horizontal",Vertical:"vertical"},W=z.Horizontal,we=Object.values(z),te=m.forwardRef(ee(function(n,h){const{decorative:c,orientation:s=W,...x}=n,p=se(s)?s:W,b=p===z.Vertical?p:void 0,v=c?{role:"none"}:{"aria-orientation":b,role:"separator"};return e.jsx(re.div,{"data-orientation":p,...v,...x,ref:h})},"Separator"));function se(t){return we.includes(t)}ee(se,"isValidOrientation");/**
1
+ import{r as m,j as e,I as re,c as M,d as k,c1 as V,_ as p,$ as y,T as K,c2 as ie,B as w,W as oe,an as de,ao as F,ap as T,aq as A,ar as D,as as C,a9 as le,a as X,b as ce,c3 as me,c4 as he,c5 as ue,ai as xe,c6 as ge,c7 as pe,E as fe,bE as be,ab as G,c8 as I,V as ve,c9 as W,ca as q}from"./index-hiTCEgOL.js";import{u as je,a as ye,b as Ne,c as _e}from"./useKnowledge-BxN3CmKQ.js";import{D as ke}from"./download-CkO5a0rx.js";import{S as Z}from"./save-kaln3lLx.js";var we=Object.defineProperty,ee=(t,n)=>we(t,"name",{value:n,configurable:!0}),z={Horizontal:"horizontal",Vertical:"vertical"},Y=z.Horizontal,Se=Object.values(z),te=m.forwardRef(ee(function(n,h){const{decorative:c,orientation:s=Y,...x}=n,g=se(s)?s:Y,b=g===z.Vertical?g:void 0,v=c?{role:"none"}:{"aria-orientation":b,role:"separator"};return e.jsx(re.div,{"data-orientation":g,...v,...x,ref:h})},"Separator"));function se(t){return Se.includes(t)}ee(se,"isValidOrientation");/**
2
2
  * @license lucide-react v1.27.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const Se=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Ce=M("circle-check-big",Se);/**
6
+ */const Ce=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Ee=M("circle-check-big",Ce);/**
7
7
  * @license lucide-react v1.27.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const Ee=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]],Re=M("plug",Ee);/**
11
+ */const Re=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]],Pe=M("plug",Re);/**
12
12
  * @license lucide-react v1.27.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const Pe=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],Oe=M("rotate-cw",Pe);function Ie(){const[t,n]=m.useState(null),[h,c]=m.useState(""),[s,x]=m.useState(""),[p,b]=m.useState(!1);m.useEffect(()=>{let o=!1;return _.settings.get().then(d=>{if(o)return;const f=V.parse(d.chat??{});n(f),c(f.models.map(u=>`${u.agent}: ${u.id}`).join(`
16
+ */const Ie=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],Oe=M("rotate-cw",Ie);function Fe(){const[t,n]=m.useState(null),[h,c]=m.useState(""),[s,x]=m.useState(""),[g,b]=m.useState(!1);m.useEffect(()=>{let o=!1;return k.settings.get().then(d=>{if(o)return;const f=V.parse(d.chat??{});n(f),c(f.models.map(u=>`${u.agent}: ${u.id}`).join(`
17
17
  `))}).catch(d=>{o||x(d.message)}),()=>{o=!0}},[]);async function v(){if(t){b(!0),x("");try{const o=h.split(`
18
- `).filter(f=>f.trim()).map(f=>{const u=f.match(/^([a-z][a-z0-9-]*):\s*(.+)$/i);if(!u)throw new Error("Use agent: model-id on each model line.");return{agent:u[1]??"",id:u[2]??""}}),d=V.parse({...t,models:o});await _.settings.save({chat:d}),n(d),window.dispatchEvent(new Event("orc-chat-settings-changed")),x("Chat defaults saved. They apply to new conversations on every device.")}catch(o){x(o instanceof Error?o.message:"Chat settings could not be saved.")}finally{b(!1)}}}return e.jsxs("section",{"aria-labelledby":"chat-settings-title",className:"space-y-4","data-testid":"chat-settings",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"chat-settings-title",className:"text-base font-medium",children:"Chat"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Defaults for new conversations. Existing chats keep their configuration. Credentials stay on the execution host."})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"chat-default-agent",children:"Default agent"}),e.jsx(y,{id:"chat-default-agent","data-testid":"chat-default-agent",value:t.agent,onChange:o=>n({...t,agent:o.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"chat-default-model",children:"Default model"}),e.jsx(y,{id:"chat-default-model","data-testid":"chat-default-model",value:t.model,placeholder:"Agent default",onChange:o=>n({...t,model:o.target.value})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"chat-model-catalog",children:"Model picker choices"}),e.jsx(K,{id:"chat-model-catalog","data-testid":"chat-model-catalog",value:h,onChange:o=>c(o.target.value),placeholder:`codex: your-model-id
19
- claude: your-model-id`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"One agent: model-id per line. Use model IDs supported by your installed agent and account."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"chat-system-prompt",children:"Instructions"}),e.jsx(K,{id:"chat-system-prompt","data-testid":"chat-system-prompt",rows:6,value:t.system,onChange:o=>n({...t,system:o.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Claude appends these to its coding system prompt. Codex and other agents receive them as turn instructions. Workspace rules remain enforced."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"chat-mcp",children:"Tools connection"}),e.jsxs("select",{id:"chat-mcp","data-testid":"chat-mcp",className:"min-h-11 w-full rounded-md border border-control-border bg-background px-3 text-base sm:text-sm",value:t.mcp,onChange:o=>n({...t,mcp:o.target.value}),children:[e.jsx("option",{value:"orc",children:"Connect ORC MCP (Claude and Codex)"}),e.jsx("option",{value:"native",children:"Use the agent’s host configuration"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The ORC connection uses server credentials internally. Host configuration may include other MCP servers; this setting does not disable them. Protected workspaces may also require ORC tools."})]}),e.jsxs("label",{className:"flex min-h-11 items-start gap-3 py-2 text-sm",children:[e.jsx("input",{"data-testid":"chat-auto-approve",type:"checkbox",checked:t.autoApprove,onChange:o=>n({...t,autoApprove:o.target.checked}),className:"mt-1 size-4"}),e.jsxs("span",{children:["Allow agent actions automatically",e.jsx("span",{className:"mt-1 block text-xs text-muted-foreground",children:"Off: Claude asks in chat; Codex runs with a read-only sandbox; other agents use their native permission policy. On: Claude bypasses permission prompts; Codex can write in its workspace. ORC rules still apply."})]})]}),e.jsx(w,{"data-testid":"chat-settings-save",disabled:p,onClick:()=>void v(),children:p?"Saving…":"Save chat defaults"})]}),s&&e.jsx("p",{role:"status","data-testid":"chat-settings-feedback",className:"break-words text-sm text-muted-foreground",children:s})]})}const E=m.forwardRef(({className:t,orientation:n="horizontal",decorative:h=!0,...c},s)=>e.jsx(te,{ref:s,decorative:h,orientation:n,className:ie("shrink-0 bg-surface-bright ",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...c}));E.displayName=te.displayName;const P=1024*1024;function Q(t){return t===null?"":t>=1024*P?`${(t/1024/P).toFixed(1)} GB`:`${Math.round(t/P)} MB`}function Ae(t){return{session_embeddings:t.session_embeddings??!1,parser:t.parser,docling_enabled:t.docling_enabled,parser_timeout_secs:String(t.parser_timeout_secs),max_upload_mb:String(Math.round(t.max_upload_bytes/P)),usage_retention_days:String(t.usage_retention_days),provider:t.embedding.provider,base_url:t.embedding.base_url??"",model:t.embedding.model??"",dimensions:t.embedding.dimensions?String(t.embedding.dimensions):"",api_key:"",clear_key:!1}}const Fe={none:"Keyword search only. Add an embedding provider for semantic and hybrid search.",ollama:"Local embeddings from Ollama, for example nomic-embed-text at http://localhost:11434.",openai:"OpenAI or any OpenAI-compatible endpoint, for example text-embedding-3-small."};function De(){var L,$,H,U;const t=ve(),n=je(),h=ye(),c=Ne(),[s,x]=m.useState(null),[p,b]=m.useState(null),[v,o]=m.useState(!1),[d,f]=m.useState(!1),[u,k]=m.useState(!1);if(m.useEffect(()=>{t.data&&x(Ae(t.data))},[t.data]),t.error)return e.jsxs("section",{children:[e.jsx("h2",{className:"mb-1 text-base font-medium",children:"Knowledge"}),e.jsx("p",{role:"alert",className:"text-sm text-error",children:t.error.message})]});if(!s||!t.data)return null;const j=t.data,N=a=>j.env_overrides.includes(`ORC_KNOWLEDGE_${a}`),l=a=>{o(!1),x({...s,...a})},i=(L=n.data)==null?void 0:L.parsers.find(a=>a.id==="docling"),r=($=n.data)==null?void 0:$.docling;async function S(a){f(!0),b(null);try{return await a(),await c(),!0}catch(R){return b(R instanceof Error?R.message:"Request failed"),!1}finally{f(!1)}}async function ae(a){if(a.preventDefault(),!s)return;const R=B=>B.trim()?Number(B):null,ne={session_embeddings:s.session_embeddings,parser:s.parser,docling_enabled:s.docling_enabled,parser_timeout_secs:Number(s.parser_timeout_secs),max_upload_bytes:Number(s.max_upload_mb)*P,usage_retention_days:Number(s.usage_retention_days),embedding:{provider:s.provider,base_url:s.base_url.trim()||null,model:s.model.trim()||null,dimensions:R(s.dimensions),...s.clear_key?{api_key:null}:s.api_key?{api_key:s.api_key}:{}}};await S(()=>_.kb.updateSettings(ne))&&o(!0)}return e.jsxs("section",{"data-testid":"settings-knowledge","aria-labelledby":"settings-knowledge-title",children:[e.jsx("h2",{id:"settings-knowledge-title",className:"mb-1 text-base font-medium text-on-surface",children:"Knowledge"}),e.jsxs("p",{className:"mb-4 text-sm text-muted-foreground",children:["How ORC parses uploads and searches knowledge bases. Saved on the server in"," ",e.jsx("code",{className:"text-primary",children:"~/.orc/config.json"}),"; files live in"," ",e.jsx("code",{className:"break-all text-primary",children:j.root}),"."]}),e.jsx(E,{className:"mb-4 bg-outline-variant"}),j.env_overrides.length>0&&e.jsxs("p",{className:"mb-4 text-sm text-warning","data-testid":"settings-knowledge-env",children:["Set by environment, these win over saved values: ",j.env_overrides.join(", ")]}),e.jsxs("form",{onSubmit:ae,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Parsers"}),(H=n.data)==null?void 0:H.parsers.map(a=>e.jsxs("div",{"data-testid":`settings-parser-${a.id}`,className:"rounded-md border border-outline-variant p-3 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:a.label}),e.jsxs("span",{className:"text-xs text-outline",children:[a.installed?`v${a.version}`:"not installed",a.size_bytes?` · ${Q(a.size_bytes)}${a.installed?"":" download"}`:""]})]}),e.jsx("p",{className:"mt-1 text-outline",children:a.description}),e.jsxs("p",{className:"mt-1 text-xs text-outline",children:["Formats: ",a.capabilities.formats.join(", ")]}),a.detail&&e.jsx("p",{className:"mt-1 text-xs text-outline",children:a.detail}),a.id==="docling"&&e.jsxs("div",{className:"mt-3 space-y-2",children:[(r==null?void 0:r.state)==="installing"&&e.jsxs("div",{role:"status","data-testid":"settings-docling-progress",className:"text-xs text-outline",children:[r.step,e.jsx("pre",{className:"mt-1 max-h-32 overflow-y-auto whitespace-pre-wrap font-mono",children:r.log.slice(-8).join(`
20
- `)})]}),(r==null?void 0:r.state)==="failed"&&e.jsx("p",{role:"alert",className:"text-xs text-error",children:r.error}),a.installed?e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox","data-testid":"settings-docling-enabled",checked:s.docling_enabled,onChange:R=>l({docling_enabled:R.target.checked})}),"Use automatically for PDFs and images"]}),e.jsxs(w,{type:"button",size:"sm",variant:"ghost",className:"text-error","data-testid":"settings-docling-remove",onClick:()=>k(!0),children:[e.jsx(oe,{size:14}),"Remove"]})]}):e.jsxs(w,{type:"button",size:"sm",variant:"outline","data-testid":"settings-docling-install",disabled:d||(r==null?void 0:r.state)==="installing",onClick:()=>S(()=>_.kb.installDocling()),children:[e.jsx(ke,{size:14}),(r==null?void 0:r.state)==="installing"?"Installing…":`Install Docling (${Q((i==null?void 0:i.size_bytes)??null)||"about 2 GB"})`]})]})]},a.id)),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"settings-kb-parser",className:"text-sm text-muted-foreground",children:"Default parser"}),e.jsxs(A,{value:s.parser,onValueChange:a=>l({parser:a}),disabled:N("PARSER"),children:[e.jsx(F,{id:"settings-kb-parser","data-testid":"settings-kb-parser",children:e.jsx(D,{})}),e.jsxs(T,{children:[e.jsx(C,{value:"auto",children:"Automatic: Docling for PDFs and images when enabled"}),(U=n.data)==null?void 0:U.parsers.map(a=>e.jsx(C,{value:a.id,disabled:!a.installed,children:a.label},a.id))]})]}),e.jsx("p",{className:"text-xs text-outline",children:"Knowledge bases can override it. Changing parsers applies to new uploads; reparse a document to apply it to existing ones."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"settings-kb-timeout",className:"text-sm text-muted-foreground",children:"Parse timeout (s)"}),e.jsx(y,{id:"settings-kb-timeout",type:"number",min:10,value:s.parser_timeout_secs,onChange:a=>l({parser_timeout_secs:a.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"settings-kb-max-upload",className:"text-sm text-muted-foreground",children:"Max upload (MB)"}),e.jsx(y,{id:"settings-kb-max-upload",type:"number",min:1,value:s.max_upload_mb,onChange:a=>l({max_upload_mb:a.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"settings-kb-retention",className:"text-sm text-muted-foreground",children:"Read log (days)"}),e.jsx(y,{id:"settings-kb-retention",type:"number",min:1,value:s.usage_retention_days,onChange:a=>l({usage_retention_days:a.target.value})})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Semantic search"}),e.jsxs("label",{className:"flex items-start gap-2 text-sm",children:[e.jsx("input",{type:"checkbox","data-testid":"settings-session-embeddings",checked:s.session_embeddings,onChange:a=>l({session_embeddings:a.target.checked})}),e.jsxs("span",{children:["Search coding sessions with embeddings",e.jsx("span",{className:"block text-xs text-outline",children:"Uses the provider below for session passages. Keyword search and transcript reading remain available when off. Enabling sends session text to this provider and indexes discovered project sessions."})]})]}),h.data&&e.jsxs("p",{className:"text-xs text-outline","data-testid":"settings-embedding-status",children:[h.data.embedding.ready?`Ready · ${h.data.embedding.model} · ${h.data.embedding.vector_backend}`:h.data.embedding.detail??"Not configured",h.data.embedding.pending_chunks?` · ${h.data.embedding.pending_chunks} passages waiting`:""]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"settings-kb-provider",className:"text-sm text-muted-foreground",children:"Embedding provider"}),e.jsxs(A,{value:s.provider,onValueChange:a=>l({provider:a}),disabled:N("EMBEDDING_PROVIDER"),children:[e.jsx(F,{id:"settings-kb-provider","data-testid":"settings-kb-provider",children:e.jsx(D,{})}),e.jsxs(T,{children:[e.jsx(C,{value:"none",children:"None"}),e.jsx(C,{value:"ollama",children:"Ollama"}),e.jsx(C,{value:"openai",children:"OpenAI-compatible"})]})]}),e.jsx("p",{className:"text-xs text-outline",children:Fe[s.provider]})]}),s.provider!=="none"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"settings-kb-model",className:"text-sm text-muted-foreground",children:"Model"}),e.jsx(y,{id:"settings-kb-model","data-testid":"settings-kb-model",value:s.model,disabled:N("EMBEDDING_MODEL"),onChange:a=>l({model:a.target.value}),placeholder:s.provider==="ollama"?"nomic-embed-text":"text-embedding-3-small"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"settings-kb-dimensions",className:"text-sm text-muted-foreground",children:"Dimensions"}),e.jsx(y,{id:"settings-kb-dimensions",type:"number",value:s.dimensions,onChange:a=>l({dimensions:a.target.value}),placeholder:"Model default"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"settings-kb-base-url",className:"text-sm text-muted-foreground",children:"Base URL"}),e.jsx(y,{id:"settings-kb-base-url","data-testid":"settings-kb-base-url",value:s.base_url,disabled:N("EMBEDDING_URL"),onChange:a=>l({base_url:a.target.value}),placeholder:s.provider==="ollama"?"http://localhost:11434":"https://api.openai.com/v1"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{htmlFor:"settings-kb-api-key",className:"text-sm text-muted-foreground",children:s.provider==="ollama"?"Token (hosted or proxied Ollama)":"API key"}),e.jsx(y,{id:"settings-kb-api-key",type:"password",autoComplete:"off","data-testid":"settings-kb-api-key",value:s.api_key,disabled:s.clear_key||N("EMBEDDING_API_KEY"),onChange:a=>l({api_key:a.target.value}),placeholder:j.embedding.api_key_set?"Saved. Type to replace":"Not set"}),j.embedding.api_key_set&&e.jsxs("label",{className:"flex items-center gap-2 text-xs text-outline",children:[e.jsx("input",{type:"checkbox","data-testid":"settings-kb-api-key-clear",checked:s.clear_key,onChange:a=>l({clear_key:a.target.checked,api_key:""})}),"Remove the saved key"]}),e.jsxs("p",{className:"text-xs text-outline",children:["Stored encrypted with the key in ",e.jsx("code",{children:"~/.orc/secret.key"})," and never sent back to the browser. Sent as a bearer token to the base URL."]})]}),e.jsx("p",{className:"text-xs text-outline",children:"Changing the model re-embeds every passage in the background; keyword search keeps working meanwhile."})]})]}),p&&e.jsx("p",{role:"alert","data-testid":"settings-knowledge-error",className:"text-sm text-error",children:p}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(w,{type:"submit","data-testid":"settings-knowledge-save",disabled:d,children:"Save knowledge settings"}),v&&e.jsx("span",{role:"status",className:"text-sm text-muted-foreground",children:"Saved"})]})]}),e.jsx(de,{open:u,title:"Remove Docling",description:"Deletes the Docling runtime and models from this machine. Documents it parsed keep their text; reparse them to use the basic parser.",confirmLabel:"Remove",isPending:d,onCancel:()=>k(!1),onConfirm:async()=>{k(!1),await S(()=>_.kb.uninstallDocling())}})]})}function Te(){const t=J();return le({mutationFn:async()=>{const n=await _.system.restart(),h=Date.now()+6e4;for(;Date.now()<h;){await new Promise(c=>setTimeout(c,500));try{if((await _.health.check(AbortSignal.timeout(2e3))).instance_id!==n.instance_id)return}catch(c){if(c instanceof ce&&c.status===401)throw c}}throw new Error("ORC has not reconnected yet. Check the server and try again when it is online.")},onSuccess:()=>t.invalidateQueries()})}function Me(){const{data:t}=me(),n=Te();return e.jsxs("section",{"aria-labelledby":"server-title",children:[e.jsx("h2",{id:"server-title",className:"mb-1 text-base font-medium",children:"ORC server"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Restart ORC to reload server and host information. This closes active terminals and may interrupt running work. Your settings are kept, and this dashboard reconnects automatically. Switching hosts applies to new actions without a restart."}),e.jsx(E,{className:"mb-4"}),e.jsxs(w,{variant:"outline","data-testid":"settings-restart",disabled:!(t!=null&&t.restart_supported)||n.isPending,onClick:()=>n.mutate(),children:[e.jsx(Oe,{className:n.isPending?"mr-2 size-4 animate-spin":"mr-2 size-4"}),n.isPending?"Restarting and reconnecting…":"Restart ORC server"]}),t&&!t.restart_supported&&e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This server does not support restart from the dashboard."}),n.isPending&&e.jsx("p",{role:"status","data-testid":"settings-restart-status",className:"mt-2 text-sm text-muted-foreground",children:"Waiting for ORC to restart…"}),n.isSuccess&&e.jsx("p",{role:"status","data-testid":"settings-restart-status",className:"mt-2 text-sm text-muted-foreground",children:"ORC restarted. Reconnected."}),n.isError&&e.jsx("p",{role:"alert","data-testid":"settings-restart-error",className:"mt-2 text-sm text-error",children:n.error.message})]})}const I="__local__";function Z(t){return t?t instanceof Error?t.message:String(t):null}function ze(){var i;const{data:t,error:n,refetch:h}=he(),{data:c}=ue(),s=xe(),x=ge(),[p,b]=m.useState(I),[v,o]=m.useState("");if(m.useEffect(()=>{t&&(b(t.host??I),o(t.remote_port===null?"":String(t.remote_port)))},[t]),n)return e.jsxs("section",{children:[e.jsx("h2",{className:"mb-3 text-base font-semibold",children:"Execution host"}),e.jsx(pe,{message:n.message,onRetry:()=>void h()})]});if(!t)return e.jsx("p",{role:"status","data-testid":"page-loading",className:"text-sm text-muted-foreground",children:"Loading execution host…"});const d=p===I?null:p,f=t.host&&!t.hosts.includes(t.host)?[t.host,...t.hosts]:t.hosts,u=Number(v),k=v.trim()===""||Number.isInteger(u)&&u>=1&&u<=65535,j=t.locked||!t.supported,N=c==null?void 0:c.backends.find(r=>r.name==="claude"),l=((i=x.data)==null?void 0:i.host)===d?x.data:void 0;return e.jsxs("section",{"data-testid":"ssh-settings",children:[e.jsx("h2",{className:"font-headline font-semibold text-base text-on-surface mb-1",children:"Execution host"}),e.jsxs("p",{className:"font-body text-sm text-muted-foreground mb-4",children:["Run every agent, terminal, git and file action on a host from"," ",e.jsx("code",{className:"text-primary",children:"~/.ssh/config"}),". Agents there reach orc through a reverse tunnel on the remote port. Terminals already open keep their host."]}),e.jsx(E,{className:"bg-surface-highest mb-4"}),e.jsxs("div",{className:"space-y-4",children:[t.locked&&e.jsx("p",{"data-testid":"ssh-locked",className:"font-body text-sm text-tertiary",children:"Fixed by ORC_SSH_HOST in orc's environment."}),!t.supported&&e.jsx("p",{"data-testid":"ssh-unsupported",className:"font-body text-sm text-error",children:t.unsupported_reason}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"ssh-host",className:"font-label text-sm text-muted-foreground",children:"Host"}),e.jsxs(A,{value:p,onValueChange:b,disabled:j,children:[e.jsx(F,{id:"ssh-host","aria-label":"Execution host","data-testid":"ssh-host-picker",className:"bg-surface-highest border-control-border text-on-surface font-body text-sm",children:e.jsx(D,{})}),e.jsxs(T,{className:"bg-surface-highest border-outline-variant max-h-72",children:[e.jsx(C,{value:I,"data-testid":"ssh-host-option-local",className:"font-label text-sm",children:"Local (this machine)"}),f.map(r=>e.jsx(C,{value:r,"data-testid":`ssh-host-option-${r}`,className:"font-label text-sm",children:r},r))]})]}),f.length===0&&e.jsx("p",{"data-testid":"page-empty",className:"font-body text-sm text-muted-foreground",children:"No Host entries found in ~/.ssh/config on the machine running orc."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"ssh-remote-port",className:"font-label text-sm text-muted-foreground",children:"Tunnel port override"}),e.jsx(y,{id:"ssh-remote-port","aria-invalid":!!(d&&!k),"data-testid":"ssh-remote-port",value:v,placeholder:"Automatic",onChange:r=>o(r.target.value),disabled:j||!d,inputMode:"numeric",className:"bg-surface-highest border-outline-variant text-on-surface font-body text-sm"}),d&&!k&&e.jsx("p",{className:"text-sm text-error",children:"Enter a remote port from 1 to 65535."}),e.jsx("p",{className:"font-body text-sm text-muted-foreground",children:"Leave empty to let SSH choose an available port automatically."})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(w,{"data-testid":"ssh-save",disabled:j||d!==null&&!k||s.isPending,onClick:()=>s.mutate({host:d,remotePort:d&&v.trim()?u:null}),className:"font-label text-sm bg-primary text-primary-foreground hover:bg-primary/90",children:[e.jsx(X,{size:12,className:"mr-1.5"})," Use Host"]}),e.jsxs(w,{"data-testid":"ssh-test",variant:"ghost",disabled:!d||!t.supported||x.isPending,onClick:()=>d&&x.mutate(d),className:"font-label text-sm text-muted-foreground hover:text-on-surface",children:[e.jsx(Re,{size:12,className:"mr-1.5"})," ",x.isPending?"Testing…":"Test"]})]}),Z(s.error??x.error)&&e.jsx("p",{"data-testid":"ssh-error",className:"font-body text-sm text-error",children:Z(s.error??x.error)}),l&&e.jsx("div",{"data-testid":"ssh-test-result",className:"font-body text-sm space-y-1",children:l.ok?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-secondary",children:["Connected to ",l.host," (",l.os,", ",l.shell,")"]}),e.jsx("p",{className:"text-muted-foreground",children:Object.entries(l.binaries).map(([r,S])=>`${S?"●":"○"} ${r}`).join(" ")}),l.binaries.claude&&l.claude_logged_in===!1&&e.jsxs("p",{className:l.api_key_forwarded?"text-muted-foreground":"text-error",children:["claude is not logged in on ",l.host,"."," ",l.api_key_forwarded?"ANTHROPIC_API_KEY from orc's environment will be forwarded.":"Set ANTHROPIC_API_KEY in orc's environment or run claude login there."]})]}):e.jsx("p",{className:"text-error",children:l.error})}),t.host&&N&&!N.available&&e.jsxs("p",{"data-testid":"ssh-claude-error",className:"font-body text-sm text-error",children:["claude backend: ",N.error]})]})]})}function Be(){const{theme:t}=fe(),[n,h]=m.useState(G),[c,s]=m.useState(()=>localStorage.getItem(O)??""),[x,p]=m.useState(!1),[b,v]=m.useState(""),[o,d]=m.useState(""),[f,u]=m.useState(!1),k=J(),j=async()=>{d(""),u(!0);try{const i=n.trim();if(i&&!i.startsWith("/")&&!/^https?:\/\//i.test(i))throw new Error("Use a relative API path or an http(s) server URL.");const r=await _.settings.save({theme:t,terminal_font:c.trim()});Y(r.theme??t),s(r.terminal_font??""),r.terminal_font?localStorage.setItem(O,r.terminal_font):localStorage.removeItem(O);const S=(i||"/api")!==G();localStorage.setItem("orc_api_url",i||"/api"),S&&window.dispatchEvent(new Event(q)),k.invalidateQueries(),p(!0),v("Workspace preferences saved on the server. API address saved in this browser."),setTimeout(()=>p(!1),2e3)}catch(i){d(i instanceof Error?i.message:"Browser settings could not be saved.")}finally{u(!1)}},N=async()=>{d(""),u(!0);try{const i=await _.settings.save({terminal_font:""});localStorage.removeItem("orc_api_url"),localStorage.setItem(O,i.terminal_font??""),h("/api"),s(i.terminal_font??""),window.dispatchEvent(new Event(q)),k.invalidateQueries(),p(!1),v("Connection and terminal font restored to their defaults. Appearance and execution host were kept.")}catch(i){d(i instanceof Error?i.message:"Browser settings could not be reset.")}finally{u(!1)}};async function l(i){d(""),u(!0);try{const r=await _.settings.save({theme:i});Y(r.theme??i)}catch(r){d(r instanceof Error?r.message:"Appearance could not be saved.")}finally{u(!1)}}return e.jsxs("div",{children:[e.jsx(be,{title:"Settings"}),e.jsxs("div",{className:"max-w-lg space-y-8",children:[e.jsxs("section",{"aria-labelledby":"appearance-title",children:[e.jsx("h2",{id:"appearance-title",className:"mb-1 text-base font-medium",children:"Appearance"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Choose a workspace theme. Your choice is saved on the server immediately."}),e.jsx("fieldset",{className:"flex flex-wrap gap-2","aria-label":"Theme",children:["dark","light"].map(i=>e.jsx(w,{variant:t===i?"secondary":"outline","aria-pressed":t===i,"data-testid":`settings-theme-${i}`,disabled:f,onClick:()=>void l(i),children:i==="dark"?"Dark":"Light"},i))})]}),e.jsxs("section",{children:[e.jsx("h2",{className:"font-headline font-medium text-base text-on-surface mb-1",children:"API connection"}),e.jsxs("p",{className:"font-body text-sm text-muted-foreground mb-4",children:["Connect this workspace to an ORC server. The default"," ",e.jsx("code",{className:"text-primary",children:"/api"})," uses the current server or the configured development proxy."]}),e.jsx(E,{className:"bg-outline-variant mb-4"}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"settings-api-url",className:"font-label text-sm text-muted-foreground",children:"API base URL"}),e.jsx(y,{id:"settings-api-url","data-testid":"settings-api-url",value:n,onChange:i=>h(i.target.value),placeholder:"/api or http://localhost:7700",className:"bg-background text-on-surface font-body text-sm"}),e.jsxs("p",{className:"font-body text-sm text-muted-foreground",children:["Use ",e.jsx("code",{children:"/api"})," (dev proxy) or a direct URL when CORS is enabled."]})]})})]}),e.jsx(ze,{}),e.jsx(Me,{}),e.jsx(Ie,{}),e.jsx(De,{}),e.jsxs("section",{children:[e.jsx("h2",{className:"font-headline font-medium text-base text-on-surface mb-1",children:"Terminal"}),e.jsx("p",{className:"font-body text-sm text-muted-foreground mb-4",children:"Prompt and agent status icons need a Nerd Font installed on this machine. Common ones are tried automatically; set the exact family name if your icons show as empty boxes. Applies to terminals opened after saving."}),e.jsx(E,{className:"bg-outline-variant mb-4"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"settings-terminal-font",className:"font-label text-sm text-muted-foreground",children:"Terminal font family"}),e.jsx(y,{id:"settings-terminal-font",value:c,onChange:i=>s(i.target.value),placeholder:"e.g. MesloLGS NF",className:"bg-background text-on-surface font-body text-sm"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 pt-2",children:[e.jsx(w,{"data-testid":"settings-save",disabled:f,onClick:()=>void j(),className:"font-label text-sm ",children:x?e.jsxs(e.Fragment,{children:[e.jsx(Ce,{size:12,className:"mr-1.5"})," Saved"]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{size:12,className:"mr-1.5"})," Save settings"]})}),e.jsx(w,{variant:"ghost",disabled:f,onClick:()=>void N(),className:"font-label text-sm text-muted-foreground hover:text-on-surface",children:"Reset to defaults"})]}),o&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:o}),b&&!o&&e.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:b}),e.jsxs("section",{children:[e.jsx(E,{className:"bg-outline-variant mb-4"}),e.jsx("div",{className:"font-label text-sm text-muted-foreground mb-2",children:"Storage"}),e.jsxs("p",{className:"font-body text-sm text-muted-foreground",children:["Workspace preferences and SSH selection are persisted in the server's"," ",e.jsx("code",{children:"~/.orc/config.json"}),". The API address and optionally remembered login are stored in this browser."]})]})]})]})}export{Be as default};
18
+ `).filter(f=>f.trim()).map(f=>{const u=f.match(/^([a-z][a-z0-9-]*):\s*(.+)$/i);if(!u)throw new Error("Use agent: model-id on each model line.");return{agent:u[1]??"",id:u[2]??""}}),d=V.parse({...t,models:o});await k.settings.save({chat:d}),n(d),window.dispatchEvent(new Event("orc-chat-settings-changed")),x("Chat defaults saved. They apply to new conversations on every device.")}catch(o){x(o instanceof Error?o.message:"Chat settings could not be saved.")}finally{b(!1)}}}return e.jsxs("section",{"aria-labelledby":"chat-settings-title",className:"space-y-4","data-testid":"chat-settings",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"chat-settings-title",className:"text-base font-medium",children:"Chat"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Defaults for new conversations. Existing chats keep their configuration. Credentials stay on the execution host."})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"chat-default-agent",children:"Default agent"}),e.jsx(y,{id:"chat-default-agent","data-testid":"chat-default-agent",value:t.agent,onChange:o=>n({...t,agent:o.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"chat-default-model",children:"Default model"}),e.jsx(y,{id:"chat-default-model","data-testid":"chat-default-model",value:t.model,placeholder:"Agent default",onChange:o=>n({...t,model:o.target.value})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"chat-model-catalog",children:"Model picker choices"}),e.jsx(K,{id:"chat-model-catalog","data-testid":"chat-model-catalog",value:h,onChange:o=>c(o.target.value),placeholder:`codex: your-model-id
19
+ claude: your-model-id`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"One agent: model-id per line. Use model IDs supported by your installed agent and account."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"chat-system-prompt",children:"Instructions"}),e.jsx(K,{id:"chat-system-prompt","data-testid":"chat-system-prompt",rows:6,value:t.system,onChange:o=>n({...t,system:o.target.value})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Claude appends these to its coding system prompt. Codex and other agents receive them as turn instructions. Workspace rules remain enforced."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"chat-mcp",children:"Tools connection"}),e.jsxs("select",{id:"chat-mcp","data-testid":"chat-mcp",className:"min-h-11 w-full rounded-md border border-control-border bg-background px-3 text-base sm:text-sm",value:t.mcp,onChange:o=>n({...t,mcp:o.target.value}),children:[e.jsx("option",{value:"orc",children:"Connect ORC MCP (Claude and Codex)"}),e.jsx("option",{value:"native",children:"Use the agent’s host configuration"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The ORC connection uses server credentials internally. Host configuration may include other MCP servers; this setting does not disable them. Protected workspaces may also require ORC tools."})]}),e.jsx(ie,{config:t,onChange:n,disabled:g}),e.jsx(w,{"data-testid":"chat-settings-save",disabled:g,onClick:()=>void v(),children:g?"Saving…":"Save chat defaults"})]}),s&&e.jsx("p",{role:"status","data-testid":"chat-settings-feedback",className:"break-words text-sm text-muted-foreground",children:s})]})}const E=m.forwardRef(({className:t,orientation:n="horizontal",decorative:h=!0,...c},s)=>e.jsx(te,{ref:s,decorative:h,orientation:n,className:oe("shrink-0 bg-surface-bright ",n==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...c}));E.displayName=te.displayName;const P=1024*1024;function Q(t){return t===null?"":t>=1024*P?`${(t/1024/P).toFixed(1)} GB`:`${Math.round(t/P)} MB`}function Te(t){return{session_embeddings:t.session_embeddings??!1,parser:t.parser,docling_enabled:t.docling_enabled,parser_timeout_secs:String(t.parser_timeout_secs),max_upload_mb:String(Math.round(t.max_upload_bytes/P)),usage_retention_days:String(t.usage_retention_days),provider:t.embedding.provider,base_url:t.embedding.base_url??"",model:t.embedding.model??"",dimensions:t.embedding.dimensions?String(t.embedding.dimensions):"",api_key:"",clear_key:!1}}const Ae={none:"Keyword search only. Add an embedding provider for semantic and hybrid search.",ollama:"Local embeddings from Ollama, for example nomic-embed-text at http://localhost:11434.",openai:"OpenAI or any OpenAI-compatible endpoint, for example text-embedding-3-small."};function De(){var L,$,H,U;const t=je(),n=ye(),h=Ne(),c=_e(),[s,x]=m.useState(null),[g,b]=m.useState(null),[v,o]=m.useState(!1),[d,f]=m.useState(!1),[u,_]=m.useState(!1);if(m.useEffect(()=>{t.data&&x(Te(t.data))},[t.data]),t.error)return e.jsxs("section",{children:[e.jsx("h2",{className:"mb-1 text-base font-medium",children:"Knowledge"}),e.jsx("p",{role:"alert",className:"text-sm text-error",children:t.error.message})]});if(!s||!t.data)return null;const j=t.data,N=a=>j.env_overrides.includes(`ORC_KNOWLEDGE_${a}`),l=a=>{o(!1),x({...s,...a})},i=(L=n.data)==null?void 0:L.parsers.find(a=>a.id==="docling"),r=($=n.data)==null?void 0:$.docling;async function S(a){f(!0),b(null);try{return await a(),await c(),!0}catch(R){return b(R instanceof Error?R.message:"Request failed"),!1}finally{f(!1)}}async function ae(a){if(a.preventDefault(),!s)return;const R=B=>B.trim()?Number(B):null,ne={session_embeddings:s.session_embeddings,parser:s.parser,docling_enabled:s.docling_enabled,parser_timeout_secs:Number(s.parser_timeout_secs),max_upload_bytes:Number(s.max_upload_mb)*P,usage_retention_days:Number(s.usage_retention_days),embedding:{provider:s.provider,base_url:s.base_url.trim()||null,model:s.model.trim()||null,dimensions:R(s.dimensions),...s.clear_key?{api_key:null}:s.api_key?{api_key:s.api_key}:{}}};await S(()=>k.kb.updateSettings(ne))&&o(!0)}return e.jsxs("section",{"data-testid":"settings-knowledge","aria-labelledby":"settings-knowledge-title",children:[e.jsx("h2",{id:"settings-knowledge-title",className:"mb-1 text-base font-medium text-on-surface",children:"Knowledge"}),e.jsxs("p",{className:"mb-4 text-sm text-muted-foreground",children:["How ORC parses uploads and searches knowledge bases. Saved on the server in"," ",e.jsx("code",{className:"text-primary",children:"~/.orc/config.json"}),"; files live in"," ",e.jsx("code",{className:"break-all text-primary",children:j.root}),"."]}),e.jsx(E,{className:"mb-4 bg-outline-variant"}),j.env_overrides.length>0&&e.jsxs("p",{className:"mb-4 text-sm text-warning","data-testid":"settings-knowledge-env",children:["Set by environment, these win over saved values: ",j.env_overrides.join(", ")]}),e.jsxs("form",{onSubmit:ae,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Parsers"}),(H=n.data)==null?void 0:H.parsers.map(a=>e.jsxs("div",{"data-testid":`settings-parser-${a.id}`,className:"rounded-md border border-outline-variant p-3 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:a.label}),e.jsxs("span",{className:"text-xs text-outline",children:[a.installed?`v${a.version}`:"not installed",a.size_bytes?` · ${Q(a.size_bytes)}${a.installed?"":" download"}`:""]})]}),e.jsx("p",{className:"mt-1 text-outline",children:a.description}),e.jsxs("p",{className:"mt-1 text-xs text-outline",children:["Formats: ",a.capabilities.formats.join(", ")]}),a.detail&&e.jsx("p",{className:"mt-1 text-xs text-outline",children:a.detail}),a.id==="docling"&&e.jsxs("div",{className:"mt-3 space-y-2",children:[(r==null?void 0:r.state)==="installing"&&e.jsxs("div",{role:"status","data-testid":"settings-docling-progress",className:"text-xs text-outline",children:[r.step,e.jsx("pre",{className:"mt-1 max-h-32 overflow-y-auto whitespace-pre-wrap font-mono",children:r.log.slice(-8).join(`
20
+ `)})]}),(r==null?void 0:r.state)==="failed"&&e.jsx("p",{role:"alert",className:"text-xs text-error",children:r.error}),a.installed?e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox","data-testid":"settings-docling-enabled",checked:s.docling_enabled,onChange:R=>l({docling_enabled:R.target.checked})}),"Use automatically for PDFs and images"]}),e.jsxs(w,{type:"button",size:"sm",variant:"ghost",className:"text-error","data-testid":"settings-docling-remove",onClick:()=>_(!0),children:[e.jsx(de,{size:14}),"Remove"]})]}):e.jsxs(w,{type:"button",size:"sm",variant:"outline","data-testid":"settings-docling-install",disabled:d||(r==null?void 0:r.state)==="installing",onClick:()=>S(()=>k.kb.installDocling()),children:[e.jsx(ke,{size:14}),(r==null?void 0:r.state)==="installing"?"Installing…":`Install Docling (${Q((i==null?void 0:i.size_bytes)??null)||"about 2 GB"})`]})]})]},a.id)),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"settings-kb-parser",className:"text-sm text-muted-foreground",children:"Default parser"}),e.jsxs(F,{value:s.parser,onValueChange:a=>l({parser:a}),disabled:N("PARSER"),children:[e.jsx(T,{id:"settings-kb-parser","data-testid":"settings-kb-parser",children:e.jsx(A,{})}),e.jsxs(D,{children:[e.jsx(C,{value:"auto",children:"Automatic: Docling for PDFs and images when enabled"}),(U=n.data)==null?void 0:U.parsers.map(a=>e.jsx(C,{value:a.id,disabled:!a.installed,children:a.label},a.id))]})]}),e.jsx("p",{className:"text-xs text-outline",children:"Knowledge bases can override it. Changing parsers applies to new uploads; reparse a document to apply it to existing ones."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"settings-kb-timeout",className:"text-sm text-muted-foreground",children:"Parse timeout (s)"}),e.jsx(y,{id:"settings-kb-timeout",type:"number",min:10,value:s.parser_timeout_secs,onChange:a=>l({parser_timeout_secs:a.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"settings-kb-max-upload",className:"text-sm text-muted-foreground",children:"Max upload (MB)"}),e.jsx(y,{id:"settings-kb-max-upload",type:"number",min:1,value:s.max_upload_mb,onChange:a=>l({max_upload_mb:a.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"settings-kb-retention",className:"text-sm text-muted-foreground",children:"Read log (days)"}),e.jsx(y,{id:"settings-kb-retention",type:"number",min:1,value:s.usage_retention_days,onChange:a=>l({usage_retention_days:a.target.value})})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Semantic search"}),e.jsxs("label",{className:"flex items-start gap-2 text-sm",children:[e.jsx("input",{type:"checkbox","data-testid":"settings-session-embeddings",checked:s.session_embeddings,onChange:a=>l({session_embeddings:a.target.checked})}),e.jsxs("span",{children:["Search coding sessions with embeddings",e.jsx("span",{className:"block text-xs text-outline",children:"Uses the provider below for session passages. Keyword search and transcript reading remain available when off. Enabling sends session text to this provider and indexes discovered project sessions."})]})]}),h.data&&e.jsxs("p",{className:"text-xs text-outline","data-testid":"settings-embedding-status",children:[h.data.embedding.ready?`Ready · ${h.data.embedding.model} · ${h.data.embedding.vector_backend}`:h.data.embedding.detail??"Not configured",h.data.embedding.pending_chunks?` · ${h.data.embedding.pending_chunks} passages waiting`:""]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"settings-kb-provider",className:"text-sm text-muted-foreground",children:"Embedding provider"}),e.jsxs(F,{value:s.provider,onValueChange:a=>l({provider:a}),disabled:N("EMBEDDING_PROVIDER"),children:[e.jsx(T,{id:"settings-kb-provider","data-testid":"settings-kb-provider",children:e.jsx(A,{})}),e.jsxs(D,{children:[e.jsx(C,{value:"none",children:"None"}),e.jsx(C,{value:"ollama",children:"Ollama"}),e.jsx(C,{value:"openai",children:"OpenAI-compatible"})]})]}),e.jsx("p",{className:"text-xs text-outline",children:Ae[s.provider]})]}),s.provider!=="none"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"settings-kb-model",className:"text-sm text-muted-foreground",children:"Model"}),e.jsx(y,{id:"settings-kb-model","data-testid":"settings-kb-model",value:s.model,disabled:N("EMBEDDING_MODEL"),onChange:a=>l({model:a.target.value}),placeholder:s.provider==="ollama"?"nomic-embed-text":"text-embedding-3-small"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"settings-kb-dimensions",className:"text-sm text-muted-foreground",children:"Dimensions"}),e.jsx(y,{id:"settings-kb-dimensions",type:"number",value:s.dimensions,onChange:a=>l({dimensions:a.target.value}),placeholder:"Model default"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"settings-kb-base-url",className:"text-sm text-muted-foreground",children:"Base URL"}),e.jsx(y,{id:"settings-kb-base-url","data-testid":"settings-kb-base-url",value:s.base_url,disabled:N("EMBEDDING_URL"),onChange:a=>l({base_url:a.target.value}),placeholder:s.provider==="ollama"?"http://localhost:11434":"https://api.openai.com/v1"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"settings-kb-api-key",className:"text-sm text-muted-foreground",children:s.provider==="ollama"?"Token (hosted or proxied Ollama)":"API key"}),e.jsx(y,{id:"settings-kb-api-key",type:"password",autoComplete:"off","data-testid":"settings-kb-api-key",value:s.api_key,disabled:s.clear_key||N("EMBEDDING_API_KEY"),onChange:a=>l({api_key:a.target.value}),placeholder:j.embedding.api_key_set?"Saved. Type to replace":"Not set"}),j.embedding.api_key_set&&e.jsxs("label",{className:"flex items-center gap-2 text-xs text-outline",children:[e.jsx("input",{type:"checkbox","data-testid":"settings-kb-api-key-clear",checked:s.clear_key,onChange:a=>l({clear_key:a.target.checked,api_key:""})}),"Remove the saved key"]}),e.jsxs("p",{className:"text-xs text-outline",children:["Stored encrypted with the key in ",e.jsx("code",{children:"~/.orc/secret.key"})," and never sent back to the browser. Sent as a bearer token to the base URL."]})]}),e.jsx("p",{className:"text-xs text-outline",children:"Changing the model re-embeds every passage in the background; keyword search keeps working meanwhile."})]})]}),g&&e.jsx("p",{role:"alert","data-testid":"settings-knowledge-error",className:"text-sm text-error",children:g}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(w,{type:"submit","data-testid":"settings-knowledge-save",disabled:d,children:"Save knowledge settings"}),v&&e.jsx("span",{role:"status",className:"text-sm text-muted-foreground",children:"Saved"})]})]}),e.jsx(le,{open:u,title:"Remove Docling",description:"Deletes the Docling runtime and models from this machine. Documents it parsed keep their text; reparse them to use the basic parser.",confirmLabel:"Remove",isPending:d,onCancel:()=>_(!1),onConfirm:async()=>{_(!1),await S(()=>k.kb.uninstallDocling())}})]})}function Me(){const t=X();return ce({mutationFn:async()=>{const n=await k.system.restart(),h=Date.now()+6e4;for(;Date.now()<h;){await new Promise(c=>setTimeout(c,500));try{if((await k.health.check(AbortSignal.timeout(2e3))).instance_id!==n.instance_id)return}catch(c){if(c instanceof me&&c.status===401)throw c}}throw new Error("ORC has not reconnected yet. Check the server and try again when it is online.")},onSuccess:()=>t.invalidateQueries()})}function ze(){const{data:t}=he(),n=Me();return e.jsxs("section",{"aria-labelledby":"server-title",children:[e.jsx("h2",{id:"server-title",className:"mb-1 text-base font-medium",children:"ORC server"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Restart ORC to reload server and host information. This closes active terminals and may interrupt running work. Your settings are kept, and this dashboard reconnects automatically. Switching hosts applies to new actions without a restart."}),e.jsx(E,{className:"mb-4"}),e.jsxs(w,{variant:"outline","data-testid":"settings-restart",disabled:!(t!=null&&t.restart_supported)||n.isPending,onClick:()=>n.mutate(),children:[e.jsx(Oe,{className:n.isPending?"mr-2 size-4 animate-spin":"mr-2 size-4"}),n.isPending?"Restarting and reconnecting…":"Restart ORC server"]}),t&&!t.restart_supported&&e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This server does not support restart from the dashboard."}),n.isPending&&e.jsx("p",{role:"status","data-testid":"settings-restart-status",className:"mt-2 text-sm text-muted-foreground",children:"Waiting for ORC to restart…"}),n.isSuccess&&e.jsx("p",{role:"status","data-testid":"settings-restart-status",className:"mt-2 text-sm text-muted-foreground",children:"ORC restarted. Reconnected."}),n.isError&&e.jsx("p",{role:"alert","data-testid":"settings-restart-error",className:"mt-2 text-sm text-error",children:n.error.message})]})}const O="__local__";function J(t){return t?t instanceof Error?t.message:String(t):null}function Le(){var i;const{data:t,error:n,refetch:h}=ue(),{data:c}=xe(),s=ge(),x=pe(),[g,b]=m.useState(O),[v,o]=m.useState("");if(m.useEffect(()=>{t&&(b(t.host??O),o(t.remote_port===null?"":String(t.remote_port)))},[t]),n)return e.jsxs("section",{children:[e.jsx("h2",{className:"mb-3 text-base font-semibold",children:"Execution host"}),e.jsx(fe,{message:n.message,onRetry:()=>void h()})]});if(!t)return e.jsx("p",{role:"status","data-testid":"page-loading",className:"text-sm text-muted-foreground",children:"Loading execution host…"});const d=g===O?null:g,f=t.host&&!t.hosts.includes(t.host)?[t.host,...t.hosts]:t.hosts,u=Number(v),_=v.trim()===""||Number.isInteger(u)&&u>=1&&u<=65535,j=t.locked||!t.supported,N=c==null?void 0:c.backends.find(r=>r.name==="claude"),l=((i=x.data)==null?void 0:i.host)===d?x.data:void 0;return e.jsxs("section",{"data-testid":"ssh-settings",children:[e.jsx("h2",{className:"font-headline font-semibold text-base text-on-surface mb-1",children:"Execution host"}),e.jsxs("p",{className:"font-body text-sm text-muted-foreground mb-4",children:["Run every agent, terminal, git and file action on a host from"," ",e.jsx("code",{className:"text-primary",children:"~/.ssh/config"}),". Agents there reach orc through a reverse tunnel on the remote port. Terminals already open keep their host."]}),e.jsx(E,{className:"bg-surface-highest mb-4"}),e.jsxs("div",{className:"space-y-4",children:[t.locked&&e.jsx("p",{"data-testid":"ssh-locked",className:"font-body text-sm text-tertiary",children:"Fixed by ORC_SSH_HOST in orc's environment."}),!t.supported&&e.jsx("p",{"data-testid":"ssh-unsupported",className:"font-body text-sm text-error",children:t.unsupported_reason}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"ssh-host",className:"font-label text-sm text-muted-foreground",children:"Host"}),e.jsxs(F,{value:g,onValueChange:b,disabled:j,children:[e.jsx(T,{id:"ssh-host","aria-label":"Execution host","data-testid":"ssh-host-picker",className:"bg-surface-highest border-control-border text-on-surface font-body text-sm",children:e.jsx(A,{})}),e.jsxs(D,{className:"bg-surface-highest border-outline-variant max-h-72",children:[e.jsx(C,{value:O,"data-testid":"ssh-host-option-local",className:"font-label text-sm",children:"Local (this machine)"}),f.map(r=>e.jsx(C,{value:r,"data-testid":`ssh-host-option-${r}`,className:"font-label text-sm",children:r},r))]})]}),f.length===0&&e.jsx("p",{"data-testid":"page-empty",className:"font-body text-sm text-muted-foreground",children:"No Host entries found in ~/.ssh/config on the machine running orc."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"ssh-remote-port",className:"font-label text-sm text-muted-foreground",children:"Tunnel port override"}),e.jsx(y,{id:"ssh-remote-port","aria-invalid":!!(d&&!_),"data-testid":"ssh-remote-port",value:v,placeholder:"Automatic",onChange:r=>o(r.target.value),disabled:j||!d,inputMode:"numeric",className:"bg-surface-highest border-outline-variant text-on-surface font-body text-sm"}),d&&!_&&e.jsx("p",{className:"text-sm text-error",children:"Enter a remote port from 1 to 65535."}),e.jsx("p",{className:"font-body text-sm text-muted-foreground",children:"Leave empty to let SSH choose an available port automatically."})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(w,{"data-testid":"ssh-save",disabled:j||d!==null&&!_||s.isPending,onClick:()=>s.mutate({host:d,remotePort:d&&v.trim()?u:null}),className:"font-label text-sm bg-primary text-primary-foreground hover:bg-primary/90",children:[e.jsx(Z,{size:12,className:"mr-1.5"})," Use Host"]}),e.jsxs(w,{"data-testid":"ssh-test",variant:"ghost",disabled:!d||!t.supported||x.isPending,onClick:()=>d&&x.mutate(d),className:"font-label text-sm text-muted-foreground hover:text-on-surface",children:[e.jsx(Pe,{size:12,className:"mr-1.5"})," ",x.isPending?"Testing…":"Test"]})]}),J(s.error??x.error)&&e.jsx("p",{"data-testid":"ssh-error",className:"font-body text-sm text-error",children:J(s.error??x.error)}),l&&e.jsx("div",{"data-testid":"ssh-test-result",className:"font-body text-sm space-y-1",children:l.ok?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-secondary",children:["Connected to ",l.host," (",l.os,", ",l.shell,")"]}),e.jsx("p",{className:"text-muted-foreground",children:Object.entries(l.binaries).map(([r,S])=>`${S?"●":"○"} ${r}`).join(" ")}),l.binaries.claude&&l.claude_logged_in===!1&&e.jsxs("p",{className:l.api_key_forwarded?"text-muted-foreground":"text-error",children:["claude is not logged in on ",l.host,"."," ",l.api_key_forwarded?"ANTHROPIC_API_KEY from orc's environment will be forwarded.":"Set ANTHROPIC_API_KEY in orc's environment or run claude login there."]})]}):e.jsx("p",{className:"text-error",children:l.error})}),t.host&&N&&!N.available&&e.jsxs("p",{"data-testid":"ssh-claude-error",className:"font-body text-sm text-error",children:["claude backend: ",N.error]})]})]})}function Ve(){const{theme:t}=be(),[n,h]=m.useState(G),[c,s]=m.useState(()=>localStorage.getItem(I)??""),[x,g]=m.useState(!1),[b,v]=m.useState(""),[o,d]=m.useState(""),[f,u]=m.useState(!1),_=X(),j=async()=>{d(""),u(!0);try{const i=n.trim();if(i&&!i.startsWith("/")&&!/^https?:\/\//i.test(i))throw new Error("Use a relative API path or an http(s) server URL.");const r=await k.settings.save({theme:t,terminal_font:c.trim()});W(r.theme??t),s(r.terminal_font??""),r.terminal_font?localStorage.setItem(I,r.terminal_font):localStorage.removeItem(I);const S=(i||"/api")!==G();localStorage.setItem("orc_api_url",i||"/api"),S&&window.dispatchEvent(new Event(q)),_.invalidateQueries(),g(!0),v("Workspace preferences saved on the server. API address saved in this browser."),setTimeout(()=>g(!1),2e3)}catch(i){d(i instanceof Error?i.message:"Browser settings could not be saved.")}finally{u(!1)}},N=async()=>{d(""),u(!0);try{const i=await k.settings.save({terminal_font:""});localStorage.removeItem("orc_api_url"),localStorage.setItem(I,i.terminal_font??""),h("/api"),s(i.terminal_font??""),window.dispatchEvent(new Event(q)),_.invalidateQueries(),g(!1),v("Connection and terminal font restored to their defaults. Appearance and execution host were kept.")}catch(i){d(i instanceof Error?i.message:"Browser settings could not be reset.")}finally{u(!1)}};async function l(i){d(""),u(!0);try{const r=await k.settings.save({theme:i});W(r.theme??i)}catch(r){d(r instanceof Error?r.message:"Appearance could not be saved.")}finally{u(!1)}}return e.jsxs("div",{children:[e.jsx(ve,{title:"Settings"}),e.jsxs("div",{className:"max-w-lg space-y-8",children:[e.jsxs("section",{"aria-labelledby":"appearance-title",children:[e.jsx("h2",{id:"appearance-title",className:"mb-1 text-base font-medium",children:"Appearance"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Choose a workspace theme. Your choice is saved on the server immediately."}),e.jsx("fieldset",{className:"flex flex-wrap gap-2","aria-label":"Theme",children:["dark","light"].map(i=>e.jsx(w,{variant:t===i?"secondary":"outline","aria-pressed":t===i,"data-testid":`settings-theme-${i}`,disabled:f,onClick:()=>void l(i),children:i==="dark"?"Dark":"Light"},i))})]}),e.jsxs("section",{children:[e.jsx("h2",{className:"font-headline font-medium text-base text-on-surface mb-1",children:"API connection"}),e.jsxs("p",{className:"font-body text-sm text-muted-foreground mb-4",children:["Connect this workspace to an ORC server. The default"," ",e.jsx("code",{className:"text-primary",children:"/api"})," uses the current server or the configured development proxy."]}),e.jsx(E,{className:"bg-outline-variant mb-4"}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"settings-api-url",className:"font-label text-sm text-muted-foreground",children:"API base URL"}),e.jsx(y,{id:"settings-api-url","data-testid":"settings-api-url",value:n,onChange:i=>h(i.target.value),placeholder:"/api or http://localhost:7700",className:"bg-background text-on-surface font-body text-sm"}),e.jsxs("p",{className:"font-body text-sm text-muted-foreground",children:["Use ",e.jsx("code",{children:"/api"})," (dev proxy) or a direct URL when CORS is enabled."]})]})})]}),e.jsx(Le,{}),e.jsx(ze,{}),e.jsx(Fe,{}),e.jsx(De,{}),e.jsxs("section",{children:[e.jsx("h2",{className:"font-headline font-medium text-base text-on-surface mb-1",children:"Terminal"}),e.jsx("p",{className:"font-body text-sm text-muted-foreground mb-4",children:"Prompt and agent status icons need a Nerd Font installed on this machine. Common ones are tried automatically; set the exact family name if your icons show as empty boxes. Applies to terminals opened after saving."}),e.jsx(E,{className:"bg-outline-variant mb-4"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"settings-terminal-font",className:"font-label text-sm text-muted-foreground",children:"Terminal font family"}),e.jsx(y,{id:"settings-terminal-font",value:c,onChange:i=>s(i.target.value),placeholder:"e.g. MesloLGS NF",className:"bg-background text-on-surface font-body text-sm"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 pt-2",children:[e.jsx(w,{"data-testid":"settings-save",disabled:f,onClick:()=>void j(),className:"font-label text-sm ",children:x?e.jsxs(e.Fragment,{children:[e.jsx(Ee,{size:12,className:"mr-1.5"})," Saved"]}):e.jsxs(e.Fragment,{children:[e.jsx(Z,{size:12,className:"mr-1.5"})," Save settings"]})}),e.jsx(w,{variant:"ghost",disabled:f,onClick:()=>void N(),className:"font-label text-sm text-muted-foreground hover:text-on-surface",children:"Reset to defaults"})]}),o&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:o}),b&&!o&&e.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:b}),e.jsxs("section",{children:[e.jsx(E,{className:"bg-outline-variant mb-4"}),e.jsx("div",{className:"font-label text-sm text-muted-foreground mb-2",children:"Storage"}),e.jsxs("p",{className:"font-body text-sm text-muted-foreground",children:["Workspace preferences and SSH selection are persisted in the server's"," ",e.jsx("code",{children:"~/.orc/config.json"}),". The API address and optionally remembered login are stored in this browser."]})]})]})]})}export{Ve as default};
@@ -0,0 +1,16 @@
1
+ var Ae=a=>{throw TypeError(a)};var ve=(a,t,i)=>t.has(a)||Ae("Cannot "+i);var j=(a,t,i)=>(ve(a,t,"read from private field"),i?i.call(a):t.get(a)),D=(a,t,i)=>t.has(a)?Ae("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(a):t.set(a,i),I=(a,t,i,r)=>(ve(a,t,"write to private field"),r?r.call(a,i):t.set(a,i),i),Q=(a,t,i)=>(ve(a,t,"access private method"),i);import{cb as rt,cc as ke,cd as nt,ce as lt,cf as Ye,a as A,cg as ot,ch as ct,r as N,ci as dt,cj as ut,ck as mt,cl as ht,cm as He,cn as xt,co as pt,c as Le,j as e,cp as ft,u as Z,b as $,d as L,aa as me,X as he,Y as xe,Z as pe,B as C,at as fe,ak as Je,_ as de,$ as Y,am as Xe,a1 as ue,a2 as gt,E as Ze,V as yt,al as bt,aD as jt,S as We,ah as vt,t as kt,v as St,w as $e,x as G,aE as Nt,cq as wt,y as Ct,z as V,e as Rt,a4 as Lt,a5 as It,a6 as Ot,a7 as Et,a8 as _t,ae as Te,l as et,M as qt}from"./index-hiTCEgOL.js";import{D as Pt,c as ze}from"./DocumentWorkspace-OemhbAq7.js";import{u as Kt}from"./useProjectScope-NWbe41dR.js";import{r as Dt}from"./primitive-files-BwTyowra.js";import{D as Be}from"./download-CkO5a0rx.js";function Me(a,t){const i=new Set(t);return a.filter(r=>!i.has(r))}function Qt(a,t,i){const r=a.slice(0);return r[t]=i,r}var J,_,X,B,P,H,se,ae,ie,re,R,Se,Ne,tt,we,Ce,Re,Ve,Ft=(Ve=class extends rt{constructor(t,i,r){super();D(this,R);D(this,J);D(this,_);D(this,X);D(this,B);D(this,P);D(this,H);D(this,se);D(this,ae);D(this,ie);D(this,re,[]);I(this,J,t),I(this,B,r),I(this,X,[]),I(this,P,[]),I(this,_,[]),this.setQueries(i)}onSubscribe(){this.listeners.size===1&&j(this,P).forEach(t=>{t.subscribe(i=>{Q(this,R,Ce).call(this,t,i)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,j(this,P).forEach(t=>{t.destroy()})}setQueries(t,i){I(this,X,t),I(this,B,i),ke.batch(()=>{const r=j(this,P),o=Q(this,R,we).call(this,j(this,X));o.forEach(y=>y.observer.setOptions(y.defaultedQueryOptions));const n=o.map(y=>y.observer),s=n.map(y=>y.getCurrentResult()),u=r.length!==n.length,d=n.some((y,p)=>y!==r[p]),h=u||d,g=h?!0:s.some((y,p)=>{const w=j(this,_)[p];return!w||!nt(y,w)});!h&&!g||(h&&(I(this,re,o),I(this,P,n)),I(this,_,s),this.hasListeners()&&(h&&(Me(r,n).forEach(y=>{y.destroy()}),Me(n,r).forEach(y=>{y.subscribe(p=>{Q(this,R,Ce).call(this,y,p)})})),Q(this,R,Re).call(this)))})}getCurrentResult(){return j(this,_)}getQueries(){return j(this,P).map(t=>t.getCurrentQuery())}getObservers(){return j(this,P)}getOptimisticResult(t,i){const r=Q(this,R,we).call(this,t),o=r.map(s=>s.observer.getOptimisticResult(s.defaultedQueryOptions)),n=r.map(s=>s.defaultedQueryOptions.queryHash);return[o,s=>Q(this,R,Ne).call(this,s??o,i,n),()=>Q(this,R,Se).call(this,o,r)]}},J=new WeakMap,_=new WeakMap,X=new WeakMap,B=new WeakMap,P=new WeakMap,H=new WeakMap,se=new WeakMap,ae=new WeakMap,ie=new WeakMap,re=new WeakMap,R=new WeakSet,Se=function(t,i){return i.map((r,o)=>{const n=t[o];return r.defaultedQueryOptions.notifyOnChangeProps?n:r.observer.trackResult(n,s=>{i.forEach(u=>{u.observer.trackProp(s)})})})},Ne=function(t,i,r){if(i){const o=j(this,ie),n=r!==void 0&&o!==void 0&&(o.length!==r.length||r.some((s,u)=>s!==o[u]));return(!j(this,H)||j(this,_)!==j(this,ae)||n||i!==j(this,se))&&(I(this,se,i),I(this,ae,j(this,_)),r!==void 0&&I(this,ie,r),I(this,H,lt(j(this,H),i(t)))),j(this,H)}return t},tt=function(){var t;return((t=j(this,B))==null?void 0:t.combine)!==void 0&&j(this,P).some((i,r)=>{var o;return i.options.suspense&&((o=j(this,_)[r])==null?void 0:o.data)===void 0})},we=function(t){const i=new Map;j(this,P).forEach(o=>{const n=o.options.queryHash;if(!n)return;const s=i.get(n);s?s.push(o):i.set(n,[o])});const r=[];return t.forEach(o=>{var d;const n=j(this,J).defaultQueryOptions(o),u=((d=i.get(n.queryHash))==null?void 0:d.shift())??new Ye(j(this,J),n);r.push({defaultedQueryOptions:n,observer:u})}),r},Ce=function(t,i){const r=j(this,P).indexOf(t);r!==-1&&(I(this,_,Qt(j(this,_),r,i)),Q(this,R,Re).call(this))},Re=function(){var t;if(this.hasListeners()){const i=Q(this,R,Se).call(this,j(this,_),j(this,re)),r=Q(this,R,tt).call(this),o=j(this,H),n=r?o:Q(this,R,Ne).call(this,i,(t=j(this,B))==null?void 0:t.combine);(r||o!==n)&&ke.batch(()=>{this.listeners.forEach(s=>{s(j(this,_))})})}},Ve);function At({queries:a,...t},i){const r=A(i),o=ot(),n=ct(),s=N.useMemo(()=>a.map(c=>{const m=r.defaultQueryOptions(c);return m._optimisticResults=o?"isRestoring":"optimistic",m}),[a,r,o]);s.forEach(c=>{dt(c);const m=r.getQueryCache().get(c.queryHash);ut(c,n,m)}),mt(n);const[u]=N.useState(()=>new Ft(r,s,t)),[d,h,g]=u.getOptimisticResult(s,t.combine),y=!o&&t.subscribed!==!1;N.useSyncExternalStore(N.useCallback(c=>y?u.subscribe(ke.batchCalls(c)):ht,[u,y]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),N.useEffect(()=>{u.setQueries(s,t)},[s,t,u]);const w=d.some((c,m)=>He(s[m],c))?d.flatMap((c,m)=>{const v=s[m];if(v&&He(v,c)){const x=new Ye(r,v);return xt(v,x,n)}return[]}):[];if(w.length>0)throw Promise.all(w);const f=d.find((c,m)=>{const v=s[m];return v&&pt({result:c,errorResetBoundary:n,throwOnError:v.throwOnError,query:r.getQueryCache().get(v.queryHash),suspense:v.suspense})});if(f!=null&&f.error)throw f.error;return h(g())}/**
2
+ * @license lucide-react v1.27.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Ht=[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]],$t=Le("arrow-up-down",Ht);/**
7
+ * @license lucide-react v1.27.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Tt=[["circle",{cx:"9",cy:"12",r:"3",key:"u3jwor"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]],zt=Le("toggle-left",Tt);/**
12
+ * @license lucide-react v1.27.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const Bt=[["circle",{cx:"15",cy:"12",r:"3",key:"1afu0r"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]],Mt=Le("toggle-right",Bt);function Ut({files:a,selected:t,onSelect:i,testId:r="document-file-tab",entryTestId:o}){return e.jsxs("nav",{"aria-label":"Document files",className:"min-w-0 space-y-2","data-testid":"document-tabs",children:[e.jsx("div",{role:"tablist","aria-label":"Open a file",className:"flex max-w-full gap-1 overflow-x-auto overscroll-x-contain rounded-md border border-surface-highest p-1",children:a.map((n,s)=>e.jsxs("button",{type:"button",role:"tab","aria-selected":n===t,"data-testid":s===0&&o?o:r,"data-file-name":n,title:n,tabIndex:n===t?0:-1,onKeyDown:u=>{var y,p;if(!["ArrowRight","ArrowLeft","Home","End"].includes(u.key))return;u.preventDefault();let h=s;if(u.key==="ArrowRight"&&(h=(s+1)%a.length),u.key==="ArrowLeft"&&(h=(s+a.length-1)%a.length),u.key==="Home"&&(h=0),u.key==="End"&&(h=a.length-1),i(a[h])===!1)return;const g=(y=u.currentTarget.parentElement)==null?void 0:y.querySelectorAll('[role="tab"]');(p=g==null?void 0:g[h])==null||p.focus()},onClick:()=>i(n),className:`flex min-h-11 shrink-0 items-center gap-2 rounded px-3 text-sm ${n===t?"bg-surface-highest text-on-surface":"text-muted-foreground hover:bg-surface-low hover:text-on-surface"}`,children:[e.jsx(ft,{size:14,"aria-hidden":"true"}),e.jsx("span",{className:"max-w-[180px] truncate",children:n.split("/").pop()})]},n))}),e.jsxs("label",{className:"flex min-w-0 items-center gap-2 text-sm text-outline sm:hidden",children:["File",e.jsx("select",{"aria-label":"Choose document file","data-testid":"document-file-picker",value:t,onChange:n=>i(n.target.value),className:"min-h-11 min-w-0 flex-1 rounded border border-control-border bg-surface px-2 text-on-surface",children:a.map(n=>e.jsx("option",{value:n,children:n},n))})]})]})}const Ue={new:"",installed:"Already in ORC",conflict:"Name taken in ORC (different content)",changed:"Changed since import",invalid:"Invalid"},te=a=>`${a.agent}/${a.name}`;function Gt({onClose:a}){var y,p,w;const[t,i]=N.useState([]),r=A(),o=Z({queryKey:["skills","local-agents"],queryFn:L.skills.localAgents}),n=$({mutationFn:L.skills.importLocal,onSuccess:async f=>{i([]),await r.invalidateQueries({queryKey:["skills"]}),f.skipped.length||a()}}),s=n.isPending,u=((y=o.data)==null?void 0:y.agents)??[],d=new Set(t.map(f=>f.split("/")[1])),h=(f,c)=>i(c?[...t,te(f)]:t.filter(m=>m!==te(f))),g=f=>{const c=[...t],m=new Set(d);for(const v of f)v.status!=="new"||m.has(v.name)||(c.push(te(v)),m.add(v.name));i(c)};return e.jsx(me,{open:!0,onOpenChange:f=>!f&&!s&&a(),children:e.jsxs(he,{className:"max-w-xl",children:[e.jsx(xe,{children:e.jsx(pe,{children:"Import from local agents"})}),e.jsx("p",{className:"text-xs text-outline",children:"Copies skills from agent folders such as ~/.claude/skills and ~/.codex/skills into ORC. The originals are not changed."}),o.isLoading&&e.jsx("p",{role:"status",children:"Scanning agent folders…"}),o.data&&!u.length&&e.jsx("p",{role:"status",children:"No local agent skill folders found."}),e.jsx("div",{className:"max-h-[55vh] overflow-y-auto space-y-4",children:u.map(f=>{const c=f.skills.filter(m=>m.status==="new");return e.jsxs("section",{"data-testid":"local-agent","data-agent":f.id,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:f.label}),e.jsx("p",{className:"text-xs text-outline",children:f.dir})]}),e.jsxs(C,{size:"sm",variant:"outline","data-testid":"local-agent-select-all",disabled:s||!c.length,onClick:()=>g(f.skills),children:["Select all new (",c.length,")"]})]}),e.jsx("div",{className:"space-y-2",children:f.skills.map(m=>{const v=t.includes(te(m)),x=!v&&d.has(m.name);return e.jsxs("label",{className:"flex items-start gap-3 border border-surface-highest rounded p-3","data-testid":"local-skill","data-skill-name":m.name,children:[e.jsx("input",{type:"checkbox","data-testid":"local-skill-select",checked:v,disabled:s||m.status!=="new"||x,onChange:b=>h(m,b.target.checked)}),e.jsxs("span",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:m.name}),Ue[m.status]&&e.jsx("span",{className:"ml-2 text-xs text-outline",children:Ue[m.status]}),e.jsx("span",{className:"block text-xs text-outline",children:m.error??m.description}),m.extra_fields.length>0&&e.jsxs("span",{className:"block text-xs text-outline","data-testid":"local-skill-extra-fields",children:["Extra fields: ",m.extra_fields.join(", ")]}),m.also_in.length>0&&e.jsxs("span",{className:"block text-xs text-outline",children:["Also in ",m.also_in.join(", ")]})]})]},te(m))})})]},f.id)})}),(p=n.data)==null?void 0:p.skipped.map(f=>e.jsxs("p",{role:"alert",className:"text-xs text-destructive",children:["Skipped ",f.name,": ",f.reason]},`${f.agent}/${f.name}`)),(o.error||n.error)&&e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:(w=o.error||n.error)==null?void 0:w.message}),e.jsxs(fe,{children:[e.jsx(C,{variant:"ghost",disabled:s,onClick:a,children:"Close"}),e.jsx(C,{"data-testid":"local-skill-import-submit",disabled:s||!t.length,onClick:()=>n.mutate(t.map(f=>{const[c="",m=""]=f.split("/");return{agent:c,name:m}})),children:n.isPending?"Importing…":`Import selected${t.length?` (${t.length})`:""}`})]})]})})}function Vt({onClose:a}){var y,p,w,f;const[t,i]=N.useState(""),[r,o]=N.useState([]),n=A(),s=$({mutationFn:L.skills.discover,onSuccess:()=>{u.clear(),o([])}}),u=Je((((y=s.data)==null?void 0:y.skills)??[]).filter(c=>!c.installed&&!r.includes(c.path)).map(c=>c.path),`${t}:${((p=s.data)==null?void 0:p.commit)??""}`),d=u.selectedIds,h=$({mutationFn:async()=>{if(!s.data)throw new Error("Discover skills first");const c=[],m=[];for(let v=0;v<d.length;v+=16){const x=d.slice(v,v+16);try{await L.skills.import({source:t.trim(),commit:s.data.commit,paths:x}),m.push(...x)}catch(b){c.push(...x.map(k=>({path:k,error:b instanceof Error?b.message:"Import failed"})))}}return{imported:m,failed:c}},onSuccess:async c=>{await n.invalidateQueries({queryKey:["skills"]}),o(m=>[...m,...c.imported]),u.select(c.failed.map(m=>m.path)),c.failed.length||a()}}),g=s.isPending||h.isPending;return e.jsx(me,{open:!0,onOpenChange:c=>!c&&!g&&a(),children:e.jsxs(he,{className:"max-w-xl",children:[e.jsx(xe,{children:e.jsx(pe,{children:"Import from GitHub"})}),e.jsxs("form",{className:"space-y-4",onSubmit:c=>{c.preventDefault(),s.mutate(t.trim())},children:[e.jsx(de,{htmlFor:"skill-repository",children:"Repository or skills.sh link"}),e.jsx(Y,{id:"skill-repository","data-testid":"skill-repository-input",value:t,disabled:g,onChange:c=>{i(c.target.value),s.reset(),h.reset(),u.clear(),o([])},placeholder:"https://github.com/vercel-labs/agent-skills",autoFocus:!0}),e.jsx("p",{className:"text-xs text-outline",children:"GitHub repositories, owner/repo, skill-folder URLs and skills.sh links. Private repositories use gh login on the execution host (local or SSH), or ORC_GITHUB_TOKEN on the ORC server. Supporting files are included."}),e.jsx(C,{type:"submit","data-testid":"skill-discover",disabled:g||!t.trim(),children:s.isPending?"Discovering…":"Discover skills"})]}),s.data&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-xs text-outline",children:[s.data.skills.length," skills found · ",s.data.commit.slice(0,8)]}),!s.data.skills.length&&e.jsx("p",{role:"status",children:"No valid skills found in this source."}),e.jsx(Xe,{resourceLabel:"new skills",count:d.length,allSelected:u.allSelected,someSelected:u.someSelected,onSelectAll:u.selectAll,onClear:u.clear,disabled:g,children:e.jsx("span",{className:"text-xs text-muted-foreground",children:"Imports run in batches of up to 16."})}),e.jsx("div",{className:"max-h-[45vh] overflow-y-auto space-y-2",children:s.data.skills.map(c=>e.jsxs("label",{className:"flex items-start gap-3 border border-surface-highest rounded p-3","data-testid":"remote-skill","data-skill-name":c.name,children:[e.jsx("input",{type:"checkbox","data-testid":"remote-skill-select",checked:d.includes(c.path),disabled:g||c.installed||r.includes(c.path),onChange:()=>u.toggle(c.path)}),e.jsxs("span",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:c.name}),(c.installed||r.includes(c.path))&&e.jsx("span",{className:"ml-2 text-xs text-outline",children:"Already installed"}),e.jsx("span",{className:"block text-xs text-outline",children:c.description}),e.jsx("span",{className:"block text-xs text-outline",children:c.path||"Repository root"})]})]},c.path))}),s.data.issues.map(c=>e.jsxs("p",{role:"alert",className:"text-xs text-destructive",children:[c.path,": ",c.error]},c.path))]}),(s.error||h.error)&&e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:(w=s.error||h.error)==null?void 0:w.message}),!!((f=h.data)!=null&&f.failed.length)&&e.jsxs("div",{role:"alert",className:"text-sm text-destructive",children:[e.jsxs("p",{children:[h.data.imported.length," imported; ",h.data.failed.length," failed. Failed selections retained for retry."]}),h.data.failed.map(c=>e.jsxs("p",{children:[c.path||"Repository root",": ",c.error]},c.path))]}),e.jsxs(fe,{children:[e.jsx(C,{variant:"ghost",disabled:g,onClick:a,children:"Cancel"}),e.jsx(C,{"data-testid":"skill-import-submit",disabled:g||!s.data||!d.length,onClick:()=>h.mutate(),children:h.isPending?"Importing…":`Import selected${d.length?` (${d.length})`:""}`})]})]})})}function Yt({name:a,scope:t,mutation:i}){var d,h;const r=A(),[o,n]=N.useState(""),s=Z({queryKey:["skill-history",a,t],queryFn:()=>L.skills.history(a,t)}),u=$({mutationFn:g=>{if(!i)throw new Error("No active instruction edit");return L.skills.revert(a,{project_id:i.project_id,change_id:g,expected_change_id:i.id,reason:o.trim()})},onSuccess:()=>{r.invalidateQueries({queryKey:["skill"]}),r.invalidateQueries({queryKey:["skills"]}),r.invalidateQueries({queryKey:["skill-history"]}),n("")}});return!((d=s.data)!=null&&d.changes.length)&&!s.error?null:e.jsxs("section",{"data-testid":"skill-history-panel",className:"mb-5 space-y-3",children:[i&&e.jsxs("p",{"data-testid":"skill-mutated-label",className:"text-xs text-primary",children:["Mutated · ",i.project_id?"Project":"Global"," ·"," ",new Date(i.updated_at*1e3).toLocaleString()," · ",i.author]}),e.jsx("h3",{className:"text-sm font-medium",children:"Instruction history"}),e.jsx(Y,{"data-testid":"skill-revert-reason","aria-label":"Reason for reverting instructions",value:o,onChange:g=>n(g.target.value),placeholder:"Reason for reverting..."}),s.error&&e.jsx("p",{role:"alert",children:s.error.message}),u.error&&e.jsx("p",{role:"alert",children:u.error.message}),(h=s.data)==null?void 0:h.changes.map(g=>e.jsxs("details",{"data-testid":"skill-history-change",className:"border-b border-outline-variant p-3",children:[e.jsxs("summary",{className:"text-xs cursor-pointer",children:[g.action," · ",g.reason," · ",g.author]}),e.jsx("p",{className:"text-xs text-outline mt-2",children:"Before"}),e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:g.previous_raw}),e.jsx("p",{className:"text-xs text-outline mt-2",children:"After"}),e.jsx("pre",{className:"text-xs whitespace-pre-wrap break-all",children:g.raw}),e.jsx(C,{"data-testid":"skill-revert-change",size:"sm",variant:"outline",disabled:!o.trim()||u.isPending,onClick:()=>u.mutate(g.id),children:"Restore instructions before this change"})]},g.id))]})}function Jt({name:a}){const t=A(),[i,r]=N.useState(!1),o=Z({queryKey:["skill-origin",a],queryFn:()=>L.skills.origin(a)}),n=$({mutationFn:d=>L.skills.sync(a,d),onSuccess:async d=>{r(!1),d.applied&&await Promise.all([t.invalidateQueries({queryKey:["skill",a]}),t.invalidateQueries({queryKey:["skills"]}),t.invalidateQueries({queryKey:["skill-origin",a]})])}});if(o.error)return e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:o.error.message});if(!o.data)return null;const s=n.data,u=s&&!s.applied&&s.conflicts.length>0;return e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs("p",{className:"text-xs text-outline",children:["Imported from"," ",e.jsx("a",{className:"text-primary underline",href:`https://github.com/${o.data.repository}/tree/${encodeURIComponent(o.data.ref==="HEAD"?o.data.commit:o.data.ref)}/${o.data.path}`,target:"_blank",rel:"noreferrer",children:o.data.repository})," ","· ",o.data.commit.slice(0,8)]}),e.jsx(C,{"data-testid":"skill-sync",variant:"outline",size:"sm",disabled:n.isPending,onClick:()=>n.mutate({}),children:n.isPending?"Syncing…":"Sync from GitHub"}),(s==null?void 0:s.applied)&&e.jsx("p",{role:"status","data-testid":"skill-sync-status",className:"text-xs",children:s.changed.length?`Synced ${s.changed.length} files. Local edits preserved outside confirmed conflicts.`:"Up to date. Local edits preserved."}),u&&e.jsxs("div",{"data-testid":"skill-sync-conflicts",className:"space-y-2",children:[e.jsx("p",{role:"alert",className:"text-sm",children:"Sync paused. Both you and GitHub changed these files:"}),e.jsx("ul",{className:"text-xs space-y-1",children:s.conflicts.map(d=>e.jsx("li",{children:d},d))}),e.jsx(C,{"data-testid":"skill-sync-review-override",variant:"outline",size:"sm",onClick:()=>r(!0),children:"Review override"})]}),n.error&&e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:n.error.message}),e.jsx(me,{open:i,onOpenChange:d=>!n.isPending&&r(d),children:e.jsxs(he,{children:[e.jsx(xe,{children:e.jsx(pe,{children:"Replace conflicting local edits?"})}),e.jsxs("p",{className:"text-sm",children:["GitHub's version at ",s==null?void 0:s.commit.slice(0,8)," will replace or remove these files. Your other local edits will be kept. The current skill folder will be backed up."]}),e.jsx("ul",{className:"text-sm space-y-1",children:s==null?void 0:s.conflicts.map(d=>e.jsx("li",{children:d},d))}),e.jsxs(fe,{children:[e.jsx(C,{variant:"ghost",disabled:n.isPending,onClick:()=>r(!1),children:"Keep local edits"}),e.jsx(C,{"data-testid":"skill-sync-confirm-override",disabled:n.isPending,onClick:()=>s&&n.mutate({override:!0,expectedCommit:s.commit,expectedRevision:s.revision}),children:n.isPending?"Syncing…":"Replace listed files"})]})]})})]})}function Xt(a){return Z({queryKey:["skills",a],queryFn:()=>L.skills.list(a)})}function Zt(){return Z({queryKey:["skill-visibility"],queryFn:()=>L.skills.visibility()})}function Wt(){const a=A();return $({mutationFn:t=>L.skills.setVisibility(t),onSuccess:t=>{a.setQueryData(["skill-visibility"],t),a.invalidateQueries({queryKey:["skills"]})}})}function Ge(a,t,i={}){return Z({queryKey:["skill",a,t,i],queryFn:()=>L.skills.get(a,t,i),enabled:!!a})}function es(){const a=A();return $({mutationFn:t=>L.skills.create(t),onSuccess:()=>a.invalidateQueries({queryKey:["skills"]})})}const ts={default:"none",asc:"ascending",desc:"descending"},ss={default:$t,asc:wt,desc:Nt},as=[{value:"all",label:"All"},{value:"builtin",label:"Built-in"},{value:"user",label:"User"}],st={builtin:"text-muted-foreground",user:"text-muted-foreground"};function ms({projectId:a}){var Pe,Ke,De,Qe,Fe;const t=Kt(a),i=t==="all"||t==="unassigned"?{scope:"global"}:{project_id:t},[r,o]=ue("skillQuery",""),[n,s]=N.useState(r),[u,d]=ue("source","all",["all","builtin","user"]),[h,g]=ue("skillRepositorySort","default",["default","asc","desc"]),y=ss[h];N.useEffect(()=>s(r),[r]);const{selectedId:p,openDetail:w,closeDetail:f}=gt("/skills","skillName"),[c,m]=N.useState(!1),[v,x]=N.useState(!1),[b,k]=N.useState(!1),O=Zt(),ne=Wt(),le=JSON.stringify([t,r,u]),[Ie,Oe]=N.useState({scope:le,offset:0}),T=Ie.scope===le?Ie.offset:0,{data:q,isLoading:ge,error:Ee,refetch:at}=Xt({...i,q:r||void 0,source:u==="all"?void 0:u,include_hidden:!0,limit:30,offset:T}),oe=q==null?void 0:q.skills,ye=A(),be=(oe??[]).filter(l=>l.source==="user"),W=At({queries:be.map(l=>({queryKey:["skill-origin",l.name],queryFn:()=>L.skills.origin(l.name)}))}),je=be.filter((l,S)=>{var E;return!!((E=W[S])!=null&&E.data)}).map(l=>l.name),M=new Map(be.map((l,S)=>{var E,K;return[l.name,(K=(E=W[S])==null?void 0:E.data)==null?void 0:K.repository]})),_e=[...oe??[]];!r&&h!=="default"&&_e.sort((l,S)=>{const E=M.get(l.name),K=M.get(S.name);if(!E&&K)return 1;if(E&&!K)return-1;const U=(E??"").localeCompare(K??"",void 0,{sensitivity:"base"});return U?h==="asc"?U:-U:l.name.localeCompare(S.name)});const ee=JSON.stringify([t,r,u,T]),qe=N.useRef(ee);qe.current=ee;const F=Je(je,ee),z=$({mutationFn:async({names:l,scope:S})=>({...await Rt(l,async E=>{const K=await L.skills.sync(E);if(!K.applied)throw new Error(`Conflicts: ${K.conflicts.join(", ")}. Open this skill to review.`)}),scope:S}),onSuccess:async()=>{await Promise.all([ye.invalidateQueries({queryKey:["skills"]}),ye.invalidateQueries({queryKey:["skill"]}),ye.invalidateQueries({queryKey:["skill-origin"]})])}}),ce=((Pe=z.data)==null?void 0:Pe.scope)===ee?z.data:void 0;async function it(){const l=await z.mutateAsync({names:F.selectedIds,scope:ee});l.scope===qe.current&&F.select(l.failed.map(S=>S.id))}return Ee?e.jsx(Ze,{message:Ee.message,onRetry:()=>at()}):e.jsxs("div",{children:[e.jsx(yt,{title:"Skills",meta:`${(oe??[]).length} skills`,action:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(C,{"data-testid":"import-skill-button",size:"sm",variant:"outline",onClick:()=>x(!0),children:[e.jsx(Be,{size:12,className:"mr-1"})," Import from GitHub"]}),e.jsxs(C,{"data-testid":"import-local-skills-button",size:"sm",variant:"outline",onClick:()=>k(!0),children:[e.jsx(Be,{size:12,className:"mr-1"})," Import from agents"]}),e.jsxs(C,{"data-testid":"new-skill-button",size:"sm",onClick:()=>m(!0),className:"font-label text-sm ",children:[e.jsx(bt,{size:12,className:"mr-1"})," New skill"]})]})}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-3",children:["Skill folders follow the"," ",e.jsx("a",{className:"text-primary underline",href:"https://agentskills.io/specification",target:"_blank",rel:"noreferrer",children:"Agent Skills specification"}),"."]}),e.jsx("p",{className:"mb-4 text-sm leading-relaxed text-muted-foreground",children:"Visibility applies to agent discovery across this installation. Hidden skills remain readable by name and available to flows. Modified means the skill instructions were edited."}),(O.error||ne.error)&&e.jsx("p",{role:"alert",className:"text-destructive text-xs mb-2",children:(Ke=O.error||ne.error)==null?void 0:Ke.message}),(De=q==null?void 0:q.broken)==null?void 0:De.map(l=>e.jsxs("p",{role:"alert",className:"text-destructive text-xs mb-2",children:[l.path,": ",l.error]},l.path)),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-4",children:[e.jsx("div",{className:"flex shrink-0 flex-wrap gap-1.5",children:as.map(l=>e.jsx("button",{type:"button",onClick:()=>d(l.value),"data-testid":`skill-source-${l.value}`,"aria-pressed":u===l.value,className:`font-label text-sm px-3 py-1.5 border transition-colors ${u===l.value?"bg-surface-highest text-on-surface border-transparent":"bg-transparent border-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface"}`,children:l.label},l.value))}),e.jsxs("div",{className:"relative min-w-[160px] flex-1",children:[e.jsx(jt,{size:12,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(Y,{"data-testid":"skill-search-input","aria-label":"Search skills",value:n,onChange:l=>s(l.target.value),onKeyDown:l=>l.key==="Enter"&&o(l.currentTarget.value),placeholder:"Search skills...",className:"pl-8 bg-background text-on-surface font-body text-sm placeholder:text-muted-foreground"})]}),e.jsx(C,{"data-testid":"skill-search-submit",variant:"outline",size:"sm",onClick:()=>o(n),className:"font-label text-sm ",children:"Search"})]}),!!je.length&&e.jsxs(Xe,{resourceLabel:"GitHub skills",count:F.selectedIds.length,allSelected:F.allSelected,someSelected:F.someSelected,onSelectAll:F.selectAll,onClear:F.clear,disabled:z.isPending||W.some(l=>l.isPending),children:[e.jsx(C,{"data-testid":"skills-bulk-sync",variant:"outline",size:"sm",disabled:z.isPending,onClick:()=>void it(),children:z.isPending?"Syncing…":"Sync selected from GitHub"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Local edits are preserved; conflicts require review."})]}),W.some(l=>l.error)&&e.jsxs("p",{role:"alert",className:"text-sm text-destructive",children:["Could not check GitHub origins: ",(Fe=(Qe=W.find(l=>l.error))==null?void 0:Qe.error)==null?void 0:Fe.message]}),ce&&e.jsxs("div",{"data-testid":"skills-bulk-result",role:"status",className:"mb-3 text-sm",children:[e.jsxs("p",{children:[ce.succeeded.length," synced; ",ce.failed.length," need attention."]}),ce.failed.map(l=>e.jsxs("button",{type:"button",className:"block text-left text-destructive underline",onClick:()=>w(l.id),children:[l.id,": ",l.error]},l.id))]}),ge?e.jsx("div",{className:"space-y-2",children:[...Array(5)].map((l,S)=>e.jsx(We,{className:"h-10 w-full bg-surface-highest"},S))}):(oe??[]).length===0?e.jsx(vt,{message:r?"No skills match your search":"No skills found"}):e.jsx("div",{className:"overflow-hidden",children:e.jsxs(kt,{children:[e.jsx(St,{children:e.jsxs($e,{className:"border-b border-outline-variant hover:bg-transparent",children:[e.jsx(G,{className:"w-12",children:e.jsx("span",{className:"sr-only",children:"Select GitHub skills"})}),e.jsx(G,{className:"font-label text-sm text-muted-foreground",children:"Name"}),e.jsx(G,{className:"font-label text-sm text-muted-foreground",children:"Description"}),e.jsx(G,{className:"font-label text-sm text-muted-foreground w-24",children:"Source"}),e.jsx(G,{"data-testid":"skill-repository-header","aria-sort":ts[h],children:e.jsxs("button",{type:"button","data-testid":"skill-repository-sort",className:"flex min-h-11 items-center gap-2 text-sm text-muted-foreground hover:text-on-surface",onClick:()=>{g(h==="default"?"asc":h==="asc"?"desc":"default")},title:"Sort by GitHub repository: ascending, descending, then default order",children:["GitHub repository ",e.jsx(y,{size:14,"aria-hidden":"true"})]})}),e.jsx(G,{className:"text-xs text-muted-foreground",children:"Agent discovery"})]})}),e.jsx(Ct,{children:_e.map(l=>e.jsxs($e,{"data-testid":"skill-row","data-skill-name":l.name,className:"border-b border-outline-variant/50 hover:bg-surface-low cursor-pointer",onClick:()=>w(l.name),children:[e.jsx(V,{onClick:S=>S.stopPropagation(),children:je.includes(l.name)&&e.jsx("input",{type:"checkbox","data-testid":"skill-select","aria-label":`Select ${l.name}`,checked:F.selectedIds.includes(l.name),disabled:z.isPending,onChange:()=>F.toggle(l.name),className:"size-4 accent-primary"})}),e.jsxs(V,{className:"font-body text-sm font-medium text-on-surface",children:[e.jsx("button",{type:"button","data-testid":"skill-open",className:"min-h-11 text-left hover:text-primary",onClick:S=>{S.stopPropagation(),w(l.name)},children:l.name}),l.mutation&&e.jsx("span",{className:"ml-2 text-primary text-xs",children:"Modified"})]}),e.jsx(V,{className:"font-body text-sm text-muted-foreground max-w-md truncate",children:l.description||"—"}),e.jsx(V,{"data-testid":"skill-source-cell",children:e.jsx("span",{className:`inline-flex py-0.5 font-label text-sm ${st[l.source]}`,children:l.source})}),e.jsx(V,{"data-testid":"skill-repository-cell",onClick:S=>S.stopPropagation(),className:"max-w-56 truncate text-sm text-muted-foreground",children:M.get(l.name)?e.jsx("a",{"data-testid":"skill-repository-link",href:`https://github.com/${M.get(l.name)}`,target:"_blank",rel:"noreferrer",className:"text-primary hover:underline",title:M.get(l.name),children:M.get(l.name)}):"—"}),e.jsx(V,{onClick:S=>S.stopPropagation(),children:e.jsxs("button",{type:"button",role:"switch","aria-label":`${l.name} visible to agents`,"aria-checked":!l.discovery_hidden,"data-testid":`skill-visibility-${l.name}`,disabled:!O.data||ne.isPending,className:"inline-flex min-h-11 items-center gap-2 text-xs text-primary disabled:opacity-50",title:l.discovery_hidden?"Show in agent discovery":"Hide from agent discovery",onClick:()=>{var K,U;const S=new Set(((K=O.data)==null?void 0:K.hidden_skills)??[]),E=new Set(((U=O.data)==null?void 0:U.hidden_builtins)??[]);l.discovery_hidden?(S.delete(l.name),E.delete(l.name)):S.add(l.name),ne.mutate({hidden_skills:[...S],hidden_builtins:[...E]})},children:[l.discovery_hidden?e.jsx(zt,{size:22,"aria-hidden":"true",className:"text-muted-foreground"}):e.jsx(Mt,{size:22,"aria-hidden":"true"}),l.discovery_hidden?"Hidden":"Visible",l.mutation&&" (Modified)"]})})]},l.name))})]})}),q&&q.total>30&&e.jsxs("div",{className:"flex items-center justify-end gap-3 mt-4","data-testid":"skills-pagination",children:[e.jsxs("span",{className:"text-sm text-muted-foreground","data-testid":"skills-page-summary",children:[T+1,"–",Math.min(T+q.skills.length,q.total)," of"," ",q.total]}),e.jsx(C,{variant:"outline",size:"sm","data-testid":"skills-previous",disabled:T===0||ge,onClick:()=>Oe({scope:le,offset:Math.max(0,T-30)}),children:"Previous"}),e.jsx(C,{variant:"outline",size:"sm","data-testid":"skills-next",disabled:q.next_offset===null||ge,onClick:()=>Oe({scope:le,offset:q.next_offset??T}),children:"Next"})]}),e.jsx(is,{scope:i,skillName:p,open:!!p,onClose:f},p),c&&e.jsx(rs,{open:c,onClose:()=>m(!1)}),v&&e.jsx(Vt,{onClose:()=>x(!1)}),b&&e.jsx(Gt,{onClose:()=>k(!1)})]})}function is({skillName:a,scope:t,open:i,onClose:r}){const{data:o,isLoading:n,error:s,refetch:u}=Ge(a,void 0,t),d=o,[h,g]=ue("skillFile","SKILL.md"),y=Ge(a,h??"SKILL.md",t),p=y.data,w=A(),[f,c]=N.useState(!1),m=`skill:${t.project_id??"global"}:${a}:${h??"SKILL.md"}`;function v(b){return(b??"SKILL.md")===(h??"SKILL.md")?!0:ze(m)?(g(b??"SKILL.md"),!0):!1}const x=d?e.jsx(Ut,{files:["SKILL.md",...(d.files??[]).map(b=>b.name)],selected:h??"SKILL.md",onSelect:b=>v(b==="SKILL.md"?void 0:b),testId:"skill-file",entryTestId:"skill-show-entry"}):null;return e.jsx(Lt,{open:i,onOpenChange:b=>!b&&ze(m)&&r(),children:e.jsxs(It,{className:"w-screen max-w-full sm:w-[1120px] sm:max-w-[96vw]",children:[e.jsxs(Ot,{children:[e.jsx(Et,{children:(d==null?void 0:d.name)??"Skill Details"}),(d==null?void 0:d.description)&&e.jsx("p",{className:"font-body text-sm text-muted-foreground mt-1",children:d.description})]}),e.jsx(_t,{children:e.jsxs(e.Fragment,{children:[a&&d&&e.jsx(Yt,{name:a,scope:t,mutation:d.mutation}),a&&d&&e.jsx(Jt,{name:a}),s?e.jsx(Ze,{message:s.message,onRetry:()=>void u()}):n||!d?e.jsx("div",{className:"space-y-3",children:[...Array(4)].map((b,k)=>e.jsx(We,{className:"h-8 w-full bg-surface-highest"},k))}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(Te,{label:"Source",children:e.jsx("span",{className:`inline-flex py-0.5 font-label text-sm ${st[d.source]}`,children:d.source})}),e.jsx(Te,{label:"Path",children:e.jsx("code",{className:"font-mono text-sm text-muted-foreground break-all",children:d.path})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-sm text-muted-foreground mb-2",children:h??"SKILL.md"}),e.jsxs("div",{className:"overflow-hidden",children:[(p==null?void 0:p.encoding)==="base64"&&e.jsx("div",{className:"p-3",children:x}),y.error?e.jsx("p",{role:"alert",children:y.error.message}):y.isLoading?e.jsx("p",{children:"Loading..."}):(p==null?void 0:p.encoding)==="base64"?e.jsx(et,{path:h??"SKILL.md",value:(p==null?void 0:p.content)??"",readOnly:!0,hidePreview:!0,height:400,testId:"skill-file-content"}):e.jsx(Pt,{documentId:m,expanded:f,onExpandedChange:c,navigation:x,path:h??"SKILL.md",content:(p==null?void 0:p.content)??"",testId:"skill-file-content",onSave:d.source==="user"&&(p==null?void 0:p.encoding)==="utf8"?async(b,k)=>{const O=h??"SKILL.md";return d.mutation&&O==="SKILL.md"?await L.skills.updateInstructions(d.name,{project_id:t.project_id??null,content:b,expected_content:k,reason:"Manual instruction edit",author:"human"}):await L.skills.editFile(d.name,{path:O,content:b,expectedContent:k}),await w.invalidateQueries({queryKey:["skill",d.name]}),await w.invalidateQueries({queryKey:["skills"]}),await w.invalidateQueries({queryKey:["skill-history",d.name]}),b}:void 0},m),(p==null?void 0:p.encoding)==="base64"&&e.jsx("p",{className:"p-4 text-xs text-muted-foreground",children:"Binary asset shown as base64 (read-only)."})]})]})]})]})})]})})}function rs({open:a,onClose:t}){var v;const[i,r]=N.useState(""),[o,n]=N.useState(""),s=es(),[u,d]=N.useState([]),[h,g]=N.useState(),[y,p]=N.useState(!1),w=!!(i||o||u.length);N.useEffect(()=>{if(!w)return;function x(b){b.preventDefault(),b.returnValue=""}return window.addEventListener("beforeunload",x),()=>window.removeEventListener("beforeunload",x)},[w]);function f(){s.isPending||y||(!w||window.confirm("Discard this unsaved skill?"))&&t()}async function c(x){if(x!=null&&x.length){p(!0),g(void 0);try{const b=(await Dt(x)).map(O=>({...O,encoding:O.encoding??"utf8",id:crypto.randomUUID()})),k=b.find(O=>O.path==="SKILL.md");if(!k)throw new Error("Choose a skill folder containing SKILL.md");if(k.encoding!=="utf8")throw new Error("SKILL.md must be UTF-8 text");n(k.content),r(x[0].webkitRelativePath.split("/")[0]),d(b.filter(O=>O!==k))}catch(b){g(b.message)}finally{p(!1)}}}const m=()=>{!i.trim()||!o.trim()||s.isPending||y||u.some(x=>!x.path.trim())||s.mutate({name:i.trim(),content:o.trim(),files:u.map(({path:x,content:b,encoding:k})=>({path:x,content:b,encoding:k}))},{onSuccess:t})};return e.jsx(me,{open:a,onOpenChange:x=>!x&&f(),children:e.jsxs(he,{className:"bg-surface border-outline-variant w-[calc(100%_-_1rem)] max-w-5xl max-h-[94dvh] overflow-y-auto",children:[e.jsx(xe,{children:e.jsx(pe,{className:"font-headline text-base text-on-surface",children:"New skill"})}),e.jsxs("form",{onSubmit:x=>{x.preventDefault(),m()},className:"space-y-3 mt-2",children:[e.jsx(de,{htmlFor:"skill-folder-input",children:"Import skill folder"}),e.jsx(Y,{id:"skill-folder-input","data-testid":"skill-folder-input",type:"file",multiple:!0,webkitdirectory:"",onChange:x=>void c(x.target.files)}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(de,{className:"font-label text-sm text-muted-foreground",children:"Name *"}),e.jsx(Y,{"aria-label":"Name","data-testid":"skill-name-input",value:i,onChange:x=>r(x.target.value),placeholder:"my-skill",className:"bg-background text-on-surface font-body text-sm",autoFocus:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(de,{className:"font-label text-sm text-muted-foreground",children:"SKILL.md *"}),e.jsx(qt,{testId:"skill-content-input",path:"SKILL.md",value:o,onChange:n,onSave:m})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(C,{"data-testid":"skill-add-file",type:"button",variant:"outline",onClick:()=>d([...u,{id:crypto.randomUUID(),path:"",content:"",encoding:"utf8"}]),children:"Add file"}),u.map(x=>e.jsxs("div",{"data-testid":"skill-supporting-file",className:"space-y-2 border border-outline-variant p-3",children:[e.jsx(Y,{"data-testid":"skill-file-path-input","aria-label":"File path",placeholder:"references/guide.md or scripts/check.py",value:x.path,onChange:b=>d(u.map(k=>k.id===x.id?{...k,path:b.target.value}:k))}),e.jsx(et,{testId:"skill-file-content-input",path:x.path||"supporting.txt",readOnly:x.encoding==="base64",label:`Content of ${x.path||"supporting file"}`,value:x.content,height:180,onChange:b=>d(u.map(k=>k.id===x.id?{...k,content:b}:k))}),x.encoding==="base64"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Binary asset (base64)"}),e.jsx(C,{type:"button",variant:"ghost",onClick:()=>d(u.filter(b=>b.id!==x.id)),children:"Remove file"})]},x.id))]}),(h||s.error)&&e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:h??((v=s.error)==null?void 0:v.message)}),e.jsxs(fe,{children:[e.jsx(C,{type:"button",variant:"ghost",size:"sm",onClick:f,className:"font-label text-sm text-muted-foreground",children:"Cancel"}),e.jsx(C,{"data-testid":"skill-submit",type:"submit",size:"sm",disabled:y||s.isPending||!i.trim()||!o.trim()||u.some(x=>!x.path.trim()),className:"font-label text-sm ",children:s.isPending?"Creating...":"Create"})]})]})]})})}export{ms as default};