rvlib-shipkit 2.28.0 → 2.29.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 +55 -0
- package/package.json +10 -2
- package/src/advisors/acts.ts +277 -0
- package/src/advisors/advice.ts +384 -0
- package/src/advisors/advisor-view.ts +417 -0
- package/src/advisors/app-graph.ts +112 -0
- package/src/advisors/app.ts +75 -0
- package/src/advisors/door.ts +59 -0
- package/src/advisors/edge/api.ts +292 -0
- package/src/advisors/edge/bucket.ts +43 -0
- package/src/advisors/edge/certs.ts +20 -0
- package/src/advisors/edge/form.ts +45 -0
- package/src/advisors/edge/handler.ts +156 -0
- package/src/advisors/edge/jwt.ts +76 -0
- package/src/advisors/edge/shell.ts +27 -0
- package/src/advisors/edge/status.ts +12 -0
- package/src/advisors/edge/types.ts +137 -0
- package/src/advisors/edge/worker.ts +52 -0
- package/src/advisors/expose.ts +150 -0
- package/src/advisors/job.ts +35 -0
- package/src/advisors/owner-store.ts +226 -0
- package/src/advisors/photos.ts +182 -0
- package/src/advisors/project.ts +311 -0
- package/src/advisors/r2.ts +48 -0
- package/src/advisors/routes.ts +469 -0
- package/src/advisors/scan.ts +194 -0
- package/src/advisors/sync.ts +363 -0
- package/src/agent-time/accounts-usage-disk.ts +29 -0
- package/src/agent-time/accounts-usage.ts +97 -0
- package/src/agent-time/hooks.ts +64 -27
- package/src/agent-time/lane-name.ts +7 -0
- package/src/agent-time/leads.ts +95 -0
- package/src/agent-time/registry.ts +106 -41
- package/src/agent-time/render.ts +35 -4
- package/src/agent-time/report-cache.ts +4 -8
- package/src/agent-time/report.ts +19 -1
- package/src/agent-time/store.ts +10 -16
- package/src/annex/snapshots.ts +3 -3
- package/src/annex/tidy.ts +10 -23
- package/src/asks/ask-after.ts +2 -1
- package/src/asks/ask-carry.ts +190 -0
- package/src/asks/ask-close.ts +72 -0
- package/src/asks/ask-doc.ts +42 -0
- package/src/asks/ask-migrate.ts +9 -9
- package/src/asks/ask-steps-fold.ts +71 -114
- package/src/asks/ask-store.ts +170 -53
- package/src/asks/ask-words-fold.ts +208 -0
- package/src/checks/SK001-package-json-shape.check.ts +5 -7
- package/src/checks/SK004-gitignore-policy.check.ts +13 -13
- package/src/checks/SK010-undeclared-unit.check.ts +77 -64
- package/src/checks/SK013-one-way-in-policy.check.ts +20 -8
- package/src/checks/SK027-agent-wiki-links.check.ts +46 -6
- package/src/checks/SK033-global-contribution.check.ts +1 -1
- package/src/checks/SK036-draft-media-size.check.ts +5 -4
- package/src/checks/SK039-vscode-watch-generated.check.ts +1 -1
- package/src/checks/SK040-release-words.check.ts +39 -10
- package/src/checks/SK042-post-kinds.check.ts +2 -2
- package/src/checks/SK045-slow-hooks.check.ts +5 -2
- package/src/checks/SK049-thread-answers-hook.check.ts +6 -4
- package/src/checks/SK051-no-formatter.check.ts +485 -0
- package/src/cli/cmd_Advisors.ts +336 -0
- package/src/cli/cmd_Annex.ts +10 -10
- package/src/cli/cmd_Asks.ts +111 -10
- package/src/cli/cmd_Backup.ts +7 -7
- package/src/cli/cmd_CacheAudit.ts +1 -1
- package/src/cli/cmd_Check.ts +3 -3
- package/src/cli/cmd_Checks.ts +1 -1
- package/src/cli/cmd_Ci.ts +15 -16
- package/src/cli/cmd_Db.ts +9 -9
- package/src/cli/cmd_FleetPush.ts +1 -1
- package/src/cli/cmd_History.ts +2 -2
- package/src/cli/cmd_Home.ts +5 -6
- package/src/cli/cmd_Hooks.ts +13 -3
- package/src/cli/cmd_Hq.ts +30 -19
- package/src/cli/cmd_Keys.ts +1 -1
- package/src/cli/cmd_Lanes.ts +9 -3
- package/src/cli/cmd_Media.ts +59 -13
- package/src/cli/cmd_Orchestrator.ts +138 -0
- package/src/cli/cmd_Rec.ts +5 -2
- package/src/cli/cmd_Reflect.ts +17 -3
- package/src/cli/cmd_Releases.ts +38 -38
- package/src/cli/cmd_Review.ts +690 -316
- package/src/cli/cmd_Shot.ts +14 -6
- package/src/cli/cmd_Social.ts +5 -4
- package/src/cli/cmd_SocialDrafts.ts +23 -10
- package/src/cli/cmd_Space.ts +1 -1
- package/src/cli/cmd_Start.ts +1 -1
- package/src/cli/cmd_ThreadKinds.ts +18 -11
- package/src/cli/cmd_ThreadReflect.ts +20 -12
- package/src/cli/cmd_ThreadSyncNeeds.ts +7 -7
- package/src/cli/cmd_Time.ts +2 -1
- package/src/cli/cmd_Tmp.ts +9 -8
- package/src/cli/cmd_TraceAudit.ts +1 -1
- package/src/cli/cmd_Trailer.ts +5 -5
- package/src/cli/cmd_Urls.ts +3 -3
- package/src/cli/cmd_Vault.ts +4 -4
- package/src/cli/cmd_When.ts +1 -1
- package/src/cli/cmd_Worktrees.ts +109 -0
- package/src/cli/registry.ts +15 -4
- package/src/cli.ts +21 -13
- package/src/collections/actions.ts +2 -1
- package/src/collections/checks.ts +1 -1
- package/src/collections/collection-types.ts +16 -5
- package/src/collections/pings.ts +3 -0
- package/src/collections/providers.ts +15 -15
- package/src/collections/review.ts +25 -23
- package/src/collections/state-rules.ts +8 -7
- package/src/comfy/comfy-panel.ts +2 -2
- package/src/commands/model.ts +1 -1
- package/src/commands/routes.ts +1 -1
- package/src/commands/runs.ts +1 -1
- package/src/core/app-icon.ts +3 -9
- package/src/core/atomic-write.ts +36 -0
- package/src/core/budget.ts +16 -1
- package/src/core/bun-builtins.ts +7 -7
- package/src/core/canonical-scripts.ts +4 -6
- package/src/core/check-ctx.ts +17 -3
- package/src/core/day-stamp.ts +20 -0
- package/src/core/git-bin.ts +10 -0
- package/src/core/git.ts +60 -16
- package/src/core/hard-reset.ts +1 -2
- package/src/core/history-files.ts +4 -8
- package/src/core/house-layout.ts +3 -0
- package/src/core/hub-theme.ts +16 -0
- package/src/core/identity.ts +1 -1
- package/src/core/in-base.ts +19 -0
- package/src/core/instance.ts +15 -5
- package/src/core/last-good.ts +42 -133
- package/src/core/layout.ts +1 -1
- package/src/core/load-probe.ts +4 -8
- package/src/core/locked-write.ts +117 -47
- package/src/core/loop-watch.ts +24 -3
- package/src/core/machine-db.ts +54 -12
- package/src/core/machine-link.ts +1 -1
- package/src/core/memory-watch.ts +3 -2
- package/src/core/motherhome.ts +2 -1
- package/src/core/nearest.ts +23 -0
- package/src/core/on-loop.ts +57 -0
- package/src/core/one-way-in-policy.ts +26 -13
- package/src/core/raw-access.ts +9 -2
- package/src/core/reexec.ts +3 -5
- package/src/core/repo-walk.ts +104 -0
- package/src/core/retention.ts +10 -12
- package/src/core/run-dirs.ts +45 -0
- package/src/core/runs-matrix.ts +1 -1
- package/src/core/slots.ts +2 -2
- package/src/core/slug.ts +33 -0
- package/src/core/spawn-timeout.ts +3 -1
- package/src/core/squircle.ts +0 -8
- package/src/core/throwaway-worktree.ts +21 -2
- package/src/core/unit-files.ts +4 -4
- package/src/core/when-block.ts +4 -5
- package/src/core/when.ts +1 -3
- package/src/core/words.ts +33 -0
- package/src/fleet/push-fleet.ts +4 -11
- package/src/{core → gate}/cache-audit.ts +1 -1
- package/src/{core → gate}/check-runner.ts +24 -54
- package/src/{core → gate}/discover-checks.ts +5 -102
- package/src/{core → gate}/discover-legacy-checks.ts +3 -3
- package/src/{ledger → gate}/gate-checks.ts +5 -5
- package/src/gate/head-gate.ts +151 -0
- package/src/{core → gate}/job-follow.ts +1 -1
- package/src/{core → gate}/job-run.ts +3 -3
- package/src/{core → gate}/pre-commit-discovery.ts +2 -2
- package/src/{core → gate}/run-check.ts +7 -7
- package/src/{core → gate}/run-ci.ts +9 -9
- package/src/gate/run-fix.ts +173 -0
- package/src/{core → gate}/run-fixers.ts +14 -14
- package/src/{core → gate}/trace-audit.ts +8 -8
- package/src/home/activity-shape.ts +1 -1
- package/src/home/activity.ts +13 -11
- package/src/home/app-sign.ts +17 -9
- package/src/home/daemon-guard.ts +6 -0
- package/src/home/daemon-jobs.ts +52 -10
- package/src/home/database-words.ts +21 -27
- package/src/home/databases.ts +3 -3
- package/src/home/global-context.ts +2 -2
- package/src/home/global-units.ts +1 -1
- package/src/home/gui-app/ShipkitGui.swift +129 -55
- package/src/home/gui-app.ts +1 -1
- package/src/home/handover.ts +126 -0
- package/src/home/home-move.ts +29 -16
- package/src/home/home-paths.ts +30 -8
- package/src/home/home-routes.ts +75 -5
- package/src/home/home-start.ts +1 -1
- package/src/home/home-state.ts +12 -6
- package/src/home/hubs.ts +28 -5
- package/src/home/inbox-shape.ts +61 -38
- package/src/home/inbox.ts +2 -1
- package/src/home/lib-watch.ts +93 -74
- package/src/home/machine-fold.ts +46 -43
- package/src/home/machine-repair.ts +5 -6
- package/src/home/machine-stores.ts +3 -3
- package/src/home/machine-temp.ts +58 -67
- package/src/home/page-build.ts +330 -0
- package/src/home/page-held.ts +338 -0
- package/src/home/pm-config.ts +10 -2
- package/src/home/pm.ts +35 -1
- package/src/home/process-apps.ts +3 -3
- package/src/home/push-sources.ts +132 -0
- package/src/home/run-daemon.ts +54 -4
- package/src/home/run-pm.ts +2 -1
- package/src/home/run-web.ts +11 -6
- package/src/home/search-shape.ts +54 -0
- package/src/home/search.ts +114 -0
- package/src/home/serve-daemon.ts +40 -18
- package/src/home/serve-web.ts +86 -145
- package/src/home/space-page.ts +7 -7
- package/src/home/space-words.ts +11 -10
- package/src/home/supervise.ts +24 -0
- package/src/home/time-page-shape.ts +0 -13
- package/src/home/vault-page.ts +15 -15
- package/src/home/vault-reveal.ts +29 -0
- package/src/home/vault-words.ts +3 -3
- package/src/home/via-hub.ts +3 -4
- package/src/home/worktree-tidy.ts +236 -0
- package/src/hooks/edit-guard.ts +12 -0
- package/src/hooks/hook-gates.ts +2 -0
- package/src/hooks/leak-guard.ts +9 -3
- package/src/hooks/one-way-in-guard.ts +11 -3
- package/src/hooks/run-hooks.ts +58 -5
- package/src/hooks/shared-file.ts +174 -0
- package/src/{serve → house}/project-gutter.ts +5 -1
- package/src/hq/door-route.ts +2 -2
- package/src/hq/door.ts +3 -3
- package/src/hq/files-send.ts +5 -5
- package/src/hq/forgotten-log.ts +1 -1
- package/src/hq/history-check.ts +7 -6
- package/src/hq/history-send.ts +12 -14
- package/src/hq/hq-db.ts +1 -1
- package/src/hq/hq-local.ts +12 -10
- package/src/hq/hq-routes.ts +1 -1
- package/src/hq/hq-store.ts +4 -4
- package/src/hq/kinds/ask.ts +4 -3
- package/src/hq/kinds/index.ts +4 -4
- package/src/hq/kinds/{card-gone.ts → item-gone.ts} +24 -25
- package/src/hq/kinds/{card-msg.ts → item-msg.ts} +25 -27
- package/src/hq/kinds/{card.ts → item.ts} +31 -29
- package/src/hq/kinds/kind.ts +3 -0
- package/src/hq/kinds/media.ts +2 -3
- package/src/hq/kinds/prompt.ts +2 -1
- package/src/hq/kinds/time-day.ts +5 -4
- package/src/hq/ledger.ts +22 -22
- package/src/hq/machine-notes.ts +14 -15
- package/src/hq/outbox.ts +31 -22
- package/src/hq/report.ts +10 -12
- package/src/hq/switch.ts +20 -23
- package/src/hq/{cards.ts → thread-sync.ts} +127 -99
- package/src/hq/vault-route.ts +1 -1
- package/src/{serve → http}/door-forward.ts +11 -4
- package/src/http/loopback-serve.ts +84 -0
- package/src/{serve → http}/same-origin.ts +3 -2
- package/src/{serve → http}/tailnet-caller.ts +5 -4
- package/src/identities/machine-route.ts +2 -2
- package/src/identities/shown.ts +2 -6
- package/src/ledger/check-table.ts +1 -1
- package/src/ledger/db.ts +1 -0
- package/src/ledger/git-key.ts +9 -3
- package/src/ledger/git-scan.ts +2 -2
- package/src/ledger/ledger.ts +6 -16
- package/src/media-kinds.ts +4 -1
- package/src/media-store/backup/daemon.ts +3 -2
- package/src/media-store/backup/keys.ts +0 -3
- package/src/media-store/backup/manifest.ts +1 -1
- package/src/media-store/backup/prune.ts +15 -18
- package/src/media-store/backup/retention.ts +2 -2
- package/src/media-store/backup/run.ts +8 -27
- package/src/media-store/backup/sources.ts +11 -12
- package/src/media-store/backup/thread-copy.ts +8 -9
- package/src/media-store/backup/watch.ts +10 -6
- package/src/media-store/content.ts +3 -0
- package/src/media-store/copy/night.ts +4 -4
- package/src/media-store/daemon.ts +5 -4
- package/src/media-store/db.ts +10 -20
- package/src/media-store/forget-one.ts +247 -0
- package/src/media-store/forget.ts +23 -4
- package/src/media-store/hq-send.ts +5 -4
- package/src/media-store/purge.ts +2 -2
- package/src/media-store/remote.ts +2 -2
- package/src/media-store/space-listing.ts +0 -5
- package/src/media-store/space.ts +1 -0
- package/src/media-store/tidy.ts +3 -3
- package/src/media-store/upload.ts +2 -2
- package/src/media-store/webp.ts +3 -3
- package/src/messages/objects.ts +5 -3
- package/src/messages/score.ts +1 -3
- package/src/messages/store-doc.ts +114 -0
- package/src/messages/verdicts.ts +6 -0
- package/src/messages/write.ts +3 -3
- package/src/mv/mv-md.ts +43 -12
- package/src/orchestrator/brief.md +29 -0
- package/src/orchestrator/deliver.ts +81 -0
- package/src/orchestrator/drill.ts +129 -0
- package/src/orchestrator/guards.ts +63 -0
- package/src/orchestrator/keeper.ts +332 -0
- package/src/orchestrator/phone.ts +98 -0
- package/src/orchestrator/pm.ts +20 -0
- package/src/orchestrator/presence-shape.ts +17 -0
- package/src/orchestrator/presence.ts +68 -0
- package/src/orchestrator/push.ts +102 -0
- package/src/orchestrator/routes.ts +113 -0
- package/src/orchestrator/state.ts +92 -0
- package/src/orchestrator/switch.ts +86 -0
- package/src/orchestrator/tmux.ts +82 -0
- package/src/orchestrator/unheard.ts +68 -0
- package/src/pages/unit.ts +1 -1
- package/src/plan/repo-source.ts +1 -1
- package/src/recordings/load.ts +1 -1
- package/src/recordings/model.ts +18 -10
- package/src/recordings/place.ts +3 -3
- package/src/recordings/recorder-app/Capture.swift +69 -21
- package/src/recordings/recorder-app/Editor.swift +214 -11
- package/src/recordings/recorder-app/main.swift +229 -47
- package/src/recordings/recorder-app.ts +1 -1
- package/src/recordings/routes.ts +11 -1
- package/src/recordings/take.ts +7 -5
- package/src/recordings/view.ts +6 -0
- package/src/reflect/prompt-corpus.ts +5 -3
- package/src/reflect/thread-words.ts +51 -0
- package/src/reflections/reflection-close.ts +123 -0
- package/src/reflections/reflection-doc.ts +59 -0
- package/src/reflections/reflection-place.ts +60 -0
- package/src/release/gate-checkout.ts +122 -20
- package/src/release/git-facts.ts +9 -8
- package/src/release/machine-words.ts +21 -3
- package/src/release/public-clean.ts +78 -19
- package/src/release/run-bump.ts +3 -5
- package/src/release/run-release.ts +42 -38
- package/src/releases/add.ts +33 -87
- package/src/releases/{from-card.ts → from-thread.ts} +47 -46
- package/src/releases/model.ts +207 -36
- package/src/releases/routes.ts +2 -2
- package/src/releases/shape.ts +184 -0
- package/src/releases/store.ts +10 -10
- package/src/repo-config.ts +13 -3
- package/src/review/anim.ts +7 -7
- package/src/review/answer-kinds.ts +39 -10
- package/src/review/auto.ts +3 -3
- package/src/review/band.ts +95 -3
- package/src/review/branch-hold.ts +12 -5
- package/src/review/cells.ts +169 -46
- package/src/review/doc-card.ts +41 -0
- package/src/review/doc-model.ts +100 -0
- package/src/review/doc-routes.ts +66 -0
- package/src/review/doc-save.ts +152 -0
- package/src/review/{draft-card.ts → draft-item.ts} +10 -7
- package/src/review/draft-model.ts +125 -17
- package/src/review/events.ts +5 -12
- package/src/review/file-tags.ts +52 -0
- package/src/review/format.ts +84 -41
- package/src/review/gone.ts +20 -20
- package/src/review/hand-over.ts +58 -0
- package/src/review/heard.ts +29 -0
- package/src/review/house-kind-defs.ts +34 -4
- package/src/review/http.ts +1 -1
- package/src/review/inbox-hook.ts +55 -9
- package/src/review/inbox-read.ts +38 -13
- package/src/review/instructions.ts +42 -0
- package/src/review/{card-db.ts → item-db.ts} +32 -30
- package/src/review/{card-rows.ts → item-rows.ts} +77 -50
- package/src/review/kind-still.ts +125 -0
- package/src/review/kinds.ts +46 -10
- package/src/review/lane-ask.ts +6 -2
- package/src/review/live-post.ts +107 -0
- package/src/review/live-view.ts +137 -0
- package/src/review/media-kind.ts +4 -4
- package/src/review/media-read.ts +4 -4
- package/src/review/media.ts +3 -5
- package/src/review/mentions.ts +100 -0
- package/src/review/model-moved.ts +76 -0
- package/src/review/model.ts +471 -149
- package/src/review/move.ts +59 -58
- package/src/review/need-address.ts +5 -5
- package/src/review/need-threads.ts +15 -57
- package/src/review/notes.ts +2 -1
- package/src/review/one-block.ts +64 -0
- package/src/review/owner-read.ts +41 -0
- package/src/review/owner-verdict.ts +3 -3
- package/src/review/parties.ts +101 -9
- package/src/review/paste.ts +4 -4
- package/src/review/phone-push.ts +137 -0
- package/src/review/previews.ts +16 -16
- package/src/review/project.ts +1 -1
- package/src/review/push.ts +269 -0
- package/src/review/referring.ts +26 -4
- package/src/review/reflection-object.ts +13 -18
- package/src/review/rev.ts +1 -1
- package/src/review/role.ts +3 -3
- package/src/review/routes.ts +113 -74
- package/src/review/search-index.ts +218 -0
- package/src/review/search-job.ts +40 -0
- package/src/review/search-ocr.ts +138 -0
- package/src/review/search-text.ts +129 -0
- package/src/review/secret-route.ts +44 -14
- package/src/review/settle.ts +67 -0
- package/src/review/stage-routes.ts +15 -13
- package/src/review/{stage-card.ts → stage-thread.ts} +18 -17
- package/src/review/store-index.ts +49 -0
- package/src/review/store-parties.ts +20 -0
- package/src/review/store.ts +394 -214
- package/src/review/supersede.ts +23 -7
- package/src/review/take-back.ts +19 -6
- package/src/review/threads.ts +184 -63
- package/src/review/traces.ts +21 -33
- package/src/review/trailer-desk.ts +7 -7
- package/src/review/{trailer-card.ts → trailer-item.ts} +10 -10
- package/src/review/trailer-model.ts +4 -4
- package/src/review/trailer-notes.ts +2 -2
- package/src/review/trailer-routes.ts +5 -4
- package/src/review/trailer-shots.ts +3 -3
- package/src/review/unit.ts +70 -9
- package/src/review/uploads.ts +103 -0
- package/src/review/verdict-items.ts +2 -2
- package/src/review/verdict-write.ts +1 -1
- package/src/review/view-layout.ts +69 -0
- package/src/review/wait.ts +11 -5
- package/src/review/wakes.ts +115 -0
- package/src/review/watch-feed.ts +183 -0
- package/src/review/watchers.ts +27 -6
- package/src/rules/untrack-generated.ts +40 -39
- package/src/scaffold/files/bunfig.toml +1 -9
- package/src/scaffold/files/vscode-settings.json +1 -1
- package/src/scaffold/project-scaffold.ts +14 -10
- package/src/secrets/archive.ts +2 -1
- package/src/secrets/keychain-write.ts +11 -3
- package/src/secrets/lapse-mark.ts +8 -3
- package/src/secrets/lapse.ts +26 -15
- package/src/secrets/security-line.ts +19 -0
- package/src/serve/embed.ts +1 -1
- package/src/serve/house-runs.ts +1 -1
- package/src/serve/hub-app/accounts-line.tsx +67 -0
- package/src/serve/hub-app/activity-st.ts +46 -50
- package/src/serve/hub-app/advice-box.tsx +66 -0
- package/src/serve/hub-app/advisor-app.tsx +46 -0
- package/src/serve/hub-app/advisor-face.tsx +29 -0
- package/src/serve/hub-app/advisor-host.ts +142 -0
- package/src/serve/hub-app/advisor.html +22 -0
- package/src/serve/hub-app/advisors-st.ts +261 -0
- package/src/serve/hub-app/advisors-view.tsx +269 -0
- package/src/serve/hub-app/advisors.css +57 -0
- package/src/serve/hub-app/app-bridge.ts +27 -24
- package/src/serve/hub-app/ask-steps-st.ts +60 -0
- package/src/serve/hub-app/ask-steps.tsx +23 -0
- package/src/serve/hub-app/asks-page.tsx +8 -5
- package/src/serve/hub-app/asks-st.ts +1 -4
- package/src/serve/hub-app/auto-text.tsx +106 -14
- package/src/serve/hub-app/checks-svc.ts +1 -1
- package/src/serve/hub-app/clock-svc.ts +21 -5
- package/src/serve/hub-app/code-copy.ts +173 -12
- package/src/serve/hub-app/col-card.tsx +14 -21
- package/src/serve/hub-app/col-list-page.tsx +2 -2
- package/src/serve/hub-app/col-list-st.ts +6 -1
- package/src/serve/hub-app/col-tables.ts +14 -8
- package/src/serve/hub-app/cols-svc.ts +11 -1
- package/src/serve/hub-app/comfy-svc.ts +3 -2
- package/src/serve/hub-app/commands/commands-st.ts +36 -26
- package/src/serve/hub-app/controls.css +27 -11
- package/src/serve/hub-app/cursor-spot.ts +81 -0
- package/src/serve/hub-app/database-st.ts +31 -26
- package/src/serve/hub-app/database-view.tsx +12 -12
- package/src/serve/hub-app/dock-st.ts +51 -10
- package/src/serve/hub-app/dock-view.tsx +14 -1
- package/src/serve/hub-app/editor/doc-editor-st.ts +223 -0
- package/src/serve/hub-app/editor/doc-editor.tsx +116 -0
- package/src/serve/hub-app/editor/doc-saved.tsx +26 -0
- package/src/serve/hub-app/editor/doc-slot.ts +66 -0
- package/src/serve/hub-app/editor.css +36 -0
- package/src/serve/hub-app/emoji-names.ts +1915 -0
- package/src/serve/hub-app/emoji.ts +133 -0
- package/src/serve/hub-app/floating.tsx +162 -6
- package/src/serve/hub-app/git-st.ts +25 -19
- package/src/serve/hub-app/hash-route.ts +1 -1
- package/src/serve/hub-app/header-bar.tsx +4 -3
- package/src/serve/hub-app/held-keys.ts +25 -0
- package/src/serve/hub-app/home-st.ts +114 -16
- package/src/serve/hub-app/home-strip.css +3 -2
- package/src/serve/hub-app/home-strip.tsx +5 -2
- package/src/serve/hub-app/home.html +7 -0
- package/src/serve/hub-app/hub-app.tsx +56 -6
- package/src/serve/hub-app/hub.css +67 -31
- package/src/serve/hub-app/icons.tsx +10 -0
- package/src/serve/hub-app/identities-st.ts +35 -25
- package/src/serve/hub-app/identities-view.tsx +9 -6
- package/src/serve/hub-app/inbox-st.ts +39 -11
- package/src/serve/hub-app/inbox-view.tsx +10 -5
- package/src/serve/hub-app/inbox.css +6 -3
- package/src/serve/hub-app/index.html +7 -0
- package/src/serve/hub-app/insights-st.ts +27 -19
- package/src/serve/hub-app/instructions.css +9 -6
- package/src/serve/hub-app/kept-folds.ts +43 -0
- package/src/serve/hub-app/keys.ts +9 -3
- package/src/serve/hub-app/later.tsx +1 -1
- package/src/serve/hub-app/layout-st.ts +37 -6
- package/src/serve/hub-app/list-filter.tsx +1 -1
- package/src/serve/hub-app/live-bar.css +12 -0
- package/src/serve/hub-app/live-svc.ts +12 -2
- package/src/serve/hub-app/machine-st.ts +36 -10
- package/src/serve/hub-app/machines-st.ts +40 -34
- package/src/serve/hub-app/machines-view.tsx +5 -5
- package/src/serve/hub-app/markdown.css +81 -4
- package/src/serve/hub-app/md.ts +155 -9
- package/src/serve/hub-app/media-svc.ts +44 -11
- package/src/serve/hub-app/messages/messages-page.tsx +56 -12
- package/src/serve/hub-app/messages/messages-st.ts +26 -22
- package/src/serve/hub-app/new-thread.tsx +121 -0
- package/src/serve/hub-app/objects.css +1 -0
- package/src/serve/hub-app/orchestrator-line.tsx +104 -0
- package/src/serve/hub-app/orchestrator.css +37 -0
- package/src/serve/hub-app/page-keys.ts +7 -4
- package/src/serve/hub-app/page-reload.ts +111 -0
- package/src/serve/hub-app/pages-frames.tsx +2 -1
- package/src/serve/hub-app/pages-svc.ts +8 -3
- package/src/serve/hub-app/palette-st.ts +7 -2
- package/src/serve/hub-app/pane-boundary.tsx +13 -0
- package/src/serve/hub-app/pane-errors.ts +2 -1
- package/src/serve/hub-app/pano.css +20 -0
- package/src/serve/hub-app/plan-view.tsx +1 -1
- package/src/serve/hub-app/planned-st.ts +30 -26
- package/src/serve/hub-app/planned-view.tsx +16 -9
- package/src/serve/hub-app/polled.ts +201 -0
- package/src/serve/hub-app/presence-st.ts +110 -0
- package/src/serve/hub-app/project-list.css +98 -55
- package/src/serve/hub-app/project-list.tsx +136 -149
- package/src/serve/hub-app/projects-svc.ts +109 -57
- package/src/serve/hub-app/push-sign.tsx +15 -0
- package/src/serve/hub-app/push-svc.ts +273 -0
- package/src/serve/hub-app/quiet-st.ts +59 -0
- package/src/serve/hub-app/rail-fly.tsx +95 -0
- package/src/serve/hub-app/reach.ts +16 -0
- package/src/serve/hub-app/recordings-st.ts +169 -9
- package/src/serve/hub-app/recordings-take.ts +58 -0
- package/src/serve/hub-app/recordings-view.tsx +42 -35
- package/src/serve/hub-app/recordings.css +1 -1
- package/src/serve/hub-app/reflections-page.tsx +16 -4
- package/src/serve/hub-app/releases/releases-page.tsx +52 -19
- package/src/serve/hub-app/releases/releases-st.ts +39 -26
- package/src/serve/hub-app/releases.css +4 -0
- package/src/serve/hub-app/repo-sections.ts +21 -10
- package/src/serve/hub-app/repo-st.ts +36 -9
- package/src/serve/hub-app/review/advisor-bar.tsx +40 -0
- package/src/serve/hub-app/review/attach-st.ts +195 -0
- package/src/serve/hub-app/review/attach-view.tsx +260 -0
- package/src/serve/hub-app/review/clip-st.ts +1 -1
- package/src/serve/hub-app/review/cta.tsx +11 -0
- package/src/serve/hub-app/review/diff-view.tsx +37 -35
- package/src/serve/hub-app/review/doc-body.tsx +109 -0
- package/src/serve/hub-app/review/dock.tsx +36 -22
- package/src/serve/hub-app/review/draft-body.tsx +235 -0
- package/src/serve/hub-app/review/faces.tsx +26 -0
- package/src/serve/hub-app/review/group-block.tsx +75 -45
- package/src/serve/hub-app/review/heard-line.tsx +31 -0
- package/src/serve/hub-app/review/instructions-view.tsx +57 -32
- package/src/serve/hub-app/review/item-verdict.tsx +99 -26
- package/src/serve/hub-app/review/kind-states.tsx +148 -76
- package/src/serve/hub-app/review/kind-view.tsx +22 -7
- package/src/serve/hub-app/review/kit.tsx +4 -28
- package/src/serve/hub-app/review/lane-bar.tsx +4 -4
- package/src/serve/hub-app/review/lightbox.tsx +16 -0
- package/src/serve/hub-app/review/line-window.ts +149 -0
- package/src/serve/hub-app/review/live-bar-st.ts +145 -0
- package/src/serve/hub-app/review/live-bar.tsx +126 -0
- package/src/serve/hub-app/review/live-view.tsx +104 -0
- package/src/serve/hub-app/review/mention-st.ts +85 -0
- package/src/serve/hub-app/review/mesh-view.tsx +9 -0
- package/src/serve/hub-app/review/object-panel.tsx +35 -17
- package/src/serve/hub-app/review/pano-gl.ts +145 -0
- package/src/serve/hub-app/review/pano-view.tsx +192 -0
- package/src/serve/hub-app/review/phone-top.tsx +16 -0
- package/src/serve/hub-app/review/pictures-st.ts +38 -0
- package/src/serve/hub-app/review/question-views.tsx +107 -105
- package/src/serve/hub-app/review/review-board.tsx +1 -1
- package/src/serve/hub-app/review/review-cells.tsx +169 -111
- package/src/serve/hub-app/review/review-host.ts +69 -0
- package/src/serve/hub-app/review/review-kit.ts +34 -19
- package/src/serve/hub-app/review/review-list.tsx +123 -20
- package/src/serve/hub-app/review/review-page.tsx +7 -18
- package/src/serve/hub-app/review/review-st.ts +241 -138
- package/src/serve/hub-app/review/review-thread.tsx +463 -150
- package/src/serve/hub-app/review/review-views.tsx +540 -449
- package/src/serve/hub-app/review/scene-view.tsx +26 -0
- package/src/serve/hub-app/review/secret-facts.ts +26 -0
- package/src/serve/hub-app/review/space3d.tsx +114 -0
- package/src/serve/hub-app/review/splat-view.tsx +9 -0
- package/src/serve/hub-app/review/superseded-runs.ts +76 -0
- package/src/serve/hub-app/review/thread-close.tsx +17 -7
- package/src/serve/hub-app/review/thread-control-st.ts +2 -1
- package/src/serve/hub-app/review/thread-st.ts +528 -158
- package/src/serve/hub-app/review/thread-views.ts +71 -0
- package/src/serve/hub-app/review/{trailer-card.tsx → trailer-body.tsx} +34 -34
- package/src/serve/hub-app/review/trailer-page.tsx +23 -25
- package/src/serve/hub-app/review/trailer-st.ts +38 -38
- package/src/serve/hub-app/review/trailer-timeline.tsx +23 -19
- package/src/serve/hub-app/review/trailer-voices.tsx +3 -2
- package/src/serve/hub-app/review.css +259 -147
- package/src/serve/hub-app/search-st.ts +138 -0
- package/src/serve/hub-app/search-view.tsx +92 -0
- package/src/serve/hub-app/section-head.tsx +5 -4
- package/src/serve/hub-app/shell-rows.ts +126 -0
- package/src/serve/hub-app/site/site-st.ts +18 -23
- package/src/serve/hub-app/social/comms-page.tsx +14 -11
- package/src/serve/hub-app/social/group-editor.tsx +44 -0
- package/src/serve/hub-app/social/kit.tsx +7 -46
- package/src/serve/hub-app/social/next-release.tsx +2 -2
- package/src/serve/hub-app/social/post-card.tsx +16 -52
- package/src/serve/hub-app/social/problems.tsx +5 -4
- package/src/serve/hub-app/social/social-page.tsx +3 -3
- package/src/serve/hub-app/social/social-st.ts +31 -84
- package/src/serve/hub-app/social/stage-popup.tsx +6 -6
- package/src/serve/hub-app/social/stage-st.ts +9 -9
- package/src/serve/hub-app/social.css +0 -8
- package/src/serve/hub-app/space-st.ts +38 -48
- package/src/serve/hub-app/space-view.tsx +6 -6
- package/src/serve/hub-app/stores/stores-page.tsx +4 -4
- package/src/serve/hub-app/stores/stores-st.ts +19 -23
- package/src/serve/hub-app/terminal-input.ts +12 -0
- package/src/serve/hub-app/terminal-panel.tsx +40 -0
- package/src/serve/hub-app/terminal-st.ts +416 -0
- package/src/serve/hub-app/terminal.css +15 -0
- package/src/serve/hub-app/tests-svc.ts +3 -2
- package/src/serve/hub-app/theme-st.ts +1 -9
- package/src/serve/hub-app/thread-row.tsx +52 -17
- package/src/serve/hub-app/time-ago.tsx +39 -16
- package/src/serve/hub-app/time-st.ts +43 -27
- package/src/serve/hub-app/time-view.tsx +3 -3
- package/src/serve/hub-app/tree-build.ts +2 -2
- package/src/serve/hub-app/tree-row.tsx +43 -18
- package/src/serve/hub-app/tree-svc.ts +1 -1
- package/src/serve/hub-app/urls-svc.ts +6 -5
- package/src/serve/hub-app/vault-st.ts +32 -27
- package/src/serve/hub-app/vault-view.tsx +53 -2
- package/src/serve/hub-app/vault.css +2 -0
- package/src/serve/hub-app/veille/veille-page.tsx +4 -4
- package/src/serve/hub-app/veille/veille-st.ts +56 -49
- package/src/serve/hub-app/view-layout.css +90 -0
- package/src/serve/hub-app/waiting-svc.ts +2 -1
- package/src/serve/hub-app/wiki-st.ts +3 -2
- package/src/serve/hub-app/wikis-view.tsx +18 -15
- package/src/serve/hub-app/words.tsx +15 -0
- package/src/serve/hub-collections.ts +105 -0
- package/src/serve/hub-runtime.ts +67 -89
- package/src/serve/live-hop.ts +102 -0
- package/src/serve/other-repos.ts +1 -1
- package/src/serve/project-gutter-route.ts +53 -40
- package/src/serve/read-thread.ts +76 -0
- package/src/serve/read-worker.ts +53 -0
- package/src/serve/run-serve.ts +11 -7
- package/src/serve/secret-gate.ts +3 -3
- package/src/serve/serve-hub.ts +103 -34
- package/src/serve/terminal-guard.ts +50 -0
- package/src/serve/terminal-route.ts +176 -0
- package/src/shipkit.ts +8 -8
- package/src/shot/client.ts +32 -16
- package/src/shot/dom-clip.ts +30 -5
- package/src/shot/film-box.ts +23 -8
- package/src/shot/serve-shot.ts +16 -5
- package/src/shot/shooter.ts +72 -24
- package/src/shot/shot-ask.ts +17 -6
- package/src/shot/shot-guard.ts +53 -0
- package/src/shot/shot-theme.ts +70 -0
- package/src/shot/still-file.ts +60 -0
- package/src/site/desk.ts +4 -3
- package/src/social/compose.ts +13 -7
- package/src/social/cover.ts +4 -3
- package/src/social/desk-index.ts +2 -2
- package/src/social/draft-doc.ts +88 -0
- package/src/social/draft-versions.ts +80 -0
- package/src/social/drafts.ts +22 -4
- package/src/social/fit.ts +4 -3
- package/src/social/house.ts +1 -1
- package/src/social/import-drafts.ts +1 -1
- package/src/social/kinds.ts +1 -1
- package/src/social/load.ts +21 -13
- package/src/social/media-facts.ts +1 -19
- package/src/social/media-kind.ts +2 -2
- package/src/social/media-limit.ts +3 -18
- package/src/social/no-account.ts +38 -0
- package/src/social/post-sources.ts +4 -4
- package/src/social/post-text.ts +33 -13
- package/src/social/posts.ts +73 -18
- package/src/social/presence.ts +10 -8
- package/src/social/release-stage.ts +22 -22
- package/src/social/routes.ts +12 -30
- package/src/social/stage.ts +3 -3
- package/src/social/stats.ts +3 -4
- package/src/social/strip.ts +4 -6
- package/src/social/text.ts +2 -1
- package/src/social/{card-drafts.ts → thread-drafts.ts} +3 -3
- package/src/social/unit.ts +12 -3
- package/src/social/writes.ts +0 -6
- package/src/start-repo.ts +33 -13
- package/src/stores/desk.ts +1 -1
- package/src/suite/core-counters.ts +31 -3
- package/src/suite/judge-suites.ts +69 -47
- package/src/suite/select.ts +1 -27
- package/src/suite/suite-cli.ts +18 -8
- package/src/suite/suite-cpu-preload.ts +10 -6
- package/src/trace/tracer.ts +4 -5
- package/src/trailer/build.ts +30 -15
- package/src/trailer/ffmpeg.ts +90 -31
- package/src/trailer/fonts.ts +5 -6
- package/src/trailer/footage.ts +9 -3
- package/src/trailer/grammar.ts +2 -1
- package/src/trailer/graph.ts +12 -10
- package/src/trailer/load-unit.ts +1 -1
- package/src/trailer/passage.ts +4 -3
- package/src/trailer/prune.ts +4 -4
- package/src/trailer/score/sound.ts +3 -3
- package/src/trailer/shot-plan.ts +5 -5
- package/src/trailer/shot-state.ts +25 -31
- package/src/trailer/sound/eleven.ts +2 -1
- package/src/trailer/sound/gen.ts +3 -3
- package/src/trailer/sound/run.ts +76 -64
- package/src/trailer/sound/takes.ts +0 -3
- package/src/trailer/take-fault.ts +41 -0
- package/src/trailer/titles.ts +17 -13
- package/src/trailer/url.ts +1 -1
- package/src/trailer/vertical-draw.ts +7 -7
- package/src/trailer/vertical.ts +3 -3
- package/src/trailer/vocab.ts +3 -4
- package/src/ts/config.ts +60 -24
- package/src/ts/cycles.ts +3 -1
- package/src/ts/imports.ts +17 -3
- package/src/ts/rename.ts +6 -7
- package/src/ts/source-graph.ts +15 -9
- package/src/ts/workspaces.ts +26 -0
- package/src/tui/build-steps-panel.ts +3 -3
- package/src/tui/checks-panel.ts +2 -2
- package/src/urls/frame.ts +3 -3
- package/src/urls/routes.ts +1 -1
- package/src/urls/rows.ts +1 -1
- package/src/vault/house-keys.ts +1 -1
- package/src/vault/vault-audit.ts +2 -3
- package/src/vault/vault-config.ts +6 -2
- package/src/vault/vault-restore.ts +3 -9
- package/src/vault/vault-serve.ts +47 -11
- package/src/vault/vault-snapshot.ts +5 -14
- package/src/veille/desk.ts +2 -2
- package/src/veille/routes.ts +1 -1
- package/src/view3d/cam.ts +101 -0
- package/src/view3d/lib.ts +69 -0
- package/src/view3d/loop.ts +39 -0
- package/src/view3d/scene-cache.ts +62 -0
- package/src/view3d/viewer.ts +480 -0
- package/src/wiki/agent-paths.ts +55 -0
- package/src/wiki/run-wiki.ts +4 -1
- package/src/wiki/serve-graph.ts +2 -3
- package/src/core/run-fix.ts +0 -120
- package/src/home/hmr-keep.ts +0 -134
- package/src/serve/hub-app/review/draft-card.tsx +0 -163
- package/src/serve/hub-app/review/note-place.ts +0 -31
- /package/src/{serve → http}/door-names.ts +0 -0
- /package/src/{serve → http}/hub-port.ts +0 -0
package/src/review/store.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// media, and `thread/`, one file per message, never rewritten. An item is built in a dot folder and renamed, every file
|
|
3
3
|
// written beside its place and renamed, so no reader sees half of one. The format is a project's own store's, verbatim. A folder of
|
|
4
4
|
// the old shape (request.json, feedback.json, a message with `seen`) fails loud. With the switch cards-in-db on, the
|
|
5
|
-
// heads and the messages are rows of the daemon's file instead (
|
|
5
|
+
// heads and the messages are rows of the daemon's file instead (item-rows.ts), through the same functions: `io` picks
|
|
6
6
|
// the backend, every function above it is one code path
|
|
7
|
+
import { ownerCursorAt } from './owner-read.ts'
|
|
7
8
|
import * as fs from 'node:fs'
|
|
8
9
|
import { existsSync, readdirSync, readFileSync, statSync, watch } from 'node:fs'
|
|
9
10
|
import { basename, dirname, extname, join, resolve } from 'node:path'
|
|
@@ -14,9 +15,9 @@ import { probe, sizeOf, stillAt } from './media.ts'
|
|
|
14
15
|
import { factsOf } from '../media-store/content.ts'
|
|
15
16
|
import { anyWebp, exactWebp, webpable } from '../media-store/webp.ts'
|
|
16
17
|
import { mediaDb, tryWrite } from '../media-store/db.ts'
|
|
17
|
-
import {
|
|
18
|
-
import { rowsAll, rowsIO, rowsStamp, type
|
|
19
|
-
import { moveFolder, repoIdOf, spoolOf } from './
|
|
18
|
+
import { threadsInDb, threadsMoving, threadsOn } from '../hq/switch.ts'
|
|
19
|
+
import { rowsAll, rowsIO, rowsStamp, type ItemBackend } from './item-rows.ts'
|
|
20
|
+
import { moveFolder, repoIdOf, spoolOf } from './item-db.ts'
|
|
20
21
|
import { machineDbPath } from '../core/machine-db.ts'
|
|
21
22
|
import { jsonText, revOf } from './rev.ts'
|
|
22
23
|
import { GONE, goneEntryFor } from './gone.ts'
|
|
@@ -25,9 +26,9 @@ import {
|
|
|
25
26
|
ANSWER_KINDS,
|
|
26
27
|
type AnswerKind,
|
|
27
28
|
type MessageAsk,
|
|
29
|
+
itemWithdrawOf,
|
|
28
30
|
ownAddressOf,
|
|
29
31
|
partyOf,
|
|
30
|
-
proposeOpen,
|
|
31
32
|
AGENT_RE,
|
|
32
33
|
allowed,
|
|
33
34
|
FILE_RE,
|
|
@@ -39,6 +40,12 @@ import {
|
|
|
39
40
|
isMarkItem,
|
|
40
41
|
itemProblems,
|
|
41
42
|
MESSAGE_FILE_RE,
|
|
43
|
+
MESSAGE_FILES_MAX,
|
|
44
|
+
attachFile,
|
|
45
|
+
cleanFileName,
|
|
46
|
+
isThreadMedia,
|
|
47
|
+
mimeOf,
|
|
48
|
+
type MessageFile,
|
|
42
49
|
MESSAGE_RE,
|
|
43
50
|
messageIdOf,
|
|
44
51
|
messageProblems,
|
|
@@ -58,20 +65,24 @@ import {
|
|
|
58
65
|
updatesOf,
|
|
59
66
|
type UpdateState,
|
|
60
67
|
type GalleryTile,
|
|
61
|
-
type
|
|
68
|
+
type ItemChangelog,
|
|
62
69
|
type Item,
|
|
63
70
|
type Message,
|
|
71
|
+
type Mention,
|
|
72
|
+
mayReadNamed,
|
|
64
73
|
type Op,
|
|
65
74
|
type Origin,
|
|
66
|
-
type Party,
|
|
67
75
|
type Rect,
|
|
68
76
|
type ReviewClip,
|
|
69
77
|
type ReviewFiles,
|
|
70
78
|
type ReviewItem,
|
|
71
79
|
type ReviewMark,
|
|
80
|
+
type ReviewScene,
|
|
72
81
|
type ReviewView,
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
panoRefusal,
|
|
83
|
+
SPACE_EXT,
|
|
84
|
+
type ItemTrailer,
|
|
85
|
+
type ItemDraft,
|
|
75
86
|
type Spec,
|
|
76
87
|
type Subject,
|
|
77
88
|
type Verdict,
|
|
@@ -87,15 +98,24 @@ import {
|
|
|
87
98
|
type ProposeField,
|
|
88
99
|
type StoredState,
|
|
89
100
|
type AskHead,
|
|
101
|
+
docProblem,
|
|
102
|
+
type ItemDoc,
|
|
90
103
|
} from './model.ts'
|
|
91
104
|
import { kindOfValue, valueKindOf } from './kinds.ts'
|
|
92
|
-
import { askOpen, linesOf } from './answer-kinds.ts'
|
|
93
|
-
import {
|
|
105
|
+
import { askOpen, linesOf, tickText } from './answer-kinds.ts'
|
|
106
|
+
import { isObject, objectOpen } from './supersede.ts'
|
|
107
|
+
import { asksVerdict } from './verdict-items.ts'
|
|
94
108
|
import { SECRET_NAME } from '../secrets/name.ts'
|
|
95
109
|
import { beatRole, roleOf } from './role.ts'
|
|
96
|
-
import { chainOf, coveringHead, followedIds, isFollowed, threadOfAddress } from './threads.ts'
|
|
110
|
+
import { chainOf, coveringHead, followedIds, isFollowed, threadIdOf, threadOfAddress } from './threads.ts'
|
|
97
111
|
import { liveWatchers } from './watchers.ts'
|
|
112
|
+
import { liveUrlRefusal, type ViewLive } from './live-view.ts'
|
|
113
|
+
import { STILLS_LABEL } from './kind-still.ts'
|
|
98
114
|
import { noteSession } from '../agent-time/registry.ts'
|
|
115
|
+
import { modelWatch } from './model-moved.ts'
|
|
116
|
+
import { isLockFile, withLease, withLeaseSync } from '../core/locked-write.ts'
|
|
117
|
+
import { wroteOnLoop } from '../core/on-loop.ts'
|
|
118
|
+
import { atomicWrite } from '../core/atomic-write.ts'
|
|
99
119
|
|
|
100
120
|
/** the store of a repo */
|
|
101
121
|
export const storeDir = (root: string): string => join(root, LAYOUT.review)
|
|
@@ -115,27 +135,26 @@ let wrote = 0
|
|
|
115
135
|
const renameSync = (a: string, b: string): void => (fs.renameSync(a, b), touched(a), touched(b))
|
|
116
136
|
const rmSync = (p: string, o?: fs.RmOptions): void => (fs.rmSync(p, o), touched(p))
|
|
117
137
|
const copyFileSync = (a: string, b: string): void => (fs.copyFileSync(a, b), touched(b))
|
|
118
|
-
const writeFileSync = (p: string, d: string): void => (fs.writeFileSync(p, d), touched(p))
|
|
119
138
|
const mkdirSync = (p: string, o?: fs.MakeDirectoryOptions): void => (fs.mkdirSync(p, o), touched(p))
|
|
120
139
|
|
|
121
140
|
export { jsonText, revOf }
|
|
122
141
|
|
|
142
|
+
/** the bytes jsonText gives, so the rev of a file is the rev of its value */
|
|
123
143
|
function writeJson(file: string, v: unknown): void {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
renameSync(tmp, file)
|
|
144
|
+
atomicWrite(file, jsonText(v))
|
|
145
|
+
touched(file)
|
|
127
146
|
}
|
|
128
147
|
|
|
129
148
|
/** where the store's operations read and write: the rows of the local copy while the switch cards-in-db is on, else
|
|
130
149
|
* the files. Picked once an operation, so one operation never reads one backend and writes the other */
|
|
131
|
-
const io = (dir: string):
|
|
150
|
+
const io = (dir: string): ItemBackend => (threadsInDb() ? rowsIO(dir) : filesIO(dir))
|
|
132
151
|
|
|
133
|
-
/** the store holds this
|
|
134
|
-
export const
|
|
152
|
+
/** the store holds this item's head, or this message of its thread: what the machine has, never what it sent */
|
|
153
|
+
export const holdsItem = (dir: string, id: string): boolean => io(dir).has(id)
|
|
135
154
|
export const holdsMessage = (dir: string, id: string, mid: string): boolean => io(dir).hasMessage(id, mid)
|
|
136
155
|
|
|
137
|
-
/** the store's files, as they always were: one folder
|
|
138
|
-
export function filesIO(dir: string):
|
|
156
|
+
/** the store's files, as they always were: one folder an item */
|
|
157
|
+
export function filesIO(dir: string): ItemBackend {
|
|
139
158
|
const folder = (id: string): string => join(dir, id)
|
|
140
159
|
return {
|
|
141
160
|
rows: false,
|
|
@@ -160,25 +179,31 @@ export function filesIO(dir: string): CardBackend {
|
|
|
160
179
|
hasMessage: (id, mid) => existsSync(join(dir, id, 'thread', `${mid}.json`)),
|
|
161
180
|
raw: (id) => readRawFile(dir, id),
|
|
162
181
|
create: (id, tmp, head) => {
|
|
182
|
+
wroteOnLoop()
|
|
163
183
|
writeJson(join(tmp, 'item.json'), head)
|
|
164
|
-
//
|
|
184
|
+
// an item begun while the rows were the store: its folder comes from the spool
|
|
165
185
|
moveFolder(tmp, folder(id))
|
|
166
186
|
touched(tmp)
|
|
167
187
|
touched(folder(id))
|
|
168
188
|
},
|
|
169
189
|
write: (id, head, at) => {
|
|
190
|
+
wroteOnLoop()
|
|
170
191
|
const f = join(dir, id, 'item.json')
|
|
171
192
|
writeJson(f, head)
|
|
172
193
|
if (at !== undefined) fs.utimesSync(f, new Date(at), new Date(at))
|
|
173
194
|
},
|
|
174
195
|
append: (id, m) => {
|
|
196
|
+
wroteOnLoop()
|
|
175
197
|
const t = join(dir, id, 'thread')
|
|
176
198
|
if (!existsSync(t)) mkdirSync(t)
|
|
177
199
|
writeJson(join(t, `${m.id}.json`), m)
|
|
178
200
|
},
|
|
179
|
-
lock: (id, fn, waitMs) =>
|
|
201
|
+
lock: (id, fn, waitMs) => lockedItem(dir, id, fn, waitMs),
|
|
180
202
|
setAside: (id, o) => setAsideFile(dir, id, o),
|
|
181
|
-
keepReplaced: (id, head) =>
|
|
203
|
+
keepReplaced: (id, head) => {
|
|
204
|
+
wroteOnLoop()
|
|
205
|
+
writeJson(join(folder(id), REPLACED), head)
|
|
206
|
+
},
|
|
182
207
|
hasReplaced: (id) => ID_RE.test(id) && existsSync(join(dir, id, REPLACED)),
|
|
183
208
|
stamp: (id) => stampOf(folder(id)),
|
|
184
209
|
folder,
|
|
@@ -192,12 +217,19 @@ export interface ViewInput {
|
|
|
192
217
|
image?: string
|
|
193
218
|
video?: string
|
|
194
219
|
audio?: string
|
|
220
|
+
/** an equirectangular panorama (2:1): one image he looks around in */
|
|
221
|
+
pano?: string
|
|
222
|
+
/** a Gaussian splat (.ply, .spz) or a .glb mesh he moves in, `image` its poster; loaded only in the lightbox */
|
|
223
|
+
splat?: string
|
|
224
|
+
mesh?: string
|
|
195
225
|
before?: string
|
|
196
226
|
after?: string
|
|
197
227
|
/** a list of small images shown as a wrapping grid, each with its label; never the first view */
|
|
198
|
-
gallery?: { file: string; label: string; before?: string; group?: string }[]
|
|
199
|
-
/** a line on this view alone: an option's description on a choice
|
|
228
|
+
gallery?: { file: string; label: string; before?: string; group?: string; view?: string }[]
|
|
229
|
+
/** a line on this view alone: an option's description on a choice version */
|
|
200
230
|
note?: string
|
|
231
|
+
/** a live view: the page the hub frames over `image`, its shot (review/live-view.ts) */
|
|
232
|
+
live?: ViewLive
|
|
201
233
|
}
|
|
202
234
|
|
|
203
235
|
/** the most one side of a version of an object weighs, as json */
|
|
@@ -209,13 +241,16 @@ export interface AddInput {
|
|
|
209
241
|
/** the public line for a post of it (`--post`); the caller runs the repo's guard on it first */
|
|
210
242
|
post?: string
|
|
211
243
|
/** the change its approval adds to next.md (`--changelog`); the caller runs the repo's guard on it first */
|
|
212
|
-
changelog?:
|
|
244
|
+
changelog?: ItemChangelog
|
|
213
245
|
/** what is judged; a plain shot by default */
|
|
214
246
|
subject?: Subject
|
|
215
247
|
topic?: string
|
|
216
248
|
image?: string
|
|
217
249
|
video?: string
|
|
218
250
|
audio?: string
|
|
251
|
+
pano?: string
|
|
252
|
+
splat?: string
|
|
253
|
+
mesh?: string
|
|
219
254
|
before?: string
|
|
220
255
|
after?: string
|
|
221
256
|
commit?: string
|
|
@@ -224,7 +259,7 @@ export interface AddInput {
|
|
|
224
259
|
/** written by the machine (a check run, the reflections queue): no lane and no session, so nobody holds it */
|
|
225
260
|
machine?: true
|
|
226
261
|
supersedes?: string
|
|
227
|
-
/** the raised items (a report, his note) this
|
|
262
|
+
/** the raised items (a report, his note) this version answers, by id */
|
|
228
263
|
answers?: string[]
|
|
229
264
|
/** its subject's address when the agent names it (`--on`): one thread per address */
|
|
230
265
|
on?: string
|
|
@@ -232,7 +267,7 @@ export interface AddInput {
|
|
|
232
267
|
about?: string[]
|
|
233
268
|
/** what a new version of an approved look keeps of it: required then */
|
|
234
269
|
keeps?: string
|
|
235
|
-
/** another subject on purpose, next to an active
|
|
270
|
+
/** another subject on purpose, next to an active version: needs `why` */
|
|
236
271
|
fresh?: boolean
|
|
237
272
|
why?: string
|
|
238
273
|
/** the first view's label, and the other views of the same subject */
|
|
@@ -242,7 +277,7 @@ export interface AddInput {
|
|
|
242
277
|
marks?: ReviewMark[][]
|
|
243
278
|
/** the shots used the review light over a dark place */
|
|
244
279
|
light?: 'review'
|
|
245
|
-
/** a draft
|
|
280
|
+
/** a draft version on a live shot: its image a live frame, no verdict until it is ready */
|
|
246
281
|
wip?: { live: string }
|
|
247
282
|
/** every view is an option he picks one of */
|
|
248
283
|
choice?: boolean
|
|
@@ -250,18 +285,22 @@ export interface AddInput {
|
|
|
250
285
|
asksVerdict?: true
|
|
251
286
|
/** on a choice: the option the agent suggests, by its label or its letter */
|
|
252
287
|
agentPick?: string
|
|
253
|
-
/** a trailer
|
|
254
|
-
trailer?:
|
|
255
|
-
/** a draft
|
|
256
|
-
draft?:
|
|
257
|
-
/** every picture as given, never a webp: the file itself kept, where the
|
|
288
|
+
/** a trailer version: the cut the hub plays in its body; its one view is the cut's strip */
|
|
289
|
+
trailer?: ItemTrailer
|
|
290
|
+
/** a draft version: the post draft the hub shows in its body, read live; it holds no view */
|
|
291
|
+
draft?: ItemDraft
|
|
292
|
+
/** every picture as given, never a webp: the file itself kept, where the item holds only its webp otherwise */
|
|
258
293
|
keep?: boolean
|
|
259
294
|
/** a thread opened with words on its address (`on`): no media, nothing he judges (openThread) */
|
|
260
295
|
opening?: boolean
|
|
261
296
|
/** a version of an object of a kind (`on`): its two states as the kind read them; it holds no view */
|
|
262
297
|
states?: { before?: StoredState; after: StoredState }
|
|
298
|
+
/** a save of the object in its home (review/doc-save.ts): who saved it; it holds its states */
|
|
299
|
+
saved?: { by: string }
|
|
263
300
|
/** an ask's facts, on the head of its thread `ask:<id>` (asks/ask-store.ts) */
|
|
264
301
|
ask?: AskHead
|
|
302
|
+
/** a document as the version's subject (`--md`, `--html`); views beside it are allowed */
|
|
303
|
+
doc?: ItemDoc
|
|
265
304
|
now?: Date
|
|
266
305
|
}
|
|
267
306
|
|
|
@@ -274,21 +313,24 @@ interface Loaded {
|
|
|
274
313
|
clip?: { duration: number; fps: number; from: string }
|
|
275
314
|
/** a sound: its length, and the files its waveforms are drawn from (the after's or the one's, then the before's) */
|
|
276
315
|
audio?: { duration: number; from: string; before?: string }
|
|
277
|
-
|
|
316
|
+
scene?: ReviewScene
|
|
317
|
+
/** a splat's or a mesh's 3D file, copied beside its poster as `space.<ext>` */
|
|
318
|
+
space?: string
|
|
319
|
+
tiles?: { path: string; label: string; size: { w: number; h: number }; before?: string; group?: string; view?: string }[]
|
|
278
320
|
/** the webps made of its pictures, by the name of each in place of its source (`<source>.webp`, no such file) */
|
|
279
321
|
webps?: Map<string, Uint8Array>
|
|
280
322
|
}
|
|
281
323
|
|
|
282
|
-
/** the view's pictures as the
|
|
283
|
-
* memory and written where the
|
|
324
|
+
/** the view's pictures as the item keeps them: each png a lossless webp found exact (media-store/webp.ts), made in
|
|
325
|
+
* memory and written where the item is by copyFiles; never with `keep`. The sides of a pair, and a tile and its
|
|
284
326
|
* before, are webps together or stay as given together, so two sides never differ in kind. `always`: a webp whatever
|
|
285
|
-
* the picture holds (a draft's live frame, whose name its
|
|
327
|
+
* the picture holds (a draft's live frame, whose name its item made a webp) */
|
|
286
328
|
async function asWebp(v: Loaded, keep: boolean, always: boolean): Promise<Loaded> {
|
|
287
329
|
if (keep || v.clip || v.audio) return v
|
|
288
330
|
const pics = [...v.sources.map(([, p]) => p), ...(v.tiles ?? []).flatMap((t) => [t.path, ...(t.before ? [t.before] : [])])]
|
|
289
331
|
if (!pics.some(webpable) && !always) return v
|
|
290
332
|
const webps = new Map<string, Uint8Array>()
|
|
291
|
-
/** the paths of a group as the
|
|
333
|
+
/** the paths of a group as the item keeps them: every one a webp, or every one as given */
|
|
292
334
|
const group = async (paths: readonly string[]): Promise<string[]> => {
|
|
293
335
|
const made = await Promise.all(paths.map(async (p) => (always ? { bytes: await anyWebp(p) } : await exactWebp(p))))
|
|
294
336
|
if (made.some((m) => 'keep' in m)) return [...paths]
|
|
@@ -315,8 +357,8 @@ async function loadView(v: ViewInput, which: string, o: { keep?: boolean; always
|
|
|
315
357
|
/** a view's files checked and sized, as given */
|
|
316
358
|
async function checkView(v: ViewInput, which: string): Promise<Loaded> {
|
|
317
359
|
if (v.gallery !== undefined) {
|
|
318
|
-
if (v.image !== undefined || v.video !== undefined || v.audio !== undefined || v.before !== undefined || v.after !== undefined)
|
|
319
|
-
throw new Error(`${which}: a gallery is a list of images, no --image, --video or pair beside it`)
|
|
360
|
+
if (v.image !== undefined || v.video !== undefined || v.audio !== undefined || v.pano !== undefined || v.splat !== undefined || v.mesh !== undefined || v.before !== undefined || v.after !== undefined)
|
|
361
|
+
throw new Error(`${which}: a gallery is a list of images, no --image, --video, --pano, --splat, --mesh or pair beside it`)
|
|
320
362
|
if (v.gallery.length === 0) throw new Error(`${which}: a gallery needs at least one image`)
|
|
321
363
|
const tiles = await Promise.all(
|
|
322
364
|
v.gallery.map(async (t) => {
|
|
@@ -328,11 +370,13 @@ async function checkView(v: ViewInput, which: string): Promise<Loaded> {
|
|
|
328
370
|
}
|
|
329
371
|
const path = image(t.file)
|
|
330
372
|
const group = t.group?.trim()
|
|
331
|
-
return { path, label: t.label.trim(), size: await sizeOf(path), ...(t.before !== undefined ? { before: image(t.before) } : {}), ...(group ? { group } : {}) }
|
|
373
|
+
return { path, label: t.label.trim(), size: await sizeOf(path), ...(t.before !== undefined ? { before: image(t.before) } : {}), ...(group ? { group } : {}), ...(t.view !== undefined ? { view: t.view } : {}) }
|
|
332
374
|
}),
|
|
333
375
|
)
|
|
334
376
|
return { label: v.label.trim(), sources: [], size: tiles[0]?.size ?? { w: 0, h: 0 }, tiles }
|
|
335
377
|
}
|
|
378
|
+
if (v.pano !== undefined) return checkPano(v, which)
|
|
379
|
+
if (v.splat !== undefined || v.mesh !== undefined) return checkSpace(v, which)
|
|
336
380
|
if ([v.image, v.video, v.audio].filter((x) => x !== undefined).length > 1) throw new Error(`${which}: give one of an image, a clip or a sound`)
|
|
337
381
|
const one = v.image ?? v.video ?? v.audio
|
|
338
382
|
const pair = v.before !== undefined || v.after !== undefined
|
|
@@ -382,7 +426,36 @@ async function checkView(v: ViewInput, which: string): Promise<Loaded> {
|
|
|
382
426
|
return { label: v.label.trim(), sources, size: { w: b.w, h: b.h }, clip: { duration: b.duration, fps: b.fps, from: main[1] } }
|
|
383
427
|
}
|
|
384
428
|
|
|
385
|
-
/**
|
|
429
|
+
/** a panorama's one image, checked 2:1: a view whose files are an image's, drawn by the hub's scene viewer */
|
|
430
|
+
async function checkPano(v: ViewInput, which: string): Promise<Loaded> {
|
|
431
|
+
if ([v.image, v.video, v.audio, v.before, v.after].some((x) => x !== undefined)) throw new Error(`${which}: --pano is the view's one image, no --image, --video, --audio or pair beside it`)
|
|
432
|
+
const path = resolve(v.pano ?? '')
|
|
433
|
+
if (!existsSync(path)) throw new Error(`${path}: no such file`)
|
|
434
|
+
if (!IMAGE_EXT.test(extname(path).toLowerCase())) throw new Error(`--pano ${path}: a png, jpg or webp`)
|
|
435
|
+
const size = await sizeOf(path)
|
|
436
|
+
const why = panoRefusal(size)
|
|
437
|
+
if (why) throw new Error(`--pano ${path}: ${why}`)
|
|
438
|
+
return { label: v.label.trim(), sources: [['image', path]], size, scene: { kind: 'pano' } }
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** a splat or a mesh: its 3D file of the kind's own type, and its poster, the view's one image (the cli shoots one when
|
|
442
|
+
* none is given). The file is never read here: 66 to 79 MB, the lightbox loads it */
|
|
443
|
+
async function checkSpace(v: ViewInput, which: string): Promise<Loaded> {
|
|
444
|
+
const kind = v.splat !== undefined ? 'splat' : 'mesh'
|
|
445
|
+
const file = v.splat ?? v.mesh ?? ''
|
|
446
|
+
if (v.splat !== undefined && v.mesh !== undefined) throw new Error(`${which}: one 3D file a view, --splat or --mesh`)
|
|
447
|
+
if ([v.video, v.audio, v.pano, v.before, v.after].some((x) => x !== undefined)) throw new Error(`${which}: --${kind} is the view's 3D file and --image its poster, no --video, --audio, --pano or pair beside it`)
|
|
448
|
+
const path = resolve(file)
|
|
449
|
+
if (!existsSync(path)) throw new Error(`${path}: no such file`)
|
|
450
|
+
if (!SPACE_EXT[kind].test(path)) throw new Error(`--${kind} ${path}: ${kind === 'splat' ? 'a Gaussian splat, .ply or .spz' : 'a .glb mesh'}`)
|
|
451
|
+
if (v.image === undefined) throw new Error(`${which}: --${kind} needs its poster, --image <a.png> (sk thread post shoots one when none is given)`)
|
|
452
|
+
const poster = resolve(v.image)
|
|
453
|
+
if (!existsSync(poster)) throw new Error(`${poster}: no such file`)
|
|
454
|
+
if (!IMAGE_EXT.test(extname(poster).toLowerCase())) throw new Error(`--image ${poster}: the poster of a ${kind}, a png, jpg or webp`)
|
|
455
|
+
return { label: v.label.trim(), sources: [['image', poster]], size: await sizeOf(poster), scene: { kind, file: '' }, space: path }
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/** what an item records of a clip: its size, its length and its rate, to the millisecond */
|
|
386
459
|
function clipInfo(file: string): { w: number; h: number; duration: number; fps: number } {
|
|
387
460
|
let p: ReturnType<typeof probe>
|
|
388
461
|
try {
|
|
@@ -421,18 +494,32 @@ async function writeWaves(v: Loaded, n: number, folder: string): Promise<void> {
|
|
|
421
494
|
}
|
|
422
495
|
|
|
423
496
|
const prefix = (n: number): string => (n > 0 ? `v${n}-` : '')
|
|
497
|
+
/** a scene's 3D file in the folder (model.ts SPACE_RE) */
|
|
498
|
+
const spaceName = (n: number, path: string): string => `${prefix(n)}space${extname(path).toLowerCase()}`
|
|
424
499
|
|
|
425
500
|
/** the file name of tile `k` of gallery view `n` */
|
|
426
501
|
const tileName = (n: number, k: number, path: string, side = ''): string => `v${n}-g${k}${side}${extname(path).toLowerCase()}`
|
|
427
502
|
|
|
503
|
+
/** a live view's page beside its shot: an image alone, its url past the wall the cli holds (live-view.ts) */
|
|
504
|
+
function liveOf(v: ViewInput, which: string): { live: ViewLive } | Record<string, never> {
|
|
505
|
+
if (v.live === undefined) return {}
|
|
506
|
+
if (v.image === undefined || isClipFile(v.image) || [v.video, v.audio, v.before, v.after, v.gallery].some((x) => x !== undefined)) throw new Error(`${which}: a live view keeps one image, its shot`)
|
|
507
|
+
const why = liveUrlRefusal(v.live.url, [])
|
|
508
|
+
if (why) throw new Error(`${which}: ${why}`)
|
|
509
|
+
if (Number.isNaN(Date.parse(v.live.at))) throw new Error(`${which}: a live view says when its shot was taken`)
|
|
510
|
+
return { live: { url: v.live.url, at: v.live.at } }
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const withLive = (v: ReviewView, l: { live?: ViewLive } | undefined): ReviewView => (l?.live && !isGallery(v) ? { ...v, live: l.live } : v)
|
|
514
|
+
|
|
428
515
|
function viewOf(v: Loaded, n: number, marks: readonly ReviewMark[] = [], note?: string, message?: true): ReviewView {
|
|
429
516
|
if (v.tiles)
|
|
430
517
|
return {
|
|
431
518
|
label: v.label,
|
|
432
|
-
gallery: v.tiles.map((t, k): GalleryTile => ({ file: tileName(n, k, t.path), label: t.label, size: t.size, ...(t.before ? { before: tileName(n, k, t.before, '-before') } : {}), ...(t.group ? { group: t.group } : {}) })),
|
|
519
|
+
gallery: v.tiles.map((t, k): GalleryTile => ({ file: tileName(n, k, t.path), label: t.label, size: t.size, ...(t.before ? { before: tileName(n, k, t.before, '-before') } : {}), ...(t.group ? { group: t.group } : {}), ...(t.view ? { view: t.view } : {}) })),
|
|
433
520
|
}
|
|
434
521
|
const audio = v.audio ? { audio: { duration: v.audio.duration, wave: `${prefix(n)}wave.png`, ...(v.audio.before ? { waveBefore: `${prefix(n)}before-wave.png` } : {}) } } : {}
|
|
435
|
-
return { label: v.label, files: filesOf(v, n), size: v.size, ...clipOf(v, n), ...audio, ...(marks.length > 0 ? { marks: [...marks] } : {}), ...(note?.trim() ? { note: note.trim() } : {}), ...(message ? { message } : {}) }
|
|
522
|
+
return { label: v.label, files: filesOf(v, n), size: v.size, ...clipOf(v, n), ...audio, ...(v.scene ? { scene: v.space && v.scene.kind !== 'pano' ? { kind: v.scene.kind, file: spaceName(n, v.space) } : v.scene } : {}), ...(marks.length > 0 ? { marks: [...marks] } : {}), ...(note?.trim() ? { note: note.trim() } : {}), ...(message ? { message } : {}) }
|
|
436
523
|
}
|
|
437
524
|
|
|
438
525
|
/** the file names of view `n` in the folder: `image.png` on the first, `v2-before.png` on a later one */
|
|
@@ -468,17 +555,17 @@ function coveredText(c: { head: ReviewItem; by: 'subject' | 'near' | 'title' }):
|
|
|
468
555
|
* or it names none (the older guard decides) */
|
|
469
556
|
export function threadLink(
|
|
470
557
|
dir: string,
|
|
471
|
-
|
|
558
|
+
item: Pick<Item, 'subject' | 'on' | 'trailer'>,
|
|
472
559
|
given: { supersedes?: string; answers: readonly string[] },
|
|
473
560
|
spec: Spec = specOf(dir),
|
|
474
561
|
): { own: string | null; thread: string | null; supersedes?: string; answers: string[] } {
|
|
475
|
-
const own = ownAddressOf({ ...
|
|
562
|
+
const own = ownAddressOf({ ...item, origin: { by: 'agent' } } as Item, spec)
|
|
476
563
|
const t = own === null ? null : threadOfAddress(own, readAll(dir).items, spec)
|
|
477
564
|
if (!t) return { own, thread: null, ...given, answers: [...given.answers] }
|
|
478
565
|
const head = t.head.item
|
|
479
566
|
const want = head.origin.by === 'agent' ? head.id : undefined
|
|
480
567
|
if (given.supersedes !== undefined && given.supersedes !== want)
|
|
481
|
-
throw new Error(`${own} already has its thread ${
|
|
568
|
+
throw new Error(`${own} already has its thread ${threadIdOf(t)} "${head.title}": a new version of it supersedes its newest version${want ? ` ${want}` : ', here none: its head is his note'}, never ${given.supersedes}; or leave --supersedes out and the tool links it`)
|
|
482
569
|
return { own, thread: head.id, ...(want !== undefined ? { supersedes: want } : {}), answers: [...given.answers] }
|
|
483
570
|
}
|
|
484
571
|
|
|
@@ -488,7 +575,7 @@ export async function openThread(dir: string, address: string, o: { title: strin
|
|
|
488
575
|
// an ask is made with its facts (asks/ask-store.ts createAsk): a bare ask: thread would wait on him and no count would hold it
|
|
489
576
|
if (address.startsWith('ask:') && o.ask === undefined) throw new Error(`${address}: an ask is made with sk ask, its thread opened with its facts`)
|
|
490
577
|
const own = threadOfAddress(address, readAll(dir).items, specOf(dir))
|
|
491
|
-
if (own) throw new Error(`${address} already has its thread ${own
|
|
578
|
+
if (own) throw new Error(`${address} already has its thread ${threadIdOf(own)} "${own.head.item.title}": write in it`)
|
|
492
579
|
const first = o.title.trim().split('\n')[0] ?? ''
|
|
493
580
|
const title = first.length > 80 ? `${first.slice(0, 79).trimEnd()}…` : first
|
|
494
581
|
return addItem(dir, { title, what: o.what?.trim() || (o.ask ? '' : `the thread of ${address}`), subject: { kind: 'object', address }, on: address, opening: true, ...(o.lane ? { lane: o.lane } : {}), ...(o.machine ? { machine: true } : {}), ...(o.now ? { now: o.now } : {}), ...(o.ask ? { ask: o.ask } : {}), ...(o.asksVerdict ? { asksVerdict: o.asksVerdict } : {}) })
|
|
@@ -506,37 +593,45 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
|
|
|
506
593
|
if (!input.title.trim()) throw new Error('--title: required')
|
|
507
594
|
// an ask's head holds its facts alone: its words are its instructions, a message (asks/ask-store.ts createAsk)
|
|
508
595
|
if (!input.what.trim() && input.ask === undefined) throw new Error('--what: required, what changed and why')
|
|
509
|
-
const first = input.image !== undefined || input.video !== undefined || input.audio !== undefined || input.before !== undefined || input.after !== undefined
|
|
510
|
-
const given: ViewInput[] = [...(first ? [{ label: input.label ?? '', image: input.image, video: input.video, audio: input.audio, before: input.before, after: input.after }] : []), ...(input.views ?? [])].map(
|
|
596
|
+
const first = input.image !== undefined || input.video !== undefined || input.audio !== undefined || input.pano !== undefined || input.splat !== undefined || input.mesh !== undefined || input.before !== undefined || input.after !== undefined
|
|
597
|
+
const given: ViewInput[] = [...(first ? [{ label: input.label ?? '', image: input.image, video: input.video, audio: input.audio, pano: input.pano, splat: input.splat, mesh: input.mesh, before: input.before, after: input.after }] : []), ...(input.views ?? [])].map(
|
|
511
598
|
(v) => Object.fromEntries(Object.entries(v).filter(([, x]) => x !== undefined)) as unknown as ViewInput,
|
|
512
599
|
)
|
|
513
600
|
if (input.draft && given.length > 0) throw new Error('--draft: the version shows the draft itself, no image, clip, sound or view beside it')
|
|
514
601
|
if (input.opening && (given.length > 0 || input.draft || input.trailer)) throw new Error('a thread opened with words holds no media: a version with media goes into it after')
|
|
515
602
|
if (input.opening && !input.on) throw new Error('a thread opened with words names its address')
|
|
516
603
|
if (input.states && (given.length > 0 || input.draft || input.trailer || !input.on)) throw new Error('a version of an object shows its two states alone: its address (on), no image, clip, sound or view beside it')
|
|
604
|
+
if (input.saved && !input.states) throw new Error('a save of an object shows its two states: the text before and after')
|
|
517
605
|
for (const [side, st] of Object.entries(input.states ?? {})) if (st && JSON.stringify(st).length > STATE_MAX) throw new Error(`--${side}: the state is ${Math.round(JSON.stringify(st).length / 1024)} KB, over ${STATE_MAX / 1024} KB: a kind reads what the owner judges, not the whole repo`)
|
|
518
|
-
if (
|
|
606
|
+
if (input.doc) {
|
|
607
|
+
const why = docProblem(input.doc)
|
|
608
|
+
if (why !== null) throw new Error(why)
|
|
609
|
+
const beside = input.draft ? '--draft' : input.trailer ? '--trailer' : input.states ? 'an object\'s states' : input.opening ? 'a thread opened with words' : input.wip ? '--wip --live' : input.choice ? '--choice' : null
|
|
610
|
+
if (beside !== null) throw new Error(`--${input.doc.kind}: a document is the version's subject, never with ${beside}`)
|
|
611
|
+
}
|
|
612
|
+
if (given.length === 0 && !input.draft && !input.opening && !input.states && !input.doc) throw new Error('give --md <file.md>, --html <file.html>, --image, --video, --audio or --pano, or --before and --after, or --view "<label>" <image>')
|
|
519
613
|
for (const [i, v] of given.entries()) if (i > 0 && !v.label.trim()) throw new Error('--view: every view after the first needs its label')
|
|
520
614
|
if (input.choice && given.length < 2) throw new Error('--choice: a choice has two options or more, one --view each')
|
|
521
|
-
if (input.agentPick !== undefined && !input.choice) throw new Error('--pick: only on a --choice
|
|
615
|
+
if (input.agentPick !== undefined && !input.choice) throw new Error('--pick: only on a --choice version')
|
|
522
616
|
const agentPick = input.agentPick === undefined ? undefined : pickIndex(given, input.agentPick)
|
|
523
617
|
for (const v of given) if (v.note !== undefined && v.gallery) throw new Error(`--view "${v.label}": a note goes on an image, a clip or a sound, never a gallery`)
|
|
618
|
+
const lives = given.map((v, i) => liveOf(v, i === 0 ? 'the first view' : `--live "${v.label}"`))
|
|
524
619
|
const loaded = await Promise.all(given.map((v, i) => loadView(v, i === 0 ? 'the first view' : `--view "${v.label}"`, { keep: input.keep === true })))
|
|
525
620
|
const c = io(dir)
|
|
526
|
-
if (input.supersedes !== undefined && !c.has(input.supersedes)) throw new Error(`--supersedes ${input.supersedes}: no such
|
|
621
|
+
if (input.supersedes !== undefined && !c.has(input.supersedes)) throw new Error(`--supersedes ${input.supersedes}: no such thread in ${dir}`)
|
|
527
622
|
if (input.supersedes !== undefined && readItem(dir, input.supersedes)?.item.origin.by !== 'agent')
|
|
528
623
|
throw new Error(`--supersedes ${input.supersedes}: a report or a note is answered, never superseded: --answers ${input.supersedes}`)
|
|
529
624
|
const answers = [...new Set(input.answers ?? [])]
|
|
530
625
|
for (const a of answers) {
|
|
531
626
|
const y = ID_RE.test(a) ? readItem(dir, a) : null
|
|
532
627
|
if (!y) throw new Error(`--answers ${a}: no such item in ${dir}`)
|
|
533
|
-
if (y.item.origin.by === 'agent') throw new Error(`--answers ${a}: an agent's
|
|
628
|
+
if (y.item.origin.by === 'agent') throw new Error(`--answers ${a}: an agent's version; a newer one passes --supersedes ${a}`)
|
|
534
629
|
}
|
|
535
630
|
const subject: Subject = input.subject ?? { kind: 'shot' }
|
|
536
631
|
const topic = input.topic?.trim() || undefined
|
|
537
632
|
const wrong = specProblems({ subject, ...(topic ? { topic } : {}) } as Item, spec)
|
|
538
633
|
if (wrong.length > 0) throw new Error(wrong.join('; '))
|
|
539
|
-
if (input.wip && (given.length > 2 || given.slice(1).some((v) => !v.gallery))) throw new Error('--wip: the
|
|
634
|
+
if (input.wip && (given.length > 2 || given.slice(1).some((v) => !v.gallery))) throw new Error('--wip: the version shows the live frame, and its history as a gallery, nothing else')
|
|
540
635
|
if (input.marks && input.marks.length > given.length) throw new Error(`marks: ${input.marks.length} lists for ${given.length} views`)
|
|
541
636
|
const about = [...new Set((input.about ?? []).map(addressOrThrow))]
|
|
542
637
|
const on = input.on?.trim() ? addressOrThrow(input.on) : undefined
|
|
@@ -546,7 +641,9 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
|
|
|
546
641
|
* refusal costs no write, and again under the address's lock, where the version is written */
|
|
547
642
|
const settle = (): { own: string | null; supersedes?: string; answers: string[] } => {
|
|
548
643
|
const link = threadLink(dir, { subject, ...(on ? { on } : {}), ...(input.trailer ? { trailer: input.trailer } : {}) }, given0, spec)
|
|
549
|
-
|
|
644
|
+
// a draft settled is posted, not a look he locked: its next save shows as the next version (review/settle.ts);
|
|
645
|
+
// a save of the object in its home (review/doc-save.ts) moved it already
|
|
646
|
+
if (link.supersedes !== undefined && !input.keeps?.trim() && input.draft === undefined && input.saved === undefined) {
|
|
550
647
|
const all = readAll(dir).items
|
|
551
648
|
const old = all.find((x) => x.item.id === link.supersedes)
|
|
552
649
|
const answered = old ? chainOf(old, all).find((x) => verdictOf(x)) : undefined
|
|
@@ -559,7 +656,7 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
|
|
|
559
656
|
// an address decides alone: the older guard reads titles only for a version that names none
|
|
560
657
|
if (link.supersedes === undefined && link.thread === null && link.own === null) {
|
|
561
658
|
if (input.fresh === true) {
|
|
562
|
-
if (!input.why?.trim()) throw new Error('--new needs --why "<reason>": why this is another subject than the active
|
|
659
|
+
if (!input.why?.trim()) throw new Error('--new needs --why "<reason>": why this is another subject than the active thread next to it')
|
|
563
660
|
} else {
|
|
564
661
|
const others = readAll(dir).items.filter((x) => !link.answers.includes(x.item.id))
|
|
565
662
|
const c = coveringHead({ title: input.title, ...(topic ? { topic } : {}), subject }, others, spec)
|
|
@@ -589,7 +686,7 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
|
|
|
589
686
|
...(input.changelog ? { changelog: { category: input.changelog.category.trim(), line: input.changelog.line.trim(), ...(input.changelog.rating ? { rating: input.changelog.rating } : {}) } } : {}),
|
|
590
687
|
...(topic ? { topic } : {}),
|
|
591
688
|
...(input.commit ? { commit: input.commit } : {}),
|
|
592
|
-
views: loaded.map((v, n) => viewOf(v, n, input.marks?.[n], given[n]?.note)),
|
|
689
|
+
views: loaded.map((v, n) => withLive(viewOf(v, n, input.marks?.[n], given[n]?.note), lives[n])),
|
|
593
690
|
...(link.supersedes ? { supersedes: link.supersedes } : {}),
|
|
594
691
|
...(link.answers.length > 0 ? { answers: link.answers } : {}),
|
|
595
692
|
...(on ? { on } : {}),
|
|
@@ -604,7 +701,9 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
|
|
|
604
701
|
...(input.trailer ? { trailer: input.trailer } : {}),
|
|
605
702
|
...(input.draft ? { draft: input.draft } : {}),
|
|
606
703
|
...(input.states ? { states: input.states } : {}),
|
|
704
|
+
...(input.saved ? { saved: { by: input.saved.by } } : {}),
|
|
607
705
|
...(input.ask ? { ask: input.ask } : {}),
|
|
706
|
+
...(input.doc ? { doc: { kind: input.doc.kind, text: input.doc.text } } : {}),
|
|
608
707
|
})
|
|
609
708
|
const problems = itemProblems(itemOf(early))
|
|
610
709
|
if (problems.length > 0) throw new Error(problems.join('; '))
|
|
@@ -614,7 +713,7 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
|
|
|
614
713
|
const media = await factsOf(tmp, viewFilesOf(itemOf(early)))
|
|
615
714
|
try {
|
|
616
715
|
// the link read and the version written under one lock: two posts at once on one address make one thread
|
|
617
|
-
return addressLocked(dir, early.own, () => {
|
|
716
|
+
return await addressLocked(dir, early.own, () => {
|
|
618
717
|
const head: Item = { ...itemOf(settle()), media }
|
|
619
718
|
createAtCommit(dir, c, id, tmp, head)
|
|
620
719
|
return head
|
|
@@ -625,51 +724,49 @@ export async function addItem(dir: string, input: AddInput): Promise<Item> {
|
|
|
625
724
|
}
|
|
626
725
|
}
|
|
627
726
|
|
|
628
|
-
/** where the lock of one own address lives: the store's `.locks/` while the
|
|
727
|
+
/** where the lock of one own address lives: the store's `.locks/` while the items are files (a store per checkout),
|
|
629
728
|
* else beside the machine db, keyed by the repo the rows belong to, so every worktree of a repo takes one lock */
|
|
630
729
|
export function addressLockPath(dir: string, address: string): string {
|
|
631
|
-
const rows =
|
|
730
|
+
const rows = threadsInDb()
|
|
632
731
|
const key = new Bun.CryptoHasher('sha1').update(rows ? `${repoIdOf(dir)}\n${address}` : address).digest('hex').slice(0, 16)
|
|
633
732
|
return join(rows ? join(dirname(machineDbPath()), 'thread-locks') : join(dir, '.locks'), key)
|
|
634
733
|
}
|
|
635
734
|
|
|
636
|
-
/** the
|
|
637
|
-
* no address, no lock */
|
|
638
|
-
function addressLocked<T>(dir: string, address: string | null, fn: () => T): T {
|
|
735
|
+
/** the lease of one own address (`<addressLockPath>.lock`) while its thread is read and a version written into it,
|
|
736
|
+
* waited on off the thread (the daemon's loop answers meanwhile); no address, no lock */
|
|
737
|
+
async function addressLocked<T>(dir: string, address: string | null, fn: () => T): Promise<T> {
|
|
639
738
|
if (address === null) return fn()
|
|
640
739
|
const at = addressLockPath(dir, address)
|
|
641
|
-
mkdirSync(at, { recursive: true })
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
throw (e as Error).message.endsWith('locked by another process') ? new Error(`${address}: another post on it holds its lock past 2 s; post again`) : e
|
|
646
|
-
}
|
|
740
|
+
mkdirSync(dirname(at), { recursive: true })
|
|
741
|
+
const r = await withLease(at, { label: `the address ${address}`, waitMs: 2000 }, fn)
|
|
742
|
+
if (!r.ok) throw new Error(`${address}: another post on it holds its lock past 2 s; post again`)
|
|
743
|
+
return r.value
|
|
647
744
|
}
|
|
648
745
|
|
|
649
|
-
/** the empty folder a new
|
|
650
|
-
function tmpOf(c:
|
|
746
|
+
/** the empty folder a new item's files are written in, beside the folder they become: the repo's store, or the spool */
|
|
747
|
+
function tmpOf(c: ItemBackend, id: string): string {
|
|
651
748
|
const tmp = join(dirname(c.folder(id)), `.${id}.tmp`)
|
|
652
749
|
rmSync(tmp, { recursive: true, force: true })
|
|
653
750
|
mkdirSync(tmp, { recursive: true })
|
|
654
751
|
return tmp
|
|
655
752
|
}
|
|
656
753
|
|
|
657
|
-
/** where a store's
|
|
658
|
-
* daemon's file (
|
|
659
|
-
export const mediaDir = (dir: string): string => (
|
|
754
|
+
/** where a store's item media are: the folder of each item in the repo, or, with the items as rows, the spool beside the
|
|
755
|
+
* daemon's file (item-db.ts spoolOf). An item's file is `join(mediaDir(dir), id, name)` either way */
|
|
756
|
+
export const mediaDir = (dir: string): string => (threadsInDb() ? spoolOf(dir) : dir)
|
|
660
757
|
|
|
661
|
-
/** a new
|
|
758
|
+
/** a new item committed to the store the switch names NOW: its files took their time (a clip, a big picture), and a
|
|
662
759
|
* move may have turned the switch meanwhile, past its lag. Its id was free in the store it was chosen in */
|
|
663
|
-
function createAtCommit(dir: string, picked:
|
|
760
|
+
function createAtCommit(dir: string, picked: ItemBackend, id: string, tmp: string, head: Item): void {
|
|
664
761
|
const now = io(dir)
|
|
665
|
-
if (now.rows !== picked.rows && now.taken(id)) throw new Error(`${id}: the store moved while this
|
|
762
|
+
if (now.rows !== picked.rows && now.taken(id)) throw new Error(`${id}: the store moved while this item was written, and the id is taken there: add it again`)
|
|
666
763
|
now.create(id, tmp, head)
|
|
667
764
|
}
|
|
668
765
|
|
|
669
766
|
/** every file of view `n` into the folder, each as `<name>.tmp` renamed, so no reader sees half of one */
|
|
670
767
|
function copyFiles(v: Loaded, n: number, into: string): void {
|
|
671
768
|
const files = filesOf(v, n) as Record<string, string>
|
|
672
|
-
const copies: [string, string][] = [...v.sources.map(([name, p]): [string, string] => [p, files[name] ?? name]), ...(v.tiles ?? []).flatMap((t, k): [string, string][] => [[t.path, tileName(n, k, t.path)], ...(t.before ? [[t.before, tileName(n, k, t.before, '-before')] as [string, string]] : [])])]
|
|
769
|
+
const copies: [string, string][] = [...v.sources.map(([name, p]): [string, string] => [p, files[name] ?? name]), ...(v.space ? [[v.space, spaceName(n, v.space)] as [string, string]] : []), ...(v.tiles ?? []).flatMap((t, k): [string, string][] => [[t.path, tileName(n, k, t.path)], ...(t.before ? [[t.before, tileName(n, k, t.before, '-before')] as [string, string]] : [])])]
|
|
673
770
|
for (const [from, name] of copies) {
|
|
674
771
|
const to = join(into, name)
|
|
675
772
|
putFile(v, from, `${to}.tmp`)
|
|
@@ -688,11 +785,11 @@ function putFile(v: Loaded, from: string, to: string): void {
|
|
|
688
785
|
/** the command that posts an update, as a refusal names it */
|
|
689
786
|
const updateLine = (id: string): string => `sk thread update ${id} <${UPDATE_STATES.join('|')}> "<one line>" <file> | <before> <after>`
|
|
690
787
|
|
|
691
|
-
/** another angle of an open
|
|
788
|
+
/** another angle of an open version's subject, appended as its next view; refused once he answered, except the view of an
|
|
692
789
|
* update (`update`), which goes on at any time */
|
|
693
790
|
export async function addView(dir: string, id: string, v: ViewInput, o: { marks?: ReviewMark[]; light?: 'review'; message?: true; keep?: boolean } = {}): Promise<Item> {
|
|
694
791
|
const x = readItem(dir, id)
|
|
695
|
-
if (!x) throw new Error(`no
|
|
792
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
696
793
|
if (verdictOf(x) && !o.message) throw new Error(`${id} has the owner's answer already: a picture of the work since goes on as an update, ${updateLine(id)}; a new version passes --supersedes ${id}`)
|
|
697
794
|
if (v.note !== undefined && v.gallery) throw new Error(`"${v.label}": a note goes on an image, a clip or a sound, never a gallery`)
|
|
698
795
|
if (!v.label.trim()) throw new Error('add-view: the view needs its label')
|
|
@@ -712,6 +809,50 @@ export async function addView(dir: string, id: string, v: ViewInput, o: { marks?
|
|
|
712
809
|
})
|
|
713
810
|
}
|
|
714
811
|
|
|
812
|
+
/** a view and the views a repo's `addView` hook adds after it (`also`), each through `addView`, in order; the added
|
|
813
|
+
* views take no marks. The item after the last, and the number of each view added */
|
|
814
|
+
export async function addViewAlso(dir: string, id: string, v: ViewInput, o: { marks?: ReviewMark[]; light?: 'review'; keep?: boolean; also?: readonly ViewInput[] } = {}): Promise<{ item: Item; added: number[] }> {
|
|
815
|
+
const { also = [], ...first } = o
|
|
816
|
+
let item = await addView(dir, id, v, first)
|
|
817
|
+
const added = [item.views.length - 1]
|
|
818
|
+
for (const a of also) {
|
|
819
|
+
item = await addView(dir, id, a, o.keep ? { keep: true } : {})
|
|
820
|
+
added.push(item.views.length - 1)
|
|
821
|
+
}
|
|
822
|
+
return { item, added }
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/** the still of a version a kind's page draws (review/kind-still.ts): one image, or a before and an after of one size,
|
|
826
|
+
* copied into its folder under a first view's names (a version of an object holds no view) */
|
|
827
|
+
export async function setStill(dir: string, id: string, s: { image: string } | { before: string; after: string }): Promise<Item> {
|
|
828
|
+
const x = readItem(dir, id)
|
|
829
|
+
if (!x?.item.states) throw new Error(`${id}: a still goes on a version of an object, which holds its states`)
|
|
830
|
+
const loaded = await loadView({ label: '', ...s }, 'the still')
|
|
831
|
+
if (loaded.clip || loaded.audio || loaded.tiles || loaded.scene) throw new Error('the still: a png, jpg or webp image')
|
|
832
|
+
const folder = io(dir).folder(id)
|
|
833
|
+
if (!existsSync(folder)) mkdirSync(folder, { recursive: true })
|
|
834
|
+
copyFiles(loaded, 0, folder)
|
|
835
|
+
const files = filesOf(loaded, 0) as { image: string } | { before: string; after: string }
|
|
836
|
+
const facts = await factsOf(folder, Object.values(files))
|
|
837
|
+
return updateHead(dir, id, (cur) => ({ ...cur, states: { ...cur.states!, still: { files, size: loaded.size } }, media: { ...cur.media, ...facts } }))
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/** the stills of a version of an object whose state names its views (review/kind-still.ts): one gallery tile a view,
|
|
841
|
+
* its label the legend under it, its id the tile's `view`, a before beside each view the before has; the version's
|
|
842
|
+
* one view, set once */
|
|
843
|
+
export async function setKindStills(dir: string, id: string, tiles: readonly { view: string; label: string; file: string; before?: string }[]): Promise<Item> {
|
|
844
|
+
const x = readItem(dir, id)
|
|
845
|
+
if (!x?.item.states) throw new Error(`${id}: stills go on a version of an object, which holds its states`)
|
|
846
|
+
if (x.item.views.length > 0) throw new Error(`${id}: its stills are set once, when it is posted`)
|
|
847
|
+
const loaded = await loadView({ label: STILLS_LABEL, gallery: tiles.map((t) => ({ file: t.file, label: t.label, view: t.view, ...(t.before !== undefined ? { before: t.before } : {}) })) }, 'the stills')
|
|
848
|
+
const folder = io(dir).folder(id)
|
|
849
|
+
if (!existsSync(folder)) mkdirSync(folder, { recursive: true })
|
|
850
|
+
copyFiles(loaded, 0, folder)
|
|
851
|
+
const view = viewOf(loaded, 0)
|
|
852
|
+
const facts = await factsOf(folder, isGallery(view) ? view.gallery.flatMap((g) => [g.file, ...(g.before ? [g.before] : [])]) : [])
|
|
853
|
+
return updateHead(dir, id, (cur) => ({ ...cur, views: [view], media: { ...cur.media, ...facts } }))
|
|
854
|
+
}
|
|
855
|
+
|
|
715
856
|
/** the option the agent suggests, by its label or its letter; throws naming every option */
|
|
716
857
|
function pickIndex(views: readonly { label: string }[], ref: string, flag = '--pick'): number {
|
|
717
858
|
try {
|
|
@@ -721,12 +862,12 @@ function pickIndex(views: readonly { label: string }[], ref: string, flag = '--p
|
|
|
721
862
|
}
|
|
722
863
|
}
|
|
723
864
|
|
|
724
|
-
/** the agent's pick set on an open choice
|
|
865
|
+
/** the agent's pick set on an open choice version, by the view's label or letter; refused once he answered */
|
|
725
866
|
export function setAgentPick(dir: string, id: string, ref: string): Item {
|
|
726
867
|
const x = readItem(dir, id)
|
|
727
|
-
if (!x) throw new Error(`no
|
|
868
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
728
869
|
if (verdictOf(x)) throw new Error(`${id} has his answer already: the pick shows what was suggested, never rewritten after`)
|
|
729
|
-
if (x.item.choice !== true) throw new Error(`${id} is no choice
|
|
870
|
+
if (x.item.choice !== true) throw new Error(`${id} is no choice version: a pick names one of its options`)
|
|
730
871
|
const n = pickIndex(x.item.views, ref, 'pick')
|
|
731
872
|
return updateHead(dir, id, (cur) => ({ ...cur, agentPick: n }))
|
|
732
873
|
}
|
|
@@ -736,7 +877,7 @@ export function updateHead(dir: string, id: string, fn: (cur: Item) => Item): It
|
|
|
736
877
|
const c = io(dir)
|
|
737
878
|
return c.lock(id, () => {
|
|
738
879
|
const held = c.head(id)
|
|
739
|
-
if (held == null) throw Object.assign(new Error(`no
|
|
880
|
+
if (held == null) throw Object.assign(new Error(`no item ${id}`), { code: 'ENOENT' })
|
|
740
881
|
const next = fn(held.head as Item)
|
|
741
882
|
const problems = itemProblems(next)
|
|
742
883
|
if (problems.length > 0) throw new Error(problems.join('; '))
|
|
@@ -745,16 +886,16 @@ export function updateHead(dir: string, id: string, fn: (cur: Item) => Item): It
|
|
|
745
886
|
})
|
|
746
887
|
}
|
|
747
888
|
|
|
748
|
-
/** the ids of a store's
|
|
749
|
-
export const
|
|
889
|
+
/** the ids of a store's items, as their folders name them */
|
|
890
|
+
export const itemIds = (dir: string): string[] => io(dir).names().filter((n) => ID_RE.test(n))
|
|
750
891
|
|
|
751
|
-
/**
|
|
752
|
-
export const
|
|
892
|
+
/** an item's stamp: any write of its head or its thread moves it */
|
|
893
|
+
export const itemStamp = (dir: string, id: string): string => io(dir).stamp(id)
|
|
753
894
|
|
|
754
|
-
/**
|
|
895
|
+
/** an item's head as it is stored, and the time it was written; null with no head */
|
|
755
896
|
export const rawHead = (dir: string, id: string): { head: unknown; at: number } | null => io(dir).head(id)
|
|
756
897
|
|
|
757
|
-
/** the ids of
|
|
898
|
+
/** the ids of an item's messages, oldest first */
|
|
758
899
|
export const threadIds = (dir: string, id: string): string[] => (ID_RE.test(id) ? io(dir).threadIds(id) : [])
|
|
759
900
|
|
|
760
901
|
/** one message as it is stored */
|
|
@@ -762,17 +903,17 @@ export const rawMessage = (dir: string, id: string, mid: string): unknown => io(
|
|
|
762
903
|
|
|
763
904
|
export type LandedFile = { did: 'landed' | 'same' | 'kept'; why?: string }
|
|
764
905
|
|
|
765
|
-
/** the longest
|
|
906
|
+
/** the longest item or message id an item carried between machines may have: a folder or file name of about 120
|
|
766
907
|
* characters fits every file system, with its `.tmp` and `.land-<pid>` beside it */
|
|
767
908
|
export const MAX_ID_LENGTH = 120
|
|
768
909
|
|
|
769
|
-
/** a head made on another machine written as this
|
|
910
|
+
/** a head made on another machine written as this item's item.json: a new item built in a dot folder and renamed,
|
|
770
911
|
* an existing one rewritten under its lock once `keep` (given the head as the file says now) has no reason to keep
|
|
771
912
|
* it. A head that is no item of that id is kept out. `dry` says what it would do */
|
|
772
913
|
export function landHead(dir: string, id: string, head: unknown, o: { keep: (cur: Item) => string | null; aside?: (cur: Item) => boolean; dry?: boolean; waitMs?: number }): LandedFile {
|
|
773
|
-
if (id.length > MAX_ID_LENGTH) return { did: 'kept', why: `
|
|
914
|
+
if (id.length > MAX_ID_LENGTH) return { did: 'kept', why: `item ${id.slice(0, 40)}…: its id is over ${MAX_ID_LENGTH} characters` }
|
|
774
915
|
const problems = itemProblems(head)
|
|
775
|
-
if (problems.length > 0 || (head as Item).id !== id) return { did: 'kept', why: `
|
|
916
|
+
if (problems.length > 0 || (head as Item).id !== id) return { did: 'kept', why: `item ${id}: its head is no item of that id (${problems.join('; ') || 'another id'})` }
|
|
776
917
|
const c = io(dir)
|
|
777
918
|
const folder = c.folder(id)
|
|
778
919
|
const decide = (cur: Item): LandedFile | null => {
|
|
@@ -782,7 +923,7 @@ export function landHead(dir: string, id: string, head: unknown, o: { keep: (cur
|
|
|
782
923
|
}
|
|
783
924
|
if (!c.has(id)) {
|
|
784
925
|
if (o.dry) return { did: 'landed' }
|
|
785
|
-
// the rows land a new
|
|
926
|
+
// the rows land a new item under the lock below, in one transaction
|
|
786
927
|
if (!c.rows && !c.taken(id)) {
|
|
787
928
|
mkdirSync(dir, { recursive: true })
|
|
788
929
|
const tmp = join(dir, `.${id}.land-${process.pid}`)
|
|
@@ -793,7 +934,7 @@ export function landHead(dir: string, id: string, head: unknown, o: { keep: (cur
|
|
|
793
934
|
renameSync(tmp, folder)
|
|
794
935
|
return { did: 'landed' }
|
|
795
936
|
} catch {
|
|
796
|
-
//
|
|
937
|
+
// an item of that id came meanwhile: its lock decides below
|
|
797
938
|
rmSync(tmp, { recursive: true, force: true })
|
|
798
939
|
}
|
|
799
940
|
}
|
|
@@ -818,7 +959,7 @@ export function landHead(dir: string, id: string, head: unknown, o: { keep: (cur
|
|
|
818
959
|
...(aside ? [`a head made apart replaced this machine's, which is kept beside it as ${REPLACED}`] : []),
|
|
819
960
|
...(moved.length > 0 ? [`this machine's files of the names the landing head gives to other bytes are kept as ${moved.join(', ')}`] : []),
|
|
820
961
|
]
|
|
821
|
-
return said.length > 0 ? { did: 'landed', why: `
|
|
962
|
+
return said.length > 0 ? { did: 'landed', why: `item ${id}: ${said.join('; ')}` } : { did: 'landed' }
|
|
822
963
|
}, o.waitMs)
|
|
823
964
|
}
|
|
824
965
|
|
|
@@ -847,20 +988,20 @@ function setAsideClashes(folder: string, head: Item): string[] {
|
|
|
847
988
|
return moved
|
|
848
989
|
}
|
|
849
990
|
|
|
850
|
-
/** does that
|
|
991
|
+
/** does that item keep a head a landing replaced */
|
|
851
992
|
export const hasReplaced = (dir: string, id: string): boolean => ID_RE.test(id) && io(dir).hasReplaced(id)
|
|
852
993
|
|
|
853
|
-
/** a message made on another machine written into its
|
|
854
|
-
* while the
|
|
855
|
-
export function landMessage(dir: string, id: string, m: unknown, o: { dry?: boolean } = {}): LandedFile | { did: 'no-
|
|
994
|
+
/** a message made on another machine written into its item's thread, once: never over a file of its id. `no-item`
|
|
995
|
+
* while the item has no head here: the caller holds it. A message that is not one is kept out */
|
|
996
|
+
export function landMessage(dir: string, id: string, m: unknown, o: { dry?: boolean } = {}): LandedFile | { did: 'no-item' } {
|
|
856
997
|
const mid = m != null && typeof m === 'object' ? (m as { id?: unknown }).id : undefined
|
|
857
998
|
const problems = typeof mid === 'string' && MESSAGE_RE.test(mid) ? messageProblems(m, mid) : ['no message id']
|
|
858
|
-
if (id.length > MAX_ID_LENGTH || (typeof mid === 'string' && mid.length > MAX_ID_LENGTH)) return { did: 'kept', why: `a message of
|
|
859
|
-
if (!ID_RE.test(id) || problems.length > 0) return { did: 'kept', why: `a message of
|
|
999
|
+
if (id.length > MAX_ID_LENGTH || (typeof mid === 'string' && mid.length > MAX_ID_LENGTH)) return { did: 'kept', why: `a message of item ${id.slice(0, 40)}: an id over ${MAX_ID_LENGTH} characters` }
|
|
1000
|
+
if (!ID_RE.test(id) || problems.length > 0) return { did: 'kept', why: `a message of item ${id}: ${problems.join('; ') || 'no item id'}` }
|
|
860
1001
|
const c = io(dir)
|
|
861
|
-
if (!c.has(id)) return { did: 'no-
|
|
1002
|
+
if (!c.has(id)) return { did: 'no-item' }
|
|
862
1003
|
// one id is made on two machines only by one party in one millisecond: the one here stays, and it is said
|
|
863
|
-
if (c.hasMessage(id, mid as string)) return revOf(c.message(id, mid as string)) === revOf(m) ? { did: 'same' } : { did: 'kept', why: `message ${mid as string} of
|
|
1004
|
+
if (c.hasMessage(id, mid as string)) return revOf(c.message(id, mid as string)) === revOf(m) ? { did: 'same' } : { did: 'kept', why: `message ${mid as string} of item ${id}: another message of that id is on this machine, each machine keeps its own` }
|
|
864
1005
|
if (o.dry) return { did: 'landed' }
|
|
865
1006
|
c.append(id, m as Message)
|
|
866
1007
|
return { did: 'landed' }
|
|
@@ -901,15 +1042,15 @@ export function readItem(dir: string, id: string): ReviewItem | null {
|
|
|
901
1042
|
/** one item as it is stored, whatever the unit: what the index keeps */
|
|
902
1043
|
const readRaw = (dir: string, id: string): ReviewItem | null => (ID_RE.test(id) ? (io(dir).raw(id) ?? (healed(dir, id) ? io(dir).raw(id) : null)) : null)
|
|
903
1044
|
|
|
904
|
-
/**
|
|
1045
|
+
/** an item this process misses while a move runs: a process that read the switch before it turned made it on the side
|
|
905
1046
|
* the move left, so it is carried over now, as the move's own pass after its lag would. Whether it is here now */
|
|
906
1047
|
function healed(dir: string, id: string): boolean {
|
|
907
|
-
if (!
|
|
1048
|
+
if (!threadsMoving()) return false
|
|
908
1049
|
const c = io(dir)
|
|
909
1050
|
const other = c.rows ? filesIO(dir) : rowsIO(dir)
|
|
910
1051
|
if (!other.has(id)) return false
|
|
911
|
-
const {
|
|
912
|
-
|
|
1052
|
+
const { carryItem } = require('./move.ts') as typeof import('./move.ts')
|
|
1053
|
+
carryItem(dir, id, other, c)
|
|
913
1054
|
return c.has(id)
|
|
914
1055
|
}
|
|
915
1056
|
|
|
@@ -947,15 +1088,22 @@ function readThread(dir: string, id: string): Message[] {
|
|
|
947
1088
|
}
|
|
948
1089
|
|
|
949
1090
|
/** appends one message to an item's thread, its image copied in beside it; the id never collides */
|
|
950
|
-
export function appendMessage(dir: string, id: string, m: Omit<Message, 'id' | 'at'>, o: { image?: string; now?: Date; machine?: true } = {}): Message {
|
|
1091
|
+
export function appendMessage(dir: string, id: string, m: Omit<Message, 'id' | 'at'>, o: { image?: string; files?: readonly { path: string; name: string }[]; now?: Date; machine?: true } = {}): Message {
|
|
951
1092
|
const now = o.now ?? new Date()
|
|
952
1093
|
if (o.image !== undefined) {
|
|
953
1094
|
if (!existsSync(o.image)) throw new Error(`${o.image}: no such file`)
|
|
954
1095
|
if (!IMAGE_EXT.test(extname(o.image).toLowerCase())) throw new Error(`${o.image}: a png, jpg or webp`)
|
|
955
1096
|
}
|
|
956
|
-
|
|
1097
|
+
const given = o.files ?? []
|
|
1098
|
+
if (given.length > MESSAGE_FILES_MAX) throw new Error(`at most ${MESSAGE_FILES_MAX} files on one message`)
|
|
1099
|
+
const sizes = given.map((f) => {
|
|
1100
|
+
const st = statSync(f.path, { throwIfNoEntry: false })
|
|
1101
|
+
if (!st?.isFile()) throw new Error(`${f.name}: no such file`)
|
|
1102
|
+
return st.size
|
|
1103
|
+
})
|
|
1104
|
+
// an item with no head here (set aside, deleted) gets no thread: a folder with no head would read as a broken item
|
|
957
1105
|
const c = io(dir)
|
|
958
|
-
if (!c.has(id) && !healed(dir, id)) throw new Error(`no
|
|
1106
|
+
if (!c.has(id) && !healed(dir, id)) throw new Error(`no item ${id}`)
|
|
959
1107
|
const folder = join(c.folder(id), 'thread')
|
|
960
1108
|
const base = messageIdOf(now, m.who)
|
|
961
1109
|
let n = 1
|
|
@@ -967,9 +1115,15 @@ export function appendMessage(dir: string, id: string, m: Omit<Message, 'id' | '
|
|
|
967
1115
|
mkdirSync(folder, { recursive: true })
|
|
968
1116
|
copyFileSync(o.image, join(folder, file))
|
|
969
1117
|
}
|
|
1118
|
+
const files: MessageFile[] = given.map((f, i) => {
|
|
1119
|
+
const name = cleanFileName(f.name)
|
|
1120
|
+
return { file: attachFile(mid, i + 1, name), name, size: sizes[i]!, type: mimeOf(name) }
|
|
1121
|
+
})
|
|
1122
|
+
if (files.length > 0) mkdirSync(folder, { recursive: true })
|
|
1123
|
+
for (const [i, f] of files.entries()) copyFileSync(given[i]!.path, join(folder, f.file))
|
|
970
1124
|
const session = !o.machine && partyOf(m.who) === 'agent' && m.session === undefined ? sessionId() : null
|
|
971
1125
|
if (session) noteSession(dir)
|
|
972
|
-
const out: Message = { id: mid, at: now.toISOString(), ...m, ...(session ? { session } : {}), ...(file ? { image: file } : {}) }
|
|
1126
|
+
const out: Message = { id: mid, at: now.toISOString(), ...m, ...(session ? { session } : {}), ...(file ? { image: file } : {}), ...(files.length > 0 ? { files } : {}) }
|
|
973
1127
|
try {
|
|
974
1128
|
c.append(id, out)
|
|
975
1129
|
return out
|
|
@@ -983,13 +1137,15 @@ export function appendMessage(dir: string, id: string, m: Omit<Message, 'id' | '
|
|
|
983
1137
|
|
|
984
1138
|
/** a reply on an item from `who` (the owner, or an agent by its name), with an optional image; `re` the message of the
|
|
985
1139
|
* item it answers (his hint on an update); throws with the reason */
|
|
986
|
-
export function addMessage(dir: string, id: string, who: string, text: unknown, image?: string, now = new Date(), re?: unknown): Message {
|
|
1140
|
+
export function addMessage(dir: string, id: string, who: string, text: unknown, image?: string, now = new Date(), re?: unknown, files?: readonly { path: string; name: string }[], to?: readonly Mention[]): Message {
|
|
987
1141
|
const x = readItem(dir, id)
|
|
988
|
-
if (!x) throw new Error(`no
|
|
989
|
-
|
|
1142
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
1143
|
+
// files alone are a reply too: their words may be empty
|
|
1144
|
+
const bare = (files?.length ?? 0) > 0 && (text === undefined || (typeof text === 'string' && text.trim() === ''))
|
|
1145
|
+
const t = bare ? { text: '' } : textOf(text)
|
|
990
1146
|
if ('error' in t) throw new Error(t.error)
|
|
991
1147
|
if (re !== undefined && !(typeof re === 'string' && x.thread.some((m) => m.id === re))) throw new Error(`re: ${String(re)} is no message of ${id}`)
|
|
992
|
-
return appendMessage(dir, id, { who, text: t.text, ...(typeof re === 'string' ? { re } : {}) }, { ...(image !== undefined ? { image } : {}), now })
|
|
1148
|
+
return appendMessage(dir, id, { who, text: t.text, ...(typeof re === 'string' ? { re } : {}), ...(to !== undefined && to.length > 0 ? { to: [...to] } : {}) }, { ...(image !== undefined ? { image } : {}), ...(files !== undefined && files.length > 0 ? { files } : {}), now })
|
|
993
1149
|
}
|
|
994
1150
|
|
|
995
1151
|
/** one option of a question: its words, and its media, one file (a picture, a clip, a sound) or a before and an after */
|
|
@@ -1001,7 +1157,7 @@ export interface AskOption {
|
|
|
1001
1157
|
/** an agent's question to the owner on a thread's item: its words, two options or more, each words or a media, the
|
|
1002
1158
|
* option it picks; each option's media becomes a view the message holds (addView `message`), and the owner answers in
|
|
1003
1159
|
* one click (answerAsk) */
|
|
1004
|
-
export async function postAsk(dir: string, id: string, q: { who: string; text: unknown; options?: readonly (string | AskOption)[]; pick?: number; kind?: AnswerKind; secret?: { name: string; login?: boolean }; done?: readonly number[]; now?: Date; replaces?: string; step?: { of: string; i: number } }): Promise<Message> {
|
|
1160
|
+
export async function postAsk(dir: string, id: string, q: { who: string; text: unknown; options?: readonly (string | AskOption)[]; pick?: number; kind?: AnswerKind; secret?: { name: string; login?: boolean }; done?: readonly number[]; now?: Date; replaces?: string; step?: { of: string; i: number; carries?: string } }): Promise<Message> {
|
|
1005
1161
|
const x = readItem(dir, id)
|
|
1006
1162
|
if (!x) throw new Error(`no item ${id}`)
|
|
1007
1163
|
const t = textOf(q.text)
|
|
@@ -1132,8 +1288,7 @@ export function answerAsk(dir: string, id: string, a: { re: string; option?: num
|
|
|
1132
1288
|
const choice = m.ask.choices?.[o] ?? null
|
|
1133
1289
|
if (a.pick !== undefined && choice === null) throw new Error(`pick: the step « ${lines[o]} » holds no choice`)
|
|
1134
1290
|
if (a.pick !== undefined && !(Number.isInteger(a.pick) && a.pick >= 0 && a.pick < choice!.options.length && tick)) throw new Error(`pick: one of 0 to ${choice!.options.length - 1}, with a tick`)
|
|
1135
|
-
|
|
1136
|
-
return appendMessage(dir, id, { who: 'owner', re: a.re, answer: { option: o, tick, ...(a.pick !== undefined ? { pick: a.pick } : {}) }, text: words === '' ? `${tick ? '✓' : '✗'} ${lines[o]}${picked}` : words }, at)
|
|
1291
|
+
return appendMessage(dir, id, { who: 'owner', re: a.re, answer: { option: o, tick, ...(a.pick !== undefined ? { pick: a.pick } : {}) }, text: words === '' ? tickText(m, o, tick, a.pick) : words }, at)
|
|
1137
1292
|
}
|
|
1138
1293
|
if (m.ask && (kind === 'text' || kind === 'url')) {
|
|
1139
1294
|
const value = a.value?.trim() ?? ''
|
|
@@ -1160,20 +1315,23 @@ export function answerAsk(dir: string, id: string, a: { re: string; option?: num
|
|
|
1160
1315
|
}
|
|
1161
1316
|
|
|
1162
1317
|
/** the open secret question `re` of item `id`, or why there is none; its name and whether an account goes with it */
|
|
1163
|
-
export function secretQuestion(dir: string, id: string, re: string): { name: string; login: boolean } | { error: string } {
|
|
1318
|
+
export function secretQuestion(dir: string, id: string, re: string, o: { again?: true } = {}): { name: string; login: boolean; open: boolean; at: number } | { error: string } {
|
|
1164
1319
|
const x = readItem(dir, id)
|
|
1165
1320
|
const m = x?.thread.find((y) => y.id === re)
|
|
1166
1321
|
if (!x || !m || m.ask?.kind !== 'secret' || !m.ask.secret) return { error: `${re} is no secret question of ${id}` }
|
|
1167
|
-
|
|
1168
|
-
|
|
1322
|
+
const open = askOpen(x.thread, m)
|
|
1323
|
+
// `again`: a value stored already may be replaced, the question answered once more
|
|
1324
|
+
if (!open && o.again !== true) return { error: `${m.ask.secret.name} is no longer asked here` }
|
|
1325
|
+
return { name: m.ask.secret.name, login: m.ask.secret.login === true, open, at: Date.parse(m.at) }
|
|
1169
1326
|
}
|
|
1170
1327
|
|
|
1171
1328
|
/** the owner's answer to a secret question once its value is in the house secret manager: the name and the time, never
|
|
1172
1329
|
* the value, which this function never sees */
|
|
1173
|
-
export function answerSecret(dir: string, id: string, a: { re: string; now?: Date }): Message {
|
|
1174
|
-
const q = secretQuestion(dir, id, a.re)
|
|
1330
|
+
export function answerSecret(dir: string, id: string, a: { re: string; now?: Date; again?: true; found?: true }): Message {
|
|
1331
|
+
const q = secretQuestion(dir, id, a.re, a.again ? { again: true } : {})
|
|
1175
1332
|
if ('error' in q) throw new Error(q.error)
|
|
1176
|
-
|
|
1333
|
+
// `found`: the store holds it since the question, put there from a terminal, not typed in the field
|
|
1334
|
+
return appendMessage(dir, id, { who: 'owner', re: a.re, answer: { stored: q.name }, text: `stored as ${q.name}${a.found ? ', found in the store' : ''}` }, a.now ? { now: a.now } : {})
|
|
1177
1335
|
}
|
|
1178
1336
|
|
|
1179
1337
|
/** the owner's click on one of the kind's actions on the thread's object: a message the holder's watch prints */
|
|
@@ -1217,12 +1375,12 @@ export interface UpdateInput {
|
|
|
1217
1375
|
machine?: true
|
|
1218
1376
|
}
|
|
1219
1377
|
|
|
1220
|
-
/** an agent's update on its
|
|
1378
|
+
/** an agent's update on its version, at any time, before or after his answer: its file, or its pair, becomes the version's next view
|
|
1221
1379
|
* (labelled `update <k>: <state>`, the line its note), then one message carries the state and the line. Still broken
|
|
1222
|
-
* or better holds the
|
|
1380
|
+
* or better holds the version in work, fixed asks the owner's verdict again (model.ts stateOf) */
|
|
1223
1381
|
export async function postUpdate(dir: string, id: string, u: UpdateInput): Promise<{ item: Item; message: Message; tag: string; view: number | null }> {
|
|
1224
1382
|
const x = readItem(dir, id)
|
|
1225
|
-
if (!x) throw new Error(`no
|
|
1383
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
1226
1384
|
if (x.item.origin.by !== 'agent') return lineOnNote(dir, x, u)
|
|
1227
1385
|
if (x.item.wip) throw new Error(`${id} is a draft on a live shot: its frame refreshes itself, sk thread ready ${id} when it is done`)
|
|
1228
1386
|
if (!UPDATE_STATES.includes(u.state as UpdateState)) throw new Error(`the state: one of ${UPDATE_STATES.join(', ')}, not « ${u.state} »`)
|
|
@@ -1255,16 +1413,40 @@ async function lineOnNote(dir: string, x: ReviewItem, u: UpdateInput): Promise<{
|
|
|
1255
1413
|
return { item: x.item, message, tag: `update ${k} (${UPDATE_WORDS[state]})`, view: null }
|
|
1256
1414
|
}
|
|
1257
1415
|
|
|
1258
|
-
/** `
|
|
1259
|
-
*
|
|
1260
|
-
export function markRead(dir: string, id: string,
|
|
1416
|
+
/** agent `who` read what the owner wrote on an item: one `seen` message naming them; how many it read. `only`: the words
|
|
1417
|
+
* it may read, as `sk thread seen` reads them with the registry (threads.ts seenOnly). The owner's read: markOwnerRead */
|
|
1418
|
+
export function markRead(dir: string, id: string, who: string = agentName(), now = new Date(), only?: readonly string[]): number {
|
|
1261
1419
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
1262
1420
|
if (!x) return 0
|
|
1263
|
-
|
|
1421
|
+
// a word that names other agents is theirs to read (wiki tools/shipkit/threads-how-it-fits.md, Mentions); `only`, read
|
|
1422
|
+
// with the registry, already says which reach the caller
|
|
1423
|
+
const theirs = new Set(only === undefined ? x.thread.filter((m) => !mayReadNamed(m, who, sessionId())).map((m) => m.id) : [])
|
|
1424
|
+
const of = toAcknowledge(x, 'agent').filter((m) => (only === undefined || only.includes(m)) && !theirs.has(m))
|
|
1264
1425
|
if (of.length > 0) appendMessage(dir, id, { who, op: 'seen', of }, { now })
|
|
1265
1426
|
return of.length
|
|
1266
1427
|
}
|
|
1267
1428
|
|
|
1429
|
+
/** his cursor moves to `upTo`, the newest thing the page drew of the thread `ids` (head first): every agent word up to it
|
|
1430
|
+
* goes read, and the read mark is dated `upTo` itself (never later than now), so what an agent wrote after it stays new
|
|
1431
|
+
* to him (review/owner-read.ts). The number of read marks written: 0 when his cursor already passed `upTo` */
|
|
1432
|
+
export function markOwnerRead(dir: string, ids: readonly string[], upTo: string, now = new Date()): number {
|
|
1433
|
+
const at = new Date(Math.min(Date.parse(upTo), now.getTime()))
|
|
1434
|
+
if (Number.isNaN(at.getTime())) throw new Error('upTo: the time of the newest thing the page drew')
|
|
1435
|
+
const members = ids.flatMap((id) => (ID_RE.test(id) ? (readItem(dir, id) ?? []) : []))
|
|
1436
|
+
const to = at.toISOString()
|
|
1437
|
+
if (members.length === 0 || ownerCursorAt(members) >= to) return 0
|
|
1438
|
+
let wrote = 0
|
|
1439
|
+
for (const x of members) {
|
|
1440
|
+
const before = new Set(x.thread.filter((m) => m.at <= to).map((m) => m.id))
|
|
1441
|
+
const of = toAcknowledge(x, 'owner').filter((m) => before.has(m))
|
|
1442
|
+
if (of.length === 0) continue
|
|
1443
|
+
appendMessage(dir, x.item.id, { who: 'owner', op: 'seen', of }, { now: at })
|
|
1444
|
+
wrote++
|
|
1445
|
+
}
|
|
1446
|
+
if (wrote === 0) appendMessage(dir, members[0]!.item.id, { who: 'owner', op: 'seen', of: [] }, { now: at })
|
|
1447
|
+
return Math.max(wrote, 1)
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1268
1450
|
/** the path of a message's image, null for any other name */
|
|
1269
1451
|
export function threadImage(dir: string, id: string, name: string): string | null {
|
|
1270
1452
|
if (!ID_RE.test(id) || !MESSAGE_FILE_RE.test(name)) return null
|
|
@@ -1272,6 +1454,13 @@ export function threadImage(dir: string, id: string, name: string): string | nul
|
|
|
1272
1454
|
return existsSync(f) ? f : null
|
|
1273
1455
|
}
|
|
1274
1456
|
|
|
1457
|
+
/** the path of a message's image or attached file on the disk, null for any other name or when the disk let it go */
|
|
1458
|
+
export function threadFile(dir: string, id: string, name: string): string | null {
|
|
1459
|
+
if (!ID_RE.test(id) || !isThreadMedia(`thread/${name}`)) return null
|
|
1460
|
+
const f = join(io(dir).folder(id), 'thread', name)
|
|
1461
|
+
return existsSync(f) ? f : null
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1275
1464
|
/** an item's stamp: its folder and its thread. Every write renames a file into one of them (the head into the folder, a
|
|
1276
1465
|
* message into thread/), which moves that directory's change time, so any write moves it. Two stats an item, never
|
|
1277
1466
|
* three: on a 3000 item store each stat is 10 ms of every read */
|
|
@@ -1301,7 +1490,12 @@ function readOne(dir: string, id: string): Read {
|
|
|
1301
1490
|
|
|
1302
1491
|
/** every item of the store as its unit reads it: an item its unit refuses (a subject kind or a topic it does not
|
|
1303
1492
|
* declare, a subject's problems) is broken; the index keeps the raw reads, so a unit's change never invalidates it */
|
|
1304
|
-
export
|
|
1493
|
+
export function readAll(dir: string): ReadAll {
|
|
1494
|
+
const all = checked(threadsInDb() ? rowsAll(dir) : readRaws(dir), specOf(dir))
|
|
1495
|
+
// a long running reader whose model moved restarts on it (model-moved.ts)
|
|
1496
|
+
if (all.broken.length > 0) modelWatch.readFailed()
|
|
1497
|
+
return all
|
|
1498
|
+
}
|
|
1305
1499
|
|
|
1306
1500
|
const checks = new WeakMap<ReadAll, { spec: Spec; all: ReadAll }>()
|
|
1307
1501
|
|
|
@@ -1412,48 +1606,53 @@ function* readRawsSteps(dir: string, stamps?: Map<string, string>): Generator<vo
|
|
|
1412
1606
|
/** the owner's verdict, checked against its item, appended as his message */
|
|
1413
1607
|
export function writeVerdict(dir: string, id: string, body: unknown, now = new Date()): { ok: true; message: Message } | { ok: false; errors: string[] } {
|
|
1414
1608
|
const x = readItem(dir, id)
|
|
1415
|
-
if (!x) return { ok: false, errors: [`no
|
|
1416
|
-
if (x.item.wip) return { ok: false, errors: [`${id} is a draft
|
|
1417
|
-
if (x.item.origin.by !== 'agent') return { ok: false, errors: [`${id} was raised, not shown by an agent: a verdict goes on the
|
|
1609
|
+
if (!x) return { ok: false, errors: [`no item ${id}`] }
|
|
1610
|
+
if (x.item.wip) return { ok: false, errors: [`${id} is a draft version: the agent makes it ready before a verdict; a comment goes in a reply`] }
|
|
1611
|
+
if (x.item.origin.by !== 'agent') return { ok: false, errors: [`${id} was raised, not shown by an agent: a verdict goes on the version that shows its fix; a word goes in a reply`] }
|
|
1418
1612
|
const r = verdictMessageOf(body, x.item)
|
|
1419
1613
|
if (!r.ok) return r
|
|
1420
1614
|
return { ok: true, message: appendMessage(dir, id, { who: 'owner', ...r.message }, { now }) }
|
|
1421
1615
|
}
|
|
1422
1616
|
|
|
1423
1617
|
/** an agent acted on the verdict and the owner's replies; false when the item has neither */
|
|
1424
|
-
export function markSeen(dir: string, id: string, now = new Date()): boolean {
|
|
1618
|
+
export function markSeen(dir: string, id: string, now = new Date(), only?: readonly string[]): boolean {
|
|
1425
1619
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
1426
1620
|
if (!x) return false
|
|
1427
|
-
const read = markRead(dir, id,
|
|
1621
|
+
const read = markRead(dir, id, agentName(), now, only)
|
|
1622
|
+
if (only !== undefined) return read > 0
|
|
1428
1623
|
return verdictOf(x) !== null || read > 0
|
|
1429
1624
|
}
|
|
1430
1625
|
|
|
1431
|
-
/** takes an unanswered
|
|
1626
|
+
/** takes an unanswered version back; `already` names who took it back before, `refused` says why it may not and what to type */
|
|
1432
1627
|
export function withdraw(dir: string, id: string, why: string, now = new Date()): { already?: string } | { refused: string } {
|
|
1433
1628
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
1434
|
-
if (!x) return { refused: `no
|
|
1435
|
-
const
|
|
1629
|
+
if (!x) return { refused: `no item ${id}` }
|
|
1630
|
+
const o = x.item.origin
|
|
1631
|
+
if (o.by === 'owner' || o.by === 'player')
|
|
1632
|
+
return { refused: `${id} was raised by ${o.by === 'owner' ? 'the owner' : 'a player'}: an agent never takes it back; close it with sk thread fixed ${id} "<what was done>", or sk thread wontfix ${id} --note "<why>"` }
|
|
1633
|
+
const before = itemWithdrawOf(x)
|
|
1436
1634
|
if (before) return { already: `by ${before.who}, ${before.at.slice(0, 16).replace('T', ' ')} UTC` }
|
|
1437
1635
|
const v = verdictOf(x)
|
|
1438
1636
|
if (v) {
|
|
1439
1637
|
const owes = v.status === 'approved-with-fix' ? `sk thread done ${id} "<what changed>", ` : ''
|
|
1440
|
-
const close = v.status === 'approved-with-fix' || v.status === 'rejected' ? `; what it owes: ${owes}--supersedes ${id} on its new
|
|
1638
|
+
const close = v.status === 'approved-with-fix' || v.status === 'rejected' ? `; what it owes: ${owes}--supersedes ${id} on its new version, or sk thread wontfix ${id} --note "<why>"` : ''
|
|
1441
1639
|
return { refused: `${id}: he answered it (${v.status}), so it waits on him no more${close}` }
|
|
1442
1640
|
}
|
|
1443
1641
|
appendMessage(dir, id, { who: agentName(), op: 'withdraw', note: why }, { now })
|
|
1444
1642
|
return {}
|
|
1445
1643
|
}
|
|
1446
1644
|
|
|
1447
|
-
/** takes back one
|
|
1448
|
-
* nobody from then, read only, its line « withdrawn: <why> » (review/supersede.ts). The words he said elsewhere
|
|
1449
|
-
* chat) go in the reason, quoted, so a question answered outside the hub never stays open */
|
|
1645
|
+
/** takes back one object of an agent (`re`, its message id: a question, a proposed change, words), with the reason: it
|
|
1646
|
+
* waits on nobody from then, read only, its line « withdrawn: <why> » (review/supersede.ts). The words he said elsewhere
|
|
1647
|
+
* (in chat) go in the reason, quoted, so a question answered outside the hub never stays open. The owner's words are never one */
|
|
1450
1648
|
export function withdrawObject(dir: string, re: string, why: string, now = new Date()): { item: string } | { refused: string } {
|
|
1451
1649
|
const x = readAll(dir).items.find((y) => y.thread.some((m) => m.id === re))
|
|
1452
1650
|
const m = x?.thread.find((y) => y.id === re)
|
|
1453
1651
|
if (!x || !m) return { refused: `no message ${re} (sk thread show <address> lists them)` }
|
|
1454
|
-
if (partyOf(m.who) !== 'agent'
|
|
1455
|
-
|
|
1456
|
-
if (
|
|
1652
|
+
if (partyOf(m.who) !== 'agent') return { refused: `${re} is the owner's: an agent never takes back what he wrote` }
|
|
1653
|
+
if (m.instructions !== undefined) return { refused: `${re} is an ask's instructions: sk ask … --replaces, or its bar` }
|
|
1654
|
+
if (!isObject(m)) return { refused: `${re} is no question, proposed change or words of an agent: withdraw takes those back` }
|
|
1655
|
+
if ((m.ask !== undefined || m.propose !== undefined || asksVerdict(m)) && !objectOpen(x.thread, m)) return { refused: `${re}: he answered it already, so it waits on him no more` }
|
|
1457
1656
|
const before = x.thread.find((y) => y.op === 'withdraw' && y.re === re)
|
|
1458
1657
|
if (before) return { refused: `${re}: withdrawn already by ${before.who} (${before.note ?? ''})` }
|
|
1459
1658
|
appendMessage(dir, x.item.id, { who: agentName(), op: 'withdraw', re, note: why }, { now })
|
|
@@ -1463,7 +1662,7 @@ export function withdrawObject(dir: string, re: string, why: string, now = new D
|
|
|
1463
1662
|
/** the reason a question answered in chat is withdrawn with: the owner's words, quoted */
|
|
1464
1663
|
export const answeredInChat = (words: string): string => `answered in chat by the owner: « ${words.replace(/\s+/g, ' ').trim()} »`
|
|
1465
1664
|
|
|
1466
|
-
/** an answered
|
|
1665
|
+
/** an answered version waits for his answer again: its verdict stays in the thread, before the reopen. `who`: an agent
|
|
1467
1666
|
* (the CLI), or the owner taking the verdict back (the hub). The verdict reopened, null when it has none */
|
|
1468
1667
|
export function reopen(dir: string, id: string, o: { who?: string; now?: Date } = {}): Verdict | null {
|
|
1469
1668
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
@@ -1486,7 +1685,7 @@ export interface RaiseInput {
|
|
|
1486
1685
|
subject: Subject
|
|
1487
1686
|
origin: Exclude<Origin, { by: 'agent' }>
|
|
1488
1687
|
title: string
|
|
1489
|
-
/** an auto item's markdown, what its rule saw: shown as a
|
|
1688
|
+
/** an auto item's markdown, what its rule saw: shown as a version's `what` */
|
|
1490
1689
|
what?: string
|
|
1491
1690
|
topic?: string
|
|
1492
1691
|
commit?: string
|
|
@@ -1496,6 +1695,8 @@ export interface RaiseInput {
|
|
|
1496
1695
|
rects?: Rect[]
|
|
1497
1696
|
/** the image the item shows, copied in as its first view */
|
|
1498
1697
|
image?: string
|
|
1698
|
+
/** files of the first message, staged (stagedFiles): its words name them by their tags */
|
|
1699
|
+
files?: readonly { path: string; name: string }[]
|
|
1499
1700
|
now?: Date
|
|
1500
1701
|
}
|
|
1501
1702
|
|
|
@@ -1534,7 +1735,7 @@ export async function raiseItem(dir: string, input: RaiseInput): Promise<ReviewI
|
|
|
1534
1735
|
const head = { ...item, ...(image ? { media: await factsOf(tmp, [image]) } : {}) }
|
|
1535
1736
|
createAtCommit(dir, c, id, tmp, head)
|
|
1536
1737
|
const who = input.origin.by === 'player' ? 'player' : 'owner'
|
|
1537
|
-
if (text) appendMessage(dir, id, { who, text, ...(input.rects && input.rects.length > 0 ? { rects: input.rects } : {}) }, { now })
|
|
1738
|
+
if (text) appendMessage(dir, id, { who, text, ...(input.rects && input.rects.length > 0 ? { rects: input.rects } : {}) }, { now, ...(input.files && input.files.length > 0 ? { files: input.files } : {}) })
|
|
1538
1739
|
return readItem(dir, id) as ReviewItem
|
|
1539
1740
|
}
|
|
1540
1741
|
|
|
@@ -1573,33 +1774,11 @@ export async function ownerVerdict(dir: string, o: { subject: Subject; from: str
|
|
|
1573
1774
|
else appendMessage(dir, x.item.id, { who: 'owner', op: 'reopen' }, at)
|
|
1574
1775
|
}
|
|
1575
1776
|
|
|
1576
|
-
/** the
|
|
1577
|
-
function
|
|
1578
|
-
const
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
try {
|
|
1582
|
-
mkdirSync(lock)
|
|
1583
|
-
break
|
|
1584
|
-
} catch (e) {
|
|
1585
|
-
// only a lock another holds is waited for: a folder that is missing or a file in the way is said at once
|
|
1586
|
-
if ((e as { code?: unknown }).code !== 'EEXIST') throw e
|
|
1587
|
-
if (Date.now() >= until) {
|
|
1588
|
-
// a lock left by a dead process: older than the wait itself
|
|
1589
|
-
if (Date.now() - statSync(lock).mtimeMs > 2000) {
|
|
1590
|
-
rmSync(lock, { recursive: true, force: true })
|
|
1591
|
-
continue
|
|
1592
|
-
}
|
|
1593
|
-
throw new Error(`${id}: locked by another process`)
|
|
1594
|
-
}
|
|
1595
|
-
Bun.sleepSync(10)
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
try {
|
|
1599
|
-
return fn()
|
|
1600
|
-
} finally {
|
|
1601
|
-
rmSync(lock, { recursive: true, force: true })
|
|
1602
|
-
}
|
|
1777
|
+
/** the lease of one item (`<id>/.item.lock`) while an act is checked and written, waited on for at most `waitMs` */
|
|
1778
|
+
export function lockedItem<T>(dir: string, id: string, fn: () => T, waitMs = 2000): T {
|
|
1779
|
+
const r = withLeaseSync(join(dir, id, '.item'), { label: `the item ${id}`, waitMs }, fn)
|
|
1780
|
+
if (!r.ok) throw new Error(`${id}: locked by another process`)
|
|
1781
|
+
return r.value
|
|
1603
1782
|
}
|
|
1604
1783
|
|
|
1605
1784
|
/** a state change on an item by `who`, checked by `allowed` under the item's lock, so two workers claiming at once
|
|
@@ -1615,13 +1794,13 @@ export function act(dir: string, id: string, op: Exclude<Op, 'seen'>, who: strin
|
|
|
1615
1794
|
if (o.topic !== undefined && Object.keys(spec.topics).length > 0 && !spec.topics[o.topic]) throw new Error(`no topic « ${o.topic} »: ${Object.keys(spec.topics).join(', ')}`)
|
|
1616
1795
|
if (o.commit !== undefined && !/^[0-9a-f]{7,40}$/.test(o.commit)) throw new Error(`« ${o.commit} » is no commit`)
|
|
1617
1796
|
const now = o.now ?? new Date()
|
|
1618
|
-
// the first read of a process reads every
|
|
1797
|
+
// the first read of a process reads every item: done before the lock, the read under it only takes what moved
|
|
1619
1798
|
readAll(dir)
|
|
1620
1799
|
return io(dir).lock(id, () => {
|
|
1621
1800
|
const x = readItem(dir, id) as ReviewItem
|
|
1622
1801
|
const superseded = isFollowed(id, readAll(dir).items)
|
|
1623
1802
|
const role = spec.dispatcher ? (roleOf(dir)?.name ?? null) : null
|
|
1624
|
-
const why = op === 'claim' && superseded && x.item.origin.by === 'agent' ? 'a newer
|
|
1803
|
+
const why = op === 'claim' && superseded && x.item.origin.by === 'agent' ? 'a newer version redoes it: claim that one' : allowed(stateOf(x, superseded), op, who, role, spec.dispatcher, o.holds === true)
|
|
1625
1804
|
if (why) throw new Error(`${id}: ${why}`)
|
|
1626
1805
|
const m = appendMessage(
|
|
1627
1806
|
dir,
|
|
@@ -1665,7 +1844,7 @@ export function claimNext(dir: string, by: { lane: string } | { topic: string },
|
|
|
1665
1844
|
return null
|
|
1666
1845
|
}
|
|
1667
1846
|
|
|
1668
|
-
/** the owner deletes what he raised himself (a note he takes back): its folder goes; an agent's
|
|
1847
|
+
/** the owner deletes what he raised himself (a note he takes back): its folder goes; an agent's version is never deleted
|
|
1669
1848
|
* this way */
|
|
1670
1849
|
export function deleteRaised(dir: string, id: string): void {
|
|
1671
1850
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
@@ -1684,35 +1863,36 @@ export function deleteReport(dir: string, id: string): void {
|
|
|
1684
1863
|
|
|
1685
1864
|
export { GONE, GONE_KEEP_MS, goneCreated, goneEntries, sweepGone } from './gone.ts'
|
|
1686
1865
|
|
|
1687
|
-
/**
|
|
1866
|
+
/** an item out of the store: set aside while this machine carries its items to the hq (the switch hq-cards), so the
|
|
1688
1867
|
* job sends its deletion, and always as rows (kept GONE_KEEP_MS, the way back), else removed as it always was */
|
|
1689
1868
|
function removeItem(dir: string, id: string): void {
|
|
1690
1869
|
const c = io(dir)
|
|
1691
|
-
// while a move runs, a deletion stays as
|
|
1692
|
-
if (c.rows ||
|
|
1870
|
+
// while a move runs, a deletion stays as an item set aside, so neither pass carries the item back
|
|
1871
|
+
if (c.rows || threadsOn() || threadsMoving()) c.setAside(id, {})
|
|
1693
1872
|
else rmSync(join(dir, id), { recursive: true, force: true })
|
|
1694
1873
|
}
|
|
1695
1874
|
|
|
1696
|
-
/**
|
|
1697
|
-
*
|
|
1698
|
-
*
|
|
1875
|
+
/** an item's folder moved to `.gone/<id>` (or `<id>.<n>` beside an earlier one), whole and under its lock: the one way
|
|
1876
|
+
* an item leaves the store when another machine deleted it. `created`: only the item made at that moment, so another
|
|
1877
|
+
* item under that id stays. What it did */
|
|
1699
1878
|
export const setAside = (dir: string, id: string, o: { created?: string; before?: number } = {}): 'moved' | 'none' | 'other' => (ID_RE.test(id) ? io(dir).setAside(id, o) : 'none')
|
|
1700
1879
|
|
|
1701
1880
|
/** the files' set aside: the folder moved, whole */
|
|
1702
1881
|
function setAsideFile(dir: string, id: string, o: { created?: string; before?: number }): 'moved' | 'none' | 'other' {
|
|
1703
1882
|
if (!ID_RE.test(id) || !existsSync(join(dir, id))) return 'none'
|
|
1704
|
-
return
|
|
1883
|
+
return lockedItem(dir, id, () => {
|
|
1705
1884
|
if (o.created !== undefined || o.before !== undefined) {
|
|
1706
1885
|
const f = join(dir, id, 'item.json')
|
|
1707
1886
|
const cur = existsSync(f) ? (JSON.parse(readFileSync(f, 'utf8')) as { created?: unknown }) : null
|
|
1708
1887
|
if (o.created !== undefined && cur?.created !== o.created) return 'other'
|
|
1709
|
-
// `before`: only
|
|
1888
|
+
// `before`: only an item made before that moment
|
|
1710
1889
|
if (o.before !== undefined && !(Date.parse(String(cur?.created)) < o.before)) return 'other'
|
|
1711
1890
|
}
|
|
1712
1891
|
mkdirSync(join(dir, GONE), { recursive: true })
|
|
1713
1892
|
const to = join(dir, GONE, goneEntryFor(dir, id))
|
|
1714
1893
|
renameSync(join(dir, id), to)
|
|
1715
|
-
// the lock moved with the folder: the
|
|
1894
|
+
// the lock moved with the folder: the item is no longer here to lock (`.lock`, the folder of before the lease)
|
|
1895
|
+
rmSync(join(to, '.item.lock'), { force: true })
|
|
1716
1896
|
rmSync(join(to, '.lock'), { recursive: true, force: true })
|
|
1717
1897
|
return 'moved'
|
|
1718
1898
|
})
|
|
@@ -1749,19 +1929,19 @@ function itemOfPrefix(dir: string, ref: string): ReviewItem | null {
|
|
|
1749
1929
|
/** a player's report as the owner names it: `live#85`; any other item by its id */
|
|
1750
1930
|
export const refOf = (x: ReviewItem): string => (x.item.origin.by === 'player' ? `${x.item.origin.server}#${x.item.origin.serverId}` : x.item.id)
|
|
1751
1931
|
|
|
1752
|
-
/** a draft
|
|
1932
|
+
/** a draft version's live frame and its history again: the first view's image replaced, the history a gallery view; the
|
|
1753
1933
|
* draft's frame count moves */
|
|
1754
1934
|
export async function refreshDraft(dir: string, id: string, o: { image: string; history?: { file: string; label: string }[] }): Promise<Item> {
|
|
1755
1935
|
const x = readItem(dir, id)
|
|
1756
|
-
if (!x) throw new Error(`no
|
|
1936
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
1757
1937
|
const r = x.item
|
|
1758
|
-
if (!r.wip || verdictOf(x)) throw new Error(`${id} is not a draft
|
|
1938
|
+
if (!r.wip || verdictOf(x)) throw new Error(`${id} is not a draft version waiting`)
|
|
1759
1939
|
const f0 = r.views[0]
|
|
1760
1940
|
if (!f0 || isGallery(f0) || !('image' in f0.files)) throw new Error(`${id}: its first view is no image`)
|
|
1761
1941
|
const folder = io(dir).folder(id)
|
|
1762
1942
|
mkdirSync(folder, { recursive: true })
|
|
1763
1943
|
const image = f0.files.image
|
|
1764
|
-
// the frame keeps the name the
|
|
1944
|
+
// the frame keeps the name the version gave its first one: a webp, or a picture as given before items kept webps
|
|
1765
1945
|
const webp = extname(image) === '.webp'
|
|
1766
1946
|
const main = await loadView({ label: f0.label, image: o.image }, 'the live frame', webp ? { always: true } : { keep: true })
|
|
1767
1947
|
putFile(main, main.sources[0]?.[1] ?? '', join(folder, `${image}.tmp`))
|
|
@@ -1782,21 +1962,21 @@ export async function refreshDraft(dir: string, id: string, o: { image: string;
|
|
|
1782
1962
|
return updateHead(dir, id, () => ({ ...next, media }))
|
|
1783
1963
|
}
|
|
1784
1964
|
|
|
1785
|
-
/** the label of a draft
|
|
1965
|
+
/** the label of a draft version's history view */
|
|
1786
1966
|
export const HISTORY = 'history'
|
|
1787
1967
|
|
|
1788
|
-
/** a draft
|
|
1968
|
+
/** a draft version made a version he answers: its image the last frame or `image`, the draft state gone */
|
|
1789
1969
|
export async function readyItem(dir: string, id: string, o: { image?: string; now?: Date } = {}): Promise<Item> {
|
|
1790
1970
|
const x = readItem(dir, id)
|
|
1791
|
-
if (!x) throw new Error(`no
|
|
1971
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
1792
1972
|
const { wip, ...rest } = x.item
|
|
1793
1973
|
if (!wip && inWork(x)) {
|
|
1794
|
-
// a
|
|
1974
|
+
// a version its updates hold in work: ready asks the owner's verdict, its newest picture goes on as an update
|
|
1795
1975
|
if (o.image !== undefined) throw new Error(`${id} is in work by its updates: its new picture goes on as one, ${updateLine(id).replace('<broken|better|fixed>', 'fixed')}`)
|
|
1796
1976
|
appendMessage(dir, id, { who: agentName(), op: 'ready' }, o.now ? { now: o.now } : {})
|
|
1797
1977
|
return x.item
|
|
1798
1978
|
}
|
|
1799
|
-
if (!wip) throw new Error(`${id} is not a draft
|
|
1979
|
+
if (!wip) throw new Error(`${id} is not a draft version: it already takes a verdict`)
|
|
1800
1980
|
let item: Item = rest
|
|
1801
1981
|
if (o.image !== undefined) {
|
|
1802
1982
|
const f0 = rest.views[0]
|
|
@@ -1840,7 +2020,7 @@ const folderStamp = (key: string): string => {
|
|
|
1840
2020
|
}
|
|
1841
2021
|
|
|
1842
2022
|
/** the disk checked under the watch, which goes silent under load (FSEvents drops events) and must never freeze the
|
|
1843
|
-
* list: each call stats the store folder (1 µs), which
|
|
2023
|
+
* list: each call stats the store folder (1 µs), which an item's arrival or removal moves (a rename in it), and every
|
|
1844
2024
|
* SWEEP_MS the stamp of each item. What moved unheard goes dirty and moves the ETag */
|
|
1845
2025
|
function verify(key: string, w: Watched, now: number): void {
|
|
1846
2026
|
if (!w.held) return
|
|
@@ -1884,11 +2064,11 @@ function touched(path: string): void {
|
|
|
1884
2064
|
}
|
|
1885
2065
|
|
|
1886
2066
|
const STORE_SEGMENT = `/${LAYOUT.review}/`
|
|
1887
|
-
/** a write in
|
|
2067
|
+
/** a write in an item moves the store folder's own times: a process with no watch of it (the daemon's due, a watch that
|
|
1888
2068
|
* died) sees any process's write with one stat of the folder. A lock is no change of the store */
|
|
1889
2069
|
function stampStore(p: string): void {
|
|
1890
2070
|
const i = p.lastIndexOf(STORE_SEGMENT)
|
|
1891
|
-
if (i < 0 || p
|
|
2071
|
+
if (i < 0 || isLockFile(p)) return
|
|
1892
2072
|
const now = new Date()
|
|
1893
2073
|
try {
|
|
1894
2074
|
fs.utimesSync(p.slice(0, i + STORE_SEGMENT.length - 1), now, now)
|
|
@@ -1904,7 +2084,7 @@ function watchOf(dir: string): Watched | null {
|
|
|
1904
2084
|
try {
|
|
1905
2085
|
// an item's lock is no change of the list
|
|
1906
2086
|
const watcher = watch(key, { recursive: true }, (_, name) => {
|
|
1907
|
-
if (name
|
|
2087
|
+
if (name != null && isLockFile(name)) return
|
|
1908
2088
|
w.moved++
|
|
1909
2089
|
if (name) w.dirty.add(name.split('/')[0] ?? '')
|
|
1910
2090
|
else w.held = null
|
|
@@ -1922,7 +2102,7 @@ function watchOf(dir: string): Watched | null {
|
|
|
1922
2102
|
/** a watched store read whole before a page asks, the loop given back between two steps: the first read after a boot
|
|
1923
2103
|
* is the only whole one, every later one reads the items that moved */
|
|
1924
2104
|
export async function warmStore(dir: string): Promise<void> {
|
|
1925
|
-
if (
|
|
2105
|
+
if (threadsInDb()) return void rowsAll(dir)
|
|
1926
2106
|
if (!existsSync(dir)) return
|
|
1927
2107
|
const w = watchOf(dir)
|
|
1928
2108
|
if (!w || (w.held && w.all)) return
|
|
@@ -1938,7 +2118,7 @@ export async function warmStore(dir: string): Promise<void> {
|
|
|
1938
2118
|
/** changes when anything the list is built from changes: watched, a count of writes and what the disk check found;
|
|
1939
2119
|
* else a scan. The list's ETag */
|
|
1940
2120
|
export function storeStamp(dir: string, now = Date.now()): string {
|
|
1941
|
-
if (
|
|
2121
|
+
if (threadsInDb()) return rowsStamp(dir)
|
|
1942
2122
|
if (!existsSync(dir)) return 'none'
|
|
1943
2123
|
const w = watchOf(dir)
|
|
1944
2124
|
if (!w) return scanStamp(dir)
|
|
@@ -1949,22 +2129,22 @@ export function storeStamp(dir: string, now = Date.now()): string {
|
|
|
1949
2129
|
/** what moved the store, from what this process heard: its watch's events, its own writes, the store folder (one
|
|
1950
2130
|
* stat). Never a stat of its items: an event the watch missed waits for the next walk of the caller's own */
|
|
1951
2131
|
export function storeMoved(dir: string): string {
|
|
1952
|
-
if (
|
|
2132
|
+
if (threadsInDb()) return rowsStamp(dir)
|
|
1953
2133
|
if (!existsSync(dir)) return 'none'
|
|
1954
2134
|
const key = resolve(dir)
|
|
1955
2135
|
const w = watchOf(dir)
|
|
1956
2136
|
return w ? `${BOOT}.${w.moved}.${wrote}.${folderStamp(key)}` : `${BOOT}.-.${wrote}.${folderStamp(key)}`
|
|
1957
2137
|
}
|
|
1958
2138
|
|
|
1959
|
-
/** does the store hold anything: its folder, or with the switch cards-in-db its rows (a repo's
|
|
1960
|
-
export const hasStore = (dir: string): boolean => (
|
|
2139
|
+
/** does the store hold anything: its folder, or with the switch cards-in-db its rows (a repo's items may have no folder) */
|
|
2140
|
+
export const hasStore = (dir: string): boolean => (threadsInDb() ? rowsStamp(dir) !== 'none' : existsSync(dir))
|
|
1961
2141
|
|
|
1962
2142
|
/** the store's stamp and who listens (the live watchers' pids), so a watch that starts or dies moves it too */
|
|
1963
2143
|
export const listingStamp = (dir: string): string => `${storeStamp(dir)}~${liveWatchers(dir).map((w) => w.pid).join(',')}`
|
|
1964
2144
|
|
|
1965
2145
|
/** the stamp from a scan of every item's files: the safety net of a watcher that may miss an event */
|
|
1966
2146
|
export function scanStamp(dir: string): string {
|
|
1967
|
-
if (
|
|
2147
|
+
if (threadsInDb()) return rowsStamp(dir)
|
|
1968
2148
|
const h = new Bun.CryptoHasher('sha1')
|
|
1969
2149
|
if (!existsSync(dir)) return 'none'
|
|
1970
2150
|
const mark = (f: string): void => {
|
|
@@ -1983,7 +2163,7 @@ export function scanStamp(dir: string): string {
|
|
|
1983
2163
|
let cached: { dir: string; tag: string; all: ReadAll } | null = null
|
|
1984
2164
|
|
|
1985
2165
|
/** readAll kept while nothing it reads changed: watched, only the items written since are read again */
|
|
1986
|
-
export const readAllCached = (dir: string): ReadAll => checked(
|
|
2166
|
+
export const readAllCached = (dir: string): ReadAll => checked(threadsInDb() ? rowsAll(dir) : readRawsCached(dir), specOf(dir))
|
|
1987
2167
|
|
|
1988
2168
|
function readRawsCached(dir: string): ReadAll {
|
|
1989
2169
|
const w = existsSync(dir) ? watchOf(dir) : null
|