@plannotator/opencode 0.17.6 → 0.17.7

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.
package/dist/index.js CHANGED
@@ -30045,6 +30045,14 @@ function stripConflictingPlanModeRules(systemEntries) {
30045
30045
  }
30046
30046
 
30047
30047
  // index.ts
30048
+ var _proto = Object.getPrototypeOf(Response.prototype);
30049
+ if (_proto?.constructor && _proto.constructor !== Response && _proto.constructor !== Object) {
30050
+ globalThis.Response = _proto.constructor;
30051
+ const _reqProto = Object.getPrototypeOf(Request.prototype);
30052
+ if (_reqProto?.constructor && _reqProto.constructor !== Request && _reqProto.constructor !== Object) {
30053
+ globalThis.Request = _reqProto.constructor;
30054
+ }
30055
+ }
30048
30056
  var _planHtml = null;
30049
30057
  var _reviewHtml = null;
30050
30058
  function getPlanHtml() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plannotator/opencode",
3
- "version": "0.17.6",
3
+ "version": "0.17.7",
4
4
  "description": "Plannotator plugin for OpenCode - interactive plan review with visual annotation",
5
5
  "author": "backnotprop",
6
6
  "license": "MIT OR Apache-2.0",
@@ -38,7 +38,7 @@
38
38
  "@opencode-ai/plugin": "^1.1.10"
39
39
  },
40
40
  "devDependencies": {
41
- "@plannotator/server": "0.17.6",
41
+ "@plannotator/server": "0.17.7",
42
42
  "@plannotator/shared": "0.0.1"
43
43
  },
44
44
  "peerDependencies": {
package/plannotator.html CHANGED
@@ -508,7 +508,7 @@ created: ${new Date().toISOString().slice(0,19)}Z
508
508
  source: plannotator
509
509
  tags: [plan, ...]
510
510
  ---`})]}),w.jsx("div",{className:"border-t border-border/30"}),w.jsxs("div",{className:"flex items-center justify-between",children:[w.jsxs("div",{children:[w.jsx("div",{className:"text-xs font-medium",children:"Auto-save on Plan Arrival"}),w.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Automatically save to Obsidian when a plan loads, before you approve or deny"})]}),w.jsx("button",{role:"switch","aria-checked":Q.autoSave,onClick:()=>zA({autoSave:!Q.autoSave}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${Q.autoSave?"bg-primary":"bg-muted"}`,children:w.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${Q.autoSave?"translate-x-6":"translate-x-1"}`})})]}),w.jsxs("div",{className:"flex items-center justify-between",children:[w.jsxs("div",{children:[w.jsx("div",{className:"text-xs font-medium",children:"Vault Browser"}),w.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Browse and annotate vault files from the sidebar"})]}),w.jsx("button",{role:"switch","aria-checked":Q.vaultBrowserEnabled,onClick:()=>zA({vaultBrowserEnabled:!Q.vaultBrowserEnabled}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${Q.vaultBrowserEnabled?"bg-primary":"bg-muted"}`,children:w.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${Q.vaultBrowserEnabled?"translate-x-6":"translate-x-1"}`})})]})]})]})]}),C==="bear"&&w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"flex items-center justify-between",children:[w.jsxs("div",{children:[w.jsx("div",{className:"text-sm font-medium",children:"Bear Notes"}),w.jsx("div",{className:"text-xs text-muted-foreground",children:"Auto-save approved plans to Bear"})]}),w.jsx("button",{role:"switch","aria-checked":k.enabled,onClick:()=>le({enabled:!k.enabled}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${k.enabled?"bg-primary":"bg-muted"}`,children:w.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${k.enabled?"translate-x-6":"translate-x-1"}`})})]}),k.enabled&&w.jsxs("div",{className:"mt-3 space-y-3",children:[w.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[w.jsx("label",{className:"text-xs text-muted-foreground",children:"Custom Tags"}),w.jsx("input",{type:"text",value:k.customTags,onChange:hA=>le({customTags:hA.target.value}),onBlur:hA=>le({customTags:TYA(hA.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"}),w.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Comma-separated, kebab-case. Leave empty for auto-generated tags."})]}),w.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[w.jsx("label",{className:"text-xs text-muted-foreground",children:"Tag Position"}),w.jsxs("select",{value:k.tagPosition,onChange:hA=>le({tagPosition:hA.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:[w.jsx("option",{value:"append",children:"Append (end of note)"}),w.jsx("option",{value:"prepend",children:"Prepend (after title)"})]})]}),w.jsx("div",{className:"border-t border-border/30"}),w.jsxs("div",{className:"flex items-center justify-between",children:[w.jsxs("div",{children:[w.jsx("div",{className:"text-xs font-medium",children:"Auto-save on Plan Arrival"}),w.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Automatically save to Bear when a plan loads, before you approve or deny"})]}),w.jsx("button",{role:"switch","aria-checked":k.autoSave,onClick:()=>le({autoSave:!k.autoSave}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${k.autoSave?"bg-primary":"bg-muted"}`,children:w.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${k.autoSave?"translate-x-6":"translate-x-1"}`})})]})]})]}),C==="octarine"&&w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"flex items-center justify-between",children:[w.jsxs("div",{children:[w.jsx("div",{className:"text-sm font-medium",children:"Octarine"}),w.jsx("div",{className:"text-xs text-muted-foreground",children:"Auto-save approved plans to Octarine"})]}),w.jsx("button",{role:"switch","aria-checked":b.enabled,onClick:()=>MA({enabled:!b.enabled}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${b.enabled?"bg-primary":"bg-muted"}`,children:w.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${b.enabled?"translate-x-6":"translate-x-1"}`})})]}),b.enabled&&w.jsxs("div",{className:"mt-3 space-y-3",children:[w.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[w.jsx("label",{className:"text-xs text-muted-foreground",children:"Workspace Name"}),w.jsx("input",{type:"text",value:b.workspace,onChange:hA=>MA({workspace:hA.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"}),w.jsx("div",{className:"text-[10px] text-muted-foreground",children:"The Octarine workspace name to save plans into."})]}),w.jsxs("div",{className:"space-y-1.5 pl-0.5",children:[w.jsx("label",{className:"text-xs text-muted-foreground",children:"Folder"}),w.jsx("input",{type:"text",value:b.folder,onChange:hA=>MA({folder:hA.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"}),w.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Subfolder within the workspace for saved plans."})]}),w.jsxs("div",{className:"text-[10px] text-muted-foreground/70",children:["Plans saved to: ",b.workspace||"..."," / ",b.folder||"plannotator","/"]}),w.jsx("div",{className:"border-t border-border/30"}),w.jsxs("div",{className:"flex items-center justify-between",children:[w.jsxs("div",{children:[w.jsx("div",{className:"text-xs font-medium",children:"Auto-save on Plan Arrival"}),w.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Automatically save to Octarine when a plan loads, before you approve or deny"})]}),w.jsx("button",{role:"switch","aria-checked":b.autoSave,onClick:()=>MA({autoSave:!b.autoSave}),className:`relative inline-flex h-6 w-11 flex-shrink-0 items-center rounded-full transition-colors ${b.autoSave?"bg-primary":"bg-muted"}`,children:w.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${b.autoSave?"translate-x-6":"translate-x-1"}`})})]})]})]})]})})]})]})}),document.body)]})},kZ=({onClick:e,disabled:A=!1,isLoading:t=!1,label:i="Send Feedback",shortLabel:r,loadingLabel:n="Sending...",shortLoadingLabel:a,title:s="Send Feedback",muted:o=!1})=>w.jsxs("button",{onClick:e,disabled:A,className:`p-1.5 md:px-2.5 md:py-1 rounded-md text-xs font-medium transition-all ${o?"opacity-50 cursor-not-allowed bg-accent/10 text-accent/50":A?"opacity-50 cursor-not-allowed bg-muted text-muted-foreground":"bg-accent/15 text-accent hover:bg-accent/25 border border-accent/30"}`,title:s,children:[w.jsx("svg",{className:"w-4 h-4 md:hidden",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.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?w.jsxs(w.Fragment,{children:[w.jsx("span",{className:"hidden md:inline lg:hidden",children:t?a??n:r}),w.jsx("span",{className:"hidden lg:inline",children:t?n:i})]}):w.jsx("span",{className:"hidden md:inline",children:t?n:i})]}),xZ=({onClick:e,disabled:A=!1,isLoading:t=!1,label:i="Approve",loadingLabel:r="Approving...",mobileLabel:n="OK",mobileLoadingLabel:a="...",title:s,dimmed:o=!1,muted:g=!1})=>w.jsxs("button",{onClick:e,disabled:A,className:`px-2 py-1 md:px-2.5 rounded-md text-xs font-medium transition-all ${g?"opacity-40 cursor-not-allowed bg-muted text-muted-foreground":A?"opacity-50 cursor-not-allowed bg-muted text-muted-foreground":o?"bg-success/50 text-success-foreground/70 hover:bg-success hover:text-success-foreground":"bg-success text-success-foreground hover:opacity-90"}`,title:s,children:[w.jsx("span",{className:"md:hidden",children:t?a:n}),w.jsx("span",{className:"hidden md:inline",children:t?r:i})]});async function mIA(e){const A=JSON.stringify(e),t=new TextEncoder().encode(A),i=new CompressionStream("deflate-raw"),r=i.writable.getWriter();r.write(t),r.close();const n=await new Response(i.readable).arrayBuffer(),a=new Uint8Array(n);let s="";for(let g=0;g<a.length;g++)s+=String.fromCharCode(a[g]);return btoa(s).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}async function DS(e){const A=e.replace(/-/g,"+").replace(/_/g,"/"),t=atob(A),i=Uint8Array.from(t,o=>o.charCodeAt(0)),r=new DecompressionStream("deflate-raw"),n=r.writable.getWriter();n.write(i),n.close();const a=await new Response(r.readable).arrayBuffer(),s=new TextDecoder().decode(a);return JSON.parse(s)}async function U8A(e){const A=await crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt"]),t=crypto.getRandomValues(new Uint8Array(12)),i=new TextEncoder().encode(e),r=await crypto.subtle.encrypt({name:"AES-GCM",iv:t},A,i),n=new Uint8Array(t.length+r.byteLength);n.set(t,0),n.set(new Uint8Array(r),t.length);const a=await crypto.subtle.exportKey("raw",A);return{ciphertext:LZ(n),key:LZ(new Uint8Array(a))}}async function K8A(e,A){const t=TZ(e),i=TZ(A),r=t.slice(0,12),n=t.slice(12),a=await crypto.subtle.importKey("raw",i.buffer,{name:"AES-GCM",length:256},!1,["decrypt"]),s=await crypto.subtle.decrypt({name:"AES-GCM",iv:r},a,n);return new TextDecoder().decode(s)}function LZ(e){let A="";for(let t=0;t<e.length;t++)A+=String.fromCharCode(e[t]);return btoa(A).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function TZ(e){const A=e.replace(/-/g,"+").replace(/_/g,"/"),t=atob(A);return Uint8Array.from(t,i=>i.charCodeAt(0))}function Ed(e){if(e?.length)return e.map(A=>{if(typeof A=="string"){const t=A.split("/").pop()?.replace(/\.[^.]+$/,"")||"image";return{path:A,name:t}}return{path:A[0],name:A[1]}})}function m5(e){if(e?.length)return e.map(A=>[A.path,A.name])}function yIA(e){return e.map(A=>{const t=A.author||null,i=m5(A.images);return A.type===oi.GLOBAL_COMMENT?["G",A.text||"",t,i]:A.type===oi.DELETION?["D",A.originalText,t,i]:A.isQuickLabel?["C",A.originalText,A.text||"",t,i??void 0,1]:["C",A.originalText,A.text||"",t,i]})}function Sw(e,A,t){const i={D:oi.DELETION,C:oi.COMMENT,G:oi.GLOBAL_COMMENT};return e.map((r,n)=>{const a=r[0];if(a==="G"){const C=r[1],E=r[2],u=r[3];return{id:`shared-${n}-${Date.now()}`,blockId:"",startOffset:0,endOffset:0,type:oi.GLOBAL_COMMENT,text:C||void 0,originalText:"",createdA:Date.now()+n,author:E||void 0,images:Ed(u),...t?.[n]?{source:t[n]}:{}}}const s=r[1],o=a==="D"?void 0:r[2],g=a==="D"?r[2]:r[3],l=a==="D"?r[3]:r[4],I=a==="C"&&r.length>5&&r[5]===1?!0:void 0;return{id:`shared-${n}-${Date.now()}`,blockId:"",startOffset:0,endOffset:0,type:i[a],text:o||void 0,originalText:s,createdA:Date.now()+n,author:g||void 0,images:Ed(l),...I?{isQuickLabel:I}:{},...A?.[n]?{diffContext:A[n]}:{},...t?.[n]?{source:t[n]}:{}}})}function DIA(e){const A=e.map(t=>t.diffContext||null);return A.some(t=>t!==null)?A:null}function wIA(e){const A=e.map(t=>t.source||void 0);return A.some(t=>t!==void 0)?A:null}async function Y8A(e,A,t,i=SIA){const r=DIA(A),n=wIA(A),a={p:e,a:yIA(A),g:t?.length?m5(t):void 0,...r?{d:r}:{},...n?{s:n}:{}},s=await mIA(a);return`${i}/#${s}`}async function H8A(){const A=window.location.hash.slice(1).split("?")[0];if(!A)return null;try{return await DS(A)}catch(t){return console.warn("Failed to parse share hash:",t),null}}function P8A(e){const A=new Blob([e]).size;return A<1024?`${A} B`:`${(A/1024).toFixed(1)} KB`}const vIA="https://plannotator-paste.plannotator.workers.dev",SIA="https://share.plannotator.ai";async function J8A(e,A,t,i){const r=i?.pasteApiUrl??vIA,n=i?.shareBaseUrl??SIA;try{const a=DIA(A),s=wIA(A),o={p:e,a:yIA(A),g:t?.length?m5(t):void 0,...a?{d:a}:{},...s?{s}:{}},g=await mIA(o),{ciphertext:l,key:I}=await U8A(g),C=await fetch(`${r}/api/paste`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:l}),signal:AbortSignal.timeout(5e3)});if(!C.ok)return console.warn(`[sharing] Paste service returned ${C.status}`),null;const E=await C.json();return{shortUrl:`${n}/p/${E.id}#key=${I}`,id:E.id}}catch(a){return console.debug("[sharing] Short URL service unavailable, using hash-based sharing:",a),null}}async function FZ(e,A=vIA,t){try{const i=await fetch(`${A}/api/paste/${e}`,{signal:AbortSignal.timeout(1e4)});if(!i.ok)return console.warn(`[sharing] Paste fetch returned ${i.status} for id ${e}`),null;const r=await i.json();if(t){const n=await K8A(r.data,t);return await DS(n)}return await DS(r.data)}catch(i){return console.warn("[sharing] Failed to load from paste ID:",i),null}}function z8A(e,A,t,i,r,n,a,s,o){const[g,l]=aA.useState(!1),[I,C]=aA.useState(!0),[E,u]=aA.useState(""),[d,Q]=aA.useState(""),[f,p]=aA.useState(""),[y,D]=aA.useState(!1),[S,k]=aA.useState(""),[R,b]=aA.useState(null),[N,T]=aA.useState(null),[L,K]=aA.useState(""),H=aA.useCallback(()=>{b(null),T(null)},[]),x=aA.useCallback(()=>K(""),[]),U=aA.useCallback(async()=>{try{const P=window.location.pathname.match(/^\/p\/([A-Za-z0-9]{6,16})$/);if(P){const z=P[1],j=window.location.hash.slice(1),X=j.startsWith("key=")?j.slice(4):void 0,_=await FZ(z,o,X);if(_){i(_.p);const gA=Sw(_.a,_.d,_.s);if(r(gA),_.g?.length){const dA=Ed(_.g)??[];n(dA),T(dA)}b(gA),l(!0),a?.();const eA=window.location.pathname.replace(/\/p\/[A-Za-z0-9]+$/,"")||"/";return window.history.replaceState({},"",eA),!0}return K("Failed to load shared plan — the link may be expired or incomplete."),!1}const q=window.location.hash.slice(1),Y=await H8A();if(Y){i(Y.p);const z=Sw(Y.a,Y.d,Y.s);if(r(z),Y.g?.length){const j=Ed(Y.g)??[];n(j),T(j)}return b(z),l(!0),a?.(),window.history.replaceState({},"",window.location.pathname),!0}return q&&K("Failed to load shared plan — the URL may have been truncated by your browser."),!1}catch(P){return console.error("Failed to load from share hash:",P),K("Failed to load shared plan — an unexpected error occurred."),!1}},[i,r,n,a,o]);aA.useEffect(()=>{U().finally(()=>C(!1))},[]),aA.useEffect(()=>{const P=()=>{window.location.hash.length>1&&U()};return window.addEventListener("hashchange",P),()=>window.removeEventListener("hashchange",P)},[U]);const G=aA.useCallback(async()=>{try{const P=await Y8A(e,A,t,s);u(P),Q(P8A(P))}catch(P){console.error("Failed to generate share URL:",P),u(""),Q("")}},[e,A,t,s]);aA.useEffect(()=>{G()},[G]),aA.useEffect(()=>{p(""),k("")},[e,A]);const F=aA.useCallback(async()=>{if(e){D(!0),k("");try{const P=await J8A(e,A,t,{pasteApiUrl:o,shareBaseUrl:s});P?p(P.shortUrl):(p(""),k("Short URL service unavailable"))}catch{p(""),k("Failed to generate short URL")}finally{D(!1)}}},[e,A,t,s,o]),O=aA.useCallback(async P=>{try{let q;const Y=P.match(/\/p\/([A-Za-z0-9]{6,16})(?:#key=([A-Za-z0-9_-]+))?(?:\?|#|$)/);if(Y){const eA=Y[1],dA=Y[2],tA=await FZ(eA,o,dA);if(!tA)return{success:!1,count:0,planTitle:"",error:"Failed to load from short URL — paste may have expired"};q=tA}else{const eA=P.indexOf("#");if(eA===-1)return{success:!1,count:0,planTitle:"",error:"Invalid share URL: no hash fragment or short link found"};const dA=P.slice(eA+1);if(!dA)return{success:!1,count:0,planTitle:"",error:"Invalid share URL: empty hash"};q=await DS(dA)}const j=(q.p||"").trim().split(`
511
- `).find(eA=>eA.startsWith("#")),X=j?j.replace(/^#+\s*/,"").trim():"Unknown Plan",_=Sw(q.a,q.d,q.s);if(_.length===0)return{success:!0,count:0,planTitle:X,error:"No annotations found in share link"};const gA=_.filter(eA=>!A.some(dA=>dA.originalText===eA.originalText&&dA.type===eA.type&&dA.text===eA.text));if(gA.length>0&&(r(eA=>{const dA=_.filter(oA=>!eA.some(nA=>nA.originalText===oA.originalText&&nA.type===oA.type&&nA.text===oA.text));if(dA.length===0)return eA;const tA=[...eA,...dA];return b(tA),tA}),q.g?.length)){const eA=Ed(q.g)??[];n(dA=>{const tA=new Set(dA.map(nA=>nA.path)),oA=eA.filter(nA=>!tA.has(nA.path));return oA.length>0?[...dA,...oA]:dA}),T(eA)}return{success:!0,count:gA.length,planTitle:X}}catch(q){return{success:!1,count:0,planTitle:"",error:q instanceof Error?q.message:"Failed to decompress share URL"}}},[A,t,r,n,o]);return{isSharedSession:g,isLoadingShared:I,shareUrl:E,shareUrlSize:d,shortShareUrl:f,isGeneratingShortUrl:y,shortUrlError:S,pendingSharedAnnotations:R,sharedGlobalAttachments:N,clearPendingSharedAnnotations:H,refreshShareUrl:G,generateShortUrl:F,importFromShareUrl:O,shareLoadError:L,clearShareLoadError:x}}var bw=(e=>(e.Approve="approve",e.Feedback="feedback",e))(bw||{});function q8A(e=window.location){const A=new URLSearchParams(e.search);let t=A.get("cb"),i=A.get("ct");if(!t||!i){const r=e.hash.indexOf("?");if(r!==-1){const n=new URLSearchParams(e.hash.slice(r+1));t=t??n.get("cb"),i=i??n.get("ct")}}if(!t||!i)return null;try{const{protocol:r}=new URL(t);if(r!=="https:"&&r!=="http:")return null}catch{return null}return{callbackUrl:t,token:i}}async function W8A(e,A,t){const i=e==="approve"?"Plan approved! The bot will proceed to implementation.":"Feedback sent! The bot will re-plan with your annotations.";try{const r=await fetch(A.callbackUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e,token:A.token,annotated_url:t})});return r.ok?{type:"success",message:i}:{type:"error",message:r.status===401?"Plan link expired — request a new one from the bot.":"Callback failed."}}catch{return{type:"error",message:"Callback failed."}}}function V8A(e,A,t){const[i,r]=aA.useState(null),n=aA.useRef(null);return aA.useEffect(()=>{const a=t??e.current;if(!a)return;const s=a.querySelectorAll('[data-block-type="heading"]');if(s.length===0)return;const o=new Map;return n.current=new IntersectionObserver(g=>{g.forEach(C=>{o.set(C.target,C.isIntersecting)});let l=null,I=1/0;for(const[C,E]of o)if(E){const u=C.getBoundingClientRect();u.top<I&&(I=u.top,l=C)}if(l){const C=l.getAttribute("data-block-id");C&&r(C)}},{root:a,rootMargin:"-80px 0px -80% 0px",threshold:[0,.1,.5,1]}),s.forEach(g=>{n.current?.observe(g)}),()=>{n.current?.disconnect()}},[e,A,t]),i}function GZ(e){window.close(),setTimeout(()=>{window.closed||e()},300)}function Z8A(e){const[A,t]=aA.useState({phase:"idle"});aA.useEffect(()=>{if(!e)return;const r=yiA();r==="0"?(GZ(()=>t({phase:"closeFailed"})),t({phase:"closed"})):t(r!=="off"?{phase:"counting",remaining:Number(r)}:{phase:"prompt"})},[e]),aA.useEffect(()=>{if(A.phase!=="counting")return;if(A.remaining<=0){GZ(()=>t({phase:"closeFailed"}));return}const r=setTimeout(()=>t(n=>n.phase==="counting"?{phase:"counting",remaining:n.remaining-1}:n),1e3);return()=>clearTimeout(r)},[A]);const i=aA.useCallback(()=>{DiA("3"),t({phase:"counting",remaining:3})},[]);return{state:A,enableAndStart:i}}const j8A=()=>w.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),_8A=()=>w.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:w.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 X8A({submitted:e,title:A,subtitle:t,agentLabel:i}){const{state:r,enableAndStart:n}=Z8A(!!e);if(!e)return null;const a=e==="approved";return w.jsx("div",{className:"fixed inset-0 z-[100] bg-background flex items-center justify-center",children:w.jsxs("div",{className:"text-center space-y-6 max-w-md px-8",children:[w.jsx("div",{className:`mx-auto w-16 h-16 rounded-full flex items-center justify-center ${a?"bg-success/20 text-success":"bg-accent/20 text-accent"}`,children:a?w.jsx(j8A,{}):w.jsx(_8A,{})}),w.jsxs("div",{className:"space-y-2",children:[w.jsx("h2",{className:"text-xl font-semibold text-foreground",children:A}),w.jsx("p",{className:"text-muted-foreground",children:t})]}),w.jsx("div",{className:"pt-4 border-t border-border space-y-2",children:r.phase==="counting"?w.jsxs(w.Fragment,{children:[w.jsxs("p",{className:"text-sm text-muted-foreground",children:["This tab will close in ",w.jsx("span",{className:"text-foreground font-medium",children:r.remaining})," second",r.remaining!==1?"s":"","..."]}),w.jsx("p",{className:"text-xs text-muted-foreground/60",children:"You can change this in Settings."})]}):r.phase==="closeFailed"?w.jsxs(w.Fragment,{children:[w.jsx("p",{className:"text-sm text-muted-foreground",children:"Could not close this tab automatically. Please close it manually."}),w.jsxs("p",{className:"text-xs text-muted-foreground/60",children:["Auto-close works when the tab is opened by ",i,"."]})]}):w.jsxs(w.Fragment,{children:[w.jsxs("p",{className:"text-sm text-muted-foreground",children:["You can close this tab and return to ",w.jsx("span",{className:"text-foreground font-medium",children:i}),"."]}),r.phase==="prompt"?w.jsxs(w.Fragment,{children:[w.jsxs("label",{className:"flex items-center justify-center gap-2 cursor-pointer group",children:[w.jsx("input",{type:"checkbox",checked:!1,onChange:n,className:"accent-primary"}),w.jsx("span",{className:"text-xs text-muted-foreground group-hover:text-foreground transition-colors",children:"Auto-close this tab after 3 seconds"})]}),w.jsx("p",{className:"text-xs text-muted-foreground/60",children:"You can change the delay in Settings."})]}):w.jsx("p",{className:"text-xs text-muted-foreground/60",children:"Your response has been sent."})]})})]})})}const $8A="https://api.github.com/repos/backnotprop/plannotator/releases/latest",OZ={"0.5.0":{title:"Code Review is here!",description:"Review git diffs with inline annotations. Run /plannotator-review to try it."}};function A9A(e,A){const t=n=>n.replace(/^v/,""),i=t(e).split(".").map(Number),r=t(A).split(".").map(Number);for(let n=0;n<Math.max(i.length,r.length);n++){const a=i[n]||0,s=r[n]||0;if(s>a)return!0;if(s<a)return!1}return!1}function e9A(){const[e,A]=aA.useState(null);return aA.useEffect(()=>{(async()=>{try{const i="0.17.6",n=new URLSearchParams(window.location.search).get("preview-update");if(n){const C=n.replace(/^v/,"");A({currentVersion:i,latestVersion:n,updateAvailable:!0,releaseUrl:`https://github.com/backnotprop/plannotator/releases/tag/v${C}`,featureHighlight:OZ[C]});return}const a=await fetch($8A);if(!a.ok)return;const s=await a.json(),o=s.tag_name,g=A9A(i,o),l=o.replace(/^v/,""),I=OZ[l];A({currentVersion:i,latestVersion:o,updateAvailable:g,releaseUrl:s.html_url,featureHighlight:I})}catch(i){console.debug("Update check failed:",i)}})()},[]),e}const t9A="pi install npm:@plannotator/pi-extension";function i9A(e){return lSA&&!e?'powershell -c "irm https://plannotator.ai/install.ps1 | iex"':"curl -fsSL https://plannotator.ai/install.sh | bash"}const r9A=({origin:e,isWSL:A=!1})=>{const t=e9A(),[i,r]=aA.useState(!1),[n,a]=aA.useState(!1),g=new URLSearchParams(window.location.search).get("preview-origin")||e,l=g==="pi",I=g==="opencode",C=l?t9A:i9A(A);if(!t?.updateAvailable||n)return null;const E=async()=>{try{await navigator.clipboard.writeText(C),r(!0),setTimeout(()=>r(!1),2e3)}catch(d){console.error("Failed to copy:",d)}};return t.featureHighlight?w.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:w.jsxs("div",{className:"bg-card border border-primary/30 rounded-xl shadow-2xl overflow-hidden",children:[w.jsx("div",{className:"bg-gradient-to-r from-primary/20 to-primary/5 px-5 py-4 border-b border-border/50",children:w.jsxs("div",{className:"flex items-start justify-between gap-3",children:[w.jsxs("div",{className:"flex items-center gap-3",children:[w.jsx("div",{className:"flex-shrink-0 w-10 h-10 rounded-lg bg-primary/20 flex items-center justify-center",children:w.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.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"})})}),w.jsxs("div",{children:[w.jsx("h4",{className:"text-base font-semibold text-foreground",children:t.featureHighlight.title}),w.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["New in ",t.latestVersion]})]})]}),w.jsx("button",{onClick:()=>a(!0),className:"text-muted-foreground hover:text-foreground transition-colors p-1",children:w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})}),w.jsxs("div",{className:"px-5 py-4",children:[w.jsx("p",{className:"text-sm text-foreground/80 leading-relaxed",children:t.featureHighlight.description}),w.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:["You have ",t.currentVersion]}),I&&w.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Run the install script, then restart OpenCode."}),l&&w.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Run the install command, then restart Pi."}),w.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[w.jsx("button",{onClick:E,className:"flex-1 px-4 py-2 text-sm font-medium bg-primary text-primary-foreground rounded-lg hover:opacity-90 transition-opacity",children:i?"Copied!":"Copy install command"}),w.jsx("a",{href:t.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"})]})]})]})}):w.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:w.jsx("div",{className:"bg-card border border-border rounded-lg shadow-xl p-4",children:w.jsxs("div",{className:"flex items-start gap-3",children:[w.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-primary/20 flex items-center justify-center",children:w.jsx("svg",{className:"w-4 h-4 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.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"})})}),w.jsxs("div",{className:"flex-1 min-w-0",children:[w.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Update available"}),w.jsx("button",{onClick:()=>a(!0),className:"text-muted-foreground hover:text-foreground transition-colors",children:w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),w.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[t.latestVersion," is available (you have ",t.currentVersion,")"]}),w.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[w.jsx("button",{onClick:E,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:i?"Copied!":"Copy install command"}),w.jsx("a",{href:t.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"})]})]})]})})})},bIA="plannotator-editor-mode",n9A="selection";function a9A(){const e=Ke.getItem(bIA);return e==="selection"||e==="comment"||e==="redline"||e==="quickLabel"?e:n9A}function s9A(e){Ke.setItem(bIA,e)}const RIA="plannotator-input-method",o9A="drag";function g9A(){const e=Ke.getItem(RIA);return e==="drag"||e==="pinpoint"?e:o9A}function l9A(e){Ke.setItem(RIA,e)}const c9A=300,I9A=300;function C9A(e,A){const t=aA.useRef("idle"),i=aA.useRef(0),r=aA.useRef(void 0),n=aA.useRef(e);aA.useEffect(()=>{t.current==="idle"&&(n.current=e)},[e]);const a=aA.useCallback(s=>s==="drag"?"pinpoint":"drag",[]);aA.useEffect(()=>{const s=g=>{if(g.key!=="Alt"||g.repeat)return;const l=g.target?.tagName;l==="INPUT"||l==="TEXTAREA"||g.target?.isContentEditable||document.querySelector("[data-quick-label-picker]")||(t.current==="idle"?(n.current=e,i.current=Date.now(),t.current="held",A(a(e))):t.current==="tapped"&&(clearTimeout(r.current),t.current="idle",n.current=a(n.current)))},o=g=>{g.key==="Alt"&&t.current==="held"&&(Date.now()-i.current>=I9A?(A(n.current),t.current="idle"):(t.current="tapped",r.current=setTimeout(()=>{t.current==="tapped"&&(A(n.current),t.current="idle")},c9A)))};return window.addEventListener("keydown",s),window.addEventListener("keyup",o),()=>{clearTimeout(r.current),window.removeEventListener("keydown",s),window.removeEventListener("keyup",o)}},[e,A,a])}function E9A(){aA.useEffect(()=>{const e=()=>document.documentElement.classList.add("plannotator-print"),A=()=>document.documentElement.classList.remove("plannotator-print"),t=()=>{!document.hidden&&document.documentElement.classList.contains("plannotator-print")&&document.documentElement.classList.remove("plannotator-print")};return window.addEventListener("beforeprint",e),window.addEventListener("afterprint",A),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("beforeprint",e),window.removeEventListener("afterprint",A),document.removeEventListener("visibilitychange",t),document.documentElement.classList.remove("plannotator-print")}},[])}function UZ({storageKey:e,defaultWidth:A=288,minWidth:t=200,maxWidth:i=600,side:r="right"}){const[n,a]=aA.useState(()=>{const Q=Ke.getItem(e);if(Q){const f=Number(Q);if(!Number.isNaN(f)&&f>=t&&f<=i)return f}return A}),[s,o]=aA.useState(!1),g=aA.useRef(0),l=aA.useRef(0),I=aA.useRef(n),C=aA.useCallback(Q=>{I.current=Q,a(Q)},[]),E=aA.useCallback(Q=>{Q.preventDefault(),g.current=Q.clientX,l.current=I.current,o(!0)},[]),u=aA.useCallback(Q=>{Q.preventDefault(),g.current=Q.touches[0].clientX,l.current=I.current,o(!0)},[]);aA.useEffect(()=>{if(!s)return;const Q=y=>"touches"in y?y.touches[0]?.clientX??y.changedTouches[0]?.clientX??0:y.clientX,f=y=>{const D=Q(y),S=r==="right"?g.current-D:D-g.current;C(Math.min(i,Math.max(t,l.current+S)))},p=()=>{o(!1),Ke.setItem(e,String(I.current))};return document.addEventListener("mousemove",f),document.addEventListener("mouseup",p),document.addEventListener("touchmove",f,{passive:!1}),document.addEventListener("touchend",p),document.addEventListener("touchcancel",p),()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",p),document.removeEventListener("touchmove",f),document.removeEventListener("touchend",p),document.removeEventListener("touchcancel",p)}},[s,t,i,e,r,C]);const d=aA.useCallback(()=>{C(A),Ke.setItem(e,String(A))},[A,e,C]);return{width:n,isDragging:s,handleProps:{isDragging:s,onMouseDown:E,onTouchStart:u,onDoubleClick:d}}}const KZ=({isDragging:e,onMouseDown:A,onTouchStart:t,onDoubleClick:i,className:r,side:n})=>w.jsxs("div",{className:`relative w-0 cursor-col-resize flex-shrink-0 group z-10${r?` ${r}`:""}`,children:[w.jsx("div",{className:`absolute inset-y-0 -left-0.5 -right-0.5 transition-colors ${e?"bg-primary/50":"group-hover:bg-border"}`}),w.jsx("div",{className:`absolute inset-y-0 ${n==="left"?"-right-2 -left-1":n==="right"?"-right-3 left-0":"-inset-x-2"}`,onMouseDown:A,onTouchStart:t,onDoubleClick:i})]});function u9A(){const e=aA.useRef(null),[A,t]=aA.useState(null),i=aA.useCallback(r=>{const n=r;e.current=n,t(n)},[]);return{ref:e,viewport:A,onViewportReady:i}}const B9A=({className:e,panelClassName:A,renderTrigger:t,children:i})=>{const[r,n]=aA.useState(!1),a=aA.useRef(null);return aA.useEffect(()=>{if(!r)return;const s=g=>{a.current&&!a.current.contains(g.target)&&n(!1)},o=g=>{g.key==="Escape"&&n(!1)};return document.addEventListener("pointerdown",s),document.addEventListener("keydown",o),()=>{document.removeEventListener("pointerdown",s),document.removeEventListener("keydown",o)}},[r]),w.jsxs("div",{ref:a,className:e?`relative ${e}`:"relative",children:[t({isOpen:r,toggleMenu:()=>n(s=>!s)}),r&&w.jsx("div",{className:A??"absolute top-full right-0 mt-1 w-56 rounded-lg border border-border bg-popover py-1 shadow-xl z-[70]",children:i({closeMenu:()=>n(!1)})})]})},Yg=({onClick:e,icon:A,label:t,subtitle:i,badge:r})=>w.jsxs("button",{onClick:e,className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-muted",children:[w.jsx("span",{className:"text-muted-foreground",children:A}),i?w.jsxs("span",{className:"flex flex-1 flex-col gap-0.5",children:[w.jsx("span",{children:t}),w.jsx("span",{className:"text-[10px] text-muted-foreground",children:i})]}):w.jsx("span",{className:"flex-1",children:t}),r]}),AD=()=>w.jsx("div",{className:"my-1 border-t border-border"}),YZ=({children:e})=>w.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:e}),d9A=({className:e="w-3.5 h-3.5"})=>w.jsxs("svg",{className:`${e} flex-shrink-0`,viewBox:"0 0 64 64",fill:"none",stroke:"currentColor",children:[w.jsx("path",{d:"M40.5 40.5L55 55",strokeWidth:7,strokeLinecap:"round"}),w.jsx("circle",{cx:"27",cy:"27",r:"20",strokeWidth:4}),w.jsx("path",{d:"M27 14L29.2 14.3L30.2 17.2L32.6 18.6L35.5 17.5L37.2 19.2L36.1 22.1L37.5 24.5L40.4 25.5L40.7 27.7L40.4 29.9L37.5 30.9L36.1 33.3L37.2 36.2L35.5 37.9L32.6 36.8L30.2 38.2L29.2 41.1L27 41.4L24.8 41.1L23.8 38.2L21.4 36.8L18.5 37.9L16.8 36.2L17.9 33.3L16.5 30.9L13.6 29.9L13.3 27.7L13.6 25.5L16.5 24.5L17.9 22.1L16.8 19.2L18.5 17.5L21.4 18.6L23.8 17.2L24.8 14.3Z",strokeWidth:1.5,strokeLinejoin:"round"}),w.jsx("circle",{cx:"27",cy:"27.7",r:"7",strokeWidth:1.5})]}),h9A=({appVersion:e,onOpenSettings:A,onOpenExport:t,onCopyAgentInstructions:i,onDownloadAnnotations:r,onPrint:n,onCopyShareLink:a,onOpenImport:s,onSaveToObsidian:o,onSaveToBear:g,onSaveToOctarine:l,sharingEnabled:I,isApiMode:C,agentInstructionsEnabled:E,hasNewSettingsHints:u,obsidianConfigured:d,bearConfigured:Q,octarineConfigured:f})=>{const{theme:p,setTheme:y}=WcA(),D=C&&(d||Q||f);return w.jsx(B9A,{renderTrigger:({isOpen:S,toggleMenu:k})=>w.jsxs("button",{onClick:k,className:`relative flex items-center gap-1.5 p-1.5 md:px-2.5 md:py-1 rounded-md text-xs font-medium transition-colors ${S?"bg-muted text-foreground":"text-muted-foreground hover:text-foreground hover:bg-muted"}`,title:"Options","aria-label":"Options","aria-expanded":S,children:[S?w.jsx(f9A,{}):w.jsx(Q9A,{}),w.jsx("span",{className:"hidden md:inline",children:"Options"}),u&&!S&&w.jsxs("span",{className:"absolute -top-0.5 -right-0.5 flex h-2 w-2",children:[w.jsx("span",{className:"absolute inset-0 rounded-full bg-primary opacity-75 animate-ping"}),w.jsx("span",{className:"relative rounded-full h-2 w-2 bg-primary"})]})]}),children:({closeMenu:S})=>w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"px-3 py-2 space-y-1.5",children:[w.jsx(YZ,{children:"Theme"}),w.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-muted/50 p-0.5",children:["light","dark","system"].map(k=>w.jsxs("button",{onClick:()=>{S(),y(k)},className:`flex flex-1 items-center justify-center gap-1.5 rounded-md px-2 py-1 text-[11px] font-medium transition-colors ${p===k?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[k==="light"?w.jsx(uIA,{}):k==="dark"?w.jsx(BIA,{}):w.jsx(dIA,{}),w.jsx("span",{className:"capitalize",children:k})]},k))})]}),w.jsx(AD,{}),w.jsx(Yg,{onClick:()=>{S(),A()},icon:w.jsx(p9A,{}),label:"Settings"}),w.jsx(Yg,{onClick:()=>{S(),t()},icon:w.jsx(m9A,{}),label:"Export"}),E&&w.jsx(Yg,{onClick:()=>{S(),i()},icon:w.jsx(d9A,{}),label:"Agent Instructions",subtitle:"Copy agent instructions for external annotations"}),w.jsx(AD,{}),w.jsx(Yg,{onClick:()=>{S(),r()},icon:w.jsx(y9A,{}),label:"Download Annotations"}),w.jsx(Yg,{onClick:()=>{S(),n()},icon:w.jsx(D9A,{}),label:"Print Plan"}),I&&w.jsx(Yg,{onClick:()=>{S(),a()},icon:w.jsx(w9A,{}),label:"Copy Share Link"}),I&&w.jsx(Yg,{onClick:()=>{S(),s()},icon:w.jsx(v9A,{}),label:"Import Review"}),D&&w.jsxs(w.Fragment,{children:[w.jsx(AD,{}),d&&w.jsx(Yg,{onClick:()=>{S(),o()},icon:w.jsx(yT,{}),label:"Save to Obsidian"}),Q&&w.jsx(Yg,{onClick:()=>{S(),g()},icon:w.jsx(yT,{}),label:"Save to Bear"}),f&&w.jsx(Yg,{onClick:()=>{S(),l()},icon:w.jsx(yT,{}),label:"Save to Octarine"})]}),w.jsx(AD,{}),w.jsxs("div",{className:"px-3 py-2 space-y-2",children:[w.jsxs("div",{className:"flex items-center justify-between gap-3",children:[w.jsx(YZ,{children:"Plannotator"}),w.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground/70",children:["v",e]})]}),w.jsxs("div",{className:"flex flex-col items-start gap-1 text-[11px]",children:[w.jsx("a",{href:"https://github.com/backnotprop/plannotator/releases",target:"_blank",rel:"noopener noreferrer",onClick:S,className:"text-muted-foreground hover:text-foreground transition-colors",children:"Release notes"}),w.jsx("a",{href:"https://github.com/backnotprop/plannotator",target:"_blank",rel:"noopener noreferrer",onClick:S,className:"text-muted-foreground hover:text-foreground transition-colors",children:"Project repo"})]})]})]})})},Q9A=()=>w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 6h16M4 12h16M4 18h16"})}),f9A=()=>w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),p9A=()=>w.jsxs("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),m9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.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"})}),y9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),D9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 17h2a2 2 0 002-2v-4a2 2 0 00-2-2H5a2 2 0 00-2 2v4a2 2 0 002 2h2m2 4h6a2 2 0 002-2v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2zm8-12V5a2 2 0 00-2-2H9a2 2 0 00-2 2v4h10z"})}),w9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})}),v9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 3h4a2 2 0 012 2v14a2 2 0 01-2 2h-4M10 17l5-5-5-5M15 12H3"})}),yT=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"})}),S9A=({isOpen:e,onComplete:A})=>{const[t,i]=aA.useState("acceptEdits");if(!e)return null;const r=()=>{sIA(t),A(t)};return mg.createPortal(w.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-background/90 backdrop-blur-sm p-4",children:w.jsxs("div",{className:"bg-card border border-border rounded-xl w-full max-w-lg shadow-2xl",children:[w.jsxs("div",{className:"p-5 border-b border-border",children:[w.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[w.jsx("div",{className:"p-1.5 rounded-lg bg-primary/15",children:w.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0"})})}),w.jsx("h3",{className:"font-semibold text-base",children:"New: Permission Mode Preservation"})]}),w.jsx("p",{className:"text-sm text-muted-foreground",children:"Claude Code 2.1.7+ supports preserving your permission mode after plan approval. Choose your preferred automation level."}),w.jsxs("p",{className:"text-xs text-muted-foreground/70 mt-1",children:["Requires Claude Code 2.1.7 or later. Run ",w.jsx("code",{className:"bg-muted px-1 rounded",children:"claude update"})," to update."]})]}),w.jsx("div",{className:"p-4 space-y-2",children:FO.map(n=>w.jsxs("label",{className:`flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-all border ${t===n.value?"border-primary bg-primary/10":"border-transparent bg-muted/50 hover:bg-muted"}`,children:[w.jsx("input",{type:"radio",name:"permissionMode",value:n.value,checked:t===n.value,onChange:()=>i(n.value),className:"mt-0.5 accent-primary"}),w.jsxs("div",{className:"flex-1",children:[w.jsx("div",{className:"text-sm font-medium",children:n.label}),w.jsx("div",{className:"text-xs text-muted-foreground",children:n.description})]})]},n.value))}),w.jsxs("div",{className:"p-4 border-t border-border flex justify-between items-center",children:[w.jsx("p",{className:"text-xs text-muted-foreground",children:"You can change this later in Settings."}),w.jsx("button",{onClick:r,className:"px-4 py-2 bg-primary text-primary-foreground rounded-lg text-sm font-medium hover:opacity-90 transition-opacity",children:"Continue"})]})]})}),document.body)};function b9A(e){const[A,t]=aA.useState(e),[i,r]=aA.useState("toc"),n=aA.useCallback(o=>{t(!0),o&&r(o)},[]),a=aA.useCallback(()=>{t(!1)},[]),s=aA.useCallback(o=>{A?i===o?t(!1):r(o):(t(!0),r(o))},[A,i]);return{isOpen:A,activeTab:i,open:n,close:a,toggleTab:s}}class R9A{diff(A,t,i={}){let r;typeof i=="function"?(r=i,i={}):"callback"in i&&(r=i.callback);const n=this.castInput(A,i),a=this.castInput(t,i),s=this.removeEmpty(this.tokenize(n,i)),o=this.removeEmpty(this.tokenize(a,i));return this.diffWithOptionsObj(s,o,i,r)}diffWithOptionsObj(A,t,i,r){var n;const a=p=>{if(p=this.postProcess(p,i),r){setTimeout(function(){r(p)},0);return}else return p},s=t.length,o=A.length;let g=1,l=s+o;i.maxEditLength!=null&&(l=Math.min(l,i.maxEditLength));const I=(n=i.timeout)!==null&&n!==void 0?n:1/0,C=Date.now()+I,E=[{oldPos:-1,lastComponent:void 0}];let u=this.extractCommon(E[0],t,A,0,i);if(E[0].oldPos+1>=o&&u+1>=s)return a(this.buildValues(E[0].lastComponent,t,A));let d=-1/0,Q=1/0;const f=()=>{for(let p=Math.max(d,-g);p<=Math.min(Q,g);p+=2){let y;const D=E[p-1],S=E[p+1];D&&(E[p-1]=void 0);let k=!1;if(S){const b=S.oldPos-p;k=S&&0<=b&&b<s}const R=D&&D.oldPos+1<o;if(!k&&!R){E[p]=void 0;continue}if(!R||k&&D.oldPos<S.oldPos?y=this.addToPath(S,!0,!1,0,i):y=this.addToPath(D,!1,!0,1,i),u=this.extractCommon(y,t,A,p,i),y.oldPos+1>=o&&u+1>=s)return a(this.buildValues(y.lastComponent,t,A))||!0;E[p]=y,y.oldPos+1>=o&&(Q=Math.min(Q,p-1)),u+1>=s&&(d=Math.max(d,p+1))}g++};if(r)(function p(){setTimeout(function(){if(g>l||Date.now()>C)return r(void 0);f()||p()},0)})();else for(;g<=l&&Date.now()<=C;){const p=f();if(p)return p}}addToPath(A,t,i,r,n){const a=A.lastComponent;return a&&!n.oneChangePerToken&&a.added===t&&a.removed===i?{oldPos:A.oldPos+r,lastComponent:{count:a.count+1,added:t,removed:i,previousComponent:a.previousComponent}}:{oldPos:A.oldPos+r,lastComponent:{count:1,added:t,removed:i,previousComponent:a}}}extractCommon(A,t,i,r,n){const a=t.length,s=i.length;let o=A.oldPos,g=o-r,l=0;for(;g+1<a&&o+1<s&&this.equals(i[o+1],t[g+1],n);)g++,o++,l++,n.oneChangePerToken&&(A.lastComponent={count:1,previousComponent:A.lastComponent,added:!1,removed:!1});return l&&!n.oneChangePerToken&&(A.lastComponent={count:l,previousComponent:A.lastComponent,added:!1,removed:!1}),A.oldPos=o,g}equals(A,t,i){return i.comparator?i.comparator(A,t):A===t||!!i.ignoreCase&&A.toLowerCase()===t.toLowerCase()}removeEmpty(A){const t=[];for(let i=0;i<A.length;i++)A[i]&&t.push(A[i]);return t}castInput(A,t){return A}tokenize(A,t){return Array.from(A)}join(A){return A.join("")}postProcess(A,t){return A}get useLongestToken(){return!1}buildValues(A,t,i){const r=[];let n;for(;A;)r.push(A),n=A.previousComponent,delete A.previousComponent,A=n;r.reverse();const a=r.length;let s=0,o=0,g=0;for(;s<a;s++){const l=r[s];if(l.removed)l.value=this.join(i.slice(g,g+l.count)),g+=l.count;else{if(!l.added&&this.useLongestToken){let I=t.slice(o,o+l.count);I=I.map(function(C,E){const u=i[g+E];return u.length>C.length?u:C}),l.value=this.join(I)}else l.value=this.join(t.slice(o,o+l.count));o+=l.count,l.added||(g+=l.count)}}return r}}class N9A extends R9A{constructor(){super(...arguments),this.tokenize=x9A}equals(A,t,i){return i.ignoreWhitespace?((!i.newlineIsToken||!A.includes(`
511
+ `).find(eA=>eA.startsWith("#")),X=j?j.replace(/^#+\s*/,"").trim():"Unknown Plan",_=Sw(q.a,q.d,q.s);if(_.length===0)return{success:!0,count:0,planTitle:X,error:"No annotations found in share link"};const gA=_.filter(eA=>!A.some(dA=>dA.originalText===eA.originalText&&dA.type===eA.type&&dA.text===eA.text));if(gA.length>0&&(r(eA=>{const dA=_.filter(oA=>!eA.some(nA=>nA.originalText===oA.originalText&&nA.type===oA.type&&nA.text===oA.text));if(dA.length===0)return eA;const tA=[...eA,...dA];return b(tA),tA}),q.g?.length)){const eA=Ed(q.g)??[];n(dA=>{const tA=new Set(dA.map(nA=>nA.path)),oA=eA.filter(nA=>!tA.has(nA.path));return oA.length>0?[...dA,...oA]:dA}),T(eA)}return{success:!0,count:gA.length,planTitle:X}}catch(q){return{success:!1,count:0,planTitle:"",error:q instanceof Error?q.message:"Failed to decompress share URL"}}},[A,t,r,n,o]);return{isSharedSession:g,isLoadingShared:I,shareUrl:E,shareUrlSize:d,shortShareUrl:f,isGeneratingShortUrl:y,shortUrlError:S,pendingSharedAnnotations:R,sharedGlobalAttachments:N,clearPendingSharedAnnotations:H,refreshShareUrl:G,generateShortUrl:F,importFromShareUrl:O,shareLoadError:L,clearShareLoadError:x}}var bw=(e=>(e.Approve="approve",e.Feedback="feedback",e))(bw||{});function q8A(e=window.location){const A=new URLSearchParams(e.search);let t=A.get("cb"),i=A.get("ct");if(!t||!i){const r=e.hash.indexOf("?");if(r!==-1){const n=new URLSearchParams(e.hash.slice(r+1));t=t??n.get("cb"),i=i??n.get("ct")}}if(!t||!i)return null;try{const{protocol:r}=new URL(t);if(r!=="https:"&&r!=="http:")return null}catch{return null}return{callbackUrl:t,token:i}}async function W8A(e,A,t){const i=e==="approve"?"Plan approved! The bot will proceed to implementation.":"Feedback sent! The bot will re-plan with your annotations.";try{const r=await fetch(A.callbackUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:e,token:A.token,annotated_url:t})});return r.ok?{type:"success",message:i}:{type:"error",message:r.status===401?"Plan link expired — request a new one from the bot.":"Callback failed."}}catch{return{type:"error",message:"Callback failed."}}}function V8A(e,A,t){const[i,r]=aA.useState(null),n=aA.useRef(null);return aA.useEffect(()=>{const a=t??e.current;if(!a)return;const s=a.querySelectorAll('[data-block-type="heading"]');if(s.length===0)return;const o=new Map;return n.current=new IntersectionObserver(g=>{g.forEach(C=>{o.set(C.target,C.isIntersecting)});let l=null,I=1/0;for(const[C,E]of o)if(E){const u=C.getBoundingClientRect();u.top<I&&(I=u.top,l=C)}if(l){const C=l.getAttribute("data-block-id");C&&r(C)}},{root:a,rootMargin:"-80px 0px -80% 0px",threshold:[0,.1,.5,1]}),s.forEach(g=>{n.current?.observe(g)}),()=>{n.current?.disconnect()}},[e,A,t]),i}function GZ(e){window.close(),setTimeout(()=>{window.closed||e()},300)}function Z8A(e){const[A,t]=aA.useState({phase:"idle"});aA.useEffect(()=>{if(!e)return;const r=yiA();r==="0"?(GZ(()=>t({phase:"closeFailed"})),t({phase:"closed"})):t(r!=="off"?{phase:"counting",remaining:Number(r)}:{phase:"prompt"})},[e]),aA.useEffect(()=>{if(A.phase!=="counting")return;if(A.remaining<=0){GZ(()=>t({phase:"closeFailed"}));return}const r=setTimeout(()=>t(n=>n.phase==="counting"?{phase:"counting",remaining:n.remaining-1}:n),1e3);return()=>clearTimeout(r)},[A]);const i=aA.useCallback(()=>{DiA("3"),t({phase:"counting",remaining:3})},[]);return{state:A,enableAndStart:i}}const j8A=()=>w.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),_8A=()=>w.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:w.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 X8A({submitted:e,title:A,subtitle:t,agentLabel:i}){const{state:r,enableAndStart:n}=Z8A(!!e);if(!e)return null;const a=e==="approved";return w.jsx("div",{className:"fixed inset-0 z-[100] bg-background flex items-center justify-center",children:w.jsxs("div",{className:"text-center space-y-6 max-w-md px-8",children:[w.jsx("div",{className:`mx-auto w-16 h-16 rounded-full flex items-center justify-center ${a?"bg-success/20 text-success":"bg-accent/20 text-accent"}`,children:a?w.jsx(j8A,{}):w.jsx(_8A,{})}),w.jsxs("div",{className:"space-y-2",children:[w.jsx("h2",{className:"text-xl font-semibold text-foreground",children:A}),w.jsx("p",{className:"text-muted-foreground",children:t})]}),w.jsx("div",{className:"pt-4 border-t border-border space-y-2",children:r.phase==="counting"?w.jsxs(w.Fragment,{children:[w.jsxs("p",{className:"text-sm text-muted-foreground",children:["This tab will close in ",w.jsx("span",{className:"text-foreground font-medium",children:r.remaining})," second",r.remaining!==1?"s":"","..."]}),w.jsx("p",{className:"text-xs text-muted-foreground/60",children:"You can change this in Settings."})]}):r.phase==="closeFailed"?w.jsxs(w.Fragment,{children:[w.jsx("p",{className:"text-sm text-muted-foreground",children:"Could not close this tab automatically. Please close it manually."}),w.jsxs("p",{className:"text-xs text-muted-foreground/60",children:["Auto-close works when the tab is opened by ",i,"."]})]}):w.jsxs(w.Fragment,{children:[w.jsxs("p",{className:"text-sm text-muted-foreground",children:["You can close this tab and return to ",w.jsx("span",{className:"text-foreground font-medium",children:i}),"."]}),r.phase==="prompt"?w.jsxs(w.Fragment,{children:[w.jsxs("label",{className:"flex items-center justify-center gap-2 cursor-pointer group",children:[w.jsx("input",{type:"checkbox",checked:!1,onChange:n,className:"accent-primary"}),w.jsx("span",{className:"text-xs text-muted-foreground group-hover:text-foreground transition-colors",children:"Auto-close this tab after 3 seconds"})]}),w.jsx("p",{className:"text-xs text-muted-foreground/60",children:"You can change the delay in Settings."})]}):w.jsx("p",{className:"text-xs text-muted-foreground/60",children:"Your response has been sent."})]})})]})})}const $8A="https://api.github.com/repos/backnotprop/plannotator/releases/latest",OZ={"0.5.0":{title:"Code Review is here!",description:"Review git diffs with inline annotations. Run /plannotator-review to try it."}};function A9A(e,A){const t=n=>n.replace(/^v/,""),i=t(e).split(".").map(Number),r=t(A).split(".").map(Number);for(let n=0;n<Math.max(i.length,r.length);n++){const a=i[n]||0,s=r[n]||0;if(s>a)return!0;if(s<a)return!1}return!1}function e9A(){const[e,A]=aA.useState(null);return aA.useEffect(()=>{(async()=>{try{const i="0.17.7",n=new URLSearchParams(window.location.search).get("preview-update");if(n){const C=n.replace(/^v/,"");A({currentVersion:i,latestVersion:n,updateAvailable:!0,releaseUrl:`https://github.com/backnotprop/plannotator/releases/tag/v${C}`,featureHighlight:OZ[C]});return}const a=await fetch($8A);if(!a.ok)return;const s=await a.json(),o=s.tag_name,g=A9A(i,o),l=o.replace(/^v/,""),I=OZ[l];A({currentVersion:i,latestVersion:o,updateAvailable:g,releaseUrl:s.html_url,featureHighlight:I})}catch(i){console.debug("Update check failed:",i)}})()},[]),e}const t9A="pi install npm:@plannotator/pi-extension";function i9A(e){return lSA&&!e?'powershell -c "irm https://plannotator.ai/install.ps1 | iex"':"curl -fsSL https://plannotator.ai/install.sh | bash"}const r9A=({origin:e,isWSL:A=!1})=>{const t=e9A(),[i,r]=aA.useState(!1),[n,a]=aA.useState(!1),g=new URLSearchParams(window.location.search).get("preview-origin")||e,l=g==="pi",I=g==="opencode",C=l?t9A:i9A(A);if(!t?.updateAvailable||n)return null;const E=async()=>{try{await navigator.clipboard.writeText(C),r(!0),setTimeout(()=>r(!1),2e3)}catch(d){console.error("Failed to copy:",d)}};return t.featureHighlight?w.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:w.jsxs("div",{className:"bg-card border border-primary/30 rounded-xl shadow-2xl overflow-hidden",children:[w.jsx("div",{className:"bg-gradient-to-r from-primary/20 to-primary/5 px-5 py-4 border-b border-border/50",children:w.jsxs("div",{className:"flex items-start justify-between gap-3",children:[w.jsxs("div",{className:"flex items-center gap-3",children:[w.jsx("div",{className:"flex-shrink-0 w-10 h-10 rounded-lg bg-primary/20 flex items-center justify-center",children:w.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.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"})})}),w.jsxs("div",{children:[w.jsx("h4",{className:"text-base font-semibold text-foreground",children:t.featureHighlight.title}),w.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["New in ",t.latestVersion]})]})]}),w.jsx("button",{onClick:()=>a(!0),className:"text-muted-foreground hover:text-foreground transition-colors p-1",children:w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})}),w.jsxs("div",{className:"px-5 py-4",children:[w.jsx("p",{className:"text-sm text-foreground/80 leading-relaxed",children:t.featureHighlight.description}),w.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:["You have ",t.currentVersion]}),I&&w.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Run the install script, then restart OpenCode."}),l&&w.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Run the install command, then restart Pi."}),w.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[w.jsx("button",{onClick:E,className:"flex-1 px-4 py-2 text-sm font-medium bg-primary text-primary-foreground rounded-lg hover:opacity-90 transition-opacity",children:i?"Copied!":"Copy install command"}),w.jsx("a",{href:t.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"})]})]})]})}):w.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:w.jsx("div",{className:"bg-card border border-border rounded-lg shadow-xl p-4",children:w.jsxs("div",{className:"flex items-start gap-3",children:[w.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-primary/20 flex items-center justify-center",children:w.jsx("svg",{className:"w-4 h-4 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.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"})})}),w.jsxs("div",{className:"flex-1 min-w-0",children:[w.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Update available"}),w.jsx("button",{onClick:()=>a(!0),className:"text-muted-foreground hover:text-foreground transition-colors",children:w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),w.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[t.latestVersion," is available (you have ",t.currentVersion,")"]}),w.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[w.jsx("button",{onClick:E,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:i?"Copied!":"Copy install command"}),w.jsx("a",{href:t.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"})]})]})]})})})},bIA="plannotator-editor-mode",n9A="selection";function a9A(){const e=Ke.getItem(bIA);return e==="selection"||e==="comment"||e==="redline"||e==="quickLabel"?e:n9A}function s9A(e){Ke.setItem(bIA,e)}const RIA="plannotator-input-method",o9A="drag";function g9A(){const e=Ke.getItem(RIA);return e==="drag"||e==="pinpoint"?e:o9A}function l9A(e){Ke.setItem(RIA,e)}const c9A=300,I9A=300;function C9A(e,A){const t=aA.useRef("idle"),i=aA.useRef(0),r=aA.useRef(void 0),n=aA.useRef(e);aA.useEffect(()=>{t.current==="idle"&&(n.current=e)},[e]);const a=aA.useCallback(s=>s==="drag"?"pinpoint":"drag",[]);aA.useEffect(()=>{const s=g=>{if(g.key!=="Alt"||g.repeat)return;const l=g.target?.tagName;l==="INPUT"||l==="TEXTAREA"||g.target?.isContentEditable||document.querySelector("[data-quick-label-picker]")||(t.current==="idle"?(n.current=e,i.current=Date.now(),t.current="held",A(a(e))):t.current==="tapped"&&(clearTimeout(r.current),t.current="idle",n.current=a(n.current)))},o=g=>{g.key==="Alt"&&t.current==="held"&&(Date.now()-i.current>=I9A?(A(n.current),t.current="idle"):(t.current="tapped",r.current=setTimeout(()=>{t.current==="tapped"&&(A(n.current),t.current="idle")},c9A)))};return window.addEventListener("keydown",s),window.addEventListener("keyup",o),()=>{clearTimeout(r.current),window.removeEventListener("keydown",s),window.removeEventListener("keyup",o)}},[e,A,a])}function E9A(){aA.useEffect(()=>{const e=()=>document.documentElement.classList.add("plannotator-print"),A=()=>document.documentElement.classList.remove("plannotator-print"),t=()=>{!document.hidden&&document.documentElement.classList.contains("plannotator-print")&&document.documentElement.classList.remove("plannotator-print")};return window.addEventListener("beforeprint",e),window.addEventListener("afterprint",A),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("beforeprint",e),window.removeEventListener("afterprint",A),document.removeEventListener("visibilitychange",t),document.documentElement.classList.remove("plannotator-print")}},[])}function UZ({storageKey:e,defaultWidth:A=288,minWidth:t=200,maxWidth:i=600,side:r="right"}){const[n,a]=aA.useState(()=>{const Q=Ke.getItem(e);if(Q){const f=Number(Q);if(!Number.isNaN(f)&&f>=t&&f<=i)return f}return A}),[s,o]=aA.useState(!1),g=aA.useRef(0),l=aA.useRef(0),I=aA.useRef(n),C=aA.useCallback(Q=>{I.current=Q,a(Q)},[]),E=aA.useCallback(Q=>{Q.preventDefault(),g.current=Q.clientX,l.current=I.current,o(!0)},[]),u=aA.useCallback(Q=>{Q.preventDefault(),g.current=Q.touches[0].clientX,l.current=I.current,o(!0)},[]);aA.useEffect(()=>{if(!s)return;const Q=y=>"touches"in y?y.touches[0]?.clientX??y.changedTouches[0]?.clientX??0:y.clientX,f=y=>{const D=Q(y),S=r==="right"?g.current-D:D-g.current;C(Math.min(i,Math.max(t,l.current+S)))},p=()=>{o(!1),Ke.setItem(e,String(I.current))};return document.addEventListener("mousemove",f),document.addEventListener("mouseup",p),document.addEventListener("touchmove",f,{passive:!1}),document.addEventListener("touchend",p),document.addEventListener("touchcancel",p),()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",p),document.removeEventListener("touchmove",f),document.removeEventListener("touchend",p),document.removeEventListener("touchcancel",p)}},[s,t,i,e,r,C]);const d=aA.useCallback(()=>{C(A),Ke.setItem(e,String(A))},[A,e,C]);return{width:n,isDragging:s,handleProps:{isDragging:s,onMouseDown:E,onTouchStart:u,onDoubleClick:d}}}const KZ=({isDragging:e,onMouseDown:A,onTouchStart:t,onDoubleClick:i,className:r,side:n})=>w.jsxs("div",{className:`relative w-0 cursor-col-resize flex-shrink-0 group z-10${r?` ${r}`:""}`,children:[w.jsx("div",{className:`absolute inset-y-0 -left-0.5 -right-0.5 transition-colors ${e?"bg-primary/50":"group-hover:bg-border"}`}),w.jsx("div",{className:`absolute inset-y-0 ${n==="left"?"-right-2 -left-1":n==="right"?"-right-3 left-0":"-inset-x-2"}`,onMouseDown:A,onTouchStart:t,onDoubleClick:i})]});function u9A(){const e=aA.useRef(null),[A,t]=aA.useState(null),i=aA.useCallback(r=>{const n=r;e.current=n,t(n)},[]);return{ref:e,viewport:A,onViewportReady:i}}const B9A=({className:e,panelClassName:A,renderTrigger:t,children:i})=>{const[r,n]=aA.useState(!1),a=aA.useRef(null);return aA.useEffect(()=>{if(!r)return;const s=g=>{a.current&&!a.current.contains(g.target)&&n(!1)},o=g=>{g.key==="Escape"&&n(!1)};return document.addEventListener("pointerdown",s),document.addEventListener("keydown",o),()=>{document.removeEventListener("pointerdown",s),document.removeEventListener("keydown",o)}},[r]),w.jsxs("div",{ref:a,className:e?`relative ${e}`:"relative",children:[t({isOpen:r,toggleMenu:()=>n(s=>!s)}),r&&w.jsx("div",{className:A??"absolute top-full right-0 mt-1 w-56 rounded-lg border border-border bg-popover py-1 shadow-xl z-[70]",children:i({closeMenu:()=>n(!1)})})]})},Yg=({onClick:e,icon:A,label:t,subtitle:i,badge:r})=>w.jsxs("button",{onClick:e,className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-muted",children:[w.jsx("span",{className:"text-muted-foreground",children:A}),i?w.jsxs("span",{className:"flex flex-1 flex-col gap-0.5",children:[w.jsx("span",{children:t}),w.jsx("span",{className:"text-[10px] text-muted-foreground",children:i})]}):w.jsx("span",{className:"flex-1",children:t}),r]}),AD=()=>w.jsx("div",{className:"my-1 border-t border-border"}),YZ=({children:e})=>w.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:e}),d9A=({className:e="w-3.5 h-3.5"})=>w.jsxs("svg",{className:`${e} flex-shrink-0`,viewBox:"0 0 64 64",fill:"none",stroke:"currentColor",children:[w.jsx("path",{d:"M40.5 40.5L55 55",strokeWidth:7,strokeLinecap:"round"}),w.jsx("circle",{cx:"27",cy:"27",r:"20",strokeWidth:4}),w.jsx("path",{d:"M27 14L29.2 14.3L30.2 17.2L32.6 18.6L35.5 17.5L37.2 19.2L36.1 22.1L37.5 24.5L40.4 25.5L40.7 27.7L40.4 29.9L37.5 30.9L36.1 33.3L37.2 36.2L35.5 37.9L32.6 36.8L30.2 38.2L29.2 41.1L27 41.4L24.8 41.1L23.8 38.2L21.4 36.8L18.5 37.9L16.8 36.2L17.9 33.3L16.5 30.9L13.6 29.9L13.3 27.7L13.6 25.5L16.5 24.5L17.9 22.1L16.8 19.2L18.5 17.5L21.4 18.6L23.8 17.2L24.8 14.3Z",strokeWidth:1.5,strokeLinejoin:"round"}),w.jsx("circle",{cx:"27",cy:"27.7",r:"7",strokeWidth:1.5})]}),h9A=({appVersion:e,onOpenSettings:A,onOpenExport:t,onCopyAgentInstructions:i,onDownloadAnnotations:r,onPrint:n,onCopyShareLink:a,onOpenImport:s,onSaveToObsidian:o,onSaveToBear:g,onSaveToOctarine:l,sharingEnabled:I,isApiMode:C,agentInstructionsEnabled:E,hasNewSettingsHints:u,obsidianConfigured:d,bearConfigured:Q,octarineConfigured:f})=>{const{theme:p,setTheme:y}=WcA(),D=C&&(d||Q||f);return w.jsx(B9A,{renderTrigger:({isOpen:S,toggleMenu:k})=>w.jsxs("button",{onClick:k,className:`relative flex items-center gap-1.5 p-1.5 md:px-2.5 md:py-1 rounded-md text-xs font-medium transition-colors ${S?"bg-muted text-foreground":"text-muted-foreground hover:text-foreground hover:bg-muted"}`,title:"Options","aria-label":"Options","aria-expanded":S,children:[S?w.jsx(f9A,{}):w.jsx(Q9A,{}),w.jsx("span",{className:"hidden md:inline",children:"Options"}),u&&!S&&w.jsxs("span",{className:"absolute -top-0.5 -right-0.5 flex h-2 w-2",children:[w.jsx("span",{className:"absolute inset-0 rounded-full bg-primary opacity-75 animate-ping"}),w.jsx("span",{className:"relative rounded-full h-2 w-2 bg-primary"})]})]}),children:({closeMenu:S})=>w.jsxs(w.Fragment,{children:[w.jsxs("div",{className:"px-3 py-2 space-y-1.5",children:[w.jsx(YZ,{children:"Theme"}),w.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-muted/50 p-0.5",children:["light","dark","system"].map(k=>w.jsxs("button",{onClick:()=>{S(),y(k)},className:`flex flex-1 items-center justify-center gap-1.5 rounded-md px-2 py-1 text-[11px] font-medium transition-colors ${p===k?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[k==="light"?w.jsx(uIA,{}):k==="dark"?w.jsx(BIA,{}):w.jsx(dIA,{}),w.jsx("span",{className:"capitalize",children:k})]},k))})]}),w.jsx(AD,{}),w.jsx(Yg,{onClick:()=>{S(),A()},icon:w.jsx(p9A,{}),label:"Settings"}),w.jsx(Yg,{onClick:()=>{S(),t()},icon:w.jsx(m9A,{}),label:"Export"}),E&&w.jsx(Yg,{onClick:()=>{S(),i()},icon:w.jsx(d9A,{}),label:"Agent Instructions",subtitle:"Copy agent instructions for external annotations"}),w.jsx(AD,{}),w.jsx(Yg,{onClick:()=>{S(),r()},icon:w.jsx(y9A,{}),label:"Download Annotations"}),w.jsx(Yg,{onClick:()=>{S(),n()},icon:w.jsx(D9A,{}),label:"Print Plan"}),I&&w.jsx(Yg,{onClick:()=>{S(),a()},icon:w.jsx(w9A,{}),label:"Copy Share Link"}),I&&w.jsx(Yg,{onClick:()=>{S(),s()},icon:w.jsx(v9A,{}),label:"Import Review"}),D&&w.jsxs(w.Fragment,{children:[w.jsx(AD,{}),d&&w.jsx(Yg,{onClick:()=>{S(),o()},icon:w.jsx(yT,{}),label:"Save to Obsidian"}),Q&&w.jsx(Yg,{onClick:()=>{S(),g()},icon:w.jsx(yT,{}),label:"Save to Bear"}),f&&w.jsx(Yg,{onClick:()=>{S(),l()},icon:w.jsx(yT,{}),label:"Save to Octarine"})]}),w.jsx(AD,{}),w.jsxs("div",{className:"px-3 py-2 space-y-2",children:[w.jsxs("div",{className:"flex items-center justify-between gap-3",children:[w.jsx(YZ,{children:"Plannotator"}),w.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground/70",children:["v",e]})]}),w.jsxs("div",{className:"flex flex-col items-start gap-1 text-[11px]",children:[w.jsx("a",{href:"https://github.com/backnotprop/plannotator/releases",target:"_blank",rel:"noopener noreferrer",onClick:S,className:"text-muted-foreground hover:text-foreground transition-colors",children:"Release notes"}),w.jsx("a",{href:"https://github.com/backnotprop/plannotator",target:"_blank",rel:"noopener noreferrer",onClick:S,className:"text-muted-foreground hover:text-foreground transition-colors",children:"Project repo"})]})]})]})})},Q9A=()=>w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 6h16M4 12h16M4 18h16"})}),f9A=()=>w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),p9A=()=>w.jsxs("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),m9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.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"})}),y9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),D9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 17h2a2 2 0 002-2v-4a2 2 0 00-2-2H5a2 2 0 00-2 2v4a2 2 0 002 2h2m2 4h6a2 2 0 002-2v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2zm8-12V5a2 2 0 00-2-2H9a2 2 0 00-2 2v4h10z"})}),w9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})}),v9A=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 3h4a2 2 0 012 2v14a2 2 0 01-2 2h-4M10 17l5-5-5-5M15 12H3"})}),yT=()=>w.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"})}),S9A=({isOpen:e,onComplete:A})=>{const[t,i]=aA.useState("acceptEdits");if(!e)return null;const r=()=>{sIA(t),A(t)};return mg.createPortal(w.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-background/90 backdrop-blur-sm p-4",children:w.jsxs("div",{className:"bg-card border border-border rounded-xl w-full max-w-lg shadow-2xl",children:[w.jsxs("div",{className:"p-5 border-b border-border",children:[w.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[w.jsx("div",{className:"p-1.5 rounded-lg bg-primary/15",children:w.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0"})})}),w.jsx("h3",{className:"font-semibold text-base",children:"New: Permission Mode Preservation"})]}),w.jsx("p",{className:"text-sm text-muted-foreground",children:"Claude Code 2.1.7+ supports preserving your permission mode after plan approval. Choose your preferred automation level."}),w.jsxs("p",{className:"text-xs text-muted-foreground/70 mt-1",children:["Requires Claude Code 2.1.7 or later. Run ",w.jsx("code",{className:"bg-muted px-1 rounded",children:"claude update"})," to update."]})]}),w.jsx("div",{className:"p-4 space-y-2",children:FO.map(n=>w.jsxs("label",{className:`flex items-start gap-3 p-3 rounded-lg cursor-pointer transition-all border ${t===n.value?"border-primary bg-primary/10":"border-transparent bg-muted/50 hover:bg-muted"}`,children:[w.jsx("input",{type:"radio",name:"permissionMode",value:n.value,checked:t===n.value,onChange:()=>i(n.value),className:"mt-0.5 accent-primary"}),w.jsxs("div",{className:"flex-1",children:[w.jsx("div",{className:"text-sm font-medium",children:n.label}),w.jsx("div",{className:"text-xs text-muted-foreground",children:n.description})]})]},n.value))}),w.jsxs("div",{className:"p-4 border-t border-border flex justify-between items-center",children:[w.jsx("p",{className:"text-xs text-muted-foreground",children:"You can change this later in Settings."}),w.jsx("button",{onClick:r,className:"px-4 py-2 bg-primary text-primary-foreground rounded-lg text-sm font-medium hover:opacity-90 transition-opacity",children:"Continue"})]})]})}),document.body)};function b9A(e){const[A,t]=aA.useState(e),[i,r]=aA.useState("toc"),n=aA.useCallback(o=>{t(!0),o&&r(o)},[]),a=aA.useCallback(()=>{t(!1)},[]),s=aA.useCallback(o=>{A?i===o?t(!1):r(o):(t(!0),r(o))},[A,i]);return{isOpen:A,activeTab:i,open:n,close:a,toggleTab:s}}class R9A{diff(A,t,i={}){let r;typeof i=="function"?(r=i,i={}):"callback"in i&&(r=i.callback);const n=this.castInput(A,i),a=this.castInput(t,i),s=this.removeEmpty(this.tokenize(n,i)),o=this.removeEmpty(this.tokenize(a,i));return this.diffWithOptionsObj(s,o,i,r)}diffWithOptionsObj(A,t,i,r){var n;const a=p=>{if(p=this.postProcess(p,i),r){setTimeout(function(){r(p)},0);return}else return p},s=t.length,o=A.length;let g=1,l=s+o;i.maxEditLength!=null&&(l=Math.min(l,i.maxEditLength));const I=(n=i.timeout)!==null&&n!==void 0?n:1/0,C=Date.now()+I,E=[{oldPos:-1,lastComponent:void 0}];let u=this.extractCommon(E[0],t,A,0,i);if(E[0].oldPos+1>=o&&u+1>=s)return a(this.buildValues(E[0].lastComponent,t,A));let d=-1/0,Q=1/0;const f=()=>{for(let p=Math.max(d,-g);p<=Math.min(Q,g);p+=2){let y;const D=E[p-1],S=E[p+1];D&&(E[p-1]=void 0);let k=!1;if(S){const b=S.oldPos-p;k=S&&0<=b&&b<s}const R=D&&D.oldPos+1<o;if(!k&&!R){E[p]=void 0;continue}if(!R||k&&D.oldPos<S.oldPos?y=this.addToPath(S,!0,!1,0,i):y=this.addToPath(D,!1,!0,1,i),u=this.extractCommon(y,t,A,p,i),y.oldPos+1>=o&&u+1>=s)return a(this.buildValues(y.lastComponent,t,A))||!0;E[p]=y,y.oldPos+1>=o&&(Q=Math.min(Q,p-1)),u+1>=s&&(d=Math.max(d,p+1))}g++};if(r)(function p(){setTimeout(function(){if(g>l||Date.now()>C)return r(void 0);f()||p()},0)})();else for(;g<=l&&Date.now()<=C;){const p=f();if(p)return p}}addToPath(A,t,i,r,n){const a=A.lastComponent;return a&&!n.oneChangePerToken&&a.added===t&&a.removed===i?{oldPos:A.oldPos+r,lastComponent:{count:a.count+1,added:t,removed:i,previousComponent:a.previousComponent}}:{oldPos:A.oldPos+r,lastComponent:{count:1,added:t,removed:i,previousComponent:a}}}extractCommon(A,t,i,r,n){const a=t.length,s=i.length;let o=A.oldPos,g=o-r,l=0;for(;g+1<a&&o+1<s&&this.equals(i[o+1],t[g+1],n);)g++,o++,l++,n.oneChangePerToken&&(A.lastComponent={count:1,previousComponent:A.lastComponent,added:!1,removed:!1});return l&&!n.oneChangePerToken&&(A.lastComponent={count:l,previousComponent:A.lastComponent,added:!1,removed:!1}),A.oldPos=o,g}equals(A,t,i){return i.comparator?i.comparator(A,t):A===t||!!i.ignoreCase&&A.toLowerCase()===t.toLowerCase()}removeEmpty(A){const t=[];for(let i=0;i<A.length;i++)A[i]&&t.push(A[i]);return t}castInput(A,t){return A}tokenize(A,t){return Array.from(A)}join(A){return A.join("")}postProcess(A,t){return A}get useLongestToken(){return!1}buildValues(A,t,i){const r=[];let n;for(;A;)r.push(A),n=A.previousComponent,delete A.previousComponent,A=n;r.reverse();const a=r.length;let s=0,o=0,g=0;for(;s<a;s++){const l=r[s];if(l.removed)l.value=this.join(i.slice(g,g+l.count)),g+=l.count;else{if(!l.added&&this.useLongestToken){let I=t.slice(o,o+l.count);I=I.map(function(C,E){const u=i[g+E];return u.length>C.length?u:C}),l.value=this.join(I)}else l.value=this.join(t.slice(o,o+l.count));o+=l.count,l.added||(g+=l.count)}}return r}}class N9A extends R9A{constructor(){super(...arguments),this.tokenize=x9A}equals(A,t,i){return i.ignoreWhitespace?((!i.newlineIsToken||!A.includes(`
512
512
  `))&&(A=A.trim()),(!i.newlineIsToken||!t.includes(`
513
513
  `))&&(t=t.trim())):i.ignoreNewlineAtEof&&!i.newlineIsToken&&(A.endsWith(`
514
514
  `)&&(A=A.slice(0,-1)),t.endsWith(`
@@ -977,7 +977,7 @@ export const CursorOverlay: React.FC<CursorOverlayProps> = ({
977
977
  ---
978
978
 
979
979
  **Target:** Ship MVP in next sprint
980
- `;function hHA({blocks:e,annotations:A,addAnnotation:t,removeAnnotation:i}){const[r,n]=aA.useState(new Map),a=aA.useRef(e);a.current=e;const s=aA.useRef(A);s.current=A,aA.useEffect(()=>{if(r.size===0)return;const l=new Set(e.map(C=>C.id)),I=[...r.keys()].filter(C=>!l.has(C));I.length>0&&n(C=>{const E=new Map(C);return I.forEach(u=>E.delete(u)),E})},[e]);const o=aA.useCallback((l,I)=>{const C=a.current,E=s.current,u=C.find(Q=>Q.id===l);if(u&&I===u.checked)n(f=>{const p=new Map(f);return p.delete(l),p}),E.filter(f=>f.blockId===l&&f.id.startsWith("ann-checkbox-")).forEach(f=>i(f.id));else if(E.filter(f=>f.blockId===l&&f.id.startsWith("ann-checkbox-")).forEach(f=>i(f.id)),n(f=>{const p=new Map(f);return p.set(l,I),p}),u){const f=C.indexOf(u);let p="";for(let k=f-1;k>=0;k--)if(C[k].type==="heading"){p=C[k].content;break}const y=I?"Mark as completed":"Mark as not completed",D=p?` (under "${p}")`:` (line ${u.startLine})`,S={id:`ann-checkbox-${l}-${Date.now()}`,blockId:l,startOffset:0,endOffset:u.content.length,type:oi.COMMENT,text:`${y}${D}: ${u.content}`,originalText:u.content,createdA:Date.now()};t(S)}},[t,i]),g=aA.useCallback(l=>{n(I=>{const C=new Map(I);return C.delete(l),C})},[]);return{overrides:r,toggle:o,revertOverride:g}}const QHA=()=>{const[e,A]=aA.useState(dHA),[t,i]=aA.useState([]),[r,n]=aA.useState(null),[a,s]=aA.useState([]),[o,g]=aA.useState(null),[l,I]=aA.useState(!1),[C,E]=aA.useState(!1),[u,d]=aA.useState(!1),[Q,f]=aA.useState(!1),[p,y]=aA.useState(!1),[D,S]=aA.useState(""),[k,R]=aA.useState(()=>window.innerWidth>=768),[b,N]=aA.useState(!1),[T,L]=aA.useState(()=>CIA()),[K,H]=aA.useState(a9A),[x,U]=aA.useState(g9A),[G,F]=aA.useState(()=>Ke.getItem("plannotator-tater-mode")==="true"),[O,P]=aA.useState(()=>TO()),q=aA.useRef(null),[Y,z]=aA.useState("full");aA.useLayoutEffect(()=>{const re=q.current;if(!re)return;const Pe=Et=>Et>=800?"full":Et>=680?"short":"icon";z(Pe(re.getBoundingClientRect().width));const Xe=new ResizeObserver(([Et])=>{const ei=Pe(Et.contentRect.width);z(Cr=>Cr===ei?Cr:ei)});return Xe.observe(re),()=>Xe.disconnect()},[]);const[j,X]=aA.useState(!1),[_,gA]=aA.useState(null),[eA,dA]=aA.useState(),[tA,oA]=aA.useState(!1),[nA,rA]=aA.useState([]),[EA,cA]=aA.useState(!1),[wA,uA]=aA.useState(null),[PA,sA]=aA.useState(void 0),[ee,SA]=aA.useState(!0),[XA,ie]=aA.useState(!1),[oe,GA]=aA.useState(null),[$A,HA]=aA.useState(null),[zA,le]=aA.useState(!1),[MA,Ae]=aA.useState("bypassPermissions"),[BA,vA]=aA.useState(!0),[Z,yA]=aA.useState(void 0),[fA,LA]=aA.useState(void 0),[kA,hA]=aA.useState(null),[TA,NA]=aA.useState(null);aA.useEffect(()=>{document.title=kA?`${kA.display} · Plannotator`:"Plannotator"},[kA]);const[YA,jA]=aA.useState(),[ae,mA]=aA.useState(null),[KA,UA]=aA.useState(!1),[se,Ne]=aA.useState("clean"),[ve,iA]=aA.useState(null),[Ie,ce]=aA.useState(null),De=aA.useRef(null),{ref:Se,viewport:Oe,onViewportReady:Ge}=u9A();E9A();const Ve=UZ({storageKey:"plannotator-panel-width"}),St=UZ({storageKey:"plannotator-toc-width",defaultWidth:240,minWidth:160,maxWidth:400,side:"left"}),At=Ve.isDragging||St.isDragging,rt=b9A(TO().tocEnabled);aA.useEffect(()=>{O.tocEnabled?rt.open("toc"):rt.close()},[O.tocEnabled]),aA.useEffect(()=>{rt.activeTab==="toc"&&KA&&UA(!1)},[rt.activeTab]),aA.useEffect(()=>{if(!KA)return;const re=Pe=>{Pe.key==="Escape"&&UA(!1)};return document.addEventListener("keydown",re),()=>document.removeEventListener("keydown",re)},[KA]);const ht=T9A(e,ve,Ie),je=F9A({markdown:e,annotations:t,selectedAnnotationId:r,globalAttachments:nA,setMarkdown:A,setAnnotations:i,setSelectedAnnotationId:n,setGlobalAttachments:rA,viewerRef:De,sidebar:rt}),et=Y9A({markdown:e,viewerRef:De,linkedDocHook:je,setMarkdown:A,setAnnotations:i,setSelectedAnnotationId:n,setSubmitted:GA}),ot=Z9A(),Ci=aA.useMemo(()=>fZ()?FI(TI()):"",[O]),He=aA.useMemo(()=>!!TA||MZ()||fZ(),[TA,O]),WA=aA.useMemo(()=>{const re=TA?[TA]:[],Pe=MZ()?p5().directories:[];return[...new Set([...re,...Pe])]},[TA,O]);aA.useEffect(()=>{He||ot.setActiveFile(null)},[He]),aA.useEffect(()=>{Ci||ot.clearVaultDirs()},[Ci]),aA.useEffect(()=>{if(rt.activeTab==="files"&&He){if(WA.length>0){const re=ot.dirs.filter(Xe=>!Xe.isVault).map(Xe=>Xe.path);(WA.some(Xe=>!re.includes(Xe))||re.some(Xe=>!WA.includes(Xe)))&&ot.fetchAll(WA)}Ci&&!ot.dirs.find(re=>re.isVault&&re.path===Ci&&!re.error)&&ot.addVaultDir(Ci)}},[rt.activeTab,He,WA,Ci]);const be=Qn.useCallback((re,Pe)=>{const Et=ot.dirs.find(ei=>ei.path===Pe)?.isVault?ei=>`/api/reference/obsidian/doc?vaultPath=${encodeURIComponent(Pe)}&path=${encodeURIComponent(ei)}`:ei=>`/api/doc?path=${encodeURIComponent(ei)}&base=${encodeURIComponent(Pe)}`;je.open(re,Et,"files"),ot.setActiveFile(re)},[je,ot]),_e=Qn.useCallback(re=>{if(ot.dirs.find(Xe=>Xe.path===ot.activeDirPath)?.isVault&&ot.activeDirPath)je.open(re,Xe=>`/api/reference/obsidian/doc?vaultPath=${encodeURIComponent(ot.activeDirPath)}&path=${encodeURIComponent(Xe)}`);else if(ot.activeFile&&ot.activeDirPath){const Xe=je.filepath?.replace(/\/[^/]+$/,"")||ot.activeDirPath;je.open(re,Et=>`/api/doc?path=${encodeURIComponent(Et)}&base=${encodeURIComponent(Xe)}`)}else{const Xe=je.filepath?je.filepath.replace(/\/[^/]+$/,""):PA;Xe?je.open(re,Et=>`/api/doc?path=${encodeURIComponent(Et)}&base=${encodeURIComponent(Xe)}`):je.open(re)}},[ot.dirs,ot.activeDirPath,ot.activeFile,je,PA]),Kt=Qn.useCallback(()=>{je.back(),ot.setActiveFile(null),et.clearSelection()},[je,ot,et]),$t=aA.useMemo(()=>{const re=new Map;for(const[Pe,Xe]of je.getDocAnnotations()){const Et=Xe.annotations.length+Xe.globalAttachments.length;Et>0&&re.set(Pe,Et)}return re},[je.getDocAnnotations,t,nA]),Bt=aA.useMemo(()=>{const re=ot.dirs.map(Xe=>Xe.path);if(re.length===0)return $t;const Pe=new Map;for(const[Xe,Et]of $t)re.some(ei=>Xe.startsWith(ei+"/"))&&Pe.set(Xe,Et);return Pe},[$t,ot.dirs]),hi=Bt.size>0,Zi=aA.useMemo(()=>{const re=je.filepath;let Pe=0,Xe=0;for(const[Et,ei]of $t)Et!==re&&(Pe+=ei,Xe++);return Pe>0?{count:Pe,files:Xe}:void 0},[$t,je.filepath]),[mi,ke]=aA.useState(),ye=Qn.useRef(),xe=Qn.useCallback(()=>{const re=new Set($t.keys());re.size!==0&&((!rt.isOpen||rt.activeTab!=="files")&&rt.open("files"),ye.current&&clearTimeout(ye.current),ke(void 0),requestAnimationFrame(()=>{ke(re),ye.current=setTimeout(()=>ke(void 0),1200)}))},[$t,rt,hi]),Re=wA==="folder"?"file list":wA==="file"?"file":wA==="message"?"message":"plan",me=aA.useMemo(()=>a.filter(re=>re.type==="heading").length,[a]),Ct=V8A(Se,me,Oe),{editorAnnotations:xA,deleteEditorAnnotation:ir}=P9A(),{externalAnnotations:FA,updateExternalAnnotation:Yt,deleteExternalAnnotation:as}=q9A({enabled:j}),{reset:Fa}=W9A({viewerRef:De,externalAnnotations:FA,enabled:j&&!je.isActive&&!KA,planKey:e}),ci=aA.useMemo(()=>FA.length===0?t:[...t.filter(Pe=>Pe.source?!FA.some(Xe=>Xe.source===Pe.source&&Xe.type===Pe.type&&Xe.originalText===Pe.originalText):!0),...FA],[t,FA]),xs=aA.useMemo(()=>ci.filter(re=>!!re.diffContext),[ci]),lr=aA.useMemo(()=>ci.filter(re=>!re.diffContext),[ci]),{isSharedSession:Ri,isLoadingShared:fa,shareUrl:Or,shareUrlSize:ss,shortShareUrl:dr,isGeneratingShortUrl:Ls,shortUrlError:cr,pendingSharedAnnotations:dt,clearPendingSharedAnnotations:Rt,generateShortUrl:Yi,importFromShareUrl:ti,shareLoadError:zr,clearShareLoadError:Ir}=z8A(e,ci,nA,A,i,rA,()=>{SA(!1)},Z,fA),{draftBanner:An,restoreDraft:en,dismissDraft:qe}=K9A({annotations:ci,globalAttachments:nA,isApiMode:j,isSharedSession:Ri,submitted:!!oe}),W=Qn.useCallback(()=>{const{annotations:re,globalAttachments:Pe}=en();re.length>0&&(i(re),Pe.length>0&&rA(Pe),setTimeout(()=>{De.current?.applySharedAnnotations(re.filter(Xe=>!Xe.diffContext))},100))},[en]),{getAgentWarning:$}=lIA(_);aA.useEffect(()=>{if(dt&&dt.length>0){const re=setTimeout(()=>{De.current?.clearAllHighlights(),De.current?.applySharedAnnotations(dt.filter(Pe=>!Pe.diffContext)),Rt(),Fa()},100);return()=>clearTimeout(re)}},[dt,Rt,Fa]);const CA=re=>{F(re),Ke.setItem("plannotator-tater-mode",String(re))},DA=re=>{H(re),s9A(re)},OA=re=>{U(re),l9A(re)};C9A(x,OA),aA.useEffect(()=>{fa||Ri||fetch("/api/plan").then(re=>{if(!re.ok)throw new Error("Not in API mode");return re.json()}).then(re=>{kn.init(re.serverConfig),dA(re.serverConfig?.gitUser),re.mode==="archive"?(A(re.plan||""),re.archivePlans&&et.init(re.archivePlans),et.fetchPlans(),vA(!1),rt.open("archive")):re.mode==="annotate-folder"?A(""):re.plan&&A(re.plan),X(!0),(re.mode==="annotate"||re.mode==="annotate-last"||re.mode==="annotate-folder")&&cA(!0),re.mode==="annotate-folder"&&rt.open("files"),re.mode&&re.mode!=="archive"&&uA(re.mode==="annotate-last"?"message":re.mode==="annotate-folder"?"folder":"file"),re.filePath&&sA(re.mode==="annotate-folder"?re.filePath:re.filePath.replace(/\/[^/]+$/,"")),re.sharingEnabled!==void 0&&vA(re.sharingEnabled),re.shareBaseUrl&&yA(re.shareBaseUrl),re.pasteApiUrl&&LA(re.pasteApiUrl),re.repoInfo&&hA(re.repoInfo),re.projectRoot&&NA(re.projectRoot),re.previousPlan!==void 0&&iA(re.previousPlan),re.versionInfo&&ce(re.versionInfo),re.origin&&(gA(re.origin),re.origin==="claude-code"&&l8A()&&le(!0),Ae(aIA().mode)),re.isWSL&&oA(!0)}).catch(()=>{X(!1)}).finally(()=>SA(!1))},[fa,Ri]),aA.useEffect(()=>{const{frontmatter:re}=uiA(e);g(re),s(BiA(e))},[e]);const _A=aA.useRef(!1),Ee=aA.useRef({}),fe=aA.useRef(null);aA.useEffect(()=>{_A.current=!1,Ee.current={},fe.current=null},[e]),aA.useEffect(()=>{if(!j||!e||Ri||EA||et.archiveMode||_A.current)return;const re={},Pe=[],Xe=TI();if(Xe.autoSave&&Xe.enabled){const hr=FI(Xe);hr&&(re.obsidian={vaultPath:hr,folder:Xe.folder||"plannotator",plan:e,...Xe.filenameFormat&&{filenameFormat:Xe.filenameFormat},...Xe.filenameSeparator&&Xe.filenameSeparator!=="space"&&{filenameSeparator:Xe.filenameSeparator}},Pe.push("Obsidian"))}const Et=yE();Et.autoSave&&Et.enabled&&(re.bear={plan:e,customTags:Et.customTags,tagPosition:Et.tagPosition},Pe.push("Bear"));const ei=Cd();if(ei.autoSave&&Xy()&&(re.octarine={plan:e,workspace:ei.workspace,folder:ei.folder||"plannotator"},Pe.push("Octarine")),Pe.length===0)return;_A.current=!0;const Cr=fetch("/api/save-notes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(re)}).then(hr=>hr.json()).then(hr=>{const jo={...re.obsidian?{obsidian:!!hr.results?.obsidian?.success}:{},...re.bear?{bear:!!hr.results?.bear?.success}:{},...re.octarine?{octarine:!!hr.results?.octarine?.success}:{}};Ee.current=jo;const Tl=Pe.filter(Gh=>!hr.results?.[Gh.toLowerCase()]?.success);return Tl.length===0?mA({type:"success",message:`Auto-saved to ${Pe.join(" & ")}`}):mA({type:"error",message:`Auto-save failed for ${Tl.join(" & ")}`}),jo}).catch(()=>(Ee.current={},mA({type:"error",message:"Auto-save failed"}),{})).finally(()=>setTimeout(()=>mA(null),3e3));fe.current=Cr},[j,e,Ri,EA]),aA.useEffect(()=>{const re=Pe=>{const Xe=Pe.clipboardData?.items;if(Xe){for(const Et of Xe)if(Et.type.startsWith("image/")){Pe.preventDefault();const ei=Et.getAsFile();if(ei){const Cr=c3(ei.name,nA.map(jo=>jo.name)),hr=URL.createObjectURL(ei);HA({file:ei,blobUrl:hr,initialName:Cr})}break}}};return document.addEventListener("paste",re),()=>document.removeEventListener("paste",re)},[nA]);const $e=async(re,Pe,Xe)=>{if($A)try{const Et=new FormData,ei=Pe?new File([re],"annotated.png",{type:"image/png"}):$A.file;Et.append("file",ei);const Cr=await fetch("/api/upload",{method:"POST",body:Et});if(Cr.ok){const hr=await Cr.json();rA(jo=>[...jo,{path:hr.path,name:Xe}])}}catch{}finally{URL.revokeObjectURL($A.blobUrl),HA(null)}},zt=()=>{$A&&(URL.revokeObjectURL($A.blobUrl),HA(null))},Lt=async()=>{ie(!0);try{const re=TI(),Pe=yE(),Xe=Cd(),Et=Q5(),ei=mS(),Cr=Pe.autoSave&&fe.current?await fe.current:Ee.current,hr={};_==="claude-code"&&(hr.permissionMode=MA);const jo=a8A(Et);jo&&(hr.agentSwitch=jo),hr.planSave={enabled:ei.enabled,...ei.customPath&&{customPath:ei.customPath}};const Tl=FI(re);re.enabled&&Tl&&(hr.obsidian={vaultPath:Tl,folder:re.folder||"plannotator",plan:e,...re.filenameFormat&&{filenameFormat:re.filenameFormat},...re.filenameSeparator&&re.filenameSeparator!=="space"&&{filenameSeparator:re.filenameSeparator}}),Pe.enabled&&!(Pe.autoSave&&Cr.bear)&&(hr.bear={plan:e,customTags:Pe.customTags,tagPosition:Pe.tagPosition}),Xy()&&(hr.octarine={plan:e,workspace:Xe.workspace,folder:Xe.folder||"plannotator"});const Gh=Array.from(je.getDocAnnotations().values()).some(Dm=>Dm.annotations.length>0||Dm.globalAttachments.length>0);(ci.length>0||nA.length>0||Gh||xA.length>0)&&(hr.feedback=_i),await fetch("/api/approve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(hr)}),GA("approved")}catch{ie(!1)}},ii=async()=>{ie(!0);try{const re=mS();await fetch("/api/deny",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({feedback:_i,planSave:{enabled:re.enabled,...re.customPath&&{customPath:re.customPath}}})}),GA("denied")}catch{ie(!1)}},Ai=async()=>{ie(!0);try{await fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({feedback:_i,annotations:ci})}),GA("denied")}catch{ie(!1)}};aA.useEffect(()=>{const re=Pe=>{if(Pe.key!=="Enter"||!(Pe.metaKey||Pe.ctrlKey))return;const Xe=Pe.target?.tagName;if(Xe==="INPUT"||Xe==="TEXTAREA"||l||C||u||Q||p||zA||$A||oe||XA||!j||je.isActive)return;if(Pe.preventDefault(),EA){Ai();return}const Et=je.getDocAnnotations(),ei=Array.from(Et.values()).some(Cr=>Cr.annotations.length>0||Cr.globalAttachments.length>0);if(ci.length===0&&xA.length===0&&!ei){if(_==="opencode"){const Cr=$();if(Cr){S(Cr),y(!0);return}}Lt()}else ii()};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[l,C,u,Q,p,zA,$A,oe,XA,j,je.isActive,t.length,FA.length,EA,_,$]);const Dt=re=>{i(Pe=>[...Pe,re]),n(re.id),R(!0)},Tt=Qn.useCallback(re=>{n(re),re&&window.innerWidth<768&&R(!0)},[]),ji=re=>{De.current?.removeHighlight(re),i(Pe=>Pe.filter(Xe=>Xe.id!==re)),r===re&&n(null)},Cn=hHA({blocks:a,annotations:t,addAnnotation:Dt,removeAnnotation:ji}),zn=re=>{const Pe=ci.find(Xe=>Xe.id===re);if(Pe?.source&&FA.some(Xe=>Xe.id===re)){as(re),r===re&&n(null);return}re.startsWith("ann-checkbox-")&&Pe&&Cn.revertOverride(Pe.blockId),ji(re)},rr=(re,Pe)=>{if(ci.find(Et=>Et.id===re)?.source&&FA.some(Et=>Et.id===re)){Yt(re,Pe);return}i(Et=>Et.map(ei=>ei.id===re?{...ei,...Pe}:ei))},tn=(re,Pe)=>{i(Xe=>Xe.map(Et=>Et.author===re?{...Et,author:Pe}:Et))},co=re=>{rA(Pe=>[...Pe,re])},qn=re=>{rA(Pe=>Pe.filter(Xe=>Xe.path!==re))},xg=re=>{},_i=aA.useMemo(()=>{const re=je.getDocAnnotations(),Pe=Array.from(re.values()).some(Cr=>Cr.annotations.length>0||Cr.globalAttachments.length>0),Xe=ci.length>0||nA.length>0,Et=xA.length>0;if(!Xe&&!Pe&&!Et)return"User reviewed the document and has no feedback.";let ei=Xe?YmA(a,ci,nA,wA==="message"?"Message Feedback":wA==="folder"?"Folder Feedback":wA==="file"?"File Feedback":"Plan Feedback",wA??"plan"):"";return Pe&&(ei+=HmA(re)),Et&&(ei+=PmA(xA)),ei},[a,ci,nA,je.getDocAnnotations,xA]),_c=Qn.useMemo(()=>q8A(),[]),Lg=Qn.useCallback(async re=>{if(!(!_c||XA||!Or)){ie(!0);try{const Pe=await W8A(re,_c,Or);Pe&&(mA(Pe),setTimeout(()=>mA(null),4e3),Pe.type==="success"&&GA(re===bw.Approve?"approved":"denied"))}finally{ie(!1)}}},[_c,XA,Or]),Ju=Qn.useCallback(()=>Lg(bw.Approve),[Lg]),mm=Qn.useCallback(()=>Lg(bw.Feedback),[Lg]),ym=()=>{const re=new Blob([_i],{type:"text/plain"}),Pe=URL.createObjectURL(re),Xe=document.createElement("a");Xe.href=Pe,Xe.download="annotations.md",Xe.click(),URL.revokeObjectURL(Pe),mA({type:"success",message:"Downloaded annotations"}),setTimeout(()=>mA(null),3e3)},Xc=async re=>{const Pe={};if(re==="obsidian"){const Et=TI(),ei=FI(Et);ei&&(Pe.obsidian={vaultPath:ei,folder:Et.folder||"plannotator",plan:e,...Et.filenameFormat&&{filenameFormat:Et.filenameFormat},...Et.filenameSeparator&&Et.filenameSeparator!=="space"&&{filenameSeparator:Et.filenameSeparator}})}if(re==="bear"){const Et=yE();Pe.bear={plan:e,customTags:Et.customTags,tagPosition:Et.tagPosition}}if(re==="octarine"){const Et=Cd();Pe.octarine={plan:e,workspace:Et.workspace,folder:Et.folder||"plannotator"}}const Xe=re==="obsidian"?"Obsidian":re==="bear"?"Bear":"Octarine";try{const Cr=(await(await fetch("/api/save-notes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Pe)})).json()).results?.[re];Cr?.success?mA({type:"success",message:`Saved to ${Xe}`}):mA({type:"error",message:Cr?.error||"Save failed"})}catch{mA({type:"error",message:"Save failed"})}setTimeout(()=>mA(null),3e3)},WR=async()=>{const re=V9A(window.location.origin);try{await navigator.clipboard.writeText(re),mA({type:"success",message:"Agent instructions copied"})}catch{mA({type:"error",message:"Failed to copy"})}setTimeout(()=>mA(null),3e3)},Fh=async()=>{try{await navigator.clipboard.writeText(Or),mA({type:"success",message:"Share link copied"})}catch{mA({type:"error",message:"Failed to copy"})}setTimeout(()=>mA(null),3e3)};aA.useEffect(()=>{const re=Pe=>{if(Pe.key!=="s"||!(Pe.metaKey||Pe.ctrlKey))return;const Xe=Pe.target?.tagName;if(Xe==="INPUT"||Xe==="TEXTAREA"||l||u||Q||p||zA||$A||oe||!j)return;Pe.preventDefault();const Et=gIA(),ei=QZ(),Cr=yE().enabled,hr=Xy();Et==="download"?ym():Et==="obsidian"&&ei?Xc("obsidian"):Et==="bear"&&Cr?Xc("bear"):Et==="octarine"&&hr?Xc("octarine"):(jA("notes"),I(!0))};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[l,u,Q,p,zA,$A,oe,j,e,_i]),aA.useEffect(()=>{const re=Pe=>{if(Pe.key!=="p"||!(Pe.metaKey||Pe.ctrlKey))return;const Xe=Pe.target?.tagName;Xe==="INPUT"||Xe==="TEXTAREA"||l||u||Q||p||zA||$A||oe||(Pe.preventDefault(),window.print())};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[l,u,Q,p,zA,$A,oe]);const Ll=aA.useMemo(()=>UmA(_),[_]),zu=aA.useMemo(()=>({compact:832,default:1040,wide:1280})[O.planWidth]??832,[O.planWidth]);return w.jsx(UYA,{defaultTheme:"dark",children:w.jsxs("div",{"data-print-region":"root",className:"h-screen flex flex-col bg-background overflow-hidden",children:[w.jsxs("header",{className:"h-12 flex items-center justify-between px-2 md:px-4 border-b border-border/50 bg-card/50 backdrop-blur-xl sticky top-0 z-[50]",children:[w.jsx("div",{className:"flex items-center gap-2 md:gap-3",children:w.jsx("a",{href:"https://plannotator.ai",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 md:gap-2 hover:opacity-80 transition-opacity",children:w.jsx("span",{className:"text-sm font-semibold tracking-tight",children:"Plannotator"})})}),w.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[_c&&!j&&Ri&&w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"w-px h-5 bg-border/50 mx-1 hidden md:block"}),w.jsx(kZ,{onClick:mm,disabled:XA||!Or,isLoading:XA,title:"Send feedback to bot"}),w.jsx(xZ,{onClick:Ju,disabled:XA||!Or,isLoading:XA,title:"Approve design and notify bot"})]}),j&&!je.isActive&&et.archiveMode&&w.jsxs(w.Fragment,{children:[w.jsxs("button",{onClick:et.copy,className:"px-2.5 py-1 rounded-md text-xs font-medium transition-all bg-muted text-foreground hover:bg-muted/80 border border-border",title:"Copy plan content",children:[w.jsx("span",{className:"hidden md:inline",children:"Copy"}),w.jsx("svg",{className:"w-4 h-4 md:hidden",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})]}),w.jsx("button",{onClick:et.done,className:"px-2.5 py-1 rounded-md text-xs font-medium transition-all bg-success text-success-foreground hover:opacity-90",title:"Close archive",children:"Done"})]}),j&&(!je.isActive||EA)&&!et.archiveMode&&w.jsxs(w.Fragment,{children:[w.jsx(kZ,{onClick:()=>{if(EA){Ai();return}const re=je.getDocAnnotations(),Pe=Array.from(re.values()).some(Xe=>Xe.annotations.length>0||Xe.globalAttachments.length>0);ci.length===0&&xA.length===0&&!Pe?d(!0):ii()},disabled:XA,isLoading:XA,label:EA?ci.length>0||xA.length>0||je.docAnnotationCount>0?"Send Annotations":"Done":"Send Feedback",title:EA?ci.length>0||xA.length>0||je.docAnnotationCount>0?"Send Annotations":"Done":"Send Feedback"}),!EA&&w.jsxs("div",{className:"relative group/approve",children:[w.jsx(xZ,{onClick:()=>{if(_==="claude-code"&&ci.length>0){f(!0);return}if(_==="opencode"){const re=$();if(re){S(re),y(!0);return}}Lt()},disabled:XA,isLoading:XA,dimmed:(_==="claude-code"||_==="gemini-cli")&&ci.length>0}),(_==="claude-code"||_==="gemini-cli")&&ci.length>0&&w.jsxs("div",{className:"absolute top-full right-0 mt-2 px-3 py-2 bg-popover border border-border rounded-lg shadow-xl text-xs text-foreground w-56 text-center opacity-0 invisible group-hover/approve:opacity-100 group-hover/approve:visible transition-all pointer-events-none z-50",children:[w.jsx("div",{className:"absolute bottom-full right-4 border-4 border-transparent border-b-border"}),w.jsx("div",{className:"absolute bottom-full right-4 mt-px border-4 border-transparent border-b-popover"}),Ll," doesn't support feedback on approval. Your annotations won't be seen."]})]}),w.jsx("div",{className:"w-px h-5 bg-border/50 mx-1 hidden md:block"})]}),w.jsx("button",{onClick:()=>R(!k),className:`p-1.5 rounded-md text-xs font-medium transition-all ${k?"bg-primary/15 text-primary":"text-muted-foreground hover:text-foreground hover:bg-muted"}`,title:k?"Hide annotations":"Show annotations",children:w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),w.jsx("div",{className:"hidden",children:w.jsx(O8A,{taterMode:G,onTaterModeChange:CA,onIdentityChange:tn,origin:_,onUIPreferencesChange:P,externalOpen:b,onExternalClose:()=>N(!1),gitUser:eA})}),w.jsx(h9A,{appVersion:"0.17.6",hasNewSettingsHints:T,onOpenSettings:()=>{T&&(EIA(),L(!1)),N(!0)},onOpenExport:()=>{jA(void 0),I(!0)},onCopyAgentInstructions:WR,onDownloadAnnotations:ym,onPrint:()=>window.print(),onCopyShareLink:Fh,onOpenImport:()=>E(!0),onSaveToObsidian:()=>Xc("obsidian"),onSaveToBear:()=>Xc("bear"),onSaveToOctarine:()=>Xc("octarine"),sharingEnabled:BA,isApiMode:j,agentInstructionsEnabled:j&&!et.archiveMode&&!EA,obsidianConfigured:QZ(),bearConfigured:yE().enabled,octarineConfigured:Xy()})]})]}),je.error&&w.jsxs("div",{className:"bg-destructive/10 border-b border-destructive/20 px-4 py-2 flex items-center gap-2 flex-shrink-0",children:[w.jsx("span",{className:"text-xs text-destructive",children:je.error}),w.jsx("button",{onClick:je.dismissError,className:"ml-auto text-xs text-destructive/60 hover:text-destructive",children:"dismiss"})]}),w.jsx(UlA.Provider,{value:Oe,children:w.jsxs("div",{"data-print-region":"content",className:`flex-1 flex overflow-hidden relative z-0 ${At?"select-none":""}`,children:[G&&w.jsx($YA,{}),!rt.isOpen&&w.jsx(j9A,{activeTab:rt.activeTab,onToggleTab:rt.toggleTab,hasDiff:ht.hasPreviousVersion,showVersionsTab:Ie!==null&&Ie.totalVersions>1,showFilesTab:He&&!et.archiveMode,hasFileAnnotations:hi,className:"hidden lg:flex absolute left-0 top-0 z-10"}),rt.isOpen&&w.jsxs(w.Fragment,{children:[w.jsx(oHA,{activeTab:rt.activeTab,onTabChange:re=>{rt.toggleTab(re),re==="archive"&&!et.archiveMode&&et.fetchPlans()},onClose:rt.close,width:St.width,blocks:a,annotations:t,activeSection:Ct,onTocNavigate:xg,linkedDocFilepath:je.filepath,onLinkedDocBack:je.isActive?Kt:void 0,backLabel:Re,showFilesTab:He&&!et.archiveMode,fileAnnotationCounts:Bt,highlightedFiles:mi,fileBrowser:ot,onFilesSelectFile:be,onFilesFetchAll:()=>ot.fetchAll(WA),onFilesRetryVaultDir:re=>ot.addVaultDir(re),hasFileAnnotations:hi,showVersionsTab:Ie!==null&&Ie.totalVersions>1,versionInfo:Ie,versions:ht.versions,selectedBaseVersion:ht.diffBaseVersion,onSelectBaseVersion:ht.selectBaseVersion,isPlanDiffActive:KA,hasPreviousVersion:ht.hasPreviousVersion,onActivatePlanDiff:()=>UA(!0),isLoadingVersions:ht.isLoadingVersions,isSelectingVersion:ht.isSelectingVersion,fetchingVersion:ht.fetchingVersion,onFetchVersions:ht.fetchVersions,showArchiveTab:j&&!EA,archivePlans:et.plans,selectedArchiveFile:et.selectedFile,onArchiveSelect:et.select,isLoadingArchive:et.isLoading}),w.jsx(KZ,{...St.handleProps,className:"hidden lg:block",side:"left"})]}),w.jsxs(Yp,{element:"main",className:`flex-1 min-w-0 bg-grid ${rt.isOpen?"":"lg:pl-[30px]"}`,"data-print-region":"document",onViewportReady:Ge,children:[w.jsx(zQ,{isOpen:!!An,onClose:qe,onConfirm:W,title:"Draft Recovered",message:An?`Found ${An.count} annotation${An.count!==1?"s":""} from ${An.timeAgo}. Would you like to restore them?`:"",confirmText:"Restore",cancelText:"Dismiss",showCancel:!0}),w.jsxs("div",{ref:q,className:"min-h-full flex flex-col items-center px-2 py-3 md:px-10 md:py-8 xl:px-16 relative z-10",children:[!KA&&!et.archiveMode&&O.stickyActionsEnabled&&w.jsx(VYA,{inputMethod:x,onInputMethodChange:OA,mode:K,onModeChange:DA,taterMode:G,repoInfo:kA,planDiffStats:ht.diffStats,isPlanDiffActive:KA,hasPreviousVersion:ht.hasPreviousVersion,onPlanDiffToggle:()=>UA(!KA),archiveInfo:et.currentInfo,maxWidth:zu,remountToken:je.isActive?`doc:${je.filepath}`:"plan"}),!KA&&!et.archiveMode&&w.jsx("div",{"data-print-hide":!0,className:"w-full mb-3 md:mb-4 flex items-center justify-start",style:{maxWidth:zu},children:w.jsx(ZcA,{inputMethod:x,onInputMethodChange:OA,mode:K,onModeChange:DA,taterMode:G})}),ht.diffBlocks&&ht.diffStats&&w.jsx("div",{className:"w-full flex justify-center",style:{display:KA?void 0:"none"},children:w.jsx(BHA,{diffBlocks:ht.diffBlocks,diffStats:ht.diffStats,diffMode:se,onDiffModeChange:Ne,onPlanDiffToggle:()=>UA(!1),repoInfo:kA,baseVersionLabel:ht.diffBaseVersion!=null?`v${ht.diffBaseVersion}`:void 0,baseVersion:ht.diffBaseVersion??void 0,maxWidth:zu,annotations:xs,onAddAnnotation:Dt,onSelectAnnotation:Tt,selectedAnnotationId:r,mode:K})}),wA==="folder"&&!e&&!je.isActive&&w.jsx("div",{className:"w-full flex justify-center",children:w.jsxs("div",{className:"w-full max-w-3xl p-12 text-center text-muted-foreground",children:[w.jsx("p",{className:"text-lg font-medium mb-2",children:"Select a file to annotate"}),w.jsx("p",{className:"text-sm",children:"Pick a markdown file from the sidebar to begin."})]})}),w.jsx("div",{className:"w-full flex justify-center",style:{display:KA&&ht.diffBlocks||wA==="folder"&&!e&&!je.isActive?"none":void 0},children:w.jsx(E5A,{ref:De,blocks:a,markdown:e,frontmatter:o,annotations:lr,onAddAnnotation:Dt,onSelectAnnotation:Tt,selectedAnnotationId:r,mode:K,inputMethod:x,taterMode:G,globalAttachments:nA,onAddGlobalAttachment:co,onRemoveGlobalAttachment:qn,repoInfo:kA,stickyActions:O.stickyActionsEnabled,planDiffStats:je.isActive?null:ht.diffStats,isPlanDiffActive:KA,onPlanDiffToggle:()=>UA(!KA),hasPreviousVersion:!je.isActive&&ht.hasPreviousVersion,showDemoBadge:!j&&!fa&&!Ri,maxWidth:zu,onOpenLinkedDoc:_e,linkedDocInfo:je.isActive?{filepath:je.filepath,onBack:Kt,label:ot.dirs.find(re=>re.path===ot.activeDirPath)?.isVault?"Vault File":ot.activeFile?"File":void 0,backLabel:Re}:null,imageBaseDir:PA,copyLabel:wA==="message"?"Copy message":wA==="file"||wA==="folder"?"Copy file":void 0,archiveInfo:et.currentInfo,onToggleCheckbox:Cn.toggle,checkboxOverrides:Cn.overrides,actionsLabelMode:Y},je.isActive?`doc:${je.filepath}`:"plan")})]})]}),k&&w.jsx(KZ,{...Ve.handleProps,className:"hidden md:block",side:"right"}),w.jsx(RYA,{isOpen:k,blocks:a,annotations:ci,selectedId:r,onSelect:n,onDelete:zn,onEdit:rr,sharingEnabled:BA,width:Ve.width,editorAnnotations:xA,onDeleteEditorAnnotation:ir,onClose:()=>R(!1),onQuickCopy:async()=>{await navigator.clipboard.writeText(hiA(_i))},onShare:Or?()=>{R(!1),jA("share"),I(!0)}:void 0,otherFileAnnotations:Zi,onOtherFileAnnotationsClick:xe})]})}),w.jsx(GYA,{isOpen:l,onClose:()=>{I(!1),jA(void 0)},shareUrl:Or,shareUrlSize:ss,shortShareUrl:dr,isGeneratingShortUrl:Ls,shortUrlError:cr,onGenerateShortUrl:Yi,annotationsOutput:_i,annotationCount:ci.length,taterSprite:G?w.jsx(h5,{}):void 0,sharingEnabled:BA,markdown:e,isApiMode:j,initialTab:YA}),w.jsx(OYA,{isOpen:C,onClose:()=>E(!1),onImport:ti,shareBaseUrl:Z}),w.jsx(zQ,{isOpen:u,onClose:()=>d(!1),title:"Add Annotations First",message:`To provide feedback, select text in the plan and add annotations. ${Ll} will use your annotations to revise the plan.`,variant:"info"}),w.jsx(zQ,{isOpen:Q,onClose:()=>f(!1),onConfirm:()=>{f(!1),Lt()},title:"Annotations Won't Be Sent",message:w.jsxs(w.Fragment,{children:[Ll," doesn't yet support feedback on approval. Your ",ci.length," annotation",ci.length!==1?"s":""," will be lost."]}),subMessage:w.jsxs(w.Fragment,{children:["To send feedback, use ",w.jsx("strong",{children:"Send Feedback"})," instead.",w.jsx("br",{}),w.jsx("br",{}),"Want this feature? Upvote these issues:",w.jsx("br",{}),w.jsx("a",{href:"https://github.com/anthropics/claude-code/issues/16001",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"#16001"})," · ",w.jsx("a",{href:"https://github.com/anthropics/claude-code/issues/15755",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"#15755"})]}),confirmText:"Approve Anyway",cancelText:"Cancel",variant:"warning",showCancel:!0}),w.jsx(zQ,{isOpen:p,onClose:()=>y(!1),onConfirm:()=>{y(!1),Lt()},title:"Agent Not Found",message:D,subMessage:w.jsxs(w.Fragment,{children:["You can change the agent in ",w.jsx("strong",{children:"Settings"}),", or approve anyway and OpenCode will use the default agent."]}),confirmText:"Approve Anyway",cancelText:"Cancel",variant:"warning",showCancel:!0}),w.jsx(zQ,{isOpen:!!zr&&!j,onClose:Ir,title:"Shared Plan Could Not Be Loaded",message:zr,subMessage:"You are viewing a demo plan. This is sample content — it is not your data or anyone else's.",variant:"warning"}),ae&&w.jsx("div",{className:`fixed top-16 right-4 z-50 px-3 py-2 rounded-lg text-xs font-medium shadow-lg transition-opacity ${ae.type==="success"?"bg-success/15 text-success border border-success/30":"bg-destructive/15 text-destructive border border-destructive/30"}`,children:ae.message}),w.jsx(X8A,{submitted:oe,title:et.archiveMode?"Archive Closed":oe==="approved"?"Plan Approved":EA?"Annotations Sent":"Feedback Sent",subtitle:et.archiveMode?"You can reopen with plannotator archive.":oe==="approved"?`${Ll} will proceed with the implementation.`:EA?`${Ll} will address your annotations on the ${wA==="message"?"message":wA==="folder"?"files":"file"}.`:`${Ll} will revise the plan based on your annotations.`,agentLabel:Ll}),w.jsx(r9A,{origin:_,isWSL:tA}),w.jsx(NiA,{isOpen:!!$A,imageSrc:$A?.blobUrl??"",initialName:$A?.initialName,onAccept:$e,onClose:zt}),w.jsx(S9A,{isOpen:zA,onComplete:re=>{Ae(re),le(!1)}})]})})},xIA=document.getElementById("root");if(!xIA)throw new Error("Could not find root element to mount to");const fHA=OmA.createRoot(xIA);fHA.render(w.jsx(Qn.StrictMode,{children:w.jsx(QHA,{})}));class us{constructor(A,t,i){this.lexer=void 0,this.start=void 0,this.end=void 0,this.lexer=A,this.start=t,this.end=i}static range(A,t){return t?!A||!A.loc||!t.loc||A.loc.lexer!==t.loc.lexer?null:new us(A.loc.lexer,A.loc.start,t.loc.end):A&&A.loc}}class Xs{constructor(A,t){this.text=void 0,this.loc=void 0,this.noexpand=void 0,this.treatAsRelax=void 0,this.text=A,this.loc=t}range(A,t){return new Xs(t,us.range(this,A))}}class Ze{constructor(A,t){this.name=void 0,this.position=void 0,this.length=void 0,this.rawMessage=void 0;var i="KaTeX parse error: "+A,r,n,a=t&&t.loc;if(a&&a.start<=a.end){var s=a.lexer.input;r=a.start,n=a.end,r===s.length?i+=" at end of input: ":i+=" at position "+(r+1)+": ";var o=s.slice(r,n).replace(/[^]/g,"$&̲"),g;r>15?g="…"+s.slice(r-15,r):g=s.slice(0,r);var l;n+15<s.length?l=s.slice(n,n+15)+"…":l=s.slice(n),i+=g+o+l}var I=new Error(i);return I.name="ParseError",I.__proto__=Ze.prototype,I.position=r,r!=null&&n!=null&&(I.length=n-r),I.rawMessage=A,I}}Ze.prototype.__proto__=Error.prototype;var pHA=function(A,t){return A===void 0?t:A},mHA=/([A-Z])/g,yHA=function(A){return A.replace(mHA,"-$1").toLowerCase()},DHA={"&":"&amp;",">":"&gt;","<":"&lt;",'"':"&quot;","'":"&#x27;"},wHA=/[&><"']/g;function vHA(e){return String(e).replace(wHA,A=>DHA[A])}var LIA=function e(A){return A.type==="ordgroup"||A.type==="color"?A.body.length===1?e(A.body[0]):A:A.type==="font"?e(A.body):A},SHA=function(A){var t=LIA(A);return t.type==="mathord"||t.type==="textord"||t.type==="atom"},bHA=function(A){if(!A)throw new Error("Expected non-null, but got "+String(A));return A},RHA=function(A){var t=/^[\x00-\x20]*([^\\/#?]*?)(:|&#0*58|&#x0*3a|&colon)/i.exec(A);return t?t[2]!==":"||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():"_relative"},Oi={deflt:pHA,escape:vHA,hyphenate:yHA,getBaseElem:LIA,isCharacterBox:SHA,protocolFromUrl:RHA},h0={displayMode:{type:"boolean",description:"Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.",cli:"-d, --display-mode"},output:{type:{enum:["htmlAndMathml","html","mathml"]},description:"Determines the markup language of the output.",cli:"-F, --format <type>"},leqno:{type:"boolean",description:"Render display math in leqno style (left-justified tags)."},fleqn:{type:"boolean",description:"Render display math flush left."},throwOnError:{type:"boolean",default:!0,cli:"-t, --no-throw-on-error",cliDescription:"Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error."},errorColor:{type:"string",default:"#cc0000",cli:"-c, --error-color <color>",cliDescription:"A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.",cliProcessor:e=>"#"+e},macros:{type:"object",cli:"-m, --macro <def>",cliDescription:"Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).",cliDefault:[],cliProcessor:(e,A)=>(A.push(e),A)},minRuleThickness:{type:"number",description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:"--min-rule-thickness <size>",cliProcessor:parseFloat},colorIsTextColor:{type:"boolean",description:"Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.",cli:"-b, --color-is-text-color"},strict:{type:[{enum:["warn","ignore","error"]},"boolean","function"],description:"Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.",cli:"-S, --strict",cliDefault:!1},trust:{type:["boolean","function"],description:"Trust the input, enabling all HTML features such as \\url.",cli:"-T, --trust"},maxSize:{type:"number",default:1/0,description:"If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large",processor:e=>Math.max(0,e),cli:"-s, --max-size <n>",cliProcessor:parseInt},maxExpand:{type:"number",default:1e3,description:"Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.",processor:e=>Math.max(0,e),cli:"-e, --max-expand <n>",cliProcessor:e=>e==="Infinity"?1/0:parseInt(e)},globalGroup:{type:"boolean",cli:!1}};function NHA(e){if(e.default)return e.default;var A=e.type,t=Array.isArray(A)?A[0]:A;if(typeof t!="string")return t.enum[0];switch(t){case"boolean":return!1;case"string":return"";case"number":return 0;case"object":return{}}}class y5{constructor(A){this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,A=A||{};for(var t in h0)if(h0.hasOwnProperty(t)){var i=h0[t];this[t]=A[t]!==void 0?i.processor?i.processor(A[t]):A[t]:NHA(i)}}reportNonstrict(A,t,i){var r=this.strict;if(typeof r=="function"&&(r=r(A,t,i)),!(!r||r==="ignore")){if(r===!0||r==="error")throw new Ze("LaTeX-incompatible input and strict mode is set to 'error': "+(t+" ["+A+"]"),i);r==="warn"?typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(t+" ["+A+"]")):typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+r+"': "+t+" ["+A+"]"))}}useStrictBehavior(A,t,i){var r=this.strict;if(typeof r=="function")try{r=r(A,t,i)}catch{r="error"}return!r||r==="ignore"?!1:r===!0||r==="error"?!0:r==="warn"?(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(t+" ["+A+"]")),!1):(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+r+"': "+t+" ["+A+"]")),!1)}isTrusted(A){if(A.url&&!A.protocol){var t=Oi.protocolFromUrl(A.url);if(t==null)return!1;A.protocol=t}var i=typeof this.trust=="function"?this.trust(A):this.trust;return!!i}}class mI{constructor(A,t,i){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=A,this.size=t,this.cramped=i}sup(){return el[MHA[this.id]]}sub(){return el[kHA[this.id]]}fracNum(){return el[xHA[this.id]]}fracDen(){return el[LHA[this.id]]}cramp(){return el[THA[this.id]]}text(){return el[FHA[this.id]]}isTight(){return this.size>=2}}var D5=0,wS=1,ud=2,Dc=3,X0=4,Lo=5,Wd=6,Wa=7,el=[new mI(D5,0,!1),new mI(wS,0,!0),new mI(ud,1,!1),new mI(Dc,1,!0),new mI(X0,2,!1),new mI(Lo,2,!0),new mI(Wd,3,!1),new mI(Wa,3,!0)],MHA=[X0,Lo,X0,Lo,Wd,Wa,Wd,Wa],kHA=[Lo,Lo,Lo,Lo,Wa,Wa,Wa,Wa],xHA=[ud,Dc,X0,Lo,Wd,Wa,Wd,Wa],LHA=[Dc,Dc,Lo,Lo,Wa,Wa,Wa,Wa],THA=[wS,wS,Dc,Dc,Lo,Lo,Wa,Wa],FHA=[D5,wS,ud,Dc,ud,Dc,ud,Dc],Ot={DISPLAY:el[D5],TEXT:el[ud],SCRIPT:el[X0],SCRIPTSCRIPT:el[Wd]},KO=[{name:"latin",blocks:[[256,591],[768,879]]},{name:"cyrillic",blocks:[[1024,1279]]},{name:"armenian",blocks:[[1328,1423]]},{name:"brahmic",blocks:[[2304,4255]]},{name:"georgian",blocks:[[4256,4351]]},{name:"cjk",blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:"hangul",blocks:[[44032,55215]]}];function GHA(e){for(var A=0;A<KO.length;A++)for(var t=KO[A],i=0;i<t.blocks.length;i++){var r=t.blocks[i];if(e>=r[0]&&e<=r[1])return t.name}return null}var Rw=[];KO.forEach(e=>e.blocks.forEach(A=>Rw.push(...A)));function TIA(e){for(var A=0;A<Rw.length;A+=2)if(e>=Rw[A]&&e<=Rw[A+1])return!0;return!1}var vB=80,OHA=function(A,t){return"M95,"+(622+A+t)+`
980
+ `;function hHA({blocks:e,annotations:A,addAnnotation:t,removeAnnotation:i}){const[r,n]=aA.useState(new Map),a=aA.useRef(e);a.current=e;const s=aA.useRef(A);s.current=A,aA.useEffect(()=>{if(r.size===0)return;const l=new Set(e.map(C=>C.id)),I=[...r.keys()].filter(C=>!l.has(C));I.length>0&&n(C=>{const E=new Map(C);return I.forEach(u=>E.delete(u)),E})},[e]);const o=aA.useCallback((l,I)=>{const C=a.current,E=s.current,u=C.find(Q=>Q.id===l);if(u&&I===u.checked)n(f=>{const p=new Map(f);return p.delete(l),p}),E.filter(f=>f.blockId===l&&f.id.startsWith("ann-checkbox-")).forEach(f=>i(f.id));else if(E.filter(f=>f.blockId===l&&f.id.startsWith("ann-checkbox-")).forEach(f=>i(f.id)),n(f=>{const p=new Map(f);return p.set(l,I),p}),u){const f=C.indexOf(u);let p="";for(let k=f-1;k>=0;k--)if(C[k].type==="heading"){p=C[k].content;break}const y=I?"Mark as completed":"Mark as not completed",D=p?` (under "${p}")`:` (line ${u.startLine})`,S={id:`ann-checkbox-${l}-${Date.now()}`,blockId:l,startOffset:0,endOffset:u.content.length,type:oi.COMMENT,text:`${y}${D}: ${u.content}`,originalText:u.content,createdA:Date.now()};t(S)}},[t,i]),g=aA.useCallback(l=>{n(I=>{const C=new Map(I);return C.delete(l),C})},[]);return{overrides:r,toggle:o,revertOverride:g}}const QHA=()=>{const[e,A]=aA.useState(dHA),[t,i]=aA.useState([]),[r,n]=aA.useState(null),[a,s]=aA.useState([]),[o,g]=aA.useState(null),[l,I]=aA.useState(!1),[C,E]=aA.useState(!1),[u,d]=aA.useState(!1),[Q,f]=aA.useState(!1),[p,y]=aA.useState(!1),[D,S]=aA.useState(""),[k,R]=aA.useState(()=>window.innerWidth>=768),[b,N]=aA.useState(!1),[T,L]=aA.useState(()=>CIA()),[K,H]=aA.useState(a9A),[x,U]=aA.useState(g9A),[G,F]=aA.useState(()=>Ke.getItem("plannotator-tater-mode")==="true"),[O,P]=aA.useState(()=>TO()),q=aA.useRef(null),[Y,z]=aA.useState("full");aA.useLayoutEffect(()=>{const re=q.current;if(!re)return;const Pe=Et=>Et>=800?"full":Et>=680?"short":"icon";z(Pe(re.getBoundingClientRect().width));const Xe=new ResizeObserver(([Et])=>{const ei=Pe(Et.contentRect.width);z(Cr=>Cr===ei?Cr:ei)});return Xe.observe(re),()=>Xe.disconnect()},[]);const[j,X]=aA.useState(!1),[_,gA]=aA.useState(null),[eA,dA]=aA.useState(),[tA,oA]=aA.useState(!1),[nA,rA]=aA.useState([]),[EA,cA]=aA.useState(!1),[wA,uA]=aA.useState(null),[PA,sA]=aA.useState(void 0),[ee,SA]=aA.useState(!0),[XA,ie]=aA.useState(!1),[oe,GA]=aA.useState(null),[$A,HA]=aA.useState(null),[zA,le]=aA.useState(!1),[MA,Ae]=aA.useState("bypassPermissions"),[BA,vA]=aA.useState(!0),[Z,yA]=aA.useState(void 0),[fA,LA]=aA.useState(void 0),[kA,hA]=aA.useState(null),[TA,NA]=aA.useState(null);aA.useEffect(()=>{document.title=kA?`${kA.display} · Plannotator`:"Plannotator"},[kA]);const[YA,jA]=aA.useState(),[ae,mA]=aA.useState(null),[KA,UA]=aA.useState(!1),[se,Ne]=aA.useState("clean"),[ve,iA]=aA.useState(null),[Ie,ce]=aA.useState(null),De=aA.useRef(null),{ref:Se,viewport:Oe,onViewportReady:Ge}=u9A();E9A();const Ve=UZ({storageKey:"plannotator-panel-width"}),St=UZ({storageKey:"plannotator-toc-width",defaultWidth:240,minWidth:160,maxWidth:400,side:"left"}),At=Ve.isDragging||St.isDragging,rt=b9A(TO().tocEnabled);aA.useEffect(()=>{O.tocEnabled?rt.open("toc"):rt.close()},[O.tocEnabled]),aA.useEffect(()=>{rt.activeTab==="toc"&&KA&&UA(!1)},[rt.activeTab]),aA.useEffect(()=>{if(!KA)return;const re=Pe=>{Pe.key==="Escape"&&UA(!1)};return document.addEventListener("keydown",re),()=>document.removeEventListener("keydown",re)},[KA]);const ht=T9A(e,ve,Ie),je=F9A({markdown:e,annotations:t,selectedAnnotationId:r,globalAttachments:nA,setMarkdown:A,setAnnotations:i,setSelectedAnnotationId:n,setGlobalAttachments:rA,viewerRef:De,sidebar:rt}),et=Y9A({markdown:e,viewerRef:De,linkedDocHook:je,setMarkdown:A,setAnnotations:i,setSelectedAnnotationId:n,setSubmitted:GA}),ot=Z9A(),Ci=aA.useMemo(()=>fZ()?FI(TI()):"",[O]),He=aA.useMemo(()=>!!TA||MZ()||fZ(),[TA,O]),WA=aA.useMemo(()=>{const re=TA?[TA]:[],Pe=MZ()?p5().directories:[];return[...new Set([...re,...Pe])]},[TA,O]);aA.useEffect(()=>{He||ot.setActiveFile(null)},[He]),aA.useEffect(()=>{Ci||ot.clearVaultDirs()},[Ci]),aA.useEffect(()=>{if(rt.activeTab==="files"&&He){if(WA.length>0){const re=ot.dirs.filter(Xe=>!Xe.isVault).map(Xe=>Xe.path);(WA.some(Xe=>!re.includes(Xe))||re.some(Xe=>!WA.includes(Xe)))&&ot.fetchAll(WA)}Ci&&!ot.dirs.find(re=>re.isVault&&re.path===Ci&&!re.error)&&ot.addVaultDir(Ci)}},[rt.activeTab,He,WA,Ci]);const be=Qn.useCallback((re,Pe)=>{const Et=ot.dirs.find(ei=>ei.path===Pe)?.isVault?ei=>`/api/reference/obsidian/doc?vaultPath=${encodeURIComponent(Pe)}&path=${encodeURIComponent(ei)}`:ei=>`/api/doc?path=${encodeURIComponent(ei)}&base=${encodeURIComponent(Pe)}`;je.open(re,Et,"files"),ot.setActiveFile(re)},[je,ot]),_e=Qn.useCallback(re=>{if(ot.dirs.find(Xe=>Xe.path===ot.activeDirPath)?.isVault&&ot.activeDirPath)je.open(re,Xe=>`/api/reference/obsidian/doc?vaultPath=${encodeURIComponent(ot.activeDirPath)}&path=${encodeURIComponent(Xe)}`);else if(ot.activeFile&&ot.activeDirPath){const Xe=je.filepath?.replace(/\/[^/]+$/,"")||ot.activeDirPath;je.open(re,Et=>`/api/doc?path=${encodeURIComponent(Et)}&base=${encodeURIComponent(Xe)}`)}else{const Xe=je.filepath?je.filepath.replace(/\/[^/]+$/,""):PA;Xe?je.open(re,Et=>`/api/doc?path=${encodeURIComponent(Et)}&base=${encodeURIComponent(Xe)}`):je.open(re)}},[ot.dirs,ot.activeDirPath,ot.activeFile,je,PA]),Kt=Qn.useCallback(()=>{je.back(),ot.setActiveFile(null),et.clearSelection()},[je,ot,et]),$t=aA.useMemo(()=>{const re=new Map;for(const[Pe,Xe]of je.getDocAnnotations()){const Et=Xe.annotations.length+Xe.globalAttachments.length;Et>0&&re.set(Pe,Et)}return re},[je.getDocAnnotations,t,nA]),Bt=aA.useMemo(()=>{const re=ot.dirs.map(Xe=>Xe.path);if(re.length===0)return $t;const Pe=new Map;for(const[Xe,Et]of $t)re.some(ei=>Xe.startsWith(ei+"/"))&&Pe.set(Xe,Et);return Pe},[$t,ot.dirs]),hi=Bt.size>0,Zi=aA.useMemo(()=>{const re=je.filepath;let Pe=0,Xe=0;for(const[Et,ei]of $t)Et!==re&&(Pe+=ei,Xe++);return Pe>0?{count:Pe,files:Xe}:void 0},[$t,je.filepath]),[mi,ke]=aA.useState(),ye=Qn.useRef(),xe=Qn.useCallback(()=>{const re=new Set($t.keys());re.size!==0&&((!rt.isOpen||rt.activeTab!=="files")&&rt.open("files"),ye.current&&clearTimeout(ye.current),ke(void 0),requestAnimationFrame(()=>{ke(re),ye.current=setTimeout(()=>ke(void 0),1200)}))},[$t,rt,hi]),Re=wA==="folder"?"file list":wA==="file"?"file":wA==="message"?"message":"plan",me=aA.useMemo(()=>a.filter(re=>re.type==="heading").length,[a]),Ct=V8A(Se,me,Oe),{editorAnnotations:xA,deleteEditorAnnotation:ir}=P9A(),{externalAnnotations:FA,updateExternalAnnotation:Yt,deleteExternalAnnotation:as}=q9A({enabled:j}),{reset:Fa}=W9A({viewerRef:De,externalAnnotations:FA,enabled:j&&!je.isActive&&!KA,planKey:e}),ci=aA.useMemo(()=>FA.length===0?t:[...t.filter(Pe=>Pe.source?!FA.some(Xe=>Xe.source===Pe.source&&Xe.type===Pe.type&&Xe.originalText===Pe.originalText):!0),...FA],[t,FA]),xs=aA.useMemo(()=>ci.filter(re=>!!re.diffContext),[ci]),lr=aA.useMemo(()=>ci.filter(re=>!re.diffContext),[ci]),{isSharedSession:Ri,isLoadingShared:fa,shareUrl:Or,shareUrlSize:ss,shortShareUrl:dr,isGeneratingShortUrl:Ls,shortUrlError:cr,pendingSharedAnnotations:dt,clearPendingSharedAnnotations:Rt,generateShortUrl:Yi,importFromShareUrl:ti,shareLoadError:zr,clearShareLoadError:Ir}=z8A(e,ci,nA,A,i,rA,()=>{SA(!1)},Z,fA),{draftBanner:An,restoreDraft:en,dismissDraft:qe}=K9A({annotations:ci,globalAttachments:nA,isApiMode:j,isSharedSession:Ri,submitted:!!oe}),W=Qn.useCallback(()=>{const{annotations:re,globalAttachments:Pe}=en();re.length>0&&(i(re),Pe.length>0&&rA(Pe),setTimeout(()=>{De.current?.applySharedAnnotations(re.filter(Xe=>!Xe.diffContext))},100))},[en]),{getAgentWarning:$}=lIA(_);aA.useEffect(()=>{if(dt&&dt.length>0){const re=setTimeout(()=>{De.current?.clearAllHighlights(),De.current?.applySharedAnnotations(dt.filter(Pe=>!Pe.diffContext)),Rt(),Fa()},100);return()=>clearTimeout(re)}},[dt,Rt,Fa]);const CA=re=>{F(re),Ke.setItem("plannotator-tater-mode",String(re))},DA=re=>{H(re),s9A(re)},OA=re=>{U(re),l9A(re)};C9A(x,OA),aA.useEffect(()=>{fa||Ri||fetch("/api/plan").then(re=>{if(!re.ok)throw new Error("Not in API mode");return re.json()}).then(re=>{kn.init(re.serverConfig),dA(re.serverConfig?.gitUser),re.mode==="archive"?(A(re.plan||""),re.archivePlans&&et.init(re.archivePlans),et.fetchPlans(),vA(!1),rt.open("archive")):re.mode==="annotate-folder"?A(""):re.plan&&A(re.plan),X(!0),(re.mode==="annotate"||re.mode==="annotate-last"||re.mode==="annotate-folder")&&cA(!0),re.mode==="annotate-folder"&&rt.open("files"),re.mode&&re.mode!=="archive"&&uA(re.mode==="annotate-last"?"message":re.mode==="annotate-folder"?"folder":"file"),re.filePath&&sA(re.mode==="annotate-folder"?re.filePath:re.filePath.replace(/\/[^/]+$/,"")),re.sharingEnabled!==void 0&&vA(re.sharingEnabled),re.shareBaseUrl&&yA(re.shareBaseUrl),re.pasteApiUrl&&LA(re.pasteApiUrl),re.repoInfo&&hA(re.repoInfo),re.projectRoot&&NA(re.projectRoot),re.previousPlan!==void 0&&iA(re.previousPlan),re.versionInfo&&ce(re.versionInfo),re.origin&&(gA(re.origin),re.origin==="claude-code"&&l8A()&&le(!0),Ae(aIA().mode)),re.isWSL&&oA(!0)}).catch(()=>{X(!1)}).finally(()=>SA(!1))},[fa,Ri]),aA.useEffect(()=>{const{frontmatter:re}=uiA(e);g(re),s(BiA(e))},[e]);const _A=aA.useRef(!1),Ee=aA.useRef({}),fe=aA.useRef(null);aA.useEffect(()=>{_A.current=!1,Ee.current={},fe.current=null},[e]),aA.useEffect(()=>{if(!j||!e||Ri||EA||et.archiveMode||_A.current)return;const re={},Pe=[],Xe=TI();if(Xe.autoSave&&Xe.enabled){const hr=FI(Xe);hr&&(re.obsidian={vaultPath:hr,folder:Xe.folder||"plannotator",plan:e,...Xe.filenameFormat&&{filenameFormat:Xe.filenameFormat},...Xe.filenameSeparator&&Xe.filenameSeparator!=="space"&&{filenameSeparator:Xe.filenameSeparator}},Pe.push("Obsidian"))}const Et=yE();Et.autoSave&&Et.enabled&&(re.bear={plan:e,customTags:Et.customTags,tagPosition:Et.tagPosition},Pe.push("Bear"));const ei=Cd();if(ei.autoSave&&Xy()&&(re.octarine={plan:e,workspace:ei.workspace,folder:ei.folder||"plannotator"},Pe.push("Octarine")),Pe.length===0)return;_A.current=!0;const Cr=fetch("/api/save-notes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(re)}).then(hr=>hr.json()).then(hr=>{const jo={...re.obsidian?{obsidian:!!hr.results?.obsidian?.success}:{},...re.bear?{bear:!!hr.results?.bear?.success}:{},...re.octarine?{octarine:!!hr.results?.octarine?.success}:{}};Ee.current=jo;const Tl=Pe.filter(Gh=>!hr.results?.[Gh.toLowerCase()]?.success);return Tl.length===0?mA({type:"success",message:`Auto-saved to ${Pe.join(" & ")}`}):mA({type:"error",message:`Auto-save failed for ${Tl.join(" & ")}`}),jo}).catch(()=>(Ee.current={},mA({type:"error",message:"Auto-save failed"}),{})).finally(()=>setTimeout(()=>mA(null),3e3));fe.current=Cr},[j,e,Ri,EA]),aA.useEffect(()=>{const re=Pe=>{const Xe=Pe.clipboardData?.items;if(Xe){for(const Et of Xe)if(Et.type.startsWith("image/")){Pe.preventDefault();const ei=Et.getAsFile();if(ei){const Cr=c3(ei.name,nA.map(jo=>jo.name)),hr=URL.createObjectURL(ei);HA({file:ei,blobUrl:hr,initialName:Cr})}break}}};return document.addEventListener("paste",re),()=>document.removeEventListener("paste",re)},[nA]);const $e=async(re,Pe,Xe)=>{if($A)try{const Et=new FormData,ei=Pe?new File([re],"annotated.png",{type:"image/png"}):$A.file;Et.append("file",ei);const Cr=await fetch("/api/upload",{method:"POST",body:Et});if(Cr.ok){const hr=await Cr.json();rA(jo=>[...jo,{path:hr.path,name:Xe}])}}catch{}finally{URL.revokeObjectURL($A.blobUrl),HA(null)}},zt=()=>{$A&&(URL.revokeObjectURL($A.blobUrl),HA(null))},Lt=async()=>{ie(!0);try{const re=TI(),Pe=yE(),Xe=Cd(),Et=Q5(),ei=mS(),Cr=Pe.autoSave&&fe.current?await fe.current:Ee.current,hr={};_==="claude-code"&&(hr.permissionMode=MA);const jo=a8A(Et);jo&&(hr.agentSwitch=jo),hr.planSave={enabled:ei.enabled,...ei.customPath&&{customPath:ei.customPath}};const Tl=FI(re);re.enabled&&Tl&&(hr.obsidian={vaultPath:Tl,folder:re.folder||"plannotator",plan:e,...re.filenameFormat&&{filenameFormat:re.filenameFormat},...re.filenameSeparator&&re.filenameSeparator!=="space"&&{filenameSeparator:re.filenameSeparator}}),Pe.enabled&&!(Pe.autoSave&&Cr.bear)&&(hr.bear={plan:e,customTags:Pe.customTags,tagPosition:Pe.tagPosition}),Xy()&&(hr.octarine={plan:e,workspace:Xe.workspace,folder:Xe.folder||"plannotator"});const Gh=Array.from(je.getDocAnnotations().values()).some(Dm=>Dm.annotations.length>0||Dm.globalAttachments.length>0);(ci.length>0||nA.length>0||Gh||xA.length>0)&&(hr.feedback=_i),await fetch("/api/approve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(hr)}),GA("approved")}catch{ie(!1)}},ii=async()=>{ie(!0);try{const re=mS();await fetch("/api/deny",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({feedback:_i,planSave:{enabled:re.enabled,...re.customPath&&{customPath:re.customPath}}})}),GA("denied")}catch{ie(!1)}},Ai=async()=>{ie(!0);try{await fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({feedback:_i,annotations:ci})}),GA("denied")}catch{ie(!1)}};aA.useEffect(()=>{const re=Pe=>{if(Pe.key!=="Enter"||!(Pe.metaKey||Pe.ctrlKey))return;const Xe=Pe.target?.tagName;if(Xe==="INPUT"||Xe==="TEXTAREA"||l||C||u||Q||p||zA||$A||oe||XA||!j||je.isActive)return;if(Pe.preventDefault(),EA){Ai();return}const Et=je.getDocAnnotations(),ei=Array.from(Et.values()).some(Cr=>Cr.annotations.length>0||Cr.globalAttachments.length>0);if(ci.length===0&&xA.length===0&&!ei){if(_==="opencode"){const Cr=$();if(Cr){S(Cr),y(!0);return}}Lt()}else ii()};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[l,C,u,Q,p,zA,$A,oe,XA,j,je.isActive,t.length,FA.length,EA,_,$]);const Dt=re=>{i(Pe=>[...Pe,re]),n(re.id),R(!0)},Tt=Qn.useCallback(re=>{n(re),re&&window.innerWidth<768&&R(!0)},[]),ji=re=>{De.current?.removeHighlight(re),i(Pe=>Pe.filter(Xe=>Xe.id!==re)),r===re&&n(null)},Cn=hHA({blocks:a,annotations:t,addAnnotation:Dt,removeAnnotation:ji}),zn=re=>{const Pe=ci.find(Xe=>Xe.id===re);if(Pe?.source&&FA.some(Xe=>Xe.id===re)){as(re),r===re&&n(null);return}re.startsWith("ann-checkbox-")&&Pe&&Cn.revertOverride(Pe.blockId),ji(re)},rr=(re,Pe)=>{if(ci.find(Et=>Et.id===re)?.source&&FA.some(Et=>Et.id===re)){Yt(re,Pe);return}i(Et=>Et.map(ei=>ei.id===re?{...ei,...Pe}:ei))},tn=(re,Pe)=>{i(Xe=>Xe.map(Et=>Et.author===re?{...Et,author:Pe}:Et))},co=re=>{rA(Pe=>[...Pe,re])},qn=re=>{rA(Pe=>Pe.filter(Xe=>Xe.path!==re))},xg=re=>{},_i=aA.useMemo(()=>{const re=je.getDocAnnotations(),Pe=Array.from(re.values()).some(Cr=>Cr.annotations.length>0||Cr.globalAttachments.length>0),Xe=ci.length>0||nA.length>0,Et=xA.length>0;if(!Xe&&!Pe&&!Et)return"User reviewed the document and has no feedback.";let ei=Xe?YmA(a,ci,nA,wA==="message"?"Message Feedback":wA==="folder"?"Folder Feedback":wA==="file"?"File Feedback":"Plan Feedback",wA??"plan"):"";return Pe&&(ei+=HmA(re)),Et&&(ei+=PmA(xA)),ei},[a,ci,nA,je.getDocAnnotations,xA]),_c=Qn.useMemo(()=>q8A(),[]),Lg=Qn.useCallback(async re=>{if(!(!_c||XA||!Or)){ie(!0);try{const Pe=await W8A(re,_c,Or);Pe&&(mA(Pe),setTimeout(()=>mA(null),4e3),Pe.type==="success"&&GA(re===bw.Approve?"approved":"denied"))}finally{ie(!1)}}},[_c,XA,Or]),Ju=Qn.useCallback(()=>Lg(bw.Approve),[Lg]),mm=Qn.useCallback(()=>Lg(bw.Feedback),[Lg]),ym=()=>{const re=new Blob([_i],{type:"text/plain"}),Pe=URL.createObjectURL(re),Xe=document.createElement("a");Xe.href=Pe,Xe.download="annotations.md",Xe.click(),URL.revokeObjectURL(Pe),mA({type:"success",message:"Downloaded annotations"}),setTimeout(()=>mA(null),3e3)},Xc=async re=>{const Pe={};if(re==="obsidian"){const Et=TI(),ei=FI(Et);ei&&(Pe.obsidian={vaultPath:ei,folder:Et.folder||"plannotator",plan:e,...Et.filenameFormat&&{filenameFormat:Et.filenameFormat},...Et.filenameSeparator&&Et.filenameSeparator!=="space"&&{filenameSeparator:Et.filenameSeparator}})}if(re==="bear"){const Et=yE();Pe.bear={plan:e,customTags:Et.customTags,tagPosition:Et.tagPosition}}if(re==="octarine"){const Et=Cd();Pe.octarine={plan:e,workspace:Et.workspace,folder:Et.folder||"plannotator"}}const Xe=re==="obsidian"?"Obsidian":re==="bear"?"Bear":"Octarine";try{const Cr=(await(await fetch("/api/save-notes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Pe)})).json()).results?.[re];Cr?.success?mA({type:"success",message:`Saved to ${Xe}`}):mA({type:"error",message:Cr?.error||"Save failed"})}catch{mA({type:"error",message:"Save failed"})}setTimeout(()=>mA(null),3e3)},WR=async()=>{const re=V9A(window.location.origin);try{await navigator.clipboard.writeText(re),mA({type:"success",message:"Agent instructions copied"})}catch{mA({type:"error",message:"Failed to copy"})}setTimeout(()=>mA(null),3e3)},Fh=async()=>{try{await navigator.clipboard.writeText(Or),mA({type:"success",message:"Share link copied"})}catch{mA({type:"error",message:"Failed to copy"})}setTimeout(()=>mA(null),3e3)};aA.useEffect(()=>{const re=Pe=>{if(Pe.key!=="s"||!(Pe.metaKey||Pe.ctrlKey))return;const Xe=Pe.target?.tagName;if(Xe==="INPUT"||Xe==="TEXTAREA"||l||u||Q||p||zA||$A||oe||!j)return;Pe.preventDefault();const Et=gIA(),ei=QZ(),Cr=yE().enabled,hr=Xy();Et==="download"?ym():Et==="obsidian"&&ei?Xc("obsidian"):Et==="bear"&&Cr?Xc("bear"):Et==="octarine"&&hr?Xc("octarine"):(jA("notes"),I(!0))};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[l,u,Q,p,zA,$A,oe,j,e,_i]),aA.useEffect(()=>{const re=Pe=>{if(Pe.key!=="p"||!(Pe.metaKey||Pe.ctrlKey))return;const Xe=Pe.target?.tagName;Xe==="INPUT"||Xe==="TEXTAREA"||l||u||Q||p||zA||$A||oe||(Pe.preventDefault(),window.print())};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[l,u,Q,p,zA,$A,oe]);const Ll=aA.useMemo(()=>UmA(_),[_]),zu=aA.useMemo(()=>({compact:832,default:1040,wide:1280})[O.planWidth]??832,[O.planWidth]);return w.jsx(UYA,{defaultTheme:"dark",children:w.jsxs("div",{"data-print-region":"root",className:"h-screen flex flex-col bg-background overflow-hidden",children:[w.jsxs("header",{className:"h-12 flex items-center justify-between px-2 md:px-4 border-b border-border/50 bg-card/50 backdrop-blur-xl sticky top-0 z-[50]",children:[w.jsx("div",{className:"flex items-center gap-2 md:gap-3",children:w.jsx("a",{href:"https://plannotator.ai",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 md:gap-2 hover:opacity-80 transition-opacity",children:w.jsx("span",{className:"text-sm font-semibold tracking-tight",children:"Plannotator"})})}),w.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[_c&&!j&&Ri&&w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"w-px h-5 bg-border/50 mx-1 hidden md:block"}),w.jsx(kZ,{onClick:mm,disabled:XA||!Or,isLoading:XA,title:"Send feedback to bot"}),w.jsx(xZ,{onClick:Ju,disabled:XA||!Or,isLoading:XA,title:"Approve design and notify bot"})]}),j&&!je.isActive&&et.archiveMode&&w.jsxs(w.Fragment,{children:[w.jsxs("button",{onClick:et.copy,className:"px-2.5 py-1 rounded-md text-xs font-medium transition-all bg-muted text-foreground hover:bg-muted/80 border border-border",title:"Copy plan content",children:[w.jsx("span",{className:"hidden md:inline",children:"Copy"}),w.jsx("svg",{className:"w-4 h-4 md:hidden",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})]}),w.jsx("button",{onClick:et.done,className:"px-2.5 py-1 rounded-md text-xs font-medium transition-all bg-success text-success-foreground hover:opacity-90",title:"Close archive",children:"Done"})]}),j&&(!je.isActive||EA)&&!et.archiveMode&&w.jsxs(w.Fragment,{children:[w.jsx(kZ,{onClick:()=>{if(EA){Ai();return}const re=je.getDocAnnotations(),Pe=Array.from(re.values()).some(Xe=>Xe.annotations.length>0||Xe.globalAttachments.length>0);ci.length===0&&xA.length===0&&!Pe?d(!0):ii()},disabled:XA,isLoading:XA,label:EA?ci.length>0||xA.length>0||je.docAnnotationCount>0?"Send Annotations":"Done":"Send Feedback",title:EA?ci.length>0||xA.length>0||je.docAnnotationCount>0?"Send Annotations":"Done":"Send Feedback"}),!EA&&w.jsxs("div",{className:"relative group/approve",children:[w.jsx(xZ,{onClick:()=>{if(_==="claude-code"&&ci.length>0){f(!0);return}if(_==="opencode"){const re=$();if(re){S(re),y(!0);return}}Lt()},disabled:XA,isLoading:XA,dimmed:(_==="claude-code"||_==="gemini-cli")&&ci.length>0}),(_==="claude-code"||_==="gemini-cli")&&ci.length>0&&w.jsxs("div",{className:"absolute top-full right-0 mt-2 px-3 py-2 bg-popover border border-border rounded-lg shadow-xl text-xs text-foreground w-56 text-center opacity-0 invisible group-hover/approve:opacity-100 group-hover/approve:visible transition-all pointer-events-none z-50",children:[w.jsx("div",{className:"absolute bottom-full right-4 border-4 border-transparent border-b-border"}),w.jsx("div",{className:"absolute bottom-full right-4 mt-px border-4 border-transparent border-b-popover"}),Ll," doesn't support feedback on approval. Your annotations won't be seen."]})]}),w.jsx("div",{className:"w-px h-5 bg-border/50 mx-1 hidden md:block"})]}),w.jsx("button",{onClick:()=>R(!k),className:`p-1.5 rounded-md text-xs font-medium transition-all ${k?"bg-primary/15 text-primary":"text-muted-foreground hover:text-foreground hover:bg-muted"}`,title:k?"Hide annotations":"Show annotations",children:w.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),w.jsx("div",{className:"hidden",children:w.jsx(O8A,{taterMode:G,onTaterModeChange:CA,onIdentityChange:tn,origin:_,onUIPreferencesChange:P,externalOpen:b,onExternalClose:()=>N(!1),gitUser:eA})}),w.jsx(h9A,{appVersion:"0.17.7",hasNewSettingsHints:T,onOpenSettings:()=>{T&&(EIA(),L(!1)),N(!0)},onOpenExport:()=>{jA(void 0),I(!0)},onCopyAgentInstructions:WR,onDownloadAnnotations:ym,onPrint:()=>window.print(),onCopyShareLink:Fh,onOpenImport:()=>E(!0),onSaveToObsidian:()=>Xc("obsidian"),onSaveToBear:()=>Xc("bear"),onSaveToOctarine:()=>Xc("octarine"),sharingEnabled:BA,isApiMode:j,agentInstructionsEnabled:j&&!et.archiveMode&&!EA,obsidianConfigured:QZ(),bearConfigured:yE().enabled,octarineConfigured:Xy()})]})]}),je.error&&w.jsxs("div",{className:"bg-destructive/10 border-b border-destructive/20 px-4 py-2 flex items-center gap-2 flex-shrink-0",children:[w.jsx("span",{className:"text-xs text-destructive",children:je.error}),w.jsx("button",{onClick:je.dismissError,className:"ml-auto text-xs text-destructive/60 hover:text-destructive",children:"dismiss"})]}),w.jsx(UlA.Provider,{value:Oe,children:w.jsxs("div",{"data-print-region":"content",className:`flex-1 flex overflow-hidden relative z-0 ${At?"select-none":""}`,children:[G&&w.jsx($YA,{}),!rt.isOpen&&w.jsx(j9A,{activeTab:rt.activeTab,onToggleTab:rt.toggleTab,hasDiff:ht.hasPreviousVersion,showVersionsTab:Ie!==null&&Ie.totalVersions>1,showFilesTab:He&&!et.archiveMode,hasFileAnnotations:hi,className:"hidden lg:flex absolute left-0 top-0 z-10"}),rt.isOpen&&w.jsxs(w.Fragment,{children:[w.jsx(oHA,{activeTab:rt.activeTab,onTabChange:re=>{rt.toggleTab(re),re==="archive"&&!et.archiveMode&&et.fetchPlans()},onClose:rt.close,width:St.width,blocks:a,annotations:t,activeSection:Ct,onTocNavigate:xg,linkedDocFilepath:je.filepath,onLinkedDocBack:je.isActive?Kt:void 0,backLabel:Re,showFilesTab:He&&!et.archiveMode,fileAnnotationCounts:Bt,highlightedFiles:mi,fileBrowser:ot,onFilesSelectFile:be,onFilesFetchAll:()=>ot.fetchAll(WA),onFilesRetryVaultDir:re=>ot.addVaultDir(re),hasFileAnnotations:hi,showVersionsTab:Ie!==null&&Ie.totalVersions>1,versionInfo:Ie,versions:ht.versions,selectedBaseVersion:ht.diffBaseVersion,onSelectBaseVersion:ht.selectBaseVersion,isPlanDiffActive:KA,hasPreviousVersion:ht.hasPreviousVersion,onActivatePlanDiff:()=>UA(!0),isLoadingVersions:ht.isLoadingVersions,isSelectingVersion:ht.isSelectingVersion,fetchingVersion:ht.fetchingVersion,onFetchVersions:ht.fetchVersions,showArchiveTab:j&&!EA,archivePlans:et.plans,selectedArchiveFile:et.selectedFile,onArchiveSelect:et.select,isLoadingArchive:et.isLoading}),w.jsx(KZ,{...St.handleProps,className:"hidden lg:block",side:"left"})]}),w.jsxs(Yp,{element:"main",className:`flex-1 min-w-0 bg-grid ${rt.isOpen?"":"lg:pl-[30px]"}`,"data-print-region":"document",onViewportReady:Ge,children:[w.jsx(zQ,{isOpen:!!An,onClose:qe,onConfirm:W,title:"Draft Recovered",message:An?`Found ${An.count} annotation${An.count!==1?"s":""} from ${An.timeAgo}. Would you like to restore them?`:"",confirmText:"Restore",cancelText:"Dismiss",showCancel:!0}),w.jsxs("div",{ref:q,className:"min-h-full flex flex-col items-center px-2 py-3 md:px-10 md:py-8 xl:px-16 relative z-10",children:[!KA&&!et.archiveMode&&O.stickyActionsEnabled&&w.jsx(VYA,{inputMethod:x,onInputMethodChange:OA,mode:K,onModeChange:DA,taterMode:G,repoInfo:kA,planDiffStats:ht.diffStats,isPlanDiffActive:KA,hasPreviousVersion:ht.hasPreviousVersion,onPlanDiffToggle:()=>UA(!KA),archiveInfo:et.currentInfo,maxWidth:zu,remountToken:je.isActive?`doc:${je.filepath}`:"plan"}),!KA&&!et.archiveMode&&w.jsx("div",{"data-print-hide":!0,className:"w-full mb-3 md:mb-4 flex items-center justify-start",style:{maxWidth:zu},children:w.jsx(ZcA,{inputMethod:x,onInputMethodChange:OA,mode:K,onModeChange:DA,taterMode:G})}),ht.diffBlocks&&ht.diffStats&&w.jsx("div",{className:"w-full flex justify-center",style:{display:KA?void 0:"none"},children:w.jsx(BHA,{diffBlocks:ht.diffBlocks,diffStats:ht.diffStats,diffMode:se,onDiffModeChange:Ne,onPlanDiffToggle:()=>UA(!1),repoInfo:kA,baseVersionLabel:ht.diffBaseVersion!=null?`v${ht.diffBaseVersion}`:void 0,baseVersion:ht.diffBaseVersion??void 0,maxWidth:zu,annotations:xs,onAddAnnotation:Dt,onSelectAnnotation:Tt,selectedAnnotationId:r,mode:K})}),wA==="folder"&&!e&&!je.isActive&&w.jsx("div",{className:"w-full flex justify-center",children:w.jsxs("div",{className:"w-full max-w-3xl p-12 text-center text-muted-foreground",children:[w.jsx("p",{className:"text-lg font-medium mb-2",children:"Select a file to annotate"}),w.jsx("p",{className:"text-sm",children:"Pick a markdown file from the sidebar to begin."})]})}),w.jsx("div",{className:"w-full flex justify-center",style:{display:KA&&ht.diffBlocks||wA==="folder"&&!e&&!je.isActive?"none":void 0},children:w.jsx(E5A,{ref:De,blocks:a,markdown:e,frontmatter:o,annotations:lr,onAddAnnotation:Dt,onSelectAnnotation:Tt,selectedAnnotationId:r,mode:K,inputMethod:x,taterMode:G,globalAttachments:nA,onAddGlobalAttachment:co,onRemoveGlobalAttachment:qn,repoInfo:kA,stickyActions:O.stickyActionsEnabled,planDiffStats:je.isActive?null:ht.diffStats,isPlanDiffActive:KA,onPlanDiffToggle:()=>UA(!KA),hasPreviousVersion:!je.isActive&&ht.hasPreviousVersion,showDemoBadge:!j&&!fa&&!Ri,maxWidth:zu,onOpenLinkedDoc:_e,linkedDocInfo:je.isActive?{filepath:je.filepath,onBack:Kt,label:ot.dirs.find(re=>re.path===ot.activeDirPath)?.isVault?"Vault File":ot.activeFile?"File":void 0,backLabel:Re}:null,imageBaseDir:PA,copyLabel:wA==="message"?"Copy message":wA==="file"||wA==="folder"?"Copy file":void 0,archiveInfo:et.currentInfo,onToggleCheckbox:Cn.toggle,checkboxOverrides:Cn.overrides,actionsLabelMode:Y},je.isActive?`doc:${je.filepath}`:"plan")})]})]}),k&&w.jsx(KZ,{...Ve.handleProps,className:"hidden md:block",side:"right"}),w.jsx(RYA,{isOpen:k,blocks:a,annotations:ci,selectedId:r,onSelect:n,onDelete:zn,onEdit:rr,sharingEnabled:BA,width:Ve.width,editorAnnotations:xA,onDeleteEditorAnnotation:ir,onClose:()=>R(!1),onQuickCopy:async()=>{await navigator.clipboard.writeText(hiA(_i))},onShare:Or?()=>{R(!1),jA("share"),I(!0)}:void 0,otherFileAnnotations:Zi,onOtherFileAnnotationsClick:xe})]})}),w.jsx(GYA,{isOpen:l,onClose:()=>{I(!1),jA(void 0)},shareUrl:Or,shareUrlSize:ss,shortShareUrl:dr,isGeneratingShortUrl:Ls,shortUrlError:cr,onGenerateShortUrl:Yi,annotationsOutput:_i,annotationCount:ci.length,taterSprite:G?w.jsx(h5,{}):void 0,sharingEnabled:BA,markdown:e,isApiMode:j,initialTab:YA}),w.jsx(OYA,{isOpen:C,onClose:()=>E(!1),onImport:ti,shareBaseUrl:Z}),w.jsx(zQ,{isOpen:u,onClose:()=>d(!1),title:"Add Annotations First",message:`To provide feedback, select text in the plan and add annotations. ${Ll} will use your annotations to revise the plan.`,variant:"info"}),w.jsx(zQ,{isOpen:Q,onClose:()=>f(!1),onConfirm:()=>{f(!1),Lt()},title:"Annotations Won't Be Sent",message:w.jsxs(w.Fragment,{children:[Ll," doesn't yet support feedback on approval. Your ",ci.length," annotation",ci.length!==1?"s":""," will be lost."]}),subMessage:w.jsxs(w.Fragment,{children:["To send feedback, use ",w.jsx("strong",{children:"Send Feedback"})," instead.",w.jsx("br",{}),w.jsx("br",{}),"Want this feature? Upvote these issues:",w.jsx("br",{}),w.jsx("a",{href:"https://github.com/anthropics/claude-code/issues/16001",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"#16001"})," · ",w.jsx("a",{href:"https://github.com/anthropics/claude-code/issues/15755",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"#15755"})]}),confirmText:"Approve Anyway",cancelText:"Cancel",variant:"warning",showCancel:!0}),w.jsx(zQ,{isOpen:p,onClose:()=>y(!1),onConfirm:()=>{y(!1),Lt()},title:"Agent Not Found",message:D,subMessage:w.jsxs(w.Fragment,{children:["You can change the agent in ",w.jsx("strong",{children:"Settings"}),", or approve anyway and OpenCode will use the default agent."]}),confirmText:"Approve Anyway",cancelText:"Cancel",variant:"warning",showCancel:!0}),w.jsx(zQ,{isOpen:!!zr&&!j,onClose:Ir,title:"Shared Plan Could Not Be Loaded",message:zr,subMessage:"You are viewing a demo plan. This is sample content — it is not your data or anyone else's.",variant:"warning"}),ae&&w.jsx("div",{className:`fixed top-16 right-4 z-50 px-3 py-2 rounded-lg text-xs font-medium shadow-lg transition-opacity ${ae.type==="success"?"bg-success/15 text-success border border-success/30":"bg-destructive/15 text-destructive border border-destructive/30"}`,children:ae.message}),w.jsx(X8A,{submitted:oe,title:et.archiveMode?"Archive Closed":oe==="approved"?"Plan Approved":EA?"Annotations Sent":"Feedback Sent",subtitle:et.archiveMode?"You can reopen with plannotator archive.":oe==="approved"?`${Ll} will proceed with the implementation.`:EA?`${Ll} will address your annotations on the ${wA==="message"?"message":wA==="folder"?"files":"file"}.`:`${Ll} will revise the plan based on your annotations.`,agentLabel:Ll}),w.jsx(r9A,{origin:_,isWSL:tA}),w.jsx(NiA,{isOpen:!!$A,imageSrc:$A?.blobUrl??"",initialName:$A?.initialName,onAccept:$e,onClose:zt}),w.jsx(S9A,{isOpen:zA,onComplete:re=>{Ae(re),le(!1)}})]})})},xIA=document.getElementById("root");if(!xIA)throw new Error("Could not find root element to mount to");const fHA=OmA.createRoot(xIA);fHA.render(w.jsx(Qn.StrictMode,{children:w.jsx(QHA,{})}));class us{constructor(A,t,i){this.lexer=void 0,this.start=void 0,this.end=void 0,this.lexer=A,this.start=t,this.end=i}static range(A,t){return t?!A||!A.loc||!t.loc||A.loc.lexer!==t.loc.lexer?null:new us(A.loc.lexer,A.loc.start,t.loc.end):A&&A.loc}}class Xs{constructor(A,t){this.text=void 0,this.loc=void 0,this.noexpand=void 0,this.treatAsRelax=void 0,this.text=A,this.loc=t}range(A,t){return new Xs(t,us.range(this,A))}}class Ze{constructor(A,t){this.name=void 0,this.position=void 0,this.length=void 0,this.rawMessage=void 0;var i="KaTeX parse error: "+A,r,n,a=t&&t.loc;if(a&&a.start<=a.end){var s=a.lexer.input;r=a.start,n=a.end,r===s.length?i+=" at end of input: ":i+=" at position "+(r+1)+": ";var o=s.slice(r,n).replace(/[^]/g,"$&̲"),g;r>15?g="…"+s.slice(r-15,r):g=s.slice(0,r);var l;n+15<s.length?l=s.slice(n,n+15)+"…":l=s.slice(n),i+=g+o+l}var I=new Error(i);return I.name="ParseError",I.__proto__=Ze.prototype,I.position=r,r!=null&&n!=null&&(I.length=n-r),I.rawMessage=A,I}}Ze.prototype.__proto__=Error.prototype;var pHA=function(A,t){return A===void 0?t:A},mHA=/([A-Z])/g,yHA=function(A){return A.replace(mHA,"-$1").toLowerCase()},DHA={"&":"&amp;",">":"&gt;","<":"&lt;",'"':"&quot;","'":"&#x27;"},wHA=/[&><"']/g;function vHA(e){return String(e).replace(wHA,A=>DHA[A])}var LIA=function e(A){return A.type==="ordgroup"||A.type==="color"?A.body.length===1?e(A.body[0]):A:A.type==="font"?e(A.body):A},SHA=function(A){var t=LIA(A);return t.type==="mathord"||t.type==="textord"||t.type==="atom"},bHA=function(A){if(!A)throw new Error("Expected non-null, but got "+String(A));return A},RHA=function(A){var t=/^[\x00-\x20]*([^\\/#?]*?)(:|&#0*58|&#x0*3a|&colon)/i.exec(A);return t?t[2]!==":"||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():"_relative"},Oi={deflt:pHA,escape:vHA,hyphenate:yHA,getBaseElem:LIA,isCharacterBox:SHA,protocolFromUrl:RHA},h0={displayMode:{type:"boolean",description:"Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.",cli:"-d, --display-mode"},output:{type:{enum:["htmlAndMathml","html","mathml"]},description:"Determines the markup language of the output.",cli:"-F, --format <type>"},leqno:{type:"boolean",description:"Render display math in leqno style (left-justified tags)."},fleqn:{type:"boolean",description:"Render display math flush left."},throwOnError:{type:"boolean",default:!0,cli:"-t, --no-throw-on-error",cliDescription:"Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error."},errorColor:{type:"string",default:"#cc0000",cli:"-c, --error-color <color>",cliDescription:"A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.",cliProcessor:e=>"#"+e},macros:{type:"object",cli:"-m, --macro <def>",cliDescription:"Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).",cliDefault:[],cliProcessor:(e,A)=>(A.push(e),A)},minRuleThickness:{type:"number",description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:"--min-rule-thickness <size>",cliProcessor:parseFloat},colorIsTextColor:{type:"boolean",description:"Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.",cli:"-b, --color-is-text-color"},strict:{type:[{enum:["warn","ignore","error"]},"boolean","function"],description:"Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.",cli:"-S, --strict",cliDefault:!1},trust:{type:["boolean","function"],description:"Trust the input, enabling all HTML features such as \\url.",cli:"-T, --trust"},maxSize:{type:"number",default:1/0,description:"If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large",processor:e=>Math.max(0,e),cli:"-s, --max-size <n>",cliProcessor:parseInt},maxExpand:{type:"number",default:1e3,description:"Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.",processor:e=>Math.max(0,e),cli:"-e, --max-expand <n>",cliProcessor:e=>e==="Infinity"?1/0:parseInt(e)},globalGroup:{type:"boolean",cli:!1}};function NHA(e){if(e.default)return e.default;var A=e.type,t=Array.isArray(A)?A[0]:A;if(typeof t!="string")return t.enum[0];switch(t){case"boolean":return!1;case"string":return"";case"number":return 0;case"object":return{}}}class y5{constructor(A){this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,A=A||{};for(var t in h0)if(h0.hasOwnProperty(t)){var i=h0[t];this[t]=A[t]!==void 0?i.processor?i.processor(A[t]):A[t]:NHA(i)}}reportNonstrict(A,t,i){var r=this.strict;if(typeof r=="function"&&(r=r(A,t,i)),!(!r||r==="ignore")){if(r===!0||r==="error")throw new Ze("LaTeX-incompatible input and strict mode is set to 'error': "+(t+" ["+A+"]"),i);r==="warn"?typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(t+" ["+A+"]")):typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+r+"': "+t+" ["+A+"]"))}}useStrictBehavior(A,t,i){var r=this.strict;if(typeof r=="function")try{r=r(A,t,i)}catch{r="error"}return!r||r==="ignore"?!1:r===!0||r==="error"?!0:r==="warn"?(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to 'warn': "+(t+" ["+A+"]")),!1):(typeof console<"u"&&console.warn("LaTeX-incompatible input and strict mode is set to "+("unrecognized '"+r+"': "+t+" ["+A+"]")),!1)}isTrusted(A){if(A.url&&!A.protocol){var t=Oi.protocolFromUrl(A.url);if(t==null)return!1;A.protocol=t}var i=typeof this.trust=="function"?this.trust(A):this.trust;return!!i}}class mI{constructor(A,t,i){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=A,this.size=t,this.cramped=i}sup(){return el[MHA[this.id]]}sub(){return el[kHA[this.id]]}fracNum(){return el[xHA[this.id]]}fracDen(){return el[LHA[this.id]]}cramp(){return el[THA[this.id]]}text(){return el[FHA[this.id]]}isTight(){return this.size>=2}}var D5=0,wS=1,ud=2,Dc=3,X0=4,Lo=5,Wd=6,Wa=7,el=[new mI(D5,0,!1),new mI(wS,0,!0),new mI(ud,1,!1),new mI(Dc,1,!0),new mI(X0,2,!1),new mI(Lo,2,!0),new mI(Wd,3,!1),new mI(Wa,3,!0)],MHA=[X0,Lo,X0,Lo,Wd,Wa,Wd,Wa],kHA=[Lo,Lo,Lo,Lo,Wa,Wa,Wa,Wa],xHA=[ud,Dc,X0,Lo,Wd,Wa,Wd,Wa],LHA=[Dc,Dc,Lo,Lo,Wa,Wa,Wa,Wa],THA=[wS,wS,Dc,Dc,Lo,Lo,Wa,Wa],FHA=[D5,wS,ud,Dc,ud,Dc,ud,Dc],Ot={DISPLAY:el[D5],TEXT:el[ud],SCRIPT:el[X0],SCRIPTSCRIPT:el[Wd]},KO=[{name:"latin",blocks:[[256,591],[768,879]]},{name:"cyrillic",blocks:[[1024,1279]]},{name:"armenian",blocks:[[1328,1423]]},{name:"brahmic",blocks:[[2304,4255]]},{name:"georgian",blocks:[[4256,4351]]},{name:"cjk",blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:"hangul",blocks:[[44032,55215]]}];function GHA(e){for(var A=0;A<KO.length;A++)for(var t=KO[A],i=0;i<t.blocks.length;i++){var r=t.blocks[i];if(e>=r[0]&&e<=r[1])return t.name}return null}var Rw=[];KO.forEach(e=>e.blocks.forEach(A=>Rw.push(...A)));function TIA(e){for(var A=0;A<Rw.length;A+=2)if(e>=Rw[A]&&e<=Rw[A+1])return!0;return!1}var vB=80,OHA=function(A,t){return"M95,"+(622+A+t)+`
981
981
  c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14
982
982
  c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54
983
983
  c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10
@@ -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.6",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.7",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.6",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.7",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