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,293 @@
1
+ // What a person does in the run workspace, as store actions: open or close a tab, start a terminal or an agent, split, move
2
+ // and drag items between panes, the Run app button, the pane keys. Each changes the layout store (lib/run/layout-store.ts) or
3
+ // asks the server, then redraws (ws-draw.ts); the panes themselves are React (components/run).
4
+ import { ask, isPhone, post, toast, toastAction } from "@lib/core";
5
+ import { cardKey as key, getServer, load } from "@lib/server";
6
+ import { wsOfCardNow as wsOfCard } from "@lib/rail";
7
+ import { setHelp } from "@lib/shell";
8
+ import { preview } from "@lib/markdown";
9
+ import { devUrl, leaves, localPort } from "./ws-tabs.ts";
10
+ import { tabs, draw } from "./ws-draw.ts";
11
+ import type { Tab } from "./ws-derive.ts";
12
+ import { addShell, cx, edit, getWs, saved, screens, setElsewhere, setWs } from "./ws-store.ts";
13
+ import { boxesOf, detach, focusItem, focusPane, keepUrl, moveInLayout, nearestPane, patch, placeItems, rects, requestBrowse, selectScreen, setFlip, setPanel, getPanel, setRunView, setTarget, showItem, useLayout } from "./index.ts";
14
+
15
+ export const byKey = (k: string) => getServer().state.cards.find((x) => key(x) === k);
16
+
17
+ // Moves an item out of its tab into another one (split beside a pane there, or next to its
18
+ // focused pane), or into a tab of its own (to = null). Terminals keep running and frames stay loaded.
19
+ export function moveItem(id: string, to: string | null, at?: { pane: string; dir: "cols" | "rows"; before: boolean }) {
20
+ if (moveInLayout(cx().k, id, to, at)) draw();
21
+ }
22
+ export function addTab(t: Tab) {
23
+ if (!saved().tabs.some((x) => x.id === t.id)) edit((s) => ({ ...s, tabs: [...s.tabs, t] }));
24
+ // Already open somewhere: moving it into the target screen means taking it out of its old one.
25
+ else if (useLayout.getState().target) detach(cx().k, t.id);
26
+ show(t.id);
27
+ }
28
+ // Automatic opens (a run's Preview, `kaizen preview`) bring a tab forward only when it is not open yet;
29
+ // an open one just navigates, so the user can leave it.
30
+ export const autoTab = (t: Tab) => { if (!saved().tabs.some((x) => x.id === t.id)) addTab(t); };
31
+ // After an item is added: place it (which uses the split target) and show the screen holding it.
32
+ export function show(id: string) {
33
+ placeItems(cx().k, tabs().map((t) => t.id));
34
+ showItem(cx().k, id);
35
+ draw();
36
+ }
37
+ export const openNoteTab = (name: string) => addTab({ id: "note:" + name, kind: "note", title: name.slice(name.lastIndexOf("/") + 1), note: name });
38
+ export const openPreview = () => {
39
+ addTab({ id: "preview", kind: "preview", title: "Preview" });
40
+ if (isPhone()) setFlip(false); // Preview is a centre tab: the sheet would sit over it
41
+ };
42
+
43
+ // The run's recorded session, resumed in a board terminal tied to it. While it still runs in
44
+ // another terminal the server says so (409 live) and a tab explains; with no session, a shell.
45
+ export async function openAgent(c, again = false, focus = true) {
46
+ const k = key(c);
47
+ const r = await fetch("/shell", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ dir: c.state, ws: cx().ws, run: k, resume: true }) }).catch(() => null);
48
+ if (r?.ok) {
49
+ setElsewhere(k, false);
50
+ const sh = await r.json();
51
+ addShell(sh);
52
+ return focus ? show("sh:" + sh.key) : draw();
53
+ }
54
+ const j: any = r ? await r.json().catch(() => ({})) : {};
55
+ if (r?.status === 409 && j.live) {
56
+ setElsewhere(k, true);
57
+ if (again) toast("Still running in another terminal");
58
+ return draw();
59
+ }
60
+ setElsewhere(k, false);
61
+ if (again) toast(j.error || "Could not resume the session");
62
+ else draw();
63
+ }
64
+
65
+ // `yolo` only when the + menu's switch was flipped; otherwise the server applies that agent's saved setting.
66
+ export async function newPty(agent?: string, yolo?: boolean) {
67
+ const r = await fetch("/shell", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ dir: cx().dir, ws: cx().ws, run: cx().k, ...(agent ? { agent, yolo } : {}) }) });
68
+ if (r.status === 501) {
69
+ setWs({ noPty: true });
70
+ return draw();
71
+ }
72
+ if (!r.ok) {
73
+ // 429 (too many terminals), 403, anything else: say why, and keep the tab bar drawn.
74
+ let why = "";
75
+ try {
76
+ why = (await r.json()).error;
77
+ } catch {}
78
+ toast(why ? "No new terminal: " + why : "No new terminal (" + r.status + ")");
79
+ return draw();
80
+ }
81
+ const sh = await r.json();
82
+ addShell(sh);
83
+ show("sh:" + sh.key);
84
+ }
85
+
86
+ // The Run app button (play icon; the + menu's Preview is the run's Preview tab): the workspace's app in the Browser tab. A dev server already listening
87
+ // opens at once; otherwise the board starts the folder's dev script in a terminal here, waits
88
+ // for its port, then opens it. No dev script: the run's Preview (report and screenshots).
89
+ let starting = false;
90
+ export async function previewApp() {
91
+ if (!getWs().ctx || starting) return;
92
+ const c = cx();
93
+ const ports = async (): Promise<number[]> => {
94
+ try {
95
+ return await (await fetch("/devports?ws=" + encodeURIComponent(c.ws))).json();
96
+ } catch {
97
+ return [];
98
+ }
99
+ };
100
+ // The newest run here names the page to open (its ## Preview), when it has one.
101
+ const card = getServer().state.cards.filter((x) => x.state === c.dir && wsOfCard(x) === c.ws && x.id).sort((a, b) => String(b.id).localeCompare(String(a.id)))[0];
102
+ let pv = "";
103
+ try {
104
+ if (card) pv = preview((await (await fetch(`/run/${encodeURIComponent(card.id)}?dir=${encodeURIComponent(c.dir)}`)).json()).impl) ?? "";
105
+ } catch {}
106
+ const openAt = (u: string) => {
107
+ keepUrl(c.k, u);
108
+ addTab({ id: "local", kind: "local", title: "Browser" });
109
+ requestBrowse(c.k, u);
110
+ // Which port it is, and a way to close it.
111
+ const at = localPort(u);
112
+ if (at) toastAction(`Opened localhost:${at}`, "Stop server", () => void stopServer(at));
113
+ };
114
+ const now = await ports();
115
+ if (now.length) return openAt(devUrl(pv, now)!);
116
+ const u = devUrl(pv, []);
117
+ const r = await fetch("/shell", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ dir: c.dir, ws: c.ws, run: c.k, dev: true }) }).catch(() => null);
118
+ if (!r?.ok) {
119
+ let why = "";
120
+ try {
121
+ why = (await r!.json()).error;
122
+ } catch {}
123
+ toast(why ? `Preview: ${why}` : "Preview: the dev server did not start");
124
+ return openPreview();
125
+ }
126
+ const sh = await r.json();
127
+ addShell(sh);
128
+ draw();
129
+ starting = true;
130
+ toast("Starting the app…");
131
+ let handled = false,
132
+ retry = false;
133
+ try {
134
+ // Up to a minute for the first port; Linux only reads ports, elsewhere the run's address after a pause.
135
+ for (let i = 0; i < 40 && getWs().ctx?.k === c.k; i++) {
136
+ await new Promise((ok) => setTimeout(ok, 1500));
137
+ const p = await ports();
138
+ if (p.length) return openAt(devUrl(pv, p)!);
139
+ // The dev server's terminal says its port is taken: ask whether to stop what holds it, then start again.
140
+ const cf = await portConflict(sh.key);
141
+ if (cf) {
142
+ handled = true;
143
+ retry = await askStopPort(cf);
144
+ break;
145
+ }
146
+ if (i === 5 && u && !navigator.platform.startsWith("Linux")) return openAt(u);
147
+ }
148
+ if (!handled && getWs().ctx?.k === c.k) toast("The app did not open a port. Its terminal tab shows why.");
149
+ } finally {
150
+ starting = false;
151
+ }
152
+ if (retry) return previewApp();
153
+ }
154
+
155
+ // "Stop server" on the toast: the board stops what listens on that port (a process of this user, never the board itself).
156
+ async function stopServer(port: number) {
157
+ try {
158
+ const r = await fetch("/port/stop", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ port }) });
159
+ if (r.ok) return toast(`Stopped localhost:${port}`);
160
+ toast(`Could not stop localhost:${port}: ${((await r.json()) as { error?: string }).error ?? "unknown error"}`);
161
+ } catch {
162
+ toast(`Could not stop localhost:${port}: the board did not answer`);
163
+ }
164
+ }
165
+
166
+ type Conflict = { port: number; board?: boolean; holders: { pid: number; name: string; cmd: string; cwd: string }[] };
167
+ async function portConflict(key: string): Promise<Conflict | null> {
168
+ try {
169
+ const r = (await (await fetch("/shell/conflict?key=" + encodeURIComponent(key))).json()) as Partial<Conflict>;
170
+ return r.port ? (r as Conflict) : null;
171
+ } catch {
172
+ return null;
173
+ }
174
+ }
175
+ // "Port 3000 is already in use": who holds it, and the choice to stop it. True when it was stopped (the caller starts again).
176
+ async function askStopPort(cf: Conflict): Promise<boolean> {
177
+ const who = cf.holders.map((h) => `${h.name || "a process"} (pid ${h.pid})${h.cwd ? ` in ${h.cwd}` : ""}`).join(", ");
178
+ if (cf.board) return toast(`Port ${cf.port} is this board's own: the app needs another port.`), false;
179
+ const yes = await ask({
180
+ title: `Port ${cf.port} is already in use`,
181
+ description: who ? `${who} is using it. Stop it so the app can start on this port?` : "Something is using it. Stop it so the app can start on this port?",
182
+ confirmLabel: "Stop it and run the app",
183
+ danger: true,
184
+ });
185
+ if (!yes) return false;
186
+ try {
187
+ const r = await fetch("/port/stop", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ port: cf.port }) });
188
+ if (r.ok) return true;
189
+ toast(`Could not stop it: ${((await r.json()) as { error?: string }).error ?? "unknown error"}`);
190
+ } catch {
191
+ toast("Could not stop it: the board did not answer");
192
+ }
193
+ return false;
194
+ }
195
+
196
+ export async function closeTab(id: string) {
197
+ const wk = cx().k;
198
+ if (id.startsWith("sh:")) {
199
+ await post("/pty/exit", { key: id.slice(3) });
200
+ setWs((s) => ({ shells: s.shells.filter((x) => "sh:" + x.key !== id) }));
201
+ } else if (id.startsWith("agent:")) {
202
+ // Closing the tab ends the agent, so the sidebar stops listing it; one mid-turn asks first.
203
+ const k = id.slice(6),
204
+ a = getServer().state.agents?.find((x) => x.key === k);
205
+ if (a?.busy && !(await ask({ title: "This agent is still working. End it?", confirmLabel: "End", danger: true }))) return;
206
+ patch(wk, (s) => ({ ...s, hidden: [...s.hidden, id], hb: { ...s.hb, [id]: a?.born ?? 0 } }));
207
+ await post("/pty/exit", { key: k });
208
+ load(true);
209
+ }
210
+ else if (id.startsWith("wait:")) setElsewhere(id.slice(5), false);
211
+ else patch(wk, (s) => ({ ...s, tabs: s.tabs.filter((t) => t.id !== id) }));
212
+ if (getWs().ctx?.k === wk) draw();
213
+ }
214
+ // A tab's ×: everything in it closes (shells end, the agent is only hidden).
215
+ export async function closeScreen(sid: string) {
216
+ const sc = saved().screens.find((x) => x.id === sid);
217
+ for (const id of sc ? leaves(sc.tree) : []) await closeTab(id);
218
+ }
219
+
220
+ // + makes a new tab; split right/down adds to the tab shown. `n` is a menu item's data-n.
221
+ export function openNew(n: string, mode: string, yolo?: boolean) {
222
+ const s = saved();
223
+ setTarget(mode === "tab" || !s.on ? null : { screen: s.on, dir: mode as "cols" | "rows" });
224
+ if (n === "shell") void newPty();
225
+ else if (n.startsWith("agent:")) void newPty(n.slice(6), yolo);
226
+ else if (n === "local") addTab({ id: "local", kind: "local", title: "Browser" });
227
+ else if (n === "history") addTab({ id: "history", kind: "history", title: "History" });
228
+ else openPreview();
229
+ }
230
+ // Ctrl+Space r / d: a second terminal like the focused one (same agent, or a shell), split right or down.
231
+ // Anything else (Browser, Preview, notes) has no copy to make, so the menu opens to pick from.
232
+ function likeFocused(): string | null {
233
+ const sc = screens().find((x) => x.id === saved().on),
234
+ t = sc && tabs().find((x) => x.id === sc.focus),
235
+ w = getWs();
236
+ if (t?.kind === "shell") return "shell";
237
+ if (t?.kind === "agent") return "agent:" + (t.agent ?? (w.defAgent || w.agents[0]?.cmd || ""));
238
+ return null;
239
+ }
240
+
241
+ // The strip's Project notes: the project's notes as a tree in the panel (components/run/project-notes.tsx); a note opens as a centre tab.
242
+ export async function projectNotes() {
243
+ const pn = !getPanel().pn;
244
+ setPanel({ pn });
245
+ if (!pn) return;
246
+ setRunView({ notes: { loading: true } });
247
+ try {
248
+ const d = await (await fetch("/vault?dir=" + encodeURIComponent(cx().dir))).json();
249
+ setRunView({ notes: { names: (d.notes ?? []).map((n) => n.name).sort() } });
250
+ } catch {
251
+ setRunView({ notes: { failed: true } });
252
+ }
253
+ }
254
+
255
+ // The keyboard, tmux style: Ctrl+Space puts focus in the current pane, then one more key
256
+ // moves it: arrows or hjkl between panes, 1-9, n, p between tabs.
257
+ const setPane = (id: string) => {
258
+ focusItem(cx().k, id);
259
+ draw();
260
+ focusPane(id);
261
+ };
262
+ const DIRS = { ArrowLeft: "l", h: "l", ArrowRight: "r", l: "r", ArrowUp: "u", k: "u", ArrowDown: "d", j: "d" } as const;
263
+ export function paneKey(k: string) {
264
+ if (k === "?") {
265
+ (document.activeElement as HTMLElement)?.blur(); // Escape closes it only from outside the terminal
266
+ return void setHelp(true);
267
+ }
268
+ if (k === "x") {
269
+ const sc = screens().find((x) => x.id === saved().on);
270
+ if (sc) void closeTab(sc.focus).then(() => focusPane(screens().find((x) => x.id === saved().on)?.focus));
271
+ return;
272
+ }
273
+ const mode = { c: "tab", r: "cols", d: "rows" }[k];
274
+ const same = mode && mode !== "tab" && getWs().noPty === false ? likeFocused() : null;
275
+ if (same) return void openNew(same, mode!);
276
+ if (mode) return void setRunView({ menu: mode as "tab" | "cols" | "rows" });
277
+ const s = saved(),
278
+ scs = screens(),
279
+ at = scs.findIndex((x) => x.id === s.on),
280
+ sc = scs[at];
281
+ if (!sc) return;
282
+ if (DIRS[k]) {
283
+ const to = nearestPane(boxesOf(rects(sc.tree).panes), sc.focus, DIRS[k]);
284
+ if (to) setPane(to);
285
+ return;
286
+ }
287
+ const i = k === "n" ? (at + 1) % scs.length : k === "p" ? (at - 1 + scs.length) % scs.length : /^[1-9]$/.test(k) ? +k - 1 : -1;
288
+ const to = scs[i];
289
+ if (!to) return;
290
+ selectScreen(cx().k, to.id);
291
+ draw();
292
+ focusPane(to.focus);
293
+ }
@@ -0,0 +1,50 @@
1
+ // The tabs a workspace has, derived from what the server lists and what the layout saved. No DOM, no store, tested alone
2
+ // (ws-derive.test.ts): workspace.ts reads the stores and hands them in.
3
+ import { liveIn, stageTabs } from "./ws-tabs.ts";
4
+ import type { Saved, SavedTab } from "./layout-store.ts";
5
+
6
+ export type Tab = SavedTab & { kind: "agent" | "shell" | "local" | "preview" | "note" | "wait" | "history" };
7
+ export const AGENTS = ["claude", "codex", "gemini", "agy", "opencode", "cursor"];
8
+ export type DeriveIn = {
9
+ ctx: { dir: string; ws: string; k: string };
10
+ cards: any[];
11
+ shells: { key: string; run: string; title: string; agent?: string }[];
12
+ agents: { name: string; cmd: string }[]; // every agent installed for the project (/agents)
13
+ serverAgents: any[]; // the sessions the board lists (state.agents)
14
+ elsewhere: ReadonlySet<string>; // runs whose own session is open in another terminal
15
+ saved: Saved;
16
+ wsOfCard: (c: any) => string;
17
+ key: (c: any) => string;
18
+ };
19
+ // `revive`: closed agent tabs that come back. A tab closed stays hidden only for that agent: one started again under the
20
+ // same key (a resume) is a new agent (`born` differs) and the sidebar lists it, so its tab returns (the caller saves it).
21
+ export function deriveTabs(i: DeriveIn): { tabs: Tab[]; revive: string[] } {
22
+ const { ctx, cards, shells, agents, key } = i,
23
+ out: Tab[] = [],
24
+ named = (a?: string) => agents.find((x) => x.cmd === a)?.name ?? "Agent",
25
+ live = liveIn(cards, ctx.dir, ctx.ws, i.wsOfCard),
26
+ liveKeys = new Set(live.map(key)),
27
+ mineCards = cards.filter((c) => c.state === ctx.dir && i.wsOfCard(c) === ctx.ws),
28
+ // A finished run's agent that is still open keeps its tab, as the sidebar keeps it.
29
+ open = mineCards.filter((c) => !liveKeys.has(key(c)) && c.pty?.alive),
30
+ sh = (x: (typeof shells)[number]): Tab => ({ id: "sh:" + x.key, kind: x.agent ? "agent" : "shell", agent: x.agent || undefined, title: x.title, key: x.key });
31
+ // Each live run's terminals: its stage terminals ("Build · Claude"), other sessions, shells, the waiting note.
32
+ for (const c of [...live, ...open]) {
33
+ const k = key(c),
34
+ runAgent = AGENTS.find((a) => a === c.pty?.agent) ?? AGENTS.find((a) => c.tags?.includes(a)) ?? undefined;
35
+ for (const t of stageTabs(c, named(runAgent))) out.push({ id: "agent:" + t.key, kind: "agent", agent: runAgent, title: t.title, key: t.key });
36
+ for (const x of shells.filter((x) => x.run === k)) out.push(sh(x));
37
+ // The run's own session is running in another terminal: a tab that says so.
38
+ if (i.elsewhere.has(k)) out.push({ id: "wait:" + k, kind: "wait", agent: "claude", title: named("claude") });
39
+ }
40
+ // The workspace's own shells and agents, and those of its finished runs.
41
+ const owned = new Set(mineCards.map(key));
42
+ for (const x of shells.filter((x) => x.run === ctx.k || (owned.has(x.run) && !liveKeys.has(x.run)))) out.push(sh(x));
43
+ const hb = i.saved.hb,
44
+ revive = i.serverAgents.map((a) => "agent:" + a.key).filter((id, n) => hb && id in hb && hb[id] !== (i.serverAgents[n].born ?? 0)),
45
+ hidden = i.saved.hidden.filter((h) => !revive.includes(h)),
46
+ // Opened by hand: History, localhost, Preview, notes. "local" was saved before the rename to Browser.
47
+ mine = i.saved.tabs.map((t) => (t.kind === "local" ? { ...t, title: "Browser" } : t)) as Tab[],
48
+ all = [...out.filter((t) => !hidden.includes(t.id)), ...mine];
49
+ return { tabs: all.filter((t, n) => all.findIndex((x) => x.id === t.id) === n), revive };
50
+ }
@@ -0,0 +1,102 @@
1
+ // The redraw of the run workspace: which tabs it has now (ws-derive.ts over the server and layout stores), what the tab bar,
2
+ // the panes and the panel's picker are handed (run-view-store), and the pick of the run the panel shows. Called after every
3
+ // change of the tabs, a layout or the server's cards.
4
+ import { age } from "@lib/core";
5
+ import { cardState as stateOf, titleOf, wsOfCardNow as wsOfCard } from "@lib/rail";
6
+ import { cardKey as key, getServer } from "@lib/server";
7
+ import { openPanel } from "./panel-actions.ts";
8
+ import { deriveTabs, type Tab } from "./ws-derive.ts";
9
+ import { awaiting, chosen, dueWord, gitDue, historyOf, leaves, liveIn, newRun, pickable } from "./ws-tabs.ts";
10
+ import { evict, touch } from "./kept.ts";
11
+ import { getWs, cx, edit, saved, setWs } from "./ws-store.ts";
12
+ import { placeItems, setPanel, getPanel, setRunView } from "./index.ts";
13
+
14
+ export const wsCards = () => (getWs().ctx ? liveIn(getServer().state.cards, cx().dir, cx().ws, wsOfCard) : []);
15
+ export const mineNow = () => getServer().state.cards.filter((c) => c.state === cx().dir && wsOfCard(c) === cx().ws);
16
+ export function tabs(): Tab[] {
17
+ const w = getWs(),
18
+ { tabs: out, revive } = deriveTabs({
19
+ ctx: cx(), cards: getServer().state.cards, shells: w.shells, agents: w.agents, serverAgents: getServer().state.agents ?? [],
20
+ elsewhere: new Set(w.elsewhere), saved: saved(), wsOfCard, key,
21
+ });
22
+ if (revive.length) edit((s) => ({ ...s, hidden: s.hidden.filter((h) => !revive.includes(h)), hb: Object.fromEntries(Object.entries(s.hb ?? {}).filter(([x]) => !revive.includes(x))) }));
23
+ return out;
24
+ }
25
+
26
+ // The run panel (#panel) stays docked on the right of the centre and shows one run: the one picked
27
+ // in its header (run-pick.ts), first the run waiting on you, else the newest. A pick is sticky; a
28
+ // run that starts waiting later does not replace it: the picker's trigger and, with the panel
29
+ // collapsed, the panel button show a dot. Only a run created during the visit takes the pick
30
+ // (followNew). With no run the panel is parked.
31
+ export const picked = new Map<string, string>();
32
+ // Every card seen in the workspace this visit. It only grows, so a restored run or a /state tick
33
+ // missing cards never reads as new.
34
+ export const seenRuns = new Map<string, Set<string>>();
35
+ export function followNew() {
36
+ const seen = getWs().ctx && seenRuns.get(cx().k);
37
+ if (!seen) return;
38
+ const c = newRun(pickable(getServer().state.cards, cx().dir, cx().ws, wsOfCard), seen, key);
39
+ for (const m of mineNow()) seen.add(key(m));
40
+ if (c) picked.set(cx().k, key(c));
41
+ }
42
+ // Shows a run in the panel (a picker row, a History row); the centre stays as it is.
43
+ export const pickRun = (k: string) => (picked.set(cx().k, k), draw());
44
+
45
+ export function draw() {
46
+ const ts = tabs(),
47
+ ctx = cx();
48
+ // Every item sits in exactly one screen: new ones are placed, closed ones leave.
49
+ placeItems(ctx.k, ts.map((t) => t.id));
50
+ const s = saved(),
51
+ scs = s.screens,
52
+ cur = scs.find((sc) => sc.id === s.on);
53
+ const item = (id: string) => ts.find((t) => t.id === id)!;
54
+ // The chrome and the panes are React (components/run): they are handed what to show, never an element. A pane is
55
+ // made once per item and kept (hidden while its screen is not shown), so terminals never reconnect.
56
+ const now = Date.now(),
57
+ w = getWs();
58
+ setRunView({
59
+ message: null,
60
+ screens: scs.map((sc) => {
61
+ const ids = leaves(sc.tree),
62
+ { id, kind, title, agent } = item(ids[0]);
63
+ return { id: sc.id, ids, focus: sc.focus, title: ids.map((x) => item(x).title).join(" + "), first: { id, kind, title, agent } };
64
+ }),
65
+ on: s.on,
66
+ split: !!cur,
67
+ agents: w.agents,
68
+ defAgent: w.defAgent,
69
+ pty: !w.noPty,
70
+ titles: Object.fromEntries(ts.map((t) => [t.id, t.title])),
71
+ items: ts,
72
+ wsk: ctx.k,
73
+ ws: ctx,
74
+ history: historyOf(getServer().state.cards, ctx.dir, ctx.ws, wsOfCard).map((c) => ({ k: key(c), title: titleOf(c), state: stateOf(c), line: `${c.status} · ${age(c.moved ?? now, now)} ago` })),
75
+ empty: !scs.length,
76
+ });
77
+ // Every pane stays mounted when the workspace is left, up to the cap (kept.ts): this one is the most recent.
78
+ setRunView((v) => {
79
+ const recent = touch(v.recent, ctx.k).slice(-32);
80
+ return { recent, kept: evict({ ...v.kept, [ctx.k]: { items: ts, ws: ctx } }, recent, ctx.k) };
81
+ });
82
+ mountPanel();
83
+ }
84
+
85
+ export function mountPanel() {
86
+ const ctx = cx(),
87
+ live = pickable(getServer().state.cards, ctx.dir, ctx.ws, wsOfCard),
88
+ hist = historyOf(getServer().state.cards, ctx.dir, ctx.ws, wsOfCard),
89
+ c = chosen(live, hist, picked.get(ctx.k), key);
90
+ setPanel({ parked: !c });
91
+ // Collapsed (a phone: sheet down) and a run waits: a dot on the panel button, no pop-open.
92
+ setRunView({ awaiting: live.some(awaiting) });
93
+ if (!c) return void (setWs({ card: null }), setRunView({ picker: null }));
94
+ picked.set(ctx.k, key(c));
95
+ setPanel({ ro: hist.includes(c) }); // a run from History: no edit buttons (the commit and push ones stay)
96
+ setWs({ card: c });
97
+ // The picker is React (components/run/run-picker.tsx): the run shown, a dot when another needs you, the runs, then History.
98
+ const now = Date.now(),
99
+ row = (r) => ({ k: key(r), title: titleOf(r), state: stateOf(r), line: `${gitDue(r) ? `waiting on you · ${dueWord(r)}` : awaiting(r) ? "needs you" : r.status} · ${age(r.moved ?? now, now)}` });
100
+ setRunView({ picker: { cur: row(c), live: live.map(row), hist: hist.map(row), other: live.some((r) => r !== c && awaiting(r)) } });
101
+ if (getPanel().openKey !== key(c)) openPanel(c);
102
+ }
@@ -0,0 +1,21 @@
1
+ // What the run workspace knows about the one it shows: which workspace (`ctx`), the card whose panel is up, the shells and
2
+ // agents it read from the server, whether the server can start terminals, and the runs whose own session is open in another
3
+ // terminal, and the terminal the sidebar asked for (`selectTerm`). A store, so the actions (ws-actions.ts), the redraw (ws-draw.ts) and the lifecycle (workspace.ts) read one
4
+ // place instead of sharing module variables.
5
+ import { create } from "zustand";
6
+ import { layoutOf, patch, type Saved } from "./layout-store.ts";
7
+ import type { RvAgent } from "./run-view-store.ts";
8
+
9
+ export type WsCtx = { dir: string; ws: string; k: string };
10
+ export type WsShell = { key: string; run: string; title: string; agent?: string };
11
+ type Ws = { ctx: WsCtx | null; card: any; shells: WsShell[]; agents: RvAgent[]; defAgent: string; noPty: boolean; elsewhere: string[]; selectTerm: string | null };
12
+ export const useWs = create<Ws>()(() => ({ ctx: null, card: null, shells: [], agents: [], defAgent: "", noPty: false, elsewhere: [], selectTerm: null }));
13
+ export const getWs = useWs.getState;
14
+ export const setWs = useWs.setState;
15
+ export const cx = () => getWs().ctx!;
16
+ // The shown workspace's saved layout, and a change to it.
17
+ export const saved = (): Saved => layoutOf(cx().k);
18
+ export const edit = (fn: (s: Saved) => Saved) => patch(cx().k, fn);
19
+ export const screens = () => saved().screens;
20
+ export const addShell = (sh: WsShell) => setWs((s) => (s.shells.some((x) => x.key === sh.key) ? s : { shells: [...s.shells, sh] }));
21
+ export const setElsewhere = (k: string, on: boolean) => setWs((s) => ({ elsewhere: on ? [...new Set([...s.elsewhere, k])] : s.elsewhere.filter((x) => x !== k) }));
@@ -0,0 +1,125 @@
1
+ // The workspace centre's logic without the DOM, so it is tested alone (ws-tabs.test.ts):
2
+ // which runs the panel's picker lists, which are History, how stage terminals are named, and
3
+ // how the old per-run tab layouts move to their workspace.
4
+ // A screen's layout is a tmux-style tree (lib/run/layout.ts, no DOM there); re-exported so the board code and its
5
+ // tests keep their imports.
6
+ import { gitDue } from "../rail/rules.ts";
7
+ import { loopbackUrl } from "./preview.ts";
8
+ export { loopbackUrl, previewIn, previewOpens } from "./preview.ts";
9
+ import { leaves, prune, wsKey, type Node } from "./layout.ts";
10
+ export { leaves, nearestPane, prune, wsKey, type Box, type Node } from "./layout.ts";
11
+
12
+ // A run that is over: abandoned, or done and neither waiting on an approval nor on its commit. It is History.
13
+ export const finished = (c) => c.kind === "run" && (c.status === "abandoned" || (c.status === "done" && c.accept !== "needs" && !gitDue(c)));
14
+ const here = (c, dir: string, ws: string, wsOfCard) => c.state === dir && wsOfCard(c) === ws;
15
+ // The cards whose agent terminals get tabs in a workspace: runs not over, and tasks whose agent is open.
16
+ export const liveIn = (cards: any[], dir: string, ws: string, wsOfCard) =>
17
+ cards.filter((c) => !c.archived && here(c, dir, ws, wsOfCard) && (c.kind === "idea" ? !!c.pty : c.kind === "run" && !finished(c)));
18
+ // History: the workspace's finished runs, newest first.
19
+ export const historyOf = (cards: any[], dir: string, ws: string, wsOfCard) =>
20
+ cards.filter((c) => finished(c) && here(c, dir, ws, wsOfCard)).sort((a, b) => (b.moved ?? 0) - (a.moved ?? 0));
21
+
22
+ type Saved = { tabs: any[]; hidden: string[]; screens: { id: string; tree: Node; focus: string }[]; on: string | null };
23
+ // Moves each card's old saved layout (keyed by the card) to its workspace's key. A key no
24
+ // card on the board owns is left as it is. Returns whether anything moved.
25
+ export function migrate(all: Record<string, Saved>, cards: any[], keyOf: (c) => string, wsOfCard): boolean {
26
+ let moved = false;
27
+ for (const c of cards) {
28
+ const old = keyOf(c),
29
+ from = all[old];
30
+ if (!from) continue;
31
+ const to = (all[wsKey(c.state, wsOfCard(c))] ||= { tabs: [], hidden: [], screens: [], on: null });
32
+ const placed = new Set(to.screens.flatMap((s) => leaves(s.tree)));
33
+ for (const t of from.tabs ?? []) if (!to.tabs.some((x) => x.id === t.id)) to.tabs.push(t);
34
+ for (const h of from.hidden ?? []) if (!to.hidden.includes(h)) to.hidden.push(h);
35
+ // An item sits in one screen only: a leaf the workspace already shows is dropped here.
36
+ for (const s of from.screens ?? []) {
37
+ const tree = s.tree && prune(s.tree, (id) => !placed.has(id));
38
+ if (!tree) continue;
39
+ leaves(tree).forEach((id) => placed.add(id));
40
+ to.screens.push({ ...s, tree, focus: leaves(tree).includes(s.focus) ? s.focus : leaves(tree)[0] });
41
+ }
42
+ to.on ??= from.on;
43
+ delete all[old];
44
+ moved = true;
45
+ }
46
+ return moved;
47
+ }
48
+
49
+ // A run that waits on the user (an approval, a question, a done run to accept).
50
+ export const awaiting = (c) => c.kind === "run" && (c.status === "waiting" || (c.status === "done" && c.accept === "needs") || gitDue(c) || !!(c.pty?.alive && c.pty.asking));
51
+ // The panel's picker: the workspace's runs not over (waiting on you first, then the newest), as the
52
+ // sidebar count shows them.
53
+ export const pickable = (cards: any[], dir: string, ws: string, wsOfCard) =>
54
+ liveIn(cards, dir, ws, wsOfCard)
55
+ .filter((c) => c.kind === "run")
56
+ .sort((a, b) => +awaiting(b) - +awaiting(a) || (b.moved ?? 0) - (a.moved ?? 0));
57
+ // The run the panel shows: the one picked while it is still pickable or History, else the first
58
+ // waiting/newest, else none.
59
+ export const chosen = (live: any[], hist: any[], picked?: string | null, keyOf: (c) => string = (c) => c.id) =>
60
+ [...live, ...hist].find((c) => keyOf(c) === picked) ?? live[0] ?? null;
61
+ // A run the picker lists that this visit has not seen yet: it was just created.
62
+ export const newRun = (live: any[], seen: Set<string>, keyOf: (c) => string = (c) => c.id) => live.find((c) => !seen.has(keyOf(c)));
63
+
64
+ // The terminal the board launched for each stage of a run: plan/impl/review sub-tab -> pty key.
65
+ // plan, impl and review are recorded when the board launches them (the task's agent once its run
66
+ // exists, /decide, /fix). A plan that was not recorded falls back to the session no stage claims,
67
+ // and only until a later stage has been launched.
68
+ export function stageKeys(c): Record<string, string> {
69
+ if (c?.kind !== "run") return {};
70
+ const all: string[] = c?.pty?.all ?? [],
71
+ st = c?.pty?.stages ?? {},
72
+ out: Record<string, string> = {};
73
+ for (const s of ["explore", "impl", "review"]) if (st[s] && all.includes(st[s])) out[s] = st[s];
74
+ if (st.plan && all.includes(st.plan)) out.plan = st.plan;
75
+ // Fallback for a terminal the board did not record (a run it did not start): the lone unclaimed agent
76
+ // is named by the run's current stage (column 1 plan, 2 build, 3 review); at any other point it stays plain.
77
+ const first = all.find((k) => !Object.values(st).includes(k)),
78
+ now = c.stage === "explore" ? "explore" : { 1: "plan", 2: "impl", 3: "review" }[c.column as number];
79
+ if (first && now && !Object.keys(st).length) out[now] = first;
80
+ return out;
81
+ }
82
+
83
+ // A run's terminals as centre tabs: those a stage claimed are named "Plan · Claude", "Build · Claude",
84
+ // "Review · Claude"; the rest keep the agent's name, numbered when there are several.
85
+ export function stageTabs(c, agent: string): { key: string; title: string }[] {
86
+ const word = { explore: "Explore", plan: "Plan", impl: "Build", review: "Review" },
87
+ all: string[] = c?.pty ? c.pty.all ?? [c.pty.key] : [],
88
+ by = new Map(Object.entries(stageKeys(c)).map(([s, k]) => [k, word[s]])),
89
+ free = all.filter((k) => !by.has(k)),
90
+ now = c?.stage === "explore" ? "Explore" : word[{ 1: "plan", 2: "impl", 3: "review" }[c?.column as number] ?? ""],
91
+ last = all.at(-1);
92
+ // One terminal can carry several stages: the newest staged one is named for where the run is now.
93
+ if (now && last && by.has(last)) by.set(last, now);
94
+ return all.map((key) => ({ key, title: by.has(key) ? `${by.get(key)} · ${agent}` : agent + (free.length > 1 ? " " + (free.indexOf(key) + 1) : "") }));
95
+ }
96
+
97
+ // A run at review or done: its localhost Preview may open the Browser.
98
+ export const reviewing = (c) => c.kind === "run" && (c.column === 3 || c.status === "done");
99
+ // The address the Browser opens for a run: the Preview's first localhost address on a port the
100
+ // workspace's own processes listen on (`ports`, from /devports), else the first such port, else
101
+ // the Preview's first address. Another project on the Preview's port never wins.
102
+ // ponytail: with no Preview match the lowest port wins, which may be an asset server (Vite) over the app.
103
+ export function devUrl(pv: string | null | undefined, ports: number[]): string | undefined {
104
+ const all = pv ? [...pv.matchAll(/https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?[^\s)`'"<>]*/g)].map((m) => m[0]) : [];
105
+ const portOf = (u: string) => Number(new URL(u).port || 80);
106
+ return all.find((u) => ports.includes(portOf(u))) ?? (ports.length ? `http://localhost:${ports[0]}` : all[0]);
107
+ }
108
+ // Runs that moved into review or done since the last tick (`was` = the keys reviewing then) and have not
109
+ // yet opened the Browser: once per run id (`seen`).
110
+ export const toOpen = (cards: any[], was: Set<string>, seen: string[], keyOf: (c) => string) => cards.filter((c) => reviewing(c) && !was.has(keyOf(c)) && !seen.includes(keyOf(c)));
111
+
112
+
113
+ // The sidebar card's agents, the project drag's moveTo and gitDue moved to lib/rail (no DOM there); re-exported so the run view and its tests keep their imports.
114
+ export * from "@lib/rail/agents.ts";
115
+ export { moveTo, gitDue, dueWord } from "@lib/rail/rules.ts";
116
+ export { branchSlug } from "@lib/project/branch.ts";
117
+ // The port of a loopback address (localhost, 127.0.0.1, [::1]), or null for anything else.
118
+ export function localPort(u: string): number | null {
119
+ try {
120
+ const x = new URL(u);
121
+ return /^(localhost|127\.0\.0\.1|\[::1\])$/.test(x.hostname) && x.port ? Number(x.port) : null;
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./search-match.ts";
2
+ export * from "./search.ts";
3
+ export * from "./use-search-rows.ts";
@@ -0,0 +1,48 @@
1
+ // The search palette's matcher, apart from the page so a test can load it.
2
+ export type Item = {
3
+ group: string;
4
+ title: string;
5
+ sub?: string;
6
+ when?: string;
7
+ hay: string;
8
+ at?: number;
9
+ dot?: string;
10
+ ico: string;
11
+ page?: boolean; // a page of the app (the empty box lists these when it has little else)
12
+ act: () => void;
13
+ };
14
+
15
+ // One edit away: a letter missing, extra, wrong, or two swapped ("tsaks" for "tasks").
16
+ export function near(a: string, b: string): boolean {
17
+ if (a === b) return true;
18
+ if (Math.abs(a.length - b.length) > 1) return false;
19
+ let i = 0;
20
+ while (i < a.length && i < b.length && a[i] === b[i]) i++;
21
+ if (a.length === b.length) {
22
+ if (a.slice(i + 1) === b.slice(i + 1)) return true; // one letter wrong
23
+ return a[i] === b[i + 1] && a[i + 1] === b[i] && a.slice(i + 2) === b.slice(i + 2); // two swapped
24
+ }
25
+ const [s, l] = a.length < b.length ? [a, b] : [b, a];
26
+ return s.slice(i) === l.slice(i + 1); // one letter extra
27
+ }
28
+
29
+ // Whether `w` is in the text: as typed, or (from 4 letters) one typo away from a word of it.
30
+ const has = (text: string, w: string) => text.includes(w) || (w.length >= 4 && text.split(/[^\p{L}\p{N}]+/u).some((t) => near(w, t.slice(0, w.length)) || near(w, t)));
31
+
32
+ // Every word of the query in the item (a typo allowed in the longer words). Ranked: the title is the query, starts with it, has a
33
+ // word that starts with it, holds it, else the rest; then what waits on you, then recency.
34
+ export function match(list: Item[], q: string): Item[] {
35
+ const words = q.toLowerCase().split(/\s+/).filter(Boolean);
36
+ if (!words.length) return list;
37
+ const lq = q.trim().toLowerCase();
38
+ const score = (i: Item) => {
39
+ const t = i.title.toLowerCase();
40
+ return t === lq ? 0 : t.startsWith(lq) ? 1 : t.split(/[^\p{L}\p{N}]+/u).some((x) => x.startsWith(lq)) ? 2 : t.includes(lq) ? 3 : 4;
41
+ };
42
+ return list
43
+ .filter((i) => {
44
+ const h = (i.title + " " + (i.sub ?? "") + " " + i.hay).toLowerCase();
45
+ return words.every((w) => has(h, w));
46
+ })
47
+ .sort((a, b) => score(a) - score(b) || +(b.dot === "wait") - +(a.dot === "wait") || (b.at ?? 0) - (a.at ?? 0));
48
+ }