agent-canvas 0.1.3 → 0.1.4

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.
@@ -1,4 +1,4 @@
1
- import U1,{useEffect as c1,useLayoutEffect as y2,useState as o,useCallback as d1,useRef as T1,createContext as n0}from"react";import{createRoot as P2}from"react-dom/client";import{SessionContext as e0,ActiveViewCtx as S2}from"#canvas/runtime";import{useState as F1,useCallback as Y1,useEffect as U0,useRef as K0}from"react";import{AnnotationCtx as Q5}from"#canvas/runtime";import{useAnnotations as t}from"#canvas/runtime";import{jsxDEV as z5}from"react/jsx-dev-runtime";function r1($,J){return`canvas:${$}:rev:${J}`}function N1($,J){try{let Q=localStorage.getItem(r1($,J));if(!Q)return null;return JSON.parse(Q)}catch{return null}}function Y5($,J,Q){try{localStorage.setItem(r1($,J),JSON.stringify(Q))}catch{}}function Z5($,J){try{localStorage.removeItem(r1($,J))}catch{}}function G0({sessionId:$,revision:J,isReadOnly:Q,children:Z}){let Y=K0(`${$}:${J}`),[X,z]=F1(()=>{return N1($,J)?.annotations??[]}),[_,q]=F1(()=>{return N1($,J)?.generalNote??""}),[U,K]=F1(null),[G,W]=F1(()=>{let A=N1($,J);return A?.responses?new Map(A.responses):new Map}),[T,N]=F1(()=>{let A=N1($,J);return A?.feedbackEntries?new Map(A.feedbackEntries):new Map});U0(()=>{let A=`${$}:${J}`;if(A===Y.current)return;Y.current=A;let C=N1($,J);z(C?.annotations??[]),q(C?.generalNote??""),W(C?.responses?new Map(C.responses):new Map),N(C?.feedbackEntries?new Map(C.feedbackEntries):new Map),K(null)},[$,J]);let P=K0(null);U0(()=>{if(Q)return;if(P.current)clearTimeout(P.current);return P.current=setTimeout(()=>{Y5($,J,{annotations:X,generalNote:_,responses:Array.from(G.entries()),feedbackEntries:Array.from(T.entries())})},300),()=>{if(P.current)clearTimeout(P.current)}},[X,_,G,T,$,J,Q]);let L=Y1((A,C,H,M,h)=>{z((c)=>[...c,{id:A,snippet:C,note:H,createdAt:new Date().toISOString(),filePath:M,context:h}])},[]),y=Y1((A,C,H)=>{let M=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;L(M,A,C,H)},[L]),w=Y1((A,C)=>{z((H)=>H.map((M)=>M.id===A?{...M,note:C}:M))},[]),O=Y1((A)=>{X5(A),z((C)=>C.filter((H)=>H.id!==A)),K((C)=>C===A?null:C)},[]),b=Y1((A,C)=>{W((H)=>{let M=new Map(H);return M.set(A,C),M})},[]),v=Y1((A,C)=>{N((H)=>{let M=H.get(A);if(M&&M.markdown===C.markdown&&M.label===C.label&&M.required===C.required)return H;let h=new Map(H);return h.set(A,C),h})},[]),D=Y1((A)=>{N((C)=>{if(!C.has(A))return C;let H=new Map(C);return H.delete(A),H})},[]),j=Y1(()=>{for(let A of document.querySelectorAll("[data-annotation-id]"))H0(A);z([]),q(""),K(null),W(new Map),N(new Map),Z5($,J)},[$,J]);return z5(Q5.Provider,{value:{annotations:X,addAnnotation:y,addAnnotationWithId:L,updateAnnotation:w,removeAnnotation:O,generalNote:_,setGeneralNote:q,clearAll:j,activeAnnotationId:U,setActiveAnnotationId:K,responses:G,setResponse:b,feedbackEntries:T,setFeedbackEntry:v,removeFeedbackEntry:D},children:Z},void 0,!1,void 0,this)}function X5($){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Q of J)H0(Q)}function H0($){let J=$.parentNode;if(!J)return;let Q=document.createTextNode($.textContent||"");J.replaceChild(Q,$),J.normalize()}import a1,{useEffect as $1,useState as n,useRef as G5,useContext as H5,useCallback as W5,useMemo as D1}from"react";import{createPortal as T5}from"react-dom";import{SessionContext as F5}from"#canvas/runtime";function L1($,J){let Q=[],Z=q5($);for(let Y of Z){let X=document.createRange();if(X.selectNodeContents(Y),Y===$.startContainer)X.setStart(Y,$.startOffset);if(Y===$.endContainer)X.setEnd(Y,$.endOffset);let z=X.toString();if(!z||!z.trim())continue;let _=document.createElement("mark");_.setAttribute("data-annotation-id",J),_.style.cssText=`
1
+ import U1,{useEffect as c1,useLayoutEffect as P2,useState as i,useCallback as d1,useRef as T1,createContext as e0}from"react";import{createRoot as S2}from"react-dom/client";import{SessionContext as $5,ActiveViewCtx as A2}from"#canvas/runtime";import{useState as F1,useCallback as Y1,useEffect as U0,useRef as K0}from"react";import{AnnotationCtx as Y5}from"#canvas/runtime";import{useAnnotations as o}from"#canvas/runtime";import{jsxDEV as q5}from"react/jsx-dev-runtime";function r1($,J){return`canvas:${$}:rev:${J}`}function N1($,J){try{let Q=localStorage.getItem(r1($,J));if(!Q)return null;return JSON.parse(Q)}catch{return null}}function Z5($,J,Q){try{localStorage.setItem(r1($,J),JSON.stringify(Q))}catch{}}function X5($,J){try{localStorage.removeItem(r1($,J))}catch{}}function G0({sessionId:$,revision:J,isReadOnly:Q,children:Z}){let Y=K0(`${$}:${J}`),[X,z]=F1(()=>{return N1($,J)?.annotations??[]}),[q,_]=F1(()=>{return N1($,J)?.generalNote??""}),[U,K]=F1(null),[G,W]=F1(()=>{let C=N1($,J);return C?.responses?new Map(C.responses):new Map}),[T,N]=F1(()=>{let C=N1($,J);return C?.feedbackEntries?new Map(C.feedbackEntries):new Map});U0(()=>{let C=`${$}:${J}`;if(C===Y.current)return;Y.current=C;let I=N1($,J);z(I?.annotations??[]),_(I?.generalNote??""),W(I?.responses?new Map(I.responses):new Map),N(I?.feedbackEntries?new Map(I.feedbackEntries):new Map),K(null)},[$,J]);let S=K0(null);U0(()=>{if(Q)return;if(S.current)clearTimeout(S.current);return S.current=setTimeout(()=>{Z5($,J,{annotations:X,generalNote:q,responses:Array.from(G.entries()),feedbackEntries:Array.from(T.entries())})},300),()=>{if(S.current)clearTimeout(S.current)}},[X,q,G,T,$,J,Q]);let O=Y1((C,I,H,y,E)=>{z((c)=>[...c,{id:C,snippet:I,note:H,createdAt:new Date().toISOString(),filePath:y,context:E}])},[]),P=Y1((C,I,H)=>{let y=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;O(y,C,I,H)},[O]),w=Y1((C,I)=>{z((H)=>H.map((y)=>y.id===C?{...y,note:I}:y))},[]),B=Y1((C)=>{z5(C),z((I)=>I.filter((H)=>H.id!==C)),K((I)=>I===C?null:I)},[]),R=Y1((C,I)=>{W((H)=>{let y=new Map(H);return y.set(C,I),y})},[]),D=Y1((C,I)=>{N((H)=>{let y=H.get(C);if(y&&y.markdown===I.markdown&&y.label===I.label&&y.required===I.required)return H;let E=new Map(H);return E.set(C,I),E})},[]),m=Y1((C)=>{N((I)=>{if(!I.has(C))return I;let H=new Map(I);return H.delete(C),H})},[]),j=Y1(()=>{for(let C of document.querySelectorAll("[data-annotation-id]"))H0(C);z([]),_(""),K(null),W(new Map),N(new Map),X5($,J)},[$,J]);return q5(Y5.Provider,{value:{annotations:X,addAnnotation:P,addAnnotationWithId:O,updateAnnotation:w,removeAnnotation:B,generalNote:q,setGeneralNote:_,clearAll:j,activeAnnotationId:U,setActiveAnnotationId:K,responses:G,setResponse:R,feedbackEntries:T,setFeedbackEntry:D,removeFeedbackEntry:m},children:Z},void 0,!1,void 0,this)}function z5($){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Q of J)H0(Q)}function H0($){let J=$.parentNode;if(!J)return;let Q=document.createTextNode($.textContent||"");J.replaceChild(Q,$),J.normalize()}import a1,{useEffect as n,useState as s,useRef as H5,useContext as W5,useCallback as T5,useMemo as D1}from"react";import{createPortal as F5}from"react-dom";import{SessionContext as N5}from"#canvas/runtime";function L1($,J){let Q=[],Z=_5($);for(let Y of Z){let X=document.createRange();if(X.selectNodeContents(Y),Y===$.startContainer)X.setStart(Y,$.startOffset);if(Y===$.endContainer)X.setEnd(Y,$.endOffset);let z=X.toString();if(!z||!z.trim())continue;let q=document.createElement("mark");q.setAttribute("data-annotation-id",J),q.style.cssText=`
2
2
  background: var(--color-highlight-annotation);
3
3
  border-bottom: 1.5px solid var(--color-highlight-bg);
4
4
  border-radius: 2px;
@@ -6,7 +6,7 @@ import U1,{useEffect as c1,useLayoutEffect as y2,useState as o,useCallback as d1
6
6
  transition: background 150ms ease;
7
7
  color: inherit;
8
8
  padding: 1px 0;
9
- `;try{X.surroundContents(_)}catch{let q=X.extractContents();_.appendChild(q),X.insertNode(_)}Q.push(_)}return Q}function q5($){let J=[],Q=$.commonAncestorContainer;if(Q.nodeType===Node.TEXT_NODE)return J.push(Q),J;let Z=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),Y;while(Y=Z.nextNode()){if(Y.parentElement?.classList.contains("select-none"))continue;if($.intersectsNode(Y))J.push(Y)}return J}function l1($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Z of Q)Z.style.cssText=J?`
9
+ `;try{X.surroundContents(q)}catch{let _=X.extractContents();q.appendChild(_),X.insertNode(q)}Q.push(q)}return Q}function _5($){let J=[],Q=$.commonAncestorContainer;if(Q.nodeType===Node.TEXT_NODE)return J.push(Q),J;let Z=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),Y;while(Y=Z.nextNode()){if(Y.parentElement?.classList.contains("select-none"))continue;if($.intersectsNode(Y))J.push(Y)}return J}function l1($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Z of Q)Z.style.cssText=J?`
10
10
  background: var(--color-highlight-bg);
11
11
  border-bottom: 1.5px solid var(--color-highlight-border);
12
12
  border-radius: 2px;
@@ -22,7 +22,7 @@ import U1,{useEffect as c1,useLayoutEffect as y2,useState as o,useCallback as d1
22
22
  transition: background 150ms ease;
23
23
  color: inherit;
24
24
  padding: 1px 0;
25
- `}function C1($){let J=document.querySelectorAll("[data-annotation-id]");for(let Q of J){let Z=Q.getAttribute("data-annotation-id");Q.style.cssText=Z===$?`
25
+ `}function I1($){let J=document.querySelectorAll("[data-annotation-id]");for(let Q of J){let Z=Q.getAttribute("data-annotation-id");Q.style.cssText=Z===$?`
26
26
  background: var(--color-highlight-bg);
27
27
  border-bottom: 1.5px solid var(--color-highlight-border);
28
28
  border-radius: 2px;
@@ -38,31 +38,31 @@ import U1,{useEffect as c1,useLayoutEffect as y2,useState as o,useCallback as d1
38
38
  transition: background 150ms ease;
39
39
  color: inherit;
40
40
  padding: 1px 0;
41
- `}}function I1($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Z of Q)Z.setAttribute("data-annotation-id",J)}function b1($,J){let Q=J.filter((_)=>!document.querySelector(`[data-annotation-id="${_.id}"]`));if(!Q.length)return;let Z=[],Y="",X=document.createTreeWalker($,NodeFilter.SHOW_TEXT),z;while(z=X.nextNode()){if(z.parentElement?.classList.contains("select-none"))continue;Z.push({node:z,start:Y.length}),Y+=z.textContent||""}for(let _ of Q){let q=_.snippet;if(!q)continue;let U=[],K=0;while(!0){let L=Y.indexOf(q,K);if(L===-1)break;U.push(L),K=L+1}if(U.length===0)continue;let G=U[0];if(U.length>1&&_.context){let L=-1;for(let y of U){let w=0;if(_.context.before){let O=Y.slice(Math.max(0,y-80),y);if(O.includes(_.context.before))w+=2;else if(_.context.before.length>10&&O.includes(_.context.before.slice(-10)))w+=1}if(_.context.after){let O=Y.slice(y+q.length,y+q.length+80);if(O.includes(_.context.after))w+=2;else if(_.context.after.length>10&&O.includes(_.context.after.slice(0,10)))w+=1}if(w>L)L=w,G=y}}let W=G,T=G+q.length,N=W0(Z,W),P=W0(Z,T);if(!N||!P)continue;try{let L=document.createRange();L.setStart(N.node,N.offset),L.setEnd(P.node,P.offset),L1(L,_.id)}catch{}}}function W0($,J){for(let Q=$.length-1;Q>=0;Q--)if($[Q].start<=J){let Z=J-$[Q].start,Y=$[Q].node.textContent?.length??0;if(Z<=Y)return{node:$[Q].node,offset:Z}}return null}function j1($){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Q of J){let Z=Q.parentNode;if(!Z)continue;while(Q.firstChild)Z.insertBefore(Q.firstChild,Q);Z.removeChild(Q),Z.normalize()}}function F0($,J){let Q=T0($,"before",60),Z=T0($,"after",60),Y=U5($.startContainer,J);return{before:Q,after:Z,hierarchy:Y}}function T0($,J,Q){let Z=_5(J==="before"?$.startContainer:$.endContainer);if(!Z)return"";let Y="";if(J==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),z;while(z=X.nextNode()){if(z===$.startContainer){Y+=(z.textContent||"").slice(0,$.startOffset);break}if(z.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=z.textContent||""}if(Y.length>Q){Y=Y.slice(-Q);let _=Y.indexOf(" ");if(_>0)Y=Y.slice(_+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),z=!1,_;while(_=X.nextNode()){if(_===$.endContainer){Y+=(_.textContent||"").slice($.endOffset),z=!0;continue}if(z){if(_.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=_.textContent||""}}if(Y.length>Q){Y=Y.slice(0,Q);let q=Y.lastIndexOf(" ");if(q>0)Y=Y.slice(0,q)}}return Y.trim()}function _5($){let J=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=$.parentElement;while(Q){if(J.has(Q.tagName))return Q;Q=Q.parentElement}return null}function U5($,J){let Q=[],Z=$ instanceof Element?$:$.parentElement;while(Z&&Z!==J){let Y=Z.getAttribute?.("data-task-id");if(Y){let X=Z.querySelector(".font-semibold");if(X)Q.unshift(X.textContent?.trim()||Y)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Q.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Q}function N0($){let J=$.snippet.trim(),Q=$.context,Z=J.length<30;if(Q&&Z&&(Q.before||Q.after)){let Y=[];if(Q.before)Y.push(`...${Q.before} `);if(Y.push(J),Q.after)Y.push(` ${Q.after}...`);return Y.join("")}return J}import{useEffect as m1,useRef as V1,useState as O1,useCallback as i1,useMemo as O0}from"react";import{createPortal as K5}from"react-dom";function L0($,J){let Y=J||document.body,X=$.getBoundingClientRect(),z=Y.getBoundingClientRect(),_=Y===document.body?window.scrollY:Y.scrollTop,q=X.bottom-z.top+_+8,U=Math.max(0,Math.min(X.left-z.left,z.width-280-12));return Y.style.position="relative",{style:{position:"absolute",top:`${q}px`,left:`${U}px`},parent:Y}}import{jsxDEV as i}from"react/jsx-dev-runtime";function B0({anchorEl:$,scrollContainer:J,onClose:Q,ignoreSelector:Z,zIndex:Y="50",padding:X="12px",width:z="280px",children:_}){let q=V1(null),U=V1(Q);U.current=Q;let{style:K,parent:G}=L0($,J);return m1(()=>{let W=setTimeout(()=>{let T=(N)=>{if(q.current&&!q.current.contains(N.target)){if(Z&&N.target.closest?.(Z))return;U.current(),document.removeEventListener("mousedown",T)}};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},0);return()=>clearTimeout(W)},[Z]),K5(i("div",{ref:q,style:{...K,zIndex:Y,width:z,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:_},void 0,!1,void 0,this),G)}var y0=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],M0=y0.flatMap(($)=>$.items);function M1({anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:Z=100,header:Y,onAdd:X,onCancel:z}){let[_,q]=O1(""),[U,K]=O1(null),[G,W]=O1(!1),T=V1(null);m1(()=>{T.current?.focus()},[]);let N=i1(()=>{if(_.trim())X(_.trim());else z()},[_,X,z]),P=_.trim().length>0?M0.filter((H)=>H.toLowerCase().startsWith(_.trim().toLowerCase())):M0,L=G?[]:P.length===1&&P[0].toLowerCase()===_.trim().toLowerCase()?[]:P,y=new Set(L),w=y0.map((H)=>({label:H.label,items:H.items.filter((M)=>y.has(M))})).filter((H)=>H.items.length>0),O=w.map((H)=>H.items),b=O.flat(),v=O0(()=>{if(U===null)return 0;let H=0;for(let M=0;M<O.length;M++){if(U<H+O[M].length)return M;H+=O[M].length}return 0},[U,O]),D=O0(()=>{if(U===null)return 0;let H=0;for(let M=0;M<v;M++)H+=O[M].length;return U-H},[U,v,O]),j=(H,M)=>{let h=0;for(let c=0;c<H;c++)h+=O[c].length;return h+M};m1(()=>{K(null),W(!1)},[_]);let A=i1((H)=>{q(H)},[]),C=Q.length>Z?Q.slice(0,Z)+"...":Q;return i(B0,{anchorEl:$,scrollContainer:J,onClose:z,width:"420px",children:[Y??i("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",C,"”"]},void 0,!0,void 0,this),i("textarea",{ref:T,value:_,onChange:(H)=>q(H.target.value),onKeyDown:(H)=>{if(b.length>0&&(H.key==="ArrowDown"||H.key==="ArrowUp"||H.key==="ArrowLeft"||H.key==="ArrowRight")){if(H.preventDefault(),U===null){K(0);return}if(H.key==="ArrowDown"){let M=Math.min(D+1,O[v].length-1);K(j(v,M))}else if(H.key==="ArrowUp"){let M=Math.max(D-1,0);K(j(v,M))}else if(H.key==="ArrowRight"){let M=Math.min(v+1,O.length-1),h=Math.min(D,O[M].length-1);K(j(M,h))}else if(H.key==="ArrowLeft"){let M=Math.max(v-1,0),h=Math.min(D,O[M].length-1);K(j(M,h))}return}if(U!==null&&b.length>0){if(H.key==="Tab"){H.preventDefault(),A(b[U]);return}if(H.key==="Enter"&&!H.shiftKey){H.preventDefault(),X(b[U]);return}}if(H.key==="Enter"&&!H.shiftKey){H.preventDefault(),N();return}if(H.key==="Escape")if(b.length>0&&!G)W(!0);else z()},style:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"8px"},children:[i("button",{onClick:z,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),i("button",{onClick:N,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b.length>0&&i("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:w.map((H)=>i("div",{style:{flex:1},children:[i("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:H.label},void 0,!1,void 0,this),H.items.map((M)=>{let h=b.indexOf(M);return i("div",{onMouseDown:(c)=>{c.preventDefault(),c.stopPropagation(),A(M)},onMouseEnter:()=>K(h),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:h===U?"var(--color-text-primary)":"var(--color-text-secondary)",background:h===U?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[i("span",{style:{fontWeight:500},children:M.slice(0,_.trim().length)},void 0,!1,void 0,this),M.slice(_.trim().length)]},M,!0,void 0,this)})]},H.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B1({anchorEl:$,scrollContainer:J,initialNote:Q,onUpdate:Z,onDelete:Y,onClose:X}){let[z,_]=O1(Q),q=V1(null),[U,K]=O1(!1);m1(()=>{let W=q.current;if(W)W.style.height="auto",W.style.height=W.scrollHeight+"px",W.focus(),W.setSelectionRange(W.value.length,W.value.length)},[]);let G=i1(()=>{if(!z.trim()){Y(),X();return}Z(z),X()},[z,Z,Y,X]);return i(B0,{anchorEl:$,scrollContainer:J,onClose:G,ignoreSelector:"[data-annotation-id]",zIndex:"60",padding:"10px 12px",children:[i("textarea",{ref:q,value:z,onChange:(W)=>{_(W.target.value),Z(W.target.value),W.target.style.height="auto",W.target.style.height=W.target.scrollHeight+"px"},onKeyDown:(W)=>{if(W.key==="Enter"&&!W.shiftKey)W.preventDefault(),G();if(W.key==="Escape")G()},style:{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}},void 0,!1,void 0,this),i("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"6px"},children:i("button",{onClick:()=>{Y(),X()},onMouseEnter:()=>K(!0),onMouseLeave:()=>K(!1),style:{fontSize:"11px",color:U?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as p,Fragment as S0}from"react/jsx-dev-runtime";var s1="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",o1="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function P0({revision:$}){let J=H5(F5),[Q,Z]=n(null),[Y,X]=n(null),[z,_]=n(!0),q=G5(null),{annotations:U,addAnnotationWithId:K,removeAnnotation:G,updateAnnotation:W,activeAnnotationId:T,setActiveAnnotationId:N}=t(),[P,L]=n(null),[y,w]=n(null),[O,b]=n(null),[v,D]=n(null),[j,A]=n(null),[C,H]=n(null),[M,h]=n(!1);$1(()=>{_(!0),X(null),H(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((B)=>{Z(()=>B.default),_(!1)}).catch((B)=>{X(B.message),_(!1)})},[J,$]),$1(()=>{if(!Q||!q.current)return;let B=setTimeout(()=>{if(q.current)b1(q.current,U)},50);return()=>clearTimeout(B)},[Q]),$1(()=>{C1(T)},[T]),$1(()=>{let B=q.current;if(!B)return;let S=(E)=>{let V=E.target.closest("[data-annotation-id]");if(!V)return;E.stopPropagation();let d=V.getAttribute("data-annotation-id");if(d===T)w({anchorEl:V,annId:d});else N(d)},m=(E)=>{let V=E.target.closest("[data-annotation-id]");if(V){let d=V.getAttribute("data-annotation-id");N(d)}},x=(E)=>{let V=E.target.closest("[data-annotation-id]"),d=E.relatedTarget?.closest?.("[data-annotation-id]");if(V&&!d){if(!document.getElementById("ann-inline-popover"))N(null)}};return B.addEventListener("click",S),B.addEventListener("mouseover",m),B.addEventListener("mouseout",x),()=>{B.removeEventListener("click",S),B.removeEventListener("mouseover",m),B.removeEventListener("mouseout",x)}},[Q,U,T]);let c=D1(()=>{let B=new Map;for(let S of U)if(S.snippet.startsWith("["))B.set(S.snippet,S.id);return B},[U]);$1(()=>{let B=q.current;if(!B)return;let S=(x)=>{if(j||O||y)return;let E=x.target;if(E.closest("[data-block-comment-btn]"))return;h(!1);let V=E.closest(s1);if(V&&B.contains(V)){let s=z1(B).indexOf(V);H(s>=0?s:null)}else H(null);let d=E.closest(o1);if(d&&B.contains(d)){D(d);let r=K1(d),s=r?c.get(r):void 0;if(s&&s!==T)N(s)}else D(null)},m=(x)=>{if(j||O||y)return;if(x.relatedTarget?.closest("[data-block-comment-btn]"))return;D(null),N(null)};return B.addEventListener("mousemove",S),B.addEventListener("mouseleave",m),()=>{B.removeEventListener("mousemove",S),B.removeEventListener("mouseleave",m)}},[Q,j,O,y,c,T]),$1(()=>{let B=(S)=>{let m=S.target.tagName;if(m==="INPUT"||m==="TEXTAREA"||S.target.isContentEditable)return;if(j||O||y)return;let x=q.current;if(!x)return;if(S.key==="ArrowDown"){S.preventDefault(),h(!0);let E=z1(x);if(E.length===0)return;H((V)=>{if(V===null)return 0;return Math.min(V+1,E.length-1)})}else if(S.key==="ArrowUp"){S.preventDefault(),h(!0);let E=z1(x);if(E.length===0)return;H((V)=>{if(V===null)return E.length-1;return Math.max(V-1,0)})}else if(S.key==="a"||S.key==="A"){if(C===null||!x)return;S.preventDefault();let V=z1(x)[C];if(!V)return;let d=K1(V);if(!d)return;let r=c.get(d);if(r)N(r),A({anchorEl:V,snippet:d,annId:r});else A({anchorEl:V,snippet:d})}else if(S.key===" "||S.key==="Enter"){if(C===null)return;let V=z1(x)[C];if(!V)return;let d=V.getAttribute("data-md");if(d==="choice-option"||d==="multichoice-option")S.preventDefault(),V.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(d==="userinput"){S.preventDefault();let r=V.querySelector("textarea");if(r){r.focus();let s=(X1)=>{if(X1.key==="Escape")X1.preventDefault(),r.blur(),h(!0)};r.addEventListener("keydown",s),r.addEventListener("blur",()=>r.removeEventListener("keydown",s),{once:!0})}}else if(d==="rangeinput"){S.preventDefault();let r=V.querySelector("input[type='range']");if(r){r.focus();let s=(X1)=>{if(X1.key==="Escape"||X1.key==="ArrowUp"||X1.key==="ArrowDown")X1.preventDefault(),r.blur(),h(!0)};r.addEventListener("keydown",s),r.addEventListener("blur",()=>r.removeEventListener("keydown",s),{once:!0})}}}else if(S.key==="Escape")H(null),h(!1),N(null)};return document.addEventListener("keydown",B),()=>document.removeEventListener("keydown",B)},[C,j,O,y,c]),$1(()=>{let B=q.current;if(!B||C===null||!M)return;let m=z1(B)[C];if(!m)return;m.style.outline="2px solid var(--color-accent-blue)",m.style.outlineOffset="-2px",m.style.borderRadius="8px",m.scrollIntoView({block:"nearest",behavior:"smooth"});let x=K1(m),E=x?c.get(x):void 0;if(E)N(E);return()=>{m.style.outline="",m.style.outlineOffset="",m.style.borderRadius=""}},[C,M,c]),$1(()=>{let B=()=>I();return document.addEventListener("mouseup",B),()=>document.removeEventListener("mouseup",B)},[]);let I=W5(()=>{let B=window.getSelection();if(!B||B.isCollapsed||!B.toString().trim())return;if(!q.current)return;let S=B.getRangeAt(0);if(!q.current.contains(S.startContainer))return;if(S.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let m=B.toString().trim();if(m.length<2)return;let x=S.cloneRange(),E=F0(S,q.current),V=`__pending_${Date.now()}`;try{L1(x,V)}catch{}window.getSelection()?.removeAllRanges();let d=document.querySelectorAll(`[data-annotation-id="${V}"]`),r=d[d.length-1];if(!r)return;b({anchorEl:r,tempId:V,snippet:m,ctx:E})},[K]),l=D1(()=>Q?p(Q,{},void 0,!1,void 0,this):null,[Q]);if(z)return p("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading plan..."},void 0,!1,void 0,this);if(Y)return p("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[p("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),p("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return p("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);let R=document.getElementById("plan-scroll-container");return p(S0,{children:[p("div",{ref:q,className:"plan-content plan-updated",children:l},void 0,!1,void 0,this),P&&p(O5,{note:P.note,onSave:(B)=>{W(P.id,B),L(null)},onCancel:()=>L(null)},void 0,!1,void 0,this),y&&(()=>{let B=U.find((S)=>S.id===y.annId);if(!B)return null;return p(B1,{anchorEl:y.anchorEl,scrollContainer:R,initialNote:B.note,onUpdate:(S)=>W(y.annId,S),onDelete:()=>{G(y.annId),N(null)},onClose:()=>w(null)},void 0,!1,void 0,this)})(),O&&p(M1,{anchorEl:O.anchorEl,scrollContainer:R,snippet:O.snippet,truncateAt:80,onAdd:(B)=>{let S=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;I1(O.tempId,S),K(S,O.snippet,B,void 0,O.ctx),b(null)},onCancel:()=>{j1(O.tempId),b(null)}},void 0,!1,void 0,this),p(N5,{containerRef:q,hoveredBlock:v,focusedBlockIndex:C,blockPopover:j,blockAnnotationMap:c,activeAnnotationId:T,onOpen:(B,S,m)=>{if(m)N(m),A({anchorEl:B,snippet:S,annId:m});else A({anchorEl:B,snippet:S})}},void 0,!1,void 0,this),j&&!j.annId&&p(M1,{anchorEl:j.anchorEl,scrollContainer:R,snippet:j.snippet,truncateAt:80,onAdd:(B)=>{let S=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;K(S,j.snippet,B),A(null)},onCancel:()=>A(null)},void 0,!1,void 0,this),j?.annId&&(()=>{let B=U.find((S)=>S.id===j.annId);if(!B)return null;return p(B1,{anchorEl:j.anchorEl,scrollContainer:R,initialNote:B.note,onUpdate:(S)=>W(j.annId,S),onDelete:()=>{G(j.annId),N(null),A(null)},onClose:()=>A(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function z1($){return Array.from($.querySelectorAll(s1))}function K1($){let J=$.getAttribute("data-md");if(J==="item"){let Q=$.getAttribute("data-md-label");return Q?`[Item] ${Q}`:null}if(J==="section"){let Q=$.getAttribute("data-md-title");return Q?`[Section] ${Q}`:null}if(J==="callout"){let Q=$.getAttribute("data-md-type")||"info",Z=$.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Q}] ${Z}`}if(J==="note")return`[Note] ${$.textContent?.trim().slice(0,60)||"Note"}`;if($.tagName==="TR"){let Q=Array.from($.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}if(J==="checklist-item"){let Q=$.getAttribute("data-md-label");return Q?`[Checklist] ${Q}`:null}if(J==="choice-option"||J==="multichoice-option"){let Q=$.getAttribute("data-md-label");return Q?`[Option] ${Q}`:null}if(J==="userinput"){let Q=$.getAttribute("data-md-label");return Q?`[Input] ${Q}`:null}if(J==="rangeinput"){let Q=$.getAttribute("data-md-label");return Q?`[Range] ${Q}`:null}if(J==="image"){let Q=$.getAttribute("data-md-src");return Q?`[Image] ${Q}`:null}return null}function N5({containerRef:$,hoveredBlock:J,focusedBlockIndex:Q,blockPopover:Z,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:z}){let[_,q]=n([]);$1(()=>{let T=$.current;if(!T||Y.size===0){q([]);return}let N=[];for(let P of T.querySelectorAll(o1)){let L=K1(P);if(L&&Y.has(L))N.push(P)}q(N)},[Y,$.current]);let[U,K]=n(null);$1(()=>{if(!X||!$.current){K(null);return}for(let T of $.current.querySelectorAll(s1)){let N=K1(T);if(N&&Y.get(N)===X){K(T);return}}K(null)},[X,Y]),$1(()=>{if(!U)return;return U.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",U.style.borderRadius="8px",()=>{U.style.boxShadow="",U.style.borderRadius=""}},[U]);let G=D1(()=>{if(Q===null||!$.current)return null;let T=z1($.current)[Q];if(!T)return null;return T.matches(o1)?T:null},[Q,$.current]),W=D1(()=>{let T=new Set(_);if(J)T.add(J);if(G)T.add(G);if(Z?.anchorEl)T.add(Z.anchorEl);return Array.from(T)},[_,J,G,Z]);return p(S0,{children:W.map((T)=>p(L5,{block:T,isHovered:T===J||T===G||T===Z?.anchorEl,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:z},T.getAttribute("data-task-id")||T.getAttribute("data-md-title")||T.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function L5({block:$,isHovered:J,blockAnnotationMap:Q,activeAnnotationId:Z,onOpen:Y}){let X=K1($);if(!X)return null;let z=Q.get(X),_=!!z;return T5(p("button",{"data-block-comment-btn":!0,onClick:(U)=>{U.stopPropagation(),Y(U.currentTarget,X,z)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${_?z===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":J?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:_?"Edit annotation":"Add annotation",children:p("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:_?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:p("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),$)}function O5({note:$,onSave:J,onCancel:Q}){let[Z,Y]=a1.useState($),X=a1.useRef(null);return a1.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),p("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:p("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(z)=>z.stopPropagation(),children:[p("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),p("textarea",{ref:X,value:Z,onChange:(z)=>Y(z.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(z)=>{if(z.key==="Enter"&&(z.ctrlKey||z.metaKey))J(Z.trim());if(z.key==="Escape")Q()}},void 0,!1,void 0,this),p("div",{className:"flex justify-end gap-2 mt-2",children:[p("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),p("button",{onClick:()=>J(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import C5,{useRef as I0,useEffect as m0,useCallback as b0,useState as $0,useContext as j0}from"react";function y1($,J,Q,Z){let Y=[],X=$.filter((K)=>!K.filePath),z=$.filter((K)=>K.filePath),_=Q?Array.from(Q.values()).filter((K)=>t1(K)):[],q=Z?Array.from(Z.values()).filter((K)=>K.markdown.trim()):[];if(_.length>0||q.length>0){Y.push("## Responses"),Y.push("");for(let K of _)Y.push(M5(K));for(let K of q)Y.push(K.markdown.trim()),Y.push("")}if(X.length>0){Y.push("## Plan annotations"),Y.push("");let K=B5(X);Y.push(w0(K))}if(z.length>0){let K={};for(let G of z){let W=G.filePath;if(!K[W])K[W]=[];K[W].push(G)}Y.push("## File annotations"),Y.push("");for(let[G,W]of Object.entries(K)){Y.push(`### ${G}`),Y.push("");for(let T of W)Y.push(A0(T))}}if(J.trim())Y.push("## General notes"),Y.push(""),Y.push(J.trim()),Y.push("");return Y.join(`
41
+ `}}function R1($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Z of Q)Z.setAttribute("data-annotation-id",J)}function b1($,J){let Q=J.filter((q)=>!document.querySelector(`[data-annotation-id="${q.id}"]`));if(!Q.length)return;let Z=[],Y="",X=document.createTreeWalker($,NodeFilter.SHOW_TEXT),z;while(z=X.nextNode()){if(z.parentElement?.classList.contains("select-none"))continue;Z.push({node:z,start:Y.length}),Y+=z.textContent||""}for(let q of Q){let _=q.snippet;if(!_)continue;let U=[],K=0;while(!0){let O=Y.indexOf(_,K);if(O===-1)break;U.push(O),K=O+1}if(U.length===0)continue;let G=U[0];if(U.length>1&&q.context){let O=-1;for(let P of U){let w=0;if(q.context.before){let B=Y.slice(Math.max(0,P-80),P);if(B.includes(q.context.before))w+=2;else if(q.context.before.length>10&&B.includes(q.context.before.slice(-10)))w+=1}if(q.context.after){let B=Y.slice(P+_.length,P+_.length+80);if(B.includes(q.context.after))w+=2;else if(q.context.after.length>10&&B.includes(q.context.after.slice(0,10)))w+=1}if(w>O)O=w,G=P}}let W=G,T=G+_.length,N=W0(Z,W),S=W0(Z,T);if(!N||!S)continue;try{let O=document.createRange();O.setStart(N.node,N.offset),O.setEnd(S.node,S.offset),L1(O,q.id)}catch{}}}function W0($,J){for(let Q=$.length-1;Q>=0;Q--)if($[Q].start<=J){let Z=J-$[Q].start,Y=$[Q].node.textContent?.length??0;if(Z<=Y)return{node:$[Q].node,offset:Z}}return null}function j1($){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Q of J){let Z=Q.parentNode;if(!Z)continue;while(Q.firstChild)Z.insertBefore(Q.firstChild,Q);Z.removeChild(Q),Z.normalize()}}function F0($,J){let Q=T0($,"before",60),Z=T0($,"after",60),Y=K5($.startContainer,J);return{before:Q,after:Z,hierarchy:Y}}function T0($,J,Q){let Z=U5(J==="before"?$.startContainer:$.endContainer);if(!Z)return"";let Y="";if(J==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),z;while(z=X.nextNode()){if(z===$.startContainer){Y+=(z.textContent||"").slice(0,$.startOffset);break}if(z.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=z.textContent||""}if(Y.length>Q){Y=Y.slice(-Q);let q=Y.indexOf(" ");if(q>0)Y=Y.slice(q+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),z=!1,q;while(q=X.nextNode()){if(q===$.endContainer){Y+=(q.textContent||"").slice($.endOffset),z=!0;continue}if(z){if(q.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=q.textContent||""}}if(Y.length>Q){Y=Y.slice(0,Q);let _=Y.lastIndexOf(" ");if(_>0)Y=Y.slice(0,_)}}return Y.trim()}function U5($){let J=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=$.parentElement;while(Q){if(J.has(Q.tagName))return Q;Q=Q.parentElement}return null}function K5($,J){let Q=[],Z=$ instanceof Element?$:$.parentElement;while(Z&&Z!==J){let Y=Z.getAttribute?.("data-task-id");if(Y){let X=Z.querySelector(".font-semibold");if(X)Q.unshift(X.textContent?.trim()||Y)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Q.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Q}function N0($){let J=$.snippet.trim(),Q=$.context,Z=J.length<30;if(Q&&Z&&(Q.before||Q.after)){let Y=[];if(Q.before)Y.push(`...${Q.before} `);if(Y.push(J),Q.after)Y.push(` ${Q.after}...`);return Y.join("")}return J}import{useEffect as m1,useRef as V1,useState as O1,useCallback as i1,useMemo as O0}from"react";import{createPortal as G5}from"react-dom";function L0($,J){let Y=J||document.body,X=$.getBoundingClientRect(),z=Y.getBoundingClientRect(),q=Y===document.body?window.scrollY:Y.scrollTop,_=X.bottom-z.top+q+8,U=Math.max(0,Math.min(X.left-z.left,z.width-280-12));return Y.style.position="relative",{style:{position:"absolute",top:`${_}px`,left:`${U}px`},parent:Y}}import{jsxDEV as r}from"react/jsx-dev-runtime";function B0({anchorEl:$,scrollContainer:J,onClose:Q,ignoreSelector:Z,zIndex:Y="50",padding:X="12px",width:z="280px",children:q}){let _=V1(null),U=V1(Q);U.current=Q;let{style:K,parent:G}=L0($,J);return m1(()=>{let W=setTimeout(()=>{let T=(N)=>{if(_.current&&!_.current.contains(N.target)){if(Z&&N.target.closest?.(Z))return;U.current(),document.removeEventListener("mousedown",T)}};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},0);return()=>clearTimeout(W)},[Z]),G5(r("div",{ref:_,style:{...K,zIndex:Y,width:z,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:q},void 0,!1,void 0,this),G)}var y0=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],M0=y0.flatMap(($)=>$.items);function M1({anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:Z=100,header:Y,onAdd:X,onCancel:z}){let[q,_]=O1(""),[U,K]=O1(null),[G,W]=O1(!1),T=V1(null);m1(()=>{T.current?.focus()},[]);let N=i1(()=>{if(q.trim())X(q.trim());else z()},[q,X,z]),S=q.trim().length>0?M0.filter((H)=>H.toLowerCase().startsWith(q.trim().toLowerCase())):M0,O=G?[]:S.length===1&&S[0].toLowerCase()===q.trim().toLowerCase()?[]:S,P=new Set(O),w=y0.map((H)=>({label:H.label,items:H.items.filter((y)=>P.has(y))})).filter((H)=>H.items.length>0),B=w.map((H)=>H.items),R=B.flat(),D=O0(()=>{if(U===null)return 0;let H=0;for(let y=0;y<B.length;y++){if(U<H+B[y].length)return y;H+=B[y].length}return 0},[U,B]),m=O0(()=>{if(U===null)return 0;let H=0;for(let y=0;y<D;y++)H+=B[y].length;return U-H},[U,D,B]),j=(H,y)=>{let E=0;for(let c=0;c<H;c++)E+=B[c].length;return E+y};m1(()=>{K(null),W(!1)},[q]);let C=i1((H)=>{_(H)},[]),I=Q.length>Z?Q.slice(0,Z)+"...":Q;return r(B0,{anchorEl:$,scrollContainer:J,onClose:z,width:"420px",children:[Y??r("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",I,"”"]},void 0,!0,void 0,this),r("textarea",{ref:T,value:q,onChange:(H)=>_(H.target.value),onKeyDown:(H)=>{if(R.length>0&&(H.key==="ArrowDown"||H.key==="ArrowUp"||H.key==="ArrowLeft"||H.key==="ArrowRight")){if(H.preventDefault(),U===null){K(0);return}if(H.key==="ArrowDown"){let y=Math.min(m+1,B[D].length-1);K(j(D,y))}else if(H.key==="ArrowUp"){let y=Math.max(m-1,0);K(j(D,y))}else if(H.key==="ArrowRight"){let y=Math.min(D+1,B.length-1),E=Math.min(m,B[y].length-1);K(j(y,E))}else if(H.key==="ArrowLeft"){let y=Math.max(D-1,0),E=Math.min(m,B[y].length-1);K(j(y,E))}return}if(U!==null&&R.length>0){if(H.key==="Tab"){H.preventDefault(),C(R[U]);return}if(H.key==="Enter"&&!H.shiftKey){H.preventDefault(),X(R[U]);return}}if(H.key==="Enter"&&!H.shiftKey){H.preventDefault(),N();return}if(H.key==="Escape")if(R.length>0&&!G)W(!0);else z()},style:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),r("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"8px"},children:[r("button",{onClick:z,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),r("button",{onClick:N,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R.length>0&&r("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:w.map((H)=>r("div",{style:{flex:1},children:[r("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:H.label},void 0,!1,void 0,this),H.items.map((y)=>{let E=R.indexOf(y);return r("div",{onMouseDown:(c)=>{c.preventDefault(),c.stopPropagation(),C(y)},onMouseEnter:()=>K(E),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:E===U?"var(--color-text-primary)":"var(--color-text-secondary)",background:E===U?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[r("span",{style:{fontWeight:500},children:y.slice(0,q.trim().length)},void 0,!1,void 0,this),y.slice(q.trim().length)]},y,!0,void 0,this)})]},H.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B1({anchorEl:$,scrollContainer:J,initialNote:Q,onUpdate:Z,onDelete:Y,onClose:X}){let[z,q]=O1(Q),_=V1(null),[U,K]=O1(!1);m1(()=>{let W=_.current;if(W)W.style.height="auto",W.style.height=W.scrollHeight+"px",W.focus(),W.setSelectionRange(W.value.length,W.value.length)},[]);let G=i1(()=>{if(!z.trim()){Y(),X();return}Z(z),X()},[z,Z,Y,X]);return r(B0,{anchorEl:$,scrollContainer:J,onClose:G,ignoreSelector:"[data-annotation-id]",zIndex:"60",padding:"10px 12px",children:[r("textarea",{ref:_,value:z,onChange:(W)=>{q(W.target.value),Z(W.target.value),W.target.style.height="auto",W.target.style.height=W.target.scrollHeight+"px"},onKeyDown:(W)=>{if(W.key==="Enter"&&!W.shiftKey)W.preventDefault(),G();if(W.key==="Escape")G()},style:{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}},void 0,!1,void 0,this),r("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"6px"},children:r("button",{onClick:()=>{Y(),X()},onMouseEnter:()=>K(!0),onMouseLeave:()=>K(!1),style:{fontSize:"11px",color:U?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as x,Fragment as S0}from"react/jsx-dev-runtime";var s1="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",o1="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function P0({revision:$}){let J=W5(N5),[Q,Z]=s(null),[Y,X]=s(null),[z,q]=s(!0),_=H5(null),{annotations:U,addAnnotationWithId:K,removeAnnotation:G,updateAnnotation:W,activeAnnotationId:T,setActiveAnnotationId:N}=o(),[S,O]=s(null),[P,w]=s(null),[B,R]=s(null),[D,m]=s(null),[j,C]=s(null),[I,H]=s(null),[y,E]=s(!1);n(()=>{q(!0),X(null),H(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((L)=>{Z(()=>L.default),q(!1)}).catch((L)=>{X(L.message),q(!1)})},[J,$]),n(()=>{if(!Q||!_.current)return;let L=setTimeout(()=>{if(_.current)b1(_.current,U)},50);return()=>clearTimeout(L)},[Q]),n(()=>{I1(T)},[T]),n(()=>{let L=_.current;if(!L)return;let A=(b)=>{let V=b.target.closest("[data-annotation-id]");if(!V)return;b.stopPropagation();let p=V.getAttribute("data-annotation-id");if(p===T)w({anchorEl:V,annId:p});else N(p)},u=(b)=>{let V=b.target.closest("[data-annotation-id]");if(V){let p=V.getAttribute("data-annotation-id");N(p)}},h=(b)=>{let V=b.target.closest("[data-annotation-id]"),p=b.relatedTarget?.closest?.("[data-annotation-id]");if(V&&!p){if(!document.getElementById("ann-inline-popover"))N(null)}};return L.addEventListener("click",A),L.addEventListener("mouseover",u),L.addEventListener("mouseout",h),()=>{L.removeEventListener("click",A),L.removeEventListener("mouseover",u),L.removeEventListener("mouseout",h)}},[Q,U,T]);let c=D1(()=>{let L=new Map;for(let A of U)if(A.snippet.startsWith("["))L.set(A.snippet,A.id);return L},[U]);n(()=>{let L=_.current;if(!L)return;let A=(h)=>{if(j||B||P)return;let b=h.target;if(b.closest("[data-block-comment-btn]"))return;E(!1);let V=b.closest(s1);if(V&&L.contains(V)){let a=z1(L).indexOf(V);H(a>=0?a:null)}else H(null);let p=b.closest(o1);if(p&&L.contains(p)){m(p);let d=K1(p),a=d?c.get(d):void 0;if(a&&a!==T)N(a)}else m(null)},u=(h)=>{if(j||B||P)return;if(h.relatedTarget?.closest("[data-block-comment-btn]"))return;m(null),N(null)};return L.addEventListener("mousemove",A),L.addEventListener("mouseleave",u),()=>{L.removeEventListener("mousemove",A),L.removeEventListener("mouseleave",u)}},[Q,j,B,P,c,T]),n(()=>{let L=(A)=>{let u=A.target.tagName;if(u==="INPUT"||u==="TEXTAREA"||A.target.isContentEditable)return;if(j||B||P)return;let h=_.current;if(!h)return;if(A.key==="ArrowDown"){A.preventDefault(),E(!0);let b=z1(h);if(b.length===0)return;H((V)=>{if(V===null)return 0;return Math.min(V+1,b.length-1)})}else if(A.key==="ArrowUp"){A.preventDefault(),E(!0);let b=z1(h);if(b.length===0)return;H((V)=>{if(V===null)return b.length-1;return Math.max(V-1,0)})}else if(A.key==="a"||A.key==="A"){if(I===null||!h)return;A.preventDefault();let V=z1(h)[I];if(!V)return;let p=K1(V);if(!p)return;let d=c.get(p);if(d)N(d),C({anchorEl:V,snippet:p,annId:d});else C({anchorEl:V,snippet:p})}else if(A.key===" "||A.key==="Enter"){if(I===null)return;let V=z1(h)[I];if(!V)return;let p=V.getAttribute("data-md");if(p==="choice-option"||p==="multichoice-option")A.preventDefault(),V.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(p==="userinput"){A.preventDefault();let d=V.querySelector("textarea");if(d){d.focus();let a=(X1)=>{if(X1.key==="Escape")X1.preventDefault(),d.blur(),E(!0)};d.addEventListener("keydown",a),d.addEventListener("blur",()=>d.removeEventListener("keydown",a),{once:!0})}}else if(p==="rangeinput"){A.preventDefault();let d=V.querySelector("input[type='range']");if(d){d.focus();let a=(X1)=>{if(X1.key==="Escape"||X1.key==="ArrowUp"||X1.key==="ArrowDown")X1.preventDefault(),d.blur(),E(!0)};d.addEventListener("keydown",a),d.addEventListener("blur",()=>d.removeEventListener("keydown",a),{once:!0})}}}else if(A.key==="Escape")H(null),E(!1),N(null)};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[I,j,B,P,c]),n(()=>{let L=_.current;if(!L||I===null||!y)return;let u=z1(L)[I];if(!u)return;u.style.outline="2px solid var(--color-accent-blue)",u.style.outlineOffset="-2px",u.style.borderRadius="8px",u.scrollIntoView({block:"nearest",behavior:"smooth"});let h=K1(u),b=h?c.get(h):void 0;if(b)N(b);return()=>{u.style.outline="",u.style.outlineOffset="",u.style.borderRadius=""}},[I,y,c]),n(()=>{let L=()=>$1();return document.addEventListener("mouseup",L),()=>document.removeEventListener("mouseup",L)},[]);let $1=T5(()=>{let L=window.getSelection();if(!L||L.isCollapsed||!L.toString().trim())return;if(!_.current)return;let A=L.getRangeAt(0);if(!_.current.contains(A.startContainer))return;if(A.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let u=L.toString().trim();if(u.length<2)return;let h=A.cloneRange(),b=F0(A,_.current),V=`__pending_${Date.now()}`;try{L1(h,V)}catch{}window.getSelection()?.removeAllRanges();let p=document.querySelectorAll(`[data-annotation-id="${V}"]`),d=p[p.length-1];if(!d)return;R({anchorEl:d,tempId:V,snippet:u,ctx:b})},[K]),Q1=D1(()=>Q?x(Q,{},void 0,!1,void 0,this):null,[Q]);if(z)return x("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading plan..."},void 0,!1,void 0,this);if(Y)return x("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[x("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),x("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return x("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);let M=document.getElementById("plan-scroll-container");return x(S0,{children:[x("div",{ref:_,className:"plan-content plan-updated",children:Q1},void 0,!1,void 0,this),S&&x(M5,{note:S.note,onSave:(L)=>{W(S.id,L),O(null)},onCancel:()=>O(null)},void 0,!1,void 0,this),P&&(()=>{let L=U.find((A)=>A.id===P.annId);if(!L)return null;return x(B1,{anchorEl:P.anchorEl,scrollContainer:M,initialNote:L.note,onUpdate:(A)=>W(P.annId,A),onDelete:()=>{G(P.annId),N(null)},onClose:()=>w(null)},void 0,!1,void 0,this)})(),B&&x(M1,{anchorEl:B.anchorEl,scrollContainer:M,snippet:B.snippet,truncateAt:80,onAdd:(L)=>{let A=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;R1(B.tempId,A),K(A,B.snippet,L,void 0,B.ctx),R(null)},onCancel:()=>{j1(B.tempId),R(null)}},void 0,!1,void 0,this),x(L5,{containerRef:_,hoveredBlock:D,focusedBlockIndex:I,blockPopover:j,blockAnnotationMap:c,activeAnnotationId:T,onOpen:(L,A,u)=>{if(u)N(u),C({anchorEl:L,snippet:A,annId:u});else C({anchorEl:L,snippet:A})}},void 0,!1,void 0,this),j&&!j.annId&&x(M1,{anchorEl:j.anchorEl,scrollContainer:M,snippet:j.snippet,truncateAt:80,onAdd:(L)=>{let A=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;K(A,j.snippet,L),C(null)},onCancel:()=>C(null)},void 0,!1,void 0,this),j?.annId&&(()=>{let L=U.find((A)=>A.id===j.annId);if(!L)return null;return x(B1,{anchorEl:j.anchorEl,scrollContainer:M,initialNote:L.note,onUpdate:(A)=>W(j.annId,A),onDelete:()=>{G(j.annId),N(null),C(null)},onClose:()=>C(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function z1($){return Array.from($.querySelectorAll(s1))}function K1($){let J=$.getAttribute("data-md");if(J==="item"){let Q=$.getAttribute("data-md-label");return Q?`[Item] ${Q}`:null}if(J==="section"){let Q=$.getAttribute("data-md-title");return Q?`[Section] ${Q}`:null}if(J==="callout"){let Q=$.getAttribute("data-md-type")||"info",Z=$.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Q}] ${Z}`}if(J==="note")return`[Note] ${$.textContent?.trim().slice(0,60)||"Note"}`;if($.tagName==="TR"){let Q=Array.from($.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}if(J==="checklist-item"){let Q=$.getAttribute("data-md-label");return Q?`[Checklist] ${Q}`:null}if(J==="choice-option"||J==="multichoice-option"){let Q=$.getAttribute("data-md-label");return Q?`[Option] ${Q}`:null}if(J==="userinput"){let Q=$.getAttribute("data-md-label");return Q?`[Input] ${Q}`:null}if(J==="rangeinput"){let Q=$.getAttribute("data-md-label");return Q?`[Range] ${Q}`:null}if(J==="image"){let Q=$.getAttribute("data-md-src");return Q?`[Image] ${Q}`:null}return null}function L5({containerRef:$,hoveredBlock:J,focusedBlockIndex:Q,blockPopover:Z,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:z}){let[q,_]=s([]);n(()=>{let T=$.current;if(!T||Y.size===0){_([]);return}let N=[];for(let S of T.querySelectorAll(o1)){let O=K1(S);if(O&&Y.has(O))N.push(S)}_(N)},[Y,$.current]);let[U,K]=s(null);n(()=>{if(!X||!$.current){K(null);return}for(let T of $.current.querySelectorAll(s1)){let N=K1(T);if(N&&Y.get(N)===X){K(T);return}}K(null)},[X,Y]),n(()=>{if(!U)return;return U.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",U.style.borderRadius="8px",()=>{U.style.boxShadow="",U.style.borderRadius=""}},[U]);let G=D1(()=>{if(Q===null||!$.current)return null;let T=z1($.current)[Q];if(!T)return null;return T.matches(o1)?T:null},[Q,$.current]),W=D1(()=>{let T=new Set(q);if(J)T.add(J);if(G)T.add(G);if(Z?.anchorEl)T.add(Z.anchorEl);return Array.from(T)},[q,J,G,Z]);return x(S0,{children:W.map((T)=>x(O5,{block:T,isHovered:T===J||T===G||T===Z?.anchorEl,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:z},T.getAttribute("data-task-id")||T.getAttribute("data-md-title")||T.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function O5({block:$,isHovered:J,blockAnnotationMap:Q,activeAnnotationId:Z,onOpen:Y}){let X=K1($);if(!X)return null;let z=Q.get(X),q=!!z;return F5(x("button",{"data-block-comment-btn":!0,onClick:(U)=>{U.stopPropagation(),Y(U.currentTarget,X,z)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${q?z===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":J?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:q?"Edit annotation":"Add annotation",children:x("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:q?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:x("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),$)}function M5({note:$,onSave:J,onCancel:Q}){let[Z,Y]=a1.useState($),X=a1.useRef(null);return a1.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),x("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:x("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(z)=>z.stopPropagation(),children:[x("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),x("textarea",{ref:X,value:Z,onChange:(z)=>Y(z.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(z)=>{if(z.key==="Enter"&&(z.ctrlKey||z.metaKey))J(Z.trim());if(z.key==="Escape")Q()}},void 0,!1,void 0,this),x("div",{className:"flex justify-end gap-2 mt-2",children:[x("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),x("button",{onClick:()=>J(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import R5,{useRef as R0,useEffect as m0,useCallback as b0,useState as $0,useContext as j0}from"react";function y1($,J,Q,Z){let Y=[],X=$.filter((K)=>!K.filePath),z=$.filter((K)=>K.filePath),q=Q?Array.from(Q.values()).filter((K)=>t1(K)):[],_=Z?Array.from(Z.values()).filter((K)=>K.markdown.trim()):[];if(q.length>0||_.length>0){Y.push("## Responses"),Y.push("");for(let K of q)Y.push(B5(K));for(let K of _)Y.push(K.markdown.trim()),Y.push("")}if(X.length>0){Y.push("## Plan annotations"),Y.push("");let K=y5(X);Y.push(w0(K))}if(z.length>0){let K={};for(let G of z){let W=G.filePath;if(!K[W])K[W]=[];K[W].push(G)}Y.push("## File annotations"),Y.push("");for(let[G,W]of Object.entries(K)){Y.push(`### ${G}`),Y.push("");for(let T of W)Y.push(A0(T))}}if(J.trim())Y.push("## General notes"),Y.push(""),Y.push(J.trim()),Y.push("");return Y.join(`
42
42
  `).trim()+`
43
- `}function t1($){if($.note?.trim())return!0;if($.value===null||$.value===void 0)return!1;if($.type==="text"&&!$.value.trim())return!1;if($.type==="checkbox"&&$.value.length===0)return!1;return!0}function g1($){let J=[];for(let Q of $.values()){if(!Q.required)continue;if(Q.value===null||Q.value===void 0){J.push(Q);continue}if(Q.type==="text"&&!Q.value.trim()){J.push(Q);continue}if(Q.type==="checkbox"&&Q.value.length===0){J.push(Q);continue}}return J}function f1($){let J=[];for(let Q of $.values())if(Q.required&&!Q.markdown.trim())J.push(Q);return J}function M5($){let J=[];switch(J.push(`**${$.label}**`),$.type){case"radio":case"select":J.push(`Answer: ${$.value}`);break;case"checkbox":for(let Q of $.value)J.push(`- [x] ${Q}`);break;case"text":J.push(""),J.push($.value.trim());break;case"range":J.push(`Answer: ${$.value}`);break}if($.note?.trim())J.push(""),J.push(`Note: ${$.note.trim()}`);return J.push(""),J.join(`
43
+ `}function t1($){if($.note?.trim())return!0;if($.value===null||$.value===void 0)return!1;if($.type==="text"&&!$.value.trim())return!1;if($.type==="checkbox"&&$.value.length===0)return!1;return!0}function g1($){let J=[];for(let Q of $.values()){if(!Q.required)continue;if(Q.value===null||Q.value===void 0){J.push(Q);continue}if(Q.type==="text"&&!Q.value.trim()){J.push(Q);continue}if(Q.type==="checkbox"&&Q.value.length===0){J.push(Q);continue}}return J}function f1($){let J=[];for(let Q of $.values())if(Q.required&&!Q.markdown.trim())J.push(Q);return J}function B5($){let J=[];switch(J.push(`**${$.label}**`),$.type){case"radio":case"select":J.push(`Answer: ${$.value}`);break;case"checkbox":for(let Q of $.value)J.push(`- [x] ${Q}`);break;case"text":J.push(""),J.push($.value.trim());break;case"range":J.push(`Answer: ${$.value}`);break}if($.note?.trim())J.push(""),J.push(`Note: ${$.note.trim()}`);return J.push(""),J.join(`
44
44
  `)}function A0($){let J=[],Q=$.snippet.trim(),Z=N0($);if(Q.split(`
45
45
  `).length<=3)J.push(`> ${Z.split(`
46
46
  `).join(`
47
47
  > `)}`);else{let Y=Q.split(`
48
48
  `);J.push(`> ${Y[0]}`),J.push(`> ... (${Y.length} lines)`),J.push(`> ${Y[Y.length-1]}`)}if($.note.trim())J.push(""),J.push($.note.trim());return J.push(""),J.join(`
49
- `)}function B5($){let J={label:"",annotations:[],children:new Map};for(let Q of $){let Z=Q.context?.hierarchy||[],Y=J;for(let X of Z){if(!Y.children.has(X))Y.children.set(X,{label:X,annotations:[],children:new Map});Y=Y.children.get(X)}Y.annotations.push(Q)}return J}function w0($,J=0){let Q=[];for(let Z of $.annotations)Q.push(A0(Z));for(let[,Z]of $.children){let Y=J===0?"###":"####";Q.push(`${Y} ${Z.label}`),Q.push(""),Q.push(w0(Z,J+1))}return Q.join(`
50
- `)}import{SessionContext as I5}from"#canvas/runtime";import{useEffect as n1,useState as k1,useRef as y5,useMemo as P5}from"react";import{jsxDEV as f,Fragment as A5}from"react/jsx-dev-runtime";function C0({open:$,onClose:J,onSubmit:Q}){let{annotations:Z,generalNote:Y,responses:X,feedbackEntries:z}=t(),[_,q]=k1(""),[U,K]=k1(!1),[G,W]=k1(!1),[T,N]=k1(null),P=y5(null);if(n1(()=>{if(!$){K(!1),W(!1),N(null);return}if(U)return;q(y1(Z,Y,X,z))},[Z,Y,X,z,U,$]),n1(()=>{if($&&G&&P.current)P.current.focus()},[$,G]),n1(()=>{if(!$)return;let y=(w)=>{if(w.key==="Escape")J()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[$,J]),!$)return null;let L=_.trim().length>0;return f("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:J,children:f("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(y)=>y.stopPropagation(),children:[f("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[f("div",{className:"flex items-center gap-3",children:[f("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),U&&f("button",{onClick:()=>{K(!1),W(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-2",children:[f("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[f("button",{onClick:()=>W(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!G?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),f("button",{onClick:()=>W(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${G?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("button",{onClick:J,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),G?f("textarea",{ref:P,value:_,onChange:(y)=>{q(y.target.value),K(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):f("div",{className:"flex-1 overflow-y-auto p-5",children:f(e1,{text:_},void 0,!1,void 0,this)},void 0,!1,void 0,this),T&&f("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[f("span",{children:T},void 0,!1,void 0,this),f("button",{onClick:()=>{N(null),Q(_)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[f("button",{onClick:J,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),f("button",{onClick:()=>{let y=g1(X),w=f1(z),O=[...y.map((b)=>b.label),...w.map((b)=>b.label||b.id)];if(O.length>0){N(`Please answer: ${O.join(", ")}`);return}N(null),Q(_)},disabled:!L,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${L?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function e1({text:$}){let J=P5(()=>S5($),[$]);return f("div",{className:"font-body text-body text-text-primary leading-relaxed",children:J},void 0,!1,void 0,this)}function R0({text:$}){let J=[],Q=/(\*\*(.+?)\*\*|`(.+?)`)/g,Z=0,Y,X=0;while((Y=Q.exec($))!==null){if(Y.index>Z)J.push($.slice(Z,Y.index));if(Y[2])J.push(f("strong",{className:"font-semibold text-text-primary",children:Y[2]},X++,!1,void 0,this));else if(Y[3])J.push(f("code",{className:"font-mono text-code bg-bg-code px-1 py-px rounded",children:Y[3]},X++,!1,void 0,this));Z=Q.lastIndex}if(Z<$.length)J.push($.slice(Z));return f(A5,{children:J},void 0,!1,void 0,this)}function S5($){let J=$.split(`
51
- `),Q=[],Z=0,Y=0;while(Z<J.length){let X=J[Z];if(X.startsWith("#### ")){Q.push(f("h4",{className:"text-[13px] font-body font-semibold text-text-primary mt-5 mb-1",children:X.slice(5)},Y++,!1,void 0,this)),Z++;continue}if(X.startsWith("### ")){Q.push(f("h3",{className:"text-[14px] font-body font-semibold text-text-primary mt-5 mb-1",children:X.slice(4)},Y++,!1,void 0,this)),Z++;continue}if(X.startsWith("## ")){Q.push(f("h2",{className:"text-task-label font-body font-semibold text-text-primary mt-6 mb-2 pb-1 border-b border-border-subtle",children:X.slice(3)},Y++,!1,void 0,this)),Z++;continue}if(X.startsWith("> ")){let z=[];while(Z<J.length&&J[Z].startsWith("> "))z.push(J[Z].slice(2)),Z++;Q.push(f("blockquote",{className:"border-l-2 border-border-hover pl-3 my-2 text-text-secondary italic text-[13px]",children:z.map((_,q)=>f("div",{children:_},q,!1,void 0,this))},Y++,!1,void 0,this));continue}if(X.startsWith("- [x] ")||X.startsWith("- [ ] ")){let z=[];while(Z<J.length&&(J[Z].startsWith("- [x] ")||J[Z].startsWith("- [ ] ")))z.push({checked:J[Z].startsWith("- [x] "),label:J[Z].slice(6)}),Z++;Q.push(f("ul",{className:"my-1 space-y-0.5",children:z.map((_,q)=>f("li",{className:"flex items-center gap-2 text-[13px]",children:[f("span",{className:`w-3.5 h-3.5 rounded flex items-center justify-center flex-shrink-0 ${_.checked?"bg-accent-amber":"border border-border-hover"}`,children:_.checked&&f("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"none",children:f("path",{d:"M2.5 5L4.5 7L7.5 3",style:{stroke:"var(--color-text-inverse)"},strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("span",{className:_.checked?"text-text-primary":"text-text-tertiary",children:_.label},void 0,!1,void 0,this)]},q,!0,void 0,this))},Y++,!1,void 0,this));continue}if(X.startsWith("- ")){let z=[];while(Z<J.length&&J[Z].startsWith("- "))z.push(J[Z].slice(2)),Z++;Q.push(f("ul",{className:"my-1 space-y-0.5 list-disc list-inside",children:z.map((_,q)=>f("li",{className:"text-[13px] text-text-secondary",children:f(R0,{text:_},void 0,!1,void 0,this)},q,!1,void 0,this))},Y++,!1,void 0,this));continue}if(X.trim()===""){Z++;continue}Q.push(f("p",{className:"my-1.5 text-[13px]",children:f(R0,{text:X},void 0,!1,void 0,this)},Y++,!1,void 0,this)),Z++}return Q}import{jsxDEV as q1}from"react/jsx-dev-runtime";var w5={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},R5={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function P1({name:$,type:J,expanded:Q,className:Z=""}){if(J==="dir")return q1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Q?q1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):q1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=$.includes(".")?$.split(".").pop().toLowerCase():"",X=w5[Y]||"#6b6560",z=R5[Y];return q1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[q1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:X,opacity:"0.85"},void 0,!1,void 0,this),q1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),z&&q1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as g}from"react/jsx-dev-runtime";function J0({onPreview:$,onSubmit:J,collapseButton:Q}){let{isReadOnly:Z,selectedRevision:Y,currentRevision:X,revisions:z}=j0(H1),_=j0(I5),q=Z&&Y===X,K=z.find((G)=>G.revision===Y)?.label||`Round ${Y}`;if(Z)return g(b5,{sessionId:_,revision:Y,label:K,waitingForUpdate:q,collapseButton:Q},void 0,!1,void 0,this);return g(j5,{onPreview:$,onSubmit:J,collapseButton:Q},void 0,!1,void 0,this)}function b5({sessionId:$,revision:J,label:Q,waitingForUpdate:Z,collapseButton:Y}){let[X,z]=$0(null),[_,q]=$0(!0);return m0(()=>{q(!0),fetch(`/api/session/${$}/revision/${J}/feedback`).then((U)=>U.json()).then((U)=>{z(U.feedback||null),q(!1)}).catch(()=>{z(null),q(!1)})},[$,J]),g("div",{className:"flex flex-col h-full",children:[g("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[g("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),Z&&g("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[g("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),g("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g("div",{className:"flex-1 overflow-y-auto px-4",children:_?g("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?g(e1,{text:X},void 0,!1,void 0,this):g("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function j5({onPreview:$,onSubmit:J,collapseButton:Q}){let{annotations:Z,updateAnnotation:Y,removeAnnotation:X,generalNote:z,setGeneralNote:_,activeAnnotationId:q,setActiveAnnotationId:U,responses:K,feedbackEntries:G}=t(),{setActiveView:W}=C5.useContext(G1),T=I0(null),N=I0(new Map),P=Z.filter((H)=>!H.filePath),L=Z.filter((H)=>H.filePath),y={};for(let H of L){let M=H.filePath;if(!y[M])y[M]=[];y[M].push(H)}m0(()=>{if(!q)return;let H=N.current.get(q);if(H)H.scrollIntoView({behavior:"smooth",block:"nearest"})},[q]);let w=b0((H)=>{U(H),l1(H,!0);let M=document.querySelector(`[data-annotation-id="${H}"]`);if(M)M.scrollIntoView({behavior:"smooth",block:"nearest"})},[U]),O=b0((H)=>{U(null),l1(H,!1)},[q]),b=Array.from(K.values()).some(t1),v=G.size>0,D=Z.length>0||z.trim().length>0||b||v,[j,A]=$0(null),C=(H)=>g("div",{ref:(M)=>{if(M)N.current.set(H.id,M);else N.current.delete(H.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${q===H.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>w(H.id),onMouseLeave:()=>O(H.id),onClick:()=>{if(H.id===q)U(null);else if(U(H.id),H.filePath)W({type:"file",path:H.filePath}),setTimeout(()=>{let M=document.querySelector(`[data-annotation-id="${H.id}"]`);if(M)M.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[g("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:H.snippet.length>80?H.snippet.slice(0,80)+"...":H.snippet},void 0,!1,void 0,this),g("textarea",{value:H.note,onChange:(M)=>Y(H.id,M.target.value),onClick:(M)=>M.stopPropagation(),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",rows:1,style:{height:"auto",overflow:"hidden"},onInput:(M)=>{let h=M.target;h.style.height="auto",h.style.height=h.scrollHeight+"px"},ref:(M)=>{if(M)M.style.height="auto",M.style.height=M.scrollHeight+"px"}},void 0,!1,void 0,this),g("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:g("button",{onClick:(M)=>{M.stopPropagation(),X(H.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:g("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[g("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),g("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},H.id,!0,void 0,this);return g("div",{className:"flex flex-col h-full",children:[g("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[g("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&g("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),g("div",{ref:T,className:"flex-1 overflow-y-auto",children:[Z.length===0&&g("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the plan or in files to add annotations."},void 0,!1,void 0,this),P.length>0&&L.length>0&&g("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),P.map(C),Object.entries(y).map(([H,M])=>g("div",{children:[g("button",{onClick:()=>W({type:"file",path:H}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:H,children:[g(P1,{name:H.split("/").pop()||H,type:"file"},void 0,!1,void 0,this),g("span",{className:"truncate",children:H},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.map(C)]},H,!0,void 0,this))]},void 0,!0,void 0,this),g("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:g("textarea",{value:z,onChange:(H)=>_(H.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(H)=>{let M=H.target;M.style.height="auto",M.style.height=Math.max(40,M.scrollHeight)+"px"},ref:(H)=>{if(H)H.style.height="auto",H.style.height=Math.max(40,H.scrollHeight)+"px"}},void 0,!1,void 0,this)},void 0,!1,void 0,this),j&&g("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[g("span",{children:j},void 0,!1,void 0,this),g("button",{onClick:()=>{A(null);let H=y1(Z,z,K,G);J(H)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:D?g("div",{className:"flex gap-2",children:[g("button",{onClick:$,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),g("button",{onClick:()=>{let H=g1(K),M=f1(G),h=[...H.map((I)=>I.label),...M.map((I)=>I.label||I.id)];if(h.length>0){A(`Please answer: ${h.join(", ")}`);return}A(null);let c=y1(Z,z,K,G);J(c)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):g("button",{onClick:()=>J("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as m5,useState as V0,useContext as D0}from"react";import{SessionContext as V5}from"#canvas/runtime";import{jsxDEV as u,Fragment as Q0}from"react/jsx-dev-runtime";function g0({embedded:$}={}){let J=D0(V5),{annotations:Q,addAnnotation:Z}=t(),{setActiveView:Y}=D0(G1),[X,z]=V0(!1),[_,q]=V0({}),U=Q.filter((O)=>O.filePath),K=new Map;for(let O of U)K.set(O.filePath,(K.get(O.filePath)||0)+1);let G=[...K.keys()],W=async(O)=>{let v=await(await fetch(`/api/tree?session=${J}&path=${encodeURIComponent(O)}`)).json();if(v.entries)q((D)=>({...D,[O]:{entries:v.entries,expanded:!0,loaded:!0}}))};m5(()=>{if(!X&&!_[""])W("")},[X]);let T=(O)=>{if(_[O]?.loaded)q((b)=>({...b,[O]:{...b[O],expanded:!b[O].expanded}}));else W(O)},N=(O)=>{Y({type:"file",path:O})},P=async(O)=>{let v=await(await fetch(`/api/file?session=${J}&path=${encodeURIComponent(O)}`)).json();if(!v.error){let D=v.content.split(`
49
+ `)}function y5($){let J={label:"",annotations:[],children:new Map};for(let Q of $){let Z=Q.context?.hierarchy||[],Y=J;for(let X of Z){if(!Y.children.has(X))Y.children.set(X,{label:X,annotations:[],children:new Map});Y=Y.children.get(X)}Y.annotations.push(Q)}return J}function w0($,J=0){let Q=[];for(let Z of $.annotations)Q.push(A0(Z));for(let[,Z]of $.children){let Y=J===0?"###":"####";Q.push(`${Y} ${Z.label}`),Q.push(""),Q.push(w0(Z,J+1))}return Q.join(`
50
+ `)}import{SessionContext as b5}from"#canvas/runtime";import{useEffect as n1,useState as k1,useRef as P5,useMemo as S5}from"react";import{jsxDEV as f,Fragment as w5}from"react/jsx-dev-runtime";function I0({open:$,onClose:J,onSubmit:Q}){let{annotations:Z,generalNote:Y,responses:X,feedbackEntries:z}=o(),[q,_]=k1(""),[U,K]=k1(!1),[G,W]=k1(!1),[T,N]=k1(null),S=P5(null);if(n1(()=>{if(!$){K(!1),W(!1),N(null);return}if(U)return;_(y1(Z,Y,X,z))},[Z,Y,X,z,U,$]),n1(()=>{if($&&G&&S.current)S.current.focus()},[$,G]),n1(()=>{if(!$)return;let P=(w)=>{if(w.key==="Escape")J()};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[$,J]),!$)return null;let O=q.trim().length>0;return f("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:J,children:f("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(P)=>P.stopPropagation(),children:[f("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[f("div",{className:"flex items-center gap-3",children:[f("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),U&&f("button",{onClick:()=>{K(!1),W(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-2",children:[f("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[f("button",{onClick:()=>W(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!G?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),f("button",{onClick:()=>W(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${G?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("button",{onClick:J,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),G?f("textarea",{ref:S,value:q,onChange:(P)=>{_(P.target.value),K(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):f("div",{className:"flex-1 overflow-y-auto p-5",children:f(e1,{text:q},void 0,!1,void 0,this)},void 0,!1,void 0,this),T&&f("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[f("span",{children:T},void 0,!1,void 0,this),f("button",{onClick:()=>{N(null),Q(q)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[f("button",{onClick:J,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),f("button",{onClick:()=>{let P=g1(X),w=f1(z),B=[...P.map((R)=>R.label),...w.map((R)=>R.label||R.id)];if(B.length>0){N(`Please answer: ${B.join(", ")}`);return}N(null),Q(q)},disabled:!O,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${O?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function e1({text:$}){let J=S5(()=>A5($),[$]);return f("div",{className:"font-body text-body text-text-primary leading-relaxed",children:J},void 0,!1,void 0,this)}function C0({text:$}){let J=[],Q=/(\*\*(.+?)\*\*|`(.+?)`)/g,Z=0,Y,X=0;while((Y=Q.exec($))!==null){if(Y.index>Z)J.push($.slice(Z,Y.index));if(Y[2])J.push(f("strong",{className:"font-semibold text-text-primary",children:Y[2]},X++,!1,void 0,this));else if(Y[3])J.push(f("code",{className:"font-mono text-code bg-bg-code px-1 py-px rounded",children:Y[3]},X++,!1,void 0,this));Z=Q.lastIndex}if(Z<$.length)J.push($.slice(Z));return f(w5,{children:J},void 0,!1,void 0,this)}function A5($){let J=$.split(`
51
+ `),Q=[],Z=0,Y=0;while(Z<J.length){let X=J[Z];if(X.startsWith("#### ")){Q.push(f("h4",{className:"text-[13px] font-body font-semibold text-text-primary mt-5 mb-1",children:X.slice(5)},Y++,!1,void 0,this)),Z++;continue}if(X.startsWith("### ")){Q.push(f("h3",{className:"text-[14px] font-body font-semibold text-text-primary mt-5 mb-1",children:X.slice(4)},Y++,!1,void 0,this)),Z++;continue}if(X.startsWith("## ")){Q.push(f("h2",{className:"text-task-label font-body font-semibold text-text-primary mt-6 mb-2 pb-1 border-b border-border-subtle",children:X.slice(3)},Y++,!1,void 0,this)),Z++;continue}if(X.startsWith("> ")){let z=[];while(Z<J.length&&J[Z].startsWith("> "))z.push(J[Z].slice(2)),Z++;Q.push(f("blockquote",{className:"border-l-2 border-border-hover pl-3 my-2 text-text-secondary italic text-[13px]",children:z.map((q,_)=>f("div",{children:q},_,!1,void 0,this))},Y++,!1,void 0,this));continue}if(X.startsWith("- [x] ")||X.startsWith("- [ ] ")){let z=[];while(Z<J.length&&(J[Z].startsWith("- [x] ")||J[Z].startsWith("- [ ] ")))z.push({checked:J[Z].startsWith("- [x] "),label:J[Z].slice(6)}),Z++;Q.push(f("ul",{className:"my-1 space-y-0.5",children:z.map((q,_)=>f("li",{className:"flex items-center gap-2 text-[13px]",children:[f("span",{className:`w-3.5 h-3.5 rounded flex items-center justify-center flex-shrink-0 ${q.checked?"bg-accent-amber":"border border-border-hover"}`,children:q.checked&&f("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"none",children:f("path",{d:"M2.5 5L4.5 7L7.5 3",style:{stroke:"var(--color-text-inverse)"},strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("span",{className:q.checked?"text-text-primary":"text-text-tertiary",children:q.label},void 0,!1,void 0,this)]},_,!0,void 0,this))},Y++,!1,void 0,this));continue}if(X.startsWith("- ")){let z=[];while(Z<J.length&&J[Z].startsWith("- "))z.push(J[Z].slice(2)),Z++;Q.push(f("ul",{className:"my-1 space-y-0.5 list-disc list-inside",children:z.map((q,_)=>f("li",{className:"text-[13px] text-text-secondary",children:f(C0,{text:q},void 0,!1,void 0,this)},_,!1,void 0,this))},Y++,!1,void 0,this));continue}if(X.trim()===""){Z++;continue}Q.push(f("p",{className:"my-1.5 text-[13px]",children:f(C0,{text:X},void 0,!1,void 0,this)},Y++,!1,void 0,this)),Z++}return Q}import{jsxDEV as q1}from"react/jsx-dev-runtime";var C5={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},I5={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function P1({name:$,type:J,expanded:Q,className:Z=""}){if(J==="dir")return q1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Q?q1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):q1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=$.includes(".")?$.split(".").pop().toLowerCase():"",X=C5[Y]||"#6b6560",z=I5[Y];return q1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[q1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:X,opacity:"0.85"},void 0,!1,void 0,this),q1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),z&&q1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as g}from"react/jsx-dev-runtime";function J0({onPreview:$,onSubmit:J,collapseButton:Q}){let{isReadOnly:Z,selectedRevision:Y,currentRevision:X,revisions:z}=j0(H1),q=j0(b5),_=Z&&Y===X,K=z.find((G)=>G.revision===Y)?.label||`Round ${Y}`;if(Z)return g(j5,{sessionId:q,revision:Y,label:K,waitingForUpdate:_,collapseButton:Q},void 0,!1,void 0,this);return g(m5,{onPreview:$,onSubmit:J,collapseButton:Q},void 0,!1,void 0,this)}function j5({sessionId:$,revision:J,label:Q,waitingForUpdate:Z,collapseButton:Y}){let[X,z]=$0(null),[q,_]=$0(!0);return m0(()=>{_(!0),fetch(`/api/session/${$}/revision/${J}/feedback`).then((U)=>U.json()).then((U)=>{z(U.feedback||null),_(!1)}).catch(()=>{z(null),_(!1)})},[$,J]),g("div",{className:"flex flex-col h-full",children:[g("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[g("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),Z&&g("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[g("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),g("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g("div",{className:"flex-1 overflow-y-auto px-4",children:q?g("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?g(e1,{text:X},void 0,!1,void 0,this):g("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function m5({onPreview:$,onSubmit:J,collapseButton:Q}){let{annotations:Z,updateAnnotation:Y,removeAnnotation:X,generalNote:z,setGeneralNote:q,activeAnnotationId:_,setActiveAnnotationId:U,responses:K,feedbackEntries:G}=o(),{setActiveView:W}=R5.useContext(G1),T=R0(null),N=R0(new Map),S=Z.filter((H)=>!H.filePath),O=Z.filter((H)=>H.filePath),P={};for(let H of O){let y=H.filePath;if(!P[y])P[y]=[];P[y].push(H)}m0(()=>{if(!_)return;let H=N.current.get(_);if(H)H.scrollIntoView({behavior:"smooth",block:"nearest"})},[_]);let w=b0((H)=>{U(H),l1(H,!0);let y=document.querySelector(`[data-annotation-id="${H}"]`);if(y)y.scrollIntoView({behavior:"smooth",block:"nearest"})},[U]),B=b0((H)=>{U(null),l1(H,!1)},[_]),R=Array.from(K.values()).some(t1),D=G.size>0,m=Z.length>0||z.trim().length>0||R||D,[j,C]=$0(null),I=(H)=>g("div",{ref:(y)=>{if(y)N.current.set(H.id,y);else N.current.delete(H.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${_===H.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>w(H.id),onMouseLeave:()=>B(H.id),onClick:()=>{if(H.id===_)U(null);else if(U(H.id),H.filePath)W({type:"file",path:H.filePath}),setTimeout(()=>{let y=document.querySelector(`[data-annotation-id="${H.id}"]`);if(y)y.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[g("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:H.snippet.length>80?H.snippet.slice(0,80)+"...":H.snippet},void 0,!1,void 0,this),g("textarea",{value:H.note,onChange:(y)=>Y(H.id,y.target.value),onClick:(y)=>y.stopPropagation(),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",rows:1,style:{height:"auto",overflow:"hidden"},onInput:(y)=>{let E=y.target;E.style.height="auto",E.style.height=E.scrollHeight+"px"},ref:(y)=>{if(y)y.style.height="auto",y.style.height=y.scrollHeight+"px"}},void 0,!1,void 0,this),g("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:g("button",{onClick:(y)=>{y.stopPropagation(),X(H.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:g("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[g("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),g("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},H.id,!0,void 0,this);return g("div",{className:"flex flex-col h-full",children:[g("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[g("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&g("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),g("div",{ref:T,className:"flex-1 overflow-y-auto",children:[Z.length===0&&g("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the plan or in files to add annotations."},void 0,!1,void 0,this),S.length>0&&O.length>0&&g("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),S.map(I),Object.entries(P).map(([H,y])=>g("div",{children:[g("button",{onClick:()=>W({type:"file",path:H}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:H,children:[g(P1,{name:H.split("/").pop()||H,type:"file"},void 0,!1,void 0,this),g("span",{className:"truncate",children:H},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y.map(I)]},H,!0,void 0,this))]},void 0,!0,void 0,this),g("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:g("textarea",{value:z,onChange:(H)=>q(H.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(H)=>{let y=H.target;y.style.height="auto",y.style.height=Math.max(40,y.scrollHeight)+"px"},ref:(H)=>{if(H)H.style.height="auto",H.style.height=Math.max(40,H.scrollHeight)+"px"}},void 0,!1,void 0,this)},void 0,!1,void 0,this),j&&g("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[g("span",{children:j},void 0,!1,void 0,this),g("button",{onClick:()=>{C(null);let H=y1(Z,z,K,G);J(H)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:m?g("div",{className:"flex gap-2",children:[g("button",{onClick:$,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),g("button",{onClick:()=>{let H=g1(K),y=f1(G),E=[...H.map(($1)=>$1.label),...y.map(($1)=>$1.label||$1.id)];if(E.length>0){C(`Please answer: ${E.join(", ")}`);return}C(null);let c=y1(Z,z,K,G);J(c)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):g("button",{onClick:()=>J("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as V5,useState as V0,useContext as D0}from"react";import{SessionContext as D5}from"#canvas/runtime";import{jsxDEV as v,Fragment as Q0}from"react/jsx-dev-runtime";function g0({embedded:$}={}){let J=D0(D5),{annotations:Q,addAnnotation:Z}=o(),{setActiveView:Y}=D0(G1),[X,z]=V0(!1),[q,_]=V0({}),U=Q.filter((B)=>B.filePath),K=new Map;for(let B of U)K.set(B.filePath,(K.get(B.filePath)||0)+1);let G=[...K.keys()],W=async(B)=>{let D=await(await fetch(`/api/tree?session=${J}&path=${encodeURIComponent(B)}`)).json();if(D.entries)_((m)=>({...m,[B]:{entries:D.entries,expanded:!0,loaded:!0}}))};V5(()=>{if(!X&&!q[""])W("")},[X]);let T=(B)=>{if(q[B]?.loaded)_((R)=>({...R,[B]:{...R[B],expanded:!R[B].expanded}}));else W(B)},N=(B)=>{Y({type:"file",path:B})},S=async(B)=>{let D=await(await fetch(`/api/file?session=${J}&path=${encodeURIComponent(B)}`)).json();if(!D.error){let m=D.content.split(`
52
52
  `).slice(0,3).join(`
53
- `)+(v.content.split(`
53
+ `)+(D.content.split(`
54
54
  `).length>3?`
55
- ...`:"");Z(D,"Include this file for context",O)}},L=async(O)=>{let b=[];if(_[O]?.loaded)b=_[O].entries;else{let D=await(await fetch(`/api/tree?session=${J}&path=${encodeURIComponent(O)}`)).json();if(D.entries)b=D.entries}await Promise.all(b.filter((v)=>v.type==="file").map((v)=>P(O?`${O}/${v.name}`:v.name)))},y=(O)=>K.get(O)||0,w=(O,b=0)=>{let v=_[O];if(!v?.expanded)return null;return v.entries.map((D)=>{let j=O?`${O}/${D.name}`:D.name,A=y(j);return u("div",{children:[u("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+b*16}px`,paddingRight:"8px"},children:D.type==="dir"?u(Q0,{children:[u("span",{onClick:()=>T(j),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[u(P1,{name:D.name,type:"dir",expanded:_[j]?.expanded},void 0,!1,void 0,this),u("span",{className:"truncate",children:D.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u("button",{onClick:(C)=>{C.stopPropagation(),L(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):u(Q0,{children:[u("span",{onClick:()=>N(j),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${A>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[u(P1,{name:D.name,type:"file"},void 0,!1,void 0,this),u("span",{className:"truncate",children:D.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[A>0&&u("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:A},void 0,!1,void 0,this),u("button",{onClick:(C)=>{C.stopPropagation(),P(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),D.type==="dir"&&w(j,b+1)]},j,!0,void 0,this)})};if($)return u(Q0,{children:[u("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:u("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u("div",{className:"flex-1 overflow-y-auto",children:w("")},void 0,!1,void 0,this),G.length>0&&u("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[u("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),G.map((O)=>u("div",{onClick:()=>N(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[u("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),u("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:y(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(X)return u("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:u("button",{onClick:()=>z(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:u("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:u("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return u("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[u("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[u("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),u("button",{onClick:()=>z(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:u("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:u("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u("div",{className:"flex-1 overflow-y-auto",children:w("")},void 0,!1,void 0,this),G.length>0&&u("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[u("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),G.map((O)=>u("div",{onClick:()=>N(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[u("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),u("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:y(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as S1,useState as _1,useContext as D5,useCallback as g5,useRef as v1,useMemo as f5}from"react";import{SessionContext as k5}from"#canvas/runtime";var u1={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as J1}from"react/jsx-dev-runtime";function f0({path:$}){let J=D5(k5),{annotations:Q,addAnnotationWithId:Z,removeAnnotation:Y,updateAnnotation:X,activeAnnotationId:z,setActiveAnnotationId:_}=t(),[q,U]=_1(null),[K,G]=_1("text"),[W,T]=_1(!0),[N,P]=_1(null),L=v1(null),[y,w]=_1(null),O=v1(""),[b,v]=_1(null),[D,j]=_1(null),A=Q.filter((R)=>R.filePath===$);S1(()=>{T(!0),P(null),fetch(`/api/file?session=${J}&path=${encodeURIComponent($)}`).then((R)=>R.json()).then((R)=>{if(R.error)P(R.error),T(!1);else U(R.content),G(R.language||"text"),T(!1)}).catch(()=>{P("Failed to fetch file"),T(!1)})},[J,$]),S1(()=>{if(!q||!L.current)return;let R=setTimeout(()=>{if(L.current)b1(L.current,A)},50);return()=>clearTimeout(R)},[q,$]),S1(()=>{C1(z)},[z]),S1(()=>{let R=L.current;if(!R)return;let B=(x)=>{let E=x.target.closest("[data-annotation-id]");if(!E)return;x.stopPropagation();let V=E.getAttribute("data-annotation-id");if(V===z)v({anchorEl:E,annId:V});else _(V)},S=(x)=>{let E=x.target.closest("[data-annotation-id]");if(E)_(E.getAttribute("data-annotation-id"))},m=(x)=>{let E=x.target.closest("[data-annotation-id]"),V=x.relatedTarget?.closest?.("[data-annotation-id]");if(E&&!V&&!document.getElementById("ann-inline-popover"))_(null)};return R.addEventListener("click",B),R.addEventListener("mouseover",S),R.addEventListener("mouseout",m),()=>{R.removeEventListener("click",B),R.removeEventListener("mouseover",S),R.removeEventListener("mouseout",m)}},[q,Q,z]),S1(()=>{let R=()=>M();return document.addEventListener("mouseup",R),()=>document.removeEventListener("mouseup",R)},[]);let C=v1($);C.current=$;let H=v1(Z);H.current=Z;let M=g5(()=>{let R=window.getSelection();if(!R||R.isCollapsed||!R.toString().trim())return;if(!L.current)return;let B=R.getRangeAt(0);if(!L.current.contains(B.startContainer))return;if(B.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let S=R.toString().trim();if(S.length<2)return;let m=`__pending_${Date.now()}`,x=B.cloneRange();try{L1(x,m)}catch{}R.removeAllRanges();let E=document.querySelectorAll(`[data-annotation-id="${m}"]`),V=E[E.length-1];if(!V)return;O.current=S,w(m),j({anchorEl:V,tempId:m,snippet:S})},[]),h=f5(()=>{if(!q)return null;let R=window.hljs;if(!R)return null;let B=$.split(".").pop()||"",S=u1[B];try{return(S?R.highlight(q,{language:S}):R.highlightAuto(q)).value.split(`
56
- `)}catch{return null}},[q,$]);if(W)return J1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",$,"..."]},void 0,!0,void 0,this);if(N)return J1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:N},void 0,!1,void 0,this);if(!q)return null;let c=q.split(`
57
- `),I=()=>{let R=q.split(`
55
+ ...`:"");Z(m,"Include this file for context",B)}},O=async(B)=>{let R=[];if(q[B]?.loaded)R=q[B].entries;else{let m=await(await fetch(`/api/tree?session=${J}&path=${encodeURIComponent(B)}`)).json();if(m.entries)R=m.entries}await Promise.all(R.filter((D)=>D.type==="file").map((D)=>S(B?`${B}/${D.name}`:D.name)))},P=(B)=>K.get(B)||0,w=(B,R=0)=>{let D=q[B];if(!D?.expanded)return null;return D.entries.map((m)=>{let j=B?`${B}/${m.name}`:m.name,C=P(j);return v("div",{children:[v("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+R*16}px`,paddingRight:"8px"},children:m.type==="dir"?v(Q0,{children:[v("span",{onClick:()=>T(j),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[v(P1,{name:m.name,type:"dir",expanded:q[j]?.expanded},void 0,!1,void 0,this),v("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v("button",{onClick:(I)=>{I.stopPropagation(),O(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):v(Q0,{children:[v("span",{onClick:()=>N(j),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${C>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[v(P1,{name:m.name,type:"file"},void 0,!1,void 0,this),v("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[C>0&&v("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:C},void 0,!1,void 0,this),v("button",{onClick:(I)=>{I.stopPropagation(),S(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),m.type==="dir"&&w(j,R+1)]},j,!0,void 0,this)})};if($)return v(Q0,{children:[v("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:v("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),v("div",{className:"flex-1 overflow-y-auto",children:w("")},void 0,!1,void 0,this),G.length>0&&v("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[v("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),G.map((B)=>v("div",{onClick:()=>N(B),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[v("span",{className:"truncate",children:B.split("/").pop()},void 0,!1,void 0,this),v("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:P(B)},void 0,!1,void 0,this)]},B,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(X)return v("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:v("button",{onClick:()=>z(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:v("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:v("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return v("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[v("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[v("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),v("button",{onClick:()=>z(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:v("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:v("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v("div",{className:"flex-1 overflow-y-auto",children:w("")},void 0,!1,void 0,this),G.length>0&&v("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[v("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),G.map((B)=>v("div",{onClick:()=>N(B),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[v("span",{className:"truncate",children:B.split("/").pop()},void 0,!1,void 0,this),v("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:P(B)},void 0,!1,void 0,this)]},B,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as S1,useState as _1,useContext as g5,useCallback as f5,useRef as v1,useMemo as k5}from"react";import{SessionContext as u5}from"#canvas/runtime";var u1={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as e}from"react/jsx-dev-runtime";function f0({path:$}){let J=g5(u5),{annotations:Q,addAnnotationWithId:Z,removeAnnotation:Y,updateAnnotation:X,activeAnnotationId:z,setActiveAnnotationId:q}=o(),[_,U]=_1(null),[K,G]=_1("text"),[W,T]=_1(!0),[N,S]=_1(null),O=v1(null),[P,w]=_1(null),B=v1(""),[R,D]=_1(null),[m,j]=_1(null),C=Q.filter((M)=>M.filePath===$);S1(()=>{T(!0),S(null),fetch(`/api/file?session=${J}&path=${encodeURIComponent($)}`).then((M)=>M.json()).then((M)=>{if(M.error)S(M.error),T(!1);else U(M.content),G(M.language||"text"),T(!1)}).catch(()=>{S("Failed to fetch file"),T(!1)})},[J,$]),S1(()=>{if(!_||!O.current)return;let M=setTimeout(()=>{if(O.current)b1(O.current,C)},50);return()=>clearTimeout(M)},[_,$]),S1(()=>{I1(z)},[z]),S1(()=>{let M=O.current;if(!M)return;let L=(h)=>{let b=h.target.closest("[data-annotation-id]");if(!b)return;h.stopPropagation();let V=b.getAttribute("data-annotation-id");if(V===z)D({anchorEl:b,annId:V});else q(V)},A=(h)=>{let b=h.target.closest("[data-annotation-id]");if(b)q(b.getAttribute("data-annotation-id"))},u=(h)=>{let b=h.target.closest("[data-annotation-id]"),V=h.relatedTarget?.closest?.("[data-annotation-id]");if(b&&!V&&!document.getElementById("ann-inline-popover"))q(null)};return M.addEventListener("click",L),M.addEventListener("mouseover",A),M.addEventListener("mouseout",u),()=>{M.removeEventListener("click",L),M.removeEventListener("mouseover",A),M.removeEventListener("mouseout",u)}},[_,Q,z]),S1(()=>{let M=()=>y();return document.addEventListener("mouseup",M),()=>document.removeEventListener("mouseup",M)},[]);let I=v1($);I.current=$;let H=v1(Z);H.current=Z;let y=f5(()=>{let M=window.getSelection();if(!M||M.isCollapsed||!M.toString().trim())return;if(!O.current)return;let L=M.getRangeAt(0);if(!O.current.contains(L.startContainer))return;if(L.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let A=M.toString().trim();if(A.length<2)return;let u=`__pending_${Date.now()}`,h=L.cloneRange();try{L1(h,u)}catch{}M.removeAllRanges();let b=document.querySelectorAll(`[data-annotation-id="${u}"]`),V=b[b.length-1];if(!V)return;B.current=A,w(u),j({anchorEl:V,tempId:u,snippet:A})},[]),E=k5(()=>{if(!_)return null;let M=window.hljs;if(!M)return null;let L=$.split(".").pop()||"",A=u1[L];try{return(A?M.highlight(_,{language:A}):M.highlightAuto(_)).value.split(`
56
+ `)}catch{return null}},[_,$]);if(W)return e("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",$,"..."]},void 0,!0,void 0,this);if(N)return e("div",{className:"p-8 text-accent-red font-body text-[13px]",children:N},void 0,!1,void 0,this);if(!_)return null;let c=_.split(`
57
+ `),$1=()=>{let M=_.split(`
58
58
  `).slice(0,3).join(`
59
59
  `)+(c.length>3?`
60
- ...`:""),B=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;Z(B,R,"",$),_(B)},l=L.current?.closest("#plan-scroll-container");return J1("div",{children:[J1("pre",{ref:L,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:c.map((R,B)=>J1("div",{className:"flex hover:bg-bg-elevated-half px-5",children:[J1("span",{className:"text-text-tertiary opacity-40 select-none w-10 text-right pr-4 shrink-0 py-px text-[12px]",children:B+1},void 0,!1,void 0,this),h?J1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:h[B]||" "}},void 0,!1,void 0,this):J1("code",{className:"py-px",children:R||" "},void 0,!1,void 0,this)]},B,!0,void 0,this))},void 0,!1,void 0,this),b&&(()=>{let R=Q.find((B)=>B.id===b.annId);if(!R)return null;return J1(B1,{anchorEl:b.anchorEl,scrollContainer:l,initialNote:R.note,onUpdate:(B)=>X(b.annId,B),onDelete:()=>{Y(b.annId),_(null)},onClose:()=>v(null)},void 0,!1,void 0,this)})(),D&&J1(M1,{anchorEl:D.anchorEl,scrollContainer:l,snippet:D.snippet,onAdd:(R)=>{let B=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;I1(D.tempId,B),Z(B,D.snippet,R,$),w(null),j(null)},onCancel:()=>{j1(D.tempId),w(null),j(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as k0,useState as u0,useRef as u5}from"react";import{jsxDEV as Q1}from"react/jsx-dev-runtime";function Y0({currentSessionId:$}){let[J,Q]=u0([]),[Z,Y]=u0(!1),X=u5(null);k0(()=>{let q=async()=>{try{let K=await fetch("/api/sessions");Q(await K.json())}catch{}};q();let U=setInterval(q,5000);return()=>clearInterval(U)},[]),k0(()=>{if(!Z)return;let q=(U)=>{if(X.current&&!X.current.contains(U.target))Y(!1)};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[Z]);let z=J.filter((q)=>q.id!==$),_=$.length>30?$.slice(0,30)+"...":$;return Q1("div",{className:"relative",ref:X,children:[Q1("button",{onClick:()=>z.length>0&&Y(!Z),className:"flex items-center gap-1.5 font-body text-body font-medium text-text-primary hover:text-text-secondary transition-colors",children:[Q1("span",{children:_},void 0,!1,void 0,this),z.length>0&&Q1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${Z?"rotate-180":""}`,children:Q1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z&&z.length>0&&Q1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:z.map((q)=>Q1("a",{href:`/s/${q.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[Q1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${q.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),Q1("span",{className:"truncate",children:q.id},void 0,!1,void 0,this)]},q.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function v0($){let J=[];return E1($,J,0),J.join(`
60
+ ...`:""),L=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;Z(L,M,"",$),q(L)},Q1=O.current?.closest("#plan-scroll-container");return e("div",{children:[e("pre",{ref:O,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:c.map((M,L)=>e("div",{className:"flex hover:bg-bg-elevated-half px-5",children:[e("span",{className:"text-text-tertiary opacity-40 select-none w-10 text-right pr-4 shrink-0 py-px text-[12px]",children:L+1},void 0,!1,void 0,this),E?e("code",{className:"py-px",dangerouslySetInnerHTML:{__html:E[L]||" "}},void 0,!1,void 0,this):e("code",{className:"py-px",children:M||" "},void 0,!1,void 0,this)]},L,!0,void 0,this))},void 0,!1,void 0,this),R&&(()=>{let M=Q.find((L)=>L.id===R.annId);if(!M)return null;return e(B1,{anchorEl:R.anchorEl,scrollContainer:Q1,initialNote:M.note,onUpdate:(L)=>X(R.annId,L),onDelete:()=>{Y(R.annId),q(null)},onClose:()=>D(null)},void 0,!1,void 0,this)})(),m&&e(M1,{anchorEl:m.anchorEl,scrollContainer:Q1,snippet:m.snippet,onAdd:(M)=>{let L=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;R1(m.tempId,L),Z(L,m.snippet,M,$),w(null),j(null)},onCancel:()=>{j1(m.tempId),w(null),j(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as k0,useState as u0,useRef as v5}from"react";import{jsxDEV as J1}from"react/jsx-dev-runtime";function v0($,J){if(J){let Q=J.replace(/\/+$/,"").split("/");return Q[Q.length-1]||$}return $.length>30?$.slice(0,30)+"...":$}function Y0({currentSessionId:$,projectRoot:J}){let[Q,Z]=u0([]),[Y,X]=u0(!1),z=v5(null);k0(()=>{let U=async()=>{try{let G=await fetch("/api/sessions");Z(await G.json())}catch{}};U();let K=setInterval(U,5000);return()=>clearInterval(K)},[]),k0(()=>{if(!Y)return;let U=(K)=>{if(z.current&&!z.current.contains(K.target))X(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[Y]);let q=Q.filter((U)=>U.id!==$),_=v0($,J);return J1("div",{className:"relative",ref:z,children:[J1("button",{onClick:()=>q.length>0&&X(!Y),className:"flex items-center gap-1.5 font-body text-body font-medium text-text-primary hover:text-text-secondary transition-colors",children:[J1("span",{children:_},void 0,!1,void 0,this),q.length>0&&J1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${Y?"rotate-180":""}`,children:J1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&q.length>0&&J1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:q.map((U)=>J1("a",{href:`/s/${U.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[J1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),J1("span",{className:"truncate",children:v0(U.id,U.projectRoot)},void 0,!1,void 0,this)]},U.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function E0($){let J=[];return E1($,J,0),J.join(`
61
61
  `).replace(/\n{3,}/g,`
62
62
 
63
63
  `).trim()+`
64
- `}var v5=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function E1($,J,Q){if(E5($)){let Z=h5($);if(Z)J.push(Z,"");return}for(let Z of $.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)x5(Z,J,Q);else if(Z.nodeType===Node.TEXT_NODE){let Y=Z.textContent?.trim();if(Y)J.push(Y,"")}}function E5($){for(let J of $.childNodes){if(J.nodeType===Node.TEXT_NODE)continue;if(J.nodeType===Node.ELEMENT_NODE){let Q=J;if(!v5.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return $.childNodes.length>0}function h5($){let J="";for(let Q of $.childNodes)if(Q.nodeType===Node.TEXT_NODE)J+=Q.textContent||"";else if(Q.nodeType===Node.ELEMENT_NODE){let Z=Q;if(Z.tagName==="CODE")J+="`"+(Z.textContent||"")+"`";else J+=Z.textContent||""}return J.trim()}function x5($,J,Q){let Z=$.getAttribute("data-md");if(Z)switch(Z){case"section":return p5($,J,Q);case"item":return c5($,J);case"codeblock":return d5($,J);case"callout":return r5($,J);case"note":return l5($,J);case"table":return i5($,J);case"checklist":return a5($,J);case"diff":return o5($,J);case"mermaid":return s5($,J);case"choice":return t5($,J);case"multichoice":return n5($,J);case"choice-option":case"multichoice-option":return;case"userinput":return e5($,J);case"rangeinput":return $2($,J);case"checklist-item":return;case"filepreview":return J2($,J);case"priority":return Q2($,J)}if($.querySelector("button, input, select, textarea"))return;if($.children.length>0)E1($,J,Q);else{let Y=$.textContent?.trim();if(Y)J.push(Y,"")}}function p5($,J,Q){let Z=$.getAttribute("data-md-title")||"Untitled",Y=Q===0?"##":"###";J.push(`${Y} ${Z}`,"");let X=$.querySelector(":scope > div:last-of-type");if(X)E1(X,J,Q+1)}function c5($,J){let Q=$.getAttribute("data-md-label")||"",Z=$.getAttribute("data-md-status"),Y=$.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let z=`${X} **${Q}**`;if(Y)z+=` \`${Y}\``;J.push(z);let _=$.querySelector(".text-text-secondary");if(_){let q=[];E1(_,q,0);for(let U of q)J.push(U?` ${U}`:"")}J.push("")}function d5($,J){let Q=$.getAttribute("data-md-language")||"",Y=$.querySelector("code")?.textContent||"";J.push(`\`\`\`${Q}`,Y,"```","")}function r5($,J){let Q=$.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Y=Y2($.querySelector(".text-text-secondary")||$);J.push(`> **${Z[Q]||Q}:** ${Y}`,"")}function l5($,J){let Q=$.textContent?.trim()||"";J.push(`> *${Q}*`,"")}function i5($,J){let Q=$.querySelector("table");if(!Q)return;let Z=[];for(let Y of Q.querySelectorAll("thead th"))Z.push(Y.textContent?.trim()||"");if(Z.length===0)return;J.push(`| ${Z.join(" | ")} |`),J.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Y of Q.querySelectorAll("tbody tr")){let X=[];for(let z of Y.querySelectorAll("td"))X.push(z.textContent?.trim()||"");J.push(`| ${X.join(" | ")} |`)}J.push("")}function a5($,J){for(let Q of $.querySelectorAll("li")){let Z=Q.querySelector(".bg-accent-green")!==null,Y=Q.textContent?.trim()||"";J.push(`- [${Z?"x":" "}] ${Y}`)}J.push("")}function o5($,J){let Q=$.getAttribute("data-md-language")||"";J.push(`\`\`\`diff${Q?` (${Q})`:""}`);for(let Z of $.querySelectorAll("[class*='flex']")){let Y=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)J.push(`${Y} ${X.textContent}`)}J.push("```","")}function s5($,J){let Q=$.getAttribute("data-md-source")||"";if(Q)J.push("```mermaid",Q,"```","")}function t5($,J){let Q=$.getAttribute("data-md-label")||"";J.push(`**${Q}:**`);for(let Z of $.querySelectorAll("[data-md='choice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;J.push(`- ${X?"(x)":"( )"} ${Y}`)}J.push("")}function n5($,J){let Q=$.getAttribute("data-md-label")||"";J.push(`**${Q}:**`);for(let Z of $.querySelectorAll("[data-md='multichoice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;J.push(`- [${X?"x":" "}] ${Y}`)}J.push("")}function e5($,J){let Q=$.getAttribute("data-md-label")||"",Y=$.querySelector("textarea")?.value?.trim()||"";J.push(`**${Q}:** ${Y||"_empty_"}`,"")}function $2($,J){let Q=$.getAttribute("data-md-label")||"",Z=$.querySelector("input[type='range']"),X=$.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";J.push(`**${Q}:** ${X}`,"")}function J2($,J){let Q=$.getAttribute("data-md-path")||"",Z=$.getAttribute("data-md-lines")||"",X=$.querySelector("code")?.textContent||"",z=Q.split(".").pop()||"",_=u1[z]||"",q=Z?`${Q} (L${Z})`:Q;J.push(q,"",`\`\`\`${_}`,X,"```","")}function Q2($,J){}function Y2($){return $?.textContent?.trim()||""}import L2,{useEffect as W1,useState as a,useRef as Z1}from"react";import{useEffect as Z2,useState as X2,useRef as z2,useContext as q2}from"react";import{jsxDEV as e,Fragment as E0}from"react/jsx-dev-runtime";function _2($){return $.label||`Round ${$.revision}`}function U2($){let J=Date.now()-new Date($).getTime(),Q=Math.floor(J/1000);if(Q<60)return"just now";let Z=Math.floor(Q/60);if(Z<60)return`${Z}m ago`;let Y=Math.floor(Z/60);if(Y<24)return`${Y}h ago`;return`${Math.floor(Y/24)}d ago`}function A1({value:$,onChange:J,accent:Q="default",className:Z}){let{currentRevision:Y,revisions:X}=q2(H1),[z,_]=X2(!1),q=z2(null);Z2(()=>{if(!z)return;let G=(W)=>{if(q.current&&!q.current.contains(W.target))_(!1)};return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[z]);let U=X.find((G)=>G.revision===$);return e("div",{className:"relative",ref:q,children:[e("button",{onClick:()=>_(!z),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Q]} ${Z||""}`,children:[U?_2(U):`Round ${$}`,e("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${z?"rotate-180":""}`,children:e("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z&&e("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((G)=>e("button",{onClick:()=>{J(G.revision),_(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${G.revision===$?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[e("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${G.revision===Y?"bg-accent-green":G.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),e("span",{className:"flex-1 text-left truncate",children:G.label?e(E0,{children:[G.label," ",e("span",{className:"text-text-tertiary",children:["#",G.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):e(E0,{children:["Round ",G.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),e("span",{className:"text-[10px] text-text-tertiary flex-shrink-0",children:G.revision===Y?"current":G.hasFeedback?"sent":U2(G.createdAt)},void 0,!1,void 0,this)]},G.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function h1($,J){let Q=$.length,Z=J.length;if(Q===0||Z===0)return[];let Y=Array.from({length:Q+1},()=>Array(Z+1).fill(0));for(let q=1;q<=Q;q++)for(let U=1;U<=Z;U++)Y[q][U]=$[q-1]===J[U-1]?Y[q-1][U-1]+1:Math.max(Y[q-1][U],Y[q][U-1]);let X=[],z=Q,_=Z;while(z>0&&_>0)if($[z-1]===J[_-1])X.unshift($[z-1]),z--,_--;else if(Y[z-1][_]>Y[z][_-1])z--;else _--;return X}function h0($){let J=[],Q=[],Z=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(X){let z=X.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=Z.nextNode()){let z=(Y.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let _=0;for(let q of z)J.push(q),Q.push({text:q,node:Y,offset:_}),_+=q.length}return{words:J,map:Q}}function Z0($,J){if($.length>5000||J.length>5000)return K2($,J);return c0($,J)}function c0($,J){let Q=x1($,J),Z=[],Y=[],X=0,z=0,_=0;while(X<$.length||z<J.length)if(_<Q.length&&X<$.length&&z<J.length&&$[X]===Q[_]&&J[z]===Q[_])Z.push({type:"same",index:X}),Y.push({type:"same",index:z}),X++,z++,_++;else if(X<$.length&&(_>=Q.length||$[X]!==Q[_]))Z.push({type:"removed",index:X}),X++;else if(z<J.length)Y.push({type:"added",index:z}),z++;return{oldOps:Z,newOps:Y}}function x1($,J){let Q=$.length,Z=J.length;if(Q===0||Z===0)return[];if(Q===1)return J.includes($[0])?[$[0]]:[];if(Z===1)return $.includes(J[0])?[J[0]]:[];if(Q*Z<=1e6)return h1($,J);let Y=Math.floor(Q/2),X=$.slice(0,Y),z=$.slice(Y),_=x0(X,J),q=x0([...z].reverse(),[...J].reverse()),U=0,K=0;for(let T=0;T<=Z;T++){let N=_[T]+q[Z-T];if(N>U)U=N,K=T}let G=J.slice(0,K),W=J.slice(K);return[...x1(X,G),...x1(z,W)]}function x0($,J){let Q=J.length,Z=Array(Q+1).fill(0),Y=Array(Q+1).fill(0);for(let X=0;X<$.length;X++){for(let z=1;z<=Q;z++)Y[z]=$[X]===J[z-1]?Z[z-1]+1:Math.max(Z[z],Y[z-1]);[Z,Y]=[Y,Z],Y.fill(0)}return Z}function K2($,J){let Z=(N)=>{let P=[];for(let L=0;L<N.length;L+=200){let y=Math.min(L+200,N.length);P.push({start:L,end:y,text:N.slice(L,y).join("")})}return P},Y=Z($),X=Z(J),z=Y.map((N)=>N.text),_=X.map((N)=>N.text),q=x1(z,_),U=[],K=[],G=0,W=0,T=0;while(G<Y.length||W<X.length)if(T<q.length&&G<Y.length&&W<X.length&&z[G]===q[T]&&_[W]===q[T]){for(let N=Y[G].start;N<Y[G].end;N++)U.push({type:"same",index:N});for(let N=X[W].start;N<X[W].end;N++)K.push({type:"same",index:N});G++,W++,T++}else if(G<Y.length&&(T>=q.length||z[G]!==q[T]))if(W<X.length&&(T>=q.length||_[W]!==q[T])){let N=c0($.slice(Y[G].start,Y[G].end),J.slice(X[W].start,X[W].end));for(let P of N.oldOps)U.push({type:P.type,index:P.index+Y[G].start});for(let P of N.newOps)K.push({type:P.type,index:P.index+X[W].start});G++,W++}else{for(let N=Y[G].start;N<Y[G].end;N++)U.push({type:"removed",index:N});G++}else if(W<X.length){for(let N=X[W].start;N<X[W].end;N++)K.push({type:"added",index:N});W++}return{oldOps:U,newOps:K}}function p0($,J,Q){let Z=new Map;for(let Y of $){if(Y.type==="same")continue;let X=J[Y.index];if(!X||!X.node.parentNode)continue;let z=Z.get(X.node);if(!z)z=[],Z.set(X.node,z);z.push({offset:X.offset,length:X.text.length})}for(let[Y,X]of Z){if(!Y.parentNode)continue;let z=Y.nodeValue||"";X.sort((G,W)=>G.offset-W.offset);let _=[];for(let G of X){let W=_[_.length-1];if(W&&G.offset<=W.offset+W.length)W.length=Math.max(W.length,G.offset+G.length-W.offset);else _.push({...G})}let q=Y.parentNode,U=document.createDocumentFragment(),K=0;for(let G of _){if(G.offset>K)U.appendChild(document.createTextNode(z.slice(K,G.offset)));let W=document.createElement("span");W.className=Q,W.textContent=z.slice(G.offset,G.offset+G.length),U.appendChild(W),K=G.offset+G.length}if(K<z.length)U.appendChild(document.createTextNode(z.slice(K)));q.replaceChild(U,Y)}}function d0($,J){let Q=h0($),Z=h0(J),{oldOps:Y,newOps:X}=Z0(Q.words,Z.words),z=Y.some((_)=>_.type==="removed")||X.some((_)=>_.type==="added");return p0(Y,Q.map,"diff-removed"),p0(X,Z.map,"diff-added"),z}function X0($){let J=[],Q=$.querySelectorAll(":scope > [data-md]");for(let Z of Q)J.push(w1(Z));if(J.length===0){let Z=$.querySelectorAll("[data-md]"),Y=new Set;for(let X of Z){let z=X.parentElement?.closest("[data-md]");if(z&&$.contains(z))continue;if(Y.has(X))continue;Y.add(X),J.push(w1(X))}}return J}function w1($){let J=$.getAttribute("data-md")||"unknown",Q=G2($,J),Z=[];if(J==="section"){let Y=$.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Y)for(let X of Y.querySelectorAll(":scope > [data-md]"))Z.push(w1(X))}else if(J==="table")for(let Y of $.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Y.textContent||"").slice(0,80),type:"tr",element:Y,children:[]});else if(J==="checklist")for(let Y of $.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(w1(Y));else for(let Y of $.querySelectorAll("[data-md]"))if(Y.parentElement?.closest("[data-md]")===$)Z.push(w1(Y));return{key:Q,type:J,element:$,children:Z}}function G2($,J){switch(J){case"section":return"section:"+($.getAttribute("data-md-title")||"");case"item":return"item:"+($.getAttribute("data-task-id")||$.getAttribute("data-md-label")||"");case"codeblock":case"diff":return J+":"+($.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+$.querySelectorAll("[data-md='checklist-item']").length;case"callout":return"callout:"+($.getAttribute("data-md-type")||"")+":"+($.textContent||"").slice(0,60);default:return J+":"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"")}}function z0($,J){let Q=$.map((U)=>U.key),Z=J.map((U)=>U.key),Y=h1(Q,Z),X=[],z=0,_=0,q=0;while(z<$.length||_<J.length)if(q<Y.length&&z<$.length&&_<J.length&&Q[z]===Y[q]&&Z[_]===Y[q]){let U=$[z],K=J[_],G=U.children.length>0||K.children.length>0?z0(U.children,K.children):void 0;X.push({kind:"matched",oldBlock:U,newBlock:K,childMatches:G}),z++,_++,q++}else if(z<$.length&&(q>=Y.length||Q[z]!==Y[q]))X.push({kind:"removed",oldBlock:$[z]}),z++;else if(_<J.length)X.push({kind:"added",newBlock:J[_]}),_++;return X}function l0($){let J=document.createDocumentFragment(),Q=!1;for(let Z of $)if(Z.kind==="removed")Q=!0,J.appendChild(i0(Z.oldBlock.element));else if(Z.kind==="added")Q=!0,J.appendChild(H2(Z.newBlock.element));else{let Y=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(o0(Y,Z.childMatches,X))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(a0(Z.oldBlock,Y,Z.childMatches,X))Q=!0}else if(R1(Z.oldBlock.element,Y,!1))Q=!0;J.appendChild(Y)}return{fragment:J,hasChanges:Q}}function i0($){let J=$.cloneNode(!0);return J.classList.add("diff-block-removed"),J.style.position="relative",q0(J,"Removed","var(--color-accent-red)"),J}function H2($){let J=$.cloneNode(!0);return J.classList.add("diff-block-added"),J.style.position="relative",q0(J,"Added","var(--color-accent-green)"),J}function a0($,J,Q,Z){let Y=!1,X=W2($,J),z,_;if(Z==="section"){let q=$.element.querySelector(":scope > div:first-child"),U=J.querySelector(":scope > div:first-child");if(q&&U){if(R1(q,U,!1))Y=!0}z=$.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),_=J.querySelector(":scope > div.mt-6, :scope > div:last-child")}else z=$.element,_=J;if(!z||!_)return Y;for(let q of Q)if(q.kind==="matched"){let U=X.newMap.get(q.newBlock.element);if(U){if(q.childMatches&&q.childMatches.length>0&&(q.newBlock.type==="table"||q.newBlock.type==="checklist")){if(o0(U,q.childMatches,q.newBlock.type))Y=!0}else if(q.childMatches&&q.childMatches.length>0){if(a0(q.oldBlock,U,q.childMatches,q.newBlock.type))Y=!0}else if(R1(q.oldBlock.element,U,!1))Y=!0}}else if(q.kind==="removed"){Y=!0;let U=i0(q.oldBlock.element),K=F2(Q,q,X.newMap);_.insertBefore(U,K)}else if(q.kind==="added"){Y=!0;let U=X.newMap.get(q.newBlock.element);if(U)U.classList.add("diff-block-added"),U.style.position="relative",q0(U,"Added","var(--color-accent-green)")}if(R1(z,_,!0))Y=!0;return Y}function o0($,J,Q){let Z=Q==="table"?$.querySelector(":scope table > tbody"):$;if(!Z)return!1;let Y=!1;Z.innerHTML="";for(let X of J)if(X.kind==="removed"){Y=!0;let z=X.oldBlock.element.cloneNode(!0);z.classList.add(Q==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(z)}else if(X.kind==="added"){Y=!0;let z=X.newBlock.element.cloneNode(!0);z.classList.add(Q==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(z)}else{let z=X.newBlock.element.cloneNode(!0);if(R1(X.oldBlock.element,z,!1))Y=!0;Z.appendChild(z)}return Y}function W2($,J){let Q=new Map,Z=$.element.querySelectorAll("[data-md]"),Y=J.querySelectorAll("[data-md]");return{newMap:{get(X){return T2(J,X)}}}}function T2($,J){let Q=J.getAttribute("data-md");if(!Q)return null;let Z=J.getAttribute("data-md-label"),Y=J.getAttribute("data-md-title"),X=`[data-md="${Q}"]`;if(Y)X+=`[data-md-title="${CSS.escape(Y)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let z=$.querySelectorAll(X);if(z.length===1)return z[0];let _=(J.textContent||"").slice(0,100),q=null,U=-1;for(let K of z){let G=(K.textContent||"").slice(0,100),W=0;for(let T=0;T<Math.min(_.length,G.length);T++)if(_[T]===G[T])W++;if(W>U)U=W,q=K}return q}function F2($,J,Q){let Z=$.indexOf(J);for(let Y=Z+1;Y<$.length;Y++){let X=$[Y];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Q.get(X.newBlock.element)||null}return null}function r0($,J){let Q=J?new Set(Array.from($.querySelectorAll("[data-md]"))):new Set,Z=[],Y=[],X=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(_){let q=_.parentElement;if(!q)return NodeFilter.FILTER_REJECT;if(q.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if(J){for(let U of Q)if(U.contains(_))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),z;while(z=X.nextNode()){let q=(z.nodeValue||"").match(/\S+|\s+/g);if(!q)continue;let U=0;for(let K of q)Z.push(K),Y.push({text:K,node:z,offset:U}),U+=K.length}return{words:Z,map:Y}}function R1($,J,Q){let Z=r0($,Q),Y=r0(J,Q);if(Z.words.length===0&&Y.words.length===0)return!1;let{oldOps:X,newOps:z}=Z0(Z.words,Y.words),_=X.some((L)=>L.type==="removed"),q=z.some((L)=>L.type==="added");if(!_&&!q)return!1;let U=[],K=[];for(let L of X)if(L.type==="same")U.push(L.index);for(let L of z)if(L.type==="same")K.push(L.index);let G=new Map;for(let L=0;L<U.length&&L<K.length;L++)G.set(U[L],K[L]);let W=[];{let L=[],y=-1;for(let w of X)if(w.type==="same"){if(L.length>0)W.push({text:L.join(""),anchorNewIdx:y>=0?G.get(y)??null:null}),L=[];y=w.index}else if(w.type==="removed")L.push(Z.words[w.index]);if(L.length>0)W.push({text:L.join(""),anchorNewIdx:y>=0?G.get(y)??null:null})}let T=new Map,N=new Map;for(let L of z){if(L.type!=="added")continue;let y=Y.map[L.index];if(!y?.node.parentNode)continue;let w=T.get(y.node);if(!w)w=[],T.set(y.node,w);w.push({start:y.offset,end:y.offset+y.text.length})}for(let L of W)if(L.anchorNewIdx===null){if(Y.map.length>0){let y=Y.map[0].node,w=N.get(y);if(!w)w=[],N.set(y,w);w.push({offset:0,text:L.text})}}else{let y=Y.map[L.anchorNewIdx];if(!y)continue;let w=N.get(y.node);if(!w)w=[],N.set(y.node,w);w.push({offset:y.offset+y.text.length,text:L.text})}let P=new Set([...T.keys(),...N.keys()]);for(let L of P)N2(L,T.get(L)||[],N.get(L)||[]);return!0}function N2($,J,Q){if(!$.parentNode)return;let Z=$.nodeValue||"";J.sort((K,G)=>K.start-G.start);let Y=[];for(let K of J){let G=Y[Y.length-1];if(G&&K.start<=G.end)G.end=Math.max(G.end,K.end);else Y.push({...K})}Q.sort((K,G)=>K.offset-G.offset);let X=$.parentNode,z=document.createDocumentFragment(),_=0,q=0,U=0;while(_<=Z.length){let K=q<Y.length?Y[q].start:1/0,G=U<Q.length?Q[U].offset:1/0,W=Math.min(K,G);if(W===1/0){if(_<Z.length)z.appendChild(document.createTextNode(Z.slice(_)));break}let T=Math.max(W,_);if(T>_)z.appendChild(document.createTextNode(Z.slice(_,T))),_=T;while(U<Q.length&&Q[U].offset<=_){let N=document.createElement("span");N.className="diff-removed",N.textContent=Q[U].text,z.appendChild(N),U++}if(q<Y.length&&Y[q].start<=_){let N=Y[q],P=document.createElement("span");P.className="diff-added",P.textContent=Z.slice(_,N.end),z.appendChild(P),_=N.end,q++;while(U<Q.length&&Q[U].offset<=_){let L=document.createElement("span");L.className="diff-removed",L.textContent=Q[U].text,z.appendChild(L),U++}}}while(U<Q.length){let K=document.createElement("span");K.className="diff-removed",K.textContent=Q[U].text,z.appendChild(K),U++}X.replaceChild(z,$)}function q0($,J,Q){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=J,Z.style.color=Q,Z.style.backgroundColor=`color-mix(in srgb, ${Q} 12%, transparent)`,$.appendChild(Z)}import{jsxDEV as k}from"react/jsx-dev-runtime";function s0({initialLeft:$,initialRight:J,sessionId:Q,onExit:Z}){let[Y,X]=a($),[z,_]=a(J),[q,U]=a("unified"),[K,G]=a(!0),[W,T]=a(!1);return k("div",{className:"flex flex-col h-screen",children:[k("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[k("div",{className:"flex items-center gap-3",children:[k("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),k(A1,{value:Y,onChange:X,accent:"red"},void 0,!1,void 0,this),k("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),k(A1,{value:z,onChange:_,accent:"green"},void 0,!1,void 0,this),W&&!K&&k("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k("div",{className:"flex items-center gap-4",children:[k("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[k("button",{onClick:()=>U("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${q==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),k("button",{onClick:()=>U("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${q==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q==="side-by-side"&&k(O2,{},void 0,!1,void 0,this),k("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),q==="unified"?k(M2,{sessionId:Q,leftRev:Y,rightRev:z,onDiffResult:(N,P)=>{T(N),G(P)}},`unified-${Y}-${z}`,!1,void 0,this):k(B2,{sessionId:Q,leftRev:Y,rightRev:z,onDiffResult:(N,P)=>{T(N),G(P)}},`sbs-${Y}-${z}`,!1,void 0,this)]},void 0,!0,void 0,this)}function O2(){let[$,J]=a(!0);return W1(()=>{return document.documentElement.dataset.syncScroll=$?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[$]),k("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[k("input",{type:"checkbox",checked:$,onChange:(Q)=>J(Q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),k("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function M2({sessionId:$,leftRev:J,rightRev:Q,onDiffResult:Z}){let Y=Z1(null),X=Z1(null),z=Z1(null),[_,q]=a(!1),[U,K]=a(!1),[G,W]=a(!1);return W1(()=>{if(!_||!U||G)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!z.current)return;let T=X0(Y.current),N=X0(X.current),P=z0(T,N),{fragment:L,hasChanges:y}=l0(P);z.current.innerHTML="",z.current.appendChild(L),W(!0),Z(!0,y)})})},[_,U,G]),k("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[k("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[k(p1,{ref:Y,sessionId:$,revision:J,onReady:()=>q(!0)},void 0,!1,void 0,this),k(p1,{ref:X,sessionId:$,revision:Q,onReady:()=>K(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!G&&k("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),k("div",{ref:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function B2({sessionId:$,leftRev:J,rightRev:Q,onDiffResult:Z}){let Y=Z1(null),X=Z1(null),[z,_]=a(!1),[q,U]=a(!1),[K,G]=a(!1),W=Z1(null),T=Z1(null),N=Z1(!1);return W1(()=>{if(!z||!q||K)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let P=d0(Y.current,X.current);G(!0),Z(!0,P)})})},[z,q,K]),W1(()=>{let P=W.current,L=T.current;if(!P||!L)return;let y=(b,v)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let D=b.scrollHeight-b.clientHeight,j=v.scrollHeight-v.clientHeight;if(D>0&&j>0)v.scrollTop=b.scrollTop/D*j;requestAnimationFrame(()=>{N.current=!1})},w=()=>y(P,L),O=()=>y(L,P);return P.addEventListener("scroll",w),L.addEventListener("scroll",O),()=>{P.removeEventListener("scroll",w),L.removeEventListener("scroll",O)}},[]),k("div",{className:"flex flex-1 min-h-0",children:[k("div",{ref:W,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:k(p1,{ref:Y,sessionId:$,revision:J,onReady:()=>_(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),k("div",{ref:T,className:"w-1/2 overflow-y-auto",children:k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:k(p1,{ref:X,sessionId:$,revision:Q,onReady:()=>U(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var p1=L2.forwardRef(({sessionId:$,revision:J,onReady:Q},Z)=>{let[Y,X]=a(null),[z,_]=a(null),[q,U]=a(!0);if(W1(()=>{U(!0),_(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((K)=>{X(()=>K.default),U(!1)}).catch((K)=>{_(K.message),U(!1)})},[$,J]),W1(()=>{if(!Y)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[Y]),q)return k("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(z)return k("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[k("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),k("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return k("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);return k("div",{ref:Z,children:k(Y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)});import{jsxDEV as F,Fragment as _0}from"react/jsx-dev-runtime";var G1=n0({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),H1=n0({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function $5(){let[$,J]=o(()=>localStorage.getItem("canvas-theme")||document.documentElement.dataset.theme||"dark");return F("button",{onClick:()=>{let Z=$==="dark"?"light":"dark";document.documentElement.dataset.theme=Z,localStorage.setItem("canvas-theme",Z),J(Z)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:$==="dark"?"Switch to light theme":"Switch to dark theme",children:$==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function J5(){let{currentRevision:$,selectedRevision:J,revisions:Q,setSelectedRevision:Z,setCompareRevision:Y}=U1.useContext(H1);if(Q.length<=1){let _=Q[0]?.label||`Round ${$}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:_},void 0,!1,void 0,this)}return F("div",{className:"flex items-center gap-1.5",children:[F(A1,{value:J,onChange:Z,accent:J===$?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let _=Q.find((U)=>U.revision===J)?.sourceFile,q;if(J===$)q=[...Q].reverse().find((K)=>K.revision<$&&(!_||K.sourceFile===_))?.revision??Math.max(1,$-1);else q=J;Y({left:q,right:$})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function A2(){let $=window.location.pathname.replace("/s/","")||"",[J,Q]=o(1),[Z,Y]=o(1),[X,z]=o([]),[_,q]=o(null),[U,K]=o(!1),[G,W]=o(!1),[T,N]=o({type:"plan"}),[P,L]=o([]),y=T1(null),[w,O]=o(!1),[b,v]=o(!1),[D,j]=o(!1);c1(()=>{let I=["Agent Canvas"];if($)I.push($);if(T.type==="file")I.push(T.path.split("/").pop()||T.path);else if(_)I.push("Compare");document.title=I.join(" — ")},[$,T,_]);let A=T1(new Map),C=X.find((I)=>I.revision===Z),H=Z!==J||!!C?.hasFeedback,M=d1((I)=>{if(A.current.set(T.type==="plan"?"plan":`file:${T.path}`,window.scrollY),N(I),I.type==="file")L((l)=>l.includes(I.path)?l:[...l,I.path])},[T]),h=d1((I)=>{A.current.delete(`file:${I}`),L((l)=>l.filter((R)=>R!==I)),N((l)=>{if(l.type==="file"&&l.path===I)return A.current.set(`file:${I}`,window.scrollY),{type:"plan"};return l})},[]);y2(()=>{let I=T.type==="plan"?"plan":`file:${T.path}`;window.scrollTo(0,A.current.get(I)||0)},[T]),c1(()=>{if(!$)return;fetch(`/api/session/${$}/meta`).then((I)=>I.json()).then((I)=>{if(I.currentRevision)Q(I.currentRevision),Y(I.currentRevision),z(I.revisions||[])}).catch(()=>{})},[$]),c1(()=>{if(!$)return;let I=null,l=()=>{let R=window.location.protocol==="https:"?"wss:":"ws:",B=new WebSocket(`${R}//${window.location.host}/ws/session/${$}`);y.current=B,B.onopen=()=>K(!0),B.onclose=()=>{K(!1),I=setTimeout(l,2000)},B.onmessage=(S)=>{try{let m=JSON.parse(S.data);if(m.type==="plan-updated"){if(Q(m.currentRevision),Y(m.currentRevision),q(null),m.revisions)z(m.revisions)}if(m.type==="revision-updated"){if(m.revisions)z(m.revisions)}}catch{}}};return l(),()=>{if(I)clearTimeout(I);y.current?.close()}},[$]);let c=d1((I)=>{if(y.current?.readyState===WebSocket.OPEN)y.current.send(JSON.stringify({type:"submit",feedback:I})),W(!1)},[]);if(!$)return F("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return F(e0.Provider,{value:$,children:F(H1.Provider,{value:{currentRevision:J,selectedRevision:Z,revisions:X,setSelectedRevision:Y,isReadOnly:H,compareRevision:_,setCompareRevision:q},children:F(G0,{sessionId:$,revision:Z,isReadOnly:H,children:F(G1.Provider,{value:{activeView:T,setActiveView:M,openFiles:P,closeFile:h},children:F(S2.Provider,{value:{setActiveView:M},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(w2,{sessionId:$,connected:U,onMobileSidebar:()=>O(!w),collapsed:b,onToggle:()=>v((I)=>!I)},void 0,!1,void 0,this),_===null&&F(R2,{collapsed:D,onToggle:()=>j((I)=>!I),children:F(J0,{onPreview:()=>W(!0),onSubmit:c},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?F("div",{className:`${b?"lg:ml-0":"lg:ml-60"} transition-[margin] duration-200`,children:F(s0,{initialLeft:_.left,initialRight:_.right,sessionId:$,onExit:()=>q(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${b?"lg:ml-0":"lg:ml-60"} ${D?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[F("div",{className:"flex items-center gap-2",children:[F(Y0,{currentSessionId:$},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full ${U?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(J5,{},void 0,!1,void 0,this),F("button",{onClick:()=>O(!w),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F($5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(C2,{},void 0,!1,void 0,this),F("div",{style:{display:T.type==="plan"?void 0:"none"},children:F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[F("button",{onClick:()=>{let I=document.querySelector(".plan-content");if(!I)return;let l=v0(I);navigator.clipboard.writeText(l).then(()=>{let R=document.getElementById("export-md-btn");if(R)R.setAttribute("data-copied","true"),setTimeout(()=>{R.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:F("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(P0,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),P.map((I)=>F("div",{style:{display:T.type==="file"&&T.path===I?void 0:"none"},children:F(f0,{path:I},void 0,!1,void 0,this)},I,!1,void 0,this))]},void 0,!0,void 0,this),w&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>O(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>O(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 overflow-hidden",children:F(J0,{onPreview:()=>W(!0),onSubmit:c},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(C0,{open:G,onClose:()=>W(!1),onSubmit:c},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${$}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function w2({sessionId:$,connected:J,onMobileSidebar:Q,collapsed:Z,onToggle:Y}){return F(_0,{children:[Z&&F("button",{onClick:Y,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Z?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(Y0,{currentSessionId:$},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${J?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),F("button",{onClick:Y,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(J5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(g0,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F($5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function R2({children:$,collapsed:J,onToggle:Q}){let[Z,Y]=o(()=>{let K=localStorage.getItem("canvas-sidebar-width");return K?parseInt(K,10):320}),X=T1(!1),z=T1(0),_=T1(0),q=T1(Z);q.current=Z;let U=d1((K)=>{K.preventDefault(),X.current=!0,z.current=K.clientX,_.current=q.current;let G=(T)=>{if(!X.current)return;let N=z.current-T.clientX,P=Math.max(240,Math.min(600,_.current+N));Y(P),q.current=P},W=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(q.current)),document.removeEventListener("mousemove",G),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",G),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return c1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),F(_0,{children:[J&&F("button",{onClick:Q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${J?"translate-x-full":""}`,style:{width:Z},children:[F("div",{onMouseDown:U,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),U1.Children.map($,(K)=>U1.isValidElement(K)?U1.cloneElement(K,{collapseButton:F("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):K)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function C2(){let{activeView:$,setActiveView:J,openFiles:Q,closeFile:Z}=U1.useContext(G1),Y=U1.useContext(e0),{addAnnotationWithId:X,setActiveAnnotationId:z}=t(),_=Q.length>0;if(!_)return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[_&&F("button",{onClick:()=>J({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${$.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Plan",$.type==="plan"&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_&&F(_0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((q,U)=>{let K=q.split("/").pop()||q,G=$.type==="file"&&$.path===q;return F(U1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>J({type:"file",path:q}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-mono whitespace-nowrap transition-colors relative ${G?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[K,G&&F("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:(W)=>{W.stopPropagation(),Z(q)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U<Q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},q,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:$.type==="file"&&F("button",{onClick:async()=>{let q=$.path;try{let K=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(q)}`)).json();if(!K.error){let G=K.content.split(`
64
+ `}var E5=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function E1($,J,Q){if(h5($)){let Z=x5($);if(Z)J.push(Z,"");return}for(let Z of $.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)p5(Z,J,Q);else if(Z.nodeType===Node.TEXT_NODE){let Y=Z.textContent?.trim();if(Y)J.push(Y,"")}}function h5($){for(let J of $.childNodes){if(J.nodeType===Node.TEXT_NODE)continue;if(J.nodeType===Node.ELEMENT_NODE){let Q=J;if(!E5.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return $.childNodes.length>0}function x5($){let J="";for(let Q of $.childNodes)if(Q.nodeType===Node.TEXT_NODE)J+=Q.textContent||"";else if(Q.nodeType===Node.ELEMENT_NODE){let Z=Q;if(Z.tagName==="CODE")J+="`"+(Z.textContent||"")+"`";else J+=Z.textContent||""}return J.trim()}function p5($,J,Q){let Z=$.getAttribute("data-md");if(Z)switch(Z){case"section":return c5($,J,Q);case"item":return d5($,J);case"codeblock":return r5($,J);case"callout":return l5($,J);case"note":return i5($,J);case"table":return a5($,J);case"checklist":return o5($,J);case"diff":return s5($,J);case"mermaid":return t5($,J);case"choice":return n5($,J);case"multichoice":return e5($,J);case"choice-option":case"multichoice-option":return;case"userinput":return $2($,J);case"rangeinput":return J2($,J);case"checklist-item":return;case"filepreview":return Q2($,J);case"priority":return Y2($,J)}if($.querySelector("button, input, select, textarea"))return;if($.children.length>0)E1($,J,Q);else{let Y=$.textContent?.trim();if(Y)J.push(Y,"")}}function c5($,J,Q){let Z=$.getAttribute("data-md-title")||"Untitled",Y=Q===0?"##":"###";J.push(`${Y} ${Z}`,"");let X=$.querySelector(":scope > div:last-of-type");if(X)E1(X,J,Q+1)}function d5($,J){let Q=$.getAttribute("data-md-label")||"",Z=$.getAttribute("data-md-status"),Y=$.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let z=`${X} **${Q}**`;if(Y)z+=` \`${Y}\``;J.push(z);let q=$.querySelector(".text-text-secondary");if(q){let _=[];E1(q,_,0);for(let U of _)J.push(U?` ${U}`:"")}J.push("")}function r5($,J){let Q=$.getAttribute("data-md-language")||"",Y=$.querySelector("code")?.textContent||"";J.push(`\`\`\`${Q}`,Y,"```","")}function l5($,J){let Q=$.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Y=Z2($.querySelector(".text-text-secondary")||$);J.push(`> **${Z[Q]||Q}:** ${Y}`,"")}function i5($,J){let Q=$.textContent?.trim()||"";J.push(`> *${Q}*`,"")}function a5($,J){let Q=$.querySelector("table");if(!Q)return;let Z=[];for(let Y of Q.querySelectorAll("thead th"))Z.push(Y.textContent?.trim()||"");if(Z.length===0)return;J.push(`| ${Z.join(" | ")} |`),J.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Y of Q.querySelectorAll("tbody tr")){let X=[];for(let z of Y.querySelectorAll("td"))X.push(z.textContent?.trim()||"");J.push(`| ${X.join(" | ")} |`)}J.push("")}function o5($,J){for(let Q of $.querySelectorAll("li")){let Z=Q.querySelector(".bg-accent-green")!==null,Y=Q.textContent?.trim()||"";J.push(`- [${Z?"x":" "}] ${Y}`)}J.push("")}function s5($,J){let Q=$.getAttribute("data-md-language")||"";J.push(`\`\`\`diff${Q?` (${Q})`:""}`);for(let Z of $.querySelectorAll("[class*='flex']")){let Y=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)J.push(`${Y} ${X.textContent}`)}J.push("```","")}function t5($,J){let Q=$.getAttribute("data-md-source")||"";if(Q)J.push("```mermaid",Q,"```","")}function n5($,J){let Q=$.getAttribute("data-md-label")||"";J.push(`**${Q}:**`);for(let Z of $.querySelectorAll("[data-md='choice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;J.push(`- ${X?"(x)":"( )"} ${Y}`)}J.push("")}function e5($,J){let Q=$.getAttribute("data-md-label")||"";J.push(`**${Q}:**`);for(let Z of $.querySelectorAll("[data-md='multichoice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;J.push(`- [${X?"x":" "}] ${Y}`)}J.push("")}function $2($,J){let Q=$.getAttribute("data-md-label")||"",Y=$.querySelector("textarea")?.value?.trim()||"";J.push(`**${Q}:** ${Y||"_empty_"}`,"")}function J2($,J){let Q=$.getAttribute("data-md-label")||"",Z=$.querySelector("input[type='range']"),X=$.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";J.push(`**${Q}:** ${X}`,"")}function Q2($,J){let Q=$.getAttribute("data-md-path")||"",Z=$.getAttribute("data-md-lines")||"",X=$.querySelector("code")?.textContent||"",z=Q.split(".").pop()||"",q=u1[z]||"",_=Z?`${Q} (L${Z})`:Q;J.push(_,"",`\`\`\`${q}`,X,"```","")}function Y2($,J){}function Z2($){return $?.textContent?.trim()||""}import O2,{useEffect as W1,useState as l,useRef as Z1}from"react";import{useEffect as X2,useState as z2,useRef as q2,useContext as _2}from"react";import{jsxDEV as t,Fragment as h0}from"react/jsx-dev-runtime";function U2($){return $.label||`Round ${$.revision}`}function K2($){let J=Date.now()-new Date($).getTime(),Q=Math.floor(J/1000);if(Q<60)return"just now";let Z=Math.floor(Q/60);if(Z<60)return`${Z}m ago`;let Y=Math.floor(Z/60);if(Y<24)return`${Y}h ago`;return`${Math.floor(Y/24)}d ago`}function A1({value:$,onChange:J,accent:Q="default",className:Z}){let{currentRevision:Y,revisions:X}=_2(H1),[z,q]=z2(!1),_=q2(null);X2(()=>{if(!z)return;let G=(W)=>{if(_.current&&!_.current.contains(W.target))q(!1)};return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[z]);let U=X.find((G)=>G.revision===$);return t("div",{className:"relative",ref:_,children:[t("button",{onClick:()=>q(!z),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Q]} ${Z||""}`,children:[U?U2(U):`Round ${$}`,t("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${z?"rotate-180":""}`,children:t("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z&&t("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((G)=>t("button",{onClick:()=>{J(G.revision),q(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${G.revision===$?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[t("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${G.revision===Y?"bg-accent-green":G.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),t("span",{className:"flex-1 text-left truncate",children:G.label?t(h0,{children:[G.label," ",t("span",{className:"text-text-tertiary",children:["#",G.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):t(h0,{children:["Round ",G.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),t("span",{className:"text-[10px] text-text-tertiary flex-shrink-0",children:G.revision===Y?"current":G.hasFeedback?"sent":K2(G.createdAt)},void 0,!1,void 0,this)]},G.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function h1($,J){let Q=$.length,Z=J.length;if(Q===0||Z===0)return[];let Y=Array.from({length:Q+1},()=>Array(Z+1).fill(0));for(let _=1;_<=Q;_++)for(let U=1;U<=Z;U++)Y[_][U]=$[_-1]===J[U-1]?Y[_-1][U-1]+1:Math.max(Y[_-1][U],Y[_][U-1]);let X=[],z=Q,q=Z;while(z>0&&q>0)if($[z-1]===J[q-1])X.unshift($[z-1]),z--,q--;else if(Y[z-1][q]>Y[z][q-1])z--;else q--;return X}function x0($){let J=[],Q=[],Z=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(X){let z=X.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=Z.nextNode()){let z=(Y.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let q=0;for(let _ of z)J.push(_),Q.push({text:_,node:Y,offset:q}),q+=_.length}return{words:J,map:Q}}function Z0($,J){if($.length>5000||J.length>5000)return G2($,J);return d0($,J)}function d0($,J){let Q=x1($,J),Z=[],Y=[],X=0,z=0,q=0;while(X<$.length||z<J.length)if(q<Q.length&&X<$.length&&z<J.length&&$[X]===Q[q]&&J[z]===Q[q])Z.push({type:"same",index:X}),Y.push({type:"same",index:z}),X++,z++,q++;else if(X<$.length&&(q>=Q.length||$[X]!==Q[q]))Z.push({type:"removed",index:X}),X++;else if(z<J.length)Y.push({type:"added",index:z}),z++;return{oldOps:Z,newOps:Y}}function x1($,J){let Q=$.length,Z=J.length;if(Q===0||Z===0)return[];if(Q===1)return J.includes($[0])?[$[0]]:[];if(Z===1)return $.includes(J[0])?[J[0]]:[];if(Q*Z<=1e6)return h1($,J);let Y=Math.floor(Q/2),X=$.slice(0,Y),z=$.slice(Y),q=p0(X,J),_=p0([...z].reverse(),[...J].reverse()),U=0,K=0;for(let T=0;T<=Z;T++){let N=q[T]+_[Z-T];if(N>U)U=N,K=T}let G=J.slice(0,K),W=J.slice(K);return[...x1(X,G),...x1(z,W)]}function p0($,J){let Q=J.length,Z=Array(Q+1).fill(0),Y=Array(Q+1).fill(0);for(let X=0;X<$.length;X++){for(let z=1;z<=Q;z++)Y[z]=$[X]===J[z-1]?Z[z-1]+1:Math.max(Z[z],Y[z-1]);[Z,Y]=[Y,Z],Y.fill(0)}return Z}function G2($,J){let Z=(N)=>{let S=[];for(let O=0;O<N.length;O+=200){let P=Math.min(O+200,N.length);S.push({start:O,end:P,text:N.slice(O,P).join("")})}return S},Y=Z($),X=Z(J),z=Y.map((N)=>N.text),q=X.map((N)=>N.text),_=x1(z,q),U=[],K=[],G=0,W=0,T=0;while(G<Y.length||W<X.length)if(T<_.length&&G<Y.length&&W<X.length&&z[G]===_[T]&&q[W]===_[T]){for(let N=Y[G].start;N<Y[G].end;N++)U.push({type:"same",index:N});for(let N=X[W].start;N<X[W].end;N++)K.push({type:"same",index:N});G++,W++,T++}else if(G<Y.length&&(T>=_.length||z[G]!==_[T]))if(W<X.length&&(T>=_.length||q[W]!==_[T])){let N=d0($.slice(Y[G].start,Y[G].end),J.slice(X[W].start,X[W].end));for(let S of N.oldOps)U.push({type:S.type,index:S.index+Y[G].start});for(let S of N.newOps)K.push({type:S.type,index:S.index+X[W].start});G++,W++}else{for(let N=Y[G].start;N<Y[G].end;N++)U.push({type:"removed",index:N});G++}else if(W<X.length){for(let N=X[W].start;N<X[W].end;N++)K.push({type:"added",index:N});W++}return{oldOps:U,newOps:K}}function c0($,J,Q){let Z=new Map;for(let Y of $){if(Y.type==="same")continue;let X=J[Y.index];if(!X||!X.node.parentNode)continue;let z=Z.get(X.node);if(!z)z=[],Z.set(X.node,z);z.push({offset:X.offset,length:X.text.length})}for(let[Y,X]of Z){if(!Y.parentNode)continue;let z=Y.nodeValue||"";X.sort((G,W)=>G.offset-W.offset);let q=[];for(let G of X){let W=q[q.length-1];if(W&&G.offset<=W.offset+W.length)W.length=Math.max(W.length,G.offset+G.length-W.offset);else q.push({...G})}let _=Y.parentNode,U=document.createDocumentFragment(),K=0;for(let G of q){if(G.offset>K)U.appendChild(document.createTextNode(z.slice(K,G.offset)));let W=document.createElement("span");W.className=Q,W.textContent=z.slice(G.offset,G.offset+G.length),U.appendChild(W),K=G.offset+G.length}if(K<z.length)U.appendChild(document.createTextNode(z.slice(K)));_.replaceChild(U,Y)}}function r0($,J){let Q=x0($),Z=x0(J),{oldOps:Y,newOps:X}=Z0(Q.words,Z.words),z=Y.some((q)=>q.type==="removed")||X.some((q)=>q.type==="added");return c0(Y,Q.map,"diff-removed"),c0(X,Z.map,"diff-added"),z}function X0($){let J=[],Q=$.querySelectorAll(":scope > [data-md]");for(let Z of Q)J.push(w1(Z));if(J.length===0){let Z=$.querySelectorAll("[data-md]"),Y=new Set;for(let X of Z){let z=X.parentElement?.closest("[data-md]");if(z&&$.contains(z))continue;if(Y.has(X))continue;Y.add(X),J.push(w1(X))}}return J}function w1($){let J=$.getAttribute("data-md")||"unknown",Q=H2($,J),Z=[];if(J==="section"){let Y=$.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Y)for(let X of Y.querySelectorAll(":scope > [data-md]"))Z.push(w1(X))}else if(J==="table")for(let Y of $.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Y.textContent||"").slice(0,80),type:"tr",element:Y,children:[]});else if(J==="checklist")for(let Y of $.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(w1(Y));else for(let Y of $.querySelectorAll("[data-md]"))if(Y.parentElement?.closest("[data-md]")===$)Z.push(w1(Y));return{key:Q,type:J,element:$,children:Z}}function H2($,J){switch(J){case"section":return"section:"+($.getAttribute("data-md-title")||"");case"item":return"item:"+($.getAttribute("data-task-id")||$.getAttribute("data-md-label")||"");case"codeblock":case"diff":return J+":"+($.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+$.querySelectorAll("[data-md='checklist-item']").length;case"callout":return"callout:"+($.getAttribute("data-md-type")||"")+":"+($.textContent||"").slice(0,60);default:return J+":"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"")}}function z0($,J){let Q=$.map((U)=>U.key),Z=J.map((U)=>U.key),Y=h1(Q,Z),X=[],z=0,q=0,_=0;while(z<$.length||q<J.length)if(_<Y.length&&z<$.length&&q<J.length&&Q[z]===Y[_]&&Z[q]===Y[_]){let U=$[z],K=J[q],G=U.children.length>0||K.children.length>0?z0(U.children,K.children):void 0;X.push({kind:"matched",oldBlock:U,newBlock:K,childMatches:G}),z++,q++,_++}else if(z<$.length&&(_>=Y.length||Q[z]!==Y[_]))X.push({kind:"removed",oldBlock:$[z]}),z++;else if(q<J.length)X.push({kind:"added",newBlock:J[q]}),q++;return X}function i0($){let J=document.createDocumentFragment(),Q=!1;for(let Z of $)if(Z.kind==="removed")Q=!0,J.appendChild(a0(Z.oldBlock.element));else if(Z.kind==="added")Q=!0,J.appendChild(W2(Z.newBlock.element));else{let Y=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(s0(Y,Z.childMatches,X))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(o0(Z.oldBlock,Y,Z.childMatches,X))Q=!0}else if(C1(Z.oldBlock.element,Y,!1))Q=!0;J.appendChild(Y)}return{fragment:J,hasChanges:Q}}function a0($){let J=$.cloneNode(!0);return J.classList.add("diff-block-removed"),J.style.position="relative",q0(J,"Removed","var(--color-accent-red)"),J}function W2($){let J=$.cloneNode(!0);return J.classList.add("diff-block-added"),J.style.position="relative",q0(J,"Added","var(--color-accent-green)"),J}function o0($,J,Q,Z){let Y=!1,X=T2($,J),z,q;if(Z==="section"){let _=$.element.querySelector(":scope > div:first-child"),U=J.querySelector(":scope > div:first-child");if(_&&U){if(C1(_,U,!1))Y=!0}z=$.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),q=J.querySelector(":scope > div.mt-6, :scope > div:last-child")}else z=$.element,q=J;if(!z||!q)return Y;for(let _ of Q)if(_.kind==="matched"){let U=X.newMap.get(_.newBlock.element);if(U){if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(s0(U,_.childMatches,_.newBlock.type))Y=!0}else if(_.childMatches&&_.childMatches.length>0){if(o0(_.oldBlock,U,_.childMatches,_.newBlock.type))Y=!0}else if(C1(_.oldBlock.element,U,!1))Y=!0}}else if(_.kind==="removed"){Y=!0;let U=a0(_.oldBlock.element),K=N2(Q,_,X.newMap);q.insertBefore(U,K)}else if(_.kind==="added"){Y=!0;let U=X.newMap.get(_.newBlock.element);if(U)U.classList.add("diff-block-added"),U.style.position="relative",q0(U,"Added","var(--color-accent-green)")}if(C1(z,q,!0))Y=!0;return Y}function s0($,J,Q){let Z=Q==="table"?$.querySelector(":scope table > tbody"):$;if(!Z)return!1;let Y=!1;Z.innerHTML="";for(let X of J)if(X.kind==="removed"){Y=!0;let z=X.oldBlock.element.cloneNode(!0);z.classList.add(Q==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(z)}else if(X.kind==="added"){Y=!0;let z=X.newBlock.element.cloneNode(!0);z.classList.add(Q==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(z)}else{let z=X.newBlock.element.cloneNode(!0);if(C1(X.oldBlock.element,z,!1))Y=!0;Z.appendChild(z)}return Y}function T2($,J){let Q=new Map,Z=$.element.querySelectorAll("[data-md]"),Y=J.querySelectorAll("[data-md]");return{newMap:{get(X){return F2(J,X)}}}}function F2($,J){let Q=J.getAttribute("data-md");if(!Q)return null;let Z=J.getAttribute("data-md-label"),Y=J.getAttribute("data-md-title"),X=`[data-md="${Q}"]`;if(Y)X+=`[data-md-title="${CSS.escape(Y)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let z=$.querySelectorAll(X);if(z.length===1)return z[0];let q=(J.textContent||"").slice(0,100),_=null,U=-1;for(let K of z){let G=(K.textContent||"").slice(0,100),W=0;for(let T=0;T<Math.min(q.length,G.length);T++)if(q[T]===G[T])W++;if(W>U)U=W,_=K}return _}function N2($,J,Q){let Z=$.indexOf(J);for(let Y=Z+1;Y<$.length;Y++){let X=$[Y];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Q.get(X.newBlock.element)||null}return null}function l0($,J){let Q=J?new Set(Array.from($.querySelectorAll("[data-md]"))):new Set,Z=[],Y=[],X=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(q){let _=q.parentElement;if(!_)return NodeFilter.FILTER_REJECT;if(_.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if(J){for(let U of Q)if(U.contains(q))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),z;while(z=X.nextNode()){let _=(z.nodeValue||"").match(/\S+|\s+/g);if(!_)continue;let U=0;for(let K of _)Z.push(K),Y.push({text:K,node:z,offset:U}),U+=K.length}return{words:Z,map:Y}}function C1($,J,Q){let Z=l0($,Q),Y=l0(J,Q);if(Z.words.length===0&&Y.words.length===0)return!1;let{oldOps:X,newOps:z}=Z0(Z.words,Y.words),q=X.some((O)=>O.type==="removed"),_=z.some((O)=>O.type==="added");if(!q&&!_)return!1;let U=[],K=[];for(let O of X)if(O.type==="same")U.push(O.index);for(let O of z)if(O.type==="same")K.push(O.index);let G=new Map;for(let O=0;O<U.length&&O<K.length;O++)G.set(U[O],K[O]);let W=[];{let O=[],P=-1;for(let w of X)if(w.type==="same"){if(O.length>0)W.push({text:O.join(""),anchorNewIdx:P>=0?G.get(P)??null:null}),O=[];P=w.index}else if(w.type==="removed")O.push(Z.words[w.index]);if(O.length>0)W.push({text:O.join(""),anchorNewIdx:P>=0?G.get(P)??null:null})}let T=new Map,N=new Map;for(let O of z){if(O.type!=="added")continue;let P=Y.map[O.index];if(!P?.node.parentNode)continue;let w=T.get(P.node);if(!w)w=[],T.set(P.node,w);w.push({start:P.offset,end:P.offset+P.text.length})}for(let O of W)if(O.anchorNewIdx===null){if(Y.map.length>0){let P=Y.map[0].node,w=N.get(P);if(!w)w=[],N.set(P,w);w.push({offset:0,text:O.text})}}else{let P=Y.map[O.anchorNewIdx];if(!P)continue;let w=N.get(P.node);if(!w)w=[],N.set(P.node,w);w.push({offset:P.offset+P.text.length,text:O.text})}let S=new Set([...T.keys(),...N.keys()]);for(let O of S)L2(O,T.get(O)||[],N.get(O)||[]);return!0}function L2($,J,Q){if(!$.parentNode)return;let Z=$.nodeValue||"";J.sort((K,G)=>K.start-G.start);let Y=[];for(let K of J){let G=Y[Y.length-1];if(G&&K.start<=G.end)G.end=Math.max(G.end,K.end);else Y.push({...K})}Q.sort((K,G)=>K.offset-G.offset);let X=$.parentNode,z=document.createDocumentFragment(),q=0,_=0,U=0;while(q<=Z.length){let K=_<Y.length?Y[_].start:1/0,G=U<Q.length?Q[U].offset:1/0,W=Math.min(K,G);if(W===1/0){if(q<Z.length)z.appendChild(document.createTextNode(Z.slice(q)));break}let T=Math.max(W,q);if(T>q)z.appendChild(document.createTextNode(Z.slice(q,T))),q=T;while(U<Q.length&&Q[U].offset<=q){let N=document.createElement("span");N.className="diff-removed",N.textContent=Q[U].text,z.appendChild(N),U++}if(_<Y.length&&Y[_].start<=q){let N=Y[_],S=document.createElement("span");S.className="diff-added",S.textContent=Z.slice(q,N.end),z.appendChild(S),q=N.end,_++;while(U<Q.length&&Q[U].offset<=q){let O=document.createElement("span");O.className="diff-removed",O.textContent=Q[U].text,z.appendChild(O),U++}}}while(U<Q.length){let K=document.createElement("span");K.className="diff-removed",K.textContent=Q[U].text,z.appendChild(K),U++}X.replaceChild(z,$)}function q0($,J,Q){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=J,Z.style.color=Q,Z.style.backgroundColor=`color-mix(in srgb, ${Q} 12%, transparent)`,$.appendChild(Z)}import{jsxDEV as k}from"react/jsx-dev-runtime";function t0({initialLeft:$,initialRight:J,sessionId:Q,onExit:Z}){let[Y,X]=l($),[z,q]=l(J),[_,U]=l("unified"),[K,G]=l(!0),[W,T]=l(!1);return k("div",{className:"flex flex-col h-screen",children:[k("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[k("div",{className:"flex items-center gap-3",children:[k("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),k(A1,{value:Y,onChange:X,accent:"red"},void 0,!1,void 0,this),k("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),k(A1,{value:z,onChange:q,accent:"green"},void 0,!1,void 0,this),W&&!K&&k("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k("div",{className:"flex items-center gap-4",children:[k("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[k("button",{onClick:()=>U("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),k("button",{onClick:()=>U("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="side-by-side"&&k(M2,{},void 0,!1,void 0,this),k("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),_==="unified"?k(B2,{sessionId:Q,leftRev:Y,rightRev:z,onDiffResult:(N,S)=>{T(N),G(S)}},`unified-${Y}-${z}`,!1,void 0,this):k(y2,{sessionId:Q,leftRev:Y,rightRev:z,onDiffResult:(N,S)=>{T(N),G(S)}},`sbs-${Y}-${z}`,!1,void 0,this)]},void 0,!0,void 0,this)}function M2(){let[$,J]=l(!0);return W1(()=>{return document.documentElement.dataset.syncScroll=$?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[$]),k("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[k("input",{type:"checkbox",checked:$,onChange:(Q)=>J(Q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),k("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B2({sessionId:$,leftRev:J,rightRev:Q,onDiffResult:Z}){let Y=Z1(null),X=Z1(null),z=Z1(null),[q,_]=l(!1),[U,K]=l(!1),[G,W]=l(!1);return W1(()=>{if(!q||!U||G)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!z.current)return;let T=X0(Y.current),N=X0(X.current),S=z0(T,N),{fragment:O,hasChanges:P}=i0(S);z.current.innerHTML="",z.current.appendChild(O),W(!0),Z(!0,P)})})},[q,U,G]),k("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[k("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[k(p1,{ref:Y,sessionId:$,revision:J,onReady:()=>_(!0)},void 0,!1,void 0,this),k(p1,{ref:X,sessionId:$,revision:Q,onReady:()=>K(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!G&&k("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),k("div",{ref:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function y2({sessionId:$,leftRev:J,rightRev:Q,onDiffResult:Z}){let Y=Z1(null),X=Z1(null),[z,q]=l(!1),[_,U]=l(!1),[K,G]=l(!1),W=Z1(null),T=Z1(null),N=Z1(!1);return W1(()=>{if(!z||!_||K)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let S=r0(Y.current,X.current);G(!0),Z(!0,S)})})},[z,_,K]),W1(()=>{let S=W.current,O=T.current;if(!S||!O)return;let P=(R,D)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let m=R.scrollHeight-R.clientHeight,j=D.scrollHeight-D.clientHeight;if(m>0&&j>0)D.scrollTop=R.scrollTop/m*j;requestAnimationFrame(()=>{N.current=!1})},w=()=>P(S,O),B=()=>P(O,S);return S.addEventListener("scroll",w),O.addEventListener("scroll",B),()=>{S.removeEventListener("scroll",w),O.removeEventListener("scroll",B)}},[]),k("div",{className:"flex flex-1 min-h-0",children:[k("div",{ref:W,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:k(p1,{ref:Y,sessionId:$,revision:J,onReady:()=>q(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),k("div",{ref:T,className:"w-1/2 overflow-y-auto",children:k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:k(p1,{ref:X,sessionId:$,revision:Q,onReady:()=>U(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var p1=O2.forwardRef(({sessionId:$,revision:J,onReady:Q},Z)=>{let[Y,X]=l(null),[z,q]=l(null),[_,U]=l(!0);if(W1(()=>{U(!0),q(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((K)=>{X(()=>K.default),U(!1)}).catch((K)=>{q(K.message),U(!1)})},[$,J]),W1(()=>{if(!Y)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[Y]),_)return k("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(z)return k("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[k("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),k("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return k("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);return k("div",{ref:Z,children:k(Y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)});import{jsxDEV as F,Fragment as _0}from"react/jsx-dev-runtime";var G1=e0({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),H1=e0({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function J5(){let[$,J]=i(()=>localStorage.getItem("canvas-theme")||document.documentElement.dataset.theme||"dark");return F("button",{onClick:()=>{let Z=$==="dark"?"light":"dark";document.documentElement.dataset.theme=Z,localStorage.setItem("canvas-theme",Z),J(Z)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:$==="dark"?"Switch to light theme":"Switch to dark theme",children:$==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Q5(){let{currentRevision:$,selectedRevision:J,revisions:Q,setSelectedRevision:Z,setCompareRevision:Y}=U1.useContext(H1);if(Q.length<=1){let q=Q[0]?.label||`Round ${$}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:q},void 0,!1,void 0,this)}return F("div",{className:"flex items-center gap-1.5",children:[F(A1,{value:J,onChange:Z,accent:J===$?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let q=Q.find((U)=>U.revision===J)?.sourceFile,_;if(J===$)_=[...Q].reverse().find((K)=>K.revision<$&&(!q||K.sourceFile===q))?.revision??Math.max(1,$-1);else _=J;Y({left:_,right:$})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function w2(){let $=window.location.pathname.replace("/s/","")||"",[J,Q]=i(1),[Z,Y]=i(1),[X,z]=i([]),[q,_]=i(null),[U,K]=i(!1),[G,W]=i(!1),[T,N]=i({type:"plan"}),[S,O]=i([]),P=T1(null),[w,B]=i(),[R,D]=i(!1),[m,j]=i(!1),[C,I]=i(!1);c1(()=>{let M=["Agent Canvas"];if(w){let L=w.replace(/\/+$/,"").split("/");M.push(L[L.length-1]||$)}else if($)M.push($);if(T.type==="file")M.push(T.path.split("/").pop()||T.path);else if(q)M.push("Compare");document.title=M.join(" — ")},[$,w,T,q]);let H=T1(new Map),y=X.find((M)=>M.revision===Z),E=Z!==J||!!y?.hasFeedback,c=d1((M)=>{if(H.current.set(T.type==="plan"?"plan":`file:${T.path}`,window.scrollY),N(M),M.type==="file")O((L)=>L.includes(M.path)?L:[...L,M.path])},[T]),$1=d1((M)=>{H.current.delete(`file:${M}`),O((L)=>L.filter((A)=>A!==M)),N((L)=>{if(L.type==="file"&&L.path===M)return H.current.set(`file:${M}`,window.scrollY),{type:"plan"};return L})},[]);P2(()=>{let M=T.type==="plan"?"plan":`file:${T.path}`;window.scrollTo(0,H.current.get(M)||0)},[T]),c1(()=>{if(!$)return;fetch(`/api/session/${$}/meta`).then((M)=>M.json()).then((M)=>{if(M.currentRevision)Q(M.currentRevision),Y(M.currentRevision),z(M.revisions||[]);if(M.projectRoot)B(M.projectRoot)}).catch(()=>{})},[$]),c1(()=>{if(!$)return;let M=null,L=()=>{let A=window.location.protocol==="https:"?"wss:":"ws:",u=new WebSocket(`${A}//${window.location.host}/ws/session/${$}`);P.current=u,u.onopen=()=>K(!0),u.onclose=()=>{K(!1),M=setTimeout(L,2000)},u.onmessage=(h)=>{try{let b=JSON.parse(h.data);if(b.type==="plan-updated"){if(Q(b.currentRevision),Y(b.currentRevision),_(null),b.revisions)z(b.revisions)}if(b.type==="revision-updated"){if(b.revisions)z(b.revisions)}}catch{}}};return L(),()=>{if(M)clearTimeout(M);P.current?.close()}},[$]);let Q1=d1((M)=>{if(P.current?.readyState===WebSocket.OPEN)P.current.send(JSON.stringify({type:"submit",feedback:M})),W(!1)},[]);if(!$)return F("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return F($5.Provider,{value:$,children:F(H1.Provider,{value:{currentRevision:J,selectedRevision:Z,revisions:X,setSelectedRevision:Y,isReadOnly:E,compareRevision:q,setCompareRevision:_},children:F(G0,{sessionId:$,revision:Z,isReadOnly:E,children:F(G1.Provider,{value:{activeView:T,setActiveView:c,openFiles:S,closeFile:$1},children:F(A2.Provider,{value:{setActiveView:c},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(C2,{sessionId:$,projectRoot:w,connected:U,onMobileSidebar:()=>D(!R),collapsed:m,onToggle:()=>j((M)=>!M)},void 0,!1,void 0,this),q===null&&F(I2,{collapsed:C,onToggle:()=>I((M)=>!M),children:F(J0,{onPreview:()=>W(!0),onSubmit:Q1},void 0,!1,void 0,this)},void 0,!1,void 0,this),q!==null?F("div",{className:`${m?"lg:ml-0":"lg:ml-60"} transition-[margin] duration-200`,children:F(t0,{initialLeft:q.left,initialRight:q.right,sessionId:$,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${m?"lg:ml-0":"lg:ml-60"} ${C?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[F("div",{className:"flex items-center gap-2",children:[F(Y0,{currentSessionId:$,projectRoot:w},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full ${U?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(Q5,{},void 0,!1,void 0,this),F("button",{onClick:()=>D(!R),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(J5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(R2,{},void 0,!1,void 0,this),F("div",{style:{display:T.type==="plan"?void 0:"none"},children:F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[F("button",{onClick:()=>{let M=document.querySelector(".plan-content");if(!M)return;let L=E0(M);navigator.clipboard.writeText(L).then(()=>{let A=document.getElementById("export-md-btn");if(A)A.setAttribute("data-copied","true"),setTimeout(()=>{A.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:F("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(P0,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),S.map((M)=>F("div",{style:{display:T.type==="file"&&T.path===M?void 0:"none"},children:F(f0,{path:M},void 0,!1,void 0,this)},M,!1,void 0,this))]},void 0,!0,void 0,this),R&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>D(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>D(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 overflow-hidden",children:F(J0,{onPreview:()=>W(!0),onSubmit:Q1},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(I0,{open:G,onClose:()=>W(!1),onSubmit:Q1},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${$}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function C2({sessionId:$,projectRoot:J,connected:Q,onMobileSidebar:Z,collapsed:Y,onToggle:X}){return F(_0,{children:[Y&&F("button",{onClick:X,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Y?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(Y0,{currentSessionId:$,projectRoot:J},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),F("button",{onClick:X,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(Q5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(g0,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F(J5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function I2({children:$,collapsed:J,onToggle:Q}){let[Z,Y]=i(()=>{let K=localStorage.getItem("canvas-sidebar-width");return K?parseInt(K,10):320}),X=T1(!1),z=T1(0),q=T1(0),_=T1(Z);_.current=Z;let U=d1((K)=>{K.preventDefault(),X.current=!0,z.current=K.clientX,q.current=_.current;let G=(T)=>{if(!X.current)return;let N=z.current-T.clientX,S=Math.max(240,Math.min(600,q.current+N));Y(S),_.current=S},W=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(_.current)),document.removeEventListener("mousemove",G),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",G),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return c1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),F(_0,{children:[J&&F("button",{onClick:Q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${J?"translate-x-full":""}`,style:{width:Z},children:[F("div",{onMouseDown:U,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),U1.Children.map($,(K)=>U1.isValidElement(K)?U1.cloneElement(K,{collapseButton:F("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):K)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function R2(){let{activeView:$,setActiveView:J,openFiles:Q,closeFile:Z}=U1.useContext(G1),Y=U1.useContext($5),{addAnnotationWithId:X,setActiveAnnotationId:z}=o(),q=Q.length>0;if(!q)return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[q&&F("button",{onClick:()=>J({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${$.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Plan",$.type==="plan"&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&F(_0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((_,U)=>{let K=_.split("/").pop()||_,G=$.type==="file"&&$.path===_;return F(U1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>J({type:"file",path:_}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-mono whitespace-nowrap transition-colors relative ${G?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[K,G&&F("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:(W)=>{W.stopPropagation(),Z(_)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U<Q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:$.type==="file"&&F("button",{onClick:async()=>{let _=$.path;try{let K=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(_)}`)).json();if(!K.error){let G=K.content.split(`
65
65
  `).slice(0,3).join(`
66
66
  `)+(K.content.split(`
67
67
  `).length>3?`
68
- ...`:""),W=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;X(W,G,"",q),z(W)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[F("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var t0=document.getElementById("root");if(t0)P2(t0).render(F(A2,{},void 0,!1,void 0,this));export{H1 as RevisionContext,G1 as ActiveViewContext};
68
+ ...`:""),W=`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;X(W,G,"",_),z(W)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[F("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var n0=document.getElementById("root");if(n0)S2(n0).render(F(w2,{},void 0,!1,void 0,this));export{H1 as RevisionContext,G1 as ActiveViewContext};