lantern-harness 0.1.38 → 0.1.40

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.
Files changed (118) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/500.html +4 -4
  3. package/dist/_astro/Base.CQ_XCsxM.css +1 -0
  4. package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.C17uMscj.js → Base.astro_astro_type_script_index_0_lang.rrUCMnye.js} +1 -1
  5. package/dist/_astro/CaseExecBoard.1aCJ_MsC.js +1 -0
  6. package/dist/_astro/CaseGenerateApp.C9bJ0es1.js +10 -0
  7. package/dist/_astro/CasesLibrary.DBxhr8Z1.js +21 -0
  8. package/dist/_astro/ChatApp.CRCMwSjv.js +226 -0
  9. package/dist/_astro/{DashboardBoard.BTFyQf9w.js → DashboardBoard.B-EpZOnS.js} +1 -1
  10. package/dist/_astro/{DocsFileBrowser.9WTBumS5.js → DocsFileBrowser.DceJyP9V.js} +1 -1
  11. package/dist/_astro/{DocsPager.BS20yicJ.js → DocsPager.D0TMvJ67.js} +1 -1
  12. package/dist/_astro/{DrawerField.CiHAvXHQ.js → DrawerField.CWpOf3L_.js} +1 -1
  13. package/dist/_astro/{KnowledgeLibrary.CiBRybeE.js → KnowledgeLibrary.C-_UybI5.js} +1 -1
  14. package/dist/_astro/LifeKrTasksBoard.DktIT_uO.js +1 -0
  15. package/dist/_astro/LifeKrTodosBoard.DVUmgRmh.js +1 -0
  16. package/dist/_astro/LifeObjectivesBoard.Cjg3hCkJ.js +1 -0
  17. package/dist/_astro/LifePlanTypeSelect.C63oD8zZ.js +1 -0
  18. package/dist/_astro/{LifeReviewsBoard.Bn-uxMI5.js → LifeReviewsBoard.Bj4otl26.js} +1 -1
  19. package/dist/_astro/LifeShared.-pwCbSyP.js +3 -0
  20. package/dist/_astro/LifeStagesBoard.DJpc4f7A.js +1 -0
  21. package/dist/_astro/LifeYearCycleSelect.CObXQA5s.js +1 -0
  22. package/dist/_astro/{LifeYearPlansBoard.ChAoQUB5.js → LifeYearPlansBoard.Bt6Hc8M9.js} +1 -1
  23. package/dist/_astro/PluginsPage.BWrcEbFk.js +1 -0
  24. package/dist/_astro/PluginsPage.CMeKGbb1.js +17 -0
  25. package/dist/_astro/PmBugsBoard.NUiKlz46.js +1 -0
  26. package/dist/_astro/PmIterationsBoard.C8F55feg.js +1 -0
  27. package/dist/_astro/{PmProjectDetail.DH8Z3nHb.js → PmProjectDetail.CMiWhGxn.js} +1 -1
  28. package/dist/_astro/{PmProjectsBoard.Dokaj4V1.js → PmProjectsBoard.-g9KAiZJ.js} +1 -1
  29. package/dist/_astro/PmRequirementsBoard.C0_6ye63.js +1 -0
  30. package/dist/_astro/PmRequirementsBoard.C5_NcAzj.js +1 -0
  31. package/dist/_astro/{PmShared.BJpoEYvk.js → PmShared.D6iq_Z9g.js} +1 -1
  32. package/dist/_astro/{PromptsLibrary.CNLcQ66B.js → PromptsLibrary.BLEjapm6.js} +1 -1
  33. package/dist/_astro/ReportsPage.DFsDsjow.js +1 -0
  34. package/dist/_astro/ReqAnalysisBoard.C1ki8w9Z.js +39 -0
  35. package/dist/_astro/{RequirementsLibrary.BnY7_YXU.js → RequirementsLibrary.Dat8rP5c.js} +1 -1
  36. package/dist/_astro/{SearchableSelect.5SfNLwNW.js → SearchableSelect.DFZBUFIs.js} +1 -1
  37. package/dist/_astro/SelectDropdown.Dmk5n225.js +1 -0
  38. package/dist/_astro/{SettingsDialog.DFnXkw7a.js → SettingsDialog.D486FVZ4.js} +1 -1
  39. package/dist/_astro/{SpaceSwitcher.Cy4UrzbH.js → SpaceSwitcher.Bw13MkIw.js} +2 -2
  40. package/dist/_astro/TableFieldConfig.C_NeWm8L.js +1 -0
  41. package/dist/_astro/TasksBoard.wGJOOJpR.js +1 -0
  42. package/dist/_astro/TemplatesLibrary.YIgI089k.js +1 -0
  43. package/dist/_astro/TestStatsBoard.ETea2KcX.js +1 -0
  44. package/dist/_astro/TodosBoard.OfBeAGWO.js +1 -0
  45. package/dist/_astro/UiAutoBoard.Df2ky1Cs.js +9 -0
  46. package/dist/_astro/app-version.DaJuJwsd.js +1 -0
  47. package/dist/_astro/{export.joBT53eb.js → case-fields.CmePqYfh.js} +1 -1
  48. package/dist/_astro/case-gen-run.CxlmN4EC.js +22 -0
  49. package/dist/_astro/{case-review.s1w_mD4l.js → case-review.TdDs1WFM.js} +1 -1
  50. package/dist/_astro/case-template.C-GBxgBC.js +8 -0
  51. package/dist/_astro/{req-analysis.ilj0McI3.js → req-analysis.BAC_bd4R.js} +1 -1
  52. package/dist/_astro/{story-review.Bsm2JWdj.js → story-review.CCSxTgNL.js} +1 -1
  53. package/dist/_astro/tasks.DEyD8pmq.js +1 -0
  54. package/dist/case-exec/index.html +5 -5
  55. package/dist/cases/generate/index.html +5 -5
  56. package/dist/cases/library/index.html +5 -5
  57. package/dist/dashboard/index.html +5 -5
  58. package/dist/docs/changelog/index.html +69 -44
  59. package/dist/docs/install/index.html +4 -4
  60. package/dist/docs/manual/index.html +22 -21
  61. package/dist/knowledge/index.html +5 -5
  62. package/dist/life/kr-tasks/index.html +5 -5
  63. package/dist/life/kr-todos/index.html +5 -5
  64. package/dist/life/objectives/index.html +5 -5
  65. package/dist/life/reviews/index.html +5 -5
  66. package/dist/life/stages/index.html +5 -5
  67. package/dist/life/year-plans/index.html +5 -5
  68. package/dist/plugins/index.html +5 -5
  69. package/dist/pm/bugs/index.html +5 -5
  70. package/dist/pm/iterations/index.html +5 -5
  71. package/dist/pm/projects/detail/index.html +5 -5
  72. package/dist/pm/projects/index.html +5 -5
  73. package/dist/pm/requirements/index.html +5 -5
  74. package/dist/prompts/index.html +5 -5
  75. package/dist/reports/index.html +5 -5
  76. package/dist/requirement-analysis/index.html +5 -5
  77. package/dist/requirements/index.html +5 -5
  78. package/dist/tasks/index.html +5 -5
  79. package/dist/templates/index.html +5 -5
  80. package/dist/test-automation/index.html +5 -5
  81. package/dist/test-stats/index.html +5 -5
  82. package/dist/todos/index.html +5 -5
  83. package/dist/workbench/index.html +5 -5
  84. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +18 -17
  85. package/lh-plugins/lh-mcp.mjs +4 -1
  86. package/lh-plugins/lh-todos.mjs +27 -10
  87. package/package.json +1 -1
  88. package/dist/_astro/Base.B-G3Zgu4.css +0 -1
  89. package/dist/_astro/CaseExecBoard.BWxBjYPI.js +0 -1
  90. package/dist/_astro/CaseGenerateApp.fUXTG_NE.js +0 -10
  91. package/dist/_astro/CasesLibrary.CVPhAnFf.js +0 -24
  92. package/dist/_astro/ChatApp.KceL1TNg.js +0 -226
  93. package/dist/_astro/LifeKrTasksBoard.RENBU_z9.js +0 -1
  94. package/dist/_astro/LifeKrTodosBoard.CbNnGHSZ.js +0 -1
  95. package/dist/_astro/LifeObjectivesBoard.BTGFpny2.js +0 -1
  96. package/dist/_astro/LifePlanTypeSelect.BGtEEsL-.js +0 -1
  97. package/dist/_astro/LifeShared.SnLIiFdN.js +0 -3
  98. package/dist/_astro/LifeStagesBoard.DrbIVrCK.js +0 -1
  99. package/dist/_astro/LifeYearCycleSelect.CuiWO8Tc.js +0 -1
  100. package/dist/_astro/PluginsPage.BFEwg0vr.js +0 -17
  101. package/dist/_astro/PluginsPage.CPEoYrlx.js +0 -1
  102. package/dist/_astro/PmBugsBoard.Cu1uf0TC.js +0 -1
  103. package/dist/_astro/PmIterationsBoard.RzRKkAH0.js +0 -1
  104. package/dist/_astro/PmRequirementsBoard.DET5YIVX.js +0 -1
  105. package/dist/_astro/PmRequirementsBoard.i203nmYC.js +0 -1
  106. package/dist/_astro/ReportsPage.BU3GtBvl.js +0 -1
  107. package/dist/_astro/ReqAnalysisBoard.DaOV-2Z2.js +0 -39
  108. package/dist/_astro/SelectDropdown.TgxIOKMD.js +0 -1
  109. package/dist/_astro/TasksBoard.CWkx5cD1.js +0 -1
  110. package/dist/_astro/TemplatesLibrary.phzK5kho.js +0 -1
  111. package/dist/_astro/TestStatsBoard.Dp1TWEf7.js +0 -1
  112. package/dist/_astro/TodosBoard.ofiKHKcQ.js +0 -1
  113. package/dist/_astro/UiAutoBoard.Cpb_EF46.js +0 -9
  114. package/dist/_astro/app-version.BsRPDlqD.js +0 -1
  115. package/dist/_astro/case-fields.Dqkws1iX.js +0 -1
  116. package/dist/_astro/case-gen-run.BaUxa_BR.js +0 -22
  117. package/dist/_astro/case-template.F1Nv08GV.js +0 -5
  118. package/dist/_astro/tasks.DefXqRfI.js +0 -1
@@ -0,0 +1,226 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_astro/lib.S37S0T6S.js","_astro/react.Blvh0GOs.js","_astro/jszip.min.Bh2Mgo40.js","_astro/case-fields.CmePqYfh.js"])))=>i.map(i=>d[i]);
2
+ import{s as e,t}from"./react.Blvh0GOs.js";import{B as n,H as r,U as i,V as a,W as o,i as s,p as c,r as l,t as u,u as d,z as f}from"./app-config.C4rpn1Ix.js";import{a as p,i as m,o as h,s as g,t as _}from"./plugins.C0NrHGZv.js";import{_ as v,a as y,h as b,o as x,r as S,s as C,t as w}from"./case-exec.BMNk9OyF.js";import{n as T,o as E}from"./view-prefs.8MPl3A7e.js";import{t as D}from"./react-dom.DLW9pGCF.js";import{i as O,n as k,r as ee,t as te}from"./dialog.DZHZCe_T.js";import{i as ne,n as re,r as A,t as j}from"./menu.Dnrpz489.js";import{t as ie}from"./jsx-runtime.DUg_B_vD.js";import{t as ae}from"./ConfirmDialog.D5qXeML0.js";import{t as M}from"./DatePicker.Bkl71M49.js";import{t as oe}from"./OverflowHint.pvo2Xc8R.js";import{t as N}from"./SelectDropdown.Dmk5n225.js";import{C as se,E as ce,M as le,O as P,R as F,S as ue,T as de,a as fe,d as I,g as pe,h as me,k as he,l as ge,r as L,s as R,t as _e,w as ve,x as ye,y as be}from"./pm.BXmOiFfW.js";import{t as xe}from"./SlideOverDrawer.C1IVOc_8.js";import{showToast as z}from"./Toast.BO2NFckG.js";import{a as Se,i as Ce,n as we,o as Te,r as Ee,t as De}from"./case-types.CprZTsyX.js";import{a as Oe,c as ke,l as Ae,s as je,t as Me}from"./case-gen-run.CxlmN4EC.js";import{a as Ne,c as Pe,l as Fe}from"./case-fields.CmePqYfh.js";import{c as Ie,f as Le,p as Re,r as ze,u as Be,v as Ve}from"./project-docs.DAw9bzgk.js";import{i as He,n as Ue,r as We}from"./case-template.C-GBxgBC.js";import{a as Ge,b as Ke,c as qe,f as Je,h as B,m as Ye,p as Xe,r as Ze,s as Qe,u as $e}from"./settings.NTeTjmxg.js";import{D as et,M as tt,rt as nt,y as rt,z as it}from"./req-analysis.BAC_bd4R.js";import{a as at,i as ot,r as st,s as ct,t as lt}from"./llm.DyweO-KK.js";import{n as ut,t as dt}from"./doc-roots.DAJP9Svr.js";import{a as V,l as ft,n as pt,r as mt,t as ht}from"./prompts-meta.Dnmq-SnF.js";import{t as gt}from"./ExcelFieldTags.CXif3Ilh.js";import{t as _t}from"./MultiSelectDropdown.y8JMbCxO.js";import{t as vt}from"./SearchableSelect.DFZBUFIs.js";import{A as yt,C as bt,D as xt,E as St,O as Ct,S as wt,T as Tt,_ as Et,a as Dt,b as Ot,c as kt,d as At,f as jt,g as Mt,h as Nt,i as Pt,j as Ft,k as It,l as Lt,m as Rt,n as zt,o as Bt,p as Vt,r as Ht,s as Ut,u as Wt,v as Gt,w as Kt,x as qt,y as Jt}from"./open-docs-in-session.5cTowYAC.js";import{t as Yt}from"./NamePromptDialog.Csfnh5eM.js";import{a as Xt,c as Zt,i as Qt,n as $t,o as en,r as tn,s as nn}from"./composer-task.DJmluzPT.js";import{n as rn}from"./i18n.BJeTr39S.js";import{n as an,t as on}from"./PromptMountDialog.CpTT6L0a.js";import{_ as sn,a as cn,b as ln,c as un,d as dn,f as fn,g as pn,h as mn,i as hn,l as gn,m as _n,n as vn,o as yn,p as bn,r as xn,s as Sn,t as Cn,u as wn,v as Tn,y as En}from"./fs-tools.3F9MFrLf.js";import{C as Dn,D as On,E as H,F as kn,O as An,P as jn,S as Mn,T as Nn,_ as Pn,a as Fn,b as In,c as Ln,d as Rn,g as zn,i as Bn,j as U,k as Vn,l as Hn,m as Un,n as Wn,o as Gn,r as Kn,t as W,u as qn,v as Jn,x as Yn,y as Xn}from"./tasks.DEyD8pmq.js";import{_ as Zn,a as Qn,c as $n,d as er,f as tr,g as nr,h as rr,i as ir,l as ar,m as or,n as sr,o as cr,p as lr,r as ur,s as dr,t as fr,u as pr,v as mr,y as hr}from"./bash-tools.RQcI4_42.js";import{C as gr,S as _r,_ as vr,a as yr,b as br,c as xr,d as G,g as Sr,h as Cr,i as wr,l as Tr,m as Er,n as Dr,o as Or,p as kr,r as Ar,s as jr,t as Mr,u as Nr,v as Pr,w as Fr,x as Ir,y as Lr}from"./PluginsPage.CMeKGbb1.js";import{l as Rr,r as zr,t as Br}from"./report-prompt.B9C4cv84.js";import{s as Vr}from"./test-stats.Cf3_L4wu.js";import{i as Hr}from"./ui-auto-prompt.l_EXfDs5.js";import{h as Ur}from"./ui-auto.BmC9JJ_X.js";import{b as Wr,l as Gr,v as Kr}from"./story-review.CCSxTgNL.js";var K=e(t(),1),qr=e(D(),1),q=`/__tb_sessions/runs`;async function Jr(e){try{return(await fetch(q,{signal:e??AbortSignal.timeout(1500)})).ok}catch{return!1}}async function Yr(e){let t=await fetch(q,{signal:e??AbortSignal.timeout(3e3)});if(!t.ok)return[];let n=await t.json();return Array.isArray(n.runs)?n.runs:[]}async function Xr(e){let t=await fetch(q,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error||`HTTP ${t.status}`}}async function Zr(e){await fetch(`${q}/${encodeURIComponent(e)}/stop`,{method:`POST`}).catch(()=>{})}async function Qr(e){try{let t=await fetch(`${q}/${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(3e3)});return t.status===404?{ok:!1}:t.ok?await t.json():null}catch{return null}}function $r(e){return e===`completed`||e===`stopped`||e===`error`}function ei(e,t,n,r){let i=new AbortController,a=`${q}/${encodeURIComponent(e)}/events?after=${Math.max(0,t)}`;return(async()=>{try{let e=await fetch(a,{headers:{Accept:`text/event-stream`},signal:i.signal});if(!e.ok||!e.body){r?.(Error(`SSE ${e.status}`));return}let t=e.body.getReader(),o=new TextDecoder,s=``;for(;;){let{done:e,value:a}=await t.read();if(e){i.signal.aborted||r?.(Error(`SSE disconnected`));break}s+=o.decode(a,{stream:!0});let c=s.split(`
3
+ `);s=c.pop()??``;for(let e of c){let t=e.trim();if(!t.startsWith(`data:`))continue;let r=t.slice(5).trim();if(r)try{n(JSON.parse(r))}catch{}}}}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;r?.(e instanceof Error?e:Error(String(e)))}})(),()=>i.abort()}function ti(e,t,n){let r=!1,i=Math.max(0,t),a=0,o=null,s,c=n.maxAttempts??10,l=()=>{r=!0,s!=null&&clearTimeout(s),s=void 0,o?.(),o=null},u=()=>{r||n.signal?.aborted||(o?.(),o=ei(e,i,e=>{typeof e.seq==`number`&&Number.isFinite(e.seq)&&(i=Math.max(i,e.seq)),n.onEvent(e),e.type===`status`&&$r(e.status)&&(n.onTerminal?.(e),l())},t=>{r||n.signal?.aborted||(async()=>{a+=1;try{let r=await Qr(e);if(r?.ok&&typeof r.seq==`number`&&(i=Math.max(i,r.seq)),r?.ok&&$r(r.status)){let e={type:`status`,status:r.status,seq:r.seq,assistant:r.assistant};n.onEvent(e),n.onTerminal?.(e),l();return}if(r&&r.ok===!1){n.onGaveUp?.(Error(t.message||`run not found`)),l();return}}catch{}if(a>=c){n.onGaveUp?.(t),l();return}let r=Math.min(4e3,250*a);s=setTimeout(u,r)})()}))},d=()=>l();return n.signal?.addEventListener(`abort`,d),u(),()=>{n.signal?.removeEventListener(`abort`,d),l()}}function ni(e){for(let t of e)if(t.role===`user`&&typeof t.content==`string`){let e=t.content.trim();if(e)return e}return``}function ri(e,t){let n=(e||``).trim()||`新对话`;return n===`新对话`||n===St(t)}function ii(e){let t=String(e??``).trim().replace(/^["「『]+|["」』]+$/g,``).replace(/\s+/g,` `).replace(/^标题[::]\s*/i,``);return t=t.replace(/[。.!!]+$/g,``).trim(),t?t.length>28?`${t.slice(0,28)}…`:t:``}async function ai(e,t,n){let r=t.trim().slice(0,800);if(!r)return null;let i=[{role:`system`,content:`你为对话生成侧栏短标题。只输出标题本身:中文优先,不超过 16 个字,无引号、无标点收尾、无解释。`},{role:`user`,content:`用户首条消息:\n${r}\n\n请给出标题:`}];try{return ii(await st(e,i,n))||null}catch{return null}}function oi(e){let t=Array.isArray(e.messages)?e.messages:[],n=0,r=0,i=0,a=0,o=0;for(let e of t){if(!e||typeof e!=`object`)continue;let t=e;t.role===`user`?n+=1:t.role===`assistant`&&(r+=1);let s=t.usage;if(s&&typeof s==`object`){let e=s;typeof e.promptTokens==`number`&&(i+=e.promptTokens),typeof e.completionTokens==`number`&&(a+=e.completionTokens),typeof e.totalTokens==`number`?o+=e.totalTokens:(typeof e.promptTokens==`number`||typeof e.completionTokens==`number`)&&(o+=(Number(e.promptTokens)||0)+(Number(e.completionTokens)||0))}}let s=e.goal,c=!!(s&&s.status!==`cleared`&&s.text?.trim());return{sessionId:e.id,title:e.title||`新对话`,messageCount:t.length,userCount:n,assistantCount:r,promptTokens:i,completionTokens:a,totalTokens:o,createdAt:e.createdAt,updatedAt:e.updatedAt,hasGoal:c,todoCount:Array.isArray(e.todos)?e.todos.length:0}}function si(e){let t=new Date(e.createdAt).toLocaleString(),n=new Date(e.updatedAt).toLocaleString();return[`会话:${e.title}`,`消息 ${e.messageCount}(用户 ${e.userCount} / 助手 ${e.assistantCount})`,`用量≈ 输入 ${e.promptTokens} · 输出 ${e.completionTokens} · 合计 ${e.totalTokens}`,`待办 ${e.todoCount} · 目标 ${e.hasGoal?`有`:`无`}`,`创建 ${t}`,`更新 ${n}`].join(`
4
+ `)}var ci=new Map,li=new Map,ui=40;function di(e,t,n=``){return`${e}:${t}:${n}`}function fi(e){for(;e.size>ui;){let t=e.keys().next().value;if(t===void 0)break;e.delete(t)}}function pi(e,t,n,r,i=``){let a=e===`outline`?ci:li,o=di(t,n,i),s=a.get(t);if(s&&s.stamp===o)return s.value;let c=r();return a.set(t,{stamp:o,value:c}),fi(a),c}var mi=`/__tb_sessions/log`;function hi(e){let t=String(e.userContent??``).trim(),n=String(e.assistantContent??``).trim(),r=String(e.reasoning??``).trim(),i=[];if(t&&i.push({role:`user`,content:t}),n||r){let e={role:`assistant`,content:n};r&&(e.reasoning_content=r),i.push(e)}return i}async function gi(e){try{let t=await fetch(mi,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:AbortSignal.timeout(5e3)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,path:n.path}:{ok:!1,error:n.error||`HTTP ${t.status}`}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}}function _i(e){return String(e??``).trim()}function vi(e,t=80){let n=_i(e).replace(/\s+/g,` `);return n?n.length>t?`${n.slice(0,t)}…`:n:``}function yi(e,t=40){let n=[],r=null;for(let i=0;i<e.length;i++){let a=e[i];if(a.role===`user`){let e=_i(a.content),t=vi(e);if(!t)continue;r&&n.push({index:n.length+1,userPreview:r.preview,assistantPreview:``,userText:r.text,assistantText:``,userTime:r.time,endMessageIndex:r.messageIndex}),r={text:e,preview:t,time:typeof a.time==`number`?a.time:void 0,messageIndex:i}}else if(a.role===`assistant`&&r){let e=_i(a.content),t=_i(a.reasoning)||void 0;n.push({index:n.length+1,userPreview:r.preview,assistantPreview:vi(e)||(t?`(含思考)`:``),userText:r.text,assistantText:e,reasoning:t,reasoningDuration:typeof a.reasoningDuration==`number`?a.reasoningDuration:void 0,userTime:r.time,assistantTime:typeof a.time==`number`?a.time:void 0,endMessageIndex:i}),r=null}if(n.length>=t)break}return r&&n.length<t&&n.push({index:n.length+1,userPreview:r.preview,assistantPreview:``,userText:r.text,assistantText:``,userTime:r.time,endMessageIndex:r.messageIndex}),n}function bi(e,t){let n=String(t??``).trim();return!n||n===`inherit`||n===e.model?e:{...e,model:n}}var xi=`/__tb_fs`,Si=`你可以使用 office_to_pdf:优先用本机 LibreOffice 转为 PDF;若未安装,则对 docx/xlsx/pptx 降级抽取正文为同目录 .extracted.md(需写权限)。`,Ci={type:`function`,function:{name:`office_to_pdf`,description:`Convert Office docs to PDF via LibreOffice when available; otherwise extract text to .extracted.md for docx/xlsx/pptx.`,parameters:{type:`object`,properties:{path:{type:`string`,description:`Input file path relative to workspace (or absolute when allowed)`},outDir:{type:`string`,description:`Optional output directory (default: same as input)`}},required:[`path`]}}};async function wi(e,t,n){if(e!==`office_to_pdf`)return JSON.stringify({error:`unknown tool: ${e}`});let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({ok:!1,error:`invalid JSON arguments`})}let i=String(r.path??``).trim();if(!i)return JSON.stringify({ok:!1,error:`path is required`});try{let e=await(await fetch(`${xi}/office-to-pdf`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:i,outDir:typeof r.outDir==`string`?r.outDir:void 0,access:n}),signal:AbortSignal.timeout(13e4)})).json().catch(()=>({}));return JSON.stringify(e,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}var Ti=`/__tb_fs`,Ei=`你可以使用 load_workspace_dependencies:查询本机 node / npm / pnpm / python 等可执行文件绝对路径(需本地 fs 服务)。`,Di={type:`function`,function:{name:`load_workspace_dependencies`,description:`Resolve absolute paths of common runtimes/package managers on this machine (node, npm, pnpm, python, …).`,parameters:{type:`object`,properties:{}}}};async function Oi(e){if(e!==`load_workspace_dependencies`)return JSON.stringify({error:`unknown tool: ${e}`});try{let e=await fetch(`${Ti}/workspace-dependencies`,{signal:AbortSignal.timeout(8e3)}),t=await e.json().catch(()=>({}));if(!e.ok){let n=typeof t==`object`&&t&&`error`in t?String(t.error):`HTTP ${e.status}`;return JSON.stringify({ok:!1,error:n})}return JSON.stringify(t,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}function ki(e){return Array.isArray(e)}function Ai(e){return ki(e)?e.some(e=>e.type===`image_url`):!1}function ji(e){let t=e.filter(e=>e.type===`text`).map(e=>e.text),n=e.filter(e=>e.type===`image_url`).length,r=n>0?`[image-offload] 已卸载 ${n} 张图片(超预算,仅保留最近附图)。`:``;return[{type:`text`,text:[...t,r].filter(Boolean).join(`
5
+ `)||r||`(图片已卸载)`}]}function Mi(e,t={}){let n=Math.max(0,Math.floor(t.keepRecentImageMessages??1)),r=[];for(let t=0;t<e.length;t++){let n=e[t];n.role===`user`&&Ai(n.content)&&r.push(t)}if(r.length<=n)return e;let i=new Set(r.slice(-n)),a=!1,o=e.map((e,t)=>e.role!==`user`||!Ai(e.content)||i.has(t)||!ki(e.content)?e:(a=!0,{...e,content:ji(e.content)}));return a?o:e}var Ni=/(\s*(TP-[A-Za-z0-9_-]+)\s*)|\(\s*(TP-[A-Za-z0-9_-]+)\s*\)/i;function Pi(e){let t=String(e||``).replace(/\r\n/g,`
6
+ `);if(!t.trim())return[];let n=t.split(`
7
+ `),r=[],i=``,a=null,o=()=>{a&&a.lines.some(e=>e.trim())&&r.push(a),a=null};for(let e of n)if(/^#{1,6}\s/.test(e.trim())||/^#{1,6}\s/.test(e))o(),i=e;else if(/^\s*-\s+\*\*/.test(e)){let t=e.match(Ni),n=(t?.[1]||t?.[2]||``).toUpperCase();o(),a={id:n||`anon_${r.length+1}`,storyHeader:i,lines:[e]}}else a&&a.lines.push(e);return o(),r}function Fi(e,t){if(!t.length)return``;let n=new Set(t.map(e=>e.toUpperCase())),r=e.filter(e=>n.has(e.id.toUpperCase()));if(!r.length)return``;let i=[],a=`\0`;for(let e of r)e.storyHeader&&e.storyHeader!==a&&(a=e.storyHeader,i.push(e.storyHeader)),i.push(...e.lines);return i.join(`
8
+ `).trim()}function Ii(e,t){let n=Math.max(1,Math.floor(t)),r=[];for(let t=0;t<e.length;t+=n)r.push(e.slice(t,t+n));return r}function Li(e,t){let n=t?.maxPerBatch??40,r=t?.threshold??40,i=(e.testPointIds??[]).map(e=>String(e).trim()).filter(Boolean);if(i.length<=r)return[{index:1,total:1,ids:i,testPointBlock:e.testPointBlock??``,label:i.length?`${i.length} 条测试点`:`全量`}];let a=Pi(e.testPointBlock??``),o=new Map(a.map(e=>[e.id.toUpperCase(),e])),s=Ii(i.map(e=>e.toUpperCase()),n),c=s.length;return s.map((t,n)=>{let r=t.map(e=>o.get(e)).filter(Boolean),i=r.length>0?Fi(r,t):Ri(e.testPointBlock??``,t),a=t[0]??``,s=t[t.length-1]??``;return{index:n+1,total:c,ids:t,testPointBlock:i,label:`${a}…${s}(${t.length} 条)`}})}function Ri(e,t){let n=new Set(t.map(e=>e.toUpperCase())),r=String(e||``).replace(/\r\n/g,`
9
+ `).split(`
10
+ `),i=[],a=``,o=!1;for(let e of r)if(/^#{1,6}\s/.test(e))a=e,o=!1;else if(/^\s*-\s+\*\*/.test(e)){let t=e.match(Ni),r=(t?.[1]||t?.[2]||``).toUpperCase();o=!!(r&&n.has(r)),o&&(a&&i[i.length-1]!==a&&i.push(a),i.push(e))}else o&&i.push(e);return i.join(`
11
+ `).trim()}function zi(e,t){return{...e,testPointIds:t.ids.length?t.ids:e.testPointIds,testPointBlock:t.testPointBlock||e.testPointBlock}}function Bi(){let e=l().promptKinds;return r(e?.length?e:f)}function Vi(e){let t=Bi();return t.find(t=>t.id===e)??t[0]??f[0]}function Hi(e){let t=r(e);return d({promptKinds:t}),u(),t}function Ui(e){let t=e.trim();if(!t)throw Error(`类型名称不能为空`);if(t.length>40)throw Error(`类型名称过长(最多 40 字)`);let r=Bi();if(r.some(e=>e.label===t))throw Error(`已存在「${t}」`);let i={id:a(),label:t,hint:n(t)};return Hi([...r,i]),i}function Wi(e,t){let r=t.trim();if(!r)throw Error(`类型名称不能为空`);if(r.length>40)throw Error(`类型名称过长(最多 40 字)`);let i=Bi(),a=i.findIndex(t=>t.id===e);if(a<0)throw Error(`类型不存在`);if(i.some(t=>t.id!==e&&t.label===r))throw Error(`已存在「${r}」`);let o=i[a],s={...o,label:r,hint:o.id===`case`||o.id===`general`?o.hint:n(r)},c=[...i];return c[a]=s,Hi(c),s}function Gi(e){let t=Bi();if(t.length<=1)throw Error(`至少保留一个提示词类型`);if(!t.some(t=>t.id===e))throw Error(`类型不存在`);return Hi(t.filter(t=>t.id!==e))}function Ki(e){return`${Vi(e.kind).label} · ${e.titleHint.trim()||`未命名`}`}function qi(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(!e||typeof e!=`object`)return null;let n=e.提示词名称??e.title??e.name,r=e.正文??e.body??e.content??e.markdown,i=typeof n==`string`?n.trim():``,a=typeof r==`string`?r.trim():``;if(!a)return null;let o=e.质检通过??e.qcPass??e.pass,s=typeof o==`boolean`?o:typeof o!=`string`||!/^(false|0|no|否|未通过|fail)/i.test(o.trim()),c=e.质检问题??e.qcIssues??e.issues,l=Array.isArray(c)?c.map(e=>String(e).trim()).filter(Boolean):typeof c==`string`&&c.trim()?[c.trim()]:[],u=e.质检说明??e.qcNote??e.note;return{title:i,body:a,qcPass:s,qcIssues:l,qcNote:typeof u==`string`?u.trim():``}}catch{return null}}function Ji(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名提示词`}function Yi(e,t=``){let n=[...e.qcIssues],r=(e.title||t||`未命名提示词`).trim();e.qcPass||n.push(`模型自检未通过(质检通过=false)`),(!r||r.length<2)&&n.push(`提示词名称过短(至少 2 字)`),r.length>80&&n.push(`提示词名称过长(最多 80 字)`),/[\\/]/.test(r)&&n.push(`提示词名称不可包含路径分隔符`);let i=Ji(r),a=`${i}.md`;V(a,p())&&n.push(`不可覆盖受保护提示词「${a}」:${ft(a,p())}`),e.body.trim()?e.body.trim().length<80&&n.push(`正文过短(建议不少于 80 字)`):n.push(`正文为空`),!/^#\s+/m.test(e.body)&&!e.body.includes(`
12
+ `)&&n.push(`正文建议使用 Markdown 标题与分段结构`);let o=[...new Set(n.filter(Boolean))];return{ok:o.length===0,issues:o,title:r,fileBase:i}}function Xi(e){return`你是资深提示词工程师,擅长为测试与研发场景编写可落地的中文提示词。
13
+
14
+ 【任务】
15
+ 根据用户在对话中的需求,编写一份完整的 Markdown 提示词正文,供后续入库到提示词库。
16
+ 具体要求以用户本轮及近期对话输入为准。
17
+
18
+ 【类型】
19
+ ${Vi(e.kind).hint}
20
+
21
+ 【用户期望名称】
22
+ ${e.titleHint.trim()||`(可在结果中自拟简洁中文名)`}
23
+
24
+ 【输出前自检(必须)】
25
+ 1. 角色与目标是否清晰?
26
+ 2. 约束是否可执行、无互相矛盾?
27
+ 3. 是否避免空话与不可判定要求?
28
+ 4. 用例类提示词:是否要求按模板字段输出、步骤换行、按需求覆盖(不设固定条数)?
29
+ 5. 若未通过,将「质检通过」设为 false,并在「质检问题」列出具体项。
30
+
31
+ 【输出格式(强制)】
32
+ 仅输出一个 JSON 对象(可无代码围栏),不要其它解释:
33
+ {
34
+ "提示词名称": "简短中文名(不含 .md)",
35
+ "质检通过": true,
36
+ "质检问题": [],
37
+ "质检说明": "一句话说明质检结论",
38
+ "正文": "# 标题\\n\\n完整 Markdown 正文……"
39
+ }
40
+
41
+ 约束:
42
+ - 「正文」为完整 Markdown 字符串,可含换行;不要把正文拆到 JSON 外。
43
+ - 「质检通过」为 false 时系统不会入库。
44
+ - 不要输出 JSON 以外的闲聊;界面只展示执行摘要。`}function Zi(e=0){let t=Math.max(0,Math.floor(e));return`正在编写提示词…\n\n进度约 ${Math.min(95,Math.max(1,Math.round(95*(1-Math.exp(-t/90)))))}% · 已用 ${t}s\n完成后将质检并自动入库到提示词管理。`}function Qi(e){if(!e.ok){let t=[`**执行失败 / 未入库**`,``,e.error||`质检未通过或解析失败`],n=e.issues??[];if(n.length){t.push(``,`**质检问题**`);for(let e of n)t.push(`- ${e}`)}return t.push(``,`可在对话中补充要求后重新发送,或在插件中修改名称/类型。`),t.join(`
45
+ `)}let t=[`**执行成功**`,``,`- 提示词名称:${e.title||`—`}`];return e.path&&t.push(`- 入库文件:提示词管理/${e.path}`),e.qcNote&&t.push(``,`**质检说明**`,e.qcNote),t.push(``,`下方卡片可点击打开文件。`),t.join(`
46
+ `)}async function $i(e){let t=`${e}.md`;try{let{entries:n}=await Ie(`prompts`,`.`),r=new Set(n.filter(e=>e.type===`file`).map(e=>e.name));if(!r.has(t))return t;for(let t=2;t<100;t++){let n=`${e}-${t}.md`;if(!r.has(n))return n}}catch{}return`${e}-${Date.now().toString(36)}.md`}async function ea(e,t){let n=qi(e);if(!n){let e=`未能解析出提示词结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:Qi({ok:!1,error:e})}}let r=Yi(n,t.titleHint);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:Qi({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!m(`prompts`)){let e=g(`prompts`);return{ok:!1,error:e,issues:[],summary:Qi({ok:!1,error:e})}}try{let e=await $i(r.fileBase);await Ve(`prompts`,e,n.body.endsWith(`
47
+ `)?n.body:`${n.body}\n`);let t=Qi({ok:!0,title:r.title,path:e,qcNote:n.qcNote});return{ok:!0,path:e,title:r.title,qcNote:n.qcNote,summary:t}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,issues:[],summary:Qi({ok:!1,error:t})}}}function ta(){let e=l().knowledgeCategories;return e?.length?[...e]:[...i]}function na(e){let t=o(e);return d({knowledgeCategories:t}),u(),t}function ra(e){let t=e.trim();if(!t)throw Error(`分类名称不能为空`);if(t.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(t))throw Error(`分类名称不可包含路径分隔符`);let n=ta();if(n.includes(t))throw Error(`已存在「${t}」`);return na([...n,t]),t}function ia(e,t){let n=t.trim();if(!n)throw Error(`分类名称不能为空`);if(n.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(n))throw Error(`分类名称不可包含路径分隔符`);let r=ta(),i=r.indexOf(e);if(i<0)throw Error(`分类不存在`);if(r.some((e,t)=>t!==i&&e===n))throw Error(`已存在「${n}」`);let a=[...r];return a[i]=n,na(a),n}function aa(e){let t=ta();if(t.length<=1)throw Error(`至少保留一个分类`);if(!t.includes(e))throw Error(`分类不存在`);return na(t.filter(t=>t!==e))}function oa(e){let t=e.titleHint.trim()||`未命名`;return`${e.category} · ${t}`}function sa(e){return ta().includes(e)}function ca(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(!e||typeof e!=`object`)return null;let n=e.标题??e.知识库名称??e.title??e.name,r=e.分类??e.category,i=e.描述??e.description,a=e.正文??e.body??e.content??e.markdown,o=typeof n==`string`?n.trim():``,s=typeof r==`string`?r.trim():``,c=typeof i==`string`?i.trim():``,l=typeof a==`string`?a.trim():``;if(!l)return null;let u=e.质检通过??e.qcPass??e.pass,d=typeof u==`boolean`?u:typeof u!=`string`||!/^(false|0|no|否|未通过|fail)/i.test(u.trim()),f=e.质检问题??e.qcIssues??e.issues,p=Array.isArray(f)?f.map(e=>String(e).trim()).filter(Boolean):typeof f==`string`&&f.trim()?[f.trim()]:[],m=e.质检说明??e.qcNote??e.note;return{title:o,category:s,description:c,body:l,qcPass:d,qcIssues:p,qcNote:typeof m==`string`?m.trim():``}}catch{return null}}function la(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名知识`}function ua(e){let t=e.trim();return!t||/[:#{}[\],&*?|>!<>=%@`"'\\\n]/.test(t)||/^\s|\s$/.test(e)?JSON.stringify(t):t}function da(e){return(e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?([\s\S]*)$/)?.[1]??e).trim()}function fa(e){let t=e.description.trim(),n=da(e.body),r=n.startsWith(`#`)?n:`# ${e.title}\n\n${n}`,i=[`---`,`title: ${ua(e.title)}`,`category: ${ua(e.category)}`];return t&&i.push(`description: ${ua(t)}`),i.push(`---`,``,r,``),i.join(`
48
+ `)}function pa(e,t){let n=[...e.qcIssues],r=(e.title||t.titleHint||`未命名知识`).trim(),i=(e.category||t.category||``).trim();sa(i)||(i=t.category),e.qcPass||n.push(`模型自检未通过(质检通过=false)`),(!r||r.length<2)&&n.push(`标题过短(至少 2 字)`),r.length>80&&n.push(`标题过长(最多 80 字)`),/[\\/]/.test(r)&&n.push(`标题不可包含路径分隔符`),sa(i)||n.push(`分类必须是:${ta().join(` / `)}`),e.body.trim()?e.body.trim().length<60&&n.push(`正文过短(建议不少于 60 字)`):n.push(`正文为空`);let a=[...new Set(n.filter(Boolean))];return{ok:a.length===0,issues:a,title:r,category:i,fileBase:la(r),description:(e.description||``).trim().slice(0,120)}}function ma(e){let t=e.titleHint.trim()||`(可在结果中自拟简洁中文名)`;return`你是资深测试知识库编辑,擅长把规范、方法论、环境约定写成可复用的 Markdown 文档。
49
+
50
+ 【任务】
51
+ 根据用户在对话中提供的素材/需求,编写一份完整的知识库 Markdown 正文,入库到知识库对应分类目录。
52
+ 具体要求以用户本轮及近期对话输入为准。
53
+
54
+ 【目标分类】
55
+ ${e.category}
56
+ (分类仅限:${ta().join(` / `)};不要写成需求文档或测试用例)
57
+
58
+ 【用户期望标题】
59
+ ${t}
60
+
61
+ 【内容要求】
62
+ 1. 结构清晰:标题、条目/表格/步骤可执行;避免空话。
63
+ 2. 可复用:适合后续对话用「@」引用。
64
+ 3. 不要输出用例表格字段集;不要写成需求 PRD。
65
+
66
+ 【输出前自检(必须)】
67
+ 1. 分类是否正确?
68
+ 2. 标题是否简洁可作文件名?
69
+ 3. 正文是否可落地、无互相矛盾?
70
+ 4. 若未通过,将「质检通过」设为 false,并在「质检问题」列出具体项。
71
+
72
+ 【输出格式(强制)】
73
+ 仅输出一个 JSON 对象(可无代码围栏),不要其它解释:
74
+ {
75
+ "标题": "简短中文名(不含 .md)",
76
+ "分类": "${e.category}",
77
+ "描述": "一句话摘要",
78
+ "质检通过": true,
79
+ "质检问题": [],
80
+ "质检说明": "一句话说明质检结论",
81
+ "正文": "# 标题\\n\\n完整 Markdown 正文……"
82
+ }
83
+
84
+ 约束:
85
+ - 「正文」为完整 Markdown 字符串(可含换行);frontmatter 由系统自动拼接,正文不要再写 --- frontmatter。
86
+ - 「质检通过」为 false 时系统不会入库。
87
+ - 不要输出 JSON 以外的闲聊;界面只展示执行摘要。`}function ha(e=0){let t=Math.max(0,Math.floor(e));return`正在编写知识库文档…\n\n进度约 ${Math.min(95,Math.max(1,Math.round(95*(1-Math.exp(-t/90)))))}% · 已用 ${t}s\n完成后将质检并自动入库到知识库管理。`}function ga(e){if(!e.ok){let t=[`**执行失败 / 未入库**`,``,e.error||`质检未通过或解析失败`],n=e.issues??[];if(n.length){t.push(``,`**质检问题**`);for(let e of n)t.push(`- ${e}`)}return t.push(``,`可调整说明后重新发送,或在插件中修改分类/标题。`),t.join(`
88
+ `)}let t=[`**执行成功**`,``,`- 标题:${e.title||`—`}`];return e.category&&t.push(`- 分类:${e.category}`),e.path&&t.push(`- 入库文件:知识库管理/${e.path}`),e.qcNote&&t.push(``,`**质检说明**`,e.qcNote),t.push(``,`下方卡片可点击打开文件;对话中也可用「@」引用(构建后或刷新列表)。`),t.join(`
89
+ `)}async function _a(e){let t=`${e}.md`;try{let{entries:n}=await Ie(`knowledge`,`.`),r=new Set(n.filter(e=>e.type===`file`).map(e=>e.name));if(!r.has(t))return t;for(let t=2;t<100;t++){let n=`${e}-${t}.md`;if(!r.has(n))return n}}catch{}return`${e}-${Date.now().toString(36)}.md`}async function va(e,t){let n=ca(e);if(!n){let e=`未能解析出知识库结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:ga({ok:!1,error:e})}}let r=pa(n,t);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:ga({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!m(`knowledgeLib`)){let e=g(`knowledgeLib`);return{ok:!1,error:e,issues:[],summary:ga({ok:!1,error:e})}}try{let e=await _a(r.fileBase),t=fa({title:r.title,category:r.category,description:r.description,body:n.body});await Ve(`knowledge`,e,t.endsWith(`
90
+ `)?t:`${t}\n`);let i=ga({ok:!0,title:r.title,path:e,category:r.category,qcNote:n.qcNote});return{ok:!0,path:e,title:r.title,category:r.category,qcNote:n.qcNote,summary:i}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,issues:[],summary:ga({ok:!1,error:t})}}}var ya=`你是 Lantern Harness(仓库 lantern-harness)的「插件开发」助手,只负责在本项目里开发「扩展插件」。
91
+
92
+ # 铁律:先评估、再确认、后开发
93
+ 1. 收到需求后,先只读调研相关代码(fs_read / fs_glob / fs_grep,必要时用只读命令),弄清现有插件约定。
94
+ 调研纪律:先用 fs_grep 定位符号 / 字符串,再只读命中片段;不要为了「看清楚」把整个目录、整份大文件逐个读一遍;
95
+ 与本次插件无关的模块不必打开;发出确认选项前,读取次数控制在必要范围(一般 8 次以内,确有必要再增加)。
96
+ 2. 在改任何文件之前,必须调用 ask_user_question 提出 2~4 个选择题(每题 2~4 个选项),覆盖:
97
+ - 插件形态:纯提示词型 / 带配置面板 / 侧栏库 / 需要本地服务能力
98
+ - 范围与边界:做什么、不做什么
99
+ - 命名与入口:插件 id / 中文名 / 从「+」「/」还是侧栏进入
100
+ - 默认开关:新插件在新建空间里默认开还是关(推荐默认关)
101
+ 每题给出推荐项,便于用户直接确认。
102
+ 3. 用户回答之前,禁止 fs_write / fs_mkdir / 改配置 / 写文档;这一轮只允许只读调研。
103
+ 4. 用户确认后才开始实现;用户改选或补充要求时,按新答案调整后再动手。
104
+ 5. 「确认」只认用户明确表达(如「开始实施」「按这个方案做」「确认」)。用户跳过(skipped)、关闭提问卡片、没作答、沉默,都不算确认,也绝不等于批准实施:
105
+ - 这类情况先停手,用几行说明你将采用的默认假设(哪几项按推荐)、插件形态与准备改动的文件范围;
106
+ - 然后等用户明确回复「开始实施」再写文件;跳过当轮只能写代码计划,禁止 fs_write / fs_mkdir / 改配置。
107
+ 6. 只改与本次插件相关的文件:不重构无关代码、不改主题样式、不动其它插件行为、不执行 git commit / git push。
108
+ 7. 完成后用简短条目汇报:插件 id / 中文名 / 入口位置 / 默认开关 / 改动文件 / 用户如何验证。
109
+
110
+ # 项目插件实现位置(先读再改)
111
+ - 注册表:src/lib/plugins.ts → PluginId 联合类型 + PLUGIN_CATALOG(字段:id/name/description/version/requiresDev/defaultEnabled/hasPanel/requires)
112
+ - 新建空间默认开关:config/app.defaults.json 的 plugins;同时补 src/lib/app-config.ts 的 emptyAppConfig().plugins
113
+ - 我的插件页:src/components/islands/PluginsPage.tsx(按注册表自动渲染;Tab「扩展插件」即扩展插件列表,卡片按 PLUGIN_CATALOG 的 category 分组)
114
+ - 工作台入口:hasPanel=true 的插件会自动出现在「+」弹窗与「/」菜单;入口文案与面板打开逻辑在 src/components/islands/ChatApp.tsx(pluginMenuItems / openPluginPanel / pickPluginMenu / 菜单 tip)
115
+ - 胶囊型入口(与「计划」「插件开发」一致):在 ChatApp 的 composerChip 增加一个取值,+ 菜单里点击后只激活胶囊,用户在主输入框描述要求后发送
116
+ - 带配置面板的插件:新建 src/components/islands/XxxPanel.tsx(复用 SlideOverDrawer);配置类型放 src/lib/xxx.ts;若配置需要跟会话保存,加到 src/lib/sessions.ts 的 ChatSession 与 SessionMetaPatch,并在 ChatApp 的会话切换 / 新建流程里同步
117
+ - 纯提示词型插件:在 src/lib/xxx.ts 导出固定系统提示词与 buildXxxSystemPrompt(),在 ChatApp 的 executeSend 里按会话配置替换 baseSystem
118
+ - 侧栏库:src/lib/nav-menu.ts(NavEntryId / NavEntryDef / i18n 键)、src/lib/plugin-nav.ts、src/components/islands/NavLibraries.tsx、src/lib/i18n.ts,以及 lh-plugins/lh-project-docs.mjs 的 DOC_ROOT_DIRS
119
+ - 本地 API:新建 lh-plugins/lh-xxx.mjs(导出 lhXxxPlugin,提供 configureServer 中间件),并在 astro.config.mjs 与 cli/server.mjs 的插件列表里注册;数据根用 builtin/session/space-context.mjs 的 getDataRoot() / getBaseRoot();PLUGIN_CATALOG 里补 category(内容库 / 生成能力 / 记忆与检索 / 待办与效率 / 开发工具),没有合适的分类时先问用户
120
+ - 文档:更新 docs/操作手册.md 的插件表与对应章节;在 CHANGELOG.md 顶部(当前版本或 Unreleased)增加条目
121
+
122
+ # 默认值约定
123
+ - 新建空间的插件开关默认关闭:config/app.defaults.json 与 src/lib/app-config.ts 的 emptyAppConfig().plugins 都写 false,不要为新插件破例。
124
+ - 唯一例外是「提示词管理」:它是内置常开项(每个空间都需要默认提示词),在 PLUGIN_CATALOG 里 defaultEnabled / alwaysOn 都为 true,新插件不要照抄。
125
+ - 「用户故事审查」是另一个例外:它随「需求分析」默认打开(defaultEnabled true + autoEnableWith: 'reqAnalysis'),但可以被单独关掉;只有挂在父插件下、默认就该一起用的子项才这么写。
126
+ - PLUGIN_CATALOG 里的 defaultEnabled 也写 false:新增插件默认关闭,由用户在「我的插件」里手动开启。
127
+ - 依赖其它插件时用 requires 声明(如生成器依赖对应管理插件);父项打开时子项若应默认一起开,再加 autoEnableWith。
128
+
129
+ # 验证
130
+ - 可用时至少运行 pnpm typecheck;涉及服务端或纯函数时补充/运行相关 node:test。
131
+ - 不执行 git commit / git push,不擅自格式化无关文件。
132
+ - 改完说明哪些点没有实际运行验证,不要声称已跑通。
133
+
134
+ # 回答风格
135
+ - 中文、直接、少客套;评估阶段先说结论(做成哪种插件、为什么),再给确认选项。
136
+ - 不要空泛地描述「可以开发」,要给具体方案与取舍。
137
+ - 需要用户批准开工时,用一句明确的话收尾,例如「确认无误请回复:开始实施」。`;function ba(e,t){let n=String(t??``).trim(),r=[ya];return n&&r.push(`# 本次运行环境\n项目根(可直接用 fs_* 工具读写):${n}`),r.push(`# 本次需求\n${e.requirement.trim()||`(未填写,按用户后续消息执行)`}`),r.join(`
138
+
139
+ `)}var xa=`/__tb_fs`,Sa=`你可以使用 Skill 工具(本地 fs 可用时):
140
+ - skill_list:列出工作区 / 项目根下约定目录中的 SKILL.md
141
+ - skill_load:按 id(目录名)或 path 加载技能正文到本轮上下文
142
+ - 需要遵循某技能流程时先 skill_list 再 skill_load,勿臆造技能内容`,Ca=[{type:`function`,function:{name:`skill_list`,description:`List available skills (SKILL.md) under the workspace / project (.cursor/skills, .agents/skills, skills/, or */SKILL.md).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`skill_load`,description:`Load a skill by id (directory name) or path to SKILL.md. Returns the skill markdown body (may be truncated).`,parameters:{type:`object`,properties:{name:{type:`string`,description:`Skill id / directory name from skill_list, or relative/absolute path to SKILL.md`},path:{type:`string`,description:`Optional path to SKILL.md (alias of name)`}}}}}];async function wa(e,t){if(e===`skill_list`)try{let e=await fetch(`${xa}/skills`,{signal:AbortSignal.timeout(5e3)}),t=await e.json().catch(()=>({}));return e.ok?JSON.stringify({ok:!0,count:t.count??t.skills?.length??0,skills:t.skills??[]},null,2):JSON.stringify({ok:!1,error:t.error||`HTTP ${e.status}`})}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}if(e===`skill_load`){let e={};try{e=JSON.parse(t||`{}`)}catch{return JSON.stringify({ok:!1,error:`invalid JSON arguments`})}let n=String(e.name??e.path??e.id??``).trim();if(!n)return JSON.stringify({ok:!1,error:`name or path is required`});try{let e=await fetch(`${xa}/skill-load`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n}),signal:AbortSignal.timeout(8e3)}),t=await e.json().catch(()=>({}));if(!e.ok){let n=typeof t==`object`&&t&&`error`in t?String(t.error):`HTTP ${e.status}`;return JSON.stringify({ok:!1,error:n})}return JSON.stringify(t,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}return JSON.stringify({error:`unknown tool: ${e}`})}var Ta=`写操作只在用户明确要求时执行;改 / 删之前先用 list 拿到真实 id,不要臆造 id。参数可以用 id,也可以传名称(project / iteration / requirement),系统先精确再忽略大小写匹配。日期一律 YYYY-MM-DD;不确定就不要填,不要凭空猜测。`,Ea=`项目列表工具(空间级,页面在 /pm/projects/):`+Ta+`新建项目只需要 name;归档用 pm_project_update 把 status 改成 archived。删除项目会连带删掉它的迭代、需求与缺陷,执行前先向用户确认影响范围。`,Da=`迭代管理工具(空间级,页面在 /pm/iterations/):`+Ta+`迭代必须挂在项目下;endDate 不能早于 startDate。进度按日期流逝计算,不要把它当成需求完成度。`,Oa=`需求管理工具(空间级,页面在 /pm/requirements/):`+Ta+`需求必须挂在项目下,iterationId 可留空表示未排期;编号 REQ-### 由系统分配,不要自己编。acceptanceCriteria 是 [{ text, done }] 数组,仅在用户给出验收标准时填写。`,ka=`缺陷管理工具(空间级,页面在 /pm/bugs/):`+Ta+`缺陷必须挂在项目下;iterationId / requirementId 可留空,填了就必须属于同一项目。编号 BUG-### 由系统分配,不要自己编。`,Aa={project:{type:`string`,description:`Project name (exact, then case-insensitive).`},projectId:{type:`string`,description:`Project id from pm_project_list. Prefer this.`},keyword:{type:`string`,description:`Match name / description / title.`},limit:{type:`number`,description:`Max rows, default 50.`}},ja=[{type:`function`,function:{name:`pm_project_list`,description:`List projects in the current space with iteration / requirement / bug counts. Use before any project write to get ids.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:[...R,`all`]},keyword:{type:`string`},limit:{type:`number`}}}}},{type:`function`,function:{name:`pm_project_add`,description:`Create one or more projects. Only when the user explicitly asks. name is required.`,parameters:{type:`object`,properties:{items:{type:`array`,items:{type:`object`,properties:{name:{type:`string`},description:{type:`string`},status:{type:`string`,enum:R}},required:[`name`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_project_update`,description:`Update one project by id or name. Only pass fields that change.`,parameters:{type:`object`,properties:{id:{type:`string`},project:{type:`string`,description:`Project name, used when id is omitted.`},name:{type:`string`},description:{type:`string`},status:{type:`string`,enum:R}}}}},{type:`function`,function:{name:`pm_project_delete`,description:`Delete projects by id or name. Also deletes their iterations, requirements and bugs; confirm scope with the user first.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},project:{type:`string`}}}}}],Ma=[{type:`function`,function:{name:`pm_iteration_list`,description:`List iterations, optionally filtered by project / status. Includes date-based progress and overdue days.`,parameters:{type:`object`,properties:{...Aa,status:{type:`string`,enum:[...fe,`all`]}}}}},{type:`function`,function:{name:`pm_iteration_add`,description:`Create one or more iterations under a project.`,parameters:{type:`object`,properties:{project:{type:`string`,description:`Project name (exact, then case-insensitive).`},projectId:{type:`string`,description:`Project id. Prefer this.`},items:{type:`array`,items:{type:`object`,properties:{name:{type:`string`},startDate:{type:`string`,description:`YYYY-MM-DD.`},endDate:{type:`string`,description:`YYYY-MM-DD, not before startDate.`},status:{type:`string`,enum:fe},remark:{type:`string`}},required:[`name`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_iteration_update`,description:`Update one iteration by id or name. Use status "done" when the iteration is closed.`,parameters:{type:`object`,properties:{id:{type:`string`},iteration:{type:`string`,description:`Iteration name, used when id is omitted.`},project:{type:`string`},projectId:{type:`string`},name:{type:`string`},startDate:{type:`string`},endDate:{type:`string`},status:{type:`string`,enum:fe},remark:{type:`string`}}}}},{type:`function`,function:{name:`pm_iteration_delete`,description:`Delete iterations by id or name. Requirements and bugs keep existing but lose the iteration link.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},iteration:{type:`string`}}}}}],Na=[{type:`function`,function:{name:`pm_requirement_list`,description:`List requirements, optionally filtered by project / iteration / status / priority / keyword.`,parameters:{type:`object`,properties:{...Aa,iteration:{type:`string`},iterationId:{type:`string`},status:{type:`string`,enum:[...I,`all`]},priority:{type:`string`,enum:[...ge,`all`]}}}}},{type:`function`,function:{name:`pm_requirement_add`,description:`Create one or more requirements under a project. The REQ-### code is assigned by the server.`,parameters:{type:`object`,properties:{project:{type:`string`},projectId:{type:`string`},items:{type:`array`,items:{type:`object`,properties:{title:{type:`string`,description:`需求描述(可多行)`},iterationId:{type:`string`,description:`Optional; must belong to the project.`},iteration:{type:`string`,description:`Iteration name instead of id.`},priority:{type:`string`,enum:ge},status:{type:`string`,enum:I},description:{type:`string`},acceptanceCriteria:{type:`array`,items:{type:`object`,properties:{text:{type:`string`},done:{type:`boolean`}},required:[`text`]}},githubIssue:{type:`string`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_requirement_update`,description:`Update one requirement by id, REQ code or title. Use status "done" when it is completed.`,parameters:{type:`object`,properties:{id:{type:`string`},requirement:{type:`string`,description:`Requirement title or REQ-###.`},project:{type:`string`},projectId:{type:`string`},iteration:{type:`string`},iterationId:{type:`string`},title:{type:`string`},priority:{type:`string`,enum:ge},status:{type:`string`,enum:I},description:{type:`string`},acceptanceCriteria:{type:`array`,items:{type:`object`,properties:{text:{type:`string`},done:{type:`boolean`}},required:[`text`]}},githubIssue:{type:`string`}}}}},{type:`function`,function:{name:`pm_requirement_delete`,description:`Delete requirements by id, REQ code or title. Linked bugs lose the link.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},requirement:{type:`string`}}}}}],Pa=[{type:`function`,function:{name:`pm_bug_list`,description:`List bugs, optionally filtered by project / iteration / status / severity / keyword.`,parameters:{type:`object`,properties:{...Aa,iteration:{type:`string`},iterationId:{type:`string`},status:{type:`string`,enum:[...L,`all`]},severity:{type:`string`,enum:[..._e,`all`]}}}}},{type:`function`,function:{name:`pm_bug_add`,description:`Create one or more bugs under a project. The BUG-### code is assigned by the server.`,parameters:{type:`object`,properties:{project:{type:`string`},projectId:{type:`string`},items:{type:`array`,items:{type:`object`,properties:{title:{type:`string`},iterationId:{type:`string`},iteration:{type:`string`},requirementId:{type:`string`},requirement:{type:`string`,description:`Requirement title or REQ-###.`},severity:{type:`string`,enum:_e},status:{type:`string`,enum:L},reproduceSteps:{type:`string`},expectedResult:{type:`string`},actualResult:{type:`string`},environment:{type:`string`},githubIssue:{type:`string`},attachment:{type:`string`},remark:{type:`string`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_bug_update`,description:`Update one bug by id, BUG code or title. Bug status flow: pending → todo → fixed → verifying → passed (or cancelled). Set status "verifying" after a fix is pushed and awaits the user's confirmation; only the user sets "passed".`,parameters:{type:`object`,properties:{id:{type:`string`},bug:{type:`string`,description:`Bug title or BUG-###.`},project:{type:`string`},projectId:{type:`string`},iteration:{type:`string`},iterationId:{type:`string`},requirement:{type:`string`},requirementId:{type:`string`},title:{type:`string`},severity:{type:`string`,enum:_e},status:{type:`string`,enum:L},reproduceSteps:{type:`string`},expectedResult:{type:`string`},actualResult:{type:`string`},environment:{type:`string`},githubIssue:{type:`string`},attachment:{type:`string`},remark:{type:`string`}}}}},{type:`function`,function:{name:`pm_bug_delete`,description:`Delete bugs by id, BUG code or title.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},bug:{type:`string`}}}}}];function J(e,t){let n=e[t];return typeof n==`string`?n.trim():``}function Fa(e,t){let n=J(t,`projectId`);return n?e.projects.some(e=>e.id===n)?n:``:de(e.projects,J(t,`project`))}function Ia(e,t,n){let r=J(n,`iterationId`);if(r)return e.iterations.some(e=>e.id===r&&e.projectId===t)?r:``;let i=J(n,`iteration`);if(!i)return``;let a=e.iterations.find(e=>e.projectId===t&&e.name===i);if(a)return a.id;let o=i.toLowerCase();return e.iterations.find(e=>e.projectId===t&&e.name.toLowerCase()===o)?.id??``}function La(e,t,n){let r=J(n,`requirementId`);if(r)return e.requirements.some(e=>e.id===r&&e.projectId===t)?r:``;let i=J(n,`requirement`);if(!i)return``;let a=e.requirements.filter(e=>e.projectId===t);return ce(a,i)}function Ra(e,t,n,r,i){let a=J(t,`id`);if(a)return e.some(e=>e.id===a)?{id:a}:{id:``,error:`${r}不存在:${a}`};let o=J(t,n);if(!o)return{id:``,error:`缺少${r} id 或名称`};let s=o.toLowerCase(),c=e.find(e=>i(e)===o)??e.find(e=>i(e).toLowerCase()===s);return c?{id:c.id}:{id:``,error:`找不到${r}:${o}`}}function za(e,t){let n={};for(let r of t){if(!(r in e))continue;let t=e[r];t!=null&&(n[r]=t)}return n}function Ba(e,t){let n=J(t,`id`);if(n)return e.requirements.find(e=>e.id===n)??null;let r=J(t,`requirement`);if(!r)return null;let i=r.toLowerCase();return e.requirements.find(e=>e.autoId.toLowerCase()===i)??e.requirements.find(e=>e.title===r)??e.requirements.find(e=>e.title.toLowerCase()===i)??null}function Y(e,t){let n=J(t,`id`);if(n)return e.bugs.find(e=>e.id===n)??null;let r=J(t,`bug`);if(!r)return null;let i=r.toLowerCase();return e.bugs.find(e=>e.autoId.toLowerCase()===i)??e.bugs.find(e=>e.title===r)??e.bugs.find(e=>e.title.toLowerCase()===i)??null}function Va(e,t){let n=t[e.id];return`[${e.id}] ${e.name} | 状态=${e.status} | 迭代=${n?.iterations??0} | 需求=${n?.requirements??0} | 缺陷=${n?.bugs??0}`}function Ha(e){let t=he(e),n=P(e);return`[${e.id}] ${e.name} | 项目=${e.projectId} | ${e.startDate||`—`} → ${e.endDate||`—`} | 状态=${e.status} | 进度=${t}%`+(n===null?``:` | 逾期${n}天`)}function Ua(e){return`[${e.id}] ${e.autoId} ${e.title} | 项目=${e.projectId} | 迭代=${e.iterationId||`—`} | 优先级=${e.priority} | 状态=${e.status}`}function X(e){return`[${e.id}] ${e.autoId} ${e.title} | 项目=${e.projectId} | 迭代=${e.iterationId||`—`} | 严重程度=${e.severity} | 状态=${e.status}`}function Wa(e,t){return e.length?e.map((e,t)=>`${t+1}. ${e}`).join(`
143
+ `):t}function Ga(e,t,n,r){return r.map(r=>{let i=r&&typeof r==`object`?{...r}:{};if(i.projectId=n,t!==`iterations`){let t=Ia(e,n,i);(`iteration`in i||`iterationId`in i)&&(i.iterationId=t)}if(t===`bugs`){let t=La(e,n,i);(`requirement`in i||`requirementId`in i)&&(i.requirementId=t)}return delete i.project,delete i.iteration,delete i.requirement,i})}async function Ka(e,t,n={}){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}try{let t=await be(),i=Math.max(1,Math.min(200,Number(r.limit)||50));if(e===`pm_project_list`){let e=J(r,`status`),n=se(t.projects,{status:e||`all`,keyword:J(r,`keyword`)}).slice(0,i),a=le(t);return JSON.stringify({ok:!0,total:t.projects.length,count:n.length,items:n,summary:Wa(n.map(e=>Va(e,a)),`当前没有匹配的项目。`)})}if(e===`pm_project_add`){let e=(Array.isArray(r.items)?r.items:[r]).map(e=>e&&typeof e==`object`?e:{}).filter(e=>typeof e.name==`string`);if(!e.length)return JSON.stringify({error:`项目名称不能为空`});let i=await me(`projects`,e,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:i.length,items:i,summary:`已创建 ${i.length} 个项目:\n${Wa(i.map(e=>Va(e,le(t))),``)}`})}if(e===`pm_project_update`){let e=Ra(t.projects,r,`project`,`项目`,e=>e.name);if(e.error)return JSON.stringify({error:e.error});let n=za(r,[`name`,`description`,`status`]);if(!Object.keys(n).length)return JSON.stringify({error:`没有可更新的字段`});let i=await F(`projects`,e.id,n);return JSON.stringify({ok:!0,item:i,summary:`已更新项目:${i.name}`})}if(e===`pm_project_delete`){let e=Array.isArray(r.ids)?r.ids:[J(r,`id`)||J(r,`project`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=t.projects.find(t=>t.id===e)??t.projects.find(t=>t.name===e);i&&n.push(i.id)}if(!n.length)return JSON.stringify({error:`缺少项目 id 或名称`});let i=await pe(`projects`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 个项目,并连带删除 ${i.cascaded} 条迭代 / 需求 / 缺陷。`})}if(e===`pm_iteration_list`){let e=Fa(t,r),n=J(r,`status`),a=ue(t.iterations,{projectId:e||`all`,status:n||`all`,keyword:J(r,`keyword`)}).slice(0,i);return JSON.stringify({ok:!0,total:t.iterations.length,count:a.length,items:a,summary:Wa(a.map(Ha),`当前没有匹配的迭代。`)})}if(e===`pm_iteration_add`){let e=Fa(t,r);if(!e)return JSON.stringify({error:`请先指定项目(projectId 或 project 名称)`});let i=Ga(t,`iterations`,e,Array.isArray(r.items)?r.items:[r]);if(!i.length)return JSON.stringify({error:`迭代名称不能为空`});let a=await me(`iterations`,i,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:a.length,items:a,summary:`已创建 ${a.length} 个迭代:\n${Wa(a.map(Ha),``)}`})}if(e===`pm_iteration_update`){let e=Ra(t.iterations,r,`iteration`,`迭代`,e=>e.name);if(e.error)return JSON.stringify({error:e.error});let n=za(r,[`name`,`startDate`,`endDate`,`status`,`remark`]);if(`projectId`in r||`project`in r){let e=Fa(t,r);if(!e)return JSON.stringify({error:`所属项目不存在`});n.projectId=e}if(!Object.keys(n).length)return JSON.stringify({error:`没有可更新的字段`});let i=await F(`iterations`,e.id,n);return JSON.stringify({ok:!0,item:i,summary:`已更新迭代:${Ha(i)}`})}if(e===`pm_iteration_delete`){let e=Array.isArray(r.ids)?r.ids:[J(r,`id`)||J(r,`iteration`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=t.iterations.find(t=>t.id===e)??t.iterations.find(t=>t.name===e);i&&n.push(i.id)}if(!n.length)return JSON.stringify({error:`缺少迭代 id 或名称`});let i=await pe(`iterations`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 个迭代;关联需求与缺陷已解除迭代关联。`})}if(e===`pm_requirement_list`){let e=Fa(t,r),n=e?Ia(t,e,r):J(r,`iterationId`)||`all`,a=J(r,`status`),o=J(r,`priority`),s=ve(t.requirements,{projectId:e||`all`,iterationId:n||`all`,status:a||`all`,priority:o||`all`,keyword:J(r,`keyword`)}).slice(0,i);return JSON.stringify({ok:!0,total:t.requirements.length,count:s.length,items:s,summary:Wa(s.map(Ua),`当前没有匹配的需求。`)})}if(e===`pm_requirement_add`){let e=Fa(t,r);if(!e)return JSON.stringify({error:`请先指定项目(projectId 或 project 名称)`});let i=Ga(t,`requirements`,e,Array.isArray(r.items)?r.items:[r]);if(!i.length)return JSON.stringify({error:`需求描述不能为空`});let a=await me(`requirements`,i,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:a.length,items:a,summary:`已创建 ${a.length} 条需求:\n${Wa(a.map(Ua),``)}`})}if(e===`pm_requirement_update`){let e=Ba(t,r);if(!e)return JSON.stringify({error:`找不到需求:请传 id、REQ-### 或标题`});let n={id:e.id},i=za(r,[`title`,`priority`,`status`,`description`,`acceptanceCriteria`,`githubIssue`]),a=`projectId`in r||`project`in r?Fa(t,r):e.projectId;if(!a)return JSON.stringify({error:`所属项目不存在`});if(a!==e.projectId&&(i.projectId=a),(`iterationId`in r||`iteration`in r)&&(i.iterationId=Ia(t,a,r)),!Object.keys(i).length)return JSON.stringify({error:`没有可更新的字段`});let o=await F(`requirements`,n.id,i);return JSON.stringify({ok:!0,item:o,summary:`已更新需求:${Ua(o)}`})}if(e===`pm_requirement_delete`){let e=Array.isArray(r.ids)?r.ids:[J(r,`id`)||J(r,`requirement`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=ce(t.requirements,e),a=t.requirements.find(t=>t.id===e)??t.requirements.find(t=>t.autoId===e)??t.requirements.find(e=>e.id===i);a&&n.push(a.id)}if(!n.length)return JSON.stringify({error:`缺少需求 id / 编号 / 名称`});let i=await pe(`requirements`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 条需求;关联缺陷已解除需求关联。`})}if(e===`pm_bug_list`){let e=Fa(t,r),n=e?Ia(t,e,r):J(r,`iterationId`)||`all`,a=J(r,`status`),o=J(r,`severity`),s=ye(t.bugs,{projectId:e||`all`,iterationId:n||`all`,status:a||`all`,severity:o||`all`,keyword:J(r,`keyword`)}).slice(0,i);return JSON.stringify({ok:!0,total:t.bugs.length,count:s.length,items:s,summary:Wa(s.map(X),`当前没有匹配的缺陷。`)})}if(e===`pm_bug_add`){let e=Fa(t,r);if(!e)return JSON.stringify({error:`请先指定项目(projectId 或 project 名称)`});let i=Ga(t,`bugs`,e,Array.isArray(r.items)?r.items:[r]);if(!i.length)return JSON.stringify({error:`缺陷标题不能为空`});let a=await me(`bugs`,i,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:a.length,items:a,summary:`已创建 ${a.length} 条缺陷:\n${Wa(a.map(X),``)}`})}if(e===`pm_bug_update`){let e=Y(t,r);if(!e)return JSON.stringify({error:`找不到缺陷:请传 id、BUG-### 或标题`});let n={id:e.id},i=za(r,[`title`,`severity`,`status`,`reproduceSteps`,`expectedResult`,`actualResult`,`environment`,`githubIssue`,`attachment`,`remark`]),a=`projectId`in r||`project`in r?Fa(t,r):e.projectId;if(!a)return JSON.stringify({error:`所属项目不存在`});if(a!==e.projectId&&(i.projectId=a),(`iterationId`in r||`iteration`in r)&&(i.iterationId=Ia(t,a,r)),(`requirementId`in r||`requirement`in r)&&(i.requirementId=La(t,a,r)),!Object.keys(i).length)return JSON.stringify({error:`没有可更新的字段`});let o=await F(`bugs`,n.id,i);return JSON.stringify({ok:!0,item:o,summary:`已更新缺陷:${X(o)}`})}if(e===`pm_bug_delete`){let e=Array.isArray(r.ids)?r.ids:[J(r,`id`)||J(r,`bug`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=t.bugs.find(t=>t.id===e)??t.bugs.find(t=>t.autoId===e)??t.bugs.find(t=>t.title===e)??t.bugs.find(t=>t.title.toLowerCase()===e.toLowerCase());i&&n.push(i.id)}if(!n.length)return JSON.stringify({error:`缺少缺陷 id / 编号 / 名称`});let i=await pe(`bugs`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 条缺陷。`})}return JSON.stringify({error:`unknown pm tool: ${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var qa=`待办事项工具(空间级,跨会话保留,页面在 /todos/):
144
+ - 只有用户明确要求把某件事记成待办时才调用 todo_add:例如「记一下 / 加个待办 / 帮我跟进 / 周五一前完成记得提醒我 / 把这件事加到待办」。
145
+ - 用户只是在聊天里说到一件事、行程或计划,没有要你记录(没有「记 / 待办 / 跟进 / 提醒我」这类意图)时,不要调用 todo_add,也不要弹确认卡片;把内容正常聊完即可。不要从普通对话里自动「提炼」待办。
146
+ - 不要先用 ask_user_question 逐项追问待办字段。直接调用 todo_add,把已知内容填好;系统会弹出「待办快卡」:用户确认名称,状态自动为「进行中」、日期自动取当天(开始 / 截止可在快卡里直接改成区间)、所属任务默认「日常待办」(快卡里可下拉换成已有任务,任务管理里没有「日常待办」就按 进行中 / 重要不紧急 / 当年第一天 ~ 当年最后一天 创建),紧急程度跟随所属任务,点「确认新增」才落库。
147
+ - 用户明确说了要归到某个任务(如「加到登录模块这个任务下」)时,照常在 taskId / linkedTask 里填该任务,系统会保留你的指定,不再套「日常待办」。
148
+ - 调用 todo_add 必须给出待办标题(title);不要为了打开一张空白卡片而调用工具。用户想自己填名称时,让 ta 用侧栏「+ → 待办」。
149
+ - 用户问「还有哪些待办 / 进度」时用 todo_list;完成后用 todo_update 把 status 改为 done;删掉用 todo_delete。
150
+ - 日期一律 YYYY-MM-DD;不确定截止日期就先不填,不要凭空猜测;用户说了相对日期(如「后天」)时换算成具体日期。
151
+ - 只记录用户明确要求或明确同意的事项,不要把闲聊、假设写成待办。`,Ja=[`all`,...Xn],Ya=[{type:`function`,function:{name:`todo_add`,description:`Create one or more long-lived todos in the current space (visible on the /todos/ page). Call ONLY when the user explicitly asks to record / track something as a todo (e.g. "记一下", "加个待办", "帮我跟进", "提醒我周五前完成"). Do NOT call it just because the conversation mentions a task, plan or trip, and do NOT extract todos from ordinary chat. A title is required: never call with empty items to open a blank card (the user has "+ → 待办" for manual entry). This opens a compact confirm card where the user checks the title, may change the date range (start ~ due), and may pick a different task from the task dropdown: status defaults to in_progress, dates default to today, the todo is attached to the "日常待办" task (auto-created when missing), and its priority follows the linked task. Pass taskId/linkedTask only when the user explicitly named a task. Do not ask the user for the other fields first.`,parameters:{type:`object`,properties:{items:{type:`array`,description:`Todos to create; each needs a title. Never send an empty array — only call this tool when the user explicitly asked to record a todo.`,items:{type:`object`,properties:{title:{type:`string`,description:`Short imperative title.`},status:{type:`string`,enum:Xn,description:`New todos are always saved as in_progress; kept for update compatibility.`},priority:{type:`string`,enum:Pn,description:`urgent_important | important | urgent | normal. Omit when unclear.`},linkedTask:{type:`string`,description:`Related task name / project name.`},taskId:{type:`string`,description:`Task id from the 任务管理 plugin (task_add / task_list). Prefer over linkedTask. Omit to use the default 日常待办 task.`},startDate:{type:`string`,description:`YYYY-MM-DD. Omit to default to today.`},dueDate:{type:`string`,description:`YYYY-MM-DD. Omit to default to today; keep an explicit deadline.`},note:{type:`string`,description:`Extra detail, dependencies, links.`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`todo_list`,description:`List long-lived todos of the current space, optionally filtered by status, priority or keyword.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:Ja,description:`Default all.`},priority:{type:`string`,enum:[...Pn,`all`],description:`Default all.`},keyword:{type:`string`,description:`Match title / linked task / note.`},limit:{type:`number`,description:`Max rows, default 50.`}}}}},{type:`function`,function:{name:`todo_update`,description:`Update one todo by id. Only pass fields that change; use status "done" when the user finishes it.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`Todo id from todo_list / todo_add.`},title:{type:`string`},status:{type:`string`,enum:Xn},priority:{type:`string`,enum:Pn},linkedTask:{type:`string`},taskId:{type:`string`,description:`Task id; empty string unlinks.`},startDate:{type:`string`,description:`YYYY-MM-DD.`},dueDate:{type:`string`,description:`YYYY-MM-DD.`},note:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`todo_delete`,description:`Delete one or more todos by id.`,parameters:{type:`object`,properties:{ids:{type:`array`,description:`Todo ids to delete.`,items:{type:`string`}}},required:[`ids`]}}}];function Xa(e){let t=Dn(e),n=jn(e);return[`[${e.id}] ${e.title}`,`状态=${In[t]}`,e.priority?`紧急程度=${Jn[e.priority]}`:``,e.dueDate?`截止=${e.dueDate}`:``,n!==null&&t!==`done`&&t!==`cancelled`?n<0?`逾期${Math.abs(n)}天`:`剩余${n}天`:``,e.linkedTask?`关联=${e.linkedTask}`:``,e.note?`备注=${e.note}`:``].filter(Boolean).join(` | `)}function Za(e){return e.length?e.map((e,t)=>`${t+1}. ${Xa(e)}`).join(`
152
+ `):`当前没有匹配的待办。`}function Qa(e){return typeof e==`string`&&Xn.includes(e)}function $a(e){return typeof e==`string`&&Pn.includes(e)}function eo(e){let t={};return typeof e.title==`string`&&(t.title=e.title.trim()),Qa(e.status)&&(t.status=e.status),$a(e.priority)&&(t.priority=e.priority),typeof e.linkedTask==`string`&&(t.linkedTask=e.linkedTask.trim()),typeof e.taskId==`string`&&(t.taskId=e.taskId.trim()),typeof e.startDate==`string`&&(t.startDate=e.startDate.trim()),typeof e.dueDate==`string`&&(t.dueDate=e.dueDate.trim()),typeof e.note==`string`&&(t.note=e.note.trim()),t}async function to(e,t,n={}){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}try{if(e===`todo_add`){let e=(Array.isArray(r.items)?r.items:[r]).map(Vn).filter(e=>!!e);if(!e.length)return JSON.stringify({error:`待办名称不能为空`});let t=await Yn(e,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:t.length,items:t,summary:`已记录 ${t.length} 条待办:\n${Za(t)}`})}if(e===`todo_list`){let e=await An(),t=r.status,n=Qa(t)?t:`all`,i=$a(r.priority)?r.priority:`all`,a=typeof r.keyword==`string`?r.keyword:``,o=Math.max(1,Math.min(200,Number(r.limit)||50)),s=Nn(e,{status:n,priority:i,keyword:a}).slice(0,o);return JSON.stringify({ok:!0,total:e.length,count:s.length,items:s,summary:Za(s)})}if(e===`todo_update`){let e=typeof r.id==`string`?r.id.trim():``;if(!e)return JSON.stringify({error:`缺少待办 id`});let t=eo(r);if(!Object.keys(t).length)return JSON.stringify({error:`没有可更新的字段`});let n=await kn(e,t);return JSON.stringify({ok:!0,item:n,summary:`已更新待办:${Xa(n)}`})}if(e===`todo_delete`){let e=(Array.isArray(r.ids)?r.ids:[r.id]).filter(e=>typeof e==`string`&&!!e.trim()).map(e=>e.trim());if(!e.length)return JSON.stringify({error:`缺少待办 id`});let t=await Mn(e);return JSON.stringify({ok:!0,removed:t,summary:`已删除 ${t} 条待办。`})}return JSON.stringify({error:`unknown todo tool: ${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var no=`日常待办`;function ro(e=U()){let t=/^\d{4}/.test(e)?e.slice(0,4):String(new Date().getFullYear());return{title:no,status:`in_progress`,priority:`important`,startDate:`${t}-01-01`,dueDate:`${t}-12-31`}}function io(e){let t=e.filter(e=>e.title.trim()===no).filter(e=>e.status!==`closed`&&e.status!==`cancelled`);return t.find(e=>e.status===`in_progress`)??t[0]??null}function ao(e,t){let n=t.taskId?.trim();if(n){let t=e.find(e=>e.id===n);if(t)return t}let r=t.linkedTask?.trim();if(!r)return null;let i=e.filter(e=>e.title.trim()===r);return i.find(e=>e.status!==`closed`&&e.status!==`cancelled`)??i[0]??null}function oo(e,t,n=U()){let r=e=>/^\d{4}-\d{2}-\d{2}$/.test(e),i=r(e),a=r(t),o=i?e:a&&t<n?t:n;return{startDate:o,dueDate:a?t<o?o:t:o}}async function so(e,t=U()){let n=[],r=!0;try{n=await qn()}catch{r=!1}let i=r?io(n):null,a=e.map(e=>{let a={...e,status:`in_progress`,...oo(e.startDate,e.dueDate,t)};if(!r)return{...a,taskId:``,linkedTask:``};let o=ao(n,e);return o?{...a,taskId:o.id,linkedTask:o.title}:e.linkedTask.trim()?{...a,taskId:``}:{...a,taskId:i?.id??``,linkedTask:i?.title??`日常待办`}}),o=!i&&r&&a.some(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`);return{items:a,tasksAvailable:r,willCreateRoutine:o}}async function co(e){if(!e.some(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`))return e;let t=io(await qn());if(!t){let[e]=await Fn([ro()],{mode:`ai`});t=e??null}let n=t;if(!n)throw Error(`创建「日常待办」任务失败`);return e.map(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`?{...e,taskId:n.id,linkedTask:n.title,priority:n.priority}:e)}var lo=`任务管理工具(空间级,跨会话保留,页面在 /tasks/):
153
+ - 用户说「建个任务 / 开个项目任务 / 把这件事拆成任务」时调用 task_add;一次可传多条。
154
+ - 不要先用 ask_user_question 逐项追问任务字段。直接调用 task_add,把已知字段填好;系统会弹出与「+ → 任务」完全相同的确认卡片,用户在卡片里补充或修改,点「确认新增」才落库。
155
+ - 用户没说任务内容时也直接调用 task_add(items 传空数组或 [{ "title": "" }]),系统会打开空白确认卡片让用户自己填。
156
+ - 只查询用 task_list;改状态 / 日期用 task_update;删任务用 task_delete。
157
+ - 任务下的待办用 todo_add 的 taskId 关联,任务本身不重复记录待办内容。
158
+ - 日期一律 YYYY-MM-DD;不确定就先不填,不要凭空猜测。`,uo=[...Kn,`urgent`,`all`];function fo(e){return typeof e==`string`&&Kn.includes(e)}function po(e){let t=Un(e);return[`[${e.id}] ${e.title}`,`状态=${Bn[e.status]}`,e.priority?`紧急程度=${Wn[e.priority]}`:``,e.startDate?`开始=${e.startDate}`:``,e.dueDate?`截止=${e.dueDate}`:``,t===null?``:`周期=${t}天`,e.note?`备注=${e.note}`:``].filter(Boolean).join(` | `)}function mo(e){return e.length?e.map((e,t)=>`${t+1}. ${po(e)}`).join(`
159
+ `):`当前没有匹配的任务。`}var ho=[{type:`function`,function:{name:`task_add`,description:`Create one or more long-lived tasks in the current space (visible on the /tasks/ page). Use when the user asks to create a task / project item. This opens the same editable confirm card as the manual + menu, so do not ask the user for the fields first.`,parameters:{type:`object`,properties:{items:{type:`array`,description:`Tasks to create. Pass an empty array to open a blank confirm card for the user to fill in.`,items:{type:`object`,properties:{title:{type:`string`,description:`Short task title.`},status:{type:`string`,enum:Kn,description:`pool | in_progress | done | closed. Default pool.`},priority:{type:`string`,enum:W,description:`urgent_important | important | urgent | normal. Omit when unclear.`},startDate:{type:`string`,description:`YYYY-MM-DD.`},dueDate:{type:`string`,description:`YYYY-MM-DD.`},note:{type:`string`,description:`Extra detail, scope, links.`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`task_list`,description:`List tasks of the current space, optionally filtered by status, priority or keyword.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:uo,description:`Default all.`},priority:{type:`string`,enum:[...W,`all`],description:`Default all.`},keyword:{type:`string`,description:`Match title / note.`},limit:{type:`number`,description:`Max rows, default 50.`}}}}},{type:`function`,function:{name:`task_update`,description:`Update one task by id. Only pass fields that change.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`Task id from task_list / task_add.`},title:{type:`string`},status:{type:`string`,enum:Kn},priority:{type:`string`,enum:[...W,``]},startDate:{type:`string`,description:`YYYY-MM-DD; empty string clears.`},dueDate:{type:`string`,description:`YYYY-MM-DD; empty string clears.`},note:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`task_delete`,description:`Delete one or more tasks by id. Linked todos are kept (only unlinked).`,parameters:{type:`object`,properties:{ids:{type:`array`,description:`Task ids to delete.`,items:{type:`string`}}},required:[`ids`]}}}];function go(e){try{let t=JSON.parse(e||`{}`);return(Array.isArray(t.items)?t.items:[t]).filter(e=>!!e&&typeof e==`object`&&typeof e.title==`string`)}catch{return[]}}async function _o(e,t,n={}){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}try{if(e===`task_add`){let e=(Array.isArray(r.items)?r.items:[r]).map(Rn).filter(e=>!!e);if(!e.length)return JSON.stringify({error:`任务名称不能为空`});let t=await Fn(e,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:t.length,items:t,summary:`已创建 ${t.length} 个任务:\n${mo(t)}`})}if(e===`task_list`){let e=await qn(),t=r.status,n=fo(t)?t:t===`urgent`?`urgent`:`all`,i=typeof r.priority==`string`&&W.includes(r.priority)?r.priority:`all`,a=typeof r.keyword==`string`?r.keyword:``,o=Math.max(1,Math.min(200,Number(r.limit)||50)),s=Ln(e,{status:n,priority:i,keyword:a}).slice(0,o);return JSON.stringify({ok:!0,total:e.length,count:s.length,items:s,summary:mo(s)})}if(e===`task_update`){let e=typeof r.id==`string`?r.id.trim():``;if(!e)return JSON.stringify({error:`缺少任务 id`});let t={};if(typeof r.title==`string`&&(t.title=r.title.trim()),fo(r.status)&&(t.status=r.status),r.priority===``?t.priority=``:Hn(r.priority)&&(t.priority=r.priority),typeof r.startDate==`string`&&(t.startDate=r.startDate.trim()),typeof r.dueDate==`string`&&(t.dueDate=r.dueDate.trim()),typeof r.note==`string`&&(t.note=r.note.trim()),!Object.keys(t).length)return JSON.stringify({error:`没有可更新的字段`});let n=await zn(e,t);return JSON.stringify({ok:!0,item:n,summary:`已更新任务:${po(n)}`})}if(e===`task_delete`){let e=(Array.isArray(r.ids)?r.ids:[r.id]).filter(e=>typeof e==`string`&&!!e.trim()).map(e=>e.trim());if(!e.length)return JSON.stringify({error:`缺少任务 id`});let t=await Gn(e);return JSON.stringify({ok:!0,removed:t,summary:`已删除 ${t} 个任务。`})}return JSON.stringify({error:`unknown task tool: ${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var vo=`/__tb_sessions/query`;function yo(e){if(!e||typeof e!=`object`)return``;let t=e;return typeof t.content==`string`?t.content:Array.isArray(t.content)?t.content.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e?String(e.text??``):``).join(`
160
+ `):``}function bo(e,t){let n=t.trim().toLowerCase();if(!n)return null;let r=(e.title||``).trim(),i=0,a=``;r.toLowerCase().includes(n)&&(i+=10,a=r);let o=Array.isArray(e.messages)?e.messages:[];for(let e=o.length-1;e>=0;e--){let t=yo(o[e]),r=t.toLowerCase().indexOf(n);if(!(r<0)){if(i+=1,!a){let e=Math.max(0,r-24),i=Math.min(t.length,r+n.length+48);a=`${e>0?`…`:``}${t.slice(e,i).replace(/\s+/g,` `)}${i<t.length?`…`:``}`}if(o.length-e>40)break}}return i<=0?null:{score:i,snippet:a||r||e.id}}function xo(e,t,n){let r=String(t??``).trim();if(!r||!e?.sessions?.length)return[];let i=Math.min(Math.max(n?.limit??20,1),50),a=n?.includeArchived===!0,o=[];for(let t of e.sessions){if(t.deleted||t.archived&&!a)continue;let e=bo(t,r);e&&o.push({sessionId:t.id,title:t.title||`新对话`,archived:!!t.archived,score:e.score,snippet:e.snippet,updatedAt:t.updatedAt})}return o.sort((e,t)=>t.score-e.score||t.updatedAt-e.updatedAt),o.slice(0,i)}async function So(e,t){let n=String(e??``).trim();if(!n)return{backend:`sqlite`,hits:[]};try{let e=new URLSearchParams({q:n,limit:String(t?.limit??20)});t?.includeArchived&&e.set(`archived`,`1`);let r=await fetch(`${vo}?${e}`,{signal:AbortSignal.timeout(4e3)}),i=await r.json().catch(()=>null);return!r.ok||!i||!Array.isArray(i.hits)?null:{backend:i.backend||`sqlite`,hits:i.hits}}catch{return null}}var Co=`你可以使用工作区变更工具:
161
+ - workspace_changes_list:查看本会话内已记录的写文件/建目录
162
+ - workspace_changes_clear:清空本会话变更记录(不回滚磁盘文件)`,wo=[{type:`function`,function:{name:`workspace_changes_list`,description:`List workspace file mutations recorded in this chat session (fs_write / fs_mkdir).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`workspace_changes_clear`,description:`Clear the in-session workspace change log (does not delete files on disk).`,parameters:{type:`object`,properties:{}}}}];function To(e){return String(e??``).trim().replace(/\\/g,`/`).replace(/^\.\//,``)}function Eo(e,t){let n=To(t.path);if(!n)return Array.isArray(e)?[...e]:[];let r={path:n,op:t.op,at:t.at??Date.now()};return[...Array.isArray(e)?e.filter(e=>To(e.path)!==n):[],r].slice(-100)}function Do(e,t){if(e!==`fs_write`&&e!==`fs_mkdir`)return null;try{let n=JSON.parse(t||`{}`);if(n.error||n.ok===!1)return null;let r=To(String(n.path??``));return r?{path:r,op:e===`fs_mkdir`?`mkdir`:`write`}:null}catch{return null}}function Oo(e,t){if(e===`workspace_changes_list`){let e=Array.isArray(t)?t:[];return{text:JSON.stringify({ok:!0,count:e.length,changes:e.map(e=>({path:e.path,op:e.op,at:new Date(e.at).toISOString()}))},null,2)}}return e===`workspace_changes_clear`?{text:JSON.stringify({ok:!0,cleared:!0,count:0}),next:[]}:{text:JSON.stringify({error:`unknown tool: ${e}`})}}var ko=6e5;function Ao(e){if(e==null||!Number.isFinite(e)||e<0)return`unavailable`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;if(n<60)return r?`${n}m${r}s`:`${n}m`;let i=Math.floor(n/60),a=n%60;return a?`${i}h${a}m`:`${i}h`}function jo(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||`unavailable`}catch{return`unavailable`}}function Mo(e,t){try{return`${new Intl.DateTimeFormat(`en-CA`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1,timeZoneName:`shortOffset`}).format(e).replace(`,`,``)} (${t})`}catch{return e.toISOString()}}function No(e={}){let t=e.now??Date.now(),n=jo(),r=e.lastInjectAt??null;if(!(r==null||!Number.isFinite(r)||t-r>=6e5)&&r!=null)return{text:`【时间上下文 time-context】沿用上次采样(节流 ${ko/6e4} 分钟)。浏览器时区:${n}。解释未标注时区的日期时间时请使用该时区;若不确定请向用户确认。`,injected:!1,at:r};let i=e.lastUserMessageAt!=null&&Number.isFinite(e.lastUserMessageAt)?t-e.lastUserMessageAt:null;return{text:[`【时间上下文 time-context】`,`当前时间:${Mo(new Date(t),n)}`,`浏览器时区:${n}`,`距上一轮用户消息:${Ao(i)}`,`解释未标注时区的日期时间时请使用上述时区;若时区信息混杂或缺失,请向用户确认。`].join(`
163
+ `),injected:!0,at:t}}var Po=`会话交互工具(默认可用):
164
+ - todo_write:维护本会话完整待办列表(替换式写入);多步任务用它展示进度;允许多个 in_progress
165
+ - ask_user_question:向用户提出结构化问题并等待回答;缺信息或需确认时使用,勿空猜`,Fo={type:`function`,function:{name:`todo_write`,description:`Record and update a task list for multi-step work. Replace the complete list each call. Keep active work in_progress (several allowed in parallel). Mark completed as soon as done. Skip for trivial single-step tasks.`,parameters:{type:`object`,properties:{todos:{type:`array`,description:`The COMPLETE task list, replacing any previous list.`,items:{type:`object`,properties:{content:{type:`string`,description:`What the task is — a short imperative line.`},status:{type:`string`,enum:[`pending`,`in_progress`,`completed`],description:`pending | in_progress | completed`}},required:[`content`,`status`]}}},required:[`todos`]}}},Io={type:`function`,function:{name:`ask_user_question`,description:`Ask the user a concise structured question when you need confirmation, a choice, or missing information before proceeding. Pauses until the user answers.`,parameters:{type:`object`,properties:{questions:{type:`array`,description:`Questions to ask the user before continuing.`,items:{type:`object`,properties:{id:{type:`string`,description:`Stable id; echoed in the answer.`},question:{type:`string`,description:`The specific question.`},header:{type:`string`,description:`Optional short heading.`},options:{type:`array`,items:{type:`object`,properties:{label:{type:`string`},description:{type:`string`}},required:[`label`]}},multi_select:{type:`boolean`,description:`Allow selecting more than one option. Default false.`}},required:[`id`,`question`]}}},required:[`questions`]}}};function Lo(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=String(n.content??``).trim(),r=String(n.status??``);e&&(r===`pending`||r===`in_progress`||r===`completed`)&&t.push({content:e,status:r})}return t}function Ro(e){let t={};try{t=JSON.parse(e||`{}`)}catch{return[]}if(!Array.isArray(t.questions))return[];let n=[];for(let e of t.questions){if(!e||typeof e!=`object`)continue;let t=String(e.id??``).trim(),r=String(e.question??``).trim();if(!t||!r)continue;let i=e.options,a=Array.isArray(i)?i.map(e=>({label:String(e?.label??``).trim(),description:e?.description?String(e.description):void 0})).filter(e=>e.label):void 0;n.push({id:t,question:r,header:e.header?String(e.header):void 0,options:a?.length?a:void 0,multi_select:!!e.multi_select})}return n}function zo(e,t){let n=e.options??[];if(!n.length)return null;let r=t.trim().split(/[,,、;;\s]+/).filter(Boolean);if(!r.length)return null;let i=[];for(let e of r){let t=Number(e.replace(/^第/,``).replace(/[.。)]$/,``));if(!Number.isInteger(t)||t<1||t>n.length)return null;let r=n[t-1]?.label;r&&!i.includes(r)&&i.push(r)}return!e.multi_select&&i.length>1?null:i.length?i:null}function Bo(e,t){let n=t??{selected:[],text:``};if(n.skipped)return{id:e.id,selected:[],skipped:!0};let r=n.text.trim();if(r){let t=e.options?.length?zo(e,r):null;return t?{id:e.id,selected:t}:{id:e.id,text:r}}return{id:e.id,selected:[...n.selected]}}function Vo(e,t){return e.map((e,n)=>{let r=t[n],i=r?.skipped?`(跳过,未作答)`:r?.text?.trim()?r.text.trim():(r?.selected??[]).join(`、`)||`(跳过,未作答)`,a=e.header?`${e.header} / ${e.question}`:e.question;return`${n+1}. ${a}\n → ${i}`}).join(`
166
+ `)}var Ho=`【计划模式 · 探查中】当前禁止写操作(不可 fs_write / bash / pwsh 等)。
167
+ - 先用只读工具(fs_list / fs_read / fs_glob / fs_grep / web_* / kb_*)探查
168
+ - 形成方案后调用 submit_plan,等待用户批准;未批准前不要声称已修改文件
169
+ - 可用 ask_user_question / todo_write 澄清与拆解`,Uo=`【计划模式 · 已批准】用户已批准方案,可以按批准内容实施(写文件 / 执行命令)。
170
+ - 实施中若需大幅变更方案,再次 submit_plan 征求批准
171
+ - 仍优先小步、可回滚的改动`,Wo={type:`function`,function:{name:`submit_plan`,description:`Submit an implementation plan for user approval (plan mode). Blocks until the user approves or rejects.`,parameters:{type:`object`,properties:{title:{type:`string`,description:`Short plan title`},summary:{type:`string`,description:`What will change and why`},steps:{type:`array`,items:{type:`string`},description:`Ordered implementation steps`}},required:[`title`,`steps`]}}};function Go(e){try{let t=JSON.parse(e||`{}`),n=String(t.title??``).trim(),r=String(t.summary??``).trim(),i=Array.isArray(t.steps)?t.steps.map(e=>String(e??``).trim()).filter(Boolean):[];return!n||!i.length?null:{title:n,summary:r,steps:i.slice(0,24)}}catch{return null}}function Ko(e){return e===`planning`||e===`approved`?e:`off`}function qo(e){if(!e||typeof e!=`object`)return null;let t=e,n=String(t.title??``).trim(),r=String(t.summary??``).trim(),i=Array.isArray(t.steps)?t.steps.map(e=>String(e??``).trim()).filter(Boolean):[];return!n||!i.length?null:{title:n,summary:r,steps:i.slice(0,24)}}var Jo=8e4,Yo=.28;function Xo(e){return(e.content?.length??0)+(e.reasoning?.length??0)}function Zo(e){return e.reduce((e,t)=>e+Xo(t),0)}function Qo(e,t){let n=typeof t==`number`&&t>0?t:e?lt[e]:void 0;return n&&n>0?Math.max(24e3,Math.floor(n*4*Yo)):Jo}function $o(e,t,n){return Zo(e)>=Qo(t,n)}function es(e){return e.map(e=>{let t=e.role===`user`?`User`:`Assistant`,n=(e.content||``).trim(),r=e.reasoning?.trim()?`\n[thinking]\n${e.reasoning.trim().slice(0,1200)}`:``;return`${t}:\n${n.slice(0,6e3)}${r}`}).join(`
172
+
173
+ ---
174
+
175
+ `).slice(0,6e4)}async function ts(e,t,n){let r=es(t);if(!r.trim())return``;let i=[{role:`system`,content:`你是会话压缩助手。将对话历史压缩为简洁中文摘要,保留:目标、关键决策、文件路径、未完成事项、约束。不要编造;不要输出寒暄;用条目或短段落,控制在 800 字以内。`},{role:`user`,content:`请压缩下列对话历史:\n\n${r}`}];return(await st(e,i,n)).trim()||`(摘要为空)`}async function ns(e,t,n){let r=Math.max(2,n?.keepRecent??8);if(t.length<=r+1||!n?.force&&!$o(t,e.model,n?.contextWindow))return{messages:t,summary:``,compacted:!1};let i=t.slice(0,-r),a=t.slice(-r),o=await ts(e,i,n?.signal);return{messages:[{role:`user`,content:`【会话摘要 · 较早消息已压缩】\n${o}`},{role:`assistant`,content:`已记录摘要。后续回复将基于摘要与最近对话继续。`},...a],summary:o,compacted:!0}}function rs(e){return/^\/compact(?:\s|$)/i.test(e.trim())}var is=`你可以使用会话目标工具:
176
+ - goal_get:读取本会话当前目标
177
+ - goal_set:设定或更新目标(status=active)
178
+ - goal_done:将目标标为已完成
179
+ - goal_clear:清除目标
180
+ 有活跃目标时应围绕其推进;重大偏离前用 ask_user_question 或更新目标。
181
+ 系统可能在目标未完成时自动续轮(goal-round-driver);完成后务必 goal_done,避免空转。`,as=[{type:`function`,function:{name:`goal_get`,description:`Get the current session goal (text + status).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`goal_set`,description:`Set or replace the session goal. Marks it active.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Goal statement for this session`}},required:[`text`]}}},{type:`function`,function:{name:`goal_done`,description:`Mark the current session goal as done.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`goal_clear`,description:`Clear the session goal.`,parameters:{type:`object`,properties:{}}}}];function os(e){if(!e||typeof e!=`object`)return null;let t=e,n=String(t.text??``).trim();if(!n)return null;let r=t.status===`done`||t.status===`cleared`||t.status===`active`?t.status:`active`;return{text:n.slice(0,500),status:r,updatedAt:typeof t.updatedAt==`number`?t.updatedAt:Date.now()}}function ss(e){return!e||e.status===`cleared`||!e.text?JSON.stringify({ok:!0,goal:null}):JSON.stringify({ok:!0,goal:{text:e.text,status:e.status}})}function cs(e){return!e||e.status!==`active`?null:e.text.trim()||null}function ls(e){let t=e.trim();if(!/^\/goal(?:\s|$)/i.test(t))return null;let n=t.replace(/^\/goal\s*/i,``).trim();if(!n)return{kind:`show`};if(/^clear\b/i.test(n))return{kind:`clear`};if(/^done\b/i.test(n))return{kind:`done`};if(/^set\s+/i.test(n)){let e=n.replace(/^set\s+/i,``).trim();return e?{kind:`set`,text:e}:{kind:`show`}}return{kind:`set`,text:n}}function us(e){return ls(e)!=null}var ds=`[goal-round-driver]`;function fs(e,t,n){return`${ds} 续轮 ${t}/${n}:请继续推进目标「${e.trim().slice(0,200)}」。若已完成请调用 goal_done;若阻塞请说明原因或 ask_user_question,勿空转重复相同工具。`}function ps(e){return e.trimStart().startsWith(ds)}function ms(e){let t=Math.max(1,Math.floor(e.maxRounds??3));return!(!e.goalActive||!e.turnOk||e.aborted||e.hasFollowUp||e.askUserPending||e.roundsUsed>=t)}function hs(e){return e.trim().replace(/[\\/:*?"<>|]+/g,`_`).replace(/\s+/g,` `).slice(0,48)||`session`}function gs(e){if(!e||typeof e!=`object`)return{raw:e};let t=e,n={role:t.role,content:(t.content,t.content)};return typeof t.reasoning==`string`&&t.reasoning&&(n.reasoning=t.reasoning),typeof t.time==`number`&&(n.time=t.time),typeof t.model==`string`&&(n.model=t.model),t.usage&&typeof t.usage==`object`&&(n.usage=t.usage),typeof t.scheduleId==`string`&&(n.scheduleId=t.scheduleId),Array.isArray(t.attachments)&&(n.attachments=t.attachments.map(e=>{if(!e||typeof e!=`object`)return e;let t=e;return{name:t.name,size:t.size,type:t.type}})),Array.isArray(t.images)&&(n.images=t.images.map(e=>{if(!e||typeof e!=`object`)return e;let t=e;return{id:t.id,name:t.name,omittedDataUrl:!0}})),Array.isArray(t.refs)&&(n.refs=t.refs),n}var _s=`lantern-harness-session-v1`;function vs(e){return{exportedAt:new Date().toISOString(),format:_s,session:{id:e.id,title:e.title,createdAt:e.createdAt,updatedAt:e.updatedAt,archived:e.archived,pinned:e.pinned,workspacePath:e.workspacePath,goal:e.goal,todos:e.todos,messages:(e.messages??[]).map(gs)}}}function ys(e){return`${JSON.stringify(vs(e),null,2)}\n`}function bs(e){let t=[];t.push(JSON.stringify({type:`session`,exportedAt:new Date().toISOString(),id:e.id,title:e.title,createdAt:e.createdAt,updatedAt:e.updatedAt,workspacePath:e.workspacePath,goal:e.goal}));for(let n of e.messages??[])t.push(JSON.stringify({type:`message`,sessionId:e.id,...gs(n)}));return`${t.join(`
182
+ `)}\n`}function xs(e,t,n){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.rel=`noopener`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function Ss(e,t=`json`){if(typeof document>`u`)return{ok:!1,error:`download requires browser`};let n=new Date().toISOString().replace(/[:.]/g,`-`).slice(0,19),r=`session-${hs(e.title)}-${n}`;if(t===`jsonl`){let t=`${r}.jsonl`;return xs(t,bs(e),`application/x-ndjson;charset=utf-8`),{ok:!0,filename:t}}let i=`${r}.json`;return xs(i,ys(e),`application/json;charset=utf-8`),{ok:!0,filename:i}}var Cs=`tw-session-schedules`,ws=`/__tb_schedule`,Ts=`你可以使用定时提醒工具:
183
+ - schedule_create:创建提醒(text + dueAt ISO 或 delayMinutes)
184
+ - schedule_list:列出本会话未取消的提醒
185
+ - schedule_update:修改 text / dueAt
186
+ - schedule_cancel:取消提醒
187
+ 本地服务在线时提醒落盘并由主机到点写入原会话;否则仅页面打开时投递。`,Es=[{type:`function`,function:{name:`schedule_create`,description:`Create a session reminder. Provide dueAt (ISO datetime) or delayMinutes from now.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Reminder content`},dueAt:{type:`string`,description:`ISO 8601 datetime`},delayMinutes:{type:`number`,description:`Minutes from now (alternative to dueAt)`}},required:[`text`]}}},{type:`function`,function:{name:`schedule_list`,description:`List scheduled reminders for the current session.`,parameters:{type:`object`,properties:{includeDelivered:{type:`boolean`}}}}},{type:`function`,function:{name:`schedule_update`,description:`Update a scheduled reminder text and/or dueAt.`,parameters:{type:`object`,properties:{id:{type:`string`},text:{type:`string`},dueAt:{type:`string`},delayMinutes:{type:`number`}},required:[`id`]}}},{type:`function`,function:{name:`schedule_cancel`,description:`Cancel a scheduled reminder.`,parameters:{type:`object`,properties:{id:{type:`string`}},required:[`id`]}}}];function Ds(){return`sch_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}var Os=null;async function ks(){try{let e=await fetch(`${ws}/health`,{signal:AbortSignal.timeout(1500)});return e.ok?(Os=!!(await e.json()).ok,Os):(Os=!1,!1)}catch{return Os=!1,!1}}function As(){try{let e=localStorage.getItem(c(Cs));if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>Ms(e)).filter(e=>!!e):[]}catch{return[]}}function js(e){localStorage.setItem(c(Cs),JSON.stringify(e.slice(-200)))}function Ms(e){if(!e||typeof e!=`object`)return null;let t=e,n=String(t.id??``).trim(),r=String(t.sessionId??``).trim(),i=String(t.text??``).trim(),a=Number(t.dueAt);if(!n||!r||!i||!Number.isFinite(a))return null;let o=t.status===`delivered`||t.status===`cancelled`||t.status===`scheduled`?t.status:`scheduled`;return{id:n,sessionId:r,text:i.slice(0,500),dueAt:a,status:o,createdAt:Number(t.createdAt)||Date.now(),updatedAt:Number(t.updatedAt)||Date.now()}}function Ns(e){if(typeof e.delayMinutes==`number`&&Number.isFinite(e.delayMinutes)){let t=Math.max(.1,e.delayMinutes);return Date.now()+Math.round(t*6e4)}let t=String(e.dueAt??``).trim();if(!t)return null;let n=Date.parse(t);return Number.isFinite(n)?n:null}function Ps(e,t=!1){return As().filter(t=>t.sessionId===e).filter(e=>t||e.status===`scheduled`).sort((e,t)=>e.dueAt-t.dueAt)}function Fs(e,t){let n=String(t.text??``).trim();if(!n)return{ok:!1,error:`text is required`};if(!e)return{ok:!1,error:`no active session`};let r=Ns(t);if(r==null)return{ok:!1,error:`dueAt or delayMinutes is required`};if(r<Date.now()-5e3)return{ok:!1,error:`dueAt is in the past`};let i=Date.now(),a={id:Ds(),sessionId:e,text:n.slice(0,500),dueAt:r,status:`scheduled`,createdAt:i,updatedAt:i},o=As();return o.push(a),js(o),{ok:!0,reminder:a}}function Is(e,t){let n=String(t.id??``).trim();if(!n)return{ok:!1,error:`id is required`};let r=As(),i=r.findIndex(t=>t.id===n&&t.sessionId===e);if(i<0)return{ok:!1,error:`reminder not found`};let a=r[i];if(a.status!==`scheduled`)return{ok:!1,error:`cannot update status=${a.status}`};let o=a.dueAt;if(t.dueAt!=null||t.delayMinutes!=null){let e=Ns(t);if(e==null)return{ok:!1,error:`invalid dueAt / delayMinutes`};o=e}let s=t.text==null?a.text:String(t.text).trim();if(!s)return{ok:!1,error:`text cannot be empty`};let c={...a,text:s.slice(0,500),dueAt:o,updatedAt:Date.now()};return r[i]=c,js(r),{ok:!0,reminder:c}}function Ls(e,t){let n=String(t??``).trim();if(!n)return{ok:!1,error:`id is required`};let r=As(),i=r.findIndex(t=>t.id===n&&t.sessionId===e);if(i<0)return{ok:!1,error:`reminder not found`};let a={...r[i],status:`cancelled`,updatedAt:Date.now()};return r[i]=a,js(r),{ok:!0,reminder:a}}function Rs(e=Date.now()){let t=As(),n=[],r=!1;for(let i=0;i<t.length;i++){let a=t[i];if(a.status===`scheduled`&&a.dueAt<=e){let o={...a,status:`delivered`,updatedAt:e};t[i]=o,n.push(o),r=!0}}return r&&js(t),n}function zs(e,t){return`⏰ 定时提醒:${e}\n<!--tb-schedule:${t}-->`}async function Bs(e,t){try{let n=await fetch(`${ws}${e}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t),signal:AbortSignal.timeout(8e3)});return n.ok?await n.json():null}catch{return null}}async function Vs(){if(Os!==!1){let e=await Bs(`/claim`,{});if(e&&e.ok)return Os=!0,Array.isArray(e.reminders)?e.reminders.map(Ms).filter(e=>!!e):[];if(Os===!0)return Rs();if(await ks(),Os){let e=await Bs(`/claim`,{});if(e&&e.ok&&Array.isArray(e.reminders))return e.reminders.map(Ms).filter(e=>!!e)}}return Rs()}async function Hs(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}if(Os??await ks()){if(e===`schedule_create`){let e=await Bs(`/create`,{...r,sessionId:n});if(e)return JSON.stringify(e,null,2)}else if(e===`schedule_list`)try{let e=new URLSearchParams({sessionId:n,includeDelivered:r.includeDelivered?`1`:`0`}),t=await fetch(`${ws}/list?${e}`,{signal:AbortSignal.timeout(5e3)});if(t.ok)return JSON.stringify(await t.json(),null,2)}catch{}else if(e===`schedule_update`){let e=await Bs(`/update`,{...r,sessionId:n});if(e)return JSON.stringify(e,null,2)}else if(e===`schedule_cancel`){let e=await Bs(`/cancel`,{id:r.id,sessionId:n});if(e)return JSON.stringify(e,null,2)}else return JSON.stringify({error:`unknown tool: ${e}`});Os=!1}if(e===`schedule_create`)return JSON.stringify(Fs(n,r),null,2);if(e===`schedule_list`){let e=Ps(n,!!r.includeDelivered);return JSON.stringify({ok:!0,count:e.length,reminders:e},null,2)}return e===`schedule_update`?JSON.stringify(Is(n,r),null,2):e===`schedule_cancel`?JSON.stringify(Ls(n,r.id),null,2):JSON.stringify({error:`unknown tool: ${e}`})}var Us=[{id:`explore`,label:`探索`,description:`只读查文件 / 搜网页,汇总结论(不可写盘、无 bash)`,mode:`explore`},{id:`general`,label:`通用`,description:`可读写工作区文件 + 网页(无 bash、不可再派生子代理)`,mode:`general`}],Ws=`你可以使用子代理工具(进程内;默认与主会话同模型,可在设置里改子代理模型):
188
+ - list_agents:列出可用预设与正在运行/最近完成的子代理(仅本会话)
189
+ - spawn_subagent:派生子代理执行独立任务(默认等待完成;background=true 则后台跑)
190
+ - fork_subagent:带着当前对话上下文 fork 子代理并行干活(仍是子代理,不是分叉会话)
191
+ - subagent_list / subagent_status / subagent_await / subagent_abort:查看、查询、等待、中断
192
+ - subagent_message:向运行中的子代理追加指示(steer)
193
+ 适合可隔离的探索/子任务;主会话勿把全部工作塞给子代理。`,Gs=[{type:`function`,function:{name:`list_agents`,description:`List available subagent presets and recent/running subagents.`,parameters:{type:`object`,properties:{includeRecent:{type:`boolean`,description:`Include recent finished agents (default true)`}}}}},{type:`function`,function:{name:`spawn_subagent`,description:`Spawn a subagent to run a focused task. Default waits until done and returns the result.`,parameters:{type:`object`,properties:{agent:{type:`string`,description:`Preset id: explore | general (default explore)`},prompt:{type:`string`,description:`Task for the subagent`},background:{type:`boolean`,description:`If true, return id immediately; use subagent_await later`}},required:[`prompt`]}}},{type:`function`,function:{name:`fork_subagent`,description:`Fork a subagent with a slice of the current conversation context, then run a task.`,parameters:{type:`object`,properties:{agent:{type:`string`,description:`Preset id: explore | general`},prompt:{type:`string`,description:`Task for the forked subagent`},background:{type:`boolean`}},required:[`prompt`]}}},{type:`function`,function:{name:`subagent_list`,description:`List running and recent subagents for this page session.`,parameters:{type:`object`,properties:{includeDone:{type:`boolean`}}}}},{type:`function`,function:{name:`subagent_status`,description:`Get status of one subagent by id in this page session (no wait).`,parameters:{type:`object`,properties:{id:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`subagent_await`,description:`Wait for a background subagent to finish and return its result.`,parameters:{type:`object`,properties:{id:{type:`string`},timeoutMs:{type:`number`,description:`Default 120000`}},required:[`id`]}}},{type:`function`,function:{name:`subagent_abort`,description:`Abort a running subagent in this chat session.`,parameters:{type:`object`,properties:{id:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`subagent_message`,description:`Steer a running subagent by queueing an extra user instruction (applied mid-run when possible).`,parameters:{type:`object`,properties:{id:{type:`string`},message:{type:`string`,description:`Extra instruction for the subagent`}},required:[`id`,`message`]}}}],Ks=2,qs=6,Js=24,Ys=12e3,Xs=new Map,Zs=new Map,Qs=new Map,$s=new Map;function ec(){return`sa_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function tc(e){let t=String(e??`explore`).trim()||`explore`;return Us.find(e=>e.id===t)??Us[0]}function nc(e){let t=String(e.sessionId??``).trim();if(!t)throw Error(`sessionId is required for subagent tools`);return t}function rc(e){let t=0;for(let n of Xs.values())n.status===`running`&&(e&&n.sessionId!==e||t++);return t}function ic(){if(Xs.size<=Js)return;let e=[...Xs.values()].sort((e,t)=>e.updatedAt-t.updatedAt);for(let t of e){if(Xs.size<=Js)break;t.status!==`running`&&(Xs.delete(t.id),Zs.delete(t.id),Qs.delete(t.id),$s.delete(t.id))}}function ac(e){return{id:e.id,sessionId:e.sessionId,agent:e.agent,prompt:e.prompt.slice(0,200),forked:e.forked,status:e.status,createdAt:e.createdAt,updatedAt:e.updatedAt,result:e.result,error:e.error,toolCalls:e.toolCalls}}function oc(e){let t=$s.get(e);return t?.length?($s.set(e,[]),t):[]}function sc(e,t){return e.mode===`explore`?`readonly`:t===`full`?`readwrite`:t}async function cc(e,t,n,r){let i=new AbortController;Zs.set(e.id,i);let a=()=>i.abort();n.parentSignal?.addEventListener(`abort`,a);let o=0;try{if(i.signal.aborted||n.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);let a=sc(t,n.access),s=[],c=`你是 Lantern Harness 子代理「${t.id}」(${t.label})。\n任务:独立完成用户交给你的子任务,给出简洁可核对的结论。\n- 不要声称自己是主会话;不要尝试再派生子代理或执行 shell\n- 工具轮次有限,优先检索再结论`;n.fsEnabled&&(s.push(...gn(a)),c+=`\n\n${vn}`),n.webEnabled&&(s.push(...nr),c+=`\n\n${rr}`),s.length||(c+=`
194
+ (当前无 fs/web 工具,仅凭已有上下文回答。)`);let l=[{role:`system`,content:c}];if(r&&n.parentMessages?.length){let e=n.parentMessages.filter(e=>e.role===`user`||e.role===`assistant`).slice(-12).map(e=>({role:e.role,content:typeof e.content==`string`?e.content.slice(0,4e3):JSON.stringify(e.content).slice(0,4e3)}));l.push(...e)}l.push({role:`user`,content:`【子代理任务】\n${e.prompt}`}),n.onHint?.(`子代理 ${e.id}(${t.id})运行中…`);let u=``;for(let t=0;t<3;t++){if(i.signal.aborted||n.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);let r=oc(e.id),c=[...l];(t>0||r.length)&&c.push({role:`user`,content:[r.length?`【追加指示】\n${r.join(`
195
+ `)}`:``,u.trim()?`【此前进展】\n${u.trim().slice(0,6e3)}`:``,t>0?`请在此前基础上继续完成任务,给出简洁结论。`:``].filter(Boolean).join(`
196
+
197
+ `)});let d=``;for await(let t of ct(n.settings,c,i.signal,{tools:s.length?s:void 0,maxToolRounds:4,thinking:!1,runTool:s.length?async(t,r)=>(o++,n.onHint?.(`子代理 ${e.id}: ${t}`),t.startsWith(`fs_`)?n.runFs(t,r,a):t.startsWith(`web_`)?n.runWeb(t,r):JSON.stringify({error:`subagent cannot use tool: ${t}`})):void 0}))t.type===`content`&&(d+=t.delta);if(d.trim()&&(u=d.trim()),!$s.get(e.id)?.length)break}let d=u.trim().slice(0,Ys);e.status=`done`,e.result=d||`(子代理无文本输出)`,e.toolCalls=o,e.updatedAt=Date.now()}catch(t){let r=t instanceof DOMException&&t.name===`AbortError`||i.signal.aborted||!!n.parentSignal?.aborted;e.status=r?`aborted`:`error`,e.error=r?`aborted`:t instanceof Error?t.message:String(t),e.toolCalls=o,e.updatedAt=Date.now()}finally{n.parentSignal?.removeEventListener(`abort`,a),Zs.delete(e.id),$s.delete(e.id),ic()}}function lc(e,t,n,r,i){if(!e)return{ok:!1,error:`prompt is required`};let a=``;try{a=nc(n)}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}if(rc(a)>=i)return{ok:!1,error:`too many running subagents (max ${i})`};let o=tc(t),s=Date.now(),c={id:ec(),sessionId:a,agent:o.id,prompt:e.slice(0,4e3),forked:r,status:`running`,createdAt:s,updatedAt:s};Xs.set(c.id,c);let l=cc(c,o,n,r).then(()=>c);return Qs.set(c.id,l),{ok:!0,rec:c,job:l}}function uc(e,t,n){let r=lc(String(e.prompt??``).trim(),e.agent,t,n,Ks);return r.ok?e.background===!0?(r.job.finally(()=>{}),JSON.stringify({ok:!0,id:r.rec.id,agent:r.rec.agent,status:`running`,forked:n,hint:`Use subagent_await to get the result`})):r.job.then(e=>JSON.stringify({ok:e.status===`done`,id:e.id,agent:e.agent,status:e.status,forked:e.forked,toolCalls:e.toolCalls??0,result:e.result,error:e.error},null,2)):JSON.stringify({ok:!1,error:r.error})}async function dc(e,t,n){let r=lc(e.trim(),n?.agent??`explore`,t,!!n?.forked,qs);if(!r.ok)return{ok:!1,id:``,text:null,error:r.error};let i=await r.job;return i.status===`done`?{ok:!0,id:i.id,text:i.result??null}:{ok:!1,id:i.id,text:null,error:i.error??i.status}}function fc(e=!0,t){return[...Xs.values()].filter(e=>!t||e.sessionId===t).filter(t=>e||t.status===`running`).sort((e,t)=>t.updatedAt-e.updatedAt).map(ac)}function pc(e,t){let n=String(e??``).trim();if(!n)return{ok:!1,error:`id is required`};let r=Xs.get(n);return!r||t&&r.sessionId!==t?{ok:!1,error:`subagent not found`}:r.status===`running`?(Zs.get(n)?.abort(),{ok:!0,record:{...ac(r),status:`aborted`}}):{ok:!0,record:ac(r)}}function mc(e,t,n){let r=String(e??``).trim(),i=String(t??``).trim();if(!r)return{ok:!1,error:`id is required`};if(!i)return{ok:!1,error:`message is required`};let a=Xs.get(r);if(!a||n&&a.sessionId!==n)return{ok:!1,error:`subagent not found`};if(a.status!==`running`)return{ok:!1,error:`subagent is not running`};let o=$s.get(r)??[];return o.push(i.slice(0,4e3)),$s.set(r,o),{ok:!0,queued:o.length}}async function hc(e,t,n){let r=String(e??``).trim();if(!r)return JSON.stringify({ok:!1,error:`id is required`});let i=typeof t==`number`&&Number.isFinite(t)?Math.min(Math.max(1e3,t),3e5):12e4,a=Xs.get(r);if(!a||n&&a.sessionId!==n)return JSON.stringify({ok:!1,error:`subagent not found`});if(a.status!==`running`)return JSON.stringify({ok:a.status===`done`,...ac(a)},null,2);let o=Qs.get(r);if(!o)return JSON.stringify({ok:!1,error:`subagent waiter missing`});let s=await Promise.race([o,new Promise(e=>{setTimeout(()=>e(null),i)})]);return s?JSON.stringify({ok:s.status===`done`,...ac(s)},null,2):JSON.stringify({ok:!1,id:r,status:`running`,error:`timeout after ${i}ms`})}async function gc(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}let i=``;try{i=nc(n)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}if(e===`list_agents`){let e=r.includeRecent!==!1;return JSON.stringify({ok:!0,presets:Us,agents:fc(e,i),running:rc(i),maxConcurrent:Ks,sessionId:i},null,2)}if(e===`subagent_list`)return JSON.stringify({ok:!0,agents:fc(r.includeDone!==!1,i),running:rc(i),sessionId:i},null,2);if(e===`subagent_status`){let e=String(r.id??``).trim();if(!e)return JSON.stringify({ok:!1,error:`id is required`});let t=Xs.get(e);return!t||t.sessionId!==i?JSON.stringify({ok:!1,error:`subagent not found`}):JSON.stringify({ok:!0,...ac(t)},null,2)}return e===`subagent_abort`?JSON.stringify(pc(r.id,i),null,2):e===`subagent_message`?JSON.stringify(mc(r.id,r.message,i),null,2):e===`subagent_await`?await hc(r.id,r.timeoutMs,i):e===`spawn_subagent`?await Promise.resolve(uc(r,n,!1)):e===`fork_subagent`?await Promise.resolve(uc(r,n,!0)):JSON.stringify({error:`unknown tool: ${e}`})}var _c=4e4,vc=5e4,yc=12,bc=4,xc=80,Sc=`你可以使用 workflow 工具(仅当用户明确要求工作流 / 大规模多代理编排时):
198
+ - 参数:meta{name,description,phases?}、script(纯 JS 函数体,可用 top-level await)、args?
199
+ - 脚本内钩子:agent(prompt, opts?)、parallel(fns)、pipeline(fns)、phase(name)、log(...)
200
+ - agent() 返回子代理结论文本,失败返回 null
201
+ - 一两个子任务请用 spawn_subagent / fork_subagent,勿滥用 workflow`,Cc=[{type:`function`,function:{name:`workflow`,description:`Run a JavaScript orchestration script that fans out subagents and returns a JSON value. Use ONLY when the user explicitly asks for a workflow or large multi-agent orchestration. Script body may use top-level await and helpers: agent, parallel, pipeline, phase, log. Example body: const xs = await parallel([() => agent("task A"), () => agent("task B")]); return xs.filter(Boolean);`,parameters:{type:`object`,properties:{meta:{type:`object`,description:`Workflow identity`,properties:{name:{type:`string`},description:{type:`string`},phases:{type:`array`,items:{type:`string`}}},required:[`name`,`description`]},script:{type:`string`,description:`Plain JavaScript body (no export). Globals: args, agent, parallel, pipeline, phase, log.`},args:{type:`object`,description:`JSON object exposed to the script as args (wrap arrays in a field)`}},required:[`meta`,`script`]}}}];function wc(){return`wf_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function Tc(e){if(!e||typeof e!=`object`)return{error:`meta is required`};let t=e,n=String(t.name??``).trim(),r=String(t.description??``).trim();if(!n)return{error:`meta.name is required`};if(!r)return{error:`meta.description is required`};let i=Array.isArray(t.phases)?t.phases.map(e=>String(e).trim()).filter(Boolean).slice(0,20):void 0;return{name:n.slice(0,80),description:r.slice(0,400),phases:i}}function Ec(e){return/\brequire\b|\bprocess\.|\bchild_process\b|\bfs\.|\bglobalThis\b|\bFunction\s*\(|\beval\s*\(|\bimport\s*\(|\bXMLHttpRequest\b|\blocalStorage\b|\bindexedDB\b|\bdocument\.|\bwindow\./.test(e)?`script uses disallowed APIs (browser/Node escape)`:null}async function Dc(e,t,n,r){let i=Array(e.length),a=0;async function o(){for(;a<e.length;){if(r?.aborted)throw new DOMException(`Aborted`,`AbortError`);let t=a++;i[t]=await n(e[t],t)}}let s=Math.min(Math.max(1,t),e.length||1);return await Promise.all(Array.from({length:s},()=>o())),i}async function Oc(e,t,n,r){let i=wc(),a=[],o=[],s=0,c=yc,l=(...t)=>{let n=t.map(e=>{if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}).join(` `);a.push(n.slice(0,500)),a.length>xc&&a.splice(0,a.length-xc),r.onHint?.(`workflow ${e.name}: ${n.slice(0,80)}`)},u=async(e,t)=>{if(r.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);let n=String(e??``).trim();if(!n)return null;if(c<=0)return l(`agent budget exhausted`),null;c--,s++;let i=t?.label?` [${t.label}]`:``;l(`agent${i}: ${n.slice(0,120)}`);let a=await dc(n,r,{agent:t?.agent??`explore`,forked:!1});return a.ok?a.text:(l(`agent failed${i}: ${a.error??`error`}`),null)},d=async(e,t=bc)=>{if(!Array.isArray(e))throw Error(`parallel() expects an array of functions`);return Dc(e.slice(0,yc),Math.min(bc,t||bc),async e=>{if(typeof e!=`function`)return null;try{return await e()}catch(e){return l(`parallel task error`,e instanceof Error?e.message:String(e)),null}},r.parentSignal)},f=async e=>{if(!Array.isArray(e))throw Error(`pipeline() expects an array of functions`);let t=[];for(let n of e.slice(0,yc)){if(r.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);if(typeof n!=`function`)t.push(null);else try{t.push(await n())}catch(e){l(`pipeline task error`,e instanceof Error?e.message:String(e)),t.push(null)}}return t},p=t=>{let n=String(t??``).trim()||`phase`;o.push(n.slice(0,80)),l(`phase: ${n}`),r.onHint?.(`workflow ${e.name} · ${n}`)},m=(...e)=>l(...e),h=Ec(t);if(h)return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:0,stopReason:`error`,error:h};if(t.length>_c)return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:0,stopReason:`error`,error:`script too long (max ${_c})`};try{let c=Object.getPrototypeOf(async function(){}).constructor,l=await new c(`args`,`agent`,`parallel`,`pipeline`,`phase`,`log`,`"use strict";\n${t}`)(n,u,d,f,p,m);if(r.parentSignal?.aborted)return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:s,stopReason:`cancelled`,error:`workflow run was cancelled`,logs:a,phases:o};let h=l===void 0?null:l;try{let e=JSON.stringify(h);h=e&&e.length>vc?{truncated:!0,preview:e.slice(0,vc)}:e===void 0?null:JSON.parse(e)}catch{h=String(h).slice(0,vc)}return{ok:!0,kind:`foreground`,runId:i,name:e.name,agentsStarted:s,result:h,stopReason:`completed`,logs:a,phases:o}}catch(t){let n=t instanceof DOMException&&t.name===`AbortError`||!!r.parentSignal?.aborted;return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:s,stopReason:n?`cancelled`:`error`,error:n?`workflow run was cancelled`:t instanceof Error?t.message:String(t),logs:a,phases:o}}}async function kc(e,t,n){if(e!==`workflow`)return JSON.stringify({error:`unknown tool: ${e}`});let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}let i=Tc(r.meta);if(`error`in i)return JSON.stringify({ok:!1,error:i.error});let a=String(r.script??``);if(!a.trim())return JSON.stringify({ok:!1,error:`script is required`});let o=r.args&&typeof r.args==`object`&&!Array.isArray(r.args)?r.args:{};n.onHint?.(`workflow "${i.name}" 启动…`);let s=await Oc(i,a,o,n);return s.ok?[`workflow "${s.name}" completed (${s.agentsStarted} agent${s.agentsStarted===1?``:`s`}).`,`Return value:`,JSON.stringify(s.result,null,2)].join(`
202
+ `):s.stopReason===`cancelled`?`Error: workflow run was cancelled${s.error&&s.error!==`workflow run was cancelled`?` (${s.error})`:``}`:`Error: workflow run failed: ${s.error??`unknown`}`}function Ac(e){return e===`md`?`Markdown`:e===`xlsx`||e===`xls`?`Excel`:e===`docx`||e===`doc`?`Word`:e===`dir`?`文件夹`:e===`file`?`文件`:e.toUpperCase()}function jc(e,t){return!(t&&![e.title,e.category,e.id,e.description,e.path,e.format,Ac(e.format)].join(`
203
+ `).toLowerCase().includes(t)&&(t!==`excel`&&t!==`表格`&&t!==`xls`||e.format!==`xlsx`&&e.format!==`xls`)&&(t!==`word`&&t!==`文档`&&t!==`doc`||e.format!==`docx`&&e.format!==`doc`)&&(t!==`md`&&t!==`markdown`&&t!==`标记`||e.format!==`md`))}var Mc=`用户可能通过「@」引用了知识库与模板下的 Markdown / Excel / Word 等文档(消息中会列出路径)。仅当用户引用了文档,或问题明显依赖知识库/模板时,再调用 kb_read / kb_search;一般闲聊或无关问题不要为了凑答去检索。读取时:Markdown 为全文,Excel/Word 为字段或元数据摘要;不要臆造未读到的正文。`,Nc=[{type:`function`,function:{name:`kb_search`,description:`在知识库与模板(含 Markdown、Excel、Word)中按关键词搜索,返回 path、标题、格式与摘要。`,parameters:{type:`object`,properties:{query:{type:`string`,description:`搜索关键词,如 接口、excel、用例`},scope:{type:`string`,enum:[`all`,`knowledge`,`templates`],description:`限定范围,默认 all`}},required:[`query`]}}},{type:`function`,function:{name:`kb_read`,description:`按 path 读取文档。Markdown 返回全文;Excel/Word 返回构建期摘要。path 如 测试模板库/接口测试用例/接口测试用例模版.xlsx 或 知识库管理/xxx.md`,parameters:{type:`object`,properties:{path:{type:`string`,description:`相对路径(与引用列表中的 path 一致)`}},required:[`path`]}}}];function Pc(e){return e.trim().replace(/^\/+/,``).replace(/\\/g,`/`)}function Fc(e,t){let n=Pc(t),r=n.replace(/\.md$/i,``);return e.find(e=>{let t=Pc(e.path);return t===n||t===`${r}.md`||`${e.collection}/${e.id}`===n||`${e.collection}/${e.id}.md`===n||e.id===n||e.id===r})}async function Ic(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}let i=typeof n.base==`string`&&n.base?n.base:`/`,a=i.endsWith(`/`)?i:`${i}/`;try{switch(e){case`kb_search`:{let e=String(r.query??``).trim().toLowerCase(),t=String(r.scope??`all`);if(!e)return JSON.stringify({error:`query required`,results:[]});let i=n.docs.filter(e=>t===`all`||e.collection===t).filter(t=>jc(t,e)).slice(0,12).map(e=>({path:e.path,title:e.title,category:e.category,collection:e.collection,format:e.format,snippet:e.description||e.category}));return JSON.stringify({results:i,count:i.length})}case`kb_read`:{let e=Fc(n.docs,String(r.path??``));if(!e)return JSON.stringify({error:`未找到文档;请使用 kb_search 返回的 path`,path:String(r.path??``)});if(e.attachText)return JSON.stringify({path:e.path,title:e.title,category:e.category,format:e.format,content:e.attachText,note:`Office 模板返回构建期摘要,非完整二进制内容`});let t=`${a}raw/${e.collection}/${e.id}.md`,i=await fetch(t);if(!i.ok)return JSON.stringify({error:`读取失败 HTTP ${i.status}`,path:e.path});let o=await i.text();return JSON.stringify({path:e.path,title:e.title,category:e.category,format:e.format,content:o})}default:return JSON.stringify({error:`unknown tool: ${e}`})}}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var Lc=e=>e;function Rc(e){if(e.structuredPlugin)return[];let t=e.caps,n=e.access,r=!!e.planGatesWrites,i=e.planPhase??`off`,a=[];return t.knowledge&&a.push(...Lc(Nc)),t.fs&&(a.push(...Lc(gn(n))),a.push(...Lc(hn)),a.push(...Lc(Ca)),a.push(...Lc(wo)),a.push(Di),r||(a.push(Ci),a.push(xn))),t.bash&&n!==`readonly`&&(a.push(ur),a.push(...Lc(fr))),t.pwsh&&n!==`readonly`&&(a.push(dr),a.push(...Lc(Qn))),(t.bash||t.pwsh)&&n!==`readonly`&&a.push(...Lc(ir)),t.web&&a.push(...Lc(nr)),t.memory&&a.push(...Lc(jr)),t.interact!==!1&&a.push(Fo),t.todos&&a.push(...Lc(Ya)),t.tasks&&a.push(...Lc(ho)),t.projects&&a.push(...Lc(ja)),t.iterations&&a.push(...Lc(Ma)),t.pmRequirements&&a.push(...Lc(Na)),t.bugs&&a.push(...Lc(Pa)),t.interact!==!1&&a.push(Io),t.goal!==!1&&a.push(...Lc(as)),t.schedule!==!1&&a.push(...Lc(Es)),t.subagent!==!1&&a.push(...Lc(Gs)),t.workflow!==!1&&a.push(...Lc(Cc)),t.mcp!==!1&&e.mcpTools?.length&&a.push(...e.mcpTools),(i===`planning`||i===`approved`)&&a.push(Wo),a}function zc(e){return!(e&&e!==`ask_user_question`&&e!==`submit_plan`&&e!==`workflow`&&e!==`spawn_subagent`&&e!==`fork_subagent`&&e!==`list_agents`&&!e.startsWith(`subagent_`))}function Bc(e){return e.filter(e=>{let t=e.function?.name??``;return!!t&&!zc(t)})}function Vc(e){let t=String(e||``);return t===`bash`||t===`pwsh`||t.endsWith(`_session_exec`)?12e4:t.startsWith(`bash_session_`)||t.startsWith(`pwsh_session_`)?3e4:t===`web_fetch`?35e3:t===`web_search`?3e4:t.startsWith(`mcp__`)?6e4:t.startsWith(`fs_`)||t.startsWith(`kb_`)||t.startsWith(`memory_`)?3e4:t.startsWith(`subagent_`)||t===`spawn_subagent`||t===`fork_subagent`?3e5:6e4}async function Hc(e,t,n=`tool`){let r=Math.max(1e3,Math.min(6e5,Number(t)||6e4)),i;try{return await Promise.race([e,new Promise((e,t)=>{i=setTimeout(()=>{t(Error(`${n} timed out after ${r}ms`))},r)})])}finally{i&&clearTimeout(i)}}function Uc(e){return async(t,n)=>{try{return await Hc(e(t,n),Vc(t),t||`tool`)}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}}var Wc=/^\d{4}-\d{2}-\d{2}$/;function Gc(e){return String(e).padStart(2,`0`)}function Kc(e,t,n){return`${e}-${Gc(t+1)}-${Gc(n)}`}function qc(e){return e.replace(/-/g,`.`)}function Jc(e,t=new Date,n){let r=t.getFullYear(),i=t.getMonth(),a=t.getDate();if(e===`day`){let e=Kc(r,i,a);return{from:e,to:e,label:`日报(${qc(e)})`}}if(e===`month`){let e=new Date(r,i+1,0).getDate();return{from:Kc(r,i,1),to:Kc(r,i,e),label:`月报(${r}.${Gc(i+1)})`}}let o=t.getDay(),s=o===0?-6:1-o,c=n?.weekOffset??0,l=new Date(r,i,a+s+c*7),u=new Date(l.getFullYear(),l.getMonth(),l.getDate()+6),d=Kc(l.getFullYear(),l.getMonth(),l.getDate()),f=Kc(u.getFullYear(),u.getMonth(),u.getDate());return{from:d,to:f,label:`周报(${qc(d)}-${qc(f)})`}}function Yc(e){let t=e.trim();return/上一周|上周/.test(t)}function Z(e,t,n){return Wc.test(e)?e>=t&&e<=n:!1}function Xc(e,t,n,r){let i=Wc.test(e)?e:Wc.test(t)?t:``,a=Wc.test(t)?t:Wc.test(e)?e:``;return!i||!a?!1:(i<=a?i:a)<=r&&(i<=a?a:i)>=n}function Zc(e,t,n){return e.filter(e=>e.startDate||e.dueDate?Xc(e.startDate,e.dueDate,t,n):Z((e.createdAt||``).slice(0,10),t,n))}function Qc(e,t,n){return e.filter(e=>e.startDate||e.dueDate?Xc(e.startDate,e.dueDate,t,n):Z((e.createdAt||``).slice(0,10),t,n))}function $c(e,t,n){return e.filter(e=>!e.draft&&Z(e.date,t,n))}function el(e,t,n){return e.filter(e=>e.draft?!1:Z(e.date,t,n)?!0:Xc(e.startDate||e.date,e.endDate||e.date,t,n))}function tl(e){if(!e.length)return[`### 待办事项`,``,`本期无相关记录。`,``];let t=[`### 待办事项`,``];for(let n of e){let e=[In[n.status]||n.status,n.linkedTask?`任务:${n.linkedTask}`:``,n.startDate||n.dueDate?`${n.startDate||`—`} ~ ${n.dueDate||`—`}`:``].filter(Boolean);t.push(`- ${n.title||`(无标题)`}(${e.join(` · `)})`),n.note.trim()&&t.push(` 备注:${n.note.trim()}`)}return t.push(``),t}function nl(e){if(!e.length)return[`### 任务管理`,``,`本期无相关记录。`,``];let t=[`### 任务管理`,``];for(let n of e){let e=[Bn[n.status]||n.status,n.startDate||n.dueDate?`${n.startDate||`—`} ~ ${n.dueDate||`—`}`:``].filter(Boolean);t.push(`- ${n.title||`(无标题)`}(${e.join(` · `)})`),n.note.trim()&&t.push(` 备注:${n.note.trim()}`)}return t.push(``),t}function rl(e){if(!e.length)return[`### 测试统计`,``,`本期无相关记录。`,``];let t=[`### 测试统计`,``],n=[...e].sort((e,t)=>t.date.localeCompare(e.date)||t.createdAt.localeCompare(e.createdAt));for(let e of n){let n=e.dimensions[0]||`(未选维度)`;t.push(`- ${e.date} · ${n}:${e.count}`)}return t.push(``),t}function il(e,t){if(!e.length)return[`### 用例执行统计`,``,`本期无相关记录。`,``];let n=[`### 用例执行统计`,``],r=w(t?.length?t:e),i=new Map;for(let t of e){let e=t.project.trim()||`(无项目:${t.id})`,n=i.get(e);n?n.push(t):i.set(e,[t])}let a=[...i.entries()].sort((e,t)=>{let n=v(e[1])[0]?.date??``;return(v(t[1])[0]?.date??``).localeCompare(n)});for(let[e,t]of a){let e=v(t),i=e[0]?.project.trim()??``,a=i||`(无项目)`,o=i?r.get(i)??0:0,s=e.find(e=>e.total>0)??e[0],c=s?S(s,o||void 0):0,l=s?y(s,o||void 0).toFixed(2):`0.00`,u=e.find(e=>e.startDate||e.endDate)??e[0],d=u?.startDate||u?.endDate?`(周期 ${u?.startDate||`—`} ~ ${u?.endDate||`—`})`:``,f=o>0?String(o):`—`;n.push(`- **${a}**${d}:基线 ${f} · 已执行 ${c} / ${f}(${l}%)`);for(let t of e){let e=x(t),r=C(t),i=S(t,o||void 0),a=y(t,o||void 0).toFixed(2),s=o>0?o:t.total||`—`;n.push(` - ${t.date}:本轮总数 ${t.total} · 待执行 ${t.pending} · 本轮已执行 ${r} · 剩余 ${e} · 累计已执行 ${i} / ${s}(${a}%)`)}}return n.push(``),n}function al(e){let{period:t,include:n}=e,r=[`## 本期工作数据`,``,`区间:${t.from} ~ ${t.to}(${t.label})`,``,`以下由插件按区间带入,请据此整理汇报;不要编造未出现的数字或事项。`,``];return n.todos&&r.push(...tl(e.todos??[])),n.tasks&&r.push(...nl(e.tasks??[])),n.testStats&&r.push(...rl(e.testStats??[])),n.caseExec&&r.push(...il(e.caseExec??[],e.caseExecAll)),!n.todos&&!n.tasks&&!n.testStats&&!n.caseExec?``:r.join(`
204
+ `).trimEnd()+`
205
+ `}async function ol(e,t,n=new Date,r){let i=Jc(e,n,{weekOffset:r?.weekOffset}),a={todos:!!t.todos,tasks:!!t.tasks,testStats:!!t.testStats,caseExec:!!t.caseExec};if(!a.todos&&!a.tasks&&!a.testStats&&!a.caseExec)return``;let[o,s,c,l]=await Promise.all([a.todos?An().then(e=>Zc(e,i.from,i.to)).catch(()=>[]):Promise.resolve(void 0),a.tasks?qn().then(e=>Qc(e,i.from,i.to)).catch(()=>[]):Promise.resolve(void 0),a.testStats?Vr().then(e=>$c(e.items,i.from,i.to)).catch(()=>[]):Promise.resolve(void 0),a.caseExec?b().then(e=>({periodItems:el(e.items,i.from,i.to),all:e.items.filter(e=>!e.draft)})).catch(()=>({periodItems:[],all:[]})):Promise.resolve(void 0)]);return al({period:i,todos:o,tasks:s,testStats:c,caseExec:l?.periodItems,caseExecAll:l?.all,include:a})}function sl(e){let t=e.trim();return t.startsWith(`生成日报`)||/^生成.*日报/.test(t)?`day`:t.startsWith(`生成周报`)||/^生成.*(上周|上一周)?周报/.test(t)?`week`:t.startsWith(`生成月报`)||/^生成.*月报/.test(t)?`month`:null}var cl=10485760,ll=new Set([`png`,`jpg`,`jpeg`,`webp`,`gif`]),ul=new Set([`xlsx`,`xls`,`xlsm`,`xlsb`,`ods`]),dl=new Set([`docx`]),fl=new Set(`md.markdown.txt.text.json.csv.tsv.yaml.yml.xml.html.htm.log.sql.feature.toml.ini.conf.properties.rst.css.js.ts.tsx.jsx.py.java.go.rs.sh.bash.zsh.env.gitignore.dockerfile.makefile.svg`.split(`.`)),pl=[...fl,...ll,...ul,...dl,`doc`,`pdf`];function ml(e){let t=e.lastIndexOf(`.`);return t>=0?e.slice(t+1).toLowerCase():``}async function hl(e){let t=await e.arrayBuffer(),n=Pe(t,{type:`array`}),r=[`# ${e.name}`,`工作表数:${n.SheetNames.length}`,``];for(let e of n.SheetNames){let t=n.Sheets[e];if(!t)continue;let i=Fe.sheet_to_csv(t);r.push(`## ${e}`,i.trim()||`(空表)`,``)}return r.join(`
206
+ `).trim()}async function gl(t){let n=await Ke(()=>import(`./lib.S37S0T6S.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1,2])),r=await t.arrayBuffer(),i=await n.extractRawText({arrayBuffer:r}),a=(i.value??``).trim(),o=[`# ${t.name}`,``];return i.messages?.length&&o.push(`(解析备注:${i.messages.slice(0,3).map(e=>e.message).join(`;`)})`,``),o.push(a||`(未提取到正文)`),o.join(`
207
+ `)}async function _l(e){let t=ml(e.name);if(!t)throw Error(`${e.name}:无法识别扩展名`);if(e.size>10485760)throw Error(`${e.name}:超过 ${Math.round(cl/1024/1024)} MB`);if(ll.has(t)||e.type.startsWith(`image/`))return{kind:`image`,file:e};if(ul.has(t))return{kind:`text`,name:e.name,size:e.size,content:await hl(e)};if(dl.has(t))return{kind:`text`,name:e.name,size:e.size,content:await gl(e)};if(t===`doc`)throw Error(`${e.name}:旧版 .doc 请另存为 .docx 后再添加`);if(t===`pdf`)throw Error(`${e.name}:PDF 暂不解析正文,请转 Markdown/图片后添加`);if(fl.has(t)||e.type.startsWith(`text/`)||e.type===`application/json`)return{kind:`text`,name:e.name,size:e.size,content:await e.text()};throw Error(`${e.name}:暂不支持的类型 .${t}`)}var vl=[{prefix:`知识库管理`,aliases:[`knowledge`],collection:`knowledge`,category:`知识库`},{prefix:`用例管理`,aliases:[`cases`],collection:`cases`,category:`用例`},{prefix:`提示词管理`,aliases:[`prompts`],collection:`prompts`,category:`提示词`},{prefix:`测试模板库`,aliases:[`templates`],collection:`templates`,category:`模板`}];function yl(e){return e.replace(/\\/g,`/`).replace(/\/+/g,`/`)}function bl(e){let t=yl(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t}function xl(e){let t=e.lastIndexOf(`.`);return t>=0?e.slice(t+1).toLowerCase():`file`}function Sl(e){let t=e.trim();if(!/^file:/i.test(t))return null;try{let e=new URL(t),n=decodeURIComponent(e.pathname||``);return/^\/[A-Za-z]:\//.test(n)&&(n=n.slice(1)),yl(n)}catch{return null}}function Cl(e){let t=yl(e);return t.startsWith(`/`)||/^[A-Za-z]:\//.test(t)}function wl(e){let t=e.trim();return!t||t.includes(`
208
+ `)||/\s/.test(t)||t.includes(`://`)||t.includes(`/`)||t.includes(`\\`)?!1:/\.[A-Za-z0-9]{1,16}$/.test(t)}function Tl(e){let t=e.trim();return!t||t.includes(`
209
+ `)?!1:!!(/^file:/i.test(t)||Cl(t)||(t.includes(`/`)||t.includes(`\\`))&&!/\s/.test(t)&&t.length<512)}function El(e){let t=[],n=e.getData(`text/uri-list`)||``;for(let e of n.split(/\r?\n/)){let n=e.trim();if(!n||n.startsWith(`#`))continue;let r=Sl(n);r?t.push(r):Cl(n)&&t.push(yl(n))}let r=(e.getData(`text/plain`)||``).trim();if(r&&!r.includes(`
210
+ `)){let e=Sl(r);e?t.push(e):Tl(r)&&!wl(r)&&t.push(yl(r))}return[...new Set(t)]}function Dl(e){return{collection:e.collection,id:`${e.collection}:${e.path}`,title:e.title||bl(e.path),category:e.category,path:e.path,format:e.format||xl(e.path)}}function Ol(e,t){let n=yl(e),r=yl(t).replace(/\/$/,``);return n===r?``:n.startsWith(`${r}/`)?n.slice(r.length+1):null}function kl(e,t){let n=yl(e.trim()),r=Sl(n);r&&(n=r);let i=t.projectRoot?yl(t.projectRoot):``,a=t.workspace?yl(t.workspace):``,o=n;if(i){let e=Ol(n,i);e!=null&&(o=e)}for(let{prefix:e,aliases:t,collection:n,category:r}of vl)for(let i of[e,...t??[]])if(o!==i&&o.startsWith(`${i}/`)){let e=o.slice(i.length+1);if(!e)continue;return Dl({collection:n,path:e,title:bl(e),category:r,format:xl(e)})}if(a){let e=Ol(n,a);if(e!=null&&e!==``)return Dl({collection:`workspace`,path:e,title:bl(e),category:t.workspaceLabel||`工作区`,format:xl(e)})}if(!Cl(o)&&o.includes(`/`)){let e=o.split(`/`)[0]||``,n=vl.find(t=>t.prefix===e||t.aliases?.includes(e));if(n){let t=o.slice(e.length+1);if(t)return Dl({collection:n.collection,path:t,title:bl(t),category:n.category,format:xl(t)})}return Dl({collection:`workspace`,path:o,title:bl(o),category:t.workspaceLabel||`工作区`,format:xl(o)})}return null}function Al(e,t){let n=e.trim();if(!n)return null;let r=n.toLowerCase(),i=t.filter(e=>{let t=bl(e.path).toLowerCase(),n=(e.title||``).toLowerCase();return t===r||n===r||e.path.toLowerCase()===r});return i.length===1?Dl(i[0]):null}function jl(e){return[`# ${e.replace(/\.md$/i,``).trim()||`用例生成提示词`}`,``,`> 用例生成提示词:确认后本轮只按这份提示词写用例,工作台的系统提示词不再叠加。`,``,`## 生成用例`,``,`- 逐条覆盖需求 / 用户故事,一条用例只验一个点,不合并步骤;`,`- 前置条件、操作步骤、预期结果要一一对应,步骤给人看也能照着执行;`,`- 正常流程之外补齐边界值、异常与业务规则,非功能(性能 / 兼容 / 安全)按需覆盖;`,`- 每条用例标注优先级 P0–P3,P0 放主流程与核心校验;`,`- 字段与顺序严格跟随用例模板;Ideal 表时「模块」=大模块、「子模块」=小模块原文,并按小模块行序输出;`,`- 「引用需求点」只填材料里真实的 RO-… id,格式「RO-id 标题或原文」;不要填 US-… / TP-…;补充场景同引用并在「备注」写「补充:…」;`,`- 「待业务确认」类不确定项也要写成用例,并在「备注」标注「待业务确认:…」,不要只写进未覆盖说明;`,``].join(`
211
+ `)}async function Ml(e){let t=Hr(e);if(!t)throw Error(`文件名不合法:不能包含 / \\ : * ? " < > |`);return await Ve(`prompts`,t,jl(t)),t}var Q=ie();function Nl({mode:e,entityLabel:t,currentLabel:n,placeholder:r,hint:i,deleteMessage:a,deleteNote:o,error:s=``,onClose:c,onSubmit:l,onDelete:u}){let[d,f]=(0,K.useState)(``),p=(0,K.useRef)(null);if((0,K.useEffect)(()=>{if(e!==`add`&&e!==`edit`)return;f(e===`edit`?n:``);let t=window.setTimeout(()=>{p.current?.focus(),p.current?.select()},50);return()=>window.clearTimeout(t)},[e,n]),typeof document>`u`)return null;let m=d.trim(),h=(0,Q.jsxs)(ee,{open:e!==null,onClose:c,className:`relative z-110`,children:[(0,Q.jsx)(te,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,Q.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,Q.jsxs)(O,{transition:!0,className:`tw-confirm-dialog tw-dialog-panel-anim relative w-full max-w-sm rounded-xl border border-stone-200 bg-white p-5 shadow-xl`,children:[(0,Q.jsx)(k,{className:`tw-confirm-title pr-8 text-base font-semibold text-stone-900`,children:e===`delete`?`删除${t}`:e===`edit`?`编辑${t}`:`新增${t}`}),e===`delete`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`tw-confirm-msg mt-3 text-sm leading-relaxed text-stone-600`,children:a?a(n):`确定删除「${n}」?删除后该项将不再出现在配置里,已生成的内容不受影响。`}),o?(0,Q.jsx)(`p`,{className:`mt-2 rounded-lg bg-stone-50 px-3 py-2 text-[11px] leading-4 text-stone-500`,children:o}):null]}):(0,Q.jsxs)(`label`,{className:`tw-confirm-msg mt-4 block text-xs font-medium text-stone-500`,children:[`名称`,(0,Q.jsx)(`input`,{ref:p,value:d,maxLength:40,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m&&l(m))},placeholder:r,className:`mt-1.5 h-9 w-full rounded-lg border border-stone-200 bg-white px-3 text-sm text-stone-800 outline-none transition-colors focus:border-[#4176e6] focus:ring-2 focus:ring-[#4176e6]/30`})]}),s?(0,Q.jsx)(`p`,{className:`mt-2 text-[11px] font-normal leading-relaxed text-red-600`,role:`alert`,children:s}):null,e===`delete`||!i?null:(0,Q.jsx)(`p`,{className:`mt-2 text-[11px] leading-4 text-stone-400`,children:i(m)}),(0,Q.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:c,className:`tw-confirm-cancel h-8 rounded-lg px-3 text-sm text-stone-600 transition-colors hover:bg-stone-100`,children:`取消`}),e===`delete`?(0,Q.jsx)(`button`,{type:`button`,onClick:u,className:`h-8 rounded-lg bg-red-600 px-4 text-sm font-medium text-white transition-colors hover:bg-red-700`,children:`删除`}):(0,Q.jsx)(`button`,{type:`button`,disabled:!m,onClick:()=>l(m),className:`h-8 rounded-lg bg-[#4176e6] px-4 text-sm font-medium text-white transition-colors hover:bg-[#3565c7] disabled:opacity-40`,children:e===`edit`?`保存`:`新增`})]})]})})]});return(0,qr.createPortal)(h,document.body)}function Pl({mode:e,currentLabel:t,templateFolder:n,error:r=``,onClose:i,onSubmit:a,onDelete:o}){return(0,Q.jsx)(Nl,{mode:e,entityLabel:`用例类型`,currentLabel:t,placeholder:`如:安全测试`,error:r,onClose:i,onSubmit:a,onDelete:o,deleteMessage:e=>(0,Q.jsxs)(Q.Fragment,{children:[`确定删除「`,e,`」?已有用例与模板不会被删除,但该类型将不再出现在生成配置里。`]}),deleteNote:(0,Q.jsxs)(Q.Fragment,{children:[`关联模板目录:测试模板库/`,n,`/`]}),hint:e=>(0,Q.jsxs)(Q.Fragment,{children:[`模板目录随名称生成:测试模板库/`,e||`名称`,`用例/`]})})}var Fl=[{value:`md`,label:`Markdown 表格`},{value:`xlsx`,label:`Excel`},{value:`csv`,label:`CSV`}];async function Il(e,t){let n=t.find(t=>t.id===e)?.templateFolder??Ee(e).templateFolder;try{let{entries:e}=await Ie(`templates`,n),t=e.filter(e=>e.type===`file`).sort((e,t)=>(t.mtime??0)-(e.mtime??0)),r=[];for(let e of t){let t=e.name.toLowerCase(),n=[...Ne],i=``;try{if(t.endsWith(`.xlsx`)||t.endsWith(`.xls`)){let t=await Le(`templates`,e.path);if(t.encoding===`base64`&&t.contentBase64){let e=He(t.contentBase64);n=e.headers,i=e.body}}else if(t.endsWith(`.csv`)){let t=await Re(`templates`,e.path),r=Ue(t.content);n=r.headers,i=r.body}else if(t.endsWith(`.md`)||t.endsWith(`.txt`)){let t=await Re(`templates`,e.path),r=We(t.content);n=r.headers,i=r.body}}catch{i=``}r.push({id:e.path,title:e.name.replace(/\.[^.]+$/,``),body:i,headers:n})}return r}catch{return[]}}async function Ll(t){let n=t.toLowerCase();if(n.endsWith(`.md`)||n.endsWith(`.txt`)||n.endsWith(`.csv`))return(await Re(`requirements`,t)).content;if(n.endsWith(`.xlsx`)||n.endsWith(`.xls`)){let e=await Le(`requirements`,t);if(e.encoding!==`base64`||!e.contentBase64)throw Error(`无法读取 Excel`);let n=await Ke(()=>import(`./case-fields.CmePqYfh.js`).then(e=>e.d),__vite__mapDeps([3,1])),r=n.read(e.contentBase64,{type:`base64`,cellDates:!0}),i=[];for(let e of r.SheetNames){let t=r.Sheets[e];if(!t)continue;let a=n.utils.sheet_to_csv(t,{blankrows:!1}).trim();a&&i.push(`## 工作表:${e}\n${a}`)}return i.join(`
212
+
213
+ `).trim()}if(n.endsWith(`.docx`)){let n=await Le(`requirements`,t);if(n.encoding!==`base64`||!n.contentBase64)throw Error(`无法读取 docx`);let r=atob(n.contentBase64),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return((await(await Ke(()=>import(`./lib.S37S0T6S.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1,2]))).extractRawText({arrayBuffer:i.buffer})).value??``).trim()}return``}function Rl({open:e,onClose:t,initial:n,presetStories:r,onConfirm:i}){let[a,o]=(0,K.useState)(!1),[c,l]=(0,K.useState)([]),[d,f]=(0,K.useState)(n?.reqPath??``),[p,g]=(0,K.useState)(n?.reqSource?.kind===`stories`?`stories`:`doc`),[_,v]=(0,K.useState)([]),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(n?.reqSource?.kind===`stories`?n.reqSource.docId:``),[C,w]=(0,K.useState)(n?.reqSource?.kind===`stories`?n.reqSource.storyIds:[]),[T,E]=(0,K.useState)(()=>Ce()),[D,O]=(0,K.useState)(n?.caseType??Ce()[0]?.id??`functional`),[k,ee]=(0,K.useState)([]),[te,ne]=(0,K.useState)(n?.templateId??``),[re,A]=(0,K.useState)([]),[j,ie]=(0,K.useState)(!1),[ae,M]=(0,K.useState)(``),[se,ce]=(0,K.useState)(!1),[le,P]=(0,K.useState)(n?.promptBody??``),[F,ue]=(0,K.useState)([]),[de,fe]=(0,K.useState)(n?.knowledgePaths??[]),[I,pe]=(0,K.useState)(n?.testPointIds??[]),[me,he]=(0,K.useState)(n?.outputFormat??`xlsx`),[ge,L]=(0,K.useState)(null),[R,_e]=(0,K.useState)(!1),[ve,ye]=(0,K.useState)(null),[be,Oe]=(0,K.useState)(null),[ke,Ae]=(0,K.useState)(()=>m(`prompts`)),[je,Me]=(0,K.useState)(()=>m(`knowledgeLib`)),[Pe,Fe]=(0,K.useState)(()=>m(`requirements`)),[Le,Be]=(0,K.useState)(()=>m(`templates`)),[Ve,He]=(0,K.useState)(()=>m(`reqAnalysis`)),Ue=(0,K.useMemo)(()=>k.find(e=>e.id===te)??k[0],[k,te]),We=T.find(e=>e.id===D)??T[0]??Ee(D),Ge=We.label,Ke=(We.promptPath??``).trim(),qe=Ke&&re.some(e=>e.path===Ke)?Ke:``,Je=ke&&j&&!qe;(0,K.useEffect)(()=>{if(!e)return;if(!ke){M(``);return}if(!j)return;let t=new Set(re.map(e=>e.path)),r=(We.promptPath??``).trim();if(r&&t.has(r)){M(r);return}let i=(n?.promptPath??``).trim();if(!r&&i&&t.has(i))try{we(D,i),E(Ce()),M(i);return}catch{}M(``)},[e,ke,j,re,We.promptPath,D,n?.promptPath]);async function B(e){we(D,e),E(Ce()),M(e),ce(!1),await u().catch(()=>void 0),Ur(),z(`已为「${Ge}」挂载「${e}」`,`success`)}let Ye=(0,K.useCallback)(async()=>{async function e(t,n){let{entries:r}=await Ie(`prompts`,t);for(let t of r)t.type===`file`?n.push(t):await e(t.path,n)}try{let t=[];await e(`.`,t);let n=t.filter(e=>!mt(e.path));return n.sort((e,t)=>(t.mtime??0)-(e.mtime??0)),A(n),n}catch{return A([]),[]}},[]);async function Xe(e){let t=await Ml(e);return await Ye(),t}function Ze(e){let t=Ce();E(t),O(n=>{let r=e??n;return t.some(e=>e.id===r)?r:t[0]?.id??n})}function Qe(e){try{ve===`add`?(Ze(De(e).id),z(`已新增用例类型「${e}」`,`success`)):ve===`edit`&&(Te(D,e),Ze(D),z(`已重命名为「${e}」`,`success`)),ye(null),Oe(null)}catch(e){let t=e instanceof Error?e.message:String(e);Oe(t),z(`${ve===`add`?`新增`:`保存`}失败:${t}`,`error`)}}function $e(){try{let e=T.find(e=>e.id===D)?.label??`该类型`,t=Se(D);E(t),O(t[0]?.id??``),ye(null),Oe(null),z(`已删除用例类型「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);Oe(t),z(`删除失败:${t}`,`error`)}}(0,K.useEffect)(()=>{let e=()=>{Ae(m(`prompts`)),Me(m(`knowledgeLib`)),Fe(m(`requirements`)),Be(m(`templates`)),He(m(`reqAnalysis`))},t=h(()=>e());return s().then(e),t},[]),(0,K.useEffect)(()=>{if(!e)return;Ze(n?.caseType);let t=n?.reqSource,i=t?.kind===`stories`;g(i?`stories`:`doc`),f(t?.kind===`doc`?t.path:n?.reqPath??``),S(i?t.docId:``),w(i?t.storyIds:[]),O(n?.caseType??Ce()[0]?.id??`functional`),ne(n?.templateId??``),M(``),ie(!1),ce(!1),P(n?.promptBody??``),fe(n?.knowledgePaths??[]),pe(n?.testPointIds??[]),he(n?.outputFormat??`xlsx`),ye(null),Oe(null),L(null),r?.docId&&(g(`stories`),S(r.docId),w(r.storyIds)),(async()=>{let e=await ze(`templates`),t=await ze(`prompts`),n=await ze(`requirements`),i=await ze(`knowledge`);o(e&&t);let a=[];if(m(`reqAnalysis`)&&await rt())try{a=await tt(),a.sort((e,t)=>String(t.updatedAt).localeCompare(String(e.updatedAt))),b(!0),v(a)}catch{b(!1)}else b(!1);if(r?.docId){let e=a.find(e=>e.id===r.docId);e&&(S(e.id),w(r.storyIds.length?r.storyIds:e.stories.map(e=>e.id)))}async function s(e,t,n){let{entries:r}=await Ie(e,t);for(let t of r)t.type===`file`?n.push(t):await s(e,t.path,n)}if(!Pe||!n)l([]),f(``);else try{let e=[];await s(`requirements`,`.`,e),l(e),f(t=>t&&e.some(e=>e.path===t)?t:``)}catch{}if(!je||!i)ue([]),fe([]);else try{let e=[];await s(`knowledge`,`.`,e),e.sort((e,t)=>(t.mtime??0)-(e.mtime??0)),ue(e),fe(t=>t.filter(t=>e.some(e=>e.path===t)))}catch{}ke?(await Ye(),ie(!0)):(A([]),M(``),P(``),ie(!0))})()},[e,n,ke,je,Pe,r,Ye]),(0,K.useEffect)(()=>{if(!e||!a)return;if(!Le){ee([]),ne(``);return}let t=!1;return Il(D,T).then(e=>{t||(ee(e),ne(t=>t&&e.some(e=>e.id===t)?t:n?.templateId&&e.some(e=>e.id===n.templateId)?n.templateId:e[0]?.id??``))}),()=>{t=!0}},[e,a,Le,D,T,n?.templateId]),(0,K.useEffect)(()=>{ae?Re(`prompts`,ae).then(e=>{let t=e.content??``;P(t),t.trim()||z(`「提示词管理/${ae}」是空的,生成前请先补上提示词内容。`,`error`)}).catch(e=>{P(``);let t=e instanceof Error?e.message:String(e);z(`没有读到「提示词管理/${ae}」:${t}`,`error`)}):P(``)},[ae]);let at=c.map(e=>({value:e.path,label:e.path})),ot=k.map(e=>({value:e.id,label:e.title})),st=re.map(e=>e.path),ct=F.map(e=>({value:e.path,label:e.path.replace(/\.[^.]+$/,``)})),lt=(0,K.useMemo)(()=>_.find(e=>e.id===x)??null,[_,x]),ut=lt?.stories??[],dt=C.filter(e=>ut.some(t=>t.id===e)).length,V=lt?.testPoints?.points??[],ft=I.filter(e=>V.some(t=>t.id===e)),pt=V.map(e=>({value:e.id,label:`${e.id} · ${Gr[e.dimension].label} ${e.priority} · ${e.title}`})),ht=Ve?p===`doc`?`切到「用户故事」来源后可选`:lt?V.length?`选择要覆盖的测试点…`:`这份分析还没有测试点`:`先选择一份需求分析记录`:`需求分析插件未启用`,yt=p===`doc`?`测试点来自「需求分析」拆好的结果:切到「用户故事」来源就能选。`:lt?V.length?`选中的测试点连同前置 / 步骤 / 预期一起拼进提示词;不选则按需求本身生成。`:`先去需求分析的「测试点」Tab 生成,再回来按测试点写用例。`:`选好需求分析记录后,这里会列出它的测试点。`;async function bt(){_e(!0),L(null);try{if(!ke){L(`请先在「我的插件」中启用「提示词管理」`);return}if(!qe||!le.trim()){let e=qe?`「提示词管理/${qe}」还是空的,先补上内容再生成`:`请先为「${Ge}」挂载生成提示词(点提示词框选择或新建)`;L(e),z(e,`error`);return}let e=k.find(e=>e.id===te)??k[0],r=(lt?.stories??[]).map(e=>e.id),a=r.filter(e=>C.includes(e)),o=p===`stories`?x?{kind:`stories`,docId:x,storyIds:a}:void 0:d?{kind:`doc`,path:d}:void 0,s=``,c=``,l;if(o?.kind===`doc`){s=o.path.split(`/`).pop()?.replace(/\.[^.]+$/,``)??``;try{let e=await Ll(o.path),t=/大模块/.test(e)&&/小模块/.test(e)?`Ideal 需求表:按「需求条目 → 条目内测试点」顺序编写;「模块」填大模块原文,「子模块」填小模块名(层级路径只取最后一段,不要自造更细的名字)。
214
+ `:`按文档条目 / 章节自上而下的顺序编写用例,不要重排。
215
+ `;c=`### 需求文档:${o.path}\n${t}${e}`}catch(e){L(e instanceof Error?e.message:String(e));return}}else if(o?.kind===`stories`){if(!y){L(Ve?`需求分析服务未就绪,暂时读不到用户故事;可切回「需求文档」`:`需求分析插件未启用,读不到用户故事;可切回「需求文档」`);return}if(!lt){L(`所选需求分析记录已不存在,请重新选择`);return}if(!dt){L(`请至少勾选一条用户故事,或点「全选」`);return}s=lt.title;let e=lt.outline??[];if(e.length&&(l=[...it(e).entries()].sort((e,t)=>e[1]-t[1]).map(([e])=>e)),c=`### 用户故事:${lt.title}\n按下列用户故事逐条覆盖;用例顺序以「需求条目(RO)→ 条目内测试点(TP)」为准,模块字段取来源需求的章节 / Ideal 小模块原文(优先于 US 编号)。\n${nt(lt,a)}`,lt.sourcePath)try{let e=await Ll(lt.sourcePath),t=et(e);t&&(c=`${t}\n\n${c}`)}catch{}}let u=[];for(let e of de)try{let t=await Re(`knowledge`,e);u.push(`\n### 知识库:${e}\n${t.content}`)}catch{u.push(`\n### 知识库:${e}\n(无法读取)`)}let f=V.filter(e=>ft.includes(e.id)),m=f.length?Kr(f,r):[];i({active:!0,caseType:D,outputFormat:me,reqPath:o?.kind===`doc`?o.path:void 0,reqSource:o,docTitle:s||void 0,reqBlock:[c,...u].filter(Boolean).join(`
216
+
217
+ `)||void 0,templateId:e?.id,templateTitle:e?.title,promptPath:ae,knowledgePaths:de.length?[...de]:void 0,testPointIds:m.length?m.map(e=>e.id):void 0,outlineOrder:l,testPointBlock:m.length?Wr(m,r):void 0,templateHeaders:e?.headers?.length?e.headers:[...Ne],templateBody:(e?.body||``).trim(),promptBody:le.trim(),confirmedAt:Date.now(),linkedCasePath:n?.linkedCasePath}),t()}finally{_e(!1)}}return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(xe,{open:e,onClose:t,title:`生成测试用例 · 配置`,closeAriaLabel:`关闭生成测试用例面板`,widthClass:`max-w-3xl`,escDisabled:ve!==null,footer:(0,Q.jsxs)(`footer`,{className:`shrink-0 border-t border-stone-100 px-4 py-3 flex items-center gap-2`,children:[(0,Q.jsx)(`p`,{className:`flex-1 min-w-0 truncate text-[11px] text-stone-400`,children:`配置仅对当前会话生效,可在输入区胶囊里再改`}),(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Q.jsx)(`button`,{type:`button`,disabled:R||!a||!ke||!qe,onClick:()=>void bt(),className:`h-9 px-5 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[a?null:(0,Q.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写文档库。`}),ge?(0,Q.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:ge}):null,(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-1 lg:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`order-1 min-w-0`,children:[(0,Q.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`用例类型`}),(0,Q.jsx)(N,{options:T.map(e=>({value:e.id,label:e.label})),value:D,onChange:O,dimWhenOpen:!0})]}),(0,Q.jsxs)(`div`,{className:`order-3 min-w-0 lg:order-2`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:[`用例模板`,(0,Q.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[`(`,Ge,` · `,We.templateFolder,`)`]})]}),(0,Q.jsx)(vt,{options:ot,value:Ue?.id??``,onChange:ne,allowEmpty:!1,disabled:!Le,placeholder:Le?ot.length?`搜索并选择模板…`:`暂无「${We.templateFolder}」模板`:`测试模板库未启用`})]}),(0,Q.jsxs)(`div`,{className:`order-2 flex min-w-0 items-start justify-end gap-1 pt-1.5 lg:order-3`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{Oe(null),ye(`add`)},children:`新增`}),(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{Oe(null),ye(`edit`)},children:`编辑`}),(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:T.length<=1,onClick:()=>{Oe(null),ye(`delete`)},children:`删除`})]}),(0,Q.jsx)(`div`,{className:`order-4 min-w-0 lg:order-4`,children:Le?Ue?.headers?.length?(0,Q.jsx)(gt,{fields:Ue.headers}):null:(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「测试模板库」后再选择;未启用时按默认字段生成。`})})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-4 lg:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`输出格式`}),(0,Q.jsx)(N,{options:Fl,value:me,onChange:he,dimWhenOpen:!0})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`引用知识库(可多选)`}),(0,Q.jsx)(_t,{options:ct,values:de,onChange:fe,disabled:!je,placeholder:je?ct.length?`选择知识库文档…`:`暂无知识库文档`:`知识库管理未启用`}),je?null:(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「知识库管理」后再引用。`})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-stone-500`,children:`需求来源`}),(0,Q.jsxs)(`div`,{className:`inline-flex rounded-lg border border-stone-200 bg-stone-50 p-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>g(`doc`),className:`h-7 rounded-md px-2.5 text-xs transition-colors ${p===`doc`?`bg-white text-stone-900 shadow-sm`:`text-stone-500 hover:text-stone-700`}`,children:`需求文档`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!y,onClick:()=>{y&&g(`stories`)},className:`h-7 rounded-md px-2.5 text-xs transition-colors disabled:opacity-40 ${p===`stories`?`bg-white text-stone-900 shadow-sm`:`text-stone-500 hover:text-stone-700`}`,children:`用户故事`})]}),(0,Q.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:p===`stories`?`来自「需求分析」拆好的故事:按 US 编号逐条覆盖,改动后重新生成即可`:`来自「需求文档库」的原始文档`})]}),(0,Q.jsx)(`div`,{className:`mt-2`,children:p===`stories`?(0,Q.jsx)(vt,{options:_.map(e=>({value:e.id,label:`${e.title}(${e.stories.length} 个故事)`})),value:x,onChange:e=>{S(e);let t=_.find(t=>t.id===e);w(t?.stories.map(e=>e.id)??[]),pe([])},allowEmpty:!1,disabled:!y,placeholder:Ve?y?_.length?`搜索并选择需求分析记录…`:`暂无需求分析记录,请先在「需求分析」拆解`:`需求分析服务未就绪`:`需求分析插件未启用`}):(0,Q.jsx)(vt,{options:at,value:d,onChange:f,allowEmpty:!1,disabled:!Pe,placeholder:Pe?at.length?`搜索并选择需求文档…`:`请先在需求文档库中上传`:`需求文档库未启用`})}),p===`stories`?(0,Q.jsxs)(`div`,{className:`mt-2 rounded-lg bg-stone-50/80 p-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 text-[11px] text-stone-500`,children:[`选择故事`,(0,Q.jsxs)(`span`,{className:`ml-1 text-stone-400`,children:[dt,`/`,ut.length]})]}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-[#4176e6] hover:underline`,onClick:()=>w(ut.map(e=>e.id)),children:`全选`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-500 hover:underline`,onClick:()=>w([]),children:`全不选`})]}),ut.length?(0,Q.jsx)(`div`,{className:`mt-1.5 grid max-h-56 grid-cols-1 gap-x-4 overflow-y-auto sm:grid-cols-2`,children:ut.map(e=>(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-1.5 py-1 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:C.includes(e.id),onChange:t=>w(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-stone-400`,children:e.id}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(oe,{text:e.title,className:`block truncate text-stone-800`})}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:e.priority})]},e.id))}):(0,Q.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400`,children:x?`这份分析还没有拆出用户故事`:`先选择一份需求分析记录`}),Ve?null:(0,Q.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400`,children:`需求分析插件已关闭;用户故事来源暂不可用,可改用「需求文档」。`})]}):Pe?null:(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「需求文档库」后再选择。`})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 text-xs font-medium text-stone-500`,children:[`测试点(可多选)`,V.length?(0,Q.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[ft.length,`/`,V.length]}):null]}),V.length?(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 text-[11px]`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`text-[#4176e6] transition-colors hover:text-[#3565c7]`,onClick:()=>pe(V.map(e=>e.id)),children:`全选`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-stone-500 transition-colors hover:text-stone-700`,onClick:()=>pe([]),children:`清空`})]}):null]}),(0,Q.jsx)(_t,{options:pt,values:ft,onChange:pe,disabled:!pt.length,placeholder:ht}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:yt})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:[`提示词`,(0,Q.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[`(`,Ge,` 挂载)`]})]}),(0,Q.jsx)(`button`,{type:`button`,disabled:!ke,onClick:()=>ce(!0),className:`flex h-9 w-full min-w-0 items-center gap-2 rounded-lg border px-2.5 text-left text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${Je?`border-amber-300 bg-amber-50/50 text-amber-700 hover:border-amber-400`:`border-stone-200 bg-white text-stone-800 hover:border-stone-300`}`,children:(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:ke?qe?qe.replace(/\.md$/i,``):j?`未挂载提示词 · 点击挂载`:`读取提示词…`:`提示词管理未启用`})}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:ke?Je?j?`当前类型还没有挂载提示词,未挂载时无法确认。`:`正在读取提示词列表…`:`每个用例类型只挂一份提示词:换类型会切到该类型挂载的那份。`:`请先在「我的插件」中启用「提示词管理」后再挂载。`})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-stone-50/60 px-4 py-3`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-semibold text-stone-600`,children:`本次配置`}),(0,Q.jsxs)(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-4 gap-y-2 sm:grid-cols-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`用例类型`}),(0,Q.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Ge})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`用例模板`}),(0,Q.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Ue?.title||`—`})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`输出格式`}),(0,Q.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Fl.find(e=>e.value===me)?.label??me})]}),(0,Q.jsxs)(`div`,{className:`col-span-2 min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`需求来源`}),(0,Q.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:p===`stories`?lt?`用户故事 · ${lt.title}(${dt}/${ut.length} 条)`:`用户故事 · 未选择`:d?`需求文档 · ${d}`:`需求文档 · 未选择`})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`引用知识库`}),(0,Q.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:de.length?`${de.length} 个文档`:`未引用`})]}),(0,Q.jsxs)(`div`,{className:`col-span-2 grid min-w-0 grid-cols-2 gap-x-4 sm:col-span-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`测试点`}),(0,Q.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:ft.length?`${ft.length} 条`:`未选择`})]}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`提示词`}),(0,Q.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:qe?`${qe.replace(/\.md$/i,``)}(${Ge})`:`未挂载`})]})]})]}),(0,Q.jsx)(`p`,{className:`mt-2.5 text-[10px] leading-4 text-stone-400`,children:`确认后输入区出现「生成测试用例」胶囊,直接发送或补充范围说明即可;点 × 取消后按普通对话修改,不再整批生成。`})]})]}),(0,Q.jsx)(Pl,{mode:ve,currentLabel:We.label,templateFolder:We.templateFolder,error:be??``,onClose:()=>{ye(null),Oe(null)},onSubmit:Qe,onDelete:$e}),(0,Q.jsx)(on,{open:se,prompts:st,value:qe,force:!qe,onClose:()=>ce(!1),onMount:B,onCreate:Xe,target:`用例类型`,createHint:`会按用例生成的模板生成一份(逐条覆盖、边界 / 异常 / 优先级),之后可在「提示词管理」里改。`})]})}function zl({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(``),[c,l]=(0,K.useState)(()=>Bi()),[u,d]=(0,K.useState)(Bi()[0]?.id??`case`),[f,p]=(0,K.useState)(null),[m,h]=(0,K.useState)(null),[g,_]=(0,K.useState)(null),v=c.find(e=>e.id===u)??c[0]??Vi(u);function y(e){let t=Bi();l(t),d(n=>{let r=e??n;return t.some(e=>e.id===r)?r:t[0]?.id??n})}function b(e){let t=m===`add`;try{if(t){let t=Ui(e);y(t.id),z(`已新增提示词类型「${t.label}」`,`success`)}else Wi(u,e),y(u),z(`已重命名为「${e.trim()}」`,`success`);h(null),_(null)}catch(e){let n=e instanceof Error?e.message:String(e);_(n),z(`${t?`新增`:`保存`}提示词类型失败:${n}`,`error`)}}function x(){try{let e=v.label,t=Gi(u);l(t),d(t[0]?.id??``),h(null),_(null),p(null),z(`已删除提示词类型「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);_(t),z(`删除提示词类型失败:${t}`,`error`)}}(0,K.useEffect)(()=>{e&&(y(n?.kind),s(n?.titleHint??``),d(n?.kind??Bi()[0]?.id??`case`),h(null),_(null),p(null),ze(`prompts`).then(a))},[e,n]);function S(){p(null),i?(r({active:!0,titleHint:o.trim(),kind:u,confirmedAt:Date.now(),linkedPromptPath:n?.linkedPromptPath}),t()):p(`本地文档服务未就绪,无法写入提示词库`)}return(0,Q.jsxs)(xe,{open:e,onClose:t,title:`生成提示词 · 配置`,closeAriaLabel:`关闭生成提示词面板`,escDisabled:m!==null,footer:(0,Q.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!i,onClick:S,className:`flex-1 h-9 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[i?null:(0,Q.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写提示词库。`}),(0,Q.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选类型生成可复用提示词:确认后输入区出现「生成提示词」胶囊,描述编写要求后发送;点 × 取消后按普通对话修改,不再整批生成。质检通过后写入提示词库。`}),f?(0,Q.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:f}):null,(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 text-xs font-medium text-stone-500`,children:`提示词类型`}),(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{h(`add`),_(null)},children:`新增`}),(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{h(`edit`),_(null)},children:`编辑`}),(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:c.length<=1,onClick:()=>{h(`delete`),_(null)},children:`删除`})]}),(0,Q.jsx)(N,{options:c.map(e=>({value:e.id,label:e.label})),value:u,onChange:d,dimWhenOpen:!0}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:v.hint}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:`类型决定生成时给模型的写作侧重(例如用例提示词要求约束 JSON 与模板字段), 同时出现在这份提示词的配置标签里;不影响你在主输入框补充的具体要求。`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,htmlFor:`pg-title`,children:`期望名称`}),(0,Q.jsx)(`input`,{id:`pg-title`,value:o,onChange:e=>s(e.target.value),placeholder:`如:接口测试用例提示词.md`,className:`mt-1 w-full h-9 px-3 text-sm rounded-lg border border-stone-200 focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-4`,children:`可填期望文件名;留空则由模型自拟。具体编写要求在主输入框描述。`})]}),(0,Q.jsx)(Nl,{mode:m,entityLabel:`提示词类型`,currentLabel:v.label,placeholder:`如:缺陷分析提示词`,error:g??``,onClose:()=>{h(null),_(null)},onSubmit:b,onDelete:x,hint:e=>(0,Q.jsxs)(Q.Fragment,{children:[`类型名称会写入这份提示词的配置标签:`,e||`名称`]}),deleteMessage:e=>(0,Q.jsxs)(Q.Fragment,{children:[`确定删除「`,e,`」?已生成的提示词与文档不会被删除,只是不能再选这个类型。`]})})]})}function Bl({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(``),[c,l]=(0,K.useState)(()=>ta()),[u,d]=(0,K.useState)(ta()[0]??`测试规范`),[f,p]=(0,K.useState)(null),[m,h]=(0,K.useState)(null),[g,_]=(0,K.useState)(null);function v(e){let t=ta();l(t),d(n=>{let r=e??n;return t.includes(r)?r:t[0]??n})}function y(e){let t=m===`add`;try{if(t){let t=ra(e);v(t),z(`已新增分类「${t}」`,`success`)}else{let t=ia(u,e);v(t),z(`已重命名为「${t}」`,`success`)}h(null),_(null)}catch(e){let n=e instanceof Error?e.message:String(e);_(n),z(`${t?`新增`:`保存`}分类失败:${n}`,`error`)}}function b(){try{let e=u,t=aa(u);l(t),d(t[0]??``),h(null),_(null),p(null),z(`已删除分类「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);_(t),z(`删除分类失败:${t}`,`error`)}}(0,K.useEffect)(()=>{e&&(v(n?.category),s(n?.titleHint??``),d(n?.category??ta()[0]??`测试规范`),h(null),_(null),p(null),ze(`knowledge`).then(a))},[e,n]);function x(){p(null),i?(r({active:!0,titleHint:o.trim(),category:u,confirmedAt:Date.now(),linkedKnowledgePath:n?.linkedKnowledgePath}),t()):p(`本地文档服务未就绪,无法写入知识库`)}return(0,Q.jsxs)(xe,{open:e,onClose:t,title:`生成知识库 · 配置`,closeAriaLabel:`关闭生成知识库面板`,escDisabled:m!==null,footer:(0,Q.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!i,onClick:x,className:`flex-1 h-9 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[i?null:(0,Q.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写知识库。`}),(0,Q.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选分类沉淀测试规范、方法论或环境约定:确认后输入区出现「生成知识库」胶囊,粘贴或描述素材后发送;点 × 取消后按普通对话修改,不再整批生成。质检通过后写入知识库,可在「知识库管理」中查看与 @ 引用。`}),f?(0,Q.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:f}):null,(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 text-xs font-medium text-stone-500`,children:`分类`}),(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{h(`add`),_(null)},children:`新增`}),(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{h(`edit`),_(null)},children:`编辑`}),(0,Q.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:c.length<=1,onClick:()=>{h(`delete`),_(null)},children:`删除`})]}),(0,Q.jsx)(N,{options:c.map(e=>({value:e,label:e})),value:u,onChange:d,dimWhenOpen:!0}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:`分类决定两件事:生成时告诉模型按哪类知识写(规范 / 方法论 / 环境约定侧重不同), 入库时写进文档 frontmatter 的 category,知识库管理里就按它归类展示。`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,htmlFor:`kg-title`,children:`期望名称`}),(0,Q.jsx)(`input`,{id:`kg-title`,value:o,onChange:e=>s(e.target.value),placeholder:`如:接口自动化环境约定.md`,className:`mt-1 w-full h-9 px-3 text-sm rounded-lg border border-stone-200 focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-4`,children:`可填期望文件名;留空则由模型自拟。素材与编写要求在主输入框描述。`})]}),(0,Q.jsx)(Nl,{mode:m,entityLabel:`知识库分类`,currentLabel:u,placeholder:`如:安全基线`,error:g??``,onClose:()=>{h(null),_(null)},onSubmit:y,onDelete:b,hint:()=>(0,Q.jsx)(Q.Fragment,{children:`分类写入文档 frontmatter,文件平铺存放于 知识库管理/;改名不会自动迁移已有文件。`}),deleteMessage:e=>(0,Q.jsxs)(Q.Fragment,{children:[`确定删除「`,e,`」?已入库的知识文档不会被删除,但该分类将不能再用于生成。`]})})]})}function Vl({task:e,onClose:t,onSave:n,onRemove:r,readOnly:i=!1}){let[a,o]=(0,K.useState)(``),s=!!e;(0,K.useEffect)(()=>{o(e?.body??``)},[e]);let c=!!e&&a.trim()!==e?.body.trim();return(0,Q.jsxs)(ee,{open:s,onClose:t,className:`relative z-110`,children:[(0,Q.jsx)(te,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,Q.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,Q.jsxs)(O,{transition:!0,className:`tw-dialog-panel-anim relative flex max-h-[85vh] w-full max-w-2xl flex-col rounded-xl border border-stone-200 bg-white p-5 shadow-xl`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`absolute top-3.5 right-3.5 flex h-7 w-7 items-center justify-center rounded-md text-stone-400 transition-colors hover:bg-stone-100 hover:text-stone-700`,"aria-label":`关闭`,children:`✕`}),(0,Q.jsx)(k,{className:`pr-8 text-base font-semibold text-stone-900`,children:e?.label||`任务要求`}),(0,Q.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-stone-400`,children:[(0,Q.jsx)(`span`,{children:i?`已随消息发送给模型`:`发送时这段要求会随消息一起带给模型`}),e?.detail?(0,Q.jsxs)(`span`,{className:`truncate`,children:[`· `,e.detail]}):null]}),(0,Q.jsx)(`textarea`,{value:a,onChange:e=>{i||o(e.target.value)},readOnly:i,spellCheck:!1,className:`mt-3 min-h-[240px] flex-1 resize-none overflow-y-auto rounded-lg border border-stone-200 px-3 py-2.5 font-mono text-[12.5px] leading-relaxed text-stone-700 outline-none ${i?`bg-stone-50/80`:`bg-stone-50/60 focus:border-[#4176e6]/40 focus:bg-white`}`}),(0,Q.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-2`,children:[i||!r?(0,Q.jsx)(`span`,{}):(0,Q.jsx)(`button`,{type:`button`,onClick:r,className:`h-8 rounded-lg border border-stone-200 px-3 text-sm text-stone-500 transition-colors hover:border-red-300 hover:bg-red-50 hover:text-red-600`,children:`移除`}),(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:i||!n?(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`h-8 rounded-lg bg-[#4176e6] px-3.5 text-sm text-white transition-colors hover:bg-[#3566d0]`,children:`关闭`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`h-8 rounded-lg border border-stone-200 px-3 text-sm text-stone-600 transition-colors hover:bg-stone-100`,children:`取消`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!a.trim(),onClick:()=>n(a.trim()),className:`h-8 rounded-lg bg-[#4176e6] px-3.5 text-sm text-white transition-colors hover:bg-[#3566d0] disabled:cursor-not-allowed disabled:bg-stone-300`,children:c?`保存修改`:`完成`})]})})]})]})})]})}var Hl={user:`用户档案`,memory:`长期记忆`,key:`项目关键记忆`,project:`项目日志`};function Ul(e){return e?e.replace(/\\/g,`/`).replace(/^\/Users\/[^/]+/,`~`):``}var Wl={project:{title:`项目日志`,fileHint:`MEMORY.md`,desc:`项目进展流水账,按需查阅,默认不注入上下文。`,curated:!1},key:{title:`项目关键记忆`,fileHint:`KEY.md`,desc:`项目关键约定与事实;写入需经待确认记忆建议采纳后注入。`,curated:!0},memory:{title:`长期记忆`,fileHint:`MEMORY.md`,desc:`全局环境与跨项目事实,注入所有会话;写入需审查建议并经确认。`,curated:!0}},Gl=[{id:`guide`,label:`指南`},{id:`suggestions`,label:`待确认记忆建议`},{id:`project`,label:`项目日志`},{id:`key`,label:`项目关键记忆 KEY.md`},{id:`memory`,label:`长期记忆 MEMORY.md`},{id:`agents`,label:`全局规则 AGENTS.md`},{id:`archive`,label:`归档`},{id:`settings`,label:`设置`}];function Kl({live:e,pluginOn:t,workspacePath:n=``,onHealthChange:r}){let[i,a]=(0,K.useState)(`suggestions`),[o,s]=(0,K.useState)(null),[c,l]=(0,K.useState)({}),[u,d]=(0,K.useState)(``),[f,p]=(0,K.useState)([]),[m,h]=(0,K.useState)([]),[g,_]=(0,K.useState)(`memory`),[v,y]=(0,K.useState)(null),[b,x]=(0,K.useState)([]),[S,C]=(0,K.useState)(null),[w,T]=(0,K.useState)(``),[E,D]=(0,K.useState)(!1),[O,k]=(0,K.useState)(null),[ee,te]=(0,K.useState)(null),[ne,re]=(0,K.useState)(null),A=n.trim(),j=(0,K.useRef)(r);j.current=r;let ie=(0,K.useCallback)(async()=>{if(!e)s(null),l({}),p([]),x([]),j.current?.(null);else{C(null);try{let[e,t,n,r,a]=await Promise.all([Cr(),Sr(A,`all`),vr(),Er(),yn().catch(()=>null)]);s(e),l(t.tracks),d(t.projectId||``),p(n),y(r),x(a?.files?.length?a.files:a?.text?[{path:`AGENTS.md`,name:`AGENTS.md`}]:[]),i===`archive`&&h(await kr(g,A)),j.current?.(e)}catch(e){C(e instanceof Error?e.message:String(e))}}},[e,A,i,g]);if((0,K.useEffect)(()=>{ie()},[ie]),!t)return(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆未启用`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`在「我的插件」中打开「会话记忆」后,可在此管理记忆轨与待确认记忆建议`})]});if(!e)return(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆中间件未就绪`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`本地记忆服务未就绪`})]});let M=i===`memory`||i===`key`,oe=i===`memory`||i===`key`||i===`project`,N=oe?c[i]?.entries??[]:[],se=oe?c[i]?.path:null,ce=o?.path||`.lantern/local/memories`;async function le(e){D(!0);try{await xr(e),await ie()}catch(e){C(e instanceof Error?e.message:String(e))}finally{D(!1)}}async function P(e){D(!0);try{await _r(e),await ie()}catch(e){C(e instanceof Error?e.message:String(e))}finally{D(!1)}}function F(e){M&&te(e)}async function ue(){if(ee==null||!M)return;let e=ee;te(null),D(!0);try{await Tr(i,e,A),await ie()}catch(e){C(e instanceof Error?e.message:String(e))}finally{D(!1)}}async function de(){if(ne==null)return;let e=ne;re(null),D(!0);try{await Nr(g,e,A),await ie()}catch(e){C(e instanceof Error?e.message:String(e))}finally{D(!1)}}function fe(e){k(e)}async function I(){if(O==null)return;let e=O;k(null),D(!0);try{await G(i,e,A),await ie()}catch(e){C(e instanceof Error?e.message:String(e))}finally{D(!1)}}async function pe(){if(M&&w.trim()){D(!0);try{await Pr(i,w.trim(),A),T(``),await ie()}catch(e){C(e instanceof Error?e.message:String(e))}finally{D(!1)}}}async function me(e){D(!0);try{let t=await Fr(e);y(t)}catch(e){C(e instanceof Error?e.message:String(e))}finally{D(!1)}}function he(e){let t=Wl[e],n=e===`key`?`KEY.md`:t.fileHint,r=e===`key`?`项目关键记忆 ${n}`:e===`memory`?`长期记忆 ${n}`:t.title,i=Ul(se)||`${Ul(ce)}/…/${n}`;return(0,Q.jsxs)(`div`,{className:`mb-3 space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 flex-wrap min-w-0`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:r}),t.curated?null:(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-stone-100 text-stone-500 border border-stone-200`,children:`只读追加`}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[N.length,` 条`]}),(0,Q.jsx)(`span`,{className:`max-w-full break-all whitespace-normal text-[11px] text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/20 rounded-lg px-2 py-0.5 font-mono leading-4`,"data-hint":se||i,children:i})]}),(0,Q.jsx)(`p`,{className:`text-xs text-stone-500 leading-5 break-words`,children:t.desc}),A?(0,Q.jsxs)(`p`,{className:`text-[11px] text-stone-400 break-all`,children:[`当前会话工作目录:`,(0,Q.jsx)(`span`,{className:`font-mono`,children:A}),u?(0,Q.jsxs)(Q.Fragment,{children:[` · `,`项目 id `,(0,Q.jsx)(`span`,{className:`font-mono`,children:u.slice(0,12)})]}):null]}):null]})}return(0,Q.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Q.jsxs)(`div`,{className:`shrink-0 flex flex-wrap items-center gap-2 px-4 py-2 border-b border-stone-200/80`,children:[Gl.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:`h-7 px-2.5 text-xs rounded-md whitespace-normal text-left leading-tight ${i===e.id?`bg-stone-900 text-white`:`text-stone-600 hover:bg-stone-100`}`,children:[e.label,e.id===`suggestions`&&f.length>0?(0,Q.jsxs)(`span`,{className:`ml-1 tabular-nums`,children:[`(`,f.length,`)`]}):null]},e.id)),(0,Q.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[o?.entryCount??0,` 条 · 待确认 `,o?.suggestionCount??f.length]})]}),S?(0,Q.jsx)(`div`,{className:`mx-4 mt-3 px-3 py-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg`,children:S}):null,(0,Q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:[i===`guide`?(0,Q.jsxs)(`div`,{className:`space-y-3 max-w-2xl`,children:[(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`确认制:为什么必须你点头`}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`记忆会改变后续对话行为。长期记忆 / 项目关键记忆经「待确认记忆建议」采纳后才写入并注入;项目日志可直写但不注入。`})]}),(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议:AI 只提议,你拍板`}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`后台或对话中产出的记忆建议进入独立队列。采纳可写入对应轨;拒绝则丢弃。`}),(0,Q.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2 break-words`,children:`采纳 → 长期记忆 MEMORY.md / 项目关键记忆 KEY.md`}),(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`拒绝 → 丢弃,不落盘`})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`各轨文件(对齐 dsh)`}),(0,Q.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目日志 · 项目目录 MEMORY.md(不注入)`}),(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目关键记忆 KEY.md(注入,需确认)`}),(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`长期记忆 MEMORY.md(注入,需确认)`}),(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`全局规则:展示工作区 AGENTS.md 等规则文件`})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`编辑与维护`}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`可在本 Tab 浏览条目、手动添加(注入轨)、归档或删除。文件为 § 分隔结构化记忆,用外部编辑器打开时请谨慎修改。`}),(0,Q.jsxs)(`p`,{className:`mt-2 text-[11px] text-amber-700/90`,children:[`存储目录:`,(0,Q.jsx)(`code`,{className:`font-mono`,children:ce})]})]})]}):null,i===`suggestions`?(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-stone-500 leading-5`,children:`后台审查或对话沉淀产出的记忆建议:采纳后写入记忆文件并注入;拒绝则丢弃。`})]}),f.length===0?(0,Q.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-16 text-center text-sm text-stone-400`,children:`没有待确认的建议。`}):(0,Q.jsx)(`ul`,{className:`space-y-3`,children:f.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-lg border border-amber-200/80 bg-amber-50/30 p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-stone-400 mb-1 flex-wrap`,children:[(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-amber-100 text-amber-900 border border-amber-200 font-medium`,children:`待确认记忆建议`}),(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-white text-stone-600 border border-stone-200`,children:Hl[e.target]??e.target}),(0,Q.jsx)(`span`,{children:e.time}),e.hits&&e.hits>1?(0,Q.jsxs)(`span`,{children:[`×`,e.hits]}):null]}),(0,Q.jsx)(`p`,{className:`text-sm text-stone-800 whitespace-pre-wrap`,children:e.content}),e.reason?(0,Q.jsxs)(`p`,{className:`mt-1 text-xs text-stone-500`,children:[`原因:`,e.reason]}):null,(0,Q.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:E,onClick:()=>void le(e.id),className:`h-7 px-2.5 text-xs text-white bg-emerald-600 rounded-md hover:bg-emerald-700 disabled:opacity-40`,children:`采纳`}),(0,Q.jsx)(`button`,{type:`button`,disabled:E,onClick:()=>void P(e.id),className:`h-7 px-2.5 text-xs text-stone-600 border border-stone-200 rounded-md hover:bg-stone-50 disabled:opacity-40`,children:`拒绝`})]})]},e.id))})]}):null,oe?(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[he(i),M?(0,Q.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white p-3 space-y-2`,children:[(0,Q.jsx)(`textarea`,{value:w,onChange:e=>T(e.target.value),placeholder:i===`key`?`输入一条项目关键约定,例如:本仓库包管理器用 pnpm…`:`输入一条想长期记住的全局事实/惯例/环境…`,rows:3,className:`w-full text-sm rounded-lg border border-stone-200 px-3 py-2 focus:outline-none focus:border-[#4176e6] resize-y`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:`手动写入会直接落盘;重要偏好更推荐走「待确认记忆建议」。`}),(0,Q.jsx)(`button`,{type:`button`,disabled:E||!w.trim(),onClick:()=>void pe(),className:`shrink-0 h-8 px-3 text-xs text-white bg-[#4176e6] rounded-lg disabled:opacity-40`,children:`保存`})]})]}):(0,Q.jsx)(`p`,{className:`text-xs text-stone-400`,children:`本轨由对话中 memory_append 自动追加,一般不注入上下文。`}),N.length===0?(0,Q.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-12 text-center text-sm text-stone-400`,children:`(文件不存在或为空)`}):(0,Q.jsx)(`ul`,{className:`space-y-2`,children:N.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Q.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Q.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[M?(0,Q.jsx)(`button`,{type:`button`,disabled:E,onClick:()=>void F(e.index),className:`h-7 px-2 text-[11px] text-stone-500 hover:bg-stone-50 rounded-md`,children:`归档`}):null,(0,Q.jsx)(`button`,{type:`button`,disabled:E,onClick:()=>void fe(e.index),className:`h-7 px-2 text-[11px] text-red-600 hover:bg-red-50 rounded-md`,children:`删除`})]})]},`${i}-${e.index}`))})]}):null,i===`agents`?(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`全局规则`}),(0,Q.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`工作区规则文件(AGENTS.md 等),随系统提示注入。`}),b.length===0?(0,Q.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-12 text-center text-sm text-stone-400`,children:`(未找到规则文件)`}):(0,Q.jsx)(`ul`,{className:`space-y-2 w-full`,children:b.map(e=>{let t=Ul(e.abs)||Ul(e.path)||e.label||e.path||e.name;return(0,Q.jsx)(`li`,{className:`w-full`,children:(0,Q.jsxs)(`div`,{className:`w-full flex items-center gap-4 rounded-xl border border-stone-200 bg-white px-4 py-3.5`,children:[(0,Q.jsx)(`span`,{className:`w-12 h-12 rounded-xl bg-[#edf3fe] text-[#4176e6] flex items-center justify-center text-[11px] font-semibold shrink-0`,children:(e.name.split(`.`).pop()||`MD`).toUpperCase()}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-[15px] font-medium text-stone-800 break-all`,children:e.name||`AGENTS.md`}),(0,Q.jsx)(`span`,{className:`block text-xs text-stone-400 break-all font-mono mt-1`,children:t})]}),(0,Q.jsx)(`button`,{type:`button`,disabled:E,onClick:()=>{C(null),D(!0),dn(e.path||e.name||`AGENTS.md`,Qe(),{abs:e.abs}).catch(e=>C(e instanceof Error?e.message:String(e))).finally(()=>D(!1))},className:`shrink-0 h-9 px-4 text-xs text-[#4176e6] border border-[#4176e6]/30 rounded-lg hover:bg-[#f5f8ff] disabled:opacity-40`,children:`打开文件`})]})},e.abs||e.path)})})]}):null,i===`archive`?(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(`div`,{className:`flex gap-2`,children:[`user`,`memory`,`key`].map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{_(e)},className:`h-7 px-2.5 text-xs rounded-md ${g===e?`bg-stone-800 text-white`:`border border-stone-200`}`,children:Hl[e]??e},e))}),m.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-stone-400 text-center py-10`,children:`暂无归档`}):(0,Q.jsx)(`ul`,{className:`space-y-2`,children:m.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Q.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Q.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:E,onClick:()=>void(async()=>{D(!0);try{await br(g,e.index,A),await ie()}catch(e){C(e instanceof Error?e.message:String(e))}finally{D(!1)}})(),className:`h-7 px-2 text-[11px] text-emerald-700 hover:bg-emerald-50 rounded-md`,children:`转正`}),(0,Q.jsx)(`button`,{type:`button`,disabled:E,onClick:()=>re(e.index),className:`h-7 px-2 text-[11px] text-red-600 hover:bg-red-50 rounded-md`,children:`删除`})]})]},`a-${e.index}`))})]}):null,i===`settings`&&v?(0,Q.jsxs)(`div`,{className:`space-y-4 max-w-md`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Q.jsx)(`span`,{children:`每回合注入 USER / MEMORY / KEY`}),(0,Q.jsx)(`input`,{type:`checkbox`,checked:v.injectMemory,onChange:e=>void me({injectMemory:e.target.checked})})]}),(0,Q.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Q.jsx)(`span`,{children:`收尾提示写 project`}),(0,Q.jsx)(`input`,{type:`checkbox`,checked:v.perTurnProjectWrites,onChange:e=>void me({perTurnProjectWrites:e.target.checked})})]}),(0,Q.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Q.jsx)(`span`,{children:`重要事实用 suggest(KEY)`}),(0,Q.jsx)(`input`,{type:`checkbox`,checked:v.perTurnKeyWrites,onChange:e=>void me({perTurnKeyWrites:e.target.checked})})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-stone-400 leading-5 break-all`,children:[`存储目录:`,(0,Q.jsx)(`code`,{className:`font-mono`,children:o?.path??`.lantern/local/memories`}),`。memory/key 经待确认记忆建议后注入;project 不注入。`]})]}):null]}),(0,Q.jsx)(ae,{open:O!=null,title:`删除记忆`,message:`永久删除该条目?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>k(null),onConfirm:()=>void I()}),(0,Q.jsx)(ae,{open:ee!=null,title:`归档记忆`,message:`归档该条目?归档后不再注入上下文。`,confirmLabel:`归档`,cancelLabel:`取消`,onClose:()=>te(null),onConfirm:()=>void ue()}),(0,Q.jsx)(ae,{open:ne!=null,title:`删除归档`,message:`永久删除该归档?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>re(null),onConfirm:()=>void de()})]})}var ql=`/`,Jl=[{id:`all`,label:`全部待办`},{id:`open`,label:`未完成`},{id:`done`,label:`已完成`}],Yl={urgent_important:`bg-red-500`,important:`bg-amber-500`,urgent:`bg-orange-500`,normal:`bg-stone-300`},Xl={urgent_important:`text-red-600`,important:`text-amber-600`,urgent:`text-orange-600`,normal:`text-stone-500`};function Zl(){let e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function Ql(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function $l(e,t){let n=Ql(e.dueDate),r=e.status===`done`||e.status===`cancelled`,i=jn(e,t),a=``,o=`text-stone-500`;return r?a=In[e.status]:i===null?(a=`未设置截止`,o=`text-stone-400`):i<0?(a=`逾期 ${Math.abs(i)} 天`,o=`text-red-600`):i===0?(a=`今天截止`,o=`text-[#4176e6]`):a=`剩余 ${i} 天`,{due:n,remain:a,tone:r?`text-stone-400`:o}}function eu(e){return[...e].filter(e=>e.status===`done`||e.status===`cancelled`).sort((e,t)=>e.updatedAt<t.updatedAt?1:-1).slice(0,30)}function tu(e,t,n){if(t===`done`)return[{key:`done`,label:`已完成 / 已取消`,items:eu(e)}];let r=e.filter(e=>{let t=Dn(e,n);return t!==`done`&&t!==`cancelled`}),i=[],a=[],o=[],s=[];for(let e of r){let t=jn(e,n);t===null?s.push(e):t<0?i.push(e):t===0?a.push(e):o.push(e)}let c=[{key:`overdue`,label:`已逾期`,items:i,tone:`text-red-600`},{key:`today`,label:`今天截止`,items:a,tone:`text-[#4176e6]`},{key:`later`,label:`接下来`,items:o},{key:`undated`,label:`没有截止日期`,items:s}];return t===`all`&&c.push({key:`done`,label:`已完成 / 已取消`,items:eu(e)}),c.filter(e=>e.items.length>0)}function nu(e){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)(`all`),[s,c]=(0,K.useState)({}),l=(0,K.useCallback)(async()=>{try{let e=await An();n(e),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}},[]);(0,K.useEffect)(()=>{l();let e=window.setInterval(()=>void l(),15e3);return()=>window.clearInterval(e)},[l]);let u=Zl(),d=(0,K.useMemo)(()=>t?tu(t,a,u):[],[t,a,u]),f=(0,K.useMemo)(()=>{let e=t??[],n=0,r=0,i=0;for(let t of e){let e=Dn(t,u);if(e===`done`||e===`cancelled`)continue;i+=1;let a=jn(t,u);a!==null&&a<0?n+=1:a===0&&(r+=1)}return{overdue:n,dueToday:r,open:i}},[t,u]);async function p(e){if(s[e.id])return;let t=e.status===`done`?`pending`:`done`;c(t=>({...t,[e.id]:!0})),n(n=>n&&n.map(n=>n.id===e.id?{...n,status:t}:n));try{await kn(e.id,{status:t}),i(null)}catch(t){n(t=>t&&t.map(t=>t.id===e.id?{...t,status:e.status}:t)),i(t instanceof Error?t.message:String(t))}finally{c(t=>{let n={...t};return delete n[e.id],n})}}return e.live===!1?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-stone-600`,children:`待办事项需要本地服务`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`当前未就绪(仅 npm run dev / 本地一体服务可用)`})]}):(0,Q.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Q.jsx)(`div`,{className:`shrink-0 border-b border-stone-200/80`,children:(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-[min(64rem,100%)] flex-wrap items-center gap-2 px-4 py-2 sm:px-8 lg:px-12`,children:[Jl.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),"aria-pressed":a===e.id,className:`h-7 px-2.5 text-xs rounded-md ${a===e.id?`bg-stone-900 text-white`:`text-stone-600 hover:bg-stone-100`}`,children:[e.label,e.id===`all`&&f.dueToday+f.overdue>0?(0,Q.jsx)(`span`,{className:`ml-1 tabular-nums`,children:f.dueToday+f.overdue}):null]},e.id)),(0,Q.jsxs)(`span`,{className:`ml-auto text-[11px] text-stone-400 tabular-nums`,children:[`未完成 `,f.open,f.overdue?` · 逾期 ${f.overdue}`:``]}),(0,Q.jsx)(`a`,{href:`${ql}todos/`,className:`text-[11px] text-[#4176e6] hover:underline shrink-0`,children:`打开待办页 →`})]})}),r?(0,Q.jsx)(`div`,{className:`mx-auto mt-3 w-full max-w-[min(64rem,100%)] px-4 sm:px-8 lg:px-12`,children:(0,Q.jsx)(`div`,{className:`px-3 py-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg`,children:r})}):null,(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-4 py-3 sm:px-8 lg:px-12`,children:t===null?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,Q.jsx)(`span`,{className:`tw-lib-spin`,"aria-hidden":`true`})}):d.length===0?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-stone-500`,children:a===`all`?`当前空间还没有待办`:a===`done`?`还没有已完成的待办`:`当前没有未完成的待办`}),(0,Q.jsx)(`a`,{href:`${ql}todos/`,className:`mt-2 text-xs text-[#4176e6] hover:underline`,children:`去待办页新增 →`})]}):(0,Q.jsx)(`div`,{className:`mx-auto w-full max-w-[min(64rem,100%)] space-y-5`,children:d.map(e=>(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(`h3`,{className:`mb-2 flex items-center gap-1.5 px-0.5 text-[11px] font-medium ${e.tone??`text-stone-500`}`,children:[e.label,(0,Q.jsx)(`span`,{className:`text-stone-400 tabular-nums`,children:e.items.length})]}),(0,Q.jsx)(`ul`,{className:`list-none m-0 space-y-1.5 p-0`,children:e.items.map(e=>{let t=e.status===`done`||e.status===`cancelled`,n=$l(e,u);return(0,Q.jsxs)(`li`,{className:`group flex min-w-0 items-start gap-2.5 rounded-xl border border-stone-200 bg-white px-3 py-2.5 hover:border-stone-300`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>void p(e),"aria-label":t?`恢复 ${e.title}`:`完成 ${e.title}`,"aria-pressed":t,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded-full border transition-colors ${t?`border-[#4176e6] bg-[#4176e6] text-white`:`border-stone-300 text-transparent hover:border-[#4176e6]`}`,children:(0,Q.jsx)(`svg`,{viewBox:`0 0 20 20`,width:`10`,height:`10`,fill:`none`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,Q.jsx)(`path`,{d:`m4 10 4 4 8-9`})})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 break-words text-[13px] leading-5 ${t?`text-stone-400 line-through`:`text-stone-800`}`,children:e.title}),t?(0,Q.jsx)(`span`,{className:`shrink-0 pt-0.5 text-[11px] text-stone-400`,children:In[e.status]}):e.priority?(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 pt-0.5 text-[11px] ${Xl[e.priority]??`text-stone-400`}`,children:[(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${Yl[e.priority]??`bg-stone-300`}`}),Jn[e.priority]]}):null]}),(0,Q.jsxs)(`div`,{className:`mt-1 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] leading-4`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-stone-400 tabular-nums`,children:n.due?`截止 ${n.due}`:`无截止日期`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Q.jsx)(`span`,{className:`shrink-0 tabular-nums ${n.tone}`,children:n.remain}),e.linkedTask?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Q.jsxs)(`span`,{className:`min-w-0 truncate ${t?`text-stone-400`:`text-stone-500`}`,children:[`任务 `,e.linkedTask]})]}):null]})]})]},e.id)})})]},e.key))})})]})}var ru=`__routine__`;function iu(e){let t=U(),n=U();return{title:``,status:e===`todo`?H(t,n)??`in_progress`:`pool`,statusManual:!1,priority:``,taskId:``,linkedTask:``,startDate:t,dueDate:n,note:``}}function au(e,t){let n=Array.isArray(t)?t:[],r=[];for(let t of n){if(!t||typeof t!=`object`)continue;let n=t,i=typeof n.title==`string`?n.title.trim():``;if(!i)continue;let a=e===`todo`?Xn:Kn,o=e===`todo`?Pn:W,s=iu(e),c=typeof n.status==`string`&&a.includes(n.status),l=c?n.status:e===`todo`?s.status:`pool`;r.push({...s,title:i,status:l,statusManual:e===`todo`&&c,priority:typeof n.priority==`string`&&o.includes(n.priority)?n.priority:``,taskId:typeof n.taskId==`string`?n.taskId.trim():``,linkedTask:typeof n.linkedTask==`string`?n.linkedTask.trim():``,startDate:typeof n.startDate==`string`?n.startDate.trim().slice(0,10):s.startDate,dueDate:typeof n.dueDate==`string`?n.dueDate.trim().slice(0,10):s.dueDate,note:typeof n.note==`string`?n.note.trim():``})}return r}function ou(e,t){return t.map(t=>{let n={title:t.title.trim(),status:t.status,priority:t.priority,startDate:t.startDate,dueDate:t.dueDate,note:t.note};return e===`todo`&&(n.taskId=t.taskId,n.linkedTask=t.linkedTask,n.statusManual=!!t.statusManual),n})}var su=`text-[11px] font-medium text-stone-500`,cu=`h-9 w-full rounded-lg border border-stone-200 px-2.5 text-[13px] text-stone-800 outline-none focus:border-[#4176e6]`;function lu(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function uu(e){return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:e.label}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.children})]})}function du(e){return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:e.label}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.children})]})}function fu(e){let{startDate:t,dueDate:n}=e,r=n||t,i=`h-7 rounded-md px-1.5 text-[12px] text-stone-700 tabular-nums transition-colors hover:bg-stone-100`;return(0,Q.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`日期`}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(M,{value:t,ariaLabel:`开始日期`,placeholder:`开始日期`,clearable:!1,className:i,onChange:t=>{t&&e.onChange({startDate:t,dueDate:t>r?t:r})}})}),(0,Q.jsx)(`span`,{className:`shrink-0 px-0.5 text-[11px] text-stone-300`,"aria-hidden":!0,children:`~`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(M,{value:n,ariaLabel:`截止日期`,placeholder:`截止日期`,clearable:!1,className:i,onChange:n=>{n&&e.onChange({startDate:n<t?n:t,dueDate:n})}})})]})]})}function pu(e){let[t,n]=(0,K.useState)(()=>e.items),[r,i]=(0,K.useState)(0),[a,o]=(0,K.useState)([]);(0,K.useEffect)(()=>{n(e.items),i(0)},[e.items]);let s=e.kind===`todo`,c=!!e.quick&&s,l=s&&e.tasksOn!==!1,u=s&&!c&&l,d=s?`待办`:`任务`,f=s?`待办事项`:`任务管理`;(0,K.useEffect)(()=>{if(!l)return;let e=!0;return qn().then(t=>{e&&o(t)}).catch(()=>{}),()=>{e=!1}},[l]);let p=s?Xn:Kn,m=s?Pn:W,h=(0,K.useMemo)(()=>p.map(e=>({value:e,label:s?In[e]:Bn[e]})),[s,p]),g=(0,K.useMemo)(()=>[...m.map(e=>({value:e,label:s?Jn[e]:Wn[e]}))],[s,m]),_=(0,K.useMemo)(()=>[{value:``,label:`不关联`},...a.filter(e=>e.status!==`closed`&&e.status!==`cancelled`).map(e=>({value:e.id,label:e.title}))],[a]),v=(0,K.useMemo)(()=>!!io(a),[a]),y=(0,K.useMemo)(()=>{let e=new Set(t.map(e=>e.taskId).filter(Boolean));return[{value:``,label:`不关联`},...v?[]:[{value:ru,label:`${no}(确认后自动创建)`}],...a.filter(t=>e.has(t.id)||t.status!==`closed`&&t.status!==`cancelled`).map(e=>({value:e.id,label:e.title}))]},[t,a,v]);function b(e){return e.taskId&&a.some(t=>t.id===e.taskId)?e.taskId:!v&&e.linkedTask.trim()===`日常待办`?ru:``}function x(e,t){if(t===ru){S(e,{taskId:``,linkedTask:no});return}let n=a.find(e=>e.id===t);S(e,{taskId:n?.id??``,linkedTask:n?.title??``,...n?{priority:n.priority}:{}})}function S(e,t){n(n=>n.map((n,r)=>{if(r!==e)return n;let i={...n,...t};if(!s)return i;if(`status`in t&&!(`startDate`in t||`dueDate`in t))i.statusManual=!0;else if((`startDate`in t||`dueDate`in t)&&!i.statusManual&&!On(i.status)){let e=H(i.startDate,i.dueDate);e&&(i.status=e)}return i.dueDate&&i.dueDate<U()&&!On(i.status)&&(i.status=`overdue`,i.statusManual=!1),i}))}function C(e,n){let r=t[e],i=a.find(e=>e.id===n);i?S(e,{taskId:i.id,linkedTask:i.title,startDate:i.startDate||r?.startDate||``,dueDate:i.dueDate||r?.dueDate||``,priority:r?.priority||i.priority||``}):S(e,{taskId:``,linkedTask:``})}function w(e){n(t=>t.filter((t,n)=>n!==e))}let T=t.length>0&&t.every(e=>!!e.title.trim()),E=u&&r>=1,D=c&&t.some(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`)&&!v,O=E?`所属任务的日期与紧急程度已带到第一页,可回去再调`:c?D?e.quickNote??`确认后会自动创建任务「日常待办」并关联`:`状态 / 所属任务 / 日期已填好(日期可点开改),确认后写入「待办事项」`:`确认后才会写入「${f}」`;return(0,Q.jsxs)(`div`,{className:[`tw-create-card tw-create-card-anim mb-2 flex max-h-[min(62vh,560px)] flex-col overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_6px_24px_rgba(15,23,42,0.08)]`,e.closing?`is-closing`:``].filter(Boolean).join(` `),children:[(0,Q.jsxs)(`div`,{className:`shrink-0 px-5 pt-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-[11px] leading-4 text-stone-400`,children:[(0,Q.jsxs)(`span`,{children:[`新增 `,t.length,` 条`,d]}),u?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-stone-300`,children:`·`}),(0,Q.jsxs)(`span`,{className:`tabular-nums`,children:[`第 `,r+1,` / 2 步`]})]}):null]}),(0,Q.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:E?`关联任务`:r===0?`确认内容后再添加到${f}`:f})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-3`,children:(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[t.map((e,n)=>{let r=a.find(t=>t.id===e.taskId);return(0,Q.jsx)(`div`,{className:`rounded-xl border border-stone-200 bg-stone-50/40 p-3`,children:c?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`input`,{value:e.title,onChange:e=>S(n,{title:e.target.value}),placeholder:`待办名称`,className:`${cu} bg-white`,autoFocus:n===0}),t.length>1?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>w(n),"aria-label":`移除这一条`,className:`h-9 shrink-0 rounded-lg px-2 text-[12px] text-stone-400 hover:bg-white hover:text-red-600`,children:`移除`}):null]}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded-lg border border-stone-200 bg-white px-2.5 py-2`,children:[(0,Q.jsx)(du,{label:`状态`,children:In[e.status]??`进行中`}),l?(0,Q.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`所属任务`}),a.length||!v?(0,Q.jsx)(N,{flat:!0,ariaLabel:`所属任务`,menuMatchTrigger:!1,menuMinWidth:200,options:y,value:b(e),onChange:e=>x(n,e),className:`min-w-0`,triggerClassName:`h-7 gap-1 rounded-md border-0 bg-transparent pl-0 pr-0.5 text-[12px] hover:bg-stone-50`}):(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.linkedTask||`未关联`})]}):null,(0,Q.jsx)(fu,{startDate:e.startDate,dueDate:e.dueDate,onChange:e=>S(n,e)})]})]}):E?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:su,children:`所属任务`}),a.length?(0,Q.jsx)(N,{flat:!0,ariaLabel:`所属任务`,options:_,value:e.taskId,onChange:e=>C(n,e),className:`w-full`}):(0,Q.jsx)(`span`,{className:`flex h-9 items-center rounded-lg border border-stone-200 bg-white px-2 text-[13px] text-stone-400`,children:`任务管理里还没有任务,可稍后到任务管理关联`})]}),r?(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded-lg border border-stone-200 bg-white px-2.5 py-2`,children:[(0,Q.jsx)(uu,{label:`任务名称`,children:r.title}),(0,Q.jsx)(uu,{label:`状态`,children:Bn[r.status]??r.status}),(0,Q.jsx)(uu,{label:`紧急程度`,children:r.priority?Wn[r.priority]:`未选择`}),(0,Q.jsx)(uu,{label:`开始日期`,children:lu(r.startDate)||`未设置`}),(0,Q.jsx)(uu,{label:`结束日期`,children:lu(r.dueDate)||`未设置`})]}):(0,Q.jsx)(`p`,{className:`mt-2 text-[11px] leading-4 text-stone-400`,children:`选中任务后,它的开始 / 结束日期与紧急程度会自动带到第一页。`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`input`,{value:e.title,onChange:e=>S(n,{title:e.target.value}),placeholder:s?`待办名称`:`任务名称`,className:`${cu} bg-white`,autoFocus:n===0}),t.length>1?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>w(n),"aria-label":`移除这一条`,className:`h-9 shrink-0 rounded-lg px-2 text-[12px] text-stone-400 hover:bg-white hover:text-red-600`,children:`移除`}):null]}),(0,Q.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:su,children:`状态`}),(0,Q.jsx)(N,{flat:!0,ariaLabel:s?`待办状态`:`任务状态`,options:h,value:e.status,onChange:e=>S(n,{status:e}),className:`w-full`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:su,children:`紧急程度`}),(0,Q.jsx)(N,{flat:!0,ariaLabel:`紧急程度`,options:g,value:e.priority,onChange:e=>S(n,{priority:e}),className:`w-full`,renderTrigger:()=>(0,Q.jsx)(`span`,{className:`truncate ${e.priority?`text-stone-800`:`text-stone-400`}`,children:e.priority?s?Jn[e.priority]:Wn[e.priority]:`未选择`})})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:su,children:`开始日期`}),(0,Q.jsx)(M,{value:e.startDate,onChange:e=>S(n,{startDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:su,children:`截止日期`}),(0,Q.jsx)(M,{value:e.dueDate,onChange:e=>S(n,{dueDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]})]}),(0,Q.jsxs)(`label`,{className:`mt-2 flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:su,children:`备注`}),(0,Q.jsx)(`input`,{value:e.note,onChange:e=>S(n,{note:e.target.value}),placeholder:`备注(可选)`,className:`${cu} bg-white`})]})]})},n)}),t.length?null:(0,Q.jsx)(`p`,{className:`py-4 text-center text-[12px] text-stone-400`,children:`内容已清空,点「取消」放弃这次新增。`})]})}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-t border-stone-100 px-5 py-3`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-[11px] text-stone-400`,children:O}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:E?()=>i(0):e.onCancel,className:`h-8 rounded-lg px-3 text-[12px] text-stone-600 outline-none hover:bg-stone-100`,children:E?`上一步`:`取消`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!E&&!T,onClick:()=>{u&&r===0?i(1):e.onConfirm(t)},className:`h-8 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4] disabled:cursor-not-allowed disabled:bg-stone-300`,children:u&&r===0?`下一步`:e.manual?`提交`:`确认新增`})]})]})]})}function mu(e,t,n){let r=e;if(n.knowledge&&(r=`${r}\n\n${Mc}`),n.fs&&(r=`${r}\n\n${vn}\n\n${Sa}\n\n${Co}\n\n${Ei}\n\n${Si}`),n.bash&&(r=`${r}\n\n${sr}`),n.pwsh&&(r=`${r}\n\n${cr}`),n.web&&(r=`${r}\n\n${rr}`),n.memory&&(r=`${r}\n\n${Or}`),n.interact&&(r=`${r}\n\n${Po}`),n.todos&&(r=`${r}\n\n${qa}`),n.tasks&&(r=`${r}\n\n${lo}`),n.projects&&(r=`${r}\n\n${Ea}`),n.iterations&&(r=`${r}\n\n${Da}`),n.pmRequirements&&(r=`${r}\n\n${Oa}`),n.bugs&&(r=`${r}\n\n${ka}`),n.planPhase===`planning`&&(r=`${r}\n\n${Ho}`),n.planPhase===`approved`&&(r=`${r}\n\n${Uo}`),n.goalEnabled){r=`${r}\n\n${is}`;let e=cs(n.goal);e&&(r=`${r}\n\n【当前会话目标】${e}`)}n.scheduleEnabled&&(r=`${r}\n\n${Ts}`),n.subagentEnabled&&(r=`${r}\n\n${Ws}`),n.workflowEnabled&&(r=`${r}\n\n${Sc}`),n.mcpEnabled&&(r=`${r}\n\n${Dr}`);let i=n.memory?t.slice(-10):t;return[{role:`system`,content:r},...i]}function hu(e){if(!/(?:^|[\s\n])\/$/.test(e))return null;let t=e.lastIndexOf(`/`);return t<0?null:{from:t}}function gu(e){let t=/(?:^|[\s\n])@([^\s@]*)$/.exec(e);if(!t)return null;let n=e.lastIndexOf(`@`);return n<0?null:{from:n,query:t[1]??``}}function _u(e){let t=/\s*(?:[((](?:recommended|推荐)[))])\s*$/i;return t.test(e)?{label:e.replace(t,``),recommended:!0}:{label:e,recommended:!1}}var vu=pt,yu=5,bu=[`image/png`,`image/jpeg`,`image/jpg`,`image/webp`,`image/gif`],xu=[`dialog`,`thread`,`todos`,`memory`],Su=`chat.tab`;function Cu(e){let t=[];if(e.content&&t.push(e.content),e.refs?.length){let n=e.refs.filter(e=>e.collection!==`workspace`),r=e.refs.filter(e=>e.collection===`workspace`);if(n.length){let e=n.filter(e=>e.collection===`knowledge`||e.collection===`templates`),r=n.filter(e=>e.collection===`prompts`||e.collection===`cases`);if(e.length){let n=e.map(e=>`- ${e.path} 《${e.title}》(${e.category} · ${Ac(e.format)})`);t.push(`引用项目文档(请使用 kb_read 读取):\n${n.join(`
218
+ `)}`)}if(r.length){let e=r.map(e=>`- ${e.collection}/${e.path} 《${e.title}》(${e.category})`);t.push(`引用管理文档(路径已给出,正文可能已在上文):\n${e.join(`
219
+ `)}`)}}if(r.length){let e=r.map(e=>`- ${e.path} 《${e.title}》(${e.format===`dir`?`文件夹`:`文件`})`);t.push(`引用工作区路径(请使用 fs_list / fs_read):\n${e.join(`
220
+ `)}`)}}return e.attachments?.length&&t.push(e.attachments.map(e=>`附件《${e.name}》:\n\`\`\`\`\n${e.content}\n\`\`\`\``).join(`
221
+
222
+ `)),t.join(`
223
+
224
+ `)}function wu(e,t){let n=Cu(e),r=t?.supportsVision===!0;if(!e.images?.length||!r){if(e.images?.length&&!r){let t=`(当前模型未声明支持视觉,已忽略图片:${e.images.map(e=>e.name||`image`).join(`, `)})`;return n?`${n}\n\n${t}`:t}return n}let i=[];n?i.push({type:`text`,text:n}):i.push({type:`text`,text:`请查看图片。`});for(let t of e.images)i.push({type:`image_url`,image_url:{url:t.dataUrl}});return i}function Tu(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(Error(`读取图片失败`)),r.readAsDataURL(e)})}async function Eu(e){if(!bu.includes(e.type)&&!/\.(png|jpe?g|webp|gif)$/i.test(e.name))throw Error(`${e.name||`图片`}:不支持的格式`);if(e.size>10485760)throw Error(`${e.name||`图片`}:超过 ${Math.round(cl/1024/1024)} MB`);let t=await Tu(e);if(!t.startsWith(`data:image/`))throw Error(`无法识别为图片`);return{id:`img_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`,name:e.name||`paste-${new Date().toISOString().slice(11,19).replace(/:/g,``)}.png`,size:e.size,mime:e.type||`image/png`,dataUrl:t}}function Du(e,t){return e.length+t.length}var Ou=[{value:`low`,label:`Low`,desc:`响应更快,适合简单问答`},{value:`high`,label:`High`,desc:`质量与速度均衡(默认)`},{value:`max`,label:`Max`,desc:`最深推理,适合复杂分析`}],ku=[{value:`readonly`,label:`仅可查看`},{value:`readwrite`,label:`工作区内修改`},{value:`full`,label:`完全权限`}];function Au(e){return e===`present`?`交付文件`:e===`todo_write`?`待办`:e.startsWith(`todo_`)?`待办事项`:e===`ask_user_question`?`向用户提问`:e===`bash`?`Bash`:e===`pwsh`?`PowerShell`:e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)?`持久终端`:e.startsWith(`working_directory_`)?`工作目录`:e.startsWith(`skill_`)?`Skill`:e.startsWith(`workspace_changes_`)?`工作区变更`:e===`load_workspace_dependencies`?`工作区依赖`:e===`office_to_pdf`?`Office转PDF`:e===`submit_plan`?`提交计划`:e.startsWith(`goal_`)?`会话目标`:e.startsWith(`schedule_`)?`定时提醒`:e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)?`子代理`:e.startsWith(`mcp__`)?`MCP`:e===`workflow`?`工作流`:e===`job_list`?`任务列表`:e===`job_output`?`任务输出`:e===`job_kill`?`终止任务`:e===`web_search`?rn(`tool.kind.webSearch`):e===`web_fetch`?rn(`tool.kind.webFetch`):e.startsWith(`kb_`)?rn(`tool.kind.kb`):e.startsWith(`fs_`)?rn(`tool.kind.fs`):e.startsWith(`memory_`)?rn(`tool.kind.memory`):e}function ju(e){let t=String(e??``).trim();if(!t)return`请求失败`;if(/service_unavailable|too busy|瞬时繁忙|服务繁忙/i.test(t))return`模型服务瞬时繁忙,请稍后重试`;try{let e=JSON.parse(t),n=e?.error??e;if(n&&typeof n==`object`){let e=`${n.message||``} ${n.code||``} ${n.type||``}`;if(/service_unavailable|too busy/i.test(e))return`模型服务瞬时繁忙,请稍后重试`;if(typeof n.message==`string`&&n.message.trim())return n.message.trim()}}catch{}return t.length>280?`${t.slice(0,280)}…`:t}function Mu(e){return e===`present`?`fs`:e===`todo_write`||e.startsWith(`todo_`)||e===`ask_user_question`||e===`bash`||e===`pwsh`||e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)||e.startsWith(`working_directory_`)||e.startsWith(`skill_`)||e.startsWith(`workspace_changes_`)||e===`load_workspace_dependencies`||e===`office_to_pdf`||e===`submit_plan`||e.startsWith(`goal_`)||e.startsWith(`schedule_`)||e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)||e===`workflow`||e.startsWith(`job_`)?`tool`:e===`web_search`?`web_search`:e===`web_fetch`?`web_fetch`:e.startsWith(`fs_`)?`fs`:e.startsWith(`kb_`)?`kb`:e.startsWith(`memory_`)?`memory`:`tool`}function Nu({kind:e,status:t}){let n=t===`error`?`w-3.5 h-3.5 shrink-0 text-red-500`:t===`running`?`w-3.5 h-3.5 shrink-0 text-stone-500`:`w-3.5 h-3.5 shrink-0 text-stone-400`;return t===`running`&&e===`thinking`?(0,Q.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):e===`thinking`?(0,Q.jsxs)($,{className:n,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,Q.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}):e===`web_search`||e===`web_fetch`?(0,Q.jsxs)($,{className:n,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`path`,{d:`M2 12h20`}),(0,Q.jsx)(`path`,{d:`M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z`})]}):e===`fs`||e===`kb`?(0,Q.jsxs)($,{className:n,children:[(0,Q.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Q.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}):e===`memory`?(0,Q.jsx)($,{className:n,children:(0,Q.jsx)(`path`,{d:`M12 2a4 4 0 0 1 4 4v2h2a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2V6a4 4 0 0 1 4-4Z`})}):(0,Q.jsx)($,{className:n,children:(0,Q.jsx)(`path`,{d:`m12 3 1.9 5.8H20l-4.9 3.6 1.9 5.8L12 14.6 7.1 18.2l1.9-5.8L4 8.8h6.1Z`})})}function Pu(e,t){if(!t)return``;if(e.startsWith(`web_`))return hr(e,t);if(e===`present`)try{let e=(JSON.parse(t).files??[]).map(e=>e.path).filter(Boolean);return e.slice(0,3).join(`, `)+(e.length>3?`…`:``)}catch{return``}try{let n=JSON.parse(t);if(e===`submit_plan`){let e=typeof n.title==`string`?n.title.trim():``;return e.length>60?`${e.slice(0,60)}…`:e}if(e===`bash`||e===`pwsh`){let e=typeof n.command==`string`?n.command.trim():``,t=n.background===!0?` [bg]`:``;return`${e.length>80?`${e.slice(0,80)}…`:e}${t}`}if(e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)){let e=typeof n.sessionId==`string`?n.sessionId.trim():``,t=typeof n.command==`string`?n.command.trim():``;return[e,t.length>48?`${t.slice(0,48)}…`:t].filter(Boolean).join(` · `)}if(e.startsWith(`working_directory_`)){let e=typeof n.path==`string`?n.path.trim():``;return[typeof n.id==`string`?n.id.trim():``,e].filter(Boolean).join(` · `)}if(e.startsWith(`skill_`))return[typeof n.name==`string`?n.name.trim():``,typeof n.path==`string`?n.path.trim():``].filter(Boolean).join(` · `);if(e.startsWith(`workspace_changes_`))return``;if(e.startsWith(`job_`))return typeof n.jobId==`string`?n.jobId.trim():``;if(e.startsWith(`schedule_`)){let e=typeof n.text==`string`?n.text.trim():``,t=typeof n.id==`string`?n.id.trim():``,r=typeof n.dueAt==`string`?n.dueAt.trim():``,i=typeof n.delayMinutes==`number`&&Number.isFinite(n.delayMinutes)?`+${n.delayMinutes}m`:``;return[e,t,r||i].filter(Boolean).join(` · `)}if(e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)){let t=typeof n.agent==`string`?n.agent.trim():``,r=typeof n.prompt==`string`?n.prompt.trim():``,i=typeof n.id==`string`?n.id.trim():``,a=r.length>48?`${r.slice(0,48)}…`:r;return[e===`fork_subagent`?`fork`:``,t,i,a].filter(Boolean).join(` · `)}if(e===`workflow`){let e=n.meta;return(typeof e?.name==`string`?e.name.trim():``)||`workflow`}if(e===`fs_glob`||e===`fs_grep`){let e=typeof n.pattern==`string`?n.pattern.trim():``;return[e,typeof n.path==`string`?n.path.trim():``].filter(Boolean).join(` @ `)||e}if(typeof n.path==`string`&&n.path.trim())return n.path.trim();if(typeof n.query==`string`&&n.query.trim())return n.query.trim()}catch{}return``}function Fu(e){let t=``,n=0,r=/\r?\n(?:[\t ]*\r?\n)+/g;for(;;){let i=r.exec(e),a=i===null?e.length:i.index+i[0].indexOf(`
225
+ `),o=e.indexOf(`
226
+ `,n);if(o!==-1&&o<=a){let r=e.slice(n,o).trim();r!==``&&(t=r)}if(i===null)return t;n=i.index+i[0].length}}function Iu(e,t,n,r){return e===`concise`?r===`running`?rn(`tool.running`):null:e===`standard`?rn(r===`running`?`tool.callingKind`:`tool.doneKind`,{kind:t}):rn(e===`detailed`?r===`running`?`tool.callingNamed`:`tool.doneNamed`:r===`running`?`tool.callingFull`:`tool.doneFull`,{kind:t,name:n})}function $({className:e=``,children:t}){return(0,Q.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:t})}var Lu=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m6 9 6 6 6-6`})}),Ru=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m9 18 6-6-6-6`})}),zu=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`M20 6 9 17l-5-5`})}),Bu=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`}),(0,Q.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),Vu=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`}),(0,Q.jsx)(`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`}),(0,Q.jsx)(`path`,{d:`M3 12a9 3 0 0 0 18 0`})]}),Hu=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`m12 14 4-4`}),(0,Q.jsx)(`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`})]}),Uu=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Q.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}),Wu=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m16.5 9.4-7.07 7.07a3 3 0 0 1-4.24-4.24l7.07-7.07a2 2 0 1 1 2.83 2.83L8.02 14.1a1 1 0 0 1-1.41-1.41l7.07-7.07`})}),Gu=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`m5 12 7-7 7 7`}),(0,Q.jsx)(`path`,{d:`M12 19V5`})]}),Ku=({className:e=``,open:t=!1})=>(0,Q.jsx)($,{className:e,children:t?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.55 6A2 2 0 0 1 18.45 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.69.9H18a2 2 0 0 1 2 2v2`})}):(0,Q.jsx)(`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9l-.81-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`})}),qu=({className:e=``,open:t=!1})=>(0,Q.jsx)(`svg`,{className:`${e} tw-arrow ${t?`is-open`:``}`,viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":!0,children:(0,Q.jsx)(`path`,{d:`M4.2 2.4a.75.75 0 0 1 1.2-.57l4.2 3.35a.75.75 0 0 1 0 1.14l-4.2 3.35A.75.75 0 0 1 4.2 9.1V2.9Z`})}),Ju=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,Q.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),Yu=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M12 8v8`}),(0,Q.jsx)(`path`,{d:`M8 12h8`})]}),Xu=({className:e=``,filled:t=!1})=>(0,Q.jsx)($,{className:e,children:t?(0,Q.jsx)(`path`,{fill:`currentColor`,stroke:`none`,d:`M12 2a3 3 0 0 1 3 3v3.5l2.5 2.5V13h-3.5V20l-1.5 2-1.5-2v-7H7.5v-2L10 8.5V5a3 3 0 0 1 3-3Z`}):(0,Q.jsx)(`path`,{d:`M12 17v5M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16h14v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2z`})}),Zu=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Q.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Q.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]}),Qu=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M4 8h16v11a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8Z`}),(0,Q.jsx)(`path`,{d:`M8 8V5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v3`}),(0,Q.jsx)(`path`,{d:`M10 12h4`})]}),$u=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M12 22v-5`}),(0,Q.jsx)(`path`,{d:`M9 8V2`}),(0,Q.jsx)(`path`,{d:`M15 8V2`}),(0,Q.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});function ed(e){let t=Math.max(0,Math.floor((Date.now()-e)/1e3));if(t<60)return`刚刚`;let n=Math.floor(t/60);if(n<60)return`${n}分钟`;let r=Math.floor(n/60);if(r<24)return`${r}小时`;let i=Math.floor(r/24);if(i<30)return`${i}天`;let a=Math.floor(i/30);return a<12?`${a}个月`:`${Math.floor(a/12)}年`}function td(e){let t=ed(e);return t===`刚刚`?`刚刚`:t.endsWith(`前`)?t:`${t}前`}function nd({open:e,onToggle:t,onRename:n,onDelete:r}){let i=(0,K.useRef)(null);return(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{ref:i,type:`button`,"aria-label":`更多`,onClick:e=>{e.stopPropagation(),t()},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Q.jsx)(Zu,{className:`w-3.5 h-3.5`})}),(0,Q.jsxs)(rd,{open:e,anchorRef:i,dataAttr:`data-ws-menu`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:e=>{e.stopPropagation(),n()},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),r?(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:e=>{e.stopPropagation(),r()},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`删除工作区`]}):null]})]})}function rd({open:e,anchorRef:t,dataAttr:n,children:r}){let[i,a]=(0,K.useState)(null);return(0,K.useLayoutEffect)(()=>{if(!e){a(null);return}let n=()=>{let e=t.current;if(!e)return;let n=e.getBoundingClientRect(),r=n.bottom+200>window.innerHeight-8,i=Math.max(8,Math.min(n.left,window.innerWidth-160-8));a({top:r?n.top-4:n.bottom+4,left:i,openUp:r})};return n(),window.addEventListener(`scroll`,n,!0),window.addEventListener(`resize`,n),()=>{window.removeEventListener(`scroll`,n,!0),window.removeEventListener(`resize`,n)}},[e,t]),!e||!i||typeof document>`u`?null:(0,qr.createPortal)((0,Q.jsx)(`div`,{[n]:``,className:`tw-popover tw-popover-anim z-80 w-40 rounded-xl border border-stone-200 py-1 shadow-lg`,style:{position:`fixed`,top:i.top,left:i.left,transform:i.openUp?`translateY(-100%)`:void 0},children:r}),document.body)}function id({s:e,nested:t=!1,active:n,menuOpen:r,busy:i,onOpen:a,onRename:o,onToggleMenu:s,onTogglePin:c,onToggleArchive:l,onExport:u,onFork:d,onRemove:f,onRestore:p}){let m=(0,K.useRef)(null),h=(0,K.useRef)(null),g=(0,K.useRef)(null),_=(0,K.useRef)(null),v=(0,K.useRef)(null),y=(0,K.useRef)(null),[b,x]=(0,K.useState)(!1),[S,C]=(0,K.useState)(!1),[w,T]=(0,K.useState)(null);function E(){v.current!=null&&(clearTimeout(v.current),v.current=null)}function D(){y.current!=null&&(clearTimeout(y.current),y.current=null)}function O(){D(),y.current=setTimeout(()=>{C(!1),E()},180)}function k(){D(),E(),v.current=setTimeout(()=>C(!0),1e3)}let ee=e.title.trim()||`新对话`;(0,K.useLayoutEffect)(()=>{let e=g.current,t=_.current;if(!e||!t)return;let n=()=>{t.style.maxWidth=`none`,t.style.overflow=`visible`,t.style.display=`inline-block`;let n=t.scrollWidth;t.style.maxWidth=``,t.style.overflow=``,t.style.display=``;let r=e.clientWidth,i=n>r+1;x(i),i?t.style.setProperty(`--tw-marquee-shift`,`${Math.min(0,r-n-28)}px`):t.style.removeProperty(`--tw-marquee-shift`)};n();let r=typeof ResizeObserver<`u`?new ResizeObserver(n):null;return r?.observe(e),()=>r?.disconnect()},[e.title]),(0,K.useLayoutEffect)(()=>{if(!S||r){T(null);return}let e=()=>{let e=m.current;if(!e)return;let t=e.getBoundingClientRect();T({top:t.top+t.height/2,left:t.right+8})};return e(),window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[S,r,e.title]),(0,K.useEffect)(()=>{r&&(E(),D(),C(!1))},[r]);let te=i?`生成中`:`空闲`,ne=!!(e.archived||e.deleted);return(0,Q.jsxs)(`div`,{ref:m,className:`tw-session-row relative ${t?`is-nested`:``} ${n?`is-selected`:``} ${r?`is-menu-open`:``} ${i?`is-busy`:``} ${ne?`opacity-50`:``}`,onMouseLeave:()=>{E(),O()},children:[i?(0,Q.jsx)(`span`,{className:`tw-session-busy-slot`,"data-hint":`生成中`,"aria-label":`生成中`,children:(0,Q.jsx)(`span`,{className:`tw-session-busy-dot`,"aria-hidden":!0})}):null,e.pinned&&!ne?(0,Q.jsx)(`span`,{className:`tw-slot`,"aria-hidden":!0,children:(0,Q.jsx)(Xu,{filled:!0,className:`tw-pin-indicator w-3 h-3`})}):null,(0,Q.jsx)(`button`,{ref:g,type:`button`,onClick:a,onDoubleClick:o,onMouseEnter:()=>k(),onMouseLeave:()=>{E(),O()},className:`tw-session-title text-left outline-none focus:outline-none focus-visible:outline-none ${b?`is-overflow`:``}`,children:(0,Q.jsx)(`span`,{ref:_,className:`tw-session-title-inner`,children:e.title})}),(0,Q.jsx)(`span`,{className:`tw-session-time pr-1`,children:ed(e.updatedAt)}),(0,Q.jsxs)(`div`,{"data-session-menu":``,className:`tw-row-actions items-center gap-0.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{ref:h,type:`button`,"aria-label":`更多`,onClick:s,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(Zu,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(rd,{open:r,anchorRef:h,dataAttr:`data-session-menu`,children:e.deleted?(0,Q.jsxs)(Q.Fragment,{children:[p?(0,Q.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:p,children:`恢复会话`}):null,(0,Q.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:f,children:`永久删除`})]}):(0,Q.jsxs)(Q.Fragment,{children:[!e.archived&&(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:c,children:[(0,Q.jsx)(Xu,{filled:!!e.pinned,className:`w-3.5 h-3.5`}),e.pinned?`取消置顶`:`置顶会话`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:o,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:l,children:[(0,Q.jsx)(Qu,{className:`w-3.5 h-3.5`}),e.archived?`取消归档`:`归档会话`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:u,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,Q.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,Q.jsx)(`line`,{x1:`12`,x2:`12`,y1:`15`,y2:`3`})]}),`导出会话`]}),d&&!e.archived?(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:d,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`circle`,{cx:`6`,cy:`6`,r:`2.5`}),(0,Q.jsx)(`circle`,{cx:`18`,cy:`6`,r:`2.5`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`18`,r:`2.5`}),(0,Q.jsx)(`path`,{d:`M8.2 7.2 10.5 15`}),(0,Q.jsx)(`path`,{d:`M15.8 7.2 13.5 15`})]}),`分叉会话`]}):null,e.archived?(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:f,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`永久删除`]}):null]})})]}),!e.deleted&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":e.archived?`取消归档`:`归档会话`,"data-hint":e.archived?`取消归档`:`归档会话`,onClick:l,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(Qu,{className:`w-3.5 h-3.5`})}),!e.archived&&!e.deleted&&(0,Q.jsx)(`button`,{type:`button`,"data-hint":e.pinned?`取消置顶`:`置顶`,onClick:c,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(Xu,{filled:!!e.pinned,className:`w-3.5 h-3.5`})})]}),S&&!r&&w&&typeof document<`u`?(0,qr.createPortal)((0,Q.jsxs)(`div`,{className:`tw-session-preview`,role:`tooltip`,style:{position:`fixed`,top:w.top,left:w.left,transform:`translateY(-50%)`},onMouseEnter:()=>{E(),D(),C(!0)},onMouseLeave:()=>O(),children:[(0,Q.jsx)(`div`,{className:`tw-session-preview-title`,children:ee}),(0,Q.jsx)(`div`,{className:`tw-session-preview-meta`,children:td(e.updatedAt)}),(0,Q.jsx)(`div`,{className:`tw-session-preview-status ${i?`is-busy`:``}`,children:te})]}),document.body):null]})}var ad=`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`;function od({level:e,className:t=``}){return(0,Q.jsxs)($,{className:t,children:[(0,Q.jsx)(`path`,{d:ad}),e===`readonly`&&(0,Q.jsx)(`path`,{d:`m9 12 2 2 4-4`}),e===`readwrite`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M9 10h6`}),(0,Q.jsx)(`path`,{d:`M9 14h3`})]}),e===`full`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M12 8v4`}),(0,Q.jsx)(`path`,{d:`M12 16h.01`})]})]})}function sd(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function cd(e){return`${e.toLocaleString(`en-US`)} tok`}function ld(e){let t=e/1e3;if(t<60)return`${Math.round(t*10)/10} 秒`;let n=Math.round(t);return`${Math.floor(n/60)} 分 ${n%60} 秒`}function ud(e){return e>=99.95?`100`:e>=10?String(Math.round(e)):e.toFixed(1)}function dd(e){let t=0;for(let n of e)t+=/[\u4e00-\u9fff]/.test(n)?1:.25;return Math.max(1,Math.round(t))}function fd(e){return e.uncachedTokens==null?e.cachedTokens==null?e.promptTokens:Math.max(0,e.promptTokens-e.cachedTokens):e.uncachedTokens}function pd(e){return e?typeof e.completionTokens==`number`&&e.completionTokens>0?e.completionTokens:typeof e.totalTokens==`number`&&typeof e.promptTokens==`number`?Math.max(0,e.totalTokens-e.promptTokens):typeof e.completionTokens==`number`?Math.max(0,e.completionTokens):0:0}function md(e,t){return t<=0?null:e/t*100}function hd(e){return e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function gd(e){let t=new Date(e),n=`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`;return t.toDateString()===new Date().toDateString()?n:`${t.getMonth()+1}/${t.getDate()} ${n}`}async function _d(e){try{return await navigator.clipboard.writeText(e),!0}catch{try{let t=document.createElement(`textarea`);t.value=e,t.style.cssText=`position:fixed;opacity:0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}}function vd({text:e}){let[t,n]=(0,K.useState)(!1),r=(0,K.useRef)(null);(0,K.useEffect)(()=>()=>{r.current!==null&&window.clearTimeout(r.current)},[]);async function i(){t||await _d(e)&&(n(!0),r.current=window.setTimeout(()=>n(!1),1e3))}return(0,Q.jsx)(`button`,{type:`button`,onClick:i,"aria-label":t?`已复制`:`复制`,className:`tw-icon-btn tw-msg-action-btn inline-flex items-center justify-center rounded-md transition-colors`,children:t?(0,Q.jsx)(zu,{className:`w-3.5 h-3.5 text-emerald-600`}):(0,Q.jsx)(Bu,{className:`w-3.5 h-3.5`})})}function yd({pct:e}){return(0,Q.jsxs)(`svg`,{className:`w-3.5 h-3.5 -rotate-90`,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,Q.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`var(--color-stone-200)`,strokeWidth:`3`}),(0,Q.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`#4176e6`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:`${Math.max(e,1)/100*50.27} 50.27`})]})}function bd(){let[e,t]=(0,K.useState)(!1),n=(0,K.useRef)(null),r=(0,K.useRef)(null),[i,a]=(0,K.useState)(null);return(0,K.useEffect)(()=>{if(!e){a(null);return}let t=()=>{let e=n.current,t=r.current;if(!e||!t)return;let i=e.getBoundingClientRect(),o=t.getBoundingClientRect(),s=i.left+i.width/2-o.width/2;s=Math.max(12,Math.min(s,window.innerWidth-o.width-12));let c=i.top-o.height-8;c<12&&(c=i.bottom+8),a({position:`fixed`,left:s,top:c,visibility:`visible`})};a({position:`fixed`,left:0,top:0,visibility:`hidden`});let i=requestAnimationFrame(t);return window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,!0),()=>{cancelAnimationFrame(i),window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t,!0)}},[e]),(0,K.useEffect)(()=>{if(!e)return;let i=e=>{e.key===`Escape`&&t(!1)},a=e=>{let i=e.target;n.current?.contains(i)||r.current?.contains(i)||t(!1)};return document.addEventListener(`keydown`,i),document.addEventListener(`click`,a,!0),()=>{document.removeEventListener(`keydown`,i),document.removeEventListener(`click`,a,!0)}},[e]),{open:e,setOpen:t,rootRef:n,panelRef:r,pos:i}}function xd({title:e,titleValue:t,icon:n,children:r}){return(0,Q.jsxs)(`div`,{className:`tw-popover w-[min(320px,calc(100vw-24px))] rounded-2xl border border-stone-200 p-3.5 shadow-xl text-left`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[n,(0,Q.jsx)(`span`,{className:`tw-popover-title font-medium text-stone-800`,children:e}),t!==void 0&&(0,Q.jsx)(`span`,{className:`tw-popover-muted ml-auto text-stone-500 tabular-nums`,children:t})]}),(0,Q.jsx)(`div`,{className:`mt-2.5 mb-2.5 border-t border-stone-100`}),r]})}function Sd({rows:e}){return(0,Q.jsx)(`dl`,{className:`grid grid-cols-[1fr_auto] gap-x-6 gap-y-2 text-[13px]`,children:e.filter(e=>!e.hide).map(e=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(`dt`,{className:`text-stone-500`,children:e.label}),(0,Q.jsx)(`dd`,{className:`text-stone-800 tabular-nums text-right`,children:e.value})]},e.label))})}function Cd({label:e,icon:t,ariaLabel:n,title:r,titleValue:i,children:a,variant:o=`pill`}){let{open:s,setOpen:c,rootRef:l,panelRef:u,pos:d}=bd();return(0,Q.jsxs)(`span`,{ref:l,className:`relative inline-flex items-center`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":s,"aria-label":n,onClick:()=>c(!s),className:o===`ghost`?`tw-msg-action-meta inline-flex items-center gap-1 tabular-nums transition-colors ${s?`text-stone-600`:`text-stone-400 hover:text-stone-600`}`:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full transition-colors ${s?`bg-stone-200/70 text-stone-600`:`hover:bg-stone-200/60 hover:text-stone-600`}`,children:[t,(0,Q.jsx)(`span`,{className:`leading-none`,children:e})]}),s&&(0,qr.createPortal)((0,Q.jsx)(`div`,{ref:u,role:`dialog`,"aria-label":r,style:d??{position:`fixed`,left:0,top:0,visibility:`hidden`},className:`z-80`,children:(0,Q.jsx)(xd,{title:r,titleValue:i,icon:t,children:a})}),document.body)]})}function wd({messages:e,busy:t,onRestoreCheckpoint:n}){let[r,i]=(0,K.useState)(()=>new Set),a=(0,K.useMemo)(()=>yi(e.map(e=>({role:e.role,content:typeof e.content==`string`?e.content:Cu(e),time:e.time}))),[e]);function o(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return a.length?(0,Q.jsx)(`ol`,{className:`list-none m-0 p-0 w-full max-w-[min(64rem,100%)] mx-auto space-y-2`,children:a.map(e=>{let i=r.has(e.index),a=!!e.assistantText;return(0,Q.jsxs)(`li`,{className:`rounded-xl border bg-white shadow-sm overflow-hidden ${i?`border-[#4176e6]/35`:`border-stone-200`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-1 px-3 py-2.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(e.index),"aria-expanded":i,className:`min-w-0 flex-1 text-left hover:bg-stone-50/80 rounded-lg -mx-1 px-1 py-0.5 transition-colors`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] font-medium text-stone-400 tabular-nums`,children:[`第 `,e.index,` 轮`]}),(0,Q.jsx)(Lu,{className:`w-3.5 h-3.5 text-stone-400 ml-auto shrink-0 transition-transform ${i?`rotate-180`:``}`})]}),i?null:(0,Q.jsxs)(`div`,{className:`space-y-1 text-[13px] leading-5`,children:[(0,Q.jsxs)(`p`,{className:`m-0 text-stone-800 truncate`,children:[(0,Q.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`用户`}),e.userPreview]}),(0,Q.jsxs)(`p`,{className:`m-0 text-stone-600 truncate`,children:[(0,Q.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`助手`}),e.assistantPreview||`(待回复)`]})]})]}),n?(0,Q.jsx)(`button`,{type:`button`,disabled:t||!a,"data-hint":a?`截断到本轮末,填入续写并发送`:`待本轮助手回复完成后可从此处继续`,className:`shrink-0 mt-0.5 text-[11px] text-[#4176e6] hover:underline disabled:opacity-40 disabled:no-underline px-1 whitespace-nowrap`,onClick:()=>n(e.endMessageIndex,e.index),children:`从此处继续`}):null]}),i?(0,Q.jsxs)(`div`,{className:`px-3 pb-3 space-y-2.5 text-[13px] leading-5 border-t border-stone-100 pt-2.5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`用户`}),(0,Q.jsx)(`div`,{className:`whitespace-pre-wrap break-words text-stone-800`,children:e.userText||`—`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`助手`}),e.assistantText?(0,Q.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:an(e.assistantText)}}):(0,Q.jsx)(`div`,{className:`text-stone-400`,children:`(待回复)`})]})]}):null]},e.index)})}):(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-stone-400`,children:`暂无回合(还没有用户/助手对话)`})}function Td({messages:e,model:t,systemPromptTokens:n}){let r=e.filter(e=>e.role===`assistant`&&e.usage);if(!r.length)return null;let i=r[r.length-1],a=e.filter(e=>e.role===`user`).length,o=r.length,s=r.reduce((e,t)=>e+(t.usage?.totalTokens??0),0),c=r.reduce((e,t)=>e+(t.usage?.promptTokens??0),0),l=r.reduce((e,t)=>e+(t.usage?.cachedTokens??0),0),u=r.reduce((e,t)=>e+(t.usage?fd(t.usage):0),0),d=r.reduce((e,t)=>e+(t.usage?.cacheWriteTokens??0),0),f=r.reduce((e,t)=>e+pd(t.usage),0),p=r.some(e=>e.usage?.cachedTokens!=null),m=p?md(l,c):null,h=r.reduce((e,t)=>e+(t.llmMs??0),0),g=r.reduce((e,t)=>e+(t.toolMs??0),0),_=r.map(e=>e.ttftMs).filter(e=>e!=null&&e>0),v=_.length?_.reduce((e,t)=>e+t,0)/_.length:0,y=r.reduce((e,t)=>t.llmMs==null||t.ttftMs==null?e:e+Math.max(0,t.llmMs-t.ttftMs),0),b=r.map(e=>e.tps).filter(e=>e!=null&&e>0),x=b.length?b.reduce((e,t)=>e+t,0)/b.length:void 0,S=y>200&&f>0?f/(y/1e3):x??(i.tps&&i.tps>0?i.tps:void 0),C=Ge().contextWindow||(t?lt[t]:void 0),w=i.usage?.promptTokens??0,T=C?Math.min(100,w/C*100):void 0,E=Math.min(n,w),D=Math.max(0,w-E);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-1 pt-2 text-xs text-stone-400 tabular-nums select-none`,children:[(0,Q.jsx)(Cd,{icon:(0,Q.jsx)(Hu,{className:`w-3.5 h-3.5`}),label:(0,Q.jsxs)(Q.Fragment,{children:[a,` 轮 `,o,` 步`,S?` · ${Math.round(S)} tok/s`:``]}),ariaLabel:`会话统计`,title:`会话统计`,children:(0,Q.jsx)(Sd,{rows:[{label:`模型用时`,value:h>0?ld(h):`—`},{label:`工具调用用时`,value:g>0?ld(g):`—`},{label:`首 token 平均 (TTFT)`,value:_.length?ld(v):`—`},{label:`输出速度 (TPS)`,value:S?`${Math.round(S)} tok/s`:`—`}]})}),(0,Q.jsx)(Cd,{icon:(0,Q.jsx)(Vu,{className:`w-3.5 h-3.5`}),label:(0,Q.jsxs)(Q.Fragment,{children:[sd(s),` tok`,m==null?``:` · 缓存命中 ${ud(m)}%`]}),ariaLabel:`Token 用量`,title:`Token 用量`,titleValue:cd(s),children:(0,Q.jsx)(Sd,{rows:[{label:`缓存命中`,value:m==null?`—`:`${ud(m)}%`,hide:m==null},{label:`未缓存输入`,value:cd(u)},{label:`缓存读取`,value:cd(l),hide:!p},{label:`缓存写入`,value:cd(d),hide:d<=0},{label:`输出`,value:cd(f)}]})}),T!==void 0&&C&&(0,Q.jsxs)(Cd,{icon:(0,Q.jsx)(yd,{pct:T}),label:`${ud(T)}%`,ariaLabel:`上下文占用`,title:`上下文已用 ${ud(T)}%`,titleValue:`~${sd(w)} / ${sd(C)}`,children:[(0,Q.jsxs)(`div`,{className:`h-2 rounded-full bg-stone-100 overflow-hidden flex mb-3`,children:[(0,Q.jsx)(`span`,{className:`h-full bg-stone-400`,style:{width:`${E/C*100}%`},"data-hint":`系统提示词`}),(0,Q.jsx)(`span`,{className:`h-full bg-[#4176e6]`,style:{width:`${D/C*100}%`},"data-hint":`对话消息`})]}),(0,Q.jsx)(Sd,{rows:[{label:`系统提示词`,value:`~${sd(E)}`},{label:`对话消息`,value:`~${sd(D)}`}]}),(0,Q.jsx)(`p`,{className:`mt-2.5 text-[11px] leading-4 text-stone-400`,children:`分段为示意估算(API 不返回上下文拆分);总量以最近一轮 prompt_tokens 为准。`})]})]})}function Ed({usage:e,model:t}){let n=e.cachedTokens==null?null:md(e.cachedTokens,e.promptTokens);return(0,Q.jsx)(Cd,{variant:`ghost`,icon:(0,Q.jsx)(Vu,{className:`w-3.5 h-3.5 shrink-0`}),label:(0,Q.jsxs)(Q.Fragment,{children:[`用量 `,sd(e.totalTokens),` tok`]}),ariaLabel:`本轮用量`,title:`本轮用量`,titleValue:cd(e.totalTokens),children:(0,Q.jsx)(Sd,{rows:[{label:`提供方 / 模型`,value:t??`—`,hide:!t},{label:`缓存命中`,value:n==null?`—`:`${ud(n)}%`,hide:n==null},{label:`未缓存输入`,value:cd(fd(e))},{label:`缓存读取`,value:cd(e.cachedTokens??0),hide:e.cachedTokens==null},{label:`缓存写入`,value:cd(e.cacheWriteTokens??0),hide:!(e.cacheWriteTokens&&e.cacheWriteTokens>0)},{label:`输出`,value:cd(e.completionTokens)}]})})}function Dd({settings:e}){let[t,n]=(0,K.useState)(!1),[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)([]),[s,c]=(0,K.useState)(`idle`),l=(0,K.useRef)(null),u=(0,K.useRef)(0);if((0,K.useEffect)(()=>{if(!t)return;let e=()=>{n(!1),i(null)},r=t=>{l.current?.contains(t.target)||e()},a=t=>{t.key===`Escape`&&e()};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,a),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,a)}},[t]),(0,K.useEffect)(()=>{if(!t||!e)return;let n=e.availableModels?.length?e.availableModels:[e.model];o(n),c(e.availableModels?.length?`ok`:`loading`);let r=++u.current;ot(e.baseURL,e.apiKey).then(t=>{if(r!==u.current)return;let n=t.length?t:[e.model];o(n),c(`ok`),t.length&&B({availableModels:t})}).catch(()=>{r===u.current&&c(n.length>1?`ok`:`fail`)})},[t,e]),!e)return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Ye(`model`),className:`flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-500 rounded-md hover:bg-stone-100 transition-colors`,children:[(0,Q.jsx)(`span`,{className:`whitespace-nowrap`,children:`配置模型`}),(0,Q.jsx)(Lu,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`})]});let d=e.reasoningEffort??`high`,f=Ou.find(e=>e.value===d)?.label??`High`;function p(e){B(e),n(!1),i(null)}let m=e=>`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left text-[13px] transition-colors ${e?`bg-stone-100`:`hover:bg-stone-100`}`;return(0,Q.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{n(e=>!e),i(null)},className:`tw-composer-bar-model group flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium rounded-md outline-none focus:outline-none focus-visible:outline-none transition-colors ${t?`bg-stone-100`:`hover:bg-stone-100`}`,title:`${e.model} · ${f}`,"aria-label":`模型 ${e.model},推理 ${f}`,children:[(0,Q.jsx)(`span`,{className:`tw-composer-bar-model-name max-w-40 truncate text-stone-600`,children:e.model}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-effort whitespace-nowrap text-stone-400`,children:f}),(0,Q.jsx)(Lu,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,Q.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute bottom-full right-0 mb-2 w-64 rounded-xl border border-stone-200 p-1 shadow-xl z-50`,children:[(0,Q.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`model`),onClick:()=>i(`model`),className:m(r===`model`),children:[(0,Q.jsx)(`span`,{className:`text-stone-700`,children:`模型`}),(0,Q.jsx)(`span`,{className:`ml-auto max-w-32 truncate text-stone-400`,children:e.model}),(0,Q.jsx)(Ru,{className:`w-3.5 h-3.5 text-stone-400`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`effort`),onClick:()=>i(`effort`),className:m(r===`effort`),children:[(0,Q.jsx)(`span`,{className:`text-stone-700`,children:`推理等级`}),(0,Q.jsx)(`span`,{className:`ml-auto text-stone-400`,children:f}),(0,Q.jsx)(Ru,{className:`w-3.5 h-3.5 text-stone-400`})]}),r===`model`&&(0,Q.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-64 max-h-72 overflow-y-auto rounded-xl border border-stone-200 p-1 shadow-xl`,children:[s===`loading`&&a.length<=1&&(0,Q.jsx)(`div`,{className:`px-3 py-2 text-xs text-stone-400`,children:`正在识别可用模型…`}),a.map(t=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p({model:t}),className:m(!1),children:[(0,Q.jsx)(`span`,{className:`flex-1 truncate ${t===e.model?`text-stone-900 font-medium`:`text-stone-600`}`,children:t}),t===e.model&&(0,Q.jsx)(zu,{className:`w-3.5 h-3.5 text-[#4176e6]`})]},t)),(0,Q.jsx)(`div`,{className:`mt-1 border-t border-stone-100 pt-1`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{n(!1),i(null),Ye(`model`)},className:`w-full px-3 py-1.5 rounded-lg text-left text-xs text-stone-400 hover:bg-stone-100`,children:s===`fail`?`识别失败,打开设置检查…`:a.length>1?`打开设置 · 模型…`:`打开设置识别可用模型…`})})]}),r===`effort`&&(0,Q.jsx)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-60 rounded-xl border border-stone-200 p-1 shadow-xl`,children:Ou.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p({reasoningEffort:e.value}),className:`w-full px-3 py-2 rounded-lg text-left hover:bg-stone-100 transition-colors`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`flex-1 ${d===e.value?`text-stone-900 font-medium`:`text-stone-600`}`,children:e.label}),d===e.value&&(0,Q.jsx)(zu,{className:`w-3.5 h-3.5 text-[#4176e6]`})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400`,children:e.desc})]},e.value))})]})]})}var Od=null;function kd(){if(!Od){let e=Nt();Od={store:e,messages:e.sessions.find(t=>t.id===e.activeId)?.messages??[]}}return Od}var Ad=new Map,jd=new Map,Md={current:null};function Nd({slashDocs:e=[]}){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(!1),[a,o]=(0,K.useState)(()=>kd().store),[c,l]=(0,K.useState)(()=>kd().messages),[u,d]=(0,K.useState)(()=>nn(kd().store.activeId??``)),[f,m]=(0,K.useState)([]),[v,y]=(0,K.useState)([]),[b,x]=(0,K.useState)([]),[S,C]=(0,K.useState)(vu),[w,D]=(0,K.useState)(!1),[O,k]=(0,K.useState)(null),ee=(0,K.useRef)(null);ee.current=O;let[te,ie]=(0,K.useState)(null),[M,oe]=(0,K.useState)(!1),[N,se]=(0,K.useState)(null),ce=(0,K.useRef)(null);ce.current=N;let[le,P]=(0,K.useState)(!1),[F,ue]=(0,K.useState)(null),de=(0,K.useRef)(null);de.current=F;let[fe,I]=(0,K.useState)(null),pe=(0,K.useRef)(null);pe.current=fe;let me=(0,K.useRef)(null),[he,ge]=(0,K.useState)(null),[L,R]=(0,K.useState)(0),[_e,ve]=(0,K.useState)(()=>T(`plugins.open`,[`0`,`1`],`0`)===`1`),ye=(0,K.useCallback)(e=>{ve(t=>{let n=typeof e==`function`?e(t):e;return E(`plugins.open`,n?`1`:`0`),n})},[]),[be,xe]=(0,K.useState)(null),[Se,Ce]=(0,K.useState)(null),[we,Te]=(0,K.useState)(null),[Ee,De]=(0,K.useState)(null),[Ne,Pe]=(0,K.useState)(null),[Fe,Ie]=(0,K.useState)(!1),[Le,Ve]=(0,K.useState)([]),[He,Ue]=(0,K.useState)(null),[We,Ke]=(0,K.useState)(`error`);function B(e,t=`error`){Ke(t),Ue(e)}let[et,tt]=(0,K.useState)(`readonly`),[nt,rt]=(0,K.useState)(!1),[it,ot]=(0,K.useState)(!0),[st,lt]=(0,K.useState)(!1),[V,ft]=(0,K.useState)(()=>p()),[pt,mt]=(0,K.useState)(``),[gt,_t]=(0,K.useState)(null),[vt,St]=(0,K.useState)(null),[Nt,on]=(0,K.useState)(!1),[hn,gn]=(0,K.useState)(null),[vn,xn]=(0,K.useState)(null),[Dn,On]=(0,K.useState)(null),[H,kn]=(0,K.useState)(null),[An,jn]=(0,K.useState)(!1),[Mn,Nn]=(0,K.useState)({}),[Pn,In]=(0,K.useState)(``),[Ln,Rn]=(0,K.useState)(!1),[zn,Bn]=(0,K.useState)(null),[U,Vn]=(0,K.useState)(()=>T(Su,xu,`dialog`)),[Hn,Un]=(0,K.useState)(()=>typeof window>`u`?{language:`zh-CN`,appearance:`system`,sessionFontSize:14,toolStepDetail:`standard`,busySendBehavior:`queue`,subagentModel:``}:qe()),[Wn,Gn]=(0,K.useState)(!1),[Kn,W]=(0,K.useState)(null),[qn,Jn]=(0,K.useState)(0),[Xn,Qn]=(0,K.useState)(!1),[nr,rr]=(0,K.useState)(!1),[ir,sr]=(0,K.useState)(!1),[cr,ur]=(0,K.useState)(!0),[dr,fr]=(0,K.useState)([]),[hr,_r]=(0,K.useState)([]),vr=!!(V.memory&&gt?.ok),br=!!V.knowledge,xr=!!Dn?.ok,G=!!vt?.ok,Sr=Nt&&!G,Tr=!!hn?.ok,Er=!!(vn?.ok&&vn.available),Dr=(0,K.useRef)(null),Or=(0,K.useRef)(Ad),kr=Md,jr=(0,K.useRef)(jd),Nr=(0,K.useRef)(new Map),Pr=(0,K.useRef)(new Map),Fr=(0,K.useRef)(null),Vr=(0,K.useRef)(!1),Hr=(0,K.useRef)(null),Ur=(0,K.useRef)(null),[Wr,Gr]=(0,K.useState)([]),[Kr,qr]=(0,K.useState)(null),q=(0,K.useRef)(null),$r=(0,K.useRef)(0),ei=(0,K.useRef)(new Set),[ii,ci]=(0,K.useState)(`off`),[li,ui]=(0,K.useState)(null),[di,fi]=(0,K.useState)(`day`),[mi,_i]=(0,K.useState)([]),[vi,yi]=(0,K.useState)(null),[xi,Si]=(0,K.useState)(null),[Ci,Ti]=(0,K.useState)(null);function Ei(e,t,n){e&&Y.current&&X(Ft(Y.current,e,{planPhase:t===`off`?void 0:t,planProposal:n??void 0}))}function Di(e,t,n){ci(e),Ti(t),ui(e===`planning`||e===`approved`?`plan`:e=>e===`plan`?null:e),Ei(n??Y.current?.activeId,e,t)}function ki(e){let t=Ko(e?.planPhase),n=qo(e?.planProposal);ci(t),Ti(n),(t===`planning`||t===`approved`)&&ui(`plan`)}let[Ai,ji]=(0,K.useState)(null),[Ni,Pi]=(0,K.useState)({}),[Fi,Ii]=(0,K.useState)(0),[Ri,Bi]=(0,K.useState)(!1),[Vi,Hi]=(0,K.useState)(null),[Ui,Wi]=(0,K.useState)(!1),[Gi,qi]=(0,K.useState)(``),[Ji,Yi]=(0,K.useState)(null),[Qi,$i]=(0,K.useState)(!1),ta=(0,K.useRef)(null),na=(0,K.useRef)(null);function ra(){na.current!==null&&(window.clearTimeout(na.current),na.current=null)}function ia(){ra(),$i(!1)}function aa(e,t,n={}){return new Promise(r=>{ta.current?.(null),ta.current=r,ia(),Yi({kind:e,items:t,quick:n.quick,quickNote:n.quickNote})})}function sa(e){let t=ta.current;ta.current=null,$i(!0),ra(),na.current=window.setTimeout(()=>{na.current=null,Yi(null),$i(!1)},160),t?.(e)}let ca=(0,K.useRef)(()=>{});ca.current=()=>sa(null),(0,K.useEffect)(()=>{if(!Ji||Qi)return;let e=e=>{let t=e.target;t instanceof Element&&(t.closest(`.tw-create-card`)||t.closest(`[data-headlessui-portal]`)||t.closest(`.tw-select-menu`)||t.closest(`.tw-date-panel`)||ca.current())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Ji,Qi]);function la(e){sr(!1),V[e===`todo`?`todos`:`tasks`]&&(ia(),Yi({kind:e,manual:!0,items:[iu(e)]}))}async function ua(e,t){let n=e===`todo`?`待办`:`任务`;try{e===`todo`?await Yn(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,taskId:e.taskId,linkedTask:e.linkedTask,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}):await Fn(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}),B(`已新增 ${t.length} 条${n},可在侧栏「${n===`待办`?`待办事项`:`任务管理`}」查看。`,`ok`)}catch(e){Ke(`error`),B(e instanceof Error?e.message:String(e))}}(0,K.useEffect)(()=>()=>{ta.current?.(null),ta.current=null,na.current!==null&&(window.clearTimeout(na.current),na.current=null)},[]);let da=(0,K.useRef)([]),fa=(0,K.useRef)(null);function pa(e){da.current=e,fr(e)}function ga(e){if(e.taskCards?.length){let t=e.taskCards.map(e=>e.label).join(` · `);return t.length>28?`${t.slice(0,28)}…`:t}let t=(e.displayContent||e.content).trim().replace(/\s+/g,` `);if(t)return t.length>28?`${t.slice(0,28)}…`:t;let n=e.files.length+e.imgs.length+e.refs.length;return n>0?`附件 ${n} 项`:`(空消息)`}let _a=(0,K.useRef)(null),ya=(0,K.useRef)(null),xa=(0,K.useRef)({stack:[``],index:0}),Sa=(0,K.useRef)(!1),Ca=(0,K.useRef)(null),Ta=(0,K.useRef)(null),Ea=(0,K.useRef)(null),Da=(0,K.useRef)(null),Oa=(0,K.useRef)(null),ka=(0,K.useRef)(null),Aa=(0,K.useRef)({}),ja=!!(G&&H?.workspace),Ma=gu(u),Na=(()=>{if(!Ma||!br)return[];let t=Ma.query.toLowerCase();return(t?e.filter(e=>jc(e,t)):e).slice(0,10)})(),Pa=(()=>{if(!Ma||!ja)return[];let e=Ma.query.toLowerCase(),t=hr.map(e=>({collection:`workspace`,id:`ws:${e.path}`,title:e.name,category:En(H?.workspace,H?.projectRoot),description:e.path,format:e.type===`dir`?`dir`:`file`,path:e.path}));return(e?t.filter(t=>jc(t,e)||t.path.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)):t).slice(0,10)})(),J=[...Na.map(e=>({section:`project`,doc:e})),...Pa.map(e=>({section:`workspace`,doc:e}))],Fa=!(!Ma||Xn),Ia=hu(u),La=_.filter(e=>e.hasPanel&&V[e.id]),Ra=!!(Ia&&!nr&&!Fa&&La.length>0),za=(0,K.useRef)(!0),Ba=(0,K.useRef)(!1),Y=(0,K.useRef)(null),Va=(0,K.useRef)(null),Ha=(0,K.useRef)([]);Ha.current=c;let Ua=(0,K.useRef)(u);Ua.current=u,Va.current=H,(0,K.useEffect)(()=>{let e=a?.activeId;if(!e)return;let t=window.setTimeout(()=>Zt(e,u),400);return()=>window.clearTimeout(t)},[u,a?.activeId]),(0,K.useEffect)(()=>{let e=()=>{let e=Y.current?.activeId;e&&Zt(e,Ua.current)},t=()=>{document.visibilityState===`hidden`&&e()};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t)}},[]);function X(e){Y.current=e,o(e),qt(e)}let Wa=a?.sessions.find(e=>e.id===a.activeId),Ga=Wa?.id,qa=Wa?.access;(0,K.useEffect)(()=>{Ga&&tt(qa??Qe())},[Ga,qa]),(0,K.useEffect)(()=>{let e=!1,t=Xe(()=>n($e())),r=h(e=>ft(e)),a=Je(e=>{Un(e),Ze(e)});return(async()=>{if(await s(),e)return;let t=qe();Un(t),Ze(t),n($e()),tt(Qe()),ft(p()),ot(Rt());let r=new URLSearchParams(window.location.search),a=r.get(`session`),c=await At({preferSessionId:a});if(e)return;let u=c;if(a&&!u.sessions.some(e=>e.id===a))try{let e=sessionStorage.getItem(zt(a));if(e){let t=JSON.parse(e)?.session;t&&t.id===a&&(u={...u,sessions:[t,...u.sessions.filter(e=>e.id!==a)],activeId:a},await Lt(u))}}catch{}if(a)try{sessionStorage.removeItem(zt(a))}catch{}let f=r.get(`focusRoot`),m=r.get(`focusPath`),h=r.get(`attachRoot`),_=r.get(`attachPath`),v=r.get(`attachName`),y=null;if(f&&m)try{y=`${f}:${decodeURIComponent(m).replace(/\\/g,`/`).replace(/^\/+/,``)}`}catch{y=`${f}:${m}`}if(a){let e=u.sessions.find(e=>e.id===a);Vt(e)&&(u=Tt(u,a),qt(u))}if(y&&ge(y),h&&_){let e=h;if(e===`cases`||e===`prompts`||e===`knowledge`||e===`templates`){let t=_,n=v||``;try{t=decodeURIComponent(_).replace(/\\/g,`/`).replace(/^\/+/,``),v&&(n=decodeURIComponent(v))}catch{}n||=t.split(`/`).pop()||t;let r=(n.split(`.`).pop()||`md`).toLowerCase(),i=e===`cases`?`用例`:e===`prompts`?`提示词`:e===`knowledge`?`知识库`:`模板`;x([{collection:e,id:`${e}:${t}`,title:n,category:i,path:t,format:r}])}}let b=r.get(`report`);try{let e=new URL(window.location.href);e.searchParams.delete(`report`),e.searchParams.delete(`session`),e.searchParams.delete(`focusRoot`),e.searchParams.delete(`focusPath`),e.searchParams.delete(`attachRoot`),e.searchParams.delete(`attachPath`),e.searchParams.delete(`attachName`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}catch{}let S=[];try{S=(await Yr()).map(e=>e.sessionId)}catch{S=[]}let w=new Set(S);u=w.size?{...u,sessions:u.sessions.map(e=>{if(w.has(e.id))return e;let t=wt(e.messages);return t===e.messages?e:{...e,messages:t}})}:bt(u);let T=Qe();u.sessions.some(e=>!e.access)&&(u={...u,sessions:u.sessions.map(e=>e.access?e:{...e,access:T})}),u=Gt(u,u.activeId,e=>!!nn(e).trim()||tn(e).length>0),Y.current=u,o(u),qt(u);let E=u.sessions.find(e=>e.id===u.activeId),O=E?Ad.get(E.id)?.messages:void 0;if(l(O??E?.messages??[]),O&&(Ha.current=O),d(e=>{let t=e.trim()?e:nn(u.activeId);return Po(t),t}),_i(tn(u.activeId)),k(E?.caseGen?.active?E.caseGen:null),se(E?.promptGen?.active?E.promptGen:null),ue(E?.knowledgeGen?.active?E.knowledgeGen:null),I(E?.pluginDev?.active?E.pluginDev:null),tt(E?.access??T),E?.pluginDev?.active&&(ui(`pluginDev`),E.access!==`readwrite`&&E.access!==`full`)){tt(`readwrite`);let e={...u,sessions:u.sessions.map(e=>e.id===u.activeId?{...e,access:`readwrite`}:e)};Y.current=e,o(e),qt(e)}Gr(Lo(E?.todos));{let e=os(E?.goal);q.current=e,qr(e)}if(ki(E),(b===`day`||b===`week`||b===`month`)&&p().reports){let e=Y.current?.sessions.find(e=>e.id===Y.current?.activeId);if((!e||e.archived||e.deleted||Array.isArray(e.messages)&&e.messages.length>0||e.caseGen?.active||e.promptGen?.active||e.knowledgeGen?.active||e.pluginDev?.active)&&Y.current){let e=Y.current.activeId,t=oo(e)??Y.current,n=Va.current?.workspace?.trim()||void 0,r=Bt(t,{workspacePath:n,access:Qe()});Y.current=r,o(r),qt(r),l([]),k(null),se(null),ue(null),I(null),ui(null),Gr([]),q.current=null,qr(null),ci(`off`),d(``),Po(``),_i([]),tt(Qe())}Qo(b)}E?.workspacePath&&Nn(e=>({...e,[E.workspacePath]:!0})),(E?.messages??[]).length||Vn(`dialog`);let ee=[...Ad.keys()],te=[...new Set([...S,...ee])];Ve(te),i(!0),te.length&&queueMicrotask(()=>{for(let e of te)yo(e,!0),e===Y.current?.activeId&&(Vr.current=!0,Ie(!0),Dr.current=Ad.get(e)?.abort??null,S.includes(e)&&!Ad.has(e)&&wo(e,0))});try{let e=new URL(window.location.href),t=e.searchParams.get(`plugin`);if(t===`promptGen`||t===`knowledgeGen`||t===`caseGen`||t===`pluginDev`){let n=t;if(p()[n]){let t=Y.current?.sessions.find(e=>e.id===Y.current?.activeId);if((!Vt(t)||Array.isArray(t.messages)&&t.messages.length>0||t.caseGen?.active||t.promptGen?.active||t.knowledgeGen?.active||n!==`pluginDev`&&t.pluginDev?.active)&&Y.current){let e=Y.current.activeId,t=oo(e)??Y.current,n=Va.current?.workspace?.trim()||H?.workspace?.trim()||void 0,r=Bt(t,{workspacePath:n,access:Qe()});Y.current=r,o(r),qt(r),l([]),k(null),se(null),ue(null),I(null),ui(null),Gr([]),q.current=null,qr(null),ci(`off`),d(``),Po(``),_i([]),tt(Qe())}if(n===`pluginDev`)Zo();else if(n===`promptGen`)oe(!0);else if(n===`knowledgeGen`)P(!0);else{let t=e.searchParams.get(`reqDoc`);t&&(ie({docId:t,storyIds:(e.searchParams.get(`stories`)??``).split(`,`).map(e=>e.trim()).filter(Boolean)}),e.searchParams.delete(`reqDoc`),e.searchParams.delete(`stories`)),D(!0)}}else B(g(n));e.searchParams.delete(`plugin`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}}catch{}(async()=>{try{if(!await ze(`prompts`)){z(`提示词管理服务未就绪,系统提示词暂时用内置兜底。`,`error`);return}let e=(await Re(`prompts`,ht)).content.trim();e?C(e):z(`「提示词管理/${ht}」是空的,系统提示词暂时用内置兜底。`,`error`)}catch{z(`没有读到「提示词管理/${ht}」,系统提示词暂时用内置兜底。`,`error`)}})(),Cr().then(e=>_t(e)),Sn().then(e=>{St(e),on(!0)}),$n().then(e=>gn(e)),ar().then(e=>xn(e)),Zn().then(e=>On(e)),un().then(e=>{kn(e),e?.workspace&&Nn(t=>({...t,[e.workspace]:!0}))})})(),()=>{e=!0,t(),r(),a()}},[]),(0,K.useEffect)(()=>{!V.memory&&U===`memory`&&Vn(`dialog`)},[V.memory,U]),(0,K.useEffect)(()=>{!V.todos&&U===`todos`&&Vn(`dialog`)},[V.todos,U]),(0,K.useEffect)(()=>{E(Su,U)},[U]),(0,K.useEffect)(()=>{if(!V.reports){mt(``);return}let e=!0;return(async()=>{try{await Rr(!0);let t=await zr();e&&mt(t),t||z(`工作汇报提示词没读到(提示词管理里为空或缺失),汇报不会注入提示词。`,`error`)}catch(e){let t=e instanceof Error?e.message:String(e);z(`读取工作汇报提示词失败:${t}`,`error`)}})(),()=>{e=!1}},[V.reports]),(0,K.useEffect)(()=>{if(!r)return;let e=!1,t=async()=>{if(!Y.current)return;let t=await Vs();if(e||!Y.current)return;let n=Y.current,r=!1;for(let e of t){let t=n.sessions.find(t=>t.id===e.sessionId)?.messages??[],i=`<!--tb-schedule:${e.id}-->`;if(!t.some(t=>t.scheduleId===e.id||typeof t.content==`string`&&t.content.includes(i))){let t={role:`assistant`,content:zs(e.text,e.id),time:Date.now(),scheduleId:e.id};n=Ht(n,e.sessionId,t),e.sessionId===n.activeId&&(r=!0)}try{typeof Notification<`u`&&Notification.permission===`granted`&&new Notification(`Lantern Harness 定时提醒`,{body:e.text})}catch{}}let i=await kt();if(!e&&Y.current){if(i){let e=Mt(n,i);e!==n&&(n=e,n.activeId&&(r=!0))}if((n!==Y.current||t.length)&&X(n),r){let e=n.sessions.find(e=>e.id===n.activeId);l(e?.messages??[])}}};t();let n=window.setInterval(()=>{t()},1e4);return()=>{e=!0,window.clearInterval(n)}},[r]),(0,K.useEffect)(()=>{if(!r||!G||!H)return;let e=a?.sessions.find(e=>e.id===a.activeId);Qa(e)},[r,G,a?.activeId,H?.items]),(0,K.useEffect)(()=>{let e=e=>{if(e.key!==`Shift`||e.repeat||e.ctrlKey||e.metaKey||e.altKey)return;let t=document.activeElement;t instanceof HTMLElement&&t!==document.body&&(t.tagName===`TEXTAREA`||t.tagName===`INPUT`||t.tagName===`SELECT`||t.isContentEditable||t.blur())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,K.useEffect)(()=>{Jn(0),Qn(!1)},[Ma?.query,Ma?.from]),(0,K.useEffect)(()=>{rr(!1),R(0)},[Ia?.from]),(0,K.useEffect)(()=>{R(e=>La.length?Math.min(e,La.length-1):0)},[La.length]),(0,K.useEffect)(()=>{if(!Fa||!ja){ja||_r([]);return}let e=!1;return wn(et,{maxDepth:3,maxEntries:80}).then(t=>{e||_r(t)}),()=>{e=!0}},[Fa,ja,et,H?.workspace]),(0,K.useEffect)(()=>{if(!Fa)return;let e=Ta.current;e&&e.querySelector(`[data-mention-index="${qn}"]`)?.scrollIntoView({block:`nearest`})},[qn,Fa,J.length]),(0,K.useEffect)(()=>{if(!Ra)return;let e=Ea.current;e&&e.querySelector(`[data-plugin-index="${L}"]`)?.scrollIntoView({block:`nearest`})},[L,Ra,La.length]),(0,K.useEffect)(()=>{if(!Fa&&!Ra&&!ir)return;function e(e){let t=e.target;Ta.current?.contains(t)||Ea.current?.contains(t)||Da.current?.contains(t)||ya.current?.contains(t)||e.target?.closest?.(`[data-add-menu-btn]`)||(Qn(!0),rr(!0),sr(!1))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Fa,Ra,ir]),(0,K.useEffect)(()=>{if(!He||We!==`ok`)return;function e(e){let t=e.target;Oa.current?.contains(t)||B(null)}let t=window.setTimeout(()=>{document.addEventListener(`pointerdown`,e,!0)},0);return()=>{window.clearTimeout(t),document.removeEventListener(`pointerdown`,e,!0)}},[He,We]),(0,K.useEffect)(()=>{if(!zn&&!we)return;function e(e){let t=e.target;t?.closest?.(`[data-session-menu]`)||t?.closest?.(`[data-ws-menu]`)||(Bn(null),Te(null))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[zn,we]);function Ja(){Cr().then(e=>_t(e)),Sn().then(e=>{St(e),on(!0)}),$n().then(e=>gn(e)),ar().then(e=>xn(e)),Zn().then(e=>On(e)),un().then(e=>kn(e))}function Ya(e){kn(e),Nn(t=>({...t,[e.workspace]:!0}))}async function Xa(e,t=`select`){if(G&&!An){jn(!0),B(null);try{Ya(t===`add`?await cn(e):await Tn(e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{jn(!1)}}}function Za(e){let t=Va.current;if(!t)return null;let n=e?.workspacePath?.trim();return n&&(n===t.harnessRoot||t.items.some(e=>e.path===n))?n:t.projectRoot?.trim()||null}async function Qa(e){if(!G||An)return;let t=Za(e);if(!t)return;let n=Va.current;if(n&&t!==n.workspace){jn(!0);try{Ya(await Tn(t))}catch{}finally{jn(!1)}}}async function $a(e){if(!G||An)return;await Xa(e.path,`select`);let t=Y.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId);n&&!n.workspacePath&&((n.messages??[]).length>0||(X(Dt(t,n.id,e.path)),Nn(t=>({...t,[e.path]:!0}))))}async function eo(){if(G&&!An){jn(!0),B(null);try{let e=await fn();if(!e)return;Ya(await cn(e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{jn(!1)}}}async function no(){let e=Ee;if(e&&G&&!An){if(e.id===`ws_project`)De(null);else{De(null),Te(null),jn(!0),B(null);try{Y.current&&X(xt(Y.current,e.path));let t=await bn(e.id);Ya(t),t.projectRoot&&Nn(e=>({...e,[t.projectRoot]:!0}))}catch(e){B(e instanceof Error?e.message:String(e))}finally{jn(!1)}}}}function ro(e){G&&!An&&e.id!==`ws_project`&&(Bn(null),Te(null),De(e))}async function io(e){let t=Ne;if(Pe(null),t&&G){jn(!0),B(null);try{Ya(await _n(t,e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{jn(!1)}}}function ao(e){let t=Aa.current[e];return!!(t&&(t.input?.trim()||(t.attachments?.length??0)>0||(t.images?.length??0)>0||(t.docRefs?.length??0)>0)||nn(e).trim()||tn(e).length>0)}function oo(e){if(!e||!Y.current)return Y.current;let t=Y.current.sessions.find(t=>t.id===e);return!t||!jt(t)||ao(e)?Y.current:(delete Aa.current[e],en(e),Xt(e,[]),Ut(Y.current,e))}function lo(e){if(!Y.current)return Y.current;let t=Y.current,n=Gt(t,e,ao);if(n===t||n.sessions.length===t.sessions.length)return n;for(let e of t.sessions)n.sessions.some(t=>t.id===e.id)||(delete Aa.current[e.id],en(e.id),Xt(e.id,[]));return n}function uo(e){Ma&&(e.collection!==`workspace`&&!br?B(g(`knowledge`)):b.length>=yu?B(`最多引用 ${yu} 篇文档`):(B(null),x(t=>t.some(t=>t.collection===e.collection&&t.path===e.path)?t:[...t,{collection:e.collection,id:e.id,title:e.title,category:e.category,path:e.path,format:e.format}].slice(0,yu)),d(u.slice(0,Ma.from).replace(/\s+$/,``)),Qn(!0),ya.current?.focus()))}function fo(){Ia&&(d(u.slice(0,Ia.from).replace(/\s+$/,``)),rr(!0))}function po(e){if(!V[e])return B(g(e)),!1;if(B(null),e===`caseGen`)return D(!0),!0;if(e===`promptGen`)return oe(!0),!0;if(e===`knowledgeGen`)return P(!0),!0;if(e===`pluginDev`)return Zo(),!0;if(e===`memory`)return Vn(`memory`),!0;if(e===`knowledge`){let e=u.replace(/\s+$/,``);return d(e?`${e} @`:`@`),Qn(!1),requestAnimationFrame(()=>ya.current?.focus()),!0}return!1}function mo(e){fo(),po(e)}function ho(){let e=_a.current;if(!e)return;let t=e.scrollHeight-e.clientHeight-e.scrollTop<=48;if(Ba.current){if(!t)return;Ba.current=!1}za.current=t,rt(!t)}function vo(){let e=_a.current;e&&(za.current=!0,Ba.current=!0,rt(!1),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))}(0,K.useEffect)(()=>{if(!r||!Y.current)return;let e=Y.current.sessions.find(e=>e.id===Y.current.activeId)?.messages??[],t=JSON.stringify(e)!==JSON.stringify(c),n=Ct(Y.current,c,{touchUpdatedAt:t});if(Y.current=n,o(n),qt(n),za.current&&!Ba.current){let e=_a.current;e&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{za.current&&!Ba.current&&_a.current===e&&e.scrollTo({top:e.scrollHeight})})})}},[c,r]),(0,K.useEffect)(()=>{let e=()=>{Y.current&&qt(Y.current)};return window.addEventListener(`pagehide`,e),()=>window.removeEventListener(`pagehide`,e)},[]),(0,K.useLayoutEffect)(()=>{let e=ya.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,280)}px`)},[u]),(0,K.useEffect)(()=>{if(!r||!he||!c.length)return;let e=he,t=window.setTimeout(()=>{let t=(_a.current??document).querySelector(`[data-focus-doc="${CSS.escape(e)}"]`);t instanceof HTMLElement&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`),window.setTimeout(()=>{t.classList.remove(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`)},2400)),ge(null)},80);return()=>window.clearTimeout(t)},[r,he,c]);function yo(e,t){Ve(n=>{let r=n.includes(e);return t&&!r?[...n,e]:!t&&r?n.filter(t=>t!==e):n}),Y.current?.activeId===e&&(Vr.current=t,Ie(t))}function bo(e){e&&(Or.current.get(e)?.abort.abort(),jr.current.get(e)?.(),jr.current.delete(e),Zr(e))}function Co(e,t){if(t.type===`reasoning`&&t.delta)To(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=at((r.reasoning??``)+t.delta),a=[...r.activitySteps??[]],o=a.findIndex(e=>e.kind===`thinking`),s={id:`thinking`,kind:`thinking`,title:`思考`,detail:Fu(i).replaceAll(`**`,``).slice(0,80)||void 0,status:`running`};o>=0?a[o]={...a[o],...s}:a.unshift(s);let c=n.slice(),l=Pr.current.get(e),u=r.ttftMs;return l&&l.firstToken==null&&(l.firstToken=Date.now(),u=Math.max(0,l.firstToken-l.start)),c[c.length-1]={...r,reasoning:i,activitySteps:a,turnStatus:`running`,ttftMs:u},c});else if(t.type===`content`&&t.delta)To(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=(r.activitySteps??[]).map(e=>e.kind===`thinking`&&e.status===`running`?{...e,status:`done`}:e),a=n.slice(),o=Pr.current.get(e),s=r.ttftMs;return o&&o.firstToken==null&&(o.firstToken=Date.now(),s=Math.max(0,o.firstToken-o.start)),a[a.length-1]={...r,content:at((r.content??``)+t.delta),activitySteps:i,turnStatus:`running`,ttftMs:s},a});else if(t.type===`tool`&&t.name){let n=Au(t.name),r=Pu(t.name,t.args),i=`tool_${t.name}_${t.args?.slice(0,24)??``}`;Ao(e,i,t.status);let a=t.status===`done`&&typeof t.result==`string`&&/^\s*\{\s*"error"\s*:/.test(t.result);To(e,e=>{let o=e[e.length-1];if(o?.role!==`assistant`)return e;let s=[...o.activitySteps??[]],c=s.findIndex(e=>e.id===i||e.detail===r&&e.title===n&&e.status===`running`),l={id:i,kind:Mu(t.name),title:n,detail:r||void 0,status:t.status===`running`?`running`:a?`error`:`done`};c>=0?s[c]={...s[c],...l}:s.push(l);let u=e.slice();return u[u.length-1]={...o,activitySteps:s,turnStatus:`running`},u}),Y.current?.activeId===e&&W(Iu(qe().toolStepDetail,n,t.name,t.status===`running`?`running`:`done`))}else if(t.type===`usage`&&t.usage)To(e,e=>{let n=e[e.length-1];if(n?.role!==`assistant`)return e;let r=e.slice();return r[r.length-1]={...n,usage:t.usage},r});else if(t.type===`status`){let n=t.status;(n===`completed`||n===`stopped`||n===`error`)&&(To(e,e=>{let r=e[e.length-1];if(r?.role!==`assistant`)return e;let i=t.assistant,a=e.slice(),o=typeof i?.toolMs==`number`?i.toolMs:void 0,s=typeof i?.llmMs==`number`?i.llmMs:void 0,c=typeof i?.ttftMs==`number`?i.ttftMs:void 0,l=typeof i?.tps==`number`?i.tps:void 0;return a[a.length-1]={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:(i?.activitySteps??r.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e),turnStatus:n===`completed`?`completed`:`stopped`,time:Date.now(),usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,toolMs:o==null?r.toolMs:Math.max(o,r.toolMs??0),llmMs:s??r.llmMs,ttftMs:c??r.ttftMs,tps:l??r.tps},a}),n===`error`&&t.error&&Y.current?.activeId===e&&B(ju(t.error)),Or.current.delete(e),kr.current===e&&(kr.current=null),yo(e,!1),Y.current?.activeId===e&&W(null))}}function wo(e,t=0){Or.current.has(e)||(jr.current.get(e)?.(),yo(e,!0),(async()=>{let n=await Qr(e),r=t;if(n?.ok&&n.assistant){if(r=Math.max(r,n.seq??0),To(e,e=>{let t=e[e.length-1],r=t?.role===`assistant`?t:{role:`assistant`,content:``,turnStatus:`running`},i=n.assistant,a={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:i?.activitySteps??r.activitySteps,turnStatus:n.status===`completed`?`completed`:n.status===`stopped`||n.status===`error`?`stopped`:`running`,usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,llmMs:typeof i?.llmMs==`number`?i.llmMs:r.llmMs,ttftMs:typeof i?.ttftMs==`number`?i.ttftMs:r.ttftMs,toolMs:typeof i?.toolMs==`number`?Math.max(i.toolMs,r.toolMs??0):r.toolMs,tps:typeof i?.tps==`number`?i.tps:r.tps};if(t?.role===`assistant`){let t=e.slice();return t[t.length-1]=a,t}return[...e,a]}),n.status&&n.status!==`running`&&n.status!==`waiting_user`){yo(e,!1);return}}else if(n&&n.ok===!1){yo(e,!1);return}let i=ti(e,r,{onEvent:t=>Co(e,t),onGaveUp:t=>{Or.current.has(e)||(Y.current?.activeId===e&&B(t.message||`与服务端回合断开`),yo(e,!1))}});jr.current.set(e,i)})())}function To(e,t,n){let r=Or.current.get(e),i=Y.current?.sessions.find(t=>t.id===e)?.messages??[],a=r?.messages??(Y.current?.activeId===e?Ha.current:i),o=typeof t==`function`?t(a):t;r&&(r.messages=o),Y.current?.activeId===e&&(Ha.current=o,l(o)),Y.current&&X(yt(Y.current,e,o,{touchUpdatedAt:n?.touchUpdatedAt!==!1}))}function ko(e){let t=kr.current??Y.current?.activeId;t&&To(t,t=>{let n=t[t.length-1];if(n?.role!==`assistant`)return t;let r=t.slice();return r[r.length-1]=e(n),r})}function Ao(e,t,n){let r=`${e}:${t}`;if(n===`running`){Nr.current.set(r,Date.now());return}if(n!==`done`&&n!==`error`)return;let i=Nr.current.get(r);if(Nr.current.delete(r),i==null)return;let a=Math.max(0,Date.now()-i);To(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,toolMs:(t.toolMs??0)+a},n})}async function jo(e){if(!e.length)return;let t=[],n=[],r=Du(f,v);for(let i of e)if(r+t.length>=6)n.push(`${i.name||`图片`}(最多 6 个文件)`);else try{t.push(await Eu(i))}catch(e){n.push(e instanceof Error?e.message:String(e))}t.length&&y(e=>[...e,...t].slice(0,6)),B(n.length?`以下图片未添加:${n.join(`、`)}`:null)}function Mo(e){let t=vi;if(!t)return;let n={...t,body:e,at:Date.now()};_i(e=>{let t=e.map(e=>e.id===n.id?n:e);return Xt(Y.current?.activeId,t),t}),yi(null)}function Po(e){xa.current={stack:[e],index:0}}function Fo(e){if(Sa.current)return;let t=xa.current;if(t.stack[t.index]===e)return;let n=t.stack.slice(0,t.index+1);n.push(e),n.length>80&&n.shift(),xa.current={stack:n,index:n.length-1}}function Io(){let e=xa.current;e.index<=0||(Sa.current=!0,--e.index,d(e.stack[e.index]??``),Sa.current=!1)}function Ho(){let e=xa.current;e.index>=e.stack.length-1||(Sa.current=!0,e.index+=1,d(e.stack[e.index]??``),Sa.current=!1)}function Uo(e){Qt(Y.current?.activeId,e),_i(t=>t.filter(t=>t.id!==e)),yi(t=>t?.id===e?null:t),(e.startsWith(`case-fix:`)||e.startsWith(`case-batch-fix:`)||e.startsWith(`blindspot-writeback:`))&&x(e=>e.filter(e=>e.collection!==`cases`))}function Wo(){Po(``),d(``),m([]),y([]),x([]),_i([]),Xt(Y.current?.activeId,[]),Qn(!1),rr(!1)}function Jo(){if(li===`plan`&&(Ms(),ci(`off`)),li===`pluginDev`){I(null),pe.current=null,Y.current&&X(It(Y.current,{pluginDev:void 0}));let e=me.current;me.current=null,e===`readonly`&&(tt(`readonly`),Y.current&&X(It(Y.current,{access:`readonly`})))}ui(null)}function Yo(){ui(`goal`),requestAnimationFrame(()=>ya.current?.focus())}function Xo(){ii===`off`?Di(`planning`,null):ui(`plan`),requestAnimationFrame(()=>ya.current?.focus())}function Zo(){G?(ui(`pluginDev`),et===`readonly`&&(me.current=`readonly`,tt(`readwrite`),Y.current&&X(It(Y.current,{access:`readwrite`}))),requestAnimationFrame(()=>ya.current?.focus())):B(`本地文件服务未就绪:插件开发需要读写项目源码`)}function Qo(e){fi(e),ui(`reports`),window.setTimeout(()=>ya.current?.focus(),400)}function es(e){return e.filter(e=>e.role===`user`||e.role===`assistant`).map(e=>({role:e.role,content:typeof e.content==`string`?e.content:``,reasoning:e.reasoning}))}async function ts(e){if(!t)return Ye(`model`),!1;let n=es(Ha.current);if(n.length<4)return B(`对话轮次较少,无需压缩`),!1;W(`正在压缩上下文…`);try{let{messages:r,compacted:i}=await ns(t,n,{force:e.force,signal:e.signal});if(!i)return W(null),B(`当前上下文未超过阈值,未压缩`),!1;let a=Date.now(),o=r.map((e,t)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:a+t}));return Ha.current=o,l(o),Y.current&&X(Ct(Y.current,o,{touchUpdatedAt:!0})),W(null),!0}catch(e){return W(null),e instanceof DOMException&&e.name===`AbortError`||B(e instanceof Error?e.message:String(e)),!1}}function is(e){let t=[`请根据以下需求生成测试用例`],n=e.reqSource;return n?.kind===`stories`?t.push(`(来源:${e.docTitle||`用户故事`},共 ${n.storyIds.length} 条故事)`):n?.kind===`doc`&&t.push(`(来源文档:${e.docTitle||n.path.split(`/`).pop()||n.path})`),e.testPointIds?.length&&t.push(`,参考 ${e.testPointIds.length} 条测试点`),e.templateTitle&&t.push(`,按「${e.templateTitle}」模板输出`),t.push(`。`),t.join(``)}async function as(e,n){let r=e===void 0,i=r&&li===`reports`?`生成${Br[di]}`:``,a=r&&ee.current?.active&&V.caseGen?is(ee.current):``,o=r?$t(mi):``,s=r?mi.filter(e=>e.body.trim()).map(e=>({id:e.id,label:e.label.trim()||`任务要求`,detail:e.detail,body:e.body})):[],c=(e??u).trim()||i||a,l=o?c?`${c}\n\n${o}`:o:c,d=s.length&&c||void 0,p=r?f:[],m=r?b:[],h=r?v:[];if(!l&&!p.length&&!m.length&&!h.length)return;if(!t){Ye(`model`);return}let g=r&&li===`reports`?di:V.reports?sl(c):null;if(g&&V.reports)try{let e=g===`week`&&Yc(c)?-1:0,t=await ol(g,{todos:!!V.todos,tasks:!!V.tasks,testStats:!!V.testStats,caseExec:!!V.caseExec},new Date,{weekOffset:e});t&&(l=`${l}\n\n${t}`,d||=c||Br[g])}catch{}if(r&&li===`reports`&&ui(null),rs(l)&&!p.length&&!m.length&&!h.length){if(Vr.current){B(`请等待当前回复结束后再压缩`);return}r&&Wo(),await ts({force:!0})&&B(null);return}if(li===`goal`&&l&&!p.length&&!m.length&&!h.length&&!us(l)&&!rs(l)){r&&Wo();let e={text:l.slice(0,500),status:`active`,updatedAt:Date.now()};q.current=e,qr(e),$r.current=0,Y.current&&X(It(Y.current,{goal:e})),ui(null),B(`已设定目标:${e.text}`);return}if(us(l)&&!p.length&&!m.length&&!h.length){let e=ls(l);if(r&&Wo(),!e)return;if(e.kind===`show`){let e=Kr;B(e&&e.status!==`cleared`?`当前目标(${e.status}):${e.text}`:`当前无会话目标。可用 /goal set <内容> 设定`);return}if(e.kind===`clear`){q.current=null,qr(null),$r.current=0,Y.current&&X(It(Y.current,{goal:void 0})),B(`已清除会话目标`);return}if(e.kind===`done`){if(!Kr?.text){B(`当前无目标可标记完成`);return}let e={...Kr,status:`done`,updatedAt:Date.now()};q.current=e,qr(e),$r.current=0,Y.current&&X(It(Y.current,{goal:e})),B(`已标记目标完成:${e.text}`);return}if(e.kind===`set`&&e.text){let t={text:e.text.slice(0,500),status:`active`,updatedAt:Date.now()};q.current=t,qr(t),$r.current=0,Y.current&&X(It(Y.current,{goal:t})),B(`已设定目标:${t.text}`);return}return}if(li===`pluginDev`&&l&&!p.length&&!m.length&&!h.length){if(Vr.current){B(`请等待当前回复结束后再开始插件开发`);return}await Es(l)}let _={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:l,...d?{displayContent:d}:{},...s.length?{taskCards:s}:{},files:[...p],refs:[...m],imgs:[...h]};if(Vr.current){let e=qe().busySendBehavior??`queue`;if((n?.forceBusy??e)===`queue`){pa([...da.current,_]),r&&Wo();return}fa.current=_,r&&Wo(),bo(Y.current?.activeId)}else await ds(_)}async function ds(n){let r=Y.current?.activeId;if(!t||!r||Or.current.has(r))return;let{content:i,displayContent:a,taskCards:o,files:s,refs:c,imgs:u}=n;ps(i)||($r.current=0),B(null);let d=Date.now(),f={role:`user`,content:i,time:d};a&&(f.displayContent=a),o?.length&&(f.taskCards=o),s.length&&(f.attachments=s),c.length&&(f.refs=c),u.length&&(f.images=u);let p=Ha.current,m=p[p.length-1];m?.role===`assistant`&&!m.content&&!m.reasoning&&(p=p.slice(0,-1));let h=[...p,f],g=new AbortController,_=Ge();if($o(es(h),t.model,_.contextWindow)){W(`上下文较长,正在压缩…(可在右下角中断)`);try{let{messages:e,compacted:n}=await ns(t,es(h),{force:!1,signal:g.signal,contextWindow:_.contextWindow});if(n){let t=Date.now();h=e.map((e,n)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:t+n})),Ha.current=h,l(h),Y.current&&X(Ct(Y.current,h,{touchUpdatedAt:!0}))}}catch{}W(null)}let v=[...h,{role:`assistant`,content:``,time:d,turnStatus:`running`}];Ha.current=v,l(v),Wo(),kr.current=r,Or.current.set(r,{abort:g,messages:v}),Dr.current=g,yo(r,!0),za.current=!0,rt(!1);let y=Mi(h.map(e=>{let t={role:e.role,content:wu(e,{supportsVision:_.supportsVision})},n=(e.reasoningApi??e.reasoning)?.trim();return e.role===`assistant`&&n&&(t.reasoning_content=n),t}),{keepRecentImageMessages:1}),b=vr,x=br,C=G,w=xr,T=!!V.todos,E=!!V.tasks,D=!!V.projects,O=!!V.iterations,te=!!V.pmRequirements,ne=!!V.bugs,re=ii===`planning`,A=V.pluginDev&&pe.current?.active?pe.current:null,j=A?et===`full`?`full`:`readwrite`:re?`readonly`:et,ie=Tr&&j!==`readonly`,ae=Er&&j!==`readonly`,M=Va.current?.workspace?.trim()||``,oe=M?`\n当前工作区:${M}`:``,N=V.promptGen&&ce.current?.active?ce.current:null,le=!N&&V.knowledgeGen&&de.current?.active?de.current:null,P=!N&&!le&&V.caseGen&&ee.current?.active?ee.current:null,F=!!(N||le||P),fe=M,I=S;if(A)I=ba(A,Va.current?.harnessRoot||Va.current?.projectRoot||M);else if(N)I=Xi(N);else if(le)I=ma(le);else if(P){if(!P.promptBody?.trim()){B(`生成测试用例已启用,但未选择提示词。请打开插件重新「确认」。`),Or.current.delete(r),kr.current=null,Dr.current=null,yo(r,!1),l(e=>e[e.length-1]?.role===`assistant`&&!e[e.length-1]?.content?e.slice(0,-1):e);return}try{I=Me(P,P.docTitle||P.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``)}catch(e){B(e instanceof Error?e.message:String(e)),Or.current.delete(r),kr.current=null,Dr.current=null,yo(r,!1);return}}if(!F){let e=pt;if(!A&&!e.trim()&&V.reports)try{await Rr(!0),e=await zr()}catch{}!A&&e.trim()&&(I=`${I}\n\n${e.trim()}`);let t=No({lastUserMessageAt:[...h].reverse().find(e=>e.role===`user`&&e!==h[h.length-1])?.time??[...h].reverse().find(e=>e.role===`user`)?.time??null,lastInjectAt:Fr.current});if(t.injected&&(Fr.current=t.at),I=`${I}\n\n${t.text}`,C)try{let e=await yn();e?.text&&(I=`${I}\n\n${Cn}\n\n${e.text}`)}catch{}}let me=[];if(!F&&!A&&_.supportsTools)try{me=wr(await Ar())}catch{me=[]}let he=mu(I,y,{memory:b&&!F,knowledge:x&&!F,fs:C&&!F,web:w&&!F,bash:ie&&!F,pwsh:ae&&!F,interact:!F,todos:T&&!F,tasks:E&&!F,projects:D&&!F,iterations:O&&!F,pmRequirements:te&&!F,bugs:ne&&!F,planPhase:F||A?`off`:ii,goalEnabled:!F,goal:Kr,scheduleEnabled:!F,subagentEnabled:!F,workflowEnabled:!F,mcpEnabled:me.length>0}).map((e,t)=>t===0&&e.role===`system`&&C&&oe&&!F?{...e,content:`${typeof e.content==`string`?e.content:``}${oe}`}:e);if(b&&!F&&!A){W(`记忆注入中…`);let{context:e}=await Ir(i,{cwd:fe});if(e&&he[0]?.role===`system`){let t=typeof he[0].content==`string`?he[0].content:``;he=[{...he[0],content:`${t}\n\n${e}`},...he.slice(1)]}W(null)}let ge=_.supportsTools?Rc({access:j,planPhase:F||A?`off`:ii,planGatesWrites:re,structuredPlugin:F,mcpTools:me,caps:{knowledge:x,fs:C,web:w,bash:ie,pwsh:ae,memory:b,todos:T,tasks:E,projects:D,iterations:O,pmRequirements:te,bugs:ne,subagent:!F,workflow:!F,interact:!F,goal:!F,schedule:!F,mcp:me.length>0}}):[],L=Date.now(),R=0;Pr.current.set(r,{start:L});let _e=0,ve=!1,ye=``,be=!1,xe,z=!!(N||le||P),Se={index:1,total:1,label:``};function Ce(e){return N?Zi(e):le?ha(e):Oe(e,Se.total>1?{index:Se.index,total:Se.total,label:Se.label}:void 0)}function we(){return N?`正在编写提示词…`:le?`正在编写知识库…`:`正在编写用例…`}let Te=!1;try{let n=``,i=``,a=``;if(z){W(we());let e=()=>{let e=Math.max(0,Math.floor((Date.now()-L)/1e3));ko(t=>({...t,content:Ce(e)}))};e(),xe=window.setInterval(e,1e3)}if(!(T||E||D||O||te||ne)&&!z&&!A&&await Jr(g.signal)){let e=Bc(ge);(await Xr({sessionId:r,messages:he,settings:{baseURL:t.baseURL,apiKey:t.apiKey,model:t.model,reasoningEffort:t.reasoningEffort},tools:e,thinking:!0,workspace:M||``,access:j})).ok&&(Te=!0,await new Promise(e=>{let t=!1,n=()=>{t||(t=!0,e())},i=()=>{Zr(r)};g.signal.addEventListener(`abort`,i),jr.current.get(r)?.();let a=ti(r,0,{signal:g.signal,onEvent:e=>Co(r,e),onTerminal:e=>{be=e.status===`completed`,g.signal.removeEventListener(`abort`,i),jr.current.delete(r),n()},onGaveUp:e=>{Y.current?.activeId===r&&B(e.message||`与服务端回合断开`),To(r,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),g.signal.removeEventListener(`abort`,i),jr.current.delete(r),n()}});jr.current.set(r,()=>{a(),n()})}))}if(!Te){if(P&&Li(P).length>1){let e=Li(P);Se.total=e.length,Se.index=1,Se.label=e[0]?.label??``;let n=P.docTitle||P.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``,r={memory:!1,knowledge:!1,fs:!1,web:!1,bash:!1,pwsh:!1,interact:!1,todos:!1,tasks:!1,projects:!1,iterations:!1,pmRequirements:!1,bugs:!1,planPhase:`off`,goalEnabled:!1,goal:null,scheduleEnabled:!1,subagentEnabled:!1,workflowEnabled:!1,mcpEnabled:!1},i=[],a;for(let o of e){if(g.signal.aborted)throw new DOMException(`Aborted`,`AbortError`);Se.index=o.index,Se.total=o.total,Se.label=o.label,W(`正在编写用例(第 ${o.index}/${o.total} 批)…`);{let e=Math.max(0,Math.floor((Date.now()-L)/1e3));ko(t=>({...t,content:Ce(e)}))}let e=zi(P,o),s=mu(Me(e,n,{index:o.index,total:o.total,pointCount:o.ids.length}),y,r),c=``,l=ct(t,s,g.signal,{thinking:!0});for await(let e of l)if(e.type===`usage`){let n=Date.now();a=a?{promptTokens:a.promptTokens+e.usage.promptTokens,completionTokens:a.completionTokens+e.usage.completionTokens,totalTokens:a.totalTokens+e.usage.totalTokens,cachedTokens:(a.cachedTokens??0)+(e.usage.cachedTokens??0),uncachedTokens:(a.uncachedTokens??0)+(e.usage.uncachedTokens??0),cacheWriteTokens:(a.cacheWriteTokens??0)+(e.usage.cacheWriteTokens??0)}:{...e.usage};let r=pd(a),i=R?(n-R)/1e3:0,o=i>.2&&r>0?r/i:void 0;ko(e=>({...e,usage:a,tps:o,model:t.model,ttftMs:R?R-L:e.ttftMs,llmMs:n-L}))}else R===0&&(e.type===`content`||e.type===`reasoning`||e.type===`reasoning_api`)&&(R=Date.now(),ko(e=>({...e,ttftMs:R-L,model:t.model}))),e.type===`reasoning_api`?ko(t=>({...t,reasoningApi:e.content})):e.type===`reasoning`?(_e===0&&(_e=Date.now()),ye+=e.delta):e.type===`content`&&(c+=e.delta);i.push({index:o.index,total:o.total,raw:c})}xe!=null&&(window.clearInterval(xe),xe=void 0),be=!0,W(`正在检测覆盖并入库…`);let o=await ke(i,P,n);if(ko(e=>({...e,content:o.summary,caseFile:o.ok?{path:o.path,name:o.path.split(`/`).pop()||o.path,count:o.count}:void 0,usage:a??e.usage,llmMs:Date.now()-L,reasoningDuration:_e>0?Math.max(1,Math.round((Date.now()-_e)/1e3)):e.reasoningDuration})),o.ok&&Y.current){let e={...P,active:!1,linkedCasePath:o.path};k(e),ee.current=e,X(It(Y.current,{caseGen:e}))}}else{let o=ct(t,he,g.signal,{tools:ge.length?ge:void 0,runTool:ge.length?Uc(async(n,i)=>{Gn(!0);let a=Au(n);W(Iu(qe().toolStepDetail,a,n,`running`));let o=Date.now();try{if(n.startsWith(`kb_`))return await Ic(n,i,{base:`/`,docs:e});if(n.startsWith(`fs_`)){let e=await mn(n,i,j),t=Do(n,e);if(t&&Y.current){let e=Eo(Y.current.sessions.find(e=>e.id===r)?.workspaceChanges,t);X(Ft(Y.current,r,{workspaceChanges:e}))}return e}if(n.startsWith(`skill_`))return await wa(n,i);if(n===`load_workspace_dependencies`)return await Oi(n);if(n===`office_to_pdf`)return re?JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`}):await wi(n,i,j);if(n.startsWith(`workspace_changes_`)){let e=Y.current?.sessions.find(e=>e.id===r),{text:t,next:i}=Oo(n,e?.workspaceChanges);return i&&Y.current&&X(Ft(Y.current,r,{workspaceChanges:i})),t}if(n.startsWith(`working_directory_`)){let{text:e,info:t}=await sn(n,i);return t&&(Ya(t),n===`working_directory_set`&&Y.current&&X(Ft(Y.current,r,{workspacePath:t.workspace}))),e}if(n===`present`){if(re)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await pn(i,j);try{let t=JSON.parse(e);t.ok&&t.files?.length&&ko(e=>{let n=e.presentFiles??[],r=new Map(n.map(e=>[e.path,e]));for(let e of t.files)r.set(e.path,e);return{...e,presentFiles:[...r.values()]}})}catch{}return e}if(n===`todo_add`){if(re)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e;try{e=JSON.parse(i||`{}`).items}catch{e=void 0}let t=au(`todo`,e);if(!t.length)return JSON.stringify({error:`没有可记录的待办:只有用户明确要求记录待办时才调用 todo_add,并给出待办标题;不要为了弹出卡片而调用工具。`});let n=await so(t),r=await aa(`todo`,n.items,{quick:!0,quickNote:n.willCreateRoutine?`确认后会创建任务「日常待办」并关联,状态 / 日期已自动填好`:void 0});if(!r)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增待办,未写入任何数据。`});let a;try{a=await co(r)}catch(e){return JSON.stringify({error:`创建所属任务失败:${e instanceof Error?e.message:String(e)}`})}i=JSON.stringify({items:ou(`todo`,a)})}if(n===`task_add`){if(re)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=au(`task`,go(i));e.length||e.push(iu(`task`));let t=await aa(`task`,e);if(!t)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增任务,未写入任何数据。`});i=JSON.stringify({items:ou(`task`,t)})}if(n.startsWith(`task_`)){let e=await _o(n,i,{sessionId:r});if(n===`task_add`)try{let t=JSON.parse(e);t.ok&&t.count&&B(`已创建 ${t.count} 个任务,可在侧栏「任务管理」查看。`,`ok`)}catch{}return e}if(n.startsWith(`todo_`)&&n!==`todo_write`){if(re&&n!==`todo_list`)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await to(n,i,{sessionId:r});if(n===`todo_add`)try{let t=JSON.parse(e);t.ok&&t.count&&B(`已记录 ${t.count} 条待办,可在侧栏「待办事项」查看。`,`ok`)}catch{}return e}if(n===`todo_write`){let e;try{e=JSON.parse(i||`{}`).todos}catch{return JSON.stringify({error:`invalid JSON arguments`})}let t=Lo(e);return Y.current?.activeId===r&&Gr(t),Y.current&&X(Ft(Y.current,r,{todos:t})),JSON.stringify({ok:!0,count:t.length,todos:t})}if(n.startsWith(`pm_`)){if(re&&!n.endsWith(`_list`))return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await Ka(n,i,{sessionId:r});if(n.endsWith(`_add`))try{let t=JSON.parse(e);if(t.ok&&t.count){let e=n.startsWith(`pm_project_`)?`项目列表`:n.startsWith(`pm_iteration_`)?`迭代管理`:n.startsWith(`pm_requirement_`)?`需求管理`:`缺陷管理`,r=n.startsWith(`pm_iteration_`)?`迭代`:n.startsWith(`pm_requirement_`)?`条需求`:n.startsWith(`pm_bug_`)?`条缺陷`:`个项目`;B(`已创建 ${t.count} ${r},可在侧栏「${e}」查看。`,`ok`)}}catch{}return e}if(n.startsWith(`goal_`)){if(n===`goal_get`)return ss(Y.current?.activeId===r?q.current:os(Y.current?.sessions.find(e=>e.id===r)?.goal));if(n===`goal_set`){let e=``;try{e=String(JSON.parse(i||`{}`).text??``).trim()}catch{return JSON.stringify({error:`invalid JSON arguments`})}if(!e)return JSON.stringify({error:`text is required`});let t={text:e.slice(0,500),status:`active`,updatedAt:Date.now()};return Y.current?.activeId===r&&(q.current=t,qr(t),$r.current=0),Y.current&&X(Ft(Y.current,r,{goal:t})),ss(t)}if(n===`goal_done`){let e=Y.current?.activeId===r?q.current:os(Y.current?.sessions.find(e=>e.id===r)?.goal);if(!e?.text)return JSON.stringify({ok:!1,error:`no goal to complete`});let t={...e,status:`done`,updatedAt:Date.now()};return Y.current?.activeId===r&&(q.current=t,qr(t),$r.current=0),Y.current&&X(Ft(Y.current,r,{goal:t})),ss(t)}return n===`goal_clear`?(Y.current?.activeId===r&&(q.current=null,qr(null),$r.current=0),Y.current&&X(Ft(Y.current,r,{goal:void 0})),JSON.stringify({ok:!0,goal:null})):JSON.stringify({error:`unknown tool: ${n}`})}if(n.startsWith(`schedule_`))return await Hs(n,i,r);if(n===`list_agents`||n===`spawn_subagent`||n===`fork_subagent`||n.startsWith(`subagent_`))return await gc(n,i,{settings:bi(t,qe().subagentModel),sessionId:r,parentSignal:g.signal,access:j,fsEnabled:C,webEnabled:w,parentMessages:y,onHint:e=>W(e),runFs:(e,t,n)=>mn(e,t,n),runWeb:(e,t)=>mr(e,t)});if(n===`workflow`)return await kc(n,i,{settings:t,sessionId:r,parentSignal:g.signal,access:j,fsEnabled:C,webEnabled:w,parentMessages:y,onHint:e=>W(e),runFs:(e,t,n)=>mn(e,t,n),runWeb:(e,t)=>mr(e,t)});if(n===`ask_user_question`){let e=Ro(i);if(!e.length)return JSON.stringify({error:`questions is required`});let t={};for(let n of e)t[n.id]={selected:[],text:``};return Pi(t),Ii(0),Bi(!1),Hi(null),Wi(!1),qi(``),ji(e),await new Promise((e,t)=>{Hr.current={resolve:e,reject:t};let n=Dr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),js()};n?.signal.addEventListener(`abort`,r)})}if(n===`submit_plan`){let e=Go(i);return e?(Di(`planning`,e,r),await new Promise((e,t)=>{Ur.current={resolve:e,reject:t};let n=Dr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),Ms()};n?.signal.addEventListener(`abort`,r)})):JSON.stringify({error:`title and steps are required`})}return n===`bash`?await er(i,j):n===`pwsh`?await or(i,j):n.startsWith(`bash_session_`)?await pr(n,i,j):n.startsWith(`pwsh_session_`)?await lr(n,i,j):n.startsWith(`job_`)?await tr(n,i,j):n.startsWith(`web_`)?await mr(n,i):n.startsWith(`memory_`)?await gr(n,i,fe):n.startsWith(`mcp__`)?await yr(n,i):JSON.stringify({error:`unknown tool: ${n}`})}finally{let e=Math.max(0,Date.now()-o);ko(t=>({...t,toolMs:(t.toolMs??0)+e})),Gn(!1),Ja()}}):void 0});for await(let e of o){if(e.type===`tool`){let t=Au(e.name);W(Iu(qe().toolStepDetail,t,e.name,e.status===`running`?`running`:`done`));let n=Pu(e.name,e.args),r=`tool_${e.name}_${e.args?.slice(0,24)??``}`,i=e.status===`done`&&typeof e.result==`string`&&/^\s*\{\s*"error"\s*:/.test(e.result);ko(a=>{let o=[...a.activitySteps??[]],s=o.findIndex(e=>e.id===r||e.detail===n&&e.title===t&&e.status===`running`),c={id:r,kind:Mu(e.name),title:t,detail:n||void 0,status:e.status===`running`?`running`:i?`error`:`done`};return s>=0?o[s]={...o[s],...c}:o.push(c),{...a,activitySteps:o}});continue}if(e.type===`usage`){let n=Date.now(),r=R?(n-R)/1e3:0,i=pd(e.usage),a=r>.2&&i>0?i/r:void 0;ko(r=>({...r,usage:e.usage,tps:a,model:t.model,ttftMs:R?R-L:r.ttftMs,llmMs:n-L}));continue}if(R===0&&(R=Date.now(),ko(e=>({...e,ttftMs:R-L,model:t.model}))),e.type===`reasoning_api`){ko(t=>({...t,reasoningApi:e.content}));continue}e.type===`reasoning`&&_e===0&&(_e=Date.now());let r=e.type===`content`&&_e>0&&!ve;if(r&&(ve=!0),z){if(e.type===`content`?N?i+=e.delta:le?a+=e.delta:n+=e.delta:e.type===`reasoning`&&(ye+=e.delta),r){let e=Math.max(0,Math.floor((Date.now()-L)/1e3));ko(t=>({...t,content:Ce(e),reasoningDuration:Math.max(1,Math.round((Date.now()-_e)/1e3))}))}}else e.type===`reasoning`&&(ye+=e.delta),ko(t=>{let n=e.type===`reasoning`?{...t,reasoning:at(ye)}:{...t,content:at(t.content+e.delta)};if(e.type===`reasoning`){let e=[...n.activitySteps??[]],t=e.findIndex(e=>e.kind===`thinking`),r={id:`thinking`,kind:`thinking`,title:`思考`,detail:Fu(n.reasoning??``).replaceAll(`**`,``).slice(0,80)||void 0,status:`running`};t>=0?e[t]={...e[t],...r}:e.unshift(r),n.activitySteps=e}if(r){n.reasoningDuration=Math.max(1,Math.round((Date.now()-_e)/1e3));let e=[...n.activitySteps??[]],t=e.findIndex(e=>e.kind===`thinking`);t>=0&&(e[t]={...e[t],status:`done`}),n.activitySteps=e}return n})}if(be=!0,!z){let e=[...Y.current?.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`);if(e&&typeof e.content==`string`&&!e.content.trim()){let t=typeof e.reasoning==`string`&&!!e.reasoning.trim(),n=(e.activitySteps??[]).some(e=>e.kind===`tool`||e.kind===`fs`);B(t&&n?`模型已跑完工具并完成思考,但没有写出正文(常见于思考过长只想不写)。请回复「继续」补写结论,或缩小改动范围后重试`:t?`模型本轮只输出了思考、没有正文。请重试或回复「继续」`:`模型本轮没有返回正文(可能工具轮次用尽或输出被截断),请重试或回复「继续」`)}}{let e=_e>0&&!ve?Math.max(1,Math.round((Date.now()-_e)/1e3)):null;ko(t=>{let n=(t.activitySteps??[]).map(e=>e.kind===`thinking`&&e.status===`running`?{...e,status:`done`}:e),r={...t,activitySteps:n};return e!=null&&t.reasoning&&t.reasoningDuration==null&&(r.reasoningDuration=e),r})}if(xe!=null&&(window.clearInterval(xe),xe=void 0),N){W(`正在质检并入库…`);let e=await ea(i,N);if(ko(t=>({...t,content:e.summary,docsFile:e.ok?{root:`prompts`,path:e.path,name:e.path.split(`/`).pop()||e.title||e.path}:void 0})),e.ok&&Y.current){let t={...N,active:!1,linkedPromptPath:e.path};se(t),ce.current=t,X(It(Y.current,{promptGen:t}))}}else if(le){W(`正在质检并入库…`);let e=await va(a,le);if(ko(t=>({...t,content:e.summary,docsFile:e.ok?{root:`knowledge`,path:e.path,name:e.path.split(`/`).pop()||e.title||e.path,note:e.category}:void 0})),e.ok&&Y.current){let t={...le,active:!1,linkedKnowledgePath:e.path};ue(t),de.current=t,X(It(Y.current,{knowledgeGen:t}))}}else if(P){W(`正在检测覆盖并入库…`);let e=P.docTitle||P.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``,t=await je(n,P,e);if(ko(e=>({...e,content:t.summary,caseFile:t.ok?{path:t.path,name:t.path.split(`/`).pop()||t.path,count:t.count}:void 0})),t.ok&&Y.current){let e={...P,active:!1,linkedCasePath:t.path};k(e),ee.current=e,X(It(Y.current,{caseGen:e}))}}}}Te&&be&&ko(e=>({...e,turnStatus:e.turnStatus===`stopped`?`stopped`:`completed`,activitySteps:(e.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)}))}catch(e){e instanceof DOMException&&e.name===`AbortError`||Y.current?.activeId===r&&B(e instanceof Error?e.message:String(e)),To(r,e=>{let t=e[e.length-1];if(t?.role===`assistant`&&!t.content&&!t.reasoning&&!t.activitySteps?.length)return e.slice(0,-1);if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n})}finally{xe!=null&&(window.clearInterval(xe),xe=void 0);let e=Date.now(),n=Pr.current.get(r),a=R||n?.firstToken||0;ko(n=>{let r=n.llmMs??e-L,i=n.ttftMs??(a?a-L:void 0),o=i==null?0:Math.max(0,(r-i)/1e3),s=pd(n.usage),c=n.tps??(o>.2&&s>0?s/o:void 0);return{...n,time:e,model:n.model??t.model,llmMs:r,ttftMs:i,tps:c,turnStatus:n.turnStatus===`stopped`||n.turnStatus===`completed`?n.turnStatus:be?`completed`:(g.signal.aborted||!Te)&&n.turnStatus===`running`?`stopped`:n.turnStatus,activitySteps:(n.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)}}),Pr.current.delete(r),Or.current.delete(r),jr.current.get(r)?.(),jr.current.delete(r),kr.current===r&&(kr.current=null),Dr.current===g&&(Dr.current=null),yo(r,!1);{let e=qe().toolStepDetail;e===`full`?window.setTimeout(()=>W(null),2800):e===`detailed`?window.setTimeout(()=>W(null),1200):W(null)}if(be&&b&&Lr(i,fe).finally(()=>{Ja()}),be&&Y.current){let e=[...Y.current.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`),n=hi({userContent:i,assistantContent:typeof e?.content==`string`?e.content:``,reasoning:e?.reasoning});n.length&&gi({sessionId:r,model:e?.model??t.model,messages:n})}if(be&&t&&!g.signal.aborted&&Y.current){let e=Y.current.sessions.find(e=>e.id===r),n=e?.messages??[];if(e&&!ei.current.has(r)&&ri(e.title,n)){let e=ni(n);e&&(ei.current.add(r),ai(t,e).then(e=>{if(!e||!Y.current)return;let t=Y.current.sessions.find(e=>e.id===r);t&&ri(t.title,t.messages)&&X(Jt(Y.current,r,e))}))}}let o=Y.current?.activeId===r,s=null;if(o){s=fa.current,fa.current=null,!s&&da.current.length&&(s=da.current[0],pa(da.current.slice(1)));let e=cs(q.current);if(!s&&!F&&ms({goalActive:!!e,turnOk:be,aborted:g.signal.aborted,hasFollowUp:!1,askUserPending:!!Hr.current,roundsUsed:$r.current,maxRounds:3})){let t=$r.current+1;$r.current=t,s={id:`goal_drv_${Date.now().toString(36)}`,content:fs(e,t,3),files:[],refs:[],imgs:[]}}}s&&window.setTimeout(()=>{ds(s)},0)}}function hs(){fa.current=null,pa([]),$r.current=0;let e=Y.current?.activeId;e&&To(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),bo(e)}function gs(e){pa(da.current.filter(t=>t.id!==e))}function _s(e){let t=da.current.find(t=>t.id===e);t&&(gs(e),d(t.content),m(t.files),y(t.imgs),x(t.refs),requestAnimationFrame(()=>ya.current?.focus()))}function vs(e){let t=da.current.find(t=>t.id===e);t&&(pa(da.current.filter(t=>t.id!==e)),Vr.current?(fa.current=t,bo(Y.current?.activeId)):ds(t))}function ys(e){let t=[...da.current],n=e??t.shift()??null;n&&(pa(t),Vr.current?(fa.current=n,bo(Y.current?.activeId)):ds(n))}function bs(e,t){let n=!(c[e]?.reasoningOpen??!1);if(l(t=>t.map((t,n)=>n===e?{...t,reasoningOpen:!t.reasoningOpen}:t)),n){let e=t.currentTarget;requestAnimationFrame(()=>{(e.nextElementSibling??e).scrollIntoView({block:`nearest`,behavior:`smooth`})})}}function xs(e){e&&(u.trim()||f.length>0||v.length>0||b.length>0?Aa.current[e]={input:u,attachments:f,images:v,docRefs:b}:delete Aa.current[e],Zt(e,u))}function Cs(e){let t=e?Aa.current[e]:void 0,n=t?.input??nn(e);Po(n),d(n),m(t?.attachments??[]),y(t?.images??[]),x(t?.docRefs??[]),_i(tn(e))}function ws(e){e?.abortRun!==!1&&bo(Y.current?.activeId),Vr.current=!1,Ie(!1),m([]),y([]),x([]),_i([]),yi(null),Po(``),d(``),B(null),rt(!1),za.current=!0,e?.clearDraft&&Y.current?.activeId&&(delete Aa.current[Y.current.activeId],en(Y.current.activeId))}function Ts(e,t){if(!Y.current)return;ye(!1),Vn(`dialog`);let n=Y.current.activeId,r=Y.current.sessions.find(e=>e.id===n),i=!!r&&!r.archived&&!r.deleted&&(!Array.isArray(r.messages)||r.messages.length===0),a=n=>({...n,title:n.title?.trim()||`新对话`,caseGen:e===`caseGen`?t:void 0,promptGen:e===`promptGen`?t:void 0,knowledgeGen:e===`knowledgeGen`?t:void 0,updatedAt:Date.now()}),o;if(i&&n)ws({clearDraft:!0,abortRun:!1}),o={...Y.current,activeId:n,sessions:Y.current.sessions.map(e=>e.id===n?a(e):e)};else{xs(n),ws({clearDraft:!0,abortRun:!1});let e=oo(n)??Y.current,t=H?.workspace?.trim()||void 0;o=Bt(e,{workspacePath:t,access:Qe()});let r=o.activeId;o={...o,sessions:o.sessions.map(e=>e.id===r?a(e):e)}}X(o),l([]),k(e===`caseGen`?t:null),ee.current=e===`caseGen`?t:null,se(e===`promptGen`?t:null),ce.current=e===`promptGen`?t:null,ue(e===`knowledgeGen`?t:null),de.current=e===`knowledgeGen`?t:null,(e===`caseGen`||e===`promptGen`||e===`knowledgeGen`)&&d(``);let s=o.sessions.find(e=>e.id===o.activeId)?.workspacePath||H?.workspace?.trim()||H?.projectRoot;s&&Nn(e=>({...e,[s]:!0})),Qa(o.sessions.find(e=>e.id===o.activeId));let c=()=>ya.current?.focus();requestAnimationFrame(c),window.setTimeout(c,320)}async function Es(e){let t=Y.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId),r=Va.current?.harnessRoot?.trim()||Va.current?.projectRoot?.trim()||Va.current?.workspace?.trim(),i=n?.pluginDev?.active?n.pluginDev:{active:!0,requirement:e.trim(),confirmedAt:Date.now()};if(X(It(t,{pluginDev:i,access:et===`full`?`full`:`readwrite`,...r?{workspacePath:r}:{}})),I(i),pe.current=i,me.current=null,Ms(),ci(`off`),r&&Nn(e=>({...e,[r]:!0})),G&&r&&Va.current?.workspace!==r)try{Ya(await Tn(r))}catch{}}function Ds(e){if(e?.active){Ts(`caseGen`,e);return}let t=ee.current,n=t?.linkedCasePath?{...t,active:!1}:void 0;k(n??null),ee.current=n??null,Y.current&&X(It(Y.current,{caseGen:n}))}function Os(e){if(e?.active){Ts(`promptGen`,e);return}let t=ce.current,n=t?.linkedPromptPath?{...t,active:!1}:void 0;se(n??null),ce.current=n??null,Y.current&&X(It(Y.current,{promptGen:n}))}function ks(e){if(e?.active){Ts(`knowledgeGen`,e);return}let t=de.current,n=t?.linkedKnowledgePath?{...t,active:!1}:void 0;ue(n??null),de.current=n??null,Y.current&&X(It(Y.current,{knowledgeGen:n}))}function As(e){if(ye(!1),!Y.current)return;Vn(`dialog`);let t=Y.current.activeId;xs(t),ws({clearDraft:!0,abortRun:!1});let n=oo(t)??Y.current;Y.current=n;let r=e?.trim()||H?.workspace?.trim()||void 0,i=Bt(n,{workspacePath:r,access:Qe()});Y.current=i,i=lo(i.activeId),X(i),l([]),k(null),se(null),ue(null),I(null),pe.current=null,Gr([]),q.current=null,qr(null),$r.current=0,ci(`off`),ui(e=>e===`pluginDev`?null:e),js(),Ms();let a=r||H?.projectRoot;a&&Nn(e=>({...e,[a]:!0})),Qa(i.sessions.find(e=>e.id===i.activeId))}function js(){let e=Hr.current;e&&(Hr.current=null,ji(null),Pi({}),Ii(0),Bi(!1),Hi(null),Wi(!1),qi(``),e.resolve(JSON.stringify({canceled:!0,error:`user aborted`})))}function Ms(){let e=Ur.current;e?(Ur.current=null,Di(ii===`off`?`off`:`planning`,null),e.resolve(JSON.stringify({approved:!1,canceled:!0}))):Ci&&Di(ii===`approved`?`approved`:`planning`,null)}function Ns(){let e=Ur.current;Ur.current=null,Di(`approved`,null),e?.resolve(JSON.stringify({approved:!0,message:`用户已批准计划,可以开始实施`}))}function Ps(){let e=Ur.current;Ur.current=null,Di(`planning`,null),e?.resolve(JSON.stringify({approved:!1,message:`用户驳回了计划,请修订后再次 submit_plan`}))}function Fs(){ii===`off`?Di(`planning`,null):(Ms(),Di(`off`,null))}function Is(e,t){return!e||!t?!1:t.skipped||t.text.trim()!==``?!0:e.options?.length?t.selected.length>0:!1}function Ls(e,t,n){let r=Hr.current;if(!r)return;Hr.current=null,ji(null),Pi({}),Ii(0),Bi(!1),Hi(null),Wi(!1),qi(``),B(null);let i=t.filter(e=>e.skipped).length,a=String(n?.skipReason??``).trim();r.resolve(JSON.stringify({answers:t,summary:Vo(e,t),...i?{skipped:!0,approvalRequired:!0,...a?{skipReason:a}:{},note:`用户跳过了部分或全部问题:跳过的题不算确认,也未批准实施。`+(a?`用户给出的跳过原因:${a}。`:``)+`本轮只允许只读调研与文字方案,禁止 fs_write / fs_mkdir / 改配置;请先说明采用的默认假设(哪几项按推荐)与准备改动的范围`+(a?`,并针对上述原因给出调整`:``)+`,然后等用户明确回复「开始实施」再动手。`}:{note:`answers 为结构化答案;summary 是同一批答案的中文文本版本,可直接据此继续,无需再次提问。`},...n}))}function Rs(e,t,n){Pi(r=>{let i=r[e.id]??{selected:[],text:``},a=e.multi_select?n?i.selected.filter(e=>e!==t):[...i.selected,t]:[t];return{...r,[e.id]:{selected:a,text:``,skipped:!1}}}),Hi(null),e.multi_select||Ii(e=>Math.min(e+1,(Ai?.length??1)-1))}function Bs(e){let t=Ai?.length??0;t&&(Ii(Math.max(0,Math.min(e,t-1))),Hi(null))}function Us(e,t){e&&(Pi(n=>{let r=n[e.id]??{selected:[],text:``};return{...n,[e.id]:{selected:e.multi_select?r.selected:[],text:t,skipped:!1}}}),Hi(null))}function Ws(e,t){let n=t.trim(),r=n&&e.options?.length?zo(e,n):null,i=r?{selected:r,text:``,skipped:!1}:{selected:e.multi_select?Ni[e.id]?.selected??[]:[],text:n,skipped:!1},a={...Ni,[e.id]:i};Pi(a),Hi(null),Zc?Ks(a):Bs(Jc+1)}function Gs(e){return(Ai??[]).map(t=>{let n=Bo(t,e[t.id]??{selected:[],text:``});return n.skipped||n.text?.trim()||n.selected?.length?n:{id:t.id,selected:[],skipped:!0}})}function Ks(e=Ni,t=!1){let n=Ai;if(!n?.length||!Hr.current)return!1;let r=Gs(e),i=r.findIndex(e=>!e.skipped&&!e.text?.trim()&&!e.selected?.length);if(i>=0)return Bs(i),Hi(n[i]?.options?.length?`请先选择选项再提交`:`请先填写回答再提交`),!1;if(!t&&r.some(e=>e.skipped))return Wi(!0),Hi(null),!1;let a=Gi.trim();return Ls(n,r,a?{skipReason:a}:void 0),!0}function qs(){let e=Ai,t=Z;if(!e?.length||!t)return;let n={...Ni,[t.id]:{selected:[],text:``,skipped:!0}};Pi(n),Hi(null),Zc?Ks(n):Bs(Jc+1)}function Js(){Ks(Ni,!0)}function Ys(){Wi(!1);let e=Gs(Ni).findIndex(e=>e.skipped);Bs(e>=0?e:0)}function Xs(e){if(!Y.current)return;Bn(null),Te(null);let t=Y.current.activeId;xs(t),js(),Ms(),ci(`off`),B(null);let n=oo(t)??Y.current;Y.current=n;let r=new Set(n.sessions.map(e=>e.id)),i=Wt(n,e,{activate:!0}),a=i.sessions.find(e=>!r.has(e.id));if(!a)return;let o=a.id;X(i);let s=i.sessions.find(e=>e.id===o),c=s?.messages??[];Ha.current=c,l(c),Vr.current=!1,Ie(!1),Dr.current=null,k(s?.caseGen?.active?s.caseGen:null),se(s?.promptGen?.active?s.promptGen:null),ue(s?.knowledgeGen?.active?s.knowledgeGen:null),I(s?.pluginDev?.active?s.pluginDev:null),pe.current=s?.pluginDev?.active?s.pluginDev:null,Gr(Array.isArray(s?.todos)?s.todos:[]),q.current=s?.goal??null,qr(s?.goal??null),$r.current=0,Di(`off`,null,o),ui(null),Cs(o);let u=s?.workspacePath||H?.projectRoot;u&&Nn(e=>({...e,[u]:!0})),Qa(s)}function Zs(e){if(ye(!1),!Y.current||(Vn(`dialog`),Bn(null),e===Y.current.activeId))return;let t=Y.current.activeId;if(xs(t),js(),Ur.current){let e=Ur.current;Ur.current=null,e.resolve(JSON.stringify({approved:!1,canceled:!0,reason:`switched session`}))}Ei(t,ii,Ci),B(null),rt(!1),za.current=!0;let n=oo(t)??Y.current;Y.current=n,n=lo(e),Y.current=n,n.sessions.some(t=>t.id===e)||(n=Y.current);let r=Tt(n,e),i=r.sessions.find(t=>t.id===e),a=Or.current.get(e)?.messages??i?.messages??[];Ha.current=a,l(a);let o=Or.current.has(e)||Le.includes(e);Vr.current=o,Ie(o),Dr.current=Or.current.get(e)?.abort??null,o&&!Or.current.has(e)&&!jr.current.has(e)&&wo(e,0),k(i?.caseGen?.active?i.caseGen:null),se(i?.promptGen?.active?i.promptGen:null),ue(i?.knowledgeGen?.active?i.knowledgeGen:null),I(i?.pluginDev?.active?i.pluginDev:null),ui(e=>i?.pluginDev?.active?`pluginDev`:e===`pluginDev`?null:e),Gr(Lo(i?.todos));{let e=os(i?.goal);q.current=e,qr(e),$r.current=0}ki(i),Cs(e),X(r),Qa(i)}function Qs(e){if(!Y.current)return;Bn(null),Te(null);let t=Y.current.activeId===e;t&&ws({clearDraft:!0}),delete Aa.current[e],en(e),Xt(e,[]);let n=Ut(Y.current,e);if(X(n),t){let e=n.sessions.find(e=>e.id===n.activeId);l(e?.messages??[]),k(e?.caseGen?.active?e.caseGen:null),se(e?.promptGen?.active?e.promptGen:null),ue(e?.knowledgeGen?.active?e.knowledgeGen:null),I(e?.pluginDev?.active?e.pluginDev:null),ui(t=>e?.pluginDev?.active?`pluginDev`:t===`pluginDev`?null:t)}}function $s(e,t){if(!Y.current)return;Bn(null);let n=Y.current.activeId===e&&t;n&&ws();let r=Pt(Y.current,e,t);if(X(r),n){let e=r.sessions.find(e=>e.id===r.activeId);l(e?.messages??[])}}function ec(e){if(!Y.current)return;let t=Y.current.sessions.find(t=>t.id===e);t&&(Bn(null),X(Et(Y.current,e,!t.pinned)))}function tc(e){Y.current&&Y.current.sessions.some(t=>t.id===e)&&(Bn(null),Te(null),xe(e))}function nc(){let e=Y.current?.activeId,t=Y.current?.sessions.find(t=>t.id===e);t?B(pi(`stats`,t.id,t.updatedAt,()=>si(oi(t))),`ok`):B(`无活跃会话可统计`)}function rc(e){Y.current&&be&&(ei.current.add(be),X(Jt(Y.current,be,e)),xe(null))}function ic(){ot(e=>(Ot(!e),!e))}async function ac(e){let t=Array.from(e.target.files??[]);e.target.value=``,await cc(t)}function oc(){let t=e.map(e=>({collection:e.collection,path:e.path,title:e.title,category:e.category,format:String(e.format)})),n=hr.map(e=>({collection:`workspace`,path:e.path,title:e.name,category:En(H?.workspace,H?.projectRoot),format:e.type===`dir`?`dir`:`file`}));return[...t,...n]}function sc(e){e.length&&x(t=>{let n=[...t];for(let t of e){if(n.length>=yu)break;n.some(e=>e.collection===t.collection&&e.path===t.path)||n.push(t)}return n})}async function cc(e,t){let n=[],r=[],i=[],a=Du(f,v);for(let o of e)if(a>=6)i.push(`${o.name}(最多 6 个文件)`);else try{let e=await _l(o);e.kind===`image`?r.push(await Eu(e.file)):n.push({name:e.name,size:e.size,content:e.content,path:t?.get(o.name)||t?.get(e.name)}),a+=1}catch(e){i.push(e instanceof Error?e.message:String(e))}n.length&&m(e=>[...e,...n]),r.length&&y(e=>[...e,...r]),B(i.length?`以下文件未添加:${i.join(`、`)}`:null),ya.current?.focus()}function lc(e){let t=e.clipboardData;if(!t)return;let n=Array.from(t.items??[]),r=n.filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.filter(e=>e.kind===`file`&&!e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e);for(let e of Array.from(t.files??[]))e.type.startsWith(`image/`)?r.some(t=>t.name===e.name&&t.size===e.size)||r.push(e):i.some(t=>t.name===e.name&&t.size===e.size)||i.push(e);let a=El(t),o=(t.getData(`text/plain`)||``).trim(),s=oc(),c=En(H?.workspace,H?.projectRoot),l={projectRoot:H?.projectRoot,workspace:H?.workspace,workspaceLabel:c},u=[],d=new Map;for(let e of a){let t=kl(e,l);t?(u.push(t),d.set(bl(e),t.path)):d.set(bl(e),e)}let f=null;!r.length&&!i.length&&!a.length&&wl(o)&&(f=Al(o,s));let p=[],m=[];for(let e of i){let t=d.get(e.name),n=(t?kl(t,l):null)||Al(e.name,s);n?p.push(n):m.push(e)}(u.length>0||p.length>0||f||r.length>0||m.length>0)&&(e.preventDefault(),B(null),sc([...u,...p,...f?[f]:[]]),r.length&&jo(r),m.length&&cc(m,d),ya.current?.focus())}function uc(e){let t=e.target.closest(`[data-copy-code]`);t&&_d(t.closest(`.code-block`)?.querySelector(`pre`)?.textContent??``).then(e=>{e&&(t.textContent=`已复制`,window.setTimeout(()=>{t.textContent=`复制`},1e3))})}let dc=c.length===0,fc=!!(u.trim()||f.length||b.length||v.length||mi.length||li===`reports`||O?.active&&V.caseGen),pc=-1,mc=-1;c.forEach((e,t)=>{e.role===`user`?pc=t:e.role===`assistant`&&(mc=t)});let hc=e=>e===pc||e===mc?``:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity`,_c=ku.find(e=>e.value===et)??ku[0],vc=li===`pluginDev`,yc=(a?.sessions??[]).filter(e=>!e.archived&&!e.deleted),bc=(a?.sessions??[]).filter(e=>e.archived&&!e.deleted),xc=H?.items??[],Sc=new Set(xc.map(e=>e.path)),Cc=H?.workspace??``,wc=H?.projectRoot??``,Tc=a?.sessions.find(e=>e.id===a.activeId),Ec=Tc?.workspacePath,Dc=!Ec||!Sc.has(Ec),Oc=H?.workspace?.trim()||``,Mc=xc.find(e=>e.path===Oc),Nc=Mc?ln(Mc,wc):Oc?En(Oc,wc):`工作区`,Pc=Pn.trim().toLowerCase(),Fc=(0,K.useMemo)(()=>Pc?new Set(xo(a,Pn,{limit:50,includeArchived:!0}).map(e=>e.sessionId)):null,[Pc,a,Pn]),[Lc,zc]=(0,K.useState)(null);(0,K.useEffect)(()=>{if(!Pc){zc(null);return}let e=!1;return zc(null),So(Pn,{limit:50,includeArchived:!0}).then(t=>{!e&&t?.hits&&zc(new Set(t.hits.map(e=>e.sessionId)))}),()=>{e=!0}},[Pc,Pn]);let Vc=Lc??Fc,Hc=Vc?bc.filter(e=>Vc.has(e.id)):bc;function Wc(e){let t=e.id===`ws_project`||e.path===wc;return Kt(yc.filter(n=>!(n.workspacePath!==e.path&&(!t||n.workspacePath&&Sc.has(n.workspacePath)))).filter(e=>!Vc||Vc.has(e.id)))}let Gc=xc.filter(e=>!Pc||e.name.toLowerCase().includes(Pc)||e.path.toLowerCase().includes(Pc)?!0:Wc(e).length>0);function Kc({s:e,nested:t=!1}){let n=e.id===a?.activeId,r=zn===e.id,i=Le.includes(e.id);return(0,Q.jsx)(id,{s:e,nested:t,active:n,menuOpen:r,busy:i,onOpen:()=>Zs(e.id),onRename:()=>tc(e.id),onToggleMenu:()=>{Te(null),Bn(r?null:e.id)},onTogglePin:()=>ec(e.id),onToggleArchive:()=>$s(e.id,!e.archived),onExport:()=>{Bn(null);let t=Ss(e,`json`);B(t.ok?`已导出 ${t.filename}`:t.error)},onFork:()=>Xs(e.id),onRemove:()=>{Bn(null),Te(null),Ce(e.id)}})}let qc=Ai?.length??0,Jc=Math.max(0,Math.min(Fi,qc-1)),Z=Ai?.[Jc],Xc=Z&&Ni[Z.id]||{selected:[],text:``},Zc=Jc>=qc-1,Qc=Is(Z,Xc),$c=(Ai??[]).map((e,t)=>({q:e,index:t})).filter(({q:e})=>Ni[e.id]?.skipped);return(0,Q.jsxs)(`div`,{className:`tw-app h-full min-h-0 flex overflow-hidden bg-(--tw-surface-page)`,children:[(0,Q.jsxs)(`aside`,{className:`tw-session-rail shrink-0 border-r border-(--tw-border) flex flex-col transition-[width] ${it?`w-64`:`w-10`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 ${it?`px-2.5 pt-2.5`:`px-1 pt-2 justify-center`}`,children:[it&&(0,Q.jsx)(`div`,{className:`flex-1 min-w-0 text-[13px] font-medium text-stone-700 truncate px-1`,children:rn(`chat.workbench`,void 0,Hn.language)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":it?`收起侧栏`:`展开侧栏`,onClick:ic,className:`w-8 h-8 shrink-0 flex items-center justify-center rounded-lg text-stone-500 hover:bg-stone-200/70`,children:(0,Q.jsx)($,{className:`w-4 h-4`,children:it?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M9 3v18`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M15 3v18`})]})})})]}),it?(0,Q.jsxs)(`div`,{className:`px-2.5 pt-2 space-y-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>As(),className:`w-full h-9 flex items-center justify-center gap-1.5 text-[13px] font-medium text-stone-700 bg-white rounded-full border border-stone-200/80 shadow-sm hover:bg-stone-50 transition-colors`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]}),rn(`chat.newSession`,void 0,Hn.language)]}),(0,Q.jsxs)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>ye(e=>!e),className:`tw-rail-plugin-btn w-full h-9 flex items-center justify-center gap-1.5 text-[13px] font-medium rounded-full transition-colors ${_e?`is-active`:``}`,children:[(0,Q.jsx)($u,{className:`w-3.5 h-3.5`}),`插件`]})]}):(0,Q.jsxs)(`div`,{className:`px-1 pt-1 flex flex-col gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>As(),"data-hint":`新会话`,className:`w-8 h-8 flex items-center justify-center rounded-lg text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-4 h-4`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>ye(e=>!e),className:`tw-rail-plugin-btn tw-rail-plugin-btn--icon w-8 h-8 flex items-center justify-center rounded-lg ${_e?`is-active`:``}`,children:(0,Q.jsx)($u,{className:`w-4 h-4`})})]}),it&&(0,Q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-2 py-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5 pb-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 text-[12px] font-semibold text-stone-500`,children:rn(`chat.workspace`,void 0,Hn.language)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`搜索`,onClick:()=>{Rn(e=>!e),Ln&&In(``)},className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70`,children:(0,Q.jsx)(Ju,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":G?`添加工作区(选择本地文件夹)`:`本地文件服务未就绪`,disabled:!G||An,onClick:()=>void eo(),className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70 disabled:opacity-40`,children:(0,Q.jsx)(Yu,{className:`w-3.5 h-3.5`})})]}),Ln&&(0,Q.jsx)(`input`,{value:Pn,onChange:e=>In(e.target.value),placeholder:`搜索工作区 / 会话标题 / 消息`,className:`w-full mb-2 px-2.5 py-1.5 text-[12px] rounded-lg border border-stone-200 bg-white text-stone-700 placeholder:text-stone-400 focus:outline-none focus:ring-1 focus:ring-[#4176e6]/40`}),Sr&&(0,Q.jsx)(`div`,{className:`px-1.5 py-2 text-[11px] text-amber-700/80`,children:`本地文件服务未就绪,工作区暂不可用`}),(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[Gc.map(e=>{let t=Wc(e),n=!!(Mn[e.path]??t.length>0),r=e.id===`ws_project`||e.path===wc,i=!!(Tc&&(Dc?r:Ec===e.path)),a=we===e.id;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`tw-project-row group relative ${i?`is-active`:``} ${n?`is-expanded`:``} ${a?`is-menu-open`:``}`,children:[(0,Q.jsxs)(`button`,{type:`button`,"data-hint":e.path,onClick:t=>{t.stopPropagation(),Bn(null),Te(null),Nn(t=>({...t,[e.path]:!n})),G&&e.path!==Cc&&Xa(e.path,`select`)},className:`flex-1 min-w-0 h-full flex items-center gap-1.5 text-left outline-none focus:outline-none`,children:[(0,Q.jsx)(`span`,{className:`tw-slot tw-folder`,children:(0,Q.jsx)(Ku,{open:n,className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`span`,{className:`tw-slot tw-chevron`,children:(0,Q.jsx)(qu,{open:n,className:`w-3 h-3`})}),(0,Q.jsx)(`span`,{className:`tw-project-title`,children:ln(e,wc)})]}),(0,Q.jsxs)(`div`,{className:`tw-ws-actions relative shrink-0`,"data-ws-menu":``,children:[(0,Q.jsx)(nd,{open:a,onToggle:()=>{Bn(null),Te(a?null:e.id)},onRename:()=>{Bn(null),Te(null),Pe(e.id)},onDelete:e.id===`ws_project`?void 0:()=>ro(e)}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`在此工作区新建会话`,onClick:t=>{t.stopPropagation(),As(e.path)},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})})]})]}),(0,Q.jsx)(`div`,{className:`tw-collapse ${n?`is-open`:``}`,children:(0,Q.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5 pb-0.5`,children:t.map(e=>(0,Q.jsx)(Kc,{s:e,nested:!0},e.id))})})]},e.id)}),!Gc.length&&G&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-stone-400`,children:`暂无工作区`})]}),Hc.length>0&&(0,Q.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-stone-200/60`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>lt(e=>!e),className:`w-full flex items-center gap-1 px-1.5 pb-1 text-[11px] text-stone-400 hover:text-stone-600`,children:[(0,Q.jsx)(Lu,{className:`w-3 h-3 transition-transform ${st?`rotate-180`:``}`}),`已归档 (`,Hc.length,`)`]}),(0,Q.jsx)(`div`,{className:`tw-collapse ${st?`is-open`:``}`,children:(0,Q.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5`,children:Hc.map(e=>(0,Q.jsx)(Kc,{s:e},e.id))})})]})]}),it&&(Cc||Wn||Kn)&&(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-stone-200/60 px-3 py-2 space-y-1`,children:[Cc&&(0,Q.jsxs)(`div`,{className:`tw-rail-workspace-footer`,"data-hint":Cc,children:[(0,Q.jsx)(`span`,{className:`tw-rail-workspace-label`,"data-i18n":`chat.workspace`,children:`工作区`}),(0,Q.jsx)(`span`,{className:`tw-rail-workspace-name`,children:En(Cc,wc)})]}),(Wn||Kn)&&(0,Q.jsx)(`div`,{className:`text-[11px] text-(--tw-accent)`,children:Kn??rn(`tool.running`,void 0,Hn.language)})]})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col flex-1 ${_e?`hidden`:``}`,children:[dc?null:(0,Q.jsxs)(`div`,{className:`shrink-0 border-b border-(--tw-border) bg-(--tw-surface-page)`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 px-6 pt-4 pb-2 min-w-0`,children:(0,Q.jsx)(`button`,{type:`button`,"data-hint":`点击重命名`,onClick:()=>{let e=a?.activeId;e&&tc(e)},className:`min-w-0 flex-1 text-left text-[18px] leading-7 font-semibold text-(--tw-label-primary) truncate hover:text-[#4176e6] transition-colors`,children:a?.sessions.find(e=>e.id===a.activeId)?.title||`新对话`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-6 px-6`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Vn(`dialog`),className:`relative h-10 text-sm transition-colors ${U===`dialog`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`对话`,U===`dialog`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Vn(`thread`),className:`relative h-10 text-sm transition-colors ${U===`thread`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`回合`,U===`thread`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),V.memory&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Vn(`memory`),className:`relative h-10 text-sm transition-colors ${U===`memory`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`记忆`,(gt?.suggestionCount??0)>0?(0,Q.jsx)(`span`,{className:`min-w-4.5 h-4.5 px-1 inline-flex items-center justify-center rounded-full bg-red-500 text-[10px] font-medium text-white tabular-nums leading-none`,"data-hint":`${gt?.suggestionCount} 条待确认`,children:gt.suggestionCount>99?`99+`:gt.suggestionCount}):null]}),U===`memory`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),V.todos&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Vn(`todos`),className:`relative h-10 text-sm transition-colors ${U===`todos`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`待办`,U===`todos`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]})]}),Kr&&Kr.status!==`cleared`&&U===`dialog`?(0,Q.jsx)(`div`,{className:`px-6 pb-2`,children:(0,Q.jsxs)(`div`,{className:`rounded-xl border border-[#4176e6]/25 bg-[#f5f8ff] px-3 py-2 flex items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] font-medium text-[#4176e6] shrink-0 pt-0.5`,children:[`目标`,Kr.status===`done`?`·完成`:``]}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 text-[12px] leading-5 ${Kr.status===`done`?`text-stone-400 line-through`:`text-stone-800`}`,children:Kr.text}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`清除目标`,className:`text-[11px] text-stone-400 hover:text-stone-600 shrink-0`,onClick:()=>{q.current=null,qr(null),$r.current=0,Y.current&&X(It(Y.current,{goal:void 0}))},children:`清除`})]})}):null,Wr.length>0&&U===`dialog`?(0,Q.jsx)(`div`,{className:`px-6 pb-3`,children:(0,Q.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white px-3 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`text-[11px] font-medium text-stone-500 mb-1.5`,children:[`待办 · `,Wr.filter(e=>e.status===`completed`).length,`/`,Wr.length]}),(0,Q.jsx)(`ul`,{className:`space-y-1 max-h-28 overflow-y-auto`,children:Wr.map((e,t)=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-2 text-[12px] text-stone-700`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 w-3.5 h-3.5 rounded-sm border shrink-0 flex items-center justify-center text-[9px] ${e.status===`completed`?`bg-emerald-500 border-emerald-500 text-white`:e.status===`in_progress`?`border-[#4176e6] text-[#4176e6]`:`border-stone-300 text-transparent`}`,"aria-hidden":!0,children:e.status===`completed`?`✓`:e.status===`in_progress`?`…`:``}),(0,Q.jsx)(`span`,{className:e.status===`completed`?`line-through text-stone-400`:``,children:e.content})]},`${t}-${e.content}`))})]})}):null]}),U===`todos`&&V.todos?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Q.jsx)(nu,{})},`todos-${a?.activeId??``}`):U===`memory`&&V.memory?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Q.jsx)(Kl,{live:vr,pluginOn:!!V.memory,workspacePath:a?.sessions.find(e=>e.id===a.activeId)?.workspacePath||H?.projectRoot||``,onHealthChange:e=>_t(e)})},`memory-${a?.activeId??``}`):U===`thread`?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter overflow-y-auto px-4 py-3 sm:px-8 lg:px-12`,children:(0,Q.jsx)(wd,{messages:c,busy:!!(a?.activeId&&Le.includes(a.activeId)),onRestoreCheckpoint:(e,t)=>{let n=Y.current?.activeId;if(!n)return;if(Le.includes(n)||Fe){B(`请等待当前回复结束后再从此处继续`);return}let r=Math.max(0,Math.min(e,Ha.current.length-1)),i=Ha.current.slice(0,r+1);Ha.current=i,l(i),Y.current&&X(Ct(Y.current,i,{touchUpdatedAt:!0}));let a=`请从第 ${t} 轮继续`;Vn(`dialog`),d(a),B(`已回到第 ${t} 轮,正在继续…`,`ok`),window.setTimeout(()=>{as(a)},0)}})},`thread-${a?.activeId??``}`):(0,Q.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col${dc?` justify-center`:``}`,children:[dc?(0,Q.jsxs)(`div`,{className:`shrink-0 flex flex-col items-center text-center px-8 sm:px-10 lg:px-12 pb-8`,children:[(0,Q.jsx)(`img`,{src:`/brand/brand-mark.png`,alt:``,width:64,height:64,className:`w-16 h-16 rounded-[14px] object-contain`}),(0,Q.jsx)(`h2`,{className:`mt-5 text-[22px] leading-8 font-semibold tracking-tight text-stone-800 text-balance`,children:rn(`chat.emptyTitle`,void 0,Hn.language)})]}):null,dc?null:(0,Q.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,Q.jsx)(`div`,{ref:_a,onScroll:ho,className:`h-full overflow-y-auto px-8 sm:px-10 lg:px-12 py-6`,style:{fontSize:`var(--tw-session-font-size, ${Hn.sessionFontSize}px)`},children:(0,Q.jsx)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto flex flex-col gap-4`,onClick:uc,children:c.map((e,n)=>e.role===`user`?(0,Q.jsxs)(`div`,{className:`group flex flex-col items-end gap-1`,children:[e.taskCards?.length||e.refs?.length||e.attachments?.length||e.images?.length?(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-1.5 max-w-[82%]`,children:[e.taskCards?.map(t=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Si({id:t.id,label:t.label,detail:t.detail,body:t.body,at:e.time??Date.now()}),className:`flex items-center gap-1.5 rounded-lg border border-[#4176e6]/25 bg-[#edf3fe] py-1 pr-2.5 pl-2.5 text-xs text-[#4176e6] transition-colors hover:border-[#4176e6]/45`,children:[(0,Q.jsxs)($,{className:`h-3.5 w-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Q.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Q.jsx)(`path`,{d:`M8 13h8`}),(0,Q.jsx)(`path`,{d:`M8 17h5`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[10px] text-[#4176e6]/80`,children:`要求`}),(0,Q.jsx)(`span`,{className:`max-w-56 truncate text-left`,children:t.label}),t.detail?(0,Q.jsx)(`span`,{className:`max-w-40 truncate text-[10px] text-[#4176e6]/70`,children:t.detail}):null]},t.id)),e.refs?.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/30 rounded-lg`,"data-hint":e.collection===`workspace`?e.path:`${e.collection}/${e.path}`,children:[(0,Q.jsx)(Uu,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:e.collection===`workspace`?`工作区`:e.collection===`prompts`||e.collection===`cases`||e.collection===`knowledge`?e.category:Ac(e.format)}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.title})]},e.path)),e.attachments?.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-stone-600 bg-white border border-stone-200 rounded-lg`,children:[(0,Q.jsx)(Uu,{className:`w-3.5 h-3.5 text-[#4176e6]`}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-stone-400`,children:hd(e.size)})]},e.name)),e.images?.map(e=>(0,Q.jsx)(`a`,{href:e.dataUrl,target:`_blank`,rel:`noreferrer`,className:`block overflow-hidden rounded-lg border border-stone-200 bg-white`,"data-hint":e.name,children:(0,Q.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`max-h-40 max-w-48 object-contain`})},e.id))]}):null,(e.taskCards?.length?e.displayContent:e.displayContent||e.content)?(0,Q.jsx)(`div`,{className:`tw-chat-text max-w-[82%] px-4 py-2.5 bg-[#edf3fe] rounded-2xl whitespace-pre-wrap break-words`,children:e.taskCards?.length?e.displayContent:e.displayContent||e.content}):null,(0,Q.jsxs)(`div`,{className:`tw-msg-actions ${hc(n)}`,children:[e.time!=null&&(0,Q.jsx)(`span`,{className:`tw-msg-action-time pr-0.5`,children:gd(e.time)}),(0,Q.jsx)(vd,{text:e.content})]})]},n):(0,Q.jsxs)(`div`,{className:`group`,children:[e.turnStatus===`stopped`?(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`div`,{className:`text-[13px] text-stone-500 py-1`,children:`已停止`}),(0,Q.jsx)(`div`,{className:`border-t border-stone-200/80`})]}):null,(()=>{let t=e.activitySteps??[],r=t.some(e=>e.status===`running`),i=n===c.length-1&&e.turnStatus!==`stopped`&&(Fe||r),a=i&&!e.content,o=t.filter(e=>e.kind!==`thinking`);if(!(a||e.reasoning||o.length>0||t.length>0))return null;let s=e.reasoningOpen??!1,l=i||s||r,u=a&&!s&&!l&&e.reasoning?Fu(e.reasoning).replaceAll(`**`,``):``;return(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>bs(n,e),className:`flex w-full items-center gap-2 py-1 text-left select-none`,children:[a||i&&!e.content?(0,Q.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`,children:[(0,Q.jsx)(`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`}),(0,Q.jsx)(`path`,{d:`M9 18h6`}),(0,Q.jsx)(`path`,{d:`M10 22h4`})]}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium shrink-0 ${i&&!e.content?`text-shimmer`:`text-shimmer-static`}`,children:i&&!e.content?t.some(e=>e.kind!==`thinking`&&e.status===`running`)?`正在分析请求`:`思考中…`:i?`正在生成…`:e.turnStatus===`stopped`?`已完成分析`:`思考完成`}),!i&&e.reasoningDuration!=null&&(0,Q.jsxs)(`span`,{className:`text-xs text-stone-400 shrink-0`,children:[`用时 `,e.reasoningDuration,`s`]}),(0,Q.jsx)(Lu,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${s?`rotate-180`:``}`}),u?(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-xs text-shimmer-muted think-mask`,children:u}):null]}),l&&t.length>0?(0,Q.jsx)(`ul`,{className:`mt-1.5 mb-1 pl-5.5 space-y-1.5`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:`text-[12px] flex items-start gap-2 min-w-0 ${e.status===`error`?`text-red-600`:e.status===`running`?`text-stone-600`:`text-stone-500`}`,children:[(0,Q.jsx)(Nu,{kind:e.kind,status:e.status}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 leading-5`,children:[(0,Q.jsx)(`span`,{className:`font-medium ${e.status===`running`?`text-shimmer`:``}`,children:e.title}),e.detail?(0,Q.jsxs)(`span`,{className:`text-stone-400`,children:[` · `,(0,Q.jsx)(`span`,{className:e.status===`error`?`text-red-600`:e.status===`running`?`text-shimmer-muted`:``,"data-hint":e.detail,children:e.detail.length>72?`${e.detail.slice(0,72)}…`:e.detail})]}):e.status===`running`?(0,Q.jsxs)(`span`,{className:`text-stone-400 text-shimmer-muted`,children:[` · `,`…`]}):null]})]},e.id))}):null,s&&e.reasoning?(0,Q.jsx)(`div`,{className:`mt-1.5 mb-2 pl-5.5 text-[13px] leading-5 text-stone-500 whitespace-pre-wrap max-h-80 overflow-y-auto`,children:e.reasoning}):null,e.turnStatus===`stopped`?(0,Q.jsx)(`div`,{className:`mt-1.5 pl-5.5`,children:(0,Q.jsx)(`span`,{className:`tw-turn-stopped-pill`,children:`已停止`})}):null]})})(),e.content?(0,Q.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:an(e.content)}}):null,e.caseFile?(0,Q.jsxs)(`button`,{type:`button`,"data-focus-doc":`cases:${e.caseFile.path.replace(/\\/g,`/`)}`,"data-hint":`双击本地打开`,onDoubleClick:()=>{Be(`cases`,e.caseFile.path).catch(e=>B(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-emerald-50 text-emerald-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.caseFile.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.caseFile.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[ut(`cases`),e.caseFile.path,e.caseFile.count>0?` · ${e.caseFile.count} 条`:``,` · 双击本地打开`]})]})]}):null,e.docsFile?(0,Q.jsxs)(`button`,{type:`button`,"data-focus-doc":`${e.docsFile.root}:${e.docsFile.path.replace(/\\/g,`/`)}`,"data-hint":`点击本地打开`,onClick:()=>{Be(e.docsFile.root,e.docsFile.path).catch(e=>B(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg flex items-center justify-center text-[10px] font-semibold shrink-0 ${e.docsFile.root===`knowledge`?`bg-amber-50 text-amber-800`:`bg-sky-50 text-sky-700`}`,children:e.docsFile.name.split(`.`).pop()?.toUpperCase()||`MD`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.docsFile.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[ut(e.docsFile.root),e.docsFile.path,e.docsFile.note?` · ${e.docsFile.note}`:``,` · 点击打开`]})]})]}):null,e.presentFiles?.length?e.presentFiles.map(e=>(0,Q.jsxs)(`button`,{type:`button`,"data-hint":`点击本地打开`,onClick:()=>{dn(e.path,et).catch(e=>B(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-violet-50 text-violet-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[e.path,e.description?` · ${e.description}`:``,` · 点击打开`]})]})]},e.path)):null,e.content&&!(n===c.length-1&&Fe)?(0,Q.jsxs)(`div`,{className:`tw-msg-actions mt-1 ${hc(n)}`,children:[(0,Q.jsx)(vd,{text:e.content}),e.usage&&(0,Q.jsx)(Ed,{usage:e.usage,model:e.model??t?.model}),e.time!=null&&(0,Q.jsx)(`span`,{className:`tw-msg-action-time`,children:gd(e.time)})]}):null]},n))})}),nt&&(0,Q.jsx)(`button`,{type:`button`,onClick:vo,"aria-label":`回到底部`,className:`absolute bottom-3 right-8 sm:right-10 lg:right-12 w-8 h-8 rounded-full bg-white border border-stone-200 shadow-md flex items-center justify-center text-stone-500 hover:text-stone-800 transition-colors`,children:(0,Q.jsx)(Lu,{className:`w-4 h-4`})})]},`dialog-${a?.activeId??``}`),He&&(0,Q.jsx)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-2`,children:(0,Q.jsxs)(`div`,{ref:Oa,className:`w-full max-w-[min(64rem,100%)] mx-auto flex items-start gap-3 px-4 py-3 rounded-xl text-sm border ${We===`ok`?`tw-notice-anim`:``} ${We===`ok`?`bg-emerald-50 border-emerald-200 text-emerald-900`:`bg-red-50 border-red-200 text-red-800`}`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 w-5 h-5 shrink-0 rounded-full flex items-center justify-center text-xs font-semibold ${We===`ok`?`bg-emerald-100 text-emerald-700`:`bg-red-100 text-red-600`}`,children:We===`ok`?`i`:`!`}),(0,Q.jsx)(`pre`,{className:`flex-1 min-w-0 m-0 font-sans text-[13px] leading-5 whitespace-pre-wrap break-words`,children:He.replace(/\*\*/g,``).replace(/\s*:\s*\*\*/g,`: `).trim()}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>B(null),className:`shrink-0 text-xs ${We===`ok`?`text-emerald-500 hover:text-emerald-700`:`text-red-400 hover:text-red-600`}`,children:`关闭`})]})}),(0,Q.jsxs)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-5`,children:[(0,Q.jsxs)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto`,children:[N?.active&&V.promptGen?(0,Q.jsx)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-[#4176e6]/30 bg-[#edf3fe] text-xs text-[#3565c7]`,children:(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成提示词已启用 · `,Ki(N)]})}):null,F?.active&&V.knowledgeGen?(0,Q.jsx)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-amber-300/60 bg-amber-50 text-xs text-amber-900`,children:(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成知识库已启用 · `,oa(F)]})}):null,O?.active&&V.caseGen?(0,Q.jsx)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-[#4176e6]/30 bg-[#edf3fe] text-xs text-[#3565c7]`,children:(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成测试用例已启用 · `,Ae(O)]})}):null,dr.length>0?(0,Q.jsx)(`div`,{className:`mb-2 rounded-xl border border-stone-200/80 bg-stone-100/80 overflow-hidden`,children:dr.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-stone-200/60 last:border-b-0`,children:[(0,Q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-stone-400 shrink-0`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-stone-700`,children:ga(e)}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`编辑回输入框`,onClick:()=>_s(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`从队列移除`,onClick:()=>gs(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`插话立即发送(其后队列仍会续发)`,onClick:()=>vs(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none text-[#4176e6]`,children:(0,Q.jsx)(Gu,{className:`w-3.5 h-3.5`})})]},e.id))}):null,Ci?(0,Q.jsxs)(`div`,{className:`mb-2 rounded-xl border border-amber-300/60 bg-amber-50/90 px-4 py-3 shadow-sm`,children:[(0,Q.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 mb-1`,children:`待批准计划`}),(0,Q.jsx)(`div`,{className:`text-[14px] font-medium text-stone-900`,children:Ci.title}),Ci.summary?(0,Q.jsx)(`p`,{className:`mt-1 text-[13px] text-stone-600 leading-5`,children:Ci.summary}):null,(0,Q.jsx)(`ol`,{className:`mt-2 list-decimal pl-5 space-y-1 text-[13px] text-stone-700`,children:Ci.steps.map((e,t)=>(0,Q.jsx)(`li`,{children:e},`${t}-${e.slice(0,24)}`))}),(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg border border-stone-200 bg-white text-[12px] text-stone-600 hover:bg-stone-50`,onClick:()=>Ps(),children:`驳回`}),(0,Q.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg bg-[#4176e6] text-[12px] text-white hover:bg-[#3467d4]`,onClick:()=>Ns(),children:`批准实施`})]})]}):null,Ji?(0,Q.jsx)(pu,{kind:Ji.kind,items:Ji.items,manual:Ji.manual,quick:Ji.quick,quickNote:Ji.quickNote,tasksOn:V.tasks,closing:Qi,onConfirm:e=>{Ji.manual?(sa(null),ua(Ji.kind,e)):sa(e)},onCancel:()=>sa(null)}):null,qc>0&&Z?(0,Q.jsxs)(`div`,{className:`mb-2 flex max-h-[min(60vh,520px)] flex-col overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_6px_24px_rgba(15,23,42,0.08)]`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 justify-between gap-4 px-5 ${Ri?`items-center py-3.5`:`items-start pt-4`}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`mb-1 text-[11px] leading-4 text-stone-400`,children:Ui?`跳过确认`:Z.header||`模型需要你的确认`}),(0,Q.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:Ui?`确认 ${$c.length} 道跳过的题怎么处理`:Z.question})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[Ri?(0,Q.jsx)(`span`,{className:`text-[11px] leading-4 text-stone-400`,children:Ui?`已跳过 ${$c.length} 题`:`第 ${Jc+1} 步 / 共 ${qc} 步`}):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":Ri?`展开问题`:`收起问题`,onClick:()=>Bi(e=>!e),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600`,children:(0,Q.jsx)(Lu,{className:`h-4 w-4 transition-transform ${Ri?`rotate-180`:``}`})})]})]}),Ri?null:Ui?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-[12px] leading-5 text-stone-500`,children:`跳过不算确认,本轮不会开始改代码。留下原因后我只出方案,等你回复「开始实施」。`}),(0,Q.jsx)(`ul`,{className:`mt-2 space-y-1 rounded-lg bg-stone-50 px-3 py-2`,children:$c.map(({q:e,index:t})=>(0,Q.jsxs)(`li`,{className:`text-[12px] leading-5 text-stone-600`,children:[(0,Q.jsxs)(`span`,{className:`text-stone-400`,children:[t+1,`.`]}),` `,e.header?`${e.header} / `:``,e.question,(0,Q.jsx)(`span`,{className:`ml-1 text-stone-400`,children:`— 已跳过`})]},e.id))}),(0,Q.jsx)(`textarea`,{autoFocus:!0,value:Gi,onChange:e=>qi(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Js())},rows:3,className:`mt-2 w-full resize-none rounded-lg border border-stone-200 px-2.5 py-2 text-[13px] leading-5 outline-none focus:border-[#4176e6]`,placeholder:`为什么跳过这几题?例如:先只做评估,方案我稍后定 / 这几项按你推荐的来`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>Ys(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`返回继续回答`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>Js(),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4]`,children:`提交并继续`})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-1`,children:[Z.options?.length?(0,Q.jsx)(`div`,{className:`mt-2 flex flex-col gap-0.5`,role:Z.multi_select?`group`:`radiogroup`,children:Z.options.map((e,t)=>{let n=Xc.selected.includes(e.label),r=_u(e.label);return(0,Q.jsxs)(`button`,{type:`button`,role:Z.multi_select?`checkbox`:`radio`,"aria-checked":n,onClick:()=>Rs(Z,e.label,n),className:`flex w-full shrink-0 items-start gap-2 rounded-lg border px-2 py-2 text-left outline-none transition-colors ${n?`border-[#4176e6]/40 bg-[#f2f7ff]`:`border-transparent hover:bg-stone-50`}`,children:[Z.multi_select?(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded border ${n?`border-[#4176e6] bg-[#4176e6] text-white`:`border-stone-300 text-transparent`}`,children:(0,Q.jsx)(zu,{className:`h-3 w-3`})}):(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-5 w-5 shrink-0 place-items-center rounded-md text-[11px] font-medium ${n?`bg-[#4176e6] text-white`:`bg-stone-100 text-stone-500`}`,children:t+1}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] leading-5 font-medium text-stone-800`,children:r.label}),r.recommended?(0,Q.jsx)(`span`,{className:`rounded bg-[#edf3fe] px-1 text-[10px] leading-4 font-semibold text-[#4176e6]`,children:`推荐`}):null]}),e.description?(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[12px] leading-4.5 text-stone-400`,children:e.description}):null]})]},`${e.label}-${t}`)})}):(0,Q.jsx)(`div`,{className:`px-1.5 py-2`,children:(0,Q.jsx)(`textarea`,{autoFocus:!0,value:Xc.text,onChange:e=>Us(Z,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Ws(Z,Xc.text))},rows:2,className:`w-full resize-none rounded-lg border border-stone-200 px-2.5 py-2 text-[13px] leading-5 outline-none focus:border-[#4176e6]`,placeholder:`输入你的回答…`})}),Z.options?.length?(0,Q.jsx)(`div`,{className:`mt-1 px-1.5 pb-1`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-stone-200 px-2 py-1.5 focus-within:border-[#4176e6]`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded bg-stone-100 text-[10px] font-medium text-stone-500`,children:`#`}),(0,Q.jsx)(`textarea`,{value:Xc.text,onChange:e=>Us(Z,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Ws(Z,Xc.text))},rows:1,className:`min-h-5 w-full resize-none bg-transparent text-[13px] leading-5 outline-none`,placeholder:`输入序号选择(如 1${Z.multi_select?` 或 1,3`:``}),也可直接写你的回答`})]})}):null,(0,Q.jsx)(`div`,{className:`px-2 pb-2 pt-1 text-[11px] leading-4 text-stone-400`,children:Z.options?.length?`回车确认这一步;跳过的题会在提交前让你说明原因,不会直接开始实施`:`回车确认;跳过的题会在提交前让你说明原因,不会直接开始实施`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":`上一步`,disabled:Jc===0,onClick:()=>Bs(Jc-1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Q.jsx)(Ru,{className:`h-4 w-4 rotate-180`})}),(0,Q.jsxs)(`span`,{className:`px-1 text-[12px] font-medium text-stone-500`,children:[`第 `,Jc+1,` 步 / 共 `,qc,` 步`]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`下一步`,disabled:Zc,onClick:()=>Bs(Jc+1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Q.jsx)(Ru,{className:`h-4 w-4`})})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[Vi?(0,Q.jsx)(`span`,{className:`truncate text-[11px] text-rose-500`,children:Vi}):null,(0,Q.jsx)(`button`,{type:`button`,onClick:()=>qs(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`跳过`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!Qc,onClick:()=>Zc?Ks():Bs(Jc+1),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4] disabled:cursor-not-allowed disabled:bg-stone-300`,children:Zc?`提交回答`:`下一步`})]})]})]})]}):null,(0,Q.jsxs)(`div`,{ref:ka,className:`pt-2 rounded-[20px] bg-white border border-stone-200 shadow-[0_4px_20px_rgba(15,23,42,0.06)] transition-shadow focus-within:shadow-[0_4px_24px_rgba(65,118,230,0.14)]`,children:[(b.length>0||f.length>0||v.length>0||mi.length>0)&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-0.5 pb-2`,children:[mi.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 rounded-lg border border-[#4176e6]/25 bg-[#edf3fe] py-1 pr-1 pl-2.5 text-xs text-[#4176e6]`,children:[(0,Q.jsxs)($,{className:`h-3.5 w-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Q.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Q.jsx)(`path`,{d:`M8 13h8`}),(0,Q.jsx)(`path`,{d:`M8 17h5`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[10px] text-[#4176e6]/80`,children:`要求`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>yi(e),className:`max-w-56 truncate text-left hover:underline`,children:e.label}),e.detail?(0,Q.jsx)(`span`,{className:`max-w-44 truncate text-[10px] text-[#4176e6]/70`,children:e.detail}):null,(0,Q.jsx)(`button`,{type:`button`,onClick:()=>Uo(e.id),className:`flex h-5 w-5 items-center justify-center rounded text-[#4176e6]/70 hover:bg-white/80 hover:text-[#4176e6]`,"aria-label":`取消${e.label}`,children:(0,Q.jsxs)($,{className:`h-3 w-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id)),b.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.collection===`workspace`?e.path:`${e.collection}/${e.path}`,children:[(0,Q.jsx)(Uu,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:e.collection===`workspace`?`工作区`:e.collection===`prompts`||e.collection===`cases`||e.collection===`knowledge`?e.category:Ac(e.format)}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.title}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{x(t=>t.filter(t=>t.collection!==e.collection||t.path!==e.path)),e.collection===`cases`&&(_i(e=>{let t=e.filter(e=>!(e.id.startsWith(`case-fix:`)||e.id.startsWith(`case-batch-fix:`)||e.id.startsWith(`blindspot-writeback:`)));return Xt(Y.current?.activeId,t),t}),yi(null))},className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.collection}:${e.path}`)),f.map((e,t)=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.path||e.name,children:[(0,Q.jsx)(Uu,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:`文件`}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`移除`,onClick:()=>m(e=>e.filter((e,n)=>n!==t)),className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.name}-${t}`)),v.map(e=>(0,Q.jsxs)(`span`,{className:`relative group inline-flex rounded-lg border border-stone-200 overflow-hidden bg-stone-50`,"data-hint":`${e.name} · ${hd(e.size)}`,children:[(0,Q.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`h-14 w-14 object-cover`}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`移除图片`,onClick:()=>y(t=>t.filter(t=>t.id!==e.id)),className:`absolute top-0.5 right-0.5 w-5 h-5 flex items-center justify-center rounded bg-black/55 text-white hover:bg-black/75`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id))]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[ir&&!Ra&&!Fa&&(0,Q.jsx)(`div`,{ref:Da,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-3 z-40 h-[min(70vh,20rem)] overflow-hidden rounded-xl border border-stone-200 py-2.5 shadow-[0_4px_14px_-4px_rgba(15,23,42,0.08)]`,children:(0,Q.jsxs)(`div`,{className:`tw-dsh-scroll h-full overflow-y-auto overflow-x-hidden`,children:[(0,Q.jsx)(`div`,{className:`px-3 pt-0.5 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`添加`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{sr(!1),Ca.current?.click()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)(Wu,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`文件`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`file`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`添加本地附件`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{sr(!1),Yo()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`目标`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`goal`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`设置或查看长期任务目标`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{sr(!1),ii===`off`?Xo():Fs()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100 ${ii===`planning`?`bg-amber-50`:ii===`approved`?`bg-emerald-50`:``}`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 ${ii===`planning`?`text-amber-800`:ii===`approved`?`text-emerald-800`:`text-stone-500`}`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`计划`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`plan`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`进入或退出计划模式`})]}),V.todos||V.tasks?(0,Q.jsxs)(Q.Fragment,{children:[V.todos?(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>la(`todo`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`待办`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`todo`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一条待办`})]}):null,V.tasks?(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>la(`task`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M9 5h10`}),(0,Q.jsx)(`path`,{d:`M9 12h10`}),(0,Q.jsx)(`path`,{d:`M9 19h10`}),(0,Q.jsx)(`path`,{d:`M4 5h.01`}),(0,Q.jsx)(`path`,{d:`M4 12h.01`}),(0,Q.jsx)(`path`,{d:`M4 19h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`任务`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`task`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一个任务`})]}):null]}):null,La.length?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>ur(e=>!e),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-stone-50`,children:[(0,Q.jsx)(`span`,{className:`flex-1 text-[11px] font-medium text-stone-400 tracking-wide`,children:`扩展插件`}),(0,Q.jsx)(Lu,{className:`w-3.5 h-3.5 text-stone-400 shrink-0 transition-transform ${cr?`rotate-180`:``}`})]}),cr?La.map(e=>{let t=e.id===`caseGen`?`case`:e.id===`promptGen`?`prompt`:e.id===`knowledgeGen`?`knowledge`:e.id===`pluginDev`?`dev`:``,n=e.id===`caseGen`?`打开配置后生成用例并写入用例库`:e.id===`promptGen`?`对话生成提示词并写入提示词库`:e.id===`knowledgeGen`?`对话生成规范/方法论并写入知识库`:e.id===`pluginDev`?`输入需求后先评估确认,再开发扩展插件`:``;return(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{sr(!1),mo(e.id)},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)($u,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[e.name,t?(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:t}):null]}),n?(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:n}):null]},e.id)}):null]}):null,(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`指令`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{sr(!1),Vr.current?B(`请等待当前回复结束后再压缩`):ts({force:!0}).then(e=>{e&&B(`已压缩上下文`)})},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`压缩`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`compact`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`压缩以上对话内容`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{sr(!1),nc()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M3 3v18h18`}),(0,Q.jsx)(`path`,{d:`M7 14v4`}),(0,Q.jsx)(`path`,{d:`M12 10v8`}),(0,Q.jsx)(`path`,{d:`M17 6v12`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`会话统计`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`stats`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`查看本会话用量摘要`})]})]})}),Ra&&(0,Q.jsxs)(`div`,{ref:Ea,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`插件`}),La.map((e,t)=>(0,Q.jsxs)(`button`,{type:`button`,"data-plugin-index":t,onMouseDown:e=>e.preventDefault(),onMouseEnter:()=>R(t),onClick:()=>mo(e.id),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===L?`is-active`:``}`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Q.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 flex-1`,children:e.name})}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400 line-clamp-2`,children:e.description})]},e.id))]}),Fa&&(0,Q.jsx)(`div`,{ref:Ta,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:J.length===0?(0,Q.jsxs)(`div`,{className:`px-3 py-2 text-xs text-stone-400 space-y-1`,children:[br?(0,Q.jsx)(`p`,{children:`项目文档:无匹配`}):null,ja?(0,Q.jsx)(`p`,{children:`工作区:无匹配`}):(0,Q.jsx)(`p`,{children:`工作区:请先在侧栏添加并选择工作区`}),br?null:(0,Q.jsxs)(`p`,{children:[`「知识库检索」未启用:启用后才能用 @ 引用`,dt(`knowledge`),` / `,dt(`templates`),`文档`]})]}):(0,Q.jsxs)(Q.Fragment,{children:[Na.length>0?(0,Q.jsxs)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:[`项目文档(`,dt(`knowledge`),` / `,dt(`templates`),`)`]}):null,J.map((e,t)=>{let n=e.doc,r=J[t-1],i=e.section===`workspace`&&r?.section!==`workspace`;return(0,Q.jsxs)(`div`,{children:[i?(0,Q.jsxs)(Q.Fragment,{children:[Na.length>0?(0,Q.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}):null,(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:`工作区`})]}):null,(0,Q.jsxs)(`button`,{type:`button`,"data-mention-index":t,onMouseDown:e=>e.preventDefault(),onClick:()=>uo(n),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===qn?`is-active`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] text-stone-800`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:n.collection===`knowledge`?dt(`knowledge`):n.collection===`templates`?dt(`templates`):n.format===`dir`?`文件夹`:`文件`}),n.collection===`workspace`?null:(0,Q.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:Ac(n.format)}),(0,Q.jsx)(`span`,{className:`truncate font-medium`,children:n.title})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 pl-0 text-xs text-stone-400 truncate`,children:n.collection===`workspace`?n.path:`${n.category}${n.description?` · ${n.description}`:``}`})]})]},`${n.collection}/${n.id}`)}),br?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}),(0,Q.jsx)(`p`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`「知识库检索」未启用:@ 仅引用工作区文件`})]})]})}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 px-3`,children:[li===`goal`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-goal`,"data-hint":`会话目标`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Q.jsx)(`span`,{children:`目标`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消目标输入`,onClick:()=>ui(null),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,li===`plan`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-plan${ii===`approved`?` is-approved`:``}`,"data-hint":ii===`approved`?`计划模式·已批准`:`计划模式·探查中`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsx)(`span`,{children:`计划`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`退出计划模式`,onClick:()=>Jo(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,li===`pluginDev`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-plugin-dev`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M9 7V3`}),(0,Q.jsx)(`path`,{d:`M15 7V3`}),(0,Q.jsx)(`path`,{d:`M6 7h12v4a6 6 0 0 1-12 0V7Z`}),(0,Q.jsx)(`path`,{d:`M12 17v4`})]}),(0,Q.jsx)(`span`,{children:`插件开发`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`退出插件开发`,onClick:()=>Jo(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,li===`reports`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-report`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Q.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Q.jsx)(`path`,{d:`M8 13h8`}),(0,Q.jsx)(`path`,{d:`M8 17h5`})]}),(0,Q.jsxs)(`span`,{children:[`生成`,Br[di]]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消汇报生成`,onClick:()=>Jo(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,N?.active&&V.promptGen?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-prompt-gen`,"data-hint":`改配置 · ${Ki(N)}`,role:`button`,tabIndex:0,onClick:()=>oe(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),oe(!0))},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Q.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Q.jsx)(`path`,{d:`M8 13h8`}),(0,Q.jsx)(`path`,{d:`M8 17h5`})]}),(0,Q.jsx)(`span`,{children:`生成提示词`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消生成提示词`,onClick:e=>{e.stopPropagation(),Os(null)},children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,F?.active&&V.knowledgeGen?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-knowledge-gen`,"data-hint":`改配置 · ${oa(F)}`,role:`button`,tabIndex:0,onClick:()=>P(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),P(!0))},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,Q.jsx)(`path`,{d:`M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z`})]}),(0,Q.jsx)(`span`,{children:`生成知识库`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消生成知识库`,onClick:e=>{e.stopPropagation(),ks(null)},children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,O?.active&&V.caseGen?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-case-gen`,"data-hint":`改配置 · ${Ae(O)}`,role:`button`,tabIndex:0,onClick:()=>D(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),D(!0))},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Q.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Q.jsx)(`path`,{d:`M8 13h8`}),(0,Q.jsx)(`path`,{d:`M8 17h5`})]}),(0,Q.jsx)(`span`,{children:`生成测试用例`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消生成测试用例`,onClick:e=>{e.stopPropagation(),Ds(null)},children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,(0,Q.jsx)(`textarea`,{ref:ya,value:u,onChange:e=>{let t=e.target.value;Fo(t),d(t)},onPaste:lc,onKeyDown:e=>{if((e.metaKey||e.ctrlKey)&&!e.altKey&&(e.key===`z`||e.key===`Z`))e.preventDefault(),e.shiftKey?Ho():Io();else if(e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey&&(e.key===`y`||e.key===`Y`))e.preventDefault(),Ho();else{if(Ra&&La.length){if(e.key===`ArrowDown`){e.preventDefault(),R(e=>(e+1)%La.length);return}if(e.key===`ArrowUp`){e.preventDefault(),R(e=>(e-1+La.length)%La.length);return}if(e.key===`Escape`){e.preventDefault(),rr(!0),Ia&&d(u.slice(0,Ia.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=La[L]??La[0];t&&mo(t.id);return}}if(Fa&&J.length){if(e.key===`ArrowDown`){e.preventDefault(),Jn(e=>(e+1)%J.length);return}if(e.key===`ArrowUp`){e.preventDefault(),Jn(e=>(e-1+J.length)%J.length);return}if(e.key===`Escape`){e.preventDefault(),Qn(!0),Ma&&d(u.slice(0,Ma.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=J[qn]?.doc;t&&uo(t);return}}if(e.key===`Escape`&&ir)e.preventDefault(),sr(!1);else if(e.key===`Escape`&&(Ma||Ia)){e.preventDefault(),Qn(!0),rr(!0);let t=Ma?.from??Ia?.from;t!=null&&d(u.slice(0,t))}else if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=e.metaKey||e.ctrlKey;if(Vr.current){if(t){let e=u.trim();if(e||f.length>0||v.length>0||b.length>0){let t={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:e,files:[...f],refs:[...b],imgs:[...v]};Wo(),ys(t)}else da.current.length&&ys();return}as(void 0,{forceBusy:qe().busySendBehavior??`queue`})}else as()}}},rows:1,placeholder:t?N?.active&&V.promptGen?`描述提示词编写要求后发送(点 × 取消生成)`:F?.active&&V.knowledgeGen?`粘贴或描述素材后发送(点 × 取消生成)`:O?.active&&V.caseGen?`可补充生成范围;直接发送即按配置生成用例(点 × 取消)`:mi.length>0?`可补充说明;直接发送会带上「要求」与引用文件`:dr.length>0&&Fe?`Cmd/Ctrl+Enter 插话发送全部排队消息`:br?`请输入内容,或用 @ 引用文档`:ja?`请输入内容,或用 @ 引用工作区文件`:`请输入内容(@ 引用文档需先启用「知识库检索」)`:`请先配置模型(左下角「设置」→ 模型)`,className:`tw-chat-input block min-w-0 flex-1 min-h-13 pl-0 pr-2 pt-1.5 pb-0.5 bg-transparent resize-none focus:outline-none placeholder:text-(--tw-label-tertiary)`})]})]}),(0,Q.jsxs)(`div`,{className:`tw-composer-bar flex items-center gap-1.5 px-3 pb-3 pt-3`,children:[(0,Q.jsx)(`button`,{type:`button`,"data-add-menu-btn":!0,"aria-label":ii===`off`?`添加`:ii===`planning`?`添加(计划模式·探查中)`:`添加(计划模式·已批准)`,onClick:()=>{sr(e=>!e),Qn(!0),rr(!0)},className:`tw-icon-btn w-8 h-8 shrink-0 rounded-full flex items-center justify-center outline-none focus:outline-none focus-visible:outline-none transition-colors ${ir?`bg-(--tw-session-hover-bg)`:``}`,children:(0,Q.jsxs)($,{className:`w-4 h-4`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})}),G&&(0,Q.jsxs)(A,{children:[(0,Q.jsxs)(j,{title:Oc?`工作区:${Oc}`:`选择工作区`,"aria-label":Nc?`工作区:${Nc}`:`选择工作区`,disabled:An,className:`tw-composer-bar-ws group flex items-center gap-1 h-7 shrink-0 max-w-[min(40vw,11rem)] pl-1.5 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(Ku,{className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:Nc}),(0,Q.jsx)(Lu,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Q.jsxs)(ne,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-[min(100vw-2rem,16rem)] rounded-xl border border-stone-200 py-1 shadow-xl focus:outline-none`,children:[(H?.items??[]).map(e=>{let t=e.path===Oc;return(0,Q.jsx)(re,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:An,onClick:()=>void $a(e),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Q.jsx)(Ku,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] ${t?`text-stone-900 font-medium`:`text-stone-700`}`,"data-hint":e.path,children:ln(e,wc)}),t&&(0,Q.jsx)(zu,{className:`w-3.5 h-3.5 shrink-0 text-[#4176e6]`})]})},e.id)}),(H?.items?.length??0)>0&&(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsx)(re,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:An,onClick:()=>void eo(),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left text-[13px] text-stone-700 data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`w-4 h-4 shrink-0 flex items-center justify-center text-stone-500 text-base leading-none`,children:`+`}),`添加工作区...`]})})]})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsxs)(j,{title:`访问权限:${_c.label}`,"aria-label":`访问权限:${_c.label}`,className:`tw-composer-bar-access group flex items-center gap-1 h-7 shrink-0 max-w-55 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors`,children:[(0,Q.jsx)(od,{level:et,className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:_c.label}),(0,Q.jsx)(`span`,{className:`ml-0.5 w-1.5 h-1.5 rounded-full shrink-0 ${G?`bg-emerald-500`:`bg-stone-300`}`,"data-hint":G?`Runner 在线`:`Runner 离线`}),(0,Q.jsx)(Lu,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Q.jsxs)(ne,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-56 rounded-xl border border-stone-200 p-1 shadow-xl focus:outline-none`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:G?`本地文件服务已连接`:`本地文件服务未就绪`}),ku.map(e=>{let t=vc&&e.value===`readonly`;return(0,Q.jsx)(re,{disabled:t,children:(0,Q.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>{tt(e.value),Y.current&&X(It(Y.current,{access:e.value}))},className:`w-full flex items-center gap-2 px-3 py-2 rounded-lg text-left text-[13px] data-[focus]:bg-stone-100 disabled:cursor-not-allowed`,children:[(0,Q.jsx)(od,{level:e.value,className:`w-4 h-4 shrink-0 ${t?`text-stone-300`:`text-stone-500`}`}),(0,Q.jsx)(`span`,{className:`flex-1 ${t?`text-stone-400`:et===e.value?`text-stone-900 font-medium`:`text-stone-700`}`,children:e.label}),t?(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`插件开发需要写入`}):et===e.value?(0,Q.jsx)(zu,{className:`w-3.5 h-3.5 text-[#4176e6]`}):null]})},e.value)})]})]}),(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsx)(Dd,{settings:t}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{Vr.current?hs():as()},disabled:!Fe&&!fc,"aria-label":Fe?`停止生成`:`发送`,className:`w-8 h-8 shrink-0 rounded-full flex items-center justify-center outline-none focus:outline-none focus-visible:outline-none transition-colors ${Fe?`bg-stone-200 text-stone-700 hover:bg-stone-300`:`bg-[#4176e6] text-white hover:bg-[#3565c7] disabled:bg-[#a9c3ef] disabled:cursor-not-allowed`}`,children:Fe?(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 bg-current rounded-xs`}):(0,Q.jsx)(Gu,{className:`w-4 h-4`})})]})]}),(0,Q.jsx)(Td,{messages:c,model:t?.model,systemPromptTokens:dd(S)})]}),(0,Q.jsx)(`input`,{ref:Ca,type:`file`,multiple:!0,hidden:!0,accept:[...pl.map(e=>`.${e}`),`image/*`,`text/*`,`application/json`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/msword`].join(`,`),onChange:e=>void ac(e)})]})]})]}),_e?(0,Q.jsx)(`div`,{className:`tw-plugins-rail flex-1 min-w-0 min-h-0 self-stretch h-full overflow-hidden flex flex-col`,children:(0,Q.jsx)(Mr,{embedded:!0})}):null,(0,Q.jsx)(Rl,{open:w,initial:O,presetStories:te,onClose:()=>{D(!1),ie(null)},onConfirm:e=>Ds(e)}),(0,Q.jsx)(zl,{open:M,initial:N,onClose:()=>oe(!1),onConfirm:e=>Os(e)}),(0,Q.jsx)(Bl,{open:le,initial:F,onClose:()=>P(!1),onConfirm:e=>ks(e)}),(0,Q.jsx)(Yt,{open:!!be,title:`重命名会话`,label:`会话名称`,placeholder:`请输入会话名称`,initialValue:be?a?.sessions.find(e=>e.id===be)?.title??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>xe(null),onConfirm:rc}),(0,Q.jsx)(Yt,{open:!!Ne,title:`重命名工作区`,label:`显示名称`,placeholder:`请输入工作区名称`,initialValue:Ne?H?.items.find(e=>e.id===Ne)?.name??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>Pe(null),onConfirm:e=>void io(e)}),(0,Q.jsx)(Vl,{task:vi,onClose:()=>yi(null),onSave:Mo,onRemove:()=>{vi&&Uo(vi.id)}}),(0,Q.jsx)(Vl,{task:xi,readOnly:!0,onClose:()=>Si(null)}),(0,Q.jsx)(ae,{open:!!Se,title:`删除会话`,message:Se?`确定永久删除「${a?.sessions.find(e=>e.id===Se)?.title??`该会话`}」?此操作不可恢复。`:``,confirmLabel:`删除`,cancelLabel:`取消`,danger:`outline`,onClose:()=>Ce(null),onConfirm:()=>{if(!Se)return;let e=Se;Ce(null),Qs(e)}}),(0,Q.jsx)(ae,{open:!!Ee,title:`删除工作区`,message:Ee?`将把「${Ee.name}」从工作区列表中移除。文件夹与会话记录会保留,其会话将归入项目根工作区。`:``,confirmLabel:`删除工作区`,cancelLabel:`取消`,danger:`outline`,onClose:()=>De(null),onConfirm:()=>void no()})]})}export{Nd as default};