rvlib-shipkit 2.25.0 → 2.27.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 +33 -0
- package/package.json +2 -2
- package/src/agent-time/diet.ts +77 -0
- package/src/agent-time/family.ts +72 -0
- package/src/agent-time/hooks.ts +331 -0
- package/src/agent-time/limits.ts +44 -0
- package/src/agent-time/live.ts +1 -3
- package/src/agent-time/mask.ts +96 -18
- package/src/agent-time/refused.ts +45 -0
- package/src/agent-time/render.ts +130 -17
- package/src/agent-time/report-cache.ts +57 -0
- package/src/agent-time/report.ts +349 -23
- package/src/agent-time/shape.ts +50 -3
- package/src/agent-time/store.ts +370 -95
- package/src/agent-time/timeline.ts +140 -21
- package/src/agent-time/turns.ts +18 -8
- package/src/annex/offload.ts +17 -6
- package/src/annex/tidy.ts +70 -10
- package/src/asks/ask-after.ts +40 -0
- package/src/asks/asks-queue.ts +205 -47
- package/src/assets/kit-config.ts +7 -3
- package/src/assets/kits/identity-kit.ts +289 -10
- package/src/check.ts +3 -1
- package/src/checks/SK004-gitignore-policy.check.ts +12 -5
- package/src/checks/SK013-one-way-in-policy.check.ts +8 -3
- package/src/checks/SK026-asks-autoclose.check.ts +5 -5
- 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/SK043-scratch-on-the-mac.check.ts +59 -4
- package/src/checks/SK045-slow-hooks.check.ts +47 -0
- package/src/checks/SK046-hook-records.check.ts +76 -0
- package/src/checks/SK047-login-in-description.check.ts +36 -0
- package/src/checks/SK048-one-local-file.check.ts +36 -0
- package/src/cli/cmd_Asks.ts +71 -5
- package/src/cli/cmd_Backup.ts +5 -3
- package/src/cli/cmd_Capacity.ts +2 -2
- 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_Machines.ts +36 -0
- package/src/cli/cmd_Media.ts +38 -6
- package/src/cli/cmd_Mv.ts +1 -1
- package/src/cli/cmd_Reflect.ts +23 -2
- package/src/cli/cmd_Releases.ts +30 -0
- package/src/cli/cmd_Review.ts +569 -118
- package/src/cli/cmd_Secret.ts +62 -12
- package/src/cli/cmd_Social.ts +83 -1
- package/src/cli/cmd_Space.ts +324 -0
- package/src/cli/cmd_Time.ts +82 -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/family-help.ts +4 -2
- package/src/cli/family-pages.ts +1 -1
- package/src/cli/registry.ts +26 -4
- package/src/collections/actions.ts +63 -13
- package/src/collections/collection-types.ts +23 -1
- package/src/collections/providers.ts +117 -23
- package/src/collections/review.ts +4 -4
- package/src/commands/runner.ts +5 -1
- 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/history-files.ts +9 -5
- package/src/core/layout.ts +3 -0
- package/src/core/machine-busy.ts +127 -0
- package/src/core/machine-commit.ts +6 -1
- package/src/core/machine-db.ts +368 -20
- package/src/core/machine-layout.ts +137 -0
- package/src/core/machine-read.ts +81 -0
- package/src/core/migrate-layout.ts +1 -1
- 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/signal-name.ts +6 -0
- package/src/core/slots.ts +5 -4
- package/src/core/trace-audit.ts +6 -1
- package/src/core/transient.ts +6 -0
- package/src/drill/clean.ts +25 -1
- package/src/drill/run.ts +2 -2
- package/src/drill/seal.ts +27 -4
- package/src/home/activity-shape.ts +2 -0
- package/src/home/activity.ts +66 -3
- package/src/home/app-sign.ts +15 -4
- package/src/home/daemon-jobs.ts +149 -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 +12 -3
- package/src/home/home-routes.ts +68 -0
- package/src/home/inbox-shape.ts +24 -14
- package/src/home/machine-fold.ts +820 -0
- package/src/home/machine-host.ts +20 -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/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 +175 -7
- 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 +482 -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 +17 -4
- 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 +348 -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 +99 -0
- package/src/hq/hq-local.ts +469 -0
- package/src/hq/hq-routes.ts +196 -0
- package/src/hq/hq-store.ts +599 -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 +372 -0
- package/src/hq/replica.ts +168 -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/identities/identities.ts +15 -3
- package/src/identities/steps.ts +31 -0
- package/src/ledger/db.ts +73 -26
- package/src/ledger/gate-checks.ts +29 -4
- package/src/ledger/git-key.ts +3 -3
- package/src/ledger/git-scan.ts +49 -7
- package/src/ledger/run-log.ts +11 -3
- package/src/ledger/store.ts +26 -4
- package/src/media-store/backup/daemon.ts +36 -17
- package/src/media-store/backup/kept.ts +241 -0
- package/src/media-store/backup/restore.ts +14 -4
- package/src/media-store/backup/run.ts +11 -11
- 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 +68 -20
- package/src/media-store/copy/config.ts +77 -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 +22 -11
- package/src/media-store/forget.ts +23 -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 +18 -15
- package/src/media-store/put.ts +24 -8
- package/src/media-store/remote.ts +16 -7
- package/src/media-store/space-listing.ts +240 -0
- package/src/media-store/space.ts +40 -21
- 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/model.ts +16 -7
- package/src/messages/routes.ts +14 -4
- package/src/messages/score.ts +2 -2
- package/src/messages/suggest.ts +96 -0
- package/src/pages/frame-client.ts +10 -0
- 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 +146 -36
- package/src/release/machine-words.ts +67 -0
- package/src/release/public-clean.ts +8 -3
- package/src/releases/from-card.ts +1 -1
- package/src/releases/model.ts +18 -0
- package/src/releases/routes.ts +10 -5
- package/src/releases/store.ts +23 -2
- package/src/repo-config.ts +42 -2
- package/src/review/anim.ts +2 -2
- package/src/review/auto.ts +2 -2
- package/src/review/card-db.ts +244 -0
- package/src/review/card-rows.ts +266 -0
- package/src/review/cells.ts +76 -5
- package/src/review/draft-card.ts +41 -0
- package/src/review/draft-model.ts +78 -0
- package/src/review/format.ts +29 -10
- package/src/review/gone.ts +98 -0
- package/src/review/inbox-hook.ts +35 -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 +214 -45
- package/src/review/move.ts +491 -0
- package/src/review/notes.ts +12 -20
- package/src/review/previews.ts +15 -19
- package/src/review/project.ts +1 -1
- package/src/review/rev.ts +8 -0
- package/src/review/role.ts +1 -1
- package/src/review/routes.ts +64 -13
- package/src/review/stage-card.ts +8 -4
- package/src/review/stage-routes.ts +1 -1
- package/src/review/store.ts +529 -83
- package/src/review/thread-fold.ts +51 -0
- package/src/review/threads.ts +147 -9
- package/src/review/trailer-auto-mock.ts +63 -0
- package/src/review/trailer-card.ts +4 -4
- 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 +6 -6
- package/src/review/watchers.ts +1 -1
- package/src/rules/untrack-generated.ts +92 -8
- package/src/secrets/held.ts +16 -0
- package/src/secrets/keychain.ts +113 -0
- package/src/secrets/list.ts +16 -6
- package/src/secrets/manager.ts +24 -10
- package/src/secrets/read.ts +257 -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 +48 -0
- package/src/serve/hub-app/asks-st.ts +25 -0
- package/src/serve/hub-app/clock-svc.ts +1 -2
- package/src/serve/hub-app/col-card.tsx +64 -13
- package/src/serve/hub-app/col-list-page.tsx +122 -0
- package/src/serve/hub-app/col-list-st.ts +103 -0
- package/src/serve/hub-app/col-tables-view.tsx +10 -41
- package/src/serve/hub-app/col-tables.ts +76 -8
- package/src/serve/hub-app/cols-svc.ts +70 -16
- 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/hash-route.ts +11 -1
- package/src/serve/hub-app/header-bar.tsx +14 -18
- package/src/serve/hub-app/home-st.ts +89 -9
- package/src/serve/hub-app/home-strip.css +5 -19
- package/src/serve/hub-app/home-strip.tsx +58 -92
- package/src/serve/hub-app/home.html +7 -0
- package/src/serve/hub-app/hub-app.tsx +31 -142
- package/src/serve/hub-app/hub-types.ts +3 -1
- package/src/serve/hub-app/hub.css +109 -23
- package/src/serve/hub-app/icons.tsx +18 -1
- package/src/serve/hub-app/identities-st.ts +56 -6
- package/src/serve/hub-app/identities-view.tsx +100 -58
- 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 +41 -24
- package/src/serve/hub-app/inbox-view.tsx +37 -41
- package/src/serve/hub-app/inbox.css +2 -5
- package/src/serve/hub-app/index.html +7 -0
- package/src/serve/hub-app/kept-cols.tsx +7 -0
- package/src/serve/hub-app/keys.ts +28 -15
- 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/machines-st.ts +251 -0
- package/src/serve/hub-app/machines-view.tsx +224 -0
- package/src/serve/hub-app/machines.css +76 -0
- package/src/serve/hub-app/md-copy.tsx +79 -0
- package/src/serve/hub-app/media-view.tsx +2 -0
- package/src/serve/hub-app/messages/messages-page.tsx +79 -7
- package/src/serve/hub-app/messages/messages-st.ts +99 -3
- package/src/serve/hub-app/messages.css +14 -0
- package/src/serve/hub-app/page-keys.ts +175 -0
- package/src/serve/hub-app/pages-frames.tsx +11 -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/project-list.css +54 -8
- package/src/serve/hub-app/project-list.tsx +128 -59
- package/src/serve/hub-app/projects-svc.ts +78 -7
- 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 +27 -5
- package/src/serve/hub-app/reflections-page.tsx +42 -0
- package/src/serve/hub-app/reflections-st.ts +17 -0
- package/src/serve/hub-app/releases/releases-page.tsx +25 -2
- package/src/serve/hub-app/releases/releases-st.ts +1 -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/draft-card.tsx +163 -0
- package/src/serve/hub-app/review/kit.tsx +50 -7
- package/src/serve/hub-app/review/note-place.ts +1 -1
- package/src/serve/hub-app/review/review-board.tsx +2 -2
- package/src/serve/hub-app/review/review-cells.tsx +145 -65
- package/src/serve/hub-app/review/review-kit.ts +27 -1
- package/src/serve/hub-app/review/review-list.tsx +68 -30
- package/src/serve/hub-app/review/review-page.tsx +7 -8
- package/src/serve/hub-app/review/review-st.ts +111 -24
- package/src/serve/hub-app/review/review-thread.tsx +49 -19
- package/src/serve/hub-app/review/review-views.tsx +475 -144
- 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 +73 -26
- package/src/serve/hub-app/review/trailer-card.tsx +1 -1
- 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.css +267 -61
- 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/comms-page.tsx +20 -5
- package/src/serve/hub-app/social/kit.tsx +30 -4
- package/src/serve/hub-app/social/post-card.tsx +139 -49
- package/src/serve/hub-app/social/serial-writes.ts +13 -0
- package/src/serve/hub-app/social/social-model.ts +11 -0
- package/src/serve/hub-app/social/social-page.tsx +94 -35
- package/src/serve/hub-app/social/social-st.ts +120 -36
- 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 +3 -0
- 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 +91 -23
- 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/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 +76 -0
- package/src/serve/hub-app/time.css +138 -0
- package/src/serve/hub-app/tree-build.ts +52 -42
- package/src/serve/hub-app/tree-row.tsx +4 -4
- 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-st.ts +12 -10
- package/src/serve/hub-app/waiting-svc.ts +29 -0
- package/src/serve/hub-app/wikis-view.tsx +2 -2
- package/src/serve/hub-runtime.ts +15 -2
- package/src/serve/project-gutter-route.ts +27 -14
- package/src/serve/project-gutter.ts +25 -12
- package/src/serve/same-origin.ts +10 -0
- package/src/serve/serve-hub.ts +13 -4
- package/src/shipkit-files.ts +16 -2
- package/src/shipkit.ts +1 -1
- package/src/shot/shooter.ts +616 -420
- package/src/shot/shot-ask.ts +246 -155
- package/src/site/desk.ts +2 -2
- package/src/smoke/run-smoke.ts +3 -2
- package/src/social/cover.ts +202 -0
- package/src/social/discord-layout.ts +37 -13
- package/src/social/drafts.ts +3 -0
- package/src/social/load.ts +23 -2
- package/src/social/media-kind.ts +2 -1
- package/src/social/publish/discord.ts +5 -2
- package/src/social/publish/secret.ts +2 -2
- package/src/social/release-stage.ts +28 -13
- package/src/social/routes.ts +26 -1
- package/src/social/stage.ts +1 -1
- package/src/social/stats.ts +12 -9
- package/src/social/strip.ts +4 -1
- package/src/social/thumbnail.ts +255 -0
- package/src/stores/collection.ts +15 -11
- package/src/stores/desk.ts +236 -42
- package/src/stores/model.ts +72 -6
- package/src/stores/routes.ts +37 -12
- package/src/stores/unit.ts +14 -8
- package/src/suite/judge-suites.ts +113 -16
- package/src/suite/select.ts +45 -3
- package/src/suite/suite-cli.ts +81 -34
- 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/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 +352 -0
- package/src/vault/vault-import.ts +208 -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/wiki/run-wiki.ts +2 -1
- package/src/wiki/scan-md.ts +42 -2
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// the one read of a secret on this machine, and its one write (wiki services/secrets): every reader of the lib and
|
|
2
|
+
// the house's command line tool come here. On the machine that runs the vault, the vault is the store: a name is read
|
|
3
|
+
// there first, and the keychain only when the vault does not hold it or does not answer, with one line on stderr
|
|
4
|
+
// that says so. Elsewhere the house's secret manager (`credsReadCommand`) as before. An env override answers before
|
|
5
|
+
// anything. A value never rides an argv, a log or an error
|
|
6
|
+
import { existsSync } from 'fs'
|
|
7
|
+
import { scopesAll, type Scope } from '../core/scope.ts'
|
|
8
|
+
import { KV_MOUNT, pathOf } from '../vault/layout.ts'
|
|
9
|
+
import { setInVault } from '../vault/vault-client.ts'
|
|
10
|
+
import { markerFile, refuseRealVault, vaultPlace, vaultUrl } from '../vault/vault-config.ts'
|
|
11
|
+
import { VaultApi, VaultError, vaultHealth } from '../vault/vault-http.ts'
|
|
12
|
+
import type { Held } from './held.ts'
|
|
13
|
+
import { keychainReader } from './keychain.ts'
|
|
14
|
+
import type { Presence } from './list.ts'
|
|
15
|
+
import { houseScopeOf, managerTemplate, readRefusal, secretsWhere, type SecretsWhere } from './manager.ts'
|
|
16
|
+
|
|
17
|
+
export type Field = 'get' | 'account'
|
|
18
|
+
export type Read = { value: string; from: 'env' | 'vault' | 'keychain' | 'manager' } | { refused: string } | { missing: string }
|
|
19
|
+
|
|
20
|
+
/** `rv/foo-bar/baz` → `RV_SECRET_FOO_BAR_BAZ`, `_ACCOUNT` after it for the account */
|
|
21
|
+
export const envVarOf = (name: string, field: Field = 'get'): string => `RV_SECRET_${name.replace(/^rv\//, '').toUpperCase().replace(/[^A-Z0-9]/g, '_')}${field === 'account' ? '_ACCOUNT' : ''}`
|
|
22
|
+
|
|
23
|
+
/** this machine runs the vault: its marker alone, no call */
|
|
24
|
+
export const vaultHere = (): boolean => {
|
|
25
|
+
const p = vaultPlace()
|
|
26
|
+
refuseRealVault({ place: p })
|
|
27
|
+
return existsSync(markerFile(p))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** a read waits this long for the vault, then reads the keychain with its line: a vault that holds a call forever
|
|
31
|
+
* must never hold every reader of the machine with it */
|
|
32
|
+
export const READ_BUDGET_MS = 1_500
|
|
33
|
+
/** a write's calls wait this long each, then the write says loudly what the vault holds */
|
|
34
|
+
export const WRITE_BUDGET_MS = 5_000
|
|
35
|
+
/** after a write that ran out of its budget, the wait before the one read back */
|
|
36
|
+
export const LATE_READ_MS = 2_000
|
|
37
|
+
/** after STRIKES reads in a row that ran out of their budget, the reads of this process skip the vault this long: a
|
|
38
|
+
* vault that holds every call costs a process two budgets, not one a read, and one slow answer costs nothing more
|
|
39
|
+
* (a healthy vault answers a read in under 2 ms, p99 0.7 ms measured at a load of 10). In the window a name the
|
|
40
|
+
* keychain lacks still asks the vault, and each keychain read says it may be stale */
|
|
41
|
+
export const SKIP_MS = 10_000
|
|
42
|
+
export const STRIKES = 2
|
|
43
|
+
let skipUntil = 0
|
|
44
|
+
let strikes = 0
|
|
45
|
+
|
|
46
|
+
let api: { token: string; vault: VaultApi } | null = null
|
|
47
|
+
/** the vault as this daemon's token reads it. The token is read from its file again when it changed (the vault job
|
|
48
|
+
* renews it each 12 h and the hq revokes the old one), so a process that lives long never keeps a dead token */
|
|
49
|
+
async function vaultApi(fresh = false): Promise<VaultApi | null> {
|
|
50
|
+
const { readVaultToken } = await import('../hq/hq-local.ts')
|
|
51
|
+
if (api != null && !fresh) return api.vault
|
|
52
|
+
const token = readVaultToken()
|
|
53
|
+
if (token == null) return (api = null)
|
|
54
|
+
if (api?.token !== token) api = { token, vault: new VaultApi(vaultUrl(vaultPlace()), token, READ_BUDGET_MS) }
|
|
55
|
+
return api.vault
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** where a registry name lives in the vault for the asker: one scope only. A repo row names the repo by its id, and
|
|
59
|
+
* the asker standing in that repo gives its key (the scope gate has let it in). Null with no place */
|
|
60
|
+
export function vaultPathFor(w: SecretsWhere, name: string): string | null {
|
|
61
|
+
if (w.house?.creds?.some((c) => c.name === name) !== true) return null
|
|
62
|
+
const s: Scope | undefined = houseScopeOf(w, name)
|
|
63
|
+
if (scopesAll(s)) return pathOf(name, undefined)
|
|
64
|
+
const n = (s!.repos?.length ?? 0) + (s!.identities?.length ?? 0) + (s!.machines?.length ?? 0)
|
|
65
|
+
if (n !== 1) return null
|
|
66
|
+
if (s!.repos?.length === 1) {
|
|
67
|
+
const r = s!.repos[0]!
|
|
68
|
+
if (r.includes('/')) return pathOf(name, { repos: [r] })
|
|
69
|
+
return w.repos.includes(r) && w.key != null ? pathOf(name, { repos: [w.key] }) : null
|
|
70
|
+
}
|
|
71
|
+
return pathOf(name, s)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** one name from the vault: a 403 reads the token file again and tries once more (a token renewed since); STRIKES
|
|
75
|
+
* calls in a row that run out of their budget make the next reads of this process skip the vault for SKIP_MS */
|
|
76
|
+
async function readVault(path: string, field: Field): Promise<{ value: string } | { why: string }> {
|
|
77
|
+
for (const fresh of [false, true]) {
|
|
78
|
+
const v = await vaultApi(fresh)
|
|
79
|
+
if (v == null) return { why: 'this daemon holds no vault token' }
|
|
80
|
+
try {
|
|
81
|
+
const held = await v.readKv(KV_MOUNT, path)
|
|
82
|
+
strikes = 0
|
|
83
|
+
skipUntil = 0
|
|
84
|
+
if (typeof held?.['value'] === 'string' && held['value'] !== '') return { value: field === 'account' ? String(held['account'] ?? '') : held['value'] }
|
|
85
|
+
return { why: 'the vault does not hold it' }
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (e instanceof VaultError && e.status === 403 && !fresh) continue
|
|
88
|
+
if ((e as Error).name === 'TimeoutError' || /timed out/i.test((e as Error).message)) {
|
|
89
|
+
strikes++
|
|
90
|
+
if (strikes < STRIKES) return { why: `the vault did not answer within ${READ_BUDGET_MS} ms` }
|
|
91
|
+
skipUntil = Date.now() + SKIP_MS
|
|
92
|
+
return { why: `the vault did not answer within ${READ_BUDGET_MS} ms, ${strikes} times in a row; this process reads the keychain for ${SKIP_MS / 1000} s` }
|
|
93
|
+
}
|
|
94
|
+
const h = await vaultHealth(vaultUrl(vaultPlace()), 500)
|
|
95
|
+
return { why: h == null ? 'the vault does not answer' : h.sealed ? 'the vault is sealed' : `the vault refused the read (${(e as Error).message.replace(/^.*: (\d{3}).*$/, '$1')})` }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { why: 'the vault refused this daemon\'s token twice' }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** the keychain's copy, read exact; null when it holds none */
|
|
102
|
+
function fromKeychain(name: string, field: Field): string | null {
|
|
103
|
+
const r = keychainReader().read(name)
|
|
104
|
+
if (r == null) return null
|
|
105
|
+
if (!r.ok) throw new Error(`${name}: the keychain's copy is not read: ${r.why}`)
|
|
106
|
+
return field === 'account' ? r.account : r.value
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** the template's read, as before the vault: its argv, the value on its stdout */
|
|
110
|
+
function fromManager(template: string, name: string, field: Field, cwd: string): Read {
|
|
111
|
+
const argv = template.trim().split(/\s+/).map((x) => x.replaceAll('{name}', name).replaceAll('{field}', field))
|
|
112
|
+
if (argv[0] == null || Bun.which(argv[0]) == null) return { missing: `credsReadCommand names '${argv[0] ?? ''}', which is not on PATH` }
|
|
113
|
+
const r = Bun.spawnSync(argv, { cwd, stdin: 'ignore', stderr: 'pipe', env: { ...process.env, SHIPKIT_SECRET_KEYCHAIN_ONLY: 'lib' } })
|
|
114
|
+
const v = r.stdout.toString().trim()
|
|
115
|
+
if (r.exitCode === 0 && v !== '') return { value: v, from: 'manager' }
|
|
116
|
+
const why = r.stderr.toString().trim().split('\n').at(-1) ?? ''
|
|
117
|
+
return why.startsWith('REFUSED') ? { refused: why } : { missing: `\`${argv.join(' ')}\` answered nothing — store the secret under that name first${why !== '' ? ` (${why})` : ''}` }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** a name read for the repo at `cwd`. `say` gets the one line of a read that falls back to the keychain */
|
|
121
|
+
export async function readSecretHere(o: { name: string; field?: Field; cwd: string; say?: (l: string) => void; w?: SecretsWhere; template?: string }): Promise<Read> {
|
|
122
|
+
const field = o.field ?? 'get'
|
|
123
|
+
const env = process.env[envVarOf(o.name, field)]
|
|
124
|
+
if (env != null && env !== '') return { value: env, from: 'env' }
|
|
125
|
+
const w = o.w ?? (await secretsWhere(o.cwd))
|
|
126
|
+
const refused = readRefusal(o.name, houseScopeOf(w, o.name), w)
|
|
127
|
+
if (refused != null) return { refused }
|
|
128
|
+
const say = o.say ?? ((l: string) => void process.stderr.write(`${l}\n`))
|
|
129
|
+
const only = process.env['SHIPKIT_SECRET_KEYCHAIN_ONLY']
|
|
130
|
+
if (only === '1' && vaultHere()) say(`note: SHIPKIT_SECRET_KEYCHAIN_ONLY=1 sends ${o.name} past the vault to this Mac's keychain: the owner's undo switch, never an agent's. It may be stale`)
|
|
131
|
+
if (only !== '1' && only !== 'lib' && vaultHere()) {
|
|
132
|
+
const path = vaultPathFor(w, o.name)
|
|
133
|
+
let why = path == null ? 'the vault has no place for this name (no registry row of one scope)' : ''
|
|
134
|
+
const skipping = path != null && Date.now() < skipUntil
|
|
135
|
+
if (skipping) why = `the vault did not answer within ${READ_BUDGET_MS} ms ${STRIKES} times a moment ago, it is tried again in ${Math.ceil((skipUntil - Date.now()) / 1000)} s`
|
|
136
|
+
else if (path != null) {
|
|
137
|
+
const got = await readVault(path, field)
|
|
138
|
+
if ('value' in got) return { value: got.value, from: 'vault' }
|
|
139
|
+
why = got.why
|
|
140
|
+
}
|
|
141
|
+
let k = fromKeychain(o.name, field)
|
|
142
|
+
if ((k == null || k === '') && skipping && path != null) {
|
|
143
|
+
const got = await readVault(path, field)
|
|
144
|
+
if ('value' in got) return { value: got.value, from: 'vault' }
|
|
145
|
+
why = got.why
|
|
146
|
+
k = null
|
|
147
|
+
}
|
|
148
|
+
if (k == null || k === '') return { missing: `${o.name}: neither the vault nor the keychain holds it (${why}): store it with sk secret set ${o.name}` }
|
|
149
|
+
say(`note: ${o.name} comes from this Mac's keychain, not the vault: ${why}. It may be stale`)
|
|
150
|
+
return { value: k, from: 'keychain' }
|
|
151
|
+
}
|
|
152
|
+
return fromManager(o.template ?? managerTemplate(w, 'credsReadCommand'), o.name, field, o.cwd)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** whether the store holds each name, and since when: never a value. On the machine that runs the vault, the vault's
|
|
156
|
+
* metadata of its path (its current version's day); a name it lacks, and every name elsewhere, by presence only
|
|
157
|
+
* (list.ts, the read this machine makes), stored with no day. A name out of the asker's scope is unknown. `vault`
|
|
158
|
+
* and `presence` are the reads a test passes */
|
|
159
|
+
export async function heldHere(o: { names: readonly string[]; cwd: string; w?: SecretsWhere; vault?: Pick<VaultApi, 'writtenAt'> | null; presence?: (names: string[]) => Promise<Map<string, Presence>> }): Promise<Record<string, Held>> {
|
|
160
|
+
const w = o.w ?? (await secretsWhere(o.cwd))
|
|
161
|
+
const out: Record<string, Held> = {}
|
|
162
|
+
const rest: string[] = []
|
|
163
|
+
const vault = o.vault !== undefined ? o.vault : vaultHere() ? await vaultApi() : null
|
|
164
|
+
await Promise.all(o.names.map(async (name) => {
|
|
165
|
+
const refused = readRefusal(name, houseScopeOf(w, name), w)
|
|
166
|
+
if (refused != null) return void (out[name] = { held: 'unknown', why: refused })
|
|
167
|
+
const path = vault == null ? null : vaultPathFor(w, name)
|
|
168
|
+
const meta = path == null ? null : await vault!.writtenAt(KV_MOUNT, path).catch(() => null)
|
|
169
|
+
if (meta != null) out[name] = { held: 'stored', at: meta.at }
|
|
170
|
+
else rest.push(name)
|
|
171
|
+
}))
|
|
172
|
+
if (rest.length === 0) return out
|
|
173
|
+
let present: Map<string, Presence>
|
|
174
|
+
try {
|
|
175
|
+
present = o.presence != null ? await o.presence(rest) : await (await import('./list.ts')).presence(managerTemplate(w, 'credsReadCommand'), rest, o.cwd)
|
|
176
|
+
} catch (e) {
|
|
177
|
+
for (const n of rest) out[n] = { held: 'unknown', why: (e as Error).message }
|
|
178
|
+
return out
|
|
179
|
+
}
|
|
180
|
+
for (const n of rest) {
|
|
181
|
+
const p = present.get(n)
|
|
182
|
+
out[n] = p === 'ok' || p === 'locked' ? { held: 'stored', at: null } : { held: 'missing' }
|
|
183
|
+
}
|
|
184
|
+
return out
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** a name read, or the error a reader throws: the one form every reader of the lib calls */
|
|
188
|
+
export async function readSecretValue(name: string, field: Field = 'get', cwd: string = process.cwd()): Promise<string> {
|
|
189
|
+
const r = await readSecretHere({ name, field, cwd })
|
|
190
|
+
if ('value' in r) return r.value
|
|
191
|
+
throw new Error('refused' in r ? `FAIL ${r.refused}` : `FAIL ${r.missing}`)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** a name removed on the machine that runs the vault: its newest version soft deleted in the vault (undone with
|
|
195
|
+
* `bao kv undelete`), then checked gone. `older`: the versions before it, which stay readable by version: a node
|
|
196
|
+
* token may never destroy (vault/policy.ts, nothing a node does is final), so the line says so. Elsewhere null.
|
|
197
|
+
* The caller removes the keychain's copy as well, else the read falls back to it */
|
|
198
|
+
export async function removeSecretHere(o: { name: string; cwd: string; w?: SecretsWhere }): Promise<{ removed: boolean; older: number } | { refused: string } | null> {
|
|
199
|
+
if (!vaultHere()) return null
|
|
200
|
+
const w = o.w ?? (await secretsWhere(o.cwd))
|
|
201
|
+
const path = vaultPathFor(w, o.name)
|
|
202
|
+
if (path == null) return { refused: `${o.name} has no place in the vault: it needs a registry row of one scope, and for a repo row this command run inside that repo` }
|
|
203
|
+
const { readVaultToken } = await import('../hq/hq-local.ts')
|
|
204
|
+
const token = readVaultToken()
|
|
205
|
+
if (token == null) return { refused: 'this daemon holds no vault token yet: sk pm restart daemon, then sk vault status' }
|
|
206
|
+
const v = new VaultApi(vaultUrl(vaultPlace()), token)
|
|
207
|
+
const older = Math.max(0, (await v.currentVersion(KV_MOUNT, path)) - 1)
|
|
208
|
+
if ((await v.readKv(KV_MOUNT, path)) == null) return { removed: false, older }
|
|
209
|
+
await v.deleteKv(KV_MOUNT, path)
|
|
210
|
+
if ((await v.readKv(KV_MOUNT, path)) != null) return { refused: 'the vault still answers it after the delete' }
|
|
211
|
+
return { removed: true, older }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** a name written on the machine that runs the vault: into the vault, read back. Elsewhere null: the caller writes
|
|
215
|
+
* through the house's secret manager */
|
|
216
|
+
export async function writeSecretHere(o: { name: string; account: string; value: string; cwd: string; w?: SecretsWhere }): Promise<{ version: number } | { refused: string } | null> {
|
|
217
|
+
if (!vaultHere()) return null
|
|
218
|
+
const w = o.w ?? (await secretsWhere(o.cwd))
|
|
219
|
+
const path = vaultPathFor(w, o.name)
|
|
220
|
+
if (path == null) return { refused: `${o.name} has no place in the vault: it needs a registry row of one scope, and for a repo row this command run inside that repo` }
|
|
221
|
+
const h = await vaultHealth(vaultUrl(vaultPlace()))
|
|
222
|
+
if (h == null) return { refused: 'the vault does not answer: start it (sk gp start vault), then sk vault status' }
|
|
223
|
+
if (h.sealed) return { refused: 'the vault is sealed: restart it (sk gp restart vault), then sk vault status' }
|
|
224
|
+
const { readVaultToken } = await import('../hq/hq-local.ts')
|
|
225
|
+
const token = readVaultToken()
|
|
226
|
+
if (token == null) return { refused: 'this daemon holds no vault token yet: sk pm restart daemon, then sk vault status' }
|
|
227
|
+
const vault = new VaultApi(vaultUrl(vaultPlace()), token, WRITE_BUDGET_MS)
|
|
228
|
+
const before = await vault.currentVersion(KV_MOUNT, path).catch((e: Error) => e)
|
|
229
|
+
const late = (e: Error): boolean => e.name === 'TimeoutError' || /timed out/i.test(e.message)
|
|
230
|
+
if (before instanceof Error) {
|
|
231
|
+
if (late(before)) return { refused: `the vault answers its health but did not answer a read of ${o.name} within ${WRITE_BUDGET_MS / 1000} s: nothing was stored, the keychain is not written` }
|
|
232
|
+
throw before
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const version = await setInVault({ vault, path, account: o.account, value: o.value })
|
|
236
|
+
strikes = 0
|
|
237
|
+
skipUntil = 0
|
|
238
|
+
return { version }
|
|
239
|
+
} catch (e) {
|
|
240
|
+
if (!late(e as Error)) throw e
|
|
241
|
+
// a client that gave up cannot know whether the vault takes the write later: one read back after a short wait
|
|
242
|
+
// says what it holds now, and the answer is a refusal either way, so no caller takes a doubt for a success
|
|
243
|
+
await Bun.sleep(LATE_READ_MS)
|
|
244
|
+
const now = await new VaultApi(vaultUrl(vaultPlace()), token, READ_BUDGET_MS).readKv(KV_MOUNT, path).then((h) => ({ held: h }), () => null)
|
|
245
|
+
const head = `the vault did not answer the write of ${o.name} within ${WRITE_BUDGET_MS / 1000} s`
|
|
246
|
+
if (now != null && now.held?.['value'] === o.value) return { refused: `${head}; read back ${LATE_READ_MS / 1000} s later, it holds the new value: stored late. The keychain is not written` }
|
|
247
|
+
return { refused: `${head}: the value MAY have been stored, or may still land; read it back with sk secret get ${o.name} in a few seconds${now == null ? ' (a read back did not answer either)' : ', the vault still held the value before it'}, and set it again if it did not take. The keychain is not written` }
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** the read every reader of the lib makes, `template` the manager it would have run: the value, or a FAIL line it
|
|
252
|
+
* throws (a refusal kept as REFUSED, a missing name with how to store it) */
|
|
253
|
+
export async function readThrough(template: string, name: string, field: Field = 'get', cwd: string = process.cwd()): Promise<string> {
|
|
254
|
+
const r = await readSecretHere({ name, field, cwd, template })
|
|
255
|
+
if ('value' in r) return r.value
|
|
256
|
+
throw new Error('refused' in r ? `FAIL ${r.refused}` : `FAIL ${r.missing}`)
|
|
257
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// who will be able to read a secret, said in words before its value is pasted: the name's registry row in the house
|
|
2
|
+
// (a name with no row is every repo's), worded by core/scope.ts scopeWords over the house's repos and identities.
|
|
3
|
+
// Names and scopes only, never a value. The one function every page that lists a secret for the owner calls
|
|
4
|
+
import { isRepoKey, scopeChips, scopesAll, scopeShort, scopeWords, type Scope, type ScopeChip, type ScopeHouse } from '../core/scope.ts'
|
|
5
|
+
import { houseRootOf } from '../home/home-start.ts'
|
|
6
|
+
import { loadIdentities, speakerOf } from '../identities/identities.ts'
|
|
7
|
+
import { loadRepoConfig, type RepoConfig } from '../repo-config.ts'
|
|
8
|
+
|
|
9
|
+
/** `registered`: the house's registry has a row for the name; without one every repo reads it. `words`: the long
|
|
10
|
+
* form, a sentence (a file, a hover); `short`: the console's cell; `chips`: what the hub draws */
|
|
11
|
+
export type WhoReads = { name: string; registered: boolean; scope: Scope | undefined; words: string; short: string; chips: ScopeChip[] }
|
|
12
|
+
|
|
13
|
+
type Row = Pick<NonNullable<RepoConfig['creds']>[number], 'name' | 'for'>
|
|
14
|
+
|
|
15
|
+
/** one name against the registry's rows and the house */
|
|
16
|
+
export function whoReadsIn(name: string, rows: readonly Row[] | undefined, house: ScopeHouse): WhoReads {
|
|
17
|
+
const row = rows?.find((r) => r.name === name)
|
|
18
|
+
if (row == null) return { name, registered: false, scope: undefined, words: `no registry row yet, so ${scopeWords(undefined, house)}`, short: scopeShort(undefined, house), chips: scopeChips(undefined, house) }
|
|
19
|
+
return { name, registered: true, scope: row.for, words: scopeWords(row.for, house), short: scopeShort(row.for, house), chips: scopeChips(row.for, house) }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** the house's repos with the identity each speaks as (its `speaksAs`, else the default one), and their keys when
|
|
23
|
+
* a scope names a repo by its key */
|
|
24
|
+
export async function scopeHouse(cwd: string, o: { keys?: boolean } = {}): Promise<ScopeHouse> {
|
|
25
|
+
const [{ houseRepoRoots }, ids] = await Promise.all([import('../social/house.ts'), loadIdentities({ cwd })])
|
|
26
|
+
const roots = await houseRepoRoots(cwd)
|
|
27
|
+
const keyOf = o.keys === true ? (await import('../hq/report.ts')).repoKey : null
|
|
28
|
+
const repos = await Promise.all(roots.map(async (r) => ({ name: r.name, key: keyOf == null ? null : ((await keyOf(r.path).catch(() => null)) ?? null), speaksAs: speakerOf(r.speaksAs, ids)?.id ?? null })))
|
|
29
|
+
return { repos, identities: ids.identities.map((i) => ({ id: i.id, name: i.name })) }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const KEEP_MS = 60_000
|
|
33
|
+
const kept = new Map<string, { at: number; house: ScopeHouse; rows: Row[] }>()
|
|
34
|
+
|
|
35
|
+
/** who reads each name, for the repo at `cwd`'s house; none outside a house, where no registry says. The house is
|
|
36
|
+
* read once a minute at most: the hub asks on every poll */
|
|
37
|
+
export async function whoReads(names: readonly string[], cwd: string): Promise<Record<string, WhoReads>> {
|
|
38
|
+
const root = houseRootOf(cwd)
|
|
39
|
+
if (names.length === 0 || root == null) return {}
|
|
40
|
+
let k = kept.get(root)
|
|
41
|
+
if (k == null || Date.now() - k.at > KEEP_MS) {
|
|
42
|
+
const config = await loadRepoConfig(root).catch(() => null)
|
|
43
|
+
const rows = config?.creds ?? []
|
|
44
|
+
const keys = rows.some((r) => !scopesAll(r.for) && (r.for?.repos ?? []).some(isRepoKey))
|
|
45
|
+
k = { at: Date.now(), house: await scopeHouse(cwd, { keys }), rows }
|
|
46
|
+
kept.set(root, k)
|
|
47
|
+
}
|
|
48
|
+
return Object.fromEntries(names.map((n) => [n, whoReadsIn(n, k!.rows, k!.house)]))
|
|
49
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// the door to a machine's dev url (wiki tools/shipkit/hq.md, The door): the address a process gets on the hq's home
|
|
2
|
+
// (`<process>.<machine>.localhost`, an origin of its own), what crosses each hop and what never does. The same hop
|
|
3
|
+
// frames a declared url behind http basic auth at `<url id>--<repo>.localhost`, its login added on the server
|
|
4
|
+
// (wiki tools/shipkit/urls.md). Light on purpose: the web imports it. The one constraint a reader breaks first: the
|
|
5
|
+
// target's origin always comes from a lookup (hq/door.ts, urls/frame.ts), never from the request; the request gives a
|
|
6
|
+
// path and names, never an address
|
|
7
|
+
import { DNS_LABEL, doorOrigin, loopbackOrigin, machineLabel, urlFrameLabel, urlFrameOrigin } from './door-names.ts'
|
|
8
|
+
import { createHmac } from 'crypto'
|
|
9
|
+
import { readFileSync } from 'fs'
|
|
10
|
+
import { join } from 'path'
|
|
11
|
+
import { homeDir } from '../home/home-paths.ts'
|
|
12
|
+
|
|
13
|
+
/** a node's door key: only the hq can make it, and it opens that node's door alone */
|
|
14
|
+
export const doorKeyOf = (s: Buffer, node: string): string => createHmac('sha256', s).update(`door:${node}`).digest('base64url')
|
|
15
|
+
|
|
16
|
+
/** the key the hq's web shows another machine's door, made here from the hq's secret file: no route of the daemon
|
|
17
|
+
* ever answers a key. Null while the file is not made (the proxy never turned on) */
|
|
18
|
+
export function doorKeyFor(node: string): string | null {
|
|
19
|
+
try {
|
|
20
|
+
const held = readFileSync(join(homeDir(), 'hq-door-secret'), 'utf8').trim()
|
|
21
|
+
return held.length >= 43 ? doorKeyOf(Buffer.from(held, 'base64url'), node) : null
|
|
22
|
+
} catch {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** the header a hop carries the door key in, from the hq's web to the door of a machine's web */
|
|
28
|
+
export const DOOR_KEY_HEADER = 'x-shipkit-door'
|
|
29
|
+
/** the path of a machine's own door on its web: `/door/<process id>/<rest>` */
|
|
30
|
+
export const DOOR_PATH = '/door/'
|
|
31
|
+
|
|
32
|
+
/** the content policy of every answer under a door name: a page there talks to its own origin and nothing else.
|
|
33
|
+
* `*.localhost` is an origin the hq machine's own dev servers trust (vite's default cors), so without it a page of
|
|
34
|
+
* another machine would read their files. Its own hot reload socket is named, since `'self'` covers ws in some
|
|
35
|
+
* browsers only. `webrtc 'block'` is the spec's (CSP 3) against a TURN connection to any port; Chromium ignores it
|
|
36
|
+
* today, so that blind write stays open there. `host` is the door's own, with its port */
|
|
37
|
+
export const doorPolicy = (host: string): string => `default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:; connect-src 'self' ws://${host.replace(/[^a-z0-9.:-]/g, '')}; form-action 'self'; base-uri 'self'; webrtc 'block'`
|
|
38
|
+
|
|
39
|
+
const LABEL = DNS_LABEL
|
|
40
|
+
const PROCESS_ID = /^[a-z][a-z0-9-]*$/
|
|
41
|
+
|
|
42
|
+
/** the process and machine a Host names, `<process>.<machine>.localhost[:port]`; null for any other name */
|
|
43
|
+
export function doorHostOf(host: string | null): { process: string; machine: string } | null {
|
|
44
|
+
if (host == null) return null
|
|
45
|
+
const name = host.trim().toLowerCase().replace(/:\d+$/, '').replace(/\.$/, '')
|
|
46
|
+
const parts = name.split('.')
|
|
47
|
+
if (parts.length !== 3 || parts[2] !== 'localhost') return null
|
|
48
|
+
const [process, machine] = parts as [string, string]
|
|
49
|
+
return LABEL.test(process) && PROCESS_ID.test(process) && LABEL.test(machine) ? { process, machine } : null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { doorOrigin, loopbackOrigin, machineLabel, urlFrameOrigin }
|
|
53
|
+
|
|
54
|
+
/** the declared url a Host names, `<url id>--<repo>.localhost[:port]` (urlFrameLabel); null for any other name */
|
|
55
|
+
export function urlHostOf(host: string | null): { id: string; repo: string } | null {
|
|
56
|
+
if (host == null) return null
|
|
57
|
+
const parts = host.trim().toLowerCase().replace(/:\d+$/, '').replace(/\.$/, '').split('.')
|
|
58
|
+
if (parts.length !== 2 || parts[1] !== 'localhost') return null
|
|
59
|
+
const label = parts[0]!
|
|
60
|
+
const cut = label.lastIndexOf('--')
|
|
61
|
+
if (cut < 1) return null
|
|
62
|
+
const id = label.slice(0, cut)
|
|
63
|
+
const repo = label.slice(cut + 2)
|
|
64
|
+
return urlFrameLabel(id, repo) === label && machineLabel(repo) === repo ? { id, repo } : null
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** the hub page's own origins on a port: the three loopback names the home's page is opened by on this Mac */
|
|
68
|
+
export const hubOrigins = (port: string): string[] => [`http://localhost:${port}`, `http://127.0.0.1:${port}`, `http://[::1]:${port}`]
|
|
69
|
+
|
|
70
|
+
const portOf = (host: string): string => /:(\d+)$/.exec(host)?.[1] ?? '80'
|
|
71
|
+
|
|
72
|
+
/** the content policy of every answer under a url's name: the site keeps the web over https and its own origin, never
|
|
73
|
+
* a plain http server of this Mac (they trust `*.localhost`), and only the hub's own page may render it */
|
|
74
|
+
export function urlPolicy(host: string): string {
|
|
75
|
+
const h = host.replace(/[^a-z0-9.:-]/g, '')
|
|
76
|
+
return `default-src 'self' https: 'unsafe-inline' 'unsafe-eval' data: blob:; connect-src 'self' https: wss: ws://${h}; form-action 'self' https:; base-uri 'self'; frame-ancestors ${hubOrigins(portOf(h)).join(' ')}; webrtc 'block'`
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** why a request of another site never crosses a url's hop, which may add a login: the one that passes is the frame
|
|
80
|
+
* the hub's own page opens, told by its `Referer` (a page of another site cannot send one of the hub's origins; a
|
|
81
|
+
* frame without one is refused). `frame-ancestors` holds the render only, so the request is held here. Null when it may */
|
|
82
|
+
export function crossSiteRefusal(req: Request): string | null {
|
|
83
|
+
const site = req.headers.get('sec-fetch-site')
|
|
84
|
+
if (site == null || site === 'same-origin' || site === 'none') return null
|
|
85
|
+
if (req.headers.get('sec-fetch-mode') === 'navigate' && req.headers.get('sec-fetch-dest') === 'iframe') {
|
|
86
|
+
let from: string | null = null
|
|
87
|
+
try {
|
|
88
|
+
from = new URL(req.headers.get('referer') ?? '').origin
|
|
89
|
+
} catch {
|
|
90
|
+
// no referer, or not a url
|
|
91
|
+
}
|
|
92
|
+
if (from != null && hubOrigins(portOf(req.headers.get('host') ?? '')).includes(from)) return null
|
|
93
|
+
return "refused: a url's frame opens from the hub's own page only, never from another site's"
|
|
94
|
+
}
|
|
95
|
+
return `refused: a ${site} request does not reach a url framed through the hub, only its own page and the hub's frame do`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** the guard of every login a hop sends: `url` is on the declared origin `target`, over https or this Mac's loopback,
|
|
99
|
+
* with no user part. The one test a request passes before it carries a login */
|
|
100
|
+
export function loginHop(url: string, target: string): boolean {
|
|
101
|
+
let u: URL
|
|
102
|
+
let t: URL
|
|
103
|
+
try {
|
|
104
|
+
u = new URL(url)
|
|
105
|
+
t = new URL(target)
|
|
106
|
+
} catch {
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
const scheme = u.protocol === 'wss:' ? 'https:' : u.protocol === 'ws:' ? 'http:' : u.protocol
|
|
110
|
+
if (u.username !== '' || u.password !== '' || scheme !== t.protocol || u.host !== t.host) return false
|
|
111
|
+
return t.protocol === 'https:' || loopbackOrigin(t.origin) != null
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** whether an answer asks for an http basic login */
|
|
115
|
+
export const basicChallenge = (r: Response): boolean => r.status === 401 && /(^|,)\s*basic(\s|$|,)/i.test(r.headers.get('www-authenticate') ?? '')
|
|
116
|
+
|
|
117
|
+
/** a door's `/door/<id>/<rest>` path read: the process id and the rest, which starts with `/`; null for another path */
|
|
118
|
+
export function doorPathOf(path: string): { id: string; rest: string } | null {
|
|
119
|
+
const m = /^\/door\/([a-z][a-z0-9-]*)(\/.*)?$/.exec(path)
|
|
120
|
+
return m == null ? null : { id: m[1]!, rest: m[2] ?? '/' }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** what never crosses a hop: this hop's own headers, a credential, where the request came from, shipkit's own */
|
|
124
|
+
const DROP = new Set(['host', 'origin', 'referer', 'cookie', 'authorization', 'proxy-authorization', 'connection', 'keep-alive', 'content-length', 'transfer-encoding', 'upgrade', 'te', 'trailer', 'forwarded', 'x-real-ip', 'proxy-connection'])
|
|
125
|
+
const DROP_PREFIX = ['x-forwarded-', 'tailscale-', 'x-shipkit-', 'sec-websocket-']
|
|
126
|
+
|
|
127
|
+
/** what a site's own page sends it through its hop, which the door drops: its cookies and its own authorization */
|
|
128
|
+
const SITE_KEEPS = new Set(['cookie', 'authorization'])
|
|
129
|
+
|
|
130
|
+
const dropped = (k: string, site: boolean): boolean => (DROP.has(k) && !(site && SITE_KEEPS.has(k))) || DROP_PREFIX.some((p) => k.startsWith(p))
|
|
131
|
+
|
|
132
|
+
/** whether a proxy brought the request: tailscale serve writes `x-forwarded-for` (Go's reverse proxy does by default)
|
|
133
|
+
* and the caller's identity (`tailscale-user-*`, its own documentation), any proxy writes one of the others. A
|
|
134
|
+
* browser never reaches a door name through it anyway: it sends the tailnet name as its Host. What is left is a
|
|
135
|
+
* client that forges its Host from a tagged device through a proxy that writes none of these */
|
|
136
|
+
export function broughtByProxy(req: Request): boolean {
|
|
137
|
+
for (const k of ['x-forwarded-for', 'x-forwarded-proto', 'x-forwarded-host', 'x-forwarded-port', 'forwarded', 'x-real-ip', 'via']) if (req.headers.has(k)) return true
|
|
138
|
+
let tailscale = false
|
|
139
|
+
req.headers.forEach((_v, k) => {
|
|
140
|
+
if (k.startsWith('tailscale-')) tailscale = true
|
|
141
|
+
})
|
|
142
|
+
return tailscale
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** why a request must not cross: it names another site as its origin. Null when it may */
|
|
146
|
+
export function foreignOrigin(req: Request, own: string): string | null {
|
|
147
|
+
const origin = req.headers.get('origin')
|
|
148
|
+
if (origin == null || origin === own) return null
|
|
149
|
+
return `refused: a request from ${origin.slice(0, 80)} does not reach a process through the door, only one of its own page`
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** the headers a hop sends on: the browser's minus DROP, `Origin` the process's own when the browser named the door's.
|
|
153
|
+
* `key`: the door key, for the hop to a machine's door. `site`: the hop of a url framed with its login */
|
|
154
|
+
export function hopHeaders(req: Request, target: string, key: string | null = null, site = false): Headers {
|
|
155
|
+
const out = new Headers()
|
|
156
|
+
req.headers.forEach((v, k) => {
|
|
157
|
+
if (!dropped(k, site)) out.set(k, v)
|
|
158
|
+
})
|
|
159
|
+
if (req.headers.has('origin')) out.set('origin', target)
|
|
160
|
+
if (key != null) out.set(DOOR_KEY_HEADER, key)
|
|
161
|
+
return out
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** what makes a browser post a report wherever the process says: a write to any port of the hq's Mac */
|
|
165
|
+
const REPORT_HEADERS = ['content-security-policy-report-only', 'report-to', 'reporting-endpoints', 'nel']
|
|
166
|
+
|
|
167
|
+
/** a process's own policies, each without its report directives: the browser still applies them, and reports nowhere.
|
|
168
|
+
* `frames`: without `frame-ancestors` too, for the hop of a url the hub frames */
|
|
169
|
+
export function withoutReports(csp: string, frames = false): string {
|
|
170
|
+
const gone = frames ? /^(report-(uri|to)|frame-ancestors)(\s|$)/i : /^report-(uri|to)(\s|$)/i
|
|
171
|
+
return csp
|
|
172
|
+
.split(',')
|
|
173
|
+
.map((policy) => policy.split(';').map((d) => d.trim()).filter((d) => d !== '' && !gone.test(d)).join('; '))
|
|
174
|
+
.filter((p) => p !== '')
|
|
175
|
+
.join(', ')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** a site's cookie as it lands on its hop's name: no domain (the name alone holds it), partitioned under the hub's
|
|
179
|
+
* page, `Secure` (a `*.localhost` name is a secure context) so the browser keeps it inside the hub's frame */
|
|
180
|
+
export function hopCookie(c: string): string {
|
|
181
|
+
const [pair = '', ...attrs] = c.split(';')
|
|
182
|
+
const kept = attrs.map((a) => a.trim()).filter((a) => a !== '' && !/^(domain|secure|samesite|partitioned)(\s*=|$)/i.test(a))
|
|
183
|
+
return [pair.trim(), ...kept, 'Secure', 'SameSite=None', 'Partitioned'].join('; ')
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** the headers back: a cookie never lands (another process would read it under the home's names), a service worker
|
|
187
|
+
* never widens its scope, a redirect to the process's own origin stays behind the door. `site`: the hop of a url
|
|
188
|
+
* the hub frames, whose cookies land on its own name and whose frame refusals are dropped */
|
|
189
|
+
export function backHeaders(r: Response, target: string, own: string | null, site = false): Headers {
|
|
190
|
+
const out = new Headers(r.headers)
|
|
191
|
+
for (const k of ['set-cookie', 'service-worker-allowed', 'content-length', 'transfer-encoding', 'connection', 'keep-alive', ...REPORT_HEADERS]) out.delete(k)
|
|
192
|
+
if (site) {
|
|
193
|
+
out.delete('x-frame-options')
|
|
194
|
+
for (const c of r.headers.getSetCookie()) out.append('set-cookie', hopCookie(c))
|
|
195
|
+
}
|
|
196
|
+
const csp = out.get('content-security-policy')
|
|
197
|
+
if (csp != null) {
|
|
198
|
+
const kept = withoutReports(csp, site)
|
|
199
|
+
if (kept === '') out.delete('content-security-policy')
|
|
200
|
+
else out.set('content-security-policy', kept)
|
|
201
|
+
}
|
|
202
|
+
const loc = out.get('location')
|
|
203
|
+
if (own != null && loc != null) {
|
|
204
|
+
try {
|
|
205
|
+
const u = new URL(loc)
|
|
206
|
+
if (u.origin === target) out.set('location', `${own}${u.pathname}${u.search}${u.hash}`)
|
|
207
|
+
} catch {
|
|
208
|
+
// a path: the browser keeps it on the door's origin
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return out
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export const DOWN_HEADER = 'x-shipkit-door-down'
|
|
215
|
+
|
|
216
|
+
const said = (text: string, status: number): Response => new Response(text, { status, headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' } })
|
|
217
|
+
|
|
218
|
+
/** a declared url's login on its hop. `atOnce`: the site already took it, so it goes unasked, as a browser sends a
|
|
219
|
+
* login once the site asked it; `took` hears whether the site took it or refused it */
|
|
220
|
+
export type HopLogin = { login: string | null; atOnce?: boolean; took?: (yes: boolean) => void }
|
|
221
|
+
|
|
222
|
+
/** one http request through a hop: `url` the full target, the answer streamed back, a redirect never followed.
|
|
223
|
+
* `site`: the hop of a declared url the hub frames (its cookies and frame refusals, backHeaders), with `login`, the
|
|
224
|
+
* url's `Authorization`, sent only to the declared origin, never on a request that carries one of its own, first to
|
|
225
|
+
* answer its basic challenge, then at once; a challenge left is a line, never a prompt */
|
|
226
|
+
export async function forwardHop(req: Request, url: string, o: { target: string; own: string | null; key?: string | null; site?: HopLogin; srv?: { timeout(req: Request, s: number): void } }): Promise<Response> {
|
|
227
|
+
const site = o.site != null
|
|
228
|
+
const login = o.site?.login ?? null
|
|
229
|
+
if (login != null && !loginHop(url, o.target)) return said('refused: a login goes to the origin its repo declares, and this request names another', 403)
|
|
230
|
+
const headers = hopHeaders(req, o.target, o.key ?? null, site)
|
|
231
|
+
// a dev server's live stream stays silent between edits: never cut
|
|
232
|
+
o.srv?.timeout(req, 0)
|
|
233
|
+
const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : await req.arrayBuffer()
|
|
234
|
+
try {
|
|
235
|
+
// the browser gone, the request upstream goes too: a reload of a hanging page never leaves a socket behind
|
|
236
|
+
const send = (h: Headers): Promise<Response> => fetch(url, { method: req.method, headers: h, body, redirect: 'manual', decompress: false, signal: req.signal } as RequestInit)
|
|
237
|
+
const ownAuth = headers.has('authorization')
|
|
238
|
+
const withLogin = new Headers(headers)
|
|
239
|
+
if (login != null) withLogin.set('authorization', login)
|
|
240
|
+
const atOnce = login != null && !ownAuth && o.site?.atOnce === true
|
|
241
|
+
let r = await send(atOnce ? withLogin : headers)
|
|
242
|
+
if (login != null && basicChallenge(r)) {
|
|
243
|
+
await r.body?.cancel()
|
|
244
|
+
if (ownAuth) return said('refused: the site asks its basic login on a request that carries an authorization of its own', 401)
|
|
245
|
+
if (!atOnce) r = await send(withLogin)
|
|
246
|
+
if (atOnce || basicChallenge(r)) {
|
|
247
|
+
if (!atOnce) await r.body?.cancel()
|
|
248
|
+
o.site?.took?.(false)
|
|
249
|
+
return said('refused: the site refused the login its repo declares: its password may have changed. Open it in a tab to log in by hand', 401)
|
|
250
|
+
}
|
|
251
|
+
o.site?.took?.(true)
|
|
252
|
+
}
|
|
253
|
+
return new Response(r.body, { status: r.status, statusText: r.statusText, headers: backHeaders(r, o.target, o.own, site) })
|
|
254
|
+
} catch (e) {
|
|
255
|
+
return new Response(`the process does not answer through the door (${(e as Error).message.slice(0, 200)})`, { status: 502, headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store', [DOWN_HEADER]: 'down' } })
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** where a websocket goes upstream: the same path and query on the target, ws for http and wss for https */
|
|
260
|
+
export const wsUrl = (base: string, pathAndQuery: string): string => `${base.replace(/^http/, 'ws')}${pathAndQuery}`
|
|
261
|
+
|
|
262
|
+
/** the sub protocols a browser asked for its socket, to ask upstream and to answer with the first */
|
|
263
|
+
export const protocolsOf = (req: Request): string[] =>
|
|
264
|
+
(req.headers.get('sec-websocket-protocol') ?? '')
|
|
265
|
+
.split(',')
|
|
266
|
+
.map((p) => p.trim())
|
|
267
|
+
.filter((p) => /^[\x21-\x7e]{1,64}$/.test(p) && !p.includes(','))
|
|
268
|
+
.slice(0, 8)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// the names of a door: a machine as a dns label, a process's origin on the hq's home, the loopback origin of a url a
|
|
2
|
+
// machine reported. Pure, so the page's bundle takes it: it imports nothing of the server
|
|
3
|
+
|
|
4
|
+
/** a machine's name as one dns label: lowercase, every other sign a dash, at most 63 */
|
|
5
|
+
export const machineLabel = (name: string): string =>
|
|
6
|
+
name
|
|
7
|
+
.toLowerCase()
|
|
8
|
+
.replace(/[^a-z0-9-]+/g, '-')
|
|
9
|
+
.replace(/-+/g, '-')
|
|
10
|
+
.replace(/^-|-$/g, '')
|
|
11
|
+
.slice(0, 63)
|
|
12
|
+
.replace(/-$/, '')
|
|
13
|
+
|
|
14
|
+
/** a dns label: what a name must be to stand in a host */
|
|
15
|
+
export const DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/
|
|
16
|
+
|
|
17
|
+
/** the one label of a declared url the home frames: `<url id>--<repo>`, the repo as a label (which never holds two
|
|
18
|
+
* dashes), so the last `--` splits it. One label under `localhost` is a site of its own: a cookie of one url's page
|
|
19
|
+
* never reaches another's. Null when the id is no kebab name or the label is over 63 */
|
|
20
|
+
export function urlFrameLabel(id: string, repo: string): string | null {
|
|
21
|
+
const label = `${id}--${machineLabel(repo)}`
|
|
22
|
+
return /^[a-z0-9][a-z0-9-]*$/.test(id) && machineLabel(repo) !== '' && DNS_LABEL.test(label) ? label : null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** the address of a declared url the home frames: `<url id>--<repo>.localhost` on the home's port */
|
|
26
|
+
export function urlFrameOrigin(id: string, repo: string, port: number | string): string | null {
|
|
27
|
+
const label = urlFrameLabel(id, repo)
|
|
28
|
+
return label == null ? null : `http://${label}.localhost:${port}`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** the process's address on the hq's home: its own origin on the home's port */
|
|
32
|
+
export const doorOrigin = (process: string, machine: string, port: number): string => `http://${process}.${machineLabel(machine)}.localhost:${port}`
|
|
33
|
+
|
|
34
|
+
/** the origin of a url a machine reported, kept only when it is plain http on this machine's loopback: a url that
|
|
35
|
+
* names any other host is never followed, so the door relays to nothing but the process that reported it */
|
|
36
|
+
export function loopbackOrigin(url: string): string | null {
|
|
37
|
+
let u: URL
|
|
38
|
+
try {
|
|
39
|
+
u = new URL(url)
|
|
40
|
+
} catch {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
if (u.protocol !== 'http:' || u.username !== '' || u.password !== '') return null
|
|
44
|
+
const h = u.hostname.replace(/^\[|\]$/g, '')
|
|
45
|
+
if (h !== 'localhost' && h !== '::1' && !/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(h)) return null
|
|
46
|
+
return u.origin
|
|
47
|
+
}
|
package/src/serve/embed.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// a repo's review or trailer page alone, for another tool to frame (wiki tools/shipkit/
|
|
1
|
+
// a repo's review or trailer page alone, for another tool to frame (wiki tools/shipkit/threads.md, The review page):
|
|
2
2
|
// `<base>/embed/?page=review` serves the same app bundled with RELATIVE asset paths, so the page and every request it
|
|
3
3
|
// makes work under any prefix a proxy puts in front of the hub (a project's admin frames it under its own origin). The
|
|
4
4
|
// bundle is made once a process, in memory
|