@marver-design/marver 0.27.2 → 0.29.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 (91) hide show
  1. package/CHANGELOG.md +160 -0
  2. package/README.md +6 -4
  3. package/dist/{anchor-check-gkxkPAIv.mjs → anchor-check-DhlpKl2K.mjs} +1 -1
  4. package/dist/{audio-Dw1lfMdb.mjs → audio-DX4POHAj.mjs} +39 -4
  5. package/dist/{boards-BqUqKNW8.mjs → boards-BeWtjGUM.mjs} +49 -4
  6. package/dist/boards-EH2onUXM.mjs +995 -0
  7. package/dist/{build-VgNg4rr8.mjs → build-CWbrb2bl.mjs} +9 -5
  8. package/dist/{capture-vadKjuCo.mjs → capture-DEtM4qm5.mjs} +259 -34
  9. package/dist/cli.mjs +40 -19
  10. package/dist/{comments-YEU1Zhv9.mjs → comments-XNhMmSSu.mjs} +4 -4
  11. package/dist/config-BezZTiov.mjs +182 -0
  12. package/dist/conn-BMiHS42T.mjs +222 -0
  13. package/dist/connectors-DekQvKt9.mjs +292 -0
  14. package/dist/{context-Ccjrhr1J.mjs → context-BUnFiyA3.mjs} +2 -2
  15. package/dist/{daemon-Dc9AH0M3.mjs → daemon-Sc_z8gT6.mjs} +2209 -205
  16. package/dist/{dev-ri6nAlRp.mjs → dev-DWBKQhxf.mjs} +31 -15
  17. package/dist/{init-W0nxR1OY.mjs → init-CYlFaRzG.mjs} +7 -2
  18. package/dist/jam-Cj5gBvwD.mjs +373 -0
  19. package/dist/{link-CdTgn94Y.mjs → link-BFFRgrMt.mjs} +3 -3
  20. package/dist/listener-DdLEM79A.mjs +80 -0
  21. package/dist/logo-CXY-1yrn.mjs +305 -0
  22. package/dist/{ls-BZ5TAtd5.mjs → ls-NqmePKOf.mjs} +1 -1
  23. package/dist/{manifest-aFyDmL8C.mjs → manifest-DPZ3WNg_.mjs} +1 -1
  24. package/dist/{marks-CnCCfAbD.mjs → marks-BnNANic9.mjs} +22 -3
  25. package/dist/{marks-BF9pNEgH.mjs → marks-DBp3h1Mc.mjs} +3 -6
  26. package/dist/{marver-id-gate-D-R0hSt_.mjs → marver-id-gate-vBLb_Icb.mjs} +1 -1
  27. package/dist/{perf-DkAUFT6W.mjs → perf-Denssrko.mjs} +45 -27
  28. package/dist/{perf-jam-BaH3Lg0m.mjs → perf-jam-CLkERSHo.mjs} +9 -2
  29. package/dist/permit-DDa6wqOs.mjs +187 -0
  30. package/dist/{plugin-B8UghYuF.mjs → plugin-DqoZB-D6.mjs} +849 -789
  31. package/dist/{poster-BNgafWMK.mjs → poster-CrsjqhY4.mjs} +1 -1
  32. package/dist/{profile-jIS6BcAs.mjs → profile-B1FKOM1e.mjs} +1 -1
  33. package/dist/{publish-bakes-38Nja78p.mjs → publish-bakes-DW-NDgU2.mjs} +3 -3
  34. package/dist/{queue-CAM_vNmX.mjs → queue-DeSQm24g.mjs} +189 -35
  35. package/dist/{recover-B8AiI29B.mjs → recover-GtJ9UDAB.mjs} +2 -2
  36. package/dist/{serve-Dp3nHstu.mjs → serve-DQv3Ti6X.mjs} +8 -4
  37. package/dist/{session-BAaJsK5c.mjs → session-VDJfXEEm.mjs} +1 -1
  38. package/dist/{share-Ce4tP7ji.mjs → share-Bu_kuOKL.mjs} +1 -1
  39. package/dist/{shot-CMQgMVZm.mjs → shot-DBWN8hPP.mjs} +1 -1
  40. package/dist/{shot-Ch24tiMO.mjs → shot-T04Ixrvq.mjs} +7 -6
  41. package/dist/sizes-wjXDev3b.mjs +139 -0
  42. package/dist/{slots-CFNnegCc.mjs → slots-Dn4Onb0V.mjs} +101 -3
  43. package/dist/speech-worker.mjs +23 -3
  44. package/dist/{sync-CQdGARJ9.mjs → sync-CMozOwZ0.mjs} +1 -1
  45. package/dist/transport-C5FnY9ni.mjs +203 -0
  46. package/dist/{work-Bxz-ObF3.mjs → work-BYWD_1Zf.mjs} +3 -3
  47. package/dist/{work-CNhFF9pU.mjs → work-DJxH7cCX.mjs} +1 -1
  48. package/docs/boards-and-folders.md +11 -0
  49. package/docs/jam-session.md +52 -18
  50. package/docs/live-jam.md +95 -10
  51. package/docs/performance.md +1 -1
  52. package/docs/publish.md +7 -0
  53. package/package.json +1 -1
  54. package/src/client/shell/Comments.tsx +5 -4
  55. package/src/client/shell/ContextMenu.tsx +5 -4
  56. package/src/client/shell/JamSurface.tsx +135 -29
  57. package/src/client/shell/Play.tsx +16 -4
  58. package/src/client/shell/api.ts +7 -3
  59. package/src/client/shell/app-bridge.ts +11 -3
  60. package/src/client/shell/comments-store.ts +14 -0
  61. package/src/client/shell/goto.ts +4 -3
  62. package/src/client/shell/icons.tsx +1 -0
  63. package/src/client/shell/jam-capture.ts +136 -37
  64. package/src/client/shell/jam-keys.ts +170 -18
  65. package/src/client/shell/jam-lane.tsx +14 -5
  66. package/src/client/shell/jam-lines.ts +76 -10
  67. package/src/client/shell/jam-panel.tsx +58 -4
  68. package/src/client/shell/jam-queue.ts +55 -8
  69. package/src/client/shell/jam-session.tsx +55 -6
  70. package/src/client/shell/jam-state.ts +19 -4
  71. package/src/client/shell/jam-surface-parts.tsx +6 -3
  72. package/src/client/shell/jam-ui.tsx +10 -1
  73. package/src/client/shell/jam-voice-wait.ts +21 -0
  74. package/src/client/shell/jam-voice.ts +14 -5
  75. package/src/client/shell/live-picture.ts +134 -0
  76. package/src/client/shell/open-item.ts +83 -0
  77. package/src/client/shell/open-resolve.ts +50 -0
  78. package/src/client/shell/store.ts +6 -2
  79. package/src/client/shell/styles.css +29 -11
  80. package/src/client/shell/tidy.ts +3 -2
  81. package/src/client/stage/main.tsx +30 -8
  82. package/src/shared/app-api.ts +173 -3
  83. package/src/shared/app-perf.ts +4 -2
  84. package/src/shared/approval.ts +20 -0
  85. package/src/shared/events.ts +1 -1
  86. package/templates/AGENTS-embedded.md +28 -1
  87. package/templates/AGENTS-studio.md +28 -1
  88. package/templates/instructions/boards.md +7 -1
  89. package/templates/instructions/jam.md +94 -0
  90. package/dist/boards-BHKP5yhI.mjs +0 -342
  91. package/dist/live-Cgzsicwi.mjs +0 -4
@@ -19,9 +19,10 @@ import { create } from 'zustand'
19
19
  import { ROUTE } from '../const.ts'
20
20
  import { CONFIG, useStore } from './store.ts'
21
21
  import { api } from './api.ts'
22
+ import { finalWait, FINAL_MS, wordsWhole } from './jam-voice-wait.ts'
22
23
 
23
24
  export const RATE = 16_000
24
- const FINAL_MS = 3_000
25
+ // how long a segment's last words are waited for: jam-voice-wait.ts (FINAL_MS, longer while the engine is heard from)
25
26
  const CHUNK = 1_600 // 100 ms
26
27
 
27
28
  const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
@@ -164,6 +165,8 @@ let wsOpen: Promise<WebSocket | null> | null = null
164
165
  const finals = new Map<string, (complete: boolean) => void>() // segment -> its final
165
166
  let toldUnavailable = false
166
167
  let takenOver = false
168
+ /** when the speech engine last answered (words or a final): a final still to come is waited for longer while it works */
169
+ let engineAt = 0
167
170
 
168
171
  const setLive = () => useJamVoice.setState({ live: !!mic && !mic.closed, hearing: mic && !mic.closed && mic.seg?.owner.kind === 'capture' ? mic.seg.owner.id : null })
169
172
 
@@ -183,6 +186,7 @@ function socket(reclaim = false): Promise<WebSocket | null> {
183
186
  let m: any
184
187
  try { m = JSON.parse(String(e.data)) } catch { return }
185
188
  if (typeof m?.capture !== 'string') return
189
+ if (m.type === 'words' || m.type === 'final') engineAt = Date.now()
186
190
  const owner = owners.get(m.capture)
187
191
  if (m.type === 'words' && Array.isArray(m.words)) {
188
192
  if (!owner || owner.kind !== 'capture' || !accepting.has(owner.id)) return // talk goes to the transcript on the server
@@ -306,8 +310,12 @@ function endSegment(s: Segment, at: { start: number; pcm: Int16Array; mark: numb
306
310
  const clean = !!at && s.from >= 0
307
311
  if (clean) sendChunk(s, at!.start, at!.pcm)
308
312
  const lastSample = clean ? s.base + at!.mark - s.from : s.sent
313
+ const cut = Date.now()
309
314
  const done = !ws || ws.readyState !== WebSocket.OPEN ? Promise.resolve(false) : new Promise<boolean>((res) => {
310
- const t = setTimeout(() => { finals.delete(s.seg); res(false) }, FINAL_MS)
315
+ // FINAL_MS after the cut - longer while the engine keeps answering (it is working through what came before)
316
+ let t: ReturnType<typeof setTimeout>
317
+ const wait = () => { const ms = finalWait(cut, engineAt, Date.now()); if (ms > 0) t = setTimeout(wait, ms); else { finals.delete(s.seg); res(false) } }
318
+ t = setTimeout(wait, FINAL_MS)
311
319
  finals.set(s.seg, (complete) => { clearTimeout(t); res(complete && clean) })
312
320
  ws!.send(JSON.stringify({ type: 'end', capture: s.seg, lastSample }))
313
321
  })
@@ -448,12 +456,13 @@ async function begin() {
448
456
  await reconcile()
449
457
  }
450
458
 
451
- /** Every segment of an owner ended: true when all its words came back whole. */
459
+ /** Every segment of an owner ended: true when all its words came back whole - and, with the microphone on for this
460
+ * canvas, when it heard the owner at all (an engine not available, a microphone still opening or refused: none). */
452
461
  async function settled(owner: string): Promise<boolean> {
453
462
  const list = cuts.get(owner) ?? []
454
463
  cuts.delete(owner)
455
464
  const all = await Promise.all(list)
456
- const ok = all.every(Boolean) && !broken.has(owner)
465
+ const ok = wordsWhole(all, broken.has(owner), useJamVoice.getState().choice === 'yes')
457
466
  broken.delete(owner)
458
467
  return ok
459
468
  }
@@ -469,7 +478,7 @@ export async function voiceBegin(id: string, t0: number) {
469
478
  }
470
479
 
471
480
  /** A capture ends: its audio cut at this instant (in a session the talk goes on from it), its words awaited
472
- * (3 s at most). Resolves true when the words are complete, false when they may not be. */
481
+ * (jam-voice-wait.ts). Resolves true when the words are complete, false when they may not be. */
473
482
  export async function voiceEnd(id: string): Promise<boolean> {
474
483
  if (capture?.id === id) capture = null
475
484
  useJamVoice.setState((st) => ({ asking: st.asking && st.choice === null && !session ? false : st.asking }))
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Live pictures (spec 28 A4.6 #31-#38): in the Mac app, a capture's picture of the play stage is the owner's screen as
3
+ * they see it - an open menu, typed text, the pins on it - in place of the server's render. One logical picture per shot
4
+ * (#33): the live one when the shot is eligible and it lands, else the render, as without the app (jam-capture.ts
5
+ * `shoot`). Everywhere else - Chrome, a published canvas, an app without `capture` - nothing here runs.
6
+ *
7
+ * Eligible (#34), decided synchronously at the trigger, never cropped to fit: the app offers `capture`; the shot's frame
8
+ * is the one playing; the stage document has shown it for `STAGE_SETTLE_MS` (its `__mvStage` record, past a slide's
9
+ * tempo); the stage's whole rect is on screen below the scroll edge (`onScreen`, unchanged), at least `RING` px inside
10
+ * the view (the Jam ring), a 3 x 3 grid of `elementFromPoint` over it finds only the stage - its frame and its own
11
+ * pins and cards - and no floating layer of the shell's touches it by its box (the live caption and tips take no
12
+ * pointer, so hit-testing alone never sees them): never a lane tile, a panel, the notes card, the caption, a toast or
13
+ * a menu. So fill and doc presets, edge to edge, take the render; a device preset or a slide fitted to the window
14
+ * takes a live one.
15
+ *
16
+ * The ask binds what it was decided for - the frame, the theme, the rect, the view's size, the stage's `boot` and
17
+ * `seq` - and the answer is checked against all of it again (#35): a reload, A -> B -> A, a resize or an overlay
18
+ * opened meanwhile drops the bytes. Then the upload (`POST jam/picture/live`, the raw PNG), all under the caller's one
19
+ * deadline.
20
+ */
21
+ import { APP } from './marver-app.ts'
22
+ import { onScreen } from './inset.ts'
23
+ import { useStore } from './store.ts'
24
+ import { api } from './api.ts'
25
+ import type { StageRecord } from '../stage/main.tsx'
26
+
27
+ /** The stage has shown the frame this long: past the slide tempo (350 ms), so a transition is never pictured. */
28
+ export const STAGE_SETTLE_MS = 1000
29
+ /** The capture call and the upload together, at most; then the render (#36). */
30
+ export const LIVE_PICTURE_MS = 5000
31
+ /** The Jam ring's width at the view's edge (styles.css `.jm-edge`): the stage lies inside it. */
32
+ const RING = 6
33
+
34
+ const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
35
+
36
+ /** What a live picture was decided for: the answer must find all of it as it was. */
37
+ export interface LiveAsk {
38
+ frame: string
39
+ theme: string
40
+ /** the stage in view CSS px */
41
+ rect: { x: number; y: number; width: number; height: number }
42
+ view: { w: number; h: number }
43
+ boot: string
44
+ seq: number
45
+ }
46
+
47
+ const stageRecord = (stage: Element): StageRecord | null => {
48
+ try {
49
+ const r = (stage.querySelector('iframe')?.contentWindow as { __mvStage?: StageRecord } | null)?.__mvStage
50
+ return r && typeof r.boot === 'string' && typeof r.seq === 'number' ? r : null
51
+ } catch { return null }
52
+ }
53
+
54
+ /** Only the stage under a 3 x 3 grid over it: its frame, its own pins and cards. */
55
+ function clear(stage: Element, r: DOMRect): boolean {
56
+ for (const fy of [1 / 6, 1 / 2, 5 / 6]) for (const fx of [1 / 6, 1 / 2, 5 / 6]) {
57
+ const el = document.elementFromPoint(r.left + r.width * fx, r.top + r.height * fy)
58
+ if (!el || !stage.contains(el)) return false
59
+ }
60
+ return true
61
+ }
62
+
63
+ /** The shell's floating layers, by their visible boxes: the caption, the notes card and the mic question, the lane's
64
+ * tiles (never its full-width row), toasts, tips, menus, the focus panel, Jam's sheets. */
65
+ const LAYERS = '.jm-caption, .jm-over, .jm-lane-in > *, .sh-toasts > *, .sh-tip, .sh-menu, .jm-focus > *, .jm-sheet-at > *'
66
+
67
+ /** Does any of them, outside the stage, touch its rect? By box, not by hit-testing: the caption and a tip take no
68
+ * pointer, so the grid looks through them, and a band along an edge falls between its points - yet the readback
69
+ * holds whatever is drawn there. */
70
+ function covered(stage: Element, r: DOMRect): boolean {
71
+ for (const el of document.querySelectorAll(LAYERS)) {
72
+ if (stage.contains(el)) continue
73
+ const b = el.getBoundingClientRect()
74
+ if (b.width > 0 && b.height > 0 && b.left < r.right && r.left < b.right && b.top < r.bottom && r.top < b.bottom) return true
75
+ }
76
+ return false
77
+ }
78
+
79
+ const near = (a: number, b: number) => Math.abs(a - b) < 0.01
80
+
81
+ /** The ask for a live picture of `frame` now, or null: the shot takes the server's render (#34). */
82
+ export function liveAsk(frame: string): LiveAsk | null {
83
+ if (typeof APP?.capture !== 'function') return null
84
+ const play = useStore.getState().play
85
+ if (!play || play.at !== frame) return null
86
+ const stage = document.querySelector('.sh-play-stage')
87
+ const dev = stage?.querySelector('.dev')
88
+ if (!stage || !dev) return null
89
+ const rec = stageRecord(stage)
90
+ if (!rec || rec.at !== frame || Date.now() - rec.t < STAGE_SETTLE_MS) return null
91
+ const r = dev.getBoundingClientRect()
92
+ // its whole rect on screen, below the strip and its scroll edge: none of it cut
93
+ const on = onScreen(r)
94
+ if (!on || !near(on.left, r.left) || !near(on.top, r.top) || !near(on.right, r.right) || !near(on.bottom, r.bottom)) return null
95
+ if (r.left < RING || r.top < RING || r.right > innerWidth - RING || r.bottom > innerHeight - RING) return null
96
+ if (!clear(stage, r) || covered(stage, r)) return null
97
+ return { frame, theme: play.theme, rect: { x: r.left, y: r.top, width: r.width, height: r.height }, view: { w: innerWidth, h: innerHeight }, boot: rec.boot, seq: rec.seq }
98
+ }
99
+
100
+ /** Is everything the ask was decided for still so? The same frame, theme, rect and view, the same stage document and
101
+ * showing, and the grid clear again (#35). */
102
+ export function stillHolds(a: LiveAsk): boolean {
103
+ const b = liveAsk(a.frame)
104
+ return !!b && b.theme === a.theme && b.boot === a.boot && b.seq === a.seq && b.view.w === a.view.w && b.view.h === a.view.h
105
+ && near(b.rect.x, a.rect.x) && near(b.rect.y, a.rect.y) && near(b.rect.width, a.rect.width) && near(b.rect.height, a.rect.height)
106
+ }
107
+
108
+ /** `p`, or null once `signal` aborts (a capture call cannot be cancelled: its late answer is dropped). */
109
+ const until = <T>(p: Promise<T>, signal: AbortSignal): Promise<T | null> => new Promise((done) => {
110
+ if (signal.aborted) return done(null)
111
+ signal.addEventListener('abort', () => done(null), { once: true })
112
+ p.then(done, () => done(null))
113
+ })
114
+
115
+ /**
116
+ * The live picture for a shot of `capture`: the app's readback of the stage, checked again against the ask, then
117
+ * uploaded - its picture id, or null and the shot takes the render. `open()`: the capture is still unsealed. Every step
118
+ * stops at `signal` (the caller's one deadline over the call and the upload).
119
+ */
120
+ export async function takeLive(a: LiveAsk, capture: string, open: () => boolean, signal: AbortSignal): Promise<string | null> {
121
+ try {
122
+ const app = APP
123
+ if (!app?.capture) return null
124
+ const answer = await until(app.capture({ rect: a.rect }), signal)
125
+ if (!answer || !answer.ok || !(answer.png instanceof Uint8Array) || !answer.png.length) return null
126
+ if (signal.aborted || !open() || !stillHolds(a)) return null
127
+ const r = await api(`jam/picture/live?capture=${encodeURIComponent(capture)}&frame=${encodeURIComponent(a.frame)}`, {
128
+ method: 'POST', signal, headers: { 'content-type': 'image/png', 'x-mv-c': csrf() }, body: answer.png as Uint8Array<ArrayBuffer>,
129
+ })
130
+ if (!r.ok || signal.aborted) return null
131
+ const id = ((await r.json()) as { id?: unknown })?.id
132
+ return typeof id === 'string' && /^p-[0-9a-f]{16}$/.test(id) && !signal.aborted ? id : null
133
+ } catch { return null }
134
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * A notice's click, in the shell (spec 28 A4.6 #29, #30; r1 #1-#3, r2 #1, #2, r3, r4 #1). Main hands `mv:open` the item
3
+ * as the live stream named it, once this document is admitted; the shell reads afresh what it resolves against - never
4
+ * the click's copy - compares the occurrence, its state and its counter, and opens the target through the helpers
5
+ * every other path uses (jam-keys.ts). Its answer: `handled` - the item is on screen; `stale` - its target stands in
6
+ * another state, or the same state with another counter, and opens as it stands (never another item); `missing` - the
7
+ * target is gone, and only its board opens; `busy` - a capture records or words wait unsent, and nothing moved;
8
+ * `dropped` - a read failed, the deadline passed, or a later click, a hidden tab or a revoked trust took its place.
9
+ *
10
+ * One request at a time, under one deadline over everything: `alive()` holds while the request is the current one,
11
+ * before its deadline, with no capture recording and no words typed and unsent - and once it fails it stays failed. The helpers read it before every step
12
+ * that moves the UI - a board change, comments turned on, a thread made active, a panel or a menu opened, Play left -
13
+ * so words typed during the reads or a wait are seen at the next step, and once it fails nothing more moves. Opening
14
+ * a question never marks it answered.
15
+ */
16
+ import { LIVE_KINDS, type OpenItem, type OpenResult } from '../../shared/app-api.ts'
17
+ import { typedUnsent } from './api.ts'
18
+ import { useComments } from './comments-store.ts'
19
+ import { useJamCapture } from './jam-capture.ts'
20
+ import { openRunControls, openThreadAt, openTile, toBoard, type Alive } from './jam-keys.ts'
21
+ import { useJamQueue } from './jam-queue.ts'
22
+ import { resolveItem, type Target } from './open-resolve.ts'
23
+ import { fetchBoardNames, useStore } from './store.ts'
24
+
25
+ /** One deadline over a request: the manifest, the reads, the helpers' waits. */
26
+ export const OPEN_MS = 10_000
27
+ let current = 0
28
+
29
+ /** The request in hand ends - `mv:app-state` hidden or untrusted: nothing of it moves after this. */
30
+ export function endOpen(): void { current++ }
31
+
32
+ /** Nothing may move: a capture records, or a field holds words typed and not sent (a move would lose them). */
33
+ const busy = () => !!useJamCapture.getState().current || typedUnsent()
34
+
35
+ /** Open the live item a notice named, and say what was found (A4.6 #30). Registered by startAppBridge as `onOpen`. */
36
+ export async function openLiveItem(p: OpenItem): Promise<OpenResult> {
37
+ const n = ++current
38
+ const until = performance.now() + OPEN_MS
39
+ // one way (code review r3): the first time it reads false - a later click, hidden, untrusted, the deadline, a recording,
40
+ // words unsent - the request has ended for good, for every helper and every deferred callback at once. Words cleared or
41
+ // sent after never bring it back: a switch it started would otherwise commit when they go (toBoard's predicate)
42
+ let ended: 'busy' | 'dropped' | null = null
43
+ const alive: Alive = () => {
44
+ if (!ended && (n !== current || performance.now() >= until || busy())) ended = busy() ? 'busy' : 'dropped'
45
+ return !ended
46
+ }
47
+ /** once it fails: busy if a capture recorded or words waited when it ended, else dropped */
48
+ const gaveUp = (): OpenResult => ended ?? (busy() ? 'busy' : 'dropped')
49
+ if (!p || typeof p.board !== 'string' || !(LIVE_KINDS as readonly string[]).includes(p.kind)) return 'dropped'
50
+ if (busy()) return 'busy'
51
+ /** a promise, or undefined at the deadline */
52
+ const inTime = <T>(pr: Promise<T>) => Promise.race([pr.catch(() => undefined), new Promise<undefined>((r) => setTimeout(() => r(undefined), Math.max(0, until - performance.now())))])
53
+ // the board's manifest first
54
+ while (!useStore.getState().manifest) {
55
+ if (!alive()) return gaveUp()
56
+ await new Promise((r) => setTimeout(r, 50))
57
+ }
58
+ // then what it resolves against, read afresh - only a read that succeeds counts
59
+ const needsQueue = p.kind !== 'ask' || !!p.cards?.length
60
+ const [comments, queue] = await Promise.all([inTime(useComments.getState().refresh(p.board)), needsQueue ? inTime(useJamQueue.getState().load()) : Promise.resolve(false)])
61
+ if (!alive() || comments !== true) return gaveUp()
62
+ // the occurrence against what was just read (open-resolve.ts): an ask with cards opens through its thread alone when
63
+ // the queue could not be read; review, failed and stalled stand on it
64
+ const found = resolveItem(p, useComments.getState().threads, queue === true ? useJamQueue.getState().cards ?? [] : null)
65
+ if (found === 'unread') return gaveUp()
66
+ if (found === 'missing') {
67
+ // only its board opens, when it exists - its switch under the request, as every move here
68
+ const exists = p.board === useStore.getState().board || !!(await inTime(fetchBoardNames()))?.includes(p.board)
69
+ if (exists && p.board !== useStore.getState().board && !(await toBoard(p.board, alive))) return gaveUp()
70
+ return 'missing'
71
+ }
72
+ return (await openTarget(p.board, found.target, alive)) ? found.result : gaveUp()
73
+ }
74
+
75
+ /** Open a target through the one helper of its kind (jam-keys.ts), each reading `alive` before every move. */
76
+ function openTarget(board: string, t: Target, alive: Alive): Promise<boolean> {
77
+ if ('thread' in t) return openThreadAt(board, t.thread, { alive })
78
+ if ('tile' in t) return openTile(t.tile, { alive })
79
+ return openRunControls(t.controls, { alive })
80
+ }
81
+
82
+ // dev-only inspection hook for tests (never installed in published builds)
83
+ if (typeof window !== 'undefined' && import.meta.env.DEV) (window as unknown as { __mvOpen: unknown }).__mvOpen = { openLiveItem, endOpen }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * What a notice's click names, against what the page holds now (spec 28 A4.6 #30, r1 #1, r3 #2) - pure, so its rules
3
+ * are the package's unit cases: the occurrence compared, its state and its counter, and the target to open. A target
4
+ * that still stands in that state with that counter is `handled`; one in another state, or the same state with another
5
+ * counter (a second stall of one claim, a redelivery that failed again, a review after More work), is `stale` and opens
6
+ * as it stands - never another item; one gone is `missing`. A comment card the queue's view no longer holds (it keeps a
7
+ * finished one 60 s) is not gone while its thread stands: stale, its thread opened.
8
+ */
9
+ import { asks, type Thread } from '../../shared/events.ts'
10
+ import type { OpenItem } from '../../shared/app-api.ts'
11
+ import type { JamCard } from './jam-queue.ts'
12
+
13
+ /** Where it opens: a thread (`openThreadAt`), a card's tile surface (`openTile`), or a run's controls (`openRunControls`). */
14
+ export type Target = { thread: string } | { tile: string } | { controls: JamCard }
15
+ /** `unread`: it stands on the queue, which was not read - nothing can be said, nothing moves. */
16
+ export type Resolution = { result: 'handled' | 'stale'; target: Target } | 'missing' | 'unread'
17
+
18
+ /** A card's target as it stands: a comment card's thread, else its tile's surface. */
19
+ const asItStands = (c: JamCard): Target => (c.kind === 'comment' && c.thread ? { thread: c.thread } : { tile: c.id })
20
+
21
+ /** `threads`: every board's, as the comments store holds them; `cards`: the queue's view read now, or null when unread. */
22
+ export function resolveItem(p: OpenItem, threads: readonly Thread[], cards: readonly JamCard[] | null): Resolution {
23
+ const threadOf = (id?: string) => (id ? threads.find((t) => t.id === id && (!t.board || t.board === p.board)) : undefined)
24
+ const mine = (cards ?? []).filter((c) => p.cards?.includes(c.id))
25
+ const viaThread = (): Resolution => { const t = threadOf(p.thread); return t ? { result: 'stale', target: { thread: t.id } } : 'missing' }
26
+ if (p.kind === 'ask') {
27
+ const t = threadOf(p.thread)
28
+ if (!t) return 'missing'
29
+ const last = t.replies.length ? t.replies[t.replies.length - 1] : t
30
+ const msg = last === t ? t.id : (last as Thread['replies'][number]).id
31
+ const now = !t.resolved && msg === p.msg && !!last.agent && asks(last, last === t)
32
+ // its Jam card is only a way in: read, and still asking, it opens through the card (a capture keeps its panel)
33
+ const card = now ? mine.find((c) => c.state === 'asks' && c.thread === t.id) : undefined
34
+ return { result: now ? 'handled' : 'stale', target: card ? { tile: card.id } : { thread: t.id } }
35
+ }
36
+ if (!cards) return 'unread'
37
+ if (p.kind === 'review') {
38
+ const c = mine[0]
39
+ if (!c) return 'missing'
40
+ const now = c.state === 'review' && c.batch === p.batch && (c.att ?? 0) === p.occ
41
+ return { result: now ? 'handled' : 'stale', target: now ? { tile: c.id } : asItStands(c) }
42
+ }
43
+ // failed: the same run failing again is another occurrence - its batch and failures, or (no run) the card's attempts;
44
+ // stalled: a second stall of the same claim is another
45
+ const now = p.kind === 'failed'
46
+ ? mine.find((c) => c.state === 'failed' && (p.batch ? c.batch === p.batch && (c.fails ?? 0) === p.occ : (c.att ?? 0) === p.occ))
47
+ : mine.find((c) => c.state === 'working' && c.runner?.state === 'stalled' && c.runner.batch === p.batch && c.runner.gen === p.gen && (c.runner.stalls ?? 0) === p.occ)
48
+ if (now) return { result: 'handled', target: { controls: now } }
49
+ return mine[0] ? { result: 'stale', target: asItStands(mine[0]) } : viaThread()
50
+ }
@@ -667,7 +667,9 @@ interface State {
667
667
  setSelectedTheme(theme: string): void
668
668
  setDeviceView(name: string | null): void
669
669
  resizeSelected(name: string | null): void
670
- switchBoard(name: string): Promise<void>
670
+ /** `mayCommit`, read last before the new board commits: false leaves the board shown as it is (a notice's request,
671
+ * jam-keys.ts toBoard) */
672
+ switchBoard(name: string, mayCommit?: () => boolean): Promise<void>
671
673
  /** what the sidebar labels boards by: slug → title, off the last tree read */
672
674
  boardTitles: Record<string, string>
673
675
  /** what the sidebar draws beside a board: its type and status (spec 20), off the last tree read */
@@ -1194,7 +1196,7 @@ export const useStore = create<State>((set, get) => {
1194
1196
  return true
1195
1197
  },
1196
1198
 
1197
- async switchBoard(name) {
1199
+ async switchBoard(name, mayCommit) {
1198
1200
  const mySwitch = ++switchSeq // also cancels any pending switch (incl. re-clicking the current board)
1199
1201
  switchCalls++
1200
1202
  recorderHooks.cut(switchRequest, 'superseded')
@@ -1224,6 +1226,8 @@ export const useStore = create<State>((set, get) => {
1224
1226
  for (let i = 0; i < 5 && get().dirty && ok; i++) { clearTimeout(saveTimer); ok = await get().save() }
1225
1227
  if (mySwitch !== switchSeq) return recorderHooks.cut(request, 'superseded')
1226
1228
  if (get().dirty) { recorderHooks.cut(request, 'unsaved'); get().toast('current board could not be saved - staying here'); return }
1229
+ // the caller's own condition, read last: words typed while the board loaded, or its request ended, keep this board
1230
+ if (mayCommit && !mayCommit()) return recorderHooks.cut(request, 'superseded')
1227
1231
  clearTimeout(saveTimer) // a scheduled-but-clean timer must not fire against the new board
1228
1232
  ++loadSeq // invalidate any in-flight boot of the old board
1229
1233
  recorderHooks.cut(bootRequest, 'superseded')
@@ -463,8 +463,10 @@ body.sh-space .sh-node { pointer-events: none } /* space-drag
463
463
  .sh-ibtn:hover { background: var(--glass-hover); color: var(--glass-ink) }
464
464
 
465
465
  /* floating glass panel; collapses into the fab with a scale-fade morph */
466
- .sh-panel { position: absolute; left: var(--edge); top: calc(var(--mv-top, 0px) + var(--edge)); width: 236px;
467
- max-height: calc(100% - 2 * var(--edge) - var(--mv-top, 0px)); z-index: 10;
466
+ /* The floating chrome sits at the larger of the edge and the app's top inset (Nic, 26 Oct): in the Mac app the strip's own
467
+ padding is the gap, so nothing stacks the edge under it; in a browser --mv-top is 0 and the edge holds, as before. */
468
+ .sh-panel { position: absolute; left: var(--edge); top: max(var(--edge), var(--mv-top, 0px)); width: 236px;
469
+ max-height: calc(100% - var(--edge) - max(var(--edge), var(--mv-top, 0px))); z-index: 10;
468
470
  border-radius: var(--r-panel); padding: 10px; display: flex; flex-direction: column;
469
471
  font-size: 13px; color: var(--glass-ink);
470
472
  transform-origin: 22px 22px; transition: transform var(--morph), opacity .2s ease }
@@ -588,7 +590,7 @@ body.sh-space .sh-node { pointer-events: none } /* space-drag
588
590
  .sh-panel .sub.dim:hover { background: none; color: var(--glass-ink-3) }
589
591
 
590
592
  /* collapsed panel: a round glass button; morphs against the panel */
591
- .sh-fab { position: absolute; left: var(--edge); top: calc(var(--mv-top, 0px) + var(--edge)); z-index: 11; width: 44px; height: 44px;
593
+ .sh-fab { position: absolute; left: var(--edge); top: max(var(--edge), var(--mv-top, 0px)); z-index: 11; width: 44px; height: 44px;
592
594
  display: grid; place-items: center; border-radius: 999px;
593
595
  color: var(--glass-ink-2); cursor: pointer;
594
596
  transition: transform var(--morph), opacity .2s ease }
@@ -597,13 +599,13 @@ body.sh-space .sh-node { pointer-events: none } /* space-drag
597
599
 
598
600
  /* pill nav */
599
601
  /* uniform 5px inset on every side: 34px buttons + 2*5px = 44px, same as the fab */
600
- .sh-pill { position: absolute; right: var(--edge); top: calc(var(--mv-top, 0px) + var(--edge)); z-index: 10; display: flex; align-items: center; gap: 1px;
602
+ .sh-pill { position: absolute; right: var(--edge); top: max(var(--edge), var(--mv-top, 0px)); z-index: 10; display: flex; align-items: center; gap: 1px;
601
603
  border-radius: 999px; padding: 5px;
602
604
  transform-origin: calc(100% - 22px) 22px; transition: transform var(--morph), opacity .2s ease }
603
605
  .sh-pill.closed { transform: scale(.16); opacity: 0; pointer-events: none }
604
606
  /* the pill's expand chip - the sidebar fab, mirrored top-right: same glass (shared
605
607
  surface rule above), same morph, the bar shrinking into the chip's spot */
606
- .sh-pill-fab { position: absolute; right: var(--edge); top: calc(var(--mv-top, 0px) + var(--edge)); z-index: 11; width: 44px; height: 44px;
608
+ .sh-pill-fab { position: absolute; right: var(--edge); top: max(var(--edge), var(--mv-top, 0px)); z-index: 11; width: 44px; height: 44px;
607
609
  display: grid; place-items: center; border-radius: 999px;
608
610
  color: var(--glass-ink-2); cursor: pointer;
609
611
  transition: transform var(--morph), opacity .2s ease }
@@ -1153,6 +1155,8 @@ body.sh-hide-ui .sh-play-nav { display: none !important }
1153
1155
  @keyframes sh-tstat-pop { from { opacity: 0; transform: translateY(-3px) } }
1154
1156
  .cm-tstat-pop { animation-name: sh-tstat-pop }
1155
1157
  .cm-tstat-pop .sh-tip-lines { display: flex; flex-direction: column; gap: 2px; white-space: normal; min-width: 0 }
1158
+ .cm-tstat-pop.many { flex-wrap: wrap; row-gap: 6px } /* a stalled run's three choices wrap under its lines */
1159
+ .cm-tstat-pop.many .sh-tip-lines { flex-basis: 100% }
1156
1160
  .cm-tstat-pop .sh-tip-lines b { font-weight: 600; font-size: 12px; letter-spacing: 0; white-space: normal; overflow: visible; text-overflow: clip; max-width: none; color: inherit }
1157
1161
  .cm-tstat-pop .sh-tip-lines small { opacity: .62; font-size: 11px; line-height: 1.35 }
1158
1162
  .cm-tstat-act { flex: none; height: 24px; padding: 0 10px; border: 0; border-radius: 6px; cursor: pointer;
@@ -1585,7 +1589,7 @@ body.sh-commenting .sh-sticky-body { cursor: crosshair }
1585
1589
  .sh-pill-btn.jm-jam .jm-nomic { color: var(--glass-ink-2) }
1586
1590
 
1587
1591
  /* ---- a capture's tile (round 3): two lines, a little squarer - glyph | title over a status line
1588
- ("Ready to review", "Agent working · 0:41", "Done · 1 frame changed"). Colour only in the glyph. ---- */
1592
+ ("Ready to review", "Claude Code is working · 0:41", "Done · 1 frame changed"). Colour only in the glyph. ---- */
1589
1593
  .jm-card { display: inline-flex; align-items: center; gap: 10px; height: 44px; width: 216px; flex: none; /* one width: a tile never resizes */
1590
1594
  padding: 0 14px 0 12px; border-radius: 10px; color: var(--glass-ink); text-align: left; cursor: pointer }
1591
1595
  .jm-card .jm-st { flex: none }
@@ -1797,6 +1801,9 @@ body.sh-commenting .sh-sticky-body { cursor: crosshair }
1797
1801
  .jm-chip .stop svg { display: none }
1798
1802
  .jm-chip .stop::before { content: ''; width: 8px; height: 8px; border-radius: 2px; background: var(--jm-rec); flex: none }
1799
1803
  .jm-chip .stop:disabled::before { background: var(--glass-ink-3) }
1804
+ .jm-chip .stop.review::before { display: none }
1805
+ .jm-chip .stop.review svg { display: block; color: var(--jm-rec) }
1806
+ .jm-chip .stop.review:disabled svg { color: var(--glass-ink-3) }
1800
1807
  .jm-stage .jm-chip { height: 40px; padding: 0 5px 0 14px; border-radius: 999px; background: rgba(18, 18, 24, .82);
1801
1808
  border: 1px solid rgba(255, 255, 255, .12); box-shadow: none; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px) }
1802
1809
  .jm-stage .jm-chip .note, .jm-stage .jm-chip .stop { height: 30px; border-radius: 999px }
@@ -1842,7 +1849,7 @@ body.sh-commenting .sh-sticky-body { cursor: crosshair }
1842
1849
  .jm-notefield .caret { display: inline-block; width: 1px; height: 15px; background: var(--accent); vertical-align: -3px; margin-left: 1px }
1843
1850
  .jm-notes .foot { display: flex; gap: 12px; justify-content: flex-end; font: 500 11px -apple-system, system-ui, sans-serif; color: var(--glass-ink-3) }
1844
1851
  /* the focus panel: top edge to just above the lane; the panel inside fills it and its middle scrolls */
1845
- .jm-focus { position: absolute; top: calc(var(--mv-top, 0px) + var(--edge)); bottom: calc(var(--edge) + var(--jm-lane) + 2px); z-index: 31; display: flex }
1852
+ .jm-focus { position: absolute; top: max(var(--edge), var(--mv-top, 0px)); bottom: calc(var(--edge) + var(--jm-lane) + 2px); z-index: 31; display: flex }
1846
1853
  .jm-focus > .jm-panel { width: 100%; height: 100%; min-height: 0 }
1847
1854
  /* one big picture at a time: the frame tabs and a Before | After switch above it (B flips) */
1848
1855
  .jm-fbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap } /* a narrow window wraps the switch under the tabs */
@@ -1863,7 +1870,13 @@ body.sh-commenting .sh-sticky-body { cursor: crosshair }
1863
1870
  .jm-ftabs button.on { background: var(--solid); color: var(--glass-ink); font-weight: 600; box-shadow: 0 1px 2px rgba(24, 24, 27, .12), 0 0 0 .5px var(--glass-brd) }
1864
1871
  .jm-focus > .jm-readback .jm-thumbs { gap: 12px }
1865
1872
  /* the review's big picture sits centred in a quiet well that takes the panel's spare height */
1866
- .jm-focus .jm-big { align-items: center; padding: 10px; border-radius: 14px; background: var(--glass-hover) }
1873
+ .jm-focus .jm-big { align-items: center; padding: 14px 16px 16px; border-radius: 14px; background: #0a0a0b }
1874
+ /* the pictures sit on the play-mode stage (Nic, 27 Oct): dark in both themes, so the frames read apart from the panel */
1875
+ .jm-focus .jm-big.pair { gap: 16px }
1876
+ .jm-focus .jm-big.pair .jm-shot { gap: 8px }
1877
+ .jm-focus .jm-big.pair .jm-shot .cap { color: rgba(255, 255, 255, .86) }
1878
+ .jm-focus .jm-big .jm-shot .pic img { box-shadow: 0 0 0 1px rgba(255, 255, 255, .1), 0 6px 20px -8px rgba(0, 0, 0, .6) }
1879
+ .jm-focus .jm-big .jm-shot .pic.none { border-color: rgba(255, 255, 255, .28); color: rgba(255, 255, 255, .6) }
1867
1880
  /* in play the Note button is a pill like Stop beside it (the navigator material) */
1868
1881
  .jm-stage .jm-chip .notebtn { height: 30px; border-radius: 999px; padding: 0 11px }
1869
1882
 
@@ -1878,6 +1891,8 @@ body.sh-commenting .sh-sticky-body { cursor: crosshair }
1878
1891
  /* the panel's middle scrolls; its head and its footer stay in view */
1879
1892
  .jm-panel .jm-body { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow-y: auto; margin: 0 -16px; padding: 0 16px }
1880
1893
  .jm-focus .jm-panel .jm-body { flex: 1 }
1894
+ /* the thread panel (spec 28 A4.6 #30): each Jam card's status icon on its own line, its popover opening under it */
1895
+ .jm-thread .jm-thread-status { display: flex; align-items: center; min-height: 20px; padding-left: 4px }
1881
1896
  .jm-review .jm-big { min-height: 160px }
1882
1897
  .jm-shot .pic img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top center }
1883
1898
  /* the review's one big picture: the shot at its own proportions, centred in the well, never cropped */
@@ -1916,14 +1931,14 @@ button.jm-link { padding: 0; border: 0; background: none; text-align: left; widt
1916
1931
 
1917
1932
  /* Jam V2: while the lane shows, the sidebar stops above it and the bottom edge rises one lane - the
1918
1933
  Update pill, toasts and notices (LANE_H, jam-lane.tsx) */
1919
- .sh-app.jm-lane-on .sh-panel { max-height: calc(100% - 2 * var(--edge) - 56px - var(--mv-top, 0px)); bottom: auto }
1934
+ .sh-app.jm-lane-on .sh-panel { max-height: calc(100% - var(--edge) - 56px - max(var(--edge), var(--mv-top, 0px))); bottom: auto }
1920
1935
  .sh-app.jm-lane-on .sh-update { bottom: calc(var(--edge) + 56px) }
1921
1936
  .sh-app.jm-lane-on .sh-toasts { bottom: calc(var(--edge) + 56px) }
1922
1937
  .sh-app.jm-lane-on .sh-banner { bottom: calc(var(--edge) + 56px) }
1923
1938
  /* the canvas stopped (spec 28 A1.11): on the toolbar's centre line in the gap between the sidebar and the
1924
1939
  toolbar, or just below the toolbar row - placed by the shell (App.tsx placeBanner), which measures both; above
1925
1940
  play and focus. The fallback before it measures: top centre, on the line (34px tall, the row 46px) */
1926
- .sh-app .sh-banner.sh-stopped { top: calc(var(--mv-top, 0px) + var(--edge) + 6px); bottom: auto; left: 50%; right: auto; transform: translateX(-50%);
1941
+ .sh-app .sh-banner.sh-stopped { top: calc(max(var(--edge), var(--mv-top, 0px)) + 6px); bottom: auto; left: 50%; right: auto; transform: translateX(-50%);
1927
1942
  z-index: 40; width: max-content; max-width: none; white-space: nowrap; text-align: center; text-wrap: balance; pointer-events: auto }
1928
1943
  .sh-banner.sh-stopped code { font: 500 11.5px/14px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 1px 5px; border-radius: 5px;
1929
1944
  background: color-mix(in srgb, currentColor 11%, transparent); white-space: nowrap }
@@ -2033,8 +2048,11 @@ button.jm-link { padding: 0; border: 0; background: none; text-align: left; widt
2033
2048
  .jm-panel button.row:hover { background: var(--glass-hover) }
2034
2049
  textarea.jm-field { width: 100%; resize: none; outline: none; overflow: hidden; display: block }
2035
2050
  textarea.jm-field:focus { border-color: transparent; box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-ring) }
2036
- .jm-sheet-at { position: absolute; right: var(--edge); top: calc(var(--mv-top, 0px) + 64px); z-index: 42 }
2051
+ .jm-sheet-at { position: absolute; right: var(--edge); top: calc(max(var(--edge), var(--mv-top, 0px)) + 54px); z-index: 42 }
2037
2052
  .jm-sheet .rows, .jm-wrapup .rows { margin: 0 -8px }
2053
+ /* a row with a second line (who works, the switches): air between rows, the line under the name kept to one line */
2054
+ .jm-sheet .rows .row:has(small) { padding-top: 5px; padding-bottom: 5px; line-height: 1.25 }
2055
+ .jm-sheet .rows .row.jm-two small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-block; max-width: 200px; vertical-align: top }
2038
2056
  .jm-sc-row { position: relative; cursor: default; outline: none }
2039
2057
  .jm-record-panel .jm-body { overflow: auto }
2040
2058
  .jm-record-panel .jm-record { white-space: pre-wrap; overflow-wrap: anywhere }
@@ -22,8 +22,9 @@ export type Warn = (msg: string) => void
22
22
 
23
23
  const isSpace = (x: unknown): x is Space => !!x && typeof x === 'object' && !Array.isArray(x)
24
24
  /** Drop the items `isGone` names, each with the spacer that led into it (or, at the start, the
25
- * one that followed it) - what is left reads as if the item was never there. */
26
- function dropGone<T>(items: T[], isGone: (x: T) => boolean): T[] {
25
+ * one that followed it) - what is left reads as if the item was never there. (`boards place` takes a frame out of a
26
+ * scene recipe the same way.) */
27
+ export function dropGone<T>(items: T[], isGone: (x: T) => boolean): T[] {
27
28
  const out: T[] = []
28
29
  let skip = false
29
30
  for (const it of items) {
@@ -87,6 +87,14 @@ const startId = params.get('at') ?? ''
87
87
  // data-goto ever navigates the stage cross-origin
88
88
  const post = (msg: Record<string, unknown>) => { if (window.parent !== window) window.parent.postMessage(msg, location.origin) }
89
89
 
90
+ /** What a live picture binds (spec 28 A4.6 #34, r1 #5), read by the shell straight from this same-origin document - no
91
+ * message ordering involved (src/client/shell/live-picture.ts). `boot` is this document's; `seq` rises as every swap
92
+ * starts and as it commits; `at` is cleared as a swap starts and set, with `t`, in the tick the committed frame says
93
+ * `sh:stage-shown`. A reloaded stage is a new document: a new `boot`, and no `at` until its first frame commits. */
94
+ export interface StageRecord { boot: string; seq: number; at: string | null; t: number }
95
+ const stageRecord: StageRecord = { boot: `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`, seq: 0, at: null, t: 0 }
96
+ ;(window as unknown as { __mvStage: StageRecord }).__mvStage = stageRecord
97
+
90
98
  window.addEventListener('error', (e) => post({ type: 'sh:stage-error', message: String(e.message || e.error) }))
91
99
  window.addEventListener('unhandledrejection', (e) => post({ type: 'sh:stage-error', message: `unhandled rejection: ${e.reason}` }))
92
100
  // pinch inside the stage must not zoom the parent page (same rule as the frame bridge)
@@ -95,7 +103,9 @@ document.addEventListener('gesturestart', (e) => e.preventDefault())
95
103
  // B0.2: a nested scroll container hitting its boundary must not chain into the shell page
96
104
  document.documentElement.style.overscrollBehavior = 'contain'
97
105
 
98
- interface Mounted { id: string; Frame: ComponentType; wrappers: ComponentType[]; slide: boolean }
106
+ interface Mounted { id: string; Frame: ComponentType; wrappers: ComponentType[]; slide: boolean
107
+ /** the swap that committed it: the same frame committed again (a restart on it) is a new showing */
108
+ commit?: number }
99
109
 
100
110
  /** Resolve a frame id to its component + wrapper chain. Modules are import()-cached by
101
111
  * Vite, so re-resolving a chain yields the SAME component references - React keeps
@@ -118,7 +128,11 @@ class Boundary extends Component<{ resetKey: string; children?: ReactNode }, { e
118
128
  componentDidUpdate(prev: { resetKey: string }) {
119
129
  if (prev.resetKey !== this.props.resetKey && this.state.err) this.setState({ err: null })
120
130
  }
121
- componentDidCatch(err: Error) { post({ type: 'sh:stage-error', message: err.message }) }
131
+ componentDidCatch(err: Error) {
132
+ // its card holds the stage now: nothing on it is the frame
133
+ stageRecord.at = null; stageRecord.seq++
134
+ post({ type: 'sh:stage-error', message: err.message })
135
+ }
122
136
  render() {
123
137
  if (!this.state.err) return this.props.children
124
138
  return createElement(ErrorCard, { title: 'frame crashed', message: this.state.err.message, detail: this.props.resetKey })
@@ -128,13 +142,18 @@ class Boundary extends Component<{ resetKey: string; children?: ReactNode }, { e
128
142
  /** spec 26: a frame that committed - inside the error boundary, so a crash never counts - says which
129
143
  * frame the stage shows, at which revision (the stamp this document was served with: a frame imported
130
144
  * later never claims more than the wrappers it renders with), for which document generation. */
131
- function Shown({ id }: { id: string }) {
145
+ function Shown({ id, commit }: { id: string; commit?: number }) {
146
+ const said = useRef(false)
132
147
  // a tick later, and only if it is still mounted: a frame that throws from its own effects is replaced by
133
- // the boundary's card first, which unmounts this and cancels the report
148
+ // the boundary's card first, which unmounts this and cancels the report. Said once per frame shown; the record
149
+ // follows every commit (A4.6 #34), so the same frame committed again is shown again from then
134
150
  useEffect(() => {
135
- const t = setTimeout(() => post({ type: 'sh:stage-shown', at: id, nav: params.get('r') ?? '', epoch: stamps?.epoch ?? '', doc: stamps?.doc[id] ?? 0 }), 0)
151
+ const t = setTimeout(() => {
152
+ if (!said.current) { said.current = true; post({ type: 'sh:stage-shown', at: id, nav: params.get('r') ?? '', epoch: stamps?.epoch ?? '', doc: stamps?.doc[id] ?? 0 }) }
153
+ stageRecord.at = id; stageRecord.t = Date.now()
154
+ }, 0)
136
155
  return () => clearTimeout(t)
137
- }, [id])
156
+ }, [id, commit])
138
157
  return null
139
158
  }
140
159
 
@@ -158,6 +177,8 @@ function Stage() {
158
177
  const goto = async (id: string, announce: boolean) => {
159
178
  if (id === current.current && mounted && !err) return
160
179
  const seq = ++swapSeq.current
180
+ // a live picture asked before this swap is of another showing (A4.6 #34)
181
+ stageRecord.seq++; stageRecord.at = null
161
182
  try {
162
183
  const next = await resolve(id)
163
184
  if (seq !== swapSeq.current) return // a newer swap superseded this one
@@ -187,7 +208,8 @@ function Stage() {
187
208
  if (seq !== swapSeq.current) return
188
209
  // the slide mark first: content primitives read it while they render
189
210
  document.documentElement.toggleAttribute('data-mv-slide', next.slide)
190
- flushSync(() => { setErr(null); setMounted(next) })
211
+ stageRecord.seq++
212
+ flushSync(() => { setErr(null); setMounted({ ...next, commit: seq }) })
191
213
  current.current = id
192
214
  disarm()
193
215
  }
@@ -310,7 +332,7 @@ function Stage() {
310
332
  // that differs at depth k legitimately remounts everything below
311
333
  let tree: ReactNode = createElement(mounted.Frame)
312
334
  for (const W of [...mounted.wrappers].reverse()) tree = createElement(W, null, tree)
313
- return createElement(Boundary, { resetKey: mounted.id }, createElement(Shown, { key: mounted.id, id: mounted.id }), tree)
335
+ return createElement(Boundary, { resetKey: mounted.id }, createElement(Shown, { key: mounted.id, id: mounted.id, commit: mounted.commit }), tree)
314
336
  }
315
337
 
316
338
  async function boot() {