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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
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
+
12
+ ## 2.16.0
13
+
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.
15
+ - **`sk media put --public` publishes a file anyone downloads.** It goes up under `public/<label>/<sha256>.<ext>` with a public-read ACL and prints a permanent URL on the CDN edge; nobody lists the bucket, and every object outside `public/` stays private, its ACL decided by its key alone. A public file is never purged from the disk, `public` is no label for a plain put, and `--public --link` is refused. A put of many files sends 8 at a time and still prints them in the order named.
16
+ - **A shipkit suite run without its preload is refused the machine's real home.** Run from another folder, the suite skipped its temp home and a test that deletes the media index deleted the real one; `homeDir()` now throws under the suite unless a home is set, the fix named.
17
+ - **SK038: a repo names the identity it speaks as.** On a machine with identities, `repo.config.ts` without `speaksAs`, or with an id the machine does not hold, fails, and the message lists the ids to pick from. A repo that names none no longer falls to the default identity silently. With no identities on the machine it passes.
18
+ - **`sk identities` says why a repo list is empty.** Archived repos show apart (`archived: …`), a repo naming no `speaksAs` is a FAIL line that exits 1, and run outside a folder of house repos it notes that none can be seen from there. `--json` adds `archived`, `unnamed` and `seen`.
19
+
1
20
  ## 2.15.0
2
21
 
3
22
  - **`sk drill clean <run folder>`** moves a recorded drill run folder to the trash, never deletes it, and refuses a folder that is not a drill copy: a git repo of its own, one commit named « drill base », no remote. `--dry-run` says what would move.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rvlib-shipkit",
3
- "version": "2.15.0",
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",
@@ -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
 
@@ -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 }
@@ -0,0 +1,66 @@
1
+ // SK038 speaks as: on a machine with identities (a house), every repo names the identity it
2
+ // speaks as, `speaksAs` in repo.config.ts, and that identity exists. A repo that names none
3
+ // would speak as the default one, a choice nobody made, so it fails instead. Outside a house,
4
+ // or with a house that holds none (a stranger, a CI box), there is nothing to name, and it
5
+ // passes; an identities folder named by SHIPKIT_IDENTITIES_DIR that is missing fails.
6
+ import { existsSync, readdirSync } from 'fs'
7
+ import { join } from 'path'
8
+ import { check } from '../check.ts'
9
+ import { CONFIG_FILE } from '../core/identity.ts'
10
+ import { LAYOUT } from '../core/layout.ts'
11
+ import { houseRootOf } from '../home/home-start.ts'
12
+ import { speaksAsOfText } from '../social/house.ts'
13
+
14
+ const FIX = "add `speaksAs: '<id>'` to defineRepo in repo.config.ts, an id `sk identities` lists"
15
+
16
+ export type MachineIds = { ids: string[] } | { none: string } | { broken: string }
17
+
18
+ /** the identity ids of this machine's house, sorted, or why there are none, or a named folder that is missing */
19
+ export function machineIdentityIds(root: string): MachineIds {
20
+ const env = process.env['SHIPKIT_IDENTITIES_DIR']
21
+ if (env != null && env !== '' && !existsSync(env)) return { broken: `SHIPKIT_IDENTITIES_DIR names ${env}, which does not exist` }
22
+ const house = env ? null : houseRootOf(root)
23
+ if (!env && house == null) return { none: 'not a house repo: no identities to name' }
24
+ const dir = env || join(house!, LAYOUT.identities)
25
+ const ids = existsSync(dir)
26
+ ? readdirSync(dir, { withFileTypes: true })
27
+ .filter((e) => e.isDirectory() && existsSync(join(dir, e.name, 'identity.md')))
28
+ .map((e) => e.name)
29
+ .sort()
30
+ : []
31
+ return ids.length === 0 ? { none: 'the house holds no identity' } : { ids }
32
+ }
33
+
34
+ /** what is wrong with a config's speaksAs against the machine's ids, null when it is fine */
35
+ export function speaksAsProblem(configText: string, ids: string[]): string | null {
36
+ const id = speaksAsOfText(configText)
37
+ if (id == null) return `${CONFIG_FILE} names no speaksAs: every repo on this machine says which identity it speaks as (${ids.join(', ')})`
38
+ if (!ids.includes(id)) return `${CONFIG_FILE}: speaksAs '${id}' is no identity of this machine (${ids.join(', ')})`
39
+ return null
40
+ }
41
+
42
+ export const speaksAs = check({
43
+ id: 'SK038',
44
+ blocking: true,
45
+ title: 'speaks as',
46
+ description: 'repo.config.ts names the identity the repo speaks as, one this machine holds',
47
+ owner: 'tools/shipkit/social-identities.md',
48
+ runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
49
+ // the config, and which identities this machine holds
50
+ cache: { by: 'files', inputs: [CONFIG_FILE], key: (env) => JSON.stringify(machineIdentityIds(env.root)) },
51
+ fix: 'none',
52
+ applies: 'always',
53
+ run: (c) => {
54
+ const m = machineIdentityIds(c.root)
55
+ if ('broken' in m) return c.fail(m.broken, 'point it at the identities folder, or unset it')
56
+ if ('none' in m) return c.ok(m.none)
57
+ const { ids } = m
58
+ const text = c.read(CONFIG_FILE)
59
+ if (text == null) return c.note(`no ${CONFIG_FILE}`)
60
+ const why = speaksAsProblem(text, ids)
61
+ if (why != null) return c.fail(why, FIX)
62
+ c.ok(`speaks as ${speaksAsOfText(text)}`)
63
+ },
64
+ })
65
+
66
+ export default speaksAs
@@ -1,8 +1,9 @@
1
- // `sk drill`: the records of a measured drill (wiki meta/speed-up-agents/index.md). report = one run's transcript
2
- // as run<n>.json + run<n>.md, verdict = the judged quality added to a run, compare = every run of a drill side
3
- // by side. It reads transcripts and writes files; it never starts an agent (core/agent-spawn.ts). Exit 0 with
4
- // the files written, 1 when a transcript or a run is missing or an argument does not parse, 2 on a bad verdict or --out.
5
- // clean = a run folder moved to the trash once it is recorded, refused unless it is a drill copy.
1
+ // `sk drill`: a measured drill (wiki meta/speed-up-agents/index.md). clone = a sealed copy for one run and the
2
+ // command that runs it cold, finish = that run recorded (patch, report, done cmd) and its copy trashed, calibrate =
3
+ // the card's done cmd proven on the base and the reference, report = one transcript as run<n>.json + run<n>.md,
4
+ // verdict = the judged quality added to a run, compare = every run side by side with the keep or revert line,
5
+ // clean = a copy moved to the trash. It never starts an agent (core/agent-spawn.ts): the session runs the printed
6
+ // command. Exit 0 when done, 1 when something is missing or a check fails, 2 on a bad argument.
6
7
  import { Command, Option } from 'clipanion'
7
8
  import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs'
8
9
  import { basename, dirname, join, resolve } from 'path'
@@ -23,6 +24,13 @@ async function findTranscript(ref: string): Promise<string | null> {
23
24
  return null
24
25
  }
25
26
 
27
+ const projectRoots = async (): Promise<string[]> => {
28
+ const { discoverConfigRoots } = await import('../reflect/prompt-corpus.ts')
29
+ return discoverConfigRoots().map((r) => r.projects)
30
+ }
31
+ const expand = (p: string): string => resolve(p.replace(/^~(?=\/)/, process.env.HOME ?? '~'))
32
+ const short = (sha: string): string => sha.slice(0, 10)
33
+
26
34
  const writeRun = async (outBase: string, run: import('../drill/run.ts').DrillRun): Promise<void> => {
27
35
  const { renderRun } = await import('../drill/render.ts')
28
36
  writeFileSync(`${outBase}.json`, JSON.stringify(run, null, 2) + '\n')
@@ -103,7 +111,8 @@ export class DrillVerdictCommand extends Command {
103
111
  err.write(`FAIL: ${v}\n`)
104
112
  return 2
105
113
  }
106
- const run = JSON.parse(readFileSync(this.run, 'utf8')) as import('../drill/run.ts').DrillRun
114
+ const { normalizeRun } = await import('../drill/run.ts')
115
+ const run = normalizeRun(JSON.parse(readFileSync(this.run, 'utf8')))
107
116
  await writeRun(resolve(this.run).replace(/\.json$/, ''), { ...run, verdict: v })
108
117
  this.context.stdout.write(`ok: ${this.run}: done ${v.done}, quality ${v.quality}, tests ${v.tests}, design ${v.design}\n`)
109
118
  return 0
@@ -114,7 +123,7 @@ export class DrillCompareCommand extends Command {
114
123
  static override paths = [['drill', 'compare']]
115
124
  static override usage = Command.Usage({
116
125
  category: 'Drill',
117
- description: 'every run of a drill side by side in compare.md: deltas, verdicts, when each md page was read',
126
+ description: 'every run of a drill side by side in compare.md: keep or revert, the gate, deltas, pages read',
118
127
  details: 'Reads the run<n>.json records of one task folder in run order and writes compare.md beside them. Flags a run whose prompt differs from the first. A ratio always reads up from 1: "1.7x more", never "0.6x fewer".',
119
128
  examples: [['one task of a speed-up drill', 'sk drill compare .shipkit/plans/20261104-speed-up/form']],
120
129
  })
@@ -137,10 +146,13 @@ export class DrillCompareCommand extends Command {
137
146
  return 1
138
147
  }
139
148
  const { renderCompare } = await import('../drill/render.ts')
140
- const runs = labels.map((label) => ({ label, run: JSON.parse(readFileSync(join(dir, `${label}.json`), 'utf8')) as import('../drill/run.ts').DrillRun }))
149
+ const { normalizeRun } = await import('../drill/run.ts')
150
+ const { groupsOf, scoreOf } = await import('../drill/score.ts')
151
+ const runs = labels.map((label) => ({ label, run: normalizeRun(JSON.parse(readFileSync(join(dir, `${label}.json`), 'utf8'))) }))
141
152
  const out = join(dir, 'compare.md')
142
153
  writeFileSync(out, renderCompare(basename(dir), runs))
143
- this.context.stdout.write(`ok: ${out}: ${runs.length} runs\n`)
154
+ const score = scoreOf(groupsOf(runs))
155
+ this.context.stdout.write(`ok: ${out}: ${runs.length} runs, ${score.verdict}: ${score.why}\n`)
144
156
  return 0
145
157
  }
146
158
  }
@@ -150,10 +162,10 @@ export class DrillCleanCommand extends Command {
150
162
  static override usage = Command.Usage({
151
163
  category: 'Drill',
152
164
  description: 'a recorded drill run folder moved to the trash, never deleted, refused unless it is a drill copy',
153
- details: 'A drill copy is a git repo of its own (no worktree) holding one commit named « drill base » and no remote. Anything else is refused with the reason, so a wrong path never moves. The folder lands in the trash under its name and the time, to put back by hand. --dry-run says what would move. Exit 0 when every folder moved, 1 when one was refused.',
165
+ details: 'A drill copy is a git repo of its own (no worktree) with no remote: a sealed copy (its record in .git/drill.json, `sk drill finish` trashes it itself), or an older copy holding one commit named « drill base ». Anything else is refused with the reason, so a wrong path never moves. The folder lands in the trash under its name and the time, to put back by hand. --dry-run says what would move. Exit 0 when every folder moved, 1 when one was refused.',
154
166
  examples: [
155
- ['one run, once its report is written', 'sk drill clean ~/drills/app--form'],
156
- ['see first', 'sk drill clean ~/drills/app--form ~/drills/app--list --dry-run'],
167
+ ['a sealed copy left by --keep', 'sk drill clean /var/folders/xx/T/app-Ab12Cd'],
168
+ ['see first', 'sk drill clean /var/folders/xx/T/app-Ab12Cd --dry-run'],
157
169
  ],
158
170
  })
159
171
  dirs = Option.Rest({ required: 1, name: 'run folder' })
@@ -172,3 +184,198 @@ export class DrillCleanCommand extends Command {
172
184
  return refused === 0 ? 0 : 1
173
185
  }
174
186
  }
187
+
188
+ export class DrillCloneCommand extends Command {
189
+ static override paths = [['drill', 'clone']]
190
+ static override usage = Command.Usage({
191
+ category: 'Drill',
192
+ description: 'a sealed copy of the repo for one cold run, and the headless command that runs it',
193
+ details: [
194
+ 'Reads the task folder\'s drill.md (its task text, its base). The copy lands in a temp folder named after the repo only, as one commit with the base\'s own message, author and date. --setup lays CLAUDE.md, AGENTS.md, agent/ and .claude/ of another sha over the base (wiki/ too when the repo is the house that hosts the wiki).',
195
+ 'Every drill folder under .shipkit/plans is removed, lines naming the drill are dropped, and the copy fails loud if a card or a run patch is left. Every file gets the commit time, deps come from a frozen install. The house repo reads its own wiki; a repo that includes the house wiki reads the live one, or a sealed copy of it with --wiki <sha>. No secret is copied.',
196
+ 'It prints the command the session runs: a headless claude in the copy, denied the web, the remote, the main repo and the transcripts. It never starts it. Then `sk drill finish <copy>`.',
197
+ ].join(' '),
198
+ examples: [
199
+ ['round 1, the card\'s base', 'sk drill clone .shipkit/plans/20261105-speed-up/deploy'],
200
+ ['round 2, the setup of the commit under test over the same base', 'sk drill clone .shipkit/plans/20261105-speed-up/deploy --setup 2be02cd3'],
201
+ ],
202
+ })
203
+ task = Option.String({ required: true, name: 'task folder' })
204
+ base = Option.String('--base', { description: 'the commit the copy holds; default: the card\'s base row' })
205
+ setup = Option.String('--setup', { description: 'the commit whose setup files the run sees; default: the base' })
206
+ wiki = Option.String('--wiki', { description: 'a house commit whose wiki the run reads instead of the live one' })
207
+ install = Option.Boolean('--install', true, { description: 'a frozen bun install in the copy (--no-install skips it)' })
208
+
209
+ async execute(): Promise<number> {
210
+ const err = this.context.stderr
211
+ const task = expand(this.task)
212
+ const { readCard } = await import('../drill/finish.ts')
213
+ const card = await readCard(task)
214
+ if (typeof card === 'string') {
215
+ err.write(`FAIL: ${card}\n`)
216
+ return 1
217
+ }
218
+ const base = this.base ?? card.base
219
+ if (base == null) {
220
+ err.write('FAIL: no base: give --base <sha>, or a `base` row in the card\n')
221
+ return 1
222
+ }
223
+ const { gitRoot } = await import('../core/git-root.ts')
224
+ const repo = gitRoot(task)?.top
225
+ if (repo == null) {
226
+ err.write(`FAIL: ${this.task} is not inside a git repo\n`)
227
+ return 1
228
+ }
229
+ const { houseRootOf } = await import('../home/home-start.ts')
230
+ const { seal, PROMPT, SETTINGS } = await import('../drill/seal.ts')
231
+ try {
232
+ const s = seal({ repo, task, base, setup: this.setup, wiki: this.wiki, house: houseRootOf(repo), prompt: card.task, install: this.install, configRoots: await projectRoots() })
233
+ const out = this.context.stdout
234
+ out.write(`ok: sealed copy ${s.dir}: base ${short(s.meta.base)}, setup ${short(s.meta.setup)}, setup key ${s.meta.setupKey}, wiki ${s.meta.wiki.mode}\n`)
235
+ for (const n of s.notes) out.write(`${n}\n`)
236
+ if ((process.env.ANTHROPIC_API_KEY ?? '') !== '') out.write('💸 ANTHROPIC_API_KEY is set: a headless run bills the API, not the plan. Unset it in the run\'s shell\n')
237
+ out.write(`run it cold, from the session, in the background (the run sees only the task text):\n (cd ${s.dir} && claude -p --permission-mode auto --permission-prompts none --settings ${SETTINGS} < ${PROMPT})\nthen: sk drill finish ${s.dir}\n`)
238
+ return 0
239
+ } catch (e) {
240
+ err.write(`FAIL: ${(e as Error).message}\n`)
241
+ return 1
242
+ }
243
+ }
244
+ }
245
+
246
+ export class DrillFinishCommand extends Command {
247
+ static override paths = [['drill', 'finish']]
248
+ static override usage = Command.Usage({
249
+ category: 'Drill',
250
+ description: 'one run recorded from its sealed copy: patch, report, leaks, done cmd, then the copy trashed',
251
+ details: [
252
+ 'Finds the one headless session started in the copy (or the sub-agent named by --agent, a smoke run never scored with cold ones), writes run<n>.patch against the copy\'s first commit, run<n>.json and run<n>.md in the task folder, then runs the card\'s done cmd in the copy and holds the patch against its forbid globs.',
253
+ 'The copy and its wiki copy go to the trash unless --keep.',
254
+ ].join(' '),
255
+ examples: [
256
+ ['after a cold run', 'sk drill finish /var/folders/xx/T/app-Ab12Cd'],
257
+ ['after a sub-agent smoke run', 'sk drill finish /var/folders/xx/T/app-Ab12Cd --agent a7e0f9cd61f44cfb4'],
258
+ ],
259
+ })
260
+ copy = Option.String({ required: true, name: 'copy' })
261
+ agent = Option.String('--agent', { description: 'the sub-agent id of a smoke run' })
262
+ keep = Option.Boolean('--keep', false, { description: 'leave the copy in place' })
263
+
264
+ async execute(): Promise<number> {
265
+ const err = this.context.stderr
266
+ const out = this.context.stdout
267
+ const copy = expand(this.copy)
268
+ const { readMeta } = await import('../drill/seal.ts')
269
+ const meta = existsSync(copy) ? readMeta(copy) : null
270
+ if (meta == null) {
271
+ err.write(`FAIL: ${this.copy} is not a sealed drill copy: no .git/drill.json (sk drill clone makes one)\n`)
272
+ return 1
273
+ }
274
+ const f = await import('../drill/finish.ts')
275
+ const card = await f.readCard(meta.task)
276
+ if (typeof card === 'string') {
277
+ err.write(`FAIL: ${card}\n`)
278
+ return 1
279
+ }
280
+ let transcript: string | null
281
+ if (this.agent != null) transcript = await findTranscript(this.agent)
282
+ else {
283
+ const found = f.coldTranscripts(copy, await projectRoots())
284
+ if (found.length > 1) {
285
+ err.write(`FAIL: ${found.length} sessions ran in the copy, one run is one session:\n${found.map((t) => ` ${t}`).join('\n')}\n`)
286
+ return 1
287
+ }
288
+ transcript = found[0] ?? null
289
+ }
290
+ if (transcript == null) {
291
+ err.write(`FAIL: no transcript: ${this.agent == null ? 'no headless session ran in the copy yet' : `no sub-agent ${this.agent}`}\n`)
292
+ return 1
293
+ }
294
+ const n = f.nextRun(meta.task)
295
+ const base = join(meta.task, `run${n}`)
296
+ const { patch, agentCommits } = f.runPatch(copy)
297
+ f.writePatch(`${base}.patch`, patch)
298
+ const { drillRun, patchStats } = await import('../drill/run.ts')
299
+ const { loadMasker } = await import('../agent-time/mask.ts')
300
+ const { forbidHits } = await import('../drill/card.ts')
301
+ const mask = loadMasker(meta.repo)
302
+ const run = drillRun(readFileSync(transcript, 'utf8').split('\n'), { transcript: transcript.replace(process.env.HOME ?? '\0', '~'), root: copy, patch, mask, private: meta.private })
303
+ const wiki = meta.wiki.mode === 'copy' ? `copy ${short(meta.wiki.sha)}` : meta.wiki.mode === 'live' ? `live ${meta.wiki.tree.slice(0, 10)}${meta.wiki.dirty ? ' dirty' : ''}` : meta.wiki.mode
304
+ const recorded = {
305
+ ...run,
306
+ mode: this.agent == null ? ('cold' as const) : ('subagent' as const),
307
+ setup: { base: meta.base, setup: meta.setup, key: meta.setupKey, wiki },
308
+ done: card.doneCmd == null ? null : f.runDone(copy, card.doneCmd, mask),
309
+ forbidHits: forbidHits(patchStats(patch).paths, card.forbid),
310
+ }
311
+ await writeRun(base, recorded)
312
+ const { gateOf } = await import('../drill/score.ts')
313
+ const gate = gateOf(recorded)
314
+ out.write(`ok: ${base}.json, .md and .patch: ${run.calls} calls, ${Math.round(run.wall / 1000)}s, gate ${gate.length === 0 ? 'passed' : `fails (${gate.join(', ')})`}\n`)
315
+ if (agentCommits > 0) out.write(`the run made ${agentCommits} commits: the patch holds them\n`)
316
+ if (this.keep) return 0
317
+ const { cleanDrillCopy, notAWikiCopy } = await import('../drill/clean.ts')
318
+ let refused = 0
319
+ for (const r of [cleanDrillCopy(copy), ...(meta.wiki.mode === 'copy' ? [cleanDrillCopy(meta.wiki.dir, { check: notAWikiCopy })] : [])]) {
320
+ if ('refused' in r) {
321
+ refused++
322
+ err.write(`REFUSE: ${r.dir} ${r.refused}: left in place\n`)
323
+ } else out.write(`moved ${r.dir} → ${r.to}\n`)
324
+ }
325
+ return refused === 0 ? 0 : 1
326
+ }
327
+ }
328
+
329
+ export class DrillCalibrateCommand extends Command {
330
+ static override paths = [['drill', 'calibrate']]
331
+ static override usage = Command.Usage({
332
+ category: 'Drill',
333
+ description: 'the card\'s done cmd proven before round 1: it fails on the base and passes on the reference',
334
+ details: 'Seals one copy at the card\'s base and one at its reference, runs the done cmd in each, and trashes both. A done cmd that passes on the base measures nothing; one that fails on the reference fails a right answer. Exit 0 when both hold, 1 otherwise with the output tail. Read the reference diff too: a done cmd that checks a name only the reference uses fails another right answer.',
335
+ examples: [['once per card', 'sk drill calibrate .shipkit/plans/20261105-speed-up/deploy']],
336
+ })
337
+ task = Option.String({ required: true, name: 'task folder' })
338
+ install = Option.Boolean('--install', true, { description: 'a frozen bun install in each copy (--no-install skips it)' })
339
+
340
+ async execute(): Promise<number> {
341
+ const err = this.context.stderr
342
+ const out = this.context.stdout
343
+ const task = expand(this.task)
344
+ const f = await import('../drill/finish.ts')
345
+ const card = await f.readCard(task)
346
+ if (typeof card === 'string') {
347
+ err.write(`FAIL: ${card}\n`)
348
+ return 1
349
+ }
350
+ if (card.base == null || card.reference == null || card.doneCmd == null) {
351
+ err.write('FAIL: calibrate needs the card rows base, reference and done cmd\n')
352
+ return 1
353
+ }
354
+ const { gitRoot } = await import('../core/git-root.ts')
355
+ const repo = gitRoot(task)?.top
356
+ if (repo == null) {
357
+ err.write(`FAIL: ${this.task} is not inside a git repo\n`)
358
+ return 1
359
+ }
360
+ const { houseRootOf } = await import('../home/home-start.ts')
361
+ const { seal } = await import('../drill/seal.ts')
362
+ const { cleanDrillCopy } = await import('../drill/clean.ts')
363
+ const roots = await projectRoots()
364
+ let ok = true
365
+ for (const [label, sha, want] of [['base', card.base, false], ['reference', card.reference, true]] as const) {
366
+ try {
367
+ const s = seal({ repo, task, base: sha, house: houseRootOf(repo), prompt: '', install: this.install, configRoots: roots })
368
+ const r = f.runDone(s.dir, card.doneCmd)
369
+ cleanDrillCopy(s.dir)
370
+ const held = (r.exit === 0) === want
371
+ ok &&= held
372
+ out.write(`${held ? 'ok' : 'FAIL'}: ${label} ${short(sha)}: exit ${r.exit} in ${Math.round(r.ms / 1000)}s, ${want ? 'must pass' : 'must fail'}\n`)
373
+ if (!held) out.write(`${r.tail}\n`)
374
+ } catch (e) {
375
+ ok = false
376
+ err.write(`FAIL: ${label} ${short(sha)}: ${(e as Error).message}\n`)
377
+ }
378
+ }
379
+ return ok ? 0 : 1
380
+ }
381
+ }
@@ -162,37 +162,63 @@ export class MediaPurgeCommand extends Command {
162
162
  }
163
163
  }
164
164
 
165
+ /** files a put sends at once: each waits on a HEAD, a PUT and a HEAD, so one at a time spends the put on round trips */
166
+ const PUT_JOBS = 8
167
+
165
168
  const PUT_DETAILS = `The one way an agent of any repo keeps a file in the owner's private Space: never call the Space client directly. Each file is kept by its content as <label>/<sha256>.<ext>, private: its index row (its repo, its place, its original name) first, then the upload, checked by a HEAD of its size; a content the Space already holds is only marked. The object never expires and nothing deletes it from the Space; the file stays on the disk, purgeable by the usual rules (sk media purge). A link is signed on the CDN edge and downloads under the file's name; it lasts at most 7d, the SigV4 limit of a signed URL, and sk media link makes a new one at any time. Page: wiki tools/shipkit/media-store.md, Put a file from any repo`
166
169
 
167
170
  export class MediaPutCommand extends Command {
168
171
  static override paths = [['media', 'put']]
169
172
  static override usage = Command.Usage({
170
173
  category: 'Media',
171
- description: 'keep files in the private Space by content, a signed link at most 7 days',
172
- details: `${PUT_DETAILS}\n\n--json prints one line a file: { key, sha, size, name, url, expires }, url and expires only with --link.`,
174
+ description: 'keep files in the Space by content: a signed link, 7 days at most; --public, a URL for all',
175
+ details: `${PUT_DETAILS}\n\n--public puts each file under public/<label>/<sha256>.<ext> instead, with a permanent URL anyone downloads and nobody lists; the file is never purged from the disk. Page: wiki tools/shipkit/media-store.md, Publish a file anyone downloads.\n\n--json prints one line a file: { key, sha, size, name, url, expires }: url and expires with --link, url alone with --public. Files go up ${PUT_JOBS} at a time, a line each as it lands.`,
173
176
  examples: [
174
177
  ['a file, its key printed', 'sk media put notes.txt'],
175
178
  ['release zips, a week long link each, as json', 'sk media put dist/a.zip dist/b.zip --kind private-build --link 7d --json'],
179
+ ['voice clips anyone downloads, their URLs as json', 'sk media put --public --kind game-voices voices/fr/*.opus --json'],
176
180
  ],
177
181
  })
178
182
  kind = Option.String('--kind', { description: 'the label, the key prefix: lowercase letters, digits, dashes (files)' })
179
183
  link = Option.String('--link', { description: 'a signed link for this long: 30m, 2h, 7d (at most 7d)' })
184
+ public = Option.Boolean('--public', false, { description: 'under public/<label>/: a permanent URL anyone downloads, nobody lists' })
180
185
  json = Option.Boolean('--json', false, { description: 'one JSON line a file' })
181
186
  files = Option.Rest({ required: 1 })
182
187
  async execute(): Promise<number> {
183
188
  return run(this.context, {}, async (h) => {
184
189
  const { durationS, linkMedia, putMedia } = await import('../media-store/put.ts')
185
190
  const { mb } = await import('../media-store/upload.ts')
191
+ if (this.public && this.link !== undefined) throw new Error('--public and --link: a public file has a permanent URL, no link to sign')
186
192
  const seconds = this.link === undefined ? null : durationS(this.link)
187
- for (const f of this.files) {
188
- const p = await putMedia(f, { ...(this.kind !== undefined ? { kind: this.kind } : {}) })
193
+ const failed: string[] = []
194
+ const one = async (f: string): Promise<string> => {
195
+ const p = await putMedia(f, { ...(this.kind !== undefined ? { kind: this.kind } : {}), public: this.public })
189
196
  const l = seconds === null ? null : await linkMedia(p.key, { seconds, name: p.name })
190
- if (this.json) h.out(JSON.stringify({ key: p.key, sha: p.sha, size: p.size, name: p.name, ...(l ? { url: l.url, expires: l.expires } : {}) }))
191
- else {
192
- h.out(`${p.key} ${p.name} ${mb(p.size)} ${p.sent ? 'up' : 'already in the Space'}`)
193
- if (l) h.out(` ${l.url}\n expires ${l.expires}`)
197
+ const url = l?.url ?? p.url
198
+ if (this.json) return JSON.stringify({ key: p.key, sha: p.sha, size: p.size, name: p.name, ...(url ? { url } : {}), ...(l ? { expires: l.expires } : {}) })
199
+ return `${p.key} ${p.name} ${mb(p.size)} ${p.sent ? 'up' : 'already in the Space'}${url ? `\n ${url}${l ? `\n expires ${l.expires}` : ''}` : ''}`
200
+ }
201
+ // lines print in the order the files were named, each once every file before it landed
202
+ const lines: (string | null | undefined)[] = []
203
+ let next = 0
204
+ let shown = 0
205
+ const flush = (): void => {
206
+ for (; shown < lines.length && lines[shown] !== undefined; shown++) if (lines[shown] !== null) h.out(lines[shown]!)
207
+ }
208
+ const work = async (): Promise<void> => {
209
+ for (let i = next++; i < this.files.length; i = next++) {
210
+ const f = this.files[i]!
211
+ try {
212
+ lines[i] = await one(f)
213
+ } catch (e) {
214
+ lines[i] = null
215
+ failed.push(`${f}: ${(e as Error).message}`)
216
+ }
217
+ flush()
194
218
  }
195
219
  }
220
+ await Promise.all(Array.from({ length: Math.min(PUT_JOBS, this.files.length) }, work))
221
+ if (failed.length > 0) throw new Error(`${failed.length} of ${this.files.length} not put:\n${failed.join('\n')}`)
196
222
  return 0
197
223
  })
198
224
  }
@@ -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
- function tileOf(arg: string): { file: string; label: string } {
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 > 0) return { label: arg.slice(0, eq), file: arg.slice(eq + 1) }
80
- const name = arg.split('/').pop() ?? arg
81
- return { file: arg, label: name.replace(/\.[a-z0-9]+$/i, '') }
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
- if (label === undefined || label.startsWith('--') || 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')
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 of small images; "<tile label>=<c.png>" names a tile (repeat it)
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()