@marver-design/marver 0.25.1 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/README.md +5 -3
  3. package/dist/{anchor-DVV732zR.mjs → anchor-5H1vnoLu.mjs} +6 -1
  4. package/dist/{anchor-check-DGZnYviN.mjs → anchor-check-l-ny3UzH.mjs} +1 -1
  5. package/dist/audio-Dw1lfMdb.mjs +443 -0
  6. package/dist/{auth-DdUKeVKt.mjs → auth-Dix8wrXV.mjs} +1 -1
  7. package/dist/{bake-BpxMZfij.mjs → bake-C-awKgLA.mjs} +1 -1
  8. package/dist/{boards-Csxj2WJn.mjs → boards-DYG22tOe.mjs} +2 -2
  9. package/dist/{build-DKaGhoVN.mjs → build-BDRiO_mP.mjs} +16 -9
  10. package/dist/capture-vadKjuCo.mjs +730 -0
  11. package/dist/cli.mjs +24 -18
  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-DL6Fwq6D.mjs +2569 -0
  18. package/dist/{dev-Diqx1Rt8.mjs → dev-Bw_qYWWq.mjs} +202 -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-DyWMv_Z1.mjs} +23 -5
  28. package/dist/{marver-id-gate-DGANtVyC.mjs → marver-id-gate-BjF6v4bT.mjs} +4 -4
  29. package/dist/perf-C75MZ73h.mjs +167 -0
  30. package/dist/{perf-CCisg-ny.mjs → perf-DPbLGhhO.mjs} +1 -1
  31. package/dist/perf-jam-BU3TVrZu.mjs +239 -0
  32. package/dist/{plugin-dTF5reck.mjs → plugin-DkGmZs_r.mjs} +298 -38
  33. package/dist/{poster-D-zjYpgk.mjs → poster-BdtSKMDm.mjs} +2 -1
  34. package/dist/{profile-Do0nGkXO.mjs → profile-WU9qcbIo.mjs} +1 -1
  35. package/dist/{publish-bakes-C_9VZ-Mq.mjs → publish-bakes-9RzRToXV.mjs} +3 -3
  36. package/dist/queue-29ok5_eZ.mjs +1319 -0
  37. package/dist/reserve-BURNQ2Y3.mjs +53 -0
  38. package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-8H4AJuhK.mjs} +1 -0
  39. package/dist/{serve-wv2QWdxB.mjs → serve-C8rVheYk.mjs} +12 -12
  40. package/dist/session-BAaJsK5c.mjs +191 -0
  41. package/dist/{share-ScamJcks.mjs → share--oFJ1bCI.mjs} +2 -2
  42. package/dist/{shot-CUlmkqFX.mjs → shot-DQeR_Pfn.mjs} +339 -20
  43. package/dist/shot-XQV7HC9A.mjs +139 -0
  44. package/dist/speech-models-DomiLQcY.mjs +299 -0
  45. package/dist/speech-worker.mjs +354 -0
  46. package/dist/{summary-CrW88e3q.mjs → summary-Y8MY1Wuc.mjs} +2 -2
  47. package/dist/{sync-C3035OnJ.mjs → sync-DKk-yT1V.mjs} +9 -8
  48. package/dist/{work-GE88wb_3.mjs → work-F5u-twpJ.mjs} +28 -5
  49. package/dist/{work-CpJn1gwY.mjs → work-VvX_JIgl.mjs} +2 -2
  50. package/docs/jam-session.md +194 -0
  51. package/docs/live-jam.md +29 -3
  52. package/package.json +7 -1
  53. package/src/client/frame-host/bridge.js +20 -2
  54. package/src/client/frame-host/inspect.d.ts +4 -0
  55. package/src/client/frame-host/inspect.js +96 -6
  56. package/src/client/frame-host/keys.d.ts +6 -0
  57. package/src/client/frame-host/keys.js +59 -0
  58. package/src/client/frame-host/trail.d.ts +7 -0
  59. package/src/client/frame-host/trail.js +204 -0
  60. package/src/client/shell/App.tsx +52 -8
  61. package/src/client/shell/Comments.tsx +20 -6
  62. package/src/client/shell/JamSurface.tsx +346 -0
  63. package/src/client/shell/Play.tsx +32 -9
  64. package/src/client/shell/Tip.tsx +8 -3
  65. package/src/client/shell/Toolbar.tsx +5 -4
  66. package/src/client/shell/canvas/Canvas.tsx +12 -2
  67. package/src/client/shell/canvas/FrameNode.tsx +14 -4
  68. package/src/client/shell/comments-store.ts +23 -16
  69. package/src/client/shell/icons.tsx +17 -0
  70. package/src/client/shell/jam-capture.ts +1005 -0
  71. package/src/client/shell/jam-keys.ts +358 -0
  72. package/src/client/shell/jam-lane.tsx +249 -0
  73. package/src/client/shell/jam-lines.ts +115 -0
  74. package/src/client/shell/jam-panel.tsx +556 -0
  75. package/src/client/shell/jam-queue.ts +126 -0
  76. package/src/client/shell/jam-session.tsx +389 -0
  77. package/src/client/shell/jam-state.ts +103 -0
  78. package/src/client/shell/jam-surface-parts.tsx +106 -0
  79. package/src/client/shell/jam-ui.tsx +104 -0
  80. package/src/client/shell/jam-voice.ts +479 -0
  81. package/src/client/shell/sound.ts +22 -0
  82. package/src/client/shell/stage-size.ts +11 -0
  83. package/src/client/shell/store.ts +47 -17
  84. package/src/client/shell/styles.css +564 -2
  85. package/src/client/stage/main.tsx +18 -2
  86. package/src/shared/capture-frames.ts +41 -0
  87. package/src/shared/events.ts +19 -4
  88. package/src/shared/speech.ts +16 -0
  89. package/templates/AGENTS-embedded.md +10 -2
  90. package/templates/AGENTS-studio.md +10 -2
  91. package/templates/instructions/iterate.md +8 -6
  92. package/templates/instructions/jam.md +131 -59
  93. package/dist/daemon-Cl8KXGW4.mjs +0 -1523
  94. package/dist/perf-QJIWtTw1.mjs +0 -68
  95. package/dist/shot-jdO_B6Qw.mjs +0 -86
@@ -0,0 +1,126 @@
1
+ /**
2
+ * The jam queue as the page sees it (spec 27): the cards the dev server holds, fetched once and then
3
+ * pushed on every change (`sh:jam-queue`). A tag's card shows only in its thread - the status icon by
4
+ * its time - so the page needs the card, its state and its one move (Drop while queued, Retry when
5
+ * failed). A card that fails raises one notice; nothing else here interrupts.
6
+ */
7
+ import { create } from 'zustand'
8
+ import { ROUTE } from '../const.ts'
9
+ import { PUBLISHED } from './store.ts'
10
+
11
+ export type JamAction = 'drop' | 'retry' | 'keep' | 'first' | 'confirm' | 'edit' | 'good' | 'more' | 'later' | 'rename' | 'note'
12
+ export type JamCardState = 'draft' | 'confirming' | 'queued' | 'working' | 'asks' | 'review' | 'done' | 'kept' | 'failed' | 'dropped'
13
+ export interface JamCard {
14
+ id: string; kind: 'comment' | 'capture' | 'wrapup'; board: string; thread?: string; frames: string[]; events: string[]
15
+ state: JamCardState; note?: string; rev: number; made: number; order: number; at: number
16
+ follows?: string; reply?: string; position?: number; waiting?: string; exclusive?: boolean; batch?: string
17
+ // captures: the lane and the review
18
+ title?: string; inRun?: boolean; shots?: { frame: string; before?: string; after?: string; same?: boolean; new?: boolean }[]
19
+ reviewing?: { card: string; batch: string; rev: number }; edited?: string; added?: { at: number; text: string }[]; notes?: number; capture?: string
20
+ /** the title is the name you gave it (Rename), not its first words */
21
+ named?: boolean
22
+ /** its name - yours, or the one a small model gave it from its words */
23
+ name?: string
24
+ /** the session it was made in (a capture), or whose record it writes (a wrap-up) */
25
+ session?: string
26
+ /** a session record: the file it writes */
27
+ file?: string
28
+ }
29
+ /** The review's frames: the ones the run changed (all of them when none did - there is still a before
30
+ * and after to look at). */
31
+ export const changedShots = (shots: JamCard['shots']) => { const all = shots ?? []; const changed = all.filter((x) => !x.same); return changed.length ? changed : all }
32
+
33
+ interface QueueState {
34
+ /** null: no queue here (published, jam off, or not loaded yet) - no icon anywhere */
35
+ cards: JamCard[] | null
36
+ agent: string | null
37
+ /** the lane's run, while one lasts */
38
+ run: { since: number } | null
39
+ /** the Jam session running now (spec 27 Part 5) */
40
+ session: { id: string; since: number } | null
41
+ load(): Promise<void>
42
+ apply(view: unknown): void
43
+ /** A session this page ended (the server said so): gone at once, and no view shows it again */
44
+ forget(session: string): void
45
+ act(card: JamCard, action: JamAction, body?: string): Promise<boolean>
46
+ }
47
+
48
+ const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
49
+ const PENDING: JamCardState[] = ['queued', 'working', 'asks', 'failed', 'draft', 'confirming']
50
+
51
+ /** The card a thread message stands for, by its event id - the LAST tag of the card carries the
52
+ * icon (joined tags carry one), and only while there is something to wait for or act on. */
53
+ export function cardForEvent(cards: JamCard[] | null, board: string | undefined, eventId: string | undefined): JamCard | undefined {
54
+ if (!cards || !eventId) return undefined
55
+ // a capture's comment (`cap-<id>-e`) wears its capture card's state
56
+ const cap = /^cap-(.+)-e$/.exec(eventId)?.[1]
57
+ if (cap) return cards.find((c) => c.id === cap && PENDING.includes(c.state) && c.state !== 'draft')
58
+ return cards.find((c) => c.kind === 'comment' && (!board || c.board === board) && c.events[c.events.length - 1] === eventId && PENDING.includes(c.state))
59
+ }
60
+
61
+ export const useJamQueue = create<QueueState>((set, get) => {
62
+ let loaded = false
63
+ /** the newest view applied: an older one (a slow answer overtaken by a push) is never applied over it */
64
+ let seen: { boot: string; n: number } | null = null
65
+ /** sessions known to be over: a view built before the end (however it arrives) never brings one back */
66
+ const over = new Set<string>()
67
+ return {
68
+ cards: null,
69
+ agent: null,
70
+ run: null,
71
+ session: null,
72
+ async load() {
73
+ if (PUBLISHED) return
74
+ try {
75
+ const res = await fetch(`${ROUTE}/api/jam/queue`, { headers: { 'x-mv-c': csrf() } })
76
+ if (res.ok) get().apply(await res.json())
77
+ } catch { /* no queue: no icons */ }
78
+ },
79
+ apply(view) {
80
+ const v = (view && typeof view === 'object' ? view : {}) as { cards?: unknown; agent?: unknown }
81
+ if (!Array.isArray(v.cards)) return
82
+ const seq = (v as { seq?: { boot?: unknown; n?: unknown } }).seq
83
+ if (seq && typeof seq.boot === 'string' && typeof seq.n === 'number') {
84
+ if (seen && seen.boot === seq.boot && seq.n <= seen.n) return
85
+ seen = { boot: seq.boot, n: seq.n }
86
+ }
87
+ const next = v.cards.filter((c): c is JamCard => !!c && typeof c === 'object' && typeof (c as JamCard).id === 'string' && typeof (c as JamCard).state === 'string')
88
+ const before = new Map((get().cards ?? []).map((c) => [c.id, c]))
89
+ const first = !loaded
90
+ loaded = true
91
+ const run = (v as { run?: { since?: unknown } }).run
92
+ const ses = (v as { session?: { id?: unknown; since?: unknown } }).session
93
+ set({ cards: next, agent: typeof v.agent === 'string' ? v.agent : null, run: run && typeof run.since === 'number' ? { since: run.since } : null,
94
+ session: ses && typeof ses.id === 'string' && typeof ses.since === 'number' && !over.has(ses.id) ? { id: ses.id, since: ses.since } : null })
95
+ if (first) return
96
+ // something to review: a soft chime, once per batch that leaves a capture to review, if the page
97
+ // has focus - never a notice (spec 27, Part 2)
98
+ const ready = new Set(next.filter((c) => c.state === 'review' && before.get(c.id)?.state !== 'review').map((c) => c.batch ?? c.id))
99
+ if (ready.size && document.hasFocus()) void import('./store.ts').then(({ CONFIG }) => {
100
+ if (CONFIG.jam?.chime === false) return
101
+ void import('./sound.ts').then(({ playChime }) => playChime())
102
+ })
103
+ // a failure interrupts once per batch: the cards that turned failed since the last look, by batch
104
+ const failed = next.filter((c) => c.state === 'failed' && before.get(c.id)?.state !== 'failed')
105
+ const byBatch = new Map<string, JamCard[]>()
106
+ for (const c of failed) { const k = c.batch ?? c.id; byBatch.set(k, [...(byBatch.get(k) ?? []), c]) }
107
+ if (failed.length) void import('./store.ts').then(({ useStore }) => {
108
+ for (const cards of byBatch.values()) useStore.getState().jamFailed(cards)
109
+ })
110
+ },
111
+ forget(session) {
112
+ over.add(session)
113
+ if (get().session?.id === session) set({ session: null })
114
+ },
115
+ async act(card, action, body) {
116
+ const res = await fetch(`${ROUTE}/api/jam/card`, {
117
+ method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
118
+ body: JSON.stringify({ id: card.id, rev: card.rev, action, ...(body !== undefined ? { body } : {}) }),
119
+ }).catch(() => null)
120
+ await get().load() // the card as it is now (its new rev) before the caller acts again
121
+ return !!res?.ok
122
+ },
123
+ }
124
+ })
125
+
126
+ if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) (window as any).__mvJamQueue = useJamQueue
@@ -0,0 +1,389 @@
1
+ /**
2
+ * The Jam session in the shell (spec 27, Part 5): `J` (or the Jam button) opens the start sheet; Start
3
+ * begins the session - the microphone (if you said yes) hears its talk between captures; `J` again ends
4
+ * it with the wrap-up sheet: every capture of the session with where it stands, your instructions to the
5
+ * agent, whether to include what was said between captures - "Write the record" queues the record job,
6
+ * "End without a record" just ends it. The record comes back as the run's last tile, reviewed in the focus
7
+ * panel like a capture.
8
+ *
9
+ * The Jam button (between Laser and Tidy): the waveform at rest; the session's minutes while one runs (a
10
+ * crossed microphone without one); a teal dot only while a capture records. Blue only on hover and press.
11
+ */
12
+ import { useEffect, useRef, useState, type CSSProperties } from 'react'
13
+ import { ROUTE } from '../const.ts'
14
+ import { setSessionEnding, useJamCapture } from './jam-capture.ts'
15
+ import { laneCards, startCapture } from './jam-keys.ts'
16
+ import { useJamQueue, type JamCard } from './jam-queue.ts'
17
+ import { useJamUi } from './jam-state.ts'
18
+ import { JamStateIcon } from './jam-ui.tsx'
19
+ import { Marver, moreDraftOf, setMoreDraft } from './jam-panel.tsx'
20
+ import { useJamVoice, voiceSession, voiceSessionEnd, voiceSessionId } from './jam-voice.ts'
21
+ import { HARNESS } from './Comments.tsx'
22
+ import { ArrowRightIcon, CaretIcon, KeyboardIcon, MicrophoneIcon, MicrophoneSlashIcon, WarningIcon, WaveformIcon } from './icons.tsx'
23
+ import { Tip } from './Tip.tsx'
24
+ import { useSessionClock } from './jam-lane.tsx'
25
+ import { CONFIG, useStore } from './store.ts'
26
+
27
+ const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
28
+ const now = () => performance.timeOrigin + performance.now()
29
+
30
+ // ---- the session's moves -------------------------------------------------------------------------------
31
+
32
+ /** Why the last session move was refused (the server's words), for the one line that says so. */
33
+ let lastError: string | undefined
34
+ async function post(body: Record<string, unknown>, onAnswer?: (ok: boolean) => void): Promise<boolean> {
35
+ const r = await fetch(`${ROUTE}/api/jam/session`, { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify(body) }).catch(() => null)
36
+ lastError = r && !r.ok ? ((await r.json().catch(() => null)) as { error?: string } | null)?.error : r ? undefined : 'marver dev did not answer'
37
+ // what the server's answer settles happens at once, never behind the refresh (which may be slow, and a push
38
+ // may come first)
39
+ try { onAnswer?.(!!r?.ok) } catch { /* the refresh still runs */ }
40
+ await useJamQueue.getState().load()
41
+ return !!r?.ok
42
+ }
43
+
44
+ /** Start a session: the dev server holds it (it survives a reload); the microphone hears its talk. */
45
+ export async function startSession(): Promise<boolean> {
46
+ const id = `ses-${Date.now()}-${Math.random().toString(36).slice(2, 8).padEnd(6, '0')}`
47
+ // this tab holds the session's microphone (a reload of it takes it back; other tabs never take it) - from
48
+ // the moment the server has it: the push of it may come before the refresh
49
+ // the talk starts once the queue shows the session - whichever comes first: the push (before the answer,
50
+ // or after it), or the refresh; a session ended meanwhile never gets the microphone
51
+ const hear = () => { if (useJamQueue.getState().session?.id === id && voiceSessionId() !== id) void voiceSession(id, now()) }
52
+ const ok = await post({ action: 'start', id }, (ok) => {
53
+ if (!ok) return
54
+ try { sessionStorage.setItem(MIC_OWNER, id) } catch { /* this page only */ }
55
+ useJamUi.getState().setSheet(null)
56
+ // the session starts capturing at once - its first capture is under way as soon as it starts (its talk
57
+ // begins when that capture ends)
58
+ // (over an open review it follows that review, as S does)
59
+ if (!useJamCapture.getState().current) startCapture(id)
60
+ hear()
61
+ })
62
+ if (!ok) { useStore.getState().toast('the session could not start - look again'); return false }
63
+ useJamUi.getState().setSheet(null)
64
+ hear()
65
+ return true
66
+ }
67
+ /** The session whose microphone this tab holds (per tab: it survives a reload, not another tab). */
68
+ export const MIC_OWNER = 'mv-jam-session-mic'
69
+ export const holdsSessionMic = (id: string): boolean => { try { return sessionStorage.getItem(MIC_OWNER) === id } catch { return false } }
70
+
71
+ /** End the session - with a record (the wrap-up's instructions and talk switch), or without one. */
72
+ export async function endSession(write: { instructions: string; includeTalk: boolean } | null, onAnswer?: () => void): Promise<boolean> {
73
+ const ses = useJamQueue.getState().session
74
+ if (!ses) { useJamUi.getState().setSheet(null); return true }
75
+ // never over a capture still recording, sealing or sending: it belongs in the session (and its record)
76
+ const cap = useJamCapture.getState()
77
+ if (cap.current || Object.keys(cap.caps).length || cap.unsent.length) {
78
+ useStore.getState().toast(cap.current ? 'a capture is recording - end it first (E), then wrap up' : 'a capture is still being sent - a moment, then wrap up')
79
+ return false
80
+ }
81
+ // from here until the server answers, no capture starts (the record must not miss it); the server also
82
+ // refuses the record while a capture of the session is open in any tab
83
+ setSessionEnding(true)
84
+ // each try is its own: an older one finishing late (its refresh slow) never frees what a newer one holds
85
+ const op = ++endingOp
86
+ const mine = () => op === endingOp
87
+ // the server's answer, acted on at once (not behind the refresh): captures may start again; refused, the
88
+ // session goes on - its talk heard again in the tab that holds its microphone, and you are told why
89
+ const answered = (ok: boolean) => {
90
+ if (!mine()) return
91
+ // ended: gone from this page at once - a capture started from here on is not the session's
92
+ if (ok) useJamQueue.getState().forget(ses.id)
93
+ setSessionEnding(false)
94
+ onAnswer?.()
95
+ if (ok) { useJamUi.getState().setSheet(null); return }
96
+ if (useJamQueue.getState().session?.id === ses.id && holdsSessionMic(ses.id) && voiceSessionId() !== ses.id) void voiceSession(ses.id, now())
97
+ useStore.getState().toast(write ? `the record could not be written - ${lastError ?? 'look again'}` : 'the session could not end - look again')
98
+ }
99
+ try {
100
+ // the talk's last words first: they belong in the transcript the record reads
101
+ await voiceSessionEnd()
102
+ return write
103
+ ? await post({ action: 'wrapup', id: ses.id, instructions: write.instructions, includeTalk: write.includeTalk, board: useStore.getState().board }, answered)
104
+ : await post({ action: 'end', id: ses.id }, answered)
105
+ } finally { if (mine()) setSessionEnding(false) }
106
+ }
107
+ /** The latest try at ending the session (each Write or End is one). */
108
+ let endingOp = 0
109
+
110
+
111
+ /** `J` (or the Jam button): at rest, the start sheet (again: closes it); in a session, the wrap-up - a
112
+ * capture recording ends first, and the wrap-up waits for its read-back to close. */
113
+ export function pressJ() {
114
+ const ui = useJamUi.getState()
115
+ if (!useJamQueue.getState().session) { ui.setSheet(ui.sheet === 'start' ? null : 'start'); return }
116
+ if (ui.sheet === 'wrap' || ui.sheet === 'wrap-pending') { ui.setSheet(null); return }
117
+ if (useJamCapture.getState().current) { useJamCapture.getState().end(); ui.setSheet('wrap-pending'); return }
118
+ ui.setSheet('wrap')
119
+ }
120
+
121
+ // ---- the Jam button ----------------------------------------------------------------------------------------
122
+
123
+ /** The session's length in minutes, ticking. */
124
+
125
+
126
+ export function JamButton({ inPlay }: { inPlay?: boolean }) {
127
+ const session = useJamQueue((s) => s.session)
128
+ const recording = useJamCapture((s) => !!s.current)
129
+ const sheet = useJamUi((s) => s.sheet)
130
+ const voice = useJamVoice()
131
+ const minutes = useSessionClock(session?.since)
132
+ // off: no, blocked, no engine - or stopped (another tab has it, the connection went) while you said yes
133
+ const micOff = voice.choice === 'no' || voice.denied || voice.server === 'unavailable' || (!!session && voice.choice === 'yes' && !voice.live && !recording)
134
+ const state = recording ? 'rec' : session ? 'live' : 'idle'
135
+ const label = session ? <><b>End the session</b><span>J</span></> : <><b>Jam session</b><span>J</span></>
136
+ return (
137
+ <Tip side="bottom" inv={inPlay} label={label}>
138
+ <button className={`sh-pill-btn jm-jam${state !== 'idle' ? ` ${state}` : ''}${sheet === 'start' || sheet === 'wrap' ? ' press' : ''}`}
139
+ data-jam-button={state} aria-label={session ? 'End the Jam session' : 'Jam session'} onClick={pressJ}>
140
+ {/* the whole session reads as on: the dot pulses from start to end, between captures too */}
141
+ {session || recording ? <i className="jm-live-dot" /> : <WaveformIcon size={16} />}
142
+ {session && <span className="jm-clock">{minutes}</span>}
143
+ {session && micOff && <MicrophoneSlashIcon size={14} className="jm-nomic" />}
144
+ </button>
145
+ </Tip>
146
+ )
147
+ }
148
+
149
+ // ---- the start sheet -----------------------------------------------------------------------------------------
150
+
151
+ /** Jam's keys, one list: the shortcuts tooltip (the key table in jam-keys.ts is the source of truth). */
152
+ export const JAM_KEYS: [string, string][] = [
153
+ ['Start a capture', 'S'], ['End it', 'E'], ['Drop it', 'esc'], ['Add a note', 'N'], ['Picture of the frame', 'I'],
154
+ ['Resume a capture', 'R'], ['The captures', 'Q'], ['Open a capture', '⏎'], ['Keep it, not sent', 'K'], ['Review the next', 'V'], ['End the session', 'J'],
155
+ ]
156
+
157
+ /** "Keyboard shortcuts": one row; hovering or focusing it shows every Jam key in one column, action then
158
+ * key, in the inverse theme. */
159
+ function ShortcutsRow() {
160
+ const [on, setOn] = useState(false)
161
+ return (
162
+ <div className={`jm-sc-row${on ? ' hover' : ''}`} tabIndex={0} data-jam-shortcuts=""
163
+ onMouseEnter={() => setOn(true)} onMouseLeave={() => setOn(false)} onFocus={() => setOn(true)} onBlur={() => setOn(false)}>
164
+ <KeyboardIcon size={15} /><span>Keyboard shortcuts</span><span className="v">View<CaretIcon size={10} style={{ transform: 'rotate(-90deg)' }} /></span>
165
+ {on && (
166
+ <div className="jm-sctip" style={{ right: 'calc(100% + 18px)', top: -8 }} role="tooltip">
167
+ <div className="hd">Jam keys</div>
168
+ {JAM_KEYS.map(([a, k]) => <div key={a}>{a}<b>{k}</b></div>)}
169
+ </div>
170
+ )}
171
+ </div>
172
+ )
173
+ }
174
+
175
+ export function StartSheet({ style }: { style?: CSSProperties }) {
176
+ const agent = useJamQueue((s) => s.agent)
177
+ const voice = useJamVoice()
178
+ const mic = voice.choice === 'yes' && voice.server !== 'unavailable' && !voice.denied
179
+ const name = agent ? HARNESS[agent] ?? agent : null
180
+ return (
181
+ <div className="jm-panel jm-sheet" data-jam-sheet="start" style={style}>
182
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
183
+ <h3>Jam session</h3>
184
+ <p>Start captures at once. Between captures the session stays on; S captures again, J wraps up.</p>
185
+ </div>
186
+ <div className="rows">
187
+ <button className="row" data-jam-mic-switch={mic ? 'on' : 'off'} onClick={() => voice.setChoice(mic ? 'no' : 'yes')}>
188
+ {mic ? <MicrophoneIcon size={15} /> : <MicrophoneSlashIcon size={15} />}
189
+ <span>Microphone<br /><small>Transcribed on this Mac{CONFIG.jam?.names ? ' · Claude Haiku names each capture from its words, sent to Anthropic' : ''}</small></span>
190
+ <span className="v">{mic ? 'On' : 'Off'}<i className={`jm-switch${mic ? ' on' : ''}`} /></span>
191
+ </button>
192
+ {name
193
+ ? <div className="row"><ArrowRightIcon size={15} /><span>Hands work to</span><span className="v"><span className="jm-agent"><i />{name}</span></span></div>
194
+ : <div className="note-line warn" style={{ margin: '4px 0' }}><WarningIcon size={14} /><span>No coding agent found - work waits in the queue.<br /><code style={{ color: 'inherit', opacity: .8 }}>npx marver init</code> sets one up.</span></div>}
195
+ </div>
196
+ <ShortcutsRow />
197
+ <div className="actions">
198
+ <span className="sp" />
199
+ <button className="jm-btn ghost" onClick={() => useJamUi.getState().setSheet(null)}>Not now</button>
200
+ <button className="jm-btn primary" onClick={() => void startSession()}>Start <kbd>⏎</kbd></button>
201
+ </div>
202
+ </div>
203
+ )
204
+ }
205
+
206
+ // ---- the wrap-up ----------------------------------------------------------------------------------------------
207
+
208
+ /** The open wrap-up sheet's Write the record (the key row calls it). */
209
+ export const wrapWrite: { current: (() => void) | null } = { current: null }
210
+
211
+ const STATE_NOTE: Partial<Record<JamCard['state'], string>> = {
212
+ draft: 'to confirm', confirming: 'sending', queued: 'queued', working: 'with the agent', asks: 'asks you', review: 'to review',
213
+ done: 'done', kept: 'kept - for the record', failed: 'failed',
214
+ }
215
+
216
+ export function WrapSheet({ style }: { style?: CSSProperties }) {
217
+ const session = useJamQueue((s) => s.session)
218
+ const cards = useJamQueue((s) => s.cards)
219
+ const run = useJamQueue((s) => s.run)
220
+ const agent = useJamQueue((s) => s.agent)
221
+ const [text, setText] = useState('')
222
+ const [talk, setTalk] = useState(true)
223
+ const [talkMin, setTalkMin] = useState(0)
224
+ const [tags, setTags] = useState(0)
225
+ const [folder, setFolder] = useState<string | null>(null)
226
+ const [busy, setBusy] = useState(false)
227
+ const field = useRef<HTMLTextAreaElement>(null)
228
+ useEffect(() => {
229
+ fetch(`${ROUTE}/api/jam/session`, { headers: { 'x-mv-c': csrf() } }).then((r) => (r.ok ? r.json() : null)).then((b) => { setTalkMin(b?.talkMinutes ?? 0); setTags(b?.tags ?? 0); setFolder(typeof b?.folder === 'string' ? b.folder : null) }, () => {})
230
+ requestAnimationFrame(() => field.current?.focus())
231
+ }, [])
232
+ // the field grows with its words: three lines at least
233
+ useEffect(() => { const el = field.current; if (el) { el.style.height = 'auto'; el.style.height = `${Math.max(el.scrollHeight, 66)}px` } }, [text])
234
+ useEffect(() => () => { wrapWrite.current = null }, [])
235
+ const tries = useRef(0) // (a hook: above the early return)
236
+ if (!session) return null
237
+ const minutes = Math.max(1, Math.round((Date.now() - session.since) / 60_000))
238
+ // the session's captures - the lane's tiles - with where each stands
239
+ const caps = laneCards(cards, run).filter((c) => c.kind === 'capture' && c.session === session.id && c.state !== 'dropped')
240
+ const name = agent ? HARNESS[agent] ?? agent : 'your agent'
241
+ // Write is busy until the server answers THIS try (an older try's late end never frees it)
242
+ const write = async () => {
243
+ if (busy) return
244
+ const n = ++tries.current
245
+ setBusy(true)
246
+ await endSession({ instructions: text.trim(), includeTalk: talk }, () => { if (n === tries.current) setBusy(false) })
247
+ if (n === tries.current) setBusy(false)
248
+ }
249
+ // ⏎ anywhere in the sheet writes the record - it never reaches a panel beneath it (jam-keys' sheet row)
250
+ wrapWrite.current = () => void write()
251
+ const summary = caps.length
252
+ ? `${caps.length} capture${caps.length === 1 ? '' : 's'} in ${minutes} min.`
253
+ : `No captures in ${minutes} min.`
254
+ return (
255
+ <div className="jm-panel jm-wrapup" data-jam-sheet="wrap" style={style}>
256
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
257
+ <div className="top"><h3>Wrap up the session</h3><span className="dim">{minutes} min</span></div>
258
+ <p>{summary}{tags ? ` ${tags} tag${tags === 1 ? ' was' : 's were'} answered in ${tags === 1 ? 'its thread' : 'their threads'}.` : ''}</p>
259
+ </div>
260
+ {caps.length > 0 && (
261
+ <div className="jm-list">
262
+ {caps.map((c) => (
263
+ <div key={c.id} className={c.state === 'done' || c.state === 'kept' ? 'dim' : undefined} data-jam-wrap-row={c.state}>
264
+ <JamStateIcon state={c.state as any} /><span>{c.title ?? 'Capture'}</span><small>{STATE_NOTE[c.state] ?? c.state}</small>
265
+ </div>
266
+ ))}
267
+ </div>
268
+ )}
269
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
270
+ <span className="hd">For {name}</span>
271
+ <textarea ref={field} className="jm-field" rows={3} value={text} data-jam-wrap-field=""
272
+ placeholder="How should it take this in? Do the checkout fixes first, file the small ideas as backlog..."
273
+ onChange={(e) => setText(e.target.value)}
274
+ onKeyDown={(e) => {
275
+ e.stopPropagation()
276
+ if ((e.nativeEvent as unknown as { isComposing?: boolean }).isComposing) return
277
+ if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); void write() }
278
+ else if (e.key === 'Escape') { e.preventDefault(); useJamUi.getState().setSheet(null) }
279
+ }} />
280
+ </div>
281
+ <div className="rows">
282
+ <button className="row" data-jam-talk={talk ? 'on' : 'off'} onClick={() => setTalk(!talk)}>
283
+ <span>Include what was said between captures</span>
284
+ <span className="v">{talkMin ? <small>{talkMin} min</small> : null}<i className={`jm-switch${talk ? ' on' : ''}`} /></span>
285
+ </button>
286
+ </div>
287
+ <p style={{ fontSize: 12, color: 'var(--glass-ink-3)', margin: 0 }}>
288
+ {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.
289
+ </p>
290
+ <div className="actions">
291
+ <button className="jm-btn ghost" onClick={() => void endSession(null)}>End without a record</button>
292
+ <span className="sp" />
293
+ <button className="jm-btn primary" disabled={busy} onClick={() => void write()}>Write the record <kbd>⏎</kbd></button>
294
+ </div>
295
+ </div>
296
+ )
297
+ }
298
+
299
+ // ---- the record, in the focus panel ------------------------------------------------------------------------
300
+
301
+ /** A session record (a wrap-up card): the page the agent wrote, its reply, and the review's moves. */
302
+ export function RecordDetail({ card, agent, more, onMore, onMoreOpen, onGood, onLater, onRetry, onDrop, of, onPrev, onNext }: {
303
+ card: JamCard; agent: string; more: boolean; of?: [number, number]
304
+ onMore(text: string): void; onMoreOpen(on: boolean): void; onGood(): void; onLater(): void
305
+ /** a record job that failed: try it again, or let it go */
306
+ onRetry(): void; onDrop(): void
307
+ onPrev?: () => void; onNext?: () => void
308
+ }) {
309
+ const [rec, setRec] = useState<{ file: string; text: string | null; reply?: string } | null>(null)
310
+ useEffect(() => {
311
+ let live = true
312
+ fetch(`${ROUTE}/api/jam/record?id=${encodeURIComponent(card.id)}`, { headers: { 'x-mv-c': csrf() } })
313
+ .then((r) => (r.ok ? r.json() : null)).then((b) => { if (live && b) setRec(b) }, () => {})
314
+ return () => { live = false }
315
+ }, [card.id, card.state, card.rev])
316
+ // unsent words outlive the panel (a click elsewhere closes it), as a capture review's do
317
+ const [note, setNoteState] = useState(() => moreDraftOf(card.id))
318
+ const setNote = (t: string) => { setNoteState(t); setMoreDraft(card.id, t) }
319
+ useEffect(() => { if (moreDraftOf(card.id) && !more) onMoreOpen(true) }, [])
320
+ // left on purpose (Esc cleared the draft): the field's words go too; closed by a click elsewhere, they stay
321
+ useEffect(() => { if (!more && !moreDraftOf(card.id)) setNoteState('') }, [more])
322
+ const field = useRef<HTMLTextAreaElement>(null)
323
+ useEffect(() => { if (more) field.current?.focus() }, [more])
324
+ const review = card.state === 'review'
325
+ const failed = card.state === 'failed'
326
+ return (
327
+ <div className="jm-panel jm-review jm-record-panel" data-jam-record="">
328
+ <div className="top">
329
+ <JamStateIcon state={card.state as any} />
330
+ <h3>{card.title ?? 'Session record'}</h3>
331
+ {of && <><span className="dim">{of[0]} of {of[1]}</span>
332
+ <button className="jm-iconbtn" disabled={!onPrev} onClick={onPrev} aria-label="Previous"><CaretIcon size={11} style={{ transform: 'rotate(90deg)' }} /></button>
333
+ <button className="jm-iconbtn" disabled={!onNext} onClick={onNext} aria-label="Next"><CaretIcon size={11} style={{ transform: 'rotate(-90deg)' }} /></button></>}
334
+ </div>
335
+ <div className="meta"><span><code>{rec?.file ?? card.file ?? 'context/sessions/'}</code></span><i /><span>{agent}</span></div>
336
+ {rec?.reply && <div className="jm-reply"><Marver size={20} /><p>{rec.reply}</p></div>}
337
+ <div className="jm-body">
338
+ {failed ? <div className="note-line err" data-jam-record-failed=""><WarningIcon size={14} /><span>The record was not written{card.note ? ` - ${card.note}` : ''}. Retry runs it again.</span></div>
339
+ : rec?.text ? <div className="jm-record">{rec.text}</div>
340
+ : <div className="note-line info"><span>{review ? 'The record file is not there - the agent may not have written it.' : card.state === 'working' ? 'The agent is writing the record...' : 'Queued - the record is written when the agent is free.'}</span></div>}
341
+ </div>
342
+ {failed && <div className="rule" />}
343
+ {failed && (
344
+ <div className="actions">
345
+ <button className="jm-btn primary" onClick={onRetry}>Retry</button>
346
+ <button className="jm-btn ghost" onClick={onDrop}>Drop</button>
347
+ </div>
348
+ )}
349
+ {review && <div className="rule" />}
350
+ {review && (more ? (
351
+ <div className="jm-more">
352
+ <textarea ref={field} className="txt" rows={1} value={note} placeholder="What should the record add or change?"
353
+ onChange={(e) => setNote(e.target.value)}
354
+ onKeyDown={(e) => {
355
+ e.stopPropagation()
356
+ if ((e.nativeEvent as unknown as { isComposing?: boolean }).isComposing) return
357
+ if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); if (note.trim()) onMore(note.trim()) }
358
+ if (e.key === 'Escape') { e.preventDefault(); setNote(''); onMoreOpen(false) }
359
+ }} />
360
+ <button className="jm-send" disabled={!note.trim()} onClick={() => onMore(note.trim())}>Send <kbd>⏎</kbd></button>
361
+ </div>
362
+ ) : (
363
+ <div className="actions">
364
+ <button className="jm-btn primary" onClick={onGood}>Looks good <kbd>⏎</kbd></button>
365
+ <button className="jm-btn" onClick={() => onMoreOpen(true)}>More work <kbd>⇧⏎</kbd></button>
366
+ <button className="jm-btn ghost" onClick={onLater}>Later <kbd>→</kbd></button>
367
+ </div>
368
+ ))}
369
+ </div>
370
+ )
371
+ }
372
+
373
+ // ---- in play: the lane folds to a counter ---------------------------------------------------------------
374
+
375
+ /** The run's captures as a counter beside the navigator, by where they stand; Q opens the lane. */
376
+ export function PlayCounter({ cards, style }: { cards: JamCard[]; style?: CSSProperties }) {
377
+ const n = (s: JamCard['state']) => cards.filter((c) => c.state === s).length
378
+ // what needs you first, then what runs; what is settled counts as one more pair (the run still shows)
379
+ const pairs = (['asks', 'failed', 'review', 'draft', 'confirming', 'working', 'queued'] as const).map((s) => [s, n(s)] as const).filter(([, k]) => k > 0)
380
+ const settled = cards.filter((c) => c.state === 'done' || c.state === 'kept').length
381
+ if (!pairs.length && !settled) return null
382
+ return (
383
+ <div className="jm-count jm-stage" data-jam-counter="" style={style} onClick={() => useJamUi.getState().setLaneKeys(true)}>
384
+ {pairs.map(([s, k]) => <span key={s}><JamStateIcon state={s as any} size={13} />{k}</span>)}
385
+ {settled > 0 && <span key="done"><JamStateIcon state="done" size={13} />{settled}</span>}
386
+ <i className="sep" /><span className="q">Q</span>
387
+ </div>
388
+ )
389
+ }
@@ -0,0 +1,103 @@
1
+ /**
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.
4
+ */
5
+ import { create } from 'zustand'
6
+
7
+ export type Panel = { kind: 'capture' | 'review' | 'wrapup'; id: string } | null
8
+
9
+ interface JamUi {
10
+ panel: Panel
11
+ /** the tile that opened the panel (or Q's focus) wears the accent ring */
12
+ selected: string | null
13
+ /** the lane has the keyboard (Q) */
14
+ laneKeys: boolean
15
+ /** the review: Both (before and after at once - 0.26.1) | Before | After, the frame tab, the More work composer */
16
+ view: 'both' | 'before' | 'after'
17
+ tab: number
18
+ moreOpen: boolean
19
+ /** bumps when the lane should come back to its right end (a new capture or draft) */
20
+ followEnd: number
21
+ /** the lane's done tiles shown (the Done group opened) - folded into one tile by default (0.26.1) */
22
+ doneOpen: boolean
23
+ /** folding hands a selected done tile's selection to the group (`doneIds`: the tiles it folds) */
24
+ setDoneOpen(open: boolean, doneIds?: string[]): void
25
+ /** the session's sheets (Part 5): the start sheet (J at rest), the wrap-up (J in a session) - or
26
+ * 'wrap-pending': J pressed while a capture recorded, the wrap-up waits for its read-back to close */
27
+ sheet: 'start' | 'wrap' | 'wrap-pending' | null
28
+ setSheet(s: JamUi['sheet']): void
29
+ open(panel: Panel): void
30
+ close(): void
31
+ setLaneKeys(on: boolean): void
32
+ select(id: string | null): void
33
+ flip(): void
34
+ /** a choice in the review's switch: Both, Before or After */
35
+ setView(view: JamUi['view']): void
36
+ setTab(i: number): void
37
+ setMoreOpen(on: boolean): void
38
+ follow(): void
39
+ }
40
+
41
+ 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,
43
+ setSheet(s) { set({ sheet: s }) },
44
+ // the next card opens on Both, its first frame
45
+ open(panel) { set({ panel, selected: panel?.id ?? get().selected, view: 'both', tab: 0, moreOpen: false }) },
46
+ close() { set({ panel: null, moreOpen: false }) },
47
+ setLaneKeys(on) { set({ laneKeys: on }) },
48
+ // folding: a done tile that was selected hands its selection to the group
49
+ // the selection follows the fold: folding, a selected done tile or the collapse tile hands it to the group; opening,
50
+ // a selected group hands it to the first done tile
51
+ setDoneOpen(open, doneIds = []) {
52
+ set((s) => ({
53
+ doneOpen: open,
54
+ ...(!open && s.selected && (s.selected === DONE_CLOSE || doneIds.includes(s.selected)) ? { selected: DONE_GROUP } : {}),
55
+ ...(open && s.selected === DONE_GROUP ? { selected: doneIds[0] ?? DONE_CLOSE } : {}),
56
+ }))
57
+ },
58
+ select(id) { set({ selected: id }) },
59
+ // B: Both -> Before -> After -> Both
60
+ flip() { set((s) => ({ view: s.view === 'both' ? 'before' : s.view === 'before' ? 'after' : 'both' })) },
61
+ setTab(i) { set({ tab: i }) },
62
+ setView(view) { set({ view }) },
63
+ setMoreOpen(on) { set({ moreOpen: on }) },
64
+ follow() { set((s) => ({ followEnd: s.followEnd + 1 })) },
65
+ }))
66
+
67
+ /** A click somewhere else - the canvas, a frame, inside an interactive frame: the read-back or review open
68
+ * closes, its tile lets go, and the lane gives the keys back (trial 1: "anywhere on the canvas should
69
+ * close the review card and deselect the capture card"). Words being edited in the read-back save first:
70
+ * the field is left before the panel goes. */
71
+ export function letGoOfTile() {
72
+ const s = useJamUi.getState()
73
+ if (!s.panel && !s.selected && !s.laneKeys) return
74
+ const a = document.activeElement
75
+ if (a instanceof HTMLElement && a.closest('.jm-focus')) a.blur()
76
+ useJamUi.setState({ panel: null, moreOpen: false, selected: null, laneKeys: false })
77
+ }
78
+
79
+ if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) (window as any).__mvJamUi = useJamUi
80
+
81
+ // ---- the Done fold (0.26.1): two or more done tiles fold into one, at the lane's left end ------------------
82
+
83
+ /** The folded group's stop, and the collapse tile's when it is open. */
84
+ export const DONE_GROUP = 'jam-done-group'
85
+ export const DONE_CLOSE = 'jam-done-close'
86
+
87
+ /** How the lane shows `items` (oldest first): two or more done ones fold into one group; open, they lead, behind a
88
+ * collapse tile. `stops`: the lane's keyboard stops in that order. */
89
+ export function doneFold<T extends { id: string; state: string }>(items: T[], open: boolean): { fold: boolean; done: T[]; rest: T[]; stops: string[] } {
90
+ const done = items.filter((t) => t.state === 'done')
91
+ const rest = items.filter((t) => t.state !== 'done')
92
+ const fold = done.length >= 2
93
+ const stops = !fold ? items.map((t) => t.id) : open ? [DONE_CLOSE, ...done.map((t) => t.id), ...rest.map((t) => t.id)] : [DONE_GROUP, ...rest.map((t) => t.id)]
94
+ return { fold, done, rest, stops }
95
+ }
96
+
97
+ /** What the Done group holds: "3 captures", "2 captures · 1 record", and "· 4 frames changed" when known. */
98
+ export function doneLine(done: { record?: boolean }[], frames: number): string {
99
+ const records = done.filter((t) => t.record).length, captures = done.length - records
100
+ const parts = [captures ? `${captures} capture${captures === 1 ? '' : 's'}` : '', records ? `${records} record${records === 1 ? '' : 's'}` : '', frames ? `${frames} frame${frames === 1 ? '' : 's'} changed` : ''].filter(Boolean)
101
+ return parts.join(' · ')
102
+ }
103
+