nomoreide 0.1.61 → 0.1.62
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.
|
@@ -211,7 +211,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),fs=Re,Ot=Je),gt===void
|
|
|
211
211
|
`+R.slice(ue,Ce),ue=Ce+1),ve=Le;return H+=`
|
|
212
212
|
`,R.length-ue>ne&&ve>ue?H+=R.slice(ue,ve)+`
|
|
213
213
|
`+R.slice(ve+1):H+=R.slice(ue),H.slice(1)}function Ft(R){let ne="",Ae=0;for(let ge=0;ge<R.length;Ae>=65536?ge+=2:ge++){Ae=$e(R,ge);const ue=D[Ae];!ue&&Ge(Ae)?(ne+=R[ge],Ae>=65536&&(ne+=R[ge+1])):ne+=ue||Y(Ae)}return ne}function Qs(R,ne,Ae){let ge="";const ue=R.tag;for(let Ce=0,ve=Ae.length;Ce<ve;Ce+=1){let Le=Ae[Ce];R.replacer&&(Le=R.replacer.call(Ae,String(Ce),Le)),(me(R,ne,Le,!1,!1)||typeof Le>"u"&&me(R,ne,null,!1,!1))&&(ge!==""&&(ge+=","+(R.condenseFlow?"":" ")),ge+=R.dump)}R.tag=ue,R.dump="["+ge+"]"}function Js(R,ne,Ae,ge){let ue="";const Ce=R.tag;for(let ve=0,Le=Ae.length;ve<Le;ve+=1){let H=Ae[ve];R.replacer&&(H=R.replacer.call(Ae,String(ve),H)),(me(R,ne+1,H,!0,!0,!1,!0)||typeof H>"u"&&me(R,ne+1,null,!0,!0,!1,!0))&&((!ge||ue!=="")&&(ue+=oe(R,ne)),R.dump&&d===R.dump.charCodeAt(0)?ue+="-":ue+="- ",ue+=R.dump)}R.tag=Ce,R.dump=ue||"[]"}function Ri(R,ne,Ae){let ge="";const ue=R.tag,Ce=Object.keys(Ae);for(let ve=0,Le=Ce.length;ve<Le;ve+=1){let H="";ge!==""&&(H+=", "),R.condenseFlow&&(H+='"');const ee=Ce[ve];let fe=Ae[ee];R.replacer&&(fe=R.replacer.call(Ae,ee,fe)),me(R,ne,ee,!1,!1)&&(R.dump.length>1024&&(H+="? "),H+=R.dump+(R.condenseFlow?'"':"")+":"+(R.condenseFlow?"":" "),me(R,ne,fe,!1,!1)&&(H+=R.dump,ge+=H))}R.tag=ue,R.dump="{"+ge+"}"}function w(R,ne,Ae,ge){let ue="";const Ce=R.tag,ve=Object.keys(Ae);if(R.sortKeys===!0)ve.sort();else if(typeof R.sortKeys=="function")ve.sort(R.sortKeys);else if(R.sortKeys)throw new n("sortKeys must be a boolean or a function");for(let Le=0,H=ve.length;Le<H;Le+=1){let ee="";(!ge||ue!=="")&&(ee+=oe(R,ne));const fe=ve[Le];let Be=Ae[fe];if(R.replacer&&(Be=R.replacer.call(Ae,fe,Be)),!me(R,ne+1,fe,!0,!0,!0))continue;const rt=R.tag!==null&&R.tag!=="?"||R.dump&&R.dump.length>1024;rt&&(R.dump&&d===R.dump.charCodeAt(0)?ee+="?":ee+="? "),ee+=R.dump,rt&&(ee+=oe(R,ne)),me(R,ne+1,Be,!0,rt)&&(R.dump&&d===R.dump.charCodeAt(0)?ee+=":":ee+=": ",ee+=R.dump,ue+=ee)}R.tag=Ce,R.dump=ue||"{}"}function se(R,ne,Ae){const ge=Ae?R.explicitTypes:R.implicitTypes;for(let ue=0,Ce=ge.length;ue<Ce;ue+=1){const ve=ge[ue];if((ve.instanceOf||ve.predicate)&&(!ve.instanceOf||typeof ne=="object"&&ne instanceof ve.instanceOf)&&(!ve.predicate||ve.predicate(ne))){if(Ae?ve.multi&&ve.representName?R.tag=ve.representName(ne):R.tag=ve.tag:R.tag="?",ve.represent){const Le=R.styleMap[ve.tag]||ve.defaultStyle;let H;if(l.call(ve.represent)==="[object Function]")H=ve.represent(ne,Le);else if(u.call(ve.represent,Le))H=ve.represent[Le](ne,Le);else throw new n("!<"+ve.tag+'> tag resolver accepts not "'+Le+'" style');R.dump=H}return!0}}return!1}function me(R,ne,Ae,ge,ue,Ce,ve){R.tag=null,R.dump=Ae,se(R,Ae,!1)||se(R,Ae,!0);const Le=l.call(R.dump),H=ge;ge&&(ge=R.flowLevel<0||R.flowLevel>ne);const ee=Le==="[object Object]"||Le==="[object Array]";let fe,Be;if(ee&&(fe=R.duplicates.indexOf(Ae),Be=fe!==-1),(R.tag!==null&&R.tag!=="?"||Be||R.indent!==2&&ne>0)&&(ue=!1),Be&&R.usedDuplicates[fe])R.dump="*ref_"+fe;else{if(ee&&Be&&!R.usedDuplicates[fe]&&(R.usedDuplicates[fe]=!0),Le==="[object Object]")ge&&Object.keys(R.dump).length!==0?(w(R,ne,R.dump,ue),Be&&(R.dump="&ref_"+fe+R.dump)):(Ri(R,ne,R.dump),Be&&(R.dump="&ref_"+fe+" "+R.dump));else if(Le==="[object Array]")ge&&R.dump.length!==0?(R.noArrayIndent&&!ve&&ne>0?Js(R,ne-1,R.dump,ue):Js(R,ne,R.dump,ue),Be&&(R.dump="&ref_"+fe+R.dump)):(Qs(R,ne,R.dump),Be&&(R.dump="&ref_"+fe+" "+R.dump));else if(Le==="[object String]")R.tag!=="?"&&un(R,R.dump,ne,Ce,H);else{if(Le==="[object Undefined]")return!1;if(R.skipInvalid)return!1;throw new n("unacceptable kind of an object to dump "+Le)}if(R.tag!==null&&R.tag!=="?"){let rt=encodeURI(R.tag[0]==="!"?R.tag.slice(1):R.tag).replace(/!/g,"%21");R.tag[0]==="!"?rt="!"+rt:rt.slice(0,18)==="tag:yaml.org,2002:"?rt="!!"+rt.slice(18):rt="!<"+rt+">",R.dump=rt+" "+R.dump}}return!0}function be(R,ne){const Ae=[],ge=[];ce(R,Ae,ge);const ue=ge.length;for(let Ce=0;Ce<ue;Ce+=1)ne.duplicates.push(Ae[ge[Ce]]);ne.usedDuplicates=new Array(ue)}function ce(R,ne,Ae){if(R!==null&&typeof R=="object"){const ge=ne.indexOf(R);if(ge!==-1)Ae.indexOf(ge)===-1&&Ae.push(ge);else if(ne.push(R),Array.isArray(R))for(let ue=0,Ce=R.length;ue<Ce;ue+=1)ce(R[ue],ne,Ae);else{const ue=Object.keys(R);for(let Ce=0,ve=ue.length;Ce<ve;Ce+=1)ce(R[ue[Ce]],ne,Ae)}}}function Te(R,ne){ne=ne||{};const Ae=new Ee(ne);Ae.noRefs||be(R,Ae);let ge=R;return Ae.replacer&&(ge=Ae.replacer.call({"":ge},"",ge)),me(Ae,0,ge,!0,!0)?Ae.dump+`
|
|
214
|
-
`:""}t.exports.dump=Te})),ej=UK(Qt(((e,t)=>{var s=qK(),n=VK();function o(l,u){return function(){throw new Error("Function yaml."+l+" is removed in js-yaml 4. Use yaml."+u+" instead, which is now safe by default.")}}t.exports.Type=Sn(),t.exports.Schema=B5(),t.exports.FAILSAFE_SCHEMA=H5(),t.exports.JSON_SCHEMA=G5(),t.exports.CORE_SCHEMA=W5(),t.exports.DEFAULT_SCHEMA=Ux(),t.exports.load=s.load,t.exports.loadAll=s.loadAll,t.exports.dump=n.dump,t.exports.YAMLException=bu(),t.exports.types={binary:X5(),float:V5(),map:$5(),null:U5(),pairs:Q5(),set:J5(),timestamp:K5(),bool:F5(),int:q5(),merge:Y5(),omap:Z5(),seq:P5(),str:I5()},t.exports.safeLoad=o("safeLoad","load"),t.exports.safeLoadAll=o("safeLoadAll","loadAll"),t.exports.safeDump=o("safeDump","dump")}))()),{Type:lZ,Schema:cZ,FAILSAFE_SCHEMA:uZ,JSON_SCHEMA:dZ,CORE_SCHEMA:hZ,DEFAULT_SCHEMA:fZ,load:mZ,loadAll:pZ,dump:gZ,YAMLException:bZ,types:xZ,safeLoad:vZ,safeLoadAll:_Z,safeDump:yZ}=ej.default,GK=ej.default;function tj(e){return e!==null&&typeof e=="object"}function sj(e){return typeof e=="string"?"text-rose-700 dark:text-rose-300":typeof e=="number"?"text-emerald-700 dark:text-emerald-300":typeof e=="boolean"?"text-blue-700 dark:text-blue-400":e==null?"text-muted-foreground italic":"text-foreground"}function nj(e){return e==null?"null":typeof e=="string"?e===""?'""':e:String(e)}function ij({label:e,value:t,depth:s,defaultOpen:n}){const[o,l]=y.useState(n),u={paddingLeft:`${s*1.1}rem`};if(!tj(t))return r.jsxs("div",{className:"flex items-baseline gap-2 py-[1px]",style:u,children:[r.jsxs("span",{className:"text-muted-foreground",children:[e,":"]}),r.jsx("span",{className:de("whitespace-pre-wrap break-words",sj(t)),children:nj(t)})]});const h=Array.isArray(t)?t.map((d,p)=>[String(p),d]):Object.entries(t),m=Array.isArray(t)?`[${h.length}]`:`{${h.length}}`;return r.jsxs("div",{children:[r.jsxs("button",{type:"button",onClick:()=>l(d=>!d),className:"flex w-full items-center gap-1 py-[1px] text-left hover:bg-muted",style:u,children:[o?r.jsx(vn,{className:"size-3.5 shrink-0 text-muted-foreground"}):r.jsx(Xn,{className:"size-3.5 shrink-0 text-muted-foreground"}),r.jsx("span",{className:"font-medium text-foreground",children:e}),r.jsx("span",{className:"text-muted-foreground",children:m})]}),o?h.map(([d,p])=>r.jsx(ij,{label:d,value:p,depth:s+1,defaultOpen:s<1},d)):null]})}function WK({content:e}){const t=y.useMemo(()=>{try{const n=GK.loadAll(e);return{value:n.length<=1?n[0]:n,error:null}}catch(n){return{value:null,error:n instanceof Error?n.message:String(n)}}},[e]);if(t.error)return r.jsx("div",{className:"p-4",children:r.jsxs(tt,{variant:"destructive",children:["Could not parse YAML: ",t.error]})});if(!tj(t.value))return r.jsx("div",{className:"p-4 font-mono text-[12px]",children:r.jsx("span",{className:sj(t.value),children:nj(t.value)})});const s=Array.isArray(t.value)?t.value.map((n,o)=>[String(o),n]):Object.entries(t.value);return r.jsx("div",{className:"min-w-max px-4 py-3 font-mono text-[12px] leading-[1.6]",children:s.map(([n,o])=>r.jsx(ij,{label:n,value:o,depth:0,defaultOpen:!0},n))})}const KK=y.lazy(()=>su(()=>import("./code-editor-
|
|
214
|
+
`:""}t.exports.dump=Te})),ej=UK(Qt(((e,t)=>{var s=qK(),n=VK();function o(l,u){return function(){throw new Error("Function yaml."+l+" is removed in js-yaml 4. Use yaml."+u+" instead, which is now safe by default.")}}t.exports.Type=Sn(),t.exports.Schema=B5(),t.exports.FAILSAFE_SCHEMA=H5(),t.exports.JSON_SCHEMA=G5(),t.exports.CORE_SCHEMA=W5(),t.exports.DEFAULT_SCHEMA=Ux(),t.exports.load=s.load,t.exports.loadAll=s.loadAll,t.exports.dump=n.dump,t.exports.YAMLException=bu(),t.exports.types={binary:X5(),float:V5(),map:$5(),null:U5(),pairs:Q5(),set:J5(),timestamp:K5(),bool:F5(),int:q5(),merge:Y5(),omap:Z5(),seq:P5(),str:I5()},t.exports.safeLoad=o("safeLoad","load"),t.exports.safeLoadAll=o("safeLoadAll","loadAll"),t.exports.safeDump=o("safeDump","dump")}))()),{Type:lZ,Schema:cZ,FAILSAFE_SCHEMA:uZ,JSON_SCHEMA:dZ,CORE_SCHEMA:hZ,DEFAULT_SCHEMA:fZ,load:mZ,loadAll:pZ,dump:gZ,YAMLException:bZ,types:xZ,safeLoad:vZ,safeLoadAll:_Z,safeDump:yZ}=ej.default,GK=ej.default;function tj(e){return e!==null&&typeof e=="object"}function sj(e){return typeof e=="string"?"text-rose-700 dark:text-rose-300":typeof e=="number"?"text-emerald-700 dark:text-emerald-300":typeof e=="boolean"?"text-blue-700 dark:text-blue-400":e==null?"text-muted-foreground italic":"text-foreground"}function nj(e){return e==null?"null":typeof e=="string"?e===""?'""':e:String(e)}function ij({label:e,value:t,depth:s,defaultOpen:n}){const[o,l]=y.useState(n),u={paddingLeft:`${s*1.1}rem`};if(!tj(t))return r.jsxs("div",{className:"flex items-baseline gap-2 py-[1px]",style:u,children:[r.jsxs("span",{className:"text-muted-foreground",children:[e,":"]}),r.jsx("span",{className:de("whitespace-pre-wrap break-words",sj(t)),children:nj(t)})]});const h=Array.isArray(t)?t.map((d,p)=>[String(p),d]):Object.entries(t),m=Array.isArray(t)?`[${h.length}]`:`{${h.length}}`;return r.jsxs("div",{children:[r.jsxs("button",{type:"button",onClick:()=>l(d=>!d),className:"flex w-full items-center gap-1 py-[1px] text-left hover:bg-muted",style:u,children:[o?r.jsx(vn,{className:"size-3.5 shrink-0 text-muted-foreground"}):r.jsx(Xn,{className:"size-3.5 shrink-0 text-muted-foreground"}),r.jsx("span",{className:"font-medium text-foreground",children:e}),r.jsx("span",{className:"text-muted-foreground",children:m})]}),o?h.map(([d,p])=>r.jsx(ij,{label:d,value:p,depth:s+1,defaultOpen:s<1},d)):null]})}function WK({content:e}){const t=y.useMemo(()=>{try{const n=GK.loadAll(e);return{value:n.length<=1?n[0]:n,error:null}}catch(n){return{value:null,error:n instanceof Error?n.message:String(n)}}},[e]);if(t.error)return r.jsx("div",{className:"p-4",children:r.jsxs(tt,{variant:"destructive",children:["Could not parse YAML: ",t.error]})});if(!tj(t.value))return r.jsx("div",{className:"p-4 font-mono text-[12px]",children:r.jsx("span",{className:sj(t.value),children:nj(t.value)})});const s=Array.isArray(t.value)?t.value.map((n,o)=>[String(o),n]):Object.entries(t.value);return r.jsx("div",{className:"min-w-max px-4 py-3 font-mono text-[12px] leading-[1.6]",children:s.map(([n,o])=>r.jsx(ij,{label:n,value:o,depth:0,defaultOpen:!0},n))})}const KK=y.lazy(()=>su(()=>import("./code-editor-mbyEwBIp.js"),[]).then(e=>({default:e.CodeEditor})));function YK(e){const t=e.split("/").pop()?.toLowerCase().split(".").pop()??"";return t==="md"||t==="mdx"||t==="markdown"?"markdown":t==="yml"||t==="yaml"?"yaml":null}function XK(e){const t=e.split("/").pop()?.toLowerCase()??"",s=t.includes(".")?t.split(".").pop()??"":"",n={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",h:"c",cpp:"cpp",cc:"cpp",hpp:"cpp",cs:"csharp",sh:"bash",bash:"bash",zsh:"bash",json:"json",yaml:"yaml",yml:"yaml",toml:"ini",ini:"ini",md:"markdown",mdx:"markdown",css:"css",scss:"scss",less:"less",html:"xml",xml:"xml",sql:"sql",dockerfile:"dockerfile"};return n[s]?n[s]:t==="dockerfile"?"dockerfile":null}function ZK(e,t){const s=e.endsWith(`
|
|
215
215
|
`)?e.slice(0,-1):e;return!t||!kb.getLanguage(t)?s.split(`
|
|
216
216
|
`).map(Vk):s.split(`
|
|
217
217
|
`).map(n=>{if(!n)return"";try{return kb.highlight(n,{language:t,ignoreIllegals:!0}).value}catch{return Vk(n)}})}function Vk(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function QK({content:e,path:t}){const s=y.useMemo(()=>XK(t),[t]),n=y.useMemo(()=>ZK(e,s),[e,s]),o=`${Math.max(2,String(n.length).length)}ch`;return r.jsx("div",{className:"min-w-max font-mono text-[12px] leading-[1.5]",children:n.map((l,u)=>r.jsxs("div",{className:"flex",children:[r.jsx("span",{className:"shrink-0 select-none border-r border-zinc-200 bg-zinc-100 px-2 text-right text-zinc-400 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-500",style:{minWidth:`calc(${o} + 1rem)`},children:u+1}),r.jsx("span",{className:"hljs whitespace-pre px-3 text-zinc-800 dark:text-zinc-100",dangerouslySetInnerHTML:{__html:l||" "}})]},u))})}function JK({path:e,isModified:t,onViewDiff:s,onFileSaved:n,onSendToAi:o}){const[l,u]=y.useState(null),[h,m]=y.useState(""),[d,p]=y.useState(!1),[g,x]=y.useState(null),[v,S]=y.useState(!1),[k,N]=y.useState(!1),{success:E,error:A}=$s(),j=y.useMemo(()=>YK(e),[e]),[T,P]=y.useState("preview"),z=!!(l&&!l.binary&&!l.truncated),I=l?h!==l.content:!1;y.useEffect(()=>{P(j?"preview":"source"),p(!1)},[j]),y.useEffect(()=>{if(!e){u(null);return}let B=!0;return S(!0),x(null),p(!1),d8(e).then(G=>{B&&(u(G),m(G.content),S(!1))}).catch(G=>{B&&(x(G instanceof Error?G.message:String(G)),S(!1))}),()=>{B=!1}},[e]);async function M(){if(!(!e||!l||!I||k)){N(!0);try{await h8(e,h);const B={...l,content:h,size:new TextEncoder().encode(h).length};u(B),p(!1),E(`Saved ${e}.`),n?.(e)}catch(B){A(B instanceof Error?B.message:String(B))}finally{N(!1)}}}function L(){m(l?.content??""),p(!1)}return e?r.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col border-l border-border bg-card",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:e}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[r.jsx("span",{children:"Read-only view of tracked file."}),l?.truncated?r.jsx("span",{className:"text-amber-700",children:"Truncated — file exceeds 1MB."}):null,l?.binary?r.jsx("span",{className:"text-amber-700",children:"Binary file."}):null]})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[j&&!l?.binary?r.jsxs("div",{className:"flex items-center rounded-md border border-border p-0.5",children:[r.jsxs("button",{type:"button",onClick:()=>P("preview"),"aria-pressed":T==="preview",className:de("flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium transition-colors",T==="preview"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted"),children:[r.jsx(Lb,{className:"size-3.5"}),"Preview"]}),r.jsxs("button",{type:"button",onClick:()=>P("source"),"aria-pressed":T==="source",className:de("flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium transition-colors",T==="source"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted"),children:[r.jsx(bN,{className:"size-3.5"}),"Source"]})]}):null,t?r.jsx(J,{onClick:s,size:"sm",type:"button",variant:"outline",children:"View diff"}):null,o?r.jsx(J,{"aria-label":"Send file to AI input",className:"size-8",disabled:!e,onClick:o,size:"icon",title:"Send file path to AI input",type:"button",variant:"outline",children:r.jsx(Gt,{className:"size-4"})}):null,d?r.jsxs(r.Fragment,{children:[r.jsxs(J,{disabled:!I||k,onClick:()=>{M()},size:"sm",type:"button",children:[r.jsx(DN,{}),"Apply"]}),r.jsxs(J,{disabled:k,onClick:L,size:"sm",type:"button",variant:"outline",children:[r.jsx(ts,{}),"Cancel"]})]}):z?r.jsxs(J,{onClick:()=>{P("source"),p(!0)},size:"sm",type:"button",variant:"outline",children:[r.jsx(rl,{}),"Edit"]}):null]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-card",children:g?r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"destructive",children:g})}):v?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading…"}):l?.binary?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Cannot display binary content."}):l?d?r.jsx(y.Suspense,{fallback:r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading editor…"}),children:r.jsx(KK,{path:e,value:h,onChange:m})}):j&&T==="preview"?j==="markdown"?r.jsx(L5,{content:l.content}):r.jsx(WK,{content:l.content}):r.jsx(QK,{content:l.content,path:e}):null})]}):r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"muted",className:"border-dashed p-12 text-center",children:"Select a file to view its contents."})})}function eY({activeHunkIndex:e,filePaths:t,hunkCount:s,pendingNextFilePath:n,selectedFile:o}){if(s>0&&e<s-1)return{kind:"hunk",activeHunkIndex:e+1};const l=t.indexOf(o),u=t[l+1];return u?n===u?{kind:"file",filePath:u}:{kind:"confirm-next-file",filePath:u}:{kind:"none"}}function Gk(e){const t={name:"",fullPath:"",children:new Map};for(const s of e){const n=s.name.split("/");let o=t;n.forEach((l,u)=>{let h=o.children.get(l);h||(h={name:l,fullPath:n.slice(0,u+1).join("/"),children:new Map},o.children.set(l,h)),o=h}),o.branch=s}return t}function Wk({label:e,tree:t,onSelect:s,defaultOpen:n,forceOpen:o}){const[l,u]=y.useState(n??!1),h=o||l,m=t.children.size===0;return r.jsxs("div",{className:"mb-1",children:[r.jsxs("button",{type:"button",onClick:()=>u(d=>!d),className:"flex w-full items-center gap-1 px-2 py-0.5 text-left text-[11px] font-semibold uppercase tracking-wide text-muted-foreground hover:text-foreground",children:[h?r.jsx(vn,{size:12}):r.jsx(Xn,{size:12}),e,m?null:r.jsxs("span",{className:"ml-1 text-[10px] font-normal",children:["(",t.children.size,")"]})]}),h&&!m?r.jsx("ul",{children:Array.from(t.children.values()).map(d=>r.jsx(rj,{node:d,depth:1,onSelect:s,forceOpen:o},d.fullPath))}):null]})}function rj({node:e,depth:t,onSelect:s,forceOpen:n}){const[o,l]=y.useState(!0),u=n||o,h=e.children.size>0,m=e.branch,d={paddingLeft:`${t*10}px`};return!h&&m?r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>s(m),style:d,title:m.name,className:`flex w-full items-center gap-1.5 py-0.5 pr-2 text-left text-[12px] hover:bg-muted/60 ${m.current?"font-semibold text-emerald-700":""}`,children:[r.jsx(xn,{size:11,className:"shrink-0 opacity-70"}),r.jsx("span",{className:"truncate",children:e.name}),m.current?r.jsx("span",{className:"text-[10px]",children:"●"}):null]})}):r.jsxs("li",{children:[r.jsxs("button",{type:"button",onClick:()=>{m?s(m):l(p=>!p)},style:d,className:"flex w-full items-center gap-1 py-0.5 pr-2 text-left text-[12px] hover:bg-muted/60",children:[h?u?r.jsx(vn,{size:11}):r.jsx(Xn,{size:11}):r.jsx("span",{className:"inline-block w-[11px]"}),r.jsx("span",{className:"truncate",children:e.name})]}),u&&h?r.jsx("ul",{children:Array.from(e.children.values()).map(p=>r.jsx(rj,{node:p,depth:t+1,onSelect:s,forceOpen:n},p.fullPath))}):null]})}function tY({selectedCommit:e,selectedFile:t,diff:s,diffLoading:n,diffError:o}){return r.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col bg-card border-b border-border",children:[r.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t??(e?e.subject:"Commit")}),e?r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[r.jsx("span",{className:"font-mono",children:e.hash.slice(0,12)}),r.jsxs("span",{children:[e.author," <",e.email,">"]}),r.jsx("span",{children:new Date(e.timestamp*1e3).toLocaleString()})]}):null]})}),r.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:o?r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"destructive",children:o})}):e?n?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading diff…"}):s?r.jsx(lu,{activeHunkIndex:0,diff:s}):r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"muted",className:"border-dashed p-6 text-center",children:e.parents.length>1?"Merge commit with no conflict resolution — no diff against the first parent.":"No textual changes in this commit."})}):r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"muted",className:"border-dashed p-12 text-center",children:"Select a commit to inspect its diff."})})})]})}function sY({files:e,filesError:t,selectedHash:s,selectedFile:n,onSelect:o}){return r.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden border-r border-border",children:[r.jsx("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:r.jsxs("h2",{className:"text-[13px] font-semibold tracking-tight",children:["Files",e.length?r.jsx("span",{className:"ml-2 text-[11px] font-normal text-muted-foreground",children:e.length}):null]})}),r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:t?r.jsx("div",{className:"p-3",children:r.jsx(tt,{variant:"destructive",children:t})}):s?e.length===0?r.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:"No file changes."}):r.jsx("ul",{className:"divide-y divide-border",children:e.map(l=>r.jsx("li",{children:r.jsxs("button",{onClick:()=>o(l.path),type:"button",title:l.path,className:`flex w-full items-center gap-2 px-2 py-1 text-left text-[12px] transition-colors hover:bg-muted/60 ${n===l.path?"bg-muted":""}`,children:[r.jsx("span",{className:nY(l.index),children:l.index.trim()||"·"}),r.jsx("span",{className:"truncate font-mono",children:l.path})]})},l.path))}):r.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:"Select a commit to see its files."})})]})}function nY(e){const t="inline-flex h-4 w-4 shrink-0 items-center justify-center rounded text-[10px] font-bold";switch(e.trim().toUpperCase()){case"A":return`${t} bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-300`;case"D":return`${t} bg-red-100 text-red-800 dark:bg-red-500/15 dark:text-red-300`;case"M":return`${t} bg-amber-100 text-amber-800 dark:bg-amber-500/15 dark:text-amber-300`;case"R":return`${t} bg-blue-100 text-blue-800 dark:bg-blue-500/15 dark:text-blue-300`;case"C":return`${t} bg-indigo-100 text-indigo-800 dark:bg-indigo-500/15 dark:text-indigo-300`;default:return`${t} bg-slate-100 text-slate-700 dark:bg-slate-500/15 dark:text-slate-300`}}const Kk=["#3b82f6","#10b981","#f59e0b","#ec4899","#8b5cf6","#14b8a6","#ef4444","#84cc16"];function Sc(e){return Kk[e%Kk.length]}function iY({lane:e,laneCount:t,edges:s,throughLanes:n,isMerge:o,height:l=28,laneWidth:u=14}){const m=Math.max(e+1,t,1)*u,d=l/2,p=wc(e,u),g=o?4:3.5;return r.jsxs("svg",{width:m,height:l,viewBox:`0 0 ${m} ${l}`,style:{flex:"0 0 auto",display:"block"},children:[n.map(x=>r.jsx("line",{x1:wc(x,u),y1:0,x2:wc(x,u),y2:l,stroke:Sc(x),strokeWidth:1.5},`t-${x}`)),r.jsx("line",{x1:p,y1:0,x2:p,y2:d,stroke:Sc(e),strokeWidth:1.5}),s.map((x,v)=>{const S=wc(x.fromLane,u),k=wc(x.toLane,u);if(S===k)return r.jsx("line",{x1:S,y1:d,x2:k,y2:l,stroke:Sc(x.toLane),strokeWidth:1.5},`e-${v}`);const N=d+(l-d)/2;return r.jsx("path",{d:`M ${S} ${d} C ${S} ${N}, ${k} ${N}, ${k} ${l}`,fill:"none",stroke:Sc(x.toLane),strokeWidth:1.5},`e-${v}`)}),r.jsx("circle",{cx:p,cy:d,r:g,fill:Sc(e),stroke:"var(--background, #fff)",strokeWidth:1.5})]})}function wc(e,t){return e*t+t/2}const rY=5,Nb=new Map,o0=new Map,Cb=[];let Eb=0;function Yk(){for(;Eb<rY&&Cb.length>0;){const e=Cb.shift();e&&(Eb++,e())}}function aY(e){return Nb.get(e)}function oY(e){const t=Nb.get(e);if(t)return Promise.resolve(t);const s=o0.get(e);if(s)return s;const n=new Promise((o,l)=>{Cb.push(()=>{B8(e).then(u=>{u.state!=="pending"&&Nb.set(e,u),o(u)}).catch(l).finally(()=>{Eb--,o0.delete(e),Yk()})})});return o0.set(e,n),Yk(),n}function lY({sha:e}){const[t,s]=y.useState(()=>aY(e)??null),n=y.useRef(null);if(y.useEffect(()=>{if(t)return;const u=n.current;if(!u||typeof IntersectionObserver>"u")return;let h=!0;const m=new IntersectionObserver(d=>{d.some(p=>p.isIntersecting)&&(m.disconnect(),oY(e).then(p=>{h&&s(p)}).catch(()=>{}))},{rootMargin:"200px"});return m.observe(u),()=>{h=!1,m.disconnect()}},[e,t]),!t||t.state==="unknown"||t.totalCount===0)return r.jsx("span",{ref:n,"aria-hidden":!0,className:"inline-block size-2 shrink-0"});const o=cY(t.state),l=`CI: ${t.state} (${t.totalCount} check${t.totalCount!==1?"s":""})`;return r.jsx("span",{"aria-label":l,className:`shrink-0 size-2 rounded-full ${o}`,title:l})}function cY(e){switch(e){case"success":return"bg-emerald-500";case"pending":return"bg-amber-400 animate-pulse";case"failure":return"bg-red-500";case"error":return"bg-orange-500";default:return"bg-zinc-400"}}const Xk=28;function uY({commits:e,loading:t,error:s,selectedHash:n,maxLanes:o,rowRefs:l,onSelect:u,onLoadMore:h}){const{sendToAgent:m}=It(),[d,p]=y.useState(null);function g(x,v){p(null),m({prompt:_P(x,v),source:{type:"git-commit",label:x.hash.slice(0,7)},label:`${x.hash.slice(0,7)}: ${v}`})}return r.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden border-r border-border",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[r.jsxs("h2",{className:"text-[13px] font-semibold tracking-tight",children:["Commit tree",e.length?r.jsxs("span",{className:"ml-2 text-[11px] font-normal text-muted-foreground",children:[e.length," commits"]}):null]}),r.jsx(J,{disabled:t,onClick:h,size:"sm",type:"button",variant:"outline",children:"Load more"})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:s?r.jsx("div",{className:"p-3",children:r.jsx(tt,{variant:"destructive",children:s})}):t&&e.length===0?r.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:"Loading commits…"}):e.length===0?r.jsx("div",{className:"p-3 text-[12px] text-muted-foreground",children:"No commits."}):r.jsx("ul",{className:"divide-y divide-border",children:e.map(x=>r.jsxs("li",{ref:v=>{v?l.current.set(x.hash,v):l.current.delete(x.hash)},className:"group flex flex-col",children:[r.jsxs("div",{className:`flex items-center transition-colors hover:bg-muted/60 ${n===x.hash?"bg-muted":""}`,children:[r.jsxs("button",{onClick:()=>u(x.hash),type:"button",className:"flex min-w-0 flex-1 items-center gap-2 px-2 py-0.5 text-left",style:{minHeight:Xk},title:`${x.hash}
|
|
@@ -219,4 +219,4 @@ ${x.author} <${x.email}>
|
|
|
219
219
|
${x.subject}`,children:[r.jsx(iY,{lane:x.lane,laneCount:Math.max(x.laneCount,o),edges:x.edges,throughLanes:x.throughLanes,isMerge:x.parents.length>1,height:Xk}),r.jsxs("span",{className:"flex items-center gap-1 font-mono text-[10px] text-muted-foreground",children:[x.hash.slice(0,7),r.jsx(lY,{sha:x.hash})]}),r.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[x.refs.map(v=>r.jsx("span",{className:hY(v.kind),children:v.name},`${v.kind}-${v.name}`)),r.jsx("span",{className:"truncate text-[12px]",children:x.subject})]}),r.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:x.author}),r.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/70",title:new Date(x.timestamp*1e3).toLocaleString(),children:dY(x.timestamp)})]}),r.jsx(Ki,{className:`mr-1 shrink-0 ${d===x.hash?"opacity-100":""}`,label:`Ask AI about commit ${x.hash.slice(0,7)}`,onAsk:()=>p(v=>v===x.hash?null:x.hash)})]}),d===x.hash?r.jsx("div",{className:"px-2 pb-1.5 pt-0.5",children:r.jsx(jr,{placeholder:"What should the agent do with this commit? (explain, summarize, find regressions…)",onSubmit:v=>g(x,v),onCancel:()=>p(null)})}):null]},x.hash))})})]})}function dY(e){if(!e)return"";const t=Math.max(0,Math.floor(Date.now()/1e3-e));if(t<60)return`${t}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const n=Math.floor(s/60);if(n<24)return`${n}h`;const o=Math.floor(n/24);if(o<30)return`${o}d`;const l=Math.floor(o/30);return l<12?`${l}mo`:`${Math.floor(l/12)}y`}function hY(e){const t="rounded border px-1.5 py-px text-[10px] font-medium";switch(e){case"head":return`${t} border-emerald-200 bg-emerald-100 text-emerald-800 dark:border-emerald-400/30 dark:bg-emerald-500/15 dark:text-emerald-300`;case"branch":return`${t} border-blue-200 bg-blue-100 text-blue-800 dark:border-blue-400/30 dark:bg-blue-500/15 dark:text-blue-300`;case"remote":return`${t} border-slate-200 bg-slate-100 text-slate-700 dark:border-zinc-700/80 dark:bg-zinc-800/80 dark:text-zinc-300`;case"tag":return`${t} border-amber-200 bg-amber-100 text-amber-800 dark:border-amber-400/30 dark:bg-amber-500/15 dark:text-amber-300`}}const Zk=200;function fY(){const[e,t]=y.useState([]),[s,n]=y.useState(Zk),[o,l]=y.useState(0),[u,h]=y.useState(!0),[m,d]=y.useState(null),[p,g]=y.useState(null),[x,v]=y.useState([]),[S,k]=y.useState(!1),[N,E]=y.useState(null),[A,j]=y.useState(null),[T,P]=y.useState(""),[z,I]=y.useState(!1),[M,L]=y.useState(null),B=y.useCallback($=>{g($),v([]),j(null),P("")},[]);y.useEffect(()=>{let $=!0;return h(!0),d(null),a8(s).then(q=>{$&&(t(q),q.length>0&&!q.some(F=>F.hash===p)&&B(q[0].hash))}).catch(q=>{$&&d(q instanceof Error?q.message:String(q))}).finally(()=>{$&&h(!1)}),()=>{$=!1}},[s,o]),y.useEffect(()=>{if(!p){v([]),j(null),k(!1);return}let $=!0;return E(null),k(!0),l8(p).then(q=>{$&&(v(q),j(q[0]?.path??null))}).catch(q=>{$&&E(q instanceof Error?q.message:String(q))}).finally(()=>{$&&k(!1)}),()=>{$=!1}},[p]),y.useEffect(()=>{if(!p||!A){P(""),I(!1);return}let $=!0;return L(null),I(!0),o8(p,A).then(q=>{$&&P(q)}).catch(q=>{$&&L(q instanceof Error?q.message:String(q))}).finally(()=>{$&&I(!1)}),()=>{$=!1}},[p,A]);const G=y.useMemo(()=>e.reduce(($,q)=>Math.max($,q.laneCount),1),[e]),Z=e.find($=>$.hash===p)??null;return{commits:e,loading:u,error:m,selectedHash:p,setSelectedHash:B,files:x,filesError:N,selectedFile:A,setSelectedFile:j,diff:T,diffLoading:z||S,diffError:M,maxLanes:G,selectedCommit:Z,loadMore:()=>n($=>$+Zk),refresh:()=>l($=>$+1)}}function mY({branches:e=[]}){const{commits:t,loading:s,error:n,selectedHash:o,setSelectedHash:l,files:u,filesError:h,selectedFile:m,setSelectedFile:d,diff:p,diffLoading:g,diffError:x,maxLanes:v,selectedCommit:S,loadMore:k,refresh:N}=fY();du(N);const[E,A]=y.useState(""),j=y.useMemo(()=>{const L=E.trim().toLowerCase();return L?e.filter(B=>B.name.toLowerCase().includes(L)):e},[e,E]),T=y.useMemo(()=>Gk(j.filter(L=>!L.remote)),[j]),P=y.useMemo(()=>Gk(j.filter(L=>L.remote)),[j]),z=E.trim().length>0,I=y.useRef(new Map);function M(L){const B=L.remote?"remote":"branch",G=t.find(q=>q.refs.some(F=>F.kind===B&&F.name===L.name));if(!G)return;l(G.hash);const Z=I.current.get(G.hash),$=Z?.parentElement?.parentElement;!Z||!$||$.scrollTo({top:Math.max(Z.offsetTop-$.clientHeight/2+Z.clientHeight/2,0),behavior:"smooth"})}return r.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 grid-cols-[220px_minmax(0,1fr)]",children:[r.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden border-r border-border",children:[r.jsxs("div",{className:"flex shrink-0 flex-col gap-1 border-b border-border px-3 py-1.5",children:[r.jsx("h2",{className:"text-[13px] font-semibold tracking-tight",children:"Branches"}),r.jsx("input",{type:"search",value:E,onChange:L=>A(L.target.value),placeholder:"Search branches…",className:"w-full rounded border border-border bg-background px-2 py-1 text-[11px] outline-none focus:border-foreground"})]}),r.jsxs("div",{className:"min-h-0 flex-1 overflow-auto py-1",children:[r.jsx(Wk,{label:"Local",tree:T,onSelect:M,defaultOpen:!0,forceOpen:z}),r.jsx(Wk,{label:"Remote",tree:P,onSelect:M,forceOpen:z})]})]}),r.jsxs("div",{className:"grid min-h-0 min-w-0 grid-rows-[minmax(0,3fr)_minmax(0,2fr)]",children:[r.jsx(tY,{selectedCommit:S,selectedFile:m,diff:p,diffLoading:g,diffError:x}),r.jsxs("div",{className:"grid min-h-0 min-w-0 grid-cols-[minmax(0,1fr)_280px]",children:[r.jsx(uY,{commits:t,loading:s,error:n,selectedHash:o,maxLanes:v,rowRefs:I,onSelect:l,onLoadMore:k}),r.jsx(sY,{files:u,filesError:h,selectedHash:o,selectedFile:m,onSelect:d})]})]})]})}function pY({repo:e,file:t,onClose:s}){const[n,o]=y.useState(""),[l,u]=y.useState(null),[h,m]=y.useState(!0);y.useEffect(()=>{let p=!0;return m(!0),u(null),XN(t,e).then(g=>{p&&o(g)}).catch(g=>{p&&u(g instanceof Error?g.message:String(g))}).finally(()=>{p&&m(!1)}),()=>{p=!1}},[e,t]),y.useEffect(()=>{function p(g){g.key==="Escape"&&s()}return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[s]);const d=bx(n);return _a.createPortal(r.jsxs("div",{className:"fixed inset-0 z-[1000] flex justify-end",children:[r.jsx("button",{"aria-label":"Close diff",className:"absolute inset-0 bg-black/35",onClick:s,type:"button"}),r.jsxs("div",{className:"relative z-10 flex h-full w-[min(900px,calc(100vw-3rem))] flex-col bg-card shadow-xl",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-2",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t}),r.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground",children:[r.jsx("span",{className:"font-mono",children:e}),d.additions||d.deletions?r.jsxs("span",{className:"flex items-center gap-1 font-mono",children:[r.jsxs("span",{className:"text-emerald-700",children:["+",d.additions]}),r.jsxs("span",{className:"text-red-700",children:["-",d.deletions]})]}):null]})]}),r.jsx(J,{"aria-label":"Close diff",onClick:s,size:"icon",variant:"ghost",children:r.jsx(ts,{})})]}),r.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:l?r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"destructive",children:l})}):h?r.jsx("div",{className:"p-4 text-xs text-muted-foreground",children:"Loading diff…"}):r.jsx(lu,{diff:n||"No unstaged diff for this file."})})]})]}),document.body)}function jb(e){return e.split(/[\\/]/).filter(Boolean).pop()??"project"}function gY({initialPath:e,onSelect:t,selectedPath:s}){const[n,o]=y.useState(e),[l,u]=y.useState(e),[h,m]=y.useState(null),[d,p]=y.useState(null),[g,x]=y.useState(!1),v=bY(h);return y.useEffect(()=>{o(e)},[e]),y.useEffect(()=>{h&&u(h.path)},[h]),y.useEffect(()=>{let S=!0;return x(!0),p(null),nC(n).then(k=>{S&&(m(k),t(k.path))}).catch(k=>{S&&p(k instanceof Error?k.message:String(k))}).finally(()=>{S&&x(!1)}),()=>{S=!1}},[n,t]),r.jsxs("div",{className:"rounded-md border border-border bg-background",children:[r.jsxs("div",{className:"flex items-center gap-2 border-b border-border p-2",children:[v?r.jsx(J,{"aria-label":"Open parent folder",onClick:()=>h&&o(h.parent),size:"icon",type:"button",variant:"ghost",children:r.jsx(vn,{className:"rotate-90"})}):null,r.jsx(ht,{"aria-label":"Folder path",className:"h-7 min-w-0 flex-1 font-mono text-xs",onChange:S=>u(S.target.value),onKeyDown:S=>{if(S.key==="Enter"){S.preventDefault();const k=l.trim();k&&o(k)}},spellCheck:!1,value:l}),g?r.jsx(Et,{className:"size-4 shrink-0 animate-spin text-muted-foreground"}):null]}),r.jsxs("div",{className:"max-h-56 overflow-auto p-1",children:[d?r.jsx(tt,{variant:"destructive",className:"m-1",children:d}):null,!d&&h?.entries.length===0?r.jsx(tt,{variant:"muted",className:"m-1 text-center",children:"No folders here."}):null,h?.entries.map(S=>r.jsxs(J,{className:de("h-8 w-full justify-start rounded-sm px-2 text-left",s===S.path&&"bg-muted"),onClick:()=>o(S.path),title:S.path,type:"button",variant:"ghost",children:[r.jsx(pa,{className:"text-accent"}),r.jsx("span",{className:"truncate",children:S.name})]},S.path))]})]})}function bY(e){return!!(e&&e.parent!==e.path)}function xY({data:e,onRefresh:t}){const[s,n]=y.useState(!1),[o,l]=y.useState("path"),[u,h]=y.useState(e.git.cwd),[m,d]=y.useState(""),[p,g]=y.useState(!1),[x,v]=y.useState(null),[S,k]=y.useState(!1),[N,E]=y.useState(e.git.cwd),A=y.useRef(null),j=e.git.selectedRepository,T=j?.name??(e.git.cwd?jb(e.git.cwd):"Add Git project"),{error:P,success:z}=$s(),I=_Y({gitCwd:e.git.cwd});y.useEffect(()=>{h(e.git.cwd),E(e.git.cwd)},[e.git.cwd]),y.useEffect(()=>{if(!s)return;function q(F){A.current&&F.target instanceof Node&&!A.current.contains(F.target)&&n(!1)}return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[s]);async function M(q){try{await g8(q),n(!1),await t(),z(`Switched to ${q}.`)}catch(F){P(F instanceof Error?F.message:String(F))}}async function L(q){const F=q.trim();if(!vY(F)){const D="Please add an absolute path. Paths beginning with ~ are not expanded here.";return v(D),P(D),!1}try{const D=jb(F);return await b8(D,F),v(null),await t(),z(`Added Git project ${D}.`),!0}catch(D){const X=D instanceof Error?D.message:String(D);return v(X),P(X),!1}}async function B(q){try{await p8(q),await t(),z(`Removed Git project ${q}.`)}catch(F){P(F instanceof Error?F.message:String(F))}}async function G(q){q.preventDefault(),await L(u)&&n(!1)}async function Z(q){q.preventDefault();const F=m.trim();if(F){g(!0),v(null);try{const{name:D}=await x8(F);d(""),await t(),z(`Cloned and added ${D}.`),n(!1)}catch(D){const X=D instanceof Error?D.message:String(D);v(X),P(X)}finally{g(!1)}}}function $(){v(null),E(I.selectedPath),k(!0)}return r.jsxs("div",{className:"relative z-50 flex items-center gap-2",ref:A,children:[r.jsxs(J,{className:"max-w-[220px] justify-start gap-2 rounded-md border-border bg-card",onClick:()=>n(q=>!q),size:"sm",type:"button",variant:"outline",children:[r.jsx(pa,{className:"text-muted-foreground"}),r.jsx("span",{className:"truncate",children:T}),r.jsx(vn,{className:de("ml-auto transition-transform",s&&"rotate-180")})]}),r.jsx(J,{"aria-label":"Add Git project",onClick:$,size:"sm",type:"button",variant:"outline",children:r.jsx(Es,{})}),s?r.jsxs("div",{className:"absolute right-0 top-10 z-50 w-[min(380px,calc(100vw-2rem))] overflow-hidden rounded-lg border border-border bg-card shadow-lg",children:[r.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[r.jsx(A4,{className:"size-3.5 text-muted-foreground"}),r.jsx("div",{className:"text-xs font-semibold",children:"Git Projects"}),r.jsx(et,{className:"ml-auto h-5 px-1.5 text-[10px]",variant:"outline",children:e.config.gitRepositories.length})]}),r.jsx("div",{className:"max-h-72 overflow-auto",children:e.config.gitRepositories.length?r.jsx("div",{className:"divide-y divide-border",children:e.config.gitRepositories.map(q=>{const F=q.name===j?.name;return r.jsxs("div",{className:de("group grid w-full grid-cols-[1fr_auto_auto] items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-muted",F&&"bg-muted/70"),children:[r.jsxs("button",{className:"min-w-0 text-left",onClick:()=>{M(q.name)},type:"button",children:[r.jsx("span",{className:"block truncate text-sm font-medium leading-tight",children:q.name}),r.jsx("span",{className:"block truncate font-mono text-[10px] leading-tight text-muted-foreground",children:q.path})]}),F?r.jsx(on,{className:"size-3.5"}):r.jsx("span",{className:"size-3.5"}),r.jsx(J,{"aria-label":`Remove ${q.name}`,className:"size-6 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{B(q.name)},size:"icon",title:`Remove ${q.name}`,type:"button",variant:"ghost",children:r.jsx(Er,{className:"size-3.5 text-destructive"})})]},q.name)})}):r.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:"No saved Git projects yet."})}),r.jsxs("div",{className:"border-t border-border bg-muted/20 p-2",children:[r.jsxs("div",{className:"mb-1.5 flex gap-1 text-[11px]",children:[r.jsxs("button",{className:de("flex items-center gap-1 rounded px-2 py-0.5 transition-colors",o==="path"?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>{l("path"),v(null)},type:"button",children:[r.jsx(pa,{className:"size-3"}),"Local path"]}),r.jsxs("button",{className:de("flex items-center gap-1 rounded px-2 py-0.5 transition-colors",o==="url"?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>{l("url"),v(null)},type:"button",children:[r.jsx(kh,{className:"size-3"}),"Clone URL"]})]}),o==="path"?r.jsxs("form",{className:"flex gap-1.5",onSubmit:G,children:[r.jsx(ht,{"aria-label":"Paste absolute path",className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:q=>{h(q.target.value),v(null)},placeholder:"/absolute/path",value:u}),r.jsxs(J,{className:"h-7 px-2 text-[11px]",size:"sm",type:"submit",children:[r.jsx(Es,{className:"size-3"}),"Add"]}),r.jsx(J,{"aria-label":"Browse and add Git project",className:"h-7 px-2",onClick:$,size:"sm",type:"button",variant:"outline",children:r.jsx(wN,{className:"size-3"})})]}):r.jsxs("form",{className:"flex gap-1.5",onSubmit:Z,children:[r.jsx(ht,{"aria-label":"Git remote URL",className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:q=>{d(q.target.value),v(null)},placeholder:"https://… or git@host:owner/repo.git",value:m}),r.jsxs(J,{className:"h-7 px-2 text-[11px]",disabled:p||!m.trim(),size:"sm",type:"submit",children:[r.jsx(kh,{className:"size-3"}),p?"Cloning…":"Clone"]})]}),x?r.jsx("div",{className:"mt-1.5 truncate text-[10px] text-destructive",children:x}):null,o==="url"?r.jsx("div",{className:"mt-1 text-[10px] text-muted-foreground",children:"Private github.com repos reuse your GitHub login; SSH uses your machine's keys. Clones into ~/.nomoreide/repos."}):null]})]}):null,S?r.jsx(aj,{confirmLabel:I.confirmLabel,errorMessage:x,initialPath:I.initialPath,selectedPath:N,title:"Add Git Project",onCancel:()=>k(!1),onSelect:E,onUse:async()=>{await L(N)&&(k(!1),n(!1))}}):null]})}function vY(e){return e.startsWith("/")}function _Y({gitCwd:e}){return{confirmLabel:"Add Git project",initialPath:e,selectedPath:e}}function aj({confirmLabel:e="Use this folder",errorMessage:t,initialPath:s,onCancel:n,onSelect:o,onUse:l,selectedPath:u,title:h="Choose Git Project Folder"}){return _a.createPortal(r.jsx("div",{className:"fixed inset-0 z-[1000] grid place-items-center bg-black/35 px-4",children:r.jsxs("div",{className:"w-full max-w-2xl rounded-xl border border-border bg-card p-4 shadow-xl",children:[r.jsxs("div",{className:"mb-3 flex items-center gap-3",children:[r.jsx("div",{className:"flex size-8 items-center justify-center rounded-lg border border-border bg-background",children:r.jsx(pa,{className:"size-4"})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("div",{className:"text-sm font-semibold",children:h}),r.jsx("div",{className:"truncate font-mono text-xs text-muted-foreground",children:u})]}),r.jsx(J,{"aria-label":"Close folder picker",onClick:n,size:"icon",variant:"ghost",children:r.jsx(ts,{})})]}),r.jsx(gY,{initialPath:s,onSelect:o,selectedPath:u}),t?r.jsx("div",{className:"mt-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:t}):null,r.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[r.jsx(J,{onClick:n,type:"button",variant:"outline",children:"Cancel"}),r.jsx(J,{onClick:()=>{l()},type:"button",children:e})]})]})}),document.body)}const kc=5,yY=240,Tb=8,SY=176+Tb;function wY({currentRepoPath:e}){const[t,s]=y.useState(null),[n,o]=y.useState([]),[l,u]=y.useState(null),[h,m]=y.useState(!0),[d,p]=y.useState(null),g=y.useRef(null),x=y.useRef(null),[v,S]=y.useState(0);y.useEffect(()=>{const $=x.current;if(!$)return;const q=new ResizeObserver(F=>{S(F[0].contentRect.width)});return q.observe($),()=>q.disconnect()},[t]);const k=y.useCallback(()=>{let $=!0;return m(!0),u(null),zp().then(q=>{$&&(s(q.repos),o(q.board))}).catch(q=>{$&&u(q instanceof Error?q.message:String(q))}).finally(()=>{$&&m(!1)}),()=>{$=!1}},[]);y.useEffect(k,[k]);const N=y.useCallback(()=>{zp().then($=>{s($.repos),o($.board)}).catch($=>{u($ instanceof Error?$.message:String($))})},[]),E=y.useCallback($=>{o($),Vy($).catch(q=>{u(q instanceof Error?q.message:String(q))})},[]),A=y.useCallback(async $=>{const q=$.trim();if(!q.startsWith("/"))return"Please add an absolute path (it must start with /).";try{const F=jb(q);await ki("/api/git/repositories",{name:F,path:q});const D=await zp();s(D.repos);const X=(D.board.includes(F)?D.board:[...D.board,F]).slice(0,kc);return o(X),await Vy(X),null}catch(F){return F instanceof Error?F.message:String(F)}},[]),j=new Map((t??[]).map($=>[$.name,$])),T=n.map($=>j.get($)).filter($=>!!$).slice(0,kc),P=(t??[]).filter($=>!n.includes($.name)),z=T.length<kc,I=Math.max(0,v-(z?SY:0)),M=v===0?kc:Math.max(1,Math.floor((I+Tb)/(yY+Tb))),L=Math.min(T.length,M),B=T.slice(0,L),G=T.length-L;function Z($){const q=g.current;if(g.current=null,q===null||q===$)return;const F=[...n],[D]=F.splice(q,1);F.splice($,0,D),E(F)}return r.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border bg-card/95 px-3 py-1.5",children:[r.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] font-semibold tracking-tight",children:[r.jsx(Bb,{className:"size-3.5"}),"Repositories",t?r.jsxs(et,{variant:"secondary",className:"ml-1",children:[T.length,t.length>T.length?` / ${t.length}`:""]}):null,G>0?r.jsxs("span",{className:"ml-1 text-[10px] font-normal text-muted-foreground",children:["+",G," hidden — widen the window or remove one"]}):null]}),r.jsxs(J,{"aria-label":"Refresh repositories",disabled:h,onClick:k,size:"sm",type:"button",variant:"outline",children:[r.jsx(Cr,{className:h?"animate-spin":void 0}),"Refresh"]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:l?r.jsx(tt,{variant:"destructive",className:"m-3",children:l}):t&&t.length===0?r.jsx(tt,{variant:"muted",className:"m-3 text-center",children:"No Git projects registered. Add one with the project picker in the header."}):r.jsxs("div",{className:"flex h-full min-h-0 gap-2 p-2",ref:x,children:[B.map(($,q)=>r.jsx(kY,{repo:$,isCurrent:!!e&&$.path===e,selectedFile:d?.repo===$.name?d.file:"",onSelectFile:F=>p({repo:$.name,file:F}),onRemove:()=>E(n.filter(F=>F!==$.name)),onMutated:N,onDragStart:()=>{g.current=q},onDropColumn:()=>Z(q)},$.name)),z?r.jsx(NY,{unpinned:P,onAdd:$=>E([...n,$].slice(0,kc)),onRegister:A}):null]})}),d?r.jsx(pY,{repo:d.repo,file:d.file,onClose:()=>p(null)}):null]})}function kY({repo:e,isCurrent:t,selectedFile:s,onSelectFile:n,onRemove:o,onMutated:l,onDragStart:u,onDropColumn:h}){const[m,d]=y.useState(!1),[p,g]=y.useState(!1),[x,v]=y.useState(!1),S=y.useCallback(async(A,j)=>{if(j.length){g(!0);try{await A(j,e.name),l()}finally{g(!1)}}},[e.name,l]),k={busy:p,onStage:A=>{S($b,A)},onUnstage:A=>{S(ZN,A)}},N=e.files.filter(A=>A.index.trim()&&A.index!=="?").length,E=x?vn:Xn;return r.jsxs("div",{className:de("flex min-w-0 flex-1 flex-col overflow-hidden rounded-md border border-border bg-card",t&&"border-primary/60 ring-1 ring-primary/30",m&&"ring-2 ring-foreground/40"),onDragOver:A=>{A.preventDefault(),d(!0)},onDragLeave:()=>d(!1),onDrop:()=>{d(!1),h()},children:[r.jsxs("div",{className:"flex shrink-0 cursor-grab items-center justify-between gap-1 border-b border-border bg-muted/40 px-1.5 py-1.5 active:cursor-grabbing",draggable:!0,onDragStart:u,children:[r.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[r.jsx(cR,{className:"size-3.5 shrink-0 text-muted-foreground/60"}),r.jsx("span",{className:"truncate text-[12px] font-semibold",title:e.path,children:e.name}),t?r.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 rounded bg-primary px-1 py-px text-[9px] font-semibold uppercase tracking-wide text-primary-foreground",title:"The repository currently selected across NoMoreIDE",children:[r.jsx(on,{className:"size-2.5"}),"Current"]}):null]}),r.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[r.jsxs("span",{className:"flex items-center gap-1 font-mono text-[10px] text-muted-foreground",children:[e.ahead?r.jsxs("span",{className:"flex items-center",title:`${e.ahead} ahead`,children:[r.jsx(sf,{className:"size-3"}),e.ahead]}):null,e.behind?r.jsxs("span",{className:"flex items-center",title:`${e.behind} behind`,children:[r.jsx(tf,{className:"size-3"}),e.behind]}):null]}),r.jsx("button",{"aria-label":`Remove ${e.name} from board`,className:"rounded p-0.5 text-muted-foreground transition-colors hover:bg-background hover:text-foreground",onClick:o,title:"Remove from board (stays registered)",type:"button",children:r.jsx(ts,{className:"size-3.5"})})]})]}),r.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:r.jsx(M5,{branch:e.branch||void 0,error:e.error,files:e.files,onSelectFile:n,root:e.path,selectedFile:s,staging:k})}),r.jsxs("div",{className:"shrink-0 border-t border-border",children:[r.jsxs("button",{"aria-expanded":x,className:"flex w-full items-center gap-1.5 bg-muted/40 px-2 py-1 text-left text-[11px] font-semibold uppercase tracking-tight text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:()=>v(A=>!A),type:"button",children:[r.jsx(E,{className:"size-3.5 shrink-0"}),r.jsx("span",{className:"flex-1",children:"Commit"}),N?r.jsxs(et,{size:"small",variant:"secondary",children:[N," staged"]}):null]}),x?r.jsx(D5,{branch:e.branch||void 0,files:e.files,onDone:l,repo:e.name}):null]})]})}function NY({unpinned:e,onAdd:t,onRegister:s}){const[n,o]=y.useState(!1),[l,u]=y.useState(null),[h,m]=y.useState(""),[d,p]=y.useState(null),[g,x]=y.useState(!1),[v,S]=y.useState(!1),[k,N]=y.useState(""),E=y.useRef(null),A=y.useRef(null);function j(){if(n){o(!1);return}u(E.current?.getBoundingClientRect()??null),p(null),o(!0)}y.useEffect(()=>{if(!n)return;function z(I){const M=I.target;M instanceof Node&&(A.current?.contains(M)||E.current?.contains(M)||o(!1))}return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[n]);async function T(z){x(!0),p(null);const I=await s(z);return x(!1),I?(p(I),!1):(m(""),o(!1),!0)}async function P(z){z.preventDefault(),await T(h)}return r.jsxs("div",{className:"w-44 shrink-0",children:[r.jsxs("button",{ref:E,className:"flex h-full w-full flex-col items-center justify-center gap-1.5 rounded-md border border-dashed border-border text-muted-foreground transition-colors hover:border-foreground/40 hover:text-foreground",onClick:j,type:"button",children:[r.jsx(Es,{className:"size-5"}),r.jsx("span",{className:"text-[12px] font-medium",children:"Add repository"})]}),n&&l?_a.createPortal(r.jsxs("div",{ref:A,className:"fixed z-[1000] w-72 overflow-hidden rounded-lg border border-border bg-card shadow-xl",style:{left:Math.max(8,Math.min(l.left,window.innerWidth-296)),top:Math.min(l.top,window.innerHeight-320)},children:[e.length?r.jsxs("div",{className:"border-b border-border",children:[r.jsx("div",{className:"px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Pin a registered repo"}),r.jsx("div",{className:"max-h-52 overflow-auto pb-1",children:e.map(z=>r.jsxs("button",{className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm hover:bg-muted",onClick:()=>{t(z.name),o(!1)},type:"button",children:[r.jsx(Bb,{className:"size-3.5 shrink-0 text-muted-foreground"}),r.jsx("span",{className:"min-w-0 flex-1 truncate",title:z.path,children:z.name}),z.files.length?r.jsx(et,{variant:"outline",className:"h-5 px-1.5 text-[10px]",children:z.files.length}):null]},z.name))})]}):null,r.jsxs("div",{className:"p-2.5",children:[r.jsx("div",{className:"pb-1.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Add a new repository"}),r.jsxs("form",{className:"flex gap-1.5",onSubmit:P,children:[r.jsx(ht,{"aria-label":"Repository absolute path",className:"h-7 flex-1 px-2 font-mono text-[11px]",onChange:z=>{m(z.target.value),p(null)},placeholder:"/absolute/path/to/repo",value:h}),r.jsx(J,{className:"h-7 px-2 text-[11px]",disabled:g||!h.trim(),size:"sm",type:"submit",children:"Add"})]}),r.jsxs(J,{className:"mt-1.5 h-7 w-full gap-1.5 text-[11px]",disabled:g,onClick:()=>{N(h.trim()||""),S(!0)},size:"sm",type:"button",variant:"outline",children:[r.jsx(wN,{className:"size-3"}),"Browse folders…"]}),d?r.jsx("div",{className:"mt-1.5 text-[10px] text-destructive",children:d}):null]})]}),document.body):null,v?r.jsx(aj,{confirmLabel:"Add repository",errorMessage:d,initialPath:k||"/",selectedPath:k,title:"Add Repository",onCancel:()=>S(!1),onSelect:N,onUse:async()=>{await T(k)&&S(!1)}}):null]})}const Ab=300,CY=600,EY=new Set(["md","mdx","markdown","txt","rst","adoc","json","jsonc","json5","yaml","yml","toml","xml","ini","cfg","conf","env","properties","csv","tsv","lock","svg","map","snap","png","jpg","jpeg","gif","ico","webp"]);function jY(e){const t=e.toLowerCase();if(t.endsWith(".d.ts")||t.endsWith(".min.js")||t.endsWith(".min.css"))return!1;const s=t.lastIndexOf(".");return s<0?!0:!EY.has(t.slice(s+1))}function TY(e){return e>=CY?"danger":e>=Ab?"warn":"ok"}const AY={ok:"bg-emerald-500/60",warn:"bg-amber-500/70",danger:"bg-destructive/70"},RY={ok:"text-muted-foreground",warn:"text-amber-600 dark:text-amber-400",danger:"text-destructive"};function MY({onOpenFile:e,root:t}){const[s,n]=y.useState([]),[o,l]=y.useState(!0),[u,h]=y.useState(null),[m,d]=y.useState(!0);function p(){l(!0),h(null),u8().then(n).catch(k=>h(k instanceof Error?k.message:String(k))).finally(()=>l(!1))}y.useEffect(()=>{p()},[]);const g=y.useMemo(()=>m?s.filter(k=>jY(k.path)):s,[s,m]),x=s.length-g.length,v=g[0]?.lines??1,S=g.filter(k=>k.lines>=Ab).length;return r.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-card/85",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-2",children:[r.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[r.jsx(yN,{className:"size-4"}),r.jsx("span",{className:"font-semibold text-foreground",children:"Largest files"}),!o&&!u?r.jsxs("span",{children:[g.length," files · ",S," over ",Ab," lines",m&&x>0?` · ${x} data/docs hidden`:""]}):null]}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsxs(J,{size:"sm",variant:m?"default":"outline",className:"h-7",onClick:()=>d(k=>!k),title:"Hide docs, data, config and generated files",type:"button",children:[r.jsx(bN,{}),"Code only"]}),r.jsxs(J,{size:"sm",variant:"outline",className:"h-7",onClick:p,disabled:o,type:"button",children:[o?r.jsx(Et,{className:"animate-spin"}):r.jsx(Cr,{}),"Refresh"]})]})]}),u?r.jsx(tt,{variant:"destructive",className:"m-3",children:u}):o&&s.length===0?r.jsxs("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:[r.jsx(Et,{className:"mr-2 size-4 animate-spin"}),"Scanning tracked files…"]}):g.length===0?r.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:s.length===0?"No tracked text files found.":"No code files — toggle off “Code only” to see data & docs."}):r.jsx("ul",{className:"min-h-0 flex-1 divide-y divide-border/60 overflow-auto",children:g.map((k,N)=>{const E=TY(k.lines);return r.jsxs("li",{className:"group flex items-center gap-3 px-3 transition-colors hover:bg-muted/50",children:[r.jsx("span",{className:"w-6 shrink-0 text-right font-mono text-[10px] text-muted-foreground",children:N+1}),r.jsx("button",{type:"button",onClick:()=>e(k.path),className:"min-w-0 flex-1 py-1.5 text-left",children:r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx("span",{className:"truncate font-mono text-[11px]",children:k.path}),r.jsxs("span",{className:de("shrink-0 font-mono text-[11px] tabular-nums",RY[E]),children:[k.truncated?"≥":"",k.lines.toLocaleString()," lines"]})]}),r.jsx("div",{className:"mt-1 h-1 w-full overflow-hidden rounded-full bg-muted",children:r.jsx("div",{className:de("h-full rounded-full",AY[E]),style:{width:`${Math.max(2,k.lines/v*100)}%`}})})]})}),r.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-0.5",children:[r.jsx(DY,{file:k,root:t}),r.jsx(OY,{file:k,root:t})]})]},k.path)})})]})}function DY({file:e,root:t}){const{sendToAgent:s}=It(),n=cu(t,e.path),o=e.path.split("/").pop()??e.path;function l(){s({prompt:vP({absolutePath:n,lines:e.lines,relativePath:e.path}),source:{label:o,type:"large-file"},label:`Help me split \`${e.path}\` (${e.lines.toLocaleString()} lines).`,mode:"send"})}function u(){s({prompt:n,source:{label:o,type:"large-file"},mode:"draft"})}return r.jsx(oj,{label:`AI actions for ${e.path}`,trigger:r.jsx(Gt,{className:"size-3.5"}),children:h=>r.jsxs(r.Fragment,{children:[r.jsx(Fc,{icon:r.jsx(Gt,{className:"size-3.5"}),onSelect:()=>{h(),l()},children:"Ask AI to split this file"}),r.jsx(Fc,{icon:r.jsx(_N,{className:"size-3.5"}),onSelect:()=>{h(),u()},children:"Send file path to AI"})]})})}function OY({file:e,root:t}){const{error:s,success:n}=$s(),o=cu(t,e.path),l=e.path.split("/").pop()??e.path;async function u(h,m){try{await navigator.clipboard.writeText(h),n(`Copied ${m}.`)}catch(d){s(d instanceof Error?d.message:`Could not copy ${m}.`)}}return r.jsx(oj,{label:`Copy path for ${e.path}`,trigger:r.jsxs(r.Fragment,{children:[r.jsx(xN,{className:"size-3.5"}),r.jsx("span",{className:"sr-only",children:"More actions"})]}),children:h=>r.jsxs(r.Fragment,{children:[r.jsx(Fc,{icon:r.jsx(zb,{className:"size-3.5"}),onSelect:()=>{h(),u(l,"file name")},children:"Copy file name"}),r.jsx(Fc,{icon:r.jsx(wh,{className:"size-3.5"}),onSelect:()=>{h(),u(e.path,"relative path")},children:"Copy relative path"}),r.jsx(Fc,{icon:r.jsx(wh,{className:"size-3.5"}),onSelect:()=>{h(),u(o,"absolute path")},children:"Copy absolute path"})]})})}function oj({children:e,label:t,trigger:s}){const[n,o]=y.useState(!1),[l,u]=y.useState({right:0,top:0}),h=y.useRef(null),m=y.useRef(null);function d(){o(!1)}function p(){const g=h.current?.getBoundingClientRect();g&&u({top:g.bottom+6,right:window.innerWidth-g.right}),o(x=>!x)}return y.useEffect(()=>{if(!n)return;function g(v){const S=v.target;h.current?.contains(S)||m.current?.contains(S)||d()}function x(v){v.key==="Escape"&&d()}return document.addEventListener("mousedown",g),document.addEventListener("keydown",x),window.addEventListener("scroll",d,!0),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",x),window.removeEventListener("scroll",d,!0)}},[n]),r.jsxs(r.Fragment,{children:[r.jsx("button",{"aria-label":t,className:de("flex h-7 min-w-7 shrink-0 items-center justify-center gap-1 rounded-md px-1.5 text-muted-foreground opacity-0 transition-all duration-150 hover:bg-muted hover:text-foreground group-hover:opacity-100",n&&"bg-muted text-foreground opacity-100"),onClick:p,ref:h,title:t,type:"button",children:s}),n?_a.createPortal(r.jsx("div",{className:"fixed z-50 w-56 overflow-hidden rounded-md border border-border bg-card p-1 shadow-md",ref:m,style:{top:l.top,right:l.right},children:e(d)}),document.body):null]})}function Fc({children:e,icon:t,onSelect:s}){return r.jsxs("button",{className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-muted",onClick:s,type:"button",children:[r.jsx("span",{className:"text-muted-foreground",children:t}),r.jsx("span",{className:"min-w-0 flex-1 truncate",children:e})]})}function Qk(e,t,s){const n=e.trim(),o=n.toLowerCase(),l=[],u=/\breview|check|inspect|audit\b/.test(o),h=/\btest|verify|ci\b/.test(o),m=/\bcommit\b/.test(o)||/\bship|push|pr|pull request\b/.test(o),d=/\bpush|ship|pr|pull request\b/.test(o),p=/\bpr\b|pull request/.test(o),g=zY(o,s);return p&&l.push({kind:"action",id:"assert-pr-branch",title:"Check PR branch",op:"assert-pr-branch"}),u&&(l.push(sh("gate-review","Approve review","Review the current changes?")),l.push(Nc("review","Review changes","Review the current git changes. Summarize risks, likely bugs, and anything that should change before committing.",nh(g,["skills","mcpServers"])))),h&&l.push(Nc("verify","Run verification","Run the relevant tests or checks for this repository. If something fails, stop and explain the failure.",nh(g,["skills","mcpServers","plugins"]))),m&&(l.push(Nc("commit-message","Generate commit message","Stage the appropriate changed files, inspect the staged diff briefly, and draft one conventional commit message. Do not commit.",nh(g,["skills"]))),l.push(sh("gate-commit","Approve commit","Commit with this generated message?")),l.push({kind:"action",id:"commit",title:"Commit with approved message",op:"commit"})),d&&(l.push(sh("gate-push","Approve push",p?"Push and continue toward a PR?":"Push this branch?")),l.push({kind:"action",id:"push",title:"Push branch",op:"push"})),p&&(l.push(Nc("open-pr","Open PR","Open a pull request for the current branch. Use the latest commit subject as the title and summarize the commit list in the body.",nh(g,["mcpServers","plugins"]))),l.push({kind:"action",id:"checkout-default-and-pull",title:"Return to default branch",op:"checkout-default-and-pull"})),l.length||(l.push(sh("gate-start","Approve start","Run this workflow?")),l.push(Nc("ai-step","AI step",n||"Complete this workflow step.",g))),{id:IY(lj(Jk(o))||"custom-workflow",t),name:Jk(o),description:n||"Custom AI-authored workflow.",builtin:!1,steps:BY(l)}}function LY(e){return["Create a NoMoreIDE workflow from this user intent:","",e.trim()||"(no intent provided)","","Return a workflow JSON object only. Use this shape:","{",' "id": "short-kebab-id",',' "name": "Human name",',' "description": "One sentence",',' "steps": [',' { kind: "gate", id: "gate-id", title: "Approve thing", message: "Question for the user?" },',' { kind: "agent", id: "ai-id", title: "AI task", prompt: "Clear instruction", capabilities: { skills: [], mcpServers: [], plugins: [], hooks: [] }, verify: "committed" },',' { kind: "action", id: "push", title: "Push", op: "push" },',' { kind: "action", id: "checkout-default-and-pull", title: "Return to default branch", op: "checkout-default-and-pull" }'," ]","}","","Use gates before mutating git or GitHub state. Prefer intent-level AI steps over direct MCP tool calls."].join(`
|
|
220
220
|
`)}function Jk(e){const t=/\breview|check|inspect|audit\b/.test(e),s=/\bcommit\b|\bship|push|pr|pull request\b/.test(e),n=/\bpr\b|pull request/.test(e),o=/\btest|verify|ci\b/.test(e);return t&&s&&n?"Review, Commit & PR":o&&s&&n?"Verify, Commit & PR":t&&s?"Review & Commit":s&&n?"Commit & PR":s?"Commit workflow":t?"Review workflow":"Custom workflow"}function sh(e,t,s){return{kind:"gate",id:e,title:t,message:s}}function Nc(e,t,s,n,o){return{kind:"agent",id:e,title:t,prompt:s,capabilities:Fx(n),verify:o}}function zY(e,t){return Fx({skills:t.skills.filter(s=>e.includes(s.toLowerCase())),mcpServers:t.mcpServers.filter(s=>e.includes(s.toLowerCase())),plugins:t.plugins.filter(s=>e.includes(s.toLowerCase())),hooks:t.hooks.filter(s=>e.includes(s.toLowerCase()))})??{}}function nh(e,t){const s={};for(const n of t){const o=e[n];o?.length&&(s[n]=o)}return Fx(s)}function Fx(e){if(!e)return;const t={};for(const s of["skills","mcpServers","plugins","hooks"]){const n=Array.from(new Set((e[s]??[]).filter(Boolean)));n.length&&(t[s]=n)}return Object.keys(t).length?t:void 0}function BY(e){const t=new Map;return e.map(s=>{const n=lj(s.id)||s.kind,o=t.get(n)??0;return t.set(n,o+1),o===0?{...s,id:n}:{...s,id:`${n}-${o+1}`}})}function IY(e,t){const s=new Set(t.map(l=>l.id));let n=e||"workflow",o=2;for(;s.has(n);)n=`${e}-${o}`,o++;return n}function lj(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function PY(){const{run:e,start:t,resume:s,approve:n,skip:o,stop:l,dismiss:u}=rH(),[h,m]=y.useState([]),[d,p]=y.useState(null),[g,x]=y.useState(null),[v,S]=y.useState(null),[k,N]=y.useState(!0),[E,A]=y.useState(!1),[j,T]=y.useState(!0);y.useEffect(()=>{let L=!0;return N(!0),Promise.all([DO(),VN().catch(()=>null)]).then(([B,G])=>{L&&(m(B),p(G))}).catch(B=>{L&&S(B instanceof Error?B.message:String(B))}).finally(()=>{L&&N(!1)}),()=>{L=!1}},[]);function P(L){A(!0),t(L,j)}async function z(L){S(null);try{const B=await OO(L);m(B),x(null)}catch(B){S(B instanceof Error?B.message:String(B))}}async function I(L){if(!L.builtin&&window.confirm(`Delete workflow "${L.name}"?`)){S(null);try{m(await LO(L.id))}catch(B){S(B instanceof Error?B.message:String(B))}}}function M(L){x({...L,id:qx(`${L.id}-copy`,h),name:`${L.name} copy`,builtin:!1,steps:L.steps.map((B,G)=>({...B,id:`${B.id}-${G+1}`}))})}return e&&E?r.jsx(YY,{run:e,onApprove:n,onSkip:o,onStop:l,onBack:()=>A(!1),onResume:()=>{A(!0),s(j)},onRestart:()=>{A(!0),t(e.workflow,j)}}):g?r.jsx(UY,{agent:d?JY(d):null,existing:h,initial:g,onCancel:()=>x(null),onSave:L=>{z(L)}}):r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-auto bg-card/85",children:[r.jsxs("div",{className:"border-b border-border px-4 py-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3",children:[r.jsxs("div",{children:[r.jsxs("h2",{className:"flex items-center gap-1.5 text-[13px] font-semibold",children:[r.jsx(Gt,{className:"size-4"})," AI Workflows"]}),r.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"One-click rituals that exceed the IDE — the agent does the work in the dock, pausing at each gate for your OK."})]}),r.jsxs(J,{onClick:()=>x(tX(h)),size:"sm",type:"button",variant:"outline",children:[r.jsx(Es,{className:"size-3.5"})," New"]})]}),r.jsxs("label",{className:"mt-2 flex w-fit items-center gap-1.5 text-[11px] text-muted-foreground",children:[r.jsx("input",{checked:j,className:"size-3.5 accent-primary",onChange:L=>T(L.target.checked),type:"checkbox"}),"Run without step-by-step prompts",r.jsx("span",{className:"text-muted-foreground/60",children:"— gates still pause; risky shell still asks."})]})]}),v?r.jsx(tt,{variant:"destructive",className:"m-4",children:v}):k?r.jsxs("div",{className:"flex flex-1 items-center justify-center text-[12px] text-muted-foreground",children:[r.jsx(Et,{className:"mr-2 size-4 animate-spin"})," Loading workflows…"]}):r.jsxs(r.Fragment,{children:[e?r.jsx($Y,{onClear:u,onView:()=>A(!0),run:e}):null,r.jsx("div",{className:"grid gap-3 p-4 sm:grid-cols-2 xl:grid-cols-3",children:h.map(L=>r.jsx(HY,{lastRun:e?.workflow.id===L.id?e:null,workflow:L,onDelete:()=>{I(L)},onDuplicate:()=>M(L),onEdit:()=>x(L),onRun:()=>P(L)},L.id))})]})]})}function $Y({onClear:e,onView:t,run:s}){const n=s.outcome==="running";return r.jsx("section",{className:"mx-4 mt-4 rounded-md border border-border bg-background p-3 shadow-sm",children:r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:n?"Workflow running":"Last workflow"}),r.jsx(hj,{outcome:s.outcome})]}),r.jsx("p",{className:"mt-1 truncate text-[13px] font-medium",children:s.workflow.name}),r.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:[n?"Started":"Ran"," ",dj(s.startedAt)]})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsxs(J,{onClick:t,size:"sm",type:"button",children:[r.jsx(cl,{className:"size-3.5"})," View run"]}),n?null:r.jsxs(J,{onClick:e,size:"sm",type:"button",variant:"outline",children:[r.jsx(ts,{className:"size-3.5"})," Clear"]})]})]})})}function HY({lastRun:e,workflow:t,onDelete:s,onDuplicate:n,onEdit:o,onRun:l}){const[u,h]=y.useState(!1),m=t.steps.length;return r.jsxs("div",{className:"flex flex-col rounded-lg border border-border bg-background p-3.5 shadow-sm",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsx("h3",{className:"text-[13px] font-semibold",children:t.name}),t.builtin?r.jsx("span",{className:"rounded-full border border-border px-1.5 py-px text-[9px] uppercase tracking-wide text-muted-foreground",children:"Template"}):null]}),t.description?r.jsx("p",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:t.description}):null,e?r.jsxs("p",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[r.jsx(cl,{className:"size-3"}),e.outcome==="running"?"Running now":`Last run ${dj(e.startedAt)}`]}):null,r.jsxs("button",{"aria-expanded":u,className:"mt-2.5 flex w-full items-center gap-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground",onClick:()=>h(d=>!d),type:"button",children:[r.jsx(Xn,{className:de("size-3 shrink-0 transition-transform",u?"rotate-90":""),"aria-hidden":!0}),r.jsxs("span",{children:[m," ",m===1?"step":"steps"]})]}),u?r.jsx("ol",{className:"mt-1.5 space-y-1",children:t.steps.map(d=>r.jsxs("li",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[r.jsx(iX,{kind:d.kind}),r.jsx("span",{className:"truncate",children:Jh(d)})]},d.id))}):null,r.jsxs(J,{className:"mt-3 w-full",onClick:l,size:"sm",type:"button",children:[r.jsx(Nr,{className:"size-3.5"})," Run"]}),r.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-1.5",children:[r.jsxs(J,{onClick:o,size:"sm",type:"button",variant:"outline",children:[r.jsx(sM,{className:"size-3.5"})," Edit"]}),r.jsxs(J,{onClick:n,size:"sm",type:"button",variant:"outline",children:[r.jsx(wh,{className:"size-3.5"})," Copy"]}),r.jsxs(J,{disabled:t.builtin,onClick:s,size:"sm",title:t.builtin?"Duplicate or edit to create your own version first":"Delete workflow",type:"button",variant:"outline",children:[r.jsx(Er,{className:"size-3.5"})," Delete"]})]})]})}function UY({agent:e,existing:t,initial:s,onCancel:n,onSave:o}){const[l,u]=y.useState(()=>structuredClone(s)),[h,m]=y.useState(s.description??""),[d,p]=y.useState(!1),g=eX(e),{sendToAgent:x}=It(),v=!l.id.trim()||!l.name.trim()||l.steps.length===0;function S(z,I){u(M=>({...M,steps:M.steps.map((L,B)=>B===z?I(L):L)}))}function k(z,I){u(M=>{const L=z+I;if(L<0||L>=M.steps.length)return M;const B=[...M.steps],[G]=B.splice(z,1);return B.splice(L,0,G),{...M,steps:B}})}function N(z){u(I=>({...I,steps:I.steps.filter((M,L)=>L!==z)}))}function E(z,I){u(M=>{const L=[...M.steps];return L.splice(z,0,qY(I,M.steps)),{...M,steps:L}})}function A(z=h){const I=Qk(z,t,g);u(I)}function j(z){const I=Qk(z,[],g);u(M=>({...M,steps:[...M.steps,...I.steps]}))}function T(){x({prompt:LY(h||l.description||l.name),source:{type:"workflow",label:"Workflow composer"},mode:"draft"})}function P(){const z=il(l.id)||qx(il(l.name)||"workflow",t);o({...l,id:z,name:l.name.trim(),description:(h||l.description)?.trim()||void 0,builtin:!1,steps:l.steps.map(sX)})}return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-3",children:[r.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[r.jsx(Gt,{className:"size-4 shrink-0"}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("input",{"aria-label":"Workflow name",className:"w-full bg-transparent text-[14px] font-semibold outline-none",onChange:z=>u(I=>({...I,name:z.target.value,id:il(z.target.value)||I.id})),placeholder:"Name your workflow",value:l.name}),r.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:l.id})]})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[r.jsxs(J,{onClick:()=>p(z=>!z),size:"sm",type:"button",variant:d?"default":"outline",children:[r.jsx(Ci,{className:"size-3.5"})," AI compose"]}),r.jsxs(J,{onClick:n,size:"sm",type:"button",variant:"outline",children:[r.jsx(eu,{className:"size-3.5"})," Back"]}),r.jsxs(J,{disabled:v,onClick:P,size:"sm",type:"button",children:[r.jsx(on,{className:"size-3.5"})," Save"]})]})]}),d?r.jsx("section",{className:"shrink-0 border-b border-border bg-muted/20 p-4",children:r.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1.1fr)_minmax(0,0.9fr)]",children:[r.jsxs("div",{className:"rounded-lg border border-border bg-background p-3 shadow-sm",children:[r.jsx(wr,{children:"Describe workflow"}),r.jsx("textarea",{className:"min-h-16 w-full resize-none bg-transparent text-[13px] leading-relaxed outline-none placeholder:text-muted-foreground",onChange:z=>m(z.target.value),placeholder:"Review my changes with code-review, ask before commit, push, then open a PR with GitHub...",value:h}),r.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[r.jsxs(J,{onClick:()=>A(),size:"sm",type:"button",children:[r.jsx(Ci,{className:"size-3.5"})," Draft timeline"]}),r.jsxs(J,{onClick:T,size:"sm",type:"button",variant:"outline",children:[r.jsx(TN,{className:"size-3.5"})," Ask AI"]}),["Commit safely","Review then push","Fix CI then PR","File issue from changes"].map(z=>r.jsx("button",{className:"rounded-md border border-border bg-muted/30 px-2 py-1 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:()=>{m(z),A(z)},type:"button",children:z},z))]})]}),r.jsxs("div",{className:"grid gap-3",children:[r.jsx(VY,{onAdd:j}),r.jsx(GY,{capabilities:g})]})]})}):null,r.jsx("main",{className:"min-h-0 flex-1 overflow-auto p-4",children:r.jsxs("div",{className:"mx-auto max-w-3xl",children:[r.jsx(eN,{onInsert:z=>E(0,z)}),l.steps.length?l.steps.map((z,I)=>r.jsxs(y.Fragment,{children:[r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("div",{className:"relative flex w-9 shrink-0 justify-center pt-2",children:[r.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border"}),r.jsx(FY,{index:I,kind:z.kind})]}),r.jsx("div",{className:"min-w-0 flex-1 pb-1",children:r.jsx(WY,{capabilities:g,index:I,isFirst:I===0,isLast:I===l.steps.length-1,onMove:k,onRemove:N,onUpdate:S,step:z})})]}),r.jsx(eN,{onInsert:M=>E(I+1,M)})]},`${z.kind}:${z.id}`)):r.jsx("div",{className:"ml-[3.25rem] flex h-24 items-center justify-center rounded-lg border border-dashed border-border text-[12px] text-muted-foreground",children:"Pick a step kind above to start building."})]})})]})}function eN({defaultOpen:e=!1,onInsert:t}){const[s,n]=y.useState(e),o=[{kind:"gate",label:"Gate"},{kind:"agent",label:"AI"},{kind:"action",label:"Auto"}];return r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("div",{className:"relative flex w-9 shrink-0 justify-center",children:[r.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border"}),r.jsx("button",{"aria-label":s?"Cancel adding step":"Add step here",className:de("relative z-10 my-1.5 flex size-5 items-center justify-center rounded-full border bg-card text-muted-foreground transition-colors",s?"border-primary/50 text-primary":"border-border hover:border-primary/50 hover:text-primary"),onClick:()=>n(l=>!l),type:"button",children:s?r.jsx(ts,{className:"size-3"}):r.jsx(Es,{className:"size-3"})})]}),r.jsx("div",{className:"flex-1 py-1",children:s?r.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:o.map(({kind:l,label:u})=>r.jsxs("button",{className:"flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-muted-foreground transition-colors hover:border-primary/40 hover:text-foreground",onClick:()=>{t(l),n(!1)},type:"button",children:[r.jsx(fj,{kind:l})," ",u]},l))}):null})]})}function FY({index:e,kind:t}){return r.jsxs("div",{className:"relative z-10 flex size-9 items-center justify-center rounded-full border border-border bg-card shadow-sm",children:[r.jsx("span",{className:"absolute -right-1 -top-1 flex size-4 items-center justify-center rounded-full border border-border bg-background font-mono text-[9px] text-muted-foreground",children:e+1}),r.jsx(fj,{kind:t})]})}function qY(e,t){const s=new Set(t.map(o=>o.id)),n=o=>{let l=o,u=2;for(;s.has(l);)l=`${o}-${u++}`;return l};return e==="gate"?{kind:"gate",id:n("gate"),title:"Approve step",message:"Continue?"}:e==="action"?{kind:"action",id:n("action"),title:"Commit with approved message",op:"commit"}:{kind:"agent",id:n("step"),title:"AI step",prompt:""}}function VY({onAdd:e}){const[t,s]=y.useState("");return r.jsxs("form",{className:"rounded-lg border border-dashed border-border bg-background/70 p-3",onSubmit:n=>{n.preventDefault();const o=t.trim();o&&(e(o),s(""))},children:[r.jsx(wr,{children:"Add a step"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-[12px] outline-none placeholder:text-muted-foreground",onChange:n=>s(n.target.value),placeholder:"ask before merge, run tests, open an issue...",value:t}),r.jsxs(J,{size:"sm",type:"submit",variant:"outline",children:[r.jsx(Es,{className:"size-3.5"})," Add"]})]})]})}function GY({capabilities:e}){const t=[...e.skills.map(s=>`@skill:${s}`),...e.mcpServers.map(s=>`@mcp:${s}`),...e.plugins.map(s=>`@plugin:${s}`)].slice(0,18);return t.length?r.jsxs("div",{className:"rounded-lg border border-border bg-background p-3",children:[r.jsx(wr,{children:"Detected capabilities"}),r.jsx("div",{className:"flex max-h-20 flex-wrap gap-1.5 overflow-hidden",children:t.map(s=>r.jsx("span",{className:"rounded-md border border-border bg-muted/30 px-2 py-1 font-mono text-[11px] text-muted-foreground",children:s},s))})]}):null}function WY({capabilities:e,index:t,isFirst:s,isLast:n,onMove:o,onRemove:l,onUpdate:u,step:h}){return r.jsx("section",{className:"group rounded-lg border border-border bg-background p-3 shadow-sm",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Rb,{kind:h.kind}),r.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-[13px] font-semibold outline-none",onChange:m=>u(t,d=>({...d,title:m.target.value})),value:h.title})]}),h.kind==="gate"?r.jsx("textarea",{className:"mt-2 min-h-12 w-full resize-none bg-transparent text-[12px] leading-relaxed text-muted-foreground outline-none focus:text-foreground",onChange:m=>u(t,d=>d.kind==="gate"?{...d,message:m.target.value}:d),placeholder:"Question to ask before continuing…",value:h.message}):h.kind==="action"?r.jsxs("div",{className:"mt-2 space-y-1.5",children:[r.jsxs("select",{className:"w-full rounded-md border border-border bg-background px-2 py-1 text-[12px] outline-none",onChange:m=>{const d=m.target.value;u(t,p=>p.kind==="action"?{...p,op:d}:p)},value:h.op,children:[r.jsx("option",{value:"commit",children:"Commit staged changes"}),r.jsx("option",{value:"push",children:"Push branch"}),r.jsx("option",{value:"assert-pr-branch",children:"Check PR branch"}),r.jsx("option",{value:"checkout-default-and-pull",children:"Return to default branch"})]}),r.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:cj(h.op)})]}):r.jsxs(r.Fragment,{children:[r.jsx("textarea",{className:"mt-2 min-h-16 w-full resize-none bg-transparent text-[12px] leading-relaxed text-muted-foreground outline-none focus:text-foreground",onChange:m=>u(t,d=>d.kind==="agent"?{...d,prompt:m.target.value}:d),placeholder:"What should the agent do at this step?",value:h.prompt}),r.jsxs("label",{className:"mt-2 flex w-fit items-center gap-1.5 text-[11px] text-muted-foreground",children:[r.jsx("input",{checked:h.isolated??!1,className:"size-3.5 accent-primary",onChange:m=>u(t,d=>d.kind==="agent"?{...d,isolated:m.target.checked}:d),type:"checkbox"}),"Fresh session",r.jsx("span",{className:"text-muted-foreground/60",children:"— cheaper; this step won't see earlier steps' context."})]}),r.jsx(KY,{capabilities:e,selected:h.capabilities,onToggle:(m,d)=>u(t,p=>p.kind==="agent"?{...p,capabilities:nX(p.capabilities,m,d)}:p)})]})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-70 transition-opacity group-hover:opacity-100",children:[r.jsx(J,{disabled:s,onClick:()=>o(t,-1),size:"sm",type:"button",variant:"ghost",children:"↑"}),r.jsx(J,{disabled:n,onClick:()=>o(t,1),size:"sm",type:"button",variant:"ghost",children:"↓"}),r.jsx(J,{onClick:()=>l(t),size:"sm",type:"button",variant:"ghost",children:r.jsx(Er,{className:"size-3.5"})})]})]})})}function KY({capabilities:e,onToggle:t,selected:s}){const n=[{key:"skills",label:"Skills",values:e.skills},{key:"mcpServers",label:"MCP",values:e.mcpServers},{key:"plugins",label:"Plugins",values:e.plugins},{key:"hooks",label:"Hooks",values:e.hooks}];return r.jsxs("div",{className:"space-y-2",children:[r.jsx(wr,{children:"Capabilities"}),n.map(o=>r.jsxs("div",{children:[r.jsx("div",{className:"mb-1 text-[10px] text-muted-foreground",children:o.label}),o.values.length?r.jsx("div",{className:"flex flex-wrap gap-1.5",children:o.values.map(l=>{const u=s?.[o.key]?.includes(l)??!1;return r.jsx("button",{className:de("rounded-md border px-2 py-1 text-[11px] transition-colors",u?"border-primary/50 bg-primary/10 text-primary":"border-border bg-muted/30 text-muted-foreground hover:bg-muted"),onClick:()=>t(o.key,l),type:"button",children:l},l)})}):r.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"None detected."})]},o.key))]})}function YY({run:e,onApprove:t,onSkip:s,onStop:n,onBack:o,onResume:l,onRestart:u}){const{sendToAgent:h}=It(),m=e.outcome!=="running",[d,p]=y.useState(e.index);y.useEffect(()=>{p(e.index)},[e.index]);const g=e.workflow.steps[d]??e.workflow.steps[e.index],x=e.statuses[d]??"pending",v=e.outputs[d],S=e.outputs[d-1],k=g?.kind==="gate"&&x==="waiting",N=x==="failed"||x==="blocked",E=x==="blocked"&&g?.kind==="action"&&g.op==="assert-pr-branch";return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsxs("h2",{className:"flex items-center gap-1.5 text-[13px] font-semibold",children:[r.jsx(Gt,{className:"size-4"})," ",e.workflow.name]}),r.jsxs("p",{className:"mt-0.5 flex items-center gap-1 text-[11px] text-muted-foreground",children:[r.jsx(cl,{className:"size-3"})," Watch the agent work in the dock below."]})]}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx(hj,{outcome:e.outcome}),r.jsxs(J,{onClick:o,size:"sm",type:"button",variant:"outline",children:[r.jsx(eu,{className:"size-3.5"})," Workflows"]}),m?null:r.jsxs(J,{onClick:n,size:"sm",type:"button",variant:"outline",children:[r.jsx(so,{className:"size-3.5"})," Stop"]})]})]}),r.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden lg:grid-cols-[minmax(240px,320px)_minmax(0,1fr)]",children:[r.jsx("aside",{className:"min-h-0 overflow-auto border-b border-border bg-background/55 p-3 lg:border-b-0 lg:border-r",children:r.jsx("ol",{className:"space-y-1",children:e.workflow.steps.map((A,j)=>{const T=e.statuses[j],P=T==="running"||T==="waiting",z=j===d;return r.jsx("li",{children:r.jsxs("button",{className:de("flex w-full items-center gap-2 rounded-md border px-2.5 py-2 text-left transition-colors",z?"border-primary/45 bg-primary/[0.06]":P?"border-primary/30 bg-primary/[0.03]":"border-transparent hover:border-border hover:bg-muted/40"),onClick:()=>p(j),type:"button",children:[r.jsx("span",{className:de("flex size-7 shrink-0 items-center justify-center rounded-full border bg-card",T==="failed"?"border-destructive/50":T==="blocked"?"border-amber-500/50":P?"border-primary/50":T==="done"?"border-emerald-500/50":"border-border"),children:r.jsx(sN,{status:T,kind:A.kind})}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate text-[12px] font-medium",children:Jh(A)}),r.jsxs("span",{className:"mt-0.5 flex items-center gap-1.5",children:[r.jsx(Rb,{kind:A.kind}),r.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:tN(T)})]})]}),r.jsx(Xn,{className:de("size-3.5 shrink-0 text-muted-foreground/50 transition-transform",z?"translate-x-0.5 text-primary":"")})]})},A.id)})})}),r.jsx("main",{className:"min-h-0 overflow-auto p-4",children:g?r.jsxs("section",{className:de("min-h-full rounded-lg border bg-background p-4 shadow-sm",x==="failed"?"border-destructive/40 bg-destructive/[0.03]":x==="blocked"?"border-amber-500/40 bg-amber-500/[0.04]":x==="running"||x==="waiting"?"border-primary/40 bg-primary/[0.03]":"border-border"),children:[r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border pb-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(sN,{status:x,kind:g.kind}),r.jsx("h3",{className:"truncate text-[13px] font-semibold",children:Jh(g)})]}),r.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[r.jsx(Rb,{kind:g.kind}),r.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:tN(x)})]})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[m&&N&&d===e.index&&!E?r.jsxs(J,{"aria-label":"Resume the workflow from this step",onClick:l,size:"sm",type:"button",children:[r.jsx(Nr,{className:"size-3.5"})," Resume workflow"]}):null,N?r.jsxs(J,{"aria-label":"Debug this workflow step with AI",onClick:()=>h({prompt:H$({workflowName:e.workflow.name,step:g,status:x,error:e.error,previousOutput:S,output:v}),source:{type:"workflow-debug",label:g.title},mode:"send",label:`Debug workflow step: ${g.title}`,background:!0}),size:"sm",type:"button",variant:"outline",children:[r.jsx(Gt,{className:"size-3.5"})," Debug with AI"]}):null,m?null:r.jsxs(J,{"aria-label":"Stop workflow run from step detail",onClick:n,size:"sm",type:"button",variant:"outline",children:[r.jsx(so,{className:"size-3.5"})," Stop after this step"]})]})]}),r.jsxs("div",{className:"py-3 text-[11px] leading-relaxed",children:[r.jsx(QY,{output:v,previousOutput:S,status:x,step:g}),k?r.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-1.5",children:[r.jsxs(J,{onClick:t,size:"sm",type:"button",children:[r.jsx(on,{className:"size-3.5"})," Approve"]}),r.jsxs(J,{onClick:s,size:"sm",type:"button",variant:"outline",children:[r.jsx(IN,{className:"size-3.5"})," Skip"]}),r.jsxs(J,{onClick:n,size:"sm",type:"button",variant:"outline",children:[r.jsx(ts,{className:"size-3.5"})," Stop"]})]}):null,x==="failed"&&e.error?r.jsx("p",{className:"mt-3 text-destructive",children:e.error}):null,E?r.jsx(XY,{error:e.error,onRestart:u,workflowName:e.workflow.name}):null,x==="blocked"&&e.error?r.jsx("p",{className:"mt-3 text-amber-700 dark:text-amber-400",children:e.error}):null]})]}):null})]})]})}function XY({error:e,onRestart:t,workflowName:s}){const{sendToAgent:n,setOpen:o,streaming:l,turns:u}=It(),[h,m]=y.useState(!1),[d,p]=y.useState(null),[g,x]=y.useState(!1),[v,S]=y.useState(null),[k,N]=y.useState(null),E=d===null?"":ZY(u,d),A=Y$(E),j=h&&!A&&l;function T(z){p(u.length),N(null),S(null),n({prompt:[U$({workflowName:s,error:e}),z?.trim()?z.trim():""].filter(Boolean).join(`
|
|
221
221
|
|
|
222
|
-
`),source:{type:"workflow-branch-recovery",label:s},mode:"send",label:`Recommend PR branch for ${s}`,background:!0}),m(!0)}async function P(){if(A){x(!0),N(null);try{await m8(A),S(A)}catch(z){N(z instanceof Error?z.message:String(z))}finally{x(!1)}}}return r.jsxs("div",{className:"mt-3 rounded-md border border-border bg-muted/35 p-3",children:[r.jsx(wr,{children:"Recover with AI"}),r.jsx("p",{className:"mb-2 text-[11px] text-muted-foreground",children:"Let the agent inspect the change and suggest a feature branch. You approve before anything changes."}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsxs(J,{onClick:()=>T(),size:"sm",type:"button",children:[r.jsx(Gt,{className:"size-3.5"})," Recommend branch with AI"]}),v?r.jsxs(J,{onClick:t,size:"sm",type:"button",variant:"outline",children:[r.jsx(Nr,{className:"size-3.5"})," Run again"]}):null]}),j?r.jsxs("p",{className:"mt-2 flex items-center gap-1 text-[11px] text-muted-foreground",children:[r.jsx(Et,{className:"size-3 animate-spin"})," Choosing a branch name in the background."]}):null,A?r.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[r.jsx(wr,{children:"Recommended branch"}),r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[r.jsx("code",{className:"min-w-0 rounded bg-muted px-2 py-1 font-mono text-[12px] text-foreground",children:A}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsxs(J,{disabled:g||v===A,onClick:()=>{P()},size:"sm",type:"button",children:[g?r.jsx(Et,{className:"size-3.5 animate-spin"}):r.jsx(on,{className:"size-3.5"}),"Create this branch"]}),r.jsxs(J,{disabled:g,onClick:()=>T("Recommend a different concise branch name. Keep the same output contract with `BRANCH_NAME: <branch-name>`."),size:"sm",type:"button",variant:"outline",children:[r.jsx(Gt,{className:"size-3.5"})," Ask for another"]})]})]})]}):E&&!j?r.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[r.jsx("p",{className:"text-[11px] text-muted-foreground",children:"The agent did not return a branch name the workflow could read."}),r.jsxs(J,{className:"mt-2",onClick:()=>T("Return only a concise branch suggestion using this exact line: `BRANCH_NAME: <branch-name>`."),size:"sm",type:"button",variant:"outline",children:[r.jsx(Gt,{className:"size-3.5"})," Ask for another"]})]}):null,v?r.jsxs("p",{className:"mt-2 text-[11px] text-emerald-700 dark:text-emerald-400",children:["Branch created: ",r.jsx("code",{className:"font-mono",children:v}),". Run the workflow again from here."]}):null,k?r.jsx("p",{className:"mt-2 text-[11px] text-destructive",children:k}):null,E?r.jsxs(J,{className:"mt-2",onClick:()=>o(!0),size:"sm",type:"button",variant:"outline",children:[r.jsx(TN,{className:"size-3.5"})," Open agent"]}):null]})}function ZY(e,t){for(let s=e.length-1;s>=t;s--)if(e[s]?.role==="assistant")return e[s].text.trim();return""}function tN(e){return e==="running"?"Running":e==="waiting"?"Waiting":e==="done"?"Done":e==="blocked"?"Needs you":e==="failed"?"Failed":e==="skipped"?"Skipped":"Queued"}function QY({output:e,previousOutput:t,status:s,step:n}){if(n.kind==="gate"){const l=n.id==="gate-commit"?t?.trim():"";return r.jsxs("div",{children:[r.jsx("p",{className:"text-muted-foreground",children:n.message}),l?r.jsxs("div",{className:"mt-3",children:[r.jsx(wr,{children:"Generated commit message"}),r.jsx("div",{className:"whitespace-pre-wrap break-words rounded-md border border-border bg-muted/50 px-2.5 py-2 font-mono text-[11px] text-foreground",children:l})]}):null]})}if(n.kind==="action")return r.jsx("p",{className:"text-muted-foreground",children:cj(n.op)});const o=s==="done"||s==="failed"||s==="skipped";return e?r.jsxs("div",{children:[r.jsx(wr,{children:"Result"}),r.jsx("div",{className:"whitespace-pre-wrap break-words rounded-md bg-muted/50 px-2.5 py-2 font-mono text-[11px] text-foreground",children:e})]}):r.jsxs("div",{children:[r.jsx(wr,{children:o?"Result":"Task"}),o?r.jsx("p",{className:"italic text-muted-foreground",children:"No text reply — see the dock for what the agent did."}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-muted-foreground",children:n.prompt}),s==="running"?r.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-muted-foreground/80",children:[r.jsx(Et,{className:"size-3 animate-spin"})," Working in the dock…"]}):null]})]})}function JY(e){return e.detected.name==="codex"?e.agents.codex:e.agents["claude-code"]??e}function eX(e){return e?{skills:Lc(e.skills.map(t=>t.name)),mcpServers:Lc(e.mcpServers.map(t=>t.name)),plugins:Lc(e.plugins.map(t=>t.name)),hooks:Lc(e.hooks.map(t=>t.matcher?`${t.event}: ${t.matcher}`:t.event))}:{skills:[],mcpServers:[],plugins:[],hooks:[]}}function tX(e){return{id:qx("custom-workflow",e),name:"Custom workflow",description:"A user-built workflow.",builtin:!1,steps:[{kind:"gate",id:"gate-start",title:"Approve start",message:"Run this workflow?"}]}}function sX(e){const t=il(e.id)||e.kind,s=e.title.trim()||Jh(e);if(e.kind==="gate")return{...e,id:t,title:s,message:e.message.trim()||"Continue?"};if(e.kind==="action")return{...e,id:t,title:s};const n=uj(e.capabilities);return{...e,id:t,title:s,prompt:e.prompt.trim()||"Complete this workflow step.",capabilities:n}}function cj(e){return e==="assert-pr-branch"?"Checks that PR workflows are running from a feature branch, not main or master.":e==="checkout-default-and-pull"?"Switches back to the default branch and pulls the latest changes.":e==="push"?"Pushes the current branch to its remote.":"Commits the staged changes with the approved generated message."}function uj(e){if(!e)return;const t={};for(const s of["skills","mcpServers","plugins","hooks"]){const n=Lc((e[s]??[]).map(o=>o.trim()).filter(Boolean));n.length&&(t[s]=n)}return Object.keys(t).length?t:void 0}function nX(e,t,s){const n=e?.[t]??[],o=n.includes(s)?n.filter(l=>l!==s):[...n,s];return uj({...e??{},[t]:o})}function qx(e,t){const s=new Set(t.map(l=>l.id));let n=il(e)||"workflow",o=2;for(;s.has(n);)n=`${il(e)||"workflow"}-${o}`,o++;return n}function il(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Lc(e){return Array.from(new Set(e.filter(Boolean)))}function wr({children:e}){return r.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:e})}function dj(e){return new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(new Date(e))}function hj({outcome:e}){const t={running:{label:"Running",className:"border-primary/40 text-primary"},done:{label:"Done",className:"border-emerald-500/40 text-emerald-600 dark:text-emerald-400"},stopped:{label:"Stopped",className:"border-border text-muted-foreground"},failed:{label:"Failed",className:"border-destructive/40 text-destructive"},blocked:{label:"Needs you",className:"border-amber-500/40 text-amber-700 dark:text-amber-400"}},{label:s,className:n}=t[e];return r.jsx("span",{className:de("rounded-full border px-2 py-0.5 text-[10px] font-medium",n),children:s})}function fj({kind:e}){return e==="gate"?r.jsx(BN,{className:"size-4 text-amber-600 dark:text-amber-400"}):e==="agent"?r.jsx(Ci,{className:"size-4 text-primary"}):r.jsx(Nr,{className:"size-4 text-muted-foreground"})}function sN({status:e,kind:t}){return e==="running"?r.jsx(Et,{className:"size-4 shrink-0 animate-spin text-primary"}):e==="waiting"?r.jsx(BN,{className:"size-4 shrink-0 text-primary"}):e==="done"?r.jsx(on,{className:"size-4 shrink-0 text-emerald-600 dark:text-emerald-400"}):e==="blocked"?r.jsx(Db,{className:"size-4 shrink-0 text-amber-600 dark:text-amber-400"}):e==="failed"?r.jsx(ul,{className:"size-4 shrink-0 text-destructive"}):e==="skipped"?r.jsx(IN,{className:"size-4 shrink-0 text-muted-foreground/60"}):t==="agent"?r.jsx(Ci,{className:"size-4 shrink-0 text-muted-foreground/50"}):r.jsx(h4,{className:"size-4 shrink-0 text-muted-foreground/50"})}function iX(e){return r.jsx(Xn,{className:"size-3 shrink-0 text-muted-foreground/40","aria-hidden":!0})}function Rb({kind:e}){const t=e==="agent"?"AI":e==="gate"?"Gate":"Auto",s=e==="agent"?"border-primary/30 text-primary":e==="gate"?"border-amber-500/40 text-amber-600 dark:text-amber-400":"border-border text-muted-foreground";return r.jsx("span",{className:de("shrink-0 rounded-full border px-1.5 py-px text-[9px] uppercase tracking-wide",s),children:t})}function Jh(e){return e.title}function rX({data:e,onRefresh:t}){const{insertPath:s}=It(),[n,o]=y.useState(!1),[l,u]=y.useState("changes"),[h,m]=y.useState("changes"),[d,p]=y.useState(e.git.status?.files[0]?.path??""),[g,x]=y.useState(""),[v,S]=y.useState([]),[k,N]=y.useState(null),[E,A]=y.useState(""),[j,T]=y.useState(null),[P,z]=y.useState(0),[I,M]=y.useState(null),[L,B]=y.useState(()=>new Set),G=e.git.status?.files??[],Z=y.useMemo(()=>{const ke=new Set(G.map($e=>$e.path)),He=[...L].filter($e=>!ke.has($e)).sort().map($e=>({path:$e,index:" ",workingTree:"M"}));return[...G,...He]},[G,L]),$=y.useMemo(()=>Z.map(ke=>ke.path),[Z]),q=y.useMemo(()=>bx(E),[E]),F=y.useCallback(async(ke,He)=>{if(He.length){o(!0);try{await ke(He),t?.()}finally{o(!1)}}},[t]),D=t?{busy:n,onStage:ke=>{F($b,ke)},onUnstage:ke=>{F(ZN,ke)}}:void 0;y.useEffect(()=>{const ke=Z[0]?.path??"";p(He=>He&&Z.some($e=>$e.path===He)?He:ke)},[Z]),y.useEffect(()=>{if(l!=="all"||v.length>0)return;let ke=!0;return N(null),c8().then(He=>{ke&&S(He)}).catch(He=>{ke&&N(He instanceof Error?He.message:String(He))}),()=>{ke=!1}},[l,v.length]),y.useEffect(()=>{if(!d){A("");return}let ke=!0;return T(null),XN(d).then(He=>{ke&&(A(He),z(0),M(null))}).catch(He=>{ke&&T(He instanceof Error?He.message:String(He))}),()=>{ke=!1}},[d]);function X(ke){z(0),M(null),p(ke)}function U(){const ke=eY({activeHunkIndex:P,filePaths:$,hunkCount:q.hunks,pendingNextFilePath:I,selectedFile:d});ke.kind==="hunk"?(M(null),z(ke.activeHunkIndex)):ke.kind==="confirm-next-file"?M(ke.filePath):ke.kind==="file"?X(ke.filePath):M(null)}function K(){if(M(null),P>0){z($e=>$e-1);return}const ke=Z.findIndex($e=>$e.path===d),He=Z[ke-1];He&&X(He.path)}const Y=Z.findIndex(ke=>ke.path===d),V=!!(q.hunks&&P<q.hunks-1||Z[Y+1]),ie=!!(P>0||Z[Y-1]),Ee=I?`End of file. Click Next again to open ${I}.`:null,ye=ke=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${ke?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,oe=ke=>`flex-1 px-2 py-0.5 text-[11px] font-medium transition-colors ${ke?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,je=y.useMemo(()=>{const ke=new Set(Z.map(He=>He.path));for(const He of L)ke.add(He);return ke},[Z,L]);if(!e.git.selectedRepository)return r.jsx(aX,{});function Ne(){g&&(u("changes"),m("changes"),X(g))}function Ge(ke){B(He=>new Set(He).add(ke)),x(ke),u("changes"),m("changes"),X(ke)}function Me(ke){x(ke),u("all")}function Qe(ke){ke&&s(cu(e.git.cwd,ke))}return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[r.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[r.jsx("button",{type:"button",className:ye(l==="changes"),onClick:()=>u("changes"),children:"Changes"}),r.jsx("button",{type:"button","aria-label":"Show changed files across all repositories",className:ye(l==="board"),onClick:()=>u("board"),children:"Board"}),r.jsx("button",{type:"button","aria-label":"Open all tracked files",className:ye(l==="all"),onClick:()=>u("all"),children:"All files"}),r.jsx("button",{type:"button",className:ye(l==="graph"),onClick:()=>u("graph"),children:"Tree"}),r.jsx("button",{type:"button",className:ye(l==="largest"),onClick:()=>u("largest"),children:"Largest files"}),r.jsx("button",{type:"button",className:ye(l==="snapshots"),onClick:()=>u("snapshots"),children:"Snapshots"}),r.jsx("button",{type:"button",className:ye(l==="workflows"),onClick:()=>u("workflows"),children:r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Gt,{className:"size-3"}),"Workflows"]})})]}),r.jsx("div",{className:"min-h-0 flex-1",children:l==="workflows"?r.jsx(PY,{}):l==="board"?r.jsx(wY,{currentRepoPath:e.git.cwd}):l==="graph"?r.jsx(mY,{branches:e.git.branches??[]}):l==="largest"?r.jsx(MY,{onOpenFile:Me,root:e.git.cwd}):l==="snapshots"?r.jsx(PI,{}):l==="all"?r.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 xl:grid-cols-[320px_minmax(0,1fr)]",children:[r.jsx("aside",{className:"flex min-h-0 flex-col overflow-hidden",children:k?r.jsx(tt,{variant:"destructive",className:"m-3",children:k}):r.jsx(ak,{branch:e.git.status?.branch||void 0,onSelectFile:x,paths:v,root:e.git.cwd,selectedFile:g,status:Z})}),r.jsx(JK,{isModified:je.has(g),onFileSaved:Ge,onSendToAi:()=>Qe(g),onViewDiff:Ne,path:g})]}):r.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 xl:grid-cols-[320px_minmax(0,1fr)]",children:[r.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex shrink-0 gap-0.5 border-b border-border bg-card/95 p-1",children:[r.jsx("button",{"aria-label":"Show changed files as a list",className:oe(h==="changes"),onClick:()=>m("changes"),type:"button",children:"Changes"}),r.jsx("button",{"aria-label":"Show changed files as a tree",className:oe(h==="tree"),onClick:()=>m("tree"),type:"button",children:"Tree"})]}),h==="changes"?r.jsx(M5,{branch:e.git.status?.branch||void 0,error:e.git.error,files:Z,selectedFile:d,onSelectFile:X,root:e.git.cwd,staging:D}):r.jsx(ak,{branch:e.git.status?.branch||void 0,defaultExpandAll:!0,emptyMessage:e.git.error??"No changed files.",onSelectFile:X,paths:$,root:e.git.cwd,selectedFile:d,status:Z,title:"Changes"}),t&&e.git.status?r.jsx(D5,{branch:e.git.status.branch||void 0,files:Z,onDone:t}):null]}),r.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col border-l border-border bg-card",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:d||"Diff"}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[r.jsx("span",{children:"Long rows wrap inside the editor pane."}),q.additions||q.deletions?r.jsxs("span",{className:"flex items-center gap-1 font-mono",children:[r.jsxs("span",{className:"text-emerald-700",children:["+",q.additions]}),r.jsxs("span",{className:"text-red-700",children:["-",q.deletions]})]}):null]})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[Ee?r.jsx("span",{className:"max-w-72 truncate rounded border border-amber-200 bg-amber-50 px-2 py-1 text-[11px] text-amber-900",children:Ee}):null,r.jsxs(J,{disabled:!d||!ie,onClick:K,size:"sm",type:"button",variant:"outline",children:[r.jsx(sf,{}),"Previous"]}),r.jsxs(J,{disabled:!d||!V,onClick:U,size:"sm",type:"button",variant:"outline",children:[r.jsx(tf,{}),"Next"]}),r.jsx(J,{"aria-label":"Send selected file to AI input",className:"size-8",disabled:!d,onClick:()=>Qe(d),size:"icon",title:"Send selected file path to AI input",type:"button",variant:"outline",children:r.jsx(Gt,{className:"size-4"})})]})]}),r.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:j?r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"destructive",children:j})}):d?r.jsx(lu,{activeHunkIndex:P,diff:E||"No unstaged diff for this file."}):r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"muted",className:"border-dashed p-12 text-center",children:"Select a changed file to inspect its diff."})})})]})]})})]})}function aX(){return r.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:r.jsxs("div",{className:"max-w-sm",children:[r.jsx(Bb,{className:"mx-auto size-8 text-muted-foreground/50"}),r.jsx("p",{className:"mt-3 text-sm font-medium",children:"No Git project registered"}),r.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Add a folder that is a Git worktree to review changes, browse files, and inspect history. Use the project picker in the header to add one."})]})})}const oX={sm:"size-3.5",md:"size-4",lg:"size-6"};function Vx({size:e="md",className:t}){return r.jsx(Et,{"aria-hidden":!0,className:de("animate-spin",oX[e],t)})}function wf({label:e,size:t="md",fill:s=!1,className:n}){return r.jsxs("div",{className:de("flex items-center justify-center gap-2 text-[12px] text-muted-foreground",s&&"h-full",n),role:"status",children:[r.jsx(Vx,{size:t}),e?r.jsx("span",{children:e}):null]})}function lX(){const[e,t]=y.useState(!1),[s,n]=y.useState(!1),[o,l]=y.useState(!0),[u,h]=y.useState("checking"),[m,d]=y.useState(null),[p,g]=y.useState(null);function x(){l(!0),h("checking"),d(null),S8().then(v=>{t(v.configured),n(v.deviceFlowAvailable),h(v.status),d(v.error??null),g(v)}).catch(v=>{t(!1),n(!1),h("connection_error"),d(v instanceof Error?v.message:String(v)),g(null)}).finally(()=>l(!1))}return y.useEffect(()=>{x()},[]),{configured:e,deviceFlowAvailable:s,loading:o,status:u,error:m,info:p,isConnected:u==="connected",needsLogin:u==="not_configured"||u==="auth_error",refresh:x}}const l0=30;function cX(e="open"){const[t,s]=y.useState([]),[n,o]=y.useState(!0),[l,u]=y.useState(!1),[h,m]=y.useState(!1),[d,p]=y.useState(1),[g,x]=y.useState(null),[v,S]=y.useState(null),[k,N]=y.useState(null),[E,A]=y.useState(""),[j,T]=y.useState(!1),[P,z]=y.useState(null);y.useEffect(()=>{let L=!0;return o(!0),x(null),p(1),Bp(e,1).then(B=>{L&&(s(B),m(B.length===l0),B.length>0&&!B.some(G=>G.number===v)&&S(B[0]?.number??null))}).catch(B=>{L&&x(B instanceof Error?B.message:String(B))}).finally(()=>{L&&o(!1)}),()=>{L=!1}},[e]),y.useEffect(()=>{if(!v){N(null);return}let L=!0;return j8(v).then(B=>{L&&N(B)}).catch(()=>{}),()=>{L=!1}},[v]),y.useEffect(()=>{if(!v){A("");return}let L=!0;return T(!0),z(null),T8(v).then(B=>{L&&A(B)}).catch(B=>{L&&z(B instanceof Error?B.message:String(B))}).finally(()=>{L&&T(!1)}),()=>{L=!1}},[v]);function I(){if(l||!h)return;const L=d+1;u(!0),Bp(e,L).then(B=>{s(G=>{const Z=new Set(G.map($=>$.number));return[...G,...B.filter($=>!Z.has($.number))]}),m(B.length===l0),p(L)}).catch(B=>x(B instanceof Error?B.message:String(B))).finally(()=>u(!1))}function M(){let L=!0;return o(!0),x(null),p(1),Bp(e,1).then(B=>{L&&(s(B),m(B.length===l0))}).catch(B=>{L&&x(B instanceof Error?B.message:String(B))}).finally(()=>{L&&o(!1)}),()=>{L=!1}}return{prs:t,loading:n,loadingMore:l,hasMore:h,error:g,selectedNumber:v,setSelectedNumber:S,selectedPR:k,diff:E,diffLoading:j,diffError:P,loadMore:I,refresh:M}}const c0=30;function uX(e="open"){const[t,s]=y.useState([]),[n,o]=y.useState(!0),[l,u]=y.useState(!1),[h,m]=y.useState(!1),[d,p]=y.useState(1),[g,x]=y.useState(null),[v,S]=y.useState(null),[k,N]=y.useState(null),[E,A]=y.useState([]),[j,T]=y.useState(!1),[P,z]=y.useState(null),[I,M]=y.useState(!1);y.useEffect(()=>{let Z=!0;return o(!0),x(null),p(1),Ip(e,1).then($=>{Z&&(s($),m($.length===c0),$.length>0&&!$.some(q=>q.number===v)&&S($[0]?.number??null))}).catch($=>{Z&&x($ instanceof Error?$.message:String($))}).finally(()=>{Z&&o(!1)}),()=>{Z=!1}},[e]),y.useEffect(()=>{if(!v){N(null),A([]);return}let Z=!0;return T(!0),Promise.all([O8(v),L8(v)]).then(([$,q])=>{Z&&(N($),A(q))}).catch(()=>{}).finally(()=>{Z&&T(!1)}),()=>{Z=!1}},[v]);async function L(Z){if(v){M(!0),z(null);try{const $=await z8(v,Z);A(q=>[...q,$])}catch($){z($ instanceof Error?$.message:String($))}finally{M(!1)}}}function B(){if(l||!h)return;const Z=d+1;u(!0),Ip(e,Z).then($=>{s(q=>{const F=new Set(q.map(D=>D.number));return[...q,...$.filter(D=>!F.has(D.number))]}),m($.length===c0),p(Z)}).catch($=>x($ instanceof Error?$.message:String($))).finally(()=>u(!1))}function G(){let Z=!0;return o(!0),p(1),Ip(e,1).then($=>{Z&&(s($),m($.length===c0))}).catch(()=>{}).finally(()=>{Z&&o(!1)}),()=>{Z=!1}}return{issues:t,loading:n,loadingMore:l,hasMore:h,error:g,selectedNumber:v,setSelectedNumber:S,selectedIssue:k,comments:E,commentsLoading:j,commentError:P,submitting:I,addComment:L,loadMore:B,refresh:G}}function Gx({className:e}){return r.jsx("svg",{className:de("size-3.5",e),viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:r.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})})}function mj({deviceFlowAvailable:e,initialMode:t,onSaved:s}){const[n,o]=y.useState(()=>t==="device-pending"&&!e?"pat":t??(e?"choose":"pat"));return n==="device-pending"?r.jsx(dX,{onSuccess:s,onCancel:()=>o("choose")}):n==="pat"?r.jsx(hX,{onSaved:s,onBack:e?()=>o("choose"):void 0}):r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:r.jsx(Ly,{className:"size-6 text-muted-foreground"})}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold",children:"Connect GitHub"}),r.jsx("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:"Authorize NoMoreIDE to read pull requests, issues, and CI status for your repositories."})]})]}),r.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2",children:[r.jsxs(J,{className:"w-full",onClick:()=>o("device-pending"),type:"button",children:[r.jsx(Ly,{className:"mr-2 size-4"}),"Authorize with GitHub"]}),r.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:()=>o("pat"),type:"button",children:"Use a Personal Access Token instead"})]})]})}function dX({onSuccess:e,onCancel:t}){const[s,n]=y.useState(null),[o,l]=y.useState(null),[u,h]=y.useState(!0),[m,d]=y.useState(!1),p=y.useRef(null),g=y.useRef(5),x=y.useRef(!1);y.useEffect(()=>{let N=!0;return w8().then(E=>{if(!N)return;n(E),g.current=E.interval,h(!1);const A=E.verification_uri_complete||E.verification_uri;A&&lf(A),v(E.device_code,E.interval),setTimeout(()=>{x.current=!0},E.expires_in*1e3)}).catch(E=>{N&&(l(E instanceof Error?E.message:String(E)),h(!1))}),()=>{N=!1,p.current&&clearTimeout(p.current)}},[]);function v(N,E){p.current=setTimeout(()=>{S(N,E)},E*1e3)}async function S(N,E){if(x.current){l("Authorization expired. Please try again.");return}try{const A=await k8(N);if(A.done){e();return}const j=A.slowDown?E+5:E;g.current=j,v(N,j)}catch{v(N,g.current)}}function k(){s&&navigator.clipboard.writeText(s.user_code).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})}return u?r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx(zy,{className:"size-6 animate-spin text-muted-foreground"}),r.jsx("p",{className:"text-[13px] text-muted-foreground",children:"Requesting authorization…"})]})}):o?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8",children:[r.jsx(tt,{variant:"destructive",children:o}),r.jsx(J,{onClick:t,variant:"outline",children:"Go back"})]}):r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-emerald-100 dark:bg-emerald-500/15",children:r.jsx(rf,{className:"size-6 text-emerald-600 dark:text-emerald-400"})}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold",children:"Authorize on GitHub"}),r.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:["A GitHub page just opened in a new tab. Enter the code below and click"," ",r.jsx("strong",{children:"Authorize"}),"."]})]})]}),r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("div",{className:"flex cursor-pointer select-all items-center gap-3 rounded-xl border-2 border-border bg-muted px-6 py-4 font-mono text-2xl font-bold tracking-[0.3em] transition-colors hover:border-ring",onClick:k,title:"Click to copy",children:s?.user_code}),r.jsx("button",{className:"text-[11px] text-muted-foreground transition-colors hover:text-foreground",onClick:k,type:"button",children:m?"Copied!":"Click code to copy"})]}),r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[r.jsx(zy,{className:"size-3.5 animate-spin"}),"Waiting for authorization…"]}),r.jsx("a",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",href:s?.verification_uri_complete||s?.verification_uri,rel:"noopener noreferrer",target:"_blank",children:"Open GitHub again"}),r.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:t,type:"button",children:"Cancel"})]})]})}function hX({onSaved:e,onBack:t}){const[s,n]=y.useState(""),[o,l]=y.useState(!1),[u,h]=y.useState(null);async function m(d){d.preventDefault();const p=s.trim();if(p){l(!0),h(null);try{await N8("github.com",p),e()}catch(g){h(g instanceof Error?g.message:String(g))}finally{l(!1)}}}return r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:r.jsx(CN,{className:"size-6 text-muted-foreground"})}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold",children:"Personal Access Token"}),r.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:["Create a token at"," ",r.jsx("a",{className:"underline underline-offset-2 hover:text-foreground",href:"https://github.com/settings/tokens/new?scopes=repo,workflow",rel:"noopener noreferrer",target:"_blank",children:"github.com/settings/tokens"})," ","with ",r.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"repo"})," and"," ",r.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"workflow"})," scopes."]})]})]}),r.jsxs("form",{className:"flex w-full max-w-sm flex-col gap-3",onSubmit:d=>{m(d)},children:[r.jsx("input",{autoComplete:"off",className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-[13px] placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring",onChange:d=>n(d.target.value),placeholder:"ghp_...",spellCheck:!1,type:"password",value:s}),u?r.jsx(tt,{variant:"destructive",children:u}):null,r.jsx(J,{disabled:!s.trim()||o,type:"submit",children:o?"Saving…":"Save token"}),t?r.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:t,type:"button",children:"← Back"}):null]})]})}function Wx({hasMore:e,loading:t,onLoadMore:s}){return e?r.jsx("div",{className:"p-2",children:r.jsxs("button",{className:"flex w-full items-center justify-center gap-1.5 rounded-md border border-border py-1.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground disabled:opacity-60",disabled:t,onClick:s,type:"button",children:[t?r.jsx(Et,{className:"size-3 animate-spin"}):null,t?"Loading…":"Load more"]})}):null}function fX({prs:e,loading:t,loadingMore:s,hasMore:n,error:o,selectedNumber:l,onSelect:u,onLoadMore:h}){return t&&e.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading pull requests…"}):o?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:o}):e.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No pull requests found."}):r.jsxs(r.Fragment,{children:[r.jsx("ul",{className:"divide-y divide-border",children:e.map(m=>r.jsx("li",{children:r.jsxs("button",{className:`flex w-full items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-muted/60 ${l===m.number?"bg-muted":""}`,onClick:()=>u(m.number),type:"button",children:[r.jsx("span",{className:"mt-0.5 shrink-0",children:r.jsx(mX,{pr:m})}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate text-[13px] font-medium",children:m.title}),r.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",m.number," · ",m.base.ref," ← ",m.head.ref," · ",m.user.login]})]}),m.draft?r.jsx("span",{className:"shrink-0 rounded border border-border px-1.5 py-px text-[10px] text-muted-foreground",children:"Draft"}):null]})},m.number))}),r.jsx(Wx,{hasMore:n,loading:s,onLoadMore:h})]})}function mX({pr:e}){return e.state==="merged"?r.jsx(Nh,{className:"size-4 text-purple-500"}):e.state==="closed"?r.jsx(iR,{className:"size-4 text-red-500"}):r.jsx(NN,{className:"size-4 text-emerald-500"})}function pj({body:e,title:t="Description"}){const[s,n]=y.useState("rendered"),o=l=>de("rounded px-1.5 py-0.5 text-[10px] font-medium transition-colors",l?"bg-foreground text-background":"text-muted-foreground hover:text-foreground");return r.jsxs("section",{className:"overflow-hidden rounded-md border border-border bg-muted/25",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[r.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:t}),r.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-background/60 p-0.5",children:[r.jsx("button",{className:o(s==="rendered"),onClick:()=>n("rendered"),type:"button",children:"Rendered"}),r.jsx("button",{className:o(s==="raw"),onClick:()=>n("raw"),type:"button",children:"Raw"})]})]}),s==="rendered"?r.jsx(L5,{content:e}):r.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap px-3 py-3 font-mono text-[12px]",children:e})]})}function pX({title:e,message:t,confirmLabel:s="Confirm",cancelLabel:n="Cancel",tone:o="default",icon:l,loading:u=!1,onConfirm:h,onCancel:m}){y.useEffect(()=>{function p(g){g.key==="Escape"&&!u&&m()}return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[m,u]);const d=o==="danger"?"destructive":o==="success"?"success":"default";return _a.createPortal(r.jsx("div",{className:"fixed inset-0 z-[1000] grid place-items-center bg-black/35 px-4",onMouseDown:()=>!u&&m(),children:r.jsxs("div",{"aria-modal":"true",className:"flex w-full max-w-md flex-col overflow-hidden rounded-lg border border-border bg-card shadow-xl",onMouseDown:p=>p.stopPropagation(),role:"dialog",children:[r.jsxs("div",{className:"flex items-start gap-3 px-4 py-4",children:[l?r.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border bg-background text-foreground [&_svg]:size-4",children:l}):null,r.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[r.jsx("h2",{className:"text-sm font-semibold",children:e}),r.jsx("div",{className:"text-[13px] text-muted-foreground",children:t})]})]}),r.jsxs("div",{className:"flex justify-end gap-2 border-t border-border bg-muted/30 px-4 py-3",children:[r.jsx(J,{disabled:u,onClick:m,size:"sm",type:"button",variant:"outline",children:n}),r.jsx(J,{disabled:u,onClick:h,size:"sm",type:"button",variant:d,children:s})]})]})}),document.body)}function gX({pr:e,diff:t,diffLoading:s,diffError:n,onMerged:o}){const[l,u]=y.useState("cockpit"),[h,m]=y.useState(null),[d,p]=y.useState(!1),[g,x]=y.useState(null),[v,S]=y.useState(!1),[k,N]=y.useState(null),[E,A]=y.useState(!1),[j,T]=y.useState(null),[P,z]=y.useState(!1),{sendToAgent:I}=It(),M=y.useMemo(()=>OI(t),[t]);y.useEffect(()=>{T(F=>F&&M.some(D=>D.path===F)?F:M[0]?.path??null)},[M]);const L=M.find(F=>F.path===j)??M[0]??null;function B(F){T(F),u("diff")}function G(F,D){e&&(z(!1),I({prompt:D?EP(e,D,F):CP(e,F),source:{type:"github-pr",label:`PR #${e.number}${D?` · ${ef(D)}`:""}`},label:`PR #${e.number}${D?` (${ef(D)})`:""}: ${F}`}))}if(y.useEffect(()=>{if(z(!1),!e){m(null);return}let F=!0;return p(!0),x(null),A8(e.number).then(D=>{F&&m(D)}).catch(D=>{F&&x(D instanceof Error?D.message:String(D))}).finally(()=>{F&&p(!1)}),()=>{F=!1}},[e]),!e)return r.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:"Select a pull request"});const Z=e.state==="open"&&!e.draft;async function $(){if(!(!e||v)){S(!0),N(null);try{await D8(e.number,{method:"squash"}),A(!1),o?.()}catch(F){N(F instanceof Error?F.message:String(F)),A(!1)}finally{S(!1)}}}const q=F=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${F?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`;return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),r.jsx(Ki,{className:de("shrink-0",P&&"opacity-100"),label:`Ask AI about PR #${e.number}`,onAsk:()=>z(F=>!F)}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[r.jsx("button",{className:q(l==="cockpit"),onClick:()=>u("cockpit"),type:"button",children:"Review"}),r.jsx("button",{className:q(l==="diff"),onClick:()=>u("diff"),type:"button",children:"Diff"})]}),Z?r.jsxs(J,{className:"shrink-0",disabled:v,onClick:()=>A(!0),size:"sm",title:"Squash & merge this pull request",type:"button",variant:"success",children:[r.jsx(Nh,{}),"Squash & merge"]}):null,r.jsx("a",{"aria-label":"Open on GitHub",className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",title:"Open on GitHub",children:r.jsx(kr,{className:"size-3.5"})})]}),k?r.jsx("div",{className:"shrink-0 border-b border-border bg-red-500/10 px-3 py-1.5 text-[11px] text-red-500",children:k}):null,P?r.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:r.jsx(jr,{placeholder:"What should the agent do with this PR? (review, summarize, find regressions…)",onSubmit:F=>G(F),onCancel:()=>z(!1)})}):null,l==="cockpit"?r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:r.jsx(bX,{cockpit:h,error:g,loading:d,onOpenFile:B,pr:e})}):s?r.jsx(wf,{className:"flex-1",label:"Loading diff…"}):n?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:n}):M.length?r.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1",children:[r.jsx(xX,{files:M,onAsk:(F,D)=>G(D,F),onSelect:T,selected:L?.path??null}),r.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:L?r.jsx(lu,{diff:L.diff}):null})]}):r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No diff available."}),E?r.jsx(pX,{confirmLabel:v?r.jsxs(r.Fragment,{children:[r.jsx(Vx,{size:"sm"})," Merging…"]}):"Squash & merge",icon:r.jsx(Nh,{}),loading:v,message:r.jsxs(r.Fragment,{children:["Squash & merge PR ",r.jsxs("span",{className:"font-mono",children:["#",e.number]})," ",r.jsx("span",{className:"font-medium text-foreground",children:e.title})," into"," ",r.jsx("span",{className:"font-mono",children:e.base.ref}),"?"]}),onCancel:()=>A(!1),onConfirm:()=>{$()},title:"Squash & merge",tone:"success"}):null]})}function bX({pr:e,cockpit:t,loading:s,error:n,onOpenFile:o}){const[l,u]=y.useState(!1),h=t?.pr??e,m=t?.files??[],d=t?.reviews??[],p=t?.comments??[],g=t?.checks??null,x=g?.runs.filter(v=>v.conclusion==="failure"||v.conclusion==="timed_out"||v.conclusion==="cancelled")??[];return r.jsxs("div",{className:"space-y-3 p-4",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-[12px]",children:[r.jsx(yX,{pr:h}),r.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border bg-muted/40 px-2 py-1 font-mono text-[11px]",children:[r.jsx(xn,{className:"size-3 shrink-0 text-muted-foreground"}),h.base.ref,r.jsx(eu,{className:"size-3 shrink-0 text-muted-foreground"}),h.head.ref]}),r.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[r.jsx(BM,{className:"size-3 shrink-0"}),h.user.login]}),r.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[r.jsx(e4,{className:"size-3 shrink-0"}),new Date(h.created_at).toLocaleDateString()]})]}),n?r.jsx("div",{className:"rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[12px] text-red-500",children:n}):null,s?r.jsx(wf,{className:"justify-start",label:"Loading review cockpit…"}):null,r.jsxs("div",{className:"grid gap-2 md:grid-cols-4",children:[r.jsx(ih,{title:"Merge readiness",value:gj(h,g),tone:vX(h,g)}),r.jsx(ih,{title:"Review state",value:bj(d),tone:_X(d)}),r.jsx(ih,{title:"Checks",value:g?`${g.state} (${g.totalCount})`:"unknown",tone:g?.state==="success"?"success":g?.state==="failure"||g?.state==="error"?"danger":"muted"}),r.jsx(ih,{title:"Changed files",value:String(m.length),tone:"muted"})]}),x.length>0?r.jsxs("section",{className:"rounded-md border border-red-500/25 bg-red-500/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 text-[11px] font-medium text-red-500",children:"Failing checks"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:x.slice(0,4).map(v=>r.jsxs("a",{className:"inline-flex items-center gap-1 text-[11px] text-red-500 underline-offset-2 hover:underline",href:v.html_url,rel:"noopener noreferrer",target:"_blank",children:[r.jsx(Ob,{className:"size-3"}),"Open failing check: ",v.name]},v.id))})]}):null,r.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[r.jsxs("button",{className:"flex w-full items-center gap-2 text-[12px] font-medium",onClick:()=>u(v=>!v),type:"button",children:[l?r.jsx(vn,{className:"size-3.5 text-muted-foreground"}):r.jsx(Xn,{className:"size-3.5 text-muted-foreground"}),r.jsx(zb,{className:"size-3.5 text-muted-foreground"}),"Changed files",m.length?r.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["(",m.length,")"]}):null]}),l?m.length?r.jsx("ul",{className:"mt-2 divide-y divide-border",children:m.slice(0,12).map(v=>r.jsx("li",{children:r.jsxs("button",{className:"flex w-full items-center gap-2 py-1.5 text-left text-[12px] transition-colors hover:text-foreground",onClick:()=>o(v.path),title:`View diff for ${v.path}`,type:"button",children:[r.jsx("span",{className:"w-16 shrink-0 font-mono text-[10px] uppercase text-muted-foreground",children:v.status}),r.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:v.path}),r.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-emerald-600",children:["+",v.additions]}),r.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-red-500",children:["-",v.deletions]})]})},v.path))}):r.jsx("p",{className:"mt-2 text-[12px] text-muted-foreground",children:"No changed file metadata available."}):null]}),r.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[r.jsxs("div",{className:"mb-2 flex items-center gap-2 text-[12px] font-medium",children:[r.jsx(zR,{className:"size-3.5 text-muted-foreground"}),"Review state"]}),d.length||p.length?r.jsxs("div",{className:"space-y-2",children:[d.slice(-4).map(v=>r.jsx(nN,{href:v.html_url,meta:`${v.user.login} - ${v.state.toLowerCase()}`,text:v.body||"No review summary."},`review:${v.id}`)),p.slice(-4).map(v=>r.jsx(nN,{href:v.html_url,meta:`${v.user.login} - comment`,text:v.body},`comment:${v.id}`))]}):r.jsx("p",{className:"text-[12px] text-muted-foreground",children:"No reviews or PR comments yet."})]}),h.body?r.jsx(pj,{body:h.body}):r.jsx("p",{className:"text-[12px] italic text-muted-foreground",children:"No description provided."})]})}function xX({files:e,selected:t,onSelect:s,onAsk:n}){const[o,l]=y.useState(null);return r.jsx("div",{className:"w-44 shrink-0 overflow-y-auto border-r border-border bg-card/60",children:r.jsx("ul",{className:"py-1",children:e.map(u=>r.jsxs("li",{className:"group flex flex-col",children:[r.jsxs("div",{className:de("flex items-center transition-colors",u.path===t?"bg-muted":"hover:bg-muted/60"),children:[r.jsxs("button",{className:de("flex min-w-0 flex-1 items-center gap-1.5 px-2.5 py-1.5 text-left text-[11px]",u.path===t?"text-foreground":"text-muted-foreground group-hover:text-foreground"),onClick:()=>s(u.path),title:u.path,type:"button",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:ef(u.path)}),r.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-emerald-600",children:["+",u.additions]}),r.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-red-500",children:["-",u.deletions]})]}),r.jsx(Ki,{className:de("mr-1 shrink-0",o===u.path&&"opacity-100"),label:`Ask AI about ${ef(u.path)}`,onAsk:()=>l(h=>h===u.path?null:u.path)})]}),o===u.path?r.jsx("div",{className:"px-2 pb-1.5 pt-0.5",children:r.jsx(jr,{placeholder:"What about this file? (review, explain, find bugs…)",onSubmit:h=>{l(null),n(u.path,h)},onCancel:()=>l(null)})}):null]},u.path))})})}function ef(e){const t=e.split("/");return t[t.length-1]||e}function ih({title:e,value:t,tone:s}){const n=s==="success"?"bg-emerald-500":s==="warning"?"bg-amber-500":s==="danger"?"bg-red-500":"bg-muted-foreground";return r.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[r.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:e}),r.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[12px] font-medium",children:[r.jsx("span",{className:`size-1.5 rounded-full ${n}`}),t]})]})}function nN({meta:e,text:t,href:s}){return r.jsxs("a",{className:"block rounded border border-border bg-card px-2.5 py-2 text-[12px] transition-colors hover:bg-muted/60",href:s,rel:"noopener noreferrer",target:"_blank",children:[r.jsxs("span",{className:"mb-1 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[r.jsx(kr,{className:"size-3"}),e]}),r.jsx("span",{className:"line-clamp-2 whitespace-pre-wrap",children:t})]})}function gj(e,t){return e.state!=="open"?e.state:e.draft?"draft":e.mergeable===!1?"blocked":t?.state==="failure"||t?.state==="error"?"checks failing":t?.state==="pending"?"checks pending":e.mergeable===!0?"ready":"unknown"}function vX(e,t){const s=gj(e,t);return s==="ready"?"success":s==="blocked"||s==="checks failing"?"danger":s==="draft"||s==="checks pending"?"warning":"muted"}function bj(e){return e.some(t=>t.state==="CHANGES_REQUESTED")?"changes requested":e.some(t=>t.state==="APPROVED")?"approved":e.some(t=>t.state==="COMMENTED")?"commented":"no reviews"}function _X(e){const t=bj(e);return t==="approved"?"success":t==="changes requested"?"danger":t==="commented"?"warning":"muted"}function yX({pr:e}){const{label:t,dot:s}=e.state==="merged"?{label:"Merged",dot:"bg-violet-500"}:e.state==="closed"?{label:"Closed",dot:"bg-red-500"}:e.draft?{label:"Draft",dot:"bg-muted-foreground"}:{label:"Open",dot:"bg-emerald-500"};return r.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[r.jsx("span",{className:`size-1.5 rounded-full ${s}`}),t==="Merged"?r.jsx(Nh,{className:"size-3"}):t==="Open"?r.jsx(rf,{className:"size-3"}):r.jsx(qc,{className:"size-3"}),t]})}function xj({label:e}){return r.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",title:e.name,children:[r.jsx("span",{className:"size-2 shrink-0 rounded-sm",style:{backgroundColor:`#${e.color}`}}),r.jsx("span",{className:"truncate",children:e.name})]})}function SX({issues:e,loading:t,loadingMore:s,hasMore:n,error:o,selectedNumber:l,onSelect:u,onLoadMore:h}){return t&&e.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading issues…"}):o?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:o}):e.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No issues found."}):r.jsxs(r.Fragment,{children:[r.jsx("ul",{className:"divide-y divide-border",children:e.map(m=>r.jsx("li",{children:r.jsxs("button",{className:`flex w-full items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-muted/60 ${l===m.number?"bg-muted":""}`,onClick:()=>u(m.number),type:"button",children:[r.jsx(m4,{className:`mt-0.5 size-4 shrink-0 ${m.state==="open"?"text-emerald-500":"text-red-500"}`}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate text-[13px] font-medium",children:m.title}),r.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",m.number," · ",m.user.login," · ",m.comments," comment",m.comments!==1?"s":""]})]}),m.labels.length>0?r.jsx("span",{className:"flex max-w-40 shrink-0 flex-wrap justify-end gap-x-2 gap-y-0.5",children:m.labels.slice(0,3).map(d=>r.jsx(xj,{label:d},d.name))}):null]})},m.number))}),r.jsx(Wx,{hasMore:n,loading:s,onLoadMore:h})]})}const rh=6,wX=6,kX=8;function NX(e,t,s,n){const o=Math.max(0,Math.min(wX,e/2,t/2)),l=Math.max(0,Math.min(kX,s-o,n-o));return[`M ${o} 0`,`H ${e-o}`,`A ${o} ${o} 0 0 1 ${e} ${o}`,`V ${t-n-o}`,`A ${o} ${o} 0 0 1 ${e-o} ${t-n}`,`H ${e-s+l}`,`A ${l} ${l} 0 0 0 ${e-s} ${t-n+l}`,`V ${t-o}`,`A ${o} ${o} 0 0 1 ${e-s-o} ${t}`,`H ${o}`,`A ${o} ${o} 0 0 1 0 ${t-o}`,`V ${o}`,`A ${o} ${o} 0 0 1 ${o} 0`,"Z"].join(" ")}function CX({value:e,onChange:t,placeholder:s,rows:n=3,action:o}){const l=y.useRef(null),u=y.useRef(null),[h,m]=y.useState(null),[d,p]=y.useState({w:0,h:0});y.useLayoutEffect(()=>{const x=l.current,v=u.current;if(!x||!v)return;const S=()=>{m({w:x.clientWidth,h:x.clientHeight}),p({w:v.offsetWidth+rh*2,h:v.offsetHeight+rh*2})};S();const k=new ResizeObserver(S);return k.observe(x),k.observe(v),()=>k.disconnect()},[]);const g=h&&d.w&&d.h?NX(h.w,h.h,d.w,d.h):null;return r.jsxs("div",{className:"relative",ref:l,children:[r.jsx("textarea",{className:"peer block w-full resize-none bg-background px-3 pt-2 font-mono text-[12px] placeholder:text-muted-foreground focus:outline-none",onChange:x=>t(x.target.value),placeholder:s,rows:n,style:{clipPath:g?`path('${g}')`:void 0,paddingBottom:d.h||44},value:e}),h&&g?r.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 overflow-visible text-border transition-colors peer-focus:text-foreground/40",fill:"none",height:h.h,viewBox:`0 0 ${h.w} ${h.h}`,width:h.w,children:[r.jsx("title",{children:"Comment field border"}),r.jsx("path",{d:g,stroke:"currentColor",strokeWidth:1})]}):null,r.jsx("div",{className:"absolute",ref:u,style:{bottom:rh,right:rh},children:o})]})}function EX({issue:e,comments:t,commentsLoading:s,commentError:n,submitting:o,onAddComment:l}){const[u,h]=y.useState(""),[m,d]=y.useState(!1),{sendToAgent:p}=It();y.useEffect(()=>{d(!1)},[e?.number]);function g(v){e&&(d(!1),p({prompt:jP(e,v),source:{type:"github-issue",label:`Issue #${e.number}`},label:`Issue #${e.number}: ${v}`}))}if(!e)return r.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:"Select an issue"});async function x(v){v.preventDefault();const S=u.trim();S&&(await l(S),h(""))}return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),r.jsx(Ki,{className:de("shrink-0",m&&"opacity-100"),label:`Ask AI about issue #${e.number}`,onAsk:()=>d(v=>!v)}),r.jsx("a",{"aria-label":"Open on GitHub",className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",children:r.jsx(kr,{className:"size-3.5"})})]}),m?r.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:r.jsx(jr,{placeholder:"What should the agent do with this issue? (summarize, draft a fix plan, reproduce…)",onSubmit:g,onCancel:()=>d(!1)})}):null,r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:r.jsxs("div",{className:"space-y-3 p-4",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[12px]",children:[r.jsxs("span",{className:"text-[11px]",children:[r.jsx("span",{className:"text-muted-foreground",children:"Author: "}),r.jsx("span",{className:"font-medium",children:e.user.login})]}),r.jsxs("span",{className:"text-[11px]",children:[r.jsx("span",{className:"text-muted-foreground",children:"Opened: "}),r.jsx("span",{className:"font-medium",children:new Date(e.created_at).toLocaleDateString()})]}),e.labels.map(v=>r.jsx(xj,{label:v},v.name))]}),e.body?r.jsx(pj,{body:e.body}):r.jsx("p",{className:"text-[12px] text-muted-foreground italic",children:"No description provided."}),s?r.jsx(wf,{className:"justify-start",label:"Loading comments…"}):r.jsx("div",{className:"space-y-2",children:t.map(v=>r.jsxs("div",{className:"rounded-md border border-border bg-muted/20 p-3",children:[r.jsxs("div",{className:"mb-1 flex items-baseline gap-2",children:[r.jsx("span",{className:"text-[11px] font-semibold",children:v.user.login}),r.jsx("span",{className:"text-[10px] text-muted-foreground",children:new Date(v.created_at).toLocaleDateString()})]}),r.jsx(R3,{content:v.body})]},v.id))})]})}),r.jsx("div",{className:"shrink-0 border-t border-border p-3",children:r.jsxs("form",{className:"flex flex-col gap-2",onSubmit:v=>{x(v)},children:[r.jsx(CX,{action:r.jsx(J,{disabled:!u.trim()||o,size:"sm",type:"submit",children:o?r.jsxs(r.Fragment,{children:[r.jsx(Vx,{size:"sm"})," Posting…"]}):"Comment"}),onChange:h,placeholder:"Add a comment…",value:u}),n?r.jsx(tt,{variant:"destructive",children:n}):null]})})]})}const iN=30,jX=4e3;function TX(e){return e.status==="in_progress"||e.status==="queued"}function rN(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}`).join("|")}function aN(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}:`+t.steps.map(s=>`${s.number}:${s.status}:${s.conclusion}`).join(",")).join("|")}function AX(e,t){if(e.length===0)return t;const s=new Map(t.map(u=>[u.id,u])),n=new Set(e.map(u=>u.id)),o=t.filter(u=>!n.has(u.id)),l=e.map(u=>s.get(u.id)??u);return[...o,...l]}function RX(e){const[t,s]=y.useState([]),[n,o]=y.useState(null),[l,u]=y.useState([]),[h,m]=y.useState(!0),[d,p]=y.useState(!1),[g,x]=y.useState(!1),[v,S]=y.useState(1),[k,N]=y.useState(!1),[E,A]=y.useState(null),[j,T]=y.useState(null);function P(){let L=!0;return m(!0),A(null),S(1),ah(e,1).then(B=>{L&&(s(B),x(B.length===iN))}).catch(B=>{L&&A(B instanceof Error?B.message:String(B))}).finally(()=>{L&&m(!1)}),()=>{L=!1}}function z(){if(d||!g)return;const L=v+1;p(!0),ah(e,L).then(B=>{s(G=>{const Z=new Set(G.map($=>$.id));return[...G,...B.filter($=>!Z.has($.id))]}),x(B.length===iN),S(L)}).catch(B=>A(B instanceof Error?B.message:String(B))).finally(()=>p(!1))}const I=y.useCallback(()=>{ah(e,1).then(L=>s(B=>{const G=AX(B,L);return rN(B)===rN(G)?B:G})).catch(()=>{}),n&&Ky(n).then(L=>u(B=>aN(B)===aN(L)?B:L)).catch(()=>{})},[e,n]);y.useEffect(P,[e]),y.useEffect(()=>{o(L=>L&&t.some(B=>B.id===L)?L:t[0]?.id??null)},[t]),y.useEffect(()=>{if(!n){u([]);return}let L=!0;return N(!0),T(null),Ky(n).then(B=>{L&&u(B)}).catch(B=>{L&&T(B instanceof Error?B.message:String(B))}).finally(()=>{L&&N(!1)}),()=>{L=!1}},[n]);const M=t.some(TX);return y.useEffect(()=>{if(!M)return;const L=window.setInterval(()=>{document.visibilityState==="visible"&&I()},jX);return()=>window.clearInterval(L)},[M,I]),{runs:t,selectedRunId:n,jobs:l,loading:h,loadingMore:d,hasMore:g,jobsLoading:k,error:E,jobsError:j,loadMore:z,refresh:P,syncLatest:I,setSelectedRunId:o}}function vj(e){return e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"}function MX({branch:e,onClearBranch:t}){const{runs:s,selectedRunId:n,jobs:o,loading:l,loadingMore:u,hasMore:h,jobsLoading:m,error:d,jobsError:p,loadMore:g,refresh:x,syncLatest:v,setSelectedRunId:S}=RX(e);du(v);const k=s.find(T=>T.id===n)??null,{sendToAgent:N}=It(),[E,A]=y.useState(null);function j(T,P){A(null),N({prompt:TP(T,P),source:{type:"github-run",label:`Run #${T.run_number}`},label:`Run #${T.run_number}: ${P??"fix failing run"}`})}return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"text-[13px] font-semibold",children:"Workflow Runs"}),e?r.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[r.jsx("span",{className:"shrink-0",children:"Filtered to"}),r.jsx("span",{className:"min-w-0 truncate font-mono",children:e}),t?r.jsx("button",{"aria-label":"Clear branch filter",className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:t,title:"Clear branch filter",type:"button",children:r.jsx(ts,{className:"size-3"})}):null]}):null]}),r.jsxs(J,{disabled:l,onClick:()=>{x()},size:"sm",type:"button",variant:"outline",children:[r.jsx(Cr,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),"Refresh"]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:d?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:d}):l&&s.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading workflow runs…"}):s.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No workflow runs found."}):r.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(280px,380px)_minmax(0,1fr)] divide-x divide-border",children:[r.jsxs("div",{className:"min-h-0 overflow-auto",children:[r.jsx("ul",{className:"divide-y divide-border",children:s.map(T=>r.jsxs("li",{className:"group flex flex-col",children:[r.jsxs("div",{className:`flex items-center transition-colors hover:bg-muted/60 ${T.id===n?"bg-muted/70":""}`,children:[r.jsxs("button",{className:"flex min-w-0 flex-1 items-center gap-3 px-3 py-2.5 text-left",onClick:()=>S(T.id),type:"button",children:[r.jsx(DX,{run:T}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate text-[13px] font-medium",children:T.name}),r.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",T.run_number," · ",T.head_branch," · ",T.event," ·"," ",r.jsx("span",{title:new Date(T.created_at).toLocaleString(),children:TL(T.created_at)})]})]}),r.jsx(OX,{run:T})]}),vj(T)?r.jsx(Ki,{className:`mr-2 shrink-0 ${E===T.id?"opacity-100":""}`,label:`Fix failing run #${T.run_number} with AI`,onAsk:()=>A(P=>P===T.id?null:T.id)}):null]}),E===T.id?r.jsx("div",{className:"px-3 pb-2 pt-0.5",children:r.jsx(jr,{onCancel:()=>A(null),onSubmit:P=>j(T,P),placeholder:"What should the agent do? (fix it, explain the failure, find the broken step…)"})}):null]},T.id))}),r.jsx(Wx,{hasMore:h,loading:u,onLoadMore:g})]}),r.jsx(LX,{error:p,jobs:o,loading:m,onFix:T=>j(T),run:k})]})})]})}function DX({run:e}){return e.status==="in_progress"||e.status==="queued"?r.jsx(qc,{className:"size-4 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"?r.jsx(rf,{className:"size-4 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"?r.jsx(Ob,{className:"size-4 shrink-0 text-red-500"}):r.jsx(qc,{className:"size-4 shrink-0 text-zinc-400"})}function OX({run:e}){const t=e.status==="completed"?e.conclusion??"completed":e.status,s=t==="success"?"bg-emerald-500":t==="failure"||t==="timed_out"?"bg-red-500":t==="in_progress"||t==="queued"?"bg-amber-500":"bg-muted-foreground";return r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[r.jsx("span",{className:`size-1.5 rounded-full ${s}`}),t]})}function LX({run:e,jobs:t,loading:s,error:n,onFix:o}){return e?r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate text-[13px] font-semibold",children:e.name}),r.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["Run #",e.run_number," · ",e.head_branch," · ",e.head_sha.slice(0,7)]})]}),vj(e)?r.jsxs(J,{className:"shrink-0 gap-1",onClick:()=>o(e),size:"sm",title:"Send this failing run to the agent to investigate and fix",type:"button",variant:"outline",children:[r.jsx(Gt,{className:"size-3.5"}),"Fix with AI"]}):null,r.jsx("a",{"aria-label":"Open run on GitHub",className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",title:"Open run on GitHub",children:r.jsx(kr,{className:"size-3.5"})})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:n}):s?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading jobs…"}):t.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No jobs found for this run."}):r.jsx("ul",{className:"divide-y divide-border",children:t.map(l=>r.jsxs("li",{className:"px-3 py-3",children:[r.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[r.jsx(oN,{item:l}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium",children:l.name}),r.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:lN(l.started_at,l.completed_at)}),r.jsx("a",{"aria-label":`Open ${l.name} job on GitHub`,className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:l.html_url,rel:"noopener noreferrer",target:"_blank",title:"Open job on GitHub",children:r.jsx(kr,{className:"size-3.5"})})]}),l.steps.length?r.jsx("ol",{className:"space-y-1.5 pl-6",children:l.steps.map(u=>r.jsxs("li",{className:"flex items-center gap-2 text-[12px]",children:[r.jsx(oN,{item:u}),r.jsx("span",{className:"min-w-0 flex-1 truncate",children:u.name}),r.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:lN(u.started_at,u.completed_at)})]},`${l.id}:${u.number}`))}):r.jsx("p",{className:"pl-6 text-[12px] text-muted-foreground",children:"No step details available."})]},l.id))})})]}):r.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:"Select a workflow run"})}function oN({item:e}){return e.status==="in_progress"||e.status==="queued"?r.jsx(qc,{className:"size-3.5 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"||e.conclusion==="skipped"?r.jsx(rf,{className:"size-3.5 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"?r.jsx(Ob,{className:"size-3.5 shrink-0 text-red-500"}):r.jsx(qc,{className:"size-3.5 shrink-0 text-zinc-400"})}function lN(e,t){if(!e)return"-";const s=Date.parse(e),n=t?Date.parse(t):Date.now();if(!Number.isFinite(s)||!Number.isFinite(n)||n<s)return"-";const o=Math.max(0,Math.round((n-s)/1e3));if(o<60)return`${o}s`;const l=Math.floor(o/60),u=o%60;return u?`${l}m ${u}s`:`${l}m`}function zX({onCreatePR:e,onViewRuns:t}){const[s,n]=y.useState(null),[o,l]=y.useState(!0),[u,h]=y.useState(null);function m(){let p=!0;return l(!0),h(null),E8().then(g=>{p&&n(g)}).catch(g=>{p&&h(g instanceof Error?g.message:String(g))}).finally(()=>{p&&l(!1)}),()=>{p=!1}}y.useEffect(m,[]),du(()=>{m()});const d=y.useMemo(()=>[...s?.branches??[]].sort((g,x)=>{const v=uN(g,s),S=uN(x,s);return v-S||g.name.localeCompare(x.name)}),[s]);return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"text-[13px] font-semibold",children:"Branches"}),r.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:s?.repository.full_name??"Selected repository"})]}),r.jsxs(J,{disabled:o,onClick:()=>{m()},size:"sm",type:"button",variant:"outline",children:[r.jsx(Cr,{className:`mr-1 size-3.5 ${o?"animate-spin":""}`}),"Refresh"]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:u?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:u}):o&&!s?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading branches..."}):d.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No branches found."}):r.jsx("ul",{className:"divide-y divide-border",children:d.map(p=>r.jsx(BX,{branch:p,currentBranch:s?.currentBranch??null,defaultBranch:s?.defaultBranch??null,onCreatePR:e,onViewRuns:t},p.name))})})]})}function BX({branch:e,defaultBranch:t,currentBranch:s,onCreatePR:n,onViewRuns:o}){const l=e.name===t,u=e.name===s,h=!l;return r.jsxs("li",{className:"flex flex-wrap items-center gap-3 px-3 py-2.5",children:[r.jsx(xn,{className:"size-4 shrink-0 text-muted-foreground"}),r.jsxs("div",{className:"min-w-48 flex-1",children:[r.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[r.jsx("span",{className:"truncate font-mono text-[13px] font-medium",children:e.name}),l?r.jsx(cN,{label:"Default",tone:"success"}):null,u?r.jsx(cN,{label:"Current",tone:"warning"}):null,e.protected?r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[r.jsx(SM,{className:"size-3"}),"protected"]}):null]}),r.jsx("div",{className:"mt-0.5 font-mono text-[11px] text-muted-foreground",children:e.commit.sha.slice(0,7)})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[r.jsxs(J,{onClick:()=>o(e.name),size:"sm",title:`View workflow runs for ${e.name}`,type:"button",variant:"outline",children:[r.jsx(g4,{className:"size-3.5"}),"View runs"]}),r.jsxs(J,{disabled:!h,onClick:()=>n(e.name),size:"sm",title:h?`Open PR from ${e.name}`:"Default branch does not need a PR",type:"button",variant:"outline",children:[r.jsx(NN,{className:"size-3.5"}),"Open PR"]})]})]})}function cN({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":"bg-amber-500";return r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[r.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function uN(e,t){return e.name===t?.currentBranch?0:e.name===t?.defaultBranch?1:e.protected?2:3}function IX(){const e=lX();let t;return e.loading||e.status==="checking"?t=r.jsx(wf,{fill:!0,label:"Loading…"}):e.status==="not_configured"?t=r.jsx(mj,{deviceFlowAvailable:e.deviceFlowAvailable,onSaved:e.refresh}):e.status==="auth_error"||e.status==="connection_error"?t=r.jsx(PX,{token:e}):t=r.jsx($X,{token:e}),r.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:t})}function PX({token:e}){const[t,s]=y.useState(null);if(t)return r.jsx(mj,{deviceFlowAvailable:e.deviceFlowAvailable,initialMode:t,onSaved:e.refresh});const n=e.status==="auth_error";return r.jsx("div",{className:"flex h-full items-center justify-center p-8",children:r.jsxs("div",{className:"w-full max-w-lg space-y-4 rounded-md border border-border bg-card p-5",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Gx,{className:"size-5"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("h2",{className:"text-sm font-semibold",children:"GitHub connection failed"}),r.jsx("p",{className:"text-[12px] text-muted-foreground",children:n?"The saved GitHub token is no longer accepted.":"NoMoreIDE could not validate the GitHub connection."})]}),r.jsx(_j,{label:n?"Needs re-login":"Connection problem",tone:n?"danger":"warning"})]}),e.error?r.jsx(tt,{variant:"destructive",children:e.error}):null,r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsxs(J,{onClick:e.refresh,type:"button",variant:n?"outline":"default",children:[r.jsx(Cr,{}),"Refresh"]}),r.jsx(J,{onClick:()=>s(e.deviceFlowAvailable?"device-pending":"pat"),type:"button",variant:n?"default":"outline",children:"Reconnect GitHub"}),r.jsx(J,{onClick:()=>s("pat"),type:"button",variant:"outline",children:"Use token instead"})]})]})})}function $X({token:e}){const[t,s]=sl("github:tab","prs"),[n,o]=sl("github:pr-state","open"),[l,u]=sl("github:issue-state","open"),[h,m]=y.useState(null),[d,p]=y.useState(null),[g,x]=y.useState(!1),[v,S]=y.useState(null),k=cX(n),N=uX(l);du(()=>{t==="prs"?k.refresh():t==="issues"&&N.refresh()});const E=T=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${T?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,A=T=>`rounded px-2 py-0.5 text-[10px] font-medium transition-colors ${T?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`;async function j(){x(!0),S(null);try{await C8("github.com"),e.refresh()}catch(T){S(T instanceof Error?T.message:String(T))}finally{x(!1)}}return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[r.jsx("button",{className:E(t==="prs"),onClick:()=>s("prs"),type:"button",children:"Pull Requests"}),r.jsx("button",{className:E(t==="issues"),onClick:()=>s("issues"),type:"button",children:"Issues"}),r.jsx("button",{className:E(t==="branches"),onClick:()=>s("branches"),type:"button",children:"Branches"}),r.jsx("button",{className:E(t==="actions"),onClick:()=>s("actions"),type:"button",children:"Actions"}),r.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-2",children:[r.jsx(HX,{token:e}),r.jsxs(J,{onClick:e.refresh,size:"sm",title:"Re-check the GitHub connection",type:"button",variant:"outline",children:[r.jsx(Cr,{}),"Reconnect"]}),r.jsx(J,{disabled:g,onClick:()=>{j()},size:"sm",type:"button",variant:"outline",children:g?"Disconnecting…":"Disconnect"})]}),t==="prs"?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[r.jsx("button",{className:A(n==="open"),onClick:()=>o("open"),type:"button",children:"Open"}),r.jsx("button",{className:A(n==="closed"),onClick:()=>o("closed"),type:"button",children:"Closed"})]}),r.jsx(J,{onClick:()=>m(""),size:"sm",type:"button",variant:"outline",children:"New PR"})]}):t==="issues"?r.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[r.jsx("button",{className:A(l==="open"),onClick:()=>u("open"),type:"button",children:"Open"}),r.jsx("button",{className:A(l==="closed"),onClick:()=>u("closed"),type:"button",children:"Closed"})]}):null]}),v?r.jsx(tt,{variant:"destructive",className:"m-3",children:v}):null,h!==null?r.jsx(UX,{initialHead:h,onCreated:T=>{m(null),s("prs"),k.setSelectedNumber(T.number),k.refresh()},onCancel:()=>m(null)}):r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t==="prs"?r.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[r.jsx("div",{className:"min-h-0 overflow-auto",children:r.jsx(fX,{error:k.error,hasMore:k.hasMore,loading:k.loading,loadingMore:k.loadingMore,onLoadMore:k.loadMore,onSelect:k.setSelectedNumber,prs:k.prs,selectedNumber:k.selectedNumber})}),r.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:r.jsx(gX,{diff:k.diff,diffError:k.diffError,diffLoading:k.diffLoading,onMerged:()=>k.refresh(),pr:k.selectedPR})})]}):t==="issues"?r.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[r.jsx("div",{className:"min-h-0 overflow-auto",children:r.jsx(SX,{error:N.error,hasMore:N.hasMore,issues:N.issues,loading:N.loading,loadingMore:N.loadingMore,onLoadMore:N.loadMore,onSelect:N.setSelectedNumber,selectedNumber:N.selectedNumber})}),r.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:r.jsx(EX,{commentError:N.commentError,comments:N.comments,commentsLoading:N.commentsLoading,issue:N.selectedIssue,onAddComment:N.addComment,submitting:N.submitting})})]}):t==="branches"?r.jsx(zX,{onCreatePR:T=>m(T),onViewRuns:T=>{p(T),s("actions")}}):r.jsx(MX,{branch:d??void 0,onClearBranch:()=>p(null)})})]})}function HX({token:e}){const t=e.info?.repository?.full_name??(e.info?.user?`@${e.info.user.login}`:"GitHub");return r.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 border-r border-border pr-2",children:[r.jsx(Gx,{className:"size-4 shrink-0 text-foreground"}),r.jsx(_j,{label:"Connected",tone:"success"}),r.jsx("span",{className:"max-w-48 truncate font-mono text-[10px] text-muted-foreground",children:t})]})}function _j({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":t==="danger"?"bg-red-500":"bg-amber-500";return r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[r.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function UX({initialHead:e,onCreated:t,onCancel:s}){const[n,o]=y.useState(""),[l,u]=y.useState(""),[h,m]=y.useState(""),[d,p]=y.useState("main"),[g,x]=y.useState(!1),[v,S]=y.useState(null),[k,N]=y.useState(!0),[E,A]=y.useState(!1),[j,T]=y.useState(null);y.useEffect(()=>{let M=!0;return N(!0),T(null),R8().then(L=>{M&&(S(L),o(L.title),u(L.body),m(e||L.head),p(L.base||L.suggestedBase||"main"),x(L.draft))}).catch(L=>{M&&T(L instanceof Error?L.message:String(L))}).finally(()=>{M&&N(!1)}),()=>{M=!1}},[e]);async function P(M){if(M.preventDefault(),!(!n.trim()||!h.trim()||!d.trim())){A(!0),T(null);try{const L=await M8({title:n.trim(),body:l.trim()||void 0,head:h.trim(),base:d.trim(),draft:g});t(L)}catch(L){T(L instanceof Error?L.message:String(L))}finally{A(!1)}}}const z="w-full rounded-md border border-border bg-background px-3 py-2 text-[13px] placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring",I=v?.warnings??[];return r.jsxs("form",{className:"flex min-h-0 flex-col gap-3 overflow-auto bg-muted/20 p-4",onSubmit:M=>{P(M)},children:[r.jsxs("div",{className:"flex items-start justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h3",{className:"text-[13px] font-semibold",children:"Branch to PR Assistant"}),r.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:[v?.repository?.full_name??"Selected repository",v?.currentBranch?` - ${v.currentBranch}`:""]})]}),r.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:k?"Detecting branch...":"Editable draft"})]}),r.jsx(FX,{template:v,loading:k}),I.length>0?r.jsx("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[12px] text-amber-700 dark:text-amber-300",children:I[0]}):null,r.jsx("input",{className:z,disabled:k,onChange:M=>o(M.target.value),placeholder:"Title",required:!0,value:n}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsxs("label",{className:"space-y-1",children:[r.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:"Head"}),r.jsx("input",{className:z,disabled:k,onChange:M=>m(M.target.value),placeholder:"Head branch",required:!0,value:h})]}),r.jsxs("label",{className:"space-y-1",children:[r.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:"Base"}),r.jsx("input",{className:z,disabled:k,onChange:M=>p(M.target.value),placeholder:"Base branch",required:!0,value:d})]})]}),r.jsx("textarea",{className:`${z} resize-none`,disabled:k,onChange:M=>u(M.target.value),placeholder:"Description (optional)",rows:7,value:l}),r.jsxs("label",{className:"flex items-center gap-2 text-[12px]",children:[r.jsx("input",{checked:g,className:"size-3.5",disabled:k,onChange:M=>x(M.target.checked),type:"checkbox"}),"Create as draft"]}),j?r.jsx(tt,{variant:"destructive",children:j}):null,r.jsxs("div",{className:"flex gap-2",children:[r.jsx(J,{disabled:k||E||!n.trim()||!h.trim()||!d.trim(),type:"submit",children:E?"Creating…":"Create PR"}),r.jsx(J,{onClick:s,type:"button",variant:"outline",children:"Cancel"})]})]})}function FX({template:e,loading:t}){const s=e?.compare,n=s?.ciStatus,o=[{label:"base branch",value:s?.base||e?.base||"main"},{label:"head branch",value:s?.head||e?.head||"manual"},{label:"commits ahead",value:t?"...":String(s?.aheadBy??0)},{label:"changed files",value:t?"...":String(s?.files.length??0)},{label:"head CI",value:n?`${n.state} (${n.totalCount})`:"unavailable"}];return r.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[r.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[r.jsx("span",{className:"text-[11px] font-medium text-foreground",children:"Compare summary"}),s?.headSha?r.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:s.headSha.slice(0,7)}):null]}),r.jsx("div",{className:"grid grid-cols-5 gap-2",children:o.map(l=>r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"truncate text-[10px] uppercase text-muted-foreground",children:l.label}),r.jsx("div",{className:"truncate font-mono text-[11px] text-foreground",children:l.value})]},l.label))}),s?.files.length?r.jsx("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted-foreground",children:s.files.slice(0,4).map(l=>r.jsxs("span",{className:"max-w-52 truncate",children:[l.status," ",l.path]},`${l.status}:${l.path}`))}):null]})}function qX({ahead:e=0,behind:t=0,branches:s,currentBranch:n,disabled:o,onRefresh:l,upstream:u}){const[h,m]=y.useState(!1),[d,p]=y.useState(""),[g,x]=y.useState(null),[v,S]=y.useState(null),[k,N]=y.useState(null),E=s.filter(L=>!L.remote),A=s.filter(L=>L.remote);async function j(L,B){x(L),N(null),S(null);try{await B(),await l()}catch(G){N(G instanceof Error?G.message:String(G))}finally{x(null)}}async function T(L){await j(`switch:${L}`,async()=>{await ki("/api/git/branches/switch",{name:L}),m(!1)})}async function P(){await j("fetch",async()=>{await ki("/api/git/fetch",{}),S("Fetched latest branch refs.")})}async function z(){await j("push",async()=>{const L=await cf();S(L.setUpstream?`Pushed ${L.branch} and set upstream.`:`Pushed ${L.branch}.`)})}const I=!!n&&(e>0||!u&&t===0);async function M(L){L.preventDefault();const B=d.trim();if(!B){N("Branch name is required.");return}await j("create",async()=>{await ki("/api/git/branches",{name:B}),p(""),m(!1)})}return r.jsxs("div",{className:"fixed bottom-12 right-4 z-50 flex items-end",children:[h?r.jsxs("div",{"aria-label":"Switch Git branch",className:"mb-11 w-[min(460px,calc(100vw-2rem))] rounded-lg border border-border bg-card shadow-xl",role:"dialog",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border p-3",children:[r.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[r.jsx(xn,{className:"size-4 text-muted-foreground"}),r.jsx("span",{className:"truncate text-sm font-semibold",children:n||"Branches"})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[I?r.jsxs(J,{"aria-label":"Push current branch",className:"gap-1.5 px-2 text-xs",disabled:o||g!==null,onClick:()=>{z()},size:"sm",title:u?`Push ${e} commit${e===1?"":"s"} to ${u}`:"Push and set upstream",type:"button",variant:"default",children:[r.jsx(Ib,{className:de("size-3.5",g==="push"&&"animate-pulse")}),"Push",e>0?` ${e}`:""]}):null,r.jsx(J,{"aria-label":"Fetch branches",disabled:o||g!==null,onClick:()=>{P()},size:"icon",title:"Fetch branches",type:"button",variant:"ghost",children:r.jsx(Cr,{className:de(g==="fetch"&&"animate-spin")})}),r.jsx(J,{"aria-label":"Close branch dialog",onClick:()=>m(!1),size:"icon",type:"button",variant:"ghost",children:r.jsx(ts,{})})]})]}),r.jsx("div",{className:"max-h-72 overflow-auto",children:s.length?r.jsxs(r.Fragment,{children:[r.jsx(dN,{branches:E,busy:g!==null,disabled:o,label:"Local",onSwitch:T}),r.jsx(dN,{branches:A,busy:g!==null,disabled:o,label:"Remote",onSwitch:T})]}):r.jsx("div",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:"No branches found."})}),r.jsxs("div",{className:"border-t border-border p-3",children:[r.jsxs("form",{className:"grid gap-2 sm:grid-cols-[1fr_auto]",onSubmit:M,children:[r.jsx(ht,{"aria-label":"New branch name",disabled:o||g!==null,onChange:L=>{p(L.target.value),N(null),S(null)},placeholder:"feature/new-work",value:d}),r.jsxs(J,{disabled:o||g!==null,type:"submit",children:[r.jsx(aR,{}),"Create"]})]}),k||v?r.jsx(tt,{className:"mt-3 px-3 py-2 text-xs",variant:k?"destructive":"muted",children:k??v}):null]})]}):null,r.jsxs(J,{className:"h-8 max-w-[260px] gap-2 rounded-md shadow-lg",disabled:o,onClick:()=>m(L=>!L),size:"sm",title:"Switch Git branch",type:"button",variant:"default",children:[r.jsx(xn,{className:"size-4"}),r.jsx("span",{className:"truncate font-mono text-xs",children:n||"No branch"}),n&&(e>0||t>0)?r.jsxs("span",{className:"flex items-center gap-1 font-mono text-[11px] tabular-nums",title:u?`${e} ahead / ${t} behind ${u}`:`${e} ahead / ${t} behind`,children:[t>0?r.jsxs("span",{className:"flex items-center",children:[r.jsx(tf,{className:"size-3"}),t]}):null,e>0?r.jsxs("span",{className:"flex items-center",children:[r.jsx(sf,{className:"size-3"}),e]}):null]}):null,r.jsx(vn,{className:de("size-4 transition-transform",h&&"rotate-180")})]})]})}function dN({branches:e,busy:t,disabled:s,label:n,onSwitch:o}){return r.jsxs("section",{children:[r.jsx("div",{className:"border-b border-border bg-muted/60 px-3 py-1.5 text-[11px] font-semibold uppercase text-muted-foreground",children:n}),e.length?e.map(l=>r.jsxs("button",{className:de("grid w-full grid-cols-[1fr_auto] items-center gap-2 border-b border-border px-3 py-2 text-left text-sm last:border-b-0 hover:bg-muted",l.current&&"bg-muted/70"),disabled:s||t||l.current,onClick:()=>{o(l.name)},type:"button",children:[r.jsxs("span",{className:"min-w-0",children:[r.jsx("span",{className:"block truncate font-medium",children:l.name}),l.upstream?r.jsxs("span",{className:"block truncate font-mono text-[11px] text-muted-foreground",children:["tracks ",l.upstream]}):null]}),r.jsx(et,{variant:l.current?"success":l.remote?"outline":"secondary",children:l.current?"current":l.remote?"remote":"local"})]},`${l.remote?"remote":"local"}:${l.name}`)):r.jsxs("div",{className:"border-b border-border px-3 py-3 text-sm text-muted-foreground",children:["No ",n.toLowerCase()," branches."]})]})}const yj="nomoreide-theme-choice";function VX(){if(typeof window>"u")return"dark";const e=window.localStorage.getItem(yj);return e==="light"||e==="dark"?e:"dark"}function GX(e){const t=document.documentElement;t.classList.toggle("dark",e==="dark"),t.style.colorScheme=e}function WX(){const[e,t]=y.useState(()=>VX()),s=y.useRef(null);y.useEffect(()=>{GX(e),window.localStorage.setItem(yj,e)},[e]);const n=y.useCallback(()=>{const o=e==="dark"?"light":"dark",l=s.current,u=document;if(!l||!u.startViewTransition||window.matchMedia("(prefers-reduced-motion: reduce)").matches){t(o);return}const h=l.getBoundingClientRect(),m=h.left+h.width/2,d=h.top+h.height/2,p=Math.hypot(Math.max(m,window.innerWidth-m),Math.max(d,window.innerHeight-d));u.startViewTransition(()=>{t(o)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${m}px ${d}px)`,`circle(${p}px at ${m}px ${d}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},[e]);return r.jsxs("button",{ref:s,type:"button",onClick:n,title:e==="dark"?"Switch to light mode":"Switch to dark mode","aria-label":"Toggle theme",className:Bh(),children:[r.jsx("span",{className:Ih(),children:e==="dark"?r.jsx(AM,{}):r.jsx($R,{})}),r.jsx("span",{className:Ph(),children:"Theme"})]})}function KX(){return ln()?r.jsxs("div",{className:"flex items-center justify-between h-8 bg-background border-b border-border select-none",style:{WebkitAppRegion:"drag"},onMouseDown:()=>JM(),children:[r.jsx("span",{className:"px-3 text-xs font-medium text-muted-foreground",children:"NoMoreIDE"}),r.jsxs("div",{className:"flex items-center",style:{WebkitAppRegion:"no-drag"},children:[r.jsx("button",{type:"button",onClick:XM,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":"Minimize",children:r.jsx(RN,{className:"h-3 w-3"})}),r.jsx("button",{type:"button",onClick:ZM,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":"Maximize",children:r.jsx(so,{className:"h-3 w-3"})}),r.jsx("button",{type:"button",onClick:QM,className:"h-8 w-10 flex items-center justify-center hover:bg-destructive hover:text-destructive-foreground transition-colors","aria-label":"Close",children:r.jsx(ts,{className:"h-3 w-3"})})]})]}):null}function YX(e=!1){return de("group/sidebar hidden h-full shrink-0 overflow-x-hidden overflow-y-auto border-r border-border bg-card/85 py-5 backdrop-blur transition-[width,padding] duration-200 md:flex md:flex-col",e?"w-64 px-4":"w-16 px-2 hover:w-64 hover:px-4")}function XX(e,t=!1){return de("relative grid h-12 grid-cols-[48px_minmax(0,1fr)] items-center justify-start gap-0 overflow-hidden rounded-md px-0 text-[15px] font-medium transition-[background-color,color,width] duration-150",t?"w-full":"w-12 group-hover/sidebar:w-full",e?"bg-primary text-primary-foreground hover:bg-primary/90":"hover:bg-muted")}function ZX(e=!1,t=!1){return de("min-w-0 overflow-hidden text-left text-current transition duration-150 whitespace-pre",e?"translate-x-1 opacity-100":"opacity-0 group-hover/sidebar:translate-x-1 group-hover/sidebar:opacity-100",t?"pr-10":"pr-3")}function QX(e=!1){return de("flex size-12 items-center justify-center text-current transition-transform duration-150 [&_svg]:size-5",e?"translate-x-0":"-translate-x-px group-hover/sidebar:translate-x-0")}function JX({docked:e,onToggleDock:t}){return r.jsxs("div",{className:de("mt-auto flex h-10 min-w-0 items-center overflow-hidden border-t border-border/60 text-[11px] text-muted-foreground transition-[height,opacity,width] duration-150",e?"w-full justify-start opacity-100":"w-12 justify-center group-hover/sidebar:w-full group-hover/sidebar:justify-start group-hover/sidebar:opacity-100"),children:[r.jsxs("span",{className:de("flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-pre transition-[opacity,width] duration-150",e?"flex-1 opacity-100":"w-0 flex-none opacity-0 group-hover/sidebar:w-auto group-hover/sidebar:flex-1 group-hover/sidebar:opacity-100"),children:[r.jsx("span",{children:"Made with"}),r.jsx(dR,{"aria-label":"love",className:"size-3 shrink-0 fill-red-500 text-red-500"}),r.jsx("span",{children:"by Robert Wang"}),r.jsx("a",{"aria-label":"Robert Wang on LinkedIn",className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-[#0A66C2]",href:"https://www.linkedin.com/in/robert-wang-cs/",rel:"noopener noreferrer",target:"_blank",title:"LinkedIn",children:r.jsxs("svg",{className:"size-3 fill-current",role:"img",viewBox:"0 0 24 24",children:[r.jsx("title",{children:"LinkedIn"}),r.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.063 2.063 0 1 1 0-4.126 2.063 2.063 0 0 1 0 4.126zM7.119 20.452H3.554V9h3.565v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.225 0z"})]})})]}),r.jsx("button",{"aria-label":e?"Undock sidebar":"Dock sidebar","aria-pressed":e,className:de("flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground [&_svg]:size-4",e?"ml-auto bg-muted text-foreground":"group-hover/sidebar:ml-auto"),onClick:t,title:e?"Undock sidebar":"Dock sidebar",type:"button",children:e?r.jsx(GR,{}):r.jsx(KR,{})})]})}function eZ({className:e}){return r.jsxs("div",{className:de("min-w-0",e),children:[r.jsxs("div",{className:"flex items-baseline gap-1.5",children:[r.jsx("div",{className:"text-sm font-semibold",children:"NoMoreIDE"}),r.jsxs("div",{className:"font-mono text-[10px] text-muted-foreground",children:["v","0.1.61"]})]}),r.jsx("div",{className:"font-mono text-[11px] text-muted-foreground",children:"127.0.0.1 console"})]})}function tZ({syncLocation:e=!0}={}){const[t,s]=y.useState(()=>e?window.location.pathname.startsWith("/agent")?"agent":window.location.pathname.startsWith("/errors")?"errors":window.location.pathname.startsWith("/database")?"database":window.location.pathname.startsWith("/terminal")?"terminal":window.location.pathname.startsWith("/github")?"github":window.location.pathname.startsWith("/git")?"git":"services":"services"),[n,o]=y.useState(null),[l,u]=y.useState(null),[h,m]=y.useState(null),[d,p]=y.useState(null),[g,x]=y.useState(!0),{error:v,success:S}=$s(),[k,N]=y.useState(()=>window.localStorage.getItem("nomoreide:sidebar-docked")==="true"),E=AU(),A=y.useCallback(async(z={})=>{z.silent||x(!0),p(null);try{o(await Z8()),z.notify&&S("Dashboard refreshed.")}catch(I){const M=I instanceof Error?I.message:String(I);p(M),v(M)}finally{x(!1)}},[v,S]),j=y.useCallback(()=>{A({notify:!0}),E.runActive()},[A,E]);y.useEffect(()=>{A()},[A]),y.useEffect(()=>{function z(){document.visibilityState==="visible"&&(A({silent:!0}),E.runActive())}const I=window.setInterval(z,5e3);return window.addEventListener("focus",z),document.addEventListener("visibilitychange",z),()=>{window.clearInterval(I),window.removeEventListener("focus",z),document.removeEventListener("visibilitychange",z)}},[t,A,E.runActive]),y.useEffect(()=>{if(!e)return;const z=t==="git"?"/git":t==="github"?"/github":t==="agent"?"/agent":t==="errors"?"/errors":t==="database"?"/database":t==="terminal"?"/terminal":"/";window.location.pathname!==z&&window.history.pushState(null,"",z)},[t,e]),y.useEffect(()=>{window.localStorage.setItem("nomoreide:sidebar-docked",String(k))},[k]);const T=y.useMemo(()=>n?Object.values(n.runtime.services).filter(z=>z.state==="running").length:0,[n]),P=n?.git.selectedRepository?.name??n?.git.cwd??"no-git-repository";return r.jsx(GI,{children:r.jsx(RU,{value:E,children:r.jsx(iH,{onRefresh:()=>{A({silent:!0})},children:r.jsxs("div",{className:"flex flex-col h-screen overflow-hidden",children:[r.jsx(KX,{}),r.jsxs("div",{className:"flex-1 overflow-hidden pb-9",children:[r.jsxs("div",{className:"mx-auto flex h-full max-w-[1500px]",children:[r.jsxs("aside",{className:YX(k),children:[r.jsxs("div",{className:de("grid h-12 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden transition-[width] duration-150",k?"w-full":"w-12 group-hover/sidebar:w-full"),children:[r.jsx("div",{className:"flex size-12 items-center justify-center",children:r.jsx("div",{className:"flex size-9 items-center justify-center overflow-hidden rounded-md bg-primary text-primary-foreground",children:r.jsxs("svg",{"aria-label":"NoMoreIDE",className:"size-6",fill:"none",role:"img",viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("path",{d:"M5 17C5 13.69 7.69 11 11 11H25L31 17H53C56.31 17 59 19.69 59 23V53C59 56.31 56.31 59 53 59H11C7.69 59 5 56.31 5 53V17Z",fill:"currentColor"}),r.jsx("path",{d:"M22 31L30 39L22 47",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"4.5"}),r.jsx("path",{d:"M36 47H48",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeWidth:"4.5"})]})})}),r.jsx(eZ,{className:de("min-w-0 translate-x-1 overflow-hidden transition-opacity duration-200",k?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100")})]}),r.jsxs("nav",{className:"mt-5 grid flex-1 content-start gap-1",children:[r.jsx(qa,{active:t==="services",badge:T,docked:k,icon:r.jsx(LN,{}),label:"Services",onClick:()=>s("services")}),r.jsx(qa,{active:t==="git",docked:k,icon:r.jsx(xn,{}),label:"Git Review",onClick:()=>s("git")}),r.jsx(qa,{active:t==="github",docked:k,icon:r.jsx(Gx,{}),label:"GitHub",onClick:()=>s("github")}),r.jsx(qa,{active:t==="errors",docked:k,icon:r.jsx(Ch,{}),label:"Error Inbox",onClick:()=>s("errors")}),r.jsx(qa,{active:t==="database",docked:k,icon:r.jsx(fi,{}),label:"Database",onClick:()=>s("database")}),r.jsx(qa,{active:t==="terminal",docked:k,icon:r.jsx(EM,{}),label:"Terminal",onClick:()=>s("terminal")}),r.jsx(qa,{active:t==="agent",docked:k,icon:r.jsx(KA,{}),label:"Agent",onClick:()=>s("agent")})]}),r.jsx(JX,{docked:k,onToggleDock:()=>N(z=>!z)})]}),r.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col px-0 py-0",children:[r.jsxs("header",{className:de("relative z-40 flex shrink-0 flex-wrap items-center justify-between gap-3 border border-border bg-card/90 px-4 py-3 backdrop-blur","border-x-0 border-t-0 border-b"),children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(XR,{className:"size-4 text-muted-foreground md:hidden"}),r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold tracking-tight",children:t==="git"?"Git Review":t==="github"?"GitHub":t==="agent"?"Agent":t==="errors"?"Error Inbox":t==="database"?"Database":t==="terminal"?"Terminal":"Services"}),r.jsx("p",{className:"font-mono text-xs text-muted-foreground",children:n?.git.selectedRepository?.name??n?.git.cwd??"Local workspace"})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[d?r.jsx(et,{variant:"danger",children:d}):null,n&&(t==="git"||t==="github")?r.jsx(xY,{data:n,onRefresh:A}):null,r.jsxs("div",{"aria-label":"Dashboard quick actions",className:"flex items-center gap-1 rounded-lg border border-border bg-background p-px",role:"toolbar",children:[r.jsxs("button",{"aria-label":"Refresh",className:Bh(),onClick:j,title:"Refresh this page",type:"button",children:[r.jsx("span",{className:Ih(),children:r.jsx(Cr,{className:de(g&&"animate-spin")})}),r.jsx("span",{className:Ph(),children:"Refresh"})]}),r.jsx(WX,{}),r.jsxs("a",{"aria-label":"Open NoMoreIDE documentation",className:Bh(),href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",title:"Open NoMoreIDE documentation",children:[r.jsx("span",{className:Ih(),children:r.jsx(GA,{})}),r.jsx("span",{className:Ph(),children:"Docs"})]}),n?r.jsx(I$,{data:n}):null]})]})]}),n?r.jsx(BW,{data:n,onOpenService:z=>{u(z),s("services"),A({silent:!0})}}):null,g&&!n?r.jsx(tt,{variant:"muted",children:"Loading NoMoreIDE state..."}):null,r.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[n&&t==="services"?r.jsx(OW,{data:n,onRefresh:A,focusService:l,onServiceFocused:()=>u(null)}):null,n&&t==="git"?r.jsx(rX,{data:n,onRefresh:()=>{A({silent:!0})}}):null,t==="github"?r.jsx(IX,{},P):null,t==="agent"?r.jsx(h$,{}):null,t==="errors"?r.jsx(uF,{}):null,t==="database"?r.jsx(iF,{staged:h,onStageConsumed:()=>m(null)}):null,t==="terminal"?r.jsx(FW,{}):null]})]})]}),n&&t==="git"?r.jsx(qX,{ahead:n.git.status?.ahead??0,behind:n.git.status?.behind??0,branches:n.git.branches,currentBranch:n.git.status?.branch||void 0,disabled:!n.git.status,onRefresh:A,upstream:n.git.status?.upstream}):null,r.jsx(yU,{git:n?.git,onGitRefresh:()=>{A({silent:!0})},onOpenAgentPage:t==="agent"?void 0:()=>s("agent"),onOpenService:z=>{u(z),s("services"),A({silent:!0})},onOpenSqlConsole:(z,I)=>{m(M=>({connection:z,sql:I,nonce:(M?.nonce??0)+1})),s("database")}})]})]})})})})}function qa({active:e,badge:t,docked:s,icon:n,label:o,onClick:l}){const u=t!==void 0&&t>0;return r.jsxs(J,{"aria-label":o,title:o,className:XX(e,s),variant:"ghost",onClick:l,type:"button",children:[r.jsx("span",{className:QX(s),children:n}),r.jsx("span",{className:ZX(s,u),children:o}),t!==void 0&&t>0?r.jsx(et,{appearance:t>0?"solid":"outline",className:de("min-w-6 justify-center px-1.5 font-mono shadow-none",e?"border-primary-foreground/40 bg-primary-foreground/15 text-primary-foreground dark:border-primary-foreground/40 dark:bg-primary-foreground/15 dark:text-primary-foreground":t>0?"":"border-border bg-background text-muted-foreground","absolute right-1.5 top-1.5 h-4 min-w-4 rounded-full px-1 text-[10px] leading-none shadow-none group-hover/sidebar:right-2 group-hover/sidebar:top-1/2 group-hover/sidebar:-translate-y-1/2 group-hover/sidebar:text-xs",s&&"right-2 top-1/2 -translate-y-1/2 text-xs"),size:"small",variant:t>0?"success":"outline",children:t}):null]})}fN.createRoot(document.getElementById("root")).render(r.jsx(y.StrictMode,{children:r.jsx(tZ,{})}));export{r as j,y as r};
|
|
222
|
+
`),source:{type:"workflow-branch-recovery",label:s},mode:"send",label:`Recommend PR branch for ${s}`,background:!0}),m(!0)}async function P(){if(A){x(!0),N(null);try{await m8(A),S(A)}catch(z){N(z instanceof Error?z.message:String(z))}finally{x(!1)}}}return r.jsxs("div",{className:"mt-3 rounded-md border border-border bg-muted/35 p-3",children:[r.jsx(wr,{children:"Recover with AI"}),r.jsx("p",{className:"mb-2 text-[11px] text-muted-foreground",children:"Let the agent inspect the change and suggest a feature branch. You approve before anything changes."}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsxs(J,{onClick:()=>T(),size:"sm",type:"button",children:[r.jsx(Gt,{className:"size-3.5"})," Recommend branch with AI"]}),v?r.jsxs(J,{onClick:t,size:"sm",type:"button",variant:"outline",children:[r.jsx(Nr,{className:"size-3.5"})," Run again"]}):null]}),j?r.jsxs("p",{className:"mt-2 flex items-center gap-1 text-[11px] text-muted-foreground",children:[r.jsx(Et,{className:"size-3 animate-spin"})," Choosing a branch name in the background."]}):null,A?r.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[r.jsx(wr,{children:"Recommended branch"}),r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[r.jsx("code",{className:"min-w-0 rounded bg-muted px-2 py-1 font-mono text-[12px] text-foreground",children:A}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsxs(J,{disabled:g||v===A,onClick:()=>{P()},size:"sm",type:"button",children:[g?r.jsx(Et,{className:"size-3.5 animate-spin"}):r.jsx(on,{className:"size-3.5"}),"Create this branch"]}),r.jsxs(J,{disabled:g,onClick:()=>T("Recommend a different concise branch name. Keep the same output contract with `BRANCH_NAME: <branch-name>`."),size:"sm",type:"button",variant:"outline",children:[r.jsx(Gt,{className:"size-3.5"})," Ask for another"]})]})]})]}):E&&!j?r.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background p-2.5",children:[r.jsx("p",{className:"text-[11px] text-muted-foreground",children:"The agent did not return a branch name the workflow could read."}),r.jsxs(J,{className:"mt-2",onClick:()=>T("Return only a concise branch suggestion using this exact line: `BRANCH_NAME: <branch-name>`."),size:"sm",type:"button",variant:"outline",children:[r.jsx(Gt,{className:"size-3.5"})," Ask for another"]})]}):null,v?r.jsxs("p",{className:"mt-2 text-[11px] text-emerald-700 dark:text-emerald-400",children:["Branch created: ",r.jsx("code",{className:"font-mono",children:v}),". Run the workflow again from here."]}):null,k?r.jsx("p",{className:"mt-2 text-[11px] text-destructive",children:k}):null,E?r.jsxs(J,{className:"mt-2",onClick:()=>o(!0),size:"sm",type:"button",variant:"outline",children:[r.jsx(TN,{className:"size-3.5"})," Open agent"]}):null]})}function ZY(e,t){for(let s=e.length-1;s>=t;s--)if(e[s]?.role==="assistant")return e[s].text.trim();return""}function tN(e){return e==="running"?"Running":e==="waiting"?"Waiting":e==="done"?"Done":e==="blocked"?"Needs you":e==="failed"?"Failed":e==="skipped"?"Skipped":"Queued"}function QY({output:e,previousOutput:t,status:s,step:n}){if(n.kind==="gate"){const l=n.id==="gate-commit"?t?.trim():"";return r.jsxs("div",{children:[r.jsx("p",{className:"text-muted-foreground",children:n.message}),l?r.jsxs("div",{className:"mt-3",children:[r.jsx(wr,{children:"Generated commit message"}),r.jsx("div",{className:"whitespace-pre-wrap break-words rounded-md border border-border bg-muted/50 px-2.5 py-2 font-mono text-[11px] text-foreground",children:l})]}):null]})}if(n.kind==="action")return r.jsx("p",{className:"text-muted-foreground",children:cj(n.op)});const o=s==="done"||s==="failed"||s==="skipped";return e?r.jsxs("div",{children:[r.jsx(wr,{children:"Result"}),r.jsx("div",{className:"whitespace-pre-wrap break-words rounded-md bg-muted/50 px-2.5 py-2 font-mono text-[11px] text-foreground",children:e})]}):r.jsxs("div",{children:[r.jsx(wr,{children:o?"Result":"Task"}),o?r.jsx("p",{className:"italic text-muted-foreground",children:"No text reply — see the dock for what the agent did."}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-muted-foreground",children:n.prompt}),s==="running"?r.jsxs("p",{className:"mt-1.5 flex items-center gap-1 text-muted-foreground/80",children:[r.jsx(Et,{className:"size-3 animate-spin"})," Working in the dock…"]}):null]})]})}function JY(e){return e.detected.name==="codex"?e.agents.codex:e.agents["claude-code"]??e}function eX(e){return e?{skills:Lc(e.skills.map(t=>t.name)),mcpServers:Lc(e.mcpServers.map(t=>t.name)),plugins:Lc(e.plugins.map(t=>t.name)),hooks:Lc(e.hooks.map(t=>t.matcher?`${t.event}: ${t.matcher}`:t.event))}:{skills:[],mcpServers:[],plugins:[],hooks:[]}}function tX(e){return{id:qx("custom-workflow",e),name:"Custom workflow",description:"A user-built workflow.",builtin:!1,steps:[{kind:"gate",id:"gate-start",title:"Approve start",message:"Run this workflow?"}]}}function sX(e){const t=il(e.id)||e.kind,s=e.title.trim()||Jh(e);if(e.kind==="gate")return{...e,id:t,title:s,message:e.message.trim()||"Continue?"};if(e.kind==="action")return{...e,id:t,title:s};const n=uj(e.capabilities);return{...e,id:t,title:s,prompt:e.prompt.trim()||"Complete this workflow step.",capabilities:n}}function cj(e){return e==="assert-pr-branch"?"Checks that PR workflows are running from a feature branch, not main or master.":e==="checkout-default-and-pull"?"Switches back to the default branch and pulls the latest changes.":e==="push"?"Pushes the current branch to its remote.":"Commits the staged changes with the approved generated message."}function uj(e){if(!e)return;const t={};for(const s of["skills","mcpServers","plugins","hooks"]){const n=Lc((e[s]??[]).map(o=>o.trim()).filter(Boolean));n.length&&(t[s]=n)}return Object.keys(t).length?t:void 0}function nX(e,t,s){const n=e?.[t]??[],o=n.includes(s)?n.filter(l=>l!==s):[...n,s];return uj({...e??{},[t]:o})}function qx(e,t){const s=new Set(t.map(l=>l.id));let n=il(e)||"workflow",o=2;for(;s.has(n);)n=`${il(e)||"workflow"}-${o}`,o++;return n}function il(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Lc(e){return Array.from(new Set(e.filter(Boolean)))}function wr({children:e}){return r.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70",children:e})}function dj(e){return new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(new Date(e))}function hj({outcome:e}){const t={running:{label:"Running",className:"border-primary/40 text-primary"},done:{label:"Done",className:"border-emerald-500/40 text-emerald-600 dark:text-emerald-400"},stopped:{label:"Stopped",className:"border-border text-muted-foreground"},failed:{label:"Failed",className:"border-destructive/40 text-destructive"},blocked:{label:"Needs you",className:"border-amber-500/40 text-amber-700 dark:text-amber-400"}},{label:s,className:n}=t[e];return r.jsx("span",{className:de("rounded-full border px-2 py-0.5 text-[10px] font-medium",n),children:s})}function fj({kind:e}){return e==="gate"?r.jsx(BN,{className:"size-4 text-amber-600 dark:text-amber-400"}):e==="agent"?r.jsx(Ci,{className:"size-4 text-primary"}):r.jsx(Nr,{className:"size-4 text-muted-foreground"})}function sN({status:e,kind:t}){return e==="running"?r.jsx(Et,{className:"size-4 shrink-0 animate-spin text-primary"}):e==="waiting"?r.jsx(BN,{className:"size-4 shrink-0 text-primary"}):e==="done"?r.jsx(on,{className:"size-4 shrink-0 text-emerald-600 dark:text-emerald-400"}):e==="blocked"?r.jsx(Db,{className:"size-4 shrink-0 text-amber-600 dark:text-amber-400"}):e==="failed"?r.jsx(ul,{className:"size-4 shrink-0 text-destructive"}):e==="skipped"?r.jsx(IN,{className:"size-4 shrink-0 text-muted-foreground/60"}):t==="agent"?r.jsx(Ci,{className:"size-4 shrink-0 text-muted-foreground/50"}):r.jsx(h4,{className:"size-4 shrink-0 text-muted-foreground/50"})}function iX(e){return r.jsx(Xn,{className:"size-3 shrink-0 text-muted-foreground/40","aria-hidden":!0})}function Rb({kind:e}){const t=e==="agent"?"AI":e==="gate"?"Gate":"Auto",s=e==="agent"?"border-primary/30 text-primary":e==="gate"?"border-amber-500/40 text-amber-600 dark:text-amber-400":"border-border text-muted-foreground";return r.jsx("span",{className:de("shrink-0 rounded-full border px-1.5 py-px text-[9px] uppercase tracking-wide",s),children:t})}function Jh(e){return e.title}function rX({data:e,onRefresh:t}){const{insertPath:s}=It(),[n,o]=y.useState(!1),[l,u]=y.useState("changes"),[h,m]=y.useState("changes"),[d,p]=y.useState(e.git.status?.files[0]?.path??""),[g,x]=y.useState(""),[v,S]=y.useState([]),[k,N]=y.useState(null),[E,A]=y.useState(""),[j,T]=y.useState(null),[P,z]=y.useState(0),[I,M]=y.useState(null),[L,B]=y.useState(()=>new Set),G=e.git.status?.files??[],Z=y.useMemo(()=>{const ke=new Set(G.map($e=>$e.path)),He=[...L].filter($e=>!ke.has($e)).sort().map($e=>({path:$e,index:" ",workingTree:"M"}));return[...G,...He]},[G,L]),$=y.useMemo(()=>Z.map(ke=>ke.path),[Z]),q=y.useMemo(()=>bx(E),[E]),F=y.useCallback(async(ke,He)=>{if(He.length){o(!0);try{await ke(He),t?.()}finally{o(!1)}}},[t]),D=t?{busy:n,onStage:ke=>{F($b,ke)},onUnstage:ke=>{F(ZN,ke)}}:void 0;y.useEffect(()=>{const ke=Z[0]?.path??"";p(He=>He&&Z.some($e=>$e.path===He)?He:ke)},[Z]),y.useEffect(()=>{if(l!=="all"||v.length>0)return;let ke=!0;return N(null),c8().then(He=>{ke&&S(He)}).catch(He=>{ke&&N(He instanceof Error?He.message:String(He))}),()=>{ke=!1}},[l,v.length]),y.useEffect(()=>{if(!d){A("");return}let ke=!0;return T(null),XN(d).then(He=>{ke&&(A(He),z(0),M(null))}).catch(He=>{ke&&T(He instanceof Error?He.message:String(He))}),()=>{ke=!1}},[d]);function X(ke){z(0),M(null),p(ke)}function U(){const ke=eY({activeHunkIndex:P,filePaths:$,hunkCount:q.hunks,pendingNextFilePath:I,selectedFile:d});ke.kind==="hunk"?(M(null),z(ke.activeHunkIndex)):ke.kind==="confirm-next-file"?M(ke.filePath):ke.kind==="file"?X(ke.filePath):M(null)}function K(){if(M(null),P>0){z($e=>$e-1);return}const ke=Z.findIndex($e=>$e.path===d),He=Z[ke-1];He&&X(He.path)}const Y=Z.findIndex(ke=>ke.path===d),V=!!(q.hunks&&P<q.hunks-1||Z[Y+1]),ie=!!(P>0||Z[Y-1]),Ee=I?`End of file. Click Next again to open ${I}.`:null,ye=ke=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${ke?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,oe=ke=>`flex-1 px-2 py-0.5 text-[11px] font-medium transition-colors ${ke?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,je=y.useMemo(()=>{const ke=new Set(Z.map(He=>He.path));for(const He of L)ke.add(He);return ke},[Z,L]);if(!e.git.selectedRepository)return r.jsx(aX,{});function Ne(){g&&(u("changes"),m("changes"),X(g))}function Ge(ke){B(He=>new Set(He).add(ke)),x(ke),u("changes"),m("changes"),X(ke)}function Me(ke){x(ke),u("all")}function Qe(ke){ke&&s(cu(e.git.cwd,ke))}return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:[r.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[r.jsx("button",{type:"button",className:ye(l==="changes"),onClick:()=>u("changes"),children:"Changes"}),r.jsx("button",{type:"button","aria-label":"Show changed files across all repositories",className:ye(l==="board"),onClick:()=>u("board"),children:"Board"}),r.jsx("button",{type:"button","aria-label":"Open all tracked files",className:ye(l==="all"),onClick:()=>u("all"),children:"All files"}),r.jsx("button",{type:"button",className:ye(l==="graph"),onClick:()=>u("graph"),children:"Tree"}),r.jsx("button",{type:"button",className:ye(l==="largest"),onClick:()=>u("largest"),children:"Largest files"}),r.jsx("button",{type:"button",className:ye(l==="snapshots"),onClick:()=>u("snapshots"),children:"Snapshots"}),r.jsx("button",{type:"button",className:ye(l==="workflows"),onClick:()=>u("workflows"),children:r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Gt,{className:"size-3"}),"Workflows"]})})]}),r.jsx("div",{className:"min-h-0 flex-1",children:l==="workflows"?r.jsx(PY,{}):l==="board"?r.jsx(wY,{currentRepoPath:e.git.cwd}):l==="graph"?r.jsx(mY,{branches:e.git.branches??[]}):l==="largest"?r.jsx(MY,{onOpenFile:Me,root:e.git.cwd}):l==="snapshots"?r.jsx(PI,{}):l==="all"?r.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 xl:grid-cols-[320px_minmax(0,1fr)]",children:[r.jsx("aside",{className:"flex min-h-0 flex-col overflow-hidden",children:k?r.jsx(tt,{variant:"destructive",className:"m-3",children:k}):r.jsx(ak,{branch:e.git.status?.branch||void 0,onSelectFile:x,paths:v,root:e.git.cwd,selectedFile:g,status:Z})}),r.jsx(JK,{isModified:je.has(g),onFileSaved:Ge,onSendToAi:()=>Qe(g),onViewDiff:Ne,path:g})]}):r.jsxs("div",{className:"grid h-full min-h-0 overflow-hidden border-0 bg-card/85 xl:grid-cols-[320px_minmax(0,1fr)]",children:[r.jsxs("aside",{className:"flex min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex shrink-0 gap-0.5 border-b border-border bg-card/95 p-1",children:[r.jsx("button",{"aria-label":"Show changed files as a list",className:oe(h==="changes"),onClick:()=>m("changes"),type:"button",children:"Changes"}),r.jsx("button",{"aria-label":"Show changed files as a tree",className:oe(h==="tree"),onClick:()=>m("tree"),type:"button",children:"Tree"})]}),h==="changes"?r.jsx(M5,{branch:e.git.status?.branch||void 0,error:e.git.error,files:Z,selectedFile:d,onSelectFile:X,root:e.git.cwd,staging:D}):r.jsx(ak,{branch:e.git.status?.branch||void 0,defaultExpandAll:!0,emptyMessage:e.git.error??"No changed files.",onSelectFile:X,paths:$,root:e.git.cwd,selectedFile:d,status:Z,title:"Changes"}),t&&e.git.status?r.jsx(D5,{branch:e.git.status.branch||void 0,files:Z,onDone:t}):null]}),r.jsxs("section",{className:"flex min-h-0 min-w-0 flex-col border-l border-border bg-card",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-3 py-1.5",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:d||"Diff"}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground",children:[r.jsx("span",{children:"Long rows wrap inside the editor pane."}),q.additions||q.deletions?r.jsxs("span",{className:"flex items-center gap-1 font-mono",children:[r.jsxs("span",{className:"text-emerald-700",children:["+",q.additions]}),r.jsxs("span",{className:"text-red-700",children:["-",q.deletions]})]}):null]})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[Ee?r.jsx("span",{className:"max-w-72 truncate rounded border border-amber-200 bg-amber-50 px-2 py-1 text-[11px] text-amber-900",children:Ee}):null,r.jsxs(J,{disabled:!d||!ie,onClick:K,size:"sm",type:"button",variant:"outline",children:[r.jsx(sf,{}),"Previous"]}),r.jsxs(J,{disabled:!d||!V,onClick:U,size:"sm",type:"button",variant:"outline",children:[r.jsx(tf,{}),"Next"]}),r.jsx(J,{"aria-label":"Send selected file to AI input",className:"size-8",disabled:!d,onClick:()=>Qe(d),size:"icon",title:"Send selected file path to AI input",type:"button",variant:"outline",children:r.jsx(Gt,{className:"size-4"})})]})]}),r.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:j?r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"destructive",children:j})}):d?r.jsx(lu,{activeHunkIndex:P,diff:E||"No unstaged diff for this file."}):r.jsx("div",{className:"p-4",children:r.jsx(tt,{variant:"muted",className:"border-dashed p-12 text-center",children:"Select a changed file to inspect its diff."})})})]})]})})]})}function aX(){return r.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center",children:r.jsxs("div",{className:"max-w-sm",children:[r.jsx(Bb,{className:"mx-auto size-8 text-muted-foreground/50"}),r.jsx("p",{className:"mt-3 text-sm font-medium",children:"No Git project registered"}),r.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Add a folder that is a Git worktree to review changes, browse files, and inspect history. Use the project picker in the header to add one."})]})})}const oX={sm:"size-3.5",md:"size-4",lg:"size-6"};function Vx({size:e="md",className:t}){return r.jsx(Et,{"aria-hidden":!0,className:de("animate-spin",oX[e],t)})}function wf({label:e,size:t="md",fill:s=!1,className:n}){return r.jsxs("div",{className:de("flex items-center justify-center gap-2 text-[12px] text-muted-foreground",s&&"h-full",n),role:"status",children:[r.jsx(Vx,{size:t}),e?r.jsx("span",{children:e}):null]})}function lX(){const[e,t]=y.useState(!1),[s,n]=y.useState(!1),[o,l]=y.useState(!0),[u,h]=y.useState("checking"),[m,d]=y.useState(null),[p,g]=y.useState(null);function x(){l(!0),h("checking"),d(null),S8().then(v=>{t(v.configured),n(v.deviceFlowAvailable),h(v.status),d(v.error??null),g(v)}).catch(v=>{t(!1),n(!1),h("connection_error"),d(v instanceof Error?v.message:String(v)),g(null)}).finally(()=>l(!1))}return y.useEffect(()=>{x()},[]),{configured:e,deviceFlowAvailable:s,loading:o,status:u,error:m,info:p,isConnected:u==="connected",needsLogin:u==="not_configured"||u==="auth_error",refresh:x}}const l0=30;function cX(e="open"){const[t,s]=y.useState([]),[n,o]=y.useState(!0),[l,u]=y.useState(!1),[h,m]=y.useState(!1),[d,p]=y.useState(1),[g,x]=y.useState(null),[v,S]=y.useState(null),[k,N]=y.useState(null),[E,A]=y.useState(""),[j,T]=y.useState(!1),[P,z]=y.useState(null);y.useEffect(()=>{let L=!0;return o(!0),x(null),p(1),Bp(e,1).then(B=>{L&&(s(B),m(B.length===l0),B.length>0&&!B.some(G=>G.number===v)&&S(B[0]?.number??null))}).catch(B=>{L&&x(B instanceof Error?B.message:String(B))}).finally(()=>{L&&o(!1)}),()=>{L=!1}},[e]),y.useEffect(()=>{if(!v){N(null);return}let L=!0;return j8(v).then(B=>{L&&N(B)}).catch(()=>{}),()=>{L=!1}},[v]),y.useEffect(()=>{if(!v){A("");return}let L=!0;return T(!0),z(null),T8(v).then(B=>{L&&A(B)}).catch(B=>{L&&z(B instanceof Error?B.message:String(B))}).finally(()=>{L&&T(!1)}),()=>{L=!1}},[v]);function I(){if(l||!h)return;const L=d+1;u(!0),Bp(e,L).then(B=>{s(G=>{const Z=new Set(G.map($=>$.number));return[...G,...B.filter($=>!Z.has($.number))]}),m(B.length===l0),p(L)}).catch(B=>x(B instanceof Error?B.message:String(B))).finally(()=>u(!1))}function M(){let L=!0;return o(!0),x(null),p(1),Bp(e,1).then(B=>{L&&(s(B),m(B.length===l0))}).catch(B=>{L&&x(B instanceof Error?B.message:String(B))}).finally(()=>{L&&o(!1)}),()=>{L=!1}}return{prs:t,loading:n,loadingMore:l,hasMore:h,error:g,selectedNumber:v,setSelectedNumber:S,selectedPR:k,diff:E,diffLoading:j,diffError:P,loadMore:I,refresh:M}}const c0=30;function uX(e="open"){const[t,s]=y.useState([]),[n,o]=y.useState(!0),[l,u]=y.useState(!1),[h,m]=y.useState(!1),[d,p]=y.useState(1),[g,x]=y.useState(null),[v,S]=y.useState(null),[k,N]=y.useState(null),[E,A]=y.useState([]),[j,T]=y.useState(!1),[P,z]=y.useState(null),[I,M]=y.useState(!1);y.useEffect(()=>{let Z=!0;return o(!0),x(null),p(1),Ip(e,1).then($=>{Z&&(s($),m($.length===c0),$.length>0&&!$.some(q=>q.number===v)&&S($[0]?.number??null))}).catch($=>{Z&&x($ instanceof Error?$.message:String($))}).finally(()=>{Z&&o(!1)}),()=>{Z=!1}},[e]),y.useEffect(()=>{if(!v){N(null),A([]);return}let Z=!0;return T(!0),Promise.all([O8(v),L8(v)]).then(([$,q])=>{Z&&(N($),A(q))}).catch(()=>{}).finally(()=>{Z&&T(!1)}),()=>{Z=!1}},[v]);async function L(Z){if(v){M(!0),z(null);try{const $=await z8(v,Z);A(q=>[...q,$])}catch($){z($ instanceof Error?$.message:String($))}finally{M(!1)}}}function B(){if(l||!h)return;const Z=d+1;u(!0),Ip(e,Z).then($=>{s(q=>{const F=new Set(q.map(D=>D.number));return[...q,...$.filter(D=>!F.has(D.number))]}),m($.length===c0),p(Z)}).catch($=>x($ instanceof Error?$.message:String($))).finally(()=>u(!1))}function G(){let Z=!0;return o(!0),p(1),Ip(e,1).then($=>{Z&&(s($),m($.length===c0))}).catch(()=>{}).finally(()=>{Z&&o(!1)}),()=>{Z=!1}}return{issues:t,loading:n,loadingMore:l,hasMore:h,error:g,selectedNumber:v,setSelectedNumber:S,selectedIssue:k,comments:E,commentsLoading:j,commentError:P,submitting:I,addComment:L,loadMore:B,refresh:G}}function Gx({className:e}){return r.jsx("svg",{className:de("size-3.5",e),viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:r.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})})}function mj({deviceFlowAvailable:e,initialMode:t,onSaved:s}){const[n,o]=y.useState(()=>t==="device-pending"&&!e?"pat":t??(e?"choose":"pat"));return n==="device-pending"?r.jsx(dX,{onSuccess:s,onCancel:()=>o("choose")}):n==="pat"?r.jsx(hX,{onSaved:s,onBack:e?()=>o("choose"):void 0}):r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:r.jsx(Ly,{className:"size-6 text-muted-foreground"})}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold",children:"Connect GitHub"}),r.jsx("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:"Authorize NoMoreIDE to read pull requests, issues, and CI status for your repositories."})]})]}),r.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2",children:[r.jsxs(J,{className:"w-full",onClick:()=>o("device-pending"),type:"button",children:[r.jsx(Ly,{className:"mr-2 size-4"}),"Authorize with GitHub"]}),r.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:()=>o("pat"),type:"button",children:"Use a Personal Access Token instead"})]})]})}function dX({onSuccess:e,onCancel:t}){const[s,n]=y.useState(null),[o,l]=y.useState(null),[u,h]=y.useState(!0),[m,d]=y.useState(!1),p=y.useRef(null),g=y.useRef(5),x=y.useRef(!1);y.useEffect(()=>{let N=!0;return w8().then(E=>{if(!N)return;n(E),g.current=E.interval,h(!1);const A=E.verification_uri_complete||E.verification_uri;A&&lf(A),v(E.device_code,E.interval),setTimeout(()=>{x.current=!0},E.expires_in*1e3)}).catch(E=>{N&&(l(E instanceof Error?E.message:String(E)),h(!1))}),()=>{N=!1,p.current&&clearTimeout(p.current)}},[]);function v(N,E){p.current=setTimeout(()=>{S(N,E)},E*1e3)}async function S(N,E){if(x.current){l("Authorization expired. Please try again.");return}try{const A=await k8(N);if(A.done){e();return}const j=A.slowDown?E+5:E;g.current=j,v(N,j)}catch{v(N,g.current)}}function k(){s&&navigator.clipboard.writeText(s.user_code).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})}return u?r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx(zy,{className:"size-6 animate-spin text-muted-foreground"}),r.jsx("p",{className:"text-[13px] text-muted-foreground",children:"Requesting authorization…"})]})}):o?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8",children:[r.jsx(tt,{variant:"destructive",children:o}),r.jsx(J,{onClick:t,variant:"outline",children:"Go back"})]}):r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-emerald-100 dark:bg-emerald-500/15",children:r.jsx(rf,{className:"size-6 text-emerald-600 dark:text-emerald-400"})}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold",children:"Authorize on GitHub"}),r.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:["A GitHub page just opened in a new tab. Enter the code below and click"," ",r.jsx("strong",{children:"Authorize"}),"."]})]})]}),r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("div",{className:"flex cursor-pointer select-all items-center gap-3 rounded-xl border-2 border-border bg-muted px-6 py-4 font-mono text-2xl font-bold tracking-[0.3em] transition-colors hover:border-ring",onClick:k,title:"Click to copy",children:s?.user_code}),r.jsx("button",{className:"text-[11px] text-muted-foreground transition-colors hover:text-foreground",onClick:k,type:"button",children:m?"Copied!":"Click code to copy"})]}),r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[r.jsx(zy,{className:"size-3.5 animate-spin"}),"Waiting for authorization…"]}),r.jsx("a",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",href:s?.verification_uri_complete||s?.verification_uri,rel:"noopener noreferrer",target:"_blank",children:"Open GitHub again"}),r.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:t,type:"button",children:"Cancel"})]})]})}function hX({onSaved:e,onBack:t}){const[s,n]=y.useState(""),[o,l]=y.useState(!1),[u,h]=y.useState(null);async function m(d){d.preventDefault();const p=s.trim();if(p){l(!0),h(null);try{await N8("github.com",p),e()}catch(g){h(g instanceof Error?g.message:String(g))}finally{l(!1)}}}return r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-6 p-8",children:[r.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[r.jsx("div",{className:"flex size-12 items-center justify-center rounded-xl bg-muted",children:r.jsx(CN,{className:"size-6 text-muted-foreground"})}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold",children:"Personal Access Token"}),r.jsxs("p",{className:"mt-1 max-w-sm text-[13px] text-muted-foreground",children:["Create a token at"," ",r.jsx("a",{className:"underline underline-offset-2 hover:text-foreground",href:"https://github.com/settings/tokens/new?scopes=repo,workflow",rel:"noopener noreferrer",target:"_blank",children:"github.com/settings/tokens"})," ","with ",r.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"repo"})," and"," ",r.jsx("code",{className:"rounded bg-muted px-1 py-px text-[11px]",children:"workflow"})," scopes."]})]})]}),r.jsxs("form",{className:"flex w-full max-w-sm flex-col gap-3",onSubmit:d=>{m(d)},children:[r.jsx("input",{autoComplete:"off",className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-[13px] placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring",onChange:d=>n(d.target.value),placeholder:"ghp_...",spellCheck:!1,type:"password",value:s}),u?r.jsx(tt,{variant:"destructive",children:u}):null,r.jsx(J,{disabled:!s.trim()||o,type:"submit",children:o?"Saving…":"Save token"}),t?r.jsx("button",{className:"text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",onClick:t,type:"button",children:"← Back"}):null]})]})}function Wx({hasMore:e,loading:t,onLoadMore:s}){return e?r.jsx("div",{className:"p-2",children:r.jsxs("button",{className:"flex w-full items-center justify-center gap-1.5 rounded-md border border-border py-1.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground disabled:opacity-60",disabled:t,onClick:s,type:"button",children:[t?r.jsx(Et,{className:"size-3 animate-spin"}):null,t?"Loading…":"Load more"]})}):null}function fX({prs:e,loading:t,loadingMore:s,hasMore:n,error:o,selectedNumber:l,onSelect:u,onLoadMore:h}){return t&&e.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading pull requests…"}):o?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:o}):e.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No pull requests found."}):r.jsxs(r.Fragment,{children:[r.jsx("ul",{className:"divide-y divide-border",children:e.map(m=>r.jsx("li",{children:r.jsxs("button",{className:`flex w-full items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-muted/60 ${l===m.number?"bg-muted":""}`,onClick:()=>u(m.number),type:"button",children:[r.jsx("span",{className:"mt-0.5 shrink-0",children:r.jsx(mX,{pr:m})}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate text-[13px] font-medium",children:m.title}),r.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",m.number," · ",m.base.ref," ← ",m.head.ref," · ",m.user.login]})]}),m.draft?r.jsx("span",{className:"shrink-0 rounded border border-border px-1.5 py-px text-[10px] text-muted-foreground",children:"Draft"}):null]})},m.number))}),r.jsx(Wx,{hasMore:n,loading:s,onLoadMore:h})]})}function mX({pr:e}){return e.state==="merged"?r.jsx(Nh,{className:"size-4 text-purple-500"}):e.state==="closed"?r.jsx(iR,{className:"size-4 text-red-500"}):r.jsx(NN,{className:"size-4 text-emerald-500"})}function pj({body:e,title:t="Description"}){const[s,n]=y.useState("rendered"),o=l=>de("rounded px-1.5 py-0.5 text-[10px] font-medium transition-colors",l?"bg-foreground text-background":"text-muted-foreground hover:text-foreground");return r.jsxs("section",{className:"overflow-hidden rounded-md border border-border bg-muted/25",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[r.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:t}),r.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-background/60 p-0.5",children:[r.jsx("button",{className:o(s==="rendered"),onClick:()=>n("rendered"),type:"button",children:"Rendered"}),r.jsx("button",{className:o(s==="raw"),onClick:()=>n("raw"),type:"button",children:"Raw"})]})]}),s==="rendered"?r.jsx(L5,{content:e}):r.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap px-3 py-3 font-mono text-[12px]",children:e})]})}function pX({title:e,message:t,confirmLabel:s="Confirm",cancelLabel:n="Cancel",tone:o="default",icon:l,loading:u=!1,onConfirm:h,onCancel:m}){y.useEffect(()=>{function p(g){g.key==="Escape"&&!u&&m()}return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[m,u]);const d=o==="danger"?"destructive":o==="success"?"success":"default";return _a.createPortal(r.jsx("div",{className:"fixed inset-0 z-[1000] grid place-items-center bg-black/35 px-4",onMouseDown:()=>!u&&m(),children:r.jsxs("div",{"aria-modal":"true",className:"flex w-full max-w-md flex-col overflow-hidden rounded-lg border border-border bg-card shadow-xl",onMouseDown:p=>p.stopPropagation(),role:"dialog",children:[r.jsxs("div",{className:"flex items-start gap-3 px-4 py-4",children:[l?r.jsx("div",{className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border bg-background text-foreground [&_svg]:size-4",children:l}):null,r.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[r.jsx("h2",{className:"text-sm font-semibold",children:e}),r.jsx("div",{className:"text-[13px] text-muted-foreground",children:t})]})]}),r.jsxs("div",{className:"flex justify-end gap-2 border-t border-border bg-muted/30 px-4 py-3",children:[r.jsx(J,{disabled:u,onClick:m,size:"sm",type:"button",variant:"outline",children:n}),r.jsx(J,{disabled:u,onClick:h,size:"sm",type:"button",variant:d,children:s})]})]})}),document.body)}function gX({pr:e,diff:t,diffLoading:s,diffError:n,onMerged:o}){const[l,u]=y.useState("cockpit"),[h,m]=y.useState(null),[d,p]=y.useState(!1),[g,x]=y.useState(null),[v,S]=y.useState(!1),[k,N]=y.useState(null),[E,A]=y.useState(!1),[j,T]=y.useState(null),[P,z]=y.useState(!1),{sendToAgent:I}=It(),M=y.useMemo(()=>OI(t),[t]);y.useEffect(()=>{T(F=>F&&M.some(D=>D.path===F)?F:M[0]?.path??null)},[M]);const L=M.find(F=>F.path===j)??M[0]??null;function B(F){T(F),u("diff")}function G(F,D){e&&(z(!1),I({prompt:D?EP(e,D,F):CP(e,F),source:{type:"github-pr",label:`PR #${e.number}${D?` · ${ef(D)}`:""}`},label:`PR #${e.number}${D?` (${ef(D)})`:""}: ${F}`}))}if(y.useEffect(()=>{if(z(!1),!e){m(null);return}let F=!0;return p(!0),x(null),A8(e.number).then(D=>{F&&m(D)}).catch(D=>{F&&x(D instanceof Error?D.message:String(D))}).finally(()=>{F&&p(!1)}),()=>{F=!1}},[e]),!e)return r.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:"Select a pull request"});const Z=e.state==="open"&&!e.draft;async function $(){if(!(!e||v)){S(!0),N(null);try{await D8(e.number,{method:"squash"}),A(!1),o?.()}catch(F){N(F instanceof Error?F.message:String(F)),A(!1)}finally{S(!1)}}}const q=F=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${F?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`;return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),r.jsx(Ki,{className:de("shrink-0",P&&"opacity-100"),label:`Ask AI about PR #${e.number}`,onAsk:()=>z(F=>!F)}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[r.jsx("button",{className:q(l==="cockpit"),onClick:()=>u("cockpit"),type:"button",children:"Review"}),r.jsx("button",{className:q(l==="diff"),onClick:()=>u("diff"),type:"button",children:"Diff"})]}),Z?r.jsxs(J,{className:"shrink-0",disabled:v,onClick:()=>A(!0),size:"sm",title:"Squash & merge this pull request",type:"button",variant:"success",children:[r.jsx(Nh,{}),"Squash & merge"]}):null,r.jsx("a",{"aria-label":"Open on GitHub",className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",title:"Open on GitHub",children:r.jsx(kr,{className:"size-3.5"})})]}),k?r.jsx("div",{className:"shrink-0 border-b border-border bg-red-500/10 px-3 py-1.5 text-[11px] text-red-500",children:k}):null,P?r.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:r.jsx(jr,{placeholder:"What should the agent do with this PR? (review, summarize, find regressions…)",onSubmit:F=>G(F),onCancel:()=>z(!1)})}):null,l==="cockpit"?r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:r.jsx(bX,{cockpit:h,error:g,loading:d,onOpenFile:B,pr:e})}):s?r.jsx(wf,{className:"flex-1",label:"Loading diff…"}):n?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:n}):M.length?r.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1",children:[r.jsx(xX,{files:M,onAsk:(F,D)=>G(D,F),onSelect:T,selected:L?.path??null}),r.jsx("div",{className:"relative min-h-0 min-w-0 flex-1",children:L?r.jsx(lu,{diff:L.diff}):null})]}):r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No diff available."}),E?r.jsx(pX,{confirmLabel:v?r.jsxs(r.Fragment,{children:[r.jsx(Vx,{size:"sm"})," Merging…"]}):"Squash & merge",icon:r.jsx(Nh,{}),loading:v,message:r.jsxs(r.Fragment,{children:["Squash & merge PR ",r.jsxs("span",{className:"font-mono",children:["#",e.number]})," ",r.jsx("span",{className:"font-medium text-foreground",children:e.title})," into"," ",r.jsx("span",{className:"font-mono",children:e.base.ref}),"?"]}),onCancel:()=>A(!1),onConfirm:()=>{$()},title:"Squash & merge",tone:"success"}):null]})}function bX({pr:e,cockpit:t,loading:s,error:n,onOpenFile:o}){const[l,u]=y.useState(!1),h=t?.pr??e,m=t?.files??[],d=t?.reviews??[],p=t?.comments??[],g=t?.checks??null,x=g?.runs.filter(v=>v.conclusion==="failure"||v.conclusion==="timed_out"||v.conclusion==="cancelled")??[];return r.jsxs("div",{className:"space-y-3 p-4",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-[12px]",children:[r.jsx(yX,{pr:h}),r.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border bg-muted/40 px-2 py-1 font-mono text-[11px]",children:[r.jsx(xn,{className:"size-3 shrink-0 text-muted-foreground"}),h.base.ref,r.jsx(eu,{className:"size-3 shrink-0 text-muted-foreground"}),h.head.ref]}),r.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[r.jsx(BM,{className:"size-3 shrink-0"}),h.user.login]}),r.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[r.jsx(e4,{className:"size-3 shrink-0"}),new Date(h.created_at).toLocaleDateString()]})]}),n?r.jsx("div",{className:"rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[12px] text-red-500",children:n}):null,s?r.jsx(wf,{className:"justify-start",label:"Loading review cockpit…"}):null,r.jsxs("div",{className:"grid gap-2 md:grid-cols-4",children:[r.jsx(ih,{title:"Merge readiness",value:gj(h,g),tone:vX(h,g)}),r.jsx(ih,{title:"Review state",value:bj(d),tone:_X(d)}),r.jsx(ih,{title:"Checks",value:g?`${g.state} (${g.totalCount})`:"unknown",tone:g?.state==="success"?"success":g?.state==="failure"||g?.state==="error"?"danger":"muted"}),r.jsx(ih,{title:"Changed files",value:String(m.length),tone:"muted"})]}),x.length>0?r.jsxs("section",{className:"rounded-md border border-red-500/25 bg-red-500/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 text-[11px] font-medium text-red-500",children:"Failing checks"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:x.slice(0,4).map(v=>r.jsxs("a",{className:"inline-flex items-center gap-1 text-[11px] text-red-500 underline-offset-2 hover:underline",href:v.html_url,rel:"noopener noreferrer",target:"_blank",children:[r.jsx(Ob,{className:"size-3"}),"Open failing check: ",v.name]},v.id))})]}):null,r.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[r.jsxs("button",{className:"flex w-full items-center gap-2 text-[12px] font-medium",onClick:()=>u(v=>!v),type:"button",children:[l?r.jsx(vn,{className:"size-3.5 text-muted-foreground"}):r.jsx(Xn,{className:"size-3.5 text-muted-foreground"}),r.jsx(zb,{className:"size-3.5 text-muted-foreground"}),"Changed files",m.length?r.jsxs("span",{className:"font-mono text-[11px] text-muted-foreground",children:["(",m.length,")"]}):null]}),l?m.length?r.jsx("ul",{className:"mt-2 divide-y divide-border",children:m.slice(0,12).map(v=>r.jsx("li",{children:r.jsxs("button",{className:"flex w-full items-center gap-2 py-1.5 text-left text-[12px] transition-colors hover:text-foreground",onClick:()=>o(v.path),title:`View diff for ${v.path}`,type:"button",children:[r.jsx("span",{className:"w-16 shrink-0 font-mono text-[10px] uppercase text-muted-foreground",children:v.status}),r.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:v.path}),r.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-emerald-600",children:["+",v.additions]}),r.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-red-500",children:["-",v.deletions]})]})},v.path))}):r.jsx("p",{className:"mt-2 text-[12px] text-muted-foreground",children:"No changed file metadata available."}):null]}),r.jsxs("section",{className:"rounded-md border border-border bg-muted/25 p-3",children:[r.jsxs("div",{className:"mb-2 flex items-center gap-2 text-[12px] font-medium",children:[r.jsx(zR,{className:"size-3.5 text-muted-foreground"}),"Review state"]}),d.length||p.length?r.jsxs("div",{className:"space-y-2",children:[d.slice(-4).map(v=>r.jsx(nN,{href:v.html_url,meta:`${v.user.login} - ${v.state.toLowerCase()}`,text:v.body||"No review summary."},`review:${v.id}`)),p.slice(-4).map(v=>r.jsx(nN,{href:v.html_url,meta:`${v.user.login} - comment`,text:v.body},`comment:${v.id}`))]}):r.jsx("p",{className:"text-[12px] text-muted-foreground",children:"No reviews or PR comments yet."})]}),h.body?r.jsx(pj,{body:h.body}):r.jsx("p",{className:"text-[12px] italic text-muted-foreground",children:"No description provided."})]})}function xX({files:e,selected:t,onSelect:s,onAsk:n}){const[o,l]=y.useState(null);return r.jsx("div",{className:"w-44 shrink-0 overflow-y-auto border-r border-border bg-card/60",children:r.jsx("ul",{className:"py-1",children:e.map(u=>r.jsxs("li",{className:"group flex flex-col",children:[r.jsxs("div",{className:de("flex items-center transition-colors",u.path===t?"bg-muted":"hover:bg-muted/60"),children:[r.jsxs("button",{className:de("flex min-w-0 flex-1 items-center gap-1.5 px-2.5 py-1.5 text-left text-[11px]",u.path===t?"text-foreground":"text-muted-foreground group-hover:text-foreground"),onClick:()=>s(u.path),title:u.path,type:"button",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:ef(u.path)}),r.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-emerald-600",children:["+",u.additions]}),r.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-red-500",children:["-",u.deletions]})]}),r.jsx(Ki,{className:de("mr-1 shrink-0",o===u.path&&"opacity-100"),label:`Ask AI about ${ef(u.path)}`,onAsk:()=>l(h=>h===u.path?null:u.path)})]}),o===u.path?r.jsx("div",{className:"px-2 pb-1.5 pt-0.5",children:r.jsx(jr,{placeholder:"What about this file? (review, explain, find bugs…)",onSubmit:h=>{l(null),n(u.path,h)},onCancel:()=>l(null)})}):null]},u.path))})})}function ef(e){const t=e.split("/");return t[t.length-1]||e}function ih({title:e,value:t,tone:s}){const n=s==="success"?"bg-emerald-500":s==="warning"?"bg-amber-500":s==="danger"?"bg-red-500":"bg-muted-foreground";return r.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[r.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:e}),r.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[12px] font-medium",children:[r.jsx("span",{className:`size-1.5 rounded-full ${n}`}),t]})]})}function nN({meta:e,text:t,href:s}){return r.jsxs("a",{className:"block rounded border border-border bg-card px-2.5 py-2 text-[12px] transition-colors hover:bg-muted/60",href:s,rel:"noopener noreferrer",target:"_blank",children:[r.jsxs("span",{className:"mb-1 flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[r.jsx(kr,{className:"size-3"}),e]}),r.jsx("span",{className:"line-clamp-2 whitespace-pre-wrap",children:t})]})}function gj(e,t){return e.state!=="open"?e.state:e.draft?"draft":e.mergeable===!1?"blocked":t?.state==="failure"||t?.state==="error"?"checks failing":t?.state==="pending"?"checks pending":e.mergeable===!0?"ready":"unknown"}function vX(e,t){const s=gj(e,t);return s==="ready"?"success":s==="blocked"||s==="checks failing"?"danger":s==="draft"||s==="checks pending"?"warning":"muted"}function bj(e){return e.some(t=>t.state==="CHANGES_REQUESTED")?"changes requested":e.some(t=>t.state==="APPROVED")?"approved":e.some(t=>t.state==="COMMENTED")?"commented":"no reviews"}function _X(e){const t=bj(e);return t==="approved"?"success":t==="changes requested"?"danger":t==="commented"?"warning":"muted"}function yX({pr:e}){const{label:t,dot:s}=e.state==="merged"?{label:"Merged",dot:"bg-violet-500"}:e.state==="closed"?{label:"Closed",dot:"bg-red-500"}:e.draft?{label:"Draft",dot:"bg-muted-foreground"}:{label:"Open",dot:"bg-emerald-500"};return r.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[r.jsx("span",{className:`size-1.5 rounded-full ${s}`}),t==="Merged"?r.jsx(Nh,{className:"size-3"}):t==="Open"?r.jsx(rf,{className:"size-3"}):r.jsx(qc,{className:"size-3"}),t]})}function xj({label:e}){return r.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",title:e.name,children:[r.jsx("span",{className:"size-2 shrink-0 rounded-sm",style:{backgroundColor:`#${e.color}`}}),r.jsx("span",{className:"truncate",children:e.name})]})}function SX({issues:e,loading:t,loadingMore:s,hasMore:n,error:o,selectedNumber:l,onSelect:u,onLoadMore:h}){return t&&e.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading issues…"}):o?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:o}):e.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No issues found."}):r.jsxs(r.Fragment,{children:[r.jsx("ul",{className:"divide-y divide-border",children:e.map(m=>r.jsx("li",{children:r.jsxs("button",{className:`flex w-full items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-muted/60 ${l===m.number?"bg-muted":""}`,onClick:()=>u(m.number),type:"button",children:[r.jsx(m4,{className:`mt-0.5 size-4 shrink-0 ${m.state==="open"?"text-emerald-500":"text-red-500"}`}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate text-[13px] font-medium",children:m.title}),r.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",m.number," · ",m.user.login," · ",m.comments," comment",m.comments!==1?"s":""]})]}),m.labels.length>0?r.jsx("span",{className:"flex max-w-40 shrink-0 flex-wrap justify-end gap-x-2 gap-y-0.5",children:m.labels.slice(0,3).map(d=>r.jsx(xj,{label:d},d.name))}):null]})},m.number))}),r.jsx(Wx,{hasMore:n,loading:s,onLoadMore:h})]})}const rh=6,wX=6,kX=8;function NX(e,t,s,n){const o=Math.max(0,Math.min(wX,e/2,t/2)),l=Math.max(0,Math.min(kX,s-o,n-o));return[`M ${o} 0`,`H ${e-o}`,`A ${o} ${o} 0 0 1 ${e} ${o}`,`V ${t-n-o}`,`A ${o} ${o} 0 0 1 ${e-o} ${t-n}`,`H ${e-s+l}`,`A ${l} ${l} 0 0 0 ${e-s} ${t-n+l}`,`V ${t-o}`,`A ${o} ${o} 0 0 1 ${e-s-o} ${t}`,`H ${o}`,`A ${o} ${o} 0 0 1 0 ${t-o}`,`V ${o}`,`A ${o} ${o} 0 0 1 ${o} 0`,"Z"].join(" ")}function CX({value:e,onChange:t,placeholder:s,rows:n=3,action:o}){const l=y.useRef(null),u=y.useRef(null),[h,m]=y.useState(null),[d,p]=y.useState({w:0,h:0});y.useLayoutEffect(()=>{const x=l.current,v=u.current;if(!x||!v)return;const S=()=>{m({w:x.clientWidth,h:x.clientHeight}),p({w:v.offsetWidth+rh*2,h:v.offsetHeight+rh*2})};S();const k=new ResizeObserver(S);return k.observe(x),k.observe(v),()=>k.disconnect()},[]);const g=h&&d.w&&d.h?NX(h.w,h.h,d.w,d.h):null;return r.jsxs("div",{className:"relative",ref:l,children:[r.jsx("textarea",{className:"peer block w-full resize-none bg-background px-3 pt-2 font-mono text-[12px] placeholder:text-muted-foreground focus:outline-none",onChange:x=>t(x.target.value),placeholder:s,rows:n,style:{clipPath:g?`path('${g}')`:void 0,paddingBottom:d.h||44},value:e}),h&&g?r.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 overflow-visible text-border transition-colors peer-focus:text-foreground/40",fill:"none",height:h.h,viewBox:`0 0 ${h.w} ${h.h}`,width:h.w,children:[r.jsx("title",{children:"Comment field border"}),r.jsx("path",{d:g,stroke:"currentColor",strokeWidth:1})]}):null,r.jsx("div",{className:"absolute",ref:u,style:{bottom:rh,right:rh},children:o})]})}function EX({issue:e,comments:t,commentsLoading:s,commentError:n,submitting:o,onAddComment:l}){const[u,h]=y.useState(""),[m,d]=y.useState(!1),{sendToAgent:p}=It();y.useEffect(()=>{d(!1)},[e?.number]);function g(v){e&&(d(!1),p({prompt:jP(e,v),source:{type:"github-issue",label:`Issue #${e.number}`},label:`Issue #${e.number}: ${v}`}))}if(!e)return r.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:"Select an issue"});async function x(v){v.preventDefault();const S=u.trim();S&&(await l(S),h(""))}return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"group flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold",children:e.title}),r.jsx(Ki,{className:de("shrink-0",m&&"opacity-100"),label:`Ask AI about issue #${e.number}`,onAsk:()=>d(v=>!v)}),r.jsx("a",{"aria-label":"Open on GitHub",className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",children:r.jsx(kr,{className:"size-3.5"})})]}),m?r.jsx("div",{className:"shrink-0 border-b border-border px-3 py-1.5",children:r.jsx(jr,{placeholder:"What should the agent do with this issue? (summarize, draft a fix plan, reproduce…)",onSubmit:g,onCancel:()=>d(!1)})}):null,r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:r.jsxs("div",{className:"space-y-3 p-4",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[12px]",children:[r.jsxs("span",{className:"text-[11px]",children:[r.jsx("span",{className:"text-muted-foreground",children:"Author: "}),r.jsx("span",{className:"font-medium",children:e.user.login})]}),r.jsxs("span",{className:"text-[11px]",children:[r.jsx("span",{className:"text-muted-foreground",children:"Opened: "}),r.jsx("span",{className:"font-medium",children:new Date(e.created_at).toLocaleDateString()})]}),e.labels.map(v=>r.jsx(xj,{label:v},v.name))]}),e.body?r.jsx(pj,{body:e.body}):r.jsx("p",{className:"text-[12px] text-muted-foreground italic",children:"No description provided."}),s?r.jsx(wf,{className:"justify-start",label:"Loading comments…"}):r.jsx("div",{className:"space-y-2",children:t.map(v=>r.jsxs("div",{className:"rounded-md border border-border bg-muted/20 p-3",children:[r.jsxs("div",{className:"mb-1 flex items-baseline gap-2",children:[r.jsx("span",{className:"text-[11px] font-semibold",children:v.user.login}),r.jsx("span",{className:"text-[10px] text-muted-foreground",children:new Date(v.created_at).toLocaleDateString()})]}),r.jsx(R3,{content:v.body})]},v.id))})]})}),r.jsx("div",{className:"shrink-0 border-t border-border p-3",children:r.jsxs("form",{className:"flex flex-col gap-2",onSubmit:v=>{x(v)},children:[r.jsx(CX,{action:r.jsx(J,{disabled:!u.trim()||o,size:"sm",type:"submit",children:o?r.jsxs(r.Fragment,{children:[r.jsx(Vx,{size:"sm"})," Posting…"]}):"Comment"}),onChange:h,placeholder:"Add a comment…",value:u}),n?r.jsx(tt,{variant:"destructive",children:n}):null]})})]})}const iN=30,jX=4e3;function TX(e){return e.status==="in_progress"||e.status==="queued"}function rN(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}`).join("|")}function aN(e){return e.map(t=>`${t.id}:${t.status}:${t.conclusion}:`+t.steps.map(s=>`${s.number}:${s.status}:${s.conclusion}`).join(",")).join("|")}function AX(e,t){if(e.length===0)return t;const s=new Map(t.map(u=>[u.id,u])),n=new Set(e.map(u=>u.id)),o=t.filter(u=>!n.has(u.id)),l=e.map(u=>s.get(u.id)??u);return[...o,...l]}function RX(e){const[t,s]=y.useState([]),[n,o]=y.useState(null),[l,u]=y.useState([]),[h,m]=y.useState(!0),[d,p]=y.useState(!1),[g,x]=y.useState(!1),[v,S]=y.useState(1),[k,N]=y.useState(!1),[E,A]=y.useState(null),[j,T]=y.useState(null);function P(){let L=!0;return m(!0),A(null),S(1),ah(e,1).then(B=>{L&&(s(B),x(B.length===iN))}).catch(B=>{L&&A(B instanceof Error?B.message:String(B))}).finally(()=>{L&&m(!1)}),()=>{L=!1}}function z(){if(d||!g)return;const L=v+1;p(!0),ah(e,L).then(B=>{s(G=>{const Z=new Set(G.map($=>$.id));return[...G,...B.filter($=>!Z.has($.id))]}),x(B.length===iN),S(L)}).catch(B=>A(B instanceof Error?B.message:String(B))).finally(()=>p(!1))}const I=y.useCallback(()=>{ah(e,1).then(L=>s(B=>{const G=AX(B,L);return rN(B)===rN(G)?B:G})).catch(()=>{}),n&&Ky(n).then(L=>u(B=>aN(B)===aN(L)?B:L)).catch(()=>{})},[e,n]);y.useEffect(P,[e]),y.useEffect(()=>{o(L=>L&&t.some(B=>B.id===L)?L:t[0]?.id??null)},[t]),y.useEffect(()=>{if(!n){u([]);return}let L=!0;return N(!0),T(null),Ky(n).then(B=>{L&&u(B)}).catch(B=>{L&&T(B instanceof Error?B.message:String(B))}).finally(()=>{L&&N(!1)}),()=>{L=!1}},[n]);const M=t.some(TX);return y.useEffect(()=>{if(!M)return;const L=window.setInterval(()=>{document.visibilityState==="visible"&&I()},jX);return()=>window.clearInterval(L)},[M,I]),{runs:t,selectedRunId:n,jobs:l,loading:h,loadingMore:d,hasMore:g,jobsLoading:k,error:E,jobsError:j,loadMore:z,refresh:P,syncLatest:I,setSelectedRunId:o}}function vj(e){return e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"}function MX({branch:e,onClearBranch:t}){const{runs:s,selectedRunId:n,jobs:o,loading:l,loadingMore:u,hasMore:h,jobsLoading:m,error:d,jobsError:p,loadMore:g,refresh:x,syncLatest:v,setSelectedRunId:S}=RX(e);du(v);const k=s.find(T=>T.id===n)??null,{sendToAgent:N}=It(),[E,A]=y.useState(null);function j(T,P){A(null),N({prompt:TP(T,P),source:{type:"github-run",label:`Run #${T.run_number}`},label:`Run #${T.run_number}: ${P??"fix failing run"}`})}return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"text-[13px] font-semibold",children:"Workflow Runs"}),e?r.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:[r.jsx("span",{className:"shrink-0",children:"Filtered to"}),r.jsx("span",{className:"min-w-0 truncate font-mono",children:e}),t?r.jsx("button",{"aria-label":"Clear branch filter",className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:t,title:"Clear branch filter",type:"button",children:r.jsx(ts,{className:"size-3"})}):null]}):null]}),r.jsxs(J,{disabled:l,onClick:()=>{x()},size:"sm",type:"button",variant:"outline",children:[r.jsx(Cr,{className:`mr-1 size-3.5 ${l?"animate-spin":""}`}),"Refresh"]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:d?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:d}):l&&s.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading workflow runs…"}):s.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No workflow runs found."}):r.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(280px,380px)_minmax(0,1fr)] divide-x divide-border",children:[r.jsxs("div",{className:"min-h-0 overflow-auto",children:[r.jsx("ul",{className:"divide-y divide-border",children:s.map(T=>r.jsxs("li",{className:"group flex flex-col",children:[r.jsxs("div",{className:`flex items-center transition-colors hover:bg-muted/60 ${T.id===n?"bg-muted/70":""}`,children:[r.jsxs("button",{className:"flex min-w-0 flex-1 items-center gap-3 px-3 py-2.5 text-left",onClick:()=>S(T.id),type:"button",children:[r.jsx(DX,{run:T}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate text-[13px] font-medium",children:T.name}),r.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["#",T.run_number," · ",T.head_branch," · ",T.event," ·"," ",r.jsx("span",{title:new Date(T.created_at).toLocaleString(),children:TL(T.created_at)})]})]}),r.jsx(OX,{run:T})]}),vj(T)?r.jsx(Ki,{className:`mr-2 shrink-0 ${E===T.id?"opacity-100":""}`,label:`Fix failing run #${T.run_number} with AI`,onAsk:()=>A(P=>P===T.id?null:T.id)}):null]}),E===T.id?r.jsx("div",{className:"px-3 pb-2 pt-0.5",children:r.jsx(jr,{onCancel:()=>A(null),onSubmit:P=>j(T,P),placeholder:"What should the agent do? (fix it, explain the failure, find the broken step…)"})}):null]},T.id))}),r.jsx(Wx,{hasMore:h,loading:u,onLoadMore:g})]}),r.jsx(LX,{error:p,jobs:o,loading:m,onFix:T=>j(T),run:k})]})})]})}function DX({run:e}){return e.status==="in_progress"||e.status==="queued"?r.jsx(qc,{className:"size-4 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"?r.jsx(rf,{className:"size-4 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"?r.jsx(Ob,{className:"size-4 shrink-0 text-red-500"}):r.jsx(qc,{className:"size-4 shrink-0 text-zinc-400"})}function OX({run:e}){const t=e.status==="completed"?e.conclusion??"completed":e.status,s=t==="success"?"bg-emerald-500":t==="failure"||t==="timed_out"?"bg-red-500":t==="in_progress"||t==="queued"?"bg-amber-500":"bg-muted-foreground";return r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[r.jsx("span",{className:`size-1.5 rounded-full ${s}`}),t]})}function LX({run:e,jobs:t,loading:s,error:n,onFix:o}){return e?r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block truncate text-[13px] font-semibold",children:e.name}),r.jsxs("span",{className:"block text-[11px] text-muted-foreground",children:["Run #",e.run_number," · ",e.head_branch," · ",e.head_sha.slice(0,7)]})]}),vj(e)?r.jsxs(J,{className:"shrink-0 gap-1",onClick:()=>o(e),size:"sm",title:"Send this failing run to the agent to investigate and fix",type:"button",variant:"outline",children:[r.jsx(Gt,{className:"size-3.5"}),"Fix with AI"]}):null,r.jsx("a",{"aria-label":"Open run on GitHub",className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:e.html_url,rel:"noopener noreferrer",target:"_blank",title:"Open run on GitHub",children:r.jsx(kr,{className:"size-3.5"})})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:n?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:n}):s?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading jobs…"}):t.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No jobs found for this run."}):r.jsx("ul",{className:"divide-y divide-border",children:t.map(l=>r.jsxs("li",{className:"px-3 py-3",children:[r.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[r.jsx(oN,{item:l}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-medium",children:l.name}),r.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:lN(l.started_at,l.completed_at)}),r.jsx("a",{"aria-label":`Open ${l.name} job on GitHub`,className:"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",href:l.html_url,rel:"noopener noreferrer",target:"_blank",title:"Open job on GitHub",children:r.jsx(kr,{className:"size-3.5"})})]}),l.steps.length?r.jsx("ol",{className:"space-y-1.5 pl-6",children:l.steps.map(u=>r.jsxs("li",{className:"flex items-center gap-2 text-[12px]",children:[r.jsx(oN,{item:u}),r.jsx("span",{className:"min-w-0 flex-1 truncate",children:u.name}),r.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:lN(u.started_at,u.completed_at)})]},`${l.id}:${u.number}`))}):r.jsx("p",{className:"pl-6 text-[12px] text-muted-foreground",children:"No step details available."})]},l.id))})})]}):r.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:"Select a workflow run"})}function oN({item:e}){return e.status==="in_progress"||e.status==="queued"?r.jsx(qc,{className:"size-3.5 shrink-0 animate-pulse text-amber-400"}):e.conclusion==="success"||e.conclusion==="skipped"?r.jsx(rf,{className:"size-3.5 shrink-0 text-emerald-500"}):e.conclusion==="failure"||e.conclusion==="timed_out"||e.conclusion==="cancelled"?r.jsx(Ob,{className:"size-3.5 shrink-0 text-red-500"}):r.jsx(qc,{className:"size-3.5 shrink-0 text-zinc-400"})}function lN(e,t){if(!e)return"-";const s=Date.parse(e),n=t?Date.parse(t):Date.now();if(!Number.isFinite(s)||!Number.isFinite(n)||n<s)return"-";const o=Math.max(0,Math.round((n-s)/1e3));if(o<60)return`${o}s`;const l=Math.floor(o/60),u=o%60;return u?`${l}m ${u}s`:`${l}m`}function zX({onCreatePR:e,onViewRuns:t}){const[s,n]=y.useState(null),[o,l]=y.useState(!0),[u,h]=y.useState(null);function m(){let p=!0;return l(!0),h(null),E8().then(g=>{p&&n(g)}).catch(g=>{p&&h(g instanceof Error?g.message:String(g))}).finally(()=>{p&&l(!1)}),()=>{p=!1}}y.useEffect(m,[]),du(()=>{m()});const d=y.useMemo(()=>[...s?.branches??[]].sort((g,x)=>{const v=uN(g,s),S=uN(x,s);return v-S||g.name.localeCompare(x.name)}),[s]);return r.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-b border-border px-3 py-1.5",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"text-[13px] font-semibold",children:"Branches"}),r.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:s?.repository.full_name??"Selected repository"})]}),r.jsxs(J,{disabled:o,onClick:()=>{m()},size:"sm",type:"button",variant:"outline",children:[r.jsx(Cr,{className:`mr-1 size-3.5 ${o?"animate-spin":""}`}),"Refresh"]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:u?r.jsx("div",{className:"p-4 text-[12px] text-red-500",children:u}):o&&!s?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"Loading branches..."}):d.length===0?r.jsx("div",{className:"p-4 text-[12px] text-muted-foreground",children:"No branches found."}):r.jsx("ul",{className:"divide-y divide-border",children:d.map(p=>r.jsx(BX,{branch:p,currentBranch:s?.currentBranch??null,defaultBranch:s?.defaultBranch??null,onCreatePR:e,onViewRuns:t},p.name))})})]})}function BX({branch:e,defaultBranch:t,currentBranch:s,onCreatePR:n,onViewRuns:o}){const l=e.name===t,u=e.name===s,h=!l;return r.jsxs("li",{className:"flex flex-wrap items-center gap-3 px-3 py-2.5",children:[r.jsx(xn,{className:"size-4 shrink-0 text-muted-foreground"}),r.jsxs("div",{className:"min-w-48 flex-1",children:[r.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[r.jsx("span",{className:"truncate font-mono text-[13px] font-medium",children:e.name}),l?r.jsx(cN,{label:"Default",tone:"success"}):null,u?r.jsx(cN,{label:"Current",tone:"warning"}):null,e.protected?r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[r.jsx(SM,{className:"size-3"}),"protected"]}):null]}),r.jsx("div",{className:"mt-0.5 font-mono text-[11px] text-muted-foreground",children:e.commit.sha.slice(0,7)})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[r.jsxs(J,{onClick:()=>o(e.name),size:"sm",title:`View workflow runs for ${e.name}`,type:"button",variant:"outline",children:[r.jsx(g4,{className:"size-3.5"}),"View runs"]}),r.jsxs(J,{disabled:!h,onClick:()=>n(e.name),size:"sm",title:h?`Open PR from ${e.name}`:"Default branch does not need a PR",type:"button",variant:"outline",children:[r.jsx(NN,{className:"size-3.5"}),"Open PR"]})]})]})}function cN({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":"bg-amber-500";return r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[r.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function uN(e,t){return e.name===t?.currentBranch?0:e.name===t?.defaultBranch?1:e.protected?2:3}function IX(){const e=lX();let t;return e.loading||e.status==="checking"?t=r.jsx(wf,{fill:!0,label:"Loading…"}):e.status==="not_configured"?t=r.jsx(mj,{deviceFlowAvailable:e.deviceFlowAvailable,onSaved:e.refresh}):e.status==="auth_error"||e.status==="connection_error"?t=r.jsx(PX,{token:e}):t=r.jsx($X,{token:e}),r.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-card/85",children:t})}function PX({token:e}){const[t,s]=y.useState(null);if(t)return r.jsx(mj,{deviceFlowAvailable:e.deviceFlowAvailable,initialMode:t,onSaved:e.refresh});const n=e.status==="auth_error";return r.jsx("div",{className:"flex h-full items-center justify-center p-8",children:r.jsxs("div",{className:"w-full max-w-lg space-y-4 rounded-md border border-border bg-card p-5",children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Gx,{className:"size-5"}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("h2",{className:"text-sm font-semibold",children:"GitHub connection failed"}),r.jsx("p",{className:"text-[12px] text-muted-foreground",children:n?"The saved GitHub token is no longer accepted.":"NoMoreIDE could not validate the GitHub connection."})]}),r.jsx(_j,{label:n?"Needs re-login":"Connection problem",tone:n?"danger":"warning"})]}),e.error?r.jsx(tt,{variant:"destructive",children:e.error}):null,r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsxs(J,{onClick:e.refresh,type:"button",variant:n?"outline":"default",children:[r.jsx(Cr,{}),"Refresh"]}),r.jsx(J,{onClick:()=>s(e.deviceFlowAvailable?"device-pending":"pat"),type:"button",variant:n?"default":"outline",children:"Reconnect GitHub"}),r.jsx(J,{onClick:()=>s("pat"),type:"button",variant:"outline",children:"Use token instead"})]})]})})}function $X({token:e}){const[t,s]=sl("github:tab","prs"),[n,o]=sl("github:pr-state","open"),[l,u]=sl("github:issue-state","open"),[h,m]=y.useState(null),[d,p]=y.useState(null),[g,x]=y.useState(!1),[v,S]=y.useState(null),k=cX(n),N=uX(l);du(()=>{t==="prs"?k.refresh():t==="issues"&&N.refresh()});const E=T=>`rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${T?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"}`,A=T=>`rounded px-2 py-0.5 text-[10px] font-medium transition-colors ${T?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`;async function j(){x(!0),S(null);try{await C8("github.com"),e.refresh()}catch(T){S(T instanceof Error?T.message:String(T))}finally{x(!1)}}return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border bg-card/95 px-3 py-1",children:[r.jsx("button",{className:E(t==="prs"),onClick:()=>s("prs"),type:"button",children:"Pull Requests"}),r.jsx("button",{className:E(t==="issues"),onClick:()=>s("issues"),type:"button",children:"Issues"}),r.jsx("button",{className:E(t==="branches"),onClick:()=>s("branches"),type:"button",children:"Branches"}),r.jsx("button",{className:E(t==="actions"),onClick:()=>s("actions"),type:"button",children:"Actions"}),r.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-2",children:[r.jsx(HX,{token:e}),r.jsxs(J,{onClick:e.refresh,size:"sm",title:"Re-check the GitHub connection",type:"button",variant:"outline",children:[r.jsx(Cr,{}),"Reconnect"]}),r.jsx(J,{disabled:g,onClick:()=>{j()},size:"sm",type:"button",variant:"outline",children:g?"Disconnecting…":"Disconnect"})]}),t==="prs"?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[r.jsx("button",{className:A(n==="open"),onClick:()=>o("open"),type:"button",children:"Open"}),r.jsx("button",{className:A(n==="closed"),onClick:()=>o("closed"),type:"button",children:"Closed"})]}),r.jsx(J,{onClick:()=>m(""),size:"sm",type:"button",variant:"outline",children:"New PR"})]}):t==="issues"?r.jsxs("div",{className:"flex items-center gap-0.5 rounded-md bg-muted/60 p-0.5",children:[r.jsx("button",{className:A(l==="open"),onClick:()=>u("open"),type:"button",children:"Open"}),r.jsx("button",{className:A(l==="closed"),onClick:()=>u("closed"),type:"button",children:"Closed"})]}):null]}),v?r.jsx(tt,{variant:"destructive",className:"m-3",children:v}):null,h!==null?r.jsx(UX,{initialHead:h,onCreated:T=>{m(null),s("prs"),k.setSelectedNumber(T.number),k.refresh()},onCancel:()=>m(null)}):r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t==="prs"?r.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[r.jsx("div",{className:"min-h-0 overflow-auto",children:r.jsx(fX,{error:k.error,hasMore:k.hasMore,loading:k.loading,loadingMore:k.loadingMore,onLoadMore:k.loadMore,onSelect:k.setSelectedNumber,prs:k.prs,selectedNumber:k.selectedNumber})}),r.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:r.jsx(gX,{diff:k.diff,diffError:k.diffError,diffLoading:k.diffLoading,onMerged:()=>k.refresh(),pr:k.selectedPR})})]}):t==="issues"?r.jsxs("div",{className:"grid h-full min-h-0 grid-cols-[minmax(0,1fr)_minmax(0,2fr)] divide-x divide-border",children:[r.jsx("div",{className:"min-h-0 overflow-auto",children:r.jsx(SX,{error:N.error,hasMore:N.hasMore,issues:N.issues,loading:N.loading,loadingMore:N.loadingMore,onLoadMore:N.loadMore,onSelect:N.setSelectedNumber,selectedNumber:N.selectedNumber})}),r.jsx("div",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden",children:r.jsx(EX,{commentError:N.commentError,comments:N.comments,commentsLoading:N.commentsLoading,issue:N.selectedIssue,onAddComment:N.addComment,submitting:N.submitting})})]}):t==="branches"?r.jsx(zX,{onCreatePR:T=>m(T),onViewRuns:T=>{p(T),s("actions")}}):r.jsx(MX,{branch:d??void 0,onClearBranch:()=>p(null)})})]})}function HX({token:e}){const t=e.info?.repository?.full_name??(e.info?.user?`@${e.info.user.login}`:"GitHub");return r.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 border-r border-border pr-2",children:[r.jsx(Gx,{className:"size-4 shrink-0 text-foreground"}),r.jsx(_j,{label:"Connected",tone:"success"}),r.jsx("span",{className:"max-w-48 truncate font-mono text-[10px] text-muted-foreground",children:t})]})}function _j({label:e,tone:t}){const s=t==="success"?"bg-emerald-500":t==="danger"?"bg-red-500":"bg-amber-500";return r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[r.jsx("span",{className:`size-1.5 rounded-full ${s}`}),e]})}function UX({initialHead:e,onCreated:t,onCancel:s}){const[n,o]=y.useState(""),[l,u]=y.useState(""),[h,m]=y.useState(""),[d,p]=y.useState("main"),[g,x]=y.useState(!1),[v,S]=y.useState(null),[k,N]=y.useState(!0),[E,A]=y.useState(!1),[j,T]=y.useState(null);y.useEffect(()=>{let M=!0;return N(!0),T(null),R8().then(L=>{M&&(S(L),o(L.title),u(L.body),m(e||L.head),p(L.base||L.suggestedBase||"main"),x(L.draft))}).catch(L=>{M&&T(L instanceof Error?L.message:String(L))}).finally(()=>{M&&N(!1)}),()=>{M=!1}},[e]);async function P(M){if(M.preventDefault(),!(!n.trim()||!h.trim()||!d.trim())){A(!0),T(null);try{const L=await M8({title:n.trim(),body:l.trim()||void 0,head:h.trim(),base:d.trim(),draft:g});t(L)}catch(L){T(L instanceof Error?L.message:String(L))}finally{A(!1)}}}const z="w-full rounded-md border border-border bg-background px-3 py-2 text-[13px] placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring",I=v?.warnings??[];return r.jsxs("form",{className:"flex min-h-0 flex-col gap-3 overflow-auto bg-muted/20 p-4",onSubmit:M=>{P(M)},children:[r.jsxs("div",{className:"flex items-start justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h3",{className:"text-[13px] font-semibold",children:"Branch to PR Assistant"}),r.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:[v?.repository?.full_name??"Selected repository",v?.currentBranch?` - ${v.currentBranch}`:""]})]}),r.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:k?"Detecting branch...":"Editable draft"})]}),r.jsx(FX,{template:v,loading:k}),I.length>0?r.jsx("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[12px] text-amber-700 dark:text-amber-300",children:I[0]}):null,r.jsx("input",{className:z,disabled:k,onChange:M=>o(M.target.value),placeholder:"Title",required:!0,value:n}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsxs("label",{className:"space-y-1",children:[r.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:"Head"}),r.jsx("input",{className:z,disabled:k,onChange:M=>m(M.target.value),placeholder:"Head branch",required:!0,value:h})]}),r.jsxs("label",{className:"space-y-1",children:[r.jsx("span",{className:"text-[10px] uppercase text-muted-foreground",children:"Base"}),r.jsx("input",{className:z,disabled:k,onChange:M=>p(M.target.value),placeholder:"Base branch",required:!0,value:d})]})]}),r.jsx("textarea",{className:`${z} resize-none`,disabled:k,onChange:M=>u(M.target.value),placeholder:"Description (optional)",rows:7,value:l}),r.jsxs("label",{className:"flex items-center gap-2 text-[12px]",children:[r.jsx("input",{checked:g,className:"size-3.5",disabled:k,onChange:M=>x(M.target.checked),type:"checkbox"}),"Create as draft"]}),j?r.jsx(tt,{variant:"destructive",children:j}):null,r.jsxs("div",{className:"flex gap-2",children:[r.jsx(J,{disabled:k||E||!n.trim()||!h.trim()||!d.trim(),type:"submit",children:E?"Creating…":"Create PR"}),r.jsx(J,{onClick:s,type:"button",variant:"outline",children:"Cancel"})]})]})}function FX({template:e,loading:t}){const s=e?.compare,n=s?.ciStatus,o=[{label:"base branch",value:s?.base||e?.base||"main"},{label:"head branch",value:s?.head||e?.head||"manual"},{label:"commits ahead",value:t?"...":String(s?.aheadBy??0)},{label:"changed files",value:t?"...":String(s?.files.length??0)},{label:"head CI",value:n?`${n.state} (${n.totalCount})`:"unavailable"}];return r.jsxs("div",{className:"rounded-md border border-border bg-card px-3 py-2",children:[r.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[r.jsx("span",{className:"text-[11px] font-medium text-foreground",children:"Compare summary"}),s?.headSha?r.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:s.headSha.slice(0,7)}):null]}),r.jsx("div",{className:"grid grid-cols-5 gap-2",children:o.map(l=>r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"truncate text-[10px] uppercase text-muted-foreground",children:l.label}),r.jsx("div",{className:"truncate font-mono text-[11px] text-foreground",children:l.value})]},l.label))}),s?.files.length?r.jsx("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted-foreground",children:s.files.slice(0,4).map(l=>r.jsxs("span",{className:"max-w-52 truncate",children:[l.status," ",l.path]},`${l.status}:${l.path}`))}):null]})}function qX({ahead:e=0,behind:t=0,branches:s,currentBranch:n,disabled:o,onRefresh:l,upstream:u}){const[h,m]=y.useState(!1),[d,p]=y.useState(""),[g,x]=y.useState(null),[v,S]=y.useState(null),[k,N]=y.useState(null),E=s.filter(L=>!L.remote),A=s.filter(L=>L.remote);async function j(L,B){x(L),N(null),S(null);try{await B(),await l()}catch(G){N(G instanceof Error?G.message:String(G))}finally{x(null)}}async function T(L){await j(`switch:${L}`,async()=>{await ki("/api/git/branches/switch",{name:L}),m(!1)})}async function P(){await j("fetch",async()=>{await ki("/api/git/fetch",{}),S("Fetched latest branch refs.")})}async function z(){await j("push",async()=>{const L=await cf();S(L.setUpstream?`Pushed ${L.branch} and set upstream.`:`Pushed ${L.branch}.`)})}const I=!!n&&(e>0||!u&&t===0);async function M(L){L.preventDefault();const B=d.trim();if(!B){N("Branch name is required.");return}await j("create",async()=>{await ki("/api/git/branches",{name:B}),p(""),m(!1)})}return r.jsxs("div",{className:"fixed bottom-12 right-4 z-50 flex items-end",children:[h?r.jsxs("div",{"aria-label":"Switch Git branch",className:"mb-11 w-[min(460px,calc(100vw-2rem))] rounded-lg border border-border bg-card shadow-xl",role:"dialog",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border p-3",children:[r.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[r.jsx(xn,{className:"size-4 text-muted-foreground"}),r.jsx("span",{className:"truncate text-sm font-semibold",children:n||"Branches"})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[I?r.jsxs(J,{"aria-label":"Push current branch",className:"gap-1.5 px-2 text-xs",disabled:o||g!==null,onClick:()=>{z()},size:"sm",title:u?`Push ${e} commit${e===1?"":"s"} to ${u}`:"Push and set upstream",type:"button",variant:"default",children:[r.jsx(Ib,{className:de("size-3.5",g==="push"&&"animate-pulse")}),"Push",e>0?` ${e}`:""]}):null,r.jsx(J,{"aria-label":"Fetch branches",disabled:o||g!==null,onClick:()=>{P()},size:"icon",title:"Fetch branches",type:"button",variant:"ghost",children:r.jsx(Cr,{className:de(g==="fetch"&&"animate-spin")})}),r.jsx(J,{"aria-label":"Close branch dialog",onClick:()=>m(!1),size:"icon",type:"button",variant:"ghost",children:r.jsx(ts,{})})]})]}),r.jsx("div",{className:"max-h-72 overflow-auto",children:s.length?r.jsxs(r.Fragment,{children:[r.jsx(dN,{branches:E,busy:g!==null,disabled:o,label:"Local",onSwitch:T}),r.jsx(dN,{branches:A,busy:g!==null,disabled:o,label:"Remote",onSwitch:T})]}):r.jsx("div",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:"No branches found."})}),r.jsxs("div",{className:"border-t border-border p-3",children:[r.jsxs("form",{className:"grid gap-2 sm:grid-cols-[1fr_auto]",onSubmit:M,children:[r.jsx(ht,{"aria-label":"New branch name",disabled:o||g!==null,onChange:L=>{p(L.target.value),N(null),S(null)},placeholder:"feature/new-work",value:d}),r.jsxs(J,{disabled:o||g!==null,type:"submit",children:[r.jsx(aR,{}),"Create"]})]}),k||v?r.jsx(tt,{className:"mt-3 px-3 py-2 text-xs",variant:k?"destructive":"muted",children:k??v}):null]})]}):null,r.jsxs(J,{className:"h-8 max-w-[260px] gap-2 rounded-md shadow-lg",disabled:o,onClick:()=>m(L=>!L),size:"sm",title:"Switch Git branch",type:"button",variant:"default",children:[r.jsx(xn,{className:"size-4"}),r.jsx("span",{className:"truncate font-mono text-xs",children:n||"No branch"}),n&&(e>0||t>0)?r.jsxs("span",{className:"flex items-center gap-1 font-mono text-[11px] tabular-nums",title:u?`${e} ahead / ${t} behind ${u}`:`${e} ahead / ${t} behind`,children:[t>0?r.jsxs("span",{className:"flex items-center",children:[r.jsx(tf,{className:"size-3"}),t]}):null,e>0?r.jsxs("span",{className:"flex items-center",children:[r.jsx(sf,{className:"size-3"}),e]}):null]}):null,r.jsx(vn,{className:de("size-4 transition-transform",h&&"rotate-180")})]})]})}function dN({branches:e,busy:t,disabled:s,label:n,onSwitch:o}){return r.jsxs("section",{children:[r.jsx("div",{className:"border-b border-border bg-muted/60 px-3 py-1.5 text-[11px] font-semibold uppercase text-muted-foreground",children:n}),e.length?e.map(l=>r.jsxs("button",{className:de("grid w-full grid-cols-[1fr_auto] items-center gap-2 border-b border-border px-3 py-2 text-left text-sm last:border-b-0 hover:bg-muted",l.current&&"bg-muted/70"),disabled:s||t||l.current,onClick:()=>{o(l.name)},type:"button",children:[r.jsxs("span",{className:"min-w-0",children:[r.jsx("span",{className:"block truncate font-medium",children:l.name}),l.upstream?r.jsxs("span",{className:"block truncate font-mono text-[11px] text-muted-foreground",children:["tracks ",l.upstream]}):null]}),r.jsx(et,{variant:l.current?"success":l.remote?"outline":"secondary",children:l.current?"current":l.remote?"remote":"local"})]},`${l.remote?"remote":"local"}:${l.name}`)):r.jsxs("div",{className:"border-b border-border px-3 py-3 text-sm text-muted-foreground",children:["No ",n.toLowerCase()," branches."]})]})}const yj="nomoreide-theme-choice";function VX(){if(typeof window>"u")return"dark";const e=window.localStorage.getItem(yj);return e==="light"||e==="dark"?e:"dark"}function GX(e){const t=document.documentElement;t.classList.toggle("dark",e==="dark"),t.style.colorScheme=e}function WX(){const[e,t]=y.useState(()=>VX()),s=y.useRef(null);y.useEffect(()=>{GX(e),window.localStorage.setItem(yj,e)},[e]);const n=y.useCallback(()=>{const o=e==="dark"?"light":"dark",l=s.current,u=document;if(!l||!u.startViewTransition||window.matchMedia("(prefers-reduced-motion: reduce)").matches){t(o);return}const h=l.getBoundingClientRect(),m=h.left+h.width/2,d=h.top+h.height/2,p=Math.hypot(Math.max(m,window.innerWidth-m),Math.max(d,window.innerHeight-d));u.startViewTransition(()=>{t(o)}).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${m}px ${d}px)`,`circle(${p}px at ${m}px ${d}px)`]},{duration:500,easing:"ease-in-out",pseudoElement:"::view-transition-new(root)"})})},[e]);return r.jsxs("button",{ref:s,type:"button",onClick:n,title:e==="dark"?"Switch to light mode":"Switch to dark mode","aria-label":"Toggle theme",className:Bh(),children:[r.jsx("span",{className:Ih(),children:e==="dark"?r.jsx(AM,{}):r.jsx($R,{})}),r.jsx("span",{className:Ph(),children:"Theme"})]})}function KX(){return ln()?r.jsxs("div",{className:"flex items-center justify-between h-8 bg-background border-b border-border select-none",style:{WebkitAppRegion:"drag"},onMouseDown:()=>JM(),children:[r.jsx("span",{className:"px-3 text-xs font-medium text-muted-foreground",children:"NoMoreIDE"}),r.jsxs("div",{className:"flex items-center",style:{WebkitAppRegion:"no-drag"},children:[r.jsx("button",{type:"button",onClick:XM,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":"Minimize",children:r.jsx(RN,{className:"h-3 w-3"})}),r.jsx("button",{type:"button",onClick:ZM,className:"h-8 w-10 flex items-center justify-center hover:bg-muted transition-colors","aria-label":"Maximize",children:r.jsx(so,{className:"h-3 w-3"})}),r.jsx("button",{type:"button",onClick:QM,className:"h-8 w-10 flex items-center justify-center hover:bg-destructive hover:text-destructive-foreground transition-colors","aria-label":"Close",children:r.jsx(ts,{className:"h-3 w-3"})})]})]}):null}function YX(e=!1){return de("group/sidebar hidden h-full shrink-0 overflow-x-hidden overflow-y-auto border-r border-border bg-card/85 py-5 backdrop-blur transition-[width,padding] duration-200 md:flex md:flex-col",e?"w-64 px-4":"w-16 px-2 hover:w-64 hover:px-4")}function XX(e,t=!1){return de("relative grid h-12 grid-cols-[48px_minmax(0,1fr)] items-center justify-start gap-0 overflow-hidden rounded-md px-0 text-[15px] font-medium transition-[background-color,color,width] duration-150",t?"w-full":"w-12 group-hover/sidebar:w-full",e?"bg-primary text-primary-foreground hover:bg-primary/90":"hover:bg-muted")}function ZX(e=!1,t=!1){return de("min-w-0 overflow-hidden text-left text-current transition duration-150 whitespace-pre",e?"translate-x-1 opacity-100":"opacity-0 group-hover/sidebar:translate-x-1 group-hover/sidebar:opacity-100",t?"pr-10":"pr-3")}function QX(e=!1){return de("flex size-12 items-center justify-center text-current transition-transform duration-150 [&_svg]:size-5",e?"translate-x-0":"-translate-x-px group-hover/sidebar:translate-x-0")}function JX({docked:e,onToggleDock:t}){return r.jsxs("div",{className:de("mt-auto flex h-10 min-w-0 items-center overflow-hidden border-t border-border/60 text-[11px] text-muted-foreground transition-[height,opacity,width] duration-150",e?"w-full justify-start opacity-100":"w-12 justify-center group-hover/sidebar:w-full group-hover/sidebar:justify-start group-hover/sidebar:opacity-100"),children:[r.jsxs("span",{className:de("flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-pre transition-[opacity,width] duration-150",e?"flex-1 opacity-100":"w-0 flex-none opacity-0 group-hover/sidebar:w-auto group-hover/sidebar:flex-1 group-hover/sidebar:opacity-100"),children:[r.jsx("span",{children:"Made with"}),r.jsx(dR,{"aria-label":"love",className:"size-3 shrink-0 fill-red-500 text-red-500"}),r.jsx("span",{children:"by Robert Wang"}),r.jsx("a",{"aria-label":"Robert Wang on LinkedIn",className:"shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-[#0A66C2]",href:"https://www.linkedin.com/in/robert-wang-cs/",rel:"noopener noreferrer",target:"_blank",title:"LinkedIn",children:r.jsxs("svg",{className:"size-3 fill-current",role:"img",viewBox:"0 0 24 24",children:[r.jsx("title",{children:"LinkedIn"}),r.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.063 2.063 0 1 1 0-4.126 2.063 2.063 0 0 1 0 4.126zM7.119 20.452H3.554V9h3.565v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.225 0z"})]})})]}),r.jsx("button",{"aria-label":e?"Undock sidebar":"Dock sidebar","aria-pressed":e,className:de("flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground [&_svg]:size-4",e?"ml-auto bg-muted text-foreground":"group-hover/sidebar:ml-auto"),onClick:t,title:e?"Undock sidebar":"Dock sidebar",type:"button",children:e?r.jsx(GR,{}):r.jsx(KR,{})})]})}function eZ({className:e}){return r.jsxs("div",{className:de("min-w-0",e),children:[r.jsxs("div",{className:"flex items-baseline gap-1.5",children:[r.jsx("div",{className:"text-sm font-semibold",children:"NoMoreIDE"}),r.jsxs("div",{className:"font-mono text-[10px] text-muted-foreground",children:["v","0.1.62"]})]}),r.jsx("div",{className:"font-mono text-[11px] text-muted-foreground",children:"127.0.0.1 console"})]})}function tZ({syncLocation:e=!0}={}){const[t,s]=y.useState(()=>e?window.location.pathname.startsWith("/agent")?"agent":window.location.pathname.startsWith("/errors")?"errors":window.location.pathname.startsWith("/database")?"database":window.location.pathname.startsWith("/terminal")?"terminal":window.location.pathname.startsWith("/github")?"github":window.location.pathname.startsWith("/git")?"git":"services":"services"),[n,o]=y.useState(null),[l,u]=y.useState(null),[h,m]=y.useState(null),[d,p]=y.useState(null),[g,x]=y.useState(!0),{error:v,success:S}=$s(),[k,N]=y.useState(()=>window.localStorage.getItem("nomoreide:sidebar-docked")==="true"),E=AU(),A=y.useCallback(async(z={})=>{z.silent||x(!0),p(null);try{o(await Z8()),z.notify&&S("Dashboard refreshed.")}catch(I){const M=I instanceof Error?I.message:String(I);p(M),v(M)}finally{x(!1)}},[v,S]),j=y.useCallback(()=>{A({notify:!0}),E.runActive()},[A,E]);y.useEffect(()=>{A()},[A]),y.useEffect(()=>{function z(){document.visibilityState==="visible"&&(A({silent:!0}),E.runActive())}const I=window.setInterval(z,5e3);return window.addEventListener("focus",z),document.addEventListener("visibilitychange",z),()=>{window.clearInterval(I),window.removeEventListener("focus",z),document.removeEventListener("visibilitychange",z)}},[t,A,E.runActive]),y.useEffect(()=>{if(!e)return;const z=t==="git"?"/git":t==="github"?"/github":t==="agent"?"/agent":t==="errors"?"/errors":t==="database"?"/database":t==="terminal"?"/terminal":"/";window.location.pathname!==z&&window.history.pushState(null,"",z)},[t,e]),y.useEffect(()=>{window.localStorage.setItem("nomoreide:sidebar-docked",String(k))},[k]);const T=y.useMemo(()=>n?Object.values(n.runtime.services).filter(z=>z.state==="running").length:0,[n]),P=n?.git.selectedRepository?.name??n?.git.cwd??"no-git-repository";return r.jsx(GI,{children:r.jsx(RU,{value:E,children:r.jsx(iH,{onRefresh:()=>{A({silent:!0})},children:r.jsxs("div",{className:"flex flex-col h-screen overflow-hidden",children:[r.jsx(KX,{}),r.jsxs("div",{className:"flex-1 overflow-hidden pb-9",children:[r.jsxs("div",{className:"mx-auto flex h-full max-w-[1500px]",children:[r.jsxs("aside",{className:YX(k),children:[r.jsxs("div",{className:de("grid h-12 grid-cols-[48px_minmax(0,1fr)] items-center overflow-hidden transition-[width] duration-150",k?"w-full":"w-12 group-hover/sidebar:w-full"),children:[r.jsx("div",{className:"flex size-12 items-center justify-center",children:r.jsx("div",{className:"flex size-9 items-center justify-center overflow-hidden rounded-md bg-primary text-primary-foreground",children:r.jsxs("svg",{"aria-label":"NoMoreIDE",className:"size-6",fill:"none",role:"img",viewBox:"0 0 64 64",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("path",{d:"M5 17C5 13.69 7.69 11 11 11H25L31 17H53C56.31 17 59 19.69 59 23V53C59 56.31 56.31 59 53 59H11C7.69 59 5 56.31 5 53V17Z",fill:"currentColor"}),r.jsx("path",{d:"M22 31L30 39L22 47",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"4.5"}),r.jsx("path",{d:"M36 47H48",stroke:"hsl(var(--primary))",strokeLinecap:"round",strokeWidth:"4.5"})]})})}),r.jsx(eZ,{className:de("min-w-0 translate-x-1 overflow-hidden transition-opacity duration-200",k?"opacity-100":"opacity-0 group-hover/sidebar:opacity-100")})]}),r.jsxs("nav",{className:"mt-5 grid flex-1 content-start gap-1",children:[r.jsx(qa,{active:t==="services",badge:T,docked:k,icon:r.jsx(LN,{}),label:"Services",onClick:()=>s("services")}),r.jsx(qa,{active:t==="git",docked:k,icon:r.jsx(xn,{}),label:"Git Review",onClick:()=>s("git")}),r.jsx(qa,{active:t==="github",docked:k,icon:r.jsx(Gx,{}),label:"GitHub",onClick:()=>s("github")}),r.jsx(qa,{active:t==="errors",docked:k,icon:r.jsx(Ch,{}),label:"Error Inbox",onClick:()=>s("errors")}),r.jsx(qa,{active:t==="database",docked:k,icon:r.jsx(fi,{}),label:"Database",onClick:()=>s("database")}),r.jsx(qa,{active:t==="terminal",docked:k,icon:r.jsx(EM,{}),label:"Terminal",onClick:()=>s("terminal")}),r.jsx(qa,{active:t==="agent",docked:k,icon:r.jsx(KA,{}),label:"Agent",onClick:()=>s("agent")})]}),r.jsx(JX,{docked:k,onToggleDock:()=>N(z=>!z)})]}),r.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col px-0 py-0",children:[r.jsxs("header",{className:de("relative z-40 flex shrink-0 flex-wrap items-center justify-between gap-3 border border-border bg-card/90 px-4 py-3 backdrop-blur","border-x-0 border-t-0 border-b"),children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(XR,{className:"size-4 text-muted-foreground md:hidden"}),r.jsxs("div",{children:[r.jsx("h1",{className:"text-lg font-semibold tracking-tight",children:t==="git"?"Git Review":t==="github"?"GitHub":t==="agent"?"Agent":t==="errors"?"Error Inbox":t==="database"?"Database":t==="terminal"?"Terminal":"Services"}),r.jsx("p",{className:"font-mono text-xs text-muted-foreground",children:n?.git.selectedRepository?.name??n?.git.cwd??"Local workspace"})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[d?r.jsx(et,{variant:"danger",children:d}):null,n&&(t==="git"||t==="github")?r.jsx(xY,{data:n,onRefresh:A}):null,r.jsxs("div",{"aria-label":"Dashboard quick actions",className:"flex items-center gap-1 rounded-lg border border-border bg-background p-px",role:"toolbar",children:[r.jsxs("button",{"aria-label":"Refresh",className:Bh(),onClick:j,title:"Refresh this page",type:"button",children:[r.jsx("span",{className:Ih(),children:r.jsx(Cr,{className:de(g&&"animate-spin")})}),r.jsx("span",{className:Ph(),children:"Refresh"})]}),r.jsx(WX,{}),r.jsxs("a",{"aria-label":"Open NoMoreIDE documentation",className:Bh(),href:"https://www.nomoreide.com/docs",rel:"noreferrer",target:"_blank",title:"Open NoMoreIDE documentation",children:[r.jsx("span",{className:Ih(),children:r.jsx(GA,{})}),r.jsx("span",{className:Ph(),children:"Docs"})]}),n?r.jsx(I$,{data:n}):null]})]})]}),n?r.jsx(BW,{data:n,onOpenService:z=>{u(z),s("services"),A({silent:!0})}}):null,g&&!n?r.jsx(tt,{variant:"muted",children:"Loading NoMoreIDE state..."}):null,r.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[n&&t==="services"?r.jsx(OW,{data:n,onRefresh:A,focusService:l,onServiceFocused:()=>u(null)}):null,n&&t==="git"?r.jsx(rX,{data:n,onRefresh:()=>{A({silent:!0})}}):null,t==="github"?r.jsx(IX,{},P):null,t==="agent"?r.jsx(h$,{}):null,t==="errors"?r.jsx(uF,{}):null,t==="database"?r.jsx(iF,{staged:h,onStageConsumed:()=>m(null)}):null,t==="terminal"?r.jsx(FW,{}):null]})]})]}),n&&t==="git"?r.jsx(qX,{ahead:n.git.status?.ahead??0,behind:n.git.status?.behind??0,branches:n.git.branches,currentBranch:n.git.status?.branch||void 0,disabled:!n.git.status,onRefresh:A,upstream:n.git.status?.upstream}):null,r.jsx(yU,{git:n?.git,onGitRefresh:()=>{A({silent:!0})},onOpenAgentPage:t==="agent"?void 0:()=>s("agent"),onOpenService:z=>{u(z),s("services"),A({silent:!0})},onOpenSqlConsole:(z,I)=>{m(M=>({connection:z,sql:I,nonce:(M?.nonce??0)+1})),s("database")}})]})]})})})})}function qa({active:e,badge:t,docked:s,icon:n,label:o,onClick:l}){const u=t!==void 0&&t>0;return r.jsxs(J,{"aria-label":o,title:o,className:XX(e,s),variant:"ghost",onClick:l,type:"button",children:[r.jsx("span",{className:QX(s),children:n}),r.jsx("span",{className:ZX(s,u),children:o}),t!==void 0&&t>0?r.jsx(et,{appearance:t>0?"solid":"outline",className:de("min-w-6 justify-center px-1.5 font-mono shadow-none",e?"border-primary-foreground/40 bg-primary-foreground/15 text-primary-foreground dark:border-primary-foreground/40 dark:bg-primary-foreground/15 dark:text-primary-foreground":t>0?"":"border-border bg-background text-muted-foreground","absolute right-1.5 top-1.5 h-4 min-w-4 rounded-full px-1 text-[10px] leading-none shadow-none group-hover/sidebar:right-2 group-hover/sidebar:top-1/2 group-hover/sidebar:-translate-y-1/2 group-hover/sidebar:text-xs",s&&"right-2 top-1/2 -translate-y-1/2 text-xs"),size:"small",variant:t>0?"success":"outline",children:t}):null]})}fN.createRoot(document.getElementById("root")).render(r.jsx(y.StrictMode,{children:r.jsx(tZ,{})}));export{r as j,y as r};
|