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
@@ -2,21 +2,20 @@
2
2
  // message, each platform's part handed to its speaker's account; the rhythm; the load's errors. Read from the disk as
3
3
  // it is on every call: the desks and `sk social` never hold a stale copy
4
4
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
5
- import { join, relative, resolve, sep } from 'node:path'
5
+ import { basename, join, relative } from 'node:path'
6
6
  import { LAYOUT } from '../core/layout.ts'
7
7
  import { filledText, speakerOf, type Account, type Identities, type Identity } from '../identities/identities.ts'
8
8
  import { isPostRating, POST_RATINGS, takes, type PostRating } from '../identities/rating.ts'
9
9
  import { secretOfRef, setupProblems } from '../identities/steps.ts'
10
- import { fileList, groupKeys, longVideo, mediaNames, parseDraft, renderedTrailer, resolveMedia, tagList, topicList, type Topic } from './drafts.ts'
10
+ import { fileList, groupKeys, longVideo, mediaNames, tagList, topicList, type ParsedDraft, type Topic } from './drafts.ts'
11
11
  import { compose, fillLink, messageLength } from './compose.ts'
12
12
  import { frameProblem } from './cover.ts'
13
13
  import { parseFrontmatter, table } from './md.ts'
14
14
  import { type Family, familyOf, type Slot, slotOf, type WeeklySlot, weeklySlots } from './presence.ts'
15
- import { purgedAt } from './media-facts.ts'
16
15
  import { identityProblems } from './identity-words.ts'
17
16
  import { deskKinds, type DeskKind } from './kind-pages.ts'
18
17
  import { kindOfMeta, kindProblem } from './kinds.ts'
19
- import { heavyMedia, limitProblem, mbOf, MEDIA_MAX_BYTES } from './media-limit.ts'
18
+ import { limitProblem } from './media-limit.ts'
20
19
  import { pushFailure } from './push.ts'
21
20
  import { releaseVersionOf } from '../releases/store.ts'
22
21
  import { ceilingAt, hasLayout, landing, placesOf, type Landing } from './reach.ts'
@@ -64,7 +63,7 @@ function ratingOf(raw: string | undefined, adult: boolean, who: string, file: st
64
63
 
65
64
 
66
65
  /** a media as the draft names it, and where it is on the disk: its folder, the repo, or anywhere */
67
- export type Media = { name: string; path: string }
66
+ export type Media = { name: string; path: string; sha?: string; size?: number; key?: string }
68
67
 
69
68
  /** one account's part of a draft: what its card shows and what a publisher sends */
70
69
  export type SocialPost = {
@@ -79,8 +78,13 @@ export type SocialPost = {
79
78
  /** the draft's file, from the repo's root */
80
79
  file: string
81
80
  status: string
82
- /** the URL of its line under `## Posted`; empty, it waits */
81
+ /** its link once posted; empty, it waits */
83
82
  posted: string
83
+ /** when it was posted, and where that moment came from (its link, the commit that recorded it, his mark) */
84
+ postedAt?: number | null
85
+ postedFrom?: string
86
+ /** the group heading it was written under (`short`, `vertical`); empty for an account's own */
87
+ format: string
84
88
  kind: string
85
89
  title: string
86
90
  angle: string
@@ -114,6 +118,8 @@ export type SocialPost = {
114
118
  rating: PostRating
115
119
  /** why it may not go out: the repo's guard on its draft, or a place under its rating; empty, it may */
116
120
  refused: string
121
+ /** he will not post it here: its key is in the draft's `dropped` */
122
+ dropped?: boolean
117
123
  }
118
124
 
119
125
  /** a draft's post.md: a long article of the identity's site */
@@ -154,6 +160,8 @@ export type Draft = {
154
160
  guard: string[]
155
161
  /** the accounts its group headings skip, no place of theirs taking its rating, and why */
156
162
  skipped: { account: string; why: string }[]
163
+ /** the message keys he will not post (front matter `dropped`) */
164
+ dropped?: string[]
157
165
  }
158
166
 
159
167
  /** an identity's account with the repo's messages to it */
@@ -189,7 +197,7 @@ export const VERTICAL_FILE = /-vertical\.mp4$/
189
197
  /** what one message breaks on its account: a text past the account's max, more tags than its `max tags`, a tier its
190
198
  * account has not, a `## vertical` message without its video */
191
199
  export function messageErrors(
192
- post: Pick<SocialPost, 'file' | 'from' | 'length' | 'media' | 'tags' | 'tier'>,
200
+ post: Pick<SocialPost, 'file' | 'from' | 'length' | 'media' | 'tags' | 'tier'> & { format?: string },
193
201
  a: Pick<Account, 'name' | 'max' | 'maxTags' | 'tiers'>,
194
202
  ): string[] {
195
203
  const out: string[] = []
@@ -198,7 +206,7 @@ export function messageErrors(
198
206
  out.push(`${post.file}: ## ${post.from} has ${post.tags.length} tags on ${a.name}, over its ${a.maxTags}`)
199
207
  if (post.tier !== '' && !a.tiers.includes(post.tier))
200
208
  out.push(`${post.file}: ## ${post.from} tier "${post.tier}" is none of ${a.name}'s: ${a.tiers.join(', ') || 'it has no tiers'}`)
201
- if (post.from.split('/')[0] === VERTICAL && !VERTICAL_FILE.test(post.media?.name ?? ''))
209
+ if ((post.format || post.from.split('/')[0]) === VERTICAL && !VERTICAL_FILE.test(post.media?.name ?? ''))
202
210
  out.push(`${post.file}: ## ${post.from} goes to ${a.name} without its vertical video (media: media/<name>-vertical.mp4)`)
203
211
  return out
204
212
  }
@@ -215,33 +223,64 @@ function weekly(root: string, errors: string[]): WeeklySlot[] {
215
223
  return existsSync(abs) ? weeklySlots(table(parseFrontmatter(read(abs)).body, 'Slots'), relative(root, abs), errors) : []
216
224
  }
217
225
 
218
- function article(dir: string, root: string, unit: SocialUnit | null): Article | null {
219
- const abs = join(dir, 'post.md')
220
- if (!existsSync(abs)) return null
221
- const { meta } = parseFrontmatter(read(abs))
226
+ /** a long devlog post's facts from its bytes, its address on the identity's site from the social unit */
227
+ function article(bytes: string | null, dir: string, file: string, unit: SocialUnit | null): Article | null {
228
+ if (bytes == null) return null
229
+ const { meta } = parseFrontmatter(bytes)
222
230
  let url = ''
223
231
  try {
224
232
  url = unit?.article?.(dir).url ?? ''
225
233
  } catch {
226
234
  url = ''
227
235
  }
228
- return { title: meta.title ?? '', description: meta.description ?? '', date: meta.date ?? '', draft: meta.draft === 'true', url, file: relative(root, abs) }
236
+ return { title: meta.title ?? '', description: meta.description ?? '', date: meta.date ?? '', draft: meta.draft === 'true', url, file }
229
237
  }
230
238
 
231
- /** the v2 channel files left in the folder: each one an error naming the command that moves it */
232
- function v2Left(root: string, errors: string[]): void {
239
+ /** the social folder holds rhythm.md and README.md: a v2 channel folder is an error; a drafts folder is no longer read,
240
+ * and each draft in it no group of the database is, an error naming the import (stage, save and Publish refuse then) */
241
+ function folderLeft(root: string, errors: string[], warnings: string[]): void {
242
+ const { unimported } = require('./post-sources.ts') as typeof import('./post-sources.ts')
233
243
  const at = join(root, LAYOUT.social)
234
244
  if (!existsSync(at)) return
235
245
  for (const e of readdirSync(at)) {
236
- if (e === 'drafts' || FOLDER_FILES.has(e) || e.startsWith('.')) continue
246
+ if (FOLDER_FILES.has(e) || e.startsWith('.')) continue
237
247
  const abs = join(at, e)
238
- if (statSync(abs).isDirectory() && readdirSync(abs).some((f) => f.endsWith('.md'))) errors.push(`${relative(root, abs)}/: a v2 channel folder; sk social migrate makes its posts drafts`)
239
- else errors.push(`${relative(root, abs)}: the social folder holds drafts/, rhythm.md and README.md only`)
248
+ if (e === 'drafts') {
249
+ const left = unimported(root)
250
+ if (left.length > 0) errors.push(`${relative(root, abs)}/: ${left.length} draft${left.length === 1 ? '' : 's'} in no group of the database, read by nothing (${left.slice(0, 3).join(', ')}${left.length > 3 ? ', …' : ''}): sk social drafts import --go; stage, save and Publish wait for it`)
251
+ else warnings.push(`${relative(root, abs)}/: no longer read, its drafts are groups of the database: the folder may go once no tool of the repo reads it`)
252
+ }
253
+ else if (statSync(abs).isDirectory() && readdirSync(abs).some((f) => f.endsWith('.md'))) errors.push(`${relative(root, abs)}/: a v2 channel folder, no longer read`)
254
+ else errors.push(`${relative(root, abs)}: the social folder holds rhythm.md and README.md only`)
240
255
  }
241
256
  }
242
257
 
243
- /** the desk of a repo: every identity with its accounts, the repo's drafts on them, the newest first */
258
+ /** one draft as the builder takes it: a group and its posts from the database, or a text (a stage, a save, the import) */
259
+ export type DraftSource = {
260
+ slug: string
261
+ /** how its lines name it: `draft:<slug>`, or the text's own name */
262
+ file: string
263
+ /** its address as a folder: the social unit's `article(dir)` and `preview(dir)` read its name */
264
+ dir: string
265
+ /** the text form parsed with the groups of its speaker's accounts */
266
+ parse: (groups: ReadonlyMap<string, readonly string[]>) => ParsedDraft
267
+ /** a media name to its file; null when no file holds it */
268
+ media: (name: string) => Media | null
269
+ /** a long devlog post's bytes, null without one */
270
+ article: string | null
271
+ /** each posted post's moment, by key */
272
+ postedAt?: ReadonlyMap<string, { at: number | null; from: string }>
273
+ }
274
+
275
+ /** the desk of a repo: every identity with its accounts, the repo's posts on them, the newest group first. The groups
276
+ * and posts are the database's (post-sources.ts); a stage, a save and the import build theirs from a text (`deskOf`) */
244
277
  export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string | undefined; unit?: SocialUnit | null; now?: Date } = {}): Desk {
278
+ const { groupSources } = require('./post-sources.ts') as typeof import('./post-sources.ts')
279
+ return deskOf(root, ids, groupSources(root), o)
280
+ }
281
+
282
+ /** the desk built from these drafts */
283
+ export function deskOf(root: string, ids: Identities, sources: readonly DraftSource[], o: { speaksAs?: string | undefined; unit?: SocialUnit | null; now?: Date } = {}): Desk {
245
284
  const errors = [...ids.errors]
246
285
  const warnings: string[] = []
247
286
  const unit = o.unit ?? null
@@ -251,51 +290,35 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
251
290
  const pushed = pushFailure(root)
252
291
  if (pushed != null) errors.push(pushed)
253
292
  const week = weekly(root, errors)
254
- v2Left(root, errors)
255
- const dir = draftsDir(root)
293
+ folderLeft(root, errors, warnings)
256
294
  const drafts: Draft[] = []
257
- const named = new Set<string>()
258
295
  // the Saturday tag joins on the Mac's Saturday
259
296
  const saturday = (o.now ?? new Date()).getDay() === 6
260
- for (const slug of existsSync(dir) ? readdirSync(dir).sort().reverse() : []) {
261
- if (slug.startsWith('.')) continue
262
- const ddir = join(dir, slug)
263
- const abs = join(ddir, 'draft.md')
264
- const file = relative(root, abs)
265
- if (!DRAFT_NAME.test(slug) || !statSync(ddir).isDirectory()) {
266
- errors.push(`${relative(root, ddir)}: a draft is a folder <YYYYMMDD-HHMMSS>-<topic>/ holding draft.md`)
267
- continue
268
- }
269
- if (!existsSync(abs)) {
270
- errors.push(`${relative(root, ddir)}: no draft.md`)
271
- continue
272
- }
273
- const raw = read(abs)
274
- const head = parseFrontmatter(raw).meta
297
+ for (const src of sources) {
298
+ const { slug, file } = src
299
+ const head = src.parse(new Map()).meta
275
300
  const speaker = head.speaksAs ? ids.identities.find((i) => i.id === head.speaksAs) : own
276
301
  if (speaker == null) {
277
302
  errors.push(`${file}: ${head.speaksAs ? `speaksAs '${head.speaksAs}' is no identity` : 'no identity speaks for this repo'} (sk identities)`)
278
303
  continue
279
304
  }
280
- named.add(speaker.id)
281
305
  const accounts = identities.find((i) => i.id === speaker.id)!.accounts
282
306
  const groups = new Map([...new Set([...FORMATS, ...accounts.map((a) => a.group).filter((g) => g !== '')])].map((g) => [g, accounts.filter((a) => a.group === g).map((a) => a.id)]))
283
- const d = parseDraft(raw, file, groups)
307
+ const d = src.parse(groups)
284
308
  errors.push(...d.errors)
285
309
  const media = new Map<string, Media>()
286
310
  for (const name of mediaNames(d)) {
287
- const path = resolveMedia(name, ddir, root) ?? (renderedTrailer(name, raw, relative(root, ddir)) ? join(ddir, name) : null) ?? purgedAt(root, ddir, name)
288
- if (path == null) errors.push(`${file}: media "${name}" is in neither its folder, the repo, at that path, nor in the Space`)
289
- else media.set(name, { name, path })
311
+ const m = src.media(name)
312
+ if (m == null) errors.push(`${file}: media "${name}" is no file of it (sk social draft media ${slug} <file> --name ${name})`)
313
+ else media.set(name, m)
290
314
  }
291
- for (const h of heavyMedia(root, [...media.values()].map((m) => m.path))) errors.push(`${file}: media "${relative(ddir, h.path)}" is ${mbOf(h.size)}, over the ${mbOf(MEDIA_MAX_BYTES)} GitHub takes: shrink it, name it *-trailer.mp4 when its command renders it, or keep it with sk media put`)
292
315
  const pick = (list: string | undefined): Media[] => fileList(list).flatMap((n) => media.get(n) ?? [])
293
316
  const ownMedia = pick(d.meta.media)
294
317
  const draft: Draft = {
295
318
  slug,
296
319
  file,
297
- path: abs,
298
- dir: ddir,
320
+ path: '',
321
+ dir: src.dir,
299
322
  identity: speaker.id,
300
323
  title: d.meta.title ?? '',
301
324
  kind: kindOfMeta(d.meta).kind,
@@ -308,13 +331,14 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
308
331
  media: [...media.values()],
309
332
  alt: d.meta.alt ?? '',
310
333
  posts: [],
311
- article: article(ddir, root, unit),
334
+ article: article(src.article, src.dir, `${file} article`, unit),
312
335
  review: reviewOf(d.meta.review, file, errors),
313
336
  release: releaseOf(d.meta.release, file, errors),
314
337
  releaseVersion: releaseVersionOf(root, d.meta.release),
315
338
  rating: ratingOf(d.meta.rating, speaker.adult, speaker.name, file, errors),
316
339
  guard: [],
317
340
  skipped: [],
341
+ dropped: fileList(d.meta.dropped),
318
342
  }
319
343
  const kp = kindProblem(draft.kind, draft.kindWhy, unit?.kinds ?? [])
320
344
  if (kp != null) {
@@ -363,7 +387,8 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
363
387
  errors.push(`${file}: ${refused}`)
364
388
  }
365
389
  }
366
- const footer = from.split('/')[0] === VERTICAL ? footerText : ''
390
+ const format = s.format ?? (from !== key ? from.split('/')[0]! : '')
391
+ const footer = (format || from.split('/')[0]) === VERTICAL ? footerText : ''
367
392
  const tags = tagList(s.options.tags)
368
393
  // `[[row]]` is that account's row (its `[[links]]`), so a list the identity keeps never goes stale in a draft
369
394
  const filled = filledText(s.text, a.rows, `${file}: ## ${key}`, errors)
@@ -374,6 +399,8 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
374
399
  errors.push(`${file}: ## ${a.id} place "${place}" is no ${hasLayout(a) ? `channel of ${a.id}/layout.md` : `file of ${a.id}/places/`}`)
375
400
  const title = s.options.title ?? ''
376
401
  const write = at?.write || a.write
402
+ const posted = d.posted.get(key) ?? ''
403
+ const moment = posted === '' ? undefined : src.postedAt?.get(key)
377
404
  const post: SocialPost = {
378
405
  slug,
379
406
  identity: speaker.id,
@@ -382,7 +409,8 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
382
409
  name: s.options.name ?? '',
383
410
  file,
384
411
  status: draft.status,
385
- posted: d.posted.get(key) ?? '',
412
+ posted,
413
+ ...(moment ? { postedAt: moment.at, postedFrom: moment.from } : {}),
386
414
  kind: draft.kind,
387
415
  title,
388
416
  angle: d.angle,
@@ -401,12 +429,14 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
401
429
  pin: s.options.pin === 'true',
402
430
  embeds: s.options.embeds !== 'none',
403
431
  from,
432
+ format,
404
433
  footer,
405
434
  rating,
406
435
  refused,
436
+ ...(draft.dropped?.includes(key) ? { dropped: true } : {}),
407
437
  }
408
438
  errors.push(...messageErrors(post, a))
409
- if (post.media != null) {
439
+ if (post.media != null && existsSync(post.media.path)) {
410
440
  const over = limitProblem(post.media.path, a.limits)
411
441
  if (over != null) errors.push(`${file}: media "${post.media.name}" ${over} on ${a.name}: « fit » makes it a copy that fits`)
412
442
  }
@@ -419,6 +449,9 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
419
449
  draft.guard = guardWith(unit, { title: draft.title, alt: draft.alt, texts: [...new Set(said.filter((t) => t.trim() !== ''))], files: draft.media.map((m) => m.path) })
420
450
  for (const g of draft.guard) errors.push(`${file}: ${g}`)
421
451
  for (const p of draft.posts) if (draft.guard.length > 0) p.refused = `the repo's guard: ${draft.guard[0]}`
452
+ for (const k of draft.dropped ?? []) if (!draft.posts.some((p) => p.key === k)) errors.push(`${file}: dropped names ${k}, no message of the draft (${draft.posts.map((p) => p.key).join(', ') || 'none'})`)
453
+ // a place he dropped is never sent: the one refusal every copy, open and publish already reads
454
+ for (const p of draft.posts) if (p.dropped && p.posted === '' && p.refused === '') p.refused = 'dropped: he will not post it here'
422
455
  // a venue that picks a frame of the video as its picture offers frame 0 first: the video opens on its thumbnail
423
456
  for (const p of draft.posts) {
424
457
  const venue = accounts.find((a) => a.id === p.platform)?.name ?? p.platform
@@ -462,28 +495,20 @@ export function accountOf(desk: Desk, identity: string, account: string): DeskAc
462
495
  return a
463
496
  }
464
497
 
465
- /** a draft by what a command was given: its folder's name, its topic, or its path (relative to `cwd` or absolute, a
466
- * trailing slash or its `draft.md` alike); a path outside the drafts folder is refused */
467
- export function findDraft(desk: Desk, ref: string, cwd: string): Draft {
468
- const where = `${LAYOUT.social}/drafts/`
469
- let name = ref
470
- if (ref.includes('/') || ref.endsWith('.md') || ref === '.') {
471
- const parts = relative(draftsDir(desk.root), resolve(cwd, ref)).split(sep).filter((x) => x !== '')
472
- if (parts.length === 2 && parts[1]!.endsWith('.md')) parts.pop()
473
- if (parts.length !== 1 || parts[0] === '..') throw new Error(`${ref} is no draft of ${where}: a draft is a folder right under it`)
474
- name = parts[0]!
475
- }
498
+ /** a draft by what a command was given: its slug, its topic, or an old path to its folder (its last part) */
499
+ export function findDraft(desk: Desk, ref: string, _cwd?: string): Draft {
500
+ const name = ref.includes('/') || ref.endsWith('.md') ? basename(ref.replace(/\/draft\.md$/, '').replace(/\/+$/, '')) : ref
476
501
  const hits = desk.drafts.filter((x) => x.slug === name || x.slug.replace(/^\d{8}-\d{6}-/, '') === name)
477
- if (hits.length > 1) throw new Error(`"${ref}" is the topic of ${hits.length} drafts: ${hits.map((x) => x.slug).join(', ')}; give its folder's name`)
478
- if (hits[0] == null) throw new Error(`no draft "${ref}" in ${where}: give its folder's name, its topic or its path`)
502
+ if (hits.length > 1) throw new Error(`"${ref}" is the topic of ${hits.length} drafts: ${hits.map((x) => x.slug).join(', ')}; give its slug`)
503
+ if (hits[0] == null) throw new Error(`no draft "${ref}" in the database: give its slug or its topic (sk social)`)
479
504
  return hits[0]
480
505
  }
481
506
 
482
507
  /** one message of a draft by its key, `<account>` or `<account>/<name>` */
483
508
  export function draftPost(desk: Desk, slug: string, key: string): SocialPost {
484
509
  const d = desk.drafts.find((x) => x.slug === slug)
485
- if (d == null) throw new Error(`no draft ${slug} in ${LAYOUT.social}/drafts/`)
510
+ if (d == null) throw new Error(`no draft ${slug} in the database`)
486
511
  const p = d.posts.find((x) => x.key === key)
487
- if (p == null) throw new Error(`no message ## ${key} in ${d.file}`)
512
+ if (p == null) throw new Error(`no post ${key} in ${slug}`)
488
513
  return p
489
514
  }
@@ -1,190 +1,97 @@
1
- // the social drafts as a kind of the media store (wiki tools/shipkit/social.md, Media): every media file of every
2
- // draft folder, and every file a draft names inside the drafts folder, by its facts (media-facts.ts). Every one goes up.
3
- // A file git tracks, or would commit, never leaves the disk: a purge would read as a deletion in git. Only a file git
4
- // ignores (a rendered trailer, a public repo's drafts) may go, and the desk then serves it from the Space
5
- import { readdirSync, readFileSync, statSync, type Dirent } from 'node:fs'
6
- import { extname, join, relative } from 'node:path'
7
- import { gitBin } from '../core/git-bin.ts'
8
- import { shaOf, shaOfKey, typeOf } from '../media-store/content.ts'
9
- import { mediaDb } from '../media-store/db.ts'
1
+ // the post groups' files as a kind of the media store (wiki tools/shipkit/social-media.md): every attachment of the
2
+ // repo's groups, read from the database, its copy at `.shipkit/post-media/<sha>/<name>`, keyed `social/<sha>.<ext>`.
3
+ // Every one goes up. A file of a group that still holds a post in draft stays on the disk (the guard and the cover read
4
+ // its bytes before a send); the others may go and come back by their key
5
+ import { existsSync, readdirSync, realpathSync, statSync } from 'node:fs'
6
+ import { basename } from 'node:path'
7
+ import { cardsDb } from '../review/card-db.ts'
8
+ import type { Attachment } from '../review/events.ts'
9
+ import { eventsRepo } from '../review/events.ts'
10
+ import { storeDir } from '../review/store.ts'
11
+ import { shaOf, shaOfKey } from '../media-store/content.ts'
10
12
  import type { MediaKind, MediaRow } from '../media-store/kind.ts'
11
13
  import { fetchBack, signedUrl } from '../media-store/remote.ts'
12
- import { mediaNames, parseDraft, resolveMedia } from './drafts.ts'
13
- import { draftsOf, factAt, readFacts, rootOfDrafts, SOCIAL_KIND, socialKey, writeFacts, type FileFact } from './media-facts.ts'
14
+ import { SOCIAL_KIND, socialKey } from './media-facts.ts'
15
+ import type { Desk, Media } from './load.ts'
16
+ import { groupsNow, mainRootOf, postMediaDir } from './post-sources.ts'
14
17
 
15
- /** a file of a draft folder that is media, whether or not its draft names it */
16
- const MEDIA_EXT = new Set(['.png', '.jpg', '.jpeg', '.webp', '.gif', '.avif', '.svg', '.mp4', '.webm', '.mov', '.m4v', '.wav', '.mp3', '.flac', '.ogg', '.opus', '.m4a', '.aac'])
18
+ /** the repo of a store: `<root>/.shipkit/post-media` */
19
+ const rootOfStore = (store: string): string => store.replace(/\/\.shipkit\/post-media\/?$/, '')
17
20
 
18
- const entries = (dir: string): Dirent[] => {
19
- try {
20
- return readdirSync(dir, { withFileTypes: true })
21
- } catch {
22
- return []
23
- }
24
- }
25
-
26
- /** every media file under a draft folder, as `<name>` relative to it; dot files and the draft's text never */
27
- function mediaFiles(dir: string, at = ''): string[] {
28
- return entries(join(dir, at)).flatMap((e) => {
29
- if (e.name.startsWith('.')) return []
30
- const rel = at === '' ? e.name : `${at}/${e.name}`
31
- if (e.isDirectory()) return mediaFiles(dir, rel)
32
- return e.isFile() && MEDIA_EXT.has(extname(e.name).toLowerCase()) ? [rel] : []
33
- })
34
- }
35
-
36
- const slugs = (store: string): string[] => entries(store).filter((e) => e.isDirectory() && !e.name.startsWith('.')).map((e) => e.name).sort()
37
-
38
- /** every `<slug>/<name>` the drafts folder holds or names, the paths on the disk */
39
- function named(store: string): Set<string> {
40
- const root = rootOfDrafts(store)
41
- const out = new Set<string>()
42
- for (const slug of slugs(store)) {
43
- const dir = join(store, slug)
44
- for (const f of mediaFiles(dir)) out.add(`${slug}/${f}`)
45
- let raw: string
46
- try {
47
- raw = readFileSync(join(dir, 'draft.md'), 'utf8')
48
- } catch {
49
- continue
50
- }
51
- for (const n of mediaNames(parseDraft(raw, ''))) {
52
- const p = resolveMedia(n, dir, root)
53
- const id = p == null ? '' : relative(store, p)
54
- if (id !== '' && !id.startsWith('..') && id.includes('/')) out.add(id)
21
+ /** every file of the repo's groups once, by sha and name, and whether a group still to post holds it */
22
+ function filesOf(store: string): Map<string, { a: Attachment & { sha: string }; waits: boolean }> {
23
+ const out = new Map<string, { a: Attachment & { sha: string }; waits: boolean }>()
24
+ for (const g of groupsNow(eventsRepo(storeDir(rootOfStore(store))))) {
25
+ const waits = g.posts.some((p) => p.post.state === 'draft')
26
+ for (const a of g.event.content.attachments ?? []) {
27
+ if (a.sha == null) continue
28
+ const id = `${a.sha}/${basename(a.name)}`
29
+ const was = out.get(id)
30
+ out.set(id, { a: { ...a, sha: a.sha }, waits: waits || (was?.waits ?? false) })
55
31
  }
56
32
  }
57
33
  return out
58
34
  }
59
35
 
60
- const split = (id: string): { item: string; name: string } => {
61
- const at = id.indexOf('/')
62
- return { item: id.slice(0, at), name: id.slice(at + 1) }
63
- }
64
-
65
- /** the files under the store git ignores and does not track: the only ones a purge may take. null: git did not answer */
66
- function ignoredOf(store: string): Set<string> | null {
67
- const r = Bun.spawnSync([gitBin(), 'ls-files', '-z', '-o', '-i', '--exclude-standard', '--', '.'], { cwd: store, stdout: 'pipe', stderr: 'ignore' })
68
- if (r.exitCode !== 0) return null
69
- return new Set(r.stdout.toString().split('\0').filter((l) => l !== ''))
70
- }
71
-
72
- /** the index's own rows of the store: the keys of files the record lost (a record deleted, a machine restored) */
73
- function indexed(store: string): Map<string, { key: string; size: number }> {
74
- const p = `${SOCIAL_KIND}/`
75
- const rows = (mediaDb()?.query('select item, name, key, size from media_files where store = ? and substr(key, 1, ?) = ?').all(store, p.length, p) ?? []) as { item: string; name: string; key: string; size: number }[]
76
- return new Map(rows.map((r) => [`${r.item}/${r.name}`, { key: r.key, size: r.size }]))
77
- }
78
-
79
36
  export const socialMedia: MediaKind = {
80
37
  kind: SOCIAL_KIND,
81
- what: 'the posts\' pictures and clips',
82
- storeOf: (root) => draftsOf(root),
38
+ what: "the posts' pictures, clips and files",
39
+ // one store a repo, its main checkout's: a worktree names none of its own
40
+ storeOf: (root) => (realpathSync(mainRootOf(root)) === realpathSync(root) ? postMediaDir(root) : null),
83
41
  stamp(store) {
84
- const parts: string[] = []
85
- for (const slug of slugs(store)) {
86
- const dir = join(store, slug)
87
- for (const f of ['draft.md', ...mediaFiles(dir)]) {
88
- const s = statSync(join(dir, f), { throwIfNoEntry: false })
89
- parts.push(`${slug}/${f}:${s?.size ?? '-'}:${s?.mtimeMs ?? '-'}`)
90
- }
91
- }
92
- return Bun.hash(parts.join('\n')).toString(36)
42
+ const repo = eventsRepo(storeDir(rootOfStore(store)))
43
+ const r = cardsDb().query('select max(last_seq) as s from thread_post_groups where repo = ?').get(repo) as { s: number | null } | null
44
+ let shas: string[] = []
45
+ try {
46
+ shas = readdirSync(store).sort()
47
+ } catch {}
48
+ return Bun.hash(`${r?.s ?? 0}:${shas.join(',')}`).toString(36)
93
49
  },
94
- async scan(store, o) {
95
- const root = rootOfDrafts(store)
96
- const facts = readFacts(root)
97
- const ids = named(store)
98
- let budget = o.fill
99
- let filled = 0
100
- let left = 0
101
- let moved = false
50
+ async scan(store) {
102
51
  const rows: MediaRow[] = []
103
- for (const id of ids) {
104
- const path = join(store, id)
105
- const s = statSync(path, { throwIfNoEntry: false })
106
- const held = facts.files[id]
107
- if (!s?.isFile()) continue
108
- if (held && held.size === s.size && held.mtime === s.mtimeMs) {
109
- rows.push({ ...split(id), fact: held, local: true })
110
- continue
111
- }
112
- if (budget <= 0) {
113
- left++
114
- // its key kept while it waits for a hash, never uploaded nor purged on a fact the disk may have moved past
115
- if (held) rows.push({ ...split(id), fact: held, local: false })
116
- continue
117
- }
118
- budget--
119
- filled++
120
- const fact: FileFact = { sha: await shaOf(path), size: s.size, type: typeOf(path), mtime: s.mtimeMs }
121
- facts.files[id] = fact
122
- moved = true
123
- rows.push({ ...split(id), fact, local: true })
52
+ for (const [id, { a }] of filesOf(store)) {
53
+ const [item, name] = [id.slice(0, id.indexOf('/')), id.slice(id.indexOf('/') + 1)]
54
+ rows.push({ item, name, fact: { sha: a.sha, size: a.size, type: a.type ?? 'application/octet-stream' }, local: statSync(`${store}/${id}`, { throwIfNoEntry: false })?.isFile() ?? false })
124
55
  }
125
- // a file off the disk keeps its row while its draft folder stands: purged, or deleted by hand, its key stays
126
- const off = (id: string): boolean => !statSync(join(store, id), { throwIfNoEntry: false })?.isFile()
127
- const alive = new Set(slugs(store))
128
- for (const [id, fact] of Object.entries(facts.files)) {
129
- if (ids.has(id)) continue
130
- if (!off(id)) {
131
- // on the disk and no media of a draft any more: the disk holds it, the record needs it no more
132
- delete facts.files[id]
133
- moved = true
134
- continue
135
- }
136
- // its draft folder gone (deleted, renamed): no row, the record keeps its key for a restore
137
- if (alive.has(split(id).item)) rows.push({ ...split(id), fact, local: false })
138
- }
139
- // the record lost a file the index still keys: taken back into it
140
- for (const [id, r] of indexed(store)) {
141
- const sha = shaOfKey(r.key)
142
- if (facts.files[id] || !sha || !off(id) || !alive.has(split(id).item)) continue
143
- const fact: FileFact = { sha, size: r.size, type: typeOf(id), mtime: 0 }
144
- facts.files[id] = fact
145
- moved = true
146
- rows.push({ ...split(id), fact, local: false })
147
- }
148
- if (moved) writeFacts(root, facts)
149
- return { rows, filled, left }
56
+ return { rows, filled: 0, left: 0 }
150
57
  },
151
58
  async holds(store) {
152
- const ignored = ignoredOf(store)
59
+ const files = filesOf(store)
153
60
  return (row) => {
154
- const id = `${row.item}/${row.name}`
155
- const mtime = Math.max(statSync(join(store, id), { throwIfNoEntry: false })?.mtimeMs ?? 0, statSync(join(store, row.item, 'draft.md'), { throwIfNoEntry: false })?.mtimeMs ?? 0)
156
- return { pinned: ignored == null || !ignored.has(id), used: mtime || undefined }
61
+ const f = files.get(`${row.item}/${row.name}`)
62
+ return { pinned: f == null || f.waits, used: statSync(`${store}/${row.item}/${row.name}`, { throwIfNoEntry: false })?.mtimeMs }
157
63
  }
158
64
  },
159
65
  async beforePurge(store, _space, row) {
160
- const path = join(store, row.item, row.name)
161
- // asked again at the last moment: a file git tracks, or would commit, never leaves the disk
162
- const ig = Bun.spawnSync([gitBin(), 'check-ignore', '-q', '--', join(row.item, row.name)], { cwd: store, stdout: 'ignore', stderr: 'ignore' })
163
- if (ig.exitCode !== 0) throw new Error(`${path} is not ignored by git: kept`)
66
+ const path = `${store}/${row.item}/${row.name}`
164
67
  if ((await shaOf(path)) !== shaOfKey(row.key)) throw new Error(`${path} does not hash to its key ${row.key}: kept`)
165
68
  },
166
69
  }
167
70
 
168
- /** a signed URL for a draft file the disk let go, null when it is on the disk or the Space lacks it */
169
- export async function socialMediaUrl(root: string, path: string): Promise<string | null> {
170
- const at = factAt(root, path)
171
- return at ? signedUrl(socialKey(at.fact, path), at.fact.size) : null
71
+ const keyOf = (m: Media): string | null => m.key ?? (m.sha ? socialKey({ sha: m.sha }, m.name) : null)
72
+
73
+ /** a signed URL for a group's file the disk does not hold, null when the Space lacks it */
74
+ export async function postMediaUrl(m: Media): Promise<string | null> {
75
+ const key = keyOf(m)
76
+ return key && m.size != null ? signedUrl(key, m.size) : null
77
+ }
78
+
79
+ /** a group's file on the disk, fetched back from the Space (checked by its sha) when missing; its path either way */
80
+ export async function postMediaBack(m: Media): Promise<string> {
81
+ const key = keyOf(m)
82
+ if (key == null || m.sha == null || m.size == null) return m.path
83
+ const store = m.path.slice(0, m.path.lastIndexOf('/', m.path.lastIndexOf('/') - 1))
84
+ const back = await fetchBack(m.path, key, { sha: m.sha, size: m.size, type: 'application/octet-stream' }, { store, item: m.sha, name: basename(m.path) })
85
+ return back ?? m.path
172
86
  }
173
87
 
174
- /** the file at `path`, fetched back from the Space when the disk let it go; the path itself when the record knows none */
175
- export async function socialMediaBack(root: string, path: string): Promise<string> {
176
- const at = factAt(root, path)
177
- if (!at) return path
178
- const { item, name } = split(at.id)
179
- const back = await fetchBack(path, socialKey(at.fact, path), at.fact, { store: draftsOf(root), item, name })
180
- if (back == null) return path
181
- // the bytes are checked by their sha: the record takes the new mtime, so no scan hashes them again
182
- const facts = readFacts(root)
183
- const f = facts.files[at.id]
184
- const mtime = statSync(back, { throwIfNoEntry: false })?.mtimeMs
185
- if (f && mtime != null && f.sha === at.fact.sha) {
186
- facts.files[at.id] = { ...f, mtime }
187
- writeFacts(root, facts)
88
+ /** the media of a draft's posts still to send (`keys`: these alone), on the disk before a send: fetched back, and a file
89
+ * neither the disk nor the Space gives refuses. The caller loads the desk again after, so the guard reads these bytes */
90
+ export async function draftMediaHere(desk: Desk, slug: string, keys?: readonly string[]): Promise<void> {
91
+ const d = desk.drafts.find((x) => x.slug === slug)
92
+ for (const p of d?.posts ?? []) {
93
+ if (p.media == null || p.posted !== '' || (keys != null && !keys.includes(p.key))) continue
94
+ const at = await postMediaBack(p.media)
95
+ if (!existsSync(at)) throw new Error(`${slug} ${p.key}: its media ${p.media.name} is neither on the disk nor in the Space`)
188
96
  }
189
- return back
190
97
  }
@@ -1,7 +1,8 @@
1
- // the media a repo's drafts could lend a reply (wiki tools/shipkit/veille.md, The page): each message of each draft with
2
- // a media file, read by the desk's own loader (load.ts) with the repo's speaker, synchronously for the Veille's routes
1
+ // the media a repo's drafts could lend a reply (wiki tools/shipkit/veille.md, The page): each post of each group with a
2
+ // media file, one a text, read by the desk's own loader (load.ts) with the repo's speaker, synchronously for the Veille's routes
3
3
  import { readFileSync } from 'node:fs'
4
4
  import { join } from 'node:path'
5
+ import { HOUSE_LAYOUT } from '../core/house-layout.ts'
5
6
  import { LAYOUT } from '../core/layout.ts'
6
7
  import { houseRootOf } from '../home/home-start.ts'
7
8
  import { readIdentities } from '../identities/identities.ts'
@@ -14,7 +15,7 @@ export const DRAFTS_DIR = join(LAYOUT.social, 'drafts')
14
15
  /** every draft's messages with a media file, one a heading, the newest draft first */
15
16
  export function draftMedia(root: string): DraftMedia[] {
16
17
  const house = houseRootOf(root)
17
- const dir = process.env['SHIPKIT_IDENTITIES_DIR'] ?? (house == null ? null : join(house, LAYOUT.identities))
18
+ const dir = process.env['SHIPKIT_IDENTITIES_DIR'] ?? (house == null ? null : join(house, HOUSE_LAYOUT.identities))
18
19
  let config = ''
19
20
  try {
20
21
  config = readFileSync(join(root, 'repo.config.ts'), 'utf8')
@@ -24,7 +25,7 @@ export function draftMedia(root: string): DraftMedia[] {
24
25
  const desk = loadDesk(root, readIdentities(dir), { speaksAs: speaksAsOfText(config) })
25
26
  return desk.drafts.flatMap((d) => {
26
27
  const seen = new Set<string>()
27
- const posts = d.posts.flatMap((p) => (p.media == null || seen.has(p.from) ? [] : (seen.add(p.from), [{ text: p.body, title: d.title, media: { path: p.media.path } }])))
28
+ const posts = d.posts.flatMap((p) => (p.media == null || seen.has(`${p.body}\0${p.media.name}`) ? [] : (seen.add(`${p.body}\0${p.media.name}`), [{ text: p.body, title: d.title, media: { path: p.media.path } }])))
28
29
  return posts.length > 0 ? [{ slug: d.slug, posts }] : []
29
30
  })
30
31
  }