lantern-harness 0.1.45 → 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 (274) hide show
  1. package/CHANGELOG.md +242 -0
  2. package/README.md +25 -8
  3. package/builtin/case-backup-contract.mjs +27 -0
  4. package/builtin/case-workflow-contract.mjs +158 -0
  5. package/builtin/session/lh-fs.mjs +93 -4
  6. package/builtin/session/lh-nav-groups.mjs +36 -1
  7. package/builtin/session/mcp-client.mjs +7 -3
  8. package/builtin/session/session-runs.mjs +5 -1
  9. package/builtin/session/skill-validation.mjs +72 -0
  10. package/builtin/session/space-layout.mjs +8 -1
  11. package/builtin/session/space-skills.mjs +758 -0
  12. package/cli/data-root.mjs +21 -4
  13. package/cli/lantern.mjs +26 -1
  14. package/cli/mcp-server.mjs +3733 -0
  15. package/cli/server.mjs +10 -2
  16. package/config/app.defaults.json +4 -2
  17. package/dist/500.html +14 -6
  18. package/dist/_astro/Base.BQf1tZMl.css +1 -0
  19. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.Dm3O_y-S.js +2 -0
  20. package/dist/_astro/BusinessMapBoard.CYxHcku_.js +5 -0
  21. package/dist/_astro/CaseExecBoard.CK9aGPmH.js +1 -0
  22. package/dist/_astro/CaseExecutionBoard.C94pmIMQ.js +5 -0
  23. package/dist/_astro/CaseGenerateApp.D5xlk9At.js +10 -0
  24. package/dist/_astro/CasesLibrary.BHQC955x.js +21 -0
  25. package/dist/_astro/ChatApp.CIt15w_1.js +1 -0
  26. package/dist/_astro/ChatApp.d4a9R3YS.js +262 -0
  27. package/dist/_astro/{ConfirmDialog.DrrPf1MB.js → ConfirmDialog.DQFd6g2r.js} +1 -1
  28. package/dist/_astro/DashboardBoard.qgc1s7pG.js +5 -0
  29. package/dist/_astro/{DatePicker.Bkl71M49.js → DatePicker.BRO_CjVQ.js} +1 -1
  30. package/dist/_astro/DefectSubmitEntry.JI85N1-i.js +2 -0
  31. package/dist/_astro/DocsFileBrowser.z5JZ74cy.js +1 -0
  32. package/dist/_astro/{DocsPager.Duf4I68E.js → DocsPager.Dg765uHW.js} +1 -1
  33. package/dist/_astro/{DrawerField.BH3p4Q4D.js → DrawerField.CLdvmHc6.js} +1 -1
  34. package/dist/_astro/KnowledgeLibrary.mkShtVun.js +1 -0
  35. package/dist/_astro/LifeKrTasksBoard.DpAwQffE.js +1 -0
  36. package/dist/_astro/LifeKrTodosBoard.BIjPiZ8H.js +1 -0
  37. package/dist/_astro/LifeObjectivesBoard.DYwLHPEG.js +1 -0
  38. package/dist/_astro/LifePlanTypeSelect.CYaziESp.js +1 -0
  39. package/dist/_astro/{LifeReviewsBoard.BPXeVpg1.js → LifeReviewsBoard.DIxoWBDA.js} +3 -3
  40. package/dist/_astro/{LifeShared.tnT7aQON.js → LifeShared.DuFQsMEx.js} +2 -2
  41. package/dist/_astro/LifeStagesBoard.DtOri9EW.js +1 -0
  42. package/dist/_astro/LifeYearCycleSelect.ByJ9-PGg.js +1 -0
  43. package/dist/_astro/LifeYearPlansBoard.BQN07wcv.js +1 -0
  44. package/dist/_astro/MultiSelectDropdown.D-rbpivp.js +1 -0
  45. package/dist/_astro/{NamePromptDialog.Csfnh5eM.js → NamePromptDialog.KPCeXmri.js} +1 -1
  46. package/dist/_astro/NavLibraries.BO4ezcUc.js +1 -0
  47. package/dist/_astro/PluginsPage.B1VeDtLx.js +18 -0
  48. package/dist/_astro/PmBugsBoard.Ddl3kqqt.js +1 -0
  49. package/dist/_astro/PmIterationsBoard.BJN7disI.js +1 -0
  50. package/dist/_astro/{PmProjectDetail.DneFVBpy.js → PmProjectDetail.D78gWhqk.js} +1 -1
  51. package/dist/_astro/PmProjectsBoard.Bf8VB3t6.js +1 -0
  52. package/dist/_astro/PmRequirementsBoard.CDyNHN2a.js +1 -0
  53. package/dist/_astro/PmRequirementsBoard.DarfGIrL.js +1 -0
  54. package/dist/_astro/PmShared.TOjBbtV8.js +1 -0
  55. package/dist/_astro/ReportsPage.BXGduuY3.js +1 -0
  56. package/dist/_astro/ReqAnalysisBoard.WLtIfBg8.js +39 -0
  57. package/dist/_astro/RequirementBreakdownLibrary.DMoeTeqX.js +2 -0
  58. package/dist/_astro/RequirementsLibrary.Iv7zOqWe.js +1 -0
  59. package/dist/_astro/SearchableSelect.DXclLMJI.js +1 -0
  60. package/dist/_astro/SelectDropdown.D7IeyHDI.js +1 -0
  61. package/dist/_astro/SettingsDialog.BvDU9EU6.js +1 -0
  62. package/dist/_astro/SlideOverDrawer.CvyB-quk.js +1 -0
  63. package/dist/_astro/SpaceSwitcher.D9bBNQBZ.js +7 -0
  64. package/dist/_astro/{TableFieldConfig.C7O-mL-p.js → TableFieldConfig.DHj25OKN.js} +1 -1
  65. package/dist/_astro/{TagSelect.UUXgkMqJ.js → TagSelect.B_r2p0fp.js} +1 -1
  66. package/dist/_astro/TasksBoard.CXmGdylV.js +1 -0
  67. package/dist/_astro/TemplatesLibrary.DsL2q-wp.js +1 -0
  68. package/dist/_astro/TestReportsLibrary.BBC1TYgP.js +1 -0
  69. package/dist/_astro/TestStatsBoard.VXjP4hu6.js +1 -0
  70. package/dist/_astro/Toast.BydY-X7T.js +1 -0
  71. package/dist/_astro/TodosBoard.-yKgp06M.js +1 -0
  72. package/dist/_astro/UiAutoBoard.BD5ZyLHj.js +3 -0
  73. package/dist/_astro/UiAutoEnvPanel.DrHUOlmH.js +10 -0
  74. package/dist/_astro/UiAutoGenerationDialog.gypq1zP9.js +12 -0
  75. package/dist/_astro/UiAutoProjectsPage.Dhzr09E9.js +3 -0
  76. package/dist/_astro/app-config.BSO5r82v.js +1 -0
  77. package/dist/_astro/app-version.CkDFkv4s.js +1 -0
  78. package/dist/_astro/{bash-tools.D9HCzC_7.js → bash-tools.C4DJiRJs.js} +1 -1
  79. package/dist/_astro/business-map.BiJ85oxm.js +1 -0
  80. package/dist/_astro/business-map.DKwdW1VL.css +1 -0
  81. package/dist/_astro/case-fields.C03NY3zC.js +148 -0
  82. package/dist/_astro/case-gen-run.C4p8uyU3.js +26 -0
  83. package/dist/_astro/case-prompt.ByLTgz4r.js +2 -0
  84. package/dist/_astro/{case-review.TdDs1WFM.js → case-review.BodP2jKm.js} +2 -2
  85. package/dist/_astro/{case-template.Cd2xNbgy.js → case-template.CC2eXegU.js} +2 -2
  86. package/dist/_astro/case-types.BjF1BivA.js +1 -0
  87. package/dist/_astro/case-workflow-contract.BBQ9bbKL.js +1 -0
  88. package/dist/_astro/defect-submit.Dc49lFjm.css +1 -0
  89. package/dist/_astro/defect-workbench.DBmohR-y.js +6 -0
  90. package/dist/_astro/dialog.XgRGNF_Q.js +1 -0
  91. package/dist/_astro/doc-roots.C-20VD0x.js +1 -0
  92. package/dist/_astro/{hydrate-cache.B15Nrpq0.js → hydrate-cache.CMMErx63.js} +1 -1
  93. package/dist/_astro/i18n.CEWjL5GX.js +7 -0
  94. package/dist/_astro/{llm.DN5S1KBK.js → llm.BCYNgppW.js} +1 -1
  95. package/dist/_astro/mcp-tools.Kf-lupGn.js +7 -0
  96. package/dist/_astro/{open-docs-in-session.CRiZT022.js → open-docs-in-session.BoyV6R2A.js} +1 -1
  97. package/dist/_astro/plugins.ChGmBEkF.js +1 -0
  98. package/dist/_astro/project-docs.BRgNjXhG.js +1 -0
  99. package/dist/_astro/prompts-meta.VAjE4OET.js +2 -0
  100. package/dist/_astro/report-prompt.CwHuOcRN.js +1 -0
  101. package/dist/_astro/req-analysis.BLvcktvQ.js +31 -0
  102. package/dist/_astro/requirement-breakdown-library.l0rPd7b3.js +1 -0
  103. package/dist/_astro/{settings.38J2uD5M.js → settings.BojKNwUC.js} +2 -2
  104. package/dist/_astro/space-skills.CPucW8zt.js +1 -0
  105. package/dist/_astro/{spaces-client.DV04tRyD.js → spaces-client.B28rzu8J.js} +1 -1
  106. package/dist/_astro/story-review.dEBWTeOW.js +7 -0
  107. package/dist/_astro/test-points.BuNgdNcU.js +8 -0
  108. package/dist/_astro/test-reports.0gr6-c_0.js +19 -0
  109. package/dist/_astro/ui-auto-prompt.BmO3ja2m.js +8 -0
  110. package/dist/_astro/ui-auto.LUcREUMe.js +1 -0
  111. package/dist/_astro/{view-prefs.DhdLZjGh.js → view-prefs.CWc5cQ2q.js} +1 -1
  112. package/dist/business-map/index.html +988 -0
  113. package/dist/case-exec/index.html +15 -7
  114. package/dist/{prompts → case-execution}/index.html +17 -9
  115. package/dist/cases/api/index.html +988 -0
  116. package/dist/cases/automation/index.html +988 -0
  117. package/dist/cases/functional/index.html +988 -0
  118. package/dist/cases/generate/index.html +14 -6
  119. package/dist/cases/index.html +1 -1
  120. package/dist/cases/library/index.html +1 -980
  121. package/dist/cases/other/index.html +988 -0
  122. package/dist/cases/performance/index.html +988 -0
  123. package/dist/dashboard/index.html +15 -7
  124. package/dist/defect-rules/index.html +695 -0
  125. package/dist/defect-submit/index.html +695 -0
  126. package/dist/defect-submit/templates/index.html +695 -0
  127. package/dist/docs/changelog/index.html +289 -52
  128. package/dist/docs/install/index.html +50 -12
  129. package/dist/docs/manual/index.html +230 -82
  130. package/dist/knowledge/index.html +15 -7
  131. package/dist/life/kr-tasks/index.html +15 -7
  132. package/dist/life/kr-todos/index.html +15 -7
  133. package/dist/life/objectives/index.html +15 -7
  134. package/dist/life/reviews/index.html +15 -7
  135. package/dist/life/stages/index.html +15 -7
  136. package/dist/life/year-plans/index.html +15 -7
  137. package/dist/plugins/index.html +15 -7
  138. package/dist/pm/bugs/index.html +15 -7
  139. package/dist/pm/iterations/index.html +15 -7
  140. package/dist/pm/projects/detail/index.html +15 -7
  141. package/dist/pm/projects/index.html +15 -7
  142. package/dist/pm/requirements/index.html +15 -7
  143. package/dist/reports/index.html +15 -7
  144. package/dist/requirement-analysis/index.html +15 -7
  145. package/dist/requirement-breakdowns/index.html +988 -0
  146. package/dist/requirements/index.html +15 -7
  147. package/dist/tasks/index.html +15 -7
  148. package/dist/templates/index.html +15 -7
  149. package/dist/test-automation/index.html +15 -7
  150. package/dist/test-automation/projects/index.html +15 -7
  151. package/dist/test-reports/index.html +15 -7
  152. package/dist/test-stats/index.html +15 -7
  153. package/dist/todos/index.html +15 -7
  154. package/dist/workbench/index.html +14 -6
  155. package/docs/Codex-MCP/351/233/206/346/210/220.md +340 -0
  156. package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/204/344/274/260.md +39 -0
  157. 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
  158. package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +28 -3
  159. package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +41 -1
  160. package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +65 -17
  161. 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
  162. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +219 -74
  163. package/lh-plugins/business-map/assistant.mjs +958 -0
  164. package/lh-plugins/business-map/auth-paths.mjs +61 -0
  165. package/lh-plugins/business-map/jobs.mjs +749 -0
  166. package/lh-plugins/business-map/login.mjs +295 -0
  167. package/lh-plugins/business-map/sources.mjs +1014 -0
  168. package/lh-plugins/case-automation/service.mjs +921 -0
  169. package/lh-plugins/case-automation/store.mjs +231 -0
  170. package/lh-plugins/case-automation/tables.mjs +115 -0
  171. package/lh-plugins/case-automation-prompt.mjs +57 -0
  172. package/lh-plugins/case-execution/assets.mjs +180 -0
  173. package/lh-plugins/case-execution/files.mjs +829 -0
  174. package/lh-plugins/case-execution/plans.mjs +318 -0
  175. package/lh-plugins/case-execution/service.mjs +1026 -0
  176. package/lh-plugins/case-execution-prompt.mjs +36 -0
  177. package/lh-plugins/lh-business-map.mjs +2431 -0
  178. package/lh-plugins/lh-case-automation.mjs +169 -0
  179. package/lh-plugins/lh-case-design.mjs +456 -0
  180. package/lh-plugins/lh-case-execution.mjs +356 -0
  181. package/lh-plugins/lh-case-review.mjs +29 -11
  182. package/lh-plugins/lh-config.mjs +13 -0
  183. package/lh-plugins/lh-defect-submit.mjs +989 -0
  184. package/lh-plugins/lh-project-docs.mjs +55 -140
  185. package/lh-plugins/lh-reports.mjs +29 -57
  186. package/lh-plugins/lh-req-analysis.mjs +32 -3
  187. package/lh-plugins/lh-req-breakdown-library.mjs +1084 -0
  188. package/lh-plugins/lh-uiauto.mjs +625 -24
  189. package/lh-plugins/plugin-prompts.mjs +20 -15
  190. package/lh-plugins/req-analysis-revision.mjs +24 -0
  191. package/lh-plugins/test-points-prompt.mjs +2 -3
  192. package/lh-plugins/uiauto-adapters/playwright.mjs +44 -4
  193. package/lh-plugins/uiauto-adapters/shared.mjs +4 -0
  194. package/lh-plugins/uiauto-auth-setup.mjs +218 -0
  195. package/lh-plugins/uiauto-explorer/apps.mjs +13 -2
  196. package/lh-plugins/uiauto-explorer/emit-files.mjs +16 -2
  197. package/lh-plugins/uiauto-explorer/ir.mjs +3 -0
  198. package/lh-plugins/uiauto-explorer/merge.mjs +37 -1
  199. package/lh-plugins/uiauto-explorer/navigation-guard.mjs +255 -0
  200. package/lh-plugins/uiauto-explorer/runner.mjs +80 -5
  201. package/lh-plugins/uiauto-explorer/sessions.mjs +334 -18
  202. package/lh-plugins/uiauto-node.mjs +102 -11
  203. package/lh-plugins/uiauto-prompt.mjs +20 -15
  204. package/lh-plugins/uiauto-sso.mjs +407 -0
  205. package/package.json +5 -2
  206. package/skills/case-automation-bridge/SKILL.md +27 -0
  207. package/skills/case-execution/SKILL.md +41 -0
  208. package/skills/lantern-defect-submit/SKILL.md +15 -0
  209. package/skills/lantern-workflow/SKILL.md +95 -0
  210. package/skills/office/SKILL.md +26 -0
  211. package/dist/_astro/Base.Bkt1lrgu.css +0 -1
  212. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.UKTVQqk7.js +0 -2
  213. package/dist/_astro/CaseExecBoard.DICluCbK.js +0 -1
  214. package/dist/_astro/CaseGenerateApp.Be3h5XPG.js +0 -10
  215. package/dist/_astro/CasesLibrary.Buys7Cy-.js +0 -21
  216. package/dist/_astro/ChatApp.D3BheKci.js +0 -227
  217. package/dist/_astro/DashboardBoard.Qvf8o4v1.js +0 -5
  218. package/dist/_astro/DocsFileBrowser.DwKBffbM.js +0 -1
  219. package/dist/_astro/KnowledgeLibrary.MDpMqeOd.js +0 -1
  220. package/dist/_astro/LifeKrTasksBoard.DsvW_S66.js +0 -1
  221. package/dist/_astro/LifeKrTodosBoard.D2KTqvg1.js +0 -1
  222. package/dist/_astro/LifeObjectivesBoard.B0cDK934.js +0 -1
  223. package/dist/_astro/LifePlanTypeSelect.BELDvMWU.js +0 -1
  224. package/dist/_astro/LifeStagesBoard.CZftLR9K.js +0 -1
  225. package/dist/_astro/LifeYearCycleSelect.Bw2eRbSm.js +0 -1
  226. package/dist/_astro/LifeYearPlansBoard.DB-RJFEl.js +0 -1
  227. package/dist/_astro/MultiSelectDropdown.CBC7aNOv.js +0 -1
  228. package/dist/_astro/NavLibraries.DdQYsZbe.js +0 -1
  229. package/dist/_astro/OverflowHint.CHZeFfUj.js +0 -1
  230. package/dist/_astro/PluginsPage.C1JnInH4.js +0 -17
  231. package/dist/_astro/PluginsPage.C3eEwy3K.js +0 -1
  232. package/dist/_astro/PmBugsBoard.CGpXUTPu.js +0 -1
  233. package/dist/_astro/PmIterationsBoard.BaKiFIam.js +0 -1
  234. package/dist/_astro/PmProjectsBoard.BxoMF9gK.js +0 -1
  235. package/dist/_astro/PmRequirementsBoard.-SI8VZXI.js +0 -1
  236. package/dist/_astro/PmRequirementsBoard.DsK6RF7Q.js +0 -1
  237. package/dist/_astro/PmShared.BK8kWRSV.js +0 -1
  238. package/dist/_astro/PromptMountDialog.mrTx3U5T.js +0 -1
  239. package/dist/_astro/PromptsLibrary.B_SUf47p.js +0 -1
  240. package/dist/_astro/ReportsPage.B9lGg1_s.js +0 -16
  241. package/dist/_astro/ReqAnalysisBoard.CIZKnCQH.js +0 -39
  242. package/dist/_astro/RequirementsLibrary.cJc-bnGQ.js +0 -1
  243. package/dist/_astro/SearchableSelect.SyLRS-Jj.js +0 -1
  244. package/dist/_astro/SelectDropdown.T3CKHaLt.js +0 -1
  245. package/dist/_astro/SettingsDialog.DYdtCvLc.js +0 -1
  246. package/dist/_astro/SpaceSwitcher.C47_S1g9.js +0 -7
  247. package/dist/_astro/TasksBoard.BUEg2BYk.js +0 -1
  248. package/dist/_astro/TemplatesLibrary.BLVIphXO.js +0 -1
  249. package/dist/_astro/TestReportsLibrary.DVq30Jae.js +0 -1
  250. package/dist/_astro/TestStatsBoard.-5BWQ6bI.js +0 -1
  251. package/dist/_astro/Toast.BO2NFckG.js +0 -1
  252. package/dist/_astro/TodosBoard.DI_lTp2e.js +0 -1
  253. package/dist/_astro/UiAutoBoard.ChFdgv7s.js +0 -2
  254. package/dist/_astro/UiAutoEnvPanel.B50q4kYb.js +0 -19
  255. package/dist/_astro/UiAutoGenerationDialog.CLkFAHrm.js +0 -1
  256. package/dist/_astro/UiAutoProjectsPage.DCsDeN5d.js +0 -3
  257. package/dist/_astro/app-config.DkyjuL-S.js +0 -1
  258. package/dist/_astro/app-version.Cy-5oZO2.js +0 -1
  259. package/dist/_astro/case-fields.CmePqYfh.js +0 -148
  260. package/dist/_astro/case-gen-run.BklG1H8k.js +0 -22
  261. package/dist/_astro/case-types.DlFkbZJN.js +0 -1
  262. package/dist/_astro/dialog.DZHZCe_T.js +0 -1
  263. package/dist/_astro/doc-roots.CO3IBiY6.js +0 -1
  264. package/dist/_astro/i18n.D_aOCHSN.js +0 -7
  265. package/dist/_astro/markdown-client.BS19nLL3.js +0 -62
  266. package/dist/_astro/plugins.BRvXWHLe.js +0 -1
  267. package/dist/_astro/project-docs.CCjtiFjB.js +0 -1
  268. package/dist/_astro/prompts-meta.BUGutlsk.js +0 -2
  269. package/dist/_astro/report-prompt.B9C4cv84.js +0 -1
  270. package/dist/_astro/req-analysis.B12_MGMQ.js +0 -31
  271. package/dist/_astro/story-review.D2W5tEOY.js +0 -14
  272. package/dist/_astro/test-reports.CuIjlEyK.js +0 -19
  273. package/dist/_astro/ui-auto-prompt.H9_yhau9.js +0 -9
  274. package/dist/_astro/ui-auto.DMv940x4.js +0 -1
@@ -0,0 +1,356 @@
1
+ import {
2
+ createExecutionPlan,
3
+ listExecutionPlans,
4
+ getExecutionPlan,
5
+ startExecutionPlan,
6
+ stopExecutionPlan,
7
+ verifyExecutionPlanItem,
8
+ } from './case-execution/plans.mjs';
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+
12
+ import { getDataRoot } from '../builtin/session/space-context.mjs';
13
+ import {
14
+ CASE_EXECUTION_PROMPT_FILE,
15
+ CASE_EXECUTION_PROMPT_TEMPLATE,
16
+ } from './case-execution-prompt.mjs';
17
+ import {
18
+ applyManualResult,
19
+ cancelManualLogin,
20
+ completeManualLogin,
21
+ confirmRun,
22
+ getRun,
23
+ listExecutionRuns,
24
+ savedAuthFor,
25
+ shotPath,
26
+ startManualLogin,
27
+ startRun,
28
+ stopRun,
29
+ subscribeRun,
30
+ } from './case-execution/service.mjs';
31
+ import {
32
+ applyCaseFieldUpdates,
33
+ prepareExecutionColumns,
34
+ listCaseDocuments,
35
+ loadCaseDocument,
36
+ } from './case-execution/files.mjs';
37
+ import { ensurePluginPrompt, isPluginOnInSpace } from './plugin-prompts.mjs';
38
+ import { automationSummaryForCase } from './case-automation/store.mjs';
39
+ import { refreshAutomationLinks } from './case-automation/service.mjs';
40
+
41
+ const PREFIX = '/__tb_case_run';
42
+
43
+ function sendJson(res, status, body) {
44
+ res.statusCode = status;
45
+ res.setHeader('Content-Type', 'application/json; charset=utf-8');
46
+ res.setHeader('Cache-Control', 'no-store');
47
+ res.end(JSON.stringify(body));
48
+ }
49
+
50
+ function readBody(req) {
51
+ return new Promise((resolve, reject) => {
52
+ const chunks = [];
53
+ let size = 0;
54
+ req.on('data', (chunk) => {
55
+ size += chunk.length;
56
+ if (size > 2 * 1024 * 1024) {
57
+ reject(Object.assign(new Error('请求内容过大'), { statusCode: 413 }));
58
+ req.destroy();
59
+ return;
60
+ }
61
+ chunks.push(Buffer.from(chunk));
62
+ });
63
+ req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
64
+ req.on('error', reject);
65
+ });
66
+ }
67
+
68
+ function sameOrigin(req) {
69
+ if (!req.headers.origin) return true;
70
+ try {
71
+ return new URL(req.headers.origin).host === req.headers.host;
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ async function statsRequest(host, route = '', init = {}) {
78
+ const response = await fetch(`http://${host}/__tb_case_exec${route}`, {
79
+ ...init,
80
+ headers: {
81
+ ...(init.body ? { 'Content-Type': 'application/json' } : {}),
82
+ ...(init.headers || {}),
83
+ },
84
+ signal: AbortSignal.timeout(15_000),
85
+ });
86
+ const data = await response.json().catch(() => ({}));
87
+ if (!response.ok) {
88
+ throw Object.assign(new Error(data.error || `用例执行统计 HTTP ${response.status}`), {
89
+ statusCode: response.status,
90
+ });
91
+ }
92
+ return data;
93
+ }
94
+
95
+ async function syncStats(root, host, raw) {
96
+ const casePath = String(raw.casePath || '').trim();
97
+ const project = String(raw.project || '').trim();
98
+ const date = String(raw.date || '').trim();
99
+ const mode = raw.mode === 'overwrite' ? 'overwrite' : raw.mode === 'skip' ? 'skip' : 'preview';
100
+ if (!casePath) throw Object.assign(new Error('缺少用例文件路径'), { statusCode: 400 });
101
+ if (!project) throw Object.assign(new Error('请选择统计项目'), { statusCode: 400 });
102
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
103
+ throw Object.assign(new Error('统计日期格式无效'), { statusCode: 400 });
104
+ }
105
+ const document = await loadCaseDocument(root, casePath);
106
+ const completedStatuses = new Set(['通过', '不通过', '阻塞', '跳过']);
107
+ const executed = document.cases.filter((item) => {
108
+ const status = String(item.status || '').trim();
109
+ return (
110
+ completedStatuses.has(status) ||
111
+ /^(p|pass|passed|ok|成功|true|1|f|fail|failed|失败|false|0)$/i.test(status) ||
112
+ /block|skip|n\/?a/i.test(status)
113
+ );
114
+ }).length;
115
+ const total = document.cases.length;
116
+ const pending = Math.max(0, total - executed);
117
+ const current = await statsRequest(host);
118
+ const existing = (current.items || []).find(
119
+ (item) => item.project === project && item.date === date,
120
+ );
121
+ const preview = {
122
+ casePath,
123
+ project,
124
+ date,
125
+ total,
126
+ executed,
127
+ pending,
128
+ existing: existing || null,
129
+ };
130
+ if (mode === 'preview') return { ok: true, preview };
131
+ if (existing && mode === 'skip') {
132
+ return { ok: true, preview, skipped: true, item: existing };
133
+ }
134
+ if (existing) {
135
+ const data = await statsRequest(host, '', {
136
+ method: 'PUT',
137
+ body: JSON.stringify({
138
+ id: existing.id,
139
+ total,
140
+ pending,
141
+ executed,
142
+ }),
143
+ });
144
+ return { ok: true, preview, overwritten: true, item: data.item };
145
+ }
146
+ const data = await statsRequest(host, '', {
147
+ method: 'POST',
148
+ body: JSON.stringify({
149
+ mode: 'manual',
150
+ items: [
151
+ {
152
+ date,
153
+ project,
154
+ startDate: date,
155
+ endDate: date,
156
+ total,
157
+ pending,
158
+ executed,
159
+ },
160
+ ],
161
+ }),
162
+ });
163
+ return {
164
+ ok: true,
165
+ preview,
166
+ item: (data.items || []).find((item) => item.project === project && item.date === date) || null,
167
+ };
168
+ }
169
+
170
+ export function lhCaseExecutionPlugin() {
171
+ return {
172
+ name: 'lh-case-execution',
173
+ configureServer(server) {
174
+ server.middlewares.use(async (req, res, next) => {
175
+ const parsed = new URL(req.url || '/', 'http://127.0.0.1');
176
+ if (!parsed.pathname.startsWith(PREFIX)) return next();
177
+ const tail = parsed.pathname.slice(PREFIX.length) || '/';
178
+ const method = req.method || 'GET';
179
+ try {
180
+ const root = getDataRoot();
181
+ const enabled = isPluginOnInSpace('caseExecution', root);
182
+ if (enabled) {
183
+ ensurePluginPrompt(CASE_EXECUTION_PROMPT_FILE, CASE_EXECUTION_PROMPT_TEMPLATE, root);
184
+ }
185
+ if (parsed.pathname === `${PREFIX}/health` && parsed.searchParams.get('health') === '1') {
186
+ return sendJson(res, 200, { ok: true, enabled });
187
+ }
188
+ if (!enabled) {
189
+ return sendJson(res, 403, {
190
+ ok: false,
191
+ error: '请先在插件仓库开启「用例执行」',
192
+ });
193
+ }
194
+ if (!sameOrigin(req) && method !== 'GET') {
195
+ return sendJson(res, 403, {
196
+ ok: false,
197
+ error: '用例执行请求必须来自当前 Lantern 页面',
198
+ });
199
+ }
200
+
201
+ if (method === 'GET' && tail === '/plans')
202
+ return sendJson(res, 200, {
203
+ ok: true,
204
+ plans: listExecutionPlans(root, parsed.searchParams.get('path') || ''),
205
+ });
206
+ if (method === 'POST' && tail === '/plans')
207
+ return sendJson(res, 200, {
208
+ ok: true,
209
+ plan: await createExecutionPlan(root, JSON.parse((await readBody(req)) || '{}')),
210
+ });
211
+ if (tail.startsWith('/plans/')) {
212
+ const id = tail.split('/')[2];
213
+ if (method === 'POST' && tail.endsWith('/result'))
214
+ return sendJson(
215
+ res,
216
+ 200,
217
+ await verifyExecutionPlanItem(root, id, JSON.parse((await readBody(req)) || '{}')),
218
+ );
219
+ if (method === 'GET')
220
+ return sendJson(res, 200, { ok: true, plan: getExecutionPlan(root, id) });
221
+ if (method === 'POST' && tail.endsWith('/start'))
222
+ return sendJson(res, 200, { ok: true, plan: startExecutionPlan(root, id) });
223
+ if (method === 'POST' && tail.endsWith('/stop'))
224
+ return sendJson(res, 200, { ok: true, plan: stopExecutionPlan(root, id) });
225
+ }
226
+ if (method === 'GET' && tail === '/files') {
227
+ return sendJson(res, 200, {
228
+ ok: true,
229
+ files: await listCaseDocuments(root),
230
+ });
231
+ }
232
+ if (method === 'GET' && tail === '/cases') {
233
+ const document = await loadCaseDocument(
234
+ root,
235
+ String(parsed.searchParams.get('path') || ''),
236
+ );
237
+ refreshAutomationLinks(root, document);
238
+ const { _parsed, _map, abs, ...publicDocument } = document;
239
+ return sendJson(res, 200, {
240
+ ok: true,
241
+ document: {
242
+ ...publicDocument,
243
+ cases: publicDocument.cases.map((item) => ({
244
+ ...item,
245
+ automation: automationSummaryForCase(root, publicDocument.path, item.id),
246
+ })),
247
+ },
248
+ });
249
+ }
250
+ if (method === 'GET' && tail === '/runs') {
251
+ return sendJson(res, 200, {
252
+ ok: true,
253
+ runs: listExecutionRuns(root, parsed.searchParams.get('path') || ''),
254
+ });
255
+ }
256
+ if (method === 'GET' && tail.startsWith('/runs/') && tail.endsWith('/events')) {
257
+ const runId = tail.split('/')[2];
258
+ return subscribeRun(root, runId, Number(parsed.searchParams.get('after') || 0), res);
259
+ }
260
+ if (method === 'GET' && tail.startsWith('/runs/') && tail.includes('/shots/')) {
261
+ const parts = tail.split('/');
262
+ const file = decodeURIComponent(parts[4] || '');
263
+ const abs = shotPath(root, parts[2], file);
264
+ if (!fs.existsSync(abs)) return sendJson(res, 404, { ok: false, error: '截图不存在' });
265
+ res.statusCode = 200;
266
+ res.setHeader('Content-Type', 'image/png');
267
+ res.setHeader('Cache-Control', 'no-store');
268
+ return fs.createReadStream(abs).pipe(res);
269
+ }
270
+ if (method === 'GET' && tail.startsWith('/runs/')) {
271
+ return sendJson(res, 200, {
272
+ ok: true,
273
+ run: getRun(root, tail.split('/')[2] || ''),
274
+ });
275
+ }
276
+ if (method === 'GET' && tail === '/auth/status') {
277
+ return sendJson(res, 200, {
278
+ ok: true,
279
+ ...savedAuthFor(root, { url: parsed.searchParams.get('url') || '' }),
280
+ });
281
+ }
282
+ if (method === 'POST' && tail === '/auth/start') {
283
+ return sendJson(
284
+ res,
285
+ 200,
286
+ await startManualLogin(root, JSON.parse((await readBody(req)) || '{}')),
287
+ );
288
+ }
289
+ if (method === 'POST' && tail === '/auth/complete') {
290
+ return sendJson(res, 200, await completeManualLogin(root));
291
+ }
292
+ if (method === 'POST' && tail === '/auth/cancel') {
293
+ return sendJson(res, 200, await cancelManualLogin(root));
294
+ }
295
+ if (method === 'POST' && tail === '/runs') {
296
+ const body = JSON.parse((await readBody(req)) || '{}');
297
+ return sendJson(res, 202, { ok: true, run: await startRun(root, body) });
298
+ }
299
+ if (method === 'POST' && tail.startsWith('/runs/') && tail.endsWith('/stop')) {
300
+ return sendJson(res, 200, {
301
+ ok: true,
302
+ run: stopRun(root, tail.split('/')[2] || ''),
303
+ });
304
+ }
305
+ if (method === 'POST' && tail.startsWith('/runs/') && tail.endsWith('/apply')) {
306
+ const body = JSON.parse((await readBody(req)) || '{}');
307
+ return sendJson(res, 200, {
308
+ ok: true,
309
+ ...(await confirmRun(root, tail.split('/')[2] || '', body)),
310
+ });
311
+ }
312
+ if (method === 'POST' && tail === '/manual') {
313
+ const body = JSON.parse((await readBody(req)) || '{}');
314
+ return sendJson(res, 200, {
315
+ ok: true,
316
+ applied: await applyManualResult(root, body),
317
+ });
318
+ }
319
+ if (method === 'POST' && tail === '/prepare-columns')
320
+ return sendJson(
321
+ res,
322
+ 200,
323
+ await prepareExecutionColumns(root, JSON.parse((await readBody(req)) || '{}')),
324
+ );
325
+ if (method === 'POST' && tail === '/fields') {
326
+ const body = JSON.parse((await readBody(req)) || '{}');
327
+ return sendJson(res, 200, {
328
+ ok: true,
329
+ applied: await applyCaseFieldUpdates(root, {
330
+ path: body.casePath,
331
+ expectedFileHash: body.expectedFileHash,
332
+ rowIndex: body.rowIndex,
333
+ updates: body.updates,
334
+ }),
335
+ });
336
+ }
337
+ if (method === 'POST' && tail === '/stats/sync') {
338
+ const body = JSON.parse((await readBody(req)) || '{}');
339
+ return sendJson(
340
+ res,
341
+ 200,
342
+ await syncStats(root, req.headers.host || '127.0.0.1:4321', body),
343
+ );
344
+ }
345
+ return sendJson(res, 404, { ok: false, error: '接口不存在' });
346
+ } catch (error) {
347
+ return sendJson(res, Number(error?.statusCode) || 500, {
348
+ ok: false,
349
+ error: error instanceof Error ? error.message : String(error),
350
+ ...(error?.currentHash ? { currentHash: error.currentHash } : {}),
351
+ });
352
+ }
353
+ });
354
+ },
355
+ };
356
+ }
@@ -17,6 +17,11 @@ import path from 'node:path';
17
17
 
18
18
  import { getDataRoot } from '../builtin/session/space-context.mjs';
19
19
  import { resolveContentRoot, spaceLocalFile } from '../builtin/session/space-layout.mjs';
20
+ import {
21
+ CASE_BACKUP_DIR_NAME,
22
+ backupDirectoryForCasePath,
23
+ isCaseBackupPath,
24
+ } from '../builtin/case-backup-contract.mjs';
20
25
  import { ensurePluginPrompt, isPluginOnInSpace, readPluginPrompt } from './plugin-prompts.mjs';
21
26
  import {
22
27
  BLINDSPOT_PROMPT_FILE,
@@ -37,9 +42,6 @@ export const CASE_REVIEW_STORE_FILE = '用例评审.json';
37
42
 
38
43
  /** 用例文件根目录(与 lh-project-docs 的 DOC_ROOT_DIRS.cases.dirName 一致) */
39
44
  const CASES_DIR_NAME = '用例管理';
40
- /** 用例管理下的备份文件夹(与前端 CASE_BACKUP_DIR_NAME 一致;首次备份才创建) */
41
- const CASE_BACKUP_DIR_NAME = '备份列表';
42
-
43
45
  const VERDICTS = ['usable', 'revise', 'invalid'];
44
46
  const DIMENSION_KEYS = ['coverage', 'steps', 'expected', 'data', 'convention'];
45
47
  const BLINDSPOT_CATEGORIES = ['nonfunctional', 'security', 'compatibility', 'business'];
@@ -284,9 +286,9 @@ function legacyReviewBackupDir(root) {
284
286
  return spaceLocalFile(root, 'case-review/backup');
285
287
  }
286
288
 
287
- /** 用例管理/备份列表(相对 cases 根) */
288
- function casesBackupDirAbs(root) {
289
- return path.join(resolveContentRoot(root, CASES_DIR_NAME).abs, CASE_BACKUP_DIR_NAME);
289
+ /** 按用例所属类型返回备份目录;根目录历史文件仍写根备份列表。 */
290
+ function casesBackupDirAbs(root, backupRelDir = CASE_BACKUP_DIR_NAME) {
291
+ return path.join(resolveContentRoot(root, CASES_DIR_NAME).abs, ...backupRelDir.split('/'));
290
292
  }
291
293
 
292
294
  /** 备份文件名:默认用原名(用例名里通常已有时间戳),重名则 stem(2).ext */
@@ -305,7 +307,9 @@ function resolveBackupDest(dir, preferredName) {
305
307
  }
306
308
 
307
309
  function backupCaseFile(root, abs, preferredName) {
308
- const dir = casesBackupDirAbs(root);
310
+ const casesRoot = resolveContentRoot(root, CASES_DIR_NAME).abs;
311
+ const sourceRel = path.relative(casesRoot, abs).split(path.sep).join('/');
312
+ const dir = casesBackupDirAbs(root, backupDirectoryForCasePath(sourceRel));
309
313
  fs.mkdirSync(dir, { recursive: true });
310
314
  const dest = resolveBackupDest(dir, preferredName || path.basename(abs));
311
315
  fs.copyFileSync(abs, dest);
@@ -315,8 +319,16 @@ function backupCaseFile(root, abs, preferredName) {
315
319
  /** 列出备份:用例管理/备份列表 + 历史 .lantern/case-review/backup */
316
320
  function listReviewBackups(root) {
317
321
  const items = [];
318
- const folderDir = casesBackupDirAbs(root);
319
- if (fs.existsSync(folderDir)) {
322
+ const casesRoot = resolveContentRoot(root, CASES_DIR_NAME).abs;
323
+ const typeDirs = fs.existsSync(casesRoot)
324
+ ? fs
325
+ .readdirSync(casesRoot, { withFileTypes: true })
326
+ .filter((entry) => entry.isDirectory() && entry.name !== CASE_BACKUP_DIR_NAME)
327
+ .map((entry) => path.join(casesRoot, entry.name, CASE_BACKUP_DIR_NAME))
328
+ .filter((dir) => fs.existsSync(dir))
329
+ : [];
330
+ const folderDirs = [casesBackupDirAbs(root), ...typeDirs].filter((dir) => fs.existsSync(dir));
331
+ for (const folderDir of folderDirs) {
320
332
  for (const name of fs.readdirSync(folderDir)) {
321
333
  if (!name || name.startsWith('.') || name.includes('/') || name.includes('..')) continue;
322
334
  const abs = path.join(folderDir, name);
@@ -327,7 +339,7 @@ function listReviewBackups(root) {
327
339
  continue;
328
340
  }
329
341
  if (!st.isFile()) continue;
330
- const casesPath = `${CASE_BACKUP_DIR_NAME}/${name}`.replace(/\\/g, '/');
342
+ const casesPath = path.relative(casesRoot, abs).split(path.sep).join('/');
331
343
  items.push({
332
344
  name,
333
345
  path: casesPath,
@@ -685,6 +697,12 @@ async function reviewRoutes(req, res, root, tail, query) {
685
697
  const rel = text(body.path, 400);
686
698
  if (!rel) return sendJson(res, 400, { ok: false, error: '缺少用例文件路径' });
687
699
  const abs = caseFileAbs(root, rel);
700
+ if (
701
+ body.expectedHash &&
702
+ body.expectedHash !== hashOfFile(abs) &&
703
+ body.expectedHash !== crypto.createHash('sha256').update(fs.readFileSync(abs)).digest('hex')
704
+ )
705
+ return sendJson(res, 409, { ok: false, error: '用例文件已变化,请重新审查' });
688
706
  const store = readStore(root);
689
707
  const idx = store.files.findIndex((x) => x.path === rel);
690
708
  const base =
@@ -727,7 +745,7 @@ async function reviewRoutes(req, res, root, tail, query) {
727
745
  }
728
746
  // 禁止把「备份列表」里的文件再备份进自己
729
747
  const norm = rel.replace(/\\/g, '/');
730
- if (norm === CASE_BACKUP_DIR_NAME || norm.startsWith(`${CASE_BACKUP_DIR_NAME}/`)) {
748
+ if (isCaseBackupPath(norm)) {
731
749
  return sendJson(res, 400, { ok: false, error: '不能备份「备份列表」内的文件' });
732
750
  }
733
751
  const preferred = text(body.name, 200) || path.basename(abs);
@@ -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
  }