@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
@@ -10,17 +10,19 @@ import { ROUTE } from '../const.ts'
10
10
  import { captureCounts, endedToReview, useJamCapture } from './jam-capture.ts'
11
11
  import { useJamVoice, voiceSession, voiceSessionEnd, voiceSessionId, type Heard } from './jam-voice.ts'
12
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'
13
+ import { AsksAnswer, FocusPanel, Marver, VoiceAsk } from './jam-panel.tsx'
14
+ import { addNote, decideDraft, endOnRecording, laneCards, openThread, openTile, pendingEdit, resumeDraft, reveal, saveEdit, shownLane, startCapture } from './jam-keys.ts'
15
15
  import { ContextMenu, useContextMenu, type MenuItem } from './ContextMenu.tsx'
16
16
  import { ArrowBendUpLeftIcon, ArrowLineUpIcon, ArrowUpIcon, CheckSquareOffsetIcon, CommentIcon, EyeIcon, NotebookIcon, PencilSimpleIcon, PlayIcon, ReloadIcon, XIcon } from './icons.tsx'
17
- import { laneLine, laneTip, timelineLines } from './jam-lines.ts'
18
- import { changedShots, useJamQueue, type JamCard } from './jam-queue.ts'
19
- import { DONE_GROUP, doneFold, letGoOfTile, useJamUi } from './jam-state.ts'
17
+ import { laneLine, laneTip, pictureCaption, timelineLines } from './jam-lines.ts'
18
+ import { changedShots, useJamQueue, type JamAction, type JamCard } from './jam-queue.ts'
19
+ import { DONE_GROUP, doneFold, endOnOk, jamSurface, letGoOfTile, useJamUi } from './jam-state.ts'
20
+ import { cmd, COMMANDS, endAfterFrames, keysOf, type CmdHandle, type CmdName, type CmdOpts } from './commands.ts'
20
21
  import { CaptureLaneRow, FocusPanelView } from './jam-surface-parts.tsx'
21
22
  import { clearMoreDraft, EdgeRing, preloadShots } from './jam-panel.tsx'
22
23
  import { useComments } from './comments-store.ts'
23
- import { HARNESS } from './Comments.tsx'
24
+ import { Avatar, HARNESS } from './Comments.tsx'
25
+ import { TagStatus } from './jam-ui.tsx'
24
26
  import { PUBLISHED, useStore } from './store.ts'
25
27
  import { api, withWs } from './api.ts'
26
28
  import type { CaptureRecord } from '../../server/jam/types.ts'
@@ -29,6 +31,52 @@ const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
29
31
  /** An <img> cannot send a header: its URL names the workspace, which the server's guard reads (A1.11). */
30
32
  const picture = (id?: string) => (id ? withWs(`${ROUTE}/api/jam/picture?id=${encodeURIComponent(id)}`) : undefined)
31
33
 
34
+ /** A lane tile clicked: its command (spec 30) ends once its surface is drawn, or could not be. */
35
+ const openFromLane = (id: string, h: CmdHandle) => void endOnOk(h, openTile(id))
36
+
37
+ /** What a capture's panel does with what was chosen: its button named the command, each move ends it (spec 30). */
38
+ function panelMoves(c: JamCard) {
39
+ const ui = useJamUi.getState()
40
+ const act = (card: JamCard | undefined, action: JamAction, body?: string) => (card ? useJamQueue.getState().act(card, action, body) : Promise.resolve(false))
41
+ return {
42
+ onEdit: (text: string, h: CmdHandle) => void endOnOk(h, saveEdit(c, text)),
43
+ onConfirm: (h: CmdHandle) => void endOnOk(h, decideDraft(c.id, 'confirm')),
44
+ onKeep: (h: CmdHandle) => void endOnOk(h, decideDraft(c.id, 'keep')),
45
+ onDrop: (h: CmdHandle) => void endOnOk(h, decideDraft(c.id, 'drop')),
46
+ onResume: (h: CmdHandle) => void endOnOk(h, resumeDraft(c.id)),
47
+ onAddNote: async (text: string, id: string) => { const ok = await addNote(c, text, id); if (!ok) useStore.getState().toast('the note was not added - try again'); return ok },
48
+ onGood: (h: CmdHandle) => { void endOnOk(h, act(c, 'good')); ui.close() },
49
+ onMore: (text: string, h: CmdHandle) => void (async () => {
50
+ // the composer and its words stay until the follow-up is really queued
51
+ if (await endOnOk(h, act(c, 'more', text))) { clearMoreDraft(c.id); ui.setMoreOpen(false); ui.close() }
52
+ else useStore.getState().toast('your follow-up was not sent - try again')
53
+ })(),
54
+ onLater: (h: CmdHandle) => { void endOnOk(h, act(c, 'later')); ui.close() },
55
+ onOpenThread: (h: CmdHandle) => void endOnOk(h, openThread(c)),
56
+ asks: c.thread ? { question: replyText(c), onAnswer: async (text: string) => {
57
+ const ok = await useComments.getState().replyOk(c.thread!, /@marver\b/i.test(text) ? text : `@marver ${text}`)
58
+ if (!ok) useStore.getState().toast('your answer was not sent - try again')
59
+ else ui.close()
60
+ return ok
61
+ } } : undefined,
62
+ onRetry: (h: CmdHandle) => void (async () => { if (await endOnOk(h, act(useJamQueue.getState().cards?.find((x) => x.id === c.id), 'retry'))) ui.close(); else useStore.getState().toast('the capture could not be retried - look again') })(),
63
+ }
64
+ }
65
+
66
+ /** The same for a session record's panel. */
67
+ function recordMoves(c: JamCard) {
68
+ const ui = useJamUi.getState()
69
+ const act = (action: JamAction, body?: string) => useJamQueue.getState().act(c, action, body)
70
+ const andClose = (action: JamAction) => (h: CmdHandle) => { void endOnOk(h, act(action)); ui.close() }
71
+ return {
72
+ onGood: andClose('good'), onLater: andClose('later'), onRetry: andClose('retry'), onDrop: andClose('drop'),
73
+ onMore: (text: string, h: CmdHandle) => void (async () => {
74
+ if (await endOnOk(h, act('more', text))) { clearMoreDraft(c.id); ui.setMoreOpen(false); ui.close() }
75
+ else useStore.getState().toast('your note was not sent - try again')
76
+ })(),
77
+ }
78
+ }
79
+
32
80
  /** Is the lane showing? While a run lasts with a capture in it, or a capture records. */
33
81
  export function useLaneShown(): boolean {
34
82
  const cards = useJamQueue((s) => s.cards)
@@ -127,6 +175,18 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
127
175
  // a draft being resumed is the capture recording (or sealing) now: its own tile steps aside
128
176
  const list = shownLane(cards, run, cap.resuming)
129
177
  const cm = useContextMenu()
178
+ // a tile's menu opened at the tile, for the helper that opens a stalled run's controls (jam-keys.ts openRunControls)
179
+ useEffect(() => {
180
+ jamSurface.tileMenu = (id) => {
181
+ const c = useJamQueue.getState().cards?.find((x) => x.id === id)
182
+ const el = document.querySelector(`.jm-lane [data-tile="${CSS.escape(id)}"]`)
183
+ if (!c || !el) return false
184
+ const r = el.getBoundingClientRect()
185
+ cm.open({ preventDefault() {}, clientX: r.left + 8, clientY: r.top - 8 }, tileMenu(c), `tile:${id}`)
186
+ return true
187
+ }
188
+ return () => { jamSurface.tileMenu = () => false }
189
+ }, [])
130
190
  // a comment opening (a pin, a thread, Open thread) takes the place of the read-back or review: the panel
131
191
  // closes; the tile lets go too, unless the thread is that tile's own (a capture that asks opens its thread)
132
192
  useEffect(() => useComments.subscribe((s, p) => {
@@ -157,16 +217,16 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
157
217
  return { time: counts.time, points: c?.points.length ?? 0, pictures: c?.pictures.length ?? 0, picturesMax: (c?.pictures.length ?? 0) >= 12, steps,
158
218
  notes: counts.notes, noteOn: cap.noteOpen, onNote: () => cap.setNoteOpen(!cap.noteOpen), onStop: () => cap.end(), onStopReview: () => cap.end(true),
159
219
  // the microphone: on while it hears this capture; off once you were asked (a click asks again)
160
- ...(voice.hearing === cap.current ? { mic: 'on' as const } : voice.choice !== null || voice.denied ? { mic: 'off' as const, onMic: () => useJamVoice.setState({ asking: true, choice: null }) } : {}) }
220
+ ...(voice.hearing === cap.current ? { mic: 'on' as const } : voice.choice !== null || voice.denied ? { mic: 'off' as const, onMic: (h: CmdHandle) => { useJamVoice.setState({ asking: true, choice: null }); endAfterFrames(h) } } : {}) }
161
221
  })() : undefined
162
222
 
163
223
  // a session between captures (none recording, none still sealing here): its own tile
164
224
  const between = session && !cap.current ? {
165
225
  since: session.since, mic: voice.live,
166
- onCapture: () => startCapture(), // as S: one started over an open review follows it
226
+ onCapture: (h: CmdHandle) => { startCapture(); endOnRecording(h) }, // as S: one started over an open review follows it
167
227
  } : undefined
168
228
 
169
- const panelCard = ui.panel ? cards?.find((c) => c.id === ui.panel!.id) : undefined
229
+ const panelCard = ui.panel && ui.panel.kind !== 'thread' ? cards?.find((c) => c.id === ui.panel!.id) : undefined
170
230
  // a card ready to review, and the one whose review is open: its pictures load now, every frame's - its review opens
171
231
  // at their size and moves between frames without waiting (each URL once; never a card that is not in review)
172
232
  useEffect(() => {
@@ -174,7 +234,6 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
174
234
  }, [cards, ui.panel])
175
235
  const rec = useRecord(ui.panel?.kind === 'capture' || ui.panel?.kind === 'review' ? ui.panel.id : undefined)
176
236
  const agentName = agent ? HARNESS[agent] ?? agent : 'your agent'
177
- 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))
178
237
  /** The panel's arrows: the previous or next card of the same kind on the lane (reviews among reviews). */
179
238
  const step = (d: number) => {
180
239
  if (!ui.panel || !panelCard) return undefined
@@ -189,10 +248,14 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
189
248
  return { of: [idx + 1, of.length] as [number, number] }
190
249
  }, [ui.panel, panelCard, list])
191
250
 
251
+ // a right-click on a tile: its menu (each item a command of its own)
252
+ const menuAt = (e: React.MouseEvent, id: string) => { const c = cards?.find((x) => x.id === id); if (c) { ui.select(id); cm.open(e, tileMenu(c), `tile:${id}`) } else e.preventDefault() }
253
+
192
254
  const sheetOpen = ui.sheet === 'start' || ui.sheet === 'wrap'
193
255
  // the microphone question in a session with no capture recording: under the Jam button
194
256
  const askAlone = voice.asking && !cap.current && !!session
195
257
  if (!shown && !ui.panel && !sheetOpen && !askAlone) return null
258
+ const panel = ui.panel
196
259
  // in play the lane folds to a counter beside the navigator (Q opens it); the capture recording stays
197
260
  const folded = playing && !ui.laneKeys
198
261
  return (
@@ -206,9 +269,9 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
206
269
  {shown && (
207
270
  <CaptureLaneRow
208
271
  tiles={folded ? [] : tiles} recording={recording} between={between} selected={ui.selected ?? undefined} keyboard={ui.laneKeys} followEnd={ui.followEnd}
209
- doneOpen={ui.doneOpen} onDoneOpen={(open, ids) => ui.setDoneOpen(open, ids)}
210
- onOpen={(id) => openTile(id)}
211
- onMenu={(e, id) => { const c = cards?.find((x) => x.id === id); if (c) { ui.select(id); cm.open(e, tileMenu(c)) } else e.preventDefault() }}
272
+ doneOpen={ui.doneOpen} onDoneOpen={ui.setDoneOpen}
273
+ onOpen={openFromLane}
274
+ onMenu={menuAt}
212
275
  ask={voice.asking && cap.current ? voiceAsk(voice) : undefined}
213
276
  caption={cap.current ? captionOf(voice.heard[cap.current]) : undefined}
214
277
  notes={cap.noteOpen ? {
@@ -217,57 +280,34 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
217
280
  } : undefined}
218
281
  />
219
282
  )}
283
+ {panel?.kind === 'thread' && (
284
+ <FocusPanel left={sidebarRight} onClose={ui.close}>
285
+ <ThreadPanel key={`${panel.board}/${panel.id}`} board={panel.board} id={panel.id} />
286
+ </FocusPanel>
287
+ )}
220
288
  {ui.panel && panelCard && panelCard.kind === 'wrapup' && (
221
- <FocusPanel left={sidebarRight} onClose={() => ui.close()}>
289
+ <FocusPanel left={sidebarRight} onClose={ui.close}>
222
290
  <RecordDetail key={panelCard.id} card={panelCard} agent={agentName} more={ui.moreOpen} of={detail?.of} onPrev={step(-1)} onNext={step(1)}
223
- onMoreOpen={(on) => ui.setMoreOpen(on)}
224
- onGood={() => { void act(panelCard, 'good'); ui.close() }}
225
- onLater={() => { void act(panelCard, 'later'); ui.close() }}
226
- onRetry={() => { void act(panelCard, 'retry'); ui.close() }}
227
- onDrop={() => { void act(panelCard, 'drop'); ui.close() }}
228
- onMore={(text) => void (async () => {
229
- if (await act(panelCard, 'more', text)) { clearMoreDraft(panelCard.id); ui.setMoreOpen(false); ui.close() }
230
- else useStore.getState().toast('your note was not sent - try again')
231
- })()} />
291
+ onMoreOpen={ui.setMoreOpen} {...recordMoves(panelCard)} />
232
292
  </FocusPanel>
233
293
  )}
234
- {ui.panel && panelCard && panelCard.kind !== 'wrapup' && (
294
+ {panel && panel.kind !== 'thread' && panelCard && panelCard.kind !== 'wrapup' && (
235
295
  <FocusPanelView
236
296
  left={sidebarRight}
237
- kind={ui.panel.kind}
297
+ kind={panel.kind}
238
298
  card={panelCard}
239
299
  of={detail?.of}
240
300
  agent={agentName}
241
301
  reviewedTitle={panelCard.reviewing ? cards?.find((c) => c.id === panelCard.reviewing!.card)?.title : undefined}
242
302
  lines={rec ? timelineLines(rec.record, panelCard.edited ?? rec.edited) : []}
243
- pictures={(rec?.record.pictures ?? []).map((id, i) => ({ id, url: picture(id)!, caption: `picture ${i + 1}` }))}
303
+ pictures={(rec?.record.pictures ?? []).map((id, i) => ({ id, url: picture(id)!, caption: pictureCaption(rec!.record, id, i + 1) }))}
244
304
  shots={changedShots(panelCard.shots).map((x) => ({ frame: x.frame, before: picture(x.before), after: picture(x.after), ...(x.new ? { new: true } : {}) }))}
245
305
  reply={panelCard.reply ? replyText(panelCard) : ''}
246
306
  view={ui.view} tab={ui.tab} moreOpen={ui.moreOpen}
247
- onTab={(i) => ui.setTab(i)} onFlip={(v) => ui.setView(v)} onMoreOpen={(on) => ui.setMoreOpen(on)}
248
- onClose={() => ui.close()}
249
- onEdit={(text) => saveEdit(panelCard, text)}
250
- onConfirm={() => void decideDraft(panelCard.id, 'confirm')}
251
- onKeep={() => void decideDraft(panelCard.id, 'keep')}
252
- onDrop={() => void decideDraft(panelCard.id, 'drop')}
253
- onResume={() => void resumeDraft(panelCard.id)}
254
- 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 }}
255
- onGood={() => { void act(panelCard, 'good'); ui.close() }}
256
- onMore={(text) => void (async () => {
257
- // the composer and its words stay until the follow-up is really queued
258
- if (await act(panelCard, 'more', text)) { clearMoreDraft(panelCard.id); ui.setMoreOpen(false); ui.close() }
259
- else useStore.getState().toast('your follow-up was not sent - try again')
260
- })()}
261
- onLater={() => { void act(panelCard, 'later'); ui.close() }}
262
- onOpenThread={() => openThread(panelCard)}
263
- asks={panelCard.thread ? { question: replyText(panelCard), onAnswer: async (text) => {
264
- const ok = await useComments.getState().replyOk(panelCard.thread!, /@marver\b/i.test(text) ? text : `@marver ${text}`)
265
- if (!ok) useStore.getState().toast('your answer was not sent - try again')
266
- else ui.close()
267
- return ok
268
- } } : undefined}
307
+ onTab={ui.setTab} onFlip={ui.setView} onMoreOpen={ui.setMoreOpen}
308
+ onClose={ui.close}
309
+ {...panelMoves(panelCard)}
269
310
  onPrev={step(-1)} onNext={step(1)} pending={pendingEdit(panelCard.id)} locked={cap.settling === panelCard.id}
270
- 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') })()}
271
311
  />
272
312
  )}
273
313
  <ContextMenu menu={cm.menu} close={cm.close} />
@@ -275,6 +315,59 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
275
315
  )
276
316
  }
277
317
 
318
+ /**
319
+ * A thread no card on the canvas can show (spec 28 A4.6 #30, r1 #3, r2 #2, r3 #1): a question with no frame, one whose
320
+ * frame left its board, an early question while its card still works, a resolved thread. Its root line, its last
321
+ * message, the status of each Jam comment card on it - the thread card's own icon, tooltip and popover, so its Retry or
322
+ * its three choices act as there - and a field that answers in the thread: with @marver when a Jam card is on the
323
+ * thread (the answer carries the work on, as the capture panel's does), as typed otherwise (a tag would start a run
324
+ * nobody asked for). Resolved, it reads only - "Resolved", no field: a reply would land in a closed thread and reopen
325
+ * nothing - and its cards' status stays, since a resolve keeps a working card running.
326
+ */
327
+ function ThreadPanel({ board, id }: { board: string; id: string }) {
328
+ const t = useComments((s) => s.threads.find((x) => x.id === id && (!x.board || x.board === board)))
329
+ const cards = useJamQueue((s) => s.cards)
330
+ const frame = useStore((s) => (t?.frame ? s.manifest?.frames.find((f) => f.id === t.frame)?.title ?? t.frame : null))
331
+ const onThread = (cards ?? []).filter((c) => c.board === board && c.thread === id)
332
+ const line = (b?: string) => (b ?? '').replace(/\s+/g, ' ').trim()
333
+ const last = t && t.replies.length ? t.replies[t.replies.length - 1] : t
334
+ const answer = async (text: string) => {
335
+ const body = onThread.length && !/@marver\b/i.test(text) ? `@marver ${text}` : text
336
+ const ok = await useComments.getState().replyOk(id, body)
337
+ if (!ok) useStore.getState().toast('your answer was not sent - try again')
338
+ return ok
339
+ }
340
+ return (
341
+ <div className="jm-panel jm-thread" data-jam-thread-panel={id} {...(t?.resolved ? { 'data-resolved': '' } : {})}>
342
+ <div className="top">
343
+ <h3>{frame ?? 'Thread'}</h3>
344
+ {t?.resolved && <span className="dim" data-jam-thread-resolved="">Resolved</span>}
345
+ </div>
346
+ <div className="jm-body">
347
+ {!t ? <p>This thread is gone.</p> : <>
348
+ <div className="jm-reply" data-jam-thread-root="">
349
+ {t.agent ? <Marver size={20} /> : <Avatar author={t.author} size={20} />}
350
+ <p>{line(t.body)}</p>
351
+ </div>
352
+ {last && last !== t && (
353
+ <div className="jm-reply" data-jam-thread-last="">
354
+ {last.agent ? <Marver size={20} /> : <Avatar author={last.author} size={20} />}
355
+ <p>{last.body}</p>
356
+ </div>
357
+ )}
358
+ {/* each Jam comment card's status, by its tag's time in the thread card: here the same icon and popover */}
359
+ {onThread.filter((c) => c.kind === 'comment').map((c) => (
360
+ <div key={c.id} className="jm-thread-status"><TagStatus board={board} eventId={c.events[c.events.length - 1]} harness={HARNESS} /></div>
361
+ ))}
362
+ {!t.resolved && (
363
+ <AsksAnswer tag={onThread.length > 0} onAnswer={answer} />
364
+ )}
365
+ </>}
366
+ </div>
367
+ </div>
368
+ )
369
+ }
370
+
278
371
  /** In play: just right of the stage's navigator (its restart and frame arrows), where the counter sits. */
279
372
  function playNavRight(): number {
280
373
  const r = document.querySelector('.sh-play-nav')?.getBoundingClientRect()
@@ -291,10 +384,26 @@ function voiceAsk(v: ReturnType<typeof useJamVoice.getState>) {
291
384
  : d?.state === 'failed' ? 'failed' as const : 'download' as const
292
385
  return {
293
386
  step, mb: v.mb, progress: d && d.total ? d.received / d.total : 0, error: v.server === 'unavailable' ? v.reason : d?.error,
294
- onYes: () => v.setChoice('yes'), onNo: () => v.setChoice('no'), onDownload: () => void v.startDownload(),
387
+ // `jam-voice` ends when the consent or the download state changed; "Not now" backed out, "Typed notes only" chose
388
+ onYes: (h: CmdHandle) => void v.setChoice('yes').then(() => h.done(), () => h.done()),
389
+ onNo: (h: CmdHandle) => { void v.setChoice('no'); if (step === 'unavailable') h.done(); else h.cancel() },
390
+ onDownload: (h: CmdHandle) => void v.startDownload().then(() => endOnDownload(h)),
295
391
  }
296
392
  }
297
393
 
394
+ /** `jam-voice`'s Download or Try again: ends with the download, as the poll sees it after the request was answered - each
395
+ * answer's `download` is a new object, so a failure from before it never counts. The listener goes once nothing more can
396
+ * be written: the command's deadline, and as long again for a late end. */
397
+ function endOnDownload(h: CmdHandle) {
398
+ const stop = useJamVoice.subscribe((s, p) => {
399
+ if (s.download === p.download && s.server === p.server) return
400
+ const d = s.download?.state
401
+ if (d === 'failed' || s.server === 'unavailable') { stop(); h.fail('download-failed') }
402
+ else if (d === 'done' || s.server === 'ready' || s.server === 'loading') { stop(); h.done() }
403
+ })
404
+ setTimeout(stop, 2 * COMMANDS['jam-voice'].deadlineMs)
405
+ }
406
+
298
407
  /** The caption's words: the newest phrase in ink, a little of what came before it dim. */
299
408
  function captionOf(heard: Heard[] | undefined): { old: string; live: string } | undefined {
300
409
  if (!heard?.length) return undefined
@@ -304,10 +413,10 @@ function captionOf(heard: Heard[] | undefined): { old: string; live: string } |
304
413
  return { old: old.join(' '), live: live.join(' ') }
305
414
  }
306
415
 
307
- /** Open a card's thread with the caret in its reply field - to add to the conversation. */
308
- function replyIn(c: JamCard) {
309
- if (!c.thread) return
310
- openThread(c)
416
+ /** Open a card's thread with the caret in its reply field - to add to the conversation. `h` ends once the thread is drawn. */
417
+ function replyIn(c: JamCard, h: CmdHandle) {
418
+ if (!c.thread) { h.fail('refused'); return }
419
+ void endOnOk(h, openThread(c))
311
420
  // once the thread's card has drawn (on another board, once that board has loaded)
312
421
  const until = performance.now() + 3_000
313
422
  const focus = () => {
@@ -320,30 +429,31 @@ function replyIn(c: JamCard) {
320
429
 
321
430
  /** A tile's right-click menu: what can be done with this capture now. */
322
431
  function tileMenu(c: JamCard): MenuItem[] {
323
- const q = useJamQueue.getState()
324
- 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) }
325
- const item = (label: string, icon: ReactNode, onClick: () => void): MenuItem => ({ label, icon, onClick })
432
+ const fresh = () => useJamQueue.getState().cards?.find((x) => x.id === c.id)
433
+ const act = (a: JamAction) => (h: CmdHandle) => { const card = fresh(); if (card) void endOnOk(h, useJamQueue.getState().act(card, a)); else h.fail('refused') }
434
+ // each item is its command: named at its click, ended by what it runs
435
+ const item = (label: string, icon: ReactNode, name: CmdName, run: (h: CmdHandle) => void): MenuItem => ({ label, icon, onClick: () => run(cmd(name, { via: 'context', in: 'shell' })) })
326
436
  // one icon per action, never two alike in a menu: open (eye), review (checklist), resume (play), rename
327
437
  // (pencil), add to queue (send arrow), keep (notebook), do next (to the top), retry, reply, thread, drop
328
- 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))
438
+ const open = item(c.state === 'review' ? 'Review' : c.state === 'draft' ? 'Open read-back' : 'Open', c.state === 'review' ? <CheckSquareOffsetIcon size={14} /> : <EyeIcon size={14} />, 'jam-open', (h) => void endOnOk(h, openTile(c.id)))
329
439
  const rename: MenuItem = { label: 'Rename', icon: <PencilSimpleIcon size={14} />, panel: (close) => <RenameField card={c} close={close} /> }
330
- const reply = c.thread ? [item('Reply in thread', <ArrowBendUpLeftIcon size={14} />, () => replyIn(c))] : []
331
- const thread = c.thread ? [item('Open thread', <CommentIcon size={14} />, () => openThread(c))] : []
440
+ const reply = c.thread ? [item('Reply in thread', <ArrowBendUpLeftIcon size={14} />, 'jam-reply', (h) => replyIn(c, h))] : []
441
+ const thread = c.thread ? [item('Open thread', <CommentIcon size={14} />, 'jam-thread', (h) => void endOnOk(h, openThread(c)))] : []
332
442
  switch (c.state) {
333
- case 'draft': return [open, item('Resume capture', <PlayIcon size={14} />, () => void resumeDraft(c.id)), rename,
334
- 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')),
335
- item('Drop', <XIcon size={14} />, () => void decideDraft(c.id, 'drop'))]
443
+ case 'draft': return [open, item('Resume capture', <PlayIcon size={14} />, 'jam-resume', (h) => void endOnOk(h, resumeDraft(c.id))), rename,
444
+ item('Add to queue', <ArrowUpIcon size={14} />, 'jam-confirm', (h) => void endOnOk(h, decideDraft(c.id, 'confirm'))), item('Keep, do not send', <NotebookIcon size={14} />, 'jam-keep', (h) => void endOnOk(h, decideDraft(c.id, 'keep'))),
445
+ item('Drop', <XIcon size={14} />, 'jam-drop', (h) => void endOnOk(h, decideDraft(c.id, 'drop')))]
336
446
  case 'queued': return c.kind === 'capture'
337
- ? [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'))]
338
- : [open, item('Drop', <XIcon size={14} />, () => act('drop'))] // a queued record: open or drop it
447
+ ? [open, rename, item('Do next', <ArrowLineUpIcon size={14} />, 'jam-do-next', act('first')), item('Keep, do not send', <NotebookIcon size={14} />, 'jam-keep', act('keep')), item('Drop', <XIcon size={14} />, 'jam-drop', act('drop'))]
448
+ : [open, item('Drop', <XIcon size={14} />, 'jam-drop', act('drop'))] // a queued record: open or drop it
339
449
  case 'review': return [open, ...reply, ...thread, rename]
340
450
  case 'asks': return [...reply, open, rename]
341
- case 'failed': return [item('Retry', <ReloadIcon size={14} />, () => act('retry')), open, ...thread, item('Drop', <XIcon size={14} />, () => act('drop'))]
451
+ case 'failed': return [item('Retry', <ReloadIcon size={14} />, 'jam-retry', act('retry')), open, ...thread, item('Drop', <XIcon size={14} />, 'jam-drop', act('drop'))]
342
452
  case 'working': {
343
453
  // a run your session went quiet on (spec 29b): give it back, run it in the background, or drop it
344
454
  if (c.runner?.kind !== 'session' || c.runner.state !== 'stalled') return [open, ...reply, ...thread, rename]
345
- const run = (a: 'again' | 'background' | 'drop') => () => { const fresh = useJamQueue.getState().cards?.find((x) => x.id === c.id); if (fresh) void useJamQueue.getState().runAct(fresh, a) }
346
- return [item('Give it back to your session', <ReloadIcon size={14} />, run('again')), item('Run it in the background', <ArrowUpIcon size={14} />, run('background')), open, ...thread, item('Drop it', <XIcon size={14} />, run('drop'))]
455
+ const run = (a: 'again' | 'background' | 'drop') => (h: CmdHandle) => { const card = fresh(); if (card) void endOnOk(h, useJamQueue.getState().runAct(card, a)); else h.fail('refused') }
456
+ return [item('Give it back to your session', <ReloadIcon size={14} />, 'jam-again', run('again')), item('Run it in the background', <ArrowUpIcon size={14} />, 'jam-background', run('background')), open, ...thread, item('Drop it', <XIcon size={14} />, 'jam-drop', run('drop'))]
347
457
  }
348
458
  default: return [open, ...reply, ...thread, rename]
349
459
  }
@@ -354,16 +464,22 @@ function RenameField({ card, close }: { card: JamCard; close: () => void }) {
354
464
  const [text, setText] = useState(card.named ? card.title ?? '' : card.title === 'Capture' ? '' : card.title ?? '')
355
465
  const ref = useRef<HTMLInputElement>(null)
356
466
  useEffect(() => { requestAnimationFrame(() => ref.current?.select()) }, [])
357
- const save = async () => {
467
+ const save = async (h: CmdHandle) => {
358
468
  const fresh = useJamQueue.getState().cards?.find((x) => x.id === card.id)
359
- if (fresh && !(await useJamQueue.getState().act(fresh, 'rename', text))) useStore.getState().toast('the capture could not be renamed - look again')
469
+ if (!fresh) h.fail('refused')
470
+ else if (!(await endOnOk(h, useJamQueue.getState().act(fresh, 'rename', text)))) useStore.getState().toast('the capture could not be renamed - look again')
360
471
  close()
361
472
  }
362
473
  return (
363
474
  <div className="jm-rename">
364
475
  <input ref={ref} value={text} maxLength={80} placeholder="Name this capture" aria-label="Capture name"
365
476
  onChange={(e) => setText(e.target.value)}
366
- onKeyDown={(e) => { e.stopPropagation(); if (e.key === 'Enter') void save(); if (e.key === 'Escape') close() }} />
477
+ onKeyDown={(e) => {
478
+ e.stopPropagation()
479
+ const how: CmdOpts = { via: 'key', in: 'shell', keys: keysOf(e) }
480
+ if (e.key === 'Enter') void save(cmd('jam-rename', how))
481
+ if (e.key === 'Escape') { cmd('jam-rename', how).cancel(); close() }
482
+ }} />
367
483
  </div>
368
484
  )
369
485
  }
@@ -16,6 +16,7 @@ import { UNPLACED, bootHash, parseHash, retargetBoot, writeHash } from './hash.t
16
16
  import { isLegacyLink, landLegacy } from './legacy-links.ts'
17
17
  import { useComments } from './comments-store.ts'
18
18
  import { isLatest, navigated, switchFor } from './goto.ts'
19
+ import { cmd, endAfterFrames, endOnLoad, endOnStage, shellReload, type CmdHandle } from './commands.ts'
19
20
 
20
21
  /** App.tsx's headless-run probe (perf-run-probe.ts): a run's page is always a dev canvas, never a locked bundle. */
21
22
  export function startPerfRunProbe(): void {}
@@ -29,7 +30,7 @@ export class ShellBoundary extends Component<{ children: ReactNode }, { err: Err
29
30
  <div style={{ fontFamily: 'ui-monospace, monospace', padding: 32 }}>
30
31
  <b style={{ color: '#a81f16' }}>shell crashed</b>
31
32
  <pre style={{ whiteSpace: 'pre-wrap', fontSize: 12 }}>{this.state.err.message}</pre>
32
- <button onClick={() => location.reload()}>reload</button>
33
+ <button onClick={() => { shellReload(cmd('shell-reload', { via: 'click', in: 'shell' })); location.reload() }}>reload</button>
33
34
  </div>
34
35
  )
35
36
  }
@@ -100,9 +101,17 @@ export function App() {
100
101
 
101
102
  // back/forward + pasted links, within what the lock allows
102
103
  useEffect(() => {
104
+ let recorded: { hash: string; at: number; h: CmdHandle | null; run: number } = { hash: '', at: -1_000, h: null, run: 0 }
103
105
  const onPop = async () => {
104
106
  // a lookup newer navigation overtook - a link, a goto, a step on the stage - is dropped
105
107
  const nav = navigated(), was = useStore.getState()
108
+ // spec 30: back/forward fires popstate AND hashchange; the second carries the first's command on
109
+ const hash = location.hash
110
+ const again = hash === recorded.hash && performance.now() - recorded.at < 250
111
+ const run = recorded.run + 1
112
+ const nav_ = again ? recorded.h : cmd('history-nav', { via: 'click', in: 'shell' })
113
+ recorded = { hash, at: performance.now(), h: nav_, run }
114
+ const giveUp = () => { if (recorded.run === run) nav_?.cancel('superseded') }
106
115
  const parsed = parseHash()
107
116
  const raw = parsed.board === UNPLACED ? {} : parsed // dev's view, and what it names: not here
108
117
  // an old All Scenes link lands on a real board; it, and the bare #/, with no board: the landing one
@@ -110,17 +119,24 @@ export function App() {
110
119
  const h = r.hash
111
120
  const board = h.board ?? (h.focus ? undefined : await landingBoard())
112
121
  const s = useStore.getState()
113
- if (!isLatest(nav) || s.board !== was.board || s.play?.at !== was.play?.at) return
122
+ if (!isLatest(nav) || s.board !== was.board || s.play?.at !== was.play?.at) return giveUp()
114
123
  if (r.notice) s.toast(r.notice)
115
124
  if (h.c) pendingThread = h.c
116
125
  if (board && board !== s.board) {
117
- if (!await switchFor(board, nav)) return // failed, or a newer navigation's board and stage by now
126
+ if (nav_) endOnLoad(nav_, board) // another board: its load's way ends it (#49)
127
+ if (!await switchFor(board, nav)) return giveUp() // failed, or a newer navigation's board and stage by now
118
128
  useStore.getState().setPlay(null) // the stage restarts on the board the link names, at its frame
119
129
  if (h.play?.slides) enterSlides(h.play)
120
130
  else if (h.play) enterPlay(h.play)
121
131
  else land(h.f?.[0])
122
132
  return
123
133
  }
134
+ // the same board: the stage's next screen when it moves, else the change once drawn (#49)
135
+ const toStage = (at?: string) => { if (nav_) { if (s.play && (!at || at === s.play.at)) endAfterFrames(nav_); else endOnStage(nav_, at) } }
136
+ if (h.f?.length && s.play) toStage(h.f[0])
137
+ else if (h.focus) toStage(h.focus.at)
138
+ else if (h.play) toStage(h.play.at)
139
+ else if (nav_) endAfterFrames(nav_) // a thread link, or the board itself: nothing else moves
124
140
  openPending() // same board: its comments are here already
125
141
  if (h.f?.length && s.play) return playCtl.setAt(h.f[0]) // the stage on screen steps to the frame named
126
142
  if (h.focus) enterFocus(h.focus.at, { ...h.focus, deep: true })