rvlib-shipkit 2.27.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 +16 -0
- package/package.json +1 -1
- package/src/agent-time/hooks.ts +10 -3
- package/src/agent-time/live.ts +11 -5
- package/src/agent-time/registry.ts +289 -0
- package/src/agent-time/store.ts +2 -2
- package/src/annex/born.ts +2 -2
- package/src/annex/offload.ts +12 -11
- package/src/asks/ask-after.ts +6 -2
- 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/kits/identity-kit.ts +106 -38
- package/src/assets/kits/poster-thumbnail.ts +282 -0
- package/src/checks/SK003-claude-md-shape.check.ts +92 -25
- package/src/checks/SK004-gitignore-policy.check.ts +8 -4
- package/src/checks/SK013-one-way-in-policy.check.ts +10 -0
- package/src/checks/SK026-asks-autoclose.check.ts +9 -23
- package/src/checks/SK038-speaks-as.check.ts +3 -3
- package/src/checks/SK042-post-kinds.check.ts +26 -24
- 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 +204 -53
- package/src/cli/cmd_Backup.ts +151 -8
- package/src/cli/cmd_Calls.ts +1 -0
- package/src/cli/cmd_Commands.ts +140 -34
- package/src/cli/cmd_Contracts.ts +1 -0
- package/src/cli/cmd_Keys.ts +1 -0
- package/src/cli/cmd_Lanes.ts +15 -4
- package/src/cli/cmd_Messages.ts +152 -1
- package/src/cli/cmd_Needs.ts +1 -0
- package/src/cli/cmd_Review.ts +931 -229
- package/src/cli/cmd_Secret.ts +255 -34
- package/src/cli/cmd_Social.ts +36 -33
- package/src/cli/cmd_SocialDrafts.ts +235 -0
- package/src/cli/cmd_Sound.ts +22 -1
- 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_Vault.ts +1 -1
- package/src/cli/cmd_When.ts +1 -0
- package/src/cli/family-help.ts +2 -2
- 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 +21 -2
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +25 -74
- package/src/collections/collection-types.ts +9 -5
- package/src/collections/md-body.ts +5 -3
- package/src/collections/pings.ts +13 -6
- package/src/collections/providers.ts +53 -61
- package/src/collections/reflections.ts +9 -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 +10 -5
- package/src/core/locked-write.ts +4 -1
- package/src/core/machine-db.ts +5 -3
- package/src/core/migrate-layout.ts +8 -10
- package/src/home/activity.ts +8 -15
- package/src/home/daemon-jobs.ts +13 -1
- package/src/home/home-paths.ts +6 -3
- package/src/home/home-routes.ts +8 -0
- package/src/home/inbox-shape.ts +233 -100
- package/src/home/inbox.ts +26 -71
- package/src/home/machine-fold.ts +10 -15
- package/src/home/machine-host.ts +19 -1
- package/src/home/other-macs.ts +2 -2
- package/src/home/serve-web.ts +6 -5
- package/src/home/space-page.ts +1 -1
- package/src/home/vault-page.ts +51 -17
- package/src/home/vault-words.ts +2 -2
- package/src/hooks/one-way-in-guard.ts +24 -2
- package/src/hq/files-send.ts +27 -28
- package/src/hq/hq-db.ts +4 -1
- package/src/hq/hq-local.ts +37 -4
- package/src/hq/hq-routes.ts +10 -2
- package/src/hq/hq-store.ts +6 -2
- package/src/hq/kinds/ask.ts +6 -6
- package/src/hq/outbox.ts +5 -3
- package/src/hq/replica.ts +1 -2
- package/src/hq/vault-route.ts +112 -0
- package/src/identities/collection.ts +2 -2
- package/src/identities/identities.ts +9 -8
- package/src/identities/machine-route.ts +8 -3
- package/src/ledger/db.ts +8 -1
- package/src/media-store/backup/daemon.ts +48 -8
- 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/retention.ts +122 -0
- package/src/media-store/backup/run.ts +14 -8
- package/src/media-store/backup/sources.ts +18 -17
- package/src/media-store/backup/thread-copy.ts +340 -0
- package/src/media-store/copy/config.ts +3 -4
- package/src/media-store/copy/store.ts +2 -2
- package/src/media-store/db.ts +2 -2
- package/src/media-store/forget.ts +118 -0
- package/src/media-store/purge.ts +3 -2
- package/src/media-store/space-listing.ts +20 -4
- package/src/media-store/space.ts +6 -5
- package/src/messages/guard.ts +49 -0
- package/src/messages/model.ts +1 -1
- package/src/messages/objects.ts +201 -0
- package/src/messages/routes.ts +2 -2
- package/src/messages/score.ts +1 -1
- package/src/messages/write.ts +285 -0
- package/src/pages/frame-client.ts +181 -4
- 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/public-clean.ts +3 -2
- package/src/repo-config.ts +40 -18
- package/src/review/anim.ts +1 -1
- package/src/review/answer-kinds.ts +131 -0
- package/src/review/band.ts +53 -0
- package/src/review/branch-hold.ts +84 -0
- package/src/review/card-db.ts +16 -6
- package/src/review/card-rows.ts +4 -3
- package/src/review/cells.ts +297 -65
- package/src/review/close.ts +92 -0
- package/src/review/draft-card.ts +8 -16
- package/src/review/draft-model.ts +2 -2
- package/src/review/events.ts +171 -0
- package/src/review/format.ts +128 -14
- package/src/review/glyphs.ts +63 -0
- package/src/review/gone.ts +1 -1
- 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 +22 -9
- 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/model.ts +396 -86
- package/src/review/move.ts +3 -3
- package/src/review/need-address.ts +15 -0
- package/src/review/need-threads.ts +93 -0
- 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 +3 -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/routes.ts +137 -32
- package/src/review/secret-route.ts +80 -0
- package/src/review/snooze.ts +38 -0
- package/src/review/stage-card.ts +4 -4
- package/src/review/store.ts +366 -85
- package/src/review/supersede.ts +116 -0
- package/src/review/take-back.ts +52 -0
- package/src/review/thread-fold.ts +20 -7
- package/src/review/threads.ts +236 -39
- package/src/review/traces.ts +218 -0
- package/src/review/trailer-card.ts +2 -2
- package/src/review/unit.ts +71 -5
- 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 +22 -9
- 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/keychain-write.ts +48 -0
- package/src/secrets/keychain.ts +8 -5
- package/src/secrets/lapse-mark.ts +33 -0
- package/src/secrets/lapse.ts +60 -0
- package/src/secrets/list.ts +16 -22
- package/src/secrets/manager.ts +31 -16
- package/src/secrets/read.ts +161 -33
- package/src/secrets/tail.ts +31 -0
- package/src/serve/hub-app/asks-page.tsx +2 -1
- 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/code-copy.ts +35 -0
- package/src/serve/hub-app/col-card.tsx +31 -40
- package/src/serve/hub-app/col-list-page.tsx +5 -2
- package/src/serve/hub-app/col-tables-view.tsx +7 -4
- package/src/serve/hub-app/col-tables.ts +5 -5
- package/src/serve/hub-app/cols-svc.ts +4 -79
- 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/frames-st.ts +17 -1
- package/src/serve/hub-app/git-view.tsx +3 -2
- package/src/serve/hub-app/home-st.ts +57 -6
- package/src/serve/hub-app/home-strip.css +1 -6
- package/src/serve/hub-app/home-strip.tsx +2 -1
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/house-wiki-view.tsx +20 -0
- package/src/serve/hub-app/hub-app.tsx +48 -32
- package/src/serve/hub-app/hub-types.ts +2 -0
- package/src/serve/hub-app/hub.css +50 -61
- package/src/serve/hub-app/icons.tsx +14 -4
- package/src/serve/hub-app/identities-view.tsx +4 -3
- package/src/serve/hub-app/inbox-st.ts +203 -42
- package/src/serve/hub-app/inbox-view.tsx +189 -101
- package/src/serve/hub-app/inbox.css +47 -44
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/instructions.css +30 -0
- package/src/serve/hub-app/keys.ts +5 -3
- package/src/serve/hub-app/machine-st.ts +2 -2
- package/src/serve/hub-app/machines-view.tsx +4 -11
- package/src/serve/hub-app/machines.css +0 -9
- package/src/serve/hub-app/markdown.css +51 -0
- package/src/serve/hub-app/md-copy.tsx +18 -40
- package/src/serve/hub-app/md.ts +25 -9
- package/src/serve/hub-app/media-view.tsx +2 -2
- package/src/serve/hub-app/messages/messages-page.tsx +2 -1
- package/src/serve/hub-app/messages/messages-st.ts +1 -1
- package/src/serve/hub-app/messages.css +0 -1
- package/src/serve/hub-app/objects.css +51 -0
- package/src/serve/hub-app/page-keys.ts +1 -1
- package/src/serve/hub-app/pages-frames.tsx +11 -1
- package/src/serve/hub-app/palette-st.ts +4 -4
- 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 +5 -13
- package/src/serve/hub-app/project-list.tsx +3 -6
- package/src/serve/hub-app/projects-svc.ts +6 -2
- package/src/serve/hub-app/readme.css +9 -15
- package/src/serve/hub-app/reflections-page.tsx +54 -1
- package/src/serve/hub-app/releases/releases-page.tsx +3 -2
- package/src/serve/hub-app/releases.css +0 -1
- 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 +2 -2
- 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 +57 -54
- package/src/serve/hub-app/review/lane-bar.tsx +64 -0
- 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-cells.tsx +86 -105
- package/src/serve/hub-app/review/review-list.tsx +104 -47
- package/src/serve/hub-app/review/review-page.tsx +5 -4
- package/src/serve/hub-app/review/review-st.ts +68 -28
- package/src/serve/hub-app/review/review-thread.tsx +171 -40
- package/src/serve/hub-app/review/review-views.tsx +35 -31
- package/src/serve/hub-app/review/thread-close.tsx +124 -0
- package/src/serve/hub-app/review/thread-control.tsx +4 -4
- package/src/serve/hub-app/review/thread-st.ts +222 -22
- package/src/serve/hub-app/review/trailer-card.tsx +1 -1
- package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
- package/src/serve/hub-app/review.css +216 -57
- package/src/serve/hub-app/section-head.tsx +51 -0
- package/src/serve/hub-app/social/calendar.tsx +5 -11
- package/src/serve/hub-app/social/comms-page.tsx +23 -10
- package/src/serve/hub-app/social/kit.tsx +8 -15
- package/src/serve/hub-app/social/next-release.tsx +3 -5
- package/src/serve/hub-app/social/post-card.tsx +3 -0
- 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/social-model.ts +13 -5
- package/src/serve/hub-app/social/social-page.tsx +1 -1
- package/src/serve/hub-app/social/social-st.ts +42 -5
- package/src/serve/hub-app/social.css +7 -17
- package/src/serve/hub-app/space.css +1 -1
- package/src/serve/hub-app/stores/stores-page.tsx +6 -2
- 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-view.tsx +2 -1
- package/src/serve/hub-app/time.css +2 -5
- package/src/serve/hub-app/tree-row.tsx +1 -9
- package/src/serve/hub-app/vault-view.tsx +4 -4
- package/src/serve/hub-app/veille/veille-page.tsx +2 -11
- package/src/serve/hub-app/veille.css +0 -1
- package/src/serve/hub-app/waiting-svc.ts +4 -4
- 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 +4 -3
- package/src/serve/hub-runtime.ts +20 -6
- package/src/serve/project-gutter-route.ts +16 -6
- package/src/serve/project-gutter.ts +6 -53
- package/src/serve/same-origin.ts +3 -0
- package/src/serve/secret-gate.ts +21 -0
- package/src/serve/serve-hub.ts +29 -20
- package/src/serve/tailnet-caller.ts +117 -0
- package/src/shipkit.ts +2 -2
- package/src/site/desk.ts +2 -2
- package/src/smoke/run-smoke.ts +3 -4
- package/src/social/brands.ts +4 -0
- package/src/social/card-drafts.ts +11 -19
- package/src/social/desk-index.ts +34 -13
- package/src/social/drafts.ts +4 -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 +89 -64
- package/src/social/media-kind.ts +68 -161
- 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/index.ts +17 -5
- package/src/social/publish/secret.ts +2 -2
- package/src/social/release-stage.ts +58 -57
- package/src/social/routes.ts +64 -24
- package/src/social/stage.ts +42 -57
- package/src/social/text.ts +4 -3
- package/src/social/thumbnail.ts +135 -43
- package/src/social/tracker.ts +1 -1
- package/src/social/writes.ts +12 -29
- package/src/stores/desk.ts +16 -11
- package/src/stores/unit.ts +2 -2
- package/src/trailer/sound/eleven.ts +33 -3
- package/src/urls/rows.ts +1 -1
- package/src/vault/vault-http.ts +11 -3
- package/src/vault/vault-import.ts +6 -1
- 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 -424
- package/src/messages/suggest.ts +0 -96
- package/src/social/migrate.ts +0 -123
package/src/hq/hq-db.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { KINDS } from './kinds/index.ts'
|
|
|
10
10
|
/** what a daemon and the hq must agree on to talk: a daemon that speaks another one is told to update */
|
|
11
11
|
export const HQ_SCHEMA_VERSION = 1
|
|
12
12
|
/** the version of the file's own tables: a new table or a new kind of row raises it, and the open makes them */
|
|
13
|
-
export const HQ_FILE_VERSION =
|
|
13
|
+
export const HQ_FILE_VERSION = 13
|
|
14
14
|
|
|
15
15
|
/** moves the file for one process (a test, a drill) */
|
|
16
16
|
export const HQ_DB_ENV = 'SHIPKIT_HQ_DB'
|
|
@@ -30,6 +30,8 @@ export const hqDbPath = (): string => process.env[HQ_DB_ENV] ?? join(homeDir(),
|
|
|
30
30
|
// Before them a node had one outbox, kept on its row: `nodes.epoch` and `nodes.applied` say it no more
|
|
31
31
|
// vault_tokens a node's vault token by its accessor and its entity, never the token; `dirty` while the vault may
|
|
32
32
|
// not match the node's grants or its end (vault-grant.ts)
|
|
33
|
+
// vault_readers the tailnet device a node reads the vault from, bound at its first mint over the tailnet, and its
|
|
34
|
+
// last read through the vault route (vault-route.ts): one row a node, gone with its end
|
|
33
35
|
// meta the file's own words: its `name`, made once and kept by a restore, and the feed's generation `gen`
|
|
34
36
|
// wanted a switch value the hq's console wants a node to take (sk hq switch): given to that node alone at its
|
|
35
37
|
// hello, `done` once a report of that node shows the value
|
|
@@ -52,6 +54,7 @@ create table if not exists meta (name text primary key, value text not null) wit
|
|
|
52
54
|
create table if not exists outboxes (node text not null, epoch text not null, applied integer not null, primary key (node, epoch)) without rowid;
|
|
53
55
|
create table if not exists wanted (node text not null, name text not null, value integer not null, at integer not null, done integer, primary key (node, name)) without rowid;
|
|
54
56
|
create table if not exists vault_tokens (node text primary key, accessor text not null, entity text not null, minted integer not null, dirty integer not null default 0) without rowid;
|
|
57
|
+
create table if not exists vault_readers (node text primary key, device text not null, name text not null, os text not null, bound integer not null, read_at integer) without rowid;
|
|
55
58
|
`
|
|
56
59
|
|
|
57
60
|
/** the count a node of each kind, read again from the kinds' own tables */
|
package/src/hq/hq-local.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { flush, openDaemonDb, Outbox } from './outbox.ts'
|
|
|
18
18
|
import { buildReport } from './report.ts'
|
|
19
19
|
import type { AskSeen } from './files-send.ts'
|
|
20
20
|
import { markVault, settleVault, vaultDrift, type VaultMinter } from './vault-grant.ts'
|
|
21
|
+
import { vaultReaders, type VaultReader } from './vault-route.ts'
|
|
21
22
|
import { nameProblem } from '../core/scope.ts'
|
|
22
23
|
import { vaultInitialised, vaultPlace, vaultUrl } from '../vault/vault-config.ts'
|
|
23
24
|
import { VaultApi } from '../vault/vault-http.ts'
|
|
@@ -97,15 +98,19 @@ function vaultTokenAge(now: number): number | null {
|
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
/** the vault this daemon reads: the one beside the hq it carries, on loopback
|
|
101
|
-
*
|
|
102
|
-
export const vaultJobDue = (): boolean => carriesHq()
|
|
101
|
+
/** the vault this daemon reads: the one beside the hq it carries, on loopback, or the master beside the hq it joined
|
|
102
|
+
* on another Mac, through that hq's vault route (vault-route.ts) */
|
|
103
|
+
export const vaultJobDue = (): boolean => (carriesHq() ? vaultInitialised() : readHqToken() != null)
|
|
104
|
+
|
|
105
|
+
/** the master's vault route as this daemon reaches it, with its hq token beside the vault token */
|
|
106
|
+
export const masterVault = (token: string, timeoutMs = 5_000): VaultApi => new VaultApi(`${hqUrl().replace(/\/$/, '')}/hq/vault`, token, timeoutMs, { authorization: `Bearer ${readHqToken() ?? ''}` })
|
|
103
107
|
|
|
104
108
|
/** the vault job's body, in its child: the hq's rows settled (through the daemon, the one writer of its file), then
|
|
105
109
|
* this daemon's vault token asked again when it is half a day old or the vault refuses it. It never touches a keychain */
|
|
106
110
|
export async function vaultJob(o: { print: (l: string) => void; printErr: (l: string) => void; now?: number }): Promise<void> {
|
|
107
111
|
const now = o.now ?? Date.now()
|
|
108
112
|
if (!vaultJobDue()) return
|
|
113
|
+
if (!carriesHq()) return joinedVaultJob(o, now)
|
|
109
114
|
const checked = await askVaultCheck()
|
|
110
115
|
if ('refused' in checked) o.printErr(`WARN vault: the hq's rows were not settled: ${checked.refused}`)
|
|
111
116
|
const age = vaultTokenAge(now)
|
|
@@ -119,6 +124,20 @@ export async function vaultJob(o: { print: (l: string) => void; printErr: (l: st
|
|
|
119
124
|
if (vaultSnapshotsOn()) await vaultSnapshotJob(o, now)
|
|
120
125
|
}
|
|
121
126
|
|
|
127
|
+
/** a daemon that joined an hq on another Mac: its vault token asked again through that hq when it is half a day old
|
|
128
|
+
* or the master's vault route refuses it. Quiet while the hq is not reached or runs beside no vault: the reads say
|
|
129
|
+
* the cause loudly, at the moment one is asked */
|
|
130
|
+
async function joinedVaultJob(o: { print: (l: string) => void; printErr: (l: string) => void }, now: number): Promise<void> {
|
|
131
|
+
const age = vaultTokenAge(now)
|
|
132
|
+
const token = readVaultToken()
|
|
133
|
+
const alive = token != null && (await masterVault(token).lookupSelf().then(() => true, () => false))
|
|
134
|
+
if (age != null && age < VAULT_TOKEN_AGE_MS && alive) return
|
|
135
|
+
const r = await refreshVaultToken()
|
|
136
|
+
if (!('refused' in r)) return o.print(`ok: vault: a new vault token from the hq at ${new URL(hqUrl()).host}, for the master's vault route`)
|
|
137
|
+
if (/is not reached|runs beside no vault/.test(r.refused)) return
|
|
138
|
+
o.printErr(`WARN vault: no vault token for this daemon: ${r.refused}`)
|
|
139
|
+
}
|
|
140
|
+
|
|
122
141
|
/** the vault's sealed copy in the Space, once a day and after a change (vault/vault-snapshot.ts) */
|
|
123
142
|
async function vaultSnapshotJob(o: { print: (l: string) => void; printErr: (l: string) => void }, now: number): Promise<void> {
|
|
124
143
|
const { snapshotTick } = await import('../vault/vault-snapshot.ts')
|
|
@@ -250,7 +269,8 @@ export async function carriedHqRoute(req: Request, path: string): Promise<Respon
|
|
|
250
269
|
const store = carriedHq()
|
|
251
270
|
if (store == null) return Response.json({ refused: 'the hq of this machine does not open its file' }, { status: 503 })
|
|
252
271
|
try {
|
|
253
|
-
|
|
272
|
+
const { houseTailnet } = await import('../serve/tailnet-caller.ts')
|
|
273
|
+
return await hqRoute(store, req, path, Date.now, carriedMinter, carriedDoorKey, { who: houseTailnet, ownMachine: machineKey() })
|
|
254
274
|
} catch (e) {
|
|
255
275
|
console.error(`WARN the hq failed ${req.method} ${path}: ${(e as Error).message}`)
|
|
256
276
|
return Response.json({ refused: 'the hq failed this call: the log of its daemon says why' }, { status: 500 })
|
|
@@ -383,6 +403,8 @@ export async function hqAdminRoute(req: Request, path: string, now: number = Dat
|
|
|
383
403
|
const { failed } = await settleVault(store, api).catch((e: unknown) => ({ failed: [(e as Error).message] }))
|
|
384
404
|
return Response.json({ ended, vault: failed.length === 0 ? 'its vault token is revoked and its folders closed' : `NOT reached, retried at the next mint or check: ${failed.join('; ')}` })
|
|
385
405
|
}
|
|
406
|
+
// the other Macs bound to read the vault through the hq's vault route, for sk vault status: names and days only
|
|
407
|
+
if (path === '/api/home/hq/vault-readers') return Response.json({ readers: vaultReaders(store) })
|
|
386
408
|
// what differs between the vault and the grants, for the house check: never a value, never a token
|
|
387
409
|
if (path === '/api/home/hq/vault-check') {
|
|
388
410
|
const api = carriedMinter()
|
|
@@ -411,6 +433,17 @@ export async function hqAdminRoute(req: Request, path: string, now: number = Dat
|
|
|
411
433
|
return null
|
|
412
434
|
}
|
|
413
435
|
|
|
436
|
+
/** the readers of this machine's vault on other Macs, asked of its daemon (the one process that opens the hq's
|
|
437
|
+
* file); null when it does not answer */
|
|
438
|
+
export async function askVaultReaders(): Promise<VaultReader[] | null> {
|
|
439
|
+
try {
|
|
440
|
+
const r = await fetch(`http://127.0.0.1:${daemonPort()}/api/home/hq/vault-readers`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}', signal: AbortSignal.timeout(5_000) })
|
|
441
|
+
return r.ok ? ((await r.json()) as { readers: VaultReader[] }).readers : null
|
|
442
|
+
} catch {
|
|
443
|
+
return null
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
414
447
|
export type VaultCheck = { vault: false } | { vault: true; problems: string[]; nodes: number } | Refused
|
|
415
448
|
|
|
416
449
|
/** what differs between this machine's vault and the grants of the hq it carries, asked of its daemon (the one
|
package/src/hq/hq-routes.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type { Asked, Lack, ReadPage } from './kinds/kind.ts'
|
|
|
6
6
|
import type { HqLink } from './outbox.ts'
|
|
7
7
|
import { rulesOf } from './kinds/index.ts'
|
|
8
8
|
import { markVault, settleVault, vaultTokenFor, type VaultMinter } from './vault-grant.ts'
|
|
9
|
+
import { mintProof, VAULT_ROUTE, vaultRoute } from './vault-route.ts'
|
|
10
|
+
import type { TailnetWho } from '../serve/tailnet-caller.ts'
|
|
9
11
|
|
|
10
12
|
export const HQ_PREFIX = '/hq/'
|
|
11
13
|
|
|
@@ -37,10 +39,13 @@ const schemaRefusal = (theirs: number): string | null =>
|
|
|
37
39
|
theirs === HQ_SCHEMA_VERSION ? null : `the hq speaks schema ${HQ_SCHEMA_VERSION}, this daemon ${theirs}: update ${theirs < HQ_SCHEMA_VERSION ? 'this machine' : 'the hq'} (git pull in the house checkout)`
|
|
38
40
|
|
|
39
41
|
/** null for a path that is not the hq's. `vault`: the minter of the vault beside this hq, absent where none runs.
|
|
40
|
-
* `door`: the door key of a node (hq/door.ts), null while the hq's proxy is off
|
|
41
|
-
|
|
42
|
+
* `door`: the door key of a node (hq/door.ts), null while the hq's proxy is off. `who`: this Mac's tailscale, which
|
|
43
|
+
* names the device of a call that came over the tailnet (none: the vault route reads for nobody); `ownMachine`: the
|
|
44
|
+
* key of the machine that carries the hq, the only one whose node asks a vault token on loopback */
|
|
45
|
+
export async function hqRoute(store: HqStore, req: Request, path: string, now: () => number = Date.now, vault?: VaultMinter, door?: (node: string) => Promise<string | null>, o: { who?: TailnetWho; ownMachine?: string } = {}): Promise<Response | null> {
|
|
42
46
|
if (!path.startsWith(HQ_PREFIX)) return null
|
|
43
47
|
const route = path.slice(HQ_PREFIX.length)
|
|
48
|
+
if (route.startsWith(VAULT_ROUTE)) return vaultRoute(store, req, route.slice(VAULT_ROUTE.length), now(), { ...(vault == null ? {} : { vault }), ...(o.who == null ? {} : { who: o.who }) })
|
|
44
49
|
if (route === 'join' && req.method === 'POST') {
|
|
45
50
|
const big = tooBig(req, MAX_JOIN_BYTES)
|
|
46
51
|
if (big != null) return big
|
|
@@ -104,8 +109,11 @@ export async function hqRoute(store: HqStore, req: Request, path: string, now: (
|
|
|
104
109
|
}
|
|
105
110
|
// the caller's own token only: the node is the one its hq token names, whatever the body says
|
|
106
111
|
if (route === 'vault-token' && req.method === 'POST') {
|
|
112
|
+
const proof = await mintProof(store, req, node, o)
|
|
113
|
+
if ('refused' in proof) return json(proof, 403)
|
|
107
114
|
if (vault == null) return json({ refused: 'this hq runs beside no vault' }, 503)
|
|
108
115
|
const r = await vaultTokenFor(store, vault, node.id, now())
|
|
116
|
+
if (!('refused' in r)) proof.bind(now())
|
|
109
117
|
return json(r, 'refused' in r ? 409 : 200)
|
|
110
118
|
}
|
|
111
119
|
if (route === 'machines' && req.method === 'GET') return json({ you: node.id, machines: store.machines(node.id) })
|
package/src/hq/hq-store.ts
CHANGED
|
@@ -228,6 +228,7 @@ export class HqStore {
|
|
|
228
228
|
/** end every live node of one machine and OS user, for the daemon that carries this hq and lost its token: it
|
|
229
229
|
* writes the file itself, so it needs no proof. Never reached from a route */
|
|
230
230
|
endNodesOf(machine: string, osUser: string, now: number, except = ''): number {
|
|
231
|
+
this.db.query('delete from vault_readers where node in (select id from nodes where machine = ? and os_user = ? and ended is null and id <> ?)').run(machine, osUser, except)
|
|
231
232
|
return this.db.query('update nodes set ended = ? where machine = ? and os_user = ? and ended is null and id <> ?').run(now, machine, osUser, except).changes
|
|
232
233
|
}
|
|
233
234
|
|
|
@@ -255,7 +256,7 @@ export class HqStore {
|
|
|
255
256
|
const out = { go: o.go, machine: id, name, door: machineLabel(name), nodes: nodes.length, keeps }
|
|
256
257
|
if (!o.go) return out
|
|
257
258
|
this.db.transaction(() => {
|
|
258
|
-
for (const n of ids) for (const t of ['grants', 'outboxes', 'wanted', 'usage']) this.db.query(`delete from ${t} where node = ?`).run(n)
|
|
259
|
+
for (const n of ids) for (const t of ['grants', 'outboxes', 'wanted', 'usage', 'vault_readers']) this.db.query(`delete from ${t} where node = ?`).run(n)
|
|
259
260
|
this.db.query('delete from nodes where machine = ?').run(id)
|
|
260
261
|
this.db.query('delete from machines where id = ?').run(id)
|
|
261
262
|
}).immediate()
|
|
@@ -264,7 +265,10 @@ export class HqStore {
|
|
|
264
265
|
|
|
265
266
|
/** end a node: its token is refused from now on. False when no live node has that id */
|
|
266
267
|
end(id: string, now: number): boolean {
|
|
267
|
-
|
|
268
|
+
const ended = this.db.query('update nodes set ended = ? where id = ? and ended is null').run(now, id).changes > 0
|
|
269
|
+
// its device reads the vault no more: a new node binds its own
|
|
270
|
+
if (ended) this.db.query('delete from vault_readers where node = ?').run(id)
|
|
271
|
+
return ended
|
|
268
272
|
}
|
|
269
273
|
|
|
270
274
|
/** a row of a kind this code does not know opens nothing: never read as `all` */
|
package/src/hq/kinds/ask.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// one ask
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// once (closed wins over open, then the newest), with the nodes that hold it.
|
|
5
|
-
// row out; the ask stays while another node holds it
|
|
1
|
+
// one ask of a repo as one node holds it (wiki preferences/human-loop): its number, title, state and dates, never its
|
|
2
|
+
// words. The ask lives in the repo's thread store (asks/ask-store.ts): the row is the index. A row is named by the
|
|
3
|
+
// repo's key, the ask's id and the node, so two machines that hold one ask hold one row each, and a read gives the ask
|
|
4
|
+
// once (closed wins over open, then the newest), with the nodes that hold it. An ask gone from a node takes that
|
|
5
|
+
// node's row out; the ask stays while another node holds it
|
|
6
6
|
import { createHash } from 'crypto'
|
|
7
7
|
import { afterMs } from '../../asks/ask-after.ts'
|
|
8
8
|
import { isHistoryRepo } from './prompt.ts'
|
|
@@ -11,7 +11,7 @@ import { kind, type Lack } from './kind.ts'
|
|
|
11
11
|
/** `after`: the day the ask waits for (asks/ask-after.ts), absent when it names none, so a row without one keeps the
|
|
12
12
|
* shape an older hq takes */
|
|
13
13
|
export type AskFacts = { repo: string; name: string; number: number | null; slug: string; title: string; state: AskState; kind: string; blocks: string; pinged: string | null; created: string; closed: string | null; after?: string }
|
|
14
|
-
/** open, done, or declined by the owner (asks/
|
|
14
|
+
/** open, done, or declined by the owner (asks/ask-store.ts CLOSED) */
|
|
15
15
|
export type AskState = 'open' | 'done' | 'declined'
|
|
16
16
|
const STATES: readonly unknown[] = ['open', 'done', 'declined']
|
|
17
17
|
/** an ask that left this node's checkout */
|
package/src/hq/outbox.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { randomBytes } from 'crypto'
|
|
|
7
7
|
import { foldRefusal, machineDbPath, refusalText, storeHome } from '../core/machine-db.ts'
|
|
8
8
|
import { migrateTo, openWith } from '../ledger/db.ts'
|
|
9
9
|
import { CARD_DB_SCHEMA } from '../review/card-db.ts'
|
|
10
|
+
import { EVENTS_SCHEMA } from '../review/events.ts'
|
|
10
11
|
import { ownerOnly } from './hq-db.ts'
|
|
11
12
|
import { MAX_CALL_ROW_BYTES, MAX_ROWS, type Grant, type Refused, type RowIn } from './hq-store.ts'
|
|
12
13
|
import { KINDS, kindOf } from './kinds/index.ts'
|
|
@@ -79,13 +80,14 @@ create index if not exists history_sent_keys on history_sent (id);
|
|
|
79
80
|
create index if not exists history_forgotten_keys on history_forgotten (id);
|
|
80
81
|
create index if not exists history_days_keys on history_days (day, repo);
|
|
81
82
|
create index if not exists media_kept_keys on media_kept (key);
|
|
82
|
-
${CARD_DB_SCHEMA}
|
|
83
|
+
${CARD_DB_SCHEMA}
|
|
84
|
+
${EVENTS_SCHEMA}`
|
|
83
85
|
|
|
84
86
|
/** the version of the daemon's own tables: a new table raises it */
|
|
85
|
-
export const DAEMON_DB_VERSION =
|
|
87
|
+
export const DAEMON_DB_VERSION = 14
|
|
86
88
|
|
|
87
89
|
/** every table of the daemon's: the same names in its own file and in the machine db once folded */
|
|
88
|
-
export const DAEMON_TABLES = ['outbox', 'meta', 'sent', 'pending', 'retry', 'kept', 'waiting', 'scanned', 'history_sent', 'history_forgotten', 'history_days', 'history_pending', 'files_sent', 'files_pending', 'media_pending', 'media_kept', 'review_cards', 'review_msgs', 'review_gone', 'review_replaced', 'review_repos'] as const
|
|
90
|
+
export const DAEMON_TABLES = ['outbox', 'meta', 'sent', 'pending', 'retry', 'kept', 'waiting', 'scanned', 'history_sent', 'history_forgotten', 'history_days', 'history_pending', 'files_sent', 'files_pending', 'media_pending', 'media_kept', 'review_cards', 'review_msgs', 'review_gone', 'review_replaced', 'review_repos', 'thread_events', 'thread_post_groups', 'thread_posts'] as const
|
|
89
91
|
|
|
90
92
|
/** the row of the machine db that says which version its daemon tables are (its own version is the machine db's) */
|
|
91
93
|
export const DAEMON_VERSION_ROW = 'daemon-db-version'
|
package/src/hq/replica.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface HqReplica {
|
|
|
18
18
|
region: string
|
|
19
19
|
/** the replica's folder in the bucket, `hq` when absent */
|
|
20
20
|
path?: string
|
|
21
|
-
/** the secret whose value is `KEY:SECRET`, read through
|
|
21
|
+
/** the secret whose value is `KEY:SECRET`, read through the house store */
|
|
22
22
|
secret: string
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -43,7 +43,6 @@ export async function houseReplica(cwd: string = process.cwd()): Promise<Replica
|
|
|
43
43
|
const c = await loadRepoConfig(house)
|
|
44
44
|
const replica = c.serve?.hqReplica
|
|
45
45
|
if (!replica) return { why: `the house config (${house}) names no serve.hqReplica: the hq has no second copy`, configured: false }
|
|
46
|
-
if (!c.credsReadCommand) return { why: `the house config (${house}) declares no credsReadCommand to read ${replica.secret}`, configured: true }
|
|
47
46
|
let pair = ''
|
|
48
47
|
try {
|
|
49
48
|
pair = await readThrough(c.credsReadCommand, replica.secret)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// the vault route (wiki services/secrets, Another Mac): the one vault, the master beside the hq, read by another
|
|
2
|
+
// machine of the house through the hq's port, which tailscale serves to the tailnet over https. bao itself never
|
|
3
|
+
// leaves loopback. A read passes only as a GET of a name, its metadata, the token's own lookup or the health, from a
|
|
4
|
+
// live node (its hq token), from the tailnet device bound to that node (tailscale's whois), with the vault token the
|
|
5
|
+
// hq gave that node; then bao applies the node's policy. The one constraint a reader breaks first: a node token
|
|
6
|
+
// holds create, update and delete on its folders, so the method and path filter below is the route's only write
|
|
7
|
+
// guard, and the upstream request is built from the matched path and the vault token alone
|
|
8
|
+
import type { HqNode, HqStore, Refused } from './hq-store.ts'
|
|
9
|
+
import type { VaultMinter } from './vault-grant.ts'
|
|
10
|
+
import { isPhone, ownersDevice, servedCaller, type TailnetPeer, type TailnetWho } from '../serve/tailnet-caller.ts'
|
|
11
|
+
|
|
12
|
+
/** the route's prefix under the hq's own `/hq/` */
|
|
13
|
+
export const VAULT_ROUTE = 'vault/'
|
|
14
|
+
/** one call to bao on loopback: a reader on another machine waits 1.5 s in all (secrets/read.ts) */
|
|
15
|
+
const BAO_MS = 1_000
|
|
16
|
+
/** a reader row's last read is written at most once a minute a node */
|
|
17
|
+
const READ_MARK_MS = 60_000
|
|
18
|
+
|
|
19
|
+
const SEGMENT = '[a-z0-9_~-][a-z0-9._~-]*'
|
|
20
|
+
/** what passes, matched on the path tailscaled and URL normalised: a segment never of dots alone, never `*` */
|
|
21
|
+
const PASSES = new RegExp(`^v1/(?:rv/(?:data|metadata)/${SEGMENT}(?:/${SEGMENT})*|auth/token/lookup-self|sys/health)$`)
|
|
22
|
+
|
|
23
|
+
/** the bao path a request may read, or null: GET only, no query, the shape above */
|
|
24
|
+
export function passing(req: Request, rest: string): string | null {
|
|
25
|
+
if (req.method !== 'GET' || new URL(req.url).search !== '') return null
|
|
26
|
+
return PASSES.test(rest) ? rest : null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Reader = { node: string; device: string; name: string; os: string; bound: number; read_at: number | null }
|
|
30
|
+
export const readerOf = (store: HqStore, node: string): Reader | null => store.db.query('select node, device, name, os, bound, read_at from vault_readers where node = ?').get(node) as Reader | null
|
|
31
|
+
|
|
32
|
+
/** `errors` as bao words its own, so a reader's vault client says the route's reason */
|
|
33
|
+
const refuse = (refused: string, status = 403): Response => Response.json({ refused, errors: [refused] }, { status })
|
|
34
|
+
|
|
35
|
+
/** the tailnet device a request came from, an untagged device of the hq Mac's owner and no phone; or why not */
|
|
36
|
+
async function deviceOf(req: Request, who: TailnetWho | undefined): Promise<TailnetPeer | Refused> {
|
|
37
|
+
const caller = servedCaller(req.headers)
|
|
38
|
+
if ('refused' in caller) return caller
|
|
39
|
+
if (who == null) return { refused: 'this hq asks no tailscale: it reads no tailnet device' }
|
|
40
|
+
const self = await who.self()
|
|
41
|
+
if (self == null) return { refused: 'tailscale does not answer on the Mac that carries the hq' }
|
|
42
|
+
const peer = await ownersDevice(who, self, caller)
|
|
43
|
+
if ('refused' in peer) return peer
|
|
44
|
+
if (isPhone(peer)) return { refused: `${peer.node} is a phone: no reader of the vault` }
|
|
45
|
+
return peer
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const otherDevice = (peer: TailnetPeer, r: Reader): string =>
|
|
49
|
+
peer.node === r.name
|
|
50
|
+
? `${peer.node} came back under another tailscale id than the one bound to this node (a logout and login of tailscale): on the Mac that carries the hq, sk hq end <this node>, then a new invite`
|
|
51
|
+
: `${peer.node} is not the device bound to this node (${r.name}): a node reads the vault from its own device only`
|
|
52
|
+
|
|
53
|
+
/** `GET /hq/vault/v1/<path>`: every proof, then bao's answer with its content type alone */
|
|
54
|
+
export async function vaultRoute(store: HqStore, req: Request, rest: string, now: number, o: { vault?: VaultMinter; who?: TailnetWho }): Promise<Response> {
|
|
55
|
+
const path = passing(req, rest)
|
|
56
|
+
if (path == null) return refuse('the vault route answers a GET of a name, its metadata, lookup-self or the health, and nothing else', 404)
|
|
57
|
+
const token = /^Bearer (.+)$/.exec(req.headers.get('authorization') ?? '')?.[1] ?? ''
|
|
58
|
+
const node = store.nodeOf(token)
|
|
59
|
+
if (node == null) return refuse('this hq token is unknown or was ended: the vault route reads for a live node only')
|
|
60
|
+
const peer = await deviceOf(req, o.who)
|
|
61
|
+
if ('refused' in peer) return refuse(peer.refused)
|
|
62
|
+
const r = readerOf(store, node.id)
|
|
63
|
+
if (r == null) return refuse('this node has no device bound: its first vault token asked over the tailnet binds the device it came from')
|
|
64
|
+
if (peer.id !== r.device) return refuse(otherDevice(peer, r))
|
|
65
|
+
const vaultToken = req.headers.get('x-vault-token') ?? ''
|
|
66
|
+
if (vaultToken === '') return refuse('no vault token: ask your hq for one (the vault job of your daemon)')
|
|
67
|
+
const api = o.vault?.()
|
|
68
|
+
if (api == null) return refuse("the Mac that carries the hq runs no vault, or it is not initialised (sk vault status there)", 503)
|
|
69
|
+
const held = store.db.query('select accessor from vault_tokens where node = ?').get(node.id) as { accessor: string } | null
|
|
70
|
+
let accessor: string | null = null
|
|
71
|
+
try {
|
|
72
|
+
const look = await fetch(`${api.url}/v1/auth/token/lookup-self`, { headers: { 'X-Vault-Token': vaultToken }, signal: AbortSignal.timeout(BAO_MS) })
|
|
73
|
+
const body = (await look.json().catch(() => ({}))) as { data?: { accessor?: string } }
|
|
74
|
+
if (look.ok) accessor = body.data?.accessor ?? null
|
|
75
|
+
} catch (e) {
|
|
76
|
+
return refuse(`the vault does not answer on the Mac that carries the hq: ${(e as Error).message}`, 503)
|
|
77
|
+
}
|
|
78
|
+
if (accessor == null) return refuse('this vault token is dead or unknown to the vault: ask your hq for a new one')
|
|
79
|
+
if (held == null || held.accessor !== accessor) return refuse('this vault token is not the one the hq gave this node: ask your hq for a new one')
|
|
80
|
+
let up: Response
|
|
81
|
+
try {
|
|
82
|
+
up = await fetch(`${api.url}/${path}`, { method: 'GET', headers: { 'X-Vault-Token': vaultToken }, redirect: 'manual', signal: AbortSignal.timeout(BAO_MS) })
|
|
83
|
+
} catch (e) {
|
|
84
|
+
return refuse(`the vault does not answer on the Mac that carries the hq: ${(e as Error).message}`, 503)
|
|
85
|
+
}
|
|
86
|
+
if (r.read_at == null || now - r.read_at >= READ_MARK_MS) store.db.query('update vault_readers set read_at = ? where node = ?').run(now, node.id)
|
|
87
|
+
return new Response(await up.arrayBuffer(), { status: up.status, headers: { 'content-type': up.headers.get('content-type') ?? 'application/json' } })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** a mint's own proof, before any call to bao: over the tailnet, the device bound to the node (or none bound yet);
|
|
91
|
+
* with no forwarded header, only a node of the hq's own machine with no device bound. `bind` keeps the device once
|
|
92
|
+
* the mint made its token */
|
|
93
|
+
export async function mintProof(store: HqStore, req: Request, node: HqNode, o: { who?: TailnetWho; ownMachine?: string }): Promise<{ bind: (now: number) => void } | Refused> {
|
|
94
|
+
const r = readerOf(store, node.id)
|
|
95
|
+
if (!req.headers.has('x-forwarded-for')) {
|
|
96
|
+
if (o.ownMachine != null && node.machine !== o.ownMachine) return { refused: 'a vault token for a node of another machine is asked over the tailnet, never on loopback' }
|
|
97
|
+
if (r != null) return { refused: `this node reads the vault from the device bound to it (${r.name}): it asks its token from there` }
|
|
98
|
+
return { bind: () => {} }
|
|
99
|
+
}
|
|
100
|
+
const peer = await deviceOf(req, o.who)
|
|
101
|
+
if ('refused' in peer) return peer
|
|
102
|
+
if (r != null) return peer.id === r.device ? { bind: () => {} } : { refused: otherDevice(peer, r) }
|
|
103
|
+
return {
|
|
104
|
+
bind: (now) => void store.db.query('insert into vault_readers (node, device, name, os, bound) values (?, ?, ?, ?, ?) on conflict (node) do nothing').run(node.id, peer.id, peer.node, peer.os, now),
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type VaultReader = { node: string; machine: string; device: string; os: string; bound: number; readAt: number | null; minted: number | null }
|
|
109
|
+
|
|
110
|
+
/** every live node bound to a device, for `sk vault status` and the page: names and days, never a token */
|
|
111
|
+
export const vaultReaders = (store: HqStore): VaultReader[] =>
|
|
112
|
+
(store.db.query('select r.node, m.name as machine, r.name as device, r.os, r.bound, r.read_at as readAt, t.minted from vault_readers r join nodes n on n.id = r.node and n.ended is null join machines m on m.id = n.machine left join vault_tokens t on t.node = r.node order by m.name').all() as VaultReader[])
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { existsSync } from 'node:fs'
|
|
6
6
|
import { join } from 'node:path'
|
|
7
7
|
import { type Collection, type Instance } from '../collections/collection-types.ts'
|
|
8
|
-
import {
|
|
8
|
+
import { HOUSE_LAYOUT } from '../core/house-layout.ts'
|
|
9
9
|
import { DEFAULT_HOME_PORT } from '../home/home-paths.ts'
|
|
10
10
|
import { identityAddress } from '../serve/hub-app/identity-address.ts'
|
|
11
11
|
import { readIdentities, type Identities } from './identities.ts'
|
|
@@ -43,7 +43,7 @@ export function pictureNeeds(ids: Identities, home = `http://127.0.0.1:${DEFAULT
|
|
|
43
43
|
|
|
44
44
|
/** only in the repo that holds the identities folder, the house repo */
|
|
45
45
|
export function picturesCollection(root: string): Collection | null {
|
|
46
|
-
const dir = join(root,
|
|
46
|
+
const dir = join(root, HOUSE_LAYOUT.identities)
|
|
47
47
|
if (!existsSync(dir)) return null
|
|
48
48
|
return { id: PICTURES_COL, title: 'pictures', kind: 'ask', media: 'text', list: async () => pictureNeeds(readIdentities(dir)) }
|
|
49
49
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// the identities, who speaks (wiki
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// the identities, who speaks (wiki meta/identity-folder): one folder an identity in the house repo,
|
|
2
|
+
// `wiki/identities/<id>/`, its profile, brand, accounts and their places, and a company's legal rows. A folder whose
|
|
3
|
+
// name starts with `_` (`_common/`) is the owner's, no identity. Read from the disk as it is on every call; the one
|
|
4
|
+
// constraint: never in the npm package, a project names its identity
|
|
4
5
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
5
6
|
import { homedir } from 'node:os'
|
|
6
7
|
import { isAbsolute, join } from 'node:path'
|
|
7
|
-
import {
|
|
8
|
+
import { HOUSE_LAYOUT } from '../core/house-layout.ts'
|
|
8
9
|
import { parseFrontmatter, rows, section, table, type ProfileRow } from '../social/md.ts'
|
|
9
10
|
import { ceilingOf, ratingIn, type PostRating } from './rating.ts'
|
|
10
11
|
import { uploadsOf, type Upload } from './shown.ts'
|
|
@@ -89,7 +90,7 @@ export type Account = {
|
|
|
89
90
|
footer: string
|
|
90
91
|
/** live, free, paid, limited or none */
|
|
91
92
|
automation: string
|
|
92
|
-
/** with `automation: live`, the secret name of its token, read through the house
|
|
93
|
+
/** with `automation: live`, the secret name of its token, read through the house store */
|
|
93
94
|
secret: string
|
|
94
95
|
/** Discord: the server's id, its messages' links and the bot's posts */
|
|
95
96
|
guild: string
|
|
@@ -172,7 +173,7 @@ export async function identitiesDir(cwd = process.cwd(), known?: string | null):
|
|
|
172
173
|
const env = process.env['SHIPKIT_IDENTITIES_DIR']
|
|
173
174
|
if (env) return env
|
|
174
175
|
const house = known !== undefined ? known : (await import('../home/home-start.ts')).houseRootOf(cwd)
|
|
175
|
-
return house == null ? null : join(house,
|
|
176
|
+
return house == null ? null : join(house, HOUSE_LAYOUT.identities)
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
/** the words a `write` link fills from a message (`fillLink`) */
|
|
@@ -497,12 +498,12 @@ function identity(id: string, dir: string, errors: string[]): Identity {
|
|
|
497
498
|
/** every identity in its order; a broken folder is an error line, never a silence */
|
|
498
499
|
export function readIdentities(dir: string | null): Identities {
|
|
499
500
|
const errors: string[] = []
|
|
500
|
-
if (dir == null) return { dir, identities: [], errors: [
|
|
501
|
+
if (dir == null) return { dir, identities: [], errors: [`no house repo on this machine: the identities live in its ${HOUSE_LAYOUT.identities}/`] }
|
|
501
502
|
if (!existsSync(dir)) return { dir, identities: [], errors: [`${dir}: no identities folder`] }
|
|
502
503
|
const out: Identity[] = []
|
|
503
504
|
for (const id of readdirSync(dir).sort()) {
|
|
504
505
|
const idir = join(dir, id)
|
|
505
|
-
if (!statSync(idir).isDirectory()) continue
|
|
506
|
+
if (id.startsWith('_') || !statSync(idir).isDirectory()) continue
|
|
506
507
|
if (!SLUG.test(id)) errors.push(`${idir}: an identity id is kebab case`)
|
|
507
508
|
else if (!existsSync(join(idir, 'identity.md'))) errors.push(`${idir}: no identity.md`)
|
|
508
509
|
else out.push(identity(id, idir, errors))
|
|
@@ -5,7 +5,10 @@ import { existsSync, readdirSync } from 'node:fs'
|
|
|
5
5
|
import { homedir } from 'node:os'
|
|
6
6
|
import { openInCode } from '../serve/project-gutter-route.ts'
|
|
7
7
|
import { houseRepoRoots } from '../social/house.ts'
|
|
8
|
-
import {
|
|
8
|
+
import { cardsDb } from '../review/card-db.ts'
|
|
9
|
+
import { eventsRepo } from '../review/events.ts'
|
|
10
|
+
import { storeDir } from '../review/store.ts'
|
|
11
|
+
import { postMediaDir } from '../social/post-sources.ts'
|
|
9
12
|
import { veilleLogDir } from '../veille/identity.ts'
|
|
10
13
|
import { identitiesDir, readIdentities, type Identities, type Identity } from './identities.ts'
|
|
11
14
|
import { railOf, speakerIdOf, type RailIdentity } from './machine.ts'
|
|
@@ -64,9 +67,11 @@ function placesOf(i: Identity, repos: Repo[], ids: Identities): (DataPlace & { a
|
|
|
64
67
|
if (i.files != null && i.files !== i.dir) out.push({ place: 'pictures', repo: null, label: 'its pictures (files: in identity.md)', abs: i.files, shown: '', exists: existsSync(i.files), count: null })
|
|
65
68
|
const log = veilleLogDir(i.id)
|
|
66
69
|
out.push({ place: 'veille', repo: null, label: 'its Veille log, this machine only', abs: log, shown: '', exists: existsSync(log), count: count(log, (n) => n.endsWith('.jsonl')) })
|
|
70
|
+
// a repo's posts are events of the thread store; the place shown is the copy of their files
|
|
67
71
|
for (const r of mine) {
|
|
68
|
-
const d =
|
|
69
|
-
|
|
72
|
+
const d = postMediaDir(r.path)
|
|
73
|
+
const groups = (cardsDb().query('select count(*) as n from thread_post_groups where repo = ?').get(eventsRepo(storeDir(r.path))) as { n: number } | null)?.n ?? 0
|
|
74
|
+
out.push({ place: 'drafts', repo: r.name, label: `the posts of ${r.name} (their words in the thread store), their files`, abs: d, shown: '', exists: existsSync(d), count: groups })
|
|
70
75
|
}
|
|
71
76
|
return out.map((p) => ({ ...p, shown: tilde(p.abs) }))
|
|
72
77
|
}
|
package/src/ledger/db.ts
CHANGED
|
@@ -215,7 +215,7 @@ export function openWith(path: string, o: { create?: boolean; busyMs?: number },
|
|
|
215
215
|
// another process's transaction instead of failing
|
|
216
216
|
db.exec(`pragma busy_timeout = ${busyMs}`)
|
|
217
217
|
ensureWal(db, busyMs)
|
|
218
|
-
db
|
|
218
|
+
storeSync(db, 'NORMAL')
|
|
219
219
|
schema(db)
|
|
220
220
|
return { db }
|
|
221
221
|
} catch (e) {
|
|
@@ -247,6 +247,13 @@ export function ensureWal(db: Database, busyMs: number): void {
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
/** how a store's commits wait for the disk: `onMachine` on a machine; never in a suite, whose stores are scratch
|
|
251
|
+
* files in a temp home (tests/_setup.ts sets SHIPKIT_SUITE_HOME): a write's sync, and the checkpoint's when its last
|
|
252
|
+
* connection closes, were most of a suite's sqlite time, and a killed process still loses nothing the system holds */
|
|
253
|
+
export function storeSync(db: Database, onMachine: 'FULL' | 'NORMAL'): void {
|
|
254
|
+
db.exec(`pragma synchronous = ${process.env.SHIPKIT_SUITE_HOME === '1' ? 'OFF' : onMachine}`)
|
|
255
|
+
}
|
|
256
|
+
|
|
250
257
|
const userVersion = (db: Database): number => Number((db.query('pragma user_version').get() as { user_version?: number } | null)?.user_version ?? 0)
|
|
251
258
|
|
|
252
259
|
/** a migration held for want of its copy: every open says it, the file stays as it was */
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
// 6 h whatever moved, which reads every byte again
|
|
7
7
|
import { machineGet, machineHeld, machineSet } from '../../core/machine-db.ts'
|
|
8
8
|
import type { RepoBackup } from '../../repo-config.ts'
|
|
9
|
+
import type { GitIo } from '../../core/git.ts'
|
|
10
|
+
import type { BackupRetention } from './retention.ts'
|
|
9
11
|
import type { Space } from '../space.ts'
|
|
12
|
+
import { threadStamp } from './thread-copy.ts'
|
|
10
13
|
import { backupRun, lastRun } from './run.ts'
|
|
11
14
|
import { keepSources, keptSources, keptStamp, patchSources } from './kept.ts'
|
|
12
15
|
import { backupOfRepo, collect, localFiles, lookScope, missedBy, movesLocals, patchLocals, refreshSources, type Collect, type Source } from './sources.ts'
|
|
@@ -34,7 +37,18 @@ export const BATCH = 'backup-moved'
|
|
|
34
37
|
export const NAMED = 'backup-named'
|
|
35
38
|
|
|
36
39
|
/** `waitAt`: since when a stamp the last run did not send waits */
|
|
37
|
-
export type Stamps = { seen: string; ran: string; fullAt?: number; waitAt?: number }
|
|
40
|
+
export type Stamps = { seen: string; ran: string; fullAt?: number; waitAt?: number; threads?: string }
|
|
41
|
+
|
|
42
|
+
/** a write to the thread store alone wakes a run at most each hour: no file event tells it, and its snapshot is the
|
|
43
|
+
* machine db's, about 20 MB gzipped (the second copy on a peer follows it within 10 min: thread-copy.ts) */
|
|
44
|
+
export const THREADS_FLOOR_MS = 60 * 60_000
|
|
45
|
+
const threadsNow = (): string => {
|
|
46
|
+
try {
|
|
47
|
+
return threadStamp()
|
|
48
|
+
} catch {
|
|
49
|
+
return ''
|
|
50
|
+
}
|
|
51
|
+
}
|
|
38
52
|
export type Batch = { paths: string[]; all: boolean; done: boolean }
|
|
39
53
|
type Locals = Record<string, { at: number; files: string[] }>
|
|
40
54
|
|
|
@@ -58,6 +72,10 @@ export interface BackupTick {
|
|
|
58
72
|
now?: () => number
|
|
59
73
|
/** each repo's `backup` key; by default its config */
|
|
60
74
|
backupOf?: (repo: string) => Promise<RepoBackup | null>
|
|
75
|
+
/** the retention after a run; by default the house config's, null prunes nothing */
|
|
76
|
+
retention?: BackupRetention | null
|
|
77
|
+
/** what git tracks and ignores in each repo; the real git by default */
|
|
78
|
+
git?: GitIo
|
|
61
79
|
}
|
|
62
80
|
|
|
63
81
|
/** the daemon's read before it starts a look (no walk, no child): something heard, a batch a look did not take, the
|
|
@@ -70,6 +88,7 @@ export function backupDue(now: number, heard: boolean): boolean {
|
|
|
70
88
|
const last = lastRun()
|
|
71
89
|
const since = last ? now - Date.parse(last.at) : Infinity
|
|
72
90
|
if (since >= EVERY_MS) return true
|
|
91
|
+
if (since >= THREADS_FLOOR_MS && (s.threads ?? '') !== threadsNow()) return true
|
|
73
92
|
// with no Space a run never lands: only a change or a clock brings the next look
|
|
74
93
|
return s.seen !== s.ran && since >= FLOOR_MS && !machineGet<string>(NO_SPACE)
|
|
75
94
|
}
|
|
@@ -86,7 +105,7 @@ async function tick(o: BackupTick): Promise<void> {
|
|
|
86
105
|
const cachedLocals = async (repo: string): Promise<string[]> => {
|
|
87
106
|
const held = locals[repo]
|
|
88
107
|
if (held && now() - held.at < LOCALS_MS) return held.files
|
|
89
|
-
const files = await localFiles(repo)
|
|
108
|
+
const files = await localFiles(repo, o.git)
|
|
90
109
|
locals[repo] = { at: now(), files }
|
|
91
110
|
walked = true
|
|
92
111
|
return files
|
|
@@ -107,7 +126,7 @@ async function tick(o: BackupTick): Promise<void> {
|
|
|
107
126
|
for (const r of new Set(moved.map((p) => movesLocals(p, o.repos)).filter((r) => r != null))) {
|
|
108
127
|
const kept = locals[r]
|
|
109
128
|
if (kept == null) continue
|
|
110
|
-
locals[r] = { at: kept.at, files: await patchLocals(r, kept.files, moved) }
|
|
129
|
+
locals[r] = { at: kept.at, files: await patchLocals(r, kept.files, moved, o.git) }
|
|
111
130
|
walked = true
|
|
112
131
|
}
|
|
113
132
|
// each config read says its named paths: the daemon's watch hears them
|
|
@@ -118,7 +137,7 @@ async function tick(o: BackupTick): Promise<void> {
|
|
|
118
137
|
named[repo] = b?.paths ?? []
|
|
119
138
|
return b
|
|
120
139
|
}
|
|
121
|
-
const c: Collect = { home: o.home, repos: o.repos, locals: cachedLocals, backupOf }
|
|
140
|
+
const c: Collect = { home: o.home, repos: o.repos, locals: cachedLocals, backupOf, git: o.git }
|
|
122
141
|
let list: Source[] | null = null
|
|
123
142
|
let stamp: string
|
|
124
143
|
if (full) {
|
|
@@ -140,9 +159,12 @@ async function tick(o: BackupTick): Promise<void> {
|
|
|
140
159
|
if (batch && !batch.done) machineSet(BATCH, { ...batch, done: true } satisfies Batch)
|
|
141
160
|
const waitAt = stamp === held.ran ? undefined : (held.waitAt ?? started)
|
|
142
161
|
const waited = waitAt != null && started - waitAt >= WAIT_MAX_MS
|
|
143
|
-
const
|
|
162
|
+
const threads = threadsNow()
|
|
163
|
+
const threadsDue = since >= THREADS_FLOOR_MS && threads !== (held.threads ?? '')
|
|
164
|
+
const due = sixHours || threadsDue || (stamp !== held.ran && (stamp === held.seen || waited) && since >= FLOOR_MS)
|
|
144
165
|
const fullAt = full ? started : held.fullAt
|
|
145
|
-
|
|
166
|
+
const sent = held.threads != null ? { threads: held.threads } : {}
|
|
167
|
+
machineSet(STAMPS, { seen: stamp, ran: held.ran, ...(fullAt != null ? { fullAt } : {}), ...(waitAt != null ? { waitAt } : {}), ...sent } satisfies Stamps)
|
|
146
168
|
if (!due) return
|
|
147
169
|
const { space, why } = await o.space()
|
|
148
170
|
// said once per reason: a look is a child of its own
|
|
@@ -153,12 +175,30 @@ async function tick(o: BackupTick): Promise<void> {
|
|
|
153
175
|
}
|
|
154
176
|
machineSet(NO_SPACE, '')
|
|
155
177
|
const r = await backupRun(space, { ...c, sources: list ?? keptSources(o.home) ?? [], rehash: sixHours, now: new Date(now()) })
|
|
156
|
-
if (r.failed.length === 0) machineSet(STAMPS, { seen: stamp, ran: stamp, ...(fullAt != null ? { fullAt } : {}) } satisfies Stamps)
|
|
178
|
+
if (r.failed.length === 0) machineSet(STAMPS, { seen: stamp, ran: stamp, ...(fullAt != null ? { fullAt } : {}), threads } satisfies Stamps)
|
|
157
179
|
if (r.failed.length > 0) o.printErr(`WARN backup: ${r.failed.length} objects did not go up, no manifest written; first: ${r.failed[0]?.key}: ${r.failed[0]?.error}`)
|
|
158
|
-
else if (r.manifest)
|
|
180
|
+
else if (r.manifest) {
|
|
181
|
+
o.print(`ok: backup: ${r.files} files, ${r.sent} objects up (${(r.sentBytes / 1e6).toFixed(1)} MB), ${r.read} read again, ${r.refused.length} refused, manifest ${r.manifest}`)
|
|
182
|
+
await pruneAfterRun(space, { ...o, now: now() })
|
|
183
|
+
}
|
|
159
184
|
} catch (e) {
|
|
160
185
|
// a hand run holds the lock: the next look tries again, and says so (a lock that never goes stops every backup)
|
|
161
186
|
const msg = (e as Error).message
|
|
162
187
|
o.printErr(/^another backup runs/.test(msg) ? `note: backup: not now, ${msg}` : `WARN backup: the run broke: ${msg}`)
|
|
163
188
|
}
|
|
164
189
|
}
|
|
190
|
+
|
|
191
|
+
/** the retention after each run that wrote one (prune.ts): quiet when nothing goes or the house names no retention */
|
|
192
|
+
async function pruneAfterRun(space: Space, o: { print: (l: string) => void; printErr: (l: string) => void; now: number; retention?: BackupRetention | null }): Promise<void> {
|
|
193
|
+
try {
|
|
194
|
+
const { pruneBackups } = await import('./prune.ts')
|
|
195
|
+
const p = await pruneBackups(space, { apply: true, auto: true, now: o.now, ...(o.retention !== undefined ? { policy: o.retention } : {}) })
|
|
196
|
+
for (const l of p.lines) {
|
|
197
|
+
if (l.startsWith('WARN')) o.printErr(l)
|
|
198
|
+
else if (l.startsWith('ok:')) o.print(l)
|
|
199
|
+
}
|
|
200
|
+
} catch (e) {
|
|
201
|
+
const msg = (e as Error).message
|
|
202
|
+
o.printErr(/^another backup runs/.test(msg) ? `note: backup prune: not now, ${msg}` : `WARN backup prune: ${msg}`)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// where the backup keeps its objects in the private Space (wiki tools/shipkit/media-store.md, Backup): a file's bytes
|
|
2
2
|
// under `backup/<sha256>.<ext>`, a sqlite snapshot gzipped under `backup/<sha256 of the gz>.gz`, one manifest a run
|
|
3
3
|
// under `backup/runs/<time>-<machine>-<digest>.json.gz` (two Macs back up into one Space; a run from before the name is
|
|
4
|
-
// `<time>-<digest>` and names its host only inside).
|
|
4
|
+
// `<time>-<digest>` and names its host only inside). Only the retention deletes under the prefix (prune.ts)
|
|
5
5
|
export const BACKUP_LABEL = 'backup'
|
|
6
6
|
export const RUNS_PREFIX = `${BACKUP_LABEL}/runs/`
|
|
7
7
|
|