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
@@ -9,9 +9,10 @@
9
9
  // origin header. The daemon's own guard then refuses any page that calls its
10
10
  // port directly, and lets this door through. The host guard runs here too: a request is answered only once its Host
11
11
  // is a loopback name or this Mac's tailnet name (machine-host.ts). The page itself is built here (page-build.ts), and
12
- // each open page is told of a new build on its push stream, a `page` notice the web adds to the daemon's stream
12
+ // each open page is told of a new build on its socket, a `page` frame the web adds to the daemon's (serve/page-live.ts)
13
13
  import { HOST_HEADER, hostName, loopbackName, REACH_HEADER, reachOfCaller, sameOrigin } from '../http/same-origin.ts'
14
14
  import { loopbackServe } from '../http/loopback-serve.ts'
15
+ import { FETCH_SITE_HEADER, ORIGIN_HEADER, TEST_PAGE_HEADER, type TestPage } from '../http/owner-word.ts'
15
16
  import { daemonPort, hubBase, pmPort } from './home-paths.ts'
16
17
  import { liveHopTarget, toLive } from '../serve/live-hop.ts'
17
18
  import { forwardPage, pagePath } from '../pages/forward.ts'
@@ -20,14 +21,17 @@ import { HELD_BUILD_SCRIPT, HELD_SOURCE_PATH, heldSource } from './page-held.ts'
20
21
  import { PAGE_PATH, type PageNotice, withPageNotices } from './page-build.ts'
21
22
  import { broughtByProxy, crossSiteRefusal, DOOR_KEY_HEADER, DOOR_PATH, doorHostOf, doorKeyFor, doorPathOf, doorPolicy, foreignOrigin, forwardHop, loginHop, protocolsOf, urlHostOf, urlPolicy, wsUrl } from '../http/door-forward.ts'
22
23
  import type { DoorTarget } from '../hq/door.ts'
24
+ import { LIVE_PATH, livePath, NO_TERMINAL_HEADER, pageFrame } from '../serve/page-live.ts'
23
25
  import { REVEAL_PATH, revealRefusal, TERMINAL_PATH, terminalRefusal } from '../serve/terminal-guard.ts'
24
26
  import type { UrlLogin } from '../urls/frame.ts'
25
- import type { TailnetWho } from '../http/tailnet-caller.ts'
27
+ import { houseTailnet, type TailnetWho } from '../http/tailnet-caller.ts'
28
+ import { HOP_DEVICE_HEADER, HOP_HEADER, HOP_PATH, HOP_REPO_HEADER, hopCaller, hopVerb } from '../http/hop-caller.ts'
29
+ import { type PlaceTarget, placeHops } from './web-places.ts'
26
30
 
27
31
  /** the page routes: ONE app for the overview, the plan, and the hub page of
28
32
  * each known repo, which moves between them in place (home-st.ts) */
29
33
  export function pageRoutes<T>(names: string[], page: T): Record<string, T> {
30
- const out: Record<string, T> = { '/': page, '/live': page, '/wiki': page, '/inbox': page, '/machines': page, '/database': page, '/vault': page, '/space': page, '/advisors': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page, '/time': page, '/recordings': page, '/identities': page }
34
+ const out: Record<string, T> = { '/': page, '/live': page, '/wiki': page, '/inbox': page, '/machines': page, '/database': page, '/vault': page, '/space': page, '/advisors': page, '/planned': page, '/activity': page, '/running': page, '/archived': page, '/insights': page, '/time': page, '/recordings': page, '/identities': page }
31
35
  for (const n of names) out[`${hubBase(n)}/`] = page
32
36
  return out
33
37
  }
@@ -69,7 +73,8 @@ export const PAGE_URLS_MS = 10_000
69
73
  /** the home answers that can wait on git or on a child: the activity page's first read of a window, a repo's git page, the insights page's read of every manifest, the time page's report */
70
74
  export const readsGit = (path: string): boolean => path === '/api/home/activity.json' || path === '/api/home/git.json' || path === '/api/home/insights.json' || path === '/api/home/time.json'
71
75
 
72
- /** a run or a check run streams for minutes, and a silent one is never cut; the threads' live stream stays open */
76
+ /** a run or a check run streams for minutes, and a silent one is never cut; the threads' live stream stays open (a
77
+ * watch in a terminal reads it, review/watch-feed.ts: a page reads its socket, serve/page-live.ts) */
73
78
  export const streams = (path: string): boolean => /\/api\/(run|check\/run)$/.test(path) || path === '/api/threads/live'
74
79
 
75
80
  export { hostName }
@@ -205,7 +210,15 @@ export type WebDeps = {
205
210
  export type DoorRefused = { refused: string; status: number }
206
211
  /** where the door sends a request: on the hq's machine, a process of a machine; on any machine, its own process, and
207
212
  * a declared url with the login its hop adds */
208
- export type DoorAsk = { target(machine: string, process: string): Promise<DoorTarget | DoorRefused>; local(id: string, key: string | null): Promise<{ origin: string } | DoorRefused>; url(repo: string, id: string): Promise<UrlLogin | DoorRefused> }
213
+ export type DoorAsk = {
214
+ target(machine: string, process: string): Promise<DoorTarget | DoorRefused>
215
+ local(id: string, key: string | null): Promise<{ origin: string } | DoorRefused>
216
+ url(repo: string, id: string): Promise<UrlLogin | DoorRefused>
217
+ /** on the hq's machine: where a place's terminals of a repo (this machine's name of it) are */
218
+ place(node: string, repo: string): Promise<PlaceTarget | DoorRefused>
219
+ /** on a place: the daemon's check of a hop (its switch, the key, the hq's Mac), and its name of the repo */
220
+ terminal(repo: string, key: string | null, device: string): Promise<{ name: string } | DoorRefused>
221
+ }
209
222
 
210
223
  /** how long the web keeps a url's login: a framed page asks dozens of files at once, the daemon reads it once */
211
224
  export const URL_LOGIN_MS = 10_000
@@ -225,18 +238,46 @@ export function daemonDoor(daemon: string): DoorAsk {
225
238
  target: (machine, process) => ask<DoorTarget>(`/api/home/door/target?${new URLSearchParams({ machine, process })}`),
226
239
  local: (id, key) => ask<{ origin: string }>(`/api/home/door/local?${new URLSearchParams({ id })}`, key == null ? {} : { [DOOR_KEY_HEADER]: key }),
227
240
  url: (repo, id) => ask<UrlLogin>(`/api/home/door/url?${new URLSearchParams({ repo, id })}`),
241
+ place: (node, repo) => ask<PlaceTarget>(`/api/home/door/place?${new URLSearchParams({ node, repo })}`),
242
+ terminal: (repo, key, device) => ask<{ name: string }>(`/api/home/door/terminal?${new URLSearchParams({ repo })}`, { [HOP_DEVICE_HEADER]: device, ...(key == null ? {} : { [DOOR_KEY_HEADER]: key }) }),
228
243
  }
229
244
  }
230
245
 
231
246
  /** a close code one side may send again: a reserved one (no status, an abnormal end, a tls failure) reads as normal */
232
247
  const sendableClose = (c: number): number => ((c >= 1000 && c <= 1003) || (c >= 1007 && c <= 1014) || (c >= 3000 && c <= 4999) ? c : 1000)
233
248
 
249
+ /** whether an origin is this machine's by a loopback name on one of those ports */
250
+ const ownPort = (origin: string, ports: readonly number[]): boolean => {
251
+ try {
252
+ const u = new URL(origin)
253
+ return loopbackName(hostName(u.host)) && ports.includes(Number(u.port || (u.protocol === 'https:' ? 443 : 80)))
254
+ } catch {
255
+ return false
256
+ }
257
+ }
258
+
234
259
  const doorText = (text: string, status: number): Response => new Response(text, { status, headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' } })
235
260
 
236
261
  /** one browser socket through the door, piped to that url with those headers */
237
- type Pipe = { up: WebSocket | null; queue: (string | Uint8Array<ArrayBuffer>)[]; door: { url: string; headers: Record<string, string>; protocols: string[] } }
238
-
239
- export function serveWeb(d: WebDeps) {
262
+ /** a socket the web carries to another server: `up`, its other half; `live`: it is a hub page's own socket to the
263
+ * daemon (serve/page-live.ts), on which the web says the page's builds; `off` ends what it listens to for it */
264
+ type Pipe = { up: WebSocket | null; queue: (string | Uint8Array<ArrayBuffer>)[]; door: { url: string; headers: Record<string, string>; protocols: string[] }; live?: true; off?: () => void; /** a hub page's socket: its id, once the daemon said it, which its parts of other places name (web-places.ts) */ page?: string }
265
+
266
+ /** `test`: a test started this web, and its clients stand in for a page of the hub with that test's token
267
+ * (http/owner-word.ts TestPage). The web of the product is started with none (run-web.ts) */
268
+ export function serveWeb(d: WebDeps, test?: TestPage) {
269
+ /** the web's tags on what it forwards to the daemon, never one a client sent: where the request came from, the
270
+ * Host it named, and what the browser said of itself, which the daemon's gate on the owner's acts reads
271
+ * (owner-word.ts). A test's token is passed on only by a web that test started */
272
+ const tagged = (req: Request, set: (name: string, value: string) => void): void => {
273
+ set(REACH_HEADER, reachOfCaller(req))
274
+ set(HOST_HEADER, req.headers.get('host') ?? new URL(req.url).host)
275
+ const origin = req.headers.get('origin')
276
+ if (origin != null) set(ORIGIN_HEADER, origin)
277
+ const site = req.headers.get('sec-fetch-site')
278
+ if (site != null) set(FETCH_SITE_HEADER, site)
279
+ if (test != null && req.headers.get(TEST_PAGE_HEADER) === test.token) set(TEST_PAGE_HEADER, test.token)
280
+ }
240
281
  let known = ''
241
282
  let wasDown = false
242
283
  let stopped = false
@@ -280,8 +321,7 @@ export function serveWeb(d: WebDeps) {
280
321
  const headers = new Headers()
281
322
  req.headers.forEach((v, k) => { if (!DROP.has(k) && !k.startsWith('x-shipkit-')) headers.set(k, v) })
282
323
  // the web's own tags, never one a browser sent: tailscaled passes x-shipkit-* as the client wrote it
283
- headers.set(REACH_HEADER, reachOfCaller(req))
284
- headers.set(HOST_HEADER, req.headers.get('host') ?? url.host)
324
+ tagged(req, (name, value) => headers.set(name, value))
285
325
  // a run or a live stream can stay silent for minutes
286
326
  srv.timeout(req, 0)
287
327
  const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : await req.arrayBuffer()
@@ -304,7 +344,7 @@ export function serveWeb(d: WebDeps) {
304
344
  out.delete('transfer-encoding')
305
345
  out.delete('connection')
306
346
  if (key != null) return await lastGood.keep(key, r, out)
307
- // the threads' push stream carries the page's builds too: one stream a page
347
+ // a page loaded before the socket reads its build on the event stream: said there too, so it reloads itself
308
348
  if (path === '/api/threads/live' && r.ok && r.body != null) return new Response(withPageNotices(r.body, page), { status: r.status, headers: out })
309
349
  return new Response(r.body, { status: r.status, statusText: r.statusText, headers: out })
310
350
  } catch (e) {
@@ -356,12 +396,60 @@ export function serveWeb(d: WebDeps) {
356
396
  return out
357
397
  }
358
398
 
399
+ /** a hub page's one socket, carried to the daemon's with the web's tags, as a request it forwards: where the page
400
+ * is reached from, the Host it named, the Origin its browser named, and the terminal's gate, which needs the peer
401
+ * and the browser's own headers that only this hop sees. Only a page of the hub in a browser gets here: every
402
+ * upgrade passes the loopback guard first, and its gate on the owner's acts (http/owner-word.ts); the daemon
403
+ * judges the socket again by the tags */
404
+ function liveSocket(req: Request, srv: Bun.Server<Pipe>): Response | undefined {
405
+ const headers: Record<string, string> = {}
406
+ tagged(req, (name, value) => { headers[name] = value })
407
+ const why = terminalRefusal(req, srv.requestIP(req)?.address ?? null, 'the terminal', { socket: true })
408
+ if (why != null) headers[NO_TERMINAL_HEADER] = why
409
+ const ok = srv.upgrade(req, { data: { up: null, queue: [], door: { url: wsUrl(d.daemon, LIVE_PATH), headers, protocols: [] }, live: true } })
410
+ return ok ? undefined : new Response('this address answers a WebSocket only', { status: 426, headers: { upgrade: 'websocket', 'cache-control': 'no-store' } })
411
+ }
412
+
359
413
  const doorAsk = d.door ?? daemonDoor(d.daemon)
360
414
  const upgrading = (req: Request): boolean => req.headers.get('upgrade')?.toLowerCase() === 'websocket'
415
+ /** a page's parts of another place's terminals, each through a hop to that place's web (web-places.ts) */
416
+ const places = placeHops({ target: (node, repo) => doorAsk.place(node, repo) })
417
+
418
+ /** `/door/_terminal/<verb>` on a place: a hop of the hq Mac's page to this machine's terminals, through tailscale
419
+ * serve. The caller is tailscale's word (hop-caller.ts), the rest the daemon's (hq/terminal-hop.ts): its switch,
420
+ * the key, the hq's own Mac, and its name of the repo. Each refusal is a 404 that names why */
421
+ async function toHop(req: Request, url: URL, srv: Bun.Server<Pipe>): Promise<Response | undefined> {
422
+ const verb = hopVerb(url.pathname.slice(HOP_PATH.length))
423
+ if (verb == null) return doorText('not found: a terminal hop is /door/_terminal/<live|open|watch|close|window|history>', 404)
424
+ const caller = await hopCaller(req, d.tailnet ?? houseTailnet)
425
+ if ('refused' in caller) return doorText(`not found: ${caller.refused}`, 404)
426
+ const key = req.headers.get(DOOR_KEY_HEADER)
427
+ const t = await doorAsk.terminal(url.searchParams.get('repo') ?? '', key, caller.device)
428
+ if ('refused' in t) return doorText(`not found: ${t.refused}`, t.status === 502 ? 502 : 404)
429
+ // the web's own tags, never one the caller wrote: the daemon judges the hop again by its key
430
+ const tags: Record<string, string> = { [REACH_HEADER]: 'tailnet', [HOST_HEADER]: req.headers.get('host') ?? '', [HOP_HEADER]: 'terminal', [HOP_DEVICE_HEADER]: caller.device, [HOP_REPO_HEADER]: t.name, ...(key == null ? {} : { [DOOR_KEY_HEADER]: key }) }
431
+ if (verb === 'live') {
432
+ if (!upgrading(req)) return doorText("a terminal hop's live part is a socket", 426)
433
+ const ok = srv.upgrade(req, { data: { up: null, queue: [], door: { url: wsUrl(d.daemon, LIVE_PATH), headers: tags, protocols: [] } } })
434
+ return ok ? undefined : doorText('the socket of the hop did not open', 400)
435
+ }
436
+ if (req.method !== 'POST') return doorText('a terminal hop takes a POST', 405)
437
+ srv.timeout(req, 0)
438
+ try {
439
+ const r = await fetch(`${d.daemon}${hubBase(t.name)}/api/terminal/${verb}`, { method: 'POST', headers: { ...tags, 'content-type': 'application/json' }, body: await req.arrayBuffer(), signal: AbortSignal.timeout(MACHINE_ANSWER_MS) })
440
+ return new Response(r.body, { status: r.status, headers: { 'content-type': r.headers.get('content-type') ?? 'text/plain; charset=utf-8', 'cache-control': 'no-store' } })
441
+ } catch (e) {
442
+ return doorText(daemonDownText(d.daemon, (e as Error).message), 502)
443
+ }
444
+ }
361
445
 
362
- /** a socket through the door: the browser's upgraded here, the same path opened at `url` */
363
- function doorSocket(req: Request, srv: Bun.Server<Pipe>, url: string, headers: Record<string, string>, answer: Record<string, string> = {}): Response | undefined {
446
+ /** a socket through the door: the browser's upgraded here, the same path opened at `url`. As a hop's request
447
+ * (hopHeaders), `origin` goes on only where the browser named the hop's own: a hop never writes the mark of a
448
+ * browser for a client that sent none, or a program under a hop's name would be its target's own page (a hub's
449
+ * socket, on which a terminal is typed into) */
450
+ function doorSocket(req: Request, srv: Bun.Server<Pipe>, url: string, to: Record<string, string>, answer: Record<string, string> = {}): Response | undefined {
364
451
  const protocols = protocolsOf(req)
452
+ const headers = req.headers.has('origin') ? to : Object.fromEntries(Object.entries(to).filter(([name]) => name !== 'origin'))
365
453
  const ok = srv.upgrade(req, { data: { up: null, queue: [], door: { url, headers, protocols } }, headers: { ...answer, ...(protocols[0] == null ? {} : { 'sec-websocket-protocol': protocols[0] }) } })
366
454
  return ok ? undefined : doorText('the socket through the door did not open', 400)
367
455
  }
@@ -434,6 +522,9 @@ export function serveWeb(d: WebDeps) {
434
522
  if (foreign != null) return doorText(foreign, 403)
435
523
  const t = await urlLoginOf(at.repo, at.id)
436
524
  if ('refused' in t) return doorText(`not found: ${t.refused}`, t.status === 502 ? 502 : 404)
525
+ // the home's own ports answer under no other name: under a hop's, a request skips the gate on the owner's acts
526
+ // (a hop's paths are its target's own), and the hop would then bring it to the home as the home's own page
527
+ if (ownPort(t.origin, [Number(srv.port), daemonPort(), pmPort()])) return doorText('refused: a url never frames the hub into itself (the home, the daemon and pm answer under their own name only)', 403)
437
528
  const url = new URL(req.url)
438
529
  const key = `${at.repo}/${at.id}`
439
530
  const declared = `${t.origin}\n${t.authorization ?? ''}`
@@ -475,6 +566,7 @@ export function serveWeb(d: WebDeps) {
475
566
  if (door != null) return toDoor(req, door, srv)
476
567
  const url = new URL(req.url)
477
568
  const path = url.pathname
569
+ if (path.startsWith(HOP_PATH)) return toHop(req, url, srv)
478
570
  if (path.startsWith(DOOR_PATH)) return ownDoor(req, url, srv)
479
571
  if (path === '/manifest.webmanifest') return Response.json(MANIFEST, { headers: { 'content-type': 'application/manifest+json', 'cache-control': 'no-cache' } })
480
572
  // a browser asks it before it reads the head, and so does a page the head never reached (an error page)
@@ -486,10 +578,14 @@ export function serveWeb(d: WebDeps) {
486
578
  const direct = await toPageProcess(req, decodeURIComponent(own[1]!), own[2]!, srv)
487
579
  if (direct != null) return direct
488
580
  }
581
+ if (livePath(path)) return liveSocket(req, srv)
489
582
  // the terminal's gate needs the peer and the browser's own headers, which only this hop sees
490
583
  if (TERMINAL_PATH.test(path)) {
491
584
  const why = terminalRefusal(req, srv.requestIP(req)?.address ?? null)
492
585
  if (why != null) return new Response(why, { status: 403, headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' } })
586
+ // a part of another place's terminals: through its hop, never the daemon's
587
+ const placed = await places.route(req, path)
588
+ if (placed != null) return placed
493
589
  }
494
590
  if (path === REVEAL_PATH) {
495
591
  const why = revealRefusal(req, srv.requestIP(req)?.address ?? null)
@@ -517,10 +613,14 @@ export function serveWeb(d: WebDeps) {
517
613
  // the names it answers beside loopback: this Mac's tailnet names the house declares (`hosts`, kept fresh by sync).
518
614
  // A hop and the terminal answer another site themselves (a hop with its policy, a 204 for a frame another site
519
615
  // opened); every other route passes sameOrigin in the guard
520
- const answersOtherSites = (req: Request): boolean => {
616
+ // a name of another app (a live view, a framed url, a door): the request goes to that app whole, as fetchFn routes it
617
+ const toOtherApp = (req: Request): boolean => {
521
618
  const host = req.headers.get('host')
619
+ return liveHopTarget(host) != null || urlHostOf(host) != null || doorHostOf(host) != null
620
+ }
621
+ const answersOtherSites = (req: Request): boolean => {
522
622
  const path = new URL(req.url).pathname
523
- return liveHopTarget(host) != null || urlHostOf(host) != null || doorHostOf(host) != null || path.startsWith(DOOR_PATH) || TERMINAL_PATH.test(path)
623
+ return toOtherApp(req) || path.startsWith(DOOR_PATH) || TERMINAL_PATH.test(path)
524
624
  }
525
625
  // `/door/` answers the hq's home and its door key alone (ownDoor): the key is its guard on a write over the tailnet
526
626
  const ownDoorWrites = (req: Request): 'owner' | 'own guard' => (new URL(req.url).pathname.startsWith(DOOR_PATH) ? 'own guard' : 'owner')
@@ -536,21 +636,45 @@ export function serveWeb(d: WebDeps) {
536
636
  up.onopen = () => {
537
637
  for (const m of ws.data.queue.splice(0)) up.send(m)
538
638
  }
539
- up.onmessage = (e) => void ws.send(e.data as string | ArrayBuffer)
639
+ // a page's own socket hears each build of the page too, after the daemon's hello: it knows the
640
+ // socket is up before it hears the build
641
+ let first = ws.data.live === true
642
+ up.onmessage = (e) => {
643
+ // a frame of a page's socket that could not be handed on ends it: the page opens another and
644
+ // reads everything again, where a missed line would leave a screen that is not the terminal's
645
+ if (ws.send(e.data as string | ArrayBuffer) === 0 && ws.data.live === true) return ws.close(1011)
646
+ if (!first) return
647
+ first = false
648
+ // the socket's id: what its parts of another place name
649
+ try {
650
+ const hello = JSON.parse(String(e.data)) as { t?: unknown; id?: unknown }
651
+ // a socket the web refused a terminal (the tailnet, his phone) has no part of a place either
652
+ if (hello.t === 'hello' && typeof hello.id === 'string' && hello.id !== '' && ws.data.door.headers[NO_TERMINAL_HEADER] == null) {
653
+ ws.data.page = hello.id
654
+ places.opened(hello.id, ws)
655
+ }
656
+ } catch { /* not a hello: no part of a place is asked on it */ }
657
+ if (page.notice != null) ws.send(pageFrame(page.notice))
658
+ ws.data.off = page.on((n) => void ws.send(pageFrame(n)))
659
+ }
540
660
  up.onclose = (e) => ws.close(sendableClose(e.code))
541
661
  up.onerror = () => ws.close(1011)
542
662
  },
543
663
  message(ws, m) {
664
+ // his keys to a terminal of another place go to its hop
665
+ if (ws.data.page != null && typeof m === 'string' && places.fromPage(ws.data.page, m)) return
544
666
  const up = ws.data.up
545
667
  const msg = typeof m === 'string' ? m : new Uint8Array(m)
546
668
  if (up?.readyState === WebSocket.OPEN) up.send(msg)
547
669
  else ws.data.queue.push(msg)
548
670
  },
549
671
  close(ws) {
672
+ ws.data.off?.()
550
673
  ws.data.up?.close()
674
+ if (ws.data.page != null) places.closed(ws.data.page)
551
675
  },
552
676
  },
553
- }, { hosts: (name) => hostAllowed(name, hosts), crossSite: answersOtherSites, tailnetWrites: ownDoorWrites, ...(d.tailnet ? { who: d.tailnet } : {}) })
677
+ }, { hosts: (name) => hostAllowed(name, hosts), crossSite: answersOtherSites, otherApp: toOtherApp, front: true, tailnetWrites: ownDoorWrites, ...(d.tailnet ? { who: d.tailnet } : {}), ...(test == null ? {} : { testPage: test }) })
554
678
  /** the page routes follow the daemon's repo list, and the allowed names its tailnet names; true when the routes changed */
555
679
  function sync(list: { repos: string[]; hosts: string[] }): boolean {
556
680
  hosts = new Set([...(d.hosts ?? []), ...list.hosts].map(hostName))
@@ -27,8 +27,8 @@ export type SpaceEnd = {
27
27
  /** the origin in words: the endpoint, or the NAME of the secret that holds it */
28
28
  origin: string
29
29
  cdn: string | null
30
- /** the NAME of the secret that holds its key pair */
31
- secret: string
30
+ /** the NAMES of the two secrets of its key */
31
+ key: { accessKeyId: string; secretAccessKey: string }
32
32
  config: () => Promise<SpaceConfig | { why: string }>
33
33
  /** the prefixes a copy never mirrors */
34
34
  skip?: string[]
@@ -105,7 +105,7 @@ function aboutFacts(e: SpaceEnd, r: ListingRecord | null, d: SpacePageDeps): Fac
105
105
  else if (!counted(l)) out.push({ text: `lifecycle rules: not read (${l.why})`, tone: 'dim' })
106
106
  else if (l === null || l.length === 0) out.push({ text: 'lifecycle rules: none, nothing expires', tone: 'ok' })
107
107
  else for (const rule of l) out.push({ text: `lifecycle rule ${rule}`, tone: 'ok' })
108
- out.push({ text: `its key: the secret ${e.secret} of the registry, read through the house's secret manager, held in memory only`, tone: 'ok' })
108
+ out.push({ text: `its key: the secrets ${e.key.accessKeyId} and ${e.key.secretAccessKey} of the registry, read through the house's secret manager, held in memory only`, tone: 'ok' })
109
109
  if (e.id === 'space') {
110
110
  if (d.replica != null) out.push({ text: `the hq's replica: ${d.replica} in this bucket`, tone: 'ok' })
111
111
  const copy = d.ends.find((x) => x.id === 'copy')
@@ -22,7 +22,7 @@ export async function houseEnds(root: string | null): Promise<{ ends: SpaceEnd[]
22
22
  region: s.region,
23
23
  origin: s.endpoint,
24
24
  cdn: s.cdn ?? null,
25
- secret: s.secret,
25
+ key: s.key,
26
26
  config: async () => {
27
27
  const { houseSpaceConfig } = await import('../media-store/space.ts')
28
28
  const h = await houseSpaceConfig()
@@ -39,7 +39,7 @@ export async function houseEnds(root: string | null): Promise<{ ends: SpaceEnd[]
39
39
  region: copy.region,
40
40
  origin: copy.endpoint ?? `the origin the secret ${copy.endpointSecret ?? '(none named)'} holds`,
41
41
  cdn: null,
42
- secret: copy.secret,
42
+ key: copy.key,
43
43
  get skip() {
44
44
  return skip
45
45
  },
@@ -10,6 +10,7 @@
10
10
  import { closeSync, existsSync, mkdirSync, openSync, readSync, rmSync, statSync, writeFileSync } from 'fs'
11
11
  import { dirname } from 'path'
12
12
  import { importMachineFile, machineDelete, machineGet, machineSet } from '../core/machine-db.ts'
13
+ import { lastWords } from '../problems/failure-words.ts'
13
14
 
14
15
  export type ProcStatus = 'down' | 'starting' | 'up' | 'crashed' | 'stopping'
15
16
 
@@ -328,7 +329,7 @@ export class Proc {
328
329
  this.crashes = [...this.crashes.filter((t) => now - t < CRASH_WINDOW_MS), now]
329
330
  if (this.crashes.length >= CRASH_LIMIT && this.spec.neverGiveUp !== true) {
330
331
  this.want = 'down'
331
- this.set('crashed', `exited ${this.crashes.length} times in ${Math.round(CRASH_WINDOW_MS / 60_000)} min, left down: see the log`)
332
+ this.set('crashed', `exited ${this.crashes.length} times in ${Math.round(CRASH_WINDOW_MS / 60_000)} min, left down: ${lastWords(this.spec.log) ?? 'it printed nothing'}`)
332
333
  } else {
333
334
  this.retryAt = now + BACKOFF_MS[Math.min(this.crashes.length - 1, BACKOFF_MS.length - 1)]!
334
335
  this.set('crashed', `${hung != null ? `${hung}, killed` : 'exited'}, restart in ${Math.round((this.retryAt - now) / 1000)}s`)
@@ -4,6 +4,7 @@
4
4
  // The constraint a reader breaks first: an answer holds names, states, sizes and dates only. A value, a token, a key
5
5
  // or a raw error of the vault never enters it: the list comes from the metadata calls and the keychain's attributes,
6
6
  // and every failure is said in our own words (the status code at most)
7
+ import { isTemplate } from '../secrets/name-template.ts'
7
8
  import { existsSync, readdirSync, statSync } from 'fs'
8
9
  import { homedir } from 'os'
9
10
  import { join } from 'path'
@@ -280,7 +281,7 @@ async function secretRows(d: VaultPageDeps, versions: Map<string, Meta> | null,
280
281
  const name = nameOfPath(path)
281
282
  if (name != null) byPath.set(path, name)
282
283
  }
283
- const exact = d.rows.filter((r) => !r.name.includes('<'))
284
+ const exact = d.rows.filter((r) => !isTemplate(r.name))
284
285
  const names = [...new Set([...exact.map((r) => r.name), ...byPath.values(), ...(kc ?? [])])].sort()
285
286
  const placed = new Map((await d.placeOf(d.rows, names)).map((p) => [p.name, p]))
286
287
  const words = d.who == null ? null : await d.who(names).catch(() => null)
@@ -0,0 +1,239 @@
1
+ // the terminals of another place on a page of the hq's Mac (wiki tools/shipkit/hub.md, A terminal of another place):
2
+ // the page keeps its ONE socket to this web, and asks a part of a place's terminals as it asks one of this Mac's, its
3
+ // ask naming the place. This web holds one hop a page, place and repo: a socket to that place's web through the
4
+ // door (`/door/_terminal/live`, its door key), on which the place's daemon opens a page of its own; each part the page
5
+ // asks of that place is asked there, its lines come back under the page's key, and his keys go to it by the part's id.
6
+ // The one constraint a reader breaks first: a place is another machine, and its frames are its word only. A line goes
7
+ // to the page under a key the page asked of THAT hop, a part id that place said hello with is that place's alone (a
8
+ // place that claims another's id is not heard), and nothing else a place says (a store's notice) reaches the page
9
+ import { DOOR_KEY_HEADER, doorKeyFor, wsUrl } from '../http/door-forward.ts'
10
+ import { HOP_PATH, type HopVerb } from '../http/hop-caller.ts'
11
+
12
+ /** where a hop goes: the place's web, its node (whose door key opens it), the repo by its key */
13
+ export type PlaceTarget = { base: string; node: string; repo: string }
14
+ export type PlaceRefused = { refused: string; status: number }
15
+ export type PlaceDeps = {
16
+ /** where a place's terminals of a repo (this machine's name of it) are, asked of the daemon */
17
+ target(node: string, repo: string): Promise<PlaceTarget | PlaceRefused>
18
+ /** a node's door key; absent: made from the hq's secret file (door-forward.ts doorKeyFor) */
19
+ keyFor?: (node: string) => string | null
20
+ /** how long a hop waits for its place's hello, then for an answer */
21
+ helloMs?: number
22
+ }
23
+
24
+ /** what a page's socket is to this web: what it is sent */
25
+ type Sock = { send(text: string): number }
26
+
27
+ type Hop = {
28
+ node: string
29
+ /** this machine's name of the repo, as the page's address says it */
30
+ repo: string
31
+ target: PlaceTarget
32
+ key: string
33
+ up: WebSocket
34
+ /** the id of the page the place's daemon opened for this hop, once it said hello */
35
+ page: string | null
36
+ ready: Promise<string | null>
37
+ /** the page's keys whose parts this hop carries, and the ids of those parts */
38
+ keys: Set<string>
39
+ parts: Set<string>
40
+ ended: boolean
41
+ }
42
+ type PageHops = { sock: Sock; hops: Map<string, Promise<Hop | PlaceRefused>>; keys: Map<string, Hop> }
43
+
44
+ const HELLO_MS = 5_000
45
+ /** a terminal's routes on a page of this machine: `/r/<repo>/api/terminal/<verb>` */
46
+ const ROUTE = /^\/r\/([^/]+)\/api\/terminal\/(open|watch|close|window|history)$/
47
+ const said = (text: string, status: number): Response => new Response(text, { status, headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' } })
48
+ const isObject = (v: unknown): v is Record<string, unknown> => v != null && typeof v === 'object' && !Array.isArray(v)
49
+
50
+ export function placeHops(d: PlaceDeps) {
51
+ const pages = new Map<string, PageHops>()
52
+ /** every part a place said hello with, by its id: whose page and which hop */
53
+ const parts = new Map<string, { page: string; hop: Hop }>()
54
+ const keyFor = d.keyFor ?? doorKeyFor
55
+ const wait = d.helloMs ?? HELLO_MS
56
+
57
+ /** a hop's socket ended: each part it carried is told gone, so its page asks it again (a new hop) */
58
+ function ended(pageId: string, hop: Hop, id: string): void {
59
+ if (hop.ended) return
60
+ hop.ended = true
61
+ const p = pages.get(pageId)
62
+ for (const k of hop.keys) {
63
+ if (p?.keys.get(k) !== hop) continue
64
+ p.keys.delete(k)
65
+ p.sock.send(JSON.stringify({ k, l: { t: 'gone' } }))
66
+ }
67
+ for (const part of hop.parts) if (parts.get(part)?.hop === hop) parts.delete(part)
68
+ if (p != null) void p.hops.get(id)?.then((h) => { if (h === hop) p.hops.delete(id) })
69
+ }
70
+
71
+ /** one frame of a place: the hello of its page, or a line of a part this page asked of it */
72
+ function heard(pageId: string, hop: Hop, text: string, hello: (id: string) => void): void {
73
+ let f: unknown
74
+ try {
75
+ f = JSON.parse(text)
76
+ } catch {
77
+ return
78
+ }
79
+ if (!isObject(f)) return
80
+ if (f.t === 'hello' && f.k == null) return void (typeof f.id === 'string' && f.id !== '' ? hello(f.id) : null)
81
+ const k = f.k
82
+ const l = f.l
83
+ const p = pages.get(pageId)
84
+ if (typeof k !== 'string' || !isObject(l) || typeof l.t !== 'string' || p == null || !hop.keys.has(k) || p.keys.get(k) !== hop) return
85
+ if (l.t === 'hello') {
86
+ if (typeof l.id !== 'string' || l.id === '') return
87
+ const owner = parts.get(l.id)
88
+ // an id another place said first is that place's: this one is not heard
89
+ if (owner != null && owner.hop !== hop) return
90
+ parts.set(l.id, { page: pageId, hop })
91
+ hop.parts.add(l.id)
92
+ }
93
+ p.sock.send(JSON.stringify({ k, l }))
94
+ }
95
+
96
+ async function open(pageId: string, node: string, repo: string): Promise<Hop | PlaceRefused> {
97
+ const t = await d.target(node, repo)
98
+ if ('refused' in t) return t
99
+ const key = keyFor(t.node)
100
+ if (key == null) return { refused: 'the hq has no door secret yet: sk hq proxy on, then a report of that machine', status: 404 }
101
+ const up = new WebSocket(`${wsUrl(t.base, `${HOP_PATH}live`)}?repo=${encodeURIComponent(t.repo)}`, { headers: { [DOOR_KEY_HEADER]: key } } as never)
102
+ let hello: (id: string | null) => void = () => {}
103
+ const hop: Hop = { node, repo, target: t, key, up, page: null, ready: new Promise((r) => { hello = r }), keys: new Set(), parts: new Set(), ended: false }
104
+ const id = `${node}\0${repo}`
105
+ const timer = setTimeout(() => (hello(null), up.close()), wait)
106
+ up.onmessage = (e) => heard(pageId, hop, String(e.data), (pid) => {
107
+ if (hop.page != null) return
108
+ hop.page = pid
109
+ clearTimeout(timer)
110
+ hello(pid)
111
+ })
112
+ up.onclose = () => (clearTimeout(timer), hello(null), ended(pageId, hop, id))
113
+ up.onerror = () => up.close()
114
+ return (await hop.ready) == null ? { refused: `${t.base.replace(/^https?:\/\//, '')} did not open its terminals to this hop (its switch machine-terminals, its key, its web: its own answer says why)`, status: 502 } : hop
115
+ }
116
+
117
+ /** the page's hop to that place for that repo, made at its first ask */
118
+ function hopOf(pageId: string, node: string, repo: string): Promise<Hop | PlaceRefused> {
119
+ const p = pages.get(pageId)!
120
+ const id = `${node}\0${repo}`
121
+ const held = p.hops.get(id)
122
+ if (held != null) return held.then((h) => ('refused' in h || h.ended ? (p.hops.get(id) === held && p.hops.delete(id), hopOf(pageId, node, repo)) : h))
123
+ const made = open(pageId, node, repo)
124
+ p.hops.set(id, made)
125
+ void made.then((h) => { if ('refused' in h && p.hops.get(id) === made) p.hops.delete(id) })
126
+ return made
127
+ }
128
+
129
+ /** a request of the hop to its place, as the place's web answers it */
130
+ async function ask(hop: Hop, verb: HopVerb, body: Record<string, unknown>): Promise<Response> {
131
+ try {
132
+ const r = await fetch(`${hop.target.base}${HOP_PATH}${verb}?repo=${encodeURIComponent(hop.target.repo)}`, { method: 'POST', headers: { 'content-type': 'application/json', [DOOR_KEY_HEADER]: hop.key }, body: JSON.stringify(body), signal: AbortSignal.timeout(wait) })
133
+ return new Response(r.body, { status: r.status, headers: { 'content-type': r.headers.get('content-type') ?? 'text/plain; charset=utf-8', 'cache-control': 'no-store' } })
134
+ } catch (e) {
135
+ return said(`the place does not answer (${(e as Error).message.slice(0, 160)})`, 502)
136
+ }
137
+ }
138
+
139
+ return {
140
+ /** a page's socket said its id (the daemon's hello): its parts of other places can be asked from now */
141
+ opened(pageId: string, sock: Sock): void {
142
+ if (!pages.has(pageId)) pages.set(pageId, { sock, hops: new Map(), keys: new Map() })
143
+ },
144
+ /** the page's socket ended: every hop of it ends */
145
+ closed(pageId: string): void {
146
+ const p = pages.get(pageId)
147
+ if (p == null) return
148
+ pages.delete(pageId)
149
+ for (const h of p.hops.values()) void h.then((x) => { if (!('refused' in x)) x.up.close() })
150
+ },
151
+ /** what the page said on its socket: true when it was for a part of another place (sent there, its fields
152
+ * alone), false for this machine's daemon */
153
+ fromPage(pageId: string, text: string): boolean {
154
+ if (parts.size === 0 || !text.startsWith('{')) return false
155
+ let b: unknown
156
+ try {
157
+ b = JSON.parse(text)
158
+ } catch {
159
+ return false
160
+ }
161
+ if (!isObject(b) || typeof b.id !== 'string') return false
162
+ const owner = parts.get(b.id)
163
+ if (owner == null) return false
164
+ // a part of another page takes nothing from this one
165
+ if (owner.page !== pageId || owner.hop.ended) return true
166
+ // the hq's secret read again: `sk hq proxy off` deleted it, or made another, and no key of before types
167
+ if (keyFor(owner.hop.node) !== owner.hop.key) {
168
+ owner.hop.up.close()
169
+ return true
170
+ }
171
+ const out: Record<string, unknown> = { id: b.id }
172
+ for (const k of ['data', 'cols', 'rows', 'hidden'] as const) if (b[k] !== undefined) out[k] = b[k]
173
+ if (owner.hop.up.readyState === WebSocket.OPEN) owner.hop.up.send(JSON.stringify(out))
174
+ return true
175
+ },
176
+ /** a terminal's request of a page that is a place's: an ask that names a place, an end by a key or an act by an
177
+ * id that is a place's part. null: this machine's daemon answers it. The gate on the owner's acts and the
178
+ * terminal's (terminal-guard.ts) ran before */
179
+ async route(req: Request, path: string): Promise<Response | null> {
180
+ const m = ROUTE.exec(path)
181
+ if (m == null || req.method !== 'POST') return null
182
+ const repo = decodeURIComponent(m[1]!)
183
+ const verb = m[2] as HopVerb
184
+ const b: unknown = await req.clone().json().catch(() => null)
185
+ if (!isObject(b)) return null
186
+ if (verb === 'open' || verb === 'watch') {
187
+ const place = b.place
188
+ if (typeof place !== 'string' || place === '') {
189
+ // a part of this Mac under a key a place held: that place's part ends there first, so one source
190
+ // a key says lines under it
191
+ const p = typeof b.page === 'string' ? pages.get(b.page) : undefined
192
+ const key = typeof b.key === 'string' ? b.key : ''
193
+ const held = p?.keys.get(key)
194
+ if (p != null && held != null) {
195
+ p.keys.delete(key)
196
+ held.keys.delete(key)
197
+ await ask(held, 'close', { page: held.page, key })
198
+ }
199
+ return null
200
+ }
201
+ if (place.length > 64) return said('not a place', 404)
202
+ const pageId = typeof b.page === 'string' ? b.page : ''
203
+ const key = typeof b.key === 'string' && b.key !== '' && b.key.length <= 64 ? b.key : null
204
+ const p = pages.get(pageId)
205
+ if (p == null) return said('no such socket of a page: it ended, open one again', 410)
206
+ if (key == null) return said('a part is asked under a key of the page', 400)
207
+ const hop = await hopOf(pageId, place, repo)
208
+ if ('refused' in hop) return said(`not found: ${hop.refused}`, hop.status === 502 ? 502 : 404)
209
+ // one place a key: a key asked of another hop before is ended there
210
+ const before = p.keys.get(key)
211
+ if (before != null && before !== hop) {
212
+ before.keys.delete(key)
213
+ void ask(before, 'close', { page: before.page, key })
214
+ }
215
+ p.keys.set(key, hop)
216
+ hop.keys.add(key)
217
+ const { place: _place, page: _page, ...rest } = b
218
+ const r = await ask(hop, verb, { ...rest, page: hop.page, key })
219
+ if (!r.ok && p.keys.get(key) === hop) (p.keys.delete(key), hop.keys.delete(key))
220
+ return r
221
+ }
222
+ if (verb === 'close') {
223
+ const p = typeof b.page === 'string' ? pages.get(b.page) : undefined
224
+ const key = typeof b.key === 'string' ? b.key : ''
225
+ const hop = p?.keys.get(key)
226
+ if (p == null || hop == null) return null
227
+ p.keys.delete(key)
228
+ hop.keys.delete(key)
229
+ await ask(hop, 'close', { page: hop.page, key })
230
+ return new Response(null, { status: 204, headers: { 'cache-control': 'no-store' } })
231
+ }
232
+ const owner = typeof b.id === 'string' ? parts.get(b.id) : undefined
233
+ if (owner == null) return null
234
+ // a part of a place is acted on under its own project's address alone
235
+ if (owner.hop.repo !== repo) return said("no such terminal: it is not this project's", 404)
236
+ return ask(owner.hop, verb, b)
237
+ },
238
+ }
239
+ }