rvlib-shipkit 2.10.0 → 2.12.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 +22 -0
- package/package.json +1 -1
- package/src/cli/cmd_Media.ts +253 -0
- package/src/cli/cmd_Review.ts +4 -0
- package/src/cli/cmd_Trailer.ts +4 -0
- package/src/cli/family-pages.ts +1 -0
- package/src/cli/registry.ts +2 -0
- package/src/collections/pings.ts +6 -4
- package/src/core/app-icon.ts +17 -4
- package/src/core/scratch-objects.ts +56 -0
- package/src/core/trace-audit.ts +13 -1
- package/src/home/home-paths.ts +4 -0
- package/src/home/home-routes.ts +36 -2
- package/src/home/hubs.ts +5 -0
- package/src/home/inbox-shape.ts +188 -0
- package/src/home/inbox.ts +104 -0
- package/src/home/run-daemon.ts +12 -2
- package/src/home/serve-web.ts +161 -16
- package/src/ledger/git-scan.ts +73 -25
- package/src/ledger/repo-view.ts +2 -22
- package/src/media-kinds.ts +14 -0
- package/src/media-store/content.ts +61 -0
- package/src/media-store/daemon.ts +91 -0
- package/src/media-store/db.ts +74 -0
- package/src/media-store/fact.ts +9 -0
- package/src/media-store/hand.ts +58 -0
- package/src/media-store/kind.ts +44 -0
- package/src/media-store/purge.ts +139 -0
- package/src/media-store/put.ts +120 -0
- package/src/media-store/remote.ts +93 -0
- package/src/media-store/space.ts +167 -0
- package/src/media-store/sync.ts +101 -0
- package/src/media-store/upload.ts +98 -0
- package/src/repo-config.ts +4 -0
- package/src/review/anim.ts +6 -5
- package/src/review/cells.ts +5 -1
- package/src/review/media-kind.ts +84 -0
- package/src/review/media-read.ts +48 -0
- package/src/review/model.ts +22 -1
- package/src/review/previews.ts +41 -12
- package/src/review/routes.ts +32 -8
- package/src/review/store.ts +102 -40
- package/src/review/trailer-desk.ts +79 -46
- package/src/review/trailer-media.ts +181 -0
- package/src/review/trailer-routes.ts +5 -2
- package/src/review/trailer-shots.ts +89 -0
- package/src/serve/hub-app/cols-svc.ts +12 -1
- package/src/serve/hub-app/home-st.ts +39 -9
- package/src/serve/hub-app/home.html +2 -1
- package/src/serve/hub-app/hub-app.tsx +7 -23
- package/src/serve/hub-app/icons.tsx +2 -0
- package/src/serve/hub-app/inbox-st.ts +144 -0
- package/src/serve/hub-app/inbox-view.tsx +205 -0
- package/src/serve/hub-app/inbox.css +73 -0
- package/src/serve/hub-app/item-view.tsx +19 -0
- package/src/serve/hub-app/keys.ts +4 -3
- package/src/serve/hub-app/palette-st.ts +2 -1
- package/src/serve/hub-app/project-list.tsx +1 -0
- package/src/serve/hub-app/projects-svc.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +1 -1
- package/src/serve/hub-app/review/review-st.ts +15 -3
- package/src/serve/hub-app/review/review-thread.tsx +5 -4
- package/src/serve/hub-app/review.css +1 -1
- package/src/serve/hub-app/test-view.tsx +9 -2
- package/src/serve/hub-app/tests-svc.ts +16 -1
- package/src/serve/hub-runtime.ts +9 -4
- package/src/serve/resources-wire.ts +48 -0
- package/src/serve/serve-hub.ts +11 -7
- package/src/serve/warm-cell.ts +6 -1
- package/src/trailer/footage.ts +6 -2
- package/src/trailer/passage.ts +8 -3
- package/src/trailer/prune.ts +6 -10
- package/src/trailer/shelf.ts +16 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## 2.12.0
|
|
2
|
+
|
|
3
|
+
- **`sk media versioning [--check]`: the Space's versioning, turned on or read.** PutBucketVersioning then GetBucketVersioning, signed by hand (SigV4) since Bun's S3 client has no verb for them (`Space.versioning`, `Space.enableVersioning`). On the house Space today the read answers `off` and the PUT answers 403 AccessDenied: its key is limited to the bucket's objects.
|
|
4
|
+
- **Comment images and the trailer's shots folders join the media store.** A review message's image (`thread/<file>`) is a file of the `review` kind: its fact in `item.json` under `media["thread/<file>"]`, up and purged by the card's rules, served from the Space by `GET /api/review/<id>/thread/<file>` once the disk let it go, fetched back by `sk review show`. Each build's shelf `out/<cut>-shots/` and each version's `versions/<v>/shots/` are files of the `trailer` kind, their facts in the folder's `.media.json`: the shelf of each trailer's newest build and a folder whose cut has an open note stay on the disk, the rest goes once quiet for 14 days from the folder's birth. `sk trailer keep` fetches a purged shelf back before it clones it, and clones its facts with it.
|
|
5
|
+
- **The inbox folds the red checks of a quiet repo into « can wait ».** A repo whose last commit of its own is older than 7 days (a subject 3 house repos share, numbers taken out, is a sweep and never counts: the toolkit bumps landed in every repo yesterday; the log asked at most once every 10 minutes per repo) keeps its review cards and asks in the main list, but its red checks go to the folded list, still red, their line saying « quiet repo, last commit <day> ». A repo git cannot date stays as it was. 23 of the main rows were red checks of repos nobody works in.
|
|
6
|
+
- **`sk media put` and `sk media link`: any repo keeps a file in the private Space through the store.** `sk media put <file…> --kind <label> [--link <dur>] [--json]` keeps each file by its content as `<label>/<sha256>.<ext>` (`files` when no label is given): its index row with its original name first, then the upload, checked by a HEAD; a content already up is only marked. A label no `MediaKind` owns is the generic kind under that prefix, purgeable off the Mac by the usual rules (its bytes must still hash to its key), never deleted from the Space; `review` and `trailer` are refused. `sk media link <key|sha|path> [--for <dur>] [--name <filename>] [--json]` signs a fresh link at any time. Every link carries `response-content-disposition: attachment; filename="<name>"` and `response-content-type`, inside the signature, so a download keeps its name through the CDN edge. A link lasts at most 7d, the SigV4 limit; more is refused with that reason. `--json` prints one line a file, `{ key, sha, size, name, url, expires }`. The content types gain zip, gz, tar, dmg, pdf, gif, json, txt, md and csv.
|
|
7
|
+
|
|
8
|
+
- **A hub page loads a quarter of the bytes.** `/api/resources.json` is serialized once per compute, carries an ETag over the list and its live parts, is gzipped for a browser that takes it, and answers 304 to a page that holds it; the page then parses and swaps nothing on that poll. A test file carries its last run only in the list, and its page reads the whole list from `GET /api/test-runs.json?file=<file>`. The web answers 304 for a page file whose ETag the browser holds, so the 3.3 MB bundle no longer comes again on every load. The review page's boot reads its list, its watchers and the unit's words once, not three times. Measured on pkm-multi's review page: 12.8 MB on the wire before, 3.7 MB cold and 1.3 to 1.5 MB warm after; its list 2.18 MB to 1.18 MB (107 kB gzipped).
|
|
9
|
+
|
|
10
|
+
## 2.11.0
|
|
11
|
+
|
|
12
|
+
- **One media store for any kind of media, and the trailer renders join it.** `src/review/space/` becomes `src/media-store/`, the machine's one store: a caller writes a `MediaKind` (where its files live in a repo, what they are, what stays on the disk) and adds it to `src/media-kinds.ts`; the store does the index, the upload, the signed URL, the fetch back and the purge. Keys are `<kind>/<sha256>.<ext>`. Review is the kind `review`, unchanged on the Space. The trailer renders are the kind `trailer`: each settled render's video and strip (the desk's clones in `.shipkit/cache/trailer-view/`, recorded by the daemon even when the desk never opened) and each kept version's own files go up; the newest render of each live cut and a render an open frame note was written on stay on the disk, the rest goes once quiet for 14 days and only after its bytes hash to its key. The desk plays a render the disk let go from a URL signed on the CDN edge; a new note fetches its video back; `sk trailer clip --version` fetches a version's video back. `sk trailer prune` no longer deletes views: an old render was lost there before it went up. A purge never deletes a file a process holds open. The verbs move: `sk media`, `sk media upload [--kind]`, `sk media purge [--kind] [--dry --list] [--auto on|off]` replace `sk review media`, `sk review media upload` and `sk review purge`; the daemon's switch is `media-purge-auto` (off until turned on). The house config key is `serve.mediaSpace`; the index file is `media.sqlite` (`SHIPKIT_MEDIA_DB`). The purge works six files at a time and sends a review image's previews with a PUT and a HEAD each, none when they are up: 524 ms a file down to 62 ms on a fake S3 at 40 ms a request. Page: build/shipkit/media-store.md.
|
|
13
|
+
- **Review media go up to a private S3 bucket, and the disk lets the old ones go.** Every media file of a card (image, clip, poster, sound, waveform, tile) is known by its sha256: `item.json` holds `media`, `{ sha, size, type }` per file name, written by every writer of the head, and filled on an old head at its next index. The bucket keeps each content once, `review/<sha256>.<ext>`, private: an upload never asks a public ACL, an anonymous read is refused (`tests/review-space/space-live.test.ts`, `SHIPKIT_SPACES_LIVE=1`). The house config names it, `serve.reviewSpace: { endpoint, bucket, region, cdn, secret }`, and its key pair is read through `credsReadCommand`. The daemon syncs each house repo's store after a write, uploads what waits (a HEAD first, then a HEAD of the same size before it counts as up, retried later on a failure with one line in its log). `GET /api/review/<id>/<name>` and the preview routes answer the disk's file, else a 302 to a URL signed for one hour on the CDN edge (signed for the origin host, which the edge checks it against). A tool that needs the bytes (a preview, `sk review anim`, a poster's lit frame) fetches the file back first, checked by its sha. `sk review media` counts per store what is on the disk, up, purged, waiting and gone; `sk review media upload [--repo] [--dry]` sends every waiting file now; `sk review purge [--dry] [--older <days>] [--repo]` deletes a file only when it is up and a HEAD answers its size, never one of an active thread or of a thread with a message in the last 14 days, and sends an image's previews up first. `sk review purge --auto on` lets the daemon purge on its own under 40 GB free (off by default).
|
|
14
|
+
- **One machine index for every review store.** The item reads move from the json file beside each store (`.shipkit/.review-index.shipkit.json`, rewritten whole on any change, removed now) into one sqlite file in the home's state folder (`~/.config/shipkit/home/review.sqlite`, `SHIPKIT_REVIEW_DB`), beside each media file's state and each object's. The reads are kept per code hash: two copies of the lib reading one store (the daemon's, a repo's own install) had thrown each other's index away, and each paid the whole read again (2.3 s on a store of 3330 items). Only moved rows are written. It is derived: deleted, it builds again from the files, a HEAD finding what is up.
|
|
15
|
+
- **A head is rewritten under its lock.** `add-view`, a draft's refresh, `ready` and the media facts go through `updateHead`: under the item's lock, from the file as it is then, so two writers never lose each other's change.
|
|
16
|
+
|
|
17
|
+
- **A gate scan stores no git object.** Every key's `git add` into the scratch index wrote each blob it hashed into the repo's object store, reachable from nothing, kept two weeks by gc: one game repo held 14.3 GiB of unreachable loose objects, a 172 MB blob per trailer render under a declared ignored dir. The scan's git runs, and the trailer's world stamp, now write into an object dir of their own that sees the repo's objects as an alternate, deleted when the run returns (`src/core/scratch-objects.ts`); the ids are the same, the whole tree's file list is read inside the scan. The traced audit no longer reads a dir a probe found above a file the task read as a listing, which had widened a lint's proposal to the whole `.shipkit/cache`. A store that already holds them: `git prune -n --expire=1.hour.ago` lists them, the same without `-n` removes them, objects of the last hour left to the commits in flight.
|
|
18
|
+
- **One inbox for every repo, installable on a phone.** `/inbox` on the home lists everything that waits on the owner across every house repo, newest first: the review cards and questions waiting on his answer, the open asks, what is red. Each row carries its repo's icon, a kind badge, the title, its age and the card's preview thumb; what is yellow and the raised items in the agents' hands sit in one folded « can wait » section. A tap opens the item in place with its repo's own views: a card in the review thread (the same column as the repo's review page), an ask or a check in its item view (`item-view.tsx`, now shared with the repo page). On a phone it is the home's first page, one pane at a time, back returning to the list where it was. `GET /api/inbox` on the daemon aggregates each repo's review thread index and its hub's warm rows, no store of its own: `?list=main|yellow`, `offset`, `limit`, an ETag (304 on a poll that changed nothing), counts per repo that match each repo's own badges. Measured on this machine (19 repos, 52 rows and 93 folded): 12 ms warm, 0.3 to 0.8 s on the first reads after a daemon restart.
|
|
19
|
+
- **The home opens through the tailnet name, and only through it.** Bun's dev server answered any Host but a loopback one with 403 « Blocked: Host header does not match the dev server », so the page never opened behind `tailscale serve`. The page bundle now runs on a loopback port of its own behind the web, which forwards to it, hot reload socket included, once the Host is a loopback name or the tailnet name the house declares (`serve.publicHost`, served to the web in `/api/home/repos.json`); any other Host gets 403. The page's files are gzipped for a browser that takes it (the dev bundle: 3.3 MB to 0.65 MB).
|
|
20
|
+
- **The home installs as an app.** `/manifest.webmanifest` (standalone, starts on `/inbox`), the house repo's icon edge to edge at 180, 192 and 512 px (`/api/home/icon/<px>.png`, `appIconPngs(…, 'square')`), the apple meta tags, the safe area kept clear. No service worker.
|
|
21
|
+
- **A ping opens its item.** A hub in the home pings with a link to the inbox on that item (`https://<publicHost>:<home port>/inbox?open=<repo>/<id>`), or on the list for several. `PingIo.link` is a function of what is pinged.
|
|
22
|
+
|
|
1
23
|
## 2.10.0
|
|
2
24
|
|
|
3
25
|
- **Every old review card reads well as a thread, and his draft survives a new version.** A version that lands while he writes leaves his draft on the version he started it on (« move it to v4 / keep it on v3 »), a draft orphaned under an older version is found again, and what he types while an answer is on its way stays. The card opened with none named stays open when a poll reorders the list. An agent's word goes read when its cell shows with the tab visible, and `POST …/read` takes `{ of }` so only the words drawn are marked. The thread index is kept per store, so two repos' pages keep their 304s.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rvlib-shipkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"funding": "https://github.com/sponsors/rvion",
|
|
5
5
|
"description": "All-in-one repo companion: ci gate (task DAG), auto-discovered health checks, release-contract fulfillness, asks queue, md-wiki tools, asset atelier, live tui",
|
|
6
6
|
"license": "MIT",
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// sk media: the machine's one media store (media-store/, wiki build/shipkit/media-store.md): what each kind of each repo
|
|
2
|
+
// holds on the disk and in the private Space, every waiting file sent up now, the disk freed of what the Space holds.
|
|
3
|
+
// Every module loads inside execute: the cli registers this file on every `sk` call
|
|
4
|
+
import { Command, Option } from 'clipanion'
|
|
5
|
+
|
|
6
|
+
const DETAILS = `the machine's one media store: every media file a kind names (review: a card's files; trailer: each render's video and strip, a kept version's own) is known by its sha256, goes up to the owner's private Space as <kind>/<sha256>.<ext>, and leaves the disk once the Space holds it and its kind no longer pins it; it comes back on demand. One sqlite index for the machine. Page: wiki build/shipkit/media-store.md`
|
|
7
|
+
|
|
8
|
+
type Ctx = { stdout: NodeJS.WritableStream; stderr: NodeJS.WritableStream }
|
|
9
|
+
type Kind = import('../media-store/kind.ts').MediaKind
|
|
10
|
+
|
|
11
|
+
interface Here {
|
|
12
|
+
out: (l: string) => void
|
|
13
|
+
err: (l: string) => void
|
|
14
|
+
/** each kind asked with its store in the repo asked, the kinds the repo holds none of left out */
|
|
15
|
+
stores: { kind: Kind; dir: string; root: string }[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function run(context: Ctx, o: { repo?: string | undefined; kind?: string | undefined }, body: (h: Here) => Promise<number>): Promise<number> {
|
|
19
|
+
const out = (l: string): void => void context.stdout.write(`${l}\n`)
|
|
20
|
+
const err = (l: string): void => void context.stderr.write(`${l}\n`)
|
|
21
|
+
try {
|
|
22
|
+
const { findRepoRoot } = await import('../ts/config.ts')
|
|
23
|
+
const { mediaKinds } = await import('../media-kinds.ts')
|
|
24
|
+
const MEDIA_KINDS = mediaKinds()
|
|
25
|
+
const { existsSync } = await import('node:fs')
|
|
26
|
+
const { basename, dirname, join } = await import('node:path')
|
|
27
|
+
const here = findRepoRoot(process.cwd())
|
|
28
|
+
const root = o.repo === undefined || o.repo === basename(here) ? here : join(dirname(here), o.repo)
|
|
29
|
+
if (!existsSync(root)) throw new Error(`no repo ${root}`)
|
|
30
|
+
const kinds = MEDIA_KINDS.filter((k) => o.kind === undefined || k.kind === o.kind)
|
|
31
|
+
if (kinds.length === 0) throw new Error(`--kind ${o.kind}? the kinds: ${MEDIA_KINDS.map((k) => k.kind).join(', ')}`)
|
|
32
|
+
const stores = kinds.flatMap((kind) => {
|
|
33
|
+
const dir = kind.storeOf(root)
|
|
34
|
+
return dir && existsSync(dir) ? [{ kind, dir, root }] : []
|
|
35
|
+
})
|
|
36
|
+
return await body({ out, err, stores })
|
|
37
|
+
} catch (e) {
|
|
38
|
+
err(`FAIL: media: ${e instanceof Error ? e.message : String(e)}`)
|
|
39
|
+
return 1
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const repoOpt = (): string | undefined => Option.String('--repo', { description: 'a sibling repo by name, in place of this one' })
|
|
44
|
+
const kindOpt = (): string | undefined => Option.String('--kind', { description: 'one kind alone: review, trailer, or a label sk media put wrote' })
|
|
45
|
+
|
|
46
|
+
export class MediaCommand extends Command {
|
|
47
|
+
static override paths = [['media']]
|
|
48
|
+
static override usage = Command.Usage({
|
|
49
|
+
category: 'Media',
|
|
50
|
+
description: 'the media store per repo and kind: on the disk, up in the Space, purged, waiting, gone',
|
|
51
|
+
details: `${DETAILS}\n\nThis repo's stores are synced into the index first, then every store the index knows prints its counts and bytes. A file is local (on the disk), up (in the Space), purged (up, gone from the disk), waiting (on the disk, not up yet) or gone (neither).`,
|
|
52
|
+
examples: [['where the media stand', 'sk media']],
|
|
53
|
+
})
|
|
54
|
+
async execute(): Promise<number> {
|
|
55
|
+
return run(this.context, {}, async (h) => {
|
|
56
|
+
const { syncKind, mediaCounts } = await import('../media-store/sync.ts')
|
|
57
|
+
const { mb } = await import('../media-store/upload.ts')
|
|
58
|
+
const { findRepoRoot } = await import('../ts/config.ts')
|
|
59
|
+
const { basename } = await import('node:path')
|
|
60
|
+
for (const s of h.stores) {
|
|
61
|
+
const r = await syncKind(s.kind, s.dir, { fill: 0 })
|
|
62
|
+
if (r.unknown > 0) h.out(`${s.kind.kind}: ${r.unknown} files this repo names are on neither the disk nor in the Space: deleted before they went up`)
|
|
63
|
+
if (r.left > 0) h.out(`${s.kind.kind}: ${r.left} files of this repo are not hashed yet: sk media upload hashes them`)
|
|
64
|
+
}
|
|
65
|
+
const n = (c: { n: number; bytes: number }): string => `${c.n} (${mb(c.bytes)})`
|
|
66
|
+
for (const c of mediaCounts()) {
|
|
67
|
+
h.out(`${basename(findRepoRoot(c.store))} ${c.kind} local ${n(c.local)} up ${n(c.up)} purged ${n(c.purged)} waiting ${n(c.waiting)} gone ${n(c.gone)}`)
|
|
68
|
+
if (c.failing.n > 0) h.out(` ${c.failing.n} failing uploads, the last error: ${c.failing.error}`)
|
|
69
|
+
}
|
|
70
|
+
return 0
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class MediaUploadCommand extends Command {
|
|
76
|
+
static override paths = [['media', 'upload']]
|
|
77
|
+
static override usage = Command.Usage({
|
|
78
|
+
category: 'Media',
|
|
79
|
+
description: 'every waiting file of the media store up to the Space now: resumable, dedup by sha',
|
|
80
|
+
details: `${DETAILS}\n\nThe files not hashed yet are hashed first. A file the Space already holds (same key, same size) is only marked up. The daemon does the same in the background; this runs it now, to the end.`,
|
|
81
|
+
examples: [['this repo', 'sk media upload'], ['what pkm-multi would send of its trailers', 'sk media upload --repo pkm-multi --kind trailer --dry']],
|
|
82
|
+
})
|
|
83
|
+
repo = repoOpt()
|
|
84
|
+
kind = kindOpt()
|
|
85
|
+
dry = Option.Boolean('--dry', false, { description: 'count what would go up, send nothing' })
|
|
86
|
+
jobs = Option.String('--jobs', { description: 'uploads at once (6)' })
|
|
87
|
+
async execute(): Promise<number> {
|
|
88
|
+
return run(this.context, { repo: this.repo, kind: this.kind }, async (h) => {
|
|
89
|
+
const { resolve } = await import('node:path')
|
|
90
|
+
const { syncKind } = await import('../media-store/sync.ts')
|
|
91
|
+
const { mb, uploadWaiting, waitingObjects } = await import('../media-store/upload.ts')
|
|
92
|
+
const { machineSpace } = await import('../media-store/space.ts')
|
|
93
|
+
let failed = 0
|
|
94
|
+
for (const st of h.stores) {
|
|
95
|
+
const t0 = Date.now()
|
|
96
|
+
const s = await syncKind(st.kind, st.dir, { fill: this.dry ? 0 : Infinity })
|
|
97
|
+
const waiting = waitingObjects({ store: resolve(st.dir), now: Number.MAX_SAFE_INTEGER })
|
|
98
|
+
const bytes = waiting.reduce((n, w) => n + w.size, 0)
|
|
99
|
+
h.out(`${st.kind.kind} ${st.dir}: ${s.files} files indexed${s.filled > 0 ? `, ${s.filled} hashed` : ''}${s.left > 0 ? `, ${s.left} not hashed (no --dry to hash them)` : ''}; ${waiting.length} objects waiting (${mb(bytes)})`)
|
|
100
|
+
if (this.dry || waiting.length === 0) continue
|
|
101
|
+
const { space, why } = await machineSpace()
|
|
102
|
+
if (!space) throw new Error(why)
|
|
103
|
+
const r = await uploadWaiting(space, { store: resolve(st.dir), jobs: Number(this.jobs ?? 6) || 6, now: Number.MAX_SAFE_INTEGER, say: h.out })
|
|
104
|
+
const sec = (Date.now() - t0) / 1000
|
|
105
|
+
h.out(`${r.up} up (${mb(r.bytes)}), ${r.there} already there, ${r.failed.length} failed, in ${sec.toFixed(0)} s${r.bytes > 0 ? ` (${mb(r.bytes / sec)}/s)` : ''}`)
|
|
106
|
+
for (const f of r.failed.slice(0, 5)) h.err(`FAIL: ${f.key}: ${f.error}`)
|
|
107
|
+
failed += r.failed.length
|
|
108
|
+
}
|
|
109
|
+
return failed > 0 ? 1 : 0
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export class MediaPurgeCommand extends Command {
|
|
115
|
+
static override paths = [['media', 'purge']]
|
|
116
|
+
static override usage = Command.Usage({
|
|
117
|
+
category: 'Media',
|
|
118
|
+
description: 'free the disk of media the Space holds, never a file its kind pins or a recent one',
|
|
119
|
+
details: `${DETAILS}\n\nA file goes only when the index says it is up AND a HEAD answers its size AND its kind agrees (review sends an image's previews up first; trailer checks the file hashes to its key), and never while a process holds it open. Kept: what each kind pins (review: an active card; trailer: the newest render of each cut, a render an open frame note was written on) and every file used in the last --older days (14). Oldest first. A purged file comes back on demand. --auto on lets the daemon purge every kind on its own whenever the disk has under 40 GB free, until it is back over; --auto off stops it.`,
|
|
120
|
+
examples: [['what it would free', 'sk media purge --dry'], ['pkm-multi trailers, every file that would go', 'sk media purge --repo pkm-multi --kind trailer --dry --list'], ['the daemon purges under 40 GB free', 'sk media purge --auto on']],
|
|
121
|
+
})
|
|
122
|
+
repo = repoOpt()
|
|
123
|
+
kind = kindOpt()
|
|
124
|
+
dry = Option.Boolean('--dry', false, { description: 'print what it would free, delete nothing' })
|
|
125
|
+
list = Option.Boolean('--list', false, { description: 'with --dry: every file that would go, one line each' })
|
|
126
|
+
older = Option.String('--older', { description: 'keep the files used in the last <days> (14)' })
|
|
127
|
+
auto = Option.String('--auto', { description: 'on | off: the daemon purges on its own under 40 GB free' })
|
|
128
|
+
async execute(): Promise<number> {
|
|
129
|
+
return run(this.context, { repo: this.repo, kind: this.kind }, async (h) => {
|
|
130
|
+
const { autoPurgeOn, setAutoPurge } = await import('../media-store/daemon.ts')
|
|
131
|
+
if (this.auto !== undefined) {
|
|
132
|
+
if (this.auto !== 'on' && this.auto !== 'off') throw new Error('--auto on | off')
|
|
133
|
+
if (!setAutoPurge(this.auto === 'on')) throw new Error('the machine db did not take the switch')
|
|
134
|
+
h.out(`the daemon's purge of the media store under 40 GB free: ${this.auto}`)
|
|
135
|
+
return 0
|
|
136
|
+
}
|
|
137
|
+
const { freeBytes, purge, purgeCandidates, KEEP_DAYS } = await import('../media-store/purge.ts')
|
|
138
|
+
const { mb } = await import('../media-store/upload.ts')
|
|
139
|
+
const { machineSpace } = await import('../media-store/space.ts')
|
|
140
|
+
const { join } = await import('node:path')
|
|
141
|
+
const older = this.older === undefined ? KEEP_DAYS : Number(this.older)
|
|
142
|
+
if (!(older >= 0)) throw new Error('--older <days>: a number')
|
|
143
|
+
for (const st of h.stores) {
|
|
144
|
+
const { candidates, kept } = await purgeCandidates(st.kind, st.dir, { olderDays: older })
|
|
145
|
+
const bytes = candidates.reduce((n, c) => n + c.size, 0)
|
|
146
|
+
h.out(
|
|
147
|
+
`${st.kind.kind} ${st.dir}: ${candidates.length} files could go (${mb(bytes)}); kept on the disk while up: ${kept.n} files (${mb(kept.bytes)}), ${kept.pinned.n} of them pinned (${mb(kept.pinned.bytes)}); free now ${mb(freeBytes(st.dir))}; the daemon's purge: ${autoPurgeOn() ? 'on' : 'off'}`,
|
|
148
|
+
)
|
|
149
|
+
if (this.dry) {
|
|
150
|
+
if (this.list) for (const c of candidates) h.out(` ${join(st.dir, c.item, c.name)} ${mb(c.size)} used ${new Date(c.used).toISOString().slice(0, 10)}`)
|
|
151
|
+
continue
|
|
152
|
+
}
|
|
153
|
+
if (candidates.length === 0) continue
|
|
154
|
+
const { space, why } = await machineSpace()
|
|
155
|
+
if (!space) throw new Error(why)
|
|
156
|
+
const r = await purge(st.kind, st.dir, space, candidates, { say: h.out })
|
|
157
|
+
h.out(`${r.files} files purged, ${mb(r.freed)} freed${r.refused.length > 0 ? `, ${r.refused.length} kept: the Space or the kind did not confirm them` : ''}`)
|
|
158
|
+
for (const f of r.refused.slice(0, 5)) h.err(`WARN ${f.key}: ${f.why}`)
|
|
159
|
+
}
|
|
160
|
+
return 0
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const PUT_DETAILS = `The one way an agent of any repo keeps a file in the owner's private Space: never call the Space client directly. Each file is kept by its content as <label>/<sha256>.<ext>, private: its index row (its repo, its place, its original name) first, then the upload, checked by a HEAD of its size; a content the Space already holds is only marked. The object never expires and nothing deletes it from the Space; the file stays on the disk, purgeable by the usual rules (sk media purge). A link is signed on the CDN edge and downloads under the file's name; it lasts at most 7d, the SigV4 limit of a signed URL, and sk media link makes a new one at any time. Page: wiki build/shipkit/media-store.md, Put a file from any repo`
|
|
166
|
+
|
|
167
|
+
export class MediaPutCommand extends Command {
|
|
168
|
+
static override paths = [['media', 'put']]
|
|
169
|
+
static override usage = Command.Usage({
|
|
170
|
+
category: 'Media',
|
|
171
|
+
description: 'keep files in the private Space by content, a signed link at most 7 days',
|
|
172
|
+
details: `${PUT_DETAILS}\n\n--json prints one line a file: { key, sha, size, name, url, expires }, url and expires only with --link.`,
|
|
173
|
+
examples: [
|
|
174
|
+
['a file, its key printed', 'sk media put notes.txt'],
|
|
175
|
+
['release zips, a week long link each, as json', 'sk media put dist/a.zip dist/b.zip --kind private-build --link 7d --json'],
|
|
176
|
+
],
|
|
177
|
+
})
|
|
178
|
+
kind = Option.String('--kind', { description: 'the label, the key prefix: lowercase letters, digits, dashes (files)' })
|
|
179
|
+
link = Option.String('--link', { description: 'a signed link for this long: 30m, 2h, 7d (at most 7d)' })
|
|
180
|
+
json = Option.Boolean('--json', false, { description: 'one JSON line a file' })
|
|
181
|
+
files = Option.Rest({ required: 1 })
|
|
182
|
+
async execute(): Promise<number> {
|
|
183
|
+
return run(this.context, {}, async (h) => {
|
|
184
|
+
const { durationS, linkMedia, putMedia } = await import('../media-store/put.ts')
|
|
185
|
+
const { mb } = await import('../media-store/upload.ts')
|
|
186
|
+
const seconds = this.link === undefined ? null : durationS(this.link)
|
|
187
|
+
for (const f of this.files) {
|
|
188
|
+
const p = await putMedia(f, { ...(this.kind !== undefined ? { kind: this.kind } : {}) })
|
|
189
|
+
const l = seconds === null ? null : await linkMedia(p.key, { seconds, name: p.name })
|
|
190
|
+
if (this.json) h.out(JSON.stringify({ key: p.key, sha: p.sha, size: p.size, name: p.name, ...(l ? { url: l.url, expires: l.expires } : {}) }))
|
|
191
|
+
else {
|
|
192
|
+
h.out(`${p.key} ${p.name} ${mb(p.size)} ${p.sent ? 'up' : 'already in the Space'}`)
|
|
193
|
+
if (l) h.out(` ${l.url}\n expires ${l.expires}`)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return 0
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export class MediaLinkCommand extends Command {
|
|
202
|
+
static override paths = [['media', 'link']]
|
|
203
|
+
static override usage = Command.Usage({
|
|
204
|
+
category: 'Media',
|
|
205
|
+
description: 'a fresh signed link to a file the Space holds, by key, sha or path',
|
|
206
|
+
details: `${PUT_DETAILS}\n\nThe reference is a key (<label>/<sha256>.<ext>), a sha (12 hex of it are enough), or a file the store holds. The link downloads under the name the index keeps for it, or --name. --for defaults to 24h, at most 7d. --json prints { key, sha, size, name, url, expires }.`,
|
|
207
|
+
examples: [
|
|
208
|
+
['a link for a day', 'sk media link private-build/<sha>.zip'],
|
|
209
|
+
['a week, under a name, as json', 'sk media link private-build/<sha>.zip --for 7d --name dgen-1.2.0-mac-arm64.zip --json'],
|
|
210
|
+
],
|
|
211
|
+
})
|
|
212
|
+
for = Option.String('--for', { description: 'how long the link lasts: 30m, 2h, 7d (24h, at most 7d)' })
|
|
213
|
+
name = Option.String('--name', { description: 'the file name the link downloads under (the index row\'s name)' })
|
|
214
|
+
json = Option.Boolean('--json', false, { description: 'one JSON line' })
|
|
215
|
+
ref = Option.String({ required: true })
|
|
216
|
+
async execute(): Promise<number> {
|
|
217
|
+
return run(this.context, {}, async (h) => {
|
|
218
|
+
const { durationS, linkMedia } = await import('../media-store/put.ts')
|
|
219
|
+
const l = await linkMedia(this.ref, { seconds: durationS(this.for ?? '24h'), ...(this.name !== undefined ? { name: this.name } : {}) })
|
|
220
|
+
if (this.json) h.out(JSON.stringify(l))
|
|
221
|
+
else h.out(`${l.url}\n ${l.key} ${l.name}, expires ${l.expires}`)
|
|
222
|
+
return 0
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export class MediaVersioningCommand extends Command {
|
|
228
|
+
static override paths = [['media', 'versioning']]
|
|
229
|
+
static override usage = Command.Usage({
|
|
230
|
+
category: 'Media',
|
|
231
|
+
description: "turn on the Space's versioning: a delete from outside can be undone; --check reads it",
|
|
232
|
+
details: `PutBucketVersioning, then GetBucketVersioning to confirm: an object deleted or overwritten from the DigitalOcean dashboard or by a stray key keeps its older version. DigitalOcean offers it through the S3 API only. Once on, it can only be suspended, never turned off. Page: wiki build/shipkit/media-store.md, Versioning`,
|
|
233
|
+
examples: [
|
|
234
|
+
['turn it on', 'sk media versioning'],
|
|
235
|
+
['read it', 'sk media versioning --check'],
|
|
236
|
+
],
|
|
237
|
+
})
|
|
238
|
+
check = Option.Boolean('--check', false, { description: 'read the state, change nothing' })
|
|
239
|
+
async execute(): Promise<number> {
|
|
240
|
+
return run(this.context, {}, async (h) => {
|
|
241
|
+
const { machineSpace } = await import('../media-store/space.ts')
|
|
242
|
+
const { space, why } = await machineSpace()
|
|
243
|
+
if (!space) throw new Error(`no Space: ${why}`)
|
|
244
|
+
const before = await space.versioning()
|
|
245
|
+
if (!this.check && before !== 'Enabled') await space.enableVersioning()
|
|
246
|
+
const now = this.check ? before : await space.versioning()
|
|
247
|
+
h.out(`${space.where}: versioning ${now}${this.check || before === now ? '' : ` (was ${before})`}`)
|
|
248
|
+
return this.check || now === 'Enabled' ? 0 : 1
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export const MEDIA_COMMANDS = [MediaCommand, MediaUploadCommand, MediaPurgeCommand, MediaPutCommand, MediaLinkCommand, MediaVersioningCommand]
|
package/src/cli/cmd_Review.ts
CHANGED
|
@@ -374,6 +374,10 @@ export class ReviewShowCommand extends Command {
|
|
|
374
374
|
return 0
|
|
375
375
|
}
|
|
376
376
|
const t = threadOfItem(x.item.id, threadsOf(all.items))
|
|
377
|
+
// the image paths it prints are on the disk: a message image the purge let go comes back first
|
|
378
|
+
const { ensureLocal } = await import('../review/media-read.ts')
|
|
379
|
+
const { membersOf } = await import('../review/threads.ts')
|
|
380
|
+
await Promise.all((t ? membersOf(t) : [x]).flatMap((y) => y.thread.flatMap((m) => (m.image ? [ensureLocal(h.dir, y.item.id, `thread/${m.image}`).catch((e: Error) => h.err(`review: WARN thread/${m.image}: ${e.message}`))] : []))))
|
|
377
381
|
h.out(t && (t.head.item.id === x.item.id || t.answers.length > 0) ? threadDetail(t, h.dir, true, h.say) : detail(x, h.dir, true, false, h.say))
|
|
378
382
|
return 0
|
|
379
383
|
})
|
package/src/cli/cmd_Trailer.ts
CHANGED
|
@@ -247,6 +247,10 @@ export class TrailerKeepCommand extends Command {
|
|
|
247
247
|
return run(this.context, async (say, root, cwd) => {
|
|
248
248
|
const l = await loaded(this.file, say, root, cwd)
|
|
249
249
|
if (!l) return 1
|
|
250
|
+
// a shot the media store let go comes back first, so the version holds every take
|
|
251
|
+
const { join } = await import('node:path')
|
|
252
|
+
const lost = await (await import('../review/trailer-shots.ts')).shotsBack(l.root, join(l.dir, 'out', `${l.t.name}-shots`))
|
|
253
|
+
if (lost.length > 0) say(`WARN ${lost.length} shots not fetched back, kept by their facts only: ${lost.join(', ')}`)
|
|
250
254
|
;(await import('../trailer/passage.ts')).keep(l, this.version, say, cwd)
|
|
251
255
|
return 0
|
|
252
256
|
})
|
package/src/cli/family-pages.ts
CHANGED
|
@@ -10,6 +10,7 @@ export const FAMILY_PAGES: Readonly<Record<string, string>> = {
|
|
|
10
10
|
Gate: 'build/shipkit.md',
|
|
11
11
|
Health: 'build/shipkit.md',
|
|
12
12
|
Home: 'build/shipkit/home.md',
|
|
13
|
+
Media: 'build/shipkit/media-store.md',
|
|
13
14
|
Refactor: 'build/typescript.md',
|
|
14
15
|
Review: 'build/shipkit/review.md',
|
|
15
16
|
Scaffold: 'build/pocketbase.md',
|
package/src/cli/registry.ts
CHANGED
|
@@ -45,6 +45,7 @@ import { StartCommand } from './cmd_Start.ts'
|
|
|
45
45
|
import { TRAILER_COMMANDS } from './cmd_Trailer.ts'
|
|
46
46
|
import { SOUND_COMMANDS } from './cmd_Sound.ts'
|
|
47
47
|
import { REVIEW_COMMANDS } from './cmd_Review.ts'
|
|
48
|
+
import { MEDIA_COMMANDS } from './cmd_Media.ts'
|
|
48
49
|
import { TuiCommand } from './cmd_Tui.ts'
|
|
49
50
|
import { WikiLintCommand, WikiServeCommand } from './cmd_Wiki.ts'
|
|
50
51
|
|
|
@@ -85,6 +86,7 @@ export function buildCli(): Cli {
|
|
|
85
86
|
for (const c of TRAILER_COMMANDS) cli.register(c)
|
|
86
87
|
for (const c of SOUND_COMMANDS) cli.register(c)
|
|
87
88
|
for (const c of REVIEW_COMMANDS) cli.register(c)
|
|
89
|
+
for (const c of MEDIA_COMMANDS) cli.register(c)
|
|
88
90
|
cli.register(ServeCommand)
|
|
89
91
|
cli.register(PmCommand)
|
|
90
92
|
cli.register(DaemonCommand)
|
package/src/collections/pings.ts
CHANGED
|
@@ -21,9 +21,10 @@ export type PingIo = {
|
|
|
21
21
|
notifyCommand?: string
|
|
22
22
|
/** additive desktop notification on macOS */
|
|
23
23
|
osascript?: boolean
|
|
24
|
-
/**
|
|
25
|
-
* (serve.publicHost)
|
|
26
|
-
|
|
24
|
+
/** the url appended to the message for what it pings, in the OFF-MACHINE
|
|
25
|
+
* form (serve.publicHost), a phone can't resolve localhost: the home's
|
|
26
|
+
* inbox on that one item, or on the list for several */
|
|
27
|
+
link?: (fresh: NeedItem[]) => string | undefined
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
const stateDir = (root: string): string | null => (existsSync(join(root, 'node_modules')) ? join(root, 'node_modules', '.cache', 'shipkit') : null)
|
|
@@ -88,7 +89,8 @@ export function pingTick(root: string, asksDir: string, needs: NeedItem[], io: P
|
|
|
88
89
|
savePinged(root, state.ids)
|
|
89
90
|
if (fresh.length === 0) return []
|
|
90
91
|
const head = fresh.slice(0, 3).map((n) => n.text.slice(0, 80)).join(' · ')
|
|
91
|
-
const
|
|
92
|
+
const link = io.link?.(fresh)
|
|
93
|
+
const message = `${fresh.length} new item(s) need you: ${head}${fresh.length > 3 ? ' · …' : ''}${link != null ? ` → ${link}` : ''}`
|
|
92
94
|
// item texts come from repo data — strip shell-active chars before the template substitution
|
|
93
95
|
const safe = message.replace(/[`$\\'"]/g, '')
|
|
94
96
|
if (io.notifyCommand != null) io.run(['sh', '-c', io.notifyCommand.replaceAll('{message}', safe)])
|
package/src/core/app-icon.ts
CHANGED
|
@@ -135,16 +135,29 @@ export async function drawAppIcon(bytes: Uint8Array, id: Identity): Promise<{ ca
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/** the icon as pngs, one per size asked, drawn once. `plate` crops the macOS
|
|
138
|
-
* grid's margin away, the rounded plate edge to edge (the hub's rail)
|
|
139
|
-
|
|
138
|
+
* grid's margin away, the rounded plate edge to edge (the hub's rail);
|
|
139
|
+
* `square` fills the plate's corners with its own edge colours, edge to edge
|
|
140
|
+
* with no transparency (a phone's home screen cuts its own corners) */
|
|
141
|
+
export async function appIconPngs(bytes: Uint8Array, id: Identity, sizes: number[] = [ICON_PX], crop: 'canvas' | 'plate' | 'square' = 'canvas'): Promise<Buffer[]> {
|
|
140
142
|
const { canvas } = await drawAppIcon(bytes, id)
|
|
141
|
-
const o = crop === '
|
|
142
|
-
const side = crop === '
|
|
143
|
+
const o = crop === 'canvas' ? 0 : (ICON_PX - PLATE) / 2
|
|
144
|
+
const side = crop === 'canvas' ? ICON_PX : PLATE
|
|
145
|
+
const edge = (y: number): string => {
|
|
146
|
+
const [r, g, b] = canvas.getContext('2d').getImageData(ICON_PX / 2, y, 1, 1).data
|
|
147
|
+
return `rgb(${r},${g},${b})`
|
|
148
|
+
}
|
|
143
149
|
return sizes.map((px) => {
|
|
144
150
|
if (px === ICON_PX && crop === 'canvas') return canvas.toBuffer('image/png')
|
|
145
151
|
const small = createCanvas(px, px)
|
|
146
152
|
const ctx = small.getContext('2d')
|
|
147
153
|
ctx.imageSmoothingQuality = 'high'
|
|
154
|
+
if (crop === 'square') {
|
|
155
|
+
const g = ctx.createLinearGradient(0, 0, 0, px)
|
|
156
|
+
g.addColorStop(0, edge(o + 2))
|
|
157
|
+
g.addColorStop(1, edge(o + PLATE - 3))
|
|
158
|
+
ctx.fillStyle = g
|
|
159
|
+
ctx.fillRect(0, 0, px, px)
|
|
160
|
+
}
|
|
148
161
|
ctx.drawImage(canvas, o, o, side, side, 0, 0, px, px)
|
|
149
162
|
return small.toBuffer('image/png')
|
|
150
163
|
})
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// git that names content without keeping it. `git add` into a scratch index
|
|
2
|
+
// (a cache key, a world stamp) writes every blob it hashes into the repo's
|
|
3
|
+
// object store, where nothing reaches it and gc keeps it two weeks: measured
|
|
4
|
+
// in a game repo, 14.3 GiB of unreachable loose objects, one 172 MB blob per
|
|
5
|
+
// trailer render. A run under `env` writes its objects into a dir of its own,
|
|
6
|
+
// still finds the repo's objects through the alternates, and `drop` deletes
|
|
7
|
+
// what it wrote. An id read under `env` stays valid; an object it names may be
|
|
8
|
+
// gone once dropped, so a caller reads every tree it needs before the drop.
|
|
9
|
+
import { mkdirSync, readdirSync, rmSync } from 'fs'
|
|
10
|
+
import { delimiter, join } from 'path'
|
|
11
|
+
import { pidAlive } from '../ledger/live-runs.ts'
|
|
12
|
+
import { probeGitRoot } from './git-root.ts'
|
|
13
|
+
|
|
14
|
+
export type ScratchObjects = {
|
|
15
|
+
/** the object dir the run writes into */
|
|
16
|
+
dir: string
|
|
17
|
+
/** spread over a git run's environment */
|
|
18
|
+
env: Record<string, string>
|
|
19
|
+
/** delete what the run wrote */
|
|
20
|
+
drop: () => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let seq = 0
|
|
24
|
+
const live = new Set<string>()
|
|
25
|
+
|
|
26
|
+
/** a fresh object dir under `parent` for the git runs of one scan of `root` */
|
|
27
|
+
export function scratchObjects(root: string, parent: string): ScratchObjects {
|
|
28
|
+
const g = probeGitRoot(root).root
|
|
29
|
+
if (g == null) throw new Error(`not a git repository: ${root}`)
|
|
30
|
+
const real = process.env.GIT_OBJECT_DIRECTORY ?? join(g.commonDir, 'objects')
|
|
31
|
+
sweepScratchObjects(parent)
|
|
32
|
+
const dir = join(parent, `sk-objects-${process.pid}-${seq++}`)
|
|
33
|
+
mkdirSync(dir, { recursive: true })
|
|
34
|
+
if (live.size === 0) process.on('exit', () => { for (const d of live) rmSync(d, { recursive: true, force: true }) })
|
|
35
|
+
live.add(dir)
|
|
36
|
+
const alternates = [real, process.env.GIT_ALTERNATE_OBJECT_DIRECTORIES].filter((x) => x != null && x !== '').join(delimiter)
|
|
37
|
+
return {
|
|
38
|
+
dir,
|
|
39
|
+
env: { GIT_OBJECT_DIRECTORY: dir, GIT_ALTERNATE_OBJECT_DIRECTORIES: alternates },
|
|
40
|
+
drop: () => {
|
|
41
|
+
live.delete(dir)
|
|
42
|
+
rmSync(dir, { recursive: true, force: true })
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** the object dirs of processes that are gone: a killed scan leaves its own */
|
|
48
|
+
export function sweepScratchObjects(parent: string): void {
|
|
49
|
+
let names: string[]
|
|
50
|
+
try { names = readdirSync(parent) } catch { return }
|
|
51
|
+
for (const f of names) {
|
|
52
|
+
const m = /^sk-objects-(\d+)-\d+$/.exec(f)
|
|
53
|
+
if (m == null || Number(m[1]) === process.pid || pidAlive(Number(m[1]))) continue
|
|
54
|
+
try { rmSync(join(parent, f), { recursive: true, force: true }) } catch { /* raced: gone either way */ }
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/core/trace-audit.ts
CHANGED
|
@@ -70,6 +70,18 @@ export function proposeInputs(content: string[], listed: string[]): string[] {
|
|
|
70
70
|
return [...bytes, ...tops.filter((d) => !bytes.some((b) => under(d, b))).map((d) => `${d}/**`)].sort()
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/** the dirs a task depends on as dirs: every one it listed, and every one a
|
|
74
|
+
* probe found that nothing else it read sits under. A resolver stats each
|
|
75
|
+
* ancestor of the file it opens (a game repo's lint: `.shipkit/cache`, then each
|
|
76
|
+
* dir down to the module), and that answer is implied by the file's own key;
|
|
77
|
+
* read as a listing, it widened the proposal to the whole cache dir, renders
|
|
78
|
+
* included */
|
|
79
|
+
export function dirsRead(listed: string[], probed: string[], files: string[]): string[] {
|
|
80
|
+
const ancestors = new Set<string>()
|
|
81
|
+
for (const p of [...files, ...listed, ...probed]) for (let d = posix.dirname(p); d !== '.' && d !== '/' && !ancestors.has(d); d = posix.dirname(d)) ancestors.add(d)
|
|
82
|
+
return [...new Set([...listed, ...probed.filter((d) => !ancestors.has(d))])]
|
|
83
|
+
}
|
|
84
|
+
|
|
73
85
|
/** trace every gate task of the repo once and report what its key misses */
|
|
74
86
|
export async function traceAudit(root: string, config: RepoConfig, o: { fresh?: boolean; now?: number; env?: Record<string, string | undefined> } = {}): Promise<AuditReport> {
|
|
75
87
|
const now = o.now ?? Date.now()
|
|
@@ -98,7 +110,7 @@ export async function traceAudit(root: string, config: RepoConfig, o: { fresh?:
|
|
|
98
110
|
// Finder rewrites .DS_Store at will, and no tool's verdict reads it
|
|
99
111
|
const rel = (p: string): boolean => !p.startsWith('/') && p !== '.' && !p.split('/').includes('node_modules') && !p.startsWith('.git/') && posix.basename(p) !== '.DS_Store'
|
|
100
112
|
const files = [...new Set([...Object.keys(r.reads.files), ...Object.keys(r.reads.sigs ?? {}), ...Object.entries(r.reads.exists).filter(([, k]) => k === 'file').map(([p]) => p)])].filter(rel)
|
|
101
|
-
const dirs =
|
|
113
|
+
const dirs = dirsRead(Object.keys(r.reads.dirs ?? {}).filter(rel), Object.entries(r.reads.exists).filter(([, k]) => k === 'dir').map(([p]) => p).filter(rel), files)
|
|
102
114
|
const ignored = gitIgnored(root, [...files, ...dirs])
|
|
103
115
|
const extras = ignoredFor(config.ignoredInputs, u.id)
|
|
104
116
|
const missF = files.filter((p) => ignored.has(p) && !covered(p, false, extras))
|
package/src/home/home-paths.ts
CHANGED
|
@@ -65,6 +65,10 @@ export const stateFile = (dir: string): string => join(dir, 'state.json')
|
|
|
65
65
|
/** the url prefix of a repo's hub on the home */
|
|
66
66
|
export const hubBase = (name: string): string => `/r/${encodeURIComponent(name)}`
|
|
67
67
|
|
|
68
|
+
/** the home as the machine's other devices reach it: its tailnet name, behind \`tailscale serve --https=<home port>\`,
|
|
69
|
+
* which proxies to the web on 127.0.0.1 */
|
|
70
|
+
export const publicHome = (host: string, port = homePort()): string => `https://${host}:${port}`
|
|
71
|
+
|
|
68
72
|
/** the home page's url as a local client reaches it (the web) */
|
|
69
73
|
export const homeUrl = (port = homePort()): string => `http://127.0.0.1:${port}`
|
|
70
74
|
|
package/src/home/home-routes.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// decides WHEN a hub loads and never what is true: every verdict still comes
|
|
4
4
|
// from each repo's own runner and ledger. The machine resources are pm's
|
|
5
5
|
// (run-pm.ts), and the page reaches them through the web at /api/pm/*.
|
|
6
|
-
import { existsSync } from 'fs'
|
|
6
|
+
import { existsSync, readFileSync } from 'fs'
|
|
7
7
|
import { dirname, join } from 'path'
|
|
8
8
|
import { fileURLToPath } from 'url'
|
|
9
9
|
import { installedVersion, isBehind } from '../fleet/scan-fleet.ts'
|
|
@@ -22,6 +22,8 @@ import { devRepos, InsightsCache, type Scope } from './insights.ts'
|
|
|
22
22
|
import { GLOBAL_CONTEXT_EVERY_MS, houseContext, writeIfChanged } from './global-context.ts'
|
|
23
23
|
import { HouseRuns } from '../serve/house-runs.ts'
|
|
24
24
|
import { pushFleet } from '../fleet/push-fleet.ts'
|
|
25
|
+
import { appIconOf, appIconPngs, identityOfRoot } from '../core/app-icon.ts'
|
|
26
|
+
import { inboxResponse } from './inbox.ts'
|
|
25
27
|
|
|
26
28
|
/** how far back a repo's git page lists its commits */
|
|
27
29
|
export const GIT_PAGE_MS = 7 * 24 * 3600_000
|
|
@@ -64,8 +66,13 @@ export type HomeDeps = {
|
|
|
64
66
|
widgets?: Widgets
|
|
65
67
|
/** brings a repo current (modernizeCmd); resolves to its exit code */
|
|
66
68
|
modernize?: (repo: WiredRepo, log: string) => Promise<number>
|
|
69
|
+
/** the machine's tailnet name, the house config's serve.publicHost: the one name besides localhost the web answers to */
|
|
70
|
+
publicHost?: string
|
|
67
71
|
}
|
|
68
72
|
|
|
73
|
+
/** the sizes the app icon is drawn at: the phone's home screen, the manifest's two */
|
|
74
|
+
export const ICON_SIZES = [180, 192, 512] as const
|
|
75
|
+
|
|
69
76
|
const CLI = fileURLToPath(new URL('../cli.ts', import.meta.url))
|
|
70
77
|
|
|
71
78
|
/** what bringing a repo current runs: its first install when it has none,
|
|
@@ -164,6 +171,18 @@ export function homeRoutes(d: HomeDeps) {
|
|
|
164
171
|
return { version: LIB_VERSION, workers: d.hubs.views(repos), active: d.state.data.active, behind, modernize, held: h == null ? null : heldText(h) }
|
|
165
172
|
}
|
|
166
173
|
|
|
174
|
+
const icons = new Map<number, Promise<Uint8Array<ArrayBuffer> | null>>()
|
|
175
|
+
/** drawn once per size for the life of the daemon, from the house repo's mark */
|
|
176
|
+
const iconPng = (px: number): Promise<Uint8Array<ArrayBuffer> | null> => {
|
|
177
|
+
let p = icons.get(px)
|
|
178
|
+
if (p == null) {
|
|
179
|
+
const mark = appIconOf(d.root)
|
|
180
|
+
p = mark == null ? Promise.resolve(null) : appIconPngs(readFileSync(mark), identityOfRoot(d.root), [px], 'square').then(([b]) => new Uint8Array(b!))
|
|
181
|
+
icons.set(px, p)
|
|
182
|
+
}
|
|
183
|
+
return p
|
|
184
|
+
}
|
|
185
|
+
|
|
167
186
|
const find = (name: unknown): WiredRepo | null => repos.find((r) => r.name === name) ?? null
|
|
168
187
|
const body = async (req: Request): Promise<Record<string, unknown>> => (await req.json().catch(() => ({}))) as Record<string, unknown>
|
|
169
188
|
|
|
@@ -187,7 +206,22 @@ export function homeRoutes(d: HomeDeps) {
|
|
|
187
206
|
// the web asks which page routes to serve: one per house repo
|
|
188
207
|
if (path === '/api/home/repos.json') {
|
|
189
208
|
if (repos.length === 0) await refresh()
|
|
190
|
-
return Response.json({ repos: d.hubs.names() })
|
|
209
|
+
return Response.json({ repos: d.hubs.names(), hosts: d.publicHost == null ? [] : [d.publicHost] })
|
|
210
|
+
}
|
|
211
|
+
// everything that waits on the owner in every repo, one list (inbox.ts)
|
|
212
|
+
if (path === '/api/inbox') {
|
|
213
|
+
if (repos.length === 0) await refresh()
|
|
214
|
+
const down = d.hubs.views(repos).filter((v) => v.status !== 'up').map((v) => ({ repo: v.repo, why: `its hub is ${v.status}${v.note != null ? `: ${v.note}` : ''}` }))
|
|
215
|
+
return inboxResponse(req, d.hubs, down)
|
|
216
|
+
}
|
|
217
|
+
// the house's app icon, edge to edge: the home as an app on a phone
|
|
218
|
+
const icon = /^\/api\/home\/icon\/(\d+)\.png$/.exec(path)
|
|
219
|
+
if (icon != null) {
|
|
220
|
+
const px = Number(icon[1]) as (typeof ICON_SIZES)[number]
|
|
221
|
+
if (!ICON_SIZES.includes(px)) return new Response(`the icon is drawn at ${ICON_SIZES.join(', ')} px`, { status: 404 })
|
|
222
|
+
const png = await iconPng(px)
|
|
223
|
+
if (png == null) return new Response('the house repo has no mark to draw its icon from', { status: 404 })
|
|
224
|
+
return new Response(png, { headers: { 'content-type': 'image/png', 'cache-control': 'max-age=86400' } })
|
|
191
225
|
}
|
|
192
226
|
if (path === '/api/home/planned.json') {
|
|
193
227
|
if (repos.length === 0) await refresh()
|
package/src/home/hubs.ts
CHANGED
|
@@ -258,6 +258,11 @@ export class Hubs {
|
|
|
258
258
|
return [...this.entries.keys()]
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/** every hub that is up, with its repo: what the inbox reads */
|
|
262
|
+
loaded(): { repo: WiredRepo; rt: LoadedHub }[] {
|
|
263
|
+
return [...this.entries.values()].flatMap((e) => (e.rt == null ? [] : [{ repo: e.repo, rt: e.rt }]))
|
|
264
|
+
}
|
|
265
|
+
|
|
261
266
|
private view(e: Entry): WorkerView {
|
|
262
267
|
const blocked = hubBlocker(e.repo.path) ?? (e.status === 'crashed' && notInstalled(e.repo.path) ? NOT_INSTALLED : null)
|
|
263
268
|
return {
|