rvlib-shipkit 2.24.0 → 2.26.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 (99) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/package.json +2 -2
  3. package/src/agent-time/hooks.ts +329 -0
  4. package/src/agent-time/live.ts +153 -0
  5. package/src/agent-time/render.ts +14 -2
  6. package/src/agent-time/report.ts +56 -4
  7. package/src/agent-time/store.ts +59 -5
  8. package/src/annex/offload.ts +16 -7
  9. package/src/check.ts +3 -1
  10. package/src/checks/SK004-gitignore-policy.check.ts +32 -11
  11. package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
  12. package/src/checks/SK033-global-contribution.check.ts +1 -1
  13. package/src/checks/SK036-draft-media-size.check.ts +1 -1
  14. package/src/checks/SK040-release-words.check.ts +1 -1
  15. package/src/checks/SK042-post-kinds.check.ts +1 -1
  16. package/src/checks/SK045-slow-hooks.check.ts +47 -0
  17. package/src/checks/SK046-hook-records.check.ts +76 -0
  18. package/src/cli/cmd_Annex.ts +12 -7
  19. package/src/cli/cmd_Assets.ts +5 -5
  20. package/src/cli/cmd_Backup.ts +14 -6
  21. package/src/cli/cmd_Capacity.ts +10 -6
  22. package/src/cli/cmd_Checks.ts +12 -1
  23. package/src/cli/cmd_Ci.ts +2 -2
  24. package/src/cli/cmd_Commands.ts +11 -2
  25. package/src/cli/cmd_ConfigKeys.ts +17 -0
  26. package/src/cli/cmd_Home.ts +1 -1
  27. package/src/cli/cmd_Keys.ts +4 -1
  28. package/src/cli/cmd_Lanes.ts +35 -0
  29. package/src/cli/cmd_Mv.ts +6 -7
  30. package/src/cli/cmd_Rec.ts +22 -7
  31. package/src/cli/cmd_Releases.ts +30 -0
  32. package/src/cli/cmd_Review.ts +130 -43
  33. package/src/cli/cmd_Shot.ts +15 -4
  34. package/src/cli/cmd_Status.ts +6 -5
  35. package/src/cli/cmd_Time.ts +18 -6
  36. package/src/cli/cmd_Veille.ts +10 -6
  37. package/src/cli/family-help.ts +136 -0
  38. package/src/cli/family-pages.ts +0 -19
  39. package/src/cli/kit/calls.ts +35 -0
  40. package/src/cli/kit/project-cli.ts +2 -12
  41. package/src/cli/registry.ts +41 -7
  42. package/src/cli.ts +8 -4
  43. package/src/commands/runner.ts +5 -1
  44. package/src/core/capacity.ts +89 -33
  45. package/src/core/check-runner.ts +5 -1
  46. package/src/core/floor-resolve.ts +6 -2
  47. package/src/core/floor.ts +6 -2
  48. package/src/core/history-files.ts +22 -0
  49. package/src/core/jobs.ts +35 -16
  50. package/src/core/layout.ts +2 -2
  51. package/src/core/nearest.ts +16 -0
  52. package/src/core/remove-tree.ts +19 -0
  53. package/src/core/runs.ts +12 -3
  54. package/src/core/signal-name.ts +6 -0
  55. package/src/core/throwaway-worktree.ts +22 -4
  56. package/src/core/trace-audit.ts +22 -4
  57. package/src/core/transient.ts +6 -0
  58. package/src/drill/run.ts +1 -1
  59. package/src/home/daemon-jobs.ts +41 -4
  60. package/src/home/machine-temp.ts +2 -10
  61. package/src/ledger/gate-checks.ts +26 -4
  62. package/src/ledger/git-key.ts +25 -4
  63. package/src/ledger/git-scan.ts +59 -7
  64. package/src/media-store/backup/daemon.ts +103 -20
  65. package/src/media-store/backup/run.ts +21 -15
  66. package/src/media-store/backup/sources.ts +163 -21
  67. package/src/media-store/backup/watch.ts +106 -0
  68. package/src/media-store/daemon.ts +36 -8
  69. package/src/media-store/hand.ts +3 -1
  70. package/src/mv/mv-md.ts +50 -18
  71. package/src/pb/run-pb.ts +2 -10
  72. package/src/plan/repo-source.ts +25 -14
  73. package/src/recordings/model.ts +1 -1
  74. package/src/reflect/transcript.ts +21 -3
  75. package/src/release/run-bump.ts +3 -2
  76. package/src/release/run-release.ts +12 -4
  77. package/src/releases/model.ts +18 -0
  78. package/src/releases/store.ts +13 -1
  79. package/src/repo-config.ts +11 -1
  80. package/src/review/cells.ts +2 -1
  81. package/src/review/format.ts +1 -1
  82. package/src/review/inbox-hook.ts +35 -0
  83. package/src/review/model.ts +26 -7
  84. package/src/review/store.ts +15 -7
  85. package/src/review/trailer-model.ts +2 -2
  86. package/src/shot/client.ts +4 -2
  87. package/src/shot/serve-shot.ts +71 -2
  88. package/src/shot/shooter.ts +65 -11
  89. package/src/shot/shot-ask.ts +32 -9
  90. package/src/suite/judge-suites.ts +77 -10
  91. package/src/suite/select.ts +13 -2
  92. package/src/suite/suite-cli.ts +72 -31
  93. package/src/suite/test-units.ts +31 -12
  94. package/src/trailer/graph.ts +2 -1
  95. package/src/ts/config.ts +12 -35
  96. package/src/ts/rename.ts +31 -17
  97. package/src/ts/workspaces.ts +45 -0
  98. package/src/wiki/run-wiki.ts +8 -2
  99. package/src/wiki/scan-md.ts +42 -1
@@ -135,6 +135,61 @@ export function takeViews(args: readonly string[]): { views: ViewInput[]; rest:
135
135
  return { views, rest }
136
136
  }
137
137
 
138
+ const ADD_VIEW_USAGE = 'add-view <id> "<label>" <a.png> [<b.png>] | --image <a.png> | --before <a.png> --after <b.png> | --video <clip> | --audio <sound> | --gallery <a.png> … [--label "<label>"] [--note "<text>"]'
139
+ const MEDIA_FILE = /\.(png|jpe?g|webp|gif|mp4|webm|mov|wav|mp3|flac|ogg|opus|m4a)$/i
140
+ const quoted = (a: string): string => (/^[\w./=,@:+-]+$/.test(a) ? a : `"${a.replace(/"/g, '\\"')}"`)
141
+
142
+ /** add-view's args: the positional form, or the view flags of add; a flag is never a label, `own` are the repo unit's flags */
143
+ export async function addViewArgs(args: readonly string[], own: readonly string[]): Promise<{ id: string; view: ViewInput; repoFlags: Record<string, string[]> }> {
144
+ const one: Record<string, string> = {}
145
+ const repoFlags: Record<string, string[]> = {}
146
+ const words: string[] = []
147
+ let gallery: string[] | null = null
148
+ for (let i = 0; i < args.length; i++) {
149
+ const a = args[i] ?? ''
150
+ if (!a.startsWith('--')) {
151
+ ;(gallery ?? words).push(a)
152
+ continue
153
+ }
154
+ const name = a.slice(2)
155
+ if (name === 'gallery') {
156
+ gallery = []
157
+ continue
158
+ }
159
+ if (name === 'what') throw new Error(`--what: a view takes no --what, a line on it is --note "<text>"; ${ADD_VIEW_USAGE}`)
160
+ if (!['label', 'note', 'image', 'video', 'audio', 'before', 'after', ...own].includes(name)) throw new Error(`${a}: add-view takes no such flag; ${ADD_VIEW_USAGE}`)
161
+ const v = args[i + 1]
162
+ if (v === undefined || v.startsWith('--')) throw new Error(`${a} needs its value; ${ADD_VIEW_USAGE}`)
163
+ i++
164
+ if (own.includes(name)) (repoFlags[name] ??= []).push(v)
165
+ else one[name] = v
166
+ }
167
+ const [id, ...rest] = words
168
+ if (!id) throw new Error(ADD_VIEW_USAGE)
169
+ let label = one.label
170
+ let files = rest
171
+ if (label === undefined && rest[0] !== undefined && !MEDIA_FILE.test(rest[0])) [label, ...files] = rest
172
+ if (label === undefined && gallery?.[0] !== undefined && !MEDIA_FILE.test(gallery[0]) && !gallery[0].includes('=')) label = gallery.shift()
173
+ const given = [files.length > 0 ? 'files' : '', one.image ? '--image' : '', one.video ? '--video' : '', one.audio ? '--audio' : '', one.before || one.after ? '--before --after' : '', gallery ? '--gallery' : ''].filter((x) => x !== '')
174
+ if (given.length !== 1) throw new Error(`${given.length === 0 ? 'no media' : `one media a view, not ${given.join(' and ')}`}; ${ADD_VIEW_USAGE}`)
175
+ if (!label?.trim()) throw new Error(`the view needs its label: sk review ${['add-view', id, '"<label>"', ...args.filter((a) => a !== id).map(quoted)].join(' ')}`)
176
+ if ((one.before === undefined) !== (one.after === undefined)) throw new Error(`--before and --after go together; ${ADD_VIEW_USAGE}`)
177
+ if (gallery?.length === 0) throw new Error(`--gallery needs its images; ${ADD_VIEW_USAGE}`)
178
+ const view: ViewInput = one.image
179
+ ? { label, image: one.image }
180
+ : one.video
181
+ ? { label, video: one.video }
182
+ : one.audio
183
+ ? { label, audio: one.audio }
184
+ : one.before && one.after
185
+ ? { label, before: one.before, after: one.after }
186
+ : gallery
187
+ ? { label, gallery: gallery.map(tileOf) }
188
+ : (await import('../review/store.ts')).filesView(label, files, `${files.length} files: one image, or a before and an after; ${ADD_VIEW_USAGE}`)
189
+ if (one.note !== undefined) view.note = one.note
190
+ return { id, view, repoFlags }
191
+ }
192
+
138
193
  /** the flags of `add`, parsed by name: a value flag repeats where it says so */
139
194
  function flagsOf(args: readonly string[], values: readonly string[], repeat: readonly string[], bools: readonly string[]): { one: Record<string, string>; many: Record<string, string[]>; on: Set<string>; positionals: string[] } {
140
195
  const one: Record<string, string> = {}
@@ -163,7 +218,7 @@ function flagsOf(args: readonly string[], values: readonly string[], repeat: rea
163
218
  }
164
219
 
165
220
  const ADD_FLAGS = `flags:
166
- --title "<title>" one short line: what he looks at
221
+ --title "<title>" one short line: what he looks at (a lone "<title>" after add is the same)
167
222
  --what "<what>" what changed and why, short markdown: one line, then - bullets
168
223
  --post "<line>" the public line for a post of it, what a user gets (the repo's guard reads it)
169
224
  --changelog "<category>: <line>" its change in the release being filled: on his approval it lands in .shipkit/releases/next.md with the card's after picture (the repo's guard reads it)
@@ -268,8 +323,11 @@ export class ReviewAddCommand extends Command {
268
323
  const kind = rest.includes('--subject') && kindName ? h.unit?.kinds?.[kindName] : undefined
269
324
  const own = [...Object.keys(kind?.flags ?? {}), ...Object.keys(h.unit?.flags ?? {})]
270
325
  const f = flagsOf(rest, ['title', 'what', 'post', 'changelog', 'rating', 'image', 'video', 'audio', 'before', 'after', 'label', 'topic', 'subject', 'commit', 'lane', 'supersedes', 'keeps', 'why', 'live', 'trailer', 'version', 'shots', 'pick'], ['answers', ...own], ['new', 'wip', 'choice'])
271
- if (f.positionals.length > 0) throw new Error(`unexpected ${f.positionals.join(' ')}`)
272
326
  const o = f.one
327
+ // a lone word is the title, as `sk ask <title>` takes it; a media file never is
328
+ const [lone, ...more] = f.positionals
329
+ if (lone !== undefined && more.length === 0 && o.title === undefined && !MEDIA_FILE.test(lone)) o.title = lone
330
+ else if (lone !== undefined) throw new Error(`unexpected ${f.positionals.map(quoted).join(' ')}: the title is --title "<title>", the subject --image <a.png> (sk review add --help)`)
273
331
  const trailer = await trailerOfFlags(o, views.length > 0 || f.on.has('wip') || f.on.has('choice'))
274
332
  const repoFlags = Object.fromEntries(own.flatMap((k) => (f.many[k] ? [[k, f.many[k]]] : [])))
275
333
  const parsed = kind?.parse ? kind.parse(Object.fromEntries(Object.keys(kind.flags ?? {}).map((k) => [k, f.many[k] ?? []]))) : null
@@ -365,8 +423,11 @@ export class ReviewAddViewCommand extends Command {
365
423
  static override usage = Command.Usage({
366
424
  category: 'Review',
367
425
  description: 'another angle on a card he has not answered yet: an image, a pair, a clip or a gallery',
368
- details: `${DETAILS}\n\nsk review add-view <id> "<label>" <a.png> [<b.png>] | --video <clip.mp4> | --audio <sound.wav> | --gallery <a.png> <b.png> … [--note "<a line on that view>"]`,
369
- examples: [['a view from above', 'sk review add-view <id> "from above" top.png']],
426
+ details: `${DETAILS}\n\nsk ${ADD_VIEW_USAGE}. The view flags are add's; the id may be its moment alone (<YYYYMMDD-HHMMSS>).`,
427
+ examples: [
428
+ ['a view from above', 'sk review add-view <id> "from above" top.png'],
429
+ ['a before and after', 'sk review add-view <id> --label "on a phone" --before a.png --after b.png'],
430
+ ],
370
431
  })
371
432
  args = Option.Proxy()
372
433
 
@@ -375,34 +436,14 @@ export class ReviewAddViewCommand extends Command {
375
436
  return helpWithUnit(this.context, this.cli.usage(ReviewAddViewCommand, { detailed: true }), false)
376
437
  }
377
438
  return run(this.context, async (h) => {
378
- const { addView, filesView } = await import('../review/store.ts')
379
- const own = Object.keys(h.unit?.flags ?? {})
380
- const repoFlags: Record<string, string[]> = {}
381
- const args: string[] = []
382
- let note: string | undefined
383
- for (let i = 0; i < this.args.length; i++) {
384
- const a = this.args[i] ?? ''
385
- const name = a.startsWith('--') ? a.slice(2) : ''
386
- if (own.includes(name)) (repoFlags[name] ??= []).push(this.args[++i] ?? '')
387
- else if (name === 'note') note = this.args[++i]
388
- else args.push(a)
389
- }
390
- if (this.args.includes('--note') && (note === undefined || note.startsWith('--'))) throw new Error('--note "<text>": a line on that view')
391
- const [id, label, ...rest] = args
392
- if (!id || !label) throw new Error('add-view <id> "<label>" <media>')
393
- const v: ViewInput =
394
- rest[0] === '--video' && rest[1]
395
- ? { label, video: rest[1] }
396
- : rest[0] === '--audio' && rest[1]
397
- ? { label, audio: rest[1] }
398
- : rest[0] === '--gallery'
399
- ? { label, gallery: rest.slice(1).map(tileOf) }
400
- : filesView(label, rest, 'add-view <id> "<label>" <a.png> [<b.png>] | --video <clip> | --gallery <a.png> …')
401
- if (note !== undefined) v.note = note
402
- const extra = h.unit?.addView ? await h.unit.addView(v, repoFlags) : {}
439
+ const { addView } = await import('../review/store.ts')
440
+ const a = await addViewArgs(this.args, Object.keys(h.unit?.flags ?? {}))
441
+ const v = a.view
442
+ const id = await idOf(h.dir, a.id)
443
+ const extra = h.unit?.addView ? await h.unit.addView(v, a.repoFlags) : {}
403
444
  const item = await addView(h.dir, id, v, extra)
404
445
  const { viewLetter } = await import('../review/model.ts')
405
- h.out(`${id}: view ${viewLetter(item.views.length - 1)} "${label}" added`)
446
+ h.out(`${id}: view ${viewLetter(item.views.length - 1)} "${v.label}" added`)
406
447
  for (const line of await (await import('../review/previews.ts')).playCopies(h.dir, item, item.views.length - 1)) h.err(line)
407
448
  return 0
408
449
  })
@@ -430,7 +471,12 @@ export class ReviewLsCommand extends Command {
430
471
  return run(this.context, async (h) => {
431
472
  const verbs = h.unit?.verbs ?? {}
432
473
  const v = verbs[verb]
433
- if (!v) throw new Error(`no verb « ${verb} »: sk review --help lists sk's own; the repo's unit declares ${Object.keys(verbs).join(', ') || 'none'}`)
474
+ if (!v) {
475
+ const { typoOf } = await import('./family-help.ts')
476
+ const own = this.cli.definitions().map((d) => d.path.split(' ')).filter((w) => w[1] === 'review' && w.length === 3).map((w) => w[2]!)
477
+ const close = typoOf(verb, [...own, ...Object.keys(verbs)], 2)
478
+ throw new Error(`no verb « ${verb} »: ${close.length > 0 ? `did you mean ${close.map((c) => `sk review ${c}`).join(', ')} ? ` : ''}sk review --help lists sk's own; the repo's unit declares ${Object.keys(verbs).join(', ') || 'none'}`)
479
+ }
434
480
  const { dirname } = await import('node:path')
435
481
  return v.run(rest, { dir: h.dir, root: dirname(dirname(h.dir)), say: h.out, err: h.err })
436
482
  })
@@ -515,15 +561,23 @@ export class ReviewInboxCommand extends Command {
515
561
  category: 'Review',
516
562
  description: 'every answer not marked seen and every open item he raised, frame notes included',
517
563
  details: DETAILS,
518
- examples: [['what waits on you', 'sk review inbox'], ['his notes on trailer frames', 'sk review inbox --subject frame'], ['the cards this session sent', 'sk review inbox --mine']],
564
+ examples: [['what waits on you', 'sk review inbox'], ['his notes on trailer frames', 'sk review inbox --subject frame'], ['the cards this session sent', 'sk review inbox --mine'], ['as a Claude Code hook, on UserPromptSubmit and on Stop', 'sk review inbox --hook']],
519
565
  })
520
566
  mine = Option.Boolean('--mine', false, { description: "only this Claude Code session's cards" })
521
567
  session = Option.String('--session', { description: "only that session's cards" })
522
568
  subject = Option.String('--subject', { description: 'only items of this subject kind (frame, shot…)' })
523
569
  all = Option.Boolean('--all', false, { description: 'a plain approval too, not only the counted line' })
570
+ hook = Option.Boolean('--hook', false, { description: 'run as a Claude Code hook (UserPromptSubmit, Stop): the hook input on stdin, its json answer on stdout. The unseen answers join a prompt as context, and a turn does not end while one is unseen' })
524
571
 
525
572
  async execute(): Promise<number> {
526
- return run(this.context, async (h) => {
573
+ const { hookAnswer, hookPasses, parseHookInput } = await import('../review/inbox-hook.ts')
574
+ // the hook input is one small json on stdin; a terminal has none
575
+ const input = this.hook ? parseHookInput(process.stdin.isTTY === true ? '' : await new Response(Bun.stdin.stream()).text().catch(() => '')) : null
576
+ if (input != null && hookPasses(input)) return 0
577
+ return run(this.context, async (hh) => {
578
+ // as a hook, the lines of the inbox are the answer's text, never the output
579
+ const unseenLines: string[] = []
580
+ const h = input == null ? hh : { ...hh, out: (l: string) => void unseenLines.push(l) }
527
581
  const { liveWatchers } = await import('../review/watchers.ts')
528
582
  const { readAll } = await import('../review/store.ts')
529
583
  const { BUILTIN_KINDS, coversCard, moveOf, stateOf, unreadBy, untakenOf, verdictOf } = await import('../review/model.ts')
@@ -546,7 +600,9 @@ export class ReviewInboxCommand extends Command {
546
600
  const v = verdictOf(x)
547
601
  return v?.status === 'approved' && !v.seen && !v.comment && v.rects.length === 0 && !v.reactions && v.pick === undefined && unreadBy(x, 'agent').length === 0
548
602
  }
549
- const shown = [...(this.all ? news : news.filter((x) => !plain(x))), ...open]
603
+ // as a hook: a raised item a lane claimed is in that lane's hands until it closes it, so it never blocks a turn
604
+ const inHand = (x: (typeof news)[number]): boolean => input != null && x.item.origin.by !== 'agent' && stateOf(x, followed.has(x.item.id)).state === 'claimed'
605
+ const shown = [...(this.all ? news : news.filter((x) => !plain(x))), ...open].filter((x) => !inHand(x))
550
606
  if (shown.length === 0 && news.length === 0) h.out('review: no unseen feedback or reply')
551
607
  const threads = threadsOf(all.items)
552
608
  const printed = new Set<string>()
@@ -563,6 +619,14 @@ export class ReviewInboxCommand extends Command {
563
619
  const close = fix ? `sk review done ${x.item.id} "<what changed>"` : `--supersedes ${x.item.id} on its new version`
564
620
  return ` ${x.item.id} ${fix ? 'ok with a fix' : 'rejected'} "${x.item.title}": ${close}, or sk review wontfix ${x.item.id} --note "<why>"`
565
621
  }
622
+ if (input != null) {
623
+ const approvals = news.filter(plain)
624
+ if (approvals.length > 0) h.out(`${approvals.length} plain approval(s), nothing to do: sk review seen ${approvals.map((x) => x.item.id).join(' ')}`)
625
+ const said = unseenLines.filter((l) => l !== 'review: no unseen feedback or reply').join('\n').trim()
626
+ const answer = hookAnswer(input, said, owed.map((t) => t.head.item.id))
627
+ if (answer != null) hh.out(answer)
628
+ return 0
629
+ }
566
630
  if (owed.length > 0) h.out(`owed, read and not done:\n${owed.map((t) => owedLine(t.head)).join('\n')}\n`)
567
631
  const watchers = liveWatchers(h.dir)
568
632
  const untaken = all.items.flatMap((x) => {
@@ -585,8 +649,9 @@ const laneOfCaller = (as: string | undefined): string | null => as?.trim() || pr
585
649
  async function answererRefusal(dir: string, id: string, as: string | undefined, op: 'reply' | 'seen'): Promise<string | null> {
586
650
  const { readItem, sessionId } = await import('../review/store.ts')
587
651
  const { notAnswererOf } = await import('../review/model.ts')
652
+ const { liveWatchers } = await import('../review/watchers.ts')
588
653
  const x = readItem(dir, id)
589
- return x === null ? null : notAnswererOf(x, { lane: laneOfCaller(as), session: sessionId() }, op)
654
+ return x === null ? null : notAnswererOf(x, { lane: laneOfCaller(as), session: sessionId() }, op, op === 'seen' ? liveWatchers(dir) : undefined)
590
655
  }
591
656
 
592
657
  export class ReviewSeenCommand extends Command {
@@ -689,13 +754,17 @@ export class ReviewWithdrawCommand extends Command {
689
754
  static override paths = [['review', 'withdraw']]
690
755
  static override usage = Command.Usage({ category: 'Review', description: 'take an unanswered card back, with the reason', details: DETAILS })
691
756
  ids = Option.Rest({ required: 1 })
692
- why = Option.String('--why', { required: true, description: 'why it goes' })
757
+ why = Option.String('--why,--note', { required: true, description: 'why it goes (--note says the same, as on fixed, wontfix, blocked and drop)' })
693
758
 
694
759
  async execute(): Promise<number> {
695
760
  return run(this.context, async (h) => {
696
761
  const { withdraw } = await import('../review/store.ts')
697
- for (const id of this.ids) if (!withdraw(h.dir, id, this.why)) throw new Error(`${id}: no such card, or he answered it already`)
698
- h.out(`review: ${this.ids.length} withdrawn`)
762
+ const ids = await Promise.all(this.ids.map((ref) => idOf(h.dir, ref)))
763
+ for (const id of ids) {
764
+ const r = withdraw(h.dir, id, this.why)
765
+ if ('refused' in r) throw new Error(r.refused)
766
+ h.out(r.already ? `${id}: withdrawn already (${r.already}), nothing to do` : `${id}: withdrawn`)
767
+ }
699
768
  return 0
700
769
  })
701
770
  }
@@ -711,7 +780,8 @@ export class ReviewReopenCommand extends Command {
711
780
  const { reopen } = await import('../review/store.ts')
712
781
  const { followAnswer } = await import('../releases/from-card.ts')
713
782
  const { dirname } = await import('node:path')
714
- for (const id of this.ids) {
783
+ for (const ref of this.ids) {
784
+ const id = await idOf(h.dir, ref)
715
785
  const v = reopen(h.dir, id)
716
786
  if (!v) throw new Error(`${id}: no such card, or no answer to reopen`)
717
787
  await followAnswer(dirname(dirname(h.dir)), id, v.status)
@@ -737,9 +807,10 @@ export class ReviewPickCommand extends Command {
737
807
  return run(this.context, async (h) => {
738
808
  const { setAgentPick } = await import('../review/store.ts')
739
809
  const { viewLetter, viewName } = await import('../review/model.ts')
740
- const item = setAgentPick(h.dir, this.id, this.view)
810
+ const id = await idOf(h.dir, this.id)
811
+ const item = setAgentPick(h.dir, id, this.view)
741
812
  const n = item.agentPick ?? 0
742
- h.out(`${this.id}: my pick ${viewLetter(n)} "${viewName(item.views[n], n)}"`)
813
+ h.out(`${id}: my pick ${viewLetter(n)} "${viewName(item.views[n], n)}"`)
743
814
  return 0
744
815
  })
745
816
  }
@@ -769,6 +840,21 @@ function actCommand(op: ActOp, description: string, o: { note?: 'required' | 'op
769
840
  if (o.topic === 'required' && !this.words) throw new Error(`${op} <id> <topic> (sk review topics)`)
770
841
  const id = await idOf(h.dir, this.id)
771
842
  const who = actor(this.as, o.named, op)
843
+ if (op === 'done') {
844
+ // done is asked of a card he answered « fix »: closed already is the goal reached, unanswered is withdraw's
845
+ const { readAll } = await import('../review/store.ts')
846
+ const { followedIds } = await import('../review/threads.ts')
847
+ const was = readItem(h.dir, id)
848
+ const followed = followedIds(readAll(h.dir).items).has(id)
849
+ const st = was ? stateOf(was, followed) : null
850
+ if (st?.state === 'closed') {
851
+ h.out(`${id}: closed already (${st.why ?? 'closed'}${followed ? ', a newer card follows it' : ''}), nothing to close`)
852
+ if (this.words || this.note) h.err(`your words are not posted: sk review reply ${id} "<text>"`)
853
+ return 0
854
+ }
855
+ if (st?.state === 'asks' || st?.state === 'draft')
856
+ throw new Error(`${id}: done closes a card the owner answered « fix »; this one ${st.state === 'asks' ? "waits on the owner's verdict" : 'is in progress'}: sk review withdraw ${id} --why "<why>" takes it back`)
857
+ }
772
858
  act(h.dir, id, op, who, {
773
859
  ...(this.note ? { note: this.note } : {}),
774
860
  ...(op === 'ask' && this.words ? { text: this.words } : {}),
@@ -921,8 +1007,9 @@ export class ReviewReadyCommand extends Command {
921
1007
  async execute(): Promise<number> {
922
1008
  return run(this.context, async (h) => {
923
1009
  const { readItem, readyItem } = await import('../review/store.ts')
924
- const live = readItem(h.dir, this.id)?.item.wip?.live
925
- const r = await readyItem(h.dir, this.id, this.image ? { image: this.image } : {})
1010
+ const id = await idOf(h.dir, this.id)
1011
+ const live = readItem(h.dir, id)?.item.wip?.live
1012
+ const r = await readyItem(h.dir, id, this.image ? { image: this.image } : {})
926
1013
  if (live !== undefined) h.unit?.live?.stop?.(live, 'ready')
927
1014
  h.out(`${r.id} ready: he can answer it`)
928
1015
  return 0
@@ -1,7 +1,9 @@
1
1
  // sk shot: a still of any url (webp by default), or a clip with --video, through the machine's
2
2
  // one warm browser (shot/client.ts). A repo's own CLI wraps it with its setup
3
3
  // flags; the trailer's `url` film calls the same functions.
4
- import { relative } from 'path'
4
+ import { statSync } from 'fs'
5
+ import { relative, resolve } from 'path'
6
+ import { pathToFileURL } from 'url'
5
7
  import { Command, Option } from 'clipanion'
6
8
  import { clipUrl, shotUrl, type ShotResult } from '../shot/client.ts'
7
9
  import { askOf, isClip } from '../shot/shot-ask.ts'
@@ -17,6 +19,13 @@ export const renderShot = (r: ShotResult, cwd: string): string[] => {
17
19
  return lines
18
20
  }
19
21
 
22
+ /** the path of a file on this machine as its file url; anything else as typed */
23
+ export const fileUrlOf = (s: string, cwd: string): string => {
24
+ if (/^[a-z]+:\/\//i.test(s)) return s
25
+ const p = resolve(cwd, s)
26
+ return statSync(p, { throwIfNoEntry: false })?.isFile() ? pathToFileURL(p).href : s
27
+ }
28
+
20
29
  export class ShotCommand extends Command {
21
30
  static override paths = [['shot']]
22
31
  static essential = { args: '<url>' }
@@ -25,9 +34,10 @@ export class ShotCommand extends Command {
25
34
  category: 'Serve',
26
35
  description: 'a webp of any url through the warm browser (a png with --out x.png), or an mp4 clip with --video',
27
36
  details:
28
- 'one warm headless chromium for the whole machine (the `shot` global process, started when down). A still reuses the warm page when it already shows the url, so a warm shot answers in about 0.1 s. A page with `<meta name="shot-ready" content="wait">` is shot once it sets content="ready"; any other page --wait ms after its load. --video films a page that is a canvas through its WebCodecs encoder (H.264 muxed with no second encode), and any other page as chromium paints it (its screencast, encoded by ffmpeg as the frames arrive); --dom films the page even when a canvas fills it. --step <hook> films frame by frame: before each frame the page draws its time t (seconds) in `await window[hook](t)`, then its ready mark, so a slow page films smooth at its fps; a canvas page is encoded by its own WebCodecs at the exact time n / fps, any other page a screenshot a frame. A still with --step is the page drawn at --at s',
37
+ 'one warm headless chromium for the whole machine (the `shot` global process, started when down). A still reuses the warm page when it already shows the url, so a warm shot answers in about 0.1 s. A page with `<meta name="shot-ready" content="wait">` is shot once it sets content="ready"; any other page --wait ms after its load; a page that navigates while it loads (a sign in that redirects) gets its wait again where it lands. --full shoots the whole page at the width of the viewport. A file of this machine is a url too (its path, or file://). --video films a page that is a canvas through its WebCodecs encoder (H.264 muxed with no second encode), and any other page as chromium paints it (its screencast, encoded by ffmpeg as the frames arrive); --dom films the page even when a canvas fills it. --step <hook> films frame by frame: before each frame the page draws its time t (seconds) in `await window[hook](t)`, then its ready mark, so a slow page films smooth at its fps; a canvas page is encoded by its own WebCodecs at the exact time n / fps, any other page a screenshot a frame. A still with --step is the page drawn at --at s. A session: cookies follow every shot (one jar in memory for the whole machine), the local storage of a page does not: a shot at another viewport, a clip and the idle close (60 s) each start with an empty one, as two browser contexts do. So when an app keeps its session in local storage, open its sign in at the viewport you shoot at; a request the page sees answered 401 or 403 prints its own WARN line',
29
38
  examples: [
30
39
  ['a still of a running dev server', 'sk shot localhost:5173/'],
40
+ ['a whole tall page at a phone width', 'sk shot :5173/guest --viewport 390,844 --full --out shots/guest.png'],
31
41
  ['a phone screen, at the pixel ratio of a phone', 'sk shot :5173/play --viewport 390,844 --dpr 3 --out shots/phone.png'],
32
42
  ['a 3 s clip', 'sk shot :4808/ --video 3 --out clips/walk.mp4'],
33
43
  ['a clip of a whole web app page, canvas or not', 'sk shot :5173/settings --video 3 --dom'],
@@ -40,7 +50,8 @@ export class ShotCommand extends Command {
40
50
  dpr = Option.String('--dpr', { description: 'device pixel ratio (default 1)' })
41
51
  out = Option.String('--out', { description: 'the file (default .shipkit/tmp/shots/<url>.webp, or .mp4 with --video); its extension picks the still: .webp and .jpg at quality 90, .png lossless' })
42
52
  reload = Option.Boolean('--reload', false, { description: 'load the page again even when the warm page shows this url' })
43
- wait = Option.String('--wait', { description: 'ms after load for a page with no ready mark (default 300)' })
53
+ wait = Option.String('--wait', { description: 'ms after load for a page with no ready mark (default 300, at most 60000)' })
54
+ full = Option.Boolean('--full', false, { description: 'the whole page, past the viewport height (a still only)' })
44
55
  video = Option.String('--video', { description: 'seconds of clip: an mp4 of the page (its canvas when a canvas fills it)' })
45
56
  fps = Option.String('--fps', { description: 'clip frames per second (default 30)' })
46
57
  long = Option.Boolean('--long', false, { description: 'allow a clip past 30 s' })
@@ -53,7 +64,7 @@ export class ShotCommand extends Command {
53
64
  const cwd = process.cwd()
54
65
  const err = (l: string) => this.context.stderr.write(`${l}\n`)
55
66
  try {
56
- const a = askOf({ url: this.url, viewport: this.viewport, dpr: this.dpr, out: this.out, reload: this.reload, wait: this.wait, video: this.video, fps: this.fps, long: this.long, dom: this.dom, step: this.step, at: this.at }, cwd)
67
+ const a = askOf({ url: fileUrlOf(this.url, cwd), full: this.full, viewport: this.viewport, dpr: this.dpr, out: this.out, reload: this.reload, wait: this.wait, video: this.video, fps: this.fps, long: this.long, dom: this.dom, step: this.step, at: this.at }, cwd)
57
68
  const r = isClip(a) ? await clipUrl(a, err) : await shotUrl(a, err)
58
69
  if (this.json) this.context.stdout.write(`${JSON.stringify(r)}\n`)
59
70
  else for (const l of renderShot(r, cwd)) this.context.stdout.write(`${l}\n`)
@@ -1,7 +1,7 @@
1
1
  // shipkit status — read back a gate started with `shipkit ci --detach`. Thin
2
2
  // clipanion surface; logic in core/jobs.ts.
3
3
  import { Command, Option } from 'clipanion'
4
- import { jobStatus, STILL_RUNNING } from '../core/jobs.ts'
4
+ import { jobStatus, STILL_RUNNING, waitStatus } from '../core/jobs.ts'
5
5
 
6
6
  export class StatusCommand extends Command {
7
7
  static override paths = [['status']]
@@ -10,17 +10,18 @@ export class StatusCommand extends Command {
10
10
  static override usage = Command.Usage({
11
11
  category: 'Gate',
12
12
  description: 'the output and verdict of a gate started with `sk ci --detach`',
13
- details: `a gate started with \`shipkit ci --detach\`: its wire lines so far, then its verdict. Exit code = the gate's own once it finished, ${STILL_RUNNING} while it still runs, 1 when it died without one`,
13
+ details: `a gate started with \`shipkit ci --detach\`: its verdict on the first line (finished green, finished red, still running, died), then its wire lines so far. Exit code = the gate's own once it finished, ${STILL_RUNNING} while it still runs, 1 when it died without one. --wait holds until the run has a verdict (10 minutes at most): one call from a backgrounded shell in place of a poll every few seconds. With no id: the latest run \`--detach\` started here, never a job of the daemon`,
14
14
  examples: [
15
- ['the latest detached run of this checkout', 'sk status'],
16
- ['one run by id', 'sk status ci-mf3k2a-1x2y'],
15
+ ['hold until the run ends, then its verdict', 'sk status ci-mf3k2a-1x2y --wait'],
16
+ ['the latest detached run of this checkout, as it stands', 'sk status'],
17
17
  ],
18
18
  })
19
19
 
20
20
  id = Option.String({ required: false })
21
+ wait = Option.Boolean('--wait', false, { description: 'hold until the run has a verdict, 10 minutes at most, then print it' })
21
22
 
22
23
  async execute(): Promise<number> {
23
- const r = jobStatus(process.cwd(), this.id)
24
+ const r = this.wait ? await waitStatus(process.cwd(), this.id) : jobStatus(process.cwd(), this.id)
24
25
  for (const l of r.lines) this.context.stdout.write(`${l}\n`)
25
26
  return r.code
26
27
  }
@@ -3,7 +3,7 @@
3
3
  // through the agent time index (agent-time/store.ts). REPORT ONLY: exit 0 with
4
4
  // a report, 1 when nothing matched, 2 on a bad flag.
5
5
  import { Command, Option } from 'clipanion'
6
- import { resolve } from 'path'
6
+ import { dirname, resolve } from 'path'
7
7
 
8
8
  const BIG_BYTES = 50 * 1024 * 1024
9
9
 
@@ -17,7 +17,8 @@ export class TimeCommand extends Command {
17
17
  details: [
18
18
  'Reads every Claude Code transcript under every config root (~/.claude, ~/.claude-<name>), sub-agent runs included, through an index at ~/.shipkit/agent-time.sqlite.',
19
19
  'The first run builds the index (niced, resumable, progress on stderr); later runs read only what changed. The index keeps sessions Claude Code has pruned.',
20
- 'Views: summary (default), commands, tools, slow, fails, feedback, sessions, turns. A Bash command is grouped by its shape (`git commit`, `bun test <file>`, `sk ci --only lint`).',
20
+ 'Views: summary (default), commands, tools, slow, fails, feedback, sessions, turns, hooks. A Bash command is grouped by its shape (`git commit`, `bun test <file>`, `sk ci --only lint`).',
21
+ 'Hooks: each hook command with its event, the runs the harness timed (median, p90, worst, total) and the calls its matcher applies to. The harness records a hook run only when the hook printed something, so a silent hook is missing.',
21
22
  'Turns: every call costs a model turn before it, so the summary gives the model time before each call, the share of single read calls and the share sent in parallel, for the main sessions and the sub-agents; `turns` lists the runs and the read shapes by the model time they cost.',
22
23
  'Wall time is cut once per moment, and the buckets add up to the wall: tools in flight, a sub-agent in flight, waiting on you (an idle gap past 30 minutes is left out), stopped until a task notification woke it (background wait), stopped with nothing recorded that woke it (unknown), else the agent was in its turn (model).',
23
24
  'A background command (run_in_background, or moved there at its timeout) is timed from its start to its task notification, its row marked (bg); a run with no notification is counted as having no end, never as zero.',
@@ -28,6 +29,7 @@ export class TimeCommand extends Command {
28
29
  ['every command shape, 30 days', 'sk time commands --since 30d'],
29
30
  ['what he said while it ran', 'sk time feedback --since all'],
30
31
  ['the runs by their turns, and what the reads cost', 'sk time turns --since 30d'],
32
+ ['what the hooks cost, 30 days', 'sk time hooks --since 30d'],
31
33
  ['two repos, every recorded session', 'sk time ~/dev/game ~/dev/site --since all'],
32
34
  ['every repo on the machine', 'sk time --all'],
33
35
  ['for a script', 'sk time --json'],
@@ -70,7 +72,10 @@ export class TimeCommand extends Command {
70
72
  const { buildReport } = await import('../agent-time/report.ts')
71
73
  const { loadMasker } = await import('../agent-time/mask.ts')
72
74
 
73
- const repos = repoArgs.length > 0 ? repoArgs.map((r) => resolve(r)) : [process.cwd()]
75
+ // with no repo named: the repo this folder is in, by its main work tree, where its sessions are filed
76
+ const { gitRoot } = await import('../core/git-root.ts')
77
+ const here = gitRoot(process.cwd())
78
+ const repos = repoArgs.length > 0 ? repoArgs.map((r) => resolve(r)) : [here == null ? process.cwd() : dirname(here.commonDir)]
74
79
  const slugs = repos.map(projectSlug)
75
80
  const keep = this.all ? () => true : (p: string) => slugs.some((s) => p === s || p.startsWith(`${s}--claude-worktrees-`))
76
81
  const roots = discoverConfigRoots()
@@ -88,12 +93,14 @@ export class TimeCommand extends Command {
88
93
  try { (require('os') as typeof import('os')).setPriority(0, 15) } catch { /* not allowed: index at the normal priority */ }
89
94
  }
90
95
  const t = performance.now()
91
- if (t - lastPrint < (tty ? 200 : 10_000) && p.done < p.files) return
96
+ // off a terminal the first line is the answer: a progress line only for an index that runs long
97
+ if (tty ? t - lastPrint < 200 && p.done < p.files : t - Math.max(lastPrint, tIndex) < 10_000) return
92
98
  lastPrint = t
93
99
  const line = `index: ${p.done}/${p.files} files, ${(p.doneBytes / 1e9).toFixed(1)}/${(p.bytes / 1e9).toFixed(1)} GB, ${Math.round((t - tIndex) / 1000)}s`
94
100
  err.write(tty ? `\r${line}` : `${line}\n`)
95
101
  })
96
- if (res.bytes >= BIG_BYTES) err.write(`${tty ? '\n' : ''}index: read ${res.read} of ${pending} files, ${(res.bytes / 1e9).toFixed(2)} GB in ${(res.ms / 1000).toFixed(1)}s (${agentTimeDbPath()})\n`)
102
+ const indexed = res.bytes >= BIG_BYTES ? `index: read ${res.read} of ${pending} files, ${(res.bytes / 1e9).toFixed(2)} GB in ${(res.ms / 1000).toFixed(1)}s (${agentTimeDbPath()})\n` : ''
103
+ if (tty && indexed !== '') err.write(`\n${indexed}`)
97
104
  markGone(db, files, keep)
98
105
  const loaded = loadWindow(db, keep, from ?? 0, now)
99
106
  const labels = this.all ? [...new Set(loaded.files.map((f) => repoOfProject(f.project)))].sort() : slugs.map((s) => repoOfProject(s))
@@ -103,9 +110,14 @@ export class TimeCommand extends Command {
103
110
  err.write(` fix: widen it, --since all, or name a repo that ran Claude Code sessions\n`)
104
111
  return 1
105
112
  }
106
- const report = buildReport(loaded, { repos: labels, from, to: now, repoOf: (p) => repoOfProject(p) }, loadMasker(repos[0] ?? null))
113
+ const { repoHooks, userHooks } = await import('../agent-time/hooks.ts')
114
+ const { hookMatcherKey } = await import('../agent-time/report.ts')
115
+ // the matcher each hook declares today: the calls it applies to
116
+ const hookMatchers = new Map([...userHooks(), ...repos.flatMap((r) => repoHooks(r).hooks)].map((h) => [hookMatcherKey(h.event, h.command), h.matcher]))
117
+ const report = buildReport(loaded, { repos: labels, from, to: now, repoOf: (p) => repoOfProject(p), hookMatchers }, loadMasker(repos[0] ?? null))
107
118
  if (this.json) this.context.stdout.write(`${JSON.stringify(report)}\n`)
108
119
  else this.context.stdout.write(render(report, view, top))
120
+ if (!tty) err.write(indexed)
109
121
  return 0
110
122
  } finally {
111
123
  db.close()
@@ -15,10 +15,10 @@ interface Here {
15
15
  }
16
16
 
17
17
  /** the identity named, else the one the current repo's Veille is */
18
- async function run(context: Ctx, as: string | undefined, body: (h: Here) => Promise<number>): Promise<number> {
18
+ async function run(context: Ctx, as: string | undefined, cmd: string, body: (h: Here) => Promise<number>): Promise<number> {
19
19
  const out = (l: string): void => void context.stdout.write(`${l}\n`)
20
20
  try {
21
- const { identityOf, hasVeille } = await import('../veille/identity.ts')
21
+ const { identities, identityOf, hasVeille } = await import('../veille/identity.ts')
22
22
  const { veilleAt } = await import('../veille/routes.ts')
23
23
  const { storeDir } = await import('../review/store.ts')
24
24
  const { findRepoRoot } = await import('../ts/config.ts')
@@ -30,7 +30,11 @@ async function run(context: Ctx, as: string | undefined, body: (h: Here) => Prom
30
30
  }
31
31
  const here = root == null ? null : veilleAt(root)
32
32
  const identity = as === undefined ? here?.identity : identityOf(as)
33
- if (identity == null) throw new Error(as === undefined ? 'this repo shows no Veille: name the identity with --as <id>' : `no identity ${as}`)
33
+ if (identity == null) {
34
+ const watched = identities().filter(hasVeille).map((x) => x.id)
35
+ const pick = watched.length === 0 ? 'no identity has a watch list yet' : `name one: ${watched.map((id) => `${cmd} --as ${id}`).join(', ')}`
36
+ throw new Error(`${as === undefined ? 'this repo shows no Veille' : `no identity ${as}`}: ${pick}`)
37
+ }
34
38
  if (!hasVeille(identity)) throw new Error(`${identity.id} has no watch list (${identity.watchFile})`)
35
39
  const asksDir = here != null && here.identity.id === identity.id ? storeDir(here.asks.root) : null
36
40
  return await body({ out, identity, root, asksDir })
@@ -60,7 +64,7 @@ export class VeilleFeedCommand extends Command {
60
64
  since = Option.String('--since', '24h', { description: 'the window: 90m, 24h, 3d, 7d' })
61
65
  all = Option.Boolean('--all', false, { description: 'the expired and handled posts too' })
62
66
  async execute(): Promise<number> {
63
- return run(this.context, this.as, async (h) => {
67
+ return run(this.context, this.as, `sk ${this.path.join(' ')}`, async (h) => {
64
68
  const { feedLine } = await import('../veille/desk.ts')
65
69
  const { isPlatform } = await import('../veille/platforms.ts')
66
70
  const { interactions } = await import('../veille/asks.ts')
@@ -97,7 +101,7 @@ export class VeilleReplyCommand extends Command {
97
101
  text = Option.String('--text', { description: 'the reply' })
98
102
  media = Option.String('--media', { description: 'a media file of the drafts it lends, repo relative' })
99
103
  async execute(): Promise<number> {
100
- return run(this.context, this.as, async (h) => {
104
+ return run(this.context, this.as, `sk ${this.path.join(' ')}`, async (h) => {
101
105
  const { brief, mediaFor } = await import('../veille/desk.ts')
102
106
  const { draftMedia } = await import('../social/media-of.ts')
103
107
  const { oursOf, veilleOf } = await import('../veille/service.ts')
@@ -127,7 +131,7 @@ export class VeillePassCommand extends Command {
127
131
  as = asOpt()
128
132
  why = Option.String('--why', { required: true, description: 'the real reason, one line' })
129
133
  async execute(): Promise<number> {
130
- return run(this.context, this.as, async (h) => {
134
+ return run(this.context, this.as, `sk ${this.path.join(' ')}`, async (h) => {
131
135
  const { oursOf, veilleOf } = await import('../veille/service.ts')
132
136
  const { desk } = veilleOf(h.identity)
133
137
  if (desk.feed({ all: true, ours: oursOf(h.identity) }).every((r) => r.key !== this.key)) throw new Error(`no post ${this.key} in the log: sk veille feed gives the keys`)