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,14 +1,15 @@
1
- // the door's sign in (wiki tools/shipkit/advisors.md, The advisors page and its server): `/in`, one form, no script. The first time, an email
2
- // and the one time code of the invite set the password the person chooses; then an email and that password. Either
3
- // opens a session: a random id in an httpOnly cookie, its hash a file under the person. The one constraint a reader
4
- // breaks first: every check reads the list the Mac wrote (a person with no live grant is not in it), and every failed
5
- // try counts against the email, the caller and all callers together
1
+ // the sign in of the advisors page (wiki tools/shipkit/advisors.md, Who calls: the users' port): `/in`, one form,
2
+ // no script. The first time, an email and the one time code of the invite set the password the person chooses; then
3
+ // an email and that password. A lost password: `/reset` asks a code by mail, which sets a new password the same way.
4
+ // Each opens a session: a random id in an httpOnly cookie, its hash a file under the person. The one constraint a
5
+ // reader breaks first: every check reads the list the owner's store gives at the request (a person with no live grant
6
+ // is not in it), every failed try counts against the email and the caller, and no answer says whether an email has access
6
7
  import { getJson, type Bucket } from './bucket.ts'
7
8
  import { bytesOf } from './form.ts'
8
- import { esc, renderPage, type Page } from './status.ts'
9
- import { KEYS, type SharesFile } from './types.ts'
9
+ import { boxOf, esc, renderPage, type Page } from './status.ts'
10
+ import { KEYS, type SignInList } from './types.ts'
10
11
 
11
- /** what hashes and checks a password: argon2id, given by the door's server (door-serve.ts) */
12
+ /** what hashes and checks a password: argon2id, given by the users' port (users-listen.ts) */
12
13
  export interface PasswordHasher {
13
14
  hash: (password: string) => Promise<string>
14
15
  verify: (password: string, hash: string) => Promise<boolean>
@@ -34,24 +35,32 @@ export const sameText = (a: string, b: string): boolean => {
34
35
  return d === 0
35
36
  }
36
37
 
37
- /** the tries in the last window that did not sign in, by key (`ip:<caller>`, `email:<email>`) */
38
+ /** the tries in the last window that did not sign in, by key (`ip:<caller>`, `email:<email>`), and the resets asked
39
+ * (`reset-ip:<caller>`, `reset-email:<email>`) */
38
40
  export interface Limits {
39
41
  tries: Map<string, number[]>
40
42
  }
41
43
  export const limits = (): Limits => ({ tries: new Map() })
42
- const WINDOW_MS = 10 * 60_000
43
- const PER_EMAIL = 10
44
- const PER_CALLER = 20
44
+ /** each kind of key: how many in how long, in the port's memory (a restart of the port starts them again). A reset
45
+ * asked mails a person at most 3 times an hour and 5 a day, whoever asks */
46
+ const CAPS: Record<string, { most: number; ms: number }> = {
47
+ email: { most: 10, ms: 10 * 60_000 },
48
+ ip: { most: 20, ms: 10 * 60_000 },
49
+ 'reset-email': { most: 3, ms: 3_600_000 },
50
+ 'reset-day': { most: 5, ms: 86_400_000 },
51
+ 'reset-ip': { most: 10, ms: 3_600_000 },
52
+ }
53
+ const capOf = (k: string): { most: number; ms: number } => CAPS[k.slice(0, k.indexOf(':'))]!
45
54
 
46
55
  const kept = (l: Limits, k: string, now: number): number[] => {
47
- const ts = (l.tries.get(k) ?? []).filter((t) => t > now - WINDOW_MS)
56
+ const ts = (l.tries.get(k) ?? []).filter((t) => t > now - capOf(k).ms)
48
57
  if (ts.length === 0) l.tries.delete(k)
49
58
  else l.tries.set(k, ts)
50
59
  return ts
51
60
  }
52
61
  /** a try counted before any wait, so tries sent at once meet the limit too; a sign in takes its own back */
53
62
  function take(l: Limits, keys: readonly string[], now: number): (() => void) | null {
54
- if (keys.some((k) => kept(l, k, now).length >= (k.startsWith('email:') ? PER_EMAIL : PER_CALLER))) return null
63
+ if (keys.some((k) => kept(l, k, now).length >= capOf(k).most)) return null
55
64
  for (const k of keys) l.tries.set(k, [...(l.tries.get(k) ?? []), now])
56
65
  return () => {
57
66
  for (const k of keys) {
@@ -66,31 +75,75 @@ function take(l: Limits, keys: readonly string[], now: number): (() => void) | n
66
75
  let dummy: Promise<string> | null = null
67
76
  const DUMMY_PASSWORD = 'no password matches this one'
68
77
 
69
- /** the form, with a line of what went wrong */
70
- export function signInPage(owner: string, said?: string): Page {
71
- const field = (name: string, label: string, type: string, extra = ''): string => `<p><label>${esc(label)}<br><input name="${name}" type="${type}" ${extra} style="font:inherit;width:100%;max-width:360px;padding:6px"></label></p>`
78
+ /** the page that asks a reset: no session, no read of the folder */
79
+ export const RESET_PATH = '/reset'
80
+ /** the words of a sign in that did not match: which field is wrong is never said, so they say what to try */
81
+ export const NO_MATCH = 'Check your email and password. The code field is only for your first sign in or a reset.'
82
+ const FORGOT = { href: RESET_PATH, text: 'Forgot your password?' }
83
+ const FIELD = 'font:inherit;width:100%;max-width:360px;padding:6px;box-sizing:border-box'
84
+ const BUTTON = 'font:inherit;padding:6px 14px'
85
+ const field = (name: string, label: string, type: string, extra = ''): string => `<p><label>${esc(label)}<br><input name="${name}" type="${type}" ${extra} style="${FIELD}"></label></p>`
86
+
87
+ /** what went wrong on the sign in: the words, and whether the box offers the reset */
88
+ export type Said = { text: string; forgot: boolean }
89
+
90
+ /** the form, with a red box of what went wrong above it */
91
+ export function signInPage(owner: string, said?: Said): Page {
72
92
  return renderPage(
73
93
  'Sign in, rv advisors',
74
94
  [
75
95
  '<h1>Sign in</h1>',
76
- said !== undefined ? `<p><strong>${esc(said)}</strong></p>` : '',
96
+ said !== undefined ? boxOf('bad', said.text, said.forgot ? FORGOT : undefined) : '',
77
97
  '<form method="post" action="/in">',
78
98
  field('email', 'Your email', 'email', 'required autocomplete="email"'),
79
- field('code', 'The code of your invite (the first time only)', 'text', 'autocomplete="one-time-code"'),
80
- field('password', `Your password (the first time, choose one: ${PASSWORD_MIN} characters at least)`, 'password', 'required autocomplete="current-password"'),
81
- '<p><button type="submit" style="font:inherit;padding:6px 14px">Sign in</button></p>',
99
+ field('code', 'A code: of your invite the first time, or of a reset', 'text', 'autocomplete="one-time-code"'),
100
+ field('password', `Your password (with a code, choose a new one: ${PASSWORD_MIN} characters at least)`, 'password', 'required autocomplete="current-password"'),
101
+ `<p><button type="submit" style="${BUTTON}">Sign in</button></p>`,
82
102
  '</form>',
83
- `<p class="dim">${esc(`A lost password: ask ${owner} for a new code.`)} <a href="/about">About rv advisors</a></p>`,
103
+ `<p><a href="${RESET_PATH}">Forgot your password?</a> <span class="dim">${esc(`A code goes to your email. Or ask ${owner} for a new one.`)}</span></p>`,
104
+ '<p class="dim"><a href="/about">About rv advisors</a></p>',
84
105
  ].join(''),
85
106
  // the page of the one form that navigates: under `no-referrer` a browser posts it with `Origin: null`
86
107
  'same-origin',
87
108
  )
88
109
  }
89
110
 
90
- export type SignIn = { ok: true; cookie: string } | { ok: false; status: number; said: string }
111
+ /** a reset's code lives this long (login.ts parks it) */
112
+ export const RESET_MINUTES = 30
113
+
114
+ /** the reset's form, or its one answer once sent: the same words whatever the email, so the page says nothing of who
115
+ * has access */
116
+ export function resetPage(o: { sent: boolean; said?: string }): Page {
117
+ const minutes = RESET_MINUTES
118
+ const body = o.sent
119
+ ? ['<h1>Check your email</h1>', boxOf('ok', `If this email has access, a code is on its way. It works once, for ${minutes} minutes.`), `<p>${esc('Then sign in with your email, that code and a new password. Your old password works until you use the code.')}</p>`, `<p><a href="/in">Sign in</a></p>`]
120
+ : [
121
+ '<h1>Forgot your password?</h1>',
122
+ o.said !== undefined ? boxOf('bad', o.said) : '',
123
+ `<p>${esc(`Type the email your invite went to. If it has access, a code goes to it, for ${minutes} minutes. Your old password works until you use the code.`)}</p>`,
124
+ `<form method="post" action="${RESET_PATH}">`,
125
+ field('email', 'Your email', 'email', 'required autocomplete="email"'),
126
+ `<p><button type="submit" style="${BUTTON}">Send me a code</button></p>`,
127
+ '</form>',
128
+ '<p><a href="/in">Back to the sign in</a></p>',
129
+ ]
130
+ return renderPage('Reset your password, rv advisors', body.join(''), 'same-origin')
131
+ }
132
+
133
+ /** one reset asked by the form: the email the owner's side mails a code to when it has access, null while the caller or
134
+ * the email asked too many. Counted before anything else, the same for every email, and never given back */
135
+ export async function askReset(req: Request, o: { limits: Limits; now: number }): Promise<{ email: string } | null> {
136
+ const body = await bytesOf(req, 4096)
137
+ const form = new URLSearchParams(body === null ? '' : new TextDecoder().decode(body))
138
+ const email = (form.get('email') ?? '').trim().toLowerCase()
139
+ if (take(o.limits, [`reset-ip:${req.headers.get('cf-connecting-ip') ?? 'local'}`, `reset-email:${email}`, `reset-day:${email}`], o.now) === null) return null
140
+ return { email: email.length <= 254 ? email : '' }
141
+ }
142
+
143
+ export type SignIn = { ok: true; cookie: string } | { ok: false; status: number; said: Said }
91
144
 
92
145
  /** one try of the form: a session, or why not */
93
- export async function signIn(req: Request, o: { bucket: Bucket; file: SharesFile | null; now: number; limits: Limits; password?: PasswordHasher | undefined }): Promise<SignIn> {
146
+ export async function signIn(req: Request, o: { bucket: Bucket; logins: SignInList; now: number; limits: Limits; password?: PasswordHasher | undefined }): Promise<SignIn> {
94
147
  const body = await bytesOf(req, 4096)
95
148
  const form = new URLSearchParams(body === null ? '' : new TextDecoder().decode(body))
96
149
  const email = (form.get('email') ?? '').trim().toLowerCase()
@@ -98,22 +151,34 @@ export async function signIn(req: Request, o: { bucket: Bucket; file: SharesFile
98
151
  const password = form.get('password') ?? ''
99
152
  const keys = [`ip:${req.headers.get('cf-connecting-ip') ?? 'local'}`, `email:${email}`]
100
153
  const back = take(o.limits, keys, o.now)
101
- if (back === null) return { ok: false, status: 429, said: 'Too many tries: wait a few minutes.' }
154
+ if (back === null) return { ok: false, status: 429, said: { text: 'Too many tries: wait a few minutes.', forgot: true } }
102
155
  const hasher = o.password
103
- if (hasher === undefined) return { ok: false, status: 503, said: 'Signing in is not open right now.' }
104
- const no = async (said = 'That email, code or password does not match.'): Promise<SignIn> => {
156
+ if (hasher === undefined) return { ok: false, status: 503, said: { text: 'Signing in is not open right now.', forgot: false } }
157
+ const no = async (): Promise<SignIn> => {
105
158
  await hasher.verify(DUMMY_PASSWORD, await (dummy ??= hasher.hash(DUMMY_PASSWORD))).catch(() => false)
106
- return { ok: false, status: 401, said }
159
+ return { ok: false, status: 401, said: { text: NO_MATCH, forgot: true } }
107
160
  }
108
- const entry = o.file?.logins?.[email]
161
+ const short: SignIn = { ok: false, status: 400, said: { text: `Choose a password of ${PASSWORD_MIN} characters at least.`, forgot: false } }
162
+ const entry = o.logins[email]
109
163
  if (entry === undefined || Date.parse(entry.until) <= o.now || password.length > PASSWORD_MAX) return no()
110
164
  const eh = await sha256(email)
111
165
  const held = await getJson<{ gen: number; hash: string }>(o.bucket, KEYS.password(eh))
112
166
  const has = held !== null && held.gen === entry.gen && typeof held.hash === 'string'
113
- if (code !== '') {
114
- // the code works once: a password set with it ends it, and so does its date
115
- if (has || Date.parse(entry.codeUntil) <= o.now || !sameText(await sha256(code), entry.code)) return no()
116
- if (password.length < PASSWORD_MIN) return { ok: false, status: 400, said: `Choose a password of ${PASSWORD_MIN} characters at least.` }
167
+ const typed = code === '' ? '' : await sha256(code)
168
+ const reset = entry.reset
169
+ let gen = entry.gen
170
+ if (reset !== undefined && typed !== '' && Date.parse(reset.codeUntil) > o.now && sameText(typed, reset.code)) {
171
+ // the code of a reset they asked: the new password is the next generation's, and every session of theirs ends
172
+ if (password.length < PASSWORD_MIN) return short
173
+ if (!(await o.bucket.claim(KEYS.claim(eh, reset.gen)))) return no()
174
+ await o.bucket.put(KEYS.password(eh), JSON.stringify({ gen: reset.gen, hash: await hasher.hash(password) }), 'application/json')
175
+ for (const k of await o.bucket.list(KEYS.sessions(eh))) await o.bucket.delete(k)
176
+ gen = reset.gen
177
+ } else if (typed !== '' && !has) {
178
+ // once a password is set the code field is ignored: a password manager that fills it never blocks the password.
179
+ // The code works once: a password set with it ends it, and so does its date
180
+ if (Date.parse(entry.codeUntil) <= o.now || !sameText(typed, entry.code)) return no()
181
+ if (password.length < PASSWORD_MIN) return short
117
182
  // two first sign ins at once: only one claims the code
118
183
  if (!(await o.bucket.claim(KEYS.claim(eh, entry.gen)))) return no()
119
184
  await o.bucket.put(KEYS.password(eh), JSON.stringify({ gen: entry.gen, hash: await hasher.hash(password) }), 'application/json')
@@ -121,13 +186,13 @@ export async function signIn(req: Request, o: { bucket: Bucket; file: SharesFile
121
186
  back()
122
187
  const sid = b64url(crypto.getRandomValues(new Uint8Array(32)))
123
188
  const until = Math.min(o.now + SESSION_MAX_MS, Date.parse(entry.until))
124
- await o.bucket.put(KEYS.session(eh, await sha256(sid)), JSON.stringify({ email, gen: entry.gen, until: new Date(until).toISOString() }), 'application/json')
189
+ await o.bucket.put(KEYS.session(eh, await sha256(sid)), JSON.stringify({ email, gen, until: new Date(until).toISOString() }), 'application/json')
125
190
  return { ok: true, cookie: `${SESSION_COOKIE}=${eh}.${sid}; Path=/; Max-Age=${Math.floor((until - o.now) / 1000)}; HttpOnly; Secure; SameSite=Lax` }
126
191
  }
127
192
 
128
193
  /** who a request's session is: their email and the hash of the session; null for none, a forged one, an ended one, or
129
194
  * one of a person no longer in the list or past a new code */
130
- export async function sessionOf(req: Request, o: { bucket: Bucket; file: SharesFile | null; now: number }): Promise<{ email: string; login: string } | null> {
195
+ export async function sessionOf(req: Request, o: { bucket: Bucket; logins: SignInList; now: number }): Promise<{ email: string; login: string } | null> {
131
196
  let raw = ''
132
197
  for (const part of (req.headers.get('cookie') ?? '').split(';')) {
133
198
  const [k, ...v] = part.trim().split('=')
@@ -138,7 +203,7 @@ export async function sessionOf(req: Request, o: { bucket: Bucket; file: SharesF
138
203
  const sh = await sha256(m[2]!)
139
204
  const s = await getJson<{ email: string; gen: number; until: string }>(o.bucket, KEYS.session(m[1]!, sh))
140
205
  if (s === null || typeof s.email !== 'string' || (await sha256(s.email)) !== m[1]) return null
141
- const entry = o.file?.logins?.[s.email]
206
+ const entry = o.logins[s.email]
142
207
  if (entry === undefined || entry.gen !== s.gen || Date.parse(s.until) <= o.now || Date.parse(entry.until) <= o.now) return null
143
208
  return { email: s.email, login: sh }
144
209
  }
@@ -1,15 +1,28 @@
1
- // the door's server rendered pages (wiki tools/shipkit/advisors.md, The advisors page and its server): 403, 404, 503, « method not allowed »
2
- // and the two public pages, with no script, every text escaped. Every other page is the advisors' app
1
+ // the server rendered pages of the users' port (wiki tools/shipkit/advisors.md, Who calls: the users' port): 403,
2
+ // 404, 503, « method not allowed » and the two public pages, with no script, every text escaped. Every other page is the advisors' app
3
3
  export const esc = (s: string): string => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')
4
4
 
5
- const STYLE = `:root{color-scheme:light dark;--bg:#fbfaf7;--fg:#1d1c1a;--dim:#6b6862}@media (prefers-color-scheme:dark){:root{--bg:#161614;--fg:#ecebe6;--dim:#9a978f}}body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.5 system-ui,-apple-system,sans-serif}main{max-width:640px;margin:0 auto;padding:32px 16px}h1{font-size:20px;margin:0 0 6px}h2{font-size:16px;margin:24px 0 4px}ul{margin:4px 0;padding-left:20px}.dim{color:var(--dim)}a{color:inherit}`
5
+ const STYLE = [
6
+ ':root{color-scheme:light dark;--bg:#fbfaf7;--fg:#1d1c1a;--dim:#6b6862;--bad-bg:#fdecea;--bad-line:#d93025;--bad-fg:#8c1d18;--ok-bg:#eaf3ec;--ok-line:#2e7d4f;--ok-fg:#1d4d31}',
7
+ '@media (prefers-color-scheme:dark){:root{--bg:#161614;--fg:#ecebe6;--dim:#9a978f;--bad-bg:#3a1714;--bad-line:#f2756a;--bad-fg:#ffd9d4;--ok-bg:#15301f;--ok-line:#6cc58e;--ok-fg:#d3f2de}}',
8
+ 'body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.5 system-ui,-apple-system,sans-serif}main{max-width:640px;margin:0 auto;padding:32px 16px}h1{font-size:20px;margin:0 0 6px}h2{font-size:16px;margin:24px 0 4px}ul{margin:4px 0;padding-left:20px}.dim{color:var(--dim)}a{color:inherit}',
9
+ '.box{display:flex;gap:10px;align-items:flex-start;max-width:360px;margin:14px 0;padding:10px 12px;border:1px solid;border-left-width:4px;border-radius:6px}.box p{margin:0}.box a{white-space:nowrap}.box .ic{flex:none;width:20px;height:20px;border-radius:50%;color:var(--bg);font:700 13px/20px system-ui,sans-serif;text-align:center}',
10
+ '.box.bad{background:var(--bad-bg);border-color:var(--bad-line);color:var(--bad-fg)}.box.bad .ic{background:var(--bad-line)}.box.ok{background:var(--ok-bg);border-color:var(--ok-line);color:var(--ok-fg)}.box.ok .ic{background:var(--ok-line)}',
11
+ ].join('')
12
+
13
+ /** a box above a form: `bad` what went wrong (`role="alert"`, read out as it shows), `ok` what happened (`role="status"`);
14
+ * `text` escaped, `link` a path of the page and its words */
15
+ export function boxOf(kind: 'bad' | 'ok', text: string, link?: { href: string; text: string }): string {
16
+ const more = link === undefined ? '' : ` <a href="${esc(link.href)}">${esc(link.text)}</a>`
17
+ return `<div class="box ${kind}" role="${kind === 'bad' ? 'alert' : 'status'}"><span class="ic" aria-hidden="true">${kind === 'bad' ? '!' : '✓'}</span><p>${esc(text)}${more}</p></div>`
18
+ }
6
19
 
7
20
  /** `same-origin` on a page whose form navigates: under `no-referrer` a browser posts it with `Origin: null`, which the
8
- * door refuses. Every other page sends none */
21
+ * users' port refuses. Every other page sends none */
9
22
  export type Referrer = 'no-referrer' | 'same-origin'
10
23
 
11
- /** a page of the door and the referrer policy it carries: its meta and its response's header both read `referrer`, so
12
- * they never disagree (in a browser the meta wins over the header) */
24
+ /** a page of the advisors page and the referrer policy it carries: its meta and its response's header both read
25
+ * `referrer`, so they never disagree (in a browser the meta wins over the header) */
13
26
  export interface Page {
14
27
  html: string
15
28
  referrer: Referrer
@@ -1,56 +1,41 @@
1
- // the advisors' door (wiki tools/shipkit/advisors.md): what the sync writes to the door's folder and what the door's
2
- // server writes back. The edge folder imports its own siblings only, no node builtin (tests/advisors-edge.test.ts)
1
+ // the shapes of the advisors page (wiki tools/shipkit/advisors.md): the list the sign in reads, what a person sends,
2
+ // the keys of the users' port's folder. The edge folder imports its own siblings only, no node builtin (tests/advisors-edge.test.ts)
3
3
 
4
- /** one share as the door reads it from `shares.json` on every request: whose, until when, what it shows */
5
- export interface ServedShare {
6
- /** the advisor's email, lowercased: the session's login must be theirs */
7
- email: string
8
- name: string
9
- /** ISO time: past it the door refuses the share on its own clock */
10
- expires: string
11
- project: string
12
- title: string
13
- /** the hash of the advisor's own photo at `photo/<sha>.webp`: served to that advisor alone */
14
- photo?: string
15
- /** his name as this share's project reads it, scanned */
16
- owner?: string
17
- }
18
-
19
- /** a project an advisor is enabled on, as the door reads it from `shares.json` on every request: the one place an
20
- * advisor may start a thread, by its id (128 random bits). Gone the moment he disables the advisor there */
4
+ /** a project an advisor is enabled on, read from the owner's store at the request (sync.ts projectsOf): the one place
5
+ * an advisor may start a thread, by its id (128 random bits). Gone the moment the owner disables the advisor there */
21
6
  export interface ServedProject {
22
7
  email: string
23
8
  name: string
24
9
  /** the project's display name, scanned */
25
10
  project: string
26
- /** his name, as the advisor reads it */
11
+ /** the owner's name, as the advisor reads it */
27
12
  owner: string
28
- /** as ServedShare's */
29
- photo?: string
30
13
  }
31
14
 
32
- export interface SharesFile {
33
- v: 1
34
- shares: Record<string, ServedShare>
35
- projects?: Record<string, ServedProject>
36
- /** the owner's name as the advisors read it, scanned: the owner's words go under it */
37
- owner?: string
38
- /** each person who may sign in, by email, while they hold a live grant: their login's generation, the sha256 (hex)
39
- * of their one time code and its end, the end of their last grant. The code itself never leaves the owner's store */
40
- logins?: Record<string, { gen: number; code: string; codeUntil: string; until: string }>
41
- /** the page's two files the door serves, `<js sha>.<css sha>` */
42
- app?: string
15
+ /** one person who may sign in: their login's generation, the sha256 (hex) of their one time code and its end, the
16
+ * end of their last grant; a reset they asked: the next generation, its code's hash and end. The code itself never
17
+ * leaves the owner's store */
18
+ export interface SignInEntry {
19
+ gen: number
20
+ code: string
21
+ codeUntil: string
22
+ until: string
23
+ reset?: { gen: number; code: string; codeUntil: string }
43
24
  }
44
25
 
45
- /** what the door checks a read or a write of one share against, pushed with its copy (`files/<share>.json`): the ids
46
- * its routes may name, the pictures it may serve, what may be answered. Opaque ids only (advisors/project.ts) */
26
+ /** the list the sign in reads (edge/sign-in.ts): each person with a live grant, by email, built from the owner's store at
27
+ * each request (users-store.ts liveLogins) */
28
+ export type SignInList = Record<string, SignInEntry>
29
+
30
+ /** what the users' port checks a read or a write of one share against, made with its view at the request (sync.ts
31
+ * manifestOf): the ids its routes may name, the pictures it may serve, what may be answered. Opaque ids only (advisors/project.ts) */
47
32
  export interface ShareManifest {
48
33
  v: 1
49
- /** the copy's head: the thread's id at the door */
34
+ /** the view's head: the thread's id on the advisors page */
50
35
  head: string
51
- /** every item and cell id of the copy */
36
+ /** every item and cell id of the view */
52
37
  ids: string[]
53
- /** every served picture of the copy, by sha */
38
+ /** every served picture of the view, by sha */
54
39
  images: string[]
55
40
  /** each version that waits for a verdict: its id, and its count of views in the store (an advice on fewer is stale) */
56
41
  judge: { item: string; version: number }[]
@@ -61,7 +46,7 @@ export interface ShareManifest {
61
46
  export const ADVICE_KINDS = ['pick', 'approve', 'change', 'words'] as const
62
47
  export type AdviceKind = (typeof ADVICE_KINDS)[number]
63
48
 
64
- /** one advice as the door writes it in `inbox/<share>/`: hostile input to the Mac, read with a strict schema */
49
+ /** one advice as a person sends it (users-router.ts, advice.ts landAdvice): hostile input, read with a strict schema */
65
50
  export interface AdviceWire {
66
51
  v: 1
67
52
  at: string
@@ -79,8 +64,8 @@ export interface AdviceWire {
79
64
  files?: UploadWire[]
80
65
  }
81
66
 
82
- /** a file an advisor sent, as its inbox entry names it: what the form said, never trusted. The bytes wait in the
83
- * bucket under the entry, quarantined, until he accepts or declines */
67
+ /** a file an advisor sent, as its entry names it: what the form said, never trusted. The bytes wait in the port's
68
+ * folder under the entry, quarantined, until the owner accepts or declines */
84
69
  export interface UploadWire {
85
70
  n: number
86
71
  name: string
@@ -88,7 +73,8 @@ export interface UploadWire {
88
73
  type: string
89
74
  }
90
75
 
91
- /** a thread an advisor proposes on a project, written in `inbox/p/<project>/`: hostile input, pending on the Mac */
76
+ /** a thread an advisor proposes on a project (advice.ts landProposal): hostile input, pending in the owner's store or
77
+ * direct by the person's rights */
92
78
  export interface ProposalWire {
93
79
  v: 1
94
80
  at: string
@@ -110,36 +96,26 @@ export const FILE_MAX = 25 * 1024 * 1024
110
96
  export const FILES_MAX = 5
111
97
  export const UPLOADS_PENDING_MAX = 40
112
98
  export const FILE_NAME_MAX = 120
113
- /** an inbox entry's name, `<ms>-<random>`: the uploads of the entry sit under it */
99
+ /** an entry's name, `<ms>-<random>`: the uploads of the entry sit under it */
114
100
  export const ENTRY_RE = /^\d{13}-[A-Za-z0-9_-]{1,32}$/
115
101
 
116
102
  export const KEYS = {
117
- shares: 'shares.json',
118
103
  csrf: 'csrf.key',
119
- /** a person's password as the door wrote it, by the sha256 of their email: `{ gen, hash }` */
104
+ /** a person's password as the sign in wrote it, by the sha256 of their email: `{ gen, hash }` */
120
105
  password: (emailHash: string): string => `login/${emailHash}.json`,
121
106
  /** a code's one use, made once by the sign in that spends it */
122
107
  claim: (emailHash: string, gen: number): string => `login/${emailHash}.${gen}.claim`,
123
108
  /** one session, under its person: `{ email, gen, until }`, by the sha256 of its id */
124
109
  session: (emailHash: string, sidHash: string): string => `session/${emailHash}/${sidHash}.json`,
125
- /** the copy of one share: the hub's thread view, its list row, its manifest */
126
- view: (share: string): string => `view/${share}.json`,
127
- row: (share: string): string => `row/${share}.json`,
128
- files: (share: string): string => `files/${share}.json`,
129
- /** the advisor's read cursor on a share, the one other key the door writes */
110
+ /** every session of one person: the prefix a reset clears */
111
+ sessions: (emailHash: string): string => `session/${emailHash}/`,
112
+ /** the advisor's read cursor on a share, which the owner's pass pulls into the owner's store */
130
113
  reads: (share: string): string => `reads/${share}.json`,
131
- /** where a person is at the door, by the sha256 of their email: the thread open now and when they were last on each
132
- * (edge/here.ts); the owner's hub alone reads it */
114
+ /** where a person is on the advisors page, by the sha256 of their email: the thread open now and when they were
115
+ * last on each (edge/here.ts); the owner's hub alone reads it */
133
116
  here: (emailHash: string): string => `here/${emailHash}.json`,
134
- /** the beats the door refused, counted */
117
+ /** the beats the users' port refused, counted */
135
118
  hereRefused: 'here/refused.json',
136
- /** the advisors' page: its script and its stylesheet, by the sha256 of their bytes */
137
- app: (sha: string, ext: 'js' | 'css'): string => `app/${sha}.${ext}`,
138
- media: (sha: string): string => `media/${sha}.webp`,
139
- /** an advisor's own photo, 64 px, by the hash of its bytes */
140
- photo: (sha: string): string => `photo/${sha}.webp`,
141
- inbox: (share: string): string => `inbox/${share}/`,
142
- proposals: (project: string): string => `inbox/p/${project}/`,
143
119
  /** the files of one entry: `s` a share's words, `p` a project's proposal */
144
120
  upload: (scope: 's' | 'p', id: string, entry: string): string => `upload/${scope}/${id}/${entry}/`,
145
121
  } as const
@@ -1,32 +1,32 @@
1
- // the owner sets the advisors' door up, once, with a setup token that lives a day (wiki tools/shipkit/advisors.md,
2
- // The door): `sk advisors expose` makes the Cloudflare Tunnel `rv-advisors`, its one ingress (the name to the door's
3
- // server on this Mac), stores its token in the vault, starts the process that runs cloudflared (cloudflared absent:
4
- // nothing is written) and waits for it to connect, points the name at it LAST,
5
- // then removes what the door was before (its Worker, its bucket, its Access apps). Each step checks first and writes
1
+ // the owner sets the advisors page up, once, with a setup token that lives a day (wiki tools/shipkit/advisors.md, Who
2
+ // calls: the users' port): `sk advisors expose` makes the Cloudflare Tunnel `rv-advisors`, its one ingress (the name
3
+ // to the users' port on this Mac), stores its token in the vault, starts the process that runs cloudflared
4
+ // (cloudflared absent: nothing is written) and waits for it to connect, points the name at it LAST,
5
+ // then removes what the advisors page ran on before the tunnel (a Worker, a bucket, Access apps). Each step checks first and writes
6
6
  // only what differs: a second run writes nothing. `check` proves from outside what the name answers
7
7
  // the one constraint a reader breaks first: no agent's process runs this (the cli refuses an agent's shell), and the
8
8
  // tunnel's token is never said: it goes from Cloudflare's answer to the vault
9
9
  import { authRefused, CfError, client, type Cf, type Fetch } from './cf-api.ts'
10
- import { TUNNEL_TOKEN } from './door.ts'
10
+ import { TUNNEL_TOKEN } from './reach.ts'
11
11
  import { PUBLIC_PAGES } from './edge/pages.ts'
12
- import { advisorsDoorPort } from './door-serve.ts'
12
+ import { usersPort } from './users-store.ts'
13
13
  import { TUNNEL_PROCESS, vaultRead, type TunnelStart } from './tunnel.ts'
14
14
  import { withState } from './owner-store.ts'
15
15
 
16
16
  export type { Fetch }
17
17
 
18
18
  export const TUNNEL_NAME = 'rv-advisors'
19
- /** what the door was before the tunnel, removed by the setup once the name points at the tunnel */
19
+ /** what the advisors page ran on before the tunnel, removed by the setup once the name points at the tunnel */
20
20
  export const OLD_WORKER = 'rv-advisors'
21
21
  export const OLD_BUCKET = 'rv-advisors'
22
- // sk-disable-next-line RV045 -- the advisors door reads the house's own setup token by this name
22
+ // sk-disable-next-line RV045 -- the advisors page's setup reads the house's own setup token by this name
23
23
  export const SETUP_SECRET = 'rv/cloudflare/advisors-setup'
24
24
  /** the token's rights, for its ask and for the words of a refused one */
25
25
  export const SETUP_RIGHTS = 'Account: Cloudflare Tunnel Edit, Access: Apps and Policies Edit, Access: Organizations, Identity Providers, and Groups Edit, Workers Scripts Edit, Workers R2 Storage Edit; Zone: DNS Edit, Workers Routes Edit'
26
26
 
27
- /** why the door was not set up, with what to do in its words; `token`: the setup token, missing or refused; `local`:
27
+ /** why the advisors page was not set up, with what to do in its words; `token`: the setup token, missing or refused; `local`:
28
28
  * this Mac lacks what the setup needs, nothing written at Cloudflare */
29
- export class DoorError extends Error {
29
+ export class SetupError extends Error {
30
30
  constructor(message: string, readonly kind: 'token' | 'local' | 'other' = 'other') {
31
31
  super(message)
32
32
  }
@@ -62,11 +62,11 @@ export const NO_CLOUDFLARED = 'cloudflared is not on this Mac, so the tunnel can
62
62
  type Tunnel = { id: string; name: string; status?: string; connections?: unknown[] }
63
63
  type Dns = { id: string; type: string; name: string; content: string; proxied?: boolean }
64
64
 
65
- /** the door set up, or found set up: every step checks first and writes only what differs */
66
- export async function setupDoor(o: SetupInput): Promise<{ account: string; tunnel: string }> {
65
+ /** the advisors page set up, or found set up: every step checks first and writes only what differs */
66
+ export async function setupAdvisors(o: SetupInput): Promise<{ account: string; tunnel: string }> {
67
67
  const say = o.say ?? (() => undefined)
68
68
  // before any write: a tunnel nothing here can connect is never made
69
- if (o.tunnel.bin() === null) throw new DoorError(NO_CLOUDFLARED, 'local')
69
+ if (o.tunnel.bin() === null) throw new SetupError(NO_CLOUDFLARED, 'local')
70
70
  const zoneName = o.host.slice(o.host.indexOf('.') + 1)
71
71
  const cf = client(o.token, o.fetch ?? fetch)
72
72
  const step = async <T>(run: () => Promise<{ value: T; words: string; wrote: boolean }>): Promise<T> => {
@@ -77,12 +77,12 @@ export async function setupDoor(o: SetupInput): Promise<{ account: string; tunne
77
77
  }
78
78
  // the token's first call: a refusal here is the token itself
79
79
  const zones = await cf<{ id: string; account: { id: string } }[]>('GET', `/zones?name=${encodeURIComponent(zoneName)}`).catch((e: unknown) => {
80
- throw authRefused(e) ? new DoorError(`Cloudflare refuses the setup token ${SETUP_SECRET}: it expired or was revoked. ${FRESH_TOKEN}. (Cloudflare said: ${e.message})`, 'token') : e
80
+ throw authRefused(e) ? new SetupError(`Cloudflare refuses the setup token ${SETUP_SECRET}: it expired or was revoked. ${FRESH_TOKEN}. (Cloudflare said: ${e.message})`, 'token') : e
81
81
  })
82
82
  const zone = zones[0]
83
83
  if (zone === undefined) throw new Error(`no zone ${zoneName} for this token`)
84
84
  const A = `/accounts/${zone.account.id}`
85
- const service = `http://127.0.0.1:${advisorsDoorPort()}`
85
+ const service = `http://127.0.0.1:${usersPort()}`
86
86
 
87
87
  const tunnel = await step(async () => {
88
88
  const found = list<Tunnel>(await cf('GET', `${A}/cfd_tunnel?name=${TUNNEL_NAME}&is_deleted=false`)).find((t) => t.name === TUNNEL_NAME)
@@ -111,7 +111,7 @@ export async function setupDoor(o: SetupInput): Promise<{ account: string; tunne
111
111
  if (refused !== null) throw new Error(`the process that runs cloudflared on this Mac (${TUNNEL_PROCESS}) did not start: ${refused}. The name still points where it did`)
112
112
  return { value: null, words: `cloudflared runs on this Mac (${TUNNEL_PROCESS})`, wrote: false }
113
113
  })
114
- // the name moves only once a connector stands: until then the old door keeps answering
114
+ // the name moves only once a connector stands: until then whatever it points at keeps answering
115
115
  await step(async () => {
116
116
  const w = o.wait ?? { tries: 45, ms: 2_000 }
117
117
  for (let i = 0; ; i++) {
@@ -148,8 +148,8 @@ export async function setupDoor(o: SetupInput): Promise<{ account: string; tunne
148
148
  return { account: zone.account.id, tunnel }
149
149
  }
150
150
 
151
- /** what the door was before: its Access apps and Google login, its Worker, its bucket. A refusal is a WARN, never the
152
- * run's failure: the door works without this */
151
+ /** what the advisors page ran on before the tunnel: its Access apps and Google login, its Worker, its bucket. A refusal
152
+ * is a WARN, never the run's failure: the advisors page works without this */
153
153
  async function leftovers(cf: Cf, A: string, host: string, say: (l: string) => void): Promise<void> {
154
154
  const t = performance.now()
155
155
  let wrote = 0
@@ -181,7 +181,7 @@ async function leftovers(cf: Cf, A: string, host: string, say: (l: string) => vo
181
181
  // R2 never turned on: no bucket to remove
182
182
  const r2 = await cf<{ buckets?: unknown }>('GET', `${A}/r2/buckets`).catch((e: unknown) => (e instanceof CfError && e.codes.includes(R2_OFF) ? { buckets: [] } : Promise.reject(e)))
183
183
  if (!list<{ name: string }>(r2.buckets).some((b) => b.name === OLD_BUCKET)) return
184
- // copies only: its objects first, then the bucket
184
+ // its objects first, then the bucket
185
185
  for (;;) {
186
186
  const objects = list<{ key: string }>(await cf('GET', `${A}/r2/buckets/${OLD_BUCKET}/objects`))
187
187
  if (objects.length === 0) break
@@ -193,17 +193,17 @@ async function leftovers(cf: Cf, A: string, host: string, say: (l: string) => vo
193
193
  say(`what the advisors page was before (its Access apps, its Worker, its bucket) ${wrote === 0 ? 'is gone, no change' : 'removed'} ${took(performance.now() - t)}`)
194
194
  }
195
195
 
196
- /** `sk advisors expose`: the setup token read, the setup run, where the door stands recorded. The caller has
196
+ /** `sk advisors expose`: the setup token read, the setup run, where the advisors page stands recorded. The caller has
197
197
  * refused an agent's process */
198
- export async function exposeDoor(o: { dir: string; cwd: string; host: string; say: (l: string) => void }, d: { tunnel: TunnelStart; read?: (name: string) => Promise<string | null>; store?: (name: string, value: string) => Promise<string | null>; fetch?: Fetch; wait?: SetupInput['wait']; now?: () => Date }): Promise<void> {
198
+ export async function exposeAdvisors(o: { dir: string; cwd: string; host: string; say: (l: string) => void }, d: { tunnel: TunnelStart; read?: (name: string) => Promise<string | null>; store?: (name: string, value: string) => Promise<string | null>; fetch?: Fetch; wait?: SetupInput['wait']; now?: () => Date }): Promise<void> {
199
199
  if ((await import('../hq/hq-role.ts')).hqRole() === 'joined') throw new Error('this machine joined the hq: the advisors page runs on the machine that carries the hq, run it there')
200
200
  const read = d.read ?? vaultRead(o.cwd)
201
201
  const token = await read(SETUP_SECRET).catch((e: Error) => {
202
- throw new DoorError(`the setup token ${SETUP_SECRET} could not be read: ${e.message}`, 'token')
202
+ throw new SetupError(`the setup token ${SETUP_SECRET} could not be read: ${e.message}`, 'token')
203
203
  })
204
- if (token === null) throw new DoorError(`the setup token ${SETUP_SECRET} is not stored. ${FRESH_TOKEN}`, 'token')
204
+ if (token === null) throw new SetupError(`the setup token ${SETUP_SECRET} is not stored. ${FRESH_TOKEN}`, 'token')
205
205
  const store = d.store ?? storeIn(o.cwd)
206
- const r = await setupDoor({ token, host: o.host, say: o.say, tunnel: d.tunnel, held: () => read(TUNNEL_TOKEN), store: (v) => store(TUNNEL_TOKEN, v), ...(d.fetch !== undefined ? { fetch: d.fetch } : {}), ...(d.wait !== undefined ? { wait: d.wait } : {}) })
206
+ const r = await setupAdvisors({ token, host: o.host, say: o.say, tunnel: d.tunnel, held: () => read(TUNNEL_TOKEN), store: (v) => store(TUNNEL_TOKEN, v), ...(d.fetch !== undefined ? { fetch: d.fetch } : {}), ...(d.wait !== undefined ? { wait: d.wait } : {}) })
207
207
  const at = (d.now?.() ?? new Date()).toISOString()
208
208
  withState(o.dir, (s) => {
209
209
  s.host = o.host
@@ -218,16 +218,16 @@ const storeIn = (cwd: string) => async (name: string, value: string): Promise<st
218
218
  return 'refused' in r ? r.refused : null
219
219
  }
220
220
 
221
- /** the routes `check` asks for with no session: each the door's 401. The front page is apart: with no session it
222
- * sends a visitor to the sign in (edge/handler.ts) */
221
+ /** the routes `check` asks for with no session: each the users' port's 401. The front page is apart: with no session
222
+ * it sends a visitor to the sign in (users-router.ts liveAnswer) */
223
223
  export const GUARDED_PROBES = ['/api/advisor/projects', '/api/advisor/photo', '/api/review/threads']
224
224
  const SIGN_IN = '/in'
225
- /** paths the door never answers: the owner's hub, lookalikes of the public pages, a made up login */
225
+ /** paths the users' port never answers: the owner's hub, lookalikes of the public pages, a made up login */
226
226
  export const NOTHING_PROBES = ['/api/home/vault', '/api/home/advisors', '/r/game/', '/api/live', '/about/', '/About', '/about-x', '/privacy/x', '/about%2F..%2Fapi%2Fadvisor%2Fprojects', `/in/${'A'.repeat(43)}`]
227
227
 
228
228
  /** from outside, with no session: the two public pages answer 200 with no script, the advisor's routes 401, everything
229
229
  * else the 404. The reasons it does not, empty when it holds */
230
- export async function checkDoor(host: string, f: Fetch = fetch): Promise<string[]> {
230
+ export async function checkAdvisors(host: string, f: Fetch = fetch): Promise<string[]> {
231
231
  const out: string[] = []
232
232
  const ask = async (path: string): Promise<Response | null> => {
233
233
  try {