spexcode 0.5.2 → 0.5.3

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 (151) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/spec-cli/bin/spex.mjs +25 -1
  4. package/spec-cli/hooks/dispatch.sh +24 -1
  5. package/spec-cli/src/anchors.ts +192 -58
  6. package/spec-cli/src/attach.ts +11 -8
  7. package/spec-cli/src/claude-headless.ts +13 -52
  8. package/spec-cli/src/cli.ts +209 -71
  9. package/spec-cli/src/client.ts +143 -5
  10. package/spec-cli/src/gateway-hub.ts +2 -6
  11. package/spec-cli/src/gateway.ts +96 -11
  12. package/spec-cli/src/git.ts +1395 -96
  13. package/spec-cli/src/graph.ts +21 -17
  14. package/spec-cli/src/graphCache.ts +405 -61
  15. package/spec-cli/src/graphStream.ts +581 -182
  16. package/spec-cli/src/guide.ts +13 -3
  17. package/spec-cli/src/harness.ts +946 -71
  18. package/spec-cli/src/headless-controller.ts +63 -0
  19. package/spec-cli/src/help.ts +120 -64
  20. package/spec-cli/src/host-resources.ts +706 -0
  21. package/spec-cli/src/index.ts +95 -21
  22. package/spec-cli/src/init.ts +47 -8
  23. package/spec-cli/src/issues.ts +36 -3
  24. package/spec-cli/src/layout.ts +193 -37
  25. package/spec-cli/src/lint.ts +152 -27
  26. package/spec-cli/src/localIssues.ts +5 -1
  27. package/spec-cli/src/maintenance-wrapper.ts +276 -0
  28. package/spec-cli/src/materialize.ts +6 -7
  29. package/spec-cli/src/opencode-headless.ts +4 -8
  30. package/spec-cli/src/pi-headless.ts +17 -60
  31. package/spec-cli/src/process-identity.ts +49 -0
  32. package/spec-cli/src/project-store.ts +17 -0
  33. package/spec-cli/src/pty-bridge.ts +6 -3
  34. package/spec-cli/src/reviews.ts +17 -13
  35. package/spec-cli/src/runtime-ownership.ts +99 -0
  36. package/spec-cli/src/session-maintenance.ts +750 -0
  37. package/spec-cli/src/session-timeline.ts +6 -6
  38. package/spec-cli/src/sessions.ts +1249 -208
  39. package/spec-cli/src/sh.ts +3 -0
  40. package/spec-cli/src/source-files.ts +27 -2
  41. package/spec-cli/src/specs.ts +58 -25
  42. package/spec-cli/src/supervise.ts +31 -11
  43. package/spec-cli/src/uninstall.ts +7 -6
  44. package/spec-cli/templates/hooks/commit-msg +14 -0
  45. package/spec-cli/templates/hooks/pre-commit +26 -6
  46. package/spec-cli/templates/hooks/prepare-commit-msg +20 -48
  47. package/spec-cli/templates/hooks/reference-transaction +105 -0
  48. package/spec-cli/templates/spec/project/.plugins/commands/supervisor/spec.md +1 -1
  49. package/spec-cli/templates/spec/project/.plugins/core/mark-active/mark-active.sh +23 -21
  50. package/spec-cli/templates/spec/project/.plugins/core/spec.md +12 -10
  51. package/spec-cli/templates/spec/project/.plugins/core/stop-gate/stop-gate.sh +15 -6
  52. package/spec-cli/templates/spec/project/.plugins/prompts/atomic-landing/spec.md +32 -0
  53. package/spec-dashboard/dist/assets/App-C5vbTw8Q.js +2 -0
  54. package/spec-dashboard/dist/assets/Dashboard-u8RIS3NY.js +27 -0
  55. package/spec-dashboard/dist/assets/EvalsPage-BS7ITcNo.js +2 -0
  56. package/spec-dashboard/dist/assets/IssuesPage-DXbqQFW_.js +1 -0
  57. package/spec-dashboard/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  58. package/spec-dashboard/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  59. package/spec-dashboard/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  60. package/spec-dashboard/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  61. package/spec-dashboard/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  62. package/spec-dashboard/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  63. package/spec-dashboard/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  64. package/spec-dashboard/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  65. package/spec-dashboard/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  66. package/spec-dashboard/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  67. package/spec-dashboard/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  68. package/spec-dashboard/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  69. package/spec-dashboard/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  70. package/spec-dashboard/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  71. package/spec-dashboard/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  72. package/spec-dashboard/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  73. package/spec-dashboard/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  74. package/spec-dashboard/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  75. package/spec-dashboard/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  76. package/spec-dashboard/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  77. package/spec-dashboard/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  78. package/spec-dashboard/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  79. package/spec-dashboard/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  80. package/spec-dashboard/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  81. package/spec-dashboard/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  82. package/spec-dashboard/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  83. package/spec-dashboard/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  84. package/spec-dashboard/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  85. package/spec-dashboard/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  86. package/spec-dashboard/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  87. package/spec-dashboard/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  88. package/spec-dashboard/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  89. package/spec-dashboard/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  90. package/spec-dashboard/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  91. package/spec-dashboard/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  92. package/spec-dashboard/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  93. package/spec-dashboard/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  94. package/spec-dashboard/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  95. package/spec-dashboard/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  96. package/spec-dashboard/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  97. package/spec-dashboard/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  98. package/spec-dashboard/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  99. package/spec-dashboard/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  100. package/spec-dashboard/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  101. package/spec-dashboard/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  102. package/spec-dashboard/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  103. package/spec-dashboard/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  104. package/spec-dashboard/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  105. package/spec-dashboard/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  106. package/spec-dashboard/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  107. package/spec-dashboard/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  108. package/spec-dashboard/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  109. package/spec-dashboard/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  110. package/spec-dashboard/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  111. package/spec-dashboard/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  112. package/spec-dashboard/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  113. package/spec-dashboard/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  114. package/spec-dashboard/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  115. package/spec-dashboard/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  116. package/spec-dashboard/dist/assets/MobileApp-DVLnk9hz.js +2 -0
  117. package/spec-dashboard/dist/assets/Modal-6mHq6fbZ.js +1 -0
  118. package/spec-dashboard/dist/assets/{PageScroll-CadAKuSy.js → PageScroll-CAY4S4g4.js} +1 -1
  119. package/spec-dashboard/dist/assets/ProjectsPage-UQyzsTWN.js +1 -0
  120. package/spec-dashboard/dist/assets/SessionInterface-DKU4c1Z-.js +39 -0
  121. package/spec-dashboard/dist/assets/SessionWindow-zGwJaGbR.js +1 -0
  122. package/spec-dashboard/dist/assets/Settings-igR17pns.js +1 -0
  123. package/spec-dashboard/dist/assets/Thread-B-ZUarN1.js +13 -0
  124. package/spec-dashboard/dist/assets/TimelineChat-Cp579UoJ.css +1 -0
  125. package/spec-dashboard/dist/assets/TimelineChat-sc49Qj5d.js +276 -0
  126. package/spec-dashboard/dist/assets/data-B1ot4PF0.js +1 -0
  127. package/spec-dashboard/dist/assets/index-BqBNCa1V.js +41 -0
  128. package/spec-dashboard/dist/assets/index-CzutlTDf.css +1 -0
  129. package/spec-dashboard/dist/assets/{terminalFont-DmTPNdbU.js → terminalFont-C6oGNKrf.js} +1 -1
  130. package/spec-dashboard/dist/index.html +5 -4
  131. package/spec-dashboard/src/reviewFilters.js +46 -8
  132. package/spec-dashboard/src/session.js +64 -9
  133. package/spec-eval/src/cli.ts +144 -32
  134. package/spec-eval/src/evaltab.ts +16 -9
  135. package/spec-eval/src/freshness.ts +336 -54
  136. package/spec-eval/src/scenariofresh.ts +51 -1
  137. package/spec-eval/src/scenarios.ts +324 -25
  138. package/spec-eval/src/sessioneval.ts +969 -173
  139. package/spec-cli/src/message-stream.ts +0 -147
  140. package/spec-dashboard/dist/assets/Dashboard-CTAuTyZ3.js +0 -27
  141. package/spec-dashboard/dist/assets/EvalsPage-KbMMownG.js +0 -2
  142. package/spec-dashboard/dist/assets/IssuesPage-DmyLb9Rj.js +0 -1
  143. package/spec-dashboard/dist/assets/MobileApp-D2RZGt4Z.js +0 -2
  144. package/spec-dashboard/dist/assets/Modal-3brXUhM0.js +0 -1
  145. package/spec-dashboard/dist/assets/ProjectsPage-DU3x4Y8l.js +0 -1
  146. package/spec-dashboard/dist/assets/SessionInterface-BtrzlOPs.js +0 -39
  147. package/spec-dashboard/dist/assets/SessionWindow-BWH5O0jh.js +0 -13
  148. package/spec-dashboard/dist/assets/Settings-COgdKTJB.js +0 -1
  149. package/spec-dashboard/dist/assets/TimelineChat-DQ21GSJK.js +0 -1
  150. package/spec-dashboard/dist/assets/index-D6HBvKkJ.js +0 -41
  151. package/spec-dashboard/dist/assets/index-DFdlYy4H.css +0 -1
@@ -1,13 +0,0 @@
1
- import{j as t,r as p,d as js,I as V,u as C,e as me,a as ve,f as ys,i as bs,k as Ns,s as xe}from"./index-D6HBvKkJ.js";import{P as ee}from"./PageScroll-CadAKuSy.js";function ze(e){let s=2166136261;for(let a=0;a<(e||"").length;a++)s^=e.charCodeAt(a),s=Math.imul(s,16777619);return s>>>0}function Ue(e){return ze(e)%360}function ks(e){const s=Ue(e);return{bg:`hsl(${s} 55% 42%)`,fg:`hsl(${s} 70% 92%)`}}function Ss(e){return`hsl(${Ue(e)} 65% 50%)`}const be=["◆","▲","●","■","★","✦","⬟","⬢","❖","◈","✸","⟡","✚","❂","◐","◑","⬣","▰","✶","⬤","✹","◇","⊛","✺"],Ne=["circle","rounded","square","hex"];function $s(e){const s=ze(e);return{seed:e,glyph:be[(s>>>9)%be.length],shape:Ne[(s>>>17)%Ne.length],...ks(e)}}function Es({seed:e,status:s,title:a,size:n=16}){const r=$s(e),i={width:n,height:n};return t.jsx("span",{className:`avatar av-st-${s||"none"}`,"data-tip":a,"aria-label":a,style:i,children:t.jsx("span",{className:`av-face av-gen av-${r.shape}`,style:{...i,background:r.bg,color:r.fg,fontSize:n*.62},children:r.glyph})})}const re=typeof window<"u"?window.__escStack||(window.__escStack=[]):[];typeof window<"u"&&!window.__escStackBound&&(window.__escStackBound=!0,window.addEventListener("keydown",e=>{const s=window.__escStack;e.key!=="Escape"||!s||s.length===0||(e.preventDefault(),e.stopImmediatePropagation(),s[s.length-1].close())},!0));function Be(e,s){const a=p.useRef(s);a.current=s,p.useEffect(()=>{if(!e)return;const n={close:()=>{var r;return(r=a.current)==null?void 0:r.call(a)}};return re.push(n),()=>{const r=re.indexOf(n);r>=0&&re.splice(r,1)}},[e])}const Ls="is:issue state:open",ae="is:eval",He=e=>W(ae,"scope",e),Cs=e=>W(ae,"node",e),We=/^([A-Za-z][A-Za-z0-9-]*):(.*)$/s,ke=e=>e.length>=2&&e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e,Ge=e=>/\s/.test(String(e))?`"${e}"`:String(e);function ge(e){const s=String(e??""),a=[];let n=0;for(;n<s.length;){let r=n;if(/\s/.test(s[n])){for(;r<s.length&&/\s/.test(s[r]);)r++;a.push({ws:!0,raw:s.slice(n,r),start:n,end:r})}else{for(;r<s.length&&!/\s/.test(s[r]);)if(s[r]==='"'){for(r++;r<s.length&&s[r]!=='"';)r++;r<s.length&&r++}else r++;const i=s.slice(n,r),l=We.exec(i);a.push(l?{ws:!1,raw:i,start:n,end:r,key:l[1].toLowerCase(),value:ke(l[2])}:{ws:!1,raw:i,start:n,end:r,key:null,value:ke(i)})}n=r}return a}const we=e=>ge(e).filter(s=>!s.ws),Qe=e=>e.map(s=>s.raw).join(" "),Se=e=>Qe(we(e)),Ye=(e,s)=>Se(e)===Se(s),ft=(e,s)=>{const a=we(e);for(let n=a.length-1;n>=0;n--)if(a[n].key===s)return a[n].value;return""};function W(e,s,a){const n=a==null||String(a)===""?null:{ws:!1,raw:`${s}:${Ge(a)}`,key:s,value:String(a)},r=[];let i=!1;for(const l of we(e)){if(l.key===s){n&&!i&&(r.push(n),i=!0);continue}r.push(l)}return n&&!i&&r.push(n),Qe(r)}const As=(e,s)=>{const a=String(e??"").trim();return!a||Ye(a,s)?null:{q:a}},pt=(e,s,a=null)=>{const n=As(e,s)||{};return a!=null&&(n.page=String(a)),Object.keys(n).length?n:null},Ze={state:e=>["state",e],concluded:e=>e==="1"?["state","closed"]:null,ok:e=>e==="1"?["state","reviewed"]:null,verdict:e=>["verdict",e],freshness:e=>["freshness",e],kind:e=>e==="all"?null:["evidence",e],store:e=>["store",e],author:e=>["author",e],node:e=>["node",e],filer:e=>["filer",e],live:e=>e==="1"?["session","present"]:null,session:e=>["scope",e]},Je=e=>Object.keys(Ze).some(s=>(e==null?void 0:e[s])!=null&&e[s]!==""),Ds=e=>/[\s:"]/.test(e)?`"${e.replace(/"/g,"")}"`:e;function Rs(e,s){if(!Je(s))return null;let a=e;for(const[r,i]of Object.entries(Ze)){const l=s[r];if(l==null||l==="")continue;const o=i(String(l));o&&(a=W(a,o[0],o[1]))}const n=String(s.q??"").trim();return n&&(a=`${a} ${Ds(n)}`.trim()),a}function Is(e,s,a=[],n={}){const r=String(e??""),i=Math.max(0,Math.min(s??r.length,r.length)),l=ge(r).find(m=>!m.ws&&m.start<i&&i<=m.end);if(!l)return{start:i,end:i,items:[]};const o=r.slice(l.start,i),c=We.exec(o);if(!c){const m=o.toLowerCase();if(!m||m.includes('"'))return{start:l.start,end:l.end,items:[]};const w=a.filter(x=>x.startsWith(m)).slice(0,8).map(x=>({type:"key",key:x,insert:`${x}:`}));return{start:l.start,end:l.end,items:w}}const u=c[1].toLowerCase(),d=c[2].replace(/^"/,"").replace(/"$/,"").toLowerCase(),h=(n[u]||[]).filter(m=>String(m.value).toLowerCase().startsWith(d)&&String(m.value).toLowerCase()!==d).slice(0,8).map(m=>({type:"value",key:u,value:String(m.value),label:m.label||null,insert:`${u}:${Ge(m.value)} `}));return{start:l.start,end:l.end,items:h}}const Q=new Map;async function Ts(e){if(Q.has(e))return Q.get(e);const s=js(e).then(async a=>{const n=await a.json().catch(()=>null);if(!a.ok)throw new Error((n==null?void 0:n.error)||`HTTP ${a.status}`);return n}).finally(()=>Q.delete(e));return Q.set(e,s),s}const mt=e=>{const s=typeof e=="string"&&/^\d+$/.test(e)?Number(e):Number.NaN;return Number.isSafeInteger(s)&&s>0?s:1};function Ps(e,s){return s<=0?[]:s<=10?Array.from({length:s},(a,n)=>n+1):e<=7?[...Array.from({length:8},(a,n)=>n+1),"gap",s-1,s]:e>=s-6||e>s?[1,2,"gap",...Array.from({length:8},(a,n)=>s-7+n)]:[1,2,"gap",e-2,e-1,e,e+1,e+2,"gap",s-1,s]}function Xe(e,s,a,{enabled:n=!0,refreshKey:r=null,pollMs:i=15e3,view:l=null}={}){const[o,c]=p.useState(null),[u,d]=p.useState(null),[v,h]=p.useState(n),m=p.useRef(0),w=p.useCallback(async({quiet:f=!1}={})=>{if(!n)return null;const b=++m.current;f||h(!0),d(null);const k=new URLSearchParams({q:String(s||""),page:String(a)});l&&k.set("view",l);try{const S=await Ts(`/api/${e}?${k}`);return b===m.current&&c(D=>D&&S&&D.revision===S.revision?D:S),S}catch(S){return b===m.current&&d(S instanceof Error?S.message:String(S)),null}finally{b===m.current&&h(!1)}},[e,n,a,s,l]),x=p.useRef(null);return p.useEffect(()=>{if(!n){h(!1);return}const f=`${e}\0${s}\0${a}\0${l||""}`,b=f!==x.current;x.current=f,b&&c(null),w({quiet:!b});const k=i>0?setInterval(()=>w({quiet:!0}),i):null;return()=>{k&&clearInterval(k)}},[e,s,a,l,n,w,i,r]),{data:o,error:u,loading:v,reload:w}}const $e={issue:{open:{icon:"issue-opened",tone:"open",label:"reviewState.issueOpen"},closed:{icon:"issue-closed",tone:"closed",label:"reviewState.issueClosed"}},eval:{pass:{icon:"circle-check",tone:"pass",label:"score.pass"},fail:{icon:"circle-x",tone:"fail",label:"score.fail"},stalePass:{icon:"circle-check",tone:"stale",label:"score.stalePass"},staleFail:{icon:"circle-x",tone:"stale",label:"score.staleFail"},review:{icon:"clock",tone:"review",label:"reviewList.needsReview"},empty:{icon:"circle-minus",tone:"empty",label:"score.empty"},missing:{icon:"circle-dashed",tone:"empty",label:"score.missing"},legacy:{icon:"circle-minus",tone:"empty",label:"score.empty"}}},Vs=(e,s)=>{var n;const a=e==="issue"?s==="open"?"open":"closed":s||"empty";return((n=$e[e])==null?void 0:n[a])||$e.eval.empty};function je({kind:e,state:s,showLabel:a=!1,size:n=16,className:r="",title:i}){const l=C(),o=Vs(e,s),c=i||l(o.label);return t.jsxs("span",{className:`review-state ${e} ${o.tone} ${r}`,"data-tip":c,"aria-label":c,children:[t.jsx("span",{className:"review-state-icon",style:{width:n,height:n},children:t.jsx(V,{name:o.icon,size:n})}),a&&t.jsx("span",{className:"review-state-label",children:c})]})}function Fs(e,s){const a={...e,...s};for(const[n,r]of Object.entries(a))(r==null||r==="")&&delete a[n];return a}const qs=e=>e&&typeof e=="object"?e.hasData?e.filtered:e.dataset:e,es=(e,s,a)=>{const n=Array.isArray(e)?e:[];return!(s!=null&&String(s)!=="")||a==null||n.some(i=>String(i.value)==="")?n:[{value:"",label:a},...n]},Ms=(e=[])=>e.reduce((s,a)=>((a.active??(a.value!=null&&String(a.value)!==""))&&(s.mobile+=1,a.mobileOnly||(s.desktop+=1)),s),{desktop:0,mobile:0}),ye=(e,s,a)=>s?a==="Home"?0:a==="End"?s-1:a==="ArrowDown"||a==="ArrowRight"?e<0?0:(e+1)%s:a==="ArrowUp"||a==="ArrowLeft"?e<0?s-1:(e-1+s)%s:e:-1,Ks=(e,s)=>{var n;const a=e==null?void 0:e.tagName;return a==="INPUT"||a==="TEXTAREA"||a==="SELECT"||a==="BUTTON"&&(s==="Enter"||s===" ")||s==="Enter"&&((n=e==null?void 0:e.closest)!=null&&n.call(e,"a[href]"))?!1:s==="j"||s==="k"||s==="Enter"},le=e=>[...(e==null?void 0:e.querySelectorAll('[role="menuitemradio"]'))||[]].filter(s=>s.getClientRects().length>0),ie=(e,s)=>{const a=e[s];if(a){for(const n of e)n.tabIndex=n===a?0:-1;a.focus()}};function ss(){const[e,s]=p.useState(!1),a=p.useRef(null),n=p.useRef(null),r=p.useRef(null),i=p.useRef("checked"),l=(h=!1)=>{var m;h&&((m=r.current)==null||m.focus()),s(!1)},o=(h,m="checked")=>{r.current=h,i.current=m,s(!0)},c=h=>{e?l(!1):o(h)};return Be(e,()=>l(!0)),p.useEffect(()=>{if(!e)return;const h=m=>{var w;(w=a.current)!=null&&w.contains(m.target)||l(!1)};return window.addEventListener("pointerdown",h,!0),()=>window.removeEventListener("pointerdown",h,!0)},[e]),p.useEffect(()=>{if(!e)return;const h=requestAnimationFrame(()=>{const m=le(n.current),w=m.findIndex(f=>f.getAttribute("aria-checked")==="true"),x=i.current==="last"?m.length-1:i.current==="first"?0:w>=0?w:0;ie(m,x)});return()=>cancelAnimationFrame(h)},[e]),{open:e,ref:a,menuRef:n,close:l,toggle:c,onTriggerKeyDown:h=>{h.key!=="ArrowDown"&&h.key!=="ArrowUp"||(h.preventDefault(),h.stopPropagation(),o(h.currentTarget,h.key==="ArrowUp"?"last":"first"))},onMenuKeyDown:h=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(h.key))return;const m=le(n.current),w=m.indexOf(document.activeElement);h.preventDefault(),h.stopPropagation(),ie(m,ye(w,m.length,h.key))},onItemFocus:h=>{const m=le(n.current);ie(m,m.indexOf(h.currentTarget))}}}function vt({label:e,value:s="",options:a=[],onChange:n,mobile:r=!1,clearLabel:i}){const l=ss(),o=es(a,s,i);if(!o.length)return null;const c=o.find(v=>String(v.value)===String(s)),u=s?(c==null?void 0:c.label)||String(s):"",d=u?`${e}: ${u}`:e;return t.jsxs("div",{className:`rl-facet-wrap ${r?"mobile-stay":""}`,ref:l.ref,children:[t.jsxs("button",{type:"button",className:`rl-facet ${s?"active":""}`,"aria-label":d,"aria-haspopup":"menu","aria-expanded":l.open,onClick:v=>l.toggle(v.currentTarget),onKeyDown:l.onTriggerKeyDown,children:[t.jsx("span",{className:"rl-facet-label",children:d}),r&&t.jsx("span",{className:"rl-facet-label-mobile","aria-hidden":"true",children:u||e}),t.jsx(V,{name:"chevron-down",size:12})]}),l.open&&t.jsx("div",{className:"rl-menu",role:"menu","aria-label":e,ref:l.menuRef,onKeyDown:l.onMenuKeyDown,children:o.map(v=>t.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":String(v.value)===String(s),tabIndex:-1,className:"rl-menu-item",onFocus:l.onItemFocus,onClick:()=>{l.close(!0),n(v.value)},children:[t.jsx(V,{name:String(v.value)===String(s)?"check":"blank",size:13}),t.jsx("span",{children:v.label}),v.count!=null&&t.jsx("span",{className:"rl-menu-count",children:v.count})]},String(v.value)))})]})}function Os({label:e,groups:s=[],clearLabel:a,compact:n=!1,className:r=""}){const i=C(),l=p.useId(),o=s.map(h=>({...h,options:es(h.options,h.value,h.clearLabel===null?null:h.clearLabel||a)})).filter(h=>h.options.length),c=o.some(h=>!h.mobileOnly),u=Ms(o),d=ss();if(!o.length)return null;const v=(h,m)=>h>0&&t.jsxs("span",{className:`rl-secondary-filter-count ${m}`,children:[t.jsx("span",{"aria-hidden":"true",children:h}),t.jsx("span",{className:"sr-only",children:i("reviewList.activeFilters",{n:h})})]});return t.jsxs("div",{className:`rl-secondary-filters ${c?"":"mobile-only"} ${u.desktop?"active-desktop":""} ${u.mobile?"active-mobile":""} ${r}`,ref:d.ref,children:[n?t.jsx(me,{icon:"filter",size:16,className:"rl-secondary-filters-trigger compact",label:e,"aria-haspopup":"menu","aria-expanded":d.open,onClick:h=>d.toggle(h.currentTarget),onKeyDown:d.onTriggerKeyDown}):t.jsxs("button",{type:"button",className:"rl-secondary-filters-trigger","aria-haspopup":"menu","aria-expanded":d.open,onClick:h=>d.toggle(h.currentTarget),onKeyDown:d.onTriggerKeyDown,children:[t.jsx(V,{name:"filter",size:14}),t.jsx("span",{children:e}),v(u.desktop,"for-desktop"),v(u.mobile,"for-mobile"),t.jsx(V,{name:"chevron-down",size:12})]}),d.open&&t.jsx("div",{className:"rl-menu rl-secondary-filters-menu",role:"menu","aria-label":e,ref:d.menuRef,onKeyDown:d.onMenuKeyDown,children:o.map((h,m)=>t.jsxs("div",{role:"group","aria-labelledby":`${l}-group-${m}`,className:`rl-menu-group ${h.mobileOnly?"mobile-only":""}`,children:[t.jsx("div",{className:"rl-menu-label",id:`${l}-group-${m}`,children:h.label}),h.options.map(w=>t.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":String(w.value)===String(h.value||""),tabIndex:-1,className:"rl-menu-item",onFocus:d.onItemFocus,onClick:()=>{d.close(!0),h.onChange(w.value)},children:[t.jsx(V,{name:String(w.value)===String(h.value||"")?"check":"blank",size:13}),t.jsx("span",{children:w.label}),w.count!=null&&t.jsx("span",{className:"rl-menu-count",children:w.count})]},String(w.value)))]},`${h.label}-${h.mobileOnly?"mobile":"all"}`))})]})}function xt({state:e,title:s,meta:a,aside:n}){return t.jsxs("div",{className:"rl-row-grid",children:[t.jsx("div",{className:"rl-row-state",children:e}),t.jsxs("div",{className:"rl-row-body",children:[t.jsx("div",{className:"rl-row-title",children:s}),a&&t.jsx("div",{className:"rl-row-meta",children:a})]}),n&&t.jsx("div",{className:"rl-row-aside",children:n})]})}const Y=e=>{const s=String(e??"").trim();return s?`${s} `:""};function _s({value:e="",onSubmit:s,placeholder:a,label:n,keys:r=[],suggest:i={}}){const[l,o]=p.useState(()=>Y(e)),[c,u]=p.useState(-1),[d,v]=p.useState(-1),h=p.useRef(null),m=p.useRef(null),w=p.useId(),x=p.useRef(null),f=g=>requestAnimationFrame(()=>{const E=h.current;E&&(g&&E.focus(),E.setSelectionRange(E.value.length,E.value.length))});p.useEffect(()=>{o(Y(e)),u(-1),v(-1),f(x.current!==null&&x.current!==e),x.current=e},[e]);const b=c>=0?Is(l,c,r,i):{start:0,end:0,items:[]},k=b.items.length>0;Be(k,()=>u(-1));const S=()=>{m.current&&h.current&&(m.current.scrollLeft=h.current.scrollLeft)};p.useEffect(S);const D=g=>{u(-1),v(-1);const E=g.trim();o(Y(E)||Y(e)),f(!0),s(E)},N=g=>{const E=`${l.slice(0,b.start)}${g.insert}${l.slice(b.end)}`;if(o(E),g.type==="value"){D(E);return}const R=b.start+g.insert.length;u(R),v(-1),requestAnimationFrame(()=>{var y,$;(y=h.current)==null||y.focus(),($=h.current)==null||$.setSelectionRange(R,R)})};return t.jsxs("form",{className:"rl-query rq",role:"search",onSubmit:g=>{g.preventDefault(),D(l)},children:[t.jsxs("div",{className:"rq-wrap",children:[t.jsx("div",{className:"rq-hl","aria-hidden":"true",ref:m,children:ge(l).map((g,E)=>g.ws||g.key==null||!r.includes(g.key)?t.jsx("span",{children:g.raw},E):t.jsxs("span",{className:"rq-tok",children:[t.jsx("span",{className:"rq-tok-key",children:g.raw.slice(0,g.key.length+1)}),t.jsx("span",{className:"rq-tok-val",children:g.raw.slice(g.key.length+1)})]},E))}),t.jsx("input",{ref:h,role:"combobox","aria-expanded":k,"aria-controls":w,"aria-autocomplete":"list","aria-activedescendant":k&&d>=0?`${w}-o${d}`:void 0,value:l,spellCheck:!1,autoComplete:"off",placeholder:a,"aria-label":n,onChange:g=>{o(g.target.value),u(g.target.selectionStart??g.target.value.length),v(-1)},onScroll:S,onKeyDown:g=>{k&&(g.key==="ArrowDown"||g.key==="ArrowUp"?(g.preventDefault(),v(ye(d,b.items.length,g.key))):g.key==="Enter"&&d>=0&&(g.preventDefault(),N(b.items[d])))},onBlur:()=>u(-1)})]}),k&&t.jsx("div",{className:"rl-menu rq-list",role:"listbox",id:w,"aria-label":n,children:b.items.map((g,E)=>t.jsxs("div",{id:`${w}-o${E}`,role:"option","aria-selected":E===d,className:`rq-opt ${E===d?"active":""}`,onPointerDown:R=>{R.preventDefault(),N(g)},children:[t.jsx("span",{className:"rq-opt-token",children:g.insert.trim()}),g.label&&g.label!==g.value&&t.jsx("span",{className:"rq-opt-label",children:g.label})]},g.insert))}),t.jsx("button",{type:"submit",className:"rl-query-submit","data-tip":n,"aria-label":n,children:t.jsx(V,{name:"search",size:16})})]})}function ns({value:e="",onChange:s,placeholder:a,searchLabel:n,filterLabel:r,groups:i,clearLabel:l,clearSearchLabel:o,summary:c}){const u=C(),d=t.jsxs("div",{className:"rf-compact",role:"search",children:[t.jsx("span",{className:"rf-search-icon",children:t.jsx(V,{name:"search",size:13})}),t.jsx("input",{value:e,onChange:h=>s(h.target.value),placeholder:a,"aria-label":n}),e&&t.jsx(me,{icon:"x",size:12,className:"rf-clear",label:o,onClick:()=>s("")}),t.jsx(Os,{label:r,clearLabel:l,groups:i,compact:!0,className:"rf-secondary-filters"})]});if(!c)return d;const v=u("reviewList.showing",{shown:c.shown,total:c.total});return t.jsxs("div",{className:"rf-row",children:[t.jsxs("span",{className:"rf-summary","data-tip":v,children:[t.jsx("span",{className:"sr-only",children:v}),t.jsx("span",{className:"rf-summary-full","aria-hidden":"true",children:v}),t.jsxs("span",{className:"rf-summary-compact","aria-hidden":"true",children:[c.shown,"/",c.total]})]}),d]})}function zs({page:e,pageCount:s,prev:a,next:n,hrefFor:r}){const i=C();if(s<=1&&e<=1)return null;const l=(o,c,u,d="")=>o==null?t.jsx("span",{className:`rl-page-link disabled ${d}`,"aria-disabled":"true",children:c}):t.jsx("a",{className:`rl-page-link ${d}`,href:r(o),rel:u,"aria-label":u?i(`reviewList.${u}Page`):i("reviewList.page",{n:o}),children:c});return t.jsxs("nav",{className:"rl-pagination","aria-label":i("reviewList.pagination"),children:[l(a,i("reviewList.previous"),"prev","direction"),Ps(e,s).map((o,c)=>o==="gap"?t.jsx("span",{className:"rl-page-gap","aria-hidden":"true",children:"…"},`gap-${c}`):t.jsx("a",{className:"rl-page-link number",href:r(o),"aria-label":i("reviewList.page",{n:o}),"aria-current":o===e?"page":void 0,children:o},o)),l(n,i("reviewList.next"),"next","direction")]})}function gt({notice:e,leading:s,error:a,loading:n=!1,title:r,action:i,search:l,sections:o=[],sectionMode:c="tabs",facets:u,secondaryFilters:d,rows:v,empty:h,pagination:m,children:w}){const x=C(),[f,b]=p.useState(null),k=p.useId(),S=p.useRef({});S.current={rows:v,cur:f},p.useEffect(()=>{const y=$=>{if($.metaKey||$.ctrlKey||$.altKey||!Ks($.target,$.key))return;const A=S.current.rows.filter(F=>F.href);if(!A.length)return;if($.key==="Enter"){const F=A.find(j=>j.key===S.current.cur);F&&($.preventDefault(),$.stopPropagation(),window.location.hash=F.href);return}$.preventDefault(),$.stopPropagation();const I=A.findIndex(F=>F.key===S.current.cur),U=I<0?$.key==="j"?0:A.length-1:Math.max(0,Math.min(A.length-1,I+($.key==="j"?1:-1)));b(A[U].key)};return window.addEventListener("keydown",y,!0),()=>window.removeEventListener("keydown",y,!0)},[]),p.useEffect(()=>{var y;(y=document.querySelector(".lp-row.cur"))==null||y.scrollIntoView({block:"nearest"})},[f]);const D=qs(h),N=Math.max(0,o.findIndex(y=>y.active)),g=c==="tabs",E=`${k}-panel`,R=y=>`${k}-tab-${y}`;return t.jsxs(ee,{className:"lp-page",children:[e&&t.jsx("div",{className:"fv-notice",children:e}),s,t.jsxs("div",{className:"rl-content",children:[t.jsxs("div",{className:"rl-titlebar",children:[t.jsx("h1",{children:r}),i]}),l&&t.jsx(_s,{...l}),a&&t.jsx("div",{className:"fv-error lp-error",role:"alert",children:a}),t.jsxs("section",{className:"rl-list",children:[t.jsxs("header",{className:"lp-head",children:[t.jsx("div",{className:"rl-sections",role:g?"tablist":"group","aria-label":r,...g?{"aria-orientation":"horizontal"}:{},children:o.map((y,$)=>t.jsxs("button",{type:"button",role:g?"tab":void 0,"aria-selected":g?y.active:void 0,"aria-pressed":g?void 0:y.active,"aria-controls":g?E:void 0,id:g?R($):void 0,tabIndex:g?$===N?0:-1:void 0,className:`rl-section ${y.active?"active":""}`,onClick:y.onSelect,onKeyDown:A=>{var F,j;if(!g||!["ArrowLeft","ArrowRight","Home","End"].includes(A.key))return;const I=[...A.currentTarget.closest('[role="tablist"]').querySelectorAll('[role="tab"]')],U=ye(I.indexOf(A.currentTarget),I.length,A.key);A.preventDefault(),A.stopPropagation(),(F=I[U])==null||F.focus(),(j=I[U])==null||j.click()},children:[t.jsx("span",{children:y.label}),t.jsx("span",{className:"rl-section-count",children:y.count})]},y.key))}),t.jsxs("div",{className:"rl-facets",children:[u,d]})]}),t.jsxs("div",{className:"lp-rows",role:g?"tabpanel":"region",id:E,"aria-busy":n||void 0,"aria-labelledby":g?R(N):void 0,"aria-label":g?void 0:r,children:[v.length===0&&t.jsx("div",{className:"lp-empty",children:n?x("common.loading"):D}),v.map(y=>y.href?t.jsx("a",{className:`lp-row ${y.cls||""} ${f===y.key?"cur":""}`,href:y.href,children:y.content},y.key):t.jsx("div",{className:`lp-row inert ${y.cls||""}`,children:y.content},y.key))]})]}),m&&t.jsx(zs,{...m})]}),w]})}function wt({title:e,titleMeta:s,status:a,side:n,composer:r,missing:i,failure:l,listHref:o,listLabel:c,backHref:u,backLabel:d,children:v}){return l?t.jsxs(ee,{className:"ds-page ds-missing ds-failed",role:"alert",children:[t.jsx("div",{className:"ds-missing-note",children:l}),o&&t.jsx("a",{className:"ds-backlink",href:o,children:c})]}):i?t.jsxs(ee,{className:"ds-page ds-missing",children:[t.jsx("div",{className:"ds-missing-note",children:i}),o&&t.jsx("a",{className:"ds-backlink",href:o,children:c})]}):t.jsxs(ee,{className:"ds-page",children:[t.jsxs("header",{className:"ds-head",children:[u&&t.jsx("a",{className:"ds-back",href:u,"data-tip":d,"aria-label":d,children:t.jsx(V,{name:"arrow-left",size:16})}),t.jsxs("h1",{className:"ds-title",children:[e,s&&t.jsx("span",{className:"ds-title-meta",children:s})]})]}),a&&t.jsx("div",{className:"ds-status",children:a}),t.jsxs("div",{className:"ds-cols",children:[t.jsxs("div",{className:"ds-main",children:[v,r&&t.jsx("div",{className:"ds-compose",children:r})]}),t.jsx("aside",{className:"ds-side",children:n})]})]})}function jt({label:e,children:s}){return t.jsxs("div",{className:"ds-side-sec",children:[t.jsx("span",{className:"ds-side-label",children:e}),t.jsx("div",{className:"ds-side-body",children:s})]})}function Us({text:e,tip:s,dim:a=!1,mono:n=!1,href:r=null,external:i=!1,onClick:l=null,className:o="",lead:c=null,trail:u=null,label:d=null}){const v=`ds-val${a?" dim":""}${n?" mono":""}${r||l?" link":""}${o?` ${o}`:""}`,h=s??(typeof e=="string"?e:void 0),m=d?{"aria-label":d}:{},w=t.jsxs(t.Fragment,{children:[c,t.jsx("span",{className:"ds-val-text",children:e}),u]});return r?t.jsx("a",{className:v,href:r,"data-tip":h,...m,...i?{target:"_blank",rel:"noreferrer"}:{},children:w}):l?t.jsx("button",{type:"button",className:v,onClick:l,"data-tip":h,...m,children:w}):t.jsx("span",{className:v,"data-tip":h,children:w})}function Bs(e){var s,a;return((s=e==null?void 0:e.verdict)==null?void 0:s.status)==="pass"?"check":((a=e==null?void 0:e.verdict)==null?void 0:a.status)==="fail"?"cross":null}function ts(e){const s=Bs(e);return s?e.fresh?s==="cross"?"fail":"pass":s==="cross"?"staleFail":"stalePass":"empty"}function Hs(e,s){if(!e)return[];const a=new Map;for(const n of s||[])a.has(n.scenario)||a.set(n.scenario,n);return e.map(n=>{const r=a.get(n.name)||null;return{...n,reading:r,state:r?ts(r):"missing"}})}function Ws(e){return e.length?e.some(s=>s.state==="fail")?"fail":e.some(s=>s.state==="staleFail")?"staleFail":e.some(s=>s.state==="stalePass")?"stalePass":e.some(s=>s.state==="empty"||s.state==="missing")?"empty":"pass":null}const Gs=e=>e.fail>0?"fail":e.staleFail>0?"staleFail":e.stalePass>0?"stalePass":e.empty>0?"empty":"pass";function Qs({scenarios:e,evals:s,summary:a=null,href:n}){const r=C(),i=a?null:Hs(e,s),l=(a==null?void 0:a.total)??i.length;if(!l)return null;const o=a?Gs(a):Ws(i),c=(a==null?void 0:a.pass)??i.filter(h=>h.state==="pass").length,u=r("score.count",{satisfied:c,total:l,outstanding:l-c}),d=t.jsxs(t.Fragment,{children:[t.jsx(V,{name:"check",size:11}),c,"/",l]});if(!n)return t.jsx("span",{className:`scenario-count ${o}`,"data-tip":u,"aria-label":u,children:d});const v=`${u} — ${r("score.openList")}`;return t.jsx("a",{className:`scenario-count ${o}`,href:n,"data-tip":v,"aria-label":v,children:d})}function Z({kind:e,state:s,cls:a,n,label:r}){return t.jsxs("span",{className:`ovc ${a}`,"data-tip":r,children:[t.jsx(je,{kind:e,state:s,title:r,size:11}),n]})}function Ys({tags:e}){return e!=null&&e.length?t.jsx("span",{className:"tag-chips",children:e.map(s=>t.jsx("span",{className:"tag-chip",children:s},s))}):null}function as({state:e,title:s}){return e?t.jsx(je,{kind:"eval",state:e,title:s,className:`score-badge ${e}`,size:14}):null}const yt={merged:{color:"#859900"},active:{color:"#cb4b16"},drift:{color:"#b58900"},pending:{color:"#93a1a1"}},Zs={added:"+",edited:"~",deleted:"✕",moved:"→"},q={working:"var(--green)",parked:"var(--green)",asking:"var(--yellow)",review:"var(--yellow)",done:"var(--yellow)",error:"var(--red)",idle:"var(--muted)",starting:"var(--muted)",queued:"var(--muted)","close-pending":"var(--muted)",offline:"var(--muted)",unknown:"var(--yellow)"},Js={working:"●",parked:"‖",asking:"?",review:"◑",done:"✓",error:"✕",idle:"·",starting:"◌",queued:"⋯","close-pending":"⊘",offline:"○",unknown:"⁇"},rs=new Set(["asking","review","done","close-pending","error"]),ne=e=>(e==null?void 0:e.liveness)==="offline"||(e==null?void 0:e.status)==="offline"?"offline":rs.has(e==null?void 0:e.status)?"need":"run",Xs=(e,s)=>{const a=s?(e||[]).find(n=>n.id===s):null;return a&&ne(a)!=="offline"?a:null},Ee=e=>(e==null?void 0:e.sortKey)!=null?e.sortKey:(e==null?void 0:e.created)??0,Le=e=>{const s={need:0,run:1,offline:2};return[...e].sort((a,n)=>s[ne(a)]-s[ne(n)]||Ee(n)-Ee(a))},en=e=>(e==null?void 0:e.label)||(e==null?void 0:e.name)||(e==null?void 0:e.node)||(e==null?void 0:e.title)||(e==null?void 0:e.branch)||(e==null?void 0:e.id),ls=e=>(e==null?void 0:e.headline)||(e==null?void 0:e.name)||(e==null?void 0:e.activity)||(e==null?void 0:e.promptPreview)||(e==null?void 0:e.node)||(e==null?void 0:e.title)||(e==null?void 0:e.branch)||(e==null?void 0:e.id);function sn(e){const s=new Set(e.map(r=>r==null?void 0:r.id)),a=new Map,n=[];for(const r of e){const i=r!=null&&r.parent&&r.parent!==r.id&&s.has(r.parent)?r.parent:null;if(i){const l=a.get(i)||[];l.push(r),a.set(i,l)}else n.push(r)}return{roots:n,childrenOf:a}}function bt(e,s){const a=new Map(e.map(l=>[l==null?void 0:l.id,l])),n=[],r=new Set([s]);let i=a.get(s);for(;i!=null&&i.parent&&!r.has(i.parent);){const l=a.get(i.parent);if(!l)break;n.push(l.id),r.add(l.id),i=l}return n}function nn(e,s){let a=!1,n=!1,r=0;const i=(l,o)=>{for(const c of s.get(l)||[])o.has(c.id)||(o.add(c.id),r++,rs.has(c.status)?a=!0:q[c.status]===q.working&&(n=!0),i(c.id,o))};return i(e,new Set([e])),{color:a?q.asking:n?q.working:q.idle,count:r}}function tn(e,s){const{roots:a,childrenOf:n}=sn(e),r=[],i=(c,u,d,v)=>{const h=n.get(c.id)||[],m=h.length>0,w=m&&!!s(c.id),x=m?nn(c.id,n):null;if(r.push({type:"row",s:c,depth:u,expandable:m,expanded:w,rollup:(x==null?void 0:x.color)??null,kin:(x==null?void 0:x.count)??0,guides:v}),w){const f=Le(h).filter(b=>!d.has(b.id));f.forEach((b,k)=>{d.add(b.id),i(b,u+1,d,[...v,k<f.length-1])})}},l=new Set;let o=null;for(const c of Le(a)){if(l.has(c.id))continue;l.add(c.id);const u=ne(c);u!==o&&(r.push({type:"zone",zone:u}),o=u),i(c,0,l,[])}return r}const oe=Object.freeze({RESULT:"result",BLIND:"blind",UNMEASURED:"unmeasured",DANGLING:"dangling"}),is=e=>{var s;return(s=e==null?void 0:e.evidence)!=null&&s.length?e.evidence:(e==null?void 0:e.blob)!=null?[{hash:e.blob,kind:e.blobKind||"image",state:e.blobState||"present"}]:[]},Nt=e=>{const s=is(e);return s.length?["video","image","transcript","data"].filter(a=>s.some(n=>n.kind===a)):["note"]},kt=e=>String(e||"").length>22?`${String(e).slice(0,8)}…`:e;function os(e,s,a){return a.map(n=>n==="section"?e.section:e.facets[n]).filter(n=>{var r;return(n==null?void 0:n.meaningful)!==!1&&(((r=n==null?void 0:n.options)==null?void 0:r.length)>1||(n==null?void 0:n.value)!=null&&n.value!==""&&n.value!=="all")}).map(n=>({key:n.key,label:n.label,value:n.value,active:n.value!=null&&n.value!==""&&n.value!=="all",options:n.options,clearLabel:n.value==="all"?null:void 0,onChange:r=>s({[n.key]:r||null})}))}const B=e=>ve(`/api/evidence/${e}`);function an({src:e,alt:s,onClose:a}){return p.useEffect(()=>{const n=r=>{r.key==="Escape"&&(r.preventDefault(),r.stopPropagation(),a())};return window.addEventListener("keydown",n,!0),()=>window.removeEventListener("keydown",n,!0)},[a]),t.jsx("div",{className:"lightbox",onClick:a,children:t.jsx("img",{src:e,alt:s})})}function rn({hash:e}){const s=C(),[a,n]=p.useState(null);return p.useEffect(()=>{let r=!0;return fetch(B(e)).then(i=>i.ok?i.text():Promise.reject(new Error("miss"))).then(i=>{r&&n(i)}).catch(()=>{r&&n("")}),()=>{r=!1}},[e]),a===null?t.jsx("pre",{className:"eval-transcript loading",children:s("nodeView.eval.loadingTranscript")}):t.jsx("pre",{className:"eval-transcript",children:a})}function ln({hash:e,collapsed:s=!1}){const a=C(),[n,r]=p.useState(null);if(p.useEffect(()=>{let l=!0;return fetch(B(e)).then(o=>o.ok?o.text():Promise.reject(new Error("miss"))).then(o=>{let c=o,u=!0;try{c=JSON.stringify(JSON.parse(o),null,2)}catch{u=!1}l&&r({text:c,valid:u})}).catch(()=>{l&&r({text:"",valid:!1})}),()=>{l=!1}},[e]),n===null)return t.jsx("pre",{className:"eval-data loading",children:a("nodeView.eval.loadingData")});const i=n.valid?a("nodeView.eval.data"):a("nodeView.eval.dataInvalid");return s?t.jsxs("details",{className:"eval-datawrap eval-datafold",children:[t.jsx("summary",{className:"eval-datahead",children:i}),t.jsx("pre",{className:"eval-data",children:n.text})]}):t.jsxs("div",{className:"eval-datawrap",children:[t.jsx("div",{className:"eval-datahead",children:i}),t.jsx("pre",{className:"eval-data",children:n.text})]})}function on({hash:e,alt:s}){const[a,n]=p.useState(!1);return t.jsxs(t.Fragment,{children:[t.jsx("img",{className:"an-image",src:B(e),alt:s,loading:"lazy",onClick:()=>n(!0)}),a&&t.jsx(an,{src:B(e),alt:s,onClose:()=>n(!1)})]})}function cn({exit:e}){return t.jsx(V,{name:e?"minimize":"maximize",size:15})}function St({target:e,className:s=""}){const a=C(),[n,r]=p.useState(!1);p.useEffect(()=>{const l=()=>{const o=document.fullscreenElement,c=e==null?void 0:e.current;r(!!o&&!!c&&(o===c||c.contains(o)))};return document.addEventListener("fullscreenchange",l),()=>document.removeEventListener("fullscreenchange",l)},[e]);const i=()=>{var o,c;const l=e==null?void 0:e.current;l&&(document.fullscreenElement?(o=document.exitFullscreen||document.webkitExitFullscreen)==null||o.call(document):(c=l.requestFullscreen||l.webkitRequestFullscreen)==null||c.call(l))};return t.jsx("button",{type:"button",className:`an-fs ${s}`,onClick:i,"data-tip":a(n?"annotator.exitFullscreen":"annotator.fullscreen"),"aria-label":a(n?"annotator.exitFullscreen":"annotator.fullscreen"),children:t.jsx(cn,{exit:n})})}function cs({e,alt:s="",collapsed:a=!1}){const n=C();return e.state==="miss"?t.jsx("div",{className:"eval-noimg",children:n("nodeView.eval.miss")}):e.kind==="transcript"?t.jsx(rn,{hash:e.hash}):e.kind==="data"?t.jsx(ln,{hash:e.hash,collapsed:a}):e.kind==="video"?t.jsx("video",{className:"eval-video",src:B(e.hash),controls:!0,preload:"metadata",playsInline:!0}):t.jsx(on,{hash:e.hash,alt:s})}const J=new Map;function un(e){const[s,a]=p.useState(()=>J.get(e)??null);return p.useEffect(()=>{if(J.has(e)){a(J.get(e));return}let n=!0;return fetch(B(e),{headers:{Range:"bytes=0-0"}}).then(r=>{const i=r.headers.get("content-type")||"",l=r.ok?{kind:i.startsWith("video/")?"video":i.startsWith("image/")?"image":i.startsWith("application/json")?"data":"transcript",state:"present"}:{kind:"image",state:"miss"};J.set(e,l),n&&a(l)}).catch(()=>{n&&a({kind:"image",state:"miss"})}),()=>{n=!1}},[e]),s}function us({hash:e,alt:s=""}){const a=un(e);return a?t.jsx(cs,{e:{hash:e,...a},alt:s}):null}const $t=/\[\[(\.?[\p{L}\p{N}_-]+)\]\]/gu,ds=e=>(e||"").replace(/^\.spec\//,"").replace(/\/spec\.md$/,"");function dn(e,s,a){const n=s.toLowerCase(),r=[];for(const i of e){const l=i.id.toLowerCase(),o=ds(i.path).toLowerCase();let c;if(!n)c=3;else if(l.startsWith(n))c=0;else if(l.includes(n))c=1;else if(o.includes(n))c=2;else continue;i.id===a&&(c=-1),r.push({s:i,score:c})}return r.sort((i,l)=>i.score-l.score||i.s.id.length-l.s.id.length||i.s.id.localeCompare(l.s.id)),r.slice(0,8).map(i=>i.s)}function hn(e,s){const a=s.toLowerCase(),n=o=>ls(o)||(o.id||"").slice(0,8),r=[];for(const o of e||[]){if(o.liveness!=="online")continue;const c=(o.id||"").toLowerCase(),u=n(o).toLowerCase();let d;if(!a)d=3;else if(c===a||u===a)d=0;else if(c.startsWith(a)||u.startsWith(a))d=1;else if(c.includes(a)||u.includes(a))d=2;else continue;r.push({s:o,score:d})}r.sort((o,c)=>o.score-c.score||(c.s.created||0)-(o.s.created||0));const i=r.map(o=>({id:o.s.id,label:n(o.s),sub:o.s.node||o.s.status})),l=r.filter(o=>o.score===0).length;return i.splice(l,0,{id:"new",label:"new",sub:"choose a launcher"}),i.slice(0,8)}function fn(e,s){const a=s.toLowerCase();return(e||[]).map(n=>{const r=(n.name||"").toLowerCase(),i=a?r.startsWith(a)?0:r.includes(a)?1:-1:1;return{l:n,score:i}}).filter(n=>n.score>=0).sort((n,r)=>n.score-r.score||n.l.name.localeCompare(r.l.name)).slice(0,8).map(({l:n})=>({id:n.name,label:n.name,sub:n.cmd||n.harness||""}))}function se(e,s){if(!s)return e;const a=e.toLowerCase().indexOf(s.toLowerCase());return a<0?e:t.jsxs(t.Fragment,{children:[e.slice(0,a),t.jsx("b",{className:"mention-hit",children:e.slice(a,a+s.length)}),e.slice(a+s.length)]})}function hs(e,s){const a=s.toLowerCase(),n=[];for(const r of e){const i=r.name.toLowerCase();let l;if(!a)l=1;else if(i.startsWith(a))l=0;else if(i.includes(a))l=1;else continue;n.push({c:r,score:l})}return n.sort((r,i)=>r.score-i.score),n.slice(0,10).map(r=>r.c)}function Et(e,s,a){let n=s;for(;n>0&&!/\s/.test(e[n-1]);)n--;if(e[n]!=="/")return null;const r=e.slice(n+1,s),i=hs(a,r);return i.length?{items:i,index:0,start:n,end:s,query:r}:null}const pn=e=>e&&e[0].toUpperCase()+e.slice(1),mn={user:"(user)",project:"(project)",skill:"[skill]","built-in":"built-in",ui:"[ui]",preset:"[preset]",review:"[review]"};function vn({menu:e,up:s,head:a,onPick:n,onHover:r}){const i=C();return t.jsxs("ul",{className:s?"mention-menu up":"mention-menu",role:"listbox",children:[t.jsxs("li",{className:"mention-head",children:["// ",a," — ",i("session.menuHint")]}),e.items.map((l,o)=>{const c=l.ui?"ui":l.source??l.kind,u=l.ui?` sc-${l.color}`:"";return t.jsxs("li",{role:"option","aria-selected":o===e.index,className:`${o===e.index?"mention-item on":"mention-item"}${u}`,onMouseDown:d=>{d.preventDefault(),n(l)},onMouseEnter:()=>r(o),children:[t.jsxs("span",{className:l.ui?"slash-name ui":"slash-name",children:["/",se(l.name,e.query)]}),t.jsx("span",{className:"slash-desc",children:pn(l.description??l.desc)}),t.jsx("span",{className:`slash-src src-${c}`,children:mn[c]||c})]},`${c}:${l.name}`)})]})}function xn(e,s,a,n){let r=s-1;for(;r>=0&&/[\p{L}\p{N}_.\-]/u.test(e[r]);)r--;if(r>=1&&e[r-1]==="["&&e[r]==="["){const i=e.slice(r+1,s),l=dn(a,i,n);return l.length?{kind:"mention",items:l,index:0,start:r-1,end:s,query:i}:null}return null}function Ce(e,s,a,n=[]){let r=s-1;for(;r>=0&&/[\p{L}\p{N}_.:\-]/u.test(e[r]);)r--;if(r>=0&&e[r]==="@"&&(r===0||/\s/.test(e[r-1]))){const i=e.slice(r+1,s);if(i.startsWith("new:")){const o=i.slice(4),c=fn(n,o);return c.length?{kind:"launcher",items:c,index:0,start:r,end:s,query:o}:null}const l=hn(a,i);return l.length?{kind:"actor",items:l,index:0,start:r,end:s,query:i}:null}return null}function gn({menu:e,up:s,fixedStyle:a,onPick:n,onHover:r}){const i=C(),l=e.kind==="launcher",o=e.kind==="actor"||l,c=l?`@new:${e.query}`:e.query?o?`@${e.query}`:`[[${e.query}]]`:i(o?"session.menuSessions":"session.menuSpecNodes");return t.jsxs("ul",{className:`${s?"mention-menu up":"mention-menu"}${a?" fixed":""}`,style:a||void 0,role:"listbox",children:[t.jsxs("li",{className:"mention-head",children:["// ",c," — ",i("session.menuHint")]}),e.items.map((u,d)=>t.jsxs("li",{role:"option","aria-selected":d===e.index,className:`${d===e.index?"mention-item on":"mention-item"}${l||o&&u.id==="new"?" new":""}`,onMouseDown:v=>{v.preventDefault(),n(u)},onMouseEnter:()=>r(d),children:[!o&&t.jsx("span",{className:"mention-dot",style:{background:q[u.status]||q.offline}}),t.jsx("span",{className:"mention-id",children:l?t.jsxs(t.Fragment,{children:["@new:",se(u.label,e.query)]}):o?t.jsxs(t.Fragment,{children:["@",se(u.label,e.query)]}):se(u.id,e.query)}),t.jsx("span",{className:"mention-path",children:o?u.sub:ds(u.path)})]},u.id))]})}function wn({inputRef:e,value:s,setValue:a,specs:n=[],sessions:r=[],launchers:i=[],focusId:l=null,up:o=!1,fixedAbove:c=null}){const[u,d]=p.useState(null),[v,h]=p.useState(null),m=p.useRef(null),w=N=>`${N.value}\0${N.selectionStart}`,x=N=>{var I;if(!N){d(null),h(null);return}const g=w(N);if(m.current===g){d(null),h(null);return}m.current=null;const E=N.selectionStart,R=xn(N.value,E,n,l)||Ce(N.value,E,r,i);if(d(R),!R||!c){h(null);return}const y=N.getBoundingClientRect(),$=(I=N.closest(c))==null?void 0:I.getBoundingClientRect(),A=($==null?void 0:$.top)??y.top;h({left:`${y.left}px`,width:`${y.width}px`,right:"auto",bottom:`${Math.max(8,window.innerHeight-A+8)}px`})};p.useEffect(()=>{const N=e.current;i.length&&N&&document.activeElement===N&&x(N)},[i]);const f=N=>d(g=>g&&{...g,index:(g.index+N+g.items.length)%g.items.length}),b=N=>{if(!N||!u)return;m.current=null;const g=s.slice(0,u.start);if(u.kind==="actor"&&N.id==="new"){const y="@new:",$=g+y+s.slice(u.end),A=g.length+y.length;a($),d(Ce($,A,r,i)),requestAnimationFrame(()=>{const I=e.current;I&&(I.focus(),I.setSelectionRange(A,A))});return}const E=u.kind==="actor"?`@${N.id} `:u.kind==="launcher"?`@new:${N.id} `:`[[${N.id}]] `;a(g+E+s.slice(u.end)),d(null),h(null);const R=g.length+E.length;requestAnimationFrame(()=>{const y=e.current;y&&(y.focus(),y.setSelectionRange(R,R))})};return{menu:u,sync:x,onKeyDown:N=>u?N.key==="ArrowDown"?(N.preventDefault(),N.stopPropagation(),f(1),!0):N.key==="ArrowUp"?(N.preventDefault(),N.stopPropagation(),f(-1),!0):N.key==="Enter"||N.key==="Tab"?(N.preventDefault(),N.stopPropagation(),b(u.items[u.index]),!0):N.key==="Escape"?(N.preventDefault(),N.stopPropagation(),e.current&&(m.current=w(e.current)),d(null),h(null),!0):!1:!1,close:()=>{m.current=null,d(null),h(null)},menuEl:u?t.jsx(gn,{menu:u,up:o,fixedStyle:v,onPick:b,onHover:N=>d(g=>g&&{...g,index:N})}):null}}async function Lt(e,s){try{const a=await fetch(ve("/api/sessions"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,...s?{launcher:s}:{}})}),n=await a.json().catch(()=>null);return{ok:a.ok,error:n==null?void 0:n.error}}catch{return{ok:!1}}}let _=null,X=null;const jn=()=>_?Promise.resolve(_):(X||(X=bs().then(e=>(_=e,e)).catch(e=>{throw X=null,e})),X),Ae=e=>Array.isArray(e==null?void 0:e.launchers)?e.launchers:[],yn=()=>{try{return localStorage.getItem("si.launcher")||""}catch{return""}},De=(e,s,a=yn())=>{var n;return e.some(r=>r.name===a)?a:s&&e.some(r=>r.name===s)?s:((n=e[0])==null?void 0:n.name)||a};function bn(){const e=Ae(_),[s,a]=p.useState(e),[n,r]=p.useState(()=>De(e,_==null?void 0:_.default)),i=l=>{r(l);try{localStorage.setItem("si.launcher",l)}catch{}};return p.useEffect(()=>{jn().then(l=>{const o=Ae(l);o.length&&(a(o),r(c=>De(o,l.default,c)))}).catch(()=>{})},[]),{launchers:s,launcher:n,pickLauncher:i}}function Ct(){const[e,s]=p.useState([]);return p.useEffect(()=>{ys().then(a=>{Array.isArray(a)&&s(a)}).catch(()=>{})},[]),e}function Nn(e,s,a=0){if(!e)return;const n=e.placeholder;!e.value&&n&&(e.placeholder=""),e.style.height="auto",e.style.overflowY=e.scrollHeight>s?"auto":"hidden",e.style.height=`${Math.min(Math.max(e.scrollHeight,a),s)}px`,e.placeholder!==n&&(e.placeholder=n)}function kn(e){var s,a;return e.isComposing||((s=e.nativeEvent)==null?void 0:s.isComposing)||e.keyCode===229||((a=e.nativeEvent)==null?void 0:a.keyCode)===229}const Sn=p.forwardRef(function({value:s,className:a="",...n},r){const i=p.useRef(null);return p.useImperativeHandle(r,()=>i.current),p.useLayoutEffect(()=>{const l=i.current;if(!l)return;const o=getComputedStyle(l);Nn(l,parseFloat(o.maxHeight)||1/0,parseFloat(o.minHeight)||0)},[s]),t.jsx("textarea",{ref:i,value:s,className:`composer-textarea ${a}`.trim(),...n})});function $n({className:e="",preview:s=null,editor:a,footer:n,...r}){return t.jsxs("div",{className:`composer-surface ${e}`.trim(),...r,children:[s,t.jsx("div",{className:"composer-editor",children:a}),t.jsx("div",{className:"composer-footer",children:n})]})}const En=/^▶\s*(\d+):([0-5]?\d)(?:\s*·\s*([^\n]*))?/,Re=/^!\[frame\]\(\/api\/(?:evidence|yatsu\/blob)\/[0-9a-f]{64}\)\n?/,Ln=/\/api\/(?:evidence|yatsu\/blob)\/([0-9a-f]{64})/g,Ie=/!\[[^\]]*\]\(\/api\/(?:evidence|yatsu\/blob)\/([0-9a-f]{64})\)/g,Cn=e=>{const s=Math.floor(e/1e3);return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`};function pe(e){var i;const s=e||"",a=s.split(`
2
- `,1)[0],n=En.exec(a);return n?{tMs:(parseInt(n[1],10)*60+parseInt(n[2],10))*1e3,step:((i=n[3])==null?void 0:i.trim())||null,label:a.trim(),rest:s.slice(a.length).replace(/^\n/,"")}:null}const fs=(e,s)=>`▶${Cn(e)}${s?` · ${s}`:""}`,Te=e=>[...(e||"").matchAll(Ln)].map(s=>s[1]);function An(e,s){if(!e)return null;if(e.step&&(s!=null&&s.length)){const a=s.find(n=>n.step===e.step);return a?{tMs:a.at,step:e.step,label:fs(a.at,e.step),seekable:!0,degraded:!1}:{tMs:e.tMs,step:e.step,label:e.label,seekable:!1,degraded:!0}}return{tMs:e.tMs,step:e.step,label:e.label,seekable:!0,degraded:!1}}function At({originator:e,sessions:s=[],kind:a="issue",onOpenSession:n=null}){const r=C();if(!e)return null;const i=Xs(s,e),l=!!i,o=l?q[i.status]||q.working:q.offline,c=r(a==="eval"?"thread.originatorEval":"thread.originatorIssue",{by:e}),u=t.jsx("span",{className:"fv-originator-dot",style:{background:o},"aria-hidden":"true"});return t.jsx(Us,{text:e,tip:c,label:c,lead:u,className:`fv-originator ${l?"alive":"offline"}${l&&n?" openable":""}`,onClick:l&&n?()=>n(e):null})}function Dn({replies:e,onSeek:s,selIdx:a=null,activeIdx:n=null,onSelect:r=null,events:i=null,threadId:l=null,onRemarkChange:o=null}){const c=C(),[u,d]=p.useState(null),[v,h]=p.useState(null),m=async(w,x)=>{if(!u){d(x),h(null);try{const f=await Ns(w,x);f!=null&&f.ok?await(o==null?void 0:o()):h({ref:x,msg:(f==null?void 0:f.error)||`${w} failed`})}finally{d(null)}}};return e.map((w,x)=>{const f=pe(w.body),b=An(f,i),k=f?f.rest:w.body,S=[...k.matchAll(Ie)].map($=>$[1]),D=(S.length?k.replace(Ie,""):k).trim(),N=w.rid!==void 0,g=N?w.resolved?" remark resolved":" remark open":"",E=`fv-reply${a===x?" sel":""}${n===x?" active":""}${g}`,R=b&&b.seekable&&s?()=>r?r(x,b.tMs):s(b.tMs):null,y=N&&l?`${l}#${w.rid}`:null;return t.jsxs("div",{className:E,children:[t.jsxs("div",{className:"fv-reply-meta",children:[t.jsx("span",{className:"fv-reply-by",children:w.by}),w.at&&t.jsx("span",{className:"fv-reply-at",children:w.at}),b&&(R?t.jsx("button",{type:"button",className:"fv-anchor",onClick:R,"data-tip":"seek the clip to this moment",children:b.label}):t.jsxs("span",{className:`fv-anchor static${b.degraded?" degraded":""}`,"data-tip":b.degraded?c("thread.anchorDegraded"):void 0,children:[b.label,b.degraded?" ⚠":""]})),N&&(w.resolved?t.jsxs("span",{className:"fv-remark-state resolved","data-tip":w.resolvedBy?c("thread.resolvedBy",{by:w.resolvedBy}):c("thread.resolved"),children:["✓ ",c("thread.resolved")]}):t.jsxs("span",{className:"fv-remark-state open","data-tip":c("thread.openRemark"),children:["● ",c("thread.openRemark")]})),y&&o&&!w.resolved&&(w.by==="human"?t.jsx("button",{type:"button",className:"fv-remark-act retract",disabled:!!u,"data-tip":c("thread.retractTitle"),onClick:()=>m("retract",y),children:c("thread.retract")}):t.jsx("button",{type:"button",className:"fv-remark-act resolve",disabled:!!u,"data-tip":c("thread.resolveTitle"),onClick:()=>m("resolve",y),children:c("thread.resolve")}))]}),v&&v.ref===y&&t.jsx("div",{className:"fv-error",children:v.msg}),D&&t.jsx("div",{className:"fvd-body",children:t.jsx(te,{body:D})}),S.length>0&&t.jsx("div",{className:"fv-reply-media",children:S.map(($,A)=>t.jsx(us,{hash:$,alt:"evidence"},`${$}-${A}`))})]},x)})}function Rn(e,s,a){const n=e.lastIndexOf(`
3
- `,s-1)+1,r=/^\/(\S*)$/.exec(e.slice(n,s));if(!r)return null;const i=hs(a,r[1]);return i.length?{items:i,index:0,start:n,end:s,query:r[1]}:null}function Dt({onSend:e,specs:s=[],sessions:a=[],focusId:n=null,onDone:r,anchorNow:i=null,draft:l=null,actionsEnd:o=null,commands:c=null}){const u=C(),[d,v]=p.useState(""),[h,m]=p.useState(!1),[w,x]=p.useState(""),f=p.useRef(null),{launchers:b}=bn(),k=wn({inputRef:f,value:d,setValue:v,specs:s,sessions:a,launchers:b,focusId:n,up:!0}),[S,D]=p.useState(null),N=j=>D(j&&(c!=null&&c.length)?Rn(j.value,j.selectionStart,c):null),g=j=>{var O;if(!j||!S)return;const L=d.slice(0,S.start)+d.slice(S.end);if(D(null),j.run){v(L.trim()?L:""),j.run();return}const M=pe(L);let K="";if(M){const T=((O=Re.exec(M.rest))==null?void 0:O[0])??"";K=`${M.label}
4
- ${T}`,K.endsWith(`
5
- `)||(K+=`
6
- `)}v(K+j.prefill()),requestAnimationFrame(()=>{const T=f.current;T&&(T.focus(),T.setSelectionRange(T.value.length,T.value.length))})},E=j=>S?j.key==="ArrowDown"?(j.preventDefault(),j.stopPropagation(),D(L=>({...L,index:(L.index+1)%L.items.length})),!0):j.key==="ArrowUp"?(j.preventDefault(),j.stopPropagation(),D(L=>({...L,index:(L.index-1+L.items.length)%L.items.length})),!0):j.key==="Enter"||j.key==="Tab"?(j.preventDefault(),j.stopPropagation(),g(S.items[S.index]),!0):j.key==="Escape"?(j.preventDefault(),j.stopPropagation(),D(null),!0):!1:!1,R=Te(d);p.useEffect(()=>{var j;if(!l){v("");return}v(l.body||""),(j=f.current)==null||j.focus()},[l==null?void 0:l.seq]);const y=async()=>{var M;const j=await(i==null?void 0:i());if(!j)return;const L=fs(j.tMs,j.step)+(j.frame?`
7
- ![frame](/api/evidence/${j.frame})`:"");v(K=>{const O=pe(K),T=(O?O.rest:K).replace(Re,"");return T?`${L}
8
- ${T}`:`${L}
9
- `}),(M=f.current)==null||M.focus()},$=j=>{const L=f.current;if(!L||h)return;const M=L.selectionStart??d.length,K=L.selectionEnd??M;v(d.slice(0,M)+j+d.slice(K));const O=M+j.length;requestAnimationFrame(()=>{const T=f.current;T&&(T.focus(),T.setSelectionRange(O,O),k.sync(T),N(T))})},A=async()=>{const j=d.trim();if(!(!j||h)){m(!0);try{const L=await e(j,Te(j));L!=null&&L.ok?(v(""),x(""),await(r==null?void 0:r(L.outcomes||""))):x((L==null?void 0:L.error)||"reply failed")}finally{m(!1)}}},I=R.length>0?t.jsx("div",{className:"fv-frames",children:R.map(j=>t.jsx(us,{hash:j,alt:"frame"},j))}):null,U=t.jsxs("div",{className:"fv-tawrap",children:[t.jsx(Sn,{ref:f,className:"fv-textarea",rows:1,value:d,placeholder:u("session.issuesReplyPlaceholder"),disabled:h,onChange:j=>{v(j.target.value),k.sync(j.target),N(j.target)},onSelect:j=>{k.sync(j.target),N(j.target)},onBlur:()=>{k.close(),D(null)},onKeyDown:j=>{kn(j)||E(j)||k.onKeyDown(j)||j.key==="Enter"&&(j.metaKey||j.ctrlKey)&&(j.preventDefault(),A())}}),k.menuEl,S&&t.jsx(vn,{menu:S,up:!0,head:S.query?`/${S.query}`:u("annotator.menuReview"),onPick:g,onHover:j=>D(L=>L&&{...L,index:j})})]}),F=t.jsxs("div",{className:"fv-actions",children:[t.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":u("thread.mentionActor"),"aria-label":u("thread.mentionActor"),onMouseDown:j=>j.preventDefault(),onClick:()=>$("@"),children:"@"}),t.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":u("thread.mentionNode"),"aria-label":u("thread.mentionNode"),onMouseDown:j=>j.preventDefault(),onClick:()=>$("[["),children:"[["}),(c==null?void 0:c.length)>0&&t.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":u("thread.reviewCommands"),"aria-label":u("thread.reviewCommands"),onMouseDown:j=>j.preventDefault(),onClick:()=>$("/"),children:"/"}),i&&t.jsxs("button",{type:"button",className:"fv-anchor-btn","data-tip":u("thread.anchorTitle"),onMouseDown:j=>j.preventDefault(),onClick:y,children:[t.jsx(V,{name:"clock",size:11})," ",u("thread.anchorNow")]}),w&&t.jsx("span",{className:"fv-error",children:w}),t.jsxs("div",{className:"fv-actions-end",children:[o,t.jsx(me,{icon:"send",size:14,className:"fv-send",label:u(h?"session.issuesSending":"session.issuesSend"),disabled:h||!d.trim(),onMouseDown:j=>j.preventDefault(),onClick:A})]})]});return t.jsx($n,{className:"fv-compose",preview:I,editor:U,footer:F})}const In=["graph","sessions","evals","issues","settings"],Pe=["q","page"];function Tn(e){if(!e)return"";const s=new URLSearchParams;for(const n of Pe)e[n]!=null&&e[n]!==""&&s.set(n,e[n]);for(const n of Object.keys(e).filter(r=>!Pe.includes(r)).sort())e[n]!=null&&e[n]!==""&&s.set(n,e[n]);const a=s.toString().replace(/\+/g,"%20");return a?`?${a}`:""}function G(e){const s=(e||"").replace(/^#\/?/,""),a=s.indexOf("?"),n=a>=0?s.slice(0,a):s,r=Object.fromEntries(new URLSearchParams(a>=0?s.slice(a+1):"")),i=n.split("/").filter(Boolean),l=In.includes(i[0])?i[0]:"graph",o=(l==="sessions"||l==="evals"||l==="issues")&&i.length>1?i.slice(1).map(decodeURIComponent).join("/"):null;return{page:l,param:o,query:r}}function Pn(e){const n=(e||"").replace(/^#\/?/,"").split("?")[0].split("/").filter(Boolean);if(n[0]!=="sessions"||n[2]!=="eval")return null;const r=decodeURIComponent(n[1]||"");if(!r)return null;const i=n[3]?decodeURIComponent(n[3]):null,l=n.length>4?n.slice(4).map(decodeURIComponent).join("/"):null,o=i&&l?`${i}/${l}`:null;return P("evals",o,{q:o?`scope:${r}`:He(r)})}function Vn(e){const{page:s,param:a,query:n}=G(e);if(s!=="evals"&&s!=="issues"||!Je(n))return null;if(a!=null)return P(s,a,n.session?{q:`scope:${n.session}`}:null);const r=s==="issues"?Ls:ae,i=Rs(r,n);return P(s,null,Ye(i,r)?null:{q:i})}function Fn(e){const{page:s,param:a,query:n}=G(e);if(s!=="evals"&&s!=="issues"||a!=null||n.page==null||/^[1-9]\d*$/.test(n.page)&&Number.isSafeInteger(Number(n.page)))return null;const{page:r,...i}=n;return P(s,null,i)}const P=(e,s,a=null)=>`#/${e}${s?`/${String(s).split("/").map(encodeURIComponent).join("/")}`:""}${Tn(a)}`;function ce(e,s=null,{replace:a=!1,query:n=null}={}){const r=P(e,s,n);window.location.hash!==r&&(a?(window.history.replaceState(null,"",r),window.dispatchEvent(new HashChangeEvent("hashchange"))):window.location.hash=r)}const Ve=()=>{const e=Pn(window.location.hash)||Vn(window.location.hash)||Fn(window.location.hash);return e?(window.history.replaceState(null,"",e),G(e)):G(window.location.hash)};function Rt(){const[e,s]=p.useState(Ve);return p.useEffect(()=>{const a=()=>s(Ve());return window.addEventListener("hashchange",a),()=>window.removeEventListener("hashchange",a)},[]),e}const It=e=>({kind:"graph-node",nodeId:e}),Tt=e=>({kind:"session",sessionId:e}),qn=e=>({kind:"issue",issueId:e}),ps=(e,s)=>({kind:"review-list",page:e,query:s}),ms=(e,s=null)=>({kind:"eval",nodeId:e,scenario:s}),Mn=(e,s,a)=>({kind:"session-eval",sessionId:e,nodeId:s,scenario:a});function z(e){if(!e||e.kind==="graph-node")return P("graph");if(e.kind==="session")return P("sessions",e.sessionId);if(e.kind==="session-eval"){const s=e.nodeId&&e.scenario?`${e.nodeId}/${e.scenario}`:null;return P("evals",s,{q:s?`scope:${e.sessionId}`:He(e.sessionId)})}return e.kind==="issue"?P("issues",e.issueId):e.kind==="review-list"?P(e.page,null,e.query?{q:e.query}:null):e.kind==="eval"?e.scenario?P("evals",`${e.nodeId}/${e.scenario}`):P("evals",null,{q:Cs(e.nodeId)}):P("graph")}function Pt(e,s=null){return e==="issues"?P("issues"):s?z(Mn(s)):P("evals")}function Vt(e,{onFocusNode:s,onOpenSession:a}={}){if(e)if(e.kind==="graph-node")s==null||s(e.nodeId),ce("graph");else if(e.kind==="session")a?a(e.sessionId):ce("sessions",e.sessionId);else{const{page:n,param:r,query:i}=G(z(e));ce(n,r,{query:i})}}function Fe({issue:e,onNavigateAddress:s}){const a=(e==null?void 0:e.store)||"local",n=(e==null?void 0:e.status)||"open",r=qn(e.id);return t.jsxs("a",{className:"issue-card",href:z(r),"data-tip":e.concern||e.id,onClick:s?i=>{i.defaultPrevented||i.button!==0||i.metaKey||i.ctrlKey||i.shiftKey||i.altKey||(i.preventDefault(),s(r))}:void 0,children:[t.jsxs("span",{className:"issue-card-top",children:[t.jsx("span",{className:"issue-num",children:e.id}),t.jsx("span",{className:`fv-store fv-store-${a==="local"?"local":"forge"}`,children:a}),t.jsx(je,{kind:"issue",state:n,showLabel:!0,size:12,className:"issue-card-state"})]}),t.jsx("span",{className:"issue-card-title",children:e.concern})]})}const qe=[{key:"spec",label:"spec"},{key:"history",label:"history"},{key:"issues",label:"issues"},{key:"eval",label:"eval"}];function Kn(e){var s;return(s=e==null?void 0:e.overlays)!=null&&s.length?[{key:"edit",label:"edit"},...qe]:qe}const vs=(e,s,a={})=>{let n=`${e==="issue"?"is:issue":ae}${a.q?` ${String(a.q).trim()}`:""}`.trim();const r=e==="issue"?{state:"state",author:"author",store:"store",session:"session"}:{verdict:"verdict",review:"state",freshness:"freshness",kind:"evidence",filer:"filer",session:"session"};for(const[i,l]of Object.entries(r))a[i]&&(n=W(n,l,a[i]));return W(n,"node",s)},On={state:"reviewList.facetState",verdict:"reviewList.facetVerdict",author:"reviewList.facetAuthor",store:"reviewList.facetStore",review:"reviewList.facetReview",freshness:"reviewList.facetFreshness",kind:"reviewList.facetKind",filer:"reviewList.facetFiler",session:"reviewList.facetSession"},xs=(e,s)=>{const a=n=>n&&{...n,label:s(On[n.key]||n.label||n.key)};return{section:a(e==null?void 0:e.section),facets:Object.fromEntries(Object.entries((e==null?void 0:e.facets)||{}).map(([n,r])=>[n,a(r)]))}},_n={added:"+",edited:"~",deleted:"✕",moved:"→"};function H(e){const s=[],a=/`([^`]+)`|\*\*([^*]+)\*\*|\[\[([^\]]+)\]\]/g;let n=0,r,i=0;for(;r=a.exec(e);)r.index>n&&s.push(e.slice(n,r.index)),r[1]!=null?s.push(t.jsx("code",{children:r[1]},i++)):r[2]!=null?s.push(t.jsx("strong",{children:r[2]},i++)):s.push(t.jsx("span",{className:"doc-link",children:r[3]},i++)),n=a.lastIndex;return n<e.length&&s.push(e.slice(n)),s}function Me(e){const s=e.trim();return s.includes("|")&&/^\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/.test(s)}function ue(e){let s=e.trim();return s.startsWith("|")&&(s=s.slice(1)),s.endsWith("|")&&(s=s.slice(0,-1)),s.split("|").map(a=>a.trim())}function zn(e){const s=e.startsWith(":"),a=e.endsWith(":");return s&&a?"center":a?"right":null}function te({body:e}){if(!e)return null;const s=e.replace(/^#\s+[^\n]*\n+/,"").split(`
10
- `),a=[];let n=0,r=0;for(;n<s.length;){const i=s[n].trim();if(/^```/.test(i)){const l=[];for(n++;n<s.length&&!/^```/.test(s[n].trim());)l.push(s[n++]);n++,a.push(t.jsx("pre",{className:"doc-pre",children:t.jsx("code",{children:l.join(`
11
- `)})},r++))}else if(/^#{1,6}\s+/.test(s[n]))a.push(t.jsx("h4",{className:"doc-h",children:H(s[n].replace(/^#+\s+/,""))},r++)),n++;else if(i.includes("|")&&n+1<s.length&&Me(s[n+1])){const l=ue(s[n]),o=ue(s[n+1]).map(zn);n+=2;const c=[];for(;n<s.length&&s[n].includes("|")&&s[n].trim()!==""&&!/^```/.test(s[n].trim());)c.push(ue(s[n])),n++;a.push(t.jsxs("table",{className:"doc-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:l.map((u,d)=>t.jsx("th",{style:o[d]?{textAlign:o[d]}:void 0,children:H(u)},d))})}),t.jsx("tbody",{children:c.map((u,d)=>t.jsx("tr",{children:l.map((v,h)=>t.jsx("td",{style:o[h]?{textAlign:o[h]}:void 0,children:H(u[h]??"")},h))},d))})]},r++))}else if(/^-\s+/.test(i)){const l=[];for(;n<s.length&&/^-\s+/.test(s[n].trim());)l.push(s[n++].trim().replace(/^-\s+/,""));a.push(t.jsx("ul",{children:l.map((o,c)=>t.jsx("li",{children:H(o)},c))},r++))}else if(i==="")n++;else{const l=[];for(;n<s.length;){const o=s[n];if(o.trim()===""||/^```/.test(o.trim())||/^#{1,6}\s+/.test(o)||/^-\s+/.test(o.trim())||o.includes("|")&&n+1<s.length&&Me(s[n+1]))break;l.push(o),n++}a.push(t.jsx("p",{children:H(l.join(" "))},r++))}}return t.jsx("div",{className:"doc-body",children:a})}function Ke({kind:e,title:s,owner:a,ownerLabel:n,note:r,children:i}){return t.jsxs("section",{className:`spec-part part-${e}`,children:[t.jsxs("header",{className:"part-head",children:[t.jsx("span",{className:"part-title",children:s}),t.jsx("span",{className:`part-owner owner-${a}`,children:n}),r&&t.jsx("span",{className:"part-note",children:r})]}),t.jsx("div",{className:"part-body",children:i})]})}function Un({parts:e}){const s=C();return t.jsxs("div",{className:"spec-parts",children:[t.jsx(Ke,{kind:"raw",title:s("nodeView.rawTitle"),owner:"human",ownerLabel:s("nodeView.rawOwner"),note:s("nodeView.rawNote"),children:t.jsx(te,{body:e.rawSource})}),t.jsx(Ke,{kind:"expanded",title:s("nodeView.expandedTitle"),owner:"agent",ownerLabel:s("nodeView.expandedOwner"),note:s("nodeView.expandedNote"),children:t.jsx(te,{body:e.expandedSpec})})]})}const de=new Map;function Bn(e,s){const a=`${e}@${s??""}`,[n,r]=p.useState(()=>de.get(a)??null);return p.useEffect(()=>{const i=de.get(a);if(i){r(i);return}r(null);let l=!0;return fetch(xe(e,"content")).then(o=>o.ok?o.json():Promise.reject(o.status)).then(o=>{de.set(a,o),l&&r(o)}).catch(()=>{l&&r({body:"",parts:null})}),()=>{l=!1}},[e,s,a]),n}function Hn({node:e}){var r,i;const s=C(),a=Bn(e.id,e.version),n=(e.driftFiles||[]).map(l=>`${l.file}: ${s("specNode.driftAhead",{n:l.behind})}`).join(`
12
- `);return t.jsxs("div",{className:"pane-doc",children:[t.jsxs("h1",{children:["# ",e.title]}),t.jsx("blockquote",{children:e.desc}),t.jsxs("div",{className:"doc-stat",children:[t.jsxs("span",{className:`stat-status st-${e.status}`,"data-tip":s("nodeView.statusLabel"),children:[t.jsx("i",{className:"stat-dot"}),s(`status.${e.status}`)]}),t.jsxs("span",{className:"stat-chip","data-tip":s("nodeView.versionLabel"),children:["v",e.version||0]}),t.jsx(Qs,{summary:(r=e.reviewSummary)==null?void 0:r.evals,href:z(ms(e.id))}),e.drift>0&&t.jsxs("span",{className:"stat-chip stat-drift","data-tip":n,children:["⚠",e.drift]}),t.jsxs("span",{className:"stat-sess","data-tip":s("nodeView.lastEditedBy"),children:["✎ ",t.jsx("b",{children:e.session||s("common.none")})]})]}),((i=e.code)==null?void 0:i.length)>0?t.jsxs("div",{className:"doc-gov",children:[t.jsxs("span",{className:"doc-gov-h",children:[s("nodeView.governs")," ",t.jsx("b",{children:e.code.length})]}),t.jsx("div",{className:"doc-gov-files",children:e.code.map(l=>t.jsx("code",{className:"gov-f",children:l},l))})]}):t.jsx("div",{className:"doc-gov prose",children:t.jsx("span",{className:"doc-gov-h",children:s("nodeView.proseNode")})}),(()=>{if(a===null&&e.body==null)return t.jsx("div",{className:"pane-loading",children:t.jsx("span",{className:"spinner","aria-label":s("common.loading")})});const l=e.body??(a==null?void 0:a.body)??"",o=e.parts??(a==null?void 0:a.parts)??null;return o?t.jsx(Un,{parts:o}):t.jsx(te,{body:l})})()]})}function Wn(e,s=!0){const[a,n]=p.useState(null);return p.useEffect(()=>{if(!s)return;let r=!0;return fetch(xe(e,"history")).then(i=>i.json()).then(i=>{r&&n(i)}).catch(()=>r&&n([])),()=>{r=!1}},[e,s]),a}const he=new Map;function Gn(e,s,a){const n=`${e}/${s}`,[r,i]=p.useState(()=>he.get(n)??null);return p.useEffect(()=>{const l=he.get(n);if(l){i(l);return}let o=!0;return fetch(xe(e,"diff",s)).then(c=>c.json()).then(c=>{he.set(n,c),o&&i(c)}).catch(()=>o&&i({patch:""})),()=>{o=!1}},[e,s,a,n]),r}function Qn(e){const s=[];let a=!1;for(const n of e.split(`
13
- `)){if(n.startsWith("@@")){a=!0,s.push({t:"hunk",s:n});continue}!a||n.startsWith("\\")||(n.startsWith("+")?s.push({t:"add",s:n.slice(1)}):n.startsWith("-")?s.push({t:"del",s:n.slice(1)}):s.push({t:"ctx",s:n.slice(1)}))}for(;s.length&&s[s.length-1].t==="ctx"&&s[s.length-1].s==="";)s.pop();return s}function gs({diff:e}){const s=C();if(e==null)return t.jsx("figcaption",{className:"ev-note",children:s("nodeView.loadingChange")});const a=e.patch?Qn(e.patch):[];return a.length?t.jsxs(t.Fragment,{children:[t.jsx("figcaption",{className:"ev-difflabel",children:s("nodeView.diffLabel")}),t.jsx("pre",{className:"ev-diff",children:a.map((n,r)=>t.jsx("div",{className:`dl dl-${n.t}`,children:n.s||" "},r))})]}):t.jsx("figcaption",{className:"ev-note",children:s("nodeView.noChange")})}function ws({items:e,itemKey:s,classes:a,rowClass:n,renderHeader:r,renderEvidence:i,renderAction:l,leading:o,trailing:c,resetKey:u}){const d=p.useRef(null),[v,h]=p.useState(()=>new Set([0]));p.useEffect(()=>{u!==void 0&&h(new Set([0]))},[u]);const m=p.useCallback(x=>h(f=>{const b=new Set(f);return b.has(x)?b.delete(x):b.add(x),b}),[]),w=p.useCallback(()=>h(x=>{const f=d.current;if(!f)return x;let b=-1;for(;x.has(b+1);)b++;if(b<0||b>=e.length-1)return x;const k=f.querySelector(`[data-i="${b}"]`);return!k||k.getBoundingClientRect().bottom-f.getBoundingClientRect().top>f.clientHeight+40?x:new Set(x).add(b+1)}),[e]);return p.useEffect(()=>{const x=d.current;if(!x)return;let f=x.scrollTop;const b=()=>{const S=x.scrollTop,D=S>f;f=S,D&&w()},k=S=>{S.key!=="j"&&S.key!=="ArrowDown"||x.scrollHeight-x.clientHeight-x.scrollTop>1||w()};return x.addEventListener("scroll",b,{passive:!0}),window.addEventListener("keydown",k,!0),()=>{x.removeEventListener("scroll",b),window.removeEventListener("keydown",k,!0)}},[w]),t.jsxs("div",{className:a.pane,ref:d,children:[o,e.map((x,f)=>{const b=v.has(f),k=n?n(x,f):"";return t.jsxs("div",{"data-i":f,className:`${a.row}${k?` ${k}`:""}${b?" open":""}`,children:[t.jsx("button",{className:a.head,onClick:()=>m(f),"aria-expanded":b,children:r(x,f,b)}),l==null?void 0:l(x,f),b&&t.jsx("figure",{className:a.evidence,children:i(x,f)})]},s(x,f))}),c]})}function Yn({node:e,r:s,latest:a}){const n=Gn(e.id,s.hash,!0);return t.jsx(gs,{diff:n})}function Zn({node:e,rows:s}){const a=C();return s?s.length?t.jsx(ws,{items:s,itemKey:n=>n.hash,classes:{pane:"pane-hist",row:"ver-row",head:"rec-toggle",evidence:"rec-evidence"},rowClass:(n,r)=>r===0?"latest":"",renderHeader:(n,r,i)=>t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"rec-head",children:[t.jsx("span",{className:"rec-caret",children:i?"▾":"▸"}),t.jsxs("span",{className:"rec-v",children:["v",s.length-r]}),t.jsx("code",{className:"rec-hash",children:n.hash.slice(0,7)}),t.jsx("span",{className:"rec-date",children:(n.date||"").slice(0,10)}),t.jsxs("span",{className:"rec-diff",children:[t.jsxs("b",{className:"rec-add",children:["+",n.additions??0]}),t.jsxs("b",{className:"rec-del",children:["−",n.deletions??0]})]})]}),t.jsx("div",{className:"rec-msg",children:n.reason}),t.jsxs("div",{className:"rec-sub",children:[a("nodeView.filesChanged",{n:n.files??0})," · ",n.session||a("common.idle")]})]}),renderEvidence:(n,r)=>t.jsx(Yn,{node:e,r:n,latest:r===0})}):t.jsx("div",{className:"pane-hist empty",children:a("common.noVersions")}):t.jsx("div",{className:"pane-hist empty",children:a("nodeView.loadingHistory")})}function Jn({node:e,sessions:s=[],filter:a={},onFilter:n=()=>{}}){var m,w,x,f,b;const r=C(),i=vs("issue",e.id,a),l=Xe("issues",i,1,{pollMs:0});if(l.loading)return t.jsx("div",{className:"pane-issues pane-loading",children:t.jsx("span",{className:"spinner","aria-label":r("common.loading")})});if(l.error)return t.jsx("div",{className:"pane-issues empty",children:l.error});const o=((m=l.data)==null?void 0:m.items)||[],c=(((x=(w=e.reviewSummary)==null?void 0:w.issues)==null?void 0:x.open)||0)+(((b=(f=e.reviewSummary)==null?void 0:f.issues)==null?void 0:b.closed)||0);if(!c)return t.jsx("div",{className:"pane-issues empty",children:r("nodeView.noIssues")});const u=xs(l.data,r),d=o.filter(k=>k.status==="open"),v=o.filter(k=>k.status!=="open"),h=os(u,n,["section","author","store","session"]);return t.jsxs("div",{className:"pane-issues",children:[c>4&&t.jsx(ns,{value:a.q||"",onChange:k=>n({q:k||null}),summary:{shown:o.length,total:l.data.total},placeholder:r("nodeView.filterIssues"),searchLabel:r("reviewList.searchIssues"),filterLabel:r("reviewList.filters"),clearLabel:r("reviewList.all"),clearSearchLabel:r("reviewList.clearSearch"),groups:h}),!o.length&&t.jsx("div",{className:"pane-filter-none",children:r("nodeView.filterNone")}),d.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"issue-group-head",children:r("nodeView.openIssues",{n:d.length})}),d.map(k=>t.jsx(Fe,{issue:k},k.id))]}),v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"issue-group-head closed",children:r("nodeView.closedIssues",{n:v.length})}),v.map(k=>t.jsx(Fe,{issue:k},k.id))]}),l.data.total>o.length&&t.jsxs("a",{className:"pane-view-all",href:z(ps("issues",i)),children:[r("reviewList.showing",{shown:o.length,total:l.data.total})," ",t.jsx(V,{name:"chevron-right",size:13})]})]})}const fe=new Map;function Xn(e,s,a){const n=`${e} ${s}`,[r,i]=p.useState(()=>fe.get(n)??null);return p.useEffect(()=>{if(!e||!s)return;const l=fe.get(n);l&&i(l);let o=!0;return fetch(ve(`/api/edit?source=${encodeURIComponent(e)}&path=${encodeURIComponent(s)}`)).then(c=>c.json()).then(c=>{fe.set(n,c),o&&i(c)}).catch(()=>o&&i(c=>c??{patch:""})),()=>{o=!1}},[e,s,a,n]),r}function et({node:e,ov:s}){const a=C(),n=Xn(s.source,e.path,!0);return t.jsxs("figure",{className:"edit-rev",children:[t.jsxs("figcaption",{className:"edit-by",children:[t.jsx("span",{className:`ov-mark ov-${s.op}`,children:_n[s.op]||"•"}),t.jsx("span",{className:"edit-by-label",children:s.label}),t.jsx("span",{className:"edit-state",children:s.committed?a("nodeView.editCommitted"):a("nodeView.editDirty")})]}),t.jsx(gs,{diff:n})]})}function st({node:e}){const s=C(),a=e.overlays||[];return a.length?t.jsx("div",{className:"pane-edit",children:a.map((n,r)=>t.jsx(et,{node:e,ov:n},r))}):t.jsx("div",{className:"pane-edit empty",children:s("nodeView.noEdit")})}function nt({verdict:e}){const s=C();return e?e.status==="pass"?t.jsx("span",{className:"eval-verdict pass",children:s("nodeView.eval.pass")}):e.status==="fail"?t.jsx("span",{className:"eval-verdict fail",children:s("nodeView.eval.fail")}):t.jsx("span",{className:"eval-verdict note","data-tip":e.note,children:s("nodeView.eval.note")}):t.jsx("span",{className:"eval-verdict legacy",children:s("nodeView.eval.legacy")})}function tt({r:e}){var n;const s=C(),a=is(e);return t.jsxs(t.Fragment,{children:[e.expected&&t.jsxs("div",{className:"eval-expected",children:[t.jsx("span",{className:"eval-expected-label",children:s("nodeView.eval.expected")})," ",e.expected]}),((n=e.verdict)==null?void 0:n.note)&&t.jsxs("div",{className:"eval-note",children:[t.jsx("span",{className:"eval-expected-label",children:s("nodeView.eval.noteLabel")})," ",e.verdict.note]}),a.length>0?t.jsx("div",{className:"eval-gallery",style:{display:"flex",flexDirection:"column",gap:8},children:a.map((r,i)=>t.jsx(cs,{e:r,alt:s("nodeView.eval.shotAlt",{scenario:e.scenario})},`${r.hash}-${i}`))}):t.jsx("figcaption",{className:"eval-noimg",children:e.blobState==="miss"?s("nodeView.eval.miss"):s("nodeView.eval.noImage")})]})}function Oe({s:e}){var a;const s=C();return t.jsxs("div",{className:"eval-row eval-declared-row",children:[t.jsxs("span",{className:"eval-top",children:[t.jsx(as,{state:"empty",title:s("score.missing")}),t.jsx("span",{className:"eval-scenario",children:e.name}),t.jsx(Ys,{tags:e.tags}),((a=e.code)==null?void 0:a.length)>0&&t.jsx("code",{className:"eval-tracks",children:e.code.join(", ")})]}),e.expected&&t.jsxs("div",{className:"eval-expected",children:[t.jsx("span",{className:"eval-expected-label",children:s("nodeView.eval.expected")})," ",e.expected]})]})}function _e({track:e}){const s=C();return t.jsxs("div",{className:"eval-row eval-dangling-row",children:[t.jsxs("span",{className:"eval-top",children:[t.jsx("span",{className:"eval-dangling-badge","data-tip":s("nodeView.eval.danglingTitle"),children:"⚠"}),t.jsx("span",{className:"eval-scenario eval-dangling-name",children:e.scenario}),t.jsx("span",{className:"eval-dangling-tag",children:s("nodeView.eval.danglingGone")})]}),t.jsx("div",{className:"eval-dangling-remarks",children:t.jsx(Dn,{replies:e.remarks})})]})}function at({node:e,sessions:s=[],filter:a={},onFilter:n=()=>{}}){var x;const r=C(),i=vs("eval",e.id,a),l=Xe("evals",i,1,{pollMs:0,view:"timeline"});if(l.loading)return t.jsx("div",{className:"pane-eval pane-loading",children:t.jsx("span",{className:"spinner","aria-label":r("common.loading")})});if(l.error)return t.jsx("div",{className:"pane-eval empty",children:l.error});if(!((x=l.data)!=null&&x.hasEvalFile))return t.jsx("div",{className:"pane-eval empty",children:r("nodeView.eval.noScenarios")});const o=l.data.items||[],c=o.filter(f=>f.filterKind===oe.RESULT),u=o.filter(f=>f.filterKind===oe.UNMEASURED),d=o.filter(f=>f.filterKind===oe.DANGLING),v=xs(l.data,r),h=os(v,n,["section","review","freshness","kind","filer","session"]),m=l.data.sourceTotal>4?t.jsx(ns,{value:a.q||"",onChange:f=>n({q:f||null}),summary:{shown:o.length,total:l.data.total},placeholder:r("nodeView.filterScenarios"),searchLabel:r("reviewList.searchEvals"),filterLabel:r("reviewList.filters"),clearLabel:r("reviewList.all"),clearSearchLabel:r("reviewList.clearSearch"),groups:h},"filter"):null,w=l.data.total>o.length?t.jsxs("a",{className:"pane-view-all",href:z(ps("evals",i)),children:[r("reviewList.showing",{shown:o.length,total:l.data.total})," ",t.jsx(V,{name:"chevron-right",size:13})]}):null;return c.length?t.jsxs(t.Fragment,{children:[t.jsx(ws,{items:c,resetKey:`${l.data.revision}:${JSON.stringify(a)}`,leading:[m,o.length?null:t.jsx("div",{className:"pane-filter-none",children:r("nodeView.filterNone")},"none"),...u.map(f=>t.jsx(Oe,{s:f},f.name))],trailing:d.map(f=>t.jsx(_e,{track:f},f.threadId)),itemKey:(f,b)=>`${f.scenario}-${f.ts}-${b}`,classes:{pane:"pane-eval",row:"eval-row",head:"eval-head",evidence:"eval-shot"},renderAction:f=>t.jsx("a",{className:"eval-open",href:z(ms(e.id,f.scenario)),"data-tip":r("nodeView.eval.openDetail"),"aria-label":r("nodeView.eval.openDetail"),children:t.jsx(V,{name:"chevron-right",size:14})}),renderHeader:(f,b,k)=>t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"eval-top",children:[t.jsx("span",{className:"eval-caret",children:k?"▾":"▸"}),t.jsx("span",{className:"eval-scenario",children:f.scenario}),t.jsx(nt,{verdict:f.verdict}),t.jsx(as,{state:ts(f),title:f.fresh?void 0:r("nodeView.eval.staleAxes",{axes:f.staleAxes.join(", ")})})]}),t.jsxs("span",{className:"eval-meta",children:[f.evaluator&&t.jsx("span",{className:"eval-evaluator",children:f.evaluator}),t.jsx("code",{className:"eval-sha",children:f.codeSha.slice(0,7)}),t.jsx("span",{className:"eval-ts",children:f.ts.replace("T"," ").slice(0,16)})]})]}),renderEvidence:f=>t.jsx(tt,{r:f})}),w]}):t.jsxs("div",{className:"pane-eval pane-eval-declared",children:[m,t.jsx("div",{className:"eval-todo-note",children:o.length?r("nodeView.eval.noReadings"):r("nodeView.filterNone")}),u.map(f=>t.jsx(Oe,{s:f},f.name)),d.map(f=>t.jsx(_e,{track:f},f.threadId)),w]})}const rt={spec:"nodeView.paneSpec",history:"nodeView.paneHistory",issues:"nodeView.paneIssues",eval:"nodeView.paneEval",edit:"nodeView.paneEdit"};function Ft({node:e,pane:s,setPane:a,onClose:n,sessions:r=[]}){var b,k,S,D,N,g,E,R;const i=C(),[l,o]=p.useState({issues:{},eval:{}}),c=(y,$)=>o(A=>({...A,[y]:Fs(A[y],$)})),u=((k=(b=e.reviewSummary)==null?void 0:b.issues)==null?void 0:k.open)||0,d=((D=(S=e.reviewSummary)==null?void 0:S.issues)==null?void 0:D.closed)||0,v=((g=(N=e.reviewSummary)==null?void 0:N.evals)==null?void 0:g.pass)||0,h=((R=(E=e.reviewSummary)==null?void 0:E.evals)==null?void 0:R.fail)||0,m=(e.overlays||[]).length,w=Kn(e),x=w.some(y=>y.key===s)?s:w[0].key,f=Wn(e.id,x==="history");return t.jsx("div",{className:"ov-backdrop","data-focus-overlay":!0,onMouseDown:n,children:t.jsxs("div",{className:"ov-panel",onMouseDown:y=>y.stopPropagation(),children:[t.jsxs("div",{className:"ov-head",children:[t.jsx("span",{className:"ov-title",children:e.title}),t.jsx("div",{className:"ov-tabs",children:w.map(y=>t.jsxs("button",{className:y.key===x?"ov-tab on":"ov-tab",onClick:()=>a(y.key),children:[i(rt[y.key]),y.key==="issues"&&(u>0||d>0)&&t.jsxs("span",{className:"ov-tab-counts",children:[u>0&&t.jsx(Z,{kind:"issue",state:"open",cls:"st-open",n:u,label:i("nodeView.openIssues",{n:u})}),d>0&&t.jsx(Z,{kind:"issue",state:"closed",cls:"st-closed",n:d,label:i("nodeView.closedIssues",{n:d})})]}),y.key==="eval"&&(v>0||h>0)&&t.jsxs("span",{className:"ov-tab-counts",children:[v>0&&t.jsx(Z,{kind:"eval",state:"pass",cls:"st-pass",n:v,label:i("nodeView.eval.passCount",{n:v})}),h>0&&t.jsx(Z,{kind:"eval",state:"fail",cls:"st-fail",n:h,label:i("nodeView.eval.failCount",{n:h})})]}),y.key==="edit"&&m>0&&t.jsx("span",{className:"ov-tab-counts",children:t.jsx("span",{className:"ovc st-edit","data-tip":i("nodeView.pendingEdits",{n:m}),children:m})})]},y.key))}),t.jsx("span",{className:"ov-hint",children:i("nodeView.hint")})]}),t.jsxs("div",{className:"ov-body",children:[x==="spec"&&t.jsx("div",{className:"pane-solo",children:t.jsx(Hn,{node:e})}),x==="history"&&t.jsx(Zn,{node:e,rows:f}),x==="issues"&&t.jsx(Jn,{node:e,sessions:r,filter:l.issues,onFilter:y=>c("issues",y)}),x==="eval"&&t.jsx(at,{node:e,sessions:r,filter:l.eval,onFilter:y=>c("eval",y)}),x==="edit"&&t.jsx(st,{node:e})]})]})})}const lt=({size:e=12})=>t.jsx(V,{name:"lock",size:e});function it(e){if(!e.length)return null;const s={};return e.forEach(a=>{s[a.op]=(s[a.op]||0)+1}),Object.entries(s).map(([a,n])=>`${Zs[a]}${n}`).join(" ")}function ot({guides:e=[],expandable:s,expanded:a,rollup:n,kin:r=0,onToggle:i}){return t.jsxs("span",{className:"sess-lead",children:[e.map((l,o)=>{const c=o===e.length-1?l?"tee":"elbow":l?"rail":"gap";return t.jsx("span",{className:`sess-rail ${c}`,"aria-hidden":"true"},o)}),s&&t.jsx("span",{className:`sess-fold pod${a?" open":""}`,role:"button",style:a?{color:n,borderColor:n}:{background:n,borderColor:n},"data-tip":`${r} nested session${r===1?"":"s"} — click to ${a?"collapse":"expand"}`,onClick:l=>{l.stopPropagation(),i==null||i()},onMouseDown:l=>{l.preventDefault(),l.stopPropagation()},children:r})]})}function ct(){const[e,s]=p.useState(()=>new Set),a=r=>s(i=>{const l=new Set(i);return l.has(r)?l.delete(r):l.add(r),l}),n=p.useCallback(r=>s(i=>{const l=r.filter(c=>c&&!i.has(c));if(!l.length)return i;const o=new Set(i);return l.forEach(c=>o.add(c)),o}),[]);return{expanded:e,toggle:a,expand:n}}function ut({s:e,locked:s,showAvatar:a=!0,lead:n=null}){const r=C(),i=it(e.ops),l=ls(e),o=r(`status.${e.status}`);return t.jsxs(t.Fragment,{children:[n,a&&t.jsx(Es,{seed:e.id,status:e.status,title:`${en(e)} · ${o} — ${e.id.slice(0,8)}`}),t.jsxs("span",{className:"sess-meta",children:[t.jsx("span",{className:"sess-glyph",style:{color:q[e.status]},"data-tip":o,"aria-label":o,children:Js[e.status]}),i&&t.jsx("span",{className:"sess-ops",children:i})]}),t.jsx("span",{className:"sess-id","data-tip":l,children:l}),s&&t.jsx("span",{className:"sess-lock","data-tip":r("sessionWindow.lockedTitle"),children:t.jsx(lt,{})})]})}function qt({sessions:e,activeId:s,onPick:a,onOpenSession:n}){const r=C(),{expanded:i,toggle:l}=ct(),o=p.useMemo(()=>tn(e,c=>i.has(c)),[e,i]);return t.jsx("div",{className:"sesswin",children:e.length===0?t.jsxs("div",{className:"sesswin-empty",children:[r("sessionWindow.emptyBefore"),t.jsx("kbd",{children:"⏎"}),r("sessionWindow.emptyAfter")]}):o.map(c=>{if(c.type==="zone")return t.jsx("div",{className:`sesswin-zone sesswin-zone-${c.zone}`,children:r(`sessionZone.${c.zone}`)},`zone-${c.zone}`);const u=c.s,d=u.source===s,v=c.expandable||c.depth?t.jsx(ot,{guides:c.guides,expandable:c.expandable,expanded:c.expanded,rollup:c.rollup,kin:c.kin,onToggle:()=>l(u.id)}):null;return t.jsx("button",{className:d?"sess-row locked":"sess-row",style:{"--ov":Ss(u.id)},onClick:()=>a(u),onDoubleClick:()=>n(u.id),"data-tip":r("sessionWindow.rowTitle"),children:t.jsx(ut,{s:u,locked:d,lead:v})},u.id)})})}export{Et as $,Es as A,Fs as B,bn as C,z as D,oe as E,Mn as F,Zs as G,Zn as H,Jn as I,Lt as J,bt as K,lt as L,Ct as M,Ft as N,Sn as O,In as P,$n as Q,ot as R,yt as S,Ys as T,kn as U,vn as V,gn as W,je as X,Z as Y,xn as Z,Ce as _,Qs as a,hs as a0,$t as a1,ae as a2,ft as a3,xt as a4,gt as a5,Os as a6,vt as a7,W as a8,Nt as a9,is as aa,An as ab,pe as ac,fs as ad,ts as ae,jt as af,Us as ag,At as ah,Dt as ai,wt as aj,Cn as ak,St as al,cs as am,ss as an,Dn as ao,mt as ap,Pt as aq,As as ar,pt as as,Ls as at,te as au,kt as av,wn as aw,Js as b,q as c,Xe as d,ms as e,en as f,It as g,Tt as h,qn as i,as as j,Rt as k,Ss as l,Vt as m,ce as n,qt as o,Kn as p,Wn as q,P as r,ls as s,Hn as t,Be as u,at as v,st as w,ct as x,tn as y,ut as z};
@@ -1 +0,0 @@
1
- import{a6 as x,r as o,j as e,a7 as N}from"./index-D6HBvKkJ.js";import{A as j,k as b,a as T,i as f,r as S,s as k}from"./bindings-BC9vqpYU.js";import{P as v}from"./PageScroll-CadAKuSy.js";import{g as E,T as y,a as C,b as A,c as F}from"./terminalFont-DmTPNdbU.js";const h="spexcode.theme",g=[{code:"minimal",label:"Minimal"},{code:"things",label:"Things"},{code:"tokyonight",label:"Tokyo Night"},{code:"catppuccin",label:"Catppuccin"},{code:"everforest",label:"Everforest"},{code:"gruvbox",label:"Gruvbox"},{code:"rosepine",label:"Rosé Pine Dawn"},{code:"dracula",label:"Dracula"}],u=new Set(g.map(s=>s.code)),p="minimal";function w(){try{const s=localStorage.getItem(h);if(u.has(s))return s}catch{}return p}function L(s){const i=u.has(s)?s:p;try{document.documentElement.setAttribute("data-theme",i)}catch{}try{localStorage.setItem(h,i)}catch{}return i}function M({t:s}){const[i,d]=o.useState(0),[c,l]=o.useState(null),r=()=>d(n=>n+1);return o.useEffect(()=>{if(!c)return;const n=a=>{if(a.preventDefault(),a.stopPropagation(),a.key==="Escape"){l(null);return}["Shift","Control","Alt","Meta"].includes(a.key)||(k(c,{keys:[a.key]}),l(null),r())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[c]),e.jsxs("section",{className:"legend-sec",children:[e.jsx("div",{className:"legend-h",children:s("settings.secShortcuts")}),e.jsx("div",{className:"set-keys",children:j.map(n=>e.jsxs("div",{className:"set-key-row",children:[e.jsx("span",{className:"legend-desc",children:s(n.desc)}),e.jsx("button",{className:`bind-cell${c===n.id?" capturing":""}${n.rebind?"":" fixed"}${f(n.id)?" custom":""}`,disabled:!n.rebind,onClick:()=>n.rebind&&l(n.id),children:c===n.id?e.jsx("span",{className:"bind-hint",children:s("settings.bindPrompt")}):b(n.id).map((a,m)=>e.jsx("kbd",{children:T(a)},m))})]},n.id))}),e.jsxs("div",{className:"set-foot",children:[e.jsx("span",{className:"legend-desc set-hint",children:s("settings.shortcutsHint")}),e.jsx("button",{className:"set-reset",onClick:()=>{S(),l(null),r()},children:s("settings.reset")})]})]})}function D(){const{t:s,lang:i,setLang:d}=x(),[c,l]=o.useState(w),[r,n]=o.useState(E),a=t=>{L(t),l(t)},m=t=>n(F(t));return e.jsx(v,{className:"page-settings-scroll",children:e.jsxs("div",{className:"settings-body",children:[e.jsx("h1",{className:"page-title",children:s("settings.title")}),e.jsxs("section",{className:"legend-sec",children:[e.jsx("div",{className:"legend-h",children:s("settings.secLanguage")}),e.jsx("div",{className:"set-langs",children:N.map(t=>e.jsx("button",{className:t.code===i?"set-lang on":"set-lang",onClick:()=>d(t.code),"aria-pressed":t.code===i,children:t.label},t.code))})]}),e.jsxs("section",{className:"legend-sec",children:[e.jsx("div",{className:"legend-h",children:s("settings.secTheme")}),e.jsx("div",{className:"set-langs",children:g.map(t=>e.jsx("button",{className:t.code===c?"set-lang on":"set-lang",onClick:()=>a(t.code),"aria-pressed":t.code===c,children:s(t.label)},t.code))})]}),e.jsxs("section",{className:"legend-sec",children:[e.jsx("div",{className:"legend-h",children:s("settings.secTerminal")}),e.jsxs("label",{className:"set-terminal-font",children:[e.jsx("span",{children:s("settings.terminalFontSize")}),e.jsx("input",{type:"range",min:A,max:C,step:y,value:r,onChange:t=>m(t.target.value)}),e.jsxs("output",{children:[r,"px"]})]})]}),e.jsx(M,{t:s})]})})}export{D as default};
@@ -1 +0,0 @@
1
- import{u as L,r as i,Q as F,S as U,j as s,I as k,T as _,U as I,V as J}from"./index-D6HBvKkJ.js";import{b as w,c as D,s as K}from"./SessionWindow-BWH5O0jh.js";const ee=e=>{var n;return((n=e==null?void 0:e.capabilities)==null?void 0:n.headless)===!0},V=e=>{var n;return((n=e==null?void 0:e.capabilities)==null?void 0:n.messageStream)===!0},Y=["command","file_path","path","pattern","query","description","prompt","url"];function H(e,n=180){const o=typeof e=="string"?e:JSON.stringify(e);if(!o)return"";const r=o.replace(/\s+/g," ").trim();return r.length>n?`${r.slice(0,n-1)}…`:r}function q(e){if(!e||typeof e!="object")return"";for(const n of Y)if(e[n]!=null)return H(e[n]);return H(e)}function G(e){const n=e==null?void 0:e.event;if(!n||typeof n!="object")return[];const o=n.message&&typeof n.message=="object"?n.message:n,r=o.role||n.role||n.type;if(r!=="user"&&r!=="assistant")return[];const m=o.content,f=typeof m=="string"?[{type:"text",text:m}]:Array.isArray(m)?m:[],d=[];for(const[u,c]of f.entries())!c||typeof c!="object"||(c.type==="text"&&typeof c.text=="string"&&c.text.trim()?d.push({key:`${e.cursor}:${u}`,kind:r,text:c.text}):r==="assistant"&&c.type==="tool_use"&&d.push({key:`${e.cursor}:${u}`,kind:"tool",name:typeof c.name=="string"&&c.name?c.name:"tool",summary:q(c.input)}));return d}function Q(e){return(e||[]).flatMap(G)}function B({sessionId:e,active:n}){const o=L(),[r,m]=i.useState(null),[f,d]=i.useState("loading"),u=i.useRef(null),c=i.useRef(!0),g=i.useMemo(()=>Q(r),[r]);i.useEffect(()=>{if(!n)return;let l=!1,v=()=>{};return d("loading"),F(e).then(N=>{l||(m(N.messages),d("connecting"),v=U(e,N.cursor,{onMessage:x=>m(j=>{const h=j||[];return h.length&&x.cursor<=h[h.length-1].cursor?h:[...h,x]}),onStatus:x=>d(j=>x?"live":j==="error"?j:"disconnected"),onError:()=>d("error")}))}).catch(()=>{l||(m([]),d("error"))}),()=>{l=!0,v()}},[n,e]);const b=()=>{const l=u.current;l&&(c.current=l.scrollHeight-l.scrollTop-l.clientHeight<48)};return i.useEffect(()=>{const l=u.current;l&&c.current&&(l.scrollTop=l.scrollHeight)},[r]),s.jsxs("div",{className:"ms-console",children:[s.jsx("div",{className:"ms-scroll",ref:u,onScroll:b,"aria-live":"polite",children:r===null?s.jsx("div",{className:"ms-empty",children:o("session.messagesLoading")}):g.length===0?s.jsx("div",{className:"ms-empty",children:o("session.messagesEmpty")}):g.map(l=>l.kind==="tool"?s.jsxs("div",{className:"ms-tool",title:l.summary||l.name,children:[s.jsx(k,{name:"terminal",size:13}),s.jsx("span",{className:"ms-tool-name",children:l.name}),l.summary&&s.jsx("code",{className:"ms-tool-summary",children:l.summary})]},l.key):s.jsxs("div",{className:`ms-turn ${l.kind}`,children:[s.jsx("span",{className:"ms-role",children:o(l.kind==="user"?"session.messagesYou":"session.messagesAssistant")}),s.jsx("div",{className:"ms-bubble",children:l.text})]},l.key))}),(f==="disconnected"||f==="error")&&s.jsx("div",{className:`ms-state ${f}`,role:"status",children:o(f==="error"?"session.messagesUnavailable":"session.messagesDisconnected")})]})}const R=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),M=e=>new Date(e).toLocaleDateString([],{month:"short",day:"numeric"}),C=e=>new Date(e).toDateString(),W=(e,n)=>e!=null&&e.length===n.length&&(e.length===0||JSON.stringify(e[e.length-1])===JSON.stringify(n[n.length-1]));function se({s:e,sessions:n=[],active:o=!0}){const r=L(),m=V(e),[f,d]=i.useState(null),[u,c]=i.useState(null),[g,b]=i.useState(""),[l,v]=i.useState(!1),[N,x]=i.useState(null),[j,h]=i.useState(!1),E=i.useRef(null),T=i.useRef(!0),p=i.useCallback(()=>_(e.id).then(t=>{t&&d(a=>W(a,t.events)?a:t.events)}),[e.id]);i.useEffect(()=>{d(null),c(null),T.current=!0,p(),I(e.id).then(t=>{t&&c(t)})},[e.id,p]),i.useEffect(()=>{h(!1)},[e.id,m]),i.useEffect(()=>{const t=setInterval(p,8e3);return()=>clearInterval(t)},[p]),i.useEffect(()=>{p()},[e.status,e.note,p]);const O=()=>{const t=E.current;t&&(T.current=t.scrollHeight-t.scrollTop-t.clientHeight<48)};i.useEffect(()=>{const t=E.current;t&&T.current&&(t.scrollTop=t.scrollHeight)},[f]);const P=async()=>{const t=g.trim();if(!t||l)return;v(!0),x(null);const a=await J(e.id,t,{replyVia:"note"});v(!1),a.ok?(b(""),p()):x(a.error||r("mobile.sendFailed"))},A=t=>{if(!t)return r("mobile.you");const a=n.find(y=>y.id===t);return a?K(a):t.slice(0,8)},S=[];let $=null;for(const[t,a]of(f||[]).entries())if(C(a.ts)!==$&&($=C(a.ts),S.push(s.jsx("div",{className:"m-day",children:M(a.ts)},`d${t}`))),a.kind==="status"){const y=a.display||a.status;S.push(s.jsxs("div",{className:"m-ev",children:[s.jsxs("div",{className:"m-ev-head",children:[s.jsx("span",{className:"m-ev-glyph",style:{color:D[y]},children:w[y]||"·"}),s.jsx("span",{className:"m-ev-word",style:{color:D[y]},children:r(`status.${y}`)}),s.jsx("span",{className:"m-ev-time",children:R(a.ts)})]}),a.note&&s.jsx("div",{className:"m-ev-note",children:a.note})]},t))}else S.push(s.jsxs("div",{className:"m-ev m-ev-sent",children:[s.jsxs("div",{className:"m-ev-head",children:[s.jsx("span",{className:"m-ev-from",children:A(a.from)}),s.jsx("span",{className:"m-ev-time",children:R(a.ts)})]}),s.jsx("div",{className:"m-ev-text",children:a.text})]},t));const z=e.liveness==="offline"||e.status==="offline";return j&&m?s.jsxs("div",{className:"tl-process",children:[s.jsxs("header",{className:"tl-process-head",children:[s.jsxs("button",{type:"button",className:"tl-process-back",onClick:()=>h(!1),children:[s.jsx(k,{name:"arrow-left",size:14}),s.jsx("span",{children:r("session.backToConversation")})]}),s.jsx("span",{className:"tl-process-title",children:r("session.fullProcess")})]}),s.jsx(B,{sessionId:e.id,active:o})]}):s.jsxs("div",{className:"tl-chat",children:[m&&s.jsx("div",{className:"tl-chat-tools",children:s.jsxs("button",{type:"button",className:"tl-process-door",onClick:()=>h(!0),children:[s.jsx(k,{name:"list-checks",size:14}),s.jsx("span",{children:r("session.fullProcess")}),s.jsx(k,{name:"chevron-right",size:13})]})}),s.jsxs("div",{className:"m-timeline",ref:E,onScroll:O,children:[(u==null?void 0:u.prompt)&&s.jsxs("details",{className:"m-ev m-ev-prompt",children:[s.jsxs("summary",{children:[r("mobile.asked"),e.created?` · ${M(e.created)} ${R(e.created)}`:""]}),s.jsx("div",{className:"m-ev-text",children:u.prompt})]}),f===null?s.jsx("div",{className:"m-empty",children:r("common.loading")}):S.length===0?s.jsx("div",{className:"m-empty",children:r("mobile.noEvents")}):S]}),z&&s.jsx("div",{className:"m-offline",children:r("mobile.offlineHint")}),N&&s.jsx("div",{className:"m-senderr",children:N}),s.jsx("div",{className:"m-composer",children:s.jsxs("div",{className:"m-composer-line",children:[s.jsx("textarea",{className:"m-input",rows:1,placeholder:r("mobile.inputPlaceholder"),value:g,onChange:t=>b(t.target.value)}),s.jsx("button",{className:"m-send",disabled:!g.trim()||l,onClick:P,children:r("mobile.send")})]})})]})}export{se as T,ee as i};