rvlib-shipkit 2.12.0 → 2.14.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 +75 -21
- package/README.md +1 -1
- package/package.json +4 -2
- package/src/agent-time/store.ts +2 -2
- package/src/assets/run-assets.ts +2 -2
- package/src/assets/server/studio-server.ts +27 -23
- package/src/check.ts +4 -4
- package/src/checks/SK001-package-json-shape.check.ts +8 -4
- package/src/checks/SK002-contracts-fulfillness.check.ts +2 -2
- package/src/checks/SK003-claude-md-shape.check.ts +20 -13
- package/src/checks/SK004-gitignore-policy.check.ts +45 -6
- package/src/checks/SK005-rvlib-versions.check.ts +2 -2
- package/src/checks/SK006-npm-publish-safety.check.ts +3 -3
- package/src/checks/SK007-github-visibility.check.ts +2 -2
- package/src/checks/SK008-reviewer-agent.check.ts +3 -3
- package/src/checks/SK010-undeclared-unit.check.ts +2 -2
- package/src/checks/SK011-sibling-unit-ranges.check.ts +2 -2
- package/src/checks/SK012-config-barrel-import.check.ts +2 -2
- package/src/checks/SK013-one-way-in-policy.check.ts +2 -2
- package/src/checks/SK015-nested-repo.check.ts +3 -3
- package/src/checks/SK016-legacy-check-shapes.check.ts +2 -2
- package/src/checks/SK017-vscode-hub-task.check.ts +2 -2
- package/src/checks/SK018-test-files-run.check.ts +2 -2
- package/src/checks/SK019-tests-run-in-units.check.ts +2 -2
- package/src/checks/SK020-self-spawning-check.check.ts +2 -2
- package/src/checks/SK022-machine-runs-the-pin.check.ts +2 -2
- package/src/checks/SK024-identity-colors.check.ts +1 -1
- package/src/checks/SK025-release-drift.check.ts +2 -2
- package/src/checks/SK026-asks-autoclose.check.ts +2 -2
- package/src/checks/SK027-agent-wiki-links.check.ts +8 -2
- package/src/checks/SK028-readme.check.ts +2 -2
- package/src/checks/SK029-explicit-check-files.check.ts +3 -3
- package/src/checks/SK030-cache-audit.check.ts +7 -5
- package/src/checks/SK031-trace-audit.check.ts +7 -7
- package/src/checks/SK032-ignored-inputs.check.ts +3 -3
- package/src/checks/SK033-global-contribution.check.ts +11 -4
- package/src/checks/SK034-commit-gates-armed.check.ts +2 -2
- package/src/checks/SK035-public-clean.check.ts +46 -0
- package/src/checks/SK036-draft-media-size.check.ts +28 -0
- package/src/checks/SK037-keyword-additions.check.ts +43 -0
- package/src/cli/cmd_Backup.ts +152 -0
- package/src/cli/cmd_Ci.ts +8 -11
- package/src/cli/cmd_Commands.ts +4 -4
- package/src/cli/cmd_ConfigKeys.ts +2 -2
- package/src/cli/cmd_Drill.ts +145 -0
- package/src/cli/cmd_Home.ts +50 -3
- package/src/cli/cmd_Init.ts +1 -1
- package/src/cli/cmd_Media.ts +10 -8
- package/src/cli/cmd_Mv.ts +14 -7
- package/src/cli/cmd_Review.ts +6 -4
- package/src/cli/cmd_Shot.ts +5 -2
- package/src/cli/cmd_Smoke.ts +5 -2
- package/src/cli/cmd_Social.ts +226 -0
- package/src/cli/cmd_Sound.ts +1 -1
- package/src/cli/cmd_Start.ts +1 -1
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_TraceAudit.ts +6 -6
- package/src/cli/cmd_Trailer.ts +7 -4
- package/src/cli/cmd_Veille.ts +173 -0
- package/src/cli/cmd_When.ts +2 -2
- package/src/cli/family-pages.ts +19 -16
- 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 +12 -3
- package/src/collections/providers.ts +4 -4
- package/src/collections/review.ts +3 -2
- package/src/collections/tests.ts +19 -8
- package/src/comfy/comfy-panel.ts +2 -2
- 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/contracts/manifests/discord.contract.ts +1 -1
- package/src/contracts/manifests/identity.contract.ts +1 -1
- package/src/contracts/manifests/itch.contract.ts +1 -1
- package/src/contracts/manifests/steam.contract.ts +1 -1
- package/src/core/agent-dir-at.ts +12 -0
- package/src/core/agent-dir.ts +16 -0
- package/src/core/app-icon.ts +9 -3
- package/src/core/budget.ts +1 -1
- package/src/core/bun-builtins.ts +2 -2
- package/src/core/canonical-scripts.ts +2 -2
- package/src/core/discover-checks.ts +38 -6
- 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/global-contribution.ts +4 -1
- package/src/core/ignored-block.ts +1 -1
- package/src/core/ignored-inputs.ts +3 -2
- 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/motherhome.ts +2 -2
- package/src/core/one-way-in-policy.ts +34 -26
- package/src/core/run-ci.ts +9 -11
- package/src/core/run-fixers.ts +9 -9
- package/src/core/runs-matrix.ts +1 -1
- package/src/core/slots.ts +30 -0
- package/src/core/trace-audit.ts +50 -9
- 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 +44 -8
- package/src/home/gui-app/ShipkitGui.swift +91 -2
- package/src/home/home-routes.ts +22 -15
- package/src/home/hubs.ts +10 -3
- package/src/home/inbox-shape.ts +54 -5
- package/src/home/inbox.ts +17 -2
- package/src/home/lib-watch.ts +10 -3
- package/src/home/machine-stores.ts +15 -29
- package/src/home/pm-config.ts +4 -1
- package/src/home/pm-inputs.ts +2 -0
- package/src/home/resources.ts +7 -2
- package/src/home/run-daemon.ts +15 -18
- package/src/home/run-pm.ts +3 -1
- package/src/home/serve-daemon.ts +4 -3
- package/src/home/serve-web.ts +104 -1
- package/src/hooks/commit-message.ts +29 -20
- package/src/hooks/hook-gates.ts +1 -1
- package/src/hooks/leak-guard.ts +69 -9
- package/src/hooks/run-hooks.ts +18 -22
- 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 +3 -3
- 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 +3 -2
- 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/content.ts +1 -1
- package/src/media-store/daemon.ts +56 -70
- package/src/media-store/db.ts +1 -1
- package/src/media-store/fact.ts +1 -1
- package/src/media-store/hand.ts +1 -1
- package/src/media-store/kind.ts +1 -1
- package/src/media-store/purge.ts +1 -1
- package/src/media-store/put.ts +5 -3
- package/src/media-store/remote.ts +1 -1
- package/src/media-store/space.ts +24 -5
- package/src/mv/mv-md.ts +63 -22
- 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 +319 -0
- package/src/release/published-here.ts +22 -0
- package/src/release/run-bump.ts +3 -2
- package/src/release/run-release.ts +7 -4
- package/src/repo-config.ts +71 -13
- package/src/review/anim.ts +1 -1
- package/src/review/auto.ts +1 -1
- package/src/review/cells.ts +15 -1
- package/src/review/format.ts +2 -2
- package/src/review/http.ts +16 -2
- package/src/review/marks.ts +1 -1
- package/src/review/media-kind.ts +1 -1
- package/src/review/media-read.ts +1 -1
- package/src/review/model.ts +27 -6
- package/src/review/notes.ts +125 -0
- package/src/review/previews.ts +1 -1
- package/src/review/project.ts +7 -39
- package/src/review/role.ts +1 -1
- package/src/review/routes.ts +18 -14
- package/src/review/store.ts +42 -2
- package/src/review/threads.ts +1 -1
- package/src/review/trailer-desk.ts +3 -3
- package/src/review/trailer-media.ts +8 -5
- package/src/review/trailer-model.ts +1 -1
- package/src/review/trailer-routes.ts +1 -1
- package/src/review/trailer-shots.ts +22 -5
- package/src/review/unit.ts +2 -2
- package/src/scaffold/files/agent-handoff.md +3 -0
- package/src/scaffold/files/agent-index.md +4 -12
- package/src/scaffold/files/tsconfig.json +1 -1
- package/src/scaffold/project-scaffold.ts +6 -5
- package/src/serve/embed.ts +2 -2
- package/src/serve/hub-app/check-words.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 +32 -8
- 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 +51 -7
- 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 +353 -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 +60 -7
- package/src/serve/hub-app/inbox-view.tsx +49 -7
- package/src/serve/hub-app/inbox.css +12 -1
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/kept-cols.tsx +30 -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-svc.ts +1 -1
- 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 +76 -20
- package/src/serve/hub-app/review/review-board.tsx +1 -1
- package/src/serve/hub-app/review/review-cells.tsx +6 -5
- package/src/serve/hub-app/review/review-kit.ts +30 -7
- package/src/serve/hub-app/review/review-page.tsx +6 -5
- package/src/serve/hub-app/review/review-st.ts +34 -15
- package/src/serve/hub-app/review/review-thread.tsx +63 -14
- package/src/serve/hub-app/review/review-views.tsx +133 -51
- package/src/serve/hub-app/review/thread-st.ts +80 -37
- package/src/serve/hub-app/review/trailer-page.tsx +7 -5
- package/src/serve/hub-app/review/trailer-st.ts +1 -1
- package/src/serve/hub-app/review.css +26 -9
- 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 +330 -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 +681 -0
- package/src/serve/hub-app/social/social-st.ts +1014 -0
- package/src/serve/hub-app/social.css +289 -0
- package/src/serve/hub-app/stores/stores-page.tsx +312 -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 +515 -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 +20 -11
- 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 +160 -0
- package/src/shot/browser-slot.ts +74 -0
- package/src/shot/client.ts +42 -7
- package/src/shot/clip-encoder.ts +108 -24
- package/src/shot/film-box.ts +292 -0
- package/src/shot/shooter.ts +71 -17
- 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/card-drafts.ts +24 -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 +332 -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 +37 -0
- package/src/social/richtext.ts +37 -0
- package/src/social/routes.ts +186 -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 +95 -35
- package/src/suite/suite-cli.ts +44 -10
- package/src/suite/suite-cpu-preload.ts +34 -9
- package/src/trace/tracer.ts +12 -5
- package/src/trailer/adapter.ts +5 -1
- package/src/trailer/build.ts +45 -12
- 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/holes.ts +1 -1
- package/src/trailer/passage.ts +18 -6
- package/src/trailer/plan.ts +74 -3
- package/src/trailer/prune.ts +1 -1
- package/src/trailer/states.ts +1 -1
- package/src/trailer/stitch.ts +67 -26
- package/src/trailer/url.ts +1 -1
- package/src/trailer/versions.ts +24 -0
- package/src/trailer/words.ts +1 -1
- package/src/ts/gate-typecheck.ts +32 -0
- package/src/ts/typecheck-cli.ts +9 -11
- package/src/tui/run-tui.ts +1 -1
- package/src/tui/tui-app.tsx +0 -1
- package/src/tui/tui-store.ts +1 -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
package/src/shot/shooter.ts
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
// a canvas through the page's WebCodecs (clip-encoder.ts), any other page
|
|
7
7
|
// through chromium's screencast and ffmpeg (dom-clip.ts).
|
|
8
8
|
//
|
|
9
|
+
// A stepped clip (`step`) films a canvas page the same way, frame by frame
|
|
10
|
+
// through the page's hook, and any other page a screenshot a frame
|
|
11
|
+
// (stepped-clip.ts).
|
|
12
|
+
//
|
|
9
13
|
// it never slows the machine's other work: the browser runs niced, the page
|
|
10
14
|
// stays live only LIVE_MS after a request and is then frozen (no frame, no
|
|
11
15
|
// timer, no cpu), a frozen page is loaded again before its next still (an
|
|
@@ -16,11 +20,13 @@
|
|
|
16
20
|
// lib (a toolkit every repo installs carries no browser). It is resolved from
|
|
17
21
|
// the repo that runs this, through the one resolver `loadPlaywright`.
|
|
18
22
|
import { mkdirSync } from 'fs'
|
|
23
|
+
import { format } from 'node:util'
|
|
19
24
|
import { setPriority } from 'os'
|
|
20
25
|
import { dirname } from 'path'
|
|
21
26
|
import { loadPlaywright } from '../smoke/run-smoke.ts'
|
|
22
27
|
import { CLIP_INIT, CLIP_QUANTIZER, clipDone, installClip, KEY_EVERY, muxArgs, type PageClipAsk, type PageClipDone, TAKE, takeClip } from './clip-encoder.ts'
|
|
23
28
|
import { type ClipPath, clipPathOf, domEncodeArgs, FrameTimeline, largestCanvas, screencastParams } from './dom-clip.ts'
|
|
29
|
+
import { openBrowser, type PwBrowser } from './box.ts'
|
|
24
30
|
import { capMsOf, type ClipAsk, pageMove, readMark, type ShotAsk, slotKey, Turns, waitReady } from './shot-ask.ts'
|
|
25
31
|
|
|
26
32
|
/** the slice of playwright the shots touch, so the lib types nothing it does not ship */
|
|
@@ -34,18 +40,29 @@ type Page = {
|
|
|
34
40
|
reload(o?: { waitUntil?: string; timeout?: number }): Promise<unknown>
|
|
35
41
|
evaluate<R, A>(fn: (a: A) => R | Promise<R>, arg?: A): Promise<R>
|
|
36
42
|
waitForTimeout(ms: number): Promise<void>
|
|
37
|
-
on(event: string, cb: (x: { message?: string; text?(): string; type?(): string }) => void): void
|
|
43
|
+
on(event: string, cb: (x: { message?: string; text?(): string; type?(): string; args?(): { jsonValue(): Promise<unknown> }[] }) => void): void
|
|
38
44
|
close(): Promise<void>
|
|
39
45
|
isClosed(): boolean
|
|
40
46
|
}
|
|
47
|
+
/** a console call's format string with its arguments filled, as the page's own console prints it; null when its
|
|
48
|
+
* first argument formats nothing or an argument cannot be read */
|
|
49
|
+
export async function consoleWords(m: { args?(): { jsonValue(): Promise<unknown> }[] }): Promise<string | null> {
|
|
50
|
+
const args = m.args?.() ?? []
|
|
51
|
+
try {
|
|
52
|
+
const vs = await Promise.all(args.map((h) => h.jsonValue()))
|
|
53
|
+
return typeof vs[0] === 'string' && /%[sdifoOc]/.test(vs[0]) ? format(...vs).replace(/%c/g, '') : null
|
|
54
|
+
} catch {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
}
|
|
41
58
|
type Context = { newPage(): Promise<Page>; newCDPSession(p: Page): Promise<Cdp>; addInitScript(s: { content: string }): Promise<void>; close(): Promise<void> }
|
|
42
|
-
type Browser = {
|
|
59
|
+
export type Browser = {
|
|
43
60
|
newContext(o: { viewport: { width: number; height: number }; deviceScaleFactor: number; locale?: string }): Promise<Context>
|
|
44
61
|
close(): Promise<void>
|
|
45
62
|
isConnected(): boolean
|
|
46
63
|
on(event: 'disconnected', cb: () => void): void
|
|
47
64
|
}
|
|
48
|
-
type Playwright = { chromium: { launch(o: { headless: boolean; args: string[] }): Promise<Browser> } }
|
|
65
|
+
type Playwright = { chromium: { launch(o: { headless: boolean; args: string[] }): Promise<Browser>; connectOverCDP(url: string): Promise<PwBrowser> } }
|
|
49
66
|
|
|
50
67
|
/** WebGL on the GPU over metal on a mac: in software a 3D page crawls. Audio plays with no gesture */
|
|
51
68
|
export const BROWSER_ARGS = [...(process.platform === 'darwin' ? ['--use-angle=metal', '--enable-gpu', '--ignore-gpu-blocklist'] : []), '--autoplay-policy=no-user-gesture-required']
|
|
@@ -81,17 +98,27 @@ const ms = (t0: number): number => Math.round(performance.now() - t0)
|
|
|
81
98
|
const withCap = <T>(what: string, capMs: number, p: Promise<T>): Promise<T> =>
|
|
82
99
|
Promise.race([p, new Promise<T>((_, fail) => setTimeout(() => fail(new Error(`${what} took past ${capMs / 1000} s`)), capMs).unref?.())])
|
|
83
100
|
|
|
101
|
+
/** the repo a Shooter's browser works for, and the name its browser slot is held under */
|
|
102
|
+
export type BrowserFor = { root: string; who: string; say?: (l: string) => void }
|
|
103
|
+
|
|
84
104
|
export class Shooter {
|
|
85
105
|
readonly #roots: string[]
|
|
86
106
|
readonly #turns = new Turns()
|
|
107
|
+
readonly #for: BrowserFor | null
|
|
87
108
|
#browser: Browser | null = null
|
|
88
109
|
#launching: Promise<Browser> | null = null
|
|
110
|
+
#held: (() => void) | null = null
|
|
111
|
+
/** before a page goes to a url: the box route forwards this machine's localhost port to the box */
|
|
112
|
+
#reach: (url: string) => Promise<void> = async () => undefined
|
|
89
113
|
#slot: Slot | null = null
|
|
90
114
|
#idle: ReturnType<typeof setTimeout> | null = null
|
|
91
115
|
#live: ReturnType<typeof setTimeout> | null = null
|
|
92
116
|
|
|
93
|
-
|
|
117
|
+
/** `slot`: the repo whose browser cap (browser-slot.ts) this browser counts against, one slot held from its launch
|
|
118
|
+
* to its close; the warm service passes none, each of its askers holds one instead */
|
|
119
|
+
constructor(roots: string[], o: { slot?: BrowserFor } = {}) {
|
|
94
120
|
this.#roots = roots
|
|
121
|
+
this.#for = o.slot ?? null
|
|
95
122
|
}
|
|
96
123
|
|
|
97
124
|
get warm(): { browser: boolean; url: string | null; waiting: number } {
|
|
@@ -115,6 +142,13 @@ export class Shooter {
|
|
|
115
142
|
const b = this.#browser
|
|
116
143
|
this.#browser = null
|
|
117
144
|
await b?.close().catch(() => undefined)
|
|
145
|
+
this.#free()
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#free(): void {
|
|
149
|
+
const held = this.#held
|
|
150
|
+
this.#held = null
|
|
151
|
+
held?.()
|
|
118
152
|
}
|
|
119
153
|
|
|
120
154
|
#touch(): void {
|
|
@@ -140,11 +174,20 @@ export class Shooter {
|
|
|
140
174
|
try {
|
|
141
175
|
setPriority(SHOT_NICE)
|
|
142
176
|
} catch {}
|
|
143
|
-
const
|
|
177
|
+
const f = this.#for
|
|
178
|
+
let b: Browser
|
|
179
|
+
if (f != null) {
|
|
180
|
+
// the repo's browser: on its box from a Mac (box.ts), else launched here, its slot held until close
|
|
181
|
+
const o = await openBrowser<Browser>(pw, { root: f.root, who: f.who, args: BROWSER_ARGS, ...(f.say ? { say: f.say } : {}) })
|
|
182
|
+
b = o.browser
|
|
183
|
+
this.#reach = (url) => o.reach(url)
|
|
184
|
+
this.#held = () => void o.close()
|
|
185
|
+
} else b = await pw.chromium.launch({ headless: true, args: BROWSER_ARGS })
|
|
144
186
|
b.on('disconnected', () => {
|
|
145
187
|
if (this.#browser === b) {
|
|
146
188
|
this.#browser = null
|
|
147
189
|
this.#slot = null
|
|
190
|
+
this.#free()
|
|
148
191
|
}
|
|
149
192
|
})
|
|
150
193
|
this.#browser = b
|
|
@@ -161,7 +204,14 @@ export class Shooter {
|
|
|
161
204
|
static #listen(page: Page, errors: string[]): void {
|
|
162
205
|
page.on('pageerror', (e) => errors.push(`pageerror: ${e.message ?? ''}`))
|
|
163
206
|
page.on('console', (m) => {
|
|
164
|
-
if (m.type?.()
|
|
207
|
+
if (m.type?.() !== 'error') return
|
|
208
|
+
// the text at once, so no error is lost; then its %s filled from the call's own arguments (React names
|
|
209
|
+
// the duplicate key there), unless the list was cleared or the line moved meanwhile
|
|
210
|
+
const line = `console: ${m.text?.() ?? ''}`
|
|
211
|
+
const at = errors.push(line) - 1
|
|
212
|
+
void consoleWords(m).then((w) => {
|
|
213
|
+
if (w != null && errors[at] === line) errors[at] = `console: ${w}`
|
|
214
|
+
})
|
|
165
215
|
})
|
|
166
216
|
}
|
|
167
217
|
|
|
@@ -196,7 +246,10 @@ export class Shooter {
|
|
|
196
246
|
const t = performance.now()
|
|
197
247
|
slot.url = a.url
|
|
198
248
|
if (move === 'reload') await slot.page.reload({ waitUntil: 'load', timeout: 60_000 })
|
|
199
|
-
else
|
|
249
|
+
else {
|
|
250
|
+
await this.#reach(a.url)
|
|
251
|
+
await slot.page.goto(a.url, { waitUntil: 'load', timeout: 60_000 })
|
|
252
|
+
}
|
|
200
253
|
phases['load'] = ms(t)
|
|
201
254
|
}
|
|
202
255
|
let t = performance.now()
|
|
@@ -230,21 +283,19 @@ export class Shooter {
|
|
|
230
283
|
const page = await ctx.newPage()
|
|
231
284
|
Shooter.#listen(page, errors)
|
|
232
285
|
let t = performance.now()
|
|
286
|
+
await this.#reach(a.url)
|
|
233
287
|
await page.goto(a.url, { waitUntil: 'load', timeout: 60_000 })
|
|
234
288
|
await waitReady(() => page.evaluate(readMark), a.waitMs, { now: () => performance.now(), sleep: (n) => page.waitForTimeout(n) })
|
|
235
289
|
phases['load'] = ms(t)
|
|
236
290
|
t = performance.now()
|
|
237
|
-
|
|
238
|
-
const note = await (await import('./stepped-clip.ts')).stepPage(await ctx.newCDPSession(page), page, a as ClipAsk & { step: string })
|
|
239
|
-
phases['film'] = ms(t)
|
|
240
|
-
return { out: a.out, ms: ms(t0), phases, errors, note, stepped: true }
|
|
241
|
-
}
|
|
291
|
+
const stepped = a.step ? { stepped: true as const } : {}
|
|
242
292
|
const path: ClipPath = clipPathOf({ dom: a.dom === true, canvas: await page.evaluate(largestCanvas), viewport: a.viewport })
|
|
243
|
-
const why = path === 'canvas' ? await page.evaluate(installClip, { seconds: a.seconds, fps: a.fps, quantizer: CLIP_QUANTIZER, keyEvery: KEY_EVERY } satisfies PageClipAsk) : null
|
|
293
|
+
const why = path === 'canvas' ? await page.evaluate(installClip, { seconds: a.seconds, fps: a.fps, quantizer: CLIP_QUANTIZER, keyEvery: KEY_EVERY, ...(a.step ? { step: a.step } : {}) } satisfies PageClipAsk) : null
|
|
244
294
|
if (path === 'dom' || why != null) {
|
|
245
|
-
const
|
|
295
|
+
const cdp = await ctx.newCDPSession(page)
|
|
296
|
+
const note = a.step ? await (await import('./stepped-clip.ts')).stepPage(cdp, page, a as ClipAsk & { step: string }) : await filmPage(cdp, page, a)
|
|
246
297
|
phases['film'] = ms(t)
|
|
247
|
-
return { out: a.out, ms: ms(t0), phases, errors, note: why == null ? note : `${note}; the canvas path refused: ${why}
|
|
298
|
+
return { out: a.out, ms: ms(t0), phases, errors, note: why == null ? note : `${note}; the canvas path refused: ${why}`, ...stepped }
|
|
248
299
|
}
|
|
249
300
|
const parts: Buffer[] = []
|
|
250
301
|
let done: PageClipDone | null = null
|
|
@@ -273,8 +324,11 @@ export class Shooter {
|
|
|
273
324
|
phases['mux'] = ms(t)
|
|
274
325
|
const d = done as unknown as PageClipDone
|
|
275
326
|
const mb = (stream.length / 2 ** 20).toFixed(1)
|
|
276
|
-
const
|
|
277
|
-
|
|
327
|
+
const how = a.step
|
|
328
|
+
? `each stepped through window.${a.step}(t) and its ready mark (${d.msPerFrame?.toFixed(0)} ms a frame, ${d.repeated} the page did not draw again)`
|
|
329
|
+
: `(${d.repeated} repeated for a slow page)`
|
|
330
|
+
const note = `${d.frames} frames ${d.width}x${d.height} at ${a.fps} fps ${how}, canvas ${d.canvasOfViewport}, ${mb} MB H.264 from the page's WebCodecs, muxed`
|
|
331
|
+
return { out: a.out, ms: ms(t0), phases, errors, note, ...stepped }
|
|
278
332
|
} finally {
|
|
279
333
|
await ctx.close().catch(() => undefined)
|
|
280
334
|
}
|
package/src/shot/shot-ask.ts
CHANGED
|
@@ -87,6 +87,8 @@ export type ShotFlags = {
|
|
|
87
87
|
fps?: string
|
|
88
88
|
long?: boolean
|
|
89
89
|
dom?: boolean
|
|
90
|
+
step?: string
|
|
91
|
+
at?: string
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
const positive = (flag: string, s: string, max: number): number => {
|
|
@@ -102,6 +104,11 @@ export function askOf(f: ShotFlags, cwd: string): ShotAsk | ClipAsk {
|
|
|
102
104
|
if (seconds != null && seconds > MAX_CLIP_SECONDS && f.long !== true) throw new Error(`--video ${seconds}: a clip past ${MAX_CLIP_SECONDS} s needs --long (a long clip is a long wait and a big file)`)
|
|
103
105
|
if (seconds == null && f.fps != null) throw new Error('--fps only applies to a clip: add --video <seconds>')
|
|
104
106
|
if (seconds == null && f.dom === true) throw new Error('--dom only applies to a clip: add --video <seconds>')
|
|
107
|
+
if (f.step != null && !/^[A-Za-z_$][\w$]*$/.test(f.step)) throw new Error(`--step '${f.step}' is not a window function name, like __trailerStep`)
|
|
108
|
+
if (f.at != null && f.step == null) throw new Error('--at only applies to a stepped still: add --step <hook>')
|
|
109
|
+
if (f.at != null && seconds != null) throw new Error('--at only applies to a still: a stepped clip draws every time from 0')
|
|
110
|
+
const at = f.at == null ? undefined : Number(f.at)
|
|
111
|
+
if (at !== undefined && !(Number.isFinite(at) && at >= 0)) throw new Error(`--at '${f.at}' must be seconds, 0 or more`)
|
|
105
112
|
const base: ShotAsk = {
|
|
106
113
|
url,
|
|
107
114
|
viewport: f.viewport == null ? DEFAULT_VIEWPORT : parseViewport(f.viewport),
|
|
@@ -110,9 +117,10 @@ export function askOf(f: ShotFlags, cwd: string): ShotAsk | ClipAsk {
|
|
|
110
117
|
reload: f.reload === true,
|
|
111
118
|
waitMs: f.wait == null ? DEFAULT_WAIT_MS : f.wait === '0' ? 0 : positive('--wait', f.wait, 60_000),
|
|
112
119
|
}
|
|
113
|
-
|
|
120
|
+
const step = f.step == null ? {} : { step: f.step }
|
|
121
|
+
if (seconds == null) return { ...base, ...step, ...(f.step == null ? {} : { at: at ?? 0 }) }
|
|
114
122
|
if (!base.out.endsWith('.mp4')) throw new Error(`--out '${f.out}': a clip is an mp4 (H.264)`)
|
|
115
|
-
return { ...base, seconds, fps: f.fps == null ? DEFAULT_FPS : positive('--fps', f.fps, 60), dom: f.dom === true }
|
|
123
|
+
return { ...base, seconds, fps: f.fps == null ? DEFAULT_FPS : positive('--fps', f.fps, 60), dom: f.dom === true, ...step }
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
export const isClip = (a: ShotAsk | ClipAsk): a is ClipAsk => 'seconds' in a
|
package/src/shot/stepped-clip.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// a clip
|
|
2
|
-
// frame's time, `window[step](t)`, then the shot service waits for its ready mark and two painted
|
|
3
|
-
// screenshot, and ffmpeg encodes the frames in order.
|
|
4
|
-
//
|
|
1
|
+
// a stepped clip of a page whose canvas is not the page (wiki tools/trailer/index.md, film page): before each frame the page
|
|
2
|
+
// is asked to draw the frame's time, `window[step](t)`, then the shot service waits for its ready mark and two painted
|
|
3
|
+
// frames, takes one screenshot, and ffmpeg encodes the frames in order. A canvas page is stepped inside the page and
|
|
4
|
+
// encoded by its own WebCodecs instead (clip-encoder.ts installClip). The page's own speed never shows: a frame that
|
|
5
|
+
// takes a second to draw sits beside one that took a millisecond. The page owns its clock while it is stepped
|
|
5
6
|
import { mkdirSync } from 'fs'
|
|
6
7
|
import { dirname } from 'path'
|
|
7
8
|
import { domEncodeArgs } from './dom-clip.ts'
|
package/src/site/desk.ts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// the site desk read (wiki tools/shipkit/site.md): an identity's site, its address asked online, the repo that builds
|
|
2
|
+
// it, and through that repo's site unit its pages, its preview, what is online and what changed since. Nothing here
|
|
3
|
+
// writes: the preview and the deploy are the unit's own commands (routes.ts)
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
5
|
+
import { homedir } from 'node:os'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { importFresh, repoUnitFiles } from '../core/discover-checks.ts'
|
|
8
|
+
import { loadIdentities, type Identity } from '../identities/identities.ts'
|
|
9
|
+
import { houseRepoRoots } from '../social/house.ts'
|
|
10
|
+
import { siteProblem, type SiteDated, type SitePage, type SiteUnit } from './unit.ts'
|
|
11
|
+
|
|
12
|
+
export type { SiteDated, SitePage }
|
|
13
|
+
|
|
14
|
+
export type Deployed = { commit: string; at: string; url: string; source: 'record' | 'cloudflare' }
|
|
15
|
+
|
|
16
|
+
/** a page a changed file touches (`*` every page), and the files */
|
|
17
|
+
export type SiteChange = { path: string; files: string[] }
|
|
18
|
+
|
|
19
|
+
export type SiteRepo = { name: string; house: boolean; path: string | null }
|
|
20
|
+
|
|
21
|
+
export type SiteDesk = {
|
|
22
|
+
pages: SitePage[]
|
|
23
|
+
preview: { url: string; up: boolean } | null
|
|
24
|
+
deploy: { about: string | null } | null
|
|
25
|
+
deployed: Deployed | null
|
|
26
|
+
changes: SiteChange[]
|
|
27
|
+
dated: { since: number; words: string } | null
|
|
28
|
+
deploying: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type SiteAnswer = {
|
|
32
|
+
id: string
|
|
33
|
+
name: string
|
|
34
|
+
address: string
|
|
35
|
+
/** the address asked online: its status, null when nothing answered; null with no address */
|
|
36
|
+
online: { status: number | null; at: string } | null
|
|
37
|
+
repo: SiteRepo | null
|
|
38
|
+
/** why there is no desk, in words; null when there is one */
|
|
39
|
+
missing: string | null
|
|
40
|
+
desk: SiteDesk | null
|
|
41
|
+
error: string | null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const UNIT = /\bsite\s*\(|kind:\s*['"]site['"]/
|
|
45
|
+
const FIVE_MIN = 5 * 60_000
|
|
46
|
+
|
|
47
|
+
/** the repo's site unit, null when it has none */
|
|
48
|
+
export async function loadSiteUnit(root: string): Promise<SiteUnit | null> {
|
|
49
|
+
const found: { file: string; unit: SiteUnit }[] = []
|
|
50
|
+
for (const f of repoUnitFiles(root)) {
|
|
51
|
+
if (f.endsWith('.check.shipkit.ts') || !UNIT.test(readFileSync(f, 'utf8'))) continue
|
|
52
|
+
const d = (await importFresh(f)) as { kind?: unknown } | undefined
|
|
53
|
+
if (d?.kind !== 'site') continue
|
|
54
|
+
const why = siteProblem(d as SiteUnit)
|
|
55
|
+
if (why !== null) throw new Error(`${f}: ${why}`)
|
|
56
|
+
found.push({ file: f, unit: d as SiteUnit })
|
|
57
|
+
}
|
|
58
|
+
if (found.length > 1) throw new Error(`two site units: ${found.map((x) => x.file).join(' and ')}; keep one`)
|
|
59
|
+
return found[0]?.unit ?? null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function run(cmd: readonly string[], cwd: string): Promise<{ ok: boolean; out: string; err: string }> {
|
|
63
|
+
try {
|
|
64
|
+
const p = Bun.spawn([...cmd], { cwd, stdin: 'ignore', stdout: 'pipe', stderr: 'pipe' })
|
|
65
|
+
const [out, err, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited])
|
|
66
|
+
return { ok: code === 0, out, err: err.trim() }
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return { ok: false, out: '', err: (e as Error).message }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const answers = (url: string, ms = 800): Promise<boolean> =>
|
|
73
|
+
fetch(url, { signal: AbortSignal.timeout(ms) }).then(
|
|
74
|
+
() => true,
|
|
75
|
+
() => false,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const probes = new Map<string, { at: number; status: number | null }>()
|
|
79
|
+
|
|
80
|
+
/** the address asked online, at most every five minutes */
|
|
81
|
+
async function probe(address: string): Promise<{ status: number | null; at: string }> {
|
|
82
|
+
let p = probes.get(address)
|
|
83
|
+
if (p == null || Date.now() - p.at > FIVE_MIN) {
|
|
84
|
+
const status = await fetch(address, { redirect: 'follow', signal: AbortSignal.timeout(4000) }).then(
|
|
85
|
+
(r) => r.status,
|
|
86
|
+
() => null,
|
|
87
|
+
)
|
|
88
|
+
p = { at: Date.now(), status }
|
|
89
|
+
probes.set(address, p)
|
|
90
|
+
}
|
|
91
|
+
return { status: p.status, at: new Date(p.at).toISOString() }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const cloudflare = new Map<string, { at: number; value: Deployed | null }>()
|
|
95
|
+
|
|
96
|
+
/** a deploy ended: what Cloudflare says is asked again */
|
|
97
|
+
export const forgetDeployed = (): void => cloudflare.clear()
|
|
98
|
+
|
|
99
|
+
/** the Cloudflare token the house config names (`serve.cloudflareToken`), read through its `credsReadCommand`; null when either is missing */
|
|
100
|
+
async function cloudflareToken(cwd: string): Promise<string | null> {
|
|
101
|
+
const { houseRootOf } = await import('../home/home-start.ts')
|
|
102
|
+
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
103
|
+
const { readSecret } = await import('../smoke/run-smoke.ts')
|
|
104
|
+
const house = houseRootOf(cwd)
|
|
105
|
+
if (!house) return null
|
|
106
|
+
const c = await loadRepoConfig(house)
|
|
107
|
+
const name = c.serve?.cloudflareToken
|
|
108
|
+
if (!name || !c.credsReadCommand) return null
|
|
109
|
+
try {
|
|
110
|
+
return readSecret(c.credsReadCommand, name)
|
|
111
|
+
} catch {
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** the last production deployment Cloudflare Pages reports, asked at most every five minutes */
|
|
117
|
+
async function fromCloudflare(pages: { account: string; project: string }, cwd: string): Promise<Deployed | null> {
|
|
118
|
+
const key = `${pages.account}/${pages.project}`
|
|
119
|
+
const kept = cloudflare.get(key)
|
|
120
|
+
if (kept && Date.now() - kept.at < FIVE_MIN) return kept.value
|
|
121
|
+
const token = await cloudflareToken(cwd)
|
|
122
|
+
let value: Deployed | null = null
|
|
123
|
+
if (token != null) {
|
|
124
|
+
const url = `https://api.cloudflare.com/client/v4/accounts/${pages.account}/pages/projects/${pages.project}/deployments?env=production&per_page=1`
|
|
125
|
+
const r = await fetch(url, { headers: { Authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(5000) }).catch(() => null)
|
|
126
|
+
const d = r?.ok ? ((await r.json()) as { result?: { created_on: string; url: string; deployment_trigger?: { metadata?: { commit_hash?: string } } }[] }) : null
|
|
127
|
+
const last = d?.result?.[0]
|
|
128
|
+
const commit = last?.deployment_trigger?.metadata?.commit_hash
|
|
129
|
+
if (last && commit) value = { commit, at: last.created_on, url: last.url, source: 'cloudflare' }
|
|
130
|
+
}
|
|
131
|
+
cloudflare.set(key, { at: Date.now(), value })
|
|
132
|
+
return value
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function deployedOf(unit: SiteUnit, root: string): Promise<Deployed | null> {
|
|
136
|
+
const rec = unit.online?.record
|
|
137
|
+
if (rec != null && existsSync(join(root, rec))) {
|
|
138
|
+
const d = JSON.parse(readFileSync(join(root, rec), 'utf8')) as Omit<Deployed, 'source'>
|
|
139
|
+
return { commit: d.commit, at: d.at, url: d.url, source: 'record' }
|
|
140
|
+
}
|
|
141
|
+
return unit.online?.pages ? fromCloudflare(unit.online.pages, root) : null
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const lines = (s: string): string[] => s.split('\n').filter(Boolean)
|
|
145
|
+
|
|
146
|
+
/** the files of the unit's sources that differ from the deployed commit, the working tree's and the new ones included;
|
|
147
|
+
* no rename detection: both sides of a move changed the site, and it costs 0.7 s on a big repo */
|
|
148
|
+
async function changedFiles(root: string, commit: string, sources: readonly string[]): Promise<string[]> {
|
|
149
|
+
if (sources.length === 0) return []
|
|
150
|
+
const [diff, fresh] = await Promise.all([run(['git', 'diff', '--no-renames', '--name-only', commit, '--', ...sources], root), run(['git', 'ls-files', '--others', '--exclude-standard', '--', ...sources], root)])
|
|
151
|
+
return [...new Set([...lines(diff.out), ...lines(fresh.out)])]
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** the files of the identity's folder the site reads, changed since the deploy: committed since, or not committed */
|
|
155
|
+
async function identityChanges(i: Identity, files: readonly string[], since: string): Promise<string[]> {
|
|
156
|
+
if (files.length === 0) return []
|
|
157
|
+
const [log, status] = await Promise.all([run(['git', 'log', `--since=${since}`, '--format=', '--name-only', '--', ...files], i.dir), run(['git', 'status', '--porcelain', '--', ...files], i.dir)])
|
|
158
|
+
return [...new Set([...lines(log.out), ...lines(status.out).map((l) => l.slice(3))])]
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** each changed file grouped under the page it touches; a file that touches none is left out */
|
|
162
|
+
export function changesOf(files: readonly string[], touches: SiteUnit['touches'], ctx: { pages: readonly SitePage[]; dated: readonly SiteDated[] }): SiteChange[] {
|
|
163
|
+
const by = new Map<string, string[]>()
|
|
164
|
+
for (const f of files) {
|
|
165
|
+
const path = touches == null ? '*' : touches(f, ctx)
|
|
166
|
+
if (path != null) by.set(path, [...(by.get(path) ?? []), f])
|
|
167
|
+
}
|
|
168
|
+
return [...by].map(([path, fs]) => ({ path, files: fs }))
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const deploying = new Set<string>()
|
|
172
|
+
export const isDeploying = (id: string): boolean => deploying.has(id)
|
|
173
|
+
export const setDeploying = (id: string, on: boolean): void => void (on ? deploying.add(id) : deploying.delete(id))
|
|
174
|
+
|
|
175
|
+
/** the repo that builds an identity's site: a house repo, else a folder of `~/dev` by that name, else null */
|
|
176
|
+
export async function siteRepoOf(root: string, name: string): Promise<SiteRepo | null> {
|
|
177
|
+
if (name === '') return null
|
|
178
|
+
const house = (await houseRepoRoots(root)).find((r) => r.name === name)
|
|
179
|
+
if (house) return { name, house: true, path: house.path }
|
|
180
|
+
const dev = join(homedir(), 'dev', name)
|
|
181
|
+
return { name, house: false, path: existsSync(dev) ? dev : null }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function deskOf(i: Identity, root: string, unit: SiteUnit): Promise<SiteDesk> {
|
|
185
|
+
const listed = await run(unit.pages, root)
|
|
186
|
+
if (!listed.ok) throw new Error(`${unit.pages.join(' ')}: ${listed.err || 'failed'}`)
|
|
187
|
+
const { pages, dated = [] } = JSON.parse(listed.out) as { pages: SitePage[]; dated?: SiteDated[] }
|
|
188
|
+
const [live, up] = await Promise.all([deployedOf(unit, root), unit.preview ? answers(unit.preview.url) : Promise.resolve(false)])
|
|
189
|
+
const [files, ids] = live ? await Promise.all([changedFiles(root, live.commit, unit.sources ?? []), identityChanges(i, unit.identityFiles ?? [], live.at)]) : [[], []]
|
|
190
|
+
const changes = changesOf(files, unit.touches, { pages, dated })
|
|
191
|
+
if (ids.length > 0) {
|
|
192
|
+
const every = changes.find((c) => c.path === '*')
|
|
193
|
+
if (every) every.files.push(...ids)
|
|
194
|
+
else changes.push({ path: '*', files: ids })
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
pages,
|
|
198
|
+
preview: unit.preview ? { url: unit.preview.url, up } : null,
|
|
199
|
+
deploy: unit.deploy ? { about: unit.deploy.about ?? null } : null,
|
|
200
|
+
deployed: live,
|
|
201
|
+
changes,
|
|
202
|
+
dated: unit.dated && live ? { since: dated.filter((d) => d.at > live.at).length, words: unit.dated } : null,
|
|
203
|
+
deploying: deploying.has(i.id),
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** the identity named, its unit and the repo that holds it: what the preview and the deploy act on */
|
|
208
|
+
export async function siteTarget(root: string, id: string): Promise<{ i: Identity; repo: SiteRepo | null; unit: SiteUnit | null; unitError: string | null }> {
|
|
209
|
+
const ids = await loadIdentities({ cwd: root })
|
|
210
|
+
const i = ids.identities.find((x) => x.id === id)
|
|
211
|
+
if (i == null) throw new Error(`no identity ${id} (${ids.identities.map((x) => x.id).join(', ') || 'none'})`)
|
|
212
|
+
const repo = await siteRepoOf(root, i.siteRepo)
|
|
213
|
+
if (!repo?.house || repo.path == null) return { i, repo, unit: null, unitError: null }
|
|
214
|
+
try {
|
|
215
|
+
return { i, repo, unit: await loadSiteUnit(repo.path), unitError: null }
|
|
216
|
+
} catch (e) {
|
|
217
|
+
return { i, repo, unit: null, unitError: (e as Error).message }
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** why an identity's site has no desk, in words */
|
|
222
|
+
function missingOf(i: Identity, repo: SiteRepo | null): string {
|
|
223
|
+
if (repo == null) return `no repo builds it: siteRepo: in ${i.id}'s identity.md`
|
|
224
|
+
if (repo.path == null) return `${repo.name} is not on this disk`
|
|
225
|
+
if (!repo.house) return `${repo.name} is not wired to shipkit: no site unit, so no pages, no preview and no deploy here`
|
|
226
|
+
return `${repo.name} declares no site unit: a site({...}) in a .shipkit.ts (tools/shipkit/site.md)`
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export async function siteAnswer(root: string, id: string): Promise<SiteAnswer> {
|
|
230
|
+
const { i, repo, unit, unitError } = await siteTarget(root, id)
|
|
231
|
+
const online = i.site === '' ? Promise.resolve(null) : probe(i.site)
|
|
232
|
+
let desk: SiteDesk | null = null
|
|
233
|
+
let error = unitError
|
|
234
|
+
if (unit && repo?.path) {
|
|
235
|
+
try {
|
|
236
|
+
desk = await deskOf(i, repo.path, unit)
|
|
237
|
+
} catch (e) {
|
|
238
|
+
error = (e as Error).message
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return { id: i.id, name: i.name, address: i.site, online: await online, repo, missing: unit || unitError ? null : missingOf(i, repo), desk, error }
|
|
242
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// the site desk's routes (wiki tools/shipkit/site.md, Routes), on the home daemon: an identity's site read, its local
|
|
2
|
+
// preview started when down, its deploy run on his press with the log streamed. Each names an identity, never a path
|
|
3
|
+
// or a command: the commands are the site unit's
|
|
4
|
+
import { bad, NO_STORE } from '../review/http.ts'
|
|
5
|
+
import { answers, forgetDeployed, isDeploying, setDeploying, siteAnswer, siteTarget } from './desk.ts'
|
|
6
|
+
|
|
7
|
+
const BASE = '/api/home/sites/'
|
|
8
|
+
|
|
9
|
+
/** the preview answers, started when down: detached, so it outlives the daemon */
|
|
10
|
+
async function preview(root: string, id: string): Promise<Response> {
|
|
11
|
+
const { repo, unit } = await siteTarget(root, id)
|
|
12
|
+
const p = unit?.preview
|
|
13
|
+
if (!p || !repo?.path) return bad(`${id}'s site has no local preview: a preview in its site unit`, 404)
|
|
14
|
+
if (await answers(p.url)) return Response.json({ ok: true, url: p.url }, { headers: NO_STORE })
|
|
15
|
+
Bun.spawn(['sh', '-c', 'nohup "$@" >/dev/null 2>&1 &', 'sh', ...p.start], { cwd: repo.path, stdin: 'ignore', stdout: 'ignore', stderr: 'ignore' })
|
|
16
|
+
for (let n = 0; n < 40; n++) {
|
|
17
|
+
await Bun.sleep(500)
|
|
18
|
+
if (await answers(p.url)) return Response.json({ ok: true, url: p.url }, { headers: NO_STORE })
|
|
19
|
+
}
|
|
20
|
+
return bad(`the preview did not answer on ${p.url} in 20 s: run « ${p.start.join(' ')} » in ${repo.name} to see why`, 500)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** the unit's deploy, only on his press, one at a time per identity, its output streamed as it comes */
|
|
24
|
+
async function deploy(root: string, id: string): Promise<Response> {
|
|
25
|
+
const { repo, unit } = await siteTarget(root, id)
|
|
26
|
+
const d = unit?.deploy
|
|
27
|
+
if (!d || !repo?.path) return bad(`${id}'s site has no deploy: a deploy in its site unit`, 404)
|
|
28
|
+
if (isDeploying(id)) return bad(`${id}'s site is being deployed already`, 409)
|
|
29
|
+
let proc: ReturnType<typeof Bun.spawn<'ignore', 'pipe', 'pipe'>>
|
|
30
|
+
try {
|
|
31
|
+
proc = Bun.spawn([...d.cmd], { cwd: repo.path, stdin: 'ignore', stdout: 'pipe', stderr: 'pipe' })
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return bad(`deploy: ${d.cmd.join(' ')}: ${(e as Error).message}`, 500)
|
|
34
|
+
}
|
|
35
|
+
setDeploying(id, true)
|
|
36
|
+
const enc = new TextEncoder()
|
|
37
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
38
|
+
async start(c) {
|
|
39
|
+
const pump = async (s: ReadableStream<Uint8Array>): Promise<void> => {
|
|
40
|
+
for await (const chunk of s) c.enqueue(chunk)
|
|
41
|
+
}
|
|
42
|
+
await Promise.all([pump(proc.stdout), pump(proc.stderr)])
|
|
43
|
+
const code = await proc.exited
|
|
44
|
+
forgetDeployed()
|
|
45
|
+
setDeploying(id, false)
|
|
46
|
+
c.enqueue(enc.encode(code === 0 ? '\n✓ deployed\n' : `\n✗ failed (exit ${code})\n`))
|
|
47
|
+
c.close()
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
return new Response(stream, { headers: { 'Content-Type': 'text/plain; charset=utf-8', ...NO_STORE } })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** null when the path is not this route's */
|
|
54
|
+
export async function siteRoutes(req: Request, path: string, root: string): Promise<Response | null> {
|
|
55
|
+
if (!path.startsWith(BASE)) return null
|
|
56
|
+
const [id = '', verb = ''] = path.slice(BASE.length).split('/').map(decodeURIComponent)
|
|
57
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(id)) return bad(`sites: ${id} is no identity id`, 404)
|
|
58
|
+
try {
|
|
59
|
+
if (verb === '' && req.method === 'GET') return Response.json(await siteAnswer(root, id), { headers: NO_STORE })
|
|
60
|
+
if (verb === 'preview' && req.method === 'POST') return await preview(root, id)
|
|
61
|
+
if (verb === 'deploy' && req.method === 'POST') return await deploy(root, id)
|
|
62
|
+
return bad(`sites: no route ${req.method} ${path}`, 404)
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return bad(e, (e as Error).message.startsWith('no identity') ? 404 : 500)
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/site/unit.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// a repo's parts of the site desk (wiki tools/shipkit/site.md, What a project adds): the command that lists its pages,
|
|
2
|
+
// its local preview, its deploy, where what is online is read, what a deploy ships and the page a changed file touches.
|
|
3
|
+
// Every unit file imports this module, so it stays light: desk.ts finds and reads the unit
|
|
4
|
+
|
|
5
|
+
/** a page of the site, as the unit's `pages` command prints it */
|
|
6
|
+
export interface SitePage {
|
|
7
|
+
path: string
|
|
8
|
+
title: string
|
|
9
|
+
draft?: boolean
|
|
10
|
+
/** the repo folder the page is made from, when it has one */
|
|
11
|
+
dir?: string | null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** a dated entry the site shows (a News message): counted when it is newer than the deploy */
|
|
15
|
+
export interface SiteDated {
|
|
16
|
+
id: string
|
|
17
|
+
at: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SiteDef {
|
|
21
|
+
/** argv from the repo root; prints `{ pages: SitePage[], dated?: SiteDated[] }` */
|
|
22
|
+
pages: readonly string[]
|
|
23
|
+
/** the local preview: its url, and the argv that serves it (detached, so it outlives the daemon) */
|
|
24
|
+
preview?: { url: string; start: readonly string[] }
|
|
25
|
+
/** the project's own deploy: argv from the repo root, and how long it takes in words */
|
|
26
|
+
deploy?: { cmd: readonly string[]; about?: string }
|
|
27
|
+
/** what is online: a record `{ commit, at, url }` the deploy writes, else a Cloudflare Pages project */
|
|
28
|
+
online?: { record?: string; pages?: { account: string; project: string } }
|
|
29
|
+
/** what a deploy ships, repo relative: a file there that differs from the deployed commit is a change */
|
|
30
|
+
sources?: readonly string[]
|
|
31
|
+
/** what the site reads from its identity's folder: a change there since the deploy touches every page */
|
|
32
|
+
identityFiles?: readonly string[]
|
|
33
|
+
/** the words for the dated entries newer than the deploy */
|
|
34
|
+
dated?: string
|
|
35
|
+
/** the page a changed file touches: its path, `*` every page, null none. Pure: it runs in the daemon */
|
|
36
|
+
touches?: (file: string, ctx: { pages: readonly SitePage[]; dated: readonly SiteDated[] }) => string | null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type SiteUnit = SiteDef & { kind: 'site' }
|
|
40
|
+
|
|
41
|
+
const REL = /^(?!\/)(?!.*(^|\/)\.\.(\/|$)).+$/
|
|
42
|
+
const argv = (v: unknown): boolean => Array.isArray(v) && v.length > 0 && v.every((a) => typeof a === 'string' && a !== '')
|
|
43
|
+
|
|
44
|
+
/** why a site unit cannot be read, or null */
|
|
45
|
+
export function siteProblem(d: SiteDef): string | null {
|
|
46
|
+
if (!argv(d.pages)) return 'site: pages is an argv that prints the pages'
|
|
47
|
+
if (d.preview !== undefined && (typeof d.preview.url !== 'string' || !/^https?:\/\//.test(d.preview.url) || !argv(d.preview.start))) return 'site: preview is { url: an http url, start: an argv }'
|
|
48
|
+
if (d.deploy !== undefined && !argv(d.deploy.cmd)) return 'site: deploy.cmd is an argv'
|
|
49
|
+
if (d.online?.record !== undefined && !REL.test(d.online.record)) return `site: online.record '${d.online.record}' is a repo relative file`
|
|
50
|
+
const pages = d.online?.pages
|
|
51
|
+
if (pages !== undefined && (typeof pages.account !== 'string' || pages.account === '' || typeof pages.project !== 'string' || pages.project === '')) return 'site: online.pages is { account, project }'
|
|
52
|
+
for (const [key, list] of [['sources', d.sources], ['identityFiles', d.identityFiles]] as const)
|
|
53
|
+
for (const s of list ?? []) if (typeof s !== 'string' || !REL.test(s)) return `site: ${key} '${String(s)}' is a relative path`
|
|
54
|
+
if (d.touches !== undefined && typeof d.touches !== 'function') return 'site: touches is a function of a file'
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function site(d: SiteDef): SiteUnit {
|
|
59
|
+
const why = siteProblem(d)
|
|
60
|
+
if (why !== null) throw new Error(why)
|
|
61
|
+
return { ...d, kind: 'site' }
|
|
62
|
+
}
|