kaizen-agent 1.86.0 → 1.87.0

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 (541) hide show
  1. package/README.md +1 -1
  2. package/cli/annotate-proxy.ts +6 -3
  3. package/cli/build-web.ts +46 -16
  4. package/cli/dev.ts +67 -0
  5. package/cli/docs.ts +1 -1
  6. package/cli/notes.ts +9 -3
  7. package/cli/ports.ts +121 -0
  8. package/cli/settings.ts +16 -17
  9. package/cli/state.ts +15 -29
  10. package/cli/task-service.ts +44 -14
  11. package/cli/tasks.ts +1 -1
  12. package/cli/term-image.ts +18 -0
  13. package/cli/ui-audit.allow.json +0 -1
  14. package/cli/ui-audit.ts +12 -12
  15. package/cli/web.ts +182 -58
  16. package/package.json +21 -4
  17. package/skills/kaizen/spec.md +10 -3
  18. package/tsconfig.json +16 -0
  19. package/web/README.md +105 -0
  20. package/web/{annotate.js → annotate/annotate.ts} +51 -50
  21. package/web/boot/boot.ts +7 -0
  22. package/web/components/annotate/annotate-bar.tsx +78 -0
  23. package/web/components/annotate/annotate-panel.tsx +20 -0
  24. package/web/components/annotate/annotate-settings.tsx +60 -0
  25. package/web/components/annotate/index.ts +1 -0
  26. package/web/components/annotate/notes-list.tsx +75 -0
  27. package/web/components/board/board-card.tsx +177 -0
  28. package/web/components/board/board-column.tsx +212 -0
  29. package/web/components/board/board-mode-switch.tsx +21 -0
  30. package/web/components/board/board-popups.tsx +45 -0
  31. package/web/components/board/card-footer.tsx +58 -0
  32. package/web/components/board/card-form.tsx +168 -0
  33. package/web/components/board/card-kids.tsx +53 -0
  34. package/web/components/board/clear-menu.tsx +36 -0
  35. package/web/components/board/filter-box.tsx +42 -0
  36. package/web/components/board/index.ts +6 -0
  37. package/web/components/board/run-form.tsx +129 -0
  38. package/web/components/board/severity-menu.tsx +44 -0
  39. package/web/components/board/status-strip.tsx +75 -0
  40. package/web/components/board/task-form.tsx +140 -0
  41. package/web/components/board/ws-card.tsx +38 -0
  42. package/web/components/context/context-panel.tsx +244 -0
  43. package/web/components/context/index.ts +1 -0
  44. package/web/components/decision/decision-bar.tsx +422 -0
  45. package/web/components/decision/index.ts +1 -0
  46. package/web/components/decision/inline-form.tsx +47 -0
  47. package/web/components/decision/plan-answers-form.tsx +78 -0
  48. package/web/components/decision/revise-form.tsx +65 -0
  49. package/web/components/decision/task-reply-form.tsx +48 -0
  50. package/web/components/footer/foot-bar.tsx +67 -0
  51. package/web/components/footer/index.ts +1 -0
  52. package/web/components/git/git-ask.tsx +88 -0
  53. package/web/components/git/git-commits.tsx +53 -0
  54. package/web/components/git/git-confirm.tsx +78 -0
  55. package/web/components/git/git-counts.tsx +10 -0
  56. package/web/components/git/git-files.tsx +113 -0
  57. package/web/components/git/git-head.tsx +70 -0
  58. package/web/components/git/git-icon.tsx +25 -0
  59. package/web/components/git/git-message.tsx +44 -0
  60. package/web/components/git/git-split.tsx +64 -0
  61. package/web/components/git/git-tab.tsx +55 -0
  62. package/web/components/git/index.ts +1 -0
  63. package/web/components/home/chat-list.tsx +57 -0
  64. package/web/components/home/home-composer.tsx +169 -0
  65. package/web/components/home/home-message.tsx +120 -0
  66. package/web/components/home/home-window.tsx +253 -0
  67. package/web/components/home/home-ws-add.tsx +47 -0
  68. package/web/components/home/index.ts +6 -0
  69. package/web/components/home/onboarding-dialog.tsx +371 -0
  70. package/web/components/icebox/board-chip.tsx +27 -0
  71. package/web/components/icebox/board-menu.tsx +41 -0
  72. package/web/components/icebox/bulk-bar.tsx +41 -0
  73. package/web/components/icebox/capture-box.tsx +155 -0
  74. package/web/components/icebox/choice-menu.tsx +39 -0
  75. package/web/components/icebox/collection-dialog.tsx +60 -0
  76. package/web/components/icebox/favicon.tsx +39 -0
  77. package/web/components/icebox/index.ts +10 -0
  78. package/web/components/icebox/kind-label.tsx +22 -0
  79. package/web/components/icebox/kind-menu.tsx +20 -0
  80. package/web/components/icebox/promote-form.tsx +93 -0
  81. package/web/components/icebox/reply-box.tsx +88 -0
  82. package/web/components/icebox/request-actions.tsx +141 -0
  83. package/web/components/icebox/request-badges.tsx +13 -0
  84. package/web/components/icebox/request-card.tsx +99 -0
  85. package/web/components/icebox/request-detail.tsx +43 -0
  86. package/web/components/icebox/request-images.tsx +33 -0
  87. package/web/components/icebox/request-phone-row.tsx +181 -0
  88. package/web/components/icebox/request-row.tsx +120 -0
  89. package/web/components/icebox/service-chip.tsx +58 -0
  90. package/web/components/icebox/snooze-menu.tsx +83 -0
  91. package/web/components/icebox/source-card.tsx +225 -0
  92. package/web/components/icebox/source-drawer.tsx +112 -0
  93. package/web/components/icebox/source-form.tsx +147 -0
  94. package/web/components/icebox/swipe-deck.tsx +242 -0
  95. package/web/components/layout/index.ts +1 -0
  96. package/web/components/layout/page-frame.tsx +44 -0
  97. package/web/components/markdown/index.ts +1 -0
  98. package/web/components/markdown/markdown.tsx +156 -0
  99. package/web/components/notebook/editor-pane.tsx +23 -0
  100. package/web/components/notebook/index.ts +5 -0
  101. package/web/components/notebook/note-body.tsx +172 -0
  102. package/web/components/notebook/note-tree.tsx +99 -0
  103. package/web/components/notebook/notes-head.tsx +37 -0
  104. package/web/components/notebook/notes-side.tsx +46 -0
  105. package/web/components/notes/index.ts +1 -0
  106. package/web/components/notes/note-composer.tsx +90 -0
  107. package/web/components/notes/notes-chat.tsx +58 -0
  108. package/web/components/panes/browser-pane.tsx +281 -0
  109. package/web/components/panes/index.ts +3 -0
  110. package/web/components/panes/preview-pane.tsx +91 -0
  111. package/web/components/panes/terminal-pane.tsx +52 -0
  112. package/web/components/phone/haptic.tsx +29 -0
  113. package/web/components/phone/index.ts +6 -0
  114. package/web/components/phone/phone-card.tsx +118 -0
  115. package/web/components/phone/phone-home.tsx +304 -0
  116. package/web/components/phone/phone-sheets.tsx +103 -0
  117. package/web/components/phone/qr-code.tsx +6 -0
  118. package/web/components/phone/usage-chips.tsx +85 -0
  119. package/web/components/phone/whatsapp-card.tsx +85 -0
  120. package/web/components/project/add-project-dialog.tsx +435 -0
  121. package/web/components/project/index.ts +3 -0
  122. package/web/components/project/project-bar.tsx +101 -0
  123. package/web/components/project/ws-menu.tsx +21 -0
  124. package/web/components/rail/agent-chips.tsx +110 -0
  125. package/web/components/rail/index.ts +4 -0
  126. package/web/components/rail/rail-filter.tsx +118 -0
  127. package/web/components/rail/rail-list.tsx +259 -0
  128. package/web/components/rail/source-marks.tsx +21 -0
  129. package/web/components/resources/index.ts +1 -0
  130. package/web/components/resources/resources-popup.tsx +490 -0
  131. package/web/components/run/doc-body.tsx +123 -0
  132. package/web/components/run/file-viewer.tsx +53 -0
  133. package/web/components/run/fix-form.tsx +88 -0
  134. package/web/components/run/index.ts +16 -0
  135. package/web/components/run/inline-md.tsx +30 -0
  136. package/web/components/run/key-hint.tsx +29 -0
  137. package/web/components/run/pane-gutter.tsx +52 -0
  138. package/web/components/run/pane-header.tsx +35 -0
  139. package/web/components/run/pane.tsx +140 -0
  140. package/web/components/run/panel-grip.tsx +49 -0
  141. package/web/components/run/panel-head.tsx +56 -0
  142. package/web/components/run/panel-tabs.tsx +35 -0
  143. package/web/components/run/phase-steps.tsx +37 -0
  144. package/web/components/run/project-notes.tsx +49 -0
  145. package/web/components/run/run-add-menu.tsx +80 -0
  146. package/web/components/run/run-bar.tsx +40 -0
  147. package/web/components/run/run-empty.tsx +10 -0
  148. package/web/components/run/run-footer.tsx +53 -0
  149. package/web/components/run/run-history.tsx +24 -0
  150. package/web/components/run/run-panes.tsx +78 -0
  151. package/web/components/run/run-picker.tsx +51 -0
  152. package/web/components/run/run-progress.tsx +30 -0
  153. package/web/components/run/run-tabs.tsx +147 -0
  154. package/web/components/run/run-wait.tsx +18 -0
  155. package/web/components/search/index.ts +1 -0
  156. package/web/components/search/search-palette.tsx +159 -0
  157. package/web/components/settings/account-rows.tsx +128 -0
  158. package/web/components/settings/agent-rows.tsx +249 -0
  159. package/web/components/settings/automation-rows.tsx +211 -0
  160. package/web/components/settings/browser-row.tsx +111 -0
  161. package/web/components/settings/cleanup-row.tsx +32 -0
  162. package/web/components/settings/commit-input.tsx +39 -0
  163. package/web/components/settings/index.ts +4 -0
  164. package/web/components/settings/integration-row.tsx +158 -0
  165. package/web/components/settings/mic-row.tsx +48 -0
  166. package/web/components/settings/orchestration-flow.tsx +87 -0
  167. package/web/components/settings/setting-row.tsx +131 -0
  168. package/web/components/settings/settings-item.tsx +78 -0
  169. package/web/components/settings/settings-loading.tsx +41 -0
  170. package/web/components/settings/settings-nav.tsx +119 -0
  171. package/web/components/settings/settings-scope.tsx +66 -0
  172. package/web/components/settings/settings-section.tsx +33 -0
  173. package/web/components/settings/skill-card.tsx +131 -0
  174. package/web/components/settings/stepper.tsx +74 -0
  175. package/web/components/settings/update-bar.tsx +167 -0
  176. package/web/components/shared/action-menu.tsx +76 -0
  177. package/web/components/shared/ask-host.tsx +18 -0
  178. package/web/components/shared/attach-button.tsx +23 -0
  179. package/web/components/shared/chip.tsx +19 -0
  180. package/web/components/shared/client-mark.tsx +15 -0
  181. package/web/components/shared/confirm-dialog.tsx +35 -0
  182. package/web/components/shared/empty-state.tsx +29 -0
  183. package/web/components/shared/field.tsx +77 -0
  184. package/web/components/shared/filter-popover.tsx +29 -0
  185. package/web/components/shared/form-frame.tsx +19 -0
  186. package/web/components/shared/icon-button.tsx +50 -0
  187. package/web/components/shared/index.ts +18 -0
  188. package/web/components/shared/mic-button.tsx +75 -0
  189. package/web/components/shared/pager.tsx +49 -0
  190. package/web/components/shared/picker.tsx +108 -0
  191. package/web/components/shared/project-mark.tsx +38 -0
  192. package/web/components/shared/segmented.tsx +43 -0
  193. package/web/components/shared/state-dot.tsx +4 -0
  194. package/web/components/shared/status-mark.tsx +26 -0
  195. package/web/components/shell/index.ts +3 -0
  196. package/web/components/shell/rail.tsx +259 -0
  197. package/web/components/shell/sprite.tsx +124 -0
  198. package/web/components/shell/wordmark.tsx +13 -0
  199. package/web/components/task/artifact-view.tsx +148 -0
  200. package/web/components/task/chat-bubble.tsx +43 -0
  201. package/web/components/task/filter-menu.tsx +38 -0
  202. package/web/components/task/index.ts +7 -0
  203. package/web/components/task/result-checks.tsx +34 -0
  204. package/web/components/task/result-view.tsx +103 -0
  205. package/web/components/task/status-badge.tsx +24 -0
  206. package/web/components/task/task-row.tsx +34 -0
  207. package/web/components/task/typing-dots.tsx +16 -0
  208. package/web/components/terminal/index.ts +3 -0
  209. package/web/components/terminal/terminal-bar.tsx +91 -0
  210. package/web/components/terminal/terminal-grid.tsx +149 -0
  211. package/web/components/terminal/terminal-modes.tsx +23 -0
  212. package/web/components/terminal/terminal-tile.tsx +139 -0
  213. package/web/dist/annotate.js +24 -0
  214. package/web/dist/board.css +718 -0
  215. package/web/dist/board.js +115 -0
  216. package/web/dist/boot.js +2 -0
  217. package/web/dist/notebook.css +319 -0
  218. package/web/dist/notebook.js +89 -0
  219. package/web/dist/popup.css +41 -0
  220. package/web/dist/popup.js +13 -0
  221. package/web/{term.js → dist/term.js} +48 -48
  222. package/web/dist/ui.css +3 -0
  223. package/web/dist/video.js +108 -0
  224. package/web/html/board.html +17 -0
  225. package/web/html/notes.html +14 -0
  226. package/web/html/popup.html +13 -0
  227. package/web/{video.html → html/video.html} +14 -15
  228. package/web/lib/annotate/index.ts +2 -0
  229. package/web/lib/annotate/notes.ts +105 -0
  230. package/web/lib/annotate/page.ts +121 -0
  231. package/web/lib/annotate/rules.ts +37 -0
  232. package/web/lib/annotate/session.ts +336 -0
  233. package/web/lib/board/board-actions.ts +119 -0
  234. package/web/lib/board/board-open.ts +12 -0
  235. package/web/lib/board/board-store.ts +159 -0
  236. package/web/lib/board/filter-box.ts +7 -0
  237. package/web/lib/board/index.ts +10 -0
  238. package/web/lib/board/nav.ts +29 -0
  239. package/web/lib/board/on-state.ts +90 -0
  240. package/web/lib/board/popups.ts +22 -0
  241. package/web/lib/board/snapshot.ts +105 -0
  242. package/web/lib/board/strip.ts +43 -0
  243. package/web/{board → lib/board}/ws-board.ts +1 -1
  244. package/web/lib/context/context-rules.ts +27 -0
  245. package/web/lib/context/context-store.ts +95 -0
  246. package/web/lib/context/feed.ts +28 -0
  247. package/web/lib/context/index.ts +3 -0
  248. package/web/lib/core/api.ts +86 -0
  249. package/web/lib/core/ask.ts +24 -0
  250. package/web/lib/core/board.ts +290 -0
  251. package/web/lib/core/brief.ts +31 -0
  252. package/web/lib/core/format.ts +8 -0
  253. package/web/lib/core/host.ts +107 -0
  254. package/web/lib/core/index.ts +16 -0
  255. package/web/{board → lib/core}/labels.ts +6 -5
  256. package/web/lib/core/layers.ts +7 -0
  257. package/web/lib/core/leave.ts +7 -0
  258. package/web/lib/core/motion.ts +10 -0
  259. package/web/{board/toast.ts → lib/core/notices.ts} +2 -20
  260. package/web/lib/core/notifier.ts +15 -0
  261. package/web/lib/core/store.ts +39 -0
  262. package/web/lib/core/term-handle.ts +8 -0
  263. package/web/lib/core/toast.ts +29 -0
  264. package/web/lib/core/utils.ts +15 -0
  265. package/web/lib/decision/index.ts +1 -0
  266. package/web/lib/decision/plan-questions.ts +39 -0
  267. package/web/lib/dictation/chunks.ts +93 -0
  268. package/web/lib/dictation/dictation-store.ts +22 -0
  269. package/web/lib/dictation/engine.ts +265 -0
  270. package/web/lib/dictation/index.ts +5 -0
  271. package/web/lib/dictation/mic.ts +42 -0
  272. package/web/lib/dictation/terminal-dictation.ts +50 -0
  273. package/web/lib/footer/footer-rules.ts +13 -0
  274. package/web/lib/footer/footer-store.ts +42 -0
  275. package/web/lib/footer/index.ts +2 -0
  276. package/web/lib/git/git-actions.ts +110 -0
  277. package/web/lib/git/git-panel.ts +43 -0
  278. package/web/lib/git/git-store.ts +47 -0
  279. package/web/lib/git/git.ts +170 -0
  280. package/web/lib/git/index.ts +4 -0
  281. package/web/lib/home/home-engine.ts +16 -0
  282. package/web/lib/home/home-events.ts +9 -0
  283. package/web/lib/home/home-store.ts +247 -0
  284. package/web/lib/home/home-window.ts +193 -0
  285. package/web/lib/home/home.ts +85 -0
  286. package/web/lib/home/index.ts +7 -0
  287. package/web/lib/home/onboarding.ts +199 -0
  288. package/web/lib/home/use-float-drag.ts +62 -0
  289. package/web/lib/icebox/icebox-actions.ts +518 -0
  290. package/web/lib/icebox/icebox-store.ts +112 -0
  291. package/web/lib/icebox/icebox-view.ts +48 -0
  292. package/web/lib/icebox/icebox.ts +273 -0
  293. package/web/lib/icebox/index.ts +8 -0
  294. package/web/lib/icebox/use-card-drag.ts +82 -0
  295. package/web/lib/icebox/use-ice-keys.ts +75 -0
  296. package/web/lib/icebox/use-icebox.ts +41 -0
  297. package/web/lib/icebox/use-row-swipe.ts +107 -0
  298. package/web/lib/markdown/index.ts +1 -0
  299. package/web/lib/markdown/markdown.ts +136 -0
  300. package/web/lib/notebook/autosave.ts +131 -0
  301. package/web/lib/notebook/deal.ts +58 -0
  302. package/web/lib/notebook/engine-complete.ts +128 -0
  303. package/web/lib/notebook/engine-preview.ts +287 -0
  304. package/web/lib/notebook/engine-types.ts +26 -0
  305. package/web/lib/notebook/engine-widgets.ts +218 -0
  306. package/web/lib/notebook/engine.ts +74 -0
  307. package/web/lib/notebook/index.ts +9 -0
  308. package/web/lib/notebook/kit-loader.ts +16 -0
  309. package/web/lib/notebook/kit.ts +12 -0
  310. package/web/{notes-lib.ts → lib/notebook/text.ts} +11 -10
  311. package/web/lib/notebook/vault-actions.ts +239 -0
  312. package/web/lib/notebook/vault-rules.ts +74 -0
  313. package/web/lib/notebook/vault-session.ts +73 -0
  314. package/web/lib/notebook/vault-store.ts +63 -0
  315. package/web/lib/notes/index.ts +4 -0
  316. package/web/lib/notes/md-html.ts +115 -0
  317. package/web/lib/notes/notes-actions.ts +32 -0
  318. package/web/lib/notes/notes-store.ts +22 -0
  319. package/web/lib/notes/notes.ts +58 -0
  320. package/web/{board → lib/notes}/rich.ts +1 -2
  321. package/web/lib/phone/index.ts +7 -0
  322. package/web/lib/phone/phone-actions.ts +77 -0
  323. package/web/lib/phone/phone-home.ts +102 -0
  324. package/web/lib/phone/phone-setup.ts +59 -0
  325. package/web/lib/phone/phone-sheet.ts +25 -0
  326. package/web/lib/phone/phone-store.ts +32 -0
  327. package/web/lib/phone/sheet-swipe.ts +55 -0
  328. package/web/lib/phone/use-phone-setup.ts +89 -0
  329. package/web/lib/project/add-project.ts +37 -0
  330. package/web/lib/project/branch.ts +14 -0
  331. package/web/lib/project/index.ts +5 -0
  332. package/web/lib/project/project-bar.ts +76 -0
  333. package/web/lib/project/project-pick.ts +36 -0
  334. package/web/lib/project/ws-menu.ts +8 -0
  335. package/web/lib/rail/agents.ts +63 -0
  336. package/web/lib/rail/card-links.ts +20 -0
  337. package/web/lib/rail/index.ts +7 -0
  338. package/web/lib/rail/rail-actions.ts +74 -0
  339. package/web/lib/rail/rail-boot.ts +99 -0
  340. package/web/lib/rail/rail-store.ts +85 -0
  341. package/web/lib/rail/rules.ts +241 -0
  342. package/web/lib/rail/source-marks.ts +17 -0
  343. package/web/lib/rail/use-rank-drag.ts +108 -0
  344. package/web/lib/resources/index.ts +3 -0
  345. package/web/lib/resources/resources-actions.ts +59 -0
  346. package/web/lib/resources/resources-store.ts +48 -0
  347. package/web/lib/resources/rules.ts +56 -0
  348. package/web/lib/router/index.ts +3 -0
  349. package/web/lib/router/route-rules.ts +96 -0
  350. package/web/lib/router/route-store.ts +115 -0
  351. package/web/lib/router/use-route-classes.ts +15 -0
  352. package/web/lib/run/browser.ts +53 -0
  353. package/web/lib/run/card-terminal.ts +32 -0
  354. package/web/lib/run/doc.ts +42 -0
  355. package/web/lib/run/grip.ts +8 -0
  356. package/web/lib/run/index.ts +19 -0
  357. package/web/lib/run/kept.ts +58 -0
  358. package/web/lib/run/layout-store.ts +156 -0
  359. package/web/lib/run/layout.ts +195 -0
  360. package/web/lib/run/panel-actions.ts +104 -0
  361. package/web/lib/run/panel-derive.ts +148 -0
  362. package/web/lib/run/panel-store.ts +125 -0
  363. package/web/lib/run/preview.ts +105 -0
  364. package/web/lib/run/run-actions.ts +118 -0
  365. package/web/lib/run/run-view-store.ts +134 -0
  366. package/web/lib/run/term-loader.ts +19 -0
  367. package/web/lib/run/use-panel-run.ts +125 -0
  368. package/web/lib/run/use-run-lifecycle.ts +70 -0
  369. package/web/lib/run/viewer.ts +12 -0
  370. package/web/lib/run/workspace.ts +281 -0
  371. package/web/lib/run/ws-actions.ts +293 -0
  372. package/web/lib/run/ws-derive.ts +50 -0
  373. package/web/lib/run/ws-draw.ts +102 -0
  374. package/web/lib/run/ws-store.ts +21 -0
  375. package/web/lib/run/ws-tabs.ts +125 -0
  376. package/web/lib/search/index.ts +3 -0
  377. package/web/lib/search/search-match.ts +48 -0
  378. package/web/lib/search/search-rows.ts +228 -0
  379. package/web/lib/search/search.ts +30 -0
  380. package/web/lib/search/use-search-rows.ts +22 -0
  381. package/web/lib/server/attention.ts +29 -0
  382. package/web/lib/server/index.ts +6 -0
  383. package/web/lib/server/poll-rules.ts +57 -0
  384. package/web/lib/server/poller.ts +210 -0
  385. package/web/lib/server/server-store.ts +39 -0
  386. package/web/lib/server/types.ts +31 -0
  387. package/web/lib/server/use-server.ts +19 -0
  388. package/web/lib/settings/agent-favicons.ts +14 -0
  389. package/web/lib/settings/index.ts +7 -0
  390. package/web/lib/settings/panel-settings.ts +29 -0
  391. package/web/lib/settings/settings-actions.ts +357 -0
  392. package/web/lib/settings/settings-store.ts +114 -0
  393. package/web/lib/settings/settings.ts +413 -0
  394. package/web/lib/settings/skill-icons.ts +24 -0
  395. package/web/lib/settings/update.ts +70 -0
  396. package/web/lib/shared/data-urls.ts +32 -0
  397. package/web/lib/shared/index.ts +4 -0
  398. package/web/lib/shared/use-draft.ts +38 -0
  399. package/web/lib/shared/use-narrow.ts +11 -0
  400. package/web/lib/shared/use-pager.ts +24 -0
  401. package/web/lib/shell/appearance.ts +97 -0
  402. package/web/lib/shell/help-store.ts +4 -0
  403. package/web/lib/shell/index.ts +4 -0
  404. package/web/lib/shell/shell-store.ts +23 -0
  405. package/web/lib/shell/stored-look.ts +47 -0
  406. package/web/lib/task/index.ts +7 -0
  407. package/web/lib/task/task-results.ts +92 -0
  408. package/web/lib/task/tasks.ts +132 -0
  409. package/web/lib/task/use-live-frame.ts +85 -0
  410. package/web/lib/task/use-saved-text.ts +25 -0
  411. package/web/lib/task/use-task.ts +161 -0
  412. package/web/lib/task/use-tasks.ts +50 -0
  413. package/web/{board → lib/task}/zoom.ts +25 -12
  414. package/web/lib/terminal/hidden-badge.ts +15 -0
  415. package/web/lib/terminal/index.ts +8 -0
  416. package/web/lib/terminal/layout.ts +138 -0
  417. package/web/{term-font.ts → lib/terminal/term-font.ts} +3 -2
  418. package/web/lib/terminal/terminal-store.ts +65 -0
  419. package/web/lib/terminal/terms-feed.ts +37 -0
  420. package/web/lib/terminal/use-arranged.ts +15 -0
  421. package/web/lib/terminal/use-terminal-keys.ts +37 -0
  422. package/web/lib/url/index.ts +1 -0
  423. package/web/lib/url/safe-url.ts +9 -0
  424. package/web/notebook/notebook.ts +27 -0
  425. package/web/notebook/notes-lib.ts +3 -0
  426. package/web/pages/board/App.tsx +76 -0
  427. package/web/pages/board/header.tsx +83 -0
  428. package/web/pages/board/help.tsx +59 -0
  429. package/web/pages/board/host-bridge.ts +94 -0
  430. package/web/pages/board/host.tsx +19 -0
  431. package/web/pages/board/keys.ts +112 -0
  432. package/web/pages/board/live.ts +39 -0
  433. package/web/pages/board/main.ts +32 -0
  434. package/web/pages/board/pages.tsx +86 -0
  435. package/web/pages/board/panel.tsx +157 -0
  436. package/web/pages/board/portal.tsx +39 -0
  437. package/web/pages/board/use-boot.ts +13 -0
  438. package/web/pages/board/views.ts +63 -0
  439. package/web/pages/board-page.tsx +62 -0
  440. package/web/pages/home-page.tsx +127 -0
  441. package/web/pages/icebox-page.tsx +440 -0
  442. package/web/pages/notebook/App.tsx +35 -0
  443. package/web/pages/notebook-page.tsx +50 -0
  444. package/web/pages/popup/App.tsx +207 -0
  445. package/web/pages/settings-page.tsx +111 -0
  446. package/web/pages/task-page.tsx +383 -0
  447. package/web/pages/tasks-page.tsx +151 -0
  448. package/web/pages/terminal-page.tsx +15 -0
  449. package/web/popup/popup.ts +7 -0
  450. package/web/{term.ts → term/term.ts} +48 -20
  451. package/web/ui/alert-dialog.tsx +39 -0
  452. package/web/ui/badge.tsx +20 -0
  453. package/web/ui/button.tsx +37 -0
  454. package/web/ui/checkbox.tsx +20 -0
  455. package/web/ui/command.tsx +41 -0
  456. package/web/ui/dialog.tsx +28 -0
  457. package/web/ui/dropdown-menu.tsx +54 -0
  458. package/web/ui/icon.tsx +17 -0
  459. package/web/ui/index.ts +21 -0
  460. package/web/ui/input.tsx +9 -0
  461. package/web/ui/label.tsx +7 -0
  462. package/web/ui/legacy/board.css +715 -0
  463. package/web/{notes.html → ui/legacy/notes.css} +23 -157
  464. package/web/ui/legacy/popup.css +40 -0
  465. package/web/ui/popover.tsx +28 -0
  466. package/web/ui/select.tsx +61 -0
  467. package/web/ui/sheet.tsx +43 -0
  468. package/web/ui/skeleton.tsx +6 -0
  469. package/web/ui/sonner.tsx +25 -0
  470. package/web/ui/spinner.tsx +12 -0
  471. package/web/ui/switch.tsx +18 -0
  472. package/web/ui/tabs.tsx +18 -0
  473. package/web/ui/textarea.tsx +14 -0
  474. package/web/ui/theme.css +125 -0
  475. package/web/ui/toggle.tsx +8 -0
  476. package/web/ui/tooltip.tsx +26 -0
  477. package/web/{video.ts → video/video.ts} +5 -5
  478. package/web/board/add-project.ts +0 -147
  479. package/web/board/agent-favicons.ts +0 -9
  480. package/web/board/agent-term.ts +0 -51
  481. package/web/board/annotate-lib.ts +0 -19
  482. package/web/board/annotate.ts +0 -221
  483. package/web/board/api.ts +0 -180
  484. package/web/board/approvals.ts +0 -109
  485. package/web/board/badge.ts +0 -115
  486. package/web/board/cards.ts +0 -1080
  487. package/web/board/chat.ts +0 -128
  488. package/web/board/context.ts +0 -248
  489. package/web/board/dictation.ts +0 -343
  490. package/web/board/dom.ts +0 -132
  491. package/web/board/drafts.ts +0 -21
  492. package/web/board/fixes.ts +0 -89
  493. package/web/board/git.ts +0 -416
  494. package/web/board/home-ws.ts +0 -266
  495. package/web/board/home.ts +0 -421
  496. package/web/board/icebox.ts +0 -1788
  497. package/web/board/keys.ts +0 -121
  498. package/web/board/live.ts +0 -87
  499. package/web/board/main.ts +0 -94
  500. package/web/board/markdown.ts +0 -210
  501. package/web/board/onboarding.ts +0 -227
  502. package/web/board/panel.ts +0 -437
  503. package/web/board/phone-setup.ts +0 -79
  504. package/web/board/phone.ts +0 -219
  505. package/web/board/projects.ts +0 -277
  506. package/web/board/resources.ts +0 -170
  507. package/web/board/run-pick.ts +0 -41
  508. package/web/board/run-view.ts +0 -1316
  509. package/web/board/search-match.ts +0 -20
  510. package/web/board/search.ts +0 -330
  511. package/web/board/settings-accounts.ts +0 -76
  512. package/web/board/settings-agents.ts +0 -102
  513. package/web/board/settings-automations.ts +0 -71
  514. package/web/board/settings-cleanup.ts +0 -42
  515. package/web/board/settings-orchestration.ts +0 -32
  516. package/web/board/settings-pages.ts +0 -62
  517. package/web/board/settings-skills.ts +0 -103
  518. package/web/board/settings-voice.ts +0 -28
  519. package/web/board/settings.ts +0 -490
  520. package/web/board/store.ts +0 -47
  521. package/web/board/task-page.ts +0 -628
  522. package/web/board/task-results.ts +0 -234
  523. package/web/board/tasks.ts +0 -242
  524. package/web/board/terms.ts +0 -390
  525. package/web/board/update.ts +0 -171
  526. package/web/board/viewer.ts +0 -47
  527. package/web/board/views.ts +0 -164
  528. package/web/board/whatsapp-setup.ts +0 -149
  529. package/web/board/workspace.ts +0 -650
  530. package/web/board/ws-board-ui.ts +0 -95
  531. package/web/board/ws-tabs.ts +0 -227
  532. package/web/board.html +0 -1563
  533. package/web/board.js +0 -505
  534. package/web/notebook.js +0 -519
  535. package/web/notebook.ts +0 -1254
  536. package/web/popup.html +0 -141
  537. package/web/video.js +0 -575
  538. /package/web/{term.css → dist/term.css} +0 -0
  539. /package/web/{board/term-sessions.ts → lib/terminal/sessions.ts} +0 -0
  540. /package/web/{board/terminal-viewport.ts → lib/terminal/viewport.ts} +0 -0
  541. /package/web/{term-paste.ts → term/term-paste.ts} +0 -0
@@ -0,0 +1,239 @@
1
+ // What the notebook page does: reads and writes through /vault (the page never sees the filesystem), opens, creates,
2
+ // renames and deletes notes, and keeps the open note saved (Autosave, 600 ms; every move away flushes first).
3
+ import { ask, toast } from "@lib/core";
4
+ import { Autosave, type SaveResult } from "./autosave.ts";
5
+ import { lift } from "./deal.ts";
6
+ import type { EditorHandle } from "./engine.ts";
7
+ import type { EditorHost } from "./engine-types.ts";
8
+ import { resolve, freshName } from "./text.ts";
9
+ import { folderOf, renameMessage, renameTarget, type Note } from "./vault-rules.ts";
10
+ import { getVault, setVault, writeWide } from "./vault-store.ts";
11
+
12
+ // ---- the editor in the page (one at a time, registered by the component that made it)
13
+ let ed: EditorHandle | null = null;
14
+ export const setEditor = (h: EditorHandle | null) => {
15
+ ed = h;
16
+ };
17
+ export const getEditor = () => ed;
18
+
19
+ async function post(body: Record<string, unknown>) {
20
+ try {
21
+ const r = await fetch("/vault", {
22
+ method: "POST",
23
+ headers: { "content-type": "application/json" },
24
+ body: JSON.stringify({ dir: getVault().dir, ...body }),
25
+ });
26
+ return { status: r.status, ...(await r.json().catch(() => ({}))) } as Record<string, any>;
27
+ } catch {
28
+ return { status: 0, error: "The board is not running" } as Record<string, any>;
29
+ }
30
+ }
31
+
32
+ // ---- saving (autosave.ts holds the rules; this wires it to the request, the editor and the store)
33
+ export const save = new Autosave({
34
+ read: () => ed?.text() ?? null,
35
+ timer: { set: (f, ms) => setTimeout(f, ms), clear: (t) => clearTimeout(t as ReturnType<typeof setTimeout>) },
36
+ save: async (name, text, base): Promise<SaveResult> => {
37
+ const r = await post({ op: "save", name, text, base });
38
+ return r.ok
39
+ ? { ok: true, mtime: r.mtime }
40
+ : { ok: false, status: r.status, error: r.error, text: r.text, mtime: r.mtime };
41
+ },
42
+ onState: (s, c) => setVault({ save: s, conflict: c }),
43
+ onSaved: (name, text, mtime) => upsert({ name, mtime, text }),
44
+ onError: toast,
45
+ });
46
+ export const flush = () => save.flush();
47
+ const upsert = (n: Note) => setVault((s) => ({ notes: [n, ...s.notes.filter((x) => x.name !== n.name)] }));
48
+ // Leaving with unsaved text: a keepalive request outlives the page (pagehide).
49
+ export function saveOnExit() {
50
+ const v = getVault();
51
+ if (v.open && ed && save.dirty && !save.conflict)
52
+ void fetch("/vault", {
53
+ method: "POST",
54
+ keepalive: true,
55
+ headers: { "content-type": "application/json" },
56
+ body: JSON.stringify({ dir: v.dir, op: "save", name: v.open, text: ed.text(), base: save.base }),
57
+ }).catch(() => {});
58
+ }
59
+ export const keepMine = () => save.keepMine();
60
+ export function takeTheirs() {
61
+ const c = save.takeTheirs();
62
+ if (c) ed?.replace(c.text);
63
+ }
64
+
65
+ // ---- the vault
66
+ export async function loadVault() {
67
+ const { dir } = getVault();
68
+ let r: { notes?: Note[]; error?: string };
69
+ try {
70
+ r = await (await fetch("/vault?dir=" + encodeURIComponent(dir))).json();
71
+ } catch {
72
+ toast("The board is not running");
73
+ return;
74
+ }
75
+ if (!r.notes) {
76
+ toast(r.error || "Could not read notes");
77
+ return;
78
+ }
79
+ const notes = r.notes;
80
+ // The board's items, for chips and completion; a failure keeps the last ones.
81
+ let board = getVault().board;
82
+ try {
83
+ const b = await (await fetch("/links?dir=" + encodeURIComponent(dir))).json();
84
+ if (Array.isArray(b.runs)) board = b;
85
+ } catch {
86
+ /* keep */
87
+ }
88
+ // A project picked while this was out: its own load is the one that counts.
89
+ if (getVault().dir !== dir) return;
90
+ setVault({ notes, board, ready: true });
91
+ const mine = getVault().open && notes.find((n) => n.name === getVault().open);
92
+ // Someone else changed the open note: take it only when nothing typed here is unsaved.
93
+ if (mine && mine.mtime !== save.base && !save.dirty && !save.busy) {
94
+ save.adopt(mine.mtime);
95
+ ed?.replace(mine.text);
96
+ }
97
+ ed?.refresh();
98
+ }
99
+
100
+ // False when the open note still holds text that is not on disk: it stays open.
101
+ export async function openNote(name: string | null): Promise<boolean> {
102
+ if (name === getVault().open) return true;
103
+ await flush();
104
+ if (save.dirty) {
105
+ toast(save.conflict ? "Choose Keep mine or Load theirs first" : "This note is not saved yet");
106
+ return false;
107
+ }
108
+ lift();
109
+ const v = getVault(),
110
+ n = name ? v.notes.find((x) => x.name === name) : null;
111
+ save.open(name, n?.mtime ?? 0);
112
+ setVault({ open: name, doc: v.doc + 1, drawer: false });
113
+ try {
114
+ name ? sessionStorage.setItem("kz-note:" + v.dir, name) : sessionStorage.removeItem("kz-note:" + v.dir);
115
+ } catch {
116
+ /* private window */
117
+ }
118
+ return true;
119
+ }
120
+
121
+ // `focus` is set before the note opens: the editor is made by that open and takes it as it mounts.
122
+ async function create(name: string, focus: "editor" | null = null) {
123
+ const r = await post({ op: "save", name, text: "", base: 0 });
124
+ if (!r.ok) {
125
+ toast(r.status === 409 ? "A note with that name exists" : r.error || "Could not create the note");
126
+ return false;
127
+ }
128
+ upsert({ name: r.name, mtime: r.mtime, text: "" });
129
+ if (focus) setVault({ focus });
130
+ const ok = await openNote(r.name);
131
+ // Not opened (the open note holds unsaved text): nothing should take the focus later.
132
+ if (focus && !ok) setVault({ focus: null });
133
+ return ok;
134
+ }
135
+ export async function openOrCreate(name: string) {
136
+ const hit = resolve(name, noteNames());
137
+ if (hit) return void openNote(hit);
138
+ await create(name, "editor");
139
+ }
140
+ export async function newNote() {
141
+ const open = getVault().open;
142
+ if (await create(freshName(noteNames(), open ? folderOf(open) : ""))) setVault({ focus: "title" });
143
+ }
144
+ export const noteNames = () => getVault().notes.map((n) => n.name);
145
+
146
+ // The name box lost focus (or Enter): rename, which is also a move when the name holds a `/`.
147
+ export async function renameNote(to: string) {
148
+ const from = getVault().open,
149
+ target = from ? renameTarget(from, to) : null;
150
+ const reset = () => setVault((s) => ({ titleRev: s.titleRev + 1 }));
151
+ if (!from || !target) return reset();
152
+ await flush();
153
+ // Typing while the rename is out waits for it: saved under the old name it would be a false conflict.
154
+ save.hold();
155
+ const r = await post({ op: "rename", name: from, to });
156
+ if (!r.ok) {
157
+ save.release();
158
+ toast(r.error || "Could not rename");
159
+ return reset();
160
+ }
161
+ // Another note was opened meanwhile: the rename stands, the editor stays where it is.
162
+ if (getVault().open !== from) return (save.release(), loadVault());
163
+ // The same editor stays: only the name changes.
164
+ save.renamed(target);
165
+ setVault({ open: target });
166
+ await loadVault();
167
+ save.adopt(getVault().notes.find((n) => n.name === target)?.mtime ?? save.base);
168
+ save.release();
169
+ reset();
170
+ toast(renameMessage(from, target));
171
+ }
172
+
173
+ export async function removeNote() {
174
+ const name = getVault().open;
175
+ if (!name) return;
176
+ const yes = await ask({
177
+ title: "Move this note to notes/.trash?",
178
+ description: name,
179
+ confirmLabel: "Delete",
180
+ danger: true,
181
+ });
182
+ if (!yes || getVault().open !== name) return;
183
+ save.discard();
184
+ const r = await post({ op: "delete", name });
185
+ if (!r.ok) {
186
+ toast(r.error || "Could not delete");
187
+ return;
188
+ }
189
+ toast("Moved to notes/.trash");
190
+ setVault((s) => ({ notes: s.notes.filter((n) => n.name !== name) }));
191
+ await openNote(null);
192
+ }
193
+
194
+ // ---- the project
195
+ export async function setProject(dir: string) {
196
+ if (dir === getVault().dir) return;
197
+ if (!(await openNote(null))) return;
198
+ setVault({ dir, notes: [], ready: false, query: "" });
199
+ const u = new URL(location.href);
200
+ u.searchParams.set("dir", dir);
201
+ window.history.replaceState(null, "", u);
202
+ await loadVault();
203
+ }
204
+
205
+ // ---- the page's own switches
206
+ export const setQuery = (query: string) => setVault({ query });
207
+ export const toggleFolder = (path: string, open: boolean) =>
208
+ setVault((s) => {
209
+ if (!!s.shut[path] === !open) return {}; // the tree reports a folder's state on first draw too
210
+ const shut = { ...s.shut };
211
+ if (open) delete shut[path];
212
+ else shut[path] = true;
213
+ return { shut };
214
+ });
215
+ export const setFull = (full: boolean) => setVault({ full });
216
+ export function setWide(wide: boolean) {
217
+ writeWide(wide);
218
+ setVault({ wide });
219
+ }
220
+ export const setDrawer = (drawer: boolean) => setVault({ drawer });
221
+
222
+ // ---- what the editor may ask of the page
223
+ export const vaultHost: EditorHost = {
224
+ names: noteNames,
225
+ board: () => getVault().board,
226
+ dir: () => getVault().dir,
227
+ edited: () => save.edit(),
228
+ save: () => void flush(),
229
+ openNote: (n) => void openNote(n),
230
+ openOrCreate: (n) => void openOrCreate(n),
231
+ search: setQuery,
232
+ toast,
233
+ // Leave for the board only once the note is on disk.
234
+ async go(href) {
235
+ await flush();
236
+ if (save.dirty) return toast("This note is not saved yet");
237
+ location.href = href;
238
+ },
239
+ };
@@ -0,0 +1,74 @@
1
+ // What the notebook page decides from its list of notes, with no DOM: names and folders, the search box, the tags, the
2
+ // backlinks, how a rename reads, and the age beside a note. The page draws what these return.
3
+ import { resolve, tags, wikilinks } from "./text.ts";
4
+
5
+ export type Note = { name: string; mtime: number; text: string };
6
+
7
+ export const last = (name: string) => name.split("/").pop()!;
8
+ export const folderOf = (name: string) => (name.includes("/") ? name.slice(0, name.lastIndexOf("/")) : "");
9
+
10
+ // The name a rename asks for, as the server stores it: no `.md`, each part trimmed. Null when there is nothing to do (an
11
+ // empty box, or the note's own name).
12
+ export function renameTarget(open: string, to: string): string | null {
13
+ const t = to.trim();
14
+ if (!t || t === open) return null;
15
+ return t
16
+ .replace(/\.md$/i, "")
17
+ .split("/")
18
+ .map((p) => p.trim())
19
+ .join("/");
20
+ }
21
+ // "Renamed" within a folder, "Moved to X" across folders (the top for none).
22
+ export const renameMessage = (from: string, to: string) =>
23
+ folderOf(from) === folderOf(to) ? "Renamed" : `Moved to ${folderOf(to) || "the top"}`;
24
+
25
+ // The search box: empty, a `#tag`, or words. `tag` is set only for a `#` query (an empty tag matches every tagged note).
26
+ export type Query = { text: string; tag: string | null };
27
+ export function parseQuery(raw: string): Query {
28
+ const text = raw.trim().toLowerCase();
29
+ return { text, tag: text.startsWith("#") ? text.slice(1) : null };
30
+ }
31
+ // Notes the query keeps, in list order: a tag also matches its children (`#work` finds `work/standup`); words match
32
+ // the name or the text.
33
+ export function searchNotes(notes: Note[], q: Query): Note[] {
34
+ if (!q.text) return notes;
35
+ const tag = q.tag;
36
+ return notes.filter((n) =>
37
+ tag !== null
38
+ ? tags(n.text).some((x) => x.tag === tag || x.tag.startsWith(tag + "/"))
39
+ : n.name.toLowerCase().includes(q.text) || n.text.toLowerCase().includes(q.text),
40
+ );
41
+ }
42
+ // Tags with the number of notes using each, most used first.
43
+ export function tagCounts(notes: Note[]): [string, number][] {
44
+ const count = new Map<string, number>();
45
+ for (const n of notes) for (const g of new Set(tags(n.text).map((x) => x.tag))) count.set(g, (count.get(g) ?? 0) + 1);
46
+ return [...count].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
47
+ }
48
+ // A tag chip pressed: the search becomes `#tag`, or empties when it already was.
49
+ export const toggleTag = (query: string, tag: string) => (query === "#" + tag ? "" : "#" + tag);
50
+
51
+ // Notes (other than `name`) that link to it by a wikilink.
52
+ export function backlinks(notes: Note[], name: string): Note[] {
53
+ const names = notes.map((n) => n.name);
54
+ return notes.filter((n) => n.name !== name && wikilinks(n.text).some((l) => resolve(l.name, names) === name));
55
+ }
56
+
57
+ // How long ago, in the one unit that fits: now, 5m, 3h, 2d.
58
+ export function age(ms: number, now = Date.now()) {
59
+ const s = (now - ms) / 1000;
60
+ return s < 60
61
+ ? "now"
62
+ : s < 3600
63
+ ? `${Math.floor(s / 60)}m`
64
+ : s < 86400
65
+ ? `${Math.floor(s / 3600)}h`
66
+ : `${Math.floor(s / 86400)}d`;
67
+ }
68
+
69
+ // The note the page opens at start: ?note= (the board's "Linked from notes") if it exists, else the one open last in
70
+ // this tab; null when that one is gone.
71
+ export function startNote(names: string[], asked: string | null, kept: string | null): string | null {
72
+ const pick = asked && names.includes(asked) ? asked : kept;
73
+ return pick && names.includes(pick) ? pick : null;
74
+ }
@@ -0,0 +1,73 @@
1
+ // The page's life: which project to show, the first load, the note open last, live refresh from the board's events, and
2
+ // every way a page can end (leaving for the board, closing, hiding) writing the open note first.
3
+ import { onLeave, toast } from "@lib/core";
4
+ import { flush, loadVault, openNote, saveOnExit, save } from "./vault-actions.ts";
5
+ import { pickProject } from "./text.ts";
6
+ import { startNote } from "./vault-rules.ts";
7
+ import { getVault, setVault } from "./vault-store.ts";
8
+
9
+ export async function startVault(o: { onChanged?: () => void } = {}) {
10
+ guards();
11
+ let st: { dir: string | null; projects: { dir: string; label: string }[]; known?: { dir: string; label: string }[] };
12
+ try {
13
+ st = await (await fetch("/state")).json();
14
+ } catch {
15
+ toast("The board is not running");
16
+ return;
17
+ }
18
+ let kept: string | null = null;
19
+ try {
20
+ kept = localStorage.getItem("kz-proj");
21
+ } catch {
22
+ /* no storage */
23
+ }
24
+ // The Notes tab lists every known project, not only the board picker's (a project outside the Projects folder too).
25
+ const p = pickProject(new URLSearchParams(location.search).get("dir"), kept, st.dir, st.known ?? st.projects);
26
+ setVault({ dir: p.dir, projects: p.projects });
27
+ await loadVault();
28
+ let lastNote: string | null = null;
29
+ try {
30
+ lastNote = sessionStorage.getItem("kz-note:" + p.dir);
31
+ } catch {
32
+ /* no storage */
33
+ }
34
+ // ?note= is the board's "Linked from notes"; otherwise the note open last in this tab.
35
+ const again = startNote(
36
+ getVault().notes.map((n) => n.name),
37
+ new URLSearchParams(location.search).get("note"),
38
+ lastNote,
39
+ );
40
+ if (again) await openNote(again);
41
+ // Every write under a state dir arrives as `changed`, this page's own saves included.
42
+ const listen = () => {
43
+ const es = new EventSource("/events");
44
+ es.onmessage = (ev) => {
45
+ if (ev.data !== "changed") return;
46
+ void loadVault();
47
+ o.onChanged?.();
48
+ };
49
+ es.onerror = () => {
50
+ es.close();
51
+ setTimeout(listen, 3000);
52
+ };
53
+ };
54
+ listen();
55
+ }
56
+
57
+ let guarded = false;
58
+ function guards() {
59
+ if (guarded) return;
60
+ guarded = true;
61
+ // Closing with text not on disk: the browser asks first.
62
+ addEventListener("beforeunload", (e) => {
63
+ if (save.dirty) e.preventDefault();
64
+ });
65
+ // Hidden (a tab switch, a phone's app switch, a window minimised): write now, the page may never come back.
66
+ document.addEventListener("visibilitychange", () => {
67
+ if (document.visibilityState === "hidden") void flush();
68
+ });
69
+ // Leaving for the board through Search (Ctrl+K): the note is written first.
70
+ onLeave(flush);
71
+ // Leaving with unsaved text: a keepalive request outlives the page.
72
+ addEventListener("pagehide", saveOnExit);
73
+ }
@@ -0,0 +1,63 @@
1
+ // The notebook page's state: the project and its notes, the note open, how its save stands, the search box and the
2
+ // page's own switches (full screen, width, the narrow layout's drawer). Read by the components; written by vault-actions.
3
+ import { create } from "zustand";
4
+ import type { Conflict, SaveState } from "./autosave.ts";
5
+ import { emptyBoard, type Board } from "./engine-types.ts";
6
+ import type { Note } from "./vault-rules.ts";
7
+
8
+ export type Project = { dir: string; label: string };
9
+ export type Vault = {
10
+ ready: boolean; // the first list of notes has arrived
11
+ dir: string; // the state dir whose notes/ is shown
12
+ projects: Project[];
13
+ notes: Note[];
14
+ board: Board; // what [[run:...]] and [[idea:...]] can name, from /links
15
+ open: string | null; // the note in the editor
16
+ doc: number; // counts note openings: the editor is made again for each, never for a rename or a redraw
17
+ save: SaveState;
18
+ conflict: Conflict | null;
19
+ query: string; // the search box
20
+ shut: Record<string, true>; // folders folded in the tree, for this page load
21
+ full: boolean; // the open note alone, no header or sidebar
22
+ wide: boolean; // the whole paper side instead of the reading column (kept per browser)
23
+ drawer: boolean; // the narrow layout's note list is open
24
+ focus: "title" | "editor" | null; // where focus goes once the note just opened is drawn
25
+ titleRev: number; // bumped to put the name box back to the note's name
26
+ };
27
+
28
+ const wideKey = "kz-note-wide";
29
+ export const readWide = () => {
30
+ try {
31
+ return localStorage.getItem(wideKey) === "1";
32
+ } catch {
33
+ return false; // no storage
34
+ }
35
+ };
36
+ export const writeWide = (on: boolean) => {
37
+ try {
38
+ localStorage.setItem(wideKey, on ? "1" : "0");
39
+ } catch {
40
+ /* no storage */
41
+ }
42
+ };
43
+
44
+ export const useVault = create<Vault>()(() => ({
45
+ ready: false,
46
+ dir: "",
47
+ projects: [],
48
+ notes: [],
49
+ board: emptyBoard(),
50
+ open: null,
51
+ doc: 0,
52
+ save: "saved",
53
+ conflict: null,
54
+ query: "",
55
+ shut: {},
56
+ full: false,
57
+ wide: readWide(),
58
+ drawer: false,
59
+ focus: null,
60
+ titleRev: 0,
61
+ }));
62
+ export const getVault = useVault.getState;
63
+ export const setVault = useVault.setState;
@@ -0,0 +1,4 @@
1
+ export * from "./notes-actions.ts";
2
+ export * from "./notes-store.ts";
3
+ export * from "./notes.ts";
4
+ export * from "./rich.ts";
@@ -0,0 +1,115 @@
1
+ // The notes editor's markdown as an HTML string (lib/notes/rich.ts sets it into its contenteditable, then reads it back with toMd).
2
+ // Every other reader of markdown draws it with React (lib/markdown, components/markdown).
3
+ import { safeUrl } from "@lib/url";
4
+
5
+ export const esc = (s: unknown) =>
6
+ String(s).replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]!);
7
+
8
+ // Enough markdown for kaizen's own files: headings, lists, fences, tables,
9
+ // inline code, bold, italic, hard line breaks. Everything is escaped first. With `tick`, a backlog item
10
+ // (`- open: …`, `- done: …`, `- rejected: …`) shows its status as a checkbox.
11
+ export function md(src, tick) {
12
+ const lines = src.split("\n"),
13
+ out = [];
14
+ let i = 0,
15
+ list = null;
16
+ const inl = (s) =>
17
+ esc(s)
18
+ .replace(/`([^`]+)`/g, "<code>$1</code>")
19
+ .replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>")
20
+ .replace(/(^|[^*])\*([^*\s<][^*<]*?)\*(?!\*)/g, "$1<i>$2</i>")
21
+ .replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (m, a, u) =>
22
+ safeUrl(u) ? `<a href="${u}" target="_blank" rel="noopener noreferrer"><img src="${u}" alt="${a}"></a>` : m,
23
+ )
24
+ .replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (m, t, u) =>
25
+ safeUrl(u) ? `<a href="${u}" target="_blank" rel="noopener noreferrer">${t}</a>` : m,
26
+ );
27
+ const endList = () => {
28
+ if (list) {
29
+ out.push(`</${list}>`);
30
+ list = null;
31
+ }
32
+ };
33
+ while (i < lines.length) {
34
+ const l = lines[i];
35
+ if (/^```/.test(l)) {
36
+ endList();
37
+ const buf = [];
38
+ i++;
39
+ while (i < lines.length && !/^```/.test(lines[i])) buf.push(lines[i++]);
40
+ out.push(`<pre>${esc(buf.join("\n"))}</pre>`);
41
+ i++;
42
+ continue;
43
+ }
44
+ const hm = /^(#{1,6})\s+(.*)$/.exec(l);
45
+ if (hm) {
46
+ endList();
47
+ out.push(`<h${Math.min(hm[1].length, 3)}>${inl(hm[2])}</h${Math.min(hm[1].length, 3)}>`);
48
+ i++;
49
+ continue;
50
+ }
51
+ if (/^---+$/.test(l.trim())) {
52
+ endList();
53
+ out.push("<hr>");
54
+ i++;
55
+ continue;
56
+ }
57
+ if (/^\|/.test(l)) {
58
+ endList();
59
+ const rows = [];
60
+ while (i < lines.length && /^\|/.test(lines[i])) rows.push(lines[i++]);
61
+ const cells = (r) =>
62
+ r
63
+ .replace(/^\||\|$/g, "")
64
+ .split("|")
65
+ .map((c) => inl(c.trim()));
66
+ out.push(
67
+ "<table>" +
68
+ rows
69
+ .filter((r) => !/^\|\s*-/.test(r))
70
+ .map(
71
+ (r, n) =>
72
+ `<tr>${cells(r)
73
+ .map((c) => (n ? `<td>${c}</td>` : `<th>${c}</th>`))
74
+ .join("")}</tr>`,
75
+ )
76
+ .join("") +
77
+ "</table>",
78
+ );
79
+ continue;
80
+ }
81
+ const li = /^\s*(?:[-*]|\d+\.)\s+(.*)$/.exec(l);
82
+ if (li) {
83
+ const t = /^\s*\d+\./.test(l) ? "ol" : "ul";
84
+ if (list !== t) {
85
+ endList();
86
+ out.push(`<${t}>`);
87
+ list = t;
88
+ }
89
+ const tk = tick && /^(open|done|rejected):\s*(.*)$/.exec(li[1]);
90
+ out.push(
91
+ tk
92
+ ? `<li class="tk${tk[1] === "rejected" ? " rej" : ""}"><label><input type="checkbox" tabindex="-1" aria-disabled="true" onclick="return false"${tk[1] === "done" ? " checked" : ""} aria-label="${tk[1]}"><span>${inl(tk[2])}</span></label></li>`
93
+ : `<li>${inl(li[1])}</li>`,
94
+ );
95
+ i++;
96
+ continue;
97
+ }
98
+ if (!l.trim()) {
99
+ endList();
100
+ i++;
101
+ continue;
102
+ }
103
+ endList();
104
+ const buf = [l];
105
+ i++;
106
+ while (i < lines.length && lines[i].trim() && !/^(#|```|\||\s*[-*]\s|\s*\d+\.\s|---)/.test(lines[i]))
107
+ buf.push(lines[i++]);
108
+ // A line ending in two spaces is a hard line break.
109
+ out.push(
110
+ `<p>${inl(buf.map((l, k) => (k < buf.length - 1 && / {2}$/.test(l) ? l.trimEnd() + "\0" : l)).join(" ")).replace(/\0 /g, "<br>")}</p>`,
111
+ );
112
+ }
113
+ endList();
114
+ return out.join("");
115
+ }
@@ -0,0 +1,32 @@
1
+ // Sending a note: the same request as the old box, POST /note with the files as data URLs.
2
+ import { host, post, toast } from "@lib/core";
3
+ import { stopDictation } from "@lib/dictation";
4
+ import { clearNoteFiles, getNotes, setNotes } from "./notes-store.ts";
5
+ import { noteBody, noteKey, type NoteCard } from "./notes.ts";
6
+
7
+ const DK = "kz-d:";
8
+ // Sends the text and the files waiting for this card. On success the box is emptied (its draft too), the board reloads, and
9
+ // the box takes focus back at the next draw. Returns whether it went.
10
+ export async function sendNote(c: NoteCard, text: string, files: File[]): Promise<boolean> {
11
+ stopDictation(true);
12
+ text = text.trim();
13
+ if (!text && !files.length) return false;
14
+ const r = await post("/note", noteBody(c, text, await host.dataUrls(files)));
15
+ if (!r.ok) return false;
16
+ const k = noteKey(c);
17
+ clearNoteFiles(k);
18
+ try {
19
+ sessionStorage.removeItem(DK + "n:" + k);
20
+ } catch {}
21
+ toast("Noted");
22
+ // Focus anywhere in the notes blocks the redraw: blur it so the note shows.
23
+ setNotes({ refocus: k });
24
+ (document.activeElement as HTMLElement | null)?.blur();
25
+ host.reload();
26
+ return true;
27
+ }
28
+ export const takeRefocus = (k: string) => {
29
+ if (getNotes().refocus !== k) return false;
30
+ setNotes({ refocus: null });
31
+ return true;
32
+ };
@@ -0,0 +1,22 @@
1
+ // The Notes tab's state: the card open, and the files picked per card. The files live here, not in the box: a redraw while
2
+ // the box is not focused (just after the file picker, say) used to rebuild it and drop them.
3
+ import { create } from "zustand";
4
+ import type { NoteCard } from "./notes.ts";
5
+
6
+ // `linked`: the notebook notes that link to this run, listed above its notes.
7
+ export type NotesView = { card: NoteCard; src: string | undefined; ro: boolean; linked?: string[] };
8
+ type Notes = {
9
+ view: NotesView | null; // a new object on every draw, even of the same notes: the box refocuses on it
10
+ files: Record<string, File[]>;
11
+ refocus: string | null; // the card whose box takes focus back at the next draw (after a send)
12
+ };
13
+ export const useNotes = create<Notes>()(() => ({ view: null, files: {}, refocus: null }));
14
+ export const getNotes = useNotes.getState;
15
+ export const setNotes = useNotes.setState;
16
+ export const addNoteFiles = (k: string, fs: File[]) =>
17
+ setNotes((s) => ({ files: { ...s.files, [k]: [...(s.files[k] ?? []), ...fs] } }));
18
+ export const clearNoteFiles = (k: string) =>
19
+ setNotes((s) => {
20
+ const { [k]: _gone, ...files } = s.files;
21
+ return { files };
22
+ });