rvlib-shipkit 2.23.0 → 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 (97) hide show
  1. package/CHANGELOG.md +25 -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/asks/asks-queue.ts +32 -11
  8. package/src/checks/SK044-behind-upstream.check.ts +38 -0
  9. package/src/cli/cmd_Asks.ts +2 -0
  10. package/src/cli/cmd_Backup.ts +7 -5
  11. package/src/cli/cmd_Bump.ts +1 -0
  12. package/src/cli/cmd_Capacity.ts +26 -0
  13. package/src/cli/cmd_Check.ts +1 -0
  14. package/src/cli/cmd_Checks.ts +1 -0
  15. package/src/cli/cmd_Ci.ts +1 -0
  16. package/src/cli/cmd_Commands.ts +50 -14
  17. package/src/cli/cmd_Home.ts +0 -29
  18. package/src/cli/cmd_Hooks.ts +1 -0
  19. package/src/cli/cmd_Mv.ts +1 -0
  20. package/src/cli/cmd_Reflect.ts +1 -0
  21. package/src/cli/cmd_Releases.ts +1 -0
  22. package/src/cli/cmd_Review.ts +97 -14
  23. package/src/cli/cmd_Secret.ts +41 -2
  24. package/src/cli/cmd_Shot.ts +1 -0
  25. package/src/cli/cmd_Status.ts +1 -0
  26. package/src/cli/cmd_Time.ts +3 -1
  27. package/src/cli/cmd_Tmp.ts +82 -0
  28. package/src/cli/cmd_Wiki.ts +1 -0
  29. package/src/cli/registry.ts +13 -1
  30. package/src/collections/pings.ts +1 -1
  31. package/src/core/capacity.ts +71 -0
  32. package/src/core/check-runner.ts +86 -15
  33. package/src/core/motherhome.ts +67 -9
  34. package/src/core/slots.ts +49 -12
  35. package/src/core/trace-audit.ts +4 -1
  36. package/src/drill/run.ts +5 -2
  37. package/src/home/gui-app/ShipkitGui.swift +1 -0
  38. package/src/home/home-launchd.ts +11 -3
  39. package/src/home/home-routes.ts +11 -4
  40. package/src/home/machine-host.ts +65 -0
  41. package/src/home/machine-stores.ts +19 -17
  42. package/src/home/machine-temp.ts +493 -0
  43. package/src/home/other-macs.ts +74 -0
  44. package/src/home/run-daemon.ts +10 -2
  45. package/src/home/serve-web.ts +2 -2
  46. package/src/home/via-hub.ts +6 -1
  47. package/src/init-repo.ts +7 -3
  48. package/src/ledger/ledger.ts +6 -0
  49. package/src/ledger/store.ts +6 -0
  50. package/src/media-store/backup/keys.ts +21 -6
  51. package/src/media-store/backup/manifest.ts +52 -11
  52. package/src/media-store/backup/restore.ts +17 -10
  53. package/src/media-store/backup/run.ts +5 -2
  54. package/src/media-store/backup/sources.ts +2 -1
  55. package/src/mv/mv-md.ts +121 -42
  56. package/src/reflect/transcript.ts +56 -11
  57. package/src/releases/from-card.ts +45 -3
  58. package/src/releases/model.ts +6 -0
  59. package/src/releases/store.ts +8 -1
  60. package/src/repo-config.ts +5 -3
  61. package/src/review/cells.ts +24 -3
  62. package/src/review/format.ts +33 -9
  63. package/src/review/media-kind.ts +14 -11
  64. package/src/review/media-read.ts +6 -5
  65. package/src/review/model.ts +71 -3
  66. package/src/review/paste.ts +2 -1
  67. package/src/review/previews.ts +123 -36
  68. package/src/review/routes.ts +29 -18
  69. package/src/review/store.ts +74 -12
  70. package/src/review/threads.ts +7 -5
  71. package/src/secrets/copy.ts +110 -0
  72. package/src/secrets/list.ts +17 -7
  73. package/src/serve/hub-app/home-strip.css +5 -0
  74. package/src/serve/hub-app/home-strip.tsx +18 -0
  75. package/src/serve/hub-app/hub-app.tsx +2 -1
  76. package/src/serve/hub-app/hub.css +14 -0
  77. package/src/serve/hub-app/inbox.css +1 -0
  78. package/src/serve/hub-app/pull-refresh.tsx +88 -0
  79. package/src/serve/hub-app/review/review-cells.tsx +52 -13
  80. package/src/serve/hub-app/review/review-list.tsx +6 -1
  81. package/src/serve/hub-app/review/review-st.ts +6 -5
  82. package/src/serve/hub-app/review/review-thread.tsx +3 -1
  83. package/src/serve/hub-app/review/review-views.tsx +18 -11
  84. package/src/serve/hub-app/review/thread-st.ts +82 -14
  85. package/src/serve/hub-app/review.css +15 -2
  86. package/src/serve/hub-runtime.ts +2 -1
  87. package/src/serve/run-serve.ts +4 -2
  88. package/src/serve/serve-hub.ts +9 -2
  89. package/src/suite/child-tools.ts +45 -0
  90. package/src/suite/judge-suites.ts +10 -22
  91. package/src/suite/select.ts +83 -8
  92. package/src/suite/suite-cli.ts +38 -14
  93. package/src/suite/suite-cores.ts +68 -0
  94. package/src/suite/suite-reads-preload.ts +8 -6
  95. package/src/ts/config.ts +44 -0
  96. package/src/ts/rename.ts +11 -1
  97. package/src/home/claude-temp.ts +0 -139
@@ -18,13 +18,23 @@ interface Here {
18
18
  err: (l: string) => void
19
19
  }
20
20
 
21
+ /** the shipkit repo the cwd stands in: only its store reaches a hub, so anywhere else a card is refused before a
22
+ * stray .shipkit/review/ is made where nobody looks */
23
+ async function reviewRoot(cwd: string): Promise<string | null> {
24
+ const { findRepoRoot } = await import('../ts/config.ts')
25
+ const { existsSync } = await import('node:fs')
26
+ const { join } = await import('node:path')
27
+ const root = findRepoRoot(cwd)
28
+ return existsSync(join(root, 'repo.config.ts')) ? root : null
29
+ }
30
+
21
31
  /** the store of the repo this runs in, its unit read when the verb needs it, and the body; a refusal is one FAIL line with its reason, exit 1 */
22
32
  async function run(context: Ctx, body: (h: Here) => Promise<number> | number, o: { unit?: boolean } = {}): Promise<number> {
23
- const { findRepoRoot } = await import('../ts/config.ts')
24
33
  const out = (l: string): void => void context.stdout.write(`${l}\n`)
25
34
  const err = (l: string): void => void context.stderr.write(`${l}\n`)
26
35
  try {
27
- const root = findRepoRoot(process.cwd())
36
+ const root = await reviewRoot(process.cwd())
37
+ if (root == null) throw new Error(`${process.cwd()} is in no shipkit repo (no repo.config.ts at its git root), so no hub would ever show what is stored here: run it from inside the repo the card is for`)
28
38
  if (o.unit === false) {
29
39
  const { storeDir } = await import('../review/store.ts')
30
40
  return await body({ dir: storeDir(root), unit: null, say: { spec: (await import('../review/model.ts')).NO_SPEC, more: () => [] }, out, err })
@@ -175,6 +185,7 @@ const ADD_FLAGS = `flags:
175
185
  --subject <kind> what is judged (default shot; the repo's unit names its kinds)
176
186
  --commit <sha> the commit it shows
177
187
  --lane <id> the lane that made it; else SK_AGENT
188
+ --wip "<what is still wrong>" a card sent in work: « in progress », no verdict asked; each step after: sk review update <id> <broken|better|fixed> "<line>" <file>
178
189
  --supersedes <id> the card it follows up, after his answer
179
190
  --answers <id | live#3> the item it answers (a note he raised, a player's report), one thread (repeat it)
180
191
  --keeps "<what stays>" with --supersedes on an approved look: what of it stays
@@ -184,6 +195,10 @@ const ADD_FLAGS = `flags:
184
195
  * `--subject <kind>`); a repo with no unit, or one that does not load, says so on one line */
185
196
  async function helpWithUnit(context: Ctx, usage: string, kinds: boolean): Promise<number> {
186
197
  context.stdout.write(usage)
198
+ if ((await reviewRoot(process.cwd())) == null) {
199
+ context.stdout.write("\nno shipkit repo here, so no review unit adds flags\n")
200
+ return 0
201
+ }
187
202
  await run(context, (h) => {
188
203
  const lines = Object.entries(h.unit?.flags ?? {}).map(([k, d]) => ` --${k} ${d}`)
189
204
  if (kinds) for (const [name, k] of Object.entries(h.unit?.kinds ?? {})) for (const [f, d] of Object.entries(k.flags ?? {})) lines.push(` --${f} ${d} (with --subject ${name})`)
@@ -222,6 +237,7 @@ export async function trailerOfFlags(o: Record<string, string>, others: boolean)
222
237
 
223
238
  export class ReviewAddCommand extends Command {
224
239
  static override paths = [['review', 'add']]
240
+ static essential = {}
225
241
  static override usage = Command.Usage({
226
242
  category: 'Review',
227
243
  description: 'show the owner a change as one card he answers in the hub: an image, a clip, a pair, views',
@@ -242,8 +258,11 @@ export class ReviewAddCommand extends Command {
242
258
  return helpWithUnit(this.context, this.cli.usage(ReviewAddCommand, { detailed: true }), true)
243
259
  }
244
260
  return run(this.context, async (h) => {
245
- const { addItem } = await import('../review/store.ts')
246
- const { views, rest } = takeViews(this.args)
261
+ const { addItem, postUpdate, agentName } = await import('../review/store.ts')
262
+ // `--wip "<what is still wrong>"`: a card sent in work, its first update still broken; a bare --wip goes with --live
263
+ const w = this.args.indexOf('--wip')
264
+ const wipLine = w >= 0 && this.args[w + 1] !== undefined && !this.args[w + 1]!.startsWith('--') ? this.args[w + 1] : undefined
265
+ const { views, rest } = takeViews(wipLine === undefined ? this.args : [...this.args.slice(0, w + 1), ...this.args.slice(w + 2)])
247
266
  // the repo's own flags: the subject kind's (--where), and the unit's for any kind (--mark), each repeatable
248
267
  const kindName = rest[rest.indexOf('--subject') + 1]
249
268
  const kind = rest.includes('--subject') && kindName ? h.unit?.kinds?.[kindName] : undefined
@@ -254,7 +273,9 @@ export class ReviewAddCommand extends Command {
254
273
  const trailer = await trailerOfFlags(o, views.length > 0 || f.on.has('wip') || f.on.has('choice'))
255
274
  const repoFlags = Object.fromEntries(own.flatMap((k) => (f.many[k] ? [[k, f.many[k]]] : [])))
256
275
  const parsed = kind?.parse ? kind.parse(Object.fromEntries(Object.keys(kind.flags ?? {}).map((k) => [k, f.many[k] ?? []]))) : null
257
- if (f.on.has('wip') !== (o.live !== undefined)) throw new Error('--wip --live <name>: a draft card names its live shot, and a live shot makes a draft card')
276
+ if (wipLine !== undefined && o.live !== undefined) throw new Error('--wip "<line>" sends a card in work; --wip --live <name> a draft on a live shot: one of the two')
277
+ if (wipLine === undefined && f.on.has('wip') !== (o.live !== undefined))
278
+ throw new Error('--wip "<what is still wrong>" sends a card in work (sk review update as it moves); --wip --live <name> a draft on a live shot')
258
279
  let wipViews: ViewInput[] = []
259
280
  if (o.live !== undefined) {
260
281
  if (!h.unit?.live) throw new Error("--live: the repo's review unit declares no live shots (live: { frames })")
@@ -319,6 +340,13 @@ export class ReviewAddCommand extends Command {
319
340
  if (h.unit?.add) input = await h.unit.add(input, repoFlags)
320
341
  const item = await addItem(h.dir, input).finally(() => trailer?.drop())
321
342
  h.out(item.id)
343
+ if (wipLine !== undefined) {
344
+ const who = item.origin.by === 'agent' ? (item.origin.lane ?? agentName()) : agentName()
345
+ await postUpdate(h.dir, item.id, { who, state: 'broken', text: wipLine })
346
+ h.err(`in progress: he sees it, it waits on no verdict; post each step with sk review update ${item.id} <broken|better|fixed> "<line>" <file>`)
347
+ }
348
+ // on stderr: a script reads the id alone on stdout
349
+ for (const line of await (await import('../review/previews.ts')).playCopies(h.dir, item)) h.err(line)
322
350
  if (item.trailer) h.out(`trailer card: ${item.trailer.trailer}/${item.trailer.after.cut}${item.trailer.before ? ` against ${item.trailer.before.cut}` : ''}${item.trailer.shots.length > 0 ? `, shots ${item.trailer.shots.join(', ')}` : ''}`)
323
351
  if (item.origin.by === 'agent' && !item.origin.lane) h.err('no lane on the card: pass --lane <id> (or SK_AGENT), so the hub colours it')
324
352
  if (item.choice && item.agentPick === undefined) h.err(`a choice with no pick of yours: every question carries one, sk review pick ${item.id} <view> (or --pick on add)`)
@@ -333,6 +361,7 @@ export class ReviewAddCommand extends Command {
333
361
 
334
362
  export class ReviewAddViewCommand extends Command {
335
363
  static override paths = [['review', 'add-view']]
364
+ static essential = {}
336
365
  static override usage = Command.Usage({
337
366
  category: 'Review',
338
367
  description: 'another angle on a card he has not answered yet: an image, a pair, a clip or a gallery',
@@ -346,7 +375,7 @@ export class ReviewAddViewCommand extends Command {
346
375
  return helpWithUnit(this.context, this.cli.usage(ReviewAddViewCommand, { detailed: true }), false)
347
376
  }
348
377
  return run(this.context, async (h) => {
349
- const { addView } = await import('../review/store.ts')
378
+ const { addView, filesView } = await import('../review/store.ts')
350
379
  const own = Object.keys(h.unit?.flags ?? {})
351
380
  const repoFlags: Record<string, string[]> = {}
352
381
  const args: string[] = []
@@ -368,18 +397,13 @@ export class ReviewAddViewCommand extends Command {
368
397
  ? { label, audio: rest[1] }
369
398
  : rest[0] === '--gallery'
370
399
  ? { label, gallery: rest.slice(1).map(tileOf) }
371
- : rest.length === 1
372
- ? { label, image: rest[0] }
373
- : rest.length === 2
374
- ? { label, before: rest[0], after: rest[1] }
375
- : (() => {
376
- throw new Error('add-view <id> "<label>" <a.png> [<b.png>] | --video <clip> | --gallery <a.png> …')
377
- })()
400
+ : filesView(label, rest, 'add-view <id> "<label>" <a.png> [<b.png>] | --video <clip> | --gallery <a.png> …')
378
401
  if (note !== undefined) v.note = note
379
402
  const extra = h.unit?.addView ? await h.unit.addView(v, repoFlags) : {}
380
403
  const item = await addView(h.dir, id, v, extra)
381
404
  const { viewLetter } = await import('../review/model.ts')
382
405
  h.out(`${id}: view ${viewLetter(item.views.length - 1)} "${label}" added`)
406
+ for (const line of await (await import('../review/previews.ts')).playCopies(h.dir, item, item.views.length - 1)) h.err(line)
383
407
  return 0
384
408
  })
385
409
  }
@@ -435,6 +459,7 @@ export class ReviewLsCommand extends Command {
435
459
 
436
460
  export class ReviewShowCommand extends Command {
437
461
  static override paths = [['review', 'show']]
462
+ static essential = { args: '<id>' }
438
463
  static override usage = Command.Usage({
439
464
  category: 'Review',
440
465
  description: 'one item and its thread: the verdict, rectangles, reactions, the whole conversation',
@@ -485,6 +510,7 @@ async function sessionOf(mine: boolean, session: string | undefined): Promise<st
485
510
 
486
511
  export class ReviewInboxCommand extends Command {
487
512
  static override paths = [['review', 'inbox']]
513
+ static essential = {}
488
514
  static override usage = Command.Usage({
489
515
  category: 'Review',
490
516
  description: 'every answer not marked seen and every open item he raised, frame notes included',
@@ -565,6 +591,7 @@ async function answererRefusal(dir: string, id: string, as: string | undefined,
565
591
 
566
592
  export class ReviewSeenCommand extends Command {
567
593
  static override paths = [['review', 'seen']]
594
+ static essential = { args: '<ids>' }
568
595
  static override usage = Command.Usage({ category: 'Review', description: 'mark his answers and replies on these items read, once you acted on them', details: DETAILS })
569
596
  ids = Option.Rest({ required: 1 })
570
597
  as = Option.String('--as', { description: 'the lane that read it (else SK_AGENT)' })
@@ -592,6 +619,7 @@ export class ReviewSeenCommand extends Command {
592
619
 
593
620
  export class ReviewReplyCommand extends Command {
594
621
  static override paths = [['review', 'reply']]
622
+ static essential = { args: '<id> <text>' }
595
623
  static override usage = Command.Usage({ category: 'Review', description: "your message on a card's thread: what you changed, the answer to his question", details: DETAILS })
596
624
  id = Option.String()
597
625
  text = Option.String()
@@ -611,6 +639,52 @@ export class ReviewReplyCommand extends Command {
611
639
  }
612
640
  }
613
641
 
642
+ export class ReviewUpdateCommand extends Command {
643
+ static override paths = [['review', 'update']]
644
+ static essential = { args: '<id> <state> <text>' }
645
+ static override usage = Command.Usage({
646
+ category: 'Review',
647
+ description: "where a card's work stands, any time: broken, better or fixed, a line, a file or a pair",
648
+ details: `${DETAILS}\n\nsk review update <id> <broken|better|fixed> "<one line>" [<file> | <before> <after>]: the file (an image, a clip or a sound, as it is: no special file) becomes the card's next view, the line and the state go on its thread in time order. Two files make that view a before and after pair, as add --before --after does: two images of one size, two clips of one size and length, or two sounds, never one of each; the owner picks how he compares them (side by side, wipe, fade). broken or better holds the card « in progress » (not waiting on the owner's verdict, still new in the list), fixed asks the owner's verdict again on the same thread, even after an answer. The owner's hint on an update reaches watch and inbox as a reply « on update <k> ». Posted on the thread's newest version.`,
649
+ examples: [
650
+ ['still broken, the take as it is', 'SK_AGENT=L2 sk review update <id> broken "her arm still crosses her leg at 2 s" take.mp4'],
651
+ ['better, not done', 'SK_AGENT=L2 sk review update <id> better "the crossing is gone, the landing still snaps" take.mp4'],
652
+ ['fixed: he answers again', 'SK_AGENT=L2 sk review update <id> fixed "no crossing, no snap over the whole clip" take.mp4'],
653
+ ['better, as a before and after he compares his way', 'SK_AGENT=L2 sk review update <id> better "the snap is half as deep" before.mp4 after.mp4'],
654
+ ],
655
+ })
656
+ id = Option.String()
657
+ state = Option.String()
658
+ text = Option.String()
659
+ files = Option.Rest()
660
+ as = Option.String('--as', { description: 'the lane that posts (else SK_AGENT)' })
661
+
662
+ async execute(): Promise<number> {
663
+ return run(this.context, async (h) => {
664
+ const { postUpdate, agentName, readAll } = await import('../review/store.ts')
665
+ const { threadsOf } = await import('../review/threads.ts')
666
+ const { threadOfId } = await import('../review/cells.ts')
667
+ const asked = await idOf(h.dir, this.id)
668
+ // an update goes where he reads: the thread's newest version
669
+ const id = threadOfId(asked, threadsOf(readAll(h.dir).items))?.head.item.id ?? asked
670
+ const refused = await answererRefusal(h.dir, id, this.as, 'reply')
671
+ if (refused !== null) throw new Error(refused)
672
+ const r = await postUpdate(h.dir, id, { who: laneOfCaller(this.as) ?? agentName(), state: this.state, text: this.text, files: this.files })
673
+ const { viewLetter, stateOf } = await import('../review/model.ts')
674
+ const { readItem } = await import('../review/store.ts')
675
+ const x = readItem(h.dir, id)
676
+ const now = x && stateOf(x, false).state === 'asks' ? "waits for the owner's verdict" : x && stateOf(x, false).state === 'draft' ? 'in progress, no verdict asked' : 'in work'
677
+ h.out(`${id}: ${r.tag}${r.view !== null ? `, view ${viewLetter(r.view)}` : ''}${id !== asked ? ` (on the newest version, ${asked} is older)` : ''}; the card ${now}`)
678
+ if (r.view !== null) for (const line of await (await import('../review/previews.ts')).playCopies(h.dir, r.item, r.view)) h.err(line)
679
+ const { unheardLine } = await import('../review/model.ts')
680
+ const { liveWatchers } = await import('../review/watchers.ts')
681
+ const unheard = unheardLine(r.item, liveWatchers(h.dir))
682
+ if (unheard) h.err(unheard)
683
+ return 0
684
+ })
685
+ }
686
+ }
687
+
614
688
  export class ReviewWithdrawCommand extends Command {
615
689
  static override paths = [['review', 'withdraw']]
616
690
  static override usage = Command.Usage({ category: 'Review', description: 'take an unanswered card back, with the reason', details: DETAILS })
@@ -635,7 +709,13 @@ export class ReviewReopenCommand extends Command {
635
709
  async execute(): Promise<number> {
636
710
  return run(this.context, async (h) => {
637
711
  const { reopen } = await import('../review/store.ts')
638
- for (const id of this.ids) if (!reopen(h.dir, id)) throw new Error(`${id}: no such card, or no answer to reopen`)
712
+ const { followAnswer } = await import('../releases/from-card.ts')
713
+ const { dirname } = await import('node:path')
714
+ for (const id of this.ids) {
715
+ const v = reopen(h.dir, id)
716
+ if (!v) throw new Error(`${id}: no such card, or no answer to reopen`)
717
+ await followAnswer(dirname(dirname(h.dir)), id, v.status)
718
+ }
639
719
  h.out(`review: ${this.ids.length} reopened`)
640
720
  return 0
641
721
  })
@@ -671,6 +751,7 @@ type ActOp = 'fixed' | 'wontfix' | 'claim' | 'release' | 'blocked' | 'done' | 'd
671
751
  function actCommand(op: ActOp, description: string, o: { note?: 'required' | 'optional'; text?: string; topic?: 'required' | 'optional'; named: boolean; examples: [string, string][] }) {
672
752
  return class extends Command {
673
753
  static override paths = [['review', op]]
754
+ static essential = op === 'done' ? { args: '<id> [what changed]' } : op === 'fixed' ? { args: '<id> --note <what was done>' } : undefined
674
755
  static override usage = Command.Usage({ category: 'Review', description, details: `${DETAILS}\n\nTakes an item id or a player report's ref (live#3). ${o.named ? 'Who acts: --as <name>, else SK_AGENT.' : 'Who acts: --as, else SK_AGENT, else agent.'}`, examples: o.examples })
675
756
  id = Option.String()
676
757
  words = o.text !== undefined || o.topic !== undefined ? Option.String({ required: false, name: o.text ?? 'topic' }) : undefined
@@ -1083,6 +1164,7 @@ export class ReviewAutoCommand extends Command {
1083
1164
 
1084
1165
  export class ReviewWatchCommand extends Command {
1085
1166
  static override paths = [['review', 'watch']]
1167
+ static essential = {}
1086
1168
  static override usage = Command.Usage({
1087
1169
  category: 'Review',
1088
1170
  description: 'one line per verdict, reply or raised note as it lands; every unseen one first; ends with its owner',
@@ -1184,6 +1266,7 @@ export const REVIEW_COMMANDS = [
1184
1266
  ReviewInboxCommand,
1185
1267
  ReviewSeenCommand,
1186
1268
  ReviewReplyCommand,
1269
+ ReviewUpdateCommand,
1187
1270
  ReviewWithdrawCommand,
1188
1271
  ReviewReopenCommand,
1189
1272
  ReviewPickCommand,
@@ -3,6 +3,9 @@
3
3
  // Logic in secrets/list.ts and secrets/manager.ts. A value only ever goes to stdout of `get`/`account`,
4
4
  // and only for a repo in the name's scope.
5
5
  import { Command, Option } from 'clipanion'
6
+ import { homedir } from 'os'
7
+ import { relative } from 'path'
8
+ import { houseRootOf } from '../home/home-start.ts'
6
9
  import { presence, secretsFor } from '../secrets/list.ts'
7
10
  import { houseScopeOf, managerTemplate as template, NoManager, readRefusal, REFUSED_EXIT, secretsWhere as where, storeArgv } from '../secrets/manager.ts'
8
11
  import { secretArgv } from '../smoke/run-smoke.ts'
@@ -20,6 +23,7 @@ async function refusing(stderr: NodeJS.WritableStream, run: () => Promise<number
20
23
 
21
24
  export class SecretListCommand extends Command {
22
25
  static override paths = [['secret', 'list'], ['secret']]
26
+ static essential = {}
23
27
 
24
28
  static override usage = Command.Usage({
25
29
  category: 'Secrets',
@@ -51,10 +55,11 @@ export class SecretListCommand extends Command {
51
55
  const mine = rows.filter((r) => r.mine).length
52
56
  say(`${w.repos[0]} speaks as ${w.identity ?? 'no identity'}: ${rows.filter((r) => r.inScope).length} secrets, ${mine} for this repo or identity`)
53
57
  const pad = (k: 'name' | 'for'): number => Math.max(...rows.map((r) => r[k].length))
58
+ if ([...has.values()].includes('locked')) say(`LOCK: there, in a keychain locked to this session (an ssh session sees it so): \`security unlock-keychain\` in it to read them`)
54
59
  for (const r of rows) {
55
60
  const p = has.get(r.name)
56
- const mark = !r.inScope ? 'out ' : p === true ? 'ok ' : 'MISS'
57
- const fix = p === false ? ` → sk secret set ${r.name}` : ''
61
+ const mark = !r.inScope ? 'out ' : p === 'ok' ? 'ok ' : p === 'locked' ? 'LOCK' : 'MISS'
62
+ const fix = p === 'missing' ? ` → sk secret set ${r.name}` : ''
58
63
  say(`${mark} ${r.name.padEnd(pad('name'))} ${r.level.padEnd(5)} ${r.for.padEnd(pad('for'))} ${(r.service ?? '').slice(0, 40)}${fix}`)
59
64
  }
60
65
  return 0
@@ -63,6 +68,7 @@ export class SecretListCommand extends Command {
63
68
 
64
69
  export class SecretReadCommand extends Command {
65
70
  static override paths = [['secret', 'get'], ['secret', 'account']]
71
+ static essential = { args: '<name>' }
66
72
 
67
73
  static override usage = Command.Usage({
68
74
  category: 'Secrets',
@@ -106,3 +112,36 @@ export class SecretSetCommand extends Command {
106
112
  })
107
113
  }
108
114
  }
115
+
116
+ export class SecretCopyCommand extends Command {
117
+ static override paths = [['secret', 'copy']]
118
+
119
+ static override usage = Command.Usage({
120
+ category: 'Secrets',
121
+ description: "this Mac's secrets into another Mac's keychain over ssh, each on ssh's stdin; what it holds stays",
122
+ details: "With no name: every secret of this repo's list that this Mac holds. The other Mac runs its own `sk secret set` from the house checkout at the same place under its home. A secret it already answers is left as it is. A keychain locked to ssh stops the copy and says how to unlock it.",
123
+ examples: [['every secret mini1 lacks', 'sk secret copy --to mini1'], ['one secret', 'sk secret copy rv/shipkit/spaces --to mini1'], ['a Mac whose keychain ssh sees locked, from your terminal', 'sk secret copy --to mini1 --unlock']],
124
+ })
125
+
126
+ names = Option.Rest()
127
+ to = Option.String('--to', { required: true, description: 'the other Mac, as ssh reaches it: an alias of ~/.ssh/config' })
128
+ unlock = Option.Boolean('--unlock', false, { description: "unlock that Mac's keychain first, in the same ssh session: run it from your terminal, it asks for that Mac's login password once" })
129
+
130
+ async execute(): Promise<number> {
131
+ return refusing(this.context.stderr, async () => {
132
+ const w = await where(process.cwd())
133
+ const houseRoot = houseRootOf(process.cwd())
134
+ if (houseRoot == null || !houseRoot.startsWith(`${homedir()}/`)) throw new NoManager('FAIL the house checkout is not under the home folder: the other Mac finds it at the same place under its own')
135
+ const inHouse = w.house != null && w.house === w.own
136
+ const rows = secretsFor({ asker: w, own: inHouse ? [] : (w.own?.creds ?? []), house: w.house?.creds ?? [] }).filter((r) => r.inScope)
137
+ const names = this.names.length > 0 ? this.names : rows.map((r) => r.name)
138
+ const { copySecrets, copyWithUnlock } = await import('../secrets/copy.ts')
139
+ if (this.unlock) return copyWithUnlock({ names, to: this.to, reader: template(w, 'credsReadCommand'), houseRel: relative(homedir(), houseRoot), say: (l) => void this.context.stdout.write(`${l}\n`) })
140
+ const r = await copySecrets({ names, to: this.to, reader: template(w, 'credsReadCommand'), houseRel: relative(homedir(), houseRoot) })
141
+ for (const c of r.copied) this.context.stdout.write(`${c.did === 'failed' ? 'FAIL' : c.did === 'copied' ? 'ok ' : 'skip'} ${c.name} ${c.did}${c.why ? `: ${c.why}` : ''}\n`)
142
+ const n = (d: string): number => r.copied.filter((c) => c.did === d).length
143
+ this.context.stdout.write(`${n('copied')} copied, ${n('there')} already on ${this.to}, ${n('not here')} not on this Mac, ${n('failed')} failed${r.locked ? ' (stopped: locked)' : ''}\n`)
144
+ return n('failed') > 0 ? 1 : 0
145
+ })
146
+ }
147
+ }
@@ -19,6 +19,7 @@ export const renderShot = (r: ShotResult, cwd: string): string[] => {
19
19
 
20
20
  export class ShotCommand extends Command {
21
21
  static override paths = [['shot']]
22
+ static essential = { args: '<url>' }
22
23
 
23
24
  static override usage = Command.Usage({
24
25
  category: 'Serve',
@@ -5,6 +5,7 @@ import { jobStatus, STILL_RUNNING } from '../core/jobs.ts'
5
5
 
6
6
  export class StatusCommand extends Command {
7
7
  static override paths = [['status']]
8
+ static essential = {}
8
9
 
9
10
  static override usage = Command.Usage({
10
11
  category: 'Gate',
@@ -9,6 +9,7 @@ const BIG_BYTES = 50 * 1024 * 1024
9
9
 
10
10
  export class TimeCommand extends Command {
11
11
  static override paths = [['time']]
12
+ static essential = {}
12
13
 
13
14
  static override usage = Command.Usage({
14
15
  category: 'Health',
@@ -18,7 +19,8 @@ export class TimeCommand extends Command {
18
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.',
19
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
21
  '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.',
21
- 'Wall time is cut once per moment: tools in flight, a sub-agent in flight, waiting on a background task, waiting on you (an idle gap past 30 minutes is left out), else the model.',
22
+ '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
+ '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.',
22
24
  'Commands and prompts are masked through the leak guard keyword list and token shapes before they print.',
23
25
  ].join(' '),
24
26
  examples: [
@@ -0,0 +1,82 @@
1
+ // sk tmp: the machine's temp folders (home/machine-temp.ts): what the last pass measured, with no walk, the pass run
2
+ // now, and the daemon's switch. Every module loads inside execute: the cli registers this file on every `sk` call
3
+ import { Command, Option } from 'clipanion'
4
+
5
+ const DETAILS = `agents and test runs write into three temp roots nothing else trims: claude code's session scratch (/tmp/claude-<uid>/<project>/<session>/), the user's temp dir and /tmp. One pass deletes each unit nothing wrote for 24 h that no live process holds open, has as its working folder or names on its command line or in its environment, and that holds no git work a remote lacks; while the disk is under 40 GB free, units idle 6 h go too, the largest first, until it is back over. A unit is a child of a root, and inside a claude session each piece of its scratchpad, so a session that runs for days loses its old pieces too. Nothing is deleted before the owner turns the switch on (--auto on); then the daemon runs the pass hourly, one process at a time on the machine. What a pass measured is kept, so this command answers at once, where a du over a temp root walks every file again. Page: wiki tools/shipkit/machine-temp.md`
6
+
7
+ type Ctx = { stdout: NodeJS.WritableStream; stderr: NodeJS.WritableStream }
8
+ const io = (c: Ctx): { out: (l: string) => void; err: (l: string) => void } => ({ out: (l) => void c.stdout.write(`${l}\n`), err: (l) => void c.stderr.write(`${l}\n`) })
9
+
10
+ export class TmpCommand extends Command {
11
+ static override paths = [['tmp']]
12
+ static override usage = Command.Usage({
13
+ category: 'Health',
14
+ description: 'the temp folders with no walk: free space, what each root holds, the largest units and why they stay',
15
+ details: DETAILS,
16
+ examples: [
17
+ ['where the temp folders stand', 'sk tmp'],
18
+ ['the daemon sweeps them hourly from now on', 'sk tmp --auto on'],
19
+ ],
20
+ })
21
+ auto = Option.String('--auto', { description: 'on: the daemon\'s hourly retention sweep and sk tmp sweep delete idle temp units; off: nothing deletes (off until the owner turns it on)' })
22
+ top = Option.String('--top', '12', { description: 'how many of the largest kept units to name' })
23
+
24
+ async execute(): Promise<number> {
25
+ const { out, err } = io(this.context)
26
+ const t = await import('../home/machine-temp.ts')
27
+ if (this.auto !== undefined) {
28
+ if (this.auto !== 'on' && this.auto !== 'off') { err(`FAIL: --auto takes on or off, not ${this.auto}`); return 1 }
29
+ if (!t.setTempAuto(this.auto === 'on')) { err('FAIL: the machine db does not open: the switch is not set'); return 1 }
30
+ }
31
+ const { statfsSync } = await import('node:fs')
32
+ const { tmpdir } = await import('node:os')
33
+ const s = statfsSync(tmpdir())
34
+ const free = s.bavail * s.bsize
35
+ const hours = (ms: number): number => ms / 3_600_000
36
+ out(`disk ${t.gb(free)} free${free < t.TEMP_FLOOR_BYTES ? ` (under the ${t.TEMP_FLOOR_BYTES / 1e9} GB floor: units idle ${hours(t.TEMP_GUARD_LOW_MS)} h go too, the largest first, until it is back over)` : ` (a unit idle ${hours(t.TEMP_GUARD_MS)} h goes)`}`)
37
+ out(`the daemon's temp sweep ${t.tempAuto() ? 'on, hourly' : 'off (sk tmp --auto on turns it on)'}`)
38
+ const use = t.tempUse()
39
+ if (use == null) { out(t.tempAuto() ? 'not measured yet: the daemon\'s next hourly sweep measures' : 'not measured yet: a pass measures once the switch is on'); return 0 }
40
+ const mins = Math.round((Date.now() - use.at) / 60_000)
41
+ out(`last pass ${new Date(use.at).toISOString().slice(0, 16)}Z, ${mins} min ago, took ${(use.tookMs / 1000).toFixed(1)} s`)
42
+ for (const p of use.passes) out(`${p.id} ${p.root} kept ${t.gb(p.keptBytes)} in ${p.kept} units freed ${t.gb(p.freed)} in ${p.dropped}${p.failed > 0 ? ` ${p.failed} not deleted` : ''}`)
43
+ const top = use.passes.flatMap((p) => p.top).sort((a, b) => b.bytes - a.bytes).slice(0, Math.max(0, Number(this.top) || 0))
44
+ if (top.length > 0) out('the largest kept:')
45
+ for (const u of top) out(` ${u.floor === true ? 'at least ' : ''}${t.gb(u.bytes)} ${u.why} ${u.path}`)
46
+ out('a du or an rm -rf over a whole temp root walks every file again: this pass is the one walker. `sk tmp sweep` runs it now')
47
+ return 0
48
+ }
49
+ }
50
+
51
+ export class TmpSweepCommand extends Command {
52
+ static override paths = [['tmp', 'sweep']]
53
+ static override usage = Command.Usage({
54
+ category: 'Health',
55
+ description: 'one pass over the temp folders now: each idle unit no live process uses deleted, or named with --dry',
56
+ details: DETAILS,
57
+ examples: [
58
+ ['what a pass would delete, nothing deleted', 'sk tmp sweep --dry'],
59
+ ['a pass now', 'sk tmp sweep'],
60
+ ['one pass the owner asked for, the switch still off', 'sk tmp sweep --once'],
61
+ ],
62
+ })
63
+ dry = Option.Boolean('--dry', false, { description: 'name each unit the pass would delete (idle age, size) and the totals, delete nothing' })
64
+ once = Option.Boolean('--once', false, { description: 'one pass by hand though the switch is off: only when the owner asked for this run' })
65
+
66
+ async execute(): Promise<number> {
67
+ const { out, err } = io(this.context)
68
+ const { sweepTemp, tempAuto } = await import('../home/machine-temp.ts')
69
+ if (!this.dry && !this.once && !tempAuto()) {
70
+ err('FAIL: the owner\'s switch is off, so nothing is deleted: `sk tmp --auto on` is the owner\'s to turn on, `sk tmp sweep --dry` names what a pass would delete, and `--once` runs one pass when the owner asked for it')
71
+ return 1
72
+ }
73
+ try {
74
+ return sweepTemp({ dry: this.dry, print: out, printErr: err }) == null ? 1 : 0
75
+ } catch (e) {
76
+ err(`FAIL: tmp sweep: ${e instanceof Error ? e.message : String(e)}`)
77
+ return 1
78
+ }
79
+ }
80
+ }
81
+
82
+ export const TMP_COMMANDS = [TmpCommand, TmpSweepCommand]
@@ -33,6 +33,7 @@ export class WikiServeCommand extends Command {
33
33
 
34
34
  export class WikiLintCommand extends Command {
35
35
  static override paths = [['wiki', 'lint']]
36
+ static essential = {}
36
37
 
37
38
  static override usage = Command.Usage({
38
39
  category: 'Wiki',
@@ -11,6 +11,7 @@ import { CallsCommand } from './cmd_Calls.ts'
11
11
  import { TimeCommand } from './cmd_Time.ts'
12
12
  import { DrillCalibrateCommand, DrillCleanCommand, DrillCloneCommand, DrillCompareCommand, DrillFinishCommand, DrillReportCommand, DrillVerdictCommand } from './cmd_Drill.ts'
13
13
  import { CheckCommand } from './cmd_Check.ts'
14
+ import { CapacityCommand } from './cmd_Capacity.ts'
14
15
  import { CommandsCommand } from './cmd_Commands.ts'
15
16
  import { withFamilyPage } from './family-pages.ts'
16
17
  import { CrossRepoActivityCommand } from './cmd_CrossRepoActivity.ts'
@@ -51,16 +52,23 @@ import { MEDIA_COMMANDS } from './cmd_Media.ts'
51
52
  import { REC_COMMANDS } from './cmd_Rec.ts'
52
53
  import { SignSetupCommand } from './cmd_Sign.ts'
53
54
  import { ANNEX_COMMANDS } from './cmd_Annex.ts'
55
+ import { TMP_COMMANDS } from './cmd_Tmp.ts'
54
56
  import { BACKUP_COMMANDS } from './cmd_Backup.ts'
55
57
  import { VEILLE_COMMANDS } from './cmd_Veille.ts'
56
58
  import { MESSAGES_COMMANDS } from './cmd_Messages.ts'
57
59
  import { TuiCommand } from './cmd_Tui.ts'
58
- import { SecretListCommand, SecretReadCommand, SecretSetCommand } from './cmd_Secret.ts'
60
+ import { SecretListCommand, SecretReadCommand, SecretSetCommand, SecretCopyCommand } from './cmd_Secret.ts'
59
61
  import { WikiLintCommand, WikiServeCommand } from './cmd_Wiki.ts'
60
62
 
61
63
 
62
64
  /** `sk <family> --help` names the family's page under its list */
63
65
  class FamilyHelpCli extends Cli {
66
+ /** every class registered, so `sk commands` reads each command's marks (essential, film) */
67
+ readonly classes: Parameters<Cli['register']>[0][] = []
68
+ override register(c: Parameters<Cli['register']>[0]): void {
69
+ this.classes.push(c)
70
+ super.register(c)
71
+ }
64
72
  override process(...args: unknown[]): Command {
65
73
  return withFamilyPage((super.process as (...a: unknown[]) => Command).apply(this, args))
66
74
  }
@@ -102,6 +110,7 @@ export function buildCli(): Cli {
102
110
  for (const c of REC_COMMANDS) cli.register(c)
103
111
  cli.register(SignSetupCommand)
104
112
  for (const c of ANNEX_COMMANDS) cli.register(c)
113
+ for (const c of TMP_COMMANDS) cli.register(c)
105
114
  for (const c of BACKUP_COMMANDS) cli.register(c)
106
115
  for (const c of VEILLE_COMMANDS) cli.register(c)
107
116
  for (const c of MESSAGES_COMMANDS) cli.register(c)
@@ -123,6 +132,7 @@ export function buildCli(): Cli {
123
132
  cli.register(SecretListCommand)
124
133
  cli.register(SecretReadCommand)
125
134
  cli.register(SecretSetCommand)
135
+ cli.register(SecretCopyCommand)
126
136
  cli.register(AssetsFillCommand)
127
137
  cli.register(AssetsAddCommand)
128
138
  cli.register(AssetsGenCommand)
@@ -154,6 +164,7 @@ export function buildCli(): Cli {
154
164
  cli.register(TraceAuditCommand)
155
165
  cli.register(UnitsAliasCommand)
156
166
  cli.register(CommandsCommand)
167
+ cli.register(CapacityCommand)
157
168
  cli.register(CallsCommand)
158
169
  cli.register(TimeCommand)
159
170
  cli.register(DrillReportCommand)
@@ -165,5 +176,6 @@ export function buildCli(): Cli {
165
176
  cli.register(DrillCalibrateCommand)
166
177
  cli.register(ConfigKeysCommand)
167
178
 
179
+ CommandsCommand.registered = cli.classes
168
180
  return cli
169
181
  }
@@ -22,7 +22,7 @@ export type PingIo = {
22
22
  /** additive desktop notification on macOS */
23
23
  osascript?: boolean
24
24
  /** the url appended to the message for what it pings, in the OFF-MACHINE
25
- * form (serve.publicHost), a phone can't resolve localhost: the home's
25
+ * form (this Mac's tailnet name, machine-host.ts), a phone can't resolve localhost: the home's
26
26
  * inbox on that one item, or on the list for several */
27
27
  link?: (fresh: NeedItem[]) => string | undefined
28
28
  }
@@ -0,0 +1,71 @@
1
+ // HOW MANY MORE LANES THE MACHINE CAN TAKE NOW, read from the machine: its
2
+ // cores, its load, and the agents writing right now (every account, every
3
+ // repo). No fixed cap: the answer moves with what the machine runs.
4
+ //
5
+ // The one constraint a reader breaks first: an agent counts for at least one
6
+ // core. Most of a lane's time is its model's turns, which load nothing here,
7
+ // so a quiet moment reads far under what its next test run will cost.
8
+ import { availableParallelism, loadavg } from 'os'
9
+ import { listTranscripts, type TranscriptFile } from '../agent-time/store.ts'
10
+
11
+ /** an agent is live when its transcript was written this recently */
12
+ export const LIVE_WINDOW_MS = 3 * 60 * 1000
13
+
14
+ export type LiveAgents = { sessions: number; lanes: number; byProject: [project: string, agents: number][] }
15
+
16
+ /** the sessions and sub-agents whose transcript moved inside the window */
17
+ export function liveAgents(files: readonly TranscriptFile[], now: number, windowMs = LIVE_WINDOW_MS): LiveAgents {
18
+ const live = files.filter((f) => now - f.mtime <= windowMs)
19
+ const by = new Map<string, number>()
20
+ for (const f of live) by.set(f.project, (by.get(f.project) ?? 0) + 1)
21
+ return {
22
+ sessions: live.filter((f) => f.agent === '').length,
23
+ lanes: live.filter((f) => f.agent !== '').length,
24
+ byProject: [...by].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)),
25
+ }
26
+ }
27
+
28
+ export type Capacity = {
29
+ cores: number
30
+ /** the larger of the 1 and the 5 minute load: a burst counts at once, and a lull does not open the door */
31
+ load: number
32
+ agents: number
33
+ /** what one agent costs now, in cores: the load shared between the live agents, never under one */
34
+ perAgent: number
35
+ /** the lanes the machine can start now */
36
+ room: number
37
+ /** how far the load sits over the cores, 0 when under */
38
+ over: number
39
+ }
40
+
41
+ export function capacityOf(p: { cores: number; load1: number; load5: number; agents: number }): Capacity {
42
+ const load = Math.max(p.load1, p.load5)
43
+ const perAgent = Math.max(1, p.agents > 0 ? load / p.agents : 1)
44
+ const free = p.cores - load
45
+ return { cores: p.cores, load, agents: p.agents, perAgent, room: free <= 0 ? 0 : Math.floor(free / perAgent), over: free < 0 ? -free : 0 }
46
+ }
47
+
48
+ /** the machine read now */
49
+ export function readCapacity(now = Date.now()): { capacity: Capacity; live: LiveAgents } {
50
+ const live = liveAgents(listTranscripts(), now)
51
+ const [load1 = 0, load5 = 0] = loadavg()
52
+ return { capacity: capacityOf({ cores: availableParallelism(), load1, load5, agents: live.sessions + live.lanes }), live }
53
+ }
54
+
55
+ const one = (n: number): string => n.toFixed(1)
56
+ const plural = (n: number, word: string): string => `${n} ${word}${n === 1 ? '' : 's'}`
57
+
58
+ /** the answer in three lines: the measure, who is live, the room */
59
+ export function capacityLines(c: Capacity, live: LiveAgents): string[] {
60
+ const who = live.byProject.slice(0, 5).map(([p, n]) => `${p.replace(/^.*-dev-/, '')} ${n}`).join(', ')
61
+ const verdict = c.room > 0
62
+ ? `ok: room for ${plural(c.room, 'more lane')} now: ${one(c.cores - c.load)} of ${c.cores} cores free, ${one(c.perAgent)} a lane`
63
+ : c.over > 0
64
+ ? `WAIT: no room for a lane: the load is ${one(c.over)} over the ${c.cores} cores, so every tool of every agent already waits. A lane started now slows the others`
65
+ : `WAIT: no room for a lane: ${one(c.cores - c.load)} of ${c.cores} cores free, and a lane costs ${one(c.perAgent)} now`
66
+ return [
67
+ `machine: ${c.cores} cores, load ${one(c.load)} (the larger of 1 and 5 min)`,
68
+ `agents writing in the last ${LIVE_WINDOW_MS / 60_000} min: ${c.agents} (${plural(live.sessions, 'session')}, ${plural(live.lanes, 'lane')})${who === '' ? '' : `: ${who}`}`,
69
+ verdict,
70
+ ]
71
+ }