lantern-harness 0.1.21 → 0.1.23

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 (106) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/builtin/session/session-runs.mjs +34 -1
  3. package/dist/500.html +4 -4
  4. package/dist/_astro/Base.GThhapKd.css +1 -0
  5. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.CWRCetQl.js +2 -0
  6. package/dist/_astro/{CaseExecBoard.CwH1rd8R.js → CaseExecBoard.Dnb8oP5i.js} +1 -1
  7. package/dist/_astro/CaseGenerateApp.ci_JowEk.js +10 -0
  8. package/dist/_astro/CasesLibrary.CDjuLV_E.js +21 -0
  9. package/dist/_astro/ChatApp.Td2xCiQG.js +216 -0
  10. package/dist/_astro/{DashboardBoard.BDURPamv.js → DashboardBoard.D-zHXRds.js} +2 -2
  11. package/dist/_astro/DocsFileBrowser.BM3nH4VD.js +1 -0
  12. package/dist/_astro/{DocsPager.v4kQH163.js → DocsPager.B9VhI6E3.js} +1 -1
  13. package/dist/_astro/{DrawerField.C0ehOlDt.js → DrawerField.C0MkN-LW.js} +1 -1
  14. package/dist/_astro/{KnowledgeLibrary.B_99kzox.js → KnowledgeLibrary.D9KnqXzr.js} +1 -1
  15. package/dist/_astro/{PluginsPage.aQKIWMKz.js → PluginsPage.DBRfSxtq.js} +2 -2
  16. package/dist/_astro/PluginsPage.DMDyUktn.js +1 -0
  17. package/dist/_astro/PmBugsBoard.BnnaNP1y.js +1 -0
  18. package/dist/_astro/PmIterationsBoard.phiyhQVA.js +1 -0
  19. package/dist/_astro/{PmProjectDetail.BYVt43oh.js → PmProjectDetail.C8kRX5lu.js} +1 -1
  20. package/dist/_astro/{PmProjectsBoard.D06_aCFK.js → PmProjectsBoard.CFApEGPo.js} +1 -1
  21. package/dist/_astro/PmRequirementsBoard.B-AI9iZX.js +1 -0
  22. package/dist/_astro/PmRequirementsBoard.DR9egcgA.js +1 -0
  23. package/dist/_astro/PmShared.BrBicDMN.js +1 -0
  24. package/dist/_astro/PromptMountDialog.CpTT6L0a.js +62 -0
  25. package/dist/_astro/PromptsLibrary.sz6MivVn.js +1 -0
  26. package/dist/_astro/{ReportsPage.DOW1fswe.js → ReportsPage.CYZtpeiv.js} +1 -1
  27. package/dist/_astro/ReqAnalysisBoard.CazI9SU-.js +29 -0
  28. package/dist/_astro/RequirementsLibrary.R4dNZa9y.js +1 -0
  29. package/dist/_astro/SearchableSelect.Cbb8jMnP.js +1 -0
  30. package/dist/_astro/SelectDropdown.apWlFGbA.js +1 -0
  31. package/dist/_astro/{SettingsDialog.BBYaIU0N.js → SettingsDialog.Bs1I8b27.js} +1 -1
  32. package/dist/_astro/{SpaceSwitcher.DyzMNGfy.js → SpaceSwitcher.Dw9LjKiJ.js} +1 -1
  33. package/dist/_astro/{TagSelect.CuN5RdF4.js → TagSelect.B9W63KWq.js} +1 -1
  34. package/dist/_astro/{TasksBoard.BODqpiYV.js → TasksBoard.D0HwS5hd.js} +1 -1
  35. package/dist/_astro/{TemplatesLibrary.DDJLVEZk.js → TemplatesLibrary.CVv5Ef30.js} +1 -1
  36. package/dist/_astro/{TestStatsBoard.diX5s3sH.js → TestStatsBoard._qNcNorG.js} +1 -1
  37. package/dist/_astro/TodosBoard.CF5wbJy7.js +1 -0
  38. package/dist/_astro/UiAutoBoard.B-7mL3ez.js +9 -0
  39. package/dist/_astro/app-version.yT2l6J8H.js +1 -0
  40. package/dist/_astro/case-fields.h0roo2br.js +1 -0
  41. package/dist/_astro/case-gen-run.D8DGX0mr.js +19 -0
  42. package/dist/_astro/{case-review._K-6xl4v.js → case-review.C1hQRbQ2.js} +3 -3
  43. package/dist/_astro/case-template.F1Nv08GV.js +5 -0
  44. package/dist/_astro/docs-format.BlGh-XA_.js +1 -0
  45. package/dist/_astro/{llm.BZEzE0x2.js → llm.BuR7z55C.js} +1 -1
  46. package/dist/_astro/pm.pMOkNqqK.js +4 -0
  47. package/dist/_astro/req-analysis.dhgy4p2f.js +14 -0
  48. package/dist/_astro/{story-review.DvCTzGfr.js → story-review.BbdIf5zg.js} +5 -5
  49. package/dist/case-exec/index.html +5 -5
  50. package/dist/cases/generate/index.html +5 -5
  51. package/dist/cases/library/index.html +5 -5
  52. package/dist/dashboard/index.html +5 -5
  53. package/dist/docs/changelog/index.html +41 -5
  54. package/dist/docs/install/index.html +4 -4
  55. package/dist/docs/manual/index.html +17 -16
  56. package/dist/index.html +2 -2
  57. package/dist/knowledge/index.html +5 -5
  58. package/dist/plugins/index.html +5 -5
  59. package/dist/pm/bugs/index.html +5 -5
  60. package/dist/pm/iterations/index.html +5 -5
  61. package/dist/pm/projects/detail/index.html +5 -5
  62. package/dist/pm/projects/index.html +5 -5
  63. package/dist/pm/requirements/index.html +5 -5
  64. package/dist/prompts/index.html +5 -5
  65. package/dist/reports/index.html +5 -5
  66. package/dist/requirement-analysis/index.html +5 -5
  67. package/dist/requirements/index.html +5 -5
  68. package/dist/tasks/index.html +5 -5
  69. package/dist/templates/index.html +5 -5
  70. package/dist/test-automation/index.html +5 -5
  71. package/dist/test-stats/index.html +5 -5
  72. package/dist/todos/index.html +5 -5
  73. package/dist/workbench/index.html +5 -5
  74. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +13 -12
  75. package/lh-plugins/case-backup-ttl.mjs +34 -0
  76. package/lh-plugins/lh-case-review.mjs +74 -2
  77. package/lh-plugins/lh-reports.mjs +6 -5
  78. package/lh-plugins/lh-req-analysis.mjs +41 -5
  79. package/package.json +1 -1
  80. package/dist/_astro/Base.NUwtco4a.css +0 -1
  81. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.2J3Qrd4B.js +0 -1
  82. package/dist/_astro/CaseGenerateApp.CpL1po9n.js +0 -9
  83. package/dist/_astro/CasesLibrary.DAZMRzzt.js +0 -19
  84. package/dist/_astro/ChatApp.iDy6-iVA.js +0 -212
  85. package/dist/_astro/DocsFileBrowser.-dkkxR4X.js +0 -1
  86. package/dist/_astro/PluginsPage.B349vNQ7.js +0 -1
  87. package/dist/_astro/PmBugsBoard.Catlw5fm.js +0 -1
  88. package/dist/_astro/PmIterationsBoard.D4Bg969F.js +0 -1
  89. package/dist/_astro/PmRequirementsBoard.CyW9CfFH.js +0 -1
  90. package/dist/_astro/PmRequirementsBoard.DuXUq0HB.js +0 -1
  91. package/dist/_astro/PmShared.CwcLNMW2.js +0 -1
  92. package/dist/_astro/PromptMountDialog.YH2odDZx.js +0 -58
  93. package/dist/_astro/PromptsLibrary.dMO4dOAT.js +0 -1
  94. package/dist/_astro/ReqAnalysisBoard.DQpPjNNr.js +0 -29
  95. package/dist/_astro/RequirementsLibrary.Dd2DRKxL.js +0 -1
  96. package/dist/_astro/SearchableSelect.DZb-mxqw.js +0 -1
  97. package/dist/_astro/SelectDropdown.Cb-QtC-D.js +0 -1
  98. package/dist/_astro/TodosBoard.DQBEeiWU.js +0 -1
  99. package/dist/_astro/UiAutoBoard.3Xs5RjDq.js +0 -9
  100. package/dist/_astro/app-version.BqfBCSsN.js +0 -1
  101. package/dist/_astro/case-fields.CtFiDM_d.js +0 -1
  102. package/dist/_astro/case-gen-run.BI_ld4oo.js +0 -16
  103. package/dist/_astro/case-template.BGCVpSKI.js +0 -5
  104. package/dist/_astro/index.astro_astro_type_script_index_0_lang.DMnFoepS.js +0 -1
  105. package/dist/_astro/pm.CagBA-ht.js +0 -4
  106. package/dist/_astro/req-analysis.Dkbi-5A_.js +0 -9
@@ -1,9 +0,0 @@
1
- import{s as e,t}from"./react.Blvh0GOs.js";import{i as n}from"./app-config.CF1xVPmo.js";import{i as r,o as i,r as a,t as o}from"./view-prefs.D1snIG5o.js";import{i as s,n as c,r as l,t as u}from"./dialog.DZHZCe_T.js";import{i as ee,n as d,r as te,t as f}from"./menu.Dnrpz489.js";import{t as ne}from"./jsx-runtime.DUg_B_vD.js";import{t as re}from"./ConfirmDialog.CsMwWevK.js";import{t as p}from"./OverflowHint.pvo2Xc8R.js";import{t as ie}from"./SelectDropdown.Cb-QtC-D.js";import{showToast as ae}from"./Toast.BO2NFckG.js";import{c as oe}from"./project-docs.DAw9bzgk.js";import{s as se}from"./llm.BZEzE0x2.js";import{u as ce}from"./prompts-meta.C_MeYq8G.js";import{f as le,l as ue,p as de}from"./settings.B1yetppp.js";import{n as fe,t as pe}from"./PromptMountDialog.YH2odDZx.js";import{a as me,n as m,r as h,t as he}from"./ui-auto-prompt.l_EXfDs5.js";import{S as ge,_ as _e,a as ve,b as g,c as ye,d as be,f as xe,h as Se,i as Ce,l as we,m as Te,n as Ee,o as De,p as Oe,r as ke,t as Ae,u as _,v,x as je,y as Me}from"./ui-auto.BmC9JJ_X.js";import{t as Ne}from"./hydrate-cache.CmC22o_H.js";import{O as y,S as Pe,d as b,g as Fe,l as Ie,m as Le}from"./PmShared.CwcLNMW2.js";var x=e(t(),1),Re=`${Ee}/agent`;async function S(e,t){let n=await fetch(`${Re}${e}`,{...t,headers:{"Content-Type":`application/json`,...t?.headers??{}}}),r=await n.text(),i=null;try{i=r?JSON.parse(r):null}catch{i=null}if(!n.ok){let e=(i&&typeof i==`object`&&`error`in i?String(i.error):``)||r.slice(0,300)||`请求失败(${n.status})`;throw Error(e)}return i??{}}async function ze(e){return S(`/prepare`,{method:`POST`,body:JSON.stringify(e)})}async function Be(e,t){return S(`/open`,{method:`POST`,body:JSON.stringify({sessionId:e,url:t})})}async function C(e,t={}){return S(`/snapshot`,{method:`POST`,body:JSON.stringify({sessionId:e,...t})})}async function w(e,t){return S(`/action`,{method:`POST`,body:JSON.stringify({sessionId:e,...t})})}async function T(e,t={}){return S(`/wait`,{method:`POST`,body:JSON.stringify({sessionId:e,...t})})}async function Ve(e){return S(`/console`,{method:`POST`,body:JSON.stringify({sessionId:e})})}async function He(e){return S(`/network`,{method:`POST`,body:JSON.stringify({sessionId:e})})}async function Ue(e,t,n){return S(`/probe`,{method:`POST`,body:JSON.stringify({sessionId:e,ref:t,stepId:n})})}async function We(e,t){return S(`/screenshot`,{method:`POST`,body:JSON.stringify({sessionId:e,label:t})})}async function Ge(e){await S(`/close`,{method:`POST`,body:JSON.stringify({sessionId:e})})}async function E(e){return S(`/save`,{method:`POST`,body:JSON.stringify(e)})}async function Ke(e,t,n={}){return S(`/emit`,{method:`POST`,body:JSON.stringify({ir:e,target:t,...n})})}async function D(e,t,n){return S(`/verify`,{method:`POST`,body:JSON.stringify({sessionId:e,ir:t,target:n,timeoutMs:18e4})})}async function qe(e){return S(`/write`,{method:`POST`,body:JSON.stringify(e)})}async function Je(e){return S(`/sessions?projectId=${encodeURIComponent(e)}`)}async function O(e){return S(`/session?id=${encodeURIComponent(e)}`)}async function Ye(e,t){return S(`/debug`,{method:`POST`,body:JSON.stringify({sessionId:e,mode:t})})}async function Xe(e){return S(`/debug/stop`,{method:`POST`,body:JSON.stringify({sessionId:e})})}async function Ze(e){return S(`/changes?sessionId=${encodeURIComponent(e)}`)}async function Qe(e){return S(`/reveal`,{method:`POST`,body:JSON.stringify(e)})}var k=null;async function $e(e=!1){return(!k||e)&&(k=S(`/apps`).then(e=>({apps:e.apps??[],defaultId:e.defaultId??``})).catch(e=>{throw k=null,e})),k}async function et(e,t){return S(`/run-file`,{method:`POST`,body:JSON.stringify({sessionId:e,path:t,timeoutMs:18e4})})}async function tt(e){return S(`/draft/clean`,{method:`POST`,body:JSON.stringify({sessionId:e})})}var A={type:`string`,description:`快照里的 ref,例如 d1-e12。页面导航后会失效。`},nt={type:`function`,function:{name:`ui_plan_steps`,description:`提交整份步骤计划(人可读的动作 + 目标描述,不含定位器)。这一步只做测试设计,不会打开浏览器。`,parameters:{type:`object`,properties:{title:{type:`string`,description:`用例标题,中文即可`},steps:{type:`array`,description:`按执行顺序排列的计划步骤`,items:{type:`object`,properties:{action:{type:`string`,enum:[`goto`,`click`,`fill`,`select`,`press`,`hover`,`expect`,`expectUrl`,`wait`],description:`测试动作;不要写「截图」——截图是探索时给人看的,不是测试步骤`},target:{type:`string`,description:`给人看的目标描述,例如「右上角的登录按钮」「用户名输入框」`},value:{type:`string`,description:"输入内容 / 选项;账号密码等占位数据写成 ${ENV_NAME}"},url:{type:`string`,description:`goto / expectUrl 的地址,相对路径即可`},note:{type:`string`,description:`补充说明,例如断言什么结果`}},required:[`action`,`target`]}}},required:[`steps`]}}},rt=[nt],it=[nt,{type:`function`,function:{name:`ui_browser_open`,description:`在浏览器里打开一个地址(相对地址会用 baseURL 拼接),返回页面快照。`,parameters:{type:`object`,properties:{url:{type:`string`,description:`绝对地址或 / 开头的相对地址`}},required:[`url`]}}},{type:`function`,function:{name:`ui_browser_snapshot`,description:`重新获取当前页面快照。页面变化较大、或 ref 不确定时用。`,parameters:{type:`object`,properties:{depth:{type:`number`,description:`快照深度,默认 6,越大越啰嗦`},targetRef:{type:`string`,description:`只看某个元素的子树`}}}}},{type:`function`,function:{name:`ui_browser_click`,description:`点击一个元素。成功后会自动返回新快照。`,parameters:{type:`object`,properties:{ref:A,note:{type:`string`,description:`这一步在做什么`}},required:[`ref`]}}},{type:`function`,function:{name:`ui_browser_fill`,description:`填写输入框(会先清空已有内容)。`,parameters:{type:`object`,properties:{ref:A,text:{type:`string`,description:"要填入的内容;占位数据用 ${ENV_NAME} 表示环境变量"},note:{type:`string`}},required:[`ref`,`text`]}}},{type:`function`,function:{name:`ui_browser_select`,description:`选择下拉框选项(按 value 或可见文本)。`,parameters:{type:`object`,properties:{ref:A,value:{type:`string`},note:{type:`string`}},required:[`ref`,`value`]}}},{type:`function`,function:{name:`ui_browser_press`,description:`按一个键,例如 Enter / Tab / Escape。`,parameters:{type:`object`,properties:{key:{type:`string`},ref:{type:`string`}},required:[`key`]}}},{type:`function`,function:{name:`ui_browser_hover`,description:`悬停到元素上(用于展开菜单)。`,parameters:{type:`object`,properties:{ref:A,note:{type:`string`}},required:[`ref`]}}},{type:`function`,function:{name:`ui_browser_back`,description:`浏览器后退一步。`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`ui_browser_wait`,description:`等待:给 text 时等到页面出现该文案(比死等毫秒可靠),否则等待指定毫秒。返回等待后的快照。`,parameters:{type:`object`,properties:{text:{type:`string`,description:`要等待出现的可见文案`},ms:{type:`number`,description:`没有 text 时等待的毫秒数`},timeout:{type:`number`,description:`等待 text 的超时毫秒数,默认 15000`}}}}},{type:`function`,function:{name:`ui_browser_screenshot`,description:`截一张当前页面图,给用户看(模型看不到图片内容)。`,parameters:{type:`object`,properties:{label:{type:`string`,description:`截图标签,例如 after-login`}}}}},{type:`function`,function:{name:`ui_browser_console`,description:`读取浏览器控制台里的 error / warning / pageerror(排查偶发失败用)。`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`ui_browser_network`,description:`读取最近的失败请求(状态码 ≥ 400 或请求失败),用来判断是不是接口挂了。`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`ui_locator_probe`,description:`把一个 ref 转成可写进脚本的定位器,并校验唯一性。写步骤之前,对每个要操作的元素都调用一次。`,parameters:{type:`object`,properties:{ref:A,stepId:{type:`string`,description:`可选:左侧计划里的步骤 id(如 p2)。传了会把定位器回填到该步骤。`}},required:[`ref`]}}},{type:`function`,function:{name:`ui_test_set_steps`,description:`提交 / 替换整份测试步骤(IR)。每次提交都会刷新右侧代码预览。先探索、再提交,不要凭想象写定位器。`,parameters:{type:`object`,properties:{title:{type:`string`,description:`用例标题,中文即可`},steps:{type:`array`,description:`按执行顺序排列的步骤`,items:{type:`object`,properties:{action:{type:`string`,enum:[`goto`,`click`,`fill`,`select`,`press`,`hover`,`expect`,`expectUrl`,`wait`,`screenshot`]},locator:{type:`object`,description:`定位器。首选 ui_locator_probe 给出的 recommended,不要自己拼长 CSS`,properties:{kind:{type:`string`,enum:[`testid`,`role`,`label`,`placeholder`,`text`,`attr`,`css`]},role:{type:`string`},name:{type:`string`},value:{type:`string`},attr:{type:`string`},exact:{type:`boolean`},nth:{type:`number`,description:`同名元素有多个时取第几个(0 = 第一个)。用 ui_locator_probe 返回的 nth,不要自己猜`}},required:[`kind`]},url:{type:`string`},value:{type:`string`,description:`输入内容 / 选项值 / 截图名`},key:{type:`string`},text:{type:`string`,description:`expect 时要断言的文本`},state:{type:`string`,enum:[`visible`,`hidden`]},ms:{type:`number`},note:{type:`string`},planStepId:{type:`string`,description:`可选:对应左侧计划步骤 id,便于逐条勾掉计划`}},required:[`action`]}}},required:[`steps`]}}},{type:`function`,function:{name:`ui_test_get_steps`,description:`读取当前已提交的步骤,改之前先看一眼。`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`ui_test_verify`,description:`在临时目录试跑当前步骤对应的脚本,返回是否通过和日志尾部。`,parameters:{type:`object`,properties:{}}}}],at=`浏览器已被关闭,这一轮探索已结束`;function ot(e){if(!e||!e.includes(`error`))return!1;let t;try{t=JSON.parse(e)}catch{return!1}if(!t||typeof t!=`object`)return!1;let n=String(t.error??``);return n.includes(`浏览器已被关闭`)||n.includes(`浏览器进程已退出`)||n.includes(`Target page, context or browser has been closed`)}var j=(e,t)=>e.length>t?`${e.slice(0,t)}…(已截断)`:e;async function st(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`工具参数不是合法 JSON`})}let i=n.sessionId,a=e=>typeof r[e]==`string`?String(r[e]):``;try{if(e===`ui_plan_steps`){let e=Array.isArray(r.steps)?r.steps:[];if(!e.length){let e=await O(i).then(e=>e.session.plan??[]).catch(()=>[]);return JSON.stringify({ok:!0,stepCount:e.length,plan:e.map(e=>({id:e.id,action:e.action,target:e.target})),note:`没有提交新步骤,计划保持不变。`})}let t=(await E({sessionId:i,title:a(`title`)||void 0,plan:e,mergePlan:!0})).session.plan??[];return n.onPlan?.(t),JSON.stringify({ok:!0,stepCount:t.length,plan:t.map(e=>({id:e.id,action:e.action,target:e.target})),note:`计划已保存,用户可以在左侧调整。接下来开始探索:逐个 probe 并回填定位器。`})}if(e===`ui_browser_open`){let e=await Be(i,a(`url`));return JSON.stringify({url:e.url,title:e.title,elements:e.count,truncated:e.truncated,snapshot:j(e.snapshot,12e3)})}if(e===`ui_browser_snapshot`){let e=await C(i,{depth:Number(r.depth)||void 0,targetRef:a(`targetRef`)||void 0});return JSON.stringify({url:e.url,title:e.title,elements:e.count,truncated:e.truncated,snapshot:j(e.snapshot,12e3)})}if(e===`ui_browser_click`||e===`ui_browser_fill`||e===`ui_browser_select`||e===`ui_browser_hover`){let t=await w(i,{action:e.replace(`ui_browser_`,``),ref:a(`ref`),text:a(`text`),value:a(`value`),note:a(`note`)});return JSON.stringify({ok:!0,action:t.action,url:t.url,snapshot:j(t.snapshot,9e3)})}if(e===`ui_browser_press`){let e=await w(i,{action:`press`,ref:a(`ref`),key:a(`key`)});return JSON.stringify({ok:!0,url:e.url,snapshot:j(e.snapshot,9e3)})}if(e===`ui_browser_back`){let e=await w(i,{action:`back`});return JSON.stringify({ok:!0,url:e.url,snapshot:j(e.snapshot,9e3)})}if(e===`ui_browser_wait`){let e=await T(i,{text:a(`text`)||void 0,ms:Number(r.ms)||void 0,timeout:Number(r.timeout)||void 0});return JSON.stringify({ok:!0,action:e.action,url:e.url,snapshot:j(e.snapshot,9e3)})}if(e===`ui_browser_screenshot`){let e=await We(i,a(`label`)||`snapshot`);return n.onShot?.(e.url),JSON.stringify({ok:!0,url:e.url,note:`截图已显示在面板里;你看不到图片内容,需要判断结构请用快照。`})}if(e===`ui_browser_console`){let e=(await Ve(i)).messages??[];return JSON.stringify(e.length?{count:e.length,messages:e.slice(-20)}:{count:0})}if(e===`ui_browser_network`){let e=(await He(i)).requests??[];return JSON.stringify(e.length?{count:e.length,requests:e.slice(-20)}:{count:0})}if(e===`ui_locator_probe`){let e=a(`ref`);if(!e)return JSON.stringify({error:`缺少 ref`});let t=a(`stepId`),r=await Ue(i,e,t||void 0);return t&&r.plan&&n.onPlan?.(r.plan),JSON.stringify({ref:r.ref,element:r.element,confidence:r.confidence,recommended:r.recommended,fragile:!!r.fragile,warning:r.warning??``,candidates:r.candidates.slice(0,3),boundStep:r.planStep?{id:r.planStep.id,status:r.planStep.status}:void 0,note:r.confidence===`high`?`定位器唯一且指向同一元素,可以写进步骤`:r.recommended?`能用但不稳:${r.warning||`同名元素较多`}。照抄 recommended(含 nth),并补一条结果断言`:`没有唯一候选:换一个更具体的元素,或改成对结果文案的 expect`})}if(e===`ui_test_set_steps`){let e=Array.isArray(r.steps)?r.steps:[],t={title:a(`title`)||`未命名流程`,target:n.target,steps:e},o=await E({sessionId:i,title:t.title,ir:t}),s=o.session.ir??t,c=t.steps.length-s.steps.length;return n.onIr?.(s),n.onCode?.(o.code,o.suggestedPath),JSON.stringify({ok:!0,title:s.title,stepCount:s.steps.length,previewPath:o.suggestedPath,note:c?`步骤已保存,但有 ${c} 步被丢掉(动作不支持或没带 locator)。用 ui_test_get_steps 核对后重新提交;不要自己试跑,试跑由用户确认代码后手动发起。`:`步骤已保存,右侧代码预览已刷新。不要自己试跑:试跑由用户确认代码后手动发起。`})}if(e===`ui_test_get_steps`){let e=await O(i);return JSON.stringify({title:e.session.ir?.title??``,steps:e.session.ir?.steps??[],suggestedPath:e.suggestedPath})}if(e===`ui_test_verify`){let e=await D(i),t=String(e.log??``);return typeof e.code==`string`&&n.onCode?.(e.code,e.suggestedPath??``),JSON.stringify({passed:!!e.passed,exitCode:e.exitCode??null,timedOut:!!e.timedOut,durationMs:e.durationMs??0,draftPath:e.draftPath??``,tracePath:e.tracePath??``,log:j(t.slice(-4e3),4e3),note:e.passed?`试跑通过。草稿留在 .lantern-ai 里,用户可以直接看 trace / 用 Playwright UI 调试,确认后再写入项目。`:`试跑失败:只改步骤 IR(定位器 / 等待 / 断言)。草稿和 trace 会保留,用户能打开看现场;如果是功能本身不符合预期,不要为了跑绿改断言。`})}return JSON.stringify({error:`未知工具:${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}function ct(e){return e?.length?e.map((e,t)=>{let n=[`${t+1}. [${e.id}] ${e.action}`];return e.target&&n.push(`目标:${e.target}`),e.url&&n.push(`url=${e.url}`),e.value&&n.push(`值=${e.value}`),e.locator&&n.push(`已绑定 ${M(e.locator)}`),n.join(` · `)}).join(`
2
- `):``}function M(e){if(!e)return``;let t=Number.isInteger(e.nth)?` nth=${e.nth}`:``;return e.kind===`role`?`role=${e.role??``}${e.name?` name="${e.name}"`:``}${t}`:e.kind===`attr`?`[${e.attr}="${e.value??``}"]${t}`:e.kind===`testid`?`testid=${e.value??``}${t}`:`${e.kind}="${e.value??e.name??``}"${t}`}function lt(e){return e===`python`?`Python + pytest + playwright.sync_api`:`TypeScript + @playwright/test`}function ut(e,t){return e.replaceAll(`{{project}}`,t.project).replaceAll(`{{dir}}`,t.dir).replaceAll(`{{language}}`,t.language).replaceAll(`{{plan}}`,t.plan)}function dt(e,t,n,r,i){let a=ct(n);if(r?.trim()){let n=ut(r.trim(),{project:e.name,dir:e.dir,language:lt(t),plan:a||`如果还没有计划:先调用 ui_plan_steps 列出计划,再开始探索。`}),o=String(i??``).trim();return o?`${n}\n\n${o}`:n}return[`你是 UI 自动化测试工程师:用浏览器把流程点一遍,确认元素能唯一定位,再提交步骤。`,`项目:${e.name}(${e.dir}),目标语言:${lt(t)}。`,`ref 导航后失效要重新 snapshot;每个元素先用 ui_locator_probe 拿唯一定位器,再用 ui_test_set_steps 提交。`,"探索阶段不要自己试跑;至少一条 expect 断言用户可见的结果;账号等占位值写成 ${ENV_NAME}。",a?`\n${a}`:``,`最后用中文简短汇报。`].filter(Boolean).join(`
3
- `)}function ft(e,t,n){return n?.trim()?ut(n.trim(),{project:e.name,dir:e.dir,language:lt(t),plan:``}):[`你是测试设计师:只把需求拆成「动作 + 目标描述」的步骤计划,不打开浏览器、不写定位器。`,`项目:${e.name}(${e.dir}),目标语言:${lt(t)}。`,`只调用一次 ui_plan_steps;4~12 步,覆盖打开页面、前置、核心操作与至少一条结果断言。`,"账号密码等写成 ${ENV_NAME}。"].join(`
4
- `)}function pt(e,t,n){return[`需求 / 流程:`,e.trim(),``,t?`起始地址(baseURL):${t}`:`起始地址:从需求里判断,用相对路径。`,`目标语言:${n===`python`?`Python (pytest)`:`TypeScript`}`,``,`请给出步骤计划。`].join(`
5
- `)}function mt(e,t,n,r){return[`要自动化的流程 / 需求:`,e.trim(),``,t?`起始地址(baseURL):${t}`:`起始地址:从需求里判断,用相对路径。`,`目标语言:${n===`python`?`Python (pytest)`:`TypeScript`}`,r?.length?`
6
- 已确认的步骤计划(按顺序执行,probe 时带上 stepId):
7
- `+ct(r):``,``,`请开始:打开页面、探索并确认元素、提交步骤。`].filter(Boolean).join(`
8
- `)}var N=ne(),ht=`ui-auto.openapp`,gt={finder:`#3b82f6`,terminal:`#334155`,editor:`#64748b`};function _t({app:e,size:t=16}){let[n,r]=(0,x.useState)(!1);return!e.iconUrl||n?e.kind===`finder`?(0,N.jsx)(`svg`,{className:`shrink-0 text-[#3b82f6]`,width:t,height:t,viewBox:`0 0 20 20`,fill:`currentColor`,"aria-hidden":`true`,children:(0,N.jsx)(`path`,{d:`M2 5.5A1.5 1.5 0 013.5 4h4l1.5 2h7.5A1.5 1.5 0 0118 7.5v7A1.5 1.5 0 0116.5 16h-13A1.5 1.5 0 012 14.5v-9z`})}):e.kind===`terminal`?(0,N.jsxs)(`svg`,{className:`shrink-0 text-stone-700`,width:t,height:t,viewBox:`0 0 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,"aria-hidden":`true`,children:[(0,N.jsx)(`rect`,{x:`2.5`,y:`3.5`,width:`15`,height:`13`,rx:`2`}),(0,N.jsx)(`path`,{d:`M6 8l2.5 2L6 12M10.5 12.5h3.5`,strokeLinecap:`round`,strokeLinejoin:`round`})]}):(0,N.jsx)(`span`,{className:`flex shrink-0 items-center justify-center rounded-[4px] text-[9px] font-semibold text-white`,style:{width:t,height:t,backgroundColor:gt[e.kind]??`#94a3b8`},"aria-hidden":`true`,children:e.label.slice(0,1).toUpperCase()}):(0,N.jsx)(`img`,{src:e.iconUrl,alt:``,width:t,height:t,className:`shrink-0 rounded-[4px] object-contain`,onError:()=>r(!0)})}function vt({onOpen:e,disabled:t=!1,compact:n=!1}){let[r,o]=(0,x.useState)([]),[s,c]=(0,x.useState)(``),[l,u]=(0,x.useState)(()=>a(ht)),[ne,re]=(0,x.useState)(!1);(0,x.useEffect)(()=>{let e=!0;return $e().then(t=>{e&&(o(t.apps),c(t.defaultId))}).catch(()=>void 0).finally(()=>{e&&re(!0)}),()=>{e=!1}},[]);let p=r.find(e=>e.id===l)??r.find(e=>e.id===s),ie=r.length>0,ae=t||!ie,oe=t=>{t&&(u(t.id),i(ht,t.id),e(t))};return(0,N.jsxs)(`div`,{className:`inline-flex shrink-0 overflow-hidden rounded-lg border border-stone-200 bg-white ${n?`h-7`:`h-8`} ${ae?`opacity-50`:``}`,children:[(0,N.jsx)(`button`,{type:`button`,className:`flex items-center px-1.5 transition-colors enabled:hover:bg-stone-50 disabled:cursor-not-allowed`,onClick:()=>{ie&&e(p??null)},disabled:ae,"aria-label":p?`用 ${p.label} 打开`:`打开方式`,children:p?(0,N.jsx)(_t,{app:p,size:n?14:16}):(0,N.jsx)(`span`,{className:`px-1 text-[11px] text-stone-400`,children:ne?`无可用应用`:`加载中`})}),(0,N.jsx)(`span`,{className:`my-1 w-px shrink-0 bg-stone-200`,"aria-hidden":`true`}),(0,N.jsxs)(te,{as:`div`,className:`relative flex`,children:[(0,N.jsx)(f,{type:`button`,className:`flex w-7 items-center justify-center text-stone-400 transition-colors enabled:hover:bg-stone-50 enabled:hover:text-stone-600 disabled:cursor-not-allowed`,disabled:ae,"aria-label":`选择打开方式`,children:(0,N.jsx)(`svg`,{className:`h-3.5 w-3.5`,viewBox:`0 0 20 20`,fill:`currentColor`,"aria-hidden":`true`,children:(0,N.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})}),(0,N.jsxs)(ee,{anchor:{to:`bottom end`,gap:4,padding:12},transition:!0,className:`tw-select-menu tw-menu-anim z-80 w-max min-w-[180px] space-y-0.5 rounded-lg p-1 pb-2 shadow-lg ring-1 ring-stone-200 focus:outline-none`,children:[r.map(e=>{let t=e.id===(l||s);return(0,N.jsx)(d,{children:(0,N.jsxs)(`button`,{type:`button`,className:`flex w-full select-none items-center gap-2 rounded-md px-2.5 py-1.5 text-left text-sm ${t?`bg-(--tw-accent-soft) font-medium text-(--tw-accent)`:`text-stone-700 data-[focus]:bg-stone-50`}`,onClick:()=>oe(e),children:[(0,N.jsx)(_t,{app:e,size:18}),(0,N.jsx)(`span`,{className:`truncate`,children:e.label}),e.id===s?(0,N.jsx)(`span`,{className:`ml-auto shrink-0 pl-3 text-[11px] text-stone-400`,children:`默认`}):null]})},e.id)}),r.length?null:(0,N.jsx)(`div`,{className:`px-2.5 py-2 text-xs text-stone-400`,children:`没有探测到可用应用`})]})]})]})}var yt=`bg-[var(--tw-surface-panel)] border-[var(--tw-border)]`,P=`divide-[var(--tw-border)]`,F=`border-[var(--tw-border)]`,bt=`text-[var(--tw-label-primary)]`,I=`text-[var(--tw-label-secondary)]`,L=`text-[var(--tw-label-tertiary)]`,R=`hover:bg-[var(--tw-session-hover-bg)]`,z=`h-8 min-w-0 rounded-lg border ${F} bg-[var(--tw-surface-recessed)] px-2.5 text-xs ${bt} outline-none transition-colors placeholder:text-[var(--tw-label-tertiary)] focus:border-[#3370ff]`,B=`inline-flex h-8 shrink-0 items-center gap-1.5 rounded-lg bg-[#4176e6] px-3 text-sm font-medium text-white transition-colors hover:bg-[#3566d0] disabled:cursor-not-allowed disabled:opacity-50`,V=`shrink-0 rounded px-1.5 py-0.5 text-[11px] ${L} transition-colors`;function xt({open:e,projectName:t,detected:n,customTasks:r,hiddenCount:i,editedCount:a,error:o,onClose:ee,onAdd:d,onRemove:te,onEdit:f,onHide:ne,onReset:re,onRescan:p}){let[ie,ae]=(0,x.useState)(``),[oe,se]=(0,x.useState)(``),[ce,le]=(0,x.useState)(!1),[ue,de]=(0,x.useState)(!1),[fe,pe]=(0,x.useState)(``),[me,m]=(0,x.useState)(``),[h,he]=(0,x.useState)(``),[ge,_e]=(0,x.useState)(``);(0,x.useEffect)(()=>{e&&(ae(``),se(``),le(!1),de(!1),pe(``),m(``))},[e]);let ve=async()=>{let e=oe.trim();if(e&&!ce){le(!0);try{await d(ie.trim(),e),ae(``),se(``)}finally{le(!1)}}},g=async()=>{if(!ue){de(!0);try{await p(),pe(new Date().toLocaleTimeString(`zh-CN`,{hour12:!1}))}finally{de(!1)}}},ye=e=>{m(e.id),he(e.edited?e.display:``),_e(e.command)},be=async()=>{if(!me)return;let e=me;m(``),await f(e,h,ge)};return(0,N.jsxs)(l,{open:e,onClose:ee,transition:!0,className:`relative z-110`,children:[(0,N.jsx)(u,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,N.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,N.jsxs)(s,{transition:!0,className:`tw-dialog-panel-anim relative flex max-h-[80vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border shadow-xl ${yt}`,children:[(0,N.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b px-5 py-4 ${F}`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(c,{className:`text-base font-semibold ${bt}`,children:`运行配置`}),(0,N.jsxs)(`p`,{className:`mt-1 truncate text-xs leading-relaxed ${L}`,children:[t,` · 命令在该项目目录下用 shell 执行,支持引号与 &&`]})]}),(0,N.jsx)(`button`,{type:`button`,onClick:ee,className:`tw-confirm-cancel -mr-1 -mt-1 flex h-7 w-7 shrink-0 items-center justify-center rounded-md ${L} transition-colors hover:bg-[var(--tw-session-hover-bg)] hover:text-[var(--tw-label-primary)]`,"aria-label":`关闭`,children:`✕`})]}),(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:[(0,N.jsxs)(`section`,{className:`border-b px-5 py-4 ${F}`,children:[(0,N.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium ${I}`,children:`自定义命令`}),(0,N.jsxs)(`span`,{className:`text-[11px] ${L}`,children:[r.length,` 条`]})]}),r.length?(0,N.jsx)(`ul`,{className:`mt-2 divide-y rounded-lg border ${P} ${F}`,children:r.map(e=>(0,N.jsxs)(`li`,{className:`flex min-w-0 items-center gap-2 px-2.5 py-1.5`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate ${I}`,children:e.name?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{className:`text-xs`,children:e.name}),(0,N.jsx)(`span`,{className:`ml-1.5 font-mono text-[11px] ${L}`,children:e.command})]}):(0,N.jsx)(`span`,{className:`font-mono text-[11px] ${I}`,children:e.command})}),(0,N.jsx)(`button`,{type:`button`,className:`${V} hover:bg-red-50 hover:text-red-600`,onClick:()=>void te(e.id),children:`删除`})]},e.id))}):(0,N.jsx)(`p`,{className:`mt-2 rounded-lg border border-dashed px-2.5 py-2 text-[11px] ${F} ${L}`,children:`还没有自定义命令。名称可以不填,不填时下拉里直接显示命令。`}),(0,N.jsxs)(`div`,{className:`mt-2 flex min-w-0 items-center gap-2`,children:[(0,N.jsx)(`input`,{className:`${z} w-28 shrink-0`,value:ie,onChange:e=>ae(e.target.value),placeholder:`名称(可选)`,"aria-label":`运行任务名称`}),(0,N.jsx)(`input`,{className:`${z} flex-1 font-mono`,value:oe,onChange:e=>se(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ve()},placeholder:`npm run test:smoke`,"aria-label":`运行命令`,spellCheck:!1}),(0,N.jsxs)(`button`,{type:`button`,className:B,onClick:()=>void ve(),disabled:!oe.trim()||ce,children:[(0,N.jsx)(Le,{name:`plus`,size:13}),`添加`]})]})]}),(0,N.jsxs)(`section`,{className:`px-5 py-4`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium ${I}`,children:`自动发现`}),(0,N.jsxs)(`span`,{className:`text-[11px] ${L}`,children:[n.length,` 条`,fe?` · ${fe} 已扫描`:` · 挂载时扫描项目配置`]}),i||a?(0,N.jsxs)(`span`,{className:`text-[11px] ${L}`,children:[`已改 `,a,` · 已删 `,i]}):null,(0,N.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[i||a?(0,N.jsx)(`button`,{type:`button`,className:`${V} hover:bg-[var(--tw-session-hover-bg)] hover:text-[#4176e6]`,onClick:()=>void re(),children:`恢复默认`}):null,(0,N.jsxs)(`button`,{type:`button`,className:`${V} inline-flex items-center gap-1 hover:bg-[var(--tw-session-hover-bg)] hover:text-[var(--tw-label-primary)] disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void g(),disabled:ue,children:[(0,N.jsxs)(`svg`,{className:`h-3 w-3 shrink-0 ${ue?`animate-spin`:``}`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,N.jsx)(`path`,{d:`M21 12a9 9 0 1 1-2.6-6.4`}),(0,N.jsx)(`path`,{d:`M21 4v5h-5`})]}),ue?`扫描中…`:`重新扫描`]})]})]}),n.length?(0,N.jsx)(`ul`,{className:`mt-2 divide-y rounded-lg border ${P} ${F}`,children:n.map(e=>me===e.id?(0,N.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-center gap-2 px-2.5 py-2`,children:[(0,N.jsx)(`input`,{className:`${z} w-28 shrink-0`,value:h,onChange:e=>he(e.target.value),placeholder:`名称(留空用原名称)`,"aria-label":`修改名称 ${e.id}`}),(0,N.jsx)(`input`,{className:`${z} flex-1 font-mono`,value:ge,onChange:e=>_e(e.target.value),onKeyDown:e=>{e.key===`Enter`&&be(),e.key===`Escape`&&m(``)},placeholder:`命令`,"aria-label":`修改命令 ${e.id}`,spellCheck:!1}),(0,N.jsx)(`button`,{type:`button`,className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-2.5 text-xs text-white transition-colors hover:bg-[#3566d0]`,onClick:()=>void be(),children:`保存`}),(0,N.jsx)(`button`,{type:`button`,className:`h-8 shrink-0 rounded-lg border px-2.5 text-xs ${F} ${I} transition-colors hover:bg-[var(--tw-session-hover-bg)]`,onClick:()=>m(``),children:`取消`})]},e.id):(0,N.jsxs)(`li`,{className:`flex min-w-0 items-center gap-2 px-2.5 py-1.5 ${R}`,children:[(0,N.jsx)(`span`,{className:`w-24 shrink-0 truncate text-xs ${I}`,children:e.display||e.command}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px] ${L}`,children:e.command}),e.edited?(0,N.jsx)(`span`,{className:`shrink-0 rounded bg-amber-500/15 px-1.5 py-0.5 text-[10px] text-amber-600`,children:`已改`}):e.hint?(0,N.jsx)(`span`,{className:`hidden max-w-[170px] shrink-0 truncate text-[11px] sm:block ${L}`,children:e.hint}):null,(0,N.jsxs)(`span`,{className:`flex shrink-0 items-center gap-0.5`,children:[(0,N.jsx)(`button`,{type:`button`,className:`${V} hover:bg-[var(--tw-session-hover-bg)] hover:text-[var(--tw-label-primary)]`,onClick:()=>ye(e),children:`修改`}),(0,N.jsx)(`button`,{type:`button`,className:`${V} hover:bg-red-50 hover:text-red-600`,onClick:()=>void ne(e.id),children:`删除`})]})]},e.id))}):(0,N.jsx)(`p`,{className:`mt-2 rounded-lg border border-dashed px-2.5 py-2 text-[11px] ${F} ${L}`,children:`没扫到可复用命令(项目里没有测试脚本 / Makefile 目标 / marker),只保留全量运行。`}),(0,N.jsx)(`p`,{className:`mt-2 text-[11px] leading-relaxed ${L}`,children:`扫描来源:package.json 的 scripts、Makefile 目标、pytest markers、Maven profiles。改过的命令按原样用 shell 执行,不再追加框架参数。`})]})]}),o?(0,N.jsx)(`p`,{className:`shrink-0 border-t px-5 py-2 text-[11px] text-red-600 ${F}`,children:o}):null]})})]})}function H(e){return e.kind===`create`?{label:`新增`,className:`bg-emerald-50 text-emerald-600`}:e.kind===`merge`?{label:`追加`,className:`bg-sky-50 text-sky-600`}:{label:`修改`,className:`bg-amber-50 text-amber-600`}}function St({changes:e,git:t,draft:n,loading:r,onReveal:i,onRefresh:a}){let[o,s]=(0,x.useState)(``),c=(0,x.useMemo)(()=>e.find(e=>e.path===o)??e[0]??null,[o,e]);return(0,N.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-stone-100 px-3 py-1`,children:[(0,N.jsxs)(`span`,{className:`shrink-0 text-[11px] text-stone-500`,children:[`本次写入 `,(0,N.jsx)(`span`,{className:`font-medium text-stone-700`,children:e.length}),` 个文件`]}),n?.draftRoot?(0,N.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-stone-400`,children:n.draftRoot}):null,(0,N.jsxs)(`button`,{type:`button`,className:`ml-auto flex shrink-0 items-center gap-1 whitespace-nowrap text-[11px] text-[#3370ff] hover:underline disabled:opacity-40`,onClick:a,disabled:r,children:[`刷新`,(0,N.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block h-2 w-2 shrink-0 rounded-full border border-[#3370ff]/30 border-t-[#3370ff] ${r?`animate-spin`:`opacity-0`}`})]})]}),e.length===0?(0,N.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-1 px-4 text-center`,children:(0,N.jsx)(`p`,{className:`text-[11px] leading-relaxed text-stone-400`,children:`还没有写入项目。试跑通过后点「写入项目」,这里会出现精确到行的改动内容。`})}):(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,N.jsxs)(`div`,{className:`flex w-60 shrink-0 flex-col overflow-auto border-r border-stone-100`,children:[(0,N.jsx)(`div`,{className:`shrink-0`,children:e.map(e=>{let t=H(e),n=c?.path===e.path;return(0,N.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-1.5 px-2.5 py-1.5 text-left text-[11px] transition-colors ${n?`bg-[#f2f6ff]`:`hover:bg-stone-50`}`,onClick:()=>s(e.path),children:[(0,N.jsx)(`span`,{className:`shrink-0 rounded px-1 text-[10px] leading-4 ${t.className}`,children:t.label}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-stone-700`,children:e.path}),(0,N.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] text-emerald-600`,children:[`+`,e.added]}),(0,N.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] text-red-500`,children:[`-`,e.removed]})]},e.path)})}),t?.ok&&t.entries.length?(0,N.jsxs)(`details`,{className:`mt-auto shrink-0 border-t border-stone-100 px-2.5 py-1.5`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer list-none text-[11px] text-stone-500`,children:[`项目工作区其它改动 `,t.entries.length,t.truncated?`(截断)`:``]}),(0,N.jsx)(`ul`,{className:`mt-1 space-y-0.5`,children:t.entries.map(e=>(0,N.jsxs)(`li`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-stone-500`,children:[(0,N.jsx)(`span`,{className:`w-4 shrink-0 text-[#3370ff]`,children:e.code}),(0,N.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 truncate text-left hover:underline`,onClick:()=>i(e.path),children:e.path})]},`${e.code}-${e.path}`))})]}):null]}),c?(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-stone-100 px-3 py-1`,children:[(0,N.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-stone-600`,children:c.path}),(0,N.jsx)(`button`,{type:`button`,className:`ml-auto shrink-0 text-[11px] text-[#3370ff] hover:underline`,onClick:()=>i(c.path),children:`打开文件`}),(0,N.jsx)(`button`,{type:`button`,className:`shrink-0 text-[11px] text-[#3370ff] hover:underline`,onClick:()=>{let e=c.path.lastIndexOf(`/`);i(e===-1?``:c.path.slice(0,e))},children:`打开目录`})]}),(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto bg-stone-50/40`,children:[c.truncated?(0,N.jsx)(`p`,{className:`px-3 py-2 text-[11px] text-stone-500`,children:c.message}):null,(c.hunks??[]).map((e,t)=>(0,N.jsxs)(`div`,{className:`border-b border-stone-100`,children:[(0,N.jsxs)(`div`,{className:`bg-stone-100/70 px-3 py-0.5 font-mono text-[10px] text-stone-500`,children:[`@@ -`,e.oldStart,`,`,e.oldLines,` +`,e.newStart,`,`,e.newLines,` @@`]}),(0,N.jsx)(`div`,{className:`py-1`,children:(()=>{let t=e.oldStart,n=e.newStart;return e.lines.map((e,r)=>{let i=e.type===`add`?`+`:e.type===`del`?`-`:` `,a=e.type===`add`?``:t,o=e.type===`del`?``:n;return e.type!==`add`&&(t+=1),e.type!==`del`&&(n+=1),(0,N.jsxs)(`div`,{className:`flex gap-2 px-2 font-mono text-[11px] leading-5 ${e.type===`add`?`bg-emerald-50 text-emerald-800`:e.type===`del`?`bg-red-50 text-red-700`:`text-stone-600`}`,children:[(0,N.jsx)(`span`,{className:`w-8 shrink-0 select-none text-right text-[10px] text-stone-400`,children:a}),(0,N.jsx)(`span`,{className:`w-8 shrink-0 select-none text-right text-[10px] text-stone-400`,children:o}),(0,N.jsx)(`span`,{className:`w-2 shrink-0 select-none text-stone-400`,children:i}),(0,N.jsx)(`span`,{className:`whitespace-pre`,children:e.text||` `})]},r)})})()})]},`${c.path}-${t}`)),!c.truncated&&(c.hunks??[]).length===0?(0,N.jsx)(`p`,{className:`px-3 py-2 text-[11px] text-stone-400`,children:`内容没有变化`}):null]})]}):null]})]})}var Ct=[{value:`goto`,label:`打开页面`},{value:`click`,label:`点击`},{value:`fill`,label:`填写`},{value:`select`,label:`选择`},{value:`press`,label:`按键`},{value:`hover`,label:`悬停`},{value:`expect`,label:`断言元素`},{value:`expectUrl`,label:`断言地址`},{value:`wait`,label:`等待`}],U=`h-7 w-full rounded-md border border-stone-200 bg-white px-2 text-[11px] text-stone-700 outline-none transition-colors focus:border-[#3370ff]`,wt={pending:{label:`待绑定`,className:`bg-stone-100 text-stone-500`},bound:{label:`已绑定`,className:`bg-emerald-50 text-emerald-600`},done:{label:`已完成`,className:`bg-emerald-50 text-emerald-600`},failed:{label:`没绑上`,className:`bg-red-50 text-red-600`}};function Tt(e){let t=new Set(e.map(e=>e.id)),n=e.length+1;for(;t.has(`p${n}`);)n+=1;return`p${n}`}function Et({plan:e,disabled:t,onChange:n}){let r=(t,r)=>{n(e.map(e=>e.id===t?{...e,...r}:e))},i=(t,r)=>{let i=t+r;if(i<0||i>=e.length)return;let a=e.slice(),[o]=a.splice(t,1);a.splice(i,0,o),n(a)},a=t=>n(e.filter(e=>e.id!==t)),o=()=>n([...e,{id:Tt(e),action:`click`,target:``,status:`pending`}]),s=e.filter(e=>e.status===`bound`||e.status===`done`).length;return(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between px-1 pb-1.5`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium text-stone-600`,children:`步骤计划`}),e.length?(0,N.jsxs)(`span`,{className:`text-[11px] text-stone-400`,children:[s,`/`,e.length,` 已绑定`]}):null]}),(0,N.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,N.jsx)(`button`,{type:`button`,className:`text-[11px] text-[#3370ff] hover:underline disabled:opacity-40`,onClick:o,disabled:t||e.length>=40,children:`+ 添加`})})]}),(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-auto px-0.5`,children:[e.length===0?(0,N.jsxs)(`p`,{className:`rounded-lg border border-dashed border-stone-200 px-3 py-6 text-center text-[11px] leading-relaxed text-stone-400`,children:[`还没有步骤。`,(0,N.jsx)(`br`,{}),`输入需求后点「生成步骤」,这里会出来一份可以手动调整的计划。`]}):null,e.map((n,o)=>{let s=wt[n.status]??wt.pending,c=n.action===`fill`||n.action===`select`||n.action===`press`;return(0,N.jsxs)(`div`,{className:`rounded-lg border border-stone-200 bg-white px-2 py-1.5`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(`span`,{className:`w-4 shrink-0 text-center font-mono text-[10px] text-stone-400`,children:o+1}),(0,N.jsx)(`div`,{className:`w-[88px] shrink-0`,children:(0,N.jsx)(ie,{options:Ct,value:n.action,onChange:e=>r(n.id,{action:e}),disabled:t,unstyled:!0,ariaLabel:`步骤动作`,triggerClassName:`flex h-6 w-full items-center justify-between gap-1 rounded-md border border-stone-200 bg-white px-1 text-[10px] text-stone-600 outline-none transition-colors hover:border-stone-300 focus:border-[#3370ff] disabled:cursor-not-allowed disabled:opacity-50`,menuMinWidth:120})}),(0,N.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${s.className}`,children:s.label}),(0,N.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-0.5`,children:[(0,N.jsx)(`button`,{type:`button`,className:`px-1 text-[11px] text-stone-400 hover:text-stone-700 disabled:opacity-30`,onClick:()=>i(o,-1),disabled:t||o===0,"aria-label":`上移`,children:`↑`}),(0,N.jsx)(`button`,{type:`button`,className:`px-1 text-[11px] text-stone-400 hover:text-stone-700 disabled:opacity-30`,onClick:()=>i(o,1),disabled:t||o===e.length-1,"aria-label":`下移`,children:`↓`}),(0,N.jsx)(`button`,{type:`button`,className:`tw-icon-danger px-1 text-[11px]`,onClick:()=>a(n.id),disabled:t,"aria-label":`删除`,children:`×`})]})]}),(0,N.jsx)(`input`,{className:`${U} mt-1`,value:n.target,disabled:t,placeholder:n.action===`goto`?`打开哪个页面`:`目标描述,例如「登录按钮」`,onChange:e=>r(n.id,{target:e.target.value}),spellCheck:!1}),n.action===`goto`||n.action===`expectUrl`?(0,N.jsx)(`input`,{className:`${U} mt-1 font-mono`,value:n.url??``,disabled:t,placeholder:`/login`,onChange:e=>r(n.id,{url:e.target.value}),spellCheck:!1}):null,c?(0,N.jsx)(`input`,{className:`${U} mt-1 font-mono`,value:n.value??``,disabled:t,placeholder:n.action===`press`?`Enter`:"输入值 / 选项(${ENV} 占位)",onChange:e=>r(n.id,{value:e.target.value}),spellCheck:!1}):null,n.locator?(0,N.jsx)(`p`,{className:`mt-1 truncate font-mono text-[10px] text-emerald-700`,children:M(n.locator)}):null,n.warning?(0,N.jsx)(`p`,{className:`mt-0.5 text-[10px] leading-4 text-amber-600`,children:n.warning}):null]},n.id)})]})]})}var Dt=`inline-flex h-8 shrink-0 select-none items-center gap-1.5 whitespace-nowrap rounded-lg px-3 text-sm outline-none transition-[background-color,border-color,color,box-shadow,opacity,transform] duration-150 motion-safe:active:translate-y-px focus-visible:ring-2 focus-visible:ring-[#4176e6]/35 disabled:cursor-not-allowed disabled:motion-safe:active:translate-y-0`,W=`${Dt} font-medium text-white shadow-[0_1px_2px_rgba(23,43,99,0.12),inset_0_1px_0_rgba(255,255,255,0.18)] bg-[#4176e6] hover:bg-[#3566d0] active:bg-[#2f5cbd] active:shadow-none disabled:opacity-40 disabled:shadow-none disabled:hover:bg-[#4176e6] disabled:active:bg-[#4176e6]`,Ot=`${Dt} border border-stone-200 text-stone-600 hover:border-stone-300 hover:bg-stone-50 disabled:opacity-40`,kt=`${Dt} border border-red-200 bg-red-50 text-red-600 hover:opacity-90 active:opacity-80`,At=`inline-flex h-7 select-none items-center gap-1.5 whitespace-nowrap rounded-md px-2 text-xs outline-none transition-[background-color,color,box-shadow,opacity,transform] duration-150 motion-safe:active:translate-y-px focus-visible:ring-2 focus-visible:ring-[#4176e6]/30 disabled:cursor-not-allowed disabled:motion-safe:active:translate-y-0`,jt=`${At} text-stone-600 hover:bg-stone-100 disabled:opacity-40`,Mt=`${At} bg-(--tw-accent-soft) text-[#4176e6]`,Nt=`text-[11px] text-[#3370ff] hover:underline disabled:opacity-40 disabled:no-underline`,Pt=`h-8 w-full rounded-lg border border-stone-200 bg-white px-2.5 text-xs text-stone-700 outline-none transition-colors focus:border-[#3370ff]`,Ft=3,It=`ui-auto.gen.panel`,Lt=160,Rt=260,zt=36,Bt=60,Vt=`ui-auto.gen.side`,Ht=330,Ut=560,Wt=380,Gt=`ui-auto.gen.top`,Kt=`ui-auto.gen.bottom`,qt=`ui-auto.gen.target`,Jt=72,Yt=420,Xt=Jt,Zt=`ui-auto.gen.reqheight`,Qt=[{value:`activity`,label:`探索活动`},{value:`code`,label:`代码`},{value:`changes`,label:`变更`}],$t=[{value:`console`,label:`控制台`},{value:`network`,label:`网络`},{value:`run`,label:`试跑`}];function en(e,t,n){let r=a(e);return t.includes(r)?r:n}var tn=`ui-auto.requirement`;function nn(){let e=o(tn,``);return typeof e==`string`&&e?e:a(tn,``)}function rn(e,t,n,r){let i=Number(a(e));return!Number.isFinite(i)||i<t?r:Math.min(i,n)}function an(e,t){let n=a(e);return n===`1`||n!==`0`&&t}var on=[{value:`1`,label:`有头(可围观)`},{value:`0`,label:`无头(更快)`}];function sn(e,t){let n=t.some(e=>e.endsWith(`.py`)),r=t.some(e=>/\.(ts|js|mjs|cjs|tsx|jsx)$/.test(e));return e===`pytest`||n&&!r?{options:[{value:`python`,label:`Python`}],fallback:`python`}:{options:[{value:`ts`,label:`TypeScript`},{value:`python`,label:`Python`}],fallback:`ts`}}var cn=new Set([`goto`,`click`,`fill`,`select`,`press`,`hover`,`expect`,`expectUrl`,`wait`]);function ln(e){return e.filter(e=>cn.has(e.action))}function un(e,t){if(!t.length)return e;let n=new Map(t.map(e=>[e.id,e])),r=e.map(e=>{let t=n.get(e.id);return t?{...e,status:t.status,locator:t.locator,warning:t.warning}:e});for(let n of t)e.some(e=>e.id===n.id)||r.push(n);return ln(r)}function dn(e,t){if(!t)return``;if(e!==`ui_browser_fill`&&e!==`ui_browser_select`)return t.slice(0,240);try{let e=JSON.parse(t);for(let t of[`text`,`value`]){let n=e[t];typeof n==`string`&&!n.startsWith("${")&&(e[t]=n.replace(/[\s\S]/g,`•`))}return JSON.stringify(e).slice(0,240)}catch{return t.slice(0,240)}}function fn(e){window.dispatchEvent(new CustomEvent(`lantern:uiauto-changed`,{detail:{count:e}}))}function pn(e){return e.split(`/`).pop()||e}function mn(e){let t=e.split(`/`);return t.pop(),t.join(`/`)||`.`}function hn(e){return e===`page`?{label:`页面`,className:`bg-sky-50 text-sky-600`}:e===`fixture`?{label:`登录态`,className:`bg-violet-50 text-violet-600`}:{label:`用例`,className:`bg-emerald-50 text-emerald-600`}}function gn({project:e,promptFile:t,onError:o}){let[s,c]=(0,x.useState)(null),l=(0,x.useCallback)(async()=>h(t),[t]),u=(0,x.useCallback)(async()=>{let e=await l();return!e.plan.trim()&&!e.agent.trim()?(ae(`没有读到「提示词管理」里的「${e.file||`Playwright提示词.md`}」。本平台提示词以提示词管理为准,请先在「提示词管理」里写好(需包含「## 规划阶段」「## 探索阶段」)再生成。`,`error`),null):e},[l]),ee=(0,x.useMemo)(()=>sn(e.framework,e.specFiles??[]),[e.framework,e.specFiles]),[d,te]=(0,x.useState)(()=>{let{options:t,fallback:n}=sn(e.framework,e.specFiles??[]),r=a(qt);return t.some(e=>e.value===r)?r:n}),[f,ne]=(0,x.useState)(nn),re=`ui-auto.baseurl.${e.id}`,[p,oe]=(0,x.useState)(()=>e.baseURL||a(re)||e.detectedBaseURL||a(`ui-auto.baseurl`)||`http://localhost:5173`),[ce,pe]=(0,x.useState)(e.detectedBaseURL||``),me=`ui-auto.storage.${e.id}`,[m,he]=(0,x.useState)(()=>e.storageState||e.detectedStorageState||a(me)||``),[_e,ve]=(0,x.useState)(e.detectedStorageState||``),[g,ye]=(0,x.useState)(()=>an(`ui-auto.headed`,!0)),[be,xe]=(0,x.useState)(()=>rn(Zt,Jt,Yt,Xt)),[Se,Ce]=(0,x.useState)(!1),we=(0,x.useRef)(null),[Te,Ee]=(0,x.useState)(()=>an(`ui-auto.gen.address`,!1)),[De,Oe]=(0,x.useState)(()=>an(`ui-auto.gen.accept`,!1)),[ke,Ae]=(0,x.useState)(!0),[_,v]=(0,x.useState)(`idle`),[je,Me]=(0,x.useState)([]),[y,Pe]=(0,x.useState)(null),[b,Fe]=(0,x.useState)([]),[Ie,Le]=(0,x.useState)(!1),[Re,S]=(0,x.useState)(!1),[Be,C]=(0,x.useState)(``),[w,T]=(0,x.useState)(``),[Ue,We]=(0,x.useState)([]),[k,$e]=(0,x.useState)(()=>a(`ui-auto.gen.file.${e.id}`)),[A,nt]=(0,x.useState)(()=>an(`ui-auto.gen.force`,!1)),[j,ct]=(0,x.useState)([]),[M,lt]=(0,x.useState)(()=>{let e=Number(a(Vt));return!Number.isFinite(e)||e<Ht?Wt:Math.min(e,Ut)}),ut=(0,x.useRef)(null),[ht,gt]=(0,x.useState)(``),[_t,yt]=(0,x.useState)(``),[P,F]=(0,x.useState)(``),[bt,I]=(0,x.useState)(``),[L,R]=(0,x.useState)(null),[z,B]=(0,x.useState)(0),[V,xt]=(0,x.useState)(()=>en(Kt,$t.map(e=>e.value),`run`)),[H,Ct]=(0,x.useState)(()=>en(Gt,Qt.map(e=>e.value),`activity`)),[U,wt]=(0,x.useState)(()=>{let e=Number(a(It));return!Number.isFinite(e)||e<zt||e<=Bt?Rt:Math.min(e,640)}),[Tt,Dt]=(0,x.useState)(()=>a(It)===`closed`),[At,cn]=(0,x.useState)(!1),gn=(0,x.useRef)(null),[xn,Sn]=(0,x.useState)([]),[Cn,wn]=(0,x.useState)([]),[Tn,En]=(0,x.useState)([]),[Dn,On]=(0,x.useState)(null),[G,K]=(0,x.useState)(null),[kn,An]=(0,x.useState)(!1),[q,jn]=(0,x.useState)(null),[Mn,Nn]=(0,x.useState)(!1),[Pn,Fn]=(0,x.useState)(``),[J,In]=(0,x.useState)(null),[Ln,Rn]=(0,x.useState)(!1),zn=(0,x.useRef)(null),Y=(0,x.useRef)(``),Bn=(0,x.useRef)(0),Vn=(0,x.useRef)([]),Hn=(0,x.useRef)(null),Un=(0,x.useRef)(null),Wn=(0,x.useRef)(null),Gn=(0,x.useRef)([]);(0,x.useEffect)(()=>{Gn.current=b},[b]);let[Kn,qn]=(0,x.useState)(!1);(0,x.useEffect)(()=>{let e=!0;n().then(()=>{e&&c(ue())});let t=le(()=>c(ue()));return()=>{e=!1,t()}},[]);let X=(0,x.useCallback)(e=>{Bn.current+=1;let t=Bn.current;return Me(n=>[...n,{...e,id:t,at:e.at??new Date().toISOString()}]),t},[]),Jn=(0,x.useRef)(null),Yn=(0,x.useRef)(``);(0,x.useEffect)(()=>{let e=Y.current;if(!e)return;let t=je.map(({kind:e,name:t,detail:n,status:r,at:i})=>({kind:e,name:t,detail:n,status:r,at:i})),n=JSON.stringify(t);n!==Yn.current&&(Yn.current=n,Jn.current&&window.clearTimeout(Jn.current),Jn.current=window.setTimeout(()=>{E({sessionId:e,activity:t}).catch(()=>void 0)},600))},[je]),(0,x.useEffect)(()=>{r(tn,f)},[f]),(0,x.useEffect)(()=>{i(re,p),i(`ui-auto.baseurl`,p)},[re,p]);let Xn=(0,x.useRef)(null),Zn=(0,x.useRef)(p);(0,x.useEffect)(()=>{p!==Zn.current&&(Zn.current=p,Xn.current&&window.clearTimeout(Xn.current),Xn.current=window.setTimeout(()=>{ge({id:e.id,baseURL:p}).then(e=>pe(e.detectedBaseURL||``)).catch(()=>void 0)},600))},[p,e.id]),(0,x.useEffect)(()=>{i(me,m)},[me,m]);let Qn=(0,x.useRef)(null),$n=(0,x.useRef)(m);(0,x.useEffect)(()=>{m!==$n.current&&($n.current=m,Qn.current&&window.clearTimeout(Qn.current),Qn.current=window.setTimeout(()=>{ge({id:e.id,storageState:m}).then(e=>ve(e.detectedStorageState||``)).catch(()=>void 0)},600))},[m,e.id]),(0,x.useEffect)(()=>{i(`ui-auto.headed`,g?`1`:`0`)},[g]),(0,x.useEffect)(()=>{i(`ui-auto.gen.force`,A?`1`:`0`)},[A]),(0,x.useEffect)(()=>{i(`ui-auto.gen.address`,Te?`1`:`0`)},[Te]),(0,x.useEffect)(()=>{i(`ui-auto.gen.accept`,De?`1`:`0`)},[De]),(0,x.useEffect)(()=>{k&&i(`ui-auto.gen.file.${e.id}`,k)},[k,e.id]),(0,x.useEffect)(()=>{Se||i(Zt,String(be))},[be,Se]);let er=(0,x.useCallback)(e=>{Ct(e),i(Gt,e)},[]),tr=(0,x.useCallback)(e=>{xt(e),i(Kt,e),Tt&&(Dt(!1),i(It,String(U)))},[Tt,U]),nr=(0,x.useCallback)(()=>{Dt(e=>{let t=!e;return i(It,t?`closed`:String(U)),t})},[U]),Z=(0,x.useCallback)(async()=>{if(!Y.current)En([]),On(null),K(null);else{An(!0);try{let e=await Ze(Y.current);En(e.changes),On(e.git),K(e.draft),e.changes.length&&fn(e.changes.length)}catch{}finally{An(!1)}}},[]),rr=(0,x.useCallback)(async(e,t,n=``)=>{if(!e?.steps?.length)return We([]),[];try{let r=await Ke(e,t,{testDir:n.includes(`/`)?n.replace(/\/[^/]+$/,``):`tests`});return We(r.files),$e(e=>r.files.some(t=>t.path===e)?e:r.files[0]?.path??``),r.files}catch{return[]}},[]),ir=(0,x.useCallback)(async()=>{if(!Y.current)return[];S(!0);try{let e=await O(Y.current);return C(e.code),T(e.suggestedPath),await rr(e.session.ir,e.session.target===`python`?`python`:`ts`,e.suggestedPath)}catch{return[]}finally{S(!1)}},[rr]);(0,x.useEffect)(()=>{let t=!0;return Pe(null),Y.current=``,Fe([]),C(``),R(null),yt(``),Me([]),En([]),On(null),K(null),jn(null),Fn(``),In(null),Ae(!0),Je(e.id).then(async n=>{if(!t)return;let r=n.sessions[0];if(!r){let t=e.baseURL||e.detectedBaseURL||``;Zn.current=t,oe(t),pe(e.detectedBaseURL||``);let n=e.storageState||e.detectedStorageState||``;$n.current=n,he(n),ve(e.detectedStorageState||``);return}let i=await O(r.id);if(!t)return;Pe(i.session),Y.current=i.session.id,Fe(ln(i.session.plan??[])),C(i.code),T(i.suggestedPath),We([]),$e(a(`ui-auto.gen.file.${e.id}`)),rr(i.session.ir,i.session.target===`python`?`python`:`ts`,i.suggestedPath),te(i.session.target===`python`?`python`:`ts`);let o=e.baseURL||i.session.baseURL||e.detectedBaseURL||``;Zn.current=o,oe(o),pe(e.detectedBaseURL||``);let s=e.storageState||i.session.storageState||e.detectedStorageState||``;if($n.current=s,he(s),ve(e.detectedStorageState||``),ne(e=>i.session.source||e),K(i.draft??null),En(i.changes??[]),i.session.lastVerify&&R({passed:i.session.lastVerify.passed,exitCode:i.session.lastVerify.exitCode,durationMs:i.session.lastVerify.durationMs,log:i.session.lastVerify.log}),Array.isArray(i.session.activity)&&i.session.activity.length){let e=i.session.activity.map(e=>{Bn.current+=1;let t=e.status===`running`?`failed`:e.status;return{id:Bn.current,kind:e.kind===`tool`||e.kind===`error`?e.kind:`info`,name:e.name,detail:e.detail,status:t,at:e.at}});Yn.current=JSON.stringify(e.map(({kind:e,name:t,detail:n,status:r,at:i})=>({kind:e,name:t,detail:n,status:r,at:i}))),Me(e)}i.session.savedPath&&er(`changes`),I(`已载入上次生成的草稿`),await Z()}).catch(()=>void 0).finally(()=>{t&&Ae(!1)}),()=>{t=!1}},[e.id,Z,rr,er]),(0,x.useEffect)(()=>{let{options:t,fallback:n}=sn(e.framework,e.specFiles??[]);t.some(e=>e.value===d)||te(n)},[e.framework,e.specFiles,d]),(0,x.useEffect)(()=>{Hn.current?.scrollTo({top:Hn.current.scrollHeight})},[je]),(0,x.useEffect)(()=>()=>{Un.current?.release(),zn.current?.abort(),Wn.current&&window.clearTimeout(Wn.current),Y.current&&(Xe(Y.current).catch(()=>void 0),Ge(Y.current).catch(()=>void 0))},[]),(0,x.useEffect)(()=>{if(!y?.id)return;let e=y.id;V===`console`?Ve(e).then(e=>Sn(e.messages??[])).catch(()=>Sn([])):V===`network`&&He(e).then(e=>wn(e.requests??[])).catch(()=>wn([]))},[V,y?.id]);let Q=_!==`idle`,ar=_===`exploring`||_===`verifying`||_===`repairing`,or=Q||!f.trim()||!b.length,sr=y?.status===`explored`||y?.status===`verified`||y?.status===`written`||y?.status===`failed`,cr=Q||!sr||!y?.ir?.steps?.length,lr=(0,x.useCallback)(()=>({sessionId:Y.current,target:d,onPlan:e=>Fe(t=>un(t,e)),onShot:e=>gt(e),onCode:(e,t)=>{C(e),T(t)},onIr:e=>{X({kind:`info`,name:`提交步骤`,detail:`${e.title} · ${e.steps.length} 步`,status:`done`})}}),[X,d]),ur=(0,x.useCallback)(async(e,t)=>{if(!s)throw de(`model`),Error(`请先配置模型`);let n=lr();for await(let r of se(s,e,t,{tools:it,maxToolRounds:40,runTool:async(e,t)=>{Un.current&&await Un.current.promise;let r=await st(e,t,n);if(ot(r)){for(let e of Vn.current.splice(0))Me(t=>t.map(t=>t.id===e?{...t,status:`failed`}:t));throw Error(at)}return r}}))if(r.type===`tool`){if(r.status===`running`){let e=X({kind:`tool`,name:r.name,detail:dn(r.name,r.args??``),status:`running`});Vn.current.push(e)}else{let e=Vn.current.pop();Me(t=>t.map(t=>t.id===e?{...t,status:`done`,detail:(r.result??``).slice(0,240)}:t))}}else r.type===`content`&&yt(e=>e+r.delta)},[X,s,lr]),dr=(0,x.useCallback)(async(t=!1)=>{let n=await ze({projectId:e.id,sessionId:Y.current||void 0,title:f.trim().split(/\r?\n/)[0]?.slice(0,60)||`未命名流程`,target:d,baseURL:p,storageState:m,source:f.trim(),headed:g,reset:t,plan:Gn.current.length?Gn.current:void 0});return Y.current=n.session.id,Pe(n.session),T(n.suggestedPath),K(n.draft),t&&(C(``),We([]),R(null),En([]),jn(null),In(null)),n.session.storageState&&he(n.session.storageState),n},[p,g,e.id,f,m,d]),fr=(0,x.useCallback)(async(t,n)=>{if(!s)throw de(`model`),Error(`请先配置模型`);let r=lr(),i=await l(),a=[{role:`system`,content:ft(e,d,i.plan)},{role:`user`,content:pt(t,p,d)}];for await(let e of se(s,a,n,{tools:rt,maxToolRounds:2,runTool:async(e,t)=>st(e,t,r)}))e.type===`tool`&&e.status===`running`?X({kind:`info`,name:`规划步骤`,detail:`只做测试设计,不打开浏览器`,status:`done`}):e.type===`content`&&yt(t=>t+e.delta);let o=ln((await O(Y.current)).session.plan??[]);return Fe(o),o},[p,l,e,X,s,d,lr]),pr=(0,x.useCallback)(async()=>{let e=f.trim();if(!e||Q)return;if(!s){F(`还没有配置模型,请先在设置里填好 API Key`),de(`model`);return}if(!await u())return;r(tn,e),i(`ui-auto.baseurl`,p),i(me,m),i(`ui-auto.headed`,g?`1`:`0`);let t=new AbortController;zn.current=t,F(``),I(``),yt(``),v(`planning`);try{await dr(!0);let n=await fr(e,t.signal);I(n.length?`已生成 ${n.length} 步计划,可以手动调整后再探索`:`没有得到步骤,补充需求后再试`)}catch(e){if(t.signal.aborted)I(`已停止`);else{let t=e instanceof Error?e.message:String(e);F(t),o?.(t),X({kind:`error`,name:`规划失败`,detail:t,status:`failed`})}}finally{zn.current=null,v(`idle`)}},[p,Q,dr,g,o,fr,X,u,f,s,m]),mr=(0,x.useCallback)(async(e,t)=>{let n=e;for(let e=0;e<=Ft;e+=1){B(e),v(`verifying`),tr(`run`);let r=X({kind:`info`,name:e?`第 ${e} 次修复后试跑`:`试跑`,detail:`写进 .lantern-ai 草稿并执行,失败保留现场`,status:`running`}),i=await D(Y.current);if(R(i),jn(null),typeof i.code==`string`&&C(i.code),Me(e=>e.map(e=>e.id===r?{...e,status:i.passed?`done`:`failed`,detail:i.passed?`通过 · ${Math.round((i.durationMs??0)/100)/10}s`:(i.log??i.error??``).slice(-800)}:e)),Z(),ir(),i.passed)return X({kind:`info`,name:`试跑通过`,detail:`${Math.round((i.durationMs??0)/100)/10}s · 草稿在 ${i.draftPath??``}`,status:`done`}),I(`试跑通过,可以打开草稿 / trace 调试,确认后写入项目`),Pe(e=>e&&{...e,status:`verified`}),v(`idle`),!0;if(e===Ft)break;v(`repairing`),n=[...n,{role:`user`,content:[`第 ${e+1} 次试跑失败(exitCode=${i.exitCode??`?`})。日志尾部:`,"```",(i.log??i.error??``).slice(-3500),"```",`请先调用 ui_test_get_steps 看当前步骤,只修改步骤 IR(定位器 / 等待 / 断言),再 ui_test_verify 重跑。`,`如果是页面行为本身不符合需求,不要为了跑绿改断言,直接在回答里说明疑似缺陷。`].join(`
9
- `)}],await ur(n,t)}return I(`自动修复 ${Ft} 轮仍未通过,请看试跑日志 / 打开 trace`),v(`idle`),!1},[tr,X,Z,ir,ur]),hr=(0,x.useCallback)(async()=>{let t=f.trim();if(!t||Q)return;if(!s){F(`还没有配置模型,请先在设置里填好 API Key`),de(`model`);return}if(!await u())return;r(tn,t),i(`ui-auto.baseurl`,p),i(me,m),i(`ui-auto.headed`,g?`1`:`0`);let n=new AbortController;zn.current=n,F(``),I(``),C(``),R(null),gt(``),B(0),We([]),ct([]),In(null),jn(null),Fn(``),yt(e=>e.trim()?`${e.trimEnd()}\n\n---\n\n`:e),er(`activity`),v(`exploring`);let a=``;try{let r=await dr(!0);a=r.session.id,X({kind:`info`,name:`探索开始`,detail:`${g?`有头`:`无头`}浏览器 · ${e.name}`,status:`done`});let i=b;if(i.length||(X({kind:`info`,name:`先规划步骤`,detail:`还没有计划,先做一次测试设计`,status:`done`}),i=await fr(t,n.signal)),!i.length){I(`没有得到步骤计划,请补充需求后重试`),v(`idle`);return}await E({sessionId:r.session.id,plan:i});let o=await l(),s=[{role:`system`,content:dt(e,d,i,o.agent,o.code)},{role:`user`,content:mt(t,p,d,i)}];await ur(s,n.signal);let c=await O(r.session.id);if(c.code&&(C(c.code),T(c.suggestedPath)),Fe(e=>un(e,c.session.plan??[])),!(c.session.ir?.steps?.length??0)){X({kind:`error`,name:`没有提交步骤`,detail:`探索结束了,但这轮没有可用的步骤 IR,代码与试跑保持为空`,status:`failed`}),I(`AI 没有提交步骤,请补充需求后重试`),await E({sessionId:r.session.id,status:`draft`}).catch(()=>void 0);return}let u=await rr(c.session.ir,d,c.suggestedPath);X({kind:`info`,name:`生成代码`,detail:u.length?`按步骤出了 ${u.length} 个文件(用例 / 页面对象 / 登录态)`:`步骤已就绪,代码页可点「重新出码」`,status:`done`}),await E({sessionId:r.session.id,status:`explored`}).catch(()=>void 0),Pe({...c.session,status:`explored`}),K(c.draft??null),En(c.changes??[]),I(`探索完成,可以点「生成代码」出码;出码后会进入代码页`)}catch(e){if(n.signal.aborted)I(`已停止`);else if(e instanceof Error&&e.message===`浏览器已被关闭,这一轮探索已结束`)I(`浏览器已关闭,这一轮探索结束;重新点「开始探索」会新开一个浏览器`),X({kind:`error`,name:`浏览器已关闭`,detail:`窗口被关闭,AI 停止操作;已提交的步骤与计划保留`,status:`failed`});else{let t=e instanceof Error?e.message:String(e);F(t),o?.(t),X({kind:`error`,name:`生成中断`,detail:t,status:`failed`})}a&&await E({sessionId:a,status:`draft`}).catch(()=>void 0)}finally{Un.current?.release(),Un.current=null,qn(!1),zn.current=null,v(`idle`),Z()}},[p,Q,dr,er,g,l,o,b,fr,e,X,Z,rr,u,f,ur,s,m,d]),gr=(0,x.useCallback)(()=>{Un.current?.release(),Un.current=null,qn(!1),zn.current?.abort(),Y.current&&(Xe(Y.current).catch(()=>void 0),Ge(Y.current).catch(()=>void 0))},[]),_r=(0,x.useCallback)(()=>{if(Un.current){Un.current.release(),Un.current=null,qn(!1),X({kind:`info`,name:`继续探索`,detail:`已手动完成登录 / 验证码`,status:`done`});return}let e=()=>{},t=new Promise(t=>{e=t});Un.current={promise:t,release:e},qn(!0),X({kind:`info`,name:`暂停`,detail:`请在打开的浏览器窗口里完成登录,完成后点「我已登录,继续」`,status:`running`})},[X]),vr=(0,x.useRef)(b.length);(0,x.useEffect)(()=>{vr.current=b.length},[b.length]);let yr=(0,x.useCallback)(e=>{if(Fe(e),!Y.current)return;let t=e.length!==vr.current;vr.current=e.length,t&&Ne(`ui-auto`);let n=()=>{let t=Y.current;t&&(Le(!0),E({sessionId:t,plan:e,allowEmptyPlan:!0}).catch(()=>void 0).finally(()=>Le(!1)))};Wn.current&&window.clearTimeout(Wn.current),t?n():Wn.current=window.setTimeout(n,400)},[]),$=(0,x.useMemo)(()=>Ue.length?Ue:Be?[{path:w||(d===`python`?`tests/test_ai_generated.py`:`tests/ai-generated.spec.ts`),content:Be,language:d,role:`spec`}]:[],[Be,Ue,w,d]),br=(0,x.useMemo)(()=>$.find(e=>e.path===k)??$[0]??null,[k,$]),xr=(0,x.useCallback)((e,t)=>{We(n=>n.map(n=>n.path===e?{...n,path:t}:n)),$e(t)},[]),Sr=(0,x.useCallback)(async()=>{if(Y.current&&$.length){F(``),ct([]);try{let e=await qe({sessionId:Y.current,files:$.map(e=>({path:e.path,content:e.content,role:e.role})),force:A});if(!e.ok){F(e.error??`写入失败`),ct((e.conflicts??[]).map(e=>e.path));return}let t=e.savedPaths?.length??e.paths?.length??1,n=e.summary?.merged??0,r=e.summary?.created??0,i=e.summary?.unchanged??0,a=[r?`新建 ${r}`:``,n?`合并 ${n}`:``,i?`无变化 ${i}`:``].filter(Boolean).join(`、`);I(`已写入 ${t} 个文件${a?`(${a})`:``}${e.path?`,主用例 ${e.path}`:``},可以按项目配置验收`),Pe(t=>t&&{...t,status:`written`,savedPath:e.path,savedPaths:e.savedPaths}),nt(!1),await Z(),er(`changes`)}catch(e){F(e instanceof Error?e.message:String(e))}}},[A,er,Z,$]),Cr=(0,x.useCallback)(async()=>{if(Y.current&&!Ln){Rn(!0),F(``),In(null);try{let e=await et(Y.current,y?.savedPath||$.find(e=>e.role===`spec`)?.path||w);In(e),X({kind:`info`,name:`按项目配置验收`,detail:e.ok?e.passed?`通过`:e.excluded?`被 testMatch 排除,没跑起来`:`失败(exit ${e.exitCode??`?`})`:e.error??`失败`,status:e.ok&&e.passed?`done`:`failed`})}catch(e){F(e instanceof Error?e.message:String(e))}finally{Rn(!1)}}},[Ln,X,y?.savedPath,w,$]),wr=(0,x.useCallback)(async()=>{if(!Y.current||_!==`idle`)return;if(!y?.ir?.steps?.length){F(`还没有步骤,先「开始探索」把流程跑一遍`);return}let t=new AbortController;zn.current=t,F(``);try{if(!s){v(`verifying`),tr(`run`);let e=X({kind:`info`,name:`试跑`,detail:`在 .lantern-ai 草稿里执行(未配置模型,不做自动修复)`,status:`running`}),t=await D(Y.current);R(t),jn(null),typeof t.code==`string`&&C(t.code),Me(n=>n.map(n=>n.id===e?{...n,status:t.passed?`done`:`failed`,detail:t.passed?`通过 · ${Math.round((t.durationMs??0)/100)/10}s`:(t.log??t.error??``).slice(-800)}:n)),I(t.passed?`试跑通过`:`试跑失败,草稿与 trace 已保留`),await Z(),await ir();return}let n=await l(),r=[{role:`system`,content:dt(e,d,b,n.agent,n.code)},{role:`user`,content:mt(f.trim()||y?.source||``,p,d,b)}];await mr(r,t.signal)}catch(e){t.signal.aborted?I(`已停止`):F(e instanceof Error?e.message:String(e))}finally{zn.current=null,v(`idle`);let e=Y.current;e&&O(e).then(e=>Pe(e.session)).catch(()=>void 0)}},[p,tr,l,_,b,e,X,Z,ir,f,mr,y?.ir?.steps?.length,y?.source,s,d]),Tr=(0,x.useCallback)(async e=>{if(Y.current&&!Mn){Nn(!0),F(``);try{let t=await Ye(Y.current,e);jn(t),t.url&&Fn(t.url),t.ok?e===`headed`&&typeof t.tracePath==`string`&&t.tracePath&&K(e=>e&&{...e,tracePath:t.tracePath??``}):F(t.error??`调试启动失败`),X({kind:`info`,name:e===`ui`?`Playwright UI`:`调试运行`,detail:t.ok?t.url||`exit ${t.exitCode??`?`} · ${t.tracePath||`无 trace`}`:t.error??`失败`,status:t.ok&&t.passed!==!1?`done`:`failed`})}catch(e){F(e instanceof Error?e.message:String(e))}finally{Nn(!1)}}},[Mn,X]),Er=(0,x.useCallback)(async()=>{Y.current&&(await Xe(Y.current).catch(()=>void 0),Fn(``),jn(null))},[]),Dr=(0,x.useCallback)(async()=>{if(Q||!Y.current)return;F(``);let e=await ir();er(`code`),I(e.length?`已生成 ${e.length} 个文件,确认后到「试跑」里执行`:`当前没有可出码的步骤,先「开始探索」把流程跑一遍`)},[Q,er,ir]),Or=(0,x.useCallback)(async e=>{if(Y.current)try{await Qe({sessionId:Y.current,path:e})}catch(e){F(e instanceof Error?e.message:String(e))}},[]),kr=(0,x.useCallback)(async()=>{if(Y.current){Nn(!0);try{let e=await tt(Y.current);K(e.draft),jn(null),R(null),Fn(``),I(`草稿已清理`)}catch(e){F(e instanceof Error?e.message:String(e))}finally{Nn(!1)}}},[]),Ar=(0,x.useCallback)(async e=>{if(te(e),i(qt,e),Y.current)try{let t=await E({sessionId:Y.current,target:e});C(t.code),T(t.suggestedPath),await rr(y?.ir??null,e,t.suggestedPath)}catch(e){F(e instanceof Error?e.message:String(e))}},[rr,y?.ir]),jr=(0,x.useCallback)(()=>{let e=br?.content??Be;e&&navigator.clipboard.writeText(e).then(()=>I(`已复制当前文件`)).catch(()=>F(`复制失败,请手动选中`))},[br?.content,Be]),Mr=(0,x.useMemo)(()=>Kn?`已暂停:请在浏览器窗口里完成登录,然后点「我已登录,继续」`:_===`planning`?`AI 正在拆解步骤计划…`:_===`exploring`?`AI 正在操作浏览器…`:_===`verifying`?`正在草稿里试跑生成的脚本…`:_===`repairing`?`试跑失败,正在修复(第 ${z} 轮)…`:``,[Kn,_,z]),Nr=_===`planning`,Pr=Re,Fr=y?y.status===`verified`?`试跑通过`:y.status===`written`?`已写入项目`:y.status===`explored`?`已探索`:y.status===`failed`?`试跑失败`:`草稿`:``,Ir=q?.tracePath||G?.tracePath||L?.tracePath||``,Lr=q?.draftPath||L?.draftPath||``,Rr=!!(G?.hasSteps||(y?.ir?.steps?.length??0));return(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden bg-stone-50/40`,"aria-busy":ke?`true`:void 0,children:[(0,N.jsxs)(`aside`,{className:`flex min-h-0 min-w-0 shrink-0 flex-col gap-2 overflow-hidden bg-white px-2.5 py-2`,style:{width:M},children:[(0,N.jsxs)(`div`,{className:`flex min-h-[104px] shrink flex-col`,children:[(0,N.jsx)(`div`,{className:`mb-1 flex items-center`,children:(0,N.jsx)(`label`,{htmlFor:`ui-gen-req`,className:`text-xs font-medium text-stone-600`,children:`需求 / 步骤`})}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden rounded-lg border border-stone-200 bg-white transition-colors focus-within:border-[#3370ff] ${Se?``:`transition-[height] duration-150`}`,style:{flexBasis:be},children:(0,N.jsx)(`textarea`,{id:`ui-gen-req`,className:`block h-full w-full resize-none bg-transparent px-2.5 py-2 text-xs leading-relaxed text-stone-700 outline-none`,value:f,onChange:e=>ne(e.target.value),placeholder:`例:登录后进入商品列表,把第一个商品加入购物车,断言购物车出现该商品`,spellCheck:!1})}),(0,N.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":`调整需求框高度`,title:`拖动调整高度,双击恢复默认`,className:`group mt-1 flex h-2 cursor-row-resize touch-none items-center justify-center`,onPointerDown:e=>{we.current={startY:e.clientY,startHeight:be},Ce(!0),e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:e=>{let t=we.current;if(!t)return;let n=Math.max(Jt,Math.min(Yt,Math.round(window.innerHeight*.45)));xe(Math.min(n,Math.max(Jt,t.startHeight+(e.clientY-t.startY))))},onPointerUp:e=>{we.current&&(we.current=null,Ce(!1),e.currentTarget.releasePointerCapture(e.pointerId))},onDoubleClick:()=>xe(Xt),onPointerCancel:()=>{we.current=null,Ce(!1)},children:(0,N.jsx)(`span`,{className:`h-[3px] w-8 rounded-full transition-colors ${Se?`bg-[#4176e6]/70`:`bg-stone-200 group-hover:bg-[#4176e6]/50`}`})})]}),(0,N.jsxs)(`div`,{className:`grid shrink-0 grid-cols-2 gap-2`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`span`,{className:`mb-1 block text-[11px] text-stone-500`,children:`目标语言`}),(0,N.jsx)(ie,{options:ee.options,value:d,onChange:e=>void Ar(e),compact:!0,ariaLabel:`目标语言`,className:`w-full`})]}),(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`span`,{className:`mb-1 block text-[11px] text-stone-500`,children:`浏览器`}),(0,N.jsx)(ie,{options:on,value:g?`1`:`0`,onChange:e=>ye(e===`1`),compact:!0,ariaLabel:`浏览器`,className:`w-full`})]})]}),(0,N.jsxs)(`details`,{className:`shrink-0 rounded-lg border border-stone-200 px-2 py-1.5`,open:Te,onToggle:e=>Ee(e.currentTarget.open),children:[(0,N.jsx)(`summary`,{className:`cursor-pointer list-none text-[11px] text-stone-500`,children:`地址与登录态`}),(0,N.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,N.jsx)(`input`,{id:`ui-gen-base`,className:`${Pt} font-mono`,value:p,onChange:e=>oe(e.target.value),placeholder:`http://localhost:5173`,spellCheck:!1,"aria-label":`起始地址`}),ce?(0,N.jsxs)(`p`,{className:`text-[10px] leading-4 text-stone-400`,children:[`项目配置里读到:`,(0,N.jsx)(`button`,{type:`button`,className:`ml-1 font-mono text-[#3370ff] hover:underline`,onClick:()=>oe(ce),disabled:p===ce,children:ce})]}):null,(0,N.jsx)(`input`,{id:`ui-gen-storage`,className:`${Pt} font-mono`,value:m,onChange:e=>he(e.target.value),placeholder:`登录态文件,留空自动检测;填 - 不用`,spellCheck:!1,"aria-label":`登录态文件`}),_e?(0,N.jsxs)(`p`,{className:`text-[10px] leading-4 text-stone-400`,children:[`项目里找到:`,(0,N.jsx)(`button`,{type:`button`,className:`ml-1 font-mono text-[#3370ff] hover:underline`,onClick:()=>he(_e),disabled:m===_e,children:_e})]}):m===`-`?(0,N.jsx)(`p`,{className:`text-[10px] leading-4 text-stone-400`,children:`按未登录身份跑,不加载 cookie`}):m?(0,N.jsx)(`p`,{className:`text-[10px] leading-4 text-stone-400`,children:`项目里没找到这个文件,跑之前会再确认一次;找不到就按未登录身份跑`}):(0,N.jsx)(`p`,{className:`text-[10px] leading-4 text-stone-400`,children:`项目里没找到登录态文件:会以未登录身份打开,探索中可以点「手动登录」`})]})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,N.jsxs)(`div`,{className:`inline-flex h-8 items-center rounded-lg border border-stone-200 bg-white p-0.5`,children:[(0,N.jsxs)(`button`,{type:`button`,className:Nr?Mt:jt,onClick:()=>void pr(),disabled:Q||!f.trim(),"aria-busy":Nr||void 0,children:[Nr?(0,N.jsx)(yn,{}):(0,N.jsx)(bn,{name:`steps`}),(0,N.jsx)(`span`,{className:`min-w-[52px] text-center`,children:Nr?`规划中…`:`生成步骤`})]}),(0,N.jsx)(`span`,{className:`mx-0.5 h-4 w-px shrink-0 bg-stone-200`,"aria-hidden":`true`}),(0,N.jsxs)(`button`,{type:`button`,className:Pr?Mt:jt,onClick:()=>void Dr(),disabled:cr,"aria-busy":Pr||void 0,children:[Pr?(0,N.jsx)(yn,{}):(0,N.jsx)(bn,{name:`code`}),(0,N.jsx)(`span`,{className:`min-w-[52px] text-center`,children:Pr?`出码中…`:`生成代码`})]})]}),(0,N.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:(0,N.jsx)(`button`,{type:`button`,className:`${ar?kt:W} min-w-[104px] justify-center`,onClick:()=>ar?gr():void hr(),disabled:!ar&&or,"aria-busy":ar||void 0,children:ar?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(yn,{}),`停止`]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(bn,{name:`play`}),`开始探索`]})})})]}),!b.length&&!Q&&!ke?(0,N.jsx)(`p`,{className:`shrink-0 text-[11px] leading-relaxed text-stone-400`,children:`先「生成步骤」,确认计划后就能开始探索`}):null,(0,N.jsxs)(`div`,{className:`max-h-[96px] shrink-0 space-y-1 overflow-y-auto`,children:[Mr||Ie||_===`exploring`&&g?(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[Mr?(0,N.jsx)(`p`,{className:`text-[11px] text-[#4176e6]`,children:Mr}):null,Ie?(0,N.jsx)(`p`,{className:`text-[10px] text-stone-400`,children:`保存中…`}):null,_===`exploring`&&g?(0,N.jsx)(`button`,{type:`button`,className:`text-[11px] font-medium text-[#4176e6] underline-offset-2 hover:underline`,onClick:_r,children:Kn?`我已登录,继续`:`手动登录`}):null]}):null,P?(0,N.jsx)(`p`,{className:`rounded-lg bg-red-50 px-3 py-2 text-[11px] leading-relaxed break-words text-red-600`,children:P}):null,bt?(0,N.jsx)(`p`,{className:`rounded-lg bg-emerald-50 px-3 py-2 text-[11px] leading-relaxed break-words text-emerald-700`,children:bt}):null]}),(0,N.jsx)(`div`,{className:`flex min-h-[150px] min-w-0 flex-1 flex-col`,children:ke?(0,N.jsx)(vn,{}):(0,N.jsx)(Et,{plan:b,disabled:Q,onChange:yr})})]}),(0,N.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`调整左栏宽度`,className:`w-1 shrink-0 cursor-col-resize touch-none bg-stone-200/70 transition-colors hover:bg-[#4176e6]/40`,onPointerDown:e=>{ut.current={startX:e.clientX,startWidth:M},e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:e=>{let t=ut.current;t&&lt(Math.min(Ut,Math.max(Ht,t.startWidth+(e.clientX-t.startX))))},onPointerUp:e=>{ut.current&&(ut.current=null,e.currentTarget.releasePointerCapture(e.pointerId),i(Vt,String(M)))},onPointerCancel:()=>{ut.current=null}}),(0,N.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,N.jsxs)(`section`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-white`,children:[(0,N.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center gap-1 border-b border-stone-100 px-3`,children:[Qt.map(e=>(0,N.jsx)(`button`,{type:`button`,className:`rounded px-2 py-0.5 text-[11px] transition-colors ${H===e.value?`bg-[#f2f6ff] text-[#3370ff]`:`text-stone-500 hover:bg-stone-50`}`,onClick:()=>er(e.value),children:e.value===`changes`&&Tn.length?`${e.label} ${Tn.length}`:e.label},e.value)),(0,N.jsxs)(`div`,{className:`ml-auto flex min-w-0 shrink items-center gap-2`,children:[H===`activity`&&je.length?(0,N.jsx)(`button`,{type:`button`,className:`shrink-0 text-[10px] text-stone-400 transition-colors hover:text-red-500`,onClick:()=>{Me([]),Y.current&&E({sessionId:Y.current,activity:[],replaceActivity:!0}).catch(()=>void 0)},children:`清除活动日志`}):null,y?(0,N.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 text-[10px] text-stone-400`,children:[(0,N.jsx)(`span`,{className:`shrink-0`,children:`会话`}),(0,N.jsx)(`span`,{className:`truncate font-mono`,children:y.id})]}):null]})]}),(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[H===`activity`?(0,N.jsx)(`div`,{ref:Hn,className:`min-h-0 flex-1 overflow-auto px-3 py-2`,children:ke?(0,N.jsx)(_n,{rows:4}):(0,N.jsxs)(N.Fragment,{children:[je.length===0?(0,N.jsx)(`p`,{className:`py-6 text-center text-xs leading-relaxed text-stone-400`,children:`生成时这里会显示每一步操作与探测结果`}):(0,N.jsx)(`ul`,{className:`space-y-1.5`,children:je.map(e=>(0,N.jsx)(`li`,{className:`text-[11px] leading-relaxed`,children:(0,N.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,N.jsx)(`span`,{className:`mt-1 h-1.5 w-1.5 shrink-0 rounded-full ${e.status===`running`?`animate-pulse bg-[#4176e6]`:e.status===`failed`?`bg-red-500`:`bg-emerald-500`}`}),(0,N.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,N.jsx)(`span`,{className:`font-mono text-stone-700`,children:e.name}),e.detail?(0,N.jsx)(`pre`,{className:`mt-0.5 max-h-24 overflow-hidden whitespace-pre-wrap break-all text-[11px] text-stone-400`,children:e.detail}):null]})]})},e.id))}),_t?(0,N.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone mt-3 max-w-none border-t border-stone-100 pt-2 text-stone-600`,style:{fontSize:11,lineHeight:1.7},onClick:e=>{let t=e.target;if(!t.closest(`[data-copy-code]`))return;let n=t.closest(`.code-block`)?.querySelector(`code`);n&&navigator.clipboard?.writeText(n.textContent??``).then(()=>ae(`已复制`,`success`),()=>ae(`复制失败`,`error`))},dangerouslySetInnerHTML:{__html:fe(_t)}}):null]})}):null,H===`code`?ke?(0,N.jsx)(_n,{rows:5}):$.length?(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,N.jsxs)(`div`,{className:`flex w-56 shrink-0 flex-col border-r border-stone-100`,children:[(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-stone-100 px-2.5 py-1.5`,children:[(0,N.jsxs)(`span`,{className:`text-[11px] font-medium text-stone-600`,children:[`待写入 `,$.length,` 个文件`]}),(0,N.jsx)(`button`,{type:`button`,className:`ml-auto rounded px-1 text-[11px] text-stone-400 hover:bg-stone-50 hover:text-stone-600`,onClick:()=>void ir(),disabled:!y?.ir||Re,children:Re?`出码中…`:`重新出码`})]}),(0,N.jsx)(`ul`,{className:`min-h-0 flex-1 overflow-auto p-1`,children:$.map(e=>{let t=br?.path===e.path;return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`flex w-full items-start gap-1.5 rounded-md px-1.5 py-1 text-left transition-colors ${t?`bg-[#f2f6ff]`:`hover:bg-stone-50`}`,onClick:()=>$e(e.path),children:[(0,N.jsx)(`span`,{className:`mt-0.5 shrink-0 rounded px-1 py-px text-[10px] leading-4 ${hn(e.role).className}`,children:hn(e.role).label}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,N.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-stone-700`,children:pn(e.path)}),(0,N.jsx)(`span`,{className:`block truncate font-mono text-[10px] leading-4 text-stone-400`,children:mn(e.path)})]})]})},e.path)})}),(0,N.jsxs)(`div`,{className:`shrink-0 space-y-1.5 border-t border-stone-100 px-2.5 py-2`,children:[(0,N.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[11px] text-stone-500`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>nt(e.target.checked)}),`整文件覆盖(默认与已有文件合并)`]}),(0,N.jsxs)(`button`,{type:`button`,className:`${W} w-full justify-center`,onClick:()=>void Sr(),disabled:Q||!$.length,children:[`写入 `,$.length,` 个文件`]})]})]}),(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-stone-100 px-3 py-1.5`,children:[(0,N.jsx)(`span`,{className:`shrink-0 rounded bg-stone-100 px-1.5 py-0.5 text-[10px] text-stone-500`,children:d===`python`?`pytest`:`Playwright Test`}),(0,N.jsx)(`input`,{className:`${Pt} min-w-[180px] flex-1 font-mono`,value:br?.path??``,onChange:e=>{br&&xr(br.path,e.target.value)},placeholder:w||`tests/xxx.spec.ts`,spellCheck:!1,"aria-label":`写入路径`}),(0,N.jsx)(`button`,{type:`button`,className:Ot,onClick:jr,children:`复制`}),(0,N.jsx)(vt,{compact:!0,disabled:!br||!y?.savedPaths?.length,onOpen:e=>{br&&Qe({sessionId:Y.current,path:br.path,app:e?.id}).catch(e=>F(e instanceof Error?e.message:String(e)))}})]}),j.length?(0,N.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-b border-amber-100 bg-amber-50 px-3 py-1.5 text-[11px] text-amber-700`,children:[(0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[`这些文件已存在:`,j.join(`、`)]}),(0,N.jsx)(`button`,{type:`button`,className:`shrink-0 rounded border border-amber-300 px-1.5 py-0.5 text-amber-800 hover:bg-amber-100`,onClick:()=>{nt(!0),ct([])},children:`勾选覆盖`})]}):null,(0,N.jsx)(`pre`,{className:`min-h-0 flex-1 overflow-auto whitespace-pre px-3 py-2 font-mono text-[11px] leading-relaxed text-stone-700`,children:br?.content||`生成后这里显示要写入的文件`})]})]}):(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs leading-relaxed text-stone-400`,children:`生成步骤并试跑后,这里会列出要写入项目的 spec、页面对象与登录态文件`}):null,H===`changes`?ke?(0,N.jsx)(_n,{rows:4}):(0,N.jsx)(St,{changes:Tn,git:Dn,draft:G,loading:kn,onReveal:e=>void Or(e),onRefresh:()=>void Z()}):null]}),ht&&H===`activity`?(0,N.jsx)(`div`,{className:`shrink-0 border-t border-stone-100 p-2`,children:(0,N.jsx)(`img`,{src:ht,alt:`最近一步截图`,className:`max-h-52 w-full rounded-md border border-stone-100 object-contain`})}):null]}),(0,N.jsxs)(`section`,{className:`relative flex shrink-0 flex-col overflow-hidden border-t border-stone-200 bg-white ${At?``:`transition-[height] duration-200 ease-out`}`,style:{height:Tt?zt:U},children:[Tt?null:(0,N.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":`调整底部面板高度`,className:`h-1 shrink-0 cursor-row-resize touch-none bg-stone-100 transition-colors hover:bg-[#4176e6]/40`,onPointerDown:e=>{gn.current={startY:e.clientY,startHeight:U},cn(!0),e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:e=>{let t=gn.current;if(!t)return;let n=Math.max(Lt,Math.round(window.innerHeight*.65));wt(Math.min(n,Math.max(zt,t.startHeight+(t.startY-e.clientY))))},onPointerUp:e=>{let t=gn.current;if(!t)return;gn.current=null,cn(!1),e.currentTarget.releasePointerCapture(e.pointerId);let n=Math.max(Lt,Math.round(window.innerHeight*.65)),r=Math.min(n,Math.max(zt,t.startHeight+(t.startY-e.clientY)));r<=Bt?(wt(Math.max(Lt,t.startHeight)),Dt(!0),i(It,`closed`)):(wt(r),i(It,String(r)))},onPointerCancel:()=>{gn.current=null,cn(!1)}}),(0,N.jsxs)(`div`,{className:`relative flex h-9 shrink-0 items-center gap-1 border-b border-stone-100 px-2`,children:[$t.map(e=>(0,N.jsx)(`button`,{type:`button`,className:`rounded px-2 py-0.5 text-[11px] transition-colors ${V===e.value?`bg-[#f2f6ff] text-[#3370ff]`:`text-stone-500 hover:bg-stone-50`}`,onClick:()=>tr(e.value),children:e.label},e.value)),(0,N.jsx)(`span`,{className:`ml-2 min-w-0 truncate text-[10px] text-stone-400`,children:Fr}),(0,N.jsx)(`button`,{type:`button`,"aria-label":Tt?`展开底部面板`:`收起底部面板`,"aria-expanded":!Tt,className:`group absolute left-1/2 top-1/2 flex h-6 w-20 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-md text-stone-400 transition-colors hover:bg-stone-100 hover:text-stone-600 focus-visible:ring-2 focus-visible:ring-[#4176e6]/30 focus-visible:outline-none`,onClick:nr,children:(0,N.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4 transition-transform duration-200 ${Tt?`rotate-180`:``}`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,N.jsx)(`path`,{d:`m6 9 6 6 6-6`})})})]}),Tt?null:(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[V===`console`?(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto px-3 py-2`,children:xn.length?(0,N.jsx)(`ul`,{className:`space-y-1 font-mono text-[11px]`,children:xn.slice(-80).map((e,t)=>(0,N.jsxs)(`li`,{className:e.type===`error`?`text-red-600`:`text-stone-600`,children:[(0,N.jsxs)(`span`,{className:`mr-1 text-stone-400`,children:[`[`,e.type,`]`]}),e.text]},t))}):(0,N.jsx)(`p`,{className:`py-6 text-center text-xs text-stone-400`,children:`暂无控制台错误 / 警告`})}):null,V===`network`?(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto px-3 py-2`,children:Cn.length?(0,N.jsx)(`ul`,{className:`space-y-1 font-mono text-[11px]`,children:Cn.slice(-80).map((e,t)=>(0,N.jsxs)(`li`,{className:`text-stone-600`,children:[(0,N.jsx)(`span`,{className:`mr-1 text-red-500`,children:e.status}),(0,N.jsx)(`span`,{className:`mr-1 text-stone-400`,children:e.method}),(0,N.jsx)(`span`,{className:`break-all`,children:e.url})]},t))}):(0,N.jsx)(`p`,{className:`py-6 text-center text-xs text-stone-400`,children:`暂无失败请求`})}):null,V===`run`?(0,N.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,N.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-x-3 gap-y-1 border-b border-stone-100 px-3 py-1.5`,children:[(0,N.jsx)(`span`,{className:`text-[11px] text-stone-500`,children:`最近一次试跑`}),(0,N.jsx)(`span`,{className:`text-[11px] font-medium ${L?L.passed?`text-emerald-600`:`text-red-600`:`text-stone-400`}`,children:L?L.passed?`通过`:`失败(exit ${L.exitCode??`?`})`:`未试跑`}),(0,N.jsxs)(`span`,{className:`text-[11px] tabular-nums text-stone-400`,children:[`耗时 `,Math.round((L?.durationMs??0)/100)/10,`s`,L?.timedOut?` · 超时`:``]}),(0,N.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,className:W,onClick:()=>void wr(),disabled:Q||!Rr,children:_===`verifying`?`试跑中…`:L?`重新试跑`:`试跑`}),(0,N.jsx)(`button`,{type:`button`,className:Ot,onClick:()=>void Tr(`headed`),disabled:Mn||!Rr,children:`调试运行`}),(0,N.jsx)(`button`,{type:`button`,className:Ot,onClick:()=>void Tr(`ui`),disabled:Mn||!Rr||d===`python`,children:`Playwright UI`}),Pn?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`a`,{className:Nt,href:Pn,target:`_blank`,rel:`noreferrer`,children:[`打开 `,Pn]}),(0,N.jsx)(`button`,{type:`button`,className:Nt,onClick:()=>void Er(),children:`结束 UI`})]}):null]})]}),(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,N.jsx)(`pre`,{className:`min-h-0 flex-1 overflow-auto whitespace-pre-wrap break-all bg-stone-50/40 px-3 py-2 font-mono text-[11px] leading-relaxed text-stone-700`,children:L?.log||(L?`试跑没有输出`:`试跑后这里显示日志;失败时草稿与 trace 会保留,方便回看现场。`)}),(0,N.jsxs)(`div`,{className:`w-64 shrink-0 space-y-2 overflow-auto border-l border-stone-100 p-2`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`p`,{className:`text-[11px] text-stone-500`,children:`草稿工作区`}),(0,N.jsx)(`p`,{className:`mt-1 break-all font-mono text-[10px] leading-4 text-stone-500`,children:G?.draftRoot||`还没有草稿,试跑后生成`}),(0,N.jsx)(`p`,{className:`break-all font-mono text-[10px] leading-4 text-stone-400`,children:Lr?`用例:${Lr}`:``}),(0,N.jsx)(`p`,{className:`break-all font-mono text-[10px] leading-4 text-stone-400`,children:Ir?`trace:${Ir}`:``}),(0,N.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,N.jsx)(`button`,{type:`button`,className:Nt,onClick:()=>void Or(Lr||G?.draftDir||``),disabled:!Lr&&!G?.draftDir,children:`打开草稿`}),(0,N.jsx)(`button`,{type:`button`,className:Nt,onClick:()=>void Or(G?.draftRoot??``),disabled:!G?.exists,children:`打开目录`}),(0,N.jsx)(`button`,{type:`button`,className:Nt,onClick:()=>void Or(Ir),disabled:!Ir,children:`打开 trace`}),(0,N.jsx)(`button`,{type:`button`,className:`${Nt} text-stone-400`,onClick:()=>void kr(),disabled:Mn||!G?.exists,children:`清理草稿`})]})]}),(0,N.jsxs)(`details`,{className:`rounded-lg border border-stone-200 px-2 py-1.5`,open:De,onToggle:e=>Oe(e.currentTarget.open),children:[(0,N.jsx)(`summary`,{className:`cursor-pointer list-none text-[11px] text-stone-500`,children:`写入后验收`}),(0,N.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2`,children:[(0,N.jsx)(`p`,{className:`text-[10px] leading-4 text-stone-400`,children:`用项目自己的配置跑正式文件`}),(0,N.jsx)(`button`,{type:`button`,className:Ot,onClick:()=>void Cr(),disabled:Ln||!(y?.savedPath||$.find(e=>e.role===`spec`)?.path),children:Ln?`验收中…`:`开始验收`})]}),J?(0,N.jsxs)(`div`,{className:`mt-1.5`,children:[(0,N.jsx)(`p`,{className:`text-[11px] font-medium ${J.passed?`text-emerald-600`:`text-red-600`}`,children:J.ok?J.passed?`验收通过`:J.excluded?`没被项目配置识别为用例`:`失败(exit ${J.exitCode??`?`})`:J.error??`失败`}),J.note?(0,N.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-4 text-amber-600`,children:J.note}):null,J.log?(0,N.jsx)(`pre`,{className:`mt-1 max-h-40 overflow-auto whitespace-pre-wrap rounded bg-stone-50 p-2 font-mono text-[10px] leading-4 text-stone-600`,children:J.log}):null]}):null]}),q?(0,N.jsxs)(`div`,{className:`rounded-lg border border-stone-200 px-2 py-1.5`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsx)(`span`,{className:`text-[11px] text-stone-500`,children:q.mode===`ui`?`Playwright UI`:`调试运行`}),(0,N.jsx)(`span`,{className:`text-[11px] ${q.ok&&q.passed!==!1?`text-emerald-600`:`text-red-600`}`,children:q.ok?q.mode===`ui`?q.ready?`已启动`:`启动较慢`:q.passed?`通过`:`失败(exit ${q.exitCode??`?`})`:q.error??`失败`})]}),q.url?(0,N.jsx)(`p`,{className:`mt-1 break-all font-mono text-[10px] text-stone-500`,children:q.url}):null,q.log?(0,N.jsx)(`pre`,{className:`mt-1 max-h-40 overflow-auto whitespace-pre-wrap rounded bg-stone-50 p-2 font-mono text-[10px] leading-4 text-stone-600`,children:q.log}):null]}):null]})]})]}):null]})]})]})]})}function _n({rows:e=3}){return(0,N.jsx)(`div`,{className:`space-y-2 p-3`,"aria-hidden":`true`,children:Array.from({length:e}).map((e,t)=>(0,N.jsx)(`div`,{className:`h-3 animate-pulse rounded bg-stone-100`,style:{width:`${Math.max(40,92-t*14)}%`}},t))})}function vn(){return(0,N.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-1.5`,"aria-hidden":`true`,children:[0,1,2].map(e=>(0,N.jsx)(`div`,{className:`h-16 animate-pulse rounded-lg bg-stone-50`},e))})}function yn(){return(0,N.jsxs)(`svg`,{className:`h-3.5 w-3.5 shrink-0 animate-spin`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,children:[(0,N.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`,stroke:`currentColor`,strokeWidth:`2`,opacity:`0.25`}),(0,N.jsx)(`path`,{d:`M14 8a6 6 0 0 0-6-6`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})]})}function bn({name:e}){let t={width:14,height:14,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.7,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,className:`h-3.5 w-3.5 shrink-0`};return e===`play`?(0,N.jsx)(`svg`,{...t,fill:`currentColor`,stroke:`none`,children:(0,N.jsx)(`path`,{d:`M8 5.5v13l11-6.5Z`})}):e===`code`?(0,N.jsxs)(`svg`,{...t,children:[(0,N.jsx)(`path`,{d:`m9 8-4 4 4 4`}),(0,N.jsx)(`path`,{d:`m15 8 4 4-4 4`})]}):(0,N.jsxs)(`svg`,{...t,children:[(0,N.jsx)(`path`,{d:`M4 7h10`}),(0,N.jsx)(`path`,{d:`M4 12h7`}),(0,N.jsx)(`path`,{d:`M4 17h10`}),(0,N.jsx)(`path`,{d:`M17 12h3`}),(0,N.jsx)(`path`,{d:`m18 10 2 2-2 2`})]})}function xn(e){if(e.kind===`full`)return`全量运行`;let t=e.display?.trim()??``;return!t||t===e.command?e.label||e.command:`${t}(${e.command})`}var Sn=[{value:`run`,label:`运行`},{value:`generate`,label:`生成`},{value:`history`,label:`历史`}],Cn=`ui-auto.project`,wn=`ui-auto.tab`,Tn=`ui-auto.task`,En=e=>`ui-auto.log-scroll.${e}`,Dn=e=>`${Tn}.${e}`,On=1e3,G=`inline-flex h-8 shrink-0 items-center gap-1.5 rounded-lg bg-[#4176e6] px-3 text-sm font-medium text-white transition-colors hover:bg-[#3566d0] disabled:cursor-not-allowed disabled:opacity-50`,K=`inline-flex h-8 shrink-0 items-center gap-1.5 rounded-lg border border-stone-200 px-3 text-sm text-stone-600 transition-colors hover:bg-stone-50 disabled:cursor-not-allowed disabled:opacity-40`,kn=`inline-flex h-8 shrink-0 items-center gap-1.5 rounded-lg border border-red-200 px-3 text-sm text-red-600 transition-colors hover:bg-red-50 disabled:cursor-not-allowed disabled:opacity-40`;function An(){let{ready:e,on:t}=y(`uiAuto`),[n,s]=(0,x.useState)([]),[c,l]=(0,x.useState)([]),[u,ne]=(0,x.useState)(()=>a(Cn)),[se,le]=(0,x.useState)(!0),[ue,de]=(0,x.useState)(!0),[fe,h]=(0,x.useState)(``),[Ee,Ne]=(0,x.useState)(()=>a(wn)===`history`?`history`:a(wn)===`generate`?`generate`:`run`),[Re,S]=(0,x.useState)(()=>a(Tn)||`full`),[ze,Be]=(0,x.useState)(!1),[C,w]=(0,x.useState)(``),[T,Ve]=(0,x.useState)([]),[He,Ue]=(0,x.useState)(!1),[We,Ge]=(0,x.useState)(!1),[E,Ke]=(0,x.useState)([]),[D,qe]=(0,x.useState)(null),[Je,O]=(0,x.useState)(``),[Ye,Xe]=(0,x.useState)(!1),[Ze,k]=(0,x.useState)(!1),$e=(0,x.useRef)(0),et=(0,x.useRef)(null),tt=(0,x.useRef)(!0),A=(0,x.useRef)(null),nt=(0,x.useRef)(0),[rt,it]=(0,x.useState)(!1),[at,ot]=(0,x.useState)(``),[j,st]=(0,x.useState)(null),[ct,M]=(0,x.useState)(``),[lt,ut]=(0,x.useState)(!1),[dt,ft]=(0,x.useState)(null),[pt,mt]=(0,x.useState)(null),[ht,gt]=(0,x.useState)(!1),[_t,yt]=(0,x.useState)(()=>Date.now()),P=(0,x.useMemo)(()=>n.find(e=>e.id===u)??null,[n,u]),F=(0,x.useMemo)(()=>{let e=P?.promptFile??``;return e&&T.some(t=>t.value===e)?e:he},[P?.promptFile,T]),bt=(0,x.useMemo)(()=>{if(!P||!He)return!1;let e=(P.promptFile??``).trim();return!e||!T.some(t=>t.value===e)},[P,He,T]),I=(0,x.useMemo)(()=>n.map(e=>({value:e.id,label:e.name,secondary:e.dir.replace(/^\/Users\/[^/]+/,`~`)})),[n]),L=(0,x.useCallback)(e=>{Ne(e),i(wn,e)},[]),R=(0,x.useCallback)(async()=>{let e=async t=>{let{entries:n}=await oe(`prompts`,t),r=t===`.`?``:`${t}/`,i=n.filter(e=>e.type===`file`&&/\.md$/i.test(e.name)).map(e=>`${r}${e.name}`),a=await Promise.all(n.filter(e=>e.type===`dir`).map(t=>e(`${r}${t.name}`)));return[...i,...a.flat()]},t=(await e(`.`)).filter(e=>{let t=ce(e);return!t||t===`uiAuto`}).sort().map(e=>({value:e,label:e}));return Ve(t),t},[]);(0,x.useEffect)(()=>{if(!t)return;R().catch(()=>void 0).finally(()=>Ue(!0));let e=()=>{document.visibilityState===`visible`&&R().catch(()=>void 0)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[t,R]);let z=(0,x.useCallback)(async()=>{let e=await ye();return s(e.projects),e.frameworks.length&&l(e.frameworks),e.projects},[]),B=(0,x.useCallback)(async e=>{let t=await _(e);return Ke(t),t},[]),V=(0,x.useRef)(``);V.current=D?.id??``;let H=(0,x.useCallback)(()=>{let e=et.current,t=V.current;if(!e||!t)return;let n=e.scrollHeight-e.scrollTop-e.clientHeight<40;r(En(t),{top:e.scrollTop,stick:n})},[]),St=(0,x.useCallback)(async e=>{H();let t=await we(e,0);qe(t.run),O(t.log),Xe(t.stopping),$e.current=t.nextOffset;let n=o(En(e),null),r=n&&typeof n.top==`number`&&!n.stick?n:null;A.current=r,tt.current=!r},[H]);(0,x.useEffect)(()=>{if(!t)return;let e=!0;return me(!0).catch(()=>void 0),le(!0),z().catch(t=>{e&&h(t instanceof Error?t.message:String(t))}).finally(()=>{e&&le(!1)}),()=>{e=!1}},[t,z]),(0,x.useEffect)(()=>{if(!n.length||n.some(e=>e.id===u))return;let e=n[0].id;ne(e),i(Cn,e)},[n,u]),(0,x.useEffect)(()=>{if(!t||!u){Ke([]),qe(null),O(``),t&&de(!1);return}let e=!0;return Ke([]),qe(null),O(``),Xe(!1),$e.current=0,A.current=null,S(a(Dn(u))||`full`),B(u).then(t=>{if(!e)return;let n=t.find(e=>e.status===`running`)??t[0];n&&St(n.id).catch(()=>void 0)}).catch(t=>{e&&h(t instanceof Error?t.message:String(t))}).finally(()=>{e&&de(!1)}),()=>{e=!1}},[t,u,B,St]);let Ct=(0,x.useCallback)(async()=>{await z().catch(()=>null),u&&await B(u).catch(()=>null)},[z,B,u]),U=(0,x.useMemo)(()=>P?.runTasks??[],[P?.runTasks]),wt=(0,x.useMemo)(()=>U.find(e=>e.id===Re)??U[0]??null,[U,Re]),Tt=(0,x.useMemo)(()=>[...U.length?U.map(e=>({value:e.id,label:xn(e)})):[{value:`full`,label:`全量运行`}]],[U]),Et=D?.status??``,Dt=D?.id??``,W=D?.status===`running`;(0,x.useEffect)(()=>{if(!Dt||!W)return;let e=!0,t=async()=>{try{let t=await we(Dt,$e.current);if(!e)return;t.reset?O(t.log):t.log&&O(e=>e+t.log),$e.current=t.nextOffset,Xe(t.stopping),qe(t.run),Te(t.run.status)&&Ct()}catch{}},n=window.setInterval(()=>void t(),On);return()=>{e=!1,window.clearInterval(n)}},[Dt,W,Ct]),(0,x.useEffect)(()=>{if(!W)return;let e=window.setInterval(()=>yt(Date.now()),1e3);return()=>window.clearInterval(e)},[W]),(0,x.useEffect)(()=>{if(W)return;let e=window.setInterval(()=>{document.visibilityState===`visible`&&(z().catch(()=>null),u&&B(u).catch(()=>null))},15e3);return()=>window.clearInterval(e)},[W,u,z,B]),(0,x.useEffect)(()=>{let e=et.current;if(!e)return;let t=A.current;t?(A.current=null,e.scrollTop=t.top):tt.current&&(e.scrollTop=e.scrollHeight)},[Je]),(0,x.useEffect)(()=>{let e=()=>H(),t=()=>{document.visibilityState===`hidden`&&H()};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t),window.clearTimeout(nt.current)}},[H]);let Ot=()=>{let e=et.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<40;tt.current=t,window.clearTimeout(nt.current),nt.current=window.setTimeout(()=>H(),200)},kt=(0,x.useCallback)(async(e={})=>{if(u){h(``),k(!0);try{let t=await Me(u,{taskId:wt?.id??`full`,...e});qe(t),O(``),Xe(!1),$e.current=0,A.current=null,tt.current=!0,L(`run`),await B(u).catch(()=>null),await z().catch(()=>null)}catch(e){h(e instanceof Error?e.message:String(e))}finally{k(!1)}}},[u,wt,B,z,L]),At=(e=null)=>{h(``),M(``),st(e),ot(e?.dir??``),it(!0)},jt=()=>{lt||it(!1)},Mt=(0,x.useCallback)(e=>{P&&Qe({projectId:P.id,path:e.path,app:e.app}).catch(e=>h(e instanceof Error?e.message:String(e)))},[P]),Nt=async()=>{ut(!0),M(``);try{let e=await _e();e&&ot(e)}catch(e){M(`${e instanceof Error?e.message:String(e)}(可在下方直接填写目录路径)`)}finally{ut(!1)}},Pt=async e=>{if(P){w(``);try{let t=await ge({id:P.id,customTasks:e.customTasks?.map(({id:e,name:t,command:n})=>({id:e,name:t,command:n})),taskOverrides:e.taskOverrides,hiddenTasks:e.hiddenTasks});s(e=>e.map(e=>e.id===t.id?t:e)),(t.runTasks??[]).some(e=>e.id===Re)||(S(`full`),i(Dn(t.id),`full`))}catch(e){w(e instanceof Error?e.message:String(e))}}},Ft=e=>Pt({customTasks:e}),It=(0,x.useCallback)(async e=>{if(!P)return;let t=P.id;s(n=>n.map(n=>n.id===t?{...n,promptFile:e}:n));try{let n=await ge({id:t,promptFile:e});s(e=>e.map(e=>e.id===n.id?n:e)),Ge(!1),Se(),ae(e?`已挂载「${e}」`:`已取消挂载`,`success`)}catch(e){throw await z().catch(()=>void 0),e}},[P,z]),Lt=(0,x.useCallback)(async e=>{await me(!0).catch(()=>void 0);let t=await m(e,he);return await R(),t},[R]),Rt=async(e,t,n)=>{if(!P)return;let r=(P.taskOverrides??[]).filter(t=>t.id!==e),i={id:e,name:t.trim(),command:n.trim()};(i.name||i.command)&&r.push(i),await Pt({taskOverrides:r})},zt=async e=>{P&&await Pt({taskOverrides:(P.taskOverrides??[]).filter(t=>t.id!==e),hiddenTasks:[...new Set([...P.hiddenTasks??[],e])]})},Bt=async()=>{await Pt({taskOverrides:[],hiddenTasks:[]})},Vt=async(e,t)=>{if(!P)return;let n=t.trim();n?await Ft([...P.customTasks??[],{id:``,name:e,command:n}]):w(`先填要执行的命令`)},Ht=async e=>{P&&await Ft((P.customTasks??[]).filter(t=>t.id!==e))},Ut=async()=>{let e=at.trim();if(!e)M(`请先选择或填写项目目录`);else{k(!0),M(``);try{let t;t=j?(await ge({id:j.id,dir:e})).id:(await ke(e)).id,await z(),ne(t),i(Cn,t),L(`run`),it(!1),st(null),ot(``)}catch(t){let r=t instanceof Error?t.message:String(t),a=n.find(t=>t.dir===e);if(a&&/已经添加/.test(r)){ne(a.id),i(Cn,a.id),L(`run`),it(!1),ot(``);return}M(r)}finally{k(!1)}}},Wt=async()=>{if(D){h(``);try{await g(D.id),Xe(!0)}catch(e){h(e instanceof Error?e.message:String(e))}}},Gt=()=>{wt?.failureFlags?kt({lastFailed:!0}):h(`当前运行任务不支持只跑失败用例,切到「全量运行」或 pytest 任务再试`)},Kt=async()=>{if(pt){h(``);try{await Ce(pt.id),D?.id===pt.id&&(qe(null),O(``)),u&&await B(u),await z().catch(()=>null)}catch(e){h(e instanceof Error?e.message:String(e))}finally{mt(null)}}};if(!e||ue)return(0,N.jsx)(`div`,{className:`tw-hydrate-pending h-full w-full`,children:(0,N.jsx)(Fe,{label:`加载自动化测试…`})});if(!t)return(0,N.jsx)(`div`,{className:`tw-lib-notice rounded-xl border border-amber-200 bg-amber-50 px-5 py-8 text-sm text-amber-900`,children:`该插件未启用,到「我的插件」里打开「自动化测试」就能挂载 Playwright / pytest / Selenium 项目。`});let qt=(0,N.jsxs)(`div`,{className:`border-b border-stone-100 bg-stone-50/60 px-4 py-3`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium text-stone-700`,children:j?`重新指定项目目录`:`挂载项目`}),(0,N.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`自动识别 Playwright / pytest / Selenium,只读取与运行,不改项目文件`})]}),(0,N.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,N.jsx)(`input`,{className:`h-8 min-w-[260px] flex-1 rounded-lg border border-stone-200 bg-white px-2.5 font-mono text-xs text-stone-700 outline-none transition-colors focus:border-[#3370ff]`,value:at,onChange:e=>ot(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Ut()},placeholder:`/path/to/your-test-project`,"aria-label":`项目目录`,spellCheck:!1}),(0,N.jsxs)(`button`,{type:`button`,className:K,onClick:()=>void Nt(),disabled:lt,children:[(0,N.jsx)(Le,{name:`folder`,size:13}),lt?`选择中…`:`浏览…`]}),(0,N.jsx)(`button`,{type:`button`,className:G,onClick:()=>void Ut(),disabled:Ze||lt||!at.trim(),children:Ze?`挂载中…`:j?`保存目录`:`挂载`})]}),ct?(0,N.jsx)(`p`,{className:`mt-2 rounded-lg bg-red-50 px-3 py-2 text-[11px] leading-relaxed text-red-600`,children:ct}):null]}),Jt=D?W?Math.max(0,_t-Date.parse(D.startedAt)):D.durationMs:0,Yt=rt||!n.length;return(0,N.jsxs)(`section`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-white`,children:[fe?(0,N.jsx)(b,{message:fe,onClose:()=>h(``)}):null,(0,N.jsxs)(`header`,{className:`relative z-20 flex h-12 shrink-0 items-center gap-3 border-b border-stone-200 px-4`,children:[(0,N.jsx)(`h1`,{className:`shrink-0 text-sm font-semibold text-stone-800`,children:`自动化测试`}),(0,N.jsx)(`span`,{className:`h-4 w-px shrink-0 bg-stone-200`,"aria-hidden":`true`}),P?(0,N.jsx)(`div`,{role:`tablist`,"aria-label":`自动化测试视图`,className:`flex h-full shrink-0 items-stretch`,children:Sn.map(e=>{let t=e.value===`history`?E.length:0,n=Ee===e.value;return(0,N.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>L(e.value),className:`relative flex h-full items-center gap-1.5 border-b-2 px-2.5 text-[13px] transition-colors ${n?`border-[#3370ff] font-medium text-stone-900`:`border-transparent text-stone-500 hover:text-stone-800`}`,children:[e.label,t?(0,N.jsx)(`span`,{className:`rounded-full px-1.5 text-[11px] leading-4 tabular-nums ${n?`bg-[#eaf1ff] text-[#3370ff]`:`bg-stone-100 text-stone-400`}`,children:t}):null]},e.value)})}):(0,N.jsx)(`span`,{className:`truncate text-[11px] text-stone-400`,children:se?`正在读取挂载列表…`:`还没有挂载项目`}),(0,N.jsxs)(`div`,{className:`ml-auto flex min-w-0 shrink-0 items-center gap-2`,children:[P?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`flex h-8 w-40 min-w-0 items-center rounded-lg border bg-white px-2.5 text-left transition-colors hover:border-stone-300 focus:border-[#4176e6] focus:outline-none focus-visible:ring-2 focus-visible:ring-[#4176e6]/30 ${bt?`border-amber-300 text-amber-700`:`border-stone-200`}`,onClick:()=>Ge(!0),"aria-label":`挂载提示词`,children:(0,N.jsx)(p,{text:bt?`未挂载提示词 · 点击挂载`:F,className:`min-w-0 flex-1 truncate text-sm ${bt?`text-amber-700`:`text-stone-700`}`})}),(0,N.jsx)(ie,{options:I,value:P.id,onChange:e=>{ne(e),i(Cn,e)},compact:!0,className:`w-48`,ariaLabel:`切换项目`,triggerClassName:P.exists?``:`text-amber-700`,hideTriggerHint:!0,renderOptionAction:e=>{let t=n.find(t=>t.id===e.value);return t?(0,N.jsx)(`button`,{type:`button`,disabled:Ze,"aria-label":`移出 ${t.name}`,className:`tw-icon-danger rounded p-1 opacity-0 transition-opacity focus-visible:opacity-100 group-hover:opacity-100 disabled:opacity-0 disabled:group-hover:opacity-40`,onClick:()=>ft(t),children:(0,N.jsx)(Le,{name:`trash`,size:13})}):null}}),P.frameworkReady?(0,N.jsx)(`span`,{className:`shrink-0 whitespace-nowrap text-[11px] text-stone-500`,children:[c.find(e=>e.id===P.framework)?.label||P.framework,P.kind?Oe(P.kind):``].filter(Boolean).join(` · `)}):(0,N.jsx)(`span`,{className:`shrink-0 whitespace-nowrap text-[11px] text-amber-600`,children:`运行环境未就绪`}),(0,N.jsx)(vt,{onOpen:e=>Mt({path:``,app:e?.id}),disabled:!P.exists})]}):null,(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`${K} ${rt?`border-[#4176e6] bg-[#f2f6ff] text-[#3566d0] hover:bg-[#eaf1ff]`:``}`,onClick:()=>rt?jt():At(null),disabled:Ze||lt,"aria-expanded":rt,children:[(0,N.jsx)(Le,{name:`plus`,size:13}),`挂载`]}),P?(0,N.jsxs)(te,{as:`div`,className:`relative shrink-0`,children:[(0,N.jsx)(f,{type:`button`,className:`flex h-8 w-8 items-center justify-center rounded-lg border border-stone-200 text-stone-500 transition-colors hover:bg-stone-50 hover:text-stone-700`,"aria-label":`更多操作`,children:(0,N.jsx)(Le,{name:`more`,size:16})}),(0,N.jsxs)(ee,{anchor:{to:`bottom end`,gap:4,padding:12},transition:!0,className:`tw-select-menu tw-menu-anim z-80 w-max min-w-[168px] space-y-0.5 rounded-lg p-1 pb-2 shadow-lg ring-1 ring-stone-200 focus:outline-none`,children:[(0,N.jsx)(d,{children:(0,N.jsx)(`button`,{type:`button`,className:`flex w-full items-center rounded-md px-2.5 py-1.5 text-left text-sm text-stone-700 data-[focus]:bg-stone-50`,onClick:()=>{(navigator.clipboard?.writeText(P.dir))?.then(()=>gt(!0)).catch(()=>void 0),window.setTimeout(()=>gt(!1),1200)},children:ht?`已复制路径`:`复制项目路径`})}),(0,N.jsx)(d,{children:(0,N.jsx)(`button`,{type:`button`,className:`flex w-full items-center rounded-md px-2.5 py-1.5 text-left text-sm text-stone-700 data-[focus]:bg-stone-50`,onClick:()=>At(P),children:`重新指定目录`})}),(0,N.jsx)(`div`,{className:`my-1 h-px bg-stone-100`,"aria-hidden":`true`}),(0,N.jsx)(d,{children:(0,N.jsx)(`button`,{type:`button`,className:`flex w-full items-center rounded-md px-2.5 py-1.5 text-left text-sm text-red-600 data-[focus]:bg-red-50`,onClick:()=>ft(P),children:`移出项目`})})]})]}):null]})]})]}),!P&&!se?(0,N.jsx)(`p`,{className:`shrink-0 border-b border-stone-100 bg-stone-50/60 px-4 py-1.5 text-[11px] text-stone-500`,children:`还没有挂载项目。点右上角「挂载」选一个 Playwright / pytest / Selenium 目录,自动识别框架。`}):null,(0,N.jsx)(`div`,{className:`grid shrink-0 transition-[grid-template-rows,opacity] duration-200 ease-out ${Yt?`grid-rows-[1fr] opacity-100`:`grid-rows-[0fr] opacity-0`}`,"aria-hidden":!Yt,children:(0,N.jsx)(`div`,{className:`overflow-hidden`,inert:!Yt,children:qt})}),(0,N.jsx)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden`,children:(0,N.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:P?bt?(0,N.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 px-6 py-10 text-center`,children:[(0,N.jsx)(`p`,{className:`text-sm font-medium text-stone-700`,children:`这个项目还没有挂载提示词`}),(0,N.jsx)(`p`,{className:`max-w-md text-xs leading-relaxed text-stone-500`,children:Ee===`run`?`挂载后才能运行用例:运行前的规划与命令都由提示词驱动,缺了它跑出来的结果不可信。`:Ee===`generate`?`挂载后才能生成:规划、探索、生成代码三段都按提示词里的要求执行。`:`历史记录里是已经跑完的结果,挂载提示词后可以重新跑同一条用例。`}),(0,N.jsx)(`button`,{type:`button`,className:`${G} mt-1`,onClick:()=>Ge(!0),children:`挂载提示词`}),(0,N.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:`一份提示词可同时挂给多个项目;也可以先去「提示词管理」新建一份`})]}):(0,N.jsxs)(N.Fragment,{children:[Ee===`run`?(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 p-4`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`text-xs text-stone-400`,children:`运行任务`}),(0,N.jsx)(ie,{options:Tt,value:wt?.id??`full`,onChange:e=>{S(e),P&&i(Dn(P.id),e)},compact:!0,className:`w-60`,ariaLabel:`运行任务`}),(0,N.jsxs)(`button`,{type:`button`,className:K,onClick:()=>{w(``),Be(!0)},disabled:Ze,"aria-label":`运行配置`,children:[(0,N.jsxs)(`svg`,{className:`h-3.5 w-3.5 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,N.jsx)(`path`,{d:`M4 7h10M18 7h2M4 17h4M12 17h8`}),(0,N.jsx)(`circle`,{cx:`16`,cy:`7`,r:`2`}),(0,N.jsx)(`circle`,{cx:`10`,cy:`17`,r:`2`})]}),`配置`]}),(0,N.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:W?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`button`,{type:`button`,className:`${G} cursor-default`,disabled:!0,children:[(0,N.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse rounded-full bg-white/90`}),`运行中…`]}),(0,N.jsx)(`button`,{type:`button`,className:kn,onClick:()=>void Wt(),disabled:Ye,children:Ye?`停止中…`:`停止`})]}):(0,N.jsxs)(`button`,{type:`button`,className:G,onClick:()=>void kt(),disabled:Ze||!P.exists,children:[(0,N.jsx)(Le,{name:`play`,size:14}),Ze?`启动中…`:Et?`重新运行`:`运行`]})})]}),P.exists?P.frameworkReady?null:(0,N.jsx)(`p`,{className:`rounded-lg bg-amber-50 px-3 py-2 text-xs leading-relaxed text-amber-700`,children:P.readyHint||`运行环境未就绪,先按项目要求安装依赖后再运行。`}):(0,N.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 rounded-lg bg-amber-50 px-3 py-2 text-xs leading-relaxed text-amber-700`,children:[`项目目录已不存在(换机器或被移动过),记录与历史报告不会丢。`,(0,N.jsx)(`button`,{type:`button`,className:`font-medium text-amber-800 underline underline-offset-2 hover:text-amber-900`,onClick:()=>At(P),children:`重新指定目录`})]}),D?(0,N.jsxs)(`div`,{className:`rounded-lg border border-stone-200 bg-stone-50/60 px-3 py-2.5`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-stone-600`,children:[(0,N.jsx)(Pe,{tone:Ae[D.status].tone,children:Ae[D.status].label}),(0,N.jsxs)(`span`,{className:`tabular-nums`,children:[`耗时 `,xe(Jt)]}),D.status===`running`?null:(0,N.jsx)(`span`,{className:`tabular-nums`,children:je(D)}),(0,N.jsx)(`span`,{className:D.command?`max-w-[360px] truncate font-mono text-[11px] text-stone-400`:`text-stone-400`,children:D.command?De(D.command):ve(D.args,D.framework)}),D.reportRel?(0,N.jsxs)(`span`,{className:`max-w-[320px] truncate font-mono text-[11px] text-stone-400`,children:[`存储:`,D.reportRel.replace(/\/[^/]+$/,``)]}):null,(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[D.reportUrl&&D.status!==`running`?(0,N.jsx)(`a`,{className:K,href:D.reportUrl,target:`_blank`,rel:`noreferrer`,children:`查看报告`}):null,D.failed>0&&D.status!==`running`?(0,N.jsx)(`button`,{type:`button`,className:K,onClick:Gt,disabled:Ze||!P.exists,children:`重跑失败用例`}):null]})]}),D.error?(0,N.jsx)(`pre`,{className:`mt-2 max-h-24 overflow-auto whitespace-pre-wrap break-all rounded bg-red-50 px-2 py-1.5 text-[11px] leading-relaxed text-red-600`,children:D.error}):null]}):null,(0,N.jsxs)(`div`,{className:`flex min-h-[220px] flex-1 flex-col overflow-hidden rounded-lg border border-stone-200`,children:[(0,N.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center gap-2 border-b border-stone-100 bg-stone-50 px-3 text-xs text-stone-500`,children:[(0,N.jsx)(`span`,{children:`运行日志`}),W?(0,N.jsx)(`span`,{className:`text-[#3370ff]`,children:`实时`}):null,Je?(0,N.jsxs)(`span`,{className:`tabular-nums text-stone-400`,children:[Je.length,` 字符`]}):null]}),(0,N.jsx)(`pre`,{ref:et,onScroll:Ot,className:`min-h-0 flex-1 overflow-auto whitespace-pre-wrap break-all bg-white p-3 font-mono text-[12px] leading-relaxed text-stone-700`,children:Je||`运行后这里会显示实时输出…`})]})]}):null,Ee===`generate`?(0,N.jsx)(gn,{project:P,promptFile:F,onError:h},P.id):null,Ee===`history`?(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:E.length===0?(0,N.jsx)(Ie,{children:`还没有运行记录`}):(0,N.jsxs)(`table`,{className:`w-full border-collapse text-sm`,children:[(0,N.jsx)(`thead`,{children:(0,N.jsxs)(`tr`,{className:`border-b border-stone-200 text-left text-xs text-stone-400`,children:[(0,N.jsx)(`th`,{className:`px-2 py-2 font-medium`,children:`开始时间`}),(0,N.jsx)(`th`,{className:`px-2 py-2 font-medium`,children:`框架`}),(0,N.jsx)(`th`,{className:`px-2 py-2 font-medium`,children:`结果`}),(0,N.jsx)(`th`,{className:`px-2 py-2 font-medium`,children:`用例`}),(0,N.jsx)(`th`,{className:`px-2 py-2 font-medium`,children:`耗时`}),(0,N.jsx)(`th`,{className:`px-2 py-2 font-medium`,children:`参数`}),(0,N.jsx)(`th`,{className:`px-2 py-2 text-right font-medium`,children:`操作`})]})}),(0,N.jsx)(`tbody`,{children:E.map(e=>(0,N.jsxs)(`tr`,{className:`border-b border-stone-100 last:border-0`,children:[(0,N.jsx)(`td`,{className:`whitespace-nowrap px-2 py-2 text-xs text-stone-600`,children:be(e.startedAt)}),(0,N.jsx)(`td`,{className:`whitespace-nowrap px-2 py-2 text-xs text-stone-500`,children:c.find(t=>t.id===e.framework)?.label??e.framework}),(0,N.jsx)(`td`,{className:`px-2 py-2`,children:(0,N.jsx)(Pe,{tone:Ae[e.status].tone,children:Ae[e.status].label})}),(0,N.jsx)(`td`,{className:`whitespace-nowrap px-2 py-2 text-xs tabular-nums text-stone-600`,children:e.total?`${e.passed}/${e.total} 通过${e.failed?` · ${e.failed} 失败`:``}`:`—`}),(0,N.jsx)(`td`,{className:`whitespace-nowrap px-2 py-2 text-xs tabular-nums text-stone-600`,children:xe(e.durationMs)}),(0,N.jsx)(`td`,{className:`max-w-[240px] truncate px-2 py-2 text-xs text-stone-500`,children:e.command?De(e.command):ve(e.args,e.framework)}),(0,N.jsxs)(`td`,{className:`whitespace-nowrap px-2 py-2 text-right`,children:[(0,N.jsx)(`button`,{type:`button`,className:`text-xs text-[#3370ff] hover:underline`,onClick:()=>{L(`run`),St(e.id).catch(e=>h(String(e)))},children:`日志`}),e.reportUrl?(0,N.jsx)(`a`,{className:`ml-3 text-xs text-[#3370ff] hover:underline`,href:e.reportUrl,target:`_blank`,rel:`noreferrer`,children:`报告`}):null,(0,N.jsx)(`button`,{type:`button`,className:`ml-3 text-xs text-red-500 hover:underline`,onClick:()=>mt(e),children:`删除`})]})]},e.id))})]})}):null]}):(0,N.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-1 px-6 py-10 text-center`,children:[(0,N.jsx)(`p`,{className:`text-sm text-stone-500`,children:`挂载一个项目后就能在这里运行用例`}),(0,N.jsx)(`p`,{className:`text-xs text-stone-400`,children:`移出项目只删除挂载记录,项目文件与历史报告都保留`})]})})}),(0,N.jsx)(pe,{open:We,prompts:T.map(e=>e.value),value:P?.promptFile&&T.some(e=>e.value===P.promptFile)?P.promptFile:``,force:bt,onClose:()=>Ge(!1),onMount:It,onCreate:Lt}),(0,N.jsx)(xt,{open:ze,projectName:P?.name??``,detected:U.filter(e=>!e.custom&&e.kind!==`full`),customTasks:P?.customTasks??[],hiddenCount:P?.hiddenTasks?.length??0,editedCount:(P?.taskOverrides??[]).length,error:C,onClose:()=>{Be(!1),w(``)},onAdd:(e,t)=>Vt(e,t),onRemove:e=>Ht(e),onEdit:(e,t,n)=>Rt(e,t,n),onHide:e=>zt(e),onReset:()=>Bt(),onRescan:()=>z().then(()=>void 0)}),(0,N.jsx)(re,{open:!!dt,title:`移出项目`,message:`确定把「${dt?.name??``}」移出挂载列表吗?\n只删除挂载记录,项目文件与历史报告都保留;该项目挂载的提示词也会自动取消引用。`,confirmLabel:`移出`,danger:`outline`,onClose:()=>ft(null),onConfirm:()=>{let e=dt;ft(null),e&&v(e.id).then(async()=>{let t=await z();if(e.id===u){let e=t[0]?.id??``;ne(e),i(Cn,e)}Se()}).catch(e=>h(e instanceof Error?e.message:String(e)))}}),(0,N.jsx)(re,{open:!!pt,title:`删除运行记录`,message:`会同时删除该次运行的 HTML 报告与原始日志,确定删除吗?`,confirmLabel:`删除`,danger:`solid`,onClose:()=>mt(null),onConfirm:()=>void Kt()})]})}export{An as default};
@@ -1 +0,0 @@
1
- var e=`0.1.21`;export{e as t};
@@ -1 +0,0 @@
1
- var e={no:`用例编号`,title:`用例标题`,precondition:`前置条件`,steps:`测试步骤`,expected:`预期结果`,priority:`优先级`,type:`用例类型`,module:`所属模块`,requirement:`需求编号`},t={no:[`用例编号`,`测试用例编号`,`案例编号`,`用例号`,`用例id`,`编号`,`no`,`caseid`,`tc编号`],title:[`用例标题`,`用例名称`,`测试用例标题`,`测试分项目`,`测试项目`,`测试点`,`检查点`,`测试内容`,`用例描述`,`用例说明`,`标题`,`名称`,`摘要`,`title`,`casename`],precondition:[`前置条件`,`预置条件`,`前提条件`,`准备条件`,`初始条件`,`前置`,`precondition`],steps:[`测试步骤`,`操作步骤`,`执行步骤`,`用例步骤`,`测试过程`,`操作过程`,`步骤`,`steps`,`step`],expected:[`预期结果`,`期望结果`,`预期内容`,`期望内容标准`,`预期效果`,`期望结果标准`,`验收标准`,`检查结果`,`预期`,`expected`],priority:[`优先级`,`优先级别`,`重要级别`,`重要程度`,`级别`,`priority`],type:[`用例类型`,`测试类型`,`用例种类`,`类型`,`类别`,`type`],module:[`所属模块`,`测试模块`,`功能模块`,`所属功能`,`所属子系统`,`模块`,`测试项目`,`module`],requirement:[`需求编号`,`关联需求`,`需求id`,`需求`,`requirement`]};function n(e){return String(e??``).replace(/[((][^))]*[))]/g,``).replace(/[\s**・·::]/g,``).toLowerCase().trim()}function r(e){let r=e.map(e=>({raw:String(e??``),norm:n(e)})).filter(e=>e.norm&&e.raw),i={},a=new Set,o=Object.keys(t);for(let e of o)for(let o of t[e].map(n)){let t=r.find(e=>!a.has(e.raw)&&e.norm===o);if(t){i[e]=t.raw,a.add(t.raw);break}}for(let e of o)if(!i[e])for(let o of t[e].map(n)){if(o.length<3)continue;let t=r.find(e=>!a.has(e.raw)&&Math.abs(e.norm.length-o.length)<=2&&(e.norm.startsWith(o)||o.startsWith(e.norm)));if(t){i[e]=t.raw,a.add(t.raw);break}}return i}function i(e){let t=[];for(let n of e)for(let e of Object.keys(n))t.includes(e)||t.push(e);return t}function a(t){if(!t.length)return[...t];let n=r(i(t));return t.map(t=>{let r={...t};for(let t of Object.keys(e)){let i=n[t];i&&(String(r[e[t]]??``).trim()||(r[e[t]]=r[i]??``))}return r})}function o(t){let n=[];for(let r of Object.keys(e)){let i=t[r];if(!i)continue;let a=e[r];n.push(i===a?a:`${a}(表头:${i})`)}return n.join(` / `)}export{o as i,a as n,r,e as t};
@@ -1,16 +0,0 @@
1
- import{p as e}from"./app-config.CF1xVPmo.js";import{i as t,s as n}from"./plugins.CVM1IaoC.js";import{i as r,r as i}from"./case-types.DS1EQ5yP.js";import{t as a}from"./export.joBT53eb.js";import{a as o,o as s,s as c,t as l}from"./case-template.BGCVpSKI.js";import{r as u,t as d}from"./case-fields.CtFiDM_d.js";import{_ as f,v as p}from"./project-docs.DAw9bzgk.js";var m=`/__tb_case_sessions`,h=`tw.case.sessions.v1`,g=!1;function _(){return`csess_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function v(e){if(typeof e==`string`&&e.trim()){let t=e.trim();return r().some(e=>e.id===t),t}return r()[0]?.id??`functional`}function y(e){if(!e||!Array.isArray(e.sessions))return{sessions:[],activeId:``};let t=e.sessions.filter(e=>e&&typeof e==`object`&&e.id).map(e=>({...e,caseType:v(e.caseType)})),n=typeof e.activeId==`string`?e.activeId:``;return t.length&&!t.some(e=>e.id===n)&&(n=t[0].id),t.length||(n=``),{sessions:t,activeId:n}}function b(){try{let t=localStorage.getItem(e(h));return t?y(JSON.parse(t)):{sessions:[],activeId:``}}catch{return{sessions:[],activeId:``}}}function x(t){try{localStorage.setItem(e(h),JSON.stringify(t))}catch{}}async function S(){try{let e=await fetch(m,{signal:AbortSignal.timeout(2e3)});if(e.ok){let t=await e.json();g=!0;let n=y(t.store);return x(n),n}}catch{}return g=!1,b()}function C(){return b()}async function w(e){if(x(e),g)try{await fetch(m,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({store:e})})}catch{}}function T(e){x(e),w(e)}function E(e){let t=Date.now(),n={id:_(),title:e.title?.trim()||`用例生成`,createdAt:t,updatedAt:t,caseType:e.caseType,outputFormat:e.outputFormat,reqPaths:e.reqPaths,templateId:e.templateId,templateTitle:e.templateTitle,promptPath:e.promptPath,knowledgePaths:e.knowledgePaths?.length?[...e.knowledgePaths]:void 0,messages:[]};return T({sessions:[n,...b().sessions],activeId:n.id}),n}function D(e,t){let n=b(),r=n.sessions.map(n=>n.id===e?{...n,...t,updatedAt:Date.now()}:n),i={...n,sessions:r};return T(i),i}function O(e){return e.reqSource?e.reqSource:e.reqPath?{kind:`doc`,path:e.reqPath}:void 0}function k(e){let t=[e.templateTitle||e.templateId?.split(`/`).pop()||`默认模板`,e.outputFormat.toUpperCase()],n=O(e);return n?.kind===`stories`?t.push(`${e.docTitle||`用户故事`} · ${n.storyIds.length} 条故事`):n?.kind===`doc`&&t.push(n.path.split(`/`).pop()||n.path),e.testPointIds?.length&&t.push(`${e.testPointIds.length} 条测试点`),t.join(` · `)}function A(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0]??e.match(/\[[\s\S]*\]/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(Array.isArray(e)&&e.length>0)return{docTitle:``,cases:e,coverageRate:null,uncovered:[],writeNote:``};if(e&&typeof e==`object`){let t=e,n=t.用例??t.cases??t.items;if(!Array.isArray(n)||n.length===0)return null;let r=t.需求名称??t.文档名称??t.docTitle??t.title,i=typeof r==`string`?r.trim():``,a=t.覆盖需求率??t.coverageRate??t.coverage,o=null;if(typeof a==`number`&&Number.isFinite(a))o=Math.max(0,Math.min(100,Math.round(a)));else if(typeof a==`string`&&a.trim()){let e=parseInt(a.replace(/%/g,``),10);Number.isFinite(e)&&(o=Math.max(0,Math.min(100,e)))}let s=t.未覆盖说明??t.uncovered??t.omissions,c=Array.isArray(s)?s.map(e=>String(e).trim()).filter(Boolean):typeof s==`string`&&s.trim()?[s.trim()]:[],l=t.编写说明??t.note??t.summary,u=typeof l==`string`?l.trim():``;return{docTitle:i,cases:n,coverageRate:o,uncovered:c,writeNote:u}}}catch{return null}return null}function j(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,`-`).slice(0,64)||`cases`}function M(e){let t=String(e??``).trim().split(/[/\\]/).pop()?.trim()||``;t=t.replace(/\.(xlsx|xls|docx|doc|md|txt|csv)$/i,``),t=t.replace(/_?需求文档$/u,``).replace(/_?需求说明$/u,``).replace(/_?需求$/u,``).trim(),t=t.replace(/_\d{8}-\d{6}$/,``);for(let e of r()){let n=`_${e.label}用例`;if(t.endsWith(n)){t=t.slice(0,-n.length);break}}return/迭代版本$/u.test(t)?j(t):/v?\d+(?:\.\d+)*版本$/iu.test(t)?j(t.replace(/版本$/u,`迭代版本`)):/v\d+(?:\.\d+)+$/i.test(t)?j(`${t}迭代版本`):j(t)}function N(e){let t=M(e).replace(/迭代版本$/u,``).replace(/版本$/u,``).trim();return t=t.replace(/[\s_\-—·()()[\]【】]/g,``).toLowerCase(),t}function P(e,t){let n=N(e),r=N(t);return n.length<4||r.length<4?!1:n===r||n.includes(r)||r.includes(n)}function F(e=new Date){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}${t(e.getMonth()+1)}${t(e.getDate())}-${t(e.getHours())}${t(e.getMinutes())}${t(e.getSeconds())}`}function I(e,t,n=new Date){let r=`_${i(t).label}用例`;return`${M(e)||`cases`}${r}_${F(n)}`}function L(e,t){let n=String(e||``).match(RegExp(`${t}-\\d+`,`i`));return n?n[0].toUpperCase():``}function R(e,t){if(e===t)return 0;if(!e)return 1;if(!t)return-1;let n=e.match(/^(.*?)(\d+)$/),r=t.match(/^(.*?)(\d+)$/);return n&&r&&n[1]===r[1]?Number(n[2])-Number(r[2]):e.localeCompare(t,`zh`)}function z(e,t,n){if(e.length<=1)return e;let r=u(t),i=r.requirement||d.requirement,a=r.no||d.no,o=r.title||d.title,s=new Map((n?.storyIds??[]).map((e,t)=>[e.toUpperCase(),t])),c=new Map((n?.testPointIds??[]).map((e,t)=>[e.toUpperCase(),t]));return[...e].map((e,t)=>({row:e,index:t})).sort((e,t)=>{let n=L(e.row[i]??``,`US`)||L(e.row[o]??``,`US`),r=L(t.row[i]??``,`US`)||L(t.row[o]??``,`US`);if(s.size){let e=n?s.get(n)??s.size+1:s.size+2,t=r?s.get(r)??s.size+1:s.size+2;if(e!==t)return e-t}let l=R(n,r);if(l)return l;let u=L(e.row[o]??``,`TP`)||L(e.row[a]??``,`TP`),d=L(t.row[o]??``,`TP`)||L(t.row[a]??``,`TP`);if(c.size&&(u||d)){let e=u?c.get(u)??c.size+1:c.size+2,t=d?c.get(d)??c.size+1:c.size+2;if(e!==t)return e-t}return R(u,d)||R(String(e.row[a]??``),String(t.row[a]??``))||e.index-t.index}).map(e=>e.row)}function B(e,t){let n=[];for(let r of t){let t=e.filter(e=>!String(e[r]??``).trim()).length;t===e.length?n.push(`字段「${r}」全部为空`):t>Math.max(2,Math.floor(e.length*.3))&&n.push(`字段「${r}」有 ${t}/${e.length} 条为空`)}return n}function V(e,t=``){let n=i(e.caseType).label,r=e.templateHeaders.length>0?e.templateHeaders:[...a],o=e.outputFormat===`md`?`最终结果将保存为 Markdown 表格文件`:e.outputFormat===`csv`?`最终结果将保存为 CSV 文件`:`最终结果将保存为 Excel 文件`,s=e.promptBody.trim();if(!s)throw Error(`请先在生成测试用例插件中选择提示词`);let c=e.templateBody?`\n\n### 用例模板:${e.templateTitle||e.templateId||``}\n${e.templateBody}`:`\n\n### 模板字段:${r.join(`、`)}`,l=e.reqBlock?`\n\n${e.reqBlock}`:``,u=e.testPointIds?.length??0;return`${s}
2
- ${c}${l}${e.testPointBlock?`\n\n### 测试点(逐条覆盖,别合并成一条用例;共 ${u||`全部`} 条,下文为完整清单)\n${e.testPointBlock}`:``}
3
-
4
- 【运行时约束 · 生成测试用例插件已启用】
5
- - 本轮以「生成测试用例」插件所选提示词为准,不要再遵循工作台闲聊/系统提示词风格
6
- - 用例类型:${n}
7
- - ${o}
8
- ${e.testPointBlock?`- 已选测试点共 ${u||`全部`} 条,正文已完整注入,须逐条落到用例里;测试点的前置 / 步骤 / 预期分别对应用例的对应字段。不要声称「材料未提供后半段测试点」\n`:``}- 需求名称默认可用「${t||`未命名需求`}」
9
- - 「用例」数组必须按上文材料出现的顺序输出(需求文档段落顺序 / 用户故事 US 顺序 / 测试点清单顺序),不要按模块名、优先级或维度重排
10
- - 「用例」对象键必须与模板字段完全一致:${r.join(`、`)}
11
- - 仅输出一个 JSON 对象(可无代码围栏),结构为:
12
- {"需求名称":"...","覆盖需求率":0-100,"未覆盖说明":["..."],"编写说明":"...","用例":[...]}
13
- - 「未覆盖说明」只写需求/故事里确有、但测试点清单未给出的缺口;已注入的测试点不得再报「未提供」
14
- - 不要输出 JSON 以外的解释性正文;界面只会展示执行摘要,用例由系统静默入库`}function H(e=0){return`正在编写用例…\n\n已用 ${Math.max(0,Math.floor(e))}s · 通常约 30–120 秒\n完成后将给出覆盖率与入库结果。`}function U(e){if(!e.ok)return[`**执行失败**`,``,e.error||`未知错误`,``,`可调整插件中的需求 / 模板 / 提示词后重试。`].join(`
15
- `);let t=[`**执行成功**`,``,`- 需求名称:${e.title||`—`}`,`- 共编写:${e.count??0} 条用例`,`- 覆盖需求率:${e.coverageRate==null?`未给出(已按用例入库)`:`${e.coverageRate}%`}`];e.path&&t.push(`- 入库文件:用例管理/${e.path}`),e.writeNote&&t.push(``,`**编写说明**`,e.writeNote);let n=e.uncovered??[];if(t.push(``,`**未覆盖 / 未编写原因**`),n.length)for(let e of n)t.push(`- ${e}`);else t.push(`- 无(模型未声明未覆盖项)`);let r=e.fieldGaps??[];if(r.length){t.push(``,`**字段完整性检测**`);for(let e of r)t.push(`- ${e}`)}return t.join(`
16
- `)}async function W(e){if(!t(`cases`))throw Error(n(`cases`));let r=i(e.caseType),l=`${I(e.title,e.caseType)}${e.outputFormat===`md`?`.md`:e.outputFormat===`csv`?`.csv`:`.xlsx`}`,u=e.headers.length?e.headers:[...a];return e.outputFormat===`md`?await p(`cases`,l,s(e.cases,e.title,u)):e.outputFormat===`csv`?await p(`cases`,l,o(e.cases,u)):await f(`cases`,l,await c(e.cases,u,r.label)),l}async function G(e,t,n){let r=A(e);if(!r){let e=`未能解析出用例结果,未写入文件`;return{ok:!1,error:e,summary:U({ok:!1,error:e})}}let o=t.templateHeaders.length>0?t.templateHeaders:[...a],s=O(t),c=s?.kind===`stories`?s.storyIds:void 0,u=z(l(r.cases,o),o,{storyIds:c,testPointIds:t.testPointIds}),d=(n||t.docTitle||``).trim()||r.docTitle||i(t.caseType).label,f=B(u,o);try{let e=await W({cases:u,headers:o,caseType:t.caseType,outputFormat:t.outputFormat,title:d}),n=U({ok:!0,title:d,path:e,count:u.length,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:f});return{ok:!0,path:e,count:u.length,title:d,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:f,summary:n}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,summary:U({ok:!1,error:t})}}}export{H as a,E as c,T as d,D as f,N as i,S as l,P as n,G as o,I as r,k as s,V as t,C as u};
@@ -1,5 +0,0 @@
1
- import{s as e}from"./react.Blvh0GOs.js";import{a as t,i as n,n as r,o as i,r as a,t as o}from"./export.joBT53eb.js";import{t as s}from"./jszip.min.Bh2Mgo40.js";var c=e(s(),1);function l(e){return e.some(e=>String(e??``).trim().length>0)}function u(e){let r=n(e,{type:`base64`}),i=r.SheetNames[0]??`Sheet1`,a=r.Sheets[i];if(!a)return{headers:[...o],body:``};let s=t.sheet_to_json(a,{header:1,defval:``,raw:!1}),c=(s.find(l)??[]).map(e=>String(e??``).trim()).filter(Boolean);if(!c.length)return{headers:[...o],body:`(模板工作表「${i}」无表头)`};let u=s.filter(l).slice(1,4),d=[`工作表:${i}`,`字段(必须原样作为 JSON 对象键,顺序一致):${c.join(`、`)}`,``,`样例行(风格与粒度请对齐,勿照抄业务内容):`];for(let e of u){let t={};c.forEach((n,r)=>{t[n]=String(e[r]??``).trim()}),d.push(JSON.stringify(t,null,2))}return{headers:c,body:d.join(`
2
- `)}}function d(e){let t=(e.split(/\r?\n/).find(e=>e.trim())??``).split(`,`).map(e=>e.replace(/^"|"$/g,``).trim()).filter(Boolean);return t.length?{headers:t,body:`字段(必须原样作为 JSON 对象键):${t.join(`、`)}\n\n${e}`}:{headers:[...o],body:e}}function f(e){let t=e.match(/^\|(.+)\|\s*$/m);if(t?.[1]){let n=t[1].split(`|`).map(e=>e.trim()).filter(e=>e&&!/^[-:]+$/.test(e));if(n.length)return{headers:n,body:`字段(必须原样作为 JSON 对象键):${n.join(`、`)}\n\n${e}`}}return{headers:[...o],body:e}}function p(e,t){let n=t.length?t:[...o];return e.map(e=>{let t=e??{},i={};for(let e of n){let n=t[e],o=typeof n==`string`?n:n==null?``:String(n);i[e]=r(e)?a(o):o}return i})}var m={实际结果:[`P`,`F`],优先级:[`P0`,`P1`,`P2`,`P3`],用例状态:[`待验证`,`通过`,`不通过`,`阻塞`,`跳过`]};function h(e){let t=e,n=``;for(;t>=0;)n=String.fromCharCode(t%26+65)+n,t=Math.floor(t/26)-1;return n}function g(e){let t=[];return e.forEach((e,n)=>{let r=m[e];if(!r?.length)return;let i=h(n),a=r.join(`,`);t.push(`<dataValidation type="list" allowBlank="1" showInputMessage="1" showErrorMessage="1" sqref="${i}2:${i}1048576"><formula1>"${a}"</formula1></dataValidation>`)}),t.length?`<dataValidations count="${t.length}">${t.join(``)}</dataValidations>`:``}async function _(e,t){let n=await c.default.loadAsync(e,{base64:!0}),r=`xl/styles.xml`,i=n.file(r),a=1,o=1;if(i){let e=await i.async(`string`);if(e.includes(`caseHeaderFill`))e.includes(`wrapText`)||e.includes(`</cellXfs>`)&&(e=e.replace(/<cellXfs([^>]*)count="(\d+)"/,(e,t,n)=>`<cellXfs${t}count="${Number(n)+1}"`).replace(`</cellXfs>`,`<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyAlignment="1"><alignment wrapText="1" vertical="top"/></xf></cellXfs>`),n.file(r,e));else{e.includes(`<fills `)||(e=e.replace(`</fonts>`,`</fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills>`)),e=e.replace(/<fonts([^>]*)count="(\d+)"/,(e,t,n)=>`<fonts${t}count="${Number(n)+1}"`).replace(`</fonts>`,`<font><b/><sz val="11"/><color rgb="FFFFFFFF"/><name val="Microsoft YaHei"/></font></fonts>`).replace(/<fills([^>]*)count="(\d+)"/,(e,t,n)=>`<fills${t}count="${Number(n)+1}"`).replace(`</fills>`,`<fill><patternFill patternType="solid"><fgColor rgb="FF000000"/><bgColor indexed="64"/></patternFill></fill><!--caseHeaderFill--></fills>`);let t=Number(e.match(/<fonts[^>]*count="(\d+)"/)?.[1]??2),i=Number(e.match(/<fills[^>]*count="(\d+)"/)?.[1]??3),s=t-1,c=i-1;if(/<cellXfs[^>]*count="1"[^>]*>\s*<xf[^/]*\/>\s*<\/cellXfs>/.test(e))e=e.replace(/<cellXfs([^>]*)count="1"([^>]*)>\s*<xf([^/]*)\/>\s*<\/cellXfs>/,`<cellXfs$1count="3"$2><xf$3/><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyAlignment="1"><alignment wrapText="1" vertical="top"/></xf><xf numFmtId="0" fontId="${s}" fillId="${c}" borderId="0" xfId="0" applyFont="1" applyFill="1" applyAlignment="1"><alignment horizontal="center" vertical="center" wrapText="1"/></xf></cellXfs>`),a=1,o=2;else if(e.includes(`</cellXfs>`)){let t=Number(e.match(/<cellXfs[^>]*count="(\d+)"/)?.[1]??1);a=t,o=t+1,e=e.replace(/<cellXfs([^>]*)count="(\d+)"/,(e,n)=>`<cellXfs${n}count="${t+2}"`).replace(`</cellXfs>`,`<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyAlignment="1"><alignment wrapText="1" vertical="top"/></xf><xf numFmtId="0" fontId="${s}" fillId="${c}" borderId="0" xfId="0" applyFont="1" applyFill="1" applyAlignment="1"><alignment horizontal="center" vertical="center" wrapText="1"/></xf></cellXfs>`)}n.file(r,e)}}let s=Object.keys(n.files).filter(e=>/^xl\/worksheets\/sheet\d+\.xml$/.test(e)),l=g(t);for(let e of s){let t=n.file(e);if(!t)continue;let r=await t.async(`string`);r=r.replace(/<c\b([^>]*)>/g,(e,t)=>{let n=/\br="([A-Z]+)(\d+)"/.exec(t);return(n?Number(n[2]):0)===1?/\bs="\d+"/.test(t)?`<c${t.replace(/\bs="\d+"/,`s="${o}"`)}>`:`<c s="${o}"${t.startsWith(` `)?t:` ${t}`}>`:!/\bt="str"/.test(t)||/\bs="\d+"/.test(t)?e:`<c s="${a}"${t.startsWith(` `)?t:` ${t}`}>`}),r=r.replace(/<row r="(\d+)"([^>]*)>/g,(e,t,n)=>Number(t)===1?/\bht=/.test(n)?`<row r="${t}"${n}>`:`<row r="${t}" ht="22" customHeight="1"${n}>`:/\bht=/.test(n)?`<row r="${t}"${n}>`:`<row r="${t}" ht="60" customHeight="1"${n}>`),l&&!r.includes(`<dataValidations`)&&r.includes(`</worksheet>`)&&(r=r.replace(`</worksheet>`,`${l}</worksheet>`)),n.file(e,r)}return n.generateAsync({type:`base64`,compression:`DEFLATE`})}function v(e){return/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function y(e){return e.replace(/\|/g,`\\|`).replace(/\n+/g,`<br>`)}function b(e,t,n){let r=n.length?n:[...o],i=[`# ${t}`,``,`| ${r.join(` | `)} |`,`|${r.map(()=>`---`).join(`|`)}|`];for(let t of e)i.push(`| ${r.map(e=>y(t[e]??``)).join(` | `)} |`);return i.join(`
3
- `)+`
4
- `}function x(e,t){let n=t.length?t:[...o];return``+[n.join(`,`),...e.map(e=>n.map(t=>v(e[t]??``)).join(`,`))].join(`
5
- `)}async function S(e,n,s=`测试用例`){let c=n.length?n:[...o],l=e.map(e=>{let t={};for(let n of c){let i=e[n]??``;n===`用例状态`&&!String(i).trim()&&(i=`待验证`),n===`实际结果`&&(i=``),t[n]=r(n)&&n!==`实际结果`?a(i):i}return t}),u=t.json_to_sheet(l,{header:[...c]}),d=u[`!ref`]?t.decode_range(u[`!ref`]):null;if(d)for(let e=d.s.r;e<=d.e.r;e++)for(let n=d.s.c;n<=d.e.c;n++){let i=u[t.encode_cell({r:e,c:n})];if(!i||typeof i.v!=`string`||e===0)continue;let o=String(u[t.encode_cell({r:0,c:n})]?.v??``);r(o)&&o!==`实际结果`&&(i.v=a(i.v),i.w!=null&&(i.w=i.v))}u[`!cols`]=c.map(e=>({wch:e===`实际结果`||e===`优先级`||e===`用例状态`?12:r(e)?48:Math.min(28,Math.max(12,e.length+4))}));let f=t.book_new();t.book_append_sheet(f,u,s.slice(0,31));let p=i(f,{bookType:`xlsx`,type:`base64`});try{return await _(p,c)}catch{return p}}export{x as a,u as i,d as n,b as o,f as r,S as s,p as t};
@@ -1 +0,0 @@
1
- import{i as e}from"./app-config.CF1xVPmo.js";import{i as t}from"./plugins.CVM1IaoC.js";var n=`/`,r=n.endsWith(`/`)?n:`${n}/`;(async()=>{try{await e()}catch{}let n=t(`uiAuto`)?`test-automation/`:`workbench/`;window.location.replace(`${r}${n}`)})();
@@ -1,4 +0,0 @@
1
- var e=`/__tb_pm`,t=[`planning`,`in_progress`,`archived`],n=[`planning`,`in_progress`,`done`],r=[`urgent`,`high`,`medium`,`low`],i=[`pending`,`todo`,`in_progress`,`testing`,`done`,`cancelled`],a=[`critical`,`major`,`minor`,`trivial`],o=[`pending`,`todo`,`fixed`,`verifying`,`passed`,`cancelled`],s={planning:`规划中`,in_progress:`进行中`,archived:`已归档`},c={planning:`规划中`,in_progress:`进行中`,done:`已完成`},l={urgent:`紧急`,high:`高`,medium:`中`,low:`低`},u={pending:`待评估`,todo:`待开发`,in_progress:`开发中`,testing:`测试中`,done:`已完成`,cancelled:`已取消`},d={critical:`致命`,major:`严重`,minor:`一般`,trivial:`轻微`},f={pending:`待确认`,todo:`待修复`,fixed:`修复完成`,verifying:`待验证`,passed:`验证通过`,cancelled:`已取消`},p={in_progress:`fixed`,closed:`passed`};function m(e){if(typeof e!=`string`)return``;let t=e.trim();return o.includes(t)?t:p[t]??``}function h(e){return e===`passed`||e===`cancelled`}var g=/^\d{4}-\d{2}-\d{2}$/;function _(e,t=2e3){return typeof e==`string`?e.trim().slice(0,t):``}function v(e){let t=_(e,10);return g.test(t)?t:``}function y(e,t,n){let r=_(e,40);return t.includes(r)?r:n}function b(e){if(!Array.isArray(e))return[];let t=[];for(let n of e.slice(0,50)){if(!n||typeof n!=`object`)continue;let e=_(n.text,500);e&&t.push({text:e,done:n.done===!0})}return t}function x(e){if(!e||typeof e!=`object`)return null;let n=e,r=_(n.name,200);if(!r)return null;let i=new Date().toISOString();return{id:_(n.id,64)||`pj_${Math.random().toString(16).slice(2,10)}`,name:r,description:_(n.description),status:y(n.status,t,`planning`),createdAt:_(n.createdAt,40)||i,updatedAt:_(n.updatedAt,40)||i}}function S(e){if(!e||typeof e!=`object`)return null;let t=e,r=_(t.name,200);if(!r)return null;let i=new Date().toISOString();return{id:_(t.id,64)||`it_${Math.random().toString(16).slice(2,10)}`,projectId:_(t.projectId,64),name:r,startDate:v(t.startDate),endDate:v(t.endDate),status:y(t.status,n,`planning`),remark:_(t.remark),createdAt:_(t.createdAt,40)||i,updatedAt:_(t.updatedAt,40)||i}}function C(e){if(!e||typeof e!=`object`)return null;let t=e,n=_(t.title,2e3);if(!n)return null;let a=new Date().toISOString();return{id:_(t.id,64)||`rq_${Math.random().toString(16).slice(2,10)}`,autoId:_(t.autoId,20),projectId:_(t.projectId,64),iterationId:_(t.iterationId,64),title:n,priority:y(t.priority,r,`medium`),status:y(t.status,i,`pending`),description:_(t.description),acceptanceCriteria:b(t.acceptanceCriteria),githubIssue:_(t.githubIssue,50),attachment:_(t.attachment),createdAt:_(t.createdAt,40)||a,updatedAt:_(t.updatedAt,40)||a}}function w(e){if(!e||typeof e!=`object`)return null;let t=e,n=_(t.title,200);if(!n)return null;let r=new Date().toISOString();return{id:_(t.id,64)||`bg_${Math.random().toString(16).slice(2,10)}`,autoId:_(t.autoId,20),projectId:_(t.projectId,64),iterationId:_(t.iterationId,64),requirementId:_(t.requirementId,64),title:n,severity:y(t.severity,a,`minor`),status:m(t.status)||`pending`,reproduceSteps:_(t.reproduceSteps),expectedResult:_(t.expectedResult),actualResult:_(t.actualResult),environment:_(t.environment,500),githubIssue:_(t.githubIssue,50),attachment:_(t.attachment),remark:_(t.remark),createdAt:_(t.createdAt,40)||r,updatedAt:_(t.updatedAt,40)||r}}function T(e,t){return Array.isArray(e)?e.map(t).filter(e=>!!e):[]}function E(){return{projects:[],iterations:[],requirements:[],bugs:[]}}function D(e){if(!e||typeof e!=`object`)return E();let t=e;return{projects:T(t.projects,x),iterations:T(t.iterations,S),requirements:T(t.requirements,C),bugs:T(t.bugs,w)}}async function O(t,n){let r=await fetch(e,{method:t,headers:n===void 0?void 0:{"Content-Type":`application/json`},body:n===void 0?void 0:JSON.stringify(n)}),i=await r.json().catch(()=>({}));if(!r.ok)throw Error(i.error||`HTTP ${r.status}`);return i}async function k(){try{return(await fetch(`${e}?health=1`,{signal:AbortSignal.timeout(1500)})).ok}catch{return!1}}async function A(){return D(await O(`GET`))}async function j(){await A()}function M(e,t){return e===`projects`?x(t):e===`iterations`?S(t):e===`requirements`?C(t):w(t)}async function N(e,t,n){let r=await O(`POST`,{entity:e,items:t,...n});return(Array.isArray(r.items)?r.items:[]).map(t=>M(e,t)).filter(e=>!!e)}async function P(e,t,n){let r=M(e,(await O(`PUT`,{entity:e,id:t,...n})).item);if(!r)throw Error(`更新记录失败`);return r}async function F(e,t){let n=await O(`DELETE`,{entity:e,ids:t});return{removed:Number(n.removed??0),cascaded:Number(n.cascaded??0)}}function I(e){let[t,n,r]=e.split(`-`).map(Number);return Date.UTC(t,(n??1)-1,r??1)}function L(e,t){return!g.test(e)||!g.test(t)?null:Math.round((I(t)-I(e))/864e5)}function R(e=new Date){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function z(e,t=R()){let n=L(e.startDate,e.endDate);if(n===null)return 0;let r=n+1,i=L(e.startDate,t);return i===null?0:Math.min(100,Math.max(0,Math.round((i+1)/r*100)))}function B(e,t=R()){if(e.status===`done`)return null;let n=L(e.endDate,t);return n===null?null:n>0?n:null}function ee(e){let t={};for(let n of e.projects)t[n.id]={iterations:0,requirements:0,requirementsDone:0,bugs:0,bugsClosed:0,requirementPercent:0,bugClosedPercent:100};for(let n of e.iterations){let e=t[n.projectId];e&&(e.iterations+=1)}for(let n of e.requirements){let e=t[n.projectId];e&&(e.requirements+=1,n.status===`done`&&(e.requirementsDone+=1))}for(let n of e.bugs){let e=t[n.projectId];e&&(e.bugs+=1,h(n.status)&&(e.bugsClosed+=1))}for(let e of Object.values(t))e.requirementPercent=e.requirements?Math.round(e.requirementsDone/e.requirements*100):0,e.bugClosedPercent=e.bugs?Math.round(e.bugsClosed/e.bugs*100):100;return t}function V(e,t={}){let n=t.status??`all`,r=(t.keyword??``).trim().toLowerCase();return e.filter(e=>!(n!==`all`&&e.status!==n||r&&!`${e.name} ${e.description}`.toLowerCase().includes(r)))}function H(e,t={}){let n=t.projectId??`all`,r=t.status??`all`,i=(t.keyword??``).trim().toLowerCase();return e.filter(e=>!(n!==`all`&&e.projectId!==n||r!==`all`&&e.status!==r||i&&!`${e.name} ${e.remark}`.toLowerCase().includes(i)))}function U(e,t={}){let n=t.projectId??`all`,r=t.iterationId??`all`,i=t.status??`all`,a=t.priority??`all`,o=(t.keyword??``).trim().toLowerCase();return e.filter(e=>!(n!==`all`&&e.projectId!==n||r!==`all`&&e.iterationId!==r||i!==`all`&&e.status!==i||a!==`all`&&e.priority!==a||o&&!`${e.autoId} ${e.title} ${e.description}`.toLowerCase().includes(o)))}function W(e){return[...e].sort((e,t)=>{let n=e.startDate||``,r=t.startDate||``;if(n!==r)return r.localeCompare(n);let i=Date.parse(e.createdAt)||0,a=Date.parse(t.createdAt)||0;return i===a?e.name.localeCompare(t.name,`zh-Hans-CN`,{numeric:!0}):a-i})}function G(e){return[...e].sort((e,t)=>{let n=Date.parse(e.createdAt)||0,r=Date.parse(t.createdAt)||0;return n===r?t.autoId.localeCompare(e.autoId,`zh-Hans-CN`,{numeric:!0}):r-n})}function K(e,t={}){let n=t.projectId??`all`,r=t.iterationId??`all`,i=t.status??`all`,a=t.severity??`all`,o=(t.keyword??``).trim().toLowerCase();return e.filter(e=>!(n!==`all`&&e.projectId!==n||r!==`all`&&e.iterationId!==r||i!==`all`&&e.status!==i||a!==`all`&&e.severity!==a||o&&!`${e.autoId} ${e.title} ${e.reproduceSteps}`.toLowerCase().includes(o)))}function q(e,t){let n=t.trim();if(!n)return``;let r=e.find(e=>e.name===n);if(r)return r.id;let i=n.toLowerCase();return e.find(e=>e.name.toLowerCase()===i)?.id??``}function J(e,t){let n=t.trim();if(!n)return``;let r=n.toLowerCase();return e.find(e=>e.title===n)?.id??e.find(e=>e.title.toLowerCase()===r)?.id??e.find(e=>e.autoId.toLowerCase()===r)?.id??``}function Y(e){let t=e.split(`
2
- `).map(e=>e.trim()).find(Boolean);return t?Array.from(t).slice(0,60).join(``):``}function X(e){return e.split(`
3
- `).map(e=>e.trim()).filter(Boolean).map(e=>({url:e,name:$(e)}))}function Z(e){return e.map(e=>e.url).join(`
4
- `)}function Q(e){try{let t=new URL(e,`http://localhost`).searchParams.get(`p`)??``;return/\.(png|jpe?g|gif|webp|bmp|svg)$/i.test(decodeURIComponent(t))}catch{return!1}}function $(e){try{let t=new URL(e,`http://localhost`),n=t.searchParams.get(`p`),r=n?decodeURIComponent(n):t.pathname;return(r.split(`/`).filter(Boolean).pop()??r).replace(/^\d{10,}-[a-z0-9]+-/,``)}catch{return e}}function te(e){let t=new Uint8Array(e),n=32768,r=``;for(let e=0;e<t.length;e+=n)r+=String.fromCharCode(...t.subarray(e,e+n));return btoa(r)}async function ne(e){if(!e.length)return[];let t=await O(`POST`,{upload:await Promise.all(e.map(async e=>({name:e.name||`attachment`,type:e.type||`application/octet-stream`,data:te(await e.arrayBuffer())})))});return(Array.isArray(t.files)?t.files:[]).map(e=>{let t=e,n=typeof t.url==`string`?t.url:``;return n?{url:n,name:typeof t.name==`string`&&t.name?t.name:$(n)}:null}).filter(e=>!!e)}async function re(e,t=``){let n=e.filter(Boolean);if(n.length)try{await O(`POST`,t?{cleanup:n,bugId:t}:{cleanup:n})}catch{}}export{X as A,U as C,B as D,Q as E,R as F,P as I,ne as L,G as M,W as N,z as O,j as P,V as S,J as T,E as _,n as a,K as b,s as c,i as d,u as f,F as g,N as h,f as i,ee as j,Z as k,r as l,re as m,d as n,c as o,Y as p,o as r,t as s,a as t,l as u,k as v,q as w,H as x,A as y};
@@ -1,9 +0,0 @@
1
- var e=`/__tb_reqanalysis`,t=`需求分析提示词.md`,n=`需求分析`,r={draft:{label:`待拆解`,tone:`gray`},decomposed:{label:`已拆解`,tone:`blue`},checked:{label:`已审查`,tone:`amber`},accepted:{label:`已验收`,tone:`green`}},i={P0:`red`,P1:`amber`,P2:`gray`},a={"uncovered-outline":`条目未覆盖`,"missing-field":`字段缺失`,"missing-scenario":`场景遗漏`,"missing-dimension":`维度缺失`,"untestable-acceptance":`验收不可测`,conflict:`与原文冲突`,"over-split":`过度拆分`,other:`其它`},o={high:`高`,medium:`中`,low:`低`},s={high:`red`,medium:`amber`,low:`gray`},c=[{key:`permission`,label:`权限与角色`,keywords:[`权限`,`角色`,`授权`,`越权`,`未登录`,`登录`,`管理员`,`普通用户`],hint:`补充不同角色 / 未登录 / 越权访问时这条流程的行为。`},{key:`boundary`,label:`边界值`,keywords:[`边界`,`上限`,`下限`,`最大`,`最小`,`长度`,`超长`,`字数`,`为空`,`空值`],hint:`补充字段长度、数量上限、刚好等于阈值时的表现。`},{key:`concurrency`,label:`并发与幂等`,keywords:[`并发`,`重复`,`幂等`,`同时`,`加锁`,`冲突`,`重复提交`],hint:`补充重复提交、多人同时操作同一数据时的结果。`},{key:`empty`,label:`空数据`,keywords:[`空数据`,`无数据`,`没有数据`,`空列表`,`暂无`,`空态`],hint:`补充列表为空、首次使用、数据被清空时的空态。`},{key:`failure`,label:`超时与失败`,keywords:[`超时`,`失败`,`异常`,`错误`,`重试`,`断网`,`不可用`,`降级`,`回滚`],hint:`补充依赖超时、接口失败、网络中断时的提示与回滚。`},{key:`i18n`,label:`国际化与时区`,keywords:[`国际化`,`时区`,`多语言`,`语言`,`翻译`,`utc`,`夏令时`],hint:`补充跨时区时间展示、多语言文案与本地化格式。`}],l=/创建|新增|新建|保存|提交|删除|编辑|修改|更新|上传|导入|导出|发布|审批|撤回|绑定|解绑|发送|支付|下单|配置|启停|启用|停用/;async function u(t,n){let r=await fetch(`${e}${t}`,{...n,headers:n?.body===void 0?void 0:{"Content-Type":`application/json`,...n?.headers}}),i=await r.json().catch(()=>({}));if(!r.ok||i.ok===!1)throw Error(i.error||`HTTP ${r.status}`);return i}async function d(){try{return(await fetch(`${e}?health=1`,{signal:AbortSignal.timeout(1500)})).ok}catch{return!1}}async function f(){return(await u(`/list`)).docs??[]}async function p(e){return(await u(`/create`,{method:`POST`,body:JSON.stringify(e)})).doc}async function m(e,t){return(await u(`/`,{method:`PUT`,body:JSON.stringify({id:e,...t})})).doc}async function h(e){await u(`/delete`,{method:`POST`,body:JSON.stringify({id:e})})}async function g(){try{let e=await u(`/prompt`);return{file:e.file||`需求分析提示词.md`,exists:e.exists===!0,decompose:e.decompose??``,audit:e.audit??``,fix:e.fix??``}}catch(e){return{file:t,exists:!1,decompose:``,audit:``,fix:``,error:e instanceof Error?e.message:String(e)}}}async function _(e){return await u(`/prompt/sync`,{method:`POST`,body:JSON.stringify({enabled:e})})}async function v(e){return(await x(e)).content}async function y(e,t=2e4){try{let n=(await v(e)).trim();return{text:n.slice(0,t),total:n.length,truncated:n.length>t}}catch{return{text:``,total:0,truncated:!1}}}async function b(){return(await u(`/sources`)).files??[]}async function x(e){return u(`/source?path=${encodeURIComponent(e)}`)}var S=/[\s\p{P}\p{S}]+/gu;function C(e){return String(e??``).toLowerCase().replace(S,``)}function w(e){return Array.from(new Set(e.map(e=>String(e??``).trim()).filter(Boolean)))}function T(e,t=500){return typeof e==`string`?e.trim().slice(0,t):``}function E(e,t=30,n=500){return Array.isArray(e)?e.map(e=>T(e,n)).filter(Boolean).slice(0,t):[]}function D(e){let t=2166136261,n=String(e??``);for(let e=0;e<n.length;e++)t^=n.charCodeAt(e),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,`0`)}function O(e){return D(String(e??``))}function k(e,t=80){return String(e??``).replace(/\s+/g,` `).trim().slice(0,t)}function A(e){let t=String(e.sourceTitle||e.sourcePath||``).trim();if(t){let e=t.split(/[/\\]/).pop()?.trim();if(e)return e}return String(e.title||``).trim()||`未命名文档`}function j(e){let t=String(e??``).replace(/\r\n/g,`
2
- `).trim();if(!t)return[];if(t.split(`
3
- `).find(e=>/大模块/.test(e)&&/小模块/.test(e))){let e=[],n=new Set;for(let r of t.split(`
4
- `)){if(/^大模块/.test(r))continue;let t=r.match(/^"?([^,"\n]{1,40})"?,"?([^,"\n]{1,40})"?,("?[^,\n]*)/);if(!t)continue;let i=t[1].trim(),a=t[2].trim();if(!a||a===`小模块`||i===`大模块`||/[。;;]/.test(a)||a.length>30||n.has(a))continue;n.add(a);let o=k((t[3]||``).replace(/^"/,``).match(/【([^】\n]{1,40})】/)?.[1]||a);o&&e.push(o)}if(e.length)return e}let n=[],r=new Set;for(let e of t.matchAll(/【([^】\n]{1,40})】/g)){let t=k(e[1]??``);!t||t.length>24||r.has(t)||(r.add(t),n.push(t))}return n}function M(e,t,n){return`g_${D(`${e}|${t}|${n}`)}`}function N(e){let t=e&&typeof e==`object`?e:{},n=T(t.priority,4);return{id:T(t.id,20),title:T(t.title,200),role:T(t.role,120),goal:T(t.goal,500),value:T(t.value,500),sourceRefs:E(t.sourceRefs,20,40),priority:n===`P0`||n===`P1`||n===`P2`?n:`P1`,preconditions:E(t.preconditions),mainFlow:(Array.isArray(t.mainFlow)?t.mainFlow:[]).map(e=>{let t=e&&typeof e==`object`?e:{};return{actor:T(t.actor,80),action:T(t.action,500),result:T(t.result,500)}}).filter(e=>e.action).slice(0,40),altFlows:(Array.isArray(t.altFlows)?t.altFlows:[]).map(e=>{let t=e&&typeof e==`object`?e:{};return{name:T(t.name,120)||`替代流程`,trigger:T(t.trigger,500),steps:E(t.steps,20)}}).slice(0,20),exceptions:(Array.isArray(t.exceptions)?t.exceptions:[]).map(e=>{let t=e&&typeof e==`object`?e:{};return{scenario:T(t.scenario,500),expected:T(t.expected,500)}}).filter(e=>e.scenario).slice(0,30),postconditions:E(t.postconditions),acceptance:(Array.isArray(t.acceptance)?t.acceptance:[]).map(e=>{let t=e&&typeof e==`object`?e:{};return{given:T(t.given,500),when:T(t.when,500),then:T(t.then,500)}}).filter(e=>e.given||e.when||e.then).slice(0,30),dimensions:E(t.dimensions,12,40)}}function P(e){return{...e,sourceRefs:[...e.sourceRefs],preconditions:[...e.preconditions],mainFlow:e.mainFlow.map(e=>({...e})),altFlows:e.altFlows.map(e=>({...e,steps:[...e.steps]})),exceptions:e.exceptions.map(e=>({...e})),postconditions:[...e.postconditions],acceptance:e.acceptance.map(e=>({...e})),dimensions:[...e.dimensions]}}function F(e){let t=e.mainFlow?.[0];return`${C(e.title)}|${t?C(`${t.action}${t.result??``}`):``}`}function I(e,t){let n=e.map(P),r=new Map(n.filter(e=>e.id).map(e=>[e.id,e])),i=new Map(n.map(e=>[F(e),e]));for(let e of t){let t=N(e);if(!t.title)continue;let a=t.id&&r.get(t.id)||i.get(F(t));if(a)!a.role&&t.role&&(a.role=t.role),!a.goal&&t.goal&&(a.goal=t.goal),!a.value&&t.value&&(a.value=t.value),a.sourceRefs=w([...a.sourceRefs,...t.sourceRefs]),a.dimensions=w([...a.dimensions,...t.dimensions]),a.preconditions.length||(a.preconditions=[...t.preconditions]),a.mainFlow.length||(a.mainFlow=t.mainFlow.map(e=>({...e}))),a.altFlows.length||(a.altFlows=t.altFlows.map(e=>({...e}))),a.exceptions.length||(a.exceptions=t.exceptions.map(e=>({...e}))),a.postconditions.length||(a.postconditions=[...t.postconditions]),a.acceptance.length||(a.acceptance=t.acceptance.map(e=>({...e}))),t.priority===`P0`&&a.priority!==`P0`?a.priority=`P0`:t.priority===`P1`&&a.priority===`P2`&&(a.priority=`P1`);else{let e={...t,id:``};n.push(e),i.set(F(e),e)}}return n}function L(e){return[e.title,e.role,e.goal,e.value,...e.dimensions,...e.preconditions,...e.postconditions,...e.mainFlow.map(e=>`${e.actor??``} ${e.action} ${e.result??``}`),...e.altFlows.map(e=>`${e.name} ${e.trigger} ${e.steps.join(` `)}`),...e.exceptions.map(e=>`${e.scenario} ${e.expected}`),...e.acceptance.map(e=>`${e.given} ${e.when} ${e.then}`)].join(` `)}function R(e){return e.mainFlow.some(e=>l.test(e.action))}function z(e,t,n,r,i,a){return{id:M(e,t,n),storyId:t,type:e,severity:a,title:n,detail:r,suggestion:i,origin:`rule`,selected:!1}}var B=new Set([`缺少角色`,`缺少目标`,`缺少前置条件`,`缺少主流程`,`没有异常场景`,`写操作缺少异常分支`,`缺少验收标准`,`验收标准缺 then`,`没有关联需求条目`,`只写了主流程`]);function V(e){let t=e.outline??[],n=e.stories??[],r=[],i=new Set(n.flatMap(e=>e.sourceRefs));for(let e of t)i.has(e.id)||r.push(z(`uncovered-outline`,``,`需求条目未覆盖:${e.title}`,`条目 ${e.id}「${e.title}」没有任何用户故事引用。`,`补一条覆盖该条目的用户故事,或在已有故事的 sourceRefs 里加上 ${e.id}。`,`high`));for(let e of n){let t=`${e.id} ${e.title}`;e.role||r.push(z(`missing-field`,e.id,`缺少角色`,`${t} 没有写清谁在用这个功能。`,`补一个来自原文的角色;原文没写就标注「推断」。`,`medium`)),e.goal||r.push(z(`missing-field`,e.id,`缺少目标`,`${t} 没有写用户要达成什么。`,`补一句用户目标(想要什么结果)。`,`medium`)),e.preconditions.length||r.push(z(`missing-field`,e.id,`缺少前置条件`,`${t} 没有前置条件。`,`补进入这条流程前必须成立的状态。`,`low`)),e.mainFlow.length||r.push(z(`missing-field`,e.id,`缺少主流程`,`${t} 没有主流程步骤。`,`按「动作 + 结果」补主流程。`,`high`)),e.sourceRefs.length||r.push(z(`missing-field`,e.id,`没有关联需求条目`,`${t} 的 sourceRefs 为空,覆盖率无法统计。`,`把这条故事挂到对应的需求条目 id 上。`,`low`)),e.exceptions.length?R(e)&&e.exceptions.length<2&&r.push(z(`missing-scenario`,e.id,`写操作缺少异常分支`,`${t} 包含写操作,但只写了 ${e.exceptions.length} 条异常。`,`补重复提交 / 并发修改 / 保存失败时的表现与回滚。`,`medium`)):r.push(z(`missing-scenario`,e.id,`没有异常场景`,`${t} 只写了顺利路径,没有异常分支。`,`至少补 3 条:输入非法、权限不足、依赖失败 / 超时。`,`high`)),!e.altFlows.length&&R(e)&&r.push(z(`missing-scenario`,e.id,`只写了主流程`,`${t} 没有替代流程:分支条件、可跳过步骤、不同入口都没覆盖。`,`按触发条件补至少一条替代路径。`,`low`)),e.acceptance.length?e.acceptance.some(e=>!e.then)&&r.push(z(`untestable-acceptance`,e.id,`验收标准缺 then`,`${t} 有 ${e.acceptance.filter(e=>!e.then).length} 条验收没有写 then。`,`补上「应该看到什么 / 查到什么」,不要停在操作步骤。`,`high`)):r.push(z(`untestable-acceptance`,e.id,`缺少验收标准`,`${t} 没有 Given / When / Then。`,`每条验收写成 Given / When / Then,then 必须可判定。`,`high`))}let a=c.map(e=>{let t=n.filter(t=>{let n=L(t).toLowerCase();return e.keywords.some(e=>n.includes(e.toLowerCase()))}).map(e=>e.id);return{key:e.key,label:e.label,covered:t.length>0,stories:t}});for(let e of a){if(e.covered)continue;let t=c.find(t=>t.key===e.key)?.hint??``;r.push(z(`missing-dimension`,``,`维度缺失:${e.label}`,`所有用户故事都没有覆盖「${e.label}」相关场景。`,t,`medium`))}let o=t.filter(e=>i.has(e.id)).length,s={total:t.length,covered:o,rate:t.length?o/t.length:0};return{at:new Date().toISOString(),summary:`规则检查:${n.length} 个故事、${t.length} 条需求条目,覆盖率 ${t.length?Math.round(s.rate*100):0}%,发现 ${r.length} 个问题。`,coverage:s,dimensions:a,gaps:r}}function H(e,t){let n=e.map(e=>({...e})),r=new Map(n.map(e=>[`${e.storyId}|${e.type}`,e])),i=new Set(n.map(e=>e.id));for(let e of t){if(i.has(e.id))continue;let t=`${e.storyId}|${e.type}`,a=r.get(t);a?B.has(a.title)?(a.title=e.title,a.detail=[a.detail,e.detail].filter(Boolean).join(` / `),a.suggestion=e.suggestion||a.suggestion,a.severity=e.severity):C(a.title)!==C(e.title)&&(n.push({...e}),i.add(e.id)):(n.push({...e}),r.set(t,e),i.add(e.id))}return n}function U(e,t){let n=new Set(e.filter(e=>e.selected).map(e=>e.id));return n.size?t.map(e=>n.has(e.id)?{...e,selected:!0}:e):t}function W(e,t){let n=[],r=``;for(let i of e.split(/\n{2,}/)){let e=r?`${r}\n\n${i}`:i;if(e.length<=t)r=e;else if(r&&n.push(r),i.length<=t)r=i;else{for(let e=0;e<i.length;e+=t)n.push(i.slice(e,e+t));r=``}}return r&&n.push(r),n}function G(e,t=12e3){let n=String(e??``).replace(/\r\n/g,`
5
- `).trim();if(!n)return[];let r=Math.max(2e3,Math.floor(t));if(n.length<=r)return[{index:0,title:``,text:n}];let i=[],a=``,o=[],s=()=>{let e=o.join(`
6
- `).trim();e&&i.push({title:a,text:e}),o=[]};for(let e of n.split(`
7
- `)){let t=/^#{2,6}\s+(.+?)\s*$/.exec(e);t&&(s(),a=t[1]),o.push(e)}if(s(),!i.length)return[{index:0,title:``,text:n}];let c=[],l=``,u=``,d=()=>{let e=l.trim();if(e){for(let t of e.length>r?W(e,r):[e])c.push({index:c.length,title:u,text:t});l=``}};for(let e of i){let t=l?`${l}\n\n${e.text}`:e.text;t.length<=r?(l||(u=e.title),l=t):(d(),u=e.title,l=e.text,l.length>r&&d())}return d(),c.length?c:[{index:0,title:``,text:n}]}function K(e,t){return t?`- **${e}**:${t}`:``}function q(e){return e.filter(Boolean).map(e=>`- ${e}`)}function J(e){let t=[];t.push(`### ${e.id} ${e.title}`),t.push(``);let n=[K(`角色`,e.role),K(`目标`,e.goal),K(`价值`,e.value),K(`优先级`,e.priority),K(`来源条目`,e.sourceRefs.join(`、`))].filter(Boolean);if(t.push(...n),n.length&&t.push(``),e.preconditions.length&&(t.push(`**前置条件**`),t.push(...q(e.preconditions)),t.push(``)),e.mainFlow.length&&(t.push(`**主流程**`),e.mainFlow.forEach((e,n)=>{let r=e.actor?`${e.actor}:`:``;t.push(`${n+1}. ${r}${e.action}${e.result?` → ${e.result}`:``}`)}),t.push(``)),e.altFlows.length){t.push(`**替代流程**`);for(let n of e.altFlows)t.push(`- **${n.name}**${n.trigger?`(触发:${n.trigger})`:``}`),n.steps.forEach((e,n)=>t.push(` ${n+1}. ${e}`));t.push(``)}if(e.exceptions.length){t.push(`**异常场景**`);for(let n of e.exceptions)t.push(`- ${n.scenario}${n.expected?` → ${n.expected}`:``}`);t.push(``)}if(e.postconditions.length&&(t.push(`**后置条件**`),t.push(...q(e.postconditions)),t.push(``)),e.acceptance.length){t.push(`**验收标准**`);for(let n of e.acceptance)t.push(`- Given ${n.given||`(未写)`};When ${n.when||`(未写)`};Then ${n.then||`(未写)`}`);t.push(``)}return e.dimensions.length&&(t.push(`**覆盖维度**:${e.dimensions.join(`、`)}`),t.push(``)),t[t.length-1]!==``&&t.push(``),t}function Y(e,t){let n=new Set((t??[]).filter(Boolean)),i=n.size?e.stories.filter(e=>n.has(e.id)):e.stories,a=[];a.push(`# ${e.title||`需求分析`} · 用户故事`),a.push(``),a.push(`> 来源需求文档:\`${e.sourcePath||`(未指定)`}\` · 状态:${r[e.status].label} · 更新:${e.updatedAt}`),a.push(``),e.outline.length&&(a.push(`## 需求条目`),a.push(``),e.outline.forEach((e,t)=>{a.push(`${t+1}. **${e.id}** ${e.title}`)}),a.push(``)),a.push(`## 用户故事`),a.push(``),i.length||(a.push(`- (暂无)`),a.push(``));for(let e of i)a.push(...J(e));return a.join(`
8
- `)}function X(e){let t=[];t.push(`# ${e.title||`需求分析`}`),t.push(``),t.push(`> 来源:\`${e.sourcePath||`(未指定)`}\` · 状态:${r[e.status].label} · 更新:${e.updatedAt}`),t.push(``),t.push(`## 需求条目`),t.push(``),e.outline.length||t.push(`- (暂无)`),e.outline.forEach((e,n)=>{t.push(`${n+1}. **${e.id}** ${e.title}`),e.quote&&t.push(` > ${e.quote.replace(/\n+/g,` `)}`)}),t.push(``),t.push(`## 用户故事`),t.push(``),e.stories.length||t.push(`- (暂无)`);for(let n of e.stories)t.push(...J(n));if(t.push(`## 审查摘要`),t.push(``),!e.check)t.push(`- 还没有跑过审查。`);else{let n=e.check.coverage.total?Math.round(e.check.coverage.rate*100):0;t.push(`- 覆盖率:${e.check.coverage.covered}/${e.check.coverage.total}(${n}%)`),t.push(`- 维度覆盖:${e.check.dimensions.map(e=>`${e.label}${e.covered?` ✓`:` ✗`}`).join(` · `)||`(无)`}`),e.check.summary&&(t.push(``),t.push(e.check.summary)),t.push(``),t.push(`### 缺口清单`),t.push(``),e.check.gaps.length||t.push(`- 没有发现缺口。`);let r=[...e.check.gaps].sort((e,t)=>{let n={high:0,medium:1,low:2};return n[e.severity]-n[t.severity]});for(let e of r){let n=e.storyId?`${e.storyId} `:``;t.push(`- **[${o[e.severity]}] ${a[e.type]}** · ${n}${e.title}`),e.detail&&t.push(` - 原因:${e.detail}`),e.suggestion&&t.push(` - 建议:${e.suggestion}`)}}return t.push(``),t.join(`
9
- `)}function Z(e){return`${(e.title||e.sourcePath.split(`/`).pop()||`需求分析`).replace(/\.(md|markdown|txt)$/i,``).replace(/[\\/:*?"<>|]/g,` `).trim()||`需求分析`}-用户故事.md`}export{A as C,_ as D,Y as E,X as O,y as S,G as T,b as _,t as a,U as b,V as c,Z as d,j as f,f as g,M as h,n as i,m as k,p as l,g as m,s as n,i as o,d as p,a as r,r as s,o as t,h as u,H as v,O as w,v as x,I as y};