claudedesk 3.8.5 → 3.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/assets/{index-Bf6T9D-F.js → index-DeLzq_MS.js} +2 -1
- package/dist/client/index.html +1 -1
- package/dist/config/settings.d.ts +15 -0
- package/dist/config/settings.d.ts.map +1 -1
- package/dist/config/settings.js +12 -3
- package/dist/config/settings.js.map +1 -1
- package/dist/core/context-manager.d.ts +8 -1
- package/dist/core/context-manager.d.ts.map +1 -1
- package/dist/core/context-manager.js +60 -13
- package/dist/core/context-manager.js.map +1 -1
- package/dist/core/token-estimator.d.ts +66 -0
- package/dist/core/token-estimator.d.ts.map +1 -0
- package/dist/core/token-estimator.js +231 -0
- package/dist/core/token-estimator.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -7787,7 +7787,8 @@ Error generating stack: `+s.message+`
|
|
|
7787
7787
|
`,...s.current()});return/^[\t ]/.test(d)&&(d=uh(d.charCodeAt(0))+d.slice(1)),d=d?o+" "+d:o,n.options.closeAtx&&(d+=" "+o),c(),l(),d}oK.peek=Kpe;function oK(e){return e.value||""}function Kpe(){return"<"}lK.peek=Ype;function lK(e,t,n,r){const i=h_(n),s=i==='"'?"Quote":"Apostrophe",o=n.enter("image");let l=n.enter("label");const c=n.createTracker(r);let d=c.move("![");return d+=c.move(n.safe(e.alt,{before:d,after:"]",...c.current()})),d+=c.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=n.enter("destinationLiteral"),d+=c.move("<"),d+=c.move(n.safe(e.url,{before:d,after:">",...c.current()})),d+=c.move(">")):(l=n.enter("destinationRaw"),d+=c.move(n.safe(e.url,{before:d,after:e.title?" ":")",...c.current()}))),l(),e.title&&(l=n.enter(`title${s}`),d+=c.move(" "+i),d+=c.move(n.safe(e.title,{before:d,after:i,...c.current()})),d+=c.move(i),l()),d+=c.move(")"),o(),d}function Ype(){return"!"}cK.peek=Xpe;function cK(e,t,n,r){const i=e.referenceType,s=n.enter("imageReference");let o=n.enter("label");const l=n.createTracker(r);let c=l.move("![");const d=n.safe(e.alt,{before:c,after:"]",...l.current()});c+=l.move(d+"]["),o();const p=n.stack;n.stack=[],o=n.enter("reference");const h=n.safe(n.associationId(e),{before:c,after:"]",...l.current()});return o(),n.stack=p,s(),i==="full"||!d||d!==h?c+=l.move(h+"]"):i==="shortcut"?c=c.slice(0,-1):c+=l.move("]"),c}function Xpe(){return"!"}dK.peek=Qpe;function dK(e,t,n){let r=e.value||"",i="`",s=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++s<n.unsafe.length;){const o=n.unsafe[s],l=n.compilePattern(o);let c;if(o.atBreak)for(;c=l.exec(r);){let d=c.index;r.charCodeAt(d)===10&&r.charCodeAt(d-1)===13&&d--,r=r.slice(0,d)+" "+r.slice(c.index+1)}}return i+r+i}function Qpe(){return"`"}function uK(e,t){const n=i_(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}pK.peek=Jpe;function pK(e,t,n,r){const i=h_(n),s=i==='"'?"Quote":"Apostrophe",o=n.createTracker(r);let l,c;if(uK(e,n)){const p=n.stack;n.stack=[],l=n.enter("autolink");let h=o.move("<");return h+=o.move(n.containerPhrasing(e,{before:h,after:">",...o.current()})),h+=o.move(">"),l(),n.stack=p,h}l=n.enter("link"),c=n.enter("label");let d=o.move("[");return d+=o.move(n.containerPhrasing(e,{before:d,after:"](",...o.current()})),d+=o.move("]("),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=n.enter("destinationLiteral"),d+=o.move("<"),d+=o.move(n.safe(e.url,{before:d,after:">",...o.current()})),d+=o.move(">")):(c=n.enter("destinationRaw"),d+=o.move(n.safe(e.url,{before:d,after:e.title?" ":")",...o.current()}))),c(),e.title&&(c=n.enter(`title${s}`),d+=o.move(" "+i),d+=o.move(n.safe(e.title,{before:d,after:i,...o.current()})),d+=o.move(i),c()),d+=o.move(")"),l(),d}function Jpe(e,t,n){return uK(e,n)?"<":"["}hK.peek=ehe;function hK(e,t,n,r){const i=e.referenceType,s=n.enter("linkReference");let o=n.enter("label");const l=n.createTracker(r);let c=l.move("[");const d=n.containerPhrasing(e,{before:c,after:"]",...l.current()});c+=l.move(d+"]["),o();const p=n.stack;n.stack=[],o=n.enter("reference");const h=n.safe(n.associationId(e),{before:c,after:"]",...l.current()});return o(),n.stack=p,s(),i==="full"||!d||d!==h?c+=l.move(h+"]"):i==="shortcut"?c=c.slice(0,-1):c+=l.move("]"),c}function ehe(){return"["}function m_(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function the(e){const t=m_(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function nhe(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function mK(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function ahe(e,t,n,r){const i=n.enter("list"),s=n.bulletCurrent;let o=e.ordered?nhe(n):m_(n);const l=e.ordered?o==="."?")":".":the(n);let c=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){const p=e.children?e.children[0]:void 0;if((o==="*"||o==="-")&&p&&(!p.children||!p.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(c=!0),mK(n)===o&&p){let h=-1;for(;++h<e.children.length;){const m=e.children[h];if(m&&m.type==="listItem"&&m.children&&m.children[0]&&m.children[0].type==="thematicBreak"){c=!0;break}}}}c&&(o=l),n.bulletCurrent=o;const d=n.containerFlow(e,r);return n.bulletLastUsed=o,n.bulletCurrent=s,i(),d}function rhe(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function ihe(e,t,n,r){const i=rhe(n);let s=n.bulletCurrent||m_(n);t&&t.type==="list"&&t.ordered&&(s=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+s);let o=s.length+1;(i==="tab"||i==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);const l=n.createTracker(r);l.move(s+" ".repeat(o-s.length)),l.shift(o);const c=n.enter("listItem"),d=n.indentLines(n.containerFlow(e,l.current()),p);return c(),d;function p(h,m,g){return m?(g?"":" ".repeat(o))+h:(g?s:s+" ".repeat(o-s.length))+h}}function she(e,t,n,r){const i=n.enter("paragraph"),s=n.enter("phrasing"),o=n.containerPhrasing(e,r);return s(),i(),o}const ohe=Pj(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function lhe(e,t,n,r){return(e.children.some(function(o){return ohe(o)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function che(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}fK.peek=dhe;function fK(e,t,n,r){const i=che(n),s=n.enter("strong"),o=n.createTracker(r),l=o.move(i+i);let c=o.move(n.containerPhrasing(e,{after:i,before:l,...o.current()}));const d=c.charCodeAt(0),p=aj(r.before.charCodeAt(r.before.length-1),d,i);p.inside&&(c=uh(d)+c.slice(1));const h=c.charCodeAt(c.length-1),m=aj(r.after.charCodeAt(0),h,i);m.inside&&(c=c.slice(0,-1)+uh(h));const g=o.move(i+i);return s(),n.attentionEncodeSurroundingInfo={after:m.outside,before:p.outside},l+c+g}function dhe(e,t,n){return n.options.strong||"*"}function uhe(e,t,n,r){return n.safe(e.value,r)}function phe(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function hhe(e,t,n){const r=(mK(n)+(n.options.ruleSpaces?" ":"")).repeat(phe(n));return n.options.ruleSpaces?r.slice(0,-1):r}const gK={blockquote:Ope,break:dq,code:Hpe,definition:Vpe,emphasis:sK,hardBreak:dq,heading:Zpe,html:oK,image:lK,imageReference:cK,inlineCode:dK,link:pK,linkReference:hK,list:ahe,listItem:ihe,paragraph:she,root:lhe,strong:fK,text:uhe,thematicBreak:hhe};function mhe(){return{enter:{table:fhe,tableData:uq,tableHeader:uq,tableRow:yhe},exit:{codeText:xhe,table:ghe,tableData:kT,tableHeader:kT,tableRow:kT}}}function fhe(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function ghe(e){this.exit(e),this.data.inTable=void 0}function yhe(e){this.enter({type:"tableRow",children:[]},e)}function kT(e){this.exit(e)}function uq(e){this.enter({type:"tableCell",children:[]},e)}function xhe(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,bhe));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function bhe(e,t){return t==="|"?t:e}function khe(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,s=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
7788
7788
|
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:m,table:o,tableCell:c,tableRow:l}};function o(g,x,k,w){return d(p(g,k,w),g.align)}function l(g,x,k,w){const y=h(g,k,w),b=d([y]);return b.slice(0,b.indexOf(`
|
|
7789
7789
|
`))}function c(g,x,k,w){const y=k.enter("tableCell"),b=k.enter("phrasing"),v=k.containerPhrasing(g,{...w,before:s,after:s});return b(),y(),v}function d(g,x){return _pe(g,{align:x,alignDelimiters:r,padding:n,stringLength:i})}function p(g,x,k){const w=g.children;let y=-1;const b=[],v=x.enter("table");for(;++y<w.length;)b[y]=h(w[y],x,k);return v(),b}function h(g,x,k){const w=g.children;let y=-1;const b=[],v=x.enter("tableRow");for(;++y<w.length;)b[y]=c(w[y],g,x,k);return v(),b}function m(g,x,k){let w=gK.inlineCode(g,x,k);return k.stack.includes("tableCell")&&(w=w.replace(/\|/g,"\\$&")),w}}function whe(){return{exit:{taskListCheckValueChecked:pq,taskListCheckValueUnchecked:pq,paragraph:She}}}function vhe(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:Nhe}}}function pq(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function She(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,o;for(;++s<i.length;){const l=i[s];if(l.type==="paragraph"){o=l;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function Nhe(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",l=n.createTracker(r);s&&l.move(o);let c=gK.listItem(e,t,n,{...r,...l.current()});return s&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,d)),c;function d(p){return p+o}}function Che(){return[ape(),Npe(),Ipe(),mhe(),whe()]}function Ehe(e){return{extensions:[rpe(),Cpe(e),Ape(),khe(e),vhe()]}}const Mhe={tokenize:Rhe,partial:!0},yK={tokenize:_he,partial:!0},xK={tokenize:Dhe,partial:!0},bK={tokenize:Ohe,partial:!0},Ihe={tokenize:Phe,partial:!0},kK={name:"wwwAutolink",tokenize:Lhe,previous:vK},wK={name:"protocolAutolink",tokenize:The,previous:SK},fr={name:"emailAutolink",tokenize:jhe,previous:NK},Pa={};function Ahe(){return{text:Pa}}let fi=48;for(;fi<123;)Pa[fi]=fr,fi++,fi===58?fi=65:fi===91&&(fi=97);Pa[43]=fr;Pa[45]=fr;Pa[46]=fr;Pa[95]=fr;Pa[72]=[fr,wK];Pa[104]=[fr,wK];Pa[87]=[fr,kK];Pa[119]=[fr,kK];function jhe(e,t,n){const r=this;let i,s;return o;function o(h){return!cR(h)||!NK.call(r,r.previous)||f_(r.events)?n(h):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(h))}function l(h){return cR(h)?(e.consume(h),l):h===64?(e.consume(h),c):n(h)}function c(h){return h===46?e.check(Ihe,p,d)(h):h===45||h===95||Wt(h)?(s=!0,e.consume(h),c):p(h)}function d(h){return e.consume(h),i=!0,c}function p(h){return s&&i&&an(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(h)):n(h)}}function Lhe(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!vK.call(r,r.previous)||f_(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Mhe,e.attempt(yK,e.attempt(xK,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function The(e,t,n){const r=this;let i="",s=!1;return o;function o(h){return(h===72||h===104)&&SK.call(r,r.previous)&&!f_(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(h),e.consume(h),l):n(h)}function l(h){if(an(h)&&i.length<5)return i+=String.fromCodePoint(h),e.consume(h),l;if(h===58){const m=i.toLowerCase();if(m==="http"||m==="https")return e.consume(h),c}return n(h)}function c(h){return h===47?(e.consume(h),s?d:(s=!0,c)):n(h)}function d(h){return h===null||ej(h)||Je(h)||ac(h)||_j(h)?n(h):e.attempt(yK,e.attempt(xK,p),n)(h)}function p(h){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(h)}}function Rhe(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),s):n(o)}function s(o){return o===null?n(o):t(o)}}function _he(e,t,n){let r,i,s;return o;function o(d){return d===46||d===95?e.check(bK,c,l)(d):d===null||Je(d)||ac(d)||d!==45&&_j(d)?c(d):(s=!0,e.consume(d),o)}function l(d){return d===95?r=!0:(i=r,r=void 0),e.consume(d),o}function c(d){return i||r||!s?n(d):t(d)}}function Dhe(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?s(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(bK,t,s)(o):o===null||Je(o)||ac(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function Ohe(e,t,n){return r;function r(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),r):l===38?(e.consume(l),s):l===93?(e.consume(l),i):l===60||l===null||Je(l)||ac(l)?t(l):n(l)}function i(l){return l===null||l===40||l===91||Je(l)||ac(l)?t(l):r(l)}function s(l){return an(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),r):an(l)?(e.consume(l),o):n(l)}}function Phe(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return Wt(s)?n(s):t(s)}}function vK(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Je(e)}function SK(e){return!an(e)}function NK(e){return!(e===47||cR(e))}function cR(e){return e===43||e===45||e===46||e===95||Wt(e)}function f_(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const zhe={tokenize:Ghe,partial:!0};function Fhe(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:qhe,continuation:{tokenize:Vhe},exit:$he}},text:{91:{name:"gfmFootnoteCall",tokenize:Hhe},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Bhe,resolveTo:Uhe}}}}function Bhe(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const c=r.events[i][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const d=xa(r.sliceSerialize({start:o.end,end:r.now()}));return d.codePointAt(0)!==94||!s.includes(d.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function Uhe(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},l=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...l),e}function Hhe(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,o;return l;function l(h){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(h),e.exit("gfmFootnoteCallLabelMarker"),c}function c(h){return h!==94?n(h):(e.enter("gfmFootnoteCallMarker"),e.consume(h),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",d)}function d(h){if(s>999||h===93&&!o||h===null||h===91||Je(h))return n(h);if(h===93){e.exit("chunkString");const m=e.exit("gfmFootnoteCallString");return i.includes(xa(r.sliceSerialize(m)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(h),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(h)}return Je(h)||(o=!0),s++,e.consume(h),h===92?p:d}function p(h){return h===91||h===92||h===93?(e.consume(h),s++,d):d(h)}}function qhe(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,o=0,l;return c;function c(x){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(x),e.exit("gfmFootnoteDefinitionLabelMarker"),d}function d(x){return x===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(x),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",p):n(x)}function p(x){if(o>999||x===93&&!l||x===null||x===91||Je(x))return n(x);if(x===93){e.exit("chunkString");const k=e.exit("gfmFootnoteDefinitionLabelString");return s=xa(r.sliceSerialize(k)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(x),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),m}return Je(x)||(l=!0),o++,e.consume(x),x===92?h:p}function h(x){return x===91||x===92||x===93?(e.consume(x),o++,p):p(x)}function m(x){return x===58?(e.enter("definitionMarker"),e.consume(x),e.exit("definitionMarker"),i.includes(s)||i.push(s),qe(e,g,"gfmFootnoteDefinitionWhitespace")):n(x)}function g(x){return t(x)}}function Vhe(e,t,n){return e.check(Nh,t,e.attempt(zhe,t,n))}function $he(e){e.exit("gfmFootnoteDefinition")}function Ghe(e,t,n){const r=this;return qe(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(s):n(s)}}function Whe(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(o,l){let c=-1;for(;++c<o.length;)if(o[c][0]==="enter"&&o[c][1].type==="strikethroughSequenceTemporary"&&o[c][1]._close){let d=c;for(;d--;)if(o[d][0]==="exit"&&o[d][1].type==="strikethroughSequenceTemporary"&&o[d][1]._open&&o[c][1].end.offset-o[c][1].start.offset===o[d][1].end.offset-o[d][1].start.offset){o[c][1].type="strikethroughSequence",o[d][1].type="strikethroughSequence";const p={type:"strikethrough",start:Object.assign({},o[d][1].start),end:Object.assign({},o[c][1].end)},h={type:"strikethroughText",start:Object.assign({},o[d][1].end),end:Object.assign({},o[c][1].start)},m=[["enter",p,l],["enter",o[d][1],l],["exit",o[d][1],l],["enter",h,l]],g=l.parser.constructs.insideSpan.null;g&&On(m,m.length,0,Dj(g,o.slice(d+1,c),l)),On(m,m.length,0,[["exit",h,l],["enter",o[c][1],l],["exit",o[c][1],l],["exit",p,l]]),On(o,d-1,c-d+3,m),c=d+m.length-2;break}}for(c=-1;++c<o.length;)o[c][1].type==="strikethroughSequenceTemporary"&&(o[c][1].type="data");return o}function s(o,l,c){const d=this.previous,p=this.events;let h=0;return m;function m(x){return d===126&&p[p.length-1][1].type!=="characterEscape"?c(x):(o.enter("strikethroughSequenceTemporary"),g(x))}function g(x){const k=_d(d);if(x===126)return h>1?c(x):(o.consume(x),h++,g);if(h<2&&!n)return c(x);const w=o.exit("strikethroughSequenceTemporary"),y=_d(x);return w._open=!y||y===2&&!!k,w._close=!k||k===2&&!!y,l(x)}}}class Zhe{constructor(){this.map=[]}add(t,n,r){Khe(this,t,n,r)}consume(t){if(this.map.sort(function(s,o){return s[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function Khe(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function Yhe(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function Xhe(){return{flow:{null:{name:"table",tokenize:Qhe,resolveAll:Jhe}}}}function Qhe(e,t,n){const r=this;let i=0,s=0,o;return l;function l(C){let O=r.events.length-1;for(;O>-1;){const G=r.events[O][1].type;if(G==="lineEnding"||G==="linePrefix")O--;else break}const L=O>-1?r.events[O][1].type:null,z=L==="tableHead"||L==="tableRow"?E:c;return z===E&&r.parser.lazy[r.now().line]?n(C):z(C)}function c(C){return e.enter("tableHead"),e.enter("tableRow"),d(C)}function d(C){return C===124||(o=!0,s+=1),p(C)}function p(C){return C===null?n(C):Me(C)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(C),e.exit("lineEnding"),g):n(C):ze(C)?qe(e,p,"whitespace")(C):(s+=1,o&&(o=!1,i+=1),C===124?(e.enter("tableCellDivider"),e.consume(C),e.exit("tableCellDivider"),o=!0,p):(e.enter("data"),h(C)))}function h(C){return C===null||C===124||Je(C)?(e.exit("data"),p(C)):(e.consume(C),C===92?m:h)}function m(C){return C===92||C===124?(e.consume(C),h):h(C)}function g(C){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(C):(e.enter("tableDelimiterRow"),o=!1,ze(C)?qe(e,x,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(C):x(C))}function x(C){return C===45||C===58?w(C):C===124?(o=!0,e.enter("tableCellDivider"),e.consume(C),e.exit("tableCellDivider"),k):N(C)}function k(C){return ze(C)?qe(e,w,"whitespace")(C):w(C)}function w(C){return C===58?(s+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(C),e.exit("tableDelimiterMarker"),y):C===45?(s+=1,y(C)):C===null||Me(C)?S(C):N(C)}function y(C){return C===45?(e.enter("tableDelimiterFiller"),b(C)):N(C)}function b(C){return C===45?(e.consume(C),b):C===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(C),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(C))}function v(C){return ze(C)?qe(e,S,"whitespace")(C):S(C)}function S(C){return C===124?x(C):C===null||Me(C)?!o||i!==s?N(C):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(C)):N(C)}function N(C){return n(C)}function E(C){return e.enter("tableRow"),M(C)}function M(C){return C===124?(e.enter("tableCellDivider"),e.consume(C),e.exit("tableCellDivider"),M):C===null||Me(C)?(e.exit("tableRow"),t(C)):ze(C)?qe(e,M,"whitespace")(C):(e.enter("data"),j(C))}function j(C){return C===null||C===124||Je(C)?(e.exit("data"),M(C)):(e.consume(C),C===92?_:j)}function _(C){return C===92||C===124?(e.consume(C),j):j(C)}}function Jhe(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],o=[0,0,0,0],l=!1,c=0,d,p,h;const m=new Zhe;for(;++n<e.length;){const g=e[n],x=g[1];g[0]==="enter"?x.type==="tableHead"?(l=!1,c!==0&&(hq(m,t,c,d,p),p=void 0,c=0),d={type:"table",start:Object.assign({},x.start),end:Object.assign({},x.end)},m.add(n,0,[["enter",d,t]])):x.type==="tableRow"||x.type==="tableDelimiterRow"?(r=!0,h=void 0,s=[0,0,0,0],o=[0,n+1,0,0],l&&(l=!1,p={type:"tableBody",start:Object.assign({},x.start),end:Object.assign({},x.end)},m.add(n,0,[["enter",p,t]])),i=x.type==="tableDelimiterRow"?2:p?3:1):i&&(x.type==="data"||x.type==="tableDelimiterMarker"||x.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(s[1]!==0&&(o[0]=o[1],h=h1(m,t,s,i,void 0,h),s=[0,0,0,0]),o[2]=n)):x.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(o[0]=o[1],h=h1(m,t,s,i,void 0,h)),s=o,o=[s[1],n,0,0])):x.type==="tableHead"?(l=!0,c=n):x.type==="tableRow"||x.type==="tableDelimiterRow"?(c=n,s[1]!==0?(o[0]=o[1],h=h1(m,t,s,i,n,h)):o[1]!==0&&(h=h1(m,t,o,i,n,h)),i=0):i&&(x.type==="data"||x.type==="tableDelimiterMarker"||x.type==="tableDelimiterFiller")&&(o[3]=n)}for(c!==0&&hq(m,t,c,d,p),m.consume(t.events),n=-1;++n<t.events.length;){const g=t.events[n];g[0]==="enter"&&g[1].type==="table"&&(g[1]._align=Yhe(t.events,n))}return e}function h1(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",l="tableContent";n[0]!==0&&(s.end=Object.assign({},xc(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const c=xc(t.events,n[1]);if(s={type:o,start:Object.assign({},c),end:Object.assign({},c)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const d=xc(t.events,n[2]),p=xc(t.events,n[3]),h={type:l,start:Object.assign({},d),end:Object.assign({},p)};if(e.add(n[2],0,[["enter",h,t]]),r!==2){const m=t.events[n[2]],g=t.events[n[3]];if(m[1].end=Object.assign({},g[1].end),m[1].type="chunkText",m[1].contentType="text",n[3]>n[2]+1){const x=n[2]+1,k=n[3]-n[2]-1;e.add(x,k,[])}}e.add(n[3]+1,0,[["exit",h,t]])}return i!==void 0&&(s.end=Object.assign({},xc(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function hq(e,t,n,r,i){const s=[],o=xc(t.events,n);i&&(i.end=Object.assign({},o),s.push(["exit",i,t])),r.end=Object.assign({},o),s.push(["exit",r,t]),e.add(n+1,0,s)}function xc(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const e1e={name:"tasklistCheck",tokenize:n1e};function t1e(){return{text:{91:e1e}}}function n1e(e,t,n){const r=this;return i;function i(c){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(c):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),s)}function s(c){return Je(c)?(e.enter("taskListCheckValueUnchecked"),e.consume(c),e.exit("taskListCheckValueUnchecked"),o):c===88||c===120?(e.enter("taskListCheckValueChecked"),e.consume(c),e.exit("taskListCheckValueChecked"),o):n(c)}function o(c){return c===93?(e.enter("taskListCheckMarker"),e.consume(c),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),l):n(c)}function l(c){return Me(c)?t(c):ze(c)?e.check({tokenize:a1e},t,n)(c):n(c)}}function a1e(e,t,n){return qe(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function r1e(e){return RZ([Ahe(),Fhe(),Whe(e),Xhe(),t1e()])}const i1e={};function dR(e){const t=this,n=e||i1e,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(r1e(n)),s.push(Che()),o.push(Ehe(n))}function mq({message:e}){const[t,n]=f.useState(!1),r=e.role==="user",i=e.timestamp?new Date(e.timestamp).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):"";return a.jsxs("div",{className:A("flex gap-3.5 py-4",r?"justify-end":""),onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),children:[!r&&a.jsx("div",{className:"flex-shrink-0 mt-1",children:a.jsxs("div",{className:"relative h-9 w-9 rounded-xl bg-gradient-to-br from-purple-500/20 to-violet-600/20 ring-2 ring-purple-500/30 flex items-center justify-center",children:[a.jsx(xn,{className:"h-4.5 w-4.5 text-purple-400"}),e.isStreaming&&a.jsx("span",{className:"absolute -top-0.5 -right-0.5 h-2.5 w-2.5 rounded-full bg-purple-400 animate-pulse ring-2 ring-[#0a0d14]"})]})}),a.jsxs("div",{className:"flex flex-col gap-1.5 max-w-[90%] sm:max-w-[85%]",children:[a.jsx(q.div,{initial:{opacity:0,y:-4},animate:{opacity:t?1:0,y:t?0:-4},transition:{duration:.2},className:A("text-[10px] text-white/30 px-1",r?"text-right":"text-left"),children:i}),a.jsx("div",{className:A("group relative rounded-2xl px-5 py-3.5 transition-all duration-200","ring-1",r?"bg-gradient-to-br from-purple-500/15 via-purple-500/10 to-purple-600/15 text-white/90 ring-purple-500/20 hover:ring-purple-500/30 hover:shadow-lg hover:shadow-purple-500/10":"bg-gradient-to-br from-white/[0.04] via-white/[0.03] to-white/[0.02] text-white/80 ring-white/[0.06] hover:ring-white/[0.09] hover:shadow-lg hover:shadow-black/20"),"aria-busy":e.isStreaming,"aria-label":`${r?"You":"Claude"} said: ${e.content}${i?` at ${i}`:""}`,children:e.isStreaming&&!e.content?a.jsxs("div",{className:"flex items-center gap-2 text-purple-300/70",children:[a.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-purple-400 animate-pulse"}),a.jsx("span",{className:"text-xs",children:"Thinking..."})]}):a.jsxs("div",{className:"prose prose-invert max-w-none text-[15px] lg:text-[15.5px] leading-[1.7]",children:[a.jsx(oR,{remarkPlugins:[lR,dR],components:{h1:({children:s})=>a.jsx("h1",{className:"text-2xl font-bold text-white mt-6 mb-4 first:mt-0",children:s}),h2:({children:s})=>a.jsx("h2",{className:"text-xl font-bold text-white mt-5 mb-3 first:mt-0",children:s}),h3:({children:s})=>a.jsx("h3",{className:"text-lg font-semibold text-white/90 mt-4 mb-2 first:mt-0",children:s}),h4:({children:s})=>a.jsx("h4",{className:"text-base font-semibold text-white/90 mt-3 mb-2 first:mt-0",children:s}),code:({inline:s,className:o,children:l,...c})=>{const d=/language-(\w+)/.exec(o||""),p=d?d[1]:"";return s?a.jsx("code",{className:"px-1.5 py-0.5 rounded-md bg-purple-500/10 text-purple-200 ring-1 ring-purple-500/20 font-mono text-[13.5px]",...c,children:l}):a.jsxs("div",{className:"relative my-4 first:mt-0 last:mb-0",children:[p&&a.jsx("div",{className:"absolute top-3 right-3 px-2 py-1 rounded-md bg-white/5 text-white/40 text-[10px] font-mono uppercase tracking-wide",children:p}),a.jsx("pre",{className:"bg-[#0d1117] rounded-xl p-4 overflow-x-auto ring-1 ring-white/10",children:a.jsx("code",{className:"text-[13.5px] font-mono text-white/90",...c,children:l})})]})},a:({href:s,children:o})=>a.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300 underline decoration-blue-400/30 hover:decoration-blue-300/50 transition-colors",children:o}),blockquote:({children:s})=>a.jsx("blockquote",{className:"border-l-2 border-purple-500/50 pl-4 py-1 my-4 italic text-white/70 first:mt-0 last:mb-0",children:s}),ul:({children:s})=>a.jsx("ul",{className:"space-y-2 my-4 pl-6 list-disc marker:text-purple-400/50 first:mt-0 last:mb-0",children:s}),ol:({children:s})=>a.jsx("ol",{className:"space-y-2 my-4 pl-6 list-decimal marker:text-purple-400/50 first:mt-0 last:mb-0",children:s}),li:({children:s})=>a.jsx("li",{className:"text-white/80 pl-1",children:s}),table:({children:s})=>a.jsx("div",{className:"my-4 overflow-x-auto first:mt-0 last:mb-0",children:a.jsx("table",{className:"min-w-full border-collapse rounded-lg overflow-hidden ring-1 ring-white/10",children:s})}),thead:({children:s})=>a.jsx("thead",{className:"bg-white/5",children:s}),th:({children:s})=>a.jsx("th",{className:"px-4 py-2 text-left text-sm font-semibold text-white/90 border-b border-white/10",children:s}),td:({children:s})=>a.jsx("td",{className:"px-4 py-2 text-sm text-white/80 border-b border-white/5",children:s}),p:({children:s})=>a.jsx("p",{className:"my-3 first:mt-0 last:mb-0 text-white/80",children:s}),strong:({children:s})=>a.jsx("strong",{className:"font-semibold text-white/95",children:s}),em:({children:s})=>a.jsx("em",{className:"italic text-white/85",children:s})},children:e.content}),e.isStreaming&&a.jsx("span",{className:"inline-block w-1.5 h-4 bg-purple-400/70 ml-0.5 align-middle rounded-sm animate-pulse"})]})})]}),r&&a.jsx("div",{className:"flex-shrink-0 mt-1",children:a.jsx("div",{className:"h-9 w-9 rounded-xl bg-gradient-to-br from-white/15 to-white/10 ring-1 ring-white/20 flex items-center justify-center",children:a.jsx(nn,{className:"h-4 w-4 text-white/70"})})})]})}const Xl=mr((e,t)=>({info:null,isChecking:!1,checkError:null,isUpdating:!1,updateStage:null,updateDetail:null,updateError:null,updateSuccess:!1,bannerDismissedVersion:null,checkForUpdate:async()=>{e({isChecking:!0,checkError:null});try{const n=await F("GET","/system/update/check");e({info:n,isChecking:!1})}catch(n){e({checkError:n instanceof Error?n.message:"Check failed",isChecking:!1})}},fetchUpdateInfo:async()=>{try{const n=await F("GET","/system/update/info");e({info:n})}catch{}},triggerUpdate:async()=>{e({isUpdating:!0,updateError:null,updateSuccess:!1,updateStage:null});try{const n=await F("POST","/system/update");return n.status==="manual"?(e({isUpdating:!1}),{status:"manual",instructions:n.instructions}):{status:n.status}}catch(n){const r=n instanceof Error?n.message:"Update failed";return e({updateError:r,isUpdating:!1}),{status:"error",instructions:r}}},dismissBanner:()=>{const n=t().info;n!=null&&n.latestVersion&&e({bannerDismissedVersion:n.latestVersion})},setUpdateProgress:(n,r)=>{e({updateStage:n,updateDetail:r||null,isUpdating:!0})},setUpdateComplete:(n,r)=>{if(e({updateSuccess:n,updateError:r||null,updateStage:null,isUpdating:!1}),n){let i=0;const s=setInterval(async()=>{if(i++,i>30){clearInterval(s);return}try{(await fetch("/api/health")).ok&&(clearInterval(s),setTimeout(()=>window.location.reload(),1500))}catch{}},2e3)}},setUpdateAvailable:(n,r)=>{e(i=>{var s,o;return{info:{updateAvailable:!0,currentVersion:n,latestVersion:r,checkedAt:new Date().toISOString(),installMethod:((s=i.info)==null?void 0:s.installMethod)||"unknown",canAutoUpdate:((o=i.info)==null?void 0:o.canAutoUpdate)||!1}}})},reset:()=>{e({isUpdating:!1,updateStage:null,updateDetail:null,updateError:null,updateSuccess:!1})}})),uR="claudedesk-active-session",s1e=()=>{try{return localStorage.getItem(uR)}catch{return null}},Nu=e=>{try{e?localStorage.setItem(uR,e):localStorage.removeItem(uR)}catch{}},ri=mr((e,t)=>({sessions:[],activeSessionId:null,isConnected:!1,ws:null,pendingAttachments:new Map,searchResults:[],isSearching:!1,isLoadingSessions:!1,pendingMCPApproval:null,showPreviewPanel:!1,showStartAppModal:!1,loadSessions:async n=>{if(!(t().isLoadingSessions&&!(n!=null&&n.forceRefresh))){e({isLoadingSessions:!0});try{const i=(await Vc.fetch($c.TERMINAL_SESSIONS,()=>F("GET","/terminal/sessions"),{staleTime:3e4,forceRefresh:n==null?void 0:n.forceRefresh})).map(l=>({...l,createdAt:new Date(l.createdAt),lastActivityAt:new Date(l.lastActivityAt),bookmarkedAt:l.bookmarkedAt?new Date(l.bookmarkedAt):void 0,isBookmarked:l.isBookmarked??!1,messages:l.messages||[],messageQueue:(l.messageQueue||[]).map(c=>({...c,queuedAt:new Date(c.queuedAt)}))})),s=t().activeSessionId;let o=s;if(!s){const l=s1e();l&&i.some(c=>c.id===l)?o=l:i.length>0&&(o=i[0].id,Nu(o))}e({isLoadingSessions:!1,sessions:i,activeSessionId:o})}catch(r){console.error("Failed to load terminal sessions:",r),e({isLoadingSessions:!1})}}},createSession:async(n,r)=>{const{handoffSummary:i,...s}=r||{},o={...Array.isArray(n)?{repoIds:n}:{repoId:n},...s,...i?{handoffSummary:i}:{}},l=await F("POST","/terminal/sessions",o),c={...l,createdAt:new Date(l.createdAt),lastActivityAt:new Date(l.lastActivityAt),bookmarkedAt:l.bookmarkedAt?new Date(l.bookmarkedAt):void 0,isBookmarked:l.isBookmarked??!1,messages:l.messages||[],messageQueue:l.messageQueue||[]};e(p=>({sessions:[c,...p.sessions],activeSessionId:c.id})),Nu(c.id);const{ws:d}=t();return d&&d.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"subscribe",sessionId:c.id})),c},mergeSessions:async n=>{const r=await F("POST","/terminal/sessions/merge",{sessionIds:n}),i={...r,createdAt:new Date(r.createdAt),lastActivityAt:new Date(r.lastActivityAt),messages:r.messages||[],messageQueue:r.messageQueue||[]};e(o=>({sessions:[i,...o.sessions.filter(l=>!n.includes(l.id))],activeSessionId:i.id})),Nu(i.id);const{ws:s}=t();if(s&&s.readyState===WebSocket.OPEN){for(const o of n)s.send(JSON.stringify({type:"unsubscribe",sessionId:o}));s.send(JSON.stringify({type:"subscribe",sessionId:i.id}))}return i},addRepoToSession:async(n,r)=>{const i=await F("POST",`/terminal/sessions/${n}/add-repo`,{repoId:r});t().updateSession(n,{repoIds:i.repoIds,repoId:i.repoIds[0],isMultiRepo:i.isMultiRepo})},removeRepoFromSession:async(n,r)=>{const i=await F("POST",`/terminal/sessions/${n}/remove-repo`,{repoId:r});t().updateSession(n,{repoIds:i.repoIds,repoId:i.repoIds[0],isMultiRepo:i.isMultiRepo})},switchSession:n=>{const{ws:r,activeSessionId:i}=t();r&&r.readyState===WebSocket.OPEN&&i&&r.send(JSON.stringify({type:"unsubscribe",sessionId:i})),e({activeSessionId:n}),Nu(n),r&&r.readyState===WebSocket.OPEN&&r.send(JSON.stringify({type:"subscribe",sessionId:n}))},sendMessage:(n,r,i,s)=>{const{ws:o,activeSessionId:l}=t();if(!o||o.readyState!==WebSocket.OPEN||!l){console.error("Cannot send message: not connected or no active session",{wsExists:!!o,wsReadyState:o==null?void 0:o.readyState,activeSessionId:l,WebSocketOPEN:WebSocket.OPEN});return}const c={type:"message",sessionId:l,content:n,attachments:r};s&&s.length>0?c.agentChain=s:i&&(c.agentId=i),o.send(JSON.stringify(c))},setMode:n=>{const{ws:r,activeSessionId:i}=t();!r||r.readyState!==WebSocket.OPEN||!i||(r.send(JSON.stringify({type:"set-mode",sessionId:i,mode:n})),t().updateSession(i,{mode:n}))},cancelOperation:()=>{const{ws:n,activeSessionId:r}=t();!n||n.readyState!==WebSocket.OPEN||!r||n.send(JSON.stringify({type:"cancel",sessionId:r}))},clearMessages:async()=>{const{activeSessionId:n}=t();n&&(await F("POST",`/terminal/sessions/${n}/clear`),t().updateSession(n,{messages:[]}))},closeSession:async(n,r,i)=>{const{ws:s,activeSessionId:o}=t();s&&s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({type:"unsubscribe",sessionId:n}));const l=new URLSearchParams;r!==void 0&&l.set("deleteBranch",String(r)),i!==void 0&&l.set("deleteWorktree",String(i));const c=l.toString(),d=`/terminal/sessions/${n}${c?`?${c}`:""}`,p=1e4;try{await Promise.race([F("DELETE",d),new Promise((h,m)=>setTimeout(()=>m(new Error("Session close timeout")),p))])}catch(h){console.error("[Terminal] Session close error:",h)}e(h=>{var x;const m=h.sessions.filter(k=>k.id!==n),g=n===o?((x=m[0])==null?void 0:x.id)||null:o;return n===o&&Nu(g),{sessions:m,activeSessionId:g}})},connect:()=>{const n=t().ws;n&&n.close();const i=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`,s=new WebSocket(i);e({ws:s}),s.onopen=()=>{console.log("[Terminal] WebSocket connected"),e({isConnected:!0});const{activeSessionId:o}=t();o&&s.send(JSON.stringify({type:"subscribe",sessionId:o}))},s.onclose=()=>{console.log("[Terminal] WebSocket disconnected"),e({isConnected:!1,ws:null}),setTimeout(()=>{const{ws:o}=t();o||t().connect()},3e3)},s.onerror=o=>{console.error("[Terminal] WebSocket error:",o)},s.onmessage=o=>{var l;try{const c=JSON.parse(o.data),{sessionId:d}=c;switch(c.type){case"connected":console.log("[Terminal] Connected with client ID:",c.clientId);break;case"session-state":d&&t().updateSession(d,{status:c.session.status,mode:c.session.mode,messages:c.session.messages.map(p=>({...p,timestamp:new Date(p.timestamp)})),messageQueue:(c.session.messageQueue||[]).map(p=>({...p,queuedAt:new Date(p.queuedAt)})),wasRecentlyStopped:c.session.wasRecentlyStopped,worktreeMode:c.session.worktreeMode,worktreePath:c.session.worktreePath,branch:c.session.branch,baseBranch:c.session.baseBranch,ownsWorktree:c.session.ownsWorktree});break;case"message":if(d&&c.message){const p={...c.message,timestamp:new Date(c.message.timestamp)};e(h=>{const m=h.sessions.find(x=>x.id===d);if(m&&m.messages.some(x=>x.id===p.id))return h;const g=p.role==="assistant"&&p.isStreaming;return{sessions:h.sessions.map(x=>x.id===d?{...x,messages:[...x.messages,p],...g?{toolActivities:[]}:{}}:x)}})}break;case"chunk":d&&c.messageId&&c.content&&t().appendChunk(d,c.messageId,c.content);break;case"status":d&&c.status&&(t().updateSession(d,{status:c.status}),c.status==="idle"&&(t().updateSession(d,{currentActivity:void 0}),Vc.invalidate($c.GIT_STATUS(d)),t().fetchGitStatus(d)));break;case"activity":if(d&&c.content){const p=c.content.trim();if(p&&!p.startsWith("[ClaudeInvoker]")){const h=p.split(`
|
|
7790
|
-
`).filter(g=>g.trim()),m=(l=h[h.length-1])==null?void 0:l.trim();m&&t().updateSession(d,{currentActivity:m})}}break;case"message-complete":d&&c.messageId&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,currentActivity:void 0,messages:h.messages.map(m=>m.id===c.messageId?{...m,isStreaming:!1}:m)}:h)}));break;case"file-change":d&&c.messageId&&c.change&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>m.id===c.messageId?{...m,fileChanges:[...(m.fileChanges||[]).filter(g=>g.filePath!==c.change.filePath),c.change]}:m)}:h)}));break;case"file-changes-complete":d&&c.messageId&&Array.isArray(c.fileChanges)&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>m.id===c.messageId?{...m,fileChanges:c.fileChanges}:m)}:h)}));break;case"mode-changed":d&&c.mode&&t().updateSession(d,{mode:c.mode});break;case"phase-changed":d&&c.phase&&console.log(`[Terminal] Phase changed to ${c.phase} for session ${d}`);break;case"workflow-blocked":d&&c.message&&console.warn("[Terminal] Workflow blocked:",c.message);break;case"bookmark-changed":d&&typeof c.isBookmarked=="boolean"&&t().updateSession(d,{isBookmarked:c.isBookmarked,bookmarkedAt:c.isBookmarked?new Date:void 0});break;case"cancelled":d&&t().updateSession(d,{status:"idle"});break;case"chain-segment-start":d&&c.messageId!=null&&c.segmentIndex!=null&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>{if(m.id!==c.messageId)return m;const g=[...m.chainSegments||[]];for(;g.length<=c.segmentIndex;)g.push({agentId:"",agentName:"",status:"pending",content:""});return g[c.segmentIndex]={agentId:c.agentId||"",agentName:c.agentName||c.agentId||"",status:"running",content:"",startedAt:new Date().toISOString()},{...m,agentId:c.agentId||m.agentId,agentName:c.agentName||c.agentId||m.agentName,chainSegments:g,chainStatus:"running"}})}:h)}));break;case"chain-segment-chunk":d&&c.messageId&&c.segmentIndex!=null&&c.content&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>{if(m.id!==c.messageId||!m.chainSegments)return m;const g=[...m.chainSegments];return g[c.segmentIndex]&&(g[c.segmentIndex]={...g[c.segmentIndex],content:g[c.segmentIndex].content+c.content}),{...m,chainSegments:g}})}:h)}));break;case"chain-segment-complete":d&&c.messageId&&c.segmentIndex!=null&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>{if(m.id!==c.messageId||!m.chainSegments)return m;const g=[...m.chainSegments];return g[c.segmentIndex]&&(g[c.segmentIndex]={...g[c.segmentIndex],status:"completed",completedAt:new Date().toISOString()}),{...m,chainSegments:g}})}:h)}));break;case"chain-segment-error":d&&c.messageId&&c.segmentIndex!=null&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>{if(m.id!==c.messageId||!m.chainSegments)return m;const g=[...m.chainSegments];return g[c.segmentIndex]&&(g[c.segmentIndex]={...g[c.segmentIndex],status:"failed",error:c.error||"Unknown error",completedAt:new Date().toISOString()}),{...m,chainSegments:g,chainStatus:"partial"}})}:h)}));break;case"chain-complete":d&&c.messageId&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>m.id!==c.messageId?m:{...m,isStreaming:!1,chainStatus:c.status||"completed"})}:h)}));break;case"messages-cleared":d&&t().updateSession(d,{messages:[]});break;case"tool-start":d&&c.activityId&&c.tool&&e(p=>{const h=p.sessions.find(k=>k.id===d),m=(h==null?void 0:h.toolActivities)||[];if(m.some(k=>k.tool===c.tool&&k.target===(c.target||"")&&k.status==="running"))return p;const x={id:c.activityId,tool:c.tool,target:c.target||"",status:"running",timestamp:new Date};return{sessions:p.sessions.map(k=>k.id===d?{...k,toolActivities:[...m,x].slice(-50)}:k)}});break;case"tool-complete":d&&c.activityId&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,toolActivities:(h.toolActivities||[]).map(m=>m.id===c.activityId?{...m,status:"complete",completedAt:new Date}:m)}:h)}));break;case"tool-error":d&&c.activityId&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,toolActivities:(h.toolActivities||[]).map(m=>m.id===c.activityId?{...m,status:"error",error:c.error,completedAt:new Date}:m)}:h)}));break;case"queue-updated":d&&Array.isArray(c.queue)&&t().updateSession(d,{messageQueue:c.queue.map(p=>({...p,queuedAt:new Date(p.queuedAt)}))});break;case"usage-update":d&&c.sessionStats&&t().updateSession(d,{usageStats:c.sessionStats,currentModel:c.model});break;case"context_state_update":d&&c.contextState&&t().updateSession(d,{contextState:c.contextState});break;case"context_split_suggested":d&&t().updateSession(d,{splitSuggested:!0});break;case"error":console.error("[Terminal] Error:",c.error),d&&t().updateSession(d,{status:"error"});break;case"mcp-tool-approval-needed":d&&c.approvalId&&e(p=>({pendingMCPApproval:{sessionId:d,approvalId:c.approvalId,toolName:c.toolName,serverName:c.serverName,serverId:c.serverId,description:c.description,inputParameters:c.inputParameters||{}}}));break;case"system:update-available":Xl.getState().setUpdateAvailable(c.currentVersion,c.latestVersion);break;case"system:update-starting":case"system:update-progress":c.stage&&Xl.getState().setUpdateProgress(c.stage,c.detail);break;case"system:update-complete":Xl.getState().setUpdateComplete(c.success,c.error);break}}catch(c){console.error("[Terminal] Failed to parse message:",c)}},e({ws:s})},disconnect:()=>{const{ws:n}=t();n&&(n.close(),e({ws:null,isConnected:!1}))},updateSession:(n,r)=>{e(i=>({sessions:i.sessions.map(s=>s.id===n?{...s,...r}:s)}))},appendChunk:(n,r,i)=>{e(s=>({sessions:s.sessions.map(o=>o.id!==n?o:{...o,messages:o.messages.map(l=>l.id!==r||i.length>10&&l.content.endsWith(i)||i.length>50&&l.content.length>0&&l.content.startsWith(i)||i.length>30&&l.content.includes(i)?l:{...l,content:l.content+i})})}))},fetchGitStatus:async n=>{try{const r=await Vc.fetch($c.GIT_STATUS(n),()=>F("GET",`/terminal/sessions/${n}/git-status`),{staleTime:5e3});t().updateSession(n,{gitStatus:r})}catch(r){console.error("Failed to fetch git status:",r)}},fetchContextState:async n=>{try{const r=await F("GET",`/terminal/sessions/${n}/context`);r&&t().updateSession(n,{contextState:r})}catch(r){console.error("Failed to fetch context state:",r)}},splitSession:async n=>{try{const r=await F("POST",`/terminal/sessions/${n}/context/split`);return r!=null&&r.id?(await t().loadSessions(),r.id):null}catch(r){return console.error("Failed to split session:",r),null}},fetchMultiGitStatus:async n=>{try{const r=await F("GET",`/terminal/sessions/${n}/multi-git-status`),i=t().sessions.find(s=>s.id===n);if(i&&i.repoIds.length>0){const s=r.repos[i.repoIds[0]];s&&t().updateSession(n,{gitStatus:s})}}catch(r){console.error("Failed to fetch multi-repo git status:",r)}},toggleBookmark:async n=>{const r=t().sessions.find(s=>s.id===n);if(!r)return;const i=!r.isBookmarked;t().updateSession(n,{isBookmarked:i,bookmarkedAt:i?new Date:void 0});try{await F("PATCH",`/terminal/sessions/${n}/bookmark`,{isBookmarked:i})}catch(s){t().updateSession(n,{isBookmarked:!i,bookmarkedAt:i?void 0:new Date}),console.error("Failed to toggle bookmark:",s)}},toggleMessageBookmark:(n,r)=>{e(i=>({sessions:i.sessions.map(s=>s.id===n?{...s,messages:s.messages.map(o=>o.id===r?{...o,isBookmarked:!o.isBookmarked}:o)}:s)}))},exportSession:(n,r)=>{const i=`/api/terminal/sessions/${n}/export?format=${r}`,s=document.createElement("a");s.href=i,s.download="",document.body.appendChild(s),s.click(),document.body.removeChild(s)},searchSessions:async n=>{if(!n.trim()){e({searchResults:[],isSearching:!1});return}e({isSearching:!0});try{const r=await F("GET",`/terminal/sessions/search?q=${encodeURIComponent(n)}`);e({searchResults:r.map(i=>({...i,timestamp:new Date(i.timestamp)})),isSearching:!1})}catch(r){console.error("Search failed:",r),e({searchResults:[],isSearching:!1})}},clearSearchResults:()=>{e({searchResults:[],isSearching:!1})},removeFromQueue:n=>{const{ws:r,activeSessionId:i}=t();!r||r.readyState!==WebSocket.OPEN||!i||r.send(JSON.stringify({type:"remove-from-queue",sessionId:i,messageId:n}))},clearQueue:()=>{const{ws:n,activeSessionId:r}=t();!n||n.readyState!==WebSocket.OPEN||!r||n.send(JSON.stringify({type:"clear-queue",sessionId:r}))},resumeQueue:()=>{const{ws:n,activeSessionId:r}=t();!n||n.readyState!==WebSocket.OPEN||!r||n.send(JSON.stringify({type:"resume-queue",sessionId:r}))},addPendingAttachment:async(n,r)=>{const i=Math.random().toString(36).substring(2,15),s=r.type.startsWith("image/");let o;s&&(o=await new Promise(c=>{const d=new FileReader;d.onload=()=>c(d.result),d.readAsDataURL(r)}));const l={id:i,file:r,preview:o,uploading:!1};e(c=>{const d=new Map(c.pendingAttachments),p=d.get(n)||[];return d.set(n,[...p,l]),{pendingAttachments:d}})},removePendingAttachment:(n,r)=>{e(i=>{const s=new Map(i.pendingAttachments),o=s.get(n)||[];return s.set(n,o.filter(l=>l.id!==r)),{pendingAttachments:s}})},clearPendingAttachments:n=>{e(r=>{const i=new Map(r.pendingAttachments);return i.set(n,[]),{pendingAttachments:i}})},getPendingAttachments:n=>t().pendingAttachments.get(n)||[],addToolActivity:(n,r)=>{const i={...r,id:Math.random().toString(36).substring(2,15),timestamp:new Date};e(s=>({sessions:s.sessions.map(o=>o.id===n?{...o,toolActivities:[...o.toolActivities||[],i].slice(-50)}:o)}))},clearToolActivities:n=>{e(r=>({sessions:r.sessions.map(i=>i.id===n?{...i,toolActivities:[]}:i)}))},setPendingPlan:(n,r,i)=>{e(s=>({sessions:s.sessions.map(o=>o.id===n?{...o,pendingPlan:{messageId:r,questions:i,additionalContext:""}}:o)}))},answerPlanQuestion:(n,r,i)=>{e(s=>({sessions:s.sessions.map(o=>o.id===n&&o.pendingPlan?{...o,pendingPlan:{...o.pendingPlan,questions:o.pendingPlan.questions.map(l=>l.id===r?{...l,answer:i}:l)}}:o)}))},setAdditionalContext:(n,r)=>{e(i=>({sessions:i.sessions.map(s=>s.id===n&&s.pendingPlan?{...s,pendingPlan:{...s.pendingPlan,additionalContext:r}}:s)}))},approvePlan:n=>{const{ws:r,sessions:i}=t(),s=i.find(c=>c.id===n);if(!r||r.readyState!==WebSocket.OPEN||!(s!=null&&s.pendingPlan))return;const o={};for(const c of s.pendingPlan.questions)c.answer&&(o[c.question]=c.answer);const l=s.pendingPlan.messageId;r.send(JSON.stringify({type:"approve-plan",sessionId:n,messageId:l,answers:o,additionalContext:s.pendingPlan.additionalContext||""})),e(c=>({sessions:c.sessions.map(d=>d.id===n?{...d,pendingPlan:void 0,approvedPlanMessageId:l}:d)}))},cancelPlan:n=>{e(r=>({sessions:r.sessions.map(i=>i.id===n?{...i,pendingPlan:void 0}:i)}))},setShowPreviewPanel:n=>e({showPreviewPanel:n}),setShowStartAppModal:n=>e({showStartAppModal:n}),approveMCPTool:async(n,r)=>{try{await F("POST",`/mcp/approve/${n}`,{autoApproveSession:r}),e({pendingMCPApproval:null})}catch(i){throw console.error("[Terminal] Failed to approve MCP tool:",i),i}},denyMCPTool:async n=>{try{await F("POST",`/mcp/deny/${n}`),e({pendingMCPApproval:null})}catch(r){throw console.error("[Terminal] Failed to deny MCP tool:",r),r}},clearMCPApproval:()=>e({pendingMCPApproval:null})}));function o1e(e){return e>=85?"bg-red-500":e>=70?"bg-orange-500":e>=50?"bg-yellow-500":"bg-emerald-500"}function l1e(e){return e>=85?"text-red-400":e>=70?"text-orange-400":e>=50?"text-yellow-400":"text-emerald-400"}const CK=f.memo(function({className:t,contextState:n,onSummarize:r}){var w;const{sessions:i,activeSessionId:s,fetchContextState:o}=ri(),l=f.useMemo(()=>i.find(y=>y.id===s),[i,s]);f.useEffect(()=>{var y;n===void 0&&s&&l&&(((y=l.messages)==null?void 0:y.length)||0)>0&&o(s)},[s,o,(w=l==null?void 0:l.messages)==null?void 0:w.length,n]);const c=n!==void 0?n:l==null?void 0:l.contextState,d=f.useCallback(async()=>{if(r){r();return}if(s)try{await F("POST",`/terminal/sessions/${s}/context/summarize`)}catch(y){console.error("[ContextGauge] Failed to trigger summarization:",y)}},[s,r]);if(!c)return null;const p=c.contextUtilizationPercent,h=c.summarizationStatus,m=p>=70&&h==="none",g=h==="in_progress",x=h==="completed",k=[`Context: ${p}%`,`Est. tokens: ${c.estimatedPromptTokens.toLocaleString()}`,`Messages: ${c.totalMessageCount} (${c.verbatimMessageCount} verbatim)`,c.summaryCount>0?`Summaries: ${c.summaryCount}`:null,`Window: ${(c.modelContextWindow/1e3).toFixed(0)}K`].filter(Boolean).join(" | ");return a.jsxs("div",{className:A("flex items-center gap-1.5",t),title:k,children:[a.jsx(Wc,{className:"h-3 w-3 text-zinc-500 shrink-0"}),a.jsx("div",{className:"w-16 h-1.5 bg-white/10 rounded-full overflow-hidden",children:a.jsx("div",{className:A("h-full rounded-full transition-all duration-500",o1e(p)),style:{width:`${Math.min(p,100)}%`}})}),a.jsxs("span",{className:A("text-[10px] font-medium tabular-nums",l1e(p)),children:[p,"%"]}),m&&a.jsx("button",{onClick:d,className:"text-[10px] text-white/40 hover:text-white/70 px-1.5 py-0.5 rounded bg-white/5 hover:bg-white/10 transition-colors",children:"Summarize"}),g&&a.jsx(he,{className:"h-3 w-3 text-blue-400 animate-spin"}),x&&a.jsx(ke,{className:"h-3 w-3 text-emerald-400"})]})});function fq({value:e,onChange:t,onSend:n,onStop:r,onKeyDown:i,inputRef:s,isRunning:o,contextState:l,onSummarize:c}){f.useEffect(()=>{s.current&&(s.current.style.height="auto",s.current.style.height=`${Math.min(s.current.scrollHeight,200)}px`)},[e,s]);const d=e.trim().length>0;return a.jsxs("div",{className:"w-full max-w-4xl mx-auto",children:[a.jsxs("div",{className:A("relative flex items-end gap-2.5 rounded-2xl px-5 py-3.5 transition-all duration-200","bg-gradient-to-br from-white/[0.05] via-white/[0.03] to-white/[0.02]","ring-1 backdrop-blur-sm",o?"ring-purple-500/30":d?"ring-purple-500/25 focus-within:ring-purple-500/40 focus-within:shadow-lg focus-within:shadow-purple-500/10":"ring-purple-500/15 focus-within:ring-purple-500/30"),children:[a.jsx("textarea",{ref:s,value:e,onChange:p=>t(p.target.value),onKeyDown:i,placeholder:"Type your idea or question...","aria-label":"Type your idea or question",className:"flex-1 bg-transparent text-white/90 text-[15px] leading-[1.6] placeholder-white/30 resize-none outline-none min-h-[24px] max-h-[200px]",rows:1,disabled:o}),o?a.jsx("button",{onClick:r,"aria-label":"Stop generation",className:A("flex-shrink-0 flex items-center justify-center rounded-lg transition-all duration-200","h-10 w-10 sm:h-9 sm:w-9","bg-gradient-to-br from-red-500/15 to-red-600/10 text-red-400","ring-1 ring-red-500/30","hover:bg-red-500/20 hover:ring-red-500/40 hover:shadow-lg hover:shadow-red-500/10","active:scale-95"),children:a.jsx(ya,{className:"h-4 w-4"})}):a.jsx("button",{onClick:n,disabled:!d,"aria-label":"Send message","aria-disabled":!d,className:A("flex-shrink-0 flex items-center justify-center rounded-lg transition-all duration-200","h-10 w-10 sm:h-9 sm:w-9",d?["bg-gradient-to-br from-purple-500/20 via-purple-500/15 to-purple-600/20","text-purple-300 ring-1 ring-purple-500/30","hover:from-purple-500/25 hover:via-purple-500/20 hover:to-purple-600/25","hover:ring-purple-500/40 hover:shadow-lg hover:shadow-purple-500/10","active:scale-95"]:"bg-white/[0.02] text-white/20 ring-1 ring-white/5 cursor-not-allowed opacity-50"),children:a.jsx(cd,{className:"h-4 w-4"})})]}),a.jsxs("div",{className:"flex items-center justify-between mt-2.5 px-2",children:[a.jsx("div",{className:"flex items-center gap-2",children:o?a.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-purple-400/70",children:[a.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-purple-400 animate-pulse"}),"Claude is thinking..."]}):a.jsx("span",{className:A("text-[11px] transition-colors duration-200",d?"text-white/30":"text-white/20"),children:"Ctrl+Enter to send"})}),a.jsxs("div",{className:"flex items-center gap-2",children:[o&&a.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-purple-400/50",children:[a.jsx(he,{className:"h-2.5 w-2.5 animate-spin"}),"Streaming"]}),a.jsx(CK,{contextState:l??null,onSummarize:c})]})]})]})}function c1e({utilizationPercent:e}){const[t,n]=f.useState(!1);return t?null:a.jsx(Ce,{children:a.jsxs(q.div,{initial:{opacity:0,y:-12,height:0},animate:{opacity:1,y:0,height:"auto"},exit:{opacity:0,y:-12,height:0},transition:{duration:.3,ease:[.4,0,.2,1]},role:"alert","aria-live":"polite","aria-label":`Context is ${e}% full`,className:A("mx-6 mt-2 mb-1 rounded-xl px-5 sm:px-6 py-3.5 flex items-center gap-3.5 ring-1","bg-gradient-to-br from-amber-500/15 via-amber-500/10 to-amber-500/5","ring-amber-500/30"),children:[a.jsx("div",{className:"flex-shrink-0 flex items-center justify-center h-8 w-8 rounded-lg bg-amber-500/20",children:a.jsx(Ge,{className:"h-4 w-4 text-amber-400"})}),a.jsxs("p",{className:"flex-1 text-sm font-medium text-amber-300 leading-relaxed",children:["Context is ",a.jsxs("span",{className:"font-semibold text-amber-200",children:[e,"%"]})," full. Consider starting a new idea to keep responses sharp."]}),a.jsx("button",{type:"button",onClick:()=>n(!0),"aria-label":"Dismiss context warning",className:A("flex-shrink-0 flex items-center justify-center h-7 w-7 rounded-lg","transition-colors duration-200","hover:bg-amber-500/20","focus:outline-none focus:ring-2 focus:ring-amber-500/40"),children:a.jsx(ve,{className:"h-4 w-4 text-amber-400"})})]})})}function d1e({onClick:e}){return a.jsx(q.button,{initial:{opacity:0,scale:.8,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.8,y:10},whileHover:{scale:1.05},whileTap:{scale:.95},transition:{duration:.2,ease:[.4,0,.2,1]},onClick:e,"aria-label":"Scroll to latest message",className:A("flex items-center justify-center rounded-xl backdrop-blur-sm","h-10 w-10 sm:h-9 sm:w-9","bg-gradient-to-br from-purple-500/15 via-purple-500/10 to-purple-600/10","ring-1 ring-purple-500/25","shadow-lg shadow-purple-500/10","hover:ring-purple-500/35 hover:shadow-xl hover:shadow-purple-500/15","focus:outline-none focus:ring-2 focus:ring-purple-500/40","transition-all duration-200","touch-manipulation"),children:a.jsx(Xe,{className:"h-5 w-5 text-purple-300"})})}function gq({onOpenAttachModal:e,onOpenPromoteModal:t}){var R,H;const{ideas:n,activeIdeaId:r,sendMessage:i,cancelOperation:s,saveIdea:o,updateIdeaTitle:l,detachFromRepo:c,fetchContextState:d}=Za(),{repos:p}=sn(),h=f.useMemo(()=>n.find(I=>I.id===r),[n,r]),[m,g]=f.useState(""),x=f.useRef(null),k=f.useRef(null),w=f.useRef(null),[y,b]=f.useState(!0),[v,S]=f.useState(!1);f.useEffect(()=>{w.current&&w.current.focus()},[r]),f.useEffect(()=>{r&&h&&h.messages.length>0&&d(r)},[r,d,(R=h==null?void 0:h.messages)==null?void 0:R.length]),f.useEffect(()=>{y&&x.current&&(x.current.scrollTop=x.current.scrollHeight)},[h==null?void 0:h.messages,y]);const N=f.useCallback(()=>{if(!x.current)return;const{scrollTop:I,scrollHeight:Q,clientHeight:Z}=x.current,D=Q-I-Z;b(D<50),S(D>100)},[]),E=f.useCallback(()=>{x.current&&(x.current.scrollTop=x.current.scrollHeight,b(!0),S(!1))},[]),M=f.useCallback(()=>{const I=m.trim();!I||!r||(i(I),g(""))},[m,r,i]),j=f.useCallback(I=>{I.key==="Enter"&&(I.ctrlKey||I.metaKey)&&(I.preventDefault(),M())},[M]),_=f.useCallback(()=>{r&&o(r)},[r,o]),C=f.useCallback(I=>{r&&l(r,I)},[r,l]),O=f.useCallback(I=>{r&&c(r,I)},[r,c]),L=f.useCallback(async()=>{if(r)try{await F("POST",`/ideas/${r}/context/summarize`)}catch(I){console.error("[IdeaView] Failed to trigger summarization:",I)}},[r]),z=f.useMemo(()=>{const I={};for(const Q of p)I[Q.id]=Q.id.split("/").pop()||Q.id;return I},[p]);if(!h)return null;const G=h.chatStatus==="running",B=h.messages.length===0,te=(H=h.contextState)==null?void 0:H.contextUtilizationPercent,Y=h.splitSuggested||te!=null&&te>=85;return a.jsxs("div",{className:"flex-1 flex flex-col min-h-0 bg-[#0a0d14]",children:[a.jsxs("div",{className:"pointer-events-none fixed inset-0 z-0",children:[a.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-purple-500/[0.02] via-transparent to-transparent"}),a.jsx("div",{className:"absolute -top-32 left-1/2 h-64 w-[600px] -translate-x-1/2 rounded-full bg-purple-500/5 blur-3xl"})]}),a.jsx(yoe,{idea:h,onUpdateTitle:C,onSave:_,onAttach:e,onDetach:O,onPromote:t,repoNames:z}),B?a.jsxs("div",{className:"relative z-10 flex-1 flex flex-col",children:[a.jsx("div",{className:"flex-1 flex items-center justify-center px-6",children:a.jsxs(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"text-center max-w-md",children:[a.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-purple-500/20 to-violet-600/20 ring-1 ring-purple-500/20",children:a.jsx(xn,{className:"h-8 w-8 text-purple-400"})}),a.jsx("h2",{className:"text-xl font-semibold text-white mb-2",children:"What would you like to explore?"}),a.jsx("p",{className:"text-sm text-white/50 leading-relaxed",children:"No repo? No problem. Start brainstorming and let your ideas flow."})]})}),a.jsx("div",{className:"w-full px-4 pb-4",children:a.jsx(fq,{value:m,onChange:g,onSend:M,onStop:s,onKeyDown:j,inputRef:w,isRunning:G,contextState:h.contextState,onSummarize:L})})]}):a.jsxs("div",{className:"relative z-10 flex-1 flex flex-col min-h-0",children:[Y&&r&&a.jsx(c1e,{utilizationPercent:te??85}),a.jsx("div",{ref:x,onScroll:N,className:"flex-1 overflow-y-auto py-4 space-y-1",role:"log","aria-live":"polite",children:a.jsxs("div",{className:"w-full px-4",children:[h.messages.map((I,Q)=>Q===h.messages.length-1?a.jsx(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},children:a.jsx(mq,{message:I})},I.id):a.jsx("div",{children:a.jsx(mq,{message:I})},I.id)),a.jsx("div",{ref:k})]})}),a.jsx(Ce,{children:v&&a.jsx("div",{className:"absolute bottom-20 right-6 z-10",children:a.jsx(d1e,{onClick:E})})}),a.jsx("div",{className:"w-full px-4 pb-4 pt-2 border-t border-purple-500/5",children:a.jsx(fq,{value:m,onChange:g,onSend:M,onStop:s,onKeyDown:j,inputRef:w,isRunning:G,contextState:h.contextState,onSummarize:L})})]})]})}function u1e(e){const t=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(t<60)return"just now";const n=Math.floor(t/60);if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function p1e({idea:e,isActive:t,onClick:n}){const r=!!e.promotedToSessionId||!!e.promotedToRepoId,i=e.status==="ephemeral",s=e.attachedRepoIds&&e.attachedRepoIds.length>0,o=e.messages.filter(l=>!l.isStreaming).length;return a.jsxs(q.button,{onClick:n,className:A("w-full text-left rounded-xl p-3 transition-all",r&&"opacity-60",t?"bg-purple-500/10 ring-1 ring-purple-500/30 shadow-[0_0_15px_rgba(139,92,246,0.1)]":i?"bg-white/[0.02] ring-1 ring-white/[0.06] border-dashed opacity-80 hover:opacity-100 hover:bg-white/[0.04]":"bg-white/[0.03] ring-1 ring-white/[0.08] hover:bg-white/[0.05]"),whileHover:{scale:1.01},whileTap:{scale:.99},children:[a.jsxs("div",{className:"flex items-start gap-2 mb-1.5",children:[a.jsx(xn,{className:A("h-3.5 w-3.5 mt-0.5 flex-shrink-0",t?"text-purple-400":"text-purple-400/60")}),a.jsx("span",{className:A("text-sm font-medium truncate flex-1",t?"text-white":"text-white/80"),children:e.title||"Untitled Idea"}),i&&a.jsx("span",{className:"h-2 w-2 rounded-full bg-purple-400/60 flex-shrink-0 mt-1.5"})]}),a.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-white/40",children:[a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(Xn,{className:"h-3 w-3"}),u1e(e.lastActivityAt)]}),o>0&&a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(rr,{className:"h-3 w-3"}),o]})]}),a.jsxs("div",{className:"flex items-center gap-1.5 mt-2",children:[s&&a.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-white/40 bg-white/5 rounded px-1.5 py-0.5",children:[a.jsx(gn,{className:"h-2.5 w-2.5"}),e.attachedRepoIds.length," repo",e.attachedRepoIds.length>1?"s":""]}),r&&a.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-emerald-400/60 bg-emerald-500/10 rounded px-1.5 py-0.5",children:[a.jsx(Dn,{className:"h-2.5 w-2.5"}),"Promoted"]})]})]})}function h1e({ideas:e,activeIdeaId:t,searchQuery:n,onIdeaClick:r}){const i=f.useMemo(()=>{if(!n.trim())return e;const s=n.toLowerCase();return e.filter(o=>{var p,h;const l=(o.title||"Untitled Idea").toLowerCase(),c=(o.tags||[]).join(" ").toLowerCase(),d=((h=(p=o.messages[o.messages.length-1])==null?void 0:p.content)==null?void 0:h.toLowerCase())||"";return l.includes(s)||c.includes(s)||d.includes(s)})},[e,n]);return i.length===0?a.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:a.jsx("p",{className:"text-xs text-white/30 text-center",children:n?"No ideas match your search.":"No ideas yet."})}):a.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-2 space-y-2 scrollbar-none",children:a.jsx(Ce,{mode:"popLayout",children:i.map(s=>a.jsx(q.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},layout:!0,children:a.jsx(p1e,{idea:s,isActive:s.id===t,onClick:()=>r(s.id)})},s.id))})})}function yq({onClose:e}){const{ideas:t,activeIdeaId:n,switchIdea:r,createIdea:i,ideaPanelSearch:s,setIdeaPanelSearch:o}=Za(),l=f.useRef(null);return f.useEffect(()=>{l.current&&l.current.focus()},[]),f.useEffect(()=>{const c=d=>{d.key==="Escape"&&e()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e]),a.jsxs(q.aside,{initial:{x:320,opacity:0},animate:{x:0,opacity:1},exit:{x:320,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:A("relative flex flex-col border-l border-purple-500/10 bg-[#080b11]/95 backdrop-blur-xl","w-full sm:w-[320px] flex-shrink-0"),children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-purple-500/10",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(xn,{className:"h-4 w-4 text-purple-400"}),a.jsx("h2",{className:"text-sm font-semibold text-white/90",children:"Ideas"})]}),a.jsx("button",{onClick:e,className:"p-1.5 rounded-lg text-white/40 hover:text-white/70 hover:bg-white/5 transition-colors",children:a.jsx(ve,{className:"h-4 w-4"})})]}),a.jsx("div",{className:"px-3 py-2",children:a.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-white/[0.04] ring-1 ring-white/[0.08] px-3 py-2 focus-within:ring-purple-500/30 transition-all",children:[a.jsx(Kt,{className:"h-3.5 w-3.5 text-white/30"}),a.jsx("input",{ref:l,value:s,onChange:c=>o(c.target.value),placeholder:"Search ideas...",className:"flex-1 bg-transparent text-sm text-white/80 placeholder-white/30 outline-none"}),s&&a.jsx("button",{onClick:()=>o(""),className:"text-white/30 hover:text-white/60",children:a.jsx(ve,{className:"h-3 w-3"})})]})}),a.jsx(h1e,{ideas:t,activeIdeaId:n,searchQuery:s,onIdeaClick:c=>r(c)}),a.jsx("div",{className:"px-3 py-3 border-t border-purple-500/10",children:a.jsxs("button",{onClick:()=>i(),className:"w-full flex items-center justify-center gap-2 rounded-xl bg-purple-500/10 px-4 py-2.5 text-sm font-medium text-purple-300 ring-1 ring-purple-500/20 hover:bg-purple-500/15 transition-all",children:[a.jsx(Zt,{className:"h-4 w-4"}),"New Idea",a.jsx("kbd",{className:"ml-1 px-1 py-0.5 rounded bg-purple-500/10 text-[10px] text-purple-400/60 font-mono",children:"Ctrl+I"})]})})]})}function xq({idea:e,repos:t,onAttach:n,onClose:r}){const[i,s]=f.useState(""),[o,l]=f.useState(null),c=f.useRef(null);f.useEffect(()=>{var h;(h=c.current)==null||h.focus()},[]),f.useEffect(()=>{const h=m=>{m.key==="Escape"&&r()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[r]);const d=f.useMemo(()=>{const h=new Set(e.attachedRepoIds||[]);return t.filter(m=>!h.has(m.id)).filter(m=>i.trim()?m.id.toLowerCase().includes(i.toLowerCase()):!0)},[t,i,e.attachedRepoIds]),p=e.status==="ephemeral";return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[a.jsx(q.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:r,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),a.jsxs(q.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative w-full max-w-[520px] rounded-2xl bg-[#0d1117] ring-1 ring-white/10 shadow-2xl overflow-hidden",role:"dialog","aria-label":"Attach repository",children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/10",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Attach Repository"}),a.jsx("button",{onClick:r,className:"p-1.5 rounded-lg text-white/40 hover:text-white/70 hover:bg-white/5 transition-colors",children:a.jsx(ve,{className:"h-5 w-5"})})]}),p&&a.jsxs("div",{className:"mx-6 mt-4 flex items-start gap-3 rounded-xl bg-amber-500/10 ring-1 ring-amber-500/20 px-4 py-3",children:[a.jsx(_n,{className:"h-4 w-4 text-amber-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-sm text-amber-200/80",children:"Save this idea before attaching a repository."})]}),a.jsxs("div",{className:"mx-6 mt-4 flex items-start gap-3 rounded-xl bg-purple-500/5 ring-1 ring-purple-500/10 px-4 py-3",children:[a.jsx(_n,{className:"h-4 w-4 text-purple-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-xs text-white/50",children:"Attaching won't modify your repository. Claude will have read-only context."})]}),a.jsx("div",{className:"px-6 mt-4",children:a.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-white/[0.04] ring-1 ring-white/[0.08] px-4 py-2.5 focus-within:ring-purple-500/30 transition-all",children:[a.jsx(Kt,{className:"h-4 w-4 text-white/30"}),a.jsx("input",{ref:c,value:i,onChange:h=>s(h.target.value),placeholder:"Search repositories...",className:"flex-1 bg-transparent text-sm text-white/80 placeholder-white/30 outline-none",disabled:p})]})}),a.jsx("div",{className:"px-6 py-4 max-h-[300px] overflow-y-auto space-y-1",children:d.length===0?a.jsx("p",{className:"text-center text-sm text-white/30 py-8",children:i?"No repositories match your search.":"No repositories available."}):d.map(h=>{const m=h.id===o;return a.jsxs("button",{onClick:()=>l(m?null:h.id),disabled:p,className:A("w-full flex items-center gap-3 rounded-xl px-4 py-3 text-left transition-all ring-1",m?"bg-purple-500/10 ring-purple-500/30 text-white":"bg-white/[0.02] ring-white/[0.06] text-white/70 hover:bg-white/[0.04]",p&&"opacity-50 cursor-not-allowed"),children:[a.jsx(gn,{className:A("h-4 w-4 flex-shrink-0",m?"text-purple-400":"text-white/40")}),a.jsx("div",{className:"flex-1 min-w-0",children:a.jsx("span",{className:"text-sm font-medium truncate block",children:h.id})}),m&&a.jsx(ke,{className:"h-4 w-4 text-purple-400 flex-shrink-0"})]},h.id)})}),a.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-white/10",children:[a.jsx("button",{onClick:r,className:"px-4 py-2 rounded-xl text-sm text-white/60 hover:text-white/80 hover:bg-white/5 transition-colors",children:"Cancel"}),a.jsx("button",{onClick:()=>o&&n(o),disabled:!o||p,className:A("px-5 py-2 rounded-xl text-sm font-medium transition-all",o&&!p?"bg-purple-500/20 text-purple-200 ring-1 ring-purple-500/30 hover:bg-purple-500/30":"bg-white/5 text-white/30 cursor-not-allowed"),children:"Attach Selected"})]})]})]})}function m1e(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,50)||"my-project"}function bq({idea:e,onPromote:t,onClose:n}){var _,C;const r=sn(O=>O.workspaces),[i,s]=f.useState(1),[o,l]=f.useState(e.title?m1e(e.title):"my-project"),[c,d]=f.useState(((_=r[0])==null?void 0:_.id)??""),p=((C=r.find(O=>O.id===c))==null?void 0:C.scanPath)??"",[h,m]=f.useState(!1),[g,x]=f.useState(!0),[k,w]=f.useState(!1),[y,b]=f.useState(null),[v,S]=f.useState(!1),N=f.useRef(null),E=f.useRef(null);f.useEffect(()=>{var O;(O=N.current)==null||O.focus()},[]),f.useEffect(()=>{const O=L=>{L.key==="Escape"&&n()};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[n]),f.useEffect(()=>{if(!v)return;const O=L=>{E.current&&!E.current.contains(L.target)&&S(!1)};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[v]);const M=f.useCallback(async()=>{if(!(!o.trim()||!p.trim())){w(!0),b(null);try{await t({repoName:o.trim(),directory:p.trim(),generateScaffold:h,transferHistory:g})}catch(O){b(O instanceof Error?O.message:"Promotion failed"),w(!1)}}},[o,p,h,g,t]),j=o.trim().length>0&&p.trim().length>0;return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[a.jsx(q.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:n,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),a.jsxs(q.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative w-full max-w-[560px] rounded-2xl bg-[#0d1117] ring-1 ring-white/10 shadow-2xl overflow-hidden",role:"dialog","aria-label":"Promote idea to project",children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/10",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"flex items-center justify-center h-8 w-8 rounded-lg bg-purple-500/10 ring-1 ring-purple-500/20",children:a.jsx(Dn,{className:"h-4 w-4 text-purple-400"})}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Promote to Project"})]}),a.jsx("button",{onClick:n,className:"p-1.5 rounded-lg text-white/40 hover:text-white/70 hover:bg-white/5 transition-colors",children:a.jsx(ve,{className:"h-5 w-5"})})]}),a.jsxs("div",{className:"flex items-center gap-2 px-6 py-3 border-b border-white/5",children:[a.jsxs("div",{className:A("flex items-center gap-1.5 text-xs font-medium",i===1?"text-purple-400":"text-white/30"),children:[a.jsx("span",{className:A("flex items-center justify-center h-5 w-5 rounded-full text-[10px]",i===1?"bg-purple-500/20 ring-1 ring-purple-500/30":"bg-white/5"),children:"1"}),"Setup"]}),a.jsx(pt,{className:"h-3 w-3 text-white/20"}),a.jsxs("div",{className:A("flex items-center gap-1.5 text-xs font-medium",i===2?"text-purple-400":"text-white/30"),children:[a.jsx("span",{className:A("flex items-center justify-center h-5 w-5 rounded-full text-[10px]",i===2?"bg-purple-500/20 ring-1 ring-purple-500/30":"bg-white/5"),children:"2"}),"Confirm"]})]}),a.jsx("div",{className:"px-6 py-5",children:a.jsxs(Ce,{mode:"wait",children:[i===1&&a.jsxs(q.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"space-y-5",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white/70 mb-1.5",children:"Project Name"}),a.jsx("input",{ref:N,value:o,onChange:O=>l(O.target.value),placeholder:"my-awesome-project",className:"w-full rounded-xl bg-white/[0.04] ring-1 ring-white/[0.08] px-4 py-2.5 text-sm text-white/90 placeholder-white/30 outline-none focus:ring-purple-500/30 transition-all"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white/70 mb-1.5",children:"Repository Location"}),a.jsxs("div",{className:"relative",ref:E,children:[a.jsxs("button",{type:"button",onClick:()=>S(!v),className:"w-full flex items-center justify-between rounded-xl bg-white/[0.04] ring-1 ring-white/[0.08] px-4 py-2.5 text-left outline-none focus:ring-purple-500/30 transition-all",children:[c&&r.find(O=>O.id===c)?a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"text-sm text-white/90 truncate",children:r.find(O=>O.id===c).name}),a.jsx("div",{className:"text-[11px] text-white/40 truncate",children:r.find(O=>O.id===c).scanPath})]}):a.jsx("span",{className:"text-sm text-white/30",children:"No workspaces available"}),a.jsx(Xe,{className:A("h-4 w-4 text-white/40 flex-shrink-0 ml-2 transition-transform",v&&"rotate-180")})]}),v&&r.length>0&&a.jsx("div",{className:"absolute z-10 mt-1 w-full rounded-xl bg-[#161b22] ring-1 ring-white/10 shadow-xl overflow-hidden",children:r.map(O=>a.jsxs("button",{type:"button",onClick:()=>{d(O.id),S(!1)},className:A("w-full px-4 py-2.5 text-left hover:bg-white/[0.06] transition-colors",O.id===c&&"bg-purple-500/10"),children:[a.jsx("div",{className:"text-sm text-white/90 truncate",children:O.name}),a.jsx("div",{className:"text-[11px] text-white/40 truncate",children:O.scanPath})]},O.id))})]}),a.jsxs("p",{className:"mt-1 text-[11px] text-white/30",children:["Project will be created at: ",p?`${p}/${o}`:"<select a workspace>"]})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer group",children:[a.jsx("input",{type:"checkbox",checked:h,onChange:O=>m(O.target.checked),className:"h-4 w-4 rounded border-white/20 bg-white/5 text-purple-500 focus:ring-purple-500/30"}),a.jsx("span",{className:"text-sm text-white/70 group-hover:text-white/90 transition-colors",children:"Generate project scaffold (README, .gitignore)"})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer group",children:[a.jsx("input",{type:"checkbox",checked:g,onChange:O=>x(O.target.checked),className:"h-4 w-4 rounded border-white/20 bg-white/5 text-purple-500 focus:ring-purple-500/30"}),a.jsx("span",{className:"text-sm text-white/70 group-hover:text-white/90 transition-colors",children:"Transfer chat history to new session"})]})]})]},"step1"),i===2&&a.jsxs(q.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"space-y-4",children:[a.jsxs("div",{className:"rounded-xl bg-white/[0.03] ring-1 ring-white/[0.06] p-4 space-y-3",children:[a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-white/50",children:"Project Name"}),a.jsx("span",{className:"text-white font-medium",children:o})]}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-white/50",children:"Location"}),a.jsxs("span",{className:"text-white/80 font-mono text-xs",children:[p,"/",o]})]}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-white/50",children:"Scaffold"}),a.jsx("span",{className:"text-white/70",children:h?"Yes":"No"})]}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-white/50",children:"Transfer History"}),a.jsx("span",{className:"text-white/70",children:g?"Yes":"No"})]})]}),a.jsxs("div",{className:"flex items-start gap-3 rounded-xl bg-amber-500/5 ring-1 ring-amber-500/10 px-4 py-3",children:[a.jsx(Ge,{className:"h-4 w-4 text-amber-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-xs text-amber-200/70",children:"This will mark the idea as Promoted and create a new session with the repository."})]}),y&&a.jsxs("div",{className:"flex items-start gap-3 rounded-xl bg-red-500/10 ring-1 ring-red-500/20 px-4 py-3",children:[a.jsx(Ge,{className:"h-4 w-4 text-red-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-xs text-red-200/80",children:y})]})]},"step2")]})}),a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-t border-white/10",children:[a.jsx("div",{children:i===2&&a.jsxs("button",{onClick:()=>s(1),disabled:k,className:"flex items-center gap-1.5 px-4 py-2 rounded-xl text-sm text-white/60 hover:text-white/80 hover:bg-white/5 transition-colors",children:[a.jsx(Zc,{className:"h-4 w-4"}),"Back"]})}),a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("button",{onClick:n,disabled:k,className:"px-4 py-2 rounded-xl text-sm text-white/60 hover:text-white/80 hover:bg-white/5 transition-colors",children:"Cancel"}),i===1?a.jsxs("button",{onClick:()=>s(2),disabled:!j,className:A("flex items-center gap-1.5 px-5 py-2 rounded-xl text-sm font-medium transition-all",j?"bg-purple-500/20 text-purple-200 ring-1 ring-purple-500/30 hover:bg-purple-500/30":"bg-white/5 text-white/30 cursor-not-allowed"),children:["Next",a.jsx(pt,{className:"h-4 w-4"})]}):a.jsx("button",{onClick:M,disabled:k,className:A("flex items-center gap-1.5 px-5 py-2 rounded-xl text-sm font-medium transition-all",k?"bg-purple-500/10 text-purple-300/50 cursor-wait":"bg-purple-500/20 text-purple-200 ring-1 ring-purple-500/30 hover:bg-purple-500/30"),children:k?a.jsxs(a.Fragment,{children:[a.jsx(he,{className:"h-4 w-4 animate-spin"}),"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(Dn,{className:"h-4 w-4"}),"Create Project"]})})]})]})]})]})}const kq=[{id:"prompt",label:"Prompt",shortcut:"1",icon:rr},{id:"review",label:"Review",shortcut:"2",icon:hp},{id:"ship",label:"Ship",shortcut:"3",icon:Dn}];function f1e({activePhase:e,onPhaseChange:t,messageCount:n=0,fileCount:r=0,warningCount:i=0,isRunning:s=!1,canReview:o=!0,canShip:l=!0,existingPR:c=null}){f.useEffect(()=>{const m=g=>{g.target instanceof HTMLInputElement||g.target instanceof HTMLTextAreaElement||g.target instanceof HTMLSelectElement||(g.key==="1"&&t("prompt"),g.key==="2"&&o&&t("review"),g.key==="3"&&l&&t("ship"))};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,o,l]);const d=m=>{switch(m){case"prompt":return n>0?n:void 0;case"review":return r>0?r:void 0;case"ship":return i>0?i:void 0;default:return}},p=m=>m==="review"?!o:m==="ship"?!l:!1,h=(m,g)=>({prompt:{bg:g?"bg-blue-500/20":"bg-white/5",ring:g?"ring-blue-500/40":"ring-white/10",text:g?"text-blue-400":"text-white/60",glow:g?"shadow-[0_0_20px_rgba(59,130,246,0.3)]":""},review:{bg:g?"bg-amber-500/20":"bg-white/5",ring:g?"ring-amber-500/40":"ring-white/10",text:g?"text-amber-400":"text-white/60",glow:g?"shadow-[0_0_20px_rgba(245,158,11,0.3)]":""},ship:{bg:g?"bg-emerald-500/20":"bg-white/5",ring:g?"ring-emerald-500/40":"ring-white/10",text:g?"text-emerald-400":"text-white/60",glow:g?"shadow-[0_0_20px_rgba(16,185,129,0.3)]":""}})[m];return a.jsx("div",{className:"flex items-center justify-center",children:a.jsx("div",{className:"flex items-center gap-1 sm:gap-2 rounded-2xl bg-white/[0.03] p-1 sm:p-1.5 ring-1 ring-white/10",children:kq.map((m,g)=>{const x=e===m.id,k=p(m.id),w=d(m.id),y=h(m.id,x),b=m.icon;return a.jsxs("div",{className:"flex items-center",children:[a.jsxs(q.button,{onClick:()=>!k&&t(m.id),disabled:k,className:A("relative flex items-center gap-1 sm:gap-2 rounded-xl px-2 py-2 sm:px-4 sm:py-2.5 text-xs sm:text-sm font-medium transition-all ring-1",y.bg,y.ring,y.text,y.glow,k&&"opacity-40 cursor-not-allowed",!k&&!x&&"hover:bg-white/10 hover:ring-white/20"),whileHover:k?void 0:{scale:1.02},whileTap:k?void 0:{scale:.98},children:[m.id==="prompt"&&s&&a.jsxs("span",{className:"absolute -top-1 -right-1 flex h-3 w-3",children:[a.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),a.jsx("span",{className:"relative inline-flex rounded-full h-3 w-3 bg-blue-500"})]}),m.id==="ship"&&c&&a.jsx("span",{className:A("absolute -top-1.5 -right-1.5 flex h-5 w-5 items-center justify-center rounded-full ring-2 ring-[#05070c]",c.state==="merged"?"bg-purple-500":c.state==="closed"?"bg-red-500":"bg-emerald-500"),title:`PR #${c.number}: ${c.title} (${c.state||"open"})`,children:c.state==="merged"?a.jsx(nr,{className:"h-3 w-3 text-white"}):a.jsx(pa,{className:"h-3 w-3 text-white"})}),a.jsx(b,{className:"h-4 w-4 shrink-0"}),a.jsx("span",{className:"hidden sm:inline",children:m.label}),w!==void 0&&a.jsx("span",{className:A("flex h-5 min-w-5 items-center justify-center rounded-full px-1.5 text-xs font-semibold",m.id==="ship"&&i>0?"bg-red-500/20 text-red-400":"bg-white/10 text-white/70"),children:w}),a.jsx("span",{className:"hidden sm:inline-flex ml-1 text-xs opacity-50 font-mono",children:m.shortcut})]}),g<kq.length-1&&a.jsx(pt,{className:"mx-0.5 sm:mx-1 h-3.5 w-3.5 sm:h-4 sm:w-4 text-white/20"})]},m.id)})})})}function wT({repos:e,onRepoClick:t,onRepoRemove:n,className:r,ideaItems:i=[],activeIdeaId:s,onIdeaClick:o,onIdeaClose:l,onNewIdea:c,onNewSession:d}){const{openOverlay:p}=vh(),[h,m]=f.useState(new Set),[g,x]=f.useState(!1),k=f.useCallback(async b=>{m(v=>new Set(v).add(b));try{await n(b)}finally{m(v=>{const S=new Set(v);return S.delete(b),S})}},[n]),w=b=>{switch(b){case"running":return a.jsx(he,{className:"h-3 w-3 animate-spin text-blue-400"});case"error":return a.jsx(dt,{className:"h-3 w-3 text-red-400"});case"modified":return a.jsx(Kr,{className:"h-3 w-3 fill-amber-400 text-amber-400"});case"clean":default:return a.jsx(Kr,{className:"h-3 w-3 fill-emerald-400 text-emerald-400"})}},y=(b,v)=>{if(v)switch(b){case"running":return"ring-blue-500/50 bg-blue-500/10";case"error":return"ring-red-500/50 bg-red-500/10";case"modified":return"ring-amber-500/50 bg-amber-500/10";default:return"ring-emerald-500/50 bg-emerald-500/10"}return"ring-white/10 bg-white/5 hover:bg-white/10 hover:ring-white/20"};return a.jsxs("div",{className:A("relative z-40 flex items-center gap-2 px-4 py-3 bg-[#05070c]/80 backdrop-blur-xl border-t border-white/10",r),children:[a.jsxs("div",{className:"flex items-center gap-2 text-white/40 text-xs font-medium uppercase tracking-wider",children:[a.jsx(gn,{className:"h-4 w-4"}),a.jsx("span",{className:"hidden sm:inline",children:"Repos"})]}),a.jsx("div",{className:"h-4 w-px bg-white/10 mx-1"}),i.length>0&&a.jsxs(a.Fragment,{children:[i.map(b=>{const v=b.id===s;return a.jsx(q.div,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},layout:!0,className:"flex-shrink-0",children:a.jsxs("button",{onClick:()=>o==null?void 0:o(b.id),className:A("group flex items-center gap-2 rounded-xl px-3 py-2 text-sm transition-all ring-1",v?"ring-purple-500/50 bg-purple-500/10":"ring-white/10 bg-white/5 hover:bg-white/10 hover:ring-white/20"),children:[a.jsx(xn,{className:A("h-3 w-3",v?"text-purple-400":"text-purple-400/60")}),b.status==="ephemeral"&&a.jsx(Kr,{className:"h-2 w-2 fill-purple-400 text-purple-400"}),a.jsx("span",{className:A("font-medium max-w-[120px] truncate",v?"text-white":"text-white/70"),children:b.title||"Untitled Idea"}),a.jsx("button",{onClick:S=>{S.stopPropagation(),l==null||l(b.id)},className:"ml-1 p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-white/10 transition-opacity",children:a.jsx(ve,{className:"h-3 w-3 text-white/50"})})]})},b.id)}),a.jsx("div",{className:"h-4 w-px bg-white/10 mx-1"})]}),a.jsx("div",{className:"flex items-center gap-2 flex-1 overflow-x-auto scrollbar-none",children:a.jsx(Ce,{mode:"popLayout",children:e.map(b=>{var S;const v=h.has(b.id);return a.jsx(q.div,{initial:{opacity:0,scale:.8,x:-10},animate:{opacity:v?.5:1,scale:1,x:0},exit:{opacity:0,scale:.8,x:-10},layout:!0,className:"flex-shrink-0",children:a.jsxs("button",{onClick:()=>!v&&t(b.id),disabled:v,className:A("group flex items-center gap-2 rounded-xl px-3 py-2 text-sm transition-all ring-1",v?"ring-red-500/30 bg-red-500/5 cursor-wait":y(b.status,b.isActive)),children:[v?a.jsx(he,{className:"h-3 w-3 animate-spin text-red-400"}):w(b.status),a.jsx("span",{className:A("font-medium max-w-[120px] truncate",v?"text-red-300/70":b.isActive?"text-white":"text-white/70"),children:v?"Closing...":b.name}),!v&&a.jsxs("span",{className:"flex items-center gap-1 rounded-md bg-white/5 px-1.5 py-0.5 text-xs text-white/50 font-mono",children:[a.jsx(yn,{className:"h-3 w-3"}),a.jsx("span",{className:"max-w-[80px] truncate",children:b.branch})]}),!v&&b.changesCount>0&&a.jsx("span",{className:"flex h-5 min-w-5 items-center justify-center rounded-full bg-amber-500/20 px-1.5 text-xs font-semibold text-amber-400",children:b.changesCount}),!v&&(b.parentSessionId||b.childSessionIds&&b.childSessionIds.length>0)&&a.jsx("span",{className:"flex items-center gap-0.5 text-xs text-blue-400/70",title:b.parentSessionId?"Continued from another session":`Continued in ${(S=b.childSessionIds)==null?void 0:S.length} session(s)`,children:a.jsx(nd,{className:"h-3 w-3"})}),!v&&a.jsx("button",{onClick:N=>{N.stopPropagation(),k(b.id)},className:"ml-1 p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-white/10 transition-opacity",title:"Close session",children:a.jsx(ve,{className:"h-3 w-3 text-white/50"})})]})},b.id)})})}),c?a.jsxs("div",{className:"relative",children:[a.jsxs(q.button,{onClick:()=>x(!g),className:"flex items-center gap-1.5 rounded-xl bg-white/5 px-3 py-2 text-sm text-white/60 ring-1 ring-white/10 hover:bg-white/10 hover:ring-white/20 hover:text-white/80 transition-all",whileHover:{scale:1.02},whileTap:{scale:.98},children:[a.jsx(Zt,{className:"h-4 w-4"}),a.jsx(Xe,{className:"h-3 w-3"})]}),a.jsx(Ce,{children:g&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-50",onClick:()=>x(!1)}),a.jsxs(q.div,{initial:{opacity:0,y:4,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.15},className:"absolute bottom-full right-0 mb-2 z-50 w-48 rounded-xl bg-[#0d1117] ring-1 ring-white/10 shadow-xl overflow-hidden",children:[a.jsxs("button",{onClick:()=>{x(!1),c()},className:"flex items-center gap-2.5 w-full px-4 py-2.5 text-sm text-white/80 hover:bg-purple-500/10 hover:text-purple-200 transition-colors",children:[a.jsx(xn,{className:"h-4 w-4 text-purple-400"}),"New Idea"]}),a.jsxs("button",{onClick:()=>{x(!1),d?d():p("new-session")},className:"flex items-center gap-2.5 w-full px-4 py-2.5 text-sm text-white/80 hover:bg-blue-500/10 hover:text-blue-200 transition-colors",children:[a.jsx(gn,{className:"h-4 w-4 text-blue-400"}),"New Session"]})]})]})})]}):a.jsxs(q.button,{onClick:()=>p("new-session"),className:"flex items-center gap-1.5 rounded-xl bg-white/5 px-3 py-2 text-sm text-white/60 ring-1 ring-white/10 hover:bg-white/10 hover:ring-white/20 hover:text-white/80 transition-all",whileHover:{scale:1.02},whileTap:{scale:.98},children:[a.jsx(Zt,{className:"h-4 w-4"}),a.jsx("span",{className:"hidden sm:inline",children:"Add Session"})]})]})}function g1e({sessionId:e,utilizationPercent:t,onSwitchSession:n}){const[r,i]=f.useState(!1),[s,o]=f.useState(!1),{splitSession:l}=ri(),c=f.useCallback(()=>{i(!0)},[]),d=f.useCallback(async()=>{o(!0);try{const p=await l(e);p&&n&&n(p)}catch(p){console.error("[ContextSplitBanner] Split failed:",p)}finally{o(!1)}},[e,l,n]);return r||t<85?null:a.jsx(Ce,{children:a.jsxs(q.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},role:"alert","aria-live":"polite",className:A("mx-6 mt-2 rounded-xl px-4 py-3 flex items-center gap-3 ring-1","bg-amber-500/10 ring-amber-500/30 text-amber-300"),children:[a.jsx(Ep,{className:"h-5 w-5 shrink-0 text-amber-400","aria-hidden":"true"}),a.jsxs("p",{className:"flex-1 text-sm",children:["Context is ",t,"% full. Split into a new session to keep responses sharp."]}),a.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[a.jsx("button",{type:"button",onClick:d,disabled:s,className:A("px-3 py-1.5 text-xs font-medium rounded-lg transition-colors","bg-amber-500/20 hover:bg-amber-500/30 text-amber-200","disabled:opacity-50"),children:s?"Splitting...":"Split Session"}),a.jsx("button",{type:"button",onClick:c,className:"p-1.5 rounded-lg transition-colors hover:bg-amber-500/20 text-amber-400","aria-label":"Dismiss alert",children:a.jsx(ve,{className:"h-4 w-4","aria-hidden":"true"})})]})]})})}function y1e({repoName:e,branchName:t}){return a.jsx("div",{className:"bg-white/[0.03] ring-1 ring-white/10 rounded-xl p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-blue-500/10 ring-1 ring-blue-400/20 flex-shrink-0",children:a.jsx(gn,{className:"h-5 w-5 text-blue-400"})}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("h3",{className:"text-white/90 font-medium text-sm truncate",children:e}),a.jsxs("div",{className:"flex items-center gap-2 text-xs text-white/40 mt-0.5",children:[a.jsx(yn,{className:"h-3 w-3 flex-shrink-0"}),a.jsx("span",{className:"truncate",children:t})]})]})]})})}const x1e={red:{iconBg:"bg-red-500/10",iconText:"text-red-400",iconRing:"ring-red-400/20"},blue:{iconBg:"bg-blue-500/10",iconText:"text-blue-400",iconRing:"ring-blue-400/20"},emerald:{iconBg:"bg-emerald-500/10",iconText:"text-emerald-400",iconRing:"ring-emerald-400/20"},purple:{iconBg:"bg-purple-500/10",iconText:"text-purple-400",iconRing:"ring-purple-400/20"}};function m1({title:e,description:t,icon:n,promptText:r,theme:i,onClick:s}){const o=x1e[i];return a.jsx("button",{onClick:()=>s(r),className:A("group relative rounded-xl p-4 bg-white/[0.02] ring-1 ring-white/[0.08]","hover:bg-white/[0.04] hover:ring-white/[0.15] hover:-translate-y-0.5","transition-all duration-200","focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-offset-2 focus:ring-offset-[#05070c]","text-left w-full"),"aria-label":`${e}: ${t}`,children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:A("flex h-8 w-8 items-center justify-center rounded-lg ring-1 flex-shrink-0","transition-colors duration-200",o.iconBg,o.iconRing,`group-hover:${o.iconBg.replace("/10","/20")}`),children:a.jsx(n,{className:A("h-4 w-4",o.iconText)})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("h3",{className:"text-sm font-medium text-white/90 mb-1",children:e}),a.jsx("p",{className:"text-xs text-white/50 leading-relaxed",children:t})]}),a.jsx(Ku,{className:A("h-4 w-4 text-white/30 flex-shrink-0","opacity-0 group-hover:opacity-100 transition-opacity duration-200","absolute top-4 right-4")})]})})}const f1=[{id:"prompt",label:"Prompt",color:"text-blue-300"},{id:"review",label:"Review",color:"text-emerald-300"},{id:"ship",label:"Ship",color:"text-purple-300"}];function b1e({currentPhase:e}){return a.jsx("div",{className:"inline-flex items-center gap-2 px-6 py-3 rounded-full bg-white/[0.02] ring-1 ring-white/[0.06]",role:"navigation","aria-label":"Workflow phases",children:f1.map((t,n)=>{const r=t.id===e,i=f1.findIndex(s=>s.id===e)>f1.findIndex(s=>s.id===t.id);return a.jsxs(Zn.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:A("h-2 w-2 rounded-full transition-colors duration-200",r||i?t.color.replace("text-","bg-"):"bg-white/20"),"aria-hidden":"true"}),a.jsx("span",{className:A("text-xs font-medium transition-colors duration-200",r?t.color:"text-white/40"),children:t.label})]}),n<f1.length-1&&a.jsx(pt,{className:"h-3 w-3 text-white/20","aria-hidden":"true"})]},t.id)})})}function k1e({messages:e,toolActivities:t,currentActivity:n,isRunning:r,isEmpty:i,renderMessage:s,messagesEndRef:o,composer:l,onExport:c,repoName:d,branchName:p,onSuggestedPromptClick:h}){var O;const m=f.useRef(null),[g,x]=f.useState(!0),[k,w]=f.useState(!1),{sessions:y,activeSessionId:b,switchSession:v}=ri(),S=f.useMemo(()=>y.find(L=>L.id===b),[y,b]),N=(O=S==null?void 0:S.contextState)==null?void 0:O.contextUtilizationPercent,E=(S==null?void 0:S.splitSuggested)||N!=null&&N>=85,M=f.useCallback(L=>{v(L)},[v]);f.useEffect(()=>{g&&m.current&&(m.current.scrollTop=m.current.scrollHeight)},[e,r,n,g]);const j=f.useCallback(()=>{if(!m.current)return;const{scrollTop:L,scrollHeight:z,clientHeight:G}=m.current,B=z-L-G;x(B<50),w(B>100)},[]),_=f.useCallback(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight,x(!0),w(!1))},[]),C=f.useCallback(L=>{h==null||h(L)},[h]);return i?a.jsxs("div",{className:"flex-1 flex flex-col",children:[a.jsx("div",{className:"flex-1 flex items-center justify-center px-6",children:a.jsxs(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"w-full max-w-2xl space-y-6",children:[d&&p&&a.jsx(y1e,{repoName:d,branchName:p}),a.jsxs("div",{className:"text-center",children:[a.jsx("div",{className:"mx-auto mb-4 flex h-20 w-20 items-center justify-center rounded-3xl bg-gradient-to-br from-orange-500/20 via-amber-500/20 to-yellow-500/10 ring-1 ring-white/10",children:a.jsx(nn,{className:"h-10 w-10 text-orange-400"})}),a.jsx("h2",{className:"text-2xl font-semibold text-white mb-2",children:"What should we build?"}),a.jsx("p",{className:"text-sm text-white/60 leading-relaxed max-w-lg mx-auto",children:d?"I can help you build features, fix bugs, refactor code, or explore your codebase.":"Let's brainstorm and plan. We can add a repository later when you're ready to build."})]}),a.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[a.jsx(m1,{title:"Fix a bug",description:"Describe the issue and I'll help debug and fix it",icon:ep,promptText:"I need help fixing a bug: ",theme:"red",onClick:C}),a.jsx(m1,{title:"Build a feature",description:"Tell me what you want to add and I'll implement it",icon:nn,promptText:"Let's build a new feature: ",theme:"blue",onClick:C}),a.jsx(m1,{title:"Refactor code",description:"Point to code that needs improvement",icon:ua,promptText:"I'd like to refactor ",theme:"emerald",onClick:C}),a.jsx(m1,{title:"Explain codebase",description:"Ask about how something works",icon:Xu,promptText:"Can you explain ",theme:"purple",onClick:C})]}),a.jsx("div",{className:"flex justify-center",children:a.jsx(b1e,{currentPhase:"prompt"})})]})}),a.jsx("div",{className:"w-full px-4 pb-4",children:l})]}):a.jsxs("div",{className:"flex-1 flex flex-col min-h-0 relative",children:[E&&b&&a.jsx(g1e,{sessionId:b,utilizationPercent:N??85,onSwitchSession:M}),a.jsx("div",{ref:m,onScroll:j,className:"flex-1 overflow-y-auto py-4 space-y-1",children:a.jsxs("div",{className:"w-full px-4",children:[e.map((L,z)=>z===e.length-1?a.jsx(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},children:s(L,z)},L.id):a.jsx("div",{children:s(L,z)},L.id)),a.jsx("div",{ref:o})]})}),a.jsx(Ce,{children:k&&a.jsx(q.button,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},onClick:_,className:"absolute bottom-20 right-6 z-10 flex h-8 w-8 items-center justify-center rounded-full bg-white/10 ring-1 ring-white/20 backdrop-blur-sm hover:bg-white/20 transition-colors",title:"Scroll to bottom",children:a.jsx(Xe,{className:"h-4 w-4 text-white/70"})})}),a.jsx("div",{className:"w-full px-4 pb-4 pt-2 border-t border-white/5",children:l})]})}function w1e({sessionId:e,repoId:t,files:n,onFileApprove:r,onApproveAll:i,onClearAll:s,onDiscardFile:o,onDeleteFile:l,onNavigateToShip:c}){const[d,p]=f.useState(n.length>0?n[0].path:null),[h,m]=f.useState(""),[g,x]=f.useState(!1),[k,w]=f.useState(new Set),[y,b]=f.useState(null),v=f.useRef(null),S=f.useCallback((z,G)=>{v.current&&clearTimeout(v.current),b({path:z,action:G}),v.current=setTimeout(()=>b(null),3e3)},[]),N=f.useCallback(()=>{v.current&&clearTimeout(v.current),b(null)},[]),E=f.useCallback(()=>{y&&(y.action==="discard"?o(y.path):l(y.path),b(null),v.current&&clearTimeout(v.current))},[y,o,l]);f.useEffect(()=>()=>{v.current&&clearTimeout(v.current)},[]);const M=n.filter(z=>z.approved).length,j=n.length,_=M===j&&j>0,C=f.useMemo(()=>{const z={};return n.forEach(G=>{const B=G.path.split("/"),te=B.length>1?B.slice(0,-1).join("/"):".";z[te]||(z[te]=[]),z[te].push(G)}),z},[n]);f.useEffect(()=>{if(!d||!e)return;(async()=>{x(!0);try{const G={filePath:d,staged:!1};t&&(G.repoId=t);const B=await F("POST",`/terminal/sessions/${e}/file-diff`,G);m(B.diff||"No changes")}catch(G){console.error("Failed to load diff:",G),m("Failed to load diff")}finally{x(!1)}})()},[d,e,t]);const O=z=>{w(G=>{const B=new Set(G);return B.has(z)?B.delete(z):B.add(z),B})},L=z=>{switch(z){case"added":return a.jsx(Hl,{className:"h-4 w-4 text-emerald-400"});case"deleted":return a.jsx(cp,{className:"h-4 w-4 text-red-400"});case"modified":case"renamed":return a.jsx(Ar,{className:"h-4 w-4 text-amber-400"});default:return a.jsx(_a,{className:"h-4 w-4 text-white/40"})}};return n.length===0?a.jsx("div",{className:"flex-1 flex items-center justify-center",children:a.jsxs("div",{className:"text-center",children:[a.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-white/5 ring-1 ring-white/10",children:a.jsx(Qn,{className:"h-8 w-8 text-white/30"})}),a.jsx("h2",{className:"text-lg font-semibold text-white mb-2",children:"No changes to review"}),a.jsx("p",{className:"text-sm text-white/50",children:"Files modified by Claude will appear here for review."})]})}):a.jsxs("div",{className:"flex-1 flex flex-col sm:flex-row min-h-0 gap-3 sm:gap-4 p-3 sm:p-4 overflow-y-auto sm:overflow-y-hidden",children:[a.jsxs("div",{className:"w-full sm:w-64 sm:flex-shrink-0 flex flex-col rounded-xl bg-white/[0.03] ring-1 ring-white/10 overflow-hidden",children:[a.jsxs("div",{className:"px-3 py-2.5 border-b border-white/10 flex items-center justify-between",children:[a.jsx("span",{className:"text-xs font-medium text-white/50 uppercase tracking-wider",children:"Changed Files"}),a.jsxs("span",{className:"text-xs text-white/40",children:[M,"/",j]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:Object.entries(C).map(([z,G])=>a.jsxs("div",{children:[z!=="."&&a.jsxs("button",{onClick:()=>O(z),className:"flex items-center gap-1 w-full px-2 py-1 text-xs text-white/40 hover:text-white/60",children:[k.has(z)||!k.size?a.jsx(Xe,{className:"h-3 w-3"}):a.jsx(pt,{className:"h-3 w-3"}),a.jsx("span",{className:"truncate font-mono",children:z})]}),a.jsx(Ce,{children:(z==="."||k.has(z)||!k.size)&&G.map(B=>{const te=(y==null?void 0:y.path)===B.path,Y=B.status==="modified"||B.status==="deleted",R=B.status==="added";return a.jsxs(q.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:A("group flex items-center gap-2 w-full px-2 py-1.5 rounded-lg text-left transition-colors cursor-pointer",d===B.path?"bg-white/10 ring-1 ring-white/20":"hover:bg-white/5",z!=="."&&"ml-3"),onClick:()=>p(B.path),children:[L(B.status),a.jsx("span",{className:"flex-1 text-sm text-white/80 truncate font-mono",children:B.path.split("/").pop()}),te?a.jsxs("span",{className:"flex items-center gap-1 flex-shrink-0",onClick:H=>H.stopPropagation(),children:[a.jsx("button",{onClick:E,className:"text-[10px] font-medium text-red-400 hover:text-red-300 px-1.5 py-0.5 rounded bg-red-500/10 hover:bg-red-500/20 transition-colors",children:"Confirm?"}),a.jsx("button",{onClick:N,className:"p-0.5 text-white/40 hover:text-white/60 transition-colors",children:a.jsx(ve,{className:"h-3 w-3"})})]}):a.jsxs(a.Fragment,{children:[B.approved&&a.jsx(ke,{className:"h-3.5 w-3.5 text-emerald-400 flex-shrink-0 group-hover:hidden"}),a.jsxs("span",{className:A("items-center gap-0.5 flex-shrink-0 hidden group-hover:flex"),onClick:H=>H.stopPropagation(),children:[a.jsx("button",{onClick:()=>r(B.path),className:A("p-1 rounded transition-colors",B.approved?"text-emerald-400 hover:text-emerald-300":"text-white/30 hover:text-emerald-400"),title:B.approved?"Unapprove":"Approve",children:a.jsx(ke,{className:"h-3.5 w-3.5"})}),Y&&a.jsx("button",{onClick:()=>S(B.path,"discard"),className:"p-1 rounded text-white/30 hover:text-red-400 transition-colors",title:"Discard changes",children:a.jsx(gd,{className:"h-3.5 w-3.5"})}),R&&a.jsx("button",{onClick:()=>S(B.path,"delete"),className:"p-1 rounded text-white/30 hover:text-red-400 transition-colors",title:"Delete file",children:a.jsx(St,{className:"h-3.5 w-3.5"})})]})]})]},B.path)})})]},z))}),a.jsxs("div",{className:"p-3 border-t border-white/10 space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("button",{onClick:i,disabled:_,className:A("flex-1 flex items-center justify-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors",_?"bg-emerald-500/20 text-emerald-400 cursor-default":"bg-white/10 text-white hover:bg-white/15"),children:[a.jsx(tp,{className:"h-4 w-4"}),_?"All Approved":"Approve All"]}),M>0&&!_&&a.jsxs("button",{onClick:s,className:"flex items-center justify-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium text-white/50 hover:text-white/80 hover:bg-white/5 transition-colors",children:[a.jsx(ve,{className:"h-3.5 w-3.5"}),"Clear"]})]}),_&&a.jsxs(a.Fragment,{children:[a.jsxs("button",{onClick:s,className:"w-full flex items-center justify-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium text-white/40 hover:text-white/60 hover:bg-white/5 transition-colors",children:[a.jsx(ve,{className:"h-3 w-3"}),"Clear All Approvals"]}),a.jsxs("button",{onClick:c,className:"w-full flex items-center justify-center gap-2 rounded-lg bg-emerald-600 px-3 py-2 text-sm font-medium text-white hover:bg-emerald-500 transition-colors",children:["Ready to Ship",a.jsx(pt,{className:"h-4 w-4"})]})]})]})]}),a.jsxs("div",{className:"hidden sm:flex flex-1 flex-col rounded-xl bg-white/[0.03] ring-1 ring-white/10 overflow-hidden min-w-0",children:[d&&(()=>{const z=n.find(R=>R.path===d),G=(z==null?void 0:z.status)||"modified",B=(y==null?void 0:y.path)===d,te=G==="modified"||G==="deleted",Y=G==="added";return a.jsxs("div",{className:"px-4 py-3 border-b border-white/10 flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[L(G),a.jsx("span",{className:"text-sm font-mono text-white/80 truncate",children:d})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[B?a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsxs("button",{onClick:E,className:"flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium bg-red-500/20 text-red-400 hover:bg-red-500/30 transition-colors",children:["Confirm ",y.action==="discard"?"Discard":"Delete","?"]}),a.jsx("button",{onClick:N,className:"p-1.5 rounded-lg text-white/40 hover:text-white/60 hover:bg-white/5 transition-colors",children:a.jsx(ve,{className:"h-4 w-4"})})]}):a.jsxs(a.Fragment,{children:[te&&a.jsxs("button",{onClick:()=>S(d,"discard"),className:"flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium text-red-400/70 hover:text-red-400 hover:bg-red-500/10 transition-colors",children:[a.jsx(gd,{className:"h-4 w-4"}),"Discard"]}),Y&&a.jsxs("button",{onClick:()=>S(d,"delete"),className:"flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium text-red-400/70 hover:text-red-400 hover:bg-red-500/10 transition-colors",children:[a.jsx(St,{className:"h-4 w-4"}),"Delete"]})]}),a.jsxs("button",{onClick:()=>r(d),className:A("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium transition-colors",z!=null&&z.approved?"bg-emerald-500/20 text-emerald-400":"bg-white/10 text-white hover:bg-white/15"),children:[a.jsx(ke,{className:"h-4 w-4"}),z!=null&&z.approved?"Approved":"Approve"]})]})]})})(),a.jsx("div",{className:"flex-1 overflow-auto p-4",children:g?a.jsx("div",{className:"flex items-center justify-center h-full",children:a.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-white/10 border-t-white/50"})}):a.jsx(v1e,{diff:h})})]}),a.jsxs("div",{className:"w-full sm:w-56 sm:flex-shrink-0 flex flex-row sm:flex-col gap-3 sm:gap-4",children:[a.jsxs("div",{className:"flex-1 sm:flex-none rounded-xl bg-white/[0.03] ring-1 ring-white/10 p-4",children:[a.jsx("div",{className:"text-xs font-medium text-white/50 uppercase tracking-wider mb-3",children:"Review Progress"}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("span",{className:"text-2xl font-semibold text-white",children:[Math.round(M/j*100),"%"]}),a.jsxs("span",{className:"text-sm text-white/50",children:[M," of ",j]})]}),a.jsx("div",{className:"h-2 rounded-full bg-white/10 overflow-hidden",children:a.jsx(q.div,{initial:{width:0},animate:{width:`${M/j*100}%`},className:"h-full bg-emerald-500 rounded-full"})})]})]}),a.jsxs("div",{className:"flex-1 sm:flex-none rounded-xl bg-white/[0.03] ring-1 ring-white/10 p-4",children:[a.jsx("div",{className:"text-xs font-medium text-white/50 uppercase tracking-wider mb-3",children:"Changes"}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white/60",children:"Added"}),a.jsxs("span",{className:"text-sm text-emerald-400 font-mono",children:["+",n.reduce((z,G)=>z+(G.insertions||0),0)]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white/60",children:"Removed"}),a.jsxs("span",{className:"text-sm text-red-400 font-mono",children:["-",n.reduce((z,G)=>z+(G.deletions||0),0)]})]})]})]}),n.some(z=>["auth","secret",".env","password","token","key"].some(G=>z.path.toLowerCase().includes(G)))&&a.jsx("div",{className:"rounded-xl bg-amber-500/10 ring-1 ring-amber-500/20 p-4",children:a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsx(Ge,{className:"h-4 w-4 text-amber-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-medium text-amber-400",children:"Security Review"}),a.jsx("p",{className:"text-xs text-amber-400/70 mt-1",children:"Some files may contain sensitive code. Review carefully."})]})]})})]})]})}function v1e({diff:e}){const t=e.split(`
|
|
7790
|
+
`).filter(g=>g.trim()),m=(l=h[h.length-1])==null?void 0:l.trim();m&&t().updateSession(d,{currentActivity:m})}}break;case"message-complete":d&&c.messageId&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,currentActivity:void 0,messages:h.messages.map(m=>m.id===c.messageId?{...m,isStreaming:!1}:m)}:h)}));break;case"file-change":d&&c.messageId&&c.change&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>m.id===c.messageId?{...m,fileChanges:[...(m.fileChanges||[]).filter(g=>g.filePath!==c.change.filePath),c.change]}:m)}:h)}));break;case"file-changes-complete":d&&c.messageId&&Array.isArray(c.fileChanges)&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>m.id===c.messageId?{...m,fileChanges:c.fileChanges}:m)}:h)}));break;case"mode-changed":d&&c.mode&&t().updateSession(d,{mode:c.mode});break;case"phase-changed":d&&c.phase&&console.log(`[Terminal] Phase changed to ${c.phase} for session ${d}`);break;case"workflow-blocked":d&&c.message&&console.warn("[Terminal] Workflow blocked:",c.message);break;case"bookmark-changed":d&&typeof c.isBookmarked=="boolean"&&t().updateSession(d,{isBookmarked:c.isBookmarked,bookmarkedAt:c.isBookmarked?new Date:void 0});break;case"cancelled":d&&t().updateSession(d,{status:"idle"});break;case"chain-segment-start":d&&c.messageId!=null&&c.segmentIndex!=null&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>{if(m.id!==c.messageId)return m;const g=[...m.chainSegments||[]];for(;g.length<=c.segmentIndex;)g.push({agentId:"",agentName:"",status:"pending",content:""});return g[c.segmentIndex]={agentId:c.agentId||"",agentName:c.agentName||c.agentId||"",status:"running",content:"",startedAt:new Date().toISOString()},{...m,agentId:c.agentId||m.agentId,agentName:c.agentName||c.agentId||m.agentName,chainSegments:g,chainStatus:"running"}})}:h)}));break;case"chain-segment-chunk":d&&c.messageId&&c.segmentIndex!=null&&c.content&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>{if(m.id!==c.messageId||!m.chainSegments)return m;const g=[...m.chainSegments];return g[c.segmentIndex]&&(g[c.segmentIndex]={...g[c.segmentIndex],content:g[c.segmentIndex].content+c.content}),{...m,chainSegments:g}})}:h)}));break;case"chain-segment-complete":d&&c.messageId&&c.segmentIndex!=null&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>{if(m.id!==c.messageId||!m.chainSegments)return m;const g=[...m.chainSegments];return g[c.segmentIndex]&&(g[c.segmentIndex]={...g[c.segmentIndex],status:"completed",completedAt:new Date().toISOString()}),{...m,chainSegments:g}})}:h)}));break;case"chain-segment-error":d&&c.messageId&&c.segmentIndex!=null&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>{if(m.id!==c.messageId||!m.chainSegments)return m;const g=[...m.chainSegments];return g[c.segmentIndex]&&(g[c.segmentIndex]={...g[c.segmentIndex],status:"failed",error:c.error||"Unknown error",completedAt:new Date().toISOString()}),{...m,chainSegments:g,chainStatus:"partial"}})}:h)}));break;case"chain-complete":d&&c.messageId&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,messages:h.messages.map(m=>m.id!==c.messageId?m:{...m,isStreaming:!1,chainStatus:c.status||"completed"})}:h)}));break;case"messages-cleared":d&&t().updateSession(d,{messages:[]});break;case"tool-start":d&&c.activityId&&c.tool&&e(p=>{const h=p.sessions.find(k=>k.id===d),m=(h==null?void 0:h.toolActivities)||[];if(m.some(k=>k.tool===c.tool&&k.target===(c.target||"")&&k.status==="running"))return p;const x={id:c.activityId,tool:c.tool,target:c.target||"",status:"running",timestamp:new Date};return{sessions:p.sessions.map(k=>k.id===d?{...k,toolActivities:[...m,x].slice(-50)}:k)}});break;case"tool-complete":d&&c.activityId&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,toolActivities:(h.toolActivities||[]).map(m=>m.id===c.activityId?{...m,status:"complete",completedAt:new Date}:m)}:h)}));break;case"tool-error":d&&c.activityId&&e(p=>({sessions:p.sessions.map(h=>h.id===d?{...h,toolActivities:(h.toolActivities||[]).map(m=>m.id===c.activityId?{...m,status:"error",error:c.error,completedAt:new Date}:m)}:h)}));break;case"queue-updated":d&&Array.isArray(c.queue)&&t().updateSession(d,{messageQueue:c.queue.map(p=>({...p,queuedAt:new Date(p.queuedAt)}))});break;case"usage-update":d&&c.sessionStats&&t().updateSession(d,{usageStats:c.sessionStats,currentModel:c.model});break;case"context_state_update":d&&c.contextState&&t().updateSession(d,{contextState:c.contextState});break;case"context_split_suggested":d&&t().updateSession(d,{splitSuggested:!0});break;case"error":console.error("[Terminal] Error:",c.error),d&&t().updateSession(d,{status:"error"});break;case"mcp-tool-approval-needed":d&&c.approvalId&&e(p=>({pendingMCPApproval:{sessionId:d,approvalId:c.approvalId,toolName:c.toolName,serverName:c.serverName,serverId:c.serverId,description:c.description,inputParameters:c.inputParameters||{}}}));break;case"system:update-available":Xl.getState().setUpdateAvailable(c.currentVersion,c.latestVersion);break;case"system:update-starting":case"system:update-progress":c.stage&&Xl.getState().setUpdateProgress(c.stage,c.detail);break;case"system:update-complete":Xl.getState().setUpdateComplete(c.success,c.error);break}}catch(c){console.error("[Terminal] Failed to parse message:",c)}},e({ws:s})},disconnect:()=>{const{ws:n}=t();n&&(n.close(),e({ws:null,isConnected:!1}))},updateSession:(n,r)=>{e(i=>({sessions:i.sessions.map(s=>s.id===n?{...s,...r}:s)}))},appendChunk:(n,r,i)=>{e(s=>({sessions:s.sessions.map(o=>o.id!==n?o:{...o,messages:o.messages.map(l=>l.id!==r||i.length>10&&l.content.endsWith(i)||i.length>50&&l.content.length>0&&l.content.startsWith(i)||i.length>30&&l.content.includes(i)?l:{...l,content:l.content+i})})}))},fetchGitStatus:async n=>{try{const r=await Vc.fetch($c.GIT_STATUS(n),()=>F("GET",`/terminal/sessions/${n}/git-status`),{staleTime:5e3});t().updateSession(n,{gitStatus:r})}catch(r){console.error("Failed to fetch git status:",r)}},fetchContextState:async n=>{try{const r=await F("GET",`/terminal/sessions/${n}/context`);r&&t().updateSession(n,{contextState:r})}catch(r){console.error("Failed to fetch context state:",r)}},splitSession:async n=>{try{const r=await F("POST",`/terminal/sessions/${n}/context/split`);return r!=null&&r.id?(await t().loadSessions(),r.id):null}catch(r){return console.error("Failed to split session:",r),null}},fetchMultiGitStatus:async n=>{try{const r=await F("GET",`/terminal/sessions/${n}/multi-git-status`),i=t().sessions.find(s=>s.id===n);if(i&&i.repoIds.length>0){const s=r.repos[i.repoIds[0]];s&&t().updateSession(n,{gitStatus:s})}}catch(r){console.error("Failed to fetch multi-repo git status:",r)}},toggleBookmark:async n=>{const r=t().sessions.find(s=>s.id===n);if(!r)return;const i=!r.isBookmarked;t().updateSession(n,{isBookmarked:i,bookmarkedAt:i?new Date:void 0});try{await F("PATCH",`/terminal/sessions/${n}/bookmark`,{isBookmarked:i})}catch(s){t().updateSession(n,{isBookmarked:!i,bookmarkedAt:i?void 0:new Date}),console.error("Failed to toggle bookmark:",s)}},toggleMessageBookmark:(n,r)=>{e(i=>({sessions:i.sessions.map(s=>s.id===n?{...s,messages:s.messages.map(o=>o.id===r?{...o,isBookmarked:!o.isBookmarked}:o)}:s)}))},exportSession:(n,r)=>{const i=`/api/terminal/sessions/${n}/export?format=${r}`,s=document.createElement("a");s.href=i,s.download="",document.body.appendChild(s),s.click(),document.body.removeChild(s)},searchSessions:async n=>{if(!n.trim()){e({searchResults:[],isSearching:!1});return}e({isSearching:!0});try{const r=await F("GET",`/terminal/sessions/search?q=${encodeURIComponent(n)}`);e({searchResults:r.map(i=>({...i,timestamp:new Date(i.timestamp)})),isSearching:!1})}catch(r){console.error("Search failed:",r),e({searchResults:[],isSearching:!1})}},clearSearchResults:()=>{e({searchResults:[],isSearching:!1})},removeFromQueue:n=>{const{ws:r,activeSessionId:i}=t();!r||r.readyState!==WebSocket.OPEN||!i||r.send(JSON.stringify({type:"remove-from-queue",sessionId:i,messageId:n}))},clearQueue:()=>{const{ws:n,activeSessionId:r}=t();!n||n.readyState!==WebSocket.OPEN||!r||n.send(JSON.stringify({type:"clear-queue",sessionId:r}))},resumeQueue:()=>{const{ws:n,activeSessionId:r}=t();!n||n.readyState!==WebSocket.OPEN||!r||n.send(JSON.stringify({type:"resume-queue",sessionId:r}))},addPendingAttachment:async(n,r)=>{const i=Math.random().toString(36).substring(2,15),s=r.type.startsWith("image/");let o;s&&(o=await new Promise(c=>{const d=new FileReader;d.onload=()=>c(d.result),d.readAsDataURL(r)}));const l={id:i,file:r,preview:o,uploading:!1};e(c=>{const d=new Map(c.pendingAttachments),p=d.get(n)||[];return d.set(n,[...p,l]),{pendingAttachments:d}})},removePendingAttachment:(n,r)=>{e(i=>{const s=new Map(i.pendingAttachments),o=s.get(n)||[];return s.set(n,o.filter(l=>l.id!==r)),{pendingAttachments:s}})},clearPendingAttachments:n=>{e(r=>{const i=new Map(r.pendingAttachments);return i.set(n,[]),{pendingAttachments:i}})},getPendingAttachments:n=>t().pendingAttachments.get(n)||[],addToolActivity:(n,r)=>{const i={...r,id:Math.random().toString(36).substring(2,15),timestamp:new Date};e(s=>({sessions:s.sessions.map(o=>o.id===n?{...o,toolActivities:[...o.toolActivities||[],i].slice(-50)}:o)}))},clearToolActivities:n=>{e(r=>({sessions:r.sessions.map(i=>i.id===n?{...i,toolActivities:[]}:i)}))},setPendingPlan:(n,r,i)=>{e(s=>({sessions:s.sessions.map(o=>o.id===n?{...o,pendingPlan:{messageId:r,questions:i,additionalContext:""}}:o)}))},answerPlanQuestion:(n,r,i)=>{e(s=>({sessions:s.sessions.map(o=>o.id===n&&o.pendingPlan?{...o,pendingPlan:{...o.pendingPlan,questions:o.pendingPlan.questions.map(l=>l.id===r?{...l,answer:i}:l)}}:o)}))},setAdditionalContext:(n,r)=>{e(i=>({sessions:i.sessions.map(s=>s.id===n&&s.pendingPlan?{...s,pendingPlan:{...s.pendingPlan,additionalContext:r}}:s)}))},approvePlan:n=>{const{ws:r,sessions:i}=t(),s=i.find(c=>c.id===n);if(!r||r.readyState!==WebSocket.OPEN||!(s!=null&&s.pendingPlan))return;const o={};for(const c of s.pendingPlan.questions)c.answer&&(o[c.question]=c.answer);const l=s.pendingPlan.messageId;r.send(JSON.stringify({type:"approve-plan",sessionId:n,messageId:l,answers:o,additionalContext:s.pendingPlan.additionalContext||""})),e(c=>({sessions:c.sessions.map(d=>d.id===n?{...d,pendingPlan:void 0,approvedPlanMessageId:l}:d)}))},cancelPlan:n=>{e(r=>({sessions:r.sessions.map(i=>i.id===n?{...i,pendingPlan:void 0}:i)}))},setShowPreviewPanel:n=>e({showPreviewPanel:n}),setShowStartAppModal:n=>e({showStartAppModal:n}),approveMCPTool:async(n,r)=>{try{await F("POST",`/mcp/approve/${n}`,{autoApproveSession:r}),e({pendingMCPApproval:null})}catch(i){throw console.error("[Terminal] Failed to approve MCP tool:",i),i}},denyMCPTool:async n=>{try{await F("POST",`/mcp/deny/${n}`),e({pendingMCPApproval:null})}catch(r){throw console.error("[Terminal] Failed to deny MCP tool:",r),r}},clearMCPApproval:()=>e({pendingMCPApproval:null})}));function o1e(e){return e>=85?"bg-red-500":e>=70?"bg-orange-500":e>=50?"bg-yellow-500":"bg-emerald-500"}function l1e(e){return e>=85?"text-red-400":e>=70?"text-orange-400":e>=50?"text-yellow-400":"text-emerald-400"}const CK=f.memo(function({className:t,contextState:n,onSummarize:r}){var y;const{sessions:i,activeSessionId:s,fetchContextState:o}=ri(),l=f.useMemo(()=>i.find(b=>b.id===s),[i,s]);f.useEffect(()=>{var b;n===void 0&&s&&l&&(((b=l.messages)==null?void 0:b.length)||0)>0&&o(s)},[s,o,(y=l==null?void 0:l.messages)==null?void 0:y.length,n]);const c=n!==void 0?n:l==null?void 0:l.contextState,d=f.useCallback(async()=>{if(r){r();return}if(s)try{await F("POST",`/terminal/sessions/${s}/context/summarize`)}catch(b){console.error("[ContextGauge] Failed to trigger summarization:",b)}},[s,r]);if(!c)return null;const p=c.contextUtilizationPercent,h=c.summarizationStatus,m=p>=70&&h==="none",g=h==="in_progress",x=h==="completed",k=[`Context: ${p}%`,`Est. tokens: ${c.estimatedPromptTokens.toLocaleString()}`];if(c.tokenBreakdown){const{messagesEstimated:b,summariesEstimated:v,systemOverhead:S,responseBuffer:N}=c.tokenBreakdown;k.push(` Messages: ${b.toLocaleString()}`,v>0?` Summaries: ${v.toLocaleString()}`:null,` System: ${S.toLocaleString()}`,` Buffer: ${N.toLocaleString()}`)}if(k.push(`Available: ${(c.availablePromptTokens||c.modelContextWindow).toLocaleString()}`,`Messages: ${c.totalMessageCount} (${c.verbatimMessageCount} verbatim)`,c.summaryCount>0?`Summaries: ${c.summaryCount}`:null),c.estimationAccuracy&&c.confidenceLevel){const b=Math.round(c.estimationAccuracy*100);k.push(`Accuracy: ${b}% (${c.confidenceLevel})`)}const w=k.filter(Boolean).join(`
|
|
7791
|
+
`);return a.jsxs("div",{className:A("flex items-center gap-1.5",t),title:w,children:[a.jsx(Wc,{className:"h-3 w-3 text-zinc-500 shrink-0"}),a.jsx("div",{className:"w-16 h-1.5 bg-white/10 rounded-full overflow-hidden",children:a.jsx("div",{className:A("h-full rounded-full transition-all duration-500",o1e(p)),style:{width:`${Math.min(p,100)}%`}})}),a.jsxs("span",{className:A("text-[10px] font-medium tabular-nums",l1e(p)),children:[p,"%"]}),m&&a.jsx("button",{onClick:d,className:"text-[10px] text-white/40 hover:text-white/70 px-1.5 py-0.5 rounded bg-white/5 hover:bg-white/10 transition-colors",children:"Summarize"}),g&&a.jsx(he,{className:"h-3 w-3 text-blue-400 animate-spin"}),x&&a.jsx(ke,{className:"h-3 w-3 text-emerald-400"})]})});function fq({value:e,onChange:t,onSend:n,onStop:r,onKeyDown:i,inputRef:s,isRunning:o,contextState:l,onSummarize:c}){f.useEffect(()=>{s.current&&(s.current.style.height="auto",s.current.style.height=`${Math.min(s.current.scrollHeight,200)}px`)},[e,s]);const d=e.trim().length>0;return a.jsxs("div",{className:"w-full max-w-4xl mx-auto",children:[a.jsxs("div",{className:A("relative flex items-end gap-2.5 rounded-2xl px-5 py-3.5 transition-all duration-200","bg-gradient-to-br from-white/[0.05] via-white/[0.03] to-white/[0.02]","ring-1 backdrop-blur-sm",o?"ring-purple-500/30":d?"ring-purple-500/25 focus-within:ring-purple-500/40 focus-within:shadow-lg focus-within:shadow-purple-500/10":"ring-purple-500/15 focus-within:ring-purple-500/30"),children:[a.jsx("textarea",{ref:s,value:e,onChange:p=>t(p.target.value),onKeyDown:i,placeholder:"Type your idea or question...","aria-label":"Type your idea or question",className:"flex-1 bg-transparent text-white/90 text-[15px] leading-[1.6] placeholder-white/30 resize-none outline-none min-h-[24px] max-h-[200px]",rows:1,disabled:o}),o?a.jsx("button",{onClick:r,"aria-label":"Stop generation",className:A("flex-shrink-0 flex items-center justify-center rounded-lg transition-all duration-200","h-10 w-10 sm:h-9 sm:w-9","bg-gradient-to-br from-red-500/15 to-red-600/10 text-red-400","ring-1 ring-red-500/30","hover:bg-red-500/20 hover:ring-red-500/40 hover:shadow-lg hover:shadow-red-500/10","active:scale-95"),children:a.jsx(ya,{className:"h-4 w-4"})}):a.jsx("button",{onClick:n,disabled:!d,"aria-label":"Send message","aria-disabled":!d,className:A("flex-shrink-0 flex items-center justify-center rounded-lg transition-all duration-200","h-10 w-10 sm:h-9 sm:w-9",d?["bg-gradient-to-br from-purple-500/20 via-purple-500/15 to-purple-600/20","text-purple-300 ring-1 ring-purple-500/30","hover:from-purple-500/25 hover:via-purple-500/20 hover:to-purple-600/25","hover:ring-purple-500/40 hover:shadow-lg hover:shadow-purple-500/10","active:scale-95"]:"bg-white/[0.02] text-white/20 ring-1 ring-white/5 cursor-not-allowed opacity-50"),children:a.jsx(cd,{className:"h-4 w-4"})})]}),a.jsxs("div",{className:"flex items-center justify-between mt-2.5 px-2",children:[a.jsx("div",{className:"flex items-center gap-2",children:o?a.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] text-purple-400/70",children:[a.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-purple-400 animate-pulse"}),"Claude is thinking..."]}):a.jsx("span",{className:A("text-[11px] transition-colors duration-200",d?"text-white/30":"text-white/20"),children:"Ctrl+Enter to send"})}),a.jsxs("div",{className:"flex items-center gap-2",children:[o&&a.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-purple-400/50",children:[a.jsx(he,{className:"h-2.5 w-2.5 animate-spin"}),"Streaming"]}),a.jsx(CK,{contextState:l??null,onSummarize:c})]})]})]})}function c1e({utilizationPercent:e}){const[t,n]=f.useState(!1);return t?null:a.jsx(Ce,{children:a.jsxs(q.div,{initial:{opacity:0,y:-12,height:0},animate:{opacity:1,y:0,height:"auto"},exit:{opacity:0,y:-12,height:0},transition:{duration:.3,ease:[.4,0,.2,1]},role:"alert","aria-live":"polite","aria-label":`Context is ${e}% full`,className:A("mx-6 mt-2 mb-1 rounded-xl px-5 sm:px-6 py-3.5 flex items-center gap-3.5 ring-1","bg-gradient-to-br from-amber-500/15 via-amber-500/10 to-amber-500/5","ring-amber-500/30"),children:[a.jsx("div",{className:"flex-shrink-0 flex items-center justify-center h-8 w-8 rounded-lg bg-amber-500/20",children:a.jsx(Ge,{className:"h-4 w-4 text-amber-400"})}),a.jsxs("p",{className:"flex-1 text-sm font-medium text-amber-300 leading-relaxed",children:["Context is ",a.jsxs("span",{className:"font-semibold text-amber-200",children:[e,"%"]})," full. Consider starting a new idea to keep responses sharp."]}),a.jsx("button",{type:"button",onClick:()=>n(!0),"aria-label":"Dismiss context warning",className:A("flex-shrink-0 flex items-center justify-center h-7 w-7 rounded-lg","transition-colors duration-200","hover:bg-amber-500/20","focus:outline-none focus:ring-2 focus:ring-amber-500/40"),children:a.jsx(ve,{className:"h-4 w-4 text-amber-400"})})]})})}function d1e({onClick:e}){return a.jsx(q.button,{initial:{opacity:0,scale:.8,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.8,y:10},whileHover:{scale:1.05},whileTap:{scale:.95},transition:{duration:.2,ease:[.4,0,.2,1]},onClick:e,"aria-label":"Scroll to latest message",className:A("flex items-center justify-center rounded-xl backdrop-blur-sm","h-10 w-10 sm:h-9 sm:w-9","bg-gradient-to-br from-purple-500/15 via-purple-500/10 to-purple-600/10","ring-1 ring-purple-500/25","shadow-lg shadow-purple-500/10","hover:ring-purple-500/35 hover:shadow-xl hover:shadow-purple-500/15","focus:outline-none focus:ring-2 focus:ring-purple-500/40","transition-all duration-200","touch-manipulation"),children:a.jsx(Xe,{className:"h-5 w-5 text-purple-300"})})}function gq({onOpenAttachModal:e,onOpenPromoteModal:t}){var R,H;const{ideas:n,activeIdeaId:r,sendMessage:i,cancelOperation:s,saveIdea:o,updateIdeaTitle:l,detachFromRepo:c,fetchContextState:d}=Za(),{repos:p}=sn(),h=f.useMemo(()=>n.find(I=>I.id===r),[n,r]),[m,g]=f.useState(""),x=f.useRef(null),k=f.useRef(null),w=f.useRef(null),[y,b]=f.useState(!0),[v,S]=f.useState(!1);f.useEffect(()=>{w.current&&w.current.focus()},[r]),f.useEffect(()=>{r&&h&&h.messages.length>0&&d(r)},[r,d,(R=h==null?void 0:h.messages)==null?void 0:R.length]),f.useEffect(()=>{y&&x.current&&(x.current.scrollTop=x.current.scrollHeight)},[h==null?void 0:h.messages,y]);const N=f.useCallback(()=>{if(!x.current)return;const{scrollTop:I,scrollHeight:Q,clientHeight:Z}=x.current,D=Q-I-Z;b(D<50),S(D>100)},[]),E=f.useCallback(()=>{x.current&&(x.current.scrollTop=x.current.scrollHeight,b(!0),S(!1))},[]),M=f.useCallback(()=>{const I=m.trim();!I||!r||(i(I),g(""))},[m,r,i]),j=f.useCallback(I=>{I.key==="Enter"&&(I.ctrlKey||I.metaKey)&&(I.preventDefault(),M())},[M]),_=f.useCallback(()=>{r&&o(r)},[r,o]),C=f.useCallback(I=>{r&&l(r,I)},[r,l]),O=f.useCallback(I=>{r&&c(r,I)},[r,c]),L=f.useCallback(async()=>{if(r)try{await F("POST",`/ideas/${r}/context/summarize`)}catch(I){console.error("[IdeaView] Failed to trigger summarization:",I)}},[r]),z=f.useMemo(()=>{const I={};for(const Q of p)I[Q.id]=Q.id.split("/").pop()||Q.id;return I},[p]);if(!h)return null;const G=h.chatStatus==="running",B=h.messages.length===0,te=(H=h.contextState)==null?void 0:H.contextUtilizationPercent,Y=h.splitSuggested||te!=null&&te>=85;return a.jsxs("div",{className:"flex-1 flex flex-col min-h-0 bg-[#0a0d14]",children:[a.jsxs("div",{className:"pointer-events-none fixed inset-0 z-0",children:[a.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-purple-500/[0.02] via-transparent to-transparent"}),a.jsx("div",{className:"absolute -top-32 left-1/2 h-64 w-[600px] -translate-x-1/2 rounded-full bg-purple-500/5 blur-3xl"})]}),a.jsx(yoe,{idea:h,onUpdateTitle:C,onSave:_,onAttach:e,onDetach:O,onPromote:t,repoNames:z}),B?a.jsxs("div",{className:"relative z-10 flex-1 flex flex-col",children:[a.jsx("div",{className:"flex-1 flex items-center justify-center px-6",children:a.jsxs(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"text-center max-w-md",children:[a.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-purple-500/20 to-violet-600/20 ring-1 ring-purple-500/20",children:a.jsx(xn,{className:"h-8 w-8 text-purple-400"})}),a.jsx("h2",{className:"text-xl font-semibold text-white mb-2",children:"What would you like to explore?"}),a.jsx("p",{className:"text-sm text-white/50 leading-relaxed",children:"No repo? No problem. Start brainstorming and let your ideas flow."})]})}),a.jsx("div",{className:"w-full px-4 pb-4",children:a.jsx(fq,{value:m,onChange:g,onSend:M,onStop:s,onKeyDown:j,inputRef:w,isRunning:G,contextState:h.contextState,onSummarize:L})})]}):a.jsxs("div",{className:"relative z-10 flex-1 flex flex-col min-h-0",children:[Y&&r&&a.jsx(c1e,{utilizationPercent:te??85}),a.jsx("div",{ref:x,onScroll:N,className:"flex-1 overflow-y-auto py-4 space-y-1",role:"log","aria-live":"polite",children:a.jsxs("div",{className:"w-full px-4",children:[h.messages.map((I,Q)=>Q===h.messages.length-1?a.jsx(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},children:a.jsx(mq,{message:I})},I.id):a.jsx("div",{children:a.jsx(mq,{message:I})},I.id)),a.jsx("div",{ref:k})]})}),a.jsx(Ce,{children:v&&a.jsx("div",{className:"absolute bottom-20 right-6 z-10",children:a.jsx(d1e,{onClick:E})})}),a.jsx("div",{className:"w-full px-4 pb-4 pt-2 border-t border-purple-500/5",children:a.jsx(fq,{value:m,onChange:g,onSend:M,onStop:s,onKeyDown:j,inputRef:w,isRunning:G,contextState:h.contextState,onSummarize:L})})]})]})}function u1e(e){const t=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(t<60)return"just now";const n=Math.floor(t/60);if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function p1e({idea:e,isActive:t,onClick:n}){const r=!!e.promotedToSessionId||!!e.promotedToRepoId,i=e.status==="ephemeral",s=e.attachedRepoIds&&e.attachedRepoIds.length>0,o=e.messages.filter(l=>!l.isStreaming).length;return a.jsxs(q.button,{onClick:n,className:A("w-full text-left rounded-xl p-3 transition-all",r&&"opacity-60",t?"bg-purple-500/10 ring-1 ring-purple-500/30 shadow-[0_0_15px_rgba(139,92,246,0.1)]":i?"bg-white/[0.02] ring-1 ring-white/[0.06] border-dashed opacity-80 hover:opacity-100 hover:bg-white/[0.04]":"bg-white/[0.03] ring-1 ring-white/[0.08] hover:bg-white/[0.05]"),whileHover:{scale:1.01},whileTap:{scale:.99},children:[a.jsxs("div",{className:"flex items-start gap-2 mb-1.5",children:[a.jsx(xn,{className:A("h-3.5 w-3.5 mt-0.5 flex-shrink-0",t?"text-purple-400":"text-purple-400/60")}),a.jsx("span",{className:A("text-sm font-medium truncate flex-1",t?"text-white":"text-white/80"),children:e.title||"Untitled Idea"}),i&&a.jsx("span",{className:"h-2 w-2 rounded-full bg-purple-400/60 flex-shrink-0 mt-1.5"})]}),a.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-white/40",children:[a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(Xn,{className:"h-3 w-3"}),u1e(e.lastActivityAt)]}),o>0&&a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(rr,{className:"h-3 w-3"}),o]})]}),a.jsxs("div",{className:"flex items-center gap-1.5 mt-2",children:[s&&a.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-white/40 bg-white/5 rounded px-1.5 py-0.5",children:[a.jsx(gn,{className:"h-2.5 w-2.5"}),e.attachedRepoIds.length," repo",e.attachedRepoIds.length>1?"s":""]}),r&&a.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-emerald-400/60 bg-emerald-500/10 rounded px-1.5 py-0.5",children:[a.jsx(Dn,{className:"h-2.5 w-2.5"}),"Promoted"]})]})]})}function h1e({ideas:e,activeIdeaId:t,searchQuery:n,onIdeaClick:r}){const i=f.useMemo(()=>{if(!n.trim())return e;const s=n.toLowerCase();return e.filter(o=>{var p,h;const l=(o.title||"Untitled Idea").toLowerCase(),c=(o.tags||[]).join(" ").toLowerCase(),d=((h=(p=o.messages[o.messages.length-1])==null?void 0:p.content)==null?void 0:h.toLowerCase())||"";return l.includes(s)||c.includes(s)||d.includes(s)})},[e,n]);return i.length===0?a.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:a.jsx("p",{className:"text-xs text-white/30 text-center",children:n?"No ideas match your search.":"No ideas yet."})}):a.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-2 space-y-2 scrollbar-none",children:a.jsx(Ce,{mode:"popLayout",children:i.map(s=>a.jsx(q.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},layout:!0,children:a.jsx(p1e,{idea:s,isActive:s.id===t,onClick:()=>r(s.id)})},s.id))})})}function yq({onClose:e}){const{ideas:t,activeIdeaId:n,switchIdea:r,createIdea:i,ideaPanelSearch:s,setIdeaPanelSearch:o}=Za(),l=f.useRef(null);return f.useEffect(()=>{l.current&&l.current.focus()},[]),f.useEffect(()=>{const c=d=>{d.key==="Escape"&&e()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e]),a.jsxs(q.aside,{initial:{x:320,opacity:0},animate:{x:0,opacity:1},exit:{x:320,opacity:0},transition:{type:"spring",damping:25,stiffness:300},className:A("relative flex flex-col border-l border-purple-500/10 bg-[#080b11]/95 backdrop-blur-xl","w-full sm:w-[320px] flex-shrink-0"),children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-purple-500/10",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(xn,{className:"h-4 w-4 text-purple-400"}),a.jsx("h2",{className:"text-sm font-semibold text-white/90",children:"Ideas"})]}),a.jsx("button",{onClick:e,className:"p-1.5 rounded-lg text-white/40 hover:text-white/70 hover:bg-white/5 transition-colors",children:a.jsx(ve,{className:"h-4 w-4"})})]}),a.jsx("div",{className:"px-3 py-2",children:a.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-white/[0.04] ring-1 ring-white/[0.08] px-3 py-2 focus-within:ring-purple-500/30 transition-all",children:[a.jsx(Kt,{className:"h-3.5 w-3.5 text-white/30"}),a.jsx("input",{ref:l,value:s,onChange:c=>o(c.target.value),placeholder:"Search ideas...",className:"flex-1 bg-transparent text-sm text-white/80 placeholder-white/30 outline-none"}),s&&a.jsx("button",{onClick:()=>o(""),className:"text-white/30 hover:text-white/60",children:a.jsx(ve,{className:"h-3 w-3"})})]})}),a.jsx(h1e,{ideas:t,activeIdeaId:n,searchQuery:s,onIdeaClick:c=>r(c)}),a.jsx("div",{className:"px-3 py-3 border-t border-purple-500/10",children:a.jsxs("button",{onClick:()=>i(),className:"w-full flex items-center justify-center gap-2 rounded-xl bg-purple-500/10 px-4 py-2.5 text-sm font-medium text-purple-300 ring-1 ring-purple-500/20 hover:bg-purple-500/15 transition-all",children:[a.jsx(Zt,{className:"h-4 w-4"}),"New Idea",a.jsx("kbd",{className:"ml-1 px-1 py-0.5 rounded bg-purple-500/10 text-[10px] text-purple-400/60 font-mono",children:"Ctrl+I"})]})})]})}function xq({idea:e,repos:t,onAttach:n,onClose:r}){const[i,s]=f.useState(""),[o,l]=f.useState(null),c=f.useRef(null);f.useEffect(()=>{var h;(h=c.current)==null||h.focus()},[]),f.useEffect(()=>{const h=m=>{m.key==="Escape"&&r()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[r]);const d=f.useMemo(()=>{const h=new Set(e.attachedRepoIds||[]);return t.filter(m=>!h.has(m.id)).filter(m=>i.trim()?m.id.toLowerCase().includes(i.toLowerCase()):!0)},[t,i,e.attachedRepoIds]),p=e.status==="ephemeral";return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[a.jsx(q.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:r,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),a.jsxs(q.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative w-full max-w-[520px] rounded-2xl bg-[#0d1117] ring-1 ring-white/10 shadow-2xl overflow-hidden",role:"dialog","aria-label":"Attach repository",children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/10",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Attach Repository"}),a.jsx("button",{onClick:r,className:"p-1.5 rounded-lg text-white/40 hover:text-white/70 hover:bg-white/5 transition-colors",children:a.jsx(ve,{className:"h-5 w-5"})})]}),p&&a.jsxs("div",{className:"mx-6 mt-4 flex items-start gap-3 rounded-xl bg-amber-500/10 ring-1 ring-amber-500/20 px-4 py-3",children:[a.jsx(_n,{className:"h-4 w-4 text-amber-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-sm text-amber-200/80",children:"Save this idea before attaching a repository."})]}),a.jsxs("div",{className:"mx-6 mt-4 flex items-start gap-3 rounded-xl bg-purple-500/5 ring-1 ring-purple-500/10 px-4 py-3",children:[a.jsx(_n,{className:"h-4 w-4 text-purple-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-xs text-white/50",children:"Attaching won't modify your repository. Claude will have read-only context."})]}),a.jsx("div",{className:"px-6 mt-4",children:a.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-white/[0.04] ring-1 ring-white/[0.08] px-4 py-2.5 focus-within:ring-purple-500/30 transition-all",children:[a.jsx(Kt,{className:"h-4 w-4 text-white/30"}),a.jsx("input",{ref:c,value:i,onChange:h=>s(h.target.value),placeholder:"Search repositories...",className:"flex-1 bg-transparent text-sm text-white/80 placeholder-white/30 outline-none",disabled:p})]})}),a.jsx("div",{className:"px-6 py-4 max-h-[300px] overflow-y-auto space-y-1",children:d.length===0?a.jsx("p",{className:"text-center text-sm text-white/30 py-8",children:i?"No repositories match your search.":"No repositories available."}):d.map(h=>{const m=h.id===o;return a.jsxs("button",{onClick:()=>l(m?null:h.id),disabled:p,className:A("w-full flex items-center gap-3 rounded-xl px-4 py-3 text-left transition-all ring-1",m?"bg-purple-500/10 ring-purple-500/30 text-white":"bg-white/[0.02] ring-white/[0.06] text-white/70 hover:bg-white/[0.04]",p&&"opacity-50 cursor-not-allowed"),children:[a.jsx(gn,{className:A("h-4 w-4 flex-shrink-0",m?"text-purple-400":"text-white/40")}),a.jsx("div",{className:"flex-1 min-w-0",children:a.jsx("span",{className:"text-sm font-medium truncate block",children:h.id})}),m&&a.jsx(ke,{className:"h-4 w-4 text-purple-400 flex-shrink-0"})]},h.id)})}),a.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-white/10",children:[a.jsx("button",{onClick:r,className:"px-4 py-2 rounded-xl text-sm text-white/60 hover:text-white/80 hover:bg-white/5 transition-colors",children:"Cancel"}),a.jsx("button",{onClick:()=>o&&n(o),disabled:!o||p,className:A("px-5 py-2 rounded-xl text-sm font-medium transition-all",o&&!p?"bg-purple-500/20 text-purple-200 ring-1 ring-purple-500/30 hover:bg-purple-500/30":"bg-white/5 text-white/30 cursor-not-allowed"),children:"Attach Selected"})]})]})]})}function m1e(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,50)||"my-project"}function bq({idea:e,onPromote:t,onClose:n}){var _,C;const r=sn(O=>O.workspaces),[i,s]=f.useState(1),[o,l]=f.useState(e.title?m1e(e.title):"my-project"),[c,d]=f.useState(((_=r[0])==null?void 0:_.id)??""),p=((C=r.find(O=>O.id===c))==null?void 0:C.scanPath)??"",[h,m]=f.useState(!1),[g,x]=f.useState(!0),[k,w]=f.useState(!1),[y,b]=f.useState(null),[v,S]=f.useState(!1),N=f.useRef(null),E=f.useRef(null);f.useEffect(()=>{var O;(O=N.current)==null||O.focus()},[]),f.useEffect(()=>{const O=L=>{L.key==="Escape"&&n()};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[n]),f.useEffect(()=>{if(!v)return;const O=L=>{E.current&&!E.current.contains(L.target)&&S(!1)};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[v]);const M=f.useCallback(async()=>{if(!(!o.trim()||!p.trim())){w(!0),b(null);try{await t({repoName:o.trim(),directory:p.trim(),generateScaffold:h,transferHistory:g})}catch(O){b(O instanceof Error?O.message:"Promotion failed"),w(!1)}}},[o,p,h,g,t]),j=o.trim().length>0&&p.trim().length>0;return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[a.jsx(q.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:n,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),a.jsxs(q.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative w-full max-w-[560px] rounded-2xl bg-[#0d1117] ring-1 ring-white/10 shadow-2xl overflow-hidden",role:"dialog","aria-label":"Promote idea to project",children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/10",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"flex items-center justify-center h-8 w-8 rounded-lg bg-purple-500/10 ring-1 ring-purple-500/20",children:a.jsx(Dn,{className:"h-4 w-4 text-purple-400"})}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Promote to Project"})]}),a.jsx("button",{onClick:n,className:"p-1.5 rounded-lg text-white/40 hover:text-white/70 hover:bg-white/5 transition-colors",children:a.jsx(ve,{className:"h-5 w-5"})})]}),a.jsxs("div",{className:"flex items-center gap-2 px-6 py-3 border-b border-white/5",children:[a.jsxs("div",{className:A("flex items-center gap-1.5 text-xs font-medium",i===1?"text-purple-400":"text-white/30"),children:[a.jsx("span",{className:A("flex items-center justify-center h-5 w-5 rounded-full text-[10px]",i===1?"bg-purple-500/20 ring-1 ring-purple-500/30":"bg-white/5"),children:"1"}),"Setup"]}),a.jsx(pt,{className:"h-3 w-3 text-white/20"}),a.jsxs("div",{className:A("flex items-center gap-1.5 text-xs font-medium",i===2?"text-purple-400":"text-white/30"),children:[a.jsx("span",{className:A("flex items-center justify-center h-5 w-5 rounded-full text-[10px]",i===2?"bg-purple-500/20 ring-1 ring-purple-500/30":"bg-white/5"),children:"2"}),"Confirm"]})]}),a.jsx("div",{className:"px-6 py-5",children:a.jsxs(Ce,{mode:"wait",children:[i===1&&a.jsxs(q.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"space-y-5",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white/70 mb-1.5",children:"Project Name"}),a.jsx("input",{ref:N,value:o,onChange:O=>l(O.target.value),placeholder:"my-awesome-project",className:"w-full rounded-xl bg-white/[0.04] ring-1 ring-white/[0.08] px-4 py-2.5 text-sm text-white/90 placeholder-white/30 outline-none focus:ring-purple-500/30 transition-all"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white/70 mb-1.5",children:"Repository Location"}),a.jsxs("div",{className:"relative",ref:E,children:[a.jsxs("button",{type:"button",onClick:()=>S(!v),className:"w-full flex items-center justify-between rounded-xl bg-white/[0.04] ring-1 ring-white/[0.08] px-4 py-2.5 text-left outline-none focus:ring-purple-500/30 transition-all",children:[c&&r.find(O=>O.id===c)?a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"text-sm text-white/90 truncate",children:r.find(O=>O.id===c).name}),a.jsx("div",{className:"text-[11px] text-white/40 truncate",children:r.find(O=>O.id===c).scanPath})]}):a.jsx("span",{className:"text-sm text-white/30",children:"No workspaces available"}),a.jsx(Xe,{className:A("h-4 w-4 text-white/40 flex-shrink-0 ml-2 transition-transform",v&&"rotate-180")})]}),v&&r.length>0&&a.jsx("div",{className:"absolute z-10 mt-1 w-full rounded-xl bg-[#161b22] ring-1 ring-white/10 shadow-xl overflow-hidden",children:r.map(O=>a.jsxs("button",{type:"button",onClick:()=>{d(O.id),S(!1)},className:A("w-full px-4 py-2.5 text-left hover:bg-white/[0.06] transition-colors",O.id===c&&"bg-purple-500/10"),children:[a.jsx("div",{className:"text-sm text-white/90 truncate",children:O.name}),a.jsx("div",{className:"text-[11px] text-white/40 truncate",children:O.scanPath})]},O.id))})]}),a.jsxs("p",{className:"mt-1 text-[11px] text-white/30",children:["Project will be created at: ",p?`${p}/${o}`:"<select a workspace>"]})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer group",children:[a.jsx("input",{type:"checkbox",checked:h,onChange:O=>m(O.target.checked),className:"h-4 w-4 rounded border-white/20 bg-white/5 text-purple-500 focus:ring-purple-500/30"}),a.jsx("span",{className:"text-sm text-white/70 group-hover:text-white/90 transition-colors",children:"Generate project scaffold (README, .gitignore)"})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer group",children:[a.jsx("input",{type:"checkbox",checked:g,onChange:O=>x(O.target.checked),className:"h-4 w-4 rounded border-white/20 bg-white/5 text-purple-500 focus:ring-purple-500/30"}),a.jsx("span",{className:"text-sm text-white/70 group-hover:text-white/90 transition-colors",children:"Transfer chat history to new session"})]})]})]},"step1"),i===2&&a.jsxs(q.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"space-y-4",children:[a.jsxs("div",{className:"rounded-xl bg-white/[0.03] ring-1 ring-white/[0.06] p-4 space-y-3",children:[a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-white/50",children:"Project Name"}),a.jsx("span",{className:"text-white font-medium",children:o})]}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-white/50",children:"Location"}),a.jsxs("span",{className:"text-white/80 font-mono text-xs",children:[p,"/",o]})]}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-white/50",children:"Scaffold"}),a.jsx("span",{className:"text-white/70",children:h?"Yes":"No"})]}),a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-white/50",children:"Transfer History"}),a.jsx("span",{className:"text-white/70",children:g?"Yes":"No"})]})]}),a.jsxs("div",{className:"flex items-start gap-3 rounded-xl bg-amber-500/5 ring-1 ring-amber-500/10 px-4 py-3",children:[a.jsx(Ge,{className:"h-4 w-4 text-amber-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-xs text-amber-200/70",children:"This will mark the idea as Promoted and create a new session with the repository."})]}),y&&a.jsxs("div",{className:"flex items-start gap-3 rounded-xl bg-red-500/10 ring-1 ring-red-500/20 px-4 py-3",children:[a.jsx(Ge,{className:"h-4 w-4 text-red-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-xs text-red-200/80",children:y})]})]},"step2")]})}),a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-t border-white/10",children:[a.jsx("div",{children:i===2&&a.jsxs("button",{onClick:()=>s(1),disabled:k,className:"flex items-center gap-1.5 px-4 py-2 rounded-xl text-sm text-white/60 hover:text-white/80 hover:bg-white/5 transition-colors",children:[a.jsx(Zc,{className:"h-4 w-4"}),"Back"]})}),a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("button",{onClick:n,disabled:k,className:"px-4 py-2 rounded-xl text-sm text-white/60 hover:text-white/80 hover:bg-white/5 transition-colors",children:"Cancel"}),i===1?a.jsxs("button",{onClick:()=>s(2),disabled:!j,className:A("flex items-center gap-1.5 px-5 py-2 rounded-xl text-sm font-medium transition-all",j?"bg-purple-500/20 text-purple-200 ring-1 ring-purple-500/30 hover:bg-purple-500/30":"bg-white/5 text-white/30 cursor-not-allowed"),children:["Next",a.jsx(pt,{className:"h-4 w-4"})]}):a.jsx("button",{onClick:M,disabled:k,className:A("flex items-center gap-1.5 px-5 py-2 rounded-xl text-sm font-medium transition-all",k?"bg-purple-500/10 text-purple-300/50 cursor-wait":"bg-purple-500/20 text-purple-200 ring-1 ring-purple-500/30 hover:bg-purple-500/30"),children:k?a.jsxs(a.Fragment,{children:[a.jsx(he,{className:"h-4 w-4 animate-spin"}),"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(Dn,{className:"h-4 w-4"}),"Create Project"]})})]})]})]})]})}const kq=[{id:"prompt",label:"Prompt",shortcut:"1",icon:rr},{id:"review",label:"Review",shortcut:"2",icon:hp},{id:"ship",label:"Ship",shortcut:"3",icon:Dn}];function f1e({activePhase:e,onPhaseChange:t,messageCount:n=0,fileCount:r=0,warningCount:i=0,isRunning:s=!1,canReview:o=!0,canShip:l=!0,existingPR:c=null}){f.useEffect(()=>{const m=g=>{g.target instanceof HTMLInputElement||g.target instanceof HTMLTextAreaElement||g.target instanceof HTMLSelectElement||(g.key==="1"&&t("prompt"),g.key==="2"&&o&&t("review"),g.key==="3"&&l&&t("ship"))};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,o,l]);const d=m=>{switch(m){case"prompt":return n>0?n:void 0;case"review":return r>0?r:void 0;case"ship":return i>0?i:void 0;default:return}},p=m=>m==="review"?!o:m==="ship"?!l:!1,h=(m,g)=>({prompt:{bg:g?"bg-blue-500/20":"bg-white/5",ring:g?"ring-blue-500/40":"ring-white/10",text:g?"text-blue-400":"text-white/60",glow:g?"shadow-[0_0_20px_rgba(59,130,246,0.3)]":""},review:{bg:g?"bg-amber-500/20":"bg-white/5",ring:g?"ring-amber-500/40":"ring-white/10",text:g?"text-amber-400":"text-white/60",glow:g?"shadow-[0_0_20px_rgba(245,158,11,0.3)]":""},ship:{bg:g?"bg-emerald-500/20":"bg-white/5",ring:g?"ring-emerald-500/40":"ring-white/10",text:g?"text-emerald-400":"text-white/60",glow:g?"shadow-[0_0_20px_rgba(16,185,129,0.3)]":""}})[m];return a.jsx("div",{className:"flex items-center justify-center",children:a.jsx("div",{className:"flex items-center gap-1 sm:gap-2 rounded-2xl bg-white/[0.03] p-1 sm:p-1.5 ring-1 ring-white/10",children:kq.map((m,g)=>{const x=e===m.id,k=p(m.id),w=d(m.id),y=h(m.id,x),b=m.icon;return a.jsxs("div",{className:"flex items-center",children:[a.jsxs(q.button,{onClick:()=>!k&&t(m.id),disabled:k,className:A("relative flex items-center gap-1 sm:gap-2 rounded-xl px-2 py-2 sm:px-4 sm:py-2.5 text-xs sm:text-sm font-medium transition-all ring-1",y.bg,y.ring,y.text,y.glow,k&&"opacity-40 cursor-not-allowed",!k&&!x&&"hover:bg-white/10 hover:ring-white/20"),whileHover:k?void 0:{scale:1.02},whileTap:k?void 0:{scale:.98},children:[m.id==="prompt"&&s&&a.jsxs("span",{className:"absolute -top-1 -right-1 flex h-3 w-3",children:[a.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),a.jsx("span",{className:"relative inline-flex rounded-full h-3 w-3 bg-blue-500"})]}),m.id==="ship"&&c&&a.jsx("span",{className:A("absolute -top-1.5 -right-1.5 flex h-5 w-5 items-center justify-center rounded-full ring-2 ring-[#05070c]",c.state==="merged"?"bg-purple-500":c.state==="closed"?"bg-red-500":"bg-emerald-500"),title:`PR #${c.number}: ${c.title} (${c.state||"open"})`,children:c.state==="merged"?a.jsx(nr,{className:"h-3 w-3 text-white"}):a.jsx(pa,{className:"h-3 w-3 text-white"})}),a.jsx(b,{className:"h-4 w-4 shrink-0"}),a.jsx("span",{className:"hidden sm:inline",children:m.label}),w!==void 0&&a.jsx("span",{className:A("flex h-5 min-w-5 items-center justify-center rounded-full px-1.5 text-xs font-semibold",m.id==="ship"&&i>0?"bg-red-500/20 text-red-400":"bg-white/10 text-white/70"),children:w}),a.jsx("span",{className:"hidden sm:inline-flex ml-1 text-xs opacity-50 font-mono",children:m.shortcut})]}),g<kq.length-1&&a.jsx(pt,{className:"mx-0.5 sm:mx-1 h-3.5 w-3.5 sm:h-4 sm:w-4 text-white/20"})]},m.id)})})})}function wT({repos:e,onRepoClick:t,onRepoRemove:n,className:r,ideaItems:i=[],activeIdeaId:s,onIdeaClick:o,onIdeaClose:l,onNewIdea:c,onNewSession:d}){const{openOverlay:p}=vh(),[h,m]=f.useState(new Set),[g,x]=f.useState(!1),k=f.useCallback(async b=>{m(v=>new Set(v).add(b));try{await n(b)}finally{m(v=>{const S=new Set(v);return S.delete(b),S})}},[n]),w=b=>{switch(b){case"running":return a.jsx(he,{className:"h-3 w-3 animate-spin text-blue-400"});case"error":return a.jsx(dt,{className:"h-3 w-3 text-red-400"});case"modified":return a.jsx(Kr,{className:"h-3 w-3 fill-amber-400 text-amber-400"});case"clean":default:return a.jsx(Kr,{className:"h-3 w-3 fill-emerald-400 text-emerald-400"})}},y=(b,v)=>{if(v)switch(b){case"running":return"ring-blue-500/50 bg-blue-500/10";case"error":return"ring-red-500/50 bg-red-500/10";case"modified":return"ring-amber-500/50 bg-amber-500/10";default:return"ring-emerald-500/50 bg-emerald-500/10"}return"ring-white/10 bg-white/5 hover:bg-white/10 hover:ring-white/20"};return a.jsxs("div",{className:A("relative z-40 flex items-center gap-2 px-4 py-3 bg-[#05070c]/80 backdrop-blur-xl border-t border-white/10",r),children:[a.jsxs("div",{className:"flex items-center gap-2 text-white/40 text-xs font-medium uppercase tracking-wider",children:[a.jsx(gn,{className:"h-4 w-4"}),a.jsx("span",{className:"hidden sm:inline",children:"Repos"})]}),a.jsx("div",{className:"h-4 w-px bg-white/10 mx-1"}),i.length>0&&a.jsxs(a.Fragment,{children:[i.map(b=>{const v=b.id===s;return a.jsx(q.div,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},layout:!0,className:"flex-shrink-0",children:a.jsxs("button",{onClick:()=>o==null?void 0:o(b.id),className:A("group flex items-center gap-2 rounded-xl px-3 py-2 text-sm transition-all ring-1",v?"ring-purple-500/50 bg-purple-500/10":"ring-white/10 bg-white/5 hover:bg-white/10 hover:ring-white/20"),children:[a.jsx(xn,{className:A("h-3 w-3",v?"text-purple-400":"text-purple-400/60")}),b.status==="ephemeral"&&a.jsx(Kr,{className:"h-2 w-2 fill-purple-400 text-purple-400"}),a.jsx("span",{className:A("font-medium max-w-[120px] truncate",v?"text-white":"text-white/70"),children:b.title||"Untitled Idea"}),a.jsx("button",{onClick:S=>{S.stopPropagation(),l==null||l(b.id)},className:"ml-1 p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-white/10 transition-opacity",children:a.jsx(ve,{className:"h-3 w-3 text-white/50"})})]})},b.id)}),a.jsx("div",{className:"h-4 w-px bg-white/10 mx-1"})]}),a.jsx("div",{className:"flex items-center gap-2 flex-1 overflow-x-auto scrollbar-none",children:a.jsx(Ce,{mode:"popLayout",children:e.map(b=>{var S;const v=h.has(b.id);return a.jsx(q.div,{initial:{opacity:0,scale:.8,x:-10},animate:{opacity:v?.5:1,scale:1,x:0},exit:{opacity:0,scale:.8,x:-10},layout:!0,className:"flex-shrink-0",children:a.jsxs("button",{onClick:()=>!v&&t(b.id),disabled:v,className:A("group flex items-center gap-2 rounded-xl px-3 py-2 text-sm transition-all ring-1",v?"ring-red-500/30 bg-red-500/5 cursor-wait":y(b.status,b.isActive)),children:[v?a.jsx(he,{className:"h-3 w-3 animate-spin text-red-400"}):w(b.status),a.jsx("span",{className:A("font-medium max-w-[120px] truncate",v?"text-red-300/70":b.isActive?"text-white":"text-white/70"),children:v?"Closing...":b.name}),!v&&a.jsxs("span",{className:"flex items-center gap-1 rounded-md bg-white/5 px-1.5 py-0.5 text-xs text-white/50 font-mono",children:[a.jsx(yn,{className:"h-3 w-3"}),a.jsx("span",{className:"max-w-[80px] truncate",children:b.branch})]}),!v&&b.changesCount>0&&a.jsx("span",{className:"flex h-5 min-w-5 items-center justify-center rounded-full bg-amber-500/20 px-1.5 text-xs font-semibold text-amber-400",children:b.changesCount}),!v&&(b.parentSessionId||b.childSessionIds&&b.childSessionIds.length>0)&&a.jsx("span",{className:"flex items-center gap-0.5 text-xs text-blue-400/70",title:b.parentSessionId?"Continued from another session":`Continued in ${(S=b.childSessionIds)==null?void 0:S.length} session(s)`,children:a.jsx(nd,{className:"h-3 w-3"})}),!v&&a.jsx("button",{onClick:N=>{N.stopPropagation(),k(b.id)},className:"ml-1 p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-white/10 transition-opacity",title:"Close session",children:a.jsx(ve,{className:"h-3 w-3 text-white/50"})})]})},b.id)})})}),c?a.jsxs("div",{className:"relative",children:[a.jsxs(q.button,{onClick:()=>x(!g),className:"flex items-center gap-1.5 rounded-xl bg-white/5 px-3 py-2 text-sm text-white/60 ring-1 ring-white/10 hover:bg-white/10 hover:ring-white/20 hover:text-white/80 transition-all",whileHover:{scale:1.02},whileTap:{scale:.98},children:[a.jsx(Zt,{className:"h-4 w-4"}),a.jsx(Xe,{className:"h-3 w-3"})]}),a.jsx(Ce,{children:g&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-50",onClick:()=>x(!1)}),a.jsxs(q.div,{initial:{opacity:0,y:4,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.15},className:"absolute bottom-full right-0 mb-2 z-50 w-48 rounded-xl bg-[#0d1117] ring-1 ring-white/10 shadow-xl overflow-hidden",children:[a.jsxs("button",{onClick:()=>{x(!1),c()},className:"flex items-center gap-2.5 w-full px-4 py-2.5 text-sm text-white/80 hover:bg-purple-500/10 hover:text-purple-200 transition-colors",children:[a.jsx(xn,{className:"h-4 w-4 text-purple-400"}),"New Idea"]}),a.jsxs("button",{onClick:()=>{x(!1),d?d():p("new-session")},className:"flex items-center gap-2.5 w-full px-4 py-2.5 text-sm text-white/80 hover:bg-blue-500/10 hover:text-blue-200 transition-colors",children:[a.jsx(gn,{className:"h-4 w-4 text-blue-400"}),"New Session"]})]})]})})]}):a.jsxs(q.button,{onClick:()=>p("new-session"),className:"flex items-center gap-1.5 rounded-xl bg-white/5 px-3 py-2 text-sm text-white/60 ring-1 ring-white/10 hover:bg-white/10 hover:ring-white/20 hover:text-white/80 transition-all",whileHover:{scale:1.02},whileTap:{scale:.98},children:[a.jsx(Zt,{className:"h-4 w-4"}),a.jsx("span",{className:"hidden sm:inline",children:"Add Session"})]})]})}function g1e({sessionId:e,utilizationPercent:t,onSwitchSession:n}){const[r,i]=f.useState(!1),[s,o]=f.useState(!1),{splitSession:l}=ri(),c=f.useCallback(()=>{i(!0)},[]),d=f.useCallback(async()=>{o(!0);try{const p=await l(e);p&&n&&n(p)}catch(p){console.error("[ContextSplitBanner] Split failed:",p)}finally{o(!1)}},[e,l,n]);return r||t<85?null:a.jsx(Ce,{children:a.jsxs(q.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},role:"alert","aria-live":"polite",className:A("mx-6 mt-2 rounded-xl px-4 py-3 flex items-center gap-3 ring-1","bg-amber-500/10 ring-amber-500/30 text-amber-300"),children:[a.jsx(Ep,{className:"h-5 w-5 shrink-0 text-amber-400","aria-hidden":"true"}),a.jsxs("p",{className:"flex-1 text-sm",children:["Context is ",t,"% full. Split into a new session to keep responses sharp."]}),a.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[a.jsx("button",{type:"button",onClick:d,disabled:s,className:A("px-3 py-1.5 text-xs font-medium rounded-lg transition-colors","bg-amber-500/20 hover:bg-amber-500/30 text-amber-200","disabled:opacity-50"),children:s?"Splitting...":"Split Session"}),a.jsx("button",{type:"button",onClick:c,className:"p-1.5 rounded-lg transition-colors hover:bg-amber-500/20 text-amber-400","aria-label":"Dismiss alert",children:a.jsx(ve,{className:"h-4 w-4","aria-hidden":"true"})})]})]})})}function y1e({repoName:e,branchName:t}){return a.jsx("div",{className:"bg-white/[0.03] ring-1 ring-white/10 rounded-xl p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-blue-500/10 ring-1 ring-blue-400/20 flex-shrink-0",children:a.jsx(gn,{className:"h-5 w-5 text-blue-400"})}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("h3",{className:"text-white/90 font-medium text-sm truncate",children:e}),a.jsxs("div",{className:"flex items-center gap-2 text-xs text-white/40 mt-0.5",children:[a.jsx(yn,{className:"h-3 w-3 flex-shrink-0"}),a.jsx("span",{className:"truncate",children:t})]})]})]})})}const x1e={red:{iconBg:"bg-red-500/10",iconText:"text-red-400",iconRing:"ring-red-400/20"},blue:{iconBg:"bg-blue-500/10",iconText:"text-blue-400",iconRing:"ring-blue-400/20"},emerald:{iconBg:"bg-emerald-500/10",iconText:"text-emerald-400",iconRing:"ring-emerald-400/20"},purple:{iconBg:"bg-purple-500/10",iconText:"text-purple-400",iconRing:"ring-purple-400/20"}};function m1({title:e,description:t,icon:n,promptText:r,theme:i,onClick:s}){const o=x1e[i];return a.jsx("button",{onClick:()=>s(r),className:A("group relative rounded-xl p-4 bg-white/[0.02] ring-1 ring-white/[0.08]","hover:bg-white/[0.04] hover:ring-white/[0.15] hover:-translate-y-0.5","transition-all duration-200","focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-offset-2 focus:ring-offset-[#05070c]","text-left w-full"),"aria-label":`${e}: ${t}`,children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:A("flex h-8 w-8 items-center justify-center rounded-lg ring-1 flex-shrink-0","transition-colors duration-200",o.iconBg,o.iconRing,`group-hover:${o.iconBg.replace("/10","/20")}`),children:a.jsx(n,{className:A("h-4 w-4",o.iconText)})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("h3",{className:"text-sm font-medium text-white/90 mb-1",children:e}),a.jsx("p",{className:"text-xs text-white/50 leading-relaxed",children:t})]}),a.jsx(Ku,{className:A("h-4 w-4 text-white/30 flex-shrink-0","opacity-0 group-hover:opacity-100 transition-opacity duration-200","absolute top-4 right-4")})]})})}const f1=[{id:"prompt",label:"Prompt",color:"text-blue-300"},{id:"review",label:"Review",color:"text-emerald-300"},{id:"ship",label:"Ship",color:"text-purple-300"}];function b1e({currentPhase:e}){return a.jsx("div",{className:"inline-flex items-center gap-2 px-6 py-3 rounded-full bg-white/[0.02] ring-1 ring-white/[0.06]",role:"navigation","aria-label":"Workflow phases",children:f1.map((t,n)=>{const r=t.id===e,i=f1.findIndex(s=>s.id===e)>f1.findIndex(s=>s.id===t.id);return a.jsxs(Zn.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:A("h-2 w-2 rounded-full transition-colors duration-200",r||i?t.color.replace("text-","bg-"):"bg-white/20"),"aria-hidden":"true"}),a.jsx("span",{className:A("text-xs font-medium transition-colors duration-200",r?t.color:"text-white/40"),children:t.label})]}),n<f1.length-1&&a.jsx(pt,{className:"h-3 w-3 text-white/20","aria-hidden":"true"})]},t.id)})})}function k1e({messages:e,toolActivities:t,currentActivity:n,isRunning:r,isEmpty:i,renderMessage:s,messagesEndRef:o,composer:l,onExport:c,repoName:d,branchName:p,onSuggestedPromptClick:h}){var O;const m=f.useRef(null),[g,x]=f.useState(!0),[k,w]=f.useState(!1),{sessions:y,activeSessionId:b,switchSession:v}=ri(),S=f.useMemo(()=>y.find(L=>L.id===b),[y,b]),N=(O=S==null?void 0:S.contextState)==null?void 0:O.contextUtilizationPercent,E=(S==null?void 0:S.splitSuggested)||N!=null&&N>=85,M=f.useCallback(L=>{v(L)},[v]);f.useEffect(()=>{g&&m.current&&(m.current.scrollTop=m.current.scrollHeight)},[e,r,n,g]);const j=f.useCallback(()=>{if(!m.current)return;const{scrollTop:L,scrollHeight:z,clientHeight:G}=m.current,B=z-L-G;x(B<50),w(B>100)},[]),_=f.useCallback(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight,x(!0),w(!1))},[]),C=f.useCallback(L=>{h==null||h(L)},[h]);return i?a.jsxs("div",{className:"flex-1 flex flex-col",children:[a.jsx("div",{className:"flex-1 flex items-center justify-center px-6",children:a.jsxs(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"w-full max-w-2xl space-y-6",children:[d&&p&&a.jsx(y1e,{repoName:d,branchName:p}),a.jsxs("div",{className:"text-center",children:[a.jsx("div",{className:"mx-auto mb-4 flex h-20 w-20 items-center justify-center rounded-3xl bg-gradient-to-br from-orange-500/20 via-amber-500/20 to-yellow-500/10 ring-1 ring-white/10",children:a.jsx(nn,{className:"h-10 w-10 text-orange-400"})}),a.jsx("h2",{className:"text-2xl font-semibold text-white mb-2",children:"What should we build?"}),a.jsx("p",{className:"text-sm text-white/60 leading-relaxed max-w-lg mx-auto",children:d?"I can help you build features, fix bugs, refactor code, or explore your codebase.":"Let's brainstorm and plan. We can add a repository later when you're ready to build."})]}),a.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[a.jsx(m1,{title:"Fix a bug",description:"Describe the issue and I'll help debug and fix it",icon:ep,promptText:"I need help fixing a bug: ",theme:"red",onClick:C}),a.jsx(m1,{title:"Build a feature",description:"Tell me what you want to add and I'll implement it",icon:nn,promptText:"Let's build a new feature: ",theme:"blue",onClick:C}),a.jsx(m1,{title:"Refactor code",description:"Point to code that needs improvement",icon:ua,promptText:"I'd like to refactor ",theme:"emerald",onClick:C}),a.jsx(m1,{title:"Explain codebase",description:"Ask about how something works",icon:Xu,promptText:"Can you explain ",theme:"purple",onClick:C})]}),a.jsx("div",{className:"flex justify-center",children:a.jsx(b1e,{currentPhase:"prompt"})})]})}),a.jsx("div",{className:"w-full px-4 pb-4",children:l})]}):a.jsxs("div",{className:"flex-1 flex flex-col min-h-0 relative",children:[E&&b&&a.jsx(g1e,{sessionId:b,utilizationPercent:N??85,onSwitchSession:M}),a.jsx("div",{ref:m,onScroll:j,className:"flex-1 overflow-y-auto py-4 space-y-1",children:a.jsxs("div",{className:"w-full px-4",children:[e.map((L,z)=>z===e.length-1?a.jsx(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},children:s(L,z)},L.id):a.jsx("div",{children:s(L,z)},L.id)),a.jsx("div",{ref:o})]})}),a.jsx(Ce,{children:k&&a.jsx(q.button,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},onClick:_,className:"absolute bottom-20 right-6 z-10 flex h-8 w-8 items-center justify-center rounded-full bg-white/10 ring-1 ring-white/20 backdrop-blur-sm hover:bg-white/20 transition-colors",title:"Scroll to bottom",children:a.jsx(Xe,{className:"h-4 w-4 text-white/70"})})}),a.jsx("div",{className:"w-full px-4 pb-4 pt-2 border-t border-white/5",children:l})]})}function w1e({sessionId:e,repoId:t,files:n,onFileApprove:r,onApproveAll:i,onClearAll:s,onDiscardFile:o,onDeleteFile:l,onNavigateToShip:c}){const[d,p]=f.useState(n.length>0?n[0].path:null),[h,m]=f.useState(""),[g,x]=f.useState(!1),[k,w]=f.useState(new Set),[y,b]=f.useState(null),v=f.useRef(null),S=f.useCallback((z,G)=>{v.current&&clearTimeout(v.current),b({path:z,action:G}),v.current=setTimeout(()=>b(null),3e3)},[]),N=f.useCallback(()=>{v.current&&clearTimeout(v.current),b(null)},[]),E=f.useCallback(()=>{y&&(y.action==="discard"?o(y.path):l(y.path),b(null),v.current&&clearTimeout(v.current))},[y,o,l]);f.useEffect(()=>()=>{v.current&&clearTimeout(v.current)},[]);const M=n.filter(z=>z.approved).length,j=n.length,_=M===j&&j>0,C=f.useMemo(()=>{const z={};return n.forEach(G=>{const B=G.path.split("/"),te=B.length>1?B.slice(0,-1).join("/"):".";z[te]||(z[te]=[]),z[te].push(G)}),z},[n]);f.useEffect(()=>{if(!d||!e)return;(async()=>{x(!0);try{const G={filePath:d,staged:!1};t&&(G.repoId=t);const B=await F("POST",`/terminal/sessions/${e}/file-diff`,G);m(B.diff||"No changes")}catch(G){console.error("Failed to load diff:",G),m("Failed to load diff")}finally{x(!1)}})()},[d,e,t]);const O=z=>{w(G=>{const B=new Set(G);return B.has(z)?B.delete(z):B.add(z),B})},L=z=>{switch(z){case"added":return a.jsx(Hl,{className:"h-4 w-4 text-emerald-400"});case"deleted":return a.jsx(cp,{className:"h-4 w-4 text-red-400"});case"modified":case"renamed":return a.jsx(Ar,{className:"h-4 w-4 text-amber-400"});default:return a.jsx(_a,{className:"h-4 w-4 text-white/40"})}};return n.length===0?a.jsx("div",{className:"flex-1 flex items-center justify-center",children:a.jsxs("div",{className:"text-center",children:[a.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-white/5 ring-1 ring-white/10",children:a.jsx(Qn,{className:"h-8 w-8 text-white/30"})}),a.jsx("h2",{className:"text-lg font-semibold text-white mb-2",children:"No changes to review"}),a.jsx("p",{className:"text-sm text-white/50",children:"Files modified by Claude will appear here for review."})]})}):a.jsxs("div",{className:"flex-1 flex flex-col sm:flex-row min-h-0 gap-3 sm:gap-4 p-3 sm:p-4 overflow-y-auto sm:overflow-y-hidden",children:[a.jsxs("div",{className:"w-full sm:w-64 sm:flex-shrink-0 flex flex-col rounded-xl bg-white/[0.03] ring-1 ring-white/10 overflow-hidden",children:[a.jsxs("div",{className:"px-3 py-2.5 border-b border-white/10 flex items-center justify-between",children:[a.jsx("span",{className:"text-xs font-medium text-white/50 uppercase tracking-wider",children:"Changed Files"}),a.jsxs("span",{className:"text-xs text-white/40",children:[M,"/",j]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:Object.entries(C).map(([z,G])=>a.jsxs("div",{children:[z!=="."&&a.jsxs("button",{onClick:()=>O(z),className:"flex items-center gap-1 w-full px-2 py-1 text-xs text-white/40 hover:text-white/60",children:[k.has(z)||!k.size?a.jsx(Xe,{className:"h-3 w-3"}):a.jsx(pt,{className:"h-3 w-3"}),a.jsx("span",{className:"truncate font-mono",children:z})]}),a.jsx(Ce,{children:(z==="."||k.has(z)||!k.size)&&G.map(B=>{const te=(y==null?void 0:y.path)===B.path,Y=B.status==="modified"||B.status==="deleted",R=B.status==="added";return a.jsxs(q.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:A("group flex items-center gap-2 w-full px-2 py-1.5 rounded-lg text-left transition-colors cursor-pointer",d===B.path?"bg-white/10 ring-1 ring-white/20":"hover:bg-white/5",z!=="."&&"ml-3"),onClick:()=>p(B.path),children:[L(B.status),a.jsx("span",{className:"flex-1 text-sm text-white/80 truncate font-mono",children:B.path.split("/").pop()}),te?a.jsxs("span",{className:"flex items-center gap-1 flex-shrink-0",onClick:H=>H.stopPropagation(),children:[a.jsx("button",{onClick:E,className:"text-[10px] font-medium text-red-400 hover:text-red-300 px-1.5 py-0.5 rounded bg-red-500/10 hover:bg-red-500/20 transition-colors",children:"Confirm?"}),a.jsx("button",{onClick:N,className:"p-0.5 text-white/40 hover:text-white/60 transition-colors",children:a.jsx(ve,{className:"h-3 w-3"})})]}):a.jsxs(a.Fragment,{children:[B.approved&&a.jsx(ke,{className:"h-3.5 w-3.5 text-emerald-400 flex-shrink-0 group-hover:hidden"}),a.jsxs("span",{className:A("items-center gap-0.5 flex-shrink-0 hidden group-hover:flex"),onClick:H=>H.stopPropagation(),children:[a.jsx("button",{onClick:()=>r(B.path),className:A("p-1 rounded transition-colors",B.approved?"text-emerald-400 hover:text-emerald-300":"text-white/30 hover:text-emerald-400"),title:B.approved?"Unapprove":"Approve",children:a.jsx(ke,{className:"h-3.5 w-3.5"})}),Y&&a.jsx("button",{onClick:()=>S(B.path,"discard"),className:"p-1 rounded text-white/30 hover:text-red-400 transition-colors",title:"Discard changes",children:a.jsx(gd,{className:"h-3.5 w-3.5"})}),R&&a.jsx("button",{onClick:()=>S(B.path,"delete"),className:"p-1 rounded text-white/30 hover:text-red-400 transition-colors",title:"Delete file",children:a.jsx(St,{className:"h-3.5 w-3.5"})})]})]})]},B.path)})})]},z))}),a.jsxs("div",{className:"p-3 border-t border-white/10 space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("button",{onClick:i,disabled:_,className:A("flex-1 flex items-center justify-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors",_?"bg-emerald-500/20 text-emerald-400 cursor-default":"bg-white/10 text-white hover:bg-white/15"),children:[a.jsx(tp,{className:"h-4 w-4"}),_?"All Approved":"Approve All"]}),M>0&&!_&&a.jsxs("button",{onClick:s,className:"flex items-center justify-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium text-white/50 hover:text-white/80 hover:bg-white/5 transition-colors",children:[a.jsx(ve,{className:"h-3.5 w-3.5"}),"Clear"]})]}),_&&a.jsxs(a.Fragment,{children:[a.jsxs("button",{onClick:s,className:"w-full flex items-center justify-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium text-white/40 hover:text-white/60 hover:bg-white/5 transition-colors",children:[a.jsx(ve,{className:"h-3 w-3"}),"Clear All Approvals"]}),a.jsxs("button",{onClick:c,className:"w-full flex items-center justify-center gap-2 rounded-lg bg-emerald-600 px-3 py-2 text-sm font-medium text-white hover:bg-emerald-500 transition-colors",children:["Ready to Ship",a.jsx(pt,{className:"h-4 w-4"})]})]})]})]}),a.jsxs("div",{className:"hidden sm:flex flex-1 flex-col rounded-xl bg-white/[0.03] ring-1 ring-white/10 overflow-hidden min-w-0",children:[d&&(()=>{const z=n.find(R=>R.path===d),G=(z==null?void 0:z.status)||"modified",B=(y==null?void 0:y.path)===d,te=G==="modified"||G==="deleted",Y=G==="added";return a.jsxs("div",{className:"px-4 py-3 border-b border-white/10 flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[L(G),a.jsx("span",{className:"text-sm font-mono text-white/80 truncate",children:d})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[B?a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsxs("button",{onClick:E,className:"flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium bg-red-500/20 text-red-400 hover:bg-red-500/30 transition-colors",children:["Confirm ",y.action==="discard"?"Discard":"Delete","?"]}),a.jsx("button",{onClick:N,className:"p-1.5 rounded-lg text-white/40 hover:text-white/60 hover:bg-white/5 transition-colors",children:a.jsx(ve,{className:"h-4 w-4"})})]}):a.jsxs(a.Fragment,{children:[te&&a.jsxs("button",{onClick:()=>S(d,"discard"),className:"flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium text-red-400/70 hover:text-red-400 hover:bg-red-500/10 transition-colors",children:[a.jsx(gd,{className:"h-4 w-4"}),"Discard"]}),Y&&a.jsxs("button",{onClick:()=>S(d,"delete"),className:"flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium text-red-400/70 hover:text-red-400 hover:bg-red-500/10 transition-colors",children:[a.jsx(St,{className:"h-4 w-4"}),"Delete"]})]}),a.jsxs("button",{onClick:()=>r(d),className:A("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium transition-colors",z!=null&&z.approved?"bg-emerald-500/20 text-emerald-400":"bg-white/10 text-white hover:bg-white/15"),children:[a.jsx(ke,{className:"h-4 w-4"}),z!=null&&z.approved?"Approved":"Approve"]})]})]})})(),a.jsx("div",{className:"flex-1 overflow-auto p-4",children:g?a.jsx("div",{className:"flex items-center justify-center h-full",children:a.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-white/10 border-t-white/50"})}):a.jsx(v1e,{diff:h})})]}),a.jsxs("div",{className:"w-full sm:w-56 sm:flex-shrink-0 flex flex-row sm:flex-col gap-3 sm:gap-4",children:[a.jsxs("div",{className:"flex-1 sm:flex-none rounded-xl bg-white/[0.03] ring-1 ring-white/10 p-4",children:[a.jsx("div",{className:"text-xs font-medium text-white/50 uppercase tracking-wider mb-3",children:"Review Progress"}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("span",{className:"text-2xl font-semibold text-white",children:[Math.round(M/j*100),"%"]}),a.jsxs("span",{className:"text-sm text-white/50",children:[M," of ",j]})]}),a.jsx("div",{className:"h-2 rounded-full bg-white/10 overflow-hidden",children:a.jsx(q.div,{initial:{width:0},animate:{width:`${M/j*100}%`},className:"h-full bg-emerald-500 rounded-full"})})]})]}),a.jsxs("div",{className:"flex-1 sm:flex-none rounded-xl bg-white/[0.03] ring-1 ring-white/10 p-4",children:[a.jsx("div",{className:"text-xs font-medium text-white/50 uppercase tracking-wider mb-3",children:"Changes"}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white/60",children:"Added"}),a.jsxs("span",{className:"text-sm text-emerald-400 font-mono",children:["+",n.reduce((z,G)=>z+(G.insertions||0),0)]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white/60",children:"Removed"}),a.jsxs("span",{className:"text-sm text-red-400 font-mono",children:["-",n.reduce((z,G)=>z+(G.deletions||0),0)]})]})]})]}),n.some(z=>["auth","secret",".env","password","token","key"].some(G=>z.path.toLowerCase().includes(G)))&&a.jsx("div",{className:"rounded-xl bg-amber-500/10 ring-1 ring-amber-500/20 p-4",children:a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsx(Ge,{className:"h-4 w-4 text-amber-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-medium text-amber-400",children:"Security Review"}),a.jsx("p",{className:"text-xs text-amber-400/70 mt-1",children:"Some files may contain sensitive code. Review carefully."})]})]})})]})]})}function v1e({diff:e}){const t=e.split(`
|
|
7791
7792
|
`);return a.jsx("div",{className:"font-mono text-xs leading-relaxed",children:t.map((n,r)=>{let i="",s="text-white/60";return n.startsWith("+")&&!n.startsWith("+++")?(i="bg-emerald-500/10",s="text-emerald-400"):n.startsWith("-")&&!n.startsWith("---")?(i="bg-red-500/10",s="text-red-400"):n.startsWith("@@")?s="text-blue-400":(n.startsWith("diff")||n.startsWith("index"))&&(s="text-white/30"),a.jsx("div",{className:A("px-2 py-0.5 whitespace-pre-wrap break-all",i,s),children:n||" "},r)})})}function S1e({orgName:e,repoName:t,onSetupPAT:n,onDismiss:r,organizationUrl:i}){const[s,o]=f.useState(!1),[l,c]=f.useState(!1);f.useEffect(()=>{const p=h=>{h.key==="Escape"&&r()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[r]),f.useEffect(()=>(document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}),[]);const d=f.useCallback(async()=>{try{await navigator.clipboard.writeText(i),c(!0),setTimeout(()=>c(!1),2e3)}catch(p){console.error("Failed to copy link:",p)}},[i]);return a.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 animate-in fade-in duration-200",role:"dialog","aria-modal":"true","aria-labelledby":"modal-title",onClick:r,children:[a.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),a.jsxs("div",{onClick:p=>p.stopPropagation(),className:A("relative w-full max-w-[560px]","bg-[#0A0A0A]/95 backdrop-blur-xl","rounded-2xl shadow-2xl","ring-1 ring-white/10","animate-in zoom-in-95 slide-in-from-bottom-4 duration-300"),children:[a.jsx("button",{onClick:r,className:A("absolute top-4 right-4 p-2 rounded-lg","text-white/40 hover:text-white/70 hover:bg-white/10","transition-all duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/30"),"aria-label":"Close modal",children:a.jsx(ve,{className:"h-5 w-5"})}),a.jsxs("div",{className:"p-8",children:[a.jsxs("div",{className:"flex items-start gap-4 mb-6",children:[a.jsx("div",{className:"flex-shrink-0",children:a.jsx("div",{className:"w-12 h-12 rounded-xl bg-amber-500/20 ring-1 ring-amber-500/40 flex items-center justify-center",children:a.jsx(Jr,{className:"h-6 w-6 text-amber-400"})})}),a.jsxs("div",{className:"flex-1 pt-1",children:[a.jsx("h2",{id:"modal-title",className:"text-xl font-semibold text-white mb-2 leading-tight",children:"Organization Access Required"}),a.jsxs("p",{className:"text-sm text-white/70 leading-relaxed",children:["Claude Desk doesn't have access to ",a.jsx("span",{className:"font-medium text-white",children:e})," repositories. To create a PR in ",a.jsx("span",{className:"font-mono text-white/90",children:t}),", choose an option below:"]})]})]}),a.jsxs("div",{className:"space-y-3 mb-6",children:[a.jsxs("div",{className:A("relative rounded-xl p-5","bg-emerald-500/5 ring-1 ring-emerald-500/20","border-l-4 border-emerald-500","animate-in slide-in-from-left-4 fade-in duration-300","style-[animation-delay:100ms]"),children:[a.jsx("div",{className:"absolute top-3 right-3",children:a.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-emerald-500/20 ring-1 ring-emerald-500/30",children:[a.jsx(ta,{className:"h-3 w-3 text-emerald-400"}),a.jsx("span",{className:"text-[10px] font-bold tracking-wider uppercase text-emerald-400",children:"Fastest"})]})}),a.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[a.jsx("div",{className:"flex-shrink-0 mt-0.5",children:a.jsx("div",{className:"w-10 h-10 rounded-lg bg-emerald-500/20 ring-1 ring-emerald-500/30 flex items-center justify-center",children:a.jsx(ta,{className:"h-5 w-5 text-emerald-400"})})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("h3",{className:"text-base font-semibold text-white mb-1",children:"Use Personal Access Token"}),a.jsx("p",{className:"text-sm text-white/60 mb-3",children:"Set up in 2 minutes. Works immediately without waiting for admin approval."}),a.jsxs("ul",{className:"space-y-1.5 mb-4",children:[a.jsxs("li",{className:"flex items-center gap-2 text-sm text-white/70",children:[a.jsx(ke,{className:"h-4 w-4 text-emerald-400 flex-shrink-0"}),a.jsx("span",{children:"Works immediately"})]}),a.jsxs("li",{className:"flex items-center gap-2 text-sm text-white/70",children:[a.jsx(ke,{className:"h-4 w-4 text-emerald-400 flex-shrink-0"}),a.jsx("span",{children:"No organization approval needed"})]}),a.jsxs("li",{className:"flex items-center gap-2 text-sm text-white/70",children:[a.jsx(ke,{className:"h-4 w-4 text-emerald-400 flex-shrink-0"}),a.jsx("span",{children:"Uses your existing GitHub permissions"})]})]}),a.jsx("button",{onClick:n,className:A("w-full px-4 py-2.5 rounded-xl","bg-emerald-500/20 hover:bg-emerald-500/30","text-emerald-400 font-medium text-sm","ring-1 ring-emerald-500/30","transition-all duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/50","active:scale-[0.98]"),children:"Set Up Token"})]})]})]}),a.jsx("div",{className:A("rounded-xl p-5","bg-blue-500/5 ring-1 ring-blue-500/20","border-l-4 border-blue-500","animate-in slide-in-from-left-4 fade-in duration-300","style-[animation-delay:200ms]"),children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"flex-shrink-0 mt-0.5",children:a.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/20 ring-1 ring-blue-500/30 flex items-center justify-center",children:a.jsx(ea,{className:"h-5 w-5 text-blue-400"})})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("h3",{className:"text-base font-semibold text-white mb-1",children:"Request Organization Approval"}),a.jsx("p",{className:"text-sm text-white/60 mb-3",children:"Ask your org admin to approve Claude Desk OAuth app access."}),a.jsxs("ul",{className:"space-y-1.5 mb-4",children:[a.jsxs("li",{className:"flex items-center gap-2 text-sm text-white/70",children:[a.jsx(ke,{className:"h-4 w-4 text-blue-400 flex-shrink-0"}),a.jsx("span",{children:"No token management"})]}),a.jsxs("li",{className:"flex items-center gap-2 text-sm text-white/60",children:[a.jsx("div",{className:"h-1 w-1 rounded-full bg-white/40 flex-shrink-0 ml-1.5"}),a.jsx("span",{children:"Requires admin approval"})]}),a.jsxs("li",{className:"flex items-center gap-2 text-sm text-white/60",children:[a.jsx("div",{className:"h-1 w-1 rounded-full bg-white/40 flex-shrink-0 ml-1.5"}),a.jsx("span",{children:"May take several days"})]})]}),s?a.jsxs("div",{className:A("rounded-lg bg-blue-500/5 p-4 ring-1 ring-blue-500/10","animate-in slide-in-from-top-2 fade-in duration-300"),children:[a.jsx("p",{className:"text-xs font-medium text-blue-400 mb-3 uppercase tracking-wide",children:"How to grant access:"}),a.jsxs("ol",{className:"space-y-2.5 text-sm text-white/70 mb-4",children:[a.jsxs("li",{className:"flex gap-3",children:[a.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500/20 ring-1 ring-blue-500/30 flex items-center justify-center text-xs font-medium text-blue-400",children:"1"}),a.jsx("span",{children:'Click "Open GitHub Settings" below'})]}),a.jsxs("li",{className:"flex gap-3",children:[a.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500/20 ring-1 ring-blue-500/30 flex items-center justify-center text-xs font-medium text-blue-400",children:"2"}),a.jsxs("span",{children:['Find "',a.jsx("span",{className:"font-medium text-white",children:e}),'" in Organization access section']})]}),a.jsxs("li",{className:"flex gap-3",children:[a.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500/20 ring-1 ring-blue-500/30 flex items-center justify-center text-xs font-medium text-blue-400",children:"3"}),a.jsxs("span",{children:['Click "Grant" next to ',e]})]}),a.jsxs("li",{className:"flex gap-3",children:[a.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500/20 ring-1 ring-blue-500/30 flex items-center justify-center text-xs font-medium text-blue-400",children:"4"}),a.jsx("span",{children:"Authorize the application"})]}),a.jsxs("li",{className:"flex gap-3",children:[a.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500/20 ring-1 ring-blue-500/30 flex items-center justify-center text-xs font-medium text-blue-400",children:"5"}),a.jsx("span",{children:"Return here and retry creating the PR"})]})]}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:A("flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg","bg-blue-500/20 hover:bg-blue-500/30","text-blue-400 font-medium text-sm","ring-1 ring-blue-500/30","transition-all duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/50"),children:[a.jsx(Tt,{className:"h-4 w-4"}),"Open GitHub Settings"]}),a.jsx("button",{onClick:d,className:A("px-3 py-2.5 rounded-lg","transition-all duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/50",l?"bg-emerald-500/20 text-emerald-400":"bg-blue-500/10 hover:bg-blue-500/20 text-blue-400"),"aria-label":l?"Link copied":"Copy link",children:l?a.jsx(ke,{className:"h-4 w-4"}):a.jsx(ht,{className:"h-4 w-4"})})]})]}):a.jsx("button",{onClick:()=>o(!0),className:A("w-full px-4 py-2.5 rounded-xl","bg-blue-500/10 hover:bg-blue-500/20","text-blue-400 font-medium text-sm","ring-1 ring-blue-500/20","transition-all duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/50","active:scale-[0.98]"),children:"View Instructions"})]})]})})]}),a.jsx("div",{className:"text-center",children:a.jsx("button",{onClick:r,className:"text-sm text-white/40 hover:text-white/60 transition-colors underline underline-offset-4",children:"I'll do this later"})})]})]})]})}function N1e({sessionId:e,repoId:t,isMultiRepo:n=!1,reviewFiles:r,onSuccess:i,onGoBack:s}){var Se,ue,ce,P,J,ne,de,xe,se,je;const[o,l]=f.useState(null),[c,d]=f.useState([]),[p,h]=f.useState(!0),[m,g]=f.useState(""),[x,k]=f.useState(""),[w,y]=f.useState(""),[b,v]=f.useState(!0),[S,N]=f.useState(!0),[E,M]=f.useState(!1),[j,_]=f.useState(!1),[C,O]=f.useState(null),[L,z]=f.useState(new Set),[G,B]=f.useState(!1);f.useEffect(()=>{var K;((K=C==null?void 0:C.errorDetails)==null?void 0:K.type)==="org_access_required"&&C.errorDetails.organizationUrl&&B(!0)},[C]);const te=(o==null?void 0:o.existingPR)&&o.existingPR.state==="open",Y=(o==null?void 0:o.existingPR)&&(o.existingPR.state==="merged"||o.existingPR.state==="closed"),R=f.useMemo(()=>{if(!o)return[];if(!o.hasUncommittedChanges)return[];const K=[],pe=new Set,ae=r&&r.length>0?new Set(r):null,Re=ae?o.files.filter(Qe=>ae.has(Qe.path)):o.files;for(const Qe of Re){const $e=Qe.path.toLowerCase();($e.includes("auth")||$e.includes("login")||$e.includes("password"))&&!pe.has("auth")&&(pe.add("auth"),K.push({id:"auth",severity:"warning",title:"Authentication code modified",description:"Review security implications of auth changes.",canDismiss:!0})),($e.includes(".env")||$e.includes("secret")||$e.includes("credential"))&&!pe.has("secrets")&&(pe.add("secrets"),K.push({id:"secrets",severity:"critical",title:"Possible secrets detected",description:"Verify no sensitive data is being committed.",canDismiss:!1})),($e.includes("security")||$e.includes("crypto")||$e.includes("token"))&&!pe.has("security")&&(pe.add("security"),K.push({id:"security",severity:"critical",title:"Security-critical code",description:"Extra review recommended for security paths.",canDismiss:!1}))}return K},[o,r]),H=R.some(K=>K.severity==="critical"&&!K.canDismiss&&!L.has(K.id)),I=f.useMemo(()=>{if(!o)return{fileCount:0,insertions:0,deletions:0};if(!r||r.length===0)return{fileCount:o.files.length,insertions:o.totalInsertions,deletions:o.totalDeletions};const K=new Set(r),pe=o.files.filter(ae=>K.has(ae.path));return{fileCount:pe.length,insertions:pe.reduce((ae,Re)=>ae+Re.insertions,0),deletions:pe.reduce((ae,Re)=>ae+Re.deletions,0)}},[o,r]),Q=f.useCallback(K=>n&&t?`${K}?repoId=${t}`:K,[n,t]);f.useEffect(()=>{if(!e)return;(async()=>{h(!0);try{const pe=await F("GET",Q(`/terminal/sessions/${e}/ship-summary`));let ae=[];try{ae=(await F("GET",`/terminal/repos/${t||e}/branches`)).branches||[]}catch{}l(pe);const Re=pe.baseBranch||"main";if(ae.length===0?ae.push(Re):ae.includes(Re)||ae.unshift(Re),d(ae),y(Qe=>Qe||Re),pe.currentBranch&&!m){const Qe=pe.currentBranch.replace(/^(feature|fix|bugfix|hotfix|chore|refactor|docs)\//,"").replace(/[-_]/g," ").replace(/^\w/,$e=>$e.toUpperCase());g(Qe)}!pe.hasUncommittedChanges&&pe.commitsAheadOfBase>0&&(v(!1),N(!0))}catch(pe){console.error("Failed to load ship summary:",pe)}finally{h(!1)}})()},[e,t,Q]);const Z=async()=>{if(e){_(!0);try{const K={targetBranch:w||(o==null?void 0:o.baseBranch)||"main"};t&&(K.repoId=t);const pe=await F("POST",`/terminal/sessions/${e}/generate-pr-content`,K);g(pe.title),k(pe.description)}catch(K){console.error("Failed to generate:",K)}finally{_(!1)}}},D=async()=>{if(!(!e||!m.trim())){M(!0),O(null);try{const K={commitMessage:m.trim(),push:b,createPR:S,prTitle:m.trim(),prBody:x,targetBranch:w||(o==null?void 0:o.baseBranch)||"main"};t&&(K.repoId=t);const pe=await F("POST",`/terminal/sessions/${e}/ship`,K);O(pe),pe.success&&i&&i({prUrl:pe.prUrl,commitHash:pe.commitHash})}catch(K){O({success:!1,error:K instanceof Error?K.message:"Ship failed"})}finally{M(!1)}}},Ie=K=>{switch(K){case"org_access_required":case"rate_limited":case"pr_already_exists":return"border-l-amber-400";case"branch_not_found":return"border-l-blue-400";default:return"border-l-red-400"}},Le=K=>{switch(K){case"org_access_required":case"rate_limited":case"pr_already_exists":return"text-amber-400";case"branch_not_found":return"text-blue-400";default:return"text-red-400"}},ge=K=>{switch(K){case"org_access_required":return Jr;case"token_expired":return gp;case"branch_not_found":return pp;case"repo_not_found":return up;case"pr_already_exists":return pa;case"rate_limited":return Xn;default:return dt}},we=K=>{switch(K){case"org_access_required":return"Organization Access Required";case"token_expired":return"GitHub Connection Expired";case"token_invalid":return"GitHub Access Denied";case"repo_not_found":return"Repository Not Found";case"branch_not_found":return"Branch Not Pushed";case"pr_already_exists":return"Pull Request Already Exists";case"rate_limited":return"GitHub Rate Limited";default:return"Failed to Create Pull Request"}};return C!=null&&C.success?a.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:a.jsxs(q.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},className:"text-center",children:[a.jsx("div",{className:"mx-auto mb-4 flex h-20 w-20 items-center justify-center rounded-full bg-emerald-500/20 ring-2 ring-emerald-500/40",children:a.jsx(ke,{className:"h-10 w-10 text-emerald-400"})}),a.jsx("h2",{className:"text-2xl font-semibold text-white mb-2",children:"Shipped!"}),a.jsx("p",{className:"text-white/60 mb-6",children:"Your changes are on their way."}),C.commitHash&&a.jsxs("p",{className:"text-sm text-white/40 mb-2",children:["Commit: ",a.jsx("span",{className:"font-mono text-white/60",children:C.commitHash})]}),C.prUrl&&a.jsxs("a",{href:C.prUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 rounded-xl bg-white px-6 py-3 text-sm font-semibold text-black hover:opacity-90 transition-opacity",children:[a.jsx(Tt,{className:"h-4 w-4"}),"View Pull Request"]}),s&&a.jsx("button",{onClick:s,className:"mt-4 block w-full text-sm text-white/50 hover:text-white/70",children:"Start new conversation"})]})}):p?a.jsx("div",{className:"flex-1 flex items-center justify-center",children:a.jsx(he,{className:"h-8 w-8 animate-spin text-white/30"})}):o!=null&&o.hasChangesToShip?a.jsxs("div",{className:"flex-1 flex flex-col sm:flex-row min-h-0 gap-3 sm:gap-4 p-3 sm:p-4 overflow-y-auto sm:overflow-y-hidden",children:[a.jsxs("div",{className:"w-full sm:w-72 sm:flex-shrink-0 flex flex-col gap-3 sm:gap-4",children:[a.jsxs("div",{className:"rounded-xl bg-white/[0.03] ring-1 ring-white/10 p-4",children:[a.jsx("div",{className:"text-xs font-medium text-white/50 uppercase tracking-wider mb-3",children:"Branch Flow"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"min-w-0 flex-1 rounded-lg bg-emerald-500/10 px-3 py-2 ring-1 ring-emerald-500/20",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(yn,{className:"h-4 w-4 flex-shrink-0 text-emerald-400"}),a.jsx("span",{className:"text-sm font-mono text-emerald-400 truncate",children:o==null?void 0:o.currentBranch})]})}),a.jsx("div",{className:"flex-shrink-0 text-white/30",children:"→"}),a.jsx("div",{className:"min-w-0 flex-1",children:a.jsx("select",{value:w,onChange:K=>y(K.target.value),className:"w-full rounded-lg bg-white/5 px-3 py-2 text-base sm:text-sm font-mono text-white/80 ring-1 ring-white/10 focus:ring-white/20 focus:outline-none",children:c.map(K=>a.jsx("option",{value:K,children:K},K))})})]}),(o==null?void 0:o.unpushedCommits)>0?a.jsxs("p",{className:"mt-2 text-xs text-white/40",children:[o.unpushedCommits," unpushed commit",o.unpushedCommits>1?"s":""]}):(o==null?void 0:o.commitsAheadOfBase)>0?a.jsxs("p",{className:"mt-2 text-xs text-emerald-400/70",children:[o.commitsAheadOfBase," commit",o.commitsAheadOfBase>1?"s":""," ahead (pushed)"]}):null]}),a.jsxs("div",{className:"rounded-xl bg-white/[0.03] ring-1 ring-white/10 p-4 sm:flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[a.jsx(ea,{className:"h-4 w-4 text-white/50"}),a.jsx("span",{className:"text-xs font-medium text-white/50 uppercase tracking-wider",children:"Safety Check"})]}),R.length===0?a.jsxs("div",{className:"flex items-center gap-2 text-emerald-400",children:[a.jsx(ke,{className:"h-4 w-4"}),a.jsx("span",{className:"text-sm",children:"All clear"})]}):a.jsx("div",{className:"space-y-2",children:R.map(K=>a.jsx("div",{className:A("rounded-lg p-3 ring-1",K.severity==="critical"?"bg-red-500/10 ring-red-500/20":K.severity==="warning"?"bg-amber-500/10 ring-amber-500/20":"bg-blue-500/10 ring-blue-500/20",L.has(K.id)&&"opacity-50"),children:a.jsxs("div",{className:"flex items-start gap-2",children:[K.severity==="critical"?a.jsx(dt,{className:"h-4 w-4 text-red-400 flex-shrink-0 mt-0.5"}):a.jsx(Ge,{className:"h-4 w-4 text-amber-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-sm font-medium text-white",children:K.title}),a.jsx("p",{className:"text-xs text-white/50 mt-0.5",children:K.description})]}),K.canDismiss&&!L.has(K.id)&&a.jsx("button",{onClick:()=>z(pe=>new Set([...pe,K.id])),className:"text-xs text-white/40 hover:text-white/60",children:"Dismiss"})]})},K.id))})]}),a.jsx("div",{className:"rounded-xl bg-white/[0.03] ring-1 ring-white/10 p-4",children:a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsxs("span",{className:"text-white/50",children:[I.fileCount," files"]}),a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsxs("span",{className:"text-emerald-400 font-mono",children:["+",I.insertions]}),a.jsxs("span",{className:"text-red-400 font-mono",children:["-",I.deletions]})]})]})})]}),a.jsxs("div",{className:"flex-1 flex flex-col rounded-xl bg-white/[0.03] ring-1 ring-white/10 overflow-hidden min-w-0 min-h-0",children:[a.jsxs("div",{className:"px-4 py-3 border-b border-white/10 flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(pa,{className:"h-4 w-4 text-white/50"}),a.jsx("span",{className:"text-sm font-medium text-white/70",children:"Pull Request Preview"})]}),a.jsxs("button",{onClick:Z,disabled:j,className:"flex items-center gap-1.5 rounded-lg bg-white/5 px-3 py-1.5 text-xs text-white/60 hover:bg-white/10 hover:text-white/80 transition-colors disabled:opacity-50",children:[j?a.jsx(he,{className:"h-3 w-3 animate-spin"}):a.jsx(nn,{className:"h-3 w-3"}),j?"Generating...":"AI Generate"]})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",children:[!(o!=null&&o.hasUncommittedChanges)&&(o==null?void 0:o.commitsAheadOfBase)>0&&!(o!=null&&o.existingPR)&&a.jsx("div",{className:"rounded-xl p-4 ring-1 bg-blue-500/10 ring-blue-500/20",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg ring-1 bg-blue-500/15 ring-blue-500/30",children:a.jsx(pa,{className:"h-4 w-4 text-blue-400"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-sm font-medium text-white mb-0.5",children:"Branch ready for PR"}),a.jsxs("p",{className:"text-xs text-white/50",children:[o.commitsAheadOfBase," commit",o.commitsAheadOfBase>1?"s":""," ahead of ",o.baseBranch,". Changes are already pushed."]})]})]})}),(o==null?void 0:o.existingPR)&&a.jsxs("div",{className:A("rounded-xl p-4 ring-1",o.existingPR.state==="merged"?"bg-purple-500/10 ring-purple-500/20":o.existingPR.state==="closed"?"bg-red-500/10 ring-red-500/20":"bg-emerald-500/10 ring-emerald-500/20"),children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:A("flex h-9 w-9 items-center justify-center rounded-lg ring-1",o.existingPR.state==="merged"?"bg-purple-500/15 ring-purple-500/30":o.existingPR.state==="closed"?"bg-red-500/15 ring-red-500/30":"bg-emerald-500/15 ring-emerald-500/30"),children:o.existingPR.state==="merged"?a.jsx(nr,{className:"h-4 w-4 text-purple-400"}):o.existingPR.state==="closed"?a.jsx(Gt,{className:"h-4 w-4 text-red-400"}):a.jsx(pa,{className:"h-4 w-4 text-emerald-400"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("span",{className:"text-sm font-medium text-white",children:["PR #",o.existingPR.number]}),a.jsx("span",{className:A("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider ring-1",o.existingPR.state==="merged"?"bg-purple-500/15 text-purple-400 ring-purple-500/30":o.existingPR.state==="closed"?"bg-red-500/15 text-red-400 ring-red-500/30":"bg-emerald-500/15 text-emerald-400 ring-emerald-500/30"),children:o.existingPR.state||"open"})]}),a.jsx("p",{className:"text-xs text-white/50 truncate mt-0.5",children:o.existingPR.title})]}),a.jsxs("a",{href:o.existingPR.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 rounded-lg bg-white/5 px-3 py-1.5 text-xs text-white/60 hover:bg-white/10 hover:text-white/80 ring-1 ring-white/10 transition-colors",children:[a.jsx(Tt,{className:"h-3.5 w-3.5"}),"View"]})]}),a.jsx("p",{className:"mt-2 text-xs text-white/40",children:Y?`Previous PR was ${o.existingPR.state}. A new PR will be created.`:"New commits will be pushed to the existing PR."})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs font-medium text-white/50 mb-1.5",children:"PR Title"}),a.jsx("input",{type:"text",value:m,onChange:K=>g(K.target.value),placeholder:"Add a concise title...",className:"w-full rounded-lg bg-white/5 px-3 py-2.5 text-sm text-white placeholder:text-white/30 ring-1 ring-white/10 focus:ring-white/20 focus:outline-none"})]}),a.jsxs("div",{className:"flex-1 flex flex-col",children:[a.jsx("label",{className:"block text-xs font-medium text-white/50 mb-1.5",children:"Description"}),a.jsx("textarea",{value:x,onChange:K=>k(K.target.value),placeholder:"Describe your changes...",className:"flex-1 min-h-[120px] sm:min-h-[200px] w-full rounded-lg bg-white/5 px-3 py-2.5 text-sm text-white placeholder:text-white/30 ring-1 ring-white/10 focus:ring-white/20 focus:outline-none resize-none"})]}),a.jsxs("div",{className:"flex items-center gap-4",children:[a.jsxs("label",{className:A("flex items-center gap-2",o!=null&&o.hasUncommittedChanges?"cursor-pointer":"cursor-not-allowed opacity-50"),children:[a.jsx("input",{type:"checkbox",checked:b,onChange:K=>v(K.target.checked),disabled:!(o!=null&&o.hasUncommittedChanges),className:"rounded border-white/20 bg-white/5 text-emerald-500 focus:ring-emerald-500/20 disabled:cursor-not-allowed"}),a.jsx("span",{className:"text-sm text-white/70",children:"Push to remote"})]}),a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:S,onChange:K=>N(K.target.checked),className:"rounded border-white/20 bg-white/5 text-emerald-500 focus:ring-emerald-500/20"}),a.jsx("span",{className:"text-sm text-white/70",children:"Create PR"})]})]}),(C==null?void 0:C.error)&&a.jsx("div",{className:A("rounded-xl p-4 bg-white/[0.03] ring-1 ring-white/10","border-l-4",Ie((Se=C.errorDetails)==null?void 0:Se.type),"space-y-3","animate-in slide-in-from-top-2 fade-in duration-200"),role:"alert","aria-live":"assertive",children:a.jsxs("div",{className:"flex items-start gap-3",children:[(()=>{var pe,ae;const K=ge((pe=C.errorDetails)==null?void 0:pe.type);return a.jsx(K,{className:A("h-5 w-5 flex-shrink-0 mt-0.5",Le((ae=C.errorDetails)==null?void 0:ae.type))})})(),a.jsxs("div",{className:"flex-1 min-w-0 space-y-3",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm font-medium text-white mb-1",children:we((ue=C.errorDetails)==null?void 0:ue.type)}),a.jsx("p",{className:"text-sm text-white/70 leading-6",children:C.error})]}),((ce=C.errorDetails)==null?void 0:ce.type)==="org_access_required"&&C.errorDetails.organizationUrl&&a.jsx("button",{onClick:()=>B(!0),className:"w-full px-4 py-2.5 rounded-lg bg-amber-500/20 hover:bg-amber-500/30 text-sm font-medium text-amber-400 ring-1 ring-amber-500/30 transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500/50",children:"View Access Options"}),((P=C.errorDetails)==null?void 0:P.type)==="token_expired"&&a.jsx("div",{className:"rounded-lg bg-white/[0.03] p-3",children:a.jsx("p",{className:"text-sm text-white/70",children:"Your GitHub connection has expired. Reconnect your account in Settings → Integrations."})}),((J=C.errorDetails)==null?void 0:J.type)==="branch_not_found"&&a.jsx("div",{className:"rounded-lg bg-white/[0.03] p-3",children:a.jsx("p",{className:"text-sm text-white/70",children:`Your branch exists locally but hasn't been pushed to GitHub yet. Try enabling "Push to remote" and shipping again.`})}),((ne=C.errorDetails)==null?void 0:ne.type)==="repo_not_found"&&!((de=C.errorDetails)!=null&&de.organizationUrl)&&a.jsx("div",{className:"rounded-lg bg-white/[0.03] p-3 space-y-2",children:a.jsxs("ol",{className:"ml-6 space-y-2 text-sm text-white/70",children:[a.jsxs("li",{className:"flex gap-2",children:[a.jsx("span",{className:"text-white/50",children:"1."}),a.jsx("span",{children:"Verify the repository exists on GitHub"})]}),a.jsxs("li",{className:"flex gap-2",children:[a.jsx("span",{className:"text-white/50",children:"2."}),a.jsx("span",{children:"Check that your GitHub account has access"})]}),a.jsxs("li",{className:"flex gap-2",children:[a.jsx("span",{className:"text-white/50",children:"3."}),a.jsx("span",{children:"If it's a new repository, ensure it's been pushed"})]})]})}),((xe=C.errorDetails)==null?void 0:xe.type)==="pr_already_exists"&&(o==null?void 0:o.existingPR)&&a.jsx("div",{className:"rounded-lg bg-white/[0.03] p-3",children:a.jsxs("a",{href:o.existingPR.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-sm font-medium text-white/70 hover:text-white underline-offset-4 hover:underline transition-colors",children:[a.jsx(Tt,{className:"h-3.5 w-3.5"}),"View Existing PR #",o.existingPR.number]})}),a.jsx("div",{className:"flex flex-col sm:flex-row gap-3 pt-1",children:(se=C.errorDetails)!=null&&se.retryable?a.jsxs("button",{onClick:()=>O(null),className:"px-4 py-2.5 rounded-lg bg-white/10 hover:bg-white/15 text-sm font-medium text-white transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/30 flex items-center justify-center gap-2 w-full sm:w-auto",children:[a.jsx(xt,{className:"h-4 w-4"}),"Retry"]}):a.jsx("button",{onClick:()=>O(null),className:"px-4 py-2.5 rounded-lg bg-white/5 hover:bg-white/10 text-sm text-white/60 hover:text-white/80 transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/30 w-full sm:w-auto",children:"Dismiss"})})]})]})})]}),a.jsxs("div",{className:"p-4 border-t border-white/10",children:[a.jsx("button",{onClick:D,disabled:E||!m.trim()||H,className:A("w-full flex items-center justify-center gap-2 rounded-xl px-4 py-3 text-sm font-semibold transition-all",E||!m.trim()||H?"bg-white/10 text-white/40 cursor-not-allowed":"bg-white text-black hover:opacity-90"),children:E?a.jsxs(a.Fragment,{children:[a.jsx(he,{className:"h-4 w-4 animate-spin"}),"Shipping..."]}):a.jsxs(a.Fragment,{children:[a.jsx(Dn,{className:"h-4 w-4"}),te&&b?"Push to Existing PR":S&&!(o!=null&&o.hasUncommittedChanges)?"Create PR":S?"Commit & Create PR":"Ship Changes"]})}),H&&a.jsx("p",{className:"mt-2 text-xs text-center text-red-400",children:"Resolve critical warnings before shipping"})]})]}),G&&((je=C==null?void 0:C.errorDetails)==null?void 0:je.type)==="org_access_required"&&C.errorDetails.organizationUrl&&a.jsx(S1e,{orgName:C.errorDetails.owner||"the organization",repoName:C.errorDetails.repo||"this repository",onSetupPAT:()=>{B(!1),window.location.hash="#/settings/integrations"},onDismiss:()=>B(!1),organizationUrl:C.errorDetails.organizationUrl})]}):a.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:a.jsx("div",{className:"text-center max-w-md",children:o!=null&&o.existingPR?a.jsxs(q.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.3},children:[a.jsx("div",{className:"mx-auto mb-5 flex h-20 w-20 items-center justify-center rounded-full bg-purple-500/15 ring-2 ring-purple-500/30",children:o.existingPR.state==="merged"?a.jsx(nr,{className:"h-10 w-10 text-purple-400"}):o.existingPR.state==="closed"?a.jsx(Gt,{className:"h-10 w-10 text-red-400"}):a.jsx(pa,{className:"h-10 w-10 text-emerald-400"})}),a.jsxs("div",{className:A("inline-flex items-center gap-1.5 rounded-full px-3 py-1 mb-3 text-xs font-medium tracking-wide uppercase ring-1",o.existingPR.state==="merged"?"bg-purple-500/15 text-purple-400 ring-purple-500/30":o.existingPR.state==="closed"?"bg-red-500/15 text-red-400 ring-red-500/30":"bg-emerald-500/15 text-emerald-400 ring-emerald-500/30"),children:[o.existingPR.state==="merged"?a.jsx(nr,{className:"h-3 w-3"}):o.existingPR.state==="closed"?a.jsx(Gt,{className:"h-3 w-3"}):a.jsx(Kr,{className:"h-3 w-3 fill-current"}),o.existingPR.state||"open"]}),a.jsxs("h2",{className:"text-xl font-semibold text-white mb-1.5",children:["PR #",o.existingPR.number]}),a.jsx("p",{className:"text-sm text-white/60 mb-1",children:o.existingPR.title}),a.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-white/40 mb-6 font-mono",children:[a.jsx(yn,{className:"h-3 w-3"}),a.jsx("span",{children:o.currentBranch}),a.jsx("span",{className:"text-white/20",children:"→"}),a.jsx("span",{children:o.baseBranch})]}),a.jsxs("div",{className:"flex flex-col items-center gap-3",children:[a.jsxs("a",{href:o.existingPR.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 rounded-xl bg-white px-6 py-3 text-sm font-semibold text-black hover:opacity-90 transition-opacity",children:[a.jsx(Tt,{className:"h-4 w-4"}),"View Pull Request"]}),s&&a.jsx("button",{onClick:s,className:"text-sm text-white/40 hover:text-white/60 transition-colors",children:"Back to prompting"})]}),a.jsx("p",{className:"mt-6 text-xs text-white/30",children:o.existingPR.state==="merged"?"This PR has been merged. Make changes to create a new PR.":o.existingPR.state==="closed"?"This PR was closed. Make changes to create a new PR.":"No uncommitted changes. Push new commits to update this PR."})]}):a.jsxs(q.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.3},children:[a.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-white/5 ring-1 ring-white/10",children:a.jsx(Dn,{className:"h-8 w-8 text-white/30"})}),a.jsx("h2",{className:"text-lg font-semibold text-white mb-2",children:"Nothing to ship"}),a.jsx("p",{className:"text-sm text-white/50",children:"Make some changes first, then come back to ship them."}),s&&a.jsx("button",{onClick:s,className:"mt-4 text-sm text-blue-400 hover:text-blue-300",children:"Go back to prompting"})]})})})}const vT=({id:e,checked:t,title:n,description:r,icon:i,accentColor:s,recommended:o,disabled:l,warningText:c,onChange:d,index:p})=>a.jsx(q.button,{type:"button",onClick:l?void 0:d,disabled:l,initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:.1+p*.05,duration:.3},className:`
|
|
7792
7793
|
group relative w-full text-left rounded-xl border-2 transition-all duration-200
|
|
7793
7794
|
${t?`${s} bg-white/[0.03] border-opacity-100`:"border-white/10 bg-white/[0.02] hover:bg-white/[0.04] hover:border-white/20"}
|