rvlib-shipkit 2.16.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.
- package/CHANGELOG.md +11 -0
- package/package.json +1 -1
- package/src/assets/kit-config.ts +19 -1
- package/src/assets/run-assets.ts +18 -0
- package/src/cli/cmd_Review.ts +22 -7
- package/src/cli/cmd_Secret.ts +127 -0
- package/src/cli/cmd_Wiki.ts +4 -4
- package/src/cli/family-pages.ts +1 -0
- package/src/cli/registry.ts +4 -0
- package/src/core/scope.ts +42 -0
- package/src/repo-config.ts +3 -0
- package/src/review/auto.ts +7 -2
- package/src/review/cells.ts +1 -1
- package/src/review/format.ts +2 -2
- package/src/review/model.ts +46 -13
- package/src/review/previews.ts +1 -1
- package/src/review/routes.ts +11 -0
- package/src/review/store.ts +18 -10
- package/src/secrets/list.ts +40 -0
- package/src/serve/hub-app/review/review-kit.ts +4 -0
- package/src/serve/hub-app/review/review-st.ts +40 -3
- package/src/serve/hub-app/review/review-views.tsx +145 -64
- package/src/serve/hub-app/review/thread-st.ts +76 -16
- package/src/serve/hub-app/review.css +17 -2
- package/src/shipkit.ts +1 -1
- package/src/wiki/run-wiki.ts +13 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## 2.17.0
|
|
2
|
+
|
|
3
|
+
- **`sk secret` lists the secrets of the repo you stand in.** `sk secret list` reads the house's creds and the repo's own, keeps the ones whose new `for` scope (`{ repos, identities }`, absent for every repo) names this repo, by its config name or its folder, or the identity it speaks as, and marks each `ok` or `MISS` through `credsReadCommand`, never printing a value; `--all` keeps the rest, marked `out`. `sk secret get|account <name>` and `sk secret set <name> [account]` go through the same `credsReadCommand` and `credsCommand` templates. A list, not an access control.
|
|
4
|
+
- **A review card can be a gallery rated tile by tile.** `sk review add --gallery "<label>" <name>=a.png …` draws one tile an image at one size for the whole card; a tile carries its before (`<name>=old.png,new.png`), variants draw as rows (`<asset>/<variant>=a.png`), a filter narrows the tiles, and a spot can be circled on any tile.
|
|
5
|
+
- **A card's downloads copy a public link.** Each file gets a « copy link » button that keeps it in the media store's public folder by its content and copies the URL.
|
|
6
|
+
- **A clip pair never decodes as an image.** The pixel diff mode applies to image pairs only; a clip pair draws side by side, where WebKit used to stall decoding an mp4 as an image.
|
|
7
|
+
- **`sk wiki lint` and `sk wiki serve` with no `--root` take the repo's wiki** (`wiki/`, else the agent folder, else the cwd), so refs written relative to the wiki folder resolve.
|
|
8
|
+
- **A `brand.ts` that throws blocks the identity outputs, never the hub.**
|
|
9
|
+
- **`svg(file)` makes a hand drawn svg file an asset or identity mark.** `mark: svg(new URL('./mark.svg', import.meta.url))` renders the file as a vector, fitted and centred, never stretched, with no box and no canvas copy of the shape; a relative path fails at declaration and a missing file fails at render, each naming the fix.
|
|
10
|
+
- **A review auto rule never writes into a repo that moved away.** After a rename, the old hub's timer raised a card into the old path and recreated its folder; a run now refuses when the store's repo folder is gone, and its timer stops.
|
|
11
|
+
|
|
1
12
|
## 2.16.0
|
|
2
13
|
|
|
3
14
|
- **A drill runs cold in a sealed copy.** `sk drill clone <task folder>` makes a copy of the repo with no way back to it and prints the headless command that runs it, `sk drill finish <copy>` records the run (patch, report, leaks, done command) and trashes the copy, `sk drill calibrate` proves the card's done command fails on the base and passes on the reference, and `sk drill compare` says keep or revert, never keeping an unjudged or worse run.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rvlib-shipkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.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",
|
package/src/assets/kit-config.ts
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// everything else. STRUCTURE lives here (git-reviewed TS); studio-edited
|
|
4
4
|
// state lives in the workspace overlays (pick.json, prompt.json, *.rect.json).
|
|
5
5
|
// Kit edits need a studio restart; prompt tweaks don't (overlay).
|
|
6
|
+
import type { SKRSContext2D } from '@napi-rs/canvas'
|
|
6
7
|
import { existsSync } from 'fs'
|
|
7
|
-
import { join } from 'path'
|
|
8
|
+
import { isAbsolute, join } from 'path'
|
|
9
|
+
import { fileURLToPath } from 'url'
|
|
8
10
|
import type { alphaHeight, toPng } from './image-ops.ts'
|
|
9
11
|
import type { GroundRect } from './panels/geometry-rects.ts'
|
|
10
12
|
|
|
@@ -34,6 +36,22 @@ export type GeminiGen = { backend: 'gemini'; model?: 'flash' | 'pro' }
|
|
|
34
36
|
export type GeneratorSpec = ComfyGen | CanvasGen | ManualGen | GeminiGen
|
|
35
37
|
export const comfy = (p?: { workflow?: string; vars?: Record<string, unknown> }): ComfyGen => ({ backend: 'comfy', workflow: p?.workflow, vars: p?.vars })
|
|
36
38
|
export const canvas = (draw: CanvasGen['draw']): CanvasGen => ({ backend: 'canvas', draw })
|
|
39
|
+
/** a hand-drawn svg file as a canvas kind: vector, fitted and centred in the target, never stretched.
|
|
40
|
+
* `svg(new URL('./icon.svg', import.meta.url))` resolves beside the kit file, never against the cwd */
|
|
41
|
+
export const svg = (file: URL | string): CanvasGen => {
|
|
42
|
+
const path = file instanceof URL ? fileURLToPath(file) : file
|
|
43
|
+
if (!isAbsolute(path)) throw new Error(`svg('${path}'): give an absolute path or new URL('./<file>.svg', import.meta.url)`)
|
|
44
|
+
return canvas(async (ctx) => {
|
|
45
|
+
if (!existsSync(path)) throw new Error(`svg mark: ${path} not found`)
|
|
46
|
+
const { loadImage } = await import('@napi-rs/canvas')
|
|
47
|
+
const c = ctx as SKRSContext2D
|
|
48
|
+
const img = await loadImage(path)
|
|
49
|
+
const k = Math.min(c.canvas.width / img.width, c.canvas.height / img.height)
|
|
50
|
+
const w = img.width * k
|
|
51
|
+
const h = img.height * k
|
|
52
|
+
c.drawImage(img, (c.canvas.width - w) / 2, (c.canvas.height - h) / 2, w, h)
|
|
53
|
+
})
|
|
54
|
+
}
|
|
37
55
|
export const manual = (): ManualGen => ({ backend: 'manual' })
|
|
38
56
|
export const gemini = (p?: { model?: 'flash' | 'pro' }): GeminiGen => ({ backend: 'gemini', model: p?.model })
|
|
39
57
|
|
package/src/assets/run-assets.ts
CHANGED
|
@@ -140,7 +140,25 @@ export async function identityLogo(root: string): Promise<string | null> {
|
|
|
140
140
|
return existsSync(join(root, file)) ? file : null
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/** the repo's own brand.ts threw (an import, a draw): its identity is
|
|
144
|
+
* blocked, never a fault of the hub that listed it */
|
|
143
145
|
export async function renderIdentityNow(root: string): Promise<IdentityRender> {
|
|
146
|
+
try {
|
|
147
|
+
return await renderBrand(root)
|
|
148
|
+
} catch (e) {
|
|
149
|
+
return { blocked: `.shipkit/identity/brand.ts failed: ${brandFault(e)}` }
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** @napi-rs/canvas loadImage takes a path it cannot find for a remote url,
|
|
154
|
+
* so a deleted image reads as 'Invalid URL' */
|
|
155
|
+
const brandFault = (e: unknown): string => {
|
|
156
|
+
const err = e as { code?: string; input?: string; message?: string }
|
|
157
|
+
if (err.code === 'ERR_INVALID_URL' && typeof err.input === 'string' && !/^[a-z]+:/i.test(err.input)) return `an image it loads is missing: ${err.input}`
|
|
158
|
+
return err.message ?? String(e)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function renderBrand(root: string): Promise<IdentityRender> {
|
|
144
162
|
const brand = await loadBrand(root)
|
|
145
163
|
if (brand == null) return { blocked: 'no .shipkit/identity/brand.ts — create one exporting a Brand (name, palette, mark)' }
|
|
146
164
|
if (typeof brand === 'string') return { blocked: brand }
|
package/src/cli/cmd_Review.ts
CHANGED
|
@@ -74,17 +74,29 @@ async function pull(h: Here): Promise<void> {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/** a gallery tile as given: `<label>=<file>`, or a file labelled by its name */
|
|
77
|
-
|
|
77
|
+
/** one tile of `--gallery`: `[<row>/]<label>=[<before>,]<after>`, or a bare file named by its own name */
|
|
78
|
+
export function tileOf(arg: string): { file: string; label: string; before?: string; group?: string } {
|
|
78
79
|
const eq = arg.lastIndexOf('=')
|
|
79
|
-
if (eq
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
if (eq <= 0) {
|
|
81
|
+
const name = arg.split('/').pop() ?? arg
|
|
82
|
+
return { file: arg, label: name.replace(/\.[a-z0-9]+$/i, '') }
|
|
83
|
+
}
|
|
84
|
+
const name = arg.slice(0, eq)
|
|
85
|
+
const files = arg.slice(eq + 1).split(',')
|
|
86
|
+
if (files.length > 2 || files.some((f) => f === '')) throw new Error(`--gallery tile ${arg}: <label>=<after.png>, or <label>=<before.png>,<after.png>`)
|
|
87
|
+
const slash = name.indexOf('/')
|
|
88
|
+
return {
|
|
89
|
+
label: slash > 0 ? name.slice(slash + 1) : name,
|
|
90
|
+
file: files.at(-1) ?? '',
|
|
91
|
+
...(files.length === 2 ? { before: files[0] } : {}),
|
|
92
|
+
...(slash > 0 ? { group: name.slice(0, slash) } : {}),
|
|
93
|
+
}
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
type ViewInput = import('../review/store.ts').ViewInput
|
|
85
97
|
|
|
86
98
|
/** `--view "<label>" a.png [b.png] [--note "<text>"]` and `--gallery "<label>" a.png b.png …` out of the args */
|
|
87
|
-
function takeViews(args: readonly string[]): { views: ViewInput[]; rest: string[] } {
|
|
99
|
+
export function takeViews(args: readonly string[]): { views: ViewInput[]; rest: string[] } {
|
|
88
100
|
const views: ViewInput[] = []
|
|
89
101
|
const rest: string[] = []
|
|
90
102
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -96,7 +108,9 @@ function takeViews(args: readonly string[]): { views: ViewInput[]; rest: string[
|
|
|
96
108
|
const label = args[i + 1]
|
|
97
109
|
const files: string[] = []
|
|
98
110
|
for (let j = i + 2; j < args.length && (a === '--gallery' || files.length < 2) && !(args[j] ?? '').startsWith('--'); j++) files.push(args[j] ?? '')
|
|
99
|
-
|
|
111
|
+
// a label that names a media file is a forgotten label: the first image would silently become it
|
|
112
|
+
const fileLike = label !== undefined && /\.(png|jpe?g|webp|gif|mp4|webm|wav|mp3|flac|ogg|opus|m4a)$/i.test(label)
|
|
113
|
+
if (label === undefined || label.startsWith('--') || fileLike || files.length === 0) throw new Error(a === '--gallery' ? '--gallery "<label>" a.png b.png …: a label, then its images' : '--view "<label>" a.png [b.png]: a label, then an image or a before and an after')
|
|
100
114
|
if (a === '--gallery') views.push({ label, gallery: files.map(tileOf) })
|
|
101
115
|
else views.push(files.length === 1 ? { label, image: files[0] } : { label, before: files[0], after: files[1] })
|
|
102
116
|
i += 1 + files.length
|
|
@@ -148,7 +162,7 @@ const ADD_FLAGS = `flags:
|
|
|
148
162
|
--label "<label>" the first view's label
|
|
149
163
|
--view "<label>" <a.png> [<b.png>] another view of the same subject (repeat it); --note "<text>" right after it: a line on that view
|
|
150
164
|
--choice every view is an option he scores and picks one of (two --view or more)
|
|
151
|
-
--gallery "<label>" <a.png> … a grid
|
|
165
|
+
--gallery "<label>" <a.png> … a grid he rates tile by tile (stars, OK, fix or no, a word), alone or beside other views; a tile is "[<row>/]<label>=[<before>,]<after>": a redraw carries its before, a row holds one asset's variants
|
|
152
166
|
--topic <topic> what part of the project it is about (sk review topics)
|
|
153
167
|
--subject <kind> what is judged (default shot; the repo's unit names its kinds)
|
|
154
168
|
--commit <sha> the commit it shows
|
|
@@ -182,6 +196,7 @@ export class ReviewAddCommand extends Command {
|
|
|
182
196
|
['a before and after', 'sk review add --title "lamps lit" --what "..." --before a.png --after b.png'],
|
|
183
197
|
['a second version after his answer', 'sk review add --title "lamps lit" --what "..." --image c.png --supersedes <id>'],
|
|
184
198
|
['a pick among three voices', 'sk review add --choice --title "the narrator" --what "..." --view "voice 0" a.flac --note "low, breathy" --view "voice 1" b.flac --view "voice 2" c.flac'],
|
|
199
|
+
['icons he rates one by one', 'sk review add --title "buff icons" --what "..." --gallery "icons" vitality=a.png haste=b.png greed=c.png'],
|
|
185
200
|
],
|
|
186
201
|
})
|
|
187
202
|
args = Option.Proxy()
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// shipkit secret — the secrets of the repo you stand in, and the reads and
|
|
2
|
+
// writes through the house's secret manager (`credsReadCommand`, `credsCommand`).
|
|
3
|
+
// Logic in secrets/list.ts. A value only ever goes to stdout of `get`/`account`.
|
|
4
|
+
import { Command, Option } from 'clipanion'
|
|
5
|
+
import { existsSync } from 'fs'
|
|
6
|
+
import { basename, join } from 'path'
|
|
7
|
+
import { gitRoot } from '../core/git-root.ts'
|
|
8
|
+
import { houseRootOf } from '../home/home-start.ts'
|
|
9
|
+
import { loadIdentities, speakerOf } from '../identities/identities.ts'
|
|
10
|
+
import { loadRepoConfig, type RepoConfig } from '../repo-config.ts'
|
|
11
|
+
import { presence, secretsFor } from '../secrets/list.ts'
|
|
12
|
+
import { secretArgv } from '../smoke/run-smoke.ts'
|
|
13
|
+
|
|
14
|
+
type Where = { repos: string[]; identity: string | null; own: RepoConfig | null; house: RepoConfig | null }
|
|
15
|
+
|
|
16
|
+
async function where(cwd: string): Promise<Where> {
|
|
17
|
+
const root = gitRoot(cwd)?.top ?? cwd
|
|
18
|
+
const own = existsSync(join(root, 'repo.config.ts')) ? await loadRepoConfig(root) : null
|
|
19
|
+
const houseRoot = houseRootOf(cwd)
|
|
20
|
+
const house = houseRoot == null ? null : houseRoot === root ? own : await loadRepoConfig(houseRoot).catch(() => null)
|
|
21
|
+
const identity = speakerOf(own?.speaksAs, await loadIdentities({ cwd }))?.id ?? null
|
|
22
|
+
return { repos: [...new Set([own?.name ?? basename(root), basename(root)])], identity, own, house }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** a refusal the command prints as one line and exits 1 on, never a stack */
|
|
26
|
+
class Refused extends Error {}
|
|
27
|
+
|
|
28
|
+
const template = (w: Where, key: 'credsReadCommand' | 'credsCommand'): string => {
|
|
29
|
+
const t = w.own?.[key] ?? w.house?.[key]
|
|
30
|
+
if (w.own == null && w.house == null) throw new Refused('FAIL not inside a house repo: run it from a repo that loads the house wiki')
|
|
31
|
+
if (t == null || t.trim() === '') throw new Refused(`FAIL no ${key} in this repo's repo.config.ts nor the house's: nothing knows how to reach the secret manager`)
|
|
32
|
+
return t
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** runs a verb, printing a refusal as its one line */
|
|
36
|
+
async function refusing(stderr: NodeJS.WritableStream, run: () => Promise<number>): Promise<number> {
|
|
37
|
+
try {
|
|
38
|
+
return await run()
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (!(e instanceof Refused)) throw e
|
|
41
|
+
stderr.write(`${e.message}\n`)
|
|
42
|
+
return 1
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class SecretListCommand extends Command {
|
|
47
|
+
static override paths = [['secret', 'list'], ['secret']]
|
|
48
|
+
|
|
49
|
+
static override usage = Command.Usage({
|
|
50
|
+
category: 'Secrets',
|
|
51
|
+
description: "the secrets for this repo: its own, its identity's, then those for every repo",
|
|
52
|
+
examples: [
|
|
53
|
+
['the secrets for this repo, and which are missing', 'sk secret list'],
|
|
54
|
+
['every row of the registry, with its scope', 'sk secret list --all'],
|
|
55
|
+
],
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
all = Option.Boolean('--all', false, { description: 'every registry row, the ones out of scope marked' })
|
|
59
|
+
json = Option.Boolean('--json', false, { description: 'one json array, no presence read' })
|
|
60
|
+
|
|
61
|
+
async execute(): Promise<number> {
|
|
62
|
+
return refusing(this.context.stderr, () => this.list())
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async list(): Promise<number> {
|
|
66
|
+
const w = await where(process.cwd())
|
|
67
|
+
// in the house repo its own creds ARE the registry, each row with the scope it declares
|
|
68
|
+
const inHouse = w.house != null && w.house === w.own
|
|
69
|
+
const rows = secretsFor({ asker: w, own: inHouse ? [] : (w.own?.creds ?? []), house: w.house?.creds ?? [], all: this.all })
|
|
70
|
+
if (this.json) {
|
|
71
|
+
this.context.stdout.write(`${JSON.stringify(rows)}\n`)
|
|
72
|
+
return 0
|
|
73
|
+
}
|
|
74
|
+
const has = await presence(template(w, 'credsReadCommand'), rows.filter((r) => r.inScope).map((r) => r.name))
|
|
75
|
+
const say = (l: string): void => void this.context.stdout.write(`${l}\n`)
|
|
76
|
+
const mine = rows.filter((r) => r.mine).length
|
|
77
|
+
say(`${w.repos[0]} speaks as ${w.identity ?? 'no identity'}: ${rows.filter((r) => r.inScope).length} secrets, ${mine} for this repo or identity`)
|
|
78
|
+
const pad = (k: 'name' | 'for'): number => Math.max(...rows.map((r) => r[k].length))
|
|
79
|
+
for (const r of rows) {
|
|
80
|
+
const p = has.get(r.name)
|
|
81
|
+
const mark = !r.inScope ? 'out ' : p === true ? 'ok ' : 'MISS'
|
|
82
|
+
const fix = p === false ? ` → sk secret set ${r.name}` : ''
|
|
83
|
+
say(`${mark} ${r.name.padEnd(pad('name'))} ${r.level.padEnd(5)} ${r.for.padEnd(pad('for'))} ${(r.service ?? '').slice(0, 40)}${fix}`)
|
|
84
|
+
}
|
|
85
|
+
return 0
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export class SecretReadCommand extends Command {
|
|
90
|
+
static override paths = [['secret', 'get'], ['secret', 'account']]
|
|
91
|
+
|
|
92
|
+
static override usage = Command.Usage({
|
|
93
|
+
category: 'Secrets',
|
|
94
|
+
description: 'print a secret (get) or the account stored with it (account), through the house secret manager',
|
|
95
|
+
examples: [['a token', 'sk secret get rv/cloudflare/api-token'], ['the login stored with it', 'sk secret account rv/pockethost/account']],
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
name = Option.String()
|
|
99
|
+
|
|
100
|
+
async execute(): Promise<number> {
|
|
101
|
+
const field = this.path[1] === 'account' ? 'account' : 'get'
|
|
102
|
+
return refusing(this.context.stderr, async () => {
|
|
103
|
+
const argv = secretArgv(template(await where(process.cwd()), 'credsReadCommand'), this.name, field)
|
|
104
|
+
return Bun.spawnSync(argv, { stdout: 'inherit', stderr: 'inherit' }).exitCode ?? 1
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export class SecretSetCommand extends Command {
|
|
110
|
+
static override paths = [['secret', 'set']]
|
|
111
|
+
|
|
112
|
+
static override usage = Command.Usage({
|
|
113
|
+
category: 'Secrets',
|
|
114
|
+
description: 'store a secret and its account through the house secret manager: it prompts, or reads stdin',
|
|
115
|
+
examples: [['store a token', 'sk secret set rv/npm/token'], ['with its login', 'sk secret set rv/pockethost/account me@example.com']],
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
name = Option.String()
|
|
119
|
+
account = Option.String({ required: false })
|
|
120
|
+
|
|
121
|
+
async execute(): Promise<number> {
|
|
122
|
+
return refusing(this.context.stderr, async () => {
|
|
123
|
+
const argv = [...template(await where(process.cwd()), 'credsCommand').trim().split(/\s+/).map((x) => x.replaceAll('{name}', this.name)), ...(this.account != null ? [this.account] : [])]
|
|
124
|
+
return Bun.spawnSync(argv, { stdin: 'inherit', stdout: 'inherit', stderr: 'inherit' }).exitCode ?? 1
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
}
|
package/src/cli/cmd_Wiki.ts
CHANGED
|
@@ -10,12 +10,12 @@ export class WikiServeCommand extends Command {
|
|
|
10
10
|
category: 'Wiki',
|
|
11
11
|
description: 'live md link-graph server — reload = rescan',
|
|
12
12
|
examples: [
|
|
13
|
-
['serve the
|
|
13
|
+
['serve the repo wiki', 'sk wiki serve'],
|
|
14
14
|
['serve a subtree on a port', 'sk wiki serve --root agent --index process.md --port 6162'],
|
|
15
15
|
],
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
root = Option.String('--root',
|
|
18
|
+
root = Option.String('--root', { required: false, description: 'wiki root directory (default: wiki/, else the agent folder, else the cwd)' })
|
|
19
19
|
port = Option.String('--port', '6161', { description: 'server port' })
|
|
20
20
|
title = Option.String('--title', { required: false, description: 'page title shown in the graph header' })
|
|
21
21
|
index = Option.String('--index', { required: false, description: 'entrypoint page (default: index.md AND README.md)' })
|
|
@@ -38,12 +38,12 @@ export class WikiLintCommand extends Command {
|
|
|
38
38
|
category: 'Wiki',
|
|
39
39
|
description: 'fail on orphan pages and dangling refs (exit 1)',
|
|
40
40
|
examples: [
|
|
41
|
-
['lint the
|
|
41
|
+
['lint the repo wiki', 'sk wiki lint'],
|
|
42
42
|
['lint a subtree', 'sk wiki lint --root agent --index process.md'],
|
|
43
43
|
],
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
root = Option.String('--root',
|
|
46
|
+
root = Option.String('--root', { required: false, description: 'wiki root directory (default: wiki/, else the agent folder, else the cwd)' })
|
|
47
47
|
index = Option.String('--index', { required: false, description: 'entrypoint page (default: index.md AND README.md)' })
|
|
48
48
|
skip = Option.String('--skip', { required: false, description: 'comma-separated dir names to exclude from the scan' })
|
|
49
49
|
|
package/src/cli/family-pages.ts
CHANGED
|
@@ -15,6 +15,7 @@ export const FAMILY_PAGES: Readonly<Record<string, string>> = {
|
|
|
15
15
|
Refactor: 'patterns/typescript/index.md',
|
|
16
16
|
Review: 'tools/shipkit/review.md',
|
|
17
17
|
Scaffold: 'patterns/pocketbase/index.md',
|
|
18
|
+
Secrets: 'services/secrets/index.md',
|
|
18
19
|
Serve: 'tools/shipkit/home.md',
|
|
19
20
|
Setup: 'patterns/rv-conventions/index.md',
|
|
20
21
|
Social: 'tools/shipkit/social.md',
|
package/src/cli/registry.ts
CHANGED
|
@@ -51,6 +51,7 @@ import { MEDIA_COMMANDS } from './cmd_Media.ts'
|
|
|
51
51
|
import { BACKUP_COMMANDS } from './cmd_Backup.ts'
|
|
52
52
|
import { VEILLE_COMMANDS } from './cmd_Veille.ts'
|
|
53
53
|
import { TuiCommand } from './cmd_Tui.ts'
|
|
54
|
+
import { SecretListCommand, SecretReadCommand, SecretSetCommand } from './cmd_Secret.ts'
|
|
54
55
|
import { WikiLintCommand, WikiServeCommand } from './cmd_Wiki.ts'
|
|
55
56
|
|
|
56
57
|
|
|
@@ -108,6 +109,9 @@ export function buildCli(): Cli {
|
|
|
108
109
|
cli.register(AskNewCommand)
|
|
109
110
|
cli.register(WikiServeCommand)
|
|
110
111
|
cli.register(WikiLintCommand)
|
|
112
|
+
cli.register(SecretListCommand)
|
|
113
|
+
cli.register(SecretReadCommand)
|
|
114
|
+
cli.register(SecretSetCommand)
|
|
111
115
|
cli.register(AssetsFillCommand)
|
|
112
116
|
cli.register(AssetsAddCommand)
|
|
113
117
|
cli.register(AssetsGenCommand)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// who a house resource is for: some repos, some identities, or every repo.
|
|
2
|
+
// One type and one reader, so a secret and anything scoped later answer alike.
|
|
3
|
+
// The md form, one cell: `all`, or `repo:<name>` and `identity:<id>` joined by commas.
|
|
4
|
+
|
|
5
|
+
/** absent or empty = every repo */
|
|
6
|
+
export type Scope = {
|
|
7
|
+
/** repo names, as `repo.config.ts` names them or as their folder is called */
|
|
8
|
+
repos?: string[]
|
|
9
|
+
/** identity ids, as `speaksAs` names them */
|
|
10
|
+
identities?: string[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** the repo asking: every name it answers to (its config name, its folder), and the identity it speaks as */
|
|
14
|
+
export type Asker = { repos: string[]; identity: string | null }
|
|
15
|
+
|
|
16
|
+
const listed = (xs: string[] | undefined): boolean => (xs ?? []).length > 0
|
|
17
|
+
|
|
18
|
+
export const scopesAll = (s: Scope | undefined): boolean => s == null || (!listed(s.repos) && !listed(s.identities))
|
|
19
|
+
|
|
20
|
+
/** in scope when the scope is for all, names the repo, or names its identity */
|
|
21
|
+
export function inScope(s: Scope | undefined, a: Asker): boolean {
|
|
22
|
+
if (scopesAll(s)) return true
|
|
23
|
+
return (s!.repos ?? []).some((r) => a.repos.includes(r)) || (a.identity != null && (s!.identities ?? []).includes(a.identity))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** the md cell as a scope; throws on a token that is neither `all`, `repo:` nor `identity:` */
|
|
27
|
+
export function parseScope(cell: string): Scope {
|
|
28
|
+
const text = cell.replaceAll('`', '').trim()
|
|
29
|
+
if (text === '' || text === 'all') return {}
|
|
30
|
+
const s: Scope = {}
|
|
31
|
+
for (const raw of text.split(',')) {
|
|
32
|
+
const t = raw.trim()
|
|
33
|
+
const m = /^(repo|identity):([a-z0-9][a-z0-9._-]*)$/.exec(t)
|
|
34
|
+
if (m == null) throw new Error(`scope "${cell}": "${t}" is not repo:<name> or identity:<id> (or all)`)
|
|
35
|
+
const key = m[1] === 'repo' ? 'repos' : 'identities'
|
|
36
|
+
;(s[key] ??= []).push(m[2]!)
|
|
37
|
+
}
|
|
38
|
+
return s
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const scopeText = (s: Scope | undefined): string =>
|
|
42
|
+
scopesAll(s) ? 'all' : [...(s!.repos ?? []).map((r) => `repo:${r}`), ...(s!.identities ?? []).map((i) => `identity:${i}`)].join(', ')
|
package/src/repo-config.ts
CHANGED
|
@@ -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'
|
|
@@ -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
|
package/src/review/auto.ts
CHANGED
|
@@ -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)
|
package/src/review/cells.ts
CHANGED
|
@@ -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),
|
package/src/review/format.ts
CHANGED
|
@@ -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(' | ')}` : ''}`
|
package/src/review/model.ts
CHANGED
|
@@ -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
|
|
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
|
-
/**
|
|
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.
|
|
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
|
|
261
|
-
export const firstView = (i: Item):
|
|
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
|
|
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 ? '
|
|
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(...
|
|
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
|
-
|
|
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
|
-
|
|
961
|
-
|
|
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
|
|
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
|
}
|