rvlib-shipkit 2.32.0 → 2.34.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 (76) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/package.json +1 -1
  3. package/src/advisors/advisor-view.ts +29 -7
  4. package/src/advisors/edge/api.ts +1 -30
  5. package/src/advisors/project.ts +3 -3
  6. package/src/advisors/sync.ts +11 -4
  7. package/src/advisors/users-router.ts +13 -11
  8. package/src/cli/cmd_BackupTargets.ts +49 -8
  9. package/src/cli/cmd_Capacity.ts +6 -2
  10. package/src/cli/cmd_Ci.ts +2 -1
  11. package/src/cli/cmd_Media.ts +1 -1
  12. package/src/cli/cmd_Shot.ts +26 -4
  13. package/src/cli/cmd_Start.ts +3 -3
  14. package/src/cli.ts +13 -2
  15. package/src/core/admission.ts +268 -0
  16. package/src/core/code-lines.ts +36 -21
  17. package/src/core/machine-read.ts +5 -2
  18. package/src/core/memory-watch.ts +1 -1
  19. package/src/core/peer-sk.ts +8 -0
  20. package/src/gate/admit-heavy.ts +150 -0
  21. package/src/gate/check-runner.ts +6 -0
  22. package/src/gate/gate-checks.ts +7 -5
  23. package/src/gate/head-gate.ts +1 -1
  24. package/src/gate/job-run.ts +2 -1
  25. package/src/gate/pre-commit-discovery.ts +6 -3
  26. package/src/gate/run-check.ts +3 -0
  27. package/src/gate/run-ci.ts +4 -0
  28. package/src/home/backup-status.ts +41 -13
  29. package/src/home/backup-verdict.ts +1 -0
  30. package/src/home/daemon-jobs.ts +5 -0
  31. package/src/home/home-routes.ts +3 -2
  32. package/src/home/house-bucket.ts +14 -0
  33. package/src/home/run-daemon.ts +3 -1
  34. package/src/home/this-house.ts +68 -0
  35. package/src/home/via-hub.ts +2 -1
  36. package/src/hooks/commit-msg-run.ts +61 -0
  37. package/src/hooks/commit-run.ts +16 -166
  38. package/src/hooks/gate-outcome.ts +108 -0
  39. package/src/hooks/git-hook.ts +9 -9
  40. package/src/hooks/hook-config.ts +2 -1
  41. package/src/hooks/pre-commit-checks.ts +1 -1
  42. package/src/hooks/run-hooks.ts +2 -1
  43. package/src/hooks/shared-file.ts +3 -2
  44. package/src/hq/backup-targets.ts +58 -5
  45. package/src/hq/hq-local.ts +1 -1
  46. package/src/media-store/backup/bucket-target.ts +58 -0
  47. package/src/media-store/backup/target-send.ts +7 -4
  48. package/src/media-store/space.ts +2 -0
  49. package/src/plan/planner.ts +3 -2
  50. package/src/repo-config.ts +8 -1
  51. package/src/review/answer-kinds.ts +2 -0
  52. package/src/review/cells.ts +40 -9
  53. package/src/review/format.ts +1 -1
  54. package/src/review/model.ts +3 -3
  55. package/src/review/routes.ts +2 -28
  56. package/src/review/store-parties.ts +28 -0
  57. package/src/review/store.ts +11 -2
  58. package/src/review/thread-state.ts +9 -3
  59. package/src/scaffold/project-scaffold.ts +2 -2
  60. package/src/secrets/copy.ts +4 -4
  61. package/src/serve/hub-app/auto-text.tsx +3 -1
  62. package/src/serve/hub-app/dock-st.ts +1 -1
  63. package/src/serve/hub-app/review/question-views.tsx +28 -17
  64. package/src/serve/hub-app/review/review-host.ts +6 -2
  65. package/src/serve/hub-app/review/review-list.tsx +8 -5
  66. package/src/serve/hub-app/review/review-st.ts +2 -2
  67. package/src/serve/hub-app/review/review-thread.tsx +2 -1
  68. package/src/serve/hub-app/review/review-views.tsx +10 -7
  69. package/src/serve/hub-app/review/thread-st.ts +25 -11
  70. package/src/serve/hub-app/review/tone-bar.tsx +29 -24
  71. package/src/serve/hub-app/review/tones.ts +18 -0
  72. package/src/serve/hub-app/review.css +11 -2
  73. package/src/setup-house.ts +1 -7
  74. package/src/shot/client.ts +2 -1
  75. package/src/shot/on-place.ts +141 -0
  76. package/src/start-repo.ts +27 -30
@@ -0,0 +1,141 @@
1
+ // sk shot --on <place>: a still or a clip shot on another place of the house, in that machine's own warm browser, the
2
+ // file brought back here. The place runs its own plain `sk shot` over ssh from its house checkout (core/peer-sk.ts,
3
+ // the reach `sk secret copy` uses), writing under its /tmp; each file comes back on ssh's stdout and leaves there.
4
+ // The one constraint a reader breaks first: the url is the place's own, so its localhost is that machine's, and a path
5
+ // of this machine is no url there
6
+ import { randomBytes } from 'crypto'
7
+ import { mkdirSync, writeFileSync } from 'fs'
8
+ import { dirname } from 'path'
9
+ import { peerSk, shq } from '../core/peer-sk.ts'
10
+ import { DEFAULT_FPS, DEFAULT_VIEWPORT, DEFAULT_WAIT_MS, MAX_CLIP_SECONDS, isClip, type ClipAsk, type ShotAsk } from './shot-ask.ts'
11
+ import type { ShotResult } from './client.ts'
12
+ import { assertStills, tileOut } from './still-file.ts'
13
+
14
+ /** a place as the hq last heard it: its name, its live daemon's user, tailnet name, shipkit, its global processes */
15
+ export type PlaceFacts = { name: string; nodes: { osUser: string; ended: number | null; seen: number; report: { at: number; body: { version: string; tailnet: { name: string | null }; processes?: { id: string; state: string }[] } } | null }[] }
16
+
17
+ /** where the shot runs: `host` is what ssh reaches, `seen` the time of its last report */
18
+ export type Place = { name: string; host: string; version: string; seen: number }
19
+
20
+ export type PlaceLook = { here: string; machines: readonly PlaceFacts[] | { refused: string }; sshAlias: (name: string) => boolean; now: number }
21
+
22
+ const ago = (ms: number): string => (ms < 90_000 ? `${Math.round(ms / 1000)} s` : ms < 5_400_000 ? `${Math.round(ms / 60_000)} min` : `${Math.round(ms / 3_600_000)} h`)
23
+
24
+ /** the place `name` names: 'here' for this machine, else the place or the one line that refuses it */
25
+ export function placeOf(name: string, l: PlaceLook): Place | 'here' | { refused: string } {
26
+ const same = (a: string): boolean => a.toLowerCase() === name.toLowerCase()
27
+ if (same(l.here)) return 'here'
28
+ if ('refused' in l.machines) return { refused: `FAIL shot --on ${name}: the hq does not answer (${l.machines.refused}), so no place is known: sk machines` }
29
+ const m = l.machines.find((x) => same(x.name))
30
+ if (m == null) {
31
+ if (l.sshAlias(name))
32
+ return { refused: `FAIL shot --on ${name}: ${name} is reached by ssh but is no place of the house (no shipkit daemon there reports to the hq), so no shot service runs on it. A repo whose repo.config.ts names it in browsers.box already films there with a plain sk shot` }
33
+ return { refused: `FAIL shot --on ${name}: no place of that name; the places the hq knows: ${l.machines.map((x) => x.name).join(', ') || 'none'} (sk machines)` }
34
+ }
35
+ const n = m.nodes.filter((x) => x.ended == null && x.report != null).sort((a, b) => b.seen - a.seen)[0]
36
+ if (n == null || n.report == null) return { refused: `FAIL shot --on ${m.name}: no daemon of ${m.name} reports to the hq any more: sk machines` }
37
+ const procs = n.report.body.processes
38
+ if (procs != null && !procs.some((p) => p.id === 'shot')) return { refused: `FAIL shot --on ${m.name}: pm on ${m.name} knows no shot service (shipkit ${n.report.body.version}): sk fleet update --place ${m.name}` }
39
+ const host = `${n.osUser}@${l.sshAlias(m.name) ? m.name : (n.report.body.tailnet.name ?? m.name)}`
40
+ return { name: m.name, host, version: n.report.body.version, seen: n.report.at }
41
+ }
42
+
43
+ /** the place's own `sk shot` words for the ask, its file at `out` there; a default left out, so an older shipkit
44
+ * takes every ask it can */
45
+ export function placeArgs(a: ShotAsk | ClipAsk, out: string): string[] {
46
+ const w = ['shot', a.url]
47
+ if (a.viewport.width !== DEFAULT_VIEWPORT.width || a.viewport.height !== DEFAULT_VIEWPORT.height) w.push('--viewport', `${a.viewport.width},${a.viewport.height}`)
48
+ if (a.dpr !== 1) w.push('--dpr', String(a.dpr))
49
+ if (a.waitMs !== DEFAULT_WAIT_MS) w.push('--wait', String(a.waitMs))
50
+ if (a.reload) w.push('--reload')
51
+ if (a.theme != null) w.push('--theme', a.theme)
52
+ if (a.step != null) w.push('--step', a.step)
53
+ if (isClip(a)) {
54
+ w.push('--video', String(a.seconds))
55
+ if (a.seconds > MAX_CLIP_SECONDS) w.push('--long')
56
+ if (a.fps !== DEFAULT_FPS) w.push('--fps', String(a.fps))
57
+ if (a.dom) w.push('--dom')
58
+ } else {
59
+ if (a.at != null && a.step != null) w.push('--at', String(a.at))
60
+ if (a.full === true) w.push('--full')
61
+ }
62
+ w.push('--out', out, '--json')
63
+ return w
64
+ }
65
+
66
+ export type Ran = { code: number; out: Uint8Array; err: string }
67
+ /** one command on the place; a test passes a fake place */
68
+ export type Ssh = (host: string, command: string) => Promise<Ran>
69
+
70
+ const lastLine = (s: string): string => s.trim().split('\n').filter(Boolean).at(-1) ?? ''
71
+
72
+ /** the one line a failed run on the place says, with the fix */
73
+ export function placeRefusal(p: Place, r: { code: number; out: string; err: string }, houseRel: string, now: number): string {
74
+ const said = lastLine(r.err) || lastLine(r.out) || `exit ${r.code}`
75
+ const at = `FAIL shot --on ${p.name}`
76
+ if (r.code === 255) return `${at}: ${p.name} does not answer ssh at ${p.host} (${said}); its daemon last reported ${ago(now - p.seen)} ago: is it on and on the tailnet? sk machines`
77
+ if (r.code === 127 || /sk: (command )?not found/.test(r.err)) return `${at}: ${p.name} has no sk on the PATH of an ssh shell ($HOME/.local/bin, $HOME/.bun/bin): run bun run relink in its house checkout`
78
+ if (/cd: .*(No such file|not a directory|can't cd)/i.test(r.err)) return `${at}: ${p.name} has no house checkout at ~/${houseRel}, where this machine has its own`
79
+ if (/Unknown Syntax Error|Unsupported option|Command not found/i.test(`${r.err}\n${r.out}`))
80
+ return `${at}: ${p.name} runs shipkit ${p.version}, whose sk shot does not take this ask (${said}): sk fleet update --place ${p.name}`
81
+ return `${at}: ${said.replace(/^FAIL (shot: )?/, '')}`
82
+ }
83
+
84
+ /** the ask shot on the place, each file it wrote brought back to `a.out` (its tiles beside it), and removed there */
85
+ export async function shotOnPlace(p: Place, a: ShotAsk | ClipAsk, o: { ssh: Ssh; houseRel: string; say?: (l: string) => void; now?: () => number }): Promise<ShotResult & { on: string }> {
86
+ const ext = /\.[^./]+$/.exec(a.out)?.[0] ?? (isClip(a) ? '.mp4' : '.webp')
87
+ const there = `/tmp/sk-shot-on-${randomBytes(6).toString('hex')}${ext}`
88
+ const text = (b: Uint8Array): string => new TextDecoder().decode(b)
89
+ const r = await o.ssh(p.host, peerSk(o.houseRel, placeArgs(a, there).map(shq).join(' ')))
90
+ const out = text(r.out)
91
+ if (r.code !== 0) throw new Error(placeRefusal(p, { code: r.code, out, err: r.err }, o.houseRel, (o.now ?? Date.now)()))
92
+ for (const l of r.err.split('\n').filter(Boolean)) o.say?.(`${p.name}: ${l}`)
93
+ let done: ShotResult
94
+ try {
95
+ done = JSON.parse(lastLine(out)) as ShotResult
96
+ } catch {
97
+ throw new Error(`FAIL shot --on ${p.name}: its sk shot answered no json (${lastLine(out) || 'nothing'}): shipkit ${p.version} there, sk fleet update --place ${p.name}`)
98
+ }
99
+ const files = done.tiles ?? [done.out]
100
+ const here = (f: string): string => {
101
+ if (f === there) return a.out
102
+ for (let n = 1; n <= files.length; n++) if (f === tileOut(there, n)) return tileOut(a.out, n)
103
+ throw new Error(`FAIL shot --on ${p.name}: it wrote ${f}, not the file it was asked for (${there})`)
104
+ }
105
+ const brought: string[] = []
106
+ for (const f of files) {
107
+ const to = here(f)
108
+ const got = await o.ssh(p.host, `cat ${shq(f)} && rm -f ${shq(f)}`)
109
+ if (got.code !== 0) throw new Error(`FAIL shot --on ${p.name}: its file ${f} did not come back (${lastLine(got.err) || `exit ${got.code}`})`)
110
+ mkdirSync(dirname(to), { recursive: true })
111
+ writeFileSync(to, got.out)
112
+ brought.push(to)
113
+ }
114
+ if (!isClip(a)) assertStills(brought)
115
+ return { ...done, out: brought[0] ?? a.out, ...(done.tiles != null ? { tiles: brought } : {}), on: p.name }
116
+ }
117
+
118
+ /** the place this machine sees under `name`, from the hq's machines and ssh's own config; 'here' for this machine */
119
+ export async function lookPlace(name: string): Promise<Place | 'here' | { refused: string }> {
120
+ const { machineName } = await import('../core/machine-name.ts')
121
+ const { machinesPage } = await import('../hq/hq-local.ts')
122
+ const page = await machinesPage(1)
123
+ // a Host block names it when ssh's resolved config for it differs from a name no block matches (its own names apart)
124
+ const resolved = (n: string): string | null => {
125
+ const g = Bun.spawnSync(['ssh', '-G', n], { stdout: 'pipe', stderr: 'ignore' })
126
+ return g.exitCode !== 0 ? null : g.stdout.toString().split('\n').filter((l) => !/^host(name)? /.test(l)).join('\n')
127
+ }
128
+ const plain = resolved('sk-no-such-host.invalid')
129
+ const sshAlias = (n: string): boolean => {
130
+ const g = Bun.spawnSync(['ssh', '-G', n], { stdout: 'pipe', stderr: 'ignore' })
131
+ const host = /^hostname (.+)$/m.exec(g.stdout.toString())?.[1]?.trim()
132
+ return g.exitCode === 0 && ((host != null && host.toLowerCase() !== n.toLowerCase()) || (plain != null && resolved(n) !== plain))
133
+ }
134
+ return placeOf(name, { here: machineName(), machines: 'refused' in page ? page : page.machines, sshAlias, now: Date.now() })
135
+ }
136
+
137
+ /** the ssh every place is reached by: one connection kept a while, so bringing the file back pays no second handshake */
138
+ export const placeSsh: Ssh = async (host, command) => {
139
+ const { houseSsh } = await import('../media-store/backup/ssh-target.ts')
140
+ return houseSsh(host, command)
141
+ }
package/src/start-repo.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // `shipkit start` — ensure <root>/<name> exists and that CLAUDE.md carries
2
- // its include lines (in order, at the top): the HOUSE lines below, unless
3
- // --include overrides them or the house index is not on this disk, then
2
+ // its include lines (in order, at the top): the house's own lines, unless
3
+ // --include overrides them or this machine has no house, then
4
4
  // `@./agent/index.md` whenever the repo has that file, because the scaffold
5
5
  // writes it and SK003 fails a repo that has it unrouted. Plain module behind
6
6
  // cmd_Start. Status lines go to STDERR —
@@ -9,9 +9,10 @@
9
9
  // for its parent shell).
10
10
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
11
11
  import { homedir } from 'os'
12
- import { dirname, join } from 'path'
12
+ import { join } from 'path'
13
13
  import { ensureGitRepo, ensureIgnoreBaseline, firstGhLine, isScratch, publishRepo, runner, type Run } from './git-bootstrap.ts'
14
14
  import { initRepo } from './init-repo.ts'
15
+ import { houseLine, isStarterHouse, reposRoot, thisHouse } from './home/this-house.ts'
15
16
  import { AGENT_LINE } from './checks/SK003-claude-md-shape.check.ts'
16
17
  import { writeContextLine } from './context/context-line.ts'
17
18
  import { writeProjectContext } from './context/project-context.ts'
@@ -19,36 +20,31 @@ import { adoptCli, adoptHouse, installedLib, scaffoldProject, TOOLCHAIN } from '
19
20
  import { kitInstalled } from './scaffold/cli-skeleton.ts'
20
21
  import { defaultHubPort } from './http/hub-port.ts'
21
22
 
22
- /** the one template: `shipkit start <name>` is the only thing anyone types,
23
- * and a repo without the house wiki in its context is not a started repo.
24
- * Base context first, the repo's own router last, so repo docs override.
25
- * A public repo swaps line 1 for the gitignored `@./CLAUDE.local.md`,
23
+ /** the lines of a started repo: the house of this machine first (home/this-house.ts), the repo's own router last, so
24
+ * repo docs override. A public repo swaps line 1 for the gitignored `@./CLAUDE.local.md`,
26
25
  * which is why that line satisfies the first include (SK003) */
27
- // sk-disable-next-line RV003, SK035 -- the start template writes the house include line itself
28
- export const HOUSE_INCLUDE = ['@~/dev/corvion/wiki/index.md', '@./agent/index.md']
26
+ export const houseInclude = (house: string, home: string): string[] => [houseLine(house, home), AGENT_LINE]
27
+ /** whether a start writes the .claude/ policy files, a pre-approved shell allowlist among them: for include lines the
28
+ * caller typed, and for a house its owner wrote; a house `sk setup` made chose no policy, so it widens no permission */
29
+ export const writesPolicy = (o: { include?: readonly string[] | undefined; house: string | null }): boolean => (o.include != null ? o.include.length > 0 : o.house != null && !isStarterHouse(o.house))
30
+
29
31
  export const HOUSE_ALSO_OK = ['@./CLAUDE.local.md']
30
32
  /** a repo shipkit never touches: no CLAUDE.md, no git, no scaffold, no push */
31
33
  export const isSkipped = (name: string, skip: readonly string[]): boolean => skip.includes(name)
32
34
 
33
35
  /** the repo names the house config lists under `start.skip` (a day-job checkout belongs there), [] with no house:
34
36
  * the names live on the machine, never in this published lib */
35
- export async function houseSkip(home: string): Promise<string[]> {
36
- const root = dirname(dirname(housePath(home)))
37
- if (!existsSync(join(root, 'repo.config.ts'))) return []
37
+ export async function houseSkip(home: string, root?: string): Promise<string[]> {
38
+ const house = thisHouse({ home, ...(root != null ? { root } : {}) })
39
+ if (house == null) return []
38
40
  const { loadRepoConfig } = await import('./repo-config.ts')
39
- return [...((await loadRepoConfig(root)).start?.skip ?? [])]
40
- }
41
-
42
- /** where the first house line points, `~` resolved against `home` */
43
- export const housePath = (home: string): string => {
44
- const p = HOUSE_INCLUDE[0]!.replace(/^@/, '')
45
- return p.startsWith('~/') ? join(home, p.slice(2)) : p
41
+ return [...((await loadRepoConfig(house)).start?.skip ?? [])]
46
42
  }
47
43
 
48
44
  export type StartOpts = {
49
- /** parent dir for repos — default ~/dev */
45
+ /** parent dir for repos — default the house's own folder, ~/dev with no house */
50
46
  root?: string
51
- /** lines CLAUDE.md must carry, in order; omitted = HOUSE_INCLUDE. An empty list means no house: only the agent route lands */
47
+ /** lines CLAUDE.md must carry, in order; omitted = the house of this machine, then the agent route. An empty list means no house: only the agent route lands */
52
48
  include?: string[]
53
49
  /** alternative lines that satisfy the FIRST include — never double-add; omitted = HOUSE_ALSO_OK */
54
50
  alsoOk?: string[]
@@ -74,20 +70,21 @@ export async function startRepo(name: string, opts: StartOpts = {}): Promise<num
74
70
  return 2
75
71
  }
76
72
  const home = opts.home ?? homedir()
77
- const dir = join(opts.root ?? join(home, 'dev'), name)
73
+ const found = thisHouse({ home, ...(opts.root != null ? { root: opts.root } : {}) })
74
+ const root = opts.root ?? reposRoot(found, home)
75
+ const dir = join(root, name)
78
76
  const justCreated = !existsSync(dir)
79
77
  if (justCreated) {
80
78
  mkdirSync(dir, { recursive: true })
81
79
  console.error(`ok: created ${dir}`)
82
80
  }
83
- // flags win, else the house, and only on a machine that HAS the house:
84
- // this lib is on npm, so elsewhere the template would be an include
81
+ // flags win, else the house, and only on a machine that HAS one:
82
+ // elsewhere the template would be an include
85
83
  // pointing at nothing plus the widened agent permissions riding on it
86
- const houseOnDisk = existsSync(housePath(home))
87
- const house = opts.include ?? (houseOnDisk ? HOUSE_INCLUDE : [])
88
- if (opts.include == null && !houseOnDisk) console.error(`skip: no house wiki at ${housePath(home)} — CLAUDE.md gets the agent route only, and no .claude/ policy files`)
84
+ const house = opts.include ?? (found != null ? houseInclude(found, home) : [])
85
+ if (opts.include == null && found == null) console.error('skip: no house on this machine (`sk setup` makes one): CLAUDE.md gets the agent route only, and no .claude/ policy files')
89
86
  const alt = opts.alsoOk ?? HOUSE_ALSO_OK
90
- const skipped = isSkipped(name, opts.skip ?? (houseOnDisk ? await houseSkip(home) : []))
87
+ const skipped = isSkipped(name, opts.skip ?? (found != null ? await houseSkip(home, root) : []))
91
88
  if (skipped && house.length > 0) console.error(`skip: ${name} is include-exempt — CLAUDE.md untouched`)
92
89
  // start is the from-anywhere verb, and a STARTED repo comes out READY:
93
90
  // any dir with no commit history gets a minimal package.json, a first
@@ -156,7 +153,7 @@ export async function startRepo(name: string, opts: StartOpts = {}): Promise<num
156
153
  // installed lib carries the kit its entry imports
157
154
  const kit = kitInstalled(installedLib(dir))
158
155
  if (kit === false) console.error(`skip: project CLI — the installed rvlib-shipkit ${installedLib(dir)?.version ?? ''} predates the CLI kit: \`sk start ${name} --cli\` once a release carries it`)
159
- try { scaffoldProject(dir, { name, port: defaultHubPort(name), print, claudePolicy: house.length > 0, projectCli: kit !== false }) }
156
+ try { scaffoldProject(dir, { name, port: defaultHubPort(name), print, claudePolicy: writesPolicy({ include: opts.include, house: found }), projectCli: kit !== false }) }
160
157
  catch (e) { console.error(`WARN scaffold incomplete in ${dir}: ${e instanceof Error ? e.message : String(e)} — the dir is still yours`) }
161
158
  await linkBin(dir, bun)
162
159
  }
@@ -173,7 +170,7 @@ export async function startRepo(name: string, opts: StartOpts = {}): Promise<num
173
170
  if (cliWritten) await linkBin(dir, bun)
174
171
  }
175
172
  if (wired && !startable && house.length > 0) {
176
- try { adoptHouse(dir, { name, print, cli: cliWritten }) }
173
+ try { adoptHouse(dir, { name, print, cli: cliWritten, claudePolicy: writesPolicy({ include: opts.include, house: found }) }) }
177
174
  catch (e) { console.error(`WARN could not seed the house files in ${dir}: ${e instanceof Error ? e.message : String(e)} — the dir is still yours`) }
178
175
  }
179
176
  let unscaffolded = false