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
@@ -1,5 +1,6 @@
1
- // a repo's desk as every surface opens it: its config's speaksAs, the house's identities, its social unit, then the
2
- // folder read (load.ts). The one way in for the routes and `sk social`
1
+ // a repo's desk as every surface opens it: its config's speaksAs, the house's identities, its social unit, the files of
2
+ // its groups still to post fetched back when missing, then the groups read (load.ts). The one way in for the routes and
3
+ // `sk social`
3
4
  import { loadRepoConfig } from '../repo-config.ts'
4
5
  import { loadIdentities, type Identities } from '../identities/identities.ts'
5
6
  import { loadDesk, type Desk } from './load.ts'
@@ -0,0 +1,120 @@
1
+ // one post's page (wiki tools/shipkit/social.md, Posts and their groups): the post as the desk loads it, its group and
2
+ // siblings, its versions, and every thread that refers to it, the open ones first. Read only
3
+ import { readAllCached, specOf, storeDir } from '../review/store.ts'
4
+ import { membersOf, ownAddressesOf, threadsOf, threadTitle, turnOf } from '../review/threads.ts'
5
+ import { accountOf, type Desk } from './load.ts'
6
+ import { groupNow } from './post-sources.ts'
7
+ import { postHistory, threadsReferring } from './posts.ts'
8
+
9
+ export interface ThreadRef {
10
+ /** what `sk thread show` and the threads page take: the thread's own address, else an item id of it */
11
+ key: string
12
+ /** its head item, the threads page's pick */
13
+ id: string
14
+ title: string
15
+ open: boolean
16
+ }
17
+
18
+ export interface PostObject {
19
+ slug: string
20
+ key: string
21
+ group: { title: string; kind: string; drafts: number; posted: number; dropped: number; posts: { key: string; account: string; state: string }[] }
22
+ post: { account: string; platform: string; place: string; state: string; url: string; postedAt: number | null; postedFrom: string; text: string; body: string; title: string; media: string | null; refused: string; live: boolean }
23
+ history: ReturnType<typeof postHistory>
24
+ threads: ThreadRef[]
25
+ }
26
+
27
+ /** the threads that refer to a group, resolved: its title and whether it waits on someone, the open ones first */
28
+ export function refsOf(root: string, slug: string): ThreadRef[] {
29
+ const dir = storeDir(root)
30
+ const threads = threadsOf(readAllCached(dir).items, specOf(dir))
31
+ const out: ThreadRef[] = []
32
+ for (const key of threadsReferring(root, slug)) {
33
+ const t = threads.find((x) => ownAddressesOf(x, specOf(dir)).includes(key) || membersOf(x).some((m) => m.item.id === key))
34
+ if (t != null) out.push({ key, id: t.head.item.id, title: threadTitle(t), open: turnOf(t) !== 'done' })
35
+ }
36
+ return out.sort((a, b) => Number(b.open) - Number(a.open))
37
+ }
38
+
39
+ export function postObject(root: string, desk: Desk, slug: string, key: string): PostObject | null {
40
+ const g = groupNow(root, slug)
41
+ const own = g?.posts.find((p) => p.post.key === key)
42
+ if (g == null || own == null) return null
43
+ const d = desk.drafts.find((x) => x.slug === slug)
44
+ const m = d?.posts.find((x) => x.key === key)
45
+ const name = (platform: string): string => {
46
+ try {
47
+ return accountOf(desk, d?.identity ?? '', platform).name
48
+ } catch {
49
+ return platform
50
+ }
51
+ }
52
+ const live = (() => {
53
+ try {
54
+ return accountOf(desk, d?.identity ?? '', own.post.platform).automation === 'live'
55
+ } catch {
56
+ return false
57
+ }
58
+ })()
59
+ const counts = { drafts: 0, posted: 0, dropped: 0 }
60
+ for (const p of g.posts) counts[p.post.state === 'draft' ? 'drafts' : p.post.state]++
61
+ return {
62
+ slug,
63
+ key,
64
+ group: { title: g.event.content.title ?? '', kind: g.group.meta['kind'] ?? '', ...counts, posts: g.posts.map((p) => ({ key: p.post.key, account: name(p.post.platform), state: p.post.state })) },
65
+ post: {
66
+ account: name(own.post.platform),
67
+ platform: own.post.platform,
68
+ place: own.post.place,
69
+ state: own.post.state,
70
+ url: own.post.url ?? '',
71
+ postedAt: own.post.postedAt ?? null,
72
+ postedFrom: own.post.postedFrom ?? '',
73
+ text: m?.text ?? own.event.content.body ?? '',
74
+ body: own.event.content.body ?? '',
75
+ title: own.event.content.title ?? '',
76
+ media: m?.media?.name ?? null,
77
+ refused: m?.refused ?? '',
78
+ live,
79
+ },
80
+ history: postHistory(root, slug, key),
81
+ threads: refsOf(root, slug),
82
+ }
83
+ }
84
+
85
+ export interface GroupObject {
86
+ slug: string
87
+ title: string
88
+ kind: string
89
+ drafts: number
90
+ posted: number
91
+ dropped: number
92
+ posts: { key: string; account: string; platform: string; place: string; state: string; url: string; text: string; refused: string; live: boolean; version: number }[]
93
+ }
94
+
95
+ /** a group as the thread's block draws it: one row a post, each with what its controls need */
96
+ export function groupObject(root: string, desk: Desk, slug: string): GroupObject | null {
97
+ const g = groupNow(root, slug)
98
+ if (g == null) return null
99
+ const d = desk.drafts.find((x) => x.slug === slug)
100
+ const acc = (platform: string) => {
101
+ try {
102
+ return accountOf(desk, d?.identity ?? '', platform)
103
+ } catch {
104
+ return null
105
+ }
106
+ }
107
+ const counts = { drafts: 0, posted: 0, dropped: 0 }
108
+ for (const p of g.posts) counts[p.post.state === 'draft' ? 'drafts' : p.post.state]++
109
+ return {
110
+ slug,
111
+ title: g.event.content.title ?? '',
112
+ kind: g.group.meta['kind'] ?? '',
113
+ ...counts,
114
+ posts: g.posts.map(({ event, post }) => {
115
+ const m = d?.posts.find((x) => x.key === post.key)
116
+ const a = acc(post.platform)
117
+ return { key: post.key, account: a?.name ?? post.platform, platform: post.platform, place: post.place, state: post.state, url: post.url ?? '', text: m?.text ?? event.content.body ?? '', refused: m?.refused ?? '', live: a?.automation === 'live', version: post.version }
118
+ }),
119
+ }
120
+ }
@@ -0,0 +1,136 @@
1
+ // the repo's post groups and their posts as the desk's drafts (wiki tools/shipkit/social.md, Posts and their groups):
2
+ // each group's newest state and each of its posts' newest, read from the events by the projections' `event` id, made
3
+ // the text form's parts the load's one builder takes. The one constraint a reader breaks first: this reads, never writes
4
+ import type { Database } from 'bun:sqlite'
5
+ import { existsSync, readdirSync } from 'node:fs'
6
+ import { basename, dirname, join } from 'node:path'
7
+ import { LAYOUT } from '../core/layout.ts'
8
+ import { cardsDb, gitCommonDir } from '../review/card-db.ts'
9
+ import { eventOfRow, eventsRepo, type Attachment, type ThreadEvent } from '../review/events.ts'
10
+ import { groupOf, postOf, type GroupContent, type PostContent } from '../review/projections.ts'
11
+ import { storeDir } from '../review/store.ts'
12
+ import type { DraftSection, Option, ParsedDraft } from './drafts.ts'
13
+ import { DRAFT_NAME, draftsDir, type DraftSource, type Media } from './load.ts'
14
+
15
+ /** a repo's main checkout: a worktree's files go to the store the repo keeps, never one a worktree removal takes */
16
+ export function mainRootOf(root: string): string {
17
+ const c = gitCommonDir(root)
18
+ return c != null && basename(c) === '.git' ? dirname(c) : root
19
+ }
20
+
21
+ /** the repo's copy of its groups' files, one folder a sha, in its main checkout: `.shipkit/post-media/<sha>/<name>` */
22
+ export const postMediaDir = (root: string): string => join(mainRootOf(root), LAYOUT.postMedia)
23
+
24
+ /** the drafts a `.shipkit/social/drafts/` folder holds that no group of the database is: written there after the import
25
+ * (an old page, an older branch, a project's own tool), they are read by nothing until imported */
26
+ export function unimported(root: string): string[] {
27
+ const dir = draftsDir(root)
28
+ let slugs: string[] = []
29
+ try {
30
+ slugs = readdirSync(dir).filter((s) => DRAFT_NAME.test(s) && existsSync(join(dir, s, 'draft.md')))
31
+ } catch {
32
+ return []
33
+ }
34
+ if (slugs.length === 0) return []
35
+ const held = new Set((cardsDb().query('select slug from thread_post_groups where repo = ?').all(eventsRepo(storeDir(root))) as { slug: string }[]).map((r) => r.slug))
36
+ return slugs.filter((s) => !held.has(s)).sort()
37
+ }
38
+
39
+ /** a write that adds or sends a post refuses while a drafts folder holds a draft no group is: the import comes first */
40
+ export function refuseUnimported(root: string): void {
41
+ const left = unimported(root)
42
+ if (left.length > 0) throw new Error(`${left.length} draft${left.length === 1 ? '' : 's'} of .shipkit/social/drafts/ ${left.length === 1 ? 'is' : 'are'} in no group of the database (${left.slice(0, 3).join(', ')}${left.length > 3 ? ', …' : ''}): sk social drafts import --go first`)
43
+ }
44
+ const base = (name: string): string => name.split('/').pop() ?? name
45
+ export const postMediaPath = (root: string, sha: string, name: string): string => join(postMediaDir(root), sha, base(name))
46
+
47
+ export const groupAddress = (slug: string): string => `draft:${slug}`
48
+ export const postAddress = (slug: string, key: string): string => `draft:${slug}/${key}`
49
+
50
+ export interface GroupNow {
51
+ event: ThreadEvent
52
+ group: GroupContent
53
+ posts: { event: ThreadEvent; post: PostContent; firstSeq: number }[]
54
+ }
55
+
56
+ type Ev = Parameters<typeof eventOfRow>[0]
57
+
58
+ /** the why of a post its group's text no longer names: out of the group until a text names it again */
59
+ export const REMOVED = 'removed'
60
+ const isRemoved = (p: PostContent): boolean => p.state === 'dropped' && p.why === REMOVED
61
+
62
+ /** every group of a repo with its posts, each at its newest event; the newest group first. A removed post is left out
63
+ * unless `removed` asks for it (a text that names it again takes its next version) */
64
+ export function groupsNow(repo: string, db: Database = cardsDb(), only?: string, removed = false): GroupNow[] {
65
+ const where = only == null ? '' : ' and g.slug = ?'
66
+ const args = only == null ? [repo] : [repo, only]
67
+ const groups = (db.query(`select e.* from thread_post_groups g join thread_events e on e.repo = g.repo and e.id = g.event where g.repo = ?${where} order by g.slug desc`).all(...args) as Ev[]).map(eventOfRow)
68
+ const posts = db.query(`select e.*, p.first_seq as first from thread_posts p join thread_events e on e.repo = p.repo and e.id = p.event where p.repo = ?${only == null ? '' : ' and p.slug = ?'} order by p.first_seq`).all(...args) as (Ev & { first: number })[]
69
+ const by = new Map<string, GroupNow['posts']>()
70
+ for (const r of posts) {
71
+ const event = eventOfRow(r)
72
+ const post = postOf(event)
73
+ if (!removed && isRemoved(post)) continue
74
+ by.set(post.group, [...(by.get(post.group) ?? []), { event, post, firstSeq: r.first }])
75
+ }
76
+ return groups.map((event) => {
77
+ const group = groupOf(event)
78
+ return { event, group, posts: by.get(group.slug) ?? [] }
79
+ })
80
+ }
81
+
82
+ /** one group of the repo at `root`, null when none */
83
+ export const groupNow = (root: string, slug: string, removed = false): GroupNow | null => groupsNow(eventsRepo(storeDir(root)), cardsDb(), slug, removed)[0] ?? null
84
+
85
+ /** a post's heading options as the text form names them: its name from its key, its place, then its own */
86
+ export function optionsOf(p: Pick<PostContent, 'key' | 'place' | 'options'>): Partial<Record<Option, string>> {
87
+ const name = p.key.includes('/') ? p.key.slice(p.key.indexOf('/') + 1) : undefined
88
+ return { ...(name ? { name } : {}), ...(p.place ? { place: p.place } : {}), ...(p.options as Partial<Record<Option, string>>) }
89
+ }
90
+
91
+ /** the text form's parts of a group as it stands: front matter, angle, one section a post, the posted links */
92
+ export function parsedOf(g: GroupNow): ParsedDraft {
93
+ const dropped = g.posts.filter((p) => p.post.state === 'dropped').map((p) => p.post.key)
94
+ const meta: Record<string, string> = {
95
+ ...g.group.meta,
96
+ title: g.event.content.title ?? '',
97
+ status: g.group.picked ? 'picked' : 'draft',
98
+ ...(g.group.media.length > 0 ? { media: g.group.media.join(', ') } : {}),
99
+ ...(dropped.length > 0 ? { dropped: dropped.join(', ') } : {}),
100
+ }
101
+ const sections: DraftSection[] = g.posts.map(({ event, post }) => ({
102
+ platform: post.platform,
103
+ key: post.key,
104
+ options: optionsOf(post),
105
+ text: event.content.body ?? '',
106
+ ...(post.format ? { format: post.format } : {}),
107
+ }))
108
+ const posted = new Map(g.posts.filter((p) => p.post.state === 'posted' && p.post.url).map((p) => [p.post.key, p.post.url!]))
109
+ return { meta, angle: g.event.content.body ?? '', sections, posted, errors: [] }
110
+ }
111
+
112
+ /** a group's file by the name its posts give it, at its place in the repo's copy (fetched back when missing) */
113
+ export function mediaOf(root: string, files: readonly Attachment[], name: string): Media | null {
114
+ const a = files.find((x) => x.name === name)
115
+ if (a?.sha == null) return null
116
+ return { name, path: postMediaPath(root, a.sha, name), sha: a.sha, size: a.size, ...(a.key ? { key: a.key } : {}) }
117
+ }
118
+
119
+ /** the desk's drafts of the repo at `root`: one a group */
120
+ export function groupSources(root: string): DraftSource[] {
121
+ return groupsNow(eventsRepo(storeDir(root))).map((g) => {
122
+ const slug = g.group.slug
123
+ const parsed = parsedOf(g)
124
+ const files = g.event.content.attachments ?? []
125
+ const postedAt = new Map(g.posts.filter((p) => p.post.state === 'posted').map((p) => [p.post.key, { at: p.post.postedAt ?? null, from: p.post.postedFrom ?? 'unknown' }]))
126
+ return {
127
+ slug,
128
+ file: groupAddress(slug),
129
+ dir: join(draftsDir(root), slug),
130
+ parse: () => parsed,
131
+ media: (name: string) => mediaOf(root, files, name),
132
+ article: g.group.article,
133
+ postedAt,
134
+ }
135
+ })
136
+ }
@@ -0,0 +1,103 @@
1
+ // a group's text form (wiki tools/shipkit/social.md, The text form of a group): the shape an agent and a stage write, read
2
+ // by the desk's own builder (`deskOf`) so every check of the desk runs on it, then written as events (posts.ts). A form,
3
+ // never a file kept: `show` prints it from the events, `save` parses it back. The one constraint a reader breaks first:
4
+ // a post's state never moves through the text, only through its verbs
5
+ import { join } from 'node:path'
6
+ import { loadIdentities } from '../identities/identities.ts'
7
+ import { eventsRepo, type Attachment } from '../review/events.ts'
8
+ import { storeDir } from '../review/store.ts'
9
+ import { idOf } from '../review/model.ts'
10
+ import { parseDraft, type ParsedDraft } from './drafts.ts'
11
+ import { deskOf, draftsDir, DRAFT_NAME, type Draft, type DraftSource, type Media } from './load.ts'
12
+ import { groupNow, groupsNow, mediaOf, optionsOf, postMediaPath, refuseUnimported, type GroupNow } from './post-sources.ts'
13
+ import { threadsFor, keepPostFile, senderOf, writeText, type Written } from './posts.ts'
14
+ import type { SocialUnit } from './unit.ts'
15
+
16
+ export type TextCtx = { unit: SocialUnit | null; speaksAs: string | undefined; identitiesDir?: string | null }
17
+
18
+ /** a text as the builder's source: its media by name, its article's bytes; `seen` keeps what the builder parsed */
19
+ export function textSource(root: string, slug: string, raw: string, media: ReadonlyMap<string, Media>, article: string | null, seen: { parsed?: ParsedDraft } = {}): DraftSource {
20
+ return {
21
+ slug,
22
+ file: `draft:${slug}`,
23
+ dir: join(draftsDir(root), slug),
24
+ parse: (groups) => (seen.parsed = parseDraft(raw, `draft:${slug}`, groups)),
25
+ media: (name) => media.get(name) ?? null,
26
+ article,
27
+ }
28
+ }
29
+
30
+ /** a text loaded as the desk loads a group: its draft, what the builder parsed, the lines about it */
31
+ export async function loadText(root: string, slug: string, raw: string, media: ReadonlyMap<string, Media>, article: string | null, c: TextCtx): Promise<{ draft: Draft | null; parsed: ParsedDraft | null; errors: string[]; warnings: string[] }> {
32
+ const ids = await loadIdentities({ ...(c.identitiesDir !== undefined ? { dir: c.identitiesDir } : {}), cwd: root })
33
+ const seen: { parsed?: ParsedDraft } = {}
34
+ const desk = deskOf(root, ids, [textSource(root, slug, raw, media, article, seen)], { speaksAs: c.speaksAs, unit: c.unit })
35
+ const mine = (l: string): boolean => l.startsWith(`draft:${slug}`)
36
+ return { draft: desk.drafts[0] ?? null, parsed: seen.parsed ?? null, errors: desk.errors.filter(mine), warnings: desk.warnings.filter(mine) }
37
+ }
38
+
39
+ const line = (v: string): string => v.replace(/\s*\n\s*/g, ' ').trim()
40
+
41
+ /** a group as its text form: front matter, its angle, one heading a post, the posted links */
42
+ export function groupText(g: GroupNow): string {
43
+ const meta: [string, string][] = [['title', g.event.content.title ?? ''], ['status', g.group.picked ? 'picked' : 'draft'], ...Object.entries(g.group.meta)]
44
+ if (g.group.media.length > 0) meta.push(['media', g.group.media.join(', ')])
45
+ const heads = g.posts.map(({ event, post }) => {
46
+ const o = optionsOf(post)
47
+ const list = Object.entries(o).map(([k, v]) => `${k}: ${v}`)
48
+ const word = post.key.split('/')[0]!
49
+ return `## ${word}${list.length ? ` (${list.join(', ')})` : ''}\n\n${(event.content.body ?? '').trim()}`
50
+ })
51
+ const posted = g.posts.filter((p) => p.post.state === 'posted' && p.post.url).map((p) => `- ${p.post.key}: ${p.post.url}`)
52
+ const dropped = g.posts.filter((p) => p.post.state === 'dropped').map((p) => p.post.key)
53
+ if (dropped.length > 0) meta.push(['dropped', dropped.join(', ')])
54
+ return [
55
+ `---\n${meta.map(([k, v]) => `${k}: ${line(v)}`).join('\n')}\n---`,
56
+ `## Angle\n\n${(g.event.content.body ?? '').trim()}`,
57
+ ...heads,
58
+ ...(posted.length > 0 ? [`## Posted\n\n${posted.join('\n')}`] : []),
59
+ ].join('\n\n') + '\n'
60
+ }
61
+
62
+ /** a group's text saved: words, options, facts and angle, a new heading a new post; a new topic makes a new group.
63
+ * `files` are added as its attachments by the names the text gives them. Refused while the desk's builder names a
64
+ * problem of the text (the guard, a place under the rating, a max) */
65
+ export async function saveText(root: string, ref: string, raw: string, files: readonly { file: string; name: string }[], c: TextCtx, o: { why?: string; sender?: string; now?: Date; force?: boolean } = {}): Promise<Written & { errors: string[]; threads: string[] }> {
66
+ refuseUnimported(root)
67
+ const repo = eventsRepo(storeDir(root))
68
+ const hits = groupsNow(repo).filter((g) => g.group.slug === ref || g.group.slug.replace(/^\d{8}-\d{6}-/, '') === ref)
69
+ if (hits.length > 1) throw new Error(`"${ref}" is the topic of ${hits.length} drafts: give its slug`)
70
+ const now = hits[0] ?? null
71
+ const slug = now?.group.slug ?? (DRAFT_NAME.test(ref) ? ref : idOf(o.now ?? new Date(), ref))
72
+ if (!DRAFT_NAME.test(slug)) throw new Error(`draft ${slug}?`)
73
+ const kept: Attachment[] = [...(now?.event.content.attachments ?? [])]
74
+ for (const f of files) {
75
+ const a = await keepPostFile(root, f.file, f.name)
76
+ const i = kept.findIndex((x) => x.name === a.name)
77
+ if (i >= 0) kept[i] = a
78
+ else kept.push(a)
79
+ }
80
+ const media = new Map<string, Media>()
81
+ for (const a of kept) {
82
+ const m = mediaOf(root, kept, a.name)
83
+ if (m) media.set(a.name, m)
84
+ }
85
+ const article = now?.group.article ?? null
86
+ const loaded = await loadText(root, slug, raw, media, article, c)
87
+ if (loaded.draft == null || loaded.parsed == null) throw new Error(`${slug}: ${loaded.errors.join('; ') || 'no draft'}`)
88
+ const stops = loaded.errors.filter((e) => !/media ".*" is no file of it/.test(e) || files.length > 0)
89
+ if (stops.length > 0 && !o.force) throw new Error(`${slug} is not saved: ${stops.join('; ')}`)
90
+ const sender = o.sender ?? senderOf()
91
+ const threads = now == null ? await threadsFor(root, slug, loaded.draft.title, { review: loaded.draft.review }) : []
92
+ const w = writeText(root, { draft: loaded.draft, parsed: loaded.parsed, attachments: kept, article }, { why: o.why ?? 'save', sender, attach: threads })
93
+ return { ...w, errors: loaded.errors, threads }
94
+ }
95
+
96
+ /** the text form of a group by its slug or topic */
97
+ export function showText(root: string, ref: string): string {
98
+ const g = groupNow(root, ref) ?? groupsNow(eventsRepo(storeDir(root))).find((x) => x.group.slug.replace(/^\d{8}-\d{6}-/, '') === ref) ?? null
99
+ if (g == null) throw new Error(`no draft "${ref}" in the database`)
100
+ return groupText(g)
101
+ }
102
+
103
+ export { postMediaPath }