rvlib-shipkit 2.15.0 → 2.17.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 (45) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/package.json +1 -1
  3. package/src/assets/kit-config.ts +19 -1
  4. package/src/assets/run-assets.ts +18 -0
  5. package/src/checks/SK038-speaks-as.check.ts +66 -0
  6. package/src/cli/cmd_Drill.ts +219 -12
  7. package/src/cli/cmd_Media.ts +34 -8
  8. package/src/cli/cmd_Review.ts +22 -7
  9. package/src/cli/cmd_Secret.ts +127 -0
  10. package/src/cli/cmd_Social.ts +19 -9
  11. package/src/cli/cmd_Wiki.ts +4 -4
  12. package/src/cli/family-pages.ts +1 -0
  13. package/src/cli/registry.ts +8 -1
  14. package/src/core/scope.ts +42 -0
  15. package/src/drill/card.ts +65 -0
  16. package/src/drill/clean.ts +17 -6
  17. package/src/drill/finish.ts +67 -0
  18. package/src/drill/render.ts +21 -2
  19. package/src/drill/run.ts +51 -2
  20. package/src/drill/score.ts +68 -0
  21. package/src/drill/seal.ts +259 -0
  22. package/src/home/home-paths.ts +10 -1
  23. package/src/init-repo.ts +14 -4
  24. package/src/media-store/content.ts +1 -1
  25. package/src/media-store/hand.ts +6 -1
  26. package/src/media-store/put.ts +11 -7
  27. package/src/media-store/space.ts +17 -3
  28. package/src/repo-config.ts +4 -1
  29. package/src/review/auto.ts +7 -2
  30. package/src/review/cells.ts +1 -1
  31. package/src/review/format.ts +2 -2
  32. package/src/review/model.ts +46 -13
  33. package/src/review/previews.ts +1 -1
  34. package/src/review/routes.ts +11 -0
  35. package/src/review/store.ts +18 -10
  36. package/src/secrets/list.ts +40 -0
  37. package/src/serve/hub-app/cols-svc.ts +2 -1
  38. package/src/serve/hub-app/review/review-kit.ts +4 -0
  39. package/src/serve/hub-app/review/review-st.ts +40 -3
  40. package/src/serve/hub-app/review/review-views.tsx +145 -64
  41. package/src/serve/hub-app/review/thread-st.ts +76 -16
  42. package/src/serve/hub-app/review.css +17 -2
  43. package/src/shipkit.ts +1 -1
  44. package/src/social/house.ts +7 -5
  45. package/src/wiki/run-wiki.ts +13 -3
@@ -8,6 +8,7 @@
8
8
  // a slot that can't fill emits a visible reason, and one turned off with
9
9
  // `off: { x: '<why>' }` prints a skipped-by-config line, never silence.
10
10
  // The `contracts` task is always present when any contract applies.
11
+ import type { Scope } from './core/scope.ts'
11
12
  import { existsSync, readFileSync } from 'fs'
12
13
  import { isAbsolute, join, normalize } from 'path'
13
14
  import { ROUTED_SCRIPTS } from './core/canonical-scripts.ts'
@@ -105,7 +106,7 @@ export type RepoConfig = {
105
106
  /** retired with the v2 social contract: read by nothing; delete the line (`sk social migrate` moves the posts) */
106
107
  social?: string[]
107
108
  /** the identity that speaks for this repo in public, an id of the house repo's `.shipkit/identities/` (`sk
108
- * identities`); unset, the one marked `default: true` speaks. A draft may name another (wiki
109
+ * identities`); required on a machine with identities (SK038). A draft may name another (wiki
109
110
  * tools/shipkit/social.md) */
110
111
  speaksAs?: string
111
112
  /** machine-only state of this repo the backup keeps beyond its own rule (wiki tools/shipkit/media-store.md,
@@ -155,6 +156,8 @@ export type RepoConfig = {
155
156
  * for something nothing uses yet, so it is dim and stays out of
156
157
  * `shipkit needs`. Default `used` */
157
158
  level?: 'core' | 'used' | 'minor'
159
+ /** the repos and identities it is for (`sk secret list` shows a repo only its own). Absent: every repo */
160
+ for?: Scope
158
161
  }[]
159
162
  /** store-command template for a missing secret tile, `{name}` substituted, as in your secret manager's set command */
160
163
  credsCommand?: string
@@ -1,7 +1,7 @@
1
1
  // auto rules (wiki tools/shipkit/review.md, A project's parts): a rule of the repo's review unit answers on a clock, and
2
2
  // its answer is raised as an item to a lane, open from the start. One open item a rule and key. The hub's daemon runs
3
3
  // them (startAuto), `sk review auto` reads their logs and runs one now
4
- import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
4
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
5
5
  import { join } from 'node:path'
6
6
  import { stateOf, type ReviewItem } from './model.ts'
7
7
  import { raiseItem } from './store.ts'
@@ -26,6 +26,10 @@ export interface AutoLog {
26
26
  /** the logs sit beside the store, out of its watch */
27
27
  export const autoLogDir = (dir: string): string => join(dir, '..', 'review-auto')
28
28
 
29
+ /** the repo a store dir lives in (`<repo>/.shipkit/review`): a run never writes into a repo that moved away, so nothing
30
+ * recreates its old folder */
31
+ const repoOf = (dir: string): string => join(dir, '..', '..')
32
+
29
33
  export function readAutoLog(dir: string, id: string): AutoLog | null {
30
34
  try {
31
35
  return JSON.parse(readFileSync(join(autoLogDir(dir), `${id}.json`), 'utf8')) as AutoLog
@@ -64,6 +68,7 @@ const answerText = (outcomes: readonly Outcome[]): string =>
64
68
  /** one rule evaluated now: its raises written as items, unless an open one holds the key; `dry` writes nothing, the log
65
69
  * included. A rule that throws is logged and rethrown */
66
70
  export async function runRule(dir: string, rule: AutoRule, o: { items: readonly ReviewItem[]; now?: Date; dry?: boolean }): Promise<Outcome[]> {
71
+ if (!existsSync(repoOf(dir))) throw new Error(`${repoOf(dir)} is gone (moved or renamed): rule ${rule.id} writes nothing there`)
67
72
  const now = o.now ?? new Date()
68
73
  const before = readAutoLog(dir, rule.id)
69
74
  const t0 = performance.now()
@@ -123,7 +128,7 @@ export function startAuto(dir: string, rules: readonly AutoRule[], items: () =>
123
128
  for (const rule of rules) {
124
129
  const tick = (): void =>
125
130
  void autoTick(dir, rule, items).then(() => {
126
- if (stopped) return
131
+ if (stopped || !existsSync(repoOf(dir))) return
127
132
  const t = setTimeout(tick, everyMs(rule.every))
128
133
  t.unref()
129
134
  timers.add(t)
@@ -474,7 +474,7 @@ function rowOf(t: Thread, items: readonly ReviewItem[], followed: ReadonlySet<st
474
474
  views: h.item.views.length,
475
475
  thumb: first ? thumbFileOf(first) || null : null,
476
476
  clip: h.item.views.some((v) => !isGallery(v) && v.clip !== undefined),
477
- pair: first !== undefined && isPair(first.files),
477
+ pair: first !== undefined && !isGallery(first) && isPair(first.files),
478
478
  choice: h.item.choice === true,
479
479
  wip: h.item.wip !== undefined,
480
480
  waits: waits(h),
@@ -19,7 +19,7 @@ const atText = (t: number | undefined): string => (t === undefined ? '' : ` at $
19
19
 
20
20
  /** each reaction to one view or tile: its place by label, its status, its comment */
21
21
  const reactionTexts = (x: ReviewItem): string[] =>
22
- (verdictOf(x)?.reactions ?? []).map((q) => `${placeText(q, x.item.views)}${q.status ? ` ${q.status}` : ''}${q.stars ? ` ★${q.stars}` : ''}${q.comment ? `: ${flat(q.comment)}` : ''}`)
22
+ (verdictOf(x)?.reactions ?? []).map((q) => `${placeText(q, x.item.views)}${q.picked ? ' picked' : ''}${q.status ? ` ${q.status}` : ''}${q.stars ? ` ★${q.stars}` : ''}${q.comment ? `: ${flat(q.comment)}` : ''}`)
23
23
 
24
24
  /** the view he picked on a choice card, `picked [voice 1]`; null when he picked none */
25
25
  const pickText = (x: ReviewItem): string | null => {
@@ -33,7 +33,7 @@ export function line(x: ReviewItem): string {
33
33
  if (!f) return x.item.id
34
34
  const views = x.item.views
35
35
  const many = views.length > 1
36
- const rects = f.rects.map((q, i) => `#${i + 1}${many ? ` ${placeText(q, views)}` : ''}${q.side ? ` ${q.side}` : ''}${atText(q.t)} ${flat(q.comment) || '(no comment)'}`)
36
+ const rects = f.rects.map((q, i) => `#${i + 1}${many || q.tile !== undefined ? ` ${placeText(q, views)}` : ''}${q.side ? ` ${q.side}` : ''}${atText(q.t)} ${flat(q.comment) || '(no comment)'}`)
37
37
  const pick = pickText(x)
38
38
  const parts = [...(pick ? [pick] : []), ...reactionTexts(x), ...rects]
39
39
  return `${x.item.id} ${f.status} "${x.item.title}": ${flat(f.comment) || '(no overall comment)'}${parts.length ? ` | ${parts.join(' | ')}` : ''}`
@@ -153,9 +153,16 @@ export interface GalleryTile {
153
153
  file: string
154
154
  label: string
155
155
  size: { w: number; h: number }
156
+ /** the asset as it was, `v<n>-g<k>-before.<ext>`: the tile shows the after, the before on a peek */
157
+ before?: string
158
+ /** the row it is a variant in: one asset per row, he picks at most one tile of a row */
159
+ group?: string
156
160
  }
157
161
 
158
- /** a view that is a list of small images, shown as a wrapping grid; never the first view */
162
+ /** a tile's name in the CLI's lines: `vitality/b` for a variant, else its label */
163
+ export const tileName = (t: GalleryTile): string => (t.group ? `${t.group}/${t.label}` : t.label)
164
+
165
+ /** a view that is a list of small images, shown as a wrapping grid, or as rows of variants when its tiles name a group */
159
166
  export interface GalleryView {
160
167
  label: string
161
168
  gallery: GalleryTile[]
@@ -180,7 +187,7 @@ export interface Item {
180
187
  what?: string
181
188
  topic?: string
182
189
  commit?: string
183
- /** the first is a media view, never a gallery */
190
+ /** a media view (an image, a clip, a sound, a pair) or a gallery of images, any of them first */
184
191
  views: ReviewView[]
185
192
  /** an earlier card this one is a new version of; never a raised item */
186
193
  supersedes?: string
@@ -252,13 +259,13 @@ export const viewName = (v: ReviewView | undefined, i: number): string => v?.lab
252
259
  /** every media file a card's views name: images, pairs, clips and their posters, sounds and their waveforms, tiles */
253
260
  export function viewFilesOf(i: Item): string[] {
254
261
  return i.views.flatMap((v) => {
255
- if (isGallery(v)) return v.gallery.map((g) => g.file)
262
+ if (isGallery(v)) return v.gallery.flatMap((g) => [g.file, ...(g.before ? [g.before] : [])])
256
263
  return [...Object.values(v.files), ...(v.clip ? [v.clip.poster] : []), ...(v.audio ? [v.audio.wave, ...(v.audio.waveBefore ? [v.audio.waveBefore] : [])] : [])]
257
264
  })
258
265
  }
259
266
 
260
- /** the first view, media when there is one; a note with no image has none */
261
- export const firstView = (i: Item): MediaView | undefined => i.views[0] as MediaView | undefined
267
+ /** the first view: media or a gallery; a note with no image has none */
268
+ export const firstView = (i: Item): ReviewView | undefined => i.views[0]
262
269
 
263
270
  /** the file that stands for a view in a list: a clip's first frame, the after of a pair, the image */
264
271
  export function thumbFileOf(v: ReviewView): string {
@@ -286,6 +293,8 @@ export interface Rect {
286
293
  side?: Side
287
294
  /** the clip time it was drawn at, in seconds */
288
295
  t?: number
296
+ /** the gallery tile it is drawn on, its coordinates the tile's image */
297
+ tile?: number
289
298
  world?: { x0: number; y0: number; x1: number; y1: number }
290
299
  nodes?: string[]
291
300
  }
@@ -305,6 +314,8 @@ export interface ReviewReaction {
305
314
  comment: string
306
315
  /** his score of the view, 1 to STARS */
307
316
  stars?: number
317
+ /** a variant tile he keeps for its row: at most one a row */
318
+ picked?: true
308
319
  }
309
320
 
310
321
  /** a state change, or a read mark (`seen`, with the ids it read in `of`) */
@@ -668,7 +679,7 @@ export function untakenOf(x: ReviewItem, superseded: boolean, watchers: readonly
668
679
  }
669
680
 
670
681
  export const ID_RE = /^\d{8}-\d{6}-[a-z0-9-]+$/
671
- export const FILE_RE = /^((v\d+-)?((image|before|after|poster|wave|before-wave)\.(png|jpe?g|webp)|(video|before|after)\.(webm|mp4)|(audio|before|after)\.(wav|mp3|flac|ogg|opus|m4a))|v\d+-g\d+\.(png|jpe?g|webp))$/
682
+ export const FILE_RE = /^((v\d+-)?((image|before|after|poster|wave|before-wave)\.(png|jpe?g|webp)|(video|before|after)\.(webm|mp4)|(audio|before|after)\.(wav|mp3|flac|ogg|opus|m4a))|v\d+-g\d+(-before)?\.(png|jpe?g|webp))$/
672
683
  /** a message's image as an item's media names it: `thread/<file>` */
673
684
  export const isThreadMedia = (n: string): boolean => n.startsWith('thread/') && MESSAGE_FILE_RE.test(n.slice('thread/'.length))
674
685
  /** a name an item's media may hold: a view's file or a message's image */
@@ -678,6 +689,7 @@ export const mediaFilesOf = (x: { item: Item; thread: readonly Message[] }): str
678
689
  /** the message images an item's media already holds: a rewrite of its views keeps their facts */
679
690
  export const threadMediaOf = (i: Item): string[] => Object.keys(i.media ?? {}).filter(isThreadMedia)
680
691
  const TILE_RE = /^v\d+-g\d+\.(png|jpe?g|webp)$/
692
+ const TILE_BEFORE_RE = /^v\d+-g\d+-before\.(png|jpe?g|webp)$/
681
693
  const POSTER_RE = /^(v\d+-)?poster\.png$/
682
694
 
683
695
  /** a clip by its extension: webm or mp4 */
@@ -769,11 +781,11 @@ export function itemProblems(v: unknown): string[] {
769
781
  out.push(...subjectProblems(v.subject, NO_SPEC), ...originProblems(v.origin))
770
782
  if (v.topic !== undefined && typeof v.topic !== 'string') out.push('topic: a text')
771
783
  const agent = obj(v.origin) && v.origin.by === 'agent'
772
- if (!Array.isArray(v.views) || (agent && v.views.length === 0)) out.push(`views: a list${agent ? ', the first a media view' : ''}`)
784
+ if (!Array.isArray(v.views) || (agent && v.views.length === 0)) out.push(`views: a list${agent ? ' of one view or more' : ''}`)
773
785
  else
774
786
  v.views.forEach((w: unknown, i: number) => {
775
787
  if (i > 0 && (!obj(w) || typeof w.label !== 'string' || w.label.trim() === '')) out.push(`views[${i}].label: a text`)
776
- if (obj(w) && w.gallery !== undefined) out.push(...(i === 0 ? ['views[0]: never a gallery'] : galleryProblems(w, `views[${i}].`)))
788
+ if (obj(w) && w.gallery !== undefined) out.push(...galleryProblems(w, `views[${i}].`))
777
789
  else out.push(...viewProblems(obj(w) ? w : {}, `views[${i}].`))
778
790
  })
779
791
  if (v.answers !== undefined && !(Array.isArray(v.answers) && v.answers.length > 0 && v.answers.every((a) => typeof a === 'string' && ID_RE.test(a))))
@@ -817,6 +829,8 @@ function galleryProblems(v: Record<string, unknown>, at: string): string[] {
817
829
  g.forEach((t: unknown, k: number) => {
818
830
  const ok = obj(t) && typeof t.file === 'string' && TILE_RE.test(t.file) && typeof t.label === 'string' && obj(t.size) && Number(t.size.w) > 0 && Number(t.size.h) > 0
819
831
  if (!ok) out.push(`${at}gallery[${k}]: { file: v<n>-g<k>.<png|jpg|webp>, label, size: { w, h } }`)
832
+ if (obj(t) && t.before !== undefined && !(typeof t.before === 'string' && TILE_BEFORE_RE.test(t.before))) out.push(`${at}gallery[${k}].before: v<n>-g<k>-before.<png|jpg|webp>`)
833
+ if (obj(t) && t.group !== undefined && !(typeof t.group === 'string' && t.group.trim() !== '')) out.push(`${at}gallery[${k}].group: a text`)
820
834
  })
821
835
  for (const k of ['files', 'size', 'clip', 'marks']) if (v[k] !== undefined) out.push(`${at}${k}: none on a gallery view`)
822
836
  return out
@@ -894,7 +908,13 @@ export function verdictMessageOf(body: unknown, item: Item): { ok: true; message
894
908
  continue
895
909
  }
896
910
  if (isGallery(on)) {
897
- errors.push(`rects[${i}].view: no rectangle on a gallery view, react to its tile instead`)
911
+ const tile = r.tile
912
+ if (!(typeof tile === 'number' && Number.isInteger(tile) && tile >= 0 && tile < on.gallery.length)) errors.push(`rects[${i}].tile: the index of the gallery tile it is drawn on`)
913
+ else out.push({ x: r.x, y: r.y, w: r.w, h: r.h, comment: typeof r.comment === 'string' ? r.comment : '', ...(view !== 0 ? { view: view as number } : {}), tile })
914
+ continue
915
+ }
916
+ if (r.tile !== undefined) {
917
+ errors.push(`rects[${i}].tile: only on a gallery view`)
898
918
  continue
899
919
  }
900
920
  if (on.audio) {
@@ -945,6 +965,7 @@ function reactionsOf(v: unknown, views: readonly ReviewView[], errors: string[],
945
965
  }
946
966
  const out: ReviewReaction[] = []
947
967
  const seen = new Set<string>()
968
+ const rowsPicked = new Set<string>()
948
969
  for (const [i, r] of v.entries()) {
949
970
  const on = obj(r) && typeof r.view === 'number' && Number.isInteger(r.view) ? views[r.view] : undefined
950
971
  if (!obj(r) || !on) {
@@ -957,19 +978,30 @@ function reactionsOf(v: unknown, views: readonly ReviewView[], errors: string[],
957
978
  if (r.status !== undefined && !STATUSES.includes(r.status as ReviewStatus)) errors.push(`reactions[${i}].status: one of ${STATUSES.join(', ')}`)
958
979
  if (r.comment !== undefined && typeof r.comment !== 'string') errors.push(`reactions[${i}].comment: a text`)
959
980
  const stars = r.stars
960
- if (stars !== undefined && !(choice && typeof stars === 'number' && Number.isInteger(stars) && stars >= 1 && stars <= STARS))
961
- errors.push(choice ? `reactions[${i}].stars: 1 to ${STARS}` : `reactions[${i}].stars: only on a choice card`)
981
+ // a choice scores its options, a gallery each of its tiles
982
+ const scored = choice || (typeof tile === 'number' && tiles > 0)
983
+ if (stars !== undefined && !(scored && typeof stars === 'number' && Number.isInteger(stars) && stars >= 1 && stars <= STARS))
984
+ errors.push(scored ? `reactions[${i}].stars: 1 to ${STARS}` : `reactions[${i}].stars: only on a choice card or a gallery tile`)
962
985
  const key = `${String(r.view)}/${String(tile ?? '')}`
963
986
  if (seen.has(key)) errors.push(`reactions[${i}]: a second reaction on the same view or tile`)
964
987
  seen.add(key)
988
+ // a variant he keeps: one tile a row
989
+ const group = typeof tile === 'number' && isGallery(on) ? on.gallery[tile]?.group : undefined
990
+ const picked = r.picked
991
+ if (picked !== undefined) {
992
+ if (picked !== true || group === undefined) errors.push(`reactions[${i}].picked: true, only on a tile of a row of variants`)
993
+ else if (rowsPicked.has(`${String(r.view)}/${group}`)) errors.push(`reactions[${i}].picked: one tile a row, and ${group} has one already`)
994
+ else rowsPicked.add(`${String(r.view)}/${group}`)
995
+ }
965
996
  const comment = typeof r.comment === 'string' ? r.comment.trim() : ''
966
- if (r.status === undefined && comment === '' && stars === undefined) continue
997
+ if (r.status === undefined && comment === '' && stars === undefined && picked !== true) continue
967
998
  out.push({
968
999
  view: r.view as number,
969
1000
  ...(typeof tile === 'number' ? { tile } : {}),
970
1001
  ...(r.status !== undefined ? { status: r.status as ReviewStatus } : {}),
971
1002
  comment,
972
1003
  ...(typeof stars === 'number' ? { stars } : {}),
1004
+ ...(picked === true && group !== undefined ? { picked: true as const } : {}),
973
1005
  })
974
1006
  }
975
1007
  return out
@@ -980,6 +1012,7 @@ function reactionsOf(v: unknown, views: readonly ReviewView[], errors: string[],
980
1012
  export function placeText(r: { view?: number | undefined; tile?: number | undefined }, views: readonly ReviewView[]): string {
981
1013
  const i = r.view ?? 0
982
1014
  const v = views[i]
983
- const tile = r.tile !== undefined && v && isGallery(v) ? ` / ${v.gallery[r.tile]?.label || `image ${r.tile + 1}`}` : ''
1015
+ const t = r.tile !== undefined && v && isGallery(v) ? v.gallery[r.tile] : undefined
1016
+ const tile = r.tile !== undefined && v && isGallery(v) ? ` / ${(t && tileName(t)) || `image ${r.tile + 1}`}` : ''
984
1017
  return `[${viewLetter(i)}${v?.label ? ` ${v.label}` : ''}${tile}]`
985
1018
  }
@@ -133,7 +133,7 @@ const mediaOf = (dir: string, id: string): Record<string, unknown> => {
133
133
  /** every image a card draws: each view's image or pair, a clip's poster, a sound's waveforms, a gallery's tiles */
134
134
  export function imagesOf(i: Item): string[] {
135
135
  const names = i.views.flatMap((v) => {
136
- if (isGallery(v)) return v.gallery.map((g) => g.file)
136
+ if (isGallery(v)) return v.gallery.flatMap((g) => [g.file, ...(g.before ? [g.before] : [])])
137
137
  const f = v.files
138
138
  return [...('image' in f ? [f.image] : isPair(f) ? [f.before, f.after] : []), ...(v.clip ? [v.clip.poster] : []), ...(v.audio ? [v.audio.wave, ...(v.audio.waveBefore ? [v.audio.waveBefore] : [])] : [])]
139
139
  })
@@ -16,6 +16,7 @@ import { roleOf } from './role.ts'
16
16
  import { addMessage, imageFile, itemOfRef, markRead, raiseItem, rateSubject, readAllCached, readItem, specOf, storeDir, storeStamp, threadImage, writeVerdict } from './store.ts'
17
17
  import { boardOf, pageOf, queryOf, threadIndex, threadOfId, threadView, type ThreadIndex } from './cells.ts'
18
18
  import { membersOf, threadsOf, type Thread } from './threads.ts'
19
+ import { putMedia } from '../media-store/put.ts'
19
20
  import { upKeys } from '../media-store/remote.ts'
20
21
  import { remoteUrl, reviewKey } from './media-read.ts'
21
22
  import { trailerRoutes } from './trailer-routes.ts'
@@ -67,6 +68,8 @@ let listing: { dir: string; tag: string; body: string; zipped: Uint8Array<ArrayB
67
68
  // ── the paged list and one thread: an index over the store's threads, built again when a file moved or a minute
68
69
  // passed (a claim goes stale on the clock); its build number is every answer's ETag ──
69
70
 
71
+ /** the label a card's file is published under: `public/review-share/<sha>.<ext>` (the review kind's own label is the code's) */
72
+ const SHARE_LABEL = 'review-share'
70
73
  const INDEX_MS = 60_000
71
74
  const BOOT = Date.now().toString(36)
72
75
  let builds = 0
@@ -251,6 +254,14 @@ async function reviewRoute(req: Request, path: string, dir: string, unit: Review
251
254
  const r = Bun.spawnSync(['open', ...(typeof b.file === 'string' ? ['-R'] : []), target], { stdout: 'ignore', stderr: 'pipe' })
252
255
  return r.exitCode === 0 ? Response.json({ ok: true }, { headers: NO_STORE }) : bad(`open: ${r.stderr.toString().trim() || `exit ${r.exitCode}`}`, 500)
253
256
  }
257
+ // one of the card's files published in the Space: a permanent public URL through the cdn, the same key for the same content
258
+ if (name === 'share') {
259
+ const b = (await req.json().catch(() => ({}))) as { file?: unknown }
260
+ const target = typeof b.file === 'string' ? imageFile(dir, id, b.file) : null
261
+ if (!target) return bad(`no file ${id}/${String(b.file)} on this disk`, 404)
262
+ const p = await putMedia(target, { public: true, kind: SHARE_LABEL })
263
+ return Response.json({ url: p.url, key: p.key, sent: p.sent }, { headers: NO_STORE })
264
+ }
254
265
  } catch (e) {
255
266
  return bad(e)
256
267
  }
@@ -95,7 +95,7 @@ export interface ViewInput {
95
95
  before?: string
96
96
  after?: string
97
97
  /** a list of small images shown as a wrapping grid, each with its label; never the first view */
98
- gallery?: { file: string; label: string }[]
98
+ gallery?: { file: string; label: string; before?: string; group?: string }[]
99
99
  /** a line on this view alone: an option's description on a choice card */
100
100
  note?: string
101
101
  }
@@ -145,7 +145,7 @@ interface Loaded {
145
145
  clip?: { duration: number; fps: number; from: string }
146
146
  /** a sound: its length, and the files its waveforms are drawn from (the after's or the one's, then the before's) */
147
147
  audio?: { duration: number; from: string; before?: string }
148
- tiles?: { path: string; label: string; size: { w: number; h: number } }[]
148
+ tiles?: { path: string; label: string; size: { w: number; h: number }; before?: string; group?: string }[]
149
149
  }
150
150
 
151
151
  /** a view's files checked and sized, a pair of one size (and one length, two clips); throws with the reason, naming the view */
@@ -156,10 +156,15 @@ async function loadView(v: ViewInput, which: string): Promise<Loaded> {
156
156
  if (v.gallery.length === 0) throw new Error(`${which}: a gallery needs at least one image`)
157
157
  const tiles = await Promise.all(
158
158
  v.gallery.map(async (t) => {
159
- const path = resolve(t.file)
160
- if (!existsSync(path)) throw new Error(`${path}: no such file`)
161
- if (!IMAGE_EXT.test(extname(path).toLowerCase())) throw new Error(`${which}: ${path}: a gallery holds png, jpg or webp images, never a clip`)
162
- return { path, label: t.label.trim(), size: await sizeOf(path) }
159
+ const image = (f: string): string => {
160
+ const path = resolve(f)
161
+ if (!existsSync(path)) throw new Error(`${path}: no such file`)
162
+ if (!IMAGE_EXT.test(extname(path).toLowerCase())) throw new Error(`${which}: ${path}: a gallery holds png, jpg or webp images, never a clip`)
163
+ return path
164
+ }
165
+ const path = image(t.file)
166
+ const group = t.group?.trim()
167
+ return { path, label: t.label.trim(), size: await sizeOf(path), ...(t.before !== undefined ? { before: image(t.before) } : {}), ...(group ? { group } : {}) }
163
168
  }),
164
169
  )
165
170
  return { label: v.label.trim(), sources: [], size: tiles[0]?.size ?? { w: 0, h: 0 }, tiles }
@@ -254,10 +259,14 @@ async function writeWaves(v: Loaded, n: number, folder: string): Promise<void> {
254
259
  const prefix = (n: number): string => (n > 0 ? `v${n}-` : '')
255
260
 
256
261
  /** the file name of tile `k` of gallery view `n` */
257
- const tileName = (n: number, k: number, path: string): string => `v${n}-g${k}${extname(path).toLowerCase()}`
262
+ const tileName = (n: number, k: number, path: string, side = ''): string => `v${n}-g${k}${side}${extname(path).toLowerCase()}`
258
263
 
259
264
  function viewOf(v: Loaded, n: number, marks: readonly ReviewMark[] = [], note?: string): ReviewView {
260
- if (v.tiles) return { label: v.label, gallery: v.tiles.map((t, k): GalleryTile => ({ file: tileName(n, k, t.path), label: t.label, size: t.size })) }
265
+ if (v.tiles)
266
+ return {
267
+ label: v.label,
268
+ gallery: v.tiles.map((t, k): GalleryTile => ({ file: tileName(n, k, t.path), label: t.label, size: t.size, ...(t.before ? { before: tileName(n, k, t.before, '-before') } : {}), ...(t.group ? { group: t.group } : {}) })),
269
+ }
261
270
  const audio = v.audio ? { audio: { duration: v.audio.duration, wave: `${prefix(n)}wave.png`, ...(v.audio.before ? { waveBefore: `${prefix(n)}before-wave.png` } : {}) } } : {}
262
271
  return { label: v.label, files: filesOf(v, n), size: v.size, ...clipOf(v, n), ...audio, ...(marks.length > 0 ? { marks: [...marks] } : {}), ...(note?.trim() ? { note: note.trim() } : {}) }
263
272
  }
@@ -305,7 +314,6 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
305
314
  )
306
315
  if (given.length === 0) throw new Error('give --image, --video or --audio, or --before and --after, or --view "<label>" <image>')
307
316
  for (const [i, v] of given.entries()) if (i > 0 && !v.label.trim()) throw new Error('--view: every view after the first needs its label')
308
- if (given[0]?.gallery) throw new Error('a gallery is never the first view: give the card an --image (or a pair, or a clip) first')
309
317
  if (input.choice && given.length < 2) throw new Error('--choice: a choice has two options or more, one --view each')
310
318
  for (const v of given) if (v.note !== undefined && v.gallery) throw new Error(`--view "${v.label}": a note goes on an image, a clip or a sound, never a gallery`)
311
319
  const loaded = await Promise.all(given.map((v, i) => loadView(v, i === 0 ? 'the first view' : `--view "${v.label}"`)))
@@ -385,7 +393,7 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
385
393
  /** every file of view `n` into the folder, each as `<name>.tmp` renamed, so no reader sees half of one */
386
394
  function copyFiles(v: Loaded, n: number, into: string): void {
387
395
  const files = filesOf(v, n) as Record<string, string>
388
- const copies: [string, string][] = [...v.sources.map(([name, p]): [string, string] => [p, files[name] ?? name]), ...(v.tiles ?? []).map((t, k): [string, string] => [t.path, tileName(n, k, t.path)])]
396
+ const copies: [string, string][] = [...v.sources.map(([name, p]): [string, string] => [p, files[name] ?? name]), ...(v.tiles ?? []).flatMap((t, k): [string, string][] => [[t.path, tileName(n, k, t.path)], ...(t.before ? [[t.before, tileName(n, k, t.before, '-before')] as [string, string]] : [])])]
389
397
  for (const [from, name] of copies) {
390
398
  const to = join(into, name)
391
399
  copyFileSync(from, `${to}.tmp`)
@@ -0,0 +1,40 @@
1
+ // the secrets one repo is for: the house's registry rows in its scope, plus the
2
+ // repo's own `creds`. Presence reads each value through `credsReadCommand` and
3
+ // keeps only whether it answered: a value is never printed, logged or returned.
4
+ import { inScope, scopesAll, scopeText, type Asker } from '../core/scope.ts'
5
+ import type { RepoConfig } from '../repo-config.ts'
6
+ import { secretArgv } from '../smoke/run-smoke.ts'
7
+
8
+ export type Cred = NonNullable<RepoConfig['creds']>[number]
9
+
10
+ /** `for`: the scope as its md cell; `mine`: the scope names this repo or its identity, not every repo */
11
+ export type SecretRow = { name: string; service?: string; level: 'core' | 'used' | 'minor'; for: string; mine: boolean; inScope: boolean }
12
+
13
+ /** the repo's own creds win over a house row of the same name; out of scope rows only with `all` */
14
+ export function secretsFor(o: { asker: Asker; own: Cred[]; house: Cred[]; all?: boolean }): SecretRow[] {
15
+ const byName = new Map<string, Cred>()
16
+ for (const c of o.house) byName.set(c.name, c)
17
+ for (const c of o.own) byName.set(c.name, { ...c, for: c.for ?? { repos: [o.asker.repos[0]!] } })
18
+ const rows = [...byName.values()].map((c): SecretRow => ({
19
+ name: c.name,
20
+ ...(c.service != null ? { service: c.service } : {}),
21
+ level: c.level ?? 'used',
22
+ for: scopeText(c.for),
23
+ mine: !scopesAll(c.for) && inScope(c.for, o.asker),
24
+ inScope: inScope(c.for, o.asker),
25
+ }))
26
+ return rows
27
+ .filter((r) => o.all === true || r.inScope)
28
+ .sort((a, b) => Number(b.mine) - Number(a.mine) || Number(b.inScope) - Number(a.inScope) || a.name.localeCompare(b.name))
29
+ }
30
+
31
+ /** whether each secret answers through the read command, all at once */
32
+ export async function presence(reader: string, names: string[]): Promise<Map<string, boolean>> {
33
+ const out = new Map<string, boolean>()
34
+ await Promise.all(names.map(async (name) => {
35
+ const p = Bun.spawn(secretArgv(reader, name, 'get'), { stdout: 'pipe', stderr: 'ignore' })
36
+ const answered = (await new Response(p.stdout).text()).trim() !== ''
37
+ out.set(name, (await p.exited) === 0 && answered)
38
+ }))
39
+ return out
40
+ }
@@ -116,7 +116,8 @@ export class ColsSvc {
116
116
  * screen does not name yet is kept at once, so the header's media link
117
117
  * is there on the next load */
118
118
  mediaListed(): void {
119
- const cat = this.st.media.assets[0]?.cat ?? null
119
+ // a heartbeat can land after its page state is gone (a closed tab, a test's teardown)
120
+ const cat = this.st.media?.assets[0]?.cat ?? null
120
121
  if (this.last != null && cat !== this.keptCat) this.keep(this.last, cat, true)
121
122
  }
122
123
 
@@ -6,6 +6,10 @@ import { reach } from '../reach.ts'
6
6
  export const ZOOMS = ['fit', '1', '1.5', '2'] as const
7
7
  export type Zoom = (typeof ZOOMS)[number]
8
8
 
9
+ /** a gallery tile's image height in px: his slider's range and its start; past THUMB a tile reads the fit preview, the
10
+ * list thumb is too small for it */
11
+ export const TILE_H = { min: 80, max: 480, start: 170, thumb: 220 } as const
12
+
9
13
  /** what a reload must not lose: a blocked storage only loses persistence */
10
14
  export const kept = {
11
15
  get(k: string): string | null {
@@ -8,7 +8,7 @@ import { MOVE_LABEL, pasteBlock, STATUS_LABEL, type Move, type ShownStatus, type
8
8
  import type { PasteHosts } from '../../../review/paste.ts'
9
9
  import type { Role } from '../../../review/role.ts'
10
10
  import type { RepoSt } from '../repo-st.ts'
11
- import { copyText, etagLoader, kept, postJson, ZOOMS, type EtagLoader, type Zoom } from './review-kit.ts'
11
+ import { copyText, etagLoader, kept, postJson, TILE_H, ZOOMS, type EtagLoader, type Zoom } from './review-kit.ts'
12
12
  import { ThreadSt, type Draft } from './thread-st.ts'
13
13
 
14
14
  /** a live `sk review watch`: its process, the session or lane it keeps, when it started */
@@ -60,6 +60,10 @@ export class CompareSt {
60
60
  if (m && (COMPARE_MODES as readonly string[]).includes(m)) this.mode = m as CompareMode
61
61
  makeAutoObservable<this, 'key'>(this, { key: false })
62
62
  }
63
+ /** the mode a pair draws in: the changes read pixels from two images, so a pair of clips shows side by side */
64
+ modeFor(clip: boolean): CompareMode {
65
+ return clip && this.mode === 'diff' ? 'side' : this.mode
66
+ }
63
67
  setMode(m: CompareMode): void {
64
68
  this.mode = m
65
69
  kept.put(this.key, m)
@@ -133,6 +137,10 @@ export class ReviewSt {
133
137
  /** the subject rings over the image (M) */
134
138
  marksOn = true
135
139
  zoom: Zoom = 'fit'
140
+ /** a gallery tile's height, his slider */
141
+ tileH: number = TILE_H.start
142
+ /** each gallery tile also drawn at 16, 32 and 64 px, the sizes an icon lives at */
143
+ tileSmall = false
136
144
  /** the contents strip beside the cells, when the column is wide enough; folded by hand */
137
145
  railOn = true
138
146
  /** the contents as a sheet over the cells: a narrow column or the phone */
@@ -141,6 +149,8 @@ export class ReviewSt {
141
149
  width = 0
142
150
  /** what the last copy put on the clipboard, in words, shown a moment */
143
151
  toast: string | null = null
152
+ /** a card file's public url once published, `sending` while it goes up; keyed `<id>/<file>` */
153
+ shared = new Map<string, string | 'sending'>()
144
154
  readonly compare: CompareSt
145
155
  readonly phone = new PhoneSt()
146
156
  /** the view a link names before its card is made */
@@ -164,12 +174,14 @@ export class ReviewSt {
164
174
  this.loadBoard = etagLoader(() => st.url('/api/review/board'))
165
175
  this.compare = new CompareSt(`${this.prefix}compare`)
166
176
  try {
167
- const p = JSON.parse(kept.get(`${this.prefix}prefs`) ?? '{}') as { hideHandled?: boolean; byLane?: boolean; zoom?: string; marks?: boolean; rail?: boolean }
177
+ const p = JSON.parse(kept.get(`${this.prefix}prefs`) ?? '{}') as { hideHandled?: boolean; byLane?: boolean; zoom?: string; marks?: boolean; rail?: boolean; tileH?: number; tileSmall?: boolean }
168
178
  if (p.hideHandled === false) this.hideHandled = false
169
179
  if (p.byLane === true) this.byLane = true
170
180
  if (p.marks === false) this.marksOn = false
171
181
  if (p.rail === false) this.railOn = false
172
182
  if ((ZOOMS as readonly string[]).includes(p.zoom ?? '')) this.zoom = p.zoom as Zoom
183
+ if (typeof p.tileH === 'number') this.setTileH(p.tileH)
184
+ if (p.tileSmall === true) this.tileSmall = true
173
185
  } catch {
174
186
  // a broken pref is the default
175
187
  }
@@ -193,7 +205,7 @@ export class ReviewSt {
193
205
  boardRows: observableRef,
194
206
  })
195
207
  reaction(
196
- () => JSON.stringify({ hideHandled: this.hideHandled, byLane: this.byLane, zoom: this.zoom, marks: this.marksOn, rail: this.railOn }),
208
+ () => JSON.stringify({ hideHandled: this.hideHandled, byLane: this.byLane, zoom: this.zoom, marks: this.marksOn, rail: this.railOn, tileH: this.tileH, tileSmall: this.tileSmall }),
197
209
  (s) => kept.put(`${this.prefix}prefs`, s),
198
210
  )
199
211
  // the card the address names, else the list's first: a new one is a new thread state, the old one disposed
@@ -472,6 +484,14 @@ export class ReviewSt {
472
484
  this.zoom = z
473
485
  }
474
486
 
487
+ toggleTileSmall(): void {
488
+ this.tileSmall = !this.tileSmall
489
+ }
490
+
491
+ setTileH(h: number): void {
492
+ this.tileH = Math.max(TILE_H.min, Math.min(TILE_H.max, Math.round(h)))
493
+ }
494
+
475
495
  toggleMarks(): void {
476
496
  this.marksOn = !this.marksOn
477
497
  }
@@ -521,6 +541,23 @@ export class ReviewSt {
521
541
  }
522
542
  }
523
543
 
544
+ /** one of a card's files published in the Space, its permanent cdn url to the clipboard: anyone with it downloads */
545
+ async share(id: string, file: string): Promise<void> {
546
+ const k = `${id}/${file}`
547
+ const known = this.shared.get(k)
548
+ if (known === 'sending') return
549
+ if (known) return this.copied(known, `link copied: ${known}`)
550
+ this.shared.set(k, 'sending')
551
+ try {
552
+ const r = await postJson<{ url: string }>(this.st.url(`/api/review/${id}/share`), { file })
553
+ runInAction(() => this.shared.set(k, r.url))
554
+ await this.copied(r.url, `link copied: ${r.url}`)
555
+ } catch (e) {
556
+ runInAction(() => this.shared.delete(k))
557
+ this.say(`not shared: ${(e as Error).message}`)
558
+ }
559
+ }
560
+
524
561
  /** the open card as one paste a fresh agent session in any repo acts on: what it is, its repo, the command that shows
525
562
  * it whole, its link here and on the phone (C) */
526
563
  async copyCard(): Promise<void> {