rvlib-shipkit 2.20.0 → 2.21.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 (91) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/checks/SK004-gitignore-policy.check.ts +6 -3
  4. package/src/cli/cmd_GlobalProcesses.ts +2 -107
  5. package/src/cli/cmd_Home.ts +1 -1
  6. package/src/cli/cmd_Overview.ts +2 -1
  7. package/src/cli/cmd_Releases.ts +39 -3
  8. package/src/cli/cmd_Review.ts +22 -13
  9. package/src/cli/cmd_Social.ts +13 -7
  10. package/src/cli/cmd_Sound.ts +17 -4
  11. package/src/cli/cmd_Trailer.ts +67 -1
  12. package/src/cli/registry.ts +2 -1
  13. package/src/collections/collection-types.ts +1 -1
  14. package/src/collections/review.ts +23 -4
  15. package/src/core/layout.ts +6 -0
  16. package/src/home/gui-app/ShipkitGui.swift +35 -0
  17. package/src/home/gui-app.ts +1 -0
  18. package/src/home/pm-switch.ts +112 -0
  19. package/src/identities/identities.ts +11 -6
  20. package/src/messages/brief.ts +3 -3
  21. package/src/messages/score.ts +2 -0
  22. package/src/releases/add.ts +33 -5
  23. package/src/releases/before.ts +31 -0
  24. package/src/releases/from-card.ts +104 -19
  25. package/src/releases/model.ts +73 -13
  26. package/src/releases/pictures.ts +29 -8
  27. package/src/review/http.ts +1 -1
  28. package/src/review/model.ts +12 -2
  29. package/src/review/stage-card.ts +1 -1
  30. package/src/review/store.ts +12 -2
  31. package/src/review/trailer-desk.ts +19 -0
  32. package/src/review/trailer-model.ts +65 -0
  33. package/src/review/trailer-routes.ts +98 -1
  34. package/src/review/trailer-voices.ts +144 -0
  35. package/src/review/watchers.ts +58 -1
  36. package/src/serve/hub-app/benign-errors.ts +22 -0
  37. package/src/serve/hub-app/hash-route.ts +27 -15
  38. package/src/serve/hub-app/home-st.ts +8 -0
  39. package/src/serve/hub-app/hub-app.tsx +2 -0
  40. package/src/serve/hub-app/project-list.css +7 -2
  41. package/src/serve/hub-app/project-list.tsx +9 -0
  42. package/src/serve/hub-app/projects-svc.ts +16 -6
  43. package/src/serve/hub-app/releases/releases-page.tsx +121 -28
  44. package/src/serve/hub-app/releases/releases-st.ts +46 -4
  45. package/src/serve/hub-app/releases.css +30 -3
  46. package/src/serve/hub-app/repo-sections.ts +1 -1
  47. package/src/serve/hub-app/repo-st.ts +15 -10
  48. package/src/serve/hub-app/review/clip-st.ts +3 -1
  49. package/src/serve/hub-app/review/kit.tsx +3 -3
  50. package/src/serve/hub-app/review/trailer-page.tsx +31 -6
  51. package/src/serve/hub-app/review/trailer-st.ts +168 -8
  52. package/src/serve/hub-app/review/trailer-timeline.tsx +36 -4
  53. package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
  54. package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
  55. package/src/serve/hub-app/review.css +88 -0
  56. package/src/serve/hub-app/social/comms-page.tsx +10 -5
  57. package/src/serve/hub-app/social/next-release.tsx +118 -0
  58. package/src/serve/hub-app/social/social-model.ts +2 -0
  59. package/src/serve/hub-app/social/social-st.ts +38 -1
  60. package/src/serve/hub-app/social.css +8 -0
  61. package/src/serve/hub-app/tree-build.ts +2 -0
  62. package/src/serve/project-gutter-route.ts +8 -0
  63. package/src/serve/project-gutter.ts +4 -2
  64. package/src/shot/box.ts +33 -12
  65. package/src/shot/client.ts +1 -1
  66. package/src/shot/shooter.ts +19 -9
  67. package/src/social/desk-index.ts +49 -8
  68. package/src/social/discord-layout.ts +6 -2
  69. package/src/social/drafts.ts +1 -1
  70. package/src/social/kinds.ts +3 -2
  71. package/src/social/load.ts +26 -7
  72. package/src/social/publish/index.ts +24 -9
  73. package/src/social/release-stage.ts +133 -29
  74. package/src/social/routes.ts +2 -1
  75. package/src/social/stage.ts +39 -20
  76. package/src/trailer/bed.ts +111 -0
  77. package/src/trailer/build.ts +57 -38
  78. package/src/trailer/ffmpeg.ts +6 -0
  79. package/src/trailer/grammar.ts +23 -2
  80. package/src/trailer/graph.ts +12 -1
  81. package/src/trailer/shot-plan.ts +75 -0
  82. package/src/trailer/shot-state.ts +191 -0
  83. package/src/trailer/sound/audio.ts +28 -0
  84. package/src/trailer/sound/brand.ts +53 -3
  85. package/src/trailer/sound/gen.ts +61 -2
  86. package/src/trailer/sound/index.ts +25 -11
  87. package/src/trailer/sound/presets.ts +86 -5
  88. package/src/trailer/sound/run.ts +1 -1
  89. package/src/trailer/sound/takes.ts +94 -0
  90. package/src/trailer/titles.ts +36 -0
  91. package/src/trailer/url.ts +1 -1
@@ -2,15 +2,18 @@
2
2
  // stats says it: the social folder, the identities, the repo's config and social unit, the media a draft names outside
3
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
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
5
+ // stood: its error line clears at the next change. next-release.json is kept the same way, on next.md beside the parts
6
6
  import { type Dirent, readdirSync, statSync } from 'node:fs'
7
7
  import { join, relative } from 'node:path'
8
8
  import { LAYOUT } from '../core/layout.ts'
9
9
  import { headCommit } from '../core/git-root.ts'
10
10
  import { unitFilesDeclaring } from '../core/unit-files.ts'
11
11
  import { identitiesDir, readIdentities, type Identities } from '../identities/identities.ts'
12
+ import { fileOf, NEXT } from '../releases/model.ts'
13
+ import { releasesDir } from '../releases/store.ts'
12
14
  import { loadRepoConfig } from '../repo-config.ts'
13
15
  import { tagged } from '../review/http.ts'
16
+ import { previewNextRelease, type NextRelease } from './release-stage.ts'
14
17
  import { wireOf } from './desk-wire.ts'
15
18
  import { loadDesk, type Desk } from './load.ts'
16
19
  import { commitMoments, dayOf, postedOf, timelineOf } from './presence.ts'
@@ -67,24 +70,29 @@ const stat = (abs: string): string => {
67
70
  const stampOf = (parts: string[]): string => Bun.hash(parts.join('\n')).toString(36)
68
71
 
69
72
  type Part<T> = { stamp: string; value: T }
73
+ type Answer = { stamp: string; tag: string; text: string; zip?: Uint8Array<ArrayBuffer> }
70
74
  type Held = {
71
75
  idsDir?: string | null
72
- config?: Part<string | undefined>
76
+ config?: Part<{ speaksAs: string | undefined; releases: boolean }>
73
77
  ids?: Part<Identities>
74
78
  unit?: Part<SocialUnit | null>
75
79
  desk?: Part<Desk> & { outside: string[] }
76
- answer?: { stamp: string; tag: string; text: string; zip?: Uint8Array<ArrayBuffer> }
80
+ answer?: Answer
81
+ next?: Answer
77
82
  }
78
83
  const held = new Map<string, Held>()
79
84
 
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> }> {
85
+ /** what both answers are built from, the config, the identities and the unit, each read again only when its stamp moved */
86
+ async function partsOf(root: string) {
82
87
  const h = held.get(root) ?? {}
83
88
  held.set(root, h)
84
89
  if (h.idsDir === undefined) h.idsDir = await identitiesDir(root)
85
90
 
86
91
  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 })
92
+ if (h.config?.stamp !== configStamp) {
93
+ const c = await loadRepoConfig(root, { fresh: true }).catch(() => null)
94
+ h.config = { stamp: configStamp, value: { speaksAs: c?.speaksAs, releases: c?.release?.releases === true } }
95
+ }
88
96
 
89
97
  const idsParts: string[] = []
90
98
  if (h.idsDir != null) tree(h.idsDir, idsParts)
@@ -93,17 +101,22 @@ export async function deskWire(root: string): Promise<{ stamp: string; tag: stri
93
101
 
94
102
  const unitStamp = stampOf(unitFilesDeclaring(root, 'social').map(stat))
95
103
  const unit = h.unit?.stamp === unitStamp ? h.unit : (h.unit = { stamp: unitStamp, value: await loadSocialUnit(root) })
104
+ return { h, config: h.config, ids, unit, stamps: [configStamp, idsStamp, unitStamp] }
105
+ }
96
106
 
107
+ /** the answer of `root` as it stands: rebuilt only for the parts whose stamp moved */
108
+ export async function deskWire(root: string): Promise<Answer> {
109
+ const { h, config, ids, unit, stamps } = await partsOf(root)
97
110
  const today = dayOf(Date.now())
98
111
  const social = join(root, LAYOUT.social)
99
- const folder: string[] = [today, configStamp, idsStamp, unitStamp]
112
+ const folder: string[] = [today, ...stamps]
100
113
  tree(social, folder)
101
114
  folder.push(stat(pushLog(root)))
102
115
  for (const p of h.desk?.outside ?? []) folder.push(stat(p))
103
116
  const deskStamp = stampOf(folder)
104
117
  let desk = h.desk
105
118
  if (desk?.stamp !== deskStamp) {
106
- const value = loadDesk(root, ids.value, { speaksAs: config.value, unit: unit.value })
119
+ const value = loadDesk(root, ids.value, { speaksAs: config.value.speaksAs, unit: unit.value })
107
120
  const outside = [...new Set(value.drafts.flatMap((d) => d.media.map((m) => m.path)).filter((p) => relative(social, p).startsWith('..')))]
108
121
  desk = h.desk = { stamp: deskStamp, value, outside }
109
122
  }
@@ -121,3 +134,31 @@ export async function deskAnswer(req: Request, root: string): Promise<Response>
121
134
  const a = await deskWire(root)
122
135
  return tagged(req, a.tag, () => a.text, a)
123
136
  }
137
+
138
+ /** what Communications shows of the release being filled: `preview` null in a repo with no release files or no
139
+ * next.md, `error` when next.md does not parse */
140
+ export type NextReleaseView = { preview: NextRelease | null; error?: string }
141
+
142
+ /** next.md as the release that cuts it would stage it, kept while next.md, the rhythm and the parts stand */
143
+ export async function nextReleaseWire(root: string): Promise<Answer> {
144
+ const { h, config, unit, stamps } = await partsOf(root)
145
+ const stamp = stampOf([...stamps, stat(join(releasesDir(root), fileOf(NEXT))), stat(join(root, LAYOUT.social, 'rhythm.md'))])
146
+ if (h.next?.stamp === stamp) return h.next
147
+ let view: NextReleaseView = { preview: null }
148
+ if (config.value.releases) {
149
+ try {
150
+ view = { preview: await previewNextRelease(root, unit.value, { ...(config.value.speaksAs ? { speaksAs: config.value.speaksAs } : {}), identitiesDir: h.idsDir ?? null }) }
151
+ } catch (e) {
152
+ view = { preview: null, error: (e as Error).message }
153
+ }
154
+ }
155
+ const text = JSON.stringify(view)
156
+ h.next = { stamp, tag: `"${Bun.hash(text).toString(36)}"`, text }
157
+ return h.next
158
+ }
159
+
160
+ /** `GET api/social/next-release.json`: 304 while the page holds the answer */
161
+ export async function nextReleaseAnswer(req: Request, root: string): Promise<Response> {
162
+ const a = await nextReleaseWire(root)
163
+ return tagged(req, a.tag, () => a.text, a)
164
+ }
@@ -248,10 +248,14 @@ export async function applyLayout(a: Account, o: { dry: boolean; prune: boolean
248
248
  await act(`rename the category ${c.name} → ${cat.name}`, () => call(a, 'PATCH', `/channels/${id}`, json({ name: cat.name })))
249
249
  }
250
250
  place(c, CATEGORY, `the category ${cat.name}`)
251
+ // a dry run before its category exists: a channel the server already holds moves into it, never a new one
251
252
  if (c == null) {
252
253
  for (const def of cat.channels) {
253
- slot(def.voice ? VOICE : TEXT)
254
- changes.push(`would create #${def.name} in ${cat.name}`)
254
+ const type = def.voice ? VOICE : TEXT
255
+ const ch = channels.find((x) => x.type === type && same(channelKey(x.name), def.name))
256
+ if (ch) kept.add(ch.id)
257
+ slot(type)
258
+ changes.push(ch ? `would set #${def.name} (${cat.name}): category` : `would create #${def.name} in ${cat.name}`)
255
259
  }
256
260
  continue
257
261
  }
@@ -8,7 +8,7 @@ import { parseFrontmatter } from './md.ts'
8
8
 
9
9
  /** the headings a draft holds besides its platforms */
10
10
  const OWN = ['Angle', 'Posted'] as const
11
- const OPTIONS = ['name', 'place', 'title', 'media', 'pin', 'outro', 'mark', 'tags'] as const
11
+ const OPTIONS = ['name', 'place', 'title', 'media', 'rating', 'pin', 'outro', 'mark', 'tags'] as const
12
12
  type Option = (typeof OPTIONS)[number]
13
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
14
  const WORDS: Partial<Record<Option, readonly string[]>> = { outro: ['montage', 'short', 'none'], mark: ['left', 'right'] }
@@ -21,8 +21,9 @@ export const KIND_FOR: Readonly<Record<PostKind, string>> = {
21
21
  /** a shared kind's rules page, from the house wiki's root */
22
22
  export const kindPage = (k: PostKind): string => `guides/post-kinds/post-kind-${k}.md`
23
23
 
24
- /** the kind a staged draft takes from its source: an approved card shows a change a user can use, a release tells a version */
25
- export const sourceKind = (s: { review: string } | { release: string }): PostKind => ('review' in s ? 'feature' : 'release')
24
+ /** the kind a staged draft takes from its source: a card logs a step of the work, a release tells a version. A card is
25
+ * never a `feature` by default: no fact the house keeps says its change reaches users, so that is picked by hand */
26
+ export const sourceKind = (s: { review: string } | { release: string }): PostKind => ('review' in s ? 'iteration' : 'release')
26
27
 
27
28
  /** a kind a project declares in its social unit: its id, what a post of it is for, its rules page from the repo's root */
28
29
  export interface OwnKind {
@@ -2,7 +2,7 @@
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 } from 'node:path'
5
+ import { join, relative, resolve, sep } from 'node:path'
6
6
  import { LAYOUT } from '../core/layout.ts'
7
7
  import { speakerOf, type Account, type Identities, type Identity } from '../identities/identities.ts'
8
8
  import { isPostRating, POST_RATINGS, takes, type PostRating } from '../identities/rating.ts'
@@ -101,7 +101,7 @@ export type SocialPost = {
101
101
  reply: string
102
102
  /** its write page takes the text (`{text}`); else « Open » copies it first */
103
103
  prefilled: boolean
104
- /** the draft's rating: what a publisher labels it with */
104
+ /** its rating, its heading's own else the draft's: what a publisher labels it with */
105
105
  rating: PostRating
106
106
  /** why it may not go out: the repo's guard on its draft, or a place under its rating; empty, it may */
107
107
  refused: string
@@ -323,12 +323,14 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
323
323
  }
324
324
  for (const { s, a, key, from } of sends) {
325
325
  // a place belongs to its account: a group's message lands on the account's own place, or the first that
326
- // takes the draft's rating; an account's own heading names its place, which must take it
326
+ // takes the message's rating; an account's own heading names its place, which must take it. A heading's own
327
+ // `rating` is its message's (a release's nsfw picture on the venue that takes it), else the draft's
328
+ const rating = s.options.rating === undefined ? draft.rating : ratingOf(s.options.rating, false, speaker.name, `${file} ## ${s.key}`, errors)
327
329
  const places = placesFor(a)
328
330
  let place = s.options.place ?? ''
329
331
  let refused = ''
330
332
  if (from !== key) {
331
- const l = landing(a, places, draft.rating)
333
+ const l = landing(a, places, rating)
332
334
  if ('skip' in l) {
333
335
  draft.skipped.push({ account: a.id, why: l.skip })
334
336
  continue
@@ -336,8 +338,8 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
336
338
  place = l.place
337
339
  } else {
338
340
  const ceiling = ceilingAt(a, places, place)
339
- if (ceiling != null && !takes(ceiling, draft.rating)) {
340
- refused = `## ${key} goes to ${place || 'its profile'} on ${a.name}, which takes ${ceiling}, and the draft is ${draft.rating}`
341
+ if (ceiling != null && !takes(ceiling, rating)) {
342
+ refused = `## ${key} goes to ${place || 'its profile'} on ${a.name}, which takes ${ceiling}, and ${s.options.rating === undefined ? 'the draft' : 'its message'} is ${rating}`
341
343
  errors.push(`${file}: ${refused}`)
342
344
  }
343
345
  }
@@ -375,7 +377,7 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
375
377
  pin: s.options.pin === 'true',
376
378
  from,
377
379
  footer,
378
- rating: draft.rating,
380
+ rating,
379
381
  refused,
380
382
  }
381
383
  errors.push(...messageErrors(post, a))
@@ -420,6 +422,23 @@ export function accountOf(desk: Desk, identity: string, account: string): DeskAc
420
422
  return a
421
423
  }
422
424
 
425
+ /** a draft by what a command was given: its folder's name, its topic, or its path (relative to `cwd` or absolute, a
426
+ * trailing slash or its `draft.md` alike); a path outside the drafts folder is refused */
427
+ export function findDraft(desk: Desk, ref: string, cwd: string): Draft {
428
+ const where = `${LAYOUT.social}/drafts/`
429
+ let name = ref
430
+ if (ref.includes('/') || ref.endsWith('.md') || ref === '.') {
431
+ const parts = relative(draftsDir(desk.root), resolve(cwd, ref)).split(sep).filter((x) => x !== '')
432
+ if (parts.length === 2 && parts[1]!.endsWith('.md')) parts.pop()
433
+ if (parts.length !== 1 || parts[0] === '..') throw new Error(`${ref} is no draft of ${where}: a draft is a folder right under it`)
434
+ name = parts[0]!
435
+ }
436
+ const hits = desk.drafts.filter((x) => x.slug === name || x.slug.replace(/^\d{8}-\d{6}-/, '') === name)
437
+ 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`)
438
+ if (hits[0] == null) throw new Error(`no draft "${ref}" in ${where}: give its folder's name, its topic or its path`)
439
+ return hits[0]
440
+ }
441
+
423
442
  /** one message of a draft by its key, `<account>` or `<account>/<name>` */
424
443
  export function draftPost(desk: Desk, slug: string, key: string): SocialPost {
425
444
  const d = desk.drafts.find((x) => x.slug === slug)
@@ -1,5 +1,6 @@
1
1
  // the accounts shipkit posts to itself (`automation: live`): one publisher a platform, the desk's « Publish », and
2
- // `sk social post --publish`, every waiting message of a draft on its live accounts (`--only` one of them)
2
+ // `sk social post --publish`, every waiting message of a draft on its live accounts (`--only` one of them), `--edit` a
3
+ // posted one sent again at its link where the venue edits in place
3
4
  import { accountOf, draftPost, type Desk } from '../load.ts'
4
5
  import { setPosted } from '../writes.ts'
5
6
  import { postBluesky } from './bluesky.ts'
@@ -14,6 +15,17 @@ const PUBLISHERS: Publishers = {
14
15
  bluesky: postBluesky,
15
16
  }
16
17
 
18
+ /** the messages `--only` keeps: a message's key (`discord`, `discord/nsfw`) that one alone, else an account's every
19
+ * message. So a release's `--only discord` posts its #announcements message, never the nsfw one beside it */
20
+ export function onlyOf<P extends Pick<SocialPost, 'key' | 'platform'>>(posts: readonly P[], only: string | undefined): P[] {
21
+ if (only == null) return [...posts]
22
+ const one = posts.filter((p) => p.key === only)
23
+ return one.length > 0 ? one : posts.filter((p) => p.platform === only)
24
+ }
25
+
26
+ /** the venues whose publisher edits a posted message at its link; any other refuses a second send */
27
+ const EDITS_IN_PLACE: ReadonlySet<string> = new Set(['discord'])
28
+
17
29
  /** posts one message of a draft and records its link; the files written. `publishers` is a test's stub */
18
30
  export async function publish(desk: Desk, slug: string, key: string, publishers: Publishers = PUBLISHERS): Promise<{ url: string; files: string[] }> {
19
31
  const post = draftPost(desk, slug, key)
@@ -22,28 +34,31 @@ export async function publish(desk: Desk, slug: string, key: string, publishers:
22
34
  const run = publishers[post.platform]
23
35
  if (run == null) throw new Error(`${post.platform}: nothing posts there by itself`)
24
36
  if (a.automation !== 'live') throw new Error(`${a.file}: its automation is not live`)
25
- if (post.posted !== '' && post.platform !== 'discord') throw new Error(`${slug} is already posted on ${a.name}: ${post.posted}`)
37
+ if (post.posted !== '' && !EDITS_IN_PLACE.has(post.platform)) throw new Error(`${slug} is already posted on ${a.name}: ${post.posted}`)
26
38
  const url = await run(a, post)
27
39
  return { url, files: url === post.posted ? [] : setPosted(desk, slug, key, url) }
28
40
  }
29
41
 
30
42
  /** each waiting message of a draft on a live account posted, the others named as waiting for his paste; `only` keeps
31
- * one account's. `before` brings a media the disk let go back first */
43
+ * one account's, `edit` sends a posted one again as an edit where its venue edits in place. `before` brings a media
44
+ * the disk let go back first */
32
45
  export async function publishDraft(
33
46
  desk: Desk,
34
47
  slug: string,
35
- o: { only?: string; publishers?: Publishers; before?: (p: SocialPost) => Promise<void> } = {},
48
+ o: { only?: string; edit?: boolean; publishers?: Publishers; before?: (p: SocialPost) => Promise<void> } = {},
36
49
  ): Promise<{ key: string; line: string }[]> {
37
50
  const d = desk.drafts.find((x) => x.slug === slug)
38
51
  if (d == null) throw new Error(`no draft ${slug}`)
39
52
  const out: { key: string; line: string }[] = []
40
- for (const p of d.posts.filter((x) => o.only == null || x.platform === o.only)) {
41
- const live = accountOf(desk, p.identity, p.platform).automation === 'live'
42
- if (p.posted !== '') out.push({ key: p.key, line: `already posted, ${p.posted}` })
43
- else if (!live) out.push({ key: p.key, line: 'waits for his paste' })
53
+ for (const p of onlyOf(d.posts, o.only)) {
54
+ const a = accountOf(desk, p.identity, p.platform)
55
+ const live = a.automation === 'live'
56
+ if (p.posted !== '' && !o.edit) out.push({ key: p.key, line: `already posted, ${p.posted}${live && EDITS_IN_PLACE.has(p.platform) ? ' (--edit sends its text again at its link)' : ''}` })
57
+ else if (p.posted !== '' && !EDITS_IN_PLACE.has(p.platform)) out.push({ key: p.key, line: `already posted, ${p.posted}: ${a.name} cannot edit a post in place, nothing sent` })
58
+ else if (!live) out.push({ key: p.key, line: p.posted !== '' ? `already posted, ${p.posted}: ${a.file} is not automation: live, edit it by hand` : 'waits for his paste' })
44
59
  else {
45
60
  await o.before?.(p)
46
- out.push({ key: p.key, line: `posted, ${(await publish(desk, slug, p.key, o.publishers)).url}` })
61
+ out.push({ key: p.key, line: `${p.posted !== '' ? 'edited at its link' : 'posted'}, ${(await publish(desk, slug, p.key, o.publishers)).url}` })
47
62
  }
48
63
  }
49
64
  return out
@@ -1,23 +1,29 @@
1
1
  // a release as the second source of a staged post (wiki tools/shipkit/social.md, A post staged): one draft for the
2
2
  // beat, a heading per venue the repo's social unit declares, the release's message under each, its notes in its angle,
3
- // its polish note raised. Its media is his pick, later, among the approved cards the release ships (a commit of theirs
4
- // in its range). Idempotent: one draft a release. A repo with no `release` headings stages nothing
3
+ // its polish note raised. Its media: the release file's pictures, each venue the one its place takes (`shotFor`): the
4
+ // safe one for the draft, a heading of its own where the place takes an nsfw one, and the nsfw twin of a venue that
5
+ // cannot (Discord's -nsfw channel), staged to wait for his Publish; else his pick, later, among the approved cards the
6
+ // release ships. Idempotent: one draft a release. A repo with no `release` headings stages nothing. Before the cut,
7
+ // Communications shows next.md as the same input loaded on a scratch copy (`previewNextRelease`), nothing written
5
8
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
6
9
  import { basename, dirname, join } from 'node:path'
7
- import { isPostRating, type PostRating } from '../identities/rating.ts'
10
+ import { loadIdentities } from '../identities/identities.ts'
11
+ import { isPostRating, POST_RATINGS, takes, type PostRating } from '../identities/rating.ts'
12
+ import { localPicture } from '../releases/pictures.ts'
13
+ import { ceilingAt, landing, placesOf } from './reach.ts'
8
14
  import { isApproved, verdictOf, type ReviewItem } from '../review/model.ts'
9
15
  import { stageablesOf, stageFileOf, type Stageable } from '../review/stage-card.ts'
10
16
  import { readAll, storeDir } from '../review/store.ts'
11
17
  import { threadsOf, type Thread } from '../review/threads.ts'
12
- import { changesOf, type Release } from '../releases/model.ts'
18
+ import { changesOf, NEXT, picturesOf, ratingOf, shotFor, type Picture, type Release } from '../releases/model.ts'
13
19
  import { hasReleases, readRelease } from '../releases/store.ts'
14
20
  import { gitBin } from '../core/git-bin.ts'
15
21
  import { setHeadingText } from './drafts.ts'
16
- import { DRAFT_NAME, draftsDir } from './load.ts'
22
+ import { DRAFT_NAME, draftsDir, type Draft } from './load.ts'
17
23
  import { parseFrontmatter, setMeta } from './md.ts'
18
- import { askPolish, dryLoad, mediaFile, stageDraft, type Staged } from './stage.ts'
24
+ import { askPolish, contextOf, draftText, dryLoad, mediaFile, stageDraft, stageDry, type Staged, type StageHeading, type StageInput, type StageMedia } from './stage.ts'
19
25
  import { stripCopy } from './strip.ts'
20
- import { guardWith, type SocialUnit } from './unit.ts'
26
+ import { guardWith, type ReleaseHeading, type SocialUnit } from './unit.ts'
21
27
  import { commitPaths } from './writes.ts'
22
28
 
23
29
  export type ReleaseAsk = {
@@ -60,43 +66,136 @@ export function noteLines(md: string): string[] {
60
66
  .map((l) => (/^[-*+]\s/.test(l) ? `- ${l.slice(2).trim()}` : l))
61
67
  }
62
68
 
69
+ type StageCtx = { speaksAs?: string; identitiesDir?: string | null }
70
+
71
+ const ctxOf = (unit: SocialUnit | null, o: StageCtx) => ({ unit, ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}), ...(o.identitiesDir !== undefined ? { identitiesDir: o.identitiesDir } : {}) })
72
+
73
+ /** a release's first picture, in the file's order, that a venue whose ceiling is `ceiling` shows; with `nsfw`, its first
74
+ * such picture rated above safe (what a venue that takes more shows that a safe one cannot); null, none */
75
+ function firstFor(file: Release, ceiling: PostRating, nsfw = false): Picture | null {
76
+ for (const ch of changesOf(file)) {
77
+ const s = shotFor(ch, ceiling)
78
+ if (s && (!nsfw || ratingOf(s.picture) !== 'safe')) return s.picture
79
+ }
80
+ return null
81
+ }
82
+
83
+ /** a release picture as a stage's media, its local file named by its rating and sha */
84
+ async function stagedPicture(root: string, p: Picture): Promise<StageMedia> {
85
+ const file = await localPicture(root, p.url)
86
+ return { file, name: `release-${ratingOf(p)}-${basename(file).slice(0, 12)}` }
87
+ }
88
+
89
+ /** each release heading with the picture its place takes (wiki tools/shipkit/social.md, A post staged): the draft's
90
+ * media is the release's first safe picture, which every place takes; an account heading whose place takes more gets
91
+ * the first nsfw picture its ceiling takes as its own, with its rating; and an account heading under the release's highest
92
+ * rating gets a twin, `name: nsfw`, on the place a message of that rating lands (Discord: its -nsfw channel), its
93
+ * nsfw picture. A group heading lands on many places, so it keeps the safe one */
94
+ async function venueMedia(root: string, file: Release | null, headings: readonly ReleaseHeading[], o: StageCtx): Promise<{ media: StageMedia | null; alt: string; headings: StageHeading[] }> {
95
+ const safe = file ? firstFor(file, 'safe') : null
96
+ const media = safe ? await stagedPicture(root, safe) : null
97
+ const top = file ? picturesOf({ shots: changesOf(file).flatMap((c) => c.shots) }).map(ratingOf).sort((a, b) => POST_RATINGS.indexOf(b) - POST_RATINGS.indexOf(a))[0] : undefined
98
+ if (file == null || top == null || top === 'safe') return { media, alt: safe?.alt ?? '', headings: [...headings] }
99
+ const c = await contextOf(root, { unit: null, ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}), ...(o.identitiesDir !== undefined ? { identitiesDir: o.identitiesDir } : {}) })
100
+ const ids = await loadIdentities({ ...(c.identitiesDir != null ? { dir: c.identitiesDir } : {}), cwd: root })
101
+ const accounts = ids.identities.find((i) => i.id === c.speaksAs)?.accounts ?? []
102
+ const out: StageHeading[] = []
103
+ for (const h of headings) {
104
+ const a = accounts.find((x) => x.id === h.id)
105
+ if (a == null) {
106
+ out.push(h)
107
+ continue
108
+ }
109
+ const errors: string[] = []
110
+ const places = placesOf(a, errors)
111
+ const ceiling = ceilingAt(a, places, h.place ?? '') ?? 'safe'
112
+ const own = firstFor(file, ceiling, true)
113
+ out.push(own ? { ...h, rating: ratingOf(own), media: await stagedPicture(root, own) } : h)
114
+ if (takes(ceiling, top)) continue
115
+ const l = landing({ name: a.name, place: h.place ?? '', ceiling: a.ceiling }, places, top)
116
+ if (!('place' in l) || l.place === (h.place ?? '')) continue
117
+ const twin = firstFor(file, ceilingAt(a, places, l.place) ?? 'safe', true)
118
+ if (twin) out.push({ id: h.id, name: 'nsfw', place: l.place, rating: ratingOf(twin), media: await stagedPicture(root, twin) })
119
+ }
120
+ return { media, alt: safe?.alt ?? '', headings: out }
121
+ }
122
+
123
+ /** what a release stages: its file's change titles when the repo keeps one (the notes handed in are only its fallback),
124
+ * else its notes' lines, and each venue's picture. The one builder of the stage and of its preview, so both write the
125
+ * same draft */
126
+ async function releaseInput(root: string, ask: ReleaseAsk, file: Release | null, headings: readonly ReleaseHeading[], o: StageCtx): Promise<StageInput> {
127
+ const ref = `${ask.unit}@${ask.version}`
128
+ const lines = file ? changesOf(file).map((c) => `- ${c.title}`) : noteLines(ask.notes)
129
+ const m = await venueMedia(root, file, headings, o)
130
+ return {
131
+ source: { release: ref },
132
+ title: ask.title ?? (file?.title ? `${file.version}: ${file.title}` : `${ask.unit} ${ask.version}`),
133
+ text: (ask.message?.trim() ? noteLines(ask.message).join('\n') : lines.join('\n')) || `${ask.unit} ${ask.version} is out.`,
134
+ rating: 'safe',
135
+ status: 'draft',
136
+ headings: m.headings,
137
+ ...(m.media ? { media: m.media, alt: m.alt } : {}),
138
+ angle: [`Staged from the release ${ref}${ask.tag ? ` (${ask.since ? `${ask.since}..` : ''}${ask.tag})` : ''}. Its notes:`, '', ...lines].join('\n'),
139
+ ...(ask.now ? { now: ask.now } : {}),
140
+ }
141
+ }
142
+
63
143
  /** one draft of the release, waiting in Communications: null when the unit declares no release headings; the draft
64
144
  * already staged for the same release when there is one, nothing written */
65
- export async function stageRelease(root: string, unit: SocialUnit | null, ask: ReleaseAsk, o: { speaksAs?: string; identitiesDir?: string | null } = {}): Promise<(Staged & { created: boolean }) | null> {
145
+ export async function stageRelease(root: string, unit: SocialUnit | null, ask: ReleaseAsk, o: StageCtx = {}): Promise<(Staged & { created: boolean }) | null> {
66
146
  const headings = unit?.release?.headings
67
147
  if (headings == null || headings.length === 0) return null
68
148
  const ref = `${ask.unit}@${ask.version}`
69
149
  const had = releaseDraft(root, ref)
70
150
  if (had != null) return { slug: had, files: [], draft: null, errors: [], created: false }
71
- // the release's file, when the repo keeps one, is its words: the notes handed in are only its fallback
72
- const file = releaseFileOf(root, ref)
73
- const lines = file ? changesOf(file).map((c) => `- ${c.title}`) : noteLines(ask.notes)
74
- const text = (ask.message?.trim() ? noteLines(ask.message).join('\n') : lines.join('\n')) || `${ask.unit} ${ask.version} is out.`
75
- const title = ask.title ?? (file?.title ? `${file.version}: ${file.title}` : `${ask.unit} ${ask.version}`)
76
- const r = await stageDraft(
77
- root,
78
- {
79
- source: { release: ref },
80
- title,
81
- text,
82
- rating: 'safe',
83
- status: 'draft',
84
- headings,
85
- angle: [`Staged from the release ${ref}${ask.tag ? ` (${ask.since ? `${ask.since}..` : ''}${ask.tag})` : ''}. Its notes:`, '', ...lines].join('\n'),
86
- ...(ask.now ? { now: ask.now } : {}),
87
- },
88
- { unit, ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}), ...(o.identitiesDir !== undefined ? { identitiesDir: o.identitiesDir } : {}) },
89
- )
151
+ const input = await releaseInput(root, ask, releaseFileOf(root, ref), headings, o)
152
+ const r = await stageDraft(root, input, ctxOf(unit, o))
90
153
  // the range its media comes from, read back by Communications
91
154
  if (ask.tag) {
92
155
  const f = join(draftsDir(root), r.slug, 'draft.md')
93
156
  writeFileSync(f, setMeta(readFileSync(f, 'utf8'), 'range', `${ask.since ? `${ask.since}..` : ''}${ask.tag}`))
94
157
  commitPaths([f], `social: ${r.slug} names the range of ${ref}`)
95
158
  }
96
- await askPolish(root, r.slug, title, unit, 'release')
159
+ await askPolish(root, r.slug, input.title, unit, 'release')
97
160
  return { ...r, created: true }
98
161
  }
99
162
 
163
+ /** the release being filled as Communications shows it: next.md, and the draft a release would stage from it */
164
+ export type NextRelease = {
165
+ release: Release
166
+ /** `root@next`: the root unit, the only one with release files */
167
+ ref: string
168
+ headings: readonly ReleaseHeading[]
169
+ /** the draft as `stageRelease` writes it, loaded from a scratch folder; null when the unit declares no headings */
170
+ draft: Draft | null
171
+ /** its draft.md; empty when the unit declares no headings */
172
+ text: string
173
+ /** the guard's and the load's lines about it */
174
+ errors: string[]
175
+ }
176
+
177
+ /** next.md as the release that cuts it would stage it, `version` still `next`: the same input as `stageRelease`, loaded
178
+ * by `stageDry` from a scratch folder, so nothing in the repo is written. Null without next.md; a next.md that does
179
+ * not parse throws */
180
+ export async function previewNextRelease(root: string, unit: SocialUnit | null, o: StageCtx & { now?: Date } = {}): Promise<NextRelease | null> {
181
+ const release = hasReleases(root) ? readRelease(root, NEXT) : null
182
+ if (release == null) return null
183
+ const headings = unit?.release?.headings ?? []
184
+ const ask: ReleaseAsk = { unit: 'root', version: NEXT, notes: '', ...(o.now ? { now: o.now } : {}) }
185
+ const ref = `${ask.unit}@${ask.version}`
186
+ if (headings.length === 0) return { release, ref, headings, draft: null, text: '', errors: [] }
187
+ // a picture the disk and the Space cannot give (offline) leaves the preview its words, and says why
188
+ const fetched = await releaseInput(root, ask, release, headings, o).then(
189
+ (input) => ({ input, why: null }),
190
+ async (e: unknown) => ({ input: await releaseInput(root, ask, null, headings, o).then((i) => ({ ...i, text: changesOf(release).map((c) => `- ${c.title}`).join('\n') || i.text })), why: `its pictures: ${(e as Error).message}` }),
191
+ )
192
+ const { input } = fetched
193
+ const r = await stageDry(root, input, ctxOf(unit, o))
194
+ // `next` is no version yet: the load's line on the ref is the one a cut release never meets
195
+ const errors = [...r.errors.filter((e) => !e.includes(`release "${ref}"`)), ...(fetched.why ? [fetched.why] : [])]
196
+ return { release, ref, headings, draft: r.draft, text: draftText(input, input.media ? mediaFile(input.media) : null), errors }
197
+ }
198
+
100
199
  /** the commits of a range, full shas; the range `a..b`, or a tag alone (every commit up to it) */
101
200
  function commitsOf(root: string, range: string): Set<string> {
102
201
  const r = Bun.spawnSync([gitBin(), 'rev-list', range], { cwd: root, stdout: 'pipe', stderr: 'pipe' })
@@ -164,7 +263,12 @@ export async function releaseMedia(
164
263
  const c = { ...(o.unit !== undefined ? { unit: o.unit } : {}), ...(o.speaksAs !== undefined ? { speaksAs: o.speaksAs } : {}) }
165
264
  const problems = guardWith(o.unit, { alt: ask.alt ?? '', texts: ask.text ? [ask.text] : [], files: [file] })
166
265
  if (problems.length > 0 && !ask.dry) throw new Error(`the repo's guard refuses it: ${problems.join('; ')}`)
167
- if (ask.dry) return dryLoad(root, slug, raw, { name, file }, c)
266
+ if (ask.dry) {
267
+ // the media the draft holds already (a heading's own picture) beside the one picked
268
+ const dir = join(draftsDir(root), slug)
269
+ const had = existsSync(join(dir, 'media')) ? readdirSync(join(dir, 'media')).map((n) => ({ name: `media/${n}`, file: join(dir, 'media', n) })) : []
270
+ return dryLoad(root, slug, raw, [...had.filter((x) => x.name !== name), { name, file }], c)
271
+ }
168
272
  mkdirSync(dirname(join(draftsDir(root), slug, name)), { recursive: true })
169
273
  stripCopy(file, join(draftsDir(root), slug, name))
170
274
  writeFileSync(f, raw)
@@ -12,7 +12,7 @@ import { isPostRating } from '../identities/rating.ts'
12
12
  import { noteLines, releaseCards, releaseMedia } from './release-stage.ts'
13
13
  import { readAllCached, storeDir } from '../review/store.ts'
14
14
  import { DRAFT_NAME, draftsDir, type Desk } from './load.ts'
15
- import { deskAnswer } from './desk-index.ts'
15
+ import { deskAnswer, nextReleaseAnswer } from './desk-index.ts'
16
16
  import { socialMediaBack, socialMediaUrl } from './media-kind.ts'
17
17
  import { openDesk } from './open.ts'
18
18
  import { openAll } from '../veille/chrome.ts'
@@ -65,6 +65,7 @@ export async function socialRoutes(root: string, req: Request, path: string): Pr
65
65
  try {
66
66
  if (req.method === 'GET') {
67
67
  if (sub === 'desk.json') return deskAnswer(req, root)
68
+ if (sub === 'next-release.json') return nextReleaseAnswer(req, root)
68
69
  if (sub === 'stats.json') {
69
70
  const { desk } = await openDesk(root)
70
71
  const out: Record<string, Record<string, string>> = {}