rvlib-shipkit 2.11.0 → 2.13.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 (298) hide show
  1. package/CHANGELOG.md +56 -12
  2. package/README.md +1 -1
  3. package/package.json +4 -2
  4. package/src/agent-time/store.ts +2 -2
  5. package/src/check.ts +1 -1
  6. package/src/checks/SK001-package-json-shape.check.ts +4 -0
  7. package/src/checks/SK003-claude-md-shape.check.ts +1 -1
  8. package/src/checks/SK004-gitignore-policy.check.ts +27 -2
  9. package/src/checks/SK005-rvlib-versions.check.ts +1 -1
  10. package/src/checks/SK008-reviewer-agent.check.ts +2 -2
  11. package/src/checks/SK012-config-barrel-import.check.ts +1 -1
  12. package/src/checks/SK015-nested-repo.check.ts +1 -1
  13. package/src/checks/SK035-public-clean.check.ts +46 -0
  14. package/src/checks/SK036-draft-media-size.check.ts +28 -0
  15. package/src/cli/cmd_Backup.ts +152 -0
  16. package/src/cli/cmd_Ci.ts +8 -11
  17. package/src/cli/cmd_Drill.ts +145 -0
  18. package/src/cli/cmd_Home.ts +50 -3
  19. package/src/cli/cmd_Media.ts +96 -5
  20. package/src/cli/cmd_Review.ts +8 -2
  21. package/src/cli/cmd_Shot.ts +5 -2
  22. package/src/cli/cmd_Smoke.ts +4 -1
  23. package/src/cli/cmd_Social.ts +226 -0
  24. package/src/cli/cmd_Start.ts +1 -1
  25. package/src/cli/cmd_Time.ts +1 -1
  26. package/src/cli/cmd_Trailer.ts +9 -2
  27. package/src/cli/cmd_Veille.ts +173 -0
  28. package/src/cli/family-pages.ts +3 -0
  29. package/src/cli/registry.ts +13 -2
  30. package/src/cli.ts +5 -2
  31. package/src/collections/actions.ts +1 -49
  32. package/src/collections/checks.ts +2 -1
  33. package/src/collections/collection-types.ts +11 -2
  34. package/src/collections/providers.ts +4 -4
  35. package/src/collections/review.ts +2 -1
  36. package/src/collections/tests.ts +19 -8
  37. package/src/contracts/apply-contracts.ts +1 -3
  38. package/src/contracts/contract-manifests.ts +2 -3
  39. package/src/contracts/contract-types.ts +0 -1
  40. package/src/contracts/contracts-engine.ts +0 -3
  41. package/src/core/app-icon.ts +9 -3
  42. package/src/core/bun-builtins.ts +2 -2
  43. package/src/core/discover-checks.ts +37 -5
  44. package/src/core/fix-scope.ts +4 -2
  45. package/src/core/floor-resolve.ts +68 -48
  46. package/src/core/floor.ts +9 -0
  47. package/src/core/git-root.ts +24 -0
  48. package/src/core/last-good.ts +3 -1
  49. package/src/core/layout.ts +8 -0
  50. package/src/core/log-stamp.ts +36 -0
  51. package/src/core/loop-watch.ts +93 -0
  52. package/src/core/machine-link.ts +134 -0
  53. package/src/core/memory-watch.ts +41 -0
  54. package/src/core/one-way-in-policy.ts +27 -19
  55. package/src/core/run-ci.ts +6 -8
  56. package/src/core/run-fixers.ts +9 -9
  57. package/src/core/slots.ts +21 -0
  58. package/src/core/tree-rev.ts +60 -0
  59. package/src/core/unit-files.ts +42 -0
  60. package/src/drill/render.ts +140 -0
  61. package/src/drill/run.ts +269 -0
  62. package/src/fleet/scan-fleet.ts +6 -5
  63. package/src/home/daemon-jobs.ts +201 -0
  64. package/src/home/global-context.ts +34 -1
  65. package/src/home/home-routes.ts +22 -15
  66. package/src/home/hubs.ts +10 -3
  67. package/src/home/inbox-shape.ts +61 -6
  68. package/src/home/inbox.ts +75 -4
  69. package/src/home/lib-watch.ts +10 -3
  70. package/src/home/machine-stores.ts +15 -29
  71. package/src/home/run-daemon.ts +15 -18
  72. package/src/home/run-pm.ts +2 -0
  73. package/src/home/serve-daemon.ts +4 -3
  74. package/src/home/serve-web.ts +110 -1
  75. package/src/hooks/commit-message.ts +28 -19
  76. package/src/hooks/leak-guard.ts +10 -3
  77. package/src/hooks/run-hooks.ts +2 -6
  78. package/src/identities/identities.ts +334 -0
  79. package/src/identities/machine-route.ts +126 -0
  80. package/src/identities/machine.ts +62 -0
  81. package/src/init-repo.ts +1 -1
  82. package/src/ledger/check-stats.ts +10 -9
  83. package/src/ledger/gate-checks.ts +32 -1
  84. package/src/ledger/record-kept.ts +112 -0
  85. package/src/ledger/repo-view.ts +10 -0
  86. package/src/ledger/run-log.ts +17 -12
  87. package/src/ledger/run-timeline.ts +8 -4
  88. package/src/ledger/store.ts +7 -0
  89. package/src/ledger/suite-log.ts +17 -13
  90. package/src/media-kinds.ts +9 -1
  91. package/src/media-store/backup/daemon.ts +73 -0
  92. package/src/media-store/backup/keys.ts +25 -0
  93. package/src/media-store/backup/manifest.ts +193 -0
  94. package/src/media-store/backup/restore.ts +192 -0
  95. package/src/media-store/backup/run.ts +278 -0
  96. package/src/media-store/backup/secret.ts +86 -0
  97. package/src/media-store/backup/snapshot.ts +64 -0
  98. package/src/media-store/backup/sources.ts +199 -0
  99. package/src/media-store/content.ts +11 -1
  100. package/src/media-store/daemon.ts +56 -70
  101. package/src/media-store/hand.ts +58 -0
  102. package/src/media-store/put.ts +122 -0
  103. package/src/media-store/space.ts +73 -11
  104. package/src/pages/forward.ts +35 -0
  105. package/src/pages/frame-client.ts +118 -0
  106. package/src/pages/routes.ts +29 -0
  107. package/src/pages/unit.ts +92 -0
  108. package/src/plan/planner.ts +12 -0
  109. package/src/plan/repo-source.ts +19 -5
  110. package/src/reflect/transcript.ts +35 -10
  111. package/src/release/public-clean.ts +301 -0
  112. package/src/release/published-here.ts +22 -0
  113. package/src/release/run-bump.ts +2 -1
  114. package/src/release/run-release.ts +4 -1
  115. package/src/repo-config.ts +53 -2
  116. package/src/review/http.ts +16 -2
  117. package/src/review/media-kind.ts +3 -3
  118. package/src/review/media-read.ts +3 -3
  119. package/src/review/model.ts +24 -5
  120. package/src/review/notes.ts +77 -0
  121. package/src/review/project.ts +6 -38
  122. package/src/review/routes.ts +8 -13
  123. package/src/review/store.ts +46 -4
  124. package/src/review/trailer-media.ts +24 -3
  125. package/src/review/trailer-shots.ts +106 -0
  126. package/src/review/unit.ts +1 -1
  127. package/src/scaffold/files/agent-handoff.md +3 -0
  128. package/src/scaffold/files/agent-index.md +4 -12
  129. package/src/scaffold/project-scaffold.ts +5 -4
  130. package/src/serve/embed.ts +1 -1
  131. package/src/serve/hub-app/col-card.tsx +3 -17
  132. package/src/serve/hub-app/col-tables-view.tsx +2 -1
  133. package/src/serve/hub-app/cols-svc.ts +12 -14
  134. package/src/serve/hub-app/dock-st.ts +4 -2
  135. package/src/serve/hub-app/dock-view.tsx +2 -0
  136. package/src/serve/hub-app/frames-st.ts +35 -0
  137. package/src/serve/hub-app/hash-route.ts +64 -1
  138. package/src/serve/hub-app/home-st.ts +31 -7
  139. package/src/serve/hub-app/home-strip.css +9 -1
  140. package/src/serve/hub-app/home-strip.tsx +7 -6
  141. package/src/serve/hub-app/home.html +5 -0
  142. package/src/serve/hub-app/hub-app.tsx +49 -5
  143. package/src/serve/hub-app/hub.css +29 -11
  144. package/src/serve/hub-app/icons.tsx +16 -1
  145. package/src/serve/hub-app/identities-st.ts +210 -0
  146. package/src/serve/hub-app/identities-view.tsx +352 -0
  147. package/src/serve/hub-app/identities.css +48 -0
  148. package/src/serve/hub-app/identity-address.ts +52 -0
  149. package/src/serve/hub-app/inbox-st.ts +59 -6
  150. package/src/serve/hub-app/inbox-view.tsx +48 -6
  151. package/src/serve/hub-app/inbox.css +12 -1
  152. package/src/serve/hub-app/index.html +3 -0
  153. package/src/serve/hub-app/keys.ts +10 -2
  154. package/src/serve/hub-app/list-walk.ts +89 -0
  155. package/src/serve/hub-app/machine-st.ts +12 -0
  156. package/src/serve/hub-app/media-view.tsx +2 -1
  157. package/src/serve/hub-app/pages-frames.tsx +134 -0
  158. package/src/serve/hub-app/pages-svc.ts +111 -0
  159. package/src/serve/hub-app/palette-st.ts +18 -3
  160. package/src/serve/hub-app/palette-view.tsx +9 -2
  161. package/src/serve/hub-app/planned-view.tsx +2 -1
  162. package/src/serve/hub-app/project-list.css +18 -14
  163. package/src/serve/hub-app/project-list.tsx +88 -49
  164. package/src/serve/hub-app/projects-svc.ts +33 -3
  165. package/src/serve/hub-app/repo-sections.ts +19 -2
  166. package/src/serve/hub-app/repo-st.ts +75 -19
  167. package/src/serve/hub-app/review/review-cells.tsx +3 -3
  168. package/src/serve/hub-app/review/review-kit.ts +30 -7
  169. package/src/serve/hub-app/review/review-page.tsx +1 -1
  170. package/src/serve/hub-app/review/review-st.ts +33 -11
  171. package/src/serve/hub-app/review/review-thread.tsx +11 -9
  172. package/src/serve/hub-app/review/review-views.tsx +84 -19
  173. package/src/serve/hub-app/review/thread-st.ts +1 -10
  174. package/src/serve/hub-app/review/trailer-page.tsx +2 -1
  175. package/src/serve/hub-app/review.css +17 -8
  176. package/src/serve/hub-app/site/site-part.tsx +173 -0
  177. package/src/serve/hub-app/site/site-st.ts +157 -0
  178. package/src/serve/hub-app/site.css +35 -0
  179. package/src/serve/hub-app/social/calendar.tsx +182 -0
  180. package/src/serve/hub-app/social/comms-page.tsx +306 -0
  181. package/src/serve/hub-app/social/kit.tsx +244 -0
  182. package/src/serve/hub-app/social/post-card.tsx +456 -0
  183. package/src/serve/hub-app/social/problems.tsx +60 -0
  184. package/src/serve/hub-app/social/social-model.ts +154 -0
  185. package/src/serve/hub-app/social/social-page.tsx +674 -0
  186. package/src/serve/hub-app/social/social-st.ts +986 -0
  187. package/src/serve/hub-app/social.css +289 -0
  188. package/src/serve/hub-app/stores/stores-page.tsx +311 -0
  189. package/src/serve/hub-app/stores/stores-st.ts +286 -0
  190. package/src/serve/hub-app/stores.css +54 -0
  191. package/src/serve/hub-app/test-view.tsx +9 -2
  192. package/src/serve/hub-app/tests-svc.ts +16 -1
  193. package/src/serve/hub-app/timeline-geometry.ts +1 -1
  194. package/src/serve/hub-app/timeline-view.tsx +3 -2
  195. package/src/serve/hub-app/tree-build.ts +6 -0
  196. package/src/serve/hub-app/tree-row.tsx +27 -4
  197. package/src/serve/hub-app/tree-svc.ts +18 -49
  198. package/src/serve/hub-app/veille/veille-page.tsx +514 -0
  199. package/src/serve/hub-app/veille/veille-st.ts +443 -0
  200. package/src/serve/hub-app/veille.css +84 -0
  201. package/src/serve/hub-runtime.ts +14 -9
  202. package/src/serve/project-gutter-route.ts +44 -12
  203. package/src/serve/resources-wire.ts +48 -0
  204. package/src/serve/run-lanes.ts +7 -4
  205. package/src/serve/same-origin.ts +1 -1
  206. package/src/serve/serve-hub.ts +27 -18
  207. package/src/serve/tracked-watch.ts +24 -3
  208. package/src/serve/warm-cell.ts +5 -1
  209. package/src/shipkit-files.ts +15 -4
  210. package/src/shipkit.ts +0 -1
  211. package/src/shot/box.ts +162 -0
  212. package/src/shot/browser-slot.ts +62 -0
  213. package/src/shot/client.ts +43 -7
  214. package/src/shot/clip-encoder.ts +93 -12
  215. package/src/shot/film-box.ts +188 -0
  216. package/src/shot/shooter.ts +50 -15
  217. package/src/shot/shot-ask.ts +10 -2
  218. package/src/shot/stepped-clip.ts +5 -4
  219. package/src/site/desk.ts +242 -0
  220. package/src/site/routes.ts +66 -0
  221. package/src/site/unit.ts +62 -0
  222. package/src/social/brands.ts +22 -0
  223. package/src/social/compose.ts +97 -0
  224. package/src/social/desk-index.ts +123 -0
  225. package/src/social/desk-wire.ts +64 -0
  226. package/src/social/drafts.ts +183 -0
  227. package/src/social/house.ts +24 -0
  228. package/src/social/load.ts +319 -0
  229. package/src/social/md.ts +70 -0
  230. package/src/social/media-facts.ts +53 -0
  231. package/src/social/media-kind.ts +189 -0
  232. package/src/social/media-limit.ts +42 -0
  233. package/src/social/media-of.ts +30 -0
  234. package/src/social/migrate.ts +123 -0
  235. package/src/social/open.ts +17 -0
  236. package/src/social/post-url.ts +158 -0
  237. package/src/social/presence.ts +332 -0
  238. package/src/social/public-read.ts +53 -0
  239. package/src/social/publish/bluesky.ts +168 -0
  240. package/src/social/publish/discord.ts +76 -0
  241. package/src/social/publish/index.ts +24 -0
  242. package/src/social/publish/secret.ts +13 -0
  243. package/src/social/push.ts +31 -0
  244. package/src/social/richtext.ts +37 -0
  245. package/src/social/routes.ts +180 -0
  246. package/src/social/stats.ts +134 -0
  247. package/src/social/text.ts +267 -0
  248. package/src/social/tracker-route.ts +39 -0
  249. package/src/social/tracker.ts +255 -0
  250. package/src/social/unit.ts +53 -0
  251. package/src/social/writes.ts +130 -0
  252. package/src/start-repo.ts +14 -9
  253. package/src/stores/collection.ts +27 -0
  254. package/src/stores/desk.ts +336 -0
  255. package/src/stores/model.ts +187 -0
  256. package/src/stores/routes.ts +126 -0
  257. package/src/stores/unit.ts +57 -0
  258. package/src/suite/calibrate.ts +127 -0
  259. package/src/suite/core-counters.ts +91 -0
  260. package/src/suite/judge-suites.ts +94 -34
  261. package/src/suite/suite-cli.ts +44 -10
  262. package/src/suite/suite-cpu-preload.ts +34 -9
  263. package/src/trailer/adapter.ts +4 -0
  264. package/src/trailer/build.ts +42 -11
  265. package/src/trailer/ffmpeg.ts +11 -0
  266. package/src/trailer/footage.ts +30 -13
  267. package/src/trailer/grammar.ts +18 -2
  268. package/src/trailer/graph.ts +28 -6
  269. package/src/trailer/passage.ts +21 -6
  270. package/src/trailer/plan.ts +74 -3
  271. package/src/trailer/shelf.ts +16 -0
  272. package/src/trailer/stitch.ts +67 -26
  273. package/src/trailer/url.ts +1 -1
  274. package/src/trailer/versions.ts +24 -0
  275. package/src/ts/gate-typecheck.ts +32 -0
  276. package/src/ts/typecheck-cli.ts +9 -11
  277. package/src/tui/tui-app.tsx +0 -1
  278. package/src/veille/asks.ts +155 -0
  279. package/src/veille/auto.ts +31 -0
  280. package/src/veille/batch.ts +27 -0
  281. package/src/veille/chrome.ts +127 -0
  282. package/src/veille/collection.ts +28 -0
  283. package/src/veille/desk.ts +242 -0
  284. package/src/veille/identity.ts +80 -0
  285. package/src/veille/import.ts +68 -0
  286. package/src/veille/log.ts +183 -0
  287. package/src/veille/platforms.ts +118 -0
  288. package/src/veille/reads.ts +66 -0
  289. package/src/veille/replied.ts +110 -0
  290. package/src/veille/routes.ts +185 -0
  291. package/src/veille/service.ts +81 -0
  292. package/src/veille/watch.ts +116 -0
  293. package/src/veille/worth.ts +46 -0
  294. package/src/wiki/scan-md.ts +18 -0
  295. package/src/collections/posts.ts +0 -142
  296. package/src/contracts/manifests/social.contract.ts +0 -20
  297. package/src/scaffold/files/agent-coding.md +0 -35
  298. package/src/ts/typecheck-cache.ts +0 -11
@@ -0,0 +1,97 @@
1
+ // a message's text on each platform (wiki build/shipkit/social.md, The tags): a filled link, the tweet's weighted
2
+ // length, a message's length and text on each account. Pure, no fs: the desk's editor counts with it too
3
+ import { richText } from './richtext.ts'
4
+
5
+ const URL_RE = /https?:\/\/\S+/g
6
+ const EMOJI = /\p{Extended_Pictographic}/u
7
+ const light = (cp: number): boolean => cp <= 4351 || (cp >= 8192 && cp <= 8205) || (cp >= 8208 && cp <= 8223) || (cp >= 8242 && cp <= 8247)
8
+
9
+ /** the length X counts: a URL is 23, an emoji 2, a CJK character 2, the rest 1 */
10
+ export function tweetLength(text: string): number {
11
+ let n = 0
12
+ const rest = text.normalize('NFC').replace(URL_RE, () => {
13
+ n += 23
14
+ return ''
15
+ })
16
+ for (const { segment } of new Intl.Segmenter().segment(rest)) {
17
+ if (EMOJI.test(segment)) n += 2
18
+ else for (const ch of segment) n += light(ch.codePointAt(0)!) ? 1 : 2
19
+ }
20
+ return n
21
+ }
22
+
23
+ /** a venue link filled; a link that is only `{url}` is the post's own address, never encoded */
24
+ export function fillLink(template: string, v: { url: string; title: string; text: string }): string {
25
+ if (template === '{url}') return v.url
26
+ return template.replace(/\{(url|title|text)\}/g, (_, k: 'url' | 'title' | 'text') => encodeURIComponent(v[k]))
27
+ }
28
+
29
+ /** the length a platform counts: X weighted, Bluesky its shown text in graphemes, the rest graphemes */
30
+ export function messageLength(platform: string, text: string): number {
31
+ if (platform === 'x') return tweetLength(text)
32
+ const shown = platform === 'bluesky' ? richText(text).text : text
33
+ return [...new Intl.Segmenter().segment(shown)].length
34
+ }
35
+
36
+ /** a hashtag as a message's `tags` holds it */
37
+ export const TAG = /^#[\p{L}\p{N}_]+$/u
38
+ /** the Saturday tag, joined where it fits */
39
+ const SATURDAY = '#ScreenshotSaturday'
40
+ /** what each platform takes of a message's tags (wiki build/shipkit/social.md, The tags); an account with no rule takes none */
41
+ const TAGS: Readonly<Record<string, 'all' | 'one' | 'vertical'>> = { x: 'all', bluesky: 'all', mastodon: 'all', threads: 'one', tiktok: 'vertical', instagram: 'vertical', youtube: 'vertical' }
42
+
43
+ /** a message as one platform posts it: its text with the tags that platform takes (within its `max`), the footer of a
44
+ * vertical; X's links go to `reply`, the first reply under the post */
45
+ export function compose(
46
+ platform: string,
47
+ m: { text: string; tags: readonly string[]; footer: string },
48
+ o: { max: number | null; saturday: boolean },
49
+ ): { text: string; reply: string } {
50
+ let text = m.text.trim()
51
+ let reply = ''
52
+ if (platform === 'x') {
53
+ const links = text.match(URL_RE) ?? []
54
+ if (links.length > 0) {
55
+ reply = links.join('\n')
56
+ text = text
57
+ .replace(URL_RE, '')
58
+ .split('\n')
59
+ .map((l) => l.replace(/[ \t]{2,}/g, ' ').replace(/[ \t]+([.,;:!?])/g, '$1').trimEnd())
60
+ .join('\n')
61
+ .replace(/\n{3,}/g, '\n\n')
62
+ .trim()
63
+ }
64
+ }
65
+ const rule = TAGS[platform]
66
+ let tags = rule == null ? [] : rule === 'one' ? m.tags.slice(0, 1) : [...m.tags]
67
+ if (o.saturday && rule === 'all' && !tags.some((t) => t.toLowerCase() === SATURDAY.toLowerCase())) tags.push(SATURDAY)
68
+ const join = (t: readonly string[]): string => [text, t.join(' ')].filter(Boolean).join('\n\n')
69
+ const footer = rule === 'vertical' && m.footer !== '' ? `\n\n${m.footer}` : ''
70
+ // a tag that would pass the max goes, the last first: the Saturday one before the message's own
71
+ while (tags.length > 0 && o.max !== null && messageLength(platform, join(tags) + footer) > o.max) tags = tags.slice(0, -1)
72
+ return { text: join(tags) + footer, reply }
73
+ }
74
+
75
+ /** a text's tags written in it, the trailing lines made only of #tags: what a draft held before its tags had a field */
76
+ export function trailingTags(text: string): { text: string; tags: string[] } {
77
+ const lines = text.trimEnd().split('\n')
78
+ const tags: string[] = []
79
+ while (lines.length > 0 && /^\s*#[\p{L}\p{N}_]+(?:\s+#[\p{L}\p{N}_]+)*\s*$/u.test(lines.at(-1)!)) tags.unshift(...lines.pop()!.trim().split(/\s+/))
80
+ return { text: lines.join('\n').trim(), tags }
81
+ }
82
+
83
+ /** a text with every `#tag` dropped (a web page, a Patreon post: tags find nobody there), and each line they leave
84
+ * empty with them; a `#` inside a word or a URL stays */
85
+ export function withoutTags(text: string): string {
86
+ return text
87
+ .split('\n')
88
+ .map((l) => {
89
+ const kept = l.replace(/(^|[ \t])#[\p{L}\p{N}_]+/gu, '$1').replace(/[ \t]{2,}/g, ' ')
90
+ return kept.trim() === '' && l.trim() !== '' ? null : kept.trimEnd()
91
+ })
92
+ .filter((l) => l != null)
93
+ .join('\n')
94
+ .replace(/\n{3,}/g, '\n\n')
95
+ .trim()
96
+ }
97
+
@@ -0,0 +1,123 @@
1
+ // the desk.json answer kept while nothing it is built from moved (wiki build/shipkit/social.md, Routes). A stamp of
2
+ // stats says it: the social folder, the identities, the repo's config and social unit, the media a draft names outside
3
+ // its folder, and the day; HEAD moves the calendar alone. The desk is built, put on the wire and zipped once a stamp,
4
+ // and a page that holds the answer gets a 304. A stamp misses a media named outside the folder that appears where none
5
+ // stood: its error line clears at the next change
6
+ import { type Dirent, readdirSync, statSync } from 'node:fs'
7
+ import { join, relative } from 'node:path'
8
+ import { LAYOUT } from '../core/layout.ts'
9
+ import { headCommit } from '../core/git-root.ts'
10
+ import { unitFilesDeclaring } from '../core/unit-files.ts'
11
+ import { identitiesDir, readIdentities, type Identities } from '../identities/identities.ts'
12
+ import { loadRepoConfig } from '../repo-config.ts'
13
+ import { tagged } from '../review/http.ts'
14
+ import { wireOf } from './desk-wire.ts'
15
+ import { loadDesk, type Desk } from './load.ts'
16
+ import { commitMoments, dayOf, postedOf, timelineOf } from './presence.ts'
17
+ import { pushLog } from './push.ts'
18
+ import { STATS_PLATFORMS } from './stats.ts'
19
+ import { loadSocialUnit, type SocialUnit } from './unit.ts'
20
+
21
+ /** the calendar's model of every identity speaking in the repo: posts dated, slots, topics, the week ahead */
22
+ function timelines(desk: Desk, today: string): Record<string, ReturnType<typeof timelineOf>> {
23
+ const out: Record<string, ReturnType<typeof timelineOf>> = {}
24
+ for (const id of new Set([desk.speaksAs, ...desk.drafts.map((d) => d.identity)].filter((x): x is string => x != null))) {
25
+ const accounts = desk.identities.find((i) => i.id === id)?.accounts ?? []
26
+ const social = { ...desk, accounts, drafts: desk.drafts.filter((d) => d.identity === id) }
27
+ out[id] = timelineOf(social, postedOf(social, commitMoments(social, desk.root)), today)
28
+ }
29
+ return out
30
+ }
31
+
32
+ /** a folder's entries as last listed, kept on its time: a name that comes or goes moves the folder's time */
33
+ const listed = new Map<string, { at: number; entries: { name: string; dir: boolean; md: boolean }[] }>()
34
+
35
+ /** what the desk reads under `dir`, into `out`: every name, the time and size of each text file (`.md`) and each folder.
36
+ * A media's bytes are never read, so a media is its name alone, and a folder whose time stands is not listed again */
37
+ function tree(dir: string, out: string[]): void {
38
+ const at = statSync(dir, { throwIfNoEntry: false })
39
+ if (at == null || !at.isDirectory()) {
40
+ out.push(`${dir}:-`)
41
+ return
42
+ }
43
+ out.push(`${dir}:${at.mtimeMs}`)
44
+ let l = listed.get(dir)
45
+ if (l?.at !== at.mtimeMs) {
46
+ let entries: Dirent[]
47
+ try {
48
+ entries = readdirSync(dir, { withFileTypes: true })
49
+ } catch {
50
+ return
51
+ }
52
+ // a link is followed: it may stand for a folder
53
+ l = { at: at.mtimeMs, entries: entries.map((e) => ({ name: e.name, dir: e.isDirectory() || (e.isSymbolicLink() && (statSync(join(dir, e.name), { throwIfNoEntry: false })?.isDirectory() ?? false)), md: e.name.endsWith('.md') })) }
54
+ listed.set(dir, l)
55
+ }
56
+ for (const e of l.entries) {
57
+ const abs = join(dir, e.name)
58
+ if (e.dir) tree(abs, out)
59
+ else out.push(e.md ? stat(abs) : abs)
60
+ }
61
+ }
62
+
63
+ const stat = (abs: string): string => {
64
+ const s = statSync(abs, { throwIfNoEntry: false })
65
+ return s == null ? `${abs}:-` : `${abs}:${s.mtimeMs}:${s.size}`
66
+ }
67
+ const stampOf = (parts: string[]): string => Bun.hash(parts.join('\n')).toString(36)
68
+
69
+ type Part<T> = { stamp: string; value: T }
70
+ type Held = {
71
+ idsDir?: string | null
72
+ config?: Part<string | undefined>
73
+ ids?: Part<Identities>
74
+ unit?: Part<SocialUnit | null>
75
+ desk?: Part<Desk> & { outside: string[] }
76
+ answer?: { stamp: string; tag: string; text: string; zip?: Uint8Array<ArrayBuffer> }
77
+ }
78
+ const held = new Map<string, Held>()
79
+
80
+ /** the answer of `root` as it stands: rebuilt only for the parts whose stamp moved */
81
+ export async function deskWire(root: string): Promise<{ stamp: string; tag: string; text: string; zip?: Uint8Array<ArrayBuffer> }> {
82
+ const h = held.get(root) ?? {}
83
+ held.set(root, h)
84
+ if (h.idsDir === undefined) h.idsDir = await identitiesDir(root)
85
+
86
+ const configStamp = stat(join(root, 'repo.config.ts'))
87
+ const config = h.config?.stamp === configStamp ? h.config : (h.config = { stamp: configStamp, value: (await loadRepoConfig(root, { fresh: true }).catch(() => null))?.speaksAs })
88
+
89
+ const idsParts: string[] = []
90
+ if (h.idsDir != null) tree(h.idsDir, idsParts)
91
+ const idsStamp = stampOf(idsParts)
92
+ const ids = h.ids?.stamp === idsStamp ? h.ids : (h.ids = { stamp: idsStamp, value: readIdentities(h.idsDir) })
93
+
94
+ const unitStamp = stampOf(unitFilesDeclaring(root, 'social').map(stat))
95
+ const unit = h.unit?.stamp === unitStamp ? h.unit : (h.unit = { stamp: unitStamp, value: await loadSocialUnit(root) })
96
+
97
+ const today = dayOf(Date.now())
98
+ const social = join(root, LAYOUT.social)
99
+ const folder: string[] = [today, configStamp, idsStamp, unitStamp]
100
+ tree(social, folder)
101
+ folder.push(stat(pushLog(root)))
102
+ for (const p of h.desk?.outside ?? []) folder.push(stat(p))
103
+ const deskStamp = stampOf(folder)
104
+ let desk = h.desk
105
+ if (desk?.stamp !== deskStamp) {
106
+ const value = loadDesk(root, ids.value, { speaksAs: config.value, unit: unit.value })
107
+ const outside = [...new Set(value.drafts.flatMap((d) => d.media.map((m) => m.path)).filter((p) => relative(social, p).startsWith('..')))]
108
+ desk = h.desk = { stamp: deskStamp, value, outside }
109
+ }
110
+
111
+ const stamp = `${deskStamp}.${headCommit(root) ?? 'no head'}`
112
+ if (h.answer?.stamp === stamp) return h.answer
113
+ const d = desk.value
114
+ const text = JSON.stringify(wireOf({ ...d, timelines: timelines(d, today), statsPlatforms: STATS_PLATFORMS, article: unit.value?.preview != null }))
115
+ h.answer = { stamp, tag: `"${Bun.hash(text).toString(36)}"`, text }
116
+ return h.answer
117
+ }
118
+
119
+ /** `GET api/social/desk.json`: 304 while the page holds the answer, gzipped when it takes it */
120
+ export async function deskAnswer(req: Request, root: string): Promise<Response> {
121
+ const a = await deskWire(root)
122
+ return tagged(req, a.tag, () => a.text, a)
123
+ }
@@ -0,0 +1,64 @@
1
+ // the desk on the wire (wiki build/shipkit/social.md, Routes): a message leaves out what its draft and its account
2
+ // already say (the draft's fields, its media by index, the write link its account fills), and an account's messages
3
+ // are not sent twice, they are its drafts' messages again. `deskOfWire` gives back the very desk `wireOf` was given
4
+ // (tests/social-desk.test.ts pins it). Pure, so the hub page imports it
5
+ import { fillLink } from './compose.ts'
6
+ import type { Desk, DeskAccount, DeskIdentity, Draft, Media, SocialPost } from './load.ts'
7
+
8
+ /** the fields every message of a draft shares with it */
9
+ const FROM_DRAFT = ['slug', 'identity', 'file', 'status', 'kind', 'angle', 'alt'] as const
10
+ type FromDraft = (typeof FROM_DRAFT)[number]
11
+
12
+ /** `media` a number: the index of the draft's media it is; `href` absent: the one its account's write page gives */
13
+ export type WirePost = Omit<SocialPost, FromDraft | 'media' | 'href'> & Partial<Pick<SocialPost, FromDraft | 'href'>> & { media: Media | number | null }
14
+ export type WireDraft = Omit<Draft, 'posts'> & { posts: WirePost[] }
15
+ export type WireAccount = Omit<DeskAccount, 'posts'>
16
+ export type WireIdentity = Omit<DeskIdentity, 'accounts'> & { accounts: WireAccount[] }
17
+ export type Wire<T extends Desk> = Omit<T, 'drafts' | 'identities'> & { drafts: WireDraft[]; identities: WireIdentity[] }
18
+
19
+ type Accounts = ReadonlyMap<string, Pick<DeskAccount, 'write' | 'places'>>
20
+
21
+ const accountsOf = (identities: readonly { id: string; accounts: readonly (Pick<DeskAccount, 'id' | 'write' | 'places'>)[] }[]): Map<string, Pick<DeskAccount, 'write' | 'places'>> =>
22
+ new Map(identities.flatMap((i) => i.accounts.map((a) => [`${i.id}/${a.id}`, a] as const)))
23
+
24
+ /** the write link a message gets from its account and place, as the load fills it */
25
+ function writeLink(p: Pick<SocialPost, 'place' | 'title' | 'text'>, a: Pick<DeskAccount, 'write' | 'places'> | undefined): string | null {
26
+ const write = a?.places.find((x) => x.id === p.place)?.write || a?.write || ''
27
+ return write === '' ? null : fillLink(write, { url: '', title: p.title, text: p.text })
28
+ }
29
+
30
+ function lean(p: SocialPost, d: Draft, accounts: Accounts): WirePost {
31
+ const out: Omit<Partial<SocialPost>, 'media'> & { media?: Media | number | null } = { ...p }
32
+ for (const k of FROM_DRAFT) if (p[k] === d[k]) delete out[k]
33
+ const at = p.media == null ? -1 : d.media.findIndex((m) => m.name === p.media!.name && m.path === p.media!.path)
34
+ if (at >= 0) out.media = at
35
+ if (p.href === writeLink(p, accounts.get(`${p.identity}/${p.platform}`))) delete out.href
36
+ return out as WirePost
37
+ }
38
+
39
+ export function wireOf<T extends Desk>(desk: T): Wire<T> {
40
+ const accounts = accountsOf(desk.identities)
41
+ return {
42
+ ...desk,
43
+ identities: desk.identities.map((i) => ({ ...i, accounts: i.accounts.map(({ posts: _, ...a }) => a) })),
44
+ drafts: desk.drafts.map((d) => ({ ...d, posts: d.posts.map((p) => lean(p, d, accounts)) })),
45
+ }
46
+ }
47
+
48
+ export function deskOfWire<T extends Desk>(w: Wire<T>): T {
49
+ const writes = accountsOf(w.identities)
50
+ const drafts: Draft[] = w.drafts.map((d) => {
51
+ const full: Draft = { ...d, posts: [] }
52
+ full.posts = d.posts.map(({ media, ...p }) => {
53
+ const post = { slug: d.slug, identity: d.identity, file: d.file, status: d.status, kind: d.kind, angle: d.angle, alt: d.alt, ...p, media: typeof media === 'number' ? (d.media[media] ?? null) : media } as SocialPost
54
+ if (!('href' in p)) post.href = writeLink(post, writes.get(`${post.identity}/${post.platform}`))
55
+ return post
56
+ })
57
+ return full
58
+ })
59
+ const identities: DeskIdentity[] = w.identities.map((i) => ({ ...i, accounts: i.accounts.map((a) => ({ ...a, posts: [] })) }))
60
+ const accounts = new Map(identities.flatMap((i) => i.accounts.map((a) => [`${i.id}/${a.id}`, a] as const)))
61
+ // the drafts newest first, each one's messages in its order: the order the load gave every account
62
+ for (const d of drafts) for (const p of d.posts) accounts.get(`${p.identity}/${p.platform}`)?.posts.push(p)
63
+ return { ...w, identities, drafts } as unknown as T
64
+ }
@@ -0,0 +1,183 @@
1
+ // one draft, one message for every platform (wiki build/shipkit/social.md, contract v3): `drafts/<slug>/draft.md` read into its
2
+ // sections and its posted links, the one write (a platform's line of `## Posted`), and where a media name points
3
+ import { existsSync } from 'node:fs'
4
+ import { homedir } from 'node:os'
5
+ import { isAbsolute, join } from 'node:path'
6
+ import { TAG } from './compose.ts'
7
+ import { parseFrontmatter } from './md.ts'
8
+
9
+ /** the headings a draft holds besides its platforms */
10
+ const OWN = ['Angle', 'Posted'] as const
11
+ const OPTIONS = ['name', 'place', 'title', 'media', 'pin', 'outro', 'mark', 'tags'] as const
12
+ type Option = (typeof OPTIONS)[number]
13
+ /** the options whose value is one of a few words: a vertical's end and its watermark's corner, words a project reads */
14
+ const WORDS: Partial<Record<Option, readonly string[]>> = { outro: ['montage', 'short', 'none'], mark: ['left', 'right'] }
15
+
16
+ const HEADING = /^## (.+?)[ \t]*$/gm
17
+ const PLATFORM = /^([a-z0-9-]+)(?:\s*\((.*)\))?$/
18
+ const POSTED_LINE = /^- ([a-z0-9-]+(?:\/[a-z0-9-]+)?): (\S+)$/
19
+
20
+ /** `key` is the platform, or `<platform>/<name>` when the platform holds several messages */
21
+ type DraftSection = { platform: string; key: string; options: Partial<Record<Option, string>>; text: string }
22
+
23
+ type ParsedDraft = {
24
+ meta: Record<string, string>
25
+ angle: string
26
+ sections: DraftSection[]
27
+ /** a section's key → the URL he pasted */
28
+ posted: Map<string, string>
29
+ errors: string[]
30
+ }
31
+
32
+ /** a comma list, `a.png, b.mp4`; `none` is the empty list */
33
+ export const fileList = (v: string | undefined): string[] =>
34
+ v == null || v.trim() === 'none'
35
+ ? []
36
+ : v
37
+ .split(',')
38
+ .map((x) => x.trim())
39
+ .filter(Boolean)
40
+
41
+ /** a topic is a word the project's unit names (its `topics`); with none, any word */
42
+ export type Topic = string
43
+
44
+ /** a draft's `topics`, `world, towns`, as a list; a word off the unit's list is an error at its file */
45
+ export function topicList(v: string | undefined, file: string, errors: string[], topics: readonly string[] | null): Topic[] {
46
+ const out: Topic[] = []
47
+ for (const t of fileList(v)) {
48
+ if (topics == null || topics.includes(t)) out.push(t)
49
+ else errors.push(`${file}: topic "${t}" is not one of ${topics.join(', ')}`)
50
+ }
51
+ return out
52
+ }
53
+
54
+ /** a heading's `tags`, `#a #b`, as a list */
55
+ export const tagList = (v: string | undefined): string[] => (v ?? '').split(/\s+/).filter(Boolean)
56
+
57
+ /** `place: public, title: Hello, world` → its keys; a comma splits only before a known key */
58
+ function options(raw: string, where: string, errors: string[]): Partial<Record<Option, string>> {
59
+ const out: Partial<Record<Option, string>> = {}
60
+ for (const part of raw.split(new RegExp(`,\\s*(?=(?:${OPTIONS.join('|')}):)`))) {
61
+ const i = part.indexOf(':')
62
+ const key = part.slice(0, i).trim()
63
+ if (i === -1 || !(OPTIONS as readonly string[]).includes(key)) {
64
+ errors.push(`${where}: "${part.trim()}" is not one of ${OPTIONS.map((o) => `${o}: …`).join(', ')}`)
65
+ continue
66
+ }
67
+ const value = part.slice(i + 1).trim()
68
+ const words = WORDS[key as Option]
69
+ if (words != null && !words.includes(value)) errors.push(`${where}: ${key} "${value}" is not ${words.length > 1 ? `${words.slice(0, -1).join(', ')} or ${words.at(-1)}` : words[0]}`)
70
+ if (key === 'tags') for (const t of tagList(value)) if (!TAG.test(t)) errors.push(`${where}: tag "${t}" is not #word`)
71
+ out[key as Option] = value
72
+ }
73
+ return out
74
+ }
75
+
76
+ /** `groups`: a group's word to its accounts (wiki build/shipkit/social.md, The accounts): a heading named for it goes to each, so their
77
+ * posted lines need no heading of their own */
78
+ export function parseDraft(raw: string, file: string, groups: ReadonlyMap<string, readonly string[]> = new Map()): ParsedDraft {
79
+ const { meta, body } = parseFrontmatter(raw)
80
+ const errors: string[] = []
81
+ const heads = [...body.matchAll(HEADING)]
82
+ const text = (k: number): string => body.slice(heads[k]!.index + heads[k]![0].length, heads[k + 1]?.index ?? body.length).trim()
83
+ const d: ParsedDraft = { meta, angle: '', sections: [], posted: new Map(), errors }
84
+ heads.forEach((h, k) => {
85
+ const name = h[1]!
86
+ if (name === 'Angle') d.angle = text(k)
87
+ else if (name === 'Posted')
88
+ for (const line of text(k).split('\n')) {
89
+ if (line.trim() === '') continue
90
+ const m = POSTED_LINE.exec(line.trim())
91
+ if (m == null) errors.push(`${file}: "${line}" under ## Posted is not "- <platform>[/<name>]: <url>"`)
92
+ else d.posted.set(m[1]!, m[2]!)
93
+ }
94
+ else {
95
+ const m = PLATFORM.exec(name)
96
+ if (m == null) {
97
+ errors.push(`${file}: "## ${name}" is neither ${OWN.join(', ')} nor a platform, "## <id> (<options>)"`)
98
+ return
99
+ }
100
+ const opts = m[2] == null ? {} : options(m[2], `${file} ## ${m[1]}`, errors)
101
+ if (groups.has(m[1]!) && opts.place != null) errors.push(`${file}: ## ${m[1]} is a group: each account's own place holds, never place: …`)
102
+ const key = opts.name == null ? m[1]! : `${m[1]}/${opts.name}`
103
+ if (opts.name != null && !/^[a-z0-9-]+$/.test(opts.name)) errors.push(`${file}: ## ${m[1]} name "${opts.name}" is not kebab case`)
104
+ if (d.sections.some((s) => s.key === key)) errors.push(`${file}: ## ${key} twice (a repeated platform takes name: …)`)
105
+ d.sections.push({ platform: m[1]!, key, options: opts, text: text(k) })
106
+ }
107
+ })
108
+ for (const p of d.posted.keys()) if (!d.sections.some((s) => s.key === p || groupKeys(s, groups).includes(p))) errors.push(`${file}: posted on ${p}, but no ## ${p}`)
109
+ return d
110
+ }
111
+
112
+ /** the keys of a group heading's message on each account of the group, `<account>[/<name>]` each; none for an account's
113
+ * own heading */
114
+ export function groupKeys(s: DraftSection, groups: ReadonlyMap<string, readonly string[]>): string[] {
115
+ return (groups.get(s.platform) ?? []).map((a) => (s.options.name == null ? a : `${a}/${s.options.name}`))
116
+ }
117
+
118
+ /** every media name a draft gives, its own then its platforms', each once */
119
+ export function mediaNames(d: ParsedDraft): string[] {
120
+ const out = fileList(d.meta.media)
121
+ for (const s of d.sections) for (const m of fileList(s.options.media)) if (!out.includes(m)) out.push(m)
122
+ return out
123
+ }
124
+
125
+ /** where a media name points: `/…` or `~/…` anywhere on the disk, else the draft's folder, else the repo's root; null
126
+ * when none holds it */
127
+ export function resolveMedia(name: string, dir: string, repo: string): string | null {
128
+ if (name.startsWith('~/')) return existsSync(join(homedir(), name.slice(2))) ? join(homedir(), name.slice(2)) : null
129
+ if (isAbsolute(name)) return existsSync(name) ? name : null
130
+ for (const base of [dir, repo]) if (existsSync(join(base, name))) return join(base, name)
131
+ return null
132
+ }
133
+
134
+ /** a rendered trailer the draft makes and never commits (wiki build/shipkit/social.md, contract v3): its name says
135
+ * `-trailer.mp4` and its text names the command that writes it, `--out <its path from the repo's root>` */
136
+ export function renderedTrailer(name: string, raw: string, dirFromRepo: string): boolean {
137
+ return name.endsWith('-trailer.mp4') && raw.includes(`--out ${join(dirFromRepo, name)}`)
138
+ }
139
+
140
+ /** a section's line of `## Posted` set, or removed when the URL is null; the section is added at the end when absent, and
141
+ * goes with its last line, so a link pasted then cleared gives the draft back as it was */
142
+ export function setPostedLine(raw: string, key: string, url: string | null): string {
143
+ const at = raw.search(/^## Posted[ \t]*$/m)
144
+ const head = at === -1 ? raw.trimEnd() : raw.slice(0, at).trimEnd()
145
+ const rest = at === -1 ? '' : raw.slice(at).replace(/^.*\n?/, '')
146
+ const end = rest.search(/^## /m)
147
+ const lines = (end === -1 ? rest : rest.slice(0, end)).split('\n').filter((l) => l.trim() !== '' && POSTED_LINE.exec(l.trim())?.[1] !== key)
148
+ if (url != null) lines.push(`- ${key}: ${url}`)
149
+ const tail = end === -1 ? '' : `\n\n${rest.slice(end).trimEnd()}`
150
+ if (lines.length === 0) return `${head}${tail}\n`
151
+ return `${head}\n\n## Posted\n\n${lines.join('\n')}\n${tail}${tail ? '\n' : ''}`
152
+ }
153
+
154
+ /** one heading's text replaced, and its `title` option when given (empty removes it); the heading is found by its key,
155
+ * `<platform or group>[/<name>]` */
156
+ export function setHeadingText(raw: string, key: string, text: string, title?: string, tags?: string): string {
157
+ const body = text.trim()
158
+ if (/^## /m.test(body)) throw new Error(`a text holds no "## " line: it would start a heading`)
159
+ const heads = [...raw.matchAll(HEADING)]
160
+ const k = heads.findIndex((h) => {
161
+ const m = PLATFORM.exec(h[1]!)
162
+ if (m == null) return false
163
+ const name = m[2] == null ? undefined : options(m[2], '', []).name
164
+ return (name == null ? m[1] : `${m[1]}/${name}`) === key
165
+ })
166
+ const h = heads[k]
167
+ if (h == null) throw new Error(`no ## ${key} in the draft`)
168
+ const m = PLATFORM.exec(h[1]!)!
169
+ let line = h[0]
170
+ if (title !== undefined || tags !== undefined) {
171
+ const opts = m[2] == null ? {} : options(m[2], '', [])
172
+ for (const [o, v] of [['title', title], ['tags', tags === undefined ? undefined : tagList(tags).join(' ')]] as const) {
173
+ if (v === undefined) continue
174
+ if (v.trim() === '') delete opts[o]
175
+ else opts[o] = v.trim()
176
+ }
177
+ const list = (Object.keys(opts) as Option[]).map((o) => `${o}: ${opts[o]}`)
178
+ line = `## ${m[1]}${list.length ? ` (${list.join(', ')})` : ''}`
179
+ }
180
+ const next = heads[k + 1]
181
+ const tail = next == null ? '\n' : `\n\n${raw.slice(next.index)}`
182
+ return `${raw.slice(0, h.index)}${line}\n\n${body}${tail}`
183
+ }
@@ -0,0 +1,24 @@
1
+ // the house repos and who each speaks as, read from each repo.config.ts as text (never imported: a repo's config may
2
+ // need its own install), so `sk identities` lists every repo in a few ms
3
+ import { readFileSync } from 'node:fs'
4
+ import { homedir } from 'node:os'
5
+ import { join } from 'node:path'
6
+ import { houseRepos } from '../serve/project-gutter.ts'
7
+
8
+ export type HouseRepo = { name: string; path: string; speaksAs: string | undefined }
9
+
10
+ /** `speaksAs: '<id>'` of a config's text, undefined when it names none */
11
+ export const speaksAsOfText = (text: string): string | undefined => /^\s*speaksAs:\s*['"]([a-z0-9-]+)['"]/m.exec(text)?.[1]
12
+
13
+ export async function houseRepoRoots(cwd = process.cwd()): Promise<HouseRepo[]> {
14
+ const { repos } = houseRepos(cwd, homedir())
15
+ return repos.map((r) => {
16
+ let text = ''
17
+ try {
18
+ text = readFileSync(join(r.path, 'repo.config.ts'), 'utf8')
19
+ } catch {
20
+ text = ''
21
+ }
22
+ return { name: r.name, path: r.path, speaksAs: speaksAsOfText(text) }
23
+ })
24
+ }