rvlib-shipkit 2.20.0 → 2.22.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 (156) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/package.json +1 -1
  3. package/src/asks/asks-queue.ts +8 -7
  4. package/src/assets/kits/identity-kit.ts +158 -2
  5. package/src/checks/SK004-gitignore-policy.check.ts +6 -3
  6. package/src/cli/cmd_Bump.ts +3 -3
  7. package/src/cli/cmd_GlobalProcesses.ts +2 -107
  8. package/src/cli/cmd_Home.ts +1 -1
  9. package/src/cli/cmd_Overview.ts +2 -1
  10. package/src/cli/cmd_Rec.ts +349 -0
  11. package/src/cli/cmd_Releases.ts +42 -3
  12. package/src/cli/cmd_Review.ts +22 -13
  13. package/src/cli/cmd_Secret.ts +10 -3
  14. package/src/cli/cmd_Sign.ts +24 -0
  15. package/src/cli/cmd_Social.ts +57 -8
  16. package/src/cli/cmd_Sound.ts +17 -4
  17. package/src/cli/cmd_Trailer.ts +67 -1
  18. package/src/cli/family-pages.ts +1 -0
  19. package/src/cli/registry.ts +6 -1
  20. package/src/collections/collection-types.ts +1 -1
  21. package/src/collections/review.ts +23 -4
  22. package/src/core/agent-spawn.ts +4 -17
  23. package/src/core/code-lines.ts +49 -0
  24. package/src/core/discover-checks.ts +27 -3
  25. package/src/core/hard-reset.ts +34 -0
  26. package/src/core/layout.ts +6 -0
  27. package/src/core/raw-access.ts +3 -13
  28. package/src/core/throwaway-worktree.ts +72 -0
  29. package/src/home/app-sign.ts +98 -0
  30. package/src/home/gui-app/ShipkitGui.swift +35 -0
  31. package/src/home/gui-app.ts +31 -11
  32. package/src/home/home-routes.ts +6 -0
  33. package/src/home/pm-switch.ts +112 -0
  34. package/src/home/serve-web.ts +1 -1
  35. package/src/identities/identities.ts +17 -6
  36. package/src/media-kinds.ts +5 -3
  37. package/src/media-store/forget.ts +54 -0
  38. package/src/media-store/put.ts +4 -3
  39. package/src/media-store/space.ts +63 -24
  40. package/src/messages/brief.ts +3 -3
  41. package/src/messages/score.ts +2 -0
  42. package/src/recordings/delete.ts +19 -0
  43. package/src/recordings/edit.ts +231 -0
  44. package/src/recordings/load.ts +37 -0
  45. package/src/recordings/marks-draw.ts +111 -0
  46. package/src/recordings/marks-png.ts +25 -0
  47. package/src/recordings/marks.ts +138 -0
  48. package/src/recordings/media-kind.ts +67 -0
  49. package/src/recordings/model.ts +170 -0
  50. package/src/recordings/open.ts +33 -0
  51. package/src/recordings/place.ts +89 -0
  52. package/src/recordings/presets.ts +99 -0
  53. package/src/recordings/recorder-app/Capture.swift +510 -0
  54. package/src/recordings/recorder-app/Clip.swift +107 -0
  55. package/src/recordings/recorder-app/Editor.swift +39 -0
  56. package/src/recordings/recorder-app/Tray.swift +298 -0
  57. package/src/recordings/recorder-app/main.swift +859 -0
  58. package/src/recordings/recorder-app.ts +46 -0
  59. package/src/recordings/recorder.shipkit.ts +11 -0
  60. package/src/recordings/routes.ts +140 -0
  61. package/src/recordings/run-recorder.ts +40 -0
  62. package/src/recordings/share.ts +107 -0
  63. package/src/recordings/take.ts +146 -0
  64. package/src/recordings/view.ts +40 -0
  65. package/src/release/gate-checkout.ts +74 -0
  66. package/src/release/release-scope.ts +35 -26
  67. package/src/release/run-bump.ts +79 -37
  68. package/src/release/run-release.ts +67 -53
  69. package/src/releases/add.ts +38 -5
  70. package/src/releases/before.ts +31 -0
  71. package/src/releases/from-card.ts +105 -20
  72. package/src/releases/model.ts +100 -18
  73. package/src/releases/pictures.ts +29 -8
  74. package/src/repo-config.ts +7 -3
  75. package/src/review/http.ts +1 -1
  76. package/src/review/model.ts +12 -2
  77. package/src/review/stage-card.ts +1 -1
  78. package/src/review/store.ts +12 -2
  79. package/src/review/trailer-desk.ts +20 -0
  80. package/src/review/trailer-model.ts +67 -0
  81. package/src/review/trailer-routes.ts +98 -1
  82. package/src/review/trailer-voices.ts +144 -0
  83. package/src/review/watchers.ts +58 -1
  84. package/src/secrets/manager.ts +18 -1
  85. package/src/serve/hub-app/benign-errors.ts +22 -0
  86. package/src/serve/hub-app/hash-route.ts +27 -15
  87. package/src/serve/hub-app/home-st.ts +23 -5
  88. package/src/serve/hub-app/home.html +1 -0
  89. package/src/serve/hub-app/hub-app.tsx +8 -1
  90. package/src/serve/hub-app/icons.tsx +2 -0
  91. package/src/serve/hub-app/palette-st.ts +1 -0
  92. package/src/serve/hub-app/project-list.css +7 -2
  93. package/src/serve/hub-app/project-list.tsx +10 -0
  94. package/src/serve/hub-app/projects-svc.ts +17 -7
  95. package/src/serve/hub-app/recordings-st.ts +641 -0
  96. package/src/serve/hub-app/recordings-view.tsx +504 -0
  97. package/src/serve/hub-app/recordings.css +82 -0
  98. package/src/serve/hub-app/releases/releases-page.tsx +121 -28
  99. package/src/serve/hub-app/releases/releases-st.ts +46 -4
  100. package/src/serve/hub-app/releases.css +30 -3
  101. package/src/serve/hub-app/repo-sections.ts +1 -1
  102. package/src/serve/hub-app/repo-st.ts +16 -11
  103. package/src/serve/hub-app/review/clip-st.ts +3 -1
  104. package/src/serve/hub-app/review/kit.tsx +3 -3
  105. package/src/serve/hub-app/review/trailer-page.tsx +32 -6
  106. package/src/serve/hub-app/review/trailer-st.ts +184 -8
  107. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -4
  108. package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
  109. package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
  110. package/src/serve/hub-app/review.css +90 -0
  111. package/src/serve/hub-app/social/comms-page.tsx +10 -5
  112. package/src/serve/hub-app/social/next-release.tsx +118 -0
  113. package/src/serve/hub-app/social/post-card.tsx +31 -3
  114. package/src/serve/hub-app/social/social-model.ts +6 -0
  115. package/src/serve/hub-app/social/social-st.ts +50 -1
  116. package/src/serve/hub-app/social.css +12 -0
  117. package/src/serve/hub-app/tree-build.ts +2 -0
  118. package/src/serve/project-gutter-route.ts +8 -0
  119. package/src/serve/project-gutter.ts +4 -2
  120. package/src/shipkit.ts +2 -2
  121. package/src/shot/box.ts +49 -22
  122. package/src/shot/browser-slot.ts +13 -3
  123. package/src/shot/client.ts +1 -1
  124. package/src/shot/film-box.ts +193 -117
  125. package/src/shot/shooter.ts +20 -8
  126. package/src/smoke/run-smoke.ts +8 -6
  127. package/src/social/compose.ts +14 -0
  128. package/src/social/desk-index.ts +49 -8
  129. package/src/social/discord-layout.ts +6 -2
  130. package/src/social/drafts.ts +1 -1
  131. package/src/social/kinds.ts +3 -2
  132. package/src/social/load.ts +42 -9
  133. package/src/social/publish/index.ts +27 -10
  134. package/src/social/publish/secret.ts +12 -4
  135. package/src/social/release-card.ts +69 -0
  136. package/src/social/release-stage.ts +173 -30
  137. package/src/social/routes.ts +7 -1
  138. package/src/social/stage.ts +45 -22
  139. package/src/trailer/bed.ts +111 -0
  140. package/src/trailer/build.ts +81 -38
  141. package/src/trailer/ffmpeg.ts +14 -0
  142. package/src/trailer/grammar.ts +32 -4
  143. package/src/trailer/graph.ts +12 -1
  144. package/src/trailer/look.ts +7 -0
  145. package/src/trailer/shot-plan.ts +75 -0
  146. package/src/trailer/shot-state.ts +191 -0
  147. package/src/trailer/sound/audio.ts +28 -0
  148. package/src/trailer/sound/brand.ts +53 -3
  149. package/src/trailer/sound/gen.ts +61 -2
  150. package/src/trailer/sound/index.ts +25 -11
  151. package/src/trailer/sound/presets.ts +86 -5
  152. package/src/trailer/sound/run.ts +1 -1
  153. package/src/trailer/sound/takes.ts +94 -0
  154. package/src/trailer/titles.ts +36 -0
  155. package/src/trailer/url.ts +1 -1
  156. package/src/veille/chrome.ts +6 -3
@@ -1,20 +1,18 @@
1
1
  // WHAT DIRT ACTUALLY BLOCKS A RELEASE.
2
2
  //
3
3
  // The clean-tree rule exists so a release is REPRODUCIBLE from a commit: the
4
- // tag must describe exactly what shipped. That argument covers the paths the
5
- // release writes or packs, and nothing else. It was implemented as "the whole
6
- // worktree", which is the same one-checkout-one-agent assumption that used to
7
- // live in the launcher: with several agents in one repo, a sub-unit bump got
8
- // refused three times in a row for uncommitted files in OTHER units, none of
9
- // which can reach its tarball and none of which the tag would contain either
10
- // way. Correctness across the repo is the GATE's job, and the gate runs.
11
- //
12
- // So a SUB-UNIT bump refuses on dirt it could actually be wrong about:
13
- // - the unit's own directory, and its changelog wherever it is declared
14
- // - every unit's package.json, because a bump rewrites dependents' rvlib
15
- // ranges (SK011) and that write lands in the version commit
16
- // - the lockfiles, which a version change can move
17
- // A ROOT bump keeps the whole-tree rule, because the root unit IS the repo.
4
+ // tag must describe exactly what shipped. The gate judges HEAD in a clean
5
+ // checkout (gate-checkout.ts), so dirt reaches a release only through what
6
+ // the release itself reads, writes or packs in the working tree:
7
+ // - the files the version commit writes: a pathspec commit takes a file
8
+ // WHOLE, so a dirty line there lands in the tag ungated. That refusal
9
+ // (`writes`) holds whatever --allow-dirty says.
10
+ // - what `npm publish` packs: a sub-unit's own directory, the whole repo
11
+ // for an npm root. A root with a post-release step keeps the whole repo
12
+ // too, because that step (a deploy) runs from the working tree.
13
+ // - the notes the release reads: the changelog, the release files.
14
+ // Everything else is another session's work in flight, and refusing on it
15
+ // stalls every lane of a shared tree for files no tag contains.
18
16
  import { relative } from 'path'
19
17
 
20
18
  import type { ReleaseUnit } from './units.ts'
@@ -25,28 +23,39 @@ const LOCKFILES = ['bun.lock', 'bun.lockb', 'package-lock.json', 'yarn.lock', 'p
25
23
  export type ReleaseScope = {
26
24
  /** pathspecs to test for dirt, or null for the whole worktree */
27
25
  specs: string[] | null
26
+ /** the files the version commit writes: dirt there refuses, no flag lifts it */
27
+ writes: string[]
28
28
  /** one line saying what was examined, for the refusal and the note */
29
29
  describe: string
30
30
  }
31
31
 
32
32
  /**
33
- * the paths a bump of `targets` may write. `null` specs means "the whole
34
- * tree", which is the honest answer for a root bump.
33
+ * the paths a release of `targets` may read, write or pack. `null` specs means
34
+ * "the whole tree", the honest answer for a root that npm packs or that runs a
35
+ * post-release step from the working tree.
35
36
  */
36
- export function releaseScope(root: string, allUnits: ReleaseUnit[], targets: ReleaseUnit[]): ReleaseScope {
37
- // the root unit is the repo: nothing in the tree is outside its release
38
- if (targets.length === 0 || targets.some((u) => u.rel === '')) return { specs: null, describe: 'the whole worktree (a root release ships the repo)' }
39
- const specs = new Set<string>()
37
+ export function releaseScope(root: string, allUnits: ReleaseUnit[], targets: ReleaseUnit[], o: { after?: boolean } = {}): ReleaseScope {
38
+ const pkg = (u: ReleaseUnit): string => (u.rel === '' ? 'package.json' : `${u.rel}/package.json`)
39
+ // a bump rewrites the rvlib range in every dependent's package.json
40
+ const set = new Set<string>([...allUnits, ...targets].map(pkg))
40
41
  for (const u of targets) {
41
- specs.add(u.rel)
42
42
  // a unit can declare its changelog outside its own directory
43
- specs.add(relative(root, u.changelog))
43
+ set.add(relative(root, u.changelog))
44
+ if (u.releases != null) set.add(relative(root, u.releases))
44
45
  }
45
- // a bump rewrites the rvlib range in every dependent's package.json
46
- for (const u of allUnits) specs.add(u.rel === '' ? 'package.json' : `${u.rel}/package.json`)
47
- for (const f of LOCKFILES) specs.add(f)
46
+ const writes = [...set].sort()
47
+ const rootUnit = targets.find((u) => u.rel === '')
48
+ // an empty scope would mean "no dirt can ever block", the one failure mode worse than over-refusing
49
+ if (targets.length === 0) return { specs: null, writes, describe: 'the whole worktree (no unit named)' }
50
+ if (rootUnit?.targets.npm === true) return { specs: null, writes, describe: 'the whole worktree (npm packs the repo)' }
51
+ if (rootUnit != null && o.after === true) return { specs: null, writes, describe: 'the whole worktree (the post-release step runs from it)' }
52
+ const subs = targets.filter((u) => u.rel !== '')
53
+ const specs = new Set([...writes, ...subs.map((u) => u.rel), ...(subs.length > 0 ? LOCKFILES : [])])
48
54
  return {
49
55
  specs: [...specs].sort(),
50
- describe: `${targets.map((u) => u.rel).join(', ')} plus every package.json and lockfile the version commit can touch`,
56
+ writes,
57
+ describe: subs.length === 0
58
+ ? `${writes.join(', ')} (what the version commit writes; the gate judges HEAD)`
59
+ : `${subs.map((u) => u.rel).join(', ')} plus every package.json and lockfile the version commit can touch`,
51
60
  }
52
61
  }
@@ -6,9 +6,14 @@
6
6
  // writes (the next version, the tag, the per-unit gate) must describe the
7
7
  // merged tree, never the branch it was computed on. Nothing is pushed until
8
8
  // the very end, so any refusal rolls the merge back and returns you to your
9
- // branch. The gate then runs before anything is written, so a red repo never
10
- // gets a version bump commit, and the prepublish scripts run before the
11
- // commit, so a failing build cannot be tagged. publishing is delegated to
9
+ // branch. The gate then runs before anything is written, on the merged
10
+ // commit in a clean checkout of it (gate-checkout.ts): the shared working
11
+ // tree holds other sessions' unsaved work, which no tag contains. So a red
12
+ // HEAD never gets a version bump commit, and the prepublish scripts run
13
+ // before the commit, so a failing build cannot be tagged. The gate judges
14
+ // HEAD and not HEAD plus the version commit, because that commit only renames
15
+ // the notes and rewrites version strings, and gating it first would leave a
16
+ // version commit behind every red gate. publishing is delegated to
12
17
  // run-release.
13
18
  //
14
19
  // --dry-run is the ONE exception, and deliberately so: it is the command you
@@ -119,22 +124,47 @@ function mergeIntoReleaseBranch(
119
124
  restore()
120
125
  return { ok: false }
121
126
  }
127
+ const merged = git(['rev-parse', 'HEAD']).out
122
128
  print(`ok: merged '${from}' into '${to}' (merge commit, not pushed yet)`)
123
129
  return {
124
130
  ok: true,
125
131
  rollback: () => {
126
- // the merge was never pushed, so this drops only local work. Both
127
- // calls are READ: an index.lock from a concurrent run makes the
128
- // reset fail, and announcing a rollback that did not happen is how
129
- // a merge nobody agreed to gets pushed by the next command.
130
- const reset = git(['reset', '--hard', before])
131
- if (reset.code !== 0) {
132
- print(`FAIL: rollback FAILED — '${to}' STILL carries the merge (git reset --hard exited ${reset.code})`)
133
- for (const l of reset.out.split('\n').slice(0, 4)) print(` ${l}`)
134
- print(` fix: git reset --hard ${before} && git checkout ${from}`)
132
+ // other sessions edit and commit in this tree while the gate runs, so
133
+ // no step overwrites a file or drops a commit: detaching on the same
134
+ // commit touches no file, the branch moves back only if it still
135
+ // points at the merge (a compare and swap), and the last checkout
136
+ // stops when an edit is in its way. The release branch is undone
137
+ // first, so a lane's push never publishes the merge. Every exit code
138
+ // is read: a rollback announced but not done gets its merge pushed.
139
+ const head = git(['rev-parse', 'HEAD']).out
140
+ if (head !== merged) {
141
+ print(`FAIL: rollback stopped: a commit landed on '${to}' after the merge (HEAD is ${head.slice(0, 10)}), so '${to}' keeps the merge under it, not pushed. Nothing was moved or overwritten`)
142
+ print(` fix: decide by hand: git log --oneline ${before.slice(0, 10)}..${to} shows what sits on the merge`)
135
143
  return
136
144
  }
137
- if (restore()) print(`ok: rolled '${to}' back and returned to '${from}' — nothing was pushed`)
145
+ const detach = git(['checkout', '--quiet', '--detach'])
146
+ if (detach.code !== 0) {
147
+ print(`FAIL: rollback stopped: cannot detach HEAD (git checkout exited ${detach.code}), '${to}' STILL carries the merge, not pushed. Nothing was overwritten`)
148
+ for (const l of detach.out.split('\n').slice(0, 4)) print(` ${l}`)
149
+ print(` fix: git checkout --detach && git update-ref refs/heads/${to} ${before} ${merged} && git checkout ${from}`)
150
+ return
151
+ }
152
+ const moved = git(['update-ref', '-m', `bump: roll back the merge of ${from}`, `refs/heads/${to}`, before, merged])
153
+ if (moved.code !== 0) {
154
+ git(['checkout', '--quiet', to])
155
+ print(`FAIL: rollback stopped: '${to}' moved during the rollback, so it keeps the merge, not pushed. Nothing was overwritten`)
156
+ for (const l of moved.out.split('\n').slice(0, 4)) print(` ${l}`)
157
+ print(` fix: decide by hand: git log --oneline ${before.slice(0, 10)}..${to}`)
158
+ return
159
+ }
160
+ const back = git(['checkout', '--quiet', from])
161
+ if (back.code !== 0) {
162
+ print(`FAIL: '${to}' is rolled back (nothing pushed), but HEAD is still DETACHED at the merge, because uncommitted edits block the way back to '${from}'. No file was overwritten:`)
163
+ for (const l of back.out.split('\n').slice(0, 8)) print(` ${l}`)
164
+ print(` fix: commit nothing here; let those edits finish, then run git log --oneline ${merged.slice(0, 10)}..HEAD and put any commit it lists on a branch (git branch <name>), then: git checkout ${from}`)
165
+ return
166
+ }
167
+ print(`ok: moved '${to}' back and returned to '${from}', no file overwritten and nothing pushed`)
138
168
  },
139
169
  }
140
170
  }
@@ -253,7 +283,16 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
253
283
  // else in the worktree can enter its tarball or its tag. Refusing on the
254
284
  // rest stalls three agents in one repo for work that cannot affect them.
255
285
  const targets = o.all === true ? onDisk.units : [unitById(onDisk.units, o.unit ?? 'root')!]
256
- const scope = releaseScope(root, onDisk.units, targets)
286
+ const scope = releaseScope(root, onDisk.units, targets, { after: (config.release?.after?.length ?? 0) > 0 })
287
+ // the version commit takes each file it writes WHOLE, and the gate judges
288
+ // HEAD, so a dirty line in one of them would land in the tag ungated
289
+ const writesDirty = (when: string): number | null => {
290
+ const d = dirtyPaths(root, config, scope.writes)
291
+ if (d === '') return null
292
+ print(`FAIL: uncommitted changes in files the version commit writes${when}:\n${d.split('\n').slice(0, 10).join('\n')}`)
293
+ print(' fix: commit them or let their owner finish, then bump again. --allow-dirty does not lift this: the commit would take them into the tag ungated')
294
+ return 1
295
+ }
257
296
 
258
297
  // surfaces the toolkit itself rewrites on gate runs, safe to auto-commit
259
298
  const machineWrittenPaths = (r: string, c: RepoConfig): Set<string> => {
@@ -290,11 +329,13 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
290
329
  print(`note: dirt beyond the machine rows (${paths.filter((p) => !machine.has(p)).join(', ')}), not auto-committing`)
291
330
  }
292
331
  }
332
+ const writing = writesDirty('')
333
+ if (writing != null) return writing
293
334
  const dirty = dirtyPaths(root, config, scope.specs ?? undefined)
294
335
  if (dirty !== '' && o.allowDirty !== true) {
295
336
  print(`FAIL: uncommitted changes inside what this release writes:\n${dirty.split('\n').slice(0, 10).join('\n')}`)
296
337
  print(` fix: commit them, or re-run with --allow-dirty (examined ${scope.describe})`)
297
- if (scope.specs != null) print(' note: dirt elsewhere in the worktree is deliberately ignored, it cannot reach this tarball or this tag')
338
+ if (scope.specs != null) print(' note: dirt elsewhere in the worktree is deliberately ignored, it cannot reach this tarball or this tag, and the gate judges HEAD')
298
339
  return 1
299
340
  }
300
341
  if (dirty !== '') print(`WARN --allow-dirty: releasing with uncommitted changes inside the release scope, the tag will not contain them:\n${dirty.split('\n').slice(0, 6).join('\n')}`)
@@ -302,6 +343,17 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
302
343
 
303
344
  const wantMerge = cur !== branch && o.noMerge !== true && (config.release?.mergeFromBranch ?? true)
304
345
  if (cur !== branch && !wantMerge) { print(`FAIL: releases ship from '${branch}', HEAD is on '${cur}'`); return 1 }
346
+ // a modified tracked file rides along both checkouts and the merge, and on
347
+ // a refusal after the merge it can block the way back, leaving HEAD on the
348
+ // release branch. The rollback never overwrites it, so refuse up front
349
+ if (wantMerge && !rehearsalOnly(o)) {
350
+ const tracked = git(['status', '--porcelain', '--untracked-files=no']).out
351
+ if (tracked !== '') {
352
+ print(`FAIL: '${cur}' merges into '${branch}' first, and these uncommitted edits could block the way back to '${cur}' after a refusal:\n${tracked.split('\n').slice(0, 10).join('\n')}`)
353
+ print(` fix: bump from '${branch}' after merging '${cur}' into it, or once these are committed. --allow-dirty does not lift this`)
354
+ return 1
355
+ }
356
+ }
305
357
  // the merge CHECKS OUT the release branch here, and git refuses to have
306
358
  // one branch checked out in two worktrees. Left to git the run dies on a
307
359
  // raw `fatal: 'main' is already used by worktree at …`, which reads like a
@@ -344,7 +396,7 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
344
396
  process.on('SIGTERM', onInterrupt)
345
397
  }
346
398
  // shut the window: after this the merge is either undone or permanent, and
347
- // an interrupt must never reset --hard over files the operator has to keep
399
+ // an interrupt must never move a branch under files the operator has to keep
348
400
  const closeMergeWindow = (): void => {
349
401
  if (onInterrupt != null) { process.off('SIGINT', onInterrupt); process.off('SIGTERM', onInterrupt); onInterrupt = null }
350
402
  rollback = null
@@ -435,25 +487,12 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
435
487
 
436
488
  for (const s of selected) print(`note: ${s.unit.id} ${s.unit.version} → ${s.version} (${s.kind})`)
437
489
 
438
- // phase 2: ONE gate for the whole repo. The repo is one worktree, so N
439
- // gates cost N times as much and prove the same thing. Frozen, and fatal
440
- // on non-blocking failures when the repo declared requireHealthy.
441
- // releaseUnit then skips it, because bump already proved this exact tree.
442
- if ((await runReleaseGate(root, config, print, { fix: true, units: picked })) !== 0) return fail('ci gate is red on the merged result — fix it, then bump')
443
- // the gate's fix pass can rewrite files. writing a version on top of that
444
- // produces a version commit that excludes the rewrite and a release that
445
- // then refuses on a dirty tree, which is a half-released repo.
446
- // scoped like the preflight, and for the same reason: this exists to catch
447
- // a FIXER rewriting what is about to ship, not to notice that another
448
- // agent saved a file in an unrelated unit while the gate ran
449
- const afterGate = dirtyPaths(root, config, scope.specs ?? undefined)
450
- if (afterGate !== '' && o.allowDirty !== true)
451
- return fail(
452
- `the gate rewrote files this release writes, so what would ship is no longer what was gated:\n${afterGate.split('\n').slice(0, 10).join('\n')}`,
453
- rollback != null
454
- ? 'the rollback below discards them. run `shipkit ci` on your branch, commit what it rewrites, then bump again — or --allow-dirty to ship anyway'
455
- : 'run `shipkit ci`, commit what it rewrites, then bump again — or --allow-dirty to ship anyway',
456
- )
490
+ // phase 2: ONE gate for the whole repo, on HEAD in a clean checkout (the
491
+ // file header owns why HEAD). N gates cost N times as much and prove the
492
+ // same thing. Frozen, and fatal on non-blocking failures when the repo
493
+ // declared requireHealthy. releaseUnit then skips it, because bump
494
+ // already proved this exact commit.
495
+ if ((await runReleaseGate(root, print, { units: picked, allowDirty: o.allowDirty })) !== 0) return fail('ci gate is red on HEAD (the merged result) — fix it, commit, then bump')
457
496
  print('ok: ci gate green')
458
497
 
459
498
  for (const s of selected) {
@@ -464,6 +503,9 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
464
503
  }
465
504
  }
466
505
  if (selected.every((s) => unitPrepublishScripts(s.unit).length === 0)) print('note: no prepublish scripts')
506
+ // the gate took minutes, and a session may have saved one of these meanwhile
507
+ const writingAfter = writesDirty(' (changed while the gate ran)')
508
+ if (writingAfter != null) { rollBack(); return writingAfter }
467
509
 
468
510
  if (rehearsal) {
469
511
  const what = selected.map((s) => `${s.unit.id} ${s.version}`).join(', ')
@@ -486,8 +528,8 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
486
528
  // Partial writes are the half-released state this whole command exists to
487
529
  // prevent, so the write and the commit are one step for the whole selection.
488
530
  //
489
- // from the first write on, a failure NEVER rolls back: `git reset --hard`
490
- // would delete the very files the fix line tells the operator to commit.
531
+ // from the first write on, a failure NEVER rolls back: the written files
532
+ // are the very ones the fix line tells the operator to commit.
491
533
  // What is on disk is reported as it is, interrupts included.
492
534
  closeMergeWindow()
493
535
  const failKeep = (msg: string, fixLine: string): number => { print(`FAIL: ${msg}`); print(` fix: ${fixLine}`); return 1 }
@@ -9,6 +9,7 @@ import { mkdtempSync, rmSync, writeFileSync } from 'fs'
9
9
  import { tmpdir } from 'os'
10
10
  import { join } from 'path'
11
11
  import { runCi } from '../core/run-ci.ts'
12
+ import { withHeadCheckout } from './gate-checkout.ts'
12
13
  import { unitNotes } from './notes.ts'
13
14
  import { deriveRemote, dirtyPaths, git, remoteTagState, tagExistsLocally, type RemoteTagState } from './git-facts.ts'
14
15
  import { releaseScope } from './release-scope.ts'
@@ -16,7 +17,7 @@ import { publishCommand, unitBlockers, type Publisher } from './unit-gate.ts'
16
17
  import { recordPublished } from './published-here.ts'
17
18
  import { publicCleanBlockers } from './public-clean.ts'
18
19
  import { formatUnitError, resolveUnits, unitById, unknownUnit, type ReleaseUnit } from './units.ts'
19
- import type { RepoConfig } from '../repo-config.ts'
20
+ import { loadRepoConfig, type RepoConfig } from '../repo-config.ts'
20
21
  import { nestedIn, nestedRefusal } from '../core/nesting.ts'
21
22
  import { declaredTestUnits, testCheckId } from '../suite/test-units.ts'
22
23
 
@@ -110,52 +111,74 @@ export type ReleaseOpts = {
110
111
  print?: (line: string) => void
111
112
  }
112
113
 
113
- /** the ci gate as the release path runs it: FROZEN (a self-updating rule that
114
- * rewrites package.json between the gate and `npm publish` packs a tree that
115
- * exists in no commit) and, when the repo asked for it, fatal on non-blocking
116
- * check failures too. There is no second health suite: `runCi` runs every
114
+ /** the ci gate as the release path runs it, on the commit that will be
115
+ * tagged: a clean checkout of HEAD (gate-checkout.ts), never the shared
116
+ * working tree, whose uncommitted files no tag contains. FROZEN, with no
117
+ * repair: what is judged is HEAD byte for byte, and a check that still
118
+ * writes a tracked file there refuses, since the gate then judged a tree that
119
+ * exists in no commit. Fatal on non-blocking check failures too when the
120
+ * repo asked for it. There is no second health suite: `runCi` runs every
117
121
  * check, and a check's own `blocking` declaration is the only severity axis.
118
122
  *
119
- * the config travels INTO the gate: classifying severity from one config
120
- * while the rules ran from another downgrades a blocking failure to a warning.
123
+ * the config is HEAD's, loaded in the checkout, and travels INTO the gate:
124
+ * classifying severity from one config while the rules ran from another
125
+ * downgrades a blocking failure to a warning.
121
126
  *
122
127
  * it also runs the FULL test tier, which `shipkit ci` skips while you work. */
123
- export async function runReleaseGate(root: string, config: RepoConfig, print: (l: string) => void, o: { fix?: boolean; units?: ReleaseUnit[] } = {}): Promise<number> {
124
- return await runCi(root, {
125
- fix: o.fix ?? false,
126
- // a check's repair never runs on the release path (runs.onRelease):
127
- // only the mechanical slots (the import fixer) may, when bump asks
128
- fixRules: false,
129
- // the rows declaring onRelease, whatever the tier
130
- release: true,
131
- frozen: true,
132
- status: false,
133
- config,
134
- // THE CAP ON EVERY REMAINING HOLE IN THE KEY. Not a flag, not a config
135
- // field: a release re-measures every unit, so the worst a wrong key
136
- // can ever produce is an agent looking at a stale local green, never a
137
- // stale green that authorised a publish (ledger/ledger.ts rule 4).
138
- ledgerRead: false,
139
- // the FULL tier, always. A release runs on a clean tree with time to
140
- // spare, and the suites the working gate skips (the ones that build
141
- // real repositories) are exactly the ones a publish must not be wrong
142
- // about. Publishing behind a partial suite is a green nobody measured.
143
- tests: 'full',
144
- // a release log is read once and kept as evidence: the tier it asked
145
- // for, the cache reads it refused and the units it left to their own
146
- // release are all part of what it proves
147
- verbose: true,
148
- // a check that cannot block cannot change the outcome, so a release
149
- // never probes the world: publishing a lib does not depend on whether
150
- // a DNS provider answers, and asking spends an API call per publish.
151
- // requireHealthy is the repo saying it wants them fatal, so then they run.
152
- onlyBlockingChecks: config.release?.requireHealthy !== true,
153
- // a sibling unit's suite proves nothing about a sub-unit's tarball: each
154
- // unit's test check runs when THAT unit ships, or when the root does
155
- skipTaskIds: [...(config.release?.skipTasks ?? []), ...otherUnitTests(config, o.units)],
156
- failOnAdvisory: config.release?.requireHealthy === true,
157
- print: (l) => print(` ${l}`),
128
+ export async function runReleaseGate(root: string, print: (l: string) => void, o: { units?: ReleaseUnit[]; allowDirty?: boolean } = {}): Promise<number> {
129
+ const r = await withHeadCheckout(root, async (dir, sha) => {
130
+ print(`note: gating HEAD ${sha.slice(0, 8)} in a clean checkout (${dir}): uncommitted work here is in no tag, so the gate never reads it`)
131
+ let config: RepoConfig
132
+ try { config = await loadRepoConfig(dir, { fresh: true }) } catch (e) {
133
+ print(`FAIL: repo.config.ts at HEAD does not load — ${String(e).slice(0, 200)}`)
134
+ return 1
135
+ }
136
+ const code = await runCi(dir, {
137
+ fix: false,
138
+ fixRules: false,
139
+ // the rows declaring onRelease, whatever the tier
140
+ release: true,
141
+ frozen: true,
142
+ status: false,
143
+ config,
144
+ // THE CAP ON EVERY REMAINING HOLE IN THE KEY. Not a flag, not a config
145
+ // field: a release re-measures every unit, so the worst a wrong key
146
+ // can ever produce is an agent looking at a stale local green, never a
147
+ // stale green that authorised a publish (ledger/ledger.ts rule 4).
148
+ ledgerRead: false,
149
+ // the FULL tier, always. A release runs on a clean tree with time to
150
+ // spare, and the suites the working gate skips (the ones that build
151
+ // real repositories) are exactly the ones a publish must not be wrong
152
+ // about. Publishing behind a partial suite is a green nobody measured.
153
+ tests: 'full',
154
+ // a release log is read once and kept as evidence: the tier it asked
155
+ // for, the cache reads it refused and the units it left to their own
156
+ // release are all part of what it proves
157
+ verbose: true,
158
+ // a check that cannot block cannot change the outcome, so a release
159
+ // never probes the world: publishing a lib does not depend on whether
160
+ // a DNS provider answers, and asking spends an API call per publish.
161
+ // requireHealthy is the repo saying it wants them fatal, so then they run.
162
+ onlyBlockingChecks: config.release?.requireHealthy !== true,
163
+ // a sibling unit's suite proves nothing about a sub-unit's tarball: each
164
+ // unit's test check runs when THAT unit ships, or when the root does
165
+ skipTaskIds: [...(config.release?.skipTasks ?? []), ...otherUnitTests(config, o.units)],
166
+ failOnAdvisory: config.release?.requireHealthy === true,
167
+ print: (l) => print(` ${l}`),
168
+ })
169
+ if (code !== 0) return code
170
+ // frozen is a declaration, not a guarantee: any check may still write
171
+ const rewrote = git(dir, ['status', '--porcelain', '--untracked-files=no']).out
172
+ if (rewrote === '') return 0
173
+ const head = rewrote.split('\n').slice(0, 10).join('\n')
174
+ if (o.allowDirty === true) { print(`WARN --allow-dirty: a check rewrote tracked files during the gate, so it judged a tree that is not HEAD:\n${head}`); return 0 }
175
+ print(`FAIL: a check rewrote tracked files during the gate, so it judged a tree that is not HEAD:\n${head}`)
176
+ print(' fix: run `shipkit ci`, commit what it rewrites, then release again (--allow-dirty ships anyway)')
177
+ return 1
158
178
  })
179
+ if (typeof r === 'number') return r
180
+ print(`FAIL: ${r.error}`)
181
+ return 1
159
182
  }
160
183
 
161
184
  /** the test checks of every sub-unit this release does not ship. No list
@@ -223,7 +246,7 @@ export async function releaseUnit(root: string, config: RepoConfig, unit: Releas
223
246
  // the sibling units matter to the SCOPE: a version write rewrites the
224
247
  // rvlib range in every dependent's package.json, so those paths are inside
225
248
  // this release even though they are outside this unit
226
- const scope = releaseScope(root, resolveUnits(root, config).units, [unit])
249
+ const scope = releaseScope(root, resolveUnits(root, config).units, [unit], { after: unit.rel === '' && (rc.after?.length ?? 0) > 0 })
227
250
  const dirty = dirtyPaths(root, config, scope.specs ?? undefined)
228
251
  if (dirty !== '' && o.allowDirty !== true) {
229
252
  blockers.push(`uncommitted changes in ${scope.describe} (--allow-dirty overrides):\n${dirty.split('\n').slice(0, 10).join('\n')}`)
@@ -284,16 +307,7 @@ export async function releaseUnit(root: string, config: RepoConfig, unit: Releas
284
307
  if (o.skipGate === true)
285
308
  print(o.skipGateReason != null ? `ok: ci gate ${o.skipGateReason}` : 'WARN ci gate SKIPPED by --skip-gate — publishing unverified')
286
309
  else {
287
- if ((await runReleaseGate(root, config, print, { units: [unit] })) !== 0) { print('FAIL: ci gate is red — fix it, commit, then release'); return 1 }
288
- // frozen is a declaration, not a guarantee: any check may still write.
289
- // npm packs the DIRECTORY, so a rewrite here would publish a tarball
290
- // that exists in no commit while the tag describes another tree.
291
- const afterGate = dirtyPaths(root, config)
292
- if (afterGate !== '' && o.allowDirty !== true) {
293
- print(`FAIL: the gate rewrote files, so the tree no longer matches what the tag would describe:\n${afterGate.split('\n').slice(0, 10).join('\n')}`)
294
- print(' fix: commit those changes, then run release again')
295
- return 1
296
- }
310
+ if ((await runReleaseGate(root, print, { units: [unit], allowDirty: o.allowDirty })) !== 0) { print('FAIL: ci gate is red on HEAD — fix it, commit, then release'); return 1 }
297
311
  print('ok: ci gate green')
298
312
  }
299
313
 
@@ -4,8 +4,9 @@
4
4
  import { itemOfRef, storeDir } from '../review/store.ts'
5
5
  import { publicProblems } from '../social/unit.ts'
6
6
  import { commitPaths } from '../social/writes.ts'
7
- import { cardParts, versionsOf } from './from-card.ts'
8
- import { changesOf, emptyRelease, NEXT, type Change, type ReleaseKind } from './model.ts'
7
+ import { isPostRating, POST_RATINGS, type PostRating } from '../identities/rating.ts'
8
+ import { cardParts, versionsOf, withShot } from './from-card.ts'
9
+ import { CHANGE_WEIGHTS, changesOf, emptyRelease, isChangeWeight, isClip, NEXT, type Change, type ChangeWeight, type ReleaseKind, type Shot } from './model.ts'
9
10
  import { keepPicture } from './pictures.ts'
10
11
  import { addChange, readRelease, undeclaredReleases, writeRelease } from './store.ts'
11
12
 
@@ -15,10 +16,16 @@ export interface AddAsk {
15
16
  text?: string
16
17
  bullets?: string[]
17
18
  image?: string
19
+ /** a still of what it looked like before, the tab beside its picture */
20
+ before?: string
21
+ /** the rating of the shot it writes; with no new picture, of the change's one unrated shot */
22
+ rating?: string
18
23
  card?: string
19
24
  commit?: string
20
25
  kind?: string
21
26
  heading?: string
27
+ /** major, feature or improvement; left out, the change keeps the weight it had */
28
+ weight?: string
22
29
  }
23
30
 
24
31
  const KINDS: readonly string[] = ['major', 'minor', 'patch']
@@ -31,7 +38,12 @@ async function guarded(root: string, what: string, texts: string[]): Promise<voi
31
38
  /** next.md written with the ask: its kind and title, and one change; the file written */
32
39
  export async function addByHand(root: string, a: AddAsk): Promise<string> {
33
40
  if (a.kind !== undefined && !KINDS.includes(a.kind)) throw new Error(`--kind ${a.kind}: major, minor or patch`)
41
+ if (a.rating !== undefined && !isPostRating(a.rating)) throw new Error(`--rating ${a.rating}: one of ${POST_RATINGS.join(', ')}`)
42
+ const rating = (a.rating as PostRating | undefined) ?? null
43
+ const weight: ChangeWeight | undefined = a.weight === undefined || isChangeWeight(a.weight) ? a.weight : undefined
44
+ if (a.weight !== undefined && weight === undefined) throw new Error(`--weight ${a.weight}: one of ${CHANGE_WEIGHTS.join(', ')}`)
34
45
  const change = a.category !== undefined || a.title !== undefined || a.card !== undefined
46
+ if (a.weight !== undefined && !change) throw new Error('--weight weighs a change: name it with --card, or its category and its title')
35
47
  if (!change && a.kind === undefined && a.heading === undefined) throw new Error('nothing to write: a change (a category and a title, or --card), or --kind, or --release-title')
36
48
  const why = await undeclaredReleases(root)
37
49
  if (why) throw new Error(why)
@@ -54,11 +66,32 @@ export async function addByHand(root: string, a: AddAsk): Promise<string> {
54
66
  // the change of the same card, else of the same title: what the hand does not give, the card included, is kept
55
67
  const all = next ? changesOf(next) : []
56
68
  const had = (given != null ? all.find((ch) => ch.card === given) : undefined) ?? all.find((ch) => ch.title === title)
57
- const c: Change = { title, text: a.text ?? had?.text ?? '', bullets: a.bullets ?? had?.bullets ?? [], picture: had?.picture ?? null, card: given ?? had?.card ?? null, commit: a.commit ?? x?.item.commit ?? had?.commit ?? null }
69
+ const c: Change = { title, text: a.text ?? had?.text ?? '', bullets: a.bullets ?? had?.bullets ?? [], shots: had?.shots ?? [], card: given ?? had?.card ?? null, commit: a.commit ?? x?.item.commit ?? had?.commit ?? null, weight: weight ?? had?.weight ?? null }
70
+ if (a.before !== undefined && isClip(a.before)) throw new Error(`--before ${a.before}: a before is a still (png, jpg, webp), not a clip`)
71
+ // the shot a --before or a --rating alone lands on: the change's one unrated shot, else its one shot
72
+ const unrated = c.shots.filter((s) => s.picture.rating == null)
73
+ const target = (): Shot => {
74
+ const s = unrated.length === 1 ? unrated[0] : c.shots.length === 1 ? c.shots[0] : undefined
75
+ if (!s) throw new Error(`"${c.title}" has ${c.shots.length === 0 ? 'no picture' : `${c.shots.length} shots`}: give --image with it`)
76
+ return s
77
+ }
58
78
  // the words first: a refused change uploads no picture
59
79
  await guarded(root, `"${c.title}"`, [category, c.title, c.text, ...c.bullets])
60
- if (a.image !== undefined) c.picture = { url: await keepPicture(root, a.image), alt: c.title }
61
- else if (x) c.picture = (await cardParts(root, x, c.title)).picture ?? c.picture
80
+ // a new picture takes the place of the shot of its rating, its old before gone unless the hand gives its own
81
+ let wrote: Shot | null = null
82
+ if (a.image !== undefined) wrote = { picture: { url: await keepPicture(root, a.image), alt: c.title, rating }, before: null }
83
+ else if (x) wrote = (await cardParts(root, x, c.title, rating)).shot
84
+ if (wrote) c.shots = withShot(c.shots, wrote)
85
+ else if (rating != null) {
86
+ const s = target()
87
+ wrote = { picture: { ...s.picture, rating }, before: s.before && { ...s.before, rating } }
88
+ c.shots = c.shots.map((t) => (t === s ? wrote! : t))
89
+ }
90
+ if (a.before !== undefined) {
91
+ const s = wrote ?? target()
92
+ const next: Shot = { picture: s.picture, before: { url: await keepPicture(root, a.before), alt: c.title, rating: rating ?? s.picture.rating } }
93
+ c.shots = c.shots.map((t) => (t.picture.url === s.picture.url ? next : t))
94
+ }
62
95
  file = addChange(root, category, c).file
63
96
  }
64
97
  commitPaths([file!], `releases: next.md takes ${a.title ?? a.card ?? 'its heading'}`)
@@ -0,0 +1,31 @@
1
+ // whether a pair's before earns its tab (wiki tools/shipkit/units.md, The release files): both stills read at a
2
+ // card's width in grey. The thresholds were measured on 21 real card pairs: an all black before spreads 0, the
3
+ // pairs that look the same differ 0.4 to 9.5 on average, the real changes 28 to 72
4
+ import sharp from 'sharp'
5
+
6
+ /** the width both stills are read at: a release card's, where a small change disappears */
7
+ const WIDTH = 320
8
+ /** under this spread of its grey values (of 255) a before is one flat colour: an all black frame */
9
+ export const BLANK_SPREAD = 4
10
+ /** under this mean difference from the after (of 255) a before shows nothing the after does not */
11
+ export const SAME_DIFF = 16
12
+
13
+ const grey = async (file: string, w: number, h: number): Promise<Buffer> => sharp(file).removeAlpha().resize(w, h, { fit: 'fill' }).greyscale().raw().toBuffer()
14
+
15
+ /** why a before stays out of the release: `blank`, `same`, or null when its tab shows a real difference */
16
+ export async function idleBefore(before: string, after: string): Promise<'blank' | 'same' | null> {
17
+ const m = await sharp(after).metadata()
18
+ const h = Math.max(1, Math.round((WIDTH * (m.height ?? WIDTH)) / Math.max(1, m.width ?? WIDTH)))
19
+ const [b, a] = await Promise.all([grey(before, WIDTH, h), grey(after, WIDTH, h)])
20
+ let sum = 0
21
+ for (const v of b) sum += v
22
+ const mean = sum / b.length
23
+ let spread = 0
24
+ let diff = 0
25
+ for (let i = 0; i < b.length; i++) {
26
+ spread += (b[i]! - mean) ** 2
27
+ diff += Math.abs(b[i]! - a[i]!)
28
+ }
29
+ if (Math.sqrt(spread / b.length) < BLANK_SPREAD) return 'blank'
30
+ return diff / b.length < SAME_DIFF ? 'same' : null
31
+ }