rvlib-shipkit 2.27.0 → 2.28.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 (338) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/hooks.ts +10 -3
  4. package/src/agent-time/live.ts +11 -5
  5. package/src/agent-time/registry.ts +289 -0
  6. package/src/agent-time/store.ts +2 -2
  7. package/src/annex/born.ts +2 -2
  8. package/src/annex/offload.ts +12 -11
  9. package/src/asks/ask-after.ts +6 -2
  10. package/src/asks/ask-bar-fold.ts +57 -0
  11. package/src/asks/ask-migrate.ts +280 -0
  12. package/src/asks/ask-steps-fold.ts +166 -0
  13. package/src/asks/ask-store.ts +586 -0
  14. package/src/assets/kits/identity-kit.ts +106 -38
  15. package/src/assets/kits/poster-thumbnail.ts +282 -0
  16. package/src/checks/SK003-claude-md-shape.check.ts +92 -25
  17. package/src/checks/SK004-gitignore-policy.check.ts +8 -4
  18. package/src/checks/SK013-one-way-in-policy.check.ts +10 -0
  19. package/src/checks/SK026-asks-autoclose.check.ts +9 -23
  20. package/src/checks/SK038-speaks-as.check.ts +3 -3
  21. package/src/checks/SK042-post-kinds.check.ts +26 -24
  22. package/src/checks/SK049-thread-answers-hook.check.ts +81 -0
  23. package/src/checks/SK050-retired-commands.check.ts +127 -0
  24. package/src/cli/cmd_Asks.ts +204 -53
  25. package/src/cli/cmd_Backup.ts +151 -8
  26. package/src/cli/cmd_Calls.ts +1 -0
  27. package/src/cli/cmd_Commands.ts +140 -34
  28. package/src/cli/cmd_Contracts.ts +1 -0
  29. package/src/cli/cmd_Keys.ts +1 -0
  30. package/src/cli/cmd_Lanes.ts +15 -4
  31. package/src/cli/cmd_Messages.ts +152 -1
  32. package/src/cli/cmd_Needs.ts +1 -0
  33. package/src/cli/cmd_Review.ts +931 -229
  34. package/src/cli/cmd_Secret.ts +255 -34
  35. package/src/cli/cmd_Social.ts +36 -33
  36. package/src/cli/cmd_SocialDrafts.ts +235 -0
  37. package/src/cli/cmd_Sound.ts +22 -1
  38. package/src/cli/cmd_Start.ts +3 -2
  39. package/src/cli/cmd_ThreadHolds.ts +34 -0
  40. package/src/cli/cmd_ThreadKinds.ts +146 -0
  41. package/src/cli/cmd_ThreadReflect.ts +83 -0
  42. package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
  43. package/src/cli/cmd_Vault.ts +1 -1
  44. package/src/cli/cmd_When.ts +1 -0
  45. package/src/cli/family-help.ts +2 -2
  46. package/src/cli/family-pages.ts +1 -1
  47. package/src/cli/kit/builtins.ts +1 -0
  48. package/src/cli/kit/verb.ts +6 -2
  49. package/src/cli/registry.ts +21 -2
  50. package/src/cli.ts +5 -2
  51. package/src/collections/actions.ts +25 -74
  52. package/src/collections/collection-types.ts +9 -5
  53. package/src/collections/md-body.ts +5 -3
  54. package/src/collections/pings.ts +13 -6
  55. package/src/collections/providers.ts +53 -61
  56. package/src/collections/reflections.ts +9 -4
  57. package/src/core/discover-checks.ts +18 -3
  58. package/src/core/git.ts +31 -0
  59. package/src/core/house-layout.ts +17 -0
  60. package/src/core/layout.ts +10 -5
  61. package/src/core/locked-write.ts +4 -1
  62. package/src/core/machine-db.ts +5 -3
  63. package/src/core/migrate-layout.ts +8 -10
  64. package/src/home/activity.ts +8 -15
  65. package/src/home/daemon-jobs.ts +13 -1
  66. package/src/home/home-paths.ts +6 -3
  67. package/src/home/home-routes.ts +8 -0
  68. package/src/home/inbox-shape.ts +233 -100
  69. package/src/home/inbox.ts +26 -71
  70. package/src/home/machine-fold.ts +10 -15
  71. package/src/home/machine-host.ts +19 -1
  72. package/src/home/other-macs.ts +2 -2
  73. package/src/home/serve-web.ts +6 -5
  74. package/src/home/space-page.ts +1 -1
  75. package/src/home/vault-page.ts +51 -17
  76. package/src/home/vault-words.ts +2 -2
  77. package/src/hooks/one-way-in-guard.ts +24 -2
  78. package/src/hq/files-send.ts +27 -28
  79. package/src/hq/hq-db.ts +4 -1
  80. package/src/hq/hq-local.ts +37 -4
  81. package/src/hq/hq-routes.ts +10 -2
  82. package/src/hq/hq-store.ts +6 -2
  83. package/src/hq/kinds/ask.ts +6 -6
  84. package/src/hq/outbox.ts +5 -3
  85. package/src/hq/replica.ts +1 -2
  86. package/src/hq/vault-route.ts +112 -0
  87. package/src/identities/collection.ts +2 -2
  88. package/src/identities/identities.ts +9 -8
  89. package/src/identities/machine-route.ts +8 -3
  90. package/src/ledger/db.ts +8 -1
  91. package/src/media-store/backup/daemon.ts +48 -8
  92. package/src/media-store/backup/keys.ts +1 -1
  93. package/src/media-store/backup/manifest.ts +20 -2
  94. package/src/media-store/backup/prune.ts +365 -0
  95. package/src/media-store/backup/retention.ts +122 -0
  96. package/src/media-store/backup/run.ts +14 -8
  97. package/src/media-store/backup/sources.ts +18 -17
  98. package/src/media-store/backup/thread-copy.ts +340 -0
  99. package/src/media-store/copy/config.ts +3 -4
  100. package/src/media-store/copy/store.ts +2 -2
  101. package/src/media-store/db.ts +2 -2
  102. package/src/media-store/forget.ts +118 -0
  103. package/src/media-store/purge.ts +3 -2
  104. package/src/media-store/space-listing.ts +20 -4
  105. package/src/media-store/space.ts +6 -5
  106. package/src/messages/guard.ts +49 -0
  107. package/src/messages/model.ts +1 -1
  108. package/src/messages/objects.ts +201 -0
  109. package/src/messages/routes.ts +2 -2
  110. package/src/messages/score.ts +1 -1
  111. package/src/messages/write.ts +285 -0
  112. package/src/pages/frame-client.ts +181 -4
  113. package/src/reflections/reflections-queue.ts +1 -1
  114. package/src/release/gate-checkout.ts +2 -1
  115. package/src/release/git-facts.ts +3 -2
  116. package/src/release/public-clean.ts +3 -2
  117. package/src/repo-config.ts +40 -18
  118. package/src/review/anim.ts +1 -1
  119. package/src/review/answer-kinds.ts +131 -0
  120. package/src/review/band.ts +53 -0
  121. package/src/review/branch-hold.ts +84 -0
  122. package/src/review/card-db.ts +16 -6
  123. package/src/review/card-rows.ts +4 -3
  124. package/src/review/cells.ts +297 -65
  125. package/src/review/close.ts +92 -0
  126. package/src/review/draft-card.ts +8 -16
  127. package/src/review/draft-model.ts +2 -2
  128. package/src/review/events.ts +171 -0
  129. package/src/review/format.ts +128 -14
  130. package/src/review/glyphs.ts +63 -0
  131. package/src/review/gone.ts +1 -1
  132. package/src/review/holds-sync.ts +62 -0
  133. package/src/review/holds.ts +85 -0
  134. package/src/review/house-kind-defs.ts +41 -0
  135. package/src/review/inbox-hook.ts +22 -9
  136. package/src/review/inbox-read.ts +201 -0
  137. package/src/review/instructions.ts +199 -0
  138. package/src/review/kind-apply.ts +61 -0
  139. package/src/review/kind-catalog.ts +96 -0
  140. package/src/review/kinds.ts +278 -0
  141. package/src/review/lane-ask.ts +109 -0
  142. package/src/review/model.ts +396 -86
  143. package/src/review/move.ts +3 -3
  144. package/src/review/need-address.ts +15 -0
  145. package/src/review/need-threads.ts +93 -0
  146. package/src/review/object-card.ts +48 -0
  147. package/src/review/object-read.ts +31 -0
  148. package/src/review/owner-verdict.ts +36 -0
  149. package/src/review/parties.ts +182 -0
  150. package/src/review/previews.ts +3 -1
  151. package/src/review/projections.ts +235 -0
  152. package/src/review/referring.ts +54 -0
  153. package/src/review/reflection-object.ts +195 -0
  154. package/src/review/routes.ts +137 -32
  155. package/src/review/secret-route.ts +80 -0
  156. package/src/review/snooze.ts +38 -0
  157. package/src/review/stage-card.ts +4 -4
  158. package/src/review/store.ts +366 -85
  159. package/src/review/supersede.ts +116 -0
  160. package/src/review/take-back.ts +52 -0
  161. package/src/review/thread-fold.ts +20 -7
  162. package/src/review/threads.ts +236 -39
  163. package/src/review/traces.ts +218 -0
  164. package/src/review/trailer-card.ts +2 -2
  165. package/src/review/unit.ts +71 -5
  166. package/src/review/verdict-items.ts +73 -0
  167. package/src/review/verdict-write.ts +15 -0
  168. package/src/review/wait.ts +85 -0
  169. package/src/review/watchers.ts +22 -9
  170. package/src/scaffold/files/claude-settings-local.json +2 -0
  171. package/src/secrets/archive-mark.ts +52 -0
  172. package/src/secrets/archive.ts +83 -0
  173. package/src/secrets/copy.ts +14 -14
  174. package/src/secrets/keychain-write.ts +48 -0
  175. package/src/secrets/keychain.ts +8 -5
  176. package/src/secrets/lapse-mark.ts +33 -0
  177. package/src/secrets/lapse.ts +60 -0
  178. package/src/secrets/list.ts +16 -22
  179. package/src/secrets/manager.ts +31 -16
  180. package/src/secrets/read.ts +161 -33
  181. package/src/secrets/tail.ts +31 -0
  182. package/src/serve/hub-app/asks-page.tsx +2 -1
  183. package/src/serve/hub-app/auto-text.tsx +14 -6
  184. package/src/serve/hub-app/benign-errors.ts +15 -1
  185. package/src/serve/hub-app/card-head.tsx +49 -0
  186. package/src/serve/hub-app/check-view.tsx +3 -2
  187. package/src/serve/hub-app/code-copy.ts +35 -0
  188. package/src/serve/hub-app/col-card.tsx +31 -40
  189. package/src/serve/hub-app/col-list-page.tsx +5 -2
  190. package/src/serve/hub-app/col-tables-view.tsx +7 -4
  191. package/src/serve/hub-app/col-tables.ts +5 -5
  192. package/src/serve/hub-app/cols-svc.ts +4 -79
  193. package/src/serve/hub-app/commands/commands-page.tsx +2 -1
  194. package/src/serve/hub-app/controls.css +83 -0
  195. package/src/serve/hub-app/frames-st.ts +17 -1
  196. package/src/serve/hub-app/git-view.tsx +3 -2
  197. package/src/serve/hub-app/home-st.ts +57 -6
  198. package/src/serve/hub-app/home-strip.css +1 -6
  199. package/src/serve/hub-app/home-strip.tsx +2 -1
  200. package/src/serve/hub-app/home.html +3 -0
  201. package/src/serve/hub-app/house-wiki-view.tsx +20 -0
  202. package/src/serve/hub-app/hub-app.tsx +48 -32
  203. package/src/serve/hub-app/hub-types.ts +2 -0
  204. package/src/serve/hub-app/hub.css +50 -61
  205. package/src/serve/hub-app/icons.tsx +14 -4
  206. package/src/serve/hub-app/identities-view.tsx +4 -3
  207. package/src/serve/hub-app/inbox-st.ts +203 -42
  208. package/src/serve/hub-app/inbox-view.tsx +189 -101
  209. package/src/serve/hub-app/inbox.css +47 -44
  210. package/src/serve/hub-app/index.html +3 -0
  211. package/src/serve/hub-app/instructions.css +30 -0
  212. package/src/serve/hub-app/keys.ts +5 -3
  213. package/src/serve/hub-app/machine-st.ts +2 -2
  214. package/src/serve/hub-app/machines-view.tsx +4 -11
  215. package/src/serve/hub-app/machines.css +0 -9
  216. package/src/serve/hub-app/markdown.css +51 -0
  217. package/src/serve/hub-app/md-copy.tsx +18 -40
  218. package/src/serve/hub-app/md.ts +25 -9
  219. package/src/serve/hub-app/media-view.tsx +2 -2
  220. package/src/serve/hub-app/messages/messages-page.tsx +2 -1
  221. package/src/serve/hub-app/messages/messages-st.ts +1 -1
  222. package/src/serve/hub-app/messages.css +0 -1
  223. package/src/serve/hub-app/objects.css +51 -0
  224. package/src/serve/hub-app/page-keys.ts +1 -1
  225. package/src/serve/hub-app/pages-frames.tsx +11 -1
  226. package/src/serve/hub-app/palette-st.ts +4 -4
  227. package/src/serve/hub-app/pane-boundary.tsx +72 -0
  228. package/src/serve/hub-app/pane-errors.ts +54 -0
  229. package/src/serve/hub-app/plan-view.tsx +3 -2
  230. package/src/serve/hub-app/planned-view.tsx +3 -3
  231. package/src/serve/hub-app/planned.css +0 -4
  232. package/src/serve/hub-app/processes-view.tsx +3 -2
  233. package/src/serve/hub-app/project-list.css +5 -13
  234. package/src/serve/hub-app/project-list.tsx +3 -6
  235. package/src/serve/hub-app/projects-svc.ts +6 -2
  236. package/src/serve/hub-app/readme.css +9 -15
  237. package/src/serve/hub-app/reflections-page.tsx +54 -1
  238. package/src/serve/hub-app/releases/releases-page.tsx +3 -2
  239. package/src/serve/hub-app/releases.css +0 -1
  240. package/src/serve/hub-app/review/code-colors.ts +30 -0
  241. package/src/serve/hub-app/review/diff-view.tsx +75 -0
  242. package/src/serve/hub-app/review/dock.tsx +104 -0
  243. package/src/serve/hub-app/review/draft-card.tsx +2 -2
  244. package/src/serve/hub-app/review/group-block.tsx +209 -0
  245. package/src/serve/hub-app/review/instructions-view.tsx +116 -0
  246. package/src/serve/hub-app/review/item-verdict.tsx +38 -0
  247. package/src/serve/hub-app/review/kind-states.tsx +193 -0
  248. package/src/serve/hub-app/review/kind-view.tsx +1 -37
  249. package/src/serve/hub-app/review/kit.tsx +57 -54
  250. package/src/serve/hub-app/review/lane-bar.tsx +64 -0
  251. package/src/serve/hub-app/review/object-card.tsx +62 -0
  252. package/src/serve/hub-app/review/object-panel.tsx +179 -0
  253. package/src/serve/hub-app/review/question-views.tsx +385 -0
  254. package/src/serve/hub-app/review/review-cells.tsx +86 -105
  255. package/src/serve/hub-app/review/review-list.tsx +104 -47
  256. package/src/serve/hub-app/review/review-page.tsx +5 -4
  257. package/src/serve/hub-app/review/review-st.ts +68 -28
  258. package/src/serve/hub-app/review/review-thread.tsx +171 -40
  259. package/src/serve/hub-app/review/review-views.tsx +35 -31
  260. package/src/serve/hub-app/review/thread-close.tsx +124 -0
  261. package/src/serve/hub-app/review/thread-control.tsx +4 -4
  262. package/src/serve/hub-app/review/thread-st.ts +222 -22
  263. package/src/serve/hub-app/review/trailer-card.tsx +1 -1
  264. package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
  265. package/src/serve/hub-app/review.css +216 -57
  266. package/src/serve/hub-app/section-head.tsx +51 -0
  267. package/src/serve/hub-app/social/calendar.tsx +5 -11
  268. package/src/serve/hub-app/social/comms-page.tsx +23 -10
  269. package/src/serve/hub-app/social/kit.tsx +8 -15
  270. package/src/serve/hub-app/social/next-release.tsx +3 -5
  271. package/src/serve/hub-app/social/post-card.tsx +3 -0
  272. package/src/serve/hub-app/social/post-page.tsx +80 -0
  273. package/src/serve/hub-app/social/problems.tsx +5 -9
  274. package/src/serve/hub-app/social/social-model.ts +13 -5
  275. package/src/serve/hub-app/social/social-page.tsx +1 -1
  276. package/src/serve/hub-app/social/social-st.ts +42 -5
  277. package/src/serve/hub-app/social.css +7 -17
  278. package/src/serve/hub-app/space.css +1 -1
  279. package/src/serve/hub-app/stores/stores-page.tsx +6 -2
  280. package/src/serve/hub-app/thread-row.tsx +101 -0
  281. package/src/serve/hub-app/time-ago.tsx +3 -2
  282. package/src/serve/hub-app/time-view.tsx +2 -1
  283. package/src/serve/hub-app/time.css +2 -5
  284. package/src/serve/hub-app/tree-row.tsx +1 -9
  285. package/src/serve/hub-app/vault-view.tsx +4 -4
  286. package/src/serve/hub-app/veille/veille-page.tsx +2 -11
  287. package/src/serve/hub-app/veille.css +0 -1
  288. package/src/serve/hub-app/waiting-svc.ts +4 -4
  289. package/src/serve/hub-app/when-view.tsx +6 -3
  290. package/src/serve/hub-app/wiki-st.ts +30 -4
  291. package/src/serve/hub-app/wikis-view.tsx +4 -3
  292. package/src/serve/hub-runtime.ts +20 -6
  293. package/src/serve/project-gutter-route.ts +16 -6
  294. package/src/serve/project-gutter.ts +6 -53
  295. package/src/serve/same-origin.ts +3 -0
  296. package/src/serve/secret-gate.ts +21 -0
  297. package/src/serve/serve-hub.ts +29 -20
  298. package/src/serve/tailnet-caller.ts +117 -0
  299. package/src/shipkit.ts +2 -2
  300. package/src/site/desk.ts +2 -2
  301. package/src/smoke/run-smoke.ts +3 -4
  302. package/src/social/brands.ts +4 -0
  303. package/src/social/card-drafts.ts +11 -19
  304. package/src/social/desk-index.ts +34 -13
  305. package/src/social/drafts.ts +4 -4
  306. package/src/social/import-drafts.ts +244 -0
  307. package/src/social/kind-pages.ts +3 -3
  308. package/src/social/kinds.ts +1 -1
  309. package/src/social/load.ts +89 -64
  310. package/src/social/media-kind.ts +68 -161
  311. package/src/social/media-of.ts +5 -4
  312. package/src/social/open.ts +3 -2
  313. package/src/social/post-object.ts +120 -0
  314. package/src/social/post-sources.ts +136 -0
  315. package/src/social/post-text.ts +103 -0
  316. package/src/social/posts.ts +378 -0
  317. package/src/social/presence.ts +7 -5
  318. package/src/social/publish/index.ts +17 -5
  319. package/src/social/publish/secret.ts +2 -2
  320. package/src/social/release-stage.ts +58 -57
  321. package/src/social/routes.ts +64 -24
  322. package/src/social/stage.ts +42 -57
  323. package/src/social/text.ts +4 -3
  324. package/src/social/thumbnail.ts +135 -43
  325. package/src/social/tracker.ts +1 -1
  326. package/src/social/writes.ts +12 -29
  327. package/src/stores/desk.ts +16 -11
  328. package/src/stores/unit.ts +2 -2
  329. package/src/trailer/sound/eleven.ts +33 -3
  330. package/src/urls/rows.ts +1 -1
  331. package/src/vault/vault-http.ts +11 -3
  332. package/src/vault/vault-import.ts +6 -1
  333. package/src/veille/identity.ts +2 -2
  334. package/src/wiki/graph-pages.ts +13 -1
  335. package/src/wiki/scan-md.ts +1 -1
  336. package/src/asks/asks-queue.ts +0 -424
  337. package/src/messages/suggest.ts +0 -96
  338. package/src/social/migrate.ts +0 -123
@@ -19,7 +19,7 @@ import { contextSourcesStamp, GLOBAL_CONTEXT_DONE, GLOBAL_CONTEXT_EVERY_MS, GLOB
19
19
  import { APPS_DONE, APPS_EVERY_MS, appsDue, appsSourcesStamp } from './process-apps.ts'
20
20
  import { REPORT_EVERY_MS } from '../hq/machine-notes.ts'
21
21
 
22
- export type JobId = 'backup' | 'retention sweep' | 'media store' | 'annex' | 'global context' | 'apps' | 'agent time' | 'hq report' | 'hq cards' | 'db census' | 'space copy' | 'space listing' | 'vault' | 'db fold'
22
+ export type JobId = 'backup' | 'retention sweep' | 'media store' | 'annex' | 'global context' | 'apps' | 'agent time' | 'hq report' | 'hq cards' | 'db census' | 'space copy' | 'space listing' | 'vault' | 'db fold' | 'thread copy'
23
23
 
24
24
  /** how often the transcripts' new lines join the index of `sk time` */
25
25
  export const AGENT_TIME_EVERY_MS = 10 * 60_000
@@ -66,6 +66,9 @@ export const DAEMON_JOBS: readonly DaemonJob[] = [
66
66
  { id: 'retention sweep', everyMs: 5 * 60_000, firstMs: 10_000, due: (now) => now - (machineGet<number>(SWEPT_AT) ?? 0) >= SWEEP_EVERY_MS },
67
67
  // a watch of the sources: a look only once a source may have moved, a run waits, or a clock says so
68
68
  { id: 'backup', everyMs: BACKUP_EVERY_MS, firstMs: BACKUP_EVERY_MS, hold: (root, printErr) => backupHold(root, printErr) },
69
+ // the thread store's second copy on another machine: a look is one count query of the machine db, a child only
70
+ // once the store moved and the last copy is 10 min old (media-store/backup/thread-copy.ts)
71
+ { id: 'thread copy', everyMs: BACKUP_EVERY_MS, firstMs: 60_000, due: async (now) => (await import('../media-store/backup/thread-copy.ts')).threadCopyDue(now) },
69
72
  // the house's generated context: its unit files are imported to be read, a second of compile the loop never pays
70
73
  { id: 'global context', everyMs: GLOBAL_CONTEXT_EVERY_MS, firstMs: 30_000, due: async (now, root) => contextDue(now, await contextSourcesStamp(root)) },
71
74
  // every global process with a url as an app in ~/Applications: built when missing or stale, removed when gone (process-apps.ts)
@@ -294,6 +297,15 @@ export async function runJobBody(id: JobId, o: { root: string; home: string; pri
294
297
  const { machineSpace } = await import('../media-store/space.ts')
295
298
  return backupTick({ home: o.home, repos: [...repos, ...house.archived.map((r) => r.path)], space: machineSpace, print: o.print, printErr: o.printErr })
296
299
  }
300
+ if (id === 'thread copy') {
301
+ const { sendThreadCopy } = await import('../media-store/backup/thread-copy.ts')
302
+ const r = await sendThreadCopy()
303
+ if (r.sent != null) {
304
+ o.print(`ok: thread copy: ${r.sent}, ${(r.bytes / 1e6).toFixed(1)} MB, ${r.pruned} pruned`)
305
+ if (r.why) o.printErr(`WARN thread copy: ${r.why}`)
306
+ } else if (!r.why.startsWith('the store did not move')) o.printErr(`WARN thread copy: ${r.why}`)
307
+ return
308
+ }
297
309
  if (id === 'media store') {
298
310
  const { mediaTick } = await import('../media-store/daemon.ts')
299
311
  const { mediaKinds } = await import('../media-kinds.ts')
@@ -46,15 +46,18 @@ export async function pmUp(port = pmPort(), timeoutMs = 400): Promise<boolean> {
46
46
  }
47
47
 
48
48
  /** shipkit's own suite run without its preload (tests/_setup.ts gives each run a temp home): it would read, write and
49
- * delete the machine's real home, its media index included */
50
- const suiteOnRealHome = (): boolean => process.env.NODE_ENV === 'test' && /\/rvlib-shipkit\/tests\//.test(Bun.main)
49
+ * delete the machine's real home and its machine db, the media index and the review cards included. Throws then */
50
+ export function refuseRealHomeInSuite(): void {
51
+ if (process.env.NODE_ENV === 'test' && /\/rvlib-shipkit\/tests\//.test(Bun.main))
52
+ throw new Error(`${Bun.main}: a shipkit suite reached the machine's real home; run it from packages/rvlib-shipkit (its bunfig preload gives the run a temp home) or through sk ci --only test`)
53
+ }
51
54
 
52
55
  /** `~/.shipkit/home` (in `~/.config/shipkit/` until the machine moved: layout.ts machinePath), beside the rail order
53
56
  * file (project-gutter-route.ts orderFile) */
54
57
  export const homeDir = (): string => {
55
58
  const dir = process.env.SHIPKIT_HOME_DIR
56
59
  if (dir) return dir
57
- if (suiteOnRealHome()) throw new Error(`${Bun.main}: a shipkit suite reached the machine's real home; run it from packages/rvlib-shipkit (its bunfig preload gives the run a temp home) or through sk ci --only test`)
60
+ refuseRealHomeInSuite()
58
61
  return machinePath('home')
59
62
  }
60
63
 
@@ -350,6 +350,14 @@ export function homeRoutes(d: HomeDeps) {
350
350
  return Response.json(await houseUrls(repos), { headers: { 'cache-control': 'no-store' } })
351
351
  }
352
352
  if (req.method !== 'POST') return null
353
+ // a pane of the page that failed to draw (hub-app/pane-errors.ts): one line in this process's log, where the
354
+ // home's own errors already go, for an agent that never saw the page
355
+ if (path === '/api/home/page-error') {
356
+ const b = await body(req)
357
+ const cut = (v: unknown): string => String(v).slice(0, 400)
358
+ console.error(`page error: the ${cut(b.pane)} pane failed to draw: ${cut(b.message)} (${cut(b.url)})`)
359
+ return Response.json({ ok: true })
360
+ }
353
361
  if (path === '/api/home/hub') {
354
362
  const b = await body(req)
355
363
  if (repos.length === 0) await refresh()
@@ -1,47 +1,58 @@
1
- // the inbox as data (wiki tools/shipkit/home.md, The inbox): everything that waits on the owner in every house repo,
2
- // one list. Pure and browser safe: the daemon (inbox.ts), the page and the tests share it. Each repo gives what it
3
- // already holds, never a store of its own: its review store's thread index and its hub's rows that need someone.
1
+ // the inbox as data (wiki tools/shipkit/home-inbox.md): every thread of every house repo, each once, in the list of who
2
+ // acts now, badged with what it waits on from him (review/wait.ts). Pure and browser safe: the daemon (inbox.ts), the
3
+ // page and the tests share it. Each repo gives what it already holds, never a store of its own: its review store's
4
+ // thread index and its hub's needs, a need being a row only while no thread stands for it.
4
5
  //
5
- // the one constraint a reader breaks first: a row here is one ACT for the owner, so what an ask already owns
6
- // (`askOwned`) and the review rows of the needs (the index says them with their thumbs) are left out, never twice
7
- import { afterWords } from '../asks/ask-after.ts'
6
+ // the one constraint a reader breaks first: a row is never typed by what its thread is (a version, an ask, a check);
7
+ // its badge is the verb, so the filter and the counts read one field, `wait`
8
8
  import { REVIEW_COL, type Resource } from '../collections/collection-types.ts'
9
+ import { bandOf } from '../review/band.ts'
9
10
  import type { ThreadIndex, ThreadRow } from '../review/cells.ts'
10
- import { STATUS_LABEL } from '../review/model.ts'
11
-
12
- /** a card the owner answers, a question raised to him, an ask for his hands, a need of a repo, an item he or a player
13
- * raised that the agents work on */
14
- export type InboxKind = 'card' | 'question' | 'ask' | 'need' | 'raised'
15
- /** the review hue, red broken, yellow can wait */
16
- export type InboxTone = 'review' | 'red' | 'yellow'
17
- /** the main list (what waits on him), the folded one (what can wait, what he can only read), or the asks that wait for
18
- * their `after:` day */
19
- export type InboxList = 'main' | 'yellow' | 'later'
20
- /** the rows that wait on the owner himself (the default: the review store's rows and the asks), or every row, the checks included */
21
- export type InboxShow = 'cards' | 'all'
11
+ import { canonicalAddress } from '../review/model.ts'
12
+ import { needAddress } from '../review/need-address.ts'
13
+ import { NO_PARTIES, type Parties } from '../review/parties.ts'
14
+ import { askVerb, isOwnerWait, OWNER_WAITS, verbsOf, waitOf, waitsMatch, type OwnerWait, type Wait, type WaitsOn } from '../review/wait.ts'
15
+
16
+ export { OWNER_WAITS, type OwnerWait, type Wait } from '../review/wait.ts'
17
+
18
+ /** who acts now (review/band.ts): him (`main`), a live agent works on it (`working`), an agent's move nobody works
19
+ * (`waiting`), him from a day still ahead (`later`), nobody (`done`) */
20
+ export type InboxList = 'main' | 'working' | 'waiting' | 'later' | 'done'
21
+ /** the lists in the order drawn */
22
+ export const INBOX_LISTS = ['main', 'working', 'waiting', 'later', 'done'] as const satisfies readonly InboxList[]
23
+ /** the lists shown and counted by default: `done` is read only once picked */
24
+ export const DEFAULT_STATE: readonly InboxList[] = ['main', 'working', 'waiting', 'later']
25
+ /** a state that names `working` shows `waiting` too: a pref kept before the split keeps the threads that moved */
26
+ const withWaiting = (s: InboxList[]): InboxList[] => (s.includes('working') && !s.includes('waiting') ? INBOX_LISTS.filter((l) => l === 'waiting' || s.includes(l)) : s)
27
+ /** the lists whose rows carry a verb of his: the verbs filter and count these */
28
+ const HIS: ReadonlySet<InboxList> = new Set(['main', 'later'])
22
29
  /** what the rows group by: each one on or off on its own, nested in this order */
23
- export const INBOX_GROUPS = ['repo', 'kind', 'lane'] as const
30
+ export const INBOX_GROUPS = ['project', 'wait', 'lane'] as const
24
31
  export type InboxGroup = (typeof INBOX_GROUPS)[number]
25
32
 
26
- /** a row that waits on the owner himself: a card, a question, an item raised in the review store, an ask for his hands */
27
- export const isOwnerKind = (k: InboxKind): boolean => k === 'card' || k === 'question' || k === 'raised' || k === 'ask'
33
+ /** the verbs filter: null every verb, else these */
34
+ export type WaitSel = null | OwnerWait[]
35
+ export const waitIn = (sel: WaitSel, w: Wait): boolean => sel === null || (sel as readonly string[]).includes(w)
28
36
 
29
37
  export interface InboxRow {
30
38
  /** `<repo>/<id>`, one per row of the whole inbox */
31
39
  key: string
32
40
  repo: string
33
- kind: InboxKind
34
- /** the item's id in its repo: a review thread's head, or a need's id */
41
+ /** a thread's head, or a need's id while no thread stands for it */
35
42
  id: string
36
- /** a need's collection, the section of its repo's hub */
43
+ /** a need's collection, the section of its repo's hub; a thread has none */
37
44
  col?: string
38
- /** the badge's word: card, choice, question, the ask's kind, the need's type */
39
- tag: string
40
- tone: InboxTone
45
+ /** what it waits on from him first: the badge */
46
+ wait: Wait
47
+ /** what waits on him first, the icon its row draws (review/wait.ts waitEntryOf) */
48
+ waitsOn?: WaitsOn
49
+ /** every verb its open objects ask: what the verbs filter and its counts read (review/wait.ts verbsOf) */
50
+ verbs: OwnerWait[]
41
51
  title: string
52
+ /** agent words he has not read */
53
+ unread?: true
42
54
  /** one more line: the lane and the versions, the need's sentence */
43
55
  sub?: string
44
- /** the lane the card belongs to; a need has none */
45
56
  lane?: string
46
57
  /** epoch ms of its newest move, null when nothing dates it */
47
58
  at: number | null
@@ -56,8 +67,8 @@ export interface InboxSource {
56
67
  repo: string
57
68
  review: { tag: string; ix: ThreadIndex } | null
58
69
  needs: Resource[]
59
- /** epoch ms of its last commit when that is older than `QUIET_DAYS`: its red rows can wait */
60
- quietSince?: number | null
70
+ /** the sessions and lanes its threads' holders name: whether a live agent works a thread (none: nobody does) */
71
+ parties?: Parties
61
72
  }
62
73
 
63
74
  export interface InboxAnswer {
@@ -67,11 +78,15 @@ export interface InboxAnswer {
67
78
  total: number
68
79
  offset: number
69
80
  limit: number
70
- /** the rows of each list the page shows */
81
+ /** the rows of each list under the filters; `done` is 0 while it is not asked */
71
82
  counts: Record<InboxList, number>
72
- /** the rows of each list with every kind: what « all » would show */
73
- all: Record<InboxList, number>
74
- show: InboxShow
83
+ /** the rows of each verb of his in the lists of `state`, under the projects filter: they add up to those lists */
84
+ byWait: Partial<Record<OwnerWait, number>>
85
+ /** the threads of his turn under the other filters, each once: « all » of the verbs, which their counts no longer
86
+ * add up to, a thread being counted under each verb it asks */
87
+ waitsAll: number
88
+ /** the rows of each repo in the lists of `state`, under the verbs filter */
89
+ byProject: Record<string, number>
75
90
  /** per repo, the rows of each list: its own badges count the same */
76
91
  repos: Record<string, Record<InboxList, number>>
77
92
  /** a repo whose items are not here, and why (its hub is down, a read broke) */
@@ -79,8 +94,6 @@ export interface InboxAnswer {
79
94
  }
80
95
 
81
96
  export const INBOX_PAGE = 50
82
- /** a repo with no commit for this long is quiet: nobody works there, its red checks fold into « can wait » */
83
- export const QUIET_DAYS = 7
84
97
  export const INBOX_MAX = 500
85
98
 
86
99
  /** where a repo's hub answers on the home */
@@ -101,18 +114,25 @@ export const isReviewId = (id: string): boolean => /^\d{8}-\d{6}-/.test(id)
101
114
 
102
115
  const IMAGE = /\.(png|jpe?g|webp)$/i
103
116
 
104
- function reviewRow(repo: string, r: ThreadRow, kind: InboxKind, tone: InboxTone): InboxRow {
105
- const tag = kind === 'card' ? (r.choice ? 'choice' : 'card') : kind === 'question' ? (r.status === 'pending' ? 'question' : STATUS_LABEL[r.status]) : STATUS_LABEL[r.status]
106
- const sub = [r.lane, r.versions > 1 ? `v${r.versions}` : null, r.unread ? 'unread words' : null].filter((x): x is string => x != null && x !== '').join(' · ')
117
+ /** the list of who acts now on a thread: its band, with the repo's parties */
118
+ const listOfRow = (r: ThreadRow, p: Parties): InboxList => {
119
+ const b = bandOf(r, p)
120
+ return b === 'yours' ? 'main' : b === 'aside' ? 'later' : b
121
+ }
122
+
123
+ function threadRow(repo: string, r: ThreadRow, wait: Wait, verbs: OwnerWait[]): InboxRow {
124
+ const later = r.turn === 'aside' && r.aside != null ? `after ${r.aside.until.slice(0, 10)}` : null
125
+ const sub = [later, r.lane, r.versions > 1 ? `v${r.versions}` : null].filter((x): x is string => x != null && x !== '').join(' · ')
107
126
  const at = Date.parse(r.updated)
108
127
  return {
109
128
  key: `${repo}/${r.head}`,
110
129
  repo,
111
- kind,
112
130
  id: r.head,
113
- tag,
114
- tone,
131
+ wait,
132
+ verbs,
133
+ ...(r.waitsOn && isOwnerWait(wait) ? { waitsOn: r.waitsOn } : {}),
115
134
  title: r.title,
135
+ ...(r.unread ? { unread: true as const } : {}),
116
136
  ...(sub !== '' ? { sub } : {}),
117
137
  ...(r.lane ? { lane: r.lane } : {}),
118
138
  at: Number.isFinite(at) ? at : null,
@@ -124,45 +144,47 @@ function reviewRow(repo: string, r: ThreadRow, kind: InboxKind, tone: InboxTone)
124
144
  /** when a need moved: a check's last run, else what `dated` reads off its file (an ask's birth, a file's last write) */
125
145
  export type Dated = (n: Resource) => number | null
126
146
 
127
- function needRow(repo: string, n: Resource, dated: Dated): InboxRow {
128
- const ask = n.collection === 'asks'
129
- const title = n.title
130
- const sub = n.text !== title ? n.text : n.slot
147
+ /** a need no thread stands for yet: his hands when its type says so (an ask, a picture to update on an account), else
148
+ * an agent's, which nobody works while no thread stands for it */
149
+ function needRow(repo: string, n: Resource, dated: Dated): { list: InboxList; row: InboxRow } {
150
+ const wait: Wait = n.collection === 'asks' ? askVerb(n.ask?.kind ?? 'action') : n.type === 'ask' ? 'do' : 'agents'
151
+ const sub = n.text !== n.title ? n.text : n.slot
131
152
  return {
132
- key: `${repo}/${n.id}`,
133
- repo,
134
- kind: ask ? 'ask' : 'need',
135
- id: n.id,
136
- col: n.collection,
137
- tag: ask ? (n.ask?.kind ?? 'ask') : n.type,
138
- tone: n.severity === 'red' ? 'red' : 'yellow',
139
- title,
140
- ...(sub != null && sub !== '' ? { sub } : {}),
141
- at: n.check?.lastAt ?? dated(n),
142
- thumb: null,
143
- open: inboxAddress(repo, n.id),
153
+ list: wait === 'agents' ? 'waiting' : 'main',
154
+ row: {
155
+ key: `${repo}/${n.id}`,
156
+ repo,
157
+ id: n.id,
158
+ col: n.collection,
159
+ wait,
160
+ verbs: isOwnerWait(wait) ? [wait] : [],
161
+ title: n.title,
162
+ ...(sub != null && sub !== '' ? { sub } : {}),
163
+ at: n.check?.lastAt ?? dated(n),
164
+ thumb: null,
165
+ open: inboxAddress(repo, n.id),
166
+ },
144
167
  }
145
168
  }
146
169
 
147
- /** one repo's rows: the main list (the cards and questions waiting on him, the asks, what is red), the folded one
148
- * (what is yellow, the raised items in the agents' hands, what is red in a quiet repo), and the asks whose `after:`
149
- * day is ahead, its day on the row */
150
- export function repoRows(s: InboxSource, dated: Dated): Record<InboxList, InboxRow[]> {
151
- const out: Record<InboxList, InboxRow[]> = { main: [], yellow: [], later: [] }
152
- for (const { row } of s.review?.ix.entries ?? []) {
153
- if (s.review!.ix.waiting.has(row.head)) out.main.push(reviewRow(s.repo, row, row.origin === 'agent' ? 'card' : 'question', 'review'))
154
- else if (row.active && row.move === 'agents' && row.origin !== 'agent') out.yellow.push(reviewRow(s.repo, row, 'raised', 'yellow'))
155
- }
170
+ /** one repo's rows by who acts now: each thread once, in its turn's list; a need only while no thread stands for it (an
171
+ * ask, a check, a reflection by its address). `done` rows only when asked: a store holds thousands */
172
+ export function repoRows(s: InboxSource, dated: Dated, withDone = false, now = new Date()): Record<InboxList, InboxRow[]> {
173
+ const out: Record<InboxList, InboxRow[]> = { main: [], working: [], waiting: [], later: [], done: [] }
174
+ const owned = new Set<string>()
175
+ for (const { row } of s.review?.ix.entries ?? []) for (const a of row.addresses) owned.add(a)
156
176
  for (const n of s.needs) {
157
- if (n.severity == null || n.collection === REVIEW_COL || n.askOwned === true) continue
158
- const r = needRow(s.repo, n, dated)
159
- if (r.kind === 'ask' && n.ask?.later === true) {
160
- out.later.push({ ...r, sub: afterWords(n.ask.after ?? '') })
161
- continue
162
- }
163
- const quiet = s.quietSince != null && r.kind !== 'ask' && r.tone === 'red'
164
- if (quiet) r.sub = [`quiet repo, last commit ${new Date(s.quietSince!).toISOString().slice(0, 10)}`, r.sub].filter((x) => x != null).join(' · ')
165
- out[!quiet && (r.kind === 'ask' || r.tone === 'red') ? 'main' : 'yellow'].push(r)
177
+ // a reflection is an object, listed by its repo's reflections page; a thread opened on it is a row below
178
+ if (n.severity == null || n.collection === REVIEW_COL || n.collection === 'reflections' || n.askOwned === true) continue
179
+ const a = n.collection === 'asks' ? canonicalAddress(n.id) : needAddress(s.repo, n)
180
+ if (a !== null && owned.has(a)) continue
181
+ const { list, row } = needRow(s.repo, n, dated)
182
+ out[list].push(row)
183
+ }
184
+ for (const { t, row } of s.review?.ix.entries ?? []) {
185
+ const l = listOfRow(row, s.parties ?? NO_PARTIES)
186
+ if (l === 'done' && !withDone) continue
187
+ out[l].push(threadRow(s.repo, row, l === 'done' ? 'done' : l === 'working' || l === 'waiting' ? 'agents' : waitOf(t, now), HIS.has(l) ? verbsOf(t, now) : []))
166
188
  }
167
189
  return out
168
190
  }
@@ -171,36 +193,88 @@ export function repoRows(s: InboxSource, dated: Dated): Record<InboxList, InboxR
171
193
  export const byNewest = (a: InboxRow, b: InboxRow): number =>
172
194
  (b.at ?? -Infinity) - (a.at ?? -Infinity) || a.repo.localeCompare(b.repo) || a.title.localeCompare(b.title)
173
195
 
196
+ export type InboxLists = Record<InboxList, InboxRow[]> & { repos: InboxAnswer['repos'] }
197
+
174
198
  /** every repo's rows, each list in its order; `dated` dates a need of that repo */
175
- export function inboxRows<S extends InboxSource>(sources: readonly S[], dated: (s: S) => Dated): Record<InboxList, InboxRow[]> & { repos: InboxAnswer['repos'] } {
176
- const main: InboxRow[] = []
177
- const yellow: InboxRow[] = []
178
- const later: InboxRow[] = []
179
- const repos: InboxAnswer['repos'] = {}
199
+ export function inboxRows<S extends InboxSource>(sources: readonly S[], dated: (s: S) => Dated, withDone = false): InboxLists {
200
+ const all: InboxLists = { main: [], working: [], waiting: [], later: [], done: [], repos: {} }
180
201
  for (const s of sources) {
181
- const r = repoRows(s, dated(s))
182
- main.push(...r.main)
183
- yellow.push(...r.yellow)
184
- later.push(...r.later)
185
- repos[s.repo] = { main: r.main.length, yellow: r.yellow.length, later: r.later.length }
202
+ const r = repoRows(s, dated(s), withDone)
203
+ for (const l of INBOX_LISTS) all[l].push(...r[l])
204
+ all.repos[s.repo] = { main: r.main.length, working: r.working.length, waiting: r.waiting.length, later: r.later.length, done: r.done.length }
186
205
  }
187
- return { main: main.sort(byNewest), yellow: yellow.sort(byNewest), later: later.sort(byNewest), repos }
206
+ for (const l of INBOX_LISTS) all[l].sort(byNewest)
207
+ return all
208
+ }
209
+
210
+ export interface InboxQuery {
211
+ list: InboxList
212
+ waits: WaitSel
213
+ /** none is every repo */
214
+ projects: string[]
215
+ /** the lists the facet counts read */
216
+ state: InboxList[]
217
+ offset: number
218
+ limit: number
188
219
  }
189
220
 
221
+ /** whether a query reads the done list */
222
+ export const wantsDone = (q: Pick<InboxQuery, 'list' | 'state'>): boolean => q.list === 'done' || q.state.includes('done')
223
+
224
+ /** a comma list of a url's search, empty when absent */
225
+ const listOf = (v: string | null): string[] => (v == null || v === '' ? [] : v.split(',').filter((x) => x !== ''))
226
+ const ownerVerbsIn = (vs: readonly string[]): OwnerWait[] => OWNER_WAITS.filter((w) => vs.includes(w))
227
+ const sameLists = (a: readonly InboxList[], b: readonly InboxList[]): boolean => a.join() === b.join()
228
+
190
229
  /** the query from a url's search: a value out of range is its default */
191
- export function inboxQuery(p: URLSearchParams): { list: InboxList; show: InboxShow; offset: number; limit: number } {
230
+ export function inboxQuery(p: URLSearchParams): InboxQuery {
192
231
  const n = (k: string, d: number, max: number): number => {
193
232
  const v = Number(p.get(k) || NaN)
194
233
  return Number.isInteger(v) && v >= 0 ? Math.min(v, max) : d
195
234
  }
196
235
  const list = p.get('list')
197
- return { list: list === 'yellow' || list === 'later' ? list : 'main', show: p.get('show') === 'all' ? 'all' : 'cards', offset: n('offset', 0, Number.MAX_SAFE_INTEGER), limit: Math.max(1, n('limit', INBOX_PAGE, INBOX_MAX)) }
236
+ const waits = p.get('waits')
237
+ return {
238
+ list: (INBOX_LISTS as readonly string[]).includes(list ?? '') ? (list as InboxList) : 'main',
239
+ waits: waits == null ? null : ownerVerbsIn(listOf(waits)),
240
+ projects: listOf(p.get('projects')),
241
+ state: p.has('state') ? withWaiting(INBOX_LISTS.filter((l) => listOf(p.get('state')).includes(l))) : [...DEFAULT_STATE],
242
+ offset: n('offset', 0, Number.MAX_SAFE_INTEGER),
243
+ limit: Math.max(1, n('limit', INBOX_PAGE, INBOX_MAX)),
244
+ }
245
+ }
246
+
247
+ /** a value in an address, its colons kept as they are: a link stays readable */
248
+ const enc = (v: string): string => encodeURIComponent(v).replaceAll('%3A', ':')
249
+
250
+ /** the address's search of a query: the defaults left out */
251
+ export function inboxSearch(q: Partial<InboxQuery>): string {
252
+ const p: string[] = []
253
+ if (q.list != null && q.list !== 'main') p.push(`list=${q.list}`)
254
+ if (q.waits != null) p.push(`waits=${q.waits.join(',')}`)
255
+ if (q.projects != null && q.projects.length > 0) p.push(`projects=${q.projects.map(enc).join(',')}`)
256
+ if (q.state != null && !sameLists(q.state, DEFAULT_STATE)) p.push(`state=${q.state.join(',')}`)
257
+ if (q.limit != null) p.push(`limit=${q.limit}`)
258
+ return p.length === 0 ? '' : `?${p.join('&')}`
198
259
  }
199
260
 
200
- /** one page of one list */
201
- export function inboxPage(all: ReturnType<typeof inboxRows>, q: ReturnType<typeof inboxQuery>, missing: InboxAnswer['missing']): InboxAnswer {
202
- // the kinds filter before the page cuts, so a card past the first page is never lost behind a check
203
- const shown = (l: InboxList): InboxRow[] => (q.show === 'all' ? all[l] : all[l].filter((r) => isOwnerKind(r.kind)))
261
+ /** one page of one list. The verbs filter the lists of his turn; `working`, `waiting` and `done` are the state filter's alone */
262
+ export function inboxPage(all: InboxLists, q: InboxQuery, missing: InboxAnswer['missing']): InboxAnswer {
263
+ const verbOk = (l: InboxList, r: InboxRow): boolean => !HIS.has(l) || waitsMatch(q.waits, r.verbs)
264
+ const projectOk = (r: InboxRow): boolean => q.projects.length === 0 || q.projects.includes(r.repo)
265
+ const shown = (l: InboxList): InboxRow[] => all[l].filter((r) => verbOk(l, r) && projectOk(r))
266
+ const byWait: InboxAnswer['byWait'] = {}
267
+ const byProject: Record<string, number> = {}
268
+ let waitsAll = 0
269
+ for (const l of q.state) {
270
+ for (const r of all[l]) {
271
+ if (HIS.has(l) && projectOk(r)) {
272
+ waitsAll++
273
+ for (const v of r.verbs) byWait[v] = (byWait[v] ?? 0) + 1
274
+ }
275
+ if (verbOk(l, r)) byProject[r.repo] = (byProject[r.repo] ?? 0) + 1
276
+ }
277
+ }
204
278
  const rows = shown(q.list)
205
279
  return {
206
280
  list: q.list,
@@ -208,22 +282,21 @@ export function inboxPage(all: ReturnType<typeof inboxRows>, q: ReturnType<typeo
208
282
  total: rows.length,
209
283
  offset: q.offset,
210
284
  limit: q.limit,
211
- counts: { main: shown('main').length, yellow: shown('yellow').length, later: shown('later').length },
212
- all: { main: all.main.length, yellow: all.yellow.length, later: all.later.length },
213
- show: q.show,
285
+ counts: { main: shown('main').length, working: shown('working').length, waiting: shown('waiting').length, later: shown('later').length, done: shown('done').length },
286
+ byWait,
287
+ waitsAll,
288
+ byProject,
214
289
  repos: all.repos,
215
290
  missing,
216
291
  }
217
292
  }
218
293
 
219
- const KIND_LABEL: Record<InboxKind, string> = { card: 'cards', question: 'questions', ask: 'asks', need: 'needs', raised: 'raised' }
220
-
221
294
  /** a group of rows: its words, its rows' count, then its rows or its inner groups */
222
295
  export type InboxGroupNode = { key: string; label: string; n: number; rows: InboxRow[]; groups: InboxGroupNode[] | null }
223
296
 
224
- const groupOf = (r: InboxRow, by: InboxGroup): string => (by === 'repo' ? r.repo : by === 'kind' ? KIND_LABEL[r.kind] : r.lane ?? 'no lane')
297
+ const groupOf = (r: InboxRow, by: InboxGroup): string => (by === 'project' ? r.repo : by === 'wait' ? r.wait : r.lane ?? 'no lane')
225
298
 
226
- /** the rows grouped by each axis that is on, nested repo then kind then lane; a group keeps its rows' order, and the
299
+ /** the rows grouped by each axis that is on, nested project then wait then lane; a group keeps its rows' order, and the
227
300
  * groups come in the order their first row comes (newest first). No axis on: one group of every row */
228
301
  export function groupRows(rows: readonly InboxRow[], on: readonly InboxGroup[], prefix = ''): InboxGroupNode[] {
229
302
  const axes = INBOX_GROUPS.filter((g) => on.includes(g))
@@ -245,3 +318,63 @@ export function groupRows(rows: readonly InboxRow[], on: readonly InboxGroup[],
245
318
  return { key, label: k, n: rs.length, rows: rs, groups: rest.length > 0 ? groupRows(rs, rest, key) : null }
246
319
  })
247
320
  }
321
+
322
+ /** what the page filters and groups by, and the groups folded: its hash and its kept pref */
323
+ export interface InboxFilters {
324
+ waits: WaitSel
325
+ projects: string[]
326
+ state: InboxList[]
327
+ groupBy: InboxGroup[]
328
+ /** the keys of the groups folded (InboxGroupNode.key), only those the grouping can draw */
329
+ fold: string[]
330
+ }
331
+
332
+ const GROUP_KEYS = new Set<string>(INBOX_GROUPS)
333
+
334
+ /** the folds a grouping can draw: a key's axes, in order, are the first axes grouped by (`wait:judge/` under wait,
335
+ * `project:orchard/wait:judge/` under project then wait); a folded list's keys lead with the list (`working/wait:do/`) */
336
+ export function foldsUnder(fold: readonly string[], groupBy: readonly InboxGroup[]): string[] {
337
+ return [...new Set(fold)].filter((k) => {
338
+ const axes = [...k.matchAll(/(?:^|\/)(project|wait|lane):/g)].map((m) => m[1])
339
+ return axes.length > 0 && axes.length <= groupBy.length && axes.every((a, i) => a === groupBy[i])
340
+ })
341
+ }
342
+
343
+ /** a fold key as text: the trailing slash left out, slashes and colons kept readable */
344
+ const foldText = (k: string): string => enc(k.replace(/\/$/, '')).replaceAll('%2F', '/')
345
+
346
+ /** the filters as text, `waits=judge,answer&projects=orchard&state=main&group=project&fold=project:orchard`: the hash
347
+ * and the kept pref share it, what is at its default left out */
348
+ export function filtersText(f: InboxFilters): string {
349
+ const p = inboxSearch({ waits: f.waits, projects: f.projects, state: f.state }).replace(/^\?/, '')
350
+ const fold = foldsUnder(f.fold, f.groupBy)
351
+ return [p, f.groupBy.length > 0 ? `group=${f.groupBy.join(',')}` : '', fold.length > 0 ? `fold=${fold.map(foldText).join(',')}` : ''].filter((x) => x !== '').join('&')
352
+ }
353
+
354
+ /** filters read back from their text: a part missing or broken is its default */
355
+ export function filtersOf(text: string): InboxFilters {
356
+ const kv = new Map<string, string>()
357
+ for (const part of text.split('&')) {
358
+ const at = part.indexOf('=')
359
+ if (at > 0) kv.set(part.slice(0, at), part.slice(at + 1))
360
+ }
361
+ const list = (k: string): string[] | null => {
362
+ const v = kv.get(k)
363
+ if (v == null) return null
364
+ try {
365
+ return v.split(',').filter((x) => x !== '').map(decodeURIComponent)
366
+ } catch {
367
+ return []
368
+ }
369
+ }
370
+ const waits = list('waits')
371
+ const state = list('state')
372
+ const groupBy = INBOX_GROUPS.filter((g) => (list('group') ?? []).filter((x) => GROUP_KEYS.has(x)).includes(g))
373
+ return {
374
+ waits: waits == null ? null : ownerVerbsIn(waits),
375
+ projects: list('projects') ?? [],
376
+ state: state == null ? [...DEFAULT_STATE] : withWaiting(INBOX_LISTS.filter((l) => state.includes(l))),
377
+ groupBy,
378
+ fold: foldsUnder((list('fold') ?? []).map((k) => `${k}/`), groupBy),
379
+ }
380
+ }