flavor-code 1.3.13 → 1.3.15

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.
@@ -147,8 +147,8 @@ Describe when and how the agent should use this skill.`,disableModelInvocation:!
147
147
  `).length+3)),value:Ce,onChange:e=>we(e.target.value),onDoubleClick:e=>e.stopPropagation(),spellCheck:!1})]}):(0,P.jsx)(Qt,{text:xu(e)})},e.id)})??(D.prdMarkdown!==void 0&&(0,P.jsx)(Qt,{text:D.prdMarkdown}))}),(0,P.jsxs)(`section`,{className:`d2c-prd-regenerate`,children:[(0,P.jsx)(`header`,{children:(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`需要整体调整?`}),(0,P.jsx)(`span`,{children:`描述期望变化,AI 会基于当前 PRD 生成一份新草案。`})]})}),(0,P.jsx)(`textarea`,{rows:3,value:ye,"aria-label":`PRD 重新生成要求`,placeholder:`例如:保留现有范围,补充退款失败后的恢复流程`,onChange:e=>be(e.target.value)}),(0,P.jsxs)(`footer`,{children:[(0,P.jsx)(`span`,{children:`当前版本不会在生成过程中被覆盖`}),(0,P.jsxs)(`button`,{type:`button`,className:`d2c-prd-regenerate-button`,disabled:Te||s||ye.trim().length===0,onClick:()=>void cn(),children:[(0,P.jsx)(`i`,{"aria-hidden":`true`,children:`↻`}),`重新生成 PRD`]})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`退回意见`}),(0,P.jsx)(`textarea`,{rows:3,value:_e,placeholder:`例如:补充退款失败后的恢复路径`,onChange:e=>ve(e.target.value)})]}),(0,P.jsxs)(`div`,{className:`d2c-artifact-actions`,children:[(0,P.jsx)(`button`,{type:`button`,disabled:Te||s||_e.trim().length===0,onClick:()=>void sn(`prd`,!1),children:`退回修改`}),(0,P.jsx)(`button`,{type:`button`,className:`primary`,disabled:Te||s,onClick:()=>void sn(`prd`,!0),children:`确认 PRD,生成交互稿`})]})]}),D?.plan.phase===`design-generating`&&(0,P.jsxs)(`div`,{className:`d2c-artifact-wait`,"data-invalid":D.validationError?.stage===`design`,"aria-live":`polite`,children:[(0,P.jsx)(`i`,{}),(0,P.jsx)(`div`,{children:D.validationError?.stage===`design`?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`strong`,{children:`交互契约未通过预检`}),(0,P.jsx)(`span`,{children:D.validationError.message})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`strong`,{children:`正在生成可交互体验基线`}),(0,P.jsx)(`span`,{children:`视觉、关键状态和行为契约会一起落盘。`})]})}),D.validationError?.stage===`design`?(0,P.jsx)(`button`,{type:`button`,disabled:Te||s,onClick:()=>void jt(),children:`自动修复清单`}):(0,P.jsx)(`button`,{type:`button`,onClick:()=>void an(D.plan.task),children:`刷新`})]}),D?.plan.phase===`design-review`&&(0,P.jsxs)(`div`,{className:`d2c-artifact-review d2c-design-review`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`span`,{children:`INTERACTIVE PROTOTYPE`}),(0,P.jsx)(`h3`,{children:`直接体验,再决定是否开发`}),(0,P.jsx)(`p`,{children:`点击、输入并检查主流程和异常状态;确认后它会成为 E2E 中 D2C 视觉还原的设计基线。`})]}),(0,P.jsx)(Uu,{url:he.url,onStart:()=>void nn(D.plan.task)}),(0,P.jsxs)(`div`,{className:`d2c-prototype-tools`,children:[(0,P.jsx)(`span`,{children:he.running?`● LOOPBACK PREVIEW`:`PREVIEW STOPPED`}),he.running&&(0,P.jsx)(`button`,{type:`button`,onClick:()=>void window.flavorDesktop.openD2cProductPreview(D.plan.task),children:`浏览器打开`})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`退回意见`}),(0,P.jsx)(`textarea`,{rows:3,value:_e,placeholder:`例如:筛选结果缺少空状态,趋势图悬停信息不够明确`,onChange:e=>ve(e.target.value)})]}),(0,P.jsxs)(`div`,{className:`d2c-artifact-actions`,children:[(0,P.jsx)(`button`,{type:`button`,disabled:Te||s||_e.trim().length===0,onClick:()=>void sn(`design`,!1),children:`退回修改`}),(0,P.jsx)(`button`,{type:`button`,className:`primary`,disabled:Te||s,onClick:()=>void sn(`design`,!0),children:`确认设计,进入 D2C 视觉还原`})]})]}),D?.plan.phase===`ready-for-d2c`&&(0,P.jsxs)(`div`,{className:`d2c-artifact-wait`,"data-ready":`true`,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`设计基线已确认`}),(0,P.jsx)(`span`,{children:`如果生成任务未启动或应用曾关闭,可从这里安全地继续 D2C 视觉还原。`})]}),(0,P.jsx)(`button`,{type:`button`,disabled:Te||s,onClick:()=>void sn(`design`,!0),children:`继续视觉还原 →`})]}),s&&(0,P.jsx)(`p`,{className:`d2c-start-warning`,children:`当前会话正在执行其他任务,完成或中断后可开始 E2E。`})]})]}):Cn===`pending`&&a!==void 0?(0,P.jsx)(Xu,{pending:a,onOpenLog:e,onInterrupt:t}):(ke===`integration`||ke===`acceptance`)&&j.running&&j.url!==void 0?(0,P.jsxs)(`main`,{className:`d2c-live-preview`,"aria-label":`Interactive integration preview`,children:[(0,P.jsxs)(`header`,{className:`d2c-live-toolbar`,children:[(0,P.jsxs)(`span`,{className:`d2c-live-state`,children:[(0,P.jsx)(`i`,{}),` LIVE`]}),(0,P.jsx)(`code`,{title:j.url,children:j.url}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>ut(e=>e+1),children:`Refresh`}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>void window.flavorDesktop.openD2cPreview(u.report.task),children:`Open in browser`})]}),(0,P.jsx)(Q,{url:j.url,reloadKey:lt,task:u.report.task})]}):(0,P.jsxs)(`main`,{className:`d2c-canvas-area`,"data-pages":yn.length>1?`multiple`:`single`,children:[u!==void 0&&Et!==void 0&&mn!==void 0&&hn!==void 0&&(0,P.jsxs)(P.Fragment,{children:[yn.length>1&&(0,P.jsxs)(`nav`,{className:`d2c-page-rail`,"aria-label":`页面评测结果`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`页面`}),(0,P.jsx)(`span`,{children:u.report.page===void 0?``:`${u.report.page.index+1} / ${u.report.page.count}`})]}),(0,P.jsx)(`div`,{children:yn.map(e=>(0,P.jsxs)(`button`,{type:`button`,"aria-pressed":e.reportId===u.report.reportId,"data-selected":e.reportId===u.report.reportId,"data-status":e.evaluationStatus,onClick:()=>void kt(e),children:[(0,P.jsx)(`span`,{children:e.page?.label??e.reportId}),(0,P.jsx)(`small`,{children:e.evaluationStatus===`invalid`?`待重测`:`${e.total.toFixed(1)} · ${e.issueCount} 项`})]},e.reportId))})]}),(0,P.jsxs)(`div`,{className:`d2c-trust-bar`,"data-status":hn.status,children:[(0,P.jsx)(`strong`,{children:Fu[hn.verdict]}),(0,P.jsx)(`span`,{children:hn.summary}),(0,P.jsx)(`div`,{children:hn.checks.map(e=>(0,P.jsxs)(`span`,{"data-status":e.status,title:e.message,children:[e.status===`pass`?`✓`:e.status===`warn`?`!`:`×`,` `,e.label]},e.key))})]}),(0,P.jsxs)(`div`,{className:`d2c-canvas-toolbar`,children:[(0,P.jsx)(`div`,{className:`d2c-mode-switch`,role:`tablist`,"aria-label":`画布显示模式`,children:gn.map(e=>(0,P.jsx)(`button`,{role:`tab`,"aria-selected":g===e,"data-active":g===e,onClick:()=>v(e),children:Pu[e]},e))}),g===`overlay`&&(0,P.jsxs)(`label`,{className:`d2c-opacity d2c-opacity-overlay`,children:[(0,P.jsxs)(`span`,{children:[`实现 `,Math.round(y*100),`%`]}),(0,P.jsx)(`input`,{type:`range`,min:0,max:100,value:Math.round(y*100),onChange:e=>b(Number(e.target.value)/100)})]}),g===`wipe`&&(0,P.jsxs)(`label`,{className:`d2c-opacity d2c-opacity-wipe`,children:[(0,P.jsxs)(`span`,{children:[`分界 `,x,`%`]}),(0,P.jsx)(`input`,{type:`range`,min:0,max:100,value:x,onChange:e=>S(Number(e.target.value))})]}),(0,P.jsxs)(`div`,{className:`d2c-zoom-tools`,"aria-label":`缩放控制`,children:[(0,P.jsx)(`button`,{onClick:()=>zt(1/1.2),"aria-label":`缩小`,children:`−`}),(0,P.jsx)(`button`,{onClick:Vt,children:`100%`}),(0,P.jsx)(`button`,{onClick:Ot,children:`适应`}),(0,P.jsx)(`button`,{onClick:()=>zt(1.2),"aria-label":`放大`,children:`+`}),(0,P.jsxs)(`output`,{children:[Math.round(pt.scale*100),`%`]})]})]}),(0,P.jsxs)(`div`,{className:`d2c-canvas-viewport`,ref:ht,tabIndex:0,"aria-label":`差异画布。滚轮缩放,拖动平移,F 适应,0 显示 100%。`,onWheel:e=>{e.preventDefault();let t=e.currentTarget.getBoundingClientRect();zt(Math.exp(-e.deltaY*.0015),{x:e.clientX-t.left,y:e.clientY-t.top},!1),xt.current!==void 0&&clearTimeout(xt.current),xt.current=setTimeout(()=>{mt({...yt.current}),xt.current=void 0},120)},onPointerDown:e=>{e.button===0&&(e.currentTarget.setPointerCapture(e.pointerId),St.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY,originX:yt.current.x,originY:yt.current.y},e.currentTarget.dataset.dragging=`true`)},onPointerMove:e=>{let t=St.current;t===void 0||t.pointerId!==e.pointerId||Dt({...yt.current,x:t.originX+e.clientX-t.x,y:t.originY+e.clientY-t.y},!1)},onPointerUp:e=>{St.current?.pointerId===e.pointerId&&(St.current=void 0,e.currentTarget.dataset.dragging=`false`,mt({...yt.current}))},onKeyDown:e=>{if(e.key===`+`||e.key===`=`)zt(1.2);else if(e.key===`-`)zt(1/1.2);else if(e.key===`0`)Vt();else if(e.key.toLowerCase()===`f`)Ot();else if(e.key.toLowerCase()===`b`&&Ct.current===void 0)Ct.current=g,v(`blink`);else if(/^[1-6]$/.test(e.key)){let t=gn[Number(e.key)-1];t!==void 0&&v(t)}},onKeyUp:e=>{e.key.toLowerCase()===`b`&&Ct.current!==void 0&&(v(Ct.current),Ct.current=void 0)},children:[(0,P.jsxs)(`div`,{className:`d2c-canvas-stage d2c-mode-${g}`,ref:vt,style:{width:Et.width,height:Et.height,"--d2c-scale":pt.scale,"--d2c-x":`${pt.x}px`,"--d2c-y":`${pt.y}px`,"--d2c-impl-opacity":y,"--d2c-wipe":`${x}%`},children:[(0,P.jsx)(`img`,{className:`d2c-layer d2c-layer-design`,src:u.designPng,alt:`设计稿截图`,draggable:!1}),(0,P.jsx)(`img`,{className:`d2c-layer d2c-layer-impl`,src:u.implementationPng,alt:`实现截图`,draggable:!1}),(0,P.jsx)(`img`,{className:`d2c-layer d2c-layer-heatmap`,src:u.heatmapPng,alt:`像素差异热力图`,draggable:!1}),hn.status===`invalid`&&(0,P.jsx)(`div`,{className:`d2c-invalid-capture-badge`,children:`错误现场 · 不参与评分`}),g===`wipe`&&(0,P.jsx)(`button`,{className:`d2c-wipe-handle`,"aria-label":`拖动拉帘分界,当前 ${Math.round(x)}%`,onPointerDown:e=>{e.stopPropagation(),e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&Bt(e.clientX,!1)},onPointerUp:e=>{Bt(e.clientX,!0),e.currentTarget.releasePointerCapture(e.pointerId)},children:(0,P.jsx)(`span`,{})}),(0,P.jsx)(`div`,{className:`d2c-annotations`,"aria-hidden":`true`,children:Lt.map(e=>{let t=e.designRect??e.implementationRect;return t===void 0?null:(0,P.jsx)(`div`,{className:`d2c-annotation`,"data-kind":e.kind,"data-severity":e.severity,"data-selected":e.fingerprint===C,style:Wu(t)},e.fingerprint)})}),It?.designRect!==void 0&&(0,P.jsx)(`div`,{className:`d2c-focus-box d2c-focus-design`,style:Wu(It.designRect),children:(0,P.jsx)(`span`,{children:`设计`})}),It?.implementationRect!==void 0&&(0,P.jsx)(`div`,{className:`d2c-focus-box d2c-focus-implementation`,style:Wu(It.implementationRect),children:(0,P.jsx)(`span`,{children:`实现`})}),It?.designRect!==void 0&&It.implementationRect!==void 0&&(0,P.jsx)(Gu,{design:It.designRect,implementation:It.implementationRect,canvas:Et,scale:pt.scale})]}),(0,P.jsx)(`aside`,{className:`d2c-difference-ruler`,"aria-label":`垂直差异分布`,children:Nt.slice(0,500).map(e=>{let t=e.designRect??e.implementationRect;return t===void 0?null:(0,P.jsx)(`button`,{style:{top:`${(t.y+t.height/2)/Et.height*100}%`},"data-severity":e.severity,"aria-label":`定位 ${e.label}`,title:e.label,onClick:()=>Rt(e)},e.fingerprint)})}),(0,P.jsx)(`div`,{className:`d2c-canvas-hint`,children:`滚轮缩放 · 拖动平移 · F 适应 · 0 原始尺寸 · 按住 B 闪烁`})]})]}),m&&(0,P.jsx)(`div`,{className:`d2c-loading`,"aria-busy":`true`,children:`正在加载报告…`})]}),Cn===`report`&&(0,P.jsx)(`aside`,{className:`d2c-inspector`,"aria-label":`差异检查器`,children:u!==void 0&&Et!==void 0&&mn!==void 0?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`section`,{className:`d2c-inspector-verdict`,"data-verdict":u.report.evaluation.verdict,children:[(0,P.jsx)(`span`,{className:`d2c-verdict-mark`,"aria-hidden":`true`,children:u.report.evaluation.verdict===`pass`?`✓`:u.report.evaluation.verdict===`conditional`?`!`:`×`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{children:u.report.evaluation.status===`invalid`?`EVALUATION INTERRUPTED`:`PAGE VERDICT`}),(0,P.jsx)(`h2`,{children:u.report.evaluation.verdict===`pass`?Nt.length===0?`本页已通过验收`:`已通过,仍可继续优化`:u.report.evaluation.verdict===`conditional`?`有差异需要确认`:u.report.evaluation.verdict===`invalid`?`评测需要重新运行`:`本页尚未通过验收`}),(0,P.jsx)(`span`,{children:u.report.evaluation.summary})]})]}),(0,P.jsxs)(`nav`,{className:`d2c-stage-tabs`,"aria-label":`E2E 交付阶段`,children:[(0,P.jsxs)(`button`,{type:`button`,"data-active":ke===`review`,"aria-pressed":ke===`review`,onClick:()=>A(`review`),children:[(0,P.jsx)(`span`,{children:`04`}),`D2C 视觉还原`]}),(0,P.jsxs)(`button`,{type:`button`,"data-active":ke===`integration`,"aria-pressed":ke===`integration`,disabled:xn===void 0||!xn.complete||u.report.evaluation.status===`invalid`,title:xn?.complete?`进入接口联调`:`全部差异通过后解锁`,onClick:Gt,children:[(0,P.jsx)(`span`,{children:`05`}),`接口联调`]}),(0,P.jsxs)(`button`,{type:`button`,"data-active":ke===`acceptance`,"aria-pressed":ke===`acceptance`,disabled:u.workflow.integrationFiles===void 0,title:u.workflow.integrationFiles===void 0?`生成联调代码后解锁`:`进入验收与交付`,onClick:Kt,children:[(0,P.jsx)(`span`,{children:`06—07`}),`验收与交付`]})]}),ke===`review`?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`section`,{className:`d2c-score-card`,"aria-label":`分项得分`,"data-status":u.report.evaluation.status,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{children:`QUALITY PROFILE`}),(0,P.jsx)(`h2`,{children:`五项质量`})]}),u.report.evaluation.status!==`invalid`&&(0,P.jsxs)(`span`,{children:[ju.filter(({key:e})=>(mn[e]??0)>=.9).length,` / 5 达标`]})]}),u.report.evaluation.status===`invalid`&&(0,P.jsx)(`p`,{className:`d2c-score-invalid`,children:`实现页面渲染失败,当前截图仅用于诊断,不生成正式分数。`}),u.report.evaluation.status!==`invalid`&&(0,P.jsx)(`div`,{className:`d2c-score-list`,children:ju.map(({key:e,label:t})=>mn[e]===void 0?null:(0,P.jsxs)(`div`,{"data-level":Vu(mn[e]),children:[(0,P.jsx)(`span`,{children:t}),(0,P.jsx)(`i`,{children:(0,P.jsx)(`b`,{style:{"--score":mn[e]}})}),(0,P.jsx)(`strong`,{children:Math.round(mn[e]*100)})]},e))})]}),u.report.evaluation.status!==`invalid`&&xn!==void 0&&(0,P.jsxs)(`section`,{className:`d2c-review-console`,"data-complete":xn.complete,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{children:`REVIEW QUEUE`}),(0,P.jsx)(`h2`,{children:xn.complete?`视觉审阅已完成`:`等待你的验收`})]}),(0,P.jsxs)(`strong`,{children:[xn.accepted,(0,P.jsxs)(`span`,{children:[` / `,xn.total]})]})]}),(0,P.jsxs)(`div`,{className:`d2c-review-meter`,"aria-label":`已通过 ${xn.accepted},待审 ${xn.pending},退回 ${xn.needsFix}`,children:[(0,P.jsx)(`i`,{style:{"--accepted":xn.total===0?1:xn.accepted/xn.total}}),(0,P.jsxs)(`span`,{children:[`待审 `,(0,P.jsx)(`b`,{children:xn.pending})]}),(0,P.jsxs)(`span`,{children:[`通过 `,(0,P.jsx)(`b`,{children:xn.accepted})]}),(0,P.jsxs)(`span`,{children:[`退回 `,(0,P.jsx)(`b`,{children:xn.needsFix})]})]}),(0,P.jsxs)(`div`,{className:`d2c-review-bulk`,children:[!xn.complete&&(0,P.jsx)(`button`,{type:`button`,disabled:Ae||s||Nt.length===0,onClick:()=>void Ut(Nt.map(e=>e.fingerprint),`accepted`),children:`全部跳过(不扣分)`}),!xn.complete&&(0,P.jsx)(`button`,{type:`button`,className:`d2c-review-reject`,disabled:Ae||s||Nt.length===0,onClick:()=>void Ut(Nt.map(e=>e.fingerprint),`needs-fix`,`集中修复所有退回差异,仍需严格限制在各自模块文件内。`),children:`全部退回并修复`}),xn.complete&&(0,P.jsxs)(`button`,{type:`button`,className:`d2c-review-next`,onClick:Gt,children:[`进入接口联调 `,(0,P.jsx)(`span`,{children:`→`})]})]})]}),(0,P.jsxs)(`div`,{className:`d2c-issue-heading`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h2`,{children:u.report.evaluation.status===`invalid`?`错误诊断`:`差异问题`}),u.report.evaluation.status!==`invalid`&&(0,P.jsxs)(`span`,{children:[Ft.length,` / `,Nt.length]})]}),u.report.evaluation.status!==`invalid`&&(0,P.jsx)(`div`,{className:`d2c-issue-filters`,children:[`all`,`blocking`,`content`,`geometry`].map(e=>(0,P.jsxs)(`button`,{type:`button`,"aria-pressed":ee===e,"data-active":ee===e,onClick:()=>{te(e),re(yu)},children:[(0,P.jsx)(`span`,{children:Mu[e]}),(0,P.jsx)(`small`,{children:Pt[e]})]},e))})]}),Ft.length===0?(0,P.jsxs)(`div`,{className:`d2c-issue-empty`,"data-kind":u.report.evaluation.status===`invalid`?`invalid`:Nt.length===0?`clear`:`filtered`,children:[(0,P.jsx)(`span`,{className:`d2c-empty-mark`,"aria-hidden":`true`,children:u.report.evaluation.status===`invalid`?`!`:Nt.length===0?`✓`:`⌁`}),(0,P.jsx)(`strong`,{children:u.report.evaluation.status===`invalid`?`等待有效评测`:Nt.length===0?`未发现可定位的差异`:`这个筛选下没有问题`}),(0,P.jsx)(`p`,{children:u.report.evaluation.status===`invalid`?`修复项目并重新运行 E2E 中的 D2C 视觉还原后,这里会生成可定位的差异清单。`:Nt.length===0?`布局、色彩、字体、内容与像素结果均已通过检查。`:`切换分类或显示全部问题,继续检查其他差异。`}),u.report.evaluation.status!==`invalid`&&(0,P.jsxs)(`div`,{className:`d2c-empty-stats`,children:[(0,P.jsxs)(`span`,{children:[`阻断 `,(0,P.jsx)(`b`,{children:Pt.blocking})]}),(0,P.jsxs)(`span`,{children:[`内容 `,(0,P.jsx)(`b`,{children:Pt.content})]}),(0,P.jsxs)(`span`,{children:[`几何 `,(0,P.jsx)(`b`,{children:Pt.geometry})]})]}),u.report.evaluation.status!==`invalid`&&(Nt.length===0?(0,P.jsx)(`button`,{type:`button`,onClick:()=>{v(`overlay`),Ot()},children:`查看叠加结果`}):(0,P.jsx)(`button`,{type:`button`,onClick:()=>{te(`all`),re(yu)},children:`显示全部问题`}))]}):(0,P.jsx)(`ol`,{className:`d2c-issue-list`,children:Ft.slice(0,ne).map(e=>{let t=Sn(e.fingerprint);return(0,P.jsxs)(`li`,{"data-severity":e.severity,"data-selected":C===e.fingerprint,"data-review":t?.decision??`pending`,children:[(0,P.jsxs)(`button`,{className:`d2c-issue-main`,onClick:()=>Rt(e),"aria-pressed":C===e.fingerprint,children:[(0,P.jsx)(`span`,{className:`d2c-impact`,children:t?.decision===`accepted`?`✓`:t?.decision===`needs-fix`?`↻`:e.impact.toFixed(1)}),(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:e.label}),zu(e).map(e=>(0,P.jsx)(`small`,{children:e},e))]})]}),C===e.fingerprint&&(0,P.jsxs)(`div`,{className:`d2c-evidence`,children:[(0,P.jsxs)(`div`,{className:`d2c-evidence-pair`,children:[e.designRect!==void 0&&(0,P.jsx)(Hu,{src:u.designPng,rect:e.designRect,canvas:Et,label:`设计`}),e.implementationRect!==void 0&&(0,P.jsx)(Hu,{src:u.implementationPng,rect:e.implementationRect,canvas:Et,label:`实现`})]}),(0,P.jsxs)(`div`,{className:`d2c-copy-actions`,children:[e.selector!==void 0&&(0,P.jsx)(`button`,{onClick:()=>Ht(e.selector),children:`复制选择器`}),(0,P.jsx)(`button`,{onClick:()=>Ht(`${e.label}\n${zu(e).join(`
148
148
  `)}\n位置:${JSON.stringify(bn)}`),children:`复制修复线索`})]}),(0,P.jsxs)(`label`,{className:`d2c-review-instruction`,children:[(0,P.jsx)(`span`,{children:`补充修改要求`}),(0,P.jsx)(`textarea`,{rows:2,value:Me,placeholder:`例如:保持卡片高度,只调整内部间距`,onChange:e=>Ne(e.target.value)})]}),(0,P.jsxs)(`div`,{className:`d2c-review-actions`,children:[(0,P.jsx)(`button`,{type:`button`,className:`d2c-accept`,disabled:Ae||s||t?.decision===`accepted`,onClick:()=>void Ut([e.fingerprint],`accepted`),children:`跳过(本项不扣分)`}),(0,P.jsx)(`button`,{type:`button`,className:`d2c-fix`,disabled:Ae||s,onClick:()=>void Ut([e.fingerprint],`needs-fix`,Me||void 0),children:`修复并自动视觉复验`})]})]})]},e.fingerprint)})}),Ft.length>ne&&(0,P.jsxs)(`button`,{className:`d2c-show-more`,onClick:()=>re(e=>e+yu),children:[`再显示 `,Math.min(yu,Ft.length-ne),` 条`]})]}):(0,P.jsxs)(`section`,{className:`d2c-integration-panel`,"data-stage":ke,"aria-label":ke===`acceptance`?`验收与交付`:`接口联调`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`p`,{children:ke===`acceptance`?`ACCEPTANCE & DELIVERY`:`API INTEGRATION`}),(0,P.jsx)(`h2`,{children:ke===`acceptance`?`验收与交付`:Pe===void 0?u.deliveryOrigin===`requirement`?`自动准备接口契约`:`导入接口描述`:Pe.document.title}),(0,P.jsx)(`span`,{children:ke===`acceptance`?`通过自动回放、人工操作与多模态质量门,完成最终交付验收。`:Pe===void 0?u.deliveryOrigin===`requirement`?`根据已确认 PRD 与实现模块生成 OpenAPI,无需手动上传。`:`上传 Swagger / OpenAPI JSON,自动匹配页面模块和接口出入参。`:`${Pe.document.version}${Pe.document.baseUrl?` · ${Pe.document.baseUrl}`:``}`})]}),Pe===void 0?(0,P.jsxs)(`div`,{className:`d2c-api-import`,"data-origin":u.deliveryOrigin,children:[(0,P.jsx)(`span`,{"aria-hidden":`true`,children:`{}`}),(0,P.jsx)(`strong`,{children:u.deliveryOrigin===`requirement`?`正在根据 PRD 与模块准备 OpenAPI 契约`:`Swagger JSON`}),(0,P.jsx)(`p`,{children:u.deliveryOrigin===`requirement`?`契约会自动生成并映射到当前实现;也可接入已有后端契约覆盖默认结果。`:`支持 Swagger 2.0、OpenAPI 3.0/3.1 和文档内引用。`}),(0,P.jsx)(`button`,{type:`button`,disabled:Ie,onClick:()=>void qt(),children:Ie?u.deliveryOrigin===`requirement`?`自动准备中…`:`正在解析…`:u.deliveryOrigin===`requirement`?`接入已有 Swagger / OpenAPI`:`选择 swagger.json`})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`d2c-api-summary`,children:[(0,P.jsxs)(`span`,{children:[`模块 `,(0,P.jsx)(`b`,{children:Pe.mappings.length})]}),(0,P.jsxs)(`span`,{children:[`自动匹配 `,(0,P.jsx)(`b`,{children:Pe.mappings.filter(e=>e.status===`auto`).length})]}),(0,P.jsxs)(`span`,{children:[`待确认 `,(0,P.jsx)(`b`,{children:Pe.mappings.filter(e=>e.status===`needs-confirmation`).length})]})]}),(0,P.jsx)(`ol`,{className:`d2c-mapping-list`,children:Pe.mappings.map(e=>(0,P.jsxs)(`li`,{"data-status":e.status,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`span`,{children:e.moduleLabel}),(0,P.jsx)(`small`,{children:e.status===`auto`?`自动匹配`:e.status===`confirmed`?`已确认`:`需要确认`})]}),(0,P.jsx)(`select`,{"aria-label":`${e.moduleLabel} 接口`,value:e.operationKey,disabled:Ie,onChange:t=>void Jt(e,t.target.value),children:Pe.document.operations.map(e=>(0,P.jsxs)(`option`,{value:e.id,children:[e.operationId,` · `,e.id]},e.id))}),e.status===`needs-confirmation`&&(0,P.jsx)(`button`,{type:`button`,className:`d2c-confirm-mapping`,disabled:Ie,onClick:()=>void Jt(e,e.operationKey),children:`确认此映射`}),(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`span`,{children:[`请求 `,e.parameters.length+e.requestFields.length,` 字段`]}),(0,P.jsxs)(`span`,{children:[`响应 `,e.responseFields.length,` 字段`]}),(0,P.jsxs)(`b`,{children:[Math.round(e.confidence*100),`%`]})]})]},e.moduleId))}),(0,P.jsxs)(`div`,{className:`d2c-integration-launch`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`span`,{children:`接口映射已就绪`}),(0,P.jsx)(`small`,{children:Pe.mappings.some(e=>e.status===`needs-confirmation`)?`仍有接口需要人工确认`:`${Pe.mappings.length} 个模块将接入真实请求链路`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`d2c-generate-integration`,disabled:Ie||Pe.mappings.some(e=>e.status===`needs-confirmation`),onClick:()=>void N(),children:[Ie?`正在准备联调…`:u.workflow.integrationFiles===void 0?`生成并开始联调`:`重新生成联调代码`,(0,P.jsx)(`span`,{children:`→`})]})]}),Pe.mappings.some(e=>e.status===`needs-confirmation`)&&(0,P.jsx)(`p`,{className:`d2c-api-hint`,children:`确认所有标记为“需要确认”的接口后即可生成。`}),(0,P.jsxs)(`section`,{className:`d2c-mock-control`,"data-running":Re.running,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:u.deliveryOrigin===`requirement`?Re.running?`真实后端服务运行中`:`真实后端服务未启动`:Re.running?`本地契约服务运行中`:`本地契约服务未启动`}),(0,P.jsx)(`small`,{children:Re.url??`生成联调代码后可启动`})]})]}),u.workflow.integrationFiles!==void 0&&(0,P.jsx)(`button`,{type:`button`,disabled:Ie||j.running,title:j.running?`请先停止交互页面`:void 0,onClick:()=>void Yt(),children:Re.running?`停止`:`启动`})]}),u.workflow.integrationFiles!==void 0&&(0,P.jsxs)(`section`,{className:`d2c-integration-ready`,"data-running":j.running,children:[(0,P.jsx)(`span`,{"aria-hidden":`true`,children:`✓`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`联调环境已生成`}),(0,P.jsx)(`small`,{children:j.running?`前端页面与后端服务已连接,可进入最终验收。`:`启动联调页面后即可进入自动与人工验收。`})]}),(0,P.jsx)(`button`,{type:`button`,onClick:Kt,children:`进入验收与交付 →`})]}),(0,P.jsxs)(`section`,{className:`d2c-preview-control`,"data-running":j.running,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{children:`INTERACTIVE ACCEPTANCE`}),(0,P.jsx)(`h3`,{children:j.running?`可交互页面运行中`:`等待启动可交互页面`})]}),(0,P.jsx)(`i`,{})]}),(0,P.jsx)(`code`,{children:j.url??`Vite preview not started`}),(0,P.jsxs)(`div`,{className:`d2c-preview-actions`,children:[(0,P.jsx)(`button`,{type:`button`,disabled:Ge||u.workflow.integrationFiles===void 0,onClick:()=>void(j.running?Zt():Xt()),children:j.running?`停止页面`:`启动页面`}),(0,P.jsx)(`button`,{type:`button`,disabled:Ge||!j.running,onClick:()=>void $t(),children:qe?`可视回放中…`:Ge?`处理中…`:`运行自动验收`}),j.running&&(0,P.jsx)(`button`,{type:`button`,onClick:()=>void window.flavorDesktop.openD2cPreview(u.report.task),children:`浏览器打开`})]}),qe&&(0,P.jsxs)(`div`,{className:`d2c-playback-notice`,role:`status`,"aria-live":`polite`,children:[(0,P.jsx)(`i`,{"aria-hidden":`true`}),(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:`正在可视化回放`}),(0,P.jsx)(`small`,{children:$e.configured?`多模态模型正在观察并规划用户旅程;随后青色指针会完成点击、输入、导航和检查。`:`请观察左侧页面:青色指针会依次完成设计契约中的定位、点击、输入和检查。配置多模态模型后可启用自主审阅。`})]})]}),Ue!==void 0&&(0,P.jsxs)(`div`,{className:`d2c-review-plan`,"data-mode":Ue.mode,children:[(0,P.jsx)(`strong`,{children:Ue.mode===`autonomous`?`自主审阅已执行`:Ue.mode===`contract-fallback`?`自主规划失败,已执行设计契约`:`设计契约已执行`}),(0,P.jsxs)(`span`,{children:[Ue.plannedScenarios,` 条用户旅程`,Ue.model?` · ${Ue.model}`:``]}),Ue.summary&&(0,P.jsx)(`p`,{children:Ue.summary}),Ue.warning&&(0,P.jsx)(`p`,{role:`alert`,children:Ue.warning})]}),Ve!==void 0&&(0,P.jsxs)(`div`,{className:`d2c-test-results`,"data-passed":Ve.passed,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:Ve.passed?`自动验收通过`:`${Ve.failures} 条自动验收失败`}),(0,P.jsxs)(`span`,{children:[Ve.total,` scenarios · `,Ve.apiRequestCount,` API requests`]})]}),!Ve.passed&&(0,P.jsx)(`button`,{type:`button`,disabled:Ye!==void 0||s,onClick:()=>void tn(Ve.scenarios.filter(e=>!e.passed)),children:Ye===`all`?`正在发起修复…`:Ze.trim()?`按要求修复全部`:`修复全部失败`})]}),!Ve.passed&&(0,P.jsxs)(`label`,{className:`d2c-interaction-repair-guide`,children:[(0,P.jsxs)(`span`,{children:[`补充修复要求 `,(0,P.jsx)(`small`,{children:`可选`})]}),(0,P.jsx)(`textarea`,{rows:3,value:Ze,placeholder:`例如:不要修改接口契约;优先检查登录响应的 data 包装层与会话持久化`,onChange:e=>Qe(e.target.value)}),(0,P.jsx)(`small`,{children:`留空则按失败证据自动修复;填写后会连同请求日志一起交给修复任务。`})]}),(0,P.jsx)(`ol`,{children:Ve.scenarios.map(e=>(0,P.jsxs)(`li`,{"data-passed":e.passed,children:[(0,P.jsxs)(`span`,{children:[e.passed?`✓`:`×`,` `,e.id]}),(0,P.jsxs)(`small`,{children:[e.apiRequestCount,` API · `,e.durationMs,`ms`]}),e.failure!==void 0&&(0,P.jsx)(`p`,{children:e.failure}),!e.passed&&(0,P.jsx)(`button`,{type:`button`,className:`d2c-fix-scenario`,disabled:Ye!==void 0||s,"aria-label":`修复失败场景 ${e.id}`,onClick:()=>void tn([e]),children:Ye===e.id?`正在发起修复…`:Ze.trim()?`按要求修复此项`:`修复此项`})]},e.id))})]}),(0,P.jsxs)(`div`,{className:`d2c-manual-acceptance`,children:[(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:`人工验收`}),(0,P.jsx)(`small`,{children:`请直接在左侧页面完成点击、输入和提交流程`})]}),(0,P.jsx)(`button`,{type:`button`,disabled:Ge||!j.running,"data-accepted":u.workflow.interaction?.manualDecision===`accepted`,onClick:()=>void en(u.workflow.interaction?.manualDecision!==`accepted`),children:u.workflow.interaction?.manualDecision===`accepted`?`已通过(撤回)`:`确认人工验收通过`})]}),(0,P.jsxs)(`section`,{className:`d2c-quality-gate`,"data-verdict":u.workflow.quality?.verdict??`pending`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{children:`LLM-AS-A-JUDGE`}),(0,P.jsx)(`h3`,{children:`最终质量门`})]}),u.workflow.quality!==void 0&&(0,P.jsx)(`strong`,{children:u.workflow.quality.overallScore.toFixed(1)})]}),!$e.configured||at?(0,P.jsxs)(`form`,{className:`d2c-judge-config`,onSubmit:e=>void dn(e),children:[(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`协议`}),(0,P.jsxs)(`select`,{value:st.protocol,onChange:e=>ct(t=>({...t,protocol:e.target.value})),children:[(0,P.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI 兼容`}),(0,P.jsx)(`option`,{value:`anthropic`,children:`Anthropic`})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`Base URL`}),(0,P.jsx)(`input`,{required:!0,type:`url`,placeholder:`https://api.example.com/v1`,value:st.baseURL,onChange:e=>ct(t=>({...t,baseURL:e.target.value}))})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`模型`}),(0,P.jsx)(`input`,{required:!0,placeholder:`支持视觉的模型名称`,value:st.model,onChange:e=>ct(t=>({...t,model:e.target.value}))})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`API Key`}),(0,P.jsx)(`input`,{required:!0,type:`password`,autoComplete:`off`,value:st.apiKey,onChange:e=>ct(t=>({...t,apiKey:e.target.value}))})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`通过阈值`}),(0,P.jsx)(`input`,{required:!0,type:`number`,min:0,max:100,value:st.passThreshold,onChange:e=>ct(t=>({...t,passThreshold:Number(e.target.value)}))})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{type:`submit`,disabled:tt,children:tt?`保存中…`:`保存多模态模型`}),$e.configured&&(0,P.jsx)(`button`,{type:`button`,onClick:()=>ot(!1),children:`取消`})]})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`d2c-judge-model`,children:[(0,P.jsx)(`span`,{children:$e.model}),(0,P.jsxs)(`small`,{children:[$e.baseURL,` · 阈值 `,$e.passThreshold]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>ot(!0),children:`修改配置`})]}),u.workflow.quality===void 0?(0,P.jsx)(`p`,{children:`可随时评测当前版本;自动与人工验收未通过时,评分只用于诊断,不会放行最终交付。`}):(0,P.jsxs)(`div`,{className:`d2c-quality-result`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`span`,{children:[`视觉质量 `,(0,P.jsx)(`b`,{children:u.workflow.quality.visualScore})]}),(0,P.jsxs)(`span`,{children:[`交互质量 `,(0,P.jsx)(`b`,{children:u.workflow.quality.interactionScore})]}),(0,P.jsxs)(`span`,{children:[`综合得分 `,(0,P.jsx)(`b`,{children:u.workflow.quality.overallScore})]})]}),(0,P.jsx)(`strong`,{children:u.workflow.quality.verdict===`pass`?`质量门通过`:`质量门未通过`}),(0,P.jsx)(`p`,{children:u.workflow.quality.summary}),u.workflow.quality.issues.length>0&&(0,P.jsx)(`ol`,{children:u.workflow.quality.issues.map(e=>(0,P.jsxs)(`li`,{"data-severity":e.severity,"data-decision":e.decision,children:[(0,P.jsx)(`span`,{children:e.description}),(0,P.jsx)(`small`,{children:e.recommendation}),(0,P.jsxs)(`em`,{children:[e.category,` · 影响 `,e.scoreImpact,` 分 · `,e.decision===`skipped`?`已跳过,不扣分`:e.decision===`fixing`?`修复中,完成后自动复验`:`待处理`]}),(0,P.jsxs)(`div`,{className:`d2c-quality-issue-actions`,children:[(0,P.jsx)(`button`,{type:`button`,disabled:rt!==void 0||e.decision===`skipped`,onClick:()=>void pn(e,`skipped`),children:`跳过(不扣分)`}),(0,P.jsx)(`button`,{type:`button`,disabled:rt!==void 0||e.decision===`fixing`,onClick:()=>void pn(e,`fixing`),children:`修复并自动复验`})]})]},e.id))})]}),(0,P.jsx)(`button`,{type:`button`,className:`d2c-run-judge`,disabled:tt||!j.running||u.workflow.interaction?.automated===void 0,title:u.workflow.interaction?.automated===void 0?`至少运行一次自动验收后可评分;验收失败也可以评分诊断`:void 0,onClick:()=>void fn(),children:tt?`AI 评审中…`:u.workflow.quality===void 0?`运行 AI 质量评审`:`重新运行 AI 质量评审`})]})]}),u.workflow.stage===`completed`&&(0,P.jsx)(`p`,{className:`d2c-acceptance-complete`,children:`✓ 自动、人工与多模态质量验收均已完成`})]})]})]})]}):(0,P.jsxs)(`div`,{className:`d2c-inspector-empty`,children:[(0,P.jsx)(`strong`,{children:`问题检查器`}),(0,P.jsx)(`span`,{children:`选择报告后,可按影响度逐项定位和取证。`})]})})]})]})}var Qu={repository:!1,branch:``,head:``,files:[]};function $u(e,t=!1){let n=e.replace(/\r\n/g,`
149
149
  `).split(`
150
- `);if(n.at(-1)===``&&n.pop(),t&&!n.some(e=>e.startsWith(`@@`)))return n.map((e,t)=>({kind:`addition`,marker:`+`,text:e,newNumber:t+1}));let r=0,i=0,a=!1;return n.map(e=>{let t=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/.exec(e);if(t!==null)return r=Number(t[1]),i=Number(t[2]),a=!0,{kind:`hunk`,marker:`@@`,text:t[3]?.trim()??``};if(!a||e.startsWith(`diff --git`)||e.startsWith(`index `)||e.startsWith(`--- `)||e.startsWith(`+++ `))return{kind:`meta`,marker:``,text:e};if(e.startsWith(`+`)&&!e.startsWith(`+++`))return{kind:`addition`,marker:`+`,text:e.slice(1),newNumber:i++};if(e.startsWith(`-`)&&!e.startsWith(`---`))return{kind:`deletion`,marker:`−`,text:e.slice(1),oldNumber:r++};if(e.startsWith(`\\ No newline`))return{kind:`meta`,marker:``,text:e};let n={kind:`context`,marker:``,text:e.startsWith(` `)?e.slice(1):e,oldNumber:r,newNumber:i};return r+=1,i+=1,n})}function ed({onClose:e,onReview:t,onError:n}){let[r,i]=(0,_.useState)(Qu),[a,o]=(0,_.useState)(),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(`working`),[d,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),v=(0,_.useMemo)(()=>$u(s,a?.untracked),[s,a?.untracked]),y=v.filter(e=>e.kind===`addition`).length,b=v.filter(e=>e.kind===`deletion`).length,x=r.files.filter(e=>e.staged).length,S=async()=>{try{i(await window.flavorDesktop.gitStatus())}catch(e){n(nd(e))}finally{f(!1)}};(0,_.useEffect)(()=>{S()},[]);let C=async(e,t)=>{m(!0),c(``),u(t);try{c(await window.flavorDesktop.gitDiff(e.path,t===`staged`))}catch(e){let t=nd(e);c(t),n(t)}finally{m(!1)}},w=async e=>{o(e),await C(e,e.unstaged||e.untracked?`working`:`staged`)},ee=async(e,t)=>{if(!(e===`discard`&&!window.confirm(`确定还原 ${t.path}?此操作无法撤销。`)))try{let n=e===`stage`?await window.flavorDesktop.gitStage(t.path):e===`unstage`?await window.flavorDesktop.gitUnstage(t.path):await window.flavorDesktop.gitDiscard(t.path);i(n);let r=n.files.find(e=>e.path===t.path);r===void 0?(o(void 0),c(``)):(o(r),await C(r,r.unstaged||r.untracked?`working`:`staged`))}catch(e){n(nd(e))}},te=async()=>{if(h.trim())try{let e=await window.flavorDesktop.gitCommit(h.trim());i(e.status),g(``),o(void 0),c(``),n(`已提交 ${e.result}`)}catch(e){n(nd(e))}};return(0,P.jsxs)(`section`,{className:`manager-view git-view`,children:[(0,P.jsxs)(`header`,{className:`manager-header git-header`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{className:`git-back`,onClick:e,"aria-label":`返回`,children:`←`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h2`,{children:`Git 变更`}),(0,P.jsx)(`span`,{children:`审阅并整理本次工作区修改`})]})]}),r.repository&&(0,P.jsxs)(`span`,{className:`git-branch`,children:[(0,P.jsx)(`i`,{}),r.branch,(0,P.jsx)(`b`,{children:r.head})]})]}),d?(0,P.jsx)(`p`,{className:`manager-empty`,children:`正在读取工作区…`}):r.repository?(0,P.jsxs)(`div`,{className:`git-layout`,children:[(0,P.jsxs)(`aside`,{className:`git-files`,children:[(0,P.jsxs)(`div`,{className:`git-toolbar`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`变更`}),(0,P.jsx)(`span`,{children:r.files.length})]}),(0,P.jsx)(`button`,{onClick:()=>void S(),title:`重新读取变更`,children:`↻`})]}),r.files.length===0?(0,P.jsxs)(`div`,{className:`git-clean`,children:[(0,P.jsx)(`i`,{children:`✓`}),(0,P.jsx)(`strong`,{children:`工作区干净`}),(0,P.jsx)(`span`,{children:`没有需要审阅的修改`})]}):r.files.map(e=>{let t=td(e.path),n=e.untracked?`U`:e.index===`A`?`A`:e.index===`D`||e.worktree===`D`?`D`:`M`;return(0,P.jsxs)(`div`,{className:`git-file-row`,"data-active":a?.path===e.path,children:[(0,P.jsxs)(`button`,{className:`git-file-name`,onClick:()=>void w(e),title:e.path,children:[(0,P.jsx)(`code`,{"data-state":n,children:n}),(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`b`,{children:t.name}),t.directory&&(0,P.jsx)(`small`,{children:t.directory})]})]}),(0,P.jsxs)(`div`,{className:`git-file-actions`,children:[e.staged?(0,P.jsx)(`button`,{onClick:()=>void ee(`unstage`,e),children:`取消暂存`}):(0,P.jsx)(`button`,{className:`stage-action`,onClick:()=>void ee(`stage`,e),children:`暂存`}),(e.unstaged||e.untracked)&&(0,P.jsx)(`button`,{className:`danger-text`,onClick:()=>void ee(`discard`,e),children:`还原`})]})]},e.path)})]}),(0,P.jsx)(`article`,{className:`git-diff`,children:a===void 0?(0,P.jsxs)(`div`,{className:`git-diff-empty`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`span`,{children:`−`}),(0,P.jsx)(`span`,{children:`+`})]}),(0,P.jsx)(`strong`,{children:`选择文件查看差异`}),(0,P.jsx)(`p`,{children:`逐行审阅修改,然后决定暂存或还原。`})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`header`,{className:`git-diff-header`,children:[(0,P.jsxs)(`div`,{className:`git-diff-title`,children:[(0,P.jsx)(`span`,{children:td(a.path).directory||`项目根目录`}),(0,P.jsx)(`strong`,{children:td(a.path).name})]}),(0,P.jsxs)(`div`,{className:`git-diff-controls`,children:[a.staged&&a.unstaged&&(0,P.jsxs)(`div`,{className:`git-layer-switch`,children:[(0,P.jsx)(`button`,{"data-active":l===`working`,onClick:()=>void C(a,`working`),children:`工作区`}),(0,P.jsx)(`button`,{"data-active":l===`staged`,onClick:()=>void C(a,`staged`),children:`已暂存`})]}),!p&&(0,P.jsxs)(`div`,{className:`git-diff-stats`,children:[(0,P.jsxs)(`span`,{className:`add`,children:[`+`,y]}),(0,P.jsxs)(`span`,{className:`del`,children:[`−`,b]})]})]})]}),(0,P.jsx)(`div`,{className:`git-code`,"aria-label":`${a.path} 差异`,children:p?(0,P.jsxs)(`div`,{className:`git-diff-loading`,children:[(0,P.jsx)(`i`,{}),`正在生成差异…`]}):v.map((e,t)=>(0,P.jsxs)(`div`,{className:`git-code-line`,"data-kind":e.kind,children:[(0,P.jsx)(`span`,{className:`old-line`,children:e.oldNumber??``}),(0,P.jsx)(`span`,{className:`new-line`,children:e.newNumber??``}),(0,P.jsx)(`span`,{className:`change-marker`,children:e.marker}),(0,P.jsx)(`code`,{children:e.text||` `})]},`${t}-${e.oldNumber??``}-${e.newNumber??``}`))})]})})]}):(0,P.jsx)(`p`,{className:`manager-empty`,children:`当前项目不是 Git 仓库`}),r.repository&&(0,P.jsxs)(`footer`,{className:`git-footer`,children:[(0,P.jsx)(`button`,{className:`review-action`,onClick:t,children:`交给 /review`}),(0,P.jsxs)(`div`,{className:`commit-field`,children:[(0,P.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),placeholder:x>0?`描述这次提交…`:`暂存文件后即可提交`}),(0,P.jsxs)(`span`,{children:[x,` 个文件已暂存`]})]}),(0,P.jsx)(`button`,{className:`commit-action`,disabled:!h.trim()||x===0,onClick:()=>void te(),children:`提交`})]})]})}function td(e){let t=e.replace(/\\/g,`/`),n=t.lastIndexOf(`/`);return n<0?{name:t,directory:``}:{name:t.slice(n+1),directory:t.slice(0,n)}}function nd(e){return e instanceof Error?e.message:String(e)}function rd(e){let t=[],n,r=()=>{if(n===void 0)return;let e=n.lines.length,r=n.hunks.map((t,r)=>({...t,end:n.hunks[r+1]?.start??e}));t.push({...n,hunks:r})};for(let t of e.split(/\r?\n/)){let e=/^diff --(?:git|flavor) a\/(.+?) b\/(.+)$/.exec(t);if(e!==null){r(),n={path:e[2],lines:[t],hunks:[],additions:0,deletions:0};continue}if(n===void 0)continue;let i=n.lines.length;n.lines.push(t),t.startsWith(`@@`)?n.hunks.push({id:`${n.path}:${n.hunks.length+1}`,header:t,start:i,end:i+1}):t.startsWith(`+`)&&!t.startsWith(`+++`)?n.additions+=1:t.startsWith(`-`)&&!t.startsWith(`---`)&&(n.deletions+=1)}return r(),t}function id(e){return Math.min(2.4,Math.max(.55,e))}function ad(e,t,n){let r=id(n),i=r/e.scale;return{x:t.x-(t.x-e.x)*i,y:t.y-(t.y-e.y)*i,scale:r}}function od(e,t,n){return{x:Math.round(t.x+e.x*n.width*t.scale/100),y:Math.round(t.y+e.y*n.height*t.scale/100)}}function sd(e,t){let n=new Map,r=[];n.set(e.id,{...e,role:`origin`,x:50,y:50});let i=(t,i,a)=>{t.slice(0,8).forEach((t,o,s)=>{n.set(t.id,{...t,role:i,x:a,y:(o+1)*100/(s.length+1)}),r.push(i===`caller`?{from:t.id,to:e.id,kind:i}:{from:e.id,to:t.id,kind:i})})};i(t.callers,`caller`,14),i(t.callees,`callee`,86);let a=t.impact.filter(e=>!n.has(e.id)).slice(0,12),o=Math.ceil(a.length/2);return a.forEach((t,i)=>{let s=i<o,c=s?i:i-o,l=s?o:a.length-o,u=Math.floor(c/3),d=c%3,f=Math.min(3,l-u*3),p=(d+1)*100/(f+1),m=s?13+u*11:87-u*11;n.set(t.id,{...t,role:`impact`,x:p,y:m,hop:t.hop}),r.push({from:e.id,to:t.id,kind:`impact`,hop:t.hop})}),{nodes:[...n.values()],edges:r}}function cd(e){let t=new Map(e.map(e=>[e.id,e]));return e.map(e=>{let n=0,r=e.parentId,i=new Set([e.id]);for(;r!==null&&n<12&&!i.has(r);){i.add(r);let e=t.get(r);if(e===void 0)break;n+=1,r=e.parentId}return{node:e,depth:n}})}function ld(e){return e.replaceAll(`\\`,`/`).split(`/`).filter(Boolean).at(-1)??e}function ud(e,t){let n=t.filter(e=>e.state!==`closed`);return e!==void 0&&n.some(t=>t.id===e)?e:n.find(e=>e.state===`running`)?.id??n[0]?.id}var dd=`modulepreload`,fd=function(e,t){return new URL(e,t).href},pd={},md=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=fd(t,n),t=s(t),t in pd)return;pd[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:dd,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},hd=[{id:`cockpit`,label:`执行`},{id:`timeline`,label:`时间机`},{id:`terminal`,label:`终端`},{id:`review`,label:`审查`},{id:`preview`,label:`预览`},{id:`context`,label:`上下文`},{id:`ast`,label:`代码图`},{id:`pals`,label:`Pals`},{id:`worktrees`,label:`工作树`}],gd=_.lazy(()=>md(()=>import(`./interactive-terminal-CKHHiGNG.js`),[],import.meta.url));function _d({snapshot:e,onClose:t,onError:n,onCompose:r}){let[i,a]=(0,_.useState)(`cockpit`),[o,s]=(0,_.useState)(()=>Ad(e.jobs.map(e=>e.label).join(`
151
- `))),c=(0,_.useRef)(new Map),l=e=>s(t=>[...new Set([...t,...Ad(e)])].slice(-20));return(0,_.useEffect)(()=>{let t=!1;return Promise.all(e.jobs.map(async e=>{let n=await window.flavorDesktop.readJob(e.id,c.current.get(e.id)??0).catch(()=>void 0);n===void 0||t||(c.current.set(e.id,n.cursor),l(n.output))})),()=>{t=!0}},[e.jobs]),(0,P.jsxs)(`section`,{className:`agent-workbench manager-view`,children:[(0,P.jsxs)(`header`,{className:`manager-header workbench-header`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{onClick:t,children:`‹`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`FLAVOR DESKTOP 1.3.4`}),(0,P.jsx)(`h2`,{children:`Agent 工作台`})]})]}),(0,P.jsx)(`span`,{children:e.activeSession?.environment===`worktree`?`隔离工作树`:`本地检出`})]}),(0,P.jsx)(`nav`,{className:`workbench-tabs`,"aria-label":`工作台功能`,children:hd.map(e=>(0,P.jsx)(`button`,{"data-active":i===e.id,onClick:()=>a(e.id),children:e.label},e.id))}),(0,P.jsxs)(`div`,{className:`workbench-stage`,children:[i===`cockpit`&&(0,P.jsx)(vd,{snapshot:e,onCompose:r}),i===`timeline`&&(0,P.jsx)($,{onError:n}),i===`terminal`&&(0,P.jsx)(yd,{onError:n,onDiscover:l}),i===`review`&&(0,P.jsx)(bd,{onError:n,onCompose:r}),i===`preview`&&(0,P.jsx)(Sd,{onError:n,suggestions:o}),i===`context`&&(0,P.jsx)(Cd,{snapshot:e,onError:n}),i===`ast`&&(0,P.jsx)(wd,{onError:n,onCompose:r}),i===`pals`&&(0,P.jsx)(Dd,{onError:n}),i===`worktrees`&&(0,P.jsx)(Od,{snapshot:e,onError:n})]})]})}function vd({snapshot:e,onCompose:t}){let[n,r]=(0,_.useState)(),[i,a]=(0,_.useState)(``);(0,_.useEffect)(()=>{window.flavorDesktop.inspectWorkbench().then(r).catch(()=>void 0)},[e.activeSession?.sessionId]);let o=n?.goals[0];(0,_.useEffect)(()=>{o!==void 0&&a(o.objective)},[o?.id]);let s=e.tasks?.plan?.tasks??[],c=Object.entries(e.tasks?.subagents.states??{});return(0,P.jsxs)(`div`,{className:`cockpit-grid`,children:[(0,P.jsxs)(`section`,{className:`cockpit-trace`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`EXECUTION TRACE`}),(0,P.jsx)(`h3`,{children:o?.objective??`当前会话尚未启动持久目标`})]}),(0,P.jsx)(`ol`,{children:s.length===0?(0,P.jsxs)(`li`,{"data-state":`pending`,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`等待执行计划`}),(0,P.jsx)(`small`,{children:`TaskPlan 出现后会自动同步`})]})]}):s.map(e=>(0,P.jsxs)(`li`,{"data-state":e.status,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:e.subject}),(0,P.jsxs)(`small`,{children:[e.status,e.result?` · ${e.result}`:``]})]})]},e.id))})]}),(0,P.jsxs)(`aside`,{className:`cockpit-evidence`,children:[(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`目标状态`}),(0,P.jsx)(`b`,{"data-phase":o?.phase,children:o?.phase??`idle`}),(0,P.jsx)(`p`,{children:o?`${o.status} · worker ${o.workerRounds} · verify ${o.verifyRounds}`:`使用 /goal 启动带验证的长期任务`}),o&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`textarea`,{className:`cockpit-goal-editor`,value:i,onChange:e=>a(e.target.value),"aria-label":`继续目标`}),(0,P.jsxs)(`div`,{className:`cockpit-goal-actions`,children:[e.activeSession?.busy&&(0,P.jsx)(`button`,{onClick:()=>void window.flavorDesktop.interrupt(),children:`安全暂停`}),(0,P.jsx)(`button`,{disabled:!i.trim(),onClick:()=>t(`/goal ${i.trim()}`),children:`以编辑目标继续`})]})]})]}),(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`协作 Agent`}),c.length===0?(0,P.jsx)(`p`,{children:`没有活跃子 Agent`}):c.map(([e,t])=>(0,P.jsxs)(`div`,{className:`cockpit-row`,children:[(0,P.jsx)(`code`,{children:e}),(0,P.jsx)(`span`,{"data-state":t,children:t})]},e))]}),(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`后台作业`}),e.jobs.length===0?(0,P.jsx)(`p`,{children:`没有后台作业`}):e.jobs.map(e=>(0,P.jsxs)(`div`,{className:`cockpit-row`,children:[(0,P.jsx)(`code`,{children:e.label}),(0,P.jsx)(`span`,{"data-state":e.state,children:e.state})]},e.id))]}),o&&o.evidenceRounds.length>0&&(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`验证证据`}),o.evidenceRounds.slice(-3).reverse().map(e=>(0,P.jsxs)(`div`,{className:`cockpit-evidence-round`,children:[(0,P.jsxs)(`b`,{children:[`ROUND `,e.round]}),(0,P.jsx)(`p`,{children:e.hostVerification?.summary??`workspace ${e.workspaceDiffHash.slice(0,10)}`}),(0,P.jsx)(`span`,{"data-passed":e.hostVerification?.passed,children:e.hostVerification===void 0?`workspace evidence`:e.hostVerification.passed?`passed`:`failed`})]},e.round))]}),o&&o.lastGaps.length>0&&(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`验证缺口`}),o.lastGaps.map((e,t)=>(0,P.jsx)(`p`,{className:`cockpit-gap`,children:e.description},t))]})]})]})}function $({onError:e}){let[t,n]=(0,_.useState)({leafId:null,nodes:[]}),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(!1),s=()=>window.flavorDesktop.historySnapshot().then(n).catch(t=>e(kd(t)));(0,_.useEffect)(()=>{s()},[]);let c=async t=>{o(!0);try{await t(),await s()}catch(t){e(kd(t))}finally{o(!1)}},l=cd(t.nodes);return(0,P.jsxs)(`div`,{className:`timeline-layout`,children:[(0,P.jsxs)(`section`,{className:`timeline-canvas`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`SESSION TREE`}),(0,P.jsxs)(`h3`,{children:[t.nodes.length,` 个可恢复节点`]})]}),(0,P.jsx)(`ol`,{children:l.map(({node:e,depth:n})=>(0,P.jsxs)(`li`,{className:`timeline-node`,style:{paddingLeft:n*26},"data-depth":n,"data-current":e.id===t.leafId,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:e.prompt||e.id}),(0,P.jsxs)(`small`,{children:[new Date(e.createdAt).toLocaleString(),` · `,e.checkpointId]})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{disabled:a,onClick:()=>void c(()=>window.flavorDesktop.rewindHistory(e.id)),children:`回到这里`}),(0,P.jsx)(`button`,{disabled:a,onClick:()=>{window.confirm(`从这个节点建立新分支?当前上下文将切换。`)&&c(()=>window.flavorDesktop.forkHistory(e.id))},children:`Fork`})]})]},e.id))})]}),(0,P.jsxs)(`aside`,{className:`timeline-actions`,children:[(0,P.jsx)(`h3`,{children:`建立安全点`}),(0,P.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`例如:重构前`}),(0,P.jsx)(`button`,{disabled:a,onClick:()=>void c(()=>window.flavorDesktop.createCheckpoint(r||void 0)),children:`创建 checkpoint`}),(0,P.jsx)(`button`,{disabled:a,onClick:()=>void c(()=>window.flavorDesktop.unrevertHistory()),children:`撤销上次回退`})]})]})}function yd({onError:e,onDiscover:t}){let[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(),o=n.find(e=>e.id===i),s=(e,t)=>{let n=e.filter(e=>e.state!==`closed`);r(n),a(e=>ud(t??e,n))},c=async e=>s(await window.flavorDesktop.listTerminals(),e);(0,_.useEffect)(()=>{c().catch(t=>e(kd(t)))},[]);let l=async()=>{try{let e=await window.flavorDesktop.openTerminal();await c(e.id)}catch(t){e(kd(t))}},u=async()=>{if(i!==void 0)try{await window.flavorDesktop.closeTerminal(i),await c()}catch(t){e(kd(t))}};return(0,P.jsxs)(`div`,{className:`terminal-layout`,children:[(0,P.jsxs)(`aside`,{children:[(0,P.jsx)(`button`,{className:`primary`,onClick:()=>void l(),children:`+ 新终端`}),n.map(e=>(0,P.jsxs)(`button`,{"data-active":e.id===i,onClick:()=>a(e.id),title:e.shell,children:[(0,P.jsx)(`strong`,{children:ld(e.shell)}),(0,P.jsxs)(`small`,{children:[e.state,` · `,e.id]})]},e.id))]}),(0,P.jsxs)(`main`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`span`,{title:o?.cwd,children:o?.cwd??`尚未打开终端`}),o&&(0,P.jsx)(`button`,{onClick:()=>void u(),children:`关闭终端`})]}),o===void 0?(0,P.jsxs)(`div`,{className:`terminal-empty`,children:[(0,P.jsx)(`b`,{children:`没有打开终端`}),(0,P.jsx)(`span`,{children:`新建终端后,直接在终端区域输入和操作。`})]}):(0,P.jsx)(_.Suspense,{fallback:(0,P.jsxs)(`div`,{className:`terminal-empty`,children:[(0,P.jsx)(`b`,{children:`正在连接终端`}),(0,P.jsx)(`span`,{children:`正在加载交互渲染器…`})]}),children:(0,P.jsx)(gd,{terminal:o,onError:e,onDiscover:t},o.id)})]})]})}function bd({onError:e,onCompose:t}){let[n,r]=(0,_.useState)(`working`),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)(),m=(0,_.useMemo)(()=>rd(o),[o]),h=m.find(e=>e.path===u)??m[0],g=async()=>{l(!0);try{let e=await window.flavorDesktop.gitReview(n,i||void 0);s(e);let t=rd(e);d(t[0]?.path),p(t[0]?.hunks[0]?.id)}catch(t){e(kd(t))}finally{l(!1)}};return(0,_.useEffect)(()=>{if(n===`commit`||n===`base`){s(``),d(void 0),p(void 0);return}g()},[n]),(0,P.jsxs)(`div`,{className:`review-layout`,children:[(0,P.jsxs)(`aside`,{className:`review-scope`,children:[(0,P.jsx)(`small`,{children:`DIFF SCOPE`}),[`working`,`staged`,`last-turn`,`commit`,`base`].map(e=>(0,P.jsx)(`button`,{"data-active":n===e,onClick:()=>r(e),children:e},e)),(n===`commit`||n===`base`)&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:n===`base`?`main / origin/main`:`commit SHA`}),(0,P.jsx)(`button`,{onClick:()=>void g(),children:`载入范围`})]})]}),(0,P.jsxs)(`section`,{className:`review-files`,"aria-label":`变更文件`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`strong`,{children:`文件`}),(0,P.jsx)(`span`,{children:m.length})]}),m.map(e=>(0,P.jsxs)(`button`,{"data-active":e.path===h?.path,onClick:()=>{d(e.path),p(e.hunks[0]?.id)},children:[(0,P.jsx)(`strong`,{children:e.path.split(`/`).at(-1)}),(0,P.jsx)(`small`,{children:e.path}),(0,P.jsxs)(`span`,{children:[(0,P.jsxs)(`b`,{children:[`+`,e.additions]}),(0,P.jsxs)(`em`,{children:[`-`,e.deletions]})]})]},e.path))]}),(0,P.jsxs)(`main`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:h?.path??n}),(0,P.jsxs)(`span`,{children:[h?.hunks.length??0,` hunks`]})]}),(0,P.jsx)(`button`,{onClick:()=>t(`/review 请审查 ${n}${i?` ${i}`:``}${h?` 中的 ${h.path}`:``},按 P0/P1/P2 分级输出发现,必须给出文件行号和触发场景。`),children:`交给 Agent 审查`})]}),h&&h.hunks.length>0&&(0,P.jsx)(`nav`,{className:`review-hunks`,"aria-label":`Hunk 导航`,children:h.hunks.map((e,t)=>(0,P.jsxs)(`button`,{"data-active":f===e.id,onClick:()=>p(e.id),children:[`H`,t+1,(0,P.jsx)(`span`,{children:e.header})]},e.id))}),(0,P.jsx)(xd,{file:h,activeHunk:f,loading:c,empty:o}),(0,P.jsxs)(`footer`,{className:`review-priority-legend`,children:[(0,P.jsx)(`span`,{"data-priority":`0`,children:`P0 阻断`}),(0,P.jsx)(`span`,{"data-priority":`1`,children:`P1 高风险`}),(0,P.jsx)(`span`,{"data-priority":`2`,children:`P2 一般`}),(0,P.jsx)(`small`,{children:`审查结果将在对话中返回,并携带文件行号。`})]})]})]})}function xd({file:e,activeHunk:t,loading:n,empty:r}){return n?(0,P.jsx)(`div`,{className:`review-empty`,children:`正在生成 diff…`}):e===void 0?(0,P.jsx)(`div`,{className:`review-empty`,children:r||`此范围没有差异`}):(0,P.jsx)(`div`,{className:`review-code`,role:`region`,"aria-label":`${e.path} 差异`,children:(0,P.jsx)(`pre`,{children:e.lines.map((n,r)=>{let i=e.hunks.find(e=>r>=e.start&&r<e.end);return(0,P.jsx)(`code`,{"data-kind":n.startsWith(`+++`)||n.startsWith(`---`)?`meta`:n.startsWith(`+`)?`addition`:n.startsWith(`-`)?`deletion`:n.startsWith(`@@`)?`hunk`:`context`,"data-active":i?.id===t,children:n||` `},r)})})})}function Sd({onError:e,suggestions:t}){let[n,r]=(0,_.useState)(`http://localhost:3000`),[i,a]=(0,_.useState)(),[o,s]=(0,_.useState)(0),c=async()=>{try{a(await window.flavorDesktop.validatePreviewUrl(n))}catch(t){e(kd(t))}};return(0,P.jsxs)(`div`,{className:`preview-layout`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()}}),(0,P.jsx)(`button`,{onClick:()=>void c(),children:`打开`}),(0,P.jsx)(`button`,{disabled:!i,onClick:()=>s(e=>e+1),children:`刷新`}),(0,P.jsx)(`button`,{disabled:!i,onClick:()=>{i&&window.flavorDesktop.openPreviewUrl(i)},children:`外部打开`}),(0,P.jsx)(`button`,{disabled:!i,onClick:()=>{i&&navigator.clipboard.writeText(i)},children:`复制`})]}),t.length>0&&(0,P.jsxs)(`div`,{className:`preview-suggestions`,children:[`检测到:`,t.map(t=>(0,P.jsx)(`button`,{onClick:()=>{r(t),window.flavorDesktop.validatePreviewUrl(t).then(a).catch(t=>e(kd(t)))},children:t},t))]}),i?(0,P.jsx)(`iframe`,{src:i,title:`本地应用预览`,sandbox:`allow-forms allow-modals allow-popups allow-scripts allow-same-origin`},o):(0,P.jsxs)(`div`,{className:`preview-empty`,children:[(0,P.jsx)(`strong`,{children:`安全的本地预览`}),(0,P.jsx)(`p`,{children:`仅允许 localhost、127.0.0.1 和 ::1 的 HTTP(S) 地址。`})]})]})}function Cd({snapshot:e,onError:t}){let[n,r]=(0,_.useState)();return(0,_.useEffect)(()=>{window.flavorDesktop.inspectWorkbench().then(r).catch(e=>t(kd(e)))},[]),(0,P.jsxs)(`div`,{className:`context-grid`,children:[(0,P.jsxs)(`section`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`RUNTIME`}),(0,P.jsx)(`h3`,{children:`上下文 Epoch`})]}),(0,P.jsxs)(`dl`,{children:[(0,P.jsx)(`dt`,{children:`Permission`}),(0,P.jsx)(`dd`,{children:e.activeSession?.permissionMode??`—`}),(0,P.jsx)(`dt`,{children:`Model`}),(0,P.jsx)(`dd`,{children:e.activeSession?.mainModel??`—`}),(0,P.jsx)(`dt`,{children:`Checkout`}),(0,P.jsx)(`dd`,{children:e.activeSession?.workingDirectory??e.workspace??`—`})]}),n?.context?.epoch!==void 0&&(0,P.jsx)(`pre`,{className:`context-record`,children:JSON.stringify(n.context.epoch,null,2)}),n?.context?.visibility.map((e,t)=>(0,P.jsx)(`pre`,{className:`context-record`,children:JSON.stringify(e,null,2)},t)),n?.context?.usage.map((e,t)=>(0,P.jsx)(`pre`,{className:`context-record`,children:JSON.stringify(e,null,2)},`usage-${t}`)),e.diagnostics.map((e,t)=>(0,P.jsx)(`p`,{className:`context-record`,children:e},`diag-${t}`))]}),(0,P.jsxs)(`section`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`INSTRUCTIONS`}),(0,P.jsx)(`h3`,{children:`生效的项目指令`})]}),n?.instructions.map(e=>(0,P.jsxs)(`details`,{children:[(0,P.jsx)(`summary`,{children:e.name}),(0,P.jsx)(`pre`,{children:e.content})]},e.path))]}),(0,P.jsxs)(`section`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`SAFETY`}),(0,P.jsx)(`h3`,{children:`权限规则与审计`})]}),n?.permissionFiles.map(e=>(0,P.jsxs)(`details`,{children:[(0,P.jsxs)(`summary`,{children:[e.tier,` · `,e.path]}),(0,P.jsx)(`pre`,{children:e.content})]},e.path)),n?.audit.slice(0,30).map((e,t)=>(0,P.jsx)(`pre`,{className:`context-record`,children:JSON.stringify(e,null,2)},t))]})]})}function wd({onError:e,onCompose:t}){let[n,r]=(0,_.useState)(),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)(2),[m,h]=(0,_.useState)(!1);(0,_.useEffect)(()=>{window.flavorDesktop.astStatus().then(r).catch(t=>e(kd(t)))},[]);let g=async()=>{try{s(await window.flavorDesktop.astSearch(i))}catch(t){e(kd(t))}},v=async(t,n=f)=>{l(t),h(!0);try{d(await window.flavorDesktop.astRelations(t.id,n))}catch(t){e(kd(t))}finally{h(!1)}},y=c===void 0||u===void 0?void 0:sd(c,u);return(0,P.jsxs)(`div`,{className:`ast-layout`,children:[(0,P.jsxs)(`aside`,{className:`ast-symbols`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`SYMBOL INDEX`}),(0,P.jsx)(`strong`,{children:`代码索引`})]}),(0,P.jsx)(`span`,{"data-ready":n?.available,children:n?.available?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`b`,{children:n.nodes}),` symbols`,(0,P.jsx)(`br`,{}),(0,P.jsx)(`b`,{children:n.edges}),` edges`]}):`尚未建立索引`})]}),(0,P.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g()},children:[(0,P.jsx)(`span`,{"aria-hidden":`true`,children:`⌕`}),(0,P.jsx)(`input`,{"aria-label":`搜索代码符号`,value:i,onChange:e=>a(e.target.value),placeholder:`函数、类型或模块`}),(0,P.jsx)(`button`,{children:`搜索`})]}),(0,P.jsx)(`div`,{className:`ast-symbol-list`,children:o.length===0?(0,P.jsx)(`p`,{children:n?.available===!1?`项目尚未建立代码索引`:`输入名称,定位代码中的关键符号`}):o.map(e=>(0,P.jsxs)(`button`,{"data-active":e.id===c?.id,onClick:()=>void v(e),children:[(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:e.name}),(0,P.jsx)(`em`,{children:e.kind})]}),(0,P.jsxs)(`small`,{children:[e.filePath,`:`,e.startLine]})]},e.id))})]}),(0,P.jsxs)(`main`,{className:`ast-graph-stage`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`RELATION MAP`}),(0,P.jsx)(`h3`,{children:c?.qualifiedName??`代码关系浏览器`}),(0,P.jsx)(`code`,{children:c?`${c.filePath}:${c.startLine}-${c.endLine}`:`搜索并选择一个符号作为图中心`})]}),(0,P.jsxs)(`div`,{className:`ast-depth`,"aria-label":`影响深度`,children:[(0,P.jsx)(`span`,{children:`影响深度`}),[1,2,3,4].map(e=>(0,P.jsx)(`button`,{"aria-label":`${e} 层影响深度`,"data-active":f===e,onClick:()=>{p(e),c&&v(c,e)},children:e},e))]})]}),m?(0,P.jsx)(`div`,{className:`ast-graph-empty`,children:`正在展开关系图…`}):y?(0,P.jsx)(Td,{graph:y,selected:c,onSelect:e=>void v(e)}):(0,P.jsxs)(`div`,{className:`ast-graph-empty`,children:[(0,P.jsx)(`strong`,{children:`从一个符号开始`}),(0,P.jsx)(`p`,{children:`搜索函数、类或模块,在同一张图上查看调用者、被调用项和多跳影响范围。`})]})]}),(0,P.jsxs)(`aside`,{className:`ast-inspector`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`SYMBOL INSPECTOR`}),(0,P.jsx)(`h3`,{children:c?.name??`未选择符号`})]}),c&&(0,P.jsx)(`span`,{children:c.kind})]}),c?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`dl`,{children:[(0,P.jsx)(`dt`,{children:`语言`}),(0,P.jsx)(`dd`,{children:c.language}),(0,P.jsx)(`dt`,{children:`位置`}),(0,P.jsxs)(`dd`,{children:[c.filePath,`:`,c.startLine]}),c.signature&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`dt`,{children:`签名`}),(0,P.jsx)(`dd`,{children:c.signature})]})]}),(0,P.jsxs)(`button`,{className:`ast-compose`,onClick:()=>t(`请查看 @${c.filePath}#L${c.startLine}-L${c.endLine} 中的 ${c.qualifiedName}`),children:[(0,P.jsx)(`span`,{children:`加入输入框`}),(0,P.jsx)(`b`,{"aria-hidden":`true`,children:`↗`})]}),(0,P.jsx)(Ed,{title:`Callers`,nodes:u?.callers??[],onSelect:e=>void v(e)}),(0,P.jsx)(Ed,{title:`Callees`,nodes:u?.callees??[],onSelect:e=>void v(e)}),(0,P.jsx)(Ed,{title:`Impact`,nodes:u?.impact??[],onSelect:e=>void v(e)})]}):(0,P.jsx)(`p`,{className:`ast-inspector-empty`,children:`选择一个符号后,这里会显示源码位置和完整关系。`})]})]})}function Td({graph:e,selected:t,onSelect:n}){let r={x:0,y:0,scale:1},[i,a]=(0,_.useState)(r),[o,s]=(0,_.useState)({width:0,height:0}),[c,l]=(0,_.useState)(!1),u=(0,_.useRef)(null),d=(0,_.useRef)(void 0),f=new Map(e.nodes.map(e=>[e.id,e]));(0,_.useEffect)(()=>{a(r)},[t.id]),(0,_.useEffect)(()=>{let e=u.current;if(e===null)return;let t=()=>{let t=e.getBoundingClientRect();s({width:t.width,height:t.height})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let p=(e,t)=>{let n=u.current?.getBoundingClientRect(),r=t??{x:(n?.width??0)/2,y:(n?.height??0)/2};a(t=>ad(t,r,e))},m=e=>{d.current?.pointerId===e.pointerId&&(d.current=void 0,l(!1),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))};return(0,P.jsxs)(`div`,{ref:u,className:`ast-graph`,"data-dragging":c,role:`region`,"aria-label":`${t.name} 代码关系图,可拖动和滚轮缩放`,onWheel:e=>{e.preventDefault();let t=e.currentTarget.getBoundingClientRect();p(i.scale*Math.exp(-e.deltaY*.0014),{x:e.clientX-t.left,y:e.clientY-t.top})},onPointerDown:e=>{e.button!==0||e.target.closest(`button`)||(e.currentTarget.setPointerCapture(e.pointerId),d.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY},l(!0))},onPointerMove:e=>{let t=d.current;if(t?.pointerId!==e.pointerId)return;let n=e.clientX-t.x,r=e.clientY-t.y;d.current={...t,x:e.clientX,y:e.clientY},a(e=>({...e,x:e.x+n,y:e.y+r}))},onPointerUp:m,onPointerCancel:m,children:[(0,P.jsx)(`div`,{className:`ast-graph-viewport`,style:{transform:`translate(${i.x}px, ${i.y}px) scale(${i.scale})`},children:(0,P.jsx)(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:e.edges.map((e,t)=>{let n=f.get(e.from),r=f.get(e.to);if(!n||!r)return null;let i=(n.x+r.x)/2;return(0,P.jsx)(`path`,{"data-kind":e.kind,d:`M ${n.x} ${n.y} C ${i} ${n.y}, ${i} ${r.y}, ${r.x} ${r.y}`},`${e.from}-${e.to}-${t}`)})})}),e.nodes.map(e=>{let t=od(e,i,o);return(0,P.jsxs)(`button`,{className:`ast-graph-node`,"data-role":e.role,style:{left:t.x,top:t.y,visibility:o.width>0?`visible`:`hidden`},onClick:()=>n(e),title:`${e.qualifiedName}\n${e.filePath}:${e.startLine}`,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:e.name}),(0,P.jsx)(`small`,{children:e.role===`impact`?`hop ${e.hop}`:e.kind})]})]},e.id)}),(0,P.jsxs)(`div`,{className:`ast-graph-hint`,children:[(0,P.jsx)(`span`,{"aria-hidden":`true`,children:`↔`}),` 拖动平移 `,(0,P.jsx)(`i`,{}),` 滚轮缩放`]}),(0,P.jsxs)(`div`,{className:`ast-graph-controls`,"aria-label":`画布缩放`,children:[(0,P.jsx)(`button`,{"aria-label":`放大`,onClick:()=>p(i.scale*1.2),children:`+`}),(0,P.jsxs)(`span`,{children:[Math.round(i.scale*100),`%`]}),(0,P.jsx)(`button`,{"aria-label":`缩小`,onClick:()=>p(i.scale/1.2),children:`−`}),(0,P.jsx)(`button`,{className:`ast-graph-reset`,"aria-label":`复位画布`,onClick:()=>a(r),children:`复位`})]}),(0,P.jsxs)(`div`,{className:`ast-graph-legend`,children:[(0,P.jsx)(`span`,{"data-kind":`caller`,children:`调用者`}),(0,P.jsx)(`span`,{"data-kind":`origin`,children:`中心符号`}),(0,P.jsx)(`span`,{"data-kind":`callee`,children:`被调用`}),(0,P.jsx)(`span`,{"data-kind":`impact`,children:`影响范围`})]})]})}function Ed({title:e,nodes:t,onSelect:n}){return(0,P.jsxs)(`section`,{className:`ast-relation`,children:[(0,P.jsxs)(`h4`,{children:[e,(0,P.jsx)(`span`,{children:t.length})]}),t.length===0?(0,P.jsx)(`p`,{children:`没有关系记录`}):t.slice(0,20).map(e=>(0,P.jsxs)(`button`,{onClick:()=>n(e),children:[(0,P.jsx)(`strong`,{children:e.name}),(0,P.jsxs)(`code`,{children:[e.filePath,`:`,e.startLine]})]},e.id))]})}function Dd({onError:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(),[d,f]=(0,_.useState)(),[p,m]=(0,_.useState)(),[h,g]=(0,_.useState)(),v=()=>window.flavorDesktop.listPals().then(e=>{f(void 0),n(e),i(t=>e.some(e=>e.alias===t)?t:e[0]?.alias)}).catch(e=>{n([]),f(kd(e))});(0,_.useEffect)(()=>{v();let e=window.setInterval(v,4e3);return()=>window.clearInterval(e)},[]);let y=async(t,n,r)=>{m(t),g(void 0);try{r(await n())}catch(t){e(kd(t))}finally{m(void 0)}},b=t.find(e=>e.alias===r),x=b?.alias,S=typeof l==`object`&&l?l:void 0,C=typeof S?.coWorkId==`string`?S.coWorkId:void 0,w=typeof S?.status==`string`?S.status:`created`,ee=e=>{x===void 0||!a.trim()||y(e,()=>window.flavorDesktop.sendPalMessage(x,a.trim(),e),()=>{o(``),g(e===`chat`?`消息已发送给 ${x}`:`任务已委托给 ${x}`)})};return(0,P.jsxs)(`div`,{className:`pals-layout`,children:[(0,P.jsxs)(`aside`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`LOCAL BROKER`}),(0,P.jsx)(`h3`,{children:`在线 Pals`})]}),(0,P.jsx)(`span`,{children:t.length})]}),d===void 0?t.length===0&&(0,P.jsxs)(`div`,{className:`pals-list-empty`,children:[(0,P.jsx)(`b`,{children:`等待其他实例`}),(0,P.jsx)(`p`,{children:`同一台设备上的 Flavor 实例上线后会出现在这里。`})]}):(0,P.jsxs)(`div`,{className:`pals-unavailable`,children:[(0,P.jsx)(`strong`,{children:`正在恢复本地协作`}),(0,P.jsx)(`p`,{children:`broker 暂时不可用,工作台会自动重试。`}),(0,P.jsx)(`button`,{onClick:()=>void v(),children:`立即重试`})]}),(0,P.jsx)(`div`,{className:`pals-list`,children:t.map(e=>(0,P.jsxs)(`button`,{"data-active":r===e.alias,onClick:()=>{i(e.alias),g(void 0)},children:[(0,P.jsx)(`span`,{className:`pal-presence`,children:(0,P.jsx)(`i`,{})}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:e.alias}),(0,P.jsx)(`small`,{title:e.projectPath??e.id,children:e.projectPath??e.id})]}),(0,P.jsx)(`em`,{children:`在线`})]},e.id))})]}),(0,P.jsxs)(`main`,{children:[(0,P.jsxs)(`header`,{className:`pals-channel-header`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`CO-WORK CHANNEL`}),(0,P.jsx)(`h3`,{children:x??`没有选中 Pal`}),(0,P.jsx)(`p`,{title:b?.projectPath,children:b?.projectPath??`从左侧选择一个在线实例后即可发送消息、委托任务或共同执行目标。`})]}),(0,P.jsxs)(`span`,{"data-online":b!==void 0,children:[(0,P.jsx)(`i`,{}),b===void 0?`等待选择`:`连接正常`]})]}),(0,P.jsxs)(`div`,{className:`pals-compose-grid`,children:[(0,P.jsxs)(`section`,{className:`pal-compose-card`,"data-kind":`message`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`span`,{children:`MESSAGE`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h4`,{children:`发消息或委托任务`}),(0,P.jsx)(`p`,{children:`同一段内容,可以即时沟通,也可以交给对方独立执行。`})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`内容`}),(0,P.jsx)(`textarea`,{"aria-label":`消息或任务内容`,value:a,onChange:e=>o(e.target.value),placeholder:`写下背景、期望结果和必要约束…`})]}),(0,P.jsxs)(`footer`,{children:[(0,P.jsx)(`small`,{children:a.length===0?`建议说明交付结果`:`${a.length} 字符`}),(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`button`,{disabled:p!==void 0||x===void 0||!a.trim(),onClick:()=>ee(`chat`),children:[(0,P.jsx)(`b`,{children:p===`chat`?`发送中…`:`发送 Chat`}),(0,P.jsx)(`span`,{children:`直接沟通`})]}),(0,P.jsxs)(`button`,{disabled:p!==void 0||x===void 0||!a.trim(),onClick:()=>ee(`task`),children:[(0,P.jsx)(`b`,{children:p===`task`?`委托中…`:`委托 Task`}),(0,P.jsx)(`span`,{children:`异步执行`})]})]})]})]}),(0,P.jsxs)(`section`,{className:`pal-compose-card`,"data-kind":`cowork`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`span`,{children:`CO-WORK`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h4`,{children:`共同完成一个目标`}),(0,P.jsx)(`p`,{children:`双方先共同规划,再持续同步执行状态与结果。`})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`共同目标`}),(0,P.jsx)(`textarea`,{"aria-label":`共同目标`,value:s,onChange:e=>c(e.target.value),placeholder:`描述目标、完成标准和双方需要协作的部分…`})]}),(0,P.jsxs)(`footer`,{children:[(0,P.jsx)(`small`,{children:s.length===0?`适合跨实例并行工作`:`${s.length} 字符`}),(0,P.jsxs)(`button`,{className:`primary`,disabled:p!==void 0||x===void 0||!s.trim(),onClick:()=>{x===void 0||!s.trim()||y(`cowork`,()=>window.flavorDesktop.startCoWork(x,s.trim()),e=>{u(e),c(``),g(`已与 ${x} 建立共同目标`)})},children:[(0,P.jsx)(`b`,{children:p===`cowork`?`建立中…`:`开始 Co-work`}),(0,P.jsx)(`span`,{children:`共同规划并执行`})]})]})]})]}),h!==void 0&&(0,P.jsxs)(`div`,{className:`pals-notice`,children:[(0,P.jsx)(`i`,{}),` `,h]}),l!==void 0&&(0,P.jsxs)(`section`,{className:`cowork-state`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`LIVE CO-WORK`}),(0,P.jsx)(`strong`,{children:`最新协作状态`})]}),(0,P.jsx)(`span`,{"data-status":w,children:w}),(0,P.jsxs)(`nav`,{children:[(0,P.jsx)(`button`,{disabled:p!==void 0,onClick:()=>void y(`refresh`,()=>window.flavorDesktop.coWorkStatus(C),u),children:`刷新状态`}),C&&(0,P.jsx)(`button`,{className:`danger`,disabled:p!==void 0,onClick:()=>{window.confirm(`取消这个 Co-work?`)&&y(`cancel`,()=>window.flavorDesktop.cancelCoWork(C,`cancelled from desktop workbench`),e=>{u(e),g(`协作已取消`)})},children:`取消协作`})]})]}),(0,P.jsxs)(`details`,{children:[(0,P.jsx)(`summary`,{children:`查看原始协作数据`}),(0,P.jsx)(`pre`,{children:JSON.stringify(l,null,2)})]})]})]})]})}function Od({snapshot:e,onError:t}){let[n,r]=(0,_.useState)([]),i=()=>window.flavorDesktop.listWorktrees().then(r).catch(e=>t(kd(e)));return(0,_.useEffect)(()=>{i()},[]),(0,P.jsxs)(`div`,{className:`worktree-pane`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`TASK ISOLATION`}),(0,P.jsx)(`h3`,{children:`工作树`}),(0,P.jsx)(`p`,{children:`新任务可在独立分支中运行,不改动当前检出。`})]}),(0,P.jsxs)(`span`,{children:[n.length,` active`]})]}),n.length===0?(0,P.jsx)(`div`,{className:`manager-empty`,children:`还没有隔离工作树。新建任务时选择“隔离工作树”。`}):(0,P.jsx)(`div`,{className:`worktree-list`,children:n.map(n=>(0,P.jsxs)(`article`,{"data-current":e.activeSession?.worktreeId===n.id,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`i`,{}),(0,P.jsx)(`strong`,{children:n.branch}),(0,P.jsx)(`small`,{children:n.path})]}),(0,P.jsx)(`span`,{"data-dirty":n.dirty,children:n.merged?`merged`:n.dirty?`dirty`:`clean`}),(0,P.jsxs)(`div`,{className:`worktree-actions`,children:[(0,P.jsx)(`button`,{disabled:n.dirty||n.merged,onClick:()=>{window.confirm(`将 ${n.branch} 合并回当前项目分支?`)&&window.flavorDesktop.mergeWorktree(n.id).then(i).catch(e=>t(kd(e)))},children:`合并交付`}),(0,P.jsx)(`button`,{onClick:()=>{window.confirm(`移除工作树 ${n.branch}?${n.dirty?`存在未提交变更,将强制移除。`:`分支会保留。`}`)&&window.flavorDesktop.removeWorktree(n.id,n.dirty).then(i).catch(e=>t(kd(e)))},children:`移除并保留分支`})]})]},n.id))})]})}function kd(e){return e instanceof Error?e.message:String(e)}function Ad(e){return e.match(/https?:\/\/(?:localhost|127\.0\.0\.1|\[?::1\]?)(?::\d{1,5})?(?:\/[^\s"'<>]*)?/gi)??[]}function jd(e,t,n=Date.now()){return{task:e,framework:t,startedAt:n,updatedAt:n,phase:`analyzing`,comparisonCycle:0,activity:[{id:`import`,label:`HTML 设计稿已导入`,state:`completed`,startedAt:n,completedAt:n}]}}function Md(e,t,n=Date.now()){if(t.type===`model-start`){let r=e.phase===`analyzing`?`分析设计并规划实现`:e.phase===`building`?`检查实现并规划下一步`:`分析评测结果`;return Id(e,{id:`model:${t.id}`,label:r,state:`running`,startedAt:n},n)}if(t.type===`model-end`)return Ld(e,`model:${t.id}`,`completed`,n);if(t.type===`tool-start`){let r=Pd(t.name,e.phase),i=Fd(t.name,t.label,t.hint);return Id({...e,phase:r},{id:`tool:${t.id}`,label:i,state:`running`,startedAt:n,...t.hint===void 0||t.hint===t.label?{}:{detail:Rd(t.hint,72)}},n)}if(t.type===`tool-end`){let r=t.result.ok?`completed`:`failed`,i=e.activity.find(e=>e.id===`tool:${t.id}`);return i===void 0?Id(e,{id:`tool:${t.id}`,label:Fd(t.name,t.label,t.hint),state:r,startedAt:n,completedAt:n},n):Ld(e,i.id,r,n)}return t.type===`model-retry`?Id(e,{id:`retry:${t.attempt}`,label:`模型请求重试 ${t.attempt}/${t.maxAttempts}`,detail:`${Math.ceil(t.delayMs/1e3)} 秒后继续`,state:`info`,startedAt:n,completedAt:n},n):t.type===`warning`?Id(e,{id:`warning:${n}`,label:Rd(t.message,96),state:`info`,startedAt:n,completedAt:n},n):t.type===`error`?Id(e,{id:`error:${n}`,label:Rd(t.error.message,96),state:`failed`,startedAt:n,completedAt:n},n):e}function Nd(e,t,n=Date.now()){if(t.task!==e.task)return e;let r=`engine:${t.cycle}:${t.stage}`,i=e.activity.find(e=>e.id===r);return Id({...e,phase:`evaluating`,comparisonCycle:t.cycle},{id:r,label:t.message,state:t.state,startedAt:i?.startedAt??n,...t.state===`running`?{}:{completedAt:n},...t.cached===!0?{detail:`已复用缓存`}:{}},n)}function Pd(e,t){return e===`D2cCompare`?`evaluating`:[`Write`,`Edit`,`ApplyPatch`,`Mkdir`,`Copy`,`Move`,`Shell`,`Bash`,`Command`,`Exec`].includes(e)?`building`:t}function Fd(e,t,n){let r=Rd(t??n??``,60),i=r===``?``:` ${r}`;return[`Read`,`Glob`,`Grep`,`Search`,`List`].includes(e)?`读取${i||`设计与项目文件`}`:e===`Write`?`创建${i||`前端文件`}`:e===`Edit`||e===`ApplyPatch`?`调整${i||`前端实现`}`:e===`Mkdir`?`创建${i||`项目目录`}`:[`Shell`,`Bash`,`Command`,`Exec`].includes(e)?`运行${i||`项目命令`}`:e===`D2cCompare`?`启动视觉评测`:`${e}${i}`}function Id(e,t,n){let r=e.activity.findIndex(e=>e.id===t.id),i=[...e.activity];return r<0?i.push(t):i[r]=t,{...e,updatedAt:n,activity:i.slice(-12)}}function Ld(e,t,n,r){let i=e.activity.find(e=>e.id===t);return i===void 0?e:Id(e,{...i,state:n,completedAt:r},r)}function Rd(e,t){let n=e.replaceAll(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,t-1)}…`}var zd={sessions:[],diagnostics:[],models:[],jobs:[]},Bd=[`default`,`acceptEdits`,`plan`,`bypassPermissions`,`auto`,`bubble`],Vd=zl.map(e=>({name:e,description:Bl[e]})),Hd=5,Ud=5*1024*1024,Wd=20*1024*1024,Gd=new Set([`image/png`,`image/jpeg`,`image/webp`]);function Kd(e,t){return[e.trim(),...t.map((e,t)=>`[Image #${t+1}]`)].filter(Boolean).join(`
152
- `)}function qd({attachments:e,onRemove:t}){return(0,P.jsx)(`div`,{className:`image-attachment-strip`,"aria-label":`待发送图片`,children:e.map((e,n)=>(0,P.jsxs)(`figure`,{className:`image-attachment-chip`,children:[(0,P.jsx)(`img`,{src:e.previewUrl,alt:e.name}),(0,P.jsxs)(`figcaption`,{children:[(0,P.jsxs)(`strong`,{children:[`[Image #`,n+1,`]`]}),(0,P.jsx)(`span`,{children:e.name})]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),"aria-label":`移除 ${e.name}`,title:`移除图片`,children:`×`})]},e.id))})}function Jd(){let[e,t]=(0,_.useState)(zd),[n,r]=(0,_.useState)(S),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(!0),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(),[y,b]=(0,_.useState)(),[x,w]=(0,_.useState)(!1),[ee,te]=(0,_.useState)(0),[ne,re]=(0,_.useState)(),[ie,ae]=(0,_.useState)([]),[oe,se]=(0,_.useState)([]),[ce,le]=(0,_.useState)(0),[ue,T]=(0,_.useState)(),[E,de]=(0,_.useState)(),[fe,pe]=(0,_.useState)(0),[D,O]=(0,_.useState)(`conversation`),[k,me]=(0,_.useState)(!1),[he,ge]=(0,_.useState)(``),[_e,ve]=(0,_.useState)(`active`),[ye,be]=(0,_.useState)(),[we,Ee]=(0,_.useState)(),[De,Oe]=(0,_.useState)(``),[ke,A]=(0,_.useState)([]),[Ae,je]=(0,_.useState)(-1),[Me,Ne]=(0,_.useState)(0),[Pe,Fe]=(0,_.useState)(),[Ie,Le]=(0,_.useState)(()=>new Map),Re=(0,_.useRef)(null),ze=(0,_.useRef)(null),j=(0,_.useRef)(void 0),Be=(0,_.useRef)(void 0),Ve=(0,_.useRef)(n),He=(0,_.useRef)(new Map),Ue=(0,_.useRef)(new Map),We=(0,_.useRef)(new Map),Ge=(0,_.useRef)(new Set),Ke=(0,_.useRef)(!1),qe=(0,_.useCallback)(e=>{a(e),re(void 0),T(void 0)},[]);(0,_.useEffect)(()=>{Ve.current=n},[n]);let Je=(0,_.useCallback)(()=>{let e=Be.current;e!==void 0&&(He.current.set(e,{sessionId:j.current,transcript:Ve.current}),j.current!==void 0&&Ue.current.set(`${e}\u0000${j.current}`,Ve.current))},[]),Ye=(0,_.useCallback)(e=>{e!==void 0&&Le(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),Xe=(0,_.useCallback)(e=>{let n=e.workspace;Be.current=n,j.current=e.activeSession?.sessionId,t(e);let i=n===void 0?void 0:He.current.get(n);r(i!==void 0&&i.sessionId===e.activeSession?.sessionId?i.transcript:S()),Ye(n),O(`conversation`),p(!1)},[Ye]);(0,_.useEffect)(()=>()=>{for(let e of Ge.current)URL.revokeObjectURL(e);Ge.current.clear()},[]);let Ze=(0,_.useCallback)(e=>{s(t=>{let n=t.find(t=>t.id===e);return n!==void 0&&(URL.revokeObjectURL(n.previewUrl),Ge.current.delete(n.previewUrl)),t.filter(t=>t.id!==e)})},[]),Qe=(0,_.useCallback)(()=>{s(e=>{for(let t of e)URL.revokeObjectURL(t.previewUrl),Ge.current.delete(t.previewUrl);return[]})},[]),$e=(0,_.useCallback)(async e=>{if(e.length===0)return;let t=Hd-o.length;if(t<=0||e.length>t){d(`每条消息最多添加 ${Hd} 张图片。`);return}if(o.reduce((e,t)=>e+Math.floor(t.dataBase64.length*3/4),0)+e.reduce((e,t)=>e+t.size,0)>Wd){d(`单条消息的图片总大小不能超过 20 MiB。`);return}try{let t=await Promise.all(e.map(uf));for(let e of t)Ge.current.add(e.previewUrl);s(e=>[...e,...t].slice(0,Hd)),d(void 0)}catch(e){d(Ef(e))}},[o]);(0,_.useEffect)(()=>{let e=Re.current;if(!e)return;let t=e=>{e.deltaY<0?Ke.current=!0:requestAnimationFrame(()=>{let e=Re.current;e&&e.scrollHeight-e.scrollTop-e.clientHeight<8&&(Ke.current=!1)})};return e.addEventListener(`wheel`,t,{passive:!0}),()=>e.removeEventListener(`wheel`,t)},[]),(0,_.useEffect)(()=>{let e=window.flavorDesktop.onEvent(e=>{if(e.type===`snapshot`&&e.workspace!==void 0&&e.snapshot.workspace===e.workspace){let t=Be.current;if(t!==void 0&&t!==e.workspace){He.current.set(t,{sessionId:j.current,transcript:Ve.current});let n=He.current.get(e.workspace);r(n!==void 0&&n.sessionId===e.snapshot.activeSession?.sessionId?n.transcript:S()),O(`conversation`),Ye(e.workspace)}Be.current=e.workspace}else if(e.workspace!==void 0&&(e.workspace!==Be.current||e.type===`session-output`&&e.sessionId!==j.current||e.type===`session-started`&&e.payload.sessionId!==j.current)){let t=He.current.get(e.workspace)??{sessionId:void 0,transcript:S()};if(e.type===`session-started`){let t=C(S(),{type:`restore`,state:e.payload.restoredTranscript});Ue.current.set(`${e.workspace}\u0000${e.payload.sessionId}`,t),He.current.set(e.workspace,{sessionId:e.payload.sessionId,transcript:t})}else if(e.type===`session-output`){let n=`${e.workspace}\u0000${e.sessionId}`,r=Te(Ue.current.get(n)??S(),e.sessionId,e);Ue.current.set(n,r),t.sessionId===e.sessionId&&He.current.set(e.workspace,{...t,transcript:r})}return}if(e.type===`d2c-report`){Ne(e=>e+1),Fe(t=>t!==void 0&&t.task===e.payload.task?void 0:t),O(`e2e`);return}if(e.type===`d2c-progress`){Fe(t=>t===void 0?t:Nd(t,e.payload));return}e.type===`session-output`&&e.sessionId===j.current&&Fe(t=>t===void 0?t:Md(t,e.event)),(e.type===`session-output`&&e.sessionId===j.current&&[`done`,`error`,`exit`].includes(e.event.type)||e.type===`runtime-error`&&(e.sessionId===void 0||e.sessionId===j.current))&&Fe(void 0),$d(e,j,t,r,d)});return window.flavorDesktop.bootstrap().then(e=>{Be.current=e.workspace,j.current=e.activeSession?.sessionId,t(e)}).catch(e=>d(Ef(e))).finally(()=>l(!1)),e},[]),(0,_.useEffect)(()=>{Ke.current||Re.current?.scrollTo({top:Re.current.scrollHeight,behavior:`smooth`})},[n]),(0,_.useEffect)(()=>{let e=!1;return window.flavorDesktop.listFiles().then(t=>{e||se(_n(t))}).catch(()=>{}),()=>{e=!0}},[e.workspace]),(0,_.useEffect)(()=>{let t=!1;return e.workspace===void 0?(ae([]),()=>{t=!0}):(window.flavorDesktop.listSkills().then(e=>{t||ae(e)}).catch(()=>{t||ae([])}),()=>{t=!0})},[e.workspace,D]);let et=e.activeSession?.busy??!1,tt=(0,_.useMemo)(()=>e.projects??(e.workspace===void 0?[]:[{workspace:e.workspace,sessions:e.sessions,...e.activeSession===void 0?{}:{activeSession:{sessionId:e.activeSession.sessionId,busy:e.activeSession.busy}},running:et||e.jobs.some(e=>e.state===`running`)}]),[e.projects,e.workspace,e.sessions,e.activeSession,e.jobs,et]);(0,_.useEffect)(()=>{Le(e=>{let t=Ce(tt,We.current,e);return We.current=t.activity,t.notices})},[tt]);let nt=(0,_.useMemo)(()=>nn(Vd,[],ie.filter(e=>e.enabled),e.managedTools??[]),[ie,e.managedTools]),rt=(0,_.useMemo)(()=>et||e.approval!==void 0||e.questions!==void 0||ne===i?null:an(i,fe,nt,ee),[i,fe,ee,ne,et,e.approval,e.questions,nt]),it=(0,_.useMemo)(()=>et||e.approval!==void 0||e.questions!==void 0||ue===i||rt!==null?null:vn(i,fe,oe,ce),[i,fe,ce,ue,et,e.approval,e.questions,oe,rt]),at=rt===null?rn(i,nt,!1):0,ot=(0,_.useCallback)(e=>{let t=sn(i,fe,e);a(t.text),re(t.text),te(0),pe(t.cursor),setTimeout(()=>{let e=ze.current;e!==null&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},0)},[i,fe]),st=(0,_.useCallback)(()=>{re(i)},[i]),ct=(0,_.useCallback)(e=>{te(t=>on(t,e,rt?.items.length??0))},[rt]),lt=(0,_.useCallback)(e=>{let t=bn(i,fe,e);a(t.text),T(t.text),le(0),de(t.span),pe(t.cursor),setTimeout(()=>{let e=ze.current;e!==null&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},0)},[i,fe]),ut=(0,_.useCallback)(()=>{T(i)},[i]),dt=(0,_.useCallback)(e=>{le(t=>yn(t,e,it?.items.length??0))},[it]),ft=async()=>{d(void 0);try{Je();let e=await window.flavorDesktop.chooseWorkspace();e!==void 0&&(Qe(),Xe(e))}catch(e){d(Ef(e))}},pt=async n=>{if(n===e.workspace)return Ye(n),window.flavorDesktop.acknowledgeSession().then(t).catch(()=>void 0),O(`conversation`),p(!1),e;d(void 0),Je();try{let e=await window.flavorDesktop.openWorkspace(n);return Qe(),Xe(e),window.flavorDesktop.acknowledgeSession().then(t).catch(()=>void 0),e}catch(e){d(Ef(e));return}},mt=async(e,t)=>{let n=await pt(e);if(n!==void 0){if(n.activeSession?.sessionId===t.sessionId){O(`conversation`),p(!1);return}await ht(t)}},ht=async e=>{d(void 0);try{Je();let n=await window.flavorDesktop.selectSession(e.sessionId),i=n.snapshot.workspace===void 0?void 0:Ue.current.get(`${n.snapshot.workspace}\u0000${n.sessionId}`);t(n.snapshot),Be.current=n.snapshot.workspace,j.current=n.sessionId,r(i??C(S(),{type:`restore`,state:n.restoredTranscript})),O(`conversation`),p(!1)}catch(e){d(Ef(e))}},gt=async(e,n)=>{d(void 0);try{let i=await window.flavorDesktop.startSession(e?.sessionId,n);Qe(),t(i.snapshot),Be.current=i.snapshot.workspace,j.current=i.sessionId,r(C(S(),{type:`restore`,state:i.restoredTranscript})),i.snapshot.workspace!==void 0&&Ue.current.set(`${i.snapshot.workspace}\u0000${i.sessionId}`,C(S(),{type:`restore`,state:i.restoredTranscript})),p(!1),O(`conversation`),setTimeout(()=>ze.current?.focus(),0)}catch(e){d(Ef(e))}},_t=async(n,s,c)=>{let l=(n??i).trim(),u=n===void 0?o:[];if(!l&&u.length===0)return!1;d(void 0);try{let i=e;if(i.activeSession===void 0){let e=await window.flavorDesktop.startSession();i=e.snapshot,t(i),r(C(S(),{type:`restore`,state:e.restoredTranscript}))}let o=s??(et?`steer`:`prompt`);if(u.length>0&&o!==`prompt`)throw Error(`图片只能随新消息发送,不能作为运行中的引导或后续消息。`);return o===`prompt`&&r(e=>C(e,{type:`submit`,prompt:Kd(l,u)})),n===void 0&&a(``),await window.flavorDesktop.submit(l,o,u.map(({name:e,mediaType:t,dataBase64:n})=>({name:e,mediaType:t,dataBase64:n})),c),u.length>0&&Qe(),!0}catch(e){let t=Ef(e);return d(t),r(e=>C(e,{type:`submit-error`,message:t})),!1}},vt=e=>void _t(`/permissions ${e}`),yt=async e=>{d(void 0);try{t(await window.flavorDesktop.switchModel(e))}catch(e){d(Ef(e))}},bt=async()=>{if(!(et||e.activeSession===void 0)){d(void 0);try{await window.flavorDesktop.finishTask()}catch(e){d(Ef(e))}}},xt=async e=>{d(void 0);try{let n=await window.flavorDesktop.addModel(e);t(n.snapshot)}catch(e){throw d(Ef(e)),e}},St=(e,t)=>{let n=t.currentTarget.getBoundingClientRect();window.flavorDesktop.showAppMenu(e,Math.round(n.left),Math.round(n.bottom))},Ct=async()=>{if(!(y===void 0||x)){w(!0),d(void 0);try{let n=y.sessionId===e.activeSession?.sessionId,i=await window.flavorDesktop.deleteSession(y.sessionId);t(i),n&&r(S()),b(void 0),v(void 0)}catch(e){d(Ef(e))}finally{w(!1)}}},wt=async(e,n)=>{try{t(await window.flavorDesktop.updateSession(e.sessionId,n)),v(void 0)}catch(e){d(Ef(e))}},M=e=>{let t=window.prompt(`任务名称`,e.title??xe(e));t!==null&&wt(e,{title:t.trim()})},Tt=async(e,n)=>{try{t(await window.flavorDesktop.updateProject(e,n)),be(void 0)}catch(e){d(Ef(e))}},Et=(e,t)=>{let n=window.prompt(`项目显示名称`,t??Se(e));n!==null&&Tt(e,{label:n.trim()})},Dt=async(e,t)=>{if(!(t&&!window.confirm(`项目中有任务正在运行。停止任务并关闭项目?`)))try{Xe(await window.flavorDesktop.closeProject(e,t)),be(void 0)}catch(e){d(Ef(e))}},Ot=async(e,t)=>{let n=await pt(e);if(n!==void 0&&t!==void 0){let e=n.sessions.find(e=>e.sessionId===t);e!==void 0&&await ht(e)}};(0,_.useEffect)(()=>{let t={...e.workspace===void 0?{}:{workspace:e.workspace},...e.activeSession===void 0?{}:{sessionId:e.activeSession.sessionId},view:D};A(e=>{let n=e[Ae];if(n?.workspace===t.workspace&&n?.sessionId===t.sessionId&&n?.view===t.view)return e;let r=[...e.slice(0,Ae+1),t].slice(-50);return je(r.length-1),r})},[e.workspace,e.activeSession?.sessionId,D]);let kt=async e=>{let n=Ae+e,i=ke[n];if(i!==void 0){if(je(n),i.workspace!==void 0){let e=await window.flavorDesktop.openWorkspace(i.workspace);if(Xe(e),i.sessionId!==void 0){let e=await window.flavorDesktop.selectSession(i.sessionId);t(e.snapshot),j.current=e.sessionId,r(Ue.current.get(`${i.workspace}\u0000${i.sessionId}`)??C(S(),{type:`restore`,state:e.restoredTranscript}))}}O(i.view)}};return(0,_.useEffect)(()=>{let e=e=>{if(!(e.ctrlKey||e.metaKey))return;let t=e.key.toLowerCase();t===`n`&&(e.preventDefault(),me(!0)),t===`p`&&(e.preventDefault(),Ee(`projects`),Oe(``)),t===`k`&&(e.preventDefault(),Ee(`commands`),Oe(``)),t===`[`&&(e.preventDefault(),kt(-1)),t===`]`&&(e.preventDefault(),kt(1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[e.workspace,ke,Ae]),(0,P.jsxs)(`div`,{className:`app-frame`,children:[(0,P.jsx)(Qd,{railCollapsed:m,onToggleRail:()=>h(e=>!e),onMenu:St,canBack:Ae>0,canForward:Ae<ke.length-1,onBack:()=>void kt(-1),onForward:()=>void kt(1)}),(0,P.jsxs)(`div`,{className:`desktop-shell`,"data-rail-collapsed":m,children:[(0,P.jsx)(`button`,{className:`rail-scrim`,"data-open":f,onClick:()=>p(!1),"aria-label":`关闭项目栏`}),(0,P.jsxs)(`aside`,{className:`project-rail`,"data-open":f,children:[(0,P.jsxs)(`div`,{className:`brand-row`,children:[(0,P.jsx)(Tf,{}),(0,P.jsx)(`strong`,{children:`Flavor Code`})]}),(0,P.jsxs)(`nav`,{className:`primary-actions`,"aria-label":`主要操作`,children:[(0,P.jsxs)(`button`,{className:`rail-action rail-action-primary`,disabled:e.workspace===void 0,onClick:()=>me(!0),children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(wf,{name:`plus`})}),(0,P.jsx)(`span`,{children:`新建任务`}),(0,P.jsx)(`kbd`,{children:`Ctrl N`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,onClick:()=>void ft(),children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(wf,{name:`folder`})}),(0,P.jsx)(`span`,{children:`打开项目`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`skills`,onClick:()=>{O(`skills`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(wf,{name:`sparkles`})}),(0,P.jsx)(`span`,{children:`技能`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`memory`,onClick:()=>{O(`memory`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(wf,{name:`database`})}),(0,P.jsx)(`span`,{children:`长期记忆`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`mcp`,onClick:()=>{O(`mcp`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(wf,{name:`server`})}),(0,P.jsx)(`span`,{children:`MCP 服务`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`e2e`,onClick:()=>{O(`e2e`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(wf,{name:`checklist`})}),(0,P.jsx)(`span`,{children:`E2E`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`activity`,onClick:()=>{O(`activity`),p(!1)},children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(wf,{name:`bell`})}),(0,P.jsx)(`span`,{children:`活动`}),(e.activities?.filter(e=>e.unread).length??0)>0&&(0,P.jsx)(`em`,{className:`rail-badge`,children:e.activities.filter(e=>e.unread).length})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`git`,onClick:()=>{O(`git`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(wf,{name:`git`})}),(0,P.jsx)(`span`,{children:`Git 变更`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`workbench`,onClick:()=>{O(`workbench`),p(!1)},disabled:e.workspace===void 0||e.activeSession===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(wf,{name:`checklist`})}),(0,P.jsx)(`span`,{children:`Agent 工作台`})]})]}),(0,P.jsxs)(`div`,{className:`sessions-scroll`,children:[(0,P.jsxs)(`div`,{className:`rail-section-heading`,children:[(0,P.jsx)(`span`,{children:`项目`}),(0,P.jsx)(`button`,{onClick:()=>void ft(),"aria-label":`打开新项目`,title:`打开新项目`,children:(0,P.jsx)(wf,{name:`plus`})})]}),tt.length>0&&(0,P.jsxs)(`div`,{className:`session-filter`,children:[(0,P.jsxs)(`div`,{className:`session-search`,children:[(0,P.jsx)(wf,{name:`search`}),(0,P.jsx)(`input`,{value:he,onChange:e=>ge(e.target.value),placeholder:`搜索任务`,"aria-label":`搜索任务`}),he.length>0&&(0,P.jsx)(`button`,{type:`button`,onClick:()=>ge(``),"aria-label":`清除搜索`,title:`清除搜索`,children:`×`})]}),(0,P.jsxs)(`div`,{className:`session-group-filter`,children:[(0,P.jsxs)(`select`,{value:_e,onChange:e=>ve(e.target.value),"aria-label":`按状态筛选`,children:[(0,P.jsx)(`option`,{value:`active`,children:`任务`}),(0,P.jsx)(`option`,{value:`running`,children:`运行`}),(0,P.jsx)(`option`,{value:`unread`,children:`未读`}),(0,P.jsx)(`option`,{value:`archived`,children:`归档`})]}),(0,P.jsx)(`span`,{"aria-hidden":`true`})]})]}),tt.length===0?(0,P.jsx)(`button`,{className:`empty-project`,onClick:()=>void ft(),children:`选择一个本地文件夹开始`}):tt.map(t=>{let n=t.workspace===e.workspace,r=Ie.has(t.workspace);Ie.get(t.workspace);let i=n||t.running||r;return(0,P.jsxs)(`section`,{className:`project-entry`,"data-active":n,children:[(0,P.jsxs)(`div`,{className:`project-heading-shell`,children:[(0,P.jsxs)(`button`,{className:`project-heading`,onClick:()=>void pt(t.workspace),title:t.workspace,children:[(0,P.jsx)(`span`,{className:`folder-icon`,"aria-hidden":`true`,children:(0,P.jsx)(wf,{name:`folder`})}),(0,P.jsx)(`span`,{children:t.label||Se(t.workspace)}),t.running?(0,P.jsx)(`span`,{className:`project-running-dot`,title:`项目中有任务正在执行`}):(t.unreadCount??0)>0&&(0,P.jsx)(`span`,{className:`project-complete-dot`,role:`status`,"aria-label":`项目有未读活动`})]}),(0,P.jsx)(`button`,{className:`project-more`,onClick:()=>be(e=>e===t.workspace?void 0:t.workspace),"aria-label":`管理项目`,children:`•••`}),ye===t.workspace&&(0,P.jsxs)(`div`,{className:`project-menu`,role:`menu`,children:[(0,P.jsx)(`button`,{onClick:()=>Et(t.workspace,t.label),children:`修改显示名称`}),(0,P.jsx)(`button`,{onClick:()=>void Tt(t.workspace,{pinned:!t.pinned}),children:t.pinned?`取消置顶`:`置顶项目`}),(0,P.jsx)(`button`,{onClick:()=>void window.flavorDesktop.revealProject(t.workspace),children:`在资源管理器中打开`}),(0,P.jsx)(`button`,{onClick:()=>void window.flavorDesktop.copyProjectPath(t.workspace),children:`复制路径`}),(0,P.jsx)(`button`,{className:`danger-item`,onClick:()=>void Dt(t.workspace,t.running),children:`关闭项目`})]})]}),i&&t.sessions.length===0&&(0,P.jsx)(`p`,{className:`no-sessions`,children:`还没有任务`}),i&&t.sessions.filter(e=>(_e===`archived`?e.archived:!e.archived)&&(_e!==`running`||t.runningSessions?.includes(e.sessionId))&&(_e!==`unread`||e.unread)&&(!he.trim()||xe(e).toLowerCase().includes(he.trim().toLowerCase()))).map(r=>{let i=n&&r.sessionId===e.activeSession?.sessionId,a=t.runningSessions?.includes(r.sessionId)??(t.running&&r.sessionId===t.activeSession?.sessionId),o=r.unread&&r.activity===`completed`;return(0,P.jsxs)(`div`,{className:`session-item-shell`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||v(void 0)},children:[(0,P.jsxs)(`button`,{className:`session-item`,"data-active":i,"data-running":a,disabled:n&&et&&!i,onClick:()=>void mt(t.workspace,r),children:[(0,P.jsxs)(`span`,{children:[r.pinned&&(0,P.jsx)(`i`,{className:`pin-mark`,children:`◆`}),xe(r)]}),a?(0,P.jsx)(`span`,{className:`session-spinner`,role:`status`,"aria-label":`任务正在执行`}):o?(0,P.jsx)(`span`,{className:`session-complete-dot`,role:`status`,"aria-label":`任务已完成,点击查看`}):(0,P.jsx)(`time`,{children:Af(r.updatedAt)})]}),n&&(0,P.jsx)(`button`,{className:`session-more`,"aria-label":`管理会话:${xe(r)}`,"aria-expanded":g===r.sessionId,onClick:()=>v(e=>e===r.sessionId?void 0:r.sessionId),children:`•••`}),n&&g===r.sessionId&&(0,P.jsxs)(`div`,{className:`session-menu`,role:`menu`,children:[(0,P.jsx)(`button`,{role:`menuitem`,onClick:()=>M(r),children:`重命名`}),(0,P.jsx)(`button`,{role:`menuitem`,onClick:()=>void wt(r,{pinned:!r.pinned}),children:r.pinned?`取消置顶`:`置顶`}),(0,P.jsx)(`button`,{role:`menuitem`,onClick:()=>void wt(r,{archived:!r.archived}),children:r.archived?`取消归档`:`归档`}),(0,P.jsx)(`button`,{role:`menuitem`,className:`danger-item`,disabled:et&&r.sessionId===e.activeSession?.sessionId,onClick:()=>{b(r),v(void 0)},children:`删除会话`})]})]},r.sessionId)})]},t.workspace)})]}),(0,P.jsxs)(`div`,{className:`rail-footer`,children:[(0,P.jsx)(`span`,{className:`avatar`,children:`F`}),(0,P.jsx)(`span`,{children:`本地工作区`}),(0,P.jsx)(`button`,{title:`帮助`,children:`?`})]})]}),(0,P.jsxs)(`main`,{className:`workspace-panel`,children:[D===`workbench`&&e.workspace!==void 0&&e.activeSession!==void 0?(0,P.jsx)(_d,{snapshot:e,onClose:()=>O(`conversation`),onError:d,onCompose:e=>{qe(e),O(`conversation`),setTimeout(()=>ze.current?.focus(),0)}}):D===`skills`&&e.workspace!==void 0?(0,P.jsx)(Hl,{onClose:()=>O(`conversation`),onError:d}):D===`memory`&&e.workspace!==void 0?(0,P.jsx)(ql,{onClose:()=>O(`conversation`),onError:d}):D===`mcp`&&e.workspace!==void 0?(0,P.jsx)(Yl,{onClose:()=>O(`conversation`),onError:d}):D===`activity`?(0,P.jsx)(Yd,{activities:e.activities??[],onClose:()=>O(`conversation`),onOpen:(e,t)=>void Ot(e,t),onClear:()=>void window.flavorDesktop.acknowledgeSession().then(t)}):D===`git`&&e.workspace!==void 0?(0,P.jsx)(ed,{onClose:()=>O(`conversation`),onError:d,onReview:()=>{O(`conversation`),_t(`/review`,`prompt`)}}):D===`e2e`&&e.workspace!==void 0?(0,P.jsx)(Zu,{onClose:()=>O(`conversation`),onInterrupt:()=>void window.flavorDesktop.interrupt(),onError:d,refreshKey:Me,pending:Pe,disabled:et,onLaunch:(e,t)=>Fe(jd(e,t)),onStartTask:e=>_t(e,`prompt`,`d2c`)}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`header`,{className:`workspace-header`,children:[(0,P.jsx)(`button`,{className:`mobile-rail-toggle`,onClick:()=>p(!0),"aria-label":`打开项目栏`,children:`☰`}),(0,P.jsx)(`div`,{className:`workspace-breadcrumb`,children:(0,P.jsx)(`span`,{children:Se(e.workspace)})}),(0,P.jsxs)(`div`,{className:`header-actions`,children:[e.jobs.some(e=>e.state===`running`)&&(0,P.jsxs)(`div`,{className:`job-strip`,title:`后台任务`,children:[(0,P.jsx)(`span`,{className:`job-pulse`}),e.jobs.filter(e=>e.state===`running`).length,` 个后台任务`]}),(0,P.jsx)(`button`,{className:`finish-task-button`,onClick:()=>void bt(),disabled:et||e.activeSession===void 0,title:`评估并完成当前任务`,children:`完成任务`}),(0,P.jsx)(`button`,{title:`更多选项`,children:`•••`})]})]}),(e.recoveryItems?.filter(t=>t.workspace===e.workspace).length??0)>0&&(0,P.jsxs)(`div`,{className:`recovery-banner`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`检测到上次未完成的任务`}),(0,P.jsx)(`span`,{children:`应用异常退出时,这些任务仍在运行。`})]}),e.recoveryItems.filter(t=>t.workspace===e.workspace).map(n=>(0,P.jsxs)(`div`,{className:`recovery-action`,children:[(0,P.jsx)(`code`,{children:Df(n.sessionId)}),(0,P.jsx)(`button`,{onClick:()=>{let t=e.sessions.find(e=>e.sessionId===n.sessionId);t!==void 0&&ht(t)},children:`恢复 / 查看`}),(0,P.jsx)(`button`,{onClick:()=>void window.flavorDesktop.dismissRecovery(n.sessionId).then(t),children:`忽略`})]},n.sessionId))]}),(0,P.jsx)(`div`,{className:`conversation-scroll`,ref:Re,children:c?(0,P.jsx)(bf,{}):e.workspace===void 0?(0,P.jsx)(yf,{onOpen:ft}):n.completed.length===0&&n.active===void 0?(0,P.jsx)(vf,{project:Se(e.workspace),onStart:e=>void _t(e)}):(0,P.jsxs)(`div`,{className:`conversation-column`,children:[n.completed.map(e=>(0,P.jsx)(ef,{turn:e},e.id)),n.active!==void 0&&(0,P.jsx)(ef,{turn:n.active,active:!0})]})}),e.diagnostics.length>0&&(0,P.jsxs)(`details`,{className:`diagnostics`,children:[(0,P.jsxs)(`summary`,{children:[e.diagnostics.length,` 条启动提示`]}),(0,P.jsx)(`pre`,{children:e.diagnostics.join(`
153
- `)})]}),(0,P.jsx)(sf,{input:i,setInput:qe,onSend:e=>void _t(void 0,e),busy:et,onInterrupt:()=>{Fe(void 0),window.flavorDesktop.interrupt()},inputRef:ze,snapshot:e,attachments:o,onAddImages:e=>void $e(e),onRemoveImage:Ze,setModel:yt,addModel:xt,setPermission:vt,slashCompletion:rt,onSlashSelect:ot,onSlashDismiss:st,onSlashMove:ct,mentionCompletion:it,onMentionSelect:lt,onMentionDismiss:ut,onMentionMove:dt,mentionSpan:E,setMentionSpan:de,completedTokenLen:at,cursorPos:fe,setCursorPos:pe})]}),u!==void 0&&(0,P.jsxs)(`div`,{className:`error-toast`,role:`alert`,children:[(0,P.jsx)(`span`,{children:`!`}),(0,P.jsx)(`p`,{children:u}),(0,P.jsx)(`button`,{onClick:()=>d(void 0),children:`×`})]})]})]}),e.approval!==void 0&&(0,P.jsx)(mf,{approval:e.approval,onResolve:e=>void window.flavorDesktop.resolveApproval(e)}),e.questions!==void 0&&(0,P.jsx)(hf,{questions:e.questions,onAnswer:e=>void window.flavorDesktop.answerQuestions(e)}),e.memoryReviews!==void 0&&e.memoryReviews.length>0&&(0,P.jsx)(gf,{reviews:e.memoryReviews,autoDismissSeconds:e.memoryAutoDismissSeconds??0,onResolve:(e,t)=>{window.flavorDesktop.resolveMemoryReview(e,t).catch(e=>d(Ef(e)))}}),y!==void 0&&(0,P.jsx)(ff,{session:y,deleting:x,onCancel:()=>b(void 0),onDelete:()=>void Ct()}),k&&(0,P.jsx)(Xd,{onCancel:()=>me(!1),onChoose:e=>{me(!1),gt(void 0,e)}}),we!==void 0&&(0,P.jsx)(Zd,{mode:we,query:De,setQuery:Oe,projects:tt,onClose:()=>Ee(void 0),onProject:e=>{Ee(void 0),pt(e)},onCommand:e=>{Ee(void 0),e===`new`?me(!0):e===`open`?ft():e===`activity`?O(`activity`):e===`git`?O(`git`):e===`skills`&&O(`skills`)}})]})}function Yd({activities:e,onClose:t,onOpen:n,onClear:r}){return(0,P.jsxs)(`section`,{className:`manager-view activity-center`,children:[(0,P.jsxs)(`header`,{className:`manager-header`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{onClick:t,children:`←`}),(0,P.jsx)(`h2`,{children:`活动`})]}),(0,P.jsx)(`button`,{onClick:r,children:`全部标为已读`})]}),(0,P.jsx)(`div`,{className:`activity-list`,children:e.length===0?(0,P.jsx)(`p`,{className:`manager-empty`,children:`还没有任务活动`}):e.map(e=>(0,P.jsxs)(`button`,{className:`activity-row`,"data-kind":e.kind,"data-unread":e.unread,onClick:()=>n(e.workspace,e.sessionId),children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:e.title}),(0,P.jsxs)(`span`,{children:[Se(e.workspace),e.detail?` · ${e.detail}`:``]})]}),(0,P.jsx)(`time`,{children:Af(e.createdAt)})]},e.id))})]})}function Xd({onCancel:e,onChoose:t}){return(0,P.jsx)(`div`,{className:`modal-layer`,onMouseDown:t=>{t.target===t.currentTarget&&e()},children:(0,P.jsxs)(`section`,{className:`new-task-sheet`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`new-task-title`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`p`,{children:`NEW TASK`}),(0,P.jsx)(`h2`,{id:`new-task-title`,children:`选择任务运行环境`}),(0,P.jsx)(`span`,{children:`隔离只影响 Electron 任务,不改变 CLI 默认行为。`})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`button`,{onClick:()=>t(`worktree`),children:[(0,P.jsx)(`i`,{children:`◇`}),(0,P.jsx)(`strong`,{children:`隔离工作树`}),(0,P.jsx)(`span`,{children:`新建 flavor/desktop-* 分支,在应用目录中独立运行。`}),(0,P.jsx)(`em`,{children:`推荐`})]}),(0,P.jsxs)(`button`,{onClick:()=>t(`local`),children:[(0,P.jsx)(`i`,{children:`⌂`}),(0,P.jsx)(`strong`,{children:`当前检出`}),(0,P.jsx)(`span`,{children:`直接使用项目当前目录,适合快速查看和轻量操作。`})]})]}),(0,P.jsx)(`footer`,{children:(0,P.jsx)(`button`,{onClick:e,children:`取消`})})]})})}function Zd({mode:e,query:t,setQuery:n,projects:r,onClose:i,onProject:a,onCommand:o}){let s=[{id:`new`,label:`新建任务`,hint:`Ctrl N`},{id:`open`,label:`打开项目`,hint:`Ctrl O`},{id:`activity`,label:`查看活动`,hint:``},{id:`git`,label:`打开 Git 变更`,hint:``},{id:`skills`,label:`管理技能`,hint:``}].filter(e=>e.label.toLowerCase().includes(t.toLowerCase())),c=r.filter(e=>`${e.label??``} ${Se(e.workspace)} ${e.workspace}`.toLowerCase().includes(t.toLowerCase()));return(0,P.jsx)(`div`,{className:`palette-layer`,onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,P.jsxs)(`section`,{className:`command-palette`,role:`dialog`,"aria-modal":`true`,children:[(0,P.jsx)(`input`,{autoFocus:!0,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Escape`&&i()},placeholder:e===`projects`?`切换到项目…`:`键入命令…`}),(0,P.jsx)(`div`,{children:e===`projects`?c.map(e=>(0,P.jsxs)(`button`,{onClick:()=>a(e.workspace),children:[(0,P.jsx)(wf,{name:`folder`}),(0,P.jsx)(`span`,{children:e.label||Se(e.workspace)}),(0,P.jsx)(`small`,{children:e.workspace})]},e.workspace)):s.map(e=>(0,P.jsxs)(`button`,{onClick:()=>o(e.id),children:[(0,P.jsx)(`span`,{children:e.label}),(0,P.jsx)(`kbd`,{children:e.hint})]},e.id))})]})})}function Qd({railCollapsed:e,onToggleRail:t,onMenu:n,canBack:r,canForward:i,onBack:a,onForward:o}){return(0,P.jsxs)(`header`,{className:`window-titlebar`,children:[(0,P.jsx)(`button`,{className:`titlebar-icon sidebar-toggle`,"data-collapsed":e,onClick:t,"aria-label":e?`显示项目栏`:`隐藏项目栏`,title:e?`显示项目栏`:`隐藏项目栏`,children:(0,P.jsxs)(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,children:[(0,P.jsx)(`rect`,{x:`2.5`,y:`2.5`,width:`11`,height:`11`,rx:`2`}),(0,P.jsx)(`path`,{d:`M6 3v10`})]})}),(0,P.jsx)(`button`,{className:`titlebar-icon nav-button`,disabled:!r,onClick:a,"aria-label":`后退`,title:`后退 (Ctrl+[)`,children:(0,P.jsx)(`span`,{children:`‹`})}),(0,P.jsx)(`button`,{className:`titlebar-icon nav-button`,disabled:!i,onClick:o,"aria-label":`前进`,title:`前进 (Ctrl+])`,children:(0,P.jsx)(`span`,{children:`›`})}),(0,P.jsxs)(`nav`,{className:`titlebar-menus`,"aria-label":`应用菜单`,children:[(0,P.jsx)(`button`,{onClick:e=>n(`file`,e),children:`文件`}),(0,P.jsx)(`button`,{onClick:e=>n(`edit`,e),children:`编辑`}),(0,P.jsx)(`button`,{onClick:e=>n(`view`,e),children:`视图`}),(0,P.jsx)(`button`,{onClick:e=>n(`help`,e),children:`帮助`})]})]})}function $d(e,t,n,r,i){e.type===`snapshot`?(t.current=e.snapshot.activeSession?.sessionId,n(e.snapshot)):e.type===`session-started`?(t.current=e.payload.sessionId,n(e.payload.snapshot),r(C(S(),{type:`restore`,state:e.payload.restoredTranscript}))):e.type===`session-output`?r(n=>Te(n,t.current,e)):e.type===`runtime-error`&&(e.sessionId===void 0||e.sessionId===t.current)&&i(e.message)}function ef({turn:e,active:t=!1}){let n=t?e.blocks:e.blocks.filter(e=>e.kind!==`status`||e.task===void 0);return(0,P.jsxs)(`article`,{className:`turn`,"data-active":t,"data-kind":e.kind??`conversation`,children:[(0,P.jsx)(`div`,{className:`user-message`,children:(0,P.jsx)(`span`,{children:e.prompt})}),(0,P.jsxs)(`div`,{className:`assistant-message`,children:[(0,P.jsx)(`div`,{className:`assistant-avatar`,children:(0,P.jsx)(Tf,{})}),(0,P.jsxs)(`div`,{className:`turn-content`,children:[n.map((e,t)=>(0,P.jsx)(tf,{block:e},e.kind===`status`?e.id:`text-${t}`)),t&&n.length===0&&(0,P.jsxs)(`div`,{className:`thinking-line`,role:`status`,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:`Flavoring`}),(0,P.jsx)(`small`,{children:`正在理解任务`})]})]})]})]})]})}function tf({block:e}){if(e.kind===`text`)return(0,P.jsx)(`div`,{className:`assistant-copy`,children:(0,P.jsx)(Qt,{text:e.text})});let t=e.state===`completed`?`✓`:e.state===`failed`?`×`:e.state===`cancelled`?`–`:e.state===`running`?``:`·`,n=e.activity===`model`,r=n&&e.thinkingText?nf(e.thinkingText):void 0;return(0,P.jsxs)(`div`,{className:`activity-card`,"data-state":e.state,"data-tone":e.tone,"data-activity":e.activity,children:[(0,P.jsx)(`span`,{className:`activity-node`,children:t}),(0,P.jsxs)(`div`,{className:`activity-body`,children:[(0,P.jsxs)(`div`,{className:`activity-title`,children:[(0,P.jsx)(`span`,{children:e.text.replace(/^[·✓×]\s*/,``)}),n&&e.state===`running`&&(0,P.jsx)(`small`,{children:`正在思考`}),e.hint&&(0,P.jsx)(`code`,{children:e.hint})]}),r&&(0,P.jsx)(`div`,{className:`reasoning-preview`,children:r}),e.progress!==void 0&&(0,P.jsx)(`div`,{className:`progress-track`,children:(0,P.jsx)(`i`,{style:{width:`${e.progress}%`}})}),e.presentation?.kind===`file-change`&&(0,P.jsx)(af,{presentation:e.presentation}),e.presentation?.kind===`generic`&&(0,P.jsxs)(`div`,{className:`tool-presentation`,children:[(0,P.jsx)(`strong`,{children:e.presentation.title}),e.presentation.summary&&(0,P.jsx)(`span`,{children:e.presentation.summary})]}),e.presentation?.kind===`terminal`&&(0,P.jsxs)(`div`,{className:`tool-presentation`,children:[(0,P.jsx)(`strong`,{children:e.presentation.title}),e.presentation.stdout&&(0,P.jsx)(`pre`,{children:e.presentation.stdout})]}),e.presentation?.kind===`web`&&(0,P.jsxs)(`div`,{className:`tool-presentation`,children:[(0,P.jsx)(`strong`,{children:e.presentation.title}),e.presentation.summary&&(0,P.jsx)(`span`,{children:e.presentation.summary})]}),e.tool&&(0,P.jsxs)(`details`,{className:`tool-details`,children:[(0,P.jsx)(`summary`,{children:`调用详情`}),(0,P.jsx)(`label`,{children:`Input`}),(0,P.jsx)(`pre`,{children:rf(e.tool.input)}),e.tool.result===void 0?null:(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`label`,{children:`Result`}),(0,P.jsx)(`pre`,{children:rf(e.tool.result)})]})]}),e.details&&(0,P.jsxs)(`details`,{className:`timeline-details`,children:[(0,P.jsx)(`summary`,{children:`压缩摘要`}),(0,P.jsx)(Qt,{text:e.details})]})]})]})}function nf(e,t=280){let n=e.replace(/\s+/gu,` `).trim(),r=Math.max(1,Math.floor(t)),i=[...n];return i.length<=r?n:`…${i.slice(-r).join(``)}`}function rf(e,t=1e4){let n;try{n=JSON.stringify(e,null,2)??`undefined`}catch{n=String(e)}return n.length<=t?n:`${n.slice(0,t)}…`}function af({presentation:e}){let t=e.operation===`delete`,n=e.operation===`create`?`新建`:e.operation===`delete`?`删除`:`修改`,r=e.path.replace(/^.*[/\\]/,``),i=t?1:Math.max(1,...e.lines.map(e=>Math.max(e.oldLine??0,e.newLine??0))).toString().length;return(0,P.jsxs)(`details`,{className:`diff-preview`,children:[(0,P.jsxs)(`summary`,{children:[(0,P.jsx)(`span`,{className:`diff-marker ${t?`diff-delete`:`diff-add`}`,children:`●`}),(0,P.jsx)(`span`,{className:`diff-label`,children:n}),(0,P.jsx)(`span`,{className:`diff-path`,children:r}),(0,P.jsxs)(`span`,{className:`diff-counts`,children:[!t&&(0,P.jsxs)(`span`,{className:`diff-added-count`,children:[`+`,e.added]}),!t&&e.removed>0&&(0,P.jsxs)(`span`,{className:`diff-removed-count`,children:[` −`,e.removed]}),t&&(0,P.jsxs)(`span`,{className:`diff-removed-count`,children:[`−`,e.removed]})]})]}),t?null:(0,P.jsx)(`div`,{className:`diff-body`,children:e.lines.map((e,t)=>(0,P.jsx)(of,{line:e,lineWidth:i},t))})]})}function of({line:e,lineWidth:t}){let n=e.kind===`removed`||e.kind===`context`?e.oldLine:e.newLine,r=e.kind===`removed`?`-`:e.kind===`added`?`+`:e.kind===`omitted`?`…`:` `;return(0,P.jsxs)(`div`,{className:`diff-row ${e.kind===`added`?`diff-row-added`:e.kind===`removed`?`diff-row-removed`:e.kind===`omitted`?`diff-row-omitted`:`diff-row-context`}`,children:[(0,P.jsx)(`span`,{className:`diff-line-number`,children:String(n??``).padStart(t)}),(0,P.jsx)(`span`,{className:`diff-line-marker`,children:r}),(0,P.jsx)(`span`,{className:`diff-line-text`,children:e.text})]})}function sf(e){let t=e.snapshot.workspace===void 0,[n,r]=(0,_.useState)(!1),i=(0,_.useRef)(null),a=e.slashCompletion!==null,o=e.mentionCompletion!==null,s=a||o,c=e.completedTokenLen>0,l=c?e.input.slice(0,e.completedTokenLen):void 0,u=l?.startsWith(`/`)?l.slice(1).trim():l?.trim(),d=c?void 0:e.mentionSpan,f=d!==void 0&&d.start>=0&&d.end>d.start&&d.start<e.input.length&&d.end<=e.input.length&&e.input.slice(d.start,d.end)===e.input.slice(d.start,d.end),p=f?e.input.slice(0,d.start):``,m=f?e.input.slice(d.start,d.end):``,h=f?e.input.slice(d.end):``,g=m.startsWith(`@`)?m.slice(1).trim():m,v=c?e.input.slice(e.completedTokenLen):f?h:e.input,y=c?l.length:f?d.start+m.length:0,b=e=>y+e,x=t=>{if(a){if(t.key===`ArrowDown`){t.preventDefault(),e.onSlashMove(1);return}if(t.key===`ArrowUp`){t.preventDefault(),e.onSlashMove(-1);return}if(t.key===`Tab`||t.key===`Enter`){t.preventDefault();let n=e.slashCompletion?.items[e.slashCompletion?.selectedIndex??0];n!==void 0&&e.onSlashSelect(n.name);return}if(t.key===`Escape`){t.preventDefault(),e.onSlashDismiss();return}}if(o){if(t.key===`ArrowDown`){t.preventDefault(),e.onMentionMove(1);return}if(t.key===`ArrowUp`){t.preventDefault(),e.onMentionMove(-1);return}if(t.key===`Tab`||t.key===`Enter`){t.preventDefault();let n=e.mentionCompletion?.items[e.mentionCompletion?.selectedIndex??0];n!==void 0&&e.onMentionSelect(n);return}if(t.key===`Escape`){t.preventDefault(),e.onMentionDismiss();return}}let n=t.target,r=n.selectionStart,i=n.selectionEnd;if(t.key===`Backspace`&&r===i&&!s){if(c){let n=cn(e.input,e.completedTokenLen,b(r));if(n!==null){t.preventDefault(),e.setInput(n.text),e.setCursorPos(n.cursor);return}}if(f&&r===0){t.preventDefault();let n=p+h;e.setInput(n),e.setMentionSpan(void 0),e.setCursorPos(p.length);return}}t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),e.onSend(t.altKey?`followUp`:e.busy?`steer`:void 0))},S=(t,n)=>{let r;if(r=c?l+t:f?p+m+t:t,f){let t=p+m;r.startsWith(t)||e.setMentionSpan(void 0)}e.setInput(r),e.setCursorPos(b(n))},C=t=>{e.setCursorPos(b(t))},w=(0,P.jsx)(`textarea`,{ref:e.inputRef,className:`composer-textarea`,value:v,onChange:e=>S(e.target.value,e.target.selectionStart),onSelect:e=>C(e.target.selectionStart),onKeyDown:x,onPaste:t=>{let n=cf(t.clipboardData.files);n.length!==0&&(t.preventDefault(),e.onAddImages(n))},onClick:e=>C(e.target.selectionStart),placeholder:t?`先打开一个项目`:c||f?``:`给 Flavor 一个任务,或输入 / 查看命令`,disabled:t,rows:1}),ee=c?(0,P.jsxs)(`div`,{className:`composer-input-row`,children:[(0,P.jsx)(`span`,{className:`slash-tag`,children:u}),w]}):f?(0,P.jsxs)(`div`,{className:`composer-input-row`,children:[p.length>0&&(0,P.jsx)(`span`,{className:`composer-plain-text`,children:p}),(0,P.jsx)(`span`,{className:`mention-tag`,children:g}),w]}):w;return(0,P.jsxs)(`div`,{className:`composer-wrap`,onDragEnter:e=>{lf(e.dataTransfer)&&(e.preventDefault(),r(!0))},onDragOver:e=>{lf(e.dataTransfer)&&e.preventDefault()},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||r(!1)},onDrop:t=>{let n=cf(t.dataTransfer.files);n.length!==0&&(t.preventDefault(),r(!1),e.onAddImages(n))},children:[a&&(0,P.jsx)(fn,{completion:e.slashCompletion,onSelect:e.onSlashSelect,onDismiss:e.onSlashDismiss}),o&&(0,P.jsx)(hn,{completion:e.mentionCompletion,onSelect:e.onMentionSelect,onDismiss:e.onMentionDismiss}),(0,P.jsxs)(`div`,{className:`composer${c||f?` has-tag`:``}`,"data-busy":e.busy,"data-image-drag":n,children:[e.attachments.length>0&&(0,P.jsx)(qd,{attachments:e.attachments,onRemove:e.onRemoveImage}),ee,(0,P.jsxs)(`div`,{className:`composer-tools`,children:[(0,P.jsx)(`input`,{ref:i,className:`image-file-input`,type:`file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,onChange:t=>{e.onAddImages(cf(t.target.files)),t.target.value=``}}),(0,P.jsxs)(`button`,{type:`button`,className:`attach-button attach-button-labeled image-attach-button`,title:`添加图片(也可粘贴或拖入)`,"aria-label":`添加图片`,onClick:()=>i.current?.click(),disabled:t||e.busy||e.attachments.length>=Hd,children:[(0,P.jsx)(wf,{name:`image`}),(0,P.jsx)(`span`,{children:`图片`})]}),(0,P.jsxs)(`button`,{className:`attach-button attach-button-labeled`,title:`在提示中输入 @ 引用项目文件`,onClick:()=>{e.setInput(`${e.input}${e.input?` `:``}@`),setTimeout(()=>{let t=e.inputRef.current;t!==null&&(t.focus(),t.setSelectionRange(t.value.length,t.value.length))},0)},disabled:t,children:[(0,P.jsx)(wf,{name:`at`}),(0,P.jsx)(`span`,{children:`文件`})]}),(0,P.jsxs)(`div`,{className:`composer-context`,children:[(0,P.jsxs)(`span`,{className:`context-item`,title:e.snapshot.workspace,children:[(0,P.jsx)(wf,{name:`folder`}),(0,P.jsx)(`span`,{children:Se(e.snapshot.workspace)})]}),(0,P.jsxs)(`span`,{className:`context-item`,children:[(0,P.jsx)(wf,{name:`monitor`}),(0,P.jsx)(`span`,{children:`本地`})]})]}),(0,P.jsxs)(`div`,{className:`composer-controls`,children:[(0,P.jsx)(kf,{models:e.snapshot.models,activeModel:e.snapshot.activeSession?.mainModel,busy:e.busy,onSelect:e.setModel,onAdd:e.addModel}),(0,P.jsx)(`select`,{"aria-label":`权限模式`,value:e.snapshot.activeSession?.permissionMode??`default`,disabled:e.busy||e.snapshot.activeSession===void 0,onChange:t=>e.setPermission(t.target.value),children:Bd.map(e=>(0,P.jsx)(`option`,{value:e,children:be(e)},e))}),e.busy&&(0,P.jsxs)(`span`,{className:`queue-count`,title:`引导 + 后续消息`,children:[e.snapshot.activeSession?.queue.steering.length??0,`+`,e.snapshot.activeSession?.queue.followUp.length??0]}),(0,P.jsx)(`button`,{className:`send-button`,onClick:()=>e.onSend(e.busy?`steer`:void 0),disabled:t||!e.input.trim()&&e.attachments.length===0,title:e.busy?`发送引导消息`:`发送`,children:(0,P.jsx)(`span`,{children:`↑`})}),e.busy&&(0,P.jsx)(`button`,{className:`send-button stop-button`,onClick:e.onInterrupt,title:`停止任务`,children:(0,P.jsx)(`span`,{})})]})]})]}),(0,P.jsx)(`p`,{className:`composer-hint`,children:`Enter 发送 · Shift Enter 换行 · 粘贴/拖入图片 · @ 引用文件 · / 调用命令`})]})}function cf(e){return e===null?[]:Array.from(e).filter(e=>e.type.startsWith(`image/`))}function lf(e){return Array.from(e.items).some(e=>e.kind===`file`&&e.type.startsWith(`image/`))}async function uf(e){if(!Gd.has(e.type))throw Error(`不支持 ${e.type||`未知格式`};请选择 PNG、JPEG 或 WebP 图片。`);if(e.size<=0)throw Error(`${e.name} 是空文件。`);if(e.size>Ud)throw Error(`${e.name} 超过单图 5 MiB 限制。`);let t=df(new Uint8Array(await e.arrayBuffer())),n=URL.createObjectURL(e);return{id:globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random()}`,name:e.name,mediaType:e.type,dataBase64:t,previewUrl:n}}function df(e){let t=``,n=32768;for(let r=0;r<e.length;r+=n)t+=String.fromCharCode(...e.subarray(r,r+n));return btoa(t)}function ff({session:e,deleting:t,onCancel:n,onDelete:r}){return(0,P.jsx)(`div`,{className:`modal-layer`,children:(0,P.jsxs)(`section`,{className:`decision-sheet delete-session-sheet`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`delete-session-title`,children:[(0,P.jsx)(`div`,{className:`sheet-icon danger`,children:`×`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{className:`sheet-kicker`,children:`删除历史会话`}),(0,P.jsxs)(`h2`,{id:`delete-session-title`,children:[`删除“`,xe(e),`”?`]}),(0,P.jsx)(`p`,{children:`此会话的消息和任务记录将从当前项目中永久删除,此操作无法撤销。`}),(0,P.jsxs)(`div`,{className:`sheet-actions`,children:[(0,P.jsx)(`button`,{disabled:t,onClick:n,children:`取消`}),(0,P.jsx)(`button`,{className:`danger`,disabled:t,onClick:r,children:t?`正在删除…`:`删除会话`})]})]})]})})}var pf=new Set([`Delete`,`Move`,`RemoveTool`]);function mf({approval:e,onResolve:t}){let n=pf.has(e.tool)||e.allowAlways===!1;return(0,P.jsx)(`div`,{className:`modal-layer`,children:(0,P.jsxs)(`section`,{className:`decision-sheet`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`approval-title`,children:[(0,P.jsx)(`div`,{className:`sheet-icon warning`,children:`!`}),(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`p`,{className:`sheet-kicker`,children:[`权限确认 · `,e.agent===`main`?`主 Agent`:`子 Agent`]}),(0,P.jsxs)(`h2`,{id:`approval-title`,children:[`允许执行 `,e.tool,`?`]}),(0,P.jsx)(`p`,{children:e.reason??`这项操作需要你的确认。`}),(e.command||e.paths?.length)&&(0,P.jsxs)(`pre`,{children:[e.command??e.paths?.join(`
154
- `),e.args?.length?` ${e.args.join(` `)}`:``]}),(0,P.jsxs)(`div`,{className:`sheet-actions`,children:[(0,P.jsx)(`button`,{onClick:()=>t(`deny`),children:`拒绝`}),!n&&(0,P.jsx)(`button`,{onClick:()=>t(`always`),children:`始终允许同类操作`}),(0,P.jsx)(`button`,{className:`primary`,onClick:()=>t(`allow`),children:`允许一次`})]})]})]})})}function hf({questions:e,onAnswer:t}){let[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)({}),o=e.every((e,t)=>!!n[t]?.trim());return(0,P.jsx)(`div`,{className:`modal-layer`,children:(0,P.jsxs)(`section`,{className:`question-sheet`,role:`dialog`,"aria-modal":`true`,children:[(0,P.jsx)(`p`,{className:`sheet-kicker`,children:`Flavor 需要确认`}),e.map((e,t)=>(0,P.jsxs)(`fieldset`,{children:[(0,P.jsx)(`legend`,{children:e.header}),(0,P.jsx)(`p`,{children:e.question}),(0,P.jsxs)(`div`,{className:`question-options`,children:[e.options.map(e=>(0,P.jsxs)(`button`,{"data-selected":!i[t]&&n[t]===e.label,onClick:()=>{a(e=>({...e,[t]:!1})),r(n=>({...n,[t]:e.label}))},children:[(0,P.jsx)(`strong`,{children:e.label}),(0,P.jsx)(`span`,{children:e.description})]},e.label)),(0,P.jsxs)(`button`,{"data-selected":i[t]===!0,onClick:()=>{a(e=>({...e,[t]:!0})),r(e=>({...e,[t]:``}))},children:[(0,P.jsx)(`strong`,{children:`其他(自定义输入)`}),(0,P.jsx)(`span`,{children:`键入你自己的回答`})]}),i[t]===!0&&(0,P.jsx)(`input`,{className:`question-custom-input`,autoFocus:!0,value:n[t]??``,onChange:e=>r(n=>({...n,[t]:e.target.value})),placeholder:`请输入回答`,"aria-label":`${e.header} 自定义回答`})]})]},`${e.header}-${t}`)),(0,P.jsx)(`div`,{className:`sheet-actions`,children:(0,P.jsx)(`button`,{className:`primary`,disabled:!o,onClick:()=>t(n),children:`继续`})})]})})}function gf({reviews:e,autoDismissSeconds:t,onResolve:n}){return(0,P.jsxs)(`aside`,{className:`memory-review-rail`,"aria-label":`长期记忆写入确认`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{children:`待确认`}),(0,P.jsx)(`h2`,{children:`长期记忆候选`})]}),(0,P.jsx)(`span`,{children:e.length})]}),(0,P.jsx)(`p`,{className:`memory-review-warning`,children:`以下内容由模型生成,确认前不会写入长期记忆,也不会影响后续会话。`}),(0,P.jsx)(`div`,{className:`memory-review-list`,children:e.map(e=>(0,P.jsxs)(`article`,{children:[(0,P.jsx)(`small`,{children:e.type}),(0,P.jsx)(`p`,{children:e.content}),(0,P.jsx)(_f,{seconds:t}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{onClick:()=>n(e.id,`dismiss`),children:`忽略`}),(0,P.jsx)(`button`,{className:`primary`,onClick:()=>n(e.id,`accept`),children:`保存`})]})]},e.id))})]})}function _f({seconds:e}){let[t,n]=(0,_.useState)(e);return(0,_.useEffect)(()=>{if(e<=0)return;n(e);let t=setInterval(()=>n(e=>Math.max(0,e-1)),1e3);return()=>clearInterval(t)},[e]),e<=0?null:(0,P.jsxs)(`small`,{className:`memory-review-countdown`,children:[`未操作将在 `,t,`s 后自动忽略`]})}function vf({project:e,onStart:t}){return(0,P.jsxs)(`section`,{className:`welcome-state`,children:[(0,P.jsx)(`div`,{className:`welcome-mark`,children:(0,P.jsx)(Tf,{})}),(0,P.jsx)(`p`,{children:`已连接本地项目`}),(0,P.jsxs)(`h1`,{children:[`我们应该在 `,(0,P.jsx)(`u`,{children:e}),` 中构建什么?`]}),(0,P.jsx)(`div`,{className:`starter-grid`,children:ve.map(e=>(0,P.jsx)(`button`,{onClick:()=>t(e),children:e},e))})]})}function yf({onOpen:e}){return(0,P.jsxs)(`section`,{className:`open-state`,children:[(0,P.jsx)(`div`,{className:`welcome-mark`,children:(0,P.jsx)(Tf,{})}),(0,P.jsx)(`h1`,{children:`从一个本地项目开始`}),(0,P.jsx)(`p`,{children:`Flavor 会在你选择的文件夹范围内阅读、修改和运行代码。`}),(0,P.jsx)(`button`,{onClick:e,children:`打开项目`})]})}function bf(){return(0,P.jsxs)(`div`,{className:`loading-state`,children:[(0,P.jsx)(Tf,{}),(0,P.jsx)(`span`,{children:`正在准备桌面工作区…`})]})}var xf;function Sf(){return xf??=window.flavorDesktop.appIcon().catch(()=>void 0),xf}function Cf(){let[e,t]=(0,_.useState)(void 0);return(0,_.useEffect)(()=>{let e=!1;return Sf().then(n=>{e||t(n)}),()=>{e=!0}},[]),e}function wf({name:e}){let t;switch(e){case`plus`:t=(0,P.jsx)(`path`,{d:`M10 4v12M4 10h12`});break;case`folder`:t=(0,P.jsx)(`path`,{d:`M2.75 6.25h5l1.5 1.75h8v7.25a1.5 1.5 0 0 1-1.5 1.5h-12a1.5 1.5 0 0 1-1.5-1.5v-7.5a1.5 1.5 0 0 1 1.5-1.5Z`});break;case`sparkles`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`path`,{d:`M8.25 3.25c.4 2.4 1.6 3.6 4 4-2.4.4-3.6 1.6-4 4-.4-2.4-1.6-3.6-4-4 2.4-.4 3.6-1.6 4-4Z`}),(0,P.jsx)(`path`,{d:`M14.5 11.5c.25 1.45 1.05 2.25 2.5 2.5-1.45.25-2.25 1.05-2.5 2.5-.25-1.45-1.05-2.25-2.5-2.5 1.45-.25 2.25-1.05 2.5-2.5Z`})]});break;case`database`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`ellipse`,{cx:`10`,cy:`5`,rx:`6.25`,ry:`2.5`}),(0,P.jsx)(`path`,{d:`M3.75 5v5c0 1.38 2.8 2.5 6.25 2.5s6.25-1.12 6.25-2.5V5M3.75 10v5c0 1.38 2.8 2.5 6.25 2.5s6.25-1.12 6.25-2.5v-5`})]});break;case`server`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`rect`,{x:`3`,y:`3.5`,width:`14`,height:`5`,rx:`1.5`}),(0,P.jsx)(`rect`,{x:`3`,y:`11.5`,width:`14`,height:`5`,rx:`1.5`}),(0,P.jsx)(`path`,{d:`M6 6h.01M6 14h.01M9 6h5M9 14h5`})]});break;case`checklist`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`rect`,{x:`3.25`,y:`2.75`,width:`13.5`,height:`14.5`,rx:`2`}),(0,P.jsx)(`path`,{d:`m6.25 7 1.25 1.25L10 5.75M11.75 7h2M6.25 12h1.5M10 12h4`})]});break;case`image`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`rect`,{x:`2.75`,y:`3.25`,width:`14.5`,height:`13.5`,rx:`2`}),(0,P.jsx)(`circle`,{cx:`7`,cy:`7.25`,r:`1.25`}),(0,P.jsx)(`path`,{d:`m4.75 14 3.5-3.5 2.25 2.25 2.25-2.5 2.5 3.75`})]});break;case`at`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`circle`,{cx:`9.5`,cy:`10`,r:`3`}),(0,P.jsx)(`path`,{d:`M12.5 10v1.25c0 1.15.8 1.75 1.75 1.75 1.4 0 2.25-1.2 2.25-3a6.5 6.5 0 1 0-2.1 4.78`})]});break;case`monitor`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`rect`,{x:`2.75`,y:`3.5`,width:`14.5`,height:`10.5`,rx:`2`}),(0,P.jsx)(`path`,{d:`M7 17h6M10 14v3`})]});break;case`bell`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`path`,{d:`M5.25 8.5a4.75 4.75 0 0 1 9.5 0c0 5 2 5.5 2 5.5H3.25s2-.5 2-5.5Z`}),(0,P.jsx)(`path`,{d:`M8 16a2.25 2.25 0 0 0 4 0`})]});break;case`git`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`circle`,{cx:`5`,cy:`4`,r:`1.75`}),(0,P.jsx)(`circle`,{cx:`15`,cy:`6.5`,r:`1.75`}),(0,P.jsx)(`circle`,{cx:`5`,cy:`16`,r:`1.75`}),(0,P.jsx)(`path`,{d:`M5 5.75v8.5M6.75 7.5C11 7.5 10.5 6.5 13.25 6.5`})]});break;case`search`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`circle`,{cx:`8.75`,cy:`8.75`,r:`5.25`}),(0,P.jsx)(`path`,{d:`m12.5 12.5 4 4`})]});break}return(0,P.jsx)(`svg`,{className:`ui-icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,focusable:`false`,children:t})}function Tf(){let e=Cf();return e===void 0?(0,P.jsxs)(`svg`,{className:`flavor-mark`,viewBox:`0 0 36 36`,"aria-hidden":`true`,children:[(0,P.jsx)(`path`,{d:`M8 17.5C8 11.7 12.5 7 18 7s10 4.7 10 10.5c0 2.7-1 5.1-2.7 7l1 3.8-4-1.2A9.5 9.5 0 0 1 18 28c-5.5 0-10-4.7-10-10.5Z`}),(0,P.jsx)(`path`,{d:`M16 15l-2 2l2 2`,fill:`none`,stroke:`#1979c9`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,P.jsx)(`path`,{d:`M20 15l2 2l-2 2`,fill:`none`,stroke:`#1979c9`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,P.jsx)(`path`,{className:`mark-smile`,d:`M14 23c2.5 1.5 5.5 1.5 8 0`}),(0,P.jsx)(`ellipse`,{cx:`22`,cy:`24`,rx:`1.2`,ry:`0.9`,fill:`#f472b6`,stroke:`#ec4899`,strokeWidth:`0.3`,transform:`rotate(15 22 24)`})]}):(0,P.jsx)(`img`,{className:`flavor-mark`,src:e,alt:``,"aria-hidden":`true`})}function Ef(e){return e instanceof Error?e.message:String(e)}function Df(e){return e.replace(/^session-/,``).slice(0,17)}function Of(e){return e?e.split(`:`).at(-1)??e:`选择模型`}function kf({models:e,activeModel:t,busy:n,onSelect:r,onAdd:i}){let[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(),[d,f]=(0,_.useState)({provider:``,model:``,baseURL:``,apiKey:``,protocol:`openai-compatible`}),p=t??e[0]?.id,m=e.find(e=>e.id===p),h=m?.label??Of(p),g=(e,t)=>{f(n=>({...n,[e]:t})),u(void 0)},v=async e=>{if(e.preventDefault(),s)return;let t=e.currentTarget;c(!0),u(void 0);try{await i(d),o(!1),f({provider:``,model:``,baseURL:``,apiKey:``,protocol:`openai-compatible`}),t.closest(`details`)?.removeAttribute(`open`)}catch(e){u(Ef(e))}finally{c(!1)}};return(0,P.jsxs)(`details`,{className:`model-menu`,children:[(0,P.jsxs)(`summary`,{"aria-label":`主模型:${h}`,title:`切换主模型`,children:[(0,P.jsx)(`span`,{className:`model-status-dot`,"data-configured":m!==void 0}),(0,P.jsx)(`span`,{className:`model-summary-label`,children:h}),(0,P.jsx)(`span`,{className:`model-summary-chevron`,"aria-hidden":`true`})]}),(0,P.jsxs)(`div`,{className:`popover model-popover`,children:[(0,P.jsxs)(`div`,{className:`model-popover-heading`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:a?`添加厂商模型`:`切换主模型`}),(0,P.jsx)(`span`,{children:a?`连接 OpenAI 兼容或 Anthropic 服务`:`DeepSeek 默认可用,也可接入其他厂商`})]}),!a&&(0,P.jsx)(`button`,{type:`button`,onClick:()=>o(!0),disabled:n,children:`+ 新增`})]}),a?(0,P.jsxs)(`form`,{className:`model-provider-form`,onSubmit:e=>void v(e),children:[(0,P.jsxs)(`div`,{className:`model-form-grid`,children:[(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`厂商名称 / ID`}),(0,P.jsx)(`input`,{required:!0,maxLength:64,placeholder:`例如 siliconflow`,value:d.provider,onChange:e=>g(`provider`,e.target.value),pattern:`[A-Za-z0-9][A-Za-z0-9_-]*`})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`模型名称`}),(0,P.jsx)(`input`,{required:!0,maxLength:256,placeholder:`例如 qwen3-coder`,value:d.model,onChange:e=>g(`model`,e.target.value)})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`接口协议`}),(0,P.jsxs)(`select`,{value:d.protocol,onChange:e=>g(`protocol`,e.target.value),children:[(0,P.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI 兼容 API`}),(0,P.jsx)(`option`,{value:`anthropic`,children:`Anthropic API`})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`Base URL`}),(0,P.jsx)(`input`,{required:!0,type:`url`,maxLength:2048,placeholder:`https://api.example.com/v1`,value:d.baseURL,onChange:e=>g(`baseURL`,e.target.value)})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`API Key`}),(0,P.jsx)(`input`,{required:!0,type:`password`,autoComplete:`off`,maxLength:16384,placeholder:`输入服务密钥`,value:d.apiKey,onChange:e=>g(`apiKey`,e.target.value)})]}),(0,P.jsxs)(`p`,{className:`model-security-note`,children:[(0,P.jsx)(`span`,{children:`◆`}),` 配置同步到当前项目,密钥只加密保存在本机。保存后会新建会话。`]}),l!==void 0&&(0,P.jsx)(`p`,{className:`model-form-error`,role:`alert`,children:l}),(0,P.jsxs)(`div`,{className:`model-form-actions`,children:[(0,P.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),u(void 0)},disabled:s,children:`取消`}),(0,P.jsx)(`button`,{type:`submit`,className:`primary`,disabled:s||n,children:s?`正在连接…`:`保存并切换`})]})]}):(0,P.jsx)(`div`,{className:`model-options`,role:`listbox`,"aria-label":`主模型`,children:e.map(e=>{let t=p===e.id;return(0,P.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,className:`model-option`,disabled:n||t,onClick:t=>{r(e.id),t.currentTarget.closest(`details`)?.removeAttribute(`open`)},children:[(0,P.jsxs)(`span`,{className:`model-option-copy`,children:[(0,P.jsx)(`strong`,{children:e.label}),(0,P.jsx)(`small`,{children:e.description})]}),e.source===`custom`&&(0,P.jsx)(`span`,{className:`model-option-badge`,children:`自定义`}),(0,P.jsx)(`span`,{className:`model-option-state`,"aria-hidden":`true`,children:t?`✓`:`→`})]},e.id)})})]})]})}function Af(e){let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString(`zh-CN`,{hour:`2-digit`,minute:`2-digit`})}var jf=document.getElementById(`root`);if(jf===null)throw Error(`Desktop root element was not found`);(0,v.createRoot)(jf).render((0,P.jsx)(_.StrictMode,{children:(0,P.jsx)(Jd,{})}));export{c as i,Xt as n,u as r,ld as t};
150
+ `);if(n.at(-1)===``&&n.pop(),t&&!n.some(e=>e.startsWith(`@@`)))return n.map((e,t)=>({kind:`addition`,marker:`+`,text:e,newNumber:t+1}));let r=0,i=0,a=!1;return n.map(e=>{let t=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/.exec(e);if(t!==null)return r=Number(t[1]),i=Number(t[2]),a=!0,{kind:`hunk`,marker:`@@`,text:t[3]?.trim()??``};if(!a||e.startsWith(`diff --git`)||e.startsWith(`index `)||e.startsWith(`--- `)||e.startsWith(`+++ `))return{kind:`meta`,marker:``,text:e};if(e.startsWith(`+`)&&!e.startsWith(`+++`))return{kind:`addition`,marker:`+`,text:e.slice(1),newNumber:i++};if(e.startsWith(`-`)&&!e.startsWith(`---`))return{kind:`deletion`,marker:`−`,text:e.slice(1),oldNumber:r++};if(e.startsWith(`\\ No newline`))return{kind:`meta`,marker:``,text:e};let n={kind:`context`,marker:``,text:e.startsWith(` `)?e.slice(1):e,oldNumber:r,newNumber:i};return r+=1,i+=1,n})}function ed({onClose:e,onReview:t,onError:n}){let[r,i]=(0,_.useState)(Qu),[a,o]=(0,_.useState)(),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(`working`),[d,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),v=(0,_.useMemo)(()=>$u(s,a?.untracked),[s,a?.untracked]),y=v.filter(e=>e.kind===`addition`).length,b=v.filter(e=>e.kind===`deletion`).length,x=r.files.filter(e=>e.staged).length,S=async()=>{try{i(await window.flavorDesktop.gitStatus())}catch(e){n(nd(e))}finally{f(!1)}};(0,_.useEffect)(()=>{S()},[]);let C=async(e,t)=>{m(!0),c(``),u(t);try{c(await window.flavorDesktop.gitDiff(e.path,t===`staged`))}catch(e){let t=nd(e);c(t),n(t)}finally{m(!1)}},w=async e=>{o(e),await C(e,e.unstaged||e.untracked?`working`:`staged`)},ee=async(e,t)=>{if(!(e===`discard`&&!window.confirm(`确定还原 ${t.path}?此操作无法撤销。`)))try{let n=e===`stage`?await window.flavorDesktop.gitStage(t.path):e===`unstage`?await window.flavorDesktop.gitUnstage(t.path):await window.flavorDesktop.gitDiscard(t.path);i(n);let r=n.files.find(e=>e.path===t.path);r===void 0?(o(void 0),c(``)):(o(r),await C(r,r.unstaged||r.untracked?`working`:`staged`))}catch(e){n(nd(e))}},te=async()=>{if(h.trim())try{let e=await window.flavorDesktop.gitCommit(h.trim());i(e.status),g(``),o(void 0),c(``),n(`已提交 ${e.result}`)}catch(e){n(nd(e))}};return(0,P.jsxs)(`section`,{className:`manager-view git-view`,children:[(0,P.jsxs)(`header`,{className:`manager-header git-header`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{className:`git-back`,onClick:e,"aria-label":`返回`,children:`←`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h2`,{children:`Git 变更`}),(0,P.jsx)(`span`,{children:`审阅并整理本次工作区修改`})]})]}),r.repository&&(0,P.jsxs)(`span`,{className:`git-branch`,children:[(0,P.jsx)(`i`,{}),r.branch,(0,P.jsx)(`b`,{children:r.head})]})]}),d?(0,P.jsx)(`p`,{className:`manager-empty`,children:`正在读取工作区…`}):r.repository?(0,P.jsxs)(`div`,{className:`git-layout`,children:[(0,P.jsxs)(`aside`,{className:`git-files`,children:[(0,P.jsxs)(`div`,{className:`git-toolbar`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`变更`}),(0,P.jsx)(`span`,{children:r.files.length})]}),(0,P.jsx)(`button`,{onClick:()=>void S(),title:`重新读取变更`,children:`↻`})]}),r.files.length===0?(0,P.jsxs)(`div`,{className:`git-clean`,children:[(0,P.jsx)(`i`,{children:`✓`}),(0,P.jsx)(`strong`,{children:`工作区干净`}),(0,P.jsx)(`span`,{children:`没有需要审阅的修改`})]}):r.files.map(e=>{let t=td(e.path),n=e.untracked?`U`:e.index===`A`?`A`:e.index===`D`||e.worktree===`D`?`D`:`M`;return(0,P.jsxs)(`div`,{className:`git-file-row`,"data-active":a?.path===e.path,children:[(0,P.jsxs)(`button`,{className:`git-file-name`,onClick:()=>void w(e),title:e.path,children:[(0,P.jsx)(`code`,{"data-state":n,children:n}),(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`b`,{children:t.name}),t.directory&&(0,P.jsx)(`small`,{children:t.directory})]})]}),(0,P.jsxs)(`div`,{className:`git-file-actions`,children:[e.staged?(0,P.jsx)(`button`,{onClick:()=>void ee(`unstage`,e),children:`取消暂存`}):(0,P.jsx)(`button`,{className:`stage-action`,onClick:()=>void ee(`stage`,e),children:`暂存`}),(e.unstaged||e.untracked)&&(0,P.jsx)(`button`,{className:`danger-text`,onClick:()=>void ee(`discard`,e),children:`还原`})]})]},e.path)})]}),(0,P.jsx)(`article`,{className:`git-diff`,children:a===void 0?(0,P.jsxs)(`div`,{className:`git-diff-empty`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`span`,{children:`−`}),(0,P.jsx)(`span`,{children:`+`})]}),(0,P.jsx)(`strong`,{children:`选择文件查看差异`}),(0,P.jsx)(`p`,{children:`逐行审阅修改,然后决定暂存或还原。`})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`header`,{className:`git-diff-header`,children:[(0,P.jsxs)(`div`,{className:`git-diff-title`,children:[(0,P.jsx)(`span`,{children:td(a.path).directory||`项目根目录`}),(0,P.jsx)(`strong`,{children:td(a.path).name})]}),(0,P.jsxs)(`div`,{className:`git-diff-controls`,children:[a.staged&&a.unstaged&&(0,P.jsxs)(`div`,{className:`git-layer-switch`,children:[(0,P.jsx)(`button`,{"data-active":l===`working`,onClick:()=>void C(a,`working`),children:`工作区`}),(0,P.jsx)(`button`,{"data-active":l===`staged`,onClick:()=>void C(a,`staged`),children:`已暂存`})]}),!p&&(0,P.jsxs)(`div`,{className:`git-diff-stats`,children:[(0,P.jsxs)(`span`,{className:`add`,children:[`+`,y]}),(0,P.jsxs)(`span`,{className:`del`,children:[`−`,b]})]})]})]}),(0,P.jsx)(`div`,{className:`git-code`,"aria-label":`${a.path} 差异`,children:p?(0,P.jsxs)(`div`,{className:`git-diff-loading`,children:[(0,P.jsx)(`i`,{}),`正在生成差异…`]}):v.map((e,t)=>(0,P.jsxs)(`div`,{className:`git-code-line`,"data-kind":e.kind,children:[(0,P.jsx)(`span`,{className:`old-line`,children:e.oldNumber??``}),(0,P.jsx)(`span`,{className:`new-line`,children:e.newNumber??``}),(0,P.jsx)(`span`,{className:`change-marker`,children:e.marker}),(0,P.jsx)(`code`,{children:e.text||` `})]},`${t}-${e.oldNumber??``}-${e.newNumber??``}`))})]})})]}):(0,P.jsx)(`p`,{className:`manager-empty`,children:`当前项目不是 Git 仓库`}),r.repository&&(0,P.jsxs)(`footer`,{className:`git-footer`,children:[(0,P.jsx)(`button`,{className:`review-action`,onClick:t,children:`交给 /review`}),(0,P.jsxs)(`div`,{className:`commit-field`,children:[(0,P.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),placeholder:x>0?`描述这次提交…`:`暂存文件后即可提交`}),(0,P.jsxs)(`span`,{children:[x,` 个文件已暂存`]})]}),(0,P.jsx)(`button`,{className:`commit-action`,disabled:!h.trim()||x===0,onClick:()=>void te(),children:`提交`})]})]})}function td(e){let t=e.replace(/\\/g,`/`),n=t.lastIndexOf(`/`);return n<0?{name:t,directory:``}:{name:t.slice(n+1),directory:t.slice(0,n)}}function nd(e){return e instanceof Error?e.message:String(e)}function rd(e){let t=[],n,r=()=>{if(n===void 0)return;let e=n.lines.length,r=n.hunks.map((t,r)=>({...t,end:n.hunks[r+1]?.start??e}));t.push({...n,hunks:r})};for(let t of e.split(/\r?\n/)){let e=/^diff --(?:git|flavor) a\/(.+?) b\/(.+)$/.exec(t);if(e!==null){r(),n={path:e[2],lines:[t],hunks:[],additions:0,deletions:0};continue}if(n===void 0)continue;let i=n.lines.length;n.lines.push(t),t.startsWith(`@@`)?n.hunks.push({id:`${n.path}:${n.hunks.length+1}`,header:t,start:i,end:i+1}):t.startsWith(`+`)&&!t.startsWith(`+++`)?n.additions+=1:t.startsWith(`-`)&&!t.startsWith(`---`)&&(n.deletions+=1)}return r(),t}function id(e){return Math.min(2.4,Math.max(.55,e))}function ad(e,t,n){let r=id(n),i=r/e.scale;return{x:t.x-(t.x-e.x)*i,y:t.y-(t.y-e.y)*i,scale:r}}function od(e,t,n){return{x:Math.round(t.x+e.x*n.width*t.scale/100),y:Math.round(t.y+e.y*n.height*t.scale/100)}}function sd(e,t){let n=new Map,r=[];n.set(e.id,{...e,role:`origin`,x:50,y:50});let i=(t,i,a)=>{t.slice(0,8).forEach((t,o,s)=>{n.set(t.id,{...t,role:i,x:a,y:(o+1)*100/(s.length+1)}),r.push(i===`caller`?{from:t.id,to:e.id,kind:i}:{from:e.id,to:t.id,kind:i})})};i(t.callers,`caller`,14),i(t.callees,`callee`,86);let a=t.impact.filter(e=>!n.has(e.id)).slice(0,12),o=Math.ceil(a.length/2);return a.forEach((t,i)=>{let s=i<o,c=s?i:i-o,l=s?o:a.length-o,u=Math.floor(c/3),d=c%3,f=Math.min(3,l-u*3),p=(d+1)*100/(f+1),m=s?13+u*11:87-u*11;n.set(t.id,{...t,role:`impact`,x:p,y:m,hop:t.hop}),r.push({from:e.id,to:t.id,kind:`impact`,hop:t.hop})}),{nodes:[...n.values()],edges:r}}function cd(e){let t=new Map(e.map(e=>[e.id,e]));return e.map(e=>{let n=0,r=e.parentId,i=new Set([e.id]);for(;r!==null&&n<12&&!i.has(r);){i.add(r);let e=t.get(r);if(e===void 0)break;n+=1,r=e.parentId}return{node:e,depth:n}})}function ld(e){return e.replaceAll(`\\`,`/`).split(`/`).filter(Boolean).at(-1)??e}function ud(e,t){let n=t.filter(e=>e.state!==`closed`);return e!==void 0&&n.some(t=>t.id===e)?e:n.find(e=>e.state===`running`)?.id??n[0]?.id}var dd=`modulepreload`,fd=function(e,t){return new URL(e,t).href},pd={},md=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=fd(t,n),t=s(t),t in pd)return;pd[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:dd,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},hd=[{id:`cockpit`,label:`执行`},{id:`timeline`,label:`时间机`},{id:`terminal`,label:`终端`},{id:`review`,label:`审查`},{id:`preview`,label:`预览`},{id:`context`,label:`上下文`},{id:`ast`,label:`代码图`},{id:`pals`,label:`Pals`},{id:`worktrees`,label:`工作树`}],gd=_.lazy(()=>md(()=>import(`./interactive-terminal-Bn8G5Pig.js`),[],import.meta.url));function _d({snapshot:e,onClose:t,onError:n,onCompose:r}){let[i,a]=(0,_.useState)(`cockpit`),[o,s]=(0,_.useState)(()=>Ad(e.jobs.map(e=>e.label).join(`
151
+ `))),c=(0,_.useRef)(new Map),l=e=>s(t=>[...new Set([...t,...Ad(e)])].slice(-20));return(0,_.useEffect)(()=>{let t=!1;return Promise.all(e.jobs.map(async e=>{let n=await window.flavorDesktop.readJob(e.id,c.current.get(e.id)??0).catch(()=>void 0);n===void 0||t||(c.current.set(e.id,n.cursor),l(n.output))})),()=>{t=!0}},[e.jobs]),(0,P.jsxs)(`section`,{className:`agent-workbench manager-view`,children:[(0,P.jsxs)(`header`,{className:`manager-header workbench-header`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{onClick:t,children:`‹`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`FLAVOR DESKTOP 1.3.4`}),(0,P.jsx)(`h2`,{children:`Agent 工作台`})]})]}),(0,P.jsx)(`span`,{children:e.activeSession?.environment===`worktree`?`隔离工作树`:`本地检出`})]}),(0,P.jsx)(`nav`,{className:`workbench-tabs`,"aria-label":`工作台功能`,children:hd.map(e=>(0,P.jsx)(`button`,{"data-active":i===e.id,onClick:()=>a(e.id),children:e.label},e.id))}),(0,P.jsxs)(`div`,{className:`workbench-stage`,children:[i===`cockpit`&&(0,P.jsx)(vd,{snapshot:e,onCompose:r}),i===`timeline`&&(0,P.jsx)($,{onError:n}),i===`terminal`&&(0,P.jsx)(yd,{onError:n,onDiscover:l}),i===`review`&&(0,P.jsx)(bd,{onError:n,onCompose:r}),i===`preview`&&(0,P.jsx)(Sd,{onError:n,suggestions:o}),i===`context`&&(0,P.jsx)(Cd,{snapshot:e,onError:n}),i===`ast`&&(0,P.jsx)(wd,{onError:n,onCompose:r}),i===`pals`&&(0,P.jsx)(Dd,{onError:n}),i===`worktrees`&&(0,P.jsx)(Od,{snapshot:e,onError:n})]})]})}function vd({snapshot:e,onCompose:t}){let[n,r]=(0,_.useState)(),[i,a]=(0,_.useState)(``);(0,_.useEffect)(()=>{window.flavorDesktop.inspectWorkbench().then(r).catch(()=>void 0)},[e.activeSession?.sessionId]);let o=n?.goals[0];(0,_.useEffect)(()=>{o!==void 0&&a(o.objective)},[o?.id]);let s=e.tasks?.plan?.tasks??[],c=Object.entries(e.tasks?.subagents.states??{});return(0,P.jsxs)(`div`,{className:`cockpit-grid`,children:[(0,P.jsxs)(`section`,{className:`cockpit-trace`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`EXECUTION TRACE`}),(0,P.jsx)(`h3`,{children:o?.objective??`当前会话尚未启动持久目标`})]}),(0,P.jsx)(`ol`,{children:s.length===0?(0,P.jsxs)(`li`,{"data-state":`pending`,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`等待执行计划`}),(0,P.jsx)(`small`,{children:`TaskPlan 出现后会自动同步`})]})]}):s.map(e=>(0,P.jsxs)(`li`,{"data-state":e.status,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:e.subject}),(0,P.jsxs)(`small`,{children:[e.status,e.result?` · ${e.result}`:``]})]})]},e.id))})]}),(0,P.jsxs)(`aside`,{className:`cockpit-evidence`,children:[(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`目标状态`}),(0,P.jsx)(`b`,{"data-phase":o?.phase,children:o?.phase??`idle`}),(0,P.jsx)(`p`,{children:o?`${o.status} · worker ${o.workerRounds} · verify ${o.verifyRounds}`:`使用 /goal 启动带验证的长期任务`}),o&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`textarea`,{className:`cockpit-goal-editor`,value:i,onChange:e=>a(e.target.value),"aria-label":`继续目标`}),(0,P.jsxs)(`div`,{className:`cockpit-goal-actions`,children:[e.activeSession?.busy&&(0,P.jsx)(`button`,{onClick:()=>void window.flavorDesktop.interrupt(),children:`安全暂停`}),(0,P.jsx)(`button`,{disabled:!i.trim(),onClick:()=>t(`/goal ${i.trim()}`),children:`以编辑目标继续`})]})]})]}),(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`协作 Agent`}),c.length===0?(0,P.jsx)(`p`,{children:`没有活跃子 Agent`}):c.map(([e,t])=>(0,P.jsxs)(`div`,{className:`cockpit-row`,children:[(0,P.jsx)(`code`,{children:e}),(0,P.jsx)(`span`,{"data-state":t,children:t})]},e))]}),(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`后台作业`}),e.jobs.length===0?(0,P.jsx)(`p`,{children:`没有后台作业`}):e.jobs.map(e=>(0,P.jsxs)(`div`,{className:`cockpit-row`,children:[(0,P.jsx)(`code`,{children:e.label}),(0,P.jsx)(`span`,{"data-state":e.state,children:e.state})]},e.id))]}),o&&o.evidenceRounds.length>0&&(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`验证证据`}),o.evidenceRounds.slice(-3).reverse().map(e=>(0,P.jsxs)(`div`,{className:`cockpit-evidence-round`,children:[(0,P.jsxs)(`b`,{children:[`ROUND `,e.round]}),(0,P.jsx)(`p`,{children:e.hostVerification?.summary??`workspace ${e.workspaceDiffHash.slice(0,10)}`}),(0,P.jsx)(`span`,{"data-passed":e.hostVerification?.passed,children:e.hostVerification===void 0?`workspace evidence`:e.hostVerification.passed?`passed`:`failed`})]},e.round))]}),o&&o.lastGaps.length>0&&(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`small`,{children:`验证缺口`}),o.lastGaps.map((e,t)=>(0,P.jsx)(`p`,{className:`cockpit-gap`,children:e.description},t))]})]})]})}function $({onError:e}){let[t,n]=(0,_.useState)({leafId:null,nodes:[]}),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(!1),s=()=>window.flavorDesktop.historySnapshot().then(n).catch(t=>e(kd(t)));(0,_.useEffect)(()=>{s()},[]);let c=async t=>{o(!0);try{await t(),await s()}catch(t){e(kd(t))}finally{o(!1)}},l=cd(t.nodes);return(0,P.jsxs)(`div`,{className:`timeline-layout`,children:[(0,P.jsxs)(`section`,{className:`timeline-canvas`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`SESSION TREE`}),(0,P.jsxs)(`h3`,{children:[t.nodes.length,` 个可恢复节点`]})]}),(0,P.jsx)(`ol`,{children:l.map(({node:e,depth:n})=>(0,P.jsxs)(`li`,{className:`timeline-node`,style:{paddingLeft:n*26},"data-depth":n,"data-current":e.id===t.leafId,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:e.prompt||e.id}),(0,P.jsxs)(`small`,{children:[new Date(e.createdAt).toLocaleString(),` · `,e.checkpointId]})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{disabled:a,onClick:()=>void c(()=>window.flavorDesktop.rewindHistory(e.id)),children:`回到这里`}),(0,P.jsx)(`button`,{disabled:a,onClick:()=>{window.confirm(`从这个节点建立新分支?当前上下文将切换。`)&&c(()=>window.flavorDesktop.forkHistory(e.id))},children:`Fork`})]})]},e.id))})]}),(0,P.jsxs)(`aside`,{className:`timeline-actions`,children:[(0,P.jsx)(`h3`,{children:`建立安全点`}),(0,P.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`例如:重构前`}),(0,P.jsx)(`button`,{disabled:a,onClick:()=>void c(()=>window.flavorDesktop.createCheckpoint(r||void 0)),children:`创建 checkpoint`}),(0,P.jsx)(`button`,{disabled:a,onClick:()=>void c(()=>window.flavorDesktop.unrevertHistory()),children:`撤销上次回退`})]})]})}function yd({onError:e,onDiscover:t}){let[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(),o=n.find(e=>e.id===i),s=(e,t)=>{let n=e.filter(e=>e.state!==`closed`);r(n),a(e=>ud(t??e,n))},c=async e=>s(await window.flavorDesktop.listTerminals(),e);(0,_.useEffect)(()=>{c().catch(t=>e(kd(t)))},[]);let l=async()=>{try{let e=await window.flavorDesktop.openTerminal();await c(e.id)}catch(t){e(kd(t))}},u=async()=>{if(i!==void 0)try{await window.flavorDesktop.closeTerminal(i),await c()}catch(t){e(kd(t))}};return(0,P.jsxs)(`div`,{className:`terminal-layout`,children:[(0,P.jsxs)(`aside`,{children:[(0,P.jsx)(`button`,{className:`primary`,onClick:()=>void l(),children:`+ 新终端`}),n.map(e=>(0,P.jsxs)(`button`,{"data-active":e.id===i,onClick:()=>a(e.id),title:e.shell,children:[(0,P.jsx)(`strong`,{children:ld(e.shell)}),(0,P.jsxs)(`small`,{children:[e.state,` · `,e.id]})]},e.id))]}),(0,P.jsxs)(`main`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`span`,{title:o?.cwd,children:o?.cwd??`尚未打开终端`}),o&&(0,P.jsx)(`button`,{onClick:()=>void u(),children:`关闭终端`})]}),o===void 0?(0,P.jsxs)(`div`,{className:`terminal-empty`,children:[(0,P.jsx)(`b`,{children:`没有打开终端`}),(0,P.jsx)(`span`,{children:`新建终端后,直接在终端区域输入和操作。`})]}):(0,P.jsx)(_.Suspense,{fallback:(0,P.jsxs)(`div`,{className:`terminal-empty`,children:[(0,P.jsx)(`b`,{children:`正在连接终端`}),(0,P.jsx)(`span`,{children:`正在加载交互渲染器…`})]}),children:(0,P.jsx)(gd,{terminal:o,onError:e,onDiscover:t},o.id)})]})]})}function bd({onError:e,onCompose:t}){let[n,r]=(0,_.useState)(`working`),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)(),m=(0,_.useMemo)(()=>rd(o),[o]),h=m.find(e=>e.path===u)??m[0],g=async()=>{l(!0);try{let e=await window.flavorDesktop.gitReview(n,i||void 0);s(e);let t=rd(e);d(t[0]?.path),p(t[0]?.hunks[0]?.id)}catch(t){e(kd(t))}finally{l(!1)}};return(0,_.useEffect)(()=>{if(n===`commit`||n===`base`){s(``),d(void 0),p(void 0);return}g()},[n]),(0,P.jsxs)(`div`,{className:`review-layout`,children:[(0,P.jsxs)(`aside`,{className:`review-scope`,children:[(0,P.jsx)(`small`,{children:`DIFF SCOPE`}),[`working`,`staged`,`last-turn`,`commit`,`base`].map(e=>(0,P.jsx)(`button`,{"data-active":n===e,onClick:()=>r(e),children:e},e)),(n===`commit`||n===`base`)&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:n===`base`?`main / origin/main`:`commit SHA`}),(0,P.jsx)(`button`,{onClick:()=>void g(),children:`载入范围`})]})]}),(0,P.jsxs)(`section`,{className:`review-files`,"aria-label":`变更文件`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`strong`,{children:`文件`}),(0,P.jsx)(`span`,{children:m.length})]}),m.map(e=>(0,P.jsxs)(`button`,{"data-active":e.path===h?.path,onClick:()=>{d(e.path),p(e.hunks[0]?.id)},children:[(0,P.jsx)(`strong`,{children:e.path.split(`/`).at(-1)}),(0,P.jsx)(`small`,{children:e.path}),(0,P.jsxs)(`span`,{children:[(0,P.jsxs)(`b`,{children:[`+`,e.additions]}),(0,P.jsxs)(`em`,{children:[`-`,e.deletions]})]})]},e.path))]}),(0,P.jsxs)(`main`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:h?.path??n}),(0,P.jsxs)(`span`,{children:[h?.hunks.length??0,` hunks`]})]}),(0,P.jsx)(`button`,{onClick:()=>t(`/review 请审查 ${n}${i?` ${i}`:``}${h?` 中的 ${h.path}`:``},按 P0/P1/P2 分级输出发现,必须给出文件行号和触发场景。`),children:`交给 Agent 审查`})]}),h&&h.hunks.length>0&&(0,P.jsx)(`nav`,{className:`review-hunks`,"aria-label":`Hunk 导航`,children:h.hunks.map((e,t)=>(0,P.jsxs)(`button`,{"data-active":f===e.id,onClick:()=>p(e.id),children:[`H`,t+1,(0,P.jsx)(`span`,{children:e.header})]},e.id))}),(0,P.jsx)(xd,{file:h,activeHunk:f,loading:c,empty:o}),(0,P.jsxs)(`footer`,{className:`review-priority-legend`,children:[(0,P.jsx)(`span`,{"data-priority":`0`,children:`P0 阻断`}),(0,P.jsx)(`span`,{"data-priority":`1`,children:`P1 高风险`}),(0,P.jsx)(`span`,{"data-priority":`2`,children:`P2 一般`}),(0,P.jsx)(`small`,{children:`审查结果将在对话中返回,并携带文件行号。`})]})]})]})}function xd({file:e,activeHunk:t,loading:n,empty:r}){return n?(0,P.jsx)(`div`,{className:`review-empty`,children:`正在生成 diff…`}):e===void 0?(0,P.jsx)(`div`,{className:`review-empty`,children:r||`此范围没有差异`}):(0,P.jsx)(`div`,{className:`review-code`,role:`region`,"aria-label":`${e.path} 差异`,children:(0,P.jsx)(`pre`,{children:e.lines.map((n,r)=>{let i=e.hunks.find(e=>r>=e.start&&r<e.end);return(0,P.jsx)(`code`,{"data-kind":n.startsWith(`+++`)||n.startsWith(`---`)?`meta`:n.startsWith(`+`)?`addition`:n.startsWith(`-`)?`deletion`:n.startsWith(`@@`)?`hunk`:`context`,"data-active":i?.id===t,children:n||` `},r)})})})}function Sd({onError:e,suggestions:t}){let[n,r]=(0,_.useState)(`http://localhost:3000`),[i,a]=(0,_.useState)(),[o,s]=(0,_.useState)(0),c=async()=>{try{a(await window.flavorDesktop.validatePreviewUrl(n))}catch(t){e(kd(t))}};return(0,P.jsxs)(`div`,{className:`preview-layout`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()}}),(0,P.jsx)(`button`,{onClick:()=>void c(),children:`打开`}),(0,P.jsx)(`button`,{disabled:!i,onClick:()=>s(e=>e+1),children:`刷新`}),(0,P.jsx)(`button`,{disabled:!i,onClick:()=>{i&&window.flavorDesktop.openPreviewUrl(i)},children:`外部打开`}),(0,P.jsx)(`button`,{disabled:!i,onClick:()=>{i&&navigator.clipboard.writeText(i)},children:`复制`})]}),t.length>0&&(0,P.jsxs)(`div`,{className:`preview-suggestions`,children:[`检测到:`,t.map(t=>(0,P.jsx)(`button`,{onClick:()=>{r(t),window.flavorDesktop.validatePreviewUrl(t).then(a).catch(t=>e(kd(t)))},children:t},t))]}),i?(0,P.jsx)(`iframe`,{src:i,title:`本地应用预览`,sandbox:`allow-forms allow-modals allow-popups allow-scripts allow-same-origin`},o):(0,P.jsxs)(`div`,{className:`preview-empty`,children:[(0,P.jsx)(`strong`,{children:`安全的本地预览`}),(0,P.jsx)(`p`,{children:`仅允许 localhost、127.0.0.1 和 ::1 的 HTTP(S) 地址。`})]})]})}function Cd({snapshot:e,onError:t}){let[n,r]=(0,_.useState)();return(0,_.useEffect)(()=>{window.flavorDesktop.inspectWorkbench().then(r).catch(e=>t(kd(e)))},[]),(0,P.jsxs)(`div`,{className:`context-grid`,children:[(0,P.jsxs)(`section`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`RUNTIME`}),(0,P.jsx)(`h3`,{children:`上下文 Epoch`})]}),(0,P.jsxs)(`dl`,{children:[(0,P.jsx)(`dt`,{children:`Permission`}),(0,P.jsx)(`dd`,{children:e.activeSession?.permissionMode??`—`}),(0,P.jsx)(`dt`,{children:`Model`}),(0,P.jsx)(`dd`,{children:e.activeSession?.mainModel??`—`}),(0,P.jsx)(`dt`,{children:`Checkout`}),(0,P.jsx)(`dd`,{children:e.activeSession?.workingDirectory??e.workspace??`—`})]}),n?.context?.epoch!==void 0&&(0,P.jsx)(`pre`,{className:`context-record`,children:JSON.stringify(n.context.epoch,null,2)}),n?.context?.visibility.map((e,t)=>(0,P.jsx)(`pre`,{className:`context-record`,children:JSON.stringify(e,null,2)},t)),n?.context?.usage.map((e,t)=>(0,P.jsx)(`pre`,{className:`context-record`,children:JSON.stringify(e,null,2)},`usage-${t}`)),e.diagnostics.map((e,t)=>(0,P.jsx)(`p`,{className:`context-record`,children:e},`diag-${t}`))]}),(0,P.jsxs)(`section`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`INSTRUCTIONS`}),(0,P.jsx)(`h3`,{children:`生效的项目指令`})]}),n?.instructions.map(e=>(0,P.jsxs)(`details`,{children:[(0,P.jsx)(`summary`,{children:e.name}),(0,P.jsx)(`pre`,{children:e.content})]},e.path))]}),(0,P.jsxs)(`section`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`small`,{children:`SAFETY`}),(0,P.jsx)(`h3`,{children:`权限规则与审计`})]}),n?.permissionFiles.map(e=>(0,P.jsxs)(`details`,{children:[(0,P.jsxs)(`summary`,{children:[e.tier,` · `,e.path]}),(0,P.jsx)(`pre`,{children:e.content})]},e.path)),n?.audit.slice(0,30).map((e,t)=>(0,P.jsx)(`pre`,{className:`context-record`,children:JSON.stringify(e,null,2)},t))]})]})}function wd({onError:e,onCompose:t}){let[n,r]=(0,_.useState)(),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)(2),[m,h]=(0,_.useState)(!1);(0,_.useEffect)(()=>{window.flavorDesktop.astStatus().then(r).catch(t=>e(kd(t)))},[]);let g=async()=>{try{s(await window.flavorDesktop.astSearch(i))}catch(t){e(kd(t))}},v=async(t,n=f)=>{l(t),h(!0);try{d(await window.flavorDesktop.astRelations(t.id,n))}catch(t){e(kd(t))}finally{h(!1)}},y=c===void 0||u===void 0?void 0:sd(c,u);return(0,P.jsxs)(`div`,{className:`ast-layout`,children:[(0,P.jsxs)(`aside`,{className:`ast-symbols`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`SYMBOL INDEX`}),(0,P.jsx)(`strong`,{children:`代码索引`})]}),(0,P.jsx)(`span`,{"data-ready":n?.available,children:n?.available?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`b`,{children:n.nodes}),` symbols`,(0,P.jsx)(`br`,{}),(0,P.jsx)(`b`,{children:n.edges}),` edges`]}):`尚未建立索引`})]}),(0,P.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g()},children:[(0,P.jsx)(`span`,{"aria-hidden":`true`,children:`⌕`}),(0,P.jsx)(`input`,{"aria-label":`搜索代码符号`,value:i,onChange:e=>a(e.target.value),placeholder:`函数、类型或模块`}),(0,P.jsx)(`button`,{children:`搜索`})]}),(0,P.jsx)(`div`,{className:`ast-symbol-list`,children:o.length===0?(0,P.jsx)(`p`,{children:n?.available===!1?`项目尚未建立代码索引`:`输入名称,定位代码中的关键符号`}):o.map(e=>(0,P.jsxs)(`button`,{"data-active":e.id===c?.id,onClick:()=>void v(e),children:[(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:e.name}),(0,P.jsx)(`em`,{children:e.kind})]}),(0,P.jsxs)(`small`,{children:[e.filePath,`:`,e.startLine]})]},e.id))})]}),(0,P.jsxs)(`main`,{className:`ast-graph-stage`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`RELATION MAP`}),(0,P.jsx)(`h3`,{children:c?.qualifiedName??`代码关系浏览器`}),(0,P.jsx)(`code`,{children:c?`${c.filePath}:${c.startLine}-${c.endLine}`:`搜索并选择一个符号作为图中心`})]}),(0,P.jsxs)(`div`,{className:`ast-depth`,"aria-label":`影响深度`,children:[(0,P.jsx)(`span`,{children:`影响深度`}),[1,2,3,4].map(e=>(0,P.jsx)(`button`,{"aria-label":`${e} 层影响深度`,"data-active":f===e,onClick:()=>{p(e),c&&v(c,e)},children:e},e))]})]}),m?(0,P.jsx)(`div`,{className:`ast-graph-empty`,children:`正在展开关系图…`}):y?(0,P.jsx)(Td,{graph:y,selected:c,onSelect:e=>void v(e)}):(0,P.jsxs)(`div`,{className:`ast-graph-empty`,children:[(0,P.jsx)(`strong`,{children:`从一个符号开始`}),(0,P.jsx)(`p`,{children:`搜索函数、类或模块,在同一张图上查看调用者、被调用项和多跳影响范围。`})]})]}),(0,P.jsxs)(`aside`,{className:`ast-inspector`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`SYMBOL INSPECTOR`}),(0,P.jsx)(`h3`,{children:c?.name??`未选择符号`})]}),c&&(0,P.jsx)(`span`,{children:c.kind})]}),c?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`dl`,{children:[(0,P.jsx)(`dt`,{children:`语言`}),(0,P.jsx)(`dd`,{children:c.language}),(0,P.jsx)(`dt`,{children:`位置`}),(0,P.jsxs)(`dd`,{children:[c.filePath,`:`,c.startLine]}),c.signature&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`dt`,{children:`签名`}),(0,P.jsx)(`dd`,{children:c.signature})]})]}),(0,P.jsxs)(`button`,{className:`ast-compose`,onClick:()=>t(`请查看 @${c.filePath}#L${c.startLine}-L${c.endLine} 中的 ${c.qualifiedName}`),children:[(0,P.jsx)(`span`,{children:`加入输入框`}),(0,P.jsx)(`b`,{"aria-hidden":`true`,children:`↗`})]}),(0,P.jsx)(Ed,{title:`Callers`,nodes:u?.callers??[],onSelect:e=>void v(e)}),(0,P.jsx)(Ed,{title:`Callees`,nodes:u?.callees??[],onSelect:e=>void v(e)}),(0,P.jsx)(Ed,{title:`Impact`,nodes:u?.impact??[],onSelect:e=>void v(e)})]}):(0,P.jsx)(`p`,{className:`ast-inspector-empty`,children:`选择一个符号后,这里会显示源码位置和完整关系。`})]})]})}function Td({graph:e,selected:t,onSelect:n}){let r={x:0,y:0,scale:1},[i,a]=(0,_.useState)(r),[o,s]=(0,_.useState)({width:0,height:0}),[c,l]=(0,_.useState)(!1),u=(0,_.useRef)(null),d=(0,_.useRef)(void 0),f=new Map(e.nodes.map(e=>[e.id,e]));(0,_.useEffect)(()=>{a(r)},[t.id]),(0,_.useEffect)(()=>{let e=u.current;if(e===null)return;let t=()=>{let t=e.getBoundingClientRect();s({width:t.width,height:t.height})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let p=(e,t)=>{let n=u.current?.getBoundingClientRect(),r=t??{x:(n?.width??0)/2,y:(n?.height??0)/2};a(t=>ad(t,r,e))},m=e=>{d.current?.pointerId===e.pointerId&&(d.current=void 0,l(!1),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))};return(0,P.jsxs)(`div`,{ref:u,className:`ast-graph`,"data-dragging":c,role:`region`,"aria-label":`${t.name} 代码关系图,可拖动和滚轮缩放`,onWheel:e=>{e.preventDefault();let t=e.currentTarget.getBoundingClientRect();p(i.scale*Math.exp(-e.deltaY*.0014),{x:e.clientX-t.left,y:e.clientY-t.top})},onPointerDown:e=>{e.button!==0||e.target.closest(`button`)||(e.currentTarget.setPointerCapture(e.pointerId),d.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY},l(!0))},onPointerMove:e=>{let t=d.current;if(t?.pointerId!==e.pointerId)return;let n=e.clientX-t.x,r=e.clientY-t.y;d.current={...t,x:e.clientX,y:e.clientY},a(e=>({...e,x:e.x+n,y:e.y+r}))},onPointerUp:m,onPointerCancel:m,children:[(0,P.jsx)(`div`,{className:`ast-graph-viewport`,style:{transform:`translate(${i.x}px, ${i.y}px) scale(${i.scale})`},children:(0,P.jsx)(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:e.edges.map((e,t)=>{let n=f.get(e.from),r=f.get(e.to);if(!n||!r)return null;let i=(n.x+r.x)/2;return(0,P.jsx)(`path`,{"data-kind":e.kind,d:`M ${n.x} ${n.y} C ${i} ${n.y}, ${i} ${r.y}, ${r.x} ${r.y}`},`${e.from}-${e.to}-${t}`)})})}),e.nodes.map(e=>{let t=od(e,i,o);return(0,P.jsxs)(`button`,{className:`ast-graph-node`,"data-role":e.role,style:{left:t.x,top:t.y,visibility:o.width>0?`visible`:`hidden`},onClick:()=>n(e),title:`${e.qualifiedName}\n${e.filePath}:${e.startLine}`,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:e.name}),(0,P.jsx)(`small`,{children:e.role===`impact`?`hop ${e.hop}`:e.kind})]})]},e.id)}),(0,P.jsxs)(`div`,{className:`ast-graph-hint`,children:[(0,P.jsx)(`span`,{"aria-hidden":`true`,children:`↔`}),` 拖动平移 `,(0,P.jsx)(`i`,{}),` 滚轮缩放`]}),(0,P.jsxs)(`div`,{className:`ast-graph-controls`,"aria-label":`画布缩放`,children:[(0,P.jsx)(`button`,{"aria-label":`放大`,onClick:()=>p(i.scale*1.2),children:`+`}),(0,P.jsxs)(`span`,{children:[Math.round(i.scale*100),`%`]}),(0,P.jsx)(`button`,{"aria-label":`缩小`,onClick:()=>p(i.scale/1.2),children:`−`}),(0,P.jsx)(`button`,{className:`ast-graph-reset`,"aria-label":`复位画布`,onClick:()=>a(r),children:`复位`})]}),(0,P.jsxs)(`div`,{className:`ast-graph-legend`,children:[(0,P.jsx)(`span`,{"data-kind":`caller`,children:`调用者`}),(0,P.jsx)(`span`,{"data-kind":`origin`,children:`中心符号`}),(0,P.jsx)(`span`,{"data-kind":`callee`,children:`被调用`}),(0,P.jsx)(`span`,{"data-kind":`impact`,children:`影响范围`})]})]})}function Ed({title:e,nodes:t,onSelect:n}){return(0,P.jsxs)(`section`,{className:`ast-relation`,children:[(0,P.jsxs)(`h4`,{children:[e,(0,P.jsx)(`span`,{children:t.length})]}),t.length===0?(0,P.jsx)(`p`,{children:`没有关系记录`}):t.slice(0,20).map(e=>(0,P.jsxs)(`button`,{onClick:()=>n(e),children:[(0,P.jsx)(`strong`,{children:e.name}),(0,P.jsxs)(`code`,{children:[e.filePath,`:`,e.startLine]})]},e.id))]})}function Dd({onError:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(),[d,f]=(0,_.useState)(),[p,m]=(0,_.useState)(),[h,g]=(0,_.useState)(),v=()=>window.flavorDesktop.listPals().then(e=>{f(void 0),n(e),i(t=>e.some(e=>e.alias===t)?t:e[0]?.alias)}).catch(e=>{n([]),f(kd(e))});(0,_.useEffect)(()=>{v();let e=window.setInterval(v,4e3);return()=>window.clearInterval(e)},[]);let y=async(t,n,r)=>{m(t),g(void 0);try{r(await n())}catch(t){e(kd(t))}finally{m(void 0)}},b=t.find(e=>e.alias===r),x=b?.alias,S=typeof l==`object`&&l?l:void 0,C=typeof S?.coWorkId==`string`?S.coWorkId:void 0,w=typeof S?.status==`string`?S.status:`created`,ee=e=>{x===void 0||!a.trim()||y(e,()=>window.flavorDesktop.sendPalMessage(x,a.trim(),e),()=>{o(``),g(e===`chat`?`消息已发送给 ${x}`:`任务已委托给 ${x}`)})};return(0,P.jsxs)(`div`,{className:`pals-layout`,children:[(0,P.jsxs)(`aside`,{children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`LOCAL BROKER`}),(0,P.jsx)(`h3`,{children:`在线 Pals`})]}),(0,P.jsx)(`span`,{children:t.length})]}),d===void 0?t.length===0&&(0,P.jsxs)(`div`,{className:`pals-list-empty`,children:[(0,P.jsx)(`b`,{children:`等待其他实例`}),(0,P.jsx)(`p`,{children:`同一台设备上的 Flavor 实例上线后会出现在这里。`})]}):(0,P.jsxs)(`div`,{className:`pals-unavailable`,children:[(0,P.jsx)(`strong`,{children:`正在恢复本地协作`}),(0,P.jsx)(`p`,{children:`broker 暂时不可用,工作台会自动重试。`}),(0,P.jsx)(`button`,{onClick:()=>void v(),children:`立即重试`})]}),(0,P.jsx)(`div`,{className:`pals-list`,children:t.map(e=>(0,P.jsxs)(`button`,{"data-active":r===e.alias,onClick:()=>{i(e.alias),g(void 0)},children:[(0,P.jsx)(`span`,{className:`pal-presence`,children:(0,P.jsx)(`i`,{})}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:e.alias}),(0,P.jsx)(`small`,{title:e.projectPath??e.id,children:e.projectPath??e.id})]}),(0,P.jsx)(`em`,{children:`在线`})]},e.id))})]}),(0,P.jsxs)(`main`,{children:[(0,P.jsxs)(`header`,{className:`pals-channel-header`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`CO-WORK CHANNEL`}),(0,P.jsx)(`h3`,{children:x??`没有选中 Pal`}),(0,P.jsx)(`p`,{title:b?.projectPath,children:b?.projectPath??`从左侧选择一个在线实例后即可发送消息、委托任务或共同执行目标。`})]}),(0,P.jsxs)(`span`,{"data-online":b!==void 0,children:[(0,P.jsx)(`i`,{}),b===void 0?`等待选择`:`连接正常`]})]}),(0,P.jsxs)(`div`,{className:`pals-compose-grid`,children:[(0,P.jsxs)(`section`,{className:`pal-compose-card`,"data-kind":`message`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`span`,{children:`MESSAGE`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h4`,{children:`发消息或委托任务`}),(0,P.jsx)(`p`,{children:`同一段内容,可以即时沟通,也可以交给对方独立执行。`})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`内容`}),(0,P.jsx)(`textarea`,{"aria-label":`消息或任务内容`,value:a,onChange:e=>o(e.target.value),placeholder:`写下背景、期望结果和必要约束…`})]}),(0,P.jsxs)(`footer`,{children:[(0,P.jsx)(`small`,{children:a.length===0?`建议说明交付结果`:`${a.length} 字符`}),(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`button`,{disabled:p!==void 0||x===void 0||!a.trim(),onClick:()=>ee(`chat`),children:[(0,P.jsx)(`b`,{children:p===`chat`?`发送中…`:`发送 Chat`}),(0,P.jsx)(`span`,{children:`直接沟通`})]}),(0,P.jsxs)(`button`,{disabled:p!==void 0||x===void 0||!a.trim(),onClick:()=>ee(`task`),children:[(0,P.jsx)(`b`,{children:p===`task`?`委托中…`:`委托 Task`}),(0,P.jsx)(`span`,{children:`异步执行`})]})]})]})]}),(0,P.jsxs)(`section`,{className:`pal-compose-card`,"data-kind":`cowork`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`span`,{children:`CO-WORK`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h4`,{children:`共同完成一个目标`}),(0,P.jsx)(`p`,{children:`双方先共同规划,再持续同步执行状态与结果。`})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`共同目标`}),(0,P.jsx)(`textarea`,{"aria-label":`共同目标`,value:s,onChange:e=>c(e.target.value),placeholder:`描述目标、完成标准和双方需要协作的部分…`})]}),(0,P.jsxs)(`footer`,{children:[(0,P.jsx)(`small`,{children:s.length===0?`适合跨实例并行工作`:`${s.length} 字符`}),(0,P.jsxs)(`button`,{className:`primary`,disabled:p!==void 0||x===void 0||!s.trim(),onClick:()=>{x===void 0||!s.trim()||y(`cowork`,()=>window.flavorDesktop.startCoWork(x,s.trim()),e=>{u(e),c(``),g(`已与 ${x} 建立共同目标`)})},children:[(0,P.jsx)(`b`,{children:p===`cowork`?`建立中…`:`开始 Co-work`}),(0,P.jsx)(`span`,{children:`共同规划并执行`})]})]})]})]}),h!==void 0&&(0,P.jsxs)(`div`,{className:`pals-notice`,children:[(0,P.jsx)(`i`,{}),` `,h]}),l!==void 0&&(0,P.jsxs)(`section`,{className:`cowork-state`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`LIVE CO-WORK`}),(0,P.jsx)(`strong`,{children:`最新协作状态`})]}),(0,P.jsx)(`span`,{"data-status":w,children:w}),(0,P.jsxs)(`nav`,{children:[(0,P.jsx)(`button`,{disabled:p!==void 0,onClick:()=>void y(`refresh`,()=>window.flavorDesktop.coWorkStatus(C),u),children:`刷新状态`}),C&&(0,P.jsx)(`button`,{className:`danger`,disabled:p!==void 0,onClick:()=>{window.confirm(`取消这个 Co-work?`)&&y(`cancel`,()=>window.flavorDesktop.cancelCoWork(C,`cancelled from desktop workbench`),e=>{u(e),g(`协作已取消`)})},children:`取消协作`})]})]}),(0,P.jsxs)(`details`,{children:[(0,P.jsx)(`summary`,{children:`查看原始协作数据`}),(0,P.jsx)(`pre`,{children:JSON.stringify(l,null,2)})]})]})]})]})}function Od({snapshot:e,onError:t}){let[n,r]=(0,_.useState)([]),i=()=>window.flavorDesktop.listWorktrees().then(r).catch(e=>t(kd(e)));return(0,_.useEffect)(()=>{i()},[]),(0,P.jsxs)(`div`,{className:`worktree-pane`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`small`,{children:`TASK ISOLATION`}),(0,P.jsx)(`h3`,{children:`工作树`}),(0,P.jsx)(`p`,{children:`新任务可在独立分支中运行,不改动当前检出。`})]}),(0,P.jsxs)(`span`,{children:[n.length,` active`]})]}),n.length===0?(0,P.jsx)(`div`,{className:`manager-empty`,children:`还没有隔离工作树。新建任务时选择“隔离工作树”。`}):(0,P.jsx)(`div`,{className:`worktree-list`,children:n.map(n=>(0,P.jsxs)(`article`,{"data-current":e.activeSession?.worktreeId===n.id,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`i`,{}),(0,P.jsx)(`strong`,{children:n.branch}),(0,P.jsx)(`small`,{children:n.path})]}),(0,P.jsx)(`span`,{"data-dirty":n.dirty,children:n.merged?`merged`:n.dirty?`dirty`:`clean`}),(0,P.jsxs)(`div`,{className:`worktree-actions`,children:[(0,P.jsx)(`button`,{disabled:n.dirty||n.merged,onClick:()=>{window.confirm(`将 ${n.branch} 合并回当前项目分支?`)&&window.flavorDesktop.mergeWorktree(n.id).then(i).catch(e=>t(kd(e)))},children:`合并交付`}),(0,P.jsx)(`button`,{onClick:()=>{window.confirm(`移除工作树 ${n.branch}?${n.dirty?`存在未提交变更,将强制移除。`:`分支会保留。`}`)&&window.flavorDesktop.removeWorktree(n.id,n.dirty).then(i).catch(e=>t(kd(e)))},children:`移除并保留分支`})]})]},n.id))})]})}function kd(e){return e instanceof Error?e.message:String(e)}function Ad(e){return e.match(/https?:\/\/(?:localhost|127\.0\.0\.1|\[?::1\]?)(?::\d{1,5})?(?:\/[^\s"'<>]*)?/gi)??[]}function jd(e,t,n=Date.now()){return{task:e,framework:t,startedAt:n,updatedAt:n,phase:`analyzing`,comparisonCycle:0,activity:[{id:`import`,label:`HTML 设计稿已导入`,state:`completed`,startedAt:n,completedAt:n}]}}function Md(e,t,n=Date.now()){if(t.type===`model-start`){let r=e.phase===`analyzing`?`分析设计并规划实现`:e.phase===`building`?`检查实现并规划下一步`:`分析评测结果`;return Id(e,{id:`model:${t.id}`,label:r,state:`running`,startedAt:n},n)}if(t.type===`model-end`)return Ld(e,`model:${t.id}`,`completed`,n);if(t.type===`tool-start`){let r=Pd(t.name,e.phase),i=Fd(t.name,t.label,t.hint);return Id({...e,phase:r},{id:`tool:${t.id}`,label:i,state:`running`,startedAt:n,...t.hint===void 0||t.hint===t.label?{}:{detail:Rd(t.hint,72)}},n)}if(t.type===`tool-end`){let r=t.result.ok?`completed`:`failed`,i=e.activity.find(e=>e.id===`tool:${t.id}`);return i===void 0?Id(e,{id:`tool:${t.id}`,label:Fd(t.name,t.label,t.hint),state:r,startedAt:n,completedAt:n},n):Ld(e,i.id,r,n)}return t.type===`model-retry`?Id(e,{id:`retry:${t.attempt}`,label:`模型请求重试 ${t.attempt}/${t.maxAttempts}`,detail:`${Math.ceil(t.delayMs/1e3)} 秒后继续`,state:`info`,startedAt:n,completedAt:n},n):t.type===`warning`?Id(e,{id:`warning:${n}`,label:Rd(t.message,96),state:`info`,startedAt:n,completedAt:n},n):t.type===`error`?Id(e,{id:`error:${n}`,label:Rd(t.error.message,96),state:`failed`,startedAt:n,completedAt:n},n):e}function Nd(e,t,n=Date.now()){if(t.task!==e.task)return e;let r=`engine:${t.cycle}:${t.stage}`,i=e.activity.find(e=>e.id===r);return Id({...e,phase:`evaluating`,comparisonCycle:t.cycle},{id:r,label:t.message,state:t.state,startedAt:i?.startedAt??n,...t.state===`running`?{}:{completedAt:n},...t.cached===!0?{detail:`已复用缓存`}:{}},n)}function Pd(e,t){return e===`D2cCompare`?`evaluating`:[`Write`,`Edit`,`ApplyPatch`,`Mkdir`,`Copy`,`Move`,`Shell`,`Bash`,`Command`,`Exec`].includes(e)?`building`:t}function Fd(e,t,n){let r=Rd(t??n??``,60),i=r===``?``:` ${r}`;return[`Read`,`Glob`,`Grep`,`Search`,`List`].includes(e)?`读取${i||`设计与项目文件`}`:e===`Write`?`创建${i||`前端文件`}`:e===`Edit`||e===`ApplyPatch`?`调整${i||`前端实现`}`:e===`Mkdir`?`创建${i||`项目目录`}`:[`Shell`,`Bash`,`Command`,`Exec`].includes(e)?`运行${i||`项目命令`}`:e===`D2cCompare`?`启动视觉评测`:`${e}${i}`}function Id(e,t,n){let r=e.activity.findIndex(e=>e.id===t.id),i=[...e.activity];return r<0?i.push(t):i[r]=t,{...e,updatedAt:n,activity:i.slice(-12)}}function Ld(e,t,n,r){let i=e.activity.find(e=>e.id===t);return i===void 0?e:Id(e,{...i,state:n,completedAt:r},r)}function Rd(e,t){let n=e.replaceAll(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,t-1)}…`}var zd={sessions:[],diagnostics:[],models:[],jobs:[]},Bd=[`default`,`acceptEdits`,`plan`,`bypassPermissions`,`auto`,`bubble`],Vd=zl.map(e=>({name:e,description:Bl[e]})),Hd=5,Ud=5*1024*1024,Wd=20*1024*1024,Gd=new Set([`image/png`,`image/jpeg`,`image/webp`]),Kd=50;function qd(e){let t=[];for(let n of e){let e=t.at(-1);n.type===`session-output`&&e?.type===`session-output`&&n.sessionId===e.sessionId&&n.workspace===e.workspace&&(n.event.type===`text`||n.event.type===`thinking`)&&e.event.type===n.event.type?t[t.length-1]={...n,event:{type:n.event.type,text:e.event.text+n.event.text}}:t.push(n)}return t}function Jd(e,t){return[e.trim(),...t.map((e,t)=>`[Image #${t+1}]`)].filter(Boolean).join(`
152
+ `)}function Yd({attachments:e,onRemove:t}){return(0,P.jsx)(`div`,{className:`image-attachment-strip`,"aria-label":`待发送图片`,children:e.map((e,n)=>(0,P.jsxs)(`figure`,{className:`image-attachment-chip`,children:[(0,P.jsx)(`img`,{src:e.previewUrl,alt:e.name}),(0,P.jsxs)(`figcaption`,{children:[(0,P.jsxs)(`strong`,{children:[`[Image #`,n+1,`]`]}),(0,P.jsx)(`span`,{children:e.name})]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),"aria-label":`移除 ${e.name}`,title:`移除图片`,children:`×`})]},e.id))})}function Xd(){let[e,t]=(0,_.useState)(zd),[n,r]=(0,_.useState)(S),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(!0),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(),[y,b]=(0,_.useState)(),[x,w]=(0,_.useState)(!1),[ee,te]=(0,_.useState)(0),[ne,re]=(0,_.useState)(),[ie,ae]=(0,_.useState)([]),[oe,se]=(0,_.useState)([]),[ce,le]=(0,_.useState)(0),[ue,T]=(0,_.useState)(),[E,de]=(0,_.useState)(),[fe,pe]=(0,_.useState)(0),[D,O]=(0,_.useState)(`conversation`),[k,me]=(0,_.useState)(!1),[he,ge]=(0,_.useState)(``),[_e,ve]=(0,_.useState)(`active`),[ye,be]=(0,_.useState)(),[we,Ee]=(0,_.useState)(),[De,Oe]=(0,_.useState)(``),[ke,A]=(0,_.useState)([]),[Ae,je]=(0,_.useState)(-1),[Me,Ne]=(0,_.useState)(0),[Pe,Fe]=(0,_.useState)(),[Ie,Le]=(0,_.useState)(()=>new Map),Re=(0,_.useRef)(null),ze=(0,_.useRef)(null),j=(0,_.useRef)(void 0),Be=(0,_.useRef)(void 0),Ve=(0,_.useRef)(n),He=(0,_.useRef)(new Map),Ue=(0,_.useRef)(new Map),We=(0,_.useRef)(new Map),Ge=(0,_.useRef)(new Set),Ke=(0,_.useRef)(!1),qe=(0,_.useCallback)(e=>{a(e),re(void 0),T(void 0)},[]);(0,_.useEffect)(()=>{Ve.current=n},[n]);let Je=(0,_.useCallback)(()=>{let e=Be.current;e!==void 0&&(He.current.set(e,{sessionId:j.current,transcript:Ve.current}),j.current!==void 0&&Ue.current.set(`${e}\u0000${j.current}`,Ve.current))},[]),Ye=(0,_.useCallback)(e=>{e!==void 0&&Le(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),Xe=(0,_.useCallback)(e=>{let n=e.workspace;Be.current=n,j.current=e.activeSession?.sessionId,t(e);let i=n===void 0?void 0:He.current.get(n);r(i!==void 0&&i.sessionId===e.activeSession?.sessionId?i.transcript:S()),Ye(n),O(`conversation`),p(!1)},[Ye]);(0,_.useEffect)(()=>()=>{for(let e of Ge.current)URL.revokeObjectURL(e);Ge.current.clear()},[]);let Ze=(0,_.useCallback)(e=>{s(t=>{let n=t.find(t=>t.id===e);return n!==void 0&&(URL.revokeObjectURL(n.previewUrl),Ge.current.delete(n.previewUrl)),t.filter(t=>t.id!==e)})},[]),Qe=(0,_.useCallback)(()=>{s(e=>{for(let t of e)URL.revokeObjectURL(t.previewUrl),Ge.current.delete(t.previewUrl);return[]})},[]),$e=(0,_.useCallback)(async e=>{if(e.length===0)return;let t=Hd-o.length;if(t<=0||e.length>t){d(`每条消息最多添加 ${Hd} 张图片。`);return}if(o.reduce((e,t)=>e+Math.floor(t.dataBase64.length*3/4),0)+e.reduce((e,t)=>e+t.size,0)>Wd){d(`单条消息的图片总大小不能超过 20 MiB。`);return}try{let t=await Promise.all(e.map(mf));for(let e of t)Ge.current.add(e.previewUrl);s(e=>[...e,...t].slice(0,Hd)),d(void 0)}catch(e){d(Af(e))}},[o]);(0,_.useEffect)(()=>{let e=Re.current;if(!e)return;let t=e=>{e.deltaY<0?Ke.current=!0:requestAnimationFrame(()=>{let e=Re.current;e&&e.scrollHeight-e.scrollTop-e.clientHeight<8&&(Ke.current=!1)})};return e.addEventListener(`wheel`,t,{passive:!0}),()=>e.removeEventListener(`wheel`,t)},[]),(0,_.useEffect)(()=>{let e=[],n,i=e=>{if(e.type===`snapshot`&&e.workspace!==void 0&&e.snapshot.workspace===e.workspace){let t=Be.current;if(t!==void 0&&t!==e.workspace){He.current.set(t,{sessionId:j.current,transcript:Ve.current});let n=He.current.get(e.workspace);r(n!==void 0&&n.sessionId===e.snapshot.activeSession?.sessionId?n.transcript:S()),O(`conversation`),Ye(e.workspace)}Be.current=e.workspace}else if(e.workspace!==void 0&&(e.workspace!==Be.current||e.type===`session-output`&&e.sessionId!==j.current||e.type===`session-started`&&e.payload.sessionId!==j.current)){let t=He.current.get(e.workspace)??{sessionId:void 0,transcript:S()};if(e.type===`session-started`){let t=C(S(),{type:`restore`,state:e.payload.restoredTranscript});Ue.current.set(`${e.workspace}\u0000${e.payload.sessionId}`,t),He.current.set(e.workspace,{sessionId:e.payload.sessionId,transcript:t})}else if(e.type===`session-output`){let n=`${e.workspace}\u0000${e.sessionId}`,r=Te(Ue.current.get(n)??S(),e.sessionId,e);Ue.current.set(n,r),t.sessionId===e.sessionId&&He.current.set(e.workspace,{...t,transcript:r})}return}if(e.type===`d2c-report`){Ne(e=>e+1),Fe(t=>t!==void 0&&t.task===e.payload.task?void 0:t),O(`e2e`);return}if(e.type===`d2c-progress`){Fe(t=>t===void 0?t:Nd(t,e.payload));return}e.type===`session-output`&&e.sessionId===j.current&&Fe(t=>t===void 0?t:Md(t,e.event)),(e.type===`session-output`&&e.sessionId===j.current&&[`done`,`error`,`exit`].includes(e.event.type)||e.type===`runtime-error`&&(e.sessionId===void 0||e.sessionId===j.current))&&Fe(void 0),tf(e,j,t,r,d)},a=()=>{n!==void 0&&(clearTimeout(n),n=void 0);let t=qd(e.splice(0));for(let e of t)i(e)},o=window.flavorDesktop.onEvent(t=>{if(e.push(t),!(t.type===`session-output`&&(t.event.type===`text`||t.event.type===`thinking`))){a();return}n??=setTimeout(a,Kd)});return window.flavorDesktop.bootstrap().then(e=>{Be.current=e.workspace,j.current=e.activeSession?.sessionId,t(e)}).catch(e=>d(Af(e))).finally(()=>l(!1)),()=>{n!==void 0&&clearTimeout(n),o()}},[]),(0,_.useEffect)(()=>{Ke.current||Re.current?.scrollTo({top:Re.current.scrollHeight,behavior:`smooth`})},[n]),(0,_.useEffect)(()=>{let e=!1;return window.flavorDesktop.listFiles().then(t=>{e||se(_n(t))}).catch(()=>{}),()=>{e=!0}},[e.workspace]),(0,_.useEffect)(()=>{let t=!1;return e.workspace===void 0?(ae([]),()=>{t=!0}):(window.flavorDesktop.listSkills().then(e=>{t||ae(e)}).catch(()=>{t||ae([])}),()=>{t=!0})},[e.workspace,D]);let et=e.activeSession?.busy??!1,tt=(0,_.useMemo)(()=>e.projects??(e.workspace===void 0?[]:[{workspace:e.workspace,sessions:e.sessions,...e.activeSession===void 0?{}:{activeSession:{sessionId:e.activeSession.sessionId,busy:e.activeSession.busy}},running:et||e.jobs.some(e=>e.state===`running`)}]),[e.projects,e.workspace,e.sessions,e.activeSession,e.jobs,et]);(0,_.useEffect)(()=>{Le(e=>{let t=Ce(tt,We.current,e);return We.current=t.activity,t.notices})},[tt]);let nt=(0,_.useMemo)(()=>nn(Vd,[],ie.filter(e=>e.enabled),e.managedTools??[]),[ie,e.managedTools]),rt=(0,_.useMemo)(()=>et||e.approval!==void 0||e.questions!==void 0||ne===i?null:an(i,fe,nt,ee),[i,fe,ee,ne,et,e.approval,e.questions,nt]),it=(0,_.useMemo)(()=>et||e.approval!==void 0||e.questions!==void 0||ue===i||rt!==null?null:vn(i,fe,oe,ce),[i,fe,ce,ue,et,e.approval,e.questions,oe,rt]),at=rt===null?rn(i,nt,!1):0,ot=(0,_.useCallback)(e=>{let t=sn(i,fe,e);a(t.text),re(t.text),te(0),pe(t.cursor),setTimeout(()=>{let e=ze.current;e!==null&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},0)},[i,fe]),st=(0,_.useCallback)(()=>{re(i)},[i]),ct=(0,_.useCallback)(e=>{te(t=>on(t,e,rt?.items.length??0))},[rt]),lt=(0,_.useCallback)(e=>{let t=bn(i,fe,e);a(t.text),T(t.text),le(0),de(t.span===void 0?void 0:{...t.span,text:t.text.slice(t.span.start,t.span.end)}),pe(t.cursor),setTimeout(()=>{let e=ze.current;e!==null&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},0)},[i,fe]),ut=(0,_.useCallback)(()=>{T(i)},[i]),dt=(0,_.useCallback)(e=>{le(t=>yn(t,e,it?.items.length??0))},[it]),ft=async()=>{d(void 0);try{Je();let e=await window.flavorDesktop.chooseWorkspace();e!==void 0&&(Qe(),Xe(e))}catch(e){d(Af(e))}},pt=async n=>{if(n===e.workspace)return Ye(n),window.flavorDesktop.acknowledgeSession().then(t).catch(()=>void 0),O(`conversation`),p(!1),e;d(void 0),Je();try{let e=await window.flavorDesktop.openWorkspace(n);return Qe(),Xe(e),window.flavorDesktop.acknowledgeSession().then(t).catch(()=>void 0),e}catch(e){d(Af(e));return}},mt=async(e,t)=>{let n=await pt(e);if(n!==void 0){if(n.activeSession?.sessionId===t.sessionId){O(`conversation`),p(!1);return}await ht(t)}},ht=async e=>{d(void 0);try{Je();let n=await window.flavorDesktop.selectSession(e.sessionId),i=n.snapshot.workspace===void 0?void 0:Ue.current.get(`${n.snapshot.workspace}\u0000${n.sessionId}`);t(n.snapshot),Be.current=n.snapshot.workspace,j.current=n.sessionId,r(i??C(S(),{type:`restore`,state:n.restoredTranscript})),O(`conversation`),p(!1)}catch(e){d(Af(e))}},gt=async(e,n)=>{d(void 0);try{let i=await window.flavorDesktop.startSession(e?.sessionId,n);Qe(),t(i.snapshot),Be.current=i.snapshot.workspace,j.current=i.sessionId,r(C(S(),{type:`restore`,state:i.restoredTranscript})),i.snapshot.workspace!==void 0&&Ue.current.set(`${i.snapshot.workspace}\u0000${i.sessionId}`,C(S(),{type:`restore`,state:i.restoredTranscript})),p(!1),O(`conversation`),setTimeout(()=>ze.current?.focus(),0)}catch(e){d(Af(e))}},_t=async(n,s,c)=>{let l=(n??i).trim(),u=n===void 0?o:[];if(!l&&u.length===0)return!1;d(void 0);try{let i=e;if(i.activeSession===void 0){let e=await window.flavorDesktop.startSession();i=e.snapshot,t(i),r(C(S(),{type:`restore`,state:e.restoredTranscript}))}let o=s??(et?`steer`:`prompt`);if(u.length>0&&o!==`prompt`)throw Error(`图片只能随新消息发送,不能作为运行中的引导或后续消息。`);return o===`prompt`&&r(e=>C(e,{type:`submit`,prompt:Jd(l,u)})),n===void 0&&a(``),await window.flavorDesktop.submit(l,o,u.map(({name:e,mediaType:t,dataBase64:n})=>({name:e,mediaType:t,dataBase64:n})),c),u.length>0&&Qe(),!0}catch(e){let t=Af(e);return d(t),r(e=>C(e,{type:`submit-error`,message:t})),!1}},vt=e=>void _t(`/permissions ${e}`),yt=async e=>{d(void 0);try{t(await window.flavorDesktop.switchModel(e))}catch(e){d(Af(e))}},bt=async()=>{if(!(et||e.activeSession===void 0)){d(void 0);try{await window.flavorDesktop.finishTask()}catch(e){d(Af(e))}}},xt=async e=>{d(void 0);try{let n=await window.flavorDesktop.addModel(e);t(n.snapshot)}catch(e){throw d(Af(e)),e}},St=(e,t)=>{let n=t.currentTarget.getBoundingClientRect();window.flavorDesktop.showAppMenu(e,Math.round(n.left),Math.round(n.bottom))},Ct=async()=>{if(!(y===void 0||x)){w(!0),d(void 0);try{let n=y.sessionId===e.activeSession?.sessionId,i=await window.flavorDesktop.deleteSession(y.sessionId);t(i),n&&r(S()),b(void 0),v(void 0)}catch(e){d(Af(e))}finally{w(!1)}}},wt=async(e,n)=>{try{t(await window.flavorDesktop.updateSession(e.sessionId,n)),v(void 0)}catch(e){d(Af(e))}},M=e=>{let t=window.prompt(`任务名称`,e.title??xe(e));t!==null&&wt(e,{title:t.trim()})},Tt=async(e,n)=>{try{t(await window.flavorDesktop.updateProject(e,n)),be(void 0)}catch(e){d(Af(e))}},Et=(e,t)=>{let n=window.prompt(`项目显示名称`,t??Se(e));n!==null&&Tt(e,{label:n.trim()})},Dt=async(e,t)=>{if(!(t&&!window.confirm(`项目中有任务正在运行。停止任务并关闭项目?`)))try{Xe(await window.flavorDesktop.closeProject(e,t)),be(void 0)}catch(e){d(Af(e))}},Ot=async(e,t)=>{let n=await pt(e);if(n!==void 0&&t!==void 0){let e=n.sessions.find(e=>e.sessionId===t);e!==void 0&&await ht(e)}};(0,_.useEffect)(()=>{let t={...e.workspace===void 0?{}:{workspace:e.workspace},...e.activeSession===void 0?{}:{sessionId:e.activeSession.sessionId},view:D};A(e=>{let n=e[Ae];if(n?.workspace===t.workspace&&n?.sessionId===t.sessionId&&n?.view===t.view)return e;let r=[...e.slice(0,Ae+1),t].slice(-50);return je(r.length-1),r})},[e.workspace,e.activeSession?.sessionId,D]);let kt=async e=>{let n=Ae+e,i=ke[n];if(i!==void 0){if(je(n),i.workspace!==void 0){let e=await window.flavorDesktop.openWorkspace(i.workspace);if(Xe(e),i.sessionId!==void 0){let e=await window.flavorDesktop.selectSession(i.sessionId);t(e.snapshot),j.current=e.sessionId,r(Ue.current.get(`${i.workspace}\u0000${i.sessionId}`)??C(S(),{type:`restore`,state:e.restoredTranscript}))}}O(i.view)}};return(0,_.useEffect)(()=>{let e=e=>{if(!(e.ctrlKey||e.metaKey))return;let t=e.key.toLowerCase();t===`n`&&(e.preventDefault(),me(!0)),t===`p`&&(e.preventDefault(),Ee(`projects`),Oe(``)),t===`k`&&(e.preventDefault(),Ee(`commands`),Oe(``)),t===`[`&&(e.preventDefault(),kt(-1)),t===`]`&&(e.preventDefault(),kt(1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[e.workspace,ke,Ae]),(0,P.jsxs)(`div`,{className:`app-frame`,children:[(0,P.jsx)(ef,{railCollapsed:m,onToggleRail:()=>h(e=>!e),onMenu:St,canBack:Ae>0,canForward:Ae<ke.length-1,onBack:()=>void kt(-1),onForward:()=>void kt(1)}),(0,P.jsxs)(`div`,{className:`desktop-shell`,"data-rail-collapsed":m,children:[(0,P.jsx)(`button`,{className:`rail-scrim`,"data-open":f,onClick:()=>p(!1),"aria-label":`关闭项目栏`}),(0,P.jsxs)(`aside`,{className:`project-rail`,"data-open":f,children:[(0,P.jsxs)(`div`,{className:`brand-row`,children:[(0,P.jsx)(kf,{}),(0,P.jsx)(`strong`,{children:`Flavor Code`})]}),(0,P.jsxs)(`nav`,{className:`primary-actions`,"aria-label":`主要操作`,children:[(0,P.jsxs)(`button`,{className:`rail-action rail-action-primary`,disabled:e.workspace===void 0,onClick:()=>me(!0),children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(Of,{name:`plus`})}),(0,P.jsx)(`span`,{children:`新建任务`}),(0,P.jsx)(`kbd`,{children:`Ctrl N`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,onClick:()=>void ft(),children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(Of,{name:`folder`})}),(0,P.jsx)(`span`,{children:`打开项目`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`skills`,onClick:()=>{O(`skills`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(Of,{name:`sparkles`})}),(0,P.jsx)(`span`,{children:`技能`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`memory`,onClick:()=>{O(`memory`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(Of,{name:`database`})}),(0,P.jsx)(`span`,{children:`长期记忆`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`mcp`,onClick:()=>{O(`mcp`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(Of,{name:`server`})}),(0,P.jsx)(`span`,{children:`MCP 服务`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`e2e`,onClick:()=>{O(`e2e`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(Of,{name:`checklist`})}),(0,P.jsx)(`span`,{children:`E2E`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`activity`,onClick:()=>{O(`activity`),p(!1)},children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(Of,{name:`bell`})}),(0,P.jsx)(`span`,{children:`活动`}),(e.activities?.filter(e=>e.unread).length??0)>0&&(0,P.jsx)(`em`,{className:`rail-badge`,children:e.activities.filter(e=>e.unread).length})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`git`,onClick:()=>{O(`git`),p(!1)},disabled:e.workspace===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(Of,{name:`git`})}),(0,P.jsx)(`span`,{children:`Git 变更`})]}),(0,P.jsxs)(`button`,{className:`rail-action`,"data-active":D===`workbench`,onClick:()=>{O(`workbench`),p(!1)},disabled:e.workspace===void 0||e.activeSession===void 0,children:[(0,P.jsx)(`span`,{className:`action-icon`,children:(0,P.jsx)(Of,{name:`checklist`})}),(0,P.jsx)(`span`,{children:`Agent 工作台`})]})]}),(0,P.jsxs)(`div`,{className:`sessions-scroll`,children:[(0,P.jsxs)(`div`,{className:`rail-section-heading`,children:[(0,P.jsx)(`span`,{children:`项目`}),(0,P.jsx)(`button`,{onClick:()=>void ft(),"aria-label":`打开新项目`,title:`打开新项目`,children:(0,P.jsx)(Of,{name:`plus`})})]}),tt.length>0&&(0,P.jsxs)(`div`,{className:`session-filter`,children:[(0,P.jsxs)(`div`,{className:`session-search`,children:[(0,P.jsx)(Of,{name:`search`}),(0,P.jsx)(`input`,{value:he,onChange:e=>ge(e.target.value),placeholder:`搜索任务`,"aria-label":`搜索任务`}),he.length>0&&(0,P.jsx)(`button`,{type:`button`,onClick:()=>ge(``),"aria-label":`清除搜索`,title:`清除搜索`,children:`×`})]}),(0,P.jsxs)(`div`,{className:`session-group-filter`,children:[(0,P.jsxs)(`select`,{value:_e,onChange:e=>ve(e.target.value),"aria-label":`按状态筛选`,children:[(0,P.jsx)(`option`,{value:`active`,children:`任务`}),(0,P.jsx)(`option`,{value:`running`,children:`运行`}),(0,P.jsx)(`option`,{value:`unread`,children:`未读`}),(0,P.jsx)(`option`,{value:`archived`,children:`归档`})]}),(0,P.jsx)(`span`,{"aria-hidden":`true`})]})]}),tt.length===0?(0,P.jsx)(`button`,{className:`empty-project`,onClick:()=>void ft(),children:`选择一个本地文件夹开始`}):tt.map(t=>{let n=t.workspace===e.workspace,r=Ie.has(t.workspace);Ie.get(t.workspace);let i=n||t.running||r;return(0,P.jsxs)(`section`,{className:`project-entry`,"data-active":n,children:[(0,P.jsxs)(`div`,{className:`project-heading-shell`,children:[(0,P.jsxs)(`button`,{className:`project-heading`,onClick:()=>void pt(t.workspace),title:t.workspace,children:[(0,P.jsx)(`span`,{className:`folder-icon`,"aria-hidden":`true`,children:(0,P.jsx)(Of,{name:`folder`})}),(0,P.jsx)(`span`,{children:t.label||Se(t.workspace)}),t.running?(0,P.jsx)(`span`,{className:`project-running-dot`,title:`项目中有任务正在执行`}):(t.unreadCount??0)>0&&(0,P.jsx)(`span`,{className:`project-complete-dot`,role:`status`,"aria-label":`项目有未读活动`})]}),(0,P.jsx)(`button`,{className:`project-more`,onClick:()=>be(e=>e===t.workspace?void 0:t.workspace),"aria-label":`管理项目`,children:`•••`}),ye===t.workspace&&(0,P.jsxs)(`div`,{className:`project-menu`,role:`menu`,children:[(0,P.jsx)(`button`,{onClick:()=>Et(t.workspace,t.label),children:`修改显示名称`}),(0,P.jsx)(`button`,{onClick:()=>void Tt(t.workspace,{pinned:!t.pinned}),children:t.pinned?`取消置顶`:`置顶项目`}),(0,P.jsx)(`button`,{onClick:()=>void window.flavorDesktop.revealProject(t.workspace),children:`在资源管理器中打开`}),(0,P.jsx)(`button`,{onClick:()=>void window.flavorDesktop.copyProjectPath(t.workspace),children:`复制路径`}),(0,P.jsx)(`button`,{className:`danger-item`,onClick:()=>void Dt(t.workspace,t.running),children:`关闭项目`})]})]}),i&&t.sessions.length===0&&(0,P.jsx)(`p`,{className:`no-sessions`,children:`还没有任务`}),i&&t.sessions.filter(e=>(_e===`archived`?e.archived:!e.archived)&&(_e!==`running`||t.runningSessions?.includes(e.sessionId))&&(_e!==`unread`||e.unread)&&(!he.trim()||xe(e).toLowerCase().includes(he.trim().toLowerCase()))).map(r=>{let i=n&&r.sessionId===e.activeSession?.sessionId,a=t.runningSessions?.includes(r.sessionId)??(t.running&&r.sessionId===t.activeSession?.sessionId),o=r.unread&&r.activity===`completed`;return(0,P.jsxs)(`div`,{className:`session-item-shell`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||v(void 0)},children:[(0,P.jsxs)(`button`,{className:`session-item`,"data-active":i,"data-running":a,disabled:n&&et&&!i,onClick:()=>void mt(t.workspace,r),children:[(0,P.jsxs)(`span`,{children:[r.pinned&&(0,P.jsx)(`i`,{className:`pin-mark`,children:`◆`}),xe(r)]}),a?(0,P.jsx)(`span`,{className:`session-spinner`,role:`status`,"aria-label":`任务正在执行`}):o?(0,P.jsx)(`span`,{className:`session-complete-dot`,role:`status`,"aria-label":`任务已完成,点击查看`}):(0,P.jsx)(`time`,{children:Pf(r.updatedAt)})]}),n&&(0,P.jsx)(`button`,{className:`session-more`,"aria-label":`管理会话:${xe(r)}`,"aria-expanded":g===r.sessionId,onClick:()=>v(e=>e===r.sessionId?void 0:r.sessionId),children:`•••`}),n&&g===r.sessionId&&(0,P.jsxs)(`div`,{className:`session-menu`,role:`menu`,children:[(0,P.jsx)(`button`,{role:`menuitem`,onClick:()=>M(r),children:`重命名`}),(0,P.jsx)(`button`,{role:`menuitem`,onClick:()=>void wt(r,{pinned:!r.pinned}),children:r.pinned?`取消置顶`:`置顶`}),(0,P.jsx)(`button`,{role:`menuitem`,onClick:()=>void wt(r,{archived:!r.archived}),children:r.archived?`取消归档`:`归档`}),(0,P.jsx)(`button`,{role:`menuitem`,className:`danger-item`,disabled:et&&r.sessionId===e.activeSession?.sessionId,onClick:()=>{b(r),v(void 0)},children:`删除会话`})]})]},r.sessionId)})]},t.workspace)})]}),(0,P.jsxs)(`div`,{className:`rail-footer`,children:[(0,P.jsx)(`span`,{className:`avatar`,children:`F`}),(0,P.jsx)(`span`,{children:`本地工作区`}),(0,P.jsx)(`button`,{title:`帮助`,children:`?`})]})]}),(0,P.jsxs)(`main`,{className:`workspace-panel`,children:[D===`workbench`&&e.workspace!==void 0&&e.activeSession!==void 0?(0,P.jsx)(_d,{snapshot:e,onClose:()=>O(`conversation`),onError:d,onCompose:e=>{qe(e),O(`conversation`),setTimeout(()=>ze.current?.focus(),0)}}):D===`skills`&&e.workspace!==void 0?(0,P.jsx)(Hl,{onClose:()=>O(`conversation`),onError:d}):D===`memory`&&e.workspace!==void 0?(0,P.jsx)(ql,{onClose:()=>O(`conversation`),onError:d}):D===`mcp`&&e.workspace!==void 0?(0,P.jsx)(Yl,{onClose:()=>O(`conversation`),onError:d}):D===`activity`?(0,P.jsx)(Zd,{activities:e.activities??[],onClose:()=>O(`conversation`),onOpen:(e,t)=>void Ot(e,t),onClear:()=>void window.flavorDesktop.acknowledgeSession().then(t)}):D===`git`&&e.workspace!==void 0?(0,P.jsx)(ed,{onClose:()=>O(`conversation`),onError:d,onReview:()=>{O(`conversation`),_t(`/review`,`prompt`)}}):D===`e2e`&&e.workspace!==void 0?(0,P.jsx)(Zu,{onClose:()=>O(`conversation`),onInterrupt:()=>void window.flavorDesktop.interrupt(),onError:d,refreshKey:Me,pending:Pe,disabled:et,onLaunch:(e,t)=>Fe(jd(e,t)),onStartTask:e=>_t(e,`prompt`,`d2c`)}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`header`,{className:`workspace-header`,children:[(0,P.jsx)(`button`,{className:`mobile-rail-toggle`,onClick:()=>p(!0),"aria-label":`打开项目栏`,children:`☰`}),(0,P.jsx)(`div`,{className:`workspace-breadcrumb`,children:(0,P.jsx)(`span`,{children:Se(e.workspace)})}),(0,P.jsxs)(`div`,{className:`header-actions`,children:[e.jobs.some(e=>e.state===`running`)&&(0,P.jsxs)(`div`,{className:`job-strip`,title:`后台任务`,children:[(0,P.jsx)(`span`,{className:`job-pulse`}),e.jobs.filter(e=>e.state===`running`).length,` 个后台任务`]}),(0,P.jsx)(`button`,{className:`finish-task-button`,onClick:()=>void bt(),disabled:et||e.activeSession===void 0,title:`评估并完成当前任务`,children:`完成任务`}),(0,P.jsx)(`button`,{title:`更多选项`,children:`•••`})]})]}),(e.recoveryItems?.filter(t=>t.workspace===e.workspace).length??0)>0&&(0,P.jsxs)(`div`,{className:`recovery-banner`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:`检测到上次未完成的任务`}),(0,P.jsx)(`span`,{children:`应用异常退出时,这些任务仍在运行。`})]}),e.recoveryItems.filter(t=>t.workspace===e.workspace).map(n=>(0,P.jsxs)(`div`,{className:`recovery-action`,children:[(0,P.jsx)(`code`,{children:jf(n.sessionId)}),(0,P.jsx)(`button`,{onClick:()=>{let t=e.sessions.find(e=>e.sessionId===n.sessionId);t!==void 0&&ht(t)},children:`恢复 / 查看`}),(0,P.jsx)(`button`,{onClick:()=>void window.flavorDesktop.dismissRecovery(n.sessionId).then(t),children:`忽略`})]},n.sessionId))]}),(0,P.jsx)(`div`,{className:`conversation-scroll`,ref:Re,children:c?(0,P.jsx)(wf,{}):e.workspace===void 0?(0,P.jsx)(Cf,{onOpen:ft}):n.completed.length===0&&n.active===void 0?(0,P.jsx)(Sf,{project:Se(e.workspace),onStart:e=>void _t(e)}):(0,P.jsxs)(`div`,{className:`conversation-column`,children:[n.completed.length>60&&(0,P.jsxs)(`div`,{className:`transcript-window-notice`,children:[`更早的 `,n.completed.length-60,` 轮仍保存在会话中,已从实时渲染窗口隐藏`]}),n.completed.slice(-60).map(e=>(0,P.jsx)(rf,{turn:e},e.id)),n.active!==void 0&&(0,P.jsx)(rf,{turn:n.active,active:!0})]})}),e.diagnostics.length>0&&(0,P.jsxs)(`details`,{className:`diagnostics`,children:[(0,P.jsxs)(`summary`,{children:[e.diagnostics.length,` 条启动提示`]}),(0,P.jsx)(`pre`,{children:e.diagnostics.join(`
153
+ `)})]}),(0,P.jsx)(df,{input:i,setInput:qe,onSend:e=>void _t(void 0,e),busy:et,onInterrupt:()=>{Fe(void 0),window.flavorDesktop.interrupt()},inputRef:ze,snapshot:e,attachments:o,onAddImages:e=>void $e(e),onRemoveImage:Ze,setModel:yt,addModel:xt,setPermission:vt,slashCompletion:rt,onSlashSelect:ot,onSlashDismiss:st,onSlashMove:ct,mentionCompletion:it,onMentionSelect:lt,onMentionDismiss:ut,onMentionMove:dt,mentionSpan:E,setMentionSpan:de,completedTokenLen:at,cursorPos:fe,setCursorPos:pe})]}),u!==void 0&&(0,P.jsxs)(`div`,{className:`error-toast`,role:`alert`,children:[(0,P.jsx)(`span`,{children:`!`}),(0,P.jsx)(`p`,{children:u}),(0,P.jsx)(`button`,{onClick:()=>d(void 0),children:`×`})]})]})]}),e.approval!==void 0&&(0,P.jsx)(vf,{approval:e.approval,onResolve:e=>void window.flavorDesktop.resolveApproval(e)}),e.questions!==void 0&&(0,P.jsx)(yf,{questions:e.questions,onAnswer:e=>void window.flavorDesktop.answerQuestions(e)}),e.memoryReviews!==void 0&&e.memoryReviews.length>0&&(0,P.jsx)(bf,{reviews:e.memoryReviews,autoDismissSeconds:e.memoryAutoDismissSeconds??0,onResolve:(e,t)=>{window.flavorDesktop.resolveMemoryReview(e,t).catch(e=>d(Af(e)))}}),y!==void 0&&(0,P.jsx)(gf,{session:y,deleting:x,onCancel:()=>b(void 0),onDelete:()=>void Ct()}),k&&(0,P.jsx)(Qd,{onCancel:()=>me(!1),onChoose:e=>{me(!1),gt(void 0,e)}}),we!==void 0&&(0,P.jsx)($d,{mode:we,query:De,setQuery:Oe,projects:tt,onClose:()=>Ee(void 0),onProject:e=>{Ee(void 0),pt(e)},onCommand:e=>{Ee(void 0),e===`new`?me(!0):e===`open`?ft():e===`activity`?O(`activity`):e===`git`?O(`git`):e===`skills`&&O(`skills`)}})]})}function Zd({activities:e,onClose:t,onOpen:n,onClear:r}){return(0,P.jsxs)(`section`,{className:`manager-view activity-center`,children:[(0,P.jsxs)(`header`,{className:`manager-header`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{onClick:t,children:`←`}),(0,P.jsx)(`h2`,{children:`活动`})]}),(0,P.jsx)(`button`,{onClick:r,children:`全部标为已读`})]}),(0,P.jsx)(`div`,{className:`activity-list`,children:e.length===0?(0,P.jsx)(`p`,{className:`manager-empty`,children:`还没有任务活动`}):e.map(e=>(0,P.jsxs)(`button`,{className:`activity-row`,"data-kind":e.kind,"data-unread":e.unread,onClick:()=>n(e.workspace,e.sessionId),children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:e.title}),(0,P.jsxs)(`span`,{children:[Se(e.workspace),e.detail?` · ${e.detail}`:``]})]}),(0,P.jsx)(`time`,{children:Pf(e.createdAt)})]},e.id))})]})}function Qd({onCancel:e,onChoose:t}){return(0,P.jsx)(`div`,{className:`modal-layer`,onMouseDown:t=>{t.target===t.currentTarget&&e()},children:(0,P.jsxs)(`section`,{className:`new-task-sheet`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`new-task-title`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsx)(`p`,{children:`NEW TASK`}),(0,P.jsx)(`h2`,{id:`new-task-title`,children:`选择任务运行环境`}),(0,P.jsx)(`span`,{children:`隔离只影响 Electron 任务,不改变 CLI 默认行为。`})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`button`,{onClick:()=>t(`worktree`),children:[(0,P.jsx)(`i`,{children:`◇`}),(0,P.jsx)(`strong`,{children:`隔离工作树`}),(0,P.jsx)(`span`,{children:`新建 flavor/desktop-* 分支,在应用目录中独立运行。`}),(0,P.jsx)(`em`,{children:`推荐`})]}),(0,P.jsxs)(`button`,{onClick:()=>t(`local`),children:[(0,P.jsx)(`i`,{children:`⌂`}),(0,P.jsx)(`strong`,{children:`当前检出`}),(0,P.jsx)(`span`,{children:`直接使用项目当前目录,适合快速查看和轻量操作。`})]})]}),(0,P.jsx)(`footer`,{children:(0,P.jsx)(`button`,{onClick:e,children:`取消`})})]})})}function $d({mode:e,query:t,setQuery:n,projects:r,onClose:i,onProject:a,onCommand:o}){let s=[{id:`new`,label:`新建任务`,hint:`Ctrl N`},{id:`open`,label:`打开项目`,hint:`Ctrl O`},{id:`activity`,label:`查看活动`,hint:``},{id:`git`,label:`打开 Git 变更`,hint:``},{id:`skills`,label:`管理技能`,hint:``}].filter(e=>e.label.toLowerCase().includes(t.toLowerCase())),c=r.filter(e=>`${e.label??``} ${Se(e.workspace)} ${e.workspace}`.toLowerCase().includes(t.toLowerCase()));return(0,P.jsx)(`div`,{className:`palette-layer`,onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,P.jsxs)(`section`,{className:`command-palette`,role:`dialog`,"aria-modal":`true`,children:[(0,P.jsx)(`input`,{autoFocus:!0,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Escape`&&i()},placeholder:e===`projects`?`切换到项目…`:`键入命令…`}),(0,P.jsx)(`div`,{children:e===`projects`?c.map(e=>(0,P.jsxs)(`button`,{onClick:()=>a(e.workspace),children:[(0,P.jsx)(Of,{name:`folder`}),(0,P.jsx)(`span`,{children:e.label||Se(e.workspace)}),(0,P.jsx)(`small`,{children:e.workspace})]},e.workspace)):s.map(e=>(0,P.jsxs)(`button`,{onClick:()=>o(e.id),children:[(0,P.jsx)(`span`,{children:e.label}),(0,P.jsx)(`kbd`,{children:e.hint})]},e.id))})]})})}function ef({railCollapsed:e,onToggleRail:t,onMenu:n,canBack:r,canForward:i,onBack:a,onForward:o}){return(0,P.jsxs)(`header`,{className:`window-titlebar`,children:[(0,P.jsx)(`button`,{className:`titlebar-icon sidebar-toggle`,"data-collapsed":e,onClick:t,"aria-label":e?`显示项目栏`:`隐藏项目栏`,title:e?`显示项目栏`:`隐藏项目栏`,children:(0,P.jsxs)(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,children:[(0,P.jsx)(`rect`,{x:`2.5`,y:`2.5`,width:`11`,height:`11`,rx:`2`}),(0,P.jsx)(`path`,{d:`M6 3v10`})]})}),(0,P.jsx)(`button`,{className:`titlebar-icon nav-button`,disabled:!r,onClick:a,"aria-label":`后退`,title:`后退 (Ctrl+[)`,children:(0,P.jsx)(`span`,{children:`‹`})}),(0,P.jsx)(`button`,{className:`titlebar-icon nav-button`,disabled:!i,onClick:o,"aria-label":`前进`,title:`前进 (Ctrl+])`,children:(0,P.jsx)(`span`,{children:`›`})}),(0,P.jsxs)(`nav`,{className:`titlebar-menus`,"aria-label":`应用菜单`,children:[(0,P.jsx)(`button`,{onClick:e=>n(`file`,e),children:`文件`}),(0,P.jsx)(`button`,{onClick:e=>n(`edit`,e),children:`编辑`}),(0,P.jsx)(`button`,{onClick:e=>n(`view`,e),children:`视图`}),(0,P.jsx)(`button`,{onClick:e=>n(`help`,e),children:`帮助`})]})]})}function tf(e,t,n,r,i){e.type===`snapshot`?(t.current=e.snapshot.activeSession?.sessionId,n(e.snapshot)):e.type===`session-started`?(t.current=e.payload.sessionId,n(e.payload.snapshot),r(C(S(),{type:`restore`,state:e.payload.restoredTranscript}))):e.type===`session-output`?r(n=>Te(n,t.current,e)):e.type===`runtime-error`&&(e.sessionId===void 0||e.sessionId===t.current)&&i(e.message)}function nf({turn:e,active:t=!1}){let n=t?e.blocks:e.blocks.filter(e=>e.kind!==`status`||e.task===void 0),r=Math.max(0,n.length-200),i=n.slice(-200);return(0,P.jsxs)(`article`,{className:`turn`,"data-active":t,"data-kind":e.kind??`conversation`,children:[(0,P.jsx)(`div`,{className:`user-message`,children:(0,P.jsx)(`span`,{children:of(e.prompt,16e3)})}),(0,P.jsxs)(`div`,{className:`assistant-message`,children:[(0,P.jsx)(`div`,{className:`assistant-avatar`,children:(0,P.jsx)(kf,{})}),(0,P.jsxs)(`div`,{className:`turn-content`,children:[r>0&&(0,P.jsxs)(`div`,{className:`transcript-window-notice`,children:[`更早的 `,r,` 条任务输出已从实时渲染窗口隐藏`]}),i.map((e,t)=>(0,P.jsx)(af,{block:e},e.kind===`status`?e.id:`text-${t}`)),t&&i.length===0&&(0,P.jsxs)(`div`,{className:`thinking-line`,role:`status`,children:[(0,P.jsx)(`i`,{}),(0,P.jsxs)(`span`,{children:[(0,P.jsx)(`strong`,{children:`Flavoring`}),(0,P.jsx)(`small`,{children:`正在理解任务`})]})]})]})]})]})}var rf=_.memo(nf);function af({block:e}){if(e.kind===`text`)return(0,P.jsx)(`div`,{className:`assistant-copy`,children:(0,P.jsx)(Qt,{text:of(e.text)})});let t=e.state===`completed`?`✓`:e.state===`failed`?`×`:e.state===`cancelled`?`–`:e.state===`running`?``:`·`,n=e.activity===`model`,r=n&&e.thinkingText?sf(e.thinkingText):void 0;return(0,P.jsxs)(`div`,{className:`activity-card`,"data-state":e.state,"data-tone":e.tone,"data-activity":e.activity,children:[(0,P.jsx)(`span`,{className:`activity-node`,children:t}),(0,P.jsxs)(`div`,{className:`activity-body`,children:[(0,P.jsxs)(`div`,{className:`activity-title`,children:[(0,P.jsx)(`span`,{children:e.text.replace(/^[·✓×]\s*/,``)}),n&&e.state===`running`&&(0,P.jsx)(`small`,{children:`正在思考`}),e.hint&&(0,P.jsx)(`code`,{children:e.hint})]}),r&&(0,P.jsx)(`div`,{className:`reasoning-preview`,children:r}),e.progress!==void 0&&(0,P.jsx)(`div`,{className:`progress-track`,children:(0,P.jsx)(`i`,{style:{width:`${e.progress}%`}})}),e.presentation?.kind===`file-change`&&(0,P.jsx)(lf,{presentation:e.presentation}),e.presentation?.kind===`generic`&&(0,P.jsxs)(`div`,{className:`tool-presentation`,children:[(0,P.jsx)(`strong`,{children:e.presentation.title}),e.presentation.summary&&(0,P.jsx)(`span`,{children:e.presentation.summary})]}),e.presentation?.kind===`terminal`&&(0,P.jsxs)(`div`,{className:`tool-presentation`,children:[(0,P.jsx)(`strong`,{children:e.presentation.title}),e.presentation.stdout&&(0,P.jsx)(`pre`,{children:of(e.presentation.stdout)})]}),e.presentation?.kind===`web`&&(0,P.jsxs)(`div`,{className:`tool-presentation`,children:[(0,P.jsx)(`strong`,{children:e.presentation.title}),e.presentation.summary&&(0,P.jsx)(`span`,{children:e.presentation.summary})]}),e.tool&&(0,P.jsxs)(`details`,{className:`tool-details`,children:[(0,P.jsx)(`summary`,{children:`调用详情`}),(0,P.jsx)(`label`,{children:`Input`}),(0,P.jsx)(`pre`,{children:cf(e.tool.input)}),e.tool.result===void 0?null:(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`label`,{children:`Result`}),(0,P.jsx)(`pre`,{children:cf(e.tool.result)})]})]}),e.details&&(0,P.jsxs)(`details`,{className:`timeline-details`,children:[(0,P.jsx)(`summary`,{children:`压缩摘要`}),(0,P.jsx)(Qt,{text:of(e.details)})]})]})]})}function of(e,t=32e3){if(e.length<=t)return e;let n=Math.floor((t-64)/2);return`${e.slice(0,n)}\n\n… ${e.length-n*2} 个字符已隐藏 …\n\n${e.slice(-n)}`}function sf(e,t=280){let n=e.replace(/\s+/gu,` `).trim(),r=Math.max(1,Math.floor(t)),i=[...n];return i.length<=r?n:`…${i.slice(-r).join(``)}`}function cf(e,t=1e4){let n;try{n=JSON.stringify(e,null,2)??`undefined`}catch{n=String(e)}return n.length<=t?n:`${n.slice(0,t)}…`}function lf({presentation:e}){let t=e.operation===`delete`,n=e.operation===`create`?`新建`:e.operation===`delete`?`删除`:`修改`,r=e.path.replace(/^.*[/\\]/,``),i=t?1:Math.max(1,...e.lines.map(e=>Math.max(e.oldLine??0,e.newLine??0))).toString().length;return(0,P.jsxs)(`details`,{className:`diff-preview`,children:[(0,P.jsxs)(`summary`,{children:[(0,P.jsx)(`span`,{className:`diff-marker ${t?`diff-delete`:`diff-add`}`,children:`●`}),(0,P.jsx)(`span`,{className:`diff-label`,children:n}),(0,P.jsx)(`span`,{className:`diff-path`,children:r}),(0,P.jsxs)(`span`,{className:`diff-counts`,children:[!t&&(0,P.jsxs)(`span`,{className:`diff-added-count`,children:[`+`,e.added]}),!t&&e.removed>0&&(0,P.jsxs)(`span`,{className:`diff-removed-count`,children:[` −`,e.removed]}),t&&(0,P.jsxs)(`span`,{className:`diff-removed-count`,children:[`−`,e.removed]})]})]}),t?null:(0,P.jsx)(`div`,{className:`diff-body`,children:e.lines.map((e,t)=>(0,P.jsx)(uf,{line:e,lineWidth:i},t))})]})}function uf({line:e,lineWidth:t}){let n=e.kind===`removed`||e.kind===`context`?e.oldLine:e.newLine,r=e.kind===`removed`?`-`:e.kind===`added`?`+`:e.kind===`omitted`?`…`:` `;return(0,P.jsxs)(`div`,{className:`diff-row ${e.kind===`added`?`diff-row-added`:e.kind===`removed`?`diff-row-removed`:e.kind===`omitted`?`diff-row-omitted`:`diff-row-context`}`,children:[(0,P.jsx)(`span`,{className:`diff-line-number`,children:String(n??``).padStart(t)}),(0,P.jsx)(`span`,{className:`diff-line-marker`,children:r}),(0,P.jsx)(`span`,{className:`diff-line-text`,children:e.text})]})}function df(e){let t=e.snapshot.workspace===void 0,[n,r]=(0,_.useState)(!1),i=(0,_.useRef)(null),a=e.slashCompletion!==null,o=e.mentionCompletion!==null,s=a||o,c=e.completedTokenLen>0,l=c?e.input.slice(0,e.completedTokenLen):void 0,u=l?.startsWith(`/`)?l.slice(1).trim():l?.trim(),d=c?void 0:e.mentionSpan,f=d!==void 0&&d.start>=0&&d.end>d.start&&d.start<e.input.length&&d.end<=e.input.length&&e.input.slice(d.start,d.end)===d.text,p=f?e.input.slice(0,d.start):``,m=f?e.input.slice(d.start,d.end):``,h=f?e.input.slice(d.end):``,g=m.startsWith(`@`)?m.slice(1).trim():m,v=c?e.input.slice(e.completedTokenLen):f?h:e.input,y=c?l.length:f?d.start+m.length:0,b=e=>y+e,x=t=>{if(a){if(t.key===`ArrowDown`){t.preventDefault(),e.onSlashMove(1);return}if(t.key===`ArrowUp`){t.preventDefault(),e.onSlashMove(-1);return}if(t.key===`Tab`||t.key===`Enter`){t.preventDefault();let n=e.slashCompletion?.items[e.slashCompletion?.selectedIndex??0];n!==void 0&&e.onSlashSelect(n.name);return}if(t.key===`Escape`){t.preventDefault(),e.onSlashDismiss();return}}if(o){if(t.key===`ArrowDown`){t.preventDefault(),e.onMentionMove(1);return}if(t.key===`ArrowUp`){t.preventDefault(),e.onMentionMove(-1);return}if(t.key===`Tab`||t.key===`Enter`){t.preventDefault();let n=e.mentionCompletion?.items[e.mentionCompletion?.selectedIndex??0];n!==void 0&&e.onMentionSelect(n);return}if(t.key===`Escape`){t.preventDefault(),e.onMentionDismiss();return}}let n=t.target,r=n.selectionStart,i=n.selectionEnd;if(t.key===`Backspace`&&r===i&&!s){if(c){let n=cn(e.input,e.completedTokenLen,b(r));if(n!==null){t.preventDefault(),e.setInput(n.text),e.setCursorPos(n.cursor);return}}if(f&&r===0){t.preventDefault();let n=p+h;e.setInput(n),e.setMentionSpan(void 0),e.setCursorPos(p.length);return}}t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),e.onSend(t.altKey?`followUp`:e.busy?`steer`:void 0))},S=(t,n)=>{let r;if(r=c?l+t:f?p+m+t:t,f){let t=p+m;r.startsWith(t)||e.setMentionSpan(void 0)}e.setInput(r),e.setCursorPos(b(n))},C=t=>{e.setCursorPos(b(t))},w=(0,P.jsx)(`textarea`,{ref:e.inputRef,className:`composer-textarea`,value:v,onChange:e=>S(e.target.value,e.target.selectionStart),onSelect:e=>C(e.target.selectionStart),onKeyDown:x,onPaste:t=>{let n=ff(t.clipboardData.files);n.length!==0&&(t.preventDefault(),e.onAddImages(n))},onClick:e=>C(e.target.selectionStart),placeholder:t?`先打开一个项目`:c||f?``:`给 Flavor 一个任务,或输入 / 查看命令`,disabled:t,rows:1}),ee=c?(0,P.jsxs)(`div`,{className:`composer-input-row`,children:[(0,P.jsx)(`span`,{className:`slash-tag`,children:u}),w]}):f?(0,P.jsxs)(`div`,{className:`composer-input-row`,children:[p.length>0&&(0,P.jsx)(`span`,{className:`composer-plain-text`,children:p}),(0,P.jsx)(`span`,{className:`mention-tag`,children:g}),w]}):w;return(0,P.jsxs)(`div`,{className:`composer-wrap`,onDragEnter:e=>{pf(e.dataTransfer)&&(e.preventDefault(),r(!0))},onDragOver:e=>{pf(e.dataTransfer)&&e.preventDefault()},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||r(!1)},onDrop:t=>{let n=ff(t.dataTransfer.files);n.length!==0&&(t.preventDefault(),r(!1),e.onAddImages(n))},children:[a&&(0,P.jsx)(fn,{completion:e.slashCompletion,onSelect:e.onSlashSelect,onDismiss:e.onSlashDismiss}),o&&(0,P.jsx)(hn,{completion:e.mentionCompletion,onSelect:e.onMentionSelect,onDismiss:e.onMentionDismiss}),(0,P.jsxs)(`div`,{className:`composer${c||f?` has-tag`:``}`,"data-busy":e.busy,"data-image-drag":n,children:[e.attachments.length>0&&(0,P.jsx)(Yd,{attachments:e.attachments,onRemove:e.onRemoveImage}),ee,(0,P.jsxs)(`div`,{className:`composer-tools`,children:[(0,P.jsx)(`input`,{ref:i,className:`image-file-input`,type:`file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,onChange:t=>{e.onAddImages(ff(t.target.files)),t.target.value=``}}),(0,P.jsxs)(`button`,{type:`button`,className:`attach-button attach-button-labeled image-attach-button`,title:`添加图片(也可粘贴或拖入)`,"aria-label":`添加图片`,onClick:()=>i.current?.click(),disabled:t||e.busy||e.attachments.length>=Hd,children:[(0,P.jsx)(Of,{name:`image`}),(0,P.jsx)(`span`,{children:`图片`})]}),(0,P.jsxs)(`button`,{className:`attach-button attach-button-labeled`,title:`在提示中输入 @ 引用项目文件`,onClick:()=>{e.setInput(`${e.input}${e.input?` `:``}@`),setTimeout(()=>{let t=e.inputRef.current;t!==null&&(t.focus(),t.setSelectionRange(t.value.length,t.value.length))},0)},disabled:t,children:[(0,P.jsx)(Of,{name:`at`}),(0,P.jsx)(`span`,{children:`文件`})]}),(0,P.jsxs)(`div`,{className:`composer-context`,children:[(0,P.jsxs)(`span`,{className:`context-item`,title:e.snapshot.workspace,children:[(0,P.jsx)(Of,{name:`folder`}),(0,P.jsx)(`span`,{children:Se(e.snapshot.workspace)})]}),(0,P.jsxs)(`span`,{className:`context-item`,children:[(0,P.jsx)(Of,{name:`monitor`}),(0,P.jsx)(`span`,{children:`本地`})]})]}),(0,P.jsxs)(`div`,{className:`composer-controls`,children:[(0,P.jsx)(Nf,{models:e.snapshot.models,activeModel:e.snapshot.activeSession?.mainModel,busy:e.busy,onSelect:e.setModel,onAdd:e.addModel}),(0,P.jsx)(`select`,{"aria-label":`权限模式`,value:e.snapshot.activeSession?.permissionMode??`default`,disabled:e.busy||e.snapshot.activeSession===void 0,onChange:t=>e.setPermission(t.target.value),children:Bd.map(e=>(0,P.jsx)(`option`,{value:e,children:be(e)},e))}),e.busy&&(0,P.jsxs)(`span`,{className:`queue-count`,title:`引导 + 后续消息`,children:[e.snapshot.activeSession?.queue.steering.length??0,`+`,e.snapshot.activeSession?.queue.followUp.length??0]}),(0,P.jsx)(`button`,{className:`send-button`,onClick:()=>e.onSend(e.busy?`steer`:void 0),disabled:t||!e.input.trim()&&e.attachments.length===0,title:e.busy?`发送引导消息`:`发送`,children:(0,P.jsx)(`span`,{children:`↑`})}),e.busy&&(0,P.jsx)(`button`,{className:`send-button stop-button`,onClick:e.onInterrupt,title:`停止任务`,children:(0,P.jsx)(`span`,{})})]})]})]}),(0,P.jsx)(`p`,{className:`composer-hint`,children:`Enter 发送 · Shift Enter 换行 · 粘贴/拖入图片 · @ 引用文件 · / 调用命令`})]})}function ff(e){return e===null?[]:Array.from(e).filter(e=>e.type.startsWith(`image/`))}function pf(e){return Array.from(e.items).some(e=>e.kind===`file`&&e.type.startsWith(`image/`))}async function mf(e){if(!Gd.has(e.type))throw Error(`不支持 ${e.type||`未知格式`};请选择 PNG、JPEG 或 WebP 图片。`);if(e.size<=0)throw Error(`${e.name} 是空文件。`);if(e.size>Ud)throw Error(`${e.name} 超过单图 5 MiB 限制。`);let t=hf(new Uint8Array(await e.arrayBuffer())),n=URL.createObjectURL(e);return{id:globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random()}`,name:e.name,mediaType:e.type,dataBase64:t,previewUrl:n}}function hf(e){let t=``,n=32768;for(let r=0;r<e.length;r+=n)t+=String.fromCharCode(...e.subarray(r,r+n));return btoa(t)}function gf({session:e,deleting:t,onCancel:n,onDelete:r}){return(0,P.jsx)(`div`,{className:`modal-layer`,children:(0,P.jsxs)(`section`,{className:`decision-sheet delete-session-sheet`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`delete-session-title`,children:[(0,P.jsx)(`div`,{className:`sheet-icon danger`,children:`×`}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{className:`sheet-kicker`,children:`删除历史会话`}),(0,P.jsxs)(`h2`,{id:`delete-session-title`,children:[`删除“`,xe(e),`”?`]}),(0,P.jsx)(`p`,{children:`此会话的消息和任务记录将从当前项目中永久删除,此操作无法撤销。`}),(0,P.jsxs)(`div`,{className:`sheet-actions`,children:[(0,P.jsx)(`button`,{disabled:t,onClick:n,children:`取消`}),(0,P.jsx)(`button`,{className:`danger`,disabled:t,onClick:r,children:t?`正在删除…`:`删除会话`})]})]})]})})}var _f=new Set([`Delete`,`Move`,`RemoveTool`]);function vf({approval:e,onResolve:t}){let n=_f.has(e.tool)||e.allowAlways===!1;return(0,P.jsx)(`div`,{className:`modal-layer`,children:(0,P.jsxs)(`section`,{className:`decision-sheet`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`approval-title`,children:[(0,P.jsx)(`div`,{className:`sheet-icon warning`,children:`!`}),(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`p`,{className:`sheet-kicker`,children:[`权限确认 · `,e.agent===`main`?`主 Agent`:`子 Agent`]}),(0,P.jsxs)(`h2`,{id:`approval-title`,children:[`允许执行 `,e.tool,`?`]}),(0,P.jsx)(`p`,{children:e.reason??`这项操作需要你的确认。`}),(e.command||e.paths?.length)&&(0,P.jsxs)(`pre`,{children:[e.command??e.paths?.join(`
154
+ `),e.args?.length?` ${e.args.join(` `)}`:``]}),(0,P.jsxs)(`div`,{className:`sheet-actions`,children:[(0,P.jsx)(`button`,{onClick:()=>t(`deny`),children:`拒绝`}),!n&&(0,P.jsx)(`button`,{onClick:()=>t(`always`),children:`始终允许同类操作`}),(0,P.jsx)(`button`,{className:`primary`,onClick:()=>t(`allow`),children:`允许一次`})]})]})]})})}function yf({questions:e,onAnswer:t}){let[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)({}),o=e.every((e,t)=>!!n[t]?.trim());return(0,P.jsx)(`div`,{className:`modal-layer`,children:(0,P.jsxs)(`section`,{className:`question-sheet`,role:`dialog`,"aria-modal":`true`,children:[(0,P.jsx)(`p`,{className:`sheet-kicker`,children:`Flavor 需要确认`}),e.map((e,t)=>(0,P.jsxs)(`fieldset`,{children:[(0,P.jsx)(`legend`,{children:e.header}),(0,P.jsx)(`p`,{children:e.question}),(0,P.jsxs)(`div`,{className:`question-options`,children:[e.options.map(e=>(0,P.jsxs)(`button`,{"data-selected":!i[t]&&n[t]===e.label,onClick:()=>{a(e=>({...e,[t]:!1})),r(n=>({...n,[t]:e.label}))},children:[(0,P.jsx)(`strong`,{children:e.label}),(0,P.jsx)(`span`,{children:e.description})]},e.label)),(0,P.jsxs)(`button`,{"data-selected":i[t]===!0,onClick:()=>{a(e=>({...e,[t]:!0})),r(e=>({...e,[t]:``}))},children:[(0,P.jsx)(`strong`,{children:`其他(自定义输入)`}),(0,P.jsx)(`span`,{children:`键入你自己的回答`})]}),i[t]===!0&&(0,P.jsx)(`input`,{className:`question-custom-input`,autoFocus:!0,value:n[t]??``,onChange:e=>r(n=>({...n,[t]:e.target.value})),placeholder:`请输入回答`,"aria-label":`${e.header} 自定义回答`})]})]},`${e.header}-${t}`)),(0,P.jsx)(`div`,{className:`sheet-actions`,children:(0,P.jsx)(`button`,{className:`primary`,disabled:!o,onClick:()=>t(n),children:`继续`})})]})})}function bf({reviews:e,autoDismissSeconds:t,onResolve:n}){return(0,P.jsxs)(`aside`,{className:`memory-review-rail`,"aria-label":`长期记忆写入确认`,children:[(0,P.jsxs)(`header`,{children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{children:`待确认`}),(0,P.jsx)(`h2`,{children:`长期记忆候选`})]}),(0,P.jsx)(`span`,{children:e.length})]}),(0,P.jsx)(`p`,{className:`memory-review-warning`,children:`以下内容由模型生成,确认前不会写入长期记忆,也不会影响后续会话。`}),(0,P.jsx)(`div`,{className:`memory-review-list`,children:e.map(e=>(0,P.jsxs)(`article`,{children:[(0,P.jsx)(`small`,{children:e.type}),(0,P.jsx)(`p`,{children:e.content}),(0,P.jsx)(xf,{seconds:t}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`button`,{onClick:()=>n(e.id,`dismiss`),children:`忽略`}),(0,P.jsx)(`button`,{className:`primary`,onClick:()=>n(e.id,`accept`),children:`保存`})]})]},e.id))})]})}function xf({seconds:e}){let[t,n]=(0,_.useState)(e);return(0,_.useEffect)(()=>{if(e<=0)return;n(e);let t=setInterval(()=>n(e=>Math.max(0,e-1)),1e3);return()=>clearInterval(t)},[e]),e<=0?null:(0,P.jsxs)(`small`,{className:`memory-review-countdown`,children:[`未操作将在 `,t,`s 后自动忽略`]})}function Sf({project:e,onStart:t}){return(0,P.jsxs)(`section`,{className:`welcome-state`,children:[(0,P.jsx)(`div`,{className:`welcome-mark`,children:(0,P.jsx)(kf,{})}),(0,P.jsx)(`p`,{children:`已连接本地项目`}),(0,P.jsxs)(`h1`,{children:[`我们应该在 `,(0,P.jsx)(`u`,{children:e}),` 中构建什么?`]}),(0,P.jsx)(`div`,{className:`starter-grid`,children:ve.map(e=>(0,P.jsx)(`button`,{onClick:()=>t(e),children:e},e))})]})}function Cf({onOpen:e}){return(0,P.jsxs)(`section`,{className:`open-state`,children:[(0,P.jsx)(`div`,{className:`welcome-mark`,children:(0,P.jsx)(kf,{})}),(0,P.jsx)(`h1`,{children:`从一个本地项目开始`}),(0,P.jsx)(`p`,{children:`Flavor 会在你选择的文件夹范围内阅读、修改和运行代码。`}),(0,P.jsx)(`button`,{onClick:e,children:`打开项目`})]})}function wf(){return(0,P.jsxs)(`div`,{className:`loading-state`,children:[(0,P.jsx)(kf,{}),(0,P.jsx)(`span`,{children:`正在准备桌面工作区…`})]})}var Tf;function Ef(){return Tf??=window.flavorDesktop.appIcon().catch(()=>void 0),Tf}function Df(){let[e,t]=(0,_.useState)(void 0);return(0,_.useEffect)(()=>{let e=!1;return Ef().then(n=>{e||t(n)}),()=>{e=!0}},[]),e}function Of({name:e}){let t;switch(e){case`plus`:t=(0,P.jsx)(`path`,{d:`M10 4v12M4 10h12`});break;case`folder`:t=(0,P.jsx)(`path`,{d:`M2.75 6.25h5l1.5 1.75h8v7.25a1.5 1.5 0 0 1-1.5 1.5h-12a1.5 1.5 0 0 1-1.5-1.5v-7.5a1.5 1.5 0 0 1 1.5-1.5Z`});break;case`sparkles`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`path`,{d:`M8.25 3.25c.4 2.4 1.6 3.6 4 4-2.4.4-3.6 1.6-4 4-.4-2.4-1.6-3.6-4-4 2.4-.4 3.6-1.6 4-4Z`}),(0,P.jsx)(`path`,{d:`M14.5 11.5c.25 1.45 1.05 2.25 2.5 2.5-1.45.25-2.25 1.05-2.5 2.5-.25-1.45-1.05-2.25-2.5-2.5 1.45-.25 2.25-1.05 2.5-2.5Z`})]});break;case`database`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`ellipse`,{cx:`10`,cy:`5`,rx:`6.25`,ry:`2.5`}),(0,P.jsx)(`path`,{d:`M3.75 5v5c0 1.38 2.8 2.5 6.25 2.5s6.25-1.12 6.25-2.5V5M3.75 10v5c0 1.38 2.8 2.5 6.25 2.5s6.25-1.12 6.25-2.5v-5`})]});break;case`server`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`rect`,{x:`3`,y:`3.5`,width:`14`,height:`5`,rx:`1.5`}),(0,P.jsx)(`rect`,{x:`3`,y:`11.5`,width:`14`,height:`5`,rx:`1.5`}),(0,P.jsx)(`path`,{d:`M6 6h.01M6 14h.01M9 6h5M9 14h5`})]});break;case`checklist`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`rect`,{x:`3.25`,y:`2.75`,width:`13.5`,height:`14.5`,rx:`2`}),(0,P.jsx)(`path`,{d:`m6.25 7 1.25 1.25L10 5.75M11.75 7h2M6.25 12h1.5M10 12h4`})]});break;case`image`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`rect`,{x:`2.75`,y:`3.25`,width:`14.5`,height:`13.5`,rx:`2`}),(0,P.jsx)(`circle`,{cx:`7`,cy:`7.25`,r:`1.25`}),(0,P.jsx)(`path`,{d:`m4.75 14 3.5-3.5 2.25 2.25 2.25-2.5 2.5 3.75`})]});break;case`at`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`circle`,{cx:`9.5`,cy:`10`,r:`3`}),(0,P.jsx)(`path`,{d:`M12.5 10v1.25c0 1.15.8 1.75 1.75 1.75 1.4 0 2.25-1.2 2.25-3a6.5 6.5 0 1 0-2.1 4.78`})]});break;case`monitor`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`rect`,{x:`2.75`,y:`3.5`,width:`14.5`,height:`10.5`,rx:`2`}),(0,P.jsx)(`path`,{d:`M7 17h6M10 14v3`})]});break;case`bell`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`path`,{d:`M5.25 8.5a4.75 4.75 0 0 1 9.5 0c0 5 2 5.5 2 5.5H3.25s2-.5 2-5.5Z`}),(0,P.jsx)(`path`,{d:`M8 16a2.25 2.25 0 0 0 4 0`})]});break;case`git`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`circle`,{cx:`5`,cy:`4`,r:`1.75`}),(0,P.jsx)(`circle`,{cx:`15`,cy:`6.5`,r:`1.75`}),(0,P.jsx)(`circle`,{cx:`5`,cy:`16`,r:`1.75`}),(0,P.jsx)(`path`,{d:`M5 5.75v8.5M6.75 7.5C11 7.5 10.5 6.5 13.25 6.5`})]});break;case`search`:t=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`circle`,{cx:`8.75`,cy:`8.75`,r:`5.25`}),(0,P.jsx)(`path`,{d:`m12.5 12.5 4 4`})]});break}return(0,P.jsx)(`svg`,{className:`ui-icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,focusable:`false`,children:t})}function kf(){let e=Df();return e===void 0?(0,P.jsxs)(`svg`,{className:`flavor-mark`,viewBox:`0 0 36 36`,"aria-hidden":`true`,children:[(0,P.jsx)(`path`,{d:`M8 17.5C8 11.7 12.5 7 18 7s10 4.7 10 10.5c0 2.7-1 5.1-2.7 7l1 3.8-4-1.2A9.5 9.5 0 0 1 18 28c-5.5 0-10-4.7-10-10.5Z`}),(0,P.jsx)(`path`,{d:`M16 15l-2 2l2 2`,fill:`none`,stroke:`#1979c9`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,P.jsx)(`path`,{d:`M20 15l2 2l-2 2`,fill:`none`,stroke:`#1979c9`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,P.jsx)(`path`,{className:`mark-smile`,d:`M14 23c2.5 1.5 5.5 1.5 8 0`}),(0,P.jsx)(`ellipse`,{cx:`22`,cy:`24`,rx:`1.2`,ry:`0.9`,fill:`#f472b6`,stroke:`#ec4899`,strokeWidth:`0.3`,transform:`rotate(15 22 24)`})]}):(0,P.jsx)(`img`,{className:`flavor-mark`,src:e,alt:``,"aria-hidden":`true`})}function Af(e){return e instanceof Error?e.message:String(e)}function jf(e){return e.replace(/^session-/,``).slice(0,17)}function Mf(e){return e?e.split(`:`).at(-1)??e:`选择模型`}function Nf({models:e,activeModel:t,busy:n,onSelect:r,onAdd:i}){let[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(),[d,f]=(0,_.useState)({provider:``,model:``,baseURL:``,apiKey:``,protocol:`openai-compatible`}),p=t??e[0]?.id,m=e.find(e=>e.id===p),h=m?.label??Mf(p),g=(e,t)=>{f(n=>({...n,[e]:t})),u(void 0)},v=async e=>{if(e.preventDefault(),s)return;let t=e.currentTarget;c(!0),u(void 0);try{await i(d),o(!1),f({provider:``,model:``,baseURL:``,apiKey:``,protocol:`openai-compatible`}),t.closest(`details`)?.removeAttribute(`open`)}catch(e){u(Af(e))}finally{c(!1)}};return(0,P.jsxs)(`details`,{className:`model-menu`,children:[(0,P.jsxs)(`summary`,{"aria-label":`主模型:${h}`,title:`切换主模型`,children:[(0,P.jsx)(`span`,{className:`model-status-dot`,"data-configured":m!==void 0}),(0,P.jsx)(`span`,{className:`model-summary-label`,children:h}),(0,P.jsx)(`span`,{className:`model-summary-chevron`,"aria-hidden":`true`})]}),(0,P.jsxs)(`div`,{className:`popover model-popover`,children:[(0,P.jsxs)(`div`,{className:`model-popover-heading`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`strong`,{children:a?`添加厂商模型`:`切换主模型`}),(0,P.jsx)(`span`,{children:a?`连接 OpenAI 兼容或 Anthropic 服务`:`DeepSeek 默认可用,也可接入其他厂商`})]}),!a&&(0,P.jsx)(`button`,{type:`button`,onClick:()=>o(!0),disabled:n,children:`+ 新增`})]}),a?(0,P.jsxs)(`form`,{className:`model-provider-form`,onSubmit:e=>void v(e),children:[(0,P.jsxs)(`div`,{className:`model-form-grid`,children:[(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`厂商名称 / ID`}),(0,P.jsx)(`input`,{required:!0,maxLength:64,placeholder:`例如 siliconflow`,value:d.provider,onChange:e=>g(`provider`,e.target.value),pattern:`[A-Za-z0-9][A-Za-z0-9_-]*`})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`模型名称`}),(0,P.jsx)(`input`,{required:!0,maxLength:256,placeholder:`例如 qwen3-coder`,value:d.model,onChange:e=>g(`model`,e.target.value)})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`接口协议`}),(0,P.jsxs)(`select`,{value:d.protocol,onChange:e=>g(`protocol`,e.target.value),children:[(0,P.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI 兼容 API`}),(0,P.jsx)(`option`,{value:`anthropic`,children:`Anthropic API`})]})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`Base URL`}),(0,P.jsx)(`input`,{required:!0,type:`url`,maxLength:2048,placeholder:`https://api.example.com/v1`,value:d.baseURL,onChange:e=>g(`baseURL`,e.target.value)})]}),(0,P.jsxs)(`label`,{children:[(0,P.jsx)(`span`,{children:`API Key`}),(0,P.jsx)(`input`,{required:!0,type:`password`,autoComplete:`off`,maxLength:16384,placeholder:`输入服务密钥`,value:d.apiKey,onChange:e=>g(`apiKey`,e.target.value)})]}),(0,P.jsxs)(`p`,{className:`model-security-note`,children:[(0,P.jsx)(`span`,{children:`◆`}),` 配置同步到当前项目,密钥只加密保存在本机。保存后会新建会话。`]}),l!==void 0&&(0,P.jsx)(`p`,{className:`model-form-error`,role:`alert`,children:l}),(0,P.jsxs)(`div`,{className:`model-form-actions`,children:[(0,P.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),u(void 0)},disabled:s,children:`取消`}),(0,P.jsx)(`button`,{type:`submit`,className:`primary`,disabled:s||n,children:s?`正在连接…`:`保存并切换`})]})]}):(0,P.jsx)(`div`,{className:`model-options`,role:`listbox`,"aria-label":`主模型`,children:e.map(e=>{let t=p===e.id;return(0,P.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,className:`model-option`,disabled:n||t,onClick:t=>{r(e.id),t.currentTarget.closest(`details`)?.removeAttribute(`open`)},children:[(0,P.jsxs)(`span`,{className:`model-option-copy`,children:[(0,P.jsx)(`strong`,{children:e.label}),(0,P.jsx)(`small`,{children:e.description})]}),e.source===`custom`&&(0,P.jsx)(`span`,{className:`model-option-badge`,children:`自定义`}),(0,P.jsx)(`span`,{className:`model-option-state`,"aria-hidden":`true`,children:t?`✓`:`→`})]},e.id)})})]})]})}function Pf(e){let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString(`zh-CN`,{hour:`2-digit`,minute:`2-digit`})}var Ff=document.getElementById(`root`);if(Ff===null)throw Error(`Desktop root element was not found`);(0,v.createRoot)(Ff).render((0,P.jsx)(_.StrictMode,{children:(0,P.jsx)(Xd,{})}));export{c as i,Xt as n,u as r,ld as t};