lantern-harness 0.2.2 → 0.2.3

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 (178) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +7 -7
  3. package/builtin/case-backup-contract.mjs +27 -0
  4. package/builtin/case-workflow-contract.mjs +158 -0
  5. package/builtin/session/lh-nav-groups.mjs +33 -1
  6. package/builtin/session/space-layout.mjs +8 -1
  7. package/builtin/session/space-skills.mjs +8 -1
  8. package/cli/mcp-server.mjs +986 -32
  9. package/cli/server.mjs +2 -0
  10. package/dist/500.html +9 -4
  11. package/dist/_astro/Base.BQf1tZMl.css +1 -0
  12. package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.XUV2H6ea.js → Base.astro_astro_type_script_index_0_lang.Dm3O_y-S.js} +1 -1
  13. package/dist/_astro/{BusinessMapBoard.mRxl2G3D.js → BusinessMapBoard.CYxHcku_.js} +1 -1
  14. package/dist/_astro/{CaseExecBoard.Cqkxuf5c.js → CaseExecBoard.CK9aGPmH.js} +1 -1
  15. package/dist/_astro/CaseExecutionBoard.C94pmIMQ.js +5 -0
  16. package/dist/_astro/CaseGenerateApp.D5xlk9At.js +10 -0
  17. package/dist/_astro/CasesLibrary.BHQC955x.js +21 -0
  18. package/dist/_astro/ChatApp.CIt15w_1.js +1 -0
  19. package/dist/_astro/ChatApp.d4a9R3YS.js +262 -0
  20. package/dist/_astro/{DashboardBoard.CAJVE2G4.js → DashboardBoard.qgc1s7pG.js} +1 -1
  21. package/dist/_astro/{DefectSubmitEntry.BzKXJ-zq.js → DefectSubmitEntry.JI85N1-i.js} +1 -1
  22. package/dist/_astro/{DocsFileBrowser.apKMbGVf.js → DocsFileBrowser.z5JZ74cy.js} +1 -1
  23. package/dist/_astro/{DocsPager.DMN9-Tjg.js → DocsPager.Dg765uHW.js} +1 -1
  24. package/dist/_astro/{KnowledgeLibrary.BcoMQeUd.js → KnowledgeLibrary.mkShtVun.js} +1 -1
  25. package/dist/_astro/{LifeKrTasksBoard.DJU0-QI-.js → LifeKrTasksBoard.DpAwQffE.js} +1 -1
  26. package/dist/_astro/{LifeKrTodosBoard.GK7KRAO3.js → LifeKrTodosBoard.BIjPiZ8H.js} +1 -1
  27. package/dist/_astro/{LifeObjectivesBoard.DuKa6Q3k.js → LifeObjectivesBoard.DYwLHPEG.js} +1 -1
  28. package/dist/_astro/{LifePlanTypeSelect.Cm2lUmnH.js → LifePlanTypeSelect.CYaziESp.js} +1 -1
  29. package/dist/_astro/{LifeReviewsBoard.BWOOVMtz.js → LifeReviewsBoard.DIxoWBDA.js} +1 -1
  30. package/dist/_astro/{LifeShared.bY2l01Ha.js → LifeShared.DuFQsMEx.js} +1 -1
  31. package/dist/_astro/{LifeStagesBoard.CIzxPOJB.js → LifeStagesBoard.DtOri9EW.js} +1 -1
  32. package/dist/_astro/{LifeYearCycleSelect.BlsyPmmI.js → LifeYearCycleSelect.ByJ9-PGg.js} +1 -1
  33. package/dist/_astro/{LifeYearPlansBoard.DaA9O08j.js → LifeYearPlansBoard.BQN07wcv.js} +1 -1
  34. package/dist/_astro/NavLibraries.BO4ezcUc.js +1 -0
  35. package/dist/_astro/{PluginsPage.B063QIlQ.js → PluginsPage.B1VeDtLx.js} +2 -2
  36. package/dist/_astro/{PmBugsBoard.Cu-v0Gfd.js → PmBugsBoard.Ddl3kqqt.js} +1 -1
  37. package/dist/_astro/{PmIterationsBoard.CgRzkP-j.js → PmIterationsBoard.BJN7disI.js} +1 -1
  38. package/dist/_astro/{PmProjectDetail.DVCEh0Lm.js → PmProjectDetail.D78gWhqk.js} +1 -1
  39. package/dist/_astro/{PmProjectsBoard.z-bQa98r.js → PmProjectsBoard.Bf8VB3t6.js} +1 -1
  40. package/dist/_astro/PmRequirementsBoard.CDyNHN2a.js +1 -0
  41. package/dist/_astro/{PmRequirementsBoard.CyfBI0u_.js → PmRequirementsBoard.DarfGIrL.js} +1 -1
  42. package/dist/_astro/{PmShared.BQVzwsiz.js → PmShared.TOjBbtV8.js} +1 -1
  43. package/dist/_astro/{ReportsPage.najSzJeT.js → ReportsPage.BXGduuY3.js} +1 -1
  44. package/dist/_astro/{ReqAnalysisBoard.BQb8dHFD.js → ReqAnalysisBoard.WLtIfBg8.js} +1 -1
  45. package/dist/_astro/{RequirementBreakdownLibrary.Cn6OV6xt.js → RequirementBreakdownLibrary.DMoeTeqX.js} +1 -1
  46. package/dist/_astro/{RequirementsLibrary.CqKNFVsP.js → RequirementsLibrary.Iv7zOqWe.js} +1 -1
  47. package/dist/_astro/{SettingsDialog.db3BpFw0.js → SettingsDialog.BvDU9EU6.js} +1 -1
  48. package/dist/_astro/SlideOverDrawer.CvyB-quk.js +1 -0
  49. package/dist/_astro/{SpaceSwitcher.DSUVAPOi.js → SpaceSwitcher.D9bBNQBZ.js} +1 -1
  50. package/dist/_astro/{TableFieldConfig.72AL-8p-.js → TableFieldConfig.DHj25OKN.js} +1 -1
  51. package/dist/_astro/{TasksBoard.CCDhCSR7.js → TasksBoard.CXmGdylV.js} +1 -1
  52. package/dist/_astro/TemplatesLibrary.DsL2q-wp.js +1 -0
  53. package/dist/_astro/{TestReportsLibrary.fWiEyCRx.js → TestReportsLibrary.BBC1TYgP.js} +1 -1
  54. package/dist/_astro/{TestStatsBoard.BSUBsWSu.js → TestStatsBoard.VXjP4hu6.js} +1 -1
  55. package/dist/_astro/{TodosBoard.By5YdlUe.js → TodosBoard.-yKgp06M.js} +1 -1
  56. package/dist/_astro/UiAutoBoard.BD5ZyLHj.js +3 -0
  57. package/dist/_astro/UiAutoEnvPanel.DrHUOlmH.js +10 -0
  58. package/dist/_astro/UiAutoGenerationDialog.gypq1zP9.js +12 -0
  59. package/dist/_astro/UiAutoProjectsPage.Dhzr09E9.js +3 -0
  60. package/dist/_astro/app-config.BSO5r82v.js +1 -0
  61. package/dist/_astro/app-version.CkDFkv4s.js +1 -0
  62. package/dist/_astro/{bash-tools.CS2w8LOb.js → bash-tools.C4DJiRJs.js} +1 -1
  63. package/dist/_astro/case-fields.C03NY3zC.js +148 -0
  64. package/dist/_astro/case-gen-run.C4p8uyU3.js +26 -0
  65. package/dist/_astro/case-prompt.ByLTgz4r.js +2 -0
  66. package/dist/_astro/{case-review.DFWZkoR9.js → case-review.BodP2jKm.js} +1 -1
  67. package/dist/_astro/{case-template.Clb7HrDB.js → case-template.CC2eXegU.js} +2 -2
  68. package/dist/_astro/case-types.BjF1BivA.js +1 -0
  69. package/dist/_astro/case-workflow-contract.BBQ9bbKL.js +1 -0
  70. package/dist/_astro/{defect-workbench.CjTb4FDv.js → defect-workbench.DBmohR-y.js} +1 -1
  71. package/dist/_astro/{hydrate-cache.O4CIma9y.js → hydrate-cache.CMMErx63.js} +1 -1
  72. package/dist/_astro/{i18n.Cp4so7KR.js → i18n.CEWjL5GX.js} +2 -2
  73. package/dist/_astro/{open-docs-in-session.BpcAcBSI.js → open-docs-in-session.BoyV6R2A.js} +1 -1
  74. package/dist/_astro/plugins.ChGmBEkF.js +1 -0
  75. package/dist/_astro/{project-docs.bB9lQ1Ki.js → project-docs.BRgNjXhG.js} +1 -1
  76. package/dist/_astro/{req-analysis.C_gARMrB.js → req-analysis.BLvcktvQ.js} +1 -1
  77. package/dist/_astro/{settings.D02wZj3w.js → settings.BojKNwUC.js} +2 -2
  78. package/dist/_astro/{spaces-client.BAtG6PkW.js → spaces-client.B28rzu8J.js} +1 -1
  79. package/dist/_astro/{story-review.DTN91Vl9.js → story-review.dEBWTeOW.js} +1 -1
  80. package/dist/_astro/{test-points.C7ZgggQT.js → test-points.BuNgdNcU.js} +1 -1
  81. package/dist/_astro/ui-auto.LUcREUMe.js +1 -0
  82. package/dist/_astro/{view-prefs.COAKEQtZ.js → view-prefs.CWc5cQ2q.js} +1 -1
  83. package/dist/business-map/index.html +10 -5
  84. package/dist/case-exec/index.html +10 -5
  85. package/dist/case-execution/index.html +10 -5
  86. package/dist/cases/api/index.html +988 -0
  87. package/dist/cases/automation/index.html +988 -0
  88. package/dist/cases/functional/index.html +988 -0
  89. package/dist/cases/generate/index.html +10 -5
  90. package/dist/cases/index.html +1 -1
  91. package/dist/cases/library/index.html +1 -983
  92. package/dist/cases/other/index.html +988 -0
  93. package/dist/cases/performance/index.html +988 -0
  94. package/dist/dashboard/index.html +10 -5
  95. package/dist/defect-rules/index.html +10 -5
  96. package/dist/defect-submit/index.html +10 -5
  97. package/dist/defect-submit/templates/index.html +10 -5
  98. package/dist/docs/changelog/index.html +88 -58
  99. package/dist/docs/install/index.html +12 -6
  100. package/dist/docs/manual/index.html +42 -31
  101. package/dist/knowledge/index.html +10 -5
  102. package/dist/life/kr-tasks/index.html +10 -5
  103. package/dist/life/kr-todos/index.html +10 -5
  104. package/dist/life/objectives/index.html +10 -5
  105. package/dist/life/reviews/index.html +10 -5
  106. package/dist/life/stages/index.html +10 -5
  107. package/dist/life/year-plans/index.html +10 -5
  108. package/dist/plugins/index.html +10 -5
  109. package/dist/pm/bugs/index.html +10 -5
  110. package/dist/pm/iterations/index.html +10 -5
  111. package/dist/pm/projects/detail/index.html +10 -5
  112. package/dist/pm/projects/index.html +10 -5
  113. package/dist/pm/requirements/index.html +10 -5
  114. package/dist/reports/index.html +10 -5
  115. package/dist/requirement-analysis/index.html +10 -5
  116. package/dist/requirement-breakdowns/index.html +10 -5
  117. package/dist/requirements/index.html +10 -5
  118. package/dist/tasks/index.html +10 -5
  119. package/dist/templates/index.html +10 -5
  120. package/dist/test-automation/index.html +10 -5
  121. package/dist/test-automation/projects/index.html +10 -5
  122. package/dist/test-reports/index.html +10 -5
  123. package/dist/test-stats/index.html +10 -5
  124. package/dist/todos/index.html +10 -5
  125. package/dist/workbench/index.html +10 -5
  126. package/docs/Codex-MCP/351/233/206/346/210/220.md +97 -53
  127. package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +7 -1
  128. package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +1 -1
  129. package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +4 -2
  130. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +43 -36
  131. package/lh-plugins/case-automation/service.mjs +921 -0
  132. package/lh-plugins/case-automation/store.mjs +231 -0
  133. package/lh-plugins/case-automation/tables.mjs +115 -0
  134. package/lh-plugins/case-automation-prompt.mjs +57 -0
  135. package/lh-plugins/case-execution/assets.mjs +180 -0
  136. package/lh-plugins/case-execution/files.mjs +67 -15
  137. package/lh-plugins/case-execution/plans.mjs +318 -0
  138. package/lh-plugins/case-execution/service.mjs +80 -13
  139. package/lh-plugins/case-execution-prompt.mjs +4 -1
  140. package/lh-plugins/lh-case-automation.mjs +169 -0
  141. package/lh-plugins/lh-case-design.mjs +456 -0
  142. package/lh-plugins/lh-case-execution.mjs +53 -1
  143. package/lh-plugins/lh-case-review.mjs +29 -11
  144. package/lh-plugins/lh-project-docs.mjs +24 -0
  145. package/lh-plugins/lh-uiauto.mjs +111 -2
  146. package/lh-plugins/plugin-prompts.mjs +1 -0
  147. package/lh-plugins/uiauto-adapters/playwright.mjs +44 -4
  148. package/lh-plugins/uiauto-adapters/shared.mjs +4 -0
  149. package/lh-plugins/uiauto-explorer/emit-files.mjs +16 -2
  150. package/lh-plugins/uiauto-explorer/ir.mjs +3 -0
  151. package/lh-plugins/uiauto-explorer/merge.mjs +37 -1
  152. package/lh-plugins/uiauto-explorer/navigation-guard.mjs +255 -0
  153. package/lh-plugins/uiauto-explorer/runner.mjs +65 -3
  154. package/lh-plugins/uiauto-explorer/sessions.mjs +29 -1
  155. package/package.json +1 -1
  156. package/skills/case-automation-bridge/SKILL.md +27 -0
  157. package/skills/case-execution/SKILL.md +11 -0
  158. package/skills/lantern-workflow/SKILL.md +39 -1
  159. package/dist/_astro/Base.Du_-4L-4.css +0 -1
  160. package/dist/_astro/CaseExecutionBoard.CjX4CoKd.js +0 -5
  161. package/dist/_astro/CaseGenerateApp.acgnxl79.js +0 -10
  162. package/dist/_astro/CasesLibrary.zmzOQwdn.js +0 -21
  163. package/dist/_astro/ChatApp.Ben9LFra.js +0 -1
  164. package/dist/_astro/ChatApp.DBi6q7Qv.js +0 -262
  165. package/dist/_astro/NavLibraries.DVR5Ua-S.js +0 -1
  166. package/dist/_astro/PmRequirementsBoard.B0W6bsW2.js +0 -1
  167. package/dist/_astro/SlideOverDrawer.BMg2tce6.js +0 -1
  168. package/dist/_astro/TemplatesLibrary.peYzrHZ2.js +0 -1
  169. package/dist/_astro/UiAutoBoard.BGdlp5Sr.js +0 -3
  170. package/dist/_astro/UiAutoEnvPanel.BUASgPLB.js +0 -10
  171. package/dist/_astro/UiAutoGenerationDialog.D1PyCgrD.js +0 -12
  172. package/dist/_astro/UiAutoProjectsPage.B6A9NlVK.js +0 -3
  173. package/dist/_astro/app-config.Dvfzl5_N.js +0 -1
  174. package/dist/_astro/app-version.CNpnKIb9.js +0 -1
  175. package/dist/_astro/case-fields.CmePqYfh.js +0 -148
  176. package/dist/_astro/case-gen-run.Cvvdv_kv.js +0 -26
  177. package/dist/_astro/case-prompt.CZ3vWUju.js +0 -2
  178. package/dist/_astro/plugins.Db9xoFZb.js +0 -1
@@ -27,6 +27,8 @@ const CONFIG_API = `/${API_PREFIX.slice(1)}config`;
27
27
  const BUSINESS_MAP_API = `/${API_PREFIX.slice(1)}business_map`;
28
28
  const REQ_BREAKDOWN_API = `/${API_PREFIX.slice(1)}req_breakdowns`;
29
29
  const CASE_EXECUTION_API = `/${API_PREFIX.slice(1)}case_run`;
30
+ const UI_AUTO_API = `/${API_PREFIX.slice(1)}uiauto`;
31
+ const CASE_AUTOMATION_API = `/${API_PREFIX.slice(1)}case_automation`;
30
32
  const SKILL_PROMPT_ROUTES = {
31
33
  '需求分析提示词.md': `/${API_PREFIX.slice(1)}reqanalysis/prompt`,
32
34
  '原文结构提示词.md': `/${API_PREFIX.slice(1)}reqanalysis/prompt`,
@@ -345,6 +347,28 @@ async function waitForCaseExecution(apiBase, runId, timeoutMs, afterSeq = 0) {
345
347
  };
346
348
  }
347
349
 
350
+ async function waitForCaseAutomationBatch(apiBase, batchId, timeoutMs) {
351
+ const deadline = Date.now() + Math.max(1000, Math.min(Number(timeoutMs) || 25_000, 55_000));
352
+ let latest = null;
353
+ while (Date.now() < deadline) {
354
+ const data = await apiRequest(
355
+ apiBase,
356
+ `${CASE_AUTOMATION_API}/runs/${encodeURIComponent(batchId)}`,
357
+ );
358
+ latest = data.batch;
359
+ if (!['pending', 'running'].includes(latest?.status)) break;
360
+ await new Promise((resolve) => setTimeout(resolve, 1000));
361
+ }
362
+ if (!latest) {
363
+ const data = await apiRequest(
364
+ apiBase,
365
+ `${CASE_AUTOMATION_API}/runs/${encodeURIComponent(batchId)}`,
366
+ );
367
+ latest = data.batch;
368
+ }
369
+ return { ok: true, batch: latest };
370
+ }
371
+
348
372
  async function loadRequirementBreakdownList(apiBase) {
349
373
  const data = await apiRequest(apiBase, `${REQ_BREAKDOWN_API}/list`);
350
374
  if (!Array.isArray(data.entries)) throw new BridgeError('需求拆解库数据不可用', 502);
@@ -595,7 +619,7 @@ export function createLanternMcpServer({ apiBase, version = '1.0.0' }) {
595
619
  { name: 'lantern-harness', version, title: 'Lantern Harness Capabilities' },
596
620
  {
597
621
  instructions:
598
- 'Lantern 提供测试业务规则、需求文档、需求分析、需求拆解库、测试点、用例执行、缺陷规则与提交、业务地图和确定性校验。需求分析可列举和批量删除;需求拆解库通过 lantern_requirement_breakdown_* 管理本地 XMind 文件;用例执行通过 lantern_case_execution_* 对单条用例启动 AI 浏览器执行、等待、停止、确认写回和同步统计;业务地图系统、目录、功能、流程、登录状态和本地资料可通过对应 lantern_business_* 工具管理,AI 目录/流程识别通过 lantern_business_assistant_* 启动和控制;缺陷规则、草稿、提交和回执通过 lantern_defect_* 管理。业务地图写入必须携带 expectedRevision。需要推理时先读取上下文,生成结构化结果后通过 Lantern 保存工具写回。外接 MCP(如腾讯文档)通过 lantern_mcp_tools 发现、lantern_mcp_call 调用,复用当前空间连接和权限。不要用浏览器点击 Lantern 页面。',
622
+ 'Lantern 提供测试业务规则、需求文档、需求分析、需求拆解库、测试点、功能用例生成、UI 自动化项目与脚本生成、自动化批量运行、缺陷规则与提交、业务地图和确定性校验。需求分析可列举和批量删除;需求拆解库通过 lantern_requirement_breakdown_* 管理本地 XMind 文件;功能用例通过 lantern_case_generation_* 校验和保存;UI 自动化项目通过 lantern_uiauto_* 管理,功能用例转换与正式运行通过 lantern_case_automation_* 管理;用例执行通过 lantern_case_execution_* 对单条用例启动 AI 浏览器执行、等待、停止、确认写回和同步统计;业务地图系统、目录、功能、流程、登录状态和本地资料可通过对应 lantern_business_* 工具管理,AI 目录/流程识别通过 lantern_business_assistant_* 启动和控制;缺陷规则、草稿、提交和回执通过 lantern_defect_* 管理。业务地图写入必须携带 expectedRevision。需要推理时先读取上下文,生成结构化结果后通过 Lantern 保存工具写回。外接 MCP(如腾讯文档)通过 lantern_mcp_tools 发现、lantern_mcp_call 调用,复用当前空间连接和权限。不要用浏览器点击 Lantern 页面。',
599
623
  },
600
624
  );
601
625
 
@@ -1353,21 +1377,236 @@ export function createLanternMcpServer({ apiBase, version = '1.0.0' }) {
1353
1377
  ),
1354
1378
  );
1355
1379
 
1380
+ const caseDesignInput = {
1381
+ analysisId: z.string().optional(),
1382
+ sourcePath: z.string().optional(),
1383
+ headers: z.array(z.string()).optional(),
1384
+ skillPath: z.string().optional(),
1385
+ };
1386
+ const caseDesignRows = { ...caseDesignInput, rows: z.array(z.record(z.string(), z.unknown())) };
1356
1387
  server.registerTool(
1357
- 'lantern_case_execution_files',
1388
+ 'lantern_case_generation_context',
1358
1389
  {
1359
- title: '列出可执行用例文件',
1360
- description: '列出用例管理中的用例文件、用例数量、是否具备状态和实际结果列。',
1390
+ title: '读取用例生成上下文',
1391
+ description:
1392
+ '读取需求基线、当前空间用例生成技能、执行就绪表头与输出约定。由 Codex 生成 rows 后校验和保存。',
1393
+ inputSchema: caseDesignInput,
1361
1394
  annotations: { readOnlyHint: true },
1362
1395
  },
1363
- protectedTool(async () => toolResult(await apiRequest(apiBase, `${CASE_EXECUTION_API}/files`))),
1396
+ protectedTool(async (args) =>
1397
+ toolResult(
1398
+ await apiRequest(apiBase, '/__tb_case_design/context', { method: 'POST', body: args }),
1399
+ ),
1400
+ ),
1401
+ );
1402
+ server.registerTool(
1403
+ 'lantern_case_generation_validate',
1404
+ {
1405
+ title: '校验生成用例与需求覆盖',
1406
+ description: '确定性检查字段、真实 RO/US/TP 引用与覆盖;不保存,不使用模型自报覆盖率。',
1407
+ inputSchema: caseDesignRows,
1408
+ annotations: { readOnlyHint: true },
1409
+ },
1410
+ protectedTool(async (args) =>
1411
+ toolResult(
1412
+ await apiRequest(apiBase, '/__tb_case_design/validate', { method: 'POST', body: args }),
1413
+ ),
1414
+ ),
1415
+ );
1416
+ server.registerTool(
1417
+ 'lantern_case_generation_save',
1418
+ {
1419
+ title: '保存生成用例',
1420
+ description:
1421
+ '在用例管理新建实际文件,补齐执行列并登记需求基线和稳定标识;必须传 context 返回的 revision 与 sourceFileHash。',
1422
+ inputSchema: {
1423
+ ...caseDesignRows,
1424
+ expectedRevision: z.string().optional(),
1425
+ expectedSourceFileHash: z.string().optional(),
1426
+ title: z.string(),
1427
+ format: z.enum(['xlsx', 'csv', 'md']).optional(),
1428
+ folder: z
1429
+ .string()
1430
+ .optional()
1431
+ .describe('用例管理内的相对分类目录,例如 功能测试;留空保存在根目录'),
1432
+ },
1433
+ annotations: { destructiveHint: true },
1434
+ },
1435
+ protectedTool(async (args) =>
1436
+ toolResult(
1437
+ await apiRequest(apiBase, '/__tb_case_design/save', { method: 'POST', body: args }),
1438
+ ),
1439
+ ),
1364
1440
  );
1365
1441
 
1366
1442
  server.registerTool(
1367
- 'lantern_case_execution_cases',
1443
+ 'lantern_uiauto_projects',
1368
1444
  {
1369
- title: '读取用例执行明细',
1370
- description: '读取指定用例文件的字段、单条用例和当前执行状态。',
1445
+ title: '列出 UI 自动化项目',
1446
+ description:
1447
+ '列出当前空间已挂载或生成的 UI 自动化项目,附带框架、目录、运行环境与可挂载状态。',
1448
+ inputSchema: {},
1449
+ annotations: { readOnlyHint: true },
1450
+ },
1451
+ protectedTool(async () => toolResult(await apiRequest(apiBase, `${UI_AUTO_API}/projects`))),
1452
+ );
1453
+
1454
+ server.registerTool(
1455
+ 'lantern_uiauto_project_mount',
1456
+ {
1457
+ title: '挂载已有 UI 自动化项目',
1458
+ description:
1459
+ '把 Codex 可访问的现有测试项目目录挂载到 Lantern;目录必须存在且能识别出 Playwright、pytest 或 Selenium。',
1460
+ inputSchema: {
1461
+ dir: z.string().describe('测试项目的绝对目录'),
1462
+ name: z.string().optional(),
1463
+ framework: z.enum(['playwright', 'pytest', 'selenium']).optional(),
1464
+ },
1465
+ annotations: { destructiveHint: true },
1466
+ },
1467
+ protectedTool(async (args) =>
1468
+ toolResult(
1469
+ await apiRequest(apiBase, `${UI_AUTO_API}/projects`, { method: 'POST', body: args }),
1470
+ ),
1471
+ ),
1472
+ );
1473
+
1474
+ server.registerTool(
1475
+ 'lantern_uiauto_project_update',
1476
+ {
1477
+ title: '更新 UI 自动化项目配置',
1478
+ description:
1479
+ '修改项目展示名、探测目录、框架、被测地址、storageState 文件、登录策略和默认环境;不接收账号密码。',
1480
+ inputSchema: {
1481
+ projectId: z.string(),
1482
+ name: z.string().optional(),
1483
+ framework: z.enum(['playwright', 'pytest', 'selenium']).optional(),
1484
+ dir: z.string().optional(),
1485
+ baseURL: z.string().optional(),
1486
+ storageState: z.string().optional().describe('项目内或本机可访问的登录态文件路径'),
1487
+ loginStrategy: z.enum(['ask_each_time', 'ui_orchestrate', 'sso']).optional(),
1488
+ envName: z.string().optional(),
1489
+ promptFile: z.string().optional(),
1490
+ },
1491
+ annotations: { destructiveHint: true },
1492
+ },
1493
+ protectedTool(async ({ projectId, ...values }) =>
1494
+ toolResult(
1495
+ await apiRequest(apiBase, `${UI_AUTO_API}/projects`, {
1496
+ method: 'PATCH',
1497
+ body: { id: projectId, ...values },
1498
+ }),
1499
+ ),
1500
+ ),
1501
+ );
1502
+
1503
+ const scaffoldInput = {
1504
+ parentDir: z.string().describe('新建项目所在父目录的绝对路径'),
1505
+ name: z.string().min(1),
1506
+ stack: z.string().optional().describe('默认 playwright'),
1507
+ baseURL: z.string().optional(),
1508
+ options: z.array(z.string()).optional(),
1509
+ };
1510
+ server.registerTool(
1511
+ 'lantern_uiauto_project_scaffold_preview',
1512
+ {
1513
+ title: '预览 UI 自动化项目骨架',
1514
+ description:
1515
+ '对指定父目录和项目名执行结构检查与文件预览,不创建目录;用于用户确认将要生成的项目。',
1516
+ inputSchema: scaffoldInput,
1517
+ annotations: { readOnlyHint: true },
1518
+ },
1519
+ protectedTool(async (args) => {
1520
+ const check = await apiRequest(apiBase, `${UI_AUTO_API}/scaffold/check`, {
1521
+ method: 'POST',
1522
+ body: args,
1523
+ });
1524
+ const preview = await apiRequest(apiBase, `${UI_AUTO_API}/scaffold/preview`, {
1525
+ method: 'POST',
1526
+ body: args,
1527
+ });
1528
+ return toolResult({ ok: check.ok && preview.ok, check, preview });
1529
+ }),
1530
+ );
1531
+
1532
+ server.registerTool(
1533
+ 'lantern_uiauto_project_scaffold_create',
1534
+ {
1535
+ title: '创建一个 UI 自动化项目',
1536
+ description:
1537
+ '按当前空间骨架在指定父目录创建并挂载 UI 自动化项目;不覆盖已有非空目录,不自动安装依赖。',
1538
+ inputSchema: scaffoldInput,
1539
+ annotations: { destructiveHint: true },
1540
+ },
1541
+ protectedTool(async (args) =>
1542
+ toolResult(
1543
+ await apiRequest(apiBase, `${UI_AUTO_API}/scaffold`, { method: 'POST', body: args }),
1544
+ ),
1545
+ ),
1546
+ );
1547
+
1548
+ server.registerTool(
1549
+ 'lantern_uiauto_project_setup_start',
1550
+ {
1551
+ title: '开始安装 UI 自动化项目环境',
1552
+ description: '启动项目依赖与浏览器运行时安装;同一项目不能重复启动。',
1553
+ inputSchema: { projectId: z.string() },
1554
+ annotations: { destructiveHint: true, openWorldHint: true },
1555
+ },
1556
+ protectedTool(async ({ projectId }) =>
1557
+ toolResult(
1558
+ await apiRequest(apiBase, `${UI_AUTO_API}/project/setup`, {
1559
+ method: 'POST',
1560
+ body: { projectId },
1561
+ }),
1562
+ ),
1563
+ ),
1564
+ );
1565
+
1566
+ server.registerTool(
1567
+ 'lantern_uiauto_project_setup_get',
1568
+ {
1569
+ title: '读取 UI 自动化项目安装进度',
1570
+ description: '读取项目安装日志和当前状态;offset 用于只取新增日志。',
1571
+ inputSchema: {
1572
+ projectId: z.string(),
1573
+ offset: z.number().int().nonnegative().optional(),
1574
+ },
1575
+ annotations: { readOnlyHint: true },
1576
+ },
1577
+ protectedTool(async ({ projectId, offset = 0 }) =>
1578
+ toolResult(
1579
+ await apiRequest(
1580
+ apiBase,
1581
+ `${UI_AUTO_API}/project/setup?projectId=${encodeURIComponent(projectId)}&offset=${offset}`,
1582
+ ),
1583
+ ),
1584
+ ),
1585
+ );
1586
+
1587
+ server.registerTool(
1588
+ 'lantern_uiauto_project_setup_stop',
1589
+ {
1590
+ title: '停止 UI 自动化项目安装',
1591
+ description: '停止当前项目的安装任务并保留已有日志。',
1592
+ inputSchema: { projectId: z.string() },
1593
+ annotations: { destructiveHint: true },
1594
+ },
1595
+ protectedTool(async ({ projectId }) =>
1596
+ toolResult(
1597
+ await apiRequest(apiBase, `${UI_AUTO_API}/project/setup/stop`, {
1598
+ method: 'POST',
1599
+ body: { projectId },
1600
+ }),
1601
+ ),
1602
+ ),
1603
+ );
1604
+
1605
+ server.registerTool(
1606
+ 'lantern_case_automation_cases',
1607
+ {
1608
+ title: '读取待转换的功能用例',
1609
+ description: '读取功能用例文件中的稳定用例 ID、步骤、预期和当前执行状态。',
1371
1610
  inputSchema: { casePath: z.string() },
1372
1611
  annotations: { readOnlyHint: true },
1373
1612
  },
@@ -1375,60 +1614,774 @@ export function createLanternMcpServer({ apiBase, version = '1.0.0' }) {
1375
1614
  toolResult(
1376
1615
  await apiRequest(
1377
1616
  apiBase,
1378
- `${CASE_EXECUTION_API}/cases?path=${encodeURIComponent(casePath)}`,
1617
+ `${CASE_AUTOMATION_API}/cases?path=${encodeURIComponent(casePath)}`,
1379
1618
  ),
1380
1619
  ),
1381
1620
  ),
1382
1621
  );
1383
1622
 
1384
1623
  server.registerTool(
1385
- 'lantern_case_execution_login_start',
1624
+ 'lantern_case_automation_iterations',
1386
1625
  {
1387
- title: '打开用例执行登录页面',
1388
- description: '打开目标系统登录窗口,由用户完成登录;工具不接收账号密码。',
1389
- inputSchema: { url: z.string() },
1626
+ title: '列出 UI 自动化迭代文件',
1627
+ description:
1628
+ '读取指定 UI 项目的 tests/iteration 文件,并按源用例文件名版本自动给出建议迭代。',
1629
+ inputSchema: { projectId: z.string(), casePath: z.string().optional() },
1630
+ annotations: { readOnlyHint: true },
1631
+ },
1632
+ protectedTool(async ({ projectId, casePath = '' }) =>
1633
+ toolResult(
1634
+ await apiRequest(
1635
+ apiBase,
1636
+ `${CASE_AUTOMATION_API}/iterations?projectId=${encodeURIComponent(projectId)}&casePath=${encodeURIComponent(casePath)}`,
1637
+ ),
1638
+ ),
1639
+ ),
1640
+ );
1641
+
1642
+ server.registerTool(
1643
+ 'lantern_case_automation_status',
1644
+ {
1645
+ title: '读取功能用例自动化状态',
1646
+ description: '按用例 ID 返回自动化链接、脚本、运行、报告和过期状态。',
1647
+ inputSchema: { casePath: z.string() },
1648
+ annotations: { readOnlyHint: true },
1649
+ },
1650
+ protectedTool(async ({ casePath }) =>
1651
+ toolResult(
1652
+ await apiRequest(
1653
+ apiBase,
1654
+ `${CASE_AUTOMATION_API}/status?casePath=${encodeURIComponent(casePath)}`,
1655
+ ),
1656
+ ),
1657
+ ),
1658
+ );
1659
+
1660
+ server.registerTool(
1661
+ 'lantern_case_automation_assess',
1662
+ {
1663
+ title: '评估并拆分功能用例为 UI 自动化用例',
1664
+ description:
1665
+ '调用 Lantern 当前模型评估明确选择的功能用例,生成自动化用例和 UI Plan;会保存评估记录,但不会修改正式地图或测试项目。',
1666
+ inputSchema: {
1667
+ casePath: z.string(),
1668
+ caseIds: z.array(z.string()).min(1).max(100),
1669
+ projectId: z.string(),
1670
+ iteration: z.string(),
1671
+ },
1390
1672
  annotations: { destructiveHint: true, openWorldHint: true },
1391
1673
  },
1392
- protectedTool(async ({ url }) =>
1674
+ protectedTool(async (args) =>
1393
1675
  toolResult(
1394
- await apiRequest(apiBase, `${CASE_EXECUTION_API}/auth/start`, {
1676
+ await apiRequest(apiBase, `${CASE_AUTOMATION_API}/assess`, {
1395
1677
  method: 'POST',
1396
- body: { url },
1397
- timeoutMs: 60_000,
1678
+ body: args,
1679
+ timeoutMs: 100_000,
1398
1680
  }),
1399
1681
  ),
1400
1682
  ),
1401
1683
  );
1402
1684
 
1403
1685
  server.registerTool(
1404
- 'lantern_case_execution_login_complete',
1686
+ 'lantern_case_automation_apply',
1405
1687
  {
1406
- title: '保存用例执行登录态',
1407
- description: '用户完成登录后保存当前目标的浏览器 storageState。',
1408
- annotations: { destructiveHint: true, openWorldHint: true },
1688
+ title: '应用自动化评估结果',
1689
+ description:
1690
+ '把用户确认过的评估结果写入自动化用例文件,并创建绑定 automationCaseId、迭代文件和目标脚本的 UI 生成会话。',
1691
+ inputSchema: {
1692
+ assessmentId: z.string(),
1693
+ selectedSourceCaseIds: z.array(z.string()).min(1),
1694
+ },
1695
+ annotations: { destructiveHint: true },
1409
1696
  },
1410
- protectedTool(async () =>
1697
+ protectedTool(async (args) =>
1411
1698
  toolResult(
1412
- await apiRequest(apiBase, `${CASE_EXECUTION_API}/auth/complete`, {
1699
+ await apiRequest(apiBase, `${CASE_AUTOMATION_API}/apply`, {
1413
1700
  method: 'POST',
1414
- body: {},
1415
- timeoutMs: 60_000,
1701
+ body: args,
1416
1702
  }),
1417
1703
  ),
1418
1704
  ),
1419
1705
  );
1420
1706
 
1421
1707
  server.registerTool(
1422
- 'lantern_case_execution_start',
1708
+ 'lantern_case_automation_run',
1423
1709
  {
1424
- title: '启动单条用例 AI 执行',
1710
+ title: '正式运行自动化用例',
1425
1711
  description:
1426
- '按用例文件路径和行号启动单条 AI 浏览器执行。只使用已有登录态路径,不接收账号密码。',
1712
+ '按 automationCaseId 启动已写入 iteration 文件的自动化测试批次;串行运行,返回批次 ID 供轮询。',
1427
1713
  inputSchema: {
1428
- casePath: z.string(),
1429
- rowIndex: z.number().int().nonnegative(),
1430
- url: z.string(),
1431
- storageStatePath: z.string().optional(),
1714
+ automationCaseIds: z.array(z.string()).min(1),
1715
+ env: z.string().optional(),
1716
+ },
1717
+ annotations: { destructiveHint: true, openWorldHint: true },
1718
+ },
1719
+ protectedTool(async (args) =>
1720
+ toolResult(
1721
+ await apiRequest(apiBase, `${CASE_AUTOMATION_API}/runs`, {
1722
+ method: 'POST',
1723
+ body: args,
1724
+ }),
1725
+ ),
1726
+ ),
1727
+ );
1728
+
1729
+ server.registerTool(
1730
+ 'lantern_case_automation_run_get',
1731
+ {
1732
+ title: '读取自动化运行批次',
1733
+ description: '读取批次状态、逐 automationCaseId 结果、报告地址和中断原因。',
1734
+ inputSchema: { batchId: z.string() },
1735
+ annotations: { readOnlyHint: true },
1736
+ },
1737
+ protectedTool(async ({ batchId }) =>
1738
+ toolResult(
1739
+ await apiRequest(apiBase, `${CASE_AUTOMATION_API}/runs/${encodeURIComponent(batchId)}`),
1740
+ ),
1741
+ ),
1742
+ );
1743
+
1744
+ server.registerTool(
1745
+ 'lantern_case_automation_run_wait',
1746
+ {
1747
+ title: '等待自动化运行批次结束',
1748
+ description: '轮询批次直到结束或达到本轮最长等待时间。',
1749
+ inputSchema: {
1750
+ batchId: z.string(),
1751
+ timeoutMs: z.number().int().min(1000).max(55_000).optional(),
1752
+ },
1753
+ annotations: { readOnlyHint: true, openWorldHint: true },
1754
+ },
1755
+ protectedTool(async ({ batchId, timeoutMs = 25_000 }) =>
1756
+ toolResult(await waitForCaseAutomationBatch(apiBase, batchId, timeoutMs)),
1757
+ ),
1758
+ );
1759
+
1760
+ server.registerTool(
1761
+ 'lantern_case_automation_run_stop',
1762
+ {
1763
+ title: '停止自动化运行批次',
1764
+ description: '停止当前批次和正在运行的项目进程,保留已有日志与报告。',
1765
+ inputSchema: { batchId: z.string() },
1766
+ annotations: { destructiveHint: true },
1767
+ },
1768
+ protectedTool(async ({ batchId }) =>
1769
+ toolResult(
1770
+ await apiRequest(
1771
+ apiBase,
1772
+ `${CASE_AUTOMATION_API}/runs/${encodeURIComponent(batchId)}/stop`,
1773
+ { method: 'POST', body: {} },
1774
+ ),
1775
+ ),
1776
+ ),
1777
+ );
1778
+
1779
+ server.registerTool(
1780
+ 'lantern_uiauto_agent_session_get',
1781
+ {
1782
+ title: '读取 UI 自动化生成会话',
1783
+ description:
1784
+ '读取 Plan、IR、探索状态、建议脚本路径、草稿与项目变更;automationCaseId 会话可直接从应用结果中的 uiSessionId 打开。',
1785
+ inputSchema: { sessionId: z.string() },
1786
+ annotations: { readOnlyHint: true },
1787
+ },
1788
+ protectedTool(async ({ sessionId }) =>
1789
+ toolResult(
1790
+ await apiRequest(
1791
+ apiBase,
1792
+ `${UI_AUTO_API}/agent/session?id=${encodeURIComponent(sessionId)}`,
1793
+ ),
1794
+ ),
1795
+ ),
1796
+ );
1797
+
1798
+ server.registerTool(
1799
+ 'lantern_uiauto_agent_open',
1800
+ {
1801
+ title: '打开 UI 自动化探索页面',
1802
+ description: '在会话绑定的项目中启动或复用只读受控浏览器并打开页面,返回当前可交互元素快照。',
1803
+ inputSchema: {
1804
+ sessionId: z.string(),
1805
+ url: z.string(),
1806
+ settle: z.number().int().min(0).max(10_000).optional(),
1807
+ },
1808
+ annotations: { destructiveHint: true, openWorldHint: true },
1809
+ },
1810
+ protectedTool(async (args) =>
1811
+ toolResult(
1812
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/open`, {
1813
+ method: 'POST',
1814
+ body: args,
1815
+ timeoutMs: 60_000,
1816
+ }),
1817
+ ),
1818
+ ),
1819
+ );
1820
+
1821
+ server.registerTool(
1822
+ 'lantern_uiauto_agent_snapshot',
1823
+ {
1824
+ title: '读取 UI 自动化页面快照',
1825
+ description: '读取当前页面可交互元素引用、角色、文本和层级,供定位器绑定与步骤设计使用。',
1826
+ inputSchema: {
1827
+ sessionId: z.string(),
1828
+ depth: z.number().int().min(1).max(20).optional(),
1829
+ targetRef: z.string().optional(),
1830
+ },
1831
+ annotations: { readOnlyHint: true, openWorldHint: true },
1832
+ },
1833
+ protectedTool(async (args) =>
1834
+ toolResult(
1835
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/snapshot`, {
1836
+ method: 'POST',
1837
+ body: args,
1838
+ timeoutMs: 45_000,
1839
+ }),
1840
+ ),
1841
+ ),
1842
+ );
1843
+
1844
+ server.registerTool(
1845
+ 'lantern_uiauto_agent_action',
1846
+ {
1847
+ title: '操作 UI 自动化探索页面',
1848
+ description:
1849
+ '点击、填写、选择、悬停、按键、勾选、滚动、后退或刷新当前页面;可能修改目标系统数据,须符合用户授权。',
1850
+ inputSchema: {
1851
+ sessionId: z.string(),
1852
+ action: z.enum([
1853
+ 'click',
1854
+ 'fill',
1855
+ 'select',
1856
+ 'hover',
1857
+ 'press',
1858
+ 'check',
1859
+ 'uncheck',
1860
+ 'scroll',
1861
+ 'back',
1862
+ 'reload',
1863
+ ]),
1864
+ ref: z.string().optional(),
1865
+ text: z.string().optional(),
1866
+ value: z.string().optional(),
1867
+ key: z.string().optional(),
1868
+ note: z.string().optional(),
1869
+ snapshot: z.boolean().optional(),
1870
+ settle: z.number().int().min(0).max(10_000).optional(),
1871
+ },
1872
+ annotations: { destructiveHint: true, openWorldHint: true },
1873
+ },
1874
+ protectedTool(async (args) =>
1875
+ toolResult(
1876
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/action`, {
1877
+ method: 'POST',
1878
+ body: args,
1879
+ timeoutMs: 100_000,
1880
+ }),
1881
+ ),
1882
+ ),
1883
+ );
1884
+
1885
+ server.registerTool(
1886
+ 'lantern_uiauto_agent_wait',
1887
+ {
1888
+ title: '等待 UI 自动化页面条件',
1889
+ description: '等待页面出现指定文本或固定时间;用于异步加载、提交结果和弹窗。',
1890
+ inputSchema: {
1891
+ sessionId: z.string(),
1892
+ text: z.string().optional(),
1893
+ ms: z.number().int().min(0).max(15_000).optional(),
1894
+ timeout: z.number().int().min(1000).max(60_000).optional(),
1895
+ },
1896
+ annotations: { readOnlyHint: true, openWorldHint: true },
1897
+ },
1898
+ protectedTool(async (args) =>
1899
+ toolResult(
1900
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/wait`, {
1901
+ method: 'POST',
1902
+ body: args,
1903
+ timeoutMs: 70_000,
1904
+ }),
1905
+ ),
1906
+ ),
1907
+ );
1908
+
1909
+ server.registerTool(
1910
+ 'lantern_uiauto_agent_probe',
1911
+ {
1912
+ title: '探测 UI 元素定位器',
1913
+ description: '把页面引用解析为可写入脚本的定位器;提供 stepId 时同时回填当前 Plan 步骤。',
1914
+ inputSchema: {
1915
+ sessionId: z.string(),
1916
+ ref: z.string(),
1917
+ stepId: z.string().optional(),
1918
+ },
1919
+ annotations: { readOnlyHint: true, openWorldHint: true },
1920
+ },
1921
+ protectedTool(async (args) =>
1922
+ toolResult(
1923
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/probe`, {
1924
+ method: 'POST',
1925
+ body: args,
1926
+ timeoutMs: 45_000,
1927
+ }),
1928
+ ),
1929
+ ),
1930
+ );
1931
+
1932
+ server.registerTool(
1933
+ 'lantern_uiauto_agent_save',
1934
+ {
1935
+ title: '保存 UI 自动化 Plan 与 IR',
1936
+ description:
1937
+ '保存生成会话的标题、计划、IR、说明和活动日志;mergePlan=true 时只合并不覆盖用户已有步骤。',
1938
+ inputSchema: {
1939
+ sessionId: z.string(),
1940
+ title: z.string().optional(),
1941
+ target: z.enum(['ts', 'python']).optional(),
1942
+ baseURL: z.string().optional(),
1943
+ source: z.string().optional(),
1944
+ plan: z.array(z.record(z.string(), z.unknown())).optional(),
1945
+ mergePlan: z.boolean().optional(),
1946
+ allowEmptyPlan: z.boolean().optional(),
1947
+ ir: z.record(z.string(), z.unknown()).nullable().optional(),
1948
+ activity: z.array(z.record(z.string(), z.unknown())).optional(),
1949
+ replaceActivity: z.boolean().optional(),
1950
+ narrative: z.string().optional(),
1951
+ status: z.string().optional(),
1952
+ },
1953
+ annotations: { destructiveHint: true },
1954
+ },
1955
+ protectedTool(async (args) =>
1956
+ toolResult(
1957
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/save`, {
1958
+ method: 'POST',
1959
+ body: args,
1960
+ }),
1961
+ ),
1962
+ ),
1963
+ );
1964
+
1965
+ server.registerTool(
1966
+ 'lantern_uiauto_agent_emit',
1967
+ {
1968
+ title: '生成 UI 自动化脚本预览',
1969
+ description:
1970
+ '按会话 IR 或显式传入的 IR 渲染 spec、page object 和 fixture;只预览文件,不写项目。',
1971
+ inputSchema: {
1972
+ sessionId: z.string(),
1973
+ ir: z.record(z.string(), z.unknown()).optional(),
1974
+ target: z.enum(['ts', 'python']).optional(),
1975
+ tag: z.string().optional(),
1976
+ hasBaseURL: z.boolean().optional(),
1977
+ },
1978
+ annotations: { readOnlyHint: true },
1979
+ },
1980
+ protectedTool(async ({ sessionId, ir, target, tag, hasBaseURL }) => {
1981
+ const detail = await apiRequest(
1982
+ apiBase,
1983
+ `${UI_AUTO_API}/agent/session?id=${encodeURIComponent(sessionId)}`,
1984
+ );
1985
+ const effectiveIr = ir || detail.session?.ir;
1986
+ if (!effectiveIr) throw new BridgeError('会话还没有 IR;先探索并保存步骤', 409);
1987
+ return toolResult(
1988
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/emit`, {
1989
+ method: 'POST',
1990
+ body: {
1991
+ sessionId,
1992
+ projectId: detail.session?.projectId,
1993
+ ir: effectiveIr,
1994
+ target: target || detail.session?.target,
1995
+ tag,
1996
+ hasBaseURL: hasBaseURL ?? Boolean(detail.session?.baseURL),
1997
+ },
1998
+ timeoutMs: 60_000,
1999
+ }),
2000
+ );
2001
+ }),
2002
+ );
2003
+
2004
+ server.registerTool(
2005
+ 'lantern_uiauto_agent_verify',
2006
+ {
2007
+ title: '试跑 UI 自动化草稿',
2008
+ description:
2009
+ '把会话 IR 或显式文件写入隔离草稿并运行验证;失败保留 trace、日志和现场,不写正式项目。',
2010
+ inputSchema: {
2011
+ sessionId: z.string(),
2012
+ ir: z.record(z.string(), z.unknown()).optional(),
2013
+ files: z
2014
+ .array(
2015
+ z.object({
2016
+ path: z.string(),
2017
+ content: z.string(),
2018
+ role: z.string().optional(),
2019
+ }),
2020
+ )
2021
+ .optional(),
2022
+ timeoutMs: z.number().int().min(10_000).max(180_000).optional(),
2023
+ },
2024
+ annotations: { destructiveHint: true, openWorldHint: true },
2025
+ },
2026
+ protectedTool(async (args) =>
2027
+ toolResult(
2028
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/verify`, {
2029
+ method: 'POST',
2030
+ body: args,
2031
+ timeoutMs: Math.max(30_000, Number(args.timeoutMs) || 180_000) + 10_000,
2032
+ }),
2033
+ ),
2034
+ ),
2035
+ );
2036
+
2037
+ server.registerTool(
2038
+ 'lantern_uiauto_agent_write',
2039
+ {
2040
+ title: '写入 UI 自动化测试项目',
2041
+ description:
2042
+ '把当前会话脚本合并进项目目标 iteration 文件;同 automationCaseId 只替换自己的测试块,保留其他用例。',
2043
+ inputSchema: {
2044
+ sessionId: z.string(),
2045
+ files: z
2046
+ .array(
2047
+ z.object({
2048
+ path: z.string(),
2049
+ content: z.string(),
2050
+ role: z.string().optional(),
2051
+ force: z.boolean().optional(),
2052
+ }),
2053
+ )
2054
+ .optional(),
2055
+ force: z.boolean().optional(),
2056
+ },
2057
+ annotations: { destructiveHint: true },
2058
+ },
2059
+ protectedTool(async (args) =>
2060
+ toolResult(
2061
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/write`, {
2062
+ method: 'POST',
2063
+ body: args,
2064
+ timeoutMs: 60_000,
2065
+ }),
2066
+ ),
2067
+ ),
2068
+ );
2069
+
2070
+ server.registerTool(
2071
+ 'lantern_uiauto_agent_close',
2072
+ {
2073
+ title: '结束 UI 自动化探索',
2074
+ description: '关闭受控浏览器并保存本轮控制台、网络和草稿摘要;会话与 Plan 保留。',
2075
+ inputSchema: { sessionId: z.string() },
2076
+ annotations: { destructiveHint: true },
2077
+ },
2078
+ protectedTool(async ({ sessionId }) =>
2079
+ toolResult(
2080
+ await apiRequest(apiBase, `${UI_AUTO_API}/agent/close`, {
2081
+ method: 'POST',
2082
+ body: { sessionId },
2083
+ timeoutMs: 30_000,
2084
+ }),
2085
+ ),
2086
+ ),
2087
+ );
2088
+ server.registerTool(
2089
+ 'lantern_case_review_context',
2090
+ {
2091
+ title: '读取用例审查上下文',
2092
+ description: '读取用例文件、文件哈希、确定性覆盖与当前空间审查技能,生成审查后调用 save。',
2093
+ inputSchema: { casePath: z.string() },
2094
+ annotations: { readOnlyHint: true },
2095
+ },
2096
+ protectedTool(async ({ casePath }) => {
2097
+ const file = await apiRequest(
2098
+ apiBase,
2099
+ CASE_EXECUTION_API + '/cases?path=' + encodeURIComponent(casePath),
2100
+ );
2101
+ const entry = await findSpaceSkillByLegacy(apiBase, '用例质量评审提示词.md');
2102
+ if (!entry) throw new BridgeError('请先开启用例质量评审并准备技能', 422);
2103
+ return toolResult({
2104
+ ...file,
2105
+ skill: await readSpaceSkill(apiBase, entry.id),
2106
+ acceptance: await apiRequest(
2107
+ apiBase,
2108
+ '/__tb_case_design/acceptance?casePath=' + encodeURIComponent(casePath),
2109
+ ),
2110
+ });
2111
+ }),
2112
+ );
2113
+ server.registerTool(
2114
+ 'lantern_case_review_save',
2115
+ {
2116
+ title: '保存用例审查报告',
2117
+ description: '文件哈希匹配后保存到页面同一份用例审查记录,不改用例正文。',
2118
+ inputSchema: {
2119
+ casePath: z.string(),
2120
+ expectedFileHash: z.string(),
2121
+ review: z.record(z.string(), z.unknown()),
2122
+ },
2123
+ annotations: { destructiveHint: true },
2124
+ },
2125
+ protectedTool(async ({ casePath, expectedFileHash, review }) =>
2126
+ toolResult(
2127
+ await apiRequest(apiBase, '/__tb_casereview/report', {
2128
+ method: 'PUT',
2129
+ body: { path: casePath, expectedHash: expectedFileHash, review },
2130
+ }),
2131
+ ),
2132
+ ),
2133
+ );
2134
+ server.registerTool(
2135
+ 'lantern_case_acceptance',
2136
+ {
2137
+ title: '读取用例验收与覆盖报告',
2138
+ description:
2139
+ '按需求基线计算设计覆盖、执行与人工判定结果;列出失效基线、未覆盖、待验证和阻塞,不自动放行发布。',
2140
+ inputSchema: { casePath: z.string(), environmentKey: z.string().optional() },
2141
+ annotations: { readOnlyHint: true },
2142
+ },
2143
+ protectedTool(async ({ casePath, environmentKey = '' }) =>
2144
+ toolResult(
2145
+ await apiRequest(
2146
+ apiBase,
2147
+ '/__tb_case_design/acceptance?casePath=' +
2148
+ encodeURIComponent(casePath) +
2149
+ '&environmentKey=' +
2150
+ encodeURIComponent(environmentKey),
2151
+ ),
2152
+ ),
2153
+ ),
2154
+ );
2155
+
2156
+ server.registerTool(
2157
+ 'lantern_case_execution_prepare_columns',
2158
+ {
2159
+ title: '预览或补齐执行列',
2160
+ description: '先 preview,用户确认后 apply;备份后补齐状态和实际结果,不支持直接写回 XLS。',
2161
+ inputSchema: {
2162
+ casePath: z.string(),
2163
+ mode: z.enum(['preview', 'apply']),
2164
+ expectedFileHash: z.string().optional(),
2165
+ },
2166
+ annotations: { destructiveHint: true },
2167
+ },
2168
+ protectedTool(async (args) =>
2169
+ toolResult(
2170
+ await apiRequest(apiBase, CASE_EXECUTION_API + '/prepare-columns', {
2171
+ method: 'POST',
2172
+ body: args,
2173
+ }),
2174
+ ),
2175
+ ),
2176
+ );
2177
+ server.registerTool(
2178
+ 'lantern_case_baseline_link',
2179
+ {
2180
+ title: '关联或更新用例需求基线',
2181
+ description:
2182
+ '先 preview,用户确认后 apply;保留历史结果并要求人工复核,不将旧通过自动计入新版本。',
2183
+ inputSchema: {
2184
+ casePath: z.string(),
2185
+ analysisId: z.string(),
2186
+ mode: z.enum(['preview', 'apply']),
2187
+ expectedFileHash: z.string().optional(),
2188
+ expectedRevision: z.string().optional(),
2189
+ },
2190
+ annotations: { destructiveHint: true },
2191
+ },
2192
+ protectedTool(async (args) =>
2193
+ toolResult(
2194
+ await apiRequest(apiBase, '/__tb_case_design/link', { method: 'POST', body: args }),
2195
+ ),
2196
+ ),
2197
+ );
2198
+ server.registerTool(
2199
+ 'lantern_case_execution_plans',
2200
+ {
2201
+ title: '列出执行计划',
2202
+ description: '读取当前空间计划、环境、用例范围和中断状态。',
2203
+ inputSchema: { casePath: z.string().optional() },
2204
+ annotations: { readOnlyHint: true },
2205
+ },
2206
+ protectedTool(async ({ casePath = '' }) =>
2207
+ toolResult(
2208
+ await apiRequest(
2209
+ apiBase,
2210
+ CASE_EXECUTION_API + '/plans?path=' + encodeURIComponent(casePath),
2211
+ ),
2212
+ ),
2213
+ ),
2214
+ );
2215
+ server.registerTool(
2216
+ 'lantern_case_execution_plan_create',
2217
+ {
2218
+ title: '创建执行计划',
2219
+ description:
2220
+ '仅创建用户明确指定范围的计划,不自动启动;浏览器串行或现有自动化项目,环境与构建必填,结果需人工判定。',
2221
+ inputSchema: {
2222
+ casePath: z.string(),
2223
+ expectedFileHash: z.string(),
2224
+ caseIds: z.array(z.string()).min(1),
2225
+ engine: z.enum(['browser', 'automation']),
2226
+ url: z.string().optional(),
2227
+ storageStatePath: z.string().optional(),
2228
+ allowedOrigins: z.array(z.string()).optional(),
2229
+ environment: z.object({
2230
+ name: z.string().min(1),
2231
+ build: z.string().min(1),
2232
+ role: z.string().optional(),
2233
+ dataNote: z.string().optional(),
2234
+ }),
2235
+ projectId: z.string().optional(),
2236
+ file: z.string().optional(),
2237
+ taskId: z.string().optional(),
2238
+ setupTaskId: z.string().optional(),
2239
+ cleanupTaskId: z.string().optional(),
2240
+ },
2241
+ annotations: { destructiveHint: true },
2242
+ },
2243
+ protectedTool(async (args) =>
2244
+ toolResult(
2245
+ await apiRequest(apiBase, CASE_EXECUTION_API + '/plans', { method: 'POST', body: args }),
2246
+ ),
2247
+ ),
2248
+ );
2249
+ server.registerTool(
2250
+ 'lantern_case_execution_plan_result',
2251
+ {
2252
+ title: '人工验证计划用例结果',
2253
+ description:
2254
+ '用户核验报告后明确选择状态,校验计划范围与基线后继承该计划环境写回。不得由 AI 自行确认。',
2255
+ inputSchema: {
2256
+ planId: z.string(),
2257
+ caseId: z.string(),
2258
+ expectedFileHash: z.string(),
2259
+ status: z.enum(['待验证', '通过', '不通过', '阻塞', '跳过']),
2260
+ actualResult: z.string().min(1),
2261
+ },
2262
+ annotations: { destructiveHint: true },
2263
+ },
2264
+ protectedTool(async ({ planId, ...body }) =>
2265
+ toolResult(
2266
+ await apiRequest(
2267
+ apiBase,
2268
+ CASE_EXECUTION_API + '/plans/' + encodeURIComponent(planId) + '/result',
2269
+ { method: 'POST', body },
2270
+ ),
2271
+ ),
2272
+ ),
2273
+ );
2274
+ for (const action of ['get', 'start', 'stop'])
2275
+ server.registerTool(
2276
+ 'lantern_case_execution_plan_' + action,
2277
+ {
2278
+ title: { get: '读取执行计划', start: '启动或继续执行计划', stop: '停止执行计划' }[action],
2279
+ description:
2280
+ action === 'start'
2281
+ ? '用户明确授权后执行已选择范围;继续仅处理未完成项,不自动写最终状态。'
2282
+ : '读取或停止当前计划并保留已有证据。',
2283
+ inputSchema: { planId: z.string() },
2284
+ annotations: { readOnlyHint: action === 'get', destructiveHint: action !== 'get' },
2285
+ },
2286
+ protectedTool(async ({ planId }) =>
2287
+ toolResult(
2288
+ await apiRequest(
2289
+ apiBase,
2290
+ CASE_EXECUTION_API +
2291
+ '/plans/' +
2292
+ encodeURIComponent(planId) +
2293
+ (action === 'get' ? '' : '/' + action),
2294
+ action === 'get' ? {} : { method: 'POST', body: {} },
2295
+ ),
2296
+ ),
2297
+ ),
2298
+ );
2299
+
2300
+ server.registerTool(
2301
+ 'lantern_case_execution_files',
2302
+ {
2303
+ title: '列出可执行用例文件',
2304
+ description: '列出用例管理中的用例文件、用例数量、是否具备状态和实际结果列。',
2305
+ annotations: { readOnlyHint: true },
2306
+ },
2307
+ protectedTool(async () => toolResult(await apiRequest(apiBase, `${CASE_EXECUTION_API}/files`))),
2308
+ );
2309
+
2310
+ server.registerTool(
2311
+ 'lantern_case_execution_cases',
2312
+ {
2313
+ title: '读取用例执行明细',
2314
+ description: '读取指定用例文件的字段、单条用例和当前执行状态。',
2315
+ inputSchema: { casePath: z.string() },
2316
+ annotations: { readOnlyHint: true },
2317
+ },
2318
+ protectedTool(async ({ casePath }) =>
2319
+ toolResult(
2320
+ await apiRequest(
2321
+ apiBase,
2322
+ `${CASE_EXECUTION_API}/cases?path=${encodeURIComponent(casePath)}`,
2323
+ ),
2324
+ ),
2325
+ ),
2326
+ );
2327
+
2328
+ server.registerTool(
2329
+ 'lantern_case_execution_login_start',
2330
+ {
2331
+ title: '打开用例执行登录页面',
2332
+ description: '打开目标系统登录窗口,由用户完成登录;工具不接收账号密码。',
2333
+ inputSchema: { url: z.string() },
2334
+ annotations: { destructiveHint: true, openWorldHint: true },
2335
+ },
2336
+ protectedTool(async ({ url }) =>
2337
+ toolResult(
2338
+ await apiRequest(apiBase, `${CASE_EXECUTION_API}/auth/start`, {
2339
+ method: 'POST',
2340
+ body: { url },
2341
+ timeoutMs: 60_000,
2342
+ }),
2343
+ ),
2344
+ ),
2345
+ );
2346
+
2347
+ server.registerTool(
2348
+ 'lantern_case_execution_login_complete',
2349
+ {
2350
+ title: '保存用例执行登录态',
2351
+ description: '用户完成登录后保存当前目标的浏览器 storageState。',
2352
+ annotations: { destructiveHint: true, openWorldHint: true },
2353
+ },
2354
+ protectedTool(async () =>
2355
+ toolResult(
2356
+ await apiRequest(apiBase, `${CASE_EXECUTION_API}/auth/complete`, {
2357
+ method: 'POST',
2358
+ body: {},
2359
+ timeoutMs: 60_000,
2360
+ }),
2361
+ ),
2362
+ ),
2363
+ );
2364
+
2365
+ server.registerTool(
2366
+ 'lantern_case_execution_start',
2367
+ {
2368
+ title: '启动单条用例 AI 执行',
2369
+ description:
2370
+ '按用例文件路径和行号启动单条 AI 浏览器执行。只使用已有登录态路径,不接收账号密码。',
2371
+ inputSchema: {
2372
+ casePath: z.string(),
2373
+ rowIndex: z.number().int().nonnegative(),
2374
+ url: z.string(),
2375
+ storageStatePath: z.string().optional(),
2376
+ allowedOrigins: z.array(z.string()).optional(),
2377
+ environment: z
2378
+ .object({
2379
+ name: z.string(),
2380
+ role: z.string().optional(),
2381
+ build: z.string().optional(),
2382
+ dataNote: z.string().optional(),
2383
+ })
2384
+ .optional(),
1432
2385
  },
1433
2386
  annotations: { destructiveHint: true, openWorldHint: true },
1434
2387
  },
@@ -1504,6 +2457,7 @@ export function createLanternMcpServer({ apiBase, version = '1.0.0' }) {
1504
2457
  status: z.enum(['待验证', '通过', '不通过', '阻塞', '跳过']),
1505
2458
  actualResult: z.string(),
1506
2459
  executor: z.string().optional(),
2460
+ expectedFileHash: z.string().optional(),
1507
2461
  defectNo: z.string().optional(),
1508
2462
  },
1509
2463
  annotations: { destructiveHint: true },