rvlib-shipkit 2.26.0 → 2.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/package.json +1 -1
- package/src/agent-time/diet.ts +77 -0
- package/src/agent-time/family.ts +72 -0
- package/src/agent-time/hooks.ts +16 -7
- package/src/agent-time/limits.ts +44 -0
- package/src/agent-time/live.ts +12 -8
- package/src/agent-time/mask.ts +96 -18
- package/src/agent-time/refused.ts +45 -0
- package/src/agent-time/registry.ts +289 -0
- package/src/agent-time/render.ts +122 -21
- package/src/agent-time/report-cache.ts +57 -0
- package/src/agent-time/report.ts +314 -40
- package/src/agent-time/shape.ts +50 -3
- package/src/agent-time/store.ts +322 -101
- package/src/agent-time/timeline.ts +140 -21
- package/src/agent-time/turns.ts +18 -8
- package/src/annex/born.ts +2 -2
- package/src/annex/offload.ts +29 -17
- package/src/annex/tidy.ts +70 -10
- package/src/asks/ask-after.ts +44 -0
- package/src/asks/ask-bar-fold.ts +57 -0
- package/src/asks/ask-migrate.ts +280 -0
- package/src/asks/ask-steps-fold.ts +166 -0
- package/src/asks/ask-store.ts +586 -0
- package/src/assets/kit-config.ts +7 -3
- package/src/assets/kits/identity-kit.ts +361 -14
- package/src/assets/kits/poster-thumbnail.ts +282 -0
- package/src/check.ts +3 -1
- package/src/checks/SK003-claude-md-shape.check.ts +92 -25
- package/src/checks/SK004-gitignore-policy.check.ts +20 -9
- package/src/checks/SK013-one-way-in-policy.check.ts +18 -3
- package/src/checks/SK026-asks-autoclose.check.ts +9 -23
- package/src/checks/SK028-readme.check.ts +7 -66
- package/src/checks/SK030-cache-audit.check.ts +6 -1
- package/src/checks/SK031-trace-audit.check.ts +2 -0
- package/src/checks/SK033-global-contribution.check.ts +3 -1
- package/src/checks/SK035-public-clean.check.ts +2 -2
- package/src/checks/SK038-speaks-as.check.ts +3 -3
- package/src/checks/SK042-post-kinds.check.ts +26 -24
- package/src/checks/SK043-scratch-on-the-mac.check.ts +59 -4
- package/src/checks/SK047-login-in-description.check.ts +36 -0
- package/src/checks/SK048-one-local-file.check.ts +36 -0
- package/src/checks/SK049-thread-answers-hook.check.ts +81 -0
- package/src/checks/SK050-retired-commands.check.ts +127 -0
- package/src/cli/cmd_Asks.ts +244 -27
- package/src/cli/cmd_Backup.ts +153 -10
- package/src/cli/cmd_Calls.ts +1 -0
- package/src/cli/cmd_Capacity.ts +2 -2
- package/src/cli/cmd_Commands.ts +140 -34
- package/src/cli/cmd_Contracts.ts +1 -0
- package/src/cli/cmd_CrossRepoActivity.ts +5 -4
- package/src/cli/cmd_Db.ts +253 -0
- package/src/cli/cmd_History.ts +212 -0
- package/src/cli/cmd_Home.ts +31 -3
- package/src/cli/cmd_Hq.ts +516 -0
- package/src/cli/cmd_Keys.ts +1 -0
- package/src/cli/cmd_Lanes.ts +15 -4
- package/src/cli/cmd_Machines.ts +36 -0
- package/src/cli/cmd_Media.ts +38 -6
- package/src/cli/cmd_Messages.ts +152 -1
- package/src/cli/cmd_Needs.ts +1 -0
- package/src/cli/cmd_Reflect.ts +23 -2
- package/src/cli/cmd_Review.ts +1357 -223
- package/src/cli/cmd_Secret.ts +295 -24
- package/src/cli/cmd_Social.ts +113 -28
- package/src/cli/cmd_SocialDrafts.ts +235 -0
- package/src/cli/cmd_Sound.ts +22 -1
- package/src/cli/cmd_Space.ts +324 -0
- package/src/cli/cmd_Start.ts +3 -2
- package/src/cli/cmd_ThreadHolds.ts +34 -0
- package/src/cli/cmd_ThreadKinds.ts +146 -0
- package/src/cli/cmd_ThreadReflect.ts +83 -0
- package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
- package/src/cli/cmd_Time.ts +76 -5
- package/src/cli/cmd_Tmp.ts +28 -4
- package/src/cli/cmd_Trailer.ts +14 -10
- package/src/cli/cmd_Urls.ts +56 -0
- package/src/cli/cmd_Vault.ts +583 -0
- package/src/cli/cmd_When.ts +1 -0
- package/src/cli/family-help.ts +5 -3
- package/src/cli/family-pages.ts +1 -1
- package/src/cli/kit/builtins.ts +1 -0
- package/src/cli/kit/verb.ts +6 -2
- package/src/cli/registry.ts +44 -4
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +42 -41
- package/src/collections/collection-types.ts +30 -4
- package/src/collections/md-body.ts +5 -3
- package/src/collections/pings.ts +13 -6
- package/src/collections/providers.ts +147 -61
- package/src/collections/reflections.ts +9 -4
- package/src/collections/review.ts +4 -4
- package/src/contracts/contract-manifests.ts +6 -5
- package/src/contracts/contract-types.ts +6 -4
- package/src/contracts/contracts-engine.ts +11 -0
- package/src/contracts/manifests/chrome-web-store.contract.ts +31 -0
- package/src/core/budget.ts +12 -17
- package/src/core/capacity.ts +27 -18
- package/src/core/check-runner.ts +7 -4
- package/src/core/discover-checks.ts +18 -3
- package/src/core/git.ts +31 -0
- package/src/core/house-layout.ts +17 -0
- package/src/core/layout.ts +13 -5
- package/src/core/locked-write.ts +4 -1
- package/src/core/machine-busy.ts +127 -0
- package/src/core/machine-commit.ts +6 -1
- package/src/core/machine-db.ts +370 -20
- package/src/core/machine-layout.ts +137 -0
- package/src/core/machine-read.ts +81 -0
- package/src/core/migrate-layout.ts +9 -11
- package/src/core/one-way-in-policy.ts +64 -7
- package/src/core/polling-policy.ts +27 -0
- package/src/core/retention.ts +16 -2
- package/src/core/scope.ts +107 -14
- package/src/core/slots.ts +5 -4
- package/src/drill/clean.ts +25 -1
- package/src/drill/run.ts +1 -1
- package/src/drill/seal.ts +27 -4
- package/src/home/activity-shape.ts +2 -0
- package/src/home/activity.ts +59 -3
- package/src/home/app-sign.ts +15 -4
- package/src/home/daemon-jobs.ts +161 -7
- package/src/home/database-projects.ts +111 -0
- package/src/home/database-words.ts +203 -0
- package/src/home/databases.ts +460 -0
- package/src/home/global-units.ts +6 -0
- package/src/home/gui-app/ShipkitGui.swift +122 -1
- package/src/home/gui-app.ts +6 -3
- package/src/home/home-move.ts +514 -0
- package/src/home/home-paths.ts +18 -6
- package/src/home/home-routes.ts +76 -0
- package/src/home/inbox-shape.ts +234 -91
- package/src/home/inbox.ts +26 -71
- package/src/home/machine-fold.ts +815 -0
- package/src/home/machine-host.ts +38 -5
- package/src/home/machine-repair.ts +503 -0
- package/src/home/machine-stores.ts +66 -15
- package/src/home/machine-temp.ts +547 -86
- package/src/home/other-macs.ts +2 -2
- package/src/home/resume.ts +79 -0
- package/src/home/run-daemon.ts +25 -4
- package/src/home/run-pm.ts +18 -5
- package/src/home/serve-daemon.ts +18 -3
- package/src/home/serve-web.ts +179 -10
- package/src/home/space-job.ts +115 -0
- package/src/home/space-page.ts +257 -0
- package/src/home/space-route.ts +167 -0
- package/src/home/space-words.ts +103 -0
- package/src/home/time-page-shape.ts +202 -0
- package/src/home/time-page.ts +64 -0
- package/src/home/vault-page.ts +516 -0
- package/src/home/vault-words.ts +132 -0
- package/src/hooks/leak-guard.ts +40 -13
- package/src/hooks/one-way-in-guard.ts +41 -6
- package/src/hq/cards.ts +581 -0
- package/src/hq/door-route.ts +43 -0
- package/src/hq/door.ts +163 -0
- package/src/hq/files-send.ts +347 -0
- package/src/hq/forgotten-log.ts +35 -0
- package/src/hq/history-check.ts +255 -0
- package/src/hq/history-place.ts +146 -0
- package/src/hq/history-send.ts +487 -0
- package/src/hq/hq-db.ts +102 -0
- package/src/hq/hq-local.ts +502 -0
- package/src/hq/hq-routes.ts +204 -0
- package/src/hq/hq-store.ts +603 -0
- package/src/hq/kinds/ask.ts +147 -0
- package/src/hq/kinds/card-gone.ts +83 -0
- package/src/hq/kinds/card-msg.ts +66 -0
- package/src/hq/kinds/card.ts +99 -0
- package/src/hq/kinds/index.ts +21 -0
- package/src/hq/kinds/kind.ts +126 -0
- package/src/hq/kinds/media.ts +125 -0
- package/src/hq/kinds/prompt.ts +219 -0
- package/src/hq/kinds/reflection.ts +128 -0
- package/src/hq/kinds/report.ts +55 -0
- package/src/hq/kinds/time-day.ts +236 -0
- package/src/hq/ledger.ts +473 -0
- package/src/hq/machine-key.ts +44 -0
- package/src/hq/machine-notes.ts +131 -0
- package/src/hq/outbox.ts +374 -0
- package/src/hq/replica.ts +167 -0
- package/src/hq/repo-id.ts +4 -0
- package/src/hq/report-facts.ts +117 -0
- package/src/hq/report.ts +274 -0
- package/src/hq/switch.ts +151 -0
- package/src/hq/vault-grant.ts +92 -0
- package/src/hq/vault-route.ts +112 -0
- package/src/identities/collection.ts +2 -2
- package/src/identities/identities.ts +24 -11
- package/src/identities/machine-route.ts +8 -3
- package/src/identities/steps.ts +31 -0
- package/src/ledger/db.ts +81 -27
- package/src/ledger/gate-checks.ts +6 -2
- package/src/ledger/run-log.ts +11 -3
- package/src/ledger/store.ts +26 -4
- package/src/media-store/backup/daemon.ts +73 -25
- package/src/media-store/backup/kept.ts +241 -0
- package/src/media-store/backup/keys.ts +1 -1
- package/src/media-store/backup/manifest.ts +20 -2
- package/src/media-store/backup/prune.ts +365 -0
- package/src/media-store/backup/restore.ts +14 -4
- package/src/media-store/backup/retention.ts +122 -0
- package/src/media-store/backup/run.ts +25 -19
- package/src/media-store/backup/secret.ts +6 -4
- package/src/media-store/backup/snapshot.ts +4 -2
- package/src/media-store/backup/sources.ts +83 -31
- package/src/media-store/backup/thread-copy.ts +340 -0
- package/src/media-store/copy/config.ts +76 -0
- package/src/media-store/copy/copy.ts +194 -0
- package/src/media-store/copy/lifecycle.ts +43 -0
- package/src/media-store/copy/night.ts +90 -0
- package/src/media-store/copy/proof.ts +151 -0
- package/src/media-store/copy/snapshot.ts +152 -0
- package/src/media-store/copy/store.ts +62 -0
- package/src/media-store/copy/stream.ts +176 -0
- package/src/media-store/daemon.ts +66 -16
- package/src/media-store/db.ts +24 -13
- package/src/media-store/forget.ts +141 -3
- package/src/media-store/hand.ts +4 -3
- package/src/media-store/hq-find.ts +75 -0
- package/src/media-store/hq-send.ts +277 -0
- package/src/media-store/kind.ts +2 -0
- package/src/media-store/purge.ts +21 -17
- package/src/media-store/put.ts +24 -8
- package/src/media-store/remote.ts +16 -7
- package/src/media-store/space-listing.ts +256 -0
- package/src/media-store/space.ts +46 -26
- package/src/media-store/sync.ts +5 -5
- package/src/media-store/tidy.ts +98 -0
- package/src/media-store/upload.ts +3 -3
- package/src/media-store/webp.ts +66 -0
- package/src/messages/guard.ts +49 -0
- package/src/messages/model.ts +16 -7
- package/src/messages/objects.ts +201 -0
- package/src/messages/routes.ts +14 -4
- package/src/messages/score.ts +3 -3
- package/src/messages/write.ts +285 -0
- package/src/pages/frame-client.ts +191 -4
- package/src/plan/planner.ts +28 -17
- package/src/recordings/media-kind.ts +1 -0
- package/src/recordings/model.ts +1 -1
- package/src/recordings/recorder-app/Capture.swift +9 -7
- package/src/reflect/hq-corpus.ts +56 -0
- package/src/reflect/prompt-corpus.ts +3 -1
- package/src/reflect/transcript.ts +129 -37
- package/src/reflections/reflections-queue.ts +1 -1
- package/src/release/gate-checkout.ts +2 -1
- package/src/release/git-facts.ts +3 -2
- package/src/release/machine-words.ts +67 -0
- package/src/release/public-clean.ts +11 -5
- package/src/releases/from-card.ts +1 -1
- package/src/releases/routes.ts +10 -5
- package/src/releases/store.ts +10 -1
- package/src/repo-config.ts +71 -19
- package/src/review/anim.ts +3 -3
- package/src/review/answer-kinds.ts +131 -0
- package/src/review/auto.ts +2 -2
- package/src/review/band.ts +53 -0
- package/src/review/branch-hold.ts +84 -0
- package/src/review/card-db.ts +254 -0
- package/src/review/card-rows.ts +267 -0
- package/src/review/cells.ts +360 -57
- package/src/review/close.ts +92 -0
- package/src/review/draft-card.ts +33 -0
- package/src/review/draft-model.ts +78 -0
- package/src/review/events.ts +171 -0
- package/src/review/format.ts +152 -19
- package/src/review/glyphs.ts +63 -0
- package/src/review/gone.ts +98 -0
- package/src/review/holds-sync.ts +62 -0
- package/src/review/holds.ts +85 -0
- package/src/review/house-kind-defs.ts +41 -0
- package/src/review/inbox-hook.ts +23 -10
- package/src/review/inbox-read.ts +201 -0
- package/src/review/instructions.ts +199 -0
- package/src/review/kind-apply.ts +61 -0
- package/src/review/kind-catalog.ts +96 -0
- package/src/review/kinds.ts +278 -0
- package/src/review/lane-ask.ts +109 -0
- package/src/review/marks.ts +1 -1
- package/src/review/media-kind.ts +7 -5
- package/src/review/media-read.ts +9 -7
- package/src/review/media.ts +32 -5
- package/src/review/model.ts +582 -109
- package/src/review/move.ts +491 -0
- package/src/review/need-address.ts +15 -0
- package/src/review/need-threads.ts +93 -0
- package/src/review/notes.ts +12 -20
- package/src/review/object-card.ts +48 -0
- package/src/review/object-read.ts +31 -0
- package/src/review/owner-verdict.ts +36 -0
- package/src/review/parties.ts +182 -0
- package/src/review/previews.ts +18 -20
- package/src/review/project.ts +1 -1
- package/src/review/projections.ts +235 -0
- package/src/review/referring.ts +54 -0
- package/src/review/reflection-object.ts +195 -0
- package/src/review/rev.ts +8 -0
- package/src/review/role.ts +1 -1
- package/src/review/routes.ts +194 -38
- package/src/review/secret-route.ts +80 -0
- package/src/review/snooze.ts +38 -0
- package/src/review/stage-card.ts +12 -8
- package/src/review/stage-routes.ts +1 -1
- package/src/review/store.ts +851 -124
- package/src/review/supersede.ts +116 -0
- package/src/review/take-back.ts +52 -0
- package/src/review/thread-fold.ts +64 -0
- package/src/review/threads.ts +349 -14
- package/src/review/traces.ts +218 -0
- package/src/review/trailer-auto-mock.ts +63 -0
- package/src/review/trailer-card.ts +6 -6
- package/src/review/trailer-desk.ts +41 -7
- package/src/review/trailer-media.ts +1 -0
- package/src/review/trailer-model.ts +8 -0
- package/src/review/trailer-notes.ts +1 -1
- package/src/review/trailer-routes.ts +9 -1
- package/src/review/unit.ts +77 -11
- package/src/review/verdict-items.ts +73 -0
- package/src/review/verdict-write.ts +15 -0
- package/src/review/wait.ts +85 -0
- package/src/review/watchers.ts +23 -10
- package/src/rules/untrack-generated.ts +92 -8
- package/src/scaffold/files/claude-settings-local.json +2 -0
- package/src/secrets/archive-mark.ts +52 -0
- package/src/secrets/archive.ts +83 -0
- package/src/secrets/copy.ts +14 -14
- package/src/secrets/held.ts +16 -0
- package/src/secrets/keychain-write.ts +48 -0
- package/src/secrets/keychain.ts +116 -0
- package/src/secrets/lapse-mark.ts +33 -0
- package/src/secrets/lapse.ts +60 -0
- package/src/secrets/list.ts +21 -17
- package/src/secrets/manager.ts +55 -26
- package/src/secrets/read.ts +385 -0
- package/src/secrets/tail.ts +31 -0
- package/src/secrets/who-reads.ts +49 -0
- package/src/serve/door-forward.ts +268 -0
- package/src/serve/door-names.ts +47 -0
- package/src/serve/embed.ts +1 -1
- package/src/serve/hub-app/activity-view.tsx +56 -32
- package/src/serve/hub-app/activity.css +7 -1
- package/src/serve/hub-app/asks-page.tsx +49 -0
- package/src/serve/hub-app/asks-st.ts +25 -0
- package/src/serve/hub-app/auto-text.tsx +14 -6
- package/src/serve/hub-app/benign-errors.ts +15 -1
- package/src/serve/hub-app/card-head.tsx +49 -0
- package/src/serve/hub-app/check-view.tsx +3 -2
- package/src/serve/hub-app/clock-svc.ts +1 -2
- package/src/serve/hub-app/code-copy.ts +35 -0
- package/src/serve/hub-app/col-card.tsx +72 -30
- package/src/serve/hub-app/col-list-page.tsx +125 -0
- package/src/serve/hub-app/col-list-st.ts +103 -0
- package/src/serve/hub-app/col-tables-view.tsx +17 -45
- package/src/serve/hub-app/col-tables.ts +76 -8
- package/src/serve/hub-app/cols-svc.ts +18 -39
- package/src/serve/hub-app/commands/commands-page.tsx +2 -1
- package/src/serve/hub-app/controls.css +83 -0
- package/src/serve/hub-app/database-st.ts +260 -0
- package/src/serve/hub-app/database-view.tsx +289 -0
- package/src/serve/hub-app/database.css +32 -0
- package/src/serve/hub-app/entry-bar.css +14 -0
- package/src/serve/hub-app/entry-bar.tsx +33 -0
- package/src/serve/hub-app/entry-pick.ts +31 -0
- package/src/serve/hub-app/floating.tsx +1 -0
- package/src/serve/hub-app/frames-st.ts +17 -1
- package/src/serve/hub-app/git-view.tsx +3 -2
- package/src/serve/hub-app/hash-route.ts +11 -1
- package/src/serve/hub-app/header-bar.tsx +14 -18
- package/src/serve/hub-app/home-st.ts +142 -11
- package/src/serve/hub-app/home-strip.css +6 -25
- package/src/serve/hub-app/home-strip.tsx +60 -93
- package/src/serve/hub-app/home.html +10 -0
- package/src/serve/hub-app/house-wiki-view.tsx +20 -0
- package/src/serve/hub-app/hub-app.tsx +71 -166
- package/src/serve/hub-app/hub-types.ts +5 -1
- package/src/serve/hub-app/hub.css +146 -71
- package/src/serve/hub-app/icons.tsx +32 -5
- package/src/serve/hub-app/identities-st.ts +56 -6
- package/src/serve/hub-app/identities-view.tsx +104 -61
- package/src/serve/hub-app/identities.css +17 -15
- package/src/serve/hub-app/identity-address.ts +5 -0
- package/src/serve/hub-app/inbox-st.ts +227 -49
- package/src/serve/hub-app/inbox-view.tsx +204 -120
- package/src/serve/hub-app/inbox.css +47 -47
- package/src/serve/hub-app/index.html +10 -0
- package/src/serve/hub-app/instructions.css +30 -0
- package/src/serve/hub-app/kept-cols.tsx +7 -0
- package/src/serve/hub-app/keys.ts +32 -17
- package/src/serve/hub-app/later.tsx +26 -0
- package/src/serve/hub-app/list-filter.tsx +14 -0
- package/src/serve/hub-app/list-walk.ts +72 -3
- package/src/serve/hub-app/machine-st.ts +2 -2
- package/src/serve/hub-app/machines-st.ts +251 -0
- package/src/serve/hub-app/machines-view.tsx +217 -0
- package/src/serve/hub-app/machines.css +67 -0
- package/src/serve/hub-app/markdown.css +51 -0
- package/src/serve/hub-app/md-copy.tsx +57 -0
- package/src/serve/hub-app/md.ts +25 -9
- package/src/serve/hub-app/media-view.tsx +4 -2
- package/src/serve/hub-app/messages/messages-page.tsx +81 -8
- package/src/serve/hub-app/messages/messages-st.ts +99 -3
- package/src/serve/hub-app/messages.css +14 -1
- package/src/serve/hub-app/objects.css +51 -0
- package/src/serve/hub-app/page-keys.ts +175 -0
- package/src/serve/hub-app/pages-frames.tsx +21 -3
- package/src/serve/hub-app/palette-st.ts +58 -11
- package/src/serve/hub-app/palette-view.tsx +3 -1
- package/src/serve/hub-app/pane-boundary.tsx +72 -0
- package/src/serve/hub-app/pane-errors.ts +54 -0
- package/src/serve/hub-app/plan-view.tsx +3 -2
- package/src/serve/hub-app/planned-view.tsx +3 -3
- package/src/serve/hub-app/planned.css +0 -4
- package/src/serve/hub-app/processes-view.tsx +3 -2
- package/src/serve/hub-app/project-list.css +46 -8
- package/src/serve/hub-app/project-list.tsx +125 -59
- package/src/serve/hub-app/projects-svc.ts +83 -8
- package/src/serve/hub-app/reader-chips.tsx +13 -0
- package/src/serve/hub-app/readme-view.tsx +2 -3
- package/src/serve/hub-app/readme.css +22 -6
- package/src/serve/hub-app/reflections-page.tsx +95 -0
- package/src/serve/hub-app/reflections-st.ts +17 -0
- package/src/serve/hub-app/releases/releases-page.tsx +28 -4
- package/src/serve/hub-app/releases/releases-st.ts +1 -1
- package/src/serve/hub-app/releases.css +0 -1
- package/src/serve/hub-app/repo-sections.ts +9 -5
- package/src/serve/hub-app/repo-st.ts +35 -8
- package/src/serve/hub-app/review/code-colors.ts +30 -0
- package/src/serve/hub-app/review/diff-view.tsx +75 -0
- package/src/serve/hub-app/review/dock.tsx +104 -0
- package/src/serve/hub-app/review/draft-card.tsx +163 -0
- package/src/serve/hub-app/review/group-block.tsx +209 -0
- package/src/serve/hub-app/review/instructions-view.tsx +116 -0
- package/src/serve/hub-app/review/item-verdict.tsx +38 -0
- package/src/serve/hub-app/review/kind-states.tsx +193 -0
- package/src/serve/hub-app/review/kind-view.tsx +1 -37
- package/src/serve/hub-app/review/kit.tsx +75 -29
- package/src/serve/hub-app/review/lane-bar.tsx +64 -0
- package/src/serve/hub-app/review/note-place.ts +1 -1
- package/src/serve/hub-app/review/object-card.tsx +62 -0
- package/src/serve/hub-app/review/object-panel.tsx +179 -0
- package/src/serve/hub-app/review/question-views.tsx +385 -0
- package/src/serve/hub-app/review/review-board.tsx +2 -2
- package/src/serve/hub-app/review/review-cells.tsx +148 -87
- package/src/serve/hub-app/review/review-kit.ts +27 -1
- package/src/serve/hub-app/review/review-list.tsx +160 -65
- package/src/serve/hub-app/review/review-page.tsx +12 -12
- package/src/serve/hub-app/review/review-st.ts +174 -47
- package/src/serve/hub-app/review/review-thread.tsx +214 -53
- package/src/serve/hub-app/review/review-views.tsx +494 -159
- package/src/serve/hub-app/review/thread-close.tsx +124 -0
- package/src/serve/hub-app/review/thread-control-st.ts +115 -0
- package/src/serve/hub-app/review/thread-control.tsx +74 -0
- package/src/serve/hub-app/review/thread-st.ts +288 -41
- package/src/serve/hub-app/review/trailer-card.tsx +2 -2
- package/src/serve/hub-app/review/trailer-page.tsx +37 -16
- package/src/serve/hub-app/review/trailer-st.ts +41 -7
- package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
- package/src/serve/hub-app/review.css +462 -97
- package/src/serve/hub-app/section-head.tsx +51 -0
- package/src/serve/hub-app/side-lists.ts +72 -0
- package/src/serve/hub-app/sidebar.tsx +6 -3
- package/src/serve/hub-app/site/site-part.tsx +2 -8
- package/src/serve/hub-app/site/site-st.ts +4 -4
- package/src/serve/hub-app/social/calendar.tsx +5 -11
- package/src/serve/hub-app/social/comms-page.tsx +43 -15
- package/src/serve/hub-app/social/kit.tsx +32 -13
- package/src/serve/hub-app/social/next-release.tsx +3 -5
- package/src/serve/hub-app/social/post-card.tsx +142 -49
- package/src/serve/hub-app/social/post-page.tsx +80 -0
- package/src/serve/hub-app/social/problems.tsx +5 -9
- package/src/serve/hub-app/social/serial-writes.ts +13 -0
- package/src/serve/hub-app/social/social-model.ts +24 -5
- package/src/serve/hub-app/social/social-page.tsx +95 -36
- package/src/serve/hub-app/social/social-st.ts +162 -41
- package/src/serve/hub-app/social/stage-popup.tsx +1 -1
- package/src/serve/hub-app/social/stage-st.ts +1 -1
- package/src/serve/hub-app/social/step-layout.ts +1 -1
- package/src/serve/hub-app/social.css +10 -17
- package/src/serve/hub-app/space-st.ts +209 -0
- package/src/serve/hub-app/space-view.tsx +196 -0
- package/src/serve/hub-app/space.css +27 -0
- package/src/serve/hub-app/stores/stores-page.tsx +97 -25
- package/src/serve/hub-app/stores/stores-st.ts +44 -19
- package/src/serve/hub-app/stores.css +6 -1
- package/src/serve/hub-app/theme-st.ts +22 -9
- package/src/serve/hub-app/thread-row.tsx +101 -0
- package/src/serve/hub-app/time-ago.tsx +3 -2
- package/src/serve/hub-app/time-charts.tsx +291 -0
- package/src/serve/hub-app/time-pages.tsx +749 -0
- package/src/serve/hub-app/time-st.ts +162 -0
- package/src/serve/hub-app/time-view.tsx +77 -0
- package/src/serve/hub-app/time.css +135 -0
- package/src/serve/hub-app/tree-build.ts +52 -42
- package/src/serve/hub-app/tree-row.tsx +3 -11
- package/src/serve/hub-app/tree-svc.ts +18 -9
- package/src/serve/hub-app/urls-svc.ts +154 -0
- package/src/serve/hub-app/urls-view.tsx +117 -0
- package/src/serve/hub-app/urls.css +30 -0
- package/src/serve/hub-app/vault-st.ts +127 -0
- package/src/serve/hub-app/vault-view.tsx +154 -0
- package/src/serve/hub-app/vault.css +38 -0
- package/src/serve/hub-app/veille/veille-page.tsx +2 -11
- package/src/serve/hub-app/veille/veille-st.ts +12 -10
- package/src/serve/hub-app/veille.css +0 -1
- package/src/serve/hub-app/waiting-svc.ts +29 -0
- package/src/serve/hub-app/when-view.tsx +6 -3
- package/src/serve/hub-app/wiki-st.ts +30 -4
- package/src/serve/hub-app/wikis-view.tsx +6 -5
- package/src/serve/hub-runtime.ts +35 -8
- package/src/serve/project-gutter-route.ts +42 -19
- package/src/serve/project-gutter.ts +16 -50
- package/src/serve/same-origin.ts +13 -0
- package/src/serve/secret-gate.ts +21 -0
- package/src/serve/serve-hub.ts +38 -20
- package/src/serve/tailnet-caller.ts +117 -0
- package/src/shipkit-files.ts +16 -2
- package/src/shipkit.ts +3 -3
- package/src/shot/shooter.ts +616 -420
- package/src/shot/shot-ask.ts +246 -155
- package/src/site/desk.ts +4 -4
- package/src/smoke/run-smoke.ts +6 -6
- package/src/social/brands.ts +4 -0
- package/src/social/card-drafts.ts +11 -19
- package/src/social/cover.ts +202 -0
- package/src/social/desk-index.ts +34 -13
- package/src/social/discord-layout.ts +37 -13
- package/src/social/drafts.ts +7 -4
- package/src/social/import-drafts.ts +244 -0
- package/src/social/kind-pages.ts +3 -3
- package/src/social/kinds.ts +1 -1
- package/src/social/load.ts +111 -65
- package/src/social/media-kind.ts +68 -160
- package/src/social/media-of.ts +5 -4
- package/src/social/open.ts +3 -2
- package/src/social/post-object.ts +120 -0
- package/src/social/post-sources.ts +136 -0
- package/src/social/post-text.ts +103 -0
- package/src/social/posts.ts +378 -0
- package/src/social/presence.ts +7 -5
- package/src/social/publish/discord.ts +5 -2
- package/src/social/publish/index.ts +17 -5
- package/src/social/publish/secret.ts +4 -4
- package/src/social/release-stage.ts +79 -63
- package/src/social/routes.ts +89 -24
- package/src/social/stage.ts +43 -58
- package/src/social/stats.ts +12 -9
- package/src/social/strip.ts +4 -1
- package/src/social/text.ts +4 -3
- package/src/social/thumbnail.ts +347 -0
- package/src/social/tracker.ts +1 -1
- package/src/social/writes.ts +12 -29
- package/src/stores/collection.ts +15 -11
- package/src/stores/desk.ts +246 -47
- package/src/stores/model.ts +72 -6
- package/src/stores/routes.ts +37 -12
- package/src/stores/unit.ts +16 -10
- package/src/suite/judge-suites.ts +41 -11
- package/src/suite/select.ts +45 -3
- package/src/suite/suite-cli.ts +16 -10
- package/src/trailer/bed.ts +1 -1
- package/src/trailer/build.ts +134 -21
- package/src/trailer/ffmpeg.ts +7 -0
- package/src/trailer/fonts.ts +3 -2
- package/src/trailer/grammar.ts +201 -2
- package/src/trailer/graph.ts +42 -5
- package/src/trailer/look.ts +21 -0
- package/src/trailer/mock.ts +154 -0
- package/src/trailer/passage.ts +65 -26
- package/src/trailer/score/heard.ts +89 -0
- package/src/trailer/score/sound.ts +14 -8
- package/src/trailer/sound/eleven.ts +33 -3
- package/src/trailer/sound/run.ts +16 -6
- package/src/trailer/stitch.ts +26 -5
- package/src/trailer/titles.ts +82 -19
- package/src/trailer/versions.ts +1 -3
- package/src/trailer/vertical.ts +3 -1
- package/src/urls/frame.ts +195 -0
- package/src/urls/routes.ts +43 -0
- package/src/urls/rows.ts +171 -0
- package/src/urls/unit.ts +73 -0
- package/src/vault/house-keys.ts +42 -0
- package/src/vault/layout.ts +50 -0
- package/src/vault/policy.ts +165 -0
- package/src/vault/vault-audit.ts +276 -0
- package/src/vault/vault-client.ts +40 -0
- package/src/vault/vault-config.ts +159 -0
- package/src/vault/vault-destroy.ts +78 -0
- package/src/vault/vault-handover.ts +305 -0
- package/src/vault/vault-http.ts +360 -0
- package/src/vault/vault-import.ts +213 -0
- package/src/vault/vault-init.ts +328 -0
- package/src/vault/vault-minter.ts +271 -0
- package/src/vault/vault-restore.ts +333 -0
- package/src/vault/vault-serve.ts +342 -0
- package/src/vault/vault-snapshot.ts +281 -0
- package/src/veille/asks.ts +1 -1
- package/src/veille/desk.ts +2 -2
- package/src/veille/identity.ts +2 -2
- package/src/wiki/graph-pages.ts +13 -1
- package/src/wiki/scan-md.ts +1 -1
- package/src/asks/asks-queue.ts +0 -266
- package/src/social/migrate.ts +0 -123
package/src/core/machine-db.ts
CHANGED
|
@@ -1,48 +1,394 @@
|
|
|
1
1
|
// THE MACHINE DB: what shipkit remembers about this machine, whatever repo
|
|
2
|
-
// asks, in one sqlite file
|
|
2
|
+
// asks, in one sqlite file, the one local file of the machine beside the hq: the
|
|
3
|
+
// media index's tables (`media_*`) and the agent time index's (`time_*`) are in
|
|
4
|
+
// it too once folded (machine-fold.ts). Its own: pm's children and resources (their pid records),
|
|
3
5
|
// the repos flagged active, the rail order, the self update answer, the
|
|
4
|
-
// instance registry.
|
|
6
|
+
// instance registry. A `state` table of named json values, and a table of
|
|
7
|
+
// its own for a value that grows without bound and would be rewritten whole
|
|
8
|
+
// at each change (the backup's list of sources and the files its runs held).
|
|
5
9
|
//
|
|
6
10
|
// The one constraint a reader breaks first: a failure reads as "nothing
|
|
7
11
|
// remembered", and every caller treats that as the safe side (no adoption,
|
|
8
12
|
// no replay, the pid rule). Slot LOCKS are not here: they are leases a dead
|
|
9
13
|
// pid must release at once, which a file does and a row does not.
|
|
10
14
|
import { Database } from 'bun:sqlite'
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync, rmSync } from 'fs'
|
|
12
|
-
import { homedir } from 'os'
|
|
15
|
+
import { chmodSync, closeSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, rmSync, statSync, writeFileSync } from 'fs'
|
|
13
16
|
import { dirname, join } from 'path'
|
|
14
|
-
import {
|
|
17
|
+
import { homeDir, refuseRealHomeInSuite } from '../home/home-paths.ts'
|
|
18
|
+
import { ensureWal, migrateTo, storeSync } from '../ledger/db.ts'
|
|
19
|
+
import { createRefusal, machinePath } from './machine-layout.ts'
|
|
15
20
|
|
|
16
21
|
export const MACHINE_DB_ENV = 'SHIPKIT_MACHINE_DB'
|
|
22
|
+
export const MACHINE_DB_FILE = 'shipkit.sqlite'
|
|
17
23
|
|
|
18
|
-
/** `~/.
|
|
19
|
-
* set, so a smoke or a suite with its own home never touches the real one */
|
|
24
|
+
/** `~/.shipkit/shipkit.sqlite` (in `~/.config/shipkit/` until the machine moved: layout.ts machinePath); beside a
|
|
25
|
+
* moved home dir when one is set, so a smoke or a suite with its own home never touches the real one */
|
|
20
26
|
export function machineDbPath(): string {
|
|
21
27
|
const env = process.env[MACHINE_DB_ENV]
|
|
22
28
|
if (env != null && env !== '') return env
|
|
23
29
|
const home = process.env.SHIPKIT_HOME_DIR
|
|
24
30
|
if (home != null && home !== '') return join(home, 'machine.sqlite')
|
|
25
|
-
|
|
31
|
+
refuseRealHomeInSuite()
|
|
32
|
+
return machinePath(MACHINE_DB_FILE)
|
|
26
33
|
}
|
|
27
34
|
|
|
28
|
-
/**
|
|
29
|
-
|
|
35
|
+
/** the stores that were files of their own and are tables of the machine db once folded (`sk db fold`) */
|
|
36
|
+
export type FoldedStore = 'media index' | 'agent time index' | 'daemon file'
|
|
37
|
+
export const FOLDED_STORES: readonly FoldedStore[] = ['media index', 'agent time index', 'daemon file']
|
|
38
|
+
/** the variable that moves a store for one process: never refused there */
|
|
39
|
+
export const STORE_ENV: Record<FoldedStore, string> = { 'media index': 'SHIPKIT_MEDIA_DB', 'agent time index': 'SHIPKIT_AGENT_TIME_DB', 'daemon file': 'SHIPKIT_DAEMON_DB' }
|
|
40
|
+
|
|
41
|
+
/** where a folded store's own file was: beside the machine db when a home dir is set (a suite, a scratch) */
|
|
42
|
+
export function oldStorePath(store: FoldedStore): string {
|
|
43
|
+
if (store === 'media index') return join(homeDir(), 'media.sqlite')
|
|
44
|
+
if (store === 'daemon file') return join(homeDir(), 'daemon.sqlite')
|
|
45
|
+
const home = process.env.SHIPKIT_HOME_DIR
|
|
46
|
+
return home != null && home !== '' ? join(home, 'agent-time.sqlite') : machinePath('agent-time.sqlite')
|
|
47
|
+
}
|
|
30
48
|
|
|
31
|
-
|
|
49
|
+
/** each folded store's table prefix in the machine db: its file of its own has the same tables after a way back */
|
|
50
|
+
export const STORE_PREFIX: Record<FoldedStore, string> = { 'media index': 'media_', 'agent time index': 'time_', 'daemon file': '' }
|
|
51
|
+
// the daemon's tables keep their names (outbox, review_cards, ...): none is a name of the machine db's own, and its
|
|
52
|
+
// own file has one shape before and after a fold
|
|
32
53
|
|
|
33
|
-
|
|
54
|
+
/** the switch of the daemon's fold (home/machine-fold.ts, hq/switch.ts): off, a store not folded is read and written
|
|
55
|
+
* in its own file. A machine db that does not read THROWS */
|
|
56
|
+
export const FOLD_AUTO = 'db-fold-auto'
|
|
57
|
+
export const foldAutoOn = (): boolean => machineRead<boolean>(FOLD_AUTO) !== false
|
|
58
|
+
|
|
59
|
+
/** the shape of a store's own file: `tables`, the machine db's tables (`media_files`, written by a way back), `old`,
|
|
60
|
+
* the names of before the fold (`files`), null when no sqlite file is there (none, or a tombstone) */
|
|
61
|
+
export function ownShape(store: FoldedStore, old = oldStorePath(store)): 'tables' | 'old' | null {
|
|
62
|
+
if (lstatSync(old, { throwIfNoEntry: false }) == null || isTombstone(old)) return null
|
|
34
63
|
let db: Database | null = null
|
|
64
|
+
try {
|
|
65
|
+
// read write and never made: a read only open of a WAL file with no shared memory beside it fails
|
|
66
|
+
db = new Database(old, { readwrite: true, create: false })
|
|
67
|
+
db.exec('pragma busy_timeout = 3000')
|
|
68
|
+
const names = (db.query("select name from sqlite_master where type = 'table'").all() as { name: string }[]).map((r) => r.name)
|
|
69
|
+
return STORE_PREFIX[store] === '' || names.some((n) => n.startsWith(STORE_PREFIX[store])) ? 'tables' : 'old'
|
|
70
|
+
} catch {
|
|
71
|
+
return 'old'
|
|
72
|
+
} finally {
|
|
73
|
+
db?.close()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** where this machine keeps a store: the machine db, or, while the store is not folded, its own file when the fold is
|
|
78
|
+
* off or the file has the tables this code reads (a fold of several stores leaves each in its file until its turn).
|
|
79
|
+
* One branch, at the place a store is opened: its readers and writers use the same tables in both */
|
|
80
|
+
export function storeHome(store: FoldedStore, now = Date.now()): string {
|
|
81
|
+
const old = oldStorePath(store)
|
|
82
|
+
const machine = machineDbPath()
|
|
83
|
+
const kept = homes.get(store)
|
|
84
|
+
// a process asks at every read and write of its store: the answer holds a second, as the switch of the cards does
|
|
85
|
+
if (kept != null && kept.old === old && kept.machine === machine && now - kept.at < HOME_EVERY_MS) return kept.home
|
|
86
|
+
const home = lstatSync(old, { throwIfNoEntry: false }) != null && !isTombstone(old) && (!foldAutoOn() || ownShape(store, old) === 'tables') ? old : machine
|
|
87
|
+
homes.set(store, { old, machine, home, at: now })
|
|
88
|
+
return home
|
|
89
|
+
}
|
|
90
|
+
const HOME_EVERY_MS = 1000
|
|
91
|
+
const homes = new Map<FoldedStore, { old: string; machine: string; home: string; at: number }>()
|
|
92
|
+
/** this process reads where its stores are again at once: a fold or a way back of its own just moved them */
|
|
93
|
+
export const forgetStoreHomes = (): void => homes.clear()
|
|
94
|
+
|
|
95
|
+
/** the mark a fold or a way back sets on a store while it walks (`<FOLD_MARK><store>` in `state`) */
|
|
96
|
+
export const FOLD_MARK = 'db-fold-partial:'
|
|
97
|
+
export type FoldMark = { way: 'go' | 'back'; pid: number; at: number }
|
|
98
|
+
export function foldMarkOf(store: FoldedStore): FoldMark | null {
|
|
99
|
+
const row = machineDb((db) => db.query('select value from state where name = ?').get(`${FOLD_MARK}${store}`) as { value: string } | null)
|
|
100
|
+
return row == null ? null : (JSON.parse(row.value) as FoldMark)
|
|
101
|
+
}
|
|
102
|
+
/** the head of a refusal that ends by itself: a fold, a way back or a repair at work. `sk time` exits WAIT_EXIT on it */
|
|
103
|
+
const WAIT = 'wait: '
|
|
104
|
+
export const WAIT_EXIT = 75
|
|
105
|
+
export const isWaitRefusal = (msg: string): boolean => msg.startsWith(WAIT)
|
|
106
|
+
export const refusalText = (msg: string): string => (isWaitRefusal(msg) ? msg.slice(WAIT.length) : msg)
|
|
107
|
+
/** a store's open refused: its words, and whether it ends by itself (a walk at work) */
|
|
108
|
+
export class StoreRefused extends Error {
|
|
109
|
+
override readonly name = 'StoreRefused'
|
|
110
|
+
readonly wait: boolean
|
|
111
|
+
constructor(refusal: string) {
|
|
112
|
+
super(refusalText(refusal))
|
|
113
|
+
this.wait = isWaitRefusal(refusal)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** a StoreRefused by its name: a process may hold two copies of this module (the daemon's hubs load the lib again) */
|
|
117
|
+
export const isStoreRefused = (e: unknown): e is StoreRefused => e instanceof Error && e.name === 'StoreRefused'
|
|
118
|
+
/** a refusal that ends once what it names ends: `sk time`, `sk db fold` exit WAIT_EXIT on it */
|
|
119
|
+
export const waitRefused = (text: string): StoreRefused => new StoreRefused(`${WAIT}${text}`)
|
|
120
|
+
/** a time of today as the owner's clock says it, the day before it when it is not today */
|
|
121
|
+
const localClock = (at: number): string => {
|
|
122
|
+
const d = new Date(at)
|
|
123
|
+
const day = d.toLocaleDateString('sv-SE')
|
|
124
|
+
return `${day === new Date().toLocaleDateString('sv-SE') ? '' : `${day} `}${d.toLocaleTimeString('sv-SE')}`
|
|
125
|
+
}
|
|
126
|
+
/** how long the last walk of a store took on this machine, by its way (`<store>:<go|back>`): `{ ms, bytes }`, the size
|
|
127
|
+
* of its file then */
|
|
128
|
+
export const WALK_TOOK = 'db-walk-took:'
|
|
129
|
+
/** the size a walk of a store moves: its file under the fold's name, its own file, else the fold's copy */
|
|
130
|
+
export function walkBytes(old: string): number {
|
|
131
|
+
for (const f of [`${old}.fold-src`, old, `${old}.before-fold`]) {
|
|
132
|
+
try {
|
|
133
|
+
const st = statSync(f)
|
|
134
|
+
if (st.size > 4096) return st.size
|
|
135
|
+
} catch { /* not there */ }
|
|
136
|
+
}
|
|
137
|
+
return 0
|
|
138
|
+
}
|
|
139
|
+
/** what is left of a walk: from the last walk of that store and way on this machine, scaled by its size, else a bound
|
|
140
|
+
* from its size (about 8 MB a second on a loaded Mac: 401 MB in 47 s, measured) */
|
|
141
|
+
function waitLeft(store: FoldedStore, old: string, mark: FoldMark): string {
|
|
142
|
+
const bytes = walkBytes(old)
|
|
143
|
+
const gone = (Date.now() - mark.at) / 1000
|
|
144
|
+
const row = machineDb((db) => db.query('select value from state where name = ?').get(`${WALK_TOOK}${store}:${mark.way}`) as { value: string } | null)
|
|
145
|
+
const last = row == null ? null : (JSON.parse(row.value) as { ms: number; bytes: number })
|
|
146
|
+
const word = mark.way === 'back' ? 'way back' : 'fold'
|
|
147
|
+
if (last != null && last.ms > 0) {
|
|
148
|
+
const took = (last.ms / 1000) * (last.bytes > 0 && bytes > 0 ? bytes / last.bytes : 1)
|
|
149
|
+
return `about ${Math.max(1, Math.round(took - gone))} s left (its last ${word} here took ${(last.ms / 1000).toFixed(1)} s)`
|
|
150
|
+
}
|
|
151
|
+
return `under ${Math.max(1, Math.ceil(bytes / 8e6 + 5 - gone))} s left (a bound by its size)`
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** the mark of a repair of a store's damaged tables (home/machine-repair.ts): `saving` while their rows go aside, `saved`
|
|
155
|
+
* once all are there and the tables may be made again */
|
|
156
|
+
export const REPAIR_MARK = 'db-fold-repair:'
|
|
157
|
+
export type RepairMark = { tables: string[]; phase: 'saving' | 'saved'; pid: number; at: number }
|
|
158
|
+
export function repairMarkOf(store: FoldedStore): RepairMark | null {
|
|
159
|
+
const row = machineDb((db) => db.query('select value from state where name = ?').get(`${REPAIR_MARK}${store}`) as { value: string } | null)
|
|
160
|
+
return row == null ? null : (JSON.parse(row.value) as RepairMark)
|
|
161
|
+
}
|
|
162
|
+
const alive = (pid: number): boolean => {
|
|
163
|
+
try {
|
|
164
|
+
process.kill(pid, 0)
|
|
165
|
+
return true
|
|
166
|
+
} catch (e) {
|
|
167
|
+
return (e as { code?: string }).code === 'EPERM'
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** what a folded store's old file holds once its tables moved: text, so sqlite refuses it (« file is not a
|
|
172
|
+
* database ») and code that predates the fold fails loud instead of making an empty store there */
|
|
173
|
+
export const TOMBSTONE = 'shipkit: this store moved into the machine db'
|
|
174
|
+
export const tombstoneText = (store: FoldedStore, to: string): string => `${TOMBSTONE} ${to} (sk db fold). The ${store} is never read here again; sk db fold --back puts its copy back.\n`
|
|
175
|
+
|
|
176
|
+
/** the file at `path` is a folded store's tombstone */
|
|
177
|
+
export function isTombstone(path: string): boolean {
|
|
178
|
+
let fd: number | null = null
|
|
179
|
+
try {
|
|
180
|
+
fd = openSync(path, 'r')
|
|
181
|
+
const buf = Buffer.alloc(TOMBSTONE.length)
|
|
182
|
+
return readSync(fd, buf, 0, buf.length, 0) === buf.length && buf.toString('utf8') === TOMBSTONE
|
|
183
|
+
} catch {
|
|
184
|
+
return false
|
|
185
|
+
} finally {
|
|
186
|
+
if (fd != null) closeSync(fd)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** why a folded store's tables may not be opened in the machine db at `path`, null when they may: its old file still
|
|
191
|
+
* holds it, so tables made here would be an empty store beside the live one. A path that is not the machine db (a
|
|
192
|
+
* store moved for one process) is never refused. An old file that does not exist gets its tombstone. An lstat, and a
|
|
193
|
+
* read of a few bytes */
|
|
194
|
+
export function foldRefusal(store: FoldedStore, path: string): string | null {
|
|
195
|
+
const old = oldStorePath(store)
|
|
196
|
+
// a store moved for one process (its variable) is never refused there
|
|
197
|
+
const moved = process.env[STORE_ENV[store]]
|
|
198
|
+
const own = path === old && (moved == null || moved === '')
|
|
199
|
+
if (path !== machineDbPath() && !own) return null
|
|
200
|
+
if (lstatSync(old, { throwIfNoEntry: false }) == null) {
|
|
201
|
+
// a machine that never had the file: its tombstone, so code that predates the fold never makes one there
|
|
202
|
+
try {
|
|
203
|
+
mkdirSync(dirname(old), { recursive: true })
|
|
204
|
+
writeFileSync(old, tombstoneText(store, path), { flag: 'wx', mode: 0o600 })
|
|
205
|
+
} catch {
|
|
206
|
+
// made by another process meanwhile, or a folder that refuses: read below
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// a fold or a way back of this store on the way (home/machine-fold.ts): neither its file nor its tables are whole
|
|
210
|
+
const mark = foldMarkOf(store)
|
|
211
|
+
if (mark != null) {
|
|
212
|
+
if (!alive(mark.pid)) return `a ${mark.way === 'back' ? 'way back' : 'fold'} of the ${store} stopped half way at ${localClock(mark.at)} (pid ${mark.pid} is gone): sk db fold ${mark.way === 'back' ? '--back ' : ''}--go ends it`
|
|
213
|
+
return `${WAIT}a ${mark.way === 'back' ? 'way back' : 'fold'} of the ${store} runs since ${localClock(mark.at)}, ${waitLeft(store, old, mark)}: run it again then`
|
|
214
|
+
}
|
|
215
|
+
const repair = repairMarkOf(store)
|
|
216
|
+
if (repair?.phase === 'saved' || (repair != null && alive(repair.pid))) return alive(repair.pid) ? `${WAIT}a repair of the ${store} runs since ${localClock(repair.at)}: its tables ${repair.tables.join(', ')} are made again; run it again in a minute` : `a repair of the ${store} stopped at ${localClock(repair.at)} (pid ${repair.pid} is gone): sk db repair --go ends it`
|
|
217
|
+
if (own) {
|
|
218
|
+
// its own file, the fold off: read and written there once it has the store's tables
|
|
219
|
+
if (ownShape(store, old) === 'tables') return null
|
|
220
|
+
return `the ${store} is its own file ${old} in the shape of before the fold, and the daemon's fold is off: sk db fold --go folds it, sk db fold --back --go gives its file the tables this code reads`
|
|
221
|
+
}
|
|
222
|
+
if (lstatSync(old, { throwIfNoEntry: false }) == null || isTombstone(old)) return null
|
|
223
|
+
const hurt = machineDb((db) => db.query('select value from state where name = ?').get(`db-fold-damaged:${store}`) as { value: string } | null)
|
|
224
|
+
if (hurt != null) return `the ${store} is still its own file ${old}, and the fold found it damaged at ${new Date((JSON.parse(hurt.value) as { at: number }).at).toLocaleString('sv-SE').slice(0, 16)}: sk db fold says what to do`
|
|
225
|
+
const lock = machineDb((db) => db.query('select value from state where name = ?').get(FOLD_LOCK) as { value: string } | null)
|
|
226
|
+
const walker = lock == null ? null : (JSON.parse(lock.value) as { pid: number }).pid
|
|
227
|
+
if (walker != null && alive(walker)) return `${WAIT}a fold runs (pid ${walker}): the ${store} folds at its turn, run it again in a moment`
|
|
228
|
+
return `the ${store} is still its own file ${old}: \`sk db fold\` moves it into ${path}, until then it is not read`
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** the row of the one walk at a time (home/machine-fold.ts): the pid of the fold or the way back that runs */
|
|
232
|
+
export const FOLD_LOCK = 'db-fold-lock'
|
|
233
|
+
|
|
234
|
+
/** a new file of the machine's: mode 0600 (it holds prompts and commands) and incremental auto vacuum, which must be
|
|
235
|
+
* set before its first table, so a delete gives its pages back in steps and never by a VACUUM of the whole file */
|
|
236
|
+
export function machineFileCreate(path: string, db: Database): void {
|
|
237
|
+
if (db.query("select 1 from sqlite_master where type = 'table' limit 1").get() != null) return
|
|
238
|
+
db.exec('pragma auto_vacuum = incremental')
|
|
239
|
+
for (const f of [path, `${path}-wal`, `${path}-shm`]) try { chmodSync(f, 0o600) } catch { /* not made yet */ }
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** free pages one step of `vacuumSteps` gives back: about 8 MB, a few ms of the write lock */
|
|
243
|
+
export const VACUUM_STEP_PAGES = 2_048
|
|
244
|
+
|
|
245
|
+
/** the free pages of a file of incremental auto vacuum given back to the disk in steps, `between` awaited after each
|
|
246
|
+
* (a loop given back): never a VACUUM, which holds the whole file's write lock for seconds. False, nothing done, for a
|
|
247
|
+
* file of another auto vacuum mode. The longest step's ms */
|
|
248
|
+
export async function vacuumSteps(db: Database, between: () => Promise<void> = async () => {}): Promise<{ pages: number; ms: number } | false> {
|
|
249
|
+
const n = (q: string): number => Number(Object.values(db.query(q).get() as Record<string, number>)[0] ?? 0)
|
|
250
|
+
if (n('pragma auto_vacuum') !== 2) return false
|
|
251
|
+
// a repair cut a table out of this file: its pages are unused and unknown to the page map that a vacuum moves pages
|
|
252
|
+
// by, so nothing is given back until a rebuild writes the file again
|
|
253
|
+
const hasState = db.query("select 1 from sqlite_master where type = 'table' and name = 'state'").get() != null
|
|
254
|
+
if (hasState && db.query('select 1 from state where name = ?').get(REPAIR_UNUSED) != null) return false
|
|
255
|
+
let pages = 0
|
|
256
|
+
let ms = 0
|
|
257
|
+
try {
|
|
258
|
+
for (;;) {
|
|
259
|
+
const free = n('pragma freelist_count')
|
|
260
|
+
if (free === 0) break
|
|
261
|
+
const t = performance.now()
|
|
262
|
+
db.query(`pragma incremental_vacuum(${VACUUM_STEP_PAGES})`).all()
|
|
263
|
+
ms = Math.max(ms, performance.now() - t)
|
|
264
|
+
pages += free - n('pragma freelist_count')
|
|
265
|
+
if (n('pragma freelist_count') >= free) break
|
|
266
|
+
await between()
|
|
267
|
+
}
|
|
268
|
+
} catch (e) {
|
|
269
|
+
if (!/malformed|corrupt/i.test((e as Error).message)) throw e
|
|
270
|
+
// pages it cannot move: given back by a rebuild, never the end of what called it
|
|
271
|
+
if (hasState) db.query('insert or replace into state (name, value, at) values (?, ?, ?)').run(REPAIR_UNUSED, JSON.stringify({ why: (e as Error).message }), Date.now())
|
|
272
|
+
console.error(`WARN ${db.filename}: its free pages are not given back (${(e as Error).message}); sk db rebuild --go, with the home down, writes the file again whole`)
|
|
273
|
+
return false
|
|
274
|
+
}
|
|
275
|
+
return { pages, ms: Math.round(ms) }
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** the row a repair leaves while the pages of the tables it cut are unused: no vacuum runs until a rebuild clears it */
|
|
279
|
+
export const REPAIR_UNUSED = 'db-repair-unused'
|
|
280
|
+
|
|
281
|
+
/** the file made owner only before sqlite opens it */
|
|
282
|
+
export function ownerOnlyFile(path: string): void {
|
|
283
|
+
if (existsSync(path)) return
|
|
35
284
|
try {
|
|
36
285
|
mkdirSync(dirname(path), { recursive: true })
|
|
37
|
-
|
|
286
|
+
closeSync(openSync(path, 'a', 0o600))
|
|
287
|
+
} catch {
|
|
288
|
+
// a path that cannot be made: the open says so
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** a machine write waits this long on another process's */
|
|
293
|
+
const BUSY_MS = 2_000
|
|
294
|
+
|
|
295
|
+
/** v1 is the file with no version: the `state` table alone. v2 adds the backup's two tables: a source is keyed by
|
|
296
|
+
* its path under the home and whether it is a refusal, its absolute path is the home's join (media-store/backup/kept.ts
|
|
297
|
+
* owns what a row means) */
|
|
298
|
+
export const MACHINE_DB_VERSION = 2
|
|
299
|
+
|
|
300
|
+
const SCHEMA = `
|
|
301
|
+
create table if not exists state (name text primary key, value text not null, at integer not null);
|
|
302
|
+
create table if not exists backup_sources (
|
|
303
|
+
rel text not null,
|
|
304
|
+
refused integer not null,
|
|
305
|
+
size integer not null,
|
|
306
|
+
mtime integer not null,
|
|
307
|
+
sqlite text,
|
|
308
|
+
whole integer not null,
|
|
309
|
+
broken text,
|
|
310
|
+
primary key (rel, refused)
|
|
311
|
+
) without rowid;
|
|
312
|
+
create table if not exists backup_seen (
|
|
313
|
+
path text primary key,
|
|
314
|
+
size integer not null,
|
|
315
|
+
mtime integer not null,
|
|
316
|
+
sha text not null,
|
|
317
|
+
key text not null
|
|
318
|
+
) without rowid;
|
|
319
|
+
`
|
|
320
|
+
|
|
321
|
+
const versionOf = (db: Database): number => Number((db.query('pragma user_version').get() as { user_version?: number } | null)?.user_version ?? 0)
|
|
322
|
+
|
|
323
|
+
/** the file to v2, once. A file of no version that holds rows is v1, so migrateTo keeps its copy first */
|
|
324
|
+
function migrate(db: Database): void {
|
|
325
|
+
if (versionOf(db) >= MACHINE_DB_VERSION) return
|
|
326
|
+
if (versionOf(db) === 0 && db.query("select 1 from sqlite_master where type = 'table' and name = 'state'").get() != null && db.query('select 1 from state limit 1').get() != null) db.exec('pragma user_version = 1')
|
|
327
|
+
migrateTo(db, MACHINE_DB_VERSION, () => db.exec(SCHEMA))
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function openMachine(path: string): Database {
|
|
331
|
+
const refused = createRefusal(path)
|
|
332
|
+
if (refused != null) throw new Error(refused)
|
|
333
|
+
ownerOnlyFile(path)
|
|
334
|
+
const db = new Database(path, { create: true, readwrite: true })
|
|
335
|
+
try {
|
|
38
336
|
db.exec(`pragma busy_timeout = ${BUSY_MS}`)
|
|
337
|
+
machineFileCreate(path, db)
|
|
39
338
|
ensureWal(db, BUSY_MS)
|
|
40
|
-
db
|
|
41
|
-
|
|
42
|
-
|
|
339
|
+
storeSync(db, 'FULL')
|
|
340
|
+
migrate(db)
|
|
341
|
+
return db
|
|
342
|
+
} catch (e) {
|
|
343
|
+
db.close()
|
|
344
|
+
throw e
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** the connection a `machineHeld` body shares, by path */
|
|
349
|
+
let held: { path: string; db: Database } | null = null
|
|
350
|
+
|
|
351
|
+
/** every read and write of the machine db inside `body` on ONE connection, opened once and closed at the end: a look
|
|
352
|
+
* that reads and writes a few rows pays one open and one checkpoint, not one per row. Its writes commit without
|
|
353
|
+
* waiting for the disk (WAL, synchronous NORMAL): a power cut can lose the last ones, never the file */
|
|
354
|
+
export async function machineHeld<R>(body: () => Promise<R>): Promise<R> {
|
|
355
|
+
if (held != null) return body()
|
|
356
|
+
const path = machineDbPath()
|
|
357
|
+
const db = openMachine(path)
|
|
358
|
+
storeSync(db, 'NORMAL')
|
|
359
|
+
held = { path, db }
|
|
360
|
+
try {
|
|
361
|
+
return await body()
|
|
362
|
+
} finally {
|
|
363
|
+
held = null
|
|
364
|
+
try { db.close() } catch { /* already gone */ }
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** each failure said once on stderr per process: a read that turns to null or a write to false is never silent */
|
|
369
|
+
const said = new Set<string>()
|
|
370
|
+
function withMachine<R>(body: (db: Database) => R, path = machineDbPath()): R | null {
|
|
371
|
+
try {
|
|
372
|
+
return machineDb(body, path)
|
|
373
|
+
} catch (e) {
|
|
374
|
+
const line = `WARN the machine db ${path}: ${(e as Error).message}`
|
|
375
|
+
if (!said.has(line)) {
|
|
376
|
+
said.add(line)
|
|
377
|
+
process.stderr.write(`${line}\n`)
|
|
378
|
+
}
|
|
43
379
|
return null
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** the machine db open for `body`, closed after; a db that does not open, or a body that throws, THROWS: for a
|
|
384
|
+
* table's reader or writer whose failure must be said, never read as "nothing" */
|
|
385
|
+
export function machineDb<R>(body: (db: Database) => R, path = machineDbPath()): R {
|
|
386
|
+
if (held?.path === path) return body(held.db)
|
|
387
|
+
const db = openMachine(path)
|
|
388
|
+
try {
|
|
389
|
+
return body(db)
|
|
44
390
|
} finally {
|
|
45
|
-
try { db
|
|
391
|
+
try { db.close() } catch { /* already gone */ }
|
|
46
392
|
}
|
|
47
393
|
}
|
|
48
394
|
|
|
@@ -55,9 +401,13 @@ export function machineGet<T>(name: string): T | null {
|
|
|
55
401
|
/** the value, null when no row: a db that does not open THROWS, for a read a write builds on (a busy db read as
|
|
56
402
|
* "nothing" would save one record over all the others) */
|
|
57
403
|
export function machineRead<T>(name: string): T | null {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
404
|
+
let row: { value: string } | null
|
|
405
|
+
try {
|
|
406
|
+
row = machineDb((db) => db.query('select value from state where name = ?').get(name) as { value: string } | null)
|
|
407
|
+
} catch (e) {
|
|
408
|
+
throw new Error(`the machine db does not read: ${name} is not read (${(e as Error).message})`)
|
|
409
|
+
}
|
|
410
|
+
return row == null ? null : (JSON.parse(row.value) as T)
|
|
61
411
|
}
|
|
62
412
|
|
|
63
413
|
export function machineSet(name: string, value: unknown): boolean {
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Where the machine keeps its own state: ONE folder, `~/.shipkit/`, and every path of it comes from machinePath.
|
|
2
|
+
// A machine that has not moved (sk home move) is still read in its old root. This half reads the disk, so it
|
|
3
|
+
// lives apart from core/layout.ts, which cached checks import.
|
|
4
|
+
import { lstatSync, readFileSync, realpathSync, statSync } from 'fs'
|
|
5
|
+
import { homedir } from 'os'
|
|
6
|
+
import { join } from 'path'
|
|
7
|
+
import { SHIPKIT_DIR } from './layout.ts'
|
|
8
|
+
|
|
9
|
+
/** where the machine kept its home and its db before one root: `~/.config/shipkit/` */
|
|
10
|
+
export const OLD_MACHINE_ROOT = join('.config', 'shipkit')
|
|
11
|
+
/** the entries the old root holds: each one stays read there until the machine moves (sk home move) */
|
|
12
|
+
export const OLD_ROOT_ENTRIES: readonly string[] = ['home', 'shipkit.sqlite', 'projects-order.txt']
|
|
13
|
+
|
|
14
|
+
/** where the machine's state is now: `old`, every entry in `~/.config/shipkit`; `moved`, that folder is a link to
|
|
15
|
+
* `~/.shipkit` or is gone; `split`, a move stopped between two entries; `both`, one entry in both places */
|
|
16
|
+
export type MachineRootState = 'old' | 'moved' | 'split' | 'both'
|
|
17
|
+
|
|
18
|
+
/** the move's record (home/home-move.ts writes it first and removes it last, under the new root, which both layouts
|
|
19
|
+
* read): while it exists, each entry it names is where it says */
|
|
20
|
+
export const MOVE_RECORD = 'home-move.json'
|
|
21
|
+
export type MoveRecord = { v: 1; way?: 'go' | 'back'; from?: string; to?: string; mode?: number; at?: number; entries: string[]; moved?: string[]; done: boolean }
|
|
22
|
+
|
|
23
|
+
export const moveRecordPath = (home: string = homedir()): string => join(home, SHIPKIT_DIR, MOVE_RECORD)
|
|
24
|
+
|
|
25
|
+
export function readMoveRecord(home: string = homedir()): MoveRecord | null {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(readFileSync(moveRecordPath(home), 'utf8')) as MoveRecord
|
|
28
|
+
} catch {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** the root a recorded entry is in now: a move that went keeps it new once moved or done, one that goes back keeps
|
|
34
|
+
* it new until moved back */
|
|
35
|
+
const recordedAt = (r: MoveRecord, entry: string): 'old' | 'new' => (r.way === 'back' ? ((r.moved ?? []).includes(entry) ? 'old' : 'new') : r.done || (r.moved ?? []).includes(entry) ? 'new' : 'old')
|
|
36
|
+
|
|
37
|
+
type Place = { old: string; neu: string; oldIsDir: boolean; oldIsLink: boolean; linksHere: boolean }
|
|
38
|
+
|
|
39
|
+
function placeOf(home: string): Place {
|
|
40
|
+
const old = join(home, OLD_MACHINE_ROOT)
|
|
41
|
+
const neu = join(home, SHIPKIT_DIR)
|
|
42
|
+
const l = lstatSync(old, { throwIfNoEntry: false })
|
|
43
|
+
const oldIsLink = l?.isSymbolicLink() === true
|
|
44
|
+
let linksHere = false
|
|
45
|
+
if (oldIsLink) {
|
|
46
|
+
try { linksHere = realpathSync(old) === realpathSync(neu) } catch { linksHere = false }
|
|
47
|
+
}
|
|
48
|
+
// a link the owner made to a folder elsewhere is still the old place: only a link to the new one marks a move
|
|
49
|
+
const oldIsDir = !linksHere && (l?.isDirectory() === true || (oldIsLink && statSync(old, { throwIfNoEntry: false })?.isDirectory() === true))
|
|
50
|
+
return { old, neu, oldIsDir, oldIsLink, linksHere }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** a path under a FILE answers ENOTDIR: absent, never a throw */
|
|
54
|
+
const has = (p: string): boolean => {
|
|
55
|
+
try {
|
|
56
|
+
return lstatSync(p, { throwIfNoEntry: false }) != null
|
|
57
|
+
} catch {
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** where one entry of the old root is read: the old place while the old folder holds it, or holds the others and the
|
|
63
|
+
* new one lacks it; the new place once the old folder is a link to it, is gone, or lacks the entry the new one has */
|
|
64
|
+
function resolveEntry(entry: string, home: string): string {
|
|
65
|
+
const r = readMoveRecord(home)
|
|
66
|
+
if (r != null && r.entries.includes(entry)) return join(home, recordedAt(r, entry) === 'new' ? SHIPKIT_DIR : OLD_MACHINE_ROOT, entry)
|
|
67
|
+
const p = placeOf(home)
|
|
68
|
+
if (!p.oldIsDir) return join(p.neu, entry)
|
|
69
|
+
if (has(join(p.old, entry))) return join(p.old, entry)
|
|
70
|
+
if (has(join(p.neu, entry))) return join(p.neu, entry)
|
|
71
|
+
return join(p.old, entry)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const resolved = new Map<string, string>()
|
|
75
|
+
|
|
76
|
+
/** THE path of one entry of the machine's state, `~/.shipkit/<entry>`: an entry of the old root is resolved once a
|
|
77
|
+
* process (a few lstats), every other one is a join */
|
|
78
|
+
export function machinePath(entry: string, home: string = homedir()): string {
|
|
79
|
+
if (!OLD_ROOT_ENTRIES.includes(entry)) return join(home, SHIPKIT_DIR, entry)
|
|
80
|
+
const k = `${home}\0${entry}`
|
|
81
|
+
let p = resolved.get(k)
|
|
82
|
+
if (p == null) {
|
|
83
|
+
p = resolveEntry(entry, home)
|
|
84
|
+
resolved.set(k, p)
|
|
85
|
+
}
|
|
86
|
+
return p
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** the resolved paths forgotten: the move, and a test that builds a home of its own */
|
|
90
|
+
export const forgetMachinePaths = (): void => resolved.clear()
|
|
91
|
+
|
|
92
|
+
/** where the old root's entries are now, read fresh (no cache) */
|
|
93
|
+
export function machineRootState(home: string = homedir()): { state: MachineRootState; old: string; neu: string; oldHolds: string[]; newHolds: string[]; link: boolean } {
|
|
94
|
+
const p = placeOf(home)
|
|
95
|
+
const oldHolds = p.oldIsDir ? OLD_ROOT_ENTRIES.filter((e) => has(join(p.old, e))) : []
|
|
96
|
+
const newHolds = OLD_ROOT_ENTRIES.filter((e) => has(join(p.neu, e)))
|
|
97
|
+
const state: MachineRootState = !p.oldIsDir ? 'moved' : oldHolds.some((e) => newHolds.includes(e)) ? 'both' : newHolds.length > 0 ? 'split' : 'old'
|
|
98
|
+
return { state, old: p.old, neu: p.neu, oldHolds, newHolds, link: p.linksHere }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** a path under the user home in its one-root form: one under `~/.config/shipkit/<entry>` of an old root entry is
|
|
102
|
+
* named under `~/.shipkit/<entry>`, every other path is itself. Two forms of one file compare equal through it */
|
|
103
|
+
export function oneRootRel(rel: string): string {
|
|
104
|
+
const old = `${OLD_MACHINE_ROOT}/`
|
|
105
|
+
if (!rel.startsWith(old) && rel !== OLD_MACHINE_ROOT) return rel
|
|
106
|
+
const rest = rel.slice(old.length)
|
|
107
|
+
return OLD_ROOT_ENTRIES.includes(rest.split('/')[0] ?? '') ? `${SHIPKIT_DIR}/${rest}` : rel
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** where a file named by its path under the user home is now: one under either root of an old root entry is where
|
|
111
|
+
* that entry is (machinePath), so a backup run of either shape lands on the machine's live state */
|
|
112
|
+
export function livePath(home: string, rel: string): string {
|
|
113
|
+
const one = oneRootRel(rel)
|
|
114
|
+
const parts = one.split('/')
|
|
115
|
+
if (parts[0] === SHIPKIT_DIR && parts.length > 1 && OLD_ROOT_ENTRIES.includes(parts[1]!)) return join(machinePath(parts[1]!, home), ...parts.slice(2))
|
|
116
|
+
return join(home, rel)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** why no store may be CREATED at `path` now, null when it may (or exists already, or lies outside both roots'
|
|
120
|
+
* entries): a move of the machine's state runs (a process that resolved its paths before it would make a second,
|
|
121
|
+
* empty home), or the other root holds the live entry this one lacks. Every store's open asks it first, before it
|
|
122
|
+
* makes the folder: a few lstats and one read, on a create only */
|
|
123
|
+
export function createRefusal(path: string, home: string = homedir()): string | null {
|
|
124
|
+
if (has(path)) return null
|
|
125
|
+
const old = join(home, OLD_MACHINE_ROOT)
|
|
126
|
+
const neu = join(home, SHIPKIT_DIR)
|
|
127
|
+
for (const [root, other] of [[old, neu], [neu, old]] as const) {
|
|
128
|
+
if (!path.startsWith(`${root}/`)) continue
|
|
129
|
+
const entry = path.slice(root.length + 1).split('/')[0]!
|
|
130
|
+
if (!OLD_ROOT_ENTRIES.includes(entry)) return null
|
|
131
|
+
const r = readMoveRecord(home)
|
|
132
|
+
if (r != null && !r.done) return `a move of the machine's state runs (${moveRecordPath(home)}): no store is made under ${root} until it ends`
|
|
133
|
+
if (!has(join(root, entry)) && has(join(other, entry))) return `the live ${entry} is in ${other}, not ${root}: no store is made beside it`
|
|
134
|
+
return null
|
|
135
|
+
}
|
|
136
|
+
return null
|
|
137
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// THIS PROCESS'S READING OF THE MACHINE (the measures: core/machine-busy.ts):
|
|
2
|
+
// the smoothed cores in use a long lived process published, else this
|
|
3
|
+
// process's own window, opened at import.
|
|
4
|
+
//
|
|
5
|
+
// the one constraint a reader breaks first: a window shorter than a reading
|
|
6
|
+
// asks is waited for once per process at most, and never in a long lived one.
|
|
7
|
+
import { readFileSync } from 'fs'
|
|
8
|
+
import { availableParallelism, loadavg } from 'os'
|
|
9
|
+
import { join } from 'path'
|
|
10
|
+
import { homeDir } from '../home/home-paths.ts'
|
|
11
|
+
import { atomicWrite } from './locked-write.ts'
|
|
12
|
+
import { BusyWatch, calmestWindow, type MachineLoad } from './machine-busy.ts'
|
|
13
|
+
|
|
14
|
+
/** `<load1>/<cores>` or `<load1>/<cores>/<busy>` in this variable pins the reading: a test of a verdict must not
|
|
15
|
+
* depend on what else the machine runs. Without the busy part, no CPU reading */
|
|
16
|
+
export const MACHINE_LOAD_ENV = 'SHIPKIT_MACHINE_LOAD'
|
|
17
|
+
|
|
18
|
+
/** a published reading older than this is the past: its writer stopped */
|
|
19
|
+
export const PUBLISHED_FRESH_MS = 15_000
|
|
20
|
+
/** how often a long lived process publishes */
|
|
21
|
+
export const PUBLISH_EVERY_MS = 5_000
|
|
22
|
+
|
|
23
|
+
const publishedFile = (): string | null => {
|
|
24
|
+
try { return join(homeDir(), 'machine-busy.json') } catch { return null }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** the cores in use a long lived process published, while fresh and for these cores */
|
|
28
|
+
export function readPublished(file: string, cores: number, now = Date.now()): number | null {
|
|
29
|
+
try {
|
|
30
|
+
const r = JSON.parse(readFileSync(file, 'utf8')) as { busy?: unknown; cores?: unknown; at?: unknown }
|
|
31
|
+
return typeof r.busy === 'number' && r.cores === cores && typeof r.at === 'number' && now - r.at <= PUBLISHED_FRESH_MS ? r.busy : null
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const cores = availableParallelism()
|
|
38
|
+
/** this process's own watch, its first window opened at import */
|
|
39
|
+
const watch = new BusyWatch({ cores })
|
|
40
|
+
let cached: { busy: number | null; at: number } | null = null
|
|
41
|
+
|
|
42
|
+
/** the smoothed reading of this process's watch, written where every short lived process reads it: a long lived
|
|
43
|
+
* one (the daemon) calls it on PUBLISH_EVERY_MS, so a command reads twenty seconds of the machine, not its own
|
|
44
|
+
* fraction of one */
|
|
45
|
+
export function publishMachine(file = publishedFile()): void {
|
|
46
|
+
const busy = watch.read(0)
|
|
47
|
+
if (file == null || busy == null) return
|
|
48
|
+
try { atomicWrite(file, JSON.stringify({ busy: Math.round(busy * 100) / 100, cores, at: Date.now() })) } catch { /* a read only home: each process reads its own window */ }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** publishes on PUBLISH_EVERY_MS until the function it returns is called */
|
|
52
|
+
export function startPublishing(file = publishedFile()): () => void {
|
|
53
|
+
const t = setInterval(() => publishMachine(file), PUBLISH_EVERY_MS)
|
|
54
|
+
t.unref?.()
|
|
55
|
+
return () => clearInterval(t)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** the machine now. `minMs`: the shortest own window a reading takes when none was published, waited for once
|
|
59
|
+
* per process at most (a verdict asks 400, a hot path keeps the default) */
|
|
60
|
+
/** from this window on a caller asks for a verdict (may a lane start), not a hint in a hot path */
|
|
61
|
+
export const VERDICT_MS = 400
|
|
62
|
+
let verdict: { busy: number | null } | null = null
|
|
63
|
+
|
|
64
|
+
export function machineLoad(minMs = 100): MachineLoad {
|
|
65
|
+
const pinned = process.env[MACHINE_LOAD_ENV]?.match(/^(\d+(?:\.\d+)?)\/(\d+)(?:\/(\d+(?:\.\d+)?))?$/)
|
|
66
|
+
if (pinned != null) return { load1: Number(pinned[1]), cores: Number(pinned[2]), ...(pinned[3] != null ? { busy: Number(pinned[3]) } : {}) }
|
|
67
|
+
const load1 = loadavg()[0] ?? 0
|
|
68
|
+
const now = Date.now()
|
|
69
|
+
if (cached == null || now - cached.at > 1_000) {
|
|
70
|
+
const file = publishedFile()
|
|
71
|
+
cached = { busy: file == null ? null : readPublished(file, cores, now), at: now }
|
|
72
|
+
}
|
|
73
|
+
// a verdict with nothing published: two windows of its own, the calmer one, read once a process
|
|
74
|
+
if (cached.busy == null && minMs >= VERDICT_MS) verdict ??= { busy: calmestWindow({ cores, windowMs: minMs / 2, wait: (ms) => Bun.sleepSync(Math.ceil(ms)) }) }
|
|
75
|
+
let busy = cached.busy ?? verdict?.busy ?? watch.read(minMs)
|
|
76
|
+
if (busy == null && watch.age() < minMs) {
|
|
77
|
+
Bun.sleepSync(Math.ceil(minMs - watch.age()))
|
|
78
|
+
busy = watch.read(minMs)
|
|
79
|
+
}
|
|
80
|
+
return busy == null ? { load1, cores } : { load1, cores, busy }
|
|
81
|
+
}
|