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
@@ -2,7 +2,8 @@
2
2
  * 生成会话:浏览器子进程管理 + 会话落盘 + 试跑 / 写盘。
3
3
  *
4
4
  * 会话数据放在本机缓存目录 `<空间>/.lantern/local/uiauto/sessions/<id>.json`,
5
- * 截图在旁边 `<id>/shots/`。
5
+ * 截图在旁边 `<id>/shots/`。未绑定工作台编排的会话超过 SESSION_TTL_MS(默认 7 天)
6
+ * 会由 cleanupStaleSessions 清掉;已写 chatSessionId 的跳过。
6
7
  * 试跑草稿写进项目的 `.lantern-ai/<会话>/`(目录自带 .gitignore),失败保留现场,
7
8
  * 可打开 / 重跑 / 看 trace;最终落盘由用户点击确认,写入后还能按项目配置验收。
8
9
  */
@@ -21,10 +22,15 @@ import { mergeGeneratedFile } from './merge.mjs';
21
22
  import { normalizePlan } from './plan.mjs';
22
23
 
23
24
  const RUNNER_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), 'runner.mjs');
24
- const MAX_VERIFY_LOG = 64 * 1024;
25
+ const MAX_VERIFY_LOG = 256 * 1024;
25
26
  const DEFAULT_VERIFY_TIMEOUT = 180000;
26
27
  /** 草稿保留天数:超过就没人再看了,留着只是占目录 */
27
28
  const DRAFT_TTL_MS = 7 * 24 * 60 * 60 * 1000;
29
+ /**
30
+ * 生成会话本机缓存保留多久。
31
+ * 未绑定工作台编排(无 chatSessionId)的会话过期会清掉;已绑定的长留。
32
+ */
33
+ export const SESSION_TTL_MS = 7 * 24 * 60 * 60 * 1000;
28
34
  const MAX_LEDGER_FILE_BYTES = 400 * 1024;
29
35
 
30
36
  /** Playwright 的 line reporter 会写光标控制符,日志里留着很难看 */
@@ -187,13 +193,16 @@ export function listGeneratedSessions(baseDir, projectId = '') {
187
193
  if (record.status === 'exploring' && !RUNNING.has(record.id)) {
188
194
  record.status = 'draft';
189
195
  }
196
+ // 规划阶段步骤在 plan;探索后才有 ir.steps。列表只回摘要,步数两边都要认。
197
+ const planLen = Array.isArray(record.plan) ? record.plan.length : 0;
198
+ const irLen = Array.isArray(record.ir?.steps) ? record.ir.steps.length : 0;
190
199
  items.push({
191
200
  id: record.id,
192
201
  projectId: record.projectId || '',
193
202
  title: record.title || '未命名流程',
194
203
  target: record.target === 'python' ? 'python' : 'ts',
195
204
  status: record.status || 'draft',
196
- stepCount: Array.isArray(record.ir?.steps) ? record.ir.steps.length : 0,
205
+ stepCount: irLen || planLen,
197
206
  createdAt: record.createdAt || '',
198
207
  updatedAt: record.updatedAt || '',
199
208
  });
@@ -201,15 +210,108 @@ export function listGeneratedSessions(baseDir, projectId = '') {
201
210
  return items.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : -1)).slice(0, 50);
202
211
  }
203
212
 
213
+ /** 删掉生成会话 JSON 与旁边的 shots 目录;不负责停浏览器(调用方先停) */
204
214
  export function deleteGeneratedSession(baseDir, id) {
205
215
  if (!id) return false;
206
216
  const file = sessionFilePath(baseDir, id);
207
- if (!fs.existsSync(file)) return false;
208
- fs.rmSync(file, { force: true });
209
- fs.rmSync(path.join(sessionsDir(baseDir), id), { recursive: true, force: true });
217
+ const shotRoot = path.join(sessionsDir(baseDir), id);
218
+ const hadFile = fs.existsSync(file);
219
+ const hadDir = fs.existsSync(shotRoot);
220
+ if (!hadFile && !hadDir) return false;
221
+ if (hadFile) fs.rmSync(file, { force: true });
222
+ if (hadDir) fs.rmSync(shotRoot, { recursive: true, force: true });
210
223
  return true;
211
224
  }
212
225
 
226
+ function sessionAgeMs(record, filePath, now) {
227
+ const stamp = Date.parse(String(record?.updatedAt || record?.createdAt || ''));
228
+ if (Number.isFinite(stamp)) return now - stamp;
229
+ try {
230
+ return now - fs.statSync(filePath).mtimeMs;
231
+ } catch {
232
+ // 读不到时间就先留着,别误删
233
+ return 0;
234
+ }
235
+ }
236
+
237
+ /**
238
+ * 清掉过期的生成会话及其截图。
239
+ *
240
+ * - 按 `updatedAt`(没有就用 `createdAt` / 文件 mtime)判断是否超过 SESSION_TTL_MS
241
+ * - 正在跑浏览器或调试的会话跳过
242
+ * - 没有对应 JSON 的孤儿 shots 目录一并清
243
+ * - 返回删掉的会话 id,方便自测与日志
244
+ */
245
+ export function cleanupStaleSessions(baseDir, opts = {}) {
246
+ const dir = sessionsDir(baseDir);
247
+ if (!fs.existsSync(dir)) return { removed: [] };
248
+ const ttl = Number.isFinite(opts.ttlMs) ? Number(opts.ttlMs) : SESSION_TTL_MS;
249
+ const now = Number.isFinite(opts.now) ? Number(opts.now) : Date.now();
250
+ const removed = [];
251
+
252
+ let names = [];
253
+ try {
254
+ names = fs.readdirSync(dir);
255
+ } catch {
256
+ return { removed };
257
+ }
258
+
259
+ const jsonIds = new Set();
260
+ for (const name of names) {
261
+ if (!name.endsWith('.json')) continue;
262
+ const id = name.slice(0, -'.json'.length);
263
+ jsonIds.add(id);
264
+ const file = path.join(dir, name);
265
+ const record = readJson(file);
266
+
267
+ // 坏文件 / 空壳:按文件 mtime 过期就清
268
+ if (!record || !record.id) {
269
+ try {
270
+ if (now - fs.statSync(file).mtimeMs > ttl) {
271
+ fs.rmSync(file, { force: true });
272
+ fs.rmSync(path.join(dir, id), { recursive: true, force: true });
273
+ removed.push(id);
274
+ }
275
+ } catch {
276
+ // 并发删除略过
277
+ }
278
+ continue;
279
+ }
280
+
281
+ // 还在探索 / 调试的别动,哪怕时间戳偏旧
282
+ if (RUNNING.has(record.id) || hasDebugSession(record.id)) continue;
283
+ // 已关联工作台编排会话:跳过 TTL,避免侧栏点开域状态已空
284
+ if (String(record.chatSessionId || '').trim()) continue;
285
+ if (sessionAgeMs(record, file, now) <= ttl) continue;
286
+
287
+ stopExplorer(record.id);
288
+ stopDebugSession(record.id);
289
+ if (deleteGeneratedSession(baseDir, record.id)) removed.push(record.id);
290
+ }
291
+
292
+ // 孤儿截图目录:JSON 已经没了,shots 还挂着
293
+ for (const name of names) {
294
+ if (name.endsWith('.json')) continue;
295
+ const abs = path.join(dir, name);
296
+ try {
297
+ if (!fs.statSync(abs).isDirectory()) continue;
298
+ } catch {
299
+ continue;
300
+ }
301
+ if (jsonIds.has(name) || RUNNING.has(name) || hasDebugSession(name)) continue;
302
+ try {
303
+ if (now - fs.statSync(abs).mtimeMs > ttl) {
304
+ fs.rmSync(abs, { recursive: true, force: true });
305
+ removed.push(name);
306
+ }
307
+ } catch {
308
+ // 并发删除略过
309
+ }
310
+ }
311
+
312
+ return { removed };
313
+ }
314
+
213
315
  function respondError(entry, id, message) {
214
316
  const pending = entry.pending.get(id);
215
317
  if (!pending) return;
@@ -361,18 +463,29 @@ export function stopExplorer(sessionId) {
361
463
  const entry = RUNNING.get(sessionId);
362
464
  if (!entry) return false;
363
465
  RUNNING.delete(sessionId);
466
+ // 用正数 seq,避免子进程把假值 id 当成无效命令丢掉
467
+ entry.seq += 1;
468
+ const closeId = entry.seq;
364
469
  try {
365
- entry.child.stdin.write(`${JSON.stringify({ id: -1, cmd: 'close', args: {} })}\n`);
470
+ entry.child.stdin.write(`${JSON.stringify({ id: closeId, cmd: 'close', args: {} })}\n`);
366
471
  } catch {
367
472
  // ignore
368
473
  }
474
+ // 有头 Chromium 偶发不跟 node 一起退:先 SIGTERM,再 SIGKILL
369
475
  setTimeout(() => {
370
476
  try {
371
477
  entry.child.kill('SIGTERM');
372
478
  } catch {
373
479
  // ignore
374
480
  }
375
- }, 1200).unref?.();
481
+ }, 400).unref?.();
482
+ setTimeout(() => {
483
+ try {
484
+ entry.child.kill('SIGKILL');
485
+ } catch {
486
+ // ignore
487
+ }
488
+ }, 1600).unref?.();
376
489
  for (const [id] of entry.pending) respondError(entry, id, '会话已关闭');
377
490
  return true;
378
491
  }
@@ -525,6 +638,8 @@ function pickBaseURLLiteral(content) {
525
638
  const STORAGE_STATE_NAMES = [
526
639
  'auth-admin.json',
527
640
  'auth-user.json',
641
+ 'auth-test.json',
642
+ 'auth-unit-test.json',
528
643
  'auth.json',
529
644
  'storage-state.json',
530
645
  'state.json',
@@ -696,7 +811,8 @@ function writeDraftConfig({ projectDir, sessionId, baseConfig, storageState, bas
696
811
  ' ...config,\n' +
697
812
  " testDir: './draft',\n" +
698
813
  " outputDir: './results',\n" +
699
- " reporter: [['line']],\n" +
814
+ // list 比 line 可读:逐步结果 + 失败断言片段;line 会刷光标控制符,落盘后几乎只剩摘要
815
+ " reporter: [['list']],\n" +
700
816
  ' use: {\n' +
701
817
  `${useLines.join('\n')}\n` +
702
818
  ' },\n' +
@@ -888,30 +1004,91 @@ export function draftSummary({ project, session }) {
888
1004
  };
889
1005
  }
890
1006
 
891
- function tailLog(output, lines = 120) {
1007
+ function tailLog(output, lines = 400) {
892
1008
  const clean = stripAnsi(output);
893
1009
  return clean
894
1010
  .split(/\r?\n/)
895
1011
  .filter((line) => line.trim())
896
1012
  .slice(-lines)
897
1013
  .join('\n')
898
- .slice(-12000);
1014
+ .slice(-48000);
1015
+ }
1016
+
1017
+ /** 试跑日志抬头:说明「在项目里跑、跑的是草稿」 */
1018
+ function formatVerifyLog({ command, args, cwd, draftRel, output }) {
1019
+ const header = [
1020
+ `$ ${[command, ...(args || [])].join(' ')}`,
1021
+ `cwd: ${cwd}`,
1022
+ draftRel ? `draft: ${draftRel}` : '',
1023
+ '(用项目内 Playwright,配置指向本会话 .lantern-ai 草稿,不是正式 tests/)',
1024
+ '─'.repeat(48),
1025
+ ]
1026
+ .filter(Boolean)
1027
+ .join('\n');
1028
+ return `${header}\n${tailLog(output)}`;
1029
+ }
1030
+
1031
+ /**
1032
+ * 把手改出码清单落到会话草稿区(与试跑同一布局)。
1033
+ * spec → draft/;page/fixture → 会话根或 draft 下,保证相对 import 能解析。
1034
+ */
1035
+ export function applyDraftFileOverlay(prepared, draftFiles) {
1036
+ if (!prepared || !Array.isArray(draftFiles) || !draftFiles.length) return prepared;
1037
+ const { paths, emitted } = prepared;
1038
+ for (const item of draftFiles) {
1039
+ const rel = String(item?.path || '')
1040
+ .replace(/\\/g, '/')
1041
+ .replace(/^\/+/, '');
1042
+ const content = typeof item?.content === 'string' ? item.content : '';
1043
+ if (!rel) continue;
1044
+ const role = String(item?.role || '');
1045
+ const isSpec = role === 'spec' || /\.(spec|test)\.(ts|js|py)$/i.test(rel);
1046
+ let abs;
1047
+ if (isSpec) {
1048
+ abs = path.join(paths.draftDir, path.basename(rel));
1049
+ if (emitted) emitted.code = content;
1050
+ } else if (/^(tests|e2e|src\/tests)\//.test(rel)) {
1051
+ const under = rel.replace(/^(tests|e2e|src\/tests)\//, '');
1052
+ abs = path.join(paths.draftDir, under);
1053
+ } else {
1054
+ abs = path.join(paths.root, rel);
1055
+ }
1056
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
1057
+ fs.writeFileSync(abs, content);
1058
+ }
1059
+ return prepared;
1060
+ }
1061
+
1062
+ /** 只写草稿、不跑用例(代码页手改落盘) */
1063
+ export function writeSessionDraftFiles({ project, session, draftFiles }) {
1064
+ const prepared = prepareDraft({ project, session });
1065
+ if (prepared.error) return { ok: false, error: prepared.error };
1066
+ applyDraftFileOverlay(prepared, draftFiles);
1067
+ return { ok: true, ...prepared.draftInfo };
899
1068
  }
900
1069
 
901
1070
  /**
902
1071
  * 试跑:草稿写到 `.lantern-ai/<会话>/draft/`,**跑完不删**。
903
1072
  * 失败现场要能打开看、能重跑、能回放 trace;正式文件只在用户确认后写。
1073
+ * `draftFiles`:前端手改后的出码清单;有则用其覆盖草稿。
904
1074
  */
905
- export async function verifySession({ project, session, timeoutMs = DEFAULT_VERIFY_TIMEOUT }) {
1075
+ export async function verifySession({
1076
+ project,
1077
+ session,
1078
+ timeoutMs = DEFAULT_VERIFY_TIMEOUT,
1079
+ draftFiles,
1080
+ }) {
906
1081
  const prepared = prepareDraft({ project, session });
907
1082
  if (prepared.error) return { ok: false, passed: false, error: prepared.error };
1083
+ applyDraftFileOverlay(prepared, draftFiles);
908
1084
  const { isPython, paths, relDraft, configRel, draftInfo, emitted } = prepared;
909
1085
 
910
1086
  let command;
911
1087
  let args;
912
1088
  if (isPython) {
913
1089
  command = detectPython(project.dir);
914
- args = ['-m', 'pytest', relDraft, '-q'];
1090
+ // -v 打出每条用例名;默认 -q 几乎只有点号
1091
+ args = ['-m', 'pytest', relDraft, '-v', '--tb=short'];
915
1092
  } else {
916
1093
  const runner = playwrightRunner(project.dir);
917
1094
  command = runner.command;
@@ -920,7 +1097,7 @@ export async function verifySession({ project, session, timeoutMs = DEFAULT_VERI
920
1097
  'test',
921
1098
  '--config',
922
1099
  configRel,
923
- '--reporter=line',
1100
+ '--reporter=list',
924
1101
  '--workers=1',
925
1102
  '--timeout=30000',
926
1103
  ];
@@ -934,7 +1111,26 @@ export async function verifySession({ project, session, timeoutMs = DEFAULT_VERI
934
1111
  env: { PLAYWRIGHT_HTML_OPEN: 'never', LANTERN_AI_DRAFT: '1' },
935
1112
  });
936
1113
 
1114
+ // 完整 stdout 落盘,面板只展示裁剪后的;需要时可「打开目录」看 last-run.log
1115
+ try {
1116
+ fs.mkdirSync(paths.resultsDir, { recursive: true });
1117
+ fs.writeFileSync(
1118
+ path.join(paths.resultsDir, 'last-run.log'),
1119
+ stripAnsi(result.output || ''),
1120
+ 'utf8',
1121
+ );
1122
+ } catch {
1123
+ // 落盘失败不影响试跑结果
1124
+ }
1125
+
937
1126
  const traceAbs = isPython ? '' : findTrace(paths.resultsDir);
1127
+ const log = formatVerifyLog({
1128
+ command,
1129
+ args,
1130
+ cwd: project.dir,
1131
+ draftRel: relDraft,
1132
+ output: result.output,
1133
+ });
938
1134
  return {
939
1135
  ok: true,
940
1136
  passed: result.exitCode === 0,
@@ -942,10 +1138,11 @@ export async function verifySession({ project, session, timeoutMs = DEFAULT_VERI
942
1138
  timedOut: result.timedOut,
943
1139
  durationMs: result.durationMs,
944
1140
  command: [command, ...args].join(' '),
945
- code: emitted.code,
946
- log: tailLog(result.output),
1141
+ code: emitted?.code || '',
1142
+ log,
947
1143
  ...draftInfo,
948
1144
  tracePath: traceAbs ? toPosix(path.relative(project.dir, traceAbs)) : '',
1145
+ logPath: toPosix(path.relative(project.dir, path.join(paths.resultsDir, 'last-run.log'))),
949
1146
  };
950
1147
  }
951
1148
 
@@ -1039,7 +1236,7 @@ export async function debugSession({ project, session, mode = 'headed' }) {
1039
1236
 
1040
1237
  const result = await runProcess({
1041
1238
  command: runner.command,
1042
- args: [...baseArgs, '--headed', '--trace=on', '--reporter=line'],
1239
+ args: [...baseArgs, '--headed', '--trace=on', '--reporter=list'],
1043
1240
  cwd: project.dir,
1044
1241
  timeoutMs: DEFAULT_VERIFY_TIMEOUT,
1045
1242
  env: { PLAYWRIGHT_HTML_OPEN: 'never', LANTERN_AI_DRAFT: '1' },
@@ -1252,6 +1449,97 @@ export function writeGeneratedFiles(params) {
1252
1449
  };
1253
1450
  }
1254
1451
 
1452
+ /**
1453
+ * 按会话变更账本撤销已写入项目的文件(多选)。
1454
+ * create → 删文件;merge/update → 写回 before;无账本则跳过。
1455
+ */
1456
+ export function revertGeneratedFiles({ project, session, paths }) {
1457
+ const wanted = Array.isArray(paths)
1458
+ ? [...new Set(paths.map((item) => normalizeRelPath(item)).filter(Boolean))]
1459
+ : [];
1460
+ if (!wanted.length) return { ok: false, error: '没有要移除的文件' };
1461
+
1462
+ const ledger = Array.isArray(session?.changes) ? session.changes.slice() : [];
1463
+ const byPath = new Map(ledger.map((entry) => [normalizeRelPath(entry.path), entry]));
1464
+ const reverted = [];
1465
+ const skipped = [];
1466
+
1467
+ for (const target of wanted) {
1468
+ const bad = checkRelPath(project, target);
1469
+ if (bad) {
1470
+ skipped.push({ path: target, reason: bad });
1471
+ continue;
1472
+ }
1473
+ const entry = byPath.get(target);
1474
+ if (!entry) {
1475
+ skipped.push({ path: target, reason: '本会话没有写入记录' });
1476
+ continue;
1477
+ }
1478
+ const abs = path.join(project.dir, target);
1479
+ try {
1480
+ if (entry.kind === 'create') {
1481
+ if (fs.existsSync(abs)) fs.rmSync(abs, { force: true });
1482
+ } else {
1483
+ // merge / update:还原写入前内容;before 为空且文件在则清空为 before
1484
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
1485
+ fs.writeFileSync(abs, String(entry.before ?? ''));
1486
+ }
1487
+ reverted.push({
1488
+ path: target,
1489
+ kind: entry.kind === 'create' ? 'deleted' : 'restored',
1490
+ role: entry.role || '',
1491
+ });
1492
+ byPath.delete(target);
1493
+ } catch (err) {
1494
+ return {
1495
+ ok: false,
1496
+ error: err instanceof Error ? err.message : String(err),
1497
+ reverted,
1498
+ skipped,
1499
+ };
1500
+ }
1501
+ }
1502
+
1503
+ if (!reverted.length) {
1504
+ return {
1505
+ ok: false,
1506
+ error: skipped[0]?.reason || '没有可撤销的写入',
1507
+ reverted,
1508
+ skipped,
1509
+ };
1510
+ }
1511
+
1512
+ const nextChanges = ledger.filter((entry) => byPath.has(normalizeRelPath(entry.path)));
1513
+ const revertedSet = new Set(reverted.map((item) => item.path));
1514
+ const prevSaved = Array.isArray(session?.savedPaths)
1515
+ ? session.savedPaths.map((item) => normalizeRelPath(item)).filter(Boolean)
1516
+ : [];
1517
+ const nextSaved = prevSaved.filter((item) => !revertedSet.has(item));
1518
+ // 主用例:优先保留仍在的 spec;否则取剩余第一条
1519
+ let nextSavedPath = normalizeRelPath(session?.savedPath || '');
1520
+ if (!nextSavedPath || revertedSet.has(nextSavedPath)) {
1521
+ const fromLedger = nextChanges.find((entry) => entry.role === 'spec')?.path;
1522
+ nextSavedPath = normalizeRelPath(fromLedger || nextSaved[0] || '');
1523
+ }
1524
+ const nextStatus =
1525
+ nextSaved.length || nextChanges.length
1526
+ ? 'written'
1527
+ : session?.lastVerify?.passed
1528
+ ? 'verified'
1529
+ : 'explored';
1530
+
1531
+ return {
1532
+ ok: true,
1533
+ reverted,
1534
+ skipped,
1535
+ paths: reverted.map((item) => item.path),
1536
+ changes: nextChanges,
1537
+ savedPaths: nextSaved,
1538
+ savedPath: nextSavedPath,
1539
+ status: nextStatus,
1540
+ };
1541
+ }
1542
+
1255
1543
  /** 写进项目(用户确认后才调用);返回 before/after 供「变更」面板出 diff */
1256
1544
  export function writeGeneratedFile({ project, session, relPath, force = false }) {
1257
1545
  const ir = normalizeIr(session.ir || {}, { target: session.target, title: session.title });
@@ -1,6 +1,9 @@
1
1
  /**
2
- * Node 版本:读项目约定的版本(`.nvmrc` / `package.json` 的 engines),
3
- * 再扫本机 nvm / fnm / volta 里已装好的版本。
2
+ * Node 版本:读项目约定的版本,再扫本机 nvm / fnm / volta 里已装好的版本。
3
+ *
4
+ * 声明优先级(有就停):
5
+ * `.nvmrc` → `.node-version` → `.tool-versions`(asdf/mise) →
6
+ * `package.json` volta.node → engines.node → `package-lock.json` 根 engines
4
7
  *
5
8
  * 只做两件事:把「项目要哪个 Node」查出来、把跑用例时的 PATH 指到那个 Node 的 bin。
6
9
  * 不去改用户 shell 的版本——`nvm use` 是 shell 函数,子进程里切了也不影响用户的终端;
@@ -144,27 +147,114 @@ export function listNodeInstallations() {
144
147
  });
145
148
  }
146
149
 
147
- /** 项目声明的 Node:`.nvmrc` 优先,其次 `.node-version`(fnm / asdf 也认这个),最后 engines */
150
+ /**
151
+ * 读版本文件里第一条有效版本行:跳过空行与 `#` 注释。
152
+ * 常见写法是文件头注释 + 下一行 `v22.23.0`;只读第一行会把「# nodejs 版本」当成要求。
153
+ */
154
+ export function readVersionFileLine(content) {
155
+ for (const raw of String(content ?? '').split(/\r?\n/)) {
156
+ const line = raw.trim();
157
+ if (!line || line.startsWith('#')) continue;
158
+ return line.replace(/^v/i, '');
159
+ }
160
+ return '';
161
+ }
162
+
163
+ /** asdf / mise:`.tool-versions` 里 `nodejs 22.23.0` 或 `node 22.23.0` */
164
+ export function readToolVersionsNode(content) {
165
+ for (const raw of String(content ?? '').split(/\r?\n/)) {
166
+ const line = raw.trim();
167
+ if (!line || line.startsWith('#')) continue;
168
+ const matched = /^(nodejs|node)\s+(\S+)/i.exec(line);
169
+ if (matched) return matched[2].replace(/^v/i, '');
170
+ }
171
+ return '';
172
+ }
173
+
174
+ /** package-lock.json 根包 engines.node(npm 装出来时常有) */
175
+ export function readLockfileNodeEngines(content) {
176
+ try {
177
+ const lock = JSON.parse(String(content ?? ''));
178
+ const root = lock?.packages?.[''] || lock?.packages?.['.'] || null;
179
+ const fromRoot = String(root?.engines?.node ?? '').trim();
180
+ if (fromRoot) return fromRoot;
181
+ return String(lock?.engines?.node ?? '').trim();
182
+ } catch {
183
+ return '';
184
+ }
185
+ }
186
+
187
+ /**
188
+ * 项目声明的 Node。
189
+ * 返回各来源字段 + `required`(实际生效)+ `source`(生效来源,便于面板展示)。
190
+ */
148
191
  export function readNodeRequirement(dir) {
149
192
  const root = path.resolve(dir);
150
- const readFirstLine = (name) => {
193
+ const readVersionFile = (name) => {
194
+ try {
195
+ return readVersionFileLine(fs.readFileSync(path.join(root, name), 'utf8'));
196
+ } catch {
197
+ return '';
198
+ }
199
+ };
200
+ const readText = (name) => {
151
201
  try {
152
- const first = fs.readFileSync(path.join(root, name), 'utf8').split(/\r?\n/)[0] ?? '';
153
- return first.trim().replace(/^v/i, '');
202
+ return fs.readFileSync(path.join(root, name), 'utf8');
154
203
  } catch {
155
204
  return '';
156
205
  }
157
206
  };
158
- const nvmrc = readFirstLine('.nvmrc');
159
- const nodeVersion = nvmrc ? '' : readFirstLine('.node-version');
207
+
208
+ const nvmrc = readVersionFile('.nvmrc');
209
+ const nodeVersion = readVersionFile('.node-version');
210
+ const toolVersions = readToolVersionsNode(readText('.tool-versions'));
211
+
212
+ let volta = '';
160
213
  let engines = '';
161
214
  try {
162
215
  const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
216
+ volta = String(pkg?.volta?.node ?? '')
217
+ .trim()
218
+ .replace(/^v/i, '');
163
219
  engines = String(pkg?.engines?.node ?? '').trim();
164
220
  } catch {
165
- engines = '';
221
+ // ignore
222
+ }
223
+
224
+ const lockfile = readLockfileNodeEngines(readText('package-lock.json'));
225
+
226
+ let required = '';
227
+ let source = '';
228
+ if (nvmrc) {
229
+ required = nvmrc;
230
+ source = 'nvmrc';
231
+ } else if (nodeVersion) {
232
+ required = nodeVersion;
233
+ source = 'node-version';
234
+ } else if (toolVersions) {
235
+ required = toolVersions;
236
+ source = 'tool-versions';
237
+ } else if (volta) {
238
+ required = volta;
239
+ source = 'volta';
240
+ } else if (engines) {
241
+ required = engines;
242
+ source = 'engines';
243
+ } else if (lockfile) {
244
+ required = lockfile;
245
+ source = 'lockfile';
166
246
  }
167
- return { nvmrc, nodeVersion, engines, required: nvmrc || nodeVersion || engines };
247
+
248
+ return {
249
+ nvmrc,
250
+ nodeVersion,
251
+ toolVersions,
252
+ volta,
253
+ engines,
254
+ lockfile,
255
+ required,
256
+ source,
257
+ };
168
258
  }
169
259
 
170
260
  /**
@@ -175,9 +265,10 @@ export function nodeStatus(dir) {
175
265
  const requirement = readNodeRequirement(dir);
176
266
  const running = process.versions.node;
177
267
  const installations = listNodeInstallations();
268
+ // 没声明版本时:尽量对齐本机已装、且等于当前进程的那一份,跑用例 PATH 更稳
178
269
  const match = requirement.required
179
270
  ? (installations.find((item) => satisfiesNode(item.version, requirement.required)) ?? null)
180
- : null;
271
+ : (installations.find((item) => satisfiesNode(item.version, running)) ?? null);
181
272
  return {
182
273
  ...requirement,
183
274
  running,