rvlib-shipkit 2.18.0 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/asks/asks-queue.ts +63 -10
- package/src/checks/SK040-release-words.check.ts +43 -0
- package/src/checks/SK041-annex-links.check.ts +28 -0
- package/src/checks/SK042-post-kinds.check.ts +73 -0
- package/src/cli/cmd_Annex.ts +179 -0
- package/src/cli/cmd_Asks.ts +3 -1
- package/src/cli/cmd_Commands.ts +4 -1
- package/src/cli/cmd_GlobalProcesses.ts +34 -11
- package/src/cli/cmd_Home.ts +41 -4
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Releases.ts +48 -0
- package/src/cli/cmd_Review.ts +161 -6
- package/src/cli/cmd_Secret.ts +4 -30
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +179 -3
- package/src/cli/cmd_Trailer.ts +15 -3
- package/src/cli/family-pages.ts +2 -0
- package/src/cli/kit/index.ts +1 -1
- package/src/cli/kit/verb.ts +11 -3
- package/src/cli/registry.ts +8 -2
- package/src/collections/actions.ts +29 -1
- package/src/collections/collection-types.ts +10 -1
- package/src/collections/providers.ts +5 -2
- package/src/commands/model.ts +36 -0
- package/src/commands/registry.ts +49 -0
- package/src/commands/routes.ts +59 -0
- package/src/commands/runner.ts +35 -0
- package/src/commands/runs.ts +112 -0
- package/src/core/app-icon.ts +4 -3
- package/src/core/icon-type.ts +8 -0
- package/src/core/jobs.ts +4 -3
- package/src/core/layout.ts +5 -2
- package/src/core/squircle.ts +95 -0
- package/src/home/daemon-jobs.ts +26 -2
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +302 -5
- package/src/home/gui-app.ts +63 -33
- package/src/home/hmr-keep.ts +134 -0
- package/src/home/home-paths.ts +5 -1
- package/src/home/home-start.ts +14 -14
- package/src/home/lib-watch.ts +21 -11
- package/src/home/pm.ts +1 -1
- package/src/home/process-apps.ts +181 -0
- package/src/home/resources.ts +3 -3
- package/src/home/run-daemon.ts +11 -2
- package/src/home/run-pm.ts +9 -1
- package/src/home/run-web.ts +7 -4
- package/src/home/serve-web.ts +64 -14
- package/src/home/supervise.ts +3 -1
- package/src/identities/collection.ts +49 -0
- package/src/identities/identities.ts +130 -11
- package/src/identities/machine.ts +4 -3
- package/src/identities/rating.ts +33 -0
- package/src/identities/shown.ts +170 -0
- package/src/identities/steps.ts +5 -0
- package/src/media-store/purge.ts +15 -1
- package/src/media-store/remote.ts +22 -6
- package/src/messages/brief.ts +117 -0
- package/src/messages/collection.ts +40 -0
- package/src/messages/model.ts +171 -0
- package/src/messages/routes.ts +15 -0
- package/src/messages/score.ts +180 -0
- package/src/messages/tabs.ts +13 -0
- package/src/release/notes.ts +130 -0
- package/src/release/run-bump.ts +41 -18
- package/src/release/run-release.ts +22 -4
- package/src/release/run-releases.ts +17 -15
- package/src/release/unit-resolve.ts +9 -0
- package/src/releases/add.ts +66 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +66 -0
- package/src/releases/model.ts +267 -0
- package/src/releases/pictures.ts +89 -0
- package/src/releases/routes.ts +36 -0
- package/src/releases/store.ts +71 -0
- package/src/repo-config.ts +5 -0
- package/src/review/cells.ts +0 -11
- package/src/review/format.ts +10 -6
- package/src/review/http.ts +7 -2
- package/src/review/model.ts +92 -3
- package/src/review/notes.ts +2 -48
- package/src/review/routes.ts +28 -10
- package/src/review/stage-card.ts +197 -0
- package/src/review/stage-routes.ts +123 -0
- package/src/review/store.ts +117 -19
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +57 -4
- package/src/review/trailer-model.ts +41 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +22 -13
- package/src/secrets/manager.ts +59 -0
- package/src/secrets/name.ts +2 -0
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/col-card.tsx +10 -0
- package/src/serve/hub-app/cols-svc.ts +37 -6
- package/src/serve/hub-app/commands/commands-page.tsx +122 -0
- package/src/serve/hub-app/commands/commands-st.ts +177 -0
- package/src/serve/hub-app/commands.css +24 -0
- package/src/serve/hub-app/hash-route.ts +40 -1
- package/src/serve/hub-app/home-st.ts +11 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +6 -0
- package/src/serve/hub-app/hub.css +1 -0
- package/src/serve/hub-app/icons.tsx +5 -0
- package/src/serve/hub-app/identities-view.tsx +4 -1
- package/src/serve/hub-app/identities.css +1 -0
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +2 -2
- package/src/serve/hub-app/machine-st.ts +41 -10
- package/src/serve/hub-app/messages/messages-page.tsx +354 -0
- package/src/serve/hub-app/messages/messages-st.ts +74 -0
- package/src/serve/hub-app/messages.css +35 -0
- package/src/serve/hub-app/releases/releases-page.tsx +94 -0
- package/src/serve/hub-app/releases/releases-st.ts +69 -0
- package/src/serve/hub-app/releases.css +25 -0
- package/src/serve/hub-app/repo-sections.ts +15 -1
- package/src/serve/hub-app/repo-st.ts +56 -5
- package/src/serve/hub-app/review/clip-st.ts +31 -3
- package/src/serve/hub-app/review/note-place.ts +31 -0
- package/src/serve/hub-app/review/review-cells.tsx +27 -3
- package/src/serve/hub-app/review/review-st.ts +77 -2
- package/src/serve/hub-app/review/review-thread.tsx +9 -31
- package/src/serve/hub-app/review/review-views.tsx +164 -58
- package/src/serve/hub-app/review/thread-st.ts +108 -41
- package/src/serve/hub-app/review/trailer-card.tsx +187 -0
- package/src/serve/hub-app/review/trailer-page.tsx +62 -31
- package/src/serve/hub-app/review/trailer-st.ts +138 -26
- package/src/serve/hub-app/review/trailer-timeline.tsx +39 -26
- package/src/serve/hub-app/review.css +49 -6
- package/src/serve/hub-app/social/comms-page.tsx +55 -23
- package/src/serve/hub-app/social/identity-pictures.ts +112 -0
- package/src/serve/hub-app/social/kit.tsx +9 -6
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +37 -3
- package/src/serve/hub-app/social/social-page.tsx +236 -82
- package/src/serve/hub-app/social/social-st.ts +79 -26
- package/src/serve/hub-app/social/stage-popup.tsx +268 -0
- package/src/serve/hub-app/social/stage-st.ts +310 -0
- package/src/serve/hub-app/social/step-layout.ts +42 -0
- package/src/serve/hub-app/social.css +68 -4
- package/src/serve/hub-app/tree-build.ts +38 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +4 -2
- package/src/serve/same-origin.ts +24 -1
- package/src/serve/serve-hub.ts +27 -3
- package/src/shipkit-files.ts +9 -7
- package/src/shot/shooter.ts +3 -3
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/discord-layout.ts +282 -0
- package/src/social/fit.ts +84 -0
- package/src/social/identity-words.ts +74 -0
- package/src/social/kind-pages.ts +41 -0
- package/src/social/kinds.ts +92 -0
- package/src/social/load.ts +105 -9
- package/src/social/md.ts +14 -6
- package/src/social/media-limit.ts +63 -2
- package/src/social/presence.ts +1 -1
- package/src/social/publish/bluesky.ts +58 -19
- package/src/social/publish/discord.ts +3 -2
- package/src/social/publish/index.ts +31 -5
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +173 -0
- package/src/social/routes.ts +44 -9
- package/src/social/stage.ts +227 -0
- package/src/social/strip.ts +85 -0
- package/src/social/text.ts +6 -2
- package/src/social/unit.ts +57 -1
- package/src/social/writes.ts +11 -0
- package/src/stores/routes.ts +2 -2
- package/src/suite/judge-suites.ts +1 -1
- package/src/suite/suite-cli.ts +5 -5
- package/src/trailer/build.ts +90 -52
- package/src/trailer/draft.ts +28 -0
- package/src/trailer/footage.ts +4 -2
- package/src/trailer/grammar.ts +25 -13
- package/src/trailer/graph.ts +32 -9
- package/src/trailer/profile.ts +35 -0
- package/src/trailer/prune.ts +15 -10
- package/src/trailer/public-words.ts +41 -0
- package/src/trailer/stitch.ts +22 -10
- package/src/trailer/titles.ts +47 -2
|
@@ -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
|
+
}
|
package/src/core/app-icon.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
172
|
-
|
|
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) => {
|
package/src/core/layout.ts
CHANGED
|
@@ -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'),
|
|
@@ -50,7 +53,7 @@ export const LAYOUT = {
|
|
|
50
53
|
tmp: sk('tmp'),
|
|
51
54
|
// a CLI's call log, `<cli>-calls.jsonl`: local, never tracked
|
|
52
55
|
logs: sk('logs'),
|
|
53
|
-
//
|
|
56
|
+
// holds no app: a process app lives in ~/Applications, and the apps job removes any shipkit bundle here (home/process-apps.ts)
|
|
54
57
|
wrapper: sk('wrapper'),
|
|
55
58
|
// generated on every run
|
|
56
59
|
status: sk('STATUS.md'),
|
|
@@ -59,7 +62,7 @@ export const LAYOUT = {
|
|
|
59
62
|
} as const
|
|
60
63
|
|
|
61
64
|
/** 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
|
|
65
|
+
export const TRACKED_DIRS = [LAYOUT.asks, LAYOUT.hooks, LAYOUT.identity, LAYOUT.assets, LAYOUT.comfy, LAYOUT.repros, LAYOUT.plans, LAYOUT.releases] as const
|
|
63
66
|
|
|
64
67
|
/** a plan file name: `YYYYMMDD-HHMMSS-<slug>.md` */
|
|
65
68
|
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
|
+
}
|
package/src/home/daemon-jobs.ts
CHANGED
|
@@ -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
|
|
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')
|
package/src/home/global-units.ts
CHANGED
|
@@ -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,
|