lantern-harness 0.1.45 → 0.2.2

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 (244) hide show
  1. package/CHANGELOG.md +215 -0
  2. package/README.md +25 -8
  3. package/builtin/session/lh-fs.mjs +93 -4
  4. package/builtin/session/lh-nav-groups.mjs +3 -0
  5. package/builtin/session/mcp-client.mjs +7 -3
  6. package/builtin/session/session-runs.mjs +5 -1
  7. package/builtin/session/skill-validation.mjs +72 -0
  8. package/builtin/session/space-skills.mjs +751 -0
  9. package/cli/data-root.mjs +21 -4
  10. package/cli/lantern.mjs +26 -1
  11. package/cli/mcp-server.mjs +2779 -0
  12. package/cli/server.mjs +8 -2
  13. package/config/app.defaults.json +4 -2
  14. package/dist/500.html +9 -6
  15. package/dist/_astro/Base.Du_-4L-4.css +1 -0
  16. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.XUV2H6ea.js +2 -0
  17. package/dist/_astro/BusinessMapBoard.mRxl2G3D.js +5 -0
  18. package/dist/_astro/CaseExecBoard.Cqkxuf5c.js +1 -0
  19. package/dist/_astro/CaseExecutionBoard.CjX4CoKd.js +5 -0
  20. package/dist/_astro/CaseGenerateApp.acgnxl79.js +10 -0
  21. package/dist/_astro/CasesLibrary.zmzOQwdn.js +21 -0
  22. package/dist/_astro/ChatApp.Ben9LFra.js +1 -0
  23. package/dist/_astro/ChatApp.DBi6q7Qv.js +262 -0
  24. package/dist/_astro/{ConfirmDialog.DrrPf1MB.js → ConfirmDialog.DQFd6g2r.js} +1 -1
  25. package/dist/_astro/DashboardBoard.CAJVE2G4.js +5 -0
  26. package/dist/_astro/{DatePicker.Bkl71M49.js → DatePicker.BRO_CjVQ.js} +1 -1
  27. package/dist/_astro/DefectSubmitEntry.BzKXJ-zq.js +2 -0
  28. package/dist/_astro/DocsFileBrowser.apKMbGVf.js +1 -0
  29. package/dist/_astro/{DocsPager.Duf4I68E.js → DocsPager.DMN9-Tjg.js} +1 -1
  30. package/dist/_astro/{DrawerField.BH3p4Q4D.js → DrawerField.CLdvmHc6.js} +1 -1
  31. package/dist/_astro/KnowledgeLibrary.BcoMQeUd.js +1 -0
  32. package/dist/_astro/LifeKrTasksBoard.DJU0-QI-.js +1 -0
  33. package/dist/_astro/LifeKrTodosBoard.GK7KRAO3.js +1 -0
  34. package/dist/_astro/LifeObjectivesBoard.DuKa6Q3k.js +1 -0
  35. package/dist/_astro/LifePlanTypeSelect.Cm2lUmnH.js +1 -0
  36. package/dist/_astro/{LifeReviewsBoard.BPXeVpg1.js → LifeReviewsBoard.BWOOVMtz.js} +3 -3
  37. package/dist/_astro/{LifeShared.tnT7aQON.js → LifeShared.bY2l01Ha.js} +2 -2
  38. package/dist/_astro/LifeStagesBoard.CIzxPOJB.js +1 -0
  39. package/dist/_astro/LifeYearCycleSelect.BlsyPmmI.js +1 -0
  40. package/dist/_astro/LifeYearPlansBoard.DaA9O08j.js +1 -0
  41. package/dist/_astro/MultiSelectDropdown.D-rbpivp.js +1 -0
  42. package/dist/_astro/{NamePromptDialog.Csfnh5eM.js → NamePromptDialog.KPCeXmri.js} +1 -1
  43. package/dist/_astro/NavLibraries.DVR5Ua-S.js +1 -0
  44. package/dist/_astro/PluginsPage.B063QIlQ.js +18 -0
  45. package/dist/_astro/PmBugsBoard.Cu-v0Gfd.js +1 -0
  46. package/dist/_astro/PmIterationsBoard.CgRzkP-j.js +1 -0
  47. package/dist/_astro/{PmProjectDetail.DneFVBpy.js → PmProjectDetail.DVCEh0Lm.js} +1 -1
  48. package/dist/_astro/PmProjectsBoard.z-bQa98r.js +1 -0
  49. package/dist/_astro/PmRequirementsBoard.B0W6bsW2.js +1 -0
  50. package/dist/_astro/PmRequirementsBoard.CyfBI0u_.js +1 -0
  51. package/dist/_astro/PmShared.BQVzwsiz.js +1 -0
  52. package/dist/_astro/ReportsPage.najSzJeT.js +1 -0
  53. package/dist/_astro/ReqAnalysisBoard.BQb8dHFD.js +39 -0
  54. package/dist/_astro/RequirementBreakdownLibrary.Cn6OV6xt.js +2 -0
  55. package/dist/_astro/RequirementsLibrary.CqKNFVsP.js +1 -0
  56. package/dist/_astro/SearchableSelect.DXclLMJI.js +1 -0
  57. package/dist/_astro/SelectDropdown.D7IeyHDI.js +1 -0
  58. package/dist/_astro/SettingsDialog.db3BpFw0.js +1 -0
  59. package/dist/_astro/SlideOverDrawer.BMg2tce6.js +1 -0
  60. package/dist/_astro/SpaceSwitcher.DSUVAPOi.js +7 -0
  61. package/dist/_astro/{TableFieldConfig.C7O-mL-p.js → TableFieldConfig.72AL-8p-.js} +1 -1
  62. package/dist/_astro/{TagSelect.UUXgkMqJ.js → TagSelect.B_r2p0fp.js} +1 -1
  63. package/dist/_astro/TasksBoard.CCDhCSR7.js +1 -0
  64. package/dist/_astro/TemplatesLibrary.peYzrHZ2.js +1 -0
  65. package/dist/_astro/TestReportsLibrary.fWiEyCRx.js +1 -0
  66. package/dist/_astro/TestStatsBoard.BSUBsWSu.js +1 -0
  67. package/dist/_astro/Toast.BydY-X7T.js +1 -0
  68. package/dist/_astro/TodosBoard.By5YdlUe.js +1 -0
  69. package/dist/_astro/UiAutoBoard.BGdlp5Sr.js +3 -0
  70. package/dist/_astro/UiAutoEnvPanel.BUASgPLB.js +10 -0
  71. package/dist/_astro/UiAutoGenerationDialog.D1PyCgrD.js +12 -0
  72. package/dist/_astro/UiAutoProjectsPage.B6A9NlVK.js +3 -0
  73. package/dist/_astro/app-config.Dvfzl5_N.js +1 -0
  74. package/dist/_astro/app-version.CNpnKIb9.js +1 -0
  75. package/dist/_astro/{bash-tools.D9HCzC_7.js → bash-tools.CS2w8LOb.js} +1 -1
  76. package/dist/_astro/business-map.BiJ85oxm.js +1 -0
  77. package/dist/_astro/business-map.DKwdW1VL.css +1 -0
  78. package/dist/_astro/case-gen-run.Cvvdv_kv.js +26 -0
  79. package/dist/_astro/case-prompt.CZ3vWUju.js +2 -0
  80. package/dist/_astro/{case-review.TdDs1WFM.js → case-review.DFWZkoR9.js} +1 -1
  81. package/dist/_astro/{case-template.Cd2xNbgy.js → case-template.Clb7HrDB.js} +1 -1
  82. package/dist/_astro/defect-submit.Dc49lFjm.css +1 -0
  83. package/dist/_astro/defect-workbench.CjTb4FDv.js +6 -0
  84. package/dist/_astro/dialog.XgRGNF_Q.js +1 -0
  85. package/dist/_astro/doc-roots.C-20VD0x.js +1 -0
  86. package/dist/_astro/{hydrate-cache.B15Nrpq0.js → hydrate-cache.O4CIma9y.js} +1 -1
  87. package/dist/_astro/i18n.Cp4so7KR.js +7 -0
  88. package/dist/_astro/{llm.DN5S1KBK.js → llm.BCYNgppW.js} +1 -1
  89. package/dist/_astro/mcp-tools.Kf-lupGn.js +7 -0
  90. package/dist/_astro/{open-docs-in-session.CRiZT022.js → open-docs-in-session.BpcAcBSI.js} +1 -1
  91. package/dist/_astro/plugins.Db9xoFZb.js +1 -0
  92. package/dist/_astro/project-docs.bB9lQ1Ki.js +1 -0
  93. package/dist/_astro/prompts-meta.VAjE4OET.js +2 -0
  94. package/dist/_astro/report-prompt.CwHuOcRN.js +1 -0
  95. package/dist/_astro/req-analysis.C_gARMrB.js +31 -0
  96. package/dist/_astro/requirement-breakdown-library.l0rPd7b3.js +1 -0
  97. package/dist/_astro/{settings.38J2uD5M.js → settings.D02wZj3w.js} +2 -2
  98. package/dist/_astro/space-skills.CPucW8zt.js +1 -0
  99. package/dist/_astro/{spaces-client.DV04tRyD.js → spaces-client.BAtG6PkW.js} +1 -1
  100. package/dist/_astro/story-review.DTN91Vl9.js +7 -0
  101. package/dist/_astro/test-points.C7ZgggQT.js +8 -0
  102. package/dist/_astro/test-reports.0gr6-c_0.js +19 -0
  103. package/dist/_astro/ui-auto-prompt.BmO3ja2m.js +8 -0
  104. package/dist/_astro/{view-prefs.DhdLZjGh.js → view-prefs.COAKEQtZ.js} +1 -1
  105. package/dist/business-map/index.html +983 -0
  106. package/dist/case-exec/index.html +10 -7
  107. package/dist/{prompts → case-execution}/index.html +12 -9
  108. package/dist/cases/generate/index.html +9 -6
  109. package/dist/cases/library/index.html +10 -7
  110. package/dist/dashboard/index.html +10 -7
  111. package/dist/defect-rules/index.html +690 -0
  112. package/dist/defect-submit/index.html +690 -0
  113. package/dist/defect-submit/templates/index.html +690 -0
  114. package/dist/docs/changelog/index.html +259 -52
  115. package/dist/docs/install/index.html +44 -12
  116. package/dist/docs/manual/index.html +212 -75
  117. package/dist/knowledge/index.html +10 -7
  118. package/dist/life/kr-tasks/index.html +10 -7
  119. package/dist/life/kr-todos/index.html +10 -7
  120. package/dist/life/objectives/index.html +10 -7
  121. package/dist/life/reviews/index.html +10 -7
  122. package/dist/life/stages/index.html +10 -7
  123. package/dist/life/year-plans/index.html +10 -7
  124. package/dist/plugins/index.html +10 -7
  125. package/dist/pm/bugs/index.html +10 -7
  126. package/dist/pm/iterations/index.html +10 -7
  127. package/dist/pm/projects/detail/index.html +10 -7
  128. package/dist/pm/projects/index.html +10 -7
  129. package/dist/pm/requirements/index.html +10 -7
  130. package/dist/reports/index.html +10 -7
  131. package/dist/requirement-analysis/index.html +10 -7
  132. package/dist/requirement-breakdowns/index.html +983 -0
  133. package/dist/requirements/index.html +10 -7
  134. package/dist/tasks/index.html +10 -7
  135. package/dist/templates/index.html +10 -7
  136. package/dist/test-automation/index.html +10 -7
  137. package/dist/test-automation/projects/index.html +10 -7
  138. package/dist/test-reports/index.html +10 -7
  139. package/dist/test-stats/index.html +10 -7
  140. package/dist/todos/index.html +10 -7
  141. package/dist/workbench/index.html +9 -6
  142. package/docs/Codex-MCP/351/233/206/346/210/220.md +296 -0
  143. package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/204/344/274/260.md +39 -0
  144. package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/206/345/210/253/351/207/215/346/236/204/346/226/271/346/241/210.md +88 -0
  145. package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +22 -3
  146. package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +41 -1
  147. package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +63 -17
  148. package/docs//346/217/222/344/273/266/344/273/223/345/272/223/344/270/216/346/212/200/350/203/275/346/225/264/345/220/210/346/226/271/346/241/210.md +187 -0
  149. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +207 -69
  150. package/lh-plugins/business-map/assistant.mjs +958 -0
  151. package/lh-plugins/business-map/auth-paths.mjs +61 -0
  152. package/lh-plugins/business-map/jobs.mjs +749 -0
  153. package/lh-plugins/business-map/login.mjs +295 -0
  154. package/lh-plugins/business-map/sources.mjs +1014 -0
  155. package/lh-plugins/case-execution/files.mjs +777 -0
  156. package/lh-plugins/case-execution/service.mjs +959 -0
  157. package/lh-plugins/case-execution-prompt.mjs +33 -0
  158. package/lh-plugins/lh-business-map.mjs +2431 -0
  159. package/lh-plugins/lh-case-execution.mjs +304 -0
  160. package/lh-plugins/lh-config.mjs +13 -0
  161. package/lh-plugins/lh-defect-submit.mjs +989 -0
  162. package/lh-plugins/lh-project-docs.mjs +31 -140
  163. package/lh-plugins/lh-reports.mjs +29 -57
  164. package/lh-plugins/lh-req-analysis.mjs +32 -3
  165. package/lh-plugins/lh-req-breakdown-library.mjs +1084 -0
  166. package/lh-plugins/lh-uiauto.mjs +514 -22
  167. package/lh-plugins/plugin-prompts.mjs +19 -15
  168. package/lh-plugins/req-analysis-revision.mjs +24 -0
  169. package/lh-plugins/test-points-prompt.mjs +2 -3
  170. package/lh-plugins/uiauto-auth-setup.mjs +218 -0
  171. package/lh-plugins/uiauto-explorer/apps.mjs +13 -2
  172. package/lh-plugins/uiauto-explorer/runner.mjs +15 -2
  173. package/lh-plugins/uiauto-explorer/sessions.mjs +305 -17
  174. package/lh-plugins/uiauto-node.mjs +102 -11
  175. package/lh-plugins/uiauto-prompt.mjs +20 -15
  176. package/lh-plugins/uiauto-sso.mjs +407 -0
  177. package/package.json +5 -2
  178. package/skills/case-execution/SKILL.md +30 -0
  179. package/skills/lantern-defect-submit/SKILL.md +15 -0
  180. package/skills/lantern-workflow/SKILL.md +57 -0
  181. package/skills/office/SKILL.md +26 -0
  182. package/dist/_astro/Base.Bkt1lrgu.css +0 -1
  183. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.UKTVQqk7.js +0 -2
  184. package/dist/_astro/CaseExecBoard.DICluCbK.js +0 -1
  185. package/dist/_astro/CaseGenerateApp.Be3h5XPG.js +0 -10
  186. package/dist/_astro/CasesLibrary.Buys7Cy-.js +0 -21
  187. package/dist/_astro/ChatApp.D3BheKci.js +0 -227
  188. package/dist/_astro/DashboardBoard.Qvf8o4v1.js +0 -5
  189. package/dist/_astro/DocsFileBrowser.DwKBffbM.js +0 -1
  190. package/dist/_astro/KnowledgeLibrary.MDpMqeOd.js +0 -1
  191. package/dist/_astro/LifeKrTasksBoard.DsvW_S66.js +0 -1
  192. package/dist/_astro/LifeKrTodosBoard.D2KTqvg1.js +0 -1
  193. package/dist/_astro/LifeObjectivesBoard.B0cDK934.js +0 -1
  194. package/dist/_astro/LifePlanTypeSelect.BELDvMWU.js +0 -1
  195. package/dist/_astro/LifeStagesBoard.CZftLR9K.js +0 -1
  196. package/dist/_astro/LifeYearCycleSelect.Bw2eRbSm.js +0 -1
  197. package/dist/_astro/LifeYearPlansBoard.DB-RJFEl.js +0 -1
  198. package/dist/_astro/MultiSelectDropdown.CBC7aNOv.js +0 -1
  199. package/dist/_astro/NavLibraries.DdQYsZbe.js +0 -1
  200. package/dist/_astro/OverflowHint.CHZeFfUj.js +0 -1
  201. package/dist/_astro/PluginsPage.C1JnInH4.js +0 -17
  202. package/dist/_astro/PluginsPage.C3eEwy3K.js +0 -1
  203. package/dist/_astro/PmBugsBoard.CGpXUTPu.js +0 -1
  204. package/dist/_astro/PmIterationsBoard.BaKiFIam.js +0 -1
  205. package/dist/_astro/PmProjectsBoard.BxoMF9gK.js +0 -1
  206. package/dist/_astro/PmRequirementsBoard.-SI8VZXI.js +0 -1
  207. package/dist/_astro/PmRequirementsBoard.DsK6RF7Q.js +0 -1
  208. package/dist/_astro/PmShared.BK8kWRSV.js +0 -1
  209. package/dist/_astro/PromptMountDialog.mrTx3U5T.js +0 -1
  210. package/dist/_astro/PromptsLibrary.B_SUf47p.js +0 -1
  211. package/dist/_astro/ReportsPage.B9lGg1_s.js +0 -16
  212. package/dist/_astro/ReqAnalysisBoard.CIZKnCQH.js +0 -39
  213. package/dist/_astro/RequirementsLibrary.cJc-bnGQ.js +0 -1
  214. package/dist/_astro/SearchableSelect.SyLRS-Jj.js +0 -1
  215. package/dist/_astro/SelectDropdown.T3CKHaLt.js +0 -1
  216. package/dist/_astro/SettingsDialog.DYdtCvLc.js +0 -1
  217. package/dist/_astro/SpaceSwitcher.C47_S1g9.js +0 -7
  218. package/dist/_astro/TasksBoard.BUEg2BYk.js +0 -1
  219. package/dist/_astro/TemplatesLibrary.BLVIphXO.js +0 -1
  220. package/dist/_astro/TestReportsLibrary.DVq30Jae.js +0 -1
  221. package/dist/_astro/TestStatsBoard.-5BWQ6bI.js +0 -1
  222. package/dist/_astro/Toast.BO2NFckG.js +0 -1
  223. package/dist/_astro/TodosBoard.DI_lTp2e.js +0 -1
  224. package/dist/_astro/UiAutoBoard.ChFdgv7s.js +0 -2
  225. package/dist/_astro/UiAutoEnvPanel.B50q4kYb.js +0 -19
  226. package/dist/_astro/UiAutoGenerationDialog.CLkFAHrm.js +0 -1
  227. package/dist/_astro/UiAutoProjectsPage.DCsDeN5d.js +0 -3
  228. package/dist/_astro/app-config.DkyjuL-S.js +0 -1
  229. package/dist/_astro/app-version.Cy-5oZO2.js +0 -1
  230. package/dist/_astro/case-gen-run.BklG1H8k.js +0 -22
  231. package/dist/_astro/case-types.DlFkbZJN.js +0 -1
  232. package/dist/_astro/dialog.DZHZCe_T.js +0 -1
  233. package/dist/_astro/doc-roots.CO3IBiY6.js +0 -1
  234. package/dist/_astro/i18n.D_aOCHSN.js +0 -7
  235. package/dist/_astro/markdown-client.BS19nLL3.js +0 -62
  236. package/dist/_astro/plugins.BRvXWHLe.js +0 -1
  237. package/dist/_astro/project-docs.CCjtiFjB.js +0 -1
  238. package/dist/_astro/prompts-meta.BUGutlsk.js +0 -2
  239. package/dist/_astro/report-prompt.B9C4cv84.js +0 -1
  240. package/dist/_astro/req-analysis.B12_MGMQ.js +0 -31
  241. package/dist/_astro/story-review.D2W5tEOY.js +0 -14
  242. package/dist/_astro/test-reports.CuIjlEyK.js +0 -19
  243. package/dist/_astro/ui-auto-prompt.H9_yhau9.js +0 -9
  244. package/dist/_astro/ui-auto.DMv940x4.js +0 -1
@@ -0,0 +1,304 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ import { getDataRoot } from '../builtin/session/space-context.mjs';
5
+ import {
6
+ CASE_EXECUTION_PROMPT_FILE,
7
+ CASE_EXECUTION_PROMPT_TEMPLATE,
8
+ } from './case-execution-prompt.mjs';
9
+ import {
10
+ applyManualResult,
11
+ cancelManualLogin,
12
+ completeManualLogin,
13
+ confirmRun,
14
+ getRun,
15
+ listExecutionRuns,
16
+ savedAuthFor,
17
+ shotPath,
18
+ startManualLogin,
19
+ startRun,
20
+ stopRun,
21
+ subscribeRun,
22
+ } from './case-execution/service.mjs';
23
+ import {
24
+ applyCaseFieldUpdates,
25
+ listCaseDocuments,
26
+ loadCaseDocument,
27
+ } from './case-execution/files.mjs';
28
+ import { ensurePluginPrompt, isPluginOnInSpace } from './plugin-prompts.mjs';
29
+
30
+ const PREFIX = '/__tb_case_run';
31
+
32
+ function sendJson(res, status, body) {
33
+ res.statusCode = status;
34
+ res.setHeader('Content-Type', 'application/json; charset=utf-8');
35
+ res.setHeader('Cache-Control', 'no-store');
36
+ res.end(JSON.stringify(body));
37
+ }
38
+
39
+ function readBody(req) {
40
+ return new Promise((resolve, reject) => {
41
+ const chunks = [];
42
+ let size = 0;
43
+ req.on('data', (chunk) => {
44
+ size += chunk.length;
45
+ if (size > 2 * 1024 * 1024) {
46
+ reject(Object.assign(new Error('请求内容过大'), { statusCode: 413 }));
47
+ req.destroy();
48
+ return;
49
+ }
50
+ chunks.push(Buffer.from(chunk));
51
+ });
52
+ req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
53
+ req.on('error', reject);
54
+ });
55
+ }
56
+
57
+ function sameOrigin(req) {
58
+ if (!req.headers.origin) return true;
59
+ try {
60
+ return new URL(req.headers.origin).host === req.headers.host;
61
+ } catch {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ async function statsRequest(host, route = '', init = {}) {
67
+ const response = await fetch(`http://${host}/__tb_case_exec${route}`, {
68
+ ...init,
69
+ headers: {
70
+ ...(init.body ? { 'Content-Type': 'application/json' } : {}),
71
+ ...(init.headers || {}),
72
+ },
73
+ signal: AbortSignal.timeout(15_000),
74
+ });
75
+ const data = await response.json().catch(() => ({}));
76
+ if (!response.ok) {
77
+ throw Object.assign(new Error(data.error || `用例执行统计 HTTP ${response.status}`), {
78
+ statusCode: response.status,
79
+ });
80
+ }
81
+ return data;
82
+ }
83
+
84
+ async function syncStats(root, host, raw) {
85
+ const casePath = String(raw.casePath || '').trim();
86
+ const project = String(raw.project || '').trim();
87
+ const date = String(raw.date || '').trim();
88
+ const mode = raw.mode === 'overwrite' ? 'overwrite' : raw.mode === 'skip' ? 'skip' : 'preview';
89
+ if (!casePath) throw Object.assign(new Error('缺少用例文件路径'), { statusCode: 400 });
90
+ if (!project) throw Object.assign(new Error('请选择统计项目'), { statusCode: 400 });
91
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
92
+ throw Object.assign(new Error('统计日期格式无效'), { statusCode: 400 });
93
+ }
94
+ const document = await loadCaseDocument(root, casePath);
95
+ const completedStatuses = new Set(['通过', '不通过', '阻塞', '跳过']);
96
+ const executed = document.cases.filter((item) => {
97
+ const status = String(item.status || '').trim();
98
+ return (
99
+ completedStatuses.has(status) ||
100
+ /^(p|pass|passed|ok|成功|true|1|f|fail|failed|失败|false|0)$/i.test(status) ||
101
+ /block|skip|n\/?a/i.test(status)
102
+ );
103
+ }).length;
104
+ const total = document.cases.length;
105
+ const pending = Math.max(0, total - executed);
106
+ const current = await statsRequest(host);
107
+ const existing = (current.items || []).find(
108
+ (item) => item.project === project && item.date === date,
109
+ );
110
+ const preview = {
111
+ casePath,
112
+ project,
113
+ date,
114
+ total,
115
+ executed,
116
+ pending,
117
+ existing: existing || null,
118
+ };
119
+ if (mode === 'preview') return { ok: true, preview };
120
+ if (existing && mode === 'skip') {
121
+ return { ok: true, preview, skipped: true, item: existing };
122
+ }
123
+ if (existing) {
124
+ const data = await statsRequest(host, '', {
125
+ method: 'PUT',
126
+ body: JSON.stringify({
127
+ id: existing.id,
128
+ total,
129
+ pending,
130
+ executed,
131
+ }),
132
+ });
133
+ return { ok: true, preview, overwritten: true, item: data.item };
134
+ }
135
+ const data = await statsRequest(host, '', {
136
+ method: 'POST',
137
+ body: JSON.stringify({
138
+ mode: 'manual',
139
+ items: [
140
+ {
141
+ date,
142
+ project,
143
+ startDate: date,
144
+ endDate: date,
145
+ total,
146
+ pending,
147
+ executed,
148
+ },
149
+ ],
150
+ }),
151
+ });
152
+ return {
153
+ ok: true,
154
+ preview,
155
+ item: (data.items || []).find((item) => item.project === project && item.date === date) || null,
156
+ };
157
+ }
158
+
159
+ export function lhCaseExecutionPlugin() {
160
+ return {
161
+ name: 'lh-case-execution',
162
+ configureServer(server) {
163
+ server.middlewares.use(async (req, res, next) => {
164
+ const parsed = new URL(req.url || '/', 'http://127.0.0.1');
165
+ if (!parsed.pathname.startsWith(PREFIX)) return next();
166
+ const tail = parsed.pathname.slice(PREFIX.length) || '/';
167
+ const method = req.method || 'GET';
168
+ try {
169
+ const root = getDataRoot();
170
+ const enabled = isPluginOnInSpace('caseExecution', root);
171
+ if (enabled) {
172
+ ensurePluginPrompt(CASE_EXECUTION_PROMPT_FILE, CASE_EXECUTION_PROMPT_TEMPLATE, root);
173
+ }
174
+ if (parsed.pathname === `${PREFIX}/health` && parsed.searchParams.get('health') === '1') {
175
+ return sendJson(res, 200, { ok: true, enabled });
176
+ }
177
+ if (!enabled) {
178
+ return sendJson(res, 403, {
179
+ ok: false,
180
+ error: '请先在插件仓库开启「用例执行」',
181
+ });
182
+ }
183
+ if (!sameOrigin(req) && method !== 'GET') {
184
+ return sendJson(res, 403, {
185
+ ok: false,
186
+ error: '用例执行请求必须来自当前 Lantern 页面',
187
+ });
188
+ }
189
+
190
+ if (method === 'GET' && tail === '/files') {
191
+ return sendJson(res, 200, {
192
+ ok: true,
193
+ files: await listCaseDocuments(root),
194
+ });
195
+ }
196
+ if (method === 'GET' && tail === '/cases') {
197
+ const document = await loadCaseDocument(
198
+ root,
199
+ String(parsed.searchParams.get('path') || ''),
200
+ );
201
+ const { _parsed, _map, abs, ...publicDocument } = document;
202
+ return sendJson(res, 200, { ok: true, document: publicDocument });
203
+ }
204
+ if (method === 'GET' && tail === '/runs') {
205
+ return sendJson(res, 200, {
206
+ ok: true,
207
+ runs: listExecutionRuns(root, parsed.searchParams.get('path') || ''),
208
+ });
209
+ }
210
+ if (method === 'GET' && tail.startsWith('/runs/') && tail.endsWith('/events')) {
211
+ const runId = tail.split('/')[2];
212
+ return subscribeRun(root, runId, Number(parsed.searchParams.get('after') || 0), res);
213
+ }
214
+ if (method === 'GET' && tail.startsWith('/runs/') && tail.includes('/shots/')) {
215
+ const parts = tail.split('/');
216
+ const file = decodeURIComponent(parts[4] || '');
217
+ const abs = shotPath(root, parts[2], file);
218
+ if (!fs.existsSync(abs)) return sendJson(res, 404, { ok: false, error: '截图不存在' });
219
+ res.statusCode = 200;
220
+ res.setHeader('Content-Type', 'image/png');
221
+ res.setHeader('Cache-Control', 'no-store');
222
+ return fs.createReadStream(abs).pipe(res);
223
+ }
224
+ if (method === 'GET' && tail.startsWith('/runs/')) {
225
+ return sendJson(res, 200, {
226
+ ok: true,
227
+ run: getRun(root, tail.split('/')[2] || ''),
228
+ });
229
+ }
230
+ if (method === 'GET' && tail === '/auth/status') {
231
+ return sendJson(res, 200, {
232
+ ok: true,
233
+ ...savedAuthFor(root, { url: parsed.searchParams.get('url') || '' }),
234
+ });
235
+ }
236
+ if (method === 'POST' && tail === '/auth/start') {
237
+ return sendJson(
238
+ res,
239
+ 200,
240
+ await startManualLogin(root, JSON.parse((await readBody(req)) || '{}')),
241
+ );
242
+ }
243
+ if (method === 'POST' && tail === '/auth/complete') {
244
+ return sendJson(res, 200, await completeManualLogin(root));
245
+ }
246
+ if (method === 'POST' && tail === '/auth/cancel') {
247
+ return sendJson(res, 200, await cancelManualLogin(root));
248
+ }
249
+ if (method === 'POST' && tail === '/runs') {
250
+ const body = JSON.parse((await readBody(req)) || '{}');
251
+ return sendJson(res, 202, { ok: true, run: await startRun(root, body) });
252
+ }
253
+ if (method === 'POST' && tail.startsWith('/runs/') && tail.endsWith('/stop')) {
254
+ return sendJson(res, 200, {
255
+ ok: true,
256
+ run: stopRun(root, tail.split('/')[2] || ''),
257
+ });
258
+ }
259
+ if (method === 'POST' && tail.startsWith('/runs/') && tail.endsWith('/apply')) {
260
+ const body = JSON.parse((await readBody(req)) || '{}');
261
+ return sendJson(res, 200, {
262
+ ok: true,
263
+ ...(await confirmRun(root, tail.split('/')[2] || '', body)),
264
+ });
265
+ }
266
+ if (method === 'POST' && tail === '/manual') {
267
+ const body = JSON.parse((await readBody(req)) || '{}');
268
+ return sendJson(res, 200, {
269
+ ok: true,
270
+ applied: await applyManualResult(root, body),
271
+ });
272
+ }
273
+ if (method === 'POST' && tail === '/fields') {
274
+ const body = JSON.parse((await readBody(req)) || '{}');
275
+ return sendJson(res, 200, {
276
+ ok: true,
277
+ applied: await applyCaseFieldUpdates(root, {
278
+ path: body.casePath,
279
+ expectedFileHash: body.expectedFileHash,
280
+ rowIndex: body.rowIndex,
281
+ updates: body.updates,
282
+ }),
283
+ });
284
+ }
285
+ if (method === 'POST' && tail === '/stats/sync') {
286
+ const body = JSON.parse((await readBody(req)) || '{}');
287
+ return sendJson(
288
+ res,
289
+ 200,
290
+ await syncStats(root, req.headers.host || '127.0.0.1:4321', body),
291
+ );
292
+ }
293
+ return sendJson(res, 404, { ok: false, error: '接口不存在' });
294
+ } catch (error) {
295
+ return sendJson(res, Number(error?.statusCode) || 500, {
296
+ ok: false,
297
+ error: error instanceof Error ? error.message : String(error),
298
+ ...(error?.currentHash ? { currentHash: error.currentHash } : {}),
299
+ });
300
+ }
301
+ });
302
+ },
303
+ };
304
+ }
@@ -246,6 +246,19 @@ function readApiKey(root, localConfig) {
246
246
  return '';
247
247
  }
248
248
 
249
+ export function resolveModelForSpace(root) {
250
+ const model = resolveGlobalModel(root);
251
+ const config = { ...ensureLocalConfig(root), model };
252
+ const providers = Array.isArray(model.providers) ? model.providers : [];
253
+ const provider = providers.find((item) => item.id === model.activeId) || providers[0] || model;
254
+ return {
255
+ baseURL: String(provider?.baseURL || '').trim(),
256
+ model: String(provider?.model || '').trim(),
257
+ apiKey: readApiKey(root, config),
258
+ reasoningEffort: String(model.reasoningEffort || '').trim(),
259
+ };
260
+ }
261
+
249
262
  function sanitizeForLocalWrite(config) {
250
263
  return structuredClone(config);
251
264
  }