rvlib-shipkit 2.31.0 → 2.33.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 +51 -0
- package/package.json +1 -1
- package/src/advisors/acts.ts +16 -15
- package/src/advisors/advice.ts +56 -102
- package/src/advisors/advisor-view.ts +122 -76
- package/src/advisors/app-graph.ts +1 -1
- package/src/advisors/app.ts +3 -11
- package/src/advisors/cf-api.ts +1 -1
- package/src/advisors/dir-bucket.ts +4 -3
- package/src/advisors/edge/api.ts +20 -221
- package/src/advisors/edge/bucket.ts +2 -2
- package/src/advisors/edge/handler.ts +13 -155
- package/src/advisors/edge/here.ts +5 -5
- package/src/advisors/edge/pages.ts +12 -9
- package/src/advisors/edge/shell.ts +6 -5
- package/src/advisors/edge/sign-in.ts +101 -36
- package/src/advisors/edge/status.ts +19 -6
- package/src/advisors/edge/types.ts +36 -60
- package/src/advisors/expose.ts +29 -29
- package/src/advisors/here.ts +12 -12
- package/src/advisors/invite-send.ts +79 -35
- package/src/advisors/invite.ts +31 -8
- package/src/advisors/job.ts +24 -16
- package/src/advisors/login.ts +40 -15
- package/src/advisors/owner-store.ts +46 -22
- package/src/advisors/photos.ts +3 -3
- package/src/advisors/project.ts +27 -25
- package/src/advisors/reach.ts +89 -0
- package/src/advisors/rights.ts +1 -1
- package/src/advisors/routes.ts +55 -74
- package/src/advisors/scan.ts +0 -4
- package/src/advisors/setup-run.ts +14 -14
- package/src/advisors/share-trace.ts +3 -3
- package/src/advisors/{door-probe.ts → sign-in-probe.ts} +7 -6
- package/src/advisors/speaks.ts +29 -0
- package/src/advisors/sync.ts +97 -183
- package/src/advisors/tunnel.ts +6 -5
- package/src/advisors/users-listen.ts +92 -0
- package/src/advisors/users-router.ts +261 -87
- package/src/advisors/users-store.ts +81 -0
- package/src/agent-time/blocked-scan.ts +181 -0
- package/src/agent-time/registry.ts +12 -5
- package/src/agent-time/store.ts +9 -109
- package/src/asks/ask-bar-fold.ts +2 -1
- package/src/asks/ask-close.ts +2 -1
- package/src/asks/ask-doc.ts +2 -1
- package/src/asks/ask-migrate.ts +3 -2
- package/src/asks/ask-steps-fold.ts +2 -1
- package/src/asks/ask-store.ts +4 -3
- package/src/check.ts +3 -43
- package/src/checks/SK001-package-json-shape.check.ts +4 -55
- package/src/checks/SK004-gitignore-policy.check.ts +24 -69
- package/src/checks/SK013-one-way-in-policy.check.ts +3 -7
- package/src/checks/SK017-vscode-hub-task.check.ts +4 -4
- package/src/checks/SK019-tests-run-in-units.check.ts +3 -14
- package/src/checks/SK020-self-spawning-check.check.ts +5 -7
- package/src/checks/SK035-public-clean.check.ts +1 -1
- package/src/checks/SK039-vscode-watch-generated.check.ts +1 -1
- package/src/checks/SK042-post-kinds.check.ts +5 -14
- package/src/checks/SK054-agent-allow-list.check.ts +5 -74
- package/src/checks/SK055-retired-config-keys.check.ts +45 -0
- package/src/cli/cmd_Advisors.ts +11 -45
- package/src/cli/cmd_Asks.ts +3 -10
- package/src/cli/cmd_Backup.ts +25 -127
- package/src/cli/cmd_BackupTargets.ts +1 -1
- package/src/cli/cmd_Capacity.ts +6 -2
- package/src/cli/cmd_Checks.ts +0 -14
- package/src/cli/cmd_Ci.ts +2 -1
- package/src/cli/cmd_Db.ts +3 -82
- package/src/cli/cmd_Home.ts +4 -32
- package/src/cli/cmd_Hq.ts +0 -17
- package/src/cli/cmd_Releases.ts +57 -4
- package/src/cli/cmd_Review.ts +333 -354
- package/src/cli/cmd_Shot.ts +26 -4
- package/src/cli/cmd_SocialDrafts.ts +6 -13
- package/src/cli/cmd_ThreadSyncNeeds.ts +6 -2
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_Trailer.ts +1 -1
- package/src/cli/inbox-hook-run.ts +5 -23
- package/src/cli/registry-heads.ts +5 -55
- package/src/cli/registry.ts +1 -5
- package/src/cli/review-here.ts +1 -1
- package/src/cli.ts +15 -4
- package/src/collections/collection-types.ts +1 -1
- package/src/collections/review.ts +5 -4
- package/src/core/admission.ts +268 -0
- package/src/core/agent-allow-policy.ts +32 -2
- package/src/core/agent-env.ts +8 -0
- package/src/core/allow-rows.ts +74 -0
- package/src/core/check-file-names.ts +19 -106
- package/src/core/code-lines.ts +36 -21
- package/src/core/footprint.ts +17 -13
- package/src/core/identities-root.ts +1 -4
- package/src/core/layout.ts +1 -2
- package/src/core/machine-db.ts +33 -208
- package/src/core/machine-layout.ts +14 -127
- package/src/core/machine-read.ts +5 -2
- package/src/core/mask-source.ts +60 -0
- package/src/core/memory-watch.ts +17 -14
- package/src/core/motherhome.ts +8 -35
- package/src/core/one-way-in-policy.ts +0 -3
- package/src/core/peer-sk.ts +8 -0
- package/src/core/repo-walk.ts +0 -9
- package/src/core/retention.ts +1 -9
- package/src/core/retired-checks.ts +2 -0
- package/src/core/tmux-policy.ts +1 -1
- package/src/core/tree-watch.ts +2 -2
- package/src/core/when.ts +7 -45
- package/src/gate/admit-heavy.ts +150 -0
- package/src/gate/check-runner.ts +6 -0
- package/src/gate/discover-checks.ts +42 -32
- package/src/gate/gate-checks.ts +21 -131
- package/src/gate/head-gate.ts +1 -1
- package/src/gate/job-run.ts +2 -1
- package/src/gate/pre-commit-discovery.ts +22 -28
- package/src/gate/run-check.ts +3 -4
- package/src/gate/run-ci.ts +4 -0
- package/src/gate/run-fix.ts +5 -17
- package/src/gate/run-fixers.ts +6 -42
- package/src/home/app-sign.ts +2 -2
- package/src/home/backup-status.ts +52 -92
- package/src/home/backup-verdict.ts +2 -2
- package/src/home/daemon-jobs.ts +51 -95
- package/src/home/database-words.ts +1 -2
- package/src/home/databases.ts +9 -25
- package/src/home/home-launchd.ts +0 -6
- package/src/home/home-paths.ts +8 -4
- package/src/home/home-routes.ts +3 -10
- package/src/home/home-state.ts +2 -14
- package/src/home/inbox-shape.ts +14 -15
- package/src/home/inbox.ts +1 -1
- package/src/home/machine-repair.ts +102 -103
- package/src/home/resume.ts +1 -15
- package/src/home/run-daemon.ts +7 -12
- package/src/home/space-page.ts +3 -2
- package/src/home/supervise.ts +3 -7
- package/src/hooks/commit-msg-run.ts +61 -0
- package/src/hooks/commit-run.ts +16 -166
- package/src/hooks/gate-outcome.ts +108 -0
- package/src/hooks/git-hook.ts +9 -9
- package/src/hooks/hook-config.ts +8 -8
- package/src/hooks/leak-guard.ts +1 -1
- package/src/hooks/pre-commit-checks.ts +1 -1
- package/src/hooks/run-hooks.ts +2 -6
- package/src/hooks/shared-file.ts +3 -2
- package/src/hq/daemon-db.ts +8 -8
- package/src/hq/door.ts +3 -16
- package/src/hq/hq-db.ts +4 -3
- package/src/hq/hq-local.ts +1 -2
- package/src/hq/hq-store.ts +0 -15
- package/src/hq/item-direct.ts +8 -10
- package/src/hq/item-fill.ts +37 -0
- package/src/hq/kinds/item-gone.ts +7 -10
- package/src/hq/kinds/item-msg.ts +12 -18
- package/src/hq/kinds/item.ts +13 -19
- package/src/hq/kinds/report.ts +3 -4
- package/src/hq/owner-switch.ts +3 -3
- package/src/hq/report.ts +5 -9
- package/src/hq/switch.ts +2 -11
- package/src/hq/thread-sync.ts +5 -17
- package/src/hq/{shapes-words.ts → threads-words.ts} +2 -12
- package/src/http/owner-word.ts +1 -1
- package/src/identities/machine.ts +16 -0
- package/src/init-repo.ts +0 -1
- package/src/ledger/check-stats.ts +6 -5
- package/src/ledger/db.ts +2 -4
- package/src/ledger/record-kept.ts +117 -48
- package/src/ledger/run-log.ts +21 -2
- package/src/ledger/slow-tests.ts +96 -0
- package/src/ledger/store.ts +3 -86
- package/src/ledger/suite-log.ts +8 -2
- package/src/media-store/backup/facts.ts +3 -37
- package/src/media-store/backup/keys.ts +1 -8
- package/src/media-store/backup/manifest.ts +6 -67
- package/src/media-store/backup/restore.ts +4 -13
- package/src/media-store/backup/retention.ts +13 -1
- package/src/media-store/backup/run.ts +6 -267
- package/src/media-store/backup/snapshot.ts +2 -38
- package/src/media-store/backup/sources.ts +3 -113
- package/src/media-store/backup/target-send.ts +5 -29
- package/src/media-store/db.ts +8 -7
- package/src/media-store/forget-one.ts +1 -1
- package/src/media-store/forget.ts +1 -80
- package/src/orchestrator/guards.ts +0 -1
- package/src/orchestrator/presence.ts +2 -2
- package/src/orchestrator/routes.ts +1 -1
- package/src/orchestrator/started.ts +0 -9
- package/src/orchestrator/talk-key.ts +3 -4
- package/src/orchestrator/unheard.ts +1 -1
- package/src/plan/planner.ts +3 -2
- package/src/recordings/edit.ts +3 -3
- package/src/recordings/marks-draw.ts +17 -6
- package/src/recordings/marks.ts +120 -9
- package/src/reflections/reflections-queue.ts +3 -10
- package/src/release/notes.ts +1 -1
- package/src/release/public-clean.ts +66 -6
- package/src/release/run-bump.ts +11 -0
- package/src/release/run-release.ts +4 -0
- package/src/releases/from-thread.ts +3 -3
- package/src/releases/model.ts +186 -36
- package/src/releases/store.ts +13 -3
- package/src/releases/validate.ts +83 -0
- package/src/repo-config.ts +36 -64
- package/src/review/answer-kinds.ts +63 -4
- package/src/review/blocked-guard.ts +11 -0
- package/src/review/blocked-object.ts +298 -0
- package/src/review/cells.ts +144 -230
- package/src/review/close.ts +39 -1
- package/src/review/doc-save.ts +3 -2
- package/src/review/draft-item.ts +1 -1
- package/src/review/events.ts +3 -7
- package/src/review/expect.ts +23 -39
- package/src/review/format.ts +79 -46
- package/src/review/glyphs.ts +1 -0
- package/src/review/hand-over.ts +3 -3
- package/src/review/heard.ts +1 -1
- package/src/review/holds-sync.ts +2 -1
- package/src/review/inbox-hook.ts +2 -2
- package/src/review/inbox-read.ts +39 -33
- package/src/review/instruction-guards.ts +12 -0
- package/src/review/instructions.ts +0 -1
- package/src/review/item-db.ts +13 -43
- package/src/review/item-hq.ts +2 -2
- package/src/review/item-rows.ts +3 -14
- package/src/review/kind-catalog.ts +3 -1
- package/src/review/kinds.ts +18 -8
- package/src/review/live-view.ts +3 -0
- package/src/review/media-kind.ts +1 -1
- package/src/review/mentions.ts +1 -2
- package/src/review/model.ts +158 -114
- package/src/review/move.ts +149 -0
- package/src/review/need-threads.ts +3 -2
- package/src/review/object-card.ts +11 -0
- package/src/review/object-read.ts +6 -1
- package/src/review/one-block.ts +1 -1
- package/src/review/owner-read.ts +1 -1
- package/src/review/phone-push.ts +10 -9
- package/src/review/previews.ts +32 -4
- package/src/review/push.ts +2 -2
- package/src/review/recap.ts +129 -0
- package/src/review/referring.ts +6 -3
- package/src/review/reflection-object.ts +4 -3
- package/src/review/routes.ts +51 -47
- package/src/review/secret-route.ts +3 -2
- package/src/review/settle.ts +0 -6
- package/src/review/snooze.ts +5 -3
- package/src/review/speaker.ts +68 -0
- package/src/review/start-title.ts +19 -0
- package/src/review/store-parties.ts +28 -0
- package/src/review/store.ts +94 -59
- package/src/review/{wakes.ts → thread-events.ts} +92 -7
- package/src/review/thread-md.ts +35 -14
- package/src/review/thread-state.ts +804 -0
- package/src/review/threads.ts +29 -347
- package/src/review/traces.ts +104 -7
- package/src/review/trailer-item.ts +1 -1
- package/src/review/unit.ts +7 -9
- package/src/review/verdict-items.ts +12 -10
- package/src/review/view-layout.ts +25 -1
- package/src/review/watch-feed.ts +1 -2
- package/src/review/working-guards.ts +2 -3
- package/src/rules/untrack-generated.ts +1 -15
- package/src/secrets/copy.ts +4 -4
- package/src/secrets/lapse.ts +2 -1
- package/src/serve/hub-app/advisor-app.tsx +4 -4
- package/src/serve/hub-app/advisor-face.tsx +9 -3
- package/src/serve/hub-app/advisor-host.ts +27 -27
- package/src/serve/hub-app/advisors-model.ts +17 -8
- package/src/serve/hub-app/advisors-rights.tsx +1 -1
- package/src/serve/hub-app/advisors-st.ts +15 -14
- package/src/serve/hub-app/advisors-view.tsx +13 -11
- package/src/serve/hub-app/app-bridge.ts +23 -3
- package/src/serve/hub-app/asks-page.tsx +1 -1
- package/src/serve/hub-app/auto-text.tsx +71 -16
- package/src/serve/hub-app/check-view.tsx +0 -8
- package/src/serve/hub-app/controls.css +14 -3
- package/src/serve/hub-app/database-view.tsx +1 -2
- package/src/serve/hub-app/dock-st.ts +1 -1
- package/src/serve/hub-app/git-view.tsx +3 -1
- package/src/serve/hub-app/hub.css +12 -5
- package/src/serve/hub-app/icons.tsx +1 -1
- package/src/serve/hub-app/inbox-view.tsx +1 -2
- package/src/serve/hub-app/live-sources.ts +2 -2
- package/src/serve/hub-app/main-panel.tsx +2 -1
- package/src/serve/hub-app/panel-repo.ts +0 -9
- package/src/serve/hub-app/pic.tsx +29 -12
- package/src/serve/hub-app/polled.ts +16 -2
- package/src/serve/hub-app/recordings-st.ts +23 -2
- package/src/serve/hub-app/recordings-view.tsx +68 -10
- package/src/serve/hub-app/ref-pill.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +1 -2
- package/src/serve/hub-app/review/advisor-add.tsx +1 -1
- package/src/serve/hub-app/review/advisor-invite.tsx +1 -1
- package/src/serve/hub-app/review/draft-body.tsx +2 -2
- package/src/serve/hub-app/review/heard-line.tsx +1 -1
- package/src/serve/hub-app/review/instructions-view.tsx +1 -8
- package/src/serve/hub-app/review/kind-states.tsx +14 -9
- package/src/serve/hub-app/review/kit.tsx +4 -11
- package/src/serve/hub-app/review/lane-bar.tsx +3 -3
- package/src/serve/hub-app/review/lightbox.tsx +15 -11
- package/src/serve/hub-app/review/line-window.ts +4 -1
- package/src/serve/hub-app/review/live-bar-st.ts +2 -2
- package/src/serve/hub-app/review/live-view.tsx +57 -1
- package/src/serve/hub-app/review/object-panel.tsx +20 -8
- package/src/serve/hub-app/review/question-views.tsx +191 -53
- package/src/serve/hub-app/review/recap-bar.tsx +40 -0
- package/src/serve/hub-app/review/request-cell.tsx +48 -0
- package/src/serve/hub-app/review/review-cells.tsx +154 -96
- package/src/serve/hub-app/review/review-host.ts +8 -4
- package/src/serve/hub-app/review/review-kit.ts +17 -11
- package/src/serve/hub-app/review/review-list.tsx +30 -35
- package/src/serve/hub-app/review/review-st.ts +32 -42
- package/src/serve/hub-app/review/review-thread.tsx +139 -85
- package/src/serve/hub-app/review/review-views.tsx +127 -68
- package/src/serve/hub-app/review/share-lines.tsx +4 -4
- package/src/serve/hub-app/review/start-st.ts +2 -5
- package/src/serve/hub-app/review/superseded-runs.ts +4 -3
- package/src/serve/hub-app/review/thread-close.tsx +10 -7
- package/src/serve/hub-app/review/thread-st.ts +381 -202
- package/src/serve/hub-app/review/tone-bar.tsx +129 -0
- package/src/serve/hub-app/review/tones.ts +53 -0
- package/src/serve/hub-app/review/trailer-body.tsx +2 -2
- package/src/serve/hub-app/review/trailer-st.ts +3 -2
- package/src/serve/hub-app/review/trailer-voices-st.ts +3 -2
- package/src/serve/hub-app/review.css +189 -106
- package/src/serve/hub-app/search-view.tsx +1 -1
- package/src/serve/hub-app/social/social-model.ts +0 -4
- package/src/serve/hub-app/source-acts.ts +2 -1
- package/src/serve/hub-app/stores/stores-page.tsx +2 -2
- package/src/serve/hub-app/terminal-sources.tsx +2 -1
- package/src/serve/hub-app/thread-row.tsx +3 -4
- package/src/serve/hub-app/tree-build.ts +0 -4
- package/src/serve/hub-app/urls-view.tsx +2 -1
- package/src/serve/hub-app/view-layout.css +13 -3
- package/src/serve/hub-app/wikis-view.tsx +5 -2
- package/src/serve/hub-runtime.ts +7 -37
- package/src/serve/project-gutter-route.ts +6 -2
- package/src/serve/read-thread.ts +20 -2
- package/src/serve/read-worker.ts +9 -1
- package/src/serve/record-pages.ts +46 -0
- package/src/serve/serve-hub.ts +2 -2
- package/src/serve/terminal-host.ts +1 -1
- package/src/serve/terminal-route.ts +1 -3
- package/src/serve/tracked-watch.ts +1 -3
- package/src/setup-house.ts +2 -2
- package/src/shipkit-files.ts +1 -1
- package/src/shipkit.ts +1 -6
- package/src/shot/client.ts +2 -1
- package/src/shot/film-box.ts +0 -20
- package/src/shot/on-place.ts +141 -0
- package/src/social/drafts.ts +1 -1
- package/src/social/kinds.ts +6 -29
- package/src/social/load.ts +2 -2
- package/src/social/post-object.ts +3 -2
- package/src/social/release-stage.ts +1 -1
- package/src/social/stage.ts +2 -2
- package/src/stores/model.ts +4 -0
- package/src/stores/routes.ts +11 -3
- package/src/suite/judge-suites.ts +58 -0
- package/src/suite/red-alone.ts +54 -18
- package/src/suite/runner-shapes.ts +2 -2
- package/src/suite/suite-cli.ts +67 -14
- package/src/suite/test-units.ts +2 -1
- package/src/urls/fill.ts +1 -1
- package/src/urls/places.ts +1 -2
- package/src/vault/vault-config.ts +2 -2
- package/src/vault/vault-init.ts +1 -5
- package/src/wiki/graph-page.ts +14 -2
- package/src/advisors/copy-truth.ts +0 -49
- package/src/advisors/door-child.ts +0 -112
- package/src/advisors/door-serve.ts +0 -52
- package/src/advisors/door.ts +0 -118
- package/src/checks/SK016-legacy-check-shapes.check.ts +0 -189
- package/src/checks/SK029-explicit-check-files.check.ts +0 -112
- package/src/checks/SK048-one-local-file.check.ts +0 -36
- package/src/core/config-rewrite.ts +0 -111
- package/src/core/daemon-port.ts +0 -10
- package/src/core/legacy-shapes.ts +0 -263
- package/src/core/migrate-layout.ts +0 -638
- package/src/core/port-check-cli.ts +0 -52
- package/src/core/port-check-file.ts +0 -295
- package/src/core/port-check-files.ts +0 -31
- package/src/gate/discover-legacy-checks.ts +0 -26
- package/src/home/home-move.ts +0 -527
- package/src/home/machine-fold.ts +0 -810
- package/src/hq/item-shapes.ts +0 -54
- package/src/hq/kinds/items-read.ts +0 -4
- package/src/media-store/backup/daemon.ts +0 -220
- package/src/media-store/backup/kept.ts +0 -241
- package/src/media-store/backup/prune.ts +0 -359
- package/src/media-store/backup/secret.ts +0 -88
- package/src/media-store/backup/ssh-space.ts +0 -202
- package/src/media-store/backup/watch.ts +0 -117
- package/src/review/band.ts +0 -182
- package/src/review/folders.ts +0 -216
- package/src/review/hook-ask.ts +0 -58
- package/src/review/role.ts +0 -48
- package/src/review/thread-fold.ts +0 -64
- package/src/review/wait.ts +0 -91
- package/src/rules/rule.ts +0 -43
- package/src/serve/hook-thread.ts +0 -37
- package/src/serve/hook-work.ts +0 -92
- package/src/serve/hook-worker.ts +0 -57
- package/src/serve/hub-app/review/dock.tsx +0 -147
- package/src/serve/hub-app/review/faces.tsx +0 -18
- package/src/serve/hub-app/review/item-verdict.tsx +0 -112
- package/src/serve/hub-app/review/review-board.tsx +0 -48
- /package/src/{scaffold → core}/jsonc-spans.ts +0 -0
package/src/core/footprint.ts
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
// this process's physical footprint on darwin, the memory Activity Monitor shows and the system charges it: its dirty
|
|
2
2
|
// and swapped pages. The resident size counts the pages bun's allocator freed and gave back as reusable too, which the
|
|
3
3
|
// kernel takes at the first pressure (measured on the daemon: 3.4 GB resident of which 619 MB dirty, footprint 858 MB).
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
4
|
+
// It counts every thread of the process, the read thread's heap included. One proc_pid_rusage call through bun:ffi, a
|
|
5
|
+
// few µs; null where it cannot be read
|
|
6
|
+
const RUSAGE_INFO_V4 = 4
|
|
7
|
+
/** struct rusage_info_v4: uuid[16], then u64 fields; phys_footprint the 8th, lifetime_max_phys_footprint the 29th */
|
|
8
|
+
const V4 = { bytes: 312, footprint: 72, peak: 240 } as const
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
export type Footprint = { now: number; peak: number }
|
|
11
|
+
let read: (() => Footprint) | null | undefined
|
|
11
12
|
|
|
12
|
-
/** the footprint in bytes, null where it cannot be read */
|
|
13
|
-
export function
|
|
13
|
+
/** the footprint in bytes and the highest it reached since the process started, null where it cannot be read */
|
|
14
|
+
export function footprintAndPeak(): Footprint | null {
|
|
14
15
|
if (read === undefined) read = open()
|
|
15
16
|
return read?.() ?? null
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
/** the footprint in bytes, null where it cannot be read */
|
|
20
|
+
export const footprint = (): number | null => footprintAndPeak()?.now ?? null
|
|
21
|
+
|
|
22
|
+
function open(): (() => Footprint) | null {
|
|
19
23
|
if (process.platform !== 'darwin') return null
|
|
20
24
|
try {
|
|
21
25
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
22
26
|
const { dlopen, FFIType, ptr } = require('bun:ffi') as typeof import('bun:ffi')
|
|
23
27
|
const lib = dlopen('/usr/lib/libSystem.B.dylib', { proc_pid_rusage: { args: [FFIType.i32, FFIType.i32, FFIType.ptr], returns: FFIType.i32 } })
|
|
24
|
-
const buf = new BigUint64Array(
|
|
28
|
+
const buf = new BigUint64Array(V4.bytes / 8)
|
|
25
29
|
const view = new DataView(buf.buffer)
|
|
26
|
-
const f = ():
|
|
27
|
-
if (lib.symbols.proc_pid_rusage(process.pid,
|
|
28
|
-
return Number(view.getBigUint64(
|
|
30
|
+
const f = (): Footprint => {
|
|
31
|
+
if (lib.symbols.proc_pid_rusage(process.pid, RUSAGE_INFO_V4, ptr(buf)) !== 0) throw new Error('proc_pid_rusage failed')
|
|
32
|
+
return { now: Number(view.getBigUint64(V4.footprint, true)), peak: Number(view.getBigUint64(V4.peak, true)) }
|
|
29
33
|
}
|
|
30
34
|
f()
|
|
31
35
|
return f
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// the identities folder of a house, the house config read from the disk: the resolver of core/identities-path.ts
|
|
2
2
|
// with its default reader. A check cached on what it reads imports identities-path.ts instead and reads through `c`
|
|
3
3
|
import { readFileSync } from 'node:fs'
|
|
4
|
-
import { identitiesFileBy,
|
|
4
|
+
import { identitiesFileBy, identitiesRootBy, type IdentitiesPath, type ReadText, type RootOpts } from './identities-path.ts'
|
|
5
5
|
|
|
6
6
|
export type { IdentitiesPath } from './identities-path.ts'
|
|
7
7
|
|
|
@@ -15,9 +15,6 @@ const readText: ReadText = (abs) => {
|
|
|
15
15
|
|
|
16
16
|
type DiskOpts = RootOpts & { read?: ReadText }
|
|
17
17
|
|
|
18
|
-
/** the repo that holds the identities folder: the house config's `ownerRepo`, else the house itself */
|
|
19
|
-
export const identitiesRepo = (house: string, o: DiskOpts = {}): string => identitiesRepoBy(house, o.read ?? readText, o)
|
|
20
|
-
|
|
21
18
|
/** the identities folder of a house: `SHIPKIT_IDENTITIES_DIR`, else `<ownerRepo>/wiki/identities`, else
|
|
22
19
|
* `<house>/wiki/identities` */
|
|
23
20
|
export const identitiesRoot = (house: string, o: DiskOpts = {}): string => identitiesRootBy(house, o.read ?? readText, o)
|
package/src/core/layout.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// Where shipkit keeps things inside a repo: ONE folder, `.shipkit/`.
|
|
2
2
|
//
|
|
3
3
|
// Every path a reader or writer needs comes from this table, so a move is one
|
|
4
|
-
// edit here
|
|
5
|
-
// (core/migrate-layout.ts). A repo root holds the project, never the toolkit.
|
|
4
|
+
// edit here. A repo root holds the project, never the toolkit.
|
|
6
5
|
//
|
|
7
6
|
// Git policy lives in the SK004 block: `.shipkit/*` is ignored, and only the
|
|
8
7
|
// TRACKED children below are re-included. A folder nobody listed is local by
|
package/src/core/machine-db.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// THE MACHINE DB: what shipkit remembers about this machine, whatever repo
|
|
2
2
|
// asks, in one sqlite file, the one local file of the machine beside the hq: the
|
|
3
|
-
// media index's tables (`media_*`)
|
|
4
|
-
//
|
|
3
|
+
// media index's tables (`media_*`), the agent time index's (`time_*`) and the
|
|
4
|
+
// daemon's are in it too. Its own: pm's children and resources (their pid records),
|
|
5
5
|
// the repos flagged active, the rail order, the self update answer, the
|
|
6
6
|
// instance registry. A `state` table of named json values, and a table of
|
|
7
7
|
// its own for a value that grows without bound and would be rewritten whole
|
|
@@ -12,19 +12,19 @@
|
|
|
12
12
|
// no replay, the pid rule). Slot LOCKS are not here: they are leases a dead
|
|
13
13
|
// pid must release at once, which a file does and a row does not.
|
|
14
14
|
import { Database } from 'bun:sqlite'
|
|
15
|
-
import { chmodSync, closeSync, existsSync,
|
|
15
|
+
import { chmodSync, closeSync, existsSync, mkdirSync, openSync } from 'fs'
|
|
16
16
|
import { dirname, join } from 'path'
|
|
17
|
-
import {
|
|
17
|
+
import { refuseRealHomeInSuite } from '../home/home-paths.ts'
|
|
18
18
|
import { ensureWal, migrateTo, storeSync } from '../ledger/db.ts'
|
|
19
|
-
import {
|
|
19
|
+
import { machinePath } from './machine-layout.ts'
|
|
20
20
|
import { wroteOnLoop } from './on-loop.ts'
|
|
21
21
|
import { pidAlive as alive } from './pid-alive.ts'
|
|
22
22
|
|
|
23
23
|
export const MACHINE_DB_ENV = 'SHIPKIT_MACHINE_DB'
|
|
24
24
|
export const MACHINE_DB_FILE = 'shipkit.sqlite'
|
|
25
25
|
|
|
26
|
-
/** `~/.shipkit/shipkit.sqlite
|
|
27
|
-
*
|
|
26
|
+
/** `~/.shipkit/shipkit.sqlite`; beside a moved home dir when one is set, so a smoke or a suite with its own home
|
|
27
|
+
* never touches the real one */
|
|
28
28
|
export function machineDbPath(): string {
|
|
29
29
|
const env = process.env[MACHINE_DB_ENV]
|
|
30
30
|
if (env != null && env !== '') return env
|
|
@@ -34,79 +34,15 @@ export function machineDbPath(): string {
|
|
|
34
34
|
return machinePath(MACHINE_DB_FILE)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/** the stores that
|
|
38
|
-
export type
|
|
39
|
-
export const FOLDED_STORES: readonly FoldedStore[] = ['media index', 'agent time index', 'daemon file']
|
|
40
|
-
/** the variable that moves a store for one process: never refused there */
|
|
41
|
-
export const STORE_ENV: Record<FoldedStore, string> = { 'media index': 'SHIPKIT_MEDIA_DB', 'agent time index': 'SHIPKIT_AGENT_TIME_DB', 'daemon file': 'SHIPKIT_DAEMON_DB' }
|
|
37
|
+
/** the stores that are tables of the machine db beside its own state, each a part `sk db repair` names */
|
|
38
|
+
export type MachinePart = 'media index' | 'agent time index' | 'daemon file'
|
|
42
39
|
|
|
43
|
-
/**
|
|
44
|
-
export function oldStorePath(store: FoldedStore): string {
|
|
45
|
-
if (store === 'media index') return join(homeDir(), 'media.sqlite')
|
|
46
|
-
if (store === 'daemon file') return join(homeDir(), 'daemon.sqlite')
|
|
47
|
-
const home = process.env.SHIPKIT_HOME_DIR
|
|
48
|
-
return home != null && home !== '' ? join(home, 'agent-time.sqlite') : machinePath('agent-time.sqlite')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** each folded store's table prefix in the machine db: its file of its own has the same tables after a way back */
|
|
52
|
-
export const STORE_PREFIX: Record<FoldedStore, string> = { 'media index': 'media_', 'agent time index': 'time_', 'daemon file': '' }
|
|
53
|
-
// the daemon's tables keep their names (outbox, review_cards, ...): none is a name of the machine db's own, and its
|
|
54
|
-
// own file has one shape before and after a fold
|
|
55
|
-
|
|
56
|
-
/** the switch of the daemon's fold (home/machine-fold.ts, hq/switch.ts): off, a store not folded is read and written
|
|
57
|
-
* in its own file. A machine db that does not read THROWS */
|
|
58
|
-
export const FOLD_AUTO = 'db-fold-auto'
|
|
59
|
-
export const foldAutoOn = (): boolean => machineRead<boolean>(FOLD_AUTO) !== false
|
|
60
|
-
|
|
61
|
-
/** the shape of a store's own file: `tables`, the machine db's tables (`media_files`, written by a way back), `old`,
|
|
62
|
-
* the names of before the fold (`files`), null when no sqlite file is there (none, or a tombstone) */
|
|
63
|
-
export function ownShape(store: FoldedStore, old = oldStorePath(store)): 'tables' | 'old' | null {
|
|
64
|
-
if (lstatSync(old, { throwIfNoEntry: false }) == null || isTombstone(old)) return null
|
|
65
|
-
let db: Database | null = null
|
|
66
|
-
try {
|
|
67
|
-
// read write and never made: a read only open of a WAL file with no shared memory beside it fails
|
|
68
|
-
db = new Database(old, { readwrite: true, create: false })
|
|
69
|
-
db.exec('pragma busy_timeout = 3000')
|
|
70
|
-
const names = (db.query("select name from sqlite_master where type = 'table'").all() as { name: string }[]).map((r) => r.name)
|
|
71
|
-
return STORE_PREFIX[store] === '' || names.some((n) => n.startsWith(STORE_PREFIX[store])) ? 'tables' : 'old'
|
|
72
|
-
} catch {
|
|
73
|
-
return 'old'
|
|
74
|
-
} finally {
|
|
75
|
-
db?.close()
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** where this machine keeps a store: the machine db, or, while the store is not folded, its own file when the fold is
|
|
80
|
-
* off or the file has the tables this code reads (a fold of several stores leaves each in its file until its turn).
|
|
81
|
-
* One branch, at the place a store is opened: its readers and writers use the same tables in both */
|
|
82
|
-
export function storeHome(store: FoldedStore, now = Date.now()): string {
|
|
83
|
-
const old = oldStorePath(store)
|
|
84
|
-
const machine = machineDbPath()
|
|
85
|
-
const kept = homes.get(store)
|
|
86
|
-
// a process asks at every read and write of its store: the answer holds a second, as the switch of the items does
|
|
87
|
-
if (kept != null && kept.old === old && kept.machine === machine && now - kept.at < HOME_EVERY_MS) return kept.home
|
|
88
|
-
const home = lstatSync(old, { throwIfNoEntry: false }) != null && !isTombstone(old) && (!foldAutoOn() || ownShape(store, old) === 'tables') ? old : machine
|
|
89
|
-
homes.set(store, { old, machine, home, at: now })
|
|
90
|
-
return home
|
|
91
|
-
}
|
|
92
|
-
const HOME_EVERY_MS = 1000
|
|
93
|
-
const homes = new Map<FoldedStore, { old: string; machine: string; home: string; at: number }>()
|
|
94
|
-
/** this process reads where its stores are again at once: a fold or a way back of its own just moved them */
|
|
95
|
-
export const forgetStoreHomes = (): void => homes.clear()
|
|
96
|
-
|
|
97
|
-
/** the mark a fold or a way back sets on a store while it walks (`<FOLD_MARK><store>` in `state`) */
|
|
98
|
-
export const FOLD_MARK = 'db-fold-partial:'
|
|
99
|
-
export type FoldMark = { way: 'go' | 'back'; pid: number; at: number }
|
|
100
|
-
export function foldMarkOf(store: FoldedStore): FoldMark | null {
|
|
101
|
-
const row = machineDb((db) => db.query('select value from state where name = ?').get(`${FOLD_MARK}${store}`) as { value: string } | null)
|
|
102
|
-
return row == null ? null : (JSON.parse(row.value) as FoldMark)
|
|
103
|
-
}
|
|
104
|
-
/** 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 */
|
|
40
|
+
/** the head of a refusal that ends by itself: a repair at work. `sk time` exits WAIT_EXIT on it */
|
|
105
41
|
const WAIT = 'wait: '
|
|
106
42
|
export const WAIT_EXIT = 75
|
|
107
43
|
export const isWaitRefusal = (msg: string): boolean => msg.startsWith(WAIT)
|
|
108
44
|
export const refusalText = (msg: string): string => (isWaitRefusal(msg) ? msg.slice(WAIT.length) : msg)
|
|
109
|
-
/** a store's open refused: its words, and whether it ends by itself (a
|
|
45
|
+
/** a store's open refused: its words, and whether it ends by itself (a repair at work) */
|
|
110
46
|
export class StoreRefused extends Error {
|
|
111
47
|
override readonly name = 'StoreRefused'
|
|
112
48
|
readonly wait: boolean
|
|
@@ -117,114 +53,32 @@ export class StoreRefused extends Error {
|
|
|
117
53
|
}
|
|
118
54
|
/** a StoreRefused by its name: a process may hold two copies of this module (the daemon's hubs load the lib again) */
|
|
119
55
|
export const isStoreRefused = (e: unknown): e is StoreRefused => e instanceof Error && e.name === 'StoreRefused'
|
|
120
|
-
/** a refusal that ends once what it names ends: `sk time`, `sk db fold` exit WAIT_EXIT on it */
|
|
121
|
-
export const waitRefused = (text: string): StoreRefused => new StoreRefused(`${WAIT}${text}`)
|
|
122
56
|
/** a time of today as the owner's clock says it, the day before it when it is not today */
|
|
123
57
|
const localClock = (at: number): string => {
|
|
124
58
|
const d = new Date(at)
|
|
125
59
|
const day = d.toLocaleDateString('sv-SE')
|
|
126
60
|
return `${day === new Date().toLocaleDateString('sv-SE') ? '' : `${day} `}${d.toLocaleTimeString('sv-SE')}`
|
|
127
61
|
}
|
|
128
|
-
/** how long the last walk of a store took on this machine, by its way (`<store>:<go|back>`): `{ ms, bytes }`, the size
|
|
129
|
-
* of its file then */
|
|
130
|
-
export const WALK_TOOK = 'db-walk-took:'
|
|
131
|
-
/** the size a walk of a store moves: its file under the fold's name, its own file, else the fold's copy */
|
|
132
|
-
export function walkBytes(old: string): number {
|
|
133
|
-
for (const f of [`${old}.fold-src`, old, `${old}.before-fold`]) {
|
|
134
|
-
try {
|
|
135
|
-
const st = statSync(f)
|
|
136
|
-
if (st.size > 4096) return st.size
|
|
137
|
-
} catch { /* not there */ }
|
|
138
|
-
}
|
|
139
|
-
return 0
|
|
140
|
-
}
|
|
141
|
-
/** 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
|
|
142
|
-
* from its size (about 8 MB a second on a loaded Mac: 401 MB in 47 s, measured) */
|
|
143
|
-
function waitLeft(store: FoldedStore, old: string, mark: FoldMark): string {
|
|
144
|
-
const bytes = walkBytes(old)
|
|
145
|
-
const gone = (Date.now() - mark.at) / 1000
|
|
146
|
-
const row = machineDb((db) => db.query('select value from state where name = ?').get(`${WALK_TOOK}${store}:${mark.way}`) as { value: string } | null)
|
|
147
|
-
const last = row == null ? null : (JSON.parse(row.value) as { ms: number; bytes: number })
|
|
148
|
-
const word = mark.way === 'back' ? 'way back' : 'fold'
|
|
149
|
-
if (last != null && last.ms > 0) {
|
|
150
|
-
const took = (last.ms / 1000) * (last.bytes > 0 && bytes > 0 ? bytes / last.bytes : 1)
|
|
151
|
-
return `about ${Math.max(1, Math.round(took - gone))} s left (its last ${word} here took ${(last.ms / 1000).toFixed(1)} s)`
|
|
152
|
-
}
|
|
153
|
-
return `under ${Math.max(1, Math.ceil(bytes / 8e6 + 5 - gone))} s left (a bound by its size)`
|
|
154
|
-
}
|
|
155
62
|
|
|
156
|
-
/** the mark of a repair of a
|
|
63
|
+
/** the mark of a repair of a part's damaged tables (home/machine-repair.ts): `saving` while their rows go aside, `saved`
|
|
157
64
|
* once all are there and the tables may be made again */
|
|
158
|
-
export const REPAIR_MARK = 'db-
|
|
65
|
+
export const REPAIR_MARK = 'db-repair:'
|
|
159
66
|
export type RepairMark = { tables: string[]; phase: 'saving' | 'saved'; pid: number; at: number }
|
|
160
|
-
export function repairMarkOf(store:
|
|
67
|
+
export function repairMarkOf(store: MachinePart): RepairMark | null {
|
|
161
68
|
const row = machineDb((db) => db.query('select value from state where name = ?').get(`${REPAIR_MARK}${store}`) as { value: string } | null)
|
|
162
69
|
return row == null ? null : (JSON.parse(row.value) as RepairMark)
|
|
163
70
|
}
|
|
164
71
|
|
|
165
|
-
/**
|
|
166
|
-
*
|
|
167
|
-
export
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
/** the file at `path` is a folded store's tombstone */
|
|
171
|
-
export function isTombstone(path: string): boolean {
|
|
172
|
-
let fd: number | null = null
|
|
173
|
-
try {
|
|
174
|
-
fd = openSync(path, 'r')
|
|
175
|
-
const buf = Buffer.alloc(TOMBSTONE.length)
|
|
176
|
-
return readSync(fd, buf, 0, buf.length, 0) === buf.length && buf.toString('utf8') === TOMBSTONE
|
|
177
|
-
} catch {
|
|
178
|
-
return false
|
|
179
|
-
} finally {
|
|
180
|
-
if (fd != null) closeSync(fd)
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/** why a folded store's tables may not be opened in the machine db at `path`, null when they may: its old file still
|
|
185
|
-
* holds it, so tables made here would be an empty store beside the live one. A path that is not the machine db (a
|
|
186
|
-
* store moved for one process) is never refused. An old file that does not exist gets its tombstone. An lstat, and a
|
|
187
|
-
* read of a few bytes */
|
|
188
|
-
export function foldRefusal(store: FoldedStore, path: string): string | null {
|
|
189
|
-
const old = oldStorePath(store)
|
|
190
|
-
// a store moved for one process (its variable) is never refused there
|
|
191
|
-
const moved = process.env[STORE_ENV[store]]
|
|
192
|
-
const own = path === old && (moved == null || moved === '')
|
|
193
|
-
if (path !== machineDbPath() && !own) return null
|
|
194
|
-
if (lstatSync(old, { throwIfNoEntry: false }) == null) {
|
|
195
|
-
// a machine that never had the file: its tombstone, so code that predates the fold never makes one there
|
|
196
|
-
try {
|
|
197
|
-
mkdirSync(dirname(old), { recursive: true })
|
|
198
|
-
writeFileSync(old, tombstoneText(store, path), { flag: 'wx', mode: 0o600 })
|
|
199
|
-
} catch {
|
|
200
|
-
// made by another process meanwhile, or a folder that refuses: read below
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
// a fold or a way back of this store on the way (home/machine-fold.ts): neither its file nor its tables are whole
|
|
204
|
-
const mark = foldMarkOf(store)
|
|
205
|
-
if (mark != null) {
|
|
206
|
-
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`
|
|
207
|
-
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`
|
|
208
|
-
}
|
|
72
|
+
/** why a part's tables may not be opened at `path`, null when they may: a repair of them at work, or one that stopped
|
|
73
|
+
* after it saved their rows. A path that is not the machine db (a store moved for one process) is never refused */
|
|
74
|
+
export function storeRefusal(store: MachinePart, path: string): string | null {
|
|
75
|
+
if (path !== machineDbPath()) return null
|
|
209
76
|
const repair = repairMarkOf(store)
|
|
210
|
-
if (repair
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
if (ownShape(store, old) === 'tables') return null
|
|
214
|
-
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`
|
|
215
|
-
}
|
|
216
|
-
if (lstatSync(old, { throwIfNoEntry: false }) == null || isTombstone(old)) return null
|
|
217
|
-
const hurt = machineDb((db) => db.query('select value from state where name = ?').get(`db-fold-damaged:${store}`) as { value: string } | null)
|
|
218
|
-
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`
|
|
219
|
-
const lock = machineDb((db) => db.query('select value from state where name = ?').get(FOLD_LOCK) as { value: string } | null)
|
|
220
|
-
const walker = lock == null ? null : (JSON.parse(lock.value) as { pid: number }).pid
|
|
221
|
-
if (walker != null && alive(walker)) return `${WAIT}a fold runs (pid ${walker}): the ${store} folds at its turn, run it again in a moment`
|
|
222
|
-
return `the ${store} is still its own file ${old}: \`sk db fold\` moves it into ${path}, until then it is not read`
|
|
77
|
+
if (repair == null) return null
|
|
78
|
+
if (alive(repair.pid)) return `${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`
|
|
79
|
+
return repair.phase === 'saved' ? `a repair of the ${store} stopped at ${localClock(repair.at)} (pid ${repair.pid} is gone): sk db repair --go ends it` : null
|
|
223
80
|
}
|
|
224
81
|
|
|
225
|
-
/** the row of the one walk at a time (home/machine-fold.ts): the pid of the fold or the way back that runs */
|
|
226
|
-
export const FOLD_LOCK = 'db-fold-lock'
|
|
227
|
-
|
|
228
82
|
/** a new file of the machine's: mode 0600 (it holds prompts and commands) and incremental auto vacuum, which must be
|
|
229
83
|
* set before its first table, so a delete gives its pages back in steps and never by a VACUUM of the whole file */
|
|
230
84
|
export function machineFileCreate(path: string, db: Database): void {
|
|
@@ -283,35 +137,17 @@ export function ownerOnlyFile(path: string): void {
|
|
|
283
137
|
}
|
|
284
138
|
}
|
|
285
139
|
|
|
286
|
-
/** how long a write to the machine db, or to a store
|
|
287
|
-
* value for all of them, long enough for any one step of a
|
|
140
|
+
/** how long a write to the machine db, or to a store in it, waits on another process's transaction: one
|
|
141
|
+
* value for all of them, long enough for any one step of a repair, an index pass or a flush, short enough that a loop
|
|
288
142
|
* that writes never stands still long */
|
|
289
143
|
export const MACHINE_BUSY_MS = 5_000
|
|
290
144
|
|
|
291
|
-
/** v1 is the file with no version: the `state` table alone. v2
|
|
292
|
-
*
|
|
293
|
-
* owns what a row means) */
|
|
145
|
+
/** v1 is the file with no version: the `state` table alone. v2 added the retired backup's two tables
|
|
146
|
+
* (`backup_sources`, `backup_seen`): nothing reads or makes them now, a file that holds them keeps them */
|
|
294
147
|
export const MACHINE_DB_VERSION = 2
|
|
295
148
|
|
|
296
149
|
const SCHEMA = `
|
|
297
150
|
create table if not exists state (name text primary key, value text not null, at integer not null);
|
|
298
|
-
create table if not exists backup_sources (
|
|
299
|
-
rel text not null,
|
|
300
|
-
refused integer not null,
|
|
301
|
-
size integer not null,
|
|
302
|
-
mtime integer not null,
|
|
303
|
-
sqlite text,
|
|
304
|
-
whole integer not null,
|
|
305
|
-
broken text,
|
|
306
|
-
primary key (rel, refused)
|
|
307
|
-
) without rowid;
|
|
308
|
-
create table if not exists backup_seen (
|
|
309
|
-
path text primary key,
|
|
310
|
-
size integer not null,
|
|
311
|
-
mtime integer not null,
|
|
312
|
-
sha text not null,
|
|
313
|
-
key text not null
|
|
314
|
-
) without rowid;
|
|
315
151
|
`
|
|
316
152
|
|
|
317
153
|
const versionOf = (db: Database): number => Number((db.query('pragma user_version').get() as { user_version?: number } | null)?.user_version ?? 0)
|
|
@@ -323,13 +159,13 @@ function migrate(db: Database): void {
|
|
|
323
159
|
migrateTo(db, MACHINE_DB_VERSION, () => db.exec(SCHEMA))
|
|
324
160
|
}
|
|
325
161
|
|
|
326
|
-
/** THE open of the machine db and of every store
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
export function openMachineFile(path: string, o: { store?:
|
|
162
|
+
/** THE open of the machine db and of every store in it (the media index, the agent time index, the daemon file),
|
|
163
|
+
* or of a file a suite moved a store to: one busy timeout, one synchronous level, WAL, the owner's only mode, then
|
|
164
|
+
* `schema`. FULL: a commit that returned is on the disk, the owner's threads among them; measured 0.1 to 0.2 ms more a
|
|
165
|
+
* commit than NORMAL. `store` adds that store's refusal while a repair holds it; `readonly` is a look that makes
|
|
166
|
+
* nothing. Throws why it does not open. A test pins that no other code opens these files
|
|
167
|
+
* (tests/machine-db-opener.test.ts) */
|
|
168
|
+
export function openMachineFile(path: string, o: { store?: MachinePart; schema?: (db: Database) => void; readonly?: boolean } = {}): Database {
|
|
333
169
|
if (o.readonly === true) {
|
|
334
170
|
const peek = new Database(path, { readonly: true })
|
|
335
171
|
try {
|
|
@@ -340,7 +176,7 @@ export function openMachineFile(path: string, o: { store?: FoldedStore; schema?:
|
|
|
340
176
|
throw e
|
|
341
177
|
}
|
|
342
178
|
}
|
|
343
|
-
const refused =
|
|
179
|
+
const refused = o.store == null ? null : storeRefusal(o.store, path)
|
|
344
180
|
if (refused != null) throw new StoreRefused(refused)
|
|
345
181
|
ownerOnlyFile(path)
|
|
346
182
|
const db = new Database(path, { create: true, readwrite: true })
|
|
@@ -463,14 +299,3 @@ export function machineList<T>(prefix: string): { name: string; value: T; at: nu
|
|
|
463
299
|
try { return [{ name: r.name, value: JSON.parse(r.value) as T, at: r.at }] } catch { return [] }
|
|
464
300
|
})
|
|
465
301
|
}
|
|
466
|
-
|
|
467
|
-
/** the migration of one json file: its value becomes the row, then the file
|
|
468
|
-
* goes. Only when the row does not exist yet, so a file an older copy wrote
|
|
469
|
-
* after the move never overwrites a newer row */
|
|
470
|
-
export function importMachineFile<T>(name: string, file: string, parse: (text: string) => T = (t) => JSON.parse(t) as T): void {
|
|
471
|
-
if (!existsSync(file)) return
|
|
472
|
-
try {
|
|
473
|
-
if (machineGet(name) == null) machineSet(name, parse(readFileSync(file, 'utf8')))
|
|
474
|
-
rmSync(file, { force: true })
|
|
475
|
-
} catch { /* an unreadable file is left for a person to look at */ }
|
|
476
|
-
}
|
|
@@ -1,137 +1,24 @@
|
|
|
1
1
|
// Where the machine keeps its own state: ONE folder, `~/.shipkit/`, and every path of it comes from machinePath.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
import { lstatSync, readFileSync, realpathSync, statSync } from 'fs'
|
|
2
|
+
// `~/.config/shipkit` is a link to it, kept for the paths written before one root (the vault's among them): nothing
|
|
3
|
+
// here reads, writes or removes that link
|
|
5
4
|
import { homedir } from 'os'
|
|
6
5
|
import { join } from 'path'
|
|
7
6
|
import { SHIPKIT_DIR } from './layout.ts'
|
|
8
7
|
|
|
9
|
-
/** where the machine kept its
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export const OLD_ROOT_ENTRIES: readonly string[] = ['home', 'shipkit.sqlite', 'projects-order.txt']
|
|
8
|
+
/** where the machine kept its state before one root, a link to `~/.shipkit` since: a backup run of then names its
|
|
9
|
+
* files under it */
|
|
10
|
+
const OLD_MACHINE_ROOT = join('.config', 'shipkit')
|
|
13
11
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
export type MachineRootState = 'old' | 'moved' | 'split' | 'both'
|
|
12
|
+
/** THE path of one entry of the machine's state, `~/.shipkit/<entry>` */
|
|
13
|
+
export const machinePath = (entry: string, home: string = homedir()): string => join(home, SHIPKIT_DIR, entry)
|
|
17
14
|
|
|
18
|
-
/** the
|
|
19
|
-
*
|
|
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 */
|
|
15
|
+
/** a path under the user home in its one root form: one under `~/.config/shipkit/` is named under `~/.shipkit/`, the
|
|
16
|
+
* folder that link names, every other path is itself. Two forms of one file compare equal through it */
|
|
103
17
|
export function oneRootRel(rel: string): string {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const rest = rel.slice(old.length)
|
|
107
|
-
return OLD_ROOT_ENTRIES.includes(rest.split('/')[0] ?? '') ? `${SHIPKIT_DIR}/${rest}` : rel
|
|
18
|
+
if (rel === OLD_MACHINE_ROOT) return SHIPKIT_DIR
|
|
19
|
+
return rel.startsWith(`${OLD_MACHINE_ROOT}/`) ? `${SHIPKIT_DIR}/${rel.slice(OLD_MACHINE_ROOT.length + 1)}` : rel
|
|
108
20
|
}
|
|
109
21
|
|
|
110
|
-
/** where a file named by its path under the user home is now:
|
|
111
|
-
*
|
|
112
|
-
export
|
|
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
|
-
}
|
|
22
|
+
/** where a file named by its path under the user home is now: a backup run of either root's form lands on the
|
|
23
|
+
* machine's live state under `~/.shipkit` */
|
|
24
|
+
export const livePath = (home: string, rel: string): string => join(home, oneRootRel(rel))
|
package/src/core/machine-read.ts
CHANGED
|
@@ -20,10 +20,13 @@ export const PUBLISHED_FRESH_MS = 15_000
|
|
|
20
20
|
/** how often a long lived process publishes */
|
|
21
21
|
export const PUBLISH_EVERY_MS = 5_000
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/** a small file of the machine's state in the home dir, or null where there is none */
|
|
24
|
+
export const homeStateFile = (name: string): string | null => {
|
|
25
|
+
try { return join(homeDir(), name) } catch { return null }
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
const publishedFile = (): string | null => homeStateFile('machine-busy.json')
|
|
29
|
+
|
|
27
30
|
/** the cores in use a long lived process published, while fresh and for these cores */
|
|
28
31
|
export function readPublished(file: string, cores: number, now = Date.now()): number | null {
|
|
29
32
|
try {
|