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
@@ -2,8 +2,9 @@
2
2
  * 「自动化测试」两份提示词:缺省短种子 + 分段解析。
3
3
  *
4
4
  * 运行时与日常维护以空间「提示词管理」里的文件为准;增删改只改那里。
5
- * - `自动化执行提示词.md`:生成用例(规划 / 探索 / 出码),「自动化执行」入口用;
5
+ * - `自动化执行提示词.md`:脚本编排(规划 → 确认并探索 → 出码),「自动化执行」入口用;
6
6
  * - `自动化项目提示词.md`:新建项目时给骨架做体检与补全,「自动化项目」入口用。
7
+ * 种子与仓库 `提示词示例/自动化执行提示词.md` 应对齐;已有空间文件不会被种子覆盖。
7
8
  */
8
9
 
9
10
  import { UI_AUTO_PROMPT_FILE, UI_AUTO_PROJECT_PROMPT_FILE } from './plugin-prompts.mjs';
@@ -18,9 +19,10 @@ export const SKELETON_SECTION = '项目骨架';
18
19
  /** 缺文件时写入的种子;完整正文请维护空间文件,参考稿见仓库 提示词示例/自动化执行提示词.md */
19
20
  export const UI_AUTO_PROMPT_TEMPLATE = `# 自动化执行提示词
20
21
 
21
- > 由「自动化执行」引用,用来生成用例(规划 / 探索 / 出码)。日常增删改请只改本空间「提示词管理」里的本文件。
22
+ > 由「自动化执行 · 脚本编排」引用。流程是:**规划(对话拆步骤)→ 用户确认并探索(绑定位器)→ 出码**。日常增删改请只改本空间「提示词管理」里的本文件。
22
23
  > 参考稿见仓库 \`提示词示例/自动化执行提示词.md\`。占位符:\`{{project}}\` \`{{dir}}\` \`{{kind}}\` \`{{language}}\` \`{{plan}}\`(只在前两段生效)。
23
24
  > 平台只读下面四个 \`##\` 段(项目骨架 / 规划阶段 / 探索阶段 / 生成代码),其它标题下的内容不会进模型,别把要求写在段外。
25
+ > 用户在编排会话里描述需求时,仍属「规划阶段」:只拆步骤,不要当成「立刻写用例并跑通」。
24
26
 
25
27
  ## 项目骨架
26
28
 
@@ -55,7 +57,8 @@ export const UI_AUTO_PROMPT_TEMPLATE = `# 自动化执行提示词
55
57
 
56
58
  ## 规划阶段
57
59
 
58
- 你是自动化测试工程师,本轮负责其中的**浏览器 UI 自动化**:把需求拆成可执行、可人工编辑的测试步骤计划。
60
+ 你是自动化测试工程师,本轮对应产品里的**脚本编排 · 规划**:把需求拆成可执行、可人工编辑的测试步骤计划。
61
+ 用户在编排会话里发的一句话需求(哪怕像用例标题),也只当规划输入,不要直接出码或跑测。
59
62
 
60
63
  自动化不只有 UI(接口、App、性能都算),但本功能目前只产出浏览器 UI 脚本(Playwright,或 pytest + \`playwright.sync_api\`),
61
64
  工具也只有浏览器那一套(打开页面、快照、点击、定位探测);接口自动化(requests / httpx)、App(Appium)、性能都没有工具与出码模板。
@@ -65,19 +68,21 @@ export const UI_AUTO_PROMPT_TEMPLATE = `# 自动化执行提示词
65
68
 
66
69
  规则:
67
70
  1. 只调用 ui_plan_steps 一次,提交完整计划;不要打开浏览器、不要写定位器。
68
- 2. 每步只描述「动作 + 目标」:target 用页面上的可见文案 / 位置描述,例如「用户名输入框」「右上角登录按钮」。
69
- 3. 除 goto / wait / press 外,缺 target 的步骤会被直接丢掉、不报错;提交后核对返回的 stepCount(实际保留条数)。
70
- 4. 账号、密码、手机号等占位数据写成 \${ENV_NAME},不要编造真实凭据。
71
- 5. 计划要覆盖:打开页面、关键前置(登录 / 导航)、核心操作、至少一条结果断言(用户能看到什么)。
72
- 6. 步骤 4~12 步为宜(最多 40 步),不要为了凑数拆得过细;一个动作一句话。
73
- 7. 计划里只写测试步骤,不要写「截图」:计划不接受截图步骤,提交了会被丢掉。
71
+ 2. **禁止**创建 / 修改 / 删除项目里的测试或源码文件;**禁止**运行 playwright / pytest / npm test 等命令;**禁止**手写完整测试代码。出码与试跑是后续阶段、由平台与用户按钮触发。
72
+ 3. 每步只描述「动作 + 目标」:target 用页面上的可见文案 / 位置描述,例如「用户名输入框」「右上角登录按钮」。
73
+ 4. 除 goto / wait / press 外,缺 target 的步骤会被直接丢掉、不报错;提交后核对返回的 stepCount(实际保留条数)。
74
+ 5. 账号、密码、手机号等占位数据写成 \${ENV_NAME},不要编造真实凭据。
75
+ 6. 计划要覆盖:打开页面、关键前置(登录 / 导航)、核心操作、至少一条结果断言(用户能看到什么)。
76
+ 7. 步骤 4~12 步为宜(最多 40 步),不要为了凑数拆得过细;一个动作一句话。
77
+ 8. 计划里只写测试步骤,不要写「截图」:计划不接受截图步骤,提交了会被丢掉。
74
78
 
75
- 提交后简短说明你的测试思路与需要人工确认的点。
79
+ 提交后用中文简短说明测试思路,并提醒用户:在右侧步骤栏确认后点「确认并探索」,才会进入绑定位器。
76
80
 
77
81
  ## 探索阶段
78
82
 
79
- 你是自动化测试工程师,本轮负责其中的**浏览器 UI 自动化**:在真实浏览器里把流程点一遍,确认每个元素都能唯一定位,再提交步骤。
83
+ 你是自动化测试工程师,本轮对应产品里的**脚本编排 · 探索**(用户已点「确认并探索」):在真实浏览器里把流程点一遍,确认每个元素都能唯一定位,再提交步骤。
80
84
  本功能只产出浏览器 UI 脚本,接口 / App / 性能自动化没有对应工具;项目类型是「接口」或需求要测接口时,直接说明不支持并停下,不要开浏览器象征性点两下再出个 UI 脚本。
85
+ 本阶段仍**不要**手写或改项目里的测试文件;定位器提交后由平台出码,不要自己 \`npx playwright test\`。
81
86
 
82
87
  当前挂载项目:{{project}}({{dir}}),项目类型:{{kind}},生成目标语言:{{language}}。
83
88
 
@@ -86,7 +91,7 @@ export const UI_AUTO_PROMPT_TEMPLATE = `# 自动化执行提示词
86
91
  2. ref 是临时的,页面导航或刷新后会失效;失效就重新 ui_browser_snapshot,不要猜。
87
92
  需要等异步渲染时用 ui_browser_wait({ text: "某段文案" }),不要用长时间死等。
88
93
  3. 写步骤之前,对每个要操作或断言的元素调用 ui_locator_probe,用返回的 recommended;
89
- 带 stepId 时定位器会回填到左侧对应计划步骤。
94
+ 带 stepId 时定位器会回填到步骤栏对应计划步骤。
90
95
  recommended 带 nth 时表示同名元素取第 N 个(出码时 TS 是 .first()、Python 是 .first,你都不要手写),照抄即可。
91
96
  没有唯一候选时换更具体的元素,不要自己拼长 CSS / XPath。
92
97
  4. 用 ui_test_set_steps 提交整份步骤(会刷新代码预览)。**不要自己试跑**:
@@ -97,19 +102,19 @@ export const UI_AUTO_PROMPT_TEMPLATE = `# 自动化执行提示词
97
102
  6. 如果页面行为本身与需求不符,保留现状并在回答里说明是疑似缺陷,不要为了跑绿改断言。
98
103
  7. 占位数据(账号、手机号)写成 \${ENV_NAME},不要编造真实凭据。
99
104
  8. 至少要有一条 expect 断言,断言用户能看到的结果,而不是断言元素存在就算过。
100
- 9. 关键节点(登录后、进入目标页、操作完成)调用一次 ui_browser_screenshot,用户会在面板里看到这一步的截图。
105
+ 9. 若本轮工具列表里有 ui_browser_screenshot,关键节点(登录后、进入目标页、操作完成)可调用一次;截图只给人看,你看不到图片内容。工具列表里没有就不要调用,用 ui_browser_snapshot 判断结构即可。
101
106
  10. 点击没反应 / 页面报错时,用 ui_browser_console 与 ui_browser_network 看错误,别盲目重试。
102
107
 
103
108
  {{plan}}
104
109
 
105
110
  步骤 IR 的 action 只用:goto / click / fill / select / press / hover / expect / expectUrl / wait。
106
- (枚举里的 screenshot 不要用:它会出成 page.screenshot 写进脚本,本平台不需要;过程截图用 ui_browser_screenshot 工具。)
111
+ (枚举里的 screenshot 不要用:它会出成 page.screenshot 写进脚本,本平台不需要;给人看的过程截图只用 ui_browser_screenshot,且仅当工具可用时。)
107
112
  locator.kind 只用 testid / role / label / placeholder / text / attr / css,按这个顺序优先(testid → role → label)。
108
113
  \${ENV_NAME} 必须是**整个值**,名字用英文大写 / 数字 / 下划线(如 \${USER_NAME});写成 user_\${NAME} 或中文名不会被识别成环境变量。
109
114
 
110
115
  ## 生成代码
111
116
 
112
- 出码与写入项目由平台按模板完成:你不写脚本,也没有读写项目文件的工具。这一段说明哪些必须由你管好、平台会怎么落盘。
117
+ 出码与写入项目由平台按模板完成:你不写脚本,也没有读写项目文件的工具;不要在会话里自己新建 \`.spec.ts\` / \`test_*.py\` 或动手跑测。这一段说明哪些必须由你管好、平台会怎么落盘。
113
118
 
114
119
  1. **用例标题**(决定用例名与文件名):中文一句话说清业务行为,一个用例只验证一件事;不要带路径分隔符。文件名由平台把标题转成 ASCII(纯中文标题会落到 ai-generated.spec.ts / test_ai_generated.py)。
115
120
  2. **步骤 IR 就是脚本内容**:出码只照抄你提交的 action / locator / value / text / ms。定位器必须来自 ui_locator_probe 的 recommended;不要用长 CSS,也不要自己猜 nth。
@@ -0,0 +1,407 @@
1
+ /**
2
+ * 平台侧 SSO / 接口登录:读项目 env → 调 LOGIN_API → 写入 Playwright storageState。
3
+ * 不跑项目里的 auth.setup(那条见 uiauto-auth-setup.mjs)。
4
+ * 给登录墙自动链与手动选 SSO 共用。
5
+ *
6
+ * 登录接口地址:优先骨架约定键,再通配 `LOGIN_API_*`(排除 BODY / TOKEN 等非地址字段)。
7
+ */
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+
11
+ import { envFilePath, parseEnvText, sanitizeEnvName } from './uiauto-env.mjs';
12
+
13
+ const AUTH_REL = path.join('.auth', 'admin.json');
14
+
15
+ /** 骨架 / 常见别名:有值时优先按此顺序取 */
16
+ export const LOGIN_API_ENDPOINT_KEYS = [
17
+ 'LOGIN_API_PATH',
18
+ 'LOGIN_API_URL',
19
+ 'LOGIN_API_ENDPOINT',
20
+ 'LOGIN_URL',
21
+ ];
22
+
23
+ /**
24
+ * `LOGIN_API_*` 里不算「接口地址」的后缀(请求体、token 路径、头等)。
25
+ * 其余后缀走通配,例如 LOGIN_API_SSO_URL、LOGIN_API_HOST。
26
+ */
27
+ export const LOGIN_API_ENDPOINT_DENY_SUFFIXES = [
28
+ 'BODY',
29
+ 'TOKEN_PATH',
30
+ 'TOKEN_KEY',
31
+ 'TOKEN_STORAGE_KEY',
32
+ 'METHOD',
33
+ 'HEADERS',
34
+ 'HEADER',
35
+ 'TIMEOUT',
36
+ 'CONTENT_TYPE',
37
+ 'TYPE',
38
+ ];
39
+
40
+ const ENDPOINT_DENY_RE = new RegExp(`^(${LOGIN_API_ENDPOINT_DENY_SUFFIXES.join('|')})$`, 'i');
41
+
42
+ function looksLikeEndpoint(value) {
43
+ const v = String(value || '').trim();
44
+ if (!v) return 0;
45
+ if (/^https?:\/\//i.test(v)) return 3;
46
+ if (v.startsWith('/')) return 2;
47
+ // 主机或相对路径也尽量认,分最低
48
+ if (/^[a-z0-9.-]+\/[a-z0-9/_.-]+$/i.test(v) || /^[a-z0-9_./-]+$/i.test(v)) return 1;
49
+ return 0;
50
+ }
51
+
52
+ function isDeniedLoginApiKey(key) {
53
+ const raw = String(key || '');
54
+ if (!/^LOGIN_API_/i.test(raw)) return true;
55
+ const suffix = raw.slice('LOGIN_API_'.length);
56
+ return ENDPOINT_DENY_RE.test(suffix);
57
+ }
58
+
59
+ /**
60
+ * 从 env map 里取出登录接口地址(相对 path 或完整 URL)。
61
+ * 1) 优先 LOGIN_API_PATH / URL / ENDPOINT / LOGIN_URL
62
+ * 2) 再通配其它 `LOGIN_API_*`(排除 BODY、TOKEN_* 等)
63
+ * @returns {{ key: string, value: string }}
64
+ */
65
+ export function resolveLoginApiEndpoint(envMap = {}) {
66
+ const map = envMap && typeof envMap === 'object' ? envMap : {};
67
+ for (const key of LOGIN_API_ENDPOINT_KEYS) {
68
+ const value = String(map[key] ?? '').trim();
69
+ if (value) return { key, value };
70
+ }
71
+
72
+ /** @type {Array<{ key: string, value: string, score: number }>} */
73
+ const wild = [];
74
+ for (const [key, raw] of Object.entries(map)) {
75
+ if (isDeniedLoginApiKey(key)) continue;
76
+ // 已在优先列表里扫过
77
+ if (LOGIN_API_ENDPOINT_KEYS.includes(key)) continue;
78
+ const value = String(raw ?? '').trim();
79
+ if (!value) continue;
80
+ const score = looksLikeEndpoint(value);
81
+ if (score <= 0) continue;
82
+ wild.push({ key, value, score });
83
+ }
84
+ if (!wild.length) return { key: '', value: '' };
85
+ wild.sort((a, b) => b.score - a.score || a.key.localeCompare(b.key));
86
+ return { key: wild[0].key, value: wild[0].value };
87
+ }
88
+
89
+ function readEnvFileMap(file) {
90
+ if (!file || !fs.existsSync(file)) return {};
91
+ try {
92
+ const parsed = parseEnvText(fs.readFileSync(file, 'utf8'));
93
+ const map = {};
94
+ for (const entry of parsed.entries) {
95
+ map[entry.key] = entry.value;
96
+ }
97
+ return map;
98
+ } catch {
99
+ return {};
100
+ }
101
+ }
102
+
103
+ /** `.env` 打底,再叠 `.env.<ENV>`(后者覆盖) */
104
+ export function readProjectEnvMap(dir, envName = '') {
105
+ const root = String(dir || '');
106
+ if (!root) return {};
107
+ const base = readEnvFileMap(envFilePath(root, ''));
108
+ const env = sanitizeEnvName(envName);
109
+ if (!env) return base;
110
+ return { ...base, ...readEnvFileMap(envFilePath(root, env)) };
111
+ }
112
+
113
+ export function projectHasSsoConfig(dir, envName = '') {
114
+ const map = readProjectEnvMap(dir, envName);
115
+ return Boolean(resolveLoginApiEndpoint(map).value);
116
+ }
117
+
118
+ function renderBody(template, username, password) {
119
+ const replace = (value) =>
120
+ value
121
+ .replace(/\{\{\s*username\s*\}\}/g, () => username)
122
+ .replace(/\{\{\s*password\s*\}\}/g, () => password);
123
+ try {
124
+ return JSON.stringify(JSON.parse(template), (_key, value) =>
125
+ typeof value === 'string' ? replace(value) : value,
126
+ );
127
+ } catch {
128
+ return replace(String(template || ''));
129
+ }
130
+ }
131
+
132
+ function pickPath(source, target) {
133
+ return String(target || '')
134
+ .split('.')
135
+ .filter(Boolean)
136
+ .reduce((acc, key) => {
137
+ if (acc && typeof acc === 'object') return acc[key];
138
+ return undefined;
139
+ }, source);
140
+ }
141
+
142
+ /** 未配 LOGIN_API_TOKEN_PATH 时按常见字段猜 token */
143
+ export const DEFAULT_TOKEN_PATHS = [
144
+ 'data.authorization',
145
+ 'data.token',
146
+ 'data.accessToken',
147
+ 'data.access_token',
148
+ 'data.data.token',
149
+ 'result.token',
150
+ 'result.access_token',
151
+ 'token',
152
+ 'access_token',
153
+ 'accessToken',
154
+ 'authorization',
155
+ ];
156
+
157
+ /** 未配 LOGIN_TOKEN_STORAGE_KEY 时的默认 localStorage key */
158
+ export const DEFAULT_TOKEN_STORAGE_KEYS = ['token', 'access_token', 'accessToken'];
159
+
160
+ function asTokenString(value) {
161
+ if (value == null) return '';
162
+ if (typeof value === 'string') return value.trim();
163
+ if (typeof value === 'number' && Number.isFinite(value)) return String(value);
164
+ return '';
165
+ }
166
+
167
+ /** 在对象里按 key 名深挖 token(最多 5 层),适配 data.xxx 自定义字段 */
168
+ export function findTokenDeep(node, prefix = '', depth = 0) {
169
+ if (depth > 5 || node == null || typeof node !== 'object') return null;
170
+ const entries = Array.isArray(node) ? node.map((v, i) => [String(i), v]) : Object.entries(node);
171
+ for (const [key, value] of entries) {
172
+ const pathKey = prefix ? `${prefix}.${key}` : key;
173
+ if (/token|jwt|access|authorization|ticket|session|sid/i.test(String(key))) {
174
+ const token = asTokenString(value);
175
+ if (token.length >= 8) return { token, path: pathKey };
176
+ }
177
+ }
178
+ for (const [key, value] of entries) {
179
+ if (value && typeof value === 'object') {
180
+ const pathKey = prefix ? `${prefix}.${key}` : key;
181
+ const hit = findTokenDeep(value, pathKey, depth + 1);
182
+ if (hit) return hit;
183
+ }
184
+ }
185
+ return null;
186
+ }
187
+
188
+ /**
189
+ * 从登录响应 JSON 取 token:显式路径优先,否则扫常见字段,再深挖 data。
190
+ * @returns {{ token: string, path: string }}
191
+ */
192
+ export function resolveLoginToken(json, explicitPath = '') {
193
+ const configured = String(explicitPath || '').trim();
194
+ if (configured) {
195
+ const token = asTokenString(pickPath(json, configured));
196
+ if (token) return { token, path: configured };
197
+ }
198
+ if (!json || typeof json !== 'object') return { token: '', path: '' };
199
+ for (const pathKey of DEFAULT_TOKEN_PATHS) {
200
+ const token = asTokenString(pickPath(json, pathKey));
201
+ if (token) return { token, path: pathKey };
202
+ }
203
+ // data 本身是 JWT / 长串
204
+ const dataAsToken = asTokenString(json.data);
205
+ if (dataAsToken.length >= 16) return { token: dataAsToken, path: 'data' };
206
+ const deep = findTokenDeep(json);
207
+ if (deep) return deep;
208
+ return { token: '', path: '' };
209
+ }
210
+
211
+ /**
212
+ * localStorage 写入用的 key:显式配置优先,否则默认 `token`。
213
+ */
214
+ export function resolveTokenStorageKey(envMap = {}, fallback = 'token') {
215
+ const map = envMap && typeof envMap === 'object' ? envMap : {};
216
+ for (const key of [
217
+ 'LOGIN_TOKEN_STORAGE_KEY',
218
+ 'LOGIN_API_TOKEN_KEY',
219
+ 'LOGIN_API_STORAGE_KEY',
220
+ 'TOKEN_STORAGE_KEY',
221
+ ]) {
222
+ const value = String(map[key] ?? '').trim();
223
+ if (value) return value;
224
+ }
225
+ return String(fallback || 'token').trim() || 'token';
226
+ }
227
+
228
+ function originFromBase(baseURL) {
229
+ try {
230
+ const u = new URL(String(baseURL || '').trim() || 'http://localhost');
231
+ return u.origin;
232
+ } catch {
233
+ return 'http://localhost';
234
+ }
235
+ }
236
+
237
+ function resolveLoginUrl(baseURL, apiPath) {
238
+ const p = String(apiPath || '').trim();
239
+ if (!p) return '';
240
+ if (/^https?:\/\//i.test(p)) return p;
241
+ const base = String(baseURL || '').replace(/\/+$/, '');
242
+ if (!base) return p.startsWith('/') ? p : `/${p}`;
243
+ return `${base}${p.startsWith('/') ? p : `/${p}`}`;
244
+ }
245
+
246
+ /**
247
+ * 调接口登录并写 `.auth/admin.json`。
248
+ * @returns {{ ok: true, storageState: string, tokenSaved: boolean } | { ok: false, error: string }}
249
+ */
250
+ export async function runSsoLoginAndSave({ dir, envName = '', baseURL = '', envMap, signal }) {
251
+ const root = String(dir || '');
252
+ if (!root || !fs.existsSync(root)) {
253
+ return { ok: false, error: '项目目录不存在' };
254
+ }
255
+ const env = envMap ?? readProjectEnvMap(root, envName);
256
+ const endpoint = resolveLoginApiEndpoint(env);
257
+ const apiPath = endpoint.value;
258
+ if (!apiPath) {
259
+ return {
260
+ ok: false,
261
+ error:
262
+ '未配置登录接口地址。请在环境配置填写 LOGIN_API_PATH / LOGIN_API_URL,或其它 LOGIN_API_* 地址类变量。',
263
+ };
264
+ }
265
+ const username = String(env.ADMIN_USERNAME || env.USER_USERNAME || '').trim();
266
+ const password = String(env.ADMIN_PASSWORD || env.USER_PASSWORD || '');
267
+ if (!username || !password) {
268
+ return { ok: false, error: '未配置 ADMIN_USERNAME / ADMIN_PASSWORD(或 USER_*)' };
269
+ }
270
+ const bodyTemplate =
271
+ String(env.LOGIN_API_BODY || '').trim() ||
272
+ '{"username":"{{username}}","password":"{{password}}"}';
273
+ const url = resolveLoginUrl(baseURL || env.BASE_URL || '', apiPath);
274
+ if (!url || !/^https?:\/\//i.test(url)) {
275
+ return {
276
+ ok: false,
277
+ error: `无法拼出登录接口地址:请配置 BASE_URL,或在 ${endpoint.key || 'LOGIN_API_PATH'} 里写完整 URL`,
278
+ };
279
+ }
280
+
281
+ let response;
282
+ try {
283
+ response = await fetch(url, {
284
+ method: 'POST',
285
+ headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
286
+ body: renderBody(bodyTemplate, username, password),
287
+ signal: signal
288
+ ? AbortSignal.any([signal, AbortSignal.timeout(30_000)])
289
+ : AbortSignal.timeout(30_000),
290
+ });
291
+ } catch (err) {
292
+ return {
293
+ ok: false,
294
+ error: `请求登录接口失败:${err instanceof Error ? err.message : String(err)}`,
295
+ };
296
+ }
297
+
298
+ const rawText = await response.text();
299
+ let json = null;
300
+ try {
301
+ json = JSON.parse(rawText);
302
+ } catch {
303
+ json = null;
304
+ }
305
+ if (!response.ok) {
306
+ return {
307
+ ok: false,
308
+ error: `登录接口返回 ${response.status}${rawText ? `:${rawText.slice(0, 200)}` : ''}`,
309
+ };
310
+ }
311
+
312
+ const explicitTokenPath = String(env.LOGIN_API_TOKEN_PATH || env.LOGIN_TOKEN_PATH || '').trim();
313
+ const { token, path: tokenPathUsed } = resolveLoginToken(json, explicitTokenPath);
314
+ const storageKey = token ? resolveTokenStorageKey(env, 'token') : '';
315
+
316
+ const cookies = [];
317
+ const setCookie = [];
318
+ if (typeof response.headers.getSetCookie === 'function') {
319
+ setCookie.push(...response.headers.getSetCookie());
320
+ }
321
+ // 兼容没有 getSetCookie 的运行时:单条 set-cookie
322
+ if (!setCookie.length) {
323
+ const single = response.headers.get('set-cookie');
324
+ if (single) setCookie.push(single);
325
+ }
326
+ for (const line of setCookie) {
327
+ const [pair] = String(line).split(';');
328
+ const eq = pair.indexOf('=');
329
+ if (eq <= 0) continue;
330
+ const name = pair.slice(0, eq).trim();
331
+ const value = pair.slice(eq + 1).trim();
332
+ if (!name) continue;
333
+ try {
334
+ const origin = new URL(url);
335
+ cookies.push({
336
+ name,
337
+ value,
338
+ domain: origin.hostname,
339
+ path: '/',
340
+ expires: -1,
341
+ httpOnly: /httponly/i.test(line),
342
+ secure: origin.protocol === 'https:',
343
+ sameSite: 'Lax',
344
+ });
345
+ } catch {
346
+ // ignore bad cookie
347
+ }
348
+ }
349
+
350
+ // localStorage 必须挂在「打开业务页的 origin」上;登录接口域名常与 BASE_URL 不同,
351
+ // 只写 API origin 时页面读不到 token → 业务请求变成 undefined / 非法请求。
352
+ const appOrigin = originFromBase(baseURL || env.BASE_URL || '');
353
+ const apiOrigin = originFromBase(url);
354
+ const storageOrigins = [
355
+ ...new Set([appOrigin, apiOrigin].filter((item) => item && item !== 'http://localhost')),
356
+ ];
357
+ if (!storageOrigins.length) storageOrigins.push(apiOrigin || appOrigin || 'http://localhost');
358
+
359
+ const localStorage = [];
360
+ if (token) {
361
+ // 与常见 Playwright auth.setup 对齐:主 key 用 token(可用 LOGIN_TOKEN_STORAGE_KEY 覆盖)
362
+ const primary = storageKey || 'token';
363
+ localStorage.push({ name: primary, value: token });
364
+ if (primary !== 'token') localStorage.push({ name: 'token', value: token });
365
+ }
366
+ // 许多中台(含本仓库挂载的热线项目)除 token 外还要 loginUser=整份 data,缺了会「非法请求」
367
+ const loginUser =
368
+ json && typeof json.data === 'object' && json.data
369
+ ? json.data
370
+ : json && typeof json === 'object'
371
+ ? null
372
+ : null;
373
+ if (loginUser) {
374
+ localStorage.push({ name: 'loginUser', value: JSON.stringify(loginUser) });
375
+ }
376
+
377
+ if (!cookies.length && !localStorage.length) {
378
+ const sample =
379
+ json && typeof json === 'object'
380
+ ? ` 响应字段:${Object.keys(json).slice(0, 8).join(', ') || '(空)'}`
381
+ : rawText
382
+ ? ` 响应片段:${rawText.slice(0, 120)}`
383
+ : '';
384
+ return {
385
+ ok: false,
386
+ error:
387
+ '接口已响应,但没有拿到可写入的 cookie / token。可配置 LOGIN_API_TOKEN_PATH(响应里 token 的路径)与 LOGIN_TOKEN_STORAGE_KEY(须与框架读取的 key 一致),或确认接口会 Set-Cookie。' +
388
+ sample,
389
+ };
390
+ }
391
+
392
+ const state = {
393
+ cookies,
394
+ origins: localStorage.length ? storageOrigins.map((origin) => ({ origin, localStorage })) : [],
395
+ };
396
+ const abs = path.join(root, AUTH_REL);
397
+ signal?.throwIfAborted();
398
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
399
+ fs.writeFileSync(abs, `${JSON.stringify(state, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
400
+ return {
401
+ ok: true,
402
+ storageState: AUTH_REL.replace(/\\/g, '/'),
403
+ tokenSaved: Boolean(token && storageKey),
404
+ tokenPath: tokenPathUsed || '',
405
+ storageKey: storageKey || '',
406
+ };
407
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lantern-harness",
3
- "version": "0.1.45",
3
+ "version": "0.2.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "AI 工作台:对话与插件工具、内容库、模板库、会话记忆,数据留在本机。",
@@ -39,6 +39,7 @@
39
39
  "lh-plugins",
40
40
  "config",
41
41
  "prompt",
42
+ "skills",
42
43
  "docs",
43
44
  "空间池/.gitkeep",
44
45
  "CHANGELOG.md",
@@ -94,12 +95,14 @@
94
95
  "jszip": "^3.10.2",
95
96
  "mammoth": "^1.13.0",
96
97
  "marked": "^15.0.6",
98
+ "playwright": "^1.65.1",
97
99
  "react": "^19.0.0",
98
100
  "react-dom": "^19.0.0",
99
101
  "react-grid-layout": "2.3.0",
100
102
  "sirv": "^3.0.2",
101
103
  "word-extractor": "^1.0.4",
102
- "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
104
+ "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
105
+ "zod": "^4.6.7"
103
106
  },
104
107
  "optionalDependencies": {
105
108
  "node-pty": "^1.0.0"
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: case-automation-bridge
3
+ description: 将功能测试用例评估、拆解为可执行的 UI 自动化用例与 UI Plan,并绑定现有 UI 自动化项目和 iteration 文件。
4
+ ---
5
+
6
+ # 功能用例转 UI 自动化
7
+
8
+ ## 适用范围
9
+
10
+ 用于从功能测试用例中提取 UI 自动化范围。功能用例仍是业务事实来源;本技能只做可自动化评估、用例拆分和 UI Plan 设计。
11
+
12
+ ## 流程
13
+
14
+ 1. 读取用户明确选择的功能用例行,以及所选 UI 自动化项目的框架、地址和迭代文件。
15
+ 2. 逐条判断 `automatable`、`needs_manual` 或 `not_automatable`,说明依据和风险。
16
+ 3. 只对可自动化条目生成自动化用例:前置条件、可执行步骤、可观察预期和最小 UI Plan。
17
+ 4. 校验 Plan 动作、断言、环境变量占位和敏感信息。
18
+ 5. 用户确认后,由平台写入自动化用例文件、创建待探索 UI 自动化会话并绑定项目与 iteration 文件。
19
+
20
+ ## 约束
21
+
22
+ - 不生成 CSS、XPath、坐标、定位器或脚本代码。
23
+ - 不把接口、性能、数据库、App 原生操作误判为 UI 自动化。
24
+ - 不修改原功能用例,不覆盖人工执行结果。
25
+ - 不自动开始浏览器探索、写项目或运行脚本。
26
+ - 一个功能用例可拆成多个自动化用例;每条自动化用例必须有唯一稳定 ID。
27
+ - 目标脚本最终合并到项目现有 `tests/iteration/<迭代>.spec.ts`,而不是独立 spec。
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: case-execution
3
+ description: 通过 Lantern 逐条执行已有测试用例、等待 AI 浏览器结果、人工确认后写回用例文件,并在失败或阻塞时衔接缺陷工作流。用于「执行某条用例」「查看执行进度」「确认执行结果」「把结果同步到执行统计」等请求;不用于生成或评审用例。
4
+ ---
5
+
6
+ # Lantern 单条用例执行
7
+
8
+ Lantern 是执行记录、用例文件和确认结果的唯一持久化入口。使用 `lantern_case_execution_*` MCP 工具,不直接编辑 Excel、Markdown、CSV 或隐藏运行记录。
9
+
10
+ ## 开始前
11
+
12
+ 1. 调用 `lantern_case_execution_files`,确认目标文件具备「用例状态」和「实际结果」列。`.xls` 必须先另存为 `.xlsx`,缺少执行列的文件不能执行。
13
+ 2. 调用 `lantern_case_execution_cases` 读取明细,按用例编号或标题定位唯一一行,并记录 `rowIndex`。
14
+ 3. 确认测试地址。目标地址必须来自本次用户输入;不要沿用其他任务或空间中的地址。
15
+ 4. 优先复用用户提供的 storageState 路径,或先检查是否已有保存登录态。需要本人完成验证码、扫码或账号登录时,调用 `lantern_case_execution_login_start`,由用户完成后再调用 `lantern_case_execution_login_complete`;不要在对话中索取或持久化账号密码。
16
+
17
+ ## 执行
18
+
19
+ 1. 每次只对用户指定的一条用例调用 `lantern_case_execution_start`,不要自行连续执行整份文件。
20
+ 2. 调用后用 `lantern_case_execution_wait` 等待,未结束时继续按 `afterSeq` 读取新增日志和进度;等待期间向用户报告当前阶段、已用时和工具操作数。
21
+ 3. 只有页面、截图、控制台或网络证据真正支持预期结果时才能建议「通过」。明确与预期不一致为「不通过」;登录失效、验证码、权限、测试数据或系统弹窗导致无法完成时为「阻塞」;用例不适用且理由充分时为「跳过」。
22
+ 4. 不要替用户确认。向用户展示建议状态、实际结果、判定依据、未验证项和证据;用户可把状态改为「待验证 / 通过 / 不通过 / 阻塞 / 跳过」。
23
+ 5. 需要停止时调用 `lantern_case_execution_stop`,保留已产生的日志和截图。
24
+ 6. 目标地址只能访问本次授权的目标 origin 和明确允许的登录 origin。脚本跳转、弹窗和每次服务端重定向都受同一限制;出现「跨域导航已拦截」时把目标地址写进阻塞原因,不继续尝试绕过。
25
+
26
+ ## 确认与后续
27
+
28
+ 1. 用户明确确认后调用 `lantern_case_execution_apply`,只写回文件已有的执行列。文件已被外部修改时停止并重新读取,不能覆盖新内容。
29
+ 2. 结果为「不通过」或「阻塞」时,主动提供创建缺陷入口,但不要在用户未要求时自动提交。用户要求提缺陷时,转入 `lantern-defect-submit`,把用例、目标地址、实际结果和证据作为待核验上下文。
30
+ 3. 用户要求同步统计时,先调用 `lantern_case_execution_sync_stats` 的 `preview`。已有同日手工统计时不自动覆盖;只有用户明确选择后才使用 `skip` 或 `overwrite`。
31
+ 4. 执行记录、日志和截图保存在当前空间的 `.lantern/local/case-execution/`。不要把这些内部文件加入 `用例管理/`,也不要把浏览器 Cookie、Token 或 API Key 写入结果。
32
+
33
+ ## 基线、生成与计划
34
+
35
+ - Codex 生成用例使用 `lantern_case_generation_context` 读取当前空间技能和需求基线,生成 rows 后用 `validate` 确定性校验引用与覆盖,再用 `save` 携带原 revision 和 sourceFileHash 入库;源文件变更后必须重新读取。新文件自动具备执行列。
36
+ - 已有文件缺执行列时用 `lantern_case_execution_prepare_columns` 先 preview,用户确认后 apply;XLS 仍需另存为 XLSX。
37
+ - 用户明确要求批量执行并指定范围时,可创建执行计划;保存 caseIds、环境、角色、构建和数据说明后,显式启动。浏览器串行执行;API / App 使用已有自动化项目与指定测试文件,环境缺失应报告阻塞。准备和清理任务只能使用用户选定的项目任务。性能测试不在本轮能力中。
38
+ - 计划停止后不启动新项;重启后显式继续未完成项。计划和单条执行都不会自动选择最终结果。
39
+ - 使用稳定 caseId 对应原用例;需求基线或用例步骤变化后不能把旧通过计入新版本验收。基线重新关联须先 preview 并由用户确认,历史运行保留但结果要求人工复核。
40
+ - 一条用例允许多个 HTTP(S) 缺陷地址;用例文件的缺陷地址字段以换行保存。仅维护链接,不自动提交、关闭或复测缺陷。
41
+ - `lantern_case_acceptance` 返回确定性的设计、执行与通过覆盖及未覆盖项;环境不同的结果要分开核验,报告不能当作缺陷关闭或性能验证证明。
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: lantern-defect-submit
3
+ description: 通过 Lantern 按当前空间规则生成、补全、提交或核验缺陷。用于「生成缺陷」「提交缺陷」「补充缺陷草稿」「查看缺陷提交回执」等请求,适用于已配置的缺陷入口。
4
+ ---
5
+
6
+ # Lantern 缺陷提交
7
+
8
+ 1. 先调用 `lantern_defect_templates` 列出规则。按用户指定的规则调用 `lantern_defect_template_select`,多份规则且用户未指定时询问选择。已有选定规则时可直接使用。调用 `lantern_defect_context` 获取当前空间的缺陷入口、规则、映射字段和可用选项。插件停用或尚未配置时,引导用户在 Lantern「插件仓库 → 测试技能」开启「缺陷规则」。用户明确要求维护缺陷规则时,先用 `lantern_defect_rule_inspect` 读取真实入口、子表和字段,再用 `lantern_defect_rule_save` 保存;删除规则前必须获得用户明确确认并使用 `lantern_defect_rule_delete`。使用上下文返回的规则,避免把具体团队的规则硬编码在 Skill 中。
9
+ 2. 用描述、截图或日志中有依据的事实生成结构化缺陷。以字段 ID 作键。每个字段的 `rule` 是必须执行的判断或生成口径:严重程度、优先级等需要判断的字段,只要 `rule` 提供了判断标准,就应按标准分析问题影响并说明依据,不能仅因需要判断而留空或要求用户决定。`defaultValue` 是规则默认值,只在没有用户值、材料证据或可执行 `rule` 结果时兜底;本次输入或材料明确提供其他值时优先使用本次值。选项和关联字段使用当前平台上下文要求的稳定标识(例如选项 ID、成员 ID、issue key 或 bug ID),多值使用标识数组。规则上下文包含 `iteration` 时,目标字段「迭代版本」必须直接使用这个当前迭代,不再向用户重复询问,也不能被其他来源覆盖。图片字段先用目标平台的上传能力取得 image ID,再传 image ID 数组;附件字段只有在连接器明确支持上传和回写时填写,否则保持为空,不能把本地路径或普通文本写进附件字段;非必填的图片 / 附件没有材料时直接留空,不阻塞提交。通用规则若引用其他文档、知识库页面或目标平台记录,必须先通过当前空间可用且与目标平台匹配的工具读取并核对其中的项目、测试分项目、经办人、迭代等事实;通用规则给出的业务映射优先于常识推断,例如指定经办人归前端、其他经办人归后端时,应先匹配真实经办人,再填写测试项目和测试分项目,空白或无关人员不能自动算作“其他”。负责人、迭代、需求关联等缺少可匹配事实时不能猜;确实无法按 `rule` 和现有证据判断的其他字段应留空或说明待确认。
10
+ 3. 整理「重现步骤」时,操作动作与前置内容分开:账号密码、登录账号、权限、特定数据准备等不属于操作步骤的内容,要放到操作步骤之后的「前置条件:」小节,并以 `1.`、`2.` 逐条编号;没有前置条件时不添加该小节,不能编造账号密码。
11
+ 4. 需要恢复未完成工作时,先调用 `lantern_defect_drafts` 查看当前空间的草稿与状态,避免重复新建。调用 `lantern_defect_draft_save`,传入上下文 `revision` 作为 `contextRevision`。未传入的字段由服务端套用规则默认值。编辑草稿时也传上次返回的草稿 `id` 和草稿 `revision`。如有版本冲突,重新读上下文并检查用户意图。
12
+ 5. 按用户意图处理保存后的草稿:「生成缺陷」「先做个草稿」「预览后再提交」只保存并展示目标、完整非空字段和 `missing`,不提交。用户说「提个缺陷」「提交缺陷」「录入缺陷」等明确要求最终提交的表达,就是授权直接提交:保存草稿后应在同一轮立即用该草稿的 `id` 和 `revision` 调用 `lantern_defect_submit`,不要再要求用户二次确认。只有必填字段缺失、目标有歧义,或负责人、迭代、需求关联等关键字段无法从证据匹配时才停下来说明。修改用户已确认的草稿后应重新提交核验。对于 `platform: manual` 的入口,提供可复制的缺陷正文和目标入口。
13
+ 6. 只有返回 `status: submitted` 才报告成功,并附缺陷编号、目标入口和记录标识(如 record_id、issue key 或 bug ID)。返回 `pending` 时用 `lantern_defect_receipt` 核验同一草稿。没有记录标识时说明需人工核对目标平台,不能重提或新建草稿来绕过。
14
+
15
+ 每个字段的 rule 是该字段的填写要求,defaultValue 是与填写要求分离的规则默认值。手动规则可以尚无目标入口,使用时按用户输入确定目标并通过远端真实字段核对。包含手动字段的规则通过工作台或与目标平台匹配的连接器解析和执行,不使用旧版直接提交工具猜测列名。目标平台可能是腾讯文档、JIRA、禅道或其他已连接系统,必须按任务中的 platform 选择工具,不能默认走腾讯文档。