rvlib-shipkit 2.31.0 → 2.32.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 +31 -0
- package/package.json +1 -1
- package/src/advisors/acts.ts +16 -15
- package/src/advisors/advice.ts +56 -102
- package/src/advisors/advisor-view.ts +98 -73
- package/src/advisors/app-graph.ts +1 -1
- package/src/advisors/app.ts +3 -11
- package/src/advisors/cf-api.ts +1 -1
- package/src/advisors/dir-bucket.ts +4 -3
- package/src/advisors/edge/api.ts +26 -198
- package/src/advisors/edge/bucket.ts +2 -2
- package/src/advisors/edge/handler.ts +13 -155
- package/src/advisors/edge/here.ts +5 -5
- package/src/advisors/edge/pages.ts +12 -9
- package/src/advisors/edge/shell.ts +6 -5
- package/src/advisors/edge/sign-in.ts +101 -36
- package/src/advisors/edge/status.ts +19 -6
- package/src/advisors/edge/types.ts +36 -60
- package/src/advisors/expose.ts +29 -29
- package/src/advisors/here.ts +12 -12
- package/src/advisors/invite-send.ts +79 -35
- package/src/advisors/invite.ts +31 -8
- package/src/advisors/job.ts +24 -16
- package/src/advisors/login.ts +40 -15
- package/src/advisors/owner-store.ts +46 -22
- package/src/advisors/photos.ts +3 -3
- package/src/advisors/project.ts +25 -23
- package/src/advisors/reach.ts +89 -0
- package/src/advisors/rights.ts +1 -1
- package/src/advisors/routes.ts +55 -74
- package/src/advisors/scan.ts +0 -4
- package/src/advisors/setup-run.ts +14 -14
- package/src/advisors/share-trace.ts +3 -3
- package/src/advisors/{door-probe.ts → sign-in-probe.ts} +7 -6
- package/src/advisors/speaks.ts +29 -0
- package/src/advisors/sync.ts +92 -182
- package/src/advisors/tunnel.ts +6 -5
- package/src/advisors/users-listen.ts +92 -0
- package/src/advisors/users-router.ts +257 -85
- package/src/advisors/users-store.ts +81 -0
- package/src/agent-time/blocked-scan.ts +181 -0
- package/src/agent-time/registry.ts +12 -5
- package/src/agent-time/store.ts +9 -109
- package/src/asks/ask-bar-fold.ts +2 -1
- package/src/asks/ask-close.ts +2 -1
- package/src/asks/ask-doc.ts +2 -1
- package/src/asks/ask-migrate.ts +3 -2
- package/src/asks/ask-steps-fold.ts +2 -1
- package/src/asks/ask-store.ts +4 -3
- package/src/check.ts +3 -43
- package/src/checks/SK001-package-json-shape.check.ts +4 -55
- package/src/checks/SK004-gitignore-policy.check.ts +24 -69
- package/src/checks/SK013-one-way-in-policy.check.ts +3 -7
- package/src/checks/SK017-vscode-hub-task.check.ts +4 -4
- package/src/checks/SK019-tests-run-in-units.check.ts +3 -14
- package/src/checks/SK020-self-spawning-check.check.ts +5 -7
- package/src/checks/SK035-public-clean.check.ts +1 -1
- package/src/checks/SK039-vscode-watch-generated.check.ts +1 -1
- package/src/checks/SK042-post-kinds.check.ts +5 -14
- package/src/checks/SK054-agent-allow-list.check.ts +5 -74
- package/src/checks/SK055-retired-config-keys.check.ts +45 -0
- package/src/cli/cmd_Advisors.ts +11 -45
- package/src/cli/cmd_Asks.ts +3 -10
- package/src/cli/cmd_Backup.ts +25 -127
- package/src/cli/cmd_BackupTargets.ts +1 -1
- package/src/cli/cmd_Checks.ts +0 -14
- package/src/cli/cmd_Db.ts +3 -82
- package/src/cli/cmd_Home.ts +4 -32
- package/src/cli/cmd_Hq.ts +0 -17
- package/src/cli/cmd_Releases.ts +57 -4
- package/src/cli/cmd_Review.ts +333 -354
- package/src/cli/cmd_SocialDrafts.ts +6 -13
- package/src/cli/cmd_ThreadSyncNeeds.ts +6 -2
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_Trailer.ts +1 -1
- package/src/cli/inbox-hook-run.ts +5 -23
- package/src/cli/registry-heads.ts +5 -55
- package/src/cli/registry.ts +1 -5
- package/src/cli/review-here.ts +1 -1
- package/src/cli.ts +2 -2
- package/src/collections/collection-types.ts +1 -1
- package/src/collections/review.ts +5 -4
- package/src/core/agent-allow-policy.ts +32 -2
- package/src/core/agent-env.ts +8 -0
- package/src/core/allow-rows.ts +74 -0
- package/src/core/check-file-names.ts +19 -106
- package/src/core/footprint.ts +17 -13
- package/src/core/identities-root.ts +1 -4
- package/src/core/layout.ts +1 -2
- package/src/core/machine-db.ts +33 -208
- package/src/core/machine-layout.ts +14 -127
- package/src/core/mask-source.ts +60 -0
- package/src/core/memory-watch.ts +17 -14
- package/src/core/motherhome.ts +8 -35
- package/src/core/one-way-in-policy.ts +0 -3
- package/src/core/repo-walk.ts +0 -9
- package/src/core/retention.ts +1 -9
- package/src/core/retired-checks.ts +2 -0
- package/src/core/tmux-policy.ts +1 -1
- package/src/core/tree-watch.ts +2 -2
- package/src/core/when.ts +7 -45
- package/src/gate/discover-checks.ts +42 -32
- package/src/gate/gate-checks.ts +21 -131
- package/src/gate/pre-commit-discovery.ts +16 -25
- package/src/gate/run-check.ts +0 -4
- package/src/gate/run-fix.ts +5 -17
- package/src/gate/run-fixers.ts +6 -42
- package/src/home/app-sign.ts +2 -2
- package/src/home/backup-status.ts +52 -92
- package/src/home/backup-verdict.ts +2 -2
- package/src/home/daemon-jobs.ts +51 -95
- package/src/home/database-words.ts +1 -2
- package/src/home/databases.ts +9 -25
- package/src/home/home-launchd.ts +0 -6
- package/src/home/home-paths.ts +8 -4
- package/src/home/home-routes.ts +3 -10
- package/src/home/home-state.ts +2 -14
- package/src/home/inbox-shape.ts +14 -15
- package/src/home/inbox.ts +1 -1
- package/src/home/machine-repair.ts +102 -103
- package/src/home/resume.ts +1 -15
- package/src/home/run-daemon.ts +4 -11
- package/src/home/space-page.ts +3 -2
- package/src/home/supervise.ts +3 -7
- package/src/hooks/hook-config.ts +6 -7
- package/src/hooks/leak-guard.ts +1 -1
- package/src/hooks/run-hooks.ts +0 -5
- package/src/hq/daemon-db.ts +8 -8
- package/src/hq/door.ts +3 -16
- package/src/hq/hq-db.ts +4 -3
- package/src/hq/hq-local.ts +1 -2
- package/src/hq/hq-store.ts +0 -15
- package/src/hq/item-direct.ts +8 -10
- package/src/hq/item-fill.ts +37 -0
- package/src/hq/kinds/item-gone.ts +7 -10
- package/src/hq/kinds/item-msg.ts +12 -18
- package/src/hq/kinds/item.ts +13 -19
- package/src/hq/kinds/report.ts +3 -4
- package/src/hq/owner-switch.ts +3 -3
- package/src/hq/report.ts +5 -9
- package/src/hq/switch.ts +2 -11
- package/src/hq/thread-sync.ts +5 -17
- package/src/hq/{shapes-words.ts → threads-words.ts} +2 -12
- package/src/http/owner-word.ts +1 -1
- package/src/identities/machine.ts +16 -0
- package/src/init-repo.ts +0 -1
- package/src/ledger/check-stats.ts +6 -5
- package/src/ledger/db.ts +2 -4
- package/src/ledger/record-kept.ts +117 -48
- package/src/ledger/run-log.ts +21 -2
- package/src/ledger/slow-tests.ts +96 -0
- package/src/ledger/store.ts +3 -86
- package/src/ledger/suite-log.ts +8 -2
- package/src/media-store/backup/facts.ts +3 -37
- package/src/media-store/backup/keys.ts +1 -8
- package/src/media-store/backup/manifest.ts +6 -67
- package/src/media-store/backup/restore.ts +4 -13
- package/src/media-store/backup/retention.ts +13 -1
- package/src/media-store/backup/run.ts +6 -267
- package/src/media-store/backup/snapshot.ts +2 -38
- package/src/media-store/backup/sources.ts +3 -113
- package/src/media-store/backup/target-send.ts +5 -29
- package/src/media-store/db.ts +8 -7
- package/src/media-store/forget-one.ts +1 -1
- package/src/media-store/forget.ts +1 -80
- package/src/orchestrator/guards.ts +0 -1
- package/src/orchestrator/presence.ts +2 -2
- package/src/orchestrator/routes.ts +1 -1
- package/src/orchestrator/started.ts +0 -9
- package/src/orchestrator/talk-key.ts +3 -4
- package/src/orchestrator/unheard.ts +1 -1
- package/src/recordings/edit.ts +3 -3
- package/src/recordings/marks-draw.ts +17 -6
- package/src/recordings/marks.ts +120 -9
- package/src/reflections/reflections-queue.ts +3 -10
- package/src/release/notes.ts +1 -1
- package/src/release/public-clean.ts +66 -6
- package/src/release/run-bump.ts +11 -0
- package/src/release/run-release.ts +4 -0
- package/src/releases/from-thread.ts +3 -3
- package/src/releases/model.ts +186 -36
- package/src/releases/store.ts +13 -3
- package/src/releases/validate.ts +83 -0
- package/src/repo-config.ts +29 -64
- package/src/review/answer-kinds.ts +61 -4
- package/src/review/blocked-guard.ts +11 -0
- package/src/review/blocked-object.ts +298 -0
- package/src/review/cells.ts +116 -229
- package/src/review/close.ts +39 -1
- package/src/review/doc-save.ts +3 -2
- package/src/review/draft-item.ts +1 -1
- package/src/review/events.ts +3 -7
- package/src/review/expect.ts +23 -39
- package/src/review/format.ts +79 -46
- package/src/review/glyphs.ts +1 -0
- package/src/review/hand-over.ts +3 -3
- package/src/review/heard.ts +1 -1
- package/src/review/holds-sync.ts +2 -1
- package/src/review/inbox-hook.ts +2 -2
- package/src/review/inbox-read.ts +39 -33
- package/src/review/instruction-guards.ts +12 -0
- package/src/review/instructions.ts +0 -1
- package/src/review/item-db.ts +13 -43
- package/src/review/item-hq.ts +2 -2
- package/src/review/item-rows.ts +3 -14
- package/src/review/kind-catalog.ts +3 -1
- package/src/review/kinds.ts +18 -8
- package/src/review/live-view.ts +3 -0
- package/src/review/media-kind.ts +1 -1
- package/src/review/mentions.ts +1 -2
- package/src/review/model.ts +158 -114
- package/src/review/move.ts +149 -0
- package/src/review/need-threads.ts +3 -2
- package/src/review/object-card.ts +11 -0
- package/src/review/object-read.ts +6 -1
- package/src/review/one-block.ts +1 -1
- package/src/review/owner-read.ts +1 -1
- package/src/review/phone-push.ts +10 -9
- package/src/review/previews.ts +32 -4
- package/src/review/push.ts +2 -2
- package/src/review/recap.ts +129 -0
- package/src/review/referring.ts +6 -3
- package/src/review/reflection-object.ts +4 -3
- package/src/review/routes.ts +49 -19
- package/src/review/secret-route.ts +3 -2
- package/src/review/settle.ts +0 -6
- package/src/review/snooze.ts +5 -3
- package/src/review/speaker.ts +68 -0
- package/src/review/start-title.ts +19 -0
- package/src/review/store.ts +86 -59
- package/src/review/{wakes.ts → thread-events.ts} +92 -7
- package/src/review/thread-md.ts +35 -14
- package/src/review/thread-state.ts +798 -0
- package/src/review/threads.ts +29 -347
- package/src/review/traces.ts +104 -7
- package/src/review/trailer-item.ts +1 -1
- package/src/review/unit.ts +7 -9
- package/src/review/verdict-items.ts +12 -10
- package/src/review/view-layout.ts +25 -1
- package/src/review/watch-feed.ts +1 -2
- package/src/review/working-guards.ts +2 -3
- package/src/rules/untrack-generated.ts +1 -15
- package/src/secrets/lapse.ts +2 -1
- package/src/serve/hub-app/advisor-app.tsx +4 -4
- package/src/serve/hub-app/advisor-face.tsx +9 -3
- package/src/serve/hub-app/advisor-host.ts +27 -27
- package/src/serve/hub-app/advisors-model.ts +17 -8
- package/src/serve/hub-app/advisors-rights.tsx +1 -1
- package/src/serve/hub-app/advisors-st.ts +15 -14
- package/src/serve/hub-app/advisors-view.tsx +13 -11
- package/src/serve/hub-app/app-bridge.ts +23 -3
- package/src/serve/hub-app/asks-page.tsx +1 -1
- package/src/serve/hub-app/auto-text.tsx +71 -16
- package/src/serve/hub-app/check-view.tsx +0 -8
- package/src/serve/hub-app/controls.css +14 -3
- package/src/serve/hub-app/database-view.tsx +1 -2
- package/src/serve/hub-app/git-view.tsx +3 -1
- package/src/serve/hub-app/hub.css +12 -5
- package/src/serve/hub-app/icons.tsx +1 -1
- package/src/serve/hub-app/inbox-view.tsx +1 -2
- package/src/serve/hub-app/live-sources.ts +2 -2
- package/src/serve/hub-app/main-panel.tsx +2 -1
- package/src/serve/hub-app/panel-repo.ts +0 -9
- package/src/serve/hub-app/pic.tsx +29 -12
- package/src/serve/hub-app/polled.ts +16 -2
- package/src/serve/hub-app/recordings-st.ts +23 -2
- package/src/serve/hub-app/recordings-view.tsx +68 -10
- package/src/serve/hub-app/ref-pill.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +1 -2
- package/src/serve/hub-app/review/advisor-add.tsx +1 -1
- package/src/serve/hub-app/review/advisor-invite.tsx +1 -1
- package/src/serve/hub-app/review/draft-body.tsx +2 -2
- package/src/serve/hub-app/review/heard-line.tsx +1 -1
- package/src/serve/hub-app/review/instructions-view.tsx +1 -8
- package/src/serve/hub-app/review/kind-states.tsx +14 -9
- package/src/serve/hub-app/review/kit.tsx +4 -11
- package/src/serve/hub-app/review/lane-bar.tsx +3 -3
- package/src/serve/hub-app/review/lightbox.tsx +15 -11
- package/src/serve/hub-app/review/line-window.ts +4 -1
- package/src/serve/hub-app/review/live-bar-st.ts +2 -2
- package/src/serve/hub-app/review/live-view.tsx +57 -1
- package/src/serve/hub-app/review/object-panel.tsx +20 -8
- package/src/serve/hub-app/review/question-views.tsx +181 -54
- package/src/serve/hub-app/review/recap-bar.tsx +40 -0
- package/src/serve/hub-app/review/request-cell.tsx +48 -0
- package/src/serve/hub-app/review/review-cells.tsx +154 -96
- package/src/serve/hub-app/review/review-host.ts +2 -2
- package/src/serve/hub-app/review/review-kit.ts +17 -11
- package/src/serve/hub-app/review/review-list.tsx +23 -31
- package/src/serve/hub-app/review/review-st.ts +30 -40
- package/src/serve/hub-app/review/review-thread.tsx +139 -85
- package/src/serve/hub-app/review/review-views.tsx +124 -68
- package/src/serve/hub-app/review/share-lines.tsx +4 -4
- package/src/serve/hub-app/review/start-st.ts +2 -5
- package/src/serve/hub-app/review/superseded-runs.ts +4 -3
- package/src/serve/hub-app/review/thread-close.tsx +10 -7
- package/src/serve/hub-app/review/thread-st.ts +372 -201
- package/src/serve/hub-app/review/tone-bar.tsx +126 -0
- package/src/serve/hub-app/review/tones.ts +35 -0
- package/src/serve/hub-app/review/trailer-body.tsx +2 -2
- package/src/serve/hub-app/review/trailer-st.ts +3 -2
- package/src/serve/hub-app/review/trailer-voices-st.ts +3 -2
- package/src/serve/hub-app/review.css +180 -106
- package/src/serve/hub-app/search-view.tsx +1 -1
- package/src/serve/hub-app/social/social-model.ts +0 -4
- package/src/serve/hub-app/source-acts.ts +2 -1
- package/src/serve/hub-app/stores/stores-page.tsx +2 -2
- package/src/serve/hub-app/terminal-sources.tsx +2 -1
- package/src/serve/hub-app/thread-row.tsx +3 -4
- package/src/serve/hub-app/tree-build.ts +0 -4
- package/src/serve/hub-app/urls-view.tsx +2 -1
- package/src/serve/hub-app/view-layout.css +13 -3
- package/src/serve/hub-app/wikis-view.tsx +5 -2
- package/src/serve/hub-runtime.ts +7 -37
- package/src/serve/project-gutter-route.ts +6 -2
- package/src/serve/read-thread.ts +20 -2
- package/src/serve/read-worker.ts +9 -1
- package/src/serve/record-pages.ts +46 -0
- package/src/serve/serve-hub.ts +2 -2
- package/src/serve/terminal-host.ts +1 -1
- package/src/serve/terminal-route.ts +1 -3
- package/src/serve/tracked-watch.ts +1 -3
- package/src/setup-house.ts +2 -2
- package/src/shipkit-files.ts +1 -1
- package/src/shipkit.ts +1 -6
- package/src/shot/film-box.ts +0 -20
- package/src/social/drafts.ts +1 -1
- package/src/social/kinds.ts +6 -29
- package/src/social/load.ts +2 -2
- package/src/social/post-object.ts +3 -2
- package/src/social/release-stage.ts +1 -1
- package/src/social/stage.ts +2 -2
- package/src/stores/model.ts +4 -0
- package/src/stores/routes.ts +11 -3
- package/src/suite/judge-suites.ts +58 -0
- package/src/suite/red-alone.ts +54 -18
- package/src/suite/runner-shapes.ts +2 -2
- package/src/suite/suite-cli.ts +67 -14
- package/src/suite/test-units.ts +2 -1
- package/src/urls/fill.ts +1 -1
- package/src/urls/places.ts +1 -2
- package/src/vault/vault-config.ts +2 -2
- package/src/vault/vault-init.ts +1 -5
- package/src/wiki/graph-page.ts +14 -2
- package/src/advisors/copy-truth.ts +0 -49
- package/src/advisors/door-child.ts +0 -112
- package/src/advisors/door-serve.ts +0 -52
- package/src/advisors/door.ts +0 -118
- package/src/checks/SK016-legacy-check-shapes.check.ts +0 -189
- package/src/checks/SK029-explicit-check-files.check.ts +0 -112
- package/src/checks/SK048-one-local-file.check.ts +0 -36
- package/src/core/config-rewrite.ts +0 -111
- package/src/core/daemon-port.ts +0 -10
- package/src/core/legacy-shapes.ts +0 -263
- package/src/core/migrate-layout.ts +0 -638
- package/src/core/port-check-cli.ts +0 -52
- package/src/core/port-check-file.ts +0 -295
- package/src/core/port-check-files.ts +0 -31
- package/src/gate/discover-legacy-checks.ts +0 -26
- package/src/home/home-move.ts +0 -527
- package/src/home/machine-fold.ts +0 -810
- package/src/hq/item-shapes.ts +0 -54
- package/src/hq/kinds/items-read.ts +0 -4
- package/src/media-store/backup/daemon.ts +0 -220
- package/src/media-store/backup/kept.ts +0 -241
- package/src/media-store/backup/prune.ts +0 -359
- package/src/media-store/backup/secret.ts +0 -88
- package/src/media-store/backup/ssh-space.ts +0 -202
- package/src/media-store/backup/watch.ts +0 -117
- package/src/review/band.ts +0 -182
- package/src/review/folders.ts +0 -216
- package/src/review/hook-ask.ts +0 -58
- package/src/review/role.ts +0 -48
- package/src/review/thread-fold.ts +0 -64
- package/src/review/wait.ts +0 -91
- package/src/rules/rule.ts +0 -43
- package/src/serve/hook-thread.ts +0 -37
- package/src/serve/hook-work.ts +0 -92
- package/src/serve/hook-worker.ts +0 -57
- package/src/serve/hub-app/review/dock.tsx +0 -147
- package/src/serve/hub-app/review/faces.tsx +0 -18
- package/src/serve/hub-app/review/item-verdict.tsx +0 -112
- package/src/serve/hub-app/review/review-board.tsx +0 -48
- /package/src/{scaffold → core}/jsonc-spans.ts +0 -0
package/src/advisors/sync.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
1
|
+
// what a person reads of a share, and the owner's pass (wiki tools/shipkit/advisors.md): `prepare` projects one live
|
|
2
|
+
// share, scanned, through the hub's own builders, for the users' port to answer at the request; the pass keeps the
|
|
3
|
+
// owner's store true about the people: who may sign in, each share's reach and what it masks, where each reader
|
|
4
|
+
// stopped, the advice the owner's rights make direct since, the sweeps of the port's folder. A thread a person reads is
|
|
5
|
+
// prepared at their request, never kept from a pass
|
|
6
|
+
import { createHash } from 'node:crypto'
|
|
5
7
|
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
6
8
|
import { HOUSE_LAYOUT } from '../core/house-layout.ts'
|
|
7
9
|
import { identitiesFile } from '../core/identities-root.ts'
|
|
8
10
|
import { imageFile, readAll, storeDir, threadFile } from '../review/store.ts'
|
|
9
11
|
import { isGallery, verdictOf, type ReviewItem } from '../review/model.ts'
|
|
10
12
|
import type { ReplyCell } from '../review/cells.ts'
|
|
11
|
-
import type { Turn } from '../review/band.ts'
|
|
12
13
|
import { namedFiles } from '../review/file-tags.ts'
|
|
13
|
-
import { membersOf,
|
|
14
|
+
import { membersOf, threadOfAddress, type Thread } from '../review/threads.ts'
|
|
14
15
|
import { cursorOf } from '../review/traces.ts'
|
|
15
16
|
import { advisorThread, personReads, storeNames, type AdvisorThread } from './advisor-view.ts'
|
|
16
|
-
import { truthfulCopy } from './copy-truth.ts'
|
|
17
|
-
import type { AppBundle } from './app.ts'
|
|
18
17
|
import { ADVISOR_WHO } from '../serve/hub-app/review/review-host.ts'
|
|
19
18
|
import { getJson, type Bucket, type Bytes } from './edge/bucket.ts'
|
|
20
|
-
import { KEYS, type ServedProject, type
|
|
21
|
-
import {
|
|
19
|
+
import { KEYS, type ServedProject, type ShareManifest } from './edge/types.ts'
|
|
20
|
+
import { deliverPending, sweepUploads } from './advice.ts'
|
|
22
21
|
import { shareAllOfAccess } from './acts.ts'
|
|
23
22
|
import { opaqueItem, opaqueMessage, picturesOf, projectItems, questionHash, type Masked } from './project.ts'
|
|
24
23
|
import { maskHits, privateWordsOf } from './scan.ts'
|
|
25
|
-
import { photoBytes } from './photos.ts'
|
|
26
24
|
import { rightsOf } from './rights.ts'
|
|
27
25
|
import { keepLogins } from './login.ts'
|
|
28
|
-
import { identityOfRoot } from './
|
|
26
|
+
import { identityOfRoot } from './speaks.ts'
|
|
29
27
|
import { ownerNameOf } from './owner-name.ts'
|
|
30
28
|
import { displayOf, isLive, startPlacesOf, readState, servedShares, withState, type OwnerState, type Share, type ShareRead } from './owner-store.ts'
|
|
29
|
+
import { threadState } from '../review/thread-state.ts'
|
|
31
30
|
|
|
32
31
|
/** a picture as the advisor gets it: re-encoded, no metadata (EXIF, PNG text) survives */
|
|
33
32
|
export type Encode = (path: string) => Promise<Bytes>
|
|
@@ -47,23 +46,21 @@ export function privateWords(house: string | null): string[] {
|
|
|
47
46
|
return existsSync(f) ? privateWordsOf(readFileSync(f, 'utf8')) : []
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
/** what one live share shows the advisor now
|
|
51
|
-
*
|
|
49
|
+
/** what one live share shows the advisor now: the hub's own view and row, the manifest the port checks requests
|
|
50
|
+
* against, every picture of the thread by the hash of its raw bytes */
|
|
52
51
|
export interface Prepared {
|
|
53
52
|
/** the project's name as the advisor reads it, scanned */
|
|
54
53
|
project: string
|
|
55
|
-
/**
|
|
54
|
+
/** the owner's name as this share's project reads it, scanned */
|
|
56
55
|
owner: string
|
|
57
|
-
/** the advisor's
|
|
58
|
-
|
|
56
|
+
/** what the advisor reads, the hub's view and row: null when nothing of the thread leaves */
|
|
57
|
+
theirs: AdvisorThread | null
|
|
59
58
|
manifest: ShareManifest | null
|
|
60
59
|
/** the entries that went out with strings masked */
|
|
61
60
|
masked: Masked[]
|
|
62
|
-
/** each
|
|
63
|
-
served: { sha: string; path: string }[]
|
|
64
|
-
/** each image of the projection, raw content hash, file: the preview draws all of them */
|
|
61
|
+
/** each image of the projection, raw content hash, file: the port encodes one at its request */
|
|
65
62
|
all: { ref: string; sha: string; path: string }[]
|
|
66
|
-
/** the time of
|
|
63
|
+
/** the time of the owner's newest word in the thread: a read up to it is « seen by <name> » in the owner's hub */
|
|
67
64
|
his: string | null
|
|
68
65
|
/** the thread's versions and how many the person sees */
|
|
69
66
|
parts: { versions: number; shown: number }
|
|
@@ -71,8 +68,8 @@ export interface Prepared {
|
|
|
71
68
|
|
|
72
69
|
const ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/
|
|
73
70
|
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
71
|
+
/** a person's read cursor of a share (users-router.ts writes it, `upTo` one of the view's own cell times): a small
|
|
72
|
+
* object of two times; anything else is no read */
|
|
76
73
|
export function readOf(bytes: Bytes | null, his: string | null): ShareRead | null {
|
|
77
74
|
if (bytes === null || bytes.byteLength > 512) return null
|
|
78
75
|
let v: unknown
|
|
@@ -89,9 +86,6 @@ export function readOf(bytes: Bytes | null, his: string | null): ShareRead | nul
|
|
|
89
86
|
return { at, upTo, seen: his === null || upTo >= his }
|
|
90
87
|
}
|
|
91
88
|
|
|
92
|
-
/** the re-encoded bytes of this run, by served name: put once each */
|
|
93
|
-
const encoded = new Map<string, Bytes>()
|
|
94
|
-
|
|
95
89
|
const resolverOf =
|
|
96
90
|
(root: string) =>
|
|
97
91
|
(itemId: string, name: string, of: 'view' | 'message'): string | null =>
|
|
@@ -99,17 +93,17 @@ const resolverOf =
|
|
|
99
93
|
|
|
100
94
|
const ADVICE_WORDS: Record<string, string> = { approve: 'I approve', change: "I'd change this", words: '' }
|
|
101
95
|
|
|
102
|
-
/** the cell of a person's own advice in their
|
|
96
|
+
/** the cell of a person's own advice in their view */
|
|
103
97
|
const adviceCell = (head: string, advice: string): string => `${head}/m${sha256(`advice|${advice}`).slice(0, 12)}`
|
|
104
98
|
|
|
105
|
-
/** each word the person's rights let in at once, as
|
|
99
|
+
/** each word the person's rights let in at once, as their view names it (opaqueMessage), and its cell there: an agent's
|
|
106
100
|
* read of it links that cell. The thread's word is the one its advice wrote, at the moment the advice says it was done */
|
|
107
101
|
function ownCells(s: OwnerState, x: Share, thread: Thread, head: string): Map<string, string> {
|
|
108
102
|
const out = new Map<string, string>()
|
|
109
103
|
const direct = s.advice.filter((a) => a.share === x.id && a.state === 'direct' && a.done !== undefined)
|
|
110
104
|
for (const y of membersOf(thread))
|
|
111
105
|
for (const m of y.thread) {
|
|
112
|
-
// their verdict is a cell of the
|
|
106
|
+
// their verdict is a cell of the view itself, never an advice's
|
|
113
107
|
if (m.who !== 'player' || m.advisor?.id !== x.advisor || m.verdict !== undefined) continue
|
|
114
108
|
const a = direct.find((z) => z.done === m.at)
|
|
115
109
|
if (a !== undefined) out.set(opaqueMessage(x.id, m.id), adviceCell(head, a.id))
|
|
@@ -117,11 +111,11 @@ function ownCells(s: OwnerState, x: Share, thread: Thread, head: string): Map<st
|
|
|
117
111
|
return out
|
|
118
112
|
}
|
|
119
113
|
|
|
120
|
-
/** the person's own advice on this share: drawn in their
|
|
121
|
-
* One their rights made direct is in the thread as a `player` word, which the projection never
|
|
122
|
-
* person's word stays theirs), so their
|
|
114
|
+
/** the person's own advice on this share: drawn in their view as their words, « waits for <owner> » while it waits.
|
|
115
|
+
* One their rights made direct is in the thread as a `player` word, which the projection never carries (another
|
|
116
|
+
* person's word stays theirs), so their view draws it from here, with no wait */
|
|
123
117
|
function pendingCells(s: OwnerState, x: Share, thread: Thread, view: AdvisorThread['view'], owner: string): AdvisorThread['view']['cells'] {
|
|
124
|
-
// a direct verdict that is the version's verdict is in the
|
|
118
|
+
// a direct verdict that is the version's verdict is in the view already (project.ts); one of the older shape (a word)
|
|
125
119
|
// is drawn from here
|
|
126
120
|
const verdicts = new Set(membersOf(thread).flatMap((y) => y.thread.filter((m) => m.who === 'player' && m.advisor?.id === x.advisor && m.verdict !== undefined).map((m) => m.at)))
|
|
127
121
|
// a pick is drawn on its question's cell (markVotes), never as words of its own
|
|
@@ -135,7 +129,7 @@ function pendingCells(s: OwnerState, x: Share, thread: Thread, view: AdvisorThre
|
|
|
135
129
|
}
|
|
136
130
|
|
|
137
131
|
/** the words a person started this thread with, opened at once by their rights: in the thread as a `player` word, which
|
|
138
|
-
* the projection never
|
|
132
|
+
* the projection never carries, so their view draws them from their proposal, as its first message */
|
|
139
133
|
function proposedCells(s: OwnerState, x: Share, thread: Thread, view: AdvisorThread['view']): AdvisorThread['view']['cells'] {
|
|
140
134
|
const heads = new Set(membersOf(thread).map((y) => y.item.id))
|
|
141
135
|
return s.proposals.flatMap((p) => {
|
|
@@ -145,12 +139,12 @@ function proposedCells(s: OwnerState, x: Share, thread: Thread, view: AdvisorThr
|
|
|
145
139
|
})
|
|
146
140
|
}
|
|
147
141
|
|
|
148
|
-
/** the person's newest pick on each question, on the question's cell of their
|
|
149
|
-
* OK. A direct pick that answered is in the
|
|
142
|
+
/** the person's newest pick on each question, on the question's cell of their view: their vote while it waits for the
|
|
143
|
+
* owner's OK. A direct pick that answered is in the view already, and wins */
|
|
150
144
|
function markVotes(s: OwnerState, x: Share, view: AdvisorThread['view']): void {
|
|
151
145
|
const newest = new Map<string, { option: number; at: string }>()
|
|
152
146
|
for (const a of s.advice) {
|
|
153
|
-
// a direct one of the older shape (a word with no answer on it) is theirs too: the
|
|
147
|
+
// a direct one of the older shape (a word with no answer on it) is theirs too: the view holds no answer for it
|
|
154
148
|
if (a.share !== x.id || a.kind !== 'pick' || (a.state !== 'pending' && a.state !== 'direct') || a.item === undefined || a.message === undefined || a.option === undefined) continue
|
|
155
149
|
const cell = `${opaqueItem(x.id, a.item)}/${opaqueMessage(x.id, a.message)}`
|
|
156
150
|
if ((newest.get(cell)?.at ?? '') <= a.at) newest.set(cell, { option: a.option, at: a.at })
|
|
@@ -174,11 +168,9 @@ function rawSha(path: string): string {
|
|
|
174
168
|
return sha
|
|
175
169
|
}
|
|
176
170
|
|
|
177
|
-
/** a share projected and its pictures
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
export async function prepare(s: OwnerState, x: Share, o: { words: string[]; encode: Encode; now: Date; preview?: boolean; names?: 'raw' }): Promise<Prepared | null> {
|
|
181
|
-
const raw = o.preview === true || o.names === 'raw'
|
|
171
|
+
/** a share projected and its pictures named: a thread the owner shared goes whole, its pictures with it, each named by
|
|
172
|
+
* the hash of its raw bytes and encoded by the reader on request (the owner's preview, the users' port), never here */
|
|
173
|
+
export async function prepare(s: OwnerState, x: Share, o: { words: string[]; now: Date }): Promise<Prepared | null> {
|
|
182
174
|
const a = s.advisors.find((y) => y.id === x.advisor)
|
|
183
175
|
if (a === undefined) return null
|
|
184
176
|
const stored = readAll(storeDir(x.root)).items
|
|
@@ -190,10 +182,9 @@ export async function prepare(s: OwnerState, x: Share, o: { words: string[]; enc
|
|
|
190
182
|
const name = ownerNameOf(s, { project: x.repo, identity: await identityOfRoot(x.root) })
|
|
191
183
|
const owner = maskHits(name, scan).length === 0 ? name : 'the owner'
|
|
192
184
|
const resolve = resolverOf(x.root)
|
|
193
|
-
// every picture once,
|
|
194
|
-
const served: Prepared['served'] = []
|
|
185
|
+
// every picture once, named by the hash of its raw bytes; the port encodes it at the request
|
|
195
186
|
const all: Prepared['all'] = []
|
|
196
|
-
const byPath = new Map<string,
|
|
187
|
+
const byPath = new Map<string, string | null>()
|
|
197
188
|
for (const pic of picturesOf(thread)) {
|
|
198
189
|
const path = resolve(pic.itemId, pic.name, pic.of)
|
|
199
190
|
if (path === null || byPath.has(path)) continue
|
|
@@ -203,61 +194,46 @@ export async function prepare(s: OwnerState, x: Share, o: { words: string[]; enc
|
|
|
203
194
|
}
|
|
204
195
|
const rawHash = rawSha(path)
|
|
205
196
|
all.push({ ref: path, sha: rawHash, path })
|
|
206
|
-
|
|
207
|
-
byPath.set(path, { raw: rawHash, served: null })
|
|
208
|
-
continue
|
|
209
|
-
}
|
|
210
|
-
const bytes = await o.encode(path)
|
|
211
|
-
const sha = sha256(bytes)
|
|
212
|
-
if (!served.some((y) => y.sha === sha)) served.push({ sha, path })
|
|
213
|
-
byPath.set(path, { raw: rawHash, served: sha })
|
|
214
|
-
encoded.set(sha, bytes)
|
|
197
|
+
byPath.set(path, rawHash)
|
|
215
198
|
}
|
|
216
|
-
/** a picture's name in the
|
|
199
|
+
/** a picture's name in what the person reads: the hash of its raw bytes */
|
|
217
200
|
const nameOf = (path: string | null): string | null => {
|
|
218
201
|
const b = path === null ? null : (byPath.get(path) ?? null)
|
|
219
|
-
|
|
220
|
-
return raw ? `${b.raw}.webp` : b.served === null ? null : `${b.served}.webp`
|
|
202
|
+
return b === null ? null : `${b}.webp`
|
|
221
203
|
}
|
|
222
204
|
const answers = rightsOf(s.rights, { person: x.advisor, project: x.repo, thread: x.address }).answers
|
|
223
205
|
const items = projectItems({ thread, share: x.id, advisor: x.advisor, answers, scan, include: x.include, picture: (itemId, name, of) => nameOf(resolve(itemId, name, of)) })
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
// their words at their own time among the thread's cells, as his hub draws them (a stable sort keeps the
|
|
206
|
+
const theirs = advisorThread(items, { scan, now: o.now, owner, cursor: cursorOf(thread, o.now), names: storeNames(thread), real: threadState(thread, o.now), deferred: x.deferred === true })
|
|
207
|
+
if (theirs !== null) {
|
|
208
|
+
// their words at their own time among the thread's cells, as the owner's hub draws them (a stable sort keeps the
|
|
228
209
|
// builders' order of cells of one time)
|
|
229
|
-
|
|
230
|
-
markVotes(s, x,
|
|
231
|
-
personReads(
|
|
232
|
-
// the turn as the advisor reads it: a thread deferred to them and set aside on his side is theirs; his turn, or a
|
|
233
|
-
// thread he set aside himself, waits for him (the page says « waits for <owner> », ReviewSt.bandWord)
|
|
234
|
-
const turnFor = (t: Turn): Turn => (x.deferred && t === 'aside' ? 'yours' : t === 'yours' || t === 'aside' ? 'aside' : t)
|
|
235
|
-
copy.view.turn = turnFor(copy.view.turn)
|
|
236
|
-
copy.row.turn = turnFor(copy.row.turn)
|
|
210
|
+
theirs.view.cells = [...theirs.view.cells, ...proposedCells(s, x, thread, theirs.view), ...pendingCells(s, x, thread, theirs.view, owner)].sort((p, q) => p.at.localeCompare(q.at))
|
|
211
|
+
markVotes(s, x, theirs.view)
|
|
212
|
+
personReads(theirs.view, items.items, { owner, own: ownCells(s, x, thread, theirs.view.head) })
|
|
237
213
|
}
|
|
238
|
-
const manifest =
|
|
214
|
+
const manifest = theirs === null ? null : manifestOf(theirs, thread, x.id, x.advisor)
|
|
239
215
|
const his = membersOf(thread).flatMap((y) => y.thread.filter((m) => m.who === 'owner' && m.op !== 'seen').map((m) => m.at)).sort().at(-1) ?? null
|
|
240
|
-
return { project, owner,
|
|
216
|
+
return { project, owner, theirs, manifest, masked: items.masked, all, his, parts: { versions: items.versions, shown: items.shown } }
|
|
241
217
|
}
|
|
242
218
|
|
|
243
|
-
/** what the
|
|
219
|
+
/** what the users' port checks a share's reads and writes against: the view's ids and pictures, each version that waits with
|
|
244
220
|
* its count of views in the store, each choice question open to `advisor` (open, or answered by their own pick alone,
|
|
245
221
|
* which they may change) with the hash of its words in the store */
|
|
246
|
-
export function manifestOf(
|
|
222
|
+
export function manifestOf(read: AdvisorThread, thread: Thread, share: string, advisor?: string): ShareManifest {
|
|
247
223
|
const real = new Map<string, ReviewItem>()
|
|
248
224
|
for (const x of membersOf(thread)) real.set(opaqueItem(share, x.item.id), x)
|
|
249
|
-
const ids = [
|
|
225
|
+
const ids = [read.view.head, ...read.view.members, ...read.view.cells.map((c) => c.id)]
|
|
250
226
|
const images = new Set<string>()
|
|
251
227
|
const judge: ShareManifest['judge'] = []
|
|
252
228
|
const questions: ShareManifest['questions'] = []
|
|
253
|
-
for (const c of
|
|
229
|
+
for (const c of read.view.cells) {
|
|
254
230
|
if (c.kind === 'version') {
|
|
255
231
|
for (const v of c.item.views) for (const f of isGallery(v) ? v.gallery.map((g) => g.file) : 'image' in v.files ? [v.files.image] : 'before' in v.files ? [v.files.before, v.files.after] : []) images.add(f.slice(0, 64))
|
|
256
232
|
const x = real.get(c.item.id)
|
|
257
233
|
// waits, or holds their own direct verdict alone, which they may change
|
|
258
234
|
const v = x === undefined ? null : verdictOf(x)
|
|
259
235
|
const theirs = v !== null && advisor !== undefined && x!.thread.some((m) => m.id === v.id && m.who === 'player' && m.advisor?.id === advisor)
|
|
260
|
-
if (x !== undefined && c.id ===
|
|
236
|
+
if (x !== undefined && c.id === read.view.head && (read.view.state.headWaits || theirs)) judge.push({ item: c.item.id, version: x.item.views.length })
|
|
261
237
|
}
|
|
262
238
|
if (c.kind === 'reply') {
|
|
263
239
|
if (c.image !== undefined) images.add(c.image.slice(0, 64))
|
|
@@ -272,10 +248,11 @@ export function manifestOf(copy: AdvisorThread, thread: Thread, share: string, a
|
|
|
272
248
|
}
|
|
273
249
|
}
|
|
274
250
|
}
|
|
275
|
-
return { v: 1, head:
|
|
251
|
+
return { v: 1, head: read.view.head, ids: [...new Set(ids)], images: [...images], judge, questions }
|
|
276
252
|
}
|
|
277
253
|
|
|
278
|
-
/** where each person may start a thread (startPlacesOf), by the
|
|
254
|
+
/** where each person may start a thread (startPlacesOf), by the id the advisors page names it by; its names scanned
|
|
255
|
+
* like any text that leaves */
|
|
279
256
|
export async function projectsOf(s: OwnerState, words: string[], now = new Date()): Promise<Record<string, ServedProject>> {
|
|
280
257
|
const out: Record<string, ServedProject> = {}
|
|
281
258
|
for (const x of startPlacesOf(s, now)) {
|
|
@@ -290,132 +267,75 @@ export async function projectsOf(s: OwnerState, words: string[], now = new Date(
|
|
|
290
267
|
}
|
|
291
268
|
|
|
292
269
|
export interface SyncReport {
|
|
293
|
-
|
|
294
|
-
|
|
270
|
+
/** the shares a person reads now */
|
|
271
|
+
reached: number
|
|
272
|
+
/** the advice his rights made direct since and that landed */
|
|
295
273
|
advice: number
|
|
296
274
|
errors: string[]
|
|
297
275
|
}
|
|
298
276
|
|
|
299
|
-
/**
|
|
300
|
-
|
|
277
|
+
/** the owner's pass over the users' port's folder `bucket` (users-store.ts): who may sign in kept equal to the grants,
|
|
278
|
+
* each live share prepared once for its reach and what it masks, where each reader stopped pulled into his store, the
|
|
279
|
+
* advice his rights make direct since delivered, the files staged and waiting swept, the sessions and passwords of
|
|
280
|
+
* people no longer listed ended. A failed share is said on it (`reach`) and in the report */
|
|
281
|
+
export async function syncOnce(dir: string, o: { bucket: Bucket; words: string[]; now?: Date }): Promise<SyncReport> {
|
|
301
282
|
const now = o.now ?? new Date()
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
// a project's access that shows every thread shares each new one before the push
|
|
283
|
+
const report: SyncReport = { reached: 0, advice: 0, errors: [] }
|
|
284
|
+
// a project's access that shows every thread shares each new one
|
|
305
285
|
shareAllOfAccess(dir, now)
|
|
306
|
-
// who may sign in: each person with a live grant, and whether the
|
|
286
|
+
// who may sign in: each person with a live grant, and whether the port says their code set a password
|
|
307
287
|
const used = new Map<string, number>()
|
|
308
288
|
for (const a of readState(dir).advisors) {
|
|
309
|
-
if (a.login === undefined || a.login.used === true) continue
|
|
289
|
+
if (a.login === undefined || (a.login.used === true && a.login.reset === undefined)) continue
|
|
310
290
|
const kept = await getJson<{ gen?: unknown }>(o.bucket, KEYS.password(sha256(a.email))).catch(() => null)
|
|
311
291
|
if (typeof kept?.gen === 'number') used.set(a.email, kept.gen)
|
|
312
292
|
}
|
|
313
293
|
const logins = withState(dir, (st) => keepLogins(st, now, used))
|
|
314
294
|
const s = readState(dir)
|
|
315
|
-
// the door opens what this writes and nothing else: the one answer to « who can open a thread » (owner-store.ts)
|
|
316
295
|
const live = servedShares(s, now)
|
|
317
|
-
const results = new Map<string, { prepared: Prepared | null;
|
|
318
|
-
const fallback = ownerNameOf(s)
|
|
319
|
-
const shares: SharesFile = { v: 1, shares: {}, projects: await projectsOf(s, o.words, now), owner: maskHits(fallback, { advisorEmail: '', words: o.words }).length === 0 ? fallback : 'the owner', logins }
|
|
320
|
-
const media = new Set<string>()
|
|
296
|
+
const results = new Map<string, { prepared: Prepared | null; read?: ShareRead | null; reach: Share['reach'] }>()
|
|
321
297
|
for (const x of live) {
|
|
322
298
|
try {
|
|
323
|
-
const p = await prepare(s, x, { words: o.words,
|
|
299
|
+
const p = await prepare(s, x, { words: o.words, now })
|
|
324
300
|
if (p === null) {
|
|
325
301
|
results.set(x.id, { prepared: null, reach: { ok: false, at: now.toISOString(), why: 'its thread or advisor is gone' } })
|
|
326
302
|
continue
|
|
327
303
|
}
|
|
328
|
-
if (p.
|
|
329
|
-
// a value the
|
|
330
|
-
report.errors.push(`${x.id}: the
|
|
331
|
-
results.set(x.id, { prepared: null, reach: { ok: false, at: now.toISOString(), why: `its
|
|
304
|
+
if (p.theirs !== null && p.theirs.faults.length > 0) {
|
|
305
|
+
// a value the output whitelist refused: a builder wrote what a person must not read, so the port shows nothing of it
|
|
306
|
+
report.errors.push(`${x.id}: the whitelist refused ${p.theirs.faults.length} values: ${p.theirs.faults.slice(0, 3).join('; ')}`)
|
|
307
|
+
results.set(x.id, { prepared: null, reach: { ok: false, at: now.toISOString(), why: `its whitelist refused ${p.theirs.faults.length} values: an agent's fix waits` } })
|
|
332
308
|
continue
|
|
333
309
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
for (const m of p.served) media.add(m.sha)
|
|
338
|
-
results.set(x.id, { prepared: p, reach: { ok: true, at: now.toISOString() } })
|
|
310
|
+
report.reached++
|
|
311
|
+
// where the person's reading stands, written by the port on their own page
|
|
312
|
+
results.set(x.id, { prepared: p, read: readOf(await o.bucket.get(KEYS.reads(x.id)), p.his), reach: { ok: true, at: now.toISOString() } })
|
|
339
313
|
} catch (e) {
|
|
340
314
|
report.errors.push(`${x.id}: ${(e as Error).message}`)
|
|
341
315
|
results.set(x.id, { prepared: null, reach: { ok: false, at: now.toISOString(), why: (e as Error).message } })
|
|
342
316
|
}
|
|
343
317
|
}
|
|
344
318
|
try {
|
|
345
|
-
|
|
346
|
-
//
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
shares.app = b.pin
|
|
319
|
+
const keep = new Set(live.map((x) => x.id))
|
|
320
|
+
// an ended share's read cursor goes with it (the privacy page says so)
|
|
321
|
+
for (const k of await o.bucket.list('reads/')) {
|
|
322
|
+
const id = /^reads\/(.+)\.json$/.exec(k)?.[1]
|
|
323
|
+
if (id !== undefined && !keep.has(id)) await o.bucket.delete(k)
|
|
351
324
|
}
|
|
352
|
-
// the
|
|
353
|
-
|
|
354
|
-
for (const x of live) {
|
|
355
|
-
const r = results.get(x.id)!
|
|
356
|
-
if (r.prepared === null) continue
|
|
357
|
-
for (const m of r.prepared.served) if ((await o.bucket.get(KEYS.media(m.sha))) === null) await o.bucket.put(KEYS.media(m.sha), encoded.get(m.sha)!, 'image/webp')
|
|
358
|
-
const { copy, manifest } = r.prepared
|
|
359
|
-
const h = sha256(JSON.stringify({ copy: copy === null ? null : { view: copy.view, row: copy.row }, manifest }))
|
|
360
|
-
if (h !== x.pushed) {
|
|
361
|
-
if (copy !== null && manifest !== null) {
|
|
362
|
-
// the manifest last: the door serves a share's copy once its manifest names it
|
|
363
|
-
await o.bucket.put(KEYS.view(x.id), JSON.stringify(copy.view), 'application/json')
|
|
364
|
-
await o.bucket.put(KEYS.row(x.id), JSON.stringify(copy.row), 'application/json')
|
|
365
|
-
await o.bucket.put(KEYS.files(x.id), JSON.stringify(manifest), 'application/json')
|
|
366
|
-
}
|
|
367
|
-
report.pushed++
|
|
368
|
-
}
|
|
369
|
-
r.pushed = h
|
|
370
|
-
// where the advisor's reading stands: pulled each pass, written by the door on their own page
|
|
371
|
-
r.read = readOf(await o.bucket.get(KEYS.reads(x.id)), r.prepared.his)
|
|
372
|
-
}
|
|
373
|
-
const keep = new Set(Object.keys(shares.shares))
|
|
374
|
-
// an ended share's copy: its manifest first, so the door stops serving it before its view goes; its cursor after
|
|
375
|
-
for (const prefix of ['files/', 'view/', 'row/', 'reads/'])
|
|
376
|
-
for (const k of await o.bucket.list(prefix)) {
|
|
377
|
-
const id = /^[a-z]+\/(.+)\.json$/.exec(k)?.[1]
|
|
378
|
-
if (id !== undefined && !keep.has(id)) {
|
|
379
|
-
await o.bucket.delete(k)
|
|
380
|
-
if (prefix === 'files/') report.removed++
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
// a file the page staged and no words took: gone after an hour, or with its share
|
|
384
|
-
const projects = new Set(Object.keys(shares.projects ?? {}))
|
|
325
|
+
// a file the page staged and no words took: gone after an hour, or with its share or project
|
|
326
|
+
const places = new Set(startPlacesOf(s, now).map((x) => x.id))
|
|
385
327
|
for (const k of await o.bucket.list('stage/')) {
|
|
386
328
|
const m = /^stage\/(s|p)\/([^/]+)\/(\d{13})-/.exec(k)
|
|
387
|
-
const open = m !== null && (m[1] === 's' ? keep :
|
|
329
|
+
const open = m !== null && (m[1] === 's' ? keep : places).has(m[2]!)
|
|
388
330
|
if (m === null || !open || Number(m[3]) < now.getTime() - 3_600_000) await o.bucket.delete(k)
|
|
389
331
|
}
|
|
390
|
-
// each advisor's own photo, while a share or a project names it: read by that advisor's page alone (edge/handler.ts)
|
|
391
|
-
const photos = new Map<string, string>()
|
|
392
|
-
for (const v of [...Object.values(shares.shares), ...Object.values(shares.projects ?? {})]) {
|
|
393
|
-
const a = s.advisors.find((y) => y.email === v.email)
|
|
394
|
-
if (v.photo !== undefined && a !== undefined) photos.set(v.photo, a.id)
|
|
395
|
-
}
|
|
396
|
-
for (const [sha, id] of photos) {
|
|
397
|
-
if ((await o.bucket.get(KEYS.photo(sha))) !== null) continue
|
|
398
|
-
const bytes = photoBytes(dir, 'advisors', id, 64)
|
|
399
|
-
if (bytes !== null) await o.bucket.put(KEYS.photo(sha), bytes, 'image/webp')
|
|
400
|
-
}
|
|
401
332
|
// a person no longer in the list: their sessions end; one no longer known: their password too
|
|
402
333
|
const signed = new Set(Object.keys(logins).map(sha256))
|
|
403
334
|
const known = new Set(s.advisors.map((a) => sha256(a.email)))
|
|
404
335
|
for (const k of await o.bucket.list('session/')) if (!signed.has(k.split('/')[1] ?? '')) await o.bucket.delete(k)
|
|
405
336
|
for (const k of await o.bucket.list('login/')) if (!known.has(/^login\/([0-9a-f]{64})\./.exec(k)?.[1] ?? '')) await o.bucket.delete(k)
|
|
406
|
-
for (const k of await o.bucket.list('photo/')) {
|
|
407
|
-
const sha = /^photo\/([0-9a-f]{64})\.webp$/.exec(k)?.[1]
|
|
408
|
-
if (sha === undefined || !photos.has(sha)) await o.bucket.delete(k)
|
|
409
|
-
}
|
|
410
|
-
for (const k of await o.bucket.list('media/')) {
|
|
411
|
-
const sha = /^media\/([0-9a-f]{64})\.webp$/.exec(k)?.[1]
|
|
412
|
-
if (sha === undefined || !media.has(sha)) await o.bucket.delete(k)
|
|
413
|
-
}
|
|
414
337
|
} catch (e) {
|
|
415
|
-
report.errors.push(`the
|
|
416
|
-
for (const r of results.values()) r.reach = { ok: false, at: now.toISOString(), why: `the bucket: ${(e as Error).message}` }
|
|
417
|
-
} finally {
|
|
418
|
-
encoded.clear()
|
|
338
|
+
report.errors.push(`the users' folder: ${(e as Error).message}`)
|
|
419
339
|
}
|
|
420
340
|
withState(dir, (st) => {
|
|
421
341
|
for (const x of st.shares) {
|
|
@@ -423,45 +343,35 @@ export async function syncOnce(dir: string, o: { bucket: Bucket; words: string[]
|
|
|
423
343
|
if (r !== undefined) {
|
|
424
344
|
x.reach = r.reach
|
|
425
345
|
if (r.prepared !== null) {
|
|
426
|
-
//
|
|
346
|
+
// a share holds nothing back: the store's stale `held` and `waiting` fields go
|
|
427
347
|
x.masked = r.prepared.masked
|
|
428
348
|
delete x.held
|
|
429
349
|
delete x.waiting
|
|
430
350
|
x.parts = r.prepared.parts
|
|
351
|
+
x.pushed = sha256(JSON.stringify({ view: r.prepared.theirs?.view ?? null, manifest: r.prepared.manifest }))
|
|
431
352
|
}
|
|
432
|
-
if (r.pushed !== undefined) x.pushed = r.pushed
|
|
433
353
|
if (r.read !== undefined) {
|
|
434
354
|
if (r.read === null) delete x.read
|
|
435
355
|
else x.read = r.read
|
|
436
356
|
}
|
|
437
357
|
} else if (x.state === 'revoked' || (x.state === 'live' && !isLive(x, now))) {
|
|
438
358
|
x.reach = report.errors.length === 0 ? { ok: true, at: now.toISOString() } : { ok: false, at: now.toISOString(), why: report.errors[0]! }
|
|
439
|
-
// where they stopped reading goes with the share
|
|
359
|
+
// where they stopped reading goes with the share
|
|
440
360
|
delete x.read
|
|
441
361
|
}
|
|
442
362
|
}
|
|
443
363
|
})
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
report.advice = (await importAdvice(dir, o.bucket, now)).length
|
|
447
|
-
// what came back is drawn in the copies by this pass, not the next: the person's page shows their act (their
|
|
448
|
-
// words, « waits for <owner> », a thread they opened) within one pass of the job
|
|
449
|
-
if (o.again !== false && (report.advice > 0 || readState(dir).proposals.length > proposed)) {
|
|
450
|
-
const r = await syncOnce(dir, { ...o, now, again: false })
|
|
451
|
-
report.pushed += r.pushed
|
|
452
|
-
report.removed += r.removed
|
|
453
|
-
report.errors.push(...r.errors)
|
|
454
|
-
}
|
|
455
|
-
}
|
|
364
|
+
report.advice = await deliverPending(dir, o.bucket, now)
|
|
365
|
+
await sweepUploads(dir, o.bucket, now)
|
|
456
366
|
return report
|
|
457
367
|
}
|
|
458
368
|
|
|
459
|
-
/** with no advisors page yet (not set up): each live share's masked entries, for
|
|
369
|
+
/** with no advisors page yet (not set up): each live share's masked entries, for the owner's preview */
|
|
460
370
|
export async function refreshLocal(dir: string, o: { words: string[]; now?: Date }): Promise<void> {
|
|
461
371
|
const now = o.now ?? new Date()
|
|
462
372
|
const s = readState(dir)
|
|
463
373
|
const got = new Map<string, Prepared | null>()
|
|
464
|
-
for (const x of s.shares.filter((y) => isLive(y, now))) got.set(x.id, await prepare(s, x, { words: o.words,
|
|
374
|
+
for (const x of s.shares.filter((y) => isLive(y, now))) got.set(x.id, await prepare(s, x, { words: o.words, now }))
|
|
465
375
|
withState(dir, (st) => {
|
|
466
376
|
for (const x of st.shares) {
|
|
467
377
|
const p = got.get(x.id)
|
package/src/advisors/tunnel.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
// the tunnel to the advisors
|
|
2
|
-
// (src/advisors-tunnel.shipkit.ts), keeps `cloudflared tunnel run` up while this machine carries
|
|
3
|
-
// tunnel's token is stored, and stops it when the hq moves: one connector only, on the Mac
|
|
1
|
+
// the tunnel to the advisors page (wiki tools/shipkit/advisors.md, Who calls: the users' port): `sk advisors
|
|
2
|
+
// tunnel`, a pm process (src/advisors-tunnel.shipkit.ts), keeps `cloudflared tunnel run` up while this machine carries
|
|
3
|
+
// the hq and the tunnel's token is stored, and stops it when the hq moves: one connector only, on the Mac whose daemon
|
|
4
|
+
// opens the users' port.
|
|
4
5
|
// The one constraint a reader breaks first: the token goes to cloudflared by its environment (TUNNEL_TOKEN), never on
|
|
5
6
|
// its command line and never in a line of the log
|
|
6
7
|
import { existsSync } from 'node:fs'
|
|
7
8
|
import { readSecretHere } from '../secrets/read.ts'
|
|
8
|
-
import { TUNNEL_TOKEN } from './
|
|
9
|
+
import { TUNNEL_TOKEN } from './reach.ts'
|
|
9
10
|
|
|
10
11
|
export type Proc = { exited: Promise<unknown>; kill: () => void }
|
|
11
12
|
|
|
@@ -38,7 +39,7 @@ export const cloudflaredBin = (): string | null => BINS.find((b) => existsSync(b
|
|
|
38
39
|
/** the global process that keeps cloudflared up (src/advisors-tunnel.shipkit.ts at the house's root) */
|
|
39
40
|
export const TUNNEL_PROCESS = 'advisors-tunnel'
|
|
40
41
|
|
|
41
|
-
/** cloudflared for the
|
|
42
|
+
/** cloudflared for the advisors page's setup: its binary, and the tunnel process started through the one road that starts a
|
|
42
43
|
* global process (pm's switch), null once it runs, else why not. A surface that reaches pm hands it in */
|
|
43
44
|
export interface TunnelStart {
|
|
44
45
|
bin: () => string | null
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// the users' port, opened by the daemon itself (wiki tools/shipkit/advisors.md, Who calls): on 127.0.0.1 alone, which
|
|
2
|
+
// the tunnel reaches, while this machine carries the hq and the advisors page is set up; looked at every 30 s, opened
|
|
3
|
+
// again with a new name. The one server besides the house's loopback one (RV040 allows this file). The one constraint
|
|
4
|
+
// a reader breaks first: its router is users-router.ts, which reaches no route of the hub, no owner word, no vault
|
|
5
|
+
import { DirBucket } from './dir-bucket.ts'
|
|
6
|
+
import { factsOf, type PageFacts } from './edge/pages.ts'
|
|
7
|
+
import { limits, type PasswordHasher } from './edge/sign-in.ts'
|
|
8
|
+
import { FILE_MAX } from './edge/types.ts'
|
|
9
|
+
import { housePageFacts } from './speaks.ts'
|
|
10
|
+
import { ownerNameOf } from './owner-name.ts'
|
|
11
|
+
import { advisorsDir, readState } from './owner-store.ts'
|
|
12
|
+
import { privateWords } from './sync.ts'
|
|
13
|
+
import { usersRouter } from './users-router.ts'
|
|
14
|
+
import { usersDir, usersPort } from './users-store.ts'
|
|
15
|
+
|
|
16
|
+
/** a password as the port keeps it: argon2id */
|
|
17
|
+
export const ARGON: PasswordHasher = { hash: (p) => Bun.password.hash(p, { algorithm: 'argon2id' }), verify: (p, h) => Bun.password.verify(p, h) }
|
|
18
|
+
|
|
19
|
+
const EVERY_MS = 30_000
|
|
20
|
+
|
|
21
|
+
/** the users' port on 127.0.0.1 with its router. No shared port: another program of this Mac may not bind beside it
|
|
22
|
+
* and take its requests */
|
|
23
|
+
export function usersServe(o: { port: number; fetch: (req: Request) => Promise<Response>; tls?: { cert: string; key: string } }): Bun.Server<undefined> {
|
|
24
|
+
// no body past the largest file a person may send, whatever the route: a stranger's 100 MB is refused by the server
|
|
25
|
+
return Bun.serve({ hostname: '127.0.0.1', port: o.port, maxRequestBodySize: FILE_MAX + 64 * 1024, ...(o.tls ? { tls: o.tls } : {}), fetch: o.fetch, error: () => new Response('error', { status: 500 }) })
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ListenerDeps {
|
|
29
|
+
carries?: () => boolean
|
|
30
|
+
host?: () => string | null
|
|
31
|
+
/** the name the public pages print: the owner's default (owner-name.ts) */
|
|
32
|
+
owner?: () => string
|
|
33
|
+
/** the port opened over the owner's advisors folder; tests pass their own */
|
|
34
|
+
listen?: (host: string, pages: PageFacts) => Promise<{ stop: () => void }>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** the port over the owner's advisors folder, the owner's private words read again each minute */
|
|
38
|
+
async function listenHere(house: string, host: string, pages: PageFacts): Promise<{ stop: () => void }> {
|
|
39
|
+
const users = new DirBucket(usersDir())
|
|
40
|
+
let words: { at: number; list: string[] } = { at: 0, list: [] }
|
|
41
|
+
const wordsNow = (): string[] => (Date.now() - words.at < 60_000 ? words.list : (words = { at: Date.now(), list: privateWords(house) }).list)
|
|
42
|
+
const s = usersServe({ port: usersPort(), fetch: usersRouter({ bucket: users, host, pages, limits: limits(), password: ARGON, dir: advisorsDir(), words: wordsNow }) })
|
|
43
|
+
return { stop: () => void s.stop(true) }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** the port kept open while this machine carries the hq and the page is set up, opened again on a new name */
|
|
47
|
+
export function usersListener(o: { house: string; print: (l: string) => void; printErr: (l: string) => void; everyMs?: number } & ListenerDeps): { stop: () => void; tick: () => Promise<void> } {
|
|
48
|
+
const host = o.host ?? (() => readState(advisorsDir()).host)
|
|
49
|
+
const owner = o.owner ?? (() => ownerNameOf(readState(advisorsDir())))
|
|
50
|
+
const listen = o.listen ?? ((h: string, pages: PageFacts) => listenHere(o.house, h, pages))
|
|
51
|
+
let here: { host: string; owner: string; stop: () => void } | null = null
|
|
52
|
+
let stopped = false
|
|
53
|
+
const look = async (): Promise<void> => {
|
|
54
|
+
let want: string | null = null
|
|
55
|
+
let name = 'the owner'
|
|
56
|
+
try {
|
|
57
|
+
const carries = o.carries ?? (await import('../hq/hq-role.ts')).carriesHq
|
|
58
|
+
want = carries() ? host() : null
|
|
59
|
+
name = owner()
|
|
60
|
+
} catch (e) {
|
|
61
|
+
o.printErr(`WARN advisors page: ${(e as Error).message}`)
|
|
62
|
+
}
|
|
63
|
+
// a new name for the public pages: the port opens again
|
|
64
|
+
if (here !== null && (here.host !== want || here.owner !== name)) {
|
|
65
|
+
here.stop()
|
|
66
|
+
here = null
|
|
67
|
+
}
|
|
68
|
+
if (want === null || here !== null) return
|
|
69
|
+
const pages = (await housePageFacts(o.house).catch(() => null))?.facts ?? factsOf(undefined, undefined)
|
|
70
|
+
if (stopped) return
|
|
71
|
+
try {
|
|
72
|
+
here = { host: want, owner: name, ...(await listen(want, pages)) }
|
|
73
|
+
o.print(`advisors page: serving ${want} from this daemon`)
|
|
74
|
+
} catch (e) {
|
|
75
|
+
o.printErr(`WARN advisors page: the users' port did not open here: ${(e as Error).message}`)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// one look at a time: a tick while one runs waits for that one
|
|
79
|
+
let running: Promise<void> | null = null
|
|
80
|
+
const tick = (): Promise<void> => (running ??= look().finally(() => (running = null)))
|
|
81
|
+
void tick()
|
|
82
|
+
const timer = setInterval(() => void tick(), o.everyMs ?? EVERY_MS)
|
|
83
|
+
return {
|
|
84
|
+
tick,
|
|
85
|
+
stop: () => {
|
|
86
|
+
stopped = true
|
|
87
|
+
clearInterval(timer)
|
|
88
|
+
here?.stop()
|
|
89
|
+
here = null
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
}
|