rvlib-shipkit 2.22.1 → 2.23.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 (52) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/package.json +1 -1
  3. package/src/annex/annex.ts +3 -0
  4. package/src/annex/born.ts +464 -0
  5. package/src/annex/flush.ts +46 -0
  6. package/src/annex/offload.ts +171 -38
  7. package/src/annex/snapshots.ts +53 -0
  8. package/src/annex/tidy.ts +368 -0
  9. package/src/checks/SK041-annex-links.check.ts +4 -2
  10. package/src/checks/SK043-scratch-on-the-mac.check.ts +45 -0
  11. package/src/cli/cmd_Annex.ts +60 -9
  12. package/src/cli/cmd_Home.ts +28 -0
  13. package/src/cli/cmd_Rec.ts +17 -7
  14. package/src/cli/cmd_Review.ts +27 -3
  15. package/src/core/machine-db.ts +8 -0
  16. package/src/home/claude-temp.ts +139 -0
  17. package/src/home/daemon-jobs.ts +10 -3
  18. package/src/home/global-units.ts +3 -0
  19. package/src/home/machine-stores.ts +27 -3
  20. package/src/home/pm.ts +4 -1
  21. package/src/home/run-pm.ts +1 -0
  22. package/src/identities/identities.ts +92 -24
  23. package/src/media-store/daemon.ts +2 -2
  24. package/src/media-store/purge.ts +4 -0
  25. package/src/recordings/load.ts +3 -3
  26. package/src/recordings/model.ts +7 -0
  27. package/src/recordings/open.ts +12 -0
  28. package/src/recordings/presets.ts +12 -5
  29. package/src/recordings/recorder-app/Capture.swift +34 -5
  30. package/src/recordings/recorder-app/Clip.swift +126 -17
  31. package/src/recordings/recorder-app/Editor.swift +177 -7
  32. package/src/recordings/recorder-app/Hud.swift +189 -0
  33. package/src/recordings/recorder-app/Tray.swift +179 -36
  34. package/src/recordings/recorder-app/icon.svg +16 -0
  35. package/src/recordings/recorder-app/main.swift +349 -18
  36. package/src/recordings/recorder-app.ts +8 -4
  37. package/src/recordings/recorder.shipkit.ts +2 -1
  38. package/src/recordings/routes.ts +52 -6
  39. package/src/recordings/run-recorder.ts +2 -1
  40. package/src/recordings/share.ts +27 -0
  41. package/src/recordings/take.ts +36 -4
  42. package/src/recordings/view.ts +11 -0
  43. package/src/repo-config.ts +9 -1
  44. package/src/review/model.ts +33 -4
  45. package/src/serve/hub-app/hub.css +4 -0
  46. package/src/serve/hub-app/recordings-st.ts +135 -24
  47. package/src/serve/hub-app/recordings-view.tsx +293 -54
  48. package/src/serve/hub-app/recordings.css +77 -24
  49. package/src/shipkit-files.ts +5 -0
  50. package/src/social/drafts.ts +4 -3
  51. package/src/social/load.ts +7 -2
  52. package/src/social/publish/discord.ts +10 -3
@@ -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) */
@@ -81,6 +81,11 @@ export type ServeConfig = {
81
81
  * `sk annex offload` moves scratch there behind a symlink. Present only
82
82
  * while `sk annex init` marked the root (wiki tools/shipkit/annex.md) */
83
83
  annexes?: import('./annex/annex.ts').AnnexSpec[]
84
+ /** the scratch policy of every house repo, read only in the house config:
85
+ * folders born on the annex, the cap and the free space floor that move
86
+ * stale scratch there; a repo's own `annex` adds to it (wiki
87
+ * tools/shipkit/annex.md, Scratch by itself) */
88
+ annexScratch?: import('./annex/tidy.ts').AnnexScratch
84
89
  /** the secret whose value is a Cloudflare API token, read through
85
90
  * `credsReadCommand`, only in the house config: the site desk asks Pages
86
91
  * for a site's last production deployment with it */
@@ -117,6 +122,9 @@ export type RepoConfig = {
117
122
  /** machine-only state of this repo the backup keeps beyond its own rule (wiki tools/shipkit/media-store.md,
118
123
  * Backup, What a repo adds). Paths are repo relative; what git tracks never goes; a secret is refused as always */
119
124
  backup?: RepoBackup
125
+ /** this repo's scratch on the annex, beside the house's `serve.annexScratch` (wiki tools/shipkit/annex.md,
126
+ * Scratch by itself): folders born there, folders that never leave the Mac, its own cap */
127
+ annex?: import('./annex/tidy.ts').RepoAnnex
120
128
  /** prefix for contract fix: pointers (docs checkout or URL) — written by init, never baked in */
121
129
  docsBase?: string
122
130
  /** a floor slot: a def with a `cmd` or `logic` REPLACES it, and a def
@@ -374,7 +382,7 @@ export type RepoConfig = {
374
382
  logDir?: string
375
383
  }
376
384
 
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'])
385
+ 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
386
 
379
387
  export function defineRepo(c: RepoConfig): RepoConfig {
380
388
  if (typeof c.name !== 'string' || c.name === '') throw new Error('defineRepo: name is required')
@@ -711,15 +711,44 @@ export interface Watcher extends WatchFilter {
711
711
  export const coversCard = (f: WatchFilter, x: ReviewItem): boolean =>
712
712
  (f.session === null || (x.item.origin.by === 'agent' && x.item.origin.session === f.session)) && (f.lane === null || laneOf(x) === f.lane)
713
713
 
714
+ /** who answers an agent's card, its reply or its seen: the worker of a live claim on it, else the lane that made it,
715
+ * else (a card with no lane) the session that sent it. null when `me` is that one, else why not and the way out.
716
+ * Another session hearing the verdict (a bare watch) is refused, so it never answers over the maker; a plain approval,
717
+ * which owes nothing, anyone marks seen. An item he raised, a player's or an auto one: the claim rules decide */
718
+ export function notAnswererOf(x: ReviewItem, me: { lane: string | null; session: string | null }, op: 'reply' | 'seen'): string | null {
719
+ const o = x.item.origin
720
+ if (o.by !== 'agent') return null
721
+ const s = stateOf(x, false)
722
+ if (op === 'seen' && s.state === 'closed' && s.why === 'approved') return null
723
+ const id = x.item.id
724
+ const takeOver = `another lane takes it over with sk review claim ${id} --as <lane>`
725
+ const claimed = s.state === 'claimed' && s.since !== undefined ? s.worker : undefined
726
+ const lane = claimed ?? o.lane
727
+ if (lane) return me.lane === lane ? null : `${id} is answered by lane ${lane} (${claimed ? 'its claim' : 'it made the card'}): as that lane, SK_AGENT=${lane} or --as ${lane}; ${takeOver}`
728
+ if (!o.session || me.session === o.session) return null
729
+ return `${id} is answered by the session that sent it (${o.session.slice(0, 8)}): ${takeOver}`
730
+ }
731
+
714
732
  /** the live watchers that will read his answer on any of these cards */
715
733
  export const listenersOf = (cards: readonly ReviewItem[], watchers: readonly Watcher[]): Watcher[] => watchers.filter((w) => cards.some((x) => coversCard(w, x)))
716
734
 
717
735
  /** who listens, in plain words: one lane's watch by its lane, any other by « an agent », several by their count */
718
736
  export function listenWords(ws: readonly Watcher[]): string {
719
- const [w] = ws
720
- if (w === undefined) return 'nobody listens'
721
- if (ws.length > 1) return `${ws.length} agents listening`
722
- return w.lane ? `the ${w.lane} lane is listening` : 'an agent is listening'
737
+ if (ws.length === 0) return 'nobody listens'
738
+ // a filtered watch is the card's own (its session or its lane); a bare one hears every card, for the dispatcher
739
+ const own = ws.filter((w) => w.lane !== null || w.session !== null)
740
+ const bare = ws.length - own.length
741
+ if (own.length === 0) return 'only a watch of every card hears it'
742
+ const lane = own.find((w) => w.lane !== null)?.lane
743
+ const head = lane ? `the ${lane} lane is listening` : 'its agent is listening'
744
+ return bare === 0 ? head : `${head} · ${bare} more ${bare === 1 ? 'watches' : 'watch'} every card`
745
+ }
746
+
747
+ /** why a bare watch may not start: another one lives in the repo, so a verdict would reach two sessions. null when
748
+ * none does. A repo keeps one, the dispatcher's; every other session watches its own cards or its lane's */
749
+ export function bareWatchTaken(live: readonly Watcher[], self: number): string | null {
750
+ const other = live.find((w) => w.pid !== self && w.lane === null && w.session === null)
751
+ return other ? `a watch of every card already runs (pid ${other.pid}): a repo keeps one, the dispatcher's. Yours: sk review watch --mine, or --lane <id>` : null
723
752
  }
724
753
 
725
754
  /** what `review add` says when no live watch of the card's own session or lane will read his answer, else null: an
@@ -12,6 +12,9 @@
12
12
  --accent:#6b8fb3;--sel:#1a2430;--chk1:#16181b;--chk2:#121417;
13
13
  /* state, and nothing else: red broken · orange taste pending · green measured passing */
14
14
  --red:#d2605c;--warn:#cf9a4e;--ok:#6faa86;--blue:#6f9bd1;
15
+ /* the recorder tray's copy buttons: a blue, a green and a purple dark enough for white text on them (5 to 1 at
16
+ least), the same in the tray, so a copy mode reads the same in both */
17
+ --recfile:#0b63ce;--recwebp:#1a7f43;--reclink:#8a3fc4;--recink:#ffffff;
15
18
  /* the colourless ones: scrims, shadows, masks and the ruler hairlines */
16
19
  --scrim:rgba(0,0,0,.6);--shadow:rgba(0,0,0,.62);--solid:#000;
17
20
  --hi1:rgba(255,255,255,.28);--hi2:rgba(255,255,255,.16);--hi3:rgba(255,255,255,.07);
@@ -38,6 +41,7 @@
38
41
  --bg-side:#e6e9ee;--bg-top:#eaedf1;--bg-dock:#e3e7ec;--panel2:#e3e7ec;--line:#bcc4ce;--ink:#16191d;--dim:#464b51;
39
42
  --accent:#355e87;--sel:#d2e0ef;--chk1:#e3e7ec;--chk2:#f7f8fa;
40
43
  --red:#a83733;--warn:#86550b;--ok:#256e45;--blue:#275fa0;
44
+ --recfile:#0b63ce;--recwebp:#1a7f43;--reclink:#8a3fc4;--recink:#ffffff;
41
45
  --scrim:rgba(20,24,30,.35);--shadow:rgba(20,24,30,.16);--solid:#000;
42
46
  --hi1:rgba(0,0,0,.2);--hi2:rgba(0,0,0,.11);--hi3:rgba(0,0,0,.045);
43
47
  --ground:#e3ede6;--groundline:#c6d6cb;--tag:#eef2f6;
@@ -11,6 +11,20 @@ import type { HomeSt } from './home-st.ts'
11
11
  import { ownTrouble, reach } from './reach.ts'
12
12
 
13
13
  const REPO_KEY = 'home:recordings:repo'
14
+ const COPY_KEY = 'home:recordings:copy'
15
+
16
+ /** what ⌘C copies in the editor: the capture's file (a still as PNG), a still as WebP HQ, or a private link */
17
+ export const COPY_MODES = ['file', 'webp-hq', 'link'] as const
18
+ export type CopyMode = (typeof COPY_MODES)[number]
19
+
20
+ function keptCopy(): CopyMode {
21
+ try {
22
+ const m = globalThis.localStorage?.getItem(COPY_KEY)
23
+ return (COPY_MODES as readonly string[]).includes(m ?? '') ? (m as CopyMode) : 'file'
24
+ } catch {
25
+ return 'file'
26
+ }
27
+ }
14
28
  const API = '/api/home/recordings'
15
29
 
16
30
  function kept(): string {
@@ -71,7 +85,7 @@ export class EditorSt {
71
85
 
72
86
  constructor(public rec: RecView, private page: RecordingsSt, draft: string | null = null) {
73
87
  this.text = draft ?? rec.edit
74
- makeAutoObservable<this, 'page' | 'raf' | 'past' | 'future' | 'wroteAt'>(this, { rec: false, page: false, video: false, raf: false, past: false, future: false, wroteAt: false })
88
+ makeAutoObservable<this, 'page' | 'raf' | 'past' | 'future' | 'wroteAt'>(this, { rec: observableRef, page: false, video: false, raf: false, past: false, future: false, wroteAt: false })
75
89
  }
76
90
 
77
91
  get cropping(): boolean {
@@ -108,6 +122,29 @@ export class EditorSt {
108
122
  return this.rec.seconds
109
123
  }
110
124
 
125
+ /** the save whose edit the text is now (0: the take as shot); null while the text is no save yet */
126
+ get versionNow(): number | null {
127
+ const t = this.text.trim()
128
+ if (t === this.rec.edit.trim()) return this.rec.version
129
+ const v = [...this.rec.versions].reverse().find((x) => x.text.trim() === t)
130
+ return v ? v.n : t === '' ? 0 : null
131
+ }
132
+
133
+ /** the number the next save takes */
134
+ get nextVersion(): number {
135
+ return (this.rec.versions.at(-1)?.n ?? this.rec.version) + 1
136
+ }
137
+
138
+ /** a save's edit in the editor again (0: the take as shot), one undo step; ⌘S then makes it the one that plays */
139
+ loadVersion(n: number): void {
140
+ const v = this.rec.versions.find((x) => x.n === n)
141
+ this.wroteAt = 0
142
+ this.remember()
143
+ this.text = v?.text ?? ''
144
+ this.selected = null
145
+ this.page.keepDraft(this)
146
+ }
147
+
111
148
  /** the pieces that play, or the reason none does */
112
149
  get plays(): { from: number; to: number; factor: number }[] {
113
150
  try {
@@ -229,18 +266,6 @@ export class EditorSt {
229
266
  this.updateMark(i, { ...m, span: whole ? null : span && { from: round(span.from), to: round(span.to) } })
230
267
  }
231
268
 
232
- /** the trim: what plays starts at `from` and ends at `to`, the cuts between kept */
233
- setTrim(from: number, to: number): void {
234
- const a = Math.max(0, round(Math.min(from, to - 0.2)))
235
- const b = Math.min(this.length, round(Math.max(to, a + 0.2)))
236
- const keep = within(this.kept, { from: a, to: b })
237
- const parts = keep.length === 0 ? [{ from: a, to: b }] : keep
238
- if (parts[0]!.from > a) parts[0] = { ...parts[0]!, from: a }
239
- if (parts.at(-1)!.to < b) parts[parts.length - 1] = { ...parts.at(-1)!, to: b }
240
- const whole = parts.length === 1 && parts[0]!.from <= 0.05 && parts[0]!.to >= this.length - 0.05
241
- this.write({ ...this.edit, keep: whole ? [] : parts })
242
- }
243
-
244
269
  startText(at: Pt): void {
245
270
  this.typing = { at, value: '' }
246
271
  }
@@ -345,10 +370,57 @@ export class EditorSt {
345
370
  cut(): void {
346
371
  const s = this.selection
347
372
  if (!s) return this.page.say('mark a part first: i at its start, o at its end')
373
+ if (this.cutSpan(s)) this.clearMarks()
374
+ }
375
+
376
+ /** `s` taken out of what plays (a part painted red on the cuts lane, or the selection); false when it would cut
377
+ * everything */
378
+ cutSpan(span: Span): boolean {
379
+ const s = { from: Math.max(0, round(span.from)), to: Math.min(this.length, round(span.to)) }
348
380
  const keep = without(this.kept, s)
349
- if (keep.length === 0) return this.page.say('that would cut everything')
350
- this.write({ ...this.edit, keep: keep.length === 1 && keep[0]!.from === 0 && keep[0]!.to >= this.length - 0.05 ? [] : keep, speed: this.edit.speed.filter((p) => without([p], s).length > 0) })
351
- this.clearMarks()
381
+ if (keep.length === 0) {
382
+ this.page.say('that would cut everything')
383
+ return false
384
+ }
385
+ this.writeKeep(keep, this.edit.speed.filter((p) => without([p], s).length > 0))
386
+ return true
387
+ }
388
+
389
+ /** a cut part plays again: `s` back into what is kept, touching parts joined */
390
+ restore(span: Span): void {
391
+ const s = { from: Math.max(0, round(span.from)), to: Math.min(this.length, round(span.to)) }
392
+ const all = [...this.kept, s].sort((a, b) => a.from - b.from)
393
+ const keep: Span[] = []
394
+ for (const k of all) {
395
+ const last = keep.at(-1)
396
+ if (last && k.from <= last.to + 0.05) last.to = Math.max(last.to, k.to)
397
+ else keep.push({ ...k })
398
+ }
399
+ this.writeKeep(keep, this.edit.speed)
400
+ }
401
+
402
+ /** a drag on the cuts lane from `from`: started on a red part it puts `span` back, anywhere else it cuts it out */
403
+ paint(from: number, span: Span): void {
404
+ if (this.removed.some((c) => from >= c.from && from <= c.to)) this.restore(span)
405
+ else this.cutSpan(span)
406
+ }
407
+
408
+ /** the parts cut out, in order: what the cuts lane paints red */
409
+ get removed(): Span[] {
410
+ const out: Span[] = []
411
+ let at = 0
412
+ for (const k of this.kept) {
413
+ if (k.from - at >= 0.05) out.push({ from: at, to: k.from })
414
+ at = k.to
415
+ }
416
+ if (this.length - at >= 0.05) out.push({ from: at, to: this.length })
417
+ return out
418
+ }
419
+
420
+ /** what is kept written: the whole take writes no keep line */
421
+ private writeKeep(keep: Span[], speed: typeof this.edit.speed): void {
422
+ const whole = keep.length === 1 && keep[0]!.from <= 0.05 && keep[0]!.to >= this.length - 0.05
423
+ this.write({ ...this.edit, keep: whole ? [] : keep, speed })
352
424
  }
353
425
 
354
426
  /** only the selection kept: both ends trimmed */
@@ -389,15 +461,22 @@ export class EditorSt {
389
461
  this.selected = null
390
462
  }
391
463
 
464
+ /** the edit saved as a new version and sent up; nothing asked of the hub when the text is the one already saved.
465
+ * The editor stays as it is: its playhead, its tool, its undo */
392
466
  async save(): Promise<void> {
393
467
  if (this.parsed.error) return this.page.say(this.parsed.error)
468
+ if (this.exporting) return
469
+ if (!this.dirty) return this.page.say(`nothing changed since ${this.rec.version > 0 ? `v${this.rec.version}` : 'the take'}: no new save, no upload`)
394
470
  this.exporting = true
395
471
  try {
396
472
  const r = await this.page.post<{ recording: RecView; said: string }>(this.rec, 'edit', { text: this.text })
397
- if (r) {
398
- this.page.dropDraft(this.rec)
399
- this.page.replace(r.recording)
400
- }
473
+ if (!r) return
474
+ runInAction(() => {
475
+ this.rec = r.recording
476
+ this.text = r.recording.edit
477
+ })
478
+ this.page.dropDraft(r.recording)
479
+ this.page.replace(r.recording)
401
480
  } finally {
402
481
  runInAction(() => (this.exporting = false))
403
482
  }
@@ -421,10 +500,16 @@ export class RecordingsSt {
421
500
  open: { repo: string; id: string } | null = null
422
501
  /** every thumb at once, big, in place of the editor */
423
502
  gallery = false
503
+ /** the recorder app's window (`?solo=1`): its addresses keep that, so a move inside it is never another page */
504
+ solo = typeof location !== 'undefined' && new URLSearchParams(location.search).has('solo')
424
505
  editor: EditorSt | null = null
425
506
  busy = ''
426
507
  /** the thumb whose delete waits for its second click */
427
508
  arming: string | null = null
509
+ /** what ⌘C copies, kept in the browser */
510
+ copyMode: CopyMode = keptCopy()
511
+ /** the mode a ⌘C copy runs in, until the hub answers */
512
+ copying: CopyMode | null = null
428
513
  private gen = 0
429
514
  private sayTimer: ReturnType<typeof setTimeout> | null = null
430
515
  /** each capture's edit text not exported yet, by `<repo>/<id>`: it waits there while another is open */
@@ -450,7 +535,28 @@ export class RecordingsSt {
450
535
  }
451
536
 
452
537
  get address(): string {
453
- return this.gallery ? '/recordings#gallery' : recordingAddress(this.open)
538
+ const a = this.gallery ? '/recordings#gallery' : recordingAddress(this.open)
539
+ return this.solo ? a.replace(/^\/recordings/, '/recordings?solo=1') : a
540
+ }
541
+
542
+ setCopyMode(m: CopyMode): void {
543
+ this.copyMode = m
544
+ try { globalThis.localStorage?.setItem(COPY_KEY, m) } catch { /* private window: the pick lasts the tab */ }
545
+ }
546
+
547
+ /** ⌘C: the capture copied as the mode says; a video under WebP copies as an animated WebP */
548
+ async copy(r: RecView): Promise<void> {
549
+ const mode = this.copyMode
550
+ this.copying = mode
551
+ try {
552
+ await this.share(r, 'copy', { format: mode })
553
+ } finally {
554
+ runInAction(() => (this.copying = null))
555
+ }
556
+ // the WebP a copy made reads as ready: a video's is made before the answer, a still's by the recorder just after
557
+ if (mode !== 'webp-hq') return
558
+ await this.load()
559
+ if (this.current?.webp == null) setTimeout(() => void this.load(), 1500)
454
560
  }
455
561
 
456
562
  setRepo(r: string): void {
@@ -481,6 +587,11 @@ export class RecordingsSt {
481
587
  else this.drafts.delete(k)
482
588
  }
483
589
 
590
+ /** an edit a capture opens with, not saved yet (the address's `draft`) */
591
+ seedDraft(r: Pick<RecView, 'repo' | 'id'>, text: string): void {
592
+ this.drafts.set(`${r.repo}/${r.id}`, text)
593
+ }
594
+
484
595
  dropDraft(r: Pick<RecView, 'repo' | 'id'>): void {
485
596
  this.drafts.delete(`${r.repo}/${r.id}`)
486
597
  }
@@ -545,13 +656,13 @@ export class RecordingsSt {
545
656
  }
546
657
  }
547
658
 
548
- /** a share of a thumb (copy file, copy link, Finder): the edit open on it exported first, so what goes out is what he sees */
549
- async share(r: RecView, verb: 'link' | 'copy-file' | 'reveal', body: Record<string, unknown> = {}): Promise<void> {
659
+ /** a share of a thumb (copy file, copy link, Finder): the edit open on it saved first, so what goes out is what shows */
660
+ async share(r: RecView, verb: 'link' | 'copy-file' | 'copy' | 'reveal', body: Record<string, unknown> = {}): Promise<void> {
550
661
  const ed = this.editor
551
662
  if (ed && ed.rec.repo === r.repo && ed.rec.id === r.id && ed.dirty) {
552
663
  await ed.save()
553
664
  if (this.editor?.dirty) return
554
- } else if (this.hasDraft(r)) return this.say(`${r.name} has an edit not exported: open it and export it first`)
665
+ } else if (this.hasDraft(r)) return this.say(`${r.name} has an edit not saved: open it and save it first (⌘S)`)
555
666
  await this.post(r, verb, body)
556
667
  }
557
668