hostlet 0.0.0-stage → 0.1.0-alpha.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 (512) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -2
  3. package/bin/hostlet.js +61 -0
  4. package/console/app/api.js +1223 -0
  5. package/console/app/boot.js +165 -0
  6. package/console/app/cards.js +222 -0
  7. package/console/app/compose-quote.js +127 -0
  8. package/console/app/config-form.js +727 -0
  9. package/console/app/document-drafts.js +62 -0
  10. package/console/app/document-tools.mjs +67 -0
  11. package/console/app/documents.js +106 -0
  12. package/console/app/pages.js +6483 -0
  13. package/console/app/plugins.js +509 -0
  14. package/console/app/preview-tools.js +172 -0
  15. package/console/app/reference-labels.js +118 -0
  16. package/console/app/selection.js +372 -0
  17. package/console/app/store.js +57 -0
  18. package/console/app/text-anchor.js +26 -0
  19. package/console/app/topic-local.js +322 -0
  20. package/console/app/topic-nav.js +414 -0
  21. package/console/app/topic-status.js +109 -0
  22. package/console/app/views.js +43 -0
  23. package/console/apple-touch-icon.png +0 -0
  24. package/console/avatars/agy.svg +34 -0
  25. package/console/avatars/alhena.svg +36 -0
  26. package/console/avatars/castor.svg +38 -0
  27. package/console/avatars/claude.svg +34 -0
  28. package/console/avatars/codex.svg +34 -0
  29. package/console/avatars/devin.svg +34 -0
  30. package/console/avatars/echo.svg +34 -0
  31. package/console/avatars/kimi.svg +33 -0
  32. package/console/avatars/opencode.svg +33 -0
  33. package/console/avatars/pinion.svg +34 -0
  34. package/console/avatars/sprocket.svg +34 -0
  35. package/console/avatars/vela.svg +44 -0
  36. package/console/avatars/wasat.svg +38 -0
  37. package/console/clients/agy.svg +1 -0
  38. package/console/clients/claude.svg +1 -0
  39. package/console/clients/codex.svg +1 -0
  40. package/console/clients/devin.svg +1 -0
  41. package/console/clients/kimi.svg +1 -0
  42. package/console/clients/opencode.svg +1 -0
  43. package/console/favicon.ico +0 -0
  44. package/console/favicon.svg +16 -0
  45. package/console/index.html +99 -0
  46. package/console/pdl/engine/README.md +13 -0
  47. package/console/pdl/engine/anchor.js +195 -0
  48. package/console/pdl/engine/core.js +1340 -0
  49. package/console/pdl/engine/frame.js +1252 -0
  50. package/console/pdl/engine/i18n.js +67 -0
  51. package/console/pdl/engine/pdl-check.js +102 -0
  52. package/console/pdl/engine/pdl-doc.js +353 -0
  53. package/console/pdl/engine/pdl-view.js +280 -0
  54. package/console/pdl/engine/pdl.js +1064 -0
  55. package/console/pdl/engine/platform.js +18 -0
  56. package/console/pdl/engine/proj.js +279 -0
  57. package/console/pdl/engine/theme.js +176 -0
  58. package/console/pdl/engine/tree.js +171 -0
  59. package/console/pdl/engine/units.js +546 -0
  60. package/console/pdl/library/README.md +28 -0
  61. package/console/pdl/library/blocks.js +1512 -0
  62. package/console/pdl/library/buttons.js +86 -0
  63. package/console/pdl/library/capsules.js +130 -0
  64. package/console/pdl/library/charts.js +287 -0
  65. package/console/pdl/library/code.js +98 -0
  66. package/console/pdl/library/css/base.css +12 -0
  67. package/console/pdl/library/css/blocks.css +98 -0
  68. package/console/pdl/library/css/capsules.css +42 -0
  69. package/console/pdl/library/css/catalog-page.css +24 -0
  70. package/console/pdl/library/css/chat.css +100 -0
  71. package/console/pdl/library/css/composer-top.css +145 -0
  72. package/console/pdl/library/css/controls.css +195 -0
  73. package/console/pdl/library/css/drag.css +29 -0
  74. package/console/pdl/library/css/edit-layout.css +93 -0
  75. package/console/pdl/library/css/floating-window.css +30 -0
  76. package/console/pdl/library/css/hover.css +50 -0
  77. package/console/pdl/library/css/label-search.css +37 -0
  78. package/console/pdl/library/css/layers.css +43 -0
  79. package/console/pdl/library/css/library-parts.css +33 -0
  80. package/console/pdl/library/css/library.css +117 -0
  81. package/console/pdl/library/css/member-select.css +34 -0
  82. package/console/pdl/library/css/message.css +72 -0
  83. package/console/pdl/library/css/page.css +104 -0
  84. package/console/pdl/library/css/parts.css +338 -0
  85. package/console/pdl/library/css/responsive.css +40 -0
  86. package/console/pdl/library/css/roles.css +28 -0
  87. package/console/pdl/library/css/rows.css +231 -0
  88. package/console/pdl/library/css/settings-rows.css +37 -0
  89. package/console/pdl/library/css/shell.css +59 -0
  90. package/console/pdl/library/css/stream.css +296 -0
  91. package/console/pdl/library/css/theme-calculator.css +18 -0
  92. package/console/pdl/library/css/thumb-choice.css +69 -0
  93. package/console/pdl/library/css/tweaks.css +16 -0
  94. package/console/pdl/library/css/widgets.css +211 -0
  95. package/console/pdl/library/css/workbench.css +59 -0
  96. package/console/pdl/library/feedback.js +83 -0
  97. package/console/pdl/library/floating-window.mjs +100 -0
  98. package/console/pdl/library/fold.js +238 -0
  99. package/console/pdl/library/format.js +53 -0
  100. package/console/pdl/library/frames.js +123 -0
  101. package/console/pdl/library/icons.js +165 -0
  102. package/console/pdl/library/identity.js +149 -0
  103. package/console/pdl/library/inputs.js +801 -0
  104. package/console/pdl/library/label-search.js +214 -0
  105. package/console/pdl/library/markdown-text.js +115 -0
  106. package/console/pdl/library/markdown.js +150 -0
  107. package/console/pdl/library/media-viewer.js +293 -0
  108. package/console/pdl/library/member-select.mjs +32 -0
  109. package/console/pdl/library/message.js +105 -0
  110. package/console/pdl/library/motion.js +56 -0
  111. package/console/pdl/library/overlays.js +165 -0
  112. package/console/pdl/library/page.js +142 -0
  113. package/console/pdl/library/plugin-form.js +154 -0
  114. package/console/pdl/library/registry.js +198 -0
  115. package/console/pdl/library/rows.js +523 -0
  116. package/console/pdl/library/shell.js +151 -0
  117. package/console/pdl/library/stream.js +58 -0
  118. package/console/pdl/library/tabs.js +259 -0
  119. package/console/pdl/library/theme-calculator.js +300 -0
  120. package/console/pdl/library/widgets.js +114 -0
  121. package/console/pdl/load-order.json +74 -0
  122. package/console/pdl/platform/README.md +3 -0
  123. package/console/pdl/platform/rich-markdown.mjs +17 -0
  124. package/console/pdl/platform/web-links.js +26 -0
  125. package/console/pdl/platform/web.js +80 -0
  126. package/console/sdk-browser/mentions.d.mts +16 -0
  127. package/console/sdk-browser/mentions.mjs +84 -0
  128. package/console/theme/assets.js +21 -0
  129. package/console/theme/theme.json +9417 -0
  130. package/console/theme/tokens.json +444 -0
  131. package/dist/core/a2a.d.ts +288 -0
  132. package/dist/core/a2a.js +2197 -0
  133. package/dist/core/address.d.ts +34 -0
  134. package/dist/core/address.js +33 -0
  135. package/dist/core/approval-inputs.d.ts +17 -0
  136. package/dist/core/approval-inputs.js +70 -0
  137. package/dist/core/archive.d.ts +19 -0
  138. package/dist/core/archive.js +135 -0
  139. package/dist/core/attachments.d.ts +17 -0
  140. package/dist/core/attachments.js +143 -0
  141. package/dist/core/blocked-handoffs.d.ts +132 -0
  142. package/dist/core/blocked-handoffs.js +349 -0
  143. package/dist/core/config-schema.d.ts +124 -0
  144. package/dist/core/config-schema.js +192 -0
  145. package/dist/core/config.d.ts +117 -0
  146. package/dist/core/config.js +638 -0
  147. package/dist/core/disk-usage.d.ts +26 -0
  148. package/dist/core/disk-usage.js +83 -0
  149. package/dist/core/documents.d.ts +9 -0
  150. package/dist/core/documents.js +48 -0
  151. package/dist/core/entry.d.ts +316 -0
  152. package/dist/core/entry.js +711 -0
  153. package/dist/core/home.d.ts +76 -0
  154. package/dist/core/home.js +449 -0
  155. package/dist/core/i18n.d.ts +36 -0
  156. package/dist/core/i18n.js +458 -0
  157. package/dist/core/instances.d.ts +224 -0
  158. package/dist/core/instances.js +1272 -0
  159. package/dist/core/members.d.ts +190 -0
  160. package/dist/core/members.js +358 -0
  161. package/dist/core/mentions.d.ts +12 -0
  162. package/dist/core/mentions.js +49 -0
  163. package/dist/core/messages.d.ts +876 -0
  164. package/dist/core/messages.js +916 -0
  165. package/dist/core/notices.d.ts +88 -0
  166. package/dist/core/notices.js +54 -0
  167. package/dist/core/ops.d.ts +117 -0
  168. package/dist/core/ops.js +146 -0
  169. package/dist/core/package.d.ts +2 -0
  170. package/dist/core/package.js +14 -0
  171. package/dist/core/parts.d.ts +25 -0
  172. package/dist/core/parts.js +119 -0
  173. package/dist/core/plugins/catalog.d.ts +14 -0
  174. package/dist/core/plugins/catalog.js +54 -0
  175. package/dist/core/plugins/external.d.ts +7 -0
  176. package/dist/core/plugins/external.js +921 -0
  177. package/dist/core/plugins/index.d.ts +5 -0
  178. package/dist/core/plugins/index.js +51 -0
  179. package/dist/core/plugins/npm.d.ts +12 -0
  180. package/dist/core/plugins/npm.js +99 -0
  181. package/dist/core/plugins/plugin-manifest.d.ts +12 -0
  182. package/dist/core/plugins/plugin-manifest.js +231 -0
  183. package/dist/core/push.d.ts +22 -0
  184. package/dist/core/push.js +63 -0
  185. package/dist/core/resource.d.ts +77 -0
  186. package/dist/core/resource.js +48 -0
  187. package/dist/core/spawn.d.ts +12 -0
  188. package/dist/core/spawn.js +30 -0
  189. package/dist/core/storage-inventory.d.ts +118 -0
  190. package/dist/core/storage-inventory.js +279 -0
  191. package/dist/core/storage.d.ts +45 -0
  192. package/dist/core/storage.js +602 -0
  193. package/dist/core/store.d.ts +15 -0
  194. package/dist/core/store.js +33 -0
  195. package/dist/core/topic-index.d.ts +19 -0
  196. package/dist/core/topic-index.js +70 -0
  197. package/dist/core/topic-ops.d.ts +139 -0
  198. package/dist/core/topic-ops.js +507 -0
  199. package/dist/core/topic-status.d.ts +32 -0
  200. package/dist/core/topic-status.js +105 -0
  201. package/dist/core/topics.d.ts +327 -0
  202. package/dist/core/topics.js +786 -0
  203. package/dist/core/turn-clients.d.ts +1 -0
  204. package/dist/core/turn-clients.js +5 -0
  205. package/dist/core/types.d.ts +2866 -0
  206. package/dist/core/types.js +166 -0
  207. package/dist/core/util.d.ts +10 -0
  208. package/dist/core/util.js +47 -0
  209. package/dist/main.d.ts +12 -0
  210. package/dist/main.js +82 -0
  211. package/dist/plugins/adapter-acp/index.d.ts +3 -0
  212. package/dist/plugins/adapter-acp/index.js +57 -0
  213. package/dist/plugins/adapter-acp/plugin.yaml +100 -0
  214. package/dist/plugins/adapter-agy/command.d.ts +9 -0
  215. package/dist/plugins/adapter-agy/command.js +34 -0
  216. package/dist/plugins/adapter-agy/index.d.ts +5 -0
  217. package/dist/plugins/adapter-agy/index.js +65 -0
  218. package/dist/plugins/adapter-agy/quota.d.ts +2 -0
  219. package/dist/plugins/adapter-agy/quota.js +155 -0
  220. package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
  221. package/dist/plugins/adapter-agy/terminal.js +132 -0
  222. package/dist/plugins/adapter-agy/version.d.ts +9 -0
  223. package/dist/plugins/adapter-agy/version.js +17 -0
  224. package/dist/plugins/adapter-claude/index.d.ts +43 -0
  225. package/dist/plugins/adapter-claude/index.js +412 -0
  226. package/dist/plugins/adapter-claude/quota.d.ts +14 -0
  227. package/dist/plugins/adapter-claude/quota.js +103 -0
  228. package/dist/plugins/adapter-codex/index.d.ts +4 -0
  229. package/dist/plugins/adapter-codex/index.js +688 -0
  230. package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
  231. package/dist/plugins/adapter-codex/responses-model.js +82 -0
  232. package/dist/plugins/adapter-kimi/index.d.ts +4 -0
  233. package/dist/plugins/adapter-kimi/index.js +51 -0
  234. package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
  235. package/dist/plugins/adapter-kimi/quota.js +171 -0
  236. package/dist/plugins/adapter-opencode/index.d.ts +12 -0
  237. package/dist/plugins/adapter-opencode/index.js +64 -0
  238. package/dist/plugins/annotations/console/cards.css +189 -0
  239. package/dist/plugins/annotations/console/cards.mjs +439 -0
  240. package/dist/plugins/annotations/console/pdl.json +52 -0
  241. package/dist/plugins/annotations/console/view.mjs +241 -0
  242. package/dist/plugins/annotations/console/window.mjs +219 -0
  243. package/dist/plugins/annotations/followups.d.ts +51 -0
  244. package/dist/plugins/annotations/followups.js +112 -0
  245. package/dist/plugins/annotations/index.d.ts +3 -0
  246. package/dist/plugins/annotations/index.js +298 -0
  247. package/dist/plugins/annotations/plugin.yaml +3 -0
  248. package/dist/plugins/ask-choice/index.d.ts +9 -0
  249. package/dist/plugins/ask-choice/index.js +24 -0
  250. package/dist/plugins/ask-choice/plugin.yaml +2 -0
  251. package/dist/plugins/background/index.d.ts +2 -0
  252. package/dist/plugins/background/index.js +398 -0
  253. package/dist/plugins/background/plugin.yaml +7 -0
  254. package/dist/plugins/builtin.json +37 -0
  255. package/dist/plugins/cards/console/pdl.json +516 -0
  256. package/dist/plugins/cards/console/view.mjs +67 -0
  257. package/dist/plugins/cards/index.d.ts +8 -0
  258. package/dist/plugins/cards/index.js +627 -0
  259. package/dist/plugins/cards/plugin.yaml +3 -0
  260. package/dist/plugins/console/browser.d.ts +2 -0
  261. package/dist/plugins/console/browser.js +115 -0
  262. package/dist/plugins/console/console/pdl.json +38 -0
  263. package/dist/plugins/console/console/view.mjs +26 -0
  264. package/dist/plugins/console/index.d.ts +4 -0
  265. package/dist/plugins/console/index.js +94 -0
  266. package/dist/plugins/console/picker.d.ts +2 -0
  267. package/dist/plugins/console/picker.js +48 -0
  268. package/dist/plugins/console/plugin.yaml +3 -0
  269. package/dist/plugins/console/topic-view.d.ts +3 -0
  270. package/dist/plugins/console/topic-view.js +388 -0
  271. package/dist/plugins/handoff/index.d.ts +2 -0
  272. package/dist/plugins/handoff/index.js +147 -0
  273. package/dist/plugins/handoff/plugin.yaml +8 -0
  274. package/dist/plugins/host-api/index.d.ts +7 -0
  275. package/dist/plugins/host-api/index.js +310 -0
  276. package/dist/plugins/host-api/plugin.yaml +2 -0
  277. package/dist/plugins/host-api/signing.d.ts +63 -0
  278. package/dist/plugins/host-api/signing.js +427 -0
  279. package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
  280. package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
  281. package/dist/plugins/inbox/index.d.ts +15 -0
  282. package/dist/plugins/inbox/index.js +161 -0
  283. package/dist/plugins/inbox/plugin.yaml +2 -0
  284. package/dist/plugins/keys/account-directories.d.ts +18 -0
  285. package/dist/plugins/keys/account-directories.js +86 -0
  286. package/dist/plugins/keys/account-storage.d.ts +18 -0
  287. package/dist/plugins/keys/account-storage.js +112 -0
  288. package/dist/plugins/keys/console/pdl.json +710 -0
  289. package/dist/plugins/keys/console/view.mjs +619 -0
  290. package/dist/plugins/keys/index.d.ts +7 -0
  291. package/dist/plugins/keys/index.js +842 -0
  292. package/dist/plugins/keys/login-link.d.ts +2 -0
  293. package/dist/plugins/keys/login-link.js +15 -0
  294. package/dist/plugins/keys/plugin.yaml +3 -0
  295. package/dist/plugins/keys/quota-history.d.ts +91 -0
  296. package/dist/plugins/keys/quota-history.js +420 -0
  297. package/dist/plugins/mcp/console/pdl.json +412 -0
  298. package/dist/plugins/mcp/console/view.mjs +207 -0
  299. package/dist/plugins/mcp/index.d.ts +7 -0
  300. package/dist/plugins/mcp/index.js +494 -0
  301. package/dist/plugins/mcp/plugin.yaml +3 -0
  302. package/dist/plugins/member-health/index.d.ts +2 -0
  303. package/dist/plugins/member-health/index.js +478 -0
  304. package/dist/plugins/member-health/plugin.yaml +2 -0
  305. package/dist/plugins/memory/capabilities.d.ts +10 -0
  306. package/dist/plugins/memory/capabilities.js +70 -0
  307. package/dist/plugins/memory/console/pdl.json +459 -0
  308. package/dist/plugins/memory/console/view.mjs +254 -0
  309. package/dist/plugins/memory/corpus.d.ts +60 -0
  310. package/dist/plugins/memory/corpus.js +521 -0
  311. package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
  312. package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
  313. package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
  314. package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
  315. package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
  316. package/dist/plugins/memory/engines/fts-tree.js +387 -0
  317. package/dist/plugins/memory/engines/search.d.ts +9 -0
  318. package/dist/plugins/memory/engines/search.js +35 -0
  319. package/dist/plugins/memory/index.d.ts +3 -0
  320. package/dist/plugins/memory/index.js +465 -0
  321. package/dist/plugins/memory/notes.d.ts +22 -0
  322. package/dist/plugins/memory/notes.js +140 -0
  323. package/dist/plugins/memory/plugin.yaml +23 -0
  324. package/dist/plugins/model-profiles/index.d.ts +2 -0
  325. package/dist/plugins/model-profiles/index.js +916 -0
  326. package/dist/plugins/model-profiles/plugin.yaml +13 -0
  327. package/dist/plugins/model-profiles/review-source.d.ts +11 -0
  328. package/dist/plugins/model-profiles/review-source.js +640 -0
  329. package/dist/plugins/model-profiles/rules.d.ts +130 -0
  330. package/dist/plugins/model-profiles/rules.js +729 -0
  331. package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +59 -0
  332. package/dist/plugins/model-profiles/sources.d.ts +61 -0
  333. package/dist/plugins/model-profiles/sources.js +375 -0
  334. package/dist/plugins/model-profiles/storage.d.ts +84 -0
  335. package/dist/plugins/model-profiles/storage.js +315 -0
  336. package/dist/plugins/model-profiles/types.d.ts +179 -0
  337. package/dist/plugins/model-profiles/types.js +12 -0
  338. package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
  339. package/dist/plugins/model-profiles/wakeup.js +390 -0
  340. package/dist/plugins/models/index.d.ts +2 -0
  341. package/dist/plugins/models/index.js +63 -0
  342. package/dist/plugins/models/plugin.yaml +8 -0
  343. package/dist/plugins/ops/collector.d.ts +22 -0
  344. package/dist/plugins/ops/collector.js +48 -0
  345. package/dist/plugins/ops/config.d.ts +11 -0
  346. package/dist/plugins/ops/config.js +13 -0
  347. package/dist/plugins/ops/console/pdl.json +676 -0
  348. package/dist/plugins/ops/console/view.mjs +700 -0
  349. package/dist/plugins/ops/index.d.ts +3 -0
  350. package/dist/plugins/ops/index.js +20 -0
  351. package/dist/plugins/ops/journal.d.ts +7 -0
  352. package/dist/plugins/ops/journal.js +109 -0
  353. package/dist/plugins/ops/metrics.d.ts +3 -0
  354. package/dist/plugins/ops/metrics.js +81 -0
  355. package/dist/plugins/ops/plugin.yaml +63 -0
  356. package/dist/plugins/ops/samples.d.ts +54 -0
  357. package/dist/plugins/ops/samples.js +100 -0
  358. package/dist/plugins/ops/trace.d.ts +3 -0
  359. package/dist/plugins/ops/trace.js +104 -0
  360. package/dist/plugins/ops/usage.d.ts +2 -0
  361. package/dist/plugins/ops/usage.js +152 -0
  362. package/dist/plugins/plans/acceptance.d.ts +284 -0
  363. package/dist/plugins/plans/acceptance.js +247 -0
  364. package/dist/plugins/plans/blocked.d.ts +25 -0
  365. package/dist/plugins/plans/blocked.js +66 -0
  366. package/dist/plugins/plans/console/pdl.json +639 -0
  367. package/dist/plugins/plans/console/view.d.mts +2 -0
  368. package/dist/plugins/plans/console/view.mjs +855 -0
  369. package/dist/plugins/plans/dependencies.d.ts +5 -0
  370. package/dist/plugins/plans/dependencies.js +21 -0
  371. package/dist/plugins/plans/index.d.ts +72 -0
  372. package/dist/plugins/plans/index.js +2057 -0
  373. package/dist/plugins/plans/plugin.yaml +44 -0
  374. package/dist/plugins/plans/progress.d.ts +82 -0
  375. package/dist/plugins/plans/progress.js +516 -0
  376. package/dist/plugins/prompt/index.d.ts +8 -0
  377. package/dist/plugins/prompt/index.js +361 -0
  378. package/dist/plugins/prompt/plugin.yaml +2 -0
  379. package/dist/plugins/recovery/console/pdl.json +50 -0
  380. package/dist/plugins/recovery/console/view.mjs +46 -0
  381. package/dist/plugins/recovery/index.d.ts +9 -0
  382. package/dist/plugins/recovery/index.js +454 -0
  383. package/dist/plugins/recovery/plugin.yaml +9 -0
  384. package/dist/plugins/recovery/probe.d.ts +11 -0
  385. package/dist/plugins/recovery/probe.js +128 -0
  386. package/dist/plugins/restart/console/pdl.json +112 -0
  387. package/dist/plugins/restart/console/view.mjs +85 -0
  388. package/dist/plugins/restart/index.d.ts +10 -0
  389. package/dist/plugins/restart/index.js +669 -0
  390. package/dist/plugins/restart/plugin.yaml +9 -0
  391. package/dist/plugins/restart/scope.d.ts +6 -0
  392. package/dist/plugins/restart/scope.js +44 -0
  393. package/dist/plugins/schedule/console/pdl.json +696 -0
  394. package/dist/plugins/schedule/console/view.mjs +398 -0
  395. package/dist/plugins/schedule/events.d.ts +76 -0
  396. package/dist/plugins/schedule/events.js +158 -0
  397. package/dist/plugins/schedule/index.d.ts +32 -0
  398. package/dist/plugins/schedule/index.js +1199 -0
  399. package/dist/plugins/schedule/plugin.yaml +26 -0
  400. package/dist/plugins/schedule/when.d.ts +14 -0
  401. package/dist/plugins/schedule/when.js +83 -0
  402. package/dist/plugins/sessions/console/pdl.json +259 -0
  403. package/dist/plugins/sessions/console/view.mjs +355 -0
  404. package/dist/plugins/sessions/index.d.ts +3 -0
  405. package/dist/plugins/sessions/index.js +126 -0
  406. package/dist/plugins/sessions/participants.d.ts +28 -0
  407. package/dist/plugins/sessions/participants.js +83 -0
  408. package/dist/plugins/sessions/plugin.yaml +3 -0
  409. package/dist/plugins/signals/console/pdl.json +802 -0
  410. package/dist/plugins/signals/console/view.mjs +284 -0
  411. package/dist/plugins/signals/content.d.ts +31 -0
  412. package/dist/plugins/signals/content.js +151 -0
  413. package/dist/plugins/signals/index.d.ts +2 -0
  414. package/dist/plugins/signals/index.js +601 -0
  415. package/dist/plugins/signals/plugin.yaml +32 -0
  416. package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
  417. package/dist/plugins/skills/console/pdl.json +254 -0
  418. package/dist/plugins/skills/console/view.mjs +204 -0
  419. package/dist/plugins/skills/index.d.ts +11 -0
  420. package/dist/plugins/skills/index.js +567 -0
  421. package/dist/plugins/skills/install.d.ts +69 -0
  422. package/dist/plugins/skills/install.js +265 -0
  423. package/dist/plugins/skills/plugin.yaml +24 -0
  424. package/dist/plugins/skills/safety-scan.d.ts +17 -0
  425. package/dist/plugins/skills/safety-scan.js +78 -0
  426. package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
  427. package/dist/plugins/terminal/console/pdl.json +115 -0
  428. package/dist/plugins/terminal/console/view.mjs +178 -0
  429. package/dist/plugins/terminal/index.d.ts +3 -0
  430. package/dist/plugins/terminal/index.js +204 -0
  431. package/dist/plugins/terminal/plugin.yaml +2 -0
  432. package/dist/plugins/tools/index.d.ts +3 -0
  433. package/dist/plugins/tools/index.js +455 -0
  434. package/dist/plugins/tools/plugin.yaml +2 -0
  435. package/dist/plugins/tools/token.d.ts +61 -0
  436. package/dist/plugins/tools/token.js +179 -0
  437. package/dist/plugins/topic-tools/index.d.ts +9 -0
  438. package/dist/plugins/topic-tools/index.js +29 -0
  439. package/dist/plugins/topic-tools/plugin.yaml +2 -0
  440. package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
  441. package/dist/plugins/works/console/pdl.json +120 -0
  442. package/dist/plugins/works/console/view.mjs +91 -0
  443. package/dist/plugins/works/document-words.d.ts +50 -0
  444. package/dist/plugins/works/document-words.js +27 -0
  445. package/dist/plugins/works/editors.d.ts +3 -0
  446. package/dist/plugins/works/editors.js +162 -0
  447. package/dist/plugins/works/events.d.ts +58 -0
  448. package/dist/plugins/works/events.js +82 -0
  449. package/dist/plugins/works/files.d.ts +23 -0
  450. package/dist/plugins/works/files.js +53 -0
  451. package/dist/plugins/works/index.d.ts +9 -0
  452. package/dist/plugins/works/index.js +1088 -0
  453. package/dist/plugins/works/plugin.yaml +9 -0
  454. package/dist/plugins/works/preview.d.ts +10 -0
  455. package/dist/plugins/works/preview.js +30 -0
  456. package/dist/plugins/works/project.d.ts +3 -0
  457. package/dist/plugins/works/project.js +245 -0
  458. package/dist/plugins/works/resource.d.ts +28 -0
  459. package/dist/plugins/works/resource.js +71 -0
  460. package/dist/plugins/works/retention.d.ts +36 -0
  461. package/dist/plugins/works/retention.js +295 -0
  462. package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
  463. package/dist/plugins/works/viewers.d.ts +13 -0
  464. package/dist/plugins/works/viewers.js +87 -0
  465. package/dist/plugins/works/web/anchors.js +94 -0
  466. package/dist/plugins/works/web/document-edit.js +245 -0
  467. package/dist/plugins/works/web/preview-bridge.js +142 -0
  468. package/dist/plugins/works/web/reading-position.js +74 -0
  469. package/dist/plugins/works/web/view.html +1118 -0
  470. package/dist/runtime/runtime.d.ts +210 -0
  471. package/dist/runtime/runtime.js +338 -0
  472. package/dist/sdk/adapter-kit.d.ts +1 -0
  473. package/dist/sdk/adapter-kit.js +1 -0
  474. package/dist/sdk/client.d.ts +163 -0
  475. package/dist/sdk/client.js +43 -0
  476. package/dist/sdk/contracts.d.ts +1263 -0
  477. package/dist/sdk/contracts.js +1 -0
  478. package/dist/sdk/index.d.ts +57 -0
  479. package/dist/sdk/index.js +27 -0
  480. package/dist/sdk/source-choice.d.ts +40 -0
  481. package/dist/sdk/source-choice.js +217 -0
  482. package/dist/sdk/topic-text.d.ts +5 -0
  483. package/dist/sdk/topic-text.js +26 -0
  484. package/dist/sdk/transport.d.ts +12 -0
  485. package/dist/sdk/transport.js +34 -0
  486. package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
  487. package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
  488. package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
  489. package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
  490. package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
  491. package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
  492. package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
  493. package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
  494. package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
  495. package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
  496. package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
  497. package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
  498. package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
  499. package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
  500. package/node_modules/@hostlet/adapter-kit/package.json +16 -0
  501. package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
  502. package/node_modules/@hostlet/platform/dist/desktop.js +270 -0
  503. package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
  504. package/node_modules/@hostlet/platform/dist/files.js +113 -0
  505. package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
  506. package/node_modules/@hostlet/platform/dist/index.js +4 -0
  507. package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
  508. package/node_modules/@hostlet/platform/dist/paths.js +9 -0
  509. package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
  510. package/node_modules/@hostlet/platform/dist/process.js +297 -0
  511. package/node_modules/@hostlet/platform/package.json +14 -0
  512. package/package.json +60 -4
@@ -0,0 +1,855 @@
1
+ // Pure dependency text operations are also used by the plans service.
2
+ const planReference = /\[[^\[\]\r\n]+\]\(#plans\/(plan_[a-z0-9]+)\)|(?<![\w/-])#plans\/(plan_[a-z0-9]+)(?![\w/-])/g;
3
+
4
+ export function planRefs(text) {
5
+ return [...new Set([...text.matchAll(planReference)].map(([, link, raw]) => link ?? raw))];
6
+ }
7
+
8
+ export function withPrerequisites(text, ids) {
9
+ const selected = new Set(ids), missing = new Set(ids);
10
+ const lines = text.split(/(\r\n?|\n)/);
11
+ let kept = '';
12
+ for (let i = 0; i < lines.length; i += 2) {
13
+ const line = lines[i];
14
+ const edited = line.replace(planReference, function (match, link, raw) {
15
+ const id = link ?? raw;
16
+ if (!selected.has(id)) return '';
17
+ missing.delete(id);
18
+ return match;
19
+ });
20
+ if (line !== edited && !edited.trim()) continue;
21
+ kept += edited + (lines[i + 1] ?? '');
22
+ }
23
+ return [kept.trim(), ...[...missing].map(id => '#plans/' + id)].filter(Boolean).join('\n');
24
+ }
25
+
26
+ export default function (ui) {
27
+ const models = {}, actions = {}, inputs = {}, changes = {};
28
+ const t = ui.t;
29
+ /* What the topics have put off, on its own page or beside a conversation. */
30
+ const HL_PLANS = { items: null, section: 'items', state: 'later', groupBy: 'topic', lineage: false, seen: '', dirty: true, jump: null };
31
+ const HL_PLAN_LIST = 'hl-plans';
32
+ const HL_OVERVIEW_LIST = 'hl-sec-plans';
33
+ const HL_OVERVIEW = { topicId: '', items: null, dirty: true, seq: 0, timer: null };
34
+ const HL_PLAN_ROW = pdlKeyed('hlPlansRow');
35
+ const HL_OVERVIEW_ROW = pdlKeyed('hlPlansOverviewRow');
36
+ const rowReads = pdlReads('plansRow', {
37
+ name: hlPlanName, path: hlPlanPath,
38
+ enabled: function (id) { return id === 'owner' ? true : hlMember(id)?.enabled !== false; },
39
+ });
40
+ function syncRows(store, items) {
41
+ const seen = new Set();
42
+ for (const p of (items || [])) {
43
+ seen.add(p.id);
44
+ if (JSON.stringify(store.peek(p.id)) !== JSON.stringify(p)) store.set(p.id, p);
45
+ }
46
+ for (const id of store.keys()) if (!seen.has(id)) store.delete(id);
47
+ }
48
+ const HL_PLAN_STATE_KEYS = { later: 'stLater', doing: 'stDoing', done: 'stDone', dropped: 'stDropped' };
49
+ const HL_PLAN_FILTER_KEYS = [['later', 'fltPlanned'], ['doing', 'fltDoing'], ['closed', 'fltClosed'], ['all', 'fltAll']];
50
+ const HL_PLAN_STEP_KEYS = { noted: 'stepNoted', started: 'stepStarted', done: 'stepDone', dropped: 'stepDropped', reopened: 'stepReopened', suspended: 'stepSuspended', resumed: 'stepResumed', waiting: 'stepWaiting', continued: 'stepContinued', reminded: 'stepReminded', checked: 'stepChecked', acceptanceAsked: 'stepAcceptanceAsked', mentioned: 'stepMentioned', sourceCorrected: 'stepSourceCorrected' };
51
+ /* The overview's own read is the fresher one while the whole list waits to be read again. */
52
+ function hlPlan(id) {
53
+ const board = HL_PLANS.items?.find(function (p) { return p.id === id; });
54
+ const overview = HL_OVERVIEW.items?.find(function (p) { return p.id === id; });
55
+ return (hlPlansFresh() ? board || overview : overview || board);
56
+ }
57
+ function canIntervene(p) { return p.activity?.kind === 'stalled' || p.activity?.kind === 'blocked'; }
58
+ function hlPlanState(p, state) {
59
+ if (state === 'attention') return p.ready || p.due || canIntervene(p);
60
+ return state === 'all' || (state === 'closed' ? !openState(p.state) : p.state === state);
61
+ }
62
+ function hlPlanPath(id) { return hlTopicPath(id).map(function (tp) { return tp.title; }).join(' › '); }
63
+ function hlPlanSearch(p, q) { return !q || [p.title, p.source, hlPlanPath(p.topicId)].some(function (s) { return s.toLowerCase().includes(q); }); }
64
+ function hlPlanScope(ls, topic) {
65
+ const scope = ls.conds.find(function (c) { return c.type === 'scope'; })?.id || 'all';
66
+ if (scope === 'all') return { limited: false, includes: function () { return true; } };
67
+ const ids = new Set(topic ? (scope === 'topic' ? [topic.id] : hlTopicPath(topic.id).map(function (t) { return t.id; })) : []);
68
+ return { limited: true, includes: function (p) { return ids.has(p.topicId) || ids.has(p.at); } };
69
+ }
70
+
71
+ /* The board fetches the whole list. A burst of pushes is one refresh, and a hidden board waits until it is shown. */
72
+ let HL_PLANS_TIMER = null, HL_PLANS_READ = 0;
73
+ /* One rule for the whole list, for the board and everything outside it: a snapshot is current only once a read that
74
+ began after the latest change has been written. Changes are counted; a read remembers the count it began at. */
75
+ let HL_PLANS_CHANGES = 0, HL_PLANS_SNAPSHOT = -1, HL_PLANS_INFLIGHT = null;
76
+ function hlPlansFresh() { return !!HL_PLANS.items && HL_PLANS_SNAPSHOT === HL_PLANS_CHANGES; }
77
+ function hlPlansRead() {
78
+ if (HL_PLANS_INFLIGHT && HL_PLANS_INFLIGHT.mark === HL_PLANS_CHANGES) return HL_PLANS_INFLIGHT.promise;
79
+ const mark = HL_PLANS_CHANGES, read = ++HL_PLANS_READ;
80
+ const promise = ui.request('GET', '/api/plans?closed=true').then(function (items) {
81
+ if (HL_PLANS_INFLIGHT?.promise === promise) HL_PLANS_INFLIGHT = null;
82
+ if (read === HL_PLANS_READ) {
83
+ HL_PLANS.items = items;
84
+ HL_PLANS_SNAPSHOT = mark;
85
+ syncRows(HL_PLAN_ROW, items);
86
+ }
87
+ return HL_PLANS.items;
88
+ }, function (error) {
89
+ if (HL_PLANS_INFLIGHT?.promise === promise) HL_PLANS_INFLIGHT = null;
90
+ throw error;
91
+ });
92
+ HL_PLANS_INFLIGHT = { mark: mark, promise: promise };
93
+ return promise;
94
+ }
95
+ /* The whole list as it is now, for the editor and prerequisite titles outside the board: waits for the read under way,
96
+ and reads once more if a change came during it. */
97
+ function hlPlansEnsureAll(tries = 8) {
98
+ if (hlPlansFresh()) return Promise.resolve(HL_PLANS.items);
99
+ return hlPlansRead().then(function () {
100
+ if (hlPlansFresh() || tries <= 1) { render(true); return hlPlansFresh() ? HL_PLANS.items : null; }
101
+ return hlPlansEnsureAll(tries - 1); // changed again during the read: read again until a snapshot is current
102
+ });
103
+ }
104
+ function hlPlansQueue(delay) {
105
+ if (HL_PLANS_TIMER !== null) {
106
+ if (delay) return;
107
+ clearTimeout(HL_PLANS_TIMER);
108
+ }
109
+ HL_PLANS_TIMER = setTimeout(function () {
110
+ HL_PLANS_TIMER = null;
111
+ if (!ui.shown('plans')) return;
112
+ HL_PLANS.dirty = false;
113
+ hlPlansRead().then(function () {
114
+ // A read that was superseded, or a snapshot a later change already outdates, leaves revealing to the read after it.
115
+ if (!hlPlansFresh()) return;
116
+ const jump = hlPlansReveal();
117
+ render(true);
118
+ if (jump) requestAnimationFrame(function () {
119
+ if (!ui.shown('plans')) return;
120
+ if (jump.id !== 'attention') {
121
+ const el = document.querySelector('[data-l="' + HL_PLAN_LIST + '"][data-k="' + CSS.escape(jump.id) + '"]');
122
+ if (!el) return;
123
+ el.scrollIntoView({ block: 'center' });
124
+ }
125
+ jump.after?.();
126
+ });
127
+ }, ui.fail);
128
+ }, delay);
129
+ }
130
+ function hlOverviewQueue(topicId, delay) {
131
+ if (HL_OVERVIEW.timer !== null) {
132
+ if (delay && HL_OVERVIEW.topicId === topicId) return;
133
+ clearTimeout(HL_OVERVIEW.timer);
134
+ }
135
+ HL_OVERVIEW.topicId = topicId;
136
+ HL_OVERVIEW.timer = setTimeout(function () {
137
+ HL_OVERVIEW.timer = null;
138
+ if (!topicId || HL.topic?.id !== topicId || !ui.shown('overview')) return;
139
+ HL_OVERVIEW.dirty = false;
140
+ const seq = ++HL_OVERVIEW.seq;
141
+ ui.request('GET', '/api/plans?topic=' + encodeURIComponent(topicId) + '&state=doing').then(function (items) {
142
+ if (seq !== HL_OVERVIEW.seq || HL.topic?.id !== topicId) return;
143
+ HL_OVERVIEW.items = items;
144
+ syncRows(HL_OVERVIEW_ROW, items);
145
+ render(true);
146
+ }, ui.fail);
147
+ }, delay);
148
+ }
149
+ /* An expanded overview row names prerequisites from the whole list: a change to the plans reads it again (once per burst),
150
+ not only a redraw of the row. Topic activity alone never reads the whole list for it. */
151
+ let HL_PLANS_EXPANDED_TIMER = null;
152
+ function hlPlansExpandedRefresh() {
153
+ if (HL_PLANS_EXPANDED_TIMER !== null) return;
154
+ HL_PLANS_EXPANDED_TIMER = setTimeout(function () {
155
+ HL_PLANS_EXPANDED_TIMER = null;
156
+ if (ui.shown('plans') || !ui.shown('overview') || !HL_OVERVIEW.items?.some(function (p) {
157
+ return p.prerequisites?.length && rowOpen(HL_OVERVIEW_LIST, p.id);
158
+ })) return;
159
+ hlPlansEnsureAll().catch(ui.fail);
160
+ }, 250);
161
+ }
162
+ function hlPlansChanged() {
163
+ hlListsChanged(true);
164
+ hlPlansExpandedRefresh();
165
+ }
166
+ /* A topic moved into or out of the trash, archived or moved changes which plans are listed: the snapshot is outdated and
167
+ expanded rows read again. Plain activity (a message, a title) only refreshes what is shown; the snapshot still holds. */
168
+ function hlTopicsChanged(d) {
169
+ const visibility = !!(d?.trashChanged?.length || d?.tree);
170
+ hlListsChanged(visibility);
171
+ if (visibility) hlPlansExpandedRefresh();
172
+ }
173
+ function hlListsChanged(outdated) {
174
+ if (outdated) HL_PLANS_CHANGES++;
175
+ HL_PLANS.dirty = true;
176
+ HL_OVERVIEW.dirty = true;
177
+ if (ui.shown('plans')) hlPlansQueue(200);
178
+ if (HL.topic && ui.shown('overview')) hlOverviewQueue(HL.topic.id, 200);
179
+ }
180
+ function hlPlansReveal() {
181
+ const jump = HL_PLANS.jump;
182
+ HL_PLANS.jump = null;
183
+ if (!jump) return;
184
+ HL_PLANS.section = 'items';
185
+ HL_PLANS.lineage = false;
186
+ const { id } = jump;
187
+ const ls = labelSearchValue('plans', { defaultScope: false });
188
+ if (id === 'attention') {
189
+ if (HL_PLANS.state !== 'attention') HL_PLAN_ROW.touchAll();
190
+ HL_PLANS.state = 'attention';
191
+ ls.q = '';
192
+ ls.conds = [];
193
+ return jump;
194
+ }
195
+ const plan = hlPlan(id);
196
+ if (!plan) {
197
+ toast(t('notFound'));
198
+ if (S.route === 'plans') go('plans', { address: true });
199
+ return;
200
+ }
201
+ if (!hlPlanState(plan, HL_PLANS.state)) { HL_PLANS.state = 'all'; HL_PLAN_ROW.touchAll(); }
202
+ if (!hlPlanSearch(plan, (ls.q || '').trim().toLowerCase())) { ls.q = ''; ls.conds = []; if (HL_PLANS.state !== 'all') HL_PLAN_ROW.touchAll(); HL_PLANS.state = 'all'; }
203
+ if (!hlPlanScope(ls, S.route === 'chat' && HL.topic).includes(plan)) {
204
+ ls.conds = ls.conds.filter(function (c) { return c.type !== 'scope'; });
205
+ }
206
+ S.folds[FOLD_ROW + HL_PLAN_LIST] = id;
207
+ return jump;
208
+ }
209
+
210
+ /* The topics are ordered as in the side tree, by creation within each level. */
211
+ function hlPlanTopics() {
212
+ const children = new Map(), ordered = [];
213
+ hlTopicCatalog().slice().sort(function (a, b) { return a.createdAt - b.createdAt; }).forEach(function (tp) {
214
+ const parent = tp.parentId || '';
215
+ if (!children.has(parent)) children.set(parent, []);
216
+ children.get(parent).push(tp);
217
+ });
218
+ function walk(parent) {
219
+ (children.get(parent) || []).forEach(function (tp) { ordered.push(tp); walk(tp.id); });
220
+ }
221
+ walk('');
222
+ return ordered;
223
+ }
224
+ function hlPlanName(id) { return id === 'owner' ? HL.owner.name : (hlMember(id) || {}).name || id; }
225
+ function hlPlanTime(at) { return typeof hlMsgTime === 'function' ? hlMsgTime(at) : new Date(at).toLocaleString([], { dateStyle: 'short', timeStyle: 'short' }); }
226
+ function hlPlanReason(why, prerequisites) {
227
+ if (!why) return null;
228
+ const parts = [];
229
+ let at = 0;
230
+ const pattern = prerequisites ? planReference : /\[[^\[\]\r\n]+\]\(#plans\/(plan_[a-z0-9]+)\)|(?<![\w/-])(?:#plans\/)?(plan_[a-z0-9]+)(?![\w/-])/g;
231
+ for (const match of why.matchAll(pattern)) {
232
+ const id = match[1] || match[2];
233
+ const prerequisite = prerequisites?.includes(id);
234
+ // A prerequisite elsewhere is named from the whole list: read it again if a change has come, even when an old title is at hand.
235
+ if (prerequisite && !hlPlansFresh() && !ui.shown('plans')) hlPlansEnsureAll().catch(ui.fail);
236
+ const target = prerequisite ? (HL_PLAN_ROW.get(id) || HL_OVERVIEW_ROW.get(id)) : hlPlan(id);
237
+ if (!target && !prerequisite) continue;
238
+ parts.push({ lit: why.slice(at, match.index) });
239
+ at = match.index + match[0].length;
240
+ if (!target) {
241
+ if (!hlPlansFresh()) {
242
+ parts.push({ control: {
243
+ type: 'button', link: true, label: { lit: id }, tip: { lit: id }, act: 'hlGo', args: { a: 'plans/' + id }
244
+ } });
245
+ } else {
246
+ parts.push({ lit: id + ' · ' + t('missingPrerequisite') });
247
+ }
248
+ continue;
249
+ }
250
+ const title = { lit: target.title };
251
+ parts.push({ control: {
252
+ type: 'button', link: true, label: title, tip: title, act: 'hlGo', args: { a: 'plans/' + target.id }
253
+ } });
254
+ if (prerequisite) parts.push({ lit: ' (' + t(HL_PLAN_STATE_KEYS[target.state]) + ')' });
255
+ }
256
+ parts.push({ lit: why.slice(at) });
257
+ return { parts: parts, sep: '' };
258
+ }
259
+ const openState = function (state) { return state === 'later' || state === 'doing'; };
260
+ const progressSteps = new Set(['noted', 'started', 'done', 'dropped', 'reopened']);
261
+ const activityLabels = { advancing: 'advancing', recovering: 'recovering', waiting: 'waiting', stalled: 'stalled', blocked: 'blocked' };
262
+ const activityDetails = { turn: 'workTurn', unread: 'workUnread', background: 'workJob', retry: 'workRetry',
263
+ silent: 'workSilent', unstarted: 'workUnstarted', failure: 'workFailed', unavailable: 'workUnavailable' };
264
+ function hlPlanAttention(p, workDetail, workSummary) {
265
+ const facts = [];
266
+ if (p.due) facts.push(t('attentionScheduledAt', hlPlanTime(Date.parse(p.when))));
267
+ if (workDetail) facts.push(workDetail);
268
+ const destination = p.dispatch?.mode === 'existing' && HL_TOPIC_LABEL.title(p.dispatch.topic);
269
+ if ((p.ready || p.due) && destination) facts.push(t('attentionDestination', destination));
270
+ return { summary: p.due ? t('attentionDue') : p.ready ? t('attentionReady') : workSummary, facts: facts };
271
+ }
272
+ function followUpMembers(topicId) {
273
+ const topic = hlTopic(topicId);
274
+ if (!topic || topic.archivedAt != null) return [];
275
+ return HL.members.filter(function (member) {
276
+ return member.enabled && member.kind === 'agent' && member.canReceive && hlWorksHere(topicId)(member);
277
+ }).map(function (member) { return member.id; });
278
+ }
279
+ function hlPlanRow(p, listId = HL_PLAN_LIST, attentionMode = HL_PLANS.state === 'attention') {
280
+ const progress = p.trail.filter(function (step) { return progressSteps.has(step.what); });
281
+ const latest = progress.at(-1), place = HL_TOPIC_LABEL.title(p.at) ?? p.place?.title;
282
+ const source = p.messageSource?.url || p.documentSource?.url, corrected = p.trail.some(function (step) { return step.what === 'sourceCorrected'; });
283
+ const resumeMs = p.resumeAt && /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}|$)/.test(p.resumeAt) ? Date.parse(p.resumeAt) : NaN;
284
+ const suspendedLabel = openState(p.state) && p.suspended
285
+ ? (Number.isFinite(resumeMs) ? t('suspendedUntil', hlPlanTime(resumeMs)) : t('suspended')) : '';
286
+ const sub = [p.pinned ? rowReads.path(p.topicId) : '', p.source, suspendedLabel];
287
+ const reason = p.activity && activityDetails[p.activity.reason];
288
+ const stalled = p.activity?.kind === 'stalled' && ['idle', 'unstarted', 'reply'].includes(p.activity.reason);
289
+ const waitingWho = p.waiting
290
+ ? (!rowReads.enabled(p.waiting.on) ? t('memberDisabled', rowReads.name(p.waiting.on)) : rowReads.name(p.waiting.on)) : '';
291
+ const waitingWhy = p.waiting
292
+ ? [p.waiting.why, p.waiting.until ? t('waitUntil', hlPlanTime(p.waiting.until)) : ''].filter(Boolean).join(' · ') : '';
293
+ const declared = p.waiting && !p.suspended ? t('responsibleWaiting', waitingWho, waitingWhy) : '';
294
+ const detail = [declared || p.activity?.detail || (reason && t(reason)),
295
+ p.waitingOn && t('workInferred', rowReads.name(p.waitingOn))].filter(Boolean).join(' · ');
296
+ const activity = p.activity && t(p.activity.reason === 'declared' ? 'waiting' : activityLabels[p.activity.kind]);
297
+ const workSummary = stalled ? t('attentionIdle') : declared || activity;
298
+ const attention = attentionMode ? hlPlanAttention(p, declared ? '' : detail, workSummary) : null;
299
+ const conditions = [p.ready && !attention && t('dependencyReady'), p.due && !attention && t('due'), activity].filter(Boolean).join(' · ');
300
+ if (attention) sub.unshift(attention.summary);
301
+ if (p.state === 'doing') {
302
+ if (!attention && (detail || stalled)) sub.unshift([stalled && t('attentionIdle'), detail].filter(Boolean).join(' · '));
303
+ if (p.responsible && !declared) sub.unshift(t('responsible', rowReads.name(p.responsible)));
304
+ if (p.assignee && p.assignee !== p.responsible) sub.push(t('followUp', rowReads.name(p.assignee)));
305
+ if (place) sub.push(t('doingIn', place));
306
+ if (p.lastWorkAt) sub.push(t('lastProgress', hlPlanTime(p.lastWorkAt)));
307
+ } else if (p.state === 'done' || p.state === 'dropped') {
308
+ sub.unshift(hlPlanReason(latest.why));
309
+ sub.push(t(HL_PLAN_STATE_KEYS[p.state]) + ' ' + hlPlanTime(latest.at));
310
+ }
311
+ const open = rowOpen(listId, p.id);
312
+ const facts = attention?.facts.concat(declared || []) ?? [stalled && t('attentionIdle'), detail].filter(Boolean);
313
+ if (open && p.dependencies) facts.unshift({ parts: [t('dependencies'), hlPlanReason(p.dependencies, p.prerequisites)], sep: ' · ' });
314
+ function record(step) {
315
+ const go = step.what === 'noted' && !corrected ? source : step.where;
316
+ const action = step.what === 'reminded' && !step.where ? 'stepReminderFailed' : HL_PLAN_STEP_KEYS[step.what];
317
+ const text = [hlPlanTime(step.at), rowReads.name(step.by), t(action), step.what === 'started' && go ? HL_TOPIC_LABEL.title(go.split('/')[0].slice(5)) : '', step.assignee && t('followUp', rowReads.name(step.assignee))].filter(Boolean).join(' · ');
318
+ const why = step.waitingOn ? t('workDeclared', rowReads.name(step.waitingOn), step.why) : step.why;
319
+ return { parts: [text, hlPlanReason(why)].filter(Boolean), go: go, hasGo: !!go };
320
+ }
321
+ const mentions = open ? p.trail.filter(function (step) { return step.what === 'mentioned'; }).map(record) : [];
322
+ const mentionPrefix = listId === HL_PLAN_LIST ? 'plan' : listId;
323
+ return {
324
+ id: p.id, title: p.title, state: t(HL_PLAN_STATE_KEYS[p.state]), sub: sub.filter(Boolean), conditions: conditions,
325
+ running: p.activity?.kind === 'advancing',
326
+ go: p.jump.url, goLabel: t({ acceptance: 'goAcceptance', current: 'goCurrent', handoff: 'goHandoff', receipt: 'goReceipt', source: 'goMessage', document: 'goDocument', work: 'goWork', home: 'goTopic' }[p.jump.kind]), open: open,
327
+ dropped: p.state === 'dropped', canDone: openState(p.state), canSuspend: openState(p.state) && !p.suspended,
328
+ attention: !!attention, facts: facts,
329
+ trail: open ? p.trail.filter(function (step) { return step.what in HL_PLAN_STEP_KEYS && step.what !== 'mentioned'; }).map(record) : [],
330
+ mentions: mentions, mentionKey: mentionPrefix + '-mentions-' + p.id, mentionLabel: t('mentionCount', mentions.length), hasMentions: !!mentions.length,
331
+ acceptance: open ? (p.acceptance || []).map(function (item) {
332
+ const checked = item.checked && [rowReads.name(item.checked.by), hlPlanTime(item.checked.at), item.checked.host, item.checked.commit, item.checked.plugin, item.checked.note].filter(Boolean).join(' · ');
333
+ return {
334
+ id: item.id, title: [item.entry, item.action, item.result].join(' → '),
335
+ sub: [t('acceptBy_' + item.by), t('acceptState_' + (item.effective || item.state)), item.effective && item.effective !== item.state && t('acceptElsewhere'), item.target && t('acceptTarget', item.target), checked, (item.evidence || []).length ? t('acceptEvidence', item.evidence.length) : ''].filter(Boolean).join(' · '),
336
+ };
337
+ }) : [],
338
+ hasAcceptance: open && !!(p.acceptance || []).length, acceptanceLabel: t('acceptanceCount', (p.acceptance || []).filter(function (item) { return (item.effective || item.state) === 'passed'; }).length, (p.acceptance || []).length)
339
+ };
340
+ }
341
+
342
+ const planTones = { later: 'idle', doing: 'info', done: 'ok', dropped: 'warn' };
343
+
344
+ function hlPlanLineage(plans, matches, highlight) {
345
+ const columnGap = 184, rowGap = 56, laneGap = 12;
346
+ const byId = new Map(plans.map(p => [p.id, p]));
347
+ const parents = new Map(plans.map(p => [p.id, p.prerequisites.filter(id => byId.has(id))]));
348
+ const children = new Map(plans.map(p => [p.id, []]));
349
+ for (const [id, refs] of parents) for (const ref of refs) children.get(ref).push(id);
350
+ const selected = new Set(matches.map(p => p.id)), placed = new Set();
351
+ const nodes = [], edges = [];
352
+ let width = 0, height = 12, cycle = false;
353
+ for (const id of selected) {
354
+ if (placed.has(id) || !(parents.get(id).length || children.get(id).length)) continue;
355
+ const component = [id];
356
+ placed.add(id);
357
+ for (const key of component) {
358
+ for (const near of [...parents.get(key), ...children.get(key)]) {
359
+ if (placed.has(near)) continue;
360
+ placed.add(near);
361
+ component.push(near);
362
+ }
363
+ }
364
+ const pending = new Map(component.map(key => [key, parents.get(key).length]));
365
+ const depth = new Map(), ready = component.filter(key => pending.get(key) === 0);
366
+ let maxDepth = 0;
367
+ for (const key of ready) {
368
+ const nextDepth = (depth.get(key) ?? 0) + 1;
369
+ maxDepth = Math.max(maxDepth, nextDepth - 1);
370
+ for (const child of children.get(key)) {
371
+ depth.set(child, Math.max(depth.get(child) ?? 0, nextDepth));
372
+ pending.set(child, pending.get(child) - 1);
373
+ if (pending.get(child) === 0) ready.push(child);
374
+ }
375
+ }
376
+ if (ready.length < component.length) cycle = true;
377
+ const columns = new Map(), ranks = new Map();
378
+ for (const key of component) {
379
+ const rank = pending.get(key) === 0 ? (depth.get(key) ?? 0) : maxDepth + 1;
380
+ ranks.set(key, rank);
381
+ if (!columns.has(rank)) columns.set(rank, []);
382
+ columns.get(rank).push(key);
383
+ }
384
+ const links = component.flatMap(key => parents.get(key).filter(parent => parent !== key).map(parent => ({ from: parent, to: key })));
385
+ const above = links.filter(({ from, to }) => ranks.get(to) - ranks.get(from) > 1).length * laneGap;
386
+ const rows = Math.max(...[...columns.values()].map(keys => keys.length));
387
+ const points = new Map();
388
+ for (const [column, keys] of columns) {
389
+ width = Math.max(width, 166 + column * columnGap);
390
+ keys.forEach(function (key, row) {
391
+ const p = byId.get(key), x = 80 + column * columnGap, y = height + above + 22 + (row + (rows - keys.length) / 2) * rowGap;
392
+ points.set(key, { x, y });
393
+ nodes.push({
394
+ id: key, x, y, text: p.title, tip: [p.title, t(HL_PLAN_STATE_KEYS[p.state]), p.topic].join(' · '),
395
+ tone: planTones[p.state], on: highlight && selected.has(key), dim: highlight && !selected.has(key),
396
+ act: ui.key('hlPlanOpenNode'), args: { id: key },
397
+ });
398
+ });
399
+ }
400
+ let lane = height + 8;
401
+ for (const { from, to } of links) {
402
+ const a = points.get(from), b = points.get(to);
403
+ if (b.x - a.x > columnGap) {
404
+ // Go through the gaps beside the columns and above the component, clear of every card.
405
+ const out = a.x + 92, into = b.x - 88;
406
+ edges.push({ from: [a.x + 76, a.y], to: [b.x - 71, b.y], via: [[out, a.y], [out, lane], [into, lane], [into, b.y]], arrow: true });
407
+ lane += laneGap;
408
+ continue;
409
+ }
410
+ if (a.x === b.x && Math.abs(b.y - a.y) > rowGap) {
411
+ const side = a.x + 92;
412
+ width = Math.max(width, side + 8);
413
+ edges.push({ from: [a.x + 76, a.y], to: [b.x + 77, b.y], via: [[side, a.y], [side, b.y]], arrow: true, dash: '4 3' });
414
+ continue;
415
+ }
416
+ const direction = Math.sign(b.y - a.y);
417
+ const horizontal = a.x !== b.x;
418
+ edges.push({
419
+ from: horizontal ? [a.x + 76, a.y] : [a.x, a.y + direction * 18],
420
+ to: horizontal ? [b.x - 71, b.y] : [b.x, b.y - direction * 19],
421
+ arrow: true, dash: a.x === b.x ? '4 3' : undefined,
422
+ });
423
+ }
424
+ height += above + rows * rowGap + 12;
425
+ }
426
+ return {
427
+ label: t('lineageView'), nodes, edges, view: [0, 0, width, height], scroll: true, cycle,
428
+ legend: nodes.length ? { items: Object.entries(planTones).map(([state, tone]) => ({ tone, label: t(HL_PLAN_STATE_KEYS[state]) })) } : undefined,
429
+ empty: HL_PLANS.items === null ? t('loading') : t('lineageEmpty'),
430
+ };
431
+ }
432
+
433
+ function hlPlanTopicGroups(visible) {
434
+ const groups = new Map(), pinned = { key: 'pinned', title: t('pinned'), ids: [] };
435
+ for (const plan of visible) {
436
+ if (plan.pinned) { pinned.ids.push(plan.id); continue; }
437
+ const id = plan.topicId;
438
+ if (!groups.has(id)) groups.set(id, { key: id, title: hlPlanPath(id), ids: [], act: 'hlGo', args: { a: 'chat-' + id } });
439
+ groups.get(id).ids.push(plan.id);
440
+ }
441
+ const ordered = hlPlanTopics().map(function (topic) { return groups.get(topic.id); }).filter(Boolean);
442
+ if (pinned.ids.length) ordered.unshift(pinned);
443
+ return ordered;
444
+ }
445
+ function hlPlanDocumentGroups(plans, visible) {
446
+ const keyOf = function (plan) {
447
+ const doc = plan.from.doc;
448
+ return doc ? JSON.stringify([doc.resource, doc.section || '']) : 'unlinked';
449
+ };
450
+ const open = new Map(), groups = new Map();
451
+ for (const plan of plans) {
452
+ if (!openState(plan.state)) continue;
453
+ const key = keyOf(plan);
454
+ open.set(key, (open.get(key) || 0) + 1);
455
+ }
456
+ for (const plan of visible) {
457
+ const key = keyOf(plan);
458
+ if (!groups.has(key)) {
459
+ const doc = plan.documentSource;
460
+ groups.set(key, {
461
+ key: key, title: doc?.label || t('groupNoDocument'), count: t('groupOpenCount', open.get(key) || 0), ids: [],
462
+ ...(doc?.url ? { act: 'hlGo', args: { a: doc.url } } : {})
463
+ });
464
+ }
465
+ groups.get(key).ids.push(plan.id);
466
+ }
467
+ return [...groups.values()].sort(function (a, b) {
468
+ return Number(a.key === 'unlinked') - Number(b.key === 'unlinked') || a.title.localeCompare(b.title);
469
+ });
470
+ }
471
+
472
+ models.hlPlans = function () {
473
+ const topic = S.route === 'chat' && HL.topic, ls = labelSearchValue('plans', { defaultScope: false });
474
+ const q = (ls.q || '').trim().toLowerCase();
475
+ const scope = hlPlanScope(ls, topic);
476
+ const detail = S.route === 'plans' ? S.param : null;
477
+ const seen = S.route + ':' + NAV.seq + ':' + (topic ? topic.id : '') + ':' + (detail || '');
478
+ const moved = HL_PLANS.seen !== seen;
479
+ if (moved || (HL_PLANS.dirty && HL_PLANS_TIMER === null)) {
480
+ HL_PLANS.seen = seen;
481
+ if (moved && S.route === 'plans' && HL_PLANS.jump?.id !== detail) HL_PLANS.jump = detail ? { id: detail } : null;
482
+ hlPlansQueue(0);
483
+ }
484
+ const sections = {
485
+ sections: [{ v: 'items', label: t('sectionItems') }, { v: 'settings', label: t('sectionSettings') }],
486
+ section: HL_PLANS.section, itemsShown: HL_PLANS.section === 'items', settingsShown: HL_PLANS.section === 'settings'
487
+ };
488
+ // Navigation reveals its item even when the settings view was selected.
489
+ if (sections.settingsShown && !HL_PLANS.jump) return sections;
490
+ const all = (HL_PLANS.items || []).filter(function (p) { return hlTopicRef(p.topicId); });
491
+ const plans = all.filter(function (p) { return scope.includes(p) && hlPlanSearch(p, q); });
492
+ const visible = plans.filter(function (p) { return hlPlanState(p, HL_PLANS.state); });
493
+ const byDocument = HL_PLANS.groupBy === 'document';
494
+ const closed = HL_PLANS.state === 'closed';
495
+ const decided = function (p) { return p.trail.findLast(function (s) { return s.what === p.state; }).at; };
496
+ const readPlanRow = function (id) {
497
+ const p = HL_PLAN_ROW.get(id) || hlPlan(id);
498
+ return p ? hlPlanRow(p) : null;
499
+ };
500
+ const ordered = HL_PLANS.lineage ? [] : visible.slice().sort(function (a, b) {
501
+ const pin = byDocument ? Number(!!b.pinned) - Number(!!a.pinned) : 0;
502
+ return pin || (closed ? decided(b) - decided(a) : a.trail[0].at - b.trail[0].at);
503
+ });
504
+ const groups = byDocument ? hlPlanDocumentGroups(plans, ordered) : hlPlanTopicGroups(ordered);
505
+ const groupByOptions = [['topic', t('groupByTopic')], ['document', t('groupByDocument')]];
506
+ return {
507
+ ...sections,
508
+ search: { key: 'plans', inputId: 'hl-plans-q', placeholder: t('s05'), types: [], defaultScope: false },
509
+ state: HL_PLANS.state, groups: groups.map(function ({ ids, ...group }) { return { ...group, items: pdlKeyedList(ids, readPlanRow) }; }),
510
+ attention: HL_PLANS.state === 'attention', groupBy: HL_PLANS.groupBy, groupByOptions: groupByOptions,
511
+ list: !HL_PLANS.lineage, switchView: t(HL_PLANS.lineage ? 'listView' : 'lineageView'),
512
+ graph: HL_PLANS.lineage ? hlPlanLineage(all, visible, !!q || scope.limited || HL_PLANS.state !== 'all') : null,
513
+ filters: HL_PLAN_FILTER_KEYS.map(function (f) { return { v: f[0], label: t(f[1]), count: plans.filter(function (p) { return hlPlanState(p, f[0]); }).length }; }),
514
+ empty: HL_PLANS.items === null ? t('loading') : HL_PLANS.items.length ? t('emptyFiltered') : t('emptyAll')
515
+ };
516
+ };
517
+ models.hlPlansOverview = function () {
518
+ const topic = HL.topic && hlTopic(HL.topic.id);
519
+ if (!topic) return { visible: false, items: [] };
520
+ if (HL_OVERVIEW.topicId !== topic.id || (HL_OVERVIEW.dirty && HL_OVERVIEW.timer === null && ui.shown('overview'))) {
521
+ if (HL_OVERVIEW.topicId !== topic.id) {
522
+ HL_OVERVIEW.items = null;
523
+ syncRows(HL_OVERVIEW_ROW, []);
524
+ }
525
+ hlOverviewQueue(topic.id, 0);
526
+ }
527
+ const list = HL_OVERVIEW.topicId === topic.id && Array.isArray(HL_OVERVIEW.items) ? HL_OVERVIEW.items : [];
528
+ const ids = list.map(function (p) { return p.id; });
529
+ const readOverviewRow = function (id) {
530
+ const p = HL_OVERVIEW_ROW.get(id) || HL_OVERVIEW.items?.find(function (item) { return item.id === id; });
531
+ return p ? hlPlanRow(p, HL_OVERVIEW_LIST, false) : null;
532
+ };
533
+ return {
534
+ visible: ids.length > 0,
535
+ items: pdlKeyedList(ids, readOverviewRow),
536
+ };
537
+ };
538
+ actions.hlPlansSection = function ({ v }) { HL_PLANS.section = v; render(true); };
539
+ changes.hlPlansGroupBy = function (e) { HL_PLANS.groupBy = e.target.value; render(true); };
540
+ actions.hlPlansState = function (d) { if (HL_PLANS.state !== d.v) HL_PLAN_ROW.touchAll(); HL_PLANS.state = d.v; render(true); };
541
+ actions.hlPlansToggleView = function () { HL_PLANS.lineage = !HL_PLANS.lineage; render(true); };
542
+ actions.hlPlanOpenNode = function ({ id }) {
543
+ if (S.route === 'plans' && S.param === id) {
544
+ HL_PLANS.jump = { id };
545
+ hlPlansQueue(0);
546
+ return;
547
+ }
548
+ A.hlGo({ a: 'plans/' + id });
549
+ };
550
+
551
+ const textFields = ['description', 'trigger'];
552
+ function hlPlanLocalTime(when) {
553
+ const at = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(when) ? Date.parse(when) : NaN;
554
+ if (!Number.isFinite(at)) return '';
555
+ const offset = new Date(at).getTimezoneOffset() * 60000;
556
+ return new Date(at - offset).toISOString().slice(0, 16);
557
+ }
558
+ function hlPlanSourceFields(plan) {
559
+ const first = plan.trail[0], fields = [
560
+ { label: t('recordedBy'), text: hlPlanName(first.by) },
561
+ { label: t('recordedAt'), text: hlPlanTime(first.at) }
562
+ ];
563
+ const source = plan.messageSource;
564
+ if (source) fields.push({
565
+ label: t('source'), text: source.label, ref: source.url,
566
+ control: source.url ? { type: 'button', link: true, label: '@text', act: ui.key('hlPlanSource'), args: { a: '@ref' } } : { type: 'text', text: '@text' }
567
+ });
568
+ const message = plan.from.message?.split('/')[1];
569
+ if (message) fields.push({
570
+ label: t('sourceMessageId'), value: message,
571
+ control: { type: 'copy', value: '@value', label: t('copySourceMessageId'), fieldLabel: '@label', field: true, mono: true }
572
+ });
573
+ const doc = plan.documentSource;
574
+ if (doc) fields.push({
575
+ label: t('documentSource'), text: doc.label, ref: doc.url,
576
+ control: doc.url ? { type: 'button', link: true, label: '@text', act: ui.key('hlPlanSource'), args: { a: '@ref' } } : { type: 'text', text: '@text' }
577
+ });
578
+ return fields;
579
+ }
580
+ function hlPlanDispatchTarget(mode, target) {
581
+ const existing = mode === 'existing';
582
+ const topics = hlPlanTopics().filter(function (topic) { return topic.archivedAt == null; });
583
+ const options = [['', t(existing ? 'pickTopic' : 'planHome')]].concat(topics.map(function (topic) { return [topic.id, hlPlanPath(topic.id)]; }));
584
+ if (target && !options.some(function ([id]) { return id === target; })) options.push([target, hlTopic(target)?.title || target]);
585
+ return { id: 'plan-dispatch-target', label: t(existing ? 'dispatchTopic' : 'dispatchParent'), options: options, value: target, change: ui.key('hlPlanDispatch'), req: existing };
586
+ }
587
+ function hlPlanDispatchMember(mode, target, member) {
588
+ const members = HL.members.filter(function (m) {
589
+ return m.enabled && (mode === 'new' || hlWorksHere(target)(m));
590
+ }).map(function (m) { return m.id; });
591
+ return { id: 'plan-dispatch-member', label: t('dispatchMember'), members, none: t('topicRouting'), value: member, change: ui.key('hlPlanDispatch') };
592
+ }
593
+ changes.hlPlanDispatch = function (e) {
594
+ dlgSync();
595
+ if (e.target.id === 'plan-dispatch-member') return;
596
+ const fields = S.dialog.fields, target = fields.findIndex(function (field) { return field.id === 'plan-dispatch-target'; });
597
+ const mode = val('plan-dispatch-mode'), destination = e.target.id === 'plan-dispatch-mode' ? '' : val('plan-dispatch-target');
598
+ const member = hlPlanDispatchMember(mode, destination, val('plan-dispatch-member'));
599
+ if (!member.members.includes(member.value)) member.value = '';
600
+ fields.splice(target, 2, hlPlanDispatchTarget(mode, destination), member);
601
+ render(true);
602
+ };
603
+ actions.hlPlanSource = function (data) {
604
+ popClose('dialog');
605
+ A.hlGo(data);
606
+ };
607
+ function hlPlanAssignee(topic, assignee, retain) {
608
+ const members = followUpMembers(topic);
609
+ if (retain && assignee && !members.includes(assignee)) members.push(assignee);
610
+ const value = members.includes(assignee) ? assignee : '';
611
+ return { id: 'plan-assignee', label: t('assignee'), members, none: value ? undefined : t('pickMember'), value };
612
+ }
613
+ changes.hlPlanWork = function () {
614
+ dlgSync();
615
+ const fields = S.dialog.fields, at = fields.findIndex(function (f) { return f.id === 'plan-assignee'; });
616
+ fields[at] = hlPlanAssignee(val('plan-work'), val('plan-assignee'), false);
617
+ render(true);
618
+ };
619
+ actions.hlPlanDone = function ({ id }) {
620
+ const plan = hlPlan(id);
621
+ if (!plan) { toast(t('notFound')); return; }
622
+ const openChecks = (plan.acceptance || []).filter(function (item) {
623
+ return (item.effective || item.state) !== 'passed';
624
+ }).length;
625
+ ui.dialog({
626
+ title: t('doneTitle', plan.title),
627
+ ...(openChecks ? { text: t('doneUnmetHelp', openChecks) } : {}),
628
+ ok: t('markDone'),
629
+ fields: [{ id: 'plan-done-why', label: t('doneNote'), area: true }],
630
+ on: function () {
631
+ const why = val('plan-done-why');
632
+ return ui.request('PATCH', '/api/plans/' + id, { state: 'done', ...(why ? { why: why } : {}) });
633
+ }
634
+ });
635
+ };
636
+ actions.hlPlanSuspend = function ({ id }) {
637
+ ui.dialog({ title: t('suspendTitle', hlPlan(id).title), ok: t('suspend'),
638
+ fields: [
639
+ { id: 'plan-hold-reason', label: t('holdReason'), area: true, req: true },
640
+ { id: 'plan-hold-resume', label: t('resumeAt'), type: 'datetime-local', value: '' }
641
+ ],
642
+ on: function () {
643
+ const why = val('plan-hold-reason');
644
+ if (!why) throw new Error(t('holdReasonRequired'));
645
+ const resume = val('plan-hold-resume');
646
+ return ui.request('PATCH', '/api/plans/' + id, { suspended: true, why: why, ...(resume ? { resumeAt: new Date(resume).toISOString() } : {}) });
647
+ }
648
+ });
649
+ };
650
+ const switchField = (key, value) => ({ id: 'plan-' + key, label: t(key), type: 'switch', value: !!value });
651
+ const resumeAtField = (value) => ({ id: 'plan-resume-at', label: t('resumeAt'), type: 'datetime-local', value: value || '', foot: t('resumeAtHint') });
652
+ function hlPlanPrerequisites(plan) {
653
+ const available = HL_PLANS.items.filter(function (p) {
654
+ return p.id !== plan.id && hlTopicRef(p.topicId);
655
+ }).map(function (p) { return { v: p.id, label: p.title, sub: [p.topic, t(HL_PLAN_STATE_KEYS[p.state])].join(' · ') }; });
656
+ const label = t('prerequisites');
657
+ return {
658
+ id: 'plan-prerequisites', label, available,
659
+ control: {
660
+ type: 'select', multi: true, id: '@id', label: '@label', options: '@choices', value: '@selected',
661
+ none: t('pickPrerequisites'), act: ui.key('hlPlanTogglePrerequisite'),
662
+ },
663
+ };
664
+ }
665
+ function hlPlanSyncPrerequisites(picker, text) {
666
+ picker.selected = planRefs(text);
667
+ const known = new Set(picker.available.map(p => p.v));
668
+ picker.choices = picker.available.concat(picker.selected.filter(id => !known.has(id)).map(id => ({ v: id, label: id, sub: t('missingPrerequisite') })));
669
+ }
670
+ inputs.hlPlanDependencies = function () {
671
+ dlgSync();
672
+ hlPlanSyncPrerequisites(dlgFieldById('plan-prerequisites'), dlgFieldById('plan-dependencies').value);
673
+ render(true);
674
+ };
675
+ actions.hlPlanTogglePrerequisite = function ({ v }) {
676
+ dlgSync();
677
+ const draft = dlgFieldById('plan-dependencies'), references = planRefs(draft.value);
678
+ const selected = references.includes(v) ? references.filter(id => id !== v) : references.concat(v);
679
+ const text = withPrerequisites(draft.value, selected);
680
+ const input = document.getElementById(draft.id);
681
+ draft.original = text;
682
+ input.value = text;
683
+ input.dispatchEvent(new Event('input', { bubbles: true }));
684
+ };
685
+ changes.hlPlanEditState = function (e) {
686
+ const fields = S.dialog.fields, index = fields.findIndex(function (f) { return f.id === 'plan-suspended'; });
687
+ const resumeIndex = fields.findIndex(function (f) { return f.id === 'plan-resume-at'; });
688
+ dlgSync();
689
+ for (const id of ['plan-why', 'plan-where']) {
690
+ fields.find(function (f) { return f.id === id; }).value = '';
691
+ document.getElementById(id).value = '';
692
+ }
693
+ if (openState(e.target.value) && index < 0) {
694
+ const pinned = fields.findIndex(function (f) { return f.id === 'plan-pinned'; });
695
+ fields.splice(pinned >= 0 ? pinned : fields.length, 0, switchField('suspended', false), resumeAtField(''));
696
+ }
697
+ if (!openState(e.target.value)) {
698
+ if (resumeIndex >= 0) fields.splice(resumeIndex, 1);
699
+ const nextIndex = fields.findIndex(function (f) { return f.id === 'plan-suspended'; });
700
+ if (nextIndex >= 0) fields.splice(nextIndex, 1);
701
+ }
702
+ render(true);
703
+ };
704
+ actions.hlPlanEdit = function ({ id }) {
705
+ if (!hlPlansFresh()) {
706
+ // Opened from the overview: read the list first, then open only if the reader is still where it asked.
707
+ const from = { route: S.route, nav: NAV.seq, topic: HL.topic?.id };
708
+ return hlPlansEnsureAll().then(function (items) {
709
+ if (S.route !== from.route || NAV.seq !== from.nav || HL.topic?.id !== from.topic) return;
710
+ // Still changing after every read: say so rather than open an editor on an outdated plan.
711
+ if (!items || !hlPlansFresh()) { toast(t('stillRefreshing')); return; }
712
+ openPlanEditor(id);
713
+ }, ui.fail);
714
+ }
715
+ openPlanEditor(id);
716
+ };
717
+ function openPlanEditor(id) {
718
+ // A current whole list is the answer: a plan it does not hold is gone, whatever an older read still shows.
719
+ const plan = hlPlansFresh() ? HL_PLANS.items.find(function (p) { return p.id === id; }) : hlPlan(id);
720
+ if (!plan) { toast(t('notFound')); return; }
721
+ const when = hlPlanLocalTime(plan.when);
722
+ const resumeAt = hlPlanLocalTime(plan.resumeAt);
723
+ const doc = plan.from.doc;
724
+ const dispatch = plan.dispatch || { mode: 'new' }, destination = dispatch.topic || dispatch.parent || '';
725
+ const decision = plan.trail.findLast(function (step) {
726
+ return step.what === (plan.suspended ? 'suspended' : plan.state === 'later' ? 'reopened' : plan.state === 'doing' ? 'started' : plan.state);
727
+ });
728
+ const initialWhy = decision?.why || '', initialWhere = decision?.where?.split('/')[1] || '';
729
+ const options = hlPlanTopics().map(function (topic) { return [topic.id, hlPlanPath(topic.id)]; });
730
+ const work = [['', t('pickTopic')]].concat(options.filter(function ([id]) { return hlTopic(id).archivedAt == null || id === plan.at; }));
731
+ const member = hlPlanDispatchMember(dispatch.mode, destination, dispatch.member || '');
732
+ if (dispatch.member && !member.members.includes(dispatch.member)) member.members.push(dispatch.member);
733
+ const prerequisites = hlPlanPrerequisites(plan);
734
+ const dependencyDraft = { id: 'plan-dependencies', label: t('dependencies'), value: plan.dependencies || '',
735
+ control: { type: 'input', id: '@id', label: '@label', value: '@value', rows: 3, input: ui.key('hlPlanDependencies') } };
736
+ hlPlanSyncPrerequisites(prerequisites, dependencyDraft.value);
737
+ const fields = [
738
+ { id: 'plan-title', label: t('fieldTitle'), req: true, value: plan.title },
739
+ ...hlPlanSourceFields(plan),
740
+ { id: 'plan-source-resource', label: t('documentResource'), placeholder: 'res:topic/…/artifacts/…', value: doc?.resource || '' },
741
+ { id: 'plan-source-section', label: t('documentSection'), value: doc?.section || '' },
742
+ ...textFields.map(function (key) {
743
+ return { id: 'plan-' + key, label: t(key), area: key === 'description', placeholder: key === 'description' ? t('descriptionHint') : '', value: plan[key] || '' };
744
+ }),
745
+ dependencyDraft,
746
+ prerequisites,
747
+ { id: 'plan-when', label: t('when'), type: 'datetime-local', value: when, foot: !when && plan.when ? t('previousWhen', plan.when) : '' },
748
+ { id: 'plan-dispatch-mode', label: t('dispatchMode'), options: [['new', t('dispatchNew')], ['existing', t('dispatchExisting')]], value: dispatch.mode, change: ui.key('hlPlanDispatch') },
749
+ hlPlanDispatchTarget(dispatch.mode, destination),
750
+ member,
751
+ { id: 'plan-state', label: t('state'), change: ui.key('hlPlanEditState'), options: Object.entries(HL_PLAN_STATE_KEYS).map(function ([v, key]) { return [v, t(key)]; }), value: plan.state },
752
+ ...(plan.state === 'doing' ? [
753
+ { id: 'plan-work', label: t('workTopic'), options: work, value: plan.at || '', change: ui.key('hlPlanWork') },
754
+ hlPlanAssignee(plan.at, plan.assignee, true)
755
+ ] : []),
756
+ { id: 'plan-home', label: t('homeTopic'), options: options, value: plan.topicId },
757
+ { id: 'plan-why', label: t('reason'), value: initialWhy },
758
+ { id: 'plan-where', label: t('receipt'), value: initialWhere },
759
+ ...(openState(plan.state) ? [switchField('suspended', plan.suspended), resumeAtField(resumeAt)] : []),
760
+ switchField('pinned', plan.pinned)
761
+ ];
762
+ ui.dialog({ title: t('edit'), ok: t('save'), fields: fields, on: function () {
763
+ const body = {}, title = val('plan-title'), state = val('plan-state'), at = val('plan-work'), home = val('plan-home'), why = val('plan-why');
764
+ if (!title) throw new Error(t('needTitle'));
765
+ if (state === 'doing' && plan.state === 'doing' && !at) throw new Error(t('needWork'));
766
+ if (state === 'dropped' && state !== plan.state && !why) throw new Error(t('needReason'));
767
+ if (at !== (plan.at || '') && state !== 'doing' && at) throw new Error(t('workOnlyDoing'));
768
+ if (title !== plan.title) body.title = title;
769
+ if (state !== plan.state) body.state = state;
770
+ if (state === 'doing' && at && at !== plan.at) body.at = at;
771
+ const assignee = val('plan-assignee');
772
+ if (plan.state === 'doing' && state === 'doing' && assignee && (assignee !== plan.assignee || body.at)) body.member = assignee;
773
+ if (home !== plan.topicId) body.topic = home;
774
+ const date = val('plan-when');
775
+ const resource = val('plan-source-resource'), section = val('plan-source-section');
776
+ if (section && !resource) throw new Error(t('needDocumentResource'));
777
+ if (resource !== (doc?.resource || '') || section !== (doc?.section || '')) {
778
+ body.doc = resource ? { resource: resource, ...(section ? { section: section } : {}) } : null;
779
+ }
780
+ if (date !== when) body.when = date ? new Date(date).toISOString() : '';
781
+ const mode = val('plan-dispatch-mode'), target = val('plan-dispatch-target'), memberId = val('plan-dispatch-member');
782
+ const starting = state === 'doing' && plan.state !== 'doing';
783
+ if (starting || mode !== dispatch.mode || target !== destination || memberId !== (dispatch.member || '')) {
784
+ if (mode === 'existing' && !target) throw new Error(t('needDispatchTopic'));
785
+ body.dispatch = { mode: mode, ...(target ? { [mode === 'existing' ? 'topic' : 'parent']: target } : {}), ...(memberId ? { member: memberId } : {}) };
786
+ }
787
+ for (const key of textFields) {
788
+ const value = val('plan-' + key);
789
+ const original = plan[key] || '';
790
+ if (value !== (key === 'description' ? original.replace(/\r\n?/g, '\n') : original)) body[key] = value;
791
+ }
792
+ if (dependencyDraft.value !== (plan.dependencies || '')) body.dependencies = dependencyDraft.value;
793
+ for (const key of ['suspended', 'pinned']) {
794
+ const on = fields.find(function (f) { return f.id === 'plan-' + key; })?.value === true;
795
+ if (on !== !!plan[key]) body[key] = on;
796
+ }
797
+ if (openState(state)) {
798
+ const suspendedOn = fields.find(function (f) { return f.id === 'plan-suspended'; })?.value === true;
799
+ const resume = val('plan-resume-at');
800
+ if (suspendedOn && resume !== resumeAt) body.resumeAt = resume ? new Date(resume).toISOString() : '';
801
+ }
802
+ if (why && (why !== initialWhy || state !== plan.state)) { body.why = why; body.state = state; }
803
+ const where = val('plan-where');
804
+ if (where && (where !== initialWhere || state !== plan.state)) { body.where = where; body.state = state; }
805
+ if (Object.keys(body).length) return ui.request('PATCH', '/api/plans/' + id, body);
806
+ render(true);
807
+ } });
808
+ };
809
+ actions.hlPlanDrop = function ({ id }) {
810
+ ui.dialog({ title: t('dlgDropTitle', hlPlan(id).title), text: t('dropHelp'), ok: t('drop'), danger: true,
811
+ fields: [{ id: 'plan-drop-why', label: t('fieldWhy'), area: true, req: true }],
812
+ on: function () {
813
+ const why = val('plan-drop-why');
814
+ if (!why) throw new Error(t('needReason'));
815
+ return ui.request('PATCH', '/api/plans/' + id, { state: 'dropped', why: why });
816
+ } });
817
+ };
818
+
819
+ function sourceChanged(topicId, id, deleted) {
820
+ const source = 'chat-' + topicId + '/' + id;
821
+ const affects = function (items) { return items?.some(function (plan) { return plan.from.message === source; }); };
822
+ if (deleted || affects(HL_PLANS.items) || affects(HL_OVERVIEW.items)) hlPlansChanged();
823
+ }
824
+ return {
825
+ models, actions, inputs, changes,
826
+ /* An item address beside a conversation asks the workbench panel to reveal that plan. */
827
+ select(id, context) {
828
+ const item = context && context.item;
829
+ if (!item) return;
830
+ HL_PLANS.jump = { id: item, after: context.after };
831
+ hlPlansChanged();
832
+ },
833
+ update() {
834
+ const id = HL.topic?.id || '';
835
+ if (id && ui.shown('overview') && (HL_OVERVIEW.topicId !== id || (HL_OVERVIEW.dirty && HL_OVERVIEW.timer === null))) {
836
+ if (HL_OVERVIEW.topicId !== id) {
837
+ HL_OVERVIEW.items = null;
838
+ syncRows(HL_OVERVIEW_ROW, []);
839
+ }
840
+ hlOverviewQueue(id, 0);
841
+ }
842
+ },
843
+ events: {
844
+ 'plans.changed': hlPlansChanged,
845
+ 'message.changed'({ message }) { sourceChanged(message.topicId, message.id); },
846
+ 'message.deleted'({ topicId, id }) { sourceChanged(topicId, id, true); },
847
+ 'topic.updated': hlTopicsChanged,
848
+ 'plans.progress': hlPlansChanged
849
+ },
850
+ dispose() {
851
+ clearTimeout(HL_PLANS_TIMER);
852
+ clearTimeout(HL_OVERVIEW.timer);
853
+ }
854
+ };
855
+ }