@plannotator/opencode 0.17.2 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,7 +80,7 @@ Error generating stack: `+m.message+`
80
80
  created: ${new Date().toISOString().slice(0,19)}Z
81
81
  source: plannotator
82
82
  tags: [plan, ...]
83
- ---`})]}),p.jsx("div",{className:"border-t border-border/30"}),p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium",children:"Auto-save on Plan Arrival"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Automatically save to Obsidian when a plan loads, before you approve or deny"})]}),p.jsx("button",{role:"switch","aria-checked":v.autoSave,onClick:()=>ft({autoSave:!v.autoSave}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${v.autoSave?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${v.autoSave?"translate-x-6":"translate-x-1"}`})})]}),p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium",children:"Vault Browser"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Browse and annotate vault files from the sidebar"})]}),p.jsx("button",{role:"switch","aria-checked":v.vaultBrowserEnabled,onClick:()=>ft({vaultBrowserEnabled:!v.vaultBrowserEnabled}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${v.vaultBrowserEnabled?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${v.vaultBrowserEnabled?"translate-x-6":"translate-x-1"}`})})]})]})]})]}),h==="bear"&&p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-sm font-medium",children:"Bear Notes"}),p.jsx("div",{className:"text-xs text-muted-foreground",children:"Auto-save approved plans to Bear"})]}),p.jsx("button",{role:"switch","aria-checked":D.enabled,onClick:()=>Kt({enabled:!D.enabled}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${D.enabled?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${D.enabled?"translate-x-6":"translate-x-1"}`})})]}),D.enabled&&p.jsxs("div",{className:"mt-3 space-y-3",children:[p.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[p.jsx("label",{className:"text-xs text-muted-foreground",children:"Custom Tags"}),p.jsx("input",{type:"text",value:D.customTags,onChange:ae=>Kt({customTags:ae.target.value}),onBlur:ae=>Kt({customTags:BM(ae.target.value)}),placeholder:"plan, work",className:"w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Comma-separated, kebab-case. Leave empty for auto-generated tags."})]}),p.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[p.jsx("label",{className:"text-xs text-muted-foreground",children:"Tag Position"}),p.jsxs("select",{value:D.tagPosition,onChange:ae=>Kt({tagPosition:ae.target.value}),className:"w-full px-3 py-2 bg-muted rounded-lg text-xs focus:outline-none focus:ring-1 focus:ring-primary/50",children:[p.jsx("option",{value:"append",children:"Append (end of note)"}),p.jsx("option",{value:"prepend",children:"Prepend (after title)"})]})]}),p.jsx("div",{className:"border-t border-border/30"}),p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium",children:"Auto-save on Plan Arrival"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Automatically save to Bear when a plan loads, before you approve or deny"})]}),p.jsx("button",{role:"switch","aria-checked":D.autoSave,onClick:()=>Kt({autoSave:!D.autoSave}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${D.autoSave?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${D.autoSave?"translate-x-6":"translate-x-1"}`})})]})]})]}),h==="octarine"&&p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-sm font-medium",children:"Octarine"}),p.jsx("div",{className:"text-xs text-muted-foreground",children:"Auto-save approved plans to Octarine"})]}),p.jsx("button",{role:"switch","aria-checked":N.enabled,onClick:()=>xn({enabled:!N.enabled}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${N.enabled?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${N.enabled?"translate-x-6":"translate-x-1"}`})})]}),N.enabled&&p.jsxs("div",{className:"mt-3 space-y-3",children:[p.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[p.jsx("label",{className:"text-xs text-muted-foreground",children:"Workspace Name"}),p.jsx("input",{type:"text",value:N.workspace,onChange:ae=>xn({workspace:ae.target.value}),placeholder:"My Workspace",className:"w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"The Octarine workspace name to save plans into."})]}),p.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[p.jsx("label",{className:"text-xs text-muted-foreground",children:"Folder"}),p.jsx("input",{type:"text",value:N.folder,onChange:ae=>xn({folder:ae.target.value}),placeholder:"plannotator",className:"w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Subfolder within the workspace for saved plans."})]}),p.jsxs("div",{className:"text-[10px] text-muted-foreground/70",children:["Plans saved to: ",N.workspace||"..."," / ",N.folder||"plannotator","/"]}),p.jsx("div",{className:"border-t border-border/30"}),p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium",children:"Auto-save on Plan Arrival"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Automatically save to Octarine when a plan loads, before you approve or deny"})]}),p.jsx("button",{role:"switch","aria-checked":N.autoSave,onClick:()=>xn({autoSave:!N.autoSave}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${N.autoSave?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${N.autoSave?"translate-x-6":"translate-x-1"}`})})]})]})]})]})})]})]})}),document.body)]})},T8=({onClick:t,disabled:e=!1,isLoading:n=!1,label:a="Send Feedback",shortLabel:r,loadingLabel:s="Sending...",shortLoadingLabel:c,title:u="Send Feedback",muted:d=!1})=>p.jsxs("button",{onClick:t,disabled:e,className:`p-1.5 md:px-2.5 md:py-1 rounded-md text-xs font-medium transition-all ${d?"opacity-50 cursor-not-allowed bg-accent/10 text-accent/50":e?"opacity-50 cursor-not-allowed bg-muted text-muted-foreground":"bg-accent/15 text-accent hover:bg-accent/25 border border-accent/30"}`,title:u,children:[p.jsx("svg",{className:"w-4 h-4 md:hidden",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),r?p.jsxs(p.Fragment,{children:[p.jsx("span",{className:"hidden md:inline lg:hidden",children:n?c??s:r}),p.jsx("span",{className:"hidden lg:inline",children:n?s:a})]}):p.jsx("span",{className:"hidden md:inline",children:n?s:a})]}),F8=({onClick:t,disabled:e=!1,isLoading:n=!1,label:a="Approve",loadingLabel:r="Approving...",mobileLabel:s="OK",mobileLoadingLabel:c="...",title:u,dimmed:d=!1,muted:A=!1})=>p.jsxs("button",{onClick:t,disabled:e,className:`px-2 py-1 md:px-2.5 rounded-md text-xs font-medium transition-all ${A?"opacity-40 cursor-not-allowed bg-muted text-muted-foreground":e?"opacity-50 cursor-not-allowed bg-muted text-muted-foreground":d?"bg-success/50 text-success-foreground/70 hover:bg-success hover:text-success-foreground":"bg-success text-success-foreground hover:opacity-90"}`,title:u,children:[p.jsx("span",{className:"md:hidden",children:n?c:s}),p.jsx("span",{className:"hidden md:inline",children:n?r:a})]}),L8="https://api.github.com/repos/backnotprop/plannotator/releases/latest",BB={"0.5.0":{title:"Code Review is here!",description:"Review git diffs with inline annotations. Run /plannotator-review to try it."}};function M8(t,e){const n=s=>s.replace(/^v/,""),a=n(t).split(".").map(Number),r=n(e).split(".").map(Number);for(let s=0;s<Math.max(a.length,r.length);s++){const c=a[s]||0,u=r[s]||0;if(u>c)return!0;if(u<c)return!1}return!1}function O8(){const[t,e]=E.useState(null);return E.useEffect(()=>{(async()=>{try{const a="0.17.2",s=new URLSearchParams(window.location.search).get("preview-update");if(s){const h=s.replace(/^v/,"");e({currentVersion:a,latestVersion:s,updateAvailable:!0,releaseUrl:`https://github.com/backnotprop/plannotator/releases/tag/v${h}`,featureHighlight:BB[h]});return}const c=await fetch(L8);if(!c.ok)return;const u=await c.json(),d=u.tag_name,A=M8(a,d),g=d.replace(/^v/,""),b=BB[g];e({currentVersion:a,latestVersion:d,updateAvailable:A,releaseUrl:u.html_url,featureHighlight:b})}catch(a){console.debug("Update check failed:",a)}})()},[]),t}const P8="pi install npm:@plannotator/pi-extension";function j8(t){return zM&&!t?'powershell -c "irm https://plannotator.ai/install.ps1 | iex"':"curl -fsSL https://plannotator.ai/install.sh | bash"}const G8=({origin:t,isWSL:e=!1})=>{const n=O8(),[a,r]=E.useState(!1),[s,c]=E.useState(!1),A=new URLSearchParams(window.location.search).get("preview-origin")||t,g=A==="pi",b=A==="opencode",h=g?P8:j8(e);if(!n?.updateAvailable||s)return null;const y=async()=>{try{await navigator.clipboard.writeText(h),r(!0),setTimeout(()=>r(!1),2e3)}catch(k){console.error("Failed to copy:",k)}};return n.featureHighlight?p.jsx("div",{className:"fixed bottom-4 right-4 z-50 max-w-md animate-in slide-in-from-bottom-2 fade-in duration-300",children:p.jsxs("div",{className:"bg-card border border-primary/30 rounded-xl shadow-2xl overflow-hidden",children:[p.jsx("div",{className:"bg-gradient-to-r from-primary/20 to-primary/5 px-5 py-4 border-b border-border/50",children:p.jsxs("div",{className:"flex items-start justify-between gap-3",children:[p.jsxs("div",{className:"flex items-center gap-3",children:[p.jsx("div",{className:"flex-shrink-0 w-10 h-10 rounded-lg bg-primary/20 flex items-center justify-center",children:p.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})})}),p.jsxs("div",{children:[p.jsx("h4",{className:"text-base font-semibold text-foreground",children:n.featureHighlight.title}),p.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["New in ",n.latestVersion]})]})]}),p.jsx("button",{onClick:()=>c(!0),className:"text-muted-foreground hover:text-foreground transition-colors p-1",children:p.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})}),p.jsxs("div",{className:"px-5 py-4",children:[p.jsx("p",{className:"text-sm text-foreground/80 leading-relaxed",children:n.featureHighlight.description}),p.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:["You have ",n.currentVersion]}),b&&p.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Run the install script, then restart OpenCode."}),g&&p.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Run the install command, then restart Pi."}),p.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[p.jsx("button",{onClick:y,className:"flex-1 px-4 py-2 text-sm font-medium bg-primary text-primary-foreground rounded-lg hover:opacity-90 transition-opacity",children:a?"Copied!":"Copy install command"}),p.jsx("a",{href:n.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:"px-4 py-2 text-sm font-medium text-muted-foreground hover:text-foreground border border-border rounded-lg hover:bg-muted transition-colors",children:"Release notes"})]})]})]})}):p.jsx("div",{className:"fixed bottom-4 right-4 z-50 max-w-sm animate-in slide-in-from-bottom-2 fade-in duration-300",children:p.jsx("div",{className:"bg-card border border-border rounded-lg shadow-xl p-4",children:p.jsxs("div",{className:"flex items-start gap-3",children:[p.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-primary/20 flex items-center justify-center",children:p.jsx("svg",{className:"w-4 h-4 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"})})}),p.jsxs("div",{className:"flex-1 min-w-0",children:[p.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Update available"}),p.jsx("button",{onClick:()=>c(!0),className:"text-muted-foreground hover:text-foreground transition-colors",children:p.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),p.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[n.latestVersion," is available (you have ",n.currentVersion,")"]}),p.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[p.jsx("button",{onClick:y,className:"flex-1 px-3 py-1.5 text-xs font-medium bg-primary text-primary-foreground rounded-md hover:opacity-90 transition-opacity",children:a?"Copied!":"Copy install command"}),p.jsx("a",{href:n.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:"px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground border border-border rounded-md hover:bg-muted transition-colors",children:"Notes"})]})]})]})})})};function IB(t){window.close(),setTimeout(()=>{window.closed||t()},300)}function z8(t){const[e,n]=E.useState({phase:"idle"});E.useEffect(()=>{if(!t)return;const r=P1();r==="0"?(IB(()=>n({phase:"closeFailed"})),n({phase:"closed"})):n(r!=="off"?{phase:"counting",remaining:Number(r)}:{phase:"prompt"})},[t]),E.useEffect(()=>{if(e.phase!=="counting")return;if(e.remaining<=0){IB(()=>n({phase:"closeFailed"}));return}const r=setTimeout(()=>n(s=>s.phase==="counting"?{phase:"counting",remaining:s.remaining-1}:s),1e3);return()=>clearTimeout(r)},[e]);const a=E.useCallback(()=>{j1("3"),n({phase:"counting",remaining:3})},[]);return{state:e,enableAndStart:a}}const q8=()=>p.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),U8=()=>p.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})});function H8({submitted:t,title:e,subtitle:n,agentLabel:a}){const{state:r,enableAndStart:s}=z8(!!t);if(!t)return null;const c=t==="approved";return p.jsx("div",{className:"fixed inset-0 z-[100] bg-background flex items-center justify-center",children:p.jsxs("div",{className:"text-center space-y-6 max-w-md px-8",children:[p.jsx("div",{className:`mx-auto w-16 h-16 rounded-full flex items-center justify-center ${c?"bg-success/20 text-success":"bg-accent/20 text-accent"}`,children:c?p.jsx(q8,{}):p.jsx(U8,{})}),p.jsxs("div",{className:"space-y-2",children:[p.jsx("h2",{className:"text-xl font-semibold text-foreground",children:e}),p.jsx("p",{className:"text-muted-foreground",children:n})]}),p.jsx("div",{className:"pt-4 border-t border-border space-y-2",children:r.phase==="counting"?p.jsxs(p.Fragment,{children:[p.jsxs("p",{className:"text-sm text-muted-foreground",children:["This tab will close in ",p.jsx("span",{className:"text-foreground font-medium",children:r.remaining})," second",r.remaining!==1?"s":"","..."]}),p.jsx("p",{className:"text-xs text-muted-foreground/60",children:"You can change this in Settings."})]}):r.phase==="closeFailed"?p.jsxs(p.Fragment,{children:[p.jsx("p",{className:"text-sm text-muted-foreground",children:"Could not close this tab automatically. Please close it manually."}),p.jsxs("p",{className:"text-xs text-muted-foreground/60",children:["Auto-close works when the tab is opened by ",a,"."]})]}):p.jsxs(p.Fragment,{children:[p.jsxs("p",{className:"text-sm text-muted-foreground",children:["You can close this tab and return to ",p.jsx("span",{className:"text-foreground font-medium",children:a}),"."]}),r.phase==="prompt"?p.jsxs(p.Fragment,{children:[p.jsxs("label",{className:"flex items-center justify-center gap-2 cursor-pointer group",children:[p.jsx("input",{type:"checkbox",checked:!1,onChange:s,className:"accent-primary"}),p.jsx("span",{className:"text-xs text-muted-foreground group-hover:text-foreground transition-colors",children:"Auto-close this tab after 3 seconds"})]}),p.jsx("p",{className:"text-xs text-muted-foreground/60",children:"You can change the delay in Settings."})]}):p.jsx("p",{className:"text-xs text-muted-foreground/60",children:"Your response has been sent."})]})})]})})}const Y8=({className:t})=>p.jsx("svg",{className:t,viewBox:"0 0 16 16",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z"})}),$8=({className:t})=>p.jsxs("svg",{className:t,viewBox:"90 90 200 195",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M282.83 170.73l-.27-.69-26.14-68.22a6.81 6.81 0 00-2.69-3.24 7 7 0 00-8 .43 7 7 0 00-2.32 3.52l-17.65 54h-71.47l-17.65-54a6.86 6.86 0 00-2.32-3.53 7 7 0 00-8-.43 6.87 6.87 0 00-2.69 3.24L97.44 170l-.26.69a48.54 48.54 0 0016.1 56.1l.09.07.24.17 39.82 29.82 19.7 14.91 12 9.06a8.07 8.07 0 009.76 0l12-9.06 19.7-14.91 40.06-30 .1-.08a48.56 48.56 0 0016.08-56.04z"}),p.jsx("path",{d:"M282.83 170.73l-.27-.69a88.3 88.3 0 00-35.15 15.8L190 229.25c19.55 14.79 36.57 27.64 36.57 27.64l40.06-30 .1-.08a48.56 48.56 0 0016.1-56.08z",opacity:"0.7"}),p.jsx("path",{d:"M153.43 256.89l19.7 14.91 12 9.06a8.07 8.07 0 009.76 0l12-9.06 19.7-14.91s-17.04-12.89-36.59-27.64c-19.55 14.75-36.57 27.64-36.57 27.64z",opacity:"0.85"}),p.jsx("path",{d:"M132.58 185.84A88.19 88.19 0 0097.44 170l-.26.69a48.54 48.54 0 0016.1 56.1l.09.07.24.17 39.82 29.82s17-12.85 36.57-27.64z",opacity:"0.7"})]}),SB=({className:t})=>p.jsx("svg",{className:t,viewBox:"0 0 768 1024",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{d:"M320 256h-64v64h64v-64z m0-128h-64v64h64v-64z m384-128c-32 0-608 0-640 0s-64 32-64 64 0 736 0 768 32 64 64 64 128 0 128 0v128l96-96 96 96v-128s288 0 320 0 64-32 64-64 0-736 0-768-32-64-64-64z m0 800c0 16-15 32-32 32s-288 0-288 0v-64h-192v64s-79 0-96 0-32-17-32-32 0-96 0-96h640s0 80 0 96z m0-160h-512v-576h513l-1 576z m-384-128h-64v64h64v-64z m0-128h-64v64h64v-64z"})}),K8=({className:t})=>p.jsx("svg",{className:t,viewBox:"0 0 768 1024",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{d:"M704 722s0-306 0-402-96-192-192-192c-64 0-64 0-64 0v-128l-192 192 192 192v-128s32 0 64 0 64 32 64 64 0 402 0 402c-38 22-64 63-64 110 0 71 57 128 128 128s128-57 128-128c0-47-26-88-64-110z m-64 174c-35 0-64-29-64-64s29-64 64-64 64 29 64 64-29 64-64 64z m-512-832c-71 0-128 57-128 128 0 47 26 88 64 110v419c-38 22-64 63-64 110 0 71 57 128 128 128s128-57 128-128c0-47-26-88-64-110v-419c38-22 64-63 64-110 0-71-57-128-128-128z m0 832c-35 0-64-29-64-64s29-64 64-64 64 29 64 64-29 64-64 64z m0-640c-35 0-64-29-64-64s29-64 64-64 64 29 64 64-29 64-64 64z"})});function W8(t){return t.platform==="github"?"GitHub":"GitLab"}function mR(t){return t.platform==="github"?"PR":"MR"}function gR(t){return t.platform==="github"?`#${t.number}`:`!${t.iid}`}function bR(t){return t.platform==="github"?`${t.owner}/${t.repo}`:t.projectPath}const fR="plannotator-ai-setup-done";function Z8(){return xe.getItem(fR)!=="true"}function V8(){xe.setItem(fR,"true")}const J8=({isOpen:t,providers:e,onComplete:n})=>{const[a,r]=E.useState(null),[s,c]=E.useState(()=>Jr().preferredModels);if(!t||e.length===0)return null;const u=a??e[0]?.id??null,d=b=>{r(b)},A=(b,h)=>{kN(b,h),c(y=>({...y,[b]:h}))},g=()=>{if(!u)return;const b=Jr();IA({...b,providerId:u}),V8(),n(u)};return Go.createPortal(p.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-background/90 backdrop-blur-sm p-4",children:p.jsxs("div",{className:"bg-card border border-border rounded-xl w-full max-w-lg shadow-2xl",children:[p.jsxs("div",{className:"p-5 border-b border-border",children:[p.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[p.jsx("div",{className:"p-1.5 rounded-lg bg-primary/15",children:p.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.455 2.456L21.75 6l-1.036.259a3.375 3.375 0 00-2.455 2.456z"})})}),p.jsx("h3",{className:"font-semibold text-base",children:"AI-Assisted Code Review"})]}),p.jsx("p",{className:"text-sm text-muted-foreground",children:"Ask questions about code changes inline or in a side chat. Select lines in a diff, click the sparkle, and get streaming answers with full diff context."})]}),p.jsxs("div",{className:"p-4",children:[p.jsx("div",{className:"text-xs text-muted-foreground mb-2",children:"Choose your default provider"}),p.jsx("div",{className:"grid grid-cols-2 gap-2",children:e.map(b=>{const h=Zp(b.name),y=h.icon,_=u===b.id;return p.jsxs("button",{type:"button",onClick:()=>d(b.id),className:`flex items-center gap-2.5 p-3 rounded-lg border transition-colors text-left ${_?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/30 hover:bg-muted/50"}`,children:[p.jsx("div",{className:"w-7 h-7 rounded-md bg-muted flex items-center justify-center text-muted-foreground flex-shrink-0",children:p.jsx(y,{className:"w-4.5 h-4.5"})}),p.jsx("span",{className:"text-sm font-medium",children:h.label}),_&&p.jsx("svg",{className:"w-3.5 h-3.5 text-primary ml-auto flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})]},b.id)})}),u&&(()=>{const h=e.find(k=>k.id===u)?.models??[];if(h.length<=1)return null;const y=h.find(k=>k.default)??h[0],_=s[u]??y?.id??"";return p.jsx("div",{className:"mt-3",children:p.jsxs("label",{className:"flex items-center gap-2",children:[p.jsx("span",{className:"text-xs text-muted-foreground",children:"Model"}),p.jsx("select",{value:_,onChange:k=>A(u,k.target.value),className:"flex-1 text-xs bg-muted rounded px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary/50 cursor-pointer",children:h.map(k=>p.jsx("option",{value:k.id,children:k.label},k.id))})]})})})()]}),p.jsxs("div",{className:"p-4 border-t border-border flex justify-between items-center gap-3",children:[p.jsxs("p",{className:"text-[10px] text-muted-foreground/70 flex-1",children:["Providers are detected from installed CLI tools. You must be authenticated with each CLI independently."," ",p.jsx("a",{href:"https://plannotator.ai/docs/guides/ai-features/",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Learn more"})]}),p.jsx("button",{onClick:g,className:"px-4 py-2 bg-primary text-primary-foreground rounded-lg text-sm font-medium hover:opacity-90 transition-opacity flex-shrink-0",children:"Done"})]})]})}),document.body)};function DB({storageKey:t,defaultWidth:e=288,minWidth:n=200,maxWidth:a=600,side:r="right"}){const[s,c]=E.useState(()=>{const v=xe.getItem(t);if(v){const C=Number(v);if(!Number.isNaN(C)&&C>=n&&C<=a)return C}return e}),[u,d]=E.useState(!1),A=E.useRef(0),g=E.useRef(0),b=E.useRef(s),h=E.useCallback(v=>{b.current=v,c(v)},[]),y=E.useCallback(v=>{v.preventDefault(),A.current=v.clientX,g.current=b.current,d(!0)},[]),_=E.useCallback(v=>{v.preventDefault(),A.current=v.touches[0].clientX,g.current=b.current,d(!0)},[]);E.useEffect(()=>{if(!u)return;const v=S=>"touches"in S?S.touches[0]?.clientX??S.changedTouches[0]?.clientX??0:S.clientX,C=S=>{const I=v(S),Q=r==="right"?A.current-I:I-A.current;h(Math.min(a,Math.max(n,g.current+Q)))},x=()=>{d(!1),xe.setItem(t,String(b.current))};return document.addEventListener("mousemove",C),document.addEventListener("mouseup",x),document.addEventListener("touchmove",C,{passive:!1}),document.addEventListener("touchend",x),document.addEventListener("touchcancel",x),()=>{document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",x),document.removeEventListener("touchmove",C),document.removeEventListener("touchend",x),document.removeEventListener("touchcancel",x)}},[u,n,a,t,r,h]);const k=E.useCallback(()=>{h(e),xe.setItem(t,String(e))},[e,t,h]);return{width:s,isDragging:u,handleProps:{isDragging:u,onMouseDown:y,onTouchStart:_,onDoubleClick:k}}}const X8=500;function eP(t){const e=Math.floor((Date.now()-t)/1e3);if(e<60)return"just now";const n=Math.floor(e/60);if(n<60)return`${n} minute${n!==1?"s":""} ago`;const a=Math.floor(n/60);if(a<24)return`${a} hour${a!==1?"s":""} ago`;const r=Math.floor(a/24);return`${r} day${r!==1?"s":""} ago`}function tP({annotations:t,viewedFiles:e,isApiMode:n,submitted:a}){const[r,s]=E.useState(null),c=E.useRef(null),u=E.useRef(null),d=E.useRef(!1);E.useEffect(()=>{n&&fetch("/api/draft").then(b=>b.ok?b.json():null).then(b=>{const h=Array.isArray(b?.codeAnnotations)?b.codeAnnotations.length:0,y=Array.isArray(b?.viewedFiles)?b.viewedFiles.length:0;(h>0||y>0)&&(c.current=b,s({count:h,viewedCount:y,timeAgo:eP(b?.ts||0)})),d.current=!0}).catch(()=>{d.current=!0})},[n]),E.useEffect(()=>{if(!(!n||a)&&d.current&&!(t.length===0&&e.size===0))return u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{const b={codeAnnotations:t,viewedFiles:[...e],ts:Date.now()};fetch("/api/draft",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)}).catch(()=>{})},X8),()=>{u.current&&clearTimeout(u.current)}},[t,e,n,a]);const A=E.useCallback(()=>{const b=c.current;return s(null),c.current=null,{annotations:b?.codeAnnotations??[],viewedFiles:b?.viewedFiles??[]}},[]),g=E.useCallback(()=>{s(null),c.current=null,fetch("/api/draft",{method:"DELETE"}).catch(()=>{})},[]);return{draftBanner:r,restoreDraft:A,dismissDraft:g}}const nP=new Set(["uncommitted","unstaged"]);function aP({activeDiffBase:t,onFileViewed:e}){const[n,a]=E.useState(new Set),[r,s]=E.useState(null),[c,u]=E.useState(null),d=E.useRef(),A=nP.has(t),g=E.useRef(n);g.current=n;const b=E.useCallback(async y=>{const _=g.current.has(y);s(y),u(null),clearTimeout(d.current);try{const k=await fetch("/api/git-add",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:y,undo:_})});if(!k.ok){const v=await k.json().catch(()=>({error:"Failed"}));throw new Error(v.error||"Failed")}a(v=>{const C=new Set(v);return _?C.delete(y):C.add(y),C}),_||e(y)}catch(k){const v=k instanceof Error?k.message:"Git add failed";u(v),d.current=setTimeout(()=>u(null),3e3)}finally{s(null)}},[e]),h=E.useCallback(()=>{a(new Set),u(null),clearTimeout(d.current)},[]);return{stagedFiles:n,stagingFile:r,canStageFiles:A,stageFile:b,resetStagedFiles:h,stageError:c}}const n_=()=>Math.random().toString(36).substring(2,9);function iP({patch:t,providerId:e,model:n,reasoningEffort:a}){const[r,s]=E.useState(null),[c,u]=E.useState([]),[d,A]=E.useState(!1),[g,b]=E.useState(!1),[h,y]=E.useState(null),[_,k]=E.useState([]),v=E.useRef(null),C=E.useRef(null);C.current=r;const x=E.useCallback(async R=>{A(!0);try{const N=await fetch("/api/ai/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({context:{mode:"code-review",review:{patch:t}},...e&&{providerId:e},...n&&{model:n},...a&&{reasoningEffort:a}}),signal:R});if(!N.ok){const P=await N.json().catch(()=>({error:"Failed to create AI session"}));throw new Error(P.error||`HTTP ${N.status}`)}const F=await N.json();return s(F.sessionId),F.sessionId}finally{A(!1)}},[t,e,n,a]),S=E.useCallback(async R=>{v.current&&v.current.abort();const N=new AbortController;v.current=N,y(null);const F=n_(),P={id:F,prompt:R.prompt,filePath:R.filePath,lineStart:R.lineStart,lineEnd:R.lineEnd,side:R.side,selectedCode:R.selectedCode,createdAt:Date.now()},T={questionId:F,text:"",isStreaming:!0,createdAt:Date.now()};u(L=>[...L,{question:P,response:T}]),b(!0);try{let L=C.current;L||(L=await x(N.signal));let Y=R.prompt;if(R.filePath&&R.lineStart!=null&&R.lineEnd!=null){const te=R.lineStart===R.lineEnd?`line ${R.lineStart}`:`lines ${R.lineStart}-${R.lineEnd}`,oe=R.side==="new"?"new (added)":"old (removed)",de=R.selectedCode?`
83
+ ---`})]}),p.jsx("div",{className:"border-t border-border/30"}),p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium",children:"Auto-save on Plan Arrival"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Automatically save to Obsidian when a plan loads, before you approve or deny"})]}),p.jsx("button",{role:"switch","aria-checked":v.autoSave,onClick:()=>ft({autoSave:!v.autoSave}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${v.autoSave?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${v.autoSave?"translate-x-6":"translate-x-1"}`})})]}),p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium",children:"Vault Browser"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Browse and annotate vault files from the sidebar"})]}),p.jsx("button",{role:"switch","aria-checked":v.vaultBrowserEnabled,onClick:()=>ft({vaultBrowserEnabled:!v.vaultBrowserEnabled}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${v.vaultBrowserEnabled?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${v.vaultBrowserEnabled?"translate-x-6":"translate-x-1"}`})})]})]})]})]}),h==="bear"&&p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-sm font-medium",children:"Bear Notes"}),p.jsx("div",{className:"text-xs text-muted-foreground",children:"Auto-save approved plans to Bear"})]}),p.jsx("button",{role:"switch","aria-checked":D.enabled,onClick:()=>Kt({enabled:!D.enabled}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${D.enabled?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${D.enabled?"translate-x-6":"translate-x-1"}`})})]}),D.enabled&&p.jsxs("div",{className:"mt-3 space-y-3",children:[p.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[p.jsx("label",{className:"text-xs text-muted-foreground",children:"Custom Tags"}),p.jsx("input",{type:"text",value:D.customTags,onChange:ae=>Kt({customTags:ae.target.value}),onBlur:ae=>Kt({customTags:BM(ae.target.value)}),placeholder:"plan, work",className:"w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Comma-separated, kebab-case. Leave empty for auto-generated tags."})]}),p.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[p.jsx("label",{className:"text-xs text-muted-foreground",children:"Tag Position"}),p.jsxs("select",{value:D.tagPosition,onChange:ae=>Kt({tagPosition:ae.target.value}),className:"w-full px-3 py-2 bg-muted rounded-lg text-xs focus:outline-none focus:ring-1 focus:ring-primary/50",children:[p.jsx("option",{value:"append",children:"Append (end of note)"}),p.jsx("option",{value:"prepend",children:"Prepend (after title)"})]})]}),p.jsx("div",{className:"border-t border-border/30"}),p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium",children:"Auto-save on Plan Arrival"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Automatically save to Bear when a plan loads, before you approve or deny"})]}),p.jsx("button",{role:"switch","aria-checked":D.autoSave,onClick:()=>Kt({autoSave:!D.autoSave}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${D.autoSave?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${D.autoSave?"translate-x-6":"translate-x-1"}`})})]})]})]}),h==="octarine"&&p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-sm font-medium",children:"Octarine"}),p.jsx("div",{className:"text-xs text-muted-foreground",children:"Auto-save approved plans to Octarine"})]}),p.jsx("button",{role:"switch","aria-checked":N.enabled,onClick:()=>xn({enabled:!N.enabled}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${N.enabled?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${N.enabled?"translate-x-6":"translate-x-1"}`})})]}),N.enabled&&p.jsxs("div",{className:"mt-3 space-y-3",children:[p.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[p.jsx("label",{className:"text-xs text-muted-foreground",children:"Workspace Name"}),p.jsx("input",{type:"text",value:N.workspace,onChange:ae=>xn({workspace:ae.target.value}),placeholder:"My Workspace",className:"w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"The Octarine workspace name to save plans into."})]}),p.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[p.jsx("label",{className:"text-xs text-muted-foreground",children:"Folder"}),p.jsx("input",{type:"text",value:N.folder,onChange:ae=>xn({folder:ae.target.value}),placeholder:"plannotator",className:"w-full px-3 py-2 bg-muted rounded-lg text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Subfolder within the workspace for saved plans."})]}),p.jsxs("div",{className:"text-[10px] text-muted-foreground/70",children:["Plans saved to: ",N.workspace||"..."," / ",N.folder||"plannotator","/"]}),p.jsx("div",{className:"border-t border-border/30"}),p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsxs("div",{children:[p.jsx("div",{className:"text-xs font-medium",children:"Auto-save on Plan Arrival"}),p.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Automatically save to Octarine when a plan loads, before you approve or deny"})]}),p.jsx("button",{role:"switch","aria-checked":N.autoSave,onClick:()=>xn({autoSave:!N.autoSave}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${N.autoSave?"bg-primary":"bg-muted"}`,children:p.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${N.autoSave?"translate-x-6":"translate-x-1"}`})})]})]})]})]})})]})]})}),document.body)]})},T8=({onClick:t,disabled:e=!1,isLoading:n=!1,label:a="Send Feedback",shortLabel:r,loadingLabel:s="Sending...",shortLoadingLabel:c,title:u="Send Feedback",muted:d=!1})=>p.jsxs("button",{onClick:t,disabled:e,className:`p-1.5 md:px-2.5 md:py-1 rounded-md text-xs font-medium transition-all ${d?"opacity-50 cursor-not-allowed bg-accent/10 text-accent/50":e?"opacity-50 cursor-not-allowed bg-muted text-muted-foreground":"bg-accent/15 text-accent hover:bg-accent/25 border border-accent/30"}`,title:u,children:[p.jsx("svg",{className:"w-4 h-4 md:hidden",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),r?p.jsxs(p.Fragment,{children:[p.jsx("span",{className:"hidden md:inline lg:hidden",children:n?c??s:r}),p.jsx("span",{className:"hidden lg:inline",children:n?s:a})]}):p.jsx("span",{className:"hidden md:inline",children:n?s:a})]}),F8=({onClick:t,disabled:e=!1,isLoading:n=!1,label:a="Approve",loadingLabel:r="Approving...",mobileLabel:s="OK",mobileLoadingLabel:c="...",title:u,dimmed:d=!1,muted:A=!1})=>p.jsxs("button",{onClick:t,disabled:e,className:`px-2 py-1 md:px-2.5 rounded-md text-xs font-medium transition-all ${A?"opacity-40 cursor-not-allowed bg-muted text-muted-foreground":e?"opacity-50 cursor-not-allowed bg-muted text-muted-foreground":d?"bg-success/50 text-success-foreground/70 hover:bg-success hover:text-success-foreground":"bg-success text-success-foreground hover:opacity-90"}`,title:u,children:[p.jsx("span",{className:"md:hidden",children:n?c:s}),p.jsx("span",{className:"hidden md:inline",children:n?r:a})]}),L8="https://api.github.com/repos/backnotprop/plannotator/releases/latest",BB={"0.5.0":{title:"Code Review is here!",description:"Review git diffs with inline annotations. Run /plannotator-review to try it."}};function M8(t,e){const n=s=>s.replace(/^v/,""),a=n(t).split(".").map(Number),r=n(e).split(".").map(Number);for(let s=0;s<Math.max(a.length,r.length);s++){const c=a[s]||0,u=r[s]||0;if(u>c)return!0;if(u<c)return!1}return!1}function O8(){const[t,e]=E.useState(null);return E.useEffect(()=>{(async()=>{try{const a="0.17.3",s=new URLSearchParams(window.location.search).get("preview-update");if(s){const h=s.replace(/^v/,"");e({currentVersion:a,latestVersion:s,updateAvailable:!0,releaseUrl:`https://github.com/backnotprop/plannotator/releases/tag/v${h}`,featureHighlight:BB[h]});return}const c=await fetch(L8);if(!c.ok)return;const u=await c.json(),d=u.tag_name,A=M8(a,d),g=d.replace(/^v/,""),b=BB[g];e({currentVersion:a,latestVersion:d,updateAvailable:A,releaseUrl:u.html_url,featureHighlight:b})}catch(a){console.debug("Update check failed:",a)}})()},[]),t}const P8="pi install npm:@plannotator/pi-extension";function j8(t){return zM&&!t?'powershell -c "irm https://plannotator.ai/install.ps1 | iex"':"curl -fsSL https://plannotator.ai/install.sh | bash"}const G8=({origin:t,isWSL:e=!1})=>{const n=O8(),[a,r]=E.useState(!1),[s,c]=E.useState(!1),A=new URLSearchParams(window.location.search).get("preview-origin")||t,g=A==="pi",b=A==="opencode",h=g?P8:j8(e);if(!n?.updateAvailable||s)return null;const y=async()=>{try{await navigator.clipboard.writeText(h),r(!0),setTimeout(()=>r(!1),2e3)}catch(k){console.error("Failed to copy:",k)}};return n.featureHighlight?p.jsx("div",{className:"fixed bottom-4 right-4 z-50 max-w-md animate-in slide-in-from-bottom-2 fade-in duration-300",children:p.jsxs("div",{className:"bg-card border border-primary/30 rounded-xl shadow-2xl overflow-hidden",children:[p.jsx("div",{className:"bg-gradient-to-r from-primary/20 to-primary/5 px-5 py-4 border-b border-border/50",children:p.jsxs("div",{className:"flex items-start justify-between gap-3",children:[p.jsxs("div",{className:"flex items-center gap-3",children:[p.jsx("div",{className:"flex-shrink-0 w-10 h-10 rounded-lg bg-primary/20 flex items-center justify-center",children:p.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})})}),p.jsxs("div",{children:[p.jsx("h4",{className:"text-base font-semibold text-foreground",children:n.featureHighlight.title}),p.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["New in ",n.latestVersion]})]})]}),p.jsx("button",{onClick:()=>c(!0),className:"text-muted-foreground hover:text-foreground transition-colors p-1",children:p.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})}),p.jsxs("div",{className:"px-5 py-4",children:[p.jsx("p",{className:"text-sm text-foreground/80 leading-relaxed",children:n.featureHighlight.description}),p.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:["You have ",n.currentVersion]}),b&&p.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Run the install script, then restart OpenCode."}),g&&p.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Run the install command, then restart Pi."}),p.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[p.jsx("button",{onClick:y,className:"flex-1 px-4 py-2 text-sm font-medium bg-primary text-primary-foreground rounded-lg hover:opacity-90 transition-opacity",children:a?"Copied!":"Copy install command"}),p.jsx("a",{href:n.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:"px-4 py-2 text-sm font-medium text-muted-foreground hover:text-foreground border border-border rounded-lg hover:bg-muted transition-colors",children:"Release notes"})]})]})]})}):p.jsx("div",{className:"fixed bottom-4 right-4 z-50 max-w-sm animate-in slide-in-from-bottom-2 fade-in duration-300",children:p.jsx("div",{className:"bg-card border border-border rounded-lg shadow-xl p-4",children:p.jsxs("div",{className:"flex items-start gap-3",children:[p.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-primary/20 flex items-center justify-center",children:p.jsx("svg",{className:"w-4 h-4 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"})})}),p.jsxs("div",{className:"flex-1 min-w-0",children:[p.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Update available"}),p.jsx("button",{onClick:()=>c(!0),className:"text-muted-foreground hover:text-foreground transition-colors",children:p.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),p.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[n.latestVersion," is available (you have ",n.currentVersion,")"]}),p.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[p.jsx("button",{onClick:y,className:"flex-1 px-3 py-1.5 text-xs font-medium bg-primary text-primary-foreground rounded-md hover:opacity-90 transition-opacity",children:a?"Copied!":"Copy install command"}),p.jsx("a",{href:n.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:"px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground border border-border rounded-md hover:bg-muted transition-colors",children:"Notes"})]})]})]})})})};function IB(t){window.close(),setTimeout(()=>{window.closed||t()},300)}function z8(t){const[e,n]=E.useState({phase:"idle"});E.useEffect(()=>{if(!t)return;const r=P1();r==="0"?(IB(()=>n({phase:"closeFailed"})),n({phase:"closed"})):n(r!=="off"?{phase:"counting",remaining:Number(r)}:{phase:"prompt"})},[t]),E.useEffect(()=>{if(e.phase!=="counting")return;if(e.remaining<=0){IB(()=>n({phase:"closeFailed"}));return}const r=setTimeout(()=>n(s=>s.phase==="counting"?{phase:"counting",remaining:s.remaining-1}:s),1e3);return()=>clearTimeout(r)},[e]);const a=E.useCallback(()=>{j1("3"),n({phase:"counting",remaining:3})},[]);return{state:e,enableAndStart:a}}const q8=()=>p.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),U8=()=>p.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})});function H8({submitted:t,title:e,subtitle:n,agentLabel:a}){const{state:r,enableAndStart:s}=z8(!!t);if(!t)return null;const c=t==="approved";return p.jsx("div",{className:"fixed inset-0 z-[100] bg-background flex items-center justify-center",children:p.jsxs("div",{className:"text-center space-y-6 max-w-md px-8",children:[p.jsx("div",{className:`mx-auto w-16 h-16 rounded-full flex items-center justify-center ${c?"bg-success/20 text-success":"bg-accent/20 text-accent"}`,children:c?p.jsx(q8,{}):p.jsx(U8,{})}),p.jsxs("div",{className:"space-y-2",children:[p.jsx("h2",{className:"text-xl font-semibold text-foreground",children:e}),p.jsx("p",{className:"text-muted-foreground",children:n})]}),p.jsx("div",{className:"pt-4 border-t border-border space-y-2",children:r.phase==="counting"?p.jsxs(p.Fragment,{children:[p.jsxs("p",{className:"text-sm text-muted-foreground",children:["This tab will close in ",p.jsx("span",{className:"text-foreground font-medium",children:r.remaining})," second",r.remaining!==1?"s":"","..."]}),p.jsx("p",{className:"text-xs text-muted-foreground/60",children:"You can change this in Settings."})]}):r.phase==="closeFailed"?p.jsxs(p.Fragment,{children:[p.jsx("p",{className:"text-sm text-muted-foreground",children:"Could not close this tab automatically. Please close it manually."}),p.jsxs("p",{className:"text-xs text-muted-foreground/60",children:["Auto-close works when the tab is opened by ",a,"."]})]}):p.jsxs(p.Fragment,{children:[p.jsxs("p",{className:"text-sm text-muted-foreground",children:["You can close this tab and return to ",p.jsx("span",{className:"text-foreground font-medium",children:a}),"."]}),r.phase==="prompt"?p.jsxs(p.Fragment,{children:[p.jsxs("label",{className:"flex items-center justify-center gap-2 cursor-pointer group",children:[p.jsx("input",{type:"checkbox",checked:!1,onChange:s,className:"accent-primary"}),p.jsx("span",{className:"text-xs text-muted-foreground group-hover:text-foreground transition-colors",children:"Auto-close this tab after 3 seconds"})]}),p.jsx("p",{className:"text-xs text-muted-foreground/60",children:"You can change the delay in Settings."})]}):p.jsx("p",{className:"text-xs text-muted-foreground/60",children:"Your response has been sent."})]})})]})})}const Y8=({className:t})=>p.jsx("svg",{className:t,viewBox:"0 0 16 16",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z"})}),$8=({className:t})=>p.jsxs("svg",{className:t,viewBox:"90 90 200 195",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:[p.jsx("path",{d:"M282.83 170.73l-.27-.69-26.14-68.22a6.81 6.81 0 00-2.69-3.24 7 7 0 00-8 .43 7 7 0 00-2.32 3.52l-17.65 54h-71.47l-17.65-54a6.86 6.86 0 00-2.32-3.53 7 7 0 00-8-.43 6.87 6.87 0 00-2.69 3.24L97.44 170l-.26.69a48.54 48.54 0 0016.1 56.1l.09.07.24.17 39.82 29.82 19.7 14.91 12 9.06a8.07 8.07 0 009.76 0l12-9.06 19.7-14.91 40.06-30 .1-.08a48.56 48.56 0 0016.08-56.04z"}),p.jsx("path",{d:"M282.83 170.73l-.27-.69a88.3 88.3 0 00-35.15 15.8L190 229.25c19.55 14.79 36.57 27.64 36.57 27.64l40.06-30 .1-.08a48.56 48.56 0 0016.1-56.08z",opacity:"0.7"}),p.jsx("path",{d:"M153.43 256.89l19.7 14.91 12 9.06a8.07 8.07 0 009.76 0l12-9.06 19.7-14.91s-17.04-12.89-36.59-27.64c-19.55 14.75-36.57 27.64-36.57 27.64z",opacity:"0.85"}),p.jsx("path",{d:"M132.58 185.84A88.19 88.19 0 0097.44 170l-.26.69a48.54 48.54 0 0016.1 56.1l.09.07.24.17 39.82 29.82s17-12.85 36.57-27.64z",opacity:"0.7"})]}),SB=({className:t})=>p.jsx("svg",{className:t,viewBox:"0 0 768 1024",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{d:"M320 256h-64v64h64v-64z m0-128h-64v64h64v-64z m384-128c-32 0-608 0-640 0s-64 32-64 64 0 736 0 768 32 64 64 64 128 0 128 0v128l96-96 96 96v-128s288 0 320 0 64-32 64-64 0-736 0-768-32-64-64-64z m0 800c0 16-15 32-32 32s-288 0-288 0v-64h-192v64s-79 0-96 0-32-17-32-32 0-96 0-96h640s0 80 0 96z m0-160h-512v-576h513l-1 576z m-384-128h-64v64h64v-64z m0-128h-64v64h64v-64z"})}),K8=({className:t})=>p.jsx("svg",{className:t,viewBox:"0 0 768 1024",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",children:p.jsx("path",{d:"M704 722s0-306 0-402-96-192-192-192c-64 0-64 0-64 0v-128l-192 192 192 192v-128s32 0 64 0 64 32 64 64 0 402 0 402c-38 22-64 63-64 110 0 71 57 128 128 128s128-57 128-128c0-47-26-88-64-110z m-64 174c-35 0-64-29-64-64s29-64 64-64 64 29 64 64-29 64-64 64z m-512-832c-71 0-128 57-128 128 0 47 26 88 64 110v419c-38 22-64 63-64 110 0 71 57 128 128 128s128-57 128-128c0-47-26-88-64-110v-419c38-22 64-63 64-110 0-71-57-128-128-128z m0 832c-35 0-64-29-64-64s29-64 64-64 64 29 64 64-29 64-64 64z m0-640c-35 0-64-29-64-64s29-64 64-64 64 29 64 64-29 64-64 64z"})});function W8(t){return t.platform==="github"?"GitHub":"GitLab"}function mR(t){return t.platform==="github"?"PR":"MR"}function gR(t){return t.platform==="github"?`#${t.number}`:`!${t.iid}`}function bR(t){return t.platform==="github"?`${t.owner}/${t.repo}`:t.projectPath}const fR="plannotator-ai-setup-done";function Z8(){return xe.getItem(fR)!=="true"}function V8(){xe.setItem(fR,"true")}const J8=({isOpen:t,providers:e,onComplete:n})=>{const[a,r]=E.useState(null),[s,c]=E.useState(()=>Jr().preferredModels);if(!t||e.length===0)return null;const u=a??e[0]?.id??null,d=b=>{r(b)},A=(b,h)=>{kN(b,h),c(y=>({...y,[b]:h}))},g=()=>{if(!u)return;const b=Jr();IA({...b,providerId:u}),V8(),n(u)};return Go.createPortal(p.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-background/90 backdrop-blur-sm p-4",children:p.jsxs("div",{className:"bg-card border border-border rounded-xl w-full max-w-lg shadow-2xl",children:[p.jsxs("div",{className:"p-5 border-b border-border",children:[p.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[p.jsx("div",{className:"p-1.5 rounded-lg bg-primary/15",children:p.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.455 2.456L21.75 6l-1.036.259a3.375 3.375 0 00-2.455 2.456z"})})}),p.jsx("h3",{className:"font-semibold text-base",children:"AI-Assisted Code Review"})]}),p.jsx("p",{className:"text-sm text-muted-foreground",children:"Ask questions about code changes inline or in a side chat. Select lines in a diff, click the sparkle, and get streaming answers with full diff context."})]}),p.jsxs("div",{className:"p-4",children:[p.jsx("div",{className:"text-xs text-muted-foreground mb-2",children:"Choose your default provider"}),p.jsx("div",{className:"grid grid-cols-2 gap-2",children:e.map(b=>{const h=Zp(b.name),y=h.icon,_=u===b.id;return p.jsxs("button",{type:"button",onClick:()=>d(b.id),className:`flex items-center gap-2.5 p-3 rounded-lg border transition-colors text-left ${_?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/30 hover:bg-muted/50"}`,children:[p.jsx("div",{className:"w-7 h-7 rounded-md bg-muted flex items-center justify-center text-muted-foreground flex-shrink-0",children:p.jsx(y,{className:"w-4.5 h-4.5"})}),p.jsx("span",{className:"text-sm font-medium",children:h.label}),_&&p.jsx("svg",{className:"w-3.5 h-3.5 text-primary ml-auto flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})]},b.id)})}),u&&(()=>{const h=e.find(k=>k.id===u)?.models??[];if(h.length<=1)return null;const y=h.find(k=>k.default)??h[0],_=s[u]??y?.id??"";return p.jsx("div",{className:"mt-3",children:p.jsxs("label",{className:"flex items-center gap-2",children:[p.jsx("span",{className:"text-xs text-muted-foreground",children:"Model"}),p.jsx("select",{value:_,onChange:k=>A(u,k.target.value),className:"flex-1 text-xs bg-muted rounded px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary/50 cursor-pointer",children:h.map(k=>p.jsx("option",{value:k.id,children:k.label},k.id))})]})})})()]}),p.jsxs("div",{className:"p-4 border-t border-border flex justify-between items-center gap-3",children:[p.jsxs("p",{className:"text-[10px] text-muted-foreground/70 flex-1",children:["Providers are detected from installed CLI tools. You must be authenticated with each CLI independently."," ",p.jsx("a",{href:"https://plannotator.ai/docs/guides/ai-features/",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Learn more"})]}),p.jsx("button",{onClick:g,className:"px-4 py-2 bg-primary text-primary-foreground rounded-lg text-sm font-medium hover:opacity-90 transition-opacity flex-shrink-0",children:"Done"})]})]})}),document.body)};function DB({storageKey:t,defaultWidth:e=288,minWidth:n=200,maxWidth:a=600,side:r="right"}){const[s,c]=E.useState(()=>{const v=xe.getItem(t);if(v){const C=Number(v);if(!Number.isNaN(C)&&C>=n&&C<=a)return C}return e}),[u,d]=E.useState(!1),A=E.useRef(0),g=E.useRef(0),b=E.useRef(s),h=E.useCallback(v=>{b.current=v,c(v)},[]),y=E.useCallback(v=>{v.preventDefault(),A.current=v.clientX,g.current=b.current,d(!0)},[]),_=E.useCallback(v=>{v.preventDefault(),A.current=v.touches[0].clientX,g.current=b.current,d(!0)},[]);E.useEffect(()=>{if(!u)return;const v=S=>"touches"in S?S.touches[0]?.clientX??S.changedTouches[0]?.clientX??0:S.clientX,C=S=>{const I=v(S),Q=r==="right"?A.current-I:I-A.current;h(Math.min(a,Math.max(n,g.current+Q)))},x=()=>{d(!1),xe.setItem(t,String(b.current))};return document.addEventListener("mousemove",C),document.addEventListener("mouseup",x),document.addEventListener("touchmove",C,{passive:!1}),document.addEventListener("touchend",x),document.addEventListener("touchcancel",x),()=>{document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",x),document.removeEventListener("touchmove",C),document.removeEventListener("touchend",x),document.removeEventListener("touchcancel",x)}},[u,n,a,t,r,h]);const k=E.useCallback(()=>{h(e),xe.setItem(t,String(e))},[e,t,h]);return{width:s,isDragging:u,handleProps:{isDragging:u,onMouseDown:y,onTouchStart:_,onDoubleClick:k}}}const X8=500;function eP(t){const e=Math.floor((Date.now()-t)/1e3);if(e<60)return"just now";const n=Math.floor(e/60);if(n<60)return`${n} minute${n!==1?"s":""} ago`;const a=Math.floor(n/60);if(a<24)return`${a} hour${a!==1?"s":""} ago`;const r=Math.floor(a/24);return`${r} day${r!==1?"s":""} ago`}function tP({annotations:t,viewedFiles:e,isApiMode:n,submitted:a}){const[r,s]=E.useState(null),c=E.useRef(null),u=E.useRef(null),d=E.useRef(!1);E.useEffect(()=>{n&&fetch("/api/draft").then(b=>b.ok?b.json():null).then(b=>{const h=Array.isArray(b?.codeAnnotations)?b.codeAnnotations.length:0,y=Array.isArray(b?.viewedFiles)?b.viewedFiles.length:0;(h>0||y>0)&&(c.current=b,s({count:h,viewedCount:y,timeAgo:eP(b?.ts||0)})),d.current=!0}).catch(()=>{d.current=!0})},[n]),E.useEffect(()=>{if(!(!n||a)&&d.current&&!(t.length===0&&e.size===0))return u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{const b={codeAnnotations:t,viewedFiles:[...e],ts:Date.now()};fetch("/api/draft",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)}).catch(()=>{})},X8),()=>{u.current&&clearTimeout(u.current)}},[t,e,n,a]);const A=E.useCallback(()=>{const b=c.current;return s(null),c.current=null,{annotations:b?.codeAnnotations??[],viewedFiles:b?.viewedFiles??[]}},[]),g=E.useCallback(()=>{s(null),c.current=null,fetch("/api/draft",{method:"DELETE"}).catch(()=>{})},[]);return{draftBanner:r,restoreDraft:A,dismissDraft:g}}const nP=new Set(["uncommitted","unstaged"]);function aP({activeDiffBase:t,onFileViewed:e}){const[n,a]=E.useState(new Set),[r,s]=E.useState(null),[c,u]=E.useState(null),d=E.useRef(),A=nP.has(t),g=E.useRef(n);g.current=n;const b=E.useCallback(async y=>{const _=g.current.has(y);s(y),u(null),clearTimeout(d.current);try{const k=await fetch("/api/git-add",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:y,undo:_})});if(!k.ok){const v=await k.json().catch(()=>({error:"Failed"}));throw new Error(v.error||"Failed")}a(v=>{const C=new Set(v);return _?C.delete(y):C.add(y),C}),_||e(y)}catch(k){const v=k instanceof Error?k.message:"Git add failed";u(v),d.current=setTimeout(()=>u(null),3e3)}finally{s(null)}},[e]),h=E.useCallback(()=>{a(new Set),u(null),clearTimeout(d.current)},[]);return{stagedFiles:n,stagingFile:r,canStageFiles:A,stageFile:b,resetStagedFiles:h,stageError:c}}const n_=()=>Math.random().toString(36).substring(2,9);function iP({patch:t,providerId:e,model:n,reasoningEffort:a}){const[r,s]=E.useState(null),[c,u]=E.useState([]),[d,A]=E.useState(!1),[g,b]=E.useState(!1),[h,y]=E.useState(null),[_,k]=E.useState([]),v=E.useRef(null),C=E.useRef(null);C.current=r;const x=E.useCallback(async R=>{A(!0);try{const N=await fetch("/api/ai/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({context:{mode:"code-review",review:{patch:t}},...e&&{providerId:e},...n&&{model:n},...a&&{reasoningEffort:a}}),signal:R});if(!N.ok){const P=await N.json().catch(()=>({error:"Failed to create AI session"}));throw new Error(P.error||`HTTP ${N.status}`)}const F=await N.json();return s(F.sessionId),F.sessionId}finally{A(!1)}},[t,e,n,a]),S=E.useCallback(async R=>{v.current&&v.current.abort();const N=new AbortController;v.current=N,y(null);const F=n_(),P={id:F,prompt:R.prompt,filePath:R.filePath,lineStart:R.lineStart,lineEnd:R.lineEnd,side:R.side,selectedCode:R.selectedCode,createdAt:Date.now()},T={questionId:F,text:"",isStreaming:!0,createdAt:Date.now()};u(L=>[...L,{question:P,response:T}]),b(!0);try{let L=C.current;L||(L=await x(N.signal));let Y=R.prompt;if(R.filePath&&R.lineStart!=null&&R.lineEnd!=null){const te=R.lineStart===R.lineEnd?`line ${R.lineStart}`:`lines ${R.lineStart}-${R.lineEnd}`,oe=R.side==="new"?"new (added)":"old (removed)",de=R.selectedCode?`
84
84
  \`\`\`
85
85
  ${R.selectedCode}
86
86
  \`\`\`
@@ -6363,7 +6363,7 @@ ${t}`:t;return F2(b)}catch{return}},[t]),[d,A]=E.useState({type:a,css:""});retur
6363
6363
  [data-diffs-header] { display: none !important; }
6364
6364
  ${v}
6365
6365
  `})});return()=>cancelAnimationFrame(g)},[a,r.fontFamily,r.fontSize]),u?p.jsxs("div",{className:`rounded overflow-hidden border border-border/20 ${n??""}`,children:[p.jsx("div",{className:"overflow-hidden",style:s?void 0:{maxHeight:e},children:p.jsx(T2,{fileDiff:u,options:{themeType:d.type,unsafeCSS:d.css,diffStyle:"unified",disableLineNumbers:!0,disableFileHeader:!0,disableBackground:!0,overflow:"wrap"}})}),!s&&p.jsx("button",{onClick:g=>{g.stopPropagation(),c(!0)},className:"w-full text-[10px] text-muted-foreground hover:text-foreground py-1 bg-muted/20 border-t border-border/20 transition-colors",children:"Show full context"})]}):null},hW={APPROVED:{bg:"bg-success/15",text:"text-success",label:"Approved"},CHANGES_REQUESTED:{bg:"bg-destructive/15",text:"text-destructive",label:"Changes Requested"},COMMENTED:{bg:"bg-muted",text:"text-muted-foreground",label:"Commented"},DISMISSED:{bg:"bg-muted",text:"text-muted-foreground/60",label:"Dismissed"}};function Z_(t){if(!t)return"";const e=new Date(t).getTime();if(isNaN(e))return"";const n=Date.now()-e,a=Math.floor(n/6e4),r=Math.floor(a/60),s=Math.floor(r/24);return a<1?"just now":a<60?`${a}m ago`:r<24?`${r}h ago`:s<30?`${s}d ago`:new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Pw(t){return t.kind==="comment"?t.data.createdAt:t.kind==="review"?t.data.submittedAt:t.data.comments[0]?.createdAt??""}function V_(t){return t.kind==="thread"?t.data.comments[0]?.author??"":t.data.author}function yW(t){return t.kind==="thread"?t.data.comments.map(e=>e.body).join(" "):t.data.body}function wW(t,e){const n=e.toLowerCase(),a=V_(t).toLowerCase(),r=yW(t).toLowerCase();return t.kind==="thread"?a.includes(n)||r.includes(n)||t.data.path.toLowerCase().includes(n):a.includes(n)||r.includes(n)}const _W=Ze.memo(({context:t,platformUser:e})=>{const[n,a]=E.useState(""),[r,s]=E.useState(!1),[c,u]=E.useState(!1),[d,A]=E.useState(!1),[g,b]=E.useState(null),[h,y]=E.useState(new Set),[_,k]=E.useState(new Set),v=E.useRef(null),C=E.useRef(null),x=E.useMemo(()=>{const T=[...t.comments.map(L=>({kind:"comment",data:L})),...t.reviews.filter(L=>L.state!=="COMMENTED"||L.body).map(L=>({kind:"review",data:L})),...(t.reviewThreads??[]).filter(L=>L.comments.length>0).map(L=>({kind:"thread",data:L}))];return T.sort((L,Y)=>new Date(Pw(L)).getTime()-new Date(Pw(Y)).getTime()),T},[t.comments,t.reviews,t.reviewThreads]),S=E.useMemo(()=>[...new Set(x.map(T=>V_(T)).filter(Boolean))].sort(),[x]),I=E.useMemo(()=>{let T=x;return c&&(T=T.filter(L=>L.kind!=="thread"||!L.data.isResolved)),d&&(T=T.filter(L=>L.kind!=="thread"||!L.data.isOutdated)),_.size>0&&(T=T.filter(L=>!_.has(V_(L)))),n.trim()&&(T=T.filter(L=>wW(L,n.trim()))),T},[x,n,_,c,d]),Q=E.useMemo(()=>r?[...I].reverse():I,[I,r]);E.useEffect(()=>{if(!g||!v.current)return;const T=v.current.querySelector(`[data-comment-id="${CSS.escape(g)}"]`);T&&T.scrollIntoView({behavior:"smooth",block:"center"})},[g]),E.useEffect(()=>{const T=L=>{(L.metaKey||L.ctrlKey)&&L.shiftKey&&L.key.toLowerCase()==="f"&&(L.preventDefault(),C.current?.focus())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]);const D=E.useCallback(T=>{y(L=>{const Y=new Set(L);return Y.has(T)?Y.delete(T):Y.add(T),Y})},[]),R=E.useCallback(()=>{y(new Set(Q.map(T=>T.data.id)))},[Q]),N=E.useCallback(()=>y(new Set),[]),F=E.useCallback(T=>{T.key==="Escape"&&(n?a(""):T.target.blur(),T.stopPropagation())},[n]),P=E.useCallback(()=>{a(""),k(new Set),u(!1),A(!1)},[]);return x.length===0?p.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center px-8",children:[p.jsx("div",{className:"w-10 h-10 rounded-full bg-muted/50 flex items-center justify-center mb-3",children:p.jsx("svg",{className:"w-5 h-5 text-muted-foreground",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),p.jsx("p",{className:"text-xs text-muted-foreground",children:"No comments on this PR."})]}):(n.trim()||_.size>0,p.jsxs("div",{ref:v,className:"h-full flex flex-col",children:[p.jsxs("div",{className:"flex-shrink-0 bg-background border-b border-border/30 px-8 py-2 space-y-2",children:[p.jsxs("div",{className:"relative",children:[p.jsx("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground/40",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),p.jsx("input",{ref:C,value:n,onChange:T=>a(T.target.value),onKeyDown:F,placeholder:"Search comments...",className:"w-full pl-8 py-1.5 pr-20 bg-muted rounded text-xs text-foreground placeholder:text-muted-foreground/40 focus:outline-none focus:ring-1 focus:ring-primary/50"}),p.jsxs("div",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 flex items-center gap-1.5",children:[n.trim()&&p.jsxs("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:[I.length," of ",x.length]}),n&&p.jsx("button",{onClick:()=>a(""),className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors",children:p.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]}),p.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto min-w-0",children:[_.size>0&&p.jsx("button",{onClick:()=>k(new Set),className:"text-[10px] px-1.5 py-0.5 rounded text-primary hover:underline whitespace-nowrap",children:"Show all"}),S.map(T=>p.jsx(vW,{label:T===e?`${T} (you)`:T,excluded:_.has(T),onClick:()=>{k(L=>{const Y=new Set(L);return Y.has(T)?Y.delete(T):Y.add(T),Y})}},T))]}),p.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[p.jsx("button",{onClick:()=>u(T=>!T),className:`text-[10px] px-1.5 py-0.5 rounded transition-colors ${c?"bg-success/15 text-success":"bg-muted text-muted-foreground hover:text-foreground"}`,title:c?"Show resolved threads":"Hide resolved threads",children:"Resolved"}),p.jsx("button",{onClick:()=>A(T=>!T),className:`text-[10px] px-1.5 py-0.5 rounded transition-colors ${d?"bg-warning/15 text-warning":"bg-muted text-muted-foreground hover:text-foreground"}`,title:d?"Show outdated threads":"Hide outdated threads",children:"Outdated"}),p.jsx("div",{className:"w-px h-3 bg-border/30 mx-0.5"}),p.jsx("button",{onClick:()=>s(T=>!T),className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground hover:text-foreground transition-colors",children:r?"Newest":"Oldest"}),p.jsx("button",{onClick:R,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted/30 transition-colors",title:"Collapse all",children:p.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 14h16M4 10h16"})})}),p.jsx("button",{onClick:N,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted/30 transition-colors",title:"Expand all",children:p.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 6h16M4 12h16M4 18h16"})})})]})]})]}),p.jsx(to,{className:"flex-1 min-h-0",children:p.jsx("div",{className:"px-8 py-4",children:p.jsx("div",{className:"space-y-3 max-w-2xl",children:Q.length===0?p.jsxs("div",{className:"text-center py-8",children:[p.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"No comments match your filters."}),p.jsx("button",{onClick:P,className:"text-[10px] text-primary hover:underline",children:"Clear filters"})]}):Q.map(T=>{const L=T.data.id,Y=g===L,V=h.has(L);if(T.kind==="thread")return p.jsx(kW,{thread:T.data,isSelected:Y,isCollapsed:V,onSelect:()=>b(Y?null:L),onToggleCollapse:()=>D(L)},L);const O=T.kind==="review"?T.data:null,U=O&&O.state!=="COMMENTED"?hW[O.state]??null:null;return p.jsxs("div",{"data-comment-id":L,onClick:()=>b(Y?null:L),className:`group/card rounded bg-card border p-3 cursor-pointer transition-all duration-150 shadow-[0_1px_3px_rgba(0,0,0,0.06)] ${Y?"border-primary/20 bg-primary/5 ring-1 ring-primary/10":"border-border/40 hover:shadow-[0_2px_6px_rgba(0,0,0,0.08)]"}`,children:[p.jsxs("div",{className:"flex items-center justify-between",onClick:te=>{te.stopPropagation(),D(L)},children:[p.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[p.jsx("span",{className:"text-xs font-semibold text-foreground truncate",children:T.data.author||"unknown"}),U&&p.jsx("span",{className:`text-[10px] font-medium px-1.5 py-0.5 rounded flex-shrink-0 ${U.bg} ${U.text}`,children:U.label})]}),p.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[p.jsx("span",{className:"text-[10px] text-muted-foreground",children:Z_(Pw(T))}),p.jsx("svg",{className:`w-3 h-3 text-muted-foreground/40 transition-transform duration-150 ${V?"":"rotate-180"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]})]}),!V&&T.data.body&&p.jsx("div",{className:"mt-2 text-xs text-foreground/80 leading-relaxed review-comment-markdown",children:p.jsx(xA,{markdown:T.data.body})}),!V&&p.jsx(K2,{url:(T.kind==="comment",T.data.url),body:T.data.body})]},L)})})})})]}))});function kW({thread:t,isSelected:e,isCollapsed:n,onSelect:a,onToggleCollapse:r}){const[s,c]=E.useState(!1),u=t.comments[0];if(!u)return null;const d=t.comments.slice(1),A=t.isResolved||t.isOutdated,g=t.startLine&&t.line&&t.startLine!==t.line?`L${t.startLine}–${t.line}`:t.line?`L${t.line}`:"";return p.jsxs("div",{"data-comment-id":t.id,onClick:a,className:`group/card rounded border p-3 cursor-pointer transition-all duration-150 ${A?"bg-card/50 shadow-[0_1px_2px_rgba(0,0,0,0.03)]":"bg-card shadow-[0_1px_3px_rgba(0,0,0,0.06)]"} ${e?"border-primary/20 bg-primary/5 ring-1 ring-primary/10":"border-border/40 hover:shadow-[0_2px_6px_rgba(0,0,0,0.08)]"}`,children:[p.jsxs("div",{className:"flex items-center justify-between",onClick:b=>{b.stopPropagation(),r()},children:[p.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[p.jsx("span",{className:`text-xs font-semibold truncate ${t.isResolved?"line-through text-muted-foreground":"text-foreground"}`,children:u.author||"unknown"}),t.isOutdated&&p.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-warning/15 text-warning flex-shrink-0",children:"Outdated"}),t.isResolved&&p.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded bg-success/15 text-success flex-shrink-0",children:"Resolved"}),t.path&&p.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground truncate flex-shrink min-w-0",children:[t.path.split("/").pop(),g?`:${g}`:""]})]}),p.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[d.length>0&&p.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[d.length," repl",d.length===1?"y":"ies"]}),p.jsx("span",{className:"text-[10px] text-muted-foreground",children:Z_(u.createdAt)}),p.jsx("svg",{className:`w-3 h-3 text-muted-foreground/40 transition-transform duration-150 ${n?"":"rotate-180"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]})]}),!n&&p.jsxs(p.Fragment,{children:[u.diffHunk&&p.jsx("div",{className:"mt-2",children:p.jsx(fW,{hunk:u.diffHunk,maxHeight:96})}),u.body&&p.jsxs("div",{className:`relative mt-2 ${A&&!s?"max-h-16 overflow-hidden":""}`,children:[p.jsx("div",{className:`text-xs leading-relaxed review-comment-markdown ${A&&!s?"text-muted-foreground":"text-foreground/80"}`,children:p.jsx(xA,{markdown:u.body})}),A&&!s&&p.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-10 bg-gradient-to-t from-card to-transparent pointer-events-none"})]}),A&&!s&&p.jsxs("button",{onClick:b=>{b.stopPropagation(),c(!0)},className:"mt-1 text-[10px] text-primary/70 hover:text-primary transition-colors",children:["Show full comment",d.length>0?` + ${d.length} repl${d.length===1?"y":"ies"}`:""]}),(!A||s)&&d.length>0&&p.jsx("div",{className:"mt-2 ml-4 space-y-2 border-l border-border/30 pl-3",children:d.map(b=>p.jsxs("div",{children:[p.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[p.jsx("span",{className:"text-[10px] font-semibold text-foreground",children:b.author}),p.jsx("span",{className:"text-[10px] text-muted-foreground",children:Z_(b.createdAt)})]}),p.jsx("div",{className:"text-xs text-foreground/80 leading-relaxed review-comment-markdown",children:p.jsx(xA,{markdown:b.body})})]},b.id))}),p.jsx(K2,{url:u.url,body:u.body})]})]})}function K2({url:t,body:e}){return!t&&!e?null:p.jsxs("div",{className:"mt-2 pt-2 border-t border-border/20 flex items-center justify-end gap-1 opacity-0 group-hover/card:opacity-100 transition-opacity duration-100",children:[t&&p.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",onClick:n=>n.stopPropagation(),className:"flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-muted/30 transition-colors",children:[p.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),t.includes("gitlab")?"View on GitLab":"View on GitHub"]}),p.jsx(Xr,{text:e,variant:"inline",label:"Copy"})]})}function vW({label:t,excluded:e,onClick:n}){return p.jsx("button",{onClick:n,className:`text-[10px] px-1.5 py-0.5 rounded whitespace-nowrap transition-colors ${e?"bg-muted/50 text-muted-foreground/40 line-through":"bg-muted text-muted-foreground hover:text-foreground"}`,title:e?`Show ${t}`:`Hide ${t}`,children:t})}const CW=()=>{const{prContext:t,isPRContextLoading:e,prContextError:n,fetchPRContext:a,platformUser:r}=Zc();return E.useEffect(()=>{!t&&!n&&!e&&a()},[t,n,e,a]),e?p.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:"Loading comments…"}):n?p.jsxs("div",{className:"h-full flex flex-col items-center justify-center gap-3 px-6 text-center",children:[p.jsx("div",{className:"text-destructive text-sm",children:n}),p.jsx("button",{type:"button",onClick:a,className:"px-2.5 py-1 rounded-md text-xs font-medium bg-muted hover:bg-muted/80 transition-colors",children:"Retry"})]}):t?p.jsx("div",{className:"h-full overflow-hidden",children:p.jsx(_W,{context:t,platformUser:r})}):null},EW={APPROVED:{bg:"bg-success/15",text:"text-success",label:"Approved"},CHANGES_REQUESTED:{bg:"bg-destructive/15",text:"text-destructive",label:"Changes Requested"},REVIEW_REQUIRED:{bg:"bg-yellow-500/15",text:"text-yellow-500",label:"Review Required"}},N1={CLEAN:{bg:"bg-success/15",text:"text-success",label:"Ready to merge"},BLOCKED:{bg:"bg-yellow-500/15",text:"text-yellow-500",label:"Blocked"},BEHIND:{bg:"bg-yellow-500/15",text:"text-yellow-500",label:"Behind base branch"},DIRTY:{bg:"bg-destructive/15",text:"text-destructive",label:"Has conflicts"},UNKNOWN:{bg:"bg-muted",text:"text-muted-foreground",label:"Unknown"}};function xW({check:t}){return t.status!=="COMPLETED"?p.jsx("svg",{className:"w-3.5 h-3.5 text-yellow-500 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}):t.conclusion==="SUCCESS"?p.jsx("svg",{className:"w-3.5 h-3.5 text-success",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):t.conclusion==="FAILURE"||t.conclusion==="TIMED_OUT"?p.jsx("svg",{className:"w-3.5 h-3.5 text-destructive",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}):t.conclusion==="SKIPPED"||t.conclusion==="NEUTRAL"?p.jsx("svg",{className:"w-3.5 h-3.5 text-muted-foreground",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M20 12H4"})}):p.jsx("svg",{className:"w-3.5 h-3.5 text-muted-foreground",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("circle",{cx:"12",cy:"12",r:"10"})})}const BW=({context:t})=>{const e=E.useMemo(()=>{const d=new Map;for(const A of t.checks){const g=A.workflowName||"Other",b=d.get(g)||[];b.push(A),d.set(g,b)}return d},[t.checks]),n=E.useMemo(()=>{const d=t.checks.length,A=t.checks.filter(y=>y.conclusion==="SUCCESS").length,g=t.checks.filter(y=>y.conclusion==="FAILURE"||y.conclusion==="TIMED_OUT").length,b=t.checks.filter(y=>y.status!=="COMPLETED").length,h=t.checks.filter(y=>y.conclusion==="SKIPPED"||y.conclusion==="NEUTRAL").length;return{total:d,passed:A,failed:g,pending:b,skipped:h}},[t.checks]),a=t.state==="MERGED",r=t.state==="CLOSED",s=EW[t.reviewDecision],c=a?{bg:"bg-violet-500/15",text:"text-violet-400",label:"Merged"}:r?{bg:"bg-destructive/15",text:"text-destructive",label:"Closed"}:N1[t.mergeStateStatus]??N1.UNKNOWN,u=!a&&!r&&t.mergeable==="CONFLICTING";return p.jsxs("div",{className:"px-8 py-4 space-y-4 max-w-2xl",children:[p.jsxs("div",{className:"space-y-2",children:[p.jsx("h3",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Merge Status"}),p.jsxs("div",{className:"space-y-1.5",children:[s&&p.jsx("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded ${s.bg}`,children:p.jsx("span",{className:`text-xs font-medium ${s.text}`,children:s.label})}),p.jsx("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded ${c.bg}`,children:p.jsx("span",{className:`text-xs font-medium ${c.text}`,children:u?"Has merge conflicts":c.label})})]})]}),t.checks.length>0&&p.jsxs("div",{className:"space-y-2",children:[p.jsxs("div",{className:"flex items-center justify-between",children:[p.jsx("h3",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Checks"}),p.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground",children:[n.passed,"/",n.total," passed",n.failed>0&&p.jsxs("span",{className:"text-destructive ml-1",children:[n.failed," failed"]}),n.pending>0&&p.jsxs("span",{className:"text-yellow-500 ml-1",children:[n.pending," pending"]})]})]}),p.jsx("div",{className:"space-y-4",children:Array.from(e.entries()).map(([d,A])=>p.jsxs("div",{children:[p.jsx("div",{className:"text-[10px] font-semibold text-muted-foreground mb-1.5 uppercase tracking-wider",children:d}),p.jsx("div",{className:"space-y-1",children:A.map((g,b)=>p.jsxs("a",{href:g.detailsUrl||void 0,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 px-2 py-1.5 rounded hover:bg-muted/30 transition-colors group cursor-pointer",children:[p.jsx(xW,{check:g}),p.jsx("span",{className:"text-xs text-primary/70 truncate group-hover:text-primary group-hover:underline",children:g.name}),p.jsx("svg",{className:"w-3 h-3 text-muted-foreground/30 ml-auto flex-shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:p.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]},`${g.name}-${b}`))})]},d))})]}),t.checks.length===0&&!s&&p.jsx("div",{className:"flex flex-col items-center justify-center h-24 text-center",children:p.jsx("p",{className:"text-xs text-muted-foreground",children:"No checks configured."})})]})},IW=()=>{const{prContext:t,isPRContextLoading:e,prContextError:n,fetchPRContext:a}=Zc();return E.useEffect(()=>{!t&&!n&&!e&&a()},[t,n,e,a]),e?p.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:"Loading checks…"}):n?p.jsxs("div",{className:"h-full flex flex-col items-center justify-center gap-3 px-6 text-center",children:[p.jsx("div",{className:"text-destructive text-sm",children:n}),p.jsx("button",{type:"button",onClick:a,className:"px-2.5 py-1 rounded-md text-xs font-medium bg-muted hover:bg-muted/80 transition-colors",children:"Retry"})]}):t?p.jsx(to,{className:"h-full",children:p.jsx(BW,{context:t})}):null},SW={[br.DIFF]:iW,[br.AGENT_JOB_DETAIL]:sW,[br.PR_SUMMARY]:bW,[br.PR_COMMENTS]:CW,[br.PR_CHECKS]:IW},DW=t=>{const[e,n]=E.useState(t.api.title??t.api.id);E.useEffect(()=>{const r=t.api.onDidTitleChange(()=>{n(t.api.title??t.api.id)});return()=>r.dispose()},[t.api]);const a=r=>{r.stopPropagation(),t.api.close()};return p.jsxs("div",{className:"dv-review-tab",title:e,children:[p.jsx("span",{className:"dv-review-tab-label",children:e}),p.jsx("button",{className:"dv-review-tab-close",onClick:a,"aria-label":"Close",children:p.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:p.jsx("path",{d:"M8 8.707l3.646 3.647.708-.707L8.707 8l3.647-3.646-.707-.708L8 7.293 4.354 3.646l-.707.708L7.293 8l-3.646 3.646.707.708L8 8.707z"})})})]})};function QW(t){const[e,n]=E.useState(null),[a,r]=E.useState(!1),[s,c]=E.useState(null),u=E.useRef(!1),d=E.useCallback(async()=>{if(!(!t||u.current)){u.current=!0,r(!0),c(null);try{const A=await fetch("/api/pr-context");if(!A.ok){const b=await A.json().catch(()=>({}));throw new Error(b.error||`HTTP ${A.status}`)}const g=await A.json();n(g)}catch(A){const g=A instanceof Error?A.message:"Failed to load PR context";c(g),u.current=!1}finally{r(!1)}}},[t]);return{prContext:e,isLoading:a,error:s,fetchContext:d}}function jw(t){const e=[],n=t.split(/^diff --git /m).filter(Boolean);for(const a of n){const r=a.split(`
6366
- `),s=r[0]?.match(/a\/(.+) b\/(.+)/);if(!s)continue;const c=s[1],u=s[2];let d=0,A=0;for(const g of r)g.startsWith("+")&&!g.startsWith("+++")&&d++,g.startsWith("-")&&!g.startsWith("---")&&A++;e.push({path:u,oldPath:c!==u?c:void 0,patch:"diff --git "+a,additions:d,deletions:A})}return e}function R1(t){return t.split("/").pop()??t}const NW=()=>{const{resolvedMode:t}=Fd(),[e,n]=E.useState(null),[a,r]=E.useState([]),[s,c]=E.useState(0),[u,d]=E.useState([]),[A,g]=E.useState(null),[b,h]=E.useState(null),[y,_]=E.useState(!1),[k,v]=E.useState(!1),[C,x]=E.useState(!1),[S,I]=E.useState(!1),[Q,D]=E.useState(!0),R=$n("diffStyle"),N=$n("diffOverflow"),F=$n("diffIndicators"),P=$n("diffLineDiffType"),T=$n("diffShowLineNumbers"),L=$n("diffShowBackground"),Y=$n("diffFontFamily"),V=$n("diffFontSize");E.useEffect(()=>{Y?(U1(Y),document.documentElement.style.setProperty("--diff-font-override",`'${Y}', monospace`)):document.documentElement.style.removeProperty("--diff-font-override"),V?document.documentElement.style.setProperty("--diff-font-size-override",V):document.documentElement.style.removeProperty("--diff-font-size-override")},[Y,V]);const[q,O]=E.useState(!0),[U,te]=E.useState(null),[oe,de]=E.useState("idle"),[j,W]=E.useState(new Set),[H,X]=E.useState(!1),[Z,ce]=E.useState(null),[ie,be]=E.useState(),[se,$]=E.useState(!1),[pe,ge]=E.useState("uncommitted"),[Ie,Re]=E.useState(null),[$e,Xe]=E.useState(null),[lt,Et]=E.useState(!1),[gt,Le]=E.useState(null),[rt,dt]=E.useState(!1),[bt,et]=E.useState(!1),[ut,yt]=E.useState(!1),[ft,Kt]=E.useState(!1),[xn,yn]=E.useState(!0),[Xt,gn]=E.useState(null);E.useEffect(()=>{document.title=Xt?`${Xt.display} · Code Review`:"Code Review"},[Xt]);const[He,Ht]=E.useState(null),[Ft,St]=E.useState(()=>xe.getItem("plannotator-review-dest")==="agent"?"agent":"platform"),[Tn,ae]=E.useState(!1),[Ne,Ke]=E.useState(!1),[Dt,Be]=E.useState(null),[ke,z]=E.useState(null),[me,_e]=E.useState(null),[Ge,It]=E.useState(""),[Lt,Pe]=E.useState(()=>{const ee=xe.getItem("plannotator-platform-open-pr");if(ee!==null)return ee!=="false";const he=xe.getItem("plannotator-github-open-pr");return he!==null?(xe.setItem("plannotator-platform-open-pr",he),he!=="false"):!0}),De=Ft==="platform"&&!!He,qe=He?W8(He):"GitHub",Rt=He?mR(He):"PR",wt=He?gR(He):"",bn=He?bR(He):"",Oa="0.17.2",la=$n("displayName");E.useCallback(()=>{h(null)},[]);const{editorAnnotations:Dn,deleteEditorAnnotation:An}=bP(),{externalAnnotations:Qt,updateExternalAnnotation:Na,deleteExternalAnnotation:Ai}=yP({enabled:!!Z}),Kn=vP({enabled:!!Z}),[Bn,kr]=E.useState(null),Ue=E.useRef(a);Ue.current=a;const J=E.useRef(!0),{prContext:Ee,isLoading:Oe,error:Mt,fetchContext:nn}=QW(He??null),tt=E.useCallback(ee=>{const he=a.find(We=>We.path===ee);if(!he)return;if(!Bn){const We=a.findIndex(_t=>_t.path===ee);We!==-1&&c(We);return}const Fe=Bn.getPanel(Cc);if(Fe){if(uA(Fe.params)===ee){Bn.activePanel?.id!==Cc&&Fe.api.setActive();const _t=a.findIndex(qt=>qt.path===ee);_t!==-1&&c(_t),J.current=!1;return}h(null),Fe.api.updateParameters({filePath:ee}),Fe.api.setTitle(R1(he.path)),Fe.api.setActive()}else h(null),Bn.addPanel({id:Cc,component:br.DIFF,title:R1(he.path),params:{filePath:ee}});c(a.findIndex(We=>We.path===ee)),J.current=!1},[Bn,a]),Fn=E.useCallback(ee=>{tt(ee.filePath)},[tt]),{searchQuery:Qn,debouncedSearchQuery:jn,isSearchPending:Se,isSearchOpen:Me,activeSearchMatchId:At,activeSearchMatch:Ot,activeFileSearchMatches:wn,searchMatches:Gn,searchGroups:xa,searchInputRef:fa,openSearch:en,closeSearch:da,clearSearch:Xi,stepSearchMatch:Ti,handleSearchInputChange:no,handleSelectSearchMatch:vr}=mP({files:a,activeFilePath:a[s]?.path??null,onRevealMatch:Fn}),zn=a.length>0,ha=zn||!!Ie?.diffOptions?.length||!!Ie?.worktrees?.length,an=E.useMemo(()=>Qt.length===0?u:[...u.filter(he=>he.source?!Qt.some(Fe=>Fe.source===he.source&&Fe.type===he.type&&Fe.filePath===he.filePath&&Fe.lineStart===he.lineStart&&Fe.lineEnd===he.lineEnd&&Fe.side===he.side):!0),...Qt],[u,Qt]),mi=E.useRef(an);mi.current=an;const{draftBanner:ua,restoreDraft:Ln,dismissDraft:ao}=tP({annotations:an,viewedFiles:j,isApiMode:!!Z,submitted:!!ut}),er=E.useCallback(()=>{const ee=Ln();ee.annotations.length>0&&d(ee.annotations),ee.viewedFiles.length>0&&W(new Set(ee.viewedFiles))},[Ln]),[at,io]=E.useState(!1),[fn,Yt]=E.useState([]),[Ba,Pa]=E.useState(()=>{const ee=Jr(),he=ee.providerId;return{providerId:he,model:he?ee.preferredModels[he]??null:null,reasoningEffort:null}}),[Cr,Va]=E.useState(!1),[Te,je]=E.useState(void 0),ze=iP({patch:e?.rawPatch??"",providerId:Ba.providerId,model:Ba.model,reasoningEffort:Ba.reasoningEffort});E.useEffect(()=>{fetch("/api/ai/capabilities").then(ee=>ee.ok?ee.json():null).then(ee=>{if(ee?.available){io(!0);const he=ee.providers??[];Yt(he),he.length>0&&Z8()&&Va(!0)}}).catch(()=>{})},[]);const vt=E.useCallback(ee=>{Pa(he=>{const Fe={...he,...ee};ee.providerId!==void 0&&ee.providerId!==he.providerId&&(Fe.model=ee.providerId?rO(ee.providerId):null);const We=Jr();return IA({...We,providerId:Fe.providerId}),Fe}),ze.resetSession()},[ze]),rn=E.useCallback(ee=>{if(!b||!a[s])return;const he=Math.min(b.start,b.end),Fe=Math.max(b.start,b.end),We=b.side==="additions"?"new":"old",_t=a_(a[s].patch,he,Fe,We);ze.ask({prompt:ee,filePath:a[s].path,lineStart:he,lineEnd:Fe,side:We,selectedCode:_t||void 0})},[b,a,s,ze]),pa=E.useCallback(ee=>{je("ai"),O(!0),ee&&(ja(ee),setTimeout(()=>ja(null),500))},[]),ro=E.useCallback((ee,he,Fe,We)=>{tt(ee),h({start:he,end:Fe,side:We==="new"?"additions":"deletions"})},[tt]),oo=E.useMemo(()=>{if(!b||!a[s])return[];const ee=a[s].path,he=Math.min(b.start,b.end),Fe=Math.max(b.start,b.end),We=b.side==="additions"?"new":"old";return ze.messages.filter(_t=>{const qt=_t.question;return qt.filePath===ee&&qt.side===We&&qt.lineStart!=null&&qt.lineEnd!=null&&qt.lineStart<=Fe&&qt.lineEnd>=he})},[b,a,s,ze.messages]),[Uo,ja]=E.useState(null),Fs=E.useCallback(ee=>{ja(ee),je("ai"),O(!0),setTimeout(()=>ja(null),500)},[]),Ho=E.useCallback(ee=>{ze.ask({prompt:ee})},[ze.ask]),gi=DB({storageKey:"plannotator-review-panel-width"}),Yo=DB({storageKey:"plannotator-filetree-width",defaultWidth:256,minWidth:160,maxWidth:400,side:"left"}),Ls=gi.isDragging||Yo.isDragging,Hd=E.useCallback(ee=>{kr(ee.api),ee.api.onDidActivePanelChange(Fe=>{if(!Fe||!H6(Fe.id))return;const We=uA(Fe.params);if(!We)return;const _t=Ue.current.findIndex(qt=>qt.path===We);_t!==-1&&c(_t)});const he=()=>{const We=(ee.api.totalPanels===1&&ee.api.groups.length===1?ee.api.groups[0]?.panels[0]:void 0)?.id===Cc;for(const _t of ee.api.groups)_t.header.hidden=We};ee.api.onDidAddPanel(he),ee.api.onDidRemovePanel(he),ee.api.onDidAddGroup(he),ee.api.onDidRemoveGroup(he),ee.api.onDidMovePanel(he),ee.api.onDidLayoutChange(he),he()},[]);E.useEffect(()=>{!Bn||!J.current||a.length===0||tt(a[0].path)},[Bn,a,tt]);const Ms=E.useCallback(ee=>{const he=Bn;if(!he)return;const Fe=G6(ee),We=he.getPanel(Fe);if(We){We.api.setActive();return}const _t=Kn.jobs.find(qt=>qt.id===ee);he.addPanel({id:Fe,component:br.AGENT_JOB_DETAIL,title:_t?.label??`Job ${ee.slice(0,8)}`,params:{jobId:ee}})},[Bn,Kn.jobs]),Er=E.useCallback(ee=>{const he=Bn;if(!he)return;const Fe={summary:{id:z6,component:br.PR_SUMMARY,title:"PR Summary"},comments:{id:q6,component:br.PR_COMMENTS,title:"PR Comments"},checks:{id:U6,component:br.PR_CHECKS,title:"PR Checks"}}[ee],We=he.getPanel(Fe.id);if(We){We.api.setActive();return}he.addPanel({id:Fe.id,component:Fe.component,title:Fe.title})},[Bn]);E.useEffect(()=>{const ee=he=>{if((he.metaKey||he.ctrlKey)&&he.key.toLowerCase()==="f"&&!NB(he.target)){zn&&(he.preventDefault(),en());return}if((he.key==="Enter"||he.key==="F3")&&Gn.length>0&&!Se&&!NB(he.target)){he.preventDefault(),Ti(he.shiftKey?-1:1);return}he.key==="Escape"&&(Tn?ae(!1):y?_(!1):Me?Qn?Xi():da():Qn&&Xi()),(he.metaKey||he.ctrlKey)&&he.shiftKey&&he.key==="c"&&(he.preventDefault(),Zd())};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[y,Tn,Me,Qn,Gn,Se,en,Ti,Xi,da,zn]),E.useEffect(()=>{fetch("/api/diff").then(ee=>{if(!ee.ok)throw new Error("Not in API mode");return ee.json()}).then(ee=>{ea.init(ee.serverConfig),be(ee.serverConfig?.gitUser);const he=jw(ee.rawPatch);n({files:he,rawPatch:ee.rawPatch,gitRef:ee.gitRef,origin:ee.origin,diffType:ee.diffType,gitContext:ee.gitContext,sharingEnabled:ee.sharingEnabled}),r(he),ee.origin&&ce(ee.origin),ee.diffType&&ge(ee.diffType),ee.gitContext&&Re(ee.gitContext),ee.agentCwd&&Xe(ee.agentCwd),ee.sharingEnabled!==void 0&&yn(ee.sharingEnabled),ee.repoInfo&&gn(ee.repoInfo),ee.prMetadata&&Ht(ee.prMetadata),ee.platformUser&&z(ee.platformUser),ee.viewedFiles&&ee.viewedFiles.length>0&&W(new Set(ee.viewedFiles)),ee.error&&Le(ee.error),ee.isWSL&&$(!0)}).catch(()=>{const ee=jw(eQ);n({files:ee,rawPatch:eQ,gitRef:"demo"}),r(ee)}).finally(()=>D(!1))},[]);const il=E.useCallback(ee=>{ea.set("diffStyle",ee)},[]),ya=E.useCallback(ee=>{h(ee)},[]),tr=E.useCallback((ee,he,Fe,We,_t,qt,Ia)=>{if(!b||!a[s])return;const wa=Math.min(b.start,b.end),ot=Math.max(b.start,b.end),nr={id:n_(),type:ee,scope:"line",filePath:a[s].path,lineStart:wa,lineEnd:ot,side:b.side==="additions"?"new":"old",text:he,suggestedCode:Fe,originalCode:We,...Ia&&{charStart:Ia.charStart,charEnd:Ia.charEnd,tokenText:Ia.tokenText},createdAt:Date.now(),author:la,conventionalLabel:_t,decorations:qt};d(Br=>[...Br,nr]),h(null)},[b,a,s,la]),$o=E.useCallback(ee=>{const he=a[s],Fe=ee.trim();if(!he||!Fe)return;const We={id:n_(),type:"comment",scope:"file",filePath:he.path,lineStart:1,lineEnd:1,side:"new",text:Fe,createdAt:Date.now(),author:la};d(_t=>[..._t,We])},[a,s,la]),so=E.useCallback((ee,he,Fe,We,_t,qt)=>{const Ia=mi.current.find(ot=>ot.id===ee),wa={...he!==void 0&&{text:he},...Fe!==void 0&&{suggestedCode:Fe},...We!==void 0&&{originalCode:We},..._t!==void 0&&{conventionalLabel:_t??void 0},...qt!==void 0&&{decorations:qt}};if(Ia?.source&&Qt.some(ot=>ot.id===ee)){Na(ee,wa);return}d(ot=>ot.map(nr=>nr.id===ee?{...nr,...wa}:nr))},[Na,Qt]),rl=E.useCallback(ee=>{if(mi.current.find(Fe=>Fe.id===ee)?.source&&Qt.some(Fe=>Fe.id===ee)){Ai(ee),A===ee&&g(null);return}d(Fe=>Fe.filter(We=>We.id!==ee)),A===ee&&g(null)},[A,Ai,Qt]),ol=E.useCallback((ee,he)=>{d(Fe=>Fe.map(We=>We.author===ee?{...We,author:he}:We))},[]),sl=E.useCallback(ee=>{const he=a[ee];he&&tt(he.path)},[a,tt]),Ko=E.useCallback(ee=>{const he=a[ee];he&&tt(he.path)},[a,tt]),Wo=E.useCallback(ee=>{const he=a[ee];he&&tt(he.path)},[a,tt]),Os=E.useCallback(ee=>{W(he=>{const Fe=new Set(he),We=!he.has(ee);return We?Fe.add(ee):Fe.delete(ee),He&&He.platform==="github"&&fetch("/api/pr-viewed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePaths:[ee],viewed:We})}).catch(()=>{}),Fe})},[He]),{activeWorktreePath:Fi,activeDiffBase:xr}=E.useMemo(()=>{if(pe.startsWith("worktree:")){const ee=pe.slice(9),he=ee.lastIndexOf(":");if(he!==-1){const Fe=ee.slice(he+1);if(["uncommitted","staged","unstaged","last-commit","branch"].includes(Fe))return{activeWorktreePath:ee.slice(0,he),activeDiffBase:Fe}}return{activeWorktreePath:ee,activeDiffBase:"uncommitted"}}return{activeWorktreePath:null,activeDiffBase:pe}},[pe]),om=E.useCallback(ee=>W(he=>new Set(he).add(ee)),[]),{stagedFiles:Zo,stagingFile:Yd,canStageFiles:sm,stageFile:$d,resetStagedFiles:Kd,stageError:Wd}=aP({activeDiffBase:xr,onFileViewed:om}),cl=sm&&!He,Ps=E.useCallback(async ee=>{Et(!0);try{const he=await fetch("/api/diff/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({diffType:ee})});if(!he.ok)throw new Error("Failed to switch diff");const Fe=await he.json(),We=jw(Fe.rawPatch);Bn?.getPanel(Cc)?.api.close(),J.current=!0,r(We),ge(Fe.diffType),c(0),h(null),Le(Fe.error||null),Kd()}catch(he){console.error("Failed to switch diff:",he),Le(he instanceof Error?he.message:"Failed to switch diff")}finally{Et(!1)}},[Bn,Kd]),cm=E.useCallback(async ee=>{const he=Fi?`worktree:${Fi}:${ee}`:ee;he!==pe&&await Ps(he)},[pe,Fi,Ps]),lm=E.useCallback(async ee=>{if(ee===Fi)return;const he=ee?`worktree:${ee}:uncommitted`:"uncommitted";await Ps(he)},[Fi,Ps]),ll=E.useCallback(ee=>{if(!ee){g(null);return}const he=an.find(We=>We.id===ee);if(!he){g(ee);return}const Fe=a.findIndex(We=>We.path===he.filePath);Fe!==-1&&Wo(Fe),g(ee)},[an,a,Wo]),dl=E.useMemo(()=>({files:a,focusedFileIndex:s,focusedFilePath:a[s]?.path??null,diffStyle:R,diffOverflow:N,diffIndicators:F,lineDiffType:P,disableLineNumbers:!T,disableBackground:!L,fontFamily:Y||void 0,fontSize:V||void 0,allAnnotations:an,externalAnnotations:Qt,selectedAnnotationId:A,pendingSelection:b,onLineSelection:ya,onAddAnnotation:tr,onAddFileComment:$o,onEditAnnotation:so,onSelectAnnotation:ll,onDeleteAnnotation:rl,viewedFiles:j,onToggleViewed:Os,stagedFiles:Zo,stagingFile:Yd,onStage:$d,canStageFiles:cl,stageError:Wd,searchQuery:Se?"":jn,isSearchPending:Se,debouncedSearchQuery:jn,activeFileSearchMatches:wn,activeSearchMatchId:At,activeSearchMatch:Ot?.filePath===a[s]?.path?Ot:null,aiAvailable:at,aiMessages:ze.messages,onAskAI:rn,isAILoading:ze.isCreatingSession||ze.isStreaming,onViewAIResponse:pa,onClickAIMarker:Fs,aiHistoryForSelection:oo,agentJobs:Kn.jobs,prMetadata:He,prContext:Ee,isPRContextLoading:Oe,prContextError:Mt,fetchPRContext:nn,platformUser:ke,openDiffFile:tt}),[a,s,R,N,F,P,T,L,Y,V,an,Qt,A,b,ya,tr,$o,so,ll,rl,j,Os,Zo,Yd,$d,cl,Wd,Se,jn,wn,At,Ot,at,ze.messages,ze.isCreatingSession,ze.isStreaming,rn,pa,Fs,oo,Kn.jobs,He,Ee,Oe,Mt,nn,ke,tt]),dm=E.useMemo(()=>({jobLogs:Kn.jobLogs}),[Kn.jobLogs]),Zd=E.useCallback(async()=>{if(e)try{await navigator.clipboard.writeText(e.rawPatch),de("success"),setTimeout(()=>de("idle"),2e3)}catch(ee){console.error("Failed to copy:",ee),de("error"),setTimeout(()=>de("idle"),2e3)}},[e]),um=E.useCallback(async()=>{if(an.length===0){I(!0);return}try{const ee=w_(an,He);await navigator.clipboard.writeText(ee),te("Feedback copied!"),setTimeout(()=>te(null),2e3)}catch(ee){console.error("Failed to copy:",ee),te("Failed to copy"),setTimeout(()=>te(null),2e3)}},[an,He]),co=E.useMemo(()=>{let ee=w_(an,He);return Dn.length>0&&(ee+=xP(Dn)),ee},[an,He,Dn]),qn=an.length+Dn.length,ul=E.useCallback(async()=>{if(qn===0){I(!0);return}dt(!0);try{const ee=Kp(),he=iB(ee);if((await fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({approved:!1,feedback:co,annotations:an,...he&&{agentSwitch:he}})})).ok)yt("feedback");else throw new Error("Failed to send")}catch(ee){console.error("Failed to send feedback:",ee),te("Failed to send"),setTimeout(()=>te(null),2e3),dt(!1)}},[qn,co,an]),js=E.useCallback(async()=>{et(!0);try{if((await fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({approved:!0,feedback:"LGTM - no changes requested.",annotations:[]})})).ok)yt("approved");else throw new Error("Failed to send")}catch(ee){console.error("Failed to approve:",ee),te("Failed to send"),setTimeout(()=>te(null),2e3),et(!1)}},[]),Vd=E.useCallback((ee,he)=>{const Fe=an.filter(ot=>(ot.scope??"line")==="line"),We=an.filter(ot=>ot.scope==="file"),_t=[];if(We.length>0)for(const ot of We)ot.text&&_t.push(`**${ot.filePath}:** ${ot.text}`);const qt=_t.length>0?`${he?he+`
6366
+ `),s=r[0]?.match(/a\/(.+) b\/(.+)/);if(!s)continue;const c=s[1],u=s[2];let d=0,A=0;for(const g of r)g.startsWith("+")&&!g.startsWith("+++")&&d++,g.startsWith("-")&&!g.startsWith("---")&&A++;e.push({path:u,oldPath:c!==u?c:void 0,patch:"diff --git "+a,additions:d,deletions:A})}return e}function R1(t){return t.split("/").pop()??t}const NW=()=>{const{resolvedMode:t}=Fd(),[e,n]=E.useState(null),[a,r]=E.useState([]),[s,c]=E.useState(0),[u,d]=E.useState([]),[A,g]=E.useState(null),[b,h]=E.useState(null),[y,_]=E.useState(!1),[k,v]=E.useState(!1),[C,x]=E.useState(!1),[S,I]=E.useState(!1),[Q,D]=E.useState(!0),R=$n("diffStyle"),N=$n("diffOverflow"),F=$n("diffIndicators"),P=$n("diffLineDiffType"),T=$n("diffShowLineNumbers"),L=$n("diffShowBackground"),Y=$n("diffFontFamily"),V=$n("diffFontSize");E.useEffect(()=>{Y?(U1(Y),document.documentElement.style.setProperty("--diff-font-override",`'${Y}', monospace`)):document.documentElement.style.removeProperty("--diff-font-override"),V?document.documentElement.style.setProperty("--diff-font-size-override",V):document.documentElement.style.removeProperty("--diff-font-size-override")},[Y,V]);const[q,O]=E.useState(!0),[U,te]=E.useState(null),[oe,de]=E.useState("idle"),[j,W]=E.useState(new Set),[H,X]=E.useState(!1),[Z,ce]=E.useState(null),[ie,be]=E.useState(),[se,$]=E.useState(!1),[pe,ge]=E.useState("uncommitted"),[Ie,Re]=E.useState(null),[$e,Xe]=E.useState(null),[lt,Et]=E.useState(!1),[gt,Le]=E.useState(null),[rt,dt]=E.useState(!1),[bt,et]=E.useState(!1),[ut,yt]=E.useState(!1),[ft,Kt]=E.useState(!1),[xn,yn]=E.useState(!0),[Xt,gn]=E.useState(null);E.useEffect(()=>{document.title=Xt?`${Xt.display} · Code Review`:"Code Review"},[Xt]);const[He,Ht]=E.useState(null),[Ft,St]=E.useState(()=>xe.getItem("plannotator-review-dest")==="agent"?"agent":"platform"),[Tn,ae]=E.useState(!1),[Ne,Ke]=E.useState(!1),[Dt,Be]=E.useState(null),[ke,z]=E.useState(null),[me,_e]=E.useState(null),[Ge,It]=E.useState(""),[Lt,Pe]=E.useState(()=>{const ee=xe.getItem("plannotator-platform-open-pr");if(ee!==null)return ee!=="false";const he=xe.getItem("plannotator-github-open-pr");return he!==null?(xe.setItem("plannotator-platform-open-pr",he),he!=="false"):!0}),De=Ft==="platform"&&!!He,qe=He?W8(He):"GitHub",Rt=He?mR(He):"PR",wt=He?gR(He):"",bn=He?bR(He):"",Oa="0.17.3",la=$n("displayName");E.useCallback(()=>{h(null)},[]);const{editorAnnotations:Dn,deleteEditorAnnotation:An}=bP(),{externalAnnotations:Qt,updateExternalAnnotation:Na,deleteExternalAnnotation:Ai}=yP({enabled:!!Z}),Kn=vP({enabled:!!Z}),[Bn,kr]=E.useState(null),Ue=E.useRef(a);Ue.current=a;const J=E.useRef(!0),{prContext:Ee,isLoading:Oe,error:Mt,fetchContext:nn}=QW(He??null),tt=E.useCallback(ee=>{const he=a.find(We=>We.path===ee);if(!he)return;if(!Bn){const We=a.findIndex(_t=>_t.path===ee);We!==-1&&c(We);return}const Fe=Bn.getPanel(Cc);if(Fe){if(uA(Fe.params)===ee){Bn.activePanel?.id!==Cc&&Fe.api.setActive();const _t=a.findIndex(qt=>qt.path===ee);_t!==-1&&c(_t),J.current=!1;return}h(null),Fe.api.updateParameters({filePath:ee}),Fe.api.setTitle(R1(he.path)),Fe.api.setActive()}else h(null),Bn.addPanel({id:Cc,component:br.DIFF,title:R1(he.path),params:{filePath:ee}});c(a.findIndex(We=>We.path===ee)),J.current=!1},[Bn,a]),Fn=E.useCallback(ee=>{tt(ee.filePath)},[tt]),{searchQuery:Qn,debouncedSearchQuery:jn,isSearchPending:Se,isSearchOpen:Me,activeSearchMatchId:At,activeSearchMatch:Ot,activeFileSearchMatches:wn,searchMatches:Gn,searchGroups:xa,searchInputRef:fa,openSearch:en,closeSearch:da,clearSearch:Xi,stepSearchMatch:Ti,handleSearchInputChange:no,handleSelectSearchMatch:vr}=mP({files:a,activeFilePath:a[s]?.path??null,onRevealMatch:Fn}),zn=a.length>0,ha=zn||!!Ie?.diffOptions?.length||!!Ie?.worktrees?.length,an=E.useMemo(()=>Qt.length===0?u:[...u.filter(he=>he.source?!Qt.some(Fe=>Fe.source===he.source&&Fe.type===he.type&&Fe.filePath===he.filePath&&Fe.lineStart===he.lineStart&&Fe.lineEnd===he.lineEnd&&Fe.side===he.side):!0),...Qt],[u,Qt]),mi=E.useRef(an);mi.current=an;const{draftBanner:ua,restoreDraft:Ln,dismissDraft:ao}=tP({annotations:an,viewedFiles:j,isApiMode:!!Z,submitted:!!ut}),er=E.useCallback(()=>{const ee=Ln();ee.annotations.length>0&&d(ee.annotations),ee.viewedFiles.length>0&&W(new Set(ee.viewedFiles))},[Ln]),[at,io]=E.useState(!1),[fn,Yt]=E.useState([]),[Ba,Pa]=E.useState(()=>{const ee=Jr(),he=ee.providerId;return{providerId:he,model:he?ee.preferredModels[he]??null:null,reasoningEffort:null}}),[Cr,Va]=E.useState(!1),[Te,je]=E.useState(void 0),ze=iP({patch:e?.rawPatch??"",providerId:Ba.providerId,model:Ba.model,reasoningEffort:Ba.reasoningEffort});E.useEffect(()=>{fetch("/api/ai/capabilities").then(ee=>ee.ok?ee.json():null).then(ee=>{if(ee?.available){io(!0);const he=ee.providers??[];Yt(he),he.length>0&&Z8()&&Va(!0)}}).catch(()=>{})},[]);const vt=E.useCallback(ee=>{Pa(he=>{const Fe={...he,...ee};ee.providerId!==void 0&&ee.providerId!==he.providerId&&(Fe.model=ee.providerId?rO(ee.providerId):null);const We=Jr();return IA({...We,providerId:Fe.providerId}),Fe}),ze.resetSession()},[ze]),rn=E.useCallback(ee=>{if(!b||!a[s])return;const he=Math.min(b.start,b.end),Fe=Math.max(b.start,b.end),We=b.side==="additions"?"new":"old",_t=a_(a[s].patch,he,Fe,We);ze.ask({prompt:ee,filePath:a[s].path,lineStart:he,lineEnd:Fe,side:We,selectedCode:_t||void 0})},[b,a,s,ze]),pa=E.useCallback(ee=>{je("ai"),O(!0),ee&&(ja(ee),setTimeout(()=>ja(null),500))},[]),ro=E.useCallback((ee,he,Fe,We)=>{tt(ee),h({start:he,end:Fe,side:We==="new"?"additions":"deletions"})},[tt]),oo=E.useMemo(()=>{if(!b||!a[s])return[];const ee=a[s].path,he=Math.min(b.start,b.end),Fe=Math.max(b.start,b.end),We=b.side==="additions"?"new":"old";return ze.messages.filter(_t=>{const qt=_t.question;return qt.filePath===ee&&qt.side===We&&qt.lineStart!=null&&qt.lineEnd!=null&&qt.lineStart<=Fe&&qt.lineEnd>=he})},[b,a,s,ze.messages]),[Uo,ja]=E.useState(null),Fs=E.useCallback(ee=>{ja(ee),je("ai"),O(!0),setTimeout(()=>ja(null),500)},[]),Ho=E.useCallback(ee=>{ze.ask({prompt:ee})},[ze.ask]),gi=DB({storageKey:"plannotator-review-panel-width"}),Yo=DB({storageKey:"plannotator-filetree-width",defaultWidth:256,minWidth:160,maxWidth:400,side:"left"}),Ls=gi.isDragging||Yo.isDragging,Hd=E.useCallback(ee=>{kr(ee.api),ee.api.onDidActivePanelChange(Fe=>{if(!Fe||!H6(Fe.id))return;const We=uA(Fe.params);if(!We)return;const _t=Ue.current.findIndex(qt=>qt.path===We);_t!==-1&&c(_t)});const he=()=>{const We=(ee.api.totalPanels===1&&ee.api.groups.length===1?ee.api.groups[0]?.panels[0]:void 0)?.id===Cc;for(const _t of ee.api.groups)_t.header.hidden=We};ee.api.onDidAddPanel(he),ee.api.onDidRemovePanel(he),ee.api.onDidAddGroup(he),ee.api.onDidRemoveGroup(he),ee.api.onDidMovePanel(he),ee.api.onDidLayoutChange(he),he()},[]);E.useEffect(()=>{!Bn||!J.current||a.length===0||tt(a[0].path)},[Bn,a,tt]);const Ms=E.useCallback(ee=>{const he=Bn;if(!he)return;const Fe=G6(ee),We=he.getPanel(Fe);if(We){We.api.setActive();return}const _t=Kn.jobs.find(qt=>qt.id===ee);he.addPanel({id:Fe,component:br.AGENT_JOB_DETAIL,title:_t?.label??`Job ${ee.slice(0,8)}`,params:{jobId:ee}})},[Bn,Kn.jobs]),Er=E.useCallback(ee=>{const he=Bn;if(!he)return;const Fe={summary:{id:z6,component:br.PR_SUMMARY,title:"PR Summary"},comments:{id:q6,component:br.PR_COMMENTS,title:"PR Comments"},checks:{id:U6,component:br.PR_CHECKS,title:"PR Checks"}}[ee],We=he.getPanel(Fe.id);if(We){We.api.setActive();return}he.addPanel({id:Fe.id,component:Fe.component,title:Fe.title})},[Bn]);E.useEffect(()=>{const ee=he=>{if((he.metaKey||he.ctrlKey)&&he.key.toLowerCase()==="f"&&!NB(he.target)){zn&&(he.preventDefault(),en());return}if((he.key==="Enter"||he.key==="F3")&&Gn.length>0&&!Se&&!NB(he.target)){he.preventDefault(),Ti(he.shiftKey?-1:1);return}he.key==="Escape"&&(Tn?ae(!1):y?_(!1):Me?Qn?Xi():da():Qn&&Xi()),(he.metaKey||he.ctrlKey)&&he.shiftKey&&he.key==="c"&&(he.preventDefault(),Zd())};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[y,Tn,Me,Qn,Gn,Se,en,Ti,Xi,da,zn]),E.useEffect(()=>{fetch("/api/diff").then(ee=>{if(!ee.ok)throw new Error("Not in API mode");return ee.json()}).then(ee=>{ea.init(ee.serverConfig),be(ee.serverConfig?.gitUser);const he=jw(ee.rawPatch);n({files:he,rawPatch:ee.rawPatch,gitRef:ee.gitRef,origin:ee.origin,diffType:ee.diffType,gitContext:ee.gitContext,sharingEnabled:ee.sharingEnabled}),r(he),ee.origin&&ce(ee.origin),ee.diffType&&ge(ee.diffType),ee.gitContext&&Re(ee.gitContext),ee.agentCwd&&Xe(ee.agentCwd),ee.sharingEnabled!==void 0&&yn(ee.sharingEnabled),ee.repoInfo&&gn(ee.repoInfo),ee.prMetadata&&Ht(ee.prMetadata),ee.platformUser&&z(ee.platformUser),ee.viewedFiles&&ee.viewedFiles.length>0&&W(new Set(ee.viewedFiles)),ee.error&&Le(ee.error),ee.isWSL&&$(!0)}).catch(()=>{const ee=jw(eQ);n({files:ee,rawPatch:eQ,gitRef:"demo"}),r(ee)}).finally(()=>D(!1))},[]);const il=E.useCallback(ee=>{ea.set("diffStyle",ee)},[]),ya=E.useCallback(ee=>{h(ee)},[]),tr=E.useCallback((ee,he,Fe,We,_t,qt,Ia)=>{if(!b||!a[s])return;const wa=Math.min(b.start,b.end),ot=Math.max(b.start,b.end),nr={id:n_(),type:ee,scope:"line",filePath:a[s].path,lineStart:wa,lineEnd:ot,side:b.side==="additions"?"new":"old",text:he,suggestedCode:Fe,originalCode:We,...Ia&&{charStart:Ia.charStart,charEnd:Ia.charEnd,tokenText:Ia.tokenText},createdAt:Date.now(),author:la,conventionalLabel:_t,decorations:qt};d(Br=>[...Br,nr]),h(null)},[b,a,s,la]),$o=E.useCallback(ee=>{const he=a[s],Fe=ee.trim();if(!he||!Fe)return;const We={id:n_(),type:"comment",scope:"file",filePath:he.path,lineStart:1,lineEnd:1,side:"new",text:Fe,createdAt:Date.now(),author:la};d(_t=>[..._t,We])},[a,s,la]),so=E.useCallback((ee,he,Fe,We,_t,qt)=>{const Ia=mi.current.find(ot=>ot.id===ee),wa={...he!==void 0&&{text:he},...Fe!==void 0&&{suggestedCode:Fe},...We!==void 0&&{originalCode:We},..._t!==void 0&&{conventionalLabel:_t??void 0},...qt!==void 0&&{decorations:qt}};if(Ia?.source&&Qt.some(ot=>ot.id===ee)){Na(ee,wa);return}d(ot=>ot.map(nr=>nr.id===ee?{...nr,...wa}:nr))},[Na,Qt]),rl=E.useCallback(ee=>{if(mi.current.find(Fe=>Fe.id===ee)?.source&&Qt.some(Fe=>Fe.id===ee)){Ai(ee),A===ee&&g(null);return}d(Fe=>Fe.filter(We=>We.id!==ee)),A===ee&&g(null)},[A,Ai,Qt]),ol=E.useCallback((ee,he)=>{d(Fe=>Fe.map(We=>We.author===ee?{...We,author:he}:We))},[]),sl=E.useCallback(ee=>{const he=a[ee];he&&tt(he.path)},[a,tt]),Ko=E.useCallback(ee=>{const he=a[ee];he&&tt(he.path)},[a,tt]),Wo=E.useCallback(ee=>{const he=a[ee];he&&tt(he.path)},[a,tt]),Os=E.useCallback(ee=>{W(he=>{const Fe=new Set(he),We=!he.has(ee);return We?Fe.add(ee):Fe.delete(ee),He&&He.platform==="github"&&fetch("/api/pr-viewed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePaths:[ee],viewed:We})}).catch(()=>{}),Fe})},[He]),{activeWorktreePath:Fi,activeDiffBase:xr}=E.useMemo(()=>{if(pe.startsWith("worktree:")){const ee=pe.slice(9),he=ee.lastIndexOf(":");if(he!==-1){const Fe=ee.slice(he+1);if(["uncommitted","staged","unstaged","last-commit","branch"].includes(Fe))return{activeWorktreePath:ee.slice(0,he),activeDiffBase:Fe}}return{activeWorktreePath:ee,activeDiffBase:"uncommitted"}}return{activeWorktreePath:null,activeDiffBase:pe}},[pe]),om=E.useCallback(ee=>W(he=>new Set(he).add(ee)),[]),{stagedFiles:Zo,stagingFile:Yd,canStageFiles:sm,stageFile:$d,resetStagedFiles:Kd,stageError:Wd}=aP({activeDiffBase:xr,onFileViewed:om}),cl=sm&&!He,Ps=E.useCallback(async ee=>{Et(!0);try{const he=await fetch("/api/diff/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({diffType:ee})});if(!he.ok)throw new Error("Failed to switch diff");const Fe=await he.json(),We=jw(Fe.rawPatch);Bn?.getPanel(Cc)?.api.close(),J.current=!0,r(We),ge(Fe.diffType),c(0),h(null),Le(Fe.error||null),Kd()}catch(he){console.error("Failed to switch diff:",he),Le(he instanceof Error?he.message:"Failed to switch diff")}finally{Et(!1)}},[Bn,Kd]),cm=E.useCallback(async ee=>{const he=Fi?`worktree:${Fi}:${ee}`:ee;he!==pe&&await Ps(he)},[pe,Fi,Ps]),lm=E.useCallback(async ee=>{if(ee===Fi)return;const he=ee?`worktree:${ee}:uncommitted`:"uncommitted";await Ps(he)},[Fi,Ps]),ll=E.useCallback(ee=>{if(!ee){g(null);return}const he=an.find(We=>We.id===ee);if(!he){g(ee);return}const Fe=a.findIndex(We=>We.path===he.filePath);Fe!==-1&&Wo(Fe),g(ee)},[an,a,Wo]),dl=E.useMemo(()=>({files:a,focusedFileIndex:s,focusedFilePath:a[s]?.path??null,diffStyle:R,diffOverflow:N,diffIndicators:F,lineDiffType:P,disableLineNumbers:!T,disableBackground:!L,fontFamily:Y||void 0,fontSize:V||void 0,allAnnotations:an,externalAnnotations:Qt,selectedAnnotationId:A,pendingSelection:b,onLineSelection:ya,onAddAnnotation:tr,onAddFileComment:$o,onEditAnnotation:so,onSelectAnnotation:ll,onDeleteAnnotation:rl,viewedFiles:j,onToggleViewed:Os,stagedFiles:Zo,stagingFile:Yd,onStage:$d,canStageFiles:cl,stageError:Wd,searchQuery:Se?"":jn,isSearchPending:Se,debouncedSearchQuery:jn,activeFileSearchMatches:wn,activeSearchMatchId:At,activeSearchMatch:Ot?.filePath===a[s]?.path?Ot:null,aiAvailable:at,aiMessages:ze.messages,onAskAI:rn,isAILoading:ze.isCreatingSession||ze.isStreaming,onViewAIResponse:pa,onClickAIMarker:Fs,aiHistoryForSelection:oo,agentJobs:Kn.jobs,prMetadata:He,prContext:Ee,isPRContextLoading:Oe,prContextError:Mt,fetchPRContext:nn,platformUser:ke,openDiffFile:tt}),[a,s,R,N,F,P,T,L,Y,V,an,Qt,A,b,ya,tr,$o,so,ll,rl,j,Os,Zo,Yd,$d,cl,Wd,Se,jn,wn,At,Ot,at,ze.messages,ze.isCreatingSession,ze.isStreaming,rn,pa,Fs,oo,Kn.jobs,He,Ee,Oe,Mt,nn,ke,tt]),dm=E.useMemo(()=>({jobLogs:Kn.jobLogs}),[Kn.jobLogs]),Zd=E.useCallback(async()=>{if(e)try{await navigator.clipboard.writeText(e.rawPatch),de("success"),setTimeout(()=>de("idle"),2e3)}catch(ee){console.error("Failed to copy:",ee),de("error"),setTimeout(()=>de("idle"),2e3)}},[e]),um=E.useCallback(async()=>{if(an.length===0){I(!0);return}try{const ee=w_(an,He);await navigator.clipboard.writeText(ee),te("Feedback copied!"),setTimeout(()=>te(null),2e3)}catch(ee){console.error("Failed to copy:",ee),te("Failed to copy"),setTimeout(()=>te(null),2e3)}},[an,He]),co=E.useMemo(()=>{let ee=w_(an,He);return Dn.length>0&&(ee+=xP(Dn)),ee},[an,He,Dn]),qn=an.length+Dn.length,ul=E.useCallback(async()=>{if(qn===0){I(!0);return}dt(!0);try{const ee=Kp(),he=iB(ee);if((await fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({approved:!1,feedback:co,annotations:an,...he&&{agentSwitch:he}})})).ok)yt("feedback");else throw new Error("Failed to send")}catch(ee){console.error("Failed to send feedback:",ee),te("Failed to send"),setTimeout(()=>te(null),2e3),dt(!1)}},[qn,co,an]),js=E.useCallback(async()=>{et(!0);try{if((await fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({approved:!0,feedback:"LGTM - no changes requested.",annotations:[]})})).ok)yt("approved");else throw new Error("Failed to send")}catch(ee){console.error("Failed to approve:",ee),te("Failed to send"),setTimeout(()=>te(null),2e3),et(!1)}},[]),Vd=E.useCallback((ee,he)=>{const Fe=an.filter(ot=>(ot.scope??"line")==="line"),We=an.filter(ot=>ot.scope==="file"),_t=[];if(We.length>0)for(const ot of We)ot.text&&_t.push(`**${ot.filePath}:** ${ot.text}`);const qt=_t.length>0?`${he?he+`
6367
6367
 
6368
6368
  `:""}Review from Plannotator
6369
6369