rvlib-shipkit 2.12.0 → 2.13.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 +48 -13
- package/README.md +1 -1
- package/package.json +4 -2
- package/src/agent-time/store.ts +2 -2
- package/src/check.ts +1 -1
- package/src/checks/SK001-package-json-shape.check.ts +4 -0
- package/src/checks/SK003-claude-md-shape.check.ts +1 -1
- package/src/checks/SK004-gitignore-policy.check.ts +27 -2
- package/src/checks/SK005-rvlib-versions.check.ts +1 -1
- package/src/checks/SK008-reviewer-agent.check.ts +2 -2
- package/src/checks/SK012-config-barrel-import.check.ts +1 -1
- package/src/checks/SK015-nested-repo.check.ts +1 -1
- package/src/checks/SK035-public-clean.check.ts +46 -0
- package/src/checks/SK036-draft-media-size.check.ts +28 -0
- package/src/cli/cmd_Backup.ts +152 -0
- package/src/cli/cmd_Ci.ts +8 -11
- package/src/cli/cmd_Drill.ts +145 -0
- package/src/cli/cmd_Home.ts +50 -3
- package/src/cli/cmd_Media.ts +7 -5
- package/src/cli/cmd_Review.ts +4 -2
- package/src/cli/cmd_Shot.ts +5 -2
- package/src/cli/cmd_Smoke.ts +4 -1
- package/src/cli/cmd_Social.ts +226 -0
- package/src/cli/cmd_Start.ts +1 -1
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_Trailer.ts +5 -2
- package/src/cli/cmd_Veille.ts +173 -0
- package/src/cli/family-pages.ts +3 -0
- package/src/cli/registry.ts +13 -2
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +1 -49
- package/src/collections/checks.ts +2 -1
- package/src/collections/collection-types.ts +11 -2
- package/src/collections/providers.ts +4 -4
- package/src/collections/review.ts +2 -1
- package/src/collections/tests.ts +19 -8
- package/src/contracts/apply-contracts.ts +1 -3
- package/src/contracts/contract-manifests.ts +2 -3
- package/src/contracts/contract-types.ts +0 -1
- package/src/contracts/contracts-engine.ts +0 -3
- package/src/core/app-icon.ts +9 -3
- package/src/core/bun-builtins.ts +2 -2
- package/src/core/discover-checks.ts +37 -5
- package/src/core/fix-scope.ts +4 -2
- package/src/core/floor-resolve.ts +68 -48
- package/src/core/floor.ts +9 -0
- package/src/core/git-root.ts +24 -0
- package/src/core/last-good.ts +3 -1
- package/src/core/layout.ts +8 -0
- package/src/core/log-stamp.ts +36 -0
- package/src/core/loop-watch.ts +93 -0
- package/src/core/machine-link.ts +134 -0
- package/src/core/memory-watch.ts +41 -0
- package/src/core/one-way-in-policy.ts +27 -19
- package/src/core/run-ci.ts +6 -8
- package/src/core/run-fixers.ts +9 -9
- package/src/core/slots.ts +21 -0
- package/src/core/tree-rev.ts +60 -0
- package/src/core/unit-files.ts +42 -0
- package/src/drill/render.ts +140 -0
- package/src/drill/run.ts +269 -0
- package/src/fleet/scan-fleet.ts +6 -5
- package/src/home/daemon-jobs.ts +201 -0
- package/src/home/global-context.ts +34 -1
- package/src/home/home-routes.ts +22 -15
- package/src/home/hubs.ts +10 -3
- package/src/home/inbox-shape.ts +53 -4
- package/src/home/inbox.ts +16 -1
- package/src/home/lib-watch.ts +10 -3
- package/src/home/machine-stores.ts +15 -29
- package/src/home/run-daemon.ts +15 -18
- package/src/home/run-pm.ts +2 -0
- package/src/home/serve-daemon.ts +4 -3
- package/src/home/serve-web.ts +104 -1
- package/src/hooks/commit-message.ts +28 -19
- package/src/hooks/leak-guard.ts +10 -3
- package/src/hooks/run-hooks.ts +2 -6
- package/src/identities/identities.ts +334 -0
- package/src/identities/machine-route.ts +126 -0
- package/src/identities/machine.ts +62 -0
- package/src/init-repo.ts +1 -1
- package/src/ledger/check-stats.ts +10 -9
- package/src/ledger/gate-checks.ts +32 -1
- package/src/ledger/record-kept.ts +112 -0
- package/src/ledger/repo-view.ts +10 -0
- package/src/ledger/run-log.ts +17 -12
- package/src/ledger/run-timeline.ts +8 -4
- package/src/ledger/store.ts +7 -0
- package/src/ledger/suite-log.ts +17 -13
- package/src/media-kinds.ts +2 -1
- package/src/media-store/backup/daemon.ts +73 -0
- package/src/media-store/backup/keys.ts +25 -0
- package/src/media-store/backup/manifest.ts +193 -0
- package/src/media-store/backup/restore.ts +192 -0
- package/src/media-store/backup/run.ts +278 -0
- package/src/media-store/backup/secret.ts +86 -0
- package/src/media-store/backup/snapshot.ts +64 -0
- package/src/media-store/backup/sources.ts +199 -0
- package/src/media-store/daemon.ts +56 -70
- package/src/media-store/put.ts +4 -2
- package/src/media-store/space.ts +23 -4
- package/src/pages/forward.ts +35 -0
- package/src/pages/frame-client.ts +118 -0
- package/src/pages/routes.ts +29 -0
- package/src/pages/unit.ts +92 -0
- package/src/plan/planner.ts +12 -0
- package/src/plan/repo-source.ts +19 -5
- package/src/reflect/transcript.ts +35 -10
- package/src/release/public-clean.ts +301 -0
- package/src/release/published-here.ts +22 -0
- package/src/release/run-bump.ts +2 -1
- package/src/release/run-release.ts +4 -1
- package/src/repo-config.ts +53 -2
- package/src/review/http.ts +16 -2
- package/src/review/model.ts +15 -4
- package/src/review/notes.ts +77 -0
- package/src/review/project.ts +6 -38
- package/src/review/routes.ts +4 -12
- package/src/review/store.ts +41 -1
- package/src/review/trailer-media.ts +7 -4
- package/src/review/trailer-shots.ts +21 -4
- package/src/review/unit.ts +1 -1
- package/src/scaffold/files/agent-handoff.md +3 -0
- package/src/scaffold/files/agent-index.md +4 -12
- package/src/scaffold/project-scaffold.ts +5 -4
- package/src/serve/embed.ts +1 -1
- package/src/serve/hub-app/col-card.tsx +3 -17
- package/src/serve/hub-app/col-tables-view.tsx +2 -1
- package/src/serve/hub-app/cols-svc.ts +0 -13
- package/src/serve/hub-app/dock-st.ts +4 -2
- package/src/serve/hub-app/dock-view.tsx +2 -0
- package/src/serve/hub-app/frames-st.ts +35 -0
- package/src/serve/hub-app/hash-route.ts +64 -1
- package/src/serve/hub-app/home-st.ts +31 -7
- package/src/serve/hub-app/home-strip.css +9 -1
- package/src/serve/hub-app/home-strip.tsx +7 -6
- package/src/serve/hub-app/home.html +5 -0
- package/src/serve/hub-app/hub-app.tsx +49 -5
- package/src/serve/hub-app/hub.css +29 -11
- package/src/serve/hub-app/icons.tsx +16 -1
- package/src/serve/hub-app/identities-st.ts +210 -0
- package/src/serve/hub-app/identities-view.tsx +352 -0
- package/src/serve/hub-app/identities.css +48 -0
- package/src/serve/hub-app/identity-address.ts +52 -0
- package/src/serve/hub-app/inbox-st.ts +59 -6
- package/src/serve/hub-app/inbox-view.tsx +48 -6
- package/src/serve/hub-app/inbox.css +12 -1
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +10 -2
- package/src/serve/hub-app/list-walk.ts +89 -0
- package/src/serve/hub-app/machine-st.ts +12 -0
- package/src/serve/hub-app/media-view.tsx +2 -1
- package/src/serve/hub-app/pages-frames.tsx +134 -0
- package/src/serve/hub-app/pages-svc.ts +111 -0
- package/src/serve/hub-app/palette-st.ts +18 -3
- package/src/serve/hub-app/palette-view.tsx +9 -2
- package/src/serve/hub-app/planned-view.tsx +2 -1
- package/src/serve/hub-app/project-list.css +18 -14
- package/src/serve/hub-app/project-list.tsx +88 -49
- package/src/serve/hub-app/projects-svc.ts +33 -3
- package/src/serve/hub-app/repo-sections.ts +19 -2
- package/src/serve/hub-app/repo-st.ts +75 -19
- package/src/serve/hub-app/review/review-cells.tsx +3 -3
- package/src/serve/hub-app/review/review-kit.ts +30 -7
- package/src/serve/hub-app/review/review-page.tsx +1 -1
- package/src/serve/hub-app/review/review-st.ts +19 -8
- package/src/serve/hub-app/review/review-thread.tsx +11 -9
- package/src/serve/hub-app/review/review-views.tsx +84 -19
- package/src/serve/hub-app/review/thread-st.ts +1 -10
- package/src/serve/hub-app/review/trailer-page.tsx +2 -1
- package/src/serve/hub-app/review.css +17 -8
- package/src/serve/hub-app/site/site-part.tsx +173 -0
- package/src/serve/hub-app/site/site-st.ts +157 -0
- package/src/serve/hub-app/site.css +35 -0
- package/src/serve/hub-app/social/calendar.tsx +182 -0
- package/src/serve/hub-app/social/comms-page.tsx +306 -0
- package/src/serve/hub-app/social/kit.tsx +244 -0
- package/src/serve/hub-app/social/post-card.tsx +456 -0
- package/src/serve/hub-app/social/problems.tsx +60 -0
- package/src/serve/hub-app/social/social-model.ts +154 -0
- package/src/serve/hub-app/social/social-page.tsx +674 -0
- package/src/serve/hub-app/social/social-st.ts +986 -0
- package/src/serve/hub-app/social.css +289 -0
- package/src/serve/hub-app/stores/stores-page.tsx +311 -0
- package/src/serve/hub-app/stores/stores-st.ts +286 -0
- package/src/serve/hub-app/stores.css +54 -0
- package/src/serve/hub-app/timeline-geometry.ts +1 -1
- package/src/serve/hub-app/timeline-view.tsx +3 -2
- package/src/serve/hub-app/tree-build.ts +6 -0
- package/src/serve/hub-app/tree-row.tsx +27 -4
- package/src/serve/hub-app/tree-svc.ts +18 -49
- package/src/serve/hub-app/veille/veille-page.tsx +514 -0
- package/src/serve/hub-app/veille/veille-st.ts +443 -0
- package/src/serve/hub-app/veille.css +84 -0
- package/src/serve/hub-runtime.ts +14 -9
- package/src/serve/project-gutter-route.ts +44 -12
- package/src/serve/run-lanes.ts +7 -4
- package/src/serve/same-origin.ts +1 -1
- package/src/serve/serve-hub.ts +20 -12
- package/src/serve/tracked-watch.ts +24 -3
- package/src/serve/warm-cell.ts +5 -1
- package/src/shipkit-files.ts +15 -4
- package/src/shipkit.ts +0 -1
- package/src/shot/box.ts +162 -0
- package/src/shot/browser-slot.ts +62 -0
- package/src/shot/client.ts +43 -7
- package/src/shot/clip-encoder.ts +93 -12
- package/src/shot/film-box.ts +188 -0
- package/src/shot/shooter.ts +50 -15
- package/src/shot/shot-ask.ts +10 -2
- package/src/shot/stepped-clip.ts +5 -4
- package/src/site/desk.ts +242 -0
- package/src/site/routes.ts +66 -0
- package/src/site/unit.ts +62 -0
- package/src/social/brands.ts +22 -0
- package/src/social/compose.ts +97 -0
- package/src/social/desk-index.ts +123 -0
- package/src/social/desk-wire.ts +64 -0
- package/src/social/drafts.ts +183 -0
- package/src/social/house.ts +24 -0
- package/src/social/load.ts +319 -0
- package/src/social/md.ts +70 -0
- package/src/social/media-facts.ts +53 -0
- package/src/social/media-kind.ts +189 -0
- package/src/social/media-limit.ts +42 -0
- package/src/social/media-of.ts +30 -0
- package/src/social/migrate.ts +123 -0
- package/src/social/open.ts +17 -0
- package/src/social/post-url.ts +158 -0
- package/src/social/presence.ts +332 -0
- package/src/social/public-read.ts +53 -0
- package/src/social/publish/bluesky.ts +168 -0
- package/src/social/publish/discord.ts +76 -0
- package/src/social/publish/index.ts +24 -0
- package/src/social/publish/secret.ts +13 -0
- package/src/social/push.ts +31 -0
- package/src/social/richtext.ts +37 -0
- package/src/social/routes.ts +180 -0
- package/src/social/stats.ts +134 -0
- package/src/social/text.ts +267 -0
- package/src/social/tracker-route.ts +39 -0
- package/src/social/tracker.ts +255 -0
- package/src/social/unit.ts +53 -0
- package/src/social/writes.ts +130 -0
- package/src/start-repo.ts +14 -9
- package/src/stores/collection.ts +27 -0
- package/src/stores/desk.ts +336 -0
- package/src/stores/model.ts +187 -0
- package/src/stores/routes.ts +126 -0
- package/src/stores/unit.ts +57 -0
- package/src/suite/calibrate.ts +127 -0
- package/src/suite/core-counters.ts +91 -0
- package/src/suite/judge-suites.ts +94 -34
- package/src/suite/suite-cli.ts +44 -10
- package/src/suite/suite-cpu-preload.ts +34 -9
- package/src/trailer/adapter.ts +4 -0
- package/src/trailer/build.ts +42 -11
- package/src/trailer/ffmpeg.ts +11 -0
- package/src/trailer/footage.ts +30 -13
- package/src/trailer/grammar.ts +18 -2
- package/src/trailer/graph.ts +28 -6
- package/src/trailer/passage.ts +17 -5
- package/src/trailer/plan.ts +74 -3
- package/src/trailer/stitch.ts +67 -26
- package/src/trailer/url.ts +1 -1
- package/src/trailer/versions.ts +24 -0
- package/src/ts/gate-typecheck.ts +32 -0
- package/src/ts/typecheck-cli.ts +9 -11
- package/src/tui/tui-app.tsx +0 -1
- package/src/veille/asks.ts +155 -0
- package/src/veille/auto.ts +31 -0
- package/src/veille/batch.ts +27 -0
- package/src/veille/chrome.ts +127 -0
- package/src/veille/collection.ts +28 -0
- package/src/veille/desk.ts +242 -0
- package/src/veille/identity.ts +80 -0
- package/src/veille/import.ts +68 -0
- package/src/veille/log.ts +183 -0
- package/src/veille/platforms.ts +118 -0
- package/src/veille/reads.ts +66 -0
- package/src/veille/replied.ts +110 -0
- package/src/veille/routes.ts +185 -0
- package/src/veille/service.ts +81 -0
- package/src/veille/watch.ts +116 -0
- package/src/veille/worth.ts +46 -0
- package/src/wiki/scan-md.ts +18 -0
- package/src/collections/posts.ts +0 -142
- package/src/contracts/manifests/social.contract.ts +0 -20
- package/src/scaffold/files/agent-coding.md +0 -35
- package/src/ts/typecheck-cache.ts +0 -11
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// /api/projects/fork in Fork: a request names a repo, never a path. The rail ORDER is one text file for the whole machine
|
|
11
11
|
// (ORDER_FILE), so every hub shows the same order and a hand edit is seen
|
|
12
12
|
// within one poll; POST /api/projects/order writes it.
|
|
13
|
+
import { loopWatch } from '../core/loop-watch.ts'
|
|
13
14
|
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'fs'
|
|
14
15
|
import { readFile, stat } from 'fs/promises'
|
|
15
16
|
import { homedir } from 'os'
|
|
@@ -24,7 +25,11 @@ import { identityOfText, identityProblem, type Identity } from '../core/identity
|
|
|
24
25
|
import { writeIdentity } from '../core/identity.ts'
|
|
25
26
|
import { appIconOf, appIconPngs, identityOfRoot } from '../core/app-icon.ts'
|
|
26
27
|
import { waitingCards } from '../collections/review.ts'
|
|
28
|
+
import { storeDir, warmStore } from '../review/store.ts'
|
|
27
29
|
import { writeArchived } from '../core/archived.ts'
|
|
30
|
+
import { identitiesDir } from '../identities/identities.ts'
|
|
31
|
+
import { identityCache, markFile, railOf, speakerIdOf, type RailIdentity } from '../identities/machine.ts'
|
|
32
|
+
import { speaksAsOfText } from '../social/house.ts'
|
|
28
33
|
|
|
29
34
|
export type { Gate }
|
|
30
35
|
|
|
@@ -42,6 +47,8 @@ function cardsOf(path: string): ProjectRow['cards'] {
|
|
|
42
47
|
const PREVIEW_PX = 256
|
|
43
48
|
/** the rail's app icon, cropped to the plate: 40px at 2x, the largest rail size */
|
|
44
49
|
const RAIL_PX = 96
|
|
50
|
+
/** the plate's opacity on a rail row that is not shown: the mark stays whole, project-list.css fades the rest */
|
|
51
|
+
const DIM_PLATE = 0.5
|
|
45
52
|
/** how long a release answer holds for a checkout whose `.git` is not a
|
|
46
53
|
* folder, since no stat can say when it moved */
|
|
47
54
|
export const RELEASE_TTL_MS = 60_000
|
|
@@ -88,8 +95,12 @@ export type ProjectRow = {
|
|
|
88
95
|
live: string | null
|
|
89
96
|
/** the colours its repo.config.ts declares (SK024), null when it declares none */
|
|
90
97
|
identity: Identity | null
|
|
98
|
+
/** the identity it speaks as (wiki build/shipkit/social.md): its `speaksAs`, else the default; null when none holds it */
|
|
99
|
+
speaksAs: string | null
|
|
91
100
|
/** its app icon cropped to the plate (core/app-icon.ts), what the folded rail draws; null with no mark */
|
|
92
101
|
appIcon: string | null
|
|
102
|
+
/** the same with its plate faded and its mark whole: the folded rail's rows that are not shown */
|
|
103
|
+
appIconDim: string | null
|
|
93
104
|
/** epoch ms of the newest of: the last commit, the last shipkit run, the
|
|
94
105
|
* newest Claude Code transcript. null when none of them exists */
|
|
95
106
|
activity: number | null
|
|
@@ -99,7 +110,8 @@ export type ProjectRow = {
|
|
|
99
110
|
/** a repo whose repo.config.ts says `archived: true`: only the archived page lists it */
|
|
100
111
|
export type ArchivedRow = { name: string; icon: string | null }
|
|
101
112
|
|
|
102
|
-
|
|
113
|
+
/** `identities`: every identity of the machine, in their order, as the list's headers draw them */
|
|
114
|
+
export type ProjectsAnswer = { projects: ProjectRow[]; archived: ArchivedRow[]; identities: RailIdentity[]; ms: number; at: number }
|
|
103
115
|
|
|
104
116
|
/** a command's exit code and stdout, or null when its binary is missing */
|
|
105
117
|
export type Run = (cmd: string[], cwd?: string) => Promise<{ code: number; out: string } | null>
|
|
@@ -132,7 +144,7 @@ const runCmd: Run = async (cmd, cwd) => {
|
|
|
132
144
|
return { code: await p.exited, out }
|
|
133
145
|
}
|
|
134
146
|
|
|
135
|
-
function openInCode(path: string): void {
|
|
147
|
+
export function openInCode(path: string): void {
|
|
136
148
|
const code = Bun.which('code')
|
|
137
149
|
if (code != null) {
|
|
138
150
|
Bun.spawn([code, path], { stdio: ['ignore', 'ignore', 'ignore'] }).unref()
|
|
@@ -315,26 +327,36 @@ export function projectGutter(d: GutterDeps) {
|
|
|
315
327
|
|
|
316
328
|
const iconUrl = (r: WiredRepo): string | null => (r.icon == null ? null : `/api/projects/icon/${encodeURIComponent(r.name)}?v=${iconStamp(join(r.path, r.icon))}`)
|
|
317
329
|
// the url names the mark's stamp and both colours, so a new mark or a colour change is a new url, cached a day
|
|
318
|
-
const railIconUrl = (r: WiredRepo, id: Identity): string | null => {
|
|
330
|
+
const railIconUrl = (r: WiredRepo, id: Identity, plate: '1' | 'dim' = '1'): string | null => {
|
|
319
331
|
const mark = appIconOf(r.path)
|
|
320
332
|
if (mark == null) return null
|
|
321
|
-
const q = new URLSearchParams({ plate
|
|
333
|
+
const q = new URLSearchParams({ plate, light: id.colorLight, dark: id.colorDark, v: String(iconStamp(mark)) })
|
|
322
334
|
return `/api/projects/app-icon/${encodeURIComponent(r.name)}?${q}`
|
|
323
335
|
}
|
|
324
336
|
/** drawn plates, by url: a page load asks for every repo's at once */
|
|
325
337
|
const plates = new Map<string, Promise<Buffer>>()
|
|
338
|
+
const identities = identityCache()
|
|
339
|
+
let idDir: string | null | undefined
|
|
340
|
+
const readIds = async () => identities(idDir === undefined ? (idDir = await identitiesDir(d.root)) : idDir)
|
|
326
341
|
|
|
327
342
|
async function measure(): Promise<ProjectsAnswer> {
|
|
328
343
|
const t0 = performance.now()
|
|
329
|
-
const house = houseRepos(d.root, userHome)
|
|
344
|
+
const house = loopWatch.timed('projects: house repos', () => houseRepos(d.root, userHome))
|
|
330
345
|
home = house.home
|
|
331
346
|
if (house.index == null) warnOnce('house', `WARN project gutter: ${home} includes no house wiki index, so no sibling shares one and the gutter is empty`)
|
|
332
347
|
repos = house.repos
|
|
333
348
|
archivedRepos = house.archived
|
|
334
|
-
const [open, cwds, facts] = await Promise.all([
|
|
335
|
-
|
|
349
|
+
const [open, cwds, facts] = await Promise.all([
|
|
350
|
+
loopWatch.spanned('projects: vscode', vscodeFolders),
|
|
351
|
+
loopWatch.spanned('projects: sessions', sessionCwds),
|
|
352
|
+
loopWatch.spanned('projects: git', () => gitFacts(repos.map((r) => r.path))),
|
|
353
|
+
])
|
|
354
|
+
const transcripts = loopWatch.timed('projects: transcripts', () => lastSessionAt(transcriptRoots(), repos.map((r) => r.path)))
|
|
336
355
|
const counts = cwds == null ? null : countSessions(cwds, repos.map((r) => r.path))
|
|
337
|
-
const
|
|
356
|
+
const ids = await loopWatch.spanned('projects: ids', readIds)
|
|
357
|
+
// each store read whole once, in steps, before the rows read its waiting cards
|
|
358
|
+
await loopWatch.spanned('projects: review stores', async () => { for (const r of repos) await warmStore(storeDir(r.path)) })
|
|
359
|
+
const projects = repos.map((r, i): ProjectRow => loopWatch.timed(`projects: row ${r.name}`, () => {
|
|
338
360
|
const config = readText(join(r.path, 'repo.config.ts'))
|
|
339
361
|
const pkg = readText(join(r.path, 'package.json'))
|
|
340
362
|
const asks = openAsks(join(r.path, asksDirOf(config, r.path)))
|
|
@@ -360,13 +382,15 @@ export function projectGutter(d: GutterDeps) {
|
|
|
360
382
|
release: facts[i]!.release,
|
|
361
383
|
live: liveUrlOf(config),
|
|
362
384
|
identity: identityOfText(config),
|
|
385
|
+
speaksAs: speakerIdOf(speaksAsOfText(config), ids),
|
|
363
386
|
appIcon: railIconUrl(r, identityOfRoot(r.path)),
|
|
387
|
+
appIconDim: railIconUrl(r, identityOfRoot(r.path), 'dim'),
|
|
364
388
|
activity: lastActivity(facts[i]!.commitAt, lastRunAt(r.path), transcripts.get(r.path)),
|
|
365
389
|
commit: facts[i]!.commitAt,
|
|
366
390
|
}
|
|
367
|
-
})
|
|
391
|
+
}))
|
|
368
392
|
const archived = archivedRepos.map((r) => ({ name: r.name, icon: iconUrl(r) }))
|
|
369
|
-
return { projects: inOrder(projects, parseOrder(readText(orderFile))), archived, ms: Math.round(performance.now() - t0), at: now() }
|
|
393
|
+
return { projects: inOrder(projects, parseOrder(readText(orderFile))), archived, identities: ids.identities.map(railOf), ms: Math.round(performance.now() - t0), at: now() }
|
|
370
394
|
}
|
|
371
395
|
|
|
372
396
|
/** the last answer while it is younger than POLL_MS, one measure otherwise,
|
|
@@ -412,6 +436,13 @@ export function projectGutter(d: GutterDeps) {
|
|
|
412
436
|
headers: { 'content-type': ICON_TYPES[r.icon.split('.').pop()!] ?? 'application/octet-stream', 'cache-control': 'max-age=86400' },
|
|
413
437
|
})
|
|
414
438
|
}
|
|
439
|
+
if (path.startsWith('/api/projects/identity-mark/')) {
|
|
440
|
+
const id = decodeURIComponent(path.slice('/api/projects/identity-mark/'.length))
|
|
441
|
+
const i = (await readIds()).identities.find((x) => x.id === id)
|
|
442
|
+
const file = i == null ? null : markFile(i)
|
|
443
|
+
if (file == null || !existsSync(file)) return new Response(`no mark for the identity ${JSON.stringify(id)}`, { status: 404 })
|
|
444
|
+
return new Response(Bun.file(file), { headers: { 'cache-control': 'max-age=86400' } })
|
|
445
|
+
}
|
|
415
446
|
if (path.startsWith('/api/projects/app-icon/')) {
|
|
416
447
|
if (repos.length === 0) await answer()
|
|
417
448
|
const r = findAny(decodeURIComponent(path.slice('/api/projects/app-icon/'.length)))
|
|
@@ -423,11 +454,12 @@ export function projectGutter(d: GutterDeps) {
|
|
|
423
454
|
const asked = { colorLight: q.get('light') ?? '', colorDark: q.get('dark') ?? '' }
|
|
424
455
|
const id = identityProblem(asked) == null ? asked : identityOfRoot(r.path)
|
|
425
456
|
try {
|
|
426
|
-
|
|
457
|
+
const plate = q.get('plate')
|
|
458
|
+
if (plate === '1' || plate === 'dim') {
|
|
427
459
|
const key = `${r.path}?${q}`
|
|
428
460
|
let png = plates.get(key)
|
|
429
461
|
if (png == null) {
|
|
430
|
-
png = readFile(icon).then(async (b) => (await appIconPngs(b, id, [RAIL_PX], 'plate'))[0]!)
|
|
462
|
+
png = readFile(icon).then(async (b) => (await appIconPngs(b, id, [RAIL_PX], 'plate', { plateAlpha: plate === 'dim' ? DIM_PLATE : 1 }))[0]!)
|
|
431
463
|
plates.set(key, png)
|
|
432
464
|
png.catch(() => plates.delete(key))
|
|
433
465
|
}
|
package/src/serve/run-lanes.ts
CHANGED
|
@@ -108,10 +108,13 @@ export function runKey(kind: string, opts: Record<string, unknown>): string {
|
|
|
108
108
|
return `${kind} ${JSON.stringify(sorted)}`
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
/** a
|
|
112
|
-
* and the hooks
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
/** a WHOLE gate whose repair pass runs (core/fix-scope.ts): its tree wide
|
|
112
|
+
* fixers and the hooks run there. A narrowed run repairs only what its checks
|
|
113
|
+
* own, under the fix lease, so it never makes other lanes wait */
|
|
114
|
+
export const writesTree = (opts: Record<string, unknown>): boolean => {
|
|
115
|
+
const onlyIds = Array.isArray(opts.onlyIds) ? (opts.onlyIds as string[]) : undefined
|
|
116
|
+
return (onlyIds ?? []).length === 0 && fixPassRuns({ fix: typeof opts.fix === 'boolean' ? opts.fix : undefined, onlyIds })
|
|
117
|
+
}
|
|
115
118
|
|
|
116
119
|
/** HEAD, what git status lists, and the stat of each listed path, hashed:
|
|
117
120
|
* equal stamps mean no tracked or untracked file moved in between. Null
|
package/src/serve/same-origin.ts
CHANGED
|
@@ -10,7 +10,7 @@ export function sameOrigin(req: Request): boolean {
|
|
|
10
10
|
if (site != null && site !== 'same-origin' && site !== 'none') return false
|
|
11
11
|
const origin = req.headers.get('origin')
|
|
12
12
|
if (origin == null) return true
|
|
13
|
-
// behind a proxy that frames the page under its own origin (
|
|
13
|
+
// behind a proxy that frames the page under its own origin (a project's admin), the host the browser asked is the
|
|
14
14
|
// proxy's, which it passes on. A browser cannot forge the header: a page of another site that sets it is held at
|
|
15
15
|
// its preflight, which this server never answers
|
|
16
16
|
const host = req.headers.get('x-forwarded-host') ?? new URL(req.url).host
|
package/src/serve/serve-hub.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { pageOf, searchWiki } from 'rvlib-shipkit/src/wiki/graph-pages.ts'
|
|
|
11
11
|
import { graphRoutes } from 'rvlib-shipkit/src/wiki/serve-graph.ts'
|
|
12
12
|
import type { StudioRoutes } from '../assets/server/studio-server.ts'
|
|
13
13
|
import { comfyBoxUp, type ComfyBox, type ComfyPanelUp } from '../comfy/comfy-panel.ts'
|
|
14
|
-
import { appendAskRemark, appendAssetNote,
|
|
14
|
+
import { appendAskRemark, appendAssetNote, askDone, askProof } from '../collections/actions.ts'
|
|
15
15
|
import { brokenRow, projectResources, type Collection, type Instance, type NeedItem, type Resource } from '../collections/collection-types.ts'
|
|
16
16
|
import type { CheckEvent } from '../core/run-check.ts'
|
|
17
17
|
import { configDirty, readGateBlock, writeGateBlock, type GateEdit } from '../core/when-block.ts'
|
|
@@ -36,7 +36,11 @@ import { WarmCell } from './warm-cell.ts'
|
|
|
36
36
|
import { resourcesAnswer, testRunsAnswer } from './resources-wire.ts'
|
|
37
37
|
import { readmeRoutes } from './readme-route.ts'
|
|
38
38
|
import { reviewRoutes } from '../review/routes.ts'
|
|
39
|
+
import { veilleRoutes } from '../veille/routes.ts'
|
|
40
|
+
import { storesRoutes } from '../stores/routes.ts'
|
|
41
|
+
import { socialRoutes } from '../social/routes.ts'
|
|
39
42
|
import { embedRoute } from './embed.ts'
|
|
43
|
+
import { pagesRoutes } from '../pages/routes.ts'
|
|
40
44
|
|
|
41
45
|
export { sameOrigin }
|
|
42
46
|
|
|
@@ -186,10 +190,10 @@ export function hubHandler(d: HubDeps, o: { base?: string; projects?: Gutter } =
|
|
|
186
190
|
await d.refresh?.()
|
|
187
191
|
const cols = d.collections()
|
|
188
192
|
return { collections: cols.map((c) => ({ id: c.id, title: c.title, media: c.media })), resources: await projectResources(cols, d.hubProblems?.collector) }
|
|
189
|
-
}, warmOpts)
|
|
193
|
+
}, { ...warmOpts, what: `warm rows: ${d.name}` })
|
|
190
194
|
// the run record and the config are all it reads, and the stamp sees both
|
|
191
|
-
const timeline = d.timeline == null ? null : new WarmCell(d.timeline, { stamp: d.stamp })
|
|
192
|
-
const graphs = new Map(d.graphs.map((g) => [g.id, new WarmCell(async () => g.load(), { maxAgeMs: WARM_MAX_AGE_MS })]))
|
|
195
|
+
const timeline = d.timeline == null ? null : new WarmCell(d.timeline, { stamp: d.stamp, what: `warm timeline: ${d.name}` })
|
|
196
|
+
const graphs = new Map(d.graphs.map((g) => [g.id, new WarmCell(async () => g.load(), { maxAgeMs: WARM_MAX_AGE_MS, what: `warm graph ${g.id}: ${d.name}` })]))
|
|
193
197
|
const fresh = (req: Request): boolean => new URL(req.url).searchParams.get('fresh') === '1'
|
|
194
198
|
/** the last gzipped list, answered again to the next page while it holds */
|
|
195
199
|
let zipped: Parameters<typeof resourcesAnswer>[3] = null
|
|
@@ -276,13 +280,6 @@ export function hubHandler(d: HubDeps, o: { base?: string; projects?: Gutter } =
|
|
|
276
280
|
const b = (await req.json()) as Record<string, string>
|
|
277
281
|
if (path === '/api/act/ask-done') askDone(d.root, d.asksDir, b.file ?? '')
|
|
278
282
|
else if (path === '/api/act/ask-proof') askProof(d.root, d.asksDir, b.file ?? '', b.url ?? '')
|
|
279
|
-
else if (path === '/api/act/post-pick') pickPostVariant(d.root, b.channel ?? '', b.file ?? '')
|
|
280
|
-
else if (path === '/api/act/post-posted') {
|
|
281
|
-
const rating = b.rating != null ? Number(b.rating) : undefined
|
|
282
|
-
if (rating != null && (!Number.isFinite(rating) || rating < 1 || rating > 5)) return new Response('rating must be 1-5', { status: 400 })
|
|
283
|
-
markPosted(d.root, b.channel ?? '', b.file ?? '', b.url ?? '', rating)
|
|
284
|
-
}
|
|
285
|
-
else if (path === '/api/act/post-feedback') appendPostFeedback(d.root, b.channel ?? '', b.file ?? '', b.text ?? '')
|
|
286
283
|
else if (path === '/api/act/remark') {
|
|
287
284
|
// ONE remark verb, routed by collection: a remark
|
|
288
285
|
// lands in the item's own truth file
|
|
@@ -290,7 +287,6 @@ export function hubHandler(d: HubDeps, o: { base?: string; projects?: Gutter } =
|
|
|
290
287
|
if (text === '') return new Response('empty remark', { status: 400 })
|
|
291
288
|
if (b.kind === 'ask') appendAskRemark(d.root, d.asksDir, b.file ?? '', text)
|
|
292
289
|
else if (b.kind === 'media') appendAssetNote(d.root, b.id ?? '', text)
|
|
293
|
-
else if (b.kind === 'post') appendPostFeedback(d.root, b.channel ?? '', b.file ?? '', text)
|
|
294
290
|
else return new Response('unknown remark kind', { status: 400 })
|
|
295
291
|
}
|
|
296
292
|
else return new Response('unknown act', { status: 404 })
|
|
@@ -346,12 +342,24 @@ export function hubHandler(d: HubDeps, o: { base?: string; projects?: Gutter } =
|
|
|
346
342
|
// the empty page shows the README, its images served from the repo
|
|
347
343
|
const readme = await readmeRoutes(d.root, path)
|
|
348
344
|
if (readme != null) return readme
|
|
345
|
+
// the repo's own pages: their list, each one proxied from the repo's process (pages/routes.ts)
|
|
346
|
+
const pages = await pagesRoutes(d.root, req, path, srv)
|
|
347
|
+
if (pages != null) return pages
|
|
349
348
|
// the review or trailer page alone, for another tool's frame (embed.ts)
|
|
350
349
|
const embed = await embedRoute(path)
|
|
351
350
|
if (embed != null) return embed
|
|
352
351
|
// the one feedback store and the trailer view (review/routes.ts)
|
|
353
352
|
const review = await reviewRoutes(d.root, req, path)
|
|
354
353
|
if (review != null) return review
|
|
354
|
+
// the Veille of the identity this repo speaks as (veille/routes.ts)
|
|
355
|
+
const veille = await veilleRoutes(d.root, req, path)
|
|
356
|
+
if (veille != null) return veille
|
|
357
|
+
// the store pages' desk (stores/routes.ts)
|
|
358
|
+
const stores = await storesRoutes(d.root, req, path)
|
|
359
|
+
if (stores != null) return stores
|
|
360
|
+
// the Communications and Social desks (social/routes.ts)
|
|
361
|
+
const social = await socialRoutes(d.root, req, path)
|
|
362
|
+
if (social != null) return social
|
|
355
363
|
if (path === '/api/status.json') {
|
|
356
364
|
const p = join(d.root, LAYOUT.status)
|
|
357
365
|
return Response.json({ statusMd: existsSync(p) ? await Bun.file(p).text() : null })
|
|
@@ -7,6 +7,8 @@ import { join } from 'path'
|
|
|
7
7
|
import { GENERATED_IGNORE_LINES } from '../rules/untrack-generated.ts'
|
|
8
8
|
import { gitBin } from '../core/git-bin.ts'
|
|
9
9
|
import { LAYOUT } from '../core/layout.ts'
|
|
10
|
+
import { followTree, treeMoved } from '../core/tree-rev.ts'
|
|
11
|
+
import { yieldLoop } from '../core/loop-watch.ts'
|
|
10
12
|
|
|
11
13
|
/** every path a run of the gate or the hub itself writes, whatever the repo
|
|
12
14
|
* ignores: the status files, the per run logs under the scratch dir, an atomic write's
|
|
@@ -58,8 +60,14 @@ export function isRefMove(rel: string): boolean {
|
|
|
58
60
|
* or untracked and not ignored. What the gate itself writes (GATE_WRITES,
|
|
59
61
|
* the ledger in .git) never counts, ignored or not, so a run never triggers
|
|
60
62
|
* the next one */
|
|
61
|
-
export function watchTracked(root: string,
|
|
63
|
+
export function watchTracked(root: string, onOwnerEdit: () => void, o: { ignored?: (paths: string[]) => Promise<Set<string>>; onError?: (e: Error) => void } = {}): { close: () => void; error: string | null } {
|
|
62
64
|
const ignored = o.ignored ?? ((paths: string[]) => gitIgnored(root, paths))
|
|
65
|
+
// the tree's revision (core/tree-rev.ts) moves with every edit this watch hears, and is gone with the watch
|
|
66
|
+
let unfollow: (() => void) | null = null
|
|
67
|
+
const onChange = (): void => {
|
|
68
|
+
treeMoved(root)
|
|
69
|
+
onOwnerEdit()
|
|
70
|
+
}
|
|
63
71
|
const pending = new Set<string>()
|
|
64
72
|
let flushing = false
|
|
65
73
|
const flush = async (): Promise<void> => {
|
|
@@ -89,11 +97,21 @@ export function watchTracked(root: string, onChange: () => void, o: { ignored?:
|
|
|
89
97
|
})
|
|
90
98
|
// a watcher that dies mid session (the tree was removed, a limit hit)
|
|
91
99
|
// says so, rather than crashing the hub or going quiet
|
|
92
|
-
w.on('error', (e) =>
|
|
100
|
+
w.on('error', (e) => {
|
|
101
|
+
unfollow?.()
|
|
102
|
+
o.onError?.(e instanceof Error ? e : new Error(String(e)))
|
|
103
|
+
})
|
|
104
|
+
unfollow = followTree(root)
|
|
93
105
|
} catch (e) {
|
|
94
106
|
error = e instanceof Error ? e.message : String(e)
|
|
95
107
|
}
|
|
96
|
-
return {
|
|
108
|
+
return {
|
|
109
|
+
close: () => {
|
|
110
|
+
unfollow?.()
|
|
111
|
+
w?.close()
|
|
112
|
+
},
|
|
113
|
+
error,
|
|
114
|
+
}
|
|
97
115
|
}
|
|
98
116
|
|
|
99
117
|
/** did the owner edit anything after `since`: a tracked file, or an untracked
|
|
@@ -112,7 +130,10 @@ export async function movedSince(root: string, since: number): Promise<boolean>
|
|
|
112
130
|
const later = (rel: string): boolean => {
|
|
113
131
|
try { return statSync(join(root, rel)).mtimeMs > since } catch { return false }
|
|
114
132
|
}
|
|
133
|
+
let n = 0
|
|
115
134
|
for (const rel of out.split('\0')) {
|
|
135
|
+
// a stat a file over tens of thousands: the loop is given back between two thousand of them
|
|
136
|
+
if (++n % 2_000 === 0) await yieldLoop()
|
|
116
137
|
if (rel === '' || rel.split('/').includes('node_modules') || isGateWrite(rel)) continue
|
|
117
138
|
if (later(rel)) return true
|
|
118
139
|
}
|
package/src/serve/warm-cell.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
// changed the truth (an act, the end of a run) asks for `fresh`, which waits
|
|
10
10
|
// on a compute that started after its call.
|
|
11
11
|
|
|
12
|
+
import { loopWatch } from '../core/loop-watch.ts'
|
|
13
|
+
|
|
12
14
|
/** a cell read within this long has a reader: a save recomputes it in the
|
|
13
15
|
* background. Past it, nothing recomputes until a reader asks */
|
|
14
16
|
export const WARM_WATCH_MS = 30_000
|
|
@@ -25,6 +27,8 @@ export type WarmCellOpts = {
|
|
|
25
27
|
* nothing said it moved: what no watch sees (a clock, another repo) */
|
|
26
28
|
maxAgeMs?: number
|
|
27
29
|
now?: () => number
|
|
30
|
+
/** the span a compute carries on the loop watch (core/loop-watch.ts), so a stall names it */
|
|
31
|
+
what?: string
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
export class WarmCell<T> {
|
|
@@ -54,7 +58,7 @@ export class WarmCell<T> {
|
|
|
54
58
|
const p = (async (): Promise<T> => {
|
|
55
59
|
try {
|
|
56
60
|
// never synchronously: `running` is set before this settles
|
|
57
|
-
const v = await Promise.resolve().then(() => this.compute())
|
|
61
|
+
const v = await Promise.resolve().then(() => (this.o.what == null ? this.compute() : loopWatch.spanned(this.o.what, () => this.compute())))
|
|
58
62
|
this.value = { v, at: this.now(), stamp }
|
|
59
63
|
return v
|
|
60
64
|
} finally {
|
package/src/shipkit-files.ts
CHANGED
|
@@ -11,16 +11,26 @@
|
|
|
11
11
|
// review({...}) the repo's parts of the review store: its subject
|
|
12
12
|
// kinds, topics, sources, auto rules, the dispatcher
|
|
13
13
|
// (review/unit.ts)
|
|
14
|
+
// social({...}) the repo's parts of the social desks: its topics,
|
|
15
|
+
// its articles and their preview (social/unit.ts)
|
|
16
|
+
// stores({...}) the repo's parts of the stores desk: extra texts,
|
|
17
|
+
// the account's ask, the commands that make its
|
|
18
|
+
// pictures again (stores/unit.ts)
|
|
19
|
+
// site({...}) the repo's parts of its identity's site desk: its
|
|
20
|
+
// pages, preview, deploy, what changed (site/unit.ts)
|
|
14
21
|
//
|
|
15
22
|
// the one constraint a reader breaks first: every kind is IMPORTED by the
|
|
16
23
|
// process that reads it (discovery, pm's config child, the daemon), so a file
|
|
17
24
|
// keeps its top level cheap and puts heavy work inside a function.
|
|
18
25
|
import { check, type CheckDef } from './check.ts'
|
|
19
26
|
import { review, type AutoRule, type KindDef, type ReviewDef, type ReviewSource, type ReviewUnit } from './review/unit.ts'
|
|
27
|
+
import { site, type SiteDef, type SiteUnit } from './site/unit.ts'
|
|
28
|
+
import { social, type SocialDef, type SocialUnit } from './social/unit.ts'
|
|
29
|
+
import { stores, type StoresDef, type StoresUnit } from './stores/unit.ts'
|
|
20
30
|
import { trailer, type TrailerDef, type TrailerUnit } from './trailer/adapter.ts'
|
|
21
31
|
|
|
22
|
-
export { check, review, trailer }
|
|
23
|
-
export type { AutoRule, KindDef, ReviewDef, ReviewSource, ReviewUnit, TrailerDef, TrailerUnit }
|
|
32
|
+
export { check, review, site, social, stores, trailer }
|
|
33
|
+
export type { AutoRule, KindDef, ReviewDef, ReviewSource, ReviewUnit, SiteDef, SiteUnit, SocialDef, SocialUnit, StoresDef, StoresUnit, TrailerDef, TrailerUnit }
|
|
24
34
|
|
|
25
35
|
/** one button beside a global process: a command, or a function of the file */
|
|
26
36
|
export type ProcessAction = {
|
|
@@ -77,7 +87,7 @@ export type WidgetDef = {
|
|
|
77
87
|
export type GlobalProcessUnit = GlobalProcessDef & { kind: 'globalProcess' }
|
|
78
88
|
export type WidgetUnit = WidgetDef & { kind: 'widget' }
|
|
79
89
|
|
|
80
|
-
export const UNIT_KINDS = ['globalProcess', 'widget', 'trailer', 'review'] as const
|
|
90
|
+
export const UNIT_KINDS = ['globalProcess', 'widget', 'trailer', 'review', 'stores', 'social', 'site', 'page'] as const
|
|
81
91
|
|
|
82
92
|
const KEBAB = /^[a-z0-9][a-z0-9-]*$/
|
|
83
93
|
const words = (v: unknown): boolean => Array.isArray(v) && v.length > 0 && v.every((w) => typeof w === 'string')
|
|
@@ -132,7 +142,8 @@ export function widget(d: WidgetDef): WidgetUnit {
|
|
|
132
142
|
|
|
133
143
|
/** the kind a default export says it is: a unit, else a check */
|
|
134
144
|
export function unitKind(d: unknown): (typeof UNIT_KINDS)[number] | 'check' {
|
|
135
|
-
|
|
145
|
+
// a repo's pages may come as one array (src/pages/unit.ts)
|
|
146
|
+
const k = Array.isArray(d) && d.length > 0 && d.every((u) => (u as { kind?: unknown } | null)?.kind === 'page') ? 'page' : (d as { kind?: unknown } | null)?.kind
|
|
136
147
|
return UNIT_KINDS.includes(k as (typeof UNIT_KINDS)[number]) ? (k as (typeof UNIT_KINDS)[number]) : 'check'
|
|
137
148
|
}
|
|
138
149
|
|
package/src/shipkit.ts
CHANGED
|
@@ -20,7 +20,6 @@ export { resolveHubDeps, defaultHubPort, baseWikiRoot, loadHub } from './serve/h
|
|
|
20
20
|
export { projectNeeds, redCount } from './collections/collection-types.ts'
|
|
21
21
|
export type { Collection, Instance, NeedItem, NeedSeverity, CurationVerb } from './collections/collection-types.ts'
|
|
22
22
|
export { buildCollections } from './collections/providers.ts'
|
|
23
|
-
export { socialPostsCollection, listPosts } from './collections/posts.ts'
|
|
24
23
|
// units — the ONE discovery every release surface reads (drift
|
|
25
24
|
// probes, per-unit tests, per-unit typecheck, the stranded-tag probe)
|
|
26
25
|
export { resolveUnits, releaseOrder, unitById, renderTag, tagGlobs, prepublishScripts, unitPrepublishScripts } from './release/units.ts'
|
package/src/shot/box.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// THE BOX ROUTE: a repo whose repo.config.ts `browsers.box` names an ssh host films there when it runs on a Mac. Every
|
|
2
|
+
// browser start of the repo (a take, a Shooter: sk shot, look sheets, thumbs, the trailer's films) asks `openBrowser`,
|
|
3
|
+
// which on such a Mac connects to the box's warm chromium (film-box.ts) instead of launching one: its devtools reached
|
|
4
|
+
// through an ssh forward, each localhost page it opens reached back on this Mac through a reverse forward (the urls
|
|
5
|
+
// unchanged), its frames drawn and encoded on the box's GPU, only the result crossing back. Anywhere else, or with
|
|
6
|
+
// SK_FILM_HERE=1 for one run, it launches here as before, under the browser cap either way.
|
|
7
|
+
//
|
|
8
|
+
// The one constraint a reader breaks first: a box that does not answer is one loud line and nothing filmed, never a
|
|
9
|
+
// browser launched on the Mac instead (the Mac is the machine the route protects).
|
|
10
|
+
import { createHash } from 'crypto'
|
|
11
|
+
import { readFileSync } from 'fs'
|
|
12
|
+
import { browserCap, type BrowserCap, browserSlot, HERE_ENV } from './browser-slot.ts'
|
|
13
|
+
import { CDP_PORT } from './film-box.ts'
|
|
14
|
+
|
|
15
|
+
/** the box this machine films on for the repo, or null: a Mac whose repo names one, unless SK_FILM_HERE=1 */
|
|
16
|
+
export function filmBox(c: Pick<BrowserCap, 'box'> | null, env: Record<string, string | undefined> = process.env, platform = process.platform): string | null {
|
|
17
|
+
return c?.box != null && platform === 'darwin' && env[HERE_ENV] !== '1' ? c.box : null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** the slice of playwright the route drives: a browser to connect to, its default context, a page's viewport */
|
|
21
|
+
type PwPage = { setViewportSize(v: { width: number; height: number }): Promise<void>; addInitScript(s: { content: string }): Promise<void>; close(): Promise<void> }
|
|
22
|
+
type PwContext = { newPage(): Promise<PwPage>; newCDPSession(p: PwPage): Promise<{ send(m: string, p?: Record<string, unknown>): Promise<unknown> }> }
|
|
23
|
+
export type PwBrowser = { contexts(): PwContext[]; close(): Promise<void>; isConnected(): boolean; on(e: 'disconnected', cb: () => void): void }
|
|
24
|
+
export type Pw = { chromium: { launch(o: { headless: boolean; args: string[] }): Promise<unknown>; connectOverCDP(url: string): Promise<PwBrowser> } }
|
|
25
|
+
|
|
26
|
+
/** a browser opened for a repo: `browser` takes newContext as a launched one does; `reach` before a page goes to a
|
|
27
|
+
* url (the box needs this Mac's localhost port forwarded); `close` ends it and frees its slot */
|
|
28
|
+
export type Opened<B> = { browser: B; where: string; reach(url: string): Promise<void>; close(): Promise<void> }
|
|
29
|
+
|
|
30
|
+
const SSH = (box: string) => ['ssh', '-o', 'ConnectTimeout=5', '-o', 'BatchMode=yes', box]
|
|
31
|
+
/** where the box's devtools answer on this Mac */
|
|
32
|
+
const localCdp = (box: string): number => 40000 + (parseInt(createHash('sha1').update(box).digest('hex').slice(0, 4), 16) % 9000)
|
|
33
|
+
const FILM_DIR = 'dev/shipkit-film'
|
|
34
|
+
const BOX_FILE = new URL('./film-box.ts', import.meta.url).pathname
|
|
35
|
+
const BOX_SCRIPT = readFileSync(BOX_FILE)
|
|
36
|
+
const BOX_HASH = createHash('sha1').update(BOX_SCRIPT).digest('hex').slice(0, 12)
|
|
37
|
+
const MISSING = 86
|
|
38
|
+
|
|
39
|
+
const down = (box: string, why: string): Error =>
|
|
40
|
+
new Error(`${box} is down, nothing filmed (${why.trim().split('\n').at(-1) ?? why}). To film on this Mac for one run: ${HERE_ENV}=1 <the same command>`)
|
|
41
|
+
|
|
42
|
+
async function run(cmd: string[], stdin?: Uint8Array): Promise<{ code: number; out: string; err: string }> {
|
|
43
|
+
const p = Bun.spawn(cmd, { stdin: stdin ?? 'ignore', stdout: 'pipe', stderr: 'pipe' })
|
|
44
|
+
const [out, err] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text()])
|
|
45
|
+
return { code: await p.exited, out, err }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** the box's warm browser answering, its script uploaded first when the box lacks this version of it */
|
|
49
|
+
async function boxUp(box: string, version: string, say: (l: string) => void): Promise<string> {
|
|
50
|
+
const script = `${FILM_DIR}/film-box-${BOX_HASH}.ts`
|
|
51
|
+
const go = () => run([...SSH(box), `if exist ${script.replaceAll('/', '\\')} (bun ${script} up ${version}) else (exit ${MISSING})`])
|
|
52
|
+
let r = await go()
|
|
53
|
+
if (r.code === MISSING) {
|
|
54
|
+
await run([...SSH(box), `mkdir ${FILM_DIR.replaceAll('/', '\\')} 2>nul`])
|
|
55
|
+
const up = await run(['scp', '-q', '-o', 'ConnectTimeout=5', '-o', 'BatchMode=yes', BOX_FILE, `${box}:${script}`])
|
|
56
|
+
if (up.code === 255 && /connect|resolve|timed out|refused/i.test(up.err)) throw down(box, up.err)
|
|
57
|
+
if (up.code !== 0) throw new Error(`${box}: uploading ${script} failed (exit ${up.code}): ${up.err.trim()}`)
|
|
58
|
+
r = await go()
|
|
59
|
+
}
|
|
60
|
+
if (r.code === 255) throw down(box, r.err)
|
|
61
|
+
if (r.code !== 0) throw new Error(`${box}: its film browser did not come up (exit ${r.code}): ${r.err.trim()}`)
|
|
62
|
+
for (const l of r.err.split('\n').filter(Boolean)) say(l)
|
|
63
|
+
return r.out.trim()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** an ssh forward added to the box's master connection (instant, kept with it), else a tunnel process of our own */
|
|
67
|
+
async function forward(box: string, spec: string[], own: { p: ReturnType<typeof Bun.spawn> | null }): Promise<void> {
|
|
68
|
+
const r = await run(['ssh', '-O', 'forward', ...spec, box])
|
|
69
|
+
if (r.code === 0) return
|
|
70
|
+
own.p?.kill()
|
|
71
|
+
own.p = Bun.spawn([...SSH(box), '-N', '-o', 'ExitOnForwardFailure=yes', ...spec], { stdin: 'ignore', stdout: 'ignore', stderr: 'pipe' })
|
|
72
|
+
await Bun.sleep(1500)
|
|
73
|
+
if (own.p.exitCode != null) throw down(box, await new Response(own.p.stderr as ReadableStream).text())
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const LOCAL = new Set(['localhost', '127.0.0.1', '[::1]'])
|
|
77
|
+
|
|
78
|
+
/** the box's default context as a launched browser's newContext: each context a set of pages there, the viewport set
|
|
79
|
+
* per page; one context because only it keeps the profile's HTTP cache */
|
|
80
|
+
function asLaunched(b: PwBrowser, all: PwPage[]) {
|
|
81
|
+
return {
|
|
82
|
+
isConnected: () => b.isConnected(),
|
|
83
|
+
on: (e: 'disconnected', cb: () => void) => b.on(e, cb),
|
|
84
|
+
close: async () => {
|
|
85
|
+
await Promise.all(all.splice(0).map((p) => p.close().catch(() => undefined)))
|
|
86
|
+
await b.close()
|
|
87
|
+
},
|
|
88
|
+
async newContext(o: { viewport: { width: number; height: number }; deviceScaleFactor: number }) {
|
|
89
|
+
const ctx = b.contexts()[0]
|
|
90
|
+
if (ctx == null) throw new Error('the box browser has no default context')
|
|
91
|
+
const pages: PwPage[] = []
|
|
92
|
+
const scripts: string[] = []
|
|
93
|
+
return {
|
|
94
|
+
async newPage() {
|
|
95
|
+
const p = await ctx.newPage()
|
|
96
|
+
pages.push(p)
|
|
97
|
+
all.push(p)
|
|
98
|
+
await p.setViewportSize(o.viewport)
|
|
99
|
+
if (o.deviceScaleFactor !== 1)
|
|
100
|
+
await (await ctx.newCDPSession(p)).send('Emulation.setDeviceMetricsOverride', { ...o.viewport, deviceScaleFactor: o.deviceScaleFactor, mobile: false })
|
|
101
|
+
for (const content of scripts) await p.addInitScript({ content })
|
|
102
|
+
return p
|
|
103
|
+
},
|
|
104
|
+
newCDPSession: (p: PwPage) => ctx.newCDPSession(p),
|
|
105
|
+
async addInitScript(s: { content: string }) {
|
|
106
|
+
scripts.push(s.content)
|
|
107
|
+
for (const p of pages) await p.addInitScript(s)
|
|
108
|
+
},
|
|
109
|
+
async close() {
|
|
110
|
+
await Promise.all(pages.splice(0).map((p) => p.close().catch(() => undefined)))
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** a browser for `who` of the repo at `root`: on its box from a Mac (filmBox), else launched here; one of the repo's
|
|
118
|
+
* browser slots held until close */
|
|
119
|
+
export async function openBrowser<B>(pw: Pw, o: { root?: string; who: string; args: string[]; say?: (l: string) => void }): Promise<Opened<B>> {
|
|
120
|
+
const say = o.say ?? ((l: string) => console.error(l))
|
|
121
|
+
const cap = await browserCap(o.root)
|
|
122
|
+
const box = filmBox(cap)
|
|
123
|
+
const release = await browserSlot(o.who, { ...(o.root ? { root: o.root } : {}), say, onBox: box != null })
|
|
124
|
+
try {
|
|
125
|
+
if (box == null) {
|
|
126
|
+
const b = (await pw.chromium.launch({ headless: true, args: o.args })) as B & { close(): Promise<void> }
|
|
127
|
+
return { browser: b, where: 'here', reach: async () => undefined, close: () => b.close().catch(() => undefined).finally(release) }
|
|
128
|
+
}
|
|
129
|
+
const t = performance.now()
|
|
130
|
+
const version = (JSON.parse(readFileSync(Bun.resolveSync('playwright-core/package.json', import.meta.dir), 'utf8')) as { version: string }).version
|
|
131
|
+
const state = await boxUp(box, version, say)
|
|
132
|
+
const own: { p: ReturnType<typeof Bun.spawn> | null } = { p: null }
|
|
133
|
+
const cdp = localCdp(box)
|
|
134
|
+
await forward(box, ['-L', `${cdp}:127.0.0.1:${CDP_PORT}`], own)
|
|
135
|
+
const b = await pw.chromium.connectOverCDP(`http://127.0.0.1:${cdp}`)
|
|
136
|
+
say(`${o.who}: filming on ${box} (${state.split(' ').slice(0, 2).join(' ')}, ${Math.round(performance.now() - t)} ms to its browser)`)
|
|
137
|
+
const reached = new Set<number>()
|
|
138
|
+
const pages: PwPage[] = []
|
|
139
|
+
const browser = asLaunched(b, pages)
|
|
140
|
+
return {
|
|
141
|
+
browser: browser as B,
|
|
142
|
+
where: box,
|
|
143
|
+
async reach(url: string) {
|
|
144
|
+
const u = new URL(url)
|
|
145
|
+
if (!LOCAL.has(u.hostname)) return
|
|
146
|
+
const port = Number(u.port || (u.protocol === 'https:' ? 443 : 80))
|
|
147
|
+
if (reached.has(port)) return
|
|
148
|
+
await forward(box, ['-R', `${port}:127.0.0.1:${port}`], own)
|
|
149
|
+
reached.add(port)
|
|
150
|
+
},
|
|
151
|
+
async close() {
|
|
152
|
+
// its pages close, the connection drops, the box's browser stays warm
|
|
153
|
+
await browser.close().catch(() => undefined)
|
|
154
|
+
own.p?.kill()
|
|
155
|
+
release()
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
} catch (e) {
|
|
159
|
+
release()
|
|
160
|
+
throw e
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// THE BROWSER CAP: every headless browser that shoots or records on a repo's behalf (an sk shot ask, a Shooter given
|
|
2
|
+
// a slot, sk smoke, the trailer's films, a repo script's own browser) holds one slot of that repo's pool
|
|
3
|
+
// (core/slots.ts browserPool) for its whole life; repo.config.ts `browsers.max` sizes the pool. A slot left by a dead
|
|
4
|
+
// process is free at once (the lease's liveness rule). A repo whose `browsers.box` names a host never starts one on a
|
|
5
|
+
// Mac: browserSlot refuses there, but for the box route's own slot (`onBox`, box.ts) and SK_FILM_HERE=1.
|
|
6
|
+
//
|
|
7
|
+
// The one constraint a reader breaks first: the slot belongs to the process that starts the browser. A parent that
|
|
8
|
+
// holds one and waits on a child that takes one deadlocks at cap 1, so a parent only counts its children (the
|
|
9
|
+
// trailer's lanes are the cap) and never holds a slot for them.
|
|
10
|
+
import { existsSync } from 'fs'
|
|
11
|
+
import { dirname, join, resolve } from 'path'
|
|
12
|
+
import { browserPool, browsersProblem, DEFAULT_BROWSERS, takeSlot } from '../core/slots.ts'
|
|
13
|
+
|
|
14
|
+
/** one run films on this machine even though its repo names a box: the owner's switch when the box is off */
|
|
15
|
+
export const HERE_ENV = 'SK_FILM_HERE'
|
|
16
|
+
|
|
17
|
+
export type BrowserCap = { repo: string; cap: number; root: string; box: string | null }
|
|
18
|
+
|
|
19
|
+
/** the nearest dir at or above `from` holding a repo.config.ts, or null */
|
|
20
|
+
function configRoot(from: string): string | null {
|
|
21
|
+
for (let d = resolve(from); ; d = dirname(d)) {
|
|
22
|
+
if (existsSync(join(d, 'repo.config.ts'))) return d
|
|
23
|
+
if (dirname(d) === d) return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** the browser cap of the repo at `root` (default: the repo the cwd is in), or null outside any repo; a value that is
|
|
28
|
+
* not a whole number of browsers throws */
|
|
29
|
+
export async function browserCap(root?: string): Promise<BrowserCap | null> {
|
|
30
|
+
const at = root ?? configRoot(process.cwd())
|
|
31
|
+
if (at == null || !existsSync(join(at, 'repo.config.ts'))) return null
|
|
32
|
+
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
33
|
+
const c = await loadRepoConfig(at)
|
|
34
|
+
const bad = browsersProblem(c.browsers)
|
|
35
|
+
if (bad != null) throw new Error(`${join(at, 'repo.config.ts')}: ${bad}`)
|
|
36
|
+
return { repo: c.name, cap: c.browsers?.max ?? DEFAULT_BROWSERS, root: at, box: c.browsers?.box ?? null }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** why `who` may not start a browser of this repo on this machine, or null: a repo filmed by its box never starts one
|
|
40
|
+
* on a Mac, unless the slot is the box route's own (its browser on the box) */
|
|
41
|
+
export function browserRefusal(c: Pick<BrowserCap, 'repo' | 'box'>, who: string, onBox: boolean, platform = process.platform, env: Record<string, string | undefined> = process.env): string | null {
|
|
42
|
+
if (c.box == null || onBox || platform !== 'darwin' || env[HERE_ENV] === '1') return null
|
|
43
|
+
return `${who}: ${c.repo} films on ${c.box} (repo.config.ts browsers.box), so no browser of it starts on this Mac: a browser goes through shot/box.ts openBrowser (${HERE_ENV}=1 films here for one run, the owner's call)`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** wait for one of the repo's browser slots and hold it until the returned release (or this process ends), saying
|
|
47
|
+
* once whom it waits on; outside any repo there is no cap and nothing is held. `onBox`: the browser runs on the
|
|
48
|
+
* repo's box, this Mac only drives it */
|
|
49
|
+
export async function browserSlot(who: string, o: { root?: string; say?: (l: string) => void; pollMs?: number; onBox?: boolean } = {}): Promise<() => void> {
|
|
50
|
+
const c = await browserCap(o.root)
|
|
51
|
+
if (c == null) return () => undefined
|
|
52
|
+
const no = browserRefusal(c, who, o.onBox === true)
|
|
53
|
+
if (no != null) throw new Error(no)
|
|
54
|
+
const say = o.say ?? ((l: string) => console.error(l))
|
|
55
|
+
const got = await takeSlot(browserPool(c.repo, c.cap), { repo: c.repo, check: who }, {
|
|
56
|
+
pollMs: o.pollMs ?? 250,
|
|
57
|
+
onWait: (held) =>
|
|
58
|
+
say(`${who}: waiting for a browser of ${c.repo}, all ${c.cap} held (repo.config.ts browsers.max): ${held.map((h) => `pid ${h.pid} (${h.check})`).join(', ') || 'a holder starting'}`),
|
|
59
|
+
})
|
|
60
|
+
if (got == null) throw new Error(`${who}: the browser slot wait of ${c.repo} stopped with no slot`)
|
|
61
|
+
return got.release
|
|
62
|
+
}
|