rvlib-shipkit 2.31.0 → 2.33.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 (408) hide show
  1. package/CHANGELOG.md +51 -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 +122 -76
  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 +20 -221
  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 +27 -25
  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 +97 -183
  37. package/src/advisors/tunnel.ts +6 -5
  38. package/src/advisors/users-listen.ts +92 -0
  39. package/src/advisors/users-router.ts +261 -87
  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_Capacity.ts +6 -2
  67. package/src/cli/cmd_Checks.ts +0 -14
  68. package/src/cli/cmd_Ci.ts +2 -1
  69. package/src/cli/cmd_Db.ts +3 -82
  70. package/src/cli/cmd_Home.ts +4 -32
  71. package/src/cli/cmd_Hq.ts +0 -17
  72. package/src/cli/cmd_Releases.ts +57 -4
  73. package/src/cli/cmd_Review.ts +333 -354
  74. package/src/cli/cmd_Shot.ts +26 -4
  75. package/src/cli/cmd_SocialDrafts.ts +6 -13
  76. package/src/cli/cmd_ThreadSyncNeeds.ts +6 -2
  77. package/src/cli/cmd_Time.ts +1 -1
  78. package/src/cli/cmd_Trailer.ts +1 -1
  79. package/src/cli/inbox-hook-run.ts +5 -23
  80. package/src/cli/registry-heads.ts +5 -55
  81. package/src/cli/registry.ts +1 -5
  82. package/src/cli/review-here.ts +1 -1
  83. package/src/cli.ts +15 -4
  84. package/src/collections/collection-types.ts +1 -1
  85. package/src/collections/review.ts +5 -4
  86. package/src/core/admission.ts +268 -0
  87. package/src/core/agent-allow-policy.ts +32 -2
  88. package/src/core/agent-env.ts +8 -0
  89. package/src/core/allow-rows.ts +74 -0
  90. package/src/core/check-file-names.ts +19 -106
  91. package/src/core/code-lines.ts +36 -21
  92. package/src/core/footprint.ts +17 -13
  93. package/src/core/identities-root.ts +1 -4
  94. package/src/core/layout.ts +1 -2
  95. package/src/core/machine-db.ts +33 -208
  96. package/src/core/machine-layout.ts +14 -127
  97. package/src/core/machine-read.ts +5 -2
  98. package/src/core/mask-source.ts +60 -0
  99. package/src/core/memory-watch.ts +17 -14
  100. package/src/core/motherhome.ts +8 -35
  101. package/src/core/one-way-in-policy.ts +0 -3
  102. package/src/core/peer-sk.ts +8 -0
  103. package/src/core/repo-walk.ts +0 -9
  104. package/src/core/retention.ts +1 -9
  105. package/src/core/retired-checks.ts +2 -0
  106. package/src/core/tmux-policy.ts +1 -1
  107. package/src/core/tree-watch.ts +2 -2
  108. package/src/core/when.ts +7 -45
  109. package/src/gate/admit-heavy.ts +150 -0
  110. package/src/gate/check-runner.ts +6 -0
  111. package/src/gate/discover-checks.ts +42 -32
  112. package/src/gate/gate-checks.ts +21 -131
  113. package/src/gate/head-gate.ts +1 -1
  114. package/src/gate/job-run.ts +2 -1
  115. package/src/gate/pre-commit-discovery.ts +22 -28
  116. package/src/gate/run-check.ts +3 -4
  117. package/src/gate/run-ci.ts +4 -0
  118. package/src/gate/run-fix.ts +5 -17
  119. package/src/gate/run-fixers.ts +6 -42
  120. package/src/home/app-sign.ts +2 -2
  121. package/src/home/backup-status.ts +52 -92
  122. package/src/home/backup-verdict.ts +2 -2
  123. package/src/home/daemon-jobs.ts +51 -95
  124. package/src/home/database-words.ts +1 -2
  125. package/src/home/databases.ts +9 -25
  126. package/src/home/home-launchd.ts +0 -6
  127. package/src/home/home-paths.ts +8 -4
  128. package/src/home/home-routes.ts +3 -10
  129. package/src/home/home-state.ts +2 -14
  130. package/src/home/inbox-shape.ts +14 -15
  131. package/src/home/inbox.ts +1 -1
  132. package/src/home/machine-repair.ts +102 -103
  133. package/src/home/resume.ts +1 -15
  134. package/src/home/run-daemon.ts +7 -12
  135. package/src/home/space-page.ts +3 -2
  136. package/src/home/supervise.ts +3 -7
  137. package/src/hooks/commit-msg-run.ts +61 -0
  138. package/src/hooks/commit-run.ts +16 -166
  139. package/src/hooks/gate-outcome.ts +108 -0
  140. package/src/hooks/git-hook.ts +9 -9
  141. package/src/hooks/hook-config.ts +8 -8
  142. package/src/hooks/leak-guard.ts +1 -1
  143. package/src/hooks/pre-commit-checks.ts +1 -1
  144. package/src/hooks/run-hooks.ts +2 -6
  145. package/src/hooks/shared-file.ts +3 -2
  146. package/src/hq/daemon-db.ts +8 -8
  147. package/src/hq/door.ts +3 -16
  148. package/src/hq/hq-db.ts +4 -3
  149. package/src/hq/hq-local.ts +1 -2
  150. package/src/hq/hq-store.ts +0 -15
  151. package/src/hq/item-direct.ts +8 -10
  152. package/src/hq/item-fill.ts +37 -0
  153. package/src/hq/kinds/item-gone.ts +7 -10
  154. package/src/hq/kinds/item-msg.ts +12 -18
  155. package/src/hq/kinds/item.ts +13 -19
  156. package/src/hq/kinds/report.ts +3 -4
  157. package/src/hq/owner-switch.ts +3 -3
  158. package/src/hq/report.ts +5 -9
  159. package/src/hq/switch.ts +2 -11
  160. package/src/hq/thread-sync.ts +5 -17
  161. package/src/hq/{shapes-words.ts → threads-words.ts} +2 -12
  162. package/src/http/owner-word.ts +1 -1
  163. package/src/identities/machine.ts +16 -0
  164. package/src/init-repo.ts +0 -1
  165. package/src/ledger/check-stats.ts +6 -5
  166. package/src/ledger/db.ts +2 -4
  167. package/src/ledger/record-kept.ts +117 -48
  168. package/src/ledger/run-log.ts +21 -2
  169. package/src/ledger/slow-tests.ts +96 -0
  170. package/src/ledger/store.ts +3 -86
  171. package/src/ledger/suite-log.ts +8 -2
  172. package/src/media-store/backup/facts.ts +3 -37
  173. package/src/media-store/backup/keys.ts +1 -8
  174. package/src/media-store/backup/manifest.ts +6 -67
  175. package/src/media-store/backup/restore.ts +4 -13
  176. package/src/media-store/backup/retention.ts +13 -1
  177. package/src/media-store/backup/run.ts +6 -267
  178. package/src/media-store/backup/snapshot.ts +2 -38
  179. package/src/media-store/backup/sources.ts +3 -113
  180. package/src/media-store/backup/target-send.ts +5 -29
  181. package/src/media-store/db.ts +8 -7
  182. package/src/media-store/forget-one.ts +1 -1
  183. package/src/media-store/forget.ts +1 -80
  184. package/src/orchestrator/guards.ts +0 -1
  185. package/src/orchestrator/presence.ts +2 -2
  186. package/src/orchestrator/routes.ts +1 -1
  187. package/src/orchestrator/started.ts +0 -9
  188. package/src/orchestrator/talk-key.ts +3 -4
  189. package/src/orchestrator/unheard.ts +1 -1
  190. package/src/plan/planner.ts +3 -2
  191. package/src/recordings/edit.ts +3 -3
  192. package/src/recordings/marks-draw.ts +17 -6
  193. package/src/recordings/marks.ts +120 -9
  194. package/src/reflections/reflections-queue.ts +3 -10
  195. package/src/release/notes.ts +1 -1
  196. package/src/release/public-clean.ts +66 -6
  197. package/src/release/run-bump.ts +11 -0
  198. package/src/release/run-release.ts +4 -0
  199. package/src/releases/from-thread.ts +3 -3
  200. package/src/releases/model.ts +186 -36
  201. package/src/releases/store.ts +13 -3
  202. package/src/releases/validate.ts +83 -0
  203. package/src/repo-config.ts +36 -64
  204. package/src/review/answer-kinds.ts +63 -4
  205. package/src/review/blocked-guard.ts +11 -0
  206. package/src/review/blocked-object.ts +298 -0
  207. package/src/review/cells.ts +144 -230
  208. package/src/review/close.ts +39 -1
  209. package/src/review/doc-save.ts +3 -2
  210. package/src/review/draft-item.ts +1 -1
  211. package/src/review/events.ts +3 -7
  212. package/src/review/expect.ts +23 -39
  213. package/src/review/format.ts +79 -46
  214. package/src/review/glyphs.ts +1 -0
  215. package/src/review/hand-over.ts +3 -3
  216. package/src/review/heard.ts +1 -1
  217. package/src/review/holds-sync.ts +2 -1
  218. package/src/review/inbox-hook.ts +2 -2
  219. package/src/review/inbox-read.ts +39 -33
  220. package/src/review/instruction-guards.ts +12 -0
  221. package/src/review/instructions.ts +0 -1
  222. package/src/review/item-db.ts +13 -43
  223. package/src/review/item-hq.ts +2 -2
  224. package/src/review/item-rows.ts +3 -14
  225. package/src/review/kind-catalog.ts +3 -1
  226. package/src/review/kinds.ts +18 -8
  227. package/src/review/live-view.ts +3 -0
  228. package/src/review/media-kind.ts +1 -1
  229. package/src/review/mentions.ts +1 -2
  230. package/src/review/model.ts +158 -114
  231. package/src/review/move.ts +149 -0
  232. package/src/review/need-threads.ts +3 -2
  233. package/src/review/object-card.ts +11 -0
  234. package/src/review/object-read.ts +6 -1
  235. package/src/review/one-block.ts +1 -1
  236. package/src/review/owner-read.ts +1 -1
  237. package/src/review/phone-push.ts +10 -9
  238. package/src/review/previews.ts +32 -4
  239. package/src/review/push.ts +2 -2
  240. package/src/review/recap.ts +129 -0
  241. package/src/review/referring.ts +6 -3
  242. package/src/review/reflection-object.ts +4 -3
  243. package/src/review/routes.ts +51 -47
  244. package/src/review/secret-route.ts +3 -2
  245. package/src/review/settle.ts +0 -6
  246. package/src/review/snooze.ts +5 -3
  247. package/src/review/speaker.ts +68 -0
  248. package/src/review/start-title.ts +19 -0
  249. package/src/review/store-parties.ts +28 -0
  250. package/src/review/store.ts +94 -59
  251. package/src/review/{wakes.ts → thread-events.ts} +92 -7
  252. package/src/review/thread-md.ts +35 -14
  253. package/src/review/thread-state.ts +804 -0
  254. package/src/review/threads.ts +29 -347
  255. package/src/review/traces.ts +104 -7
  256. package/src/review/trailer-item.ts +1 -1
  257. package/src/review/unit.ts +7 -9
  258. package/src/review/verdict-items.ts +12 -10
  259. package/src/review/view-layout.ts +25 -1
  260. package/src/review/watch-feed.ts +1 -2
  261. package/src/review/working-guards.ts +2 -3
  262. package/src/rules/untrack-generated.ts +1 -15
  263. package/src/secrets/copy.ts +4 -4
  264. package/src/secrets/lapse.ts +2 -1
  265. package/src/serve/hub-app/advisor-app.tsx +4 -4
  266. package/src/serve/hub-app/advisor-face.tsx +9 -3
  267. package/src/serve/hub-app/advisor-host.ts +27 -27
  268. package/src/serve/hub-app/advisors-model.ts +17 -8
  269. package/src/serve/hub-app/advisors-rights.tsx +1 -1
  270. package/src/serve/hub-app/advisors-st.ts +15 -14
  271. package/src/serve/hub-app/advisors-view.tsx +13 -11
  272. package/src/serve/hub-app/app-bridge.ts +23 -3
  273. package/src/serve/hub-app/asks-page.tsx +1 -1
  274. package/src/serve/hub-app/auto-text.tsx +71 -16
  275. package/src/serve/hub-app/check-view.tsx +0 -8
  276. package/src/serve/hub-app/controls.css +14 -3
  277. package/src/serve/hub-app/database-view.tsx +1 -2
  278. package/src/serve/hub-app/dock-st.ts +1 -1
  279. package/src/serve/hub-app/git-view.tsx +3 -1
  280. package/src/serve/hub-app/hub.css +12 -5
  281. package/src/serve/hub-app/icons.tsx +1 -1
  282. package/src/serve/hub-app/inbox-view.tsx +1 -2
  283. package/src/serve/hub-app/live-sources.ts +2 -2
  284. package/src/serve/hub-app/main-panel.tsx +2 -1
  285. package/src/serve/hub-app/panel-repo.ts +0 -9
  286. package/src/serve/hub-app/pic.tsx +29 -12
  287. package/src/serve/hub-app/polled.ts +16 -2
  288. package/src/serve/hub-app/recordings-st.ts +23 -2
  289. package/src/serve/hub-app/recordings-view.tsx +68 -10
  290. package/src/serve/hub-app/ref-pill.ts +1 -1
  291. package/src/serve/hub-app/repo-st.ts +1 -2
  292. package/src/serve/hub-app/review/advisor-add.tsx +1 -1
  293. package/src/serve/hub-app/review/advisor-invite.tsx +1 -1
  294. package/src/serve/hub-app/review/draft-body.tsx +2 -2
  295. package/src/serve/hub-app/review/heard-line.tsx +1 -1
  296. package/src/serve/hub-app/review/instructions-view.tsx +1 -8
  297. package/src/serve/hub-app/review/kind-states.tsx +14 -9
  298. package/src/serve/hub-app/review/kit.tsx +4 -11
  299. package/src/serve/hub-app/review/lane-bar.tsx +3 -3
  300. package/src/serve/hub-app/review/lightbox.tsx +15 -11
  301. package/src/serve/hub-app/review/line-window.ts +4 -1
  302. package/src/serve/hub-app/review/live-bar-st.ts +2 -2
  303. package/src/serve/hub-app/review/live-view.tsx +57 -1
  304. package/src/serve/hub-app/review/object-panel.tsx +20 -8
  305. package/src/serve/hub-app/review/question-views.tsx +191 -53
  306. package/src/serve/hub-app/review/recap-bar.tsx +40 -0
  307. package/src/serve/hub-app/review/request-cell.tsx +48 -0
  308. package/src/serve/hub-app/review/review-cells.tsx +154 -96
  309. package/src/serve/hub-app/review/review-host.ts +8 -4
  310. package/src/serve/hub-app/review/review-kit.ts +17 -11
  311. package/src/serve/hub-app/review/review-list.tsx +30 -35
  312. package/src/serve/hub-app/review/review-st.ts +32 -42
  313. package/src/serve/hub-app/review/review-thread.tsx +139 -85
  314. package/src/serve/hub-app/review/review-views.tsx +127 -68
  315. package/src/serve/hub-app/review/share-lines.tsx +4 -4
  316. package/src/serve/hub-app/review/start-st.ts +2 -5
  317. package/src/serve/hub-app/review/superseded-runs.ts +4 -3
  318. package/src/serve/hub-app/review/thread-close.tsx +10 -7
  319. package/src/serve/hub-app/review/thread-st.ts +381 -202
  320. package/src/serve/hub-app/review/tone-bar.tsx +129 -0
  321. package/src/serve/hub-app/review/tones.ts +53 -0
  322. package/src/serve/hub-app/review/trailer-body.tsx +2 -2
  323. package/src/serve/hub-app/review/trailer-st.ts +3 -2
  324. package/src/serve/hub-app/review/trailer-voices-st.ts +3 -2
  325. package/src/serve/hub-app/review.css +189 -106
  326. package/src/serve/hub-app/search-view.tsx +1 -1
  327. package/src/serve/hub-app/social/social-model.ts +0 -4
  328. package/src/serve/hub-app/source-acts.ts +2 -1
  329. package/src/serve/hub-app/stores/stores-page.tsx +2 -2
  330. package/src/serve/hub-app/terminal-sources.tsx +2 -1
  331. package/src/serve/hub-app/thread-row.tsx +3 -4
  332. package/src/serve/hub-app/tree-build.ts +0 -4
  333. package/src/serve/hub-app/urls-view.tsx +2 -1
  334. package/src/serve/hub-app/view-layout.css +13 -3
  335. package/src/serve/hub-app/wikis-view.tsx +5 -2
  336. package/src/serve/hub-runtime.ts +7 -37
  337. package/src/serve/project-gutter-route.ts +6 -2
  338. package/src/serve/read-thread.ts +20 -2
  339. package/src/serve/read-worker.ts +9 -1
  340. package/src/serve/record-pages.ts +46 -0
  341. package/src/serve/serve-hub.ts +2 -2
  342. package/src/serve/terminal-host.ts +1 -1
  343. package/src/serve/terminal-route.ts +1 -3
  344. package/src/serve/tracked-watch.ts +1 -3
  345. package/src/setup-house.ts +2 -2
  346. package/src/shipkit-files.ts +1 -1
  347. package/src/shipkit.ts +1 -6
  348. package/src/shot/client.ts +2 -1
  349. package/src/shot/film-box.ts +0 -20
  350. package/src/shot/on-place.ts +141 -0
  351. package/src/social/drafts.ts +1 -1
  352. package/src/social/kinds.ts +6 -29
  353. package/src/social/load.ts +2 -2
  354. package/src/social/post-object.ts +3 -2
  355. package/src/social/release-stage.ts +1 -1
  356. package/src/social/stage.ts +2 -2
  357. package/src/stores/model.ts +4 -0
  358. package/src/stores/routes.ts +11 -3
  359. package/src/suite/judge-suites.ts +58 -0
  360. package/src/suite/red-alone.ts +54 -18
  361. package/src/suite/runner-shapes.ts +2 -2
  362. package/src/suite/suite-cli.ts +67 -14
  363. package/src/suite/test-units.ts +2 -1
  364. package/src/urls/fill.ts +1 -1
  365. package/src/urls/places.ts +1 -2
  366. package/src/vault/vault-config.ts +2 -2
  367. package/src/vault/vault-init.ts +1 -5
  368. package/src/wiki/graph-page.ts +14 -2
  369. package/src/advisors/copy-truth.ts +0 -49
  370. package/src/advisors/door-child.ts +0 -112
  371. package/src/advisors/door-serve.ts +0 -52
  372. package/src/advisors/door.ts +0 -118
  373. package/src/checks/SK016-legacy-check-shapes.check.ts +0 -189
  374. package/src/checks/SK029-explicit-check-files.check.ts +0 -112
  375. package/src/checks/SK048-one-local-file.check.ts +0 -36
  376. package/src/core/config-rewrite.ts +0 -111
  377. package/src/core/daemon-port.ts +0 -10
  378. package/src/core/legacy-shapes.ts +0 -263
  379. package/src/core/migrate-layout.ts +0 -638
  380. package/src/core/port-check-cli.ts +0 -52
  381. package/src/core/port-check-file.ts +0 -295
  382. package/src/core/port-check-files.ts +0 -31
  383. package/src/gate/discover-legacy-checks.ts +0 -26
  384. package/src/home/home-move.ts +0 -527
  385. package/src/home/machine-fold.ts +0 -810
  386. package/src/hq/item-shapes.ts +0 -54
  387. package/src/hq/kinds/items-read.ts +0 -4
  388. package/src/media-store/backup/daemon.ts +0 -220
  389. package/src/media-store/backup/kept.ts +0 -241
  390. package/src/media-store/backup/prune.ts +0 -359
  391. package/src/media-store/backup/secret.ts +0 -88
  392. package/src/media-store/backup/ssh-space.ts +0 -202
  393. package/src/media-store/backup/watch.ts +0 -117
  394. package/src/review/band.ts +0 -182
  395. package/src/review/folders.ts +0 -216
  396. package/src/review/hook-ask.ts +0 -58
  397. package/src/review/role.ts +0 -48
  398. package/src/review/thread-fold.ts +0 -64
  399. package/src/review/wait.ts +0 -91
  400. package/src/rules/rule.ts +0 -43
  401. package/src/serve/hook-thread.ts +0 -37
  402. package/src/serve/hook-work.ts +0 -92
  403. package/src/serve/hook-worker.ts +0 -57
  404. package/src/serve/hub-app/review/dock.tsx +0 -147
  405. package/src/serve/hub-app/review/faces.tsx +0 -18
  406. package/src/serve/hub-app/review/item-verdict.tsx +0 -112
  407. package/src/serve/hub-app/review/review-board.tsx +0 -48
  408. /package/src/{scaffold → core}/jsonc-spans.ts +0 -0
@@ -1,145 +1,48 @@
1
- // the hub's review api as the advisors' page reads it (wiki tools/shipkit/advisors.md, The advisor's app): the same
2
- // paths the owner's hub answers, over the copies the Mac pushed (`view/`, `row/`, `files/`, `media/`). The door answers
3
- // them for the live shares of the signed in advisor; his hub answers them for one share in his preview, where every
4
- // write is refused. A write is never an act: it is one inbox entry, an advice that waits for him, or a read cursor
5
- // the one constraint a reader breaks first: every id a request names is found in that share's manifest, every
6
- // picture in its list, before anything is read or written; nothing else is reachable
7
- import { getJson, type Bucket, type Bytes } from './bucket.ts'
1
+ // what the users' port answers its page with besides a thread (wiki tools/shipkit/advisors.md, The advisor's app): the
2
+ // search text of a share, the fixed answers of the routes the page reads at its start, a read
3
+ // cursor, the files a page stages before the words that take them
4
+ // the one constraint a reader breaks first: a staged file is opaque bytes under its own token, named and typed only by
5
+ // what the browser said, cleaned (form.ts); its words take it, or the pass sweeps it within the hour
6
+ import { getJson, type Bucket } from './bucket.ts'
8
7
  import { bytesOf, cleanName, cleanType } from './form.ts'
9
- import {
10
- ADVICE_PENDING_MAX,
11
- ADVICE_PER_HOUR,
12
- ADVICE_TEXT_MAX,
8
+ import {
13
9
  FILE_MAX,
14
- FILES_MAX,
15
10
  KEYS,
16
11
  UPLOADS_PENDING_MAX,
17
- type AdviceWire,
18
- type UploadWire,
19
- type ServedShare,
20
- type ShareManifest,
21
- } from './types.ts'
12
+ type UploadWire } from './types.ts'
22
13
 
23
- /** a row of the list as the door reads it: what it sorts and counts by; the rest goes as the Mac built it */
24
- export interface CopyRow {
25
- head: string
26
- updated: string
27
- turn: string
28
- active: boolean
29
- waits: boolean
30
- unread: boolean
31
- [k: string]: unknown
32
- }
33
-
34
- /** a view as the door reads it: its head, its cells' times (the read cursor's range) */
35
- export interface CopyView {
36
- head: string
37
- asked: string
38
- cells: { id: string; at: string }[]
39
- [k: string]: unknown
40
- }
41
-
42
- /** where the reader's cursor stands on a share: the door's own clock, a cell's time of that share's view */
14
+ /** where the reader's cursor stands on a share: the port's own clock, a cell's time of that share's view */
43
15
  export interface ReadCursor {
44
16
  v: 1
45
17
  at: string
46
18
  upTo: string
47
19
  }
48
20
 
49
- export interface ApiCtx {
50
- bucket: Bucket
51
- /** the reader's live shares */
52
- shares: readonly (readonly [string, ServedShare])[]
53
- now: number
54
- /** the door's writes: the signed in email and a fresh id; null in his preview, which takes no answer */
55
- writes: { email: string; rand: () => string } | null
56
- /** headers every answer carries */
57
- headers: Record<string, string>
58
- }
59
-
60
21
  const STAGED_MAX = 40
61
22
  /** where the files the page sent wait for the words that take them: `s` a share's, `p` a project's new thread */
62
23
  export const STAGE = (scope: 's' | 'p', id: string): string => `stage/${scope}/${id}/`
63
24
  const TOKEN_RE = /^\d{13}-[A-Za-z0-9_-]{1,32}$/
64
- /** an id of a share's copy: the share, then the item it stands for */
25
+ /** an id of a share's view: the share, then the item it stands for */
65
26
  export const ID_RE = /^([A-Za-z0-9_-]{22})\.[0-9a-f]{12}$/
66
- const MSG_RE = /^m[0-9a-f]{12}$/
27
+ export const MSG_RE = /^m[0-9a-f]{12}$/
67
28
  /** a picture's name in a view: the hash of its bytes */
68
29
  export const NAME_RE = /^([0-9a-f]{64})\.webp$/
69
30
 
70
- /** the fixed answers of the routes the page reads at its start: one reader, no kind of his, no dispatcher, no lanes */
71
- const SPEC = { kinds: {}, topics: {}, dispatcher: false, role: null, sources: [], auto: [] }
72
- const PARTIES = { repo: '', parties: { sessions: [], lanes: [] } }
73
- const BOARD = { role: null, rows: [] }
31
+ /** the fixed answers of the routes the page reads at its start: one reader, no kind of his, no lanes */
32
+ export const SPEC = { kinds: {}, topics: {}, sources: [], auto: [] }
33
+ export const PARTIES = { repo: '', parties: { sessions: [], lanes: [] } }
74
34
 
75
35
  export async function etag(body: string): Promise<string> {
76
36
  const d = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(body)))
77
37
  return `"${[...d.slice(0, 12)].map((b) => b.toString(16).padStart(2, '0')).join('')}"`
78
38
  }
79
39
 
80
- const typeOf = (b: Bytes): string => (b[0] === 0x89 && b[1] === 0x50 ? 'image/png' : b[0] === 0xff && b[1] === 0xd8 ? 'image/jpeg' : 'image/webp')
81
-
82
40
  export async function readCursor(bucket: Bucket, share: string): Promise<ReadCursor | null> {
83
41
  const c = await getJson<ReadCursor>(bucket, KEYS.reads(share))
84
42
  return c !== null && c.v === 1 && typeof c.upTo === 'string' && typeof c.at === 'string' ? c : null
85
43
  }
86
44
 
87
- /** a request of the page, null when the path is not one of the api's */
88
- export async function copyApi(req: Request, path: string, ctx: ApiCtx): Promise<Response | null> {
89
- if (!path.startsWith('/api/review/')) return null
90
- const json = async (x: unknown, status = 200): Promise<Response> => {
91
- const body = JSON.stringify(x)
92
- const tag = await etag(body)
93
- if (status === 200 && req.headers.get('if-none-match') === tag) return new Response(null, { status: 304, headers: { ...ctx.headers, etag: tag } })
94
- return new Response(body, { status, headers: { ...ctx.headers, 'content-type': 'application/json', ...(status === 200 ? { etag: tag } : {}) } })
95
- }
96
- const no = (status: number, error: string): Response => new Response(JSON.stringify({ error }), { status, headers: { ...ctx.headers, 'content-type': 'application/json' } })
97
- const rest = path.slice('/api/review/'.length)
98
- const method = req.method.toUpperCase()
99
- const read = method === 'GET' || method === 'HEAD'
100
- if (read && rest === 'spec') return json(SPEC)
101
- if (read && rest === 'parties') return json(PARTIES)
102
- if (read && rest === 'board') return json(BOARD)
103
- if (read && rest === 'threads') return json(await pageOf(ctx, new URL(req.url).searchParams))
104
- const t = /^threads\/([^/]+)$/.exec(rest)
105
- if (read && t !== null) {
106
- const at = await shareOf(ctx, decodeURIComponent(t[1]!))
107
- if (at === null) return no(404, 'no such thread')
108
- const view = await getJson<CopyView>(ctx.bucket, KEYS.view(at.share))
109
- return view === null ? no(404, 'no such thread') : json({ ...view, asked: at.manifest.ids.includes(at.id) ? at.id : view.head })
110
- }
111
- const m = /^([^/]+)\/(?:preview\/(?:fit|thumb|tile)\/|thread\/)?([^/]+)$/.exec(rest)
112
- if (read && m !== null && NAME_RE.test(m[2]!)) {
113
- const at = await shareOf(ctx, decodeURIComponent(m[1]!))
114
- const sha = NAME_RE.exec(m[2]!)![1]!
115
- if (at === null || !at.manifest.images.includes(sha)) return no(404, 'no such picture')
116
- const bytes = await ctx.bucket.get(KEYS.media(sha))
117
- return bytes === null ? no(404, 'no such picture') : new Response(bytes, { headers: { ...ctx.headers, 'content-type': typeOf(bytes) } })
118
- }
119
- if (read) return no(404, 'no such route')
120
- if (method !== 'POST') return new Response('method not allowed', { status: 405, headers: ctx.headers })
121
- if (ctx.writes === null) return no(403, 'the preview takes no answer: this is what the advisor sees')
122
- const w = /^([^/]+)\/(read|feedback|answer|reply|upload)$/.exec(rest)
123
- if (w === null) return no(404, 'this is not an advice')
124
- const at = await shareOf(ctx, decodeURIComponent(w[1]!))
125
- if (at === null) return no(404, 'no such thread')
126
- return write(req, w[2] as Write, at, ctx, ctx.writes, json, no)
127
- }
128
-
129
- type Write = 'read' | 'feedback' | 'answer' | 'reply' | 'upload'
130
- type At = { share: string; id: string; manifest: ShareManifest }
131
-
132
- /** the share an id of the copy is in, by its prefix, while it is one of the reader's live shares and its manifest names it */
133
- async function shareOf(ctx: ApiCtx, id: string): Promise<At | null> {
134
- const share = ID_RE.exec(id)?.[1]
135
- if (share === undefined || !ctx.shares.some(([s]) => s === share)) return null
136
- const manifest = await getJson<ShareManifest>(ctx.bucket, KEYS.files(share))
137
- if (manifest === null || manifest.v !== 1 || !manifest.ids.includes(id)) return null
138
- return { share, id, manifest }
139
- }
140
-
141
- /** the list: one row a live share, newest first; unread from the reader's own cursor */
142
- /** every string of a json value, lowercased: a share's copy as its search reads it */
45
+ /** every string of a json value, lowercased: a share as its search reads it */
143
46
  export function wordsIn(v: unknown, out: string[] = [], depth = 0): string[] {
144
47
  if (depth > 12) return out
145
48
  if (typeof v === 'string') out.push(v.toLowerCase())
@@ -148,115 +51,6 @@ export function wordsIn(v: unknown, out: string[] = [], depth = 0): string[] {
148
51
  return out
149
52
  }
150
53
 
151
- /** the advisor's search: every word typed in the share's own copy, its row and its thread as the scan let them out.
152
- * Only the advisor's shares are read, so no other thread's words can match */
153
- async function holdsWords(ctx: ApiCtx, id: string, row: CopyRow, words: readonly string[]): Promise<boolean> {
154
- if (words.length === 0) return true
155
- const text = wordsIn([row, await getJson<unknown>(ctx.bucket, KEYS.view(id))]).join('\n')
156
- return words.every((w) => text.includes(w))
157
- }
158
-
159
- async function pageOf(ctx: ApiCtx, q: URLSearchParams): Promise<unknown> {
160
- const rows: CopyRow[] = []
161
- const words = (q.get('q') ?? '').toLowerCase().split(/\s+/).filter(Boolean)
162
- for (const [id] of ctx.shares) {
163
- const row = await getJson<CopyRow>(ctx.bucket, KEYS.row(id))
164
- if (row === null || (await getJson<ShareManifest>(ctx.bucket, KEYS.files(id))) === null) continue
165
- if (!(await holdsWords(ctx, id, row, words))) continue
166
- const cursor = await readCursor(ctx.bucket, id)
167
- rows.push({ ...row, unread: cursor === null || row.updated > cursor.upTo })
168
- }
169
- return pageOfRows(rows, q)
170
- }
171
-
172
- /** the list's page over the rows a reader may see, as the hub's own list answers it */
173
- export function pageOfRows(rows: CopyRow[], q: URLSearchParams): unknown {
174
- rows.sort((a, b) => b.updated.localeCompare(a.updated))
175
- const limit = Math.max(1, Math.min(500, Number(q.get('limit')) || 50))
176
- const offset = Math.max(0, Number(q.get('offset')) || 0)
177
- return {
178
- rows: rows.slice(offset, offset + limit),
179
- total: rows.length,
180
- offset,
181
- limit,
182
- counts: { threads: rows.length, active: rows.filter((r) => r.active).length, waiting: rows.filter((r) => r.turn === 'yours').length, unread: rows.filter((r) => r.unread).length },
183
- byWait: {},
184
- subjects: [],
185
- lanes: [],
186
- broken: [],
187
- since: null,
188
- }
189
- }
190
-
191
- async function body(req: Request, max = 16 * 1024): Promise<Record<string, unknown> | null> {
192
- const raw = await req.text()
193
- if (raw.length > max) return null
194
- try {
195
- const v = JSON.parse(raw) as unknown
196
- return v !== null && typeof v === 'object' && !Array.isArray(v) ? (v as Record<string, unknown>) : null
197
- } catch {
198
- return null
199
- }
200
- }
201
-
202
- const hourOf = (keys: readonly string[], now: number): number => keys.filter((k) => Number(/\/(\d{13})-[^/]+\.json$/.exec(k)?.[1] ?? 0) > now - 3_600_000).length
203
-
204
- async function write(req: Request, kind: Write, at: At, ctx: ApiCtx, w: NonNullable<ApiCtx['writes']>, json: (x: unknown, s?: number) => Promise<Response>, no: (s: number, e: string) => Response): Promise<Response> {
205
- const { bucket, now } = ctx
206
- if (kind === 'upload') {
207
- const r = await stageFile(req, 's', at.share, { bucket, now, rand: w.rand })
208
- return 'token' in r ? json(r) : no(r.status, r.error)
209
- }
210
- const b = await body(req)
211
- if (b === null) return no(400, 'a body of at most 16 KB, a JSON object')
212
- if (kind === 'read') {
213
- // forward only, a time one of that share's cells holds, the door's clock beside it: no string the page chose
214
- const view = await getJson<CopyView>(bucket, KEYS.view(at.share))
215
- const upTo = typeof b['upTo'] === 'string' ? b['upTo'] : ''
216
- if (view === null || !view.cells.some((c) => c.at === upTo)) return no(400, 'no such moment in this thread')
217
- const was = await readCursor(bucket, at.share)
218
- if (was === null || upTo > was.upTo) await bucket.put(KEYS.reads(at.share), JSON.stringify({ v: 1, at: new Date(now).toISOString(), upTo } satisfies ReadCursor), 'application/json')
219
- return json({ ok: true })
220
- }
221
- const text = typeof b['text'] === 'string' ? b['text'].trim() : typeof b['comment'] === 'string' ? b['comment'].trim() : ''
222
- if (text.length > ADVICE_TEXT_MAX) return no(400, `at most ${ADVICE_TEXT_MAX} characters`)
223
- let advice: Omit<AdviceWire, 'v' | 'at' | 'email'>
224
- let files: string[] = []
225
- if (kind === 'feedback') {
226
- const judge = at.manifest.judge.find((j) => j.item === at.id)
227
- if (judge === undefined) return no(409, 'this version does not wait for a verdict, or a newer one does: open it again')
228
- if (b['status'] === 'approved') advice = { kind: 'approve', item: at.id, version: judge.version, ...(text !== '' ? { text } : {}) }
229
- else if (b['status'] === 'approved-with-fix') {
230
- if (text === '') return no(400, 'say what you would change')
231
- advice = { kind: 'change', item: at.id, version: judge.version, text }
232
- } else return no(403, 'an advisor approves or says what they would change')
233
- } else if (kind === 'answer') {
234
- const re = typeof b['re'] === 'string' && MSG_RE.test(b['re']) ? b['re'] : ''
235
- const q = at.manifest.questions.find((x) => x.cell === `${at.id}/${re}`)
236
- const option = b['option']
237
- if (q === undefined) return no(409, 'this question is answered or changed: open it again')
238
- if (typeof option !== 'number' || !Number.isInteger(option) || option < 0 || option >= q.options) return no(400, 'no such option')
239
- advice = { kind: 'pick', item: at.id, message: re, option, qhash: q.qhash, ...(text !== '' ? { text } : {}) }
240
- } else {
241
- const given = tokensOf(b['files'])
242
- if (!given.every((x): x is string => typeof x === 'string' && TOKEN_RE.test(x))) return no(400, 'a file of yours is not one the page staged: add it again')
243
- files = given
244
- if (files.length > FILES_MAX) return no(400, `at most ${FILES_MAX} files`)
245
- if (text === '' && files.length === 0) return no(400, 'your words are empty')
246
- advice = { kind: 'words', ...(text !== '' ? { text } : {}) }
247
- }
248
- const pending = await bucket.list(KEYS.inbox(at.share))
249
- if (pending.length >= ADVICE_PENDING_MAX || hourOf(pending, now) >= ADVICE_PER_HOUR) return no(429, 'enough advice for now: try again in an hour')
250
- const entry = `${now}-${w.rand()}`
251
- // the files first, moved under the entry from where the page staged them; the record last, naming only files that are there
252
- const metas = await takeStaged(bucket, 's', at.share, files, entry)
253
- if (typeof metas === 'string') return no(400, metas)
254
- const wire: AdviceWire = { v: 1, at: new Date(now).toISOString(), email: w.email, ...advice, ...(metas.length > 0 ? { files: metas } : {}) }
255
- await bucket.put(`${KEYS.inbox(at.share)}${entry}.json`, JSON.stringify(wire), 'application/json')
256
- await dropStaged(bucket, 's', at.share, files)
257
- return json({ ok: true, waits: true })
258
- }
259
-
260
54
  /** the staged files of some words moved under their entry, in their order: what the record names, or why not */
261
55
  export async function takeStaged(bucket: Bucket, scope: 's' | 'p', id: string, tokens: readonly string[], entry: string): Promise<UploadWire[] | string> {
262
56
  const out: UploadWire[] = []
@@ -292,6 +86,11 @@ export async function stageFile(req: Request, scope: 's' | 'p', id: string, o: {
292
86
  return { token }
293
87
  }
294
88
 
89
+ /** the files moved under an entry the port then refused: nothing waits under words that were not kept */
90
+ export async function dropEntry(bucket: Bucket, scope: 's' | 'p', id: string, entry: string): Promise<void> {
91
+ for (const k of await bucket.list(`upload/${scope}/${id}/${entry}/`)) await bucket.delete(k)
92
+ }
93
+
295
94
  /** the staged files some words name: each a token, or the hub's `{ token, name }` (thread-st.ts sendReply) */
296
95
  export const tokensOf = (v: unknown): unknown[] => (Array.isArray(v) ? v.map((x: unknown) => (x !== null && typeof x === 'object' && 'token' in x ? x.token : x)) : [])
297
96
 
@@ -1,5 +1,5 @@
1
- // the advisors' bucket as the door reads it: a folder on the hq Mac (dir-bucket.ts), memory in tests and in the hub's
2
- // preview
1
+ // the users' port's folder as the port reads it: a folder on the hq Mac (dir-bucket.ts), memory in tests and in the
2
+ // hub's preview
3
3
 
4
4
  /** the bytes of an object: what WebCrypto and a Response take */
5
5
  export type Bytes = Uint8Array<ArrayBuffer>
@@ -1,20 +1,14 @@
1
- // the advisors' door (wiki tools/shipkit/advisors.md, The advisors page and its server): the advisors' app and the read only copy of the hub's
2
- // review api it reads, behind a session the sign in opened (sign-in.ts). Anyone reaches it through the tunnel, so it
3
- // answers only its own name, `/in`, the two public pages (pages.ts) and, for a valid session, the advisor's routes;
4
- // the list of who may sign in and the live shares are read from the bucket on EVERY request. What an advisor sends is the one thing
5
- // it writes: an advice, a thread they propose, a read cursor, the end of their own session. A missing, expired, revoked or another advisor's share
6
- // or project all get the one 404
7
- // the one constraint a reader breaks first: no cache of authority, no route beyond the list in routeOf, no owner route
8
- // ever; the page's script is only the pair the sync pinned (`app`), its bytes hashed again before they are served
9
- import { copyApi, dropStaged, stageFile, takeStaged, TOKEN, tokensOf } from './api.ts'
10
- import { getJson, type Bucket, type Bytes } from './bucket.ts'
11
- import { hereBeat } from './here.ts'
12
- import { factsOf, pageHtml, PUBLIC_PAGES, type PageFacts, type PublicPage } from './pages.ts'
13
- import { limits as newLimits, sameText, SESSION_COOKIE, sessionOf, sha256, SIGN_IN_CSP, signIn, signInPage, type Limits, type PasswordHasher } from './sign-in.ts'
14
- import { APP_CSP, appShell } from './shell.ts'
1
+ // what every answer of the users' port carries (wiki tools/shipkit/advisors.md, Who calls): its headers, its status
2
+ // pages, the page's write token. The port itself is advisors/users-router.ts; these stay here, beside the sign in and
3
+ // the pages, so the edge folder holds the port's words and none of its reads
4
+ // the one constraint a reader breaks first: a write's token is an HMAC over its scope, the email and the session, never
5
+ // a value the page chose
6
+ import type { Bucket, Bytes } from './bucket.ts'
7
+ import type { PageFacts } from './pages.ts'
8
+ import type { Limits, PasswordHasher } from './sign-in.ts'
15
9
  import { pageResponse, renderStatus, STATUS_CSP } from './status.ts'
16
- import { ADVICE_TEXT_MAX, FILES_MAX, KEYS, PROPOSAL_TITLE_MAX, PROPOSALS_PENDING_MAX, PROPOSALS_PER_HOUR, SHARE_ID_RE, type ProposalWire, type ServedProject, type ServedShare, type SharesFile } from './types.ts'
17
10
 
11
+ /** what the users' port runs over: its folder, its one name, the public pages' facts, the clock */
18
12
  export interface EdgeEnv {
19
13
  bucket: Bucket
20
14
  /** the advisors' name (`advisors.<domain>`): the one Host it answers, the one Origin a write may carry; null refuses
@@ -23,11 +17,11 @@ export interface EdgeEnv {
23
17
  /** who the public pages name; absent, « the owner » and no contact */
24
18
  pages?: PageFacts
25
19
  now?: () => number
26
- /** an id for an inbox key (tests fix it) */
20
+ /** an id for a staged file or an entry (tests fix it) */
27
21
  rand?: () => string
28
- /** the failed tries of `/in`; absent, the module's own */
22
+ /** the failed tries of `/in`; absent, the port's own */
29
23
  limits?: Limits
30
- /** argon2id, from the door's server; absent, no sign in */
24
+ /** argon2id; absent, no sign in */
31
25
  password?: PasswordHasher
32
26
  }
33
27
 
@@ -45,12 +39,8 @@ export const BASE: Record<string, string> = {
45
39
 
46
40
  export const status = (code: number, title: string, words: string): Response => pageResponse(renderStatus(title, words), { status: code, csp: STATUS_CSP, headers: BASE })
47
41
  export const NOT_FOUND = (): Response => status(404, 'Not found', 'There is nothing here, or it is no longer shared with you.')
48
- const NO_METHOD = (): Response => new Response('method not allowed', { status: 405, headers: { ...BASE, 'content-type': 'text/plain' } })
49
-
50
- const live = (s: ServedShare, now: number): boolean => Date.parse(s.expires) > now
51
42
 
52
43
  export const bytesB64url = (b: Uint8Array): string => btoa(String.fromCharCode(...b)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
53
- const hex = (b: Uint8Array): string => [...b].map((x) => x.toString(16).padStart(2, '0')).join('')
54
44
 
55
45
  /** who a session is: their email, and the hash of the session */
56
46
  export interface Who {
@@ -58,140 +48,8 @@ export interface Who {
58
48
  login: string
59
49
  }
60
50
 
61
- /** the token of the page's writes: an HMAC with the key the Mac wrote, over a scope, the email and the session */
51
+ /** the token of the page's writes: an HMAC with the port's key, over a scope, the email and the session */
62
52
  export async function csrfOf(key: Bytes, scope: string, who: Who): Promise<string> {
63
53
  const k = await crypto.subtle.importKey('raw', key, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
64
54
  return bytesB64url(new Uint8Array(await crypto.subtle.sign('HMAC', k, new TextEncoder().encode(`${scope}|${who.email}|${who.login}`))))
65
55
  }
66
-
67
- const DEFAULT_LIMITS = newLimits()
68
-
69
- type Route = { r: 'health' } | { r: 'page'; page: PublicPage } | { r: 'in' } | { r: 'shell' } | { r: 'app'; sha: string; ext: 'js' | 'css' } | { r: 'projects' } | { r: 'photo' } | { r: 'start'; id: string } | { r: 'upload'; id: string } | { r: 'here' } | { r: 'out' } | { r: 'api' }
70
-
71
- function routeOf(path: string): Route | null {
72
- if (path === '/health') return { r: 'health' }
73
- // exact: no trailing slash, no other case, no prefix, no file below
74
- const page = PUBLIC_PAGES.find((x) => x === path)
75
- if (page !== undefined) return { r: 'page', page }
76
- if (path === '/in') return { r: 'in' }
77
- if (path === '/') return { r: 'shell' }
78
- const a = /^\/app\/([0-9a-f]{64})\.(js|css)$/.exec(path)
79
- if (a !== null) return { r: 'app', sha: a[1]!, ext: a[2] as 'js' | 'css' }
80
- if (path === '/api/advisor/projects') return { r: 'projects' }
81
- if (path === '/api/advisor/photo') return { r: 'photo' }
82
- if (path === '/api/advisor/here') return { r: 'here' }
83
- if (path === '/api/advisor/out') return { r: 'out' }
84
- const s = /^\/api\/advisor\/(start|upload)\/([^/]+)$/.exec(path)
85
- if (s !== null && SHARE_ID_RE.test(s[2]!)) return { r: s[1] as 'start' | 'upload', id: s[2]! }
86
- if (/^\/api\/review\/[A-Za-z0-9_.~-]+(\/[A-Za-z0-9_.~-]+){0,3}$/.test(path) && !path.includes('..')) return { r: 'api' }
87
- return null
88
- }
89
-
90
- const writes = (r: Route): boolean => r.r === 'in' || r.r === 'start' || r.r === 'upload' || r.r === 'here' || r.r === 'out' || r.r === 'api'
91
-
92
- export async function handle(req: Request, env: EdgeEnv): Promise<Response> {
93
- const now = (env.now ?? Date.now)()
94
- // its own name only: a page of another site rebound to this port, or any other name, is nothing here
95
- if (env.host === null || (req.headers.get('host') ?? new URL(req.url).host).toLowerCase() !== env.host) return NOT_FOUND()
96
- const url = new URL(req.url)
97
- const route = routeOf(url.pathname)
98
- if (route === null) return NOT_FOUND()
99
- const method = req.method.toUpperCase()
100
- const read = method === 'GET' || method === 'HEAD'
101
- if (!read && !(method === 'POST' && writes(route))) return NO_METHOD()
102
- // a thread they start and its files are writes only: never a GET, which skips the origin and the token below
103
- if ((route.r === 'start' || route.r === 'upload' || route.r === 'here' || route.r === 'out') && method !== 'POST') return NO_METHOD()
104
- if (route.r === 'health') return new Response('ok', { headers: { ...BASE, 'content-type': 'text/plain' } })
105
- // fixed words, before any session and before any read of the bucket
106
- if (route.r === 'page') return pageResponse(pageHtml(route.page, env.pages ?? factsOf(undefined, undefined)), { csp: STATUS_CSP, headers: BASE })
107
- const file = await getJson<SharesFile>(env.bucket, KEYS.shares)
108
- const owner = file?.owner ?? 'the owner'
109
- if (route.r === 'in') {
110
- // its referrer policy is the page's own (sign-in.ts): the origin check below meets what its form really sends
111
- const page = (code: number, said?: string): Response => pageResponse(signInPage(owner, said), { status: code, csp: SIGN_IN_CSP, headers: BASE })
112
- if (read) return page(200)
113
- if (req.headers.get('origin') !== `https://${env.host}`) return status(403, 'Forbidden', 'This was not sent from the sign in page.')
114
- const r = await signIn(req, { bucket: env.bucket, file, now, limits: env.limits ?? DEFAULT_LIMITS, password: env.password })
115
- return r.ok ? new Response(null, { status: 303, headers: { ...BASE, location: '/', 'set-cookie': r.cookie } }) : page(r.status, r.said)
116
- }
117
- const who = await sessionOf(req, { bucket: env.bucket, file, now })
118
- if (who === null) return route.r === 'shell' ? new Response(null, { status: 303, headers: { ...BASE, location: '/in' } }) : status(401, 'Not signed in', `Sign in again at /in, or ask ${owner} for a new code.`)
119
- const key = await env.bucket.get(KEYS.csrf)
120
- if (!read) {
121
- // a write comes from the page itself: its own origin, and the token its shell carries for this session
122
- if (req.headers.get('origin') !== `https://${env.host}`) return status(403, 'Forbidden', 'This was not sent from the advisors page.')
123
- if (key === null) return status(503, 'Not open', 'Nothing is taken right now.')
124
- if (!sameText(req.headers.get(CSRF_HEADER) ?? '', await csrfOf(key, 'app', who))) return status(403, 'Forbidden', 'This page is out of date: open it again.')
125
- }
126
- const mine = Object.entries(file?.shares ?? {}).filter(([, s]) => s.email === who.email && live(s, now))
127
- const projects: [string, ServedProject][] = Object.entries(file?.projects ?? {}).filter(([, p]) => p.email === who.email)
128
- const pin = /^([0-9a-f]{64})\.([0-9a-f]{64})$/.exec(file?.app ?? '')
129
- // the reader's own face: from their live shares and projects alone, never another advisor's
130
- const me = mine[0]?.[1] ?? projects[0]?.[1]
131
- const photo = [...mine.map(([, s]) => s.photo), ...projects.map(([, p]) => p.photo)].find((x) => x !== undefined && /^[0-9a-f]{64}$/.test(x))
132
- if (route.r === 'shell') {
133
- if (pin === null) return status(503, 'Not open', 'This page is not ready yet.')
134
- const csrf = key === null ? '' : await csrfOf(key, 'app', who)
135
- // his name as the reader's own grants read it: the one they all agree on, else his default
136
- const names = new Set([...mine.map(([, s]) => s.owner ?? owner), ...projects.map(([, p]) => p.owner)])
137
- return pageResponse(appShell({ app: '/app', js: pin[1]!, css: pin[2]!, base: '', csrf, name: 'shared with you', owner: names.size === 1 ? [...names][0]! : owner, ...(me !== undefined ? { me: me.name } : {}), ...(photo !== undefined ? { photo: photo.slice(0, 12) } : {}) }), { csp: APP_CSP, headers: BASE })
138
- }
139
- if (route.r === 'app') {
140
- if (pin === null || (route.ext === 'js' ? pin[1] : pin[2]) !== route.sha) return NOT_FOUND()
141
- const bytes = await env.bucket.get(KEYS.app(route.sha, route.ext))
142
- if (bytes === null || hex(new Uint8Array(await crypto.subtle.digest('SHA-256', bytes))) !== route.sha) return NOT_FOUND()
143
- return new Response(bytes, { headers: { ...BASE, 'cache-control': 'private, max-age=31536000, immutable', 'content-type': route.ext === 'js' ? 'text/javascript; charset=utf-8' : 'text/css; charset=utf-8' } })
144
- }
145
- const json = (x: unknown, code = 200): Response => new Response(JSON.stringify(x), { status: code, headers: { ...BASE, 'content-type': 'application/json' } })
146
- if (route.r === 'photo') {
147
- const bytes = photo === undefined ? null : await env.bucket.get(KEYS.photo(photo))
148
- return bytes === null ? json({ error: 'no photo' }, 404) : new Response(bytes, { headers: { ...BASE, 'cache-control': 'private, max-age=86400', 'content-type': 'image/webp' } })
149
- }
150
- if (route.r === 'here') {
151
- // the thread their page has open: one of their own live shares or none; the answer says nothing of anyone
152
- const r = await hereBeat(await req.text(), { bucket: env.bucket, email: who.email, mine: mine.map(([id]) => id), now })
153
- return 'ok' in r ? json({ ok: true }) : json({ error: r.error }, r.status)
154
- }
155
- if (route.r === 'out') {
156
- // this session ends here and now: its file gone, the cookie cleared; their other sessions stay
157
- await env.bucket.delete(KEYS.session(await sha256(who.email), who.login))
158
- return new Response(JSON.stringify({ ok: true }), { headers: { ...BASE, 'content-type': 'application/json', 'set-cookie': `${SESSION_COOKIE}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Lax` } })
159
- }
160
- if (route.r === 'projects') return json(projects.map(([id, p]) => ({ id, project: p.project })))
161
- const rand = (): string => (env.rand ?? (() => bytesB64url(crypto.getRandomValues(new Uint8Array(9)))))()
162
- if (route.r === 'upload') {
163
- if (!projects.some(([id]) => id === route.id)) return json({ error: 'no such project' }, 404)
164
- const r = await stageFile(req, 'p', route.id, { bucket: env.bucket, now, rand })
165
- return 'token' in r ? json(r) : json({ error: r.error }, r.status)
166
- }
167
- if (route.r === 'start') {
168
- if (!projects.some(([id]) => id === route.id)) return json({ error: 'no such project' }, 404)
169
- const raw = await req.text()
170
- let b: Record<string, unknown> = {}
171
- try {
172
- const v = raw.length <= 16 * 1024 ? (JSON.parse(raw) as unknown) : null
173
- if (v !== null && typeof v === 'object' && !Array.isArray(v)) b = v as Record<string, unknown>
174
- } catch {
175
- // a body that is no JSON object is refused below as an empty title
176
- }
177
- const title = typeof b['title'] === 'string' ? b['title'].trim() : ''
178
- const text = typeof b['text'] === 'string' ? b['text'].trim() : ''
179
- if (title === '' || title.length > PROPOSAL_TITLE_MAX) return json({ error: `a title of 1 to ${PROPOSAL_TITLE_MAX} characters` }, 400)
180
- if (text.length > ADVICE_TEXT_MAX) return json({ error: `at most ${ADVICE_TEXT_MAX} characters` }, 400)
181
- const pending = await env.bucket.list(KEYS.proposals(route.id))
182
- const hour = pending.filter((k) => Number(/\/(\d{13})-[^/]+\.json$/.exec(k)?.[1] ?? 0) > now - 3_600_000).length
183
- if (pending.length >= PROPOSALS_PENDING_MAX || hour >= PROPOSALS_PER_HOUR) return json({ error: 'enough new threads for now: try again in an hour' }, 429)
184
- const given = tokensOf(b['files'])
185
- if (given.length > FILES_MAX || !given.every((x): x is string => typeof x === 'string' && TOKEN.test(x))) return json({ error: `at most ${FILES_MAX} files the page staged` }, 400)
186
- const entry = `${now}-${rand()}`
187
- const files = await takeStaged(env.bucket, 'p', route.id, given, entry)
188
- if (typeof files === 'string') return json({ error: files }, 400)
189
- const wire: ProposalWire = { v: 1, at: new Date(now).toISOString(), email: who.email, title, ...(text !== '' ? { text } : {}), ...(files.length > 0 ? { files } : {}) }
190
- await env.bucket.put(`${KEYS.proposals(route.id)}${entry}.json`, JSON.stringify(wire), 'application/json')
191
- await dropStaged(env.bucket, 'p', route.id, given)
192
- return json({ ok: true, waits: true })
193
- }
194
- // the bundle the shell names now: a page still open on an older one says « reload » (advisor-host.ts advisorFetch)
195
- const headers = pin === null ? BASE : { ...BASE, [APP_HEADER]: pin[1]! }
196
- return (await copyApi(req, url.pathname, { bucket: env.bucket, shares: mine, now, writes: { email: who.email, rand }, headers })) ?? NOT_FOUND()
197
- }
@@ -1,6 +1,6 @@
1
- // where an advisor is at the door (wiki tools/shipkit/advisors.md, Who is here now): their page beats every few seconds
2
- // while its tab shows, naming the thread it has open or none; the door keeps one small file a person, the thread on now
3
- // and when they were last on each of theirs. The owner's hub alone reads it (advisors/here.ts)
1
+ // where an advisor is on the advisors page (wiki tools/shipkit/advisors.md, Who is here now): their page beats every
2
+ // few seconds while its tab shows, naming the thread it has open or none; the users' port keeps one small file a
3
+ // person, the thread on now and when they were last on each of theirs. The owner's hub alone reads it (advisors/here.ts)
4
4
  // the one constraint a reader breaks first: a beat names one of the reader's own live shares or nothing, and its answer
5
5
  // carries no one's presence, theirs included; anything else is refused and counted
6
6
  import { getJson, type Bucket } from './bucket.ts'
@@ -10,7 +10,7 @@ import { KEYS } from './types.ts'
10
10
 
11
11
  /** a page beats this often while its tab shows */
12
12
  export const HERE_BEAT_MS = 10_000
13
- /** a beat older than this is no presence: the page closed, slept or lost the door */
13
+ /** a beat older than this is no presence: the page closed, slept or lost the port */
14
14
  export const HERE_FRESH_MS = 20_000
15
15
  /** the body of a beat, at most */
16
16
  const BEAT_MAX = 512
@@ -40,7 +40,7 @@ export function shareOfBeat(raw: string): string | null | undefined {
40
40
  return typeof at === 'string' ? (ID_RE.exec(at)?.[1] ?? undefined) : undefined
41
41
  }
42
42
 
43
- /** a beat of a signed in reader: `mine` their live shares as the door read them for this request; one file read and
43
+ /** a beat of a signed in reader: `mine` their live shares as the port read them for this request; one file read and
44
44
  * one written, no thread read */
45
45
  export async function hereBeat(raw: string, o: { bucket: Bucket; email: string; mine: readonly string[]; now: number }): Promise<Beat> {
46
46
  const share = shareOfBeat(raw)
@@ -1,10 +1,11 @@
1
- // the door's two public pages (wiki tools/shipkit/advisors.md, The advisors page and its server): what the door is, and its privacy words
2
- // the one constraint a reader breaks first: fixed words and two facts the daemon gives the door's server (the owner's
3
- // name, his public contact), never a fact of the bucket, a share, a person or the host
1
+ // the two public pages of the advisors page (wiki tools/shipkit/advisors.md, Who calls: the users' port): what
2
+ // the advisors page is, and its privacy words
3
+ // the one constraint a reader breaks first: fixed words and two facts the daemon gives the users' port (the owner's
4
+ // name, the owner's public contact), never a fact of the port's folder, a share, a person or the host
4
5
  import { esc, renderPage, type Page } from './status.ts'
5
6
 
6
- /** the paths anyone reads with no session (with the sign in, `/in`): the handler serves each exact path and nothing
7
- * below it */
7
+ /** the paths anyone reads with no session (with the sign in, `/in`): the users' port serves each exact path and
8
+ * nothing below it */
8
9
  export const PUBLIC_PAGES = ['/about', '/privacy'] as const
9
10
  export type PublicPage = (typeof PUBLIC_PAGES)[number]
10
11
 
@@ -12,7 +13,7 @@ export type PublicPage = (typeof PUBLIC_PAGES)[number]
12
13
  export type PageFacts = { owner: string; contact: string | null }
13
14
 
14
15
  /** the date of the privacy words: a new text is a new date (tests/advisors-edge.test.ts pins each text to its date) */
15
- export const PRIVACY_UPDATED = '28 November 2026'
16
+ export const PRIVACY_UPDATED = '29 November 2026'
16
17
  const EMAIL = /^[^\s@<>"']{1,64}@[A-Za-z0-9.-]{1,190}\.[A-Za-z]{2,}$/
17
18
 
18
19
  /** the facts as the daemon gives them: a name of 1 to 80 characters, else « the owner »; an email, else none */
@@ -35,7 +36,7 @@ function about(f: PageFacts): Page {
35
36
  p(`This is the private advisors page of ${f.owner}. People he invites read the threads he shares with them here, and answer them.`),
36
37
  p('A thread is one piece of his work: a picture, a page or a question. You can approve it, ask for a change, or write to him.'),
37
38
  h2('Sign in'),
38
- p(`Sign in with your email. The first time, the code of your invite lets you choose your password. A lost password: ask ${f.owner} for a new code.`),
39
+ p(`Sign in with your email. The first time, the code of your invite lets you choose your password. A lost password: « Forgot your password? » on the sign in page sends a code to your email. Or ask ${f.owner} for a new one.`),
39
40
  h2('Nothing here is public'),
40
41
  p('Each person sees only the threads shared with them. A share ends on its date, or when he ends it.'),
41
42
  links([
@@ -54,17 +55,19 @@ export function privacyBody(f: PageFacts): string {
54
55
  'Your name and your email, which your invite goes to.',
55
56
  'Your password, kept only as a hash that nobody can read back.',
56
57
  `Your photo, when ${f.owner} sets one. It can come from a work profile of yours. He keeps it on his computer, and it shows here on your own page only while a share lives.`,
57
- `The threads that ${f.owner} shares with you.`,
58
58
  'What you send back: your answers, your words and your files.',
59
59
  'Where you stopped reading in each thread.',
60
+ 'When you ask for a new password: the time you asked, and a code that works once, for 30 minutes.',
60
61
  ]),
61
62
  h2('Why'),
62
63
  p(`To let you in, to show you the threads shared with you, and to give your answers to ${f.owner}. For nothing else.`),
63
64
  h2('How long'),
64
65
  ul([
65
- 'A thread stays here while its share lives. When the share ends, its copy here is removed, and your reading position goes.',
66
+ `Nothing of a thread is kept here. This page reads the threads that ${f.owner} shares with you from his computer when you open one, and stops when the share ends. Your reading position goes then.`,
66
67
  `Your answers go to ${f.owner} and stay with his work.`,
67
68
  'He keeps your name, your email and your photo in his list of people until he removes them, or until you ask him to.',
69
+ `A code for a new password goes once you use it, or 30 minutes after you asked. ${f.owner} keeps the times of your last five asks with your name.`,
70
+ 'To stop too many tries, this page counts the tries of each email and each address for up to an hour, in its memory only.',
68
71
  ]),
69
72
  h2('Who sees it'),
70
73
  ul([
@@ -1,20 +1,21 @@
1
1
  // the advisors' page shell (wiki tools/shipkit/advisors.md, The advisor's app): one html naming the page's script and
2
- // stylesheet by their hash, its facts in meta tags, no inline script. The door serves it at `/`, his hub in his preview
2
+ // stylesheet by their hash, its facts in meta tags, no inline script. The users' port serves it at `/`, the owner's hub
3
+ // in the owner's preview
3
4
  import { esc, referrerMeta, type Page } from './status.ts'
4
5
 
5
6
  export interface ShellFacts {
6
- /** where the page's two files are: `/app` at the door */
7
+ /** where the page's two files are: `/app` on the users' port */
7
8
  app: string
8
9
  js: string
9
10
  css: string
10
- /** the prefix every api path goes under: '' at the door */
11
+ /** the prefix every api path goes under: '' on the users' port */
11
12
  base: string
12
13
  csrf: string
13
14
  name: string
14
15
  owner: string
15
- /** the advisor's own name, for the page's head; absent when the door knows none */
16
+ /** the advisor's own name, for the page's head; absent when the port knows none */
16
17
  me?: string
17
- /** the start of their own photo's hash when the door serves it at `<base>/api/advisor/photo`: the page's cache key */
18
+ /** the start of their own photo's hash when the port serves it at `<base>/api/advisor/photo`: the page's cache key */
18
19
  photo?: string
19
20
  }
20
21