rvlib-shipkit 2.19.0 → 2.21.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 (196) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/package.json +1 -1
  3. package/src/annex/annex.ts +227 -0
  4. package/src/annex/offload.ts +279 -0
  5. package/src/checks/SK004-gitignore-policy.check.ts +6 -3
  6. package/src/checks/SK040-release-words.check.ts +43 -0
  7. package/src/checks/SK041-annex-links.check.ts +28 -0
  8. package/src/checks/SK042-post-kinds.check.ts +73 -0
  9. package/src/cli/cmd_Annex.ts +179 -0
  10. package/src/cli/cmd_Commands.ts +4 -1
  11. package/src/cli/cmd_GlobalProcesses.ts +2 -107
  12. package/src/cli/cmd_Home.ts +4 -3
  13. package/src/cli/cmd_Messages.ts +155 -0
  14. package/src/cli/cmd_Overview.ts +2 -1
  15. package/src/cli/cmd_Releases.ts +84 -0
  16. package/src/cli/cmd_Review.ts +176 -12
  17. package/src/cli/cmd_Shot.ts +4 -4
  18. package/src/cli/cmd_Social.ts +151 -8
  19. package/src/cli/cmd_Sound.ts +17 -4
  20. package/src/cli/cmd_Trailer.ts +67 -1
  21. package/src/cli/family-pages.ts +2 -0
  22. package/src/cli/kit/index.ts +1 -1
  23. package/src/cli/kit/verb.ts +11 -3
  24. package/src/cli/registry.ts +7 -1
  25. package/src/collections/collection-types.ts +8 -1
  26. package/src/collections/providers.ts +4 -1
  27. package/src/collections/review.ts +23 -4
  28. package/src/commands/model.ts +36 -0
  29. package/src/commands/registry.ts +49 -0
  30. package/src/commands/routes.ts +59 -0
  31. package/src/commands/runner.ts +35 -0
  32. package/src/commands/runs.ts +112 -0
  33. package/src/core/app-icon.ts +4 -3
  34. package/src/core/icon-type.ts +8 -0
  35. package/src/core/jobs.ts +4 -3
  36. package/src/core/layout.ts +11 -2
  37. package/src/core/squircle.ts +95 -0
  38. package/src/home/daemon-jobs.ts +26 -2
  39. package/src/home/global-units.ts +3 -0
  40. package/src/home/gui-app/ShipkitGui.swift +337 -5
  41. package/src/home/gui-app.ts +64 -33
  42. package/src/home/hmr-keep.ts +134 -0
  43. package/src/home/home-start.ts +2 -2
  44. package/src/home/lib-watch.ts +21 -11
  45. package/src/home/pm-switch.ts +112 -0
  46. package/src/home/pm.ts +1 -1
  47. package/src/home/process-apps.ts +181 -0
  48. package/src/home/resources.ts +3 -3
  49. package/src/home/run-web.ts +7 -4
  50. package/src/home/serve-web.ts +64 -14
  51. package/src/identities/collection.ts +49 -0
  52. package/src/identities/identities.ts +121 -14
  53. package/src/identities/machine.ts +4 -3
  54. package/src/identities/rating.ts +33 -0
  55. package/src/identities/shown.ts +170 -0
  56. package/src/identities/steps.ts +5 -0
  57. package/src/media-store/purge.ts +15 -1
  58. package/src/media-store/remote.ts +22 -6
  59. package/src/messages/brief.ts +117 -0
  60. package/src/messages/collection.ts +40 -0
  61. package/src/messages/model.ts +171 -0
  62. package/src/messages/routes.ts +15 -0
  63. package/src/messages/score.ts +182 -0
  64. package/src/messages/tabs.ts +13 -0
  65. package/src/release/notes.ts +130 -0
  66. package/src/release/run-bump.ts +41 -18
  67. package/src/release/run-release.ts +22 -4
  68. package/src/release/run-releases.ts +17 -15
  69. package/src/release/unit-resolve.ts +9 -0
  70. package/src/releases/add.ts +94 -0
  71. package/src/releases/before.ts +31 -0
  72. package/src/releases/collection.ts +36 -0
  73. package/src/releases/from-card.ts +151 -0
  74. package/src/releases/model.ts +327 -0
  75. package/src/releases/pictures.ts +110 -0
  76. package/src/releases/routes.ts +36 -0
  77. package/src/releases/store.ts +71 -0
  78. package/src/repo-config.ts +5 -0
  79. package/src/review/cells.ts +0 -11
  80. package/src/review/format.ts +10 -6
  81. package/src/review/http.ts +1 -1
  82. package/src/review/model.ts +102 -3
  83. package/src/review/notes.ts +2 -48
  84. package/src/review/routes.ts +28 -10
  85. package/src/review/stage-card.ts +197 -0
  86. package/src/review/stage-routes.ts +123 -0
  87. package/src/review/store.ts +47 -1
  88. package/src/review/trailer-card.ts +99 -0
  89. package/src/review/trailer-desk.ts +76 -4
  90. package/src/review/trailer-model.ts +106 -7
  91. package/src/review/trailer-notes.ts +45 -0
  92. package/src/review/trailer-routes.ts +119 -13
  93. package/src/review/trailer-voices.ts +144 -0
  94. package/src/review/watchers.ts +58 -1
  95. package/src/serve/hub-app/app-bridge.ts +71 -0
  96. package/src/serve/hub-app/benign-errors.ts +22 -0
  97. package/src/serve/hub-app/commands/commands-page.tsx +122 -0
  98. package/src/serve/hub-app/commands/commands-st.ts +177 -0
  99. package/src/serve/hub-app/commands.css +24 -0
  100. package/src/serve/hub-app/hash-route.ts +59 -8
  101. package/src/serve/hub-app/home-st.ts +19 -2
  102. package/src/serve/hub-app/home.html +3 -0
  103. package/src/serve/hub-app/hub-app.tsx +8 -0
  104. package/src/serve/hub-app/icons.tsx +5 -0
  105. package/src/serve/hub-app/identities-view.tsx +4 -1
  106. package/src/serve/hub-app/identities.css +1 -0
  107. package/src/serve/hub-app/index.html +3 -0
  108. package/src/serve/hub-app/keys.ts +2 -2
  109. package/src/serve/hub-app/machine-st.ts +41 -10
  110. package/src/serve/hub-app/messages/messages-page.tsx +354 -0
  111. package/src/serve/hub-app/messages/messages-st.ts +74 -0
  112. package/src/serve/hub-app/messages.css +35 -0
  113. package/src/serve/hub-app/project-list.css +7 -2
  114. package/src/serve/hub-app/project-list.tsx +9 -0
  115. package/src/serve/hub-app/projects-svc.ts +16 -6
  116. package/src/serve/hub-app/releases/releases-page.tsx +187 -0
  117. package/src/serve/hub-app/releases/releases-st.ts +111 -0
  118. package/src/serve/hub-app/releases.css +52 -0
  119. package/src/serve/hub-app/repo-sections.ts +16 -2
  120. package/src/serve/hub-app/repo-st.ts +66 -10
  121. package/src/serve/hub-app/review/clip-st.ts +34 -4
  122. package/src/serve/hub-app/review/kit.tsx +3 -3
  123. package/src/serve/hub-app/review/note-place.ts +31 -0
  124. package/src/serve/hub-app/review/review-cells.tsx +27 -3
  125. package/src/serve/hub-app/review/review-st.ts +77 -2
  126. package/src/serve/hub-app/review/review-thread.tsx +9 -31
  127. package/src/serve/hub-app/review/review-views.tsx +164 -58
  128. package/src/serve/hub-app/review/thread-st.ts +108 -41
  129. package/src/serve/hub-app/review/trailer-card.tsx +187 -0
  130. package/src/serve/hub-app/review/trailer-page.tsx +92 -36
  131. package/src/serve/hub-app/review/trailer-st.ts +306 -34
  132. package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
  133. package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
  134. package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
  135. package/src/serve/hub-app/review.css +137 -6
  136. package/src/serve/hub-app/social/comms-page.tsx +65 -28
  137. package/src/serve/hub-app/social/identity-pictures.ts +46 -8
  138. package/src/serve/hub-app/social/kit.tsx +9 -6
  139. package/src/serve/hub-app/social/next-release.tsx +118 -0
  140. package/src/serve/hub-app/social/post-card.tsx +10 -2
  141. package/src/serve/hub-app/social/social-model.ts +39 -3
  142. package/src/serve/hub-app/social/social-page.tsx +179 -65
  143. package/src/serve/hub-app/social/social-st.ts +117 -27
  144. package/src/serve/hub-app/social/stage-popup.tsx +268 -0
  145. package/src/serve/hub-app/social/stage-st.ts +310 -0
  146. package/src/serve/hub-app/social/step-layout.ts +42 -0
  147. package/src/serve/hub-app/social.css +68 -1
  148. package/src/serve/hub-app/tree-build.ts +40 -1
  149. package/src/serve/hub-app/tree-svc.ts +10 -3
  150. package/src/serve/project-gutter-route.ts +12 -2
  151. package/src/serve/project-gutter.ts +4 -2
  152. package/src/serve/same-origin.ts +24 -1
  153. package/src/serve/serve-hub.ts +15 -1
  154. package/src/shipkit-files.ts +9 -7
  155. package/src/shot/box.ts +33 -12
  156. package/src/shot/client.ts +1 -1
  157. package/src/shot/shooter.ts +22 -12
  158. package/src/shot/shot-ask.ts +14 -3
  159. package/src/shot/shot.shipkit.ts +1 -1
  160. package/src/social/desk-index.ts +49 -8
  161. package/src/social/discord-layout.ts +54 -7
  162. package/src/social/drafts.ts +1 -1
  163. package/src/social/fit.ts +84 -0
  164. package/src/social/identity-words.ts +74 -0
  165. package/src/social/kind-pages.ts +41 -0
  166. package/src/social/kinds.ts +93 -0
  167. package/src/social/load.ts +125 -10
  168. package/src/social/media-limit.ts +63 -2
  169. package/src/social/presence.ts +1 -1
  170. package/src/social/publish/bluesky.ts +58 -19
  171. package/src/social/publish/index.ts +47 -6
  172. package/src/social/reach.ts +49 -0
  173. package/src/social/release-stage.ts +277 -0
  174. package/src/social/routes.ts +44 -8
  175. package/src/social/stage.ts +246 -0
  176. package/src/social/strip.ts +85 -0
  177. package/src/social/text.ts +6 -2
  178. package/src/social/unit.ts +57 -1
  179. package/src/social/writes.ts +11 -0
  180. package/src/trailer/bed.ts +111 -0
  181. package/src/trailer/build.ts +72 -40
  182. package/src/trailer/ffmpeg.ts +6 -0
  183. package/src/trailer/grammar.ts +37 -6
  184. package/src/trailer/graph.ts +12 -1
  185. package/src/trailer/public-words.ts +41 -0
  186. package/src/trailer/shot-plan.ts +75 -0
  187. package/src/trailer/shot-state.ts +191 -0
  188. package/src/trailer/sound/audio.ts +28 -0
  189. package/src/trailer/sound/brand.ts +53 -3
  190. package/src/trailer/sound/gen.ts +61 -2
  191. package/src/trailer/sound/index.ts +25 -11
  192. package/src/trailer/sound/presets.ts +86 -5
  193. package/src/trailer/sound/run.ts +1 -1
  194. package/src/trailer/sound/takes.ts +94 -0
  195. package/src/trailer/titles.ts +36 -0
  196. package/src/trailer/url.ts +1 -1
@@ -0,0 +1,49 @@
1
+ // a repo's project CLI as the hub's commands page reads it (wiki tools/shipkit/hub.md, The commands page): the `cli`
2
+ // script of its package.json, asked for its own registry (`commands --json`, guides/cli-tool). Read fresh each time,
3
+ // about 0.1 s, so the page never shows a command the CLI no longer has
4
+ import { existsSync, readFileSync } from 'node:fs'
5
+ import { join } from 'node:path'
6
+ import type { CommandRow } from '../cli/cmd_Commands.ts'
7
+
8
+ export type Registry = {
9
+ /** the binary's name, as its examples type it */
10
+ bin: string
11
+ rows: CommandRow[]
12
+ }
13
+
14
+ /** how long the registry may take before the page says so */
15
+ const READ_MS = 15_000
16
+
17
+ /** the argv that runs the repo's CLI with `words`: bun's own `run`, never a shell */
18
+ export const cliArgv = (words: readonly string[]): string[] => [process.execPath, 'run', '--silent', 'cli', ...words]
19
+
20
+ /** null when the repo has a CLI, else why it has none */
21
+ export function noCli(root: string): string | null {
22
+ const file = join(root, 'package.json')
23
+ if (!existsSync(file)) return 'no package.json, so no project CLI'
24
+ const pkg = JSON.parse(readFileSync(file, 'utf8')) as { scripts?: Record<string, unknown> }
25
+ return typeof pkg.scripts?.cli === 'string' ? null : 'no project CLI: package.json has no `cli` script (guides/cli-tool, `sk start` writes one)'
26
+ }
27
+
28
+ /** the binary's name: the first word of its usage lines */
29
+ export function binOf(rows: readonly CommandRow[]): string {
30
+ for (const r of rows) {
31
+ const w = r.usage.split(' ')[0]
32
+ if (w != null && w !== '' && w !== '$0') return w
33
+ }
34
+ return 'cli'
35
+ }
36
+
37
+ /** the CLI's registry; throws with the words the page shows */
38
+ export async function readRegistry(root: string): Promise<Registry> {
39
+ const why = noCli(root)
40
+ if (why != null) throw new Error(why)
41
+ const p = Bun.spawn(cliArgv(['commands', '--json']), { cwd: root, stdin: 'ignore', stdout: 'pipe', stderr: 'pipe', env: { ...process.env, NO_COLOR: '1' } })
42
+ const timer = setTimeout(() => p.kill(), READ_MS)
43
+ const [out, err, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited])
44
+ clearTimeout(timer)
45
+ if (code !== 0) throw new Error(`\`bun run cli commands --json\` exited ${code}: ${(err.trim() || out.trim()).split('\n').slice(-3).join(' ')}`)
46
+ let rows: CommandRow[]
47
+ try { rows = JSON.parse(out) as CommandRow[] } catch { throw new Error('`bun run cli commands --json` printed no json: the CLI is not a kit CLI (guides/cli-tool)') }
48
+ return { bin: binOf(rows), rows }
49
+ }
@@ -0,0 +1,59 @@
1
+ // the commands page's routes (wiki tools/shipkit/hub.md, The commands page): the CLI's registry with the runs, a run
2
+ // started, its log read from an offset, a run stopped. Only a path the registry lists runs, its args split as a
3
+ // shell splits them and never given to one
4
+ import { shellWords } from '../agent-time/shape.ts'
5
+ import { bad, NO_STORE } from '../review/http.ts'
6
+ import { reachOf } from '../serve/same-origin.ts'
7
+ import { type CommandsView, confirmWhy, type LogView } from './model.ts'
8
+ import { readRegistry } from './registry.ts'
9
+ import { listRuns, readLog, runView, startRun, stopRun } from './runs.ts'
10
+
11
+ const RUN = /^\/api\/commands\/runs\/([a-z0-9-]+)(\/stop)?$/
12
+ /** a sane bound on what one run takes */
13
+ const ARGS_MAX = 8000
14
+
15
+ /** the commands routes of the repo at `root`; null for any other path */
16
+ export async function commandsRoutes(root: string, req: Request, path: string): Promise<Response | null> {
17
+ if (path !== '/api/commands' && !path.startsWith('/api/commands/')) return null
18
+ try {
19
+ if (path === '/api/commands' && req.method === 'GET') {
20
+ const reach = reachOf(req)
21
+ const runs = listRuns(root)
22
+ try {
23
+ const { bin, rows } = await readRegistry(root)
24
+ return Response.json({ bin, rows, runs, reach, error: null } satisfies CommandsView, { headers: NO_STORE })
25
+ } catch (e) {
26
+ return Response.json({ bin: '', rows: [], runs, reach, error: (e as Error).message } satisfies CommandsView, { headers: NO_STORE })
27
+ }
28
+ }
29
+ if (path === '/api/commands/run' && req.method === 'POST') {
30
+ const b = (await req.json().catch(() => null)) as { path?: unknown; args?: unknown; confirmed?: unknown } | null
31
+ if (b == null || typeof b.path !== 'string') return bad('the body names no command path', 400)
32
+ const args = typeof b.args === 'string' ? b.args : ''
33
+ if (args.length > ARGS_MAX || args.includes('\0')) return bad('the args are too long, or hold a NUL', 400)
34
+ const { bin, rows } = await readRegistry(root)
35
+ const row = rows.find((r) => r.path === b.path)
36
+ if (row == null) return bad(`${bin} has no command '${b.path}'`, 404)
37
+ const reach = reachOf(req)
38
+ const why = confirmWhy(row, reach)
39
+ if (why != null && b.confirmed !== true) return Response.json({ confirm: why }, { status: 409, headers: NO_STORE })
40
+ const run = startRun(root, { bin, path: row.path, args: shellWords(args), reach })
41
+ return Response.json({ run: runView(root, run.id) }, { headers: NO_STORE })
42
+ }
43
+ const m = RUN.exec(path)
44
+ if (m != null) {
45
+ const id = m[1]!
46
+ if (m[2] != null) {
47
+ if (req.method !== 'POST') return bad('stop is a POST', 405)
48
+ return stopRun(root, id) ? Response.json({ stopped: true }, { headers: NO_STORE }) : bad(`run ${id} is not running`, 409)
49
+ }
50
+ const run = runView(root, id)
51
+ if (run == null) return bad(`no run ${id}`, 404)
52
+ const from = Number(new URL(req.url).searchParams.get('from') ?? '0')
53
+ return Response.json({ run, ...readLog(root, id, Number.isFinite(from) ? from : 0) } satisfies LogView, { headers: NO_STORE })
54
+ }
55
+ return bad(`commands: no route ${req.method} ${path}`, 404)
56
+ } catch (e) {
57
+ return bad(e, 500)
58
+ }
59
+ }
@@ -0,0 +1,35 @@
1
+ // one run of the commands page, outside the daemon: `bun runner.ts <run dir> <argv...>`. It runs the argv with its
2
+ // output into `out.log` and writes `exit.json` once it ends, so a daemon restart never loses a run or its verdict.
3
+ // Started detached (runs.ts), it leads its own process group: Stop signals the group
4
+ import { closeSync, openSync, writeSync } from 'node:fs'
5
+ import { constants } from 'node:os'
6
+ import { join } from 'node:path'
7
+ import { atomicWrite } from '../core/locked-write.ts'
8
+ import type { Exit } from '../core/jobs.ts'
9
+
10
+ /** the exit code of a run its signal ended: 128 plus the signal, as a shell says it */
11
+ export const signalCode = (signal: string | null): number => 128 + ((signal != null ? constants.signals[signal as keyof typeof constants.signals] : undefined) ?? 0)
12
+
13
+ if (import.meta.main) {
14
+ const [dir, ...argv] = process.argv.slice(2)
15
+ if (dir == null || argv.length === 0) {
16
+ console.error('usage: bun runner.ts <run dir> <argv...>')
17
+ process.exit(2)
18
+ }
19
+ // first, so a Stop sent right away still finds the runner alive to record the exit
20
+ let p: Bun.Subprocess | null = null
21
+ for (const s of ['SIGTERM', 'SIGINT', 'SIGHUP'] as const) process.on(s, () => p?.kill(s))
22
+ const out = openSync(join(dir, 'out.log'), 'a')
23
+ let code: number
24
+ try {
25
+ p = Bun.spawn(argv, { cwd: process.cwd(), stdin: 'ignore', stdout: out, stderr: out, env: process.env })
26
+ await p.exited
27
+ code = p.exitCode ?? signalCode(p.signalCode)
28
+ } catch (e) {
29
+ writeSync(out, `FAIL: ${argv[0]} did not start: ${(e as Error).message}\n`)
30
+ code = 127
31
+ }
32
+ closeSync(out)
33
+ atomicWrite(join(dir, 'exit.json'), JSON.stringify({ code, finishedAt: Date.now() } satisfies Exit))
34
+ process.exit(0)
35
+ }
@@ -0,0 +1,112 @@
1
+ // the runs of the commands page (wiki tools/shipkit/hub.md, The commands page): one folder a run under
2
+ // `.shipkit/tmp/cli-runs/<id>/`, `job.json` (who, what, when), `out.log` (its output as it prints it), `exit.json`
3
+ // (once it ended). A folder apart from the gate jobs (core/jobs.ts), whose live ones the hub reads as gates; swept
4
+ // the same way
5
+ import { spawn } from 'node:child_process'
6
+ import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, statSync } from 'node:fs'
7
+ import { join } from 'node:path'
8
+ import { fileURLToPath } from 'node:url'
9
+ import { type Exit, jobAlive, sweepJobs } from '../core/jobs.ts'
10
+ import { LAYOUT } from '../core/layout.ts'
11
+ import { atomicWrite } from '../core/locked-write.ts'
12
+ import type { Reach } from '../serve/same-origin.ts'
13
+ import { cliArgv } from './registry.ts'
14
+
15
+ export const CLI_RUNS = `${LAYOUT.tmp}/cli-runs`
16
+ const RUNNER = fileURLToPath(new URL('./runner.ts', import.meta.url))
17
+
18
+ export type CliRun = {
19
+ id: string
20
+ /** the runner's pid, its process group's id */
21
+ pid: number
22
+ /** the command's words: 'site deploy' */
23
+ path: string
24
+ args: string[]
25
+ /** the command line as he would type it */
26
+ line: string
27
+ startedAt: number
28
+ reach: Reach
29
+ }
30
+ export type RunState = 'running' | 'done' | 'lost'
31
+ export type RunView = CliRun & { exit: Exit | null; state: RunState }
32
+
33
+ /** the most log one read sends: a page catches up in a few reads */
34
+ export const LOG_CHUNK = 256 * 1024
35
+
36
+ const runDir = (root: string, id: string): string => join(root, CLI_RUNS, id)
37
+ const readJson = <T>(p: string): T | null => {
38
+ try { return JSON.parse(readFileSync(p, 'utf8')) as T } catch { return null }
39
+ }
40
+
41
+ /** a word as a shell would need it typed */
42
+ const quoted = (w: string): string => (/^[\w@%+=:,./-]+$/.test(w) ? w : `'${w.replace(/'/g, `'\\''`)}'`)
43
+ export const lineOf = (bin: string, path: string, args: readonly string[]): string => [bin, path, ...args.map(quoted)].join(' ')
44
+
45
+ let seq = 0
46
+
47
+ /** start the command detached from the daemon, and return at once */
48
+ export function startRun(root: string, o: { bin: string; path: string; args: string[]; reach: Reach }): CliRun {
49
+ sweepJobs(root, Date.now(), { dir: CLI_RUNS })
50
+ const id = `${Date.now().toString(36)}-${process.pid.toString(36)}${(seq++).toString(36)}`
51
+ const dir = runDir(root, id)
52
+ mkdirSync(dir, { recursive: true })
53
+ closeSync(openSync(join(dir, 'out.log'), 'a'))
54
+ const argv = cliArgv([...o.path.split(' '), ...o.args])
55
+ // no colour: the page shows the log as text
56
+ const child = spawn(process.execPath, [RUNNER, dir, ...argv], { cwd: root, detached: true, stdio: 'ignore', env: { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0' } })
57
+ child.unref()
58
+ const run: CliRun = { id, pid: child.pid ?? 0, path: o.path, args: o.args, line: lineOf(o.bin, o.path, o.args), startedAt: Date.now(), reach: o.reach }
59
+ atomicWrite(join(dir, 'job.json'), JSON.stringify(run))
60
+ return run
61
+ }
62
+
63
+ export function runView(root: string, id: string): RunView | null {
64
+ const run = readJson<CliRun>(join(runDir(root, id), 'job.json'))
65
+ if (run == null) return null
66
+ // alive first: a runner that ends between the two reads has written its exit by then, never lost
67
+ const alive = jobAlive(run.pid)
68
+ const exit = readJson<Exit>(join(runDir(root, id), 'exit.json'))
69
+ return { ...run, exit, state: exit != null ? 'done' : alive ? 'running' : 'lost' }
70
+ }
71
+
72
+ /** the repo's runs, newest first */
73
+ export function listRuns(root: string, max = 30): RunView[] {
74
+ let names: string[]
75
+ try { names = readdirSync(join(root, CLI_RUNS)) } catch { return [] }
76
+ return names.flatMap((n) => runView(root, n) ?? []).sort((a, b) => b.startedAt - a.startedAt).slice(0, max)
77
+ }
78
+
79
+ /** a byte count that ends on a whole utf-8 character */
80
+ export function wholeChars(buf: Uint8Array, n: number): number {
81
+ for (let k = 1; k <= Math.min(4, n); k++) {
82
+ const b = buf[n - k]!
83
+ if ((b & 0xc0) === 0x80) continue
84
+ const len = b >= 0xf0 ? 4 : b >= 0xe0 ? 3 : b >= 0xc0 ? 2 : 1
85
+ return len > k ? n - k : n
86
+ }
87
+ return n
88
+ }
89
+
90
+ /** the log from byte `from`, at most LOG_CHUNK, and where the next read starts */
91
+ export function readLog(root: string, id: string, from: number): { text: string; next: number; size: number } {
92
+ const file = join(runDir(root, id), 'out.log')
93
+ if (!existsSync(file)) return { text: '', next: from, size: 0 }
94
+ const size = statSync(file).size
95
+ const start = Math.max(0, Math.min(from, size))
96
+ const want = Math.min(LOG_CHUNK, size - start)
97
+ if (want === 0) return { text: '', next: start, size }
98
+ const buf = new Uint8Array(want)
99
+ const fd = openSync(file, 'r')
100
+ const got = readSync(fd, buf, 0, want, start)
101
+ closeSync(fd)
102
+ const n = wholeChars(buf, got)
103
+ return { text: new TextDecoder().decode(buf.subarray(0, n)), next: start + n, size }
104
+ }
105
+
106
+ /** SIGTERM to the run's process group; false when it is not running */
107
+ export function stopRun(root: string, id: string): boolean {
108
+ const v = runView(root, id)
109
+ if (v == null || v.state !== 'running') return false
110
+ try { process.kill(-v.pid, 'SIGTERM') } catch { try { process.kill(v.pid, 'SIGTERM') } catch { return false } }
111
+ return true
112
+ }
@@ -1,6 +1,7 @@
1
1
  // a repo's app icon, drawn from its mark: the mark's transparent margin is
2
2
  // cut away, and what is left sits on a rounded plate in the repo's identity
3
- // colour, on the macOS icon grid (an 824 plate on a 1024 canvas). A mark that
3
+ // colour, on the macOS icon grid (an 824 plate on a 1024 canvas, its corners
4
+ // continuous: squircle.ts). A mark that
4
5
  // already fills its box (a photo, a square tile) becomes the plate itself.
5
6
  // The app build and the page's preview both draw through appIconPngs.
6
7
  import { createCanvas, Image, type Canvas } from '@napi-rs/canvas'
@@ -9,6 +10,7 @@ import { join } from 'path'
9
10
  import { identityOfName, identityOfText, type Identity } from './identity-color.ts'
10
11
  import { configName, CONFIG_FILE } from './identity.ts'
11
12
  import { LAYOUT } from './layout.ts'
13
+ import { traceSquircle } from './squircle.ts'
12
14
 
13
15
  /** the mark an app wears: the repo's own, largest first; an svg mark is drawn
14
16
  * as an image too (the canvas decodes it) */
@@ -21,7 +23,6 @@ export function appIconOf(root: string): string | null {
21
23
 
22
24
  export const ICON_PX = 1024
23
25
  const PLATE = 824
24
- const RADIUS = 185
25
26
  /** the mark's longest side, as a share of the plate */
26
27
  const MARK = 0.7
27
28
  /** an alpha at or under this is margin, and is dropped: a generated image
@@ -93,7 +94,7 @@ async function decode(bytes: Uint8Array): Promise<Image> {
93
94
 
94
95
  function plate(ctx: ReturnType<Canvas['getContext']>, o: number): void {
95
96
  ctx.beginPath()
96
- ctx.roundRect(o, o, PLATE, PLATE, RADIUS)
97
+ traceSquircle(ctx, o, o, PLATE)
97
98
  }
98
99
 
99
100
  /** how the plate is drawn: `plateAlpha` fades the plate alone, the mark stays whole
@@ -0,0 +1,8 @@
1
+ // the image an icon names, alone in its module: pm reads it, and pm's graph stays free of the units' barrel
2
+ // (shipkit-files.ts), so an edit of a unit never restarts pm (home/lib-watch.ts)
3
+
4
+ /** the image types an icon file can be, by extension */
5
+ export const ICON_IMAGE_TYPES: Record<string, string> = { png: 'image/png', svg: 'image/svg+xml', ico: 'image/x-icon', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp' }
6
+
7
+ /** the image an icon names (its extension), or null when it is text */
8
+ export const iconImageType = (icon: string): string | null => ICON_IMAGE_TYPES[/\.([a-z]+)$/i.exec(icon)?.[1]?.toLowerCase() ?? ''] ?? null
package/src/core/jobs.ts CHANGED
@@ -167,9 +167,10 @@ export function jobStatus(root: string, id?: string): { code: number; lines: str
167
167
  }
168
168
 
169
169
  /** finished runs older than a week go, then the oldest past the count cap;
170
- * a running one never does */
171
- export function sweepJobs(root: string, now = Date.now(), o: { keepMs?: number; max?: number } = {}): void {
172
- const base = join(root, JOBS)
170
+ * a running one never does. `dir`: another repo-relative store of runs
171
+ * kept in the same shape, a folder each with its `job.json` */
172
+ export function sweepJobs(root: string, now = Date.now(), o: { keepMs?: number; max?: number; dir?: string } = {}): void {
173
+ const base = join(root, o.dir ?? JOBS)
173
174
  let dirs: { dir: string; mtime: number }[]
174
175
  try {
175
176
  dirs = readdirSync(base).flatMap((name) => {
@@ -25,6 +25,9 @@ export const LAYOUT = {
25
25
  // plans, arc boards and lane files: live state a crashed session resumes
26
26
  // from. Tracked in a private repo only, since a board quotes the owner
27
27
  plans: sk('plans'),
28
+ // the release files: next.md and one <version>.md a release, each change's picture a key in the Space, never a
29
+ // file here (wiki tools/shipkit/units.md, The release files)
30
+ releases: sk('releases'),
28
31
  // the house repo's identities, who speaks: one folder each, its accounts; the house repo tracks it with its own
29
32
  // gitignore line (wiki tools/shipkit/social.md)
30
33
  identities: sk('identities'),
@@ -34,6 +37,9 @@ export const LAYOUT = {
34
37
  // the social folder (contract v3): one folder a draft, the week's rhythm. The SK004 block re-includes it in a
35
38
  // private repo only, like plans (wiki tools/shipkit/social.md)
36
39
  social: sk('social'),
40
+ // the owner's own voice: his takes of a trailer's lines, one a text (trailer/sound/takes.ts). The SK004 block
41
+ // re-includes it in a private repo only: a recording is his voice
42
+ voice: sk('voice'),
37
43
  // local: the facts (sha, size, type) of every draft media, so a file the disk let go keeps its key in the media
38
44
  // store (wiki tools/shipkit/social.md, Media)
39
45
  socialMedia: sk('social-media.json'),
@@ -50,7 +56,10 @@ export const LAYOUT = {
50
56
  tmp: sk('tmp'),
51
57
  // a CLI's call log, `<cli>-calls.jsonl`: local, never tracked
52
58
  logs: sk('logs'),
53
- // built app bundles, one per global process opened as an app (home/gui-app.ts)
59
+ // local: what the lanes plan for each shot of a cut, `<trailer>/<cut>.json` (trailer/shot-plan.ts). It speaks of
60
+ // this machine's takes, which live in the cache, and lanes rewrite it many times an hour
61
+ trailerPlan: sk('trailer-plan'),
62
+ // holds no app: a process app lives in ~/Applications, and the apps job removes any shipkit bundle here (home/process-apps.ts)
54
63
  wrapper: sk('wrapper'),
55
64
  // generated on every run
56
65
  status: sk('STATUS.md'),
@@ -59,7 +68,7 @@ export const LAYOUT = {
59
68
  } as const
60
69
 
61
70
  /** the children the SK004 block re-includes: everything else under `.shipkit/` stays local */
62
- export const TRACKED_DIRS = [LAYOUT.asks, LAYOUT.hooks, LAYOUT.identity, LAYOUT.assets, LAYOUT.comfy, LAYOUT.repros, LAYOUT.plans] as const
71
+ export const TRACKED_DIRS = [LAYOUT.asks, LAYOUT.hooks, LAYOUT.identity, LAYOUT.assets, LAYOUT.comfy, LAYOUT.repros, LAYOUT.plans, LAYOUT.releases] as const
63
72
 
64
73
  /** a plan file name: `YYYYMMDD-HHMMSS-<slug>.md` */
65
74
  export const PLAN_FILE = /^\d{8}-\d{6}-.+\.md$/
@@ -0,0 +1,95 @@
1
+ // the macOS app icon's outline: a square whose corners are continuous (the curvature eases in, unlike a circular
2
+ // arc), Apple's grid radius 185 on an 824 plate. The cubic coefficients are the continuous corner of iOS and macOS
3
+ // (PaintCode's measure of UIBezierPath). One outline for the app icon, the hub's tiles and any art drawn to fit it.
4
+
5
+ export type Pt = { x: number; y: number }
6
+ type Cubic = { c1: Pt; c2: Pt; to: Pt }
7
+
8
+ /** the corner radius on a side of this length, on Apple's grid (185 on 824) */
9
+ export const squircleRadius = (side: number): number => (side * 185) / 824
10
+
11
+ /** the corner's reach along each edge, in radii */
12
+ const REACH = 1.52866483
13
+ type UV = [number, number]
14
+ const CORNER: [UV, UV, UV][] = [
15
+ [[1.08849296, 0], [0.86840694, 0], [0.63149399, 0.074911]],
16
+ [[0.37282383, 0.16905956], [0.16905956, 0.37282383], [0.074911, 0.63149399]],
17
+ [[0, 0.86840694], [0, 1.08849296], [0, REACH]],
18
+ ]
19
+
20
+ /** the outline from the top middle, clockwise (y down): a line then the three cubics of each corner */
21
+ export function squircle(x: number, y: number, side: number, r = squircleRadius(side)): { start: Pt; segs: (Pt | Cubic)[] } {
22
+ const c = { x: x + side / 2, y: y + side / 2 }
23
+ // the top right corner, then turned a quarter about the centre for the next three
24
+ const turn = (p: Pt, k: number): Pt => {
25
+ let dx = p.x - c.x, dy = p.y - c.y
26
+ for (let i = 0; i < k; i++) [dx, dy] = [-dy, dx]
27
+ return { x: c.x + dx, y: c.y + dy }
28
+ }
29
+ const tr = ([u, v]: [number, number]): Pt => ({ x: x + side - u * r, y: y + v * r })
30
+ const segs: (Pt | Cubic)[] = []
31
+ for (let k = 0; k < 4; k++) {
32
+ segs.push(turn({ x: x + side - REACH * r, y }, k))
33
+ for (const [a, b, e] of CORNER) segs.push({ c1: turn(tr(a), k), c2: turn(tr(b), k), to: turn(tr(e), k) })
34
+ }
35
+ segs.push({ x: c.x, y })
36
+ return { start: { x: c.x, y }, segs }
37
+ }
38
+
39
+ const isCubic = (s: Pt | Cubic): s is Cubic => 'to' in s
40
+
41
+ /** the outline traced on a canvas path (moveTo, lineTo, bezierCurveTo), closed */
42
+ export function traceSquircle(ctx: { moveTo(x: number, y: number): void; lineTo(x: number, y: number): void; bezierCurveTo(a: number, b: number, c: number, d: number, e: number, f: number): void; closePath(): void }, x: number, y: number, side: number, r?: number): void {
43
+ const { start, segs } = squircle(x, y, side, r)
44
+ ctx.moveTo(start.x, start.y)
45
+ for (const s of segs) isCubic(s) ? ctx.bezierCurveTo(s.c1.x, s.c1.y, s.c2.x, s.c2.y, s.to.x, s.to.y) : ctx.lineTo(s.x, s.y)
46
+ ctx.closePath()
47
+ }
48
+
49
+ const f = (n: number): number => +n.toFixed(2)
50
+
51
+ /** the outline as an svg path */
52
+ export function squirclePath(x: number, y: number, side: number, r?: number): string {
53
+ const { start, segs } = squircle(x, y, side, r)
54
+ return `M${f(start.x)},${f(start.y)}${segs.map((s) => (isCubic(s) ? `C${f(s.c1.x)},${f(s.c1.y)} ${f(s.c2.x)},${f(s.c2.y)} ${f(s.to.x)},${f(s.to.y)}` : `L${f(s.x)},${f(s.y)}`)).join('')}Z`
55
+ }
56
+
57
+ /** n points evenly spaced along the outline from the top middle, clockwise, each with its outward normal: what art
58
+ * that follows the outline walks (a rim, a vine) */
59
+ export function squirclePoints(x: number, y: number, side: number, n: number, r?: number): { x: number; y: number; nx: number; ny: number }[] {
60
+ const { start, segs } = squircle(x, y, side, r)
61
+ const dense: Pt[] = [start]
62
+ let at = start
63
+ for (const s of segs) {
64
+ const steps = isCubic(s) ? 64 : Math.max(1, Math.ceil(Math.hypot(s.x - at.x, s.y - at.y) / 2))
65
+ for (let i = 1; i <= steps; i++) {
66
+ const t = i / steps, u = 1 - t
67
+ dense.push(isCubic(s)
68
+ ? { x: u * u * u * at.x + 3 * u * u * t * s.c1.x + 3 * u * t * t * s.c2.x + t * t * t * s.to.x, y: u * u * u * at.y + 3 * u * u * t * s.c1.y + 3 * u * t * t * s.c2.y + t * t * t * s.to.y }
69
+ : { x: at.x + (s.x - at.x) * t, y: at.y + (s.y - at.y) * t })
70
+ }
71
+ at = isCubic(s) ? s.to : s
72
+ }
73
+ const len = [0]
74
+ for (let i = 1; i < dense.length; i++) len.push(len[i - 1]! + Math.hypot(dense[i]!.x - dense[i - 1]!.x, dense[i]!.y - dense[i - 1]!.y))
75
+ const total = len[len.length - 1]!
76
+ const pointAt = (d: number): Pt => {
77
+ d = ((d % total) + total) % total
78
+ let lo = 0, hi = len.length - 1
79
+ while (hi - lo > 1) {
80
+ const mid = (lo + hi) >> 1
81
+ if (len[mid]! <= d) lo = mid
82
+ else hi = mid
83
+ }
84
+ const t = (d - len[lo]!) / (len[hi]! - len[lo]! || 1)
85
+ return { x: dense[lo]!.x + (dense[hi]!.x - dense[lo]!.x) * t, y: dense[lo]!.y + (dense[hi]!.y - dense[lo]!.y) * t }
86
+ }
87
+ const step = total / n
88
+ return Array.from({ length: n }, (_, i) => {
89
+ const p = pointAt(i * step)
90
+ const a = pointAt(i * step - step / 2), b = pointAt(i * step + step / 2)
91
+ const tl = Math.hypot(b.x - a.x, b.y - a.y) || 1
92
+ // clockwise with y down: the outward normal is the tangent turned a quarter back
93
+ return { x: p.x, y: p.y, nx: (b.y - a.y) / tl, ny: -(b.x - a.x) / tl }
94
+ })
95
+ }
@@ -1,5 +1,5 @@
1
1
  // THE DAEMON'S BACKGROUND JOBS, OFF ITS LOOP (wiki tools/shipkit/home.md, Nothing heavy on the daemon's loop): the
2
- // backup, the retention sweep, the media store and the house's global context each run as a child process (`sk daemon job <id>`, niced), started
2
+ // backup, the retention sweep, the media store, the house's global context and the process apps each run as a child process (`sk daemon job <id>`, niced), started
3
3
  // detached with its pid in a file, its lines appended to the daemon's log. The daemon only starts it and reads the
4
4
  // pid: an in place restart adopts a child still running and never starts a second one. What a job remembers between
5
5
  // two runs lives in the machine db, so a restart never redoes a job's work.
@@ -14,8 +14,9 @@ import { BACKUP_EVERY_MS } from '../media-store/backup/daemon.ts'
14
14
  import { MEDIA_EVERY_MS } from '../media-store/daemon.ts'
15
15
  import { SWEEP_EVERY_MS, SWEPT_AT } from './machine-stores.ts'
16
16
  import { contextSourcesStamp, GLOBAL_CONTEXT_DONE, GLOBAL_CONTEXT_EVERY_MS, GLOBAL_CONTEXT_MAX_MS } from './global-context.ts'
17
+ import { APPS_DONE, APPS_EVERY_MS, appsDue, appsSourcesStamp } from './process-apps.ts'
17
18
 
18
- export type JobId = 'backup' | 'retention sweep' | 'media store' | 'global context'
19
+ export type JobId = 'backup' | 'retention sweep' | 'media store' | 'global context' | 'apps'
19
20
 
20
21
  export interface DaemonJob {
21
22
  id: JobId
@@ -39,6 +40,8 @@ export const DAEMON_JOBS: readonly DaemonJob[] = [
39
40
  { id: 'backup', everyMs: BACKUP_EVERY_MS, firstMs: BACKUP_EVERY_MS },
40
41
  // the house's generated context: its unit files are imported to be read, a second of compile the loop never pays
41
42
  { id: 'global context', everyMs: GLOBAL_CONTEXT_EVERY_MS, firstMs: 30_000, due: async (now, root) => contextDue(now, await contextSourcesStamp(root)) },
43
+ // every global process with a url as an app in ~/Applications: built when missing or stale, removed when gone (process-apps.ts)
44
+ { id: 'apps', everyMs: APPS_EVERY_MS, firstMs: 45_000, due: async (now, root) => appsDue(now, await appsSourcesStamp(root)) },
42
45
  ]
43
46
 
44
47
  /** the context is due when its sources' stamp moved since the last write, or that write is old */
@@ -194,6 +197,27 @@ export async function runJobBody(id: JobId, o: { root: string; home: string; pri
194
197
  machineSet(GLOBAL_CONTEXT_DONE, { stamp, at: Date.now() })
195
198
  return
196
199
  }
200
+ if (id === 'apps') {
201
+ const { appsDir, appsSourcesStamp, appsTick } = await import('./process-apps.ts')
202
+ const { canBuildGui, ensureWrapperApp, guiAppPath } = await import('./gui-app.ts')
203
+ const { scanGlobalUnits } = await import('./global-units.ts')
204
+ const { machineSet } = await import('../core/machine-db.ts')
205
+ const { LIB_VERSION } = await import('../core/lib-version.ts')
206
+ const stamp = await appsSourcesStamp(o.root, o.home)
207
+ const units = await scanGlobalUnits(house.repos.map((r) => ({ name: r.name, path: r.path })))
208
+ await appsTick({
209
+ processes: units.processes,
210
+ scanErrors: units.errors,
211
+ repos,
212
+ dir: appsDir(o.home),
213
+ build: canBuildGui() ? (d, dir) => ensureWrapperApp(d, { version: LIB_VERSION, dir }) : null,
214
+ reserved: [guiAppPath()],
215
+ print: o.print,
216
+ printErr: o.printErr,
217
+ })
218
+ machineSet(APPS_DONE, { stamp, at: Date.now() })
219
+ return
220
+ }
197
221
  const { sweepTick } = await import('./machine-stores.ts')
198
222
  const { homeDir } = await import('./home-paths.ts')
199
223
  const { landMotherhome } = await import('../core/motherhome.ts')
@@ -13,6 +13,8 @@ export type ActionDecl = { id: string; label: string; cmd: string[] | null }
13
13
  export type GlobalProcessDecl = {
14
14
  id: string
15
15
  label: string
16
+ /** its macOS app's name, as declared (null: the label) */
17
+ app: string | null
16
18
  description: string | null
17
19
  where: string | null
18
20
  cmd: string[]
@@ -45,6 +47,7 @@ export function toDecl(u: GlobalProcessUnit, repo: RepoRef, file: string): Globa
45
47
  return {
46
48
  id: u.id,
47
49
  label: u.label ?? u.id,
50
+ app: u.app ?? null,
48
51
  description: u.description ?? null,
49
52
  where: u.where ?? null,
50
53
  cmd: u.cmd,