rvlib-shipkit 2.22.1 → 2.24.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 (139) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/render.ts +28 -14
  4. package/src/agent-time/report.ts +46 -25
  5. package/src/agent-time/store.ts +30 -10
  6. package/src/agent-time/timeline.ts +43 -15
  7. package/src/annex/annex.ts +3 -0
  8. package/src/annex/born.ts +464 -0
  9. package/src/annex/flush.ts +46 -0
  10. package/src/annex/offload.ts +171 -38
  11. package/src/annex/snapshots.ts +53 -0
  12. package/src/annex/tidy.ts +368 -0
  13. package/src/asks/asks-queue.ts +32 -11
  14. package/src/checks/SK041-annex-links.check.ts +4 -2
  15. package/src/checks/SK043-scratch-on-the-mac.check.ts +45 -0
  16. package/src/checks/SK044-behind-upstream.check.ts +38 -0
  17. package/src/cli/cmd_Annex.ts +60 -9
  18. package/src/cli/cmd_Asks.ts +2 -0
  19. package/src/cli/cmd_Backup.ts +7 -5
  20. package/src/cli/cmd_Bump.ts +1 -0
  21. package/src/cli/cmd_Capacity.ts +26 -0
  22. package/src/cli/cmd_Check.ts +1 -0
  23. package/src/cli/cmd_Checks.ts +1 -0
  24. package/src/cli/cmd_Ci.ts +1 -0
  25. package/src/cli/cmd_Commands.ts +50 -14
  26. package/src/cli/cmd_Home.ts +0 -1
  27. package/src/cli/cmd_Hooks.ts +1 -0
  28. package/src/cli/cmd_Mv.ts +1 -0
  29. package/src/cli/cmd_Rec.ts +17 -7
  30. package/src/cli/cmd_Reflect.ts +1 -0
  31. package/src/cli/cmd_Releases.ts +1 -0
  32. package/src/cli/cmd_Review.ts +124 -17
  33. package/src/cli/cmd_Secret.ts +41 -2
  34. package/src/cli/cmd_Shot.ts +1 -0
  35. package/src/cli/cmd_Status.ts +1 -0
  36. package/src/cli/cmd_Time.ts +3 -1
  37. package/src/cli/cmd_Tmp.ts +82 -0
  38. package/src/cli/cmd_Wiki.ts +1 -0
  39. package/src/cli/registry.ts +13 -1
  40. package/src/collections/pings.ts +1 -1
  41. package/src/core/capacity.ts +71 -0
  42. package/src/core/check-runner.ts +86 -15
  43. package/src/core/machine-db.ts +8 -0
  44. package/src/core/motherhome.ts +67 -9
  45. package/src/core/slots.ts +49 -12
  46. package/src/core/trace-audit.ts +4 -1
  47. package/src/drill/run.ts +5 -2
  48. package/src/home/daemon-jobs.ts +10 -3
  49. package/src/home/global-units.ts +3 -0
  50. package/src/home/gui-app/ShipkitGui.swift +1 -0
  51. package/src/home/home-launchd.ts +11 -3
  52. package/src/home/home-routes.ts +11 -4
  53. package/src/home/machine-host.ts +65 -0
  54. package/src/home/machine-stores.ts +30 -4
  55. package/src/home/machine-temp.ts +493 -0
  56. package/src/home/other-macs.ts +74 -0
  57. package/src/home/pm.ts +4 -1
  58. package/src/home/run-daemon.ts +10 -2
  59. package/src/home/run-pm.ts +1 -0
  60. package/src/home/serve-web.ts +2 -2
  61. package/src/home/via-hub.ts +6 -1
  62. package/src/identities/identities.ts +92 -24
  63. package/src/init-repo.ts +7 -3
  64. package/src/ledger/ledger.ts +6 -0
  65. package/src/ledger/store.ts +6 -0
  66. package/src/media-store/backup/keys.ts +21 -6
  67. package/src/media-store/backup/manifest.ts +52 -11
  68. package/src/media-store/backup/restore.ts +17 -10
  69. package/src/media-store/backup/run.ts +5 -2
  70. package/src/media-store/backup/sources.ts +2 -1
  71. package/src/media-store/daemon.ts +2 -2
  72. package/src/media-store/purge.ts +4 -0
  73. package/src/mv/mv-md.ts +121 -42
  74. package/src/recordings/load.ts +3 -3
  75. package/src/recordings/model.ts +7 -0
  76. package/src/recordings/open.ts +12 -0
  77. package/src/recordings/presets.ts +12 -5
  78. package/src/recordings/recorder-app/Capture.swift +34 -5
  79. package/src/recordings/recorder-app/Clip.swift +126 -17
  80. package/src/recordings/recorder-app/Editor.swift +177 -7
  81. package/src/recordings/recorder-app/Hud.swift +189 -0
  82. package/src/recordings/recorder-app/Tray.swift +179 -36
  83. package/src/recordings/recorder-app/icon.svg +16 -0
  84. package/src/recordings/recorder-app/main.swift +349 -18
  85. package/src/recordings/recorder-app.ts +8 -4
  86. package/src/recordings/recorder.shipkit.ts +2 -1
  87. package/src/recordings/routes.ts +52 -6
  88. package/src/recordings/run-recorder.ts +2 -1
  89. package/src/recordings/share.ts +27 -0
  90. package/src/recordings/take.ts +36 -4
  91. package/src/recordings/view.ts +11 -0
  92. package/src/reflect/transcript.ts +56 -11
  93. package/src/releases/from-card.ts +45 -3
  94. package/src/releases/model.ts +6 -0
  95. package/src/releases/store.ts +8 -1
  96. package/src/repo-config.ts +14 -4
  97. package/src/review/cells.ts +24 -3
  98. package/src/review/format.ts +33 -9
  99. package/src/review/media-kind.ts +14 -11
  100. package/src/review/media-read.ts +6 -5
  101. package/src/review/model.ts +104 -7
  102. package/src/review/paste.ts +2 -1
  103. package/src/review/previews.ts +123 -36
  104. package/src/review/routes.ts +29 -18
  105. package/src/review/store.ts +74 -12
  106. package/src/review/threads.ts +7 -5
  107. package/src/secrets/copy.ts +110 -0
  108. package/src/secrets/list.ts +17 -7
  109. package/src/serve/hub-app/home-strip.css +5 -0
  110. package/src/serve/hub-app/home-strip.tsx +18 -0
  111. package/src/serve/hub-app/hub-app.tsx +2 -1
  112. package/src/serve/hub-app/hub.css +18 -0
  113. package/src/serve/hub-app/inbox.css +1 -0
  114. package/src/serve/hub-app/pull-refresh.tsx +88 -0
  115. package/src/serve/hub-app/recordings-st.ts +135 -24
  116. package/src/serve/hub-app/recordings-view.tsx +293 -54
  117. package/src/serve/hub-app/recordings.css +77 -24
  118. package/src/serve/hub-app/review/review-cells.tsx +52 -13
  119. package/src/serve/hub-app/review/review-list.tsx +6 -1
  120. package/src/serve/hub-app/review/review-st.ts +6 -5
  121. package/src/serve/hub-app/review/review-thread.tsx +3 -1
  122. package/src/serve/hub-app/review/review-views.tsx +18 -11
  123. package/src/serve/hub-app/review/thread-st.ts +82 -14
  124. package/src/serve/hub-app/review.css +15 -2
  125. package/src/serve/hub-runtime.ts +2 -1
  126. package/src/serve/run-serve.ts +4 -2
  127. package/src/serve/serve-hub.ts +9 -2
  128. package/src/shipkit-files.ts +5 -0
  129. package/src/social/drafts.ts +4 -3
  130. package/src/social/load.ts +7 -2
  131. package/src/social/publish/discord.ts +10 -3
  132. package/src/suite/child-tools.ts +45 -0
  133. package/src/suite/judge-suites.ts +10 -22
  134. package/src/suite/select.ts +83 -8
  135. package/src/suite/suite-cli.ts +38 -14
  136. package/src/suite/suite-cores.ts +68 -0
  137. package/src/suite/suite-reads-preload.ts +8 -6
  138. package/src/ts/config.ts +44 -0
  139. package/src/ts/rename.ts +11 -1
@@ -9,15 +9,16 @@ import { bad, NO_STORE, ranged } from '../review/http.ts'
9
9
  import { recorderState } from './load.ts'
10
10
  import { currentFile, findRecording, rename, type Recording } from './model.ts'
11
11
  import { deleteRecording } from './delete.ts'
12
- import { recorderUrl } from './open.ts'
12
+ import { RECORDER_SCHEME, recorderCopyTextUrl, recorderCopyUrl, recorderUrl } from './open.ts'
13
13
  import type { RecPreset } from './presets.ts'
14
- import { copyRecordingFile, copyText, privateLink, publicLink } from './share.ts'
15
- import { editText, fileBack, saveEdit } from './take.ts'
14
+ import { animatedWebp, copyRecordingFile, copyText, privateLink, publicLink, upNow, webpMade, webpPath } from './share.ts'
15
+ import { editText, fileBack, sameEdit, saveEdit, versionsOf } from './take.ts'
16
16
  import { reveal } from '../veille/chrome.ts'
17
17
  import type { RecList, RecView } from './view.ts'
18
18
 
19
19
  export function viewOf(r: Recording): RecView {
20
20
  const current = currentFile(r)
21
+ const versions = versionsOf(r)
21
22
  return {
22
23
  id: r.id,
23
24
  name: r.name,
@@ -34,10 +35,21 @@ export function viewOf(r: Recording): RecView {
34
35
  edit: editText(r),
35
36
  local: existsSync(join(r.dir, current)),
36
37
  up: r.files[current] ? isUp(mediaKey('recording', r.files[current]!, current)) : false,
38
+ bytes: r.files[current]?.size ?? 0,
39
+ version: versions.at(-1)?.n ?? 0,
40
+ versions: versions.map((v) => ({ n: v.n, at: v.at, text: v.text, bytes: v.size ?? 0 })),
41
+ webp: webpMade(r),
37
42
  publicUrl: r.publicUrl ?? null,
38
43
  }
39
44
  }
40
45
 
46
+ /** the recorder app reads its recent captures again (a save, a rename, a move or a delete changed one), behind
47
+ * whatever is in front; nothing when it does not run */
48
+ function pokeRecorder(): void {
49
+ if (Bun.spawnSync(['pgrep', '-x', 'shipkit-recorder'], { stdout: 'ignore', stderr: 'ignore' }).exitCode !== 0) return
50
+ Bun.spawn(['open', '-g', `${RECORDER_SCHEME}://refresh`], { stdout: 'ignore', stderr: 'ignore' })
51
+ }
52
+
41
53
  const API = '/api/home/recordings'
42
54
  const MEDIA = /^(raw|out)\.(mp4|png)$|^poster\.webp$/
43
55
 
@@ -111,25 +123,59 @@ export async function recordingsRoute(req: Request, path: string): Promise<Respo
111
123
  await copyRecordingFile(r)
112
124
  return Response.json({ said: 'file copied: paste it in Slack, Discord or a mail' })
113
125
  }
126
+ if (verb === 'copy') {
127
+ // the editor's ⌘C: the recorder app copies, so a capture reaches the clipboard one way, read back and shown
128
+ const ask = (url: string): Response | null => {
129
+ const p = Bun.spawnSync(['open', url], { stdout: 'ignore', stderr: 'pipe' })
130
+ return p.exitCode === 0 ? null : bad(`the recorder did not answer: ${p.stderr.toString().trim()}; sk gp start recorder`)
131
+ }
132
+ if (b.format === 'link') {
133
+ const l = await privateLink(r)
134
+ return ask(recorderCopyTextUrl(l.url, 'Private link', `plays until ${l.expires.slice(0, 10)}`)) ?? Response.json({ url: l.url, said: `copying the link of ${r.name}: the recorder's indicator says when it is on the clipboard` })
135
+ }
136
+ if (b.format === 'webp-hq' && !r.still) {
137
+ const anim = await animatedWebp(r)
138
+ return ask(recorderCopyUrl(anim, 'file')) ?? Response.json({ recording: viewOf(r), said: `copying ${r.name} as an animated WebP: the recorder's indicator says when it is on the clipboard` })
139
+ }
140
+ const file = await fileBack(r, currentFile(r))
141
+ const still = file.endsWith('.png')
142
+ const webp = still && b.format === 'webp-hq'
143
+ return ask(recorderCopyUrl(file, still ? (webp ? 'webp-hq' : 'png') : 'file', webp ? webpPath(r) : undefined)) ?? Response.json({ said: `copying ${r.name}${b.format === 'webp-hq' ? ' as WebP HQ' : still ? ' as PNG' : ''}: the recorder's indicator says when it is on the clipboard` })
144
+ }
114
145
  if (verb === 'reveal') {
115
146
  await reveal(await fileBack(r, currentFile(r)))
116
147
  return Response.json({ said: 'shown in the Finder' })
117
148
  }
118
149
  if (verb === 'rename') {
119
150
  if (typeof b.name !== 'string') return bad('rename wants a name')
120
- return Response.json({ recording: viewOf(rename(r, b.name)), said: `renamed ${b.name}` })
151
+ const named = viewOf(rename(r, b.name))
152
+ pokeRecorder()
153
+ return Response.json({ recording: named, said: `renamed ${b.name}` })
121
154
  }
122
155
  if (verb === 'move') {
123
156
  if (typeof b.repo !== 'string') return bad('move wants a repo')
124
157
  const { moveRecording } = await import('./model.ts')
125
- return Response.json({ recording: viewOf(moveRecording(r, b.repo)), said: `${r.name} filed under ${b.repo}` })
158
+ const moved = viewOf(moveRecording(r, b.repo))
159
+ pokeRecorder()
160
+ return Response.json({ recording: moved, said: `${r.name} filed under ${b.repo}` })
126
161
  }
127
162
  if (verb === 'edit') {
128
163
  if (typeof b.text !== 'string') return bad('edit wants its text')
129
- return Response.json({ recording: viewOf(await saveEdit(r, b.text)), said: b.text.trim() === '' ? 'edit removed: the take plays whole' : 'exported' })
164
+ // the edit already saved: no render, no version, no upload
165
+ if (sameEdit(r, b.text)) {
166
+ const v = viewOf(r)
167
+ return Response.json({ recording: v, unchanged: true, said: `nothing changed since ${v.version > 0 ? `v${v.version}` : 'the take'}: no new save, no upload` })
168
+ }
169
+ const done = await saveEdit(r, b.text)
170
+ const v = viewOf(done)
171
+ pokeRecorder()
172
+ // the export up now, behind the answer, as a take's own upload is: the media store's pass comes up to 30 s later
173
+ void upNow(done).catch((e: Error) => console.error(`FAIL: ${done.repo}/${done.name}: its export did not go up now, the media store's next pass retries it: ${e.message}`))
174
+ return Response.json({ recording: v, said: b.text.trim() === '' ? `v${v.version}: the edit removed, the take plays whole` : `saved as v${v.version}; it goes up now` })
130
175
  }
131
176
  if (verb === 'delete') {
132
177
  const res = await deleteRecording(r)
178
+ pokeRecorder()
133
179
  const pub = r.publicUrl ? '; a public link may play from the CDN for up to an hour' : ''
134
180
  return Response.json({ said: res.kept.length ? `${r.name} deleted, but ${res.kept.length} of its files stay up: another recording holds the same content${pub}` : `${r.name} deleted for good: its private links are dead${pub}` })
135
181
  }
@@ -13,7 +13,8 @@ if (import.meta.main) {
13
13
  Bun.spawnSync(quitCmd(RECORDER_BUNDLE_ID))
14
14
  console.log(`shipkit recorder: built ${app}`)
15
15
  }
16
- const quit = (): void => {
16
+ const quit = (sig: NodeJS.Signals): void => {
17
+ console.error(`shipkit recorder: ${sig} received, the app quits`)
17
18
  Bun.spawnSync(quitCmd(RECORDER_BUNDLE_ID))
18
19
  process.exit(0)
19
20
  }
@@ -1,16 +1,19 @@
1
1
  // a recording shared (wiki tools/shipkit/recordings.md, Share): sent up now, a private link (7 days at most), a
2
2
  // public one (permanent, published under `public/recording-share/`), the file itself on the clipboard, markdown; and
3
3
  // the `after` steps of a preset, run in order. Every link goes through the media store's own verbs
4
+ import { existsSync, readdirSync, renameSync, rmSync, statSync } from 'node:fs'
4
5
  import { join } from 'node:path'
5
6
  import { mediaKey } from '../media-store/content.ts'
6
7
  import { linkMedia, putMedia } from '../media-store/put.ts'
7
8
  import { machineSpace } from '../media-store/space.ts'
8
9
  import { syncKind } from '../media-store/sync.ts'
9
10
  import { uploadWaiting } from '../media-store/upload.ts'
11
+ import { ffmpeg } from '../trailer/ffmpeg.ts'
10
12
  import { copyFile, reveal } from '../veille/chrome.ts'
11
13
  import { recordingKindAt, RECORDING_KIND } from './media-kind.ts'
12
14
  import { currentFile, readMeta, retireKey, writeMeta, type Recording } from './model.ts'
13
15
  import type { RecAfter } from './presets.ts'
16
+ import { ANIM_MAX_SECONDS } from './view.ts'
14
17
  import { fileBack } from './take.ts'
15
18
 
16
19
  export const SHARE_LABEL = 'recording-share'
@@ -62,6 +65,30 @@ export async function copyText(text: string): Promise<void> {
62
65
  if ((await p.exited) !== 0) throw new Error(`pbcopy: ${(await new Response(p.stderr).text()).trim()}`)
63
66
  }
64
67
 
68
+ /** where the WebP of what plays is kept once a copy made it: beside the capture, named by the content it was made
69
+ * from, so a new version never reads an older one's */
70
+ export function webpPath(r: Recording): string {
71
+ return join(r.dir, `copy-${(r.files[currentFile(r)]?.sha ?? 'take').slice(0, 8)}.webp`)
72
+ }
73
+
74
+ /** the size of the WebP of what plays, null until a copy makes it */
75
+ export const webpMade = (r: Recording): number | null => statSync(webpPath(r), { throwIfNoEntry: false })?.size ?? null
76
+
77
+ /** a video as an animated WebP, made from what plays on its first copy and kept (webpPath), so the next copy is
78
+ * instant and a new version makes a new one. Measured on a 5 s 668x406 take: 0.33 s, 140 KB */
79
+ export async function animatedWebp(r: Recording): Promise<string> {
80
+ if (r.still) throw new Error(`${r.repo}/${r.name} is a screenshot: its WebP is the image's`)
81
+ if (r.seconds > ANIM_MAX_SECONDS) throw new Error(`${r.repo}/${r.name} plays ${Math.round(r.seconds)} s: an animated WebP stops at ${ANIM_MAX_SECONDS} s, cut it first or copy its file`)
82
+ const file = await fileBack(r, currentFile(r))
83
+ const out = webpPath(r)
84
+ if (existsSync(out)) return out
85
+ for (const f of readdirSync(r.dir)) if (/^copy-[0-9a-z]+\.webp$/.test(f)) rmSync(join(r.dir, f), { force: true })
86
+ const tmp = `${out}.part.webp`
87
+ await ffmpeg(['-i', file, '-vf', "fps=15,scale='min(800,iw)':-2:flags=lanczos", '-c:v', 'libwebp_anim', '-lossless', '0', '-q:v', '70', '-compression_level', '4', '-loop', '0', '-an', tmp])
88
+ renameSync(tmp, out)
89
+ return out
90
+ }
91
+
65
92
  /** the file itself on the clipboard: a paste in Slack, Discord or a mail attaches it */
66
93
  export async function copyRecordingFile(r: Recording): Promise<string> {
67
94
  const file = await fileBack(r, currentFile(r))
@@ -1,7 +1,7 @@
1
1
  // a take filed and an edit exported (wiki tools/shipkit/recordings.md, A recording): the file the recorder wrote
2
2
  // becomes `raw.mp4` (remuxed for the web, transcoded only when it must) or `raw.png`, with its poster and its facts;
3
3
  // an export renders `edit.txt` into `out.<ext>` in one ffmpeg pass. The take itself is never written again
4
- import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync } from 'node:fs'
4
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync } from 'node:fs'
5
5
  import { basename, extname, join } from 'node:path'
6
6
  import { factOf, mediaKey } from '../media-store/content.ts'
7
7
  import { fetchBack } from '../media-store/remote.ts'
@@ -9,7 +9,7 @@ import { ffmpeg, hasAudio, imageSize, probeMedia } from '../trailer/ffmpeg.ts'
9
9
  import { EMPTY_EDIT, editedLength, exportArgs, isEmpty, parseEdit, printEdit, stillArgs, type Edit } from './edit.ts'
10
10
  import { markPngs } from './marks-png.ts'
11
11
  import { RECORDING_KIND } from './media-kind.ts'
12
- import { checkName, EDIT, idOf, outOf, POSTER, readMeta, retire, writeMeta, type RecMeta, type Recording } from './model.ts'
12
+ import { checkName, EDIT, idOf, outOf, POSTER, readMeta, retire, VERSIONS_KEPT, writeMeta, type RecMeta, type Recording, type RecVersion } from './model.ts'
13
13
  import { ensureDir, rememberRoot, repoDir, writeRoot } from './place.ts'
14
14
 
15
15
  const STILL = new Set(['.png', '.jpg', '.jpeg', '.heic', '.tiff', '.webp'])
@@ -105,20 +105,50 @@ export const editText = (r: Recording): string => (existsSync(join(r.dir, EDIT))
105
105
 
106
106
  export const readEdit = (r: Recording): Edit => (existsSync(join(r.dir, EDIT)) ? parseEdit(editText(r)) : EMPTY_EDIT)
107
107
 
108
- /** the edit saved and exported: `out.<ext>` and its poster made again; an empty edit removes both, the take plays */
109
- export async function saveEdit(r: Recording, text: string): Promise<Recording> {
108
+ /** every save of the edit that changed something, oldest first; an edit saved before versions were kept is v1 */
109
+ export function versionsOf(r: Pick<Recording, 'dir' | 'versions' | 'files' | 'raw'>): RecVersion[] {
110
+ if (r.versions && r.versions.length > 0) return r.versions
111
+ const at = join(r.dir, EDIT)
112
+ if (!existsSync(at)) return []
113
+ const f = r.files[outOf(r)]
114
+ return [{ n: 1, at: statSync(at).mtime.toISOString(), text: readFileSync(at, 'utf8'), ...(f ? { sha: f.sha, size: f.size } : {}) }]
115
+ }
116
+
117
+ /** true when saving `text` would change nothing: it is the edit already saved, and its export is there */
118
+ export function sameEdit(r: Recording, text: string): boolean {
119
+ const want = printEdit(parseEdit(text))
120
+ const has = existsSync(join(r.dir, EDIT)) ? printEdit(parseEdit(editText(r))) : ''
121
+ if (want !== has) return false
122
+ return want === '' || existsSync(join(r.dir, outOf(r))) || r.files[outOf(r)] !== undefined
123
+ }
124
+
125
+ /** the WebP made for a copy of what played before: stale once another version plays */
126
+ const dropCopies = (dir: string): void => {
127
+ for (const f of readdirSync(dir)) if (/^copy-[0-9a-z]+\.webp$/.test(f)) rmSync(join(dir, f), { force: true })
128
+ }
129
+
130
+ /** the edit saved and exported as a new version: `out.<ext>` and its poster made again; an empty edit removes both,
131
+ * the take plays. An edit that is the one already saved changes nothing: no render, no version, no upload */
132
+ export async function saveEdit(r: Recording, text: string, o: { now?: Date } = {}): Promise<Recording> {
110
133
  const e = parseEdit(text)
111
134
  const m = readMeta(r.dir)
112
135
  if (!m) throw new Error(`${r.dir}: no meta.json`)
136
+ if (sameEdit(r, text)) return { ...m, dir: r.dir, root: r.root }
113
137
  const out = outOf(m)
138
+ const before = versionsOf({ ...m, dir: r.dir })
139
+ const cut = (v: Omit<RecVersion, 'n' | 'at'>): void => {
140
+ m.versions = [...before, { n: (before.at(-1)?.n ?? 0) + 1, at: (o.now ?? new Date()).toISOString(), ...v }].slice(-VERSIONS_KEPT)
141
+ }
114
142
  if (isEmpty(e)) {
115
143
  rmSync(join(r.dir, EDIT), { force: true })
116
144
  rmSync(join(r.dir, out), { force: true })
145
+ dropCopies(r.dir)
117
146
  retire(m, out)
118
147
  retire(m, POSTER)
119
148
  delete m.files[out]
120
149
  await poster(await fileBack(r, m.raw), m.seconds, join(r.dir, POSTER))
121
150
  m.files[POSTER] = await factOf(join(r.dir, POSTER))
151
+ cut({ text: '' })
122
152
  writeMeta(r.dir, m)
123
153
  return { ...m, dir: r.dir, root: r.root }
124
154
  }
@@ -136,11 +166,13 @@ export async function saveEdit(r: Recording, text: string): Promise<Recording> {
136
166
  }
137
167
  renameSync(tmp, join(r.dir, out))
138
168
  await Bun.write(join(r.dir, EDIT), printEdit(e))
169
+ dropCopies(r.dir)
139
170
  retire(m, out)
140
171
  retire(m, POSTER)
141
172
  m.files[out] = await factOf(join(r.dir, out))
142
173
  await poster(join(r.dir, out), m.still ? 0 : editedLength(e, m.seconds), join(r.dir, POSTER))
143
174
  m.files[POSTER] = await factOf(join(r.dir, POSTER))
175
+ cut({ text: printEdit(e), sha: m.files[out]!.sha, size: m.files[out]!.size })
144
176
  writeMeta(r.dir, m)
145
177
  return { ...m, dir: r.dir, root: r.root }
146
178
  }
@@ -21,9 +21,20 @@ export type RecView = {
21
21
  local: boolean
22
22
  /** what plays is up in the Space (its links work); false while it uploads */
23
23
  up: boolean
24
+ /** the size of what plays, in bytes */
25
+ bytes: number
26
+ /** the save that plays: 0 is the take as shot */
27
+ version: number
28
+ /** every save that changed something, oldest first: its edit as text, and the size of what it rendered */
29
+ versions: { n: number; at: string; text: string; bytes: number }[]
30
+ /** the size of the WebP a copy made of what plays (a still's WebP HQ, a video's animated one); null: not made yet */
31
+ webp: number | null
24
32
  publicUrl: string | null
25
33
  }
26
34
 
35
+ /** the longest video copied as an animated WebP: past it the file is too big to paste anywhere */
36
+ export const ANIM_MAX_SECONDS = 60
37
+
27
38
  export type RecList = { recordings: RecView[]; repos: string[]; repo: string; presets: { id: string; label: string; key: string | null }[]; problems: string[] }
28
39
 
29
40
  /** where the page reads a file of a recording: the disk, else a signed link (a redirect) */
@@ -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
  }
@@ -4,16 +4,16 @@
4
4
  // private in the Space. The card named is the thread's first version, so a later version approved again replaces its
5
5
  // change instead of adding a second
6
6
  import { ensureLocal } from '../review/media-read.ts'
7
- import { isApproved, verdictOf, type Item, type ReviewItem } from '../review/model.ts'
7
+ import { isApproved, verdictOf, type Item, type ReviewItem, type ReviewStatus } from '../review/model.ts'
8
8
  import { stageablesOf } from '../review/stage-card.ts'
9
- import { readAll, readItem, storeDir } from '../review/store.ts'
9
+ import { addMessage, readAll, readItem, storeDir } from '../review/store.ts'
10
10
  import { threadOfItem, threadsOf } from '../review/threads.ts'
11
11
  import { commitPaths } from '../social/writes.ts'
12
12
  import { idleBefore } from './before.ts'
13
13
  import type { PostRating } from '../identities/rating.ts'
14
14
  import { changesOf, isClip, NEXT, ratingOf, type Change, type Picture, type Shot } from './model.ts'
15
15
  import { keepPicture } from './pictures.ts'
16
- import { addChange, readRelease, undeclaredReleases, writeRelease } from './store.ts'
16
+ import { addChange, dropCardChange, readRelease, releaseVersions, undeclaredReleases, writeRelease } from './store.ts'
17
17
 
18
18
  /** the versions of a card, newest first, following `supersedes` */
19
19
  export function versionsOf(dir: string, x: ReviewItem): Item[] {
@@ -104,6 +104,48 @@ export async function onVerdict(root: string, id: string): Promise<string | null
104
104
  return file
105
105
  }
106
106
 
107
+ /** after an approval taken back (a reopen, or another verdict in its place): next.md drops the card's change, committed,
108
+ * while no version of its thread stays approved. What happened, in words for the card's thread; null when the card
109
+ * brought no change. A change already released stays, and the words say so */
110
+ export async function onTakeBack(root: string, id: string): Promise<string | null> {
111
+ const dir = storeDir(root)
112
+ const x = readItem(dir, id)
113
+ const versions = x ? versionsOf(dir, x) : []
114
+ if (!versions.some((v) => v.changelog)) return null
115
+ const card = versions.at(-1)!.id
116
+ const still = threadOfItem(id, threadsOf(readAll(dir).items))?.versions.find((v) => isApproved(verdictOf(v)?.status ?? 'rejected'))
117
+ if (still) return `the approval was taken back, and next.md keeps this card's change: its version ${still.item.id} is still approved`
118
+ const file = dropCardChange(root, card)
119
+ if (file) {
120
+ commitPaths([file], `releases: next drops the change of the card ${card}, its approval taken back`)
121
+ return 'the approval was taken back: next.md no longer holds this change (git keeps its words)'
122
+ }
123
+ const shipped = releaseVersions(root).find((v) => v !== NEXT && readRelease(root, v)?.categories.some((c) => c.changes.some((ch) => ch.card === card)))
124
+ return shipped ? `the approval was taken back, but this change already shipped in ${shipped}: that release still holds it` : null
125
+ }
126
+
127
+ /** what a change of the owner's answer does to next.md, from the hub or the CLI: an approval adds the card's change, an
128
+ * approval taken back (`was`, the status before) drops it. A failure and every take back say so on the card's thread and
129
+ * in the log, so the release never moves in silence */
130
+ export async function followAnswer(root: string, id: string, was: ReviewStatus | null): Promise<void> {
131
+ try {
132
+ const x = readItem(storeDir(root), id)
133
+ const now = x ? (verdictOf(x)?.status ?? null) : null
134
+ if (now !== null && isApproved(now)) await onVerdict(root, id)
135
+ else if (was !== null && isApproved(was)) {
136
+ const said = await onTakeBack(root, id)
137
+ if (said) {
138
+ console.error(`review: ${id}: ${said}`)
139
+ addMessage(storeDir(root), id, 'releases', said)
140
+ }
141
+ }
142
+ } catch (e) {
143
+ const why = (e as Error).message
144
+ console.error(`FAIL: the release did not follow the answer on ${id}: ${why}`)
145
+ addMessage(storeDir(root), id, 'releases', `the release did not follow this answer: ${why}. Run sk releases add --card ${id}, or edit .shipkit/releases/next.md`)
146
+ }
147
+ }
148
+
107
149
  /** the version of a card's thread a change stands for: its newest approved one, else its newest */
108
150
  function approvedOf(dir: string, id: string): ReviewItem | null {
109
151
  const t = threadOfItem(id, threadsOf(readAll(dir).items))
@@ -266,6 +266,12 @@ export function upsertChange(r: Release, category: string, change: Change): Rele
266
266
  return { ...r, categories: cats.filter((c) => c.changes.length > 0) }
267
267
  }
268
268
 
269
+ /** the release without the change of that card; a category left empty goes */
270
+ export const withoutCard = (r: Release, card: string): Release => ({
271
+ ...r,
272
+ categories: r.categories.map((c) => ({ ...c, changes: c.changes.filter((x) => x.card !== card) })).filter((c) => c.changes.length > 0),
273
+ })
274
+
269
275
  export const changesOf = (r: Release): Change[] => r.categories.flatMap((c) => c.changes)
270
276
 
271
277
  /** a change's key on a page: its card, else its title */
@@ -4,7 +4,7 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from 'node:f
4
4
  import { join } from 'node:path'
5
5
  import { atomicWrite } from '../core/locked-write.ts'
6
6
  import { LAYOUT } from '../core/layout.ts'
7
- import { byVersion, emptyRelease, fileOf, NEXT, parseRelease, renderRelease, upsertChange, type Change, type Release } from './model.ts'
7
+ import { byVersion, emptyRelease, fileOf, NEXT, parseRelease, renderRelease, upsertChange, withoutCard, type Change, type Release } from './model.ts'
8
8
 
9
9
  const FILE = /^(next|\d+\.\d+\.\d+)\.md$/
10
10
 
@@ -30,6 +30,13 @@ export function releaseVersions(root: string): string[] {
30
30
  .sort(byVersion)
31
31
  }
32
32
 
33
+ /** next without the change of that card, written; the file, or null when next holds no change of it */
34
+ export function dropCardChange(root: string, card: string): string | null {
35
+ const r = readRelease(root, NEXT)
36
+ if (!r?.categories.some((c) => c.changes.some((x) => x.card === card))) return null
37
+ return writeRelease(root, withoutCard(r, card))
38
+ }
39
+
33
40
  /** one release file, parsed; null when there is none */
34
41
  export function readRelease(root: string, version: string): Release | null {
35
42
  const f = releaseFile(root, version)
@@ -65,9 +65,11 @@ export type ServeConfig = {
65
65
  }
66
66
  /** agent/ graph entrypoint (default: index.md AND README.md) */
67
67
  agentIndex?: string
68
- /** off-machine hostname for the hub, as in a tailnet MagicDNS name. It
69
- * prints beside localhost and rides on every ping message, because a
70
- * phone cannot resolve localhost */
68
+ /** off-machine hostname for the hub, overriding this Mac's tailnet name,
69
+ * which is read from tailscale when this is absent. It prints beside
70
+ * localhost and rides on every ping message, because a phone cannot
71
+ * resolve localhost. A Mac's own name: never set it in a repo that
72
+ * more than one Mac checks out */
71
73
  publicHost?: string
72
74
  /** the ids of the global processes this repo needs (any house repo's
73
75
  * `globalProcess` unit files). The home rail marks the repo while one is off */
@@ -81,6 +83,11 @@ export type ServeConfig = {
81
83
  * `sk annex offload` moves scratch there behind a symlink. Present only
82
84
  * while `sk annex init` marked the root (wiki tools/shipkit/annex.md) */
83
85
  annexes?: import('./annex/annex.ts').AnnexSpec[]
86
+ /** the scratch policy of every house repo, read only in the house config:
87
+ * folders born on the annex, the cap and the free space floor that move
88
+ * stale scratch there; a repo's own `annex` adds to it (wiki
89
+ * tools/shipkit/annex.md, Scratch by itself) */
90
+ annexScratch?: import('./annex/tidy.ts').AnnexScratch
84
91
  /** the secret whose value is a Cloudflare API token, read through
85
92
  * `credsReadCommand`, only in the house config: the site desk asks Pages
86
93
  * for a site's last production deployment with it */
@@ -117,6 +124,9 @@ export type RepoConfig = {
117
124
  /** machine-only state of this repo the backup keeps beyond its own rule (wiki tools/shipkit/media-store.md,
118
125
  * Backup, What a repo adds). Paths are repo relative; what git tracks never goes; a secret is refused as always */
119
126
  backup?: RepoBackup
127
+ /** this repo's scratch on the annex, beside the house's `serve.annexScratch` (wiki tools/shipkit/annex.md,
128
+ * Scratch by itself): folders born there, folders that never leave the Mac, its own cap */
129
+ annex?: import('./annex/tidy.ts').RepoAnnex
120
130
  /** prefix for contract fix: pointers (docs checkout or URL) — written by init, never baked in */
121
131
  docsBase?: string
122
132
  /** a floor slot: a def with a `cmd` or `logic` REPLACES it, and a def
@@ -374,7 +384,7 @@ export type RepoConfig = {
374
384
  logDir?: string
375
385
  }
376
386
 
377
- const KNOWN_KEYS = new Set(['name', 'venues', 'social', 'speaksAs', 'backup', 'docsBase', 'defaults', 'tasks', 'asks', 'creds', 'credsCommand', 'credsReadCommand', 'notifyCommand', 'contracts', 'gitignore', 'ignoredInputs', 'untrackGenerated', 'nested', 'off', 'when', 'budgets', 'ruleExempt', 'visibility', 'archived', 'reviewer', 'oneWayIn', 'rules', 'release', 'units', 'notReleasable', 'vendored', 'hooks', 'checkDefaults', 'tui', 'serve', 'recorder', 'identity', 'logDir', 'smoke', 'tests', 'browsers', 'start'])
387
+ const KNOWN_KEYS = new Set(['name', 'venues', 'social', 'speaksAs', 'backup', 'annex','docsBase', 'defaults', 'tasks', 'asks', 'creds', 'credsCommand', 'credsReadCommand', 'notifyCommand', 'contracts', 'gitignore', 'ignoredInputs', 'untrackGenerated', 'nested', 'off', 'when', 'budgets', 'ruleExempt', 'visibility', 'archived', 'reviewer', 'oneWayIn', 'rules', 'release', 'units', 'notReleasable', 'vendored', 'hooks', 'checkDefaults', 'tui', 'serve', 'recorder', 'identity', 'logDir', 'smoke', 'tests', 'browsers', 'start'])
378
388
 
379
389
  export function defineRepo(c: RepoConfig): RepoConfig {
380
390
  if (typeof c.name !== 'string' || c.name === '') throw new Error('defineRepo: name is required')
@@ -3,6 +3,10 @@
3
3
  // folds into one thread, nothing is rewritten). The paged list's rows and its query. Pure and browser safe: the routes
4
4
  // send these shapes, the hub page draws them
5
5
  import {
6
+ inWork,
7
+ UPDATE_WORDS,
8
+ updatesOf,
9
+ type UpdateState,
6
10
  isMarkItem,
7
11
  isReply,
8
12
  isStale,
@@ -86,6 +90,10 @@ export interface ReplyCell extends CellOf<'reply'> {
86
90
  op?: 'ask' | 'answer'
87
91
  /** the other party marked it seen */
88
92
  read: boolean
93
+ /** an agent's update: its number on the item from 1, its state, the view of the item that holds its media */
94
+ update?: { k: number; state: UpdateState; view?: number }
95
+ /** his hint on an update: the update's cell id, its number and state */
96
+ re?: { id: string; k: number; state: UpdateState }
89
97
  }
90
98
 
91
99
  /** what the owner or a player raised (its item, its opening words and rectangles), or the owner's mark on the subject */
@@ -176,6 +184,7 @@ function messageCells(x: ReviewItem, n: number, opening: Message | undefined): C
176
184
  const current = verdictOf(x)?.id
177
185
  const read = { agent: readBy(x, 'agent'), owner: readBy(x, 'owner') }
178
186
  const other = (who: string): Party => (partyOf(who) === 'owner' ? 'agent' : 'owner')
187
+ const updates = updatesOf(x)
179
188
  const out: Cell[] = []
180
189
  for (const m of x.thread) {
181
190
  if (m.op === 'seen' || m === opening) continue
@@ -204,7 +213,13 @@ function messageCells(x: ReviewItem, n: number, opening: Message | undefined): C
204
213
  out.push({ ...base, kind: 'note', ...(m.text !== undefined ? { text: m.text } : {}), rects: m.rects ?? [], ...(m.image ? { image: m.image } : {}), rate: r, read: wasRead, summary: `marked ${said}${m.text ? `: ${firstLine(m.text)}` : ''}` })
205
214
  } else if (isReply(m)) {
206
215
  const op = m.op === 'ask' || m.op === 'answer' ? m.op : undefined
207
- out.push({ ...base, kind: 'reply', text: m.text ?? '', ...(m.image ? { image: m.image } : {}), ...(op ? { op } : {}), read: wasRead, summary: firstLine(m.text) })
216
+ const k = updates.findIndex((u) => u.id === m.id)
217
+ const update = k >= 0 && m.update ? { k: k + 1, state: m.update.state, ...(m.update.view !== undefined ? { view: m.update.view } : {}) } : undefined
218
+ const rk = m.re ? updates.findIndex((u) => u.id === m.re) : -1
219
+ const reOn = rk >= 0 ? updates[rk]!.update : undefined
220
+ const re = reOn ? { id: `${id}/${m.re}`, k: rk + 1, state: reOn.state } : undefined
221
+ const said = update ? `${UPDATE_WORDS[update.state]}: ` : re ? `on update ${re.k}: ` : ''
222
+ out.push({ ...base, kind: 'reply', text: m.text ?? '', ...(m.image ? { image: m.image } : {}), ...(op ? { op } : {}), read: wasRead, ...(update ? { update } : {}), ...(re ? { re } : {}), summary: `${said}${firstLine(m.text)}` })
208
223
  } else if (m.op !== undefined) {
209
224
  const commit = m.fix?.commit
210
225
  out.push({
@@ -365,6 +380,8 @@ export interface ThreadRow {
365
380
  pair: boolean
366
381
  choice: boolean
367
382
  wip: boolean
383
+ /** the head's newest agent update: its state and line; its picture is the row's thumb when it carries one */
384
+ update?: { state: UpdateState; text: string; at: string }
368
385
  waits: boolean
369
386
  active: boolean
370
387
  /** agent words the owner has not read on any of its items */
@@ -446,6 +463,9 @@ function rowOf(t: Thread, items: readonly ReviewItem[], followed: ReadonlySet<st
446
463
  const m = x.thread.at(-1)?.at ?? x.item.created
447
464
  return m > u ? m : u
448
465
  }, h.item.created)
466
+ const newest = updatesOf(h).at(-1)
467
+ const shows = newest?.update?.view !== undefined ? h.item.views[newest.update.view] : undefined
468
+ const thumbOf = shows ?? first
449
469
  return {
450
470
  head: h.item.id,
451
471
  title: h.item.title,
@@ -461,11 +481,12 @@ function rowOf(t: Thread, items: readonly ReviewItem[], followed: ReadonlySet<st
461
481
  move: moveOf(stateOf(h, followed.has(h.item.id)).state),
462
482
  versions: t.versions.length,
463
483
  views: h.item.views.length,
464
- thumb: first ? thumbFileOf(first) || null : null,
484
+ thumb: thumbOf ? thumbFileOf(thumbOf) || null : null,
465
485
  clip: h.item.views.some((v) => !isGallery(v) && v.clip !== undefined),
466
486
  pair: first !== undefined && !isGallery(first) && isPair(first.files),
467
487
  choice: h.item.choice === true,
468
- wip: h.item.wip !== undefined,
488
+ wip: inWork(h),
489
+ ...(newest?.update ? { update: { state: newest.update.state, text: newest.text ?? '', at: newest.at } } : {}),
469
490
  waits: waits(h),
470
491
  active: isActive(t, now),
471
492
  unread: members.some((x) => unreadBy(x, 'owner').length > 0),