visual-living-plan 0.1.0 → 2.32.1

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 (608) hide show
  1. package/DESIGN.md +213 -0
  2. package/README.md +155 -28
  3. package/dist/AuthScreen.d.ts +9 -0
  4. package/dist/AuthScreen.js +7 -0
  5. package/dist/DesktopModeSwitch.d.ts +13 -0
  6. package/dist/DesktopModeSwitch.js +14 -0
  7. package/dist/OAuthMark.d.ts +6 -0
  8. package/dist/OAuthMark.js +8 -0
  9. package/dist/accountInitials.d.ts +5 -0
  10. package/dist/accountInitials.js +20 -0
  11. package/dist/accountLinking.d.ts +26 -0
  12. package/dist/accountLinking.js +46 -0
  13. package/dist/agentEvents.d.ts +31 -0
  14. package/dist/agentEvents.js +260 -0
  15. package/dist/agentPresence.d.ts +42 -0
  16. package/dist/agentPresence.js +69 -0
  17. package/dist/agentSkills.d.ts +35 -0
  18. package/dist/agentSkills.js +89 -0
  19. package/dist/agentStream.d.ts +35 -0
  20. package/dist/agentStream.js +133 -0
  21. package/dist/appearanceDom.d.ts +13 -0
  22. package/dist/appearanceDom.js +24 -0
  23. package/dist/appearanceSettings.d.ts +29 -0
  24. package/dist/appearanceSettings.js +293 -0
  25. package/dist/assets.d.ts +14 -0
  26. package/dist/assets.js +72 -0
  27. package/dist/authSearch.d.ts +11 -0
  28. package/dist/authSearch.js +30 -0
  29. package/dist/changelog.d.ts +11 -0
  30. package/dist/changelog.js +63 -0
  31. package/dist/changelogParse.d.ts +53 -0
  32. package/dist/changelogParse.js +226 -0
  33. package/dist/cli.d.ts +2 -0
  34. package/dist/cli.js +1684 -0
  35. package/dist/cliLauncher.d.ts +40 -0
  36. package/dist/cliLauncher.js +170 -0
  37. package/dist/cliToken.d.ts +11 -0
  38. package/dist/cliToken.js +15 -0
  39. package/dist/client/.vite/manifest.json +1780 -0
  40. package/dist/client/assets/BarChart-DtV3dIq4.js +1 -0
  41. package/dist/client/assets/BlockEditor-BklSUBjk.js +168 -0
  42. package/dist/client/assets/BlockEditor-K5h6xc4_.css +1 -0
  43. package/dist/client/assets/CodeBlock-BbI08MlQ.js +1 -0
  44. package/dist/client/assets/CodeBlock-BxRMnldw.js +175 -0
  45. package/dist/client/assets/LineChart-CQYMEbD6.js +1 -0
  46. package/dist/client/assets/Mermaid-Ciu9eIoG.js +1 -0
  47. package/dist/client/assets/Mermaid-jPWLXX7e.js +1 -0
  48. package/dist/client/assets/Popover-DbE4vUPG.js +1 -0
  49. package/dist/client/assets/ReactFlowExecutionCanvas-BhVs-adc.js +7 -0
  50. package/dist/client/assets/ReactFlowExecutionCanvas-DLioOiRN.css +1 -0
  51. package/dist/client/assets/StatusIcon-C_-Lm9b4.js +1 -0
  52. package/dist/client/assets/Workflow-C92OpLyf.js +1 -0
  53. package/dist/client/assets/agentPresence-D8asHrTp.js +1 -0
  54. package/dist/client/assets/andromeeda-DW8vo71h.js +1 -0
  55. package/dist/client/assets/andromeeda-vGVdxbeo.js +1 -0
  56. package/dist/client/assets/arrow-up-CEVVOXD5.js +1 -0
  57. package/dist/client/assets/arrow-up-down-BSjnQK2I.js +1 -0
  58. package/dist/client/assets/aurora-x-CDeNXAV0.js +1 -0
  59. package/dist/client/assets/aurora-x-rMvKqtYI.js +1 -0
  60. package/dist/client/assets/ayu-dark-CwczpL8O.js +1 -0
  61. package/dist/client/assets/ayu-dark-DluEY0Gj.js +1 -0
  62. package/dist/client/assets/ayu-light-C3h-C4tm.js +1 -0
  63. package/dist/client/assets/ayu-light-DSh22xiD.js +1 -0
  64. package/dist/client/assets/ayu-mirage-Bqwy1Gya.js +1 -0
  65. package/dist/client/assets/ayu-mirage-JE6hAyHG.js +1 -0
  66. package/dist/client/assets/browserStore-BDGKYoJj.js +435 -0
  67. package/dist/client/assets/button-BI07wqbi.css +1 -0
  68. package/dist/client/assets/button-DJWAGApe.js +1 -0
  69. package/dist/client/assets/catppuccin-frappe-C9Q5zVZY.js +1 -0
  70. package/dist/client/assets/catppuccin-frappe-pyXErRRU.js +1 -0
  71. package/dist/client/assets/catppuccin-latte-BILSUICr.js +1 -0
  72. package/dist/client/assets/catppuccin-latte-CtsyrtPq.js +1 -0
  73. package/dist/client/assets/catppuccin-macchiato-Ck60ZZQE.js +1 -0
  74. package/dist/client/assets/catppuccin-macchiato-R8nAf1vR.js +1 -0
  75. package/dist/client/assets/catppuccin-mocha-C_2G67cS.js +1 -0
  76. package/dist/client/assets/catppuccin-mocha-DjuaAJKi.js +1 -0
  77. package/dist/client/assets/ccount-nzzEXTrh.js +1 -0
  78. package/dist/client/assets/chartRows-CNjjLsAH.js +2 -0
  79. package/dist/client/assets/circle-x-BLGxA3gi.js +1 -0
  80. package/dist/client/assets/client-BsE_buVT.js +9 -0
  81. package/dist/client/assets/constants-CmGPilXJ.js +1 -0
  82. package/dist/client/assets/dark-plus-CHgc6GYj.js +1 -0
  83. package/dist/client/assets/dark-plus-Cs2F2srj.js +1 -0
  84. package/dist/client/assets/default-5FplaXL4.js +7 -0
  85. package/dist/client/assets/diffsTheme-PJJTu2Rq.js +1 -0
  86. package/dist/client/assets/dracula-BHWKrbxM.js +1 -0
  87. package/dist/client/assets/dracula-Cf1PG3MT.js +1 -0
  88. package/dist/client/assets/dracula-soft-5eyTD99u.js +1 -0
  89. package/dist/client/assets/dracula-soft-DXuNm1Kq.js +1 -0
  90. package/dist/client/assets/editSource-DQfw4nRm.js +1 -0
  91. package/dist/client/assets/editSource-U5AoD-Wo.js +14 -0
  92. package/dist/client/assets/engine-CLTPZlti.js +1 -0
  93. package/dist/client/assets/engine-DUyaiAMV.js +2 -0
  94. package/dist/client/assets/everforest-dark-CjdfwUBe.js +1 -0
  95. package/dist/client/assets/everforest-dark-sB-x3p7T.js +1 -0
  96. package/dist/client/assets/everforest-light-CfVwwCBP.js +1 -0
  97. package/dist/client/assets/everforest-light-Df2xbC6M.js +1 -0
  98. package/dist/client/assets/forgetDocuments-CIUBitCs.js +1 -0
  99. package/dist/client/assets/formatCSSVariablePrefix-KRh9vnZf.js +1 -0
  100. package/dist/client/assets/github-dark-BL6HSl_n.js +1 -0
  101. package/dist/client/assets/github-dark-C-LZuMrd.js +1 -0
  102. package/dist/client/assets/github-dark-default-DXG-b-1a.js +1 -0
  103. package/dist/client/assets/github-dark-default-zacuWV-M.js +1 -0
  104. package/dist/client/assets/github-dark-dimmed-Bx1FflLF.js +1 -0
  105. package/dist/client/assets/github-dark-dimmed-Mc0P9idi.js +1 -0
  106. package/dist/client/assets/github-dark-high-contrast-B_tTalzw.js +1 -0
  107. package/dist/client/assets/github-dark-high-contrast-IMKX2AVF.js +1 -0
  108. package/dist/client/assets/github-light-EUqPIrTm.js +1 -0
  109. package/dist/client/assets/github-light-default-BXViO-2h.js +1 -0
  110. package/dist/client/assets/github-light-default-DVlCqP3X.js +1 -0
  111. package/dist/client/assets/github-light-high-contrast-B68TUdTA.js +1 -0
  112. package/dist/client/assets/github-light-high-contrast-Dj6zTyWR.js +1 -0
  113. package/dist/client/assets/github-light-mYhEBkPo.js +1 -0
  114. package/dist/client/assets/gruvbox-dark-hard-C820rvS2.js +1 -0
  115. package/dist/client/assets/gruvbox-dark-hard-QTgQQZn-.js +1 -0
  116. package/dist/client/assets/gruvbox-dark-medium-9d5YdCTx.js +1 -0
  117. package/dist/client/assets/gruvbox-dark-medium-BPjhmG05.js +1 -0
  118. package/dist/client/assets/gruvbox-dark-soft-MrdJrrXF.js +1 -0
  119. package/dist/client/assets/gruvbox-dark-soft-XCkqeBhR.js +1 -0
  120. package/dist/client/assets/gruvbox-light-hard--5-nXqNp.js +1 -0
  121. package/dist/client/assets/gruvbox-light-hard-BC_s9l72.js +1 -0
  122. package/dist/client/assets/gruvbox-light-medium-BAWPOn9u.js +1 -0
  123. package/dist/client/assets/gruvbox-light-medium-COA1PZW2.js +1 -0
  124. package/dist/client/assets/gruvbox-light-soft-BSMLrYjP.js +1 -0
  125. package/dist/client/assets/gruvbox-light-soft-CIJpzjAO.js +1 -0
  126. package/dist/client/assets/hastToHtml-Dj8rXue9.js +11 -0
  127. package/dist/client/assets/highlight-cB-PkhyE.js +1 -0
  128. package/dist/client/assets/highlights-LLBF1DTm.js +1 -0
  129. package/dist/client/assets/horizon-Ba2cwkSy.js +1 -0
  130. package/dist/client/assets/horizon-CE9ld1lL.js +1 -0
  131. package/dist/client/assets/horizon-bright-DSNQnXHK.js +1 -0
  132. package/dist/client/assets/horizon-bright-DaEDgBmR.js +1 -0
  133. package/dist/client/assets/houston-B6x0XVpU.js +1 -0
  134. package/dist/client/assets/houston-CsvMBhTu.js +1 -0
  135. package/dist/client/assets/jsx-runtime-DKj5X9O4.js +1 -0
  136. package/dist/client/assets/kanagawa-dragon-Bozd7klA.js +1 -0
  137. package/dist/client/assets/kanagawa-dragon-DhTFvBMT.js +1 -0
  138. package/dist/client/assets/kanagawa-lotus--m8sdOxn.js +1 -0
  139. package/dist/client/assets/kanagawa-lotus-BmuOG9ZW.js +1 -0
  140. package/dist/client/assets/kanagawa-wave-BML5mF2J.js +1 -0
  141. package/dist/client/assets/kanagawa-wave-D-tTv4k2.js +1 -0
  142. package/dist/client/assets/laserwave-C_8bwKvT.js +1 -0
  143. package/dist/client/assets/laserwave-HSLx0L75.js +1 -0
  144. package/dist/client/assets/lib-COgu-QLX.js +33 -0
  145. package/dist/client/assets/lib-CdRiGVUZ.js +1 -0
  146. package/dist/client/assets/light-plus-CUjWrTSi.js +1 -0
  147. package/dist/client/assets/light-plus-DVQuIRkW.js +1 -0
  148. package/dist/client/assets/loader-CjL04K29.js +1 -0
  149. package/dist/client/assets/main-BGMX_GnZ.js +2 -0
  150. package/dist/client/assets/main-BTko4EvJ.css +1 -0
  151. package/dist/client/assets/material-theme-Bm3Qr25_.js +1 -0
  152. package/dist/client/assets/material-theme-CnthUGfg.js +1 -0
  153. package/dist/client/assets/material-theme-darker-2IIEA8gg.js +1 -0
  154. package/dist/client/assets/material-theme-darker-DUi03Qre.js +1 -0
  155. package/dist/client/assets/material-theme-lighter-D2-qr5Vw.js +1 -0
  156. package/dist/client/assets/material-theme-lighter-uhdI0v04.js +1 -0
  157. package/dist/client/assets/material-theme-ocean-CHQ94UKr.js +1 -0
  158. package/dist/client/assets/material-theme-ocean-CWR-LogA.js +1 -0
  159. package/dist/client/assets/material-theme-palenight-B5W6OYN7.js +1 -0
  160. package/dist/client/assets/material-theme-palenight-Cnv8m1ra.js +1 -0
  161. package/dist/client/assets/mdxEntries-BNTMP8ct.css +1 -0
  162. package/dist/client/assets/mdxEntries-L-V7bB6i.js +1 -0
  163. package/dist/client/assets/mermaid-Bjhs-krb.js +1 -0
  164. package/dist/client/assets/mermaid-Di4j-zgD.js +146 -0
  165. package/dist/client/assets/min-dark-BSWPekZh.js +1 -0
  166. package/dist/client/assets/min-dark-EXoM-6Xo.js +1 -0
  167. package/dist/client/assets/min-light-DDpmG2fV.js +1 -0
  168. package/dist/client/assets/min-light-DVOTDhnA.js +1 -0
  169. package/dist/client/assets/monokai-BscAjiQZ.js +1 -0
  170. package/dist/client/assets/monokai-DkggTbGy.js +1 -0
  171. package/dist/client/assets/mountChrome-BVWpsDCy.js +122 -0
  172. package/dist/client/assets/mountChrome-DhTDH3YM.css +1 -0
  173. package/dist/client/assets/night-owl-Bdcs0PMi.js +1 -0
  174. package/dist/client/assets/night-owl-DhmEMT88.js +1 -0
  175. package/dist/client/assets/night-owl-light-RoU30LE0.js +1 -0
  176. package/dist/client/assets/night-owl-light-eJ-hLW7d.js +1 -0
  177. package/dist/client/assets/noShiki-DB8hQ_W3.js +1 -0
  178. package/dist/client/assets/noShiki-GTG3tT8x.js +1 -0
  179. package/dist/client/assets/nord-Cb4Vim4T.js +1 -0
  180. package/dist/client/assets/nord-u7hMircQ.js +1 -0
  181. package/dist/client/assets/offlineSync-Cv3FVIlJ.js +1 -0
  182. package/dist/client/assets/one-dark-pro-08PdtLzi.js +1 -0
  183. package/dist/client/assets/one-dark-pro-C6YyR8OD.js +1 -0
  184. package/dist/client/assets/one-light-D7Lr4KcI.js +1 -0
  185. package/dist/client/assets/one-light-DgvUEtgI.js +1 -0
  186. package/dist/client/assets/opfs-worker-DuTOCgWR.js +5919 -0
  187. package/dist/client/assets/pierre-dark-B2jZWvHG.js +1 -0
  188. package/dist/client/assets/pierre-dark-CpLgRqie.js +1 -0
  189. package/dist/client/assets/pierre-dark-protanopia-deuteranopia-B35FxJx-.js +1 -0
  190. package/dist/client/assets/pierre-dark-protanopia-deuteranopia-CebgQdRf.js +1 -0
  191. package/dist/client/assets/pierre-dark-soft-DdE7dyP3.js +1 -0
  192. package/dist/client/assets/pierre-dark-soft-kZQmAZld.js +1 -0
  193. package/dist/client/assets/pierre-dark-tritanopia-CXimiT7X.js +1 -0
  194. package/dist/client/assets/pierre-dark-tritanopia-CpjhbsIL.js +1 -0
  195. package/dist/client/assets/pierre-dark-vibrant-CpQYzh95.js +1 -0
  196. package/dist/client/assets/pierre-dark-vibrant-DzBsxHvQ.js +1 -0
  197. package/dist/client/assets/pierre-light-CoaEpmwp.js +1 -0
  198. package/dist/client/assets/pierre-light-Vf__O3ev.js +1 -0
  199. package/dist/client/assets/pierre-light-protanopia-deuteranopia-0fSaH845.js +1 -0
  200. package/dist/client/assets/pierre-light-protanopia-deuteranopia-BUtWcCQC.js +1 -0
  201. package/dist/client/assets/pierre-light-soft-C3QCXKvN.js +1 -0
  202. package/dist/client/assets/pierre-light-soft-lWLdNTOI.js +1 -0
  203. package/dist/client/assets/pierre-light-tritanopia-CEbqgOJL.js +1 -0
  204. package/dist/client/assets/pierre-light-tritanopia-CKLy6XvA.js +1 -0
  205. package/dist/client/assets/pierre-light-vibrant-D80Fkn33.js +1 -0
  206. package/dist/client/assets/pierre-light-vibrant-DDuTEIhH.js +1 -0
  207. package/dist/client/assets/planEditButton-CbWGczbi.js +45 -0
  208. package/dist/client/assets/planEvents-cuzv9ELr.js +1 -0
  209. package/dist/client/assets/planMdx-Db1ze_nN.js +110 -0
  210. package/dist/client/assets/plastic-B8mE6BxX.js +1 -0
  211. package/dist/client/assets/plastic-DQwYfKfQ.js +1 -0
  212. package/dist/client/assets/poimandres-DRFjx7u4.js +1 -0
  213. package/dist/client/assets/poimandres-DUFjrgxT.js +1 -0
  214. package/dist/client/assets/preload-helper-Dx0-lKy1.js +1 -0
  215. package/dist/client/assets/queryClient-Bs5tSUJh.js +1 -0
  216. package/dist/client/assets/react-dom-DpzJPrWF.js +1 -0
  217. package/dist/client/assets/rebaseDraft-B2--cj1c.js +19 -0
  218. package/dist/client/assets/red-BJvdDEUx.js +1 -0
  219. package/dist/client/assets/red-CYlAq2b0.js +1 -0
  220. package/dist/client/assets/register-hZEIk3A9.css +1 -0
  221. package/dist/client/assets/register-htm5s8o9.js +1 -0
  222. package/dist/client/assets/rolldown-runtime-Dd_uD5pT.js +1 -0
  223. package/dist/client/assets/rose-pine-BSqRqUae.js +1 -0
  224. package/dist/client/assets/rose-pine-aMsaMD1D.js +1 -0
  225. package/dist/client/assets/rose-pine-dawn-8PwUyIlP.js +1 -0
  226. package/dist/client/assets/rose-pine-dawn-U6TBE82u.js +1 -0
  227. package/dist/client/assets/rose-pine-moon-CAU7u1h4.js +1 -0
  228. package/dist/client/assets/rose-pine-moon-DO-qXg-I.js +1 -0
  229. package/dist/client/assets/routeEdges-B2z8v0di.js +24 -0
  230. package/dist/client/assets/selector-CDsXW7SO.css +1 -0
  231. package/dist/client/assets/selector-tlBGWtQl.js +1 -0
  232. package/dist/client/assets/settingsChrome-NGUDtEIp.js +1 -0
  233. package/dist/client/assets/shiki-BOXJeUHI.js +2 -0
  234. package/dist/client/assets/slack-dark-CMu0smFa.js +1 -0
  235. package/dist/client/assets/slack-dark-DnToyrRv.js +1 -0
  236. package/dist/client/assets/slack-ochin-B2OO5cIa.js +1 -0
  237. package/dist/client/assets/slack-ochin-BBne7cjw.js +1 -0
  238. package/dist/client/assets/snazzy-light-4G7pJPwS.js +1 -0
  239. package/dist/client/assets/snazzy-light-CV8HUEmk.js +1 -0
  240. package/dist/client/assets/solarized-dark-CmYmhSgI.js +1 -0
  241. package/dist/client/assets/solarized-dark-b97czJOk.js +1 -0
  242. package/dist/client/assets/solarized-light-CjLLwxRp.js +1 -0
  243. package/dist/client/assets/solarized-light-DFPxpIYQ.js +1 -0
  244. package/dist/client/assets/stampPlanParts-DVXYCykw.js +15 -0
  245. package/dist/client/assets/stampPlanParts-ctZzxWdw.css +1 -0
  246. package/dist/client/assets/stream-tokenizer-C3n8hi1h.js +4 -0
  247. package/dist/client/assets/synthwave-84-nFMaYfgc.js +1 -0
  248. package/dist/client/assets/synthwave-84-wQeDKbzQ.js +1 -0
  249. package/dist/client/assets/textChildren-ZDSs1dod.js +1 -0
  250. package/dist/client/assets/themes-CdTJhjZf.js +2 -0
  251. package/dist/client/assets/tokyo-night-D4ZgDiA7.js +1 -0
  252. package/dist/client/assets/tokyo-night-oM2G3aXe.js +1 -0
  253. package/dist/client/assets/triangle-alert-C9Sgr3jF.js +1 -0
  254. package/dist/client/assets/unwrapDefault-ByDmBtHB.js +1 -0
  255. package/dist/client/assets/utils-C9Glzetk.js +2 -0
  256. package/dist/client/assets/versionView-zkSROPw7.js +1 -0
  257. package/dist/client/assets/vesper-DdrHHSXu.js +1 -0
  258. package/dist/client/assets/vesper-sUHevyKv.js +1 -0
  259. package/dist/client/assets/vitesse-black-CfklMpOb.js +1 -0
  260. package/dist/client/assets/vitesse-black-fwtXNY1n.js +1 -0
  261. package/dist/client/assets/vitesse-dark-BZCL-v6S.js +1 -0
  262. package/dist/client/assets/vitesse-dark-CJkzwmKT.js +1 -0
  263. package/dist/client/assets/vitesse-light-BxMp8E1Y.js +1 -0
  264. package/dist/client/assets/vitesse-light-VbXTXTou.js +1 -0
  265. package/dist/client/assets/wa-sqlite-Ba70bhIr.wasm +0 -0
  266. package/dist/client/assets/warmPlans-CYFrLwcX.js +1 -0
  267. package/dist/client/assets/with-selector-HIcjK0_d.js +1 -0
  268. package/dist/client/assets/workflowSource-LMsRuqF_.js +3 -0
  269. package/dist/client/favicon.png +0 -0
  270. package/dist/client/icons/apple-touch-icon-180x180.png +0 -0
  271. package/dist/client/icons/favicon.ico +0 -0
  272. package/dist/client/icons/maskable-icon-192x192.png +0 -0
  273. package/dist/client/icons/maskable-icon-512x512.png +0 -0
  274. package/dist/client/icons/pwa-16x16.png +0 -0
  275. package/dist/client/icons/pwa-192x192.png +0 -0
  276. package/dist/client/icons/pwa-32x32.png +0 -0
  277. package/dist/client/icons/pwa-512x512.png +0 -0
  278. package/dist/client/icons/pwa-64x64.png +0 -0
  279. package/dist/clientLog.d.ts +5 -0
  280. package/dist/clientLog.js +64 -0
  281. package/dist/cloudClient.d.ts +38 -0
  282. package/dist/cloudClient.js +185 -0
  283. package/dist/cloudCommand.d.ts +23 -0
  284. package/dist/cloudCommand.js +159 -0
  285. package/dist/cloudFrontmatter.d.ts +4 -0
  286. package/dist/cloudFrontmatter.js +30 -0
  287. package/dist/cloudStore.d.ts +28 -0
  288. package/dist/cloudStore.js +70 -0
  289. package/dist/cloudWatch.d.ts +12 -0
  290. package/dist/cloudWatch.js +103 -0
  291. package/dist/commentReply.d.ts +25 -0
  292. package/dist/commentReply.js +17 -0
  293. package/dist/configHome.d.ts +34 -0
  294. package/dist/configHome.js +136 -0
  295. package/dist/dashboard.d.ts +67 -0
  296. package/dist/dashboard.js +86 -0
  297. package/dist/dashboardClientScript.d.ts +2 -0
  298. package/dist/dashboardClientScript.js +1006 -0
  299. package/dist/dashboardDocument.d.ts +13 -0
  300. package/dist/dashboardDocument.js +40 -0
  301. package/dist/dashboardFormat.d.ts +98 -0
  302. package/dist/dashboardFormat.js +199 -0
  303. package/dist/dashboardLoading.d.ts +19 -0
  304. package/dist/dashboardLoading.js +94 -0
  305. package/dist/dashboardOverview.d.ts +28 -0
  306. package/dist/dashboardOverview.js +333 -0
  307. package/dist/dashboardPage.d.ts +2 -0
  308. package/dist/dashboardPage.js +11 -0
  309. package/dist/dashboardParts.d.ts +4 -0
  310. package/dist/dashboardParts.js +367 -0
  311. package/dist/dashboardSearchView.d.ts +38 -0
  312. package/dist/dashboardSearchView.js +255 -0
  313. package/dist/desktopApp.d.ts +23 -0
  314. package/dist/desktopApp.js +110 -0
  315. package/dist/desktopBridge.d.ts +21 -0
  316. package/dist/desktopBridge.js +78 -0
  317. package/dist/desktopCommand.d.ts +61 -0
  318. package/dist/desktopCommand.js +172 -0
  319. package/dist/desktopConfig.d.ts +54 -0
  320. package/dist/desktopConfig.js +164 -0
  321. package/dist/desktopNotices.d.ts +105 -0
  322. package/dist/desktopNotices.js +427 -0
  323. package/dist/diff.d.ts +2 -0
  324. package/dist/diff.js +46 -0
  325. package/dist/diffsTheme.d.ts +51 -0
  326. package/dist/diffsTheme.js +86 -0
  327. package/dist/diffsThemeCatalog.d.ts +3 -0
  328. package/dist/diffsThemeCatalog.js +78 -0
  329. package/dist/elkRuntime.node.d.ts +7 -0
  330. package/dist/elkRuntime.node.js +63 -0
  331. package/dist/execution.d.ts +78 -0
  332. package/dist/execution.js +139 -0
  333. package/dist/expectedWorkflow.d.ts +11 -0
  334. package/dist/expectedWorkflow.js +99 -0
  335. package/dist/favicon.d.ts +4 -0
  336. package/dist/favicon.js +40 -0
  337. package/dist/favicon.png +0 -0
  338. package/dist/faviconBase64.d.ts +1 -0
  339. package/dist/faviconBase64.js +1 -0
  340. package/dist/fileVersion.d.ts +8 -0
  341. package/dist/fileVersion.js +20 -0
  342. package/dist/formatBytes.d.ts +2 -0
  343. package/dist/formatBytes.js +13 -0
  344. package/dist/gitStatus.d.ts +12 -0
  345. package/dist/gitStatus.js +88 -0
  346. package/dist/hostToolbar.d.ts +38 -0
  347. package/dist/hostToolbar.js +249 -0
  348. package/dist/http.d.ts +8 -0
  349. package/dist/http.js +38 -0
  350. package/dist/httpServer.d.ts +13 -0
  351. package/dist/httpServer.js +40 -0
  352. package/dist/icons/apple-touch-icon-180x180.png +0 -0
  353. package/dist/icons/favicon.ico +0 -0
  354. package/dist/icons/maskable-icon-192x192.png +0 -0
  355. package/dist/icons/maskable-icon-512x512.png +0 -0
  356. package/dist/icons/pwa-16x16.png +0 -0
  357. package/dist/icons/pwa-192x192.png +0 -0
  358. package/dist/icons/pwa-32x32.png +0 -0
  359. package/dist/icons/pwa-512x512.png +0 -0
  360. package/dist/icons/pwa-64x64.png +0 -0
  361. package/dist/lanAccess.d.ts +31 -0
  362. package/dist/lanAccess.js +110 -0
  363. package/dist/lanAddress.d.ts +24 -0
  364. package/dist/lanAddress.js +174 -0
  365. package/dist/lanCommand.d.ts +25 -0
  366. package/dist/lanCommand.js +159 -0
  367. package/dist/lanConfig.d.ts +40 -0
  368. package/dist/lanConfig.js +130 -0
  369. package/dist/lanFirewall.d.ts +17 -0
  370. package/dist/lanFirewall.js +221 -0
  371. package/dist/layoutGraph.d.ts +13 -0
  372. package/dist/layoutGraph.js +55 -0
  373. package/dist/localName.d.ts +9 -0
  374. package/dist/localName.js +28 -0
  375. package/dist/lockBanner.d.ts +2 -0
  376. package/dist/lockBanner.js +2 -0
  377. package/dist/mdnsPacket.d.ts +44 -0
  378. package/dist/mdnsPacket.js +384 -0
  379. package/dist/mdnsPublish.d.ts +12 -0
  380. package/dist/mdnsPublish.js +290 -0
  381. package/dist/offlineSync.d.ts +249 -0
  382. package/dist/offlineSync.js +477 -0
  383. package/dist/openUrl.d.ts +40 -0
  384. package/dist/openUrl.js +147 -0
  385. package/dist/openedPages.d.ts +14 -0
  386. package/dist/openedPages.js +48 -0
  387. package/dist/pageEditPull.d.ts +9 -0
  388. package/dist/pageEditPull.js +29 -0
  389. package/dist/pageRoutes.d.ts +3 -0
  390. package/dist/pageRoutes.js +34 -0
  391. package/dist/parse.d.ts +7 -0
  392. package/dist/parse.js +100 -0
  393. package/dist/pid.d.ts +2 -0
  394. package/dist/pid.js +13 -0
  395. package/dist/planArchive.d.ts +4 -0
  396. package/dist/planArchive.js +28 -0
  397. package/dist/planEntries.d.ts +12 -0
  398. package/dist/planEntries.js +117 -0
  399. package/dist/planHost.d.ts +31 -0
  400. package/dist/planHost.js +286 -0
  401. package/dist/planId.d.ts +2 -0
  402. package/dist/planId.js +6 -0
  403. package/dist/planMdx/blockEdit.d.ts +41 -0
  404. package/dist/planMdx/blockEdit.js +60 -0
  405. package/dist/planMdx/cellPart.d.ts +14 -0
  406. package/dist/planMdx/cellPart.js +26 -0
  407. package/dist/planMdx/compilePlanMdx.d.ts +3 -0
  408. package/dist/planMdx/compilePlanMdx.js +22 -0
  409. package/dist/planMdx/editSource.d.ts +39 -0
  410. package/dist/planMdx/editSource.js +327 -0
  411. package/dist/planMdx/frontmatter.d.ts +5 -0
  412. package/dist/planMdx/frontmatter.js +15 -0
  413. package/dist/planMdx/markdown.d.ts +6 -0
  414. package/dist/planMdx/markdown.js +470 -0
  415. package/dist/planMdx/outline.d.ts +8 -0
  416. package/dist/planMdx/outline.js +548 -0
  417. package/dist/planMdx/payload.d.ts +4 -0
  418. package/dist/planMdx/payload.js +18 -0
  419. package/dist/planMdx/rebaseDraft.d.ts +54 -0
  420. package/dist/planMdx/rebaseDraft.js +675 -0
  421. package/dist/planMdx/recmaPlanComponents.d.ts +18 -0
  422. package/dist/planMdx/recmaPlanComponents.js +52 -0
  423. package/dist/planMdx/remarkBlockRanges.d.ts +104 -0
  424. package/dist/planMdx/remarkBlockRanges.js +275 -0
  425. package/dist/planMdx/remarkCodeMeta.d.ts +16 -0
  426. package/dist/planMdx/remarkCodeMeta.js +25 -0
  427. package/dist/planMdx/remarkGfmTable.d.ts +5 -0
  428. package/dist/planMdx/remarkGfmTable.js +15 -0
  429. package/dist/planMdx/remarkGfmTaskList.d.ts +5 -0
  430. package/dist/planMdx/remarkGfmTaskList.js +15 -0
  431. package/dist/planMdx/remarkMermaid.d.ts +16 -0
  432. package/dist/planMdx/remarkMermaid.js +56 -0
  433. package/dist/planMdx/source.d.ts +11 -0
  434. package/dist/planMdx/source.js +131 -0
  435. package/dist/planMdx/titleEdit.d.ts +35 -0
  436. package/dist/planMdx/titleEdit.js +112 -0
  437. package/dist/planPage.css +2125 -0
  438. package/dist/planProgress.d.ts +17 -0
  439. package/dist/planProgress.js +78 -0
  440. package/dist/planReady.d.ts +8 -0
  441. package/dist/planReady.js +20 -0
  442. package/dist/planRefNavigation.d.ts +4 -0
  443. package/dist/planRefNavigation.js +8 -0
  444. package/dist/planRoutes.d.ts +12 -0
  445. package/dist/planRoutes.js +141 -0
  446. package/dist/planSearch.d.ts +166 -0
  447. package/dist/planSearch.js +462 -0
  448. package/dist/planSession.d.ts +130 -0
  449. package/dist/planSession.js +1182 -0
  450. package/dist/planSnapshots.d.ts +34 -0
  451. package/dist/planSnapshots.js +113 -0
  452. package/dist/planStatus.d.ts +26 -0
  453. package/dist/planStatus.js +46 -0
  454. package/dist/planStepHeading.d.ts +16 -0
  455. package/dist/planStepHeading.js +34 -0
  456. package/dist/planTarget.d.ts +16 -0
  457. package/dist/planTarget.js +92 -0
  458. package/dist/planToc.d.ts +24 -0
  459. package/dist/planToc.js +258 -0
  460. package/dist/planVersionMenu.d.ts +12 -0
  461. package/dist/planVersionMenu.js +23 -0
  462. package/dist/processRecord.d.ts +108 -0
  463. package/dist/processRecord.js +68 -0
  464. package/dist/processesPanel.d.ts +7 -0
  465. package/dist/processesPanel.js +636 -0
  466. package/dist/pwaIconFile.d.ts +2 -0
  467. package/dist/pwaIconFile.js +42 -0
  468. package/dist/pwaIcons.d.ts +28 -0
  469. package/dist/pwaIcons.js +46 -0
  470. package/dist/registerServiceWorker.d.ts +25 -0
  471. package/dist/registerServiceWorker.js +26 -0
  472. package/dist/registryClient.d.ts +94 -0
  473. package/dist/registryClient.js +490 -0
  474. package/dist/registryConstants.d.ts +9 -0
  475. package/dist/registryConstants.js +9 -0
  476. package/dist/registryLock.d.ts +19 -0
  477. package/dist/registryLock.js +48 -0
  478. package/dist/registryPage.d.ts +2 -0
  479. package/dist/registryPage.js +284 -0
  480. package/dist/registryService.d.ts +21 -0
  481. package/dist/registryService.js +562 -0
  482. package/dist/registryStore.d.ts +63 -0
  483. package/dist/registryStore.js +398 -0
  484. package/dist/releaseNotes.d.ts +35 -0
  485. package/dist/releaseNotes.js +62 -0
  486. package/dist/render.d.ts +50 -0
  487. package/dist/render.js +1506 -0
  488. package/dist/requestGuard.d.ts +21 -0
  489. package/dist/requestGuard.js +42 -0
  490. package/dist/reviewRound.d.ts +12 -0
  491. package/dist/reviewRound.js +19 -0
  492. package/dist/runFollow.d.ts +28 -0
  493. package/dist/runFollow.js +33 -0
  494. package/dist/searchMatch.d.ts +35 -0
  495. package/dist/searchMatch.js +270 -0
  496. package/dist/server.d.ts +24 -0
  497. package/dist/server.js +114 -0
  498. package/dist/serviceLog.d.ts +56 -0
  499. package/dist/serviceLog.js +481 -0
  500. package/dist/shellCache.d.ts +69 -0
  501. package/dist/shellCache.js +289 -0
  502. package/dist/shellWorker.js +322 -0
  503. package/dist/shellWorkerResponse.d.ts +4 -0
  504. package/dist/shellWorkerResponse.js +15 -0
  505. package/dist/startServer.d.ts +2 -0
  506. package/dist/startServer.js +2 -0
  507. package/dist/store/meta.d.ts +53 -0
  508. package/dist/store/meta.js +140 -0
  509. package/dist/store/migrate.d.ts +3 -0
  510. package/dist/store/migrate.js +408 -0
  511. package/dist/store/rows.d.ts +4 -0
  512. package/dist/store/rows.js +100 -0
  513. package/dist/store/schema.d.ts +5 -0
  514. package/dist/store/schema.js +5 -0
  515. package/dist/store/sqlite.d.ts +19 -0
  516. package/dist/store/sqlite.js +57 -0
  517. package/dist/store/tables.d.ts +1892 -0
  518. package/dist/store/tables.js +136 -0
  519. package/dist/theme.d.ts +174 -0
  520. package/dist/theme.js +444 -0
  521. package/dist/themeBootstrap.d.ts +2 -0
  522. package/dist/themeBootstrap.js +11 -0
  523. package/dist/tui/DashboardApp.d.ts +19 -0
  524. package/dist/tui/DashboardApp.js +237 -0
  525. package/dist/tui/PaletteProvider.d.ts +12 -0
  526. package/dist/tui/PaletteProvider.js +36 -0
  527. package/dist/tui/PlanActions.d.ts +7 -0
  528. package/dist/tui/PlanActions.js +9 -0
  529. package/dist/tui/PlanCard.d.ts +13 -0
  530. package/dist/tui/PlanCard.js +31 -0
  531. package/dist/tui/PlanRow.d.ts +13 -0
  532. package/dist/tui/PlanRow.js +31 -0
  533. package/dist/tui/PlanTable.d.ts +13 -0
  534. package/dist/tui/PlanTable.js +24 -0
  535. package/dist/tui/ProcessCard.d.ts +9 -0
  536. package/dist/tui/ProcessCard.js +24 -0
  537. package/dist/tui/ProcessList.d.ts +9 -0
  538. package/dist/tui/ProcessList.js +12 -0
  539. package/dist/tui/SegmentButton.d.ts +7 -0
  540. package/dist/tui/SegmentButton.js +18 -0
  541. package/dist/tui/StatCard.d.ts +6 -0
  542. package/dist/tui/StatCard.js +17 -0
  543. package/dist/tui/dashboardView.d.ts +45 -0
  544. package/dist/tui/dashboardView.js +192 -0
  545. package/dist/tui/openExternal.d.ts +2 -0
  546. package/dist/tui/openExternal.js +5 -0
  547. package/dist/tui/palette.d.ts +27 -0
  548. package/dist/tui/palette.js +66 -0
  549. package/dist/tui/planColumns.d.ts +38 -0
  550. package/dist/tui/planColumns.js +14 -0
  551. package/dist/tui/readDashboard.d.ts +3 -0
  552. package/dist/tui/readDashboard.js +15 -0
  553. package/dist/tui/readProcesses.d.ts +3 -0
  554. package/dist/tui/readProcesses.js +23 -0
  555. package/dist/tui/registryView.d.ts +11 -0
  556. package/dist/tui/registryView.js +56 -0
  557. package/dist/tui/runTui.d.ts +21 -0
  558. package/dist/tui/runTui.js +86 -0
  559. package/dist/tui/systemTheme.d.ts +28 -0
  560. package/dist/tui/systemTheme.js +141 -0
  561. package/dist/types.d.ts +191 -0
  562. package/dist/types.js +0 -0
  563. package/dist/webManifest.d.ts +39 -0
  564. package/dist/webManifest.js +48 -0
  565. package/dist/workflow.d.ts +8 -0
  566. package/dist/workflow.js +42 -0
  567. package/dist/workflowLayoutShared.d.ts +25 -0
  568. package/dist/workflowLayoutShared.js +33 -0
  569. package/dist/workflowSource.d.ts +31 -0
  570. package/dist/workflowSource.js +90 -0
  571. package/docs/changelogs/changelog-2026-10-27.md +203 -0
  572. package/docs/changelogs/changelog-2026-10-28.md +181 -0
  573. package/docs/changelogs/changelog-2026-10-29.md +349 -0
  574. package/docs/changelogs/changelog-2026-10-30.md +303 -0
  575. package/docs/changelogs/changelog-2026-10-31.md +129 -0
  576. package/docs/changelogs/changelog-2026-11-01.md +155 -0
  577. package/docs/changelogs/changelog-2026-11-02.md +195 -0
  578. package/docs/changelogs/changelog-2026-11-03.md +209 -0
  579. package/docs/changelogs/changelog-2026-11-04.md +243 -0
  580. package/docs/changelogs/changelog-2026-11-05.md +172 -0
  581. package/docs/changelogs/changelog-2026-11-06.md +123 -0
  582. package/docs/changelogs/changelog-2026-11-07.md +138 -0
  583. package/docs/changelogs/changelog-2026-11-08.md +47 -0
  584. package/docs/changelogs/changelog-2026-11-10.md +219 -0
  585. package/docs/changelogs/changelog-2026-11-11.md +205 -0
  586. package/docs/changelogs/changelog-2026-11-12.md +44 -0
  587. package/docs/changelogs/changelog-2026-11-13.md +48 -0
  588. package/docs/changelogs/changelog-2026-11-14.md +116 -0
  589. package/docs/changelogs/changelog-2026-11-15.md +31 -0
  590. package/docs/changelogs/changelog-2026-11-16.md +41 -0
  591. package/docs/changelogs/changelog-2026-11-17.md +25 -0
  592. package/docs/changelogs/changelog-2026-11-18.md +71 -0
  593. package/docs/changelogs/changelog-2026-11-19.md +19 -0
  594. package/examples/cloud-showcase.plan.md +181 -0
  595. package/examples/component-showcase.plan.md +378 -0
  596. package/examples/component-tour.plan.md +168 -0
  597. package/examples/data-table.plan.md +917 -0
  598. package/examples/execution-graph.json +15 -5
  599. package/examples/form-controls.plan.md +51 -0
  600. package/examples/live-plan.config.json +5 -0
  601. package/examples/rate-limit.plan.md +110 -78
  602. package/examples/submission-delivery-runbook.md +122 -0
  603. package/examples/submission-delivery.plan.md +107 -0
  604. package/examples/tables.plan.md +61 -0
  605. package/package.json +86 -15
  606. package/skills/live-plan/SKILL.md +381 -0
  607. package/skills/live-plan/primitives.md +738 -0
  608. package/skills/living-plan/SKILL.md +0 -71
@@ -0,0 +1,1182 @@
1
+ import { nanoid } from 'nanoid';
2
+ import { watch } from 'node:fs';
3
+ import { readFile, stat, writeFile } from 'node:fs/promises';
4
+ import { basename, dirname, extname, join, normalize, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { clientDistDir, loadClientAssets } from './assets';
7
+ import { html, HttpError, jsonBody } from './http';
8
+ import { inspectMutation, readBaseRevision, readUpdatedAt, rememberMutation, } from './offlineSync';
9
+ import { diffSections } from './diff';
10
+ import { applyExecutionChange, createIdleExecutionState, readExecutionPatch } from './execution';
11
+ import { collectSectionSources, parsePlan } from './parse';
12
+ import { recordLog } from './serviceLog';
13
+ import { AGENT_KEEPALIVE_MS, agentPresence } from './agentPresence';
14
+ import { loadLatestChangelog, loadPackageVersion } from './changelog';
15
+ import { defaultRegistryHome, globalThemeConfigPath } from './configHome';
16
+ import { openPlanSnapshots } from './planSnapshots';
17
+ import { SearchRequestError, searchParams, searchPlanDocuments } from './planSearch';
18
+ import { registryDatabasePath } from './registryLock';
19
+ import { renderPlanPage } from './render';
20
+ import { configPathBesidePlan, isKnownDiffsTheme, isPageWidth, loadThemeConfig, normalizeAccent, normalizeDiffsTheme, saveThemeConfig, themePayload, } from './theme';
21
+ import { planToExpectedGraph, withPlannedWorkflow } from './workflow';
22
+ import { planNotReadyReason } from './planReady';
23
+ import { INVALID_ITERATION, readIteration, UNREAD_VERDICT } from './reviewRound';
24
+ import { approvesRun, nextRunState } from './runFollow';
25
+ const MIME = {
26
+ '.js': 'text/javascript; charset=utf-8',
27
+ '.css': 'text/css; charset=utf-8',
28
+ '.map': 'application/json; charset=utf-8',
29
+ '.svg': 'image/svg+xml',
30
+ '.png': 'image/png',
31
+ '.woff2': 'font/woff2',
32
+ // The browser SQLite store compiles this with streaming only when it is served as wasm.
33
+ '.wasm': 'application/wasm',
34
+ };
35
+ /** How often an open page hears from the stream when nothing else happens. */
36
+ export const BROWSER_KEEPALIVE_MS = 20_000;
37
+ /** Pause after the last change to the plan file before it is read again. */
38
+ const RELOAD_SETTLE_MS = 120;
39
+ export async function readClientAsset(pathname) {
40
+ // Accept /client/assets/..., assets/..., or a bare path under dist/client.
41
+ const stripped = pathname.replace(/^\/client\//, '').replace(/^\//, '');
42
+ const relative = normalize(stripped);
43
+ if (relative.startsWith('..') || relative.includes('\0'))
44
+ throw new HttpError(400, 'Invalid path');
45
+ try {
46
+ const filePath = join(clientDistDir(), relative);
47
+ const info = await stat(filePath);
48
+ if (!info.isFile())
49
+ return null;
50
+ const body = await readFile(filePath);
51
+ return new Response(body, {
52
+ headers: {
53
+ 'content-type': MIME[extname(filePath)] ?? 'application/octet-stream',
54
+ 'cache-control': 'no-cache',
55
+ },
56
+ });
57
+ }
58
+ catch {
59
+ return null;
60
+ }
61
+ }
62
+ export async function openPlanSession(options) {
63
+ const id = options.id;
64
+ const token = options.token;
65
+ const planPath = resolve(options.planPath);
66
+ let mode = options.mode;
67
+ let iteration = options.iteration ?? 1;
68
+ const cwd = options.cwd ?? dirname(planPath);
69
+ const basePath = options.basePath ?? '';
70
+ const selfId = options.selfId ?? id;
71
+ const startedAt = options.startedAt ?? Date.now();
72
+ const themeConfigPath = resolve(options.configPath ?? configPathBesidePlan(planPath));
73
+ const clientAssets = await loadClientAssets();
74
+ let source = await readFile(planPath, 'utf8');
75
+ let plan = parsePlan(source, planPath, id);
76
+ let previousSections = collectSectionSources(plan);
77
+ let diffs = previousSections.map((_, index) => ({
78
+ index,
79
+ status: 'unchanged',
80
+ }));
81
+ let theme = await loadThemeConfig(themeConfigPath, globalThemeConfigPath());
82
+ let lastSeenAt = options.lastSeenAt ?? startedAt;
83
+ let closed = false;
84
+ let mdxStore = null;
85
+ try {
86
+ const opened = openPlanSnapshots(registryDatabasePath(defaultRegistryHome()), id);
87
+ try {
88
+ opened.sync(plan.title, source);
89
+ mdxStore = opened;
90
+ }
91
+ catch (error) {
92
+ opened.close();
93
+ throw error;
94
+ }
95
+ }
96
+ catch (error) {
97
+ void recordLog({
98
+ level: 'warn',
99
+ message: 'Plan snapshots did not open',
100
+ detail: error instanceof Error ? error.message : undefined,
101
+ source: 'plan',
102
+ planId: id,
103
+ }).catch(() => undefined);
104
+ }
105
+ function mdxPayload() {
106
+ return {
107
+ source,
108
+ title: plan.title,
109
+ responses,
110
+ locked: Boolean(execution.active),
111
+ revision,
112
+ snapshots: mdxStore?.list() ?? [],
113
+ headSnapshotId: mdxStore?.head()?.headSnapshotId ?? null,
114
+ };
115
+ }
116
+ function search(url) {
117
+ touch();
118
+ let params;
119
+ try {
120
+ params = searchParams(url);
121
+ }
122
+ catch (error) {
123
+ if (error instanceof SearchRequestError)
124
+ throw new HttpError(error.status, error.message);
125
+ throw error;
126
+ }
127
+ // Saved versions are read only when the request asks for them.
128
+ const saved = params.version === 'live'
129
+ ? []
130
+ : (mdxStore?.list() ?? []).map((row) => ({ seq: row.seq, title: row.title, source: row.body, createdAt: row.createdAt }));
131
+ if (typeof params.version === 'number' && !saved.some((row) => row.seq === params.version)) {
132
+ throw new HttpError(404, `Version ${params.version} is not saved for this plan.`);
133
+ }
134
+ return searchPlanDocuments({
135
+ planId: id,
136
+ ...params,
137
+ live: { seq: 'live', title: plan.title, source, createdAt: null },
138
+ saved,
139
+ });
140
+ }
141
+ function offlineSnapshot() {
142
+ touch();
143
+ return {
144
+ revision,
145
+ source,
146
+ title: plan.title,
147
+ mode,
148
+ responses,
149
+ comments: comments.map((comment) => ({ ...comment })),
150
+ review: reviewResult ?? null,
151
+ locked: Boolean(execution.active),
152
+ };
153
+ }
154
+ const responses = { ...(options.responses ?? {}) };
155
+ const waiters = new Map();
156
+ const browserClients = new Set();
157
+ const agentClients = new Set();
158
+ let agentSeenAt = null;
159
+ let announcedAgents = 0;
160
+ let execution = options.execution ? { ...options.execution } : createIdleExecutionState();
161
+ let reviewResult = options.review ?? undefined;
162
+ let reviewWaiters = [];
163
+ const comments = [...(options.comments ?? [])];
164
+ const eventLog = (options.events ?? []).map((event) => ({
165
+ ...event,
166
+ data: structuredClone(event.data),
167
+ }));
168
+ let agentSeq = eventLog.reduce((max, event) => Math.max(max, event.seq), 0);
169
+ let revision = options.revision ?? 0;
170
+ let idempotency = [...(options.idempotency ?? [])];
171
+ let themeUpdatedAt = options.themeUpdatedAt ?? 0;
172
+ function guarded(kind, body, request, locks) {
173
+ const key = request?.headers.get('idempotency-key')?.trim() || null;
174
+ const decision = inspectMutation({
175
+ kind,
176
+ key,
177
+ body,
178
+ baseRevision: readBaseRevision(body),
179
+ currentRevision: revision,
180
+ executionActive: locks && Boolean(execution.active),
181
+ source,
182
+ records: idempotency,
183
+ });
184
+ if (decision.action === 'replay')
185
+ return { body: {}, replay: decision.result, key };
186
+ if (decision.action === 'reject')
187
+ throw new HttpError(409, decision.message);
188
+ return { body: decision.body, key };
189
+ }
190
+ function note(key, body, result) {
191
+ if (!key)
192
+ return;
193
+ idempotency = rememberMutation(idempotency, key, body, result);
194
+ persist();
195
+ }
196
+ function eventKey(event, data) {
197
+ if (!data || typeof data !== 'object')
198
+ return null;
199
+ const record = data;
200
+ if ((event === 'interaction' || event === 'comment') && typeof record.id === 'string')
201
+ return `${event}:${record.id}`;
202
+ if (event === 'review' && typeof record.decision === 'string') {
203
+ return `review:${String(record.iteration ?? '')}:${record.decision}`;
204
+ }
205
+ return null;
206
+ }
207
+ function remember(event, data, createdAt) {
208
+ agentSeq += 1;
209
+ const record = {
210
+ id: `evt_${nanoid()}`,
211
+ seq: agentSeq,
212
+ event,
213
+ data: structuredClone(data),
214
+ createdAt,
215
+ deliveredAt: null,
216
+ };
217
+ eventLog.push(record);
218
+ return record;
219
+ }
220
+ function backfillEvents() {
221
+ const keys = new Set(eventLog.flatMap((event) => {
222
+ const key = eventKey(event.event, event.data);
223
+ return key ? [key] : [];
224
+ }));
225
+ for (const response of Object.values(responses)) {
226
+ const key = eventKey('interaction', response);
227
+ if (!key || keys.has(key))
228
+ continue;
229
+ remember('interaction', response, startedAt);
230
+ keys.add(key);
231
+ }
232
+ if (reviewResult) {
233
+ const key = eventKey('review', reviewResult);
234
+ if (key && !keys.has(key)) {
235
+ remember('review', reviewResult, startedAt);
236
+ keys.add(key);
237
+ }
238
+ }
239
+ for (const comment of comments) {
240
+ if (comment.addressedAt != null || comment.addressingAt)
241
+ continue;
242
+ const key = eventKey('comment', comment);
243
+ if (!key || keys.has(key))
244
+ continue;
245
+ remember('comment', comment, comment.createdAt);
246
+ keys.add(key);
247
+ }
248
+ }
249
+ backfillEvents();
250
+ function pendingEvents() {
251
+ return eventLog
252
+ .filter((event) => event.deliveredAt == null)
253
+ .sort((left, right) => left.seq - right.seq)
254
+ .map((event) => ({ ...event }));
255
+ }
256
+ function pushEvent(event, data) {
257
+ const record = remember(event, data, Date.now());
258
+ for (const client of agentClients)
259
+ client.write('notice', { ...record });
260
+ }
261
+ function persist() {
262
+ if (closed)
263
+ return;
264
+ options.onChange?.(snapshot());
265
+ }
266
+ function touch() {
267
+ lastSeenAt = Date.now();
268
+ }
269
+ function currentTheme() {
270
+ return themePayload(theme, themeConfigPath);
271
+ }
272
+ function pendingInteractionIds() {
273
+ return plan.interactionIds.filter((interactionId) => !responses[interactionId]);
274
+ }
275
+ function executionView() {
276
+ return withPlannedWorkflow(execution, plan, Object.keys(responses));
277
+ }
278
+ function snapshot() {
279
+ return {
280
+ id,
281
+ token,
282
+ planPath,
283
+ mode,
284
+ iteration,
285
+ cwd,
286
+ configPath: themeConfigPath,
287
+ responses: { ...responses },
288
+ execution: { ...execution },
289
+ review: reviewResult ?? null,
290
+ comments: comments.map((comment) => ({ ...comment })),
291
+ events: eventLog.map((event) => ({ ...event })),
292
+ revision,
293
+ idempotency: idempotency.map((record) => ({ ...record })),
294
+ themeUpdatedAt,
295
+ startedAt,
296
+ lastSeenAt,
297
+ };
298
+ }
299
+ function broadcast(event, data) {
300
+ for (const client of browserClients)
301
+ client.write(event, data);
302
+ for (const client of agentClients)
303
+ client.write(event, data);
304
+ }
305
+ function broadcastBrowsers(event, data) {
306
+ for (const client of browserClients)
307
+ client.write(event, data);
308
+ }
309
+ function eventStream(bucket, hello, signal, options = {}) {
310
+ const encoder = new TextEncoder();
311
+ let client;
312
+ const leave = () => {
313
+ if (!client || !bucket.delete(client))
314
+ return;
315
+ options.onMembership?.();
316
+ };
317
+ let keepAlive;
318
+ const stopKeepAlive = () => {
319
+ if (keepAlive)
320
+ clearInterval(keepAlive);
321
+ keepAlive = undefined;
322
+ };
323
+ const stream = new ReadableStream({
324
+ start(controller) {
325
+ let closed = false;
326
+ client = {
327
+ write(event, data) {
328
+ if (closed)
329
+ return;
330
+ try {
331
+ controller.enqueue(encoder.encode(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`));
332
+ }
333
+ catch {
334
+ closed = true;
335
+ stopKeepAlive();
336
+ leave();
337
+ }
338
+ },
339
+ close() {
340
+ if (closed)
341
+ return;
342
+ closed = true;
343
+ stopKeepAlive();
344
+ leave();
345
+ try {
346
+ controller.close();
347
+ }
348
+ catch {
349
+ // The client already went away.
350
+ }
351
+ },
352
+ };
353
+ bucket.add(client);
354
+ client.write('hello', hello);
355
+ options.onMembership?.();
356
+ // A page tells a live stream from a dead one by these pings, and reconnects when they stop.
357
+ if (options.keepAliveMs)
358
+ keepAlive = setInterval(() => client?.write('ping', { at: Date.now() }), options.keepAliveMs);
359
+ touch();
360
+ persist();
361
+ signal.addEventListener('abort', () => {
362
+ client?.close();
363
+ touch();
364
+ persist();
365
+ }, { once: true });
366
+ },
367
+ cancel() {
368
+ client?.close();
369
+ touch();
370
+ persist();
371
+ },
372
+ });
373
+ return new Response(stream, {
374
+ headers: {
375
+ 'content-type': 'text/event-stream',
376
+ 'cache-control': 'no-cache, no-transform',
377
+ connection: 'keep-alive',
378
+ },
379
+ });
380
+ }
381
+ async function applyTheme(next, save) {
382
+ theme = next;
383
+ if (save)
384
+ theme = await saveThemeConfig(themeConfigPath, next);
385
+ const payload = currentTheme();
386
+ broadcast('theme', payload);
387
+ return payload;
388
+ }
389
+ async function reloadThemeFromDisk() {
390
+ const next = await loadThemeConfig(themeConfigPath, globalThemeConfigPath());
391
+ if (next.accent === theme.accent &&
392
+ next.pageWidth === theme.pageWidth &&
393
+ next.diffsTheme === theme.diffsTheme &&
394
+ next.wrapCode === theme.wrapCode) {
395
+ return;
396
+ }
397
+ theme = next;
398
+ broadcast('theme', currentTheme());
399
+ }
400
+ function setExecution(next) {
401
+ if (next.graph && !Array.isArray(next.graph.nodes)) {
402
+ void recordLog({
403
+ level: 'warn',
404
+ message: 'Execution graph has no nodes array',
405
+ source: 'execution',
406
+ planId: id,
407
+ echo: false,
408
+ }).catch(() => undefined);
409
+ }
410
+ const wasActive = execution.active;
411
+ const willBeActive = Boolean(next.active);
412
+ if (wasActive !== willBeActive)
413
+ revision += 1;
414
+ const action = !wasActive && willBeActive ? 'started' : wasActive && !willBeActive ? 'stopped' : wasActive ? 'updated' : undefined;
415
+ if (action) {
416
+ const label = action === 'started' ? 'Execution started' : action === 'stopped' ? 'Execution stopped' : 'Execution updated';
417
+ const step = next.step?.trim();
418
+ void recordLog({
419
+ level: 'log',
420
+ message: step ? `${label}: ${step}` : label,
421
+ detail: next.detail,
422
+ source: 'execution',
423
+ planId: id,
424
+ echo: false,
425
+ }).catch(() => undefined);
426
+ }
427
+ execution = {
428
+ active: willBeActive,
429
+ step: next.step,
430
+ detail: next.detail,
431
+ graph: next.graph,
432
+ scene: next.scene,
433
+ updatedAt: Date.now(),
434
+ ...(next.follow ? { follow: next.follow } : {}),
435
+ };
436
+ const view = executionView();
437
+ broadcast('execution', { ...view, revision });
438
+ persist();
439
+ return view;
440
+ }
441
+ /**
442
+ * Start or end the run the way the plan file says (`runFollow.ts`). Every step done or one failed
443
+ * ends it. Only a new plan source (`mayStart`) can start it, after an approval. Returns true when the
444
+ * run changed; the change was then broadcast.
445
+ */
446
+ function settleRun(mayStart = false) {
447
+ const change = nextRunState(executionView(), { mayStart });
448
+ if (!change)
449
+ return false;
450
+ setExecution({ ...execution, active: change.active, step: execution.step ?? (change.active ? 'Executing' : undefined) });
451
+ return true;
452
+ }
453
+ let heldReason;
454
+ async function reloadFromDisk() {
455
+ const nextSource = await readFile(planPath, 'utf8');
456
+ if (nextSource === source)
457
+ return;
458
+ // A half-written or broken edit is not sent. The page keeps the last good plan.
459
+ const reason = await planNotReadyReason(nextSource);
460
+ if (nextSource !== (await readFile(planPath, 'utf8')))
461
+ return;
462
+ if (reason) {
463
+ if (heldReason !== reason) {
464
+ void recordLog({
465
+ level: 'warn',
466
+ message: `Plan edit not shown yet: ${reason}`,
467
+ source: 'plan',
468
+ planId: id,
469
+ }).catch(() => undefined);
470
+ }
471
+ heldReason = reason;
472
+ return;
473
+ }
474
+ heldReason = undefined;
475
+ applySource(nextSource);
476
+ }
477
+ /** Show a new plan source: parse it, keep a snapshot, and tell the page and the canvas. */
478
+ function applySource(nextSource) {
479
+ revision += 1;
480
+ const nextPlan = parsePlan(nextSource, planPath, id);
481
+ const nextSections = collectSectionSources(nextPlan);
482
+ diffs = diffSections(previousSections, nextSections);
483
+ previousSections = nextSections;
484
+ source = nextSource;
485
+ plan = nextPlan;
486
+ try {
487
+ const applied = mdxStore?.sync(nextPlan.title, nextSource);
488
+ if (applied?.changed)
489
+ broadcastBrowsers('plan', mdxPayload());
490
+ }
491
+ catch (error) {
492
+ void recordLog({
493
+ level: 'warn',
494
+ message: 'Plan snapshot was not saved',
495
+ detail: error instanceof Error ? error.message : undefined,
496
+ source: 'plan',
497
+ planId: id,
498
+ }).catch(() => undefined);
499
+ }
500
+ broadcast('reload', { at: Date.now(), changed: diffs.filter((diff) => diff.status !== 'unchanged').length });
501
+ // A phase marked active, done, or failed can start or end the run.
502
+ if (!settleRun(true))
503
+ broadcast('execution', { ...executionView(), revision });
504
+ persist();
505
+ }
506
+ /**
507
+ * Save a plan edited on the page. `base` is the source the editor started from. When the file
508
+ * changed since then (the agent wrote it), the save is refused so neither edit is lost.
509
+ */
510
+ async function saveMdxSource(body) {
511
+ touch();
512
+ if (execution.active)
513
+ throw new HttpError(409, 'The plan cannot be edited while execution is live');
514
+ const input = (body && typeof body === 'object' ? body : {});
515
+ if (typeof input.source !== 'string' || typeof input.base !== 'string') {
516
+ throw new HttpError(400, 'source and base are required');
517
+ }
518
+ const onDisk = await readFile(planPath, 'utf8');
519
+ if (input.base !== onDisk)
520
+ throw new HttpError(409, 'The plan changed while you were editing. Reload to see the new version.');
521
+ if (input.source === onDisk)
522
+ return mdxPayload();
523
+ const reason = await planNotReadyReason(input.source);
524
+ if (reason)
525
+ throw new HttpError(400, reason);
526
+ // The watcher sees this write, finds the source unchanged, and does nothing.
527
+ source = input.source;
528
+ await writeFile(planPath, input.source);
529
+ applySource(input.source);
530
+ pushEvent('edit', { at: Date.now(), title: plan.title, by: 'page' });
531
+ return mdxPayload();
532
+ }
533
+ function fulfillInteraction(response) {
534
+ if (execution.active) {
535
+ throw new Error('Plan interactions are locked while execution is live');
536
+ }
537
+ responses[response.id] = response;
538
+ const queue = waiters.get(response.id) ?? [];
539
+ waiters.delete(response.id);
540
+ for (const waiter of queue) {
541
+ if (waiter.timer)
542
+ clearTimeout(waiter.timer);
543
+ waiter.resolve(response);
544
+ }
545
+ pushEvent('interaction', response);
546
+ broadcast('interaction', response);
547
+ // An approve gate answered yes lets the agent's next edit of the plan file start the run.
548
+ if (approvesRun({ response }))
549
+ execution = { ...execution, follow: 'armed' };
550
+ // An answered step is done on the workflow too.
551
+ if (!settleRun())
552
+ broadcast('execution', { ...executionView(), revision });
553
+ persist();
554
+ }
555
+ function fulfillReview(decision, note) {
556
+ if (execution.active) {
557
+ throw new Error('Review is locked while execution is live');
558
+ }
559
+ if (reviewResult)
560
+ return;
561
+ const sent = decision === 'iterate' ? comments.filter((comment) => comment.addressedAt == null) : [];
562
+ const startedAt = Date.now();
563
+ for (const comment of sent) {
564
+ if (!comment.addressingAt)
565
+ comment.addressingAt = startedAt;
566
+ }
567
+ reviewResult = {
568
+ decision,
569
+ note,
570
+ comments: sent.map((comment) => ({
571
+ id: comment.id,
572
+ sectionId: comment.blockId ?? comment.partId,
573
+ text: comment.text,
574
+ })),
575
+ responses: Object.values(responses),
576
+ iteration,
577
+ };
578
+ for (const waiter of reviewWaiters) {
579
+ if (waiter.timer)
580
+ clearTimeout(waiter.timer);
581
+ waiter.resolve(reviewResult);
582
+ }
583
+ reviewWaiters = [];
584
+ for (const comment of sent)
585
+ broadcast('comment', { ...comment });
586
+ pushEvent('review', reviewResult);
587
+ broadcast('review', reviewResult);
588
+ if (decision === 'iterate') {
589
+ broadcast('mode', { mode, iteration, review: reviewResult });
590
+ }
591
+ else {
592
+ mode = 'watch';
593
+ broadcast('mode', { mode, iteration, review: reviewResult });
594
+ }
595
+ // From here the run follows the plan file: the agent's next edit with a phase past pending starts it.
596
+ if (approvesRun({ decision }))
597
+ execution = { ...execution, follow: 'armed' };
598
+ persist();
599
+ }
600
+ function page() {
601
+ touch();
602
+ return html(renderPlanPage({
603
+ plan,
604
+ mode,
605
+ responses,
606
+ diffs,
607
+ iteration,
608
+ pendingInteractionIds: pendingInteractionIds(),
609
+ reviewDecision: reviewResult?.decision,
610
+ review: reviewResult ?? null,
611
+ execution,
612
+ comments,
613
+ clientAssets,
614
+ theme: currentTheme(),
615
+ agent: currentAgentPresence(),
616
+ basePath,
617
+ dashboardHref: options.dashboardHref,
618
+ selfId,
619
+ changelog: loadLatestChangelog(fileURLToPath(import.meta.url)),
620
+ appVersion: loadPackageVersion(fileURLToPath(import.meta.url)),
621
+ mdxSnapshots: mdxStore?.list() ?? [],
622
+ mdxHeadSnapshotId: mdxStore?.head()?.headSnapshotId ?? null,
623
+ }));
624
+ }
625
+ function planMdxPayload() {
626
+ touch();
627
+ return mdxPayload();
628
+ }
629
+ async function restoreMdxSnapshot(snapshotId) {
630
+ touch();
631
+ if (!mdxStore)
632
+ throw new HttpError(404, 'Snapshots are not available');
633
+ let applied;
634
+ try {
635
+ applied = mdxStore.restore(snapshotId);
636
+ }
637
+ catch (error) {
638
+ throw new HttpError(404, error instanceof Error ? error.message : 'Snapshot not found');
639
+ }
640
+ if (applied.changed) {
641
+ source = applied.plan.body;
642
+ plan = parsePlan(source, planPath, id);
643
+ previousSections = collectSectionSources(plan);
644
+ diffs = previousSections.map((_, index) => ({ index, status: 'unchanged' }));
645
+ await writeFile(planPath, source);
646
+ broadcastBrowsers('plan', mdxPayload());
647
+ broadcast('reload', { at: Date.now(), changed: 1 });
648
+ persist();
649
+ }
650
+ return mdxPayload();
651
+ }
652
+ function planPayload() {
653
+ touch();
654
+ return {
655
+ plan: {
656
+ title: plan.title,
657
+ summary: plan.summary,
658
+ agent: plan.agent,
659
+ interactionIds: plan.interactionIds,
660
+ sourcePath: plan.sourcePath,
661
+ },
662
+ mode,
663
+ iteration,
664
+ responses,
665
+ pendingInteractionIds: pendingInteractionIds(),
666
+ review: reviewResult ?? null,
667
+ comments,
668
+ diffs,
669
+ execution: executionView(),
670
+ planned: planToExpectedGraph(plan, Object.keys(responses)) ?? null,
671
+ theme: currentTheme(),
672
+ };
673
+ }
674
+ function themeView() {
675
+ touch();
676
+ return { ...currentTheme(), updatedAt: themeUpdatedAt };
677
+ }
678
+ async function updateTheme(body) {
679
+ touch();
680
+ const payload = jsonBody(body, true);
681
+ const hasAccent = payload.accent !== undefined;
682
+ const hasPageWidth = payload.pageWidth !== undefined;
683
+ const hasFullWidth = payload.fullWidth !== undefined;
684
+ const hasDiffsTheme = payload.diffsTheme !== undefined;
685
+ const hasWrapCode = payload.wrapCode !== undefined;
686
+ const incomingAt = readUpdatedAt(payload);
687
+ if (incomingAt != null && themeUpdatedAt > incomingAt) {
688
+ return { ok: true, theme: themeView() };
689
+ }
690
+ if (!hasAccent && !hasPageWidth && !hasFullWidth && !hasDiffsTheme && !hasWrapCode) {
691
+ throw new HttpError(400, 'Provide accent, pageWidth, diffsTheme, and/or wrapCode.');
692
+ }
693
+ let accent = theme.accent;
694
+ if (hasAccent) {
695
+ const normalized = normalizeAccent(payload.accent);
696
+ if (!normalized)
697
+ throw new HttpError(400, 'Invalid accent color. Use a hex value like #0f766e.');
698
+ accent = normalized;
699
+ }
700
+ let pageWidth = theme.pageWidth;
701
+ if (hasPageWidth) {
702
+ if (!isPageWidth(payload.pageWidth)) {
703
+ throw new HttpError(400, 'Page width must be default, wide, or full.');
704
+ }
705
+ pageWidth = payload.pageWidth;
706
+ }
707
+ else if (hasFullWidth) {
708
+ pageWidth = payload.fullWidth ? 'wide' : 'default';
709
+ }
710
+ let diffsTheme = theme.diffsTheme;
711
+ if (hasDiffsTheme) {
712
+ if (!isKnownDiffsTheme(payload.diffsTheme)) {
713
+ throw new HttpError(400, 'Unknown Pierre diffs theme.');
714
+ }
715
+ diffsTheme = normalizeDiffsTheme(payload.diffsTheme);
716
+ }
717
+ let wrapCode = theme.wrapCode;
718
+ if (hasWrapCode) {
719
+ if (typeof payload.wrapCode !== 'boolean') {
720
+ throw new HttpError(400, 'wrapCode must be true or false.');
721
+ }
722
+ wrapCode = payload.wrapCode;
723
+ }
724
+ const view = await applyTheme({ accent, pageWidth, diffsTheme, wrapCode }, true);
725
+ themeUpdatedAt = incomingAt ?? Date.now();
726
+ persist();
727
+ return { ok: true, theme: { ...view, updatedAt: themeUpdatedAt } };
728
+ }
729
+ function executionPayload() {
730
+ touch();
731
+ return executionView();
732
+ }
733
+ function updateExecution(body) {
734
+ touch();
735
+ const payload = jsonBody(body, true);
736
+ const stopping = execution.active && !payload.active;
737
+ const follow = stopping ? 'off' : execution.follow;
738
+ setExecution({
739
+ active: Boolean(payload.active),
740
+ step: payload.step ? String(payload.step) : undefined,
741
+ detail: payload.detail ? String(payload.detail) : undefined,
742
+ graph: payload.graph,
743
+ scene: payload.scene && typeof payload.scene === 'object' ? payload.scene : undefined,
744
+ ...(follow ? { follow } : {}),
745
+ });
746
+ settleRun();
747
+ return { ok: true, execution: executionView() };
748
+ }
749
+ function changeExecution(action, body) {
750
+ touch();
751
+ const patch = readExecutionPatch(jsonBody(body, false));
752
+ setExecution(applyExecutionChange(execution, action, patch));
753
+ // A pushed graph with every step done ends the run.
754
+ settleRun();
755
+ return { ok: true, execution: executionView() };
756
+ }
757
+ function startExecution(body) {
758
+ return changeExecution('start', body);
759
+ }
760
+ function pushExecution(body) {
761
+ return changeExecution('push', body);
762
+ }
763
+ function stopExecution(body) {
764
+ return changeExecution('stop', body);
765
+ }
766
+ function browserEvents(request) {
767
+ touch();
768
+ return eventStream(browserClients, {
769
+ mode,
770
+ pendingInteractionIds: pendingInteractionIds(),
771
+ review: reviewResult ?? null,
772
+ comments,
773
+ execution: executionView(),
774
+ theme: currentTheme(),
775
+ agent: currentAgentPresence(),
776
+ }, request.signal, { keepAliveMs: BROWSER_KEEPALIVE_MS });
777
+ }
778
+ function agentEvents(request) {
779
+ touch();
780
+ return eventStream(agentClients, {
781
+ mode,
782
+ iteration,
783
+ pendingInteractionIds: pendingInteractionIds(),
784
+ responses,
785
+ review: reviewResult ?? null,
786
+ comments,
787
+ execution: executionView(),
788
+ pending: pendingEvents(),
789
+ }, request.signal, { keepAliveMs: AGENT_KEEPALIVE_MS, onMembership: agentsChanged });
790
+ }
791
+ function currentAgentPresence() {
792
+ return agentPresence(agentClients.size, agentSeenAt);
793
+ }
794
+ /** An agent stream opened or closed. Open pages hear the new count. */
795
+ function agentsChanged() {
796
+ agentSeenAt = Date.now();
797
+ const count = agentClients.size;
798
+ if (count === announcedAgents)
799
+ return;
800
+ announcedAgents = count;
801
+ broadcastBrowsers('agent', currentAgentPresence());
802
+ }
803
+ function submitInteraction(interactionId, body, request) {
804
+ touch();
805
+ const gate = guarded('interaction', body, request, true);
806
+ if (gate.replay)
807
+ return gate.replay;
808
+ const payload = jsonBody(gate.body, true);
809
+ if (!plan.interactionIds.includes(interactionId)) {
810
+ throw new HttpError(404, `Unknown interaction id: ${interactionId}`);
811
+ }
812
+ if (payload.id !== interactionId)
813
+ throw new HttpError(400, 'Interaction id mismatch');
814
+ try {
815
+ fulfillInteraction(payload);
816
+ }
817
+ catch (error) {
818
+ throw new HttpError(409, error instanceof Error ? error.message : 'Interaction locked');
819
+ }
820
+ const result = {
821
+ ok: true,
822
+ response: payload,
823
+ pendingInteractionIds: pendingInteractionIds(),
824
+ };
825
+ note(gate.key, gate.body, result);
826
+ return result;
827
+ }
828
+ function submitComment(body, request) {
829
+ touch();
830
+ const gate = guarded('comment', body, request, true);
831
+ if (gate.replay)
832
+ return gate.replay;
833
+ const payload = jsonBody(gate.body, true);
834
+ const partId = String(payload.partId ?? '').trim();
835
+ const text = String(payload.text ?? '').trim();
836
+ if (!/^[A-Za-z0-9_.:/-]{1,200}$/.test(partId))
837
+ throw new HttpError(400, 'Missing plan part');
838
+ if (!text || text.length > 4000)
839
+ throw new HttpError(400, 'Missing comment');
840
+ const blockId = String(payload.blockId ?? '').trim().slice(0, 80);
841
+ const kind = String(payload.kind ?? '').trim().slice(0, 40);
842
+ const comment = {
843
+ id: `cmt_${nanoid()}`,
844
+ partId,
845
+ kind: kind || 'part',
846
+ ...(blockId ? { blockId } : {}),
847
+ excerpt: String(payload.excerpt ?? '').replace(/\s+/g, ' ').trim().slice(0, 180),
848
+ text,
849
+ createdAt: Date.now(),
850
+ addressingAt: null,
851
+ addressedAt: null,
852
+ };
853
+ comments.push(comment);
854
+ pushEvent('comment', comment);
855
+ broadcast('comment', comment);
856
+ persist();
857
+ const result = { ok: true, comment };
858
+ note(gate.key, gate.body, result);
859
+ return result;
860
+ }
861
+ function addressComment(commentId, body, request) {
862
+ touch();
863
+ const gate = guarded('address', body ?? {}, request, true);
864
+ if (gate.replay)
865
+ return gate.replay;
866
+ const payload = jsonBody(gate.body, false);
867
+ const outcome = payload.outcome;
868
+ if (outcome != null && outcome !== 'implemented' && outcome !== 'errored' && outcome !== 'issues') {
869
+ throw new HttpError(400, 'Invalid outcome');
870
+ }
871
+ const comment = comments.find((entry) => entry.id === commentId);
872
+ if (!comment)
873
+ throw new HttpError(404, 'Unknown comment');
874
+ comment.outcome = outcome === 'errored' || outcome === 'issues' || outcome === 'implemented' ? outcome : 'implemented';
875
+ if (!comment.addressedAt)
876
+ comment.addressedAt = Date.now();
877
+ comment.addressingAt = null;
878
+ broadcast('comment', { ...comment, replies: comment.replies?.map((reply) => ({ ...reply })) });
879
+ persist();
880
+ const result = { ok: true, comment };
881
+ note(gate.key, gate.body, result);
882
+ return result;
883
+ }
884
+ function replyToComment(commentId, body, request) {
885
+ touch();
886
+ const gate = guarded('reply', body, request, true);
887
+ if (gate.replay)
888
+ return gate.replay;
889
+ const payload = jsonBody(gate.body, true);
890
+ const text = String(payload.text ?? '').trim();
891
+ if (!text || text.length > 4000)
892
+ throw new HttpError(400, 'Missing reply');
893
+ const comment = comments.find((entry) => entry.id === commentId);
894
+ if (!comment)
895
+ throw new HttpError(404, 'Unknown comment');
896
+ const reply = {
897
+ id: `rpl_${nanoid()}`,
898
+ text,
899
+ createdAt: Date.now(),
900
+ };
901
+ comment.replies = [...(comment.replies ?? []), reply];
902
+ broadcast('comment', { ...comment, replies: comment.replies.map((entry) => ({ ...entry })) });
903
+ persist();
904
+ const result = { ok: true, comment, reply };
905
+ note(gate.key, gate.body, result);
906
+ return result;
907
+ }
908
+ /**
909
+ * An agent's listener printed this comment. The page shows it in progress (Addressing, or Working on a
910
+ * minibar message) without a separate `addressing` call. `reply` or `address` answers it.
911
+ */
912
+ function markReceived(commentId, at) {
913
+ const comment = comments.find((entry) => entry.id === commentId);
914
+ if (!comment || comment.addressedAt || comment.addressingAt)
915
+ return;
916
+ comment.addressingAt = at;
917
+ broadcast('comment', { ...comment, replies: comment.replies?.map((reply) => ({ ...reply })) });
918
+ }
919
+ function markAddressing(commentId, request) {
920
+ touch();
921
+ const gate = guarded('addressing', {}, request, true);
922
+ if (gate.replay)
923
+ return gate.replay;
924
+ const comment = comments.find((entry) => entry.id === commentId);
925
+ if (!comment)
926
+ throw new HttpError(404, 'Unknown comment');
927
+ if (!comment.addressedAt && !comment.addressingAt) {
928
+ comment.addressingAt = Date.now();
929
+ broadcast('comment', { ...comment });
930
+ persist();
931
+ }
932
+ const result = { ok: true, comment };
933
+ note(gate.key, gate.body, result);
934
+ return result;
935
+ }
936
+ function acknowledgeEvents(body) {
937
+ touch();
938
+ const payload = jsonBody(body, true);
939
+ if (!Array.isArray(payload.ids) || payload.ids.length === 0 || payload.ids.some((id) => typeof id !== 'string' || !id)) {
940
+ throw new HttpError(400, 'Missing event ids');
941
+ }
942
+ const wanted = new Set(payload.ids);
943
+ const now = Date.now();
944
+ const delivered = [];
945
+ for (const event of eventLog) {
946
+ if (!wanted.has(event.id))
947
+ continue;
948
+ if (event.deliveredAt == null) {
949
+ event.deliveredAt = now;
950
+ if (event.event === 'comment')
951
+ markReceived(event.data?.id, now);
952
+ }
953
+ delivered.push(event.id);
954
+ }
955
+ persist();
956
+ return { ok: true, delivered };
957
+ }
958
+ function submitReview(body, request) {
959
+ touch();
960
+ const gate = guarded('review', body, request, true);
961
+ if (gate.replay)
962
+ return gate.replay;
963
+ if (mode !== 'review')
964
+ throw new HttpError(400, 'Server is not in review mode');
965
+ const payload = jsonBody(gate.body, true);
966
+ if (!['approve', 'deny', 'iterate'].includes(payload.decision))
967
+ throw new HttpError(400, 'Invalid decision');
968
+ try {
969
+ fulfillReview(payload.decision, payload.note);
970
+ }
971
+ catch (error) {
972
+ throw new HttpError(409, error instanceof Error ? error.message : 'Review locked');
973
+ }
974
+ const result = { ok: true, review: reviewResult };
975
+ note(gate.key, gate.body, result);
976
+ return result;
977
+ }
978
+ function setMode(nextMode, nextIteration) {
979
+ mode = nextMode;
980
+ if (nextIteration !== undefined && Number.isFinite(nextIteration))
981
+ iteration = nextIteration;
982
+ if (nextMode === 'review')
983
+ reviewResult = undefined;
984
+ broadcast('mode', { mode, iteration, review: reviewResult ?? null });
985
+ persist();
986
+ }
987
+ /** The person sent a verdict and no agent has acked its `review` row yet. */
988
+ function verdictUnread() {
989
+ if (!reviewResult?.decision)
990
+ return false;
991
+ return eventLog.some((event) => event.event === 'review' && event.deliveredAt == null);
992
+ }
993
+ function enterReview(nextIteration) {
994
+ if (verdictUnread())
995
+ return false;
996
+ setMode('review', nextIteration);
997
+ return true;
998
+ }
999
+ function updateMode(body, request) {
1000
+ touch();
1001
+ const gate = guarded('mode', body, request, false);
1002
+ if (gate.replay)
1003
+ return gate.replay;
1004
+ const payload = jsonBody(gate.body, true);
1005
+ const next = payload.mode;
1006
+ if (next !== 'watch' && next !== 'comment' && next !== 'review')
1007
+ throw new HttpError(400, 'Invalid mode');
1008
+ const nextIteration = readIteration(payload.iteration);
1009
+ if (nextIteration === 'invalid')
1010
+ throw new HttpError(400, INVALID_ITERATION);
1011
+ if (next === 'review' && verdictUnread())
1012
+ throw new HttpError(409, UNREAD_VERDICT);
1013
+ setMode(next, nextIteration);
1014
+ const result = { ok: true, mode, iteration };
1015
+ note(gate.key, gate.body, result);
1016
+ return result;
1017
+ }
1018
+ // An editor writes a file in more than one step. Read it once the writes settle.
1019
+ let reloadTimer;
1020
+ const watcher = watch(planPath, { persistent: true }, () => {
1021
+ if (reloadTimer)
1022
+ clearTimeout(reloadTimer);
1023
+ reloadTimer = setTimeout(reloadSettled, RELOAD_SETTLE_MS);
1024
+ });
1025
+ function reloadSettled() {
1026
+ reloadTimer = undefined;
1027
+ void reloadFromDisk().catch((error) => {
1028
+ const message = error instanceof Error ? error.message : 'Failed to reload plan';
1029
+ void recordLog({
1030
+ level: 'error',
1031
+ message: `Failed to reload plan: ${message}`,
1032
+ detail: error instanceof Error ? error.stack : undefined,
1033
+ source: 'plan',
1034
+ planId: id,
1035
+ }).catch(() => undefined);
1036
+ broadcast('error', { message });
1037
+ });
1038
+ }
1039
+ const themeConfigBase = basename(themeConfigPath);
1040
+ let themeWatcher;
1041
+ try {
1042
+ themeWatcher = watch(dirname(themeConfigPath), { persistent: true }, (_event, filename) => {
1043
+ if (filename && filename !== themeConfigBase)
1044
+ return;
1045
+ void reloadThemeFromDisk().catch((error) => {
1046
+ const message = error instanceof Error ? error.message : 'Failed to reload theme config';
1047
+ void recordLog({
1048
+ level: 'warn',
1049
+ message: `Failed to reload theme: ${message}`,
1050
+ detail: error instanceof Error ? error.stack : undefined,
1051
+ source: 'plan',
1052
+ planId: id,
1053
+ }).catch(() => undefined);
1054
+ broadcast('error', { message });
1055
+ });
1056
+ });
1057
+ }
1058
+ catch (error) {
1059
+ void recordLog({
1060
+ level: 'warn',
1061
+ message: 'Theme config is not being watched',
1062
+ detail: error instanceof Error ? error.message : undefined,
1063
+ source: 'plan',
1064
+ planId: id,
1065
+ }).catch(() => undefined);
1066
+ }
1067
+ return {
1068
+ id,
1069
+ token,
1070
+ planPath,
1071
+ get mode() {
1072
+ return mode;
1073
+ },
1074
+ startedAt,
1075
+ get lastSeenAt() {
1076
+ return lastSeenAt;
1077
+ },
1078
+ get browserClients() {
1079
+ return browserClients.size;
1080
+ },
1081
+ get agentClients() {
1082
+ return agentClients.size;
1083
+ },
1084
+ agentPresence: currentAgentPresence,
1085
+ touch,
1086
+ snapshot,
1087
+ setMode,
1088
+ enterReview,
1089
+ updateMode,
1090
+ offlineSnapshot,
1091
+ page,
1092
+ planMdxPayload,
1093
+ restoreMdxSnapshot,
1094
+ planPayload,
1095
+ saveMdxSource,
1096
+ search,
1097
+ themeView,
1098
+ updateTheme,
1099
+ executionPayload,
1100
+ updateExecution,
1101
+ startExecution,
1102
+ pushExecution,
1103
+ stopExecution,
1104
+ browserEvents,
1105
+ agentEvents,
1106
+ submitInteraction,
1107
+ submitComment,
1108
+ addressComment,
1109
+ replyToComment,
1110
+ markAddressing,
1111
+ submitReview,
1112
+ acknowledgeEvents,
1113
+ async close() {
1114
+ if (closed)
1115
+ return;
1116
+ closed = true;
1117
+ if (reloadTimer)
1118
+ clearTimeout(reloadTimer);
1119
+ watcher.close();
1120
+ themeWatcher?.close();
1121
+ mdxStore?.close();
1122
+ for (const client of [...browserClients, ...agentClients])
1123
+ client.close();
1124
+ browserClients.clear();
1125
+ agentClients.clear();
1126
+ for (const queue of waiters.values()) {
1127
+ for (const waiter of queue) {
1128
+ if (waiter.timer)
1129
+ clearTimeout(waiter.timer);
1130
+ waiter.reject(new Error('Plan session closed'));
1131
+ }
1132
+ }
1133
+ waiters.clear();
1134
+ for (const waiter of reviewWaiters) {
1135
+ if (waiter.timer)
1136
+ clearTimeout(waiter.timer);
1137
+ waiter.reject(new Error('Plan session closed'));
1138
+ }
1139
+ reviewWaiters = [];
1140
+ },
1141
+ waitForInteraction(interactionId, timeoutMs = 4 * 60 * 60 * 1000) {
1142
+ if (responses[interactionId])
1143
+ return Promise.resolve(responses[interactionId]);
1144
+ return new Promise((resolveWait, reject) => {
1145
+ const waiter = { id: interactionId, resolve: resolveWait, reject };
1146
+ waiter.timer = setTimeout(() => {
1147
+ const queue = waiters.get(interactionId) ?? [];
1148
+ waiters.set(interactionId, queue.filter((entry) => entry !== waiter));
1149
+ reject(new Error(`Timed out waiting for interaction: ${interactionId}`));
1150
+ }, timeoutMs);
1151
+ const queue = waiters.get(interactionId) ?? [];
1152
+ queue.push(waiter);
1153
+ waiters.set(interactionId, queue);
1154
+ });
1155
+ },
1156
+ waitForReview(timeoutMs = 4 * 60 * 60 * 1000) {
1157
+ if (reviewResult)
1158
+ return Promise.resolve(reviewResult);
1159
+ return new Promise((resolveWait, reject) => {
1160
+ const waiter = {
1161
+ resolve: resolveWait,
1162
+ reject,
1163
+ timer: setTimeout(() => {
1164
+ reviewWaiters = reviewWaiters.filter((entry) => entry !== waiter);
1165
+ reject(new Error('Timed out waiting for review decision'));
1166
+ }, timeoutMs),
1167
+ };
1168
+ reviewWaiters.push(waiter);
1169
+ });
1170
+ },
1171
+ getState() {
1172
+ return {
1173
+ plan,
1174
+ responses: { ...responses },
1175
+ pendingInteractionIds: pendingInteractionIds(),
1176
+ review: reviewResult,
1177
+ execution: executionView(),
1178
+ theme: currentTheme(),
1179
+ };
1180
+ },
1181
+ };
1182
+ }