@marver-design/marver 0.25.0 → 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.
- package/CHANGELOG.md +75 -0
- package/README.md +3 -1
- package/dist/{anchor-DVV732zR.mjs → anchor-5H1vnoLu.mjs} +6 -1
- package/dist/{anchor-check-BE5VVN6Q.mjs → anchor-check-Dg5xpNnU.mjs} +1 -1
- package/dist/audio-CmSRYFEs.mjs +429 -0
- package/dist/{auth-DdUKeVKt.mjs → auth-Dix8wrXV.mjs} +1 -1
- package/dist/{bake-D8byeRzB.mjs → bake-DtVlm0_F.mjs} +45 -6
- package/dist/{boards-Csxj2WJn.mjs → boards-DYG22tOe.mjs} +2 -2
- package/dist/{build-BHoWLvSj.mjs → build-C_gUgcdC.mjs} +16 -9
- package/dist/capture-CrqvU_jh.mjs +729 -0
- package/dist/cli.mjs +23 -17
- package/dist/{collab-gqNdScUE.mjs → collab-Dxg2trOK.mjs} +4 -3
- package/dist/{comments-Zoch254k.mjs → comments-0BSbb04K.mjs} +14 -3
- package/dist/{comments-pTLlhjh4.mjs → comments-BqXua-XL.mjs} +7 -7
- package/dist/{config-cKgZBRj0.mjs → config-Cf7EjAMf.mjs} +12 -1
- package/dist/{context-D2ugHqwO.mjs → context-HQ4Giw58.mjs} +1 -1
- package/dist/daemon-DZo6o3rU.mjs +2445 -0
- package/dist/{dev-DJdgow47.mjs → dev-_Nlsc6v9.mjs} +189 -18
- package/dist/dev-lock-DWSpa6nj.mjs +179 -0
- package/dist/{events-DnK_AnrW.mjs → events-CLH4ijKP.mjs} +14 -4
- package/dist/{init-DO4DhUt_.mjs → init-D8DtrK_F.mjs} +2 -2
- package/dist/{ledger-BNXW14Xw.mjs → ledger-D54iROST.mjs} +17 -1
- package/dist/{link-C-qUIuKU.mjs → link-BNzLvdhI.mjs} +2 -2
- package/dist/live-Cgzsicwi.mjs +4 -0
- package/dist/{manifest-DnAte_fB.mjs → manifest-Nl3KSVOk.mjs} +1 -1
- package/dist/{marks-koRsbHfe.mjs → marks-CKgzucHZ.mjs} +2 -2
- package/dist/{marks-DFuintmJ.mjs → marks-NQi0wZJ4.mjs} +23 -5
- package/dist/{marver-id-gate-DGANtVyC.mjs → marver-id-gate-BjF6v4bT.mjs} +4 -4
- package/dist/{perf-QJIWtTw1.mjs → perf-D6VmmJ2q.mjs} +1 -1
- package/dist/{perf-CCisg-ny.mjs → perf-DPbLGhhO.mjs} +1 -1
- package/dist/{plugin-CTyhjwoJ.mjs → plugin-CTD0rydA.mjs} +279 -38
- package/dist/{poster-D0cbV7hi.mjs → poster-ChjXGTS5.mjs} +1 -1
- package/dist/{profile-Do0nGkXO.mjs → profile-WU9qcbIo.mjs} +1 -1
- package/dist/{publish-bakes--l8ot2eQ.mjs → publish-bakes-CEP_2NRc.mjs} +3 -3
- package/dist/queue-BuiCKSX1.mjs +1319 -0
- package/dist/reserve-BURNQ2Y3.mjs +53 -0
- package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-8H4AJuhK.mjs} +1 -0
- package/dist/{serve-wv2QWdxB.mjs → serve-C8rVheYk.mjs} +12 -12
- package/dist/session-qZWKt_VA.mjs +191 -0
- package/dist/{share-ScamJcks.mjs → share--oFJ1bCI.mjs} +2 -2
- package/dist/{shot-jdO_B6Qw.mjs → shot-CNbHoZ6H.mjs} +1 -1
- package/dist/{shot-CckrGW-J.mjs → shot-DqcxJibP.mjs} +4 -3
- package/dist/speech-models-DomiLQcY.mjs +299 -0
- package/dist/speech-worker.mjs +319 -0
- package/dist/{summary-CrW88e3q.mjs → summary-Y8MY1Wuc.mjs} +2 -2
- package/dist/{sync-C3035OnJ.mjs → sync-DKk-yT1V.mjs} +9 -8
- package/dist/{work-GE88wb_3.mjs → work-F5u-twpJ.mjs} +28 -5
- package/dist/{work-CpJn1gwY.mjs → work-VvX_JIgl.mjs} +2 -2
- package/docs/jam-session.md +177 -0
- package/docs/live-jam.md +21 -3
- package/package.json +7 -1
- package/src/client/frame-host/bridge.js +20 -2
- package/src/client/frame-host/inspect.d.ts +4 -0
- package/src/client/frame-host/inspect.js +88 -3
- package/src/client/frame-host/keys.d.ts +6 -0
- package/src/client/frame-host/keys.js +55 -0
- package/src/client/frame-host/trail.d.ts +7 -0
- package/src/client/frame-host/trail.js +204 -0
- package/src/client/shell/App.tsx +45 -5
- package/src/client/shell/Comments.tsx +20 -6
- package/src/client/shell/JamSurface.tsx +340 -0
- package/src/client/shell/Play.tsx +22 -3
- package/src/client/shell/Tip.tsx +8 -3
- package/src/client/shell/canvas/Canvas.tsx +12 -2
- package/src/client/shell/canvas/FrameNode.tsx +11 -2
- package/src/client/shell/canvas/sleep.ts +19 -1
- package/src/client/shell/comments-store.ts +23 -16
- package/src/client/shell/icons.tsx +15 -0
- package/src/client/shell/jam-capture.ts +939 -0
- package/src/client/shell/jam-keys.ts +329 -0
- package/src/client/shell/jam-lane.tsx +208 -0
- package/src/client/shell/jam-lines.ts +115 -0
- package/src/client/shell/jam-panel.tsx +506 -0
- package/src/client/shell/jam-queue.ts +126 -0
- package/src/client/shell/jam-session.tsx +389 -0
- package/src/client/shell/jam-state.ts +61 -0
- package/src/client/shell/jam-surface-parts.tsx +102 -0
- package/src/client/shell/jam-ui.tsx +104 -0
- package/src/client/shell/jam-voice.ts +479 -0
- package/src/client/shell/sound.ts +22 -0
- package/src/client/shell/stage-size.ts +11 -0
- package/src/client/shell/store.ts +34 -13
- package/src/client/shell/styles.css +544 -2
- package/src/client/stage/main.tsx +16 -2
- package/src/shared/capture-frames.ts +41 -0
- package/src/shared/events.ts +19 -4
- package/src/shared/speech.ts +16 -0
- package/templates/AGENTS-embedded.md +10 -2
- package/templates/AGENTS-studio.md +10 -2
- package/templates/instructions/iterate.md +8 -6
- package/templates/instructions/jam.md +129 -59
- package/dist/daemon-Cl8KXGW4.mjs +0 -1523
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jam V2's panels (spec 27 Parts 1-3): the focus panel the review and the capture detail open in, the
|
|
3
|
+
* read-back, the review detail, the notes card, how a capture's comment reads in its thread, and the
|
|
4
|
+
* capture's marks on the canvas (the teal edge ring, numbered points).
|
|
5
|
+
*
|
|
6
|
+
* Presentational only: every component takes what it shows and calls back what was chosen. The shell
|
|
7
|
+
* (jam-capture.ts, App) owns state, keys and the API.
|
|
8
|
+
*/
|
|
9
|
+
import { useEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react'
|
|
10
|
+
import { JamStateIcon } from './jam-ui.tsx'
|
|
11
|
+
import type { TimelineLine } from './jam-lines.ts'
|
|
12
|
+
import { speechLines } from '../../shared/speech.ts'
|
|
13
|
+
import {
|
|
14
|
+
ArrowBendUpLeftIcon, ArrowLeftIcon, ArrowRightIcon, ArrowUpIcon, CopyIcon, CursorClickIcon, CursorIcon, EyeIcon, FileCodeIcon,
|
|
15
|
+
FrameRectIcon, ImagesSquareIcon, LaserIcon, MicrophoneIcon, MoonIcon, PencilSimpleIcon, SignpostIcon, SunIcon, TextboxIcon,
|
|
16
|
+
ParallelogramFillIcon, WarningIcon, WaveformIcon, XIcon, deviceIcon,
|
|
17
|
+
} from './icons.tsx'
|
|
18
|
+
import { LANE_H } from './jam-lane.tsx'
|
|
19
|
+
import { Tip } from './Tip.tsx'
|
|
20
|
+
import { useJamQueue } from './jam-queue.ts'
|
|
21
|
+
|
|
22
|
+
/** A heading cut short by its ellipsis: its tooltip shows it whole (one that fits shows none). */
|
|
23
|
+
const cutShort = (el: HTMLElement) => el.scrollWidth > el.clientWidth + 1
|
|
24
|
+
|
|
25
|
+
/** Marver's mark, as the thread draws it (Comments.tsx MarverAvatar) - drawn here from the same classes
|
|
26
|
+
* so the panels never import the comments module (which will import these panels). */
|
|
27
|
+
export const Marver = ({ size = 20 }: { size?: number }) => (
|
|
28
|
+
<span className="cm-avatar cm-marver" style={{ width: size, height: size }} aria-label="Marver"><ParallelogramFillIcon size={Math.round(size * 0.5)} /></span>
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
// ---- the focus panel ---------------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
/** The one place a detail opens (v9): its top level with the sidebar's and the toolbar's tops, its
|
|
34
|
+
* bottom just above the lane, its left edge at `left` (the sidebar's right edge plus an inset - the
|
|
35
|
+
* shell passes it), `width` px wide (520 at least). The panel inside fills it; its middle scrolls and
|
|
36
|
+
* its footer stays in view. `onClose` adds a quiet close button in its corner. */
|
|
37
|
+
export function FocusPanel({ children, left, width = 580, onClose }: { children: ReactNode; left: number; width?: number; onClose?: () => void }) {
|
|
38
|
+
// 580: the footer's "For Claude Code" and its four actions on one line; never wider than the window allows
|
|
39
|
+
// the window is the last word: a narrow one gets a narrower panel, never one past its edge
|
|
40
|
+
const room = (typeof window !== 'undefined' ? window.innerWidth : 1400) - left - 12
|
|
41
|
+
const w = Math.min(room, Math.max(360, Math.max(580, width)))
|
|
42
|
+
return (
|
|
43
|
+
<div className="jm-focus" data-jam-focus="" style={{ left, width: w, bottom: `calc(var(--edge) + ${LANE_H + 2}px)` }}>
|
|
44
|
+
{children}
|
|
45
|
+
{onClose && <button className="jm-iconbtn jm-focus-x" aria-label="Close" onClick={onClose}><XIcon size={13} /></button>}
|
|
46
|
+
</div>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---- the timeline --------------------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
/** More work words not sent yet, by card - they survive the panel closing on a click elsewhere. */
|
|
53
|
+
const moreDrafts = new Map<string, string>()
|
|
54
|
+
export const clearMoreDraft = (id: string) => { moreDrafts.delete(id) }
|
|
55
|
+
export const moreDraftOf = (id: string): string => moreDrafts.get(id) ?? ''
|
|
56
|
+
export const setMoreDraft = (id: string, t: string) => { if (t) moreDrafts.set(id, t); else moreDrafts.delete(id) }
|
|
57
|
+
|
|
58
|
+
const unquote = (s: string) => s.replace(/^"(.*)"$/s, '$1')
|
|
59
|
+
const DEVICE: Record<string, string> = { phone: 'mobile', mobile: 'mobile', tablet: 'tablet', laptop: 'laptop', desktop: 'monitor', monitor: 'monitor', tv: 'tv' }
|
|
60
|
+
|
|
61
|
+
/** One line: time | glyph | what happened (the read-back's merged timeline, jam-lines.ts). */
|
|
62
|
+
function LineRow({ l }: { l: TimelineLine }) {
|
|
63
|
+
const ui = (s: string) => <b className="ui">{s}</b>
|
|
64
|
+
const code = l.source ? <code>{l.source.split('/').pop()}</code> : null
|
|
65
|
+
let glyph: ReactNode = null, body: ReactNode = l.text
|
|
66
|
+
switch (l.kind) {
|
|
67
|
+
case 'words': glyph = <MicrophoneIcon size={13} />; body = <span className="words">“{unquote(l.text)}”</span>; break
|
|
68
|
+
case 'note': glyph = <PencilSimpleIcon size={13} />; body = <span className="words">{unquote(l.text)}</span>; break
|
|
69
|
+
case 'view': glyph = <EyeIcon size={13} />; break
|
|
70
|
+
case 'pick': glyph = <LaserIcon size={13} />; body = <>{l.point != null && <span className="pt pick">{l.point}</span>}{l.text}{code}</>; break
|
|
71
|
+
case 'click': glyph = <CursorClickIcon size={13} />; body = <>{l.point != null && <span className="pt click">{l.point}</span>}{l.text}{code}</>; break
|
|
72
|
+
case 'hover': glyph = <CursorIcon size={13} />; body = <>{l.text}{code}</>; break
|
|
73
|
+
case 'field': glyph = <TextboxIcon size={13} />; body = <>{l.text}{code}</>; break
|
|
74
|
+
case 'screen': glyph = <ArrowRightIcon size={13} />; break
|
|
75
|
+
case 'scroll': glyph = <ArrowUpIcon size={13} style={{ transform: 'rotate(180deg)' }} />; break
|
|
76
|
+
case 'select': glyph = <FrameRectIcon size={13} />; body = <>selected {ui(l.text)}</>; break
|
|
77
|
+
case 'device': {
|
|
78
|
+
const name = (l.text.split(' · ')[1] ?? '').split(' ')[0].toLowerCase()
|
|
79
|
+
glyph = deviceIcon(DEVICE[name] ?? null, 13); body = <>viewed at {ui(l.text.split(' · ').slice(1).join(' · ') || l.text)}</>; break
|
|
80
|
+
}
|
|
81
|
+
case 'theme': glyph = l.text === 'dark' ? <MoonIcon size={13} /> : <SunIcon size={13} />; body = <>switched to {ui(l.text)}</>; break
|
|
82
|
+
case 'copied': {
|
|
83
|
+
const [what, of] = l.text.split(' of ')
|
|
84
|
+
glyph = what === 'path' ? <SignpostIcon size={13} /> : <CopyIcon size={13} />; body = <>copied the {what} of {ui(of ?? '')}</>; break
|
|
85
|
+
}
|
|
86
|
+
case 'interact': glyph = <CursorClickIcon size={13} />; body = <>interactive mode {ui(l.text)}</>; break
|
|
87
|
+
case 'picture': glyph = <ImagesSquareIcon size={13} />; body = <>picture {l.point} · {l.text}</>; break
|
|
88
|
+
case 'missing': glyph = <WarningIcon size={13} />; body = <span className="miss">{l.text}</span>; break
|
|
89
|
+
}
|
|
90
|
+
return <div data-kind={l.kind}><span className="ts">{l.t}</span><span className="g">{glyph}</span><span>{body}</span></div>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The merged timeline: words and notes among every step, each at its moment. */
|
|
94
|
+
export const Lines = ({ lines }: { lines: TimelineLine[] }) => <div className="jm-lines">{lines.map((l, i) => <LineRow key={i} l={l} />)}</div>
|
|
95
|
+
|
|
96
|
+
const newNoteId = () => `n-${Math.random().toString(36).slice(2, 12).padEnd(8, '0')}`
|
|
97
|
+
|
|
98
|
+
/** Notes written in a read-back after the capture ended: under a divider, in the timeline's own rows, then a
|
|
99
|
+
* clean field and Add note (⏎). What you type is never a capture key. */
|
|
100
|
+
function AddedNotes({ added, onAdd }: { added: { at: number; text: string }[]; onAdd?: (text: string, id: string) => Promise<boolean> }) {
|
|
101
|
+
const [text, setText] = useState('')
|
|
102
|
+
const [busy, setBusy] = useState(false)
|
|
103
|
+
// the note in the field: one id until it saves (a failed one sent again is the same note)
|
|
104
|
+
const nid = useRef(newNoteId())
|
|
105
|
+
const add = async () => {
|
|
106
|
+
const t = text.trim()
|
|
107
|
+
if (!t || busy || !onAdd) return
|
|
108
|
+
setBusy(true)
|
|
109
|
+
const ok = await onAdd(t, nid.current)
|
|
110
|
+
setBusy(false)
|
|
111
|
+
if (ok) { setText(''); nid.current = newNoteId() }
|
|
112
|
+
}
|
|
113
|
+
return (
|
|
114
|
+
<div className="jm-added" data-jam-added="">
|
|
115
|
+
{added.length > 0 && <>
|
|
116
|
+
<div className="jm-added-rule"><span>Added after</span></div>
|
|
117
|
+
<div className="jm-lines">{added.map((a, i) => (
|
|
118
|
+
<div key={i} data-jam-added-note=""><span className="ts">{new Date(a.at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</span><span className="g"><PencilSimpleIcon size={12} /></span><span className="words">{a.text}</span></div>
|
|
119
|
+
))}</div>
|
|
120
|
+
</>}
|
|
121
|
+
{onAdd && (
|
|
122
|
+
<div className="jm-addnote">
|
|
123
|
+
{/* read-only while it saves (never disabled: a disabled field lets its focus go, and the next ⏎ would
|
|
124
|
+
reach the read-back's own keys) */}
|
|
125
|
+
<input value={text} placeholder="Add a note..." data-jam-addnote="" readOnly={busy}
|
|
126
|
+
onChange={(e) => setText(e.target.value)}
|
|
127
|
+
onKeyDown={(e) => {
|
|
128
|
+
e.stopPropagation()
|
|
129
|
+
if ((e.nativeEvent as unknown as { isComposing?: boolean }).isComposing) return
|
|
130
|
+
if (e.key === 'Enter') { e.preventDefault(); void add() }
|
|
131
|
+
else if (e.key === 'Escape') { e.preventDefault(); setText(''); (e.target as HTMLInputElement).blur() }
|
|
132
|
+
}} />
|
|
133
|
+
<button className="jm-btn" disabled={!text.trim() || busy} onClick={() => void add()}>Add note</button>
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** A picture, or the dashed "No picture" where a shot failed. */
|
|
141
|
+
export const Shot = ({ url, cap, alt }: { url?: string; cap?: ReactNode; alt?: string }) => (
|
|
142
|
+
<div className="jm-shot">
|
|
143
|
+
{url ? <div className="pic"><img src={url} alt={alt ?? ''} draggable={false} /></div> : <div className="pic none"><ImagesSquareIcon size={13} />No picture</div>}
|
|
144
|
+
{cap && <span className="cap">{cap}</span>}
|
|
145
|
+
</div>
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
/** "1 of 3" with its arrows - the walk's ends disable the arrow that has nowhere to go. */
|
|
149
|
+
const Walk = ({ of, onPrev, onNext }: { of?: [number, number]; onPrev?: () => void; onNext?: () => void }) => of ? (
|
|
150
|
+
<>
|
|
151
|
+
<span className="dim">{of[0]} of {of[1]}</span>
|
|
152
|
+
<button className="jm-iconbtn" disabled={of[0] <= 1 || !onPrev} onClick={onPrev} aria-label="Previous"><ArrowLeftIcon size={13} /></button>
|
|
153
|
+
<button className="jm-iconbtn" disabled={of[0] >= of[1] || !onNext} onClick={onNext} aria-label="Next"><ArrowRightIcon size={13} /></button>
|
|
154
|
+
</>
|
|
155
|
+
) : null
|
|
156
|
+
|
|
157
|
+
const Meta = ({ items }: { items: ReactNode[] }) => (
|
|
158
|
+
<div className="meta">{items.map((m, i) => <span key={i} style={{ display: 'contents' }}>{i > 0 && <i />}<span>{m}</span></span>)}</div>
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
// ---- the read-back --------------------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A capture's detail (the read-back of a draft; read-only once confirmed). Head: its first words and
|
|
165
|
+
* "1 of N". Then a line of meta (length, frames, points, pictures, notes, steps), the pictures large
|
|
166
|
+
* (two to a row), and the merged timeline. Click the timeline to edit the words (a field; saved on blur
|
|
167
|
+
* through `onEdit`). A draft's footer names the agent: Drop (esc), Keep (K), Add to queue (⏎). Read-only
|
|
168
|
+
* shows Open thread instead.
|
|
169
|
+
*
|
|
170
|
+
* `edited` = your edit so far (the field opens on it; else on the words of `lines`); `editing` opens
|
|
171
|
+
* the field from outside (it is also opened by a click); `follows` = the reviewed card's title for a
|
|
172
|
+
* capture made during a review; `err` = a confirm that failed closed; `warn` = degraded content
|
|
173
|
+
* ("words may be incomplete").
|
|
174
|
+
*/
|
|
175
|
+
export function ReadBack({ title, head, of, onPrev, onNext, meta, lines, pictures, edited, pending, editing, onEdit, onRetry, onConfirm, onKeep, onDrop, onResume, agent, follows, readOnly, locked, onOpenThread, added, onAddNote, autoNamed, err, warn, style }: {
|
|
176
|
+
title: string
|
|
177
|
+
/** beside the title: the Review | Capture switch (a capture under review) */
|
|
178
|
+
head?: ReactNode
|
|
179
|
+
of?: [number, number]
|
|
180
|
+
onPrev?: () => void
|
|
181
|
+
onNext?: () => void
|
|
182
|
+
meta: ReactNode[]
|
|
183
|
+
lines: TimelineLine[]
|
|
184
|
+
pictures: { id: string; url: string; caption: ReactNode }[]
|
|
185
|
+
edited?: string
|
|
186
|
+
/** words written that have not saved yet - they win over `edited` */
|
|
187
|
+
pending?: string
|
|
188
|
+
/** a failed capture: its Retry (with Drop beside it) in the read-only footer */
|
|
189
|
+
onRetry?: () => void
|
|
190
|
+
editing?: boolean
|
|
191
|
+
onEdit?: (text: string) => void
|
|
192
|
+
onConfirm?: () => void
|
|
193
|
+
onKeep?: () => void
|
|
194
|
+
onDrop?: () => void
|
|
195
|
+
/** ended too soon: recording goes on where it stopped (R) */
|
|
196
|
+
onResume?: () => void
|
|
197
|
+
agent?: string | null
|
|
198
|
+
follows?: string
|
|
199
|
+
readOnly?: boolean
|
|
200
|
+
/** the words cannot be edited for now (its Resume is starting) - the rest stays as it is */
|
|
201
|
+
locked?: boolean
|
|
202
|
+
onOpenThread?: () => void
|
|
203
|
+
/** notes written here after it ended - under a divider, as the timeline shows its own */
|
|
204
|
+
added?: { at: number; text: string }[]
|
|
205
|
+
/** the title came from Claude Haiku (jam.names): its tooltip says so, and where the words went */
|
|
206
|
+
autoNamed?: boolean
|
|
207
|
+
/** a note added from here (a draft): resolves whether it saved */
|
|
208
|
+
onAddNote?: (text: string, id: string) => Promise<boolean>
|
|
209
|
+
err?: ReactNode
|
|
210
|
+
warn?: ReactNode
|
|
211
|
+
style?: CSSProperties
|
|
212
|
+
}) {
|
|
213
|
+
const [open, setOpen] = useState(!!editing)
|
|
214
|
+
useEffect(() => { if (editing) setOpen(true) }, [editing])
|
|
215
|
+
// the words and the notes, in time order - what the capture says (server captureWords)
|
|
216
|
+
const words = speechLines(lines.flatMap((l) => (l.kind === 'words' || l.kind === 'note' ? [{ kind: l.kind, text: unquote(l.text) }] : [])))
|
|
217
|
+
const [text, setText] = useState(pending ?? edited ?? words)
|
|
218
|
+
// the field follows the saved edit only while you are not writing and nothing newer waits to save
|
|
219
|
+
// (`pending`): an older save's answer never overwrites newer words, and a failed one never loses them
|
|
220
|
+
useEffect(() => { if (!open) setText(pending ?? edited ?? words) }, [edited, words, pending])
|
|
221
|
+
const field = useRef<HTMLTextAreaElement>(null)
|
|
222
|
+
useEffect(() => { if (open) { const el = field.current; if (el) { el.focus(); el.setSelectionRange(el.value.length, el.value.length) } } }, [open])
|
|
223
|
+
// compared with what is meant now - a pending save included: going back to the saved words while a
|
|
224
|
+
// newer save is out is a save of its own, queued after it
|
|
225
|
+
const lastSent = useRef<string | undefined>(undefined)
|
|
226
|
+
const save = () => {
|
|
227
|
+
setOpen(false)
|
|
228
|
+
if (text !== (lastSent.current ?? pending ?? edited ?? words)) { lastSent.current = text; onEdit?.(text) }
|
|
229
|
+
}
|
|
230
|
+
// once the saved edit is what was last sent, the intent is settled
|
|
231
|
+
useEffect(() => { if (lastSent.current !== undefined && edited === lastSent.current && pending === undefined) lastSent.current = undefined }, [edited, pending])
|
|
232
|
+
return (
|
|
233
|
+
<div className="jm-panel jm-readback" data-jam-readback="" style={style}>
|
|
234
|
+
<div className="top">
|
|
235
|
+
<span className="jm-capglyph"><WaveformIcon size={14} /></span>
|
|
236
|
+
<Tip side="bottom" label={<span className="jm-tip-title">{title}{autoNamed && <><br /><small>Named by Claude Haiku from its words, sent to Anthropic through Claude Code - <code>jam.names: false</code> turns it off</small></>}</span>} only={autoNamed ? undefined : cutShort}><h3>{title || 'Capture'}</h3></Tip>
|
|
237
|
+
{head}
|
|
238
|
+
<Walk of={of} onPrev={onPrev} onNext={onNext} />
|
|
239
|
+
</div>
|
|
240
|
+
<Meta items={meta} />
|
|
241
|
+
<div className="jm-body">
|
|
242
|
+
{follows && <div className="note-line info"><ArrowBendUpLeftIcon size={14} /><span>Follows <b style={{ color: 'var(--glass-ink)' }}>{follows}</b> - confirming sends that review back as more work</span></div>}
|
|
243
|
+
{err && <div className="note-line err"><WarningIcon size={14} /><span>{err}</span></div>}
|
|
244
|
+
{warn && <div className="note-line warn"><WarningIcon size={14} /><span>{warn}</span></div>}
|
|
245
|
+
{pictures.length > 0 && <div className="jm-thumbs">{pictures.map((p) => <Shot key={p.id} url={p.url} cap={p.caption} />)}</div>}
|
|
246
|
+
{open && !readOnly && !locked ? (
|
|
247
|
+
<textarea ref={field} className="jm-edit" value={text} rows={Math.min(10, Math.max(3, Math.ceil(text.length / 60)))}
|
|
248
|
+
onChange={(e) => setText(e.target.value)} onBlur={save}
|
|
249
|
+
onKeyDown={(e) => { e.stopPropagation(); if (e.key === 'Escape') { setText(edited ?? words); setOpen(false) } }} />
|
|
250
|
+
) : (
|
|
251
|
+
<div className={readOnly || locked ? undefined : 'jm-editable'} title={readOnly || locked ? undefined : 'Click to edit the words'} onClick={readOnly || locked ? undefined : () => setOpen(true)}>
|
|
252
|
+
{edited !== undefined && !readOnly && <div className="jm-edited"><PencilSimpleIcon size={12} />Your edit</div>}
|
|
253
|
+
<Lines lines={lines} />
|
|
254
|
+
</div>
|
|
255
|
+
)}
|
|
256
|
+
{(added?.length || (onAddNote && !readOnly)) ? <AddedNotes added={added ?? []} onAdd={readOnly || locked ? undefined : onAddNote} /> : null}
|
|
257
|
+
</div>
|
|
258
|
+
<div className="rule" />
|
|
259
|
+
<div className="actions">
|
|
260
|
+
{readOnly ? (
|
|
261
|
+
<><span className="sp" />{onOpenThread && <button className="jm-btn" onClick={onOpenThread}>Open thread</button>}
|
|
262
|
+
{onRetry && <><button className="jm-btn ghost" onClick={onDrop}>Drop</button><button className="jm-btn primary" onClick={onRetry}>Retry</button></>}</>
|
|
263
|
+
) : (
|
|
264
|
+
<>
|
|
265
|
+
<span className="dim">{agent ? <>For <b style={{ color: 'var(--glass-ink-2)', fontWeight: 600 }}>{agent}</b></> : 'No agent yet - it waits in the queue'}</span>
|
|
266
|
+
<span className="sp" />
|
|
267
|
+
{onResume && <button className="jm-btn ghost" onClick={onResume}>Resume <kbd>R</kbd></button>}
|
|
268
|
+
<button className="jm-btn ghost" onClick={onDrop}>Drop <kbd>esc</kbd></button>
|
|
269
|
+
<button className="jm-btn ghost" onClick={onKeep}>Keep <kbd>K</kbd></button>
|
|
270
|
+
<button className="jm-btn primary" onClick={onConfirm}>Add to queue <kbd>⏎</kbd></button>
|
|
271
|
+
</>
|
|
272
|
+
)}
|
|
273
|
+
</div>
|
|
274
|
+
</div>
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ---- the review --------------------------------------------------------------------------------------
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* A capture's review (v9): one big picture at a time at the panel's width - frame tabs when several
|
|
282
|
+
* frames changed, a Before | After switch (B; it opens on After), a dashed "No picture" where a shot
|
|
283
|
+
* failed. Above it the agent's reply and "Open thread"; below it the verdicts - Looks good (⏎), More
|
|
284
|
+
* work (⇧⏎), Later (→). `more` turns the verdict row into a composer whose ⏎ (or Send) calls
|
|
285
|
+
* `onMore(text)`; esc (or `onMoreOpen(false)`) closes it.
|
|
286
|
+
*
|
|
287
|
+
* `shots` are picture URLs per frame (`frames` names the tabs; it defaults to the shots' frames);
|
|
288
|
+
* `alsoChanged` = shared files the job changed anyway.
|
|
289
|
+
*/
|
|
290
|
+
export function ReviewDetail({ title, head, of, onPrev, onNext, frames, active, onTab, view, onFlip, reply, shots, alsoChanged, agent, when, more, onMore, onMoreOpen, onGood, onLater, onOpenThread, style, draftKey }: {
|
|
291
|
+
title: string
|
|
292
|
+
/** beside the title: the Review | Capture switch */
|
|
293
|
+
head?: ReactNode
|
|
294
|
+
of?: [number, number]
|
|
295
|
+
onPrev?: () => void
|
|
296
|
+
onNext?: () => void
|
|
297
|
+
frames?: string[]
|
|
298
|
+
active: number
|
|
299
|
+
onTab(i: number): void
|
|
300
|
+
view: 'before' | 'after'
|
|
301
|
+
onFlip(view: 'before' | 'after'): void
|
|
302
|
+
reply: ReactNode
|
|
303
|
+
/** `new`: a frame the run made - nothing before it */
|
|
304
|
+
shots: { frame: string; before?: string; after?: string; new?: boolean }[]
|
|
305
|
+
alsoChanged?: string[]
|
|
306
|
+
agent?: string
|
|
307
|
+
when?: string
|
|
308
|
+
more?: boolean
|
|
309
|
+
onMore(text: string): void
|
|
310
|
+
onMoreOpen(open: boolean): void
|
|
311
|
+
onGood(): void
|
|
312
|
+
onLater(): void
|
|
313
|
+
onOpenThread?: () => void
|
|
314
|
+
/** the card the More work words belong to (kept across the panel closing) */
|
|
315
|
+
draftKey?: string
|
|
316
|
+
style?: CSSProperties
|
|
317
|
+
}) {
|
|
318
|
+
const names = frames ?? shots.map((s) => s.frame)
|
|
319
|
+
const shot = shots[active] ?? shots.find((s) => s.frame === names[active])
|
|
320
|
+
const isNew = (f: string) => !!shots.find((s) => s.frame === f)?.new
|
|
321
|
+
const label = (f: string) => f.split('/').pop() ?? f
|
|
322
|
+
// the More work words outlive the panel: a click elsewhere closes it, and the words wait for its return -
|
|
323
|
+
// they go only when sent, or when you leave the composer yourself (Esc)
|
|
324
|
+
const [text, setTextState] = useState(() => (draftKey ? moreDrafts.get(draftKey) ?? '' : ''))
|
|
325
|
+
const setText = (t: string) => { setTextState(t); if (draftKey) { if (t) moreDrafts.set(draftKey, t); else moreDrafts.delete(draftKey) } }
|
|
326
|
+
const field = useRef<HTMLTextAreaElement>(null)
|
|
327
|
+
useEffect(() => { if (draftKey && moreDrafts.get(draftKey) && !more) onMoreOpen(true) }, []) // back with words waiting: the composer is open
|
|
328
|
+
// left on purpose (Esc cleared its words from the map): the composer's words go too; closed by a click
|
|
329
|
+
// elsewhere, the map still holds them
|
|
330
|
+
useEffect(() => { if (more) field.current?.focus(); else if (draftKey && !moreDrafts.has(draftKey)) setTextState('') }, [more])
|
|
331
|
+
const send = () => { if (text.trim()) onMore(text.trim()) }
|
|
332
|
+
return (
|
|
333
|
+
<div className="jm-panel jm-review" data-jam-review="" style={style}>
|
|
334
|
+
<div className="top">
|
|
335
|
+
<JamStateIcon state="review" />
|
|
336
|
+
<Tip side="bottom" label={<span className="jm-tip-title">{title}</span>} only={cutShort}><h3>{title}</h3></Tip>
|
|
337
|
+
{head}
|
|
338
|
+
<Walk of={of} onPrev={onPrev} onNext={onNext} />
|
|
339
|
+
</div>
|
|
340
|
+
<Meta items={[...names.map((f) => <span key={f} className="jm-flink"><FrameRectIcon size={11} />{label(f)}</span>), ...(agent ? [agent] : []), ...(when ? [when] : [])]} />
|
|
341
|
+
<div className="jm-reply">
|
|
342
|
+
<Marver size={20} />
|
|
343
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, minWidth: 0 }}>
|
|
344
|
+
<p>{reply}</p>
|
|
345
|
+
{onOpenThread && <button className="jm-link" onClick={onOpenThread}>Open thread</button>}
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
{names.length > 0 && (
|
|
349
|
+
<div className="jm-fbar">
|
|
350
|
+
{names.length > 1
|
|
351
|
+
? <div className="jm-ftabs" role="tablist">{names.map((f, i) => <button key={f} role="tab" aria-selected={i === active} className={i === active ? 'on' : undefined} onClick={() => onTab(i)}><FrameRectIcon size={12} />{label(f)}{isNew(f) && <span className="jm-newtag">New</span>}</button>)}</div>
|
|
352
|
+
: <span className="jm-framehd"><FrameRectIcon size={12} />{label(names[0])}{isNew(names[0]) && <span className="jm-newtag">New</span>}</span>}
|
|
353
|
+
<span className="sp" />
|
|
354
|
+
{/* a frame the run made has nothing before it: no switch */}
|
|
355
|
+
{shot?.new ? <span className="dim" data-jam-new="">New frame</span> : (
|
|
356
|
+
<Tip side="bottom" label={<span>Before / After<kbd style={{ marginLeft: 8 }}>B</kbd></span>}>
|
|
357
|
+
<div className="jm-ftabs" data-jam-flip="">{(['before', 'after'] as const).map((v) => <button key={v} className={v === view ? 'on' : undefined} aria-pressed={v === view} onClick={() => onFlip(v)}>{v === 'before' ? 'Before' : 'After'}</button>)}</div>
|
|
358
|
+
</Tip>
|
|
359
|
+
)}
|
|
360
|
+
</div>
|
|
361
|
+
)}
|
|
362
|
+
<div className="jm-big"><Shot url={view === 'before' && !shot?.new ? shot?.before : shot?.after} alt={`${label(names[active] ?? '')} ${shot?.new ? 'new' : view}`} /></div>
|
|
363
|
+
{alsoChanged && alsoChanged.length > 0 && (
|
|
364
|
+
<div className="jm-file"><FileCodeIcon size={14} /><span>Also changed {alsoChanged.map((f, i) => <span key={f}>{i > 0 && ', '}<code>{f.split('/').pop()}</code></span>)}</span></div>
|
|
365
|
+
)}
|
|
366
|
+
<div className="rule" />
|
|
367
|
+
{more ? (
|
|
368
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 7 }}>
|
|
369
|
+
<div className="jm-more">
|
|
370
|
+
<span className="at">@marver</span>
|
|
371
|
+
<textarea ref={field} className="txt" rows={1} value={text} placeholder="What else should change?"
|
|
372
|
+
onChange={(e) => setText(e.target.value)}
|
|
373
|
+
onKeyDown={(e) => {
|
|
374
|
+
e.stopPropagation()
|
|
375
|
+
if (e.key === 'Escape') { e.preventDefault(); setText(''); onMoreOpen(false) }
|
|
376
|
+
else if (e.key === 'Enter' && !e.shiftKey && !(e.nativeEvent as unknown as { isComposing?: boolean }).isComposing) { e.preventDefault(); send() }
|
|
377
|
+
}} />
|
|
378
|
+
<button className="jm-send" disabled={!text.trim()} onClick={send}>Send <kbd>⏎</kbd></button>
|
|
379
|
+
</div>
|
|
380
|
+
<span className="dim" style={{ paddingLeft: 4 }}>Back to the agent, next in line - the tile keeps its place · esc to cancel</span>
|
|
381
|
+
</div>
|
|
382
|
+
) : (
|
|
383
|
+
<div className="actions">
|
|
384
|
+
<button className="jm-btn primary" onClick={onGood}>Looks good <kbd>⏎</kbd></button>
|
|
385
|
+
<button className="jm-btn" onClick={() => onMoreOpen(true)}>More work <kbd>⇧⏎</kbd></button>
|
|
386
|
+
<button className="jm-btn ghost" onClick={onLater}>Later <kbd>→</kbd></button>
|
|
387
|
+
<span className="sp" /><kbd>esc</kbd>
|
|
388
|
+
</div>
|
|
389
|
+
)}
|
|
390
|
+
</div>
|
|
391
|
+
)
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// ---- notes --------------------------------------------------------------------------------------------
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* The notes card (v9): opened by the capture tile's Note button (or N), floating one lane up over the
|
|
398
|
+
* tile (the shell positions it with `style`). The notes added so far, each with its time in the
|
|
399
|
+
* capture, then a field for the next one. ⏎ calls `onAdd` (the shell adds the note step at that
|
|
400
|
+
* moment and clears `draft`); esc calls `onClose`. The field swallows its keys so no Jam key fires
|
|
401
|
+
* while you type (E, S, L and I type letters). The capture keeps recording throughout.
|
|
402
|
+
*/
|
|
403
|
+
export function NotesCard({ notes, draft, onDraft, onAdd, onClose, style }: {
|
|
404
|
+
notes: { t: string; text: string }[]
|
|
405
|
+
draft: string
|
|
406
|
+
onDraft(text: string): void
|
|
407
|
+
onAdd(): void
|
|
408
|
+
onClose(): void
|
|
409
|
+
style?: CSSProperties
|
|
410
|
+
}) {
|
|
411
|
+
const field = useRef<HTMLTextAreaElement>(null)
|
|
412
|
+
useEffect(() => { field.current?.focus() }, [])
|
|
413
|
+
return (
|
|
414
|
+
<div className="jm-panel jm-notes" data-jam-notes="" style={style}>
|
|
415
|
+
<div className="top"><PencilSimpleIcon size={14} style={{ color: 'var(--glass-ink-3)' }} /><h3>Notes</h3><span className="dim">in the timeline</span></div>
|
|
416
|
+
{notes.length > 0 && <div className="jm-notelist">{notes.map((n, i) => <div key={i}><span className="ts">{n.t}</span><span>{n.text}</span></div>)}</div>}
|
|
417
|
+
<textarea ref={field} className="jm-notefield" rows={2} value={draft} placeholder="Write a note…"
|
|
418
|
+
onChange={(e) => onDraft(e.target.value)}
|
|
419
|
+
onKeyDown={(e) => {
|
|
420
|
+
e.stopPropagation()
|
|
421
|
+
if ((e.nativeEvent as unknown as { isComposing?: boolean }).isComposing) return
|
|
422
|
+
if (e.key === 'Escape') { e.preventDefault(); onClose() }
|
|
423
|
+
else if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); if (draft.trim()) onAdd() }
|
|
424
|
+
}} />
|
|
425
|
+
<div className="foot"><span>⏎ add</span><span>esc close</span></div>
|
|
426
|
+
</div>
|
|
427
|
+
)
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** The words, streaming above the capture tile (spec 27 Part 4): the earlier ones dim, the newest in ink;
|
|
431
|
+
* a dropped phrase reads "[words lost]". */
|
|
432
|
+
export const Caption = ({ old, live, style }: { old?: string; live?: string; style?: CSSProperties }) => (
|
|
433
|
+
<div className="jm-caption" data-jam-caption="" style={style}>
|
|
434
|
+
<span className="jm-bars"><i /><i /><i /><i /></span>
|
|
435
|
+
<span>{old && <span className="old">{old} </span>}{live}</span>
|
|
436
|
+
</div>
|
|
437
|
+
)
|
|
438
|
+
|
|
439
|
+
/** The one question words need (first `S` on a canvas), then the model's download if it is missing:
|
|
440
|
+
* a header that says what is happening, a line on why, then what the model is (trial 3: "Words on this
|
|
441
|
+
* Mac" said neither). */
|
|
442
|
+
export function VoiceAsk({ step, mb, progress, error, onYes, onNo, onDownload, style }: {
|
|
443
|
+
step: 'ask' | 'download' | 'downloading' | 'checking' | 'failed' | 'unavailable'
|
|
444
|
+
mb: number
|
|
445
|
+
progress?: number
|
|
446
|
+
error?: string
|
|
447
|
+
onYes(): void; onNo(): void; onDownload(): void
|
|
448
|
+
style?: CSSProperties
|
|
449
|
+
}) {
|
|
450
|
+
const pct = Math.round((progress ?? 0) * 100)
|
|
451
|
+
const title = {
|
|
452
|
+
ask: 'Say it instead of typing?',
|
|
453
|
+
download: 'Add voice to Jam',
|
|
454
|
+
downloading: 'Downloading the voice model',
|
|
455
|
+
checking: 'Almost ready',
|
|
456
|
+
failed: 'The download stopped',
|
|
457
|
+
unavailable: 'Voice is not available here',
|
|
458
|
+
}[step]
|
|
459
|
+
return (
|
|
460
|
+
<div className="jm-panel jm-voiceask" data-jam-voiceask={step} style={style}>
|
|
461
|
+
<div className="top"><MicrophoneIcon size={14} style={{ color: 'var(--jm-rec)' }} /><h3>{title}</h3></div>
|
|
462
|
+
{step === 'ask' && <p className="dim">While a capture records, what you say becomes words in it - transcribed on this Mac. The audio is never kept or sent anywhere.</p>}
|
|
463
|
+
{step === 'download' && <>
|
|
464
|
+
<p className="lead">Jam needs a speech-to-text model to turn what you say into words in each capture.</p>
|
|
465
|
+
<p className="dim">It is NVIDIA's Parakeet v3: small, fast and accurate, and it runs on this Mac, so your audio never leaves it. One {mb}{'\u00a0'}MB download, shared by every canvas.</p>
|
|
466
|
+
</>}
|
|
467
|
+
{step === 'downloading' && <p className="dim">{pct}% of {mb}{'\u00a0'}MB. Keep going: this capture records as usual, and your words start with the next one.</p>}
|
|
468
|
+
{step === 'checking' && <p className="dim">Checking the download, then voice is on.</p>}
|
|
469
|
+
{step === 'failed' && <p className="dim">{error ?? 'Unknown error'}. Try again, or keep going with typed notes.</p>}
|
|
470
|
+
{step === 'unavailable' && <p className="dim">{error ?? 'The speech engine could not start. Captures keep typed notes.'}</p>}
|
|
471
|
+
{step === 'downloading' && <div className="jm-progress"><i style={{ width: `${pct}%` }} /></div>}
|
|
472
|
+
{step === 'checking' && <div className="jm-progress busy"><i /></div>}
|
|
473
|
+
<div className="actions">
|
|
474
|
+
<span className="sp" />
|
|
475
|
+
{step === 'ask' && <><button className="jm-btn ghost" onClick={onNo}>Not now</button><button className="jm-btn primary" onClick={onYes}>Use the microphone</button></>}
|
|
476
|
+
{(step === 'download' || step === 'failed') && <><button className="jm-btn ghost" onClick={onNo}>Not now</button><button className="jm-btn primary" onClick={onDownload}>{step === 'failed' ? 'Try again' : `Download ${mb} MB`}</button></>}
|
|
477
|
+
{step === 'unavailable' && <><button className="jm-btn ghost" onClick={onNo}>Typed notes only</button><button className="jm-btn primary" onClick={onYes}>Try again</button></>}
|
|
478
|
+
</div>
|
|
479
|
+
</div>
|
|
480
|
+
)
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// ---- in a thread, and on the canvas ---------------------------------------------------------------
|
|
484
|
+
|
|
485
|
+
/** A capture's comment in its thread (round 3): labelled as a capture - a teal waveform, "Capture"
|
|
486
|
+
* with its short id and facts - then its words. Where its card stands is the status icon in the
|
|
487
|
+
* message header, not here. */
|
|
488
|
+
export const CaptureBlock = ({ id, facts, words }: { id: string; facts?: string; words: ReactNode }) => {
|
|
489
|
+
// its name, once it has one (yours, or the one a small model gave it) - else "Capture" and its short id
|
|
490
|
+
const name = useJamQueue((s) => s.cards?.find((c) => c.id === id)?.name)
|
|
491
|
+
return (
|
|
492
|
+
<span className="jm-capcm" data-capture={id}>
|
|
493
|
+
<span className="hd"><WaveformIcon size={13} /><span>{name ?? `Capture ${id.replace(/^cap-\d+-/, '')}`}</span>{facts && <span className="dim">· {facts}</span>}</span>
|
|
494
|
+
<span className="w">{words}</span>
|
|
495
|
+
</span>
|
|
496
|
+
)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** The thin teal ring round the canvas edge (or the play stage) while a capture records. */
|
|
500
|
+
export const EdgeRing = ({ style }: { style?: CSSProperties }) => <div className="jm-edge" data-jam-edge="" style={style} />
|
|
501
|
+
|
|
502
|
+
/** A capture's numbered point: `pick` (filled teal), `click` (teal ring), `hover` (dashed, no
|
|
503
|
+
* number). Screen-constant inside a world (it scales by --sh-inv). */
|
|
504
|
+
export const CapturePoint = ({ x, y, n, type = 'pick' }: { x: number; y: number; n?: number; type?: 'pick' | 'click' | 'hover' }) => (
|
|
505
|
+
<span className={`jm-pt ${type}`} style={{ left: x, top: y }}>{type === 'hover' ? null : n}</span>
|
|
506
|
+
)
|
|
@@ -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
|