@marver-design/marver 0.25.1 → 0.26.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 +62 -0
  2. package/README.md +3 -1
  3. package/dist/{anchor-DVV732zR.mjs → anchor-5H1vnoLu.mjs} +6 -1
  4. package/dist/{anchor-check-DGZnYviN.mjs → anchor-check-Dg5xpNnU.mjs} +1 -1
  5. package/dist/audio-CmSRYFEs.mjs +429 -0
  6. package/dist/{auth-DdUKeVKt.mjs → auth-Dix8wrXV.mjs} +1 -1
  7. package/dist/{bake-BpxMZfij.mjs → bake-DtVlm0_F.mjs} +1 -1
  8. package/dist/{boards-Csxj2WJn.mjs → boards-DYG22tOe.mjs} +2 -2
  9. package/dist/{build-DKaGhoVN.mjs → build-C_gUgcdC.mjs} +16 -9
  10. package/dist/capture-CrqvU_jh.mjs +729 -0
  11. package/dist/cli.mjs +23 -17
  12. package/dist/{collab-gqNdScUE.mjs → collab-Dxg2trOK.mjs} +4 -3
  13. package/dist/{comments-Zoch254k.mjs → comments-0BSbb04K.mjs} +14 -3
  14. package/dist/{comments-pTLlhjh4.mjs → comments-BqXua-XL.mjs} +7 -7
  15. package/dist/{config-cKgZBRj0.mjs → config-Cf7EjAMf.mjs} +12 -1
  16. package/dist/{context-D2ugHqwO.mjs → context-HQ4Giw58.mjs} +1 -1
  17. package/dist/daemon-DZo6o3rU.mjs +2445 -0
  18. package/dist/{dev-Diqx1Rt8.mjs → dev-_Nlsc6v9.mjs} +189 -18
  19. package/dist/dev-lock-DWSpa6nj.mjs +179 -0
  20. package/dist/{events-DnK_AnrW.mjs → events-CLH4ijKP.mjs} +14 -4
  21. package/dist/{init-DO4DhUt_.mjs → init-D8DtrK_F.mjs} +2 -2
  22. package/dist/{ledger-BNXW14Xw.mjs → ledger-D54iROST.mjs} +17 -1
  23. package/dist/{link-C-qUIuKU.mjs → link-BNzLvdhI.mjs} +2 -2
  24. package/dist/live-Cgzsicwi.mjs +4 -0
  25. package/dist/{manifest-DnAte_fB.mjs → manifest-Nl3KSVOk.mjs} +1 -1
  26. package/dist/{marks-koRsbHfe.mjs → marks-CKgzucHZ.mjs} +2 -2
  27. package/dist/{marks-DFuintmJ.mjs → marks-NQi0wZJ4.mjs} +23 -5
  28. package/dist/{marver-id-gate-DGANtVyC.mjs → marver-id-gate-BjF6v4bT.mjs} +4 -4
  29. package/dist/{perf-QJIWtTw1.mjs → perf-D6VmmJ2q.mjs} +1 -1
  30. package/dist/{perf-CCisg-ny.mjs → perf-DPbLGhhO.mjs} +1 -1
  31. package/dist/{plugin-dTF5reck.mjs → plugin-CTD0rydA.mjs} +277 -37
  32. package/dist/{poster-D-zjYpgk.mjs → poster-ChjXGTS5.mjs} +1 -1
  33. package/dist/{profile-Do0nGkXO.mjs → profile-WU9qcbIo.mjs} +1 -1
  34. package/dist/{publish-bakes-C_9VZ-Mq.mjs → publish-bakes-CEP_2NRc.mjs} +3 -3
  35. package/dist/queue-BuiCKSX1.mjs +1319 -0
  36. package/dist/reserve-BURNQ2Y3.mjs +53 -0
  37. package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-8H4AJuhK.mjs} +1 -0
  38. package/dist/{serve-wv2QWdxB.mjs → serve-C8rVheYk.mjs} +12 -12
  39. package/dist/session-qZWKt_VA.mjs +191 -0
  40. package/dist/{share-ScamJcks.mjs → share--oFJ1bCI.mjs} +2 -2
  41. package/dist/{shot-jdO_B6Qw.mjs → shot-CNbHoZ6H.mjs} +1 -1
  42. package/dist/{shot-CUlmkqFX.mjs → shot-DqcxJibP.mjs} +4 -3
  43. package/dist/speech-models-DomiLQcY.mjs +299 -0
  44. package/dist/speech-worker.mjs +319 -0
  45. package/dist/{summary-CrW88e3q.mjs → summary-Y8MY1Wuc.mjs} +2 -2
  46. package/dist/{sync-C3035OnJ.mjs → sync-DKk-yT1V.mjs} +9 -8
  47. package/dist/{work-GE88wb_3.mjs → work-F5u-twpJ.mjs} +28 -5
  48. package/dist/{work-CpJn1gwY.mjs → work-VvX_JIgl.mjs} +2 -2
  49. package/docs/jam-session.md +177 -0
  50. package/docs/live-jam.md +21 -3
  51. package/package.json +7 -1
  52. package/src/client/frame-host/bridge.js +20 -2
  53. package/src/client/frame-host/inspect.d.ts +4 -0
  54. package/src/client/frame-host/inspect.js +88 -3
  55. package/src/client/frame-host/keys.d.ts +6 -0
  56. package/src/client/frame-host/keys.js +55 -0
  57. package/src/client/frame-host/trail.d.ts +7 -0
  58. package/src/client/frame-host/trail.js +204 -0
  59. package/src/client/shell/App.tsx +45 -5
  60. package/src/client/shell/Comments.tsx +20 -6
  61. package/src/client/shell/JamSurface.tsx +340 -0
  62. package/src/client/shell/Play.tsx +22 -3
  63. package/src/client/shell/Tip.tsx +8 -3
  64. package/src/client/shell/canvas/Canvas.tsx +12 -2
  65. package/src/client/shell/canvas/FrameNode.tsx +11 -2
  66. package/src/client/shell/comments-store.ts +23 -16
  67. package/src/client/shell/icons.tsx +15 -0
  68. package/src/client/shell/jam-capture.ts +939 -0
  69. package/src/client/shell/jam-keys.ts +329 -0
  70. package/src/client/shell/jam-lane.tsx +208 -0
  71. package/src/client/shell/jam-lines.ts +115 -0
  72. package/src/client/shell/jam-panel.tsx +506 -0
  73. package/src/client/shell/jam-queue.ts +126 -0
  74. package/src/client/shell/jam-session.tsx +389 -0
  75. package/src/client/shell/jam-state.ts +61 -0
  76. package/src/client/shell/jam-surface-parts.tsx +102 -0
  77. package/src/client/shell/jam-ui.tsx +104 -0
  78. package/src/client/shell/jam-voice.ts +479 -0
  79. package/src/client/shell/sound.ts +22 -0
  80. package/src/client/shell/stage-size.ts +11 -0
  81. package/src/client/shell/store.ts +34 -13
  82. package/src/client/shell/styles.css +544 -2
  83. package/src/client/stage/main.tsx +16 -2
  84. package/src/shared/capture-frames.ts +41 -0
  85. package/src/shared/events.ts +19 -4
  86. package/src/shared/speech.ts +16 -0
  87. package/templates/AGENTS-embedded.md +10 -2
  88. package/templates/AGENTS-studio.md +10 -2
  89. package/templates/instructions/iterate.md +8 -6
  90. package/templates/instructions/jam.md +129 -59
  91. package/dist/daemon-Cl8KXGW4.mjs +0 -1523
@@ -1,3 +1,10 @@
1
+ import { frameReady, onFrameMessage, recordCopy } from './jam-capture.ts'
2
+ import { jamKey } from './jam-keys.ts'
3
+ import { letGoOfTile } from './jam-state.ts'
4
+ import { JamSurface, useLaneLift } from './JamSurface.tsx'
5
+ import { JamButton } from './jam-session.tsx'
6
+ import { useJamCapture } from './jam-capture.ts'
7
+ import { useJamQueue } from './jam-queue.ts'
1
8
  import { Component, useEffect, useRef, useState, type MouseEvent as ReactMouseEvent, type ReactNode } from 'react'
2
9
  import { useStore, CONFIG, CANVAS_NAME, LOCKED_SHELL, PUBLISHED, SOURCE_REVEALED, logReload, takeReloadCause, addToBoard, boardLabel, cap, humanize, fetchBoardNames, landingBoard, tabTitle, hydrateBoardPolicy, landingMode, playsAsSlides, sceneLabel, type FrameEntry } from './store.ts'
3
10
  import { AddToBoard, BoardList } from './BoardList.tsx'
@@ -189,6 +196,7 @@ function SelectionBar() {
189
196
  onClick={() => {
190
197
  const brd = useStore.getState().board
191
198
  const text = selectedFrames().map((f) => framePath(brd, f)).join('\n')
199
+ for (const f of selectedFrames()) recordCopy('path', f.id)
192
200
  navigator.clipboard.writeText(text).then(
193
201
  () => { toast(multi ? `${selection.length} paths copied` : 'path copied'); useStore.getState().pulsePath() },
194
202
  () => toast('copy blocked - click the canvas first'))
@@ -338,6 +346,11 @@ export function App() {
338
346
  const manifest = useStore((s) => s.manifest)
339
347
  const nodes = useStore((s) => s.nodes)
340
348
  const panelOpen = useStore((s) => s.panelOpen)
349
+ const laneLift = useLaneLift()
350
+ // the collapsed toolbar keeps the dot - while a capture records, and for a whole Jam session
351
+ const capturing = useJamCapture((st) => !!st.current)
352
+ const inSession = useJamQueue((st) => !!st.session)
353
+ const recording = capturing || inSession
341
354
  const toasts = useStore((s) => s.toasts)
342
355
  const selection = useStore((s) => s.selection)
343
356
  const laser = useStore((s) => s.laser)
@@ -566,6 +579,11 @@ export function App() {
566
579
  // Live Jam reply delivery: the daemon just wrote to a board's log - fetch it NOW instead of
567
580
  // waiting out the 30s comment poll, so the reply + notification land within a second.
568
581
  import.meta.hot.on('sh:jam-comment', (m: any) => { if (typeof m?.board === 'string') useComments.getState().poke(m.board) })
582
+ // the jam queue (spec 27): the status icon by each tag's time, and a failure's one notice
583
+ import.meta.hot.on('sh:jam-queue', (m: any) => { void import('./jam-queue.ts').then(({ useJamQueue }) => useJamQueue.getState().apply(m)) })
584
+ void import('./jam-queue.ts').then(({ useJamQueue }) => useJamQueue.getState().load())
585
+ // captures sealed in an earlier page that never reached the server
586
+ void import('./jam-capture.ts').then(({ resendSealed }) => resendSealed())
569
587
  // A7 controlled HMR: a frame file changed. Reload exactly the affected frames through the
570
588
  // lease-aware path (idle frames now, leased ones deferred to a safe point) - never a shell
571
589
  // reload, never a React Fast Refresh yanking a frame the user is in.
@@ -600,6 +618,9 @@ export function App() {
600
618
  if (!reg) return
601
619
  const { key: nodeKey, iframe: el } = reg
602
620
  const s = useStore.getState()
621
+ // Jam (spec 27): a capture's trail, handshake, probes and flushes; a key the shell owns
622
+ if (onFrameMessage(nodeKey, data)) return
623
+ if (data.type === 'sh:key') { if (typeof data.key === 'string') jamKey({ key: data.key, shift: !!data.shift, alt: !!data.alt, meta: !!data.meta, ctrl: !!data.ctrl }); return }
603
624
 
604
625
  if (data.type === 'sh:ready') {
605
626
  // a WindowProxy survives navigation, so a ready queued by a SUPERSEDED document (one the
@@ -611,6 +632,7 @@ export function App() {
611
632
  // sleeping override of the previous document must not be trusted for this one
612
633
  if (s.nodes.find((n) => n.key === nodeKey)?.status === 'ready') s.bumpRev(nodeKey)
613
634
  s.setStatus(nodeKey, 'ready')
635
+ frameReady(nodeKey)
614
636
  // the revision this document was served with (spec 26): a look counts up to it, and one older
615
637
  // than the frame's last edit reloads
616
638
  const before = s.nodes.find((n) => n.key === nodeKey)?.shown
@@ -654,6 +676,7 @@ export function App() {
654
676
  // them so an open thread card dismisses modal-style from anywhere
655
677
  const c = commentsStore()
656
678
  if (c.active) c.setActive(null)
679
+ letGoOfTile() // and a lane tile selected with nothing open for it, as a canvas click does
657
680
  } else if (data.type === 'sh:picked') {
658
681
  // comment mode: the frame reports the picked element - stage the draft on
659
682
  // that node (picking while a thread is open replaces it, modal-style);
@@ -704,6 +727,8 @@ export function App() {
704
727
  if (e.isComposing) return
705
728
  const s = useStore.getState()
706
729
  if (s.play) return // play mode owns the keyboard (Play.tsx)
730
+ // Jam's keys first (spec 27): the first state that takes the key; the rest falls through
731
+ if (!e.repeat && jamKey({ key: e.key, shift: e.shiftKey, alt: e.altKey, meta: e.metaKey, ctrl: e.ctrlKey })) { e.preventDefault(); return }
707
732
  if ((e.metaKey || e.ctrlKey) && e.key === '\\') { e.preventDefault(); togglePanel(); return }
708
733
  if ((e.metaKey || e.ctrlKey) && e.key === '/') { e.preventDefault(); setPillOpen((o) => !o); return }
709
734
  if ((e.metaKey || e.ctrlKey) && e.key === 'a') { e.preventDefault(); s.selectAll(); return }
@@ -764,6 +789,7 @@ export function App() {
764
789
  .filter((p): p is string => !!p)
765
790
  if (paths.length) {
766
791
  // pulse the toolbar icon into a check ONLY on a real copy success
792
+ for (const k of s.selection) { const f = s.frameFor(s.nodes.find((x) => x.key === k)!); if (f) recordCopy('path', f.id) }
767
793
  navigator.clipboard.writeText(paths.join('\n')).then(
768
794
  () => { toast(paths.length > 1 ? `${paths.length} paths copied` : 'path copied'); s.pulsePath() },
769
795
  () => toast('copy blocked - click the canvas first'))
@@ -850,7 +876,7 @@ export function App() {
850
876
  }
851
877
 
852
878
  return (
853
- <div ref={appRef} tabIndex={-1} className={`sh-app${dark ? ' dark' : ''}${interacting ? ' interacting' : ''}`}>
879
+ <div ref={appRef} tabIndex={-1} className={`sh-app${dark ? ' dark' : ''}${interacting ? ' interacting' : ''}${laneLift}`}>
854
880
  <Canvas />
855
881
  <SelectionBar />
856
882
 
@@ -925,7 +951,7 @@ export function App() {
925
951
  if (!shift) canvasCtl.fitNode(n.key)
926
952
  }
927
953
  const frameMenu = (fr: FrameEntry): MenuItem[] => [
928
- { label: 'Copy path', icon: <SignpostIcon size={15} />, onClick: () => copyToClipboard(framePath(useStore.getState().board, fr), 'path copied') },
954
+ { label: 'Copy path', icon: <SignpostIcon size={15} />, onClick: () => { recordCopy('path', fr.id); copyToClipboard(framePath(useStore.getState().board, fr), 'path copied') } },
929
955
  // the Not on a board view (spec 26): put the frame where it belongs
930
956
  ...(useStore.getState().board === UNPLACED ? [{ label: 'Add to board…', icon: <PlusIcon size={15} />, panel: (close: () => void) => <AddToBoard frame={fr.id} close={close} /> }] : []),
931
957
  ]
@@ -1003,6 +1029,8 @@ export function App() {
1003
1029
  {/* far-left section: actions - comment mode, laser, tidy */}
1004
1030
  <CommentButton />
1005
1031
  <LaserButton />
1032
+ {/* Jam V2 (spec 27 Part 5): the session - between Laser and Tidy */}
1033
+ {!PUBLISHED && CONFIG.jam && <JamButton />}
1006
1034
  <Tip side="bottom" label={<><b>Tidy layout</b><span>T</span></>}>
1007
1035
  <button className="sh-pill-btn" onClick={() => { animateLayout(); runTidy() }}><ColumnsIcon size={16} /></button>
1008
1036
  </Tip>
@@ -1025,7 +1053,7 @@ export function App() {
1025
1053
  </nav>
1026
1054
  <Tip side="bottom" label={<><b>Open toolbar</b><span>⌘/</span></>}>
1027
1055
  <button className={`sh-pill-fab${pillOpen ? ' hidden' : ''}`} onClick={() => setPillOpen(true)}
1028
- aria-hidden={pillOpen} tabIndex={pillOpen ? -1 : 0}><PanelHollowIcon size={18} style={{ transform: 'rotate(90deg)' }} /></button>
1056
+ aria-hidden={pillOpen} tabIndex={pillOpen ? -1 : 0}><PanelHollowIcon size={18} style={{ transform: 'rotate(90deg)' }} />{recording && <i className="jm-live-dot jm-fab-dot" />}</button>
1029
1057
  </Tip>
1030
1058
 
1031
1059
  <PlayOverlay />
@@ -1037,6 +1065,8 @@ export function App() {
1037
1065
  : CONFIG.noTheme && !contentOnly(manifest?.frames ?? []) && <div className="sh-banner">no theme configured - frames render unstyled. Create design/theme.css importing your app's stylesheet (or set theme in design/config.ts)</div>}
1038
1066
  <UpdatePill />
1039
1067
 
1068
+ {/* Jam V2 (spec 27): the lane, the focus panel, the notes card, the recording ring */}
1069
+ {!PUBLISHED && <JamSurface sidebarRight={panelOpen ? 236 + 2 * 10 : 10} />}
1040
1070
  <JamToasts toasts={toasts} />
1041
1071
  </div>
1042
1072
  )
@@ -1104,6 +1134,15 @@ async function viewNote(note: import('./store.ts').JamNote, dismiss: () => void)
1104
1134
  }
1105
1135
  }
1106
1136
 
1137
+ /** Retry a batch's failed jam cards from their notice - each one still failed (a newer change wins). */
1138
+ async function retryNote(failed: { card: string; rev: number }[]) {
1139
+ const { useJamQueue } = await import('./jam-queue.ts')
1140
+ for (const f of failed) {
1141
+ const card = useJamQueue.getState().cards?.find((c) => c.id === f.card)
1142
+ if (card && card.state === 'failed') await useJamQueue.getState().act(card, 'retry')
1143
+ }
1144
+ }
1145
+
1107
1146
  /** One jam pill, frame-first: row 1 = intent icon + FRAME TITLE (blue) · age; row 2 = Marver · preview.
1108
1147
  * `badge` shows the +N deck count (replacing View); `inert` disables inner clicks (the deck handles it). */
1109
1148
  function JamToast({ id, note, badge, inert }: { id: number; note: import('./store.ts').JamNote; badge?: number; inert?: boolean }) {
@@ -1121,13 +1160,14 @@ function JamToast({ id, note, badge, inert }: { id: number; note: import('./stor
1121
1160
  ? <b className="sh-jam-frame"><span className="t">{note.author!.name ?? 'Someone'}</span> <span className="v">{note.kind === 'mention' ? 'mentioned you' : 'replied'}</span></b>
1122
1161
  : note.stack?.length
1123
1162
  ? <b className="sh-jam-frame"><span className="t">{note.board === ALL_SCENES ? note.frameTitle ?? note.frame ?? '' : boardLabel(note.board)}</span> <span className="v">· {note.stack.length + 1} replies</span></b>
1124
- : <b className="sh-jam-frame"><span className="t">{note.frameTitle ?? note.board}</span></b>}
1163
+ : <b className="sh-jam-frame"><span className="t">{note.frameTitle ?? note.board}</span>{note.failed && <span className="v"> · failed</span>}</b>}
1125
1164
  <span className="sh-jam-prev">{note.preview}</span>
1126
1165
  </div>
1127
1166
  {badge != null
1128
1167
  ? <span className="sh-jam-badge">+{badge}</span>
1129
1168
  : !inert && <>
1130
- <button className="sh-jam-view" onClick={() => void viewNote(note, () => useStore.getState().advanceToast(id))}>View</button>
1169
+ {note.failed && <button className="sh-jam-view" onClick={() => { void retryNote(note.failed!); dismiss() }}>Retry</button>}
1170
+ {note.threadId && <button className="sh-jam-view" onClick={() => void viewNote(note, () => useStore.getState().advanceToast(id))}>View</button>}
1131
1171
  <button className="sh-jam-x" aria-label="Dismiss" onClick={dismiss}><XIcon size={13} /></button>
1132
1172
  </>}
1133
1173
  </div>
@@ -17,6 +17,9 @@ import { bootHash, buildHash, parseHash, writeHash } from './hash.ts'
17
17
  import { isLegacyLink } from './legacy-links.ts'
18
18
  import { ArrowUpIcon, CheckIcon, CheckSquareOffsetIcon, LinkIcon, ParallelogramFillIcon, PencilSimpleIcon, PlusIcon, XIcon } from './icons.tsx'
19
19
  import { Tip } from './Tip.tsx'
20
+ import { TagStatus } from './jam-ui.tsx'
21
+ import { CaptureBlock } from './jam-panel.tsx'
22
+ import { useJamQueue } from './jam-queue.ts'
20
23
  import { mentionAlerts, mentionPeople, mentionQueryAt, parseBody, type MentionPerson } from './mentions.ts'
21
24
  import { ROUTE, slideSize, stageFit } from '../const.ts'
22
25
  import type { AgentMeta, Thread } from '../../shared/events.ts'
@@ -136,6 +139,8 @@ export function Pins({ threads, placed, orphans, inv, active, alertIds }: {
136
139
  inv: number; active: string | null; alertIds?: Set<string>
137
140
  }) {
138
141
  const { setActive } = useComments.getState()
142
+ // a pin wears the thin Marver-blue working ring while the agent works on its thread (spec 27)
143
+ const working = useJamQueue((s) => s.cards)?.filter((c) => c.state === 'working').map((c) => c.thread) ?? []
139
144
  return (
140
145
  <>
141
146
  {threads.map((t) => {
@@ -143,7 +148,7 @@ export function Pins({ threads, placed, orphans, inv, active, alertIds }: {
143
148
  const orphan = orphans.has(t.id)
144
149
  return [
145
150
  p.lead && <i key={`${t.id}-lead`} data-lead={t.id} className="cm-lead" aria-hidden style={{ left: p.lead.x, top: p.lead.y, height: p.y - MARKER.h * inv - p.lead.y }} />,
146
- <div key={t.id} data-thread={t.id} className={`cm-pin sh-no-pan${t.id === active ? ' on' : ''}${orphan ? ' orphan' : ''}${alertIds?.has(t.id) ? ' mention' : ''}`}
151
+ <div key={t.id} data-thread={t.id} className={`cm-pin sh-no-pan${t.id === active ? ' on' : ''}${orphan ? ' orphan' : ''}${alertIds?.has(t.id) ? ' mention' : ''}${working.includes(t.id) ? ' working' : ''}`}
147
152
  style={{ left: p.x, top: p.y, ...hueVars(anchorHue(t.anchor)) }}
148
153
  onPointerDown={(e) => e.stopPropagation()}
149
154
  onClick={(e) => { e.stopPropagation(); setActive(t.id === active ? null : t.id) }}
@@ -423,7 +428,7 @@ function CommentBody({ body, owner }: { body?: string; owner: boolean }) {
423
428
  )
424
429
  }
425
430
 
426
- const HARNESS: Record<string, string> = { claude: 'Claude Code', codex: 'Codex', cursor: 'Cursor', opencode: 'opencode', droid: 'Factory Droid', grok: 'Grok', pi: 'pi' }
431
+ export const HARNESS: Record<string, string> = { claude: 'Claude Code', codex: 'Codex', cursor: 'Cursor', opencode: 'opencode', droid: 'Factory Droid', grok: 'Grok', pi: 'pi' }
427
432
  /** claude-opus-5 → Opus 5; gpt-5.1-codex → Gpt 5.1 Codex; unknown → as-is. */
428
433
  function prettyModel(m: string): string {
429
434
  const cleaned = m.replace(/^claude-/, '').replace(/-/g, ' ')
@@ -453,7 +458,7 @@ function AgentMetaTip({ meta }: { meta?: AgentMeta }) {
453
458
  * human messages keep their avatar + name. While the dev profile is still UNSET, every own
454
459
  * message avatar invites editing on hover (discoverability); once set, only the composer's
455
460
  * avatar is the door. */
456
- function MessageHead({ author, agent, agentMeta, ts }: { author?: Thread['author']; agent?: boolean; agentMeta?: AgentMeta; ts: number }) {
461
+ function MessageHead({ author, agent, agentMeta, ts, board, eventId }: { author?: Thread['author']; agent?: boolean; agentMeta?: AgentMeta; ts: number; board?: string; eventId?: string }) {
457
462
  const me = useComments((s) => s.me)
458
463
  const local = useComments((s) => s.local)
459
464
  const connected = useComments((s) => s.connected)
@@ -476,6 +481,7 @@ function MessageHead({ author, agent, agentMeta, ts }: { author?: Thread['author
476
481
  {unset && own ? <EditableAvatar author={author} size={24} /> : <Avatar author={author} size={24} />}
477
482
  <b>{shown?.name ?? 'Someone'}</b>
478
483
  <span className="dim">{rel(ts)}</span>
484
+ <TagStatus board={board} eventId={eventId} harness={HARNESS} />
479
485
  </header>
480
486
  )
481
487
  }
@@ -662,6 +668,9 @@ export function ThreadCard({ thread, at, bounds, nodeKey, side = 'r', flank, sta
662
668
  // without a profile, local writes are the owner.
663
669
  const isOwner = (a?: { email?: string; id?: string }) =>
664
670
  me?.id && a?.id ? a.id === me.id : me?.email ? a?.email === me.email : local
671
+ // the event behind each message - a tag's card names its events, the status icon finds it by them
672
+ const events = useComments((s) => s.events)
673
+ const eventOf = (msg: string) => events.find((e) => (e.type === 'create' || e.type === 'reply') && e.commentId === msg && (!e.board || !thread.board || e.board === thread.board))?.id
665
674
  const [text, setText] = useState('')
666
675
  const [copied, setCopied] = useState(false)
667
676
  const copyTimer = useRef<ReturnType<typeof setTimeout>>(undefined)
@@ -796,13 +805,18 @@ export function ThreadCard({ thread, at, bounds, nodeKey, side = 'r', flank, sta
796
805
  {/* "there is more": the scroller MASKS its own content at the overflowing edge - a soft fade
797
806
  of the text itself, not a paint layer over the glass */}
798
807
  <div className={`cm-scroll${shadows.top ? ' fade-top' : ''}${shadows.bot ? ' fade-bot' : ''}`} ref={scrollRef} onScroll={syncShadows}>
799
- <MessageHead author={thread.author} agent={thread.agent} agentMeta={thread.agentMeta} ts={thread.ts} />
800
- <CommentBody body={thread.body} owner={isOwner(thread.author)} />
808
+ <MessageHead author={thread.author} agent={thread.agent} agentMeta={thread.agentMeta} ts={thread.ts} board={thread.board} eventId={eventOf(thread.id)} />
809
+ {/* a capture's comment reads as a capture: a labelled block, never a typed comment (spec 27) */}
810
+ {thread.capture
811
+ ? <CaptureBlock id={thread.capture} facts={thread.facts} words={thread.body ?? ''} />
812
+ : <CommentBody body={thread.body} owner={isOwner(thread.author)} />}
801
813
  {/* replies repeat the root's exact message shape (Figma's pattern) - only the icons differ */}
802
814
  {thread.replies.map((r) => (
803
815
  <div key={r.id} className="cm-msg">
804
- <MessageHead author={r.author} agent={r.agent} agentMeta={r.agentMeta} ts={r.ts} />
816
+ <MessageHead author={r.author} agent={r.agent} agentMeta={r.agentMeta} ts={r.ts} board={thread.board} eventId={eventOf(r.id)} />
805
817
  <CommentBody body={r.body} owner={isOwner(r.author)} />
818
+ {/* a jam job changed a shared file it was not given: one line, so the reply says it (spec 27) */}
819
+ {r.agent && r.alsoChanged?.length ? <div className="cm-also">Also changed {r.alsoChanged.map((f) => f.split('/').pop()).join(', ')}</div> : null}
806
820
  </div>
807
821
  ))}
808
822
  </div>
@@ -0,0 +1,340 @@
1
+ /**
2
+ * Jam's surfaces in the shell (spec 27): the lane along the bottom (captures only, in the order made,
3
+ * the one recording last), the one focus panel (a capture's detail - a draft's read-back - or a
4
+ * review), the notes card over the capture tile, the teal edge ring and the numbered points while a
5
+ * capture records. The pieces are presentational (jam-lane.tsx, jam-panel.tsx); this file feeds
6
+ * them from the three stores and turns their clicks into queue actions.
7
+ */
8
+ import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
9
+ import { ROUTE } from '../const.ts'
10
+ import { captureCounts, useJamCapture } from './jam-capture.ts'
11
+ import { useJamVoice, voiceSession, voiceSessionEnd, voiceSessionId, type Heard } from './jam-voice.ts'
12
+ import { holdsSessionMic, PlayCounter, RecordDetail, StartSheet, WrapSheet } from './jam-session.tsx'
13
+ import { FocusPanel, VoiceAsk } from './jam-panel.tsx'
14
+ import { addNote, decideDraft, laneCards, openThread, openTile, pendingEdit, resumeDraft, reveal, saveEdit, shownLane, startCapture } from './jam-keys.ts'
15
+ import { ContextMenu, useContextMenu, type MenuItem } from './ContextMenu.tsx'
16
+ import { ArrowBendUpLeftIcon, ArrowLineUpIcon, ArrowUpIcon, CheckSquareOffsetIcon, CommentIcon, EyeIcon, NotebookIcon, PencilSimpleIcon, PlayIcon, ReloadIcon, XIcon } from './icons.tsx'
17
+ import { laneLine, timelineLines } from './jam-lines.ts'
18
+ import { changedShots, useJamQueue, type JamCard } from './jam-queue.ts'
19
+ import { letGoOfTile, useJamUi } from './jam-state.ts'
20
+ import { CaptureLaneRow, FocusPanelView } from './jam-surface-parts.tsx'
21
+ import { clearMoreDraft, EdgeRing } from './jam-panel.tsx'
22
+ import { useComments } from './comments-store.ts'
23
+ import { HARNESS } from './Comments.tsx'
24
+ import { PUBLISHED, useStore } from './store.ts'
25
+ import type { CaptureRecord } from '../../server/jam/types.ts'
26
+
27
+ const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
28
+ const picture = (id?: string) => (id ? `${ROUTE}/api/jam/picture?id=${encodeURIComponent(id)}` : undefined)
29
+
30
+ /** Is the lane showing? While a run lasts with a capture in it, or a capture records. */
31
+ export function useLaneShown(): boolean {
32
+ const cards = useJamQueue((s) => s.cards)
33
+ const run = useJamQueue((s) => s.run)
34
+ // a capture recording, sealing or waiting to send keeps the lane up until its server card arrives
35
+ const busy = useJamCapture((s) => !!s.current || Object.keys(s.caps).length > 0 || s.unsent.length > 0)
36
+ // a session keeps it up from start to end: between captures its own tile says it is still on
37
+ const session = useJamQueue((s) => !!s.session)
38
+ return !PUBLISHED && (busy || session || laneCards(cards, run).length > 0)
39
+ }
40
+
41
+ /** A capture's record, loaded once per id for its detail. */
42
+ function useRecord(id: string | undefined) {
43
+ const [rec, setRec] = useState<{ id: string; record: CaptureRecord; edited?: string } | null>(null)
44
+ useEffect(() => {
45
+ if (!id || rec?.id === id) return
46
+ let live = true
47
+ fetch(`${ROUTE}/api/jam/capture?id=${encodeURIComponent(id)}`, { headers: { 'x-mv-c': csrf() } })
48
+ .then((r) => (r.ok ? r.json() : null)).then((r) => { if (live && r?.record) setRec({ id, record: r.record, edited: r.edited }) }, () => {})
49
+ return () => { live = false }
50
+ }, [id])
51
+ return rec?.id === id ? rec : null
52
+ }
53
+
54
+ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
55
+ const cards = useJamQueue((s) => s.cards)
56
+ const run = useJamQueue((s) => s.run)
57
+ const agent = useJamQueue((s) => s.agent)
58
+ const ui = useJamUi()
59
+ const cap = useJamCapture()
60
+ const voice = useJamVoice()
61
+ const shown = useLaneShown()
62
+ const session = useJamQueue((s) => s.session)
63
+ const playing = useStore((s) => !!s.play)
64
+ const [, setTick] = useState(0)
65
+ // the capture tile's timer and a working card's clock move
66
+ useEffect(() => { const t = setInterval(() => setTick((n) => n + 1), 1000); return () => clearInterval(t) }, [])
67
+ // a new capture or a new draft brings the lane back to its right end
68
+ useEffect(() => { ui.follow() }, [cap.current, cards?.filter((c) => c.kind === 'capture').length])
69
+ // the read-back of the capture just ended opens when capturing stops - over a review too (a capture
70
+ // made during a review is confirmed in its read-back; the review it follows stays bound in its record).
71
+ // It waits for that capture's own card: a resumed one replaces its draft, which must not open instead
72
+ // the capture ENDED last, not the one that sealed last (pictures can keep an earlier one sealing longer)
73
+ const [shownFor, setShownFor] = useState<string | null>(null)
74
+ useEffect(() => {
75
+ if (cap.current || !cap.lastEnded || cap.lastEnded === shownFor) return
76
+ const sealed = cap.sealed.find((x) => x.id === cap.lastEnded)
77
+ if (!sealed?.card) return
78
+ const draft = cards?.find((c) => c.id === sealed.card!.id && c.state === 'draft')
79
+ if (!draft) return
80
+ setShownFor(cap.lastEnded)
81
+ if (ui.panel?.kind === 'capture' && ui.panel.id === draft.id) return
82
+ ui.open({ kind: 'capture', id: draft.id })
83
+ reveal(draft)
84
+ }, [cap.current, cap.sealed, cap.lastEnded, cards])
85
+
86
+ // the session as the server holds it: a page opened (or reloaded) during one hears its talk again; one
87
+ // ended elsewhere (another tab) stops the talk here
88
+ useEffect(() => {
89
+ // only the tab that holds the session's microphone hears its talk - another tab never takes it over
90
+ const heard = voiceSessionId()
91
+ if (session && heard !== session.id && holdsSessionMic(session.id)) void voiceSession(session.id, performance.timeOrigin + performance.now())
92
+ // the talk of a session that is not the server's (ended, or another one) stops here
93
+ else if (heard && heard !== session?.id) void voiceSessionEnd()
94
+ }, [session?.id])
95
+
96
+ // J pressed while a capture recorded: the wrap-up waits for that capture's read-back to have opened and
97
+ // closed (or for it to have no draft at all - dropped, or kept at once)
98
+ useEffect(() => {
99
+ if (ui.sheet !== 'wrap-pending' || cap.current || Object.keys(cap.caps).length || cap.unsent.length) return
100
+ const id = cap.lastEnded
101
+ const card = id ? cards?.find((c) => c.id === id) : undefined
102
+ // sealed but its card not here yet: wait for it (a dropped capture never sealed - nothing to wait for)
103
+ if (id && !card && cap.sealed.some((x) => x.id === id)) return
104
+ // a draft: its read-back first - opened, then closed (confirmed, kept, dropped, or set aside)
105
+ if (card && card.state === 'draft' && (shownFor !== id || ui.panel?.id === id)) return
106
+ ui.setSheet('wrap')
107
+ }, [ui.sheet, ui.panel, cap.current, cap.caps, cap.unsent, cap.lastEnded, cards, shownFor])
108
+
109
+ // a draft being resumed is the capture recording (or sealing) now: its own tile steps aside
110
+ const list = shownLane(cards, run, cap.resuming)
111
+ const cm = useContextMenu()
112
+ // a comment opening (a pin, a thread, Open thread) takes the place of the read-back or review: the panel
113
+ // closes; the tile lets go too, unless the thread is that tile's own (a capture that asks opens its thread)
114
+ useEffect(() => useComments.subscribe((s, p) => {
115
+ if (!s.active || s.active === p.active) return
116
+ const st = useJamUi.getState()
117
+ const sel = useJamQueue.getState().cards?.find((c) => c.id === st.selected)
118
+ if (sel?.thread === s.active) { if (st.panel) st.close() } else letGoOfTile()
119
+ }), [])
120
+ const made = (id: string) => Number(/^cap-(\d+)-/.exec(id)?.[1] ?? 0)
121
+ const withMade = list.map((c) => ({ made: c.made, tile: { id: c.id, state: c.state, title: c.title ?? 'Capture', line: laneLine(c), ...(c.exclusive ? { exclusive: true } : {}) } as { id: string; state: JamCard['state']; title: string; line: string; exclusive?: boolean } }))
122
+ // captures the server does not hold yet: sealing (pictures and flushes still out) or waiting to send -
123
+ // each in its place by when it started, so one sealing late never swaps with a newer one
124
+ const known = new Set(list.map((c) => c.id))
125
+ for (const c of Object.values(cap.caps)) if (c.state === 'draining' && !known.has(c.id)) withMade.push({ made: made(c.id), tile: { id: c.id, state: 'confirming', title: 'Capture', line: 'Finishing' } })
126
+ for (const id of cap.unsent) if (!known.has(id) && !cap.caps[id]) withMade.push({ made: made(id), tile: { id, state: 'confirming', title: 'Capture', line: 'Waiting to send' } })
127
+ const tiles = withMade.sort((a, b) => a.made - b.made).map((x) => x.tile)
128
+ const recording = cap.current ? (() => {
129
+ const c = cap.caps[cap.current!]
130
+ const counts = captureCounts(c)
131
+ const steps = (c?.steps ?? []).filter((x) => ['select', 'device', 'theme', 'copied', 'interact'].includes(x.event)).length
132
+ return { time: counts.time, points: c?.points.length ?? 0, pictures: c?.pictures.length ?? 0, picturesMax: (c?.pictures.length ?? 0) >= 12, steps,
133
+ notes: counts.notes, noteOn: cap.noteOpen, onNote: () => cap.setNoteOpen(!cap.noteOpen), onStop: () => cap.end(),
134
+ // the microphone: on while it hears this capture; off once you were asked (a click asks again)
135
+ ...(voice.hearing === cap.current ? { mic: 'on' as const } : voice.choice !== null || voice.denied ? { mic: 'off' as const, onMic: () => useJamVoice.setState({ asking: true, choice: null }) } : {}) }
136
+ })() : undefined
137
+
138
+ // a session between captures (none recording, none still sealing here): its own tile
139
+ const between = session && !cap.current ? {
140
+ since: session.since, mic: voice.live,
141
+ onCapture: () => startCapture(), // as S: one started over an open review follows it
142
+ } : undefined
143
+
144
+ const panelCard = ui.panel ? cards?.find((c) => c.id === ui.panel!.id) : undefined
145
+ const rec = useRecord(ui.panel?.kind === 'capture' || ui.panel?.kind === 'review' ? ui.panel.id : undefined)
146
+ const agentName = agent ? HARNESS[agent] ?? agent : 'your agent'
147
+ const act = (c: JamCard | undefined, action: Parameters<ReturnType<typeof useJamQueue.getState>['act']>[1], body?: string) => (c ? useJamQueue.getState().act(c, action, body) : Promise.resolve(false))
148
+ const openThread = (c?: JamCard) => { if (c?.thread) useComments.getState().setActive(c.thread) }
149
+ /** The panel's arrows: the previous or next card of the same kind on the lane (reviews among reviews). */
150
+ const step = (d: number) => {
151
+ if (!ui.panel || !panelCard) return undefined
152
+ const of = list.filter((c) => (ui.panel!.kind === 'review' ? c.state === 'review' : true))
153
+ const n = of[of.findIndex((c) => c.id === panelCard.id) + d]
154
+ return n ? () => openTile(n.id) : undefined
155
+ }
156
+ const detail = useMemo(() => {
157
+ if (!ui.panel || !panelCard) return null
158
+ const of = list.filter((c) => (ui.panel!.kind === 'review' ? c.state === 'review' : true))
159
+ const idx = of.findIndex((c) => c.id === panelCard.id)
160
+ return { of: [idx + 1, of.length] as [number, number] }
161
+ }, [ui.panel, panelCard, list])
162
+
163
+ const sheetOpen = ui.sheet === 'start' || ui.sheet === 'wrap'
164
+ // the microphone question in a session with no capture recording: under the Jam button
165
+ const askAlone = voice.asking && !cap.current && !!session
166
+ if (!shown && !ui.panel && !sheetOpen && !askAlone) return null
167
+ // in play the lane folds to a counter beside the navigator (Q opens it); the capture recording stays
168
+ const folded = playing && !ui.laneKeys
169
+ return (
170
+ <>
171
+ {/* the edges glow while a capture records - and for the whole session, between captures too */}
172
+ {(cap.current || session) && <EdgeRing />}
173
+ {ui.sheet === 'start' && <div className="jm-sheet-at"><StartSheet /></div>}
174
+ {ui.sheet === 'wrap' && <div className="jm-sheet-at"><WrapSheet /></div>}
175
+ {askAlone && !sheetOpen && <div className="jm-sheet-at"><VoiceAsk {...voiceAsk(voice)} /></div>}
176
+ {folded && shown && <PlayCounter cards={list} style={{ left: playNavRight(), bottom: 'var(--edge)' }} />}
177
+ {shown && (
178
+ <CaptureLaneRow
179
+ tiles={folded ? [] : tiles} recording={recording} between={between} selected={ui.selected ?? undefined} keyboard={ui.laneKeys} followEnd={ui.followEnd}
180
+ onOpen={(id) => openTile(id)}
181
+ onMenu={(e, id) => { const c = cards?.find((x) => x.id === id); if (c) { ui.select(id); cm.open(e, tileMenu(c)) } else e.preventDefault() }}
182
+ ask={voice.asking && cap.current ? voiceAsk(voice) : undefined}
183
+ caption={cap.current ? captionOf(voice.heard[cap.current]) : undefined}
184
+ notes={cap.noteOpen ? {
185
+ notes: (cap.current ? cap.caps[cap.current]?.steps ?? [] : []).filter((x) => x.event === 'note').map((x) => ({ t: captureCounts({ ...cap.caps[cap.current!]!, t0: cap.caps[cap.current!]!.t0 }, x.at).time, text: (x as { text: string }).text })),
186
+ draft: cap.noteDraft, onDraft: cap.setNoteDraft, onAdd: () => cap.note(cap.noteDraft), onClose: () => cap.setNoteOpen(false),
187
+ } : undefined}
188
+ />
189
+ )}
190
+ {ui.panel && panelCard && panelCard.kind === 'wrapup' && (
191
+ <FocusPanel left={sidebarRight} onClose={() => ui.close()}>
192
+ <RecordDetail key={panelCard.id} card={panelCard} agent={agentName} more={ui.moreOpen} of={detail?.of} onPrev={step(-1)} onNext={step(1)}
193
+ onMoreOpen={(on) => ui.setMoreOpen(on)}
194
+ onGood={() => { void act(panelCard, 'good'); ui.close() }}
195
+ onLater={() => { void act(panelCard, 'later'); ui.close() }}
196
+ onRetry={() => { void act(panelCard, 'retry'); ui.close() }}
197
+ onDrop={() => { void act(panelCard, 'drop'); ui.close() }}
198
+ onMore={(text) => void (async () => {
199
+ if (await act(panelCard, 'more', text)) { clearMoreDraft(panelCard.id); ui.setMoreOpen(false); ui.close() }
200
+ else useStore.getState().toast('your note was not sent - try again')
201
+ })()} />
202
+ </FocusPanel>
203
+ )}
204
+ {ui.panel && panelCard && panelCard.kind !== 'wrapup' && (
205
+ <FocusPanelView
206
+ left={sidebarRight}
207
+ kind={ui.panel.kind}
208
+ card={panelCard}
209
+ of={detail?.of}
210
+ agent={agentName}
211
+ reviewedTitle={panelCard.reviewing ? cards?.find((c) => c.id === panelCard.reviewing!.card)?.title : undefined}
212
+ lines={rec ? timelineLines(rec.record, panelCard.edited ?? rec.edited) : []}
213
+ pictures={(rec?.record.pictures ?? []).map((id, i) => ({ id, url: picture(id)!, caption: `picture ${i + 1}` }))}
214
+ shots={changedShots(panelCard.shots).map((x) => ({ frame: x.frame, before: picture(x.before), after: picture(x.after), ...(x.new ? { new: true } : {}) }))}
215
+ reply={panelCard.reply ? replyText(panelCard) : ''}
216
+ view={ui.view} tab={ui.tab} moreOpen={ui.moreOpen}
217
+ onTab={(i) => ui.setTab(i)} onFlip={() => ui.flip()} onMoreOpen={(on) => ui.setMoreOpen(on)}
218
+ onClose={() => ui.close()}
219
+ onEdit={(text) => saveEdit(panelCard, text)}
220
+ onConfirm={() => void decideDraft(panelCard.id, 'confirm')}
221
+ onKeep={() => void decideDraft(panelCard.id, 'keep')}
222
+ onDrop={() => void decideDraft(panelCard.id, 'drop')}
223
+ onResume={() => void resumeDraft(panelCard.id)}
224
+ onAddNote={async (text, id) => { const ok = await addNote(panelCard, text, id); if (!ok) useStore.getState().toast('the note was not added - try again'); return ok }}
225
+ onGood={() => { void act(panelCard, 'good'); ui.close() }}
226
+ onMore={(text) => void (async () => {
227
+ // the composer and its words stay until the follow-up is really queued
228
+ if (await act(panelCard, 'more', text)) { clearMoreDraft(panelCard.id); ui.setMoreOpen(false); ui.close() }
229
+ else useStore.getState().toast('your follow-up was not sent - try again')
230
+ })()}
231
+ onLater={() => { void act(panelCard, 'later'); ui.close() }}
232
+ onOpenThread={() => openThread(panelCard)}
233
+ onPrev={step(-1)} onNext={step(1)} pending={pendingEdit(panelCard.id)} locked={cap.settling === panelCard.id}
234
+ onRetry={() => void (async () => { if (await act(useJamQueue.getState().cards?.find((x) => x.id === panelCard.id), 'retry')) ui.close(); else useStore.getState().toast('the capture could not be retried - look again') })()}
235
+ />
236
+ )}
237
+ <ContextMenu menu={cm.menu} close={cm.close} />
238
+ </>
239
+ )
240
+ }
241
+
242
+ /** In play: just right of the stage's navigator (its restart and frame arrows), where the counter sits. */
243
+ function playNavRight(): number {
244
+ const r = document.querySelector('.sh-play-nav')?.getBoundingClientRect()
245
+ return r ? Math.round(r.right + 8) : 176
246
+ }
247
+
248
+ /** What the microphone question shows now: the question, the download, its progress. */
249
+ function voiceAsk(v: ReturnType<typeof useJamVoice.getState>) {
250
+ const d = v.download
251
+ const step = v.choice === null ? 'ask' as const
252
+ // the engine could not start: why, and a way to try again - never a download that would not help
253
+ : v.server === 'unavailable' ? 'unavailable' as const
254
+ : d?.state === 'downloading' ? 'downloading' as const : d?.state === 'checking' ? 'checking' as const
255
+ : d?.state === 'failed' ? 'failed' as const : 'download' as const
256
+ return {
257
+ step, mb: v.mb, progress: d && d.total ? d.received / d.total : 0, error: v.server === 'unavailable' ? v.reason : d?.error,
258
+ onYes: () => v.setChoice('yes'), onNo: () => v.setChoice('no'), onDownload: () => void v.startDownload(),
259
+ }
260
+ }
261
+
262
+ /** The caption's words: the newest phrase in ink, a little of what came before it dim. */
263
+ function captionOf(heard: Heard[] | undefined): { old: string; live: string } | undefined {
264
+ if (!heard?.length) return undefined
265
+ const text = heard.map((w) => w.w)
266
+ const live = text.slice(-12)
267
+ const old = text.slice(Math.max(0, text.length - 24), Math.max(0, text.length - 12))
268
+ return { old: old.join(' '), live: live.join(' ') }
269
+ }
270
+
271
+ /** Open a card's thread with the caret in its reply field - to add to the conversation. */
272
+ function replyIn(c: JamCard) {
273
+ if (!c.thread) return
274
+ openThread(c)
275
+ // once the thread's card has drawn (on another board, once that board has loaded)
276
+ const until = performance.now() + 3_000
277
+ const focus = () => {
278
+ const el = useComments.getState().active === c.thread ? document.querySelector<HTMLTextAreaElement>('.cm-card textarea') : null
279
+ if (el) { el.focus(); el.setSelectionRange(el.value.length, el.value.length) } else if (performance.now() < until) requestAnimationFrame(focus)
280
+ }
281
+ requestAnimationFrame(focus)
282
+ }
283
+
284
+ /** A tile's right-click menu: what can be done with this capture now. */
285
+ function tileMenu(c: JamCard): MenuItem[] {
286
+ const q = useJamQueue.getState()
287
+ const act = (a: Parameters<typeof q.act>[1], body?: string) => { const fresh = useJamQueue.getState().cards?.find((x) => x.id === c.id); if (fresh) void useJamQueue.getState().act(fresh, a, body) }
288
+ const item = (label: string, icon: ReactNode, onClick: () => void): MenuItem => ({ label, icon, onClick })
289
+ // one icon per action, never two alike in a menu: open (eye), review (checklist), resume (play), rename
290
+ // (pencil), add to queue (send arrow), keep (notebook), do next (to the top), retry, reply, thread, drop
291
+ const open = item(c.state === 'review' ? 'Review' : c.state === 'draft' ? 'Open read-back' : 'Open', c.state === 'review' ? <CheckSquareOffsetIcon size={14} /> : <EyeIcon size={14} />, () => openTile(c.id))
292
+ const rename: MenuItem = { label: 'Rename', icon: <PencilSimpleIcon size={14} />, panel: (close) => <RenameField card={c} close={close} /> }
293
+ const reply = c.thread ? [item('Reply in thread', <ArrowBendUpLeftIcon size={14} />, () => replyIn(c))] : []
294
+ const thread = c.thread ? [item('Open thread', <CommentIcon size={14} />, () => openThread(c))] : []
295
+ switch (c.state) {
296
+ case 'draft': return [open, item('Resume capture', <PlayIcon size={14} />, () => void resumeDraft(c.id)), rename,
297
+ item('Add to queue', <ArrowUpIcon size={14} />, () => void decideDraft(c.id, 'confirm')), item('Keep, do not send', <NotebookIcon size={14} />, () => void decideDraft(c.id, 'keep')),
298
+ item('Drop', <XIcon size={14} />, () => void decideDraft(c.id, 'drop'))]
299
+ case 'queued': return c.kind === 'capture'
300
+ ? [open, rename, item('Do next', <ArrowLineUpIcon size={14} />, () => act('first')), item('Keep, do not send', <NotebookIcon size={14} />, () => act('keep')), item('Drop', <XIcon size={14} />, () => act('drop'))]
301
+ : [open, item('Drop', <XIcon size={14} />, () => act('drop'))] // a queued record: open or drop it
302
+ case 'review': return [open, ...reply, ...thread, rename]
303
+ case 'asks': return [...reply, open, rename]
304
+ case 'failed': return [item('Retry', <ReloadIcon size={14} />, () => act('retry')), open, ...thread, item('Drop', <XIcon size={14} />, () => act('drop'))]
305
+ default: return [open, ...reply, ...thread, rename]
306
+ }
307
+ }
308
+
309
+ /** Rename, in place of the menu: the title as it is, ⏎ saves, Esc leaves; empty gives back its first words. */
310
+ function RenameField({ card, close }: { card: JamCard; close: () => void }) {
311
+ const [text, setText] = useState(card.named ? card.title ?? '' : card.title === 'Capture' ? '' : card.title ?? '')
312
+ const ref = useRef<HTMLInputElement>(null)
313
+ useEffect(() => { requestAnimationFrame(() => ref.current?.select()) }, [])
314
+ const save = async () => {
315
+ const fresh = useJamQueue.getState().cards?.find((x) => x.id === card.id)
316
+ if (fresh && !(await useJamQueue.getState().act(fresh, 'rename', text))) useStore.getState().toast('the capture could not be renamed - look again')
317
+ close()
318
+ }
319
+ return (
320
+ <div className="jm-rename">
321
+ <input ref={ref} value={text} maxLength={80} placeholder="Name this capture" aria-label="Capture name"
322
+ onChange={(e) => setText(e.target.value)}
323
+ onKeyDown={(e) => { e.stopPropagation(); if (e.key === 'Enter') void save(); if (e.key === 'Escape') close() }} />
324
+ </div>
325
+ )
326
+ }
327
+
328
+ /** The agent's reply to a card, as the thread shows it. */
329
+ function replyText(c: JamCard): string {
330
+ const threads = useComments.getState().threads
331
+ const t = threads.find((x) => x.id === c.thread)
332
+ return t?.replies.find((r) => r.id === c.reply)?.body ?? ''
333
+ }
334
+
335
+ /** Lift the bottom edge while the lane shows: the sidebar stops above it, the Update pill, toasts and
336
+ * notices rise one lane. Returns the class for `.sh-app` - in its className, so a re-render of the app
337
+ * (interact on or off, the theme) never drops it. */
338
+ export function useLaneLift(): string {
339
+ return useLaneShown() ? ' jm-lane-on' : ''
340
+ }