rvlib-shipkit 2.23.0 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/live.ts +153 -0
  4. package/src/agent-time/render.ts +28 -14
  5. package/src/agent-time/report.ts +46 -25
  6. package/src/agent-time/store.ts +30 -10
  7. package/src/agent-time/timeline.ts +43 -15
  8. package/src/annex/offload.ts +16 -7
  9. package/src/asks/asks-queue.ts +32 -11
  10. package/src/check.ts +3 -1
  11. package/src/checks/SK004-gitignore-policy.check.ts +32 -11
  12. package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
  13. package/src/checks/SK033-global-contribution.check.ts +1 -1
  14. package/src/checks/SK036-draft-media-size.check.ts +1 -1
  15. package/src/checks/SK040-release-words.check.ts +1 -1
  16. package/src/checks/SK042-post-kinds.check.ts +1 -1
  17. package/src/checks/SK044-behind-upstream.check.ts +38 -0
  18. package/src/cli/cmd_Annex.ts +12 -7
  19. package/src/cli/cmd_Asks.ts +2 -0
  20. package/src/cli/cmd_Assets.ts +5 -5
  21. package/src/cli/cmd_Backup.ts +16 -8
  22. package/src/cli/cmd_Bump.ts +1 -0
  23. package/src/cli/cmd_Capacity.ts +30 -0
  24. package/src/cli/cmd_Check.ts +1 -0
  25. package/src/cli/cmd_Checks.ts +13 -1
  26. package/src/cli/cmd_Ci.ts +3 -2
  27. package/src/cli/cmd_Commands.ts +61 -16
  28. package/src/cli/cmd_ConfigKeys.ts +17 -0
  29. package/src/cli/cmd_Home.ts +1 -30
  30. package/src/cli/cmd_Hooks.ts +1 -0
  31. package/src/cli/cmd_Keys.ts +4 -1
  32. package/src/cli/cmd_Lanes.ts +35 -0
  33. package/src/cli/cmd_Mv.ts +7 -7
  34. package/src/cli/cmd_Rec.ts +22 -7
  35. package/src/cli/cmd_Reflect.ts +1 -0
  36. package/src/cli/cmd_Releases.ts +1 -0
  37. package/src/cli/cmd_Review.ts +200 -49
  38. package/src/cli/cmd_Secret.ts +41 -2
  39. package/src/cli/cmd_Shot.ts +16 -4
  40. package/src/cli/cmd_Status.ts +7 -5
  41. package/src/cli/cmd_Time.ts +13 -5
  42. package/src/cli/cmd_Tmp.ts +82 -0
  43. package/src/cli/cmd_Veille.ts +10 -6
  44. package/src/cli/cmd_Wiki.ts +1 -0
  45. package/src/cli/family-help.ts +136 -0
  46. package/src/cli/family-pages.ts +0 -19
  47. package/src/cli/kit/calls.ts +35 -0
  48. package/src/cli/kit/project-cli.ts +2 -12
  49. package/src/cli/registry.ts +52 -7
  50. package/src/cli.ts +8 -4
  51. package/src/collections/pings.ts +1 -1
  52. package/src/core/capacity.ts +127 -0
  53. package/src/core/check-runner.ts +91 -16
  54. package/src/core/floor-resolve.ts +6 -2
  55. package/src/core/floor.ts +6 -2
  56. package/src/core/history-files.ts +18 -0
  57. package/src/core/jobs.ts +35 -16
  58. package/src/core/layout.ts +2 -2
  59. package/src/core/motherhome.ts +67 -9
  60. package/src/core/nearest.ts +16 -0
  61. package/src/core/remove-tree.ts +19 -0
  62. package/src/core/runs.ts +12 -3
  63. package/src/core/slots.ts +49 -12
  64. package/src/core/throwaway-worktree.ts +22 -4
  65. package/src/core/trace-audit.ts +21 -5
  66. package/src/drill/run.ts +5 -2
  67. package/src/home/daemon-jobs.ts +41 -4
  68. package/src/home/gui-app/ShipkitGui.swift +1 -0
  69. package/src/home/home-launchd.ts +11 -3
  70. package/src/home/home-routes.ts +11 -4
  71. package/src/home/machine-host.ts +65 -0
  72. package/src/home/machine-stores.ts +19 -17
  73. package/src/home/machine-temp.ts +485 -0
  74. package/src/home/other-macs.ts +74 -0
  75. package/src/home/run-daemon.ts +10 -2
  76. package/src/home/serve-web.ts +2 -2
  77. package/src/home/via-hub.ts +6 -1
  78. package/src/init-repo.ts +7 -3
  79. package/src/ledger/gate-checks.ts +3 -2
  80. package/src/ledger/git-key.ts +25 -4
  81. package/src/ledger/git-scan.ts +10 -0
  82. package/src/ledger/ledger.ts +6 -0
  83. package/src/ledger/store.ts +6 -0
  84. package/src/media-store/backup/daemon.ts +92 -20
  85. package/src/media-store/backup/keys.ts +21 -6
  86. package/src/media-store/backup/manifest.ts +52 -11
  87. package/src/media-store/backup/restore.ts +17 -10
  88. package/src/media-store/backup/run.ts +26 -17
  89. package/src/media-store/backup/sources.ts +168 -22
  90. package/src/media-store/backup/watch.ts +106 -0
  91. package/src/media-store/daemon.ts +36 -8
  92. package/src/media-store/hand.ts +3 -1
  93. package/src/mv/mv-md.ts +167 -56
  94. package/src/pb/run-pb.ts +2 -10
  95. package/src/plan/repo-source.ts +25 -14
  96. package/src/recordings/model.ts +1 -1
  97. package/src/reflect/transcript.ts +56 -11
  98. package/src/release/run-bump.ts +3 -2
  99. package/src/release/run-release.ts +12 -4
  100. package/src/releases/from-card.ts +45 -3
  101. package/src/releases/model.ts +6 -0
  102. package/src/releases/store.ts +8 -1
  103. package/src/repo-config.ts +5 -3
  104. package/src/review/cells.ts +26 -4
  105. package/src/review/format.ts +34 -10
  106. package/src/review/media-kind.ts +14 -11
  107. package/src/review/media-read.ts +6 -5
  108. package/src/review/model.ts +85 -4
  109. package/src/review/paste.ts +2 -1
  110. package/src/review/previews.ts +123 -36
  111. package/src/review/routes.ts +29 -18
  112. package/src/review/store.ts +89 -19
  113. package/src/review/threads.ts +7 -5
  114. package/src/review/trailer-model.ts +2 -2
  115. package/src/secrets/copy.ts +110 -0
  116. package/src/secrets/list.ts +17 -7
  117. package/src/serve/hub-app/home-strip.css +5 -0
  118. package/src/serve/hub-app/home-strip.tsx +18 -0
  119. package/src/serve/hub-app/hub-app.tsx +2 -1
  120. package/src/serve/hub-app/hub.css +14 -0
  121. package/src/serve/hub-app/inbox.css +1 -0
  122. package/src/serve/hub-app/pull-refresh.tsx +88 -0
  123. package/src/serve/hub-app/review/review-cells.tsx +52 -13
  124. package/src/serve/hub-app/review/review-list.tsx +6 -1
  125. package/src/serve/hub-app/review/review-st.ts +6 -5
  126. package/src/serve/hub-app/review/review-thread.tsx +3 -1
  127. package/src/serve/hub-app/review/review-views.tsx +18 -11
  128. package/src/serve/hub-app/review/thread-st.ts +82 -14
  129. package/src/serve/hub-app/review.css +15 -2
  130. package/src/serve/hub-runtime.ts +2 -1
  131. package/src/serve/run-serve.ts +4 -2
  132. package/src/serve/serve-hub.ts +9 -2
  133. package/src/shot/client.ts +4 -2
  134. package/src/shot/serve-shot.ts +71 -2
  135. package/src/shot/shooter.ts +65 -11
  136. package/src/shot/shot-ask.ts +32 -9
  137. package/src/suite/child-tools.ts +45 -0
  138. package/src/suite/judge-suites.ts +10 -22
  139. package/src/suite/select.ts +95 -9
  140. package/src/suite/suite-cli.ts +38 -14
  141. package/src/suite/suite-cores.ts +68 -0
  142. package/src/suite/suite-reads-preload.ts +8 -6
  143. package/src/suite/test-units.ts +31 -12
  144. package/src/trailer/graph.ts +2 -1
  145. package/src/ts/config.ts +21 -0
  146. package/src/ts/rename.ts +37 -13
  147. package/src/ts/workspaces.ts +45 -0
  148. package/src/wiki/run-wiki.ts +7 -2
  149. package/src/wiki/scan-md.ts +2 -1
  150. package/src/home/claude-temp.ts +0 -139
@@ -144,9 +144,11 @@ export class ThreadSt {
144
144
  full: Record<string, boolean> = {}
145
145
  /** an option row folded or unfolded by hand, by `<item>#<view>` */
146
146
  openRows: Record<string, boolean> = {}
147
+ /** his hint being typed on an agent's update, by the update's cell id */
148
+ hints: Record<string, string> = {}
147
149
  busy = false
148
- /** the verdict he just gave: shown as chosen the moment he clicks, while the store takes it */
149
- sending: { on: string; status: ReviewStatus } | null = null
150
+ /** the verdict he just gave (null: the one he took back): shown the moment he clicks, while the store takes it */
151
+ sending: { on: string; status: ReviewStatus | null } | null = null
150
152
  private readonly clips = new Map<string, ClipSt>()
151
153
  /** a trailer card's player, by its version's id */
152
154
  private readonly trailers = new Map<string, TrailerSt>()
@@ -431,7 +433,10 @@ export class ThreadSt {
431
433
  if (h?.kind !== 'version' || h.item.wip) return []
432
434
  const sent = this.verdictsOn(h.id).findLast((v) => v.current)
433
435
  const choice = isChoice(h.item)
434
- return h.item.views.map((v, i) => {
436
+ // an older update's picture is history: only the newest one waits for his answer
437
+ const ups = this.updateViewsOf(h.id)
438
+ const past = new Set(ups.slice(0, -1))
439
+ return h.item.views.flatMap((v, i) => (past.has(i) ? [] : [{ v, i }])).map(({ v, i }) => {
435
440
  const own = this.reactionOf(i)
436
441
  const given = sent?.reactions.find((r) => r.view === i && r.tile === undefined)
437
442
  const r = own ?? given
@@ -444,6 +449,11 @@ export class ThreadSt {
444
449
  })
445
450
  }
446
451
 
452
+ /** the views of an item its agent's updates hold, oldest update first: they draw in the update's cell */
453
+ updateViewsOf(on: string): number[] {
454
+ return this.cells.flatMap((c) => (c.kind === 'reply' && c.on === on && c.update?.view !== undefined ? [c.update.view] : []))
455
+ }
456
+
447
457
  /** the views of that version still waiting for his answer, of all its views: « 3 of 5 views waiting for you » */
448
458
  get waitingViews(): { waiting: number; of: number } | null {
449
459
  const marks = this.viewMarks
@@ -456,8 +466,8 @@ export class ThreadSt {
456
466
  /** the verdicts on one version, oldest first */
457
467
  /** the verdict a version shows as chosen: the one being sent, else its current one */
458
468
  chosenOn(id: string): ReviewStatus | undefined {
459
- if (this.sending?.on === id) return this.sending.status
460
- return this.verdictsOn(id).findLast((x) => x.current)?.verdict
469
+ if (this.sending?.on === id) return this.sending.status ?? undefined
470
+ return this.currentVerdict(id)?.verdict
461
471
  }
462
472
 
463
473
  verdictsOn(id: string): VerdictCell[] {
@@ -693,10 +703,15 @@ export class ThreadSt {
693
703
  return [...(this.draft.reactions ?? [])].sort((a, b) => a.view - b.view || (a.tile ?? -1) - (b.tile ?? -1))
694
704
  }
695
705
 
696
- /** « pick »: that option is his answer, sent at once as an approval; his stars and words go with it */
706
+ /** « pick »: that option is his answer, sent at once as an approval; his stars and words go with it. The option he
707
+ * picked, clicked again, takes the pick back */
697
708
  async choose(view: number): Promise<void> {
698
709
  const h = this.head
699
710
  if (h?.kind !== 'version' || !isChoice(h.item)) return
711
+ if (this.holdsPick(h.id, view)) {
712
+ this.edit(({ pick: _, ...d }) => d)
713
+ return this.takeBack()
714
+ }
700
715
  this.edit((d) => ({ ...d, pick: view }))
701
716
  await this.submit('approved')
702
717
  }
@@ -847,7 +862,19 @@ export class ThreadSt {
847
862
 
848
863
  // ── what he sends ──
849
864
 
850
- /** V, F, R, A: the draft goes to the newest version as the owner's verdict */
865
+ /** the verdict that holds on a version now, as sent: what a click on the lit verdict takes back */
866
+ private currentVerdict(id: string): VerdictCell | undefined {
867
+ return this.verdictsOn(id).findLast((x) => x.current)
868
+ }
869
+
870
+ /** that option is the pick his answer holds: a click on it takes it back */
871
+ holdsPick(id: string, view: number): boolean {
872
+ const v = this.currentVerdict(id)
873
+ return v?.verdict === 'approved' && v.pick === view
874
+ }
875
+
876
+ /** V, F, R, A: the draft goes to the newest version as the owner's verdict. The verdict that holds already, clicked
877
+ * again, is taken back instead (a new pick on a choice is a new answer) */
851
878
  async submit(status: ReviewStatus): Promise<void> {
852
879
  const h = this.head
853
880
  if (!h || this.busy) return
@@ -860,20 +887,36 @@ export class ThreadSt {
860
887
  return
861
888
  }
862
889
  const d = this.draft
863
- const head = this.data?.head ?? h.id
864
- this.busy = true
865
- this.error = null
866
- this.sending = { on: h.id, status }
867
- this.rv.setAnswering(head, status)
868
- try {
890
+ const held = this.currentVerdict(h.id)
891
+ if (held?.verdict === status && (d.pick === undefined || d.pick === held.pick)) return this.takeBack()
892
+ await this.send(h.id, status, async () => {
869
893
  const pick = isChoice(h.item) && isApproved(status) && d.pick !== undefined ? { pick: d.pick } : {}
870
894
  await postJson(this.rv.url(`/api/review/${h.id}/feedback`), { status, comment: d.comment, rects: d.rects, reactions: d.reactions ?? [], ...pick })
871
895
  runInAction(() => this.settle(h.id, d))
896
+ })
897
+ }
898
+
899
+ /** a click on his lit verdict: he takes it back, and the card waits for his answer again (the old verdict stays in
900
+ * the thread, an agent's watch hears it); his draft stays as it is */
901
+ async takeBack(): Promise<void> {
902
+ const h = this.head
903
+ if (h?.kind !== 'version' || this.busy || !this.currentVerdict(h.id)) return
904
+ await this.send(h.id, null, () => postJson(this.rv.url(`/api/review/${h.id}/reopen`), {}))
905
+ }
906
+
907
+ /** one answer on its way: shown at once on the card and its row, the truth again once the store took it or refused */
908
+ private async send(on: string, status: ReviewStatus | null, post: () => Promise<unknown>): Promise<void> {
909
+ const head = this.data?.head ?? on
910
+ this.busy = true
911
+ this.error = null
912
+ this.sending = { on, status }
913
+ this.rv.setAnswering(head, status ?? 'pending')
914
+ try {
915
+ await post()
872
916
  await this.rv.answered()
873
917
  } catch (e) {
874
918
  runInAction(() => (this.error = (e as Error).message))
875
919
  } finally {
876
- // the store's answer is in by now, or the send failed: either way what shows is the truth again
877
920
  runInAction(() => {
878
921
  this.busy = false
879
922
  this.sending = null
@@ -905,6 +948,31 @@ export class ThreadSt {
905
948
  }
906
949
  }
907
950
 
951
+ setHint(cellId: string, text: string): void {
952
+ this.hints[cellId] = text
953
+ }
954
+
955
+ /** Enter or « hint »: his few words on one update go to its item as a reply naming it; the card stays as it is */
956
+ async sendHint(c: { id: string; on: string }): Promise<void> {
957
+ const sent = this.hints[c.id] ?? ''
958
+ const text = sent.trim()
959
+ const re = c.id.slice(c.on.length + 1)
960
+ if (!text || this.busy) return
961
+ this.busy = true
962
+ this.error = null
963
+ try {
964
+ await postJson(this.rv.url(`/api/review/${c.on}/reply`), { text, re })
965
+ runInAction(() => {
966
+ if (this.hints[c.id] === sent) delete this.hints[c.id]
967
+ })
968
+ await this.rv.answered()
969
+ } catch (e) {
970
+ runInAction(() => (this.error = (e as Error).message))
971
+ } finally {
972
+ runInAction(() => (this.busy = false))
973
+ }
974
+ }
975
+
908
976
  /** the agent words he has not read, by cell id: the page sends them read once each shows on his screen */
909
977
  get unreadCells(): string[] {
910
978
  return this.cells.filter((c) => (c.kind === 'reply' || c.kind === 'note') && c.party === 'agent' && !c.read && c.id.includes('/')).map((c) => c.id)
@@ -79,9 +79,18 @@
79
79
  color:var(--bg);background:var(--tone,var(--dim));white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}
80
80
  .rv-badge.outline{background:none;color:var(--ink);border:1px solid var(--line)}
81
81
  .rv-about{font-size:11px;color:var(--dim);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
82
+ /* an agent's update: where the work stands, at a glance; its tone the state's */
83
+ .up-broken{--tone:var(--red)}
84
+ .up-better{--tone:var(--warn)}
85
+ .up-fixed{--tone:var(--ok)}
86
+ .rv-rowupdate{font-size:11.5px;line-height:1.35;margin-top:var(--s0);color:var(--ink);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
87
+ .rv-rowupdate b{color:var(--tone);text-transform:uppercase;font-size:10px;letter-spacing:.04em;margin-right:var(--s1)}
88
+ .rv-hint{display:flex;gap:var(--s1);margin-top:var(--s2)}
89
+ .rv-hint input{flex:1;min-width:0;font-size:13px}
82
90
  /* a narrow list: the title on its own line on top, a smaller image under it beside the badges */
83
91
  @container (max-width:250px){
84
- .rv-row{display:grid;grid-template-columns:40px minmax(0,1fr);grid-template-areas:"title title" "thumb meta" "rework rework";align-items:center;column-gap:var(--s2);row-gap:var(--s1)}
92
+ .rv-row{display:grid;grid-template-columns:40px minmax(0,1fr);grid-template-areas:"title title" "thumb meta" "update update" "rework rework";align-items:center;column-gap:var(--s2);row-gap:var(--s1)}
93
+ .rv-row .rv-rowupdate{grid-area:update;margin-top:0}
85
94
  .rv-row .rv-rowbody{display:contents}
86
95
  .rv-row .rv-rowtitle{grid-area:title}
87
96
  .rv-row .rv-thumb{grid-area:thumb;width:40px;height:40px}
@@ -218,6 +227,10 @@
218
227
  .rv-verdict{padding:var(--s1) var(--s3);font-size:13px;border-color:color-mix(in srgb,var(--tone) 60%,var(--line))}
219
228
  .rv-verdict .rv-vglyph{color:var(--tone);font-weight:800}
220
229
  .rv-verdict.chosen{background:color-mix(in srgb,var(--tone) 22%,var(--panel));border-color:var(--tone)}
230
+ /* the lit verdict or pick is a toggle: its ↺ says a click takes it back, and a hover shows it lifting */
231
+ .rv-undo{opacity:.7;font-weight:700}
232
+ .rv-verdict.chosen:hover:not(:disabled),.rv-pick.on:hover:not(:disabled){border-style:dashed;background:var(--panel)}
233
+ .rv-pick.on:hover:not(:disabled){color:var(--ok)}
221
234
  .rv-send{padding:var(--s1) var(--s4)}
222
235
 
223
236
  /* ── a version's views: each a sub cell, its number and title big, its kind, then what was said on it ── */
@@ -259,7 +272,7 @@ span.rv-react{display:inline-block;border:1px solid;border-radius:4px}
259
272
  .rv-over:has(.rv-note){z-index:5}
260
273
  .rv-frame{position:relative;width:100%;max-width:100%;border-radius:4px;border:1px solid var(--line);overflow:hidden;
261
274
  background:repeating-conic-gradient(var(--chk1) 0 25%,var(--chk2) 0 50%) 0 0/16px 16px}
262
- .rv-frame.swipe{cursor:ew-resize;touch-action:none}
275
+ .rv-frame.swipe{cursor:ew-resize;touch-action:pan-y pinch-zoom}
263
276
  .rv-fill{position:absolute;inset:0}
264
277
  .rv-caption{font-size:11px;color:var(--dim)}
265
278
  .rv-caption.mod,.rv-modcap{color:var(--k2)}
@@ -62,6 +62,7 @@ import type { projectGutter } from './project-gutter-route.ts'
62
62
  import { defaultHubPort } from './hub-port.ts'
63
63
  import { LAYOUT } from '../core/layout.ts'
64
64
  import { storeDir, storeStamp } from '../review/store.ts'
65
+ import { machinePublicHost } from '../home/machine-host.ts'
65
66
  export { defaultHubPort }
66
67
 
67
68
  export type ServeIo = { print: (l: string) => void; printErr: (l: string) => void }
@@ -414,7 +415,7 @@ export async function resolveHubDeps(root: string, boot: RepoConfig, io: ServeIo
414
415
  // a silent one reads as no blockers at all
415
416
  pingTick: (needs) =>
416
417
  pingTick(root, c.asks?.dir ?? LAYOUT.asks, needs, {
417
- link: o?.link ?? (() => (c.serve?.publicHost != null ? `http://${c.serve.publicHost}:${port}${o?.base ?? ''}/?f=needs` : undefined)),
418
+ link: o?.link ?? (() => { const h = machinePublicHost(c); return h != null ? `http://${h}:${port}${o?.base ?? ''}/?f=needs` : undefined }),
418
419
  run: (cmd) => {
419
420
  const p = Bun.spawn(cmd, { stdout: 'ignore', stderr: 'pipe' })
420
421
  void p.exited.then(async (code) => {
@@ -19,6 +19,7 @@ import { homeRepo } from './project-gutter.ts'
19
19
  import { serveHub } from './serve-hub.ts'
20
20
  import { StaleRestart } from './stale-restart.ts'
21
21
  import { Planner } from '../plan/planner.ts'
22
+ import { machinePublicHost } from '../home/machine-host.ts'
22
23
 
23
24
  export type { ServeIo }
24
25
 
@@ -107,8 +108,9 @@ export async function runServe(root: string, io: ServeIo, o?: { port?: number })
107
108
  // a page that cannot refresh itself looks identical to a broken one,
108
109
  // and the only tell is that every change needs a reload key
109
110
  if (!hub.liveReload) io.print(`WARN the page will not refresh itself: NODE_ENV=production strips bun hot reload, unset it and restart the hub`)
110
- // the off-machine door (phone, other machines) — publicHost is config
111
- if (c.serve?.publicHost != null) io.print(` phone: http://${c.serve.publicHost}:${hub.server.port}/`)
111
+ // the off-machine door (phone, other machines): this Mac's own name
112
+ const publicHost = machinePublicHost(c)
113
+ if (publicHost != null) io.print(` phone: http://${publicHost}:${hub.server.port}/`)
112
114
  // said once at boot, so a silent phone is never mistaken for no blockers
113
115
  if (c.notifyCommand != null && isLinkedWorktree(root)) io.print(` pings: off, this is a linked worktree (only the main checkout's hub notifies)`)
114
116
  // a lib that moved under this process (under bun --watch the version
@@ -4,7 +4,7 @@
4
4
  // is the routing alone, under a base path; serveHub puts it behind a
5
5
  // Bun.serve of its own. Resolving WHAT to mount from repo.config is
6
6
  // hub-runtime.ts's job.
7
- import { existsSync } from 'fs'
7
+ import { existsSync, realpathSync } from 'fs'
8
8
  import { join } from 'path'
9
9
  import { positionsFile } from 'rvlib-shipkit/src/wiki/graph-positions.ts'
10
10
  import { pageOf, searchWiki } from 'rvlib-shipkit/src/wiki/graph-pages.ts'
@@ -61,6 +61,9 @@ export type ComfyDeps = {
61
61
  box: () => ComfyBox
62
62
  stop: () => void
63
63
  }
64
+ /** a path as the disk resolves it, so `/tmp` and `/private/tmp` are one tree */
65
+ const sameTree = (p: string): string => { try { return realpathSync(p) } catch { return p } }
66
+
64
67
  export type HubDeps = {
65
68
  root: string
66
69
  name: string
@@ -234,8 +237,12 @@ export function hubHandler(d: HubDeps, o: { base?: string; projects?: Gutter } =
234
237
  // click opens the home on that repo, or VS Code while none runs
235
238
  if (path === '/api/home-url') return Response.json({ port: homePort(), up: await homeUp() })
236
239
  if (path === '/api/run' && req.method === 'POST' && d.runCli != null) {
237
- const b = (await req.json().catch(() => ({}))) as { kind?: string; opts?: Record<string, unknown> }
240
+ const b = (await req.json().catch(() => ({}))) as { kind?: string; opts?: Record<string, unknown>; root?: string }
238
241
  if (b.kind !== 'ci' && b.kind !== 'check') return new Response('kind must be ci or check', { status: 400 })
242
+ // a hub is found by its folder's NAME, and a clone elsewhere
243
+ // shares it: the gate runs only for the tree this hub serves
244
+ if (b.root == null || sameTree(b.root) !== sameTree(d.root))
245
+ return new Response(`the home's ${d.name} hub serves ${d.root}, not ${b.root ?? 'an unnamed tree'}`, { status: 421 })
239
246
  const runCli = d.runCli
240
247
  // a gate can stay silent for minutes (queued, or one long tsc):
241
248
  // Bun would cut the connection after its idle timeout
@@ -11,7 +11,7 @@ export const SHOT_PROCESS = 'shot'
11
11
 
12
12
  /** `root`: the repo the shot is for, whose browser cap it holds a slot of while it runs (browser-slot.ts); default the
13
13
  * repo the cwd is in */
14
- export type ShotInput = { url: string; out: string; viewport?: Viewport; dpr?: number; reload?: boolean; waitMs?: number; step?: string; at?: number; root?: string }
14
+ export type ShotInput = { url: string; out: string; viewport?: Viewport; dpr?: number; reload?: boolean; waitMs?: number; step?: string; at?: number; full?: boolean; root?: string }
15
15
  export type ClipInput = ShotInput & { seconds: number; fps?: number; dom?: boolean }
16
16
  export type ShotResult = ShotDone & { via: 'warm' | 'started' | 'local' | 'box' }
17
17
 
@@ -22,11 +22,13 @@ const shotAsk = (i: ShotInput): ShotAsk => ({
22
22
  dpr: i.dpr ?? 1,
23
23
  reload: i.reload ?? false,
24
24
  waitMs: i.waitMs ?? DEFAULT_WAIT_MS,
25
+ ...(i.full ? { full: true } : {}),
25
26
  })
26
27
 
27
28
  /** a service of an older shipkit takes a stepped ask, ignores the step and shoots the page as it loads: never kept */
28
- function stepped(i: { step?: string }, r: ShotResult): void {
29
+ function stepped(i: { step?: string; full?: boolean }, r: ShotResult): void {
29
30
  if (i.step && r.stepped !== true) throw new Error(`the shot service on ${shotUrlBase()} did not step the page (it says: ${r.note}); it runs an older shipkit: sk gp restart ${SHOT_PROCESS}`)
31
+ if (i.full && r.full !== true) throw new Error(`the shot service on ${shotUrlBase()} shot the viewport, not the whole page (it says: ${r.note}); it runs an older shipkit: sk gp restart ${SHOT_PROCESS}`)
30
32
  }
31
33
 
32
34
  /** a png of `url` at `out` (absolute), through the warm browser; with `step`, the page drawn at `at` first */
@@ -1,15 +1,17 @@
1
1
  // the warm shot service, the `shot` global process pm keeps up: an http
2
2
  // door on 127.0.0.1 over one Shooter. `sk shot` and `shotUrl` post an ask
3
3
  // and get back where the file landed. The browser launches on the first
4
- // ask and closes after BROWSER_IDLE_MS; this process itself stays, idle.
4
+ // ask and closes after BROWSER_IDLE_MS; this process itself stays, idle,
5
+ // and runs its own code again once that code moved (reloadWhenIdle).
5
6
  import { dirname } from 'path'
6
7
  import { LIB_VERSION } from '../core/lib-version.ts'
8
+ import type { LoadAnswer } from '../core/load-probe.ts'
7
9
  import { type ClipAsk, isClip, type ShotAsk, shotPort } from './shot-ask.ts'
8
10
  import { Shooter } from './shooter.ts'
9
11
 
10
12
  export const SHOT_SERVICE = 'shipkit-shot'
11
13
 
12
- export function serveShots(port = shotPort(), roots = [process.cwd(), dirname(import.meta.dir)]): { stop(): Promise<void> } {
14
+ export function serveShots(port = shotPort(), roots = [process.cwd(), dirname(import.meta.dir)]): { stop(): Promise<void>; idle(): boolean } {
13
15
  const shooter = new Shooter(roots)
14
16
  const server = Bun.serve({
15
17
  hostname: '127.0.0.1',
@@ -42,12 +44,79 @@ export function serveShots(port = shotPort(), roots = [process.cwd(), dirname(im
42
44
  await shooter.close()
43
45
  void server.stop(true)
44
46
  },
47
+ idle: () => shooter.warm.waiting === 0,
45
48
  }
46
49
  }
47
50
 
51
+ export interface ReloadDeps {
52
+ /** what moved in the service's own code, once settled, else null; `seq` counts every write */
53
+ moved(): string | null
54
+ seq(): number
55
+ idle(): boolean
56
+ loads(): Promise<LoadAnswer>
57
+ /** closes the browser and the server; then `again` runs this invocation on the new code */
58
+ before(): Promise<void>
59
+ again(): void
60
+ say(l: string): void
61
+ }
62
+
63
+ /** one look: the service runs its code again, same pid, once that code moved, no ask is in flight and the new code
64
+ * loads; a tree that fails to load is said once a change and the running code keeps serving */
65
+ export function reloadLook(d: ReloadDeps, held: { seq: number }): Promise<'reloaded' | 'held' | 'stay'> {
66
+ const why = d.moved()
67
+ if (why == null || !d.idle() || held.seq === d.seq()) return Promise.resolve('stay')
68
+ const seq = d.seq()
69
+ return d.loads().then(async (v) => {
70
+ if (!v.ok) {
71
+ held.seq = seq
72
+ d.say(`WARN ${why}, and ${v.file} fails to load (${v.error}): the shot service keeps its running code`)
73
+ return 'held'
74
+ }
75
+ if (!d.idle()) return 'stay'
76
+ d.say(`ok: ${why}: the shot service runs again on it`)
77
+ await d.before()
78
+ d.again()
79
+ return 'reloaded'
80
+ })
81
+ }
82
+
83
+ /** the service's own watch: the lib files its entry reaches, looked at every few seconds */
84
+ async function reloadWhenIdle(s: { stop(): Promise<void>; idle(): boolean }): Promise<void> {
85
+ const { LibWatch, roleGraph } = await import('../home/lib-watch.ts')
86
+ const { probeLoad } = await import('../core/load-probe.ts')
87
+ const { reexecBlocker, reexecSelf } = await import('../core/reexec.ts')
88
+ const lib = dirname(dirname(import.meta.dir))
89
+ const watch = new LibWatch(lib, { only: roleGraph(import.meta.path) })
90
+ if (watch.error != null) return console.error(`WARN no watch on the shipkit source (${watch.error}): an edit of the shots needs sk gp restart shot`)
91
+ const held = { seq: -1 }
92
+ const d: ReloadDeps = {
93
+ moved: () => watch.why(),
94
+ seq: () => watch.seq,
95
+ idle: () => s.idle(),
96
+ loads: () => probeLoad(lib, [import.meta.path]),
97
+ before: () => s.stop(),
98
+ again: () => {
99
+ const blocked = reexecBlocker()
100
+ if (blocked != null) {
101
+ console.error(`FAIL: the shot service stopped to run again and cannot: ${blocked}`)
102
+ process.exit(1)
103
+ }
104
+ reexecSelf()
105
+ },
106
+ say: (l) => (l.startsWith('WARN') ? console.error(l) : console.log(l)),
107
+ }
108
+ let busy = false
109
+ setInterval(() => {
110
+ if (busy) return
111
+ busy = true
112
+ void reloadLook(d, held).finally(() => (busy = false))
113
+ }, 5_000).unref()
114
+ }
115
+
48
116
  if (import.meta.main) {
49
117
  const s = serveShots()
50
118
  console.log(`ok shots on 127.0.0.1:${shotPort()}`)
119
+ void reloadWhenIdle(s)
51
120
  const bye = (): void => void s.stop().finally(() => process.exit(0))
52
121
  process.on('SIGTERM', bye)
53
122
  process.on('SIGINT', bye)
@@ -28,7 +28,7 @@ import { CLIP_INIT, CLIP_QUANTIZER, clipDone, installClip, KEY_EVERY, muxArgs, t
28
28
  import { type ClipPath, clipPathOf, domEncodeArgs, FrameTimeline, largestCanvas, screencastParams } from './dom-clip.ts'
29
29
  import { CLOSE_MS, openBrowser, type PwBrowser, slotFor } from './box.ts'
30
30
  import type { BrowserLease } from './browser-slot.ts'
31
- import { capMsOf, type ClipAsk, pageMove, readMark, type ShotAsk, slotKey, stillFormat, Turns, waitReady } from './shot-ask.ts'
31
+ import { capMsOf, type Clock, type ClipAsk, FULL_MAX_PX, MOVED, navigatedUnder, pageMove, readMark, type ShotAsk, slotKey, stillFormat, Turns, waitReady } from './shot-ask.ts'
32
32
 
33
33
  /** the slice of playwright the shots touch, so the lib types nothing it does not ship */
34
34
  type Cdp = {
@@ -36,11 +36,16 @@ type Cdp = {
36
36
  on(event: string, cb: (e: Record<string, unknown>) => void): unknown
37
37
  off(event: string, cb: (e: Record<string, unknown>) => void): unknown
38
38
  }
39
+ /** a response the page received, as playwright hands it */
40
+ type Answer = { status(): number; url(): string; request(): { method(): string } }
39
41
  type Page = {
40
42
  goto(url: string, o?: { waitUntil?: string; timeout?: number }): Promise<unknown>
41
43
  reload(o?: { waitUntil?: string; timeout?: number }): Promise<unknown>
44
+ url(): string
42
45
  evaluate<R, A>(fn: (a: A) => R | Promise<R>, arg?: A): Promise<R>
43
46
  waitForTimeout(ms: number): Promise<void>
47
+ waitForLoadState(state: 'load', o?: { timeout?: number }): Promise<void>
48
+ on(event: 'response', cb: (r: Answer) => void): void
44
49
  on(event: string, cb: (x: { message?: string; text?(): string; type?(): string; args?(): { jsonValue(): Promise<unknown> }[] }) => void): void
45
50
  close(): Promise<void>
46
51
  isClosed(): boolean
@@ -56,6 +61,16 @@ export async function consoleWords(m: { args?(): { jsonValue(): Promise<unknown>
56
61
  return null
57
62
  }
58
63
  }
64
+ /** the page line of a request the app refused: a shot of a page that is signed out reads as a page that worked.
65
+ * Cookies follow every shot; a page's local storage stays with its context (a viewport, a clip), as on the box */
66
+ export function deniedLine(status: number, method: string, url: string): string | null {
67
+ if (status !== 401 && status !== 403) return null
68
+ return `denied: ${status} on ${method} ${url}, so this shot is likely the page signed out. A sign in kept in local storage does not follow a new viewport, a clip or the idle close (cookies do): sign in at this viewport first`
69
+ }
70
+
71
+ /** chromium's console line for a response answered 401 or 403 */
72
+ export const DENIED_CONSOLE = /^Failed to load resource: the server responded with a status of 40[13]\b/
73
+
59
74
  /** a cookie as playwright reads and writes it */
60
75
  type Cookie = { name: string; value: string; domain: string; path: string } & Record<string, unknown>
61
76
  type Context = {
@@ -86,7 +101,7 @@ export const SHOT_NICE = 10
86
101
  /** a page that paints nothing once the screencast starts is filmed from one still taken after this */
87
102
  const FIRST_FRAME_MS = 1000
88
103
 
89
- export type ShotDone = { out: string; ms: number; phases: Record<string, number>; errors: string[]; note: string; stepped?: true }
104
+ export type ShotDone = { out: string; ms: number; phases: Record<string, number>; errors: string[]; note: string; stepped?: true; full?: true }
90
105
 
91
106
  type Slot = { key: string; url: string; ctx: Context; page: Page; cdp: Cdp; errors: string[]; frozen: boolean }
92
107
 
@@ -105,6 +120,33 @@ export async function resolvePlaywright(roots: string[]): Promise<Playwright> {
105
120
 
106
121
  const ms = (t0: number): number => Math.round(performance.now() - t0)
107
122
 
123
+ /** the page's ready mark; MOVED once a navigation that ran under the probe (a sign in that redirects, a dev server's
124
+ * reload) has loaded its new page */
125
+ const markOf =
126
+ (page: Page) =>
127
+ async (): Promise<string | null | typeof MOVED> => {
128
+ try {
129
+ return await page.evaluate(readMark)
130
+ } catch (e) {
131
+ if (!navigatedUnder(e)) throw e
132
+ await page.waitForLoadState('load', { timeout: 60_000 }).catch(() => undefined)
133
+ return MOVED
134
+ }
135
+ }
136
+ /** the clip of the whole page: the viewport's width, the content's height up to what chromium draws */
137
+ async function wholePage(cdp: Cdp, a: ShotAsk): Promise<{ clip: { x: number; y: number; width: number; height: number; scale: number }; note: string }> {
138
+ const m = await cdp.send('Page.getLayoutMetrics')
139
+ const content = (m['cssContentSize'] ?? m['contentSize']) as { height?: number } | undefined
140
+ const tall = Math.ceil(content?.height ?? a.viewport.height)
141
+ const max = Math.floor(FULL_MAX_PX / a.dpr)
142
+ const height = Math.max(a.viewport.height, Math.min(tall, max))
143
+ return { clip: { x: 0, y: 0, width: a.viewport.width, height, scale: 1 }, note: `whole page ${a.viewport.width}x${height}${tall > max ? ` (cut from ${tall}: chromium draws ${FULL_MAX_PX} px at most)` : ''}` }
144
+ }
145
+
146
+ /** a failure with the first errors the page printed meanwhile: a page that never says ready often says why */
147
+ export const withPageErrors = (msg: string, errors: readonly string[]): string => (errors.length === 0 ? msg : `${msg}; the page said: ${errors.slice(0, 3).join(' | ')}${errors.length > 3 ? ` (+${errors.length - 3} more)` : ''}`)
148
+ const clockOf = (page: Page): Clock => ({ now: () => performance.now(), sleep: (n) => page.waitForTimeout(n) })
149
+
108
150
  const withCap = <T>(what: string, capMs: number, p: Promise<T>): Promise<T> =>
109
151
  Promise.race([p, new Promise<T>((_, fail) => setTimeout(() => fail(new Error(`${what} took past ${capMs / 1000} s`)), capMs).unref?.())])
110
152
 
@@ -240,11 +282,18 @@ export class Shooter {
240
282
 
241
283
  static #listen(page: Page, errors: string[]): void {
242
284
  page.on('pageerror', (e) => errors.push(`pageerror: ${e.message ?? ''}`))
285
+ page.on('response', (r) => {
286
+ const line = deniedLine(r.status(), r.request().method(), r.url())
287
+ if (line != null && !errors.includes(line)) errors.push(line)
288
+ })
243
289
  page.on('console', (m) => {
244
290
  if (m.type?.() !== 'error') return
245
291
  // the text at once, so no error is lost; then its %s filled from the call's own arguments (React names
246
292
  // the duplicate key there), unless the list was cleared or the line moved meanwhile
247
- const line = `console: ${m.text?.() ?? ''}`
293
+ const text = m.text?.() ?? ''
294
+ // chromium's own line for a refused request: the denied line above names it with its url
295
+ if (DENIED_CONSOLE.test(text)) return
296
+ const line = `console: ${text}`
248
297
  const at = errors.push(line) - 1
249
298
  void consoleWords(m).then((w) => {
250
299
  if (w != null && errors[at] === line) errors[at] = `console: ${w}`
@@ -279,11 +328,13 @@ export class Shooter {
279
328
  slot.frozen = false
280
329
  }
281
330
  // a frozen page may have missed an edit: it loads again
282
- if (move === 'none' && thawed) move = 'reload'
331
+ const thawLoad = move === 'none' && thawed
332
+ if (thawLoad) move = 'reload'
283
333
  if (move !== 'none') {
284
334
  const t = performance.now()
285
335
  slot.url = a.url
286
- if (move === 'reload') await slot.page.reload({ waitUntil: 'load', timeout: 60_000 })
336
+ // a page that navigated away from its url (a sign in that redirects) reloads the url, not where it went
337
+ if (move === 'reload' && slot.page.url() === a.url) await slot.page.reload({ waitUntil: 'load', timeout: 60_000 })
287
338
  else {
288
339
  await this.#reach(a.url)
289
340
  await slot.page.goto(a.url, { waitUntil: 'load', timeout: 60_000 })
@@ -291,24 +342,27 @@ export class Shooter {
291
342
  phases['load'] = ms(t)
292
343
  }
293
344
  let t = performance.now()
294
- const how = await waitReady(() => slot.page.evaluate(readMark), move === 'none' ? 0 : a.waitMs, { now: () => performance.now(), sleep: (n) => slot.page.waitForTimeout(n) })
345
+ const how = await waitReady(markOf(slot.page), move === 'none' ? 0 : a.waitMs, clockOf(slot.page)).catch((e: Error) => {
346
+ throw new Error(withPageErrors(e.message, slot.errors))
347
+ })
295
348
  phases['ready'] = ms(t)
296
349
  if (a.step) {
297
350
  t = performance.now()
298
351
  const { stepTo } = await import('./stepped-clip.ts')
299
352
  if (!(await slot.page.evaluate(stepTo, [a.step, a.at ?? 0] as [string, number]))) throw new Error(`the page has no window.${a.step}(t): a stepped page draws the time it is given there`)
300
- await waitReady(() => slot.page.evaluate(readMark), 0, { now: () => performance.now(), sleep: (n) => slot.page.waitForTimeout(n) })
353
+ await waitReady(markOf(slot.page), 0, clockOf(slot.page))
301
354
  // the warm page now shows that moment: the next plain shot of this url loads it again
302
355
  slot.url = ''
303
356
  phases['step'] = ms(t)
304
357
  }
305
358
  t = performance.now()
306
- const r = await slot.cdp.send('Page.captureScreenshot', { ...stillFormat(a.out), optimizeForSpeed: true })
359
+ const whole = a.full ? await wholePage(slot.cdp, a) : null
360
+ const r = await slot.cdp.send('Page.captureScreenshot', { ...stillFormat(a.out), optimizeForSpeed: true, ...(whole ? { clip: whole.clip, captureBeyondViewport: true } : {}) })
307
361
  phases['capture'] = ms(t)
308
362
  mkdirSync(dirname(a.out), { recursive: true })
309
363
  await Bun.write(a.out, Buffer.from(String(r['data']), 'base64'))
310
- const note = `${move === 'none' ? 'warm page' : thawed ? 'frozen page reloaded' : move}, ${how === 'ready' ? 'ready mark' : move === 'none' ? 'no wait' : `${a.waitMs} ms after load`}${a.step ? `, drawn at ${a.at ?? 0}s through window.${a.step}(t)` : ''}`
311
- return { out: a.out, ms: ms(t0), phases, errors: [...slot.errors], note, ...(a.step ? { stepped: true as const } : {}) }
364
+ const note = `${move === 'none' ? 'warm page' : thawLoad ? 'frozen page reloaded' : move}, ${how === 'ready' ? 'ready mark' : move === 'none' ? 'no wait' : `${a.waitMs} ms after load`}${a.step ? `, drawn at ${a.at ?? 0}s through window.${a.step}(t)` : ''}${whole ? `, ${whole.note}` : ''}`
365
+ return { out: a.out, ms: ms(t0), phases, errors: [...slot.errors], note, ...(a.step ? { stepped: true as const } : {}), ...(whole ? { full: true as const } : {}) }
312
366
  }
313
367
 
314
368
  async #clip(a: ClipAsk): Promise<ShotDone> {
@@ -323,7 +377,7 @@ export class Shooter {
323
377
  let t = performance.now()
324
378
  await this.#reach(a.url)
325
379
  await page.goto(a.url, { waitUntil: 'load', timeout: 60_000 })
326
- await waitReady(() => page.evaluate(readMark), a.waitMs, { now: () => performance.now(), sleep: (n) => page.waitForTimeout(n) })
380
+ await waitReady(markOf(page), a.waitMs, clockOf(page))
327
381
  phases['load'] = ms(t)
328
382
  t = performance.now()
329
383
  const stepped = a.step ? { stepped: true as const } : {}