rvlib-shipkit 2.23.0 → 2.25.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 (150) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/live.ts +153 -0
  4. package/src/agent-time/render.ts +28 -14
  5. package/src/agent-time/report.ts +46 -25
  6. package/src/agent-time/store.ts +30 -10
  7. package/src/agent-time/timeline.ts +43 -15
  8. package/src/annex/offload.ts +16 -7
  9. package/src/asks/asks-queue.ts +32 -11
  10. package/src/check.ts +3 -1
  11. package/src/checks/SK004-gitignore-policy.check.ts +32 -11
  12. package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
  13. package/src/checks/SK033-global-contribution.check.ts +1 -1
  14. package/src/checks/SK036-draft-media-size.check.ts +1 -1
  15. package/src/checks/SK040-release-words.check.ts +1 -1
  16. package/src/checks/SK042-post-kinds.check.ts +1 -1
  17. package/src/checks/SK044-behind-upstream.check.ts +38 -0
  18. package/src/cli/cmd_Annex.ts +12 -7
  19. package/src/cli/cmd_Asks.ts +2 -0
  20. package/src/cli/cmd_Assets.ts +5 -5
  21. package/src/cli/cmd_Backup.ts +16 -8
  22. package/src/cli/cmd_Bump.ts +1 -0
  23. package/src/cli/cmd_Capacity.ts +30 -0
  24. package/src/cli/cmd_Check.ts +1 -0
  25. package/src/cli/cmd_Checks.ts +13 -1
  26. package/src/cli/cmd_Ci.ts +3 -2
  27. package/src/cli/cmd_Commands.ts +61 -16
  28. package/src/cli/cmd_ConfigKeys.ts +17 -0
  29. package/src/cli/cmd_Home.ts +1 -30
  30. package/src/cli/cmd_Hooks.ts +1 -0
  31. package/src/cli/cmd_Keys.ts +4 -1
  32. package/src/cli/cmd_Lanes.ts +35 -0
  33. package/src/cli/cmd_Mv.ts +7 -7
  34. package/src/cli/cmd_Rec.ts +22 -7
  35. package/src/cli/cmd_Reflect.ts +1 -0
  36. package/src/cli/cmd_Releases.ts +1 -0
  37. package/src/cli/cmd_Review.ts +200 -49
  38. package/src/cli/cmd_Secret.ts +41 -2
  39. package/src/cli/cmd_Shot.ts +16 -4
  40. package/src/cli/cmd_Status.ts +7 -5
  41. package/src/cli/cmd_Time.ts +13 -5
  42. package/src/cli/cmd_Tmp.ts +82 -0
  43. package/src/cli/cmd_Veille.ts +10 -6
  44. package/src/cli/cmd_Wiki.ts +1 -0
  45. package/src/cli/family-help.ts +136 -0
  46. package/src/cli/family-pages.ts +0 -19
  47. package/src/cli/kit/calls.ts +35 -0
  48. package/src/cli/kit/project-cli.ts +2 -12
  49. package/src/cli/registry.ts +52 -7
  50. package/src/cli.ts +8 -4
  51. package/src/collections/pings.ts +1 -1
  52. package/src/core/capacity.ts +127 -0
  53. package/src/core/check-runner.ts +91 -16
  54. package/src/core/floor-resolve.ts +6 -2
  55. package/src/core/floor.ts +6 -2
  56. package/src/core/history-files.ts +18 -0
  57. package/src/core/jobs.ts +35 -16
  58. package/src/core/layout.ts +2 -2
  59. package/src/core/motherhome.ts +67 -9
  60. package/src/core/nearest.ts +16 -0
  61. package/src/core/remove-tree.ts +19 -0
  62. package/src/core/runs.ts +12 -3
  63. package/src/core/slots.ts +49 -12
  64. package/src/core/throwaway-worktree.ts +22 -4
  65. package/src/core/trace-audit.ts +21 -5
  66. package/src/drill/run.ts +5 -2
  67. package/src/home/daemon-jobs.ts +41 -4
  68. package/src/home/gui-app/ShipkitGui.swift +1 -0
  69. package/src/home/home-launchd.ts +11 -3
  70. package/src/home/home-routes.ts +11 -4
  71. package/src/home/machine-host.ts +65 -0
  72. package/src/home/machine-stores.ts +19 -17
  73. package/src/home/machine-temp.ts +485 -0
  74. package/src/home/other-macs.ts +74 -0
  75. package/src/home/run-daemon.ts +10 -2
  76. package/src/home/serve-web.ts +2 -2
  77. package/src/home/via-hub.ts +6 -1
  78. package/src/init-repo.ts +7 -3
  79. package/src/ledger/gate-checks.ts +3 -2
  80. package/src/ledger/git-key.ts +25 -4
  81. package/src/ledger/git-scan.ts +10 -0
  82. package/src/ledger/ledger.ts +6 -0
  83. package/src/ledger/store.ts +6 -0
  84. package/src/media-store/backup/daemon.ts +92 -20
  85. package/src/media-store/backup/keys.ts +21 -6
  86. package/src/media-store/backup/manifest.ts +52 -11
  87. package/src/media-store/backup/restore.ts +17 -10
  88. package/src/media-store/backup/run.ts +26 -17
  89. package/src/media-store/backup/sources.ts +168 -22
  90. package/src/media-store/backup/watch.ts +106 -0
  91. package/src/media-store/daemon.ts +36 -8
  92. package/src/media-store/hand.ts +3 -1
  93. package/src/mv/mv-md.ts +167 -56
  94. package/src/pb/run-pb.ts +2 -10
  95. package/src/plan/repo-source.ts +25 -14
  96. package/src/recordings/model.ts +1 -1
  97. package/src/reflect/transcript.ts +56 -11
  98. package/src/release/run-bump.ts +3 -2
  99. package/src/release/run-release.ts +12 -4
  100. package/src/releases/from-card.ts +45 -3
  101. package/src/releases/model.ts +6 -0
  102. package/src/releases/store.ts +8 -1
  103. package/src/repo-config.ts +5 -3
  104. package/src/review/cells.ts +26 -4
  105. package/src/review/format.ts +34 -10
  106. package/src/review/media-kind.ts +14 -11
  107. package/src/review/media-read.ts +6 -5
  108. package/src/review/model.ts +85 -4
  109. package/src/review/paste.ts +2 -1
  110. package/src/review/previews.ts +123 -36
  111. package/src/review/routes.ts +29 -18
  112. package/src/review/store.ts +89 -19
  113. package/src/review/threads.ts +7 -5
  114. package/src/review/trailer-model.ts +2 -2
  115. package/src/secrets/copy.ts +110 -0
  116. package/src/secrets/list.ts +17 -7
  117. package/src/serve/hub-app/home-strip.css +5 -0
  118. package/src/serve/hub-app/home-strip.tsx +18 -0
  119. package/src/serve/hub-app/hub-app.tsx +2 -1
  120. package/src/serve/hub-app/hub.css +14 -0
  121. package/src/serve/hub-app/inbox.css +1 -0
  122. package/src/serve/hub-app/pull-refresh.tsx +88 -0
  123. package/src/serve/hub-app/review/review-cells.tsx +52 -13
  124. package/src/serve/hub-app/review/review-list.tsx +6 -1
  125. package/src/serve/hub-app/review/review-st.ts +6 -5
  126. package/src/serve/hub-app/review/review-thread.tsx +3 -1
  127. package/src/serve/hub-app/review/review-views.tsx +18 -11
  128. package/src/serve/hub-app/review/thread-st.ts +82 -14
  129. package/src/serve/hub-app/review.css +15 -2
  130. package/src/serve/hub-runtime.ts +2 -1
  131. package/src/serve/run-serve.ts +4 -2
  132. package/src/serve/serve-hub.ts +9 -2
  133. package/src/shot/client.ts +4 -2
  134. package/src/shot/serve-shot.ts +71 -2
  135. package/src/shot/shooter.ts +65 -11
  136. package/src/shot/shot-ask.ts +32 -9
  137. package/src/suite/child-tools.ts +45 -0
  138. package/src/suite/judge-suites.ts +10 -22
  139. package/src/suite/select.ts +95 -9
  140. package/src/suite/suite-cli.ts +38 -14
  141. package/src/suite/suite-cores.ts +68 -0
  142. package/src/suite/suite-reads-preload.ts +8 -6
  143. package/src/suite/test-units.ts +31 -12
  144. package/src/trailer/graph.ts +2 -1
  145. package/src/ts/config.ts +21 -0
  146. package/src/ts/rename.ts +37 -13
  147. package/src/ts/workspaces.ts +45 -0
  148. package/src/wiki/run-wiki.ts +7 -2
  149. package/src/wiki/scan-md.ts +2 -1
  150. package/src/home/claude-temp.ts +0 -139
package/src/mv/mv-md.ts CHANGED
@@ -6,13 +6,15 @@
6
6
  // script it runs after the moves (repo-specific re-stamps). TS module moves
7
7
  // are a different concern (a TS-aware renamer owns import graphs).
8
8
  import { execSync } from 'child_process'
9
+ import { isHistoryFile } from '../core/history-files.ts'
9
10
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs'
11
+ import { homedir } from 'os'
10
12
  import { basename, dirname, join, relative } from 'path'
11
13
  import { isVendored } from '../core/vendored.ts'
12
14
  import { vendoredAround } from '../core/vendored-read.ts'
13
15
 
14
16
  export type MvIo = { print: (l: string) => void; printErr: (l: string) => void }
15
- export type MvOpts = { write?: boolean; commit?: boolean; /** run the repo's `mv:after` script (a batch runs it once, at the end) */ after?: boolean }
17
+ export type MvOpts = { write?: boolean; commit?: boolean; /** run the repo's `mv:after` script (a batch runs it once, at the end) */ after?: boolean; /** rewrite the plans, changelogs and journals too: by default they stay as written */ history?: boolean }
16
18
 
17
19
  const sh = (cmd: string, cwd: string): string => execSync(cmd, { cwd }).toString()
18
20
 
@@ -32,15 +34,8 @@ const dirOf = (p: string): string => { const d = dirname(p); return d === '.' ?
32
34
  // were confined to one directory. A move between directories invalidates both
33
35
  // directions at once: the links the page carries out, and the links other
34
36
  // pages aim at it. This pass runs FIRST so the token sweep finds those already
35
- // rewritten.
36
- //
37
- // KNOWN RESIDUAL, do not read this as closed: the token sweep below is a
38
- // substring replace, so a path that merely ENDS with the old path
39
- // ('other/doc/bun.md' referenced as '../doc/bun.md' from a file that is not
40
- // moving) is still rewritten to a path that does not exist. This pass declines
41
- // that case on purpose, because neither the target nor the carrier moved.
42
- // Closing it means teaching the sweep which character spans were already
43
- // resolved here.
37
+ // rewritten. A path that merely ENDS with the old path is the sweep's to judge
38
+ // (`namesMoved`), never this pass's.
44
39
  //
45
40
  // A target must resolve to a FILE. Directories are excluded because the arrow
46
41
  // form appears in prose ('→ shipkit ci'), and a bare word that happens to name
@@ -55,7 +50,14 @@ const REF_FORMS: { re: RegExp; group: number }[] = [
55
50
  /** rewrite every relative reference in one file so it still points at the same
56
51
  * thing after the move. `moves` is every path this operation relocates; a ref
57
52
  * that names none of them still moves when the FILE moved under it. */
58
- export function retargetRelativeRefs(root: string, text: string, fromDir: string, toDir: string, moves: Map<string, string>): string {
53
+ export function retargetRelativeRefs(
54
+ root: string,
55
+ text: string,
56
+ fromDir: string,
57
+ toDir: string,
58
+ moves: Map<string, string>,
59
+ isFileAt: (rel: string) => boolean = (rel) => isFile(join(root, rel)),
60
+ ): string {
59
61
  const fix = (target: string): string | null => {
60
62
  // a url, an absolute path and a bare anchor are not ours to resolve
61
63
  if (target === '' || /^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith('/') || target.startsWith('#')) return null
@@ -71,7 +73,7 @@ export function retargetRelativeRefs(root: string, text: string, fromDir: string
71
73
  // nothing moved for this reference: neither its target nor its carrier
72
74
  if (to == null && fromDir === toDir) return null
73
75
  // a target that is not a real FILE is prose, not a link
74
- if (to == null && !isFile(join(root, from))) return null
76
+ if (to == null && !isFileAt(from)) return null
75
77
  const next = posix(relative(toDir, to ?? from))
76
78
  if (next === '') return null
77
79
  return `${path.startsWith('./') && !next.startsWith('.') ? `./${next}` : next}${anchor}`
@@ -91,11 +93,100 @@ export function retargetRelativeRefs(root: string, text: string, fromDir: string
91
93
  return out
92
94
  }
93
95
 
94
- export function movePage(root: string, oldRel: string, newRel: string, io: MvIo, o: MvOpts = {}): number {
96
+ /** whether the token at `at` names the moved path `full`, judged by the path characters right before it: none, a
97
+ * relative path that resolves to it from the carrier's folder, the repo's own absolute root, or a url's path. Any
98
+ * other longer path (`packages/p/agent/index.md` for `agent/index.md`) names another file */
99
+ export function namesMoved(text: string, at: number, tok: string, full: string, carrierDir: string, root: string): boolean {
100
+ let s = at
101
+ while (s > 0 && /[\w.\/~-]/.test(text[s - 1]!)) s--
102
+ const p = text.slice(s, at)
103
+ // `${root}/agent/x.md`: the folder is an expression, read as the root
104
+ if (p === '' || p.startsWith('//') || (p === '/' && s > 0 && /[})]/.test(text[s - 1]!))) return true
105
+ if (p.startsWith('/') || p.startsWith('~/')) return (p.startsWith('~/') ? join(homedir(), p.slice(2)) : p).replace(/\/+$/, '') === root.replace(/\/+$/, '')
106
+ return posix(join(carrierDir, p + tok)) === full
107
+ }
108
+
109
+ /** where a move reads and writes. Applied, it is the disk and git; a dry run is
110
+ * an overlay on them, so the dry run walks the very same steps, and a map's
111
+ * next line sees what the line before it moved */
112
+ class MvTree {
113
+ private readonly text = new Map<string, string>()
114
+ private readonly gone = new Set<string>()
115
+ private list: string[] | null = null
116
+ constructor(readonly root: string, readonly live: boolean) {}
117
+
118
+ private real = (rel: string): string => join(this.root, rel)
119
+ private isGone = (rel: string): boolean => [...this.gone].some((g) => rel === g || rel.startsWith(`${g}/`))
120
+ /** the files the sweep reads: tracked, never a binary, and third party
121
+ * code keeps its own references byte for byte */
122
+ files(): string[] {
123
+ if (this.live || this.list == null) {
124
+ const repo = vendoredAround(this.root)
125
+ const vendored = (repo?.dirs ?? []).map((d) => posix(relative(this.root, join(repo!.root, d))))
126
+ this.list = sh('git ls-files', this.root).split('\n').filter(Boolean)
127
+ .filter((f) => !/\.(png|jpe?g|gif|webp|ico|woff2?|ttf|zip|gz|lockb|lock)$/i.test(f) && !isVendored(f, vendored))
128
+ }
129
+ return this.list
130
+ }
131
+ isFile = (rel: string): boolean => this.text.has(rel) || (!this.isGone(rel) && isFile(this.real(rel)))
132
+ exists = (rel: string): boolean =>
133
+ this.isFile(rel) || (!this.live && this.files().some((f) => f.startsWith(`${rel}/`))) || (!this.isGone(rel) && existsSync(this.real(rel)))
134
+ read = (rel: string): string => this.text.get(rel) ?? readFileSync(this.real(rel), 'utf8')
135
+ /** false for a binary (a NUL in its first 8 KB, git's own test) and for a text without `needle`: no decode, no
136
+ * regex, ten times faster over a repo's tracked files */
137
+ holds(rel: string, needle: string): boolean {
138
+ const t = this.text.get(rel)
139
+ if (t !== undefined) return t.includes(needle)
140
+ const b = readFileSync(this.real(rel))
141
+ return !b.subarray(0, 8192).includes(0) && b.includes(needle)
142
+ }
143
+ write(rel: string, text: string): void {
144
+ if (this.live) writeFileSync(this.real(rel), text)
145
+ else this.text.set(rel, text)
146
+ }
147
+ /** git mv, a file or a folder; the destination's folder is made first */
148
+ mv(from: string, to: string): void {
149
+ if (this.live) {
150
+ mkdirSync(this.real(dirOf(to)), { recursive: true })
151
+ sh(`git mv ${JSON.stringify(from)} ${JSON.stringify(to)}`, this.root)
152
+ return
153
+ }
154
+ const files = this.files()
155
+ files.forEach((f, i) => {
156
+ if (f !== from && !f.startsWith(`${from}/`)) return
157
+ const next = `${to}${f.slice(from.length)}`
158
+ this.text.set(next, this.read(f))
159
+ this.text.delete(f)
160
+ files[i] = next
161
+ })
162
+ this.gone.add(from)
163
+ }
164
+ /** a leftover folder with nothing but Finder's litter */
165
+ dropEmptyDir(rel: string): void {
166
+ if (this.live) rmSync(this.real(rel), { recursive: true })
167
+ else this.gone.add(rel)
168
+ }
169
+ }
170
+
171
+ /** the first line a rewrite changed, as it reads after it, cut around the change */
172
+ const firstChanged = (before: string, after: string): string => {
173
+ const a = before.split('\n')
174
+ const b = after.split('\n')
175
+ const i = b.findIndex((l, k) => l !== a[k])
176
+ const line = b[i] ?? ''
177
+ const old = a[i] ?? ''
178
+ let at = 0
179
+ while (at < line.length && line[at] === old[at]) at++
180
+ const from = Math.max(0, at - 50)
181
+ const cut = line.slice(from, from + 160).trim()
182
+ return `${from > 0 ? '...' : ''}${cut}${from + 160 < line.length ? '...' : ''}`
183
+ }
184
+
185
+ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo, o: MvOpts = {}, tree = new MvTree(root, o.write === true || o.commit === true)): number {
95
186
  const die = (m: string): number => { io.printErr(`FAIL: ${m}`); return 1 }
96
187
  if (!oldRel.endsWith('.md') || !newRel.endsWith('.md')) return die('both paths must be .md (TS moves are not this tool\'s job)')
97
- if (!existsSync(join(root, oldRel))) return die(`${oldRel} does not exist`)
98
- if (existsSync(join(root, newRel))) return die(`${newRel} already exists`)
188
+ if (!tree.exists(oldRel)) return die(`${oldRel} does not exist`)
189
+ if (tree.exists(newRel)) return die(`${newRel} already exists`)
99
190
  // git mv puts a source directory INSIDE an existing destination instead of
100
191
  // refusing, so the probe lands one level too deep and the run still says
101
192
  // ok. Unreachable while every move was a same-dir rename, likely the
@@ -104,24 +195,27 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
104
195
  // asset dir BECOMES that folder instead of sitting beside the page
105
196
  const indexForm = basename(newRel) === 'index.md' && basename(oldRel) !== 'index.md'
106
197
  const oldBase = oldRel.slice(0, -3) // full path sans .md, the sibling dir
107
- const newBase = indexForm ? dirOf(newRel) : newRel.slice(0, -3)
108
- // in place: the page moves into its own asset dir, which already is the topic folder
109
- const inPlace = indexForm && newBase === oldBase
110
- if (indexForm && !inPlace && existsSync(join(root, newBase))) return die(`${newBase}/ already exists: a topic folder is created by its move, never merged into`)
111
- if (!indexForm && existsSync(join(root, oldBase)) && existsSync(join(root, newBase)))
198
+ // in place: the page moves into its own asset dir (`x.md` to `x/index.md` or `x/x.md`), which stays the topic folder
199
+ const inPlace = dirOf(newRel) === oldBase
200
+ const newBase = indexForm || inPlace ? dirOf(newRel) : newRel.slice(0, -3)
201
+ // git cannot move a folder into itself, and the sweep would already have run
202
+ if (!inPlace && newRel.startsWith(`${oldBase}/`) && tree.exists(oldBase))
203
+ return die(`${newRel} sits deeper inside ${oldBase}/, the page's own folder, which git cannot move into itself. Two steps: sk mv ${oldRel} ${oldBase}/${basename(newRel)} --write, then sk mv ${oldBase}/${basename(newRel)} ${newRel} --write`)
204
+ if (indexForm && !inPlace && tree.exists(newBase)) return die(`${newBase}/ already exists: a topic folder is created by its move, never merged into`)
205
+ if (!indexForm && !inPlace && tree.exists(oldBase) && tree.exists(newBase))
112
206
  return die(`${newBase}/ already exists, and ${oldBase}/ would be nested inside it rather than become it: move or merge it by hand first`)
113
207
 
114
- const write = o.write === true || o.commit === true
208
+ const write = tree.live
115
209
  const oldName = basename(oldRel, '.md')
116
210
  const newName = basename(newBase)
117
211
  // docs-root-relative id: refs inside a wiki usually omit the top dir
118
- // (`build/state`, not `wiki/build/state`) — sweep both forms
212
+ // (`build/state`, not `wiki/build/state`), so the sweep takes both forms
119
213
  const tail = (p: string): string | null => { const seg = p.split('/'); return seg.length >= 3 ? seg.slice(1).join('/') : null }
120
214
  const oldId = tail(oldBase)
215
+ const top = oldBase.split('/')[0]!
121
216
  const newId = tail(newBase)
122
217
  const newPageId = tail(newRel.slice(0, -3))
123
218
 
124
- // longest-first so `wiki/x/state.md` beats `x/state` beats bare tokens
125
219
  const pairs: [string, string][] = [
126
220
  [`${oldBase}.md`, newRel],
127
221
  ...(oldId != null ? [[`${oldId}.md`, `${newPageId}.md`] as [string, string]] : []),
@@ -136,14 +230,21 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
136
230
  [oldBase, newBase],
137
231
  ...(oldId != null ? [[oldId, newId!] as [string, string]] : []),
138
232
  ]
139
- const bound = (t: string): RegExp =>
140
- new RegExp('(?<![\\w-])' + t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + (/[/.]$/.test(t) || t.endsWith('.ts') ? '' : '(?![\\w-])'), 'g')
233
+ // ONE pass over the text, longest token first at each place: a path one
234
+ // pair writes is never read by the next (`a.md` into `a/a.md` wrote
235
+ // `a/a/a/a.md` when the pairs ran one after the other)
236
+ const to = new Map<string, string>()
237
+ for (const [oldTok, newTok] of pairs) if (!to.has(oldTok)) to.set(oldTok, newTok)
238
+ const sweep = new RegExp(
239
+ '(?<![\\w-])(?:' +
240
+ [...to.keys()].sort((a, b) => b.length - a.length)
241
+ .map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + (/[/.]$/.test(t) || t.endsWith('.ts') ? '' : '(?![\\w-])'))
242
+ .join('|') +
243
+ ')',
244
+ 'g',
245
+ )
141
246
 
142
- // third party code keeps its own references, byte for byte
143
- const repo = vendoredAround(root)
144
- const vendored = (repo?.dirs ?? []).map((d) => posix(relative(root, join(repo!.root, d))))
145
- const tracked = sh('git ls-files', root).split('\n').filter(Boolean)
146
- .filter((f) => !/\.(png|jpe?g|gif|webp|ico|woff2?|ttf|zip|gz|lockb|lock)$/i.test(f) && !isVendored(f, vendored))
247
+ const tracked = tree.files()
147
248
 
148
249
  // every path this move relocates, old → new. The sibling dir carries its
149
250
  // whole subtree, and the probe is renamed after the page, so its own entry
@@ -156,47 +257,57 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
156
257
  for (const f of tracked) if (f.startsWith(`${oldBase}/`)) moves.set(f, `${newBase}${f.slice(oldBase.length)}`)
157
258
  for (const sfx of SIBLING_SUFFIXES) {
158
259
  const probe = `${oldBase}/${oldName}${sfx}`
159
- if (existsSync(join(root, probe))) moves.set(probe, `${newBase}/${newName}${sfx}`)
260
+ if (tree.exists(probe)) moves.set(probe, `${newBase}/${newName}${sfx}`)
160
261
  }
161
262
  }
162
263
 
163
264
  let touched = 0
164
- for (const f of tracked) {
165
- const p = join(root, f)
265
+ let left = 0
266
+ for (const f of [...tracked]) {
166
267
  // a submodule is one ls-files entry and a directory: nothing to read
167
- if (!isFile(p)) continue
168
- const before = readFileSync(p, 'utf8')
169
- let after = retargetRelativeRefs(root, before, dirOf(f), dirOf(moves.get(f) ?? f), moves)
170
- for (const [oldTok, newTok] of pairs) after = after.replace(bound(oldTok), newTok)
268
+ if (!tree.isFile(f)) continue
269
+ // every token and every relative path that reaches a moved file names the page's stem
270
+ if (!moves.has(f) && !tree.holds(f, oldName)) continue
271
+ const before = tree.read(f)
272
+ let refs = 0
273
+ const linked = retargetRelativeRefs(root, before, dirOf(f), dirOf(moves.get(f) ?? f), moves, tree.isFile)
274
+ if (linked !== before) { const lines = before.split('\n'); refs += linked.split('\n').filter((l, i) => l !== lines[i]).length }
275
+ const after = linked.replace(sweep, (m: string, at: number) => {
276
+ // a docs-root-relative id names the path under the repo's top folder
277
+ if (!namesMoved(linked, at, m, m.startsWith(oldBase) ? m : `${top}/${m}`, dirOf(f), root)) return m
278
+ const next = to.get(m)!
279
+ if (next !== m) refs++
280
+ return next
281
+ })
282
+ // a record of what was true stays as written, unless it is itself what moves
283
+ if (after !== before && o.history !== true && isHistoryFile(f) && !moves.has(f)) { left++; continue }
171
284
  if (after !== before) {
172
- io.print(` ${f}`)
173
- if (write) writeFileSync(p, after)
285
+ io.print(` ${f}: ${refs} ref(s)`)
286
+ io.print(` ${firstChanged(before, after)}`)
287
+ tree.write(f, after)
174
288
  touched++
175
289
  }
176
290
  }
177
- io.print(`${write ? 'renamed' : 'DRY RUN'}: ${oldBase} → ${newBase}, refs in ${touched} file(s)`)
178
- if (!write) { io.print('re-run with --write (or --commit) to apply'); return 0 }
179
291
 
180
292
  // moves AFTER the sweep (the sweep rewrote files at their old paths).
181
- // git mv refuses into a directory that is not there yet, and a move
182
- // between directories is the case where it usually is not
183
293
  // the index form moves the asset dir FIRST, so it becomes the topic
184
294
  // folder; created first, git mv would nest it one level down
185
- if (!hasDir && existsSync(join(root, oldBase)) && readdirSync(join(root, oldBase)).every((e) => e === '.DS_Store')) rmSync(join(root, oldBase), { recursive: true })
186
- mkdirSync(join(root, dirOf(hasDir ? newBase : newRel)), { recursive: true })
187
- if (indexForm && hasDir && !inPlace) sh(`git mv ${JSON.stringify(oldBase)} ${JSON.stringify(newBase)}`, root)
188
- mkdirSync(join(root, dirOf(newRel)), { recursive: true })
189
- sh(`git mv ${JSON.stringify(oldRel)} ${JSON.stringify(newRel)}`, root)
295
+ if (!hasDir && tree.exists(oldBase) && !tree.isFile(oldBase) && readdirSync(join(root, oldBase)).every((e) => e === '.DS_Store')) tree.dropEmptyDir(oldBase)
296
+ if (indexForm && hasDir && !inPlace) tree.mv(oldBase, newBase)
297
+ tree.mv(oldRel, newRel)
190
298
  if (hasDir) {
191
- if (!indexForm) sh(`git mv ${JSON.stringify(oldBase)} ${JSON.stringify(newBase)}`, root)
299
+ if (!indexForm && !inPlace) tree.mv(oldBase, newBase)
192
300
  // the probe is named after its page, so it only moves when the NAME
193
301
  // changed. A move that keeps the name and changes the directory takes
194
302
  // the probe along inside the dir, and `git mv X X` is a fatal
195
303
  for (const sfx of SIBLING_SUFFIXES) {
196
- const oldProbe = join(newBase, `${oldName}${sfx}`)
197
- if (oldName !== newName && existsSync(join(root, oldProbe))) sh(`git mv ${JSON.stringify(oldProbe)} ${JSON.stringify(join(newBase, `${newName}${sfx}`))}`, root)
304
+ const oldProbe = `${newBase}/${oldName}${sfx}`
305
+ if (oldName !== newName && tree.exists(oldProbe)) tree.mv(oldProbe, `${newBase}/${newName}${sfx}`)
198
306
  }
199
307
  }
308
+ if (left > 0) io.print(` left as written: ${left} plan, changelog or journal file(s) that name it (--history rewrites them too)`)
309
+ io.print(`${write ? 'renamed' : 'DRY RUN'}: ${oldRel} → ${newRel}, refs in ${touched} file(s)`)
310
+ if (!write) { io.print('re-run with --write (or --commit) to apply'); return 0 }
200
311
 
201
312
  if (o.after !== false && !runAfter(root)) return die('mv:after failed, fix before committing')
202
313
  if (o.commit === true) {
@@ -205,7 +316,7 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
205
316
  execSync(`git commit -m ${JSON.stringify(`docs: rename ${oldBase} → ${newBase}`)}`, { cwd: root, stdio: 'inherit' })
206
317
  } catch { return die('commit failed (pre-commit gate?). The rename is applied, fix and commit yourself') }
207
318
  }
208
- io.print(`ok: ${oldBase} → ${newBase}${o.commit === true ? ' (committed)' : ''}`)
319
+ io.print(`ok: ${oldRel} → ${newRel}${o.commit === true ? ' (committed)' : ''}`)
209
320
  return 0
210
321
  }
211
322
 
@@ -226,13 +337,13 @@ export function parseMoveMap(text: string): [string, string][] {
226
337
  }
227
338
 
228
339
  /** many pages in one run, in map order: each move sweeps the tree the previous
229
- * one left, and `mv:after` runs once at the end. A dry run shows each move
230
- * against the CURRENT tree, so a later pair that depends on an earlier one
231
- * only reports true once applied. Stops at the first failure. */
340
+ * one left, a dry run too (its overlay holds what the lines before moved),
341
+ * and `mv:after` runs once at the end. Stops at the first failure. */
232
342
  export function movePages(root: string, pairs: [string, string][], io: MvIo, o: MvOpts = {}): number {
233
343
  if (o.commit === true) { io.printErr('FAIL: a move map applies with --write, then you commit what you own'); return 1 }
344
+ const tree = new MvTree(root, o.write === true)
234
345
  for (const [from, to] of pairs) {
235
- const code = movePage(root, from, to, io, { ...o, after: false })
346
+ const code = movePage(root, from, to, io, { ...o, after: false }, tree)
236
347
  if (code !== 0) return code
237
348
  }
238
349
  if (o.write === true && !runAfter(root)) { io.printErr('FAIL: mv:after failed, fix before committing'); return 1 }
package/src/pb/run-pb.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  // the failure mode is a runtime throw rather than a compile error.
11
11
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
12
12
  import { dirname, join } from 'path'
13
+ import { nearest } from '../core/nearest.ts'
13
14
  import { scaffoldCollectionUI, type ScaffoldedFile } from './collection-scaffold.ts'
14
15
  import { isSystemCollection, parsePbTypes, type PbCollection } from './pb-types.ts'
15
16
 
@@ -35,15 +36,6 @@ const REGISTRY_HEADER = [
35
36
  '',
36
37
  ].join('\n')
37
38
 
38
- /** names close enough to be the one that was meant */
39
- function nearest(want: string, have: string[]): string[] {
40
- const w = want.toLowerCase().replace(/[_-]/g, '')
41
- return have.filter((n) => {
42
- const h = n.toLowerCase().replace(/[_-]/g, '')
43
- return h === w || h.startsWith(w) || w.startsWith(h)
44
- })
45
- }
46
-
47
39
  export type PbCollectionOpts = { dryRun: boolean }
48
40
 
49
41
  export function runPbCollection(root: string, name: string, io: PbIo, opts: PbCollectionOpts): number {
@@ -70,7 +62,7 @@ export function runPbCollection(root: string, name: string, io: PbIo, opts: PbCo
70
62
  // pocketbase's own `_`-prefixed collections are never an app surface, so
71
63
  // offering them as choices sends the reader somewhere they cannot go
72
64
  const names = collections.filter((c) => !isSystemCollection(c.name)).map((c) => c.name)
73
- const close = nearest(name, names)
65
+ const close = nearest(name, names, Infinity)
74
66
  io.printErr(`FAIL: no collection '${name}' in ${typesRel}`)
75
67
  if (close.length > 0) io.printErr(` fix: did you mean ${close.join(', ')} ?`)
76
68
  io.printErr(` fix: known collections: ${names.join(', ')}`)
@@ -4,11 +4,12 @@
4
4
  //
5
5
  // the one constraint a reader breaks first: `changed` asks the ledger, never
6
6
  // the file event. A check is changed when its answer would not replay: a key
7
- // that moved, a read set that drifted, no stored green, or no key at all for
8
- // a gate check. A red keyed on content counts only once its key moves, so a
9
- // save elsewhere never re-runs it.
7
+ // that moved, a read set that drifted, no stored green. A red keyed on content
8
+ // counts only once its key moves, so a save elsewhere never re-runs it. A
9
+ // check with no key counts when a declared input of the repo moved (saveMoved).
10
10
  import { gateInventory, type CheckRow } from '../ledger/gate-checks.ts'
11
11
  import { Ledger } from '../ledger/ledger.ts'
12
+ import type { CheckKey } from '../ledger/git-key.ts'
12
13
  import { answersDb } from '../ledger/store.ts'
13
14
  import { hasWorld, worldKeyOf, type WorldCache } from '../ledger/world-cache.ts'
14
15
  import { FOREVER, FOREVER_MS } from '../core/wire.ts'
@@ -36,7 +37,7 @@ export function planGap(row: CheckRow): string | null {
36
37
  if (row.runs.onSave !== 'moved') return null
37
38
  const pop = populationOf(row.decl)
38
39
  if (pop === 'content' || pop === 'reads' || isForever(row)) return null
39
- return `onSave 'moved' but nothing keys it (${row.decl.uncacheable ?? row.decl.declError ?? 'no key'}), so every save moves it`
40
+ return `onSave 'moved' but nothing keys it (${row.decl.uncacheable ?? row.decl.declError ?? 'no key'}), so a save runs it whenever any declared input of the repo moved`
40
41
  }
41
42
 
42
43
  /** one inventory row as a plan check, straight from its declared axes:
@@ -103,6 +104,25 @@ export function lastStarted(path: string, o: { asked?: boolean } = {}): number |
103
104
  }
104
105
  }
105
106
 
107
+ /** whether a save moved one check, given the key it had at the last question (`seen`, updated here). A check with
108
+ * no key (an input git cannot name, a toolchain nobody can describe, a scan that failed) is due when its reason
109
+ * changes or when `tree` moved: what the scan saw of every declared input of the repo that git does not ignore,
110
+ * null when the scan failed.
111
+ * Never at each save whatever moved: the run it starts writes files of its own, so that is a loop. With no tree
112
+ * to compare (the scan failed) it is due once for the reason */
113
+ export function saveMoved(seen: Map<string, string>, id: string, k: Pick<CheckKey, 'key' | 'population' | 'reason'>, replays: () => boolean, tree: string | null = null): boolean {
114
+ const before = seen.get(id)
115
+ if (k.key == null) {
116
+ // long runs of digits out: a reason that names a pid or a time is the same reason, a file name keeps its number
117
+ const mark = `no key: ${(k.reason ?? '').replace(/\d{4,}/g, '#')} @ ${tree ?? ''}`
118
+ seen.set(id, mark)
119
+ return before !== mark
120
+ }
121
+ seen.set(id, k.key)
122
+ if (replays()) return false
123
+ return !(k.population === 'content' && before === k.key)
124
+ }
125
+
106
126
  export type RepoSourceDeps = {
107
127
  repo: string
108
128
  root: string
@@ -179,16 +199,7 @@ export function repoSource(d: RepoSourceDeps): PlanSource {
179
199
  }
180
200
  // 'burst': every quiet save burst, whatever moved
181
201
  if (r.runs.onSave === 'burst') { out.push(c.id); continue }
182
- const k = ledger.layer.keyFor(c.id)
183
- if (k.key == null) {
184
- out.push(c.id)
185
- continue
186
- }
187
- const before = seen.get(c.id)
188
- seen.set(c.id, k.key)
189
- if (ledger.replay(c.id) != null) continue
190
- if (k.population === 'content' && before === k.key) continue
191
- out.push(c.id)
202
+ if (saveMoved(seen, c.id, ledger.layer.keyFor(c.id), () => ledger.replay(c.id) != null, ledger.layer.treeStamp())) out.push(c.id)
192
203
  }
193
204
  return out
194
205
  },
@@ -128,7 +128,7 @@ export async function findRecording(ref: string, o: { repo?: string } = {}): Pro
128
128
  const hits = all.filter((r) => r.name === word || r.id === word)
129
129
  if (hits.length === 1) return hits[0]!
130
130
  if (hits.length > 1) throw new Error(`${ref}: ${hits.length} recordings answer to it (${hits.map((r) => `${r.repo}/${r.name}`).join(', ')}); name the repo`)
131
- throw new Error(`${ref}: no recording of that name${repo ? ` in ${repo}` : ''} (sk rec ls lists them)`)
131
+ throw new Error(`${ref}: no recording of that name${repo ? ` in ${repo}` : ''} (sk rec lists them)`)
132
132
  }
133
133
 
134
134
  /** the name given, checked free in the repo folder */
@@ -40,10 +40,19 @@ export type TranscriptEvent =
40
40
  * hours after the agent handed back */
41
41
  | { kind: 'message'; at: number }
42
42
  | { kind: 'use'; at: number; id: string; name: string; detail: string }
43
- /** `perm`: how the call was allowed; `user` = it waited for the human, so its time is his */
44
- | { kind: 'result'; at: number; id: string; outcome: Outcome; code: number | null; perm: Perm }
43
+ /** `perm`: how the call was allowed; `user` = it waited for the human, so its time is his.
44
+ * `bg`: the call returned while its command runs on in the background
45
+ * (started so, or moved there at its timeout); its real end is a `bgend` */
46
+ | { kind: 'result'; at: number; id: string; outcome: Outcome; code: number | null; perm: Perm; bg: boolean }
47
+ /** a background run's task notification: the call `id` ended at `at`. One
48
+ * run can be written two or three times (queued, then delivered): the
49
+ * earliest is its end */
50
+ | { kind: 'bgend'; at: number; id: string; outcome: Outcome; code: number | null }
45
51
  /** an assistant text block: the agent talking, which can end its turn */
46
52
  | { kind: 'reply'; at: number }
53
+ /** the text block that ends the turn (stop_reason end_turn): the agent
54
+ * stopped, and what follows is a wait until something wakes it */
55
+ | { kind: 'end'; at: number }
47
56
 
48
57
  // wrappers the harness injects as user-role entries: none of them are typed
49
58
  const NOISE_PREFIXES = [
@@ -82,10 +91,15 @@ export type RawEntry = {
82
91
  isCompactSummary?: unknown
83
92
  /** `peer` on a sub-agent hand-back or another session's message */
84
93
  turnOrigin?: unknown
94
+ /** `{ kind: 'task-notification' }` on a background task's notification:
95
+ * a plain turn in a main session, a meta turn in a sub-agent */
96
+ origin?: { kind?: unknown }
97
+ /** attachment entries: a notification delivered mid-turn is a `queued_command` */
98
+ attachment?: { type?: unknown; prompt?: unknown }
85
99
  /** queue-operation entries only */
86
100
  operation?: unknown
87
101
  content?: unknown
88
- message?: { role?: unknown; content?: unknown; id?: unknown; model?: unknown; usage?: { input_tokens?: unknown; output_tokens?: unknown; cache_read_input_tokens?: unknown; cache_creation_input_tokens?: unknown } }
102
+ message?: { role?: unknown; content?: unknown; id?: unknown; model?: unknown; stop_reason?: unknown; usage?: { input_tokens?: unknown; output_tokens?: unknown; cache_read_input_tokens?: unknown; cache_creation_input_tokens?: unknown } }
89
103
  toolUseResult?: unknown
90
104
  /** on a tool_result entry: who allowed the call (`config`, `user_temporary`, …) */
91
105
  permissionDecision?: { source?: unknown; reasonType?: unknown }
@@ -244,15 +258,19 @@ export function eventsOf(entry: RawEntry): TranscriptEvent[] {
244
258
 
245
259
  if (entry.type === 'queue-operation') {
246
260
  const q = queuedPromptOf(entry)
247
- return q == null ? [] : [prompt(q, 'queued')]
261
+ if (q != null) return [prompt(q, 'queued')]
262
+ return entry.operation === 'enqueue' && typeof entry.content === 'string' ? bgEndsOf(entry.content, at) : []
248
263
  }
249
264
  if (Number.isNaN(at) && entry.type !== 'user') return []
265
+ // a notification that arrives while the agent works is attached to its next turn
266
+ if (entry.type === 'attachment') return entry.attachment?.type === 'queued_command' && typeof entry.attachment.prompt === 'string' ? bgEndsOf(entry.attachment.prompt, at) : []
250
267
  if (entry.type === 'assistant') {
251
268
  const blocks = Array.isArray(entry.message?.content) ? (entry.message.content as Block[]) : []
252
269
  const out: TranscriptEvent[] = []
270
+ const ends = entry.message?.stop_reason === 'end_turn'
253
271
  for (const b of blocks) {
254
272
  if (b?.type === 'tool_use' && typeof b.id === 'string' && typeof b.name === 'string') out.push({ kind: 'use', at, id: b.id, name: b.name, detail: detailOf(b.name, b.input) })
255
- else if (b?.type === 'text') out.push({ kind: 'reply', at })
273
+ else if (b?.type === 'text') out.push({ kind: ends ? 'end' : 'reply', at })
256
274
  }
257
275
  return out
258
276
  }
@@ -261,19 +279,46 @@ export function eventsOf(entry: RawEntry): TranscriptEvent[] {
261
279
  const content = entry.message?.content
262
280
  if (Array.isArray(content)) {
263
281
  const perm = permOf(entry.permissionDecision)
282
+ const extra = entry.toolUseResult != null && typeof entry.toolUseResult === 'object' ? (entry.toolUseResult as Record<string, unknown>) : {}
283
+ const bg = typeof extra.backgroundTaskId === 'string'
264
284
  for (const b of content as Block[]) {
265
285
  if (b?.type !== 'tool_result' || typeof b.tool_use_id !== 'string' || Number.isNaN(at)) continue
266
- const o = outcomeOf({ isError: b.is_error === true, text: resultText(b.content), extra: entry.toolUseResult })
267
- out.push({ kind: 'result', at, id: b.tool_use_id, ...o, perm })
286
+ const o = outcomeOf({ isError: b.is_error === true, text: resultText(b.content), extra })
287
+ out.push({ kind: 'result', at, id: b.tool_use_id, ...o, perm, bg })
268
288
  }
269
289
  }
270
290
  const typed = typedPromptOf(entry)
271
291
  if (typed != null) out.push(prompt(typed, 'typed'))
272
- else if (out.length === 0 && !Number.isNaN(at) && entry.isMeta === true && RELAYED.test(userText(entry) ?? '')) out.push({ kind: 'message', at })
273
- // a peer message (a sub-agent hand-back, another session's message) is written isMeta, yet it wakes the agent
274
- else if (out.length === 0 && !Number.isNaN(at) && (entry.isMeta !== true || entry.turnOrigin === 'peer') && entry.isCompactSummary !== true) {
275
- const text = userText(entry)
292
+ if (out.length > 0 || Number.isNaN(at)) return out
293
+ const text = userText(entry)
294
+ if (entry.isMeta === true && RELAYED.test(text ?? '')) out.push({ kind: 'message', at })
295
+ // a peer message (a sub-agent hand-back, another session's message) and a
296
+ // sub-agent's task notification are written isMeta, yet they wake the agent
297
+ else if ((entry.isMeta !== true || entry.turnOrigin === 'peer' || entry.origin?.kind === 'task-notification') && entry.isCompactSummary !== true) {
276
298
  if (text != null && text !== '') out.push({ kind: 'wake', at })
277
299
  }
300
+ if (text != null) out.push(...bgEndsOf(text, at))
301
+ return out
302
+ }
303
+
304
+ const NOTICE = /<task-notification>([\s\S]*?)<\/task-notification>/g
305
+ const tagOf = (body: string, name: string): string | null => new RegExp(`<${name}>([^<]*)</${name}>`).exec(body)?.[1]?.trim() ?? null
306
+
307
+ /** the background runs a notification text says ended: each one that names
308
+ * its call and a final status. `stopped` is a run the harness lost track of
309
+ * (its session ended first): no end is known, so none is given */
310
+ export function bgEndsOf(text: string, at: number): TranscriptEvent[] {
311
+ if (Number.isNaN(at) || !text.includes('<task-notification>')) return []
312
+ const out: TranscriptEvent[] = []
313
+ for (const m of text.matchAll(NOTICE)) {
314
+ const body = m[1] ?? ''
315
+ const id = tagOf(body, 'tool-use-id')
316
+ const status = tagOf(body, 'status')
317
+ if (id == null || id === '' || (status !== 'completed' && status !== 'failed' && status !== 'killed')) continue
318
+ const exit = /exit code (\d+)/.exec(tagOf(body, 'summary') ?? '')?.[1]
319
+ const code = exit == null ? null : Number(exit)
320
+ const outcome: Outcome = status === 'killed' ? 'interrupted' : code != null && code !== 0 ? 'exit' : status === 'failed' ? 'error' : 'ok'
321
+ out.push({ kind: 'bgend', at, id, outcome, code: outcome === 'exit' ? code : null })
322
+ }
278
323
  return out
279
324
  }
@@ -40,7 +40,7 @@ import { unitBlockers } from './unit-gate.ts'
40
40
  import { publicCleanBlockers } from './public-clean.ts'
41
41
  import { releaseScope } from './release-scope.ts'
42
42
  import { formatUnitError, releaseOrder, renderTag, resolveUnits, unitById, unitPrepublishScripts, unknownUnit, type ReleaseUnit } from './units.ts'
43
- import { environmentBlockers, runReleaseGate, releaseUnit } from './run-release.ts'
43
+ import { environmentBlockers, gateStop, runReleaseGate, releaseUnit } from './run-release.ts'
44
44
  import type { RepoConfig } from '../repo-config.ts'
45
45
  import { nestedIn, nestedRefusal } from '../core/nesting.ts'
46
46
  import { LAYOUT } from '../core/layout.ts'
@@ -492,7 +492,8 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
492
492
  // same thing. Frozen, and fatal on non-blocking failures when the repo
493
493
  // declared requireHealthy. releaseUnit then skips it, because bump
494
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')
495
+ const gate = await runReleaseGate(root, print, { units: picked, allowDirty: o.allowDirty })
496
+ if (gate !== 0) return fail(gateStop(gate, 'bump'))
496
497
  print('ok: ci gate green')
497
498
 
498
499
  for (const s of selected) {
@@ -124,8 +124,11 @@ export type ReleaseOpts = {
124
124
  * classifying severity from one config while the rules ran from another
125
125
  * downgrades a blocking failure to a warning.
126
126
  *
127
- * it also runs the FULL test tier, which `shipkit ci` skips while you work. */
128
- export async function runReleaseGate(root: string, print: (l: string) => void, o: { units?: ReleaseUnit[]; allowDirty?: boolean } = {}): Promise<number> {
127
+ * it also runs the FULL test tier, which `shipkit ci` skips while you work.
128
+ *
129
+ * 'not run' when the checkout could not be made ready (its FAIL line says why): nothing was judged, so a caller
130
+ * never reports it as a red gate. */
131
+ export async function runReleaseGate(root: string, print: (l: string) => void, o: { units?: ReleaseUnit[]; allowDirty?: boolean } = {}): Promise<number | 'not run'> {
129
132
  const r = await withHeadCheckout(root, async (dir, sha) => {
130
133
  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
134
  let config: RepoConfig
@@ -178,9 +181,13 @@ export async function runReleaseGate(root: string, print: (l: string) => void, o
178
181
  })
179
182
  if (typeof r === 'number') return r
180
183
  print(`FAIL: ${r.error}`)
181
- return 1
184
+ return 'not run'
182
185
  }
183
186
 
187
+ /** the line a release or a bump stops on when the gate did not pass: a gate that never ran is not a red one */
188
+ export const gateStop = (gate: number | 'not run', what: 'release' | 'bump'): string =>
189
+ gate === 'not run' ? `the ci gate did not run, so nothing was judged red: fix what the FAIL line above names, then ${what} again` : `ci gate is red on HEAD${what === 'bump' ? ' (the merged result)' : ''} — fix it, commit, then ${what}`
190
+
184
191
  /** the test checks of every sub-unit this release does not ship. No list
185
192
  * given means the caller did not say, and every unit's suite runs. The root
186
193
  * depends on what it contains, so a release that ships it runs them all. A
@@ -307,7 +314,8 @@ export async function releaseUnit(root: string, config: RepoConfig, unit: Releas
307
314
  if (o.skipGate === true)
308
315
  print(o.skipGateReason != null ? `ok: ci gate ${o.skipGateReason}` : 'WARN ci gate SKIPPED by --skip-gate — publishing unverified')
309
316
  else {
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 }
317
+ const gate = await runReleaseGate(root, print, { units: [unit], allowDirty: o.allowDirty })
318
+ if (gate !== 0) { print(`FAIL: ${gateStop(gate, 'release')}`); return 1 }
311
319
  print('ok: ci gate green')
312
320
  }
313
321