@marver-design/marver 0.26.0 → 0.26.1

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 (44) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +2 -2
  3. package/dist/{anchor-check-Dg5xpNnU.mjs → anchor-check-l-ny3UzH.mjs} +1 -1
  4. package/dist/{audio-CmSRYFEs.mjs → audio-Dw1lfMdb.mjs} +14 -0
  5. package/dist/{bake-DtVlm0_F.mjs → bake-C-awKgLA.mjs} +1 -1
  6. package/dist/{build-C_gUgcdC.mjs → build-BDRiO_mP.mjs} +3 -3
  7. package/dist/{capture-CrqvU_jh.mjs → capture-vadKjuCo.mjs} +2 -1
  8. package/dist/cli.mjs +6 -6
  9. package/dist/{daemon-DZo6o3rU.mjs → daemon-DL6Fwq6D.mjs} +394 -270
  10. package/dist/{dev-_Nlsc6v9.mjs → dev-Bw_qYWWq.mjs} +24 -11
  11. package/dist/{marks-NQi0wZJ4.mjs → marks-DyWMv_Z1.mjs} +1 -1
  12. package/dist/perf-C75MZ73h.mjs +167 -0
  13. package/dist/perf-jam-BU3TVrZu.mjs +239 -0
  14. package/dist/{plugin-CTD0rydA.mjs → plugin-DkGmZs_r.mjs} +42 -22
  15. package/dist/{poster-ChjXGTS5.mjs → poster-BdtSKMDm.mjs} +2 -1
  16. package/dist/{publish-bakes-CEP_2NRc.mjs → publish-bakes-9RzRToXV.mjs} +2 -2
  17. package/dist/{queue-BuiCKSX1.mjs → queue-29ok5_eZ.mjs} +2 -2
  18. package/dist/{session-qZWKt_VA.mjs → session-BAaJsK5c.mjs} +1 -1
  19. package/dist/{shot-DqcxJibP.mjs → shot-DQeR_Pfn.mjs} +337 -19
  20. package/dist/shot-XQV7HC9A.mjs +139 -0
  21. package/dist/speech-worker.mjs +40 -5
  22. package/docs/jam-session.md +24 -7
  23. package/docs/live-jam.md +8 -0
  24. package/package.json +1 -1
  25. package/src/client/frame-host/inspect.js +8 -3
  26. package/src/client/frame-host/keys.js +6 -2
  27. package/src/client/shell/App.tsx +8 -4
  28. package/src/client/shell/JamSurface.tsx +9 -3
  29. package/src/client/shell/Play.tsx +11 -7
  30. package/src/client/shell/Toolbar.tsx +5 -4
  31. package/src/client/shell/canvas/FrameNode.tsx +3 -2
  32. package/src/client/shell/icons.tsx +2 -0
  33. package/src/client/shell/jam-capture.ts +77 -11
  34. package/src/client/shell/jam-keys.ts +47 -18
  35. package/src/client/shell/jam-lane.tsx +46 -5
  36. package/src/client/shell/jam-panel.tsx +63 -13
  37. package/src/client/shell/jam-state.ts +48 -6
  38. package/src/client/shell/jam-surface-parts.tsx +10 -6
  39. package/src/client/shell/store.ts +14 -5
  40. package/src/client/shell/styles.css +28 -8
  41. package/src/client/stage/main.tsx +2 -0
  42. package/templates/instructions/jam.md +5 -3
  43. package/dist/perf-D6VmmJ2q.mjs +0 -68
  44. package/dist/shot-CNbHoZ6H.mjs +0 -86
@@ -90,6 +90,8 @@ interface Cap {
90
90
  pictures: string[]
91
91
  probes: number // probe answers still out
92
92
  shots: number // picture requests still out
93
+ /** its timing (spec 27a Part D): when E was pressed, the wait for its last words, each picture's time, the missing ones */
94
+ timing?: { endAt?: number; wordsMs?: number; pics: number[]; late: number; failed: number }
93
95
  shotFrames: string[] // frames pictured (or being pictured) in it: an automatic picture is taken once per frame
94
96
  endShot?: boolean // its end pictures were asked for (once its steps were all in)
95
97
  inherited?: string[] // Resume: the frames the capture it continues was about (its card's)
@@ -530,11 +532,14 @@ function shoot(id: string, frame: string, why: 'key' | 'pick' | 'end', key?: str
530
532
  const size = atEnd ? { width: atEnd.w, height: atEnd.h } : onStage ? { width: onStage.w, height: onStage.h } : seen?.play && why !== 'key' ? { width: seen.w, height: seen.h } : n ? { width: n.w, height: n.h } : undefined
531
533
  const theme = st.play && st.play.at === frame ? st.play.theme : n?.theme ?? st.viewTheme
532
534
  mutate((s) => { const x = s.caps[id]; if (x) x.shots += 1 })
535
+ const t0 = performance.now()
533
536
  const done = (pid: string | null, late: boolean) => {
534
537
  mutate((s) => {
535
538
  const x = s.caps[id]
536
539
  if (!x) return
537
540
  x.shots -= 1
541
+ const tm = (x.timing ??= { pics: [], late: 0, failed: 0 })
542
+ if (pid) tm.pics.push(Math.round(performance.now() - t0)); else if (late) tm.late++; else tm.failed++
538
543
  if (pid) { x.pictures.push(pid); x.steps.push({ at, frame, event: 'picture', id: pid, why }) }
539
544
  else x.steps.push({ at, frame, event: 'missing', what: `no picture of ${frame} - ${late ? `it took over ${PICTURE_MS / 1000} s` : 'the render failed'}` })
540
545
  })
@@ -664,6 +669,7 @@ function drain(id: string) {
664
669
  const x = st.caps[id]
665
670
  if (!x) return
666
671
  x.state = 'draining'
672
+ ;(x.timing ??= { pics: [], late: 0, failed: 0 }).endAt = performance.now()
667
673
  // its frames' sizes as they are at E - a resize while it finishes is not part of it; and every instance as it
668
674
  // is at E, for a step that answers late (a hover still in flight names a frame then)
669
675
  x.endSizes = framesSizes(x)
@@ -680,11 +686,13 @@ function drain(id: string) {
680
686
  broadcast({ type: 'sh:capture', id, on: false })
681
687
  // the audio is cut at the key press, then its last words are awaited (3 s at most)
682
688
  mutate((st) => { const x = st.caps[id]; if (x) x.hearing = true })
689
+ const tWords = performance.now()
683
690
  void voiceEnd(id).then((complete) => {
684
691
  mutate((st) => {
685
692
  const x = st.caps[id]
686
693
  if (!x) return
687
694
  x.hearing = false
695
+ ;(x.timing ??= { pics: [], late: 0, failed: 0 }).wordsMs = Math.round(performance.now() - tWords)
688
696
  if (!complete) x.steps.push({ at: now(), event: 'missing', what: 'words may be incomplete' })
689
697
  })
690
698
  trySeal(id)
@@ -751,6 +759,31 @@ function sealedSizes(c: Cap): Record<string, { w: number; h: number; play?: true
751
759
  return out
752
760
  }
753
761
 
762
+ /** Jam timings (spec 27a Part D): numbers only, to the dev server's local log - best effort, never in the way. */
763
+ const perf = (body: Record<string, unknown>, keepalive = false) => {
764
+ try { void fetch(`${ROUTE}/api/perf/jam`, { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify(body), ...(keepalive ? { keepalive: true } : {}) }).catch(() => {}) } catch { /* never in the way */ }
765
+ }
766
+ /** A capture's timing as it seals: E to sealed (none when the page sealed it), the wait for its words, its pictures. */
767
+ function timeCapture(c: Cap, interrupted: boolean) {
768
+ const t = c.timing
769
+ perf({ kind: 'capture', capture: c.id, ...(t?.endAt !== undefined && !interrupted ? { sealMs: performance.now() - t.endAt } : {}),
770
+ ...(t?.wordsMs !== undefined ? { wordsWaitMs: t.wordsMs } : {}),
771
+ pictures: { count: t?.pics.length ?? 0, ms: t?.pics ?? [], late: t?.late ?? 0, failed: t?.failed ?? 0 }, ...(interrupted ? { interrupted: true } : {}) }, interrupted)
772
+ }
773
+ const uploadTries = new Map<string, number>()
774
+
775
+ /** A capture's sealed record: its steps in time order, internal fields stripped, its context, view, pictures and
776
+ * sizes. `interrupted`: sealed by its page leaving, as it stood. */
777
+ function buildRecord(c: Cap, steps: Cap['steps'], interrupted = false): CaptureRecord {
778
+ const timeline = [...steps].sort((a, b) => a.at - b.at || (a.seq ?? 0) - (b.seq ?? 0)).map(({ seq: _s, src: _k, ...step }) => step as Step)
779
+ return {
780
+ format: 'marver.jam.capture', v: 1, id: c.id,
781
+ context: { canvas: location.host, board: c.board, ...(c.session ? { session: c.session } : {}), ...(c.reviewing ? { reviewing: c.reviewing } : {}), ...(c.resumes ? { resumes: c.resumes } : {}), ...(interrupted ? { interrupted: true as const } : {}) },
782
+ view: (timeline.find((x) => x.event === 'view') as Extract<Step, { event: 'view' }> | undefined)?.view ?? {},
783
+ timeline, pictures: c.pictures, ...(() => { const sizes = sealedSizes(c); return Object.keys(sizes).length ? { sizes } : {} })(),
784
+ }
785
+ }
786
+
754
787
  function trySeal(id: string) {
755
788
  const c = capOf(id)
756
789
  if (!c || c.state !== 'draining' || c.flushWait.size || c.probes > 0) return
@@ -759,13 +792,8 @@ function trySeal(id: string) {
759
792
  if (!c.endShot) endPictures(id)
760
793
  const c2 = capOf(id)
761
794
  if (!c2 || c2.shots > 0 || c2.hearing) return
762
- const timeline = [...c2.steps].sort((a, b) => a.at - b.at || (a.seq ?? 0) - (b.seq ?? 0)).map(({ seq: _s, src: _k, ...step }) => step as Step)
763
- const record: CaptureRecord = {
764
- format: 'marver.jam.capture', v: 1, id,
765
- context: { canvas: location.host, board: c.board, ...(c.session ? { session: c.session } : {}), ...(c.reviewing ? { reviewing: c.reviewing } : {}), ...(c.resumes ? { resumes: c.resumes } : {}) },
766
- view: (timeline.find((x) => x.event === 'view') as Extract<Step, { event: 'view' }> | undefined)?.view ?? {},
767
- timeline, pictures: c2.pictures, ...(() => { const sizes = sealedSizes(c2); return Object.keys(sizes).length ? { sizes } : {} })(),
768
- }
795
+ const record = buildRecord(c2, c2.steps)
796
+ timeCapture(c2, false)
769
797
  // sealed: drop everything for this id that arrives later
770
798
  useJamCapture.setState((st) => { const caps = { ...st.caps }; delete caps[id]; return { caps, tick: st.tick + 1, sealed: [...st.sealed, { id }] } })
771
799
  forgetHeard(id)
@@ -784,18 +812,23 @@ const pendingUploads = new Map<string, CaptureRecord>()
784
812
  let retryTimer: ReturnType<typeof setTimeout> | null = null
785
813
  /** Post a sealed record - the same id, idempotent on the server - until it takes. A refusal about the
786
814
  * record itself (not the network) is final and said once; a dev server that is away is waited for. */
787
- async function upload(record: CaptureRecord): Promise<void> {
815
+ async function upload(record: CaptureRecord, leaving = false): Promise<void> {
788
816
  type Verdict = { ok?: boolean; card?: { id: string; rev: number }; error?: string; outside?: boolean }
789
817
  let r: Verdict | null = null
790
818
  try {
791
819
  // the workspace it was made in travels with it: another project served on this port refuses it
792
- const res = await fetch(`${ROUTE}/api/jam/capture`, { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify({ record, workspace: CONFIG.workspace }) })
820
+ uploadTries.set(record.id, (uploadTries.get(record.id) ?? 0) + 1)
821
+ const tUp = performance.now()
822
+ const payload = JSON.stringify({ record, workspace: CONFIG.workspace })
823
+ // a page that is going sends with keepalive (64 kB at most) so the request outlives it; a bigger one, the next page
824
+ const res = await fetch(`${ROUTE}/api/jam/capture`, { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: payload, ...(leaving && payload.length < 60_000 ? { keepalive: true } : {}) })
793
825
  const body = (await res.json().catch(() => null)) as Verdict | null
794
826
  // only an explicit verdict on THIS record is final: taken (200, naming its card) or refused as a
795
827
  // record (400, saying why). Anything else - jam not running yet, another workspace, an unreadable
796
828
  // answer, a gate, a server error - is the server being away: keep it and try again
797
829
  r = res.ok && body?.ok === true && body.card?.id === record.id ? body
798
830
  : res.status === 400 && body && typeof body.error === 'string' ? body : null
831
+ if (r?.ok) { perf({ kind: 'upload', capture: record.id, ms: performance.now() - tUp, tries: uploadTries.get(record.id) ?? 1 }, leaving); uploadTries.delete(record.id) }
799
832
  } catch { r = null }
800
833
  if (!r) {
801
834
  if (!retryTimer) useStore.getState().toast('the capture is kept here and will be sent when marver dev answers')
@@ -813,8 +846,12 @@ async function upload(record: CaptureRecord): Promise<void> {
813
846
  else if (r.outside) leftOutOfSession(record.id)
814
847
  }
815
848
 
816
- /** A capture still recording, or finishing (its pictures and words coming in), lives only in this page
817
- * until it seals - a sealed one is kept in localStorage until it lands. Leaving the page asks first. */
849
+ /** A capture still recording, or finishing (its pictures and last words coming in), lives only in this page until it
850
+ * seals; a sealed one is kept in localStorage until it lands. Leaving the page asks first - and if you leave anyway
851
+ * (`pagehide`: a close, a reload, a navigation, the back-forward cache alike), every capture not sealed yet is sealed
852
+ * at once, as it stood, for good: a missing step says so, the server keeps it as a draft, and it goes out like any
853
+ * sealed record not sent yet - from the next page, or this one if it comes back. Carrying on is Resume, with a new id.
854
+ * Best effort: a crash or a killed process fires nothing. */
818
855
  let guarded = false
819
856
  function guardUnload() {
820
857
  if (guarded || typeof window === 'undefined') return
@@ -824,6 +861,35 @@ function guardUnload() {
824
861
  e.preventDefault()
825
862
  e.returnValue = ''
826
863
  })
864
+ window.addEventListener('pagehide', () => sealOnLeave())
865
+ // back from the back-forward cache: what was kept goes out now (never amended, never dropped)
866
+ window.addEventListener('pageshow', (e) => { if (e.persisted) for (const r of pendingUploads.values()) void upload(r) })
867
+ }
868
+
869
+ /** Seal every capture not sealed yet, as it stands, and tear it down as a drop does - synchronously: the page is going. */
870
+ export function sealOnLeave() {
871
+ const s = useJamCapture.getState()
872
+ const caps = Object.values(s.caps)
873
+ if (!caps.length) return
874
+ const draft = s.noteDraft.trim()
875
+ const records: CaptureRecord[] = []
876
+ for (const c of caps) {
877
+ const at = now()
878
+ const steps = [...c.steps]
879
+ // text written in the notes card and never added is the capture's last note, as at E
880
+ if (c.id === s.current && draft) steps.push({ at, event: 'note', text: draft })
881
+ steps.push({ at, event: 'missing', what: c.state === 'recording' ? 'the page closed while it recorded' : 'the page closed before it finished' })
882
+ records.push(buildRecord(c, steps, true))
883
+ timeCapture(c, true)
884
+ // its frames stop recording, its microphone is let go; a late picture or word finds nothing to change
885
+ broadcast({ type: 'sh:capture', id: c.id, on: false })
886
+ voiceDrop(c.id)
887
+ forgetHeard(c.id)
888
+ }
889
+ cancelDwell()
890
+ unwatch?.(); unwatch = null
891
+ useJamCapture.setState((st) => ({ current: null, caps: {}, noteOpen: false, noteDraft: '', tick: st.tick + 1, sealed: [...st.sealed, ...records.map((r) => ({ id: r.id }))] }))
892
+ for (const r of records) { keepSealed(r); void upload(r, true) }
827
893
  }
828
894
 
829
895
  /** Records sealed in an earlier page that never reached the server: sent again at boot. */
@@ -18,10 +18,10 @@
18
18
  */
19
19
  import { useJamCapture, setOwnedKeys } from './jam-capture.ts'
20
20
  import { changedShots, useJamQueue, type JamCard } from './jam-queue.ts'
21
- import { useJamUi } from './jam-state.ts'
21
+ import { DONE_CLOSE, DONE_GROUP, doneFold, useJamUi } from './jam-state.ts'
22
22
  import { pressJ, startSession, wrapWrite } from './jam-session.tsx'
23
23
  import { clearMoreDraft } from './jam-panel.tsx'
24
- import { CONFIG, PUBLISHED, useStore } from './store.ts'
24
+ import { CONFIG, PUBLISHED, SOURCE_REVEALED, useStore } from './store.ts'
25
25
 
26
26
  export interface KeyIn { key: string; shift?: boolean; alt?: boolean; meta?: boolean; ctrl?: boolean }
27
27
  /** `[Ctrl+][Meta+][Alt+][Shift+]key`, a letter lowercase - the frames' descriptor (keys.js). */
@@ -209,15 +209,32 @@ function reviewNow(): { card: string; batch: string; rev: number } | undefined {
209
209
  return ui.panel?.kind === 'review' && c?.kind === 'capture' && c.batch ? { card: c.id, batch: c.batch, rev: c.rev } : undefined
210
210
  }
211
211
 
212
+ /** Esc while a laser (pointer or inspect) is on turns it off, and that is all it does. */
213
+ const laserOff = (): boolean => { const st = useStore.getState(); if (!st.laser) return false; st.setLaser(false); return true }
214
+
212
215
  /** Start a capture, as S does: one made while a capture's review is open follows that review (its run).
213
216
  * `session`: the session it belongs to when the queue may not show it yet (a session's Start). */
214
217
  export const startCapture = (session?: string) => useJamCapture.getState().start(reviewNow(), session)
215
218
 
219
+ /** A laser on (pointer or inspect): its keys come first - Esc turns it off before it closes, drops or leaves anything -
220
+ * and are owned, so they work from inside a frame too (a laser click puts the focus there). The one row a published
221
+ * canvas has (where its source is revealed - the only place a laser exists there). */
222
+ const laserRow: Row = {
223
+ on: () => useStore.getState().laser,
224
+ keys: {
225
+ l: () => useStore.getState().toggleLaser(false),
226
+ 'Alt+l': () => useStore.getState().toggleLaser(true),
227
+ Escape: () => useStore.getState().setLaser(false),
228
+ },
229
+ }
230
+ const rowsNow = (): Row[] => (PUBLISHED ? (SOURCE_REVEALED ? [laserRow] : []) : rows())
231
+
216
232
  const rows = (): Row[] => {
217
233
  const cap = useJamCapture.getState()
218
234
  const ui = useJamUi.getState()
219
235
  const panelCard = cardById(ui.panel?.id)
220
236
  return [
237
+ laserRow,
221
238
  { // a session sheet open: the start sheet's ⏎ starts; Esc closes either (the wrap-up's field keeps its own keys)
222
239
  on: () => ui.sheet === 'start' || ui.sheet === 'wrap',
223
240
  keys: {
@@ -233,7 +250,8 @@ const rows = (): Row[] => {
233
250
  Enter: () => void decideDraft(panelCard!.id, 'confirm'),
234
251
  k: () => void decideDraft(panelCard!.id, 'keep'),
235
252
  r: () => void resumeDraft(panelCard!.id),
236
- Escape: () => void decideDraft(panelCard!.id, 'drop'),
253
+ // a laser on: Esc turns it off first - never a drop by the way
254
+ Escape: () => { if (laserOff()) return; void decideDraft(panelCard!.id, 'drop') },
237
255
  },
238
256
  },
239
257
  { // the notes card open (in its field, the field handles its own keys)
@@ -249,10 +267,13 @@ const rows = (): Row[] => {
249
267
  e: () => cap.end(),
250
268
  s: () => cap.start(), // one at a time: it says to end this one first
251
269
  // L: laser picks - a pick inside a capture is its pick (frames forward it while interacting)
252
- l: () => { const st = useStore.getState(); if (!st.laser) void import('./comments-store.ts').then(({ useComments }) => useComments.getState().setMode(false)); st.setLaser(!st.laser) },
270
+ // L: the pointer laser; ⌥L: inspect - a laser click inside a capture is its pick either way
271
+ l: () => { void import('./comments-store.ts').then(({ useComments }) => useComments.getState().setMode(false)); useStore.getState().toggleLaser(false) },
272
+ 'Alt+l': () => { void import('./comments-store.ts').then(({ useComments }) => useComments.getState().setMode(false)); useStore.getState().toggleLaser(true) },
253
273
  n: () => { cap.setNoteOpen(true); window.dispatchEvent(new CustomEvent('mv-jam-note-focus')) },
254
274
  i: () => cap.picture(),
255
- Escape: () => cap.drop(),
275
+ // a laser on: Esc turns it off first - the recording goes on
276
+ Escape: () => { if (laserOff()) return; cap.drop() },
256
277
  },
257
278
  },
258
279
  { // a review open
@@ -272,13 +293,19 @@ const rows = (): Row[] => {
272
293
  on: () => ui.laneKeys,
273
294
  keys: (() => {
274
295
  const list = lane()
296
+ // the stops as the lane shows them: done tiles folded into one group (two or more), or led by the collapse tile
297
+ const { stops, done } = doneFold(list, ui.doneOpen)
275
298
  // acting keys act only on the tile you can see selected - never on a fallback
276
- const i = list.findIndex((c) => c.id === ui.selected)
277
- const sel = i >= 0 ? list[i] : undefined
278
- const move = (d: number) => { const n = i < 0 ? list[list.length - 1] : list[Math.min(list.length - 1, Math.max(0, i + d))]; if (n) ui.select(n.id) }
299
+ const i = ui.selected ? stops.indexOf(ui.selected) : -1
300
+ const sel = i >= 0 ? list.find((c) => c.id === stops[i]) : undefined
301
+ const move = (d: number) => { const n = i < 0 ? stops[stops.length - 1] : stops[Math.min(stops.length - 1, Math.max(0, i + d))]; if (n) ui.select(n) }
279
302
  return {
280
303
  ArrowLeft: () => move(-1), ArrowRight: () => move(1),
281
- Enter: () => { if (sel) openTile(sel.id) },
304
+ Enter: () => {
305
+ if (stops[i] === DONE_GROUP) ui.setDoneOpen(true, done.map((c) => c.id))
306
+ else if (stops[i] === DONE_CLOSE) ui.setDoneOpen(false, done.map((c) => c.id))
307
+ else if (sel) openTile(sel.id)
308
+ },
282
309
  'Meta+Enter': () => { if (sel?.state === 'queued') void act(sel, 'first') },
283
310
  k: () => { if (sel?.state === 'draft') void decideDraft(sel.id, 'keep'); else if (sel?.state === 'queued') void act(sel, 'keep') },
284
311
  Backspace: () => { if (sel) void act(sel, 'drop') },
@@ -301,9 +328,8 @@ const rows = (): Row[] => {
301
328
 
302
329
  /** Apply Jam's key if a state takes it. True when it did - the caller stops there. */
303
330
  export function jamKey(k: KeyIn): boolean {
304
- if (PUBLISHED) return false
305
331
  const d = descriptor(k)
306
- for (const row of rows()) {
332
+ for (const row of rowsNow()) {
307
333
  if (!row.on()) continue
308
334
  const f = row.keys[d] ?? (d.length === 1 ? row.keys[d] : undefined)
309
335
  if (f) { f(); syncOwned(); return true }
@@ -313,17 +339,20 @@ export function jamKey(k: KeyIn): boolean {
313
339
 
314
340
  /** Mirror the keys owned right now into the frames. Called whenever a state may have changed. */
315
341
  export function syncOwned() {
316
- if (PUBLISHED) return
317
342
  const owned = new Set<string>()
318
- for (const row of rows()) if (row.on()) for (const k of Object.keys(row.keys)) owned.add(k)
343
+ for (const row of rowsNow()) if (row.on()) for (const k of Object.keys(row.keys)) owned.add(k)
319
344
  setOwnedKeys([...owned])
320
345
  }
321
346
 
322
347
  if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) void import('./canvas/ctl.ts').then(({ canvasCtl }) => { (window as any).__mvJamCanvas = canvasCtl })
323
348
 
324
- if (typeof window !== 'undefined' && !PUBLISHED) {
325
- // the states live in three stores: any change may change what is owned
326
- useJamCapture.subscribe(syncOwned)
327
- useJamUi.subscribe(syncOwned)
328
- useJamQueue.subscribe(syncOwned)
349
+ if (typeof window !== 'undefined') {
350
+ if (!PUBLISHED) {
351
+ // the states live in three stores: any change may change what is owned
352
+ useJamCapture.subscribe(syncOwned)
353
+ useJamUi.subscribe(syncOwned)
354
+ useJamQueue.subscribe(syncOwned)
355
+ }
356
+ // and the laser (its keys are owned while it is on - on a published canvas too)
357
+ useStore.subscribe((s, p) => { if (s.laser !== p.laser || s.laserInspect !== p.laserInspect) syncOwned() })
329
358
  }
@@ -12,7 +12,8 @@
12
12
  import { useEffect, useLayoutEffect, useRef, useState } from 'react'
13
13
  import { JamStateIcon, type JamGlyph } from './jam-ui.tsx'
14
14
  import { Tip } from './Tip.tsx'
15
- import { CursorClickIcon, FileCodeIcon, ImagesSquareIcon, LaserIcon, MicrophoneIcon, MicrophoneSlashIcon, PencilSimpleIcon } from './icons.tsx'
15
+ import { DONE_CLOSE, DONE_GROUP, doneFold, doneLine } from './jam-state.ts'
16
+ import { ArrowsInLineHorizontalIcon, CursorClickIcon, FileCodeIcon, ImagesSquareIcon, LaserIcon, MicrophoneIcon, MicrophoneSlashIcon, PencilSimpleIcon } from './icons.tsx'
16
17
 
17
18
  /** The lane's height with its air: the 44 px tile + 12 px. While the lane shows, the sidebar stops
18
19
  * above it and everything else on the bottom edge (the Update pill, toasts, notices) rises this much. */
@@ -27,6 +28,10 @@ export interface LaneTile {
27
28
  line: string
28
29
  /** an exclusive card wears a file glyph: it changes how the queue runs */
29
30
  exclusive?: boolean
31
+ /** a done tile: the frames it changed (not the ones it left as they were) - the Done group counts each frame once */
32
+ frames?: string[]
33
+ /** a session record's tile (the Done group counts records apart from captures) */
34
+ record?: boolean
30
35
  }
31
36
 
32
37
  export interface LaneRecording {
@@ -87,8 +92,11 @@ export interface LaneBetween {
87
92
  onCapture(): void
88
93
  }
89
94
 
90
- export function Lane({ tiles, recording, between, selected, keyboard, onOpen, onMenu, followEnd }: {
95
+ export function Lane({ tiles, recording, between, selected, keyboard, onOpen, onMenu, followEnd, doneOpen = false, onDoneOpen }: {
91
96
  tiles: LaneTile[]
97
+ /** two or more done tiles fold into one Done tile (0.26.1): shown open, or folded */
98
+ doneOpen?: boolean
99
+ onDoneOpen?(open: boolean, doneIds: string[]): void
92
100
  recording?: LaneRecording
93
101
  /** no capture recording in a session: its own tile, last */
94
102
  between?: LaneBetween
@@ -101,6 +109,19 @@ export function Lane({ tiles, recording, between, selected, keyboard, onOpen, on
101
109
  }) {
102
110
  const ref = useRef<HTMLDivElement>(null)
103
111
  const [fade, setFade] = useState<'' | 'l' | 'r' | 'lr'>('')
112
+ // done tiles: folded into one (two or more), or shown first behind the collapse tile
113
+ const { fold, done, rest } = doneFold(tiles, doneOpen)
114
+ const shown = fold ? (doneOpen ? [...done, ...rest] : rest) : tiles
115
+ const doneFrames = new Set(done.flatMap((t) => t.frames ?? [])).size
116
+ // opening shows the done tiles where they are (the lane's start); folding goes back to the newest end
117
+ const firstOpen = useRef(true)
118
+ useLayoutEffect(() => {
119
+ if (firstOpen.current) { firstOpen.current = false; return }
120
+ const el = ref.current
121
+ // (folding with the group selected: the selection's own scroll shows the group)
122
+ if (el && (doneOpen || selected !== DONE_GROUP)) el.scrollLeft = doneOpen ? 0 : el.scrollWidth
123
+ measure()
124
+ }, [doneOpen])
104
125
  const measure = () => {
105
126
  const el = ref.current
106
127
  if (!el) return
@@ -138,12 +159,32 @@ export function Lane({ tiles, recording, between, selected, keyboard, onOpen, on
138
159
  }, [selected])
139
160
  return (
140
161
  <div className={`jm-lane${keyboard ? ' keyboard' : ''}`} data-jam-lane="">
141
- <div ref={ref} className={`jm-lane-in${fade ? ' ' + fade.split('').map((c) => `fade-${c}`).join(' ') : ''}`}
162
+ {fade.includes('l') && <span className="jm-lane-edge l" aria-hidden="true" />}
163
+ {fade.includes('r') && <span className="jm-lane-edge r" aria-hidden="true" />}
164
+ <div ref={ref} className="jm-lane-in"
142
165
  onScroll={measure}
143
166
  onWheel={(e) => { const el = ref.current; if (el && Math.abs(e.deltaY) > Math.abs(e.deltaX)) el.scrollLeft += e.deltaY }}>
144
- {tiles.map((t) => (
167
+ {fold && !doneOpen && (
168
+ <button key={DONE_GROUP} data-tile={DONE_GROUP} data-state="done" data-jam-done="folded"
169
+ className={`jm-card done group${selected === DONE_GROUP ? ' focus' : ''}`}
170
+ onClick={() => onDoneOpen?.(true, done.map((t) => t.id))}>
171
+ <JamStateIcon state="done" />
172
+ <span className="tx">
173
+ <span className="t">Done</span>
174
+ <span className="m">{doneLine(done, doneFrames)}</span>
175
+ </span>
176
+ </button>
177
+ )}
178
+ {fold && doneOpen && (
179
+ <button key={DONE_CLOSE} data-tile={DONE_CLOSE} data-jam-done="open" aria-label="Fold the done captures"
180
+ className={`jm-card close${selected === DONE_CLOSE ? ' focus' : ''}`}
181
+ onClick={() => onDoneOpen?.(false, done.map((t) => t.id))}>
182
+ <ArrowsInLineHorizontalIcon size={15} /><span className="t">Done</span>
183
+ </button>
184
+ )}
185
+ {shown.map((t) => (
145
186
  <button key={t.id} data-tile={t.id} data-state={t.state}
146
- className={`jm-card ${t.state}${selected === t.id ? ' focus' : ''}`}
187
+ className={`jm-card ${t.state}${selected === t.id ? ' focus' : ''}${fold && t.state === 'done' ? ' unfold' : ''}`}
147
188
  onClick={() => onOpen(t.id)} onContextMenu={onMenu ? (e) => onMenu(e, t.id) : undefined}>
148
189
  <JamStateIcon state={t.state} />
149
190
  <span className="tx">
@@ -6,7 +6,7 @@
6
6
  * Presentational only: every component takes what it shows and calls back what was chosen. The shell
7
7
  * (jam-capture.ts, App) owns state, keys and the API.
8
8
  */
9
- import { useEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react'
9
+ import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react'
10
10
  import { JamStateIcon } from './jam-ui.tsx'
11
11
  import type { TimelineLine } from './jam-lines.ts'
12
12
  import { speechLines } from '../../shared/speech.ts'
@@ -35,6 +35,9 @@ export const Marver = ({ size = 20 }: { size?: number }) => (
35
35
  * shell passes it), `width` px wide (520 at least). The panel inside fills it; its middle scrolls and
36
36
  * its footer stays in view. `onClose` adds a quiet close button in its corner. */
37
37
  export function FocusPanel({ children, left, width = 580, onClose }: { children: ReactNode; left: number; width?: number; onClose?: () => void }) {
38
+ // the window's width is the last word: follow it as it changes
39
+ const [, setTick] = useState(0)
40
+ useEffect(() => { const on = () => setTick((n) => n + 1); window.addEventListener('resize', on); return () => window.removeEventListener('resize', on) }, [])
38
41
  // 580: the footer's "For Claude Code" and its four actions on one line; never wider than the window allows
39
42
  // the window is the last word: a narrow one gets a narrower panel, never one past its edge
40
43
  const room = (typeof window !== 'undefined' ? window.innerWidth : 1400) - left - 12
@@ -138,12 +141,19 @@ function AddedNotes({ added, onAdd }: { added: { at: number; text: string }[]; o
138
141
  }
139
142
 
140
143
  /** A picture, or the dashed "No picture" where a shot failed. */
141
- export const Shot = ({ url, cap, alt }: { url?: string; cap?: ReactNode; alt?: string }) => (
142
- <div className="jm-shot">
143
- {url ? <div className="pic"><img src={url} alt={alt ?? ''} draggable={false} /></div> : <div className="pic none"><ImagesSquareIcon size={13} />No picture</div>}
144
- {cap && <span className="cap">{cap}</span>}
145
- </div>
146
- )
144
+ export function Shot({ url, cap, alt, onSize }: { url?: string; cap?: ReactNode; alt?: string; onSize?: (w: number, h: number) => void }) {
145
+ // a picture that cannot load (gone, refused) is "No picture" too - never a broken image
146
+ const [failed, setFailed] = useState<string | null>(null)
147
+ const ok = !!url && failed !== url
148
+ return (
149
+ <div className="jm-shot">
150
+ {ok ? <div className="pic"><img src={url} alt={alt ?? ''} draggable={false} onError={() => setFailed(url!)}
151
+ onLoad={onSize ? (e) => onSize(e.currentTarget.naturalWidth, e.currentTarget.naturalHeight) : undefined} /></div>
152
+ : <div className="pic none"><ImagesSquareIcon size={13} />No picture</div>}
153
+ {cap && <span className="cap">{cap}</span>}
154
+ </div>
155
+ )
156
+ }
147
157
 
148
158
  /** "1 of 3" with its arrows - the walk's ends disable the arrow that has nowhere to go. */
149
159
  const Walk = ({ of, onPrev, onNext }: { of?: [number, number]; onPrev?: () => void; onNext?: () => void }) => of ? (
@@ -287,7 +297,7 @@ export function ReadBack({ title, head, of, onPrev, onNext, meta, lines, picture
287
297
  * `shots` are picture URLs per frame (`frames` names the tabs; it defaults to the shots' frames);
288
298
  * `alsoChanged` = shared files the job changed anyway.
289
299
  */
290
- export function ReviewDetail({ title, head, of, onPrev, onNext, frames, active, onTab, view, onFlip, reply, shots, alsoChanged, agent, when, more, onMore, onMoreOpen, onGood, onLater, onOpenThread, style, draftKey }: {
300
+ export function ReviewDetail({ title, head, of, onPrev, onNext, frames, active, onTab, view, onFlip, onFit, reply, shots, alsoChanged, agent, when, more, onMore, onMoreOpen, onGood, onLater, onOpenThread, style, draftKey }: {
291
301
  title: string
292
302
  /** beside the title: the Review | Capture switch */
293
303
  head?: ReactNode
@@ -297,8 +307,10 @@ export function ReviewDetail({ title, head, of, onPrev, onNext, frames, active,
297
307
  frames?: string[]
298
308
  active: number
299
309
  onTab(i: number): void
300
- view: 'before' | 'after'
301
- onFlip(view: 'before' | 'after'): void
310
+ view: 'both' | 'before' | 'after'
311
+ onFlip(view: 'both' | 'before' | 'after'): void
312
+ /** the panel width the pictures need (0.26.1): both at once, as big as the panel's height allows; undefined: the default */
313
+ onFit?(width: number | undefined): void
302
314
  reply: ReactNode
303
315
  /** `new`: a frame the run made - nothing before it */
304
316
  shots: { frame: string; before?: string; after?: string; new?: boolean }[]
@@ -318,6 +330,39 @@ export function ReviewDetail({ title, head, of, onPrev, onNext, frames, active,
318
330
  const names = frames ?? shots.map((s) => s.frame)
319
331
  const shot = shots[active] ?? shots.find((s) => s.frame === names[active])
320
332
  const isNew = (f: string) => !!shots.find((s) => s.frame === f)?.new
333
+ // the frame's shape, from its pictures as they load (After's, else Before's): taller than wide (or square) side by
334
+ // side, wider than tall stacked - and the panel as wide as that needs (0.26.1, the owner's first real session)
335
+ const [sizes, setSizes] = useState<Record<string, number>>({})
336
+ const sized = (url?: string) => (url ? (w: number, h: number) => { if (w > 0 && h > 0) setSizes((m) => (m[url] === w / h ? m : { ...m, [url]: w / h })) } : undefined)
337
+ const aspect = (shot?.after && sizes[shot.after]) || (shot?.before && sizes[shot.before]) || undefined
338
+ // both slots whenever the frame has a before at all (either may read "No picture") - a missing After never hides a Before
339
+ const both = view === 'both' && !!shot && !shot.new && !!(shot.before || shot.after)
340
+ const side = (aspect ?? 1.6) <= 1.1
341
+ const big = useRef<HTMLDivElement>(null)
342
+ useLayoutEffect(() => {
343
+ const el = big.current
344
+ if (!el || !onFit) return
345
+ // no picture of this one measured yet (loading, or none loads): the default width - never the last tab's
346
+ if (!aspect) { onFit(undefined); return }
347
+ const ask = () => {
348
+ const panel = el.closest('.jm-panel') as HTMLElement | null
349
+ if (!panel) return
350
+ // the chrome around the pictures: the panel's width minus the well's; the well's height is what they get
351
+ const chrome = panel.getBoundingClientRect().width - el.getBoundingClientRect().width
352
+ const h = el.getBoundingClientRect().height - 20 // the well's padding
353
+ const CAP = 18, GAP = 10
354
+ let well: number
355
+ if (both && side) well = 2 * (h - CAP) * aspect + GAP // side by side: each the whole height
356
+ else if (both) well = ((h - GAP - 2 * CAP) / 2) * aspect // stacked: each half of it
357
+ else well = h * aspect // one picture
358
+ const want = Math.round(chrome + well + 20)
359
+ onFit(Math.round(want / 8) * 8)
360
+ }
361
+ ask()
362
+ const ro = new ResizeObserver(ask)
363
+ ro.observe(el)
364
+ return () => ro.disconnect()
365
+ }, [aspect, both, side, onFit])
321
366
  const label = (f: string) => f.split('/').pop() ?? f
322
367
  // the More work words outlive the panel: a click elsewhere closes it, and the words wait for its return -
323
368
  // they go only when sent, or when you leave the composer yourself (Esc)
@@ -353,13 +398,18 @@ export function ReviewDetail({ title, head, of, onPrev, onNext, frames, active,
353
398
  <span className="sp" />
354
399
  {/* a frame the run made has nothing before it: no switch */}
355
400
  {shot?.new ? <span className="dim" data-jam-new="">New frame</span> : (
356
- <Tip side="bottom" label={<span>Before / After<kbd style={{ marginLeft: 8 }}>B</kbd></span>}>
357
- <div className="jm-ftabs" data-jam-flip="">{(['before', 'after'] as const).map((v) => <button key={v} className={v === view ? 'on' : undefined} aria-pressed={v === view} onClick={() => onFlip(v)}>{v === 'before' ? 'Before' : 'After'}</button>)}</div>
401
+ <Tip side="bottom" label={<span>Both / Before / After<kbd style={{ marginLeft: 8 }}>B</kbd></span>}>
402
+ <div className="jm-ftabs" data-jam-flip="">{(['both', 'before', 'after'] as const).map((v) => <button key={v} className={v === view ? 'on' : undefined} aria-pressed={v === view} onClick={() => onFlip(v)}>{v === 'both' ? 'Both' : v === 'before' ? 'Before' : 'After'}</button>)}</div>
358
403
  </Tip>
359
404
  )}
360
405
  </div>
361
406
  )}
362
- <div className="jm-big"><Shot url={view === 'before' && !shot?.new ? shot?.before : shot?.after} alt={`${label(names[active] ?? '')} ${shot?.new ? 'new' : view}`} /></div>
407
+ <div ref={big} className={`jm-big${both ? ` pair ${side ? 'side' : 'stack'}` : ''}`} data-jam-pair={both ? (side ? 'side' : 'stack') : 'one'}>
408
+ {both
409
+ ? <><Shot key={`b-${shot!.before ?? 'none'}`} url={shot!.before} cap="Before" alt={`${label(names[active] ?? '')} before`} onSize={sized(shot!.before)} /><Shot key={`a-${shot!.after ?? 'none'}`} url={shot!.after} cap="After" alt={`${label(names[active] ?? '')} after`} onSize={sized(shot!.after)} /></>
410
+ : <Shot url={view === 'before' && !shot?.new ? shot?.before : shot?.after} alt={`${label(names[active] ?? '')} ${shot?.new ? 'new' : view}`}
411
+ onSize={sized(view === 'before' && !shot?.new ? shot?.before : shot?.after)} />}
412
+ </div>
363
413
  {alsoChanged && alsoChanged.length > 0 && (
364
414
  <div className="jm-file"><FileCodeIcon size={14} /><span>Also changed {alsoChanged.map((f, i) => <span key={f}>{i > 0 && ', '}<code>{f.split('/').pop()}</code></span>)}</span></div>
365
415
  )}
@@ -12,12 +12,16 @@ interface JamUi {
12
12
  selected: string | null
13
13
  /** the lane has the keyboard (Q) */
14
14
  laneKeys: boolean
15
- /** the review: Before | After, the frame tab, the More work composer */
16
- view: 'after' | 'before'
15
+ /** the review: Both (before and after at once - 0.26.1) | Before | After, the frame tab, the More work composer */
16
+ view: 'both' | 'before' | 'after'
17
17
  tab: number
18
18
  moreOpen: boolean
19
19
  /** bumps when the lane should come back to its right end (a new capture or draft) */
20
20
  followEnd: number
21
+ /** the lane's done tiles shown (the Done group opened) - folded into one tile by default (0.26.1) */
22
+ doneOpen: boolean
23
+ /** folding hands a selected done tile's selection to the group (`doneIds`: the tiles it folds) */
24
+ setDoneOpen(open: boolean, doneIds?: string[]): void
21
25
  /** the session's sheets (Part 5): the start sheet (J at rest), the wrap-up (J in a session) - or
22
26
  * 'wrap-pending': J pressed while a capture recorded, the wrap-up waits for its read-back to close */
23
27
  sheet: 'start' | 'wrap' | 'wrap-pending' | null
@@ -27,21 +31,35 @@ interface JamUi {
27
31
  setLaneKeys(on: boolean): void
28
32
  select(id: string | null): void
29
33
  flip(): void
34
+ /** a choice in the review's switch: Both, Before or After */
35
+ setView(view: JamUi['view']): void
30
36
  setTab(i: number): void
31
37
  setMoreOpen(on: boolean): void
32
38
  follow(): void
33
39
  }
34
40
 
35
41
  export const useJamUi = create<JamUi>((set, get) => ({
36
- panel: null, selected: null, laneKeys: false, view: 'after', tab: 0, moreOpen: false, followEnd: 0, sheet: null,
42
+ panel: null, selected: null, laneKeys: false, view: 'both', tab: 0, moreOpen: false, followEnd: 0, sheet: null, doneOpen: false,
37
43
  setSheet(s) { set({ sheet: s }) },
38
- // the next card opens on After, its first frame
39
- open(panel) { set({ panel, selected: panel?.id ?? get().selected, view: 'after', tab: 0, moreOpen: false }) },
44
+ // the next card opens on Both, its first frame
45
+ open(panel) { set({ panel, selected: panel?.id ?? get().selected, view: 'both', tab: 0, moreOpen: false }) },
40
46
  close() { set({ panel: null, moreOpen: false }) },
41
47
  setLaneKeys(on) { set({ laneKeys: on }) },
48
+ // folding: a done tile that was selected hands its selection to the group
49
+ // the selection follows the fold: folding, a selected done tile or the collapse tile hands it to the group; opening,
50
+ // a selected group hands it to the first done tile
51
+ setDoneOpen(open, doneIds = []) {
52
+ set((s) => ({
53
+ doneOpen: open,
54
+ ...(!open && s.selected && (s.selected === DONE_CLOSE || doneIds.includes(s.selected)) ? { selected: DONE_GROUP } : {}),
55
+ ...(open && s.selected === DONE_GROUP ? { selected: doneIds[0] ?? DONE_CLOSE } : {}),
56
+ }))
57
+ },
42
58
  select(id) { set({ selected: id }) },
43
- flip() { set((s) => ({ view: s.view === 'after' ? 'before' : 'after' })) },
59
+ // B: Both -> Before -> After -> Both
60
+ flip() { set((s) => ({ view: s.view === 'both' ? 'before' : s.view === 'before' ? 'after' : 'both' })) },
44
61
  setTab(i) { set({ tab: i }) },
62
+ setView(view) { set({ view }) },
45
63
  setMoreOpen(on) { set({ moreOpen: on }) },
46
64
  follow() { set((s) => ({ followEnd: s.followEnd + 1 })) },
47
65
  }))
@@ -59,3 +77,27 @@ export function letGoOfTile() {
59
77
  }
60
78
 
61
79
  if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) (window as any).__mvJamUi = useJamUi
80
+
81
+ // ---- the Done fold (0.26.1): two or more done tiles fold into one, at the lane's left end ------------------
82
+
83
+ /** The folded group's stop, and the collapse tile's when it is open. */
84
+ export const DONE_GROUP = 'jam-done-group'
85
+ export const DONE_CLOSE = 'jam-done-close'
86
+
87
+ /** How the lane shows `items` (oldest first): two or more done ones fold into one group; open, they lead, behind a
88
+ * collapse tile. `stops`: the lane's keyboard stops in that order. */
89
+ export function doneFold<T extends { id: string; state: string }>(items: T[], open: boolean): { fold: boolean; done: T[]; rest: T[]; stops: string[] } {
90
+ const done = items.filter((t) => t.state === 'done')
91
+ const rest = items.filter((t) => t.state !== 'done')
92
+ const fold = done.length >= 2
93
+ const stops = !fold ? items.map((t) => t.id) : open ? [DONE_CLOSE, ...done.map((t) => t.id), ...rest.map((t) => t.id)] : [DONE_GROUP, ...rest.map((t) => t.id)]
94
+ return { fold, done, rest, stops }
95
+ }
96
+
97
+ /** What the Done group holds: "3 captures", "2 captures · 1 record", and "· 4 frames changed" when known. */
98
+ export function doneLine(done: { record?: boolean }[], frames: number): string {
99
+ const records = done.filter((t) => t.record).length, captures = done.length - records
100
+ const parts = [captures ? `${captures} capture${captures === 1 ? '' : 's'}` : '', records ? `${records} record${records === 1 ? '' : 's'}` : '', frames ? `${frames} frame${frames === 1 ? '' : 's'} changed` : ''].filter(Boolean)
101
+ return parts.join(' · ')
102
+ }
103
+