rvlib-shipkit 2.29.0 → 2.30.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 (512) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/package.json +2 -1
  3. package/src/advisors/app-graph.ts +1 -1
  4. package/src/advisors/expose.ts +5 -1
  5. package/src/advisors/r2.ts +7 -9
  6. package/src/advisors/routes.ts +29 -2
  7. package/src/advisors/scan.ts +11 -0
  8. package/src/agent-time/accounts-usage.ts +8 -0
  9. package/src/agent-time/claude-sessions.ts +32 -0
  10. package/src/agent-time/hooks.ts +1 -1
  11. package/src/agent-time/live.ts +5 -2
  12. package/src/agent-time/registry.ts +186 -89
  13. package/src/agent-time/store.ts +6 -4
  14. package/src/asks/ask-doc.ts +2 -2
  15. package/src/asks/ask-store.ts +22 -7
  16. package/src/check.ts +9 -1
  17. package/src/checks/SK001-package-json-shape.check.ts +1 -0
  18. package/src/checks/SK003-claude-md-shape.check.ts +1 -0
  19. package/src/checks/SK004-gitignore-policy.check.ts +12 -6
  20. package/src/checks/SK008-reviewer-agent.check.ts +4 -7
  21. package/src/checks/SK013-one-way-in-policy.check.ts +1 -0
  22. package/src/checks/SK017-vscode-hub-task.check.ts +1 -0
  23. package/src/checks/SK024-identity-colors.check.ts +1 -1
  24. package/src/checks/SK027-agent-wiki-links.check.ts +2 -1
  25. package/src/checks/SK033-global-contribution.check.ts +1 -0
  26. package/src/checks/SK034-commit-gates-armed.check.ts +1 -0
  27. package/src/checks/SK039-vscode-watch-generated.check.ts +1 -0
  28. package/src/checks/SK049-thread-answers-hook.check.ts +9 -5
  29. package/src/checks/SK050-retired-commands.check.ts +1 -0
  30. package/src/checks/SK051-no-formatter.check.ts +1 -0
  31. package/src/cli/channel-run.ts +17 -0
  32. package/src/cli/cmd_Advisors.ts +28 -7
  33. package/src/cli/cmd_Asks.ts +2 -2
  34. package/src/cli/cmd_Backup.ts +5 -1
  35. package/src/cli/cmd_CacheAudit.ts +1 -1
  36. package/src/cli/cmd_Channel.ts +43 -0
  37. package/src/cli/cmd_GlobalProcesses.ts +1 -0
  38. package/src/cli/cmd_Home.ts +12 -5
  39. package/src/cli/cmd_Hooks.ts +1 -1
  40. package/src/cli/cmd_Hq.ts +43 -0
  41. package/src/cli/cmd_Lanes.ts +15 -3
  42. package/src/cli/cmd_Media.ts +8 -3
  43. package/src/cli/cmd_Orchestrator.ts +253 -84
  44. package/src/cli/cmd_OrchestratorRole.ts +163 -0
  45. package/src/cli/cmd_Review.ts +142 -165
  46. package/src/cli/cmd_Secret.ts +44 -14
  47. package/src/cli/cmd_Shot.ts +2 -4
  48. package/src/cli/cmd_Sound.ts +1 -0
  49. package/src/cli/cmd_Urls.ts +3 -3
  50. package/src/cli/inbox-hook-run.ts +109 -0
  51. package/src/cli/registry.ts +6 -2
  52. package/src/cli/review-here.ts +136 -0
  53. package/src/cli.ts +45 -14
  54. package/src/collections/actions.ts +5 -4
  55. package/src/collections/checks.ts +5 -0
  56. package/src/collections/collection-types.ts +4 -3
  57. package/src/collections/pings.ts +4 -1
  58. package/src/collections/providers.ts +6 -4
  59. package/src/collections/tests.ts +7 -4
  60. package/src/core/app-icon-frame.ts +62 -0
  61. package/src/core/app-icon.ts +179 -17
  62. package/src/core/archived.ts +10 -7
  63. package/src/core/check-ctx.ts +38 -4
  64. package/src/core/check-pass.ts +7 -0
  65. package/src/core/foreign.ts +87 -0
  66. package/src/core/gui-color.ts +75 -0
  67. package/src/core/hub-theme.ts +1 -3
  68. package/src/core/layout.ts +3 -0
  69. package/src/core/machine-commit.ts +9 -1
  70. package/src/core/one-lib.ts +2 -1
  71. package/src/core/one-way-in-policy.ts +17 -12
  72. package/src/core/owner-word-policy.ts +123 -0
  73. package/src/core/panel-shades.ts +140 -0
  74. package/src/core/repo-gui-color.ts +16 -0
  75. package/src/core/role-policy.ts +17 -0
  76. package/src/core/scope.ts +6 -3
  77. package/src/core/tmux-policy.ts +264 -0
  78. package/src/core/unit-icon.ts +43 -0
  79. package/src/fleet/push-fleet.ts +2 -0
  80. package/src/fleet/scan-fleet.ts +3 -0
  81. package/src/gate/cache-audit.ts +7 -1
  82. package/src/gate/gate-checks.ts +14 -9
  83. package/src/gate/run-fix.ts +30 -5
  84. package/src/gate/run-fixers.ts +8 -3
  85. package/src/home/activity-shape.ts +2 -0
  86. package/src/home/activity.ts +2 -1
  87. package/src/home/daemon-guard.ts +20 -2
  88. package/src/home/daemon-jobs.ts +26 -18
  89. package/src/home/gui-app/ShipkitGui.swift +2012 -144
  90. package/src/home/gui-app/icon.svg +8 -0
  91. package/src/home/gui-app.ts +94 -30
  92. package/src/home/home-routes.ts +53 -9
  93. package/src/home/home-start.ts +27 -3
  94. package/src/home/inbox-shape.ts +7 -3
  95. package/src/home/log-follow.ts +117 -0
  96. package/src/home/machine-fold.ts +1 -1
  97. package/src/home/open-app.ts +9 -3
  98. package/src/home/page-build.ts +5 -1
  99. package/src/home/page-held.ts +1 -1
  100. package/src/home/pm-config.ts +0 -8
  101. package/src/home/pm.ts +62 -5
  102. package/src/home/process-apps.ts +70 -23
  103. package/src/home/process-rows.ts +16 -1
  104. package/src/home/push-sources.ts +18 -13
  105. package/src/home/resources.ts +16 -7
  106. package/src/home/run-daemon.ts +4 -1
  107. package/src/home/run-pm.ts +1 -1
  108. package/src/home/serve-daemon.ts +13 -4
  109. package/src/home/serve-web.ts +141 -17
  110. package/src/home/space-page.ts +3 -3
  111. package/src/home/space-route.ts +2 -2
  112. package/src/home/supervise.ts +2 -1
  113. package/src/home/vault-page.ts +2 -1
  114. package/src/home/web-places.ts +239 -0
  115. package/src/home/widgets.ts +16 -2
  116. package/src/hooks/commit-message.ts +11 -9
  117. package/src/hooks/one-way-in-guard.ts +145 -68
  118. package/src/hooks/run-hooks.ts +15 -5
  119. package/src/hooks/shared-file.ts +273 -83
  120. package/src/hooks/shell-writes.ts +620 -0
  121. package/src/hooks/write-log.ts +149 -0
  122. package/src/hq/door-route.ts +63 -7
  123. package/src/hq/door.ts +45 -12
  124. package/src/hq/history-send.ts +3 -1
  125. package/src/hq/hq-db.ts +10 -3
  126. package/src/hq/hq-local.ts +24 -5
  127. package/src/hq/hq-routes.ts +3 -1
  128. package/src/hq/hq-store.ts +9 -3
  129. package/src/hq/kinds/index.ts +2 -1
  130. package/src/hq/kinds/kind.ts +9 -4
  131. package/src/hq/kinds/presence-rule.ts +56 -0
  132. package/src/hq/kinds/presence.ts +210 -0
  133. package/src/hq/kinds/report.ts +8 -5
  134. package/src/hq/lead-order.ts +68 -0
  135. package/src/hq/outbox.ts +7 -0
  136. package/src/hq/replica.ts +5 -7
  137. package/src/hq/report-facts.ts +14 -7
  138. package/src/hq/report.ts +47 -2
  139. package/src/hq/switch.ts +1 -0
  140. package/src/hq/terminal-hop.ts +64 -0
  141. package/src/hq/thread-sync.ts +13 -6
  142. package/src/http/door-forward.ts +10 -12
  143. package/src/http/door-names.ts +9 -0
  144. package/src/http/hop-caller.ts +23 -0
  145. package/src/http/hop-names.ts +14 -0
  146. package/src/http/loopback-serve.ts +28 -6
  147. package/src/http/owner-word.ts +128 -0
  148. package/src/http/same-origin.ts +12 -0
  149. package/src/{serve → http}/secret-gate.ts +3 -3
  150. package/src/ledger/run-log.ts +25 -1
  151. package/src/media-store/backup/sources.ts +53 -6
  152. package/src/media-store/backup/thread-copy.ts +9 -5
  153. package/src/media-store/copy/config.ts +10 -9
  154. package/src/media-store/daemon.ts +5 -2
  155. package/src/media-store/put.ts +3 -0
  156. package/src/media-store/space.ts +14 -16
  157. package/src/media-store/upload.ts +4 -0
  158. package/src/messages/collection.ts +2 -2
  159. package/src/messages/model.ts +6 -1
  160. package/src/messages/routes.ts +3 -0
  161. package/src/orchestrator/brief.md +8 -6
  162. package/src/orchestrator/channel-declare.ts +58 -0
  163. package/src/orchestrator/channel.ts +226 -0
  164. package/src/orchestrator/guards.ts +12 -3
  165. package/src/orchestrator/host.ts +35 -0
  166. package/src/orchestrator/lead-shape.ts +86 -0
  167. package/src/orchestrator/now.ts +88 -0
  168. package/src/orchestrator/phone.ts +4 -1
  169. package/src/orchestrator/places-file.ts +38 -0
  170. package/src/orchestrator/places-look.ts +180 -0
  171. package/src/orchestrator/places-shape.ts +151 -0
  172. package/src/orchestrator/places.ts +50 -0
  173. package/src/orchestrator/presence-shape.ts +13 -2
  174. package/src/orchestrator/presence.ts +26 -15
  175. package/src/orchestrator/push.ts +5 -10
  176. package/src/orchestrator/role-shape.ts +270 -0
  177. package/src/orchestrator/role.ts +242 -0
  178. package/src/orchestrator/routes.ts +136 -31
  179. package/src/orchestrator/sessions-shape.ts +78 -0
  180. package/src/orchestrator/sessions.ts +86 -0
  181. package/src/orchestrator/share.ts +71 -0
  182. package/src/orchestrator/start-notice.ts +61 -0
  183. package/src/orchestrator/start.ts +137 -0
  184. package/src/orchestrator/started.ts +55 -0
  185. package/src/orchestrator/stuck.ts +196 -0
  186. package/src/orchestrator/unheard.ts +18 -7
  187. package/src/pages/frame-client.ts +44 -6
  188. package/src/problems/failure-words.ts +80 -0
  189. package/src/release/run-bump.ts +26 -5
  190. package/src/release/run-release.ts +34 -14
  191. package/src/repo-config.ts +37 -9
  192. package/src/review/aside-at.ts +19 -0
  193. package/src/review/band.ts +3 -3
  194. package/src/review/doc-save.ts +1 -1
  195. package/src/review/inbox-hook.ts +12 -4
  196. package/src/review/inbox-read.ts +20 -7
  197. package/src/review/instruction-guards.ts +137 -0
  198. package/src/review/instructions.ts +14 -2
  199. package/src/review/item-db.ts +52 -2
  200. package/src/review/mentions.ts +6 -4
  201. package/src/review/model.ts +3 -2
  202. package/src/review/parties.ts +88 -19
  203. package/src/review/push.ts +32 -15
  204. package/src/review/routes.ts +12 -4
  205. package/src/review/secret-route.ts +5 -5
  206. package/src/review/snooze.ts +1 -16
  207. package/src/review/store-parties.ts +4 -2
  208. package/src/review/take-back.ts +2 -1
  209. package/src/review/threads.ts +13 -2
  210. package/src/review/unit.ts +3 -2
  211. package/src/review/view-layout.ts +8 -1
  212. package/src/review/watchers.ts +25 -4
  213. package/src/secrets/key-pair.ts +14 -0
  214. package/src/secrets/lapse.ts +3 -3
  215. package/src/secrets/manager.ts +5 -1
  216. package/src/secrets/name-template.ts +83 -0
  217. package/src/secrets/name.ts +3 -0
  218. package/src/secrets/read.ts +10 -6
  219. package/src/secrets/secrets-view.ts +299 -0
  220. package/src/secrets/who-reads.ts +2 -1
  221. package/src/serve/frame-part.ts +49 -0
  222. package/src/serve/hub-app/accounts-line.tsx +33 -45
  223. package/src/serve/hub-app/activity-st.ts +6 -5
  224. package/src/serve/hub-app/activity-view.tsx +10 -9
  225. package/src/serve/hub-app/advice-box.tsx +6 -5
  226. package/src/serve/hub-app/advisor-app.tsx +2 -0
  227. package/src/serve/hub-app/advisor-face.tsx +3 -2
  228. package/src/serve/hub-app/advisor.html +1 -0
  229. package/src/serve/hub-app/advisors-view.tsx +52 -10
  230. package/src/serve/hub-app/advisors.css +4 -0
  231. package/src/serve/hub-app/app-bridge.ts +31 -5
  232. package/src/serve/hub-app/asked-page.ts +24 -0
  233. package/src/serve/hub-app/asks-page.tsx +10 -6
  234. package/src/serve/hub-app/auto-text.tsx +7 -5
  235. package/src/serve/hub-app/card-head.tsx +3 -2
  236. package/src/serve/hub-app/check-view.tsx +10 -9
  237. package/src/serve/hub-app/checks-svc.ts +96 -32
  238. package/src/serve/hub-app/clock-svc.ts +24 -8
  239. package/src/serve/hub-app/code-copy.ts +1 -1
  240. package/src/serve/hub-app/col-card.tsx +2 -1
  241. package/src/serve/hub-app/col-list-page.tsx +12 -6
  242. package/src/serve/hub-app/col-list-st.ts +12 -2
  243. package/src/serve/hub-app/col-tables-view.tsx +8 -44
  244. package/src/serve/hub-app/col-tables.ts +0 -14
  245. package/src/serve/hub-app/cols-svc.ts +6 -12
  246. package/src/serve/hub-app/columns.ts +94 -0
  247. package/src/serve/hub-app/comfy-view.tsx +8 -7
  248. package/src/serve/hub-app/commands/commands-page.tsx +4 -3
  249. package/src/serve/hub-app/commands/commands-st.ts +2 -2
  250. package/src/serve/hub-app/controls.css +69 -23
  251. package/src/serve/hub-app/cycle-button.tsx +2 -1
  252. package/src/serve/hub-app/database-st.ts +1 -1
  253. package/src/serve/hub-app/database-view.tsx +4 -2
  254. package/src/serve/hub-app/deaf.tsx +27 -0
  255. package/src/serve/hub-app/dock-st.ts +21 -16
  256. package/src/serve/hub-app/dock-view.tsx +19 -12
  257. package/src/serve/hub-app/empty-section.tsx +30 -0
  258. package/src/serve/hub-app/entry-bar.css +1 -1
  259. package/src/serve/hub-app/entry-bar.tsx +11 -6
  260. package/src/serve/hub-app/entry-list.css +32 -0
  261. package/src/serve/hub-app/entry-list.tsx +123 -0
  262. package/src/serve/hub-app/entry-pick.ts +1 -1
  263. package/src/serve/hub-app/entry-sections.ts +140 -0
  264. package/src/serve/hub-app/event-stream-reader.ts +56 -0
  265. package/src/serve/hub-app/floating.tsx +68 -14
  266. package/src/serve/hub-app/geometry-view.tsx +3 -2
  267. package/src/serve/hub-app/git-view.tsx +3 -2
  268. package/src/serve/hub-app/hash-route.ts +14 -2
  269. package/src/serve/hub-app/header-bar.tsx +53 -36
  270. package/src/serve/hub-app/home-st.ts +131 -14
  271. package/src/serve/hub-app/home-strip.css +24 -13
  272. package/src/serve/hub-app/home-strip.tsx +131 -66
  273. package/src/serve/hub-app/home.html +5 -0
  274. package/src/serve/hub-app/hub-app.tsx +94 -102
  275. package/src/serve/hub-app/hub.css +61 -94
  276. package/src/serve/hub-app/icons.tsx +16 -0
  277. package/src/serve/hub-app/identities-st.ts +19 -54
  278. package/src/serve/hub-app/identities-view.tsx +25 -24
  279. package/src/serve/hub-app/identity-address.ts +2 -2
  280. package/src/serve/hub-app/in-sight.ts +10 -0
  281. package/src/serve/hub-app/inbox-st.ts +20 -2
  282. package/src/serve/hub-app/inbox-view.tsx +16 -9
  283. package/src/serve/hub-app/inbox.css +1 -0
  284. package/src/serve/hub-app/index.html +5 -0
  285. package/src/serve/hub-app/insights-view.tsx +6 -5
  286. package/src/serve/hub-app/instructions.css +4 -1
  287. package/src/serve/hub-app/kept-cols.tsx +83 -20
  288. package/src/serve/hub-app/kept-width.tsx +76 -0
  289. package/src/serve/hub-app/keys.ts +116 -38
  290. package/src/serve/hub-app/layout-st.ts +109 -99
  291. package/src/serve/hub-app/lightbox-zoom.css +36 -0
  292. package/src/serve/hub-app/list-filter.tsx +15 -6
  293. package/src/serve/hub-app/list-head.tsx +29 -0
  294. package/src/serve/hub-app/list-row.ts +8 -0
  295. package/src/serve/hub-app/list-walk.ts +26 -105
  296. package/src/serve/hub-app/live-socket.ts +274 -0
  297. package/src/serve/hub-app/live-sources.ts +189 -0
  298. package/src/serve/hub-app/live-svc.ts +2 -2
  299. package/src/serve/hub-app/machine-st.ts +75 -14
  300. package/src/serve/hub-app/main-panel.css +211 -0
  301. package/src/serve/hub-app/main-panel.tsx +259 -0
  302. package/src/serve/hub-app/md.ts +4 -4
  303. package/src/serve/hub-app/media-svc.ts +5 -5
  304. package/src/serve/hub-app/media-view.tsx +13 -12
  305. package/src/serve/hub-app/messages/messages-page.tsx +8 -7
  306. package/src/serve/hub-app/messages/messages-st.ts +5 -2
  307. package/src/serve/hub-app/new-thread-st.ts +170 -0
  308. package/src/serve/hub-app/new-thread.tsx +133 -107
  309. package/src/serve/hub-app/orchestrator-line.tsx +115 -45
  310. package/src/serve/hub-app/orchestrator-places.tsx +86 -0
  311. package/src/serve/hub-app/orchestrator.css +57 -5
  312. package/src/serve/hub-app/page-keys.ts +107 -68
  313. package/src/serve/hub-app/page-reload.ts +46 -6
  314. package/src/serve/hub-app/pages-frames.tsx +40 -3
  315. package/src/serve/hub-app/pages-svc.ts +3 -1
  316. package/src/serve/hub-app/palette-st.ts +198 -43
  317. package/src/serve/hub-app/palette-view.tsx +32 -8
  318. package/src/serve/hub-app/panel-head-action.tsx +39 -0
  319. package/src/serve/hub-app/panel-head.tsx +70 -0
  320. package/src/serve/hub-app/panel-repo.ts +42 -0
  321. package/src/serve/hub-app/panel-source.ts +195 -0
  322. package/src/serve/hub-app/panel-tint.css +6 -0
  323. package/src/serve/hub-app/panel-tint.ts +23 -0
  324. package/src/serve/hub-app/panel-walk.ts +107 -0
  325. package/src/serve/hub-app/pill-row.tsx +2 -1
  326. package/src/serve/hub-app/place-path.ts +4 -0
  327. package/src/serve/hub-app/places-svc.ts +75 -0
  328. package/src/serve/hub-app/plan-view.tsx +3 -2
  329. package/src/serve/hub-app/polled.ts +11 -1
  330. package/src/serve/hub-app/presence-st.ts +66 -32
  331. package/src/serve/hub-app/processes-view.tsx +2 -2
  332. package/src/serve/hub-app/project-bar.tsx +116 -0
  333. package/src/serve/hub-app/project-list.css +20 -173
  334. package/src/serve/hub-app/project-list.tsx +30 -298
  335. package/src/serve/hub-app/projects-svc.ts +59 -32
  336. package/src/serve/hub-app/push-sign.tsx +2 -1
  337. package/src/serve/hub-app/push-svc.ts +86 -69
  338. package/src/serve/hub-app/quiet-st.ts +5 -3
  339. package/src/serve/hub-app/rail-groups.ts +144 -0
  340. package/src/serve/hub-app/reader-chips.tsx +2 -1
  341. package/src/serve/hub-app/recordings-st.ts +2 -1
  342. package/src/serve/hub-app/recordings-view.tsx +19 -47
  343. package/src/serve/hub-app/recordings.css +0 -2
  344. package/src/serve/hub-app/reflections-page.tsx +10 -6
  345. package/src/serve/hub-app/releases/releases-page.tsx +6 -5
  346. package/src/serve/hub-app/repo-sections.ts +127 -38
  347. package/src/serve/hub-app/repo-st.ts +57 -36
  348. package/src/serve/hub-app/review/advisor-bar.tsx +3 -2
  349. package/src/serve/hub-app/review/ask-proof.tsx +79 -0
  350. package/src/serve/hub-app/review/attach-view.tsx +11 -10
  351. package/src/serve/hub-app/review/box-view.ts +479 -0
  352. package/src/serve/hub-app/review/box-zoom.tsx +70 -0
  353. package/src/serve/hub-app/review/diff-view.tsx +3 -2
  354. package/src/serve/hub-app/review/doc-body.tsx +2 -1
  355. package/src/serve/hub-app/review/dock.tsx +3 -2
  356. package/src/serve/hub-app/review/draft-body.tsx +4 -3
  357. package/src/serve/hub-app/review/faces.tsx +0 -8
  358. package/src/serve/hub-app/review/group-block.tsx +8 -7
  359. package/src/serve/hub-app/review/heard-line.tsx +4 -3
  360. package/src/serve/hub-app/review/instructions-view.tsx +3 -2
  361. package/src/serve/hub-app/review/item-verdict.tsx +40 -40
  362. package/src/serve/hub-app/review/kind-states.tsx +5 -4
  363. package/src/serve/hub-app/review/kit.tsx +24 -4
  364. package/src/serve/hub-app/review/lane-bar.tsx +30 -28
  365. package/src/serve/hub-app/review/lightbox.tsx +6 -4
  366. package/src/serve/hub-app/review/live-bar.tsx +7 -6
  367. package/src/serve/hub-app/review/live-view.tsx +6 -5
  368. package/src/serve/hub-app/review/object-card.tsx +2 -1
  369. package/src/serve/hub-app/review/object-panel.tsx +11 -10
  370. package/src/serve/hub-app/review/pano-view.tsx +3 -2
  371. package/src/serve/hub-app/review/question-views.tsx +6 -5
  372. package/src/serve/hub-app/review/review-cells.tsx +21 -20
  373. package/src/serve/hub-app/review/review-host.ts +3 -0
  374. package/src/serve/hub-app/review/review-kit.ts +7 -5
  375. package/src/serve/hub-app/review/review-list.tsx +98 -52
  376. package/src/serve/hub-app/review/review-page.tsx +3 -3
  377. package/src/serve/hub-app/review/review-st.ts +70 -14
  378. package/src/serve/hub-app/review/review-thread.tsx +234 -138
  379. package/src/serve/hub-app/review/review-views.tsx +166 -191
  380. package/src/serve/hub-app/review/space3d.tsx +17 -9
  381. package/src/serve/hub-app/review/thread-close.tsx +24 -32
  382. package/src/serve/hub-app/review/thread-st.ts +39 -25
  383. package/src/serve/hub-app/review/trailer-body.tsx +5 -4
  384. package/src/serve/hub-app/review/trailer-page.tsx +18 -16
  385. package/src/serve/hub-app/review/trailer-st.ts +3 -2
  386. package/src/serve/hub-app/review/trailer-timeline.tsx +10 -9
  387. package/src/serve/hub-app/review/trailer-voices.tsx +29 -28
  388. package/src/serve/hub-app/review.css +159 -42
  389. package/src/serve/hub-app/row-acts.tsx +126 -0
  390. package/src/serve/hub-app/row-face.tsx +29 -0
  391. package/src/serve/hub-app/running-rows.tsx +142 -0
  392. package/src/serve/hub-app/running-st.ts +110 -0
  393. package/src/serve/hub-app/search-view.tsx +3 -2
  394. package/src/serve/hub-app/secrets-page.tsx +290 -0
  395. package/src/serve/hub-app/secrets-st.ts +181 -0
  396. package/src/serve/hub-app/secrets.css +65 -0
  397. package/src/serve/hub-app/section-head.tsx +3 -2
  398. package/src/serve/hub-app/session-chips.tsx +55 -0
  399. package/src/serve/hub-app/shell.ts +56 -0
  400. package/src/serve/hub-app/site/site-part.tsx +6 -5
  401. package/src/serve/hub-app/site/site-st.ts +0 -6
  402. package/src/serve/hub-app/site.css +0 -1
  403. package/src/serve/hub-app/social/calendar.tsx +7 -6
  404. package/src/serve/hub-app/social/comms-page.tsx +29 -26
  405. package/src/serve/hub-app/social/group-editor.tsx +2 -1
  406. package/src/serve/hub-app/social/kit.tsx +12 -11
  407. package/src/serve/hub-app/social/next-release.tsx +3 -2
  408. package/src/serve/hub-app/social/post-card.tsx +21 -20
  409. package/src/serve/hub-app/social/post-page.tsx +2 -1
  410. package/src/serve/hub-app/social/problems.tsx +3 -2
  411. package/src/serve/hub-app/social/social-page.tsx +29 -27
  412. package/src/serve/hub-app/social/social-st.ts +4 -2
  413. package/src/serve/hub-app/social/stage-popup.tsx +11 -10
  414. package/src/serve/hub-app/social.css +7 -5
  415. package/src/serve/hub-app/source-acts.ts +79 -0
  416. package/src/serve/hub-app/source-page.tsx +17 -0
  417. package/src/serve/hub-app/space-view.tsx +5 -4
  418. package/src/serve/hub-app/stores/stores-page.tsx +21 -19
  419. package/src/serve/hub-app/stores/stores-st.ts +1 -1
  420. package/src/serve/hub-app/stores.css +1 -1
  421. package/src/serve/hub-app/terminal-history-st.ts +112 -0
  422. package/src/serve/hub-app/terminal-keys.ts +79 -0
  423. package/src/serve/hub-app/terminal-lib.ts +110 -0
  424. package/src/serve/hub-app/terminal-links.ts +55 -0
  425. package/src/serve/hub-app/terminal-list-st.ts +304 -0
  426. package/src/serve/hub-app/terminal-log-st.ts +242 -0
  427. package/src/serve/hub-app/terminal-out.ts +135 -0
  428. package/src/serve/hub-app/terminal-pages.tsx +115 -0
  429. package/src/serve/hub-app/terminal-panel.tsx +60 -9
  430. package/src/serve/hub-app/terminal-sources.tsx +335 -0
  431. package/src/serve/hub-app/terminal-st.ts +447 -167
  432. package/src/serve/hub-app/terminal-stream.ts +233 -0
  433. package/src/serve/hub-app/terminal-tab.tsx +64 -0
  434. package/src/serve/hub-app/terminal-widths.ts +30 -0
  435. package/src/serve/hub-app/terminal.css +50 -4
  436. package/src/serve/hub-app/test-view.tsx +5 -3
  437. package/src/serve/hub-app/tests-view.tsx +16 -15
  438. package/src/serve/hub-app/theme-st.ts +5 -0
  439. package/src/serve/hub-app/thread-row.tsx +39 -31
  440. package/src/serve/hub-app/time-ago.tsx +3 -2
  441. package/src/serve/hub-app/time-view.tsx +2 -1
  442. package/src/serve/hub-app/time.css +1 -1
  443. package/src/serve/hub-app/timeline-chart.tsx +5 -4
  444. package/src/serve/hub-app/timeline-view.tsx +10 -9
  445. package/src/serve/hub-app/tips.ts +247 -0
  446. package/src/serve/hub-app/tree-build.ts +40 -8
  447. package/src/serve/hub-app/tree-svc.ts +167 -134
  448. package/src/serve/hub-app/unit-icons.ts +26 -0
  449. package/src/serve/hub-app/url-address.ts +154 -0
  450. package/src/serve/hub-app/url-faces.ts +88 -0
  451. package/src/serve/hub-app/url-forms.tsx +183 -0
  452. package/src/serve/hub-app/urls-svc.ts +167 -5
  453. package/src/serve/hub-app/urls-view.tsx +56 -20
  454. package/src/serve/hub-app/urls.css +26 -0
  455. package/src/serve/hub-app/vault-view.tsx +5 -4
  456. package/src/serve/hub-app/veille/veille-page.tsx +34 -33
  457. package/src/serve/hub-app/veille/veille-st.ts +6 -3
  458. package/src/serve/hub-app/view-layout.css +3 -3
  459. package/src/serve/hub-app/when-view.tsx +5 -4
  460. package/src/serve/hub-app/wikis-view.tsx +6 -5
  461. package/src/serve/hub-app/words.tsx +9 -2
  462. package/src/serve/hub-runtime.ts +3 -2
  463. package/src/serve/orchestrator-host.ts +58 -0
  464. package/src/serve/page-live.ts +147 -0
  465. package/src/serve/project-gutter-route.ts +63 -2
  466. package/src/serve/read-worker.ts +7 -2
  467. package/src/serve/runs-stamp.ts +33 -0
  468. package/src/serve/secrets-read.ts +156 -0
  469. package/src/serve/serve-hub.ts +71 -22
  470. package/src/serve/terminal-claudes.ts +185 -0
  471. package/src/serve/terminal-guard.ts +10 -5
  472. package/src/serve/terminal-host.ts +517 -0
  473. package/src/serve/terminal-record.ts +104 -0
  474. package/src/serve/terminal-route.ts +466 -103
  475. package/src/serve/terminal-shells.ts +3 -0
  476. package/src/serve/terminal-watch.ts +102 -0
  477. package/src/shipkit-files.ts +9 -4
  478. package/src/shot/client.ts +4 -9
  479. package/src/shot/shooter.ts +2 -4
  480. package/src/shot/shot-ask.ts +2 -7
  481. package/src/shot/shot-theme.ts +6 -17
  482. package/src/social/routes.ts +2 -2
  483. package/src/social/writes.ts +3 -0
  484. package/src/suite/test-units.ts +6 -2
  485. package/src/trailer/sound/eleven.ts +1 -0
  486. package/src/urls/added.ts +111 -0
  487. package/src/urls/icons.ts +294 -0
  488. package/src/urls/places.ts +139 -0
  489. package/src/urls/routes.ts +17 -7
  490. package/src/urls/rows.ts +48 -15
  491. package/src/urls/unit.ts +57 -3
  492. package/src/urls/write-routes.ts +207 -0
  493. package/src/vault/vault-destroy.ts +2 -1
  494. package/src/vault/vault-import.ts +4 -11
  495. package/src/vault/vault-restore.ts +3 -2
  496. package/src/veille/chrome.ts +18 -3
  497. package/src/veille/identity.ts +6 -0
  498. package/src/view3d/cam.ts +30 -46
  499. package/src/view3d/lib.ts +20 -2
  500. package/src/view3d/viewer.ts +62 -88
  501. package/src/wiki/agent-paths.ts +2 -1
  502. package/src/orchestrator/deliver.ts +0 -81
  503. package/src/orchestrator/drill.ts +0 -129
  504. package/src/orchestrator/keeper.ts +0 -332
  505. package/src/orchestrator/pm.ts +0 -20
  506. package/src/orchestrator/state.ts +0 -92
  507. package/src/orchestrator/switch.ts +0 -86
  508. package/src/orchestrator/tmux.ts +0 -82
  509. package/src/serve/hub-app/rail-fly.tsx +0 -95
  510. package/src/serve/hub-app/side-lists.ts +0 -72
  511. package/src/serve/hub-app/sidebar.tsx +0 -62
  512. package/src/serve/hub-app/tree-row.tsx +0 -125
@@ -0,0 +1,517 @@
1
+ // the terminal host (wiki tools/shipkit/hub.md, The terminal panel): what keeps a repo's terminals alive apart from the
2
+ // hub's own process, behind ONE object the routes speak to (TerminalHost, at the end of this file). Today the mechanism
3
+ // is tmux, and every tmux word of the hub is in this file: a terminal is a window of the session shipkit keeps for the
4
+ // repo, the list is read from tmux each time, an act is a tmux command, and nothing about a terminal is kept by the
5
+ // hub or the page, so a reload, a hub restart and a closed app change nothing. A window keeps its last screen when
6
+ // its program ends (remain-on-exit), until he closes it. A page looks at the terminals through a VIEW: a session of
7
+ // its own grouped with the repo's (the same windows, its own current one), so two pages show two terminals at once;
8
+ // a view ends with its client.
9
+ // The one constraint a reader breaks first: a window id (`@7`) is the tmux server's, not the session's, so every act
10
+ // checks the window is one of this session's before it runs
11
+
12
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
13
+ import { dirname, join } from 'path'
14
+ import { homeDir } from '../home/home-paths.ts'
15
+ import { AGENT_ENV } from '../vault/vault-init.ts'
16
+ import { KEPT_ID, type KeptTerminal, type TerminalRecord } from './terminal-record.ts'
17
+
18
+ /** one terminal as tmux has it */
19
+ export type TermWindow = {
20
+ /** tmux's id of the window, `@7`: stable for its life, the handle of every act */
21
+ id: string
22
+ index: number
23
+ name: string
24
+ /** what runs in it now: `claude`, `bash`, `vim` */
25
+ command: string
26
+ /** its program ended: the screen and the scrollback stay */
27
+ dead: boolean
28
+ /** the exit code of a program that ended, else null */
29
+ status: number | null
30
+ /** the title its program set, '' when it is the host's name (tmux's default) */
31
+ title: string
32
+ /** its program asked the terminal for the mouse (tmux's mouse_any_flag): a click in the page is the program's */
33
+ mouse: boolean
34
+ /** its program draws on the alternate screen (vim, less, htop): it has no lines to scroll back through */
35
+ alt: boolean
36
+ /** when the program the terminal was opened with started (epoch ms): when the terminal was opened, or started
37
+ * again; null where it is not known */
38
+ startedAt: number | null
39
+ /** its folder, as its shell last said it; '' where it is not known */
40
+ dir: string
41
+ /** its name is one he gave (tmux renames it no more by what runs in it) */
42
+ named?: true
43
+ /** a restart of the Mac or of the terminals' server ended it: a row of the record (terminal-record.ts), `dead`
44
+ * too, with no screen to show. `command` is what ran in it, '' at its prompt */
45
+ gone?: true
46
+ /** what shipkit itself opened it for (ROLE_OPTION): `orchestrator`; absent on a terminal he opened */
47
+ role?: string
48
+ }
49
+
50
+ /** a tmux command run to its end: whether it succeeded, what it printed */
51
+ export type Tmux = (args: string[]) => { ok: boolean; out: string }
52
+
53
+ const SEP = '\x1f'
54
+ /** the option on a window that says what shipkit itself opened it for: set once when it is opened, read back with the
55
+ * list. Never its name, which is his to change, nor its command, which a terminal he starts can share */
56
+ export const ROLE_OPTION = '@sk_role'
57
+ const FIELDS = ['#{window_id}', '#{window_index}', '#{window_name}', '#{pane_current_command}', '#{pane_dead}', '#{pane_dead_status}', '#{pane_title}', '#{host}', '#{host_short}', '#{mouse_any_flag}', '#{alternate_on}', '#{pane_pid}', '#{pane_current_path}', '#{pid}.#{start_time}', '#{automatic-rename}', `#{${ROLE_OPTION}}`]
58
+
59
+ /** when each of these processes started, by its pid: read once a process (a start never changes) */
60
+ export type Born = (pids: number[]) => Map<number, number | null>
61
+
62
+ /** how long a process has run, as `ps -o etime=` prints it (`[[dd-]hh:]mm:ss`), in seconds; null for anything else */
63
+ export function etimeSeconds(etime: string): number | null {
64
+ const m = /^(?:(?:(\d+)-)?(\d+):)?(\d+):(\d+)$/.exec(etime.trim())
65
+ return m == null ? null : ((Number(m[1] ?? 0) * 24 + Number(m[2] ?? 0)) * 60 + Number(m[3])) * 60 + Number(m[4])
66
+ }
67
+
68
+ /** the rows `list-windows` printed with FIELDS, a window's first pane each */
69
+ export function parseWindows(out: string, born?: Born): TermWindow[] {
70
+ const rows = out.split('\n').filter((l) => l !== '').flatMap((l) => {
71
+ const [id, index, name, command, dead, status, title, host, short, mouse, alt, pid, dir, , auto, role] = l.split(SEP)
72
+ if (id == null || !/^@\d+$/.test(id)) return []
73
+ return [{ pid: Number(pid) || 0, w: { id, index: Number(index), name: name ?? '', command: command ?? '', dead: dead === '1', status: dead === '1' && status !== '' ? Number(status) : null, title: title == null || title === host || title === short ? '' : title, mouse: mouse === '1', alt: alt === '1', dir: dir ?? '', ...(auto === 'off' || auto === '0' ? { named: true as const } : {}), ...(role != null && role !== '' ? { role } : {}) } }]
74
+ })
75
+ // an ended program has no process to ask: its start is not known
76
+ const at = born?.(rows.filter((r) => r.pid > 0 && !r.w.dead).map((r) => r.pid))
77
+ return rows.map((r) => ({ ...r.w, startedAt: at?.get(r.pid) ?? null }))
78
+ }
79
+
80
+ /** the session's terminals in tmux's order, null when the session is gone */
81
+ export function listWindows(tmux: Tmux, session: string): TermWindow[] | null {
82
+ // tmux escapes a control byte it prints: the separator goes in as its own escape
83
+ const r = tmux(['list-windows', '-t', `=${session}:`, '-F', FIELDS.join('#{l:\x1f}')])
84
+ return r.ok ? parseWindows(r.out) : null
85
+ }
86
+
87
+ /** a session as one read of tmux has it: its terminals, and the window each of its views shows now */
88
+ /** `server`: which server instance said it (its pid and its start), '' where it did not say */
89
+ export type Seen = { windows: TermWindow[]; views: Record<string, string>; server?: string }
90
+ const VIEW = 'V'
91
+
92
+ /** the terminals of the session and the current window of each session grouped with it, in one tmux command; null
93
+ * when the session is gone */
94
+ export function readSession(tmux: Tmux, session: string, born?: Born): Seen | null {
95
+ const r = tmux(['list-windows', '-t', `=${session}:`, '-F', FIELDS.join('#{l:\x1f}'), ';', 'list-sessions', '-f', `#{==:#{session_group},${session}}`, '-F', [VIEW, '#{session_name}', '#{window_id}'].join('#{l:\x1f}')])
96
+ if (!r.ok) return null
97
+ const views: Record<string, string> = {}
98
+ for (const l of r.out.split('\n')) {
99
+ const [mark, name, window] = l.split(SEP)
100
+ if (mark === VIEW && name != null && window != null) views[name] = window
101
+ }
102
+ const server = r.out.split('\n').find((l) => /^@\d+\x1f/.test(l))?.split(SEP)[13] ?? ''
103
+ return { windows: parseWindows(r.out, born), views, ...(server === '' ? {} : { server }) }
104
+ }
105
+
106
+ /** a page's view of the repo's session: a session of its own in the same group, named after the part of the page's socket that looks through it */
107
+ export const viewName = (session: string, id: string): string => `${session}-v${id.slice(0, 8)}`
108
+
109
+ export type WindowAct =
110
+ | { act: 'new' }
111
+ /** a new terminal that runs Claude Code, `account` one of the names the hub offers */
112
+ | { act: 'claude'; account?: string }
113
+ | { act: 'select'; window: string }
114
+ | { act: 'rename'; window: string; name: string }
115
+ | { act: 'close'; window: string }
116
+ /** the program of an ended terminal started again, in its folder */
117
+ | { act: 'restart'; window: string }
118
+ /** a terminal a restart ended (a row of the record): a new empty shell in its folder, under its name */
119
+ | { act: 'reopen'; window: string }
120
+ /** that row out of the record, or every such row of the repo */
121
+ | { act: 'forget'; window?: string }
122
+
123
+ /** what a new terminal runs Claude Code with: the account asked for rides in its command, so ↻ starts it again as
124
+ * the same account */
125
+ export type ClaudeStart = { argv: string[] }
126
+
127
+ /** a name he typed, as tmux takes one: one line, no control byte, 40 signs */
128
+ export const windowName = (name: string): string => [...name.replace(/[\x00-\x1f\x7f]/g, ' ').trim()].slice(0, 40).join('')
129
+
130
+ /** what an act did: the terminal it opened, or why tmux refused it */
131
+ export type Acted = { ok: true; window?: string } | { ok: false; why: string }
132
+ const no = (why: string): Acted => ({ ok: false, why })
133
+
134
+ /** why « start it again » is refused on a terminal shipkit opened for a role, and the control that starts it: an
135
+ * orchestrator starts under the account the owner picks, each time */
136
+ export const keptWords = (role: string, repo: string): string =>
137
+ role === 'orchestrator'
138
+ ? `this is the terminal of sk session start: + in the project's CLAUDE section starts a session under the account you pick, or sk session start ${repo} --account <n>`
139
+ : `this terminal is shipkit's own (${role}): what keeps it starts it again`
140
+
141
+ /** the act on the session, as tmux commands run in order. `view`: the page's own view, where a new terminal shows and
142
+ * a select moves; none (the main panel's list alone): a new terminal opens in the session, and its page shows it */
143
+ export function actOn(tmux: Tmux, o: { session: string; /** the repo, for the words of a refusal */ repo?: string; view?: string | null; root: string; act: WindowAct; claude?: (account: string | undefined) => ClaudeStart | string }): Acted {
144
+ const a = o.act
145
+ const all = listWindows(tmux, o.session)
146
+ if (all == null) return no('no terminal runs here now: open one again')
147
+ // what a window keeps (its screen when its program ends, its size) is the server's config: HOST_CONF
148
+ const made = (argv: string[]): Acted => {
149
+ const r = tmux(['new-window', '-P', '-F', '#{window_id}', '-t', o.view == null ? `=${o.session}:` : `=${o.view}:`, '-c', o.root, ...argv])
150
+ const window = r.out.trim().split('\n')[0] ?? ''
151
+ return r.ok && /^@\d+$/.test(window) ? { ok: true, window } : no('the terminal did not open')
152
+ }
153
+ if (a.act === 'new') return made([])
154
+ if (a.act === 'claude') {
155
+ const start = o.claude?.(a.account) ?? 'this hub starts no Claude Code'
156
+ return typeof start === 'string' ? no(start) : made(['-n', 'claude', '--', ...start.argv])
157
+ }
158
+ if (!all.some((w) => w.id === a.window)) return no('that terminal is gone: the list is read again')
159
+ const did = (ok: boolean, why: string): Acted => (ok ? { ok: true } : no(why))
160
+ if (a.act === 'reopen' || a.act === 'forget') return no('that terminal is gone: the list is read again')
161
+ if (a.act === 'select') return o.view == null ? no('this page shows no terminal: open the terminal\'s own page') : did(tmux(['select-window', '-t', `=${o.view}:${a.window}`]).ok, 'that terminal did not show')
162
+ if (a.act === 'close') return did(tmux(['kill-window', '-t', a.window]).ok, 'that terminal did not close')
163
+ if (a.act === 'restart') {
164
+ const role = all.find((w) => w.id === a.window)?.role
165
+ if (role != null) return no(keptWords(role, o.repo ?? o.session.replace(/^sk-/, '')))
166
+ return did(tmux(['respawn-window', '-k', '-t', a.window]).ok, 'that terminal did not start again')
167
+ }
168
+ const name = windowName(a.name)
169
+ if (name === '') return no('a terminal needs a name')
170
+ return did(tmux(['rename-window', '-t', a.window, '--', name]).ok, 'that terminal took no new name')
171
+ }
172
+
173
+ /** a request's body as an act, null when it is none */
174
+ export function windowAct(b: { act?: unknown; window?: unknown; name?: unknown; account?: unknown }): WindowAct | null {
175
+ // a row a restart ended has an id of the record's own: to close it is to forget it, to start it again a new shell
176
+ if (typeof b.window === 'string' && KEPT_ID.test(b.window)) return b.act === 'close' || b.act === 'forget' ? { act: 'forget', window: b.window } : b.act === 'restart' || b.act === 'reopen' ? { act: 'reopen', window: b.window } : null
177
+ if (b.act === 'forget') return { act: 'forget' }
178
+ const window = typeof b.window === 'string' && /^@\d+$/.test(b.window) ? b.window : null
179
+ if (b.act === 'new') return { act: 'new' }
180
+ if (b.act === 'claude') return { act: 'claude', ...(typeof b.account === 'string' ? { account: b.account } : {}) }
181
+ if (window == null) return null
182
+ if (b.act === 'select' || b.act === 'close' || b.act === 'restart') return { act: b.act, window }
183
+ if (b.act === 'rename' && typeof b.name === 'string') return { act: 'rename', window, name: b.name }
184
+ return null
185
+ }
186
+
187
+ /** tmux on this Mac: launchd's PATH lacks Homebrew's folders. None in a test's process (`SHIPKIT_NO_TMUX=1`,
188
+ * tests/_setup.ts): a hub a test starts is a Mac with no tmux, so it never reads or closes the owner's own
189
+ * terminals; a test that needs terminals gives its hub a server of its own (tests/tmux-test-server.ts) */
190
+ export function tmuxBin(): string | null {
191
+ if (process.env.SHIPKIT_NO_TMUX === '1') return null
192
+ const path = [process.env.PATH ?? '', '/opt/homebrew/bin', '/usr/local/bin'].join(':')
193
+ return Bun.which('tmux', { PATH: path }) ?? null
194
+ }
195
+
196
+ /** tmux takes no dot or colon in a session name */
197
+ export const sessionName = (repo: string): string => `sk-${repo.replace(/[^A-Za-z0-9_-]/g, '-')}`
198
+
199
+ /** scrollback a pane keeps, where tmux's own default (2000) still stands: a long run of an agent stays readable */
200
+ export const HISTORY_LINES = 100_000
201
+
202
+ /** the title a pane's program set, and nothing while it is still tmux's default, the host's name */
203
+ const PANE_TITLE = '#{?#{||:#{==:#{pane_title},#{host}},#{==:#{pane_title},#{host_short}}},,#{pane_title}}'
204
+ /** the page's terminal is UTF-8 whatever the hub's locale is: under launchd the daemon has none, and a tmux client
205
+ * with none prints every sign past ASCII, and the separator of a list, as `_` */
206
+ export const UTF8 = '-u'
207
+ /** tmux commands as one argv, a lone `;` between two */
208
+ const chain = (...cmds: string[][]): string[] => cmds.flatMap((c, i) => (i === 0 ? c : [';', ...c]))
209
+
210
+ // ── the host: the one object the hub's routes speak to. Every tmux word of the hub is in this file ──
211
+
212
+ /** the mechanism that keeps a repo's terminals alive apart from the hub's own process, as the routes drive it. Today
213
+ * it is tmux; the pages know none of it: a terminal has an id, a name and what runs in it */
214
+ export type TerminalHost = {
215
+ /** the name the mechanism knows the repo's terminals by */
216
+ readonly group: string
217
+ /** what an agent types in a terminal to reach the same terminals */
218
+ readonly reach: string
219
+ /** the repo's terminals exist now */
220
+ alive(): boolean
221
+ /** the terminals, and the terminal each view shows; null when the repo has none running */
222
+ read(): Seen | null
223
+ /** the repo's group started where none runs; `first`: what its first terminal runs, a shell with none. The id of
224
+ * that terminal, null when it did not start */
225
+ start(first?: string[]): string | null
226
+ /** a view's name from the id of the part that looks through it, and what that view's pty runs. `window`: the
227
+ * terminal it shows first */
228
+ viewName(id: string): string
229
+ viewArgv(view: string, window?: string | null): string[]
230
+ /** an act on one terminal: new, claude, select, rename, close, restart. `view`: the view that asks, where a new
231
+ * terminal shows and a select moves */
232
+ act(a: WindowAct, view: string | null, claude?: (account: string | undefined) => ClaudeStart | string): Acted
233
+ /** the last `lines` lines of a terminal, its screen included, as its program printed them (colours kept).
234
+ * `target`: a terminal's id, or a view for the terminal it shows */
235
+ history(target: string, lines: number): string
236
+ /** a view on a hidden page gives up its say on the size of the terminal it shows, and takes it back */
237
+ hidden(view: string, on: boolean): void
238
+ /** one command of the mechanism, for the reader of where each Claude Code session runs (terminal-claudes.ts) */
239
+ readonly tmux: Tmux
240
+ }
241
+
242
+ /** the one tmux command the host never runs, whoever asks: it would end every terminal of every project at once */
243
+ const ENDS_SERVER = 'kill-server'
244
+
245
+ /** the whole config of shipkit's own server, passed with `-f`, so no file of his (`~/.tmux.conf`) is ever read by it.
246
+ * tmux is plumbing there: no prefix and no key binding in any table, so every key and every click reaches the
247
+ * program; no status line, no bell, no message; a key's bytes are never held back (escape-time 0). The server and a
248
+ * repo's session end with nothing but their last terminal: not with their last view, not while empty. The mouse option
249
+ * stays on as a transport alone: with no binding tmux does nothing with a click or the wheel but hand them to a
250
+ * program that asked for them. A terminal keeps its screen when its program ends, and takes the size of the views
251
+ * that show it, the smallest where two visible views show the same one, so each reads it whole */
252
+ export const HOST_CONF = `# written by shipkit (terminal-host.ts) at each start: an edit here is lost
253
+ set -s exit-empty off
254
+ set -s exit-unattached off
255
+ set -g destroy-unattached off
256
+ set -g prefix None
257
+ set -g prefix2 None
258
+ unbind-key -a -q -T prefix
259
+ unbind-key -a -q -T root
260
+ unbind-key -a -q -T copy-mode
261
+ unbind-key -a -q -T copy-mode-vi
262
+ unbind-key -a -q -T move
263
+ set -s escape-time 0
264
+ set -s extended-keys on
265
+ set -s focus-events on
266
+ set -s terminal-features[90] 'xterm*:extkeys:hyperlinks'
267
+ set -g status off
268
+ set -g mouse on
269
+ set -g history-limit ${HISTORY_LINES}
270
+ set -g bell-action none
271
+ set -g visual-bell off
272
+ set -g visual-activity off
273
+ set -g visual-silence off
274
+ set -g display-time 1
275
+ set -g set-titles on
276
+ set -g set-titles-string '${PANE_TITLE}'
277
+ set -g -w monitor-activity off
278
+ set -g -w monitor-bell off
279
+ set -g -w remain-on-exit on
280
+ set -g -w aggressive-resize on
281
+ set -g -w window-size smallest
282
+ `
283
+
284
+ export type HostDeps = {
285
+ /** the tmux binary */
286
+ bin: string
287
+ /** the repo, and its folder: where a new terminal starts */
288
+ repo: string
289
+ root: string
290
+ /** a command run to its end, its output read; and one run for its effect alone */
291
+ ask: (argv: string[]) => { ok: boolean; out: string }
292
+ run: (argv: string[]) => void
293
+ /** shipkit's own server: its socket, a path named on every command (`-S`), so no command of another tmux server
294
+ * reaches it and none of its own reaches another; and where its config is written (`write`: in place of the
295
+ * disk, a test) */
296
+ own: { socket: string; conf: string; write?: (file: string, text: string) => void; /** what a restart ends comes back as rows from it; absent: nothing comes back */ record?: TerminalRecord }
297
+ }
298
+
299
+ const writeConf = (file: string, text: string): void => {
300
+ try {
301
+ if (existsSync(file) && readFileSync(file, 'utf8') === text) return
302
+ mkdirSync(dirname(file), { recursive: true })
303
+ writeFileSync(file, text)
304
+ } catch { /* the server then starts with tmux's defaults: the terminal works, his prefix key is tmux's */ }
305
+ }
306
+
307
+ /** the repo's terminals as a session of shipkit's own tmux server: every command names its socket and its config */
308
+ export function tmuxHost(d: HostDeps): TerminalHost {
309
+ const group = sessionName(d.repo)
310
+ const own = d.own
311
+ ;(own.write ?? writeConf)(own.conf, HOST_CONF)
312
+ if (own.write == null) try { mkdirSync(dirname(own.socket), { recursive: true }) } catch { /* tmux then says why it cannot start */ }
313
+ const pre = [d.bin, UTF8, '-S', own.socket, '-f', own.conf]
314
+ const mine: Tmux = (args) => {
315
+ if (args.includes(ENDS_SERVER)) throw new Error(`the terminal host never runs ${ENDS_SERVER}: it would end every terminal of every project`)
316
+ return d.ask([...pre, ...args])
317
+ }
318
+ // a server that runs since an older shipkit takes today's config, once a process: each line is safe to repeat.
319
+ // With no server yet nothing runs: the first session starts it with the config (-f)
320
+ let current = false
321
+ const upToDate = (): void => {
322
+ if (current) return
323
+ current = true
324
+ d.run([...pre, 'source-file', '-q', own.conf])
325
+ }
326
+ const alive = (): boolean => mine(['has-session', '-t', `=${group}`]).ok
327
+ const record = own.record ?? null
328
+ /** which server instance answers now, null when none does */
329
+ const serverNow = (): string | null => {
330
+ const r = mine(['display-message', '-p', '#{pid}.#{start_time}'])
331
+ return r.ok && r.out.trim() !== '' ? r.out.trim() : null
332
+ }
333
+ /** a terminal of the record as a row: ended, with no screen */
334
+ const goneWindow = (k: KeptTerminal, index: number): TermWindow => ({ id: k.id, index, name: k.name, command: k.ran, dead: true, status: null, title: '', mouse: false, alt: false, startedAt: null, dir: k.dir, ...(k.named ? { named: true as const } : {}), gone: true })
335
+ // when each terminal's first program started: asked of `ps` once a process, never again
336
+ const starts = new Map<number, number | null>()
337
+ const born: Born = (pids) => {
338
+ const missing = pids.filter((p) => !starts.has(p))
339
+ if (missing.length > 0) {
340
+ const now = Date.now()
341
+ for (const l of d.ask(['ps', '-o', 'pid=,etime=', '-p', missing.join(',')]).out.split('\n')) {
342
+ const [pid, etime] = l.trim().split(/\s+/)
343
+ const s = etimeSeconds(etime ?? '')
344
+ if (pid != null && s != null) starts.set(Number(pid), Math.floor(now / 1000 - s) * 1000)
345
+ }
346
+ for (const p of missing) if (!starts.has(p)) starts.set(p, null)
347
+ }
348
+ for (const p of [...starts.keys()]) if (!pids.includes(p)) starts.delete(p)
349
+ return starts
350
+ }
351
+ const ttyOf = (view: string): string | null => mine(['list-clients', '-t', `=${view}`, '-F', '#{client_tty}']).out.split('\n').find((l) => l.startsWith('/')) ?? null
352
+ return {
353
+ group,
354
+ reach: `tmux -S ${own.socket} attach -t ${group}`,
355
+ alive,
356
+ read() {
357
+ const seen = readSession(mine, group, born)
358
+ if (record == null) return seen
359
+ // a terminal shipkit opened for a role (an orchestrator's) is started again by its own act (« start »), never offered as a row a restart ended
360
+ const ended = record.sync(d.repo, seen?.windows.filter((w) => w.role == null) ?? null, seen?.server ?? '', serverNow)
361
+ if (ended.length === 0) return seen
362
+ const live = seen?.windows ?? []
363
+ return { ...(seen ?? { views: {} }), windows: [...live, ...ended.map((k, i) => goneWindow(k, live.length + i))] }
364
+ },
365
+ start(first = []) {
366
+ upToDate()
367
+ d.run([...pre, 'new-session', '-d', '-s', group, '-c', d.root, ...first])
368
+ const window = mine(['display-message', '-p', '-t', `=${group}:`, '#{window_id}']).out.trim()
369
+ return /^@\d+$/.test(window) ? window : null
370
+ },
371
+ viewName: (id) => viewName(group, id),
372
+ viewArgv(view, window = null) {
373
+ upToDate()
374
+ // the view ends with its client, and it alone: every other option is the server's config
375
+ return [...pre, ...chain(['new-session', '-t', `=${group}`, '-s', view], ['set-option', '-t', view, 'destroy-unattached', 'on'], ...(window == null ? [] : [['select-window', '-t', `=${view}:${window}`]]))]
376
+ },
377
+ act(a, view, claude) {
378
+ if (a.act === 'forget') return (record?.drop(d.repo, a.window), { ok: true })
379
+ if (a.act === 'reopen') {
380
+ const k = record?.ended(d.repo).find((x) => x.id === a.window)
381
+ if (k == null) return { ok: false, why: 'that terminal is gone: the list is read again' }
382
+ // a new empty shell in its folder, under the name he gave: what ran in it is never run again
383
+ const at = ['-c', k.dir === '' ? d.root : k.dir, ...(k.named ? ['-n', k.name] : [])]
384
+ let window: string
385
+ if (alive()) window = mine(['new-window', '-P', '-F', '#{window_id}', '-t', `=${group}:`, ...at]).out.trim()
386
+ else {
387
+ upToDate()
388
+ d.run([...pre, 'new-session', '-d', '-s', group, ...at])
389
+ window = mine(['display-message', '-p', '-t', `=${group}:`, '#{window_id}']).out.trim()
390
+ }
391
+ if (!/^@\d+$/.test(window)) return { ok: false, why: 'the terminal did not open' }
392
+ record?.drop(d.repo, k.id)
393
+ return { ok: true, window }
394
+ }
395
+ return actOn(mine, { session: group, repo: d.repo, view, root: d.root, act: a, ...(claude == null ? {} : { claude }) })
396
+ },
397
+ history: (target, lines) => mine(['capture-pane', '-p', '-e', '-S', `-${Math.max(0, Math.floor(lines))}`, '-t', /^@\d+$/.test(target) ? target : `=${target}:`]).out,
398
+ hidden(view, on) {
399
+ const tty = ttyOf(view)
400
+ if (tty != null) d.run([...pre, 'refresh-client', '-t', tty, '-f', on ? 'ignore-size' : '!ignore-size'])
401
+ },
402
+ tmux: mine,
403
+ }
404
+ }
405
+
406
+ // ── shipkit's own server for a caller that is no hub (the orchestrator's host, the cli), and the terminals shipkit opens for a role ──
407
+
408
+ /** where shipkit's own server lives on this Mac: its socket, and the config written beside it */
409
+ export const ownServerFiles = (): { socket: string; conf: string } => ({ socket: join(homeDir(), 'terminals.sock'), conf: join(homeDir(), 'terminals.conf') })
410
+
411
+ const NOT_HIS = /^(TMUX|TMUX_PANE|SK_AGENT|NODE_ENV|CLAUDECODE|CLAUDE_CODE_.*)$/
412
+ /** what every tmux command and every terminal of a hub and of this door runs with, so the server is the same whoever
413
+ * starts it. The server keeps the variables of the command that started it and hands them to every terminal: none
414
+ * names another tmux server (tmux refuses to nest under TMUX), an agent or a mode, and it reads and writes UTF-8,
415
+ * under a hub with no locale too (launchd's). Every house marker of an agent's shell goes (AGENT_ENV): a daemon an
416
+ * agent started must not make his own panel read as an agent's, or the owner's commands (sk advisors expose, sk
417
+ * vault init) refuse in it */
418
+ export function ownEnv(env: Record<string, string | undefined> = process.env): Record<string, string> {
419
+ const out: Record<string, string> = {}
420
+ for (const [k, v] of Object.entries(env)) if (v != null && !NOT_HIS.test(k) && !AGENT_ENV.includes(k)) out[k] = v
421
+ if (out.LC_ALL == null && out.LC_CTYPE == null && out.LANG == null) out.LANG = 'en_US.UTF-8'
422
+ return { ...out, TERM: 'xterm-256color', COLORTERM: 'truecolor' }
423
+ }
424
+
425
+ /** one tmux command on shipkit's own server, `input` on its stdin (a buffer to load); `err`: what tmux said when it refused */
426
+ export type OwnTmux = (args: string[], input?: string) => { ok: boolean; out: string; err: string }
427
+
428
+ /** shipkit's own server as one door for a caller that is no hub: every command names the server's socket and config as
429
+ * a hub's host does, the config is written first (this caller may be the one that starts the server), and the door
430
+ * never ends the server. `spawn`: in place of the real one (a test) */
431
+ export function ownTmux(o: { bin: string; socket: string; conf: string; write?: (file: string, text: string) => void; spawn?: (argv: string[], input?: string) => { ok: boolean; out: string; err: string } }): OwnTmux {
432
+ (o.write ?? writeConf)(o.conf, HOST_CONF)
433
+ if (o.write == null) try { mkdirSync(dirname(o.socket), { recursive: true }) } catch { /* tmux then says why it cannot start */ }
434
+ const spawn = o.spawn ?? ((argv: string[], input?: string) => {
435
+ const p = Bun.spawnSync(argv, { env: ownEnv(), stdin: input === undefined ? 'ignore' : Buffer.from(input), stdout: 'pipe', stderr: 'pipe' })
436
+ return { ok: p.exitCode === 0, out: p.stdout.toString(), err: p.stderr.toString().trim() }
437
+ })
438
+ return (args, input) => {
439
+ if (args.includes(ENDS_SERVER)) throw new Error(`the terminal host never runs ${ENDS_SERVER}: it would end every terminal of every project`)
440
+ return spawn([o.bin, UTF8, '-S', o.socket, '-f', o.conf, ...args], input)
441
+ }
442
+ }
443
+
444
+ /** a terminal shipkit keeps itself in a repo's group, as its role says: its window, and the process of its pane */
445
+ export type RoleWindow = { window: string; dead: boolean; pid: number | null; status: string }
446
+
447
+ /** the terminal of `session` opened for `role`, null when none is or the session is gone */
448
+ /** the session or the server is not there: the window is gone, which is an answer */
449
+ const GONE = /can't find session|no server running|error connecting to|no sessions/i
450
+
451
+ /** the same read, with a tmux that did not answer told apart from a window that is gone: `failed` holds its error.
452
+ * A caller that would end or start a program on « gone » treats `failed` as a doubt */
453
+ export function roleWindowRead(tmux: Tmux, session: string, role: string): RoleWindow | null | { failed: string } {
454
+ const r = tmux(['list-windows', '-t', `=${session}:`, '-f', `#{==:#{${ROLE_OPTION}},${role}}`, '-F', ['#{window_id}', '#{pane_dead}', '#{pane_pid}', '#{pane_dead_status}'].join('#{l:\x1f}')])
455
+ if (!r.ok) {
456
+ const err = ((r as { err?: string }).err ?? '').trim()
457
+ return GONE.test(err) ? null : { failed: err.slice(0, 120) || 'no answer' }
458
+ }
459
+ const [window, dead, pid, status] = (r.out.split('\n').find((l) => /^@\d+\x1f/.test(l)) ?? '').split(SEP)
460
+ if (window == null || !/^@\d+$/.test(window)) return null
461
+ const n = Number(pid)
462
+ return { window, dead: dead === '1', pid: dead !== '1' && Number.isInteger(n) && n > 0 ? n : null, status: status ?? '' }
463
+ }
464
+
465
+ /** every terminal of the server opened for `role`, each with its group: one command for all the projects. `failed`:
466
+ * tmux did not answer, a doubt; no server running is no terminal */
467
+ export function roleWindows(tmux: Tmux, role: string): (RoleWindow & { session: string })[] | { failed: string } {
468
+ const r = tmux(['list-windows', '-a', '-f', `#{==:#{${ROLE_OPTION}},${role}}`, '-F', ['#{window_id}', '#{pane_dead}', '#{pane_pid}', '#{pane_dead_status}', '#{?session_group,#{session_group},#{session_name}}'].join('#{l:\x1f}')])
469
+ if (!r.ok) {
470
+ const err = ((r as { err?: string }).err ?? '').trim()
471
+ // a server with no session left (its last terminal closed) has no current target: no terminal either
472
+ return GONE.test(err) || /no current target/i.test(err) ? [] : { failed: err.slice(0, 120) || 'no answer' }
473
+ }
474
+ const seen = new Set<string>()
475
+ return r.out.split('\n').flatMap((l) => {
476
+ const [window, dead, pid, status, session] = l.split(SEP)
477
+ // a page's view is a session of the same group and lists its windows once more: one row a window, by its group
478
+ if (window == null || !/^@\d+$/.test(window) || session == null || seen.has(window)) return []
479
+ seen.add(window)
480
+ const n = Number(pid)
481
+ return [{ window, dead: dead === '1', pid: dead !== '1' && Number.isInteger(n) && n > 0 ? n : null, status: status ?? '', session }]
482
+ })
483
+ }
484
+
485
+ /** the window of `session` that carries `role`, null when none does or tmux did not say */
486
+ export function roleWindow(tmux: Tmux, session: string, role: string): RoleWindow | null {
487
+ const w = roleWindowRead(tmux, session, role)
488
+ return w !== null && 'failed' in w ? null : w
489
+ }
490
+
491
+ /** what a role's terminal is opened with: a program that ends at once. Its window stays (remain-on-exit) and is marked
492
+ * before `runInRole` starts the real program in it, so a caller that dies between the two leaves an empty ended
493
+ * terminal, never a second copy of its program that no mark finds */
494
+ const PLACEHOLDER = '/usr/bin/true'
495
+ /** the size of a role's terminal until a page shows it: no client sizes it before */
496
+ const ROLE_SIZE = { cols: 200, rows: 50 }
497
+
498
+ /** a terminal opened for `role` in the repo's group, the group started where none runs. Its id, null when it did not open */
499
+ export function openRoleWindow(tmux: Tmux, o: { session: string; root: string; role: string; name: string }): string | null {
500
+ const made = tmux(['has-session', '-t', `=${o.session}`]).ok
501
+ ? tmux(['new-window', '-d', '-P', '-F', '#{window_id}', '-t', `=${o.session}:`, '-n', o.name, '-c', o.root, '--', PLACEHOLDER])
502
+ : tmux(['new-session', '-d', '-P', '-F', '#{window_id}', '-s', o.session, '-n', o.name, '-c', o.root, '--', PLACEHOLDER])
503
+ const window = made.out.trim().split('\n')[0] ?? ''
504
+ if (!made.ok || !/^@\d+$/.test(window)) return null
505
+ if (!tmux(['set-option', '-w', '-t', window, ROLE_OPTION, o.role]).ok) return null
506
+ // a manual size would hold against the pages that show it later: sized once, then the server's rule again
507
+ tmux(['resize-window', '-t', window, '-x', String(ROLE_SIZE.cols), '-y', String(ROLE_SIZE.rows)])
508
+ tmux(['set-option', '-w', '-u', '-t', window, 'window-size'])
509
+ return window
510
+ }
511
+
512
+ /** `argv` started in a role's terminal, in place of what ran there: his view of it stays. False when tmux refused, or
513
+ * the window is no longer that role's */
514
+ export function runInRole(tmux: Tmux, o: { session: string; role: string; window: string; root: string; argv: readonly string[] }): boolean {
515
+ if (roleWindow(tmux, o.session, o.role)?.window !== o.window) return false
516
+ return tmux(['respawn-pane', '-k', '-t', o.window, '-c', o.root, '--', ...o.argv]).ok
517
+ }
@@ -0,0 +1,104 @@
1
+ // the record of every repo's terminals, one file of the machine: what a restart of the Mac or of the terminals' server
2
+ // takes away comes back as rows (a name, a folder, what ran), never as programs.
3
+ //
4
+ // the one constraint a reader breaks first: nothing here starts anything. A row comes back ended, and a new shell
5
+ // opens in its folder on his click alone. The file is written on a change of the terminals, never on a timer.
6
+ import { readFileSync } from 'fs'
7
+ import { atomicWriteJson } from '../core/atomic-write.ts'
8
+ import { SHELLS } from './terminal-shells.ts'
9
+
10
+ /** one terminal as the record keeps it */
11
+ export type KeptTerminal = {
12
+ /** tmux's id while it lives; an id of the record's own (`~k3f9a1`) once a restart ended it */
13
+ id: string
14
+ name: string
15
+ /** the name is his (tmux no longer renames the terminal by what runs in it), or the program's own: only his is
16
+ * given to the shell that opens in its place */
17
+ named: boolean
18
+ /** its folder, as its shell last said it */
19
+ dir: string
20
+ /** the program that ran in it, '' at its prompt */
21
+ ran: string
22
+ }
23
+ type RepoRecord = { server: string; live: KeptTerminal[]; ended: KeptTerminal[] }
24
+ type Live = { id: string; name: string; command: string; dead: boolean; dir: string; named?: true }
25
+
26
+ export type TerminalRecord = {
27
+ /** the repo's terminals as their server has them now (`null`: it holds none for this repo), and `server`: which
28
+ * server instance said it ('' unknown). `serverNow` is asked only when the record still holds live ones and none
29
+ * is left: null when no server answers. Answers the terminals a restart ended */
30
+ sync(repo: string, live: Live[] | null, server: string, serverNow: () => string | null): KeptTerminal[]
31
+ ended(repo: string): KeptTerminal[]
32
+ /** one ended terminal out of the record, or every ended one of the repo */
33
+ drop(repo: string, id?: string): void
34
+ }
35
+
36
+ /** an id tmux never gives: a terminal a restart ended */
37
+ export const KEPT_ID = /^~[a-z0-9]{1,12}$/
38
+
39
+ // a name tmux gives by itself lags behind the program (and reads `kernel_task` for one that just ended): the
40
+ // program's own word is the row's name then
41
+ const kept = (w: Live): KeptTerminal => ({ id: w.id, name: w.named === true || w.command === '' ? w.name : w.command, named: w.named === true, dir: w.dir, ran: w.dead || SHELLS.test(w.command) ? '' : w.command })
42
+
43
+ export function terminalRecord(file: string, io: { read?: () => string | null; write?: (value: unknown) => void; id?: () => string } = {}): TerminalRecord {
44
+ const read = io.read ?? ((): string | null => { try { return readFileSync(file, 'utf8') } catch { return null } })
45
+ const write = io.write ?? ((value: unknown): void => { try { atomicWriteJson(file, value, { indent: 1 }) } catch { /* a record that cannot be written costs the rows after a restart, never a terminal */ } })
46
+ const newId = io.id ?? ((): string => `~${Math.random().toString(36).slice(2, 8)}`)
47
+ let repos: Record<string, RepoRecord> | null = null
48
+ const load = (): Record<string, RepoRecord> => {
49
+ if (repos != null) return repos
50
+ repos = {}
51
+ try {
52
+ const raw = JSON.parse(read() ?? '{}') as { repos?: Record<string, Partial<RepoRecord>> }
53
+ for (const [name, r] of Object.entries(raw.repos ?? {})) repos[name] = { server: typeof r.server === 'string' ? r.server : '', live: Array.isArray(r.live) ? r.live : [], ended: Array.isArray(r.ended) ? r.ended : [] }
54
+ } catch { /* an unreadable record is an empty one */ }
55
+ return repos
56
+ }
57
+ const save = (): void => {
58
+ const all = load()
59
+ for (const [name, r] of Object.entries(all)) if (r.live.length === 0 && r.ended.length === 0) delete all[name]
60
+ write({ repos: all })
61
+ }
62
+ /** the live ones of a server that is gone: ended, each under an id of the record's own */
63
+ const end = (r: RepoRecord): void => {
64
+ r.ended.push(...r.live.map((k) => ({ ...k, id: newId() })))
65
+ r.live = []
66
+ }
67
+ return {
68
+ sync(repo, live, server, serverNow) {
69
+ const all = load()
70
+ const r = (all[repo] ??= { server: '', live: [], ended: [] })
71
+ const before = JSON.stringify(r)
72
+ if (live != null) {
73
+ // another server than the one that held the recorded ones: those ended with it
74
+ if (server !== '' && r.server !== '' && r.server !== server) end(r)
75
+ r.live = live.map(kept)
76
+ if (server !== '') r.server = server
77
+ } else if (r.live.length > 0) {
78
+ // none left: he closed them all on the same server, or the server is gone with them
79
+ if (serverNow() === r.server && r.server !== '') r.live = []
80
+ else end(r)
81
+ }
82
+ if (JSON.stringify(r) !== before) save()
83
+ else if (r.live.length === 0 && r.ended.length === 0) delete all[repo]
84
+ return r.ended
85
+ },
86
+ ended: (repo) => load()[repo]?.ended ?? [],
87
+ drop(repo, id) {
88
+ const r = load()[repo]
89
+ if (r == null) return
90
+ const left = id == null ? [] : r.ended.filter((k) => k.id !== id)
91
+ if (left.length === r.ended.length) return
92
+ r.ended = left
93
+ save()
94
+ },
95
+ }
96
+ }
97
+
98
+ const records = new Map<string, TerminalRecord>()
99
+ /** the record of one file, one object a process: every repo's hub writes the same file */
100
+ export function recordOf(file: string): TerminalRecord {
101
+ let r = records.get(file)
102
+ if (r == null) records.set(file, (r = terminalRecord(file)))
103
+ return r
104
+ }