rvlib-shipkit 2.26.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 +20 -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 +6 -4
- 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 +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 +320 -99
- 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/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 +2 -2
- 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_Reflect.ts +23 -2
- package/src/cli/cmd_Review.ts +548 -116
- 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 +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/family-help.ts +4 -2
- package/src/cli/family-pages.ts +1 -1
- package/src/cli/registry.ts +24 -3
- 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/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/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/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 +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 +6 -2
- package/src/ledger/run-log.ts +11 -3
- package/src/ledger/store.ts +26 -4
- package/src/media-store/backup/daemon.ts +25 -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 +67 -16
- 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 +129 -37
- 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/routes.ts +10 -5
- package/src/releases/store.ts +10 -1
- package/src/repo-config.ts +32 -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 +4 -4
- 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 +202 -39
- 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 +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/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
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
// the vault's process: `sk vault serve`, which pm keeps up. It reads the seal key from the login keychain and hands
|
|
2
|
+
// it to bao in bao's own environment, so the vault opens after a restart with nobody typing. The key is never in a
|
|
3
|
+
// file, an argument or a line of output, and bao's environment carries nothing else of this process
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from 'fs'
|
|
5
|
+
import { isAbsolute, join } from 'path'
|
|
6
|
+
import { auditLog, configFile, dataDir, isRealPlace, isSealKey, markerFile, minterTokenFile, refuseRealVault, SEAL_ACCOUNT, SEAL_KEY_ENV, SEAL_SERVICE, sealServiceOf, vaultHcl, vaultPlace, vaultUrl, type MarkerData, type VaultPlace } from './vault-config.ts'
|
|
7
|
+
import { VaultApi, vaultHealth, waitHealth } from './vault-http.ts'
|
|
8
|
+
import { AUDIT_TICK_MS, auditShape, auditTick, type AuditBao, type AuditShape } from './vault-audit.ts'
|
|
9
|
+
import { writesPolicies } from './vault-minter.ts'
|
|
10
|
+
|
|
11
|
+
/** where the seal key is kept: the login keychain, or a stand in under test */
|
|
12
|
+
export type SealStore = {
|
|
13
|
+
/** the key, null when there is none */
|
|
14
|
+
read(): string | null
|
|
15
|
+
write(key: string): void
|
|
16
|
+
/** true when an item exists, read from its attributes only */
|
|
17
|
+
has(): boolean
|
|
18
|
+
remove(): void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `login`: the runner is macOS's own `security`, the user's login keychain */
|
|
22
|
+
export type RunSecurity = ((args: string[], stdin?: string) => { code: number; out: string; err?: string }) & { login?: boolean }
|
|
23
|
+
|
|
24
|
+
/** `security` said something other than found (0) or absent (44): a locked keychain (36) above all, which is not
|
|
25
|
+
* an absent key and must never send the owner to init */
|
|
26
|
+
export class KeychainRefused extends Error {
|
|
27
|
+
constructor(readonly code: number) {
|
|
28
|
+
super(
|
|
29
|
+
code === 36
|
|
30
|
+
? `the login keychain is locked (security exit 36), as in an ssh session or before a login at the desktop: log in at this Mac's own desktop, or run security unlock-keychain`
|
|
31
|
+
: `the login keychain refused (security exit ${code})`,
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const NOT_FOUND = 44
|
|
37
|
+
|
|
38
|
+
export function runSecurity(bin: string): RunSecurity {
|
|
39
|
+
const run: RunSecurity = (args, stdin) => {
|
|
40
|
+
const p = Bun.spawnSync([bin, ...args], { stdin: stdin == null ? 'ignore' : new TextEncoder().encode(stdin), stdout: 'pipe', stderr: 'pipe', env: process.env })
|
|
41
|
+
return { code: p.exitCode ?? 1, out: p.stdout.toString(), err: p.stderr.toString() }
|
|
42
|
+
}
|
|
43
|
+
run.login = bin === 'security' || bin === '/usr/bin/security'
|
|
44
|
+
return run
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const SCRATCH = 'a scratch home never touches the login keychain: its seal key lives in a stand in (RV_KEYCHAIN_BIN)'
|
|
48
|
+
|
|
49
|
+
/** the keychain through `security`. A write goes through `security -i` on stdin, so the key is never in an argv that
|
|
50
|
+
* another process of the user could read. `security -i` exits 0 whatever its line did: the caller reads the key back.
|
|
51
|
+
* The default binary is the one `sk vault serve` reads with; the owner's two commands refuse a swapped one */
|
|
52
|
+
export function keychainSeal(place: VaultPlace, run: RunSecurity = runSecurity(process.env['RV_KEYCHAIN_BIN'] || 'security')): SealStore {
|
|
53
|
+
const service = sealServiceOf(place)
|
|
54
|
+
if (service === SEAL_SERVICE && !isRealPlace(place)) throw new Error('only the real home names the real seal item')
|
|
55
|
+
const who = ['-s', service, '-a', SEAL_ACCOUNT]
|
|
56
|
+
if (run.login === true && !isRealPlace(place)) {
|
|
57
|
+
const refuse = (): never => {
|
|
58
|
+
throw new Error(SCRATCH)
|
|
59
|
+
}
|
|
60
|
+
return { read: refuse, write: refuse, has: refuse, remove: refuse }
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
read: () => {
|
|
64
|
+
const r = run(['find-generic-password', ...who, '-w'])
|
|
65
|
+
if (r.code === NOT_FOUND) return null
|
|
66
|
+
if (r.code !== 0) throw new KeychainRefused(r.code)
|
|
67
|
+
const key = r.out.trim()
|
|
68
|
+
return key === '' ? null : key
|
|
69
|
+
},
|
|
70
|
+
write: (key) => {
|
|
71
|
+
if (!isSealKey(key)) throw new Error('a seal key is 64 hex characters')
|
|
72
|
+
run(['-i'], `add-generic-password -U -s ${service} -a ${SEAL_ACCOUNT} -w ${key}\n`)
|
|
73
|
+
},
|
|
74
|
+
has: () => {
|
|
75
|
+
const code = run(['find-generic-password', ...who]).code
|
|
76
|
+
if (code !== 0 && code !== NOT_FOUND) throw new KeychainRefused(code)
|
|
77
|
+
return code === 0
|
|
78
|
+
},
|
|
79
|
+
remove: () => void run(['delete-generic-password', ...who]),
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** bao's whole environment: what it needs to run, and the key. Nothing else of the caller's (a token, an agent's
|
|
84
|
+
* variables) reaches it */
|
|
85
|
+
export const baoEnv = (key: string, from: Record<string, string | undefined> = process.env): Record<string, string> => ({
|
|
86
|
+
PATH: from['PATH'] ?? '/usr/bin:/bin',
|
|
87
|
+
HOME: from['HOME'] ?? '/',
|
|
88
|
+
TMPDIR: from['TMPDIR'] ?? '/tmp',
|
|
89
|
+
[SEAL_KEY_ENV]: key,
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
export const baoBin = (): string | null => Bun.which('bao')
|
|
93
|
+
|
|
94
|
+
/** the version an OpenBao binary says it is, null when it is no OpenBao */
|
|
95
|
+
export function baoVersion(bin: string): string | null {
|
|
96
|
+
try {
|
|
97
|
+
const p = Bun.spawnSync([bin, 'version'], { stdin: 'ignore', stdout: 'pipe', stderr: 'pipe', env: { PATH: '/usr/bin:/bin' } })
|
|
98
|
+
return /^OpenBao v(\S+)/.exec(p.stdout.toString().trim())?.[1] ?? null
|
|
99
|
+
} catch {
|
|
100
|
+
return null
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function readMarker(p: VaultPlace): MarkerData | null {
|
|
105
|
+
try {
|
|
106
|
+
return existsSync(markerFile(p)) ? (JSON.parse(readFileSync(markerFile(p), 'utf8')) as MarkerData) : null
|
|
107
|
+
} catch {
|
|
108
|
+
return null
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** why the bao the marker names is not the one init ran, null when it is: the seal key goes in its environment */
|
|
112
|
+
export function markerBaoProblem(place: VaultPlace, marker: MarkerData): string | null {
|
|
113
|
+
const version = existsSync(marker.baoPath ?? '') ? baoVersion(marker.baoPath) : null
|
|
114
|
+
return version === marker.bao ? null : `the vault was made with OpenBao ${marker.bao} at ${marker.baoPath}, and that path is ${version == null ? 'no OpenBao' : `OpenBao ${version}`}. An upgrade is a deliberate act: snapshot first, then write the new version in ${markerFile(place)}`
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const NO_BAO = 'openbao is not installed on this machine (brew install openbao, then brew pin openbao)'
|
|
118
|
+
|
|
119
|
+
/** the vault's folder and its data at 0700, and the config written beside them */
|
|
120
|
+
/** the audit file bao uses now: the one its marker records, else the one its config on disk declares, else the
|
|
121
|
+
* place's own */
|
|
122
|
+
export function auditPathOf(p: VaultPlace): string {
|
|
123
|
+
const recorded = readMarker(p)?.auditPath
|
|
124
|
+
if (typeof recorded === 'string' && recorded !== '') return recorded
|
|
125
|
+
try {
|
|
126
|
+
const declared = /file_path = "([^"]+)"/.exec(readFileSync(configFile(p), 'utf8'))?.[1]
|
|
127
|
+
if (declared != null) return isAbsolute(declared) ? declared : join(p.dir, declared)
|
|
128
|
+
} catch {
|
|
129
|
+
// no config yet
|
|
130
|
+
}
|
|
131
|
+
return auditLog(p)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** a vault made before the marker recorded its audit file: the path it uses now, written into its marker (a file of
|
|
135
|
+
* no secret, mode 0600). What it did, null when there is no marker or the path is there already */
|
|
136
|
+
export function recordAuditPath(p: VaultPlace): string | null {
|
|
137
|
+
const m = readMarker(p)
|
|
138
|
+
if (m == null || typeof m.auditPath === 'string') return null
|
|
139
|
+
const auditPath = auditPathOf(p)
|
|
140
|
+
const tmp = `${markerFile(p)}.tmp-${process.pid}`
|
|
141
|
+
writeFileSync(tmp, `${JSON.stringify({ ...m, auditPath }, null, 2)}\n`, { mode: 0o600 })
|
|
142
|
+
renameSync(tmp, markerFile(p))
|
|
143
|
+
return auditPath
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** `configDir`: the config written there instead of the place's own bao.hcl, for a run whose config must never be the
|
|
147
|
+
* vault's (an open root generation) */
|
|
148
|
+
export function prepare(p: VaultPlace, o: { audit?: boolean; unauthedRoot?: boolean; configDir?: string } = {}): void {
|
|
149
|
+
for (const d of [p.dir, dataDir(p), ...(o.configDir != null ? [o.configDir] : [])]) {
|
|
150
|
+
mkdirSync(d, { recursive: true, mode: 0o700 })
|
|
151
|
+
chmodSync(d, 0o700)
|
|
152
|
+
}
|
|
153
|
+
writeFileSync(o.configDir != null ? join(o.configDir, 'bao.hcl') : configFile(p), vaultHcl(p, o), { mode: 0o600 })
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const sbString = (s: string): string => JSON.stringify(realpathSync(s))
|
|
157
|
+
/** a sandbox that refuses every write under `deny` but under `allow`; the paths as the kernel sees them (realpath) */
|
|
158
|
+
export function jailProfile(j: { deny: string[]; allow: string }): string {
|
|
159
|
+
const deny = j.deny.filter((d) => existsSync(d)).map((d) => `(subpath ${sbString(d)})`)
|
|
160
|
+
return `(version 1)(allow default)${deny.length > 0 ? `(deny file-write* ${deny.join(' ')})` : ''}(allow file-write* (subpath ${sbString(j.allow)}))`
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export type Bao = { proc: Bun.Subprocess; gone: () => boolean; stop: () => Promise<void> }
|
|
164
|
+
|
|
165
|
+
/** bao on `p`, its output to `out` (a file, or this process's own streams). `detached`: in a process group of its
|
|
166
|
+
* own, so a terminal's ctrl c or closed window reaches only the process that started it, which stops it */
|
|
167
|
+
/** `tethered`: bao dies with this process, even a SIGKILL of it: a shell holds bao and kills it when the pipe from
|
|
168
|
+
* this process closes, with a SIGKILL 2 s on when bao's graceful stop takes longer (a restore's bao, whose listener takes the unauthenticated root generation, must never
|
|
169
|
+
* outlive it). `jail`: bao writes only under `allow`, never under the folders of `deny` (sandbox-exec), so a proof
|
|
170
|
+
* runs as a new Mac would, where the dead machine's home is not there to write */
|
|
171
|
+
export function startBao(o: { place: VaultPlace; key: string; bin: string; out?: string; audit?: boolean; detached?: boolean; unauthedRoot?: boolean; tethered?: boolean; jail?: { deny: string[]; allow: string }; configDir?: string }): Bao {
|
|
172
|
+
prepare(o.place, { audit: o.audit, unauthedRoot: o.unauthedRoot, ...(o.configDir != null ? { configDir: o.configDir } : {}) })
|
|
173
|
+
const out = o.out == null ? 'inherit' : Bun.file(o.out)
|
|
174
|
+
let argv = [o.bin, 'server', `-config=${o.configDir != null ? join(o.configDir, 'bao.hcl') : configFile(o.place)}`]
|
|
175
|
+
if (o.jail != null) argv = ['/usr/bin/sandbox-exec', '-p', jailProfile(o.jail), ...argv]
|
|
176
|
+
if (o.tethered === true) argv = ['/bin/sh', '-c', 'trap \'kill "$p" 2>/dev/null\' TERM INT HUP; "$@" & p=$!; cat >/dev/null; kill "$p" 2>/dev/null; (sleep 2; kill -0 "$p" 2>/dev/null && kill -9 "$p") & wait "$p"', 'tether', ...argv]
|
|
177
|
+
const proc = Bun.spawn(argv, { cwd: o.place.dir, stdin: o.tethered === true ? 'pipe' : 'ignore', stdout: out, stderr: out, env: baoEnv(o.key), detached: o.detached === true })
|
|
178
|
+
let gone = false
|
|
179
|
+
void proc.exited.then(() => (gone = true))
|
|
180
|
+
return {
|
|
181
|
+
proc,
|
|
182
|
+
gone: () => gone,
|
|
183
|
+
stop: async () => {
|
|
184
|
+
if (gone) return
|
|
185
|
+
if (o.tethered === true) void (proc.stdin as import('bun').FileSink).end()
|
|
186
|
+
proc.kill('SIGTERM')
|
|
187
|
+
const killed = setTimeout(() => proc.kill('SIGKILL'), 10_000)
|
|
188
|
+
await proc.exited
|
|
189
|
+
clearTimeout(killed)
|
|
190
|
+
},
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** a periodic token dies once a period passes unrenewed: the vault's own process keeps the minter's alive */
|
|
195
|
+
export const MINTER_RENEW_MS = 12 * 3_600_000
|
|
196
|
+
|
|
197
|
+
async function renewMinter(p: VaultPlace, say: (l: string) => void): Promise<void> {
|
|
198
|
+
const f = minterTokenFile(p)
|
|
199
|
+
if (!existsSync(f)) return
|
|
200
|
+
try {
|
|
201
|
+
await new VaultApi(vaultUrl(p), readFileSync(f, 'utf8').trim()).renewSelf()
|
|
202
|
+
} catch (e) {
|
|
203
|
+
say(`WARN the minter token was not renewed: ${(e as Error).message}`)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export type VaultStatus = {
|
|
208
|
+
port: number
|
|
209
|
+
/** bao answers its health on the port */
|
|
210
|
+
answers: boolean
|
|
211
|
+
initialised: boolean
|
|
212
|
+
sealed: boolean
|
|
213
|
+
version: string
|
|
214
|
+
/** what `sk vault init` wrote, null before it ran here */
|
|
215
|
+
marker: MarkerData | null
|
|
216
|
+
/** `here` or `absent`, read from the item's attributes only, else why the keychain refused */
|
|
217
|
+
sealKey: string
|
|
218
|
+
/** the rest needs the minter token and an open vault: null when either is missing */
|
|
219
|
+
audit: boolean | null
|
|
220
|
+
rootTokens: number | null
|
|
221
|
+
minterTtlS: number | null
|
|
222
|
+
/** false while the minter writes policies (a vault made before `sk vault narrow`) */
|
|
223
|
+
minterNarrow: boolean | null
|
|
224
|
+
/** a bao on the port that this vault's config did not start, or a listener that makes a root token without one */
|
|
225
|
+
intruder?: string | null
|
|
226
|
+
/** a destroy's work folder left by a killed run */
|
|
227
|
+
destroyLeft?: boolean
|
|
228
|
+
/** the audit file's size, its last rotation, the rotated files kept (vault-audit.ts); null with no vault here */
|
|
229
|
+
auditRotation?: AuditShape | null
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** the processes listening on the place's api port, each with its command line */
|
|
233
|
+
export function portHolders(p: VaultPlace): { pid: number; command: string }[] {
|
|
234
|
+
const pids = Bun.spawnSync(['lsof', '-nP', `-iTCP:${p.port}`, '-sTCP:LISTEN', '-t']).stdout.toString().split(/\s+/).map(Number).filter((n) => n > 0)
|
|
235
|
+
return [...new Set(pids)].map((pid) => ({ pid, command: Bun.spawnSync(['ps', '-o', 'command=', '-p', String(pid)]).stdout.toString().trim() }))
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** why the port is not this vault's alone, null when it is: a holder whose command is not bao on this place's config
|
|
239
|
+
* (a restore's bao left behind, another program), or a listener that answers the unauthenticated root generation,
|
|
240
|
+
* which only a restore's own run may open */
|
|
241
|
+
export async function portIntruder(p: VaultPlace): Promise<string | null> {
|
|
242
|
+
const own = `-config=${configFile(p)}`
|
|
243
|
+
const other = portHolders(p).filter((h) => !h.command.endsWith(own) && !h.command.includes(`${own} `))
|
|
244
|
+
if (other.length > 0) return `a process this vault's config did not start holds 127.0.0.1:${p.port}: ${other.map((h) => `pid ${h.pid} (${h.command.slice(0, 120)})`).join(', ')}. Stop it (kill ${other.map((h) => h.pid).join(' ')}), then sk gp start vault`
|
|
245
|
+
refuseRealVault({ url: vaultUrl(p) })
|
|
246
|
+
const open = await fetch(`${vaultUrl(p)}/v1/sys/generate-root/attempt`, { signal: AbortSignal.timeout(1_000) }).then((r) => r.status, () => 0)
|
|
247
|
+
if (open === 200) return `the listener on 127.0.0.1:${p.port} makes a root token for anyone with the recovery key, no token asked (disable_unauthed_generate_root_endpoints is off): stop it, then sk gp restart vault, which writes the closed config`
|
|
248
|
+
return null
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** where the vault stands, from its health, its marker, the keychain's attributes and the minter. Never a value */
|
|
252
|
+
export async function vaultStatus(o: { seal?: SealStore; place?: VaultPlace } = {}): Promise<VaultStatus> {
|
|
253
|
+
const place = o.place ?? vaultPlace()
|
|
254
|
+
const h = await vaultHealth(vaultUrl(place))
|
|
255
|
+
let sealKey: string
|
|
256
|
+
try {
|
|
257
|
+
sealKey = (o.seal ?? keychainSeal(place)).has() ? 'here' : 'absent'
|
|
258
|
+
} catch (e) {
|
|
259
|
+
sealKey = (e as Error).message
|
|
260
|
+
}
|
|
261
|
+
const out: VaultStatus = { port: place.port, answers: h != null, initialised: h?.initialized ?? false, sealed: h?.sealed ?? true, version: h?.version ?? '', marker: readMarker(place), sealKey, audit: null, rootTokens: null, minterTtlS: null, minterNarrow: null }
|
|
262
|
+
out.intruder = h == null && portHolders(place).length === 0 ? null : await portIntruder(place)
|
|
263
|
+
out.destroyLeft = existsSync(`${place.dir}.destroy`)
|
|
264
|
+
out.auditRotation = auditShape(place, auditPathOf(place))
|
|
265
|
+
if (h?.code !== 200 || !existsSync(minterTokenFile(place))) return out
|
|
266
|
+
const minter = new VaultApi(vaultUrl(place), readFileSync(minterTokenFile(place), 'utf8').trim())
|
|
267
|
+
try {
|
|
268
|
+
out.minterTtlS = (await minter.lookupSelf()).ttl
|
|
269
|
+
out.minterNarrow = !(await writesPolicies(minter))
|
|
270
|
+
out.audit = (await minter.audits()).length > 0
|
|
271
|
+
let roots = 0
|
|
272
|
+
for (const a of await minter.accessors()) if ((await minter.lookupAccessor(a)).policies.includes('root')) roots++
|
|
273
|
+
out.rootTokens = roots
|
|
274
|
+
} catch {
|
|
275
|
+
// a dead minter leaves these unknown, which the status says
|
|
276
|
+
}
|
|
277
|
+
return out
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** the bao this process started, as the audit rotation drives it: a SIGHUP to this child alone makes it reopen its
|
|
281
|
+
* audit file, and a request with no token is audited all the same */
|
|
282
|
+
export const auditBaoOf = (bao: Bao, place: VaultPlace): AuditBao => ({
|
|
283
|
+
reopen: () => {
|
|
284
|
+
if (bao.gone()) throw new Error('bao is gone')
|
|
285
|
+
bao.proc.kill('SIGHUP')
|
|
286
|
+
},
|
|
287
|
+
probe: () => fetch(`${vaultUrl(place)}/v1/sys/mounts`, { signal: AbortSignal.timeout(2_000) }).then((r) => r.arrayBuffer()),
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
/** bao in the foreground until it is stopped: what pm keeps up. It runs only the binary init used, at the version
|
|
291
|
+
* init saw: another `bao` earlier on pm's PATH would get the seal key in its environment. Its exit code, 1 with a
|
|
292
|
+
* line when it cannot start */
|
|
293
|
+
export async function serveVault(o: { seal?: SealStore; place?: VaultPlace; printErr: (l: string) => void; renewMs?: number; tickMs?: number }): Promise<number> {
|
|
294
|
+
const place = o.place ?? vaultPlace()
|
|
295
|
+
const fail = (why: string): number => (o.printErr(`FAIL: ${why}`), 1)
|
|
296
|
+
const marker = readMarker(place)
|
|
297
|
+
if (marker == null) return fail(`the vault is not initialised here (no ${markerFile(place)}). The owner runs sk vault init in Terminal`)
|
|
298
|
+
let key: string | null
|
|
299
|
+
try {
|
|
300
|
+
key = (o.seal ?? keychainSeal(place)).read()
|
|
301
|
+
} catch (e) {
|
|
302
|
+
return fail((e as Error).message)
|
|
303
|
+
}
|
|
304
|
+
if (key == null) return fail(`no seal key in this Mac's login keychain (${sealServiceOf(place)}), though ${markerFile(place)} says the vault was initialised here: put the key back from the owner's copy`)
|
|
305
|
+
if (!isSealKey(key)) return fail(`the keychain item ${sealServiceOf(place)} holds no seal key of 64 hex characters`)
|
|
306
|
+
const wrong = markerBaoProblem(place, marker)
|
|
307
|
+
if (wrong != null) return fail(wrong)
|
|
308
|
+
const intruder = await portIntruder(place)
|
|
309
|
+
if (intruder != null) return fail(intruder)
|
|
310
|
+
const bao = startBao({ place, key, bin: marker.baoPath })
|
|
311
|
+
const stop = (): void => void bao.stop()
|
|
312
|
+
process.once('SIGTERM', stop)
|
|
313
|
+
process.once('SIGINT', stop)
|
|
314
|
+
void waitHealth(vaultUrl(place), (h) => h?.code === 200, { ms: 60_000, gone: bao.gone }).then((h) => {
|
|
315
|
+
if (h?.code === 200) void renewMinter(place, o.printErr)
|
|
316
|
+
})
|
|
317
|
+
// one tick: the minter renewed when due, the audit file looked at while bao answers unsealed
|
|
318
|
+
const renewMs = o.renewMs ?? MINTER_RENEW_MS
|
|
319
|
+
const live = auditPathOf(place)
|
|
320
|
+
const driven = auditBaoOf(bao, place)
|
|
321
|
+
let renewedAt = Date.now()
|
|
322
|
+
let busy = false
|
|
323
|
+
const tick = async (): Promise<void> => {
|
|
324
|
+
if (Date.now() - renewedAt >= renewMs) {
|
|
325
|
+
renewedAt = Date.now()
|
|
326
|
+
await renewMinter(place, o.printErr)
|
|
327
|
+
}
|
|
328
|
+
if (busy || bao.gone()) return
|
|
329
|
+
busy = true
|
|
330
|
+
try {
|
|
331
|
+
if ((await vaultHealth(vaultUrl(place)))?.code === 200) await auditTick({ place, live, bao: driven, say: o.printErr })
|
|
332
|
+
} catch (e) {
|
|
333
|
+
o.printErr(`WARN the look at the vault's audit file failed: ${(e as Error).message}`)
|
|
334
|
+
} finally {
|
|
335
|
+
busy = false
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const every = setInterval(() => void tick(), Math.min(o.tickMs ?? AUDIT_TICK_MS, renewMs))
|
|
339
|
+
const code = await bao.proc.exited
|
|
340
|
+
clearInterval(every)
|
|
341
|
+
return code
|
|
342
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// the vault's own copy (wiki services/secrets, step 2, section 10): a raft snapshot the minter takes, kept beside the
|
|
2
|
+
// vault at 0600 (its folder is never a source of the machine backup), proved by a restore into a scratch vault that
|
|
3
|
+
// opens with the same seal key and holds as many names, then handed to the second place of the Space as a sealed file.
|
|
4
|
+
// A snapshot is encrypted by the vault's keyring, which the seal key wraps: without that key it is bytes
|
|
5
|
+
import { proveAway } from './vault-restore.ts'
|
|
6
|
+
import { chmodSync, mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from 'fs'
|
|
7
|
+
import { tmpdir } from 'os'
|
|
8
|
+
import { join } from 'path'
|
|
9
|
+
import { DEFAULT_VAULT_CLUSTER_PORT, DEFAULT_VAULT_PORT, vaultUrl, type VaultPlace } from './vault-config.ts'
|
|
10
|
+
import { KV_MOUNT } from './layout.ts'
|
|
11
|
+
import { VaultApi, waitHealth } from './vault-http.ts'
|
|
12
|
+
import { startBao } from './vault-serve.ts'
|
|
13
|
+
import type { Space } from '../media-store/space.ts'
|
|
14
|
+
|
|
15
|
+
/** how many snapshots stay beside the vault: the copy keeps 30 days of them */
|
|
16
|
+
export const SNAPSHOTS_KEPT = 3
|
|
17
|
+
export const snapshotsDir = (p: VaultPlace): string => join(p.dir, 'snapshots')
|
|
18
|
+
|
|
19
|
+
export type Taken = { file: string; bytes: number; names: number }
|
|
20
|
+
|
|
21
|
+
/** a snapshot now, into the vault's folder at 0600, the oldest past SNAPSHOTS_KEPT removed; `names` the names the
|
|
22
|
+
* vault held when it was taken */
|
|
23
|
+
export async function takeSnapshot(minter: VaultApi, p: VaultPlace, now: number = Date.now()): Promise<Taken> {
|
|
24
|
+
const names = (await minter.versions(KV_MOUNT)).size
|
|
25
|
+
const snap = await minter.snapshot()
|
|
26
|
+
const dir = snapshotsDir(p)
|
|
27
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 })
|
|
28
|
+
chmodSync(dir, 0o700)
|
|
29
|
+
const file = join(dir, `${new Date(now).toISOString().replace(/[-:]|\.\d{3}/g, '')}.snap`)
|
|
30
|
+
writeFileSync(file, snap, { mode: 0o600 })
|
|
31
|
+
for (const old of readdirSync(dir).filter((f) => f.endsWith('.snap')).sort().slice(0, -SNAPSHOTS_KEPT)) rmSync(join(dir, old), { force: true })
|
|
32
|
+
return { file, bytes: snap.byteLength, names }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const freePort = (): number => {
|
|
36
|
+
for (;;) {
|
|
37
|
+
const s = Bun.listen({ hostname: '127.0.0.1', port: 0, socket: { data() {} } })
|
|
38
|
+
const port = s.port
|
|
39
|
+
s.stop(true)
|
|
40
|
+
if (port !== DEFAULT_VAULT_PORT && port !== DEFAULT_VAULT_CLUSTER_PORT) return port
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type Proved = { names: number; ms: number }
|
|
45
|
+
|
|
46
|
+
/** the snapshot restored into a scratch vault (a temp folder, free ports, this seal key), its names counted with the
|
|
47
|
+
* minter token it carries, the scratch vault stopped and removed. Throws when the key does not open it, or when the
|
|
48
|
+
* scratch vault holds another count than `want` */
|
|
49
|
+
export async function proveSnapshot(o: { snap: Uint8Array<ArrayBuffer>; key: string; bin: string; minterToken: string; want: number }): Promise<Proved> {
|
|
50
|
+
const t0 = performance.now()
|
|
51
|
+
const root = mkdtempSync(join(tmpdir(), 'vault-prove-'))
|
|
52
|
+
const place: VaultPlace = { dir: join(root, 'vault'), port: freePort(), clusterPort: freePort() }
|
|
53
|
+
const bao = startBao({ place, key: o.key, bin: o.bin, out: join(root, 'bao.log'), audit: false })
|
|
54
|
+
try {
|
|
55
|
+
const url = vaultUrl(place)
|
|
56
|
+
if ((await waitHealth(url, (h) => h?.code === 501, { ms: 20_000 }))?.code !== 501) throw new Error('the scratch vault did not start')
|
|
57
|
+
const scratchRoot = new VaultApi(url, (await new VaultApi(url).init()).rootToken)
|
|
58
|
+
if ((await waitHealth(url, (h) => h?.code === 200, { ms: 20_000 }))?.code !== 200) throw new Error('the scratch vault did not open with this seal key')
|
|
59
|
+
await scratchRoot.restore(o.snap, { force: false })
|
|
60
|
+
const end = Date.now() + 20_000
|
|
61
|
+
let names = -1
|
|
62
|
+
for (;;) {
|
|
63
|
+
try {
|
|
64
|
+
names = (await new VaultApi(url, o.minterToken).versions(KV_MOUNT)).size
|
|
65
|
+
break
|
|
66
|
+
} catch (e) {
|
|
67
|
+
if (Date.now() > end) throw new Error(`the restored vault does not answer its minter: ${(e as Error).message}`)
|
|
68
|
+
await Bun.sleep(250)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (names !== o.want) throw new Error(`the restored vault holds ${names} names, the live one ${o.want}`)
|
|
72
|
+
return { names, ms: Math.round(performance.now() - t0) }
|
|
73
|
+
} finally {
|
|
74
|
+
await bao.stop()
|
|
75
|
+
rmSync(root, { recursive: true, force: true })
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** the folder of this machine's sealed snapshots in its own Space: private (never under `public/`), never signed,
|
|
80
|
+
* never in the media index. The one path by which anything of the vault leaves the machine, and only sealed */
|
|
81
|
+
export const SPACE_PREFIX = '_snapshots/vault/'
|
|
82
|
+
export const spaceFolderOf = (machine: string): string => `${SPACE_PREFIX}${machine.toLowerCase()}/`
|
|
83
|
+
const stampOf = (at: number): string => new Date(at).toISOString().replace(/[-:]|\.\d{3}/g, '')
|
|
84
|
+
const atOfStamp = (s: string): number | null => {
|
|
85
|
+
const m = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/.exec(s)
|
|
86
|
+
return m == null ? null : Date.UTC(+m[1]!, +m[2]! - 1, +m[3]!, +m[4]!, +m[5]!, +m[6]!)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** the Space as this module uses it: the client the media store has, its put, list and get */
|
|
90
|
+
export type SnapshotSpace = Pick<Space, 'put' | 'list' | 'get' | 'head'>
|
|
91
|
+
|
|
92
|
+
export type InSpace = { key: string; bytes: number; at: number; sha?: string }
|
|
93
|
+
|
|
94
|
+
const shaOfBytes = (b: Uint8Array): string => new Bun.CryptoHasher('sha256').update(b).digest('hex')
|
|
95
|
+
|
|
96
|
+
/** this machine's snapshots in its Space, newest first */
|
|
97
|
+
export async function snapshotsInSpace(space: SnapshotSpace, machine: string): Promise<(InSpace & { modified: number | null })[]> {
|
|
98
|
+
const rows = await space.list(spaceFolderOf(machine))
|
|
99
|
+
return rows
|
|
100
|
+
.flatMap((r) => {
|
|
101
|
+
const at = atOfStamp(r.key.slice(spaceFolderOf(machine).length).replace(/\.snap$/, ''))
|
|
102
|
+
return at == null || !r.key.endsWith('.snap') ? [] : [{ key: r.key, bytes: r.size, at, modified: r.modified ?? null }]
|
|
103
|
+
})
|
|
104
|
+
// newest first by the Space's own date when it gives one: a key stamped by a machine whose clock ran ahead
|
|
105
|
+
// must never pass for the newest, nor wedge every later proof
|
|
106
|
+
.sort((a, b) => (b.modified ?? b.at) - (a.modified ?? a.at) || b.at - a.at)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** a proven snapshot file up to the Space, private, its size checked there after */
|
|
110
|
+
export async function sendSnapshot(o: { space: SnapshotSpace; file: string; machine: string; at: number }): Promise<InSpace> {
|
|
111
|
+
const key = `${spaceFolderOf(o.machine)}${stampOf(o.at)}.snap`
|
|
112
|
+
if (key.startsWith('public/')) throw new Error('a vault snapshot never goes public')
|
|
113
|
+
const bytes = Bun.file(o.file).size
|
|
114
|
+
await o.space.put(key, o.file, 'application/octet-stream').catch((e: Error) => {
|
|
115
|
+
throw new Error(`the Space did not take ${key}: ${e.message}`)
|
|
116
|
+
})
|
|
117
|
+
const there = await o.space.head(key)
|
|
118
|
+
if (there?.size !== bytes) throw new Error(`the Space holds ${key} at ${there?.size ?? 'no'} bytes, ${bytes} went`)
|
|
119
|
+
return { key, bytes, at: o.at, sha: shaOfBytes(new Uint8Array(await Bun.file(o.file).arrayBuffer())) }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** what a dead disk leaves: a snapshot and the seal key, restored as a new Mac would (vault-restore.ts proveAway) */
|
|
123
|
+
export const proveDeadDisk = (o: { snap: Uint8Array<ArrayBuffer>; key: string; bin: string; recoveryKey?: string; deny?: string[]; say?: (line: string) => void }): Promise<{ names: number | null; door: boolean; ms: number }> => proveAway(o)
|
|
124
|
+
|
|
125
|
+
/** the newest snapshot the Space holds, fetched into a temp folder (0700, the file 0600), its bytes checked against
|
|
126
|
+
* the hash this machine sent, then proved the dead disk way (proveDeadDisk); every file of it removed after */
|
|
127
|
+
export async function proveFromSpace(o: { space: SnapshotSpace; machine: string; key: string; bin: string; sent: Pick<InSpace, 'key' | 'sha'> | null; recoveryKey?: string; want?: number; deny?: string[]; say?: (line: string) => void }): Promise<{ names: number | null; door: boolean; ms: number } & InSpace> {
|
|
128
|
+
const newest = (await snapshotsInSpace(o.space, o.machine))[0]
|
|
129
|
+
if (newest == null) throw new Error(`the Space holds no snapshot under ${spaceFolderOf(o.machine)}`)
|
|
130
|
+
if (o.sent != null && o.sent.key !== newest.key) throw new Error(`the newest in the Space is ${newest.key}, this machine last sent ${o.sent.key}`)
|
|
131
|
+
const dir = mkdtempSync(join(tmpdir(), 'vault-from-space-'))
|
|
132
|
+
chmodSync(dir, 0o700)
|
|
133
|
+
try {
|
|
134
|
+
const file = join(dir, 'snapshot.snap')
|
|
135
|
+
o.say?.(`… the newest snapshot comes from the Space: ${newest.key}`)
|
|
136
|
+
await o.space.get(newest.key, file)
|
|
137
|
+
chmodSync(file, 0o600)
|
|
138
|
+
const snap = new Uint8Array(await Bun.file(file).arrayBuffer())
|
|
139
|
+
if (snap.byteLength !== newest.bytes) throw new Error(`${newest.key} came back at ${snap.byteLength} bytes, the Space lists ${newest.bytes}`)
|
|
140
|
+
const sha = shaOfBytes(snap)
|
|
141
|
+
if (o.sent?.sha != null && o.sent.sha !== sha) throw new Error(`${newest.key} came back with other bytes than the ones this machine sent`)
|
|
142
|
+
o.say?.(`… ${snap.byteLength} bytes${o.sent?.sha != null ? ', the bytes this machine sent' : ''}`)
|
|
143
|
+
const r = await proveDeadDisk({ snap, key: o.key, bin: o.bin, ...(o.recoveryKey != null ? { recoveryKey: o.recoveryKey } : {}), ...(o.deny != null ? { deny: o.deny } : {}), ...(o.say != null ? { say: o.say } : {}) })
|
|
144
|
+
if (r.names != null && o.want != null && r.names !== o.want) throw new Error(`the restored vault holds ${r.names} names, the live one ${o.want}`)
|
|
145
|
+
return { ...newest, sha, ...r }
|
|
146
|
+
} finally {
|
|
147
|
+
rmSync(dir, { recursive: true, force: true })
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** what changes when a secret is set, its names and their versions, as one hash: never a value */
|
|
152
|
+
export async function vaultStamp(minter: Pick<VaultApi, 'versions'>): Promise<{ stamp: string; names: number }> {
|
|
153
|
+
const v = await minter.versions(KV_MOUNT)
|
|
154
|
+
const text = [...v].sort(([a], [b]) => (a < b ? -1 : 1)).map(([p, n]) => `${p}:${n}`).join('\n')
|
|
155
|
+
return { stamp: new Bun.CryptoHasher('sha256').update(text).digest('hex'), names: v.size }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** what the jobs record, names and counts only, read by the vault's status and check and by the resume check */
|
|
159
|
+
export const SENT_KEY = 'vault-snapshot-sent'
|
|
160
|
+
export const PROVED_KEY = 'vault-snapshot-proved-space'
|
|
161
|
+
export const CHANGED_KEY = 'vault-changed-seen'
|
|
162
|
+
export type Sent = InSpace & { stamp: string; names: number }
|
|
163
|
+
/** the last proof from the Space; `deadDisk` when it got in with the recovery key, names counted with that root;
|
|
164
|
+
* `away` when it restored as a new Mac would (proveAway: jailed out of this Mac's homes). A record without `away`
|
|
165
|
+
* proves nothing for another Mac */
|
|
166
|
+
export type ProvedRecord = { key: string; at: number; names: number | null; ms: number; sha?: string; deadDisk?: boolean; away?: boolean }
|
|
167
|
+
/** the last proof the dead disk way, whole: the owner typed the recovery key */
|
|
168
|
+
export const DEAD_DISK_KEY = 'vault-dead-disk-proved'
|
|
169
|
+
|
|
170
|
+
/** a snapshot is taken once a day, and after a change of the vault's names or versions at most once every 10 minutes */
|
|
171
|
+
export const SNAPSHOT_DAY_MS = 24 * 3600_000
|
|
172
|
+
export const SNAPSHOT_CHANGE_MS = 10 * 60_000
|
|
173
|
+
export const snapshotDue = (sent: Sent | null, stamp: string, now: number): boolean =>
|
|
174
|
+
sent == null || now - sent.at >= SNAPSHOT_DAY_MS || (stamp !== sent.stamp && now - sent.at >= SNAPSHOT_CHANGE_MS)
|
|
175
|
+
|
|
176
|
+
export type TickDeps = {
|
|
177
|
+
minter: VaultApi
|
|
178
|
+
place: VaultPlace
|
|
179
|
+
space: SnapshotSpace
|
|
180
|
+
machine: string
|
|
181
|
+
bin: string
|
|
182
|
+
sealKey: string
|
|
183
|
+
minterToken: string
|
|
184
|
+
get: <T>(name: string) => T | null
|
|
185
|
+
set: (name: string, value: unknown) => unknown
|
|
186
|
+
now?: number
|
|
187
|
+
/** the prune of the Space (media-store/forget.ts forgetVaultSnapshots), the one delete the tick makes */
|
|
188
|
+
forget?: (keys: readonly string[]) => Promise<string[]>
|
|
189
|
+
/** the owner's switch vault-snapshots-prune (hq/switch.ts), OFF unless he turned it on */
|
|
190
|
+
pruneOn?: () => boolean
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** each snapshot's names, counted by the proof made before it was sent: what a prune compares */
|
|
194
|
+
export const NAMES_KEY = 'vault-snapshot-names'
|
|
195
|
+
|
|
196
|
+
/** how long a sealed snapshot stays in the Space; the newest KEEP_NEWEST always stay, whatever their age */
|
|
197
|
+
export const RETAIN_MS = 30 * SNAPSHOT_DAY_MS
|
|
198
|
+
export const KEEP_NEWEST = 2
|
|
199
|
+
|
|
200
|
+
/** what a prune would delete, and why each other one stays. Ages come from the Space's own dates (LastModified),
|
|
201
|
+
* anchored on the newest one's, never from a key's stamp nor this machine's clock alone. Nothing goes when a date
|
|
202
|
+
* is missing, or when this machine's clock and the Space's disagree by more than a day (a wrong clock must never
|
|
203
|
+
* erase the history). A snapshot goes only when the newest, proved with its names counted, holds at least as many
|
|
204
|
+
* names as it did, never one of the newest two, never one younger than 30 days, never the one a proof names */
|
|
205
|
+
export function pruneLook(o: { rows: { key: string; modified?: number | null }[]; now: number; newestNames: number | null; names: Record<string, number>; keep: string[] }): { gone: string[]; stays: string[]; refused: string | null } {
|
|
206
|
+
const rows = [...o.rows].sort((a, b) => (b.modified ?? 0) - (a.modified ?? 0))
|
|
207
|
+
if (rows.length <= KEEP_NEWEST) return { gone: [], stays: [], refused: null }
|
|
208
|
+
if (rows.some((r) => r.modified == null)) return { gone: [], stays: [], refused: 'the Space gives no date for some snapshot: nothing is deleted' }
|
|
209
|
+
const skew = o.now - rows[0]!.modified!
|
|
210
|
+
if (Math.abs(skew) > SNAPSHOT_DAY_MS) return { gone: [], stays: [], refused: `this machine's clock and the Space's disagree by ${(Math.abs(skew) / 3600_000).toFixed(0)} h: nothing is deleted` }
|
|
211
|
+
if (o.newestNames == null) return { gone: [], stays: [], refused: 'the newest snapshot has no names count from its proof: nothing is deleted' }
|
|
212
|
+
const gone: string[] = []
|
|
213
|
+
const stays: string[] = []
|
|
214
|
+
for (const r of rows.slice(KEEP_NEWEST)) {
|
|
215
|
+
const had = o.names[r.key]
|
|
216
|
+
if (rows[0]!.modified! - r.modified! <= RETAIN_MS) continue
|
|
217
|
+
if (o.keep.includes(r.key)) stays.push(`${r.key}: a proof names it`)
|
|
218
|
+
else if (had == null) stays.push(`${r.key}: its names were never counted`)
|
|
219
|
+
else if (had > o.newestNames) stays.push(`${r.key}: it held ${had} names, the newest ${o.newestNames}`)
|
|
220
|
+
else gone.push(r.key)
|
|
221
|
+
}
|
|
222
|
+
return { gone, stays, refused: null }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** the job's look: the vault's stamp read; when due a snapshot taken, proved in a scratch vault, sent, then the Space's
|
|
226
|
+
* newest proved by a restore of its own bytes. Each step recorded only after it passed */
|
|
227
|
+
export async function snapshotTick(d: TickDeps): Promise<string[]> {
|
|
228
|
+
const now = d.now ?? Date.now()
|
|
229
|
+
const { stamp, names } = await vaultStamp(d.minter)
|
|
230
|
+
const sent = d.get<Sent>(SENT_KEY)
|
|
231
|
+
const seen = d.get<{ stamp: string; at: number }>(CHANGED_KEY)
|
|
232
|
+
if (sent != null && stamp !== sent.stamp && seen?.stamp !== stamp) d.set(CHANGED_KEY, { stamp, at: now })
|
|
233
|
+
if (!snapshotDue(sent, stamp, now)) return []
|
|
234
|
+
const taken = await takeSnapshot(d.minter, d.place, now)
|
|
235
|
+
const snap = new Uint8Array(await Bun.file(taken.file).arrayBuffer())
|
|
236
|
+
await proveSnapshot({ snap, key: d.sealKey, bin: d.bin, minterToken: d.minterToken, want: taken.names })
|
|
237
|
+
const up = await sendSnapshot({ space: d.space, file: taken.file, machine: d.machine, at: now })
|
|
238
|
+
d.set(SENT_KEY, { ...up, stamp, names } satisfies Sent)
|
|
239
|
+
d.set(NAMES_KEY, { ...(d.get<Record<string, number>>(NAMES_KEY) ?? {}), [up.key]: taken.names })
|
|
240
|
+
const back = await proveFromSpace({ space: d.space, machine: d.machine, key: d.sealKey, bin: d.bin, sent: d.get<Sent>(SENT_KEY) })
|
|
241
|
+
d.set(PROVED_KEY, { key: back.key, at: now, names: null, ms: back.ms, sha: back.sha, deadDisk: false, away: true } satisfies ProvedRecord)
|
|
242
|
+
const lines = [`ok: vault snapshot ${up.key}, ${up.bytes} bytes, ${taken.names} names, proved before it went; from the Space its bytes are the ones sent and it restores with the seal key alone (${back.ms} ms)`]
|
|
243
|
+
// the prune runs only here, only with the owner's switch on, right after the newest passed its proofs
|
|
244
|
+
const on = d.pruneOn ?? (() => false)
|
|
245
|
+
if (!on()) return lines
|
|
246
|
+
const look = pruneLook({ rows: await d.space.list(spaceFolderOf(d.machine)).then((r) => r.filter((x) => x.key.endsWith('.snap'))), now, newestNames: taken.names, names: d.get<Record<string, number>>(NAMES_KEY) ?? {}, keep: [d.get<ProvedRecord>(DEAD_DISK_KEY)?.key, back.key].filter((k): k is string => k != null) })
|
|
247
|
+
if (look.refused != null) return [...lines, `WARN vault prune: ${look.refused}`]
|
|
248
|
+
if (look.gone.length > 0) {
|
|
249
|
+
const gone = await (d.forget ?? (async (k) => (await import('../media-store/forget.ts')).forgetVaultSnapshots(k)))(look.gone)
|
|
250
|
+
const left = { ...(d.get<Record<string, number>>(NAMES_KEY) ?? {}) }
|
|
251
|
+
for (const k of gone) delete left[k]
|
|
252
|
+
d.set(NAMES_KEY, left)
|
|
253
|
+
lines.push(`ok: ${gone.length} vault snapshot${gone.length === 1 ? '' : 's'} older than 30 days removed from the Space, every version; the newest ${KEEP_NEWEST}, every younger one and every one with more names kept`)
|
|
254
|
+
}
|
|
255
|
+
return lines
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** the newest copy and whether the vault moved since, for a person: the lines of the status and the warnings of the
|
|
259
|
+
* checks. `stamp` is the vault's now, null when it was not read */
|
|
260
|
+
export function snapshotHealth(o: { sent: Sent | null; proved: ProvedRecord | null; changed: { stamp: string; at: number } | null; stamp: string | null; now: number; deadDisk?: ProvedRecord | null }): { lines: string[]; warn: string[] } {
|
|
261
|
+
const age = (ms: number): string => (ms < 3600_000 ? `${Math.round(ms / 60_000)} min` : `${(ms / 3600_000).toFixed(1)} h`)
|
|
262
|
+
if (o.sent == null) return { lines: ['no sealed snapshot of this vault is in the Space'], warn: ['no sealed snapshot of this vault is in the Space: if this disk dies, its secrets are lost'] }
|
|
263
|
+
const lines = [`newest sealed snapshot in the Space: ${o.sent.key}, ${o.sent.bytes} bytes, ${o.sent.names} names, ${age(o.now - o.sent.at)} old`]
|
|
264
|
+
const warn: string[] = []
|
|
265
|
+
if (o.now - o.sent.at > 36 * 3600_000) warn.push(`the newest sealed snapshot in the Space is ${age(o.now - o.sent.at)} old (more than 36 h)`)
|
|
266
|
+
const moved = o.stamp != null && o.stamp !== o.sent.stamp
|
|
267
|
+
if (moved) {
|
|
268
|
+
const since = o.changed?.stamp === o.stamp ? o.changed.at : o.sent.at
|
|
269
|
+
lines.push(`the vault changed since it, seen ${age(o.now - since)} ago`)
|
|
270
|
+
if (o.now - since > 3600_000) warn.push(`the vault changed ${age(o.now - since)} ago and no snapshot followed`)
|
|
271
|
+
} else if (o.stamp != null) lines.push('the vault has not changed since it')
|
|
272
|
+
const proved = o.proved?.away === true ? o.proved : null
|
|
273
|
+
lines.push(proved == null ? 'no restore from the Space has passed away from this Mac\'s homes yet (sk vault snapshot --prove --from-space)' : `the Space's copy ${proved.key} came back with the bytes sent and restores with the seal key alone away from this Mac's homes, as a new Mac would, proved ${age(o.now - proved.at)} ago`)
|
|
274
|
+
if (proved == null) warn.push('no restore from the Space has passed away from this Mac\'s homes yet')
|
|
275
|
+
const dead = o.deadDisk?.away === true ? o.deadDisk : null
|
|
276
|
+
if (dead == null) {
|
|
277
|
+
lines.push('getting INTO a restored vault after a dead disk (with the recovery key) is NOT proven on this vault: the owner runs sk vault snapshot --prove --from-space --recovery in his Terminal')
|
|
278
|
+
warn.push('getting into a restored vault (the dead disk way, with the recovery key) is not proven on this vault')
|
|
279
|
+
} else lines.push(`the dead disk way proven ${age(o.now - dead.at)} ago (${new Date(dead.at).toISOString().slice(0, 16)}Z) on ${dead.key}: restored away from this Mac's homes with the seal key, a root from the recovery key, ${dead.names} names`)
|
|
280
|
+
return { lines, warn }
|
|
281
|
+
}
|
package/src/veille/asks.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { COLUMNS, type FeedRow, type Interaction, type Platform, PLATFORMS } fro
|
|
|
11
11
|
|
|
12
12
|
export const LANE = 'interaction'
|
|
13
13
|
/** the command he starts the lane's agent with, in the asks repo */
|
|
14
|
-
export const START_COMMAND = `SK_AGENT=${LANE} sk
|
|
14
|
+
export const START_COMMAND = `SK_AGENT=${LANE} sk thread next --lane ${LANE}`
|
|
15
15
|
/** the review names itself in its title; a post's ask holds one key */
|
|
16
16
|
export const REVIEW_TITLE = 'Revoir la Veille'
|
|
17
17
|
export const AUTO_ID = 'veille-review'
|
package/src/veille/desk.ts
CHANGED
|
@@ -218,7 +218,7 @@ export function brief(r: FeedRow, media: readonly MediaPick[], voice: { as: stri
|
|
|
218
218
|
'',
|
|
219
219
|
`Write it: sk veille reply ${r.key} --as ${voice.as} --text "<the reply>" [--media <path>]`,
|
|
220
220
|
`Or pass it: sk veille pass ${r.key} --as ${voice.as} --why "<one line>"`,
|
|
221
|
-
'Then close this item: sk
|
|
221
|
+
'Then close this item: sk thread fixed <its id> --note "<the draft, or why not>"',
|
|
222
222
|
'',
|
|
223
223
|
].join('\n')
|
|
224
224
|
}
|
|
@@ -236,7 +236,7 @@ export function reviewBrief(columns: readonly { label: string; rows: readonly Fe
|
|
|
236
236
|
'Read every line first, then pick the few posts truly worth a reply (often two or three, sometimes none).',
|
|
237
237
|
`Each one picked: sk veille reply <key> --as ${voice.as} for its brief, then sk veille reply <key> --as ${voice.as} --text "<the reply>".`,
|
|
238
238
|
`Every other line: sk veille pass <key> --as ${voice.as} --why "<the real reason, one line>".`,
|
|
239
|
-
'Then close this item: sk
|
|
239
|
+
'Then close this item: sk thread fixed <its id> --note "<n drafts, m passed>"',
|
|
240
240
|
'',
|
|
241
241
|
].join('\n')
|
|
242
242
|
}
|