@marver-design/marver 0.28.0 → 0.30.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 (105) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +4 -3
  3. package/dist/{anchor-check-PHUOFj1N.mjs → anchor-check-c52IDkiQ.mjs} +1 -1
  4. package/dist/{build-BsAyLMT1.mjs → build-C3mUtjEn.mjs} +7 -4
  5. package/dist/{capture-DdZ6xgoz.mjs → capture-DEtM4qm5.mjs} +168 -5
  6. package/dist/cli.mjs +11 -11
  7. package/dist/{comments-CrBHPEQl.mjs → comments-XNhMmSSu.mjs} +2 -2
  8. package/dist/{connectors-MR9d-EBP.mjs → connectors-DekQvKt9.mjs} +3 -1
  9. package/dist/{daemon-C5dg2R-V.mjs → daemon-B0Wi1OQ3.mjs} +30 -29
  10. package/dist/{dev-D7YS7iT2.mjs → dev-5dlxoW28.mjs} +19 -14
  11. package/dist/{init-WE5lQkQL.mjs → init-CYlFaRzG.mjs} +1 -1
  12. package/dist/logo-CXY-1yrn.mjs +305 -0
  13. package/dist/{ls-BZ5TAtd5.mjs → ls-NqmePKOf.mjs} +1 -1
  14. package/dist/{marks-Kmdab_5w.mjs → marks-BnNANic9.mjs} +20 -1
  15. package/dist/{marks-Dyn6tmjp.mjs → marks-DBp3h1Mc.mjs} +2 -5
  16. package/dist/{marver-id-gate-D-R0hSt_.mjs → marver-id-gate-vBLb_Icb.mjs} +1 -1
  17. package/dist/{perf-Cn5LiRaY.mjs → perf-6MOTHxay.mjs} +751 -122
  18. package/dist/perf-BCxAo0IS.mjs +1743 -0
  19. package/dist/{plugin-C_0yb-Fq.mjs → plugin-CXRoMA8g.mjs} +1382 -810
  20. package/dist/{poster-DHi6I1fO.mjs → poster-CYmCa00B.mjs} +1 -1
  21. package/dist/{profile-jIS6BcAs.mjs → profile-B1FKOM1e.mjs} +1 -1
  22. package/dist/{publish-bakes-r4PEZuPl.mjs → publish-bakes-C_2ZtHou.mjs} +3 -3
  23. package/dist/{queue-c-6aTHEz.mjs → queue-DeSQm24g.mjs} +29 -14
  24. package/dist/{recover-nrLEVLyJ.mjs → recover-XD8iXJOj.mjs} +2 -2
  25. package/dist/{serve-Dp3nHstu.mjs → serve-DQv3Ti6X.mjs} +8 -4
  26. package/dist/{session-DyVE7cCk.mjs → session-VDJfXEEm.mjs} +1 -1
  27. package/dist/{share-Ce4tP7ji.mjs → share-Bu_kuOKL.mjs} +1 -1
  28. package/dist/{shot-BrRtqaiS.mjs → shot-CRRGgxru.mjs} +3 -3
  29. package/dist/{slots-CFNnegCc.mjs → slots-Dn4Onb0V.mjs} +101 -3
  30. package/dist/{sync-CQdGARJ9.mjs → sync-CMozOwZ0.mjs} +1 -1
  31. package/docs/app.md +194 -0
  32. package/docs/boards-and-folders.md +11 -0
  33. package/docs/jam-session.md +12 -3
  34. package/docs/live-jam.md +3 -0
  35. package/docs/performance.md +99 -19
  36. package/docs/publish.md +7 -0
  37. package/package.json +1 -1
  38. package/src/client/frame-host/bridge.js +17 -8
  39. package/src/client/frame-host/inplace.ts +124 -0
  40. package/src/client/frame-host/inspect.d.ts +1 -0
  41. package/src/client/frame-host/inspect.js +13 -4
  42. package/src/client/frame-host/main.tsx +12 -3
  43. package/src/client/frame-host/messages.ts +85 -0
  44. package/src/client/frame-host/signals.d.ts +15 -0
  45. package/src/client/frame-host/signals.js +219 -0
  46. package/src/client/recorder-level.ts +41 -0
  47. package/src/client/shell/App.tsx +158 -88
  48. package/src/client/shell/BoardList.tsx +103 -48
  49. package/src/client/shell/Comments.tsx +71 -46
  50. package/src/client/shell/ContextMenu.tsx +8 -6
  51. package/src/client/shell/JamSurface.tsx +187 -71
  52. package/src/client/shell/LockedApp.tsx +19 -3
  53. package/src/client/shell/Play.tsx +110 -62
  54. package/src/client/shell/StatusPicker.tsx +19 -9
  55. package/src/client/shell/Toolbar.tsx +15 -7
  56. package/src/client/shell/api.ts +25 -7
  57. package/src/client/shell/app-bridge.ts +23 -9
  58. package/src/client/shell/app-perf.ts +31 -1
  59. package/src/client/shell/canvas/Canvas.tsx +17 -6
  60. package/src/client/shell/canvas/FrameNode.tsx +25 -12
  61. package/src/client/shell/canvas/Sticky.tsx +4 -2
  62. package/src/client/shell/canvas/ctl.ts +2 -0
  63. package/src/client/shell/canvas/ready-watch.ts +4 -0
  64. package/src/client/shell/canvas/sleep.ts +2 -0
  65. package/src/client/shell/canvas/updates.ts +13 -6
  66. package/src/client/shell/commands.ts +765 -0
  67. package/src/client/shell/comments-store.ts +56 -27
  68. package/src/client/shell/goto.ts +15 -9
  69. package/src/client/shell/jam-capture.ts +39 -15
  70. package/src/client/shell/jam-keys.ts +303 -111
  71. package/src/client/shell/jam-lane.tsx +19 -12
  72. package/src/client/shell/jam-lines.ts +10 -1
  73. package/src/client/shell/jam-panel.tsx +68 -53
  74. package/src/client/shell/jam-queue.ts +6 -1
  75. package/src/client/shell/jam-session.tsx +41 -37
  76. package/src/client/shell/jam-state.ts +28 -5
  77. package/src/client/shell/jam-surface-parts.tsx +8 -6
  78. package/src/client/shell/jam-ui.tsx +12 -5
  79. package/src/client/shell/jam-voice.ts +4 -2
  80. package/src/client/shell/live-picture.ts +134 -0
  81. package/src/client/shell/main.tsx +7 -1
  82. package/src/client/shell/marks-ui.tsx +11 -0
  83. package/src/client/shell/open-item.ts +83 -0
  84. package/src/client/shell/open-resolve.ts +50 -0
  85. package/src/client/shell/perf.ts +51 -5
  86. package/src/client/shell/recorder-core.ts +4 -1
  87. package/src/client/shell/recorder-hmr.ts +36 -0
  88. package/src/client/shell/recorder-reloads.ts +264 -0
  89. package/src/client/shell/recorder-seams.ts +116 -0
  90. package/src/client/shell/recorder-self.ts +73 -0
  91. package/src/client/shell/recorder-signals-core.ts +139 -0
  92. package/src/client/shell/recorder-signals.ts +485 -0
  93. package/src/client/shell/recorder.ts +115 -41
  94. package/src/client/shell/store.ts +62 -24
  95. package/src/client/shell/styles.css +2 -0
  96. package/src/client/shell/whiteout-probes.ts +3 -1
  97. package/src/client/stage/main.tsx +39 -12
  98. package/src/shared/app-api.ts +201 -9
  99. package/src/shared/app-perf.ts +103 -8
  100. package/src/shared/app-report.ts +586 -0
  101. package/src/shared/perf-records.ts +445 -0
  102. package/src/shared/perf-run.ts +6 -2
  103. package/templates/instructions/jam.md +4 -0
  104. package/dist/live-Cgzsicwi.mjs +0 -4
  105. package/dist/perf-jam-QxD_UnzN.mjs +0 -635
@@ -13,7 +13,8 @@ import { useEffect, useRef, useState, type CSSProperties } from 'react'
13
13
  import { setSessionEnding, useJamCapture } from './jam-capture.ts'
14
14
  import { laneCards, startCapture } from './jam-keys.ts'
15
15
  import { useJamQueue, type JamCard } from './jam-queue.ts'
16
- import { useJamUi } from './jam-state.ts'
16
+ import { endOnOk, useJamUi } from './jam-state.ts'
17
+ import { cmd, endAfterFrames, keysOf, type CmdHandle, type CmdOpts } from './commands.ts'
17
18
  import { JamStateIcon } from './jam-ui.tsx'
18
19
  import { Marver, moreDraftOf, setMoreDraft } from './jam-panel.tsx'
19
20
  import { useJamVoice, voiceSession, voiceSessionEnd, voiceSessionId } from './jam-voice.ts'
@@ -26,6 +27,7 @@ import { api, STOPPED_TIP, useStopped } from './api.ts'
26
27
 
27
28
  const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
28
29
  const now = () => performance.timeOrigin + performance.now()
30
+ const CLICK: CmdOpts = { via: 'click', in: 'shell' }
29
31
 
30
32
  // ---- the session's moves -------------------------------------------------------------------------------
31
33
 
@@ -110,11 +112,11 @@ let endingOp = 0
110
112
 
111
113
 
112
114
  /** `J` (or the Jam button): at rest, the start sheet (again: closes it); in a session, the wrap-up - a
113
- * capture recording ends first, and the wrap-up waits for its read-back to close. */
114
- export function pressJ() {
115
+ * capture recording ends first, and the wrap-up waits for its read-back to close. `h`: its `jam-session`, from the input. */
116
+ export function pressJ(h: CmdHandle) {
115
117
  const ui = useJamUi.getState()
116
118
  // the canvas stopped (spec 28 A1.11): a sheet open still closes; nothing new starts or wraps up
117
- if (!ui.sheet && stoppedFor('Jam needs the canvas running')) return
119
+ if (!ui.sheet && stoppedFor('Jam needs the canvas running')) { h.noop('stopped'); return }
118
120
  if (!useJamQueue.getState().session) { ui.setSheet(ui.sheet === 'start' ? null : 'start'); return }
119
121
  if (ui.sheet === 'wrap' || ui.sheet === 'wrap-pending') { ui.setSheet(null); return }
120
122
  if (useJamCapture.getState().current) { useJamCapture.getState().end(true); ui.setSheet('wrap-pending'); return }
@@ -142,7 +144,7 @@ export function JamButton({ inPlay }: { inPlay?: boolean }) {
142
144
  return (
143
145
  <Tip side="bottom" inv={inPlay} label={label}>
144
146
  <button className={`sh-pill-btn jm-jam${state !== 'idle' ? ` ${state}` : ''}${sheet === 'start' || sheet === 'wrap' ? ' press' : ''}${stopped ? ' off' : ''}`}
145
- data-jam-button={state} data-stopped={stopped ? '' : undefined} aria-disabled={stopped || undefined} aria-label={session ? 'End the Jam session' : 'Jam session'} onClick={pressJ}>
147
+ data-jam-button={state} data-stopped={stopped ? '' : undefined} aria-disabled={stopped || undefined} aria-label={session ? 'End the Jam session' : 'Jam session'} onClick={() => pressJ(cmd('jam-session', { via: 'click', in: 'pill' }))}>
146
148
  {/* the whole session reads as on: the dot pulses from start to end, between captures too */}
147
149
  {session || recording ? <i className="jm-live-dot" /> : <WaveformIcon size={16} />}
148
150
  {session && <span className="jm-clock">{minutes}</span>}
@@ -201,7 +203,8 @@ function WhoWorks({ fallback }: { fallback: string }) {
201
203
  const next = sessions.length > 1 ? sessions[(sessions.findIndex((x) => x.selected) + 1) % sessions.length] : undefined
202
204
  // the Codex hint only for someone who is not working in another session now: it is noise to a Claude Code user
203
205
  const trust = !sel && info?.connectors?.some((c) => c.agent === 'codex' && c.state === 'installed') && !sessions.some((x) => x.agent === 'codex')
204
- const set = useJamQueue.getState().setPrefs
206
+ // a switch's name, never its value; the command ends on the save's answer
207
+ const set = (arg: string, p: Parameters<ReturnType<typeof useJamQueue.getState>['setPrefs']>[0]) => void endOnOk(cmd('jam-pref', { ...CLICK, arg }), useJamQueue.getState().setPrefs(p), 'api')
205
208
  const sw = (on: boolean) => <span className="v">{on ? 'On' : 'Off'}<i className={`jm-switch${on ? ' on' : ''}`} /></span>
206
209
  return (<>
207
210
  {(() => {
@@ -211,16 +214,16 @@ function WhoWorks({ fallback }: { fallback: string }) {
211
214
  {sel && <span className="v"><span className="jm-agent"><i /></span></span>}
212
215
  </>)
213
216
  return next
214
- ? <button className="row jm-two" data-jam-who={sel ? sel.agent : 'background'} onClick={() => void set({ pick: next.id })}>{body}</button>
217
+ ? <button className="row jm-two" data-jam-who={sel ? sel.agent : 'background'} onClick={() => set('agent', { pick: next.id })}>{body}</button>
215
218
  : <div className="row jm-two" data-jam-who={sel ? sel.agent : 'background'}>{body}</div>
216
219
  })()}
217
- <button className="row jm-two" data-jam-switch="mcp" onClick={() => void set({ mcp: !settings.mcp, skills: !settings.mcp })}>
220
+ <button className="row jm-two" data-jam-switch="mcp" onClick={() => set('mcp', { mcp: !settings.mcp, skills: !settings.mcp })}>
218
221
  <LinkIcon size={15} /><span>MCP servers and skills<br /><small>Background runs use yours</small></span>{sw(settings.mcp)}
219
222
  </button>
220
- <button className="row jm-two" data-jam-switch="context" onClick={() => void set({ context: context ? 'fresh' : 'fork' })}>
223
+ <button className="row jm-two" data-jam-switch="context" onClick={() => set('context', { context: context ? 'fresh' : 'fork' })}>
221
224
  <NotebookIcon size={15} /><span>Your session's context<br /><small>Your session or a copy works</small></span>{sw(context)}
222
225
  </button>
223
- <button className="row jm-two" data-jam-switch="others" onClick={() => void set({ others: !settings.others })}>
226
+ <button className="row jm-two" data-jam-switch="others" onClick={() => set('collaborators', { others: !settings.others })}>
224
227
  <CommentIcon size={15} /><span>Collaborators' comments<br /><small>Their words reach the agent</small></span>{sw(settings.others)}
225
228
  </button>
226
229
  {trust && <div className="note-line" style={{ margin: '4px 8px' }}><WarningIcon size={14} /><span>Codex runs go to a copy of your session. To let your open Codex session take them itself, type <code style={{ color: 'inherit' }}>/hooks</code> in Codex once and trust Marver's.</span></div>}
@@ -239,7 +242,7 @@ export function StartSheet({ style }: { style?: CSSProperties }) {
239
242
  <p>Start captures at once. Between captures the session stays on; S captures again, J wraps up.</p>
240
243
  </div>
241
244
  <div className="rows">
242
- <button className="row" data-jam-mic-switch={mic ? 'on' : 'off'} onClick={() => voice.setChoice(mic ? 'no' : 'yes')}>
245
+ <button className="row" data-jam-mic-switch={mic ? 'on' : 'off'} onClick={() => { const h = cmd('jam-pref', { ...CLICK, arg: 'mic' }); void voice.setChoice(mic ? 'no' : 'yes'); h.done() }}>
243
246
  {mic ? <MicrophoneIcon size={15} /> : <MicrophoneSlashIcon size={15} />}
244
247
  <span>Microphone<br /><small>Transcribed on this Mac{CONFIG.jam?.names ? ' · Claude Haiku names each capture from its words, sent to Anthropic' : ''}</small></span>
245
248
  <span className="v">{mic ? 'On' : 'Off'}<i className={`jm-switch${mic ? ' on' : ''}`} /></span>
@@ -251,8 +254,8 @@ export function StartSheet({ style }: { style?: CSSProperties }) {
251
254
  <ShortcutsRow />
252
255
  <div className="actions">
253
256
  <span className="sp" />
254
- <button className="jm-btn ghost" onClick={() => useJamUi.getState().setSheet(null)}>Not now</button>
255
- <button className="jm-btn primary" onClick={() => void startSession()}>Start <kbd>⏎</kbd></button>
257
+ <button className="jm-btn ghost" onClick={() => { cmd('jam-sheet-close', CLICK); useJamUi.getState().setSheet(null) }}>Not now</button>
258
+ <button className="jm-btn primary" onClick={() => void endOnOk(cmd('jam-start', CLICK), startSession())}>Start <kbd>⏎</kbd></button>
256
259
  </div>
257
260
  </div>
258
261
  )
@@ -260,8 +263,8 @@ export function StartSheet({ style }: { style?: CSSProperties }) {
260
263
 
261
264
  // ---- the wrap-up ----------------------------------------------------------------------------------------------
262
265
 
263
- /** The open wrap-up sheet's Write the record (the key row calls it). */
264
- export const wrapWrite: { current: (() => void) | null } = { current: null }
266
+ /** The open wrap-up sheet's Write the record (the key row calls it, with its `jam-wrap-send`). */
267
+ export const wrapWrite: { current: ((h: CmdHandle) => void) | null } = { current: null }
265
268
 
266
269
  const STATE_NOTE: Partial<Record<JamCard['state'], string>> = {
267
270
  draft: 'to confirm', confirming: 'sending', queued: 'queued', working: 'with the agent', asks: 'asks you', review: 'to review',
@@ -294,15 +297,15 @@ export function WrapSheet({ style }: { style?: CSSProperties }) {
294
297
  const caps = laneCards(cards, run).filter((c) => c.kind === 'capture' && c.session === session.id && c.state !== 'dropped')
295
298
  const name = agent ? HARNESS[agent] ?? agent : 'your agent'
296
299
  // Write is busy until the server answers THIS try (an older try's late end never frees it)
297
- const write = async () => {
298
- if (busy) return
300
+ const write = async (h: CmdHandle) => {
301
+ if (busy) { h.noop('busy'); return }
299
302
  const n = ++tries.current
300
303
  setBusy(true)
301
- await endSession({ instructions: text.trim(), includeTalk: talk }, () => { if (n === tries.current) setBusy(false) })
304
+ await endOnOk(h, endSession({ instructions: text.trim(), includeTalk: talk }, () => { if (n === tries.current) setBusy(false) }))
302
305
  if (n === tries.current) setBusy(false)
303
306
  }
304
307
  // ⏎ anywhere in the sheet writes the record - it never reaches a panel beneath it (jam-keys' sheet row)
305
- wrapWrite.current = () => void write()
308
+ wrapWrite.current = (h) => void write(h)
306
309
  const summary = caps.length
307
310
  ? `${caps.length} capture${caps.length === 1 ? '' : 's'} in ${minutes} min.`
308
311
  : `No captures in ${minutes} min.`
@@ -329,12 +332,12 @@ export function WrapSheet({ style }: { style?: CSSProperties }) {
329
332
  onKeyDown={(e) => {
330
333
  e.stopPropagation()
331
334
  if ((e.nativeEvent as unknown as { isComposing?: boolean }).isComposing) return
332
- if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); void write() }
333
- else if (e.key === 'Escape') { e.preventDefault(); useJamUi.getState().setSheet(null) }
335
+ if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); void write(cmd('jam-wrap-send', { via: 'key', in: 'shell', keys: keysOf(e) })) }
336
+ else if (e.key === 'Escape') { e.preventDefault(); cmd('jam-sheet-close', { via: 'key', in: 'shell', keys: keysOf(e) }); useJamUi.getState().setSheet(null) }
334
337
  }} />
335
338
  </div>
336
339
  <div className="rows">
337
- <button className="row" data-jam-talk={talk ? 'on' : 'off'} onClick={() => setTalk(!talk)}>
340
+ <button className="row" data-jam-talk={talk ? 'on' : 'off'} onClick={() => { cmd('jam-talk', CLICK); setTalk(!talk) }}>
338
341
  <span>Include what was said between captures</span>
339
342
  <span className="v">{talkMin ? <small>{talkMin} min</small> : null}<i className={`jm-switch${talk ? ' on' : ''}`} /></span>
340
343
  </button>
@@ -343,9 +346,9 @@ export function WrapSheet({ style }: { style?: CSSProperties }) {
343
346
  {name} reads your instructions, every capture you sent or kept with its reply, and your verdicts{talk ? ', and what was said between captures' : ''}. It writes one page{folder ? <> in <code>{folder}</code></> : null} and nothing else.
344
347
  </p>
345
348
  <div className="actions">
346
- <button className="jm-btn ghost" onClick={() => void endSession(null)}>End without a record</button>
349
+ <button className="jm-btn ghost" onClick={() => void endOnOk(cmd('jam-end-bare', CLICK), endSession(null))}>End without a record</button>
347
350
  <span className="sp" />
348
- <button className="jm-btn primary" disabled={busy} onClick={() => void write()}>Write the record <kbd>⏎</kbd></button>
351
+ <button className="jm-btn primary" disabled={busy} onClick={() => void write(cmd('jam-wrap-send', CLICK))}>Write the record <kbd>⏎</kbd></button>
349
352
  </div>
350
353
  </div>
351
354
  )
@@ -356,9 +359,10 @@ export function WrapSheet({ style }: { style?: CSSProperties }) {
356
359
  /** A session record (a wrap-up card): the page the agent wrote, its reply, and the review's moves. */
357
360
  export function RecordDetail({ card, agent, more, onMore, onMoreOpen, onGood, onLater, onRetry, onDrop, of, onPrev, onNext }: {
358
361
  card: JamCard; agent: string; more: boolean; of?: [number, number]
359
- onMore(text: string): void; onMoreOpen(on: boolean): void; onGood(): void; onLater(): void
362
+ /** each ends the command its button started (spec 30), from the handle it is handed */
363
+ onMore(text: string, h: CmdHandle): void; onMoreOpen(on: boolean): void; onGood(h: CmdHandle): void; onLater(h: CmdHandle): void
360
364
  /** a record job that failed: try it again, or let it go */
361
- onRetry(): void; onDrop(): void
365
+ onRetry(h: CmdHandle): void; onDrop(h: CmdHandle): void
362
366
  onPrev?: () => void; onNext?: () => void
363
367
  }) {
364
368
  const [rec, setRec] = useState<{ file: string; text: string | null; reply?: string } | null>(null)
@@ -384,8 +388,8 @@ export function RecordDetail({ card, agent, more, onMore, onMoreOpen, onGood, on
384
388
  <JamStateIcon state={card.state as any} />
385
389
  <h3>{card.title ?? 'Session record'}</h3>
386
390
  {of && <><span className="dim">{of[0]} of {of[1]}</span>
387
- <button className="jm-iconbtn" disabled={!onPrev} onClick={onPrev} aria-label="Previous"><CaretIcon size={11} style={{ transform: 'rotate(90deg)' }} /></button>
388
- <button className="jm-iconbtn" disabled={!onNext} onClick={onNext} aria-label="Next"><CaretIcon size={11} style={{ transform: 'rotate(-90deg)' }} /></button></>}
391
+ <button className="jm-iconbtn" disabled={!onPrev} onClick={() => { cmd('jam-step', { ...CLICK, arg: 'prev' }); onPrev?.() }} aria-label="Previous"><CaretIcon size={11} style={{ transform: 'rotate(90deg)' }} /></button>
392
+ <button className="jm-iconbtn" disabled={!onNext} onClick={() => { cmd('jam-step', { ...CLICK, arg: 'next' }); onNext?.() }} aria-label="Next"><CaretIcon size={11} style={{ transform: 'rotate(-90deg)' }} /></button></>}
389
393
  </div>
390
394
  <div className="meta"><span><code>{rec?.file ?? card.file ?? 'context/sessions/'}</code></span><i /><span>{agent}</span></div>
391
395
  {rec?.reply && <div className="jm-reply"><Marver size={20} /><p>{rec.reply}</p></div>}
@@ -397,8 +401,8 @@ export function RecordDetail({ card, agent, more, onMore, onMoreOpen, onGood, on
397
401
  {failed && <div className="rule" />}
398
402
  {failed && (
399
403
  <div className="actions">
400
- <button className="jm-btn primary" onClick={onRetry}>Retry</button>
401
- <button className="jm-btn ghost" onClick={onDrop}>Drop</button>
404
+ <button className="jm-btn primary" data-jam-run-act="retry" onClick={() => onRetry(cmd('jam-retry', CLICK))}>Retry</button>
405
+ <button className="jm-btn ghost" data-jam-run-act="drop" onClick={() => onDrop(cmd('jam-drop', CLICK))}>Drop</button>
402
406
  </div>
403
407
  )}
404
408
  {review && <div className="rule" />}
@@ -409,16 +413,16 @@ export function RecordDetail({ card, agent, more, onMore, onMoreOpen, onGood, on
409
413
  onKeyDown={(e) => {
410
414
  e.stopPropagation()
411
415
  if ((e.nativeEvent as unknown as { isComposing?: boolean }).isComposing) return
412
- if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); if (note.trim()) onMore(note.trim()) }
413
- if (e.key === 'Escape') { e.preventDefault(); setNote(''); onMoreOpen(false) }
416
+ if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); if (note.trim()) onMore(note.trim(), cmd('jam-more-send', { via: 'key', in: 'shell', keys: keysOf(e) })) }
417
+ if (e.key === 'Escape') { e.preventDefault(); cmd('jam-field-discard', { via: 'key', in: 'shell', keys: keysOf(e), arg: 'more' }); setNote(''); onMoreOpen(false) }
414
418
  }} />
415
- <button className="jm-send" disabled={!note.trim()} onClick={() => onMore(note.trim())}>Send <kbd>⏎</kbd></button>
419
+ <button className="jm-send" disabled={!note.trim()} onClick={() => onMore(note.trim(), cmd('jam-more-send', CLICK))}>Send <kbd>⏎</kbd></button>
416
420
  </div>
417
421
  ) : (
418
422
  <div className="actions">
419
- <button className="jm-btn primary" onClick={onGood}>Looks good <kbd>⏎</kbd></button>
420
- <button className="jm-btn" onClick={() => onMoreOpen(true)}>More work <kbd>⇧⏎</kbd></button>
421
- <button className="jm-btn ghost" onClick={onLater}>Later <kbd>→</kbd></button>
423
+ <button className="jm-btn primary" onClick={() => onGood(cmd('jam-good', CLICK))}>Looks good <kbd>⏎</kbd></button>
424
+ <button className="jm-btn" onClick={() => { const h = cmd('jam-more', CLICK); onMoreOpen(true); endAfterFrames(h) }}>More work <kbd>⇧⏎</kbd></button>
425
+ <button className="jm-btn ghost" onClick={() => onLater(cmd('jam-later', CLICK))}>Later <kbd>→</kbd></button>
422
426
  </div>
423
427
  ))}
424
428
  </div>
@@ -435,7 +439,7 @@ export function PlayCounter({ cards, style }: { cards: JamCard[]; style?: CSSPro
435
439
  const settled = cards.filter((c) => c.state === 'done' || c.state === 'kept').length
436
440
  if (!pairs.length && !settled) return null
437
441
  return (
438
- <div className="jm-count jm-stage" data-jam-counter="" style={style} onClick={() => useJamUi.getState().setLaneKeys(true)}>
442
+ <div className="jm-count jm-stage" data-jam-counter="" style={style} onClick={() => { const h = cmd('jam-lane', CLICK); useJamUi.getState().setLaneKeys(true); endAfterFrames(h) }}>
439
443
  {pairs.map(([s, k]) => <span key={s}><JamStateIcon state={s as any} size={13} />{k}</span>)}
440
444
  {settled > 0 && <span key="done"><JamStateIcon state="done" size={13} />{settled}</span>}
441
445
  <i className="sep" /><span className="q">Q</span>
@@ -1,10 +1,13 @@
1
1
  /**
2
2
  * Where Jam's surfaces stand in the shell (spec 27): the one focus panel (a capture's detail, a
3
- * review, a wrap-up), the lane's selection and its keyboard (`Q`), the review's picture view.
3
+ * review, a wrap-up, a thread), the lane's selection and its keyboard (`Q`), the review's picture view.
4
4
  */
5
5
  import { create } from 'zustand'
6
+ import { cmd, type CmdHandle, type CmdOpts } from './commands.ts'
6
7
 
7
- export type Panel = { kind: 'capture' | 'review' | 'wrapup'; id: string } | null
8
+ /** The focus panel. `thread` (spec 28 A4.6 #30, r1 #3): a thread no frame on its board can show - frameless, its
9
+ * frame gone, resolved - opened where it can be read and answered; `id` is the thread's, on `board`. */
10
+ export type Panel = { kind: 'capture' | 'review' | 'wrapup'; id: string } | { kind: 'thread'; id: string; board: string } | null
8
11
 
9
12
  interface JamUi {
10
13
  panel: Panel
@@ -36,13 +39,22 @@ interface JamUi {
36
39
  setTab(i: number): void
37
40
  setMoreOpen(on: boolean): void
38
41
  follow(): void
42
+ /** a card's status icon asked to open its popover once (A4.6 #30): the first `TagStatus` drawing that card takes it */
43
+ statusFor: { card: string; n: number } | null
44
+ askStatus(card: string | null): void
45
+ /** the status icon of the request `n` opened: it is taken */
46
+ tookStatus(n: number): void
39
47
  }
40
48
 
49
+ let asked = 0
41
50
  export const useJamUi = create<JamUi>((set, get) => ({
42
- panel: null, selected: null, laneKeys: false, view: 'both', tab: 0, moreOpen: false, followEnd: 0, sheet: null, doneOpen: false,
51
+ panel: null, selected: null, laneKeys: false, view: 'both', tab: 0, moreOpen: false, followEnd: 0, sheet: null, doneOpen: false, statusFor: null,
52
+ askStatus(card) { set({ statusFor: card ? { card, n: ++asked } : null }) },
53
+ tookStatus(n) { if (get().statusFor?.n === n) set({ statusFor: null }) },
43
54
  setSheet(s) { set({ sheet: s }) },
44
55
  // 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 }) },
56
+ // a thread panel names a thread, never a tile: the lane's selection stays
57
+ open(panel) { set({ panel, selected: panel && panel.kind !== 'thread' ? panel.id : get().selected, view: 'both', tab: 0, moreOpen: false }) },
46
58
  close() { set({ panel: null, moreOpen: false }) },
47
59
  setLaneKeys(on) { set({ laneKeys: on }) },
48
60
  // folding: a done tile that was selected hands its selection to the group
@@ -68,14 +80,25 @@ export const useJamUi = create<JamUi>((set, get) => ({
68
80
  * closes, its tile lets go, and the lane gives the keys back (trial 1: "anywhere on the canvas should
69
81
  * close the review card and deselect the capture card"). Words being edited in the read-back save first:
70
82
  * the field is left before the panel goes. */
71
- export function letGoOfTile() {
83
+ export function letGoOfTile(from?: Pick<CmdOpts, 'via' | 'in'>) {
72
84
  const s = useJamUi.getState()
73
85
  if (!s.panel && !s.selected && !s.laneKeys) return
86
+ // an input's press: it changed something, so it is a `jam-close` (R12's silence: the return above writes nothing)
87
+ if (from) cmd('jam-close', from)
74
88
  const a = document.activeElement
75
89
  if (a instanceof HTMLElement && a.closest('.jm-focus')) a.blur()
76
90
  useJamUi.setState({ panel: null, moreOpen: false, selected: null, laneKeys: false })
77
91
  }
78
92
 
93
+ /** A command whose work answers a boolean - `act`, `runAct`, a session's move, a tile's surface drawn (spec 30): true ends
94
+ * it `done`; false, or a rejection, `failed` with `code`. Hands the answer on (a rejection reads false). */
95
+ export const endOnOk = (h: CmdHandle, answer: Promise<boolean>, code = 'refused'): Promise<boolean> =>
96
+ answer.then((ok) => { if (ok) h.done(); else h.fail(code); return ok }, () => { h.fail(code); return false })
97
+
98
+ /** What JamSurface lends the helpers that open things (jam-keys.ts): a tile's menu opened at the tile, as a right-click
99
+ * opens it (spec 28 A4.6 #30) - false when the tile is not drawn. */
100
+ export const jamSurface = { tileMenu: (_id: string): boolean => false }
101
+
79
102
  if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) (window as any).__mvJamUi = useJamUi
80
103
 
81
104
  // ---- the Done fold (0.26.1): two or more done tiles fold into one, at the lane's left end ------------------
@@ -8,9 +8,10 @@ import { Lane, type LaneBetween, type LaneRecording, type LaneTile } from './jam
8
8
  import { Caption, FocusPanel, NotesCard, ReadBack, ReviewDetail, VoiceAsk } from './jam-panel.tsx'
9
9
  import type { TimelineLine } from './jam-lines.ts'
10
10
  import type { JamCard } from './jam-queue.ts'
11
+ import { cmd, type CmdHandle } from './commands.ts'
11
12
 
12
13
  export function CaptureLaneRow({ tiles, recording, between, selected, keyboard, followEnd, onOpen, onMenu, notes, ask, caption, doneOpen, onDoneOpen }: {
13
- tiles: LaneTile[]; recording?: LaneRecording; between?: LaneBetween; selected?: string; keyboard?: boolean; followEnd?: number; onOpen(id: string): void
14
+ tiles: LaneTile[]; recording?: LaneRecording; between?: LaneBetween; selected?: string; keyboard?: boolean; followEnd?: number; onOpen(id: string, h: CmdHandle): void
14
15
  doneOpen?: boolean; onDoneOpen?(open: boolean, doneIds: string[]): void
15
16
  onMenu?(e: React.MouseEvent, id: string): void
16
17
  notes?: { notes: { t: string; text: string }[]; draft: string; onDraft(t: string): void; onAdd(): void; onClose(): void }
@@ -62,9 +63,10 @@ export function FocusPanelView(p: {
62
63
  shots: { frame: string; before?: string; after?: string; new?: boolean }[]; reply: string
63
64
  view: 'both' | 'before' | 'after'; tab: number; moreOpen: boolean
64
65
  onTab(i: number): void; onFlip(view: 'both' | 'before' | 'after'): void; onMoreOpen(on: boolean): void; onClose(): void
65
- onEdit(text: string): void; onConfirm(): void; onKeep(): void; onDrop(): void; onResume?: () => void
66
- onGood(): void; onMore(text: string): void; onLater(): void; onOpenThread(): void
67
- onPrev?: () => void; onNext?: () => void; pending?: string; onRetry?: () => void; locked?: boolean
66
+ /** each ends the command its button started (spec 30), from the handle it is handed */
67
+ onEdit(text: string, h: CmdHandle): void; onConfirm(h: CmdHandle): void; onKeep(h: CmdHandle): void; onDrop(h: CmdHandle): void; onResume?: (h: CmdHandle) => void
68
+ onGood(h: CmdHandle): void; onMore(text: string, h: CmdHandle): void; onLater(h: CmdHandle): void; onOpenThread(h: CmdHandle): void
69
+ onPrev?: () => void; onNext?: () => void; pending?: string; onRetry?: (h: CmdHandle) => void; locked?: boolean
68
70
  /** a note added in the read-back (a draft) */
69
71
  onAddNote?(text: string, id: string): Promise<boolean>
70
72
  /** a card that asks, opened here (its thread cannot show on this board): its question and your answer */
@@ -81,7 +83,7 @@ export function FocusPanelView(p: {
81
83
  const [fit, setFit] = useState<number | undefined>(undefined)
82
84
  const head = p.kind === 'review' ? (
83
85
  <div className="jm-ftabs jm-panes" role="tablist" data-jam-panes="">
84
- {(['review', 'capture'] as const).map((v) => <button key={v} role="tab" aria-selected={v === pane} className={v === pane ? 'on' : undefined} onClick={() => setPane(v)}>{v === 'review' ? 'Review' : 'Capture'}</button>)}
86
+ {(['review', 'capture'] as const).map((v) => <button key={v} role="tab" aria-selected={v === pane} className={v === pane ? 'on' : undefined} onClick={() => { cmd('jam-pane', { via: 'click', in: 'shell', arg: v }); setPane(v) }}>{v === 'review' ? 'Review' : 'Capture'}</button>)}
85
87
  </div>
86
88
  ) : undefined
87
89
  // points are picks and clicks (a picture line carries its own number, not a point)
@@ -94,7 +96,7 @@ export function FocusPanelView(p: {
94
96
  <FocusPanel left={p.left} onClose={p.onClose} width={p.kind === 'review' && pane === 'review' ? fit : undefined}>
95
97
  {p.kind === 'review' && pane === 'review' ? (
96
98
  <ReviewDetail key={c.id} title={title} head={head} of={p.of} onPrev={p.onPrev} onNext={p.onNext} frames={p.shots.map((s) => s.frame)} active={p.tab} onTab={p.onTab}
97
- view={p.view} onFlip={(v) => p.onFlip(v)} onFit={setFit} reply={p.reply} shots={p.shots} agent={p.agent}
99
+ view={p.view} onFlip={p.onFlip} onFit={setFit} reply={p.reply} shots={p.shots} agent={p.agent}
98
100
  more={p.moreOpen} draftKey={c.id} onMore={p.onMore} onMoreOpen={p.onMoreOpen} onGood={p.onGood} onLater={p.onLater} onOpenThread={p.onOpenThread} />
99
101
  ) : (
100
102
  <ReadBack key={c.id} title={title} head={head} of={p.of} onPrev={p.onPrev} onNext={p.onNext} meta={meta} lines={p.lines} pictures={p.pictures} edited={c.edited} pending={p.pending}
@@ -11,6 +11,10 @@ import { useEffect, useId, useLayoutEffect, useRef, useState, type ReactNode } f
11
11
  import { Tip } from './Tip.tsx'
12
12
  import { cardForEvent, useJamQueue, type JamCardState } from './jam-queue.ts'
13
13
  import { statusLines } from './jam-lines.ts'
14
+ import { endOnOk, useJamUi } from './jam-state.ts'
15
+ import { cmd, type CmdOpts } from './commands.ts'
16
+
17
+ const CLICK: CmdOpts = { via: 'click', in: 'shell' }
14
18
 
15
19
  const GRAY = 'var(--glass-ink-3)'
16
20
  const RED = '#e5484d' // board-icons.tsx RED - errors and failures only
@@ -66,11 +70,14 @@ export function TagStatus({ board, eventId, harness }: { board?: string; eventId
66
70
  }, [card?.state])
67
71
  useEffect(() => {
68
72
  if (!open) return
69
- const away = (e: PointerEvent) => { if (!ref.current?.contains(e.target as Node)) setOpen(false) }
73
+ const away = (e: PointerEvent) => { if (!ref.current?.contains(e.target as Node)) { cmd('jam-status-close', CLICK); setOpen(false) } }
70
74
  window.addEventListener('pointerdown', away, true)
71
75
  return () => window.removeEventListener('pointerdown', away, true)
72
76
  }, [open])
73
77
  useEffect(() => { if (!card) setOpen(false) }, [card])
78
+ // asked to open once (a notice's click, A4.6 #30): this card's icon, wherever it is drawn first - its run's controls on the page
79
+ const asked = useJamUi((s) => (card && s.statusFor?.card === card.id ? s.statusFor.n : 0))
80
+ useEffect(() => { if (asked) { setOpen(true); useJamUi.getState().tookStatus(asked) } }, [asked])
74
81
  // the open detail stays on screen: it sits under the icon and slides left at the viewport's edge
75
82
  const popRef = useRef<HTMLSpanElement>(null)
76
83
  useLayoutEffect(() => {
@@ -89,18 +96,18 @@ export function TagStatus({ board, eventId, harness }: { board?: string; eventId
89
96
  return (
90
97
  <span className={`cm-tstat${open ? ' on' : ''}`} ref={ref} data-jam-card={card.id} data-jam-state={card.state}>
91
98
  {open ? (
92
- <button className="cm-tstat-btn" aria-expanded aria-label={head} onClick={() => setOpen(false)}><JamStateIcon state={card.state} size={13} /></button>
99
+ <button className="cm-tstat-btn" aria-expanded aria-label={head} onClick={() => { cmd('jam-status-close', CLICK); setOpen(false) }}><JamStateIcon state={card.state} size={13} /></button>
93
100
  ) : (
94
101
  <Tip side="top" label={lines}>
95
- <button className="cm-tstat-btn" aria-label={head} onClick={() => setOpen(true)}><JamStateIcon state={card.state} size={13} /></button>
102
+ <button className="cm-tstat-btn" aria-label={head} onClick={() => { cmd('jam-status-open', CLICK); setOpen(true) }}><JamStateIcon state={card.state} size={13} /></button>
96
103
  </Tip>
97
104
  )}
98
105
  {open && (
99
106
  <span className={`cm-tstat-pop${stalled ? ' many' : ''}`} role="dialog" aria-label={head} ref={popRef}>
100
107
  {lines}
101
- {move && <button className="cm-tstat-act" onClick={() => { void useJamQueue.getState().act(card, move); setOpen(false) }}>{move === 'drop' ? 'Drop' : 'Retry'}</button>}
108
+ {move && <button className="cm-tstat-act" onClick={() => { void endOnOk(cmd('jam-status-act', { ...CLICK, arg: move }), useJamQueue.getState().act(card, move)); setOpen(false) }}>{move === 'drop' ? 'Drop' : 'Retry'}</button>}
102
109
  {stalled && ([['again', 'Give it back'], ['background', 'Run in the background'], ['drop', 'Drop it']] as const).map(([a, label]) => (
103
- <button key={a} className="cm-tstat-act" data-jam-run-act={a} onClick={() => { void useJamQueue.getState().runAct(card, a); setOpen(false) }}>{label}</button>
110
+ <button key={a} className="cm-tstat-act" data-jam-run-act={a} onClick={() => { void endOnOk(cmd('jam-status-act', { ...CLICK, arg: a }), useJamQueue.getState().runAct(card, a)); setOpen(false) }}>{label}</button>
104
111
  ))}
105
112
  </span>
106
113
  )}
@@ -50,7 +50,8 @@ interface VoiceStore {
50
50
  denied: boolean
51
51
  /** words heard so far, by capture - the live caption */
52
52
  heard: Record<string, Heard[]>
53
- setChoice(c: 'yes' | 'no'): void
53
+ /** resolves once a yes's engine answered (a no at once): what `jam-voice` ends on (spec 30) */
54
+ setChoice(c: 'yes' | 'no'): Promise<void>
54
55
  refresh(): Promise<void>
55
56
  /** try the engine again (it failed to start before) and refresh */
56
57
  retry(): Promise<void>
@@ -66,7 +67,8 @@ export const useJamVoice = create<VoiceStore>((set, get) => ({
66
67
  // no: an opening is cancelled, an open microphone is cut now - the words said so far are kept
67
68
  if (c === 'no') void reconcile()
68
69
  // yes: an engine that failed to start is tried again, then the microphone opens for what runs now
69
- if (c === 'yes') void get().retry().then(() => { if (get().server === 'ready' || get().server === 'loading') set({ asking: false }); void reconcile() })
70
+ if (c === 'yes') return get().retry().then(() => { if (get().server === 'ready' || get().server === 'loading') set({ asking: false }); void reconcile() })
71
+ return Promise.resolve()
70
72
  },
71
73
  async refresh() {
72
74
  try {
@@ -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
+ }
@@ -1,8 +1,11 @@
1
+ import { Profiler } from 'react'
1
2
  import { createRoot } from 'react-dom/client'
2
3
  // an all-boards-locked build gives LockedApp.tsx in App.tsx's place: what only the canvas uses comes through it
3
4
  import { App, ShellBoundary, startPerfRunProbe } from './App.tsx'
4
5
  import { useStore } from './store.ts'
5
6
  import { startRecorder } from './recorder.ts'
7
+ import { shellRendered } from './recorder-signals.ts'
8
+ import { fullRecorder } from '../recorder-level.ts'
6
9
  import { capturesPending, sealOnLeave } from './jam-capture.ts'
7
10
  import { startAppBridge } from './app-bridge.ts'
8
11
  import { startAppPerf } from './app-perf.ts'
@@ -23,4 +26,7 @@ startAppPerf()
23
26
  // a headless perf run (spec 28 A3.8 #17): what its driver reads and asks, through CDP - nothing without ?mvperfrun
24
27
  startPerfRunProbe()
25
28
 
26
- createRoot(document.getElementById('root')!).render(<ShellBoundary><App /></ShellBoundary>)
29
+ const app = <ShellBoundary><App /></ShellBoundary>
30
+ // the recorder's minute of this root's commits (spec 30 #36): dev only, at the full level - it counts nothing until the
31
+ // recorder runs, and `core` (the cost proof's other side, #58) has no Profiler at all
32
+ createRoot(document.getElementById('root')!).render(import.meta.env.DEV && fullRecorder() ? <Profiler id="shell" onRender={shellRendered}>{app}</Profiler> : app)
@@ -9,6 +9,17 @@ import { create } from 'zustand'
9
9
  import { useStore, PUBLISHED, shownRev } from './store.ts'
10
10
  import { useComments } from './comments-store.ts'
11
11
  import { frameMark, isNew, questions, type Ask, type FrameMark } from '../../shared/marks.ts'
12
+ import { cmd, endOnAnswer, type CmdOpts } from './commands.ts'
13
+
14
+ /** Mark all as seen (spec 30): `mark-seen` ends on the marks write's answer - the sidebar's, or the relay from the
15
+ * tab's menu (#51). Nothing new to clear is a noop: no write goes. */
16
+ export function markSeenFrom(how: CmdOpts, frames: string[]): void {
17
+ const s = useStore.getState(), m = s.marks
18
+ const h = cmd('mark-seen', { ...how, frames: frames.length })
19
+ if (!m || !frames.some((id) => isNew(m, id))) { h.noop('nothing-new'); return }
20
+ endOnAnswer(h, 'marks/seen')
21
+ s.markSeen(frames)
22
+ }
12
23
 
13
24
  /** Every frame's mark, derived ONCE per change of marks, threads or manifest. Rows and headers read
14
25
  * one string each, so a change re-renders only what it changes - never the whole shell. */