rvlib-shipkit 2.31.0 → 2.32.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 (384) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/package.json +1 -1
  3. package/src/advisors/acts.ts +16 -15
  4. package/src/advisors/advice.ts +56 -102
  5. package/src/advisors/advisor-view.ts +98 -73
  6. package/src/advisors/app-graph.ts +1 -1
  7. package/src/advisors/app.ts +3 -11
  8. package/src/advisors/cf-api.ts +1 -1
  9. package/src/advisors/dir-bucket.ts +4 -3
  10. package/src/advisors/edge/api.ts +26 -198
  11. package/src/advisors/edge/bucket.ts +2 -2
  12. package/src/advisors/edge/handler.ts +13 -155
  13. package/src/advisors/edge/here.ts +5 -5
  14. package/src/advisors/edge/pages.ts +12 -9
  15. package/src/advisors/edge/shell.ts +6 -5
  16. package/src/advisors/edge/sign-in.ts +101 -36
  17. package/src/advisors/edge/status.ts +19 -6
  18. package/src/advisors/edge/types.ts +36 -60
  19. package/src/advisors/expose.ts +29 -29
  20. package/src/advisors/here.ts +12 -12
  21. package/src/advisors/invite-send.ts +79 -35
  22. package/src/advisors/invite.ts +31 -8
  23. package/src/advisors/job.ts +24 -16
  24. package/src/advisors/login.ts +40 -15
  25. package/src/advisors/owner-store.ts +46 -22
  26. package/src/advisors/photos.ts +3 -3
  27. package/src/advisors/project.ts +25 -23
  28. package/src/advisors/reach.ts +89 -0
  29. package/src/advisors/rights.ts +1 -1
  30. package/src/advisors/routes.ts +55 -74
  31. package/src/advisors/scan.ts +0 -4
  32. package/src/advisors/setup-run.ts +14 -14
  33. package/src/advisors/share-trace.ts +3 -3
  34. package/src/advisors/{door-probe.ts → sign-in-probe.ts} +7 -6
  35. package/src/advisors/speaks.ts +29 -0
  36. package/src/advisors/sync.ts +92 -182
  37. package/src/advisors/tunnel.ts +6 -5
  38. package/src/advisors/users-listen.ts +92 -0
  39. package/src/advisors/users-router.ts +257 -85
  40. package/src/advisors/users-store.ts +81 -0
  41. package/src/agent-time/blocked-scan.ts +181 -0
  42. package/src/agent-time/registry.ts +12 -5
  43. package/src/agent-time/store.ts +9 -109
  44. package/src/asks/ask-bar-fold.ts +2 -1
  45. package/src/asks/ask-close.ts +2 -1
  46. package/src/asks/ask-doc.ts +2 -1
  47. package/src/asks/ask-migrate.ts +3 -2
  48. package/src/asks/ask-steps-fold.ts +2 -1
  49. package/src/asks/ask-store.ts +4 -3
  50. package/src/check.ts +3 -43
  51. package/src/checks/SK001-package-json-shape.check.ts +4 -55
  52. package/src/checks/SK004-gitignore-policy.check.ts +24 -69
  53. package/src/checks/SK013-one-way-in-policy.check.ts +3 -7
  54. package/src/checks/SK017-vscode-hub-task.check.ts +4 -4
  55. package/src/checks/SK019-tests-run-in-units.check.ts +3 -14
  56. package/src/checks/SK020-self-spawning-check.check.ts +5 -7
  57. package/src/checks/SK035-public-clean.check.ts +1 -1
  58. package/src/checks/SK039-vscode-watch-generated.check.ts +1 -1
  59. package/src/checks/SK042-post-kinds.check.ts +5 -14
  60. package/src/checks/SK054-agent-allow-list.check.ts +5 -74
  61. package/src/checks/SK055-retired-config-keys.check.ts +45 -0
  62. package/src/cli/cmd_Advisors.ts +11 -45
  63. package/src/cli/cmd_Asks.ts +3 -10
  64. package/src/cli/cmd_Backup.ts +25 -127
  65. package/src/cli/cmd_BackupTargets.ts +1 -1
  66. package/src/cli/cmd_Checks.ts +0 -14
  67. package/src/cli/cmd_Db.ts +3 -82
  68. package/src/cli/cmd_Home.ts +4 -32
  69. package/src/cli/cmd_Hq.ts +0 -17
  70. package/src/cli/cmd_Releases.ts +57 -4
  71. package/src/cli/cmd_Review.ts +333 -354
  72. package/src/cli/cmd_SocialDrafts.ts +6 -13
  73. package/src/cli/cmd_ThreadSyncNeeds.ts +6 -2
  74. package/src/cli/cmd_Time.ts +1 -1
  75. package/src/cli/cmd_Trailer.ts +1 -1
  76. package/src/cli/inbox-hook-run.ts +5 -23
  77. package/src/cli/registry-heads.ts +5 -55
  78. package/src/cli/registry.ts +1 -5
  79. package/src/cli/review-here.ts +1 -1
  80. package/src/cli.ts +2 -2
  81. package/src/collections/collection-types.ts +1 -1
  82. package/src/collections/review.ts +5 -4
  83. package/src/core/agent-allow-policy.ts +32 -2
  84. package/src/core/agent-env.ts +8 -0
  85. package/src/core/allow-rows.ts +74 -0
  86. package/src/core/check-file-names.ts +19 -106
  87. package/src/core/footprint.ts +17 -13
  88. package/src/core/identities-root.ts +1 -4
  89. package/src/core/layout.ts +1 -2
  90. package/src/core/machine-db.ts +33 -208
  91. package/src/core/machine-layout.ts +14 -127
  92. package/src/core/mask-source.ts +60 -0
  93. package/src/core/memory-watch.ts +17 -14
  94. package/src/core/motherhome.ts +8 -35
  95. package/src/core/one-way-in-policy.ts +0 -3
  96. package/src/core/repo-walk.ts +0 -9
  97. package/src/core/retention.ts +1 -9
  98. package/src/core/retired-checks.ts +2 -0
  99. package/src/core/tmux-policy.ts +1 -1
  100. package/src/core/tree-watch.ts +2 -2
  101. package/src/core/when.ts +7 -45
  102. package/src/gate/discover-checks.ts +42 -32
  103. package/src/gate/gate-checks.ts +21 -131
  104. package/src/gate/pre-commit-discovery.ts +16 -25
  105. package/src/gate/run-check.ts +0 -4
  106. package/src/gate/run-fix.ts +5 -17
  107. package/src/gate/run-fixers.ts +6 -42
  108. package/src/home/app-sign.ts +2 -2
  109. package/src/home/backup-status.ts +52 -92
  110. package/src/home/backup-verdict.ts +2 -2
  111. package/src/home/daemon-jobs.ts +51 -95
  112. package/src/home/database-words.ts +1 -2
  113. package/src/home/databases.ts +9 -25
  114. package/src/home/home-launchd.ts +0 -6
  115. package/src/home/home-paths.ts +8 -4
  116. package/src/home/home-routes.ts +3 -10
  117. package/src/home/home-state.ts +2 -14
  118. package/src/home/inbox-shape.ts +14 -15
  119. package/src/home/inbox.ts +1 -1
  120. package/src/home/machine-repair.ts +102 -103
  121. package/src/home/resume.ts +1 -15
  122. package/src/home/run-daemon.ts +4 -11
  123. package/src/home/space-page.ts +3 -2
  124. package/src/home/supervise.ts +3 -7
  125. package/src/hooks/hook-config.ts +6 -7
  126. package/src/hooks/leak-guard.ts +1 -1
  127. package/src/hooks/run-hooks.ts +0 -5
  128. package/src/hq/daemon-db.ts +8 -8
  129. package/src/hq/door.ts +3 -16
  130. package/src/hq/hq-db.ts +4 -3
  131. package/src/hq/hq-local.ts +1 -2
  132. package/src/hq/hq-store.ts +0 -15
  133. package/src/hq/item-direct.ts +8 -10
  134. package/src/hq/item-fill.ts +37 -0
  135. package/src/hq/kinds/item-gone.ts +7 -10
  136. package/src/hq/kinds/item-msg.ts +12 -18
  137. package/src/hq/kinds/item.ts +13 -19
  138. package/src/hq/kinds/report.ts +3 -4
  139. package/src/hq/owner-switch.ts +3 -3
  140. package/src/hq/report.ts +5 -9
  141. package/src/hq/switch.ts +2 -11
  142. package/src/hq/thread-sync.ts +5 -17
  143. package/src/hq/{shapes-words.ts → threads-words.ts} +2 -12
  144. package/src/http/owner-word.ts +1 -1
  145. package/src/identities/machine.ts +16 -0
  146. package/src/init-repo.ts +0 -1
  147. package/src/ledger/check-stats.ts +6 -5
  148. package/src/ledger/db.ts +2 -4
  149. package/src/ledger/record-kept.ts +117 -48
  150. package/src/ledger/run-log.ts +21 -2
  151. package/src/ledger/slow-tests.ts +96 -0
  152. package/src/ledger/store.ts +3 -86
  153. package/src/ledger/suite-log.ts +8 -2
  154. package/src/media-store/backup/facts.ts +3 -37
  155. package/src/media-store/backup/keys.ts +1 -8
  156. package/src/media-store/backup/manifest.ts +6 -67
  157. package/src/media-store/backup/restore.ts +4 -13
  158. package/src/media-store/backup/retention.ts +13 -1
  159. package/src/media-store/backup/run.ts +6 -267
  160. package/src/media-store/backup/snapshot.ts +2 -38
  161. package/src/media-store/backup/sources.ts +3 -113
  162. package/src/media-store/backup/target-send.ts +5 -29
  163. package/src/media-store/db.ts +8 -7
  164. package/src/media-store/forget-one.ts +1 -1
  165. package/src/media-store/forget.ts +1 -80
  166. package/src/orchestrator/guards.ts +0 -1
  167. package/src/orchestrator/presence.ts +2 -2
  168. package/src/orchestrator/routes.ts +1 -1
  169. package/src/orchestrator/started.ts +0 -9
  170. package/src/orchestrator/talk-key.ts +3 -4
  171. package/src/orchestrator/unheard.ts +1 -1
  172. package/src/recordings/edit.ts +3 -3
  173. package/src/recordings/marks-draw.ts +17 -6
  174. package/src/recordings/marks.ts +120 -9
  175. package/src/reflections/reflections-queue.ts +3 -10
  176. package/src/release/notes.ts +1 -1
  177. package/src/release/public-clean.ts +66 -6
  178. package/src/release/run-bump.ts +11 -0
  179. package/src/release/run-release.ts +4 -0
  180. package/src/releases/from-thread.ts +3 -3
  181. package/src/releases/model.ts +186 -36
  182. package/src/releases/store.ts +13 -3
  183. package/src/releases/validate.ts +83 -0
  184. package/src/repo-config.ts +29 -64
  185. package/src/review/answer-kinds.ts +61 -4
  186. package/src/review/blocked-guard.ts +11 -0
  187. package/src/review/blocked-object.ts +298 -0
  188. package/src/review/cells.ts +116 -229
  189. package/src/review/close.ts +39 -1
  190. package/src/review/doc-save.ts +3 -2
  191. package/src/review/draft-item.ts +1 -1
  192. package/src/review/events.ts +3 -7
  193. package/src/review/expect.ts +23 -39
  194. package/src/review/format.ts +79 -46
  195. package/src/review/glyphs.ts +1 -0
  196. package/src/review/hand-over.ts +3 -3
  197. package/src/review/heard.ts +1 -1
  198. package/src/review/holds-sync.ts +2 -1
  199. package/src/review/inbox-hook.ts +2 -2
  200. package/src/review/inbox-read.ts +39 -33
  201. package/src/review/instruction-guards.ts +12 -0
  202. package/src/review/instructions.ts +0 -1
  203. package/src/review/item-db.ts +13 -43
  204. package/src/review/item-hq.ts +2 -2
  205. package/src/review/item-rows.ts +3 -14
  206. package/src/review/kind-catalog.ts +3 -1
  207. package/src/review/kinds.ts +18 -8
  208. package/src/review/live-view.ts +3 -0
  209. package/src/review/media-kind.ts +1 -1
  210. package/src/review/mentions.ts +1 -2
  211. package/src/review/model.ts +158 -114
  212. package/src/review/move.ts +149 -0
  213. package/src/review/need-threads.ts +3 -2
  214. package/src/review/object-card.ts +11 -0
  215. package/src/review/object-read.ts +6 -1
  216. package/src/review/one-block.ts +1 -1
  217. package/src/review/owner-read.ts +1 -1
  218. package/src/review/phone-push.ts +10 -9
  219. package/src/review/previews.ts +32 -4
  220. package/src/review/push.ts +2 -2
  221. package/src/review/recap.ts +129 -0
  222. package/src/review/referring.ts +6 -3
  223. package/src/review/reflection-object.ts +4 -3
  224. package/src/review/routes.ts +49 -19
  225. package/src/review/secret-route.ts +3 -2
  226. package/src/review/settle.ts +0 -6
  227. package/src/review/snooze.ts +5 -3
  228. package/src/review/speaker.ts +68 -0
  229. package/src/review/start-title.ts +19 -0
  230. package/src/review/store.ts +86 -59
  231. package/src/review/{wakes.ts → thread-events.ts} +92 -7
  232. package/src/review/thread-md.ts +35 -14
  233. package/src/review/thread-state.ts +798 -0
  234. package/src/review/threads.ts +29 -347
  235. package/src/review/traces.ts +104 -7
  236. package/src/review/trailer-item.ts +1 -1
  237. package/src/review/unit.ts +7 -9
  238. package/src/review/verdict-items.ts +12 -10
  239. package/src/review/view-layout.ts +25 -1
  240. package/src/review/watch-feed.ts +1 -2
  241. package/src/review/working-guards.ts +2 -3
  242. package/src/rules/untrack-generated.ts +1 -15
  243. package/src/secrets/lapse.ts +2 -1
  244. package/src/serve/hub-app/advisor-app.tsx +4 -4
  245. package/src/serve/hub-app/advisor-face.tsx +9 -3
  246. package/src/serve/hub-app/advisor-host.ts +27 -27
  247. package/src/serve/hub-app/advisors-model.ts +17 -8
  248. package/src/serve/hub-app/advisors-rights.tsx +1 -1
  249. package/src/serve/hub-app/advisors-st.ts +15 -14
  250. package/src/serve/hub-app/advisors-view.tsx +13 -11
  251. package/src/serve/hub-app/app-bridge.ts +23 -3
  252. package/src/serve/hub-app/asks-page.tsx +1 -1
  253. package/src/serve/hub-app/auto-text.tsx +71 -16
  254. package/src/serve/hub-app/check-view.tsx +0 -8
  255. package/src/serve/hub-app/controls.css +14 -3
  256. package/src/serve/hub-app/database-view.tsx +1 -2
  257. package/src/serve/hub-app/git-view.tsx +3 -1
  258. package/src/serve/hub-app/hub.css +12 -5
  259. package/src/serve/hub-app/icons.tsx +1 -1
  260. package/src/serve/hub-app/inbox-view.tsx +1 -2
  261. package/src/serve/hub-app/live-sources.ts +2 -2
  262. package/src/serve/hub-app/main-panel.tsx +2 -1
  263. package/src/serve/hub-app/panel-repo.ts +0 -9
  264. package/src/serve/hub-app/pic.tsx +29 -12
  265. package/src/serve/hub-app/polled.ts +16 -2
  266. package/src/serve/hub-app/recordings-st.ts +23 -2
  267. package/src/serve/hub-app/recordings-view.tsx +68 -10
  268. package/src/serve/hub-app/ref-pill.ts +1 -1
  269. package/src/serve/hub-app/repo-st.ts +1 -2
  270. package/src/serve/hub-app/review/advisor-add.tsx +1 -1
  271. package/src/serve/hub-app/review/advisor-invite.tsx +1 -1
  272. package/src/serve/hub-app/review/draft-body.tsx +2 -2
  273. package/src/serve/hub-app/review/heard-line.tsx +1 -1
  274. package/src/serve/hub-app/review/instructions-view.tsx +1 -8
  275. package/src/serve/hub-app/review/kind-states.tsx +14 -9
  276. package/src/serve/hub-app/review/kit.tsx +4 -11
  277. package/src/serve/hub-app/review/lane-bar.tsx +3 -3
  278. package/src/serve/hub-app/review/lightbox.tsx +15 -11
  279. package/src/serve/hub-app/review/line-window.ts +4 -1
  280. package/src/serve/hub-app/review/live-bar-st.ts +2 -2
  281. package/src/serve/hub-app/review/live-view.tsx +57 -1
  282. package/src/serve/hub-app/review/object-panel.tsx +20 -8
  283. package/src/serve/hub-app/review/question-views.tsx +181 -54
  284. package/src/serve/hub-app/review/recap-bar.tsx +40 -0
  285. package/src/serve/hub-app/review/request-cell.tsx +48 -0
  286. package/src/serve/hub-app/review/review-cells.tsx +154 -96
  287. package/src/serve/hub-app/review/review-host.ts +2 -2
  288. package/src/serve/hub-app/review/review-kit.ts +17 -11
  289. package/src/serve/hub-app/review/review-list.tsx +23 -31
  290. package/src/serve/hub-app/review/review-st.ts +30 -40
  291. package/src/serve/hub-app/review/review-thread.tsx +139 -85
  292. package/src/serve/hub-app/review/review-views.tsx +124 -68
  293. package/src/serve/hub-app/review/share-lines.tsx +4 -4
  294. package/src/serve/hub-app/review/start-st.ts +2 -5
  295. package/src/serve/hub-app/review/superseded-runs.ts +4 -3
  296. package/src/serve/hub-app/review/thread-close.tsx +10 -7
  297. package/src/serve/hub-app/review/thread-st.ts +372 -201
  298. package/src/serve/hub-app/review/tone-bar.tsx +126 -0
  299. package/src/serve/hub-app/review/tones.ts +35 -0
  300. package/src/serve/hub-app/review/trailer-body.tsx +2 -2
  301. package/src/serve/hub-app/review/trailer-st.ts +3 -2
  302. package/src/serve/hub-app/review/trailer-voices-st.ts +3 -2
  303. package/src/serve/hub-app/review.css +180 -106
  304. package/src/serve/hub-app/search-view.tsx +1 -1
  305. package/src/serve/hub-app/social/social-model.ts +0 -4
  306. package/src/serve/hub-app/source-acts.ts +2 -1
  307. package/src/serve/hub-app/stores/stores-page.tsx +2 -2
  308. package/src/serve/hub-app/terminal-sources.tsx +2 -1
  309. package/src/serve/hub-app/thread-row.tsx +3 -4
  310. package/src/serve/hub-app/tree-build.ts +0 -4
  311. package/src/serve/hub-app/urls-view.tsx +2 -1
  312. package/src/serve/hub-app/view-layout.css +13 -3
  313. package/src/serve/hub-app/wikis-view.tsx +5 -2
  314. package/src/serve/hub-runtime.ts +7 -37
  315. package/src/serve/project-gutter-route.ts +6 -2
  316. package/src/serve/read-thread.ts +20 -2
  317. package/src/serve/read-worker.ts +9 -1
  318. package/src/serve/record-pages.ts +46 -0
  319. package/src/serve/serve-hub.ts +2 -2
  320. package/src/serve/terminal-host.ts +1 -1
  321. package/src/serve/terminal-route.ts +1 -3
  322. package/src/serve/tracked-watch.ts +1 -3
  323. package/src/setup-house.ts +2 -2
  324. package/src/shipkit-files.ts +1 -1
  325. package/src/shipkit.ts +1 -6
  326. package/src/shot/film-box.ts +0 -20
  327. package/src/social/drafts.ts +1 -1
  328. package/src/social/kinds.ts +6 -29
  329. package/src/social/load.ts +2 -2
  330. package/src/social/post-object.ts +3 -2
  331. package/src/social/release-stage.ts +1 -1
  332. package/src/social/stage.ts +2 -2
  333. package/src/stores/model.ts +4 -0
  334. package/src/stores/routes.ts +11 -3
  335. package/src/suite/judge-suites.ts +58 -0
  336. package/src/suite/red-alone.ts +54 -18
  337. package/src/suite/runner-shapes.ts +2 -2
  338. package/src/suite/suite-cli.ts +67 -14
  339. package/src/suite/test-units.ts +2 -1
  340. package/src/urls/fill.ts +1 -1
  341. package/src/urls/places.ts +1 -2
  342. package/src/vault/vault-config.ts +2 -2
  343. package/src/vault/vault-init.ts +1 -5
  344. package/src/wiki/graph-page.ts +14 -2
  345. package/src/advisors/copy-truth.ts +0 -49
  346. package/src/advisors/door-child.ts +0 -112
  347. package/src/advisors/door-serve.ts +0 -52
  348. package/src/advisors/door.ts +0 -118
  349. package/src/checks/SK016-legacy-check-shapes.check.ts +0 -189
  350. package/src/checks/SK029-explicit-check-files.check.ts +0 -112
  351. package/src/checks/SK048-one-local-file.check.ts +0 -36
  352. package/src/core/config-rewrite.ts +0 -111
  353. package/src/core/daemon-port.ts +0 -10
  354. package/src/core/legacy-shapes.ts +0 -263
  355. package/src/core/migrate-layout.ts +0 -638
  356. package/src/core/port-check-cli.ts +0 -52
  357. package/src/core/port-check-file.ts +0 -295
  358. package/src/core/port-check-files.ts +0 -31
  359. package/src/gate/discover-legacy-checks.ts +0 -26
  360. package/src/home/home-move.ts +0 -527
  361. package/src/home/machine-fold.ts +0 -810
  362. package/src/hq/item-shapes.ts +0 -54
  363. package/src/hq/kinds/items-read.ts +0 -4
  364. package/src/media-store/backup/daemon.ts +0 -220
  365. package/src/media-store/backup/kept.ts +0 -241
  366. package/src/media-store/backup/prune.ts +0 -359
  367. package/src/media-store/backup/secret.ts +0 -88
  368. package/src/media-store/backup/ssh-space.ts +0 -202
  369. package/src/media-store/backup/watch.ts +0 -117
  370. package/src/review/band.ts +0 -182
  371. package/src/review/folders.ts +0 -216
  372. package/src/review/hook-ask.ts +0 -58
  373. package/src/review/role.ts +0 -48
  374. package/src/review/thread-fold.ts +0 -64
  375. package/src/review/wait.ts +0 -91
  376. package/src/rules/rule.ts +0 -43
  377. package/src/serve/hook-thread.ts +0 -37
  378. package/src/serve/hook-work.ts +0 -92
  379. package/src/serve/hook-worker.ts +0 -57
  380. package/src/serve/hub-app/review/dock.tsx +0 -147
  381. package/src/serve/hub-app/review/faces.tsx +0 -18
  382. package/src/serve/hub-app/review/item-verdict.tsx +0 -112
  383. package/src/serve/hub-app/review/review-board.tsx +0 -48
  384. /package/src/{scaffold → core}/jsonc-spans.ts +0 -0
@@ -1,33 +1,32 @@
1
- // the Mac's side of the door (wiki tools/shipkit/advisors.md): every live share projected, scanned and written to the
2
- // door's folder with the images he confirmed, re-encoded; the list of live shares and logins written FIRST and the
3
- // copies of ended ones deleted after; the advice pulled
4
- import { createHash, randomBytes } from 'node:crypto'
1
+ // what a person reads of a share, and the owner's pass (wiki tools/shipkit/advisors.md): `prepare` projects one live
2
+ // share, scanned, through the hub's own builders, for the users' port to answer at the request; the pass keeps the
3
+ // owner's store true about the people: who may sign in, each share's reach and what it masks, where each reader
4
+ // stopped, the advice the owner's rights make direct since, the sweeps of the port's folder. A thread a person reads is
5
+ // prepared at their request, never kept from a pass
6
+ import { createHash } from 'node:crypto'
5
7
  import { existsSync, readFileSync, statSync } from 'node:fs'
6
8
  import { HOUSE_LAYOUT } from '../core/house-layout.ts'
7
9
  import { identitiesFile } from '../core/identities-root.ts'
8
10
  import { imageFile, readAll, storeDir, threadFile } from '../review/store.ts'
9
11
  import { isGallery, verdictOf, type ReviewItem } from '../review/model.ts'
10
12
  import type { ReplyCell } from '../review/cells.ts'
11
- import type { Turn } from '../review/band.ts'
12
13
  import { namedFiles } from '../review/file-tags.ts'
13
- import { membersOf, statusOf, threadOfAddress, turnOf, type Thread } from '../review/threads.ts'
14
+ import { membersOf, threadOfAddress, type Thread } from '../review/threads.ts'
14
15
  import { cursorOf } from '../review/traces.ts'
15
16
  import { advisorThread, personReads, storeNames, type AdvisorThread } from './advisor-view.ts'
16
- import { truthfulCopy } from './copy-truth.ts'
17
- import type { AppBundle } from './app.ts'
18
17
  import { ADVISOR_WHO } from '../serve/hub-app/review/review-host.ts'
19
18
  import { getJson, type Bucket, type Bytes } from './edge/bucket.ts'
20
- import { KEYS, type ServedProject, type ServedShare, type ShareManifest, type SharesFile } from './edge/types.ts'
21
- import { importAdvice } from './advice.ts'
19
+ import { KEYS, type ServedProject, type ShareManifest } from './edge/types.ts'
20
+ import { deliverPending, sweepUploads } from './advice.ts'
22
21
  import { shareAllOfAccess } from './acts.ts'
23
22
  import { opaqueItem, opaqueMessage, picturesOf, projectItems, questionHash, type Masked } from './project.ts'
24
23
  import { maskHits, privateWordsOf } from './scan.ts'
25
- import { photoBytes } from './photos.ts'
26
24
  import { rightsOf } from './rights.ts'
27
25
  import { keepLogins } from './login.ts'
28
- import { identityOfRoot } from './door.ts'
26
+ import { identityOfRoot } from './speaks.ts'
29
27
  import { ownerNameOf } from './owner-name.ts'
30
28
  import { displayOf, isLive, startPlacesOf, readState, servedShares, withState, type OwnerState, type Share, type ShareRead } from './owner-store.ts'
29
+ import { threadState } from '../review/thread-state.ts'
31
30
 
32
31
  /** a picture as the advisor gets it: re-encoded, no metadata (EXIF, PNG text) survives */
33
32
  export type Encode = (path: string) => Promise<Bytes>
@@ -47,23 +46,21 @@ export function privateWords(house: string | null): string[] {
47
46
  return existsSync(f) ? privateWordsOf(readFileSync(f, 'utf8')) : []
48
47
  }
49
48
 
50
- /** what one live share shows the advisor now, as the Mac reads it: the copy (the hub's own view and row, its
51
- * manifest), every picture of the thread served by its re-encoded name */
49
+ /** what one live share shows the advisor now: the hub's own view and row, the manifest the port checks requests
50
+ * against, every picture of the thread by the hash of its raw bytes */
52
51
  export interface Prepared {
53
52
  /** the project's name as the advisor reads it, scanned */
54
53
  project: string
55
- /** his name as this share's project reads it, scanned */
54
+ /** the owner's name as this share's project reads it, scanned */
56
55
  owner: string
57
- /** the advisor's copy: null when nothing of the thread leaves */
58
- copy: AdvisorThread | null
56
+ /** what the advisor reads, the hub's view and row: null when nothing of the thread leaves */
57
+ theirs: AdvisorThread | null
59
58
  manifest: ShareManifest | null
60
59
  /** the entries that went out with strings masked */
61
60
  masked: Masked[]
62
- /** each served name and its file */
63
- served: { sha: string; path: string }[]
64
- /** each image of the projection, raw content hash, file: the preview draws all of them */
61
+ /** each image of the projection, raw content hash, file: the port encodes one at its request */
65
62
  all: { ref: string; sha: string; path: string }[]
66
- /** the time of his newest word in the thread: a read up to it is « seen by <name> » in his hub */
63
+ /** the time of the owner's newest word in the thread: a read up to it is « seen by <name> » in the owner's hub */
67
64
  his: string | null
68
65
  /** the thread's versions and how many the person sees */
69
66
  parts: { versions: number; shown: number }
@@ -71,8 +68,8 @@ export interface Prepared {
71
68
 
72
69
  const ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/
73
70
 
74
- /** the door's read cursor of a share (edge/api.ts writes it, `upTo` one of the copy's own cell times, which the Mac's
75
- * clock wrote): a small object of two times; anything else is no read */
71
+ /** a person's read cursor of a share (users-router.ts writes it, `upTo` one of the view's own cell times): a small
72
+ * object of two times; anything else is no read */
76
73
  export function readOf(bytes: Bytes | null, his: string | null): ShareRead | null {
77
74
  if (bytes === null || bytes.byteLength > 512) return null
78
75
  let v: unknown
@@ -89,9 +86,6 @@ export function readOf(bytes: Bytes | null, his: string | null): ShareRead | nul
89
86
  return { at, upTo, seen: his === null || upTo >= his }
90
87
  }
91
88
 
92
- /** the re-encoded bytes of this run, by served name: put once each */
93
- const encoded = new Map<string, Bytes>()
94
-
95
89
  const resolverOf =
96
90
  (root: string) =>
97
91
  (itemId: string, name: string, of: 'view' | 'message'): string | null =>
@@ -99,17 +93,17 @@ const resolverOf =
99
93
 
100
94
  const ADVICE_WORDS: Record<string, string> = { approve: 'I approve', change: "I'd change this", words: '' }
101
95
 
102
- /** the cell of a person's own advice in their copy */
96
+ /** the cell of a person's own advice in their view */
103
97
  const adviceCell = (head: string, advice: string): string => `${head}/m${sha256(`advice|${advice}`).slice(0, 12)}`
104
98
 
105
- /** each word the person's rights let in at once, as the copy names it (opaqueMessage), and its cell there: an agent's
99
+ /** each word the person's rights let in at once, as their view names it (opaqueMessage), and its cell there: an agent's
106
100
  * read of it links that cell. The thread's word is the one its advice wrote, at the moment the advice says it was done */
107
101
  function ownCells(s: OwnerState, x: Share, thread: Thread, head: string): Map<string, string> {
108
102
  const out = new Map<string, string>()
109
103
  const direct = s.advice.filter((a) => a.share === x.id && a.state === 'direct' && a.done !== undefined)
110
104
  for (const y of membersOf(thread))
111
105
  for (const m of y.thread) {
112
- // their verdict is a cell of the copy itself, never an advice's
106
+ // their verdict is a cell of the view itself, never an advice's
113
107
  if (m.who !== 'player' || m.advisor?.id !== x.advisor || m.verdict !== undefined) continue
114
108
  const a = direct.find((z) => z.done === m.at)
115
109
  if (a !== undefined) out.set(opaqueMessage(x.id, m.id), adviceCell(head, a.id))
@@ -117,11 +111,11 @@ function ownCells(s: OwnerState, x: Share, thread: Thread, head: string): Map<st
117
111
  return out
118
112
  }
119
113
 
120
- /** the person's own advice on this share: drawn in their copy as their words, « waits for <owner> » while it waits.
121
- * One their rights made direct is in the thread as a `player` word, which the projection never copies (another
122
- * person's word stays theirs), so their copy draws it from here, with no wait */
114
+ /** the person's own advice on this share: drawn in their view as their words, « waits for <owner> » while it waits.
115
+ * One their rights made direct is in the thread as a `player` word, which the projection never carries (another
116
+ * person's word stays theirs), so their view draws it from here, with no wait */
123
117
  function pendingCells(s: OwnerState, x: Share, thread: Thread, view: AdvisorThread['view'], owner: string): AdvisorThread['view']['cells'] {
124
- // a direct verdict that is the version's verdict is in the copy already (project.ts); one of the older shape (a word)
118
+ // a direct verdict that is the version's verdict is in the view already (project.ts); one of the older shape (a word)
125
119
  // is drawn from here
126
120
  const verdicts = new Set(membersOf(thread).flatMap((y) => y.thread.filter((m) => m.who === 'player' && m.advisor?.id === x.advisor && m.verdict !== undefined).map((m) => m.at)))
127
121
  // a pick is drawn on its question's cell (markVotes), never as words of its own
@@ -135,7 +129,7 @@ function pendingCells(s: OwnerState, x: Share, thread: Thread, view: AdvisorThre
135
129
  }
136
130
 
137
131
  /** the words a person started this thread with, opened at once by their rights: in the thread as a `player` word, which
138
- * the projection never copies, so their copy draws them from their proposal, as its first message */
132
+ * the projection never carries, so their view draws them from their proposal, as its first message */
139
133
  function proposedCells(s: OwnerState, x: Share, thread: Thread, view: AdvisorThread['view']): AdvisorThread['view']['cells'] {
140
134
  const heads = new Set(membersOf(thread).map((y) => y.item.id))
141
135
  return s.proposals.flatMap((p) => {
@@ -145,12 +139,12 @@ function proposedCells(s: OwnerState, x: Share, thread: Thread, view: AdvisorThr
145
139
  })
146
140
  }
147
141
 
148
- /** the person's newest pick on each question, on the question's cell of their copy: their vote while it waits for his
149
- * OK. A direct pick that answered is in the copy already, and wins */
142
+ /** the person's newest pick on each question, on the question's cell of their view: their vote while it waits for the
143
+ * owner's OK. A direct pick that answered is in the view already, and wins */
150
144
  function markVotes(s: OwnerState, x: Share, view: AdvisorThread['view']): void {
151
145
  const newest = new Map<string, { option: number; at: string }>()
152
146
  for (const a of s.advice) {
153
- // a direct one of the older shape (a word with no answer on it) is theirs too: the copy holds no answer for it
147
+ // a direct one of the older shape (a word with no answer on it) is theirs too: the view holds no answer for it
154
148
  if (a.share !== x.id || a.kind !== 'pick' || (a.state !== 'pending' && a.state !== 'direct') || a.item === undefined || a.message === undefined || a.option === undefined) continue
155
149
  const cell = `${opaqueItem(x.id, a.item)}/${opaqueMessage(x.id, a.message)}`
156
150
  if ((newest.get(cell)?.at ?? '') <= a.at) newest.set(cell, { option: a.option, at: a.at })
@@ -174,11 +168,9 @@ function rawSha(path: string): string {
174
168
  return sha
175
169
  }
176
170
 
177
- /** a share projected and its pictures served: a thread he shared goes whole, its pictures with it. `names: 'raw'`:
178
- * each picture named by the hash of its raw bytes and encoded by the reader on request (his preview, the users'
179
- * port), never here */
180
- export async function prepare(s: OwnerState, x: Share, o: { words: string[]; encode: Encode; now: Date; preview?: boolean; names?: 'raw' }): Promise<Prepared | null> {
181
- const raw = o.preview === true || o.names === 'raw'
171
+ /** a share projected and its pictures named: a thread the owner shared goes whole, its pictures with it, each named by
172
+ * the hash of its raw bytes and encoded by the reader on request (the owner's preview, the users' port), never here */
173
+ export async function prepare(s: OwnerState, x: Share, o: { words: string[]; now: Date }): Promise<Prepared | null> {
182
174
  const a = s.advisors.find((y) => y.id === x.advisor)
183
175
  if (a === undefined) return null
184
176
  const stored = readAll(storeDir(x.root)).items
@@ -190,10 +182,9 @@ export async function prepare(s: OwnerState, x: Share, o: { words: string[]; enc
190
182
  const name = ownerNameOf(s, { project: x.repo, identity: await identityOfRoot(x.root) })
191
183
  const owner = maskHits(name, scan).length === 0 ? name : 'the owner'
192
184
  const resolve = resolverOf(x.root)
193
- // every picture once, re-encoded; his preview draws each raw
194
- const served: Prepared['served'] = []
185
+ // every picture once, named by the hash of its raw bytes; the port encodes it at the request
195
186
  const all: Prepared['all'] = []
196
- const byPath = new Map<string, { raw: string; served: string | null } | null>()
187
+ const byPath = new Map<string, string | null>()
197
188
  for (const pic of picturesOf(thread)) {
198
189
  const path = resolve(pic.itemId, pic.name, pic.of)
199
190
  if (path === null || byPath.has(path)) continue
@@ -203,61 +194,46 @@ export async function prepare(s: OwnerState, x: Share, o: { words: string[]; enc
203
194
  }
204
195
  const rawHash = rawSha(path)
205
196
  all.push({ ref: path, sha: rawHash, path })
206
- if (raw) {
207
- byPath.set(path, { raw: rawHash, served: null })
208
- continue
209
- }
210
- const bytes = await o.encode(path)
211
- const sha = sha256(bytes)
212
- if (!served.some((y) => y.sha === sha)) served.push({ sha, path })
213
- byPath.set(path, { raw: rawHash, served: sha })
214
- encoded.set(sha, bytes)
197
+ byPath.set(path, rawHash)
215
198
  }
216
- /** a picture's name in the copy: the served one, or by its raw hash where the reader encodes it */
199
+ /** a picture's name in what the person reads: the hash of its raw bytes */
217
200
  const nameOf = (path: string | null): string | null => {
218
201
  const b = path === null ? null : (byPath.get(path) ?? null)
219
- if (b === null) return null
220
- return raw ? `${b.raw}.webp` : b.served === null ? null : `${b.served}.webp`
202
+ return b === null ? null : `${b}.webp`
221
203
  }
222
204
  const answers = rightsOf(s.rights, { person: x.advisor, project: x.repo, thread: x.address }).answers
223
205
  const items = projectItems({ thread, share: x.id, advisor: x.advisor, answers, scan, include: x.include, picture: (itemId, name, of) => nameOf(resolve(itemId, name, of)) })
224
- const copy = advisorThread(items, { scan, now: o.now, owner, cursor: cursorOf(thread, o.now), names: storeNames(thread) })
225
- if (copy !== null) {
226
- truthfulCopy(copy, items, { turn: turnOf(thread, o.now), status: statusOf(thread.head, stored) })
227
- // their words at their own time among the thread's cells, as his hub draws them (a stable sort keeps the
206
+ const theirs = advisorThread(items, { scan, now: o.now, owner, cursor: cursorOf(thread, o.now), names: storeNames(thread), real: threadState(thread, o.now), deferred: x.deferred === true })
207
+ if (theirs !== null) {
208
+ // their words at their own time among the thread's cells, as the owner's hub draws them (a stable sort keeps the
228
209
  // builders' order of cells of one time)
229
- copy.view.cells = [...copy.view.cells, ...proposedCells(s, x, thread, copy.view), ...pendingCells(s, x, thread, copy.view, owner)].sort((p, q) => p.at.localeCompare(q.at))
230
- markVotes(s, x, copy.view)
231
- personReads(copy.view, items.items, { owner, own: ownCells(s, x, thread, copy.view.head) })
232
- // the turn as the advisor reads it: a thread deferred to them and set aside on his side is theirs; his turn, or a
233
- // thread he set aside himself, waits for him (the page says « waits for <owner> », ReviewSt.bandWord)
234
- const turnFor = (t: Turn): Turn => (x.deferred && t === 'aside' ? 'yours' : t === 'yours' || t === 'aside' ? 'aside' : t)
235
- copy.view.turn = turnFor(copy.view.turn)
236
- copy.row.turn = turnFor(copy.row.turn)
210
+ theirs.view.cells = [...theirs.view.cells, ...proposedCells(s, x, thread, theirs.view), ...pendingCells(s, x, thread, theirs.view, owner)].sort((p, q) => p.at.localeCompare(q.at))
211
+ markVotes(s, x, theirs.view)
212
+ personReads(theirs.view, items.items, { owner, own: ownCells(s, x, thread, theirs.view.head) })
237
213
  }
238
- const manifest = copy === null ? null : manifestOf(copy, thread, x.id, x.advisor)
214
+ const manifest = theirs === null ? null : manifestOf(theirs, thread, x.id, x.advisor)
239
215
  const his = membersOf(thread).flatMap((y) => y.thread.filter((m) => m.who === 'owner' && m.op !== 'seen').map((m) => m.at)).sort().at(-1) ?? null
240
- return { project, owner, copy, manifest, masked: items.masked, served, all, his, parts: { versions: items.versions, shown: items.shown } }
216
+ return { project, owner, theirs, manifest, masked: items.masked, all, his, parts: { versions: items.versions, shown: items.shown } }
241
217
  }
242
218
 
243
- /** what the door checks a share's reads and writes against: the copy's ids and pictures, each version that waits with
219
+ /** what the users' port checks a share's reads and writes against: the view's ids and pictures, each version that waits with
244
220
  * its count of views in the store, each choice question open to `advisor` (open, or answered by their own pick alone,
245
221
  * which they may change) with the hash of its words in the store */
246
- export function manifestOf(copy: AdvisorThread, thread: Thread, share: string, advisor?: string): ShareManifest {
222
+ export function manifestOf(read: AdvisorThread, thread: Thread, share: string, advisor?: string): ShareManifest {
247
223
  const real = new Map<string, ReviewItem>()
248
224
  for (const x of membersOf(thread)) real.set(opaqueItem(share, x.item.id), x)
249
- const ids = [copy.view.head, ...copy.view.members, ...copy.view.cells.map((c) => c.id)]
225
+ const ids = [read.view.head, ...read.view.members, ...read.view.cells.map((c) => c.id)]
250
226
  const images = new Set<string>()
251
227
  const judge: ShareManifest['judge'] = []
252
228
  const questions: ShareManifest['questions'] = []
253
- for (const c of copy.view.cells) {
229
+ for (const c of read.view.cells) {
254
230
  if (c.kind === 'version') {
255
231
  for (const v of c.item.views) for (const f of isGallery(v) ? v.gallery.map((g) => g.file) : 'image' in v.files ? [v.files.image] : 'before' in v.files ? [v.files.before, v.files.after] : []) images.add(f.slice(0, 64))
256
232
  const x = real.get(c.item.id)
257
233
  // waits, or holds their own direct verdict alone, which they may change
258
234
  const v = x === undefined ? null : verdictOf(x)
259
235
  const theirs = v !== null && advisor !== undefined && x!.thread.some((m) => m.id === v.id && m.who === 'player' && m.advisor?.id === advisor)
260
- if (x !== undefined && c.id === copy.view.head && (copy.view.waits || theirs)) judge.push({ item: c.item.id, version: x.item.views.length })
236
+ if (x !== undefined && c.id === read.view.head && (read.view.state.headWaits || theirs)) judge.push({ item: c.item.id, version: x.item.views.length })
261
237
  }
262
238
  if (c.kind === 'reply') {
263
239
  if (c.image !== undefined) images.add(c.image.slice(0, 64))
@@ -272,10 +248,11 @@ export function manifestOf(copy: AdvisorThread, thread: Thread, share: string, a
272
248
  }
273
249
  }
274
250
  }
275
- return { v: 1, head: copy.view.head, ids: [...new Set(ids)], images: [...images], judge, questions }
251
+ return { v: 1, head: read.view.head, ids: [...new Set(ids)], images: [...images], judge, questions }
276
252
  }
277
253
 
278
- /** where each person may start a thread (startPlacesOf), by the door's id; its names scanned like any text that leaves */
254
+ /** where each person may start a thread (startPlacesOf), by the id the advisors page names it by; its names scanned
255
+ * like any text that leaves */
279
256
  export async function projectsOf(s: OwnerState, words: string[], now = new Date()): Promise<Record<string, ServedProject>> {
280
257
  const out: Record<string, ServedProject> = {}
281
258
  for (const x of startPlacesOf(s, now)) {
@@ -290,132 +267,75 @@ export async function projectsOf(s: OwnerState, words: string[], now = new Date(
290
267
  }
291
268
 
292
269
  export interface SyncReport {
293
- pushed: number
294
- removed: number
270
+ /** the shares a person reads now */
271
+ reached: number
272
+ /** the advice his rights made direct since and that landed */
295
273
  advice: number
296
274
  errors: string[]
297
275
  }
298
276
 
299
- /** one pass: what leaves, what ends, what came back. A failed push is said on its share (`reach`) and in the report */
300
- export async function syncOnce(dir: string, o: { bucket: Bucket; words: string[]; encode?: Encode; now?: Date; app?: () => Promise<AppBundle>; again?: false }): Promise<SyncReport> {
277
+ /** the owner's pass over the users' port's folder `bucket` (users-store.ts): who may sign in kept equal to the grants,
278
+ * each live share prepared once for its reach and what it masks, where each reader stopped pulled into his store, the
279
+ * advice his rights make direct since delivered, the files staged and waiting swept, the sessions and passwords of
280
+ * people no longer listed ended. A failed share is said on it (`reach`) and in the report */
281
+ export async function syncOnce(dir: string, o: { bucket: Bucket; words: string[]; now?: Date }): Promise<SyncReport> {
301
282
  const now = o.now ?? new Date()
302
- const encode = o.encode ?? sharpWebp
303
- const report: SyncReport = { pushed: 0, removed: 0, advice: 0, errors: [] }
304
- // a project's access that shows every thread shares each new one before the push
283
+ const report: SyncReport = { reached: 0, advice: 0, errors: [] }
284
+ // a project's access that shows every thread shares each new one
305
285
  shareAllOfAccess(dir, now)
306
- // who may sign in: each person with a live grant, and whether the door says their code set a password
286
+ // who may sign in: each person with a live grant, and whether the port says their code set a password
307
287
  const used = new Map<string, number>()
308
288
  for (const a of readState(dir).advisors) {
309
- if (a.login === undefined || a.login.used === true) continue
289
+ if (a.login === undefined || (a.login.used === true && a.login.reset === undefined)) continue
310
290
  const kept = await getJson<{ gen?: unknown }>(o.bucket, KEYS.password(sha256(a.email))).catch(() => null)
311
291
  if (typeof kept?.gen === 'number') used.set(a.email, kept.gen)
312
292
  }
313
293
  const logins = withState(dir, (st) => keepLogins(st, now, used))
314
294
  const s = readState(dir)
315
- // the door opens what this writes and nothing else: the one answer to « who can open a thread » (owner-store.ts)
316
295
  const live = servedShares(s, now)
317
- const results = new Map<string, { prepared: Prepared | null; pushed?: string; read?: ShareRead | null; reach: Share['reach'] }>()
318
- const fallback = ownerNameOf(s)
319
- const shares: SharesFile = { v: 1, shares: {}, projects: await projectsOf(s, o.words, now), owner: maskHits(fallback, { advisorEmail: '', words: o.words }).length === 0 ? fallback : 'the owner', logins }
320
- const media = new Set<string>()
296
+ const results = new Map<string, { prepared: Prepared | null; read?: ShareRead | null; reach: Share['reach'] }>()
321
297
  for (const x of live) {
322
298
  try {
323
- const p = await prepare(s, x, { words: o.words, encode, now })
299
+ const p = await prepare(s, x, { words: o.words, now })
324
300
  if (p === null) {
325
301
  results.set(x.id, { prepared: null, reach: { ok: false, at: now.toISOString(), why: 'its thread or advisor is gone' } })
326
302
  continue
327
303
  }
328
- if (p.copy !== null && p.copy.faults.length > 0) {
329
- // a value the copy's whitelist refused: a builder wrote what the door must not hold, so nothing of it leaves
330
- report.errors.push(`${x.id}: the copy refused ${p.copy.faults.length} values: ${p.copy.faults.slice(0, 3).join('; ')}`)
331
- results.set(x.id, { prepared: null, reach: { ok: false, at: now.toISOString(), why: `its copy refused ${p.copy.faults.length} values: an agent's fix waits` } })
304
+ if (p.theirs !== null && p.theirs.faults.length > 0) {
305
+ // a value the output whitelist refused: a builder wrote what a person must not read, so the port shows nothing of it
306
+ report.errors.push(`${x.id}: the whitelist refused ${p.theirs.faults.length} values: ${p.theirs.faults.slice(0, 3).join('; ')}`)
307
+ results.set(x.id, { prepared: null, reach: { ok: false, at: now.toISOString(), why: `its whitelist refused ${p.theirs.faults.length} values: an agent's fix waits` } })
332
308
  continue
333
309
  }
334
- const a = s.advisors.find((y) => y.id === x.advisor)!
335
- const served: ServedShare = { email: a.email, name: a.name, expires: x.expires, project: p.project, owner: p.owner, title: p.copy?.view.title ?? 'a thread', ...(a.photo?.seen === true ? { photo: a.photo.sha } : {}) }
336
- shares.shares[x.id] = served
337
- for (const m of p.served) media.add(m.sha)
338
- results.set(x.id, { prepared: p, reach: { ok: true, at: now.toISOString() } })
310
+ report.reached++
311
+ // where the person's reading stands, written by the port on their own page
312
+ results.set(x.id, { prepared: p, read: readOf(await o.bucket.get(KEYS.reads(x.id)), p.his), reach: { ok: true, at: now.toISOString() } })
339
313
  } catch (e) {
340
314
  report.errors.push(`${x.id}: ${(e as Error).message}`)
341
315
  results.set(x.id, { prepared: null, reach: { ok: false, at: now.toISOString(), why: (e as Error).message } })
342
316
  }
343
317
  }
344
318
  try {
345
- if ((await o.bucket.get(KEYS.csrf)) === null) await o.bucket.put(KEYS.csrf, new Uint8Array(randomBytes(32)))
346
- // the advisors' page, by the hash of its bytes, before the list that pins it: the door serves only that pair
347
- if ((live.length > 0 || Object.keys(shares.projects ?? {}).length > 0) && o.app !== undefined) {
348
- const b = await o.app()
349
- for (const [f, ext] of [[b.js, 'js'], [b.css, 'css']] as const) if ((await o.bucket.get(KEYS.app(f.sha, ext))) === null) await o.bucket.put(KEYS.app(f.sha, ext), f.bytes, ext === 'js' ? 'text/javascript' : 'text/css')
350
- shares.app = b.pin
319
+ const keep = new Set(live.map((x) => x.id))
320
+ // an ended share's read cursor goes with it (the privacy page says so)
321
+ for (const k of await o.bucket.list('reads/')) {
322
+ const id = /^reads\/(.+)\.json$/.exec(k)?.[1]
323
+ if (id !== undefined && !keep.has(id)) await o.bucket.delete(k)
351
324
  }
352
- // the list of live shares first: an ended share is refused from this write on, whatever follows
353
- await o.bucket.put(KEYS.shares, JSON.stringify(shares), 'application/json')
354
- for (const x of live) {
355
- const r = results.get(x.id)!
356
- if (r.prepared === null) continue
357
- for (const m of r.prepared.served) if ((await o.bucket.get(KEYS.media(m.sha))) === null) await o.bucket.put(KEYS.media(m.sha), encoded.get(m.sha)!, 'image/webp')
358
- const { copy, manifest } = r.prepared
359
- const h = sha256(JSON.stringify({ copy: copy === null ? null : { view: copy.view, row: copy.row }, manifest }))
360
- if (h !== x.pushed) {
361
- if (copy !== null && manifest !== null) {
362
- // the manifest last: the door serves a share's copy once its manifest names it
363
- await o.bucket.put(KEYS.view(x.id), JSON.stringify(copy.view), 'application/json')
364
- await o.bucket.put(KEYS.row(x.id), JSON.stringify(copy.row), 'application/json')
365
- await o.bucket.put(KEYS.files(x.id), JSON.stringify(manifest), 'application/json')
366
- }
367
- report.pushed++
368
- }
369
- r.pushed = h
370
- // where the advisor's reading stands: pulled each pass, written by the door on their own page
371
- r.read = readOf(await o.bucket.get(KEYS.reads(x.id)), r.prepared.his)
372
- }
373
- const keep = new Set(Object.keys(shares.shares))
374
- // an ended share's copy: its manifest first, so the door stops serving it before its view goes; its cursor after
375
- for (const prefix of ['files/', 'view/', 'row/', 'reads/'])
376
- for (const k of await o.bucket.list(prefix)) {
377
- const id = /^[a-z]+\/(.+)\.json$/.exec(k)?.[1]
378
- if (id !== undefined && !keep.has(id)) {
379
- await o.bucket.delete(k)
380
- if (prefix === 'files/') report.removed++
381
- }
382
- }
383
- // a file the page staged and no words took: gone after an hour, or with its share
384
- const projects = new Set(Object.keys(shares.projects ?? {}))
325
+ // a file the page staged and no words took: gone after an hour, or with its share or project
326
+ const places = new Set(startPlacesOf(s, now).map((x) => x.id))
385
327
  for (const k of await o.bucket.list('stage/')) {
386
328
  const m = /^stage\/(s|p)\/([^/]+)\/(\d{13})-/.exec(k)
387
- const open = m !== null && (m[1] === 's' ? keep : projects).has(m[2]!)
329
+ const open = m !== null && (m[1] === 's' ? keep : places).has(m[2]!)
388
330
  if (m === null || !open || Number(m[3]) < now.getTime() - 3_600_000) await o.bucket.delete(k)
389
331
  }
390
- // each advisor's own photo, while a share or a project names it: read by that advisor's page alone (edge/handler.ts)
391
- const photos = new Map<string, string>()
392
- for (const v of [...Object.values(shares.shares), ...Object.values(shares.projects ?? {})]) {
393
- const a = s.advisors.find((y) => y.email === v.email)
394
- if (v.photo !== undefined && a !== undefined) photos.set(v.photo, a.id)
395
- }
396
- for (const [sha, id] of photos) {
397
- if ((await o.bucket.get(KEYS.photo(sha))) !== null) continue
398
- const bytes = photoBytes(dir, 'advisors', id, 64)
399
- if (bytes !== null) await o.bucket.put(KEYS.photo(sha), bytes, 'image/webp')
400
- }
401
332
  // a person no longer in the list: their sessions end; one no longer known: their password too
402
333
  const signed = new Set(Object.keys(logins).map(sha256))
403
334
  const known = new Set(s.advisors.map((a) => sha256(a.email)))
404
335
  for (const k of await o.bucket.list('session/')) if (!signed.has(k.split('/')[1] ?? '')) await o.bucket.delete(k)
405
336
  for (const k of await o.bucket.list('login/')) if (!known.has(/^login\/([0-9a-f]{64})\./.exec(k)?.[1] ?? '')) await o.bucket.delete(k)
406
- for (const k of await o.bucket.list('photo/')) {
407
- const sha = /^photo\/([0-9a-f]{64})\.webp$/.exec(k)?.[1]
408
- if (sha === undefined || !photos.has(sha)) await o.bucket.delete(k)
409
- }
410
- for (const k of await o.bucket.list('media/')) {
411
- const sha = /^media\/([0-9a-f]{64})\.webp$/.exec(k)?.[1]
412
- if (sha === undefined || !media.has(sha)) await o.bucket.delete(k)
413
- }
414
337
  } catch (e) {
415
- report.errors.push(`the bucket: ${(e as Error).message}`)
416
- for (const r of results.values()) r.reach = { ok: false, at: now.toISOString(), why: `the bucket: ${(e as Error).message}` }
417
- } finally {
418
- encoded.clear()
338
+ report.errors.push(`the users' folder: ${(e as Error).message}`)
419
339
  }
420
340
  withState(dir, (st) => {
421
341
  for (const x of st.shares) {
@@ -423,45 +343,35 @@ export async function syncOnce(dir: string, o: { bucket: Bucket; words: string[]
423
343
  if (r !== undefined) {
424
344
  x.reach = r.reach
425
345
  if (r.prepared !== null) {
426
- // nothing is held any more: an older pass's holds and waiting pictures leave the store
346
+ // a share holds nothing back: the store's stale `held` and `waiting` fields go
427
347
  x.masked = r.prepared.masked
428
348
  delete x.held
429
349
  delete x.waiting
430
350
  x.parts = r.prepared.parts
351
+ x.pushed = sha256(JSON.stringify({ view: r.prepared.theirs?.view ?? null, manifest: r.prepared.manifest }))
431
352
  }
432
- if (r.pushed !== undefined) x.pushed = r.pushed
433
353
  if (r.read !== undefined) {
434
354
  if (r.read === null) delete x.read
435
355
  else x.read = r.read
436
356
  }
437
357
  } else if (x.state === 'revoked' || (x.state === 'live' && !isLive(x, now))) {
438
358
  x.reach = report.errors.length === 0 ? { ok: true, at: now.toISOString() } : { ok: false, at: now.toISOString(), why: report.errors[0]! }
439
- // where they stopped reading goes with the share, here as on the door (the door's privacy page says so)
359
+ // where they stopped reading goes with the share
440
360
  delete x.read
441
361
  }
442
362
  }
443
363
  })
444
- if (report.errors.length === 0) {
445
- const proposed = readState(dir).proposals.length
446
- report.advice = (await importAdvice(dir, o.bucket, now)).length
447
- // what came back is drawn in the copies by this pass, not the next: the person's page shows their act (their
448
- // words, « waits for <owner> », a thread they opened) within one pass of the job
449
- if (o.again !== false && (report.advice > 0 || readState(dir).proposals.length > proposed)) {
450
- const r = await syncOnce(dir, { ...o, now, again: false })
451
- report.pushed += r.pushed
452
- report.removed += r.removed
453
- report.errors.push(...r.errors)
454
- }
455
- }
364
+ report.advice = await deliverPending(dir, o.bucket, now)
365
+ await sweepUploads(dir, o.bucket, now)
456
366
  return report
457
367
  }
458
368
 
459
- /** with no advisors page yet (not set up): each live share's masked entries, for his preview */
369
+ /** with no advisors page yet (not set up): each live share's masked entries, for the owner's preview */
460
370
  export async function refreshLocal(dir: string, o: { words: string[]; now?: Date }): Promise<void> {
461
371
  const now = o.now ?? new Date()
462
372
  const s = readState(dir)
463
373
  const got = new Map<string, Prepared | null>()
464
- for (const x of s.shares.filter((y) => isLive(y, now))) got.set(x.id, await prepare(s, x, { words: o.words, encode: sharpWebp, now, preview: true }))
374
+ for (const x of s.shares.filter((y) => isLive(y, now))) got.set(x.id, await prepare(s, x, { words: o.words, now }))
465
375
  withState(dir, (st) => {
466
376
  for (const x of st.shares) {
467
377
  const p = got.get(x.id)
@@ -1,11 +1,12 @@
1
- // the tunnel to the advisors' door (wiki tools/shipkit/advisors.md, The advisors page and its server): `sk advisors tunnel`, a pm process
2
- // (src/advisors-tunnel.shipkit.ts), keeps `cloudflared tunnel run` up while this machine carries the hq and the
3
- // tunnel's token is stored, and stops it when the hq moves: one connector only, on the Mac that holds the copies.
1
+ // the tunnel to the advisors page (wiki tools/shipkit/advisors.md, Who calls: the users' port): `sk advisors
2
+ // tunnel`, a pm process (src/advisors-tunnel.shipkit.ts), keeps `cloudflared tunnel run` up while this machine carries
3
+ // the hq and the tunnel's token is stored, and stops it when the hq moves: one connector only, on the Mac whose daemon
4
+ // opens the users' port.
4
5
  // The one constraint a reader breaks first: the token goes to cloudflared by its environment (TUNNEL_TOKEN), never on
5
6
  // its command line and never in a line of the log
6
7
  import { existsSync } from 'node:fs'
7
8
  import { readSecretHere } from '../secrets/read.ts'
8
- import { TUNNEL_TOKEN } from './door.ts'
9
+ import { TUNNEL_TOKEN } from './reach.ts'
9
10
 
10
11
  export type Proc = { exited: Promise<unknown>; kill: () => void }
11
12
 
@@ -38,7 +39,7 @@ export const cloudflaredBin = (): string | null => BINS.find((b) => existsSync(b
38
39
  /** the global process that keeps cloudflared up (src/advisors-tunnel.shipkit.ts at the house's root) */
39
40
  export const TUNNEL_PROCESS = 'advisors-tunnel'
40
41
 
41
- /** cloudflared for the door's setup: its binary, and the tunnel process started through the one road that starts a
42
+ /** cloudflared for the advisors page's setup: its binary, and the tunnel process started through the one road that starts a
42
43
  * global process (pm's switch), null once it runs, else why not. A surface that reaches pm hands it in */
43
44
  export interface TunnelStart {
44
45
  bin: () => string | null
@@ -0,0 +1,92 @@
1
+ // the users' port, opened by the daemon itself (wiki tools/shipkit/advisors.md, Who calls): on 127.0.0.1 alone, which
2
+ // the tunnel reaches, while this machine carries the hq and the advisors page is set up; looked at every 30 s, opened
3
+ // again with a new name. The one server besides the house's loopback one (RV040 allows this file). The one constraint
4
+ // a reader breaks first: its router is users-router.ts, which reaches no route of the hub, no owner word, no vault
5
+ import { DirBucket } from './dir-bucket.ts'
6
+ import { factsOf, type PageFacts } from './edge/pages.ts'
7
+ import { limits, type PasswordHasher } from './edge/sign-in.ts'
8
+ import { FILE_MAX } from './edge/types.ts'
9
+ import { housePageFacts } from './speaks.ts'
10
+ import { ownerNameOf } from './owner-name.ts'
11
+ import { advisorsDir, readState } from './owner-store.ts'
12
+ import { privateWords } from './sync.ts'
13
+ import { usersRouter } from './users-router.ts'
14
+ import { usersDir, usersPort } from './users-store.ts'
15
+
16
+ /** a password as the port keeps it: argon2id */
17
+ export const ARGON: PasswordHasher = { hash: (p) => Bun.password.hash(p, { algorithm: 'argon2id' }), verify: (p, h) => Bun.password.verify(p, h) }
18
+
19
+ const EVERY_MS = 30_000
20
+
21
+ /** the users' port on 127.0.0.1 with its router. No shared port: another program of this Mac may not bind beside it
22
+ * and take its requests */
23
+ export function usersServe(o: { port: number; fetch: (req: Request) => Promise<Response>; tls?: { cert: string; key: string } }): Bun.Server<undefined> {
24
+ // no body past the largest file a person may send, whatever the route: a stranger's 100 MB is refused by the server
25
+ return Bun.serve({ hostname: '127.0.0.1', port: o.port, maxRequestBodySize: FILE_MAX + 64 * 1024, ...(o.tls ? { tls: o.tls } : {}), fetch: o.fetch, error: () => new Response('error', { status: 500 }) })
26
+ }
27
+
28
+ export interface ListenerDeps {
29
+ carries?: () => boolean
30
+ host?: () => string | null
31
+ /** the name the public pages print: the owner's default (owner-name.ts) */
32
+ owner?: () => string
33
+ /** the port opened over the owner's advisors folder; tests pass their own */
34
+ listen?: (host: string, pages: PageFacts) => Promise<{ stop: () => void }>
35
+ }
36
+
37
+ /** the port over the owner's advisors folder, the owner's private words read again each minute */
38
+ async function listenHere(house: string, host: string, pages: PageFacts): Promise<{ stop: () => void }> {
39
+ const users = new DirBucket(usersDir())
40
+ let words: { at: number; list: string[] } = { at: 0, list: [] }
41
+ const wordsNow = (): string[] => (Date.now() - words.at < 60_000 ? words.list : (words = { at: Date.now(), list: privateWords(house) }).list)
42
+ const s = usersServe({ port: usersPort(), fetch: usersRouter({ bucket: users, host, pages, limits: limits(), password: ARGON, dir: advisorsDir(), words: wordsNow }) })
43
+ return { stop: () => void s.stop(true) }
44
+ }
45
+
46
+ /** the port kept open while this machine carries the hq and the page is set up, opened again on a new name */
47
+ export function usersListener(o: { house: string; print: (l: string) => void; printErr: (l: string) => void; everyMs?: number } & ListenerDeps): { stop: () => void; tick: () => Promise<void> } {
48
+ const host = o.host ?? (() => readState(advisorsDir()).host)
49
+ const owner = o.owner ?? (() => ownerNameOf(readState(advisorsDir())))
50
+ const listen = o.listen ?? ((h: string, pages: PageFacts) => listenHere(o.house, h, pages))
51
+ let here: { host: string; owner: string; stop: () => void } | null = null
52
+ let stopped = false
53
+ const look = async (): Promise<void> => {
54
+ let want: string | null = null
55
+ let name = 'the owner'
56
+ try {
57
+ const carries = o.carries ?? (await import('../hq/hq-role.ts')).carriesHq
58
+ want = carries() ? host() : null
59
+ name = owner()
60
+ } catch (e) {
61
+ o.printErr(`WARN advisors page: ${(e as Error).message}`)
62
+ }
63
+ // a new name for the public pages: the port opens again
64
+ if (here !== null && (here.host !== want || here.owner !== name)) {
65
+ here.stop()
66
+ here = null
67
+ }
68
+ if (want === null || here !== null) return
69
+ const pages = (await housePageFacts(o.house).catch(() => null))?.facts ?? factsOf(undefined, undefined)
70
+ if (stopped) return
71
+ try {
72
+ here = { host: want, owner: name, ...(await listen(want, pages)) }
73
+ o.print(`advisors page: serving ${want} from this daemon`)
74
+ } catch (e) {
75
+ o.printErr(`WARN advisors page: the users' port did not open here: ${(e as Error).message}`)
76
+ }
77
+ }
78
+ // one look at a time: a tick while one runs waits for that one
79
+ let running: Promise<void> | null = null
80
+ const tick = (): Promise<void> => (running ??= look().finally(() => (running = null)))
81
+ void tick()
82
+ const timer = setInterval(() => void tick(), o.everyMs ?? EVERY_MS)
83
+ return {
84
+ tick,
85
+ stop: () => {
86
+ stopped = true
87
+ clearInterval(timer)
88
+ here?.stop()
89
+ here = null
90
+ },
91
+ }
92
+ }