rvlib-shipkit 2.27.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 +71 -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 +73 -29
- package/src/agent-time/lane-name.ts +7 -0
- package/src/agent-time/leads.ts +95 -0
- package/src/agent-time/live.ts +11 -5
- package/src/agent-time/registry.ts +354 -0
- 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/born.ts +2 -2
- package/src/annex/offload.ts +12 -11
- package/src/annex/snapshots.ts +3 -3
- package/src/annex/tidy.ts +10 -23
- package/src/asks/ask-after.ts +8 -3
- package/src/asks/ask-bar-fold.ts +57 -0
- 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 +280 -0
- package/src/asks/ask-steps-fold.ts +123 -0
- package/src/asks/ask-store.ts +703 -0
- package/src/asks/ask-words-fold.ts +208 -0
- package/src/assets/kits/identity-kit.ts +106 -38
- package/src/assets/kits/poster-thumbnail.ts +282 -0
- package/src/checks/SK001-package-json-shape.check.ts +5 -7
- package/src/checks/SK003-claude-md-shape.check.ts +92 -25
- package/src/checks/SK004-gitignore-policy.check.ts +21 -17
- package/src/checks/SK010-undeclared-unit.check.ts +77 -64
- package/src/checks/SK013-one-way-in-policy.check.ts +27 -5
- package/src/checks/SK026-asks-autoclose.check.ts +9 -23
- 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/SK038-speaks-as.check.ts +3 -3
- 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 +26 -24
- package/src/checks/SK045-slow-hooks.check.ts +5 -2
- package/src/checks/SK049-thread-answers-hook.check.ts +83 -0
- package/src/checks/SK050-retired-commands.check.ts +127 -0
- 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 +303 -51
- package/src/cli/cmd_Backup.ts +157 -14
- package/src/cli/cmd_CacheAudit.ts +1 -1
- package/src/cli/cmd_Calls.ts +1 -0
- 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_Commands.ts +140 -34
- package/src/cli/cmd_Contracts.ts +1 -0
- 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 +2 -1
- package/src/cli/cmd_Lanes.ts +21 -4
- package/src/cli/cmd_Media.ts +59 -13
- package/src/cli/cmd_Messages.ts +152 -1
- package/src/cli/cmd_Needs.ts +1 -0
- 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 +1500 -424
- package/src/cli/cmd_Secret.ts +255 -34
- package/src/cli/cmd_Shot.ts +14 -6
- package/src/cli/cmd_Social.ts +41 -37
- package/src/cli/cmd_SocialDrafts.ts +248 -0
- package/src/cli/cmd_Sound.ts +22 -1
- package/src/cli/cmd_Space.ts +1 -1
- package/src/cli/cmd_Start.ts +3 -2
- package/src/cli/cmd_ThreadHolds.ts +34 -0
- package/src/cli/cmd_ThreadKinds.ts +153 -0
- package/src/cli/cmd_ThreadReflect.ts +91 -0
- package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
- 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 +5 -5
- package/src/cli/cmd_When.ts +2 -1
- package/src/cli/cmd_Worktrees.ts +109 -0
- package/src/cli/family-help.ts +2 -2
- package/src/cli/family-pages.ts +1 -1
- package/src/cli/kit/builtins.ts +1 -0
- package/src/cli/kit/verb.ts +6 -2
- package/src/cli/registry.ts +35 -5
- package/src/cli.ts +26 -15
- package/src/collections/actions.ts +27 -75
- package/src/collections/checks.ts +1 -1
- package/src/collections/collection-types.ts +23 -8
- package/src/collections/md-body.ts +5 -3
- package/src/collections/pings.ts +16 -6
- package/src/collections/providers.ts +63 -71
- package/src/collections/reflections.ts +9 -4
- 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 +75 -0
- package/src/core/hard-reset.ts +1 -2
- package/src/core/history-files.ts +4 -8
- package/src/core/house-layout.ts +20 -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 +11 -6
- package/src/core/load-probe.ts +4 -8
- package/src/core/locked-write.ts +116 -43
- package/src/core/loop-watch.ts +24 -3
- package/src/core/machine-db.ts +58 -14
- package/src/core/machine-link.ts +1 -1
- package/src/core/memory-watch.ts +3 -2
- package/src/core/migrate-layout.ts +8 -10
- 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 +19 -101
- 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 +21 -26
- package/src/home/app-sign.ts +17 -9
- package/src/home/daemon-guard.ts +6 -0
- package/src/home/daemon-jobs.ts +64 -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 +33 -8
- package/src/home/home-routes.ts +83 -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 +250 -94
- package/src/home/inbox.ts +27 -71
- package/src/home/lib-watch.ts +93 -74
- package/src/home/machine-fold.ts +54 -56
- package/src/home/machine-host.ts +19 -1
- 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/other-macs.ts +2 -2
- 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 +90 -148
- package/src/home/space-page.ts +8 -8
- 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 +64 -30
- package/src/home/vault-reveal.ts +29 -0
- package/src/home/vault-words.ts +5 -5
- 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 +32 -2
- package/src/hooks/run-hooks.ts +58 -5
- package/src/hooks/shared-file.ts +174 -0
- package/src/{serve → house}/project-gutter.ts +11 -54
- package/src/hq/door-route.ts +2 -2
- package/src/hq/door.ts +3 -3
- package/src/hq/files-send.ts +32 -33
- 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 +5 -2
- package/src/hq/hq-local.ts +48 -13
- package/src/hq/hq-routes.ts +10 -2
- package/src/hq/hq-store.ts +10 -6
- package/src/hq/kinds/ask.ts +9 -8
- 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 +35 -24
- package/src/hq/replica.ts +1 -2
- 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 +112 -0
- package/src/{serve → http}/door-forward.ts +11 -4
- package/src/http/loopback-serve.ts +84 -0
- package/src/{serve → http}/same-origin.ts +6 -2
- package/src/http/tailnet-caller.ts +118 -0
- package/src/identities/collection.ts +2 -2
- package/src/identities/identities.ts +9 -8
- package/src/identities/machine-route.ts +8 -3
- package/src/identities/shown.ts +2 -6
- package/src/ledger/check-table.ts +1 -1
- package/src/ledger/db.ts +9 -1
- 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 +51 -10
- package/src/media-store/backup/keys.ts +1 -4
- package/src/media-store/backup/manifest.ts +21 -3
- package/src/media-store/backup/prune.ts +362 -0
- package/src/media-store/backup/retention.ts +122 -0
- package/src/media-store/backup/run.ts +22 -35
- package/src/media-store/backup/sources.ts +27 -27
- package/src/media-store/backup/thread-copy.ts +339 -0
- package/src/media-store/backup/watch.ts +10 -6
- package/src/media-store/content.ts +3 -0
- package/src/media-store/copy/config.ts +3 -4
- package/src/media-store/copy/night.ts +4 -4
- package/src/media-store/copy/store.ts +2 -2
- 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 +141 -4
- package/src/media-store/hq-send.ts +5 -4
- package/src/media-store/purge.ts +5 -4
- package/src/media-store/remote.ts +2 -2
- package/src/media-store/space-listing.ts +20 -9
- package/src/media-store/space.ts +7 -5
- 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/guard.ts +49 -0
- package/src/messages/model.ts +1 -1
- package/src/messages/objects.ts +203 -0
- package/src/messages/routes.ts +2 -2
- package/src/messages/score.ts +2 -4
- package/src/messages/store-doc.ts +114 -0
- package/src/messages/verdicts.ts +6 -0
- package/src/messages/write.ts +285 -0
- 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/frame-client.ts +181 -4
- 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/reflections/reflections-queue.ts +1 -1
- package/src/release/gate-checkout.ts +124 -21
- package/src/release/git-facts.ts +11 -9
- package/src/release/machine-words.ts +21 -3
- package/src/release/public-clean.ts +81 -21
- 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 +53 -21
- package/src/review/anim.ts +8 -8
- package/src/review/answer-kinds.ts +160 -0
- package/src/review/auto.ts +3 -3
- package/src/review/band.ts +145 -0
- package/src/review/branch-hold.ts +91 -0
- package/src/review/cells.ts +451 -96
- package/src/review/close.ts +92 -0
- 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-item.ts +36 -0
- package/src/review/draft-model.ts +125 -17
- package/src/review/events.ts +164 -0
- package/src/review/file-tags.ts +52 -0
- package/src/review/format.ts +195 -38
- package/src/review/glyphs.ts +63 -0
- package/src/review/gone.ts +21 -21
- package/src/review/hand-over.ts +58 -0
- package/src/review/heard.ts +29 -0
- package/src/review/holds-sync.ts +62 -0
- package/src/review/holds.ts +85 -0
- package/src/review/house-kind-defs.ts +71 -0
- package/src/review/http.ts +1 -1
- package/src/review/inbox-hook.ts +69 -10
- package/src/review/inbox-read.ts +226 -0
- package/src/review/instructions.ts +241 -0
- package/src/review/{card-db.ts → item-db.ts} +48 -36
- package/src/review/{card-rows.ts → item-rows.ts} +79 -51
- package/src/review/kind-apply.ts +61 -0
- package/src/review/kind-catalog.ts +96 -0
- package/src/review/kind-still.ts +125 -0
- package/src/review/kinds.ts +314 -0
- package/src/review/lane-ask.ts +113 -0
- 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 +846 -214
- package/src/review/move.ts +62 -61
- package/src/review/need-address.ts +15 -0
- package/src/review/need-threads.ts +51 -0
- package/src/review/notes.ts +2 -1
- package/src/review/object-card.ts +48 -0
- package/src/review/object-read.ts +31 -0
- package/src/review/one-block.ts +64 -0
- package/src/review/owner-read.ts +41 -0
- package/src/review/owner-verdict.ts +36 -0
- package/src/review/parties.ts +274 -0
- package/src/review/paste.ts +4 -4
- package/src/review/phone-push.ts +137 -0
- package/src/review/previews.ts +19 -17
- package/src/review/project.ts +1 -1
- package/src/review/projections.ts +235 -0
- package/src/review/push.ts +269 -0
- package/src/review/referring.ts +76 -0
- package/src/review/reflection-object.ts +190 -0
- package/src/review/rev.ts +1 -1
- package/src/review/role.ts +3 -3
- package/src/review/routes.ts +227 -83
- 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 +110 -0
- package/src/review/settle.ts +67 -0
- package/src/review/snooze.ts +38 -0
- package/src/review/stage-routes.ts +15 -13
- package/src/review/{stage-card.ts → stage-thread.ts} +22 -21
- package/src/review/store-index.ts +49 -0
- package/src/review/store-parties.ts +20 -0
- package/src/review/store.ts +721 -260
- package/src/review/supersede.ts +132 -0
- package/src/review/take-back.ts +65 -0
- package/src/review/thread-fold.ts +20 -7
- package/src/review/threads.ts +397 -79
- package/src/review/traces.ts +206 -0
- package/src/review/trailer-desk.ts +7 -7
- package/src/review/{trailer-card.ts → trailer-item.ts} +12 -12
- 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 +140 -13
- package/src/review/uploads.ts +103 -0
- package/src/review/verdict-items.ts +73 -0
- package/src/review/verdict-write.ts +15 -0
- package/src/review/view-layout.ts +69 -0
- package/src/review/wait.ts +91 -0
- package/src/review/wakes.ts +115 -0
- package/src/review/watch-feed.ts +183 -0
- package/src/review/watchers.ts +44 -10
- package/src/rules/untrack-generated.ts +40 -39
- package/src/scaffold/files/bunfig.toml +1 -9
- package/src/scaffold/files/claude-settings-local.json +2 -0
- package/src/scaffold/files/vscode-settings.json +1 -1
- package/src/scaffold/project-scaffold.ts +14 -10
- package/src/secrets/archive-mark.ts +52 -0
- package/src/secrets/archive.ts +84 -0
- package/src/secrets/copy.ts +14 -14
- package/src/secrets/keychain-write.ts +56 -0
- package/src/secrets/keychain.ts +8 -5
- package/src/secrets/lapse-mark.ts +38 -0
- package/src/secrets/lapse.ts +71 -0
- package/src/secrets/list.ts +16 -22
- package/src/secrets/manager.ts +31 -16
- package/src/secrets/read.ts +161 -33
- package/src/secrets/security-line.ts +19 -0
- package/src/secrets/tail.ts +31 -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 +9 -5
- package/src/serve/hub-app/asks-st.ts +1 -4
- package/src/serve/hub-app/auto-text.tsx +118 -18
- package/src/serve/hub-app/benign-errors.ts +15 -1
- package/src/serve/hub-app/card-head.tsx +49 -0
- package/src/serve/hub-app/check-view.tsx +3 -2
- package/src/serve/hub-app/checks-svc.ts +1 -1
- package/src/serve/hub-app/clock-svc.ts +21 -5
- package/src/serve/hub-app/code-copy.ts +196 -0
- package/src/serve/hub-app/col-card.tsx +24 -40
- package/src/serve/hub-app/col-list-page.tsx +7 -4
- package/src/serve/hub-app/col-list-st.ts +6 -1
- package/src/serve/hub-app/col-tables-view.tsx +7 -4
- package/src/serve/hub-app/col-tables.ts +19 -13
- package/src/serve/hub-app/cols-svc.ts +15 -80
- package/src/serve/hub-app/comfy-svc.ts +3 -2
- package/src/serve/hub-app/commands/commands-page.tsx +2 -1
- package/src/serve/hub-app/commands/commands-st.ts +36 -26
- package/src/serve/hub-app/controls.css +99 -0
- 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/frames-st.ts +17 -1
- package/src/serve/hub-app/git-st.ts +25 -19
- package/src/serve/hub-app/git-view.tsx +3 -2
- 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 +167 -18
- package/src/serve/hub-app/home-strip.css +4 -8
- package/src/serve/hub-app/home-strip.tsx +7 -3
- package/src/serve/hub-app/home.html +10 -0
- package/src/serve/hub-app/house-wiki-view.tsx +20 -0
- package/src/serve/hub-app/hub-app.tsx +102 -36
- package/src/serve/hub-app/hub-types.ts +2 -0
- package/src/serve/hub-app/hub.css +117 -92
- package/src/serve/hub-app/icons.tsx +24 -4
- package/src/serve/hub-app/identities-st.ts +35 -25
- package/src/serve/hub-app/identities-view.tsx +11 -7
- package/src/serve/hub-app/inbox-st.ts +241 -52
- package/src/serve/hub-app/inbox-view.tsx +198 -105
- package/src/serve/hub-app/inbox.css +53 -47
- package/src/serve/hub-app/index.html +10 -0
- package/src/serve/hub-app/insights-st.ts +27 -19
- package/src/serve/hub-app/instructions.css +33 -0
- package/src/serve/hub-app/kept-folds.ts +43 -0
- package/src/serve/hub-app/keys.ts +13 -5
- 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 +38 -12
- package/src/serve/hub-app/machines-st.ts +40 -34
- package/src/serve/hub-app/machines-view.tsx +9 -16
- package/src/serve/hub-app/machines.css +0 -9
- package/src/serve/hub-app/markdown.css +128 -0
- package/src/serve/hub-app/md-copy.tsx +18 -40
- package/src/serve/hub-app/md.ts +176 -14
- package/src/serve/hub-app/media-svc.ts +44 -11
- package/src/serve/hub-app/media-view.tsx +2 -2
- package/src/serve/hub-app/messages/messages-page.tsx +57 -12
- package/src/serve/hub-app/messages/messages-st.ts +27 -23
- package/src/serve/hub-app/messages.css +0 -1
- package/src/serve/hub-app/new-thread.tsx +121 -0
- package/src/serve/hub-app/objects.css +52 -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 +8 -5
- package/src/serve/hub-app/page-reload.ts +111 -0
- package/src/serve/hub-app/pages-frames.tsx +12 -1
- package/src/serve/hub-app/pages-svc.ts +8 -3
- package/src/serve/hub-app/palette-st.ts +11 -6
- package/src/serve/hub-app/pane-boundary.tsx +85 -0
- package/src/serve/hub-app/pane-errors.ts +55 -0
- package/src/serve/hub-app/pano.css +20 -0
- package/src/serve/hub-app/plan-view.tsx +4 -3
- package/src/serve/hub-app/planned-st.ts +30 -26
- package/src/serve/hub-app/planned-view.tsx +17 -10
- package/src/serve/hub-app/planned.css +0 -4
- package/src/serve/hub-app/polled.ts +201 -0
- package/src/serve/hub-app/presence-st.ts +110 -0
- package/src/serve/hub-app/processes-view.tsx +3 -2
- package/src/serve/hub-app/project-list.css +101 -66
- package/src/serve/hub-app/project-list.tsx +139 -155
- package/src/serve/hub-app/projects-svc.ts +113 -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/readme.css +9 -15
- 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 +70 -5
- package/src/serve/hub-app/releases/releases-page.tsx +54 -20
- package/src/serve/hub-app/releases/releases-st.ts +39 -26
- package/src/serve/hub-app/releases.css +4 -1
- 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/code-colors.ts +30 -0
- package/src/serve/hub-app/review/cta.tsx +11 -0
- package/src/serve/hub-app/review/diff-view.tsx +77 -0
- package/src/serve/hub-app/review/doc-body.tsx +109 -0
- package/src/serve/hub-app/review/dock.tsx +118 -0
- 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 +239 -0
- package/src/serve/hub-app/review/heard-line.tsx +31 -0
- package/src/serve/hub-app/review/instructions-view.tsx +141 -0
- package/src/serve/hub-app/review/item-verdict.tsx +111 -0
- package/src/serve/hub-app/review/kind-states.tsx +265 -0
- package/src/serve/hub-app/review/kind-view.tsx +23 -44
- package/src/serve/hub-app/review/kit.tsx +54 -75
- package/src/serve/hub-app/review/lane-bar.tsx +64 -0
- 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-card.tsx +62 -0
- package/src/serve/hub-app/review/object-panel.tsx +197 -0
- 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 +387 -0
- package/src/serve/hub-app/review/review-board.tsx +1 -1
- package/src/serve/hub-app/review/review-cells.tsx +223 -184
- 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 +211 -51
- package/src/serve/hub-app/review/review-page.tsx +10 -20
- package/src/serve/hub-app/review/review-st.ts +294 -151
- package/src/serve/hub-app/review/review-thread.tsx +605 -161
- package/src/serve/hub-app/review/review-views.tsx +547 -452
- 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 +134 -0
- package/src/serve/hub-app/review/thread-control-st.ts +2 -1
- package/src/serve/hub-app/review/thread-control.tsx +4 -4
- package/src/serve/hub-app/review/thread-st.ts +710 -140
- package/src/serve/hub-app/review/thread-views.ts +71 -0
- package/src/serve/hub-app/review/{trailer-card.tsx → trailer-body.tsx} +35 -35
- 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 +24 -20
- package/src/serve/hub-app/review/trailer-voices.tsx +3 -2
- package/src/serve/hub-app/review.css +459 -188
- 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 +52 -0
- 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/calendar.tsx +5 -11
- package/src/serve/hub-app/social/comms-page.tsx +36 -20
- package/src/serve/hub-app/social/group-editor.tsx +44 -0
- package/src/serve/hub-app/social/kit.tsx +15 -61
- package/src/serve/hub-app/social/next-release.tsx +5 -7
- package/src/serve/hub-app/social/post-card.tsx +19 -52
- package/src/serve/hub-app/social/post-page.tsx +80 -0
- package/src/serve/hub-app/social/problems.tsx +9 -12
- package/src/serve/hub-app/social/social-model.ts +13 -5
- package/src/serve/hub-app/social/social-page.tsx +4 -4
- package/src/serve/hub-app/social/social-st.ts +67 -83
- 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 +7 -25
- 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/space.css +1 -1
- package/src/serve/hub-app/stores/stores-page.tsx +10 -6
- 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 +136 -0
- package/src/serve/hub-app/time-ago.tsx +40 -16
- package/src/serve/hub-app/time-st.ts +43 -27
- package/src/serve/hub-app/time-view.tsx +4 -3
- package/src/serve/hub-app/time.css +2 -5
- package/src/serve/hub-app/tree-build.ts +2 -2
- package/src/serve/hub-app/tree-row.tsx +44 -27
- 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 +57 -6
- package/src/serve/hub-app/vault.css +2 -0
- package/src/serve/hub-app/veille/veille-page.tsx +5 -14
- package/src/serve/hub-app/veille/veille-st.ts +56 -49
- package/src/serve/hub-app/veille.css +0 -1
- package/src/serve/hub-app/view-layout.css +90 -0
- package/src/serve/hub-app/waiting-svc.ts +5 -4
- package/src/serve/hub-app/when-view.tsx +6 -3
- package/src/serve/hub-app/wiki-st.ts +33 -6
- package/src/serve/hub-app/wikis-view.tsx +22 -18
- package/src/serve/hub-app/words.tsx +15 -0
- package/src/serve/hub-collections.ts +105 -0
- package/src/serve/hub-runtime.ts +83 -91
- package/src/serve/live-hop.ts +102 -0
- package/src/serve/other-repos.ts +1 -1
- package/src/serve/project-gutter-route.ts +69 -46
- 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 +21 -0
- package/src/serve/serve-hub.ts +129 -51
- package/src/serve/terminal-guard.ts +50 -0
- package/src/serve/terminal-route.ts +176 -0
- package/src/shipkit.ts +10 -10
- 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 +6 -5
- package/src/smoke/run-smoke.ts +3 -4
- package/src/social/brands.ts +4 -0
- package/src/social/compose.ts +13 -7
- package/src/social/cover.ts +4 -3
- package/src/social/desk-index.ts +34 -13
- package/src/social/draft-doc.ts +88 -0
- package/src/social/draft-versions.ts +80 -0
- package/src/social/drafts.ts +26 -8
- package/src/social/fit.ts +4 -3
- package/src/social/house.ts +1 -1
- package/src/social/import-drafts.ts +244 -0
- package/src/social/kind-pages.ts +3 -3
- package/src/social/kinds.ts +2 -2
- package/src/social/load.ts +106 -73
- package/src/social/media-facts.ts +1 -19
- package/src/social/media-kind.ts +68 -161
- package/src/social/media-limit.ts +3 -18
- package/src/social/media-of.ts +5 -4
- package/src/social/no-account.ts +38 -0
- package/src/social/open.ts +3 -2
- package/src/social/post-object.ts +120 -0
- package/src/social/post-sources.ts +136 -0
- package/src/social/post-text.ts +123 -0
- package/src/social/posts.ts +433 -0
- package/src/social/presence.ts +17 -13
- package/src/social/publish/index.ts +17 -5
- package/src/social/publish/secret.ts +2 -2
- package/src/social/release-stage.ts +76 -75
- package/src/social/routes.ts +72 -50
- package/src/social/stage.ts +45 -60
- package/src/social/stats.ts +3 -4
- package/src/social/strip.ts +4 -6
- package/src/social/text.ts +6 -4
- package/src/social/thread-drafts.ts +16 -0
- package/src/social/thumbnail.ts +135 -43
- package/src/social/tracker.ts +1 -1
- package/src/social/unit.ts +12 -3
- package/src/social/writes.ts +8 -31
- package/src/start-repo.ts +33 -13
- package/src/stores/desk.ts +17 -12
- package/src/stores/unit.ts +2 -2
- 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 +34 -3
- 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 +2 -2
- 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-http.ts +11 -3
- package/src/vault/vault-import.ts +6 -1
- 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/identity.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/graph-pages.ts +13 -1
- package/src/wiki/run-wiki.ts +4 -1
- package/src/wiki/scan-md.ts +1 -1
- package/src/wiki/serve-graph.ts +2 -3
- package/src/asks/asks-queue.ts +0 -424
- package/src/core/run-fix.ts +0 -120
- package/src/home/hmr-keep.ts +0 -134
- package/src/messages/suggest.ts +0 -96
- package/src/review/draft-card.ts +0 -41
- package/src/serve/hub-app/review/draft-card.tsx +0 -163
- package/src/serve/hub-app/review/note-place.ts +0 -31
- package/src/social/card-drafts.ts +0 -24
- package/src/social/migrate.ts +0 -123
- /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,13 +15,18 @@ 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, 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'
|
|
21
|
+
import { machineDbPath } from '../core/machine-db.ts'
|
|
20
22
|
import { jsonText, revOf } from './rev.ts'
|
|
21
23
|
import { GONE, goneEntryFor } from './gone.ts'
|
|
22
24
|
import {
|
|
23
|
-
|
|
25
|
+
addressOrThrow,
|
|
26
|
+
ANSWER_KINDS,
|
|
27
|
+
type AnswerKind,
|
|
28
|
+
type MessageAsk,
|
|
29
|
+
itemWithdrawOf,
|
|
24
30
|
ownAddressOf,
|
|
25
31
|
partyOf,
|
|
26
32
|
AGENT_RE,
|
|
@@ -34,6 +40,12 @@ import {
|
|
|
34
40
|
isMarkItem,
|
|
35
41
|
itemProblems,
|
|
36
42
|
MESSAGE_FILE_RE,
|
|
43
|
+
MESSAGE_FILES_MAX,
|
|
44
|
+
attachFile,
|
|
45
|
+
cleanFileName,
|
|
46
|
+
isThreadMedia,
|
|
47
|
+
mimeOf,
|
|
48
|
+
type MessageFile,
|
|
37
49
|
MESSAGE_RE,
|
|
38
50
|
messageIdOf,
|
|
39
51
|
messageProblems,
|
|
@@ -53,20 +65,24 @@ import {
|
|
|
53
65
|
updatesOf,
|
|
54
66
|
type UpdateState,
|
|
55
67
|
type GalleryTile,
|
|
56
|
-
type
|
|
68
|
+
type ItemChangelog,
|
|
57
69
|
type Item,
|
|
58
70
|
type Message,
|
|
71
|
+
type Mention,
|
|
72
|
+
mayReadNamed,
|
|
59
73
|
type Op,
|
|
60
74
|
type Origin,
|
|
61
|
-
type Party,
|
|
62
75
|
type Rect,
|
|
63
76
|
type ReviewClip,
|
|
64
77
|
type ReviewFiles,
|
|
65
78
|
type ReviewItem,
|
|
66
79
|
type ReviewMark,
|
|
80
|
+
type ReviewScene,
|
|
67
81
|
type ReviewView,
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
panoRefusal,
|
|
83
|
+
SPACE_EXT,
|
|
84
|
+
type ItemTrailer,
|
|
85
|
+
type ItemDraft,
|
|
70
86
|
type Spec,
|
|
71
87
|
type Subject,
|
|
72
88
|
type Verdict,
|
|
@@ -74,10 +90,32 @@ import {
|
|
|
74
90
|
mediaFilesOf,
|
|
75
91
|
threadMediaOf,
|
|
76
92
|
isGallery,
|
|
93
|
+
diffTypeOf,
|
|
94
|
+
DIFF_TYPES,
|
|
95
|
+
proposeFields,
|
|
96
|
+
type DiffType,
|
|
97
|
+
type MessagePropose,
|
|
98
|
+
type ProposeField,
|
|
99
|
+
type StoredState,
|
|
100
|
+
type AskHead,
|
|
101
|
+
docProblem,
|
|
102
|
+
type ItemDoc,
|
|
77
103
|
} from './model.ts'
|
|
104
|
+
import { kindOfValue, valueKindOf } from './kinds.ts'
|
|
105
|
+
import { askOpen, linesOf, tickText } from './answer-kinds.ts'
|
|
106
|
+
import { isObject, objectOpen } from './supersede.ts'
|
|
107
|
+
import { asksVerdict } from './verdict-items.ts'
|
|
108
|
+
import { SECRET_NAME } from '../secrets/name.ts'
|
|
78
109
|
import { beatRole, roleOf } from './role.ts'
|
|
79
|
-
import { chainOf, coveringHead, followedIds, isFollowed, threadOfAddress } from './threads.ts'
|
|
110
|
+
import { chainOf, coveringHead, followedIds, isFollowed, threadIdOf, threadOfAddress } from './threads.ts'
|
|
80
111
|
import { liveWatchers } from './watchers.ts'
|
|
112
|
+
import { liveUrlRefusal, type ViewLive } from './live-view.ts'
|
|
113
|
+
import { STILLS_LABEL } from './kind-still.ts'
|
|
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'
|
|
81
119
|
|
|
82
120
|
/** the store of a repo */
|
|
83
121
|
export const storeDir = (root: string): string => join(root, LAYOUT.review)
|
|
@@ -97,27 +135,26 @@ let wrote = 0
|
|
|
97
135
|
const renameSync = (a: string, b: string): void => (fs.renameSync(a, b), touched(a), touched(b))
|
|
98
136
|
const rmSync = (p: string, o?: fs.RmOptions): void => (fs.rmSync(p, o), touched(p))
|
|
99
137
|
const copyFileSync = (a: string, b: string): void => (fs.copyFileSync(a, b), touched(b))
|
|
100
|
-
const writeFileSync = (p: string, d: string): void => (fs.writeFileSync(p, d), touched(p))
|
|
101
138
|
const mkdirSync = (p: string, o?: fs.MakeDirectoryOptions): void => (fs.mkdirSync(p, o), touched(p))
|
|
102
139
|
|
|
103
140
|
export { jsonText, revOf }
|
|
104
141
|
|
|
142
|
+
/** the bytes jsonText gives, so the rev of a file is the rev of its value */
|
|
105
143
|
function writeJson(file: string, v: unknown): void {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
renameSync(tmp, file)
|
|
144
|
+
atomicWrite(file, jsonText(v))
|
|
145
|
+
touched(file)
|
|
109
146
|
}
|
|
110
147
|
|
|
111
148
|
/** where the store's operations read and write: the rows of the local copy while the switch cards-in-db is on, else
|
|
112
149
|
* the files. Picked once an operation, so one operation never reads one backend and writes the other */
|
|
113
|
-
const io = (dir: string):
|
|
150
|
+
const io = (dir: string): ItemBackend => (threadsInDb() ? rowsIO(dir) : filesIO(dir))
|
|
114
151
|
|
|
115
|
-
/** the store holds this
|
|
116
|
-
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)
|
|
117
154
|
export const holdsMessage = (dir: string, id: string, mid: string): boolean => io(dir).hasMessage(id, mid)
|
|
118
155
|
|
|
119
|
-
/** the store's files, as they always were: one folder
|
|
120
|
-
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 {
|
|
121
158
|
const folder = (id: string): string => join(dir, id)
|
|
122
159
|
return {
|
|
123
160
|
rows: false,
|
|
@@ -142,25 +179,31 @@ export function filesIO(dir: string): CardBackend {
|
|
|
142
179
|
hasMessage: (id, mid) => existsSync(join(dir, id, 'thread', `${mid}.json`)),
|
|
143
180
|
raw: (id) => readRawFile(dir, id),
|
|
144
181
|
create: (id, tmp, head) => {
|
|
182
|
+
wroteOnLoop()
|
|
145
183
|
writeJson(join(tmp, 'item.json'), head)
|
|
146
|
-
//
|
|
184
|
+
// an item begun while the rows were the store: its folder comes from the spool
|
|
147
185
|
moveFolder(tmp, folder(id))
|
|
148
186
|
touched(tmp)
|
|
149
187
|
touched(folder(id))
|
|
150
188
|
},
|
|
151
189
|
write: (id, head, at) => {
|
|
190
|
+
wroteOnLoop()
|
|
152
191
|
const f = join(dir, id, 'item.json')
|
|
153
192
|
writeJson(f, head)
|
|
154
193
|
if (at !== undefined) fs.utimesSync(f, new Date(at), new Date(at))
|
|
155
194
|
},
|
|
156
195
|
append: (id, m) => {
|
|
196
|
+
wroteOnLoop()
|
|
157
197
|
const t = join(dir, id, 'thread')
|
|
158
198
|
if (!existsSync(t)) mkdirSync(t)
|
|
159
199
|
writeJson(join(t, `${m.id}.json`), m)
|
|
160
200
|
},
|
|
161
|
-
lock: (id, fn, waitMs) =>
|
|
201
|
+
lock: (id, fn, waitMs) => lockedItem(dir, id, fn, waitMs),
|
|
162
202
|
setAside: (id, o) => setAsideFile(dir, id, o),
|
|
163
|
-
keepReplaced: (id, head) =>
|
|
203
|
+
keepReplaced: (id, head) => {
|
|
204
|
+
wroteOnLoop()
|
|
205
|
+
writeJson(join(folder(id), REPLACED), head)
|
|
206
|
+
},
|
|
164
207
|
hasReplaced: (id) => ID_RE.test(id) && existsSync(join(dir, id, REPLACED)),
|
|
165
208
|
stamp: (id) => stampOf(folder(id)),
|
|
166
209
|
folder,
|
|
@@ -174,34 +217,49 @@ export interface ViewInput {
|
|
|
174
217
|
image?: string
|
|
175
218
|
video?: string
|
|
176
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
|
|
177
225
|
before?: string
|
|
178
226
|
after?: string
|
|
179
227
|
/** a list of small images shown as a wrapping grid, each with its label; never the first view */
|
|
180
|
-
gallery?: { file: string; label: string; before?: string; group?: string }[]
|
|
181
|
-
/** 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 */
|
|
182
230
|
note?: string
|
|
231
|
+
/** a live view: the page the hub frames over `image`, its shot (review/live-view.ts) */
|
|
232
|
+
live?: ViewLive
|
|
183
233
|
}
|
|
184
234
|
|
|
235
|
+
/** the most one side of a version of an object weighs, as json */
|
|
236
|
+
const STATE_MAX = 256 * 1024
|
|
237
|
+
|
|
185
238
|
export interface AddInput {
|
|
186
239
|
title: string
|
|
187
240
|
what: string
|
|
188
241
|
/** the public line for a post of it (`--post`); the caller runs the repo's guard on it first */
|
|
189
242
|
post?: string
|
|
190
243
|
/** the change its approval adds to next.md (`--changelog`); the caller runs the repo's guard on it first */
|
|
191
|
-
changelog?:
|
|
244
|
+
changelog?: ItemChangelog
|
|
192
245
|
/** what is judged; a plain shot by default */
|
|
193
246
|
subject?: Subject
|
|
194
247
|
topic?: string
|
|
195
248
|
image?: string
|
|
196
249
|
video?: string
|
|
197
250
|
audio?: string
|
|
251
|
+
pano?: string
|
|
252
|
+
splat?: string
|
|
253
|
+
mesh?: string
|
|
198
254
|
before?: string
|
|
199
255
|
after?: string
|
|
200
256
|
commit?: string
|
|
201
257
|
/** the lane that made it; else SK_AGENT */
|
|
202
258
|
lane?: string
|
|
259
|
+
/** written by the machine (a check run, the reflections queue): no lane and no session, so nobody holds it */
|
|
260
|
+
machine?: true
|
|
203
261
|
supersedes?: string
|
|
204
|
-
/** the raised items (a report, his note) this
|
|
262
|
+
/** the raised items (a report, his note) this version answers, by id */
|
|
205
263
|
answers?: string[]
|
|
206
264
|
/** its subject's address when the agent names it (`--on`): one thread per address */
|
|
207
265
|
on?: string
|
|
@@ -209,7 +267,7 @@ export interface AddInput {
|
|
|
209
267
|
about?: string[]
|
|
210
268
|
/** what a new version of an approved look keeps of it: required then */
|
|
211
269
|
keeps?: string
|
|
212
|
-
/** another subject on purpose, next to an active
|
|
270
|
+
/** another subject on purpose, next to an active version: needs `why` */
|
|
213
271
|
fresh?: boolean
|
|
214
272
|
why?: string
|
|
215
273
|
/** the first view's label, and the other views of the same subject */
|
|
@@ -219,18 +277,30 @@ export interface AddInput {
|
|
|
219
277
|
marks?: ReviewMark[][]
|
|
220
278
|
/** the shots used the review light over a dark place */
|
|
221
279
|
light?: 'review'
|
|
222
|
-
/** a draft
|
|
280
|
+
/** a draft version on a live shot: its image a live frame, no verdict until it is ready */
|
|
223
281
|
wip?: { live: string }
|
|
224
282
|
/** every view is an option he picks one of */
|
|
225
283
|
choice?: boolean
|
|
284
|
+
/** it waits for the owner's verdict (`--verdict`): an opening of words asks it only so, a version always */
|
|
285
|
+
asksVerdict?: true
|
|
226
286
|
/** on a choice: the option the agent suggests, by its label or its letter */
|
|
227
287
|
agentPick?: string
|
|
228
|
-
/** a trailer
|
|
229
|
-
trailer?:
|
|
230
|
-
/** a draft
|
|
231
|
-
draft?:
|
|
232
|
-
/** 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 */
|
|
233
293
|
keep?: boolean
|
|
294
|
+
/** a thread opened with words on its address (`on`): no media, nothing he judges (openThread) */
|
|
295
|
+
opening?: boolean
|
|
296
|
+
/** a version of an object of a kind (`on`): its two states as the kind read them; it holds no view */
|
|
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 }
|
|
300
|
+
/** an ask's facts, on the head of its thread `ask:<id>` (asks/ask-store.ts) */
|
|
301
|
+
ask?: AskHead
|
|
302
|
+
/** a document as the version's subject (`--md`, `--html`); views beside it are allowed */
|
|
303
|
+
doc?: ItemDoc
|
|
234
304
|
now?: Date
|
|
235
305
|
}
|
|
236
306
|
|
|
@@ -243,21 +313,24 @@ interface Loaded {
|
|
|
243
313
|
clip?: { duration: number; fps: number; from: string }
|
|
244
314
|
/** a sound: its length, and the files its waveforms are drawn from (the after's or the one's, then the before's) */
|
|
245
315
|
audio?: { duration: number; from: string; before?: string }
|
|
246
|
-
|
|
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 }[]
|
|
247
320
|
/** the webps made of its pictures, by the name of each in place of its source (`<source>.webp`, no such file) */
|
|
248
321
|
webps?: Map<string, Uint8Array>
|
|
249
322
|
}
|
|
250
323
|
|
|
251
|
-
/** the view's pictures as the
|
|
252
|
-
* 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
|
|
253
326
|
* before, are webps together or stay as given together, so two sides never differ in kind. `always`: a webp whatever
|
|
254
|
-
* 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) */
|
|
255
328
|
async function asWebp(v: Loaded, keep: boolean, always: boolean): Promise<Loaded> {
|
|
256
329
|
if (keep || v.clip || v.audio) return v
|
|
257
330
|
const pics = [...v.sources.map(([, p]) => p), ...(v.tiles ?? []).flatMap((t) => [t.path, ...(t.before ? [t.before] : [])])]
|
|
258
331
|
if (!pics.some(webpable) && !always) return v
|
|
259
332
|
const webps = new Map<string, Uint8Array>()
|
|
260
|
-
/** 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 */
|
|
261
334
|
const group = async (paths: readonly string[]): Promise<string[]> => {
|
|
262
335
|
const made = await Promise.all(paths.map(async (p) => (always ? { bytes: await anyWebp(p) } : await exactWebp(p))))
|
|
263
336
|
if (made.some((m) => 'keep' in m)) return [...paths]
|
|
@@ -284,8 +357,8 @@ async function loadView(v: ViewInput, which: string, o: { keep?: boolean; always
|
|
|
284
357
|
/** a view's files checked and sized, as given */
|
|
285
358
|
async function checkView(v: ViewInput, which: string): Promise<Loaded> {
|
|
286
359
|
if (v.gallery !== undefined) {
|
|
287
|
-
if (v.image !== undefined || v.video !== undefined || v.audio !== undefined || v.before !== undefined || v.after !== undefined)
|
|
288
|
-
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`)
|
|
289
362
|
if (v.gallery.length === 0) throw new Error(`${which}: a gallery needs at least one image`)
|
|
290
363
|
const tiles = await Promise.all(
|
|
291
364
|
v.gallery.map(async (t) => {
|
|
@@ -297,11 +370,13 @@ async function checkView(v: ViewInput, which: string): Promise<Loaded> {
|
|
|
297
370
|
}
|
|
298
371
|
const path = image(t.file)
|
|
299
372
|
const group = t.group?.trim()
|
|
300
|
-
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 } : {}) }
|
|
301
374
|
}),
|
|
302
375
|
)
|
|
303
376
|
return { label: v.label.trim(), sources: [], size: tiles[0]?.size ?? { w: 0, h: 0 }, tiles }
|
|
304
377
|
}
|
|
378
|
+
if (v.pano !== undefined) return checkPano(v, which)
|
|
379
|
+
if (v.splat !== undefined || v.mesh !== undefined) return checkSpace(v, which)
|
|
305
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`)
|
|
306
381
|
const one = v.image ?? v.video ?? v.audio
|
|
307
382
|
const pair = v.before !== undefined || v.after !== undefined
|
|
@@ -351,7 +426,36 @@ async function checkView(v: ViewInput, which: string): Promise<Loaded> {
|
|
|
351
426
|
return { label: v.label.trim(), sources, size: { w: b.w, h: b.h }, clip: { duration: b.duration, fps: b.fps, from: main[1] } }
|
|
352
427
|
}
|
|
353
428
|
|
|
354
|
-
/**
|
|
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 */
|
|
355
459
|
function clipInfo(file: string): { w: number; h: number; duration: number; fps: number } {
|
|
356
460
|
let p: ReturnType<typeof probe>
|
|
357
461
|
try {
|
|
@@ -390,18 +494,32 @@ async function writeWaves(v: Loaded, n: number, folder: string): Promise<void> {
|
|
|
390
494
|
}
|
|
391
495
|
|
|
392
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()}`
|
|
393
499
|
|
|
394
500
|
/** the file name of tile `k` of gallery view `n` */
|
|
395
501
|
const tileName = (n: number, k: number, path: string, side = ''): string => `v${n}-g${k}${side}${extname(path).toLowerCase()}`
|
|
396
502
|
|
|
397
|
-
|
|
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
|
+
|
|
515
|
+
function viewOf(v: Loaded, n: number, marks: readonly ReviewMark[] = [], note?: string, message?: true): ReviewView {
|
|
398
516
|
if (v.tiles)
|
|
399
517
|
return {
|
|
400
518
|
label: v.label,
|
|
401
|
-
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 } : {}) })),
|
|
402
520
|
}
|
|
403
521
|
const audio = v.audio ? { audio: { duration: v.audio.duration, wave: `${prefix(n)}wave.png`, ...(v.audio.before ? { waveBefore: `${prefix(n)}before-wave.png` } : {}) } } : {}
|
|
404
|
-
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() } : {}) }
|
|
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 } : {}) }
|
|
405
523
|
}
|
|
406
524
|
|
|
407
525
|
/** the file names of view `n` in the folder: `image.png` on the first, `v2-before.png` on a later one */
|
|
@@ -418,37 +536,49 @@ async function writePoster(v: Loaded, n: number, folder: string): Promise<void>
|
|
|
418
536
|
renameSync(`${to}.tmp`, to)
|
|
419
537
|
}
|
|
420
538
|
|
|
421
|
-
/** why an active
|
|
539
|
+
/** why an active thread refuses a version that names no address, and every way out */
|
|
422
540
|
function coveredText(c: { head: ReviewItem; by: 'subject' | 'near' | 'title' }): string {
|
|
423
541
|
const r = c.head.item
|
|
424
542
|
const by = c.by === 'subject' ? 'the same subject' : c.by === 'near' ? 'the same topic and a subject near it' : 'a title this close'
|
|
425
543
|
return [
|
|
426
|
-
`one subject is one
|
|
427
|
-
`
|
|
544
|
+
`one subject is one thread: the active thread ${r.id} "${r.title}" (${r.topic ?? 'no topic'}) already covers it, ${by}.`,
|
|
545
|
+
` its next version: sk thread post ${r.id} …`,
|
|
428
546
|
` another angle of it: sk thread add-view ${r.id} "<label>" <image> [<after>]`,
|
|
429
|
-
` truly another subject:
|
|
547
|
+
` truly another subject: sk thread post <kind>:<key> … with its own address`,
|
|
430
548
|
].join('\n')
|
|
431
549
|
}
|
|
432
550
|
|
|
433
551
|
/** the thread a new version goes into (wiki tools/shipkit/threads-store.md, The one thread guard): the one that owns its
|
|
434
|
-
* address. No link given: it supersedes that thread's newest version
|
|
435
|
-
*
|
|
436
|
-
* named. `thread` null: its address has no thread yet,
|
|
552
|
+
* address. No link given: it supersedes that thread's newest version; a thread his note heads takes it in at read time,
|
|
553
|
+
* with no link. It never answers his notes: a version closes one only when its agent names it (`answers`). A link given
|
|
554
|
+
* must be the newest version, else it is refused with the thread named. `thread` null: its address has no thread yet,
|
|
555
|
+
* or it names none (the older guard decides) */
|
|
437
556
|
export function threadLink(
|
|
438
557
|
dir: string,
|
|
439
|
-
|
|
558
|
+
item: Pick<Item, 'subject' | 'on' | 'trailer'>,
|
|
440
559
|
given: { supersedes?: string; answers: readonly string[] },
|
|
441
560
|
spec: Spec = specOf(dir),
|
|
442
|
-
): { thread: string | null; supersedes?: string; answers: string[] } {
|
|
443
|
-
const own = ownAddressOf({ ...
|
|
561
|
+
): { own: string | null; thread: string | null; supersedes?: string; answers: string[] } {
|
|
562
|
+
const own = ownAddressOf({ ...item, origin: { by: 'agent' } } as Item, spec)
|
|
444
563
|
const t = own === null ? null : threadOfAddress(own, readAll(dir).items, spec)
|
|
445
|
-
if (!t) return { thread: null, ...given, answers: [...given.answers] }
|
|
564
|
+
if (!t) return { own, thread: null, ...given, answers: [...given.answers] }
|
|
446
565
|
const head = t.head.item
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
566
|
+
const want = head.origin.by === 'agent' ? head.id : undefined
|
|
567
|
+
if (given.supersedes !== undefined && given.supersedes !== want)
|
|
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`)
|
|
569
|
+
return { own, thread: head.id, ...(want !== undefined ? { supersedes: want } : {}), answers: [...given.answers] }
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** a thread opened with words on an address no thread owns: its head holds the address and a title, no media, and
|
|
573
|
+
* waits on no verdict; the question, the proposed change or the line goes in it next. Refused when a thread owns it */
|
|
574
|
+
export async function openThread(dir: string, address: string, o: { title: string; what?: string; lane?: string; machine?: true; now?: Date; ask?: AskHead; asksVerdict?: true }): Promise<Item> {
|
|
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
|
|
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`)
|
|
577
|
+
const own = threadOfAddress(address, readAll(dir).items, specOf(dir))
|
|
578
|
+
if (own) throw new Error(`${address} already has its thread ${threadIdOf(own)} "${own.head.item.title}": write in it`)
|
|
579
|
+
const first = o.title.trim().split('\n')[0] ?? ''
|
|
580
|
+
const title = first.length > 80 ? `${first.slice(0, 79).trimEnd()}…` : first
|
|
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 } : {}) })
|
|
452
582
|
}
|
|
453
583
|
|
|
454
584
|
/** the Claude Code session that runs this process, null outside one */
|
|
@@ -461,127 +591,182 @@ export const agentName = (): string => process.env.SK_AGENT?.trim() || 'agent'
|
|
|
461
591
|
export async function addItem(dir: string, input: AddInput): Promise<Item> {
|
|
462
592
|
const spec = specOf(dir)
|
|
463
593
|
if (!input.title.trim()) throw new Error('--title: required')
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
const
|
|
594
|
+
// an ask's head holds its facts alone: its words are its instructions, a message (asks/ask-store.ts createAsk)
|
|
595
|
+
if (!input.what.trim() && input.ask === undefined) throw new Error('--what: required, what changed and why')
|
|
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(
|
|
467
598
|
(v) => Object.fromEntries(Object.entries(v).filter(([, x]) => x !== undefined)) as unknown as ViewInput,
|
|
468
599
|
)
|
|
469
|
-
if (input.draft && given.length > 0) throw new Error('--draft: the
|
|
470
|
-
if (given.length
|
|
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')
|
|
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')
|
|
602
|
+
if (input.opening && !input.on) throw new Error('a thread opened with words names its address')
|
|
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')
|
|
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`)
|
|
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>')
|
|
471
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')
|
|
472
614
|
if (input.choice && given.length < 2) throw new Error('--choice: a choice has two options or more, one --view each')
|
|
473
|
-
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')
|
|
474
616
|
const agentPick = input.agentPick === undefined ? undefined : pickIndex(given, input.agentPick)
|
|
475
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}"`))
|
|
476
619
|
const loaded = await Promise.all(given.map((v, i) => loadView(v, i === 0 ? 'the first view' : `--view "${v.label}"`, { keep: input.keep === true })))
|
|
477
620
|
const c = io(dir)
|
|
478
|
-
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}`)
|
|
479
622
|
if (input.supersedes !== undefined && readItem(dir, input.supersedes)?.item.origin.by !== 'agent')
|
|
480
623
|
throw new Error(`--supersedes ${input.supersedes}: a report or a note is answered, never superseded: --answers ${input.supersedes}`)
|
|
481
624
|
const answers = [...new Set(input.answers ?? [])]
|
|
482
625
|
for (const a of answers) {
|
|
483
626
|
const y = ID_RE.test(a) ? readItem(dir, a) : null
|
|
484
627
|
if (!y) throw new Error(`--answers ${a}: no such item in ${dir}`)
|
|
485
|
-
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}`)
|
|
486
629
|
}
|
|
487
630
|
const subject: Subject = input.subject ?? { kind: 'shot' }
|
|
488
631
|
const topic = input.topic?.trim() || undefined
|
|
489
632
|
const wrong = specProblems({ subject, ...(topic ? { topic } : {}) } as Item, spec)
|
|
490
633
|
if (wrong.length > 0) throw new Error(wrong.join('; '))
|
|
491
|
-
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')
|
|
492
635
|
if (input.marks && input.marks.length > given.length) throw new Error(`marks: ${input.marks.length} lists for ${given.length} views`)
|
|
493
|
-
const about = [...new Set((input.about ?? []).map(
|
|
494
|
-
const on = input.on?.trim()
|
|
495
|
-
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
)
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
} else {
|
|
513
|
-
const others = readAll(dir).items.filter((x) => !answers.includes(x.item.id))
|
|
514
|
-
const c = coveringHead({ title: input.title, ...(topic ? { topic } : {}), subject }, others, spec)
|
|
515
|
-
if (c) throw new Error(coveredText(c))
|
|
636
|
+
const about = [...new Set((input.about ?? []).map(addressOrThrow))]
|
|
637
|
+
const on = input.on?.trim() ? addressOrThrow(input.on) : undefined
|
|
638
|
+
if (on?.startsWith('ask:') && input.ask === undefined && !threadOfAddress(on, readAll(dir).items, spec)) throw new Error(`${on}: no ask has this address: an ask is made with sk ask, its thread opened with its facts`)
|
|
639
|
+
const given0 = { ...(input.supersedes !== undefined ? { supersedes: input.supersedes } : {}), answers: [...answers] }
|
|
640
|
+
/** the thread it goes into and the refusals that read the store: asked once before the media are written, so a
|
|
641
|
+
* refusal costs no write, and again under the address's lock, where the version is written */
|
|
642
|
+
const settle = (): { own: string | null; supersedes?: string; answers: string[] } => {
|
|
643
|
+
const link = threadLink(dir, { subject, ...(on ? { on } : {}), ...(input.trailer ? { trailer: input.trailer } : {}) }, given0, spec)
|
|
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) {
|
|
647
|
+
const all = readAll(dir).items
|
|
648
|
+
const old = all.find((x) => x.item.id === link.supersedes)
|
|
649
|
+
const answered = old ? chainOf(old, all).find((x) => verdictOf(x)) : undefined
|
|
650
|
+
const v = answered ? verdictOf(answered) : null
|
|
651
|
+
if (answered && v && isApproved(v.status))
|
|
652
|
+
throw new Error(
|
|
653
|
+
`${answered.item.id} "${answered.item.title}" was approved: an approval locks the look. Keep what he approved, say what stays with --keeps "<what of the approved version stays>", and say the change in --what`,
|
|
654
|
+
)
|
|
516
655
|
}
|
|
656
|
+
// an address decides alone: the older guard reads titles only for a version that names none
|
|
657
|
+
if (link.supersedes === undefined && link.thread === null && link.own === null) {
|
|
658
|
+
if (input.fresh === true) {
|
|
659
|
+
if (!input.why?.trim()) throw new Error('--new needs --why "<reason>": why this is another subject than the active thread next to it')
|
|
660
|
+
} else {
|
|
661
|
+
const others = readAll(dir).items.filter((x) => !link.answers.includes(x.item.id))
|
|
662
|
+
const c = coveringHead({ title: input.title, ...(topic ? { topic } : {}), subject }, others, spec)
|
|
663
|
+
if (c) throw new Error(coveredText(c))
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return link
|
|
517
667
|
}
|
|
518
|
-
const
|
|
668
|
+
const early = settle()
|
|
669
|
+
const lane = input.machine ? undefined : input.lane?.trim() || process.env.SK_AGENT?.trim() || undefined
|
|
519
670
|
if (lane !== undefined && !AGENT_RE.test(lane)) throw new Error(`--lane: « ${lane} » is no lane id (${AGENT_RE.source})`)
|
|
520
671
|
mkdirSync(dir, { recursive: true })
|
|
521
672
|
const now = input.now ?? new Date()
|
|
522
673
|
const base = idOf(now, input.title)
|
|
523
674
|
let id = base
|
|
524
675
|
for (let n = 2; c.taken(id); n++) id = `${base}-${n}`
|
|
525
|
-
const session = sessionId()
|
|
526
|
-
|
|
676
|
+
const session = input.machine ? null : sessionId()
|
|
677
|
+
if (session) noteSession(dir)
|
|
678
|
+
const itemOf =(link: { supersedes?: string; answers: string[] }): Item => ({
|
|
527
679
|
id,
|
|
528
680
|
created: now.toISOString(),
|
|
529
681
|
subject,
|
|
530
682
|
origin: { by: 'agent', ...(lane ? { lane } : {}), ...(session ? { session } : {}) },
|
|
531
683
|
title: input.title.trim(),
|
|
532
|
-
what: input.what.trim(),
|
|
684
|
+
...(input.what.trim() !== '' ? { what: input.what.trim() } : {}),
|
|
533
685
|
...(input.post?.trim() ? { post: input.post.trim() } : {}),
|
|
534
686
|
...(input.changelog ? { changelog: { category: input.changelog.category.trim(), line: input.changelog.line.trim(), ...(input.changelog.rating ? { rating: input.changelog.rating } : {}) } } : {}),
|
|
535
687
|
...(topic ? { topic } : {}),
|
|
536
688
|
...(input.commit ? { commit: input.commit } : {}),
|
|
537
|
-
views: loaded.map((v, n) => viewOf(v, n, input.marks?.[n], given[n]?.note)),
|
|
538
|
-
...(
|
|
539
|
-
...(answers.length > 0 ? { answers } : {}),
|
|
689
|
+
views: loaded.map((v, n) => withLive(viewOf(v, n, input.marks?.[n], given[n]?.note), lives[n])),
|
|
690
|
+
...(link.supersedes ? { supersedes: link.supersedes } : {}),
|
|
691
|
+
...(link.answers.length > 0 ? { answers: link.answers } : {}),
|
|
540
692
|
...(on ? { on } : {}),
|
|
541
693
|
...(about.length > 0 ? { about } : {}),
|
|
542
694
|
...(input.fresh && input.why ? { why: input.why.trim() } : {}),
|
|
543
|
-
...(
|
|
695
|
+
...(link.supersedes && input.keeps?.trim() ? { keeps: input.keeps.trim() } : {}),
|
|
544
696
|
...(input.light ? { light: input.light } : {}),
|
|
545
697
|
...(input.wip ? { wip: { live: input.wip.live, frame: 1 } } : {}),
|
|
546
698
|
...(input.choice ? { choice: true as const } : {}),
|
|
699
|
+
...(input.asksVerdict ? { asksVerdict: true as const } : {}),
|
|
547
700
|
...(agentPick !== undefined ? { agentPick } : {}),
|
|
548
701
|
...(input.trailer ? { trailer: input.trailer } : {}),
|
|
549
702
|
...(input.draft ? { draft: input.draft } : {}),
|
|
550
|
-
|
|
551
|
-
|
|
703
|
+
...(input.states ? { states: input.states } : {}),
|
|
704
|
+
...(input.saved ? { saved: { by: input.saved.by } } : {}),
|
|
705
|
+
...(input.ask ? { ask: input.ask } : {}),
|
|
706
|
+
...(input.doc ? { doc: { kind: input.doc.kind, text: input.doc.text } } : {}),
|
|
707
|
+
})
|
|
708
|
+
const problems = itemProblems(itemOf(early))
|
|
552
709
|
if (problems.length > 0) throw new Error(problems.join('; '))
|
|
553
710
|
const tmp = tmpOf(c, id)
|
|
554
711
|
loaded.forEach((v, n) => copyFiles(v, n, tmp))
|
|
555
712
|
await Promise.all(loaded.map((v, n) => Promise.all([writePoster(v, n, tmp), writeWaves(v, n, tmp)])))
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
|
|
713
|
+
const media = await factsOf(tmp, viewFilesOf(itemOf(early)))
|
|
714
|
+
try {
|
|
715
|
+
// the link read and the version written under one lock: two posts at once on one address make one thread
|
|
716
|
+
return await addressLocked(dir, early.own, () => {
|
|
717
|
+
const head: Item = { ...itemOf(settle()), media }
|
|
718
|
+
createAtCommit(dir, c, id, tmp, head)
|
|
719
|
+
return head
|
|
720
|
+
})
|
|
721
|
+
} catch (e) {
|
|
722
|
+
rmSync(tmp, { recursive: true, force: true })
|
|
723
|
+
throw e
|
|
724
|
+
}
|
|
559
725
|
}
|
|
560
726
|
|
|
561
|
-
/** the
|
|
562
|
-
|
|
727
|
+
/** where the lock of one own address lives: the store's `.locks/` while the items are files (a store per checkout),
|
|
728
|
+
* else beside the machine db, keyed by the repo the rows belong to, so every worktree of a repo takes one lock */
|
|
729
|
+
export function addressLockPath(dir: string, address: string): string {
|
|
730
|
+
const rows = threadsInDb()
|
|
731
|
+
const key = new Bun.CryptoHasher('sha1').update(rows ? `${repoIdOf(dir)}\n${address}` : address).digest('hex').slice(0, 16)
|
|
732
|
+
return join(rows ? join(dirname(machineDbPath()), 'thread-locks') : join(dir, '.locks'), key)
|
|
733
|
+
}
|
|
734
|
+
|
|
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> {
|
|
738
|
+
if (address === null) return fn()
|
|
739
|
+
const at = addressLockPath(dir, address)
|
|
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
|
|
744
|
+
}
|
|
745
|
+
|
|
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 {
|
|
563
748
|
const tmp = join(dirname(c.folder(id)), `.${id}.tmp`)
|
|
564
749
|
rmSync(tmp, { recursive: true, force: true })
|
|
565
750
|
mkdirSync(tmp, { recursive: true })
|
|
566
751
|
return tmp
|
|
567
752
|
}
|
|
568
753
|
|
|
569
|
-
/** where a store's
|
|
570
|
-
* daemon's file (
|
|
571
|
-
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)
|
|
572
757
|
|
|
573
|
-
/** 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
|
|
574
759
|
* move may have turned the switch meanwhile, past its lag. Its id was free in the store it was chosen in */
|
|
575
|
-
function createAtCommit(dir: string, picked:
|
|
760
|
+
function createAtCommit(dir: string, picked: ItemBackend, id: string, tmp: string, head: Item): void {
|
|
576
761
|
const now = io(dir)
|
|
577
|
-
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`)
|
|
578
763
|
now.create(id, tmp, head)
|
|
579
764
|
}
|
|
580
765
|
|
|
581
766
|
/** every file of view `n` into the folder, each as `<name>.tmp` renamed, so no reader sees half of one */
|
|
582
767
|
function copyFiles(v: Loaded, n: number, into: string): void {
|
|
583
768
|
const files = filesOf(v, n) as Record<string, string>
|
|
584
|
-
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]] : [])])]
|
|
585
770
|
for (const [from, name] of copies) {
|
|
586
771
|
const to = join(into, name)
|
|
587
772
|
putFile(v, from, `${to}.tmp`)
|
|
@@ -600,12 +785,12 @@ function putFile(v: Loaded, from: string, to: string): void {
|
|
|
600
785
|
/** the command that posts an update, as a refusal names it */
|
|
601
786
|
const updateLine = (id: string): string => `sk thread update ${id} <${UPDATE_STATES.join('|')}> "<one line>" <file> | <before> <after>`
|
|
602
787
|
|
|
603
|
-
/** 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
|
|
604
789
|
* update (`update`), which goes on at any time */
|
|
605
|
-
export async function addView(dir: string, id: string, v: ViewInput, o: { marks?: ReviewMark[]; light?: 'review';
|
|
790
|
+
export async function addView(dir: string, id: string, v: ViewInput, o: { marks?: ReviewMark[]; light?: 'review'; message?: true; keep?: boolean } = {}): Promise<Item> {
|
|
606
791
|
const x = readItem(dir, id)
|
|
607
|
-
if (!x) throw new Error(`no
|
|
608
|
-
if (verdictOf(x) && !o.
|
|
792
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
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}`)
|
|
609
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`)
|
|
610
795
|
if (!v.label.trim()) throw new Error('add-view: the view needs its label')
|
|
611
796
|
const loaded = await loadView(v, `the view "${v.label}"`, { keep: o.keep === true })
|
|
@@ -616,7 +801,7 @@ export async function addView(dir: string, id: string, v: ViewInput, o: { marks?
|
|
|
616
801
|
copyFiles(loaded, n, folder)
|
|
617
802
|
await writePoster(loaded, n, folder)
|
|
618
803
|
await writeWaves(loaded, n, folder)
|
|
619
|
-
const view = viewOf(loaded, n, o.marks, v.note)
|
|
804
|
+
const view = viewOf(loaded, n, o.marks, v.note, o.message)
|
|
620
805
|
const facts = await factsOf(folder, viewFilesOf({ ...x.item, views: [view] }))
|
|
621
806
|
return updateHead(dir, id, (cur) => {
|
|
622
807
|
if (cur.views.length !== n) throw new Error(`${id}: another view landed while this one was written: add it again`)
|
|
@@ -624,6 +809,50 @@ export async function addView(dir: string, id: string, v: ViewInput, o: { marks?
|
|
|
624
809
|
})
|
|
625
810
|
}
|
|
626
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
|
+
|
|
627
856
|
/** the option the agent suggests, by its label or its letter; throws naming every option */
|
|
628
857
|
function pickIndex(views: readonly { label: string }[], ref: string, flag = '--pick'): number {
|
|
629
858
|
try {
|
|
@@ -633,12 +862,12 @@ function pickIndex(views: readonly { label: string }[], ref: string, flag = '--p
|
|
|
633
862
|
}
|
|
634
863
|
}
|
|
635
864
|
|
|
636
|
-
/** 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 */
|
|
637
866
|
export function setAgentPick(dir: string, id: string, ref: string): Item {
|
|
638
867
|
const x = readItem(dir, id)
|
|
639
|
-
if (!x) throw new Error(`no
|
|
868
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
640
869
|
if (verdictOf(x)) throw new Error(`${id} has his answer already: the pick shows what was suggested, never rewritten after`)
|
|
641
|
-
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`)
|
|
642
871
|
const n = pickIndex(x.item.views, ref, 'pick')
|
|
643
872
|
return updateHead(dir, id, (cur) => ({ ...cur, agentPick: n }))
|
|
644
873
|
}
|
|
@@ -648,7 +877,7 @@ export function updateHead(dir: string, id: string, fn: (cur: Item) => Item): It
|
|
|
648
877
|
const c = io(dir)
|
|
649
878
|
return c.lock(id, () => {
|
|
650
879
|
const held = c.head(id)
|
|
651
|
-
if (held == null) throw Object.assign(new Error(`no
|
|
880
|
+
if (held == null) throw Object.assign(new Error(`no item ${id}`), { code: 'ENOENT' })
|
|
652
881
|
const next = fn(held.head as Item)
|
|
653
882
|
const problems = itemProblems(next)
|
|
654
883
|
if (problems.length > 0) throw new Error(problems.join('; '))
|
|
@@ -657,16 +886,16 @@ export function updateHead(dir: string, id: string, fn: (cur: Item) => Item): It
|
|
|
657
886
|
})
|
|
658
887
|
}
|
|
659
888
|
|
|
660
|
-
/** the ids of a store's
|
|
661
|
-
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))
|
|
662
891
|
|
|
663
|
-
/**
|
|
664
|
-
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)
|
|
665
894
|
|
|
666
|
-
/**
|
|
895
|
+
/** an item's head as it is stored, and the time it was written; null with no head */
|
|
667
896
|
export const rawHead = (dir: string, id: string): { head: unknown; at: number } | null => io(dir).head(id)
|
|
668
897
|
|
|
669
|
-
/** the ids of
|
|
898
|
+
/** the ids of an item's messages, oldest first */
|
|
670
899
|
export const threadIds = (dir: string, id: string): string[] => (ID_RE.test(id) ? io(dir).threadIds(id) : [])
|
|
671
900
|
|
|
672
901
|
/** one message as it is stored */
|
|
@@ -674,17 +903,17 @@ export const rawMessage = (dir: string, id: string, mid: string): unknown => io(
|
|
|
674
903
|
|
|
675
904
|
export type LandedFile = { did: 'landed' | 'same' | 'kept'; why?: string }
|
|
676
905
|
|
|
677
|
-
/** the longest
|
|
906
|
+
/** the longest item or message id an item carried between machines may have: a folder or file name of about 120
|
|
678
907
|
* characters fits every file system, with its `.tmp` and `.land-<pid>` beside it */
|
|
679
908
|
export const MAX_ID_LENGTH = 120
|
|
680
909
|
|
|
681
|
-
/** 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,
|
|
682
911
|
* an existing one rewritten under its lock once `keep` (given the head as the file says now) has no reason to keep
|
|
683
912
|
* it. A head that is no item of that id is kept out. `dry` says what it would do */
|
|
684
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 {
|
|
685
|
-
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` }
|
|
686
915
|
const problems = itemProblems(head)
|
|
687
|
-
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'})` }
|
|
688
917
|
const c = io(dir)
|
|
689
918
|
const folder = c.folder(id)
|
|
690
919
|
const decide = (cur: Item): LandedFile | null => {
|
|
@@ -694,7 +923,7 @@ export function landHead(dir: string, id: string, head: unknown, o: { keep: (cur
|
|
|
694
923
|
}
|
|
695
924
|
if (!c.has(id)) {
|
|
696
925
|
if (o.dry) return { did: 'landed' }
|
|
697
|
-
// the rows land a new
|
|
926
|
+
// the rows land a new item under the lock below, in one transaction
|
|
698
927
|
if (!c.rows && !c.taken(id)) {
|
|
699
928
|
mkdirSync(dir, { recursive: true })
|
|
700
929
|
const tmp = join(dir, `.${id}.land-${process.pid}`)
|
|
@@ -705,7 +934,7 @@ export function landHead(dir: string, id: string, head: unknown, o: { keep: (cur
|
|
|
705
934
|
renameSync(tmp, folder)
|
|
706
935
|
return { did: 'landed' }
|
|
707
936
|
} catch {
|
|
708
|
-
//
|
|
937
|
+
// an item of that id came meanwhile: its lock decides below
|
|
709
938
|
rmSync(tmp, { recursive: true, force: true })
|
|
710
939
|
}
|
|
711
940
|
}
|
|
@@ -730,7 +959,7 @@ export function landHead(dir: string, id: string, head: unknown, o: { keep: (cur
|
|
|
730
959
|
...(aside ? [`a head made apart replaced this machine's, which is kept beside it as ${REPLACED}`] : []),
|
|
731
960
|
...(moved.length > 0 ? [`this machine's files of the names the landing head gives to other bytes are kept as ${moved.join(', ')}`] : []),
|
|
732
961
|
]
|
|
733
|
-
return said.length > 0 ? { did: 'landed', why: `
|
|
962
|
+
return said.length > 0 ? { did: 'landed', why: `item ${id}: ${said.join('; ')}` } : { did: 'landed' }
|
|
734
963
|
}, o.waitMs)
|
|
735
964
|
}
|
|
736
965
|
|
|
@@ -759,20 +988,20 @@ function setAsideClashes(folder: string, head: Item): string[] {
|
|
|
759
988
|
return moved
|
|
760
989
|
}
|
|
761
990
|
|
|
762
|
-
/** does that
|
|
991
|
+
/** does that item keep a head a landing replaced */
|
|
763
992
|
export const hasReplaced = (dir: string, id: string): boolean => ID_RE.test(id) && io(dir).hasReplaced(id)
|
|
764
993
|
|
|
765
|
-
/** a message made on another machine written into its
|
|
766
|
-
* while the
|
|
767
|
-
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' } {
|
|
768
997
|
const mid = m != null && typeof m === 'object' ? (m as { id?: unknown }).id : undefined
|
|
769
998
|
const problems = typeof mid === 'string' && MESSAGE_RE.test(mid) ? messageProblems(m, mid) : ['no message id']
|
|
770
|
-
if (id.length > MAX_ID_LENGTH || (typeof mid === 'string' && mid.length > MAX_ID_LENGTH)) return { did: 'kept', why: `a message of
|
|
771
|
-
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'}` }
|
|
772
1001
|
const c = io(dir)
|
|
773
|
-
if (!c.has(id)) return { did: 'no-
|
|
1002
|
+
if (!c.has(id)) return { did: 'no-item' }
|
|
774
1003
|
// one id is made on two machines only by one party in one millisecond: the one here stays, and it is said
|
|
775
|
-
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` }
|
|
776
1005
|
if (o.dry) return { did: 'landed' }
|
|
777
1006
|
c.append(id, m as Message)
|
|
778
1007
|
return { did: 'landed' }
|
|
@@ -813,15 +1042,15 @@ export function readItem(dir: string, id: string): ReviewItem | null {
|
|
|
813
1042
|
/** one item as it is stored, whatever the unit: what the index keeps */
|
|
814
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)
|
|
815
1044
|
|
|
816
|
-
/**
|
|
1045
|
+
/** an item this process misses while a move runs: a process that read the switch before it turned made it on the side
|
|
817
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 */
|
|
818
1047
|
function healed(dir: string, id: string): boolean {
|
|
819
|
-
if (!
|
|
1048
|
+
if (!threadsMoving()) return false
|
|
820
1049
|
const c = io(dir)
|
|
821
1050
|
const other = c.rows ? filesIO(dir) : rowsIO(dir)
|
|
822
1051
|
if (!other.has(id)) return false
|
|
823
|
-
const {
|
|
824
|
-
|
|
1052
|
+
const { carryItem } = require('./move.ts') as typeof import('./move.ts')
|
|
1053
|
+
carryItem(dir, id, other, c)
|
|
825
1054
|
return c.has(id)
|
|
826
1055
|
}
|
|
827
1056
|
|
|
@@ -859,15 +1088,22 @@ function readThread(dir: string, id: string): Message[] {
|
|
|
859
1088
|
}
|
|
860
1089
|
|
|
861
1090
|
/** appends one message to an item's thread, its image copied in beside it; the id never collides */
|
|
862
|
-
export function appendMessage(dir: string, id: string, m: Omit<Message, 'id' | 'at'>, o: { image?: string; now?: Date } = {}): 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 {
|
|
863
1092
|
const now = o.now ?? new Date()
|
|
864
1093
|
if (o.image !== undefined) {
|
|
865
1094
|
if (!existsSync(o.image)) throw new Error(`${o.image}: no such file`)
|
|
866
1095
|
if (!IMAGE_EXT.test(extname(o.image).toLowerCase())) throw new Error(`${o.image}: a png, jpg or webp`)
|
|
867
1096
|
}
|
|
868
|
-
|
|
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
|
|
869
1105
|
const c = io(dir)
|
|
870
|
-
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}`)
|
|
871
1107
|
const folder = join(c.folder(id), 'thread')
|
|
872
1108
|
const base = messageIdOf(now, m.who)
|
|
873
1109
|
let n = 1
|
|
@@ -879,8 +1115,15 @@ export function appendMessage(dir: string, id: string, m: Omit<Message, 'id' | '
|
|
|
879
1115
|
mkdirSync(folder, { recursive: true })
|
|
880
1116
|
copyFileSync(o.image, join(folder, file))
|
|
881
1117
|
}
|
|
882
|
-
const
|
|
883
|
-
|
|
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))
|
|
1124
|
+
const session = !o.machine && partyOf(m.who) === 'agent' && m.session === undefined ? sessionId() : null
|
|
1125
|
+
if (session) noteSession(dir)
|
|
1126
|
+
const out: Message = { id: mid, at: now.toISOString(), ...m, ...(session ? { session } : {}), ...(file ? { image: file } : {}), ...(files.length > 0 ? { files } : {}) }
|
|
884
1127
|
try {
|
|
885
1128
|
c.append(id, out)
|
|
886
1129
|
return out
|
|
@@ -894,45 +1137,167 @@ export function appendMessage(dir: string, id: string, m: Omit<Message, 'id' | '
|
|
|
894
1137
|
|
|
895
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
|
|
896
1139
|
* item it answers (his hint on an update); throws with the reason */
|
|
897
|
-
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 {
|
|
898
1141
|
const x = readItem(dir, id)
|
|
899
|
-
if (!x) throw new Error(`no
|
|
900
|
-
|
|
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)
|
|
901
1146
|
if ('error' in t) throw new Error(t.error)
|
|
902
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}`)
|
|
903
|
-
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 })
|
|
904
1149
|
}
|
|
905
1150
|
|
|
906
|
-
/**
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
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 */
|
|
1152
|
+
export interface AskOption {
|
|
1153
|
+
label: string
|
|
1154
|
+
files?: readonly string[]
|
|
1155
|
+
}
|
|
1156
|
+
|
|
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
|
|
1158
|
+
* option it picks; each option's media becomes a view the message holds (addView `message`), and the owner answers in
|
|
1159
|
+
* one click (answerAsk) */
|
|
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> {
|
|
1161
|
+
const x = readItem(dir, id)
|
|
1162
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
910
1163
|
const t = textOf(q.text)
|
|
911
1164
|
if ('error' in t) throw new Error(`the question: ${t.error.replace(/^text: /, '')}`)
|
|
912
|
-
const
|
|
1165
|
+
const kind = q.kind ?? 'choice'
|
|
1166
|
+
if (!ANSWER_KINDS.includes(kind)) throw new Error(`a question's kind: one of ${ANSWER_KINDS.join(', ')}`)
|
|
1167
|
+
const replaces = { ...(q.replaces !== undefined ? { replaces: q.replaces } : {}), ...(q.step !== undefined ? { step: q.step } : {}) }
|
|
1168
|
+
if (kind !== 'choice') return appendMessage(dir, id, { who: q.who, text: t.text, ask: kindAsk(dir, x, kind, q), ...replaces }, q.now ? { now: q.now } : {})
|
|
1169
|
+
if (q.options === undefined) throw new Error('a question offers two options or more: --option "<a>" --option "<b>"')
|
|
1170
|
+
const options = q.options.map((o) => (typeof o === 'string' ? { label: o } : o)).map((o) => ({ ...o, label: o.label.trim() })).filter((o) => o.label !== '' || (o.files?.length ?? 0) > 0)
|
|
913
1171
|
if (options.length < 2) throw new Error('a question offers two options or more: --option "<a>" --option "<b>"')
|
|
914
1172
|
if (q.pick !== undefined && !(Number.isInteger(q.pick) && q.pick >= 0 && q.pick < options.length)) throw new Error(`--pick: an option's number, 1 to ${options.length}`)
|
|
915
|
-
|
|
1173
|
+
for (const f of options.flatMap((o) => o.files ?? [])) if (!existsSync(f)) throw new Error(`${f}: no such file`)
|
|
1174
|
+
const labels = options.map((o, i) => o.label || basename(o.files![o.files!.length - 1]!).replace(/\.[^.]+$/, '') || `option ${i + 1}`)
|
|
1175
|
+
const views: (number | null)[] = []
|
|
1176
|
+
for (const [i, o] of options.entries()) {
|
|
1177
|
+
if (!o.files?.length) {
|
|
1178
|
+
views.push(null)
|
|
1179
|
+
continue
|
|
1180
|
+
}
|
|
1181
|
+
const item = await addView(dir, id, filesView(labels[i]!, o.files, `option ${i + 1}: one file, or a before and an after`), { message: true })
|
|
1182
|
+
views.push(item.views.length - 1)
|
|
1183
|
+
}
|
|
1184
|
+
const media = views.some((v) => v !== null) ? { views } : {}
|
|
1185
|
+
return appendMessage(dir, id, { who: q.who, text: t.text, ask: { options: labels, ...(q.pick !== undefined ? { pick: q.pick } : {}), ...media }, ...replaces }, q.now ? { now: q.now } : {})
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/** the longest text or url he answers with */
|
|
1189
|
+
export const ANSWER_VALUE_MAX = 20_000
|
|
1190
|
+
|
|
1191
|
+
export const isWebUrl = (s: string): boolean => {
|
|
1192
|
+
try {
|
|
1193
|
+
const u = new URL(s)
|
|
1194
|
+
return (u.protocol === 'https:' || u.protocol === 'http:') && u.hostname !== ''
|
|
1195
|
+
} catch {
|
|
1196
|
+
return false
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/** a question of another kind than a choice, as the store keeps it: a checklist's lines (words alone, no media), a
|
|
1201
|
+
* secret's name; a secret is refused on an object whose kind frames a page, which shares the hub's origin
|
|
1202
|
+
* (wiki tools/shipkit/threads-asks.md, The secret field) */
|
|
1203
|
+
function kindAsk(dir: string, x: ReviewItem, kind: AnswerKind, q: { options?: readonly (string | AskOption)[]; secret?: { name: string; login?: boolean }; done?: readonly number[] }): MessageAsk {
|
|
1204
|
+
if (kind === 'checklist') {
|
|
1205
|
+
const lines = (q.options ?? []).map((o) => (typeof o === 'string' ? o : o.label).replace(/\s+/g, ' ').trim())
|
|
1206
|
+
if (lines.length === 0 || lines.some((l) => l === '')) throw new Error('a checklist holds one line or more, each words: --checklist "<step>" …')
|
|
1207
|
+
if ((q.options ?? []).some((o) => typeof o !== 'string' && (o.files?.length ?? 0) > 0)) throw new Error('a checklist line is words: a picture goes as its own message before it')
|
|
1208
|
+
const done = [...new Set(q.done ?? [])].sort((a, b) => a - b)
|
|
1209
|
+
if (done.some((i) => !Number.isInteger(i) || i < 0 || i >= lines.length)) throw new Error(`a line done: one of 0 to ${lines.length - 1}`)
|
|
1210
|
+
return { kind, options: lines, ...(done.length > 0 ? { done } : {}) }
|
|
1211
|
+
}
|
|
1212
|
+
if ((q.options ?? []).length > 0) throw new Error(`a ${kind} question holds no options: --option goes with a choice`)
|
|
1213
|
+
if (kind !== 'secret') return { kind, options: [] }
|
|
1214
|
+
const name = q.secret?.name.trim() ?? ''
|
|
1215
|
+
if (!SECRET_NAME.test(name)) throw new Error(`--secret: ${name === '' ? 'the secret\'s name' : `${name} is no secret name`} (letters, digits, . _ @ / -, no leading dash), as the registry names it: rv/<service>/<what>`)
|
|
1216
|
+
const spec = specOf(dir)
|
|
1217
|
+
const own = ownAddressOf(x.item, spec)
|
|
1218
|
+
const def = own == null ? undefined : spec.kinds[own.slice(0, own.indexOf(':'))]
|
|
1219
|
+
if (def?.view !== undefined || def?.diff?.page !== undefined)
|
|
1220
|
+
throw new Error(`--secret on ${own}: its kind frames a page of the repo in the hub, and a secret field never sits beside one; ask it on the ask's own thread, ask:<id> (wiki tools/shipkit/threads-asks.md, The secret field)`)
|
|
1221
|
+
return { kind, options: [], secret: { name, ...(q.secret?.login ? { login: true as const } : {}) } }
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/** one field of a proposed change as an agent sends it: its key (empty for a change of one), its values, how it draws */
|
|
1225
|
+
export interface ProposeInput {
|
|
1226
|
+
key?: string
|
|
1227
|
+
before?: string
|
|
1228
|
+
after: string
|
|
1229
|
+
type?: DiffType
|
|
1230
|
+
lang?: string
|
|
916
1231
|
}
|
|
917
1232
|
|
|
918
|
-
/** an agent's proposed change of an object
|
|
919
|
-
* agent lands what he applied
|
|
920
|
-
|
|
1233
|
+
/** an agent's proposed change of an object, one field or several: the owner applies each field alone, as it is or
|
|
1234
|
+
* after the owner's edit (answerAsk), and the agent lands what he applied. A field draws as the agent names it, else as the
|
|
1235
|
+
* object's kind declares (`diff`), else as its values read; a sound field's two files become a view the message holds */
|
|
1236
|
+
export async function postPropose(dir: string, id: string, p: { who: string; text: unknown; on: string; fields: readonly ProposeInput[]; now?: Date; replaces?: string }): Promise<Message> {
|
|
921
1237
|
if (!readItem(dir, id)) throw new Error(`no item ${id}`)
|
|
922
|
-
|
|
923
|
-
if (p.
|
|
924
|
-
const
|
|
1238
|
+
const on = addressOrThrow(p.on)
|
|
1239
|
+
if (p.fields.length === 0) throw new Error('--after: the value it proposes')
|
|
1240
|
+
const many = p.fields.length > 1
|
|
1241
|
+
const keys = p.fields.map((f) => f.key?.trim() ?? '')
|
|
1242
|
+
if (many && keys.some((k) => k === '')) throw new Error('a change of several fields names each: --field <key> before its --before and --after')
|
|
1243
|
+
if (new Set(keys).size !== keys.length) throw new Error(`each field once: ${keys.filter((k, i) => keys.indexOf(k) !== i).join(', ')} twice`)
|
|
1244
|
+
const kind = specOf(dir).kinds[on.slice(0, on.indexOf(':'))]?.diff
|
|
1245
|
+
const fields: ProposeField[] = []
|
|
1246
|
+
for (const [i, f] of p.fields.entries()) {
|
|
1247
|
+
const key = keys[i]!
|
|
1248
|
+
if (f.after.trim() === '') throw new Error(`${key ? `--field ${key}: ` : ''}--after: the value it proposes`)
|
|
1249
|
+
if (f.type !== undefined && !DIFF_TYPES.includes(f.type)) throw new Error(`${key ? `--field ${key}: ` : ''}--type: one of ${DIFF_TYPES.join(', ')}`)
|
|
1250
|
+
const declared = kind?.fields?.[key] !== undefined ? valueKindOf(kind.fields[key]!) : null
|
|
1251
|
+
const type: DiffType = f.type ?? declared?.type ?? (f.lang ? 'code' : diffTypeOf(f))
|
|
1252
|
+
const lang = f.lang ?? (type === 'code' ? declared?.lang : undefined)
|
|
1253
|
+
let view: number | undefined
|
|
1254
|
+
if (kindOfValue(type).file) {
|
|
1255
|
+
const files = [...(f.before !== undefined ? [f.before] : []), f.after]
|
|
1256
|
+
for (const x of files) if (!existsSync(x)) throw new Error(`${key ? `--field ${key}: ` : ''}${x}: no such file (a ${kindOfValue(type).label} field takes its files)`)
|
|
1257
|
+
const item = await addView(dir, id, filesView(key || kindOfValue(type).label, files, `a ${kindOfValue(type).label} field: one file, or a before and an after`), { message: true })
|
|
1258
|
+
view = item.views.length - 1
|
|
1259
|
+
}
|
|
1260
|
+
fields.push({ key, after: f.after, ...(f.before !== undefined ? { before: f.before } : {}), ...(type !== 'text' ? { type } : {}), ...(type === 'code' && lang ? { lang } : {}), ...(view !== undefined ? { view } : {}) })
|
|
1261
|
+
}
|
|
1262
|
+
const t = textOf(p.text ?? `a change of ${on}`)
|
|
925
1263
|
if ('error' in t) throw new Error(t.error)
|
|
926
|
-
|
|
1264
|
+
const { key: _key, ...flat } = fields[0]!
|
|
1265
|
+
// one field keeps its key when it names one: an object's kind applies it by that name (review/kind-apply.ts)
|
|
1266
|
+
const propose: MessagePropose = many ? { on, after: fields.map((f) => `${f.key}: ${f.after}`).join('\n'), fields } : keys[0] ? { on, ...flat, fields } : { on, ...flat }
|
|
1267
|
+
if (kind?.page) propose.page = kind.page
|
|
1268
|
+
return appendMessage(dir, id, { who: p.who, text: t.text, propose, ...(p.replaces !== undefined ? { replaces: p.replaces } : {}) }, p.now ? { now: p.now } : {})
|
|
927
1269
|
}
|
|
928
1270
|
|
|
929
|
-
/** the owner's answer to a question (an option) or to a proposed change (apply, the
|
|
930
|
-
|
|
1271
|
+
/** the owner's answer to a question (an option) or to a proposed change (apply one field, the value as proposed or the owner's
|
|
1272
|
+
* edit of it in `value`), with the owner's words */
|
|
1273
|
+
export function answerAsk(dir: string, id: string, a: { re: string; option?: number; apply?: boolean; field?: string; value?: string; text?: string; tick?: boolean; pick?: number; opens?: number; now?: Date }): Message {
|
|
931
1274
|
const x = readItem(dir, id)
|
|
932
1275
|
if (!x) throw new Error(`no item ${id}`)
|
|
933
1276
|
const m = x.thread.find((y) => y.id === a.re)
|
|
934
1277
|
if (!m || (m.ask === undefined && m.propose === undefined)) throw new Error(`re: ${a.re} is no question nor proposed change of ${id}`)
|
|
935
1278
|
const words = a.text?.trim() ?? ''
|
|
1279
|
+
const at = a.now ? { now: a.now } : {}
|
|
1280
|
+
const kind = m.ask?.kind ?? 'choice'
|
|
1281
|
+
if (m.ask && kind === 'secret') throw new Error('a secret is typed into its own field of the hub, and its value never goes into a thread')
|
|
1282
|
+
if (m.ask && kind === 'file') throw new Error('a file question is answered by the file he drops')
|
|
1283
|
+
if (m.ask && (kind === 'checklist' || kind === 'confirm')) {
|
|
1284
|
+
const lines = linesOf(m)
|
|
1285
|
+
const o = kind === 'confirm' ? 0 : a.option
|
|
1286
|
+
if (o === undefined || !Number.isInteger(o) || o < 0 || o >= lines.length) throw new Error(`option: the line, one of 0 to ${lines.length - 1}`)
|
|
1287
|
+
const tick = a.tick ?? true
|
|
1288
|
+
const choice = m.ask.choices?.[o] ?? null
|
|
1289
|
+
if (a.pick !== undefined && choice === null) throw new Error(`pick: the step « ${lines[o]} » holds no choice`)
|
|
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`)
|
|
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)
|
|
1292
|
+
}
|
|
1293
|
+
if (m.ask && (kind === 'text' || kind === 'url')) {
|
|
1294
|
+
const value = a.value?.trim() ?? ''
|
|
1295
|
+
if (value === '') throw new Error(`value: the ${kind} he gives`)
|
|
1296
|
+
if (value.length > ANSWER_VALUE_MAX) throw new Error(`value: at most ${ANSWER_VALUE_MAX} characters`)
|
|
1297
|
+
if (kind === 'url' && !isWebUrl(value)) throw new Error('value: a link that starts with http:// or https://')
|
|
1298
|
+
const opens = kind === 'url' && a.opens !== undefined && Number.isInteger(a.opens) && a.opens >= 0 ? { opens: a.opens } : {}
|
|
1299
|
+
return appendMessage(dir, id, { who: 'owner', re: a.re, answer: { value, ...opens }, text: words === '' ? value : words }, at)
|
|
1300
|
+
}
|
|
936
1301
|
if (m.ask) {
|
|
937
1302
|
const o = a.option
|
|
938
1303
|
if (o === undefined || !Number.isInteger(o) || o < 0 || o >= m.ask.options.length) throw new Error(`option: one of 0 to ${m.ask.options.length - 1}`)
|
|
@@ -940,14 +1305,51 @@ export function answerAsk(dir: string, id: string, a: { re: string; option?: num
|
|
|
940
1305
|
return appendMessage(dir, id, { who: 'owner', re: a.re, answer: { option: o }, text: words === '' ? label : `${label}: ${words}` }, a.now ? { now: a.now } : {})
|
|
941
1306
|
}
|
|
942
1307
|
if (a.apply !== true) throw new Error('a proposed change is answered by apply, or by a reply')
|
|
943
|
-
|
|
1308
|
+
const fields = proposeFields(m.propose!)
|
|
1309
|
+
const named = a.field === undefined || a.field === '' ? undefined : a.field
|
|
1310
|
+
if (named === undefined && fields.length > 1) throw new Error(`field: one of ${fields.map((y) => y.key).join(', ')}; « apply all » is one answer a field`)
|
|
1311
|
+
const f = named === undefined ? fields[0]! : fields.find((y) => y.key === named)
|
|
1312
|
+
if (!f) throw new Error(`field: one of ${fields.map((y) => y.key).join(', ')}`)
|
|
1313
|
+
const value = a.value !== undefined && a.value.trim() !== '' ? a.value : f.after
|
|
1314
|
+
return appendMessage(dir, id, { who: 'owner', re: a.re, answer: { apply: true, ...(named !== undefined ? { field: named } : {}), value }, text: words === '' ? value : words }, a.now ? { now: a.now } : {})
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
/** the open secret question `re` of item `id`, or why there is none; its name and whether an account goes with it */
|
|
1318
|
+
export function secretQuestion(dir: string, id: string, re: string, o: { again?: true } = {}): { name: string; login: boolean; open: boolean; at: number } | { error: string } {
|
|
1319
|
+
const x = readItem(dir, id)
|
|
1320
|
+
const m = x?.thread.find((y) => y.id === re)
|
|
1321
|
+
if (!x || !m || m.ask?.kind !== 'secret' || !m.ask.secret) return { error: `${re} is no secret question of ${id}` }
|
|
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) }
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
/** the owner's answer to a secret question once its value is in the house secret manager: the name and the time, never
|
|
1329
|
+
* the value, which this function never sees */
|
|
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 } : {})
|
|
1332
|
+
if ('error' in q) throw new Error(q.error)
|
|
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 } : {})
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
/** the owner's click on one of the kind's actions on the thread's object: a message the holder's watch prints */
|
|
1338
|
+
export function postAction(dir: string, id: string, a: { name: string; text?: string; re?: string; now?: Date }): Message {
|
|
1339
|
+
const x = readItem(dir, id)
|
|
1340
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
1341
|
+
if (!/^[a-z][a-z0-9-]*$/.test(a.name)) throw new Error(`action: ${a.name} is no action name`)
|
|
1342
|
+
// `re`: the link of an object in the thread the action is on (a reflection's box), so the box reads its own answer
|
|
1343
|
+
if (a.re !== undefined && !x.thread.some((m) => m.id === a.re && m.about !== undefined)) throw new Error(`re: ${a.re} is no link of ${id}`)
|
|
1344
|
+
const words = a.text?.trim() ?? ''
|
|
1345
|
+
return appendMessage(dir, id, { who: 'owner', action: { name: a.name }, text: words === '' ? a.name : words, ...(a.re !== undefined ? { re: a.re } : {}) }, a.now ? { now: a.now } : {})
|
|
944
1346
|
}
|
|
945
1347
|
|
|
946
1348
|
/** a link from a thread to another object: the thread names it, the object's thread control finds the thread */
|
|
947
|
-
export function attachTo(dir: string, id: string, who: string, address: string, now = new Date()): Message {
|
|
1349
|
+
export function attachTo(dir: string, id: string, who: string, address: string, now = new Date(), o: { asksVerdict?: true } = {}): Message {
|
|
948
1350
|
if (!readItem(dir, id)) throw new Error(`no item ${id}`)
|
|
949
|
-
|
|
950
|
-
return appendMessage(dir, id, { who, text: `attached ${
|
|
1351
|
+
const a = addressOrThrow(address)
|
|
1352
|
+
return appendMessage(dir, id, { who, text: `attached ${a}`, about: [a], ...o }, { now })
|
|
951
1353
|
}
|
|
952
1354
|
|
|
953
1355
|
/** a view of files as typed: one file an image, a clip or a sound (by its extension), two a before and an after; loadView
|
|
@@ -969,15 +1371,17 @@ export interface UpdateInput {
|
|
|
969
1371
|
/** its pictures as given, never a webp */
|
|
970
1372
|
keep?: boolean
|
|
971
1373
|
now?: Date
|
|
1374
|
+
/** written by the machine: no session stamped, so it holds nothing */
|
|
1375
|
+
machine?: true
|
|
972
1376
|
}
|
|
973
1377
|
|
|
974
|
-
/** 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
|
|
975
1379
|
* (labelled `update <k>: <state>`, the line its note), then one message carries the state and the line. Still broken
|
|
976
|
-
* or better holds the
|
|
1380
|
+
* or better holds the version in work, fixed asks the owner's verdict again (model.ts stateOf) */
|
|
977
1381
|
export async function postUpdate(dir: string, id: string, u: UpdateInput): Promise<{ item: Item; message: Message; tag: string; view: number | null }> {
|
|
978
1382
|
const x = readItem(dir, id)
|
|
979
|
-
if (!x) throw new Error(`no
|
|
980
|
-
if (x.item.origin.by !== 'agent')
|
|
1383
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
1384
|
+
if (x.item.origin.by !== 'agent') return lineOnNote(dir, x, u)
|
|
981
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`)
|
|
982
1386
|
if (!UPDATE_STATES.includes(u.state as UpdateState)) throw new Error(`the state: one of ${UPDATE_STATES.join(', ')}, not « ${u.state} »`)
|
|
983
1387
|
const state = u.state as UpdateState
|
|
@@ -987,22 +1391,62 @@ export async function postUpdate(dir: string, id: string, u: UpdateInput): Promi
|
|
|
987
1391
|
for (const f of files) if (!existsSync(f)) throw new Error(`${f}: no such file`)
|
|
988
1392
|
const k = updatesOf(x).length + 1
|
|
989
1393
|
const label = `update ${k}: ${UPDATE_WORDS[state]}`
|
|
990
|
-
const item = files.length === 0 ? x.item : await addView(dir, id, { ...filesView(label, files, `an update holds one file, or a before and an after: ${updateLine(id)}`), note: t.text }, {
|
|
1394
|
+
const item = files.length === 0 ? x.item : await addView(dir, id, { ...filesView(label, files, `an update holds one file, or a before and an after: ${updateLine(id)}`), note: t.text }, { message: true, ...(u.keep ? { keep: true } : {}) })
|
|
991
1395
|
const view = files.length === 0 ? null : item.views.length - 1
|
|
992
|
-
const message = appendMessage(dir, id, { who: u.who, text: t.text, update: { state, ...(view !== null ? { view } : {}) } }, u.now ? { now: u.now } : {})
|
|
1396
|
+
const message = appendMessage(dir, id, { who: u.who, text: t.text, update: { state, ...(view !== null ? { view } : {}) } }, { ...(u.now ? { now: u.now } : {}), ...(u.machine ? { machine: true } : {}) })
|
|
993
1397
|
return { item, message, tag: `update ${k} (${UPDATE_WORDS[state]})`, view }
|
|
994
1398
|
}
|
|
995
1399
|
|
|
996
|
-
/**
|
|
997
|
-
*
|
|
998
|
-
|
|
1400
|
+
/** an update on an item he raised (a thread his note heads): a line on it, its one picture the line's image; the note
|
|
1401
|
+
* keeps its own state. A clip or a pair is a version of the address: sk thread post */
|
|
1402
|
+
async function lineOnNote(dir: string, x: ReviewItem, u: UpdateInput): Promise<{ item: Item; message: Message; tag: string; view: number | null }> {
|
|
1403
|
+
if (!UPDATE_STATES.includes(u.state as UpdateState)) throw new Error(`the state: one of ${UPDATE_STATES.join(', ')}, not « ${u.state} »`)
|
|
1404
|
+
const state = u.state as UpdateState
|
|
1405
|
+
const t = textOf(u.text)
|
|
1406
|
+
if ('error' in t) throw new Error(`the line: ${t.error.replace(/^text: /, '')}`)
|
|
1407
|
+
const files = u.files ?? []
|
|
1408
|
+
const own = ownAddressOf(x.item, specOf(dir))
|
|
1409
|
+
if (files.length > 1 || files.some((f) => !/\.(png|jpe?g|webp)$/i.test(f))) throw new Error(`a line on his note takes one picture; a clip or a before and an after is a version: sk thread post ${own ?? '<kind>:<key>'} …`)
|
|
1410
|
+
for (const f of files) if (!existsSync(f)) throw new Error(`${f}: no such file`)
|
|
1411
|
+
const k = updatesOf(x).length + 1
|
|
1412
|
+
const message = appendMessage(dir, x.item.id, { who: u.who, text: t.text, update: { state } }, { ...(files[0] ? { image: files[0] } : {}), ...(u.now ? { now: u.now } : {}) })
|
|
1413
|
+
return { item: x.item, message, tag: `update ${k} (${UPDATE_WORDS[state]})`, view: null }
|
|
1414
|
+
}
|
|
1415
|
+
|
|
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 {
|
|
999
1419
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
1000
1420
|
if (!x) return 0
|
|
1001
|
-
|
|
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))
|
|
1002
1425
|
if (of.length > 0) appendMessage(dir, id, { who, op: 'seen', of }, { now })
|
|
1003
1426
|
return of.length
|
|
1004
1427
|
}
|
|
1005
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
|
+
|
|
1006
1450
|
/** the path of a message's image, null for any other name */
|
|
1007
1451
|
export function threadImage(dir: string, id: string, name: string): string | null {
|
|
1008
1452
|
if (!ID_RE.test(id) || !MESSAGE_FILE_RE.test(name)) return null
|
|
@@ -1010,6 +1454,13 @@ export function threadImage(dir: string, id: string, name: string): string | nul
|
|
|
1010
1454
|
return existsSync(f) ? f : null
|
|
1011
1455
|
}
|
|
1012
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
|
+
|
|
1013
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
|
|
1014
1465
|
* message into thread/), which moves that directory's change time, so any write moves it. Two stats an item, never
|
|
1015
1466
|
* three: on a 3000 item store each stat is 10 ms of every read */
|
|
@@ -1039,7 +1490,12 @@ function readOne(dir: string, id: string): Read {
|
|
|
1039
1490
|
|
|
1040
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
|
|
1041
1492
|
* declare, a subject's problems) is broken; the index keeps the raw reads, so a unit's change never invalidates it */
|
|
1042
|
-
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
|
+
}
|
|
1043
1499
|
|
|
1044
1500
|
const checks = new WeakMap<ReadAll, { spec: Spec; all: ReadAll }>()
|
|
1045
1501
|
|
|
@@ -1150,39 +1606,63 @@ function* readRawsSteps(dir: string, stamps?: Map<string, string>): Generator<vo
|
|
|
1150
1606
|
/** the owner's verdict, checked against its item, appended as his message */
|
|
1151
1607
|
export function writeVerdict(dir: string, id: string, body: unknown, now = new Date()): { ok: true; message: Message } | { ok: false; errors: string[] } {
|
|
1152
1608
|
const x = readItem(dir, id)
|
|
1153
|
-
if (!x) return { ok: false, errors: [`no
|
|
1154
|
-
if (x.item.wip) return { ok: false, errors: [`${id} is a draft
|
|
1155
|
-
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`] }
|
|
1156
1612
|
const r = verdictMessageOf(body, x.item)
|
|
1157
1613
|
if (!r.ok) return r
|
|
1158
1614
|
return { ok: true, message: appendMessage(dir, id, { who: 'owner', ...r.message }, { now }) }
|
|
1159
1615
|
}
|
|
1160
1616
|
|
|
1161
1617
|
/** an agent acted on the verdict and the owner's replies; false when the item has neither */
|
|
1162
|
-
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 {
|
|
1163
1619
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
1164
1620
|
if (!x) return false
|
|
1165
|
-
const read = markRead(dir, id,
|
|
1621
|
+
const read = markRead(dir, id, agentName(), now, only)
|
|
1622
|
+
if (only !== undefined) return read > 0
|
|
1166
1623
|
return verdictOf(x) !== null || read > 0
|
|
1167
1624
|
}
|
|
1168
1625
|
|
|
1169
|
-
/** 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 */
|
|
1170
1627
|
export function withdraw(dir: string, id: string, why: string, now = new Date()): { already?: string } | { refused: string } {
|
|
1171
1628
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
1172
|
-
if (!x) return { refused: `no
|
|
1173
|
-
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)
|
|
1174
1634
|
if (before) return { already: `by ${before.who}, ${before.at.slice(0, 16).replace('T', ' ')} UTC` }
|
|
1175
1635
|
const v = verdictOf(x)
|
|
1176
1636
|
if (v) {
|
|
1177
1637
|
const owes = v.status === 'approved-with-fix' ? `sk thread done ${id} "<what changed>", ` : ''
|
|
1178
|
-
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>"` : ''
|
|
1179
1639
|
return { refused: `${id}: he answered it (${v.status}), so it waits on him no more${close}` }
|
|
1180
1640
|
}
|
|
1181
1641
|
appendMessage(dir, id, { who: agentName(), op: 'withdraw', note: why }, { now })
|
|
1182
1642
|
return {}
|
|
1183
1643
|
}
|
|
1184
1644
|
|
|
1185
|
-
/**
|
|
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 */
|
|
1648
|
+
export function withdrawObject(dir: string, re: string, why: string, now = new Date()): { item: string } | { refused: string } {
|
|
1649
|
+
const x = readAll(dir).items.find((y) => y.thread.some((m) => m.id === re))
|
|
1650
|
+
const m = x?.thread.find((y) => y.id === re)
|
|
1651
|
+
if (!x || !m) return { refused: `no message ${re} (sk thread show <address> lists them)` }
|
|
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` }
|
|
1656
|
+
const before = x.thread.find((y) => y.op === 'withdraw' && y.re === re)
|
|
1657
|
+
if (before) return { refused: `${re}: withdrawn already by ${before.who} (${before.note ?? ''})` }
|
|
1658
|
+
appendMessage(dir, x.item.id, { who: agentName(), op: 'withdraw', re, note: why }, { now })
|
|
1659
|
+
return { item: x.item.id }
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
/** the reason a question answered in chat is withdrawn with: the owner's words, quoted */
|
|
1663
|
+
export const answeredInChat = (words: string): string => `answered in chat by the owner: « ${words.replace(/\s+/g, ' ').trim()} »`
|
|
1664
|
+
|
|
1665
|
+
/** an answered version waits for his answer again: its verdict stays in the thread, before the reopen. `who`: an agent
|
|
1186
1666
|
* (the CLI), or the owner taking the verdict back (the hub). The verdict reopened, null when it has none */
|
|
1187
1667
|
export function reopen(dir: string, id: string, o: { who?: string; now?: Date } = {}): Verdict | null {
|
|
1188
1668
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
@@ -1205,7 +1685,7 @@ export interface RaiseInput {
|
|
|
1205
1685
|
subject: Subject
|
|
1206
1686
|
origin: Exclude<Origin, { by: 'agent' }>
|
|
1207
1687
|
title: string
|
|
1208
|
-
/** 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` */
|
|
1209
1689
|
what?: string
|
|
1210
1690
|
topic?: string
|
|
1211
1691
|
commit?: string
|
|
@@ -1215,6 +1695,8 @@ export interface RaiseInput {
|
|
|
1215
1695
|
rects?: Rect[]
|
|
1216
1696
|
/** the image the item shows, copied in as its first view */
|
|
1217
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 }[]
|
|
1218
1700
|
now?: Date
|
|
1219
1701
|
}
|
|
1220
1702
|
|
|
@@ -1253,7 +1735,7 @@ export async function raiseItem(dir: string, input: RaiseInput): Promise<ReviewI
|
|
|
1253
1735
|
const head = { ...item, ...(image ? { media: await factsOf(tmp, [image]) } : {}) }
|
|
1254
1736
|
createAtCommit(dir, c, id, tmp, head)
|
|
1255
1737
|
const who = input.origin.by === 'player' ? 'player' : 'owner'
|
|
1256
|
-
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 } : {}) })
|
|
1257
1739
|
return readItem(dir, id) as ReviewItem
|
|
1258
1740
|
}
|
|
1259
1741
|
|
|
@@ -1292,39 +1774,17 @@ export async function ownerVerdict(dir: string, o: { subject: Subject; from: str
|
|
|
1292
1774
|
else appendMessage(dir, x.item.id, { who: 'owner', op: 'reopen' }, at)
|
|
1293
1775
|
}
|
|
1294
1776
|
|
|
1295
|
-
/** the
|
|
1296
|
-
function
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
try {
|
|
1301
|
-
mkdirSync(lock)
|
|
1302
|
-
break
|
|
1303
|
-
} catch (e) {
|
|
1304
|
-
// only a lock another holds is waited for: a folder that is missing or a file in the way is said at once
|
|
1305
|
-
if ((e as { code?: unknown }).code !== 'EEXIST') throw e
|
|
1306
|
-
if (Date.now() >= until) {
|
|
1307
|
-
// a lock left by a dead process: older than the wait itself
|
|
1308
|
-
if (Date.now() - statSync(lock).mtimeMs > 2000) {
|
|
1309
|
-
rmSync(lock, { recursive: true, force: true })
|
|
1310
|
-
continue
|
|
1311
|
-
}
|
|
1312
|
-
throw new Error(`${id}: locked by another process`)
|
|
1313
|
-
}
|
|
1314
|
-
Bun.sleepSync(10)
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
try {
|
|
1318
|
-
return fn()
|
|
1319
|
-
} finally {
|
|
1320
|
-
rmSync(lock, { recursive: true, force: true })
|
|
1321
|
-
}
|
|
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
|
|
1322
1782
|
}
|
|
1323
1783
|
|
|
1324
1784
|
/** a state change on an item by `who`, checked by `allowed` under the item's lock, so two workers claiming at once
|
|
1325
1785
|
* never both win; throws with the reason it is refused. The dispatcher's ops need the repo's unit to declare one, and
|
|
1326
1786
|
* its holder; a topic is one the unit declares */
|
|
1327
|
-
export function act(dir: string, id: string, op: Exclude<Op, 'seen'>, who: string, o: { note?: string; text?: string; commit?: string; topic?: string; now?: Date } = {}): Message {
|
|
1787
|
+
export function act(dir: string, id: string, op: Exclude<Op, 'seen'>, who: string, o: { note?: string; text?: string; commit?: string; topic?: string; now?: Date; holds?: boolean } = {}): Message {
|
|
1328
1788
|
const spec = specOf(dir)
|
|
1329
1789
|
if (who !== 'owner' && who !== 'agent' && !AGENT_RE.test(who)) throw new Error(`« ${who} » is no agent name (${AGENT_RE.source})`)
|
|
1330
1790
|
if (!ID_RE.test(id) || !readItem(dir, id)) throw new Error(`no item ${id}`)
|
|
@@ -1334,13 +1794,13 @@ export function act(dir: string, id: string, op: Exclude<Op, 'seen'>, who: strin
|
|
|
1334
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(', ')}`)
|
|
1335
1795
|
if (o.commit !== undefined && !/^[0-9a-f]{7,40}$/.test(o.commit)) throw new Error(`« ${o.commit} » is no commit`)
|
|
1336
1796
|
const now = o.now ?? new Date()
|
|
1337
|
-
// 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
|
|
1338
1798
|
readAll(dir)
|
|
1339
1799
|
return io(dir).lock(id, () => {
|
|
1340
1800
|
const x = readItem(dir, id) as ReviewItem
|
|
1341
1801
|
const superseded = isFollowed(id, readAll(dir).items)
|
|
1342
1802
|
const role = spec.dispatcher ? (roleOf(dir)?.name ?? null) : null
|
|
1343
|
-
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)
|
|
1344
1804
|
if (why) throw new Error(`${id}: ${why}`)
|
|
1345
1805
|
const m = appendMessage(
|
|
1346
1806
|
dir,
|
|
@@ -1384,7 +1844,7 @@ export function claimNext(dir: string, by: { lane: string } | { topic: string },
|
|
|
1384
1844
|
return null
|
|
1385
1845
|
}
|
|
1386
1846
|
|
|
1387
|
-
/** 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
|
|
1388
1848
|
* this way */
|
|
1389
1849
|
export function deleteRaised(dir: string, id: string): void {
|
|
1390
1850
|
const x = ID_RE.test(id) ? readItem(dir, id) : null
|
|
@@ -1403,35 +1863,36 @@ export function deleteReport(dir: string, id: string): void {
|
|
|
1403
1863
|
|
|
1404
1864
|
export { GONE, GONE_KEEP_MS, goneCreated, goneEntries, sweepGone } from './gone.ts'
|
|
1405
1865
|
|
|
1406
|
-
/**
|
|
1866
|
+
/** an item out of the store: set aside while this machine carries its items to the hq (the switch hq-cards), so the
|
|
1407
1867
|
* job sends its deletion, and always as rows (kept GONE_KEEP_MS, the way back), else removed as it always was */
|
|
1408
1868
|
function removeItem(dir: string, id: string): void {
|
|
1409
1869
|
const c = io(dir)
|
|
1410
|
-
// while a move runs, a deletion stays as
|
|
1411
|
-
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, {})
|
|
1412
1872
|
else rmSync(join(dir, id), { recursive: true, force: true })
|
|
1413
1873
|
}
|
|
1414
1874
|
|
|
1415
|
-
/**
|
|
1416
|
-
*
|
|
1417
|
-
*
|
|
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 */
|
|
1418
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')
|
|
1419
1879
|
|
|
1420
1880
|
/** the files' set aside: the folder moved, whole */
|
|
1421
1881
|
function setAsideFile(dir: string, id: string, o: { created?: string; before?: number }): 'moved' | 'none' | 'other' {
|
|
1422
1882
|
if (!ID_RE.test(id) || !existsSync(join(dir, id))) return 'none'
|
|
1423
|
-
return
|
|
1883
|
+
return lockedItem(dir, id, () => {
|
|
1424
1884
|
if (o.created !== undefined || o.before !== undefined) {
|
|
1425
1885
|
const f = join(dir, id, 'item.json')
|
|
1426
1886
|
const cur = existsSync(f) ? (JSON.parse(readFileSync(f, 'utf8')) as { created?: unknown }) : null
|
|
1427
1887
|
if (o.created !== undefined && cur?.created !== o.created) return 'other'
|
|
1428
|
-
// `before`: only
|
|
1888
|
+
// `before`: only an item made before that moment
|
|
1429
1889
|
if (o.before !== undefined && !(Date.parse(String(cur?.created)) < o.before)) return 'other'
|
|
1430
1890
|
}
|
|
1431
1891
|
mkdirSync(join(dir, GONE), { recursive: true })
|
|
1432
1892
|
const to = join(dir, GONE, goneEntryFor(dir, id))
|
|
1433
1893
|
renameSync(join(dir, id), to)
|
|
1434
|
-
// 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 })
|
|
1435
1896
|
rmSync(join(to, '.lock'), { recursive: true, force: true })
|
|
1436
1897
|
return 'moved'
|
|
1437
1898
|
})
|
|
@@ -1468,19 +1929,19 @@ function itemOfPrefix(dir: string, ref: string): ReviewItem | null {
|
|
|
1468
1929
|
/** a player's report as the owner names it: `live#85`; any other item by its id */
|
|
1469
1930
|
export const refOf = (x: ReviewItem): string => (x.item.origin.by === 'player' ? `${x.item.origin.server}#${x.item.origin.serverId}` : x.item.id)
|
|
1470
1931
|
|
|
1471
|
-
/** 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
|
|
1472
1933
|
* draft's frame count moves */
|
|
1473
1934
|
export async function refreshDraft(dir: string, id: string, o: { image: string; history?: { file: string; label: string }[] }): Promise<Item> {
|
|
1474
1935
|
const x = readItem(dir, id)
|
|
1475
|
-
if (!x) throw new Error(`no
|
|
1936
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
1476
1937
|
const r = x.item
|
|
1477
|
-
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`)
|
|
1478
1939
|
const f0 = r.views[0]
|
|
1479
1940
|
if (!f0 || isGallery(f0) || !('image' in f0.files)) throw new Error(`${id}: its first view is no image`)
|
|
1480
1941
|
const folder = io(dir).folder(id)
|
|
1481
1942
|
mkdirSync(folder, { recursive: true })
|
|
1482
1943
|
const image = f0.files.image
|
|
1483
|
-
// 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
|
|
1484
1945
|
const webp = extname(image) === '.webp'
|
|
1485
1946
|
const main = await loadView({ label: f0.label, image: o.image }, 'the live frame', webp ? { always: true } : { keep: true })
|
|
1486
1947
|
putFile(main, main.sources[0]?.[1] ?? '', join(folder, `${image}.tmp`))
|
|
@@ -1501,21 +1962,21 @@ export async function refreshDraft(dir: string, id: string, o: { image: string;
|
|
|
1501
1962
|
return updateHead(dir, id, () => ({ ...next, media }))
|
|
1502
1963
|
}
|
|
1503
1964
|
|
|
1504
|
-
/** the label of a draft
|
|
1965
|
+
/** the label of a draft version's history view */
|
|
1505
1966
|
export const HISTORY = 'history'
|
|
1506
1967
|
|
|
1507
|
-
/** a draft
|
|
1968
|
+
/** a draft version made a version he answers: its image the last frame or `image`, the draft state gone */
|
|
1508
1969
|
export async function readyItem(dir: string, id: string, o: { image?: string; now?: Date } = {}): Promise<Item> {
|
|
1509
1970
|
const x = readItem(dir, id)
|
|
1510
|
-
if (!x) throw new Error(`no
|
|
1971
|
+
if (!x) throw new Error(`no item ${id}`)
|
|
1511
1972
|
const { wip, ...rest } = x.item
|
|
1512
1973
|
if (!wip && inWork(x)) {
|
|
1513
|
-
// a
|
|
1974
|
+
// a version its updates hold in work: ready asks the owner's verdict, its newest picture goes on as an update
|
|
1514
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')}`)
|
|
1515
1976
|
appendMessage(dir, id, { who: agentName(), op: 'ready' }, o.now ? { now: o.now } : {})
|
|
1516
1977
|
return x.item
|
|
1517
1978
|
}
|
|
1518
|
-
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`)
|
|
1519
1980
|
let item: Item = rest
|
|
1520
1981
|
if (o.image !== undefined) {
|
|
1521
1982
|
const f0 = rest.views[0]
|
|
@@ -1559,7 +2020,7 @@ const folderStamp = (key: string): string => {
|
|
|
1559
2020
|
}
|
|
1560
2021
|
|
|
1561
2022
|
/** the disk checked under the watch, which goes silent under load (FSEvents drops events) and must never freeze the
|
|
1562
|
-
* 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
|
|
1563
2024
|
* SWEEP_MS the stamp of each item. What moved unheard goes dirty and moves the ETag */
|
|
1564
2025
|
function verify(key: string, w: Watched, now: number): void {
|
|
1565
2026
|
if (!w.held) return
|
|
@@ -1603,11 +2064,11 @@ function touched(path: string): void {
|
|
|
1603
2064
|
}
|
|
1604
2065
|
|
|
1605
2066
|
const STORE_SEGMENT = `/${LAYOUT.review}/`
|
|
1606
|
-
/** 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
|
|
1607
2068
|
* died) sees any process's write with one stat of the folder. A lock is no change of the store */
|
|
1608
2069
|
function stampStore(p: string): void {
|
|
1609
2070
|
const i = p.lastIndexOf(STORE_SEGMENT)
|
|
1610
|
-
if (i < 0 || p
|
|
2071
|
+
if (i < 0 || isLockFile(p)) return
|
|
1611
2072
|
const now = new Date()
|
|
1612
2073
|
try {
|
|
1613
2074
|
fs.utimesSync(p.slice(0, i + STORE_SEGMENT.length - 1), now, now)
|
|
@@ -1623,7 +2084,7 @@ function watchOf(dir: string): Watched | null {
|
|
|
1623
2084
|
try {
|
|
1624
2085
|
// an item's lock is no change of the list
|
|
1625
2086
|
const watcher = watch(key, { recursive: true }, (_, name) => {
|
|
1626
|
-
if (name
|
|
2087
|
+
if (name != null && isLockFile(name)) return
|
|
1627
2088
|
w.moved++
|
|
1628
2089
|
if (name) w.dirty.add(name.split('/')[0] ?? '')
|
|
1629
2090
|
else w.held = null
|
|
@@ -1641,7 +2102,7 @@ function watchOf(dir: string): Watched | null {
|
|
|
1641
2102
|
/** a watched store read whole before a page asks, the loop given back between two steps: the first read after a boot
|
|
1642
2103
|
* is the only whole one, every later one reads the items that moved */
|
|
1643
2104
|
export async function warmStore(dir: string): Promise<void> {
|
|
1644
|
-
if (
|
|
2105
|
+
if (threadsInDb()) return void rowsAll(dir)
|
|
1645
2106
|
if (!existsSync(dir)) return
|
|
1646
2107
|
const w = watchOf(dir)
|
|
1647
2108
|
if (!w || (w.held && w.all)) return
|
|
@@ -1657,7 +2118,7 @@ export async function warmStore(dir: string): Promise<void> {
|
|
|
1657
2118
|
/** changes when anything the list is built from changes: watched, a count of writes and what the disk check found;
|
|
1658
2119
|
* else a scan. The list's ETag */
|
|
1659
2120
|
export function storeStamp(dir: string, now = Date.now()): string {
|
|
1660
|
-
if (
|
|
2121
|
+
if (threadsInDb()) return rowsStamp(dir)
|
|
1661
2122
|
if (!existsSync(dir)) return 'none'
|
|
1662
2123
|
const w = watchOf(dir)
|
|
1663
2124
|
if (!w) return scanStamp(dir)
|
|
@@ -1668,22 +2129,22 @@ export function storeStamp(dir: string, now = Date.now()): string {
|
|
|
1668
2129
|
/** what moved the store, from what this process heard: its watch's events, its own writes, the store folder (one
|
|
1669
2130
|
* stat). Never a stat of its items: an event the watch missed waits for the next walk of the caller's own */
|
|
1670
2131
|
export function storeMoved(dir: string): string {
|
|
1671
|
-
if (
|
|
2132
|
+
if (threadsInDb()) return rowsStamp(dir)
|
|
1672
2133
|
if (!existsSync(dir)) return 'none'
|
|
1673
2134
|
const key = resolve(dir)
|
|
1674
2135
|
const w = watchOf(dir)
|
|
1675
2136
|
return w ? `${BOOT}.${w.moved}.${wrote}.${folderStamp(key)}` : `${BOOT}.-.${wrote}.${folderStamp(key)}`
|
|
1676
2137
|
}
|
|
1677
2138
|
|
|
1678
|
-
/** does the store hold anything: its folder, or with the switch cards-in-db its rows (a repo's
|
|
1679
|
-
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))
|
|
1680
2141
|
|
|
1681
2142
|
/** the store's stamp and who listens (the live watchers' pids), so a watch that starts or dies moves it too */
|
|
1682
2143
|
export const listingStamp = (dir: string): string => `${storeStamp(dir)}~${liveWatchers(dir).map((w) => w.pid).join(',')}`
|
|
1683
2144
|
|
|
1684
2145
|
/** the stamp from a scan of every item's files: the safety net of a watcher that may miss an event */
|
|
1685
2146
|
export function scanStamp(dir: string): string {
|
|
1686
|
-
if (
|
|
2147
|
+
if (threadsInDb()) return rowsStamp(dir)
|
|
1687
2148
|
const h = new Bun.CryptoHasher('sha1')
|
|
1688
2149
|
if (!existsSync(dir)) return 'none'
|
|
1689
2150
|
const mark = (f: string): void => {
|
|
@@ -1702,7 +2163,7 @@ export function scanStamp(dir: string): string {
|
|
|
1702
2163
|
let cached: { dir: string; tag: string; all: ReadAll } | null = null
|
|
1703
2164
|
|
|
1704
2165
|
/** readAll kept while nothing it reads changed: watched, only the items written since are read again */
|
|
1705
|
-
export const readAllCached = (dir: string): ReadAll => checked(
|
|
2166
|
+
export const readAllCached = (dir: string): ReadAll => checked(threadsInDb() ? rowsAll(dir) : readRawsCached(dir), specOf(dir))
|
|
1706
2167
|
|
|
1707
2168
|
function readRawsCached(dir: string): ReadAll {
|
|
1708
2169
|
const w = existsSync(dir) ? watchOf(dir) : null
|