rvlib-shipkit 2.26.0 → 2.28.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 +36 -0
- package/package.json +1 -1
- package/src/agent-time/diet.ts +77 -0
- package/src/agent-time/family.ts +72 -0
- package/src/agent-time/hooks.ts +16 -7
- package/src/agent-time/limits.ts +44 -0
- package/src/agent-time/live.ts +12 -8
- package/src/agent-time/mask.ts +96 -18
- package/src/agent-time/refused.ts +45 -0
- package/src/agent-time/registry.ts +289 -0
- package/src/agent-time/render.ts +122 -21
- package/src/agent-time/report-cache.ts +57 -0
- package/src/agent-time/report.ts +314 -40
- package/src/agent-time/shape.ts +50 -3
- package/src/agent-time/store.ts +322 -101
- package/src/agent-time/timeline.ts +140 -21
- package/src/agent-time/turns.ts +18 -8
- package/src/annex/born.ts +2 -2
- package/src/annex/offload.ts +29 -17
- package/src/annex/tidy.ts +70 -10
- package/src/asks/ask-after.ts +44 -0
- package/src/asks/ask-bar-fold.ts +57 -0
- package/src/asks/ask-migrate.ts +280 -0
- package/src/asks/ask-steps-fold.ts +166 -0
- package/src/asks/ask-store.ts +586 -0
- package/src/assets/kit-config.ts +7 -3
- package/src/assets/kits/identity-kit.ts +361 -14
- package/src/assets/kits/poster-thumbnail.ts +282 -0
- package/src/check.ts +3 -1
- package/src/checks/SK003-claude-md-shape.check.ts +92 -25
- package/src/checks/SK004-gitignore-policy.check.ts +20 -9
- package/src/checks/SK013-one-way-in-policy.check.ts +18 -3
- package/src/checks/SK026-asks-autoclose.check.ts +9 -23
- package/src/checks/SK028-readme.check.ts +7 -66
- package/src/checks/SK030-cache-audit.check.ts +6 -1
- package/src/checks/SK031-trace-audit.check.ts +2 -0
- package/src/checks/SK033-global-contribution.check.ts +3 -1
- package/src/checks/SK035-public-clean.check.ts +2 -2
- package/src/checks/SK038-speaks-as.check.ts +3 -3
- package/src/checks/SK042-post-kinds.check.ts +26 -24
- package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
- package/src/checks/SK047-login-in-description.check.ts +36 -0
- package/src/checks/SK048-one-local-file.check.ts +36 -0
- package/src/checks/SK049-thread-answers-hook.check.ts +81 -0
- package/src/checks/SK050-retired-commands.check.ts +127 -0
- package/src/cli/cmd_Asks.ts +244 -27
- package/src/cli/cmd_Backup.ts +153 -10
- package/src/cli/cmd_Calls.ts +1 -0
- package/src/cli/cmd_Capacity.ts +2 -2
- package/src/cli/cmd_Commands.ts +140 -34
- package/src/cli/cmd_Contracts.ts +1 -0
- package/src/cli/cmd_CrossRepoActivity.ts +5 -4
- package/src/cli/cmd_Db.ts +253 -0
- package/src/cli/cmd_History.ts +212 -0
- package/src/cli/cmd_Home.ts +31 -3
- package/src/cli/cmd_Hq.ts +516 -0
- package/src/cli/cmd_Keys.ts +1 -0
- package/src/cli/cmd_Lanes.ts +15 -4
- package/src/cli/cmd_Machines.ts +36 -0
- package/src/cli/cmd_Media.ts +38 -6
- package/src/cli/cmd_Messages.ts +152 -1
- package/src/cli/cmd_Needs.ts +1 -0
- package/src/cli/cmd_Reflect.ts +23 -2
- package/src/cli/cmd_Review.ts +1357 -223
- package/src/cli/cmd_Secret.ts +295 -24
- package/src/cli/cmd_Social.ts +113 -28
- package/src/cli/cmd_SocialDrafts.ts +235 -0
- package/src/cli/cmd_Sound.ts +22 -1
- package/src/cli/cmd_Space.ts +324 -0
- package/src/cli/cmd_Start.ts +3 -2
- package/src/cli/cmd_ThreadHolds.ts +34 -0
- package/src/cli/cmd_ThreadKinds.ts +146 -0
- package/src/cli/cmd_ThreadReflect.ts +83 -0
- package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
- package/src/cli/cmd_Time.ts +76 -5
- package/src/cli/cmd_Tmp.ts +28 -4
- package/src/cli/cmd_Trailer.ts +14 -10
- package/src/cli/cmd_Urls.ts +56 -0
- package/src/cli/cmd_Vault.ts +583 -0
- package/src/cli/cmd_When.ts +1 -0
- package/src/cli/family-help.ts +5 -3
- package/src/cli/family-pages.ts +1 -1
- package/src/cli/kit/builtins.ts +1 -0
- package/src/cli/kit/verb.ts +6 -2
- package/src/cli/registry.ts +44 -4
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +42 -41
- package/src/collections/collection-types.ts +30 -4
- package/src/collections/md-body.ts +5 -3
- package/src/collections/pings.ts +13 -6
- package/src/collections/providers.ts +147 -61
- package/src/collections/reflections.ts +9 -4
- package/src/collections/review.ts +4 -4
- package/src/contracts/contract-manifests.ts +6 -5
- package/src/contracts/contract-types.ts +6 -4
- package/src/contracts/contracts-engine.ts +11 -0
- package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
- package/src/core/budget.ts +12 -17
- package/src/core/capacity.ts +27 -18
- package/src/core/check-runner.ts +7 -4
- package/src/core/discover-checks.ts +18 -3
- package/src/core/git.ts +31 -0
- package/src/core/house-layout.ts +17 -0
- package/src/core/layout.ts +13 -5
- package/src/core/locked-write.ts +4 -1
- package/src/core/machine-busy.ts +127 -0
- package/src/core/machine-commit.ts +6 -1
- package/src/core/machine-db.ts +370 -20
- package/src/core/machine-layout.ts +137 -0
- package/src/core/machine-read.ts +81 -0
- package/src/core/migrate-layout.ts +9 -11
- package/src/core/one-way-in-policy.ts +64 -7
- package/src/core/polling-policy.ts +27 -0
- package/src/core/retention.ts +16 -2
- package/src/core/scope.ts +107 -14
- package/src/core/slots.ts +5 -4
- package/src/drill/clean.ts +25 -1
- package/src/drill/run.ts +1 -1
- package/src/drill/seal.ts +27 -4
- package/src/home/activity-shape.ts +2 -0
- package/src/home/activity.ts +59 -3
- package/src/home/app-sign.ts +15 -4
- package/src/home/daemon-jobs.ts +161 -7
- package/src/home/database-projects.ts +111 -0
- package/src/home/database-words.ts +203 -0
- package/src/home/databases.ts +460 -0
- package/src/home/global-units.ts +6 -0
- package/src/home/gui-app/ShipkitGui.swift +122 -1
- package/src/home/gui-app.ts +6 -3
- package/src/home/home-move.ts +514 -0
- package/src/home/home-paths.ts +18 -6
- package/src/home/home-routes.ts +76 -0
- package/src/home/inbox-shape.ts +234 -91
- package/src/home/inbox.ts +26 -71
- package/src/home/machine-fold.ts +815 -0
- package/src/home/machine-host.ts +38 -5
- package/src/home/machine-repair.ts +503 -0
- package/src/home/machine-stores.ts +66 -15
- package/src/home/machine-temp.ts +547 -86
- package/src/home/other-macs.ts +2 -2
- package/src/home/resume.ts +79 -0
- package/src/home/run-daemon.ts +25 -4
- package/src/home/run-pm.ts +18 -5
- package/src/home/serve-daemon.ts +18 -3
- package/src/home/serve-web.ts +179 -10
- package/src/home/space-job.ts +115 -0
- package/src/home/space-page.ts +257 -0
- package/src/home/space-route.ts +167 -0
- package/src/home/space-words.ts +103 -0
- package/src/home/time-page-shape.ts +202 -0
- package/src/home/time-page.ts +64 -0
- package/src/home/vault-page.ts +516 -0
- package/src/home/vault-words.ts +132 -0
- package/src/hooks/leak-guard.ts +40 -13
- package/src/hooks/one-way-in-guard.ts +41 -6
- package/src/hq/cards.ts +581 -0
- package/src/hq/door-route.ts +43 -0
- package/src/hq/door.ts +163 -0
- package/src/hq/files-send.ts +347 -0
- package/src/hq/forgotten-log.ts +35 -0
- package/src/hq/history-check.ts +255 -0
- package/src/hq/history-place.ts +146 -0
- package/src/hq/history-send.ts +487 -0
- package/src/hq/hq-db.ts +102 -0
- package/src/hq/hq-local.ts +502 -0
- package/src/hq/hq-routes.ts +204 -0
- package/src/hq/hq-store.ts +603 -0
- package/src/hq/kinds/ask.ts +147 -0
- package/src/hq/kinds/card-gone.ts +83 -0
- package/src/hq/kinds/card-msg.ts +66 -0
- package/src/hq/kinds/card.ts +99 -0
- package/src/hq/kinds/index.ts +21 -0
- package/src/hq/kinds/kind.ts +126 -0
- package/src/hq/kinds/media.ts +125 -0
- package/src/hq/kinds/prompt.ts +219 -0
- package/src/hq/kinds/reflection.ts +128 -0
- package/src/hq/kinds/report.ts +55 -0
- package/src/hq/kinds/time-day.ts +236 -0
- package/src/hq/ledger.ts +473 -0
- package/src/hq/machine-key.ts +44 -0
- package/src/hq/machine-notes.ts +131 -0
- package/src/hq/outbox.ts +374 -0
- package/src/hq/replica.ts +167 -0
- package/src/hq/repo-id.ts +4 -0
- package/src/hq/report-facts.ts +117 -0
- package/src/hq/report.ts +274 -0
- package/src/hq/switch.ts +151 -0
- package/src/hq/vault-grant.ts +92 -0
- package/src/hq/vault-route.ts +112 -0
- package/src/identities/collection.ts +2 -2
- package/src/identities/identities.ts +24 -11
- package/src/identities/machine-route.ts +8 -3
- package/src/identities/steps.ts +31 -0
- package/src/ledger/db.ts +81 -27
- package/src/ledger/gate-checks.ts +6 -2
- package/src/ledger/run-log.ts +11 -3
- package/src/ledger/store.ts +26 -4
- package/src/media-store/backup/daemon.ts +73 -25
- package/src/media-store/backup/kept.ts +241 -0
- package/src/media-store/backup/keys.ts +1 -1
- package/src/media-store/backup/manifest.ts +20 -2
- package/src/media-store/backup/prune.ts +365 -0
- package/src/media-store/backup/restore.ts +14 -4
- package/src/media-store/backup/retention.ts +122 -0
- package/src/media-store/backup/run.ts +25 -19
- package/src/media-store/backup/secret.ts +6 -4
- package/src/media-store/backup/snapshot.ts +4 -2
- package/src/media-store/backup/sources.ts +83 -31
- package/src/media-store/backup/thread-copy.ts +340 -0
- package/src/media-store/copy/config.ts +76 -0
- package/src/media-store/copy/copy.ts +194 -0
- package/src/media-store/copy/lifecycle.ts +43 -0
- package/src/media-store/copy/night.ts +90 -0
- package/src/media-store/copy/proof.ts +151 -0
- package/src/media-store/copy/snapshot.ts +152 -0
- package/src/media-store/copy/store.ts +62 -0
- package/src/media-store/copy/stream.ts +176 -0
- package/src/media-store/daemon.ts +66 -16
- package/src/media-store/db.ts +24 -13
- package/src/media-store/forget.ts +141 -3
- package/src/media-store/hand.ts +4 -3
- package/src/media-store/hq-find.ts +75 -0
- package/src/media-store/hq-send.ts +277 -0
- package/src/media-store/kind.ts +2 -0
- package/src/media-store/purge.ts +21 -17
- package/src/media-store/put.ts +24 -8
- package/src/media-store/remote.ts +16 -7
- package/src/media-store/space-listing.ts +256 -0
- package/src/media-store/space.ts +46 -26
- package/src/media-store/sync.ts +5 -5
- package/src/media-store/tidy.ts +98 -0
- package/src/media-store/upload.ts +3 -3
- package/src/media-store/webp.ts +66 -0
- package/src/messages/guard.ts +49 -0
- package/src/messages/model.ts +16 -7
- package/src/messages/objects.ts +201 -0
- package/src/messages/routes.ts +14 -4
- package/src/messages/score.ts +3 -3
- package/src/messages/write.ts +285 -0
- package/src/pages/frame-client.ts +191 -4
- package/src/plan/planner.ts +28 -17
- package/src/recordings/media-kind.ts +1 -0
- package/src/recordings/model.ts +1 -1
- package/src/recordings/recorder-app/Capture.swift +9 -7
- package/src/reflect/hq-corpus.ts +56 -0
- package/src/reflect/prompt-corpus.ts +3 -1
- package/src/reflect/transcript.ts +129 -37
- package/src/reflections/reflections-queue.ts +1 -1
- package/src/release/gate-checkout.ts +2 -1
- package/src/release/git-facts.ts +3 -2
- package/src/release/machine-words.ts +67 -0
- package/src/release/public-clean.ts +11 -5
- package/src/releases/from-card.ts +1 -1
- package/src/releases/routes.ts +10 -5
- package/src/releases/store.ts +10 -1
- package/src/repo-config.ts +71 -19
- package/src/review/anim.ts +3 -3
- package/src/review/answer-kinds.ts +131 -0
- package/src/review/auto.ts +2 -2
- package/src/review/band.ts +53 -0
- package/src/review/branch-hold.ts +84 -0
- package/src/review/card-db.ts +254 -0
- package/src/review/card-rows.ts +267 -0
- package/src/review/cells.ts +360 -57
- package/src/review/close.ts +92 -0
- package/src/review/draft-card.ts +33 -0
- package/src/review/draft-model.ts +78 -0
- package/src/review/events.ts +171 -0
- package/src/review/format.ts +152 -19
- package/src/review/glyphs.ts +63 -0
- package/src/review/gone.ts +98 -0
- package/src/review/holds-sync.ts +62 -0
- package/src/review/holds.ts +85 -0
- package/src/review/house-kind-defs.ts +41 -0
- package/src/review/inbox-hook.ts +23 -10
- package/src/review/inbox-read.ts +201 -0
- package/src/review/instructions.ts +199 -0
- package/src/review/kind-apply.ts +61 -0
- package/src/review/kind-catalog.ts +96 -0
- package/src/review/kinds.ts +278 -0
- package/src/review/lane-ask.ts +109 -0
- package/src/review/marks.ts +1 -1
- package/src/review/media-kind.ts +7 -5
- package/src/review/media-read.ts +9 -7
- package/src/review/media.ts +32 -5
- package/src/review/model.ts +582 -109
- package/src/review/move.ts +491 -0
- package/src/review/need-address.ts +15 -0
- package/src/review/need-threads.ts +93 -0
- package/src/review/notes.ts +12 -20
- package/src/review/object-card.ts +48 -0
- package/src/review/object-read.ts +31 -0
- package/src/review/owner-verdict.ts +36 -0
- package/src/review/parties.ts +182 -0
- package/src/review/previews.ts +18 -20
- package/src/review/project.ts +1 -1
- package/src/review/projections.ts +235 -0
- package/src/review/referring.ts +54 -0
- package/src/review/reflection-object.ts +195 -0
- package/src/review/rev.ts +8 -0
- package/src/review/role.ts +1 -1
- package/src/review/routes.ts +194 -38
- package/src/review/secret-route.ts +80 -0
- package/src/review/snooze.ts +38 -0
- package/src/review/stage-card.ts +12 -8
- package/src/review/stage-routes.ts +1 -1
- package/src/review/store.ts +851 -124
- package/src/review/supersede.ts +116 -0
- package/src/review/take-back.ts +52 -0
- package/src/review/thread-fold.ts +64 -0
- package/src/review/threads.ts +349 -14
- package/src/review/traces.ts +218 -0
- package/src/review/trailer-auto-mock.ts +63 -0
- package/src/review/trailer-card.ts +6 -6
- package/src/review/trailer-desk.ts +41 -7
- package/src/review/trailer-media.ts +1 -0
- package/src/review/trailer-model.ts +8 -0
- package/src/review/trailer-notes.ts +1 -1
- package/src/review/trailer-routes.ts +9 -1
- package/src/review/unit.ts +77 -11
- package/src/review/verdict-items.ts +73 -0
- package/src/review/verdict-write.ts +15 -0
- package/src/review/wait.ts +85 -0
- package/src/review/watchers.ts +23 -10
- package/src/rules/untrack-generated.ts +92 -8
- package/src/scaffold/files/claude-settings-local.json +2 -0
- package/src/secrets/archive-mark.ts +52 -0
- package/src/secrets/archive.ts +83 -0
- package/src/secrets/copy.ts +14 -14
- package/src/secrets/held.ts +16 -0
- package/src/secrets/keychain-write.ts +48 -0
- package/src/secrets/keychain.ts +116 -0
- package/src/secrets/lapse-mark.ts +33 -0
- package/src/secrets/lapse.ts +60 -0
- package/src/secrets/list.ts +21 -17
- package/src/secrets/manager.ts +55 -26
- package/src/secrets/read.ts +385 -0
- package/src/secrets/tail.ts +31 -0
- package/src/secrets/who-reads.ts +49 -0
- package/src/serve/door-forward.ts +268 -0
- package/src/serve/door-names.ts +47 -0
- package/src/serve/embed.ts +1 -1
- package/src/serve/hub-app/activity-view.tsx +56 -32
- package/src/serve/hub-app/activity.css +7 -1
- package/src/serve/hub-app/asks-page.tsx +49 -0
- package/src/serve/hub-app/asks-st.ts +25 -0
- package/src/serve/hub-app/auto-text.tsx +14 -6
- package/src/serve/hub-app/benign-errors.ts +15 -1
- package/src/serve/hub-app/card-head.tsx +49 -0
- package/src/serve/hub-app/check-view.tsx +3 -2
- package/src/serve/hub-app/clock-svc.ts +1 -2
- package/src/serve/hub-app/code-copy.ts +35 -0
- package/src/serve/hub-app/col-card.tsx +72 -30
- package/src/serve/hub-app/col-list-page.tsx +125 -0
- package/src/serve/hub-app/col-list-st.ts +103 -0
- package/src/serve/hub-app/col-tables-view.tsx +17 -45
- package/src/serve/hub-app/col-tables.ts +76 -8
- package/src/serve/hub-app/cols-svc.ts +18 -39
- package/src/serve/hub-app/commands/commands-page.tsx +2 -1
- package/src/serve/hub-app/controls.css +83 -0
- package/src/serve/hub-app/database-st.ts +260 -0
- package/src/serve/hub-app/database-view.tsx +289 -0
- package/src/serve/hub-app/database.css +32 -0
- package/src/serve/hub-app/entry-bar.css +14 -0
- package/src/serve/hub-app/entry-bar.tsx +33 -0
- package/src/serve/hub-app/entry-pick.ts +31 -0
- package/src/serve/hub-app/floating.tsx +1 -0
- package/src/serve/hub-app/frames-st.ts +17 -1
- package/src/serve/hub-app/git-view.tsx +3 -2
- package/src/serve/hub-app/hash-route.ts +11 -1
- package/src/serve/hub-app/header-bar.tsx +14 -18
- package/src/serve/hub-app/home-st.ts +142 -11
- package/src/serve/hub-app/home-strip.css +6 -25
- package/src/serve/hub-app/home-strip.tsx +60 -93
- package/src/serve/hub-app/home.html +10 -0
- package/src/serve/hub-app/house-wiki-view.tsx +20 -0
- package/src/serve/hub-app/hub-app.tsx +71 -166
- package/src/serve/hub-app/hub-types.ts +5 -1
- package/src/serve/hub-app/hub.css +146 -71
- package/src/serve/hub-app/icons.tsx +32 -5
- package/src/serve/hub-app/identities-st.ts +56 -6
- package/src/serve/hub-app/identities-view.tsx +104 -61
- package/src/serve/hub-app/identities.css +17 -15
- package/src/serve/hub-app/identity-address.ts +5 -0
- package/src/serve/hub-app/inbox-st.ts +227 -49
- package/src/serve/hub-app/inbox-view.tsx +204 -120
- package/src/serve/hub-app/inbox.css +47 -47
- package/src/serve/hub-app/index.html +10 -0
- package/src/serve/hub-app/instructions.css +30 -0
- package/src/serve/hub-app/kept-cols.tsx +7 -0
- package/src/serve/hub-app/keys.ts +32 -17
- package/src/serve/hub-app/later.tsx +26 -0
- package/src/serve/hub-app/list-filter.tsx +14 -0
- package/src/serve/hub-app/list-walk.ts +72 -3
- package/src/serve/hub-app/machine-st.ts +2 -2
- package/src/serve/hub-app/machines-st.ts +251 -0
- package/src/serve/hub-app/machines-view.tsx +217 -0
- package/src/serve/hub-app/machines.css +67 -0
- package/src/serve/hub-app/markdown.css +51 -0
- package/src/serve/hub-app/md-copy.tsx +57 -0
- package/src/serve/hub-app/md.ts +25 -9
- package/src/serve/hub-app/media-view.tsx +4 -2
- package/src/serve/hub-app/messages/messages-page.tsx +81 -8
- package/src/serve/hub-app/messages/messages-st.ts +99 -3
- package/src/serve/hub-app/messages.css +14 -1
- package/src/serve/hub-app/objects.css +51 -0
- package/src/serve/hub-app/page-keys.ts +175 -0
- package/src/serve/hub-app/pages-frames.tsx +21 -3
- package/src/serve/hub-app/palette-st.ts +58 -11
- package/src/serve/hub-app/palette-view.tsx +3 -1
- package/src/serve/hub-app/pane-boundary.tsx +72 -0
- package/src/serve/hub-app/pane-errors.ts +54 -0
- package/src/serve/hub-app/plan-view.tsx +3 -2
- package/src/serve/hub-app/planned-view.tsx +3 -3
- package/src/serve/hub-app/planned.css +0 -4
- package/src/serve/hub-app/processes-view.tsx +3 -2
- package/src/serve/hub-app/project-list.css +46 -8
- package/src/serve/hub-app/project-list.tsx +125 -59
- package/src/serve/hub-app/projects-svc.ts +83 -8
- package/src/serve/hub-app/reader-chips.tsx +13 -0
- package/src/serve/hub-app/readme-view.tsx +2 -3
- package/src/serve/hub-app/readme.css +22 -6
- package/src/serve/hub-app/reflections-page.tsx +95 -0
- package/src/serve/hub-app/reflections-st.ts +17 -0
- package/src/serve/hub-app/releases/releases-page.tsx +28 -4
- package/src/serve/hub-app/releases/releases-st.ts +1 -1
- package/src/serve/hub-app/releases.css +0 -1
- package/src/serve/hub-app/repo-sections.ts +9 -5
- package/src/serve/hub-app/repo-st.ts +35 -8
- package/src/serve/hub-app/review/code-colors.ts +30 -0
- package/src/serve/hub-app/review/diff-view.tsx +75 -0
- package/src/serve/hub-app/review/dock.tsx +104 -0
- package/src/serve/hub-app/review/draft-card.tsx +163 -0
- package/src/serve/hub-app/review/group-block.tsx +209 -0
- package/src/serve/hub-app/review/instructions-view.tsx +116 -0
- package/src/serve/hub-app/review/item-verdict.tsx +38 -0
- package/src/serve/hub-app/review/kind-states.tsx +193 -0
- package/src/serve/hub-app/review/kind-view.tsx +1 -37
- package/src/serve/hub-app/review/kit.tsx +75 -29
- package/src/serve/hub-app/review/lane-bar.tsx +64 -0
- package/src/serve/hub-app/review/note-place.ts +1 -1
- package/src/serve/hub-app/review/object-card.tsx +62 -0
- package/src/serve/hub-app/review/object-panel.tsx +179 -0
- package/src/serve/hub-app/review/question-views.tsx +385 -0
- package/src/serve/hub-app/review/review-board.tsx +2 -2
- package/src/serve/hub-app/review/review-cells.tsx +148 -87
- package/src/serve/hub-app/review/review-kit.ts +27 -1
- package/src/serve/hub-app/review/review-list.tsx +160 -65
- package/src/serve/hub-app/review/review-page.tsx +12 -12
- package/src/serve/hub-app/review/review-st.ts +174 -47
- package/src/serve/hub-app/review/review-thread.tsx +214 -53
- package/src/serve/hub-app/review/review-views.tsx +494 -159
- package/src/serve/hub-app/review/thread-close.tsx +124 -0
- package/src/serve/hub-app/review/thread-control-st.ts +115 -0
- package/src/serve/hub-app/review/thread-control.tsx +74 -0
- package/src/serve/hub-app/review/thread-st.ts +288 -41
- package/src/serve/hub-app/review/trailer-card.tsx +2 -2
- package/src/serve/hub-app/review/trailer-page.tsx +37 -16
- package/src/serve/hub-app/review/trailer-st.ts +41 -7
- package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
- package/src/serve/hub-app/review.css +462 -97
- package/src/serve/hub-app/section-head.tsx +51 -0
- package/src/serve/hub-app/side-lists.ts +72 -0
- package/src/serve/hub-app/sidebar.tsx +6 -3
- package/src/serve/hub-app/site/site-part.tsx +2 -8
- package/src/serve/hub-app/site/site-st.ts +4 -4
- package/src/serve/hub-app/social/calendar.tsx +5 -11
- package/src/serve/hub-app/social/comms-page.tsx +43 -15
- package/src/serve/hub-app/social/kit.tsx +32 -13
- package/src/serve/hub-app/social/next-release.tsx +3 -5
- package/src/serve/hub-app/social/post-card.tsx +142 -49
- package/src/serve/hub-app/social/post-page.tsx +80 -0
- package/src/serve/hub-app/social/problems.tsx +5 -9
- package/src/serve/hub-app/social/serial-writes.ts +13 -0
- package/src/serve/hub-app/social/social-model.ts +24 -5
- package/src/serve/hub-app/social/social-page.tsx +95 -36
- package/src/serve/hub-app/social/social-st.ts +162 -41
- package/src/serve/hub-app/social/stage-popup.tsx +1 -1
- package/src/serve/hub-app/social/stage-st.ts +1 -1
- package/src/serve/hub-app/social/step-layout.ts +1 -1
- package/src/serve/hub-app/social.css +10 -17
- package/src/serve/hub-app/space-st.ts +209 -0
- package/src/serve/hub-app/space-view.tsx +196 -0
- package/src/serve/hub-app/space.css +27 -0
- package/src/serve/hub-app/stores/stores-page.tsx +97 -25
- package/src/serve/hub-app/stores/stores-st.ts +44 -19
- package/src/serve/hub-app/stores.css +6 -1
- package/src/serve/hub-app/theme-st.ts +22 -9
- package/src/serve/hub-app/thread-row.tsx +101 -0
- package/src/serve/hub-app/time-ago.tsx +3 -2
- package/src/serve/hub-app/time-charts.tsx +291 -0
- package/src/serve/hub-app/time-pages.tsx +749 -0
- package/src/serve/hub-app/time-st.ts +162 -0
- package/src/serve/hub-app/time-view.tsx +77 -0
- package/src/serve/hub-app/time.css +135 -0
- package/src/serve/hub-app/tree-build.ts +52 -42
- package/src/serve/hub-app/tree-row.tsx +3 -11
- package/src/serve/hub-app/tree-svc.ts +18 -9
- package/src/serve/hub-app/urls-svc.ts +154 -0
- package/src/serve/hub-app/urls-view.tsx +117 -0
- package/src/serve/hub-app/urls.css +30 -0
- package/src/serve/hub-app/vault-st.ts +127 -0
- package/src/serve/hub-app/vault-view.tsx +154 -0
- package/src/serve/hub-app/vault.css +38 -0
- package/src/serve/hub-app/veille/veille-page.tsx +2 -11
- package/src/serve/hub-app/veille/veille-st.ts +12 -10
- package/src/serve/hub-app/veille.css +0 -1
- package/src/serve/hub-app/waiting-svc.ts +29 -0
- package/src/serve/hub-app/when-view.tsx +6 -3
- package/src/serve/hub-app/wiki-st.ts +30 -4
- package/src/serve/hub-app/wikis-view.tsx +6 -5
- package/src/serve/hub-runtime.ts +35 -8
- package/src/serve/project-gutter-route.ts +42 -19
- package/src/serve/project-gutter.ts +16 -50
- package/src/serve/same-origin.ts +13 -0
- package/src/serve/secret-gate.ts +21 -0
- package/src/serve/serve-hub.ts +38 -20
- package/src/serve/tailnet-caller.ts +117 -0
- package/src/shipkit-files.ts +16 -2
- package/src/shipkit.ts +3 -3
- package/src/shot/shooter.ts +616 -420
- package/src/shot/shot-ask.ts +246 -155
- package/src/site/desk.ts +4 -4
- package/src/smoke/run-smoke.ts +6 -6
- package/src/social/brands.ts +4 -0
- package/src/social/card-drafts.ts +11 -19
- package/src/social/cover.ts +202 -0
- package/src/social/desk-index.ts +34 -13
- package/src/social/discord-layout.ts +37 -13
- package/src/social/drafts.ts +7 -4
- package/src/social/import-drafts.ts +244 -0
- package/src/social/kind-pages.ts +3 -3
- package/src/social/kinds.ts +1 -1
- package/src/social/load.ts +111 -65
- package/src/social/media-kind.ts +68 -160
- package/src/social/media-of.ts +5 -4
- package/src/social/open.ts +3 -2
- package/src/social/post-object.ts +120 -0
- package/src/social/post-sources.ts +136 -0
- package/src/social/post-text.ts +103 -0
- package/src/social/posts.ts +378 -0
- package/src/social/presence.ts +7 -5
- package/src/social/publish/discord.ts +5 -2
- package/src/social/publish/index.ts +17 -5
- package/src/social/publish/secret.ts +4 -4
- package/src/social/release-stage.ts +79 -63
- package/src/social/routes.ts +89 -24
- package/src/social/stage.ts +43 -58
- package/src/social/stats.ts +12 -9
- package/src/social/strip.ts +4 -1
- package/src/social/text.ts +4 -3
- package/src/social/thumbnail.ts +347 -0
- package/src/social/tracker.ts +1 -1
- package/src/social/writes.ts +12 -29
- package/src/stores/collection.ts +15 -11
- package/src/stores/desk.ts +246 -47
- package/src/stores/model.ts +72 -6
- package/src/stores/routes.ts +37 -12
- package/src/stores/unit.ts +16 -10
- package/src/suite/judge-suites.ts +41 -11
- package/src/suite/select.ts +45 -3
- package/src/suite/suite-cli.ts +16 -10
- package/src/trailer/bed.ts +1 -1
- package/src/trailer/build.ts +134 -21
- package/src/trailer/ffmpeg.ts +7 -0
- package/src/trailer/fonts.ts +3 -2
- package/src/trailer/grammar.ts +201 -2
- package/src/trailer/graph.ts +42 -5
- package/src/trailer/look.ts +21 -0
- package/src/trailer/mock.ts +154 -0
- package/src/trailer/passage.ts +65 -26
- package/src/trailer/score/heard.ts +89 -0
- package/src/trailer/score/sound.ts +14 -8
- package/src/trailer/sound/eleven.ts +33 -3
- package/src/trailer/sound/run.ts +16 -6
- package/src/trailer/stitch.ts +26 -5
- package/src/trailer/titles.ts +82 -19
- package/src/trailer/versions.ts +1 -3
- package/src/trailer/vertical.ts +3 -1
- package/src/urls/frame.ts +195 -0
- package/src/urls/routes.ts +43 -0
- package/src/urls/rows.ts +171 -0
- package/src/urls/unit.ts +73 -0
- package/src/vault/house-keys.ts +42 -0
- package/src/vault/layout.ts +50 -0
- package/src/vault/policy.ts +165 -0
- package/src/vault/vault-audit.ts +276 -0
- package/src/vault/vault-client.ts +40 -0
- package/src/vault/vault-config.ts +159 -0
- package/src/vault/vault-destroy.ts +78 -0
- package/src/vault/vault-handover.ts +305 -0
- package/src/vault/vault-http.ts +360 -0
- package/src/vault/vault-import.ts +213 -0
- package/src/vault/vault-init.ts +328 -0
- package/src/vault/vault-minter.ts +271 -0
- package/src/vault/vault-restore.ts +333 -0
- package/src/vault/vault-serve.ts +342 -0
- package/src/vault/vault-snapshot.ts +281 -0
- package/src/veille/asks.ts +1 -1
- package/src/veille/desk.ts +2 -2
- package/src/veille/identity.ts +2 -2
- package/src/wiki/graph-pages.ts +13 -1
- package/src/wiki/scan-md.ts +1 -1
- package/src/asks/asks-queue.ts +0 -266
- package/src/social/migrate.ts +0 -123
package/src/home/other-macs.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// machines). Nothing to configure: tailscale lists the peers, and a peer counts once its home answers on the home
|
|
3
3
|
// port. Asked in the background at most every few minutes, so no page poll ever waits on the network.
|
|
4
4
|
import { homePort, publicHome } from './home-paths.ts'
|
|
5
|
-
import { TAILSCALE } from './machine-host.ts'
|
|
5
|
+
import { TAILSCALE, tailscaleEnv } from './machine-host.ts'
|
|
6
6
|
|
|
7
7
|
export type OtherMac = { name: string; url: string }
|
|
8
8
|
type Peer = { DNSName?: string; OS?: string; Online?: boolean }
|
|
@@ -23,7 +23,7 @@ export function macPeers(status: TailscaleStatus): { name: string; host: string
|
|
|
23
23
|
export async function tailscaleStatus(bins: string[] = TAILSCALE): Promise<TailscaleStatus | null> {
|
|
24
24
|
for (const bin of bins) {
|
|
25
25
|
try {
|
|
26
|
-
const p = Bun.spawn([bin, 'status', '--json'], { stdout: 'pipe', stderr: 'ignore' })
|
|
26
|
+
const p = Bun.spawn([bin, 'status', '--json'], { stdout: 'pipe', stderr: 'ignore', env: tailscaleEnv() })
|
|
27
27
|
const timer = setTimeout(() => p.kill(), 3000)
|
|
28
28
|
const out = await new Response(p.stdout).text()
|
|
29
29
|
clearTimeout(timer)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// could this machine be made again from the Space alone? One line a thing a resume needs, each with where its copy
|
|
2
|
+
// is and its age, from what the jobs and the drills already recorded: no download and no restore here (the drills
|
|
3
|
+
// stay their own commands). What is not in the Space by design is said as such, never claimed present
|
|
4
|
+
import type { Drill } from '../hq/replica.ts'
|
|
5
|
+
import type { BackupDrill } from '../media-store/backup/restore.ts'
|
|
6
|
+
import type { ProvedRecord, Sent } from '../vault/vault-snapshot.ts'
|
|
7
|
+
import { snapshotHealth } from '../vault/vault-snapshot.ts'
|
|
8
|
+
|
|
9
|
+
const H = 3600_000
|
|
10
|
+
const DAY = 24 * H
|
|
11
|
+
/** a backup run older than this is stale: the daemon runs one within minutes of a change */
|
|
12
|
+
export const RUN_STALE_MS = 26 * H
|
|
13
|
+
/** a drill older than this is stale: the hq's runs once a week */
|
|
14
|
+
export const DRILL_STALE_MS = 8 * DAY
|
|
15
|
+
|
|
16
|
+
export type ResumeState = {
|
|
17
|
+
now: number
|
|
18
|
+
/** the hq's database: null when this machine joined another hq (its copy is checked there) */
|
|
19
|
+
hq: { replica: boolean; drill: Drill | null } | null
|
|
20
|
+
backup: { lastRun: { at: number } | null; drill: BackupDrill | null }
|
|
21
|
+
media: { waiting: number; bytes: number; failing: number }
|
|
22
|
+
/** null when this machine runs no vault */
|
|
23
|
+
vault: { sent: Sent | null; proved: ProvedRecord | null; changed: { stamp: string; at: number } | null; stamp: string | null; deadDisk?: ProvedRecord | null } | null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ResumeLine = { level: 'ok' | 'warn' | 'fail' | 'note'; text: string; fix?: string }
|
|
27
|
+
|
|
28
|
+
const age = (ms: number): string => (ms < H ? `${Math.round(ms / 60_000)} min` : ms < 2 * DAY ? `${(ms / H).toFixed(1)} h` : `${(ms / DAY).toFixed(1)} days`)
|
|
29
|
+
|
|
30
|
+
export function resumeLines(s: ResumeState): ResumeLine[] {
|
|
31
|
+
const out: ResumeLine[] = []
|
|
32
|
+
if (s.hq == null) out.push({ level: 'note', text: "the hq's database: this machine joined another hq, whose machine holds its copy" })
|
|
33
|
+
else if (!s.hq.replica) out.push({ level: 'fail', text: "the hq's database: no second copy, it is on this disk only", fix: 'serve.hqReplica in repo.config.ts, then sk gp start hq-replica' })
|
|
34
|
+
else if (s.hq.drill == null) out.push({ level: 'warn', text: "the hq's database: its replica runs, and no drill has proved it yet", fix: 'sk hq drill' })
|
|
35
|
+
else if (!s.hq.drill.ok) out.push({ level: 'fail', text: `the hq's database: its replica failed its last drill, ${age(s.now - s.hq.drill.at)} ago: ${s.hq.drill.why}`, fix: 'sk gp restart hq-replica, then sk hq drill' })
|
|
36
|
+
else out.push({ level: s.now - s.hq.drill.at > DRILL_STALE_MS ? 'warn' : 'ok', text: `the hq's database: in its replica (Litestream); last drill passed ${age(s.now - s.hq.drill.at)} ago, ${s.hq.drill.rows} rows (the replica's last write is not recorded: the drill proves it)`, ...(s.now - s.hq.drill.at > DRILL_STALE_MS ? { fix: 'sk hq drill' } : {}) })
|
|
37
|
+
const run = s.backup.lastRun
|
|
38
|
+
if (run == null) out.push({ level: 'fail', text: "this machine's own state: no backup run yet", fix: 'sk backup' })
|
|
39
|
+
else out.push({ level: s.now - run.at > RUN_STALE_MS ? 'warn' : 'ok', text: `this machine's own state, the hq's forgotten rows with it (hq.sqlite.forgotten): in the backup, last run ${age(s.now - run.at)} ago`, ...(s.now - run.at > RUN_STALE_MS ? { fix: 'sk backup' } : {}) })
|
|
40
|
+
const d = s.backup.drill
|
|
41
|
+
if (d == null) out.push({ level: 'warn', text: 'the backup: no drill has restored it yet', fix: 'sk backup drill' })
|
|
42
|
+
else if (d.failed > 0) out.push({ level: 'fail', text: `the backup: its last drill, ${age(s.now - d.at)} ago, did not bring back ${d.failed} of ${d.files} files`, fix: 'sk backup drill' })
|
|
43
|
+
else out.push({ level: s.now - d.at > DRILL_STALE_MS ? 'warn' : 'ok', text: `the backup: last drill restored ${d.restored} of ${d.files} files ${age(s.now - d.at)} ago`, ...(s.now - d.at > DRILL_STALE_MS ? { fix: 'sk backup drill' } : {}) })
|
|
44
|
+
if (s.media.waiting === 0) out.push({ level: 'ok', text: 'the media: every file is up in the Space, none waits' })
|
|
45
|
+
else out.push({ level: 'warn', text: `the media: ${s.media.waiting} files (${(s.media.bytes / 1e6).toFixed(1)} MB) wait to go up${s.media.failing > 0 ? `, ${s.media.failing} failed their last try` : ''}`, fix: 'sk media status' })
|
|
46
|
+
if (s.vault == null) out.push({ level: 'note', text: 'the vault: this machine runs none' })
|
|
47
|
+
else {
|
|
48
|
+
const h = snapshotHealth({ ...s.vault, now: s.now })
|
|
49
|
+
out.push({ level: h.warn.length === 0 ? 'ok' : s.vault.sent == null ? 'fail' : 'warn', text: `the vault: ${h.lines.join('; ')}`, ...(h.warn.length > 0 ? { fix: 'sk vault snapshot --copy, then sk vault snapshot --prove --from-space' } : {}) })
|
|
50
|
+
}
|
|
51
|
+
out.push({ level: 'note', text: "not in the Space, by design: the vault's seal key and its recovery key. They belong in the owner's password manager; this check cannot see a password manager and does not claim they are there" })
|
|
52
|
+
out.push({ level: 'note', text: "not in the Space, by design: the Space's own access key, without which nothing above can be fetched. It belongs in the owner's password manager; a new one is made in the provider's control panel (DigitalOcean: API, Spaces Keys)" })
|
|
53
|
+
return out
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** the state of this machine, from the records the jobs and drills wrote, and the vault's stamp: no download */
|
|
57
|
+
export async function resumeHere(root: string, now: number = Date.now()): Promise<ResumeState> {
|
|
58
|
+
const { carriesHq } = await import('../hq/hq-local.ts')
|
|
59
|
+
const { lastDrill } = await import('../hq/replica.ts')
|
|
60
|
+
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
61
|
+
const { lastRun } = await import('../media-store/backup/run.ts')
|
|
62
|
+
const { lastBackupDrill } = await import('../media-store/backup/restore.ts')
|
|
63
|
+
const { waitingCounts } = await import('../media-store/daemon.ts')
|
|
64
|
+
const { vaultInitialised, vaultPlace } = await import('../vault/vault-config.ts')
|
|
65
|
+
const { machineGet } = await import('../core/machine-db.ts')
|
|
66
|
+
const { CHANGED_KEY, DEAD_DISK_KEY, PROVED_KEY, SENT_KEY, vaultStamp } = await import('../vault/vault-snapshot.ts')
|
|
67
|
+
const { minterOf } = await import('../vault/vault-minter.ts')
|
|
68
|
+
const run = lastRun()
|
|
69
|
+
const minter = vaultInitialised() ? minterOf(vaultPlace()) : null
|
|
70
|
+
return {
|
|
71
|
+
now,
|
|
72
|
+
hq: carriesHq() ? { replica: (await loadRepoConfig(root).catch(() => null))?.serve?.hqReplica != null, drill: lastDrill() } : null,
|
|
73
|
+
backup: { lastRun: run == null ? null : { at: Date.parse(run.at) }, drill: lastBackupDrill() },
|
|
74
|
+
media: waitingCounts(),
|
|
75
|
+
vault: vaultInitialised()
|
|
76
|
+
? { sent: machineGet<Sent>(SENT_KEY), proved: machineGet<ProvedRecord>(PROVED_KEY), changed: machineGet<{ stamp: string; at: number }>(CHANGED_KEY), deadDisk: machineGet<ProvedRecord>(DEAD_DISK_KEY), stamp: minter == null ? null : await vaultStamp(minter).then((x) => x.stamp, () => null) }
|
|
77
|
+
: null,
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/home/run-daemon.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { ensureIdentity } from '../core/identity.ts'
|
|
|
20
20
|
import { homedir } from 'os'
|
|
21
21
|
import { join } from 'path'
|
|
22
22
|
import { startBeat } from './beat.ts'
|
|
23
|
+
import { startPublishing } from '../core/machine-read.ts'
|
|
23
24
|
import { childBeat, childLog, daemonPort, homeDir, homePort, homeUp, houseOfIndex, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
|
|
24
25
|
import { inboxAddress } from './inbox-shape.ts'
|
|
25
26
|
import { HomeState } from './home-state.ts'
|
|
@@ -27,7 +28,8 @@ import { Hubs } from './hubs.ts'
|
|
|
27
28
|
import { Planner } from '../plan/planner.ts'
|
|
28
29
|
import { machineCatchUp } from '../plan/catch-up.ts'
|
|
29
30
|
import { serveDaemon } from './serve-daemon.ts'
|
|
30
|
-
import {
|
|
31
|
+
import { carriedHq, carriesHq, hqOpen, joinCarriedHq, setHqPort } from '../hq/hq-local.ts'
|
|
32
|
+
import { jobsLimit, startJobs } from './daemon-jobs.ts'
|
|
31
33
|
import { Widgets } from './widgets.ts'
|
|
32
34
|
import { machinePublicHost } from './machine-host.ts'
|
|
33
35
|
import { OtherMacs } from './other-macs.ts'
|
|
@@ -42,6 +44,22 @@ const onlyRepos = (): Set<string> | undefined => {
|
|
|
42
44
|
|
|
43
45
|
export type HomeIo = { print: (l: string) => void; printErr: (l: string) => void }
|
|
44
46
|
|
|
47
|
+
/** a daemon that joined no other hq carries one and is its first node (wiki tools/shipkit/hq.md): a failure is
|
|
48
|
+
* said and never stops the daemon, since nothing but the machines page reads the hq yet */
|
|
49
|
+
function joinOwnHq(printErr: (l: string) => void): void {
|
|
50
|
+
if (!carriesHq()) return
|
|
51
|
+
try {
|
|
52
|
+
const store = carriedHq()
|
|
53
|
+
const r = store == null ? { refused: 'its file does not open' } : joinCarriedHq(store, Date.now())
|
|
54
|
+
if ('refused' in r) printErr(`WARN the hq this daemon carries: ${r.refused}`)
|
|
55
|
+
// the owner opened this hq to his other machines (sk hq open): its door again, after a restart
|
|
56
|
+
const d = hqOpen() ? setHqPort(true) : null
|
|
57
|
+
if (d != null && 'refused' in d) printErr(`WARN ${d.refused}`)
|
|
58
|
+
} catch (e) {
|
|
59
|
+
printErr(`WARN the hq this daemon carries: ${(e as Error).message}`)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
45
63
|
export async function runDaemon(root: string, io: HomeIo, o: { port?: number } = {}): Promise<number> {
|
|
46
64
|
const own = o.port ?? daemonPort()
|
|
47
65
|
// the port a page reaches every hub on: the web's
|
|
@@ -132,17 +150,20 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
|
|
|
132
150
|
otherMacs: () => otherMacs.get(),
|
|
133
151
|
})
|
|
134
152
|
io.print(`daemon → http://127.0.0.1:${home.server.port} (the page: http://localhost:${port})`)
|
|
153
|
+
joinOwnHq(io.printErr)
|
|
135
154
|
// the retention sweep (nothing grows unbound, core/retention.ts), the media store and the backup of the
|
|
136
155
|
// machine-only state, each a niced child process: never a job's body on this loop (daemon-jobs.ts). A daemon
|
|
137
|
-
// limited to some repos (SHIPKIT_DAEMON_ONLY) is a trial and runs none
|
|
138
|
-
const jobs = onlyRepos() == null ? startJobs({ cli: CLI, cwd: root, dir: join(dir, 'jobs'), log: childLog(dir, 'daemon'), printErr: io.printErr }) : null
|
|
156
|
+
// limited to some repos (SHIPKIT_DAEMON_ONLY) is a trial and runs none, unless SHIPKIT_DAEMON_JOBS names some
|
|
157
|
+
const jobs = onlyRepos() == null || jobsLimit() != null ? startJobs({ cli: CLI, cwd: root, dir: join(dir, 'jobs'), log: childLog(dir, 'daemon'), printErr: io.printErr }) : null
|
|
139
158
|
// a job that holds the loop holds every page: each stall is said with the work that overlapped it
|
|
140
159
|
const stalls = loopWatch.start(io.printErr)
|
|
141
160
|
// pm tells a starved daemon from a hung one by this beat: it turns with the loop
|
|
142
161
|
const beat = startBeat(childBeat(dir, 'daemon'))
|
|
143
162
|
// its memory as a trend: a line only when it moved by a tenth, at most every 10 minutes
|
|
144
163
|
const memory = new MemoryWatch().start(io.print)
|
|
145
|
-
|
|
164
|
+
// the cores in use, smoothed over twenty seconds, for every command that judges the machine
|
|
165
|
+
const cpu = startPublishing()
|
|
166
|
+
const code = reloadOnOwnCode({ role: 'daemon', entry: fileURLToPath(import.meta.url), busy: () => hubs.busy(), before: () => { stalls(); beat(); memory(); cpu(); jobs?.stop(); home.stop() }, keep: true, io })
|
|
146
167
|
io.print(` ${house.repos.length} repos, state in ${dir}, reloads on ${code.files} lib files`)
|
|
147
168
|
for (const sig of ['SIGINT', 'SIGTERM'] as const)
|
|
148
169
|
process.on(sig, () => {
|
package/src/home/run-pm.ts
CHANGED
|
@@ -21,25 +21,38 @@ const RUN_PM = fileURLToPath(import.meta.url)
|
|
|
21
21
|
|
|
22
22
|
/** how often pm stats what its last read of the house side saw */
|
|
23
23
|
export const PM_RESCAN_MS = 15_000
|
|
24
|
+
/** the longest wait between two reads of an answer that holds errors */
|
|
25
|
+
export const PM_RETRY_MAX_MS = 10 * 60_000
|
|
24
26
|
|
|
25
27
|
/** pm's reread of the house side: the child runs again only once a stat of
|
|
26
28
|
* a path the last answer read moved. A few ms of stats per poll, against a
|
|
27
29
|
* child that imports every unit file */
|
|
28
30
|
export class PmConfigWatch {
|
|
29
31
|
private last: PmConfig | null = null
|
|
32
|
+
/** reads in a row that came back with errors, and when the next one is due */
|
|
33
|
+
private failed = 0
|
|
34
|
+
private retryAt = 0
|
|
30
35
|
|
|
31
36
|
constructor(private readonly read: () => Promise<PmConfig>) {}
|
|
32
37
|
|
|
33
|
-
seed(c: PmConfig): void {
|
|
38
|
+
seed(c: PmConfig, now = Date.now()): void {
|
|
34
39
|
this.last = c
|
|
40
|
+
this.failed = c.errors.length === 0 ? 0 : 1
|
|
41
|
+
this.retryAt = now + PM_RESCAN_MS
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
/** the new answer, or null when nothing it read moved
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
/** the new answer, or null when nothing it read moved. An answer that holds errors is read again though no input
|
|
45
|
+
* moved, each wait twice the last up to PM_RETRY_MAX_MS: the cause can sit in the lib, which is no input, and an
|
|
46
|
+
* unchanged answer is null */
|
|
47
|
+
async poll(now = Date.now()): Promise<PmConfig | null> {
|
|
48
|
+
const was = this.last
|
|
49
|
+
const moved = was == null || stampOf(was.inputs) !== was.stamp
|
|
50
|
+
if (!moved && (was.errors.length === 0 || now < this.retryAt)) return null
|
|
40
51
|
const c = await this.read()
|
|
41
52
|
this.last = c
|
|
42
|
-
|
|
53
|
+
this.failed = c.errors.length === 0 ? 0 : moved ? 1 : this.failed + 1
|
|
54
|
+
this.retryAt = now + Math.min(PM_RETRY_MAX_MS, PM_RESCAN_MS * 2 ** (this.failed - 1))
|
|
55
|
+
return !moved && was != null && JSON.stringify([c.errors, c.processes]) === JSON.stringify([was.errors, was.processes]) ? null : c
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
58
|
|
package/src/home/serve-daemon.ts
CHANGED
|
@@ -4,13 +4,28 @@
|
|
|
4
4
|
// sees the web origin. A terminal client (via-hub.ts, attach.ts) talks here
|
|
5
5
|
// directly, so a gate never depends on the web.
|
|
6
6
|
import { loopWatch } from '../core/loop-watch.ts'
|
|
7
|
+
import { carriedHqRoute } from '../hq/hq-local.ts'
|
|
8
|
+
import { loopbackHost } from '../serve/same-origin.ts'
|
|
7
9
|
import { homeRoutes, TICK_MS, type HomeDeps } from './home-routes.ts'
|
|
8
10
|
|
|
9
11
|
export function serveDaemon(d: HomeDeps & { daemonPort: number }) {
|
|
10
12
|
const routes = homeRoutes(d)
|
|
11
|
-
const fetch = (req: Request, srv: Bun.Server<unknown>): Promise<Response> =>
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const fetch = (req: Request, srv: Bun.Server<unknown>): Promise<Response> | Response =>
|
|
14
|
+
// the web and the terminal clients call the daemon by a loopback name: any other Host is a page of another
|
|
15
|
+
// site rebound to this machine
|
|
16
|
+
!loopbackHost(req) ? new Response(`refused: the daemon answers to a loopback name, never to ${req.headers.get('host') ?? 'a request with no Host'}`, { status: 403 }) :
|
|
17
|
+
// the hq this daemon carries answers its own paths behind its own token (hq/hq-routes.ts), before the home's routes
|
|
18
|
+
loopWatch.spanned(`${req.method} ${new URL(req.url).pathname}`, async () => (await carriedHqRoute(req, new URL(req.url).pathname)) ?? (await routes.handle(req, srv)) ?? new Response('not found', { status: 404 }))
|
|
19
|
+
const server = Bun.serve({
|
|
20
|
+
port: d.daemonPort,
|
|
21
|
+
hostname: '127.0.0.1',
|
|
22
|
+
fetch,
|
|
23
|
+
// a throw is said in the log and never to the caller: with no handler Bun answers a page with the source
|
|
24
|
+
error: (e) => {
|
|
25
|
+
console.error(`WARN the daemon failed a request: ${e.message}`)
|
|
26
|
+
return new Response('the daemon failed this request: its log says why', { status: 500 })
|
|
27
|
+
},
|
|
28
|
+
})
|
|
14
29
|
let stopped = false
|
|
15
30
|
let running = false
|
|
16
31
|
const timer = setInterval(() => {
|
package/src/home/serve-web.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// the web: ONE Bun.serve on the home port. It serves the one page bundle (the
|
|
2
|
-
// overview at `/`, the inbox at `/inbox`, the plan at `/planned`, the activity at `/activity`, a repo's hub page at
|
|
2
|
+
// overview at `/`, the house wiki at `/wiki`, the inbox at `/inbox`, the plan at `/planned`, the activity at `/activity`, a repo's hub page at
|
|
3
3
|
// `/r/<repo>/`, all views of one app) and proxies every api,
|
|
4
4
|
// graph and media request to the daemon, streams included, and /api/pm/* to
|
|
5
5
|
// pm. A browser only ever sees this origin.
|
|
@@ -10,16 +10,19 @@
|
|
|
10
10
|
// port directly, and lets this door through. The host guard runs here too: Bun's dev server, which bundles the page
|
|
11
11
|
// and drives its hot reload, answers only to a loopback Host, so it sits on a port of its own behind this one, and a
|
|
12
12
|
// request reaches it only once its Host is a loopback name or this Mac's tailnet name (machine-host.ts)
|
|
13
|
-
import { hostName, loopbackName, REACH_HEADER,
|
|
13
|
+
import { HOST_HEADER, hostName, loopbackName, REACH_HEADER, reachOfCaller, sameOrigin } from '../serve/same-origin.ts'
|
|
14
14
|
import { hubBase } from './home-paths.ts'
|
|
15
15
|
import { forwardPage, pagePath } from '../pages/forward.ts'
|
|
16
16
|
import { statSync } from 'fs'
|
|
17
17
|
import { HMR_BEAT_MS, HMR_KEEP_SCRIPT, HMR_WORDS } from './hmr-keep.ts'
|
|
18
|
+
import { broughtByProxy, crossSiteRefusal, DOOR_KEY_HEADER, DOOR_PATH, doorHostOf, doorKeyFor, doorPathOf, doorPolicy, foreignOrigin, forwardHop, loginHop, protocolsOf, urlHostOf, urlPolicy, wsUrl } from '../serve/door-forward.ts'
|
|
19
|
+
import type { DoorTarget } from '../hq/door.ts'
|
|
20
|
+
import type { UrlLogin } from '../urls/frame.ts'
|
|
18
21
|
|
|
19
22
|
/** the page routes: ONE app for the overview, the plan, and the hub page of
|
|
20
23
|
* each known repo, which moves between them in place (home-st.ts) */
|
|
21
24
|
export function pageRoutes<T>(names: string[], page: T): Record<string, T> {
|
|
22
|
-
const out: Record<string, T> = { '/': page, '/inbox': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page, '/recordings': page, '/identities': page }
|
|
25
|
+
const out: Record<string, T> = { '/': page, '/wiki': page, '/inbox': page, '/machines': page, '/database': page, '/vault': page, '/space': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page, '/time': page, '/recordings': page, '/identities': page }
|
|
23
26
|
for (const n of names) out[`${hubBase(n)}/`] = page
|
|
24
27
|
return out
|
|
25
28
|
}
|
|
@@ -58,8 +61,8 @@ export const LIST_RETRY_MS = 1_000
|
|
|
58
61
|
/** how long the web keeps a repo's page urls before it asks the daemon again */
|
|
59
62
|
export const PAGE_URLS_MS = 10_000
|
|
60
63
|
|
|
61
|
-
/** the home answers that can wait on git: the activity page's first read of a window, a repo's git page,
|
|
62
|
-
export const readsGit = (path: string): boolean => path === '/api/home/activity.json' || path === '/api/home/git.json' || path === '/api/home/insights.json'
|
|
64
|
+
/** the home answers that can wait on git or on a child: the activity page's first read of a window, a repo's git page, the insights page's read of every manifest, the time page's report */
|
|
65
|
+
export const readsGit = (path: string): boolean => path === '/api/home/activity.json' || path === '/api/home/git.json' || path === '/api/home/insights.json' || path === '/api/home/time.json'
|
|
63
66
|
|
|
64
67
|
/** a run or a check run streams for minutes, and a silent one is never cut */
|
|
65
68
|
export const streams = (path: string): boolean => /\/api\/(run|check\/run)$/.test(path)
|
|
@@ -202,11 +205,46 @@ export type WebDeps<T> = {
|
|
|
202
205
|
/** the files of the page's bundle: a page back on the hot reload socket after a gap reloads only when one moved.
|
|
203
206
|
* Without them it always reloads */
|
|
204
207
|
pageFiles?: () => Iterable<string>
|
|
208
|
+
/** the door's two lookups, in place of asking the daemon (a test) */
|
|
209
|
+
door?: DoorAsk
|
|
205
210
|
}
|
|
206
211
|
|
|
212
|
+
/** a refusal of the door: its words and its status */
|
|
213
|
+
export type DoorRefused = { refused: string; status: number }
|
|
214
|
+
/** where the door sends a request: on the hq's machine, a process of a machine; on any machine, its own process, and
|
|
215
|
+
* a declared url with the login its hop adds */
|
|
216
|
+
export type DoorAsk = { target(machine: string, process: string): Promise<DoorTarget | DoorRefused>; local(id: string, key: string | null): Promise<{ origin: string } | DoorRefused>; url(repo: string, id: string): Promise<UrlLogin | DoorRefused> }
|
|
217
|
+
|
|
218
|
+
/** how long the web keeps a url's login: a framed page asks dozens of files at once, the daemon reads it once */
|
|
219
|
+
export const URL_LOGIN_MS = 10_000
|
|
220
|
+
|
|
221
|
+
/** the door's lookups as the daemon answers them (hq/door-route.ts), never through the proxy: a page never asks them */
|
|
222
|
+
export function daemonDoor(daemon: string): DoorAsk {
|
|
223
|
+
const ask = async <T>(path: string, headers: Record<string, string> = {}): Promise<T | DoorRefused> => {
|
|
224
|
+
try {
|
|
225
|
+
const r = await fetch(`${daemon}${path}`, { headers, signal: AbortSignal.timeout(MACHINE_ANSWER_MS) })
|
|
226
|
+
const j = (await r.json().catch(() => ({ refused: `the daemon answers ${r.status}` }))) as T | { refused: string }
|
|
227
|
+
return r.ok ? (j as T) : { refused: (j as { refused?: string }).refused ?? `the daemon answers ${r.status}`, status: r.status }
|
|
228
|
+
} catch (e) {
|
|
229
|
+
return { refused: daemonDownText(daemon, (e as Error).message), status: 502 }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
target: (machine, process) => ask<DoorTarget>(`/api/home/door/target?${new URLSearchParams({ machine, process })}`),
|
|
234
|
+
local: (id, key) => ask<{ origin: string }>(`/api/home/door/local?${new URLSearchParams({ id })}`, key == null ? {} : { [DOOR_KEY_HEADER]: key }),
|
|
235
|
+
url: (repo, id) => ask<UrlLogin>(`/api/home/door/url?${new URLSearchParams({ repo, id })}`),
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** a close code one side may send again: a reserved one (no status, an abnormal end, a tls failure) reads as normal */
|
|
240
|
+
const sendableClose = (c: number): number => ((c >= 1000 && c <= 1003) || (c >= 1007 && c <= 1014) || (c >= 3000 && c <= 4999) ? c : 1000)
|
|
241
|
+
|
|
242
|
+
const doorText = (text: string, status: number): Response => new Response(text, { status, headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' } })
|
|
243
|
+
|
|
207
244
|
/** one browser socket to the page server's hot reload, piped to the same path there. `since`: the last time a socket
|
|
208
|
-
* that came back heard this web, null on a page's first socket
|
|
209
|
-
|
|
245
|
+
* that came back heard this web, null on a page's first socket. `door`: a socket through the door instead, piped to
|
|
246
|
+
* that url with those headers */
|
|
247
|
+
type Pipe = { path: string; up: WebSocket | null; queue: (string | Uint8Array<ArrayBuffer>)[]; since: number | null; door?: { url: string; headers: Record<string, string>; protocols: string[] } }
|
|
210
248
|
|
|
211
249
|
export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
|
|
212
250
|
let known = ''
|
|
@@ -250,9 +288,10 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
|
|
|
250
288
|
|
|
251
289
|
async function forward(req: Request, url: URL, srv: Bun.Server<Pipe>, key: string | null): Promise<Response> {
|
|
252
290
|
const headers = new Headers()
|
|
253
|
-
req.headers.forEach((v, k) => { if (!DROP.has(k)) headers.set(k, v) })
|
|
254
|
-
//
|
|
255
|
-
headers.set(REACH_HEADER,
|
|
291
|
+
req.headers.forEach((v, k) => { if (!DROP.has(k) && !k.startsWith('x-shipkit-')) headers.set(k, v) })
|
|
292
|
+
// the web's own tags, never one a browser sent: tailscaled passes x-shipkit-* as the client wrote it
|
|
293
|
+
headers.set(REACH_HEADER, reachOfCaller(req))
|
|
294
|
+
headers.set(HOST_HEADER, req.headers.get('host') ?? url.host)
|
|
256
295
|
// a run or a live stream can stay silent for minutes
|
|
257
296
|
srv.timeout(req, 0)
|
|
258
297
|
const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : await req.arrayBuffer()
|
|
@@ -337,6 +376,8 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
|
|
|
337
376
|
out.delete('content-length')
|
|
338
377
|
out.delete('transfer-encoding')
|
|
339
378
|
out.delete('connection')
|
|
379
|
+
// a page of another site never frames the home: it would frame a url's hop with the hub's own Referer
|
|
380
|
+
out.set('content-security-policy', "frame-ancestors 'self'")
|
|
340
381
|
const type = out.get('content-type') ?? ''
|
|
341
382
|
if (r.status === 200 && type.startsWith('text/html')) {
|
|
342
383
|
const page = new Response(r.body, { status: r.status, headers: out })
|
|
@@ -362,11 +403,126 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
|
|
|
362
403
|
return new Response(zipped, { status: 200, headers: out })
|
|
363
404
|
}
|
|
364
405
|
|
|
406
|
+
const doorAsk = d.door ?? daemonDoor(d.daemon)
|
|
407
|
+
const upgrading = (req: Request): boolean => req.headers.get('upgrade')?.toLowerCase() === 'websocket'
|
|
408
|
+
|
|
409
|
+
/** a socket through the door: the browser's upgraded here, the same path opened at `url` */
|
|
410
|
+
function doorSocket(req: Request, srv: Bun.Server<Pipe>, url: string, headers: Record<string, string>, answer: Record<string, string> = {}): Response | undefined {
|
|
411
|
+
const protocols = protocolsOf(req)
|
|
412
|
+
const ok = srv.upgrade(req, { data: { path: '', up: null, queue: [], since: null, door: { url, headers, protocols } }, headers: { ...answer, ...(protocols[0] == null ? {} : { 'sec-websocket-protocol': protocols[0] }) } })
|
|
413
|
+
return ok ? undefined : doorText('the socket through the door did not open', 400)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** `<process>.<machine>.localhost` on the hq's machine: that process, wherever the hq says it runs. Every answer
|
|
417
|
+
* under that name carries the door's content policy, added here last beside the process's own */
|
|
418
|
+
async function toDoor(req: Request, at: { process: string; machine: string }, srv: Bun.Server<Pipe>): Promise<Response | undefined> {
|
|
419
|
+
const host = (req.headers.get('host') ?? '').toLowerCase()
|
|
420
|
+
const policy = doorPolicy(host)
|
|
421
|
+
const r = await throughDoor(req, at, srv, host, policy)
|
|
422
|
+
if (r === undefined) return r
|
|
423
|
+
// beside the process's own, never in its place: the browser applies each policy, the stricter wins on each
|
|
424
|
+
const headers = new Headers(r.headers)
|
|
425
|
+
headers.append('content-security-policy', policy)
|
|
426
|
+
return new Response(r.body, { status: r.status, statusText: r.statusText, headers })
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
async function throughDoor(req: Request, at: { process: string; machine: string }, srv: Bun.Server<Pipe>, host: string, policy: string): Promise<Response | undefined> {
|
|
430
|
+
// a request a proxy brought (tailscale serve, from a device of the tailnet) never reaches the door
|
|
431
|
+
if (broughtByProxy(req)) return doorText('not found: the door answers on the machine that carries the hq only', 404)
|
|
432
|
+
const t = await doorAsk.target(at.machine, at.process)
|
|
433
|
+
if ('refused' in t) return doorText(`not found: ${t.refused}`, t.status === 502 ? 502 : 404)
|
|
434
|
+
const own = `http://${host}`
|
|
435
|
+
const foreign = foreignOrigin(req, own)
|
|
436
|
+
if (foreign != null) return doorText(foreign, 403)
|
|
437
|
+
const url = new URL(req.url)
|
|
438
|
+
const base = t.hop == null ? t.origin : `${t.hop.base}${DOOR_PATH}${at.process}`
|
|
439
|
+
const key = t.hop == null ? null : doorKeyFor(t.hop.node)
|
|
440
|
+
if (t.hop != null && key == null) return doorText('not found: the hq has no door secret yet: sk hq proxy on, then a report of that machine', 404)
|
|
441
|
+
if (upgrading(req)) return doorSocket(req, srv, wsUrl(base, `${url.pathname}${url.search}`), { origin: t.origin, ...(key == null ? {} : { [DOOR_KEY_HEADER]: key }) }, { 'content-security-policy': policy })
|
|
442
|
+
return forwardHop(req, `${base}${url.pathname}${url.search}`, { target: t.origin, own, key, srv })
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** each url name's login as the daemon gave it, kept URL_LOGIN_MS: one lookup for a burst of requests */
|
|
446
|
+
const urlLogins = new Map<string, { at: number; p: Promise<UrlLogin | DoorRefused> }>()
|
|
447
|
+
function urlLoginOf(repo: string, id: string): Promise<UrlLogin | DoorRefused> {
|
|
448
|
+
const key = `${repo}/${id}`
|
|
449
|
+
const held = urlLogins.get(key)
|
|
450
|
+
if (held != null && Date.now() - held.at < URL_LOGIN_MS) return held.p
|
|
451
|
+
const p = doorAsk.url(repo, id)
|
|
452
|
+
urlLogins.set(key, { at: Date.now(), p })
|
|
453
|
+
return p
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** each url name whose site took its login, by the declared origin and login it took: the login then goes at once.
|
|
457
|
+
* Server memory only; a refusal or another declaration forgets it */
|
|
458
|
+
const tookLogin = new Map<string, string>()
|
|
459
|
+
|
|
460
|
+
/** `<url id>--<repo>.localhost` on this Mac: that declared url, framed, its basic login added when the site asks it.
|
|
461
|
+
* Every answer under that name carries the url policy, added last beside the site's own */
|
|
462
|
+
async function toUrl(req: Request, at: { id: string; repo: string }, srv: Bun.Server<Pipe>): Promise<Response | undefined> {
|
|
463
|
+
const host = (req.headers.get('host') ?? '').toLowerCase()
|
|
464
|
+
const policy = urlPolicy(host)
|
|
465
|
+
const r = await throughUrl(req, at, srv, host, policy)
|
|
466
|
+
if (r === undefined) return r
|
|
467
|
+
const headers = new Headers(r.headers)
|
|
468
|
+
headers.append('content-security-policy', policy)
|
|
469
|
+
return new Response(r.body, { status: r.status, statusText: r.statusText, headers })
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
async function throughUrl(req: Request, at: { id: string; repo: string }, srv: Bun.Server<Pipe>, host: string, policy: string): Promise<Response | undefined> {
|
|
473
|
+
// the tailnet reaches the home through a proxy: a login is added for this Mac's own browser alone
|
|
474
|
+
if (broughtByProxy(req)) return doorText('not found: a url framed with its login answers on the Mac that serves the hub only', 404)
|
|
475
|
+
// a navigation another site started is a 204: the browser stays where it was, so no document of this origin
|
|
476
|
+
// is left for that site (its favicon would then be a same origin request)
|
|
477
|
+
const cross = crossSiteRefusal(req)
|
|
478
|
+
if (cross != null) return req.headers.get('sec-fetch-mode') === 'navigate' ? new Response(null, { status: 204, headers: { 'cache-control': 'no-store' } }) : doorText(cross, 403)
|
|
479
|
+
const own = `http://${host}`
|
|
480
|
+
const foreign = foreignOrigin(req, own)
|
|
481
|
+
if (foreign != null) return doorText(foreign, 403)
|
|
482
|
+
const t = await urlLoginOf(at.repo, at.id)
|
|
483
|
+
if ('refused' in t) return doorText(`not found: ${t.refused}`, t.status === 502 ? 502 : 404)
|
|
484
|
+
const url = new URL(req.url)
|
|
485
|
+
const key = `${at.repo}/${at.id}`
|
|
486
|
+
const declared = `${t.origin}\n${t.authorization ?? ''}`
|
|
487
|
+
const atOnce = t.authorization != null && tookLogin.get(key) === declared
|
|
488
|
+
if (upgrading(req)) {
|
|
489
|
+
const ws = wsUrl(t.origin, `${url.pathname}${url.search}`)
|
|
490
|
+
if (!loginHop(ws, t.origin)) return doorText('refused: a hop goes to the origin its repo declares', 403)
|
|
491
|
+
// a socket follows the http rule: its own authorization kept, the login only once the site took it
|
|
492
|
+
const auth = req.headers.get('authorization') ?? (atOnce ? t.authorization : null)
|
|
493
|
+
const cookie = req.headers.get('cookie')
|
|
494
|
+
return doorSocket(req, srv, ws, { origin: t.origin, ...(auth == null ? {} : { authorization: auth }), ...(cookie == null ? {} : { cookie }) }, { 'content-security-policy': policy })
|
|
495
|
+
}
|
|
496
|
+
const took = (yes: boolean): void => {
|
|
497
|
+
if (yes) tookLogin.set(key, declared)
|
|
498
|
+
else tookLogin.delete(key)
|
|
499
|
+
}
|
|
500
|
+
return forwardHop(req, `${t.origin}${url.pathname}${url.search}`, { target: t.origin, own, site: { login: t.authorization, atOnce, took }, srv })
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** `/door/<id>/<rest>` on any machine: its own process, for the hq's home and its key alone */
|
|
504
|
+
async function ownDoor(req: Request, url: URL, srv: Bun.Server<Pipe>): Promise<Response | undefined> {
|
|
505
|
+
const at = doorPathOf(url.pathname)
|
|
506
|
+
if (at == null) return doorText('not found: a door is /door/<process id>/', 404)
|
|
507
|
+
const t = await doorAsk.local(at.id, req.headers.get(DOOR_KEY_HEADER))
|
|
508
|
+
if ('refused' in t) return doorText(`not found: ${t.refused}`, t.status === 502 ? 502 : 404)
|
|
509
|
+
const foreign = foreignOrigin(req, t.origin)
|
|
510
|
+
if (foreign != null) return doorText(foreign, 403)
|
|
511
|
+
if (upgrading(req)) return doorSocket(req, srv, wsUrl(t.origin, `${at.rest}${url.search}`), { origin: t.origin })
|
|
512
|
+
return forwardHop(req, `${t.origin}${at.rest}${url.search}`, { target: t.origin, own: null, srv })
|
|
513
|
+
}
|
|
514
|
+
|
|
365
515
|
const fetchFn = async (req: Request, srv: Bun.Server<Pipe>): Promise<Response | undefined> => {
|
|
366
516
|
const host = req.headers.get('host')
|
|
367
517
|
if (!hostAllowed(host, hosts)) return new Response(hostRefusedText(host), { status: 403, headers: { 'content-type': 'text/plain; charset=utf-8' } })
|
|
518
|
+
// a door's own name is never a page of the home: none of the home's routes answers under it
|
|
519
|
+
const named = urlHostOf(host)
|
|
520
|
+
if (named != null) return toUrl(req, named, srv)
|
|
521
|
+
const door = doorHostOf(host)
|
|
522
|
+
if (door != null) return toDoor(req, door, srv)
|
|
368
523
|
const url = new URL(req.url)
|
|
369
524
|
const path = url.pathname
|
|
525
|
+
if (path.startsWith(DOOR_PATH)) return ownDoor(req, url, srv)
|
|
370
526
|
if (path === '/_bun/hmr' && req.headers.get('upgrade')?.toLowerCase() === 'websocket') {
|
|
371
527
|
const since = url.searchParams.get('since')
|
|
372
528
|
url.searchParams.delete('since')
|
|
@@ -405,6 +561,19 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
|
|
|
405
561
|
fetch: fetchFn,
|
|
406
562
|
websocket: {
|
|
407
563
|
open(ws) {
|
|
564
|
+
const door = ws.data.door
|
|
565
|
+
if (door != null) {
|
|
566
|
+
const up = new WebSocket(door.url, { headers: door.headers, protocols: door.protocols } as never)
|
|
567
|
+
up.binaryType = 'arraybuffer'
|
|
568
|
+
ws.data.up = up
|
|
569
|
+
up.onopen = () => {
|
|
570
|
+
for (const m of ws.data.queue.splice(0)) up.send(m)
|
|
571
|
+
}
|
|
572
|
+
up.onmessage = (e) => void ws.send(e.data as string | ArrayBuffer)
|
|
573
|
+
up.onclose = (e) => ws.close(sendableClose(e.code))
|
|
574
|
+
up.onerror = () => ws.close(1011)
|
|
575
|
+
return
|
|
576
|
+
}
|
|
408
577
|
hmrSockets.add(ws)
|
|
409
578
|
ws.send(`${HMR_WORDS.beat}${Date.now()}`)
|
|
410
579
|
ws.send(`${HMR_WORDS.head}${HEAD_STAMP}`)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// the daemon's job `space listing` (daemon-jobs.ts): each Space the house names listed whole, in a child, and kept
|
|
2
|
+
// in the machine db (media-store/space-listing.ts), at most once a day by itself and at once when the page's
|
|
3
|
+
// refresh asks. A look of the daemon is three rows of the machine db.
|
|
4
|
+
//
|
|
5
|
+
// The constraint a reader breaks first: every call here is a GET of a listing or of the bucket's settings. The job
|
|
6
|
+
// never puts, copies or deletes, and a Space it cannot list keeps its last listing and says why
|
|
7
|
+
import type { Database } from 'bun:sqlite'
|
|
8
|
+
import { machineDb, machineGet, machineSet } from '../core/machine-db.ts'
|
|
9
|
+
import { readLifecycle } from '../media-store/copy/lifecycle.ts'
|
|
10
|
+
import { signedCall, type SpaceConfig } from '../media-store/space.ts'
|
|
11
|
+
import { keepListing, listObjects, listUploads, listVersions, ruleWords, splitOf, type Counted, type Listed, type ListingRecord, type Split } from '../media-store/space-listing.ts'
|
|
12
|
+
import type { SpaceEnd } from './space-page.ts'
|
|
13
|
+
|
|
14
|
+
/** a listing by itself this often at most */
|
|
15
|
+
export const LIST_EVERY_MS = 86_400_000
|
|
16
|
+
/** the listing that runs: its pid and since when */
|
|
17
|
+
export const RUN_KEY = 'space-listing-run'
|
|
18
|
+
/** when the page's refresh asked a listing */
|
|
19
|
+
export const ASKED_KEY = 'space-listing-asked'
|
|
20
|
+
/** when the job last started a listing, whatever came of it */
|
|
21
|
+
export const TRIED_KEY = 'space-listing-tried'
|
|
22
|
+
/** why each Space could not be listed at the last try, '' when it was */
|
|
23
|
+
export const WHY_KEY = 'space-listing-why'
|
|
24
|
+
|
|
25
|
+
/** due when the page asked since the last try, or the last try is a day old */
|
|
26
|
+
export function spaceListingDue(now: number, get: <T>(k: string) => T | null = machineGet): boolean {
|
|
27
|
+
const tried = get<number>(TRIED_KEY) ?? 0
|
|
28
|
+
return (get<number>(ASKED_KEY) ?? 0) > tried || now - tried >= LIST_EVERY_MS
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** the refresh button: the next look of the daemon starts a listing */
|
|
32
|
+
export const askListing = (now: number = Date.now()): boolean => machineSet(ASKED_KEY, now)
|
|
33
|
+
|
|
34
|
+
const fail = (e: unknown): { why: string } => ({ why: (e as Error).message.slice(0, 300) })
|
|
35
|
+
|
|
36
|
+
/** the bucket's versioning, one GET */
|
|
37
|
+
async function versioningOf(c: SpaceConfig): Promise<'Enabled' | 'Suspended' | 'off'> {
|
|
38
|
+
const s = /<Status>([^<]+)<\/Status>/.exec(await signedCall(c, 'GET', null, { versioning: '' }))?.[1]
|
|
39
|
+
return s === 'Enabled' || s === 'Suspended' ? s : 'off'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** the listing against the machine's media index: what the index says is up and the listing lacks, what the listing
|
|
43
|
+
* holds and no row of the index names (an object the index derives, a preview, is named by media_objects). `since`:
|
|
44
|
+
* when the listing started; an object sent up from then on may sit behind the page already read, so it is not missing */
|
|
45
|
+
export function againstIndex(rows: readonly Listed[], media: Database | null, since: number): Counted<{ upNotListed: Split; notIndexed: Split }> {
|
|
46
|
+
if (media == null) return { why: 'the media index does not open' }
|
|
47
|
+
const listed = new Set(rows.map((r) => r.key))
|
|
48
|
+
const up = media.query('select key, size, up from media_objects where up is not null').all() as { key: string; size: number; up: number }[]
|
|
49
|
+
const known = new Set(up.map((u) => u.key))
|
|
50
|
+
for (const f of media.query('select key from media_files').all() as { key: string }[]) known.add(f.key)
|
|
51
|
+
return { upNotListed: splitOf(up.filter((u) => u.up < since && !listed.has(u.key))), notIndexed: splitOf(rows.filter((r) => !known.has(r.key))) }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const under = (key: string, prefixes: readonly string[]): boolean => prefixes.some((p) => key.startsWith(p))
|
|
55
|
+
|
|
56
|
+
/** the copy against the Space, both just listed */
|
|
57
|
+
export function againstSpace(space: readonly Listed[], copy: readonly Listed[], skip: readonly string[]): { lacks: Split; only: Split } {
|
|
58
|
+
const s = new Set(space.map((r) => r.key))
|
|
59
|
+
const c = new Set(copy.map((r) => r.key))
|
|
60
|
+
return { lacks: splitOf(space.filter((r) => !c.has(r.key) && !under(r.key, skip))), only: splitOf(copy.filter((r) => !s.has(r.key) && !under(r.key, ['_snapshots/']))) }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type Listing = { record: ListingRecord; rows: Listed[] }
|
|
64
|
+
|
|
65
|
+
/** one Space listed whole: its objects, its older versions, its unfinished uploads, its versioning and rules. Only
|
|
66
|
+
* the objects' listing is the truth: a part that fails is « not counted » with its reason */
|
|
67
|
+
export async function listOne(id: string, c: SpaceConfig, clock: () => number = () => performance.now(), now: () => number = Date.now): Promise<Listing> {
|
|
68
|
+
const t0 = clock()
|
|
69
|
+
const at = now()
|
|
70
|
+
const o = await listObjects(c)
|
|
71
|
+
let calls = o.calls
|
|
72
|
+
const v = await listVersions(c).then((x) => ((calls += x.calls), x.versions), fail)
|
|
73
|
+
const u = await listUploads(c).then((x) => ((calls += x.calls), x.uploads), fail)
|
|
74
|
+
const versioning = await versioningOf(c).then((x) => (calls++, x), fail)
|
|
75
|
+
const lifecycle = await readLifecycle(c).then((x) => (calls++, x == null ? null : x.map(ruleWords)), fail)
|
|
76
|
+
const record = { space: id, at, ms: Math.round(clock() - t0), calls, objects: 0, bytes: 0, versions: v, uploads: u, versioning, lifecycle, keptBytes: 0 }
|
|
77
|
+
return { record, rows: o.rows }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** every Space the house names listed and kept; each one's reason when it could not be */
|
|
81
|
+
export async function spaceListingTick(o: { ends: SpaceEnd[]; media: Database | null; keep?: <R>(body: (db: Database) => R) => R; print: (l: string) => void; printErr: (l: string) => void; now?: () => number }): Promise<Record<string, string>> {
|
|
82
|
+
const now = o.now ?? Date.now
|
|
83
|
+
const keep = o.keep ?? machineDb
|
|
84
|
+
machineSet(TRIED_KEY, now())
|
|
85
|
+
machineSet(RUN_KEY, { pid: process.pid, at: now() })
|
|
86
|
+
const why: Record<string, string> = {}
|
|
87
|
+
try {
|
|
88
|
+
let space: Listed[] | null = null
|
|
89
|
+
for (const e of o.ends) {
|
|
90
|
+
const c = await e.config()
|
|
91
|
+
if ('why' in c) {
|
|
92
|
+
why[e.id] = c.why
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const l = await listOne(e.id, c, undefined, now)
|
|
97
|
+
if (e.id === 'space') {
|
|
98
|
+
l.record.vsIndex = againstIndex(l.rows, o.media, l.record.at)
|
|
99
|
+
space = l.rows
|
|
100
|
+
}
|
|
101
|
+
if (e.id === 'copy' && space != null) l.record.vsSpace = againstSpace(space, l.rows, e.skip ?? [])
|
|
102
|
+
const kept = keep((db) => keepListing(db, l.record, l.rows))
|
|
103
|
+
why[e.id] = ''
|
|
104
|
+
o.print(`ok: space listing ${e.id}: ${kept.objects} objects, ${(kept.bytes / 1e9).toFixed(2)} GB, ${kept.calls} calls in ${(kept.ms / 1000).toFixed(1)} s`)
|
|
105
|
+
} catch (x) {
|
|
106
|
+
why[e.id] = fail(x).why
|
|
107
|
+
o.printErr(`WARN space listing ${e.id}: ${why[e.id]}; the last listing is kept`)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} finally {
|
|
111
|
+
machineSet(WHY_KEY, why)
|
|
112
|
+
machineSet(RUN_KEY, null)
|
|
113
|
+
}
|
|
114
|
+
return why
|
|
115
|
+
}
|