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
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// one object of the Space as a node put it (wiki tools/shipkit/media-store.md): its key, its size, its repo, the name
|
|
2
|
+
// of its file, when it was seen up. Rows go up only: a machine asks the hq for a key it does not know (a file another
|
|
3
|
+
// machine put), never a feed. Stored by key and node, so two machines that put one file are one object and two rows.
|
|
4
|
+
// The one constraint a reader breaks first: a row is what a node SAYS, so the hq is never proof that the Space holds
|
|
5
|
+
// it: a purge asks the Space itself, a fetch back checks the sha
|
|
6
|
+
import type { Database } from 'bun:sqlite'
|
|
7
|
+
import { shaOfKey } from '../../media-store/content.ts'
|
|
8
|
+
import { isRepoId } from './card-msg.ts'
|
|
9
|
+
import { kind, type Lack, type ReadQuery } from './kind.ts'
|
|
10
|
+
|
|
11
|
+
export type MediaBody = { key: string; sha: string; size: number; label: string; repo: string; name: string; at: number }
|
|
12
|
+
|
|
13
|
+
/** the objects one node may say: this Mac's index held 91,125 on 2026-11-18 */
|
|
14
|
+
export const NODE_MAX_MEDIA = 150_000
|
|
15
|
+
/** and their bytes, as the file spends them: 159 B a row measured, so 91,125 rows are 14.5 MB. Two nodes at every
|
|
16
|
+
* kind's share fit under the hq's cap with 24 MB here, not 30 */
|
|
17
|
+
export const NODE_MAX_MEDIA_BYTES = 24 * 1024 * 1024
|
|
18
|
+
/** the earliest time a row can have: 2025-01-01 */
|
|
19
|
+
export const MEDIA_EPOCH = Date.UTC(2025, 0, 1)
|
|
20
|
+
/** the rows one read gives */
|
|
21
|
+
export const MEDIA_READ_MAX = 200
|
|
22
|
+
|
|
23
|
+
/** a content key: a label (or `public/<label>`), the sha, and the extensions of the file or its preview */
|
|
24
|
+
export const MEDIA_KEY_RE = /^(?:public\/)?[a-z0-9-]{1,40}\/[0-9a-f]{64}(?:\.[a-z0-9]{1,12}){0,3}$/
|
|
25
|
+
const SHA_PART_RE = /^[0-9a-f]{12,64}$/
|
|
26
|
+
|
|
27
|
+
export const labelOfKey = (key: string): string => key.slice(0, key.lastIndexOf('/'))
|
|
28
|
+
|
|
29
|
+
const isObj = (v: unknown): v is Record<string, unknown> => v != null && typeof v === 'object' && !Array.isArray(v)
|
|
30
|
+
const whole = (v: unknown): v is number => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0
|
|
31
|
+
/** a file's own name: no folder, no control character, never `.` or `..` */
|
|
32
|
+
const isFileName = (v: unknown): v is string => typeof v === 'string' && v.length <= 255 && !/[/\\\0-\x1f]/.test(v) && v !== '.' && v !== '..'
|
|
33
|
+
|
|
34
|
+
export const isMediaBody = (v: unknown): v is MediaBody =>
|
|
35
|
+
isObj(v) &&
|
|
36
|
+
typeof v['key'] === 'string' &&
|
|
37
|
+
MEDIA_KEY_RE.test(v['key']) &&
|
|
38
|
+
v['sha'] === shaOfKey(v['key']) &&
|
|
39
|
+
v['label'] === labelOfKey(v['key']) &&
|
|
40
|
+
whole(v['size']) &&
|
|
41
|
+
v['size'] <= 1e12 &&
|
|
42
|
+
(v['repo'] === '' || isRepoId(v['repo'])) &&
|
|
43
|
+
isFileName(v['name']) &&
|
|
44
|
+
whole(v['at']) &&
|
|
45
|
+
v['at'] >= MEDIA_EPOCH
|
|
46
|
+
|
|
47
|
+
// what a row costs the hq's file, measured on 91,125 rows of the usual shape (within 5 % over): the share of a node
|
|
48
|
+
// means file, not text
|
|
49
|
+
const ROW_BYTES_SQL = 'cast((length(key) + length(node) + length(cast(repo as blob)) + length(cast(name as blob)) + 22) * 1.2 as integer)'
|
|
50
|
+
const rowBytes = (b: MediaBody, node: string): number => Math.trunc((b.key.length + node.length + Buffer.byteLength(b.repo) + Buffer.byteLength(b.name) + 22) * 1.2)
|
|
51
|
+
|
|
52
|
+
type Row = { key: string; node: string; size: number; repo: string; name: string; at: number }
|
|
53
|
+
const COLS = 'key, node, size, repo, name, at'
|
|
54
|
+
|
|
55
|
+
const repoWhere = (repos: readonly string[] | null): { sql: string; args: string[] } => (repos == null ? { sql: '', args: [] } : { sql: ` and repo in (${repos.map(() => '?').join(',')})`, args: [...repos] })
|
|
56
|
+
|
|
57
|
+
/** the rows a reference names in those repos: a key, or a sha whole or its first 12 hex or more */
|
|
58
|
+
export function findMedia(db: Database, ref: string, repos: readonly string[] | null, limit = MEDIA_READ_MAX): Row[] {
|
|
59
|
+
const r = repoWhere(repos)
|
|
60
|
+
if (MEDIA_KEY_RE.test(ref)) return db.query(`select ${COLS} from media where key = ?${r.sql} order by at, node limit ?`).all(ref, ...r.args, limit) as Row[]
|
|
61
|
+
if (!SHA_PART_RE.test(ref)) return []
|
|
62
|
+
// a sha is inside the key, after its label: one scan, asked by a person, never on a page's path
|
|
63
|
+
return (db.query(`select ${COLS} from media where instr(key, ?) > 0${r.sql} order by key, at, node limit ?`).all(`/${ref}`, ...r.args, limit * 4) as Row[]).filter((x) => shaOfKey(x.key)?.startsWith(ref)).slice(0, limit)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const mediaKind = kind<MediaBody>({
|
|
67
|
+
kind: 'media',
|
|
68
|
+
schema: `
|
|
69
|
+
create table if not exists media (key text not null, node text not null, size integer not null, repo text not null, name text not null, at integer not null, primary key (key, node)) without rowid;
|
|
70
|
+
`,
|
|
71
|
+
tables: ['media'],
|
|
72
|
+
check: isMediaBody,
|
|
73
|
+
repoOf: (b) => b.repo,
|
|
74
|
+
outbox: 'media',
|
|
75
|
+
refuses: (db, b, o) => {
|
|
76
|
+
// a row of no repo is read by the nodes of the grant `all`: a narrower node never writes one
|
|
77
|
+
if (b.repo === '' && db.query("select 1 from grants where node = ? and kind = 'all'").get(o.node) == null) return `media ${b.key}: a row of no repo comes from a node of the grant all only`
|
|
78
|
+
// one content has one size: a node that says another lies, or its file changed under its key
|
|
79
|
+
const other = db.query('select size, node from media where key = ? and node <> ? and size <> ? limit 1').get(b.key, o.node, b.size) as { size: number; node: string } | null
|
|
80
|
+
return other == null ? null : `media ${b.key}: ${b.size} bytes, the hq holds it at ${other.size} from another node`
|
|
81
|
+
},
|
|
82
|
+
insert: (db, r) => {
|
|
83
|
+
const held = db.query(`select ${COLS} from media where key = ? and node = ?`).get(r.body.key, r.node) as Row | null
|
|
84
|
+
const bytes = rowBytes(r.body, r.node)
|
|
85
|
+
if (held == null) {
|
|
86
|
+
db.query(`insert into media (${COLS}) values (?, ?, ?, ?, ?, ?)`).run(r.body.key, r.node, r.body.size, r.body.repo, r.body.name, r.body.at)
|
|
87
|
+
return { rows: 1, bytes }
|
|
88
|
+
}
|
|
89
|
+
if (held.size === r.body.size && held.repo === r.body.repo && held.name === r.body.name) return null
|
|
90
|
+
db.query('update media set size = ?, repo = ?, name = ?, at = ? where key = ? and node = ?').run(r.body.size, r.body.repo, r.body.name, r.body.at, r.body.key, r.node)
|
|
91
|
+
return { rows: 0, bytes: bytes - rowBytes({ ...r.body, repo: held.repo, name: held.name }, r.node) }
|
|
92
|
+
},
|
|
93
|
+
usage: (db) => db.query(`select node, count(*) as rows, sum(${ROW_BYTES_SQL}) as bytes from media group by node`).all() as { node: string; rows: number; bytes: number }[],
|
|
94
|
+
maxPerNode: NODE_MAX_MEDIA,
|
|
95
|
+
maxBytesPerNode: NODE_MAX_MEDIA_BYTES,
|
|
96
|
+
// kept for good, as the Space keeps its objects
|
|
97
|
+
sweep: () => 0,
|
|
98
|
+
read: {
|
|
99
|
+
// by a name (a key or a sha), else a page of every row in time order
|
|
100
|
+
page: (db, q: ReadQuery) => {
|
|
101
|
+
if (q.name != null && q.name !== '') return { rows: findMedia(db, q.name, q.repos, Math.min(q.limit, MEDIA_READ_MAX)), next: null }
|
|
102
|
+
const [at, key, node] = q.after === '' ? [-1, '', ''] : (JSON.parse(q.after) as [number, string, string])
|
|
103
|
+
const r = repoWhere(q.repos)
|
|
104
|
+
const rows = db.query(`select ${COLS} from media where at >= ? and (at, key, node) > (?, ?, ?)${r.sql}${q.node == null ? '' : ' and node = ?'} order by at, key, node limit ?`).all(q.since, at, key, node, ...r.args, ...(q.node == null ? [] : [q.node]), q.limit + 1) as Row[]
|
|
105
|
+
const last = rows[q.limit - 1]
|
|
106
|
+
return { rows: rows.slice(0, q.limit), next: rows.length > q.limit && last != null ? JSON.stringify([last.at, last.key, last.node]) : null }
|
|
107
|
+
},
|
|
108
|
+
// the rev of a row is its size: a key the hq holds at another size is said changed
|
|
109
|
+
lacks: (db, asked, repos) => {
|
|
110
|
+
const r = repoWhere(repos)
|
|
111
|
+
const out: Lack[] = []
|
|
112
|
+
const q = db.query(`select size from media where key = ?${r.sql} limit 1`)
|
|
113
|
+
for (const a of asked) {
|
|
114
|
+
const h = q.get(a.name, ...r.args) as { size: number } | null
|
|
115
|
+
if (h == null) out.push({ name: a.name, why: 'missing' })
|
|
116
|
+
else if (a.rev != null && String(h.size) !== a.rev) out.push({ name: a.name, why: 'changed' })
|
|
117
|
+
}
|
|
118
|
+
return out
|
|
119
|
+
},
|
|
120
|
+
count: (db, q) => {
|
|
121
|
+
const r = repoWhere(q.repos)
|
|
122
|
+
return (db.query(`select count(*) as n from media where at >= ?${r.sql}${q.node == null ? '' : ' and node = ?'}`).get(q.since, ...r.args, ...(q.node == null ? [] : [q.node])) as { n: number }).n
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
})
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// one prompt the owner typed or queued in a Claude Code session (wiki tools/shipkit/hq.md), kept for good: its id,
|
|
2
|
+
// its time, its repo, its session and account, its text with every secret shape masked. A copy of a session in
|
|
3
|
+
// another account or on another machine gives the same id, so a prompt lands once; the first node to send it keeps it.
|
|
4
|
+
// The one constraint a reader breaks first: the text is the owner's own words, so a secret shape is masked on the machine
|
|
5
|
+
// before the row leaves it, and again here before it is stored (a daemon of older code may not mask)
|
|
6
|
+
import { createHash } from 'crypto'
|
|
7
|
+
import { maskSecrets } from '../../agent-time/mask.ts'
|
|
8
|
+
import { kind, type Lack } from './kind.ts'
|
|
9
|
+
|
|
10
|
+
export type PromptBody = { id: string; at: number; repo: string; session: string; account: string; origin: 'typed' | 'queued'; text: string; cut: number; masked: number }
|
|
11
|
+
|
|
12
|
+
/** the prompts one node may hold: this Mac typed 13,946 in 54 days, so about 4 years */
|
|
13
|
+
export const NODE_MAX_PROMPTS = 400_000
|
|
14
|
+
export const NODE_MAX_PROMPT_BYTES = 160 * 1024 * 1024
|
|
15
|
+
/** of one day of their time: the busiest day held 528. A node that makes rows up is stopped early */
|
|
16
|
+
export const NODE_MAX_PROMPTS_A_DAY = 2_000
|
|
17
|
+
/** a text kept whole up to this, as JSON encodes it; past it its head and its tail are kept, the cut said between */
|
|
18
|
+
export const PROMPT_MAX_TEXT = 48 * 1024
|
|
19
|
+
export const PROMPT_HEAD = 32 * 1024
|
|
20
|
+
export const PROMPT_TAIL = 16 * 1024
|
|
21
|
+
/** room for the line that says what was cut */
|
|
22
|
+
const CUT_LINE_ROOM = 256
|
|
23
|
+
/** the earliest time a prompt can have: 2025-01-01 */
|
|
24
|
+
export const PROMPT_EPOCH = Date.UTC(2025, 0, 1)
|
|
25
|
+
const DAY_MS = 24 * 3600_000
|
|
26
|
+
|
|
27
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
|
|
28
|
+
const HASH_ID_RE = /^q[A-Za-z0-9_-]{21}$/
|
|
29
|
+
const NAME_RE = /^[A-Za-z0-9._-]{1,64}$/
|
|
30
|
+
const PART_RE = /^[A-Za-z0-9._~-]+$/
|
|
31
|
+
|
|
32
|
+
/** a repo as the history files it: its key (host and path, lowercase), or a folder's name. Never a path of a
|
|
33
|
+
* machine: no leading slash, no `.` or `..` part */
|
|
34
|
+
export const isHistoryRepo = (v: unknown): v is string => typeof v === 'string' && v.length > 0 && v.length <= 200 && v.split('/').every((p) => PART_RE.test(p) && p !== '.' && p !== '..')
|
|
35
|
+
|
|
36
|
+
/** a prompt's id: the entry's uuid, else (a queued prompt has none) a hash of its time and its text as read */
|
|
37
|
+
export function promptId(uuid: string | null, at: number, text: string): string {
|
|
38
|
+
const u = uuid?.toLowerCase() ?? ''
|
|
39
|
+
if (UUID_RE.test(u)) return u
|
|
40
|
+
return `q${createHash('sha256').update(`${at}\0${text}`).digest('base64url').slice(0, 21)}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { maskSecrets }
|
|
44
|
+
|
|
45
|
+
/** what the check compares of a prompt the hq holds: the sha of its text, masked and cut as it was sent */
|
|
46
|
+
export const textSha = (text: string): string => createHash('sha256').update(text).digest('hex')
|
|
47
|
+
|
|
48
|
+
/** the bytes JSON spends on a text, without its quotes */
|
|
49
|
+
const encoded = (s: string): number => Buffer.byteLength(JSON.stringify(s)) - 2
|
|
50
|
+
|
|
51
|
+
/** the longest prefix (or suffix) whose JSON fits `max`, never half of a surrogate pair */
|
|
52
|
+
function fit(text: string, max: number, end: boolean): string {
|
|
53
|
+
let lo = 0
|
|
54
|
+
let hi = text.length
|
|
55
|
+
const part = (n: number): string => (end ? text.slice(text.length - n) : text.slice(0, n))
|
|
56
|
+
while (lo < hi) {
|
|
57
|
+
const mid = (lo + hi + 1) >> 1
|
|
58
|
+
if (encoded(part(mid)) <= max) lo = mid
|
|
59
|
+
else hi = mid - 1
|
|
60
|
+
}
|
|
61
|
+
let n = lo
|
|
62
|
+
const edge = (i: number): number => text.charCodeAt(i)
|
|
63
|
+
if (!end && n > 0 && n < text.length && edge(n - 1) >= 0xd800 && edge(n - 1) <= 0xdbff) n--
|
|
64
|
+
if (end && n > 0 && n < text.length && edge(text.length - n) >= 0xdc00 && edge(text.length - n) <= 0xdfff) n--
|
|
65
|
+
return part(n)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** a text over PROMPT_MAX_TEXT keeps its head and its tail (the ask often follows a paste), a line between says how
|
|
69
|
+
* many bytes went: `cut` is that count */
|
|
70
|
+
export function cutText(text: string): { text: string; cut: number } {
|
|
71
|
+
if (encoded(text) <= PROMPT_MAX_TEXT) return { text, cut: 0 }
|
|
72
|
+
const head = fit(text, PROMPT_HEAD, false)
|
|
73
|
+
const tail = fit(text, PROMPT_TAIL, true)
|
|
74
|
+
const cut = Buffer.byteLength(text) - Buffer.byteLength(head) - Buffer.byteLength(tail)
|
|
75
|
+
return { text: `${head}\n[… ${cut} bytes cut here …]\n${tail}`, cut }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** a row of the index as it leaves the machine: masked, then cut */
|
|
79
|
+
export function promptBody(p: { uuid: string | null; at: number; text: string; origin: 'typed' | 'queued'; repo: string; session: string; account: string }): PromptBody {
|
|
80
|
+
const m = maskSecrets(p.text)
|
|
81
|
+
const c = cutText(m.text)
|
|
82
|
+
return { id: promptId(p.uuid, p.at, p.text), at: p.at, repo: p.repo, session: p.session, account: p.account, origin: p.origin, text: c.text, cut: c.cut, masked: m.masked }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const isObj = (v: unknown): v is Record<string, unknown> => v != null && typeof v === 'object' && !Array.isArray(v)
|
|
86
|
+
const whole = (v: unknown): v is number => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0
|
|
87
|
+
|
|
88
|
+
export const isPromptBody = (v: unknown): v is PromptBody =>
|
|
89
|
+
isObj(v) &&
|
|
90
|
+
typeof v['id'] === 'string' &&
|
|
91
|
+
(UUID_RE.test(v['id']) || HASH_ID_RE.test(v['id'])) &&
|
|
92
|
+
whole(v['at']) &&
|
|
93
|
+
v['at'] >= PROMPT_EPOCH &&
|
|
94
|
+
isHistoryRepo(v['repo']) &&
|
|
95
|
+
typeof v['session'] === 'string' &&
|
|
96
|
+
NAME_RE.test(v['session']) &&
|
|
97
|
+
typeof v['account'] === 'string' &&
|
|
98
|
+
NAME_RE.test(v['account']) &&
|
|
99
|
+
(v['origin'] === 'typed' || v['origin'] === 'queued') &&
|
|
100
|
+
typeof v['text'] === 'string' &&
|
|
101
|
+
encoded(v['text']) <= PROMPT_MAX_TEXT + CUT_LINE_ROOM &&
|
|
102
|
+
whole(v['cut']) &&
|
|
103
|
+
whole(v['masked'])
|
|
104
|
+
|
|
105
|
+
/** what one row costs in the file, the same in the count at intake and in the count from the table */
|
|
106
|
+
// what a row costs the hq's file with its three indexes and the room its pages leave, measured from 35 B to 4 kB of
|
|
107
|
+
// text (within 7 %): the share of a node means file, not text
|
|
108
|
+
const ROW_BYTES_SQL = 'cast((length(cast(text as blob)) + length(id) + length(cast(repo as blob)) + length(session) + length(account) + 48) * 1.15 as integer) + 90'
|
|
109
|
+
const rowBytes = (b: { id: string; repo: string; session: string; account: string }, text: string): number => Math.trunc((Buffer.byteLength(text) + b.id.length + Buffer.byteLength(b.repo) + b.session.length + b.account.length + 48) * 1.15) + 90
|
|
110
|
+
|
|
111
|
+
/** a page of the prompts holds at most this many bytes of text */
|
|
112
|
+
export const READ_MAX_BYTES = 4 * 1024 * 1024
|
|
113
|
+
|
|
114
|
+
const repoWhere = (repos: readonly string[] | null): { sql: string; args: string[] } => (repos == null ? { sql: '', args: [] } : { sql: ` and repo in (${repos.map(() => '?').join(',')})`, args: [...repos] })
|
|
115
|
+
|
|
116
|
+
export const promptKind = kind<PromptBody>({
|
|
117
|
+
kind: 'prompt',
|
|
118
|
+
schema: `
|
|
119
|
+
create table if not exists prompts (id text not null unique, node text not null, at integer not null, repo text not null, session text not null, account text not null, origin text not null, text text not null, cut integer not null, masked integer not null);
|
|
120
|
+
create index if not exists prompts_repo on prompts (repo, at);
|
|
121
|
+
create index if not exists prompts_at on prompts (at);
|
|
122
|
+
create table if not exists prompts_forgotten (id text primary key, node text not null, repo text not null, at integer not null, gone integer not null) without rowid;
|
|
123
|
+
create table if not exists prompt_days (node text not null, day integer not null, n integer not null, primary key (node, day)) without rowid;
|
|
124
|
+
`,
|
|
125
|
+
tables: ['prompts', 'prompts_forgotten', 'prompt_days'],
|
|
126
|
+
check: isPromptBody,
|
|
127
|
+
repoOf: (b) => b.repo,
|
|
128
|
+
refuses: (db, b, o) => {
|
|
129
|
+
if (db.query('select 1 from prompts_forgotten where id = ?').get(b.id) != null) return `prompt ${b.id} was forgotten: it is never taken again`
|
|
130
|
+
if (db.query('select 1 from prompts where id = ?').get(b.id) != null) return null
|
|
131
|
+
if (b.at > o.now + DAY_MS) return `prompt ${b.id} is dated ${new Date(b.at).toISOString()}, after the hq's tomorrow`
|
|
132
|
+
const day = Math.floor(b.at / DAY_MS)
|
|
133
|
+
const n = (db.query('select n from prompt_days where node = ? and day = ?').get(o.node, day) as { n: number } | null)?.n ?? 0
|
|
134
|
+
return n >= NODE_MAX_PROMPTS_A_DAY ? `this node sent ${n} prompts of ${new Date(day * DAY_MS).toISOString().slice(0, 10)} already, the most of one day` : null
|
|
135
|
+
},
|
|
136
|
+
// the first node to send a prompt keeps it; that node alone may send its text again, changed (a newer mask, or a
|
|
137
|
+
// text the hq lost), and the row takes it
|
|
138
|
+
insert: (db, r) => {
|
|
139
|
+
const m = maskSecrets(r.body.text)
|
|
140
|
+
const held = db.query('select node, text from prompts where id = ?').get(r.body.id) as { node: string; text: string } | null
|
|
141
|
+
if (held != null) {
|
|
142
|
+
if (held.node !== r.node || held.text === m.text) return null
|
|
143
|
+
db.query('update prompts set text = ?, cut = ?, masked = ? where id = ?').run(m.text, r.body.cut, r.body.masked + m.masked, r.body.id)
|
|
144
|
+
return { rows: 0, bytes: rowBytes(r.body, m.text) - rowBytes(r.body, held.text) }
|
|
145
|
+
}
|
|
146
|
+
const done = db.query('insert into prompts (id, node, at, repo, session, account, origin, text, cut, masked) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) on conflict (id) do nothing').run(r.body.id, r.node, r.body.at, r.body.repo, r.body.session, r.body.account, r.body.origin, m.text, r.body.cut, r.body.masked + m.masked)
|
|
147
|
+
if (done.changes === 0) return null
|
|
148
|
+
// the count of a node's day, kept beside the rows: a count over the rows of a day costs a scan a row
|
|
149
|
+
db.query('insert into prompt_days (node, day, n) values (?, ?, 1) on conflict (node, day) do update set n = n + 1').run(r.node, Math.floor(r.body.at / DAY_MS))
|
|
150
|
+
return { rows: 1, bytes: rowBytes(r.body, m.text) }
|
|
151
|
+
},
|
|
152
|
+
usage: (db) => db.query(`select node, count(*) as rows, sum(${ROW_BYTES_SQL}) as bytes from prompts group by node`).all() as { node: string; rows: number; bytes: number }[],
|
|
153
|
+
maxPerNode: NODE_MAX_PROMPTS,
|
|
154
|
+
maxBytesPerNode: NODE_MAX_PROMPT_BYTES,
|
|
155
|
+
// the mask at intake costs about 22 ms a MB: 256 kB a call holds the hq's loop about 6 ms, five long prompts
|
|
156
|
+
maxCallBytes: 256 * 1024,
|
|
157
|
+
// kept for good: the one removal is forget
|
|
158
|
+
sweep: () => 0,
|
|
159
|
+
read: {
|
|
160
|
+
page: (db, q) => {
|
|
161
|
+
const [at, id] = q.after === '' ? [-1, ''] : [Number(q.after.slice(0, q.after.indexOf(':'))), q.after.slice(q.after.indexOf(':') + 1)]
|
|
162
|
+
const r = repoWhere(q.repos)
|
|
163
|
+
const node = q.node == null ? '' : ' and node = ?'
|
|
164
|
+
if (q.ids === true) {
|
|
165
|
+
const ids = db.query(`select id, at, session from prompts where at >= ? and (at > ? or (at = ? and id > ?))${r.sql}${node} order by at, id limit ?`).all(q.since, at, at, id, ...r.args, ...(q.node == null ? [] : [q.node]), q.limit + 1) as { id: string; at: number; session: string }[]
|
|
166
|
+
const last = ids[q.limit - 1]
|
|
167
|
+
return { rows: ids.slice(0, q.limit), next: ids.length > q.limit && last != null ? `${last.at}:${last.id}` : null }
|
|
168
|
+
}
|
|
169
|
+
const rows = db.query(`select id, node, at, repo, session, account, origin, text, cut, masked from prompts where at >= ? and (at > ? or (at = ? and id > ?))${r.sql}${node} order by at, id limit ?`).all(q.since, at, at, id, ...r.args, ...(q.node == null ? [] : [q.node]), q.limit + 1) as (PromptBody & { node: string })[]
|
|
170
|
+
// one row past the limit says whether a next page exists
|
|
171
|
+
const kept: typeof rows = []
|
|
172
|
+
let bytes = 0
|
|
173
|
+
for (const row of rows.slice(0, q.limit)) {
|
|
174
|
+
bytes += Buffer.byteLength(row.text)
|
|
175
|
+
if (kept.length > 0 && bytes > READ_MAX_BYTES) break
|
|
176
|
+
kept.push(row)
|
|
177
|
+
}
|
|
178
|
+
const last = kept.at(-1)
|
|
179
|
+
return { rows: kept, next: kept.length < rows.length && last != null ? `${last.at}:${last.id}` : null }
|
|
180
|
+
},
|
|
181
|
+
// a forgotten prompt is said as forgotten, never as missing: the check takes it as no loss. A rev is the sha of
|
|
182
|
+
// the text
|
|
183
|
+
lacks: (db, asked, repos, node) => {
|
|
184
|
+
const held = new Map<string, { node: string; text: string }>()
|
|
185
|
+
const forgotten = new Set<string>()
|
|
186
|
+
const r = repoWhere(repos)
|
|
187
|
+
for (let i = 0; i < asked.length; i += 500) {
|
|
188
|
+
const part = asked.slice(i, i + 500).map((a) => a.name)
|
|
189
|
+
const marks = part.map(() => '?').join(',')
|
|
190
|
+
for (const x of db.query(`select id, node, text from prompts where id in (${marks})${r.sql}`).all(...part, ...r.args) as { id: string; node: string; text: string }[]) held.set(x.id, x)
|
|
191
|
+
for (const x of db.query(`select id from prompts_forgotten where id in (${marks})`).all(...part) as { id: string }[]) forgotten.add(x.id)
|
|
192
|
+
}
|
|
193
|
+
const out: Lack[] = []
|
|
194
|
+
for (const a of asked) {
|
|
195
|
+
const h = held.get(a.name)
|
|
196
|
+
if (forgotten.has(a.name)) out.push({ name: a.name, why: 'forgotten' })
|
|
197
|
+
else if (h == null) out.push({ name: a.name, why: 'missing' })
|
|
198
|
+
else if (h.node !== node) out.push({ name: a.name, why: 'elsewhere' })
|
|
199
|
+
else if (a.rev != null && textSha(h.text) !== a.rev) out.push({ name: a.name, why: 'changed' })
|
|
200
|
+
}
|
|
201
|
+
return out
|
|
202
|
+
},
|
|
203
|
+
count: (db, q) => {
|
|
204
|
+
const r = repoWhere(q.repos)
|
|
205
|
+
const of = (table: string): number => (db.query(`select count(*) as n from ${table} where at >= ?${r.sql}${q.node == null ? '' : ' and node = ?'}`).get(q.since, ...r.args, ...(q.node == null ? [] : [q.node])) as { n: number }).n
|
|
206
|
+
return of('prompts') + (q.forgotten === true ? of('prompts_forgotten') : 0)
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
forget: (db, name, now) => {
|
|
210
|
+
let held = false
|
|
211
|
+
db.transaction(() => {
|
|
212
|
+
const row = db.query('delete from prompts where id = ? returning node, repo, at').get(name) as { node: string; repo: string; at: number } | null
|
|
213
|
+
held = row != null
|
|
214
|
+
if (row != null) db.query('update prompt_days set n = n - 1 where node = ? and day = ?').run(row.node, Math.floor(row.at / DAY_MS))
|
|
215
|
+
db.query('insert into prompts_forgotten (id, node, repo, at, gone) values (?, ?, ?, ?, ?) on conflict (id) do nothing').run(name, row?.node ?? '', row?.repo ?? '', row?.at ?? 0, now)
|
|
216
|
+
}).immediate()
|
|
217
|
+
return held
|
|
218
|
+
},
|
|
219
|
+
})
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// one reflection file of a repo as one node holds it (the house wiki's reflections triage), WITH its text: these
|
|
2
|
+
// files are in no git, so the row is their only copy off that disk. A file that leaves its folder is acked (the
|
|
3
|
+
// triage's ack is its move out): the row keeps its text, and goes 90 days after. The one constraint a reader breaks
|
|
4
|
+
// first: the text is written by agents and may quote a secret, so it is masked on the machine before it leaves and
|
|
5
|
+
// again here before it is stored, and cut as a prompt is
|
|
6
|
+
import { createHash } from 'crypto'
|
|
7
|
+
import { maskSecrets } from '../../agent-time/mask.ts'
|
|
8
|
+
import { isKeyRepo } from './ask.ts'
|
|
9
|
+
import { kind, type Lack } from './kind.ts'
|
|
10
|
+
import { cutText, PROMPT_MAX_TEXT } from './prompt.ts'
|
|
11
|
+
|
|
12
|
+
export type ReflectionFacts = { repo: string; file: string; title: string; text: string; cut: number; masked: number; sha: string }
|
|
13
|
+
/** a reflection that left its folder on this node */
|
|
14
|
+
export type ReflectionGone = { repo: string; file: string; gone: true }
|
|
15
|
+
export type ReflectionBody = ReflectionFacts | ReflectionGone
|
|
16
|
+
|
|
17
|
+
export type ReflectionRow = Omit<ReflectionFacts, 'text'> & { text?: string; node: string; at: number; state: 'open' | 'acked'; acked: number | null }
|
|
18
|
+
|
|
19
|
+
/** an acked row is kept this long, its text in the harvest of the machine that acked it */
|
|
20
|
+
export const REFLECTION_ACKED_KEEP_MS = 90 * 24 * 3600_000
|
|
21
|
+
/** the rows of an ended node are swept this long after its end: the node never sends their ack, and on a machine that was
|
|
22
|
+
* wiped they are the only copy of its reflections, so the triage has a month to read them */
|
|
23
|
+
export const REFLECTION_ENDED_KEEP_MS = 30 * 24 * 3600_000
|
|
24
|
+
/** this Mac holds 35 today, 3 kB at the median, 39 kB the largest, 0.12 MB in all: 4 MB is thirty times that */
|
|
25
|
+
export const NODE_MAX_REFLECTIONS = 1_000
|
|
26
|
+
export const NODE_MAX_REFLECTION_BYTES = 4 * 1024 * 1024
|
|
27
|
+
export const REFLECTION_TEXTS = ['title', 'text'] as const
|
|
28
|
+
export const REFLECTION_NAMES = ['repo', 'file', 'sha'] as const
|
|
29
|
+
|
|
30
|
+
const FILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,159}\.md$/
|
|
31
|
+
const isObj = (v: unknown): v is Record<string, unknown> => v != null && typeof v === 'object' && !Array.isArray(v)
|
|
32
|
+
const whole = (v: unknown): v is number => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0
|
|
33
|
+
const encoded = (s: string): number => Buffer.byteLength(JSON.stringify(s)) - 2
|
|
34
|
+
|
|
35
|
+
export function isReflectionBody(v: unknown): v is ReflectionBody {
|
|
36
|
+
if (!isObj(v) || !isKeyRepo(v['repo']) || typeof v['file'] !== 'string' || !FILE_RE.test(v['file']) || v['file'] === 'README.md') return false
|
|
37
|
+
if (v['gone'] === true) return Object.keys(v).length === 3
|
|
38
|
+
if (Object.keys(v).length !== 7) return false
|
|
39
|
+
return typeof v['title'] === 'string' && v['title'].length <= 300 && typeof v['text'] === 'string' && encoded(v['text']) <= PROMPT_MAX_TEXT + 256 && whole(v['cut']) && whole(v['masked']) && typeof v['sha'] === 'string' && /^[0-9a-f]{64}$/.test(v['sha'])
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** the first heading, the name its writer gave it */
|
|
43
|
+
const titleOf = (text: string, file: string): string => (text.split('\n').find((l) => /^\s*#{1,6}\s+\S/.test(l))?.replace(/^\s*#{1,6}\s+/, '').trim() ?? file).slice(0, 300)
|
|
44
|
+
|
|
45
|
+
/** a file as it leaves the machine: masked, then cut. `sha` is the file's own, so a file that did not change is one rev */
|
|
46
|
+
export function reflectionBody(repo: string, file: string, raw: string): ReflectionFacts {
|
|
47
|
+
const m = maskSecrets(raw)
|
|
48
|
+
const c = cutText(m.text)
|
|
49
|
+
return { repo, file, title: maskSecrets(titleOf(raw, file)).text, text: c.text, cut: c.cut, masked: m.masked, sha: createHash('sha256').update(raw).digest('hex') }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const repoWhere = (repos: readonly string[] | null): { sql: string; args: string[] } => (repos == null ? { sql: '', args: [] } : { sql: ` and repo in (${repos.map(() => '?').join(',')})`, args: [...repos] })
|
|
53
|
+
const cursorOf = (after: string): [string, string, string] => {
|
|
54
|
+
const p = after.split(' ')
|
|
55
|
+
return p.length === 3 ? [p[0]!, p[1]!, p[2]!] : ['', '', '']
|
|
56
|
+
}
|
|
57
|
+
const ROW_BYTES_SQL = 'length(cast(text as blob)) + length(cast(title as blob)) + 160'
|
|
58
|
+
const rowBytes = (b: ReflectionFacts, text: string): number => Buffer.byteLength(text) + Buffer.byteLength(b.title) + 160
|
|
59
|
+
|
|
60
|
+
export const reflectionKind = kind<ReflectionBody>({
|
|
61
|
+
kind: 'reflection',
|
|
62
|
+
schema: `
|
|
63
|
+
create table if not exists reflections (repo text not null, file text not null, node text not null, at integer not null, title text not null, text text not null, cut integer not null, masked integer not null, sha text not null, state text not null, acked integer, primary key (repo, file, node)) without rowid;
|
|
64
|
+
create index if not exists reflections_state on reflections (state, repo);
|
|
65
|
+
create table if not exists reflections_forgotten (repo text not null, file text not null, gone integer not null, primary key (repo, file)) without rowid;
|
|
66
|
+
`,
|
|
67
|
+
tables: ['reflections', 'reflections_forgotten'],
|
|
68
|
+
check: isReflectionBody,
|
|
69
|
+
repoOf: (b) => b.repo,
|
|
70
|
+
texts: REFLECTION_TEXTS,
|
|
71
|
+
names: REFLECTION_NAMES,
|
|
72
|
+
// a call of four rows of 48 kB, masked at intake and stored, holds the hq's loop about 12 ms (measured, tests/hq/files-hostile)
|
|
73
|
+
maxCallBytes: 192 * 1024,
|
|
74
|
+
refuses: (db, b) => (db.query('select 1 from reflections_forgotten where repo = ? and file = ?').get(b.repo, b.file) != null ? `reflection ${b.file} of ${b.repo} was forgotten: it is never taken again` : null),
|
|
75
|
+
insert: (db, r) => {
|
|
76
|
+
const held = db.query(`select sha, state, text, ${ROW_BYTES_SQL} as bytes from reflections where repo = ? and file = ? and node = ?`).get(r.body.repo, r.body.file, r.node) as { sha: string; state: string; text: string; bytes: number } | null
|
|
77
|
+
if ('gone' in r.body) {
|
|
78
|
+
if (held == null || held.state === 'acked') return null
|
|
79
|
+
db.query("update reflections set state = 'acked', acked = ? where repo = ? and file = ? and node = ?").run(r.at, r.body.repo, r.body.file, r.node)
|
|
80
|
+
return { rows: 0, bytes: 0 }
|
|
81
|
+
}
|
|
82
|
+
// its text and title come masked by the store's door (`texts`)
|
|
83
|
+
const m = { text: r.body.text, masked: 0 }
|
|
84
|
+
if (held != null && held.sha === r.body.sha && held.state === 'open' && held.text === m.text) return null
|
|
85
|
+
const title = r.body.title
|
|
86
|
+
db.query("insert into reflections (repo, file, node, at, title, text, cut, masked, sha, state, acked) values (?, ?, ?, ?, ?, ?, ?, ?, ?, 'open', null) on conflict (repo, file, node) do update set at = excluded.at, title = excluded.title, text = excluded.text, cut = excluded.cut, masked = excluded.masked, sha = excluded.sha, state = 'open', acked = null").run(r.body.repo, r.body.file, r.node, r.at, title, m.text, r.body.cut, r.body.masked + m.masked, r.body.sha)
|
|
87
|
+
return { rows: held == null ? 1 : 0, bytes: rowBytes({ ...r.body, title }, m.text) - (held?.bytes ?? 0) }
|
|
88
|
+
},
|
|
89
|
+
usage: (db) => db.query(`select node, count(*) as rows, sum(${ROW_BYTES_SQL}) as bytes from reflections group by node`).all() as { node: string; rows: number; bytes: number }[],
|
|
90
|
+
maxPerNode: NODE_MAX_REFLECTIONS,
|
|
91
|
+
maxBytesPerNode: NODE_MAX_REFLECTION_BYTES,
|
|
92
|
+
sweep: (db, now) => db.query("delete from reflections where (state = 'acked' and acked < ?) or node in (select id from nodes where ended is not null and ended < ?)").run(now - REFLECTION_ACKED_KEEP_MS, now - REFLECTION_ENDED_KEEP_MS).changes,
|
|
93
|
+
// a reflection out of the hq for good, every node's row of it: `<repo> <file>`
|
|
94
|
+
forget: (db, name, now) => {
|
|
95
|
+
const i = name.indexOf(' ')
|
|
96
|
+
const [repo, file] = i < 0 ? ['', name] : [name.slice(0, i), name.slice(i + 1)]
|
|
97
|
+
const held = db.query('delete from reflections where repo = ? and file = ?').run(repo, file).changes > 0
|
|
98
|
+
db.query('insert into reflections_forgotten (repo, file, gone) values (?, ?, ?) on conflict (repo, file) do nothing').run(repo, file, now)
|
|
99
|
+
return held
|
|
100
|
+
},
|
|
101
|
+
read: {
|
|
102
|
+
// every node's rows, oldest repo and file first; `ids` leaves the text out
|
|
103
|
+
page: (db, q) => {
|
|
104
|
+
const [repo, file, node] = cursorOf(q.after)
|
|
105
|
+
const r = repoWhere(q.repos)
|
|
106
|
+
const cols = q.ids === true ? 'repo, file, node, at, title, cut, masked, sha, state, acked' : 'repo, file, node, at, title, text, cut, masked, sha, state, acked'
|
|
107
|
+
const rows = db.query(`select ${cols} from reflections where (repo, file, node) > (?, ?, ?) and at >= ? and node in (select id from nodes where ended is null)${r.sql}${q.node == null ? '' : ' and node = ?'} order by repo, file, node limit ?`).all(repo, file, node, q.since, ...r.args, ...(q.node == null ? [] : [q.node]), q.limit + 1) as ReflectionRow[]
|
|
108
|
+
const page = rows.slice(0, q.limit)
|
|
109
|
+
const last = page.at(-1)
|
|
110
|
+
return { rows: page, next: rows.length > q.limit && last != null ? `${last.repo} ${last.file} ${last.node}` : null }
|
|
111
|
+
},
|
|
112
|
+
// a name is `<repo> <file>`, a rev the sha of the file as the asker holds it
|
|
113
|
+
lacks: (db, asked, repos, node) => {
|
|
114
|
+
const out: Lack[] = []
|
|
115
|
+
for (const a of asked) {
|
|
116
|
+
const [repo, file] = a.name.split(' ') as [string, string | undefined]
|
|
117
|
+
const held = repos != null && !repos.includes(repo) ? null : (db.query('select sha from reflections where repo = ? and file = ? and node = ?').get(repo, file ?? '', node) as { sha: string } | null)
|
|
118
|
+
if (held == null) out.push({ name: a.name, why: 'missing' })
|
|
119
|
+
else if (a.rev != null && a.rev !== held.sha) out.push({ name: a.name, why: 'changed' })
|
|
120
|
+
}
|
|
121
|
+
return out
|
|
122
|
+
},
|
|
123
|
+
count: (db, q) => {
|
|
124
|
+
const r = repoWhere(q.repos)
|
|
125
|
+
return (db.query(`select count(*) as n from reflections where at >= ? and node in (select id from nodes where ended is null)${r.sql}${q.node == null ? '' : ' and node = ?'}`).get(q.since, ...r.args, ...(q.node == null ? [] : [q.node])) as { n: number }).n
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// what a node says of its machine at one moment (hq/report.ts builds it): appends only, raw for 30 days, then the
|
|
2
|
+
// last one of each day a node. Only the newest report's activity is read, so an older one loses it after a day
|
|
3
|
+
import { isReport, REPORT_TEXTS, type Report } from '../report.ts'
|
|
4
|
+
import { kind } from './kind.ts'
|
|
5
|
+
|
|
6
|
+
/** raw reports are kept this long, then one a day a node */
|
|
7
|
+
export const REPORTS_RAW_MS = 30 * 24 * 3600_000
|
|
8
|
+
/** the reports one node may hold: 30 days of raw ones are 8,640 */
|
|
9
|
+
export const NODE_MAX_REPORTS = 20_000
|
|
10
|
+
/** and their bytes: 30 days of raw reports of 14 repos are about 17 MB. A fifth of the hq's file at most */
|
|
11
|
+
export const NODE_MAX_REPORT_BYTES = 40 * 1024 * 1024
|
|
12
|
+
/** a report keeps its activity this long: past it only its figures are read (the disk line) */
|
|
13
|
+
export const REPORT_ACTIVITY_MS = 24 * 3600_000
|
|
14
|
+
|
|
15
|
+
/** a report past a day: what only the newest one is read for (its activity, each repo's gate, each process's url) goes */
|
|
16
|
+
export function slimReport(r: Report): Report {
|
|
17
|
+
const { activity: _activity, ...rest } = r
|
|
18
|
+
return { ...rest, repos: r.repos.map(({ gate: _gate, ...x }) => x), ...(r.processes == null ? {} : { processes: r.processes.map(({ url: _url, ...p }) => p) }) }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const reportKind = kind<Report>({
|
|
22
|
+
kind: 'report',
|
|
23
|
+
schema: `
|
|
24
|
+
create table if not exists reports (node text not null, epoch text not null, seq integer not null, at integer not null, body text not null, primary key (node, epoch, seq)) without rowid;
|
|
25
|
+
create index if not exists reports_at on reports (node, at);
|
|
26
|
+
`,
|
|
27
|
+
tables: ['reports'],
|
|
28
|
+
check: isReport,
|
|
29
|
+
texts: REPORT_TEXTS,
|
|
30
|
+
// a report is the machine's, and names every repo it holds: it is filed under none
|
|
31
|
+
repoOf: () => '',
|
|
32
|
+
insert: (db, r) => {
|
|
33
|
+
if (db.query('insert into reports (node, epoch, seq, at, body) values (?, ?, ?, ?, ?) on conflict (node, epoch, seq) do nothing').run(r.node, r.epoch, r.seq, r.at, r.text).changes === 0) return null
|
|
34
|
+
// a wanted switch value is done once a report of its node shows it
|
|
35
|
+
const sw = r.body.switches
|
|
36
|
+
if (sw != null) for (const w of db.query('select name, value from wanted where node = ? and done is null').all(r.node) as { name: string; value: number }[]) if (sw[w.name] === (w.value === 1)) db.query('update wanted set done = ? where node = ? and name = ?').run(r.at, r.node, w.name)
|
|
37
|
+
return { rows: 1, bytes: Buffer.byteLength(r.text) }
|
|
38
|
+
},
|
|
39
|
+
usage: (db) => db.query('select node, count(*) as rows, sum(length(cast(body as blob))) as bytes from reports group by node').all() as { node: string; rows: number; bytes: number }[],
|
|
40
|
+
maxPerNode: NODE_MAX_REPORTS,
|
|
41
|
+
maxBytesPerNode: NODE_MAX_REPORT_BYTES,
|
|
42
|
+
// the last row of a day is the one with the latest time, then the highest number: rows of one same time are not all kept
|
|
43
|
+
sweep: (db, now) => {
|
|
44
|
+
const slim = db.query('update reports set body = ? where node = ? and epoch = ? and seq = ?')
|
|
45
|
+
for (const r of db.query("select node, epoch, seq, body from reports where at < ? and json_type(body, '$.activity') is not null").all(now - REPORT_ACTIVITY_MS) as { node: string; epoch: string; seq: number; body: string }[]) slim.run(JSON.stringify(slimReport(JSON.parse(r.body) as Report)), r.node, r.epoch, r.seq)
|
|
46
|
+
return db
|
|
47
|
+
.query(
|
|
48
|
+
`delete from reports where at < ?1 and (at, epoch, seq) <> (
|
|
49
|
+
select r2.at, r2.epoch, r2.seq from reports r2
|
|
50
|
+
where r2.node = reports.node and r2.at < ?1 and date(r2.at / 1000, 'unixepoch') = date(reports.at / 1000, 'unixepoch')
|
|
51
|
+
order by r2.at desc, r2.epoch desc, r2.seq desc limit 1)`,
|
|
52
|
+
)
|
|
53
|
+
.run(now - REPORTS_RAW_MS).changes
|
|
54
|
+
},
|
|
55
|
+
})
|