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/home/inbox.ts
CHANGED
|
@@ -1,72 +1,23 @@
|
|
|
1
|
-
// the daemon's inbox route (wiki tools/shipkit/home.md
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// the daemon's inbox route (wiki tools/shipkit/home-inbox.md): every loaded hub's thread index and needs, shaped by
|
|
2
|
+
// inbox-shape.ts. It reads memory only (each store's thread index, each hub's warm rows) and a stat per dated file, so
|
|
3
|
+
// a poll answers in milliseconds; the whole answer's hash is its ETag
|
|
4
4
|
import { statSync } from 'fs'
|
|
5
5
|
import { join } from 'path'
|
|
6
6
|
import type { Resource } from '../collections/collection-types.ts'
|
|
7
|
-
import {
|
|
7
|
+
import { afterMs } from '../asks/ask-after.ts'
|
|
8
|
+
import { partiesOfStore, storeIndex } from '../review/routes.ts'
|
|
9
|
+
import { storeDir } from '../review/store.ts'
|
|
10
|
+
import type { Parties } from '../review/parties.ts'
|
|
8
11
|
import type { Hubs } from './hubs.ts'
|
|
9
|
-
import { inboxPage, inboxQuery, inboxRows,
|
|
12
|
+
import { inboxPage, inboxQuery, inboxRows, wantsDone, type Dated, type InboxAnswer, type InboxSource } from './inbox-shape.ts'
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
/** a subject this many repos share is a sweep over the house (a toolkit bump, a doc pass), never work on the repo */
|
|
13
|
-
const SWEEP_REPOS = 3
|
|
14
|
-
const LOG_DEPTH = 200
|
|
15
|
-
|
|
16
|
-
/** one commit of a repo's log: when, and its subject with the numbers taken out (`rvlib-shipkit ^2.11.0` and
|
|
17
|
-
* `rvlib-shipkit 2.10.0` are one sweep) */
|
|
18
|
-
export interface LogLine {
|
|
19
|
-
at: number
|
|
20
|
-
subject: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const logs = new Map<string, { asked: number; lines: Promise<LogLine[] | null> }>()
|
|
24
|
-
|
|
25
|
-
/** a repo's newest commits on HEAD, asked of git at most once every 10 minutes; null when git cannot say */
|
|
26
|
-
export function recentCommits(root: string, now = Date.now()): Promise<LogLine[] | null> {
|
|
27
|
-
const hit = logs.get(root)
|
|
28
|
-
if (hit != null && now - hit.asked < COMMIT_TTL) return hit.lines
|
|
29
|
-
const lines = (async () => {
|
|
30
|
-
try {
|
|
31
|
-
const p = Bun.spawn(['git', 'log', `-${LOG_DEPTH}`, '--format=%ct%x09%s', 'HEAD'], { cwd: root, stdout: 'pipe', stderr: 'ignore' })
|
|
32
|
-
const out = await new Response(p.stdout).text()
|
|
33
|
-
if ((await p.exited) !== 0) return null
|
|
34
|
-
return out.split('\n').flatMap((l) => {
|
|
35
|
-
const tab = l.indexOf('\t')
|
|
36
|
-
const at = Number(l.slice(0, tab)) * 1000
|
|
37
|
-
return tab > 0 && Number.isFinite(at) ? [{ at, subject: l.slice(tab + 1).toLowerCase().replace(/[\d^~.]+/g, '') }] : []
|
|
38
|
-
})
|
|
39
|
-
} catch {
|
|
40
|
-
return null
|
|
41
|
-
}
|
|
42
|
-
})()
|
|
43
|
-
logs.set(root, { asked: now, lines })
|
|
44
|
-
return lines
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** per repo, its last commit of its own when the repo is quiet (none for `QUIET_DAYS`), else null. A commit whose
|
|
48
|
-
* subject `SWEEP_REPOS` repos share is a sweep and never counts; a repo git cannot read is never quiet */
|
|
49
|
-
export function quietOf(byRepo: ReadonlyMap<string, LogLine[] | null>, now = Date.now()): Map<string, number | null> {
|
|
50
|
-
const seen = new Map<string, Set<string>>()
|
|
51
|
-
for (const [repo, lines] of byRepo) for (const l of lines ?? []) seen.set(l.subject, (seen.get(l.subject) ?? new Set()).add(repo))
|
|
52
|
-
const out = new Map<string, number | null>()
|
|
53
|
-
for (const [repo, lines] of byRepo) {
|
|
54
|
-
if (lines == null || lines.length === 0) {
|
|
55
|
-
out.set(repo, null)
|
|
56
|
-
continue
|
|
57
|
-
}
|
|
58
|
-
const own = lines.find((l) => (seen.get(l.subject)?.size ?? 0) < SWEEP_REPOS) ?? lines[lines.length - 1]!
|
|
59
|
-
out.set(repo, now - own.at > QUIET_DAYS * 86_400_000 ? own.at : null)
|
|
60
|
-
}
|
|
61
|
-
return out
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** a need's file dated: an ask by its birth (its front matter keeps only the day), any other file by its last write */
|
|
14
|
+
/** a need dated: an ask by the day its thread was made, a need with a file by the file's last write */
|
|
65
15
|
export const datedIn = (root: string): Dated => (n: Resource) => {
|
|
16
|
+
if (n.collection === 'asks') return n.ask?.created != null ? afterMs(n.ask.created) : null
|
|
66
17
|
if (n.virtual === true || n.path === '') return null
|
|
67
18
|
try {
|
|
68
19
|
const s = statSync(join(root, n.path))
|
|
69
|
-
return
|
|
20
|
+
return s.mtimeMs
|
|
70
21
|
} catch {
|
|
71
22
|
return null
|
|
72
23
|
}
|
|
@@ -76,40 +27,44 @@ export const datedIn = (root: string): Dated => (n: Resource) => {
|
|
|
76
27
|
export const INBOX_SHARE_MS = 1_000
|
|
77
28
|
const shared = new WeakMap<object, { end: number | null; read: ReturnType<typeof readSources> }>()
|
|
78
29
|
|
|
30
|
+
/** a repo's parties: who holds its threads and who lives (review/band.ts reads them), the threads page's own read */
|
|
31
|
+
export type PartiesOf = (root: string) => Promise<Parties>
|
|
32
|
+
const partiesOfRepo: PartiesOf = async (root) => (await partiesOfStore(storeDir(root))).parties
|
|
33
|
+
|
|
79
34
|
/** what every hub that is up holds; concurrent pages (windows, the phone) share one read while it runs and for
|
|
80
35
|
* INBOX_SHARE_MS after it ended */
|
|
81
|
-
export function inboxSources(hubs: Pick<Hubs, 'loaded'>, now: () => number = Date.now): ReturnType<typeof readSources> {
|
|
36
|
+
export function inboxSources(hubs: Pick<Hubs, 'loaded'>, now: () => number = Date.now, partiesOf: PartiesOf = partiesOfRepo): ReturnType<typeof readSources> {
|
|
82
37
|
const held = shared.get(hubs)
|
|
83
38
|
if (held != null && (held.end == null || now() - held.end < INBOX_SHARE_MS)) return held.read
|
|
84
|
-
const entry: { end: number | null; read: ReturnType<typeof readSources> } = { end: null, read: readSources(hubs) }
|
|
39
|
+
const entry: { end: number | null; read: ReturnType<typeof readSources> } = { end: null, read: readSources(hubs, partiesOf) }
|
|
85
40
|
shared.set(hubs, entry)
|
|
86
41
|
entry.read.then(() => { entry.end = now() }, () => { if (shared.get(hubs) === entry) shared.delete(hubs) })
|
|
87
42
|
return entry.read
|
|
88
43
|
}
|
|
89
44
|
|
|
90
45
|
/** what every hub that is up holds, read in parallel; a repo whose read broke is named, never dropped silently */
|
|
91
|
-
async function readSources(hubs: Pick<Hubs, 'loaded'
|
|
46
|
+
async function readSources(hubs: Pick<Hubs, 'loaded'>, partiesOf: PartiesOf): Promise<{ sources: (InboxSource & { root: string })[]; missing: InboxAnswer['missing'] }> {
|
|
92
47
|
const missing: InboxAnswer['missing'] = []
|
|
93
48
|
const read = await Promise.all(
|
|
94
49
|
hubs.loaded().map(async ({ repo, rt }) => {
|
|
95
50
|
try {
|
|
96
|
-
const
|
|
97
|
-
|
|
51
|
+
const review = storeIndex(repo.path)
|
|
52
|
+
const [needs, parties] = await Promise.all([rt.handler.needs(), review === null ? undefined : partiesOf(repo.path)])
|
|
53
|
+
return { repo: repo.name, root: repo.path, review, needs, ...(parties ? { parties } : {}) }
|
|
98
54
|
} catch (e) {
|
|
99
55
|
missing.push({ repo: repo.name, why: `its items could not be read: ${(e as Error).message}` })
|
|
100
56
|
return null
|
|
101
57
|
}
|
|
102
58
|
}),
|
|
103
59
|
)
|
|
104
|
-
|
|
105
|
-
const quiet = quietOf(new Map(ok.map((s) => [s.repo, s.log])))
|
|
106
|
-
return { sources: ok.map(({ log: _, ...s }) => ({ ...s, quietSince: quiet.get(s.repo) ?? null })), missing }
|
|
60
|
+
return { sources: read.filter((s) => s != null), missing }
|
|
107
61
|
}
|
|
108
62
|
|
|
109
63
|
/** one page of the inbox, 304 when the page holds this answer already; gzipped when the browser takes it */
|
|
110
|
-
export async function inboxResponse(req: Request, hubs: Pick<Hubs, 'loaded'>, down: InboxAnswer['missing']): Promise<Response> {
|
|
111
|
-
const { sources, missing } = await inboxSources(hubs)
|
|
112
|
-
const
|
|
64
|
+
export async function inboxResponse(req: Request, hubs: Pick<Hubs, 'loaded'>, down: InboxAnswer['missing'], o: { partiesOf?: PartiesOf } = {}): Promise<Response> {
|
|
65
|
+
const { sources, missing } = await inboxSources(hubs, Date.now, o.partiesOf)
|
|
66
|
+
const q = inboxQuery(new URL(req.url).searchParams)
|
|
67
|
+
const page = inboxPage(inboxRows(sources, (s) => datedIn(s.root), wantsDone(q)), q, [...down, ...missing])
|
|
113
68
|
const text = JSON.stringify(page)
|
|
114
69
|
const tag = `"${Bun.hash(text).toString(36)}"`
|
|
115
70
|
const headers = { 'Content-Type': 'application/json', ETag: tag, 'Cache-Control': 'no-cache', Vary: 'Accept-Encoding' }
|
package/src/home/machine-fold.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { createIndexTables } from '../agent-time/store.ts'
|
|
|
15
15
|
import { waitRefused, FOLD_AUTO, FOLD_LOCK, foldAutoOn, FOLD_MARK, FOLDED_STORES, forgetStoreHomes, machineFileCreate, ownShape, type FoldedStore, type FoldMark, foldMarkOf, isTombstone, machineDb, machineDbPath, machineRead, oldStorePath, tombstoneText, vacuumSteps, WALK_TOOK, walkBytes } from '../core/machine-db.ts'
|
|
16
16
|
import { createMediaTables } from '../media-store/db.ts'
|
|
17
17
|
import { createDaemonTables, DAEMON_TABLES } from '../hq/outbox.ts'
|
|
18
|
+
import { storeSync } from '../ledger/db.ts'
|
|
18
19
|
|
|
19
20
|
/** where a store's whole copy is kept before its fold */
|
|
20
21
|
export const foldCopy = (old: string): string => `${old}.before-fold`
|
|
@@ -113,7 +114,7 @@ export function openHost(): Database {
|
|
|
113
114
|
for (const f of [path, `${path}-wal`, `${path}-shm`]) try { chmodSync(f, 0o600) } catch { /* not made yet */ }
|
|
114
115
|
const db = new Database(path, { readwrite: true })
|
|
115
116
|
db.exec('pragma busy_timeout = 5000')
|
|
116
|
-
db
|
|
117
|
+
storeSync(db, 'NORMAL')
|
|
117
118
|
// the unique index of a call's id takes its rows in no order: with sqlite's small default cache a copy step of
|
|
118
119
|
// 2,000 rows held the lock 838 ms on a real sized index; the pages of the indexes stay in memory instead
|
|
119
120
|
db.exec('pragma cache_size = -262144')
|
|
@@ -417,29 +418,23 @@ export function rmCopies(o: { go: boolean; print: Print }): { path: string; byte
|
|
|
417
418
|
export async function foldNotice(root: string): Promise<string | null> {
|
|
418
419
|
const folded = foldState().filter((s) => s.state === 'folded' && s.copy != null)
|
|
419
420
|
if (folded.length === 0 || machineRead(NOTICE) != null) return null
|
|
420
|
-
const { createAsk } = await import('../asks/
|
|
421
|
+
const { createAsk } = await import('../asks/ask-store.ts')
|
|
421
422
|
const { afterValue } = await import('../asks/ask-after.ts')
|
|
422
|
-
const { LAYOUT } = await import('../core/layout.ts')
|
|
423
|
-
const { join } = await import('path')
|
|
424
|
-
const { readFileSync } = await import('fs')
|
|
425
|
-
const dir = join(root, LAYOUT.asks)
|
|
426
423
|
const mb = folded.reduce((n, s) => n + s.copy!.bytes, 0) / 1e6
|
|
427
424
|
const key = shortKey()
|
|
428
|
-
//
|
|
429
|
-
const
|
|
425
|
+
// one line a paragraph or a bullet: the hub renders it as its thread's words
|
|
426
|
+
const body = [foldWords().filter((l) => !l.startsWith('the automatic fold')).map((l) => `- ${l}`).join('\n'), `## 1. Look`, 'On the machine whose key is ' + key + ' (`sk db fold` prints it), run `sk time --since 1d` and `sk db`: the agent time index answers, the machine db has three parts.', '## 2. Delete the copies', 'Run `sk db fold --rm-copies` (it says what goes), then `sk db fold --rm-copies --go`. The way back (`sk db fold --back --go`) ends with them.'].join('\n\n')
|
|
427
|
+
// the machine's key in its title and its check: two machines share the house repo, and each closes only its own
|
|
428
|
+
const ask = await createAsk(root, `the machine db of machine ${key} folded: delete its ${Math.round(mb)} MB of copies once sure`, {
|
|
430
429
|
why: `${folded.map((s) => s.store).join(', ')} ${folded.length === 1 ? 'is' : 'are'} tables of the machine db now; the copies of their old files keep the way back`,
|
|
431
430
|
blocks: 'tools/shipkit (its page home.md, One local file)',
|
|
432
431
|
check: `sk db fold --notice-done ${key}`,
|
|
433
432
|
// two days to trust the fold before the copies go: out of the owner's way until then
|
|
434
433
|
after: afterValue('2d', new Date()),
|
|
434
|
+
body,
|
|
435
435
|
})
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
// the ask contract: one line a paragraph or a bullet (RV029)
|
|
439
|
-
const body = [foldWords().filter((l) => !l.startsWith('the automatic fold')).map((l) => `- ${l}`).join('\n'), `## 1. Look`, 'On the machine whose key is ' + key + ' (`sk db fold` prints it), run `sk time --since 1d` and `sk db`: the agent time index answers, the machine db has three parts.', '## 2. Delete the copies', 'Run `sk db fold --rm-copies` (it says what goes), then `sk db fold --rm-copies --go`. The way back (`sk db fold --back --go`) ends with them.', ''].join('\n\n')
|
|
440
|
-
writeFileSync(p, text.replace(/<!-- one "## N\." section per step[\s\S]*?(?=\*\*Answer\*\*)/, body))
|
|
441
|
-
machineDb((db) => db.query('insert or replace into state (name, value, at) values (?, ?, ?)').run(NOTICE, JSON.stringify({ at: Date.now(), file }), Date.now()))
|
|
442
|
-
return file
|
|
436
|
+
machineDb((db) => db.query('insert or replace into state (name, value, at) values (?, ?, ?)').run(NOTICE, JSON.stringify({ at: Date.now(), ask: ask.id }), Date.now()))
|
|
437
|
+
return ask.address
|
|
443
438
|
}
|
|
444
439
|
/** this machine's key, short: what names it in its notice */
|
|
445
440
|
export const shortKey = (): string => {
|
package/src/home/machine-host.ts
CHANGED
|
@@ -23,6 +23,9 @@ export function machineName(): string {
|
|
|
23
23
|
|
|
24
24
|
/** the tailscale cli: on PATH when its wrapper is installed, else inside the app */
|
|
25
25
|
export const TAILSCALE = ['tailscale', '/Applications/Tailscale.app/Contents/MacOS/Tailscale']
|
|
26
|
+
/** the environment a tailscale cli runs in: the macOS app's binary acts as its cli only under a terminal type, and
|
|
27
|
+
* with no TERM (a process launchd started: pm, the daemon) it tries to start its GUI and fails */
|
|
28
|
+
export const tailscaleEnv = (): Record<string, string | undefined> => ({ ...process.env, TERM: process.env.TERM || 'dumb' })
|
|
26
29
|
|
|
27
30
|
export type TailnetNode = { HostName?: string; DNSName?: string; TailscaleIPs?: string[] }
|
|
28
31
|
/** what `tailscale status --json` says of this machine and its peers */
|
|
@@ -35,7 +38,7 @@ export const TAILSCALE_MS = 3000
|
|
|
35
38
|
export function readTailscaleStatus(bins: string[] = TAILSCALE, timeout = TAILSCALE_MS): TailnetStatus | null {
|
|
36
39
|
for (const bin of bins) {
|
|
37
40
|
try {
|
|
38
|
-
const p = Bun.spawnSync([bin, 'status', '--json'], { stdout: 'pipe', stderr: 'ignore', timeout })
|
|
41
|
+
const p = Bun.spawnSync([bin, 'status', '--json'], { stdout: 'pipe', stderr: 'ignore', timeout, env: tailscaleEnv() })
|
|
39
42
|
if (p.exitCode !== 0) continue
|
|
40
43
|
return JSON.parse(p.stdout.toString()) as TailnetStatus
|
|
41
44
|
} catch {
|
|
@@ -45,6 +48,21 @@ export function readTailscaleStatus(bins: string[] = TAILSCALE, timeout = TAILSC
|
|
|
45
48
|
return null
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
/** a tailscale cli's json answer, null when no tailscale answers within its time or answers no json */
|
|
52
|
+
export async function tailscaleJson(args: string[], bins: string[] = TAILSCALE, timeout = TAILSCALE_MS): Promise<unknown> {
|
|
53
|
+
for (const bin of bins) {
|
|
54
|
+
try {
|
|
55
|
+
const p = Bun.spawn([bin, ...args], { stdout: 'pipe', stderr: 'ignore', timeout, env: tailscaleEnv() })
|
|
56
|
+
const out = await new Response(p.stdout).text()
|
|
57
|
+
if ((await p.exited) !== 0) continue
|
|
58
|
+
return JSON.parse(out)
|
|
59
|
+
} catch {
|
|
60
|
+
// a missing binary throws: the next one is tried
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
48
66
|
/** `Self.DNSName` of `tailscale status --json`, without its final dot; null when no tailscale answers */
|
|
49
67
|
export function readTailnetName(bins: string[] = TAILSCALE, timeout = TAILSCALE_MS): string | null {
|
|
50
68
|
for (const bin of bins) {
|
package/src/home/other-macs.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// machines). Nothing to configure: tailscale lists the peers, and a peer counts once its home answers on the home
|
|
3
3
|
// port. Asked in the background at most every few minutes, so no page poll ever waits on the network.
|
|
4
4
|
import { homePort, publicHome } from './home-paths.ts'
|
|
5
|
-
import { TAILSCALE } from './machine-host.ts'
|
|
5
|
+
import { TAILSCALE, tailscaleEnv } from './machine-host.ts'
|
|
6
6
|
|
|
7
7
|
export type OtherMac = { name: string; url: string }
|
|
8
8
|
type Peer = { DNSName?: string; OS?: string; Online?: boolean }
|
|
@@ -23,7 +23,7 @@ export function macPeers(status: TailscaleStatus): { name: string; host: string
|
|
|
23
23
|
export async function tailscaleStatus(bins: string[] = TAILSCALE): Promise<TailscaleStatus | null> {
|
|
24
24
|
for (const bin of bins) {
|
|
25
25
|
try {
|
|
26
|
-
const p = Bun.spawn([bin, 'status', '--json'], { stdout: 'pipe', stderr: 'ignore' })
|
|
26
|
+
const p = Bun.spawn([bin, 'status', '--json'], { stdout: 'pipe', stderr: 'ignore', env: tailscaleEnv() })
|
|
27
27
|
const timer = setTimeout(() => p.kill(), 3000)
|
|
28
28
|
const out = await new Response(p.stdout).text()
|
|
29
29
|
clearTimeout(timer)
|
package/src/home/serve-web.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// the web: ONE Bun.serve on the home port. It serves the one page bundle (the
|
|
2
|
-
// overview at `/`, the inbox at `/inbox`, the plan at `/planned`, the activity at `/activity`, a repo's hub page at
|
|
2
|
+
// overview at `/`, the house wiki at `/wiki`, the inbox at `/inbox`, the plan at `/planned`, the activity at `/activity`, a repo's hub page at
|
|
3
3
|
// `/r/<repo>/`, all views of one app) and proxies every api,
|
|
4
4
|
// graph and media request to the daemon, streams included, and /api/pm/* to
|
|
5
5
|
// pm. A browser only ever sees this origin.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// port directly, and lets this door through. The host guard runs here too: Bun's dev server, which bundles the page
|
|
11
11
|
// and drives its hot reload, answers only to a loopback Host, so it sits on a port of its own behind this one, and a
|
|
12
12
|
// request reaches it only once its Host is a loopback name or this Mac's tailnet name (machine-host.ts)
|
|
13
|
-
import { hostName, loopbackName, REACH_HEADER, reachOfCaller, sameOrigin } from '../serve/same-origin.ts'
|
|
13
|
+
import { HOST_HEADER, hostName, loopbackName, REACH_HEADER, reachOfCaller, sameOrigin } from '../serve/same-origin.ts'
|
|
14
14
|
import { hubBase } from './home-paths.ts'
|
|
15
15
|
import { forwardPage, pagePath } from '../pages/forward.ts'
|
|
16
16
|
import { statSync } from 'fs'
|
|
@@ -22,7 +22,7 @@ import type { UrlLogin } from '../urls/frame.ts'
|
|
|
22
22
|
/** the page routes: ONE app for the overview, the plan, and the hub page of
|
|
23
23
|
* each known repo, which moves between them in place (home-st.ts) */
|
|
24
24
|
export function pageRoutes<T>(names: string[], page: T): Record<string, T> {
|
|
25
|
-
const out: Record<string, T> = { '/': page, '/inbox': page, '/machines': page, '/database': page, '/vault': page, '/space': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page, '/time': page, '/recordings': page, '/identities': page }
|
|
25
|
+
const out: Record<string, T> = { '/': page, '/wiki': page, '/inbox': page, '/machines': page, '/database': page, '/vault': page, '/space': page, '/planned': page, '/activity': page, '/archived': page, '/insights': page, '/time': page, '/recordings': page, '/identities': page }
|
|
26
26
|
for (const n of names) out[`${hubBase(n)}/`] = page
|
|
27
27
|
return out
|
|
28
28
|
}
|
|
@@ -288,9 +288,10 @@ export function serveWeb<T extends Bun.HTMLBundle | Response>(d: WebDeps<T>) {
|
|
|
288
288
|
|
|
289
289
|
async function forward(req: Request, url: URL, srv: Bun.Server<Pipe>, key: string | null): Promise<Response> {
|
|
290
290
|
const headers = new Headers()
|
|
291
|
-
req.headers.forEach((v, k) => { if (!DROP.has(k)) headers.set(k, v) })
|
|
292
|
-
//
|
|
291
|
+
req.headers.forEach((v, k) => { if (!DROP.has(k) && !k.startsWith('x-shipkit-')) headers.set(k, v) })
|
|
292
|
+
// the web's own tags, never one a browser sent: tailscaled passes x-shipkit-* as the client wrote it
|
|
293
293
|
headers.set(REACH_HEADER, reachOfCaller(req))
|
|
294
|
+
headers.set(HOST_HEADER, req.headers.get('host') ?? url.host)
|
|
294
295
|
// a run or a live stream can stay silent for minutes
|
|
295
296
|
srv.timeout(req, 0)
|
|
296
297
|
const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : await req.arrayBuffer()
|
package/src/home/space-page.ts
CHANGED
|
@@ -73,7 +73,7 @@ export function folderWhat(prefix: string, d: Pick<SpacePageDeps, 'kinds' | 'rep
|
|
|
73
73
|
const rest = prefix.slice(PUBLIC_PREFIX.length)
|
|
74
74
|
return rest.split('/').length === 2 ? kind(rest.slice(0, -1)) : null
|
|
75
75
|
}
|
|
76
|
-
if (prefix === `${BACKUP_LABEL}/`) return 'the backup of each machine\'s own state,
|
|
76
|
+
if (prefix === `${BACKUP_LABEL}/`) return 'the backup of each machine\'s own state, kept as its retention says'
|
|
77
77
|
if (prefix === RUNS_PREFIX) return 'one manifest a backup run'
|
|
78
78
|
if (prefix === PARTS_PREFIX) return 'the parts of the manifests'
|
|
79
79
|
if (prefix === SNAPSHOTS) return 'snapshots: the vault\'s sealed ones, the hq\'s nightly one'
|
package/src/home/vault-page.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// The constraint a reader breaks first: an answer holds names, states, sizes and dates only. A value, a token, a key
|
|
5
5
|
// or a raw error of the vault never enters it: the list comes from the metadata calls and the keychain's attributes,
|
|
6
6
|
// and every failure is said in our own words (the status code at most)
|
|
7
|
-
import { existsSync, readdirSync,
|
|
7
|
+
import { existsSync, readdirSync, statSync } from 'fs'
|
|
8
8
|
import { homedir } from 'os'
|
|
9
9
|
import { join } from 'path'
|
|
10
10
|
import { scopeText, type Scope, type ScopeChip } from '../core/scope.ts'
|
|
@@ -22,10 +22,12 @@ import { CHANGED_KEY, DEAD_DISK_KEY, NAMES_KEY, PROVED_KEY, SENT_KEY, snapshotHe
|
|
|
22
22
|
import type { Fact, SecretRow, VaultPage } from './vault-words.ts'
|
|
23
23
|
|
|
24
24
|
export type Row = RegistryRow & { service?: string; level?: 'core' | 'used' | 'minor' }
|
|
25
|
-
export type AskOf = { repo: string;
|
|
25
|
+
export type AskOf = { repo: string; id: string; title: string; secrets: string[] }
|
|
26
26
|
export type VaultProcess = { status: string; since: number; want: string; repo: string } | null
|
|
27
27
|
|
|
28
28
|
/** what the page reads, each one a test replaces */
|
|
29
|
+
import type { VaultReader } from '../hq/vault-route.ts'
|
|
30
|
+
|
|
29
31
|
export type VaultPageDeps = {
|
|
30
32
|
place: VaultPlace
|
|
31
33
|
machine: string
|
|
@@ -49,6 +51,11 @@ export type VaultPageDeps = {
|
|
|
49
51
|
/** the hq this machine joined on another machine, null when it carries its own */
|
|
50
52
|
joined: string | null
|
|
51
53
|
daemonToken: boolean
|
|
54
|
+
/** on the master's Mac: the nodes of other Macs bound to read it through the hq's vault route, null when the
|
|
55
|
+
* daemon does not answer */
|
|
56
|
+
readers?: () => Promise<VaultReader[] | null>
|
|
57
|
+
/** on a Mac that reads the master from afar: its host, and a read of the route now (null: it answers) */
|
|
58
|
+
master?: { host: string; check: () => Promise<string | null> } | null
|
|
52
59
|
keychainOnly: boolean
|
|
53
60
|
pruneOn: boolean
|
|
54
61
|
compared: CompareSummary | null
|
|
@@ -304,7 +311,7 @@ async function secretRows(d: VaultPageDeps, versions: Map<string, Meta> | null,
|
|
|
304
311
|
written: written?.at ?? null,
|
|
305
312
|
version: written?.version ?? null,
|
|
306
313
|
note: elsewhere ?? (versions != null && at?.why != null && row != null ? at.why : null),
|
|
307
|
-
ask: a == null ? null : { repo: a.repo,
|
|
314
|
+
ask: a == null ? null : { repo: a.repo, id: a.id, title: a.title },
|
|
308
315
|
}
|
|
309
316
|
}))
|
|
310
317
|
return rows
|
|
@@ -314,10 +321,21 @@ async function secretRows(d: VaultPageDeps, versions: Map<string, Meta> | null,
|
|
|
314
321
|
export async function vaultPage(d: VaultPageDeps): Promise<VaultPage> {
|
|
315
322
|
const notes: Fact[] = []
|
|
316
323
|
const here = existsSync(markerFile(d.place))
|
|
324
|
+
if (!here && d.master != null) {
|
|
325
|
+
const short = d.master.host.split('.')[0]
|
|
326
|
+
const why = await d.master.check()
|
|
327
|
+
const stands: Fact[] = [
|
|
328
|
+
{ text: `this machine (${d.machine}) reads the master vault on ${short}, through the hq's vault route at ${d.master.host}`, tone: 'ok' },
|
|
329
|
+
why == null ? { text: 'the master answers this Mac now: lookup-self through the route', tone: 'ok' } : { text: `the master does not answer this Mac now: ${why}; every read falls back to this Mac's keychain copies, stale, or fails`, tone: 'danger' },
|
|
330
|
+
{ text: 'writes happen on the master\'s Mac only', tone: 'dim' },
|
|
331
|
+
]
|
|
332
|
+
const secrets = await secretRows(d, null, notes, here)
|
|
333
|
+
return { at: d.now, machine: d.machine, here, stands, lives: [{ text: `its secrets: the master vault on ${short}; this Mac's keychain copies only as a stale fallback while the master does not answer`, tone: 'ok' }], copies: [{ text: `the master's sealed snapshots, on ${short}`, tone: 'dim' }], secrets, notes }
|
|
334
|
+
}
|
|
317
335
|
if (!here) {
|
|
318
336
|
const stands: Fact[] = [
|
|
319
337
|
{ text: `this machine (${d.machine}) runs no vault`, tone: 'dim' },
|
|
320
|
-
{ text: d.joined == null ? 'its secrets come from its login keychain
|
|
338
|
+
{ text: d.joined == null ? 'its secrets come from its login keychain (sk secret)' : `it reports to the hq at ${d.joined}, whose machine runs the vault; its own secrets come from its login keychain, through the house's secret manager`, tone: 'ok' },
|
|
321
339
|
{ text: 'this page shows this machine only: never another machine\'s names', tone: 'dim' },
|
|
322
340
|
]
|
|
323
341
|
const secrets = await secretRows(d, null, notes, here)
|
|
@@ -347,7 +365,19 @@ export async function vaultPage(d: VaultPageDeps): Promise<VaultPage> {
|
|
|
347
365
|
const compared = comparedFact(d)
|
|
348
366
|
if (compared != null) stands.push(compared)
|
|
349
367
|
const stamp = versions == null ? null : (await vaultStamp({ versions: async () => new Map([...versions!].map(([p, m]) => [p, m.version])) })).stamp
|
|
350
|
-
return { at: d.now, machine: d.machine, here, stands, lives: livesFacts(d, s, proc), copies: copiesFacts(d, stamp), secrets, notes }
|
|
368
|
+
return { at: d.now, machine: d.machine, here, stands, lives: [...livesFacts(d, s, proc), ...(await readerFacts(d))], copies: copiesFacts(d, stamp), secrets, notes }
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** the other Macs that read this vault, by the device bound to each node: names and days, never a token */
|
|
372
|
+
async function readerFacts(d: VaultPageDeps): Promise<Fact[]> {
|
|
373
|
+
if (d.readers == null) return []
|
|
374
|
+
const rs = await d.readers()
|
|
375
|
+
if (rs == null) return [{ text: 'its readers on other Macs: not read, the daemon does not answer', tone: 'warn' }]
|
|
376
|
+
if (rs.length === 0) return [{ text: 'its readers on other Macs: none bound, so nobody reads it through the hq\'s vault route', tone: 'dim' }]
|
|
377
|
+
return rs.map((r) => ({
|
|
378
|
+
text: `its reader ${r.machine}: from the tailnet device ${r.device} (${r.os}), bound ${new Date(r.bound).toISOString().slice(0, 10)}, ${r.readAt == null ? 'no read yet' : `last read ${ago(Math.max(0, d.now - r.readAt))} ago`}${r.minted == null ? ', no live token' : `, its token minted ${ago(Math.max(0, d.now - r.minted))} ago`}`,
|
|
379
|
+
tone: 'ok' as const,
|
|
380
|
+
}))
|
|
351
381
|
}
|
|
352
382
|
|
|
353
383
|
/** what this process read of the vault, kept KEEP_MS: the status (its health asked at each read, and read whole again
|
|
@@ -397,7 +427,8 @@ export async function vaultDeps(root: string | null, o: { fresh?: boolean; seal?
|
|
|
397
427
|
names: walk == null ? null : (o.names ?? (() => walk.read(fresh, now))),
|
|
398
428
|
keychain: c.keychain,
|
|
399
429
|
notes: c.note == null ? [] : [c.note],
|
|
400
|
-
|
|
430
|
+
// an archived name is out of use, never missing (sk secret archive)
|
|
431
|
+
rows: (config?.creds ?? []).filter((c) => c.archived == null) as Row[],
|
|
401
432
|
placeOf: async (rows, names) => {
|
|
402
433
|
const [{ placeNames }, { houseKeys, keyOfFrom }] = await Promise.all([import('../vault/vault-import.ts'), import('../vault/house-keys.ts')])
|
|
403
434
|
return placeNames({ rows, held: names, keyOf: root == null ? async () => null : keyOfFrom(await keysOnce(root, houseKeys)) })
|
|
@@ -411,6 +442,15 @@ export async function vaultDeps(root: string | null, o: { fresh?: boolean; seal?
|
|
|
411
442
|
get: machineGet,
|
|
412
443
|
joined: hq.carriesHq() ? null : new URL(hq.hqUrl()).host,
|
|
413
444
|
daemonToken: hq.readVaultToken() != null,
|
|
445
|
+
...(hq.carriesHq()
|
|
446
|
+
? { readers: hq.askVaultReaders }
|
|
447
|
+
: {
|
|
448
|
+
master: (() => {
|
|
449
|
+
const token = hq.readVaultToken()
|
|
450
|
+
if (token == null) return null
|
|
451
|
+
return { host: new URL(hq.hqUrl()).hostname, check: () => hq.masterVault(token, 3_000).lookupSelf().then(() => null, (e: Error) => e.message) }
|
|
452
|
+
})(),
|
|
453
|
+
}),
|
|
414
454
|
keychainOnly: process.env['SHIPKIT_SECRET_KEYCHAIN_ONLY'] === '1',
|
|
415
455
|
pruneOn: vaultPruneOn(),
|
|
416
456
|
compared: c.compared,
|
|
@@ -427,20 +467,14 @@ function keysOnce(root: string, read: (root: string) => Promise<Map<string, impo
|
|
|
427
467
|
return keys.v
|
|
428
468
|
}
|
|
429
469
|
|
|
430
|
-
/** the open credential asks of every house repo, by the names they store; a repo with no
|
|
470
|
+
/** the open credential asks of every house repo, by the names they store; a repo with no store is not made one */
|
|
431
471
|
async function houseAsks(root: string): Promise<AskOf[]> {
|
|
432
|
-
const [{ houseRepos
|
|
472
|
+
const [{ houseRepos }, { asksOfRepo }] = await Promise.all([import('../serve/project-gutter.ts'), import('../asks/ask-store.ts')])
|
|
433
473
|
return houseRepos(root, homedir()).repos.flatMap((r) => {
|
|
434
|
-
let src = ''
|
|
435
|
-
try {
|
|
436
|
-
src = readFileSync(join(r.path, 'repo.config.ts'), 'utf8')
|
|
437
|
-
} catch {
|
|
438
|
-
return []
|
|
439
|
-
}
|
|
440
|
-
const dir = join(r.path, asksDirOf(src, r.path))
|
|
441
|
-
if (!existsSync(dir)) return []
|
|
442
474
|
try {
|
|
443
|
-
return
|
|
475
|
+
return asksOfRepo(r.path)
|
|
476
|
+
.filter((a) => a.status === 'open' && a.kind === 'credential' && a.secrets.length > 0)
|
|
477
|
+
.map((a) => ({ repo: r.name, id: a.id, title: a.title, secrets: a.secrets }))
|
|
444
478
|
} catch {
|
|
445
479
|
return []
|
|
446
480
|
}
|
package/src/home/vault-words.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type SecretRow = {
|
|
|
32
32
|
/** why it has no place in the vault, or where the vault files it apart from its row */
|
|
33
33
|
note: string | null
|
|
34
34
|
/** the open credential ask that waits for it */
|
|
35
|
-
ask: { repo: string;
|
|
35
|
+
ask: { repo: string; id: string; title: string } | null
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export type VaultPage = {
|
|
@@ -126,7 +126,7 @@ export function vaultLines(p: VaultPage, o: { rows?: boolean } = {}): string[] {
|
|
|
126
126
|
if (o.rows === true)
|
|
127
127
|
for (const r of p.secrets) {
|
|
128
128
|
const h = heldWords(r, p.here, p.at)
|
|
129
|
-
out.push(` ${h.text.padEnd(20)} ${r.name.padEnd(44)} ${r.short ?? r.who}${r.registered ? '' : ' (no registry row)'}${r.written == null ? '' : ` written ${writtenWords(r, p.at)}`}${r.ask == null ? '' : ` ask ${r.ask.repo}
|
|
129
|
+
out.push(` ${h.text.padEnd(20)} ${r.name.padEnd(44)} ${r.short ?? r.who}${r.registered ? '' : ' (no registry row)'}${r.written == null ? '' : ` written ${writtenWords(r, p.at)}`}${r.ask == null ? '' : ` ask ${r.ask.repo} ask:${r.ask.id}`}${r.note == null ? '' : ` (${r.note})`}`)
|
|
130
130
|
}
|
|
131
131
|
return out.filter((l) => l !== '')
|
|
132
132
|
}
|
|
@@ -6,24 +6,46 @@
|
|
|
6
6
|
// sends it looking for another way in. It also refuses a gate piped into
|
|
7
7
|
// another command, whose exit code the pipe hides, a `git stash` in the
|
|
8
8
|
// forms the deny row cannot see, and a wait loop on `pgrep -f` (core/polling-policy.ts).
|
|
9
|
+
// On an Edit, a Write or a MultiEdit it refuses one thing: an agent's new persona or value proposition written by
|
|
10
|
+
// hand into the messages store (messages/guard.ts), which goes to the owner in a thread instead.
|
|
9
11
|
//
|
|
10
|
-
// It runs before EVERY Bash call, so it stays a leaf: one tiny import, one
|
|
12
|
+
// It runs before EVERY Bash call and every edit, so it stays a leaf: one tiny import, one
|
|
11
13
|
// small json read, no clipanion, no repo config. Anything it cannot decide it
|
|
12
14
|
// waves through, because a guard that fails closed on its own bugs would wedge
|
|
13
15
|
// a repo with no way to tell why, and `permissions.deny` is still the floor
|
|
14
16
|
// underneath it. Measured at ~10ms per call.
|
|
15
17
|
import { pgrepWaitIn, pgrepWaitRefusal } from '../core/polling-policy.ts'
|
|
16
18
|
import { deniedHeads, GIT_STASH_HEAD, pipedGateIn, pipedGateRefusal, rawRunnerHit, refusal, stashCallIn, stashRefusal, staleScopedRefusal } from '../core/one-way-in-policy.ts'
|
|
19
|
+
import { afterEdit, bashHandWriteRefusal, handWriteRefusal, STORE_FILE } from '../messages/guard.ts'
|
|
17
20
|
|
|
18
21
|
const input = await Bun.stdin.text()
|
|
19
22
|
let command = ''
|
|
20
23
|
try {
|
|
21
|
-
const ev = JSON.parse(input) as { tool_name?: string; tool_input?: { command?: string } }
|
|
24
|
+
const ev = JSON.parse(input) as { tool_name?: string; tool_input?: { command?: string } & Record<string, unknown> }
|
|
25
|
+
// on an edit, the one refusal is an agent's new persona or value proposition written by hand (messages/guard.ts)
|
|
26
|
+
if (ev.tool_name === 'Edit' || ev.tool_name === 'Write' || ev.tool_name === 'MultiEdit') {
|
|
27
|
+
const path = typeof ev.tool_input?.file_path === 'string' ? ev.tool_input.file_path : ''
|
|
28
|
+
if (!STORE_FILE.test(path)) process.exit(0)
|
|
29
|
+
const file = Bun.file(path)
|
|
30
|
+
const before = (await file.exists()) ? await file.text() : ''
|
|
31
|
+
const after = afterEdit(ev.tool_name, ev.tool_input ?? {}, before)
|
|
32
|
+
const why = after == null ? null : handWriteRefusal(path, before, after)
|
|
33
|
+
if (why != null) {
|
|
34
|
+
console.error(why)
|
|
35
|
+
process.exit(2)
|
|
36
|
+
}
|
|
37
|
+
process.exit(0)
|
|
38
|
+
}
|
|
22
39
|
if (ev.tool_name !== 'Bash') process.exit(0)
|
|
23
40
|
command = ev.tool_input?.command ?? ''
|
|
24
41
|
} catch {
|
|
25
42
|
process.exit(0)
|
|
26
43
|
}
|
|
44
|
+
const handWrite = bashHandWriteRefusal(command)
|
|
45
|
+
if (handWrite != null) {
|
|
46
|
+
console.error(handWrite)
|
|
47
|
+
process.exit(2)
|
|
48
|
+
}
|
|
27
49
|
const loop = pgrepWaitIn(command)
|
|
28
50
|
if (loop != null) {
|
|
29
51
|
console.error(pgrepWaitRefusal(loop))
|
package/src/hq/files-send.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// the asks and the reflections of this machine to the hq (wiki tools/shipkit/hq.md), on the outboxes of the cards and
|
|
2
2
|
// the history: one outbox a kind, a row counted as sent only once the hq took it, a row the hq kept out never counted
|
|
3
|
-
// as sent, everything again for an hq that went back in time.
|
|
4
|
-
// `gone`. The one constraint a reader breaks first: a look whose
|
|
3
|
+
// as sent, everything again for an hq that went back in time. An ask of a repo's thread store is a row, and so is a
|
|
4
|
+
// reflection file; one that left goes as `gone`. The one constraint a reader breaks first: a look whose stores and
|
|
5
|
+
// folders did not move reads nothing and makes no call
|
|
5
6
|
import type { Database } from 'bun:sqlite'
|
|
6
7
|
import { createHash } from 'crypto'
|
|
7
8
|
import { lstatSync, readdirSync, readFileSync, statSync } from 'fs'
|
|
8
9
|
import { join } from 'path'
|
|
9
10
|
import { afterMs, afterWords } from '../asks/ask-after.ts'
|
|
10
|
-
import {
|
|
11
|
+
import { asksOfRepo, type Ask } from '../asks/ask-store.ts'
|
|
12
|
+
import { hasStore, storeDir, storeStamp } from '../review/store.ts'
|
|
11
13
|
import { LAYOUT } from '../core/layout.ts'
|
|
12
14
|
import { granted, type HeldRepo } from './cards.ts'
|
|
13
15
|
import type { FeedLink, MachinesAnswer, ReadLink } from './hq-routes.ts'
|
|
@@ -64,38 +66,35 @@ const st = (path: string): string => {
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
/** a repo's asks
|
|
68
|
-
*
|
|
69
|
+
/** a repo's asks, open and closed, each a thread of its store (asks/ask-store.ts): one row an ask, named by its id. The
|
|
70
|
+
* stamp is the store's, so a look whose store did not move reads nothing */
|
|
69
71
|
export function askSource(repo: HeldRepo): Source {
|
|
70
|
-
const
|
|
71
|
-
const archives = CLOSED.map((s) => [join(dir, s), s] as const)
|
|
72
|
+
const store = storeDir(repo.path)
|
|
72
73
|
return {
|
|
73
|
-
stamp: () =>
|
|
74
|
+
stamp: () => (hasStore(store) ? storeStamp(store) : 'none'),
|
|
74
75
|
rows: () => {
|
|
75
76
|
const rows: FileRow[] = []
|
|
76
77
|
const broken: string[] = []
|
|
77
78
|
const unread: string[] = []
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
79
|
+
let asks: Ask[]
|
|
80
|
+
try {
|
|
81
|
+
asks = asksOfRepo(repo.path)
|
|
82
|
+
} catch (e) {
|
|
83
|
+
return { rows, broken: [`its thread store: ${(e as Error).message}`], unread }
|
|
84
|
+
}
|
|
85
|
+
for (const a of asks) {
|
|
86
|
+
try {
|
|
87
|
+
const n = /^(\d+)-/.exec(a.id)
|
|
88
|
+
const body = maskFields<AskBody>({ repo: repo.id, name: a.id, number: n == null ? null : Number(n[1]), slug: a.id.replace(/^\d+-/, '').slice(0, 120), title: a.title.slice(0, 300), state: a.status, kind: a.kind, blocks: a.blocks.slice(0, 300), pinged: a.pinged, created: a.created, closed: a.closed, ...(a.after != null ? { after: a.after } : {}) }, ASK_TEXTS)
|
|
89
|
+
if (secretName(body, ASK_NAMES) != null) throw new Error("its name has a secret's shape")
|
|
90
|
+
if (!isAskBody(body)) throw new Error('no row the hq takes (its name)')
|
|
91
|
+
rows.push({ name: nameOf(repo.id, a.id), rev: askRev(body), at: afterMs(a.closed ?? a.created) ?? Date.now(), body })
|
|
92
|
+
} catch (e) {
|
|
93
|
+
broken.push(`ask:${a.id}: ${(e as Error).message}`)
|
|
94
|
+
unread.push(nameOf(repo.id, a.id))
|
|
94
95
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
for (const r of rows) if (!by.has(r.name) || (r.body as { state?: string }).state !== 'open') by.set(r.name, r)
|
|
98
|
-
return { rows: [...by.values()], broken, unread }
|
|
96
|
+
}
|
|
97
|
+
return { rows, broken, unread }
|
|
99
98
|
},
|
|
100
99
|
}
|
|
101
100
|
}
|