rvlib-shipkit 2.17.1 → 2.19.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 (64) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/package.json +1 -1
  3. package/src/asks/asks-queue.ts +63 -10
  4. package/src/checks/SK039-vscode-watch-generated.check.ts +119 -0
  5. package/src/cli/cmd_Asks.ts +3 -1
  6. package/src/cli/cmd_GlobalProcesses.ts +34 -11
  7. package/src/cli/cmd_Home.ts +38 -2
  8. package/src/cli/cmd_Secret.ts +4 -30
  9. package/src/cli/cmd_Social.ts +40 -1
  10. package/src/cli/cmd_Trailer.ts +15 -3
  11. package/src/cli/registry.ts +2 -1
  12. package/src/collections/actions.ts +29 -1
  13. package/src/collections/collection-types.ts +2 -0
  14. package/src/collections/providers.ts +1 -1
  15. package/src/home/home-paths.ts +5 -1
  16. package/src/home/home-start.ts +12 -12
  17. package/src/home/run-daemon.ts +11 -2
  18. package/src/home/run-pm.ts +9 -1
  19. package/src/home/supervise.ts +3 -1
  20. package/src/identities/identities.ts +22 -5
  21. package/src/review/http.ts +7 -2
  22. package/src/review/store.ts +81 -19
  23. package/src/scaffold/files/vscode-settings.json +9 -1
  24. package/src/secrets/manager.ts +59 -0
  25. package/src/secrets/name.ts +2 -0
  26. package/src/serve/hub-app/auto-text.tsx +6 -1
  27. package/src/serve/hub-app/col-card.tsx +10 -0
  28. package/src/serve/hub-app/cols-svc.ts +37 -6
  29. package/src/serve/hub-app/hub.css +1 -0
  30. package/src/serve/hub-app/review/review-st.ts +12 -2
  31. package/src/serve/hub-app/review/review-thread.tsx +1 -1
  32. package/src/serve/hub-app/review/thread-st.ts +17 -1
  33. package/src/serve/hub-app/social/identity-pictures.ts +74 -0
  34. package/src/serve/hub-app/social/kit.tsx +3 -3
  35. package/src/serve/hub-app/social/post-card.tsx +2 -1
  36. package/src/serve/hub-app/social/social-page.tsx +77 -37
  37. package/src/serve/hub-app/social.css +9 -4
  38. package/src/serve/hub-app/stores/stores-page.tsx +4 -3
  39. package/src/serve/hub-app/veille/veille-page.tsx +2 -1
  40. package/src/serve/serve-hub.ts +16 -6
  41. package/src/serve/warm-cell.ts +63 -1
  42. package/src/shot/box.ts +23 -8
  43. package/src/shot/browser-slot.ts +8 -1
  44. package/src/shot/client.ts +9 -4
  45. package/src/shot/clip-encoder.ts +5 -2
  46. package/src/shot/job-store.ts +167 -0
  47. package/src/shot/shooter.ts +8 -3
  48. package/src/social/discord-layout.ts +239 -0
  49. package/src/social/md.ts +14 -6
  50. package/src/social/publish/discord.ts +3 -2
  51. package/src/social/routes.ts +3 -3
  52. package/src/stores/routes.ts +2 -2
  53. package/src/suite/judge-suites.ts +1 -1
  54. package/src/suite/select.ts +32 -6
  55. package/src/suite/suite-cli.ts +5 -5
  56. package/src/trailer/build.ts +75 -50
  57. package/src/trailer/draft.ts +28 -0
  58. package/src/trailer/footage.ts +4 -2
  59. package/src/trailer/grammar.ts +11 -9
  60. package/src/trailer/graph.ts +41 -12
  61. package/src/trailer/profile.ts +35 -0
  62. package/src/trailer/prune.ts +15 -10
  63. package/src/trailer/stitch.ts +22 -10
  64. package/src/trailer/titles.ts +47 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ ## 2.19.0
2
+
3
+ - **`sk trailer --draft`: a quick cut to judge the beats.** Half the size, `out/<name>-draft.mp4`, the cut's own mix, no strip (`--strip` draws one), no shelf. It reads every take the cut has filmed; a take the cut lacks films as a draft take under its own key, its row told by `SK_TRAILER_DRAFT=1` and the draft's size, so no full build or `keep` ever reads it. The prune keeps a cut's draft renders beside its own.
4
+ - **The trailer's sound is mixed while the takes film.** It reads no take, so it no longer waits for the filming nor runs beside the sections.
5
+ - **The mix lands on its `master` in two or three passes.** A pass counts what its trim takes off the loudness and what a dB of gain moved it last time, and a gap measured on the 0.3 LU tolerance holds (a float difference of 0.30000000000000071 used to run four more passes). A mix that never holds keeps its pass under the ceiling nearest its master, not its last one. Measured on a 74 s cut: 5, 6, 2 and 6 passes at four masters became 2, 2, 3 and 3. A cut whose mix is cached mixes again once, and lands within the same 0.3 LU, at a slightly different level.
6
+ - **`sk trailer --profile`** prints every phase of a build, with its start, its seconds and its share of the run.
7
+ - **A big title can stand in the middle.** `place middle` joins top and bottom and centres the title's block on the frame. `sub` draws the lines after the first break smaller, at that share of the size. `shade` lays a soft dark scrim round the words, so they read over a busy picture. A title without these words draws as before.
8
+ - **`sk social discord apply [identity]`: an identity's Discord server is data.** `layout.md` beside the identity's discord `account.md` holds a `## Roles` table, one `##` heading per category with its channels (emoji, topic, read only, voice, age restricted, the roles it is only for), and a `## Members` table that gives roles to members by username. The parser names every bad row at once. The apply writes only what differs, compares each channel by name, category, topic, nsfw flag and permission overwrites, and only gives roles, never takes them. With no guild yet, it names the servers the bot is in.
9
+ - **A credential ask takes the token on its hub page.** An ask that names `secret: <name> [<name>…]` in its front matter shows a password field and a store button per secret. The hub stores the value through the repo's `credsCommand` (the same argv as `sk secret set`, value on stdin), runs that ask's check, and archives the ask when it passes.
10
+ - **`sk pm restart [daemon|web]`** restarts the daemon, the web or both through pm and waits until each probe answers.
11
+ - **pm runs from the house wherever it starts.** `sk pm install` typed in a subfolder of a repo wrote that folder as the LaunchAgent's working directory, and the daemon died at boot with no `repo.config.ts` there. Install now writes the house root of the folder, and pm and the daemon each resolve the house from the wiki index they read, so a hand run inside any folder runs from the house too.
12
+ - **The full test tier runs in parallel workers**, as the quick tier does: the slow suites included, the serial ones alone after, with the full tier's own timeout. Measured on this package: 339 files in 20.2 s on 8 workers, against 44.1 s one suite at a time.
13
+ - **An identity's hub page shows every picture.** The hub serves `.svg` as `image/svg+xml`, so an svg avatar draws. A profile row with a note in parentheses shows its files as tiles and the note under them. The identity's own `pictures/` folder is always listed, one tile per picture with its other formats as downloads, avatars and banners grouped by venue.
14
+ - **The review list can no longer go stale.** It refreshed from file watch events alone, so a watch that went silent under load froze it until the daemon restarted. The watch is now a fast path, and every request also checks the store folder on disk.
15
+
16
+ ## 2.18.0
17
+
18
+ - **SK039: VS Code watches none of shipkit's generated folders.** `.vscode/settings.json` excludes `**/.shipkit/cache/**`, `**/.shipkit/tmp/**`, `**/.shipkit/review/**` and `**/trailer/**/out/**` from `files.watcherExclude`, so the files a build, a film or a test writes never wake the extension host. It warns, and the fix pass of every `sk ci` inserts the missing globs into the hand written jsonc, every other byte kept, or writes a settings file holding the exclusion alone. A glob set to `false` stays; a root published to npm or a linked `.vscode/` is left alone. The scaffold's template carries the block.
19
+ - **The hubs' background warms share one budget of the loop.** Every background recompute of every hub waits its turn in one process wide queue, so however many repos the daemon serves, they hold its loop a quarter of the time at most; a first read or a fresh one never queues. The home page with every repo watched stalled the daemon for over a minute at a time.
20
+ - **A verdict shows the moment it is clicked.** The card and its row draw the chosen verdict while it is sent, and show the error and the truth again if the send fails.
21
+ - **The test selection lists an ignored folder as one entry.** With `tests.select` on, the suite listing asked git for every ignored file (700k in one repo, 16 s); it now names an ignored folder once and walks only the folders bun would search.
22
+ - **A note box grows to show its whole placeholder.** `AutoText` sizes an empty box to its hint, and every multi line field of the hub is now `AutoText`.
23
+ - **A stalled browser can no longer hold a slot for hours.** A browser close and a cookie read get 5 s, the slot frees whatever happened, a call to the shot service waits at most twice the ask's cap, and a waiter names how long each holder has held its slot.
24
+ - **A page that reloads mid film fails with its reason** (a dev server's reload on a save) instead of a TypeError.
25
+ - **A slow `push` glides.** The push is drawn with `perspective` at sub pixel positions; `zoompan` stepped by whole pixels and shook.
26
+ - **A shot or a film on a box starts from an empty store of its own.** Each context of the box's warm browser sees only its own `localStorage` and IndexedDB, kept across a reload inside it and removed when it closes, so no value another job left on the origin changes the page. The HTTP cache stays shared and warm. `openBrowser(pw, { store: 'shared' })` keeps the old shared store.
27
+
1
28
  ## 2.17.1
2
29
 
3
30
  - **A `big` title keeps the cut's line breaks.** Each `\n` starts a line, and a line wider than the frame still wraps; the lines used to be joined and wrapped wherever the width fell.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rvlib-shipkit",
3
- "version": "2.17.1",
3
+ "version": "2.19.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",
@@ -8,9 +8,11 @@
8
8
  import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from 'fs'
9
9
  import { atomicWrite, mutateLease, withMutateLease } from '../core/locked-write.ts'
10
10
  import { join } from 'path'
11
+ import { SECRET_NAME } from '../secrets/name.ts'
11
12
 
12
- export type Ask = { file: string; status: string; kind: string; created: string; closed: string | null; blocks: string; check: string | null; title: string }
13
- export type CreateOpts = { kind?: string; blocks?: string; check?: string; why?: string }
13
+ /** `secrets`: the names a credential ask stores, from its `secret:` line (space or comma separated), [] for none */
14
+ export type Ask = { file: string; status: string; kind: string; created: string; closed: string | null; blocks: string; check: string | null; secrets: string[]; title: string }
15
+ export type CreateOpts = { kind?: string; blocks?: string; check?: string; why?: string; secrets?: string[] }
14
16
 
15
17
  /** filename slug: kebab, truncated at a WORD boundary (never mid-word — a
16
18
  * `…-rvlib-` stub reads as broken). Falls back to a hard cut only when the
@@ -34,6 +36,7 @@ const parse = (dir: string, file: string): Ask => {
34
36
  closed: fm('closed'),
35
37
  blocks: fm('blocks') ?? '-',
36
38
  check: fm('check'),
39
+ secrets: (fm('secret') ?? '').split(/[\s,]+/).filter((n) => n !== ''),
37
40
  title: md.match(/^# (.+)$/m)?.[1] ?? file,
38
41
  }
39
42
  }
@@ -74,12 +77,7 @@ function checkAsksBody(dir: string, print: (line: string) => void): { closed: nu
74
77
  for (const a of listAsks(dir)) {
75
78
  if (a.status === 'done') { renameSync(join(dir, a.file), join(done, a.file)); print(`archived ${a.file} → done/`); continue }
76
79
  if (a.check == null) { print(`still ${a.status.padEnd(8)} ${a.file} (manual — no probe)`); continue }
77
- // env named: bun's default is the env the process started with, blind to a later process.env write
78
- const p = Bun.spawnSync(['bash', '-lc', a.check], { env: process.env })
79
- if (p.exitCode === 0) {
80
- const md = readFileSync(join(dir, a.file), 'utf8').replace(/^status:.*$/m, `status: done\nclosed: ${new Date().toISOString().slice(0, 10)}`)
81
- atomicWrite(join(dir, a.file), md)
82
- renameSync(join(dir, a.file), join(done, a.file))
80
+ if (probeAsk(dir, a, a.check).passed) {
83
81
  print(`closed + archived ${a.file}`)
84
82
  closed++
85
83
  } else {
@@ -90,6 +88,37 @@ function checkAsksBody(dir: string, print: (line: string) => void): { closed: nu
90
88
  return { closed }
91
89
  }
92
90
 
91
+ /** one ask's probe: when it exits 0 the ask is stamped done and archived; else
92
+ * the probe's last stderr line says why */
93
+ function probeAsk(dir: string, a: Ask, check: string): { passed: true } | { passed: false; why: string } {
94
+ // env named: bun's default is the env the process started with, blind to a later process.env write
95
+ const p = Bun.spawnSync(['bash', '-lc', check], { env: process.env, stdout: 'ignore', stderr: 'pipe' })
96
+ if (p.exitCode !== 0) {
97
+ const tail = p.stderr.toString().trim().split('\n').at(-1) ?? ''
98
+ return { passed: false, why: `exit ${p.exitCode}${tail !== '' ? `: ${tail}` : ''}` }
99
+ }
100
+ const done = join(dir, 'done')
101
+ mkdirSync(done, { recursive: true })
102
+ const md = readFileSync(join(dir, a.file), 'utf8').replace(/^status:.*$/m, `status: done\nclosed: ${new Date().toISOString().slice(0, 10)}`)
103
+ atomicWrite(join(dir, a.file), md)
104
+ renameSync(join(dir, a.file), join(done, a.file))
105
+ return { passed: true }
106
+ }
107
+
108
+ export type OneCheck = { check: 'none' } | { check: 'passed' } | { check: 'failed'; why: string }
109
+
110
+ /** `checkAsks` for one open ask: its probe alone, under the same lease */
111
+ export async function checkAsk(root: string, dir: string, file: string): Promise<OneCheck> {
112
+ const leased = await withMutateLease(mutateLease(root, 'asks'), { label: 'asks archive', print: () => {}, maxWaitMs: 45_000 }, (): OneCheck => {
113
+ const a = openAsks(dir).find((x) => x.file === file)
114
+ if (a == null) return { check: 'failed', why: `${file} is no longer an open ask` }
115
+ if (a.check == null) return { check: 'none' }
116
+ const r = probeAsk(dir, a, a.check)
117
+ return r.passed ? { check: 'passed' } : { check: 'failed', why: r.why }
118
+ })
119
+ return leased.ok ? leased.value : { check: 'failed', why: `the check did not run: ${leased.warn}` }
120
+ }
121
+
93
122
  // the hub renders ask markdown, so a new ask starts as the page the human
94
123
  // follows: one section per step, a link that opens the exact page, values
95
124
  // to copy. Every {{placeholder}} is the author's to fill (braces, since markdown hides an unknown <tag>) before the ask ships
@@ -116,7 +145,31 @@ const DECISION_BODY = `<!-- a decision: numbered options, the recommended one fi
116
145
  Reply with the number.
117
146
  `
118
147
 
148
+ // a credential ask: the human mints the value, then pastes it into the field
149
+ // the hub draws under the ask, or into the store command's silent prompt
150
+ const credentialBody = (names: string[]): string => `<!-- a credential: the steps that mint the value, then the store step as written. Values in the table, buttons in bold. -->
151
+
152
+ ## 1. {{verb}} {{thing}}
153
+
154
+ Open **[{{page name}}]({{url, ids filled in}})**, then click **{{button}}**, and copy the value it shows.
155
+
156
+ ## 2. Store it
157
+
158
+ Paste it in the field below and click **store**. Or type ${names.length > 1 ? 'these lines' : 'this line'} in Claude Code and paste it at the silent prompt:
159
+
160
+ \`\`\`
161
+ ${names.map((n) => `! sk secret set ${n}`).join('\n')}
162
+ \`\`\`
163
+
164
+ The check below then closes this ask.
165
+ `
166
+
119
167
  export function createAsk(dir: string, title: string, opts?: CreateOpts): string {
168
+ const secrets = opts?.secrets ?? []
169
+ const bad = secrets.find((s) => !SECRET_NAME.test(s))
170
+ if (bad != null) throw new Error(`refusing secret name '${bad}': letters, digits and . _ @ / - only, never a leading dash`)
171
+ if (secrets.length > 0 && (opts?.kind ?? 'credential') !== 'credential') throw new Error(`a secret is stored by a credential ask, not a ${opts?.kind} one`)
172
+ opts = secrets.length > 0 ? { ...opts, kind: 'credential', check: opts?.check ?? secrets.map((s) => `sk secret get ${s} >/dev/null`).join(' && ') } : opts
120
173
  mkdirSync(dir, { recursive: true })
121
174
  // max numeric prefix across BOTH live and archived asks — numbers are never reused
122
175
  const done = join(dir, 'done')
@@ -135,12 +188,12 @@ export function createAsk(dir: string, title: string, opts?: CreateOpts): string
135
188
  status: open
136
189
  kind: ${opts?.kind ?? 'action'}
137
190
  created: ${new Date().toISOString().slice(0, 10)}
138
- blocks: ${opts?.blocks ?? '-'}${check != null ? `\ncheck: ${check}` : ''}
191
+ blocks: ${opts?.blocks ?? '-'}${check != null ? `\ncheck: ${check}` : ''}${secrets.length > 0 ? `\nsecret: ${secrets.join(' ')}` : ''}
139
192
  ---
140
193
 
141
194
  # ${title}
142
195
 
143
- ${whyBlock}${opts?.kind === 'decision' ? DECISION_BODY : STEPS_BODY}
196
+ ${whyBlock}${opts?.kind === 'decision' ? DECISION_BODY : secrets.length > 0 ? credentialBody(secrets) : STEPS_BODY}
144
197
  **Answer**: _(fill in / check off, or just do it — the check probe auto-closes when it passes)_
145
198
 
146
199
  **Done when**: ${doneWhen}
@@ -0,0 +1,119 @@
1
+ // SK039 vscode watch generated (patterns/vscode-tasks/index.md): VS Code watches no folder shipkit writes for itself.
2
+ // Its file watcher walks the whole workspace, so every file a gate, a shot, a film or a review card writes under
3
+ // these folders woke the editor's extension host, for every repo open in a window.
4
+ //
5
+ // the file is hand-written jsonc: the repair inserts the missing keys after the last one and leaves every other byte,
6
+ // and writes a settings file of its own only where the repo has none
7
+ import { check } from '../check.ts'
8
+ import type { CheckCtx } from '../core/check-ctx.ts'
9
+ import { rootPublishesNpm } from '../core/repo-facts.ts'
10
+ import { indentAt, parseSpans, type Node } from '../scaffold/jsonc-spans.ts'
11
+
12
+ const SETTINGS = '.vscode/settings.json'
13
+ const KEY = 'files.watcherExclude'
14
+
15
+ /** the folders shipkit writes in a repo that no person edits: the gate's cache, scratch, the review store's media,
16
+ * a trailer's built cuts */
17
+ export const GENERATED_GLOBS = ['**/.shipkit/cache/**', '**/.shipkit/tmp/**', '**/.shipkit/review/**', '**/trailer/**/out/**'] as const
18
+
19
+ type Obj = Extract<Node, { kind: 'object' }>
20
+
21
+ /** where new props go in `o`: after its last prop (a comma added when it has none, past a comment ending its line),
22
+ * else right after its brace; the indent of its props */
23
+ function insertPoint(text: string, o: Obj, outer: string): { at: number; comma: number | null; indent: string } {
24
+ const last = o.props.at(-1)
25
+ if (last == null) return { at: o.start + 1, comma: null, indent: `${outer} ` }
26
+ const indent = indentAt(text, last.keyStart)
27
+ let j = last.value.end
28
+ while (j < o.end && /[ \t]/.test(text[j]!)) j++
29
+ const hasComma = text[j] === ','
30
+ const from = hasComma ? j + 1 : last.value.end
31
+ // the rest of the line, a trailing comment included, stays with the prop it follows
32
+ const eol = text.indexOf('\n', from)
33
+ const rest = eol < 0 ? '' : text.slice(from, eol)
34
+ const at = eol >= 0 && eol < o.end && /^\s*(\/\/.*)?$/.test(rest) ? eol : from
35
+ return { at, comma: hasComma ? null : last.value.end, indent }
36
+ }
37
+
38
+ const splice = (text: string, edits: { at: number; put: string }[]): string =>
39
+ edits.sort((a, b) => b.at - a.at).reduce((t, e) => t.slice(0, e.at) + e.put + t.slice(e.at), text)
40
+
41
+ /** the settings text with every generated folder excluded from VS Code's watcher, and the globs it added; null when
42
+ * the file is not one object */
43
+ export function withWatchExcludes(text: string): { text: string; added: string[] } | null {
44
+ const root = parseSpans(text)
45
+ if (root.kind !== 'object') return null
46
+ const prop = root.props.find((p) => p.key === KEY)
47
+ if (prop != null && prop.value.kind !== 'object') return null
48
+ const have = prop == null ? new Map<string, unknown>() : new Map((prop.value as Obj).props.map((p) => [p.key, p.value.kind === 'scalar' ? p.value.value : null]))
49
+ // a glob the repo set to false is its own decision, kept
50
+ const added = GENERATED_GLOBS.filter((g) => !have.has(g))
51
+ if (added.length === 0) return { text, added }
52
+ if (prop != null) {
53
+ const o = prop.value as Obj
54
+ const p = insertPoint(text, o, indentAt(text, prop.keyStart))
55
+ const lines = added.map((g) => `\n${p.indent}"${g}": true`).join(',')
56
+ // an empty object gets its closing brace back on a line of its own
57
+ const close = o.props.length === 0 ? `\n${indentAt(text, prop.keyStart)}` : ''
58
+ const edits = [{ at: p.at, put: `${lines}${close}` }, ...(p.comma != null ? [{ at: p.comma, put: ',' }] : [])]
59
+ return { text: splice(text, edits), added }
60
+ }
61
+ const p = insertPoint(text, root, '')
62
+ const inner = added.map((g) => `${p.indent} "${g}": true`).join(',\n')
63
+ const block = `\n\n${p.indent}// shipkit's generated folders: never watched (SK039)\n${p.indent}"${KEY}": {\n${inner}\n${p.indent}}`
64
+ const edits = [{ at: p.at, put: block }, ...(p.comma != null ? [{ at: p.comma, put: ',' }] : [])]
65
+ return { text: splice(text, edits), added }
66
+ }
67
+
68
+ /** a settings file holding the exclusion alone, for a repo that has none */
69
+ export const freshSettings = (): string =>
70
+ `{\n // shipkit's generated folders: never watched (SK039)\n "${KEY}": {\n${GENERATED_GLOBS.map((g) => ` "${g}": true`).join(',\n')}\n }\n}\n`
71
+
72
+ const PUBLIC_SKIP = `the root unit publishes to npm: ${SETTINGS} belongs to every contributor, so it is never written`
73
+
74
+ function ownSettings(c: CheckCtx): { text: string } | 'none' | 'linked' {
75
+ if (c.isLink('.vscode')) return 'linked'
76
+ if (!c.exists(SETTINGS)) return 'none'
77
+ const text = c.read(SETTINGS)
78
+ return text == null ? 'none' : { text }
79
+ }
80
+
81
+ export const vscodeWatchGenerated = check({
82
+ id: 'SK039',
83
+ // an editor setting behind is waste, not a broken repo: it warns, and the fix pass of every gate repairs it
84
+ blocking: false,
85
+ title: 'vscode watch generated',
86
+ description: "VS Code watches none of shipkit's generated folders: cache, tmp, review, trailer cuts",
87
+ owner: 'patterns/vscode-tasks/index.md',
88
+ runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: false, onHealth: true, onSave: 'moved', onClock: false },
89
+ cache: { by: 'reads' },
90
+ fix: 'ci',
91
+ applies: 'always',
92
+ run: (c) => {
93
+ if (rootPublishesNpm(c.config)) return c.ok(PUBLIC_SKIP)
94
+ const own = ownSettings(c)
95
+ if (own === 'linked') return c.ok('.vscode/ is a link to a shared dir, left alone')
96
+ if (own === 'none') return c.fail(`no ${SETTINGS}: VS Code watches every generated folder (${GENERATED_GLOBS.join(', ')})`)
97
+ let r: ReturnType<typeof withWatchExcludes>
98
+ try { r = withWatchExcludes(own.text) }
99
+ catch (e) { return c.warn(`${SETTINGS} does not parse (${(e as Error).message}), so its watcher exclusions were not checked`) }
100
+ if (r == null) return c.warn(`${SETTINGS}: no object, or ${KEY} is no object, so its exclusions were not checked`)
101
+ if (r.added.length === 0) return c.ok(`${SETTINGS}: VS Code watches no generated folder`)
102
+ c.fail(`${SETTINGS}: ${KEY} misses ${r.added.join(', ')}`)
103
+ },
104
+ repair: (c) => {
105
+ if (rootPublishesNpm(c.config)) return { changed: false, summary: PUBLIC_SKIP }
106
+ const own = ownSettings(c)
107
+ if (own === 'linked') return { changed: false, summary: '.vscode/ is a link, left alone' }
108
+ if (own === 'none') {
109
+ c.write(SETTINGS, freshSettings())
110
+ return { changed: true, summary: `${SETTINGS}: written, VS Code watches no generated folder` }
111
+ }
112
+ const r = withWatchExcludes(own.text)
113
+ if (r == null || r.added.length === 0) return { changed: false, summary: `${SETTINGS} already current, or not one object` }
114
+ c.write(SETTINGS, r.text)
115
+ return { changed: true, summary: `${SETTINGS}: ${KEY} gained ${r.added.join(', ')}` }
116
+ },
117
+ })
118
+
119
+ export default vscodeWatchGenerated
@@ -62,6 +62,7 @@ export class AskNewCommand extends Command {
62
62
  ['minimal', 'sk ask "rotate the API token"'],
63
63
  ['with a reason', 'sk ask "buy the domain" --why "landing page is blocked on it"'],
64
64
  ['with metadata', 'sk ask "buy the domain" --kind action --blocks deploy --check "dig +short example.com"'],
65
+ ['a token he pastes in the hub', 'sk ask "mint the npm token" --secret rv/npm/token'],
65
66
  ],
66
67
  })
67
68
 
@@ -70,11 +71,12 @@ export class AskNewCommand extends Command {
70
71
  blocks = Option.String('--blocks', { required: false, description: 'what this ask blocks (task id, page, plain words)' })
71
72
  check = Option.String('--check', { required: false, description: 'shell probe that exits 0 once the ask is done (enables auto-close)' })
72
73
  why = Option.String('--why', { required: false, description: 'one line of context: why this is worth a human interrupt' })
74
+ secret = Option.Array('--secret', { required: false, description: 'a secret name the human stores (repeat for more): a credential ask whose page takes the pasted value' })
73
75
 
74
76
  async execute(): Promise<number> {
75
77
  try {
76
78
  const dir = await asksDir(process.cwd())
77
- const file = createAsk(dir, this.title, { kind: this.kind, blocks: this.blocks, check: this.check, why: this.why })
79
+ const file = createAsk(dir, this.title, { kind: this.kind, blocks: this.blocks, check: this.check, why: this.why, secrets: this.secret ?? [] })
78
80
  this.context.stdout.write(`created ${dir}/${file}\nfill every {{placeholder}} in it: the hub shows the body as written\n`)
79
81
  return 0
80
82
  } catch (e) {
@@ -8,7 +8,7 @@ import { homedir } from 'os'
8
8
  import { Command, Option } from 'clipanion'
9
9
  import { daemonPort, daemonUrl, homePort, pmPort, pmUrl } from '../home/home-paths.ts'
10
10
  import { houseRootOf } from '../home/home-start.ts'
11
- import type { PmAnswer } from '../home/pm.ts'
11
+ import { ROLES, type PmAnswer, type Role } from '../home/pm.ts'
12
12
  import type { ResourceView } from '../home/resources.ts'
13
13
  import { coreGroup, declaredRow, groupRows, processGroups, stateWords, type ProcessGroup } from '../home/process-rows.ts'
14
14
  import type { PmConfig } from '../home/pm-config.ts'
@@ -159,11 +159,14 @@ export class GlobalProcessesCommand extends Command {
159
159
 
160
160
  export type SwitchAct = 'start' | 'stop' | 'restart'
161
161
 
162
+ /** what a switch follows, the same on a global process and on one of pm's own roles (the daemon, the web) */
163
+ export type SwitchView = Pick<ResourceView, 'status' | 'pid' | 'want' | 'note' | 'tail'>
164
+
162
165
  export type SwitchDeps = {
163
166
  /** pm's answer to the switch: null when it took it, else why not */
164
167
  post: (id: string, act: SwitchAct | 'open' | 'chrome' | 'app') => Promise<string | null>
165
168
  /** the process as pm sees it now, null when pm does not answer */
166
- view: (id: string) => Promise<ResourceView | null>
169
+ view: (id: string) => Promise<SwitchView | null>
167
170
  sleep: (ms: number) => Promise<void>
168
171
  now: () => number
169
172
  log: (line: string) => void
@@ -175,10 +178,13 @@ const SWITCH_POLL_MS = 1_000
175
178
  /** how long the state the switch left counts as pm not having acted yet */
176
179
  export const SWITCH_GRACE_MS = 30_000
177
180
 
178
- /** flip a global process through pm, then follow pm's state until its probe
179
- * settles it: 0 once it is up (or down for stop), 1 otherwise. The launcher's
180
- * exit code proves nothing, pm's probe does */
181
+ /** flip a global process, or one of pm's own roles, through pm, then follow
182
+ * pm's state until its probe settles it: 0 once it is up (or down for stop),
183
+ * 1 otherwise. A restart is up only on a new pid: the old one still answers
184
+ * until pm stops it (pm stops the web after its answer is out). The
185
+ * launcher's exit code proves nothing, pm's probe does */
181
186
  export async function switchProcess(id: string, act: SwitchAct, d: SwitchDeps, waitMs = SWITCH_WAIT_MS): Promise<number> {
187
+ const before = act === 'restart' ? ((await d.view(id))?.pid ?? null) : null
182
188
  const refused = await d.post(id, act)
183
189
  if (refused != null) {
184
190
  d.log(`FAIL ${act} ${id}: ${refused}`)
@@ -199,9 +205,15 @@ export async function switchProcess(id: string, act: SwitchAct, d: SwitchDeps, w
199
205
  d.log(`${id}: ${v.status}`)
200
206
  }
201
207
  // the state it is leaving, read just after the switch, is pm not there yet
202
- const leaving = v.status === (want === 'up' ? 'down' : 'up') && d.now() - start < SWITCH_GRACE_MS
203
- const moving = v.status === 'starting' || v.status === 'stopping' || v.want !== want || leaving
208
+ const graced = d.now() - start < SWITCH_GRACE_MS
209
+ const leaving = v.status === (want === 'up' ? 'down' : 'up') && graced
210
+ const old = before != null && v.pid === before
211
+ const moving = v.status === 'starting' || v.status === 'stopping' || v.want !== want || leaving || (old && graced)
204
212
  if (!moving) {
213
+ if (old && v.status === 'up') {
214
+ d.log(`FAIL ${id} still runs pid ${before} ${Math.round(SWITCH_GRACE_MS / 1000)}s after the restart: pm did not restart it`)
215
+ return 1
216
+ }
205
217
  if (v.status === want) return 0
206
218
  d.log(`FAIL ${id} is ${v.status}, not ${want}${v.note == null ? '' : `: ${v.note}`}`)
207
219
  for (const l of v.tail.slice(-10)) d.log(` log: ${l}`)
@@ -215,17 +227,24 @@ export async function switchProcess(id: string, act: SwitchAct, d: SwitchDeps, w
215
227
  }
216
228
  }
217
229
 
218
- /** the switch against the running pm */
230
+ const isRole = (id: string): id is Role => (ROLES as string[]).includes(id)
231
+
232
+ /** the switch against the running pm: pm's own roles (the daemon, the web) through its child api, every other id a
233
+ * global process */
219
234
  export const pmSwitchDeps = (log: (line: string) => void, url = pmUrl()): SwitchDeps => ({
220
235
  post: async (id, act) => {
221
236
  try {
222
- const r = await fetch(`${url}/api/pm/resource`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id, act }), signal: AbortSignal.timeout(5_000) })
237
+ const r = await fetch(`${url}/api/pm/${isRole(id) ? 'child' : 'resource'}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id, act }), signal: AbortSignal.timeout(5_000) })
223
238
  return r.ok ? null : await r.text()
224
239
  } catch (e) {
225
240
  return `pm does not answer on ${url} (${(e as Error).message}): shipkit pm install`
226
241
  }
227
242
  },
228
- view: async (id) => (await askPm(url))?.resources.find((r) => r.id === id) ?? null,
243
+ view: async (id) => {
244
+ const a = await askPm(url)
245
+ if (a == null) return null
246
+ return (isRole(id) ? a.children.find((c) => c.id === id) : a.resources.find((r) => r.id === id)) ?? null
247
+ },
229
248
  sleep: (ms) => Bun.sleep(ms),
230
249
  now: () => Date.now(),
231
250
  log,
@@ -268,7 +287,11 @@ export class GlobalProcessRestartCommand extends SwitchCommand {
268
287
  static override usage = Command.Usage({
269
288
  category: 'Home',
270
289
  description: 'restart a global process through pm and wait until its probe answers again. Exit 0 once it is up',
271
- examples: [['restart ComfyUI, so it rescans its models', 'sk gp restart comfyui']],
290
+ details: 'restart a global process, or one of pm\'s own roles (`daemon`, `web`: the same as `sk pm restart <role>`), through pm, and wait until its probe answers again. A process pm holds a pid for is up only on a new pid. Exit 0 once it is up, 1 when it crashed, kept its old pid or pm refused',
291
+ examples: [
292
+ ['restart ComfyUI, so it rescans its models', 'sk gp restart comfyui'],
293
+ ['restart the home daemon in place', 'sk gp restart daemon'],
294
+ ],
272
295
  })
273
296
  }
274
297
 
@@ -6,7 +6,9 @@ import { fileURLToPath } from 'url'
6
6
  import { basename } from 'path'
7
7
  import { markAutostart } from '../home/autostart.ts'
8
8
  import { installHome, uninstallHome } from '../home/home-launchd.ts'
9
- import { homeInstalled, houseCli, houseRootOf, openWindow, startHome } from '../home/home-start.ts'
9
+ import { homeInstalled, houseCli, houseRoot, houseRootOf, openWindow, startHome } from '../home/home-start.ts'
10
+ import { ROLES } from '../home/pm.ts'
11
+ import { pmSwitchDeps, switchProcess } from './cmd_GlobalProcesses.ts'
10
12
  import { homeUp, homeUrl, hubBase } from '../home/home-paths.ts'
11
13
  import { homeRepo, houseIndex } from '../serve/project-gutter.ts'
12
14
  import { homedir } from 'os'
@@ -156,8 +158,42 @@ export class PmInstallCommand extends Command {
156
158
  })
157
159
 
158
160
  async execute(): Promise<number> {
161
+ const root = houseRoot(process.cwd())
162
+ if (root == null) {
163
+ io(this).printErr(`FAIL: ${process.cwd()} is in no house repo, and no pm agent names one: run \`sk pm install\` from any folder of a repo whose CLAUDE.md includes the house wiki`)
164
+ return 1
165
+ }
159
166
  markAutostart(true)
160
- return installHome({ root: process.cwd(), cli: houseCli(process.cwd(), OWN_CLI), print: io(this).print })
167
+ return installHome({ root, cli: houseCli(root, OWN_CLI), print: io(this).print })
168
+ }
169
+ }
170
+
171
+ export class PmRestartCommand extends Command {
172
+ static override paths = [['pm', 'restart']]
173
+
174
+ static override usage = Command.Usage({
175
+ category: 'Serve',
176
+ description: 'restart the daemon, the web or both through pm, and wait until each probe answers again',
177
+ details: 'restart pm\'s own roles in place, never a kill: pm stops the role, starts it again, and this waits until a new pid answers its probe (the same switch as `sk gp restart`, which takes `daemon` and `web` too). With no role, the daemon, then the web. Exit 0 once each is up on a new pid, 1 when pm does not answer, the role crashed, or it kept its old pid. pm itself restarts with `sk pm install`',
178
+ examples: [
179
+ ['the daemon reads every store and repo again', 'sk pm restart daemon'],
180
+ ['the daemon and the web', 'sk pm restart'],
181
+ ],
182
+ })
183
+
184
+ role = Option.String({ required: false, name: 'daemon|web' })
185
+
186
+ async execute(): Promise<number> {
187
+ if (this.role != null && !(ROLES as string[]).includes(this.role)) {
188
+ this.context.stderr.write(`FAIL: '${this.role}' is no pm role: ${ROLES.join(' or ')}; a global process restarts with \`sk gp restart <id>\`\n`)
189
+ return 2
190
+ }
191
+ const deps = pmSwitchDeps(io(this).print)
192
+ for (const role of this.role == null ? ROLES : [this.role]) {
193
+ const code = await switchProcess(role, 'restart', deps)
194
+ if (code !== 0) return code
195
+ }
196
+ return 0
161
197
  }
162
198
  }
163
199
 
@@ -1,43 +1,17 @@
1
1
  // shipkit secret — the secrets of the repo you stand in, and the reads and
2
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`.
3
+ // Logic in secrets/list.ts and secrets/manager.ts. A value only ever goes to stdout of `get`/`account`.
4
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
5
  import { presence, secretsFor } from '../secrets/list.ts'
6
+ import { managerTemplate as template, NoManager, secretsWhere as where, storeArgv } from '../secrets/manager.ts'
12
7
  import { secretArgv } from '../smoke/run-smoke.ts'
13
8
 
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
9
  /** runs a verb, printing a refusal as its one line */
36
10
  async function refusing(stderr: NodeJS.WritableStream, run: () => Promise<number>): Promise<number> {
37
11
  try {
38
12
  return await run()
39
13
  } catch (e) {
40
- if (!(e instanceof Refused)) throw e
14
+ if (!(e instanceof NoManager)) throw e
41
15
  stderr.write(`${e.message}\n`)
42
16
  return 1
43
17
  }
@@ -120,7 +94,7 @@ export class SecretSetCommand extends Command {
120
94
 
121
95
  async execute(): Promise<number> {
122
96
  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] : [])]
97
+ const argv = storeArgv(template(await where(process.cwd()), 'credsCommand'), this.name, this.account)
124
98
  return Bun.spawnSync(argv, { stdin: 'inherit', stdout: 'inherit', stderr: 'inherit' }).exitCode ?? 1
125
99
  })
126
100
  }
@@ -187,6 +187,45 @@ class SocialMigrateCommand extends Command {
187
187
  }
188
188
  }
189
189
 
190
+ class SocialDiscordApplyCommand extends Command {
191
+ static override paths = [['social', 'discord', 'apply']]
192
+ static override usage = Command.Usage({
193
+ category: 'Social',
194
+ description: "an identity's Discord server made to match its layout.md through its bot: roles, channels",
195
+ details:
196
+ "The layout is `layout.md` beside the identity's discord `account.md`, which names the server (`guild`) and the bot's token (`secret`). It creates, renames, moves, sets topics, read only, age restricted and role only channels; a server that matches gets no write. It never deletes but with --prune, and then only an empty text channel the layout lacks. With no guild yet, it names the servers the bot is in. Page: wiki tools/shipkit/social-identities.md, The server's layout",
197
+ examples: [
198
+ ['what would change', 'sk social discord apply studio --dry'],
199
+ ['as this repo speaks', 'sk social discord apply'],
200
+ ['and delete the empty channels it lacks', 'sk social discord apply studio --prune'],
201
+ ],
202
+ })
203
+ identity = Option.String({ required: false })
204
+ dry = Option.Boolean('--dry', false, { description: 'print what would change, write nothing' })
205
+ prune = Option.Boolean('--prune', false, { description: 'delete an empty text channel the layout lacks' })
206
+ override async execute(): Promise<number> {
207
+ return guarded(this.context, async () => {
208
+ const { loadIdentities, identityOf, speakerOf } = await import('../identities/identities.ts')
209
+ const { applyLayout } = await import('../social/discord-layout.ts')
210
+ const ids = await loadIdentities()
211
+ let id = this.identity
212
+ if (id == null) {
213
+ const { findRepoRoot } = await import('../ts/config.ts')
214
+ const { loadRepoConfig } = await import('../repo-config.ts')
215
+ id = speakerOf((await loadRepoConfig(findRepoRoot(process.cwd()))).speaksAs, ids)?.id
216
+ if (id == null) throw new Error('no identity named and none this repo speaks as')
217
+ }
218
+ const a = identityOf(id, ids).accounts.find((x) => x.id === 'discord')
219
+ if (a == null) throw new Error(`${id} has no discord account (accounts/discord/account.md)`)
220
+ const r = await applyLayout(a, { dry: this.dry, prune: this.prune })
221
+ for (const l of r.changes) say(this.context)(l)
222
+ if (r.changes.length === 0) say(this.context)(`ok: the server of ${id} matches its layout`)
223
+ for (const l of r.left) say(this.context)(`left alone: ${l}`)
224
+ return 0
225
+ })
226
+ }
227
+ }
228
+
190
229
  class IdentitiesCommand extends Command {
191
230
  static override paths = [['identities']]
192
231
  static override usage = Command.Usage({
@@ -233,4 +272,4 @@ class IdentitiesCommand extends Command {
233
272
  }
234
273
  }
235
274
 
236
- export const SOCIAL_COMMANDS = [SocialCommand, SocialTimelineCommand, SocialCoverageCommand, SocialPostCommand, SocialPlanCommand, SocialStateCommand, SocialMigrateCommand, IdentitiesCommand]
275
+ export const SOCIAL_COMMANDS = [SocialCommand, SocialTimelineCommand, SocialCoverageCommand, SocialPostCommand, SocialPlanCommand, SocialStateCommand, SocialMigrateCommand, SocialDiscordApplyCommand, IdentitiesCommand]
@@ -36,6 +36,8 @@ export class TrailerCommand extends Command {
36
36
  ['film again the takes of two shots', 'sk trailer --refilm intro,menu'],
37
37
  ['encoded by x264 for a release', 'sk trailer --final'],
38
38
  ['the music variant b on the same picture', 'sk trailer --variant b'],
39
+ ['a quick draft to judge the beats', 'sk trailer --draft'],
40
+ ['where the build spends its time', 'sk trailer --profile'],
39
41
  ],
40
42
  })
41
43
 
@@ -43,13 +45,23 @@ export class TrailerCommand extends Command {
43
45
  refilm = Option.String('--refilm', { tolerateBoolean: true, description: 'film again: every stale take, or the named shots (a,b)' })
44
46
  final = Option.Boolean('--final', false, { description: 'encode with x264 for a release (default: the fast draft encoder)' })
45
47
  variant = Option.String('--variant', { description: 'a music variant the cut names (music … variant <name>): out/<name>-<variant>.mp4' })
48
+ draft = Option.Boolean('--draft', false, { description: 'a quick draft at half the size: out/<name>-draft.mp4, the cut\'s takes read as they are, a missing one filmed small, no strip' })
49
+ strip = Option.Boolean('--strip', false, { description: 'with --draft: its strip too' })
50
+ profile = Option.Boolean('--profile', false, { description: 'print every phase of the build with its start, seconds and share' })
46
51
 
47
52
  async execute(): Promise<number> {
48
53
  return run(this.context, async (say, root, cwd) => {
49
- const b = await import('../trailer/build.ts')
50
- const l = await b.load(b.trailerFile(this.file, root, cwd), root, this.variant !== undefined ? { variant: this.variant } : {})
54
+ const { span, timed, profileLines } = await import('../trailer/profile.ts')
55
+ span('start: bun, sk, the cli', 0, performance.now())
56
+ const b = await timed('load: build modules', () => import('../trailer/build.ts'))
57
+ const l = await timed('load: parse and check', () => b.load(b.trailerFile(this.file, root, cwd), root, this.variant !== undefined ? { variant: this.variant } : {}))
51
58
  if (!b.sayErrors(l, say, cwd)) return 1
52
- await b.build(l, { refilm: refilmOf(this.refilm), final: this.final, say, cwd })
59
+ try {
60
+ const draft = this.draft ? { draft: (await import('../trailer/draft.ts')).DRAFT, strip: this.strip } : {}
61
+ await b.build(l, { refilm: refilmOf(this.refilm), final: this.final, say, cwd, ...draft })
62
+ } finally {
63
+ if (this.profile) for (const line of profileLines()) say(line)
64
+ }
53
65
  return 0
54
66
  })
55
67
  }
@@ -24,7 +24,7 @@ import { CiCommand } from './cmd_Ci.ts'
24
24
  import { ContractsCommand } from './cmd_Contracts.ts'
25
25
  import { FleetCommand } from './cmd_Fleet.ts'
26
26
  import { FleetPushCommand } from './cmd_FleetPush.ts'
27
- import { DaemonCommand, DaemonJobCommand, GuiCommand, PmCommand, PmInstallCommand, PmUninstallCommand, WebCommand } from './cmd_Home.ts'
27
+ import { DaemonCommand, DaemonJobCommand, GuiCommand, PmCommand, PmInstallCommand, PmRestartCommand, PmUninstallCommand, WebCommand } from './cmd_Home.ts'
28
28
  import { HooksCommitMsgCommand, HooksInstallCommand, HooksListCommand, HooksPreCommitCommand } from './cmd_Hooks.ts'
29
29
  import { InitCommand } from './cmd_Init.ts'
30
30
  import { KeysCommand } from './cmd_Keys.ts'
@@ -102,6 +102,7 @@ export function buildCli(): Cli {
102
102
  cli.register(WebCommand)
103
103
  cli.register(PmInstallCommand)
104
104
  cli.register(PmUninstallCommand)
105
+ cli.register(PmRestartCommand)
105
106
  cli.register(GuiCommand)
106
107
  cli.register(ContractsCommand)
107
108
  cli.register(AsksCommand)