rvlib-shipkit 2.8.0 → 2.10.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 (32) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/checks/SK005-rvlib-versions.check.ts +17 -11
  4. package/src/cli/cmd_Fleet.ts +8 -5
  5. package/src/cli/cmd_Review.ts +2 -1
  6. package/src/core/update-policy.ts +6 -0
  7. package/src/fleet/commit-bump.ts +123 -0
  8. package/src/fleet/push-fleet.ts +9 -3
  9. package/src/fleet/update-fleet.ts +38 -9
  10. package/src/review/cells.ts +548 -0
  11. package/src/review/format.ts +1 -1
  12. package/src/review/model.ts +29 -4
  13. package/src/review/previews.ts +124 -0
  14. package/src/review/routes.ts +82 -45
  15. package/src/review/store.ts +6 -5
  16. package/src/serve/hub-app/auto-text.tsx +52 -0
  17. package/src/serve/hub-app/hub.css +2 -0
  18. package/src/serve/hub-app/media-view.tsx +3 -11
  19. package/src/serve/hub-app/review/kind-view.tsx +21 -22
  20. package/src/serve/hub-app/review/kit.tsx +11 -12
  21. package/src/serve/hub-app/review/review-board.tsx +15 -13
  22. package/src/serve/hub-app/review/review-cells.tsx +241 -0
  23. package/src/serve/hub-app/review/review-kit.ts +79 -0
  24. package/src/serve/hub-app/review/review-list.tsx +87 -122
  25. package/src/serve/hub-app/review/review-page.tsx +25 -66
  26. package/src/serve/hub-app/review/review-st.ts +269 -668
  27. package/src/serve/hub-app/review/review-thread.tsx +301 -0
  28. package/src/serve/hub-app/review/review-views.tsx +372 -234
  29. package/src/serve/hub-app/review/thread-st.ts +770 -0
  30. package/src/serve/hub-app/review/trailer-page.tsx +5 -4
  31. package/src/serve/hub-app/review.css +252 -90
  32. package/src/serve/hub-app/review/review-answer.tsx +0 -248
@@ -1,7 +1,8 @@
1
1
  // the dispatcher's board (wiki build/shipkit/review.md, Raised items): what the owner, a player or a rule raised, by state,
2
- // each with its topic and its worker, a stale claim marked; who holds the dispatcher role. A row opens its item
2
+ // each with its topic and its worker, a stale claim marked (`GET /api/review/board`); who holds the dispatcher role. A row
3
+ // opens its item
3
4
  import { observer } from 'mobx-react-lite'
4
- import { isMarkItem, isStale, stateOf, topicLabel, type State } from '../../../review/model.ts'
5
+ import { topicLabel, type State } from '../../../review/model.ts'
5
6
  import type { ReviewSt } from './review-st.ts'
6
7
 
7
8
  const STATES: { state: State; label: string }[] = [
@@ -14,33 +15,34 @@ const STATES: { state: State; label: string }[] = [
14
15
 
15
16
  export const ReviewBoard = observer(({ rv }: { rv: ReviewSt }) => {
16
17
  const spec = rv.spec
17
- const now = new Date()
18
- const rows = rv.items.filter((x) => x.item.origin.by !== 'agent' && !isMarkItem(x)).map((x) => ({ x, st: stateOf(x, rv.followed.has(x.item.id)) }))
18
+ const rows = rv.boardRows
19
19
  const role = spec?.role
20
+ const open = rv.card?.data?.members ?? []
20
21
  return (
21
22
  <div className="rv-listscroll rv-board">
22
23
  <div className="rv-count">{role ? `dispatcher: ${role.name}, since ${role.since.slice(0, 16).replace('T', ' ')}` : 'dispatcher: nobody (sk review dispatcher --as <name>)'}</div>
24
+ {rows === null ? <div className="rv-empty"><span className="spin" /> reading the board…</div> : null}
23
25
  {STATES.map(({ state, label }) => {
24
- const of = rows.filter((r) => r.st.state === state)
26
+ const of = (rows ?? []).filter((r) => r.state === state)
25
27
  if (of.length === 0) return null
26
28
  return (
27
29
  <div key={state}>
28
30
  <div className="rv-divider">{label} · {of.length}</div>
29
- {of.map(({ x, st }) => (
30
- <div key={x.item.id} className={`rv-boardrow${rv.open?.item.id === x.item.id ? ' on' : ''}`} onClick={() => rv.pick(x.item.id)}>
31
- <div className="rv-linkedtitle">{x.item.title}</div>
31
+ {of.map((r) => (
32
+ <div key={r.id} className={`rv-boardrow${open.includes(r.id) ? ' on' : ''}`} onClick={() => rv.pick(r.id)}>
33
+ <div className="rv-linkedtitle">{r.title}</div>
32
34
  <div className="rv-dim">
33
- {st.topic ? topicLabel(st.topic, spec ?? undefined) : 'no topic'}
34
- {st.worker ? ` · ${st.worker}` : ''}
35
- {isStale(x, now) ? ' · stale claim' : ''}
36
- {x.item.origin.by === 'player' ? ` · ${x.item.origin.server}#${x.item.origin.serverId}` : x.item.origin.by === 'auto' ? ` · auto ${x.item.origin.rule}` : ''}
35
+ {r.topic ? topicLabel(r.topic, spec ?? undefined) : 'no topic'}
36
+ {r.worker ? ` · ${r.worker}` : ''}
37
+ {r.stale ? ' · stale claim' : ''}
38
+ {r.from ? ` · ${r.from}` : ''}
37
39
  </div>
38
40
  </div>
39
41
  ))}
40
42
  </div>
41
43
  )
42
44
  })}
43
- {rows.every((r) => r.st.state === 'closed') ? <div className="rv-empty">Nothing raised is open.</div> : null}
45
+ {rows !== null && rows.every((r) => r.state === 'closed') ? <div className="rv-empty">Nothing raised is open.</div> : null}
44
46
  </div>
45
47
  )
46
48
  })
@@ -0,0 +1,241 @@
1
+ // the cells of a thread, one framed card each (wiki build/shipkit/review.md, The review page): a header bar (who, when,
2
+ // the kind, `v2`, fold, copy the id), then the body, or one line of summary when folded. A folded cell draws no media.
3
+ // A version holds its words and its views, a verdict points back at the version it judged and lists his notes (a
4
+ // click shows the view they sit on), a reply and a note are words; a run of state changes is one thin line
5
+ import { observer } from 'mobx-react-lite'
6
+ import type { EventCell, NoteCell, ReplyCell, VerdictCell, VersionCell } from '../../../review/cells.ts'
7
+ import { isGallery, STATUS_LABEL, viewName, viewTag, type Rect } from '../../../review/model.ts'
8
+ import { Icon, ICON } from '../icons.tsx'
9
+ import { renderMd } from '../md.ts'
10
+ import { ageWords, stampWords } from '../time-ago.tsx'
11
+ import { KindView, AnimPanel } from './kind-view.tsx'
12
+ import { keepFocus, laneColor, REACTIONS, secs, SIDE_LABEL, toneOf } from './kit.tsx'
13
+ import type { ReviewSt } from './review-st.ts'
14
+ import { VersionViews } from './review-views.tsx'
15
+ import { cellDom, type Framed, type ThreadSt } from './thread-st.ts'
16
+
17
+ /** who a cell is from, as its header says it: you, a player, or the agent's lane */
18
+ const whoWords = (who: string): string => (who === 'owner' ? 'you' : who)
19
+
20
+ /** an agent that named no lane: « agent », or « agent 66573d » after its session */
21
+ const anonymous = (who: string): boolean => who === 'agent' || who.startsWith('agent ')
22
+
23
+ /** a round mark of who speaks: his own, a player's, the lane's colour and name, or a neutral mark for an agent that
24
+ * named no lane */
25
+ const avatarText = (who: string): string => (who === 'owner' ? 'you' : who === 'player' ? 'P' : anonymous(who) ? '⚙' : who.slice(0, 4))
26
+
27
+ const Avatar = ({ who }: { who: string }) => {
28
+ const mine = who === 'owner'
29
+ const player = who === 'player'
30
+ const anon = anonymous(who)
31
+ const tip = anon ? `${who}: an agent that named no lane${who === 'agent' ? '' : ' (its session)'}` : whoWords(who)
32
+ return (
33
+ <span className={`rv-avatar${mine ? ' mine' : player ? ' player' : anon ? ' anon' : ''}`} style={mine || player || anon ? undefined : { ['--lane' as string]: laneColor(who) }} title={tip}>
34
+ {avatarText(who)}
35
+ </span>
36
+ )
37
+ }
38
+
39
+ /** a time as « 3h ago », the exact stamp in its tooltip; it moves with the repo's clock */
40
+ export const When = observer(({ rv, at }: { rv: ReviewSt; at: string }) => {
41
+ const t = Date.parse(at)
42
+ return <time className="rv-when" dateTime={at} title={stampWords(t)}>{ageWords(t, rv.now)}</time>
43
+ })
44
+
45
+ const KIND_LABEL: Record<Framed['kind'], string> = { version: 'version', verdict: 'verdict', reply: 'reply', note: 'note' }
46
+
47
+ /** one framed cell: its header bar, then its body, or its summary when folded */
48
+ export const CellFrame = observer(({ rv, card, c }: { rv: ReviewSt; card: ThreadSt; c: Framed }) => {
49
+ const open = card.isOpen(c)
50
+ const head = card.head?.id === c.id
51
+ const unread = (c.kind === 'reply' || c.kind === 'note') && c.party === 'agent' && !c.read
52
+ const tone = c.kind === 'version' ? toneOf(c.status) : c.kind === 'verdict' ? toneOf(c.verdict) : ''
53
+ return (
54
+ <article id={cellDom(c.id)} data-unread={unread ? c.id : undefined} className={`rv-c k-${c.kind} p-${c.party}${open ? '' : ' folded'}${head ? ' head' : ''} ${tone}`}>
55
+ <header className="rv-chead" onClick={() => card.toggleCell(c)}>
56
+ <button className="rv-foldbtn" aria-label={open ? 'fold' : 'unfold'} aria-expanded={open} onMouseDown={keepFocus} onClick={(e) => { e.stopPropagation(); card.toggleCell(c) }}>{open ? '▾' : '▸'}</button>
57
+ <Avatar who={c.who} />
58
+ {avatarText(c.who) === whoWords(c.who) ? null : <b className="rv-cwho">{whoWords(c.who)}</b>}
59
+ <span className="rv-ckind">{c.kind === 'version' ? `v${c.n}` : c.kind === 'reply' && c.op ? (c.op === 'ask' ? 'question' : 'answer') : KIND_LABEL[c.kind]}</span>
60
+ {c.kind === 'version' ? <span className="rv-badge">{STATUS_LABEL[c.status]}</span> : null}
61
+ {c.kind === 'verdict' ? <span className="rv-badge">{STATUS_LABEL[c.verdict]}</span> : null}
62
+ {c.kind === 'verdict' ? (
63
+ <button className="rv-on ghost" title={c.n > 0 ? `the version this answers: v${c.n}` : 'the note this answers'} onMouseDown={keepFocus} onClick={(e) => { e.stopPropagation(); card.reveal(c.on) }}>↑ on {c.n > 0 ? `v${c.n}` : 'the note'}</button>
64
+ ) : c.kind !== 'version' && c.on !== c.id && c.on !== card.data?.head ? (
65
+ <button className="rv-on ghost" title="the item this was said on" onMouseDown={keepFocus} onClick={(e) => { e.stopPropagation(); card.reveal(c.on) }}>↑ on {onWords(card, c.on)}</button>
66
+ ) : null}
67
+ {head ? <span className="rv-headtag" title="your verdict and your reply go to this one">answer here</span> : null}
68
+ {unread ? <span className="rv-unread" title="not read yet" /> : null}
69
+ <span className="sp" />
70
+ <When rv={rv} at={c.at} />
71
+ <button className="rv-copyid ghost" title={`copy the id: ${c.id}`} aria-label="copy the id" onMouseDown={keepFocus} onClick={(e) => { e.stopPropagation(); void rv.copyId(c.id) }}>
72
+ <Icon d={ICON.copy} />
73
+ </button>
74
+ </header>
75
+ {open ? (
76
+ <div className="rv-cbody">
77
+ {c.kind === 'version' ? <VersionBody rv={rv} card={card} c={c} /> : c.kind === 'verdict' ? <VerdictBody card={card} c={c} /> : c.kind === 'reply' ? <ReplyBody rv={rv} c={c} /> : <NoteBody rv={rv} c={c} />}
78
+ </div>
79
+ ) : (
80
+ <div className="rv-csum" onClick={() => card.toggleCell(c)}>{c.summary || '·'}</div>
81
+ )}
82
+ </article>
83
+ )
84
+ })
85
+
86
+ /** what an item a word sits on is called: its version, or the note it answers */
87
+ const onWords = (card: ThreadSt, on: string): string => {
88
+ const v = card.versionOf(on)
89
+ return v ? `v${v.n}` : 'the note'
90
+ }
91
+
92
+ /** a long text folded to its first lines, a « more » that unfolds it in place */
93
+ const LONG_WHAT = 480
94
+
95
+ const Clamp = observer(({ card, id, md }: { card: ThreadSt; id: string; md: string }) => {
96
+ const long = md.length > LONG_WHAT || md.split('\n').length > 8
97
+ const key = `${id}#what`
98
+ const open = !long || card.folds[key] === true
99
+ return (
100
+ <div className={`rv-clamp${open ? '' : ' shut'}`}>
101
+ <div className="md rv-what" dangerouslySetInnerHTML={{ __html: renderMd(md) }} />
102
+ {long ? (
103
+ <button className="rv-more ghost" aria-expanded={open} onMouseDown={keepFocus} onClick={() => card.toggle(key, open)}>{open ? 'less ▴' : 'more ▾'}</button>
104
+ ) : null}
105
+ </div>
106
+ )
107
+ })
108
+
109
+ /** a version: its gutter (its big `v3`, sticky while it scrolls), what the agent says, the repo's facts on it, its views */
110
+ const VersionBody = observer(({ rv, card, c }: { rv: ReviewSt; card: ThreadSt; c: VersionCell }) => (
111
+ <div className="rv-vgrid">
112
+ <div className="rv-gut" aria-hidden="true"><span className="rv-gutlabel">v{c.n}</span></div>
113
+ <div className="rv-vmain"><VersionMain rv={rv} card={card} c={c} /></div>
114
+ </div>
115
+ ))
116
+
117
+ const VersionMain = observer(({ rv, card, c }: { rv: ReviewSt; card: ThreadSt; c: VersionCell }) => {
118
+ const r = c.item
119
+ const live = c.id === card.head?.id && card.takesVerdict
120
+ const stamp = card.cells.findLast((x) => x.on === c.id)?.id ?? c.id
121
+ return (
122
+ <>
123
+ {r.what ? <Clamp card={card} id={c.id} md={r.what} /> : null}
124
+ {r.keeps ? <div className="rv-keeps"><b>keeps:</b> {r.keeps}</div> : null}
125
+ {r.why ? <div className="rv-pre rv-why">another subject: {r.why}</div> : null}
126
+ <div className="rv-cfacts">
127
+ {r.commit ? <span className="rv-mono" title={`commit ${r.commit}`}>@{r.commit.slice(0, 9)}</span> : null}
128
+ <span className="rv-mono rv-dim">{r.id}</span>
129
+ </div>
130
+ <KindView app={rv} item={r} stamp={stamp} />
131
+ <AnimPanel app={rv} item={r} />
132
+ {r.views.length > 0 ? <VersionViews ver={{ rv, card, cell: c, live }} /> : null}
133
+ </>
134
+ )
135
+ })
136
+
137
+ /** where a rectangle sits, in words: its view's number and name, its side, its moment */
138
+ const rectPlace = (card: ThreadSt, on: string, r: Rect): string => {
139
+ const v = card.versionOf(on)
140
+ const i = r.view ?? 0
141
+ return `${v ? `${viewTag(v.n, i)}${v.item.views[i]?.label ? ` ${v.item.views[i]!.label}` : ''}` : viewName(undefined, i)}${r.side ? ` ${SIDE_LABEL[r.side]}` : ''}${r.t !== undefined ? ` · ${secs(r.t)}` : ''}`
142
+ }
143
+
144
+ /** the owner's verdict: the verdict, the words, the pick, then each note with the view it sits on (a click shows it) */
145
+ const VerdictBody = observer(({ card, c }: { card: ThreadSt; c: VerdictCell }) => {
146
+ const v = card.versionOf(c.on)
147
+ const views = v?.item.views ?? []
148
+ return (
149
+ <>
150
+ <div className="rv-verdictline">
151
+ <span className={`rv-bigpill ${toneOf(c.verdict)}`}>{STATUS_LABEL[c.verdict]}</span>
152
+ {c.current ? null : <span className="rv-dim">an earlier answer, before a reopen or a newer one</span>}
153
+ <span className="rv-dim">{c.read ? 'read by the agent' : 'not read yet'}</span>
154
+ </div>
155
+ {c.text ? <div className="rv-pre rv-words">{c.text}</div> : null}
156
+ {c.pick !== undefined ? (
157
+ <button className="rv-noteline re-approved" onClick={() => card.reveal(c.on, c.pick)}>✓ picked {v ? `${viewTag(v.n, c.pick)} ` : ''}{viewName(views[c.pick], c.pick)}</button>
158
+ ) : null}
159
+ {c.rects.map((r, k) => (
160
+ <button key={`r${k}`} className="rv-noteline rect" onClick={() => card.reveal(c.on, r.view ?? 0)}>
161
+ <span className="rv-notemark">⬚ {k + 1}</span>
162
+ <span className="rv-noteplace">{rectPlace(card, c.on, r)}</span>
163
+ <span className="rv-notetext">{r.comment || <i className="rv-dim">no word</i>}</span>
164
+ </button>
165
+ ))}
166
+ {c.reactions.map((q, k) => {
167
+ const o = REACTIONS.find((x) => x.status === q.status)
168
+ const view = views[q.view]
169
+ const tile = q.tile !== undefined && view && isGallery(view) ? ` · ${view.gallery[q.tile]?.label ?? `tile ${q.tile + 1}`}` : ''
170
+ return (
171
+ <button key={`q${k}`} className={`rv-noteline${q.status ? ` re-${q.status}` : ''}`} onClick={() => card.reveal(c.on, q.view)}>
172
+ <span className="rv-notemark">{o?.glyph ?? ''}{q.stars ? ` ★${q.stars}` : ''}</span>
173
+ <span className="rv-noteplace">{v ? `${viewTag(v.n, q.view)} ` : ''}{view?.label || (v ? '' : viewName(view, q.view))}{tile}</span>
174
+ <span className="rv-notetext">{q.comment || (o ? o.label : '')}</span>
175
+ </button>
176
+ )
177
+ })}
178
+ </>
179
+ )
180
+ })
181
+
182
+ /** words of either party, and an image he pasted */
183
+ const ReplyBody = ({ rv, c }: { rv: ReviewSt; c: ReplyCell }) => (
184
+ <>
185
+ <div className="rv-pre rv-words">{c.text}</div>
186
+ {c.image ? (
187
+ <a href={rv.threadImageUrl(c.on, c.image)} target="_blank" rel="noreferrer"><img className="rv-msgimg" src={rv.threadImageUrl(c.on, c.image)} alt="" loading="lazy" /></a>
188
+ ) : null}
189
+ </>
190
+ )
191
+
192
+ /** what he or a player raised, or his mark: the words, the still with his rectangles on it */
193
+ const NoteBody = ({ rv, c }: { rv: ReviewSt; c: NoteCell }) => {
194
+ const first = c.item?.views[0]
195
+ const still = first && !isGallery(first) && 'image' in first.files ? { name: first.files.image, size: first.size } : null
196
+ const r = c.rate
197
+ return (
198
+ <>
199
+ {c.item && c.item.title !== c.text ? <div className="rv-notetitle">{c.item.title}</div> : null}
200
+ {r ? <div className="rv-dim">marked {[r.stars !== undefined ? `★${r.stars}` : '', r.mark ?? '', r.part ? `on ${r.part}` : ''].filter(Boolean).join(' ')}</div> : null}
201
+ {c.text ? <div className="rv-pre rv-words">{c.text}</div> : null}
202
+ {still && c.item ? (
203
+ <div className="rv-raisedframe" style={{ aspectRatio: `${still.size.w} / ${still.size.h}` }}>
204
+ <img src={rv.fitUrl(c.item.id, still.name)} alt="" loading="lazy" decoding="async" />
205
+ {c.rects.map((q, k) => (
206
+ <div key={k} className="rv-rect sent" style={{ left: `${q.x * 100}%`, top: `${q.y * 100}%`, width: `${q.w * 100}%`, height: `${q.h * 100}%` }} title={q.comment}>
207
+ <span className="rv-rectn">{k + 1}</span>
208
+ </div>
209
+ ))}
210
+ </div>
211
+ ) : null}
212
+ {c.rects.some((q) => q.comment) ? c.rects.map((q, k) => (q.comment ? <div key={k} className="rv-noteline rect still"><span className="rv-notemark">⬚ {k + 1}</span><span className="rv-notetext">{q.comment}</span></div> : null)) : null}
213
+ {c.image && c.item ? <img className="rv-msgimg" src={rv.threadImageUrl(c.item.id, c.image)} alt="" loading="lazy" /> : null}
214
+ </>
215
+ )
216
+ }
217
+
218
+ /** a run of state changes in a row: one thin line, the same change said once with its count and its first and last
219
+ * time. A run never crosses a framed cell: the thread draws a verdict or a word between two changes as its own cell */
220
+ export const EventsLine = observer(({ rv, cells }: { rv: ReviewSt; cells: EventCell[] }) => {
221
+ const runs: { c: EventCell; n: number; last: EventCell }[] = []
222
+ for (const c of cells) {
223
+ const run = runs.at(-1)
224
+ if (run && run.c.summary === c.summary) {
225
+ run.n++
226
+ run.last = c
227
+ } else runs.push({ c, n: 1, last: c })
228
+ }
229
+ return (
230
+ <div className="rv-events">
231
+ {runs.map(({ c, n, last }) => (
232
+ <div key={c.id} id={cellDom(c.id)} className="rv-event" title={n > 1 ? `${n} times: ${c.summary}` : c.summary}>
233
+ {n > 1 ? <b className="rv-eventn">{n}×</b> : null}
234
+ <span className="rv-eventtext">{c.summary}</span>
235
+ <When rv={rv} at={c.at} />
236
+ {n > 1 ? <>{' → '}<When rv={rv} at={last.at} /></> : null}
237
+ </div>
238
+ ))}
239
+ </div>
240
+ )
241
+ })
@@ -0,0 +1,79 @@
1
+ // the review page's plumbing, no mobx and no view: the browser's storage, a polled loader that keeps its last answer
2
+ // on « not modified », a json post, the clipboard
3
+ import { reach } from '../reach.ts'
4
+
5
+ /** the zoom of a view: fit the column (and the window's height), or a share of the image's own pixels */
6
+ export const ZOOMS = ['fit', '1', '1.5', '2'] as const
7
+ export type Zoom = (typeof ZOOMS)[number]
8
+
9
+ /** what a reload must not lose: a blocked storage only loses persistence */
10
+ export const kept = {
11
+ get(k: string): string | null {
12
+ try {
13
+ return localStorage.getItem(k)
14
+ } catch {
15
+ return null
16
+ }
17
+ },
18
+ put(k: string, v: string | null): void {
19
+ try {
20
+ if (v === null) localStorage.removeItem(k)
21
+ else localStorage.setItem(k, v)
22
+ } catch {
23
+ // as above
24
+ }
25
+ },
26
+ }
27
+
28
+ /** a loader for a polled url: it sends the tag of its last answer for that same url, and on « not modified » gives
29
+ * that answer again (the same object, so nothing draws again). A tag is the store's index build, the same for every
30
+ * url, so it is only sent back to the url that answered it */
31
+ export function etagLoader<T>(url: () => string): () => Promise<T> {
32
+ let last: { url: string; tag: string; value: T } | null = null
33
+ return async () => {
34
+ const u = url()
35
+ const held = last?.url === u ? last : null
36
+ const res = await reach(u, { cache: 'no-store', headers: held ? { 'If-None-Match': held.tag } : {} })
37
+ if (res.status === 304 && held) return held.value
38
+ if (!res.ok) throw new Error(`${u}: HTTP ${res.status} ${await res.text().catch(() => '')}`.trim())
39
+ const value = (await res.json()) as T
40
+ const tag = res.headers.get('ETag')
41
+ last = tag ? { url: u, tag, value } : null
42
+ return value
43
+ }
44
+ }
45
+
46
+ export async function postJson<T>(url: string, body: unknown): Promise<T> {
47
+ const res = await reach(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
48
+ const text = await res.text()
49
+ if (!res.ok) {
50
+ let msg = text
51
+ try {
52
+ msg = (JSON.parse(text) as { error?: string }).error ?? text
53
+ } catch {
54
+ // a plain text answer says it already
55
+ }
56
+ throw new Error(msg || `HTTP ${res.status}`)
57
+ }
58
+ return JSON.parse(text) as T
59
+ }
60
+
61
+ /** a text to the clipboard: the clipboard api, else (a page over plain http, the phone through a public host) the old
62
+ * copy command on a hidden field */
63
+ export async function copyText(text: string): Promise<boolean> {
64
+ try {
65
+ await navigator.clipboard.writeText(text)
66
+ return true
67
+ } catch {
68
+ const el = document.createElement('textarea')
69
+ el.value = text
70
+ el.setAttribute('readonly', '')
71
+ el.style.position = 'fixed'
72
+ el.style.opacity = '0'
73
+ document.body.appendChild(el)
74
+ el.select()
75
+ const ok = document.execCommand('copy')
76
+ el.remove()
77
+ return ok
78
+ }
79
+ }
@@ -1,156 +1,121 @@
1
- // the review page's left column: the search and the filters, one card per thread, its older versions nested
1
+ // the review page's left column: the search and the filters (asked of the server), one row per thread, a page more
2
+ // when the list's end scrolls into view
2
3
  import { observer } from 'mobx-react-lite'
3
4
  import { useEffect, useRef } from 'react'
4
- import { aboutText, firstView, isGallery, isPair, laneOf, MOVE_LABEL, STATUS_LABEL, subjectLabel, verdictOf, type Move, type ReviewItem, type ShownStatus } from '../../../review/model.ts'
5
- import type { Thread } from '../../../review/threads.ts'
5
+ import type { ThreadRow } from '../../../review/cells.ts'
6
+ import { MOVE_LABEL, STATUS_LABEL, subjectLabel, type Move, type ShownStatus } from '../../../review/model.ts'
6
7
  import { AutoTag, LaneTag, laneColor, Listeners, Rework, ThumbOf, toneOf } from './kit.tsx'
7
8
  import { ReviewBoard } from './review-board.tsx'
8
9
  import type { ReviewSt } from './review-st.ts'
9
- import { Caret } from '../tree-row.tsx'
10
10
 
11
11
  const ALL = ''
12
12
 
13
- export const ReviewList = observer(({ rv }: { rv: ReviewSt }) => {
14
- const shown = rv.visible
15
- const open = rv.open?.item.id
16
- return (
17
- <div className="rv-listcol">
18
- <div className="rv-filters">
19
- <input className="rv-search" placeholder="search" aria-label="search the cards" value={rv.query} onChange={(e) => rv.setQuery(e.currentTarget.value)}
20
- onKeyDown={(e) => { if (e.key === 'Escape') { rv.setQuery(''); e.currentTarget.blur() } }} />
21
- <div className="rv-selects">
22
- <select aria-label="subject" value={rv.subject ?? ALL} onChange={(e) => rv.setFilter({ subject: e.currentTarget.value === ALL ? null : e.currentTarget.value })}>
23
- <option value={ALL}>every subject</option>
24
- {rv.subjects.map((k) => <option key={k} value={k}>{subjectLabel(k, rv.spec ?? undefined)}</option>)}
25
- </select>
26
- <select aria-label="state" value={rv.status ?? ALL} onChange={(e) => rv.setFilter({ status: e.currentTarget.value === ALL ? null : (e.currentTarget.value as ShownStatus) })}>
27
- <option value={ALL}>every state</option>
28
- {(Object.keys(STATUS_LABEL) as ShownStatus[]).map((s) => <option key={s} value={s}>{STATUS_LABEL[s]}</option>)}
29
- </select>
30
- </div>
31
- <span className="seg rv-whose" aria-label="whose move">
32
- <button className={rv.whose === null ? 'on' : ''} onClick={() => rv.setFilter({ whose: null })}>all</button>
33
- {(['owner', 'agents', 'none'] as const).map((m: Move) => (
34
- <button key={m} className={rv.whose === m ? 'on' : ''} onClick={() => rv.setFilter({ whose: m })}>{MOVE_LABEL[m]}</button>
35
- ))}
36
- </span>
37
- <div className="rv-switches">
38
- <label className="rv-switch"><input type="checkbox" checked={rv.hideHandled} onChange={(e) => rv.setHideHandled(e.currentTarget.checked)} />hide handled</label>
39
- <label className="rv-switch"><input type="checkbox" checked={rv.byLane} onChange={(e) => rv.setByLane(e.currentTarget.checked)} />by lane</label>
40
- {rv.spec?.dispatcher ? <label className="rv-switch"><input type="checkbox" checked={rv.board} onChange={(e) => rv.setBoard(e.currentTarget.checked)} />board</label> : null}
41
- </div>
42
- <div className="rv-count">
43
- {rv.activeCount} active · {rv.pendingCount} waiting{rv.hideHandled ? '' : ` · ${shown.length} / ${rv.threads.length} threads`}
44
- </div>
13
+ export const ReviewList = observer(({ rv }: { rv: ReviewSt }) => (
14
+ <div className="rv-listcol">
15
+ <div className="rv-filters">
16
+ <input className="rv-search" placeholder="search every version and message" aria-label="search the cards" value={rv.query} onChange={(e) => rv.setQuery(e.currentTarget.value)}
17
+ onKeyDown={(e) => { if (e.key === 'Escape') { rv.setQuery(''); e.currentTarget.blur() } }} />
18
+ <div className="rv-selects">
19
+ <select aria-label="subject" value={rv.subject ?? ALL} onChange={(e) => rv.setFilter({ subject: e.currentTarget.value === ALL ? null : e.currentTarget.value })}>
20
+ <option value={ALL}>every subject</option>
21
+ {rv.subjects.map((k) => <option key={k} value={k}>{subjectLabel(k, rv.spec ?? undefined)}</option>)}
22
+ </select>
23
+ <select aria-label="state" value={rv.status ?? ALL} onChange={(e) => rv.setFilter({ status: e.currentTarget.value === ALL ? null : (e.currentTarget.value as ShownStatus) })}>
24
+ <option value={ALL}>every state</option>
25
+ {(Object.keys(STATUS_LABEL) as ShownStatus[]).map((s) => <option key={s} value={s}>{STATUS_LABEL[s]}</option>)}
26
+ </select>
27
+ </div>
28
+ <span className="seg rv-whose" aria-label="whose move">
29
+ <button className={rv.whose === null ? 'on' : ''} onClick={() => rv.setFilter({ whose: null })}>all</button>
30
+ {(['owner', 'agents', 'none'] as const).map((m: Move) => (
31
+ <button key={m} className={rv.whose === m ? 'on' : ''} onClick={() => rv.setFilter({ whose: m })}>{MOVE_LABEL[m]}</button>
32
+ ))}
33
+ </span>
34
+ <div className="rv-switches">
35
+ <label className="rv-switch"><input type="checkbox" checked={rv.hideHandled} onChange={(e) => rv.setHideHandled(e.currentTarget.checked)} />hide handled</label>
36
+ <label className="rv-switch"><input type="checkbox" checked={rv.byLane} onChange={(e) => rv.setByLane(e.currentTarget.checked)} />by lane</label>
37
+ {rv.spec?.dispatcher ? <label className="rv-switch"><input type="checkbox" checked={rv.board} onChange={(e) => rv.setBoard(e.currentTarget.checked)} />board</label> : null}
38
+ </div>
39
+ <div className="rv-count">
40
+ {rv.activeCount} active · {rv.pendingCount} waiting{rv.page ? ` · ${rv.page.total} shown of ${rv.page.counts.threads} threads` : ''}
45
41
  </div>
46
- {rv.board && rv.spec?.dispatcher ? <ReviewBoard rv={rv} /> : <div className="rv-listscroll">
47
- {rv.byLane
48
- ? rv.laneGroups.map((g) => (
49
- <div key={g.lane ?? ''}>
50
- <LaneHeader rv={rv} lane={g.lane} threads={g.threads} />
51
- {g.threads.map((t) => <ThreadRow key={t.head.item.id} rv={rv} t={t} openId={open} />)}
52
- </div>
53
- ))
54
- : shown.map((t) => <ThreadRow key={t.head.item.id} rv={rv} t={t} openId={open} />)}
55
- {shown.length === 0 && rv.list != null ? (
56
- <div className="rv-empty">{rv.items.length === 0 ? 'No card yet. An agent sends one with sk review add.' : rv.hideHandled ? 'Nothing active: « hide handled » hides the handled threads.' : 'No card matches.'}</div>
57
- ) : null}
58
- {rv.list == null && rv.listError == null ? <div className="rv-empty"><span className="spin" /> reading the cards…</div> : null}
59
- {rv.listError != null ? <div className="rv-err">{rv.listError}</div> : null}
60
- {rv.broken.map((b) => <div key={b.id} className="rv-err">unreadable: {b.id} ({b.error})</div>)}
61
- </div>}
42
+ </div>
43
+ {rv.board && rv.spec?.dispatcher ? <ReviewBoard rv={rv} /> : <Rows rv={rv} />}
44
+ </div>
45
+ ))
46
+
47
+ const Rows = observer(({ rv }: { rv: ReviewSt }) => {
48
+ const open = rv.openRow
49
+ return (
50
+ <div className="rv-listscroll">
51
+ {rv.byLane
52
+ ? rv.laneGroups.map((g) => (
53
+ <div key={g.lane ?? ''}>
54
+ <LaneHeader rv={rv} lane={g.lane} rows={g.rows} />
55
+ {g.rows.map((r) => <Row key={r.head} rv={rv} r={r} on={r === open} />)}
56
+ </div>
57
+ ))
58
+ : rv.rows.map((r) => <Row key={r.head} rv={rv} r={r} on={r === open} />)}
59
+ {rv.page && rv.rows.length === 0 ? (
60
+ <div className="rv-empty">{rv.page.counts.threads === 0 ? 'No card yet. An agent sends one with sk review add.' : rv.hideHandled && !rv.q ? 'Nothing active: « hide handled » hides the handled threads.' : 'No card matches.'}</div>
61
+ ) : null}
62
+ {rv.more > 0 ? <More rv={rv} /> : null}
63
+ {rv.page === null && rv.listError === null ? <div className="rv-empty"><span className="spin" /> reading the cards…</div> : null}
64
+ {rv.listError !== null ? <div className="rv-err">{rv.listError}</div> : null}
65
+ {rv.broken.map((b) => <div key={b.id} className="rv-err">unreadable: {b.id} ({b.error})</div>)}
62
66
  </div>
63
67
  )
64
68
  })
65
69
 
66
- const LaneHeader = observer(({ rv, lane, threads }: { rv: ReviewSt; lane: string | null; threads: readonly Thread[] }) => (
70
+ /** the next page: asked when it scrolls into view, or on a click */
71
+ const More = observer(({ rv }: { rv: ReviewSt }) => {
72
+ const el = useRef<HTMLButtonElement>(null)
73
+ useEffect(() => {
74
+ const b = el.current
75
+ if (!b || typeof IntersectionObserver === 'undefined') return
76
+ const io = new IntersectionObserver(([e]) => e?.isIntersecting && rv.showMore(), { rootMargin: '200px' })
77
+ io.observe(b)
78
+ return () => io.disconnect()
79
+ }, [rv])
80
+ return <button ref={el} className="ghost rv-more" onClick={() => rv.showMore()}>{rv.more} more</button>
81
+ })
82
+
83
+ const LaneHeader = observer(({ rv, lane, rows }: { rv: ReviewSt; lane: string | null; rows: readonly ThreadRow[] }) => (
67
84
  <div className="rv-lanehead" style={lane ? { ['--lane' as string]: laneColor(lane) } : undefined}>
68
85
  <b>{lane ?? 'no lane'}</b>
69
- <span className="rv-dim">{threads.length}</span>
86
+ <span className="rv-dim">{rows.length}</span>
70
87
  <span className="sp" />
71
- <Listeners rv={rv} cards={threads.map((t) => t.head)} />
88
+ <Listeners rv={rv} heads={rows} />
72
89
  </div>
73
90
  ))
74
91
 
75
- const ThreadRow = observer(({ rv, t, openId }: { rv: ReviewSt; t: Thread; openId: string | undefined }) => {
76
- const older = t.versions.slice(1)
77
- const unfolded = older.length > 0 && rv.showsVersions(t)
78
- const n = t.versions.length
79
- return (
80
- <>
81
- <ReviewRow rv={rv} x={t.head} on={t.head.item.id === openId} unread={rv.unread(t)} version={n}
82
- fold={older.length > 0 ? { open: unfolded, toggle: () => rv.fold(t.head.item.id) } : undefined} />
83
- {unfolded ? older.map((x, i) => <VersionRow key={x.item.id} rv={rv} x={x} n={n - 1 - i} on={x.item.id === openId} />) : null}
84
- </>
85
- )
86
- })
87
-
88
- const laneStyle = (x: ReviewItem): React.CSSProperties | undefined => {
89
- const lane = laneOf(x)
90
- return lane ? { ['--lane' as string]: laneColor(lane) } : undefined
91
- }
92
+ const ABOUT = (r: ThreadRow, rv: ReviewSt): string =>
93
+ [subjectLabel(r.subject, rv.spec ?? undefined), r.choice ? 'choice' : '', r.clip ? 'clip' : '', r.pair ? 'before/after' : '', r.views > 1 ? `${r.views} views` : ''].filter(Boolean).join(' · ')
92
94
 
93
- /** an older version under its thread's head: small, its own status, a click opens it */
94
- const VersionRow = observer(({ rv, x, n, on }: { rv: ReviewSt; x: ReviewItem; n: number; on: boolean }) => {
95
- const status = rv.statusOf(x)
96
- const lane = laneOf(x)
97
- return (
98
- <div className={`rv-vrow ${toneOf(status)}${on ? ' on' : ''}${lane ? ' laned' : ''}`} style={laneStyle(x)} onClick={() => rv.pick(x.item.id)}>
99
- <div className="rv-thumb sm"><ThumbOf rv={rv} x={x} /></div>
100
- <b className="rv-vn">v{n}</b>
101
- <span className="rv-badge">{STATUS_LABEL[status]}</span>
102
- {lane ? <LaneTag lane={lane} /> : null}
103
- {x.item.origin.by === 'auto' ? <AutoTag rule={x.item.origin.rule} /> : null}
104
- <span className="rv-vtitle">{x.item.title}</span>
105
- </div>
106
- )
107
- })
108
-
109
- const ReviewRow = observer(({ rv, x, on, version, unread, fold }: {
110
- rv: ReviewSt
111
- x: ReviewItem
112
- on: boolean
113
- version: number
114
- unread: boolean
115
- fold: { open: boolean; toggle: () => void } | undefined
116
- }) => {
117
- const r = x.item
118
- const status = rv.statusOf(x)
119
- const rework = rv.reworkOf(x)
120
- // handled by the agent: its answer marked seen, or a newer version sent; never while a lane reworks it
121
- const muted = !on && !rework && (verdictOf(x)?.seen === true || status === 'superseded' || status === 'withdrawn')
122
- const lane = laneOf(x)
95
+ const Row = observer(({ rv, r, on }: { rv: ReviewSt; r: ThreadRow; on: boolean }) => {
96
+ // handled: nobody owes anything on it, and no lane reworks it
97
+ const muted = !on && !r.active
123
98
  const ref = useRef<HTMLDivElement>(null)
124
99
  useEffect(() => {
125
100
  if (on) ref.current?.scrollIntoView({ block: 'nearest' })
126
101
  }, [on])
127
- const first = firstView(r)
128
102
  return (
129
- <div ref={ref} className={`rv-row ${toneOf(status)}${on ? ' on' : ''}${muted ? ' muted' : ''}${lane ? ' laned' : ''}`} style={laneStyle(x)} onClick={() => rv.pick(r.id)}>
130
- <div className="rv-thumb"><ThumbOf rv={rv} x={x} /></div>
103
+ <div ref={ref} className={`rv-row ${toneOf(r.status)}${on ? ' on' : ''}${muted ? ' muted' : ''}${r.lane ? ' laned' : ''}`} style={r.lane ? { ['--lane' as string]: laneColor(r.lane) } : undefined} onClick={() => rv.pick(r.head)}>
104
+ <div className="rv-thumb"><ThumbOf rv={rv} row={r} /></div>
131
105
  <div className="rv-rowbody">
132
- <div className={`rv-rowtitle${on || status === 'pending' ? ' strong' : ''}`}>
133
- {unread ? <span className="rv-unread" title="a message of the agent to read" /> : null}
106
+ <div className={`rv-rowtitle${on || r.waits ? ' strong' : ''}`}>
107
+ {r.unread ? <span className="rv-unread" title="a message of the agent to read" /> : null}
134
108
  {r.title}
135
109
  </div>
136
110
  <div className="rv-rowmeta">
137
- <span className="rv-badge">{STATUS_LABEL[status]}</span>
138
- {version > 1 ? <span className="rv-badge outline">v{version}</span> : null}
139
- {lane ? <LaneTag lane={lane} /> : null}
140
- {r.origin.by === 'auto' ? <AutoTag rule={r.origin.rule} /> : null}
141
- <span className="rv-about">
142
- {aboutText(r, rv.spec ?? undefined)}
143
- {r.views.some((v) => !isGallery(v) && v.clip) ? ' · clip' : ''}
144
- {first && isPair(first.files) ? ' · before/after' : ''}
145
- </span>
111
+ <span className="rv-badge">{STATUS_LABEL[r.status]}</span>
112
+ {r.versions > 1 ? <span className="rv-badge outline" title={`${r.versions} versions in this thread`}>v{r.versions}</span> : null}
113
+ {r.lane ? <LaneTag lane={r.lane} /> : null}
114
+ {r.rule ? <AutoTag rule={r.rule} /> : null}
115
+ <span className="rv-about">{ABOUT(r, rv)}</span>
146
116
  </div>
147
- <Rework rv={rv} x={x} />
117
+ <Rework r={r.rework} />
148
118
  </div>
149
- {fold ? (
150
- <button className="rv-fold" aria-label={fold.open ? 'fold the versions' : 'unfold the versions'} onClick={(e) => { e.stopPropagation(); fold.toggle() }}>
151
- <Caret open={fold.open} />
152
- </button>
153
- ) : null}
154
119
  </div>
155
120
  )
156
121
  })