rvlib-shipkit 2.9.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 2.10.0
2
+
3
+ - **Every old review card reads well as a thread, and his draft survives a new version.** A version that lands while he writes leaves his draft on the version he started it on (« move it to v4 / keep it on v3 »), a draft orphaned under an older version is found again, and what he types while an answer is on its way stays. The card opened with none named stays open when a poll reorders the list. An agent's word goes read when its cell shows with the tab visible, and `POST …/read` takes `{ of }` so only the words drawn are marked. The thread index is kept per store, so two repos' pages keep their 304s.
4
+ - **Views are lettered, never numbered: `3.A`, `3.B`, then `AA`.** In the page (sub cells, rows, contents, verdict notes, the pick) and the CLI (`[B voice 1]`, `view B added`).
5
+ - **The review card reads like a notebook.** A version's gutter carries a big sticky `v3`; each view has one sticky header row (its `3.A`, title, kind, labelled OK / Fix / No, its tools). A clip opened under its row has one clock (its own bar), the downloads say « save mp4 » and « show in Finder ». The minimap (the thin strip, the contents' head, a row under the title on the phone) shows every version and, under the one he answers, a mark per view coloured by his answer, and the card's head says « 3 of 5 views waiting for you ». His draft notes are listed under their view, marked a draft the verdict sends. Long agent texts fold to « more », runs of state changes say their count and time span, forks are links, an agent with no lane names its session, a verdict on a raised item says « on the note », a view whose media the store lost says so.
6
+ - **A clip that opens on black previews on a lit frame.** A black poster (a trailer fading in) is previewed from the first frame of its clip at 10, 25 or 50 % of its length that is not black, cached like every preview.
7
+ - **The review card reads as one chat of framed cells.** The open card is one thread top to bottom, the newest at the bottom, the column opening on the newest version (or the agent word he has not read, or the version an old link names), his answer box pinned under it. Every version, verdict, reply and note is a framed cell with a header bar (who, when, the kind, `v2`, fold, copy the id); a folded cell is its header and one line, and loads no media. Inside a version each view is its own numbered sub cell (`3.2`) with a big title and its kind, drawn as before (image, the four compare modes, clip, sound, gallery, option rows), and what each answer said on it (rectangles in his pink, reactions, words) sits right under it. A verdict points back at its version and lists his notes, each a click from its view. A contents strip lists every version, view, verdict and reply, a click unfolds and scrolls there: beside the cells on a wide column, else a thin strip of version pills that opens it as a sheet. One word box sends a verdict with his marks or a reply alone (⌘Enter); his draft starts empty on each version. The list reads `GET /api/review/threads` a page at a time, its search and filters asked of the server; the thread reads `GET /api/review/threads/<id>`; images come at the column's or the list's size, the full file only on zoom. On pkm-multi a card's title shows in 0.52 s warm (was 0.8 to 1.8 s) and 4.0 s cold (was 6.7 to 7.3 s), and a card open moves 0.24 to 0.5 MB of review data (was 9 MB and more). The phone shows the same thread one pane at a time, the verdicts and « Reply » in one row under the thumb. The old layout (`top`, `left`, `auto`, the answer column) is gone; `GET /api/review/board` serves the dispatcher's board; `GET /api/review` stays for pkm-multi's admin only.
8
+ - **A review card reads as one thread of cells, and the hub can fetch one page and one thread.** A supersedes chain (v1, v2, v3…) folds at read time into one thread, nothing rewritten: each version, verdict, reply, raised note and state change is a cell in time order, with a one line summary and its default fold (`src/review/cells.ts`). `GET /api/review/threads` answers one page of the list (the waiting cards first, handled ones with `handled=1`, `subject`, `whose`, `status`, `lane`, a search over every version and message, `offset`, `limit`), about 1 to 6 KB where the whole list was 1.1 MB gzipped. `GET /api/review/threads/<id>` answers one thread by any of its ids, an old version's included. Both carry an ETag.
9
+ - **Review previews: a thumb and a fit size, made once per image.** `GET /api/review/<id>/preview/thumb|fit/<name>`, a webp 480 or 1600 px wide, kept in `.shipkit/cache/review-previews/` instead of the store's `.thumbs/` (that folder can be deleted); the active cards' previews are made ahead in the background. `…/thumb/<name>` answers the thumb preview.
10
+
1
11
  ## 2.9.0
2
12
 
3
13
  - **`sk fleet --update` commits and pushes each bump.** Every repo the update moved gets one commit of package.json and its lock alone, by pathspec, through the repo's own hooks: `chore(deps): rvlib-shipkit <range>`, then the plain push of `sk fleet push`. A repo whose manifest held changes before the update, whose package.json moved more than the bump, mid-merge, mid-rebase, on a detached HEAD or nested in another repo is skipped, its bump left in the tree and the command to run printed. A refused hook, a failed push or a branch behind its upstream is a FAIL line, and the command exits 1. `--no-commit` leaves every bump in its tree, as before.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rvlib-shipkit",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "funding": "https://github.com/sponsors/rvion",
5
5
  "description": "All-in-one repo companion: ci gate (task DAG), auto-discovered health checks, release-contract fulfillness, asks queue, md-wiki tools, asset atelier, live tui",
6
6
  "license": "MIT",
@@ -289,7 +289,8 @@ export class ReviewAddViewCommand extends Command {
289
289
  if (note !== undefined) v.note = note
290
290
  const extra = h.unit?.addView ? await h.unit.addView(v, repoFlags) : {}
291
291
  const item = await addView(h.dir, id, v, extra)
292
- h.out(`${id}: view ${item.views.length} "${label}" added`)
292
+ const { viewLetter } = await import('../review/model.ts')
293
+ h.out(`${id}: view ${viewLetter(item.views.length - 1)} "${label}" added`)
293
294
  return 0
294
295
  })
295
296
  }
@@ -0,0 +1,548 @@
1
+ // a thread read as one conversation (wiki build/shipkit/review.md, The thread): every version of a card, every verdict,
2
+ // reply, note and state change is one cell, in time order, built at read time from the store's files (a supersedes chain
3
+ // folds into one thread, nothing is rewritten). The paged list's rows and its query. Pure and browser safe: the routes
4
+ // send these shapes, the hub page draws them
5
+ import {
6
+ isMarkItem,
7
+ isReply,
8
+ isStale,
9
+ laneOf,
10
+ moveOf,
11
+ partyOf,
12
+ reworkOf,
13
+ stateOf,
14
+ STATUS_LABEL,
15
+ thumbFileOf,
16
+ firstView,
17
+ isGallery,
18
+ isPair,
19
+ unreadBy,
20
+ verdictOf,
21
+ type Item,
22
+ type ItemState,
23
+ type Message,
24
+ type Move,
25
+ type Op,
26
+ type Origin,
27
+ type Party,
28
+ type ReviewItem,
29
+ type ReviewReaction,
30
+ type ReviewStatus,
31
+ type Rect,
32
+ type ShownStatus,
33
+ type Subject,
34
+ type Verdict,
35
+ } from './model.ts'
36
+ import { followedIds, isActive, membersOf, openingOf, orderedThreads, statusOf, waits, waitingOnOwner, type Thread } from './threads.ts'
37
+
38
+ export type CellKind = 'version' | 'verdict' | 'reply' | 'note' | 'event'
39
+
40
+ interface CellOf<K extends CellKind> {
41
+ kind: K
42
+ /** a version or a raised item: its item id; a message: `<item id>/<message id>` */
43
+ id: string
44
+ /** the item it sits on: the version it answers, the raised item it belongs to */
45
+ on: string
46
+ /** ISO time */
47
+ at: string
48
+ /** `owner`, `player`, or the agent's lane */
49
+ who: string
50
+ party: Party
51
+ /** the one line a folded cell shows */
52
+ summary: string
53
+ /** unfolded when the thread opens: the latest version, the owner's latest answer, what the owner has not read, what came after the
54
+ * latest version; everything older folded */
55
+ open: boolean
56
+ }
57
+
58
+ /** an agent's post: one version of the card, its markdown and its views */
59
+ export interface VersionCell extends CellOf<'version'> {
60
+ /** 1 for the first version */
61
+ n: number
62
+ item: Item
63
+ status: ShownStatus
64
+ }
65
+
66
+ /** the owner's verdict on one version: as written in that message, never merged with an earlier one */
67
+ export interface VerdictCell extends CellOf<'verdict'> {
68
+ /** the version it judged */
69
+ n: number
70
+ verdict: ReviewStatus
71
+ text?: string
72
+ rects: Rect[]
73
+ reactions: ReviewReaction[]
74
+ pick?: number
75
+ /** the verdict the version holds now: the latest since the last reopen */
76
+ current: boolean
77
+ /** an agent marked it seen */
78
+ read: boolean
79
+ }
80
+
81
+ /** words of either party: a reply, or a question and its answer */
82
+ export interface ReplyCell extends CellOf<'reply'> {
83
+ text: string
84
+ /** a file of the item's `thread/` */
85
+ image?: string
86
+ op?: 'ask' | 'answer'
87
+ /** the other party marked it seen */
88
+ read: boolean
89
+ }
90
+
91
+ /** what the owner or a player raised (its item, its opening words and rectangles), or the owner's mark on the subject */
92
+ export interface NoteCell extends CellOf<'note'> {
93
+ /** a raised item: its head (its subject and its image views) */
94
+ item?: Item
95
+ text?: string
96
+ rects: Rect[]
97
+ image?: string
98
+ rate?: Message['rate']
99
+ read: boolean
100
+ }
101
+
102
+ /** a state change: one thin line, never a framed cell */
103
+ export interface EventCell extends CellOf<'event'> {
104
+ op: Exclude<Op, 'seen'>
105
+ note?: string
106
+ topic?: string
107
+ commit?: string
108
+ }
109
+
110
+ export type Cell = VersionCell | VerdictCell | ReplyCell | NoteCell | EventCell
111
+
112
+ /** one thread as the per card api sends it: the head's state, then every cell in time order */
113
+ export interface ThreadView {
114
+ /** the newest version, or the raised item no card answers */
115
+ head: string
116
+ /** the item id asked for, its cell's id too: an old version's id opens its thread at that version */
117
+ asked: string
118
+ title: string
119
+ subject: Subject
120
+ topic?: string
121
+ lane?: string
122
+ origin: Origin
123
+ status: ShownStatus
124
+ state: ItemState
125
+ move: Move
126
+ /** the head waits for the owner's verdict */
127
+ waits: boolean
128
+ active: boolean
129
+ rework: { lane: string; since: string; until: number } | null
130
+ verdict: Verdict | null
131
+ versions: number
132
+ /** other heads whose chain shares this thread's older versions */
133
+ forks: string[]
134
+ /** every item of the thread: the versions oldest first, then the raised items */
135
+ members: string[]
136
+ /** the items with agent words the owner has not read: the ones the page marks read */
137
+ unread: string[]
138
+ /** the media files a view names that the store no longer holds, `<item id>/<name>`: the page says so in place of a
139
+ * broken player (the routes fill it, the model never reads the disk) */
140
+ missing: string[]
141
+ cells: Cell[]
142
+ }
143
+
144
+ const firstLine = (s: string | undefined, max = 140): string => {
145
+ const l = (s ?? '').trim().split('\n')[0]?.trim() ?? ''
146
+ return l.length > max ? `${l.slice(0, max - 1)}…` : l
147
+ }
148
+
149
+ /** who posted an agent's item, as its cell names it: its lane, else its session's first letters, else « agent » */
150
+ export const agentWho = (o: Origin): string => (o.by === 'auto' ? o.lane : o.by === 'agent' ? (o.lane ?? (o.session ? `agent ${o.session.slice(0, 6)}` : 'agent')) : 'agent')
151
+
152
+ const readBy = (x: ReviewItem, party: Party): Set<string> => new Set(x.thread.flatMap((m) => (m.op === 'seen' && partyOf(m.who) === party ? (m.of ?? []) : [])))
153
+
154
+ const OP_WORDS: Record<Exclude<Op, 'seen'>, string> = {
155
+ dispatch: 'dispatched',
156
+ ask: 'asked',
157
+ answer: 'answered',
158
+ reassign: 'reassigned',
159
+ claim: 'claimed',
160
+ release: 'released',
161
+ blocked: 'blocked',
162
+ fixed: 'fixed',
163
+ done: 'done',
164
+ wontfix: 'not done',
165
+ drop: 'dropped',
166
+ withdraw: 'withdrawn',
167
+ reopen: 'reopened',
168
+ ready: 'made ready',
169
+ }
170
+
171
+ /** the cells of one item's messages: a read mark is no cell, it marks the cells it read */
172
+ function messageCells(x: ReviewItem, n: number, opening: Message | undefined): Cell[] {
173
+ const id = x.item.id
174
+ const current = verdictOf(x)?.id
175
+ const read = { agent: readBy(x, 'agent'), owner: readBy(x, 'owner') }
176
+ const other = (who: string): Party => (partyOf(who) === 'owner' ? 'agent' : 'owner')
177
+ const out: Cell[] = []
178
+ for (const m of x.thread) {
179
+ if (m.op === 'seen' || m === opening) continue
180
+ const party = partyOf(m.who)
181
+ const base = { id: `${id}/${m.id}`, on: id, at: m.at, who: m.who, party, open: false }
182
+ const wasRead = read[other(m.who)].has(m.id)
183
+ if (m.verdict !== undefined) {
184
+ const picked = m.pick !== undefined ? ` · picked ${x.item.views[m.pick]?.label || `view ${m.pick + 1}`}` : ''
185
+ const notes = m.rects && m.rects.length > 0 ? ` · ${m.rects.length} note${m.rects.length > 1 ? 's' : ''}` : ''
186
+ out.push({
187
+ ...base,
188
+ kind: 'verdict',
189
+ n,
190
+ verdict: m.verdict,
191
+ ...(m.text !== undefined ? { text: m.text } : {}),
192
+ rects: m.rects ?? [],
193
+ reactions: m.reactions ?? [],
194
+ ...(m.pick !== undefined ? { pick: m.pick } : {}),
195
+ current: m.id === current,
196
+ read: wasRead,
197
+ summary: `${STATUS_LABEL[m.verdict]}${picked}${notes}${m.text ? `: ${firstLine(m.text)}` : ''}`,
198
+ })
199
+ } else if (m.rate !== undefined) {
200
+ const r = m.rate
201
+ const said = [r.stars !== undefined ? `★${r.stars}` : '', r.mark ?? '', r.part ? `on ${r.part}` : ''].filter(Boolean).join(' ')
202
+ out.push({ ...base, kind: 'note', ...(m.text !== undefined ? { text: m.text } : {}), rects: m.rects ?? [], ...(m.image ? { image: m.image } : {}), rate: r, read: wasRead, summary: `marked ${said}${m.text ? `: ${firstLine(m.text)}` : ''}` })
203
+ } else if (isReply(m)) {
204
+ const op = m.op === 'ask' || m.op === 'answer' ? m.op : undefined
205
+ out.push({ ...base, kind: 'reply', text: m.text ?? '', ...(m.image ? { image: m.image } : {}), ...(op ? { op } : {}), read: wasRead, summary: firstLine(m.text) })
206
+ } else if (m.op !== undefined) {
207
+ const commit = m.fix?.commit
208
+ out.push({
209
+ ...base,
210
+ kind: 'event',
211
+ op: m.op,
212
+ ...(m.note !== undefined ? { note: m.note } : {}),
213
+ ...(m.topic !== undefined ? { topic: m.topic } : {}),
214
+ ...(commit ? { commit } : {}),
215
+ summary: `${m.who} ${OP_WORDS[m.op]}${m.topic ? ` to ${m.topic}` : ''}${m.note ? `: ${firstLine(m.note)}` : ''}${commit ? ` (${commit})` : ''}`,
216
+ })
217
+ } else if (m.rects && m.rects.length > 0) {
218
+ // rectangles with no words and no verdict: the owner's note on the item
219
+ out.push({ ...base, kind: 'note', rects: m.rects, ...(m.image ? { image: m.image } : {}), read: wasRead, summary: `${m.rects.length} note${m.rects.length > 1 ? 's' : ''}` })
220
+ }
221
+ }
222
+ return out
223
+ }
224
+
225
+ /** the raised item's own cell: its head, its opening words and rectangles */
226
+ function raisedCell(x: ReviewItem): NoteCell {
227
+ const o = openingOf(x)
228
+ const read = o ? readBy(x, 'agent').has(o.id) : false
229
+ return {
230
+ kind: 'note',
231
+ id: x.item.id,
232
+ on: x.item.id,
233
+ at: x.item.created,
234
+ who: x.item.origin.by === 'player' ? 'player' : x.item.origin.by === 'owner' ? 'owner' : agentWho(x.item.origin),
235
+ party: x.item.origin.by === 'owner' || x.item.origin.by === 'player' ? 'owner' : 'agent',
236
+ item: x.item,
237
+ ...(o?.text !== undefined ? { text: o.text } : {}),
238
+ rects: o?.rects ?? [],
239
+ ...(o?.image ? { image: o.image } : {}),
240
+ read,
241
+ summary: firstLine(o?.text) || x.item.title,
242
+ open: false,
243
+ }
244
+ }
245
+
246
+ const rank: Record<CellKind, number> = { version: 0, note: 1, verdict: 2, reply: 3, event: 4 }
247
+
248
+ /** every cell of a thread in time order: each version, then what was said on it; a raised item it answers where it was
249
+ * raised. Folding: the latest version, the owner's latest answer, what the owner has not read and everything after the latest version
250
+ * open; everything older folded */
251
+ export function cellsOf(t: Thread, items: readonly ReviewItem[]): Cell[] {
252
+ const chain = [...t.versions].reverse()
253
+ const cells: Cell[] = []
254
+ chain.forEach((x, i) => {
255
+ if (x.item.origin.by === 'agent') {
256
+ cells.push({
257
+ kind: 'version',
258
+ id: x.item.id,
259
+ on: x.item.id,
260
+ at: x.item.created,
261
+ who: agentWho(x.item.origin),
262
+ party: 'agent',
263
+ n: i + 1,
264
+ item: x.item,
265
+ status: statusOf(x, items),
266
+ summary: firstLine(x.item.what) || x.item.title,
267
+ open: false,
268
+ })
269
+ cells.push(...messageCells(x, i + 1, undefined))
270
+ } else {
271
+ // a raised item is no version: a verdict on it names no `vN`
272
+ cells.push(raisedCell(x))
273
+ cells.push(...messageCells(x, 0, openingOf(x)))
274
+ }
275
+ })
276
+ for (const x of t.answers) {
277
+ cells.push(raisedCell(x))
278
+ cells.push(...messageCells(x, 0, openingOf(x)))
279
+ }
280
+ cells.sort((a, b) => a.at.localeCompare(b.at) || rank[a.kind] - rank[b.kind] || a.id.localeCompare(b.id))
281
+ const last = t.head.item.id
282
+ const latest = cells.find((c) => c.id === last)
283
+ const answer = cells.findLast((c) => c.party === 'owner' && c.kind !== 'event' && c.id !== last)
284
+ const unreadIds = new Set(membersOf(t).flatMap((x) => unreadBy(x, 'owner').map((m) => `${x.item.id}/${m.id}`)))
285
+ for (const c of cells) {
286
+ if (c.kind === 'event') continue
287
+ c.open = c === latest || c === answer || unreadIds.has(c.id) || (latest !== undefined && c.at > latest.at)
288
+ }
289
+ return cells
290
+ }
291
+
292
+ /** every item id of a thread: the versions oldest first, then the raised items it answers */
293
+ const idsOf = (t: Thread): string[] => [...[...t.versions].reverse(), ...t.answers].map((x) => x.item.id)
294
+
295
+ /** the thread an id reads in: its own as a head, else the newest head whose chain or answers hold it */
296
+ export function threadOfId(id: string, threads: readonly Thread[]): Thread | null {
297
+ const own = threads.find((t) => t.head.item.id === id)
298
+ if (own) return own
299
+ const holding = threads.filter((t) => membersOf(t).some((x) => x.item.id === id))
300
+ return holding.sort((a, b) => b.head.item.created.localeCompare(a.head.item.created))[0] ?? null
301
+ }
302
+
303
+ /** one thread for the per card api; `asked` the id the caller named (an old version opens at its cell) */
304
+ export function threadView(t: Thread, items: readonly ReviewItem[], threads: readonly Thread[], asked: string, now = new Date()): ThreadView {
305
+ const h = t.head
306
+ const followed = followedIds(items)
307
+ const state = stateOf(h, followed.has(h.item.id))
308
+ const shared = new Set(t.versions.slice(1).map((x) => x.item.id))
309
+ const forks = threads.filter((o) => o !== t && o.versions.slice(1).some((x) => shared.has(x.item.id))).map((o) => o.head.item.id)
310
+ const lane = laneOf(h)
311
+ return {
312
+ head: h.item.id,
313
+ asked,
314
+ title: h.item.title,
315
+ subject: h.item.subject,
316
+ ...(h.item.topic ? { topic: h.item.topic } : {}),
317
+ ...(lane ? { lane } : {}),
318
+ origin: h.item.origin,
319
+ status: statusOf(h, items),
320
+ state,
321
+ move: moveOf(state.state),
322
+ waits: waits(h),
323
+ active: isActive(t, now),
324
+ rework: reworkOf(h, followed.has(h.item.id), now),
325
+ verdict: verdictOf(h),
326
+ versions: t.versions.length,
327
+ forks,
328
+ members: idsOf(t),
329
+ unread: membersOf(t)
330
+ .filter((x) => unreadBy(x, 'owner').length > 0)
331
+ .map((x) => x.item.id),
332
+ missing: [],
333
+ cells: cellsOf(t, items),
334
+ }
335
+ }
336
+
337
+ // ── the paged list ──
338
+
339
+ /** one row of the list: one thread, by its head */
340
+ export interface ThreadRow {
341
+ head: string
342
+ title: string
343
+ /** the head's ISO time */
344
+ created: string
345
+ /** the newest message of any of its items, else `created` */
346
+ updated: string
347
+ subject: string
348
+ topic?: string
349
+ lane?: string
350
+ origin: Origin['by']
351
+ /** an auto rule's id */
352
+ rule?: string
353
+ /** the agent session that sent the head: a watch kept to a session listens to it */
354
+ session?: string
355
+ status: ShownStatus
356
+ move: Move
357
+ versions: number
358
+ views: number
359
+ /** the file that stands for the head in a list: `/api/review/<head>/preview/thumb/<thumb>` */
360
+ thumb: string | null
361
+ clip: boolean
362
+ pair: boolean
363
+ choice: boolean
364
+ wip: boolean
365
+ waits: boolean
366
+ active: boolean
367
+ /** agent words the owner has not read on any of its items */
368
+ unread: boolean
369
+ rework: { lane: string; since: string; until: number } | null
370
+ /** every item id of the thread, the versions oldest first then the raised items: an old card's link finds its row */
371
+ ids: string[]
372
+ }
373
+
374
+ /** what the list asks: `handled` adds the threads nobody needs; every other key narrows */
375
+ export interface ThreadQuery {
376
+ handled: boolean
377
+ subject: string | null
378
+ whose: Move | null
379
+ status: ShownStatus | null
380
+ lane: string | null
381
+ q: string
382
+ offset: number
383
+ limit: number
384
+ }
385
+
386
+ export const PAGE = 50
387
+ export const MAX_PAGE = 500
388
+
389
+ const MOVES = new Set<string>(['owner', 'agents', 'none'])
390
+
391
+ /** the query from a url's search: a value out of range is its default */
392
+ export function queryOf(p: URLSearchParams): ThreadQuery {
393
+ const n = (k: string, d: number, max: number): number => {
394
+ const v = Number(p.get(k) || NaN)
395
+ return Number.isInteger(v) && v >= 0 ? Math.min(v, max) : d
396
+ }
397
+ const s = (k: string): string | null => (p.get(k) ?? '') || null
398
+ const whose = s('whose')
399
+ const status = s('status')
400
+ return {
401
+ handled: p.get('handled') === '1',
402
+ subject: s('subject'),
403
+ whose: whose && MOVES.has(whose) ? (whose as Move) : null,
404
+ status: status && status in STATUS_LABEL ? (status as ShownStatus) : null,
405
+ lane: s('lane'),
406
+ q: (p.get('q') ?? '').trim().toLowerCase(),
407
+ offset: n('offset', 0, Number.MAX_SAFE_INTEGER),
408
+ limit: Math.max(1, n('limit', PAGE, MAX_PAGE)),
409
+ }
410
+ }
411
+
412
+ /** one page of the list, its counts and the filters' choices */
413
+ export interface ThreadPage {
414
+ rows: ThreadRow[]
415
+ /** the threads that match the query */
416
+ total: number
417
+ offset: number
418
+ limit: number
419
+ /** every thread, the active ones, the ones waiting on the owner: the counts the list's head shows */
420
+ counts: { threads: number; active: number; waiting: number }
421
+ /** every subject kind and lane the store holds, for the filters */
422
+ subjects: string[]
423
+ lanes: string[]
424
+ broken: { id: string; error: string }[]
425
+ }
426
+
427
+ /** the list's threads in order with what a query reads of each: built once per store state, read by every page */
428
+ export interface ThreadIndex {
429
+ entries: { t: Thread; row: ThreadRow; text: string }[]
430
+ counts: ThreadPage['counts']
431
+ subjects: string[]
432
+ lanes: string[]
433
+ }
434
+
435
+ function rowOf(t: Thread, items: readonly ReviewItem[], followed: ReadonlySet<string>, now: Date): ThreadRow {
436
+ const h = t.head
437
+ const first = firstView(h.item)
438
+ const lane = laneOf(h)
439
+ const members = membersOf(t)
440
+ const updated = members.reduce((u, x) => {
441
+ const m = x.thread.at(-1)?.at ?? x.item.created
442
+ return m > u ? m : u
443
+ }, h.item.created)
444
+ return {
445
+ head: h.item.id,
446
+ title: h.item.title,
447
+ created: h.item.created,
448
+ updated,
449
+ subject: h.item.subject.kind,
450
+ ...(h.item.topic ? { topic: h.item.topic } : {}),
451
+ ...(lane ? { lane } : {}),
452
+ origin: h.item.origin.by,
453
+ ...(h.item.origin.by === 'auto' ? { rule: h.item.origin.rule } : {}),
454
+ ...(h.item.origin.by === 'agent' && h.item.origin.session ? { session: h.item.origin.session } : {}),
455
+ status: statusOf(h, items),
456
+ move: moveOf(stateOf(h, followed.has(h.item.id)).state),
457
+ versions: t.versions.length,
458
+ views: h.item.views.length,
459
+ thumb: first ? thumbFileOf(first) || null : null,
460
+ clip: h.item.views.some((v) => !isGallery(v) && v.clip !== undefined),
461
+ pair: first !== undefined && isPair(first.files),
462
+ choice: h.item.choice === true,
463
+ wip: h.item.wip !== undefined,
464
+ waits: waits(h),
465
+ active: isActive(t, now),
466
+ unread: members.some((x) => unreadBy(x, 'owner').length > 0),
467
+ rework: reworkOf(h, followed.has(h.item.id), now),
468
+ ids: idsOf(t),
469
+ }
470
+ }
471
+
472
+ /** what a search reads of a thread: every item's title, words and id, and every message's words */
473
+ const textOf = (t: Thread): string =>
474
+ membersOf(t)
475
+ .flatMap((x) => [x.item.title, x.item.what ?? '', x.item.id, ...x.thread.flatMap((m) => [m.text ?? '', m.note ?? ''])])
476
+ .join('\n')
477
+ .toLowerCase()
478
+
479
+ /** the list's index over a store's items: the order of the hub's list (the pending heads first, oldest first, then the
480
+ * rest newest first), one row and one search text per thread */
481
+ export function threadIndex(items: readonly ReviewItem[], now = new Date()): ThreadIndex {
482
+ const followed = followedIds(items)
483
+ const entries = orderedThreads(items).map((t) => ({ t, row: rowOf(t, items, followed, now), text: textOf(t) }))
484
+ return {
485
+ entries,
486
+ counts: { threads: entries.length, active: entries.filter((e) => e.row.active).length, waiting: waitingOnOwner(items).length },
487
+ subjects: [...new Set(items.map((x) => x.item.subject.kind))].sort(),
488
+ lanes: [...new Set(entries.flatMap((e) => (e.row.lane ? [e.row.lane] : [])))].sort(),
489
+ }
490
+ }
491
+
492
+ /** one page of the index for a query */
493
+ export function pageOf(ix: ThreadIndex, q: ThreadQuery, broken: ThreadPage['broken'] = []): ThreadPage {
494
+ const words = q.q.split(/\s+/).filter(Boolean)
495
+ const hits = ix.entries.filter(
496
+ ({ row, text }) =>
497
+ (q.handled || row.active) &&
498
+ (q.subject === null || row.subject === q.subject) &&
499
+ (q.whose === null || row.move === q.whose) &&
500
+ (q.status === null || row.status === q.status) &&
501
+ (q.lane === null || row.lane === q.lane) &&
502
+ words.every((w) => text.includes(w)),
503
+ )
504
+ return {
505
+ rows: hits.slice(q.offset, q.offset + q.limit).map((e) => e.row),
506
+ total: hits.length,
507
+ offset: q.offset,
508
+ limit: q.limit,
509
+ counts: ix.counts,
510
+ subjects: ix.subjects,
511
+ lanes: ix.lanes,
512
+ broken,
513
+ }
514
+ }
515
+
516
+ // ── the dispatcher's board ──
517
+
518
+ /** one raised item on the board: what he, a player or a rule raised, where it stands */
519
+ export interface BoardRow {
520
+ id: string
521
+ title: string
522
+ state: ItemState['state']
523
+ topic?: string
524
+ worker?: string
525
+ stale: boolean
526
+ /** who raised it, in a few words: `live#85`, `auto veille`, empty for him */
527
+ from: string
528
+ }
529
+
530
+ /** every raised item that is not a mark, by state: the board's rows */
531
+ export function boardOf(items: readonly ReviewItem[], now = new Date()): BoardRow[] {
532
+ const followed = followedIds(items)
533
+ return items
534
+ .filter((x) => x.item.origin.by !== 'agent' && !isMarkItem(x))
535
+ .map((x) => {
536
+ const st = stateOf(x, followed.has(x.item.id))
537
+ const o = x.item.origin
538
+ return {
539
+ id: x.item.id,
540
+ title: x.item.title,
541
+ state: st.state,
542
+ ...(st.topic ? { topic: st.topic } : {}),
543
+ ...(st.worker ? { worker: st.worker } : {}),
544
+ stale: isStale(x, now),
545
+ from: o.by === 'player' ? `${o.server}#${o.serverId}` : o.by === 'auto' ? `auto ${o.rule}` : '',
546
+ }
547
+ })
548
+ }
@@ -146,7 +146,7 @@ export function detail(x: ReviewItem, dir: string, full = false, followed = fals
146
146
  f.rects.forEach((q, i) => {
147
147
  const v = views[q.view ?? 0] ?? views[0]
148
148
  const size = v && !isGallery(v) ? v.size : { w: 0, h: 0 }
149
- const on = q.view ? ` view ${q.view} "${v?.label ?? ''}"` : ''
149
+ const on = views.length > 1 ? ` ${placeText(q, views)}` : ''
150
150
  const side = v && !isGallery(v) && isPair(v.files) ? ` ${q.side ?? '?'}` : ''
151
151
  const norm = `${q.x.toFixed(3)},${q.y.toFixed(3)} ${q.w.toFixed(3)}x${q.h.toFixed(3)}`
152
152
  const pix = `${px(q.x, size.w)},${px(q.y, size.h)} ${px(q.w, size.w)}x${px(q.h, size.h)} px`
@@ -205,8 +205,32 @@ export function pasteBlock(i: Item, state: string, w: CardWhere): string {
205
205
  ].join('\n')
206
206
  }
207
207
 
208
- /** a view's name as the page and the CLI show it: its label, or « view n » */
209
- export const viewName = (v: ReviewView | undefined, i: number): string => v?.label || `view ${i + 1}`
208
+ /** a view's letter in its version: A for the first, Z for the 26th, then AA, AB… A digit after a version's digit reads
209
+ * like a version, so a view is never numbered */
210
+ export function viewLetter(i: number): string {
211
+ let n = i + 1
212
+ let s = ''
213
+ while (n > 0) {
214
+ const r = (n - 1) % 26
215
+ s = String.fromCharCode(65 + r) + s
216
+ n = Math.floor((n - 1) / 26)
217
+ }
218
+ return s
219
+ }
220
+
221
+ /** a view as the page and the CLI tag it: its version's number and its letter, `3.B` */
222
+ export const viewTag = (n: number, i: number): string => `${n}.${viewLetter(i)}`
223
+
224
+ /** a view's name as the page and the CLI show it: its label, or « view B » */
225
+ export const viewName = (v: ReviewView | undefined, i: number): string => v?.label || `view ${viewLetter(i)}`
226
+
227
+ /** every media file a card's views name: images, pairs, clips and their posters, sounds and their waveforms, tiles */
228
+ export function viewFilesOf(i: Item): string[] {
229
+ return i.views.flatMap((v) => {
230
+ if (isGallery(v)) return v.gallery.map((g) => g.file)
231
+ return [...Object.values(v.files), ...(v.clip ? [v.clip.poster] : []), ...(v.audio ? [v.audio.wave, ...(v.audio.waveBefore ? [v.audio.waveBefore] : [])] : [])]
232
+ })
233
+ }
210
234
 
211
235
  /** the first view, media when there is one; a note with no image has none */
212
236
  export const firstView = (i: Item): MediaView | undefined => i.views[0] as MediaView | undefined
@@ -909,10 +933,11 @@ function reactionsOf(v: unknown, views: readonly ReviewView[], errors: string[],
909
933
  return out
910
934
  }
911
935
 
912
- /** what a reaction or a rectangle is on, as the CLI prints it: `[from above]`, `[trees / oak-v2]` */
936
+ /** what a reaction or a rectangle is on, as the CLI prints it: its view's letter and label, `[B from above]`,
937
+ * `[C trees / oak-v2]`, `[A]` */
913
938
  export function placeText(r: { view?: number | undefined; tile?: number | undefined }, views: readonly ReviewView[]): string {
914
939
  const i = r.view ?? 0
915
940
  const v = views[i]
916
941
  const tile = r.tile !== undefined && v && isGallery(v) ? ` / ${v.gallery[r.tile]?.label || `image ${r.tile + 1}`}` : ''
917
- return `[${viewName(v, i)}${tile}]`
942
+ return `[${viewLetter(i)}${v?.label ? ` ${v.label}` : ''}${tile}]`
918
943
  }