rvlib-shipkit 2.12.0 → 2.14.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 +75 -21
- package/README.md +1 -1
- package/package.json +4 -2
- package/src/agent-time/store.ts +2 -2
- package/src/assets/run-assets.ts +2 -2
- package/src/assets/server/studio-server.ts +27 -23
- package/src/check.ts +4 -4
- package/src/checks/SK001-package-json-shape.check.ts +8 -4
- package/src/checks/SK002-contracts-fulfillness.check.ts +2 -2
- package/src/checks/SK003-claude-md-shape.check.ts +20 -13
- package/src/checks/SK004-gitignore-policy.check.ts +45 -6
- package/src/checks/SK005-rvlib-versions.check.ts +2 -2
- package/src/checks/SK006-npm-publish-safety.check.ts +3 -3
- package/src/checks/SK007-github-visibility.check.ts +2 -2
- package/src/checks/SK008-reviewer-agent.check.ts +3 -3
- package/src/checks/SK010-undeclared-unit.check.ts +2 -2
- package/src/checks/SK011-sibling-unit-ranges.check.ts +2 -2
- package/src/checks/SK012-config-barrel-import.check.ts +2 -2
- package/src/checks/SK013-one-way-in-policy.check.ts +2 -2
- package/src/checks/SK015-nested-repo.check.ts +3 -3
- package/src/checks/SK016-legacy-check-shapes.check.ts +2 -2
- package/src/checks/SK017-vscode-hub-task.check.ts +2 -2
- package/src/checks/SK018-test-files-run.check.ts +2 -2
- package/src/checks/SK019-tests-run-in-units.check.ts +2 -2
- package/src/checks/SK020-self-spawning-check.check.ts +2 -2
- package/src/checks/SK022-machine-runs-the-pin.check.ts +2 -2
- package/src/checks/SK024-identity-colors.check.ts +1 -1
- package/src/checks/SK025-release-drift.check.ts +2 -2
- package/src/checks/SK026-asks-autoclose.check.ts +2 -2
- package/src/checks/SK027-agent-wiki-links.check.ts +8 -2
- package/src/checks/SK028-readme.check.ts +2 -2
- package/src/checks/SK029-explicit-check-files.check.ts +3 -3
- package/src/checks/SK030-cache-audit.check.ts +7 -5
- package/src/checks/SK031-trace-audit.check.ts +7 -7
- package/src/checks/SK032-ignored-inputs.check.ts +3 -3
- package/src/checks/SK033-global-contribution.check.ts +11 -4
- package/src/checks/SK034-commit-gates-armed.check.ts +2 -2
- package/src/checks/SK035-public-clean.check.ts +46 -0
- package/src/checks/SK036-draft-media-size.check.ts +28 -0
- package/src/checks/SK037-keyword-additions.check.ts +43 -0
- package/src/cli/cmd_Backup.ts +152 -0
- package/src/cli/cmd_Ci.ts +8 -11
- package/src/cli/cmd_Commands.ts +4 -4
- package/src/cli/cmd_ConfigKeys.ts +2 -2
- package/src/cli/cmd_Drill.ts +145 -0
- package/src/cli/cmd_Home.ts +50 -3
- package/src/cli/cmd_Init.ts +1 -1
- package/src/cli/cmd_Media.ts +10 -8
- package/src/cli/cmd_Mv.ts +14 -7
- package/src/cli/cmd_Review.ts +6 -4
- package/src/cli/cmd_Shot.ts +5 -2
- package/src/cli/cmd_Smoke.ts +5 -2
- package/src/cli/cmd_Social.ts +226 -0
- package/src/cli/cmd_Sound.ts +1 -1
- package/src/cli/cmd_Start.ts +1 -1
- package/src/cli/cmd_Time.ts +1 -1
- package/src/cli/cmd_TraceAudit.ts +6 -6
- package/src/cli/cmd_Trailer.ts +7 -4
- package/src/cli/cmd_Veille.ts +173 -0
- package/src/cli/cmd_When.ts +2 -2
- package/src/cli/family-pages.ts +19 -16
- package/src/cli/registry.ts +13 -2
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +1 -49
- package/src/collections/checks.ts +2 -1
- package/src/collections/collection-types.ts +12 -3
- package/src/collections/providers.ts +4 -4
- package/src/collections/review.ts +3 -2
- package/src/collections/tests.ts +19 -8
- package/src/comfy/comfy-panel.ts +2 -2
- package/src/contracts/apply-contracts.ts +1 -3
- package/src/contracts/contract-manifests.ts +2 -3
- package/src/contracts/contract-types.ts +0 -1
- package/src/contracts/contracts-engine.ts +0 -3
- package/src/contracts/manifests/discord.contract.ts +1 -1
- package/src/contracts/manifests/identity.contract.ts +1 -1
- package/src/contracts/manifests/itch.contract.ts +1 -1
- package/src/contracts/manifests/steam.contract.ts +1 -1
- package/src/core/agent-dir-at.ts +12 -0
- package/src/core/agent-dir.ts +16 -0
- package/src/core/app-icon.ts +9 -3
- package/src/core/budget.ts +1 -1
- package/src/core/bun-builtins.ts +2 -2
- package/src/core/canonical-scripts.ts +2 -2
- package/src/core/discover-checks.ts +38 -6
- package/src/core/fix-scope.ts +4 -2
- package/src/core/floor-resolve.ts +68 -48
- package/src/core/floor.ts +9 -0
- package/src/core/git-root.ts +24 -0
- package/src/core/global-contribution.ts +4 -1
- package/src/core/ignored-block.ts +1 -1
- package/src/core/ignored-inputs.ts +3 -2
- package/src/core/last-good.ts +3 -1
- package/src/core/layout.ts +8 -0
- package/src/core/log-stamp.ts +36 -0
- package/src/core/loop-watch.ts +93 -0
- package/src/core/machine-link.ts +134 -0
- package/src/core/memory-watch.ts +41 -0
- package/src/core/motherhome.ts +2 -2
- package/src/core/one-way-in-policy.ts +34 -26
- package/src/core/run-ci.ts +9 -11
- package/src/core/run-fixers.ts +9 -9
- package/src/core/runs-matrix.ts +1 -1
- package/src/core/slots.ts +30 -0
- package/src/core/trace-audit.ts +50 -9
- package/src/core/tree-rev.ts +60 -0
- package/src/core/unit-files.ts +42 -0
- package/src/drill/render.ts +140 -0
- package/src/drill/run.ts +269 -0
- package/src/fleet/scan-fleet.ts +6 -5
- package/src/home/daemon-jobs.ts +201 -0
- package/src/home/global-context.ts +44 -8
- package/src/home/gui-app/ShipkitGui.swift +91 -2
- package/src/home/home-routes.ts +22 -15
- package/src/home/hubs.ts +10 -3
- package/src/home/inbox-shape.ts +54 -5
- package/src/home/inbox.ts +17 -2
- package/src/home/lib-watch.ts +10 -3
- package/src/home/machine-stores.ts +15 -29
- package/src/home/pm-config.ts +4 -1
- package/src/home/pm-inputs.ts +2 -0
- package/src/home/resources.ts +7 -2
- package/src/home/run-daemon.ts +15 -18
- package/src/home/run-pm.ts +3 -1
- package/src/home/serve-daemon.ts +4 -3
- package/src/home/serve-web.ts +104 -1
- package/src/hooks/commit-message.ts +29 -20
- package/src/hooks/hook-gates.ts +1 -1
- package/src/hooks/leak-guard.ts +69 -9
- package/src/hooks/run-hooks.ts +18 -22
- package/src/identities/identities.ts +334 -0
- package/src/identities/machine-route.ts +126 -0
- package/src/identities/machine.ts +62 -0
- package/src/init-repo.ts +3 -3
- package/src/ledger/check-stats.ts +10 -9
- package/src/ledger/gate-checks.ts +32 -1
- package/src/ledger/record-kept.ts +112 -0
- package/src/ledger/repo-view.ts +10 -0
- package/src/ledger/run-log.ts +17 -12
- package/src/ledger/run-timeline.ts +8 -4
- package/src/ledger/store.ts +7 -0
- package/src/ledger/suite-log.ts +17 -13
- package/src/media-kinds.ts +3 -2
- package/src/media-store/backup/daemon.ts +73 -0
- package/src/media-store/backup/keys.ts +25 -0
- package/src/media-store/backup/manifest.ts +193 -0
- package/src/media-store/backup/restore.ts +192 -0
- package/src/media-store/backup/run.ts +278 -0
- package/src/media-store/backup/secret.ts +86 -0
- package/src/media-store/backup/snapshot.ts +64 -0
- package/src/media-store/backup/sources.ts +199 -0
- package/src/media-store/content.ts +1 -1
- package/src/media-store/daemon.ts +56 -70
- package/src/media-store/db.ts +1 -1
- package/src/media-store/fact.ts +1 -1
- package/src/media-store/hand.ts +1 -1
- package/src/media-store/kind.ts +1 -1
- package/src/media-store/purge.ts +1 -1
- package/src/media-store/put.ts +5 -3
- package/src/media-store/remote.ts +1 -1
- package/src/media-store/space.ts +24 -5
- package/src/mv/mv-md.ts +63 -22
- package/src/pages/forward.ts +35 -0
- package/src/pages/frame-client.ts +118 -0
- package/src/pages/routes.ts +29 -0
- package/src/pages/unit.ts +92 -0
- package/src/plan/planner.ts +12 -0
- package/src/plan/repo-source.ts +19 -5
- package/src/reflect/transcript.ts +35 -10
- package/src/release/public-clean.ts +319 -0
- package/src/release/published-here.ts +22 -0
- package/src/release/run-bump.ts +3 -2
- package/src/release/run-release.ts +7 -4
- package/src/repo-config.ts +71 -13
- package/src/review/anim.ts +1 -1
- package/src/review/auto.ts +1 -1
- package/src/review/cells.ts +15 -1
- package/src/review/format.ts +2 -2
- package/src/review/http.ts +16 -2
- package/src/review/marks.ts +1 -1
- package/src/review/media-kind.ts +1 -1
- package/src/review/media-read.ts +1 -1
- package/src/review/model.ts +27 -6
- package/src/review/notes.ts +125 -0
- package/src/review/previews.ts +1 -1
- package/src/review/project.ts +7 -39
- package/src/review/role.ts +1 -1
- package/src/review/routes.ts +18 -14
- package/src/review/store.ts +42 -2
- package/src/review/threads.ts +1 -1
- package/src/review/trailer-desk.ts +3 -3
- package/src/review/trailer-media.ts +8 -5
- package/src/review/trailer-model.ts +1 -1
- package/src/review/trailer-routes.ts +1 -1
- package/src/review/trailer-shots.ts +22 -5
- package/src/review/unit.ts +2 -2
- package/src/scaffold/files/agent-handoff.md +3 -0
- package/src/scaffold/files/agent-index.md +4 -12
- package/src/scaffold/files/tsconfig.json +1 -1
- package/src/scaffold/project-scaffold.ts +6 -5
- package/src/serve/embed.ts +2 -2
- package/src/serve/hub-app/check-words.ts +1 -1
- package/src/serve/hub-app/col-card.tsx +3 -17
- package/src/serve/hub-app/col-tables-view.tsx +2 -1
- package/src/serve/hub-app/cols-svc.ts +0 -13
- package/src/serve/hub-app/dock-st.ts +4 -2
- package/src/serve/hub-app/dock-view.tsx +2 -0
- package/src/serve/hub-app/frames-st.ts +35 -0
- package/src/serve/hub-app/hash-route.ts +64 -1
- package/src/serve/hub-app/home-st.ts +32 -8
- package/src/serve/hub-app/home-strip.css +9 -1
- package/src/serve/hub-app/home-strip.tsx +7 -6
- package/src/serve/hub-app/home.html +5 -0
- package/src/serve/hub-app/hub-app.tsx +51 -7
- package/src/serve/hub-app/hub.css +29 -11
- package/src/serve/hub-app/icons.tsx +16 -1
- package/src/serve/hub-app/identities-st.ts +210 -0
- package/src/serve/hub-app/identities-view.tsx +353 -0
- package/src/serve/hub-app/identities.css +48 -0
- package/src/serve/hub-app/identity-address.ts +52 -0
- package/src/serve/hub-app/inbox-st.ts +60 -7
- package/src/serve/hub-app/inbox-view.tsx +49 -7
- package/src/serve/hub-app/inbox.css +12 -1
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/kept-cols.tsx +30 -0
- package/src/serve/hub-app/keys.ts +10 -2
- package/src/serve/hub-app/list-walk.ts +89 -0
- package/src/serve/hub-app/machine-st.ts +12 -0
- package/src/serve/hub-app/media-svc.ts +1 -1
- package/src/serve/hub-app/media-view.tsx +2 -1
- package/src/serve/hub-app/pages-frames.tsx +134 -0
- package/src/serve/hub-app/pages-svc.ts +111 -0
- package/src/serve/hub-app/palette-st.ts +18 -3
- package/src/serve/hub-app/palette-view.tsx +9 -2
- package/src/serve/hub-app/planned-view.tsx +2 -1
- package/src/serve/hub-app/project-list.css +18 -14
- package/src/serve/hub-app/project-list.tsx +88 -49
- package/src/serve/hub-app/projects-svc.ts +33 -3
- package/src/serve/hub-app/repo-sections.ts +19 -2
- package/src/serve/hub-app/repo-st.ts +76 -20
- package/src/serve/hub-app/review/review-board.tsx +1 -1
- package/src/serve/hub-app/review/review-cells.tsx +6 -5
- package/src/serve/hub-app/review/review-kit.ts +30 -7
- package/src/serve/hub-app/review/review-page.tsx +6 -5
- package/src/serve/hub-app/review/review-st.ts +34 -15
- package/src/serve/hub-app/review/review-thread.tsx +63 -14
- package/src/serve/hub-app/review/review-views.tsx +133 -51
- package/src/serve/hub-app/review/thread-st.ts +80 -37
- package/src/serve/hub-app/review/trailer-page.tsx +7 -5
- package/src/serve/hub-app/review/trailer-st.ts +1 -1
- package/src/serve/hub-app/review.css +26 -9
- package/src/serve/hub-app/site/site-part.tsx +173 -0
- package/src/serve/hub-app/site/site-st.ts +157 -0
- package/src/serve/hub-app/site.css +35 -0
- package/src/serve/hub-app/social/calendar.tsx +182 -0
- package/src/serve/hub-app/social/comms-page.tsx +330 -0
- package/src/serve/hub-app/social/kit.tsx +244 -0
- package/src/serve/hub-app/social/post-card.tsx +456 -0
- package/src/serve/hub-app/social/problems.tsx +60 -0
- package/src/serve/hub-app/social/social-model.ts +154 -0
- package/src/serve/hub-app/social/social-page.tsx +681 -0
- package/src/serve/hub-app/social/social-st.ts +1014 -0
- package/src/serve/hub-app/social.css +289 -0
- package/src/serve/hub-app/stores/stores-page.tsx +312 -0
- package/src/serve/hub-app/stores/stores-st.ts +286 -0
- package/src/serve/hub-app/stores.css +54 -0
- package/src/serve/hub-app/timeline-geometry.ts +1 -1
- package/src/serve/hub-app/timeline-view.tsx +3 -2
- package/src/serve/hub-app/tree-build.ts +6 -0
- package/src/serve/hub-app/tree-row.tsx +27 -4
- package/src/serve/hub-app/tree-svc.ts +18 -49
- package/src/serve/hub-app/veille/veille-page.tsx +515 -0
- package/src/serve/hub-app/veille/veille-st.ts +443 -0
- package/src/serve/hub-app/veille.css +84 -0
- package/src/serve/hub-runtime.ts +20 -11
- package/src/serve/project-gutter-route.ts +44 -12
- package/src/serve/run-lanes.ts +7 -4
- package/src/serve/same-origin.ts +1 -1
- package/src/serve/serve-hub.ts +20 -12
- package/src/serve/tracked-watch.ts +24 -3
- package/src/serve/warm-cell.ts +5 -1
- package/src/shipkit-files.ts +15 -4
- package/src/shipkit.ts +0 -1
- package/src/shot/box.ts +160 -0
- package/src/shot/browser-slot.ts +74 -0
- package/src/shot/client.ts +42 -7
- package/src/shot/clip-encoder.ts +108 -24
- package/src/shot/film-box.ts +292 -0
- package/src/shot/shooter.ts +71 -17
- package/src/shot/shot-ask.ts +10 -2
- package/src/shot/stepped-clip.ts +5 -4
- package/src/site/desk.ts +242 -0
- package/src/site/routes.ts +66 -0
- package/src/site/unit.ts +62 -0
- package/src/social/brands.ts +22 -0
- package/src/social/card-drafts.ts +24 -0
- package/src/social/compose.ts +97 -0
- package/src/social/desk-index.ts +123 -0
- package/src/social/desk-wire.ts +64 -0
- package/src/social/drafts.ts +183 -0
- package/src/social/house.ts +24 -0
- package/src/social/load.ts +332 -0
- package/src/social/md.ts +70 -0
- package/src/social/media-facts.ts +53 -0
- package/src/social/media-kind.ts +189 -0
- package/src/social/media-limit.ts +42 -0
- package/src/social/media-of.ts +30 -0
- package/src/social/migrate.ts +123 -0
- package/src/social/open.ts +17 -0
- package/src/social/post-url.ts +158 -0
- package/src/social/presence.ts +332 -0
- package/src/social/public-read.ts +53 -0
- package/src/social/publish/bluesky.ts +168 -0
- package/src/social/publish/discord.ts +76 -0
- package/src/social/publish/index.ts +24 -0
- package/src/social/publish/secret.ts +13 -0
- package/src/social/push.ts +37 -0
- package/src/social/richtext.ts +37 -0
- package/src/social/routes.ts +186 -0
- package/src/social/stats.ts +134 -0
- package/src/social/text.ts +267 -0
- package/src/social/tracker-route.ts +39 -0
- package/src/social/tracker.ts +255 -0
- package/src/social/unit.ts +53 -0
- package/src/social/writes.ts +130 -0
- package/src/start-repo.ts +14 -9
- package/src/stores/collection.ts +27 -0
- package/src/stores/desk.ts +336 -0
- package/src/stores/model.ts +187 -0
- package/src/stores/routes.ts +126 -0
- package/src/stores/unit.ts +57 -0
- package/src/suite/calibrate.ts +127 -0
- package/src/suite/core-counters.ts +91 -0
- package/src/suite/judge-suites.ts +95 -35
- package/src/suite/suite-cli.ts +44 -10
- package/src/suite/suite-cpu-preload.ts +34 -9
- package/src/trace/tracer.ts +12 -5
- package/src/trailer/adapter.ts +5 -1
- package/src/trailer/build.ts +45 -12
- package/src/trailer/ffmpeg.ts +11 -0
- package/src/trailer/footage.ts +30 -13
- package/src/trailer/grammar.ts +18 -2
- package/src/trailer/graph.ts +28 -6
- package/src/trailer/holes.ts +1 -1
- package/src/trailer/passage.ts +18 -6
- package/src/trailer/plan.ts +74 -3
- package/src/trailer/prune.ts +1 -1
- package/src/trailer/states.ts +1 -1
- package/src/trailer/stitch.ts +67 -26
- package/src/trailer/url.ts +1 -1
- package/src/trailer/versions.ts +24 -0
- package/src/trailer/words.ts +1 -1
- package/src/ts/gate-typecheck.ts +32 -0
- package/src/ts/typecheck-cli.ts +9 -11
- package/src/tui/run-tui.ts +1 -1
- package/src/tui/tui-app.tsx +0 -1
- package/src/tui/tui-store.ts +1 -1
- package/src/veille/asks.ts +155 -0
- package/src/veille/auto.ts +31 -0
- package/src/veille/batch.ts +27 -0
- package/src/veille/chrome.ts +127 -0
- package/src/veille/collection.ts +28 -0
- package/src/veille/desk.ts +242 -0
- package/src/veille/identity.ts +80 -0
- package/src/veille/import.ts +68 -0
- package/src/veille/log.ts +183 -0
- package/src/veille/platforms.ts +118 -0
- package/src/veille/reads.ts +66 -0
- package/src/veille/replied.ts +110 -0
- package/src/veille/routes.ts +185 -0
- package/src/veille/service.ts +81 -0
- package/src/veille/watch.ts +116 -0
- package/src/veille/worth.ts +46 -0
- package/src/wiki/scan-md.ts +18 -0
- package/src/collections/posts.ts +0 -142
- package/src/contracts/manifests/social.contract.ts +0 -20
- package/src/scaffold/files/agent-coding.md +0 -35
- package/src/ts/typecheck-cache.ts +0 -11
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// WHAT THE BACKUP HOLDS (wiki tools/shipkit/media-store.md, Backup, The inventory): every file of the machine that no
|
|
2
|
+
// git and no Space keeps, its authored or irreplaceable state. The home's veille logs, the rail order, the media index
|
|
3
|
+
// and the machine db (consistent sqlite snapshots), the machine's private folder, the agents' memories of each house
|
|
4
|
+
// repo; in each house repo, every untracked file of `.shipkit/` and the hand tuned `.comfy-ts/` files, and its
|
|
5
|
+
// gitignored `*.local.*` files; and what the repo's config adds (`backup`: paths kept whole, sqlite files). Never a cache, a log, a scratch folder, a lock, a dev database it did not name or a media file a kind of
|
|
6
|
+
// the store holds. Walked with async fs: the daemon runs this between requests
|
|
7
|
+
import type { Dirent } from 'node:fs'
|
|
8
|
+
import { lstat, readdir } from 'node:fs/promises'
|
|
9
|
+
import { existsSync, statSync } from 'node:fs'
|
|
10
|
+
import { basename, extname, join, relative, sep } from 'node:path'
|
|
11
|
+
import { homeDir } from '../../home/home-paths.ts'
|
|
12
|
+
import { machineDbPath } from '../../core/machine-db.ts'
|
|
13
|
+
import { MACHINE_PRIVATE } from '../../core/layout.ts'
|
|
14
|
+
import { ORDER_FILE } from '../../serve/project-gutter-route.ts'
|
|
15
|
+
import { mediaDbPath } from '../db.ts'
|
|
16
|
+
import { loadRepoConfig, type RepoBackup } from '../../repo-config.ts'
|
|
17
|
+
import type { SqliteCut } from './snapshot.ts'
|
|
18
|
+
|
|
19
|
+
export interface Source {
|
|
20
|
+
abs: string
|
|
21
|
+
/** the path under the home folder: the form a manifest and a restore use */
|
|
22
|
+
rel: string
|
|
23
|
+
size: number
|
|
24
|
+
mtime: number
|
|
25
|
+
/** a live sqlite: snapshotted, never copied */
|
|
26
|
+
sqlite?: SqliteCut
|
|
27
|
+
/** a path the repo names whole: no size bound, read as a stream, not read again while its size and time hold */
|
|
28
|
+
whole?: true
|
|
29
|
+
/** why it cannot be read: refused with this reason, loud each run */
|
|
30
|
+
broken?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** `.shipkit/` folders rebuilt, scratch, logs, runtime, or media the store or another owner keeps */
|
|
34
|
+
const SHIPKIT_DENY = new Set(['cache', 'tmp', 'logs', 'wrapper', 'locks', 'shots', 'backups', 'cloud', 'review-watchers', 'worktrees', 'node_modules', '.git'])
|
|
35
|
+
const FILE_DENY = /^(?:STATUS(?:\.full)?\.md|\.DS_Store|\.review-index\.json|review-dispatcher\.json)$|\.(?:log|pid|lock|sqlite(?:-wal|-shm)?|db(?:-wal|-shm)?)$/
|
|
36
|
+
/** the review store's media go up as the `review` kind: only its records come here */
|
|
37
|
+
const RECORD = /\.(?:json|jsonl|md|txt|csv)$/
|
|
38
|
+
/** the atelier's rolls are generated media: its kit files and records come here, never its images or sounds */
|
|
39
|
+
const MEDIA = /\.(?:png|jpe?g|webp|gif|avif|mp4|webm|mov|wav|mp3|flac|ogg|opus|m4a|glb|exr|safetensors)$/i
|
|
40
|
+
/** the hand tuned files of `.comfy-ts/`: its caches, outputs and fetched templates stay out */
|
|
41
|
+
const COMFY_KEEP = ['drafts', 'llm-configs', 'settings.json', 'lora-keywords.json', 'image-picker.json', 'serve-tabs.json']
|
|
42
|
+
/** gitignored by some repos and authored there */
|
|
43
|
+
const REPO_EXTRA = ['agent/global-contribution.md', 'proposal', '.local']
|
|
44
|
+
const CODE = /\.(?:[cm]?[jt]sx?)$/
|
|
45
|
+
|
|
46
|
+
async function walk(dir: string, keep: (rel: string, isDir: boolean) => boolean, out: string[], base = dir): Promise<void> {
|
|
47
|
+
let names: Dirent[]
|
|
48
|
+
try {
|
|
49
|
+
names = await readdir(dir, { withFileTypes: true })
|
|
50
|
+
} catch {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
for (const d of names.sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
54
|
+
const abs = join(dir, d.name)
|
|
55
|
+
const rel = relative(base, abs)
|
|
56
|
+
if (d.isDirectory()) {
|
|
57
|
+
if (keep(rel, true)) await walk(abs, keep, out, base)
|
|
58
|
+
} else if (d.isFile() && keep(rel, false)) out.push(abs)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const shipkitKeep = (rel: string, isDir: boolean): boolean => {
|
|
63
|
+
const parts = rel.split(sep)
|
|
64
|
+
const name = parts[parts.length - 1] ?? ''
|
|
65
|
+
if (isDir) return !(parts.length === 1 && SHIPKIT_DENY.has(name)) && name !== 'node_modules' && name !== '.git' && !(parts[0] === 'social' && name === 'media')
|
|
66
|
+
if (FILE_DENY.test(name)) return false
|
|
67
|
+
if (parts[0] === 'review' && !RECORD.test(name)) return false
|
|
68
|
+
if (parts[0] === 'assets' && MEDIA.test(name)) return false
|
|
69
|
+
return true
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const comfyKeep = (rel: string): boolean => COMFY_KEEP.some((k) => rel === k || rel.startsWith(`${k}${sep}`))
|
|
73
|
+
|
|
74
|
+
async function git(repo: string, args: string[]): Promise<string[]> {
|
|
75
|
+
const p = Bun.spawn(['git', '-C', repo, ...args], { stdout: 'pipe', stderr: 'ignore' })
|
|
76
|
+
const text = await new Response(p.stdout).text()
|
|
77
|
+
if ((await p.exited) !== 0) return []
|
|
78
|
+
return text.split('\0').filter((l) => l !== '')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** the gitignored `*.local.*` files of a repo, never a settings file or code */
|
|
82
|
+
export async function localFiles(repo: string): Promise<string[]> {
|
|
83
|
+
const names = await git(repo, ['ls-files', '-z', '-o', '-i', '--exclude-standard', '--', ':(glob)**/*.local.*'])
|
|
84
|
+
return names.filter((n) => basename(n) !== 'settings.local.json' && !CODE.test(n) && !n.split('/').some((p) => p === 'node_modules')).map((n) => join(repo, n))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** the agents' config roots under the home: `.claude`, `.claude-<account>` */
|
|
88
|
+
async function agentRoots(home: string): Promise<string[]> {
|
|
89
|
+
const names = await readdir(home).catch(() => [] as string[])
|
|
90
|
+
return names.filter((n) => /^\.claude(?:-[\w-]+)?$/.test(n)).map((n) => join(home, n, 'projects')).filter((p) => existsSync(p))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** how a session folder names a repo's path */
|
|
94
|
+
const sessionName = (repo: string): string => repo.replace(/[^A-Za-z0-9]/g, '-')
|
|
95
|
+
|
|
96
|
+
export interface Collect {
|
|
97
|
+
home: string
|
|
98
|
+
repos: readonly string[]
|
|
99
|
+
/** each repo's `*.local.*` files; the daemon caches the git walk */
|
|
100
|
+
locals?: (repo: string) => Promise<string[]>
|
|
101
|
+
/** each repo's `backup` key; by default its repo.config.ts, read again when the file moves */
|
|
102
|
+
backupOf?: (repo: string) => Promise<RepoBackup | null>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const configs = new Map<string, { mtime: number; backup: RepoBackup | null }>()
|
|
106
|
+
|
|
107
|
+
/** a repo's `backup` key from its config, loaded again only when the file moved; a config that does not load throws */
|
|
108
|
+
export async function backupOfRepo(repo: string): Promise<RepoBackup | null> {
|
|
109
|
+
const path = join(repo, 'repo.config.ts')
|
|
110
|
+
const mtime = statSync(path, { throwIfNoEntry: false })?.mtimeMs
|
|
111
|
+
if (mtime === undefined) return null
|
|
112
|
+
const held = configs.get(repo)
|
|
113
|
+
if (held?.mtime === mtime) return held.backup
|
|
114
|
+
const backup = (await loadRepoConfig(repo, { fresh: held !== undefined })).backup ?? null
|
|
115
|
+
configs.set(repo, { mtime, backup })
|
|
116
|
+
return backup
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** a live db's own side files and the locks of a folder named whole: never part of it */
|
|
120
|
+
const WHOLE_DENY = /^(?:\.DS_Store)$|\.(?:pid|lock)$|-(?:wal|shm|journal)$/
|
|
121
|
+
|
|
122
|
+
/** every source the backup holds now, under the home folder, sorted by path */
|
|
123
|
+
export async function collect(o: Collect): Promise<Source[]> {
|
|
124
|
+
const files: string[] = []
|
|
125
|
+
const add = (abs: string): void => void files.push(abs)
|
|
126
|
+
// the backup's own objects and records, and the pids, move by themselves: left out, else every run differs
|
|
127
|
+
const sqlite = new Map<string, SqliteCut>([
|
|
128
|
+
[mediaDbPath(), { tables: ['files', 'objects'], except: { objects: "key like 'backup/%'" } }],
|
|
129
|
+
[machineDbPath(), { tables: null, except: { state: "name like 'pid:%' or name like 'backup-%'" } }],
|
|
130
|
+
])
|
|
131
|
+
await walk(join(homeDir(), 'veille'), () => true, files)
|
|
132
|
+
add(join(o.home, ORDER_FILE))
|
|
133
|
+
await walk(join(o.home, MACHINE_PRIVATE), () => true, files)
|
|
134
|
+
for (const root of await agentRoots(o.home)) for (const repo of o.repos) await walk(join(root, sessionName(repo), 'memory'), () => true, files)
|
|
135
|
+
// the git walks of ignored trees take seconds each: all at once
|
|
136
|
+
const locals = new Map(await Promise.all(o.repos.map(async (r) => [r, await (o.locals ?? localFiles)(r)] as const)))
|
|
137
|
+
const whole = new Set<string>()
|
|
138
|
+
const extra: Source[] = []
|
|
139
|
+
for (const repo of o.repos) {
|
|
140
|
+
let cfg: RepoBackup | null = null
|
|
141
|
+
try {
|
|
142
|
+
cfg = await (o.backupOf ?? backupOfRepo)(repo)
|
|
143
|
+
} catch (e) {
|
|
144
|
+
extra.push({ abs: join(repo, 'repo.config.ts'), rel: relative(o.home, join(repo, 'repo.config.ts')), size: 0, mtime: 0, broken: `its backup key is unread, the config does not load: ${(e as Error).message.split('\n')[0]}` })
|
|
145
|
+
}
|
|
146
|
+
const named = cfg?.paths ?? []
|
|
147
|
+
const tracked = new Set((await git(repo, ['ls-files', '-z', '--', '.shipkit', '.comfy-ts', ...REPO_EXTRA, ...named])).map((n) => join(repo, n)))
|
|
148
|
+
for (const p of named) {
|
|
149
|
+
const abs = join(repo, p)
|
|
150
|
+
const st = await lstat(abs).catch(() => null)
|
|
151
|
+
const got: string[] = []
|
|
152
|
+
if (st?.isFile()) got.push(abs)
|
|
153
|
+
else if (st?.isDirectory()) await walk(abs, (rel, isDir) => (isDir ? !['.git', 'node_modules'].includes(basename(rel)) : !WHOLE_DENY.test(basename(rel))), got)
|
|
154
|
+
else extra.push({ abs, rel: relative(o.home, abs), size: 0, mtime: 0, broken: `the repo's backup.paths names it and it is not on the disk` })
|
|
155
|
+
for (const f of got) if (!tracked.has(f)) {
|
|
156
|
+
files.push(f)
|
|
157
|
+
whole.add(f)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
for (const s of cfg?.sqlite ?? []) {
|
|
161
|
+
const { path, except } = typeof s === 'string' ? { path: s, except: undefined } : s
|
|
162
|
+
const hits = [...new Bun.Glob(path).scanSync({ cwd: repo, dot: true, onlyFiles: true })].filter((n) => !WHOLE_DENY.test(basename(n))).sort()
|
|
163
|
+
if (hits.length === 0) extra.push({ abs: join(repo, path), rel: relative(o.home, join(repo, path)), size: 0, mtime: 0, broken: `the repo's backup.sqlite names it and no file matches` })
|
|
164
|
+
for (const n of hits) sqlite.set(join(repo, n), { tables: null, ...(except ? { except } : {}) })
|
|
165
|
+
}
|
|
166
|
+
const mine: string[] = []
|
|
167
|
+
await walk(join(repo, '.shipkit'), shipkitKeep, mine)
|
|
168
|
+
await walk(join(repo, '.comfy-ts'), (rel, isDir) => (isDir ? COMFY_KEEP.some((k) => k === rel.split(sep)[0]) : comfyKeep(rel)), mine)
|
|
169
|
+
for (const x of REPO_EXTRA) {
|
|
170
|
+
const abs = join(repo, x)
|
|
171
|
+
const st = await lstat(abs).catch(() => null)
|
|
172
|
+
if (st?.isFile()) mine.push(abs)
|
|
173
|
+
else if (st?.isDirectory()) await walk(abs, (rel, isDir) => isDir || !FILE_DENY.test(basename(rel)), mine)
|
|
174
|
+
}
|
|
175
|
+
mine.push(...(locals.get(repo) ?? []))
|
|
176
|
+
for (const f of mine) if (!tracked.has(f)) files.push(f)
|
|
177
|
+
}
|
|
178
|
+
const out = new Map<string, Source>()
|
|
179
|
+
for (const abs of [...files, ...sqlite.keys()]) {
|
|
180
|
+
if (out.has(abs)) continue
|
|
181
|
+
const st = await lstat(abs).catch(() => null)
|
|
182
|
+
if (!st?.isFile()) continue
|
|
183
|
+
const rel = relative(o.home, abs)
|
|
184
|
+
if (rel.startsWith('..') || rel === '') continue
|
|
185
|
+
const cut = sqlite.get(abs)
|
|
186
|
+
out.set(abs, { abs, rel, size: st.size, mtime: Math.floor(st.mtimeMs), ...(cut !== undefined ? { sqlite: cut } : whole.has(abs) ? { whole: true as const } : {}) })
|
|
187
|
+
}
|
|
188
|
+
for (const x of extra) out.set(`extra\0${x.rel}`, x)
|
|
189
|
+
return [...out.values()].sort((a, b) => (a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** a cheap stamp of the sources that are files (a sqlite moves every few seconds; its snapshot runs on the clock) */
|
|
193
|
+
export const stampOfSources = (list: readonly Source[]): string => {
|
|
194
|
+
const h = new Bun.CryptoHasher('sha256')
|
|
195
|
+
for (const s of list) if (!s.sqlite) h.update(`${s.rel}\0${s.size}\0${s.mtime}\0${s.broken ?? ''}\n`)
|
|
196
|
+
return h.digest('hex')
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export const extOf = (rel: string): string => extname(rel).toLowerCase()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// a media file by its content (wiki
|
|
1
|
+
// a media file by its content (wiki tools/shipkit/media-store.md): its sha256, size and type, and the one key the Space
|
|
2
2
|
// keeps it under, `<kind>/<sha256>.<ext>`, the same for every caller and repo that names it
|
|
3
3
|
import { existsSync, statSync } from 'node:fs'
|
|
4
4
|
import { extname, join } from 'node:path'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// the daemon's media
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// the daemon's media job (wiki tools/shipkit/media-store.md, The daemon): one pass, in a child process the daemon
|
|
2
|
+
// starts every 30 s (home/daemon-jobs.ts), never on its loop. Every kind of every house repo scanned into the machine
|
|
3
|
+
// index once its store moved, what waits sent up, and (when the owner turned it on) the disk purged under 40 GB free.
|
|
4
|
+
// Each failure is one line in the daemon's log
|
|
4
5
|
import { existsSync } from 'node:fs'
|
|
5
6
|
import { machineGet, machineSet } from '../core/machine-db.ts'
|
|
6
7
|
import type { MediaKind } from './kind.ts'
|
|
@@ -9,7 +10,7 @@ import { machineSpace } from './space.ts'
|
|
|
9
10
|
import { syncKind } from './sync.ts'
|
|
10
11
|
import { mb, uploadWaiting } from './upload.ts'
|
|
11
12
|
|
|
12
|
-
const
|
|
13
|
+
export const MEDIA_EVERY_MS = 30_000
|
|
13
14
|
const PURGE_EVERY_MS = 10 * 60_000
|
|
14
15
|
const AUTO_KEY = 'media-purge-auto'
|
|
15
16
|
|
|
@@ -17,75 +18,60 @@ const AUTO_KEY = 'media-purge-auto'
|
|
|
17
18
|
export const autoPurgeOn = (): boolean => machineGet<boolean>(AUTO_KEY) === true
|
|
18
19
|
export const setAutoPurge = (on: boolean): boolean => machineSet(AUTO_KEY, on)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
21
|
+
/** each store's stamp at its last full scan, and the last purge: kept between two child runs */
|
|
22
|
+
const SYNCED = 'media-synced'
|
|
23
|
+
const PURGED_AT = 'media-purged-at'
|
|
24
|
+
const NO_SPACE = 'media-no-space'
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (r.filled > 0) o.print(`ok: media store: ${r.filled} ${kind.kind} files of ${root} hashed${r.left > 0 ? `, ${r.left} to go` : ''}`)
|
|
51
|
-
} catch (e) {
|
|
52
|
-
o.printErr(`WARN media store: the ${kind.kind} files of ${root} did not sync: ${(e as Error).message}`)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const { space, why } = await machineSpace()
|
|
56
|
-
if (!space) {
|
|
57
|
-
if (!toldNoSpace) o.printErr(`WARN media store: nothing goes up: ${why}`)
|
|
58
|
-
toldNoSpace = true
|
|
59
|
-
return
|
|
26
|
+
/** one pass of the daemon's media job, in its child process: what `startMediaStore` does each tick, with what it
|
|
27
|
+
* remembers in the machine db */
|
|
28
|
+
export async function mediaTick(o: { roots: string[]; kinds: () => readonly MediaKind[]; print: (l: string) => void; printErr: (l: string) => void }): Promise<void> {
|
|
29
|
+
const synced = machineGet<Record<string, string>>(SYNCED) ?? {}
|
|
30
|
+
const stores = o.roots.flatMap((root) =>
|
|
31
|
+
o.kinds().flatMap((kind) => {
|
|
32
|
+
const dir = kind.storeOf(root)
|
|
33
|
+
return dir && existsSync(dir) ? [{ kind, root, dir }] : []
|
|
34
|
+
}),
|
|
35
|
+
)
|
|
36
|
+
try {
|
|
37
|
+
let moved = false
|
|
38
|
+
for (const { kind, root, dir } of stores) {
|
|
39
|
+
const id = `${kind.kind}\0${dir}`
|
|
40
|
+
try {
|
|
41
|
+
const stamp = kind.stamp(dir)
|
|
42
|
+
if (synced[id] === stamp) continue
|
|
43
|
+
const r = await syncKind(kind, dir, { fill: 50 })
|
|
44
|
+
// files left to hash: the next pass goes on with them
|
|
45
|
+
synced[id] = r.left > 0 ? '' : stamp
|
|
46
|
+
moved = true
|
|
47
|
+
if (r.filled > 0) o.print(`ok: media store: ${r.filled} ${kind.kind} files of ${root} hashed${r.left > 0 ? `, ${r.left} to go` : ''}`)
|
|
48
|
+
} catch (e) {
|
|
49
|
+
o.printErr(`WARN media store: the ${kind.kind} files of ${root} did not sync: ${(e as Error).message}`)
|
|
60
50
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
51
|
+
}
|
|
52
|
+
if (moved) machineSet(SYNCED, synced)
|
|
53
|
+
const { space, why } = await machineSpace()
|
|
54
|
+
// said once per reason, not once per pass: a pass is a child of its own
|
|
55
|
+
if (!space) {
|
|
56
|
+
if (machineGet<string>(NO_SPACE) !== why) o.printErr(`WARN media store: nothing goes up: ${why}`)
|
|
57
|
+
machineSet(NO_SPACE, why)
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
machineSet(NO_SPACE, '')
|
|
61
|
+
const up = await uploadWaiting(space, { limit: 200, jobs: 3 })
|
|
62
|
+
if (up.up + up.there > 0) o.print(`ok: media store: ${up.up} up (${mb(up.bytes)})${up.there > 0 ? `, ${up.there} already there` : ''}`)
|
|
63
|
+
if (up.failed.length > 0) o.printErr(`WARN media store: ${up.failed.length} uploads failed, tried again later; first: ${up.failed[0]?.key}: ${up.failed[0]?.error}`)
|
|
64
|
+
if (autoPurgeOn() && Date.now() - (machineGet<number>(PURGED_AT) ?? 0) > PURGE_EVERY_MS) {
|
|
65
|
+
machineSet(PURGED_AT, Date.now())
|
|
66
|
+
for (const { kind, root, dir } of stores) {
|
|
67
|
+
if (freeBytes(dir) >= FREE_MIN_BYTES) continue
|
|
68
|
+
const { candidates } = await purgeCandidates(kind, dir)
|
|
69
|
+
const r = await purge(kind, dir, space, candidates, { enough: () => freeBytes(dir) >= FREE_MIN_BYTES })
|
|
70
|
+
if (r.files > 0) o.print(`ok: media store: the disk under ${mb(FREE_MIN_BYTES)} free, ${r.files} ${kind.kind} files of ${root} purged (${mb(r.freed)})`)
|
|
71
|
+
if (r.refused.length > 0) o.printErr(`WARN media store: ${r.refused.length} ${kind.kind} files of ${root} kept: ${r.refused[0]?.key}: ${r.refused[0]?.why}`)
|
|
73
72
|
}
|
|
74
|
-
} catch (e) {
|
|
75
|
-
o.printErr(`WARN media store: the pass broke: ${(e as Error).message}`)
|
|
76
|
-
} finally {
|
|
77
|
-
busy = false
|
|
78
73
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
every.unref()
|
|
82
|
-
const boot = setTimeout(() => void once(), 15_000)
|
|
83
|
-
boot.unref()
|
|
84
|
-
return {
|
|
85
|
-
stop: () => {
|
|
86
|
-
clearInterval(every)
|
|
87
|
-
clearTimeout(boot)
|
|
88
|
-
},
|
|
89
|
-
once,
|
|
74
|
+
} catch (e) {
|
|
75
|
+
o.printErr(`WARN media store: the pass broke: ${(e as Error).message}`)
|
|
90
76
|
}
|
|
91
77
|
}
|
package/src/media-store/db.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// THE MACHINE'S MEDIA INDEX (wiki
|
|
1
|
+
// THE MACHINE'S MEDIA INDEX (wiki tools/shipkit/media-store.md, The index): one sqlite file in the home's state folder,
|
|
2
2
|
// never in a repo, for every media file of this machine, whatever kind holds it. It is DERIVED: each kind's files stay
|
|
3
3
|
// the truth, and a deleted index builds again from them (a file's place in the Space is found again by a HEAD). It holds
|
|
4
4
|
// each file a kind names (local or not), each Space object (up or waiting, its retries), and the review store's item
|
package/src/media-store/fact.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// a media file known by its content (wiki
|
|
1
|
+
// a media file known by its content (wiki tools/shipkit/media-store.md): the shape every caller records beside its file
|
|
2
2
|
// name. Pure, so a page's types read it too
|
|
3
3
|
export interface MediaFact {
|
|
4
4
|
/** sha256, hex */
|
package/src/media-store/hand.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// the generic kind (wiki
|
|
1
|
+
// the generic kind (wiki tools/shipkit/media-store.md, Put a file from any repo): a label no `MediaKind` of the code
|
|
2
2
|
// owns, its files named by hand through `sk media put`. The index is its only record, so its scan reads the index's
|
|
3
3
|
// own rows back and asks the disk whether each file still holds the bytes of its key; nothing else names them
|
|
4
4
|
import { statSync } from 'node:fs'
|
package/src/media-store/kind.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// what a caller of the media store plugs in (wiki
|
|
1
|
+
// what a caller of the media store plugs in (wiki tools/shipkit/media-store.md, A kind): where its files live in a repo,
|
|
2
2
|
// what they are, and what must stay on the disk. The store does the rest: the index, the upload, the signed URL, the
|
|
3
3
|
// fetch back, the purge. A row's path is always `join(store, item, name)`, the one form every scan, pin and delete uses
|
|
4
4
|
import type { MediaFact } from './fact.ts'
|
package/src/media-store/purge.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// the disk lets go of media the Space holds (wiki
|
|
1
|
+
// the disk lets go of media the Space holds (wiki tools/shipkit/media-store.md, The purge). A file goes only when the
|
|
2
2
|
// index says up AND a HEAD answers its size AND its kind's `beforePurge` passed. Kept: every row its kind pins, every
|
|
3
3
|
// row used in the last `older` days, every row nothing names. Oldest first. The candidates and the delete read one path
|
|
4
4
|
// form, `join(store, item, name)`, from the same index rows
|
package/src/media-store/put.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// a file put in the store by hand, and a fresh link to anything it holds (wiki
|
|
1
|
+
// a file put in the store by hand, and a fresh link to anything it holds (wiki tools/shipkit/media-store.md, Put a file
|
|
2
2
|
// from any repo): the one way a repo's agent keeps a file in the private Space. The index row is written before the
|
|
3
3
|
// upload, so a failed upload waits for the daemon like any other; a link lasts at most 7 days, the object for good
|
|
4
4
|
import { realpathSync, statSync } from 'node:fs'
|
|
@@ -41,10 +41,12 @@ export interface Link {
|
|
|
41
41
|
expires: string
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/** the labels a kind of the code owns: their rows come from their own scan, never a hand put
|
|
44
|
+
/** the labels a kind of the code owns: their rows come from their own scan, never a hand put. `backup` too: a hand
|
|
45
|
+
* row under it would make its file a purge candidate, and a backup never frees the live file */
|
|
45
46
|
async function codeLabels(): Promise<Set<string>> {
|
|
46
47
|
const { MEDIA_KINDS } = await import('../media-kinds.ts')
|
|
47
|
-
|
|
48
|
+
const { BACKUP_LABEL } = await import('./backup/keys.ts')
|
|
49
|
+
return new Set([...MEDIA_KINDS.map((k) => k.kind), BACKUP_LABEL])
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/** where the index keeps a file: its repo (else its folder) as the store, the folder in it, its name */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// a media file from the disk or the Space (wiki
|
|
1
|
+
// a media file from the disk or the Space (wiki tools/shipkit/media-store.md, Read): a URL signed for a file the disk
|
|
2
2
|
// let go, and the file fetched back into its place, checked by its sha, for a tool that needs its bytes
|
|
3
3
|
import { existsSync, renameSync, rmSync, statSync } from 'node:fs'
|
|
4
4
|
import { resolve } from 'node:path'
|
package/src/media-store/space.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// the private S3 bucket that keeps every media file of the machine's store (wiki
|
|
1
|
+
// the private S3 bucket that keeps every media file of the machine's store (wiki tools/shipkit/media-store.md), named by
|
|
2
2
|
// the house config's `serve.mediaSpace`. Every object is PRIVATE: never a public-read ACL, never a bucket policy. A page
|
|
3
3
|
// reads one through a URL signed for one hour, on the CDN edge. The key pair (`KEY:SECRET`) is read through the house's
|
|
4
4
|
// `credsReadCommand`, held in memory only: never written to a file, never printed
|
|
@@ -45,6 +45,8 @@ export interface Space {
|
|
|
45
45
|
signed(key: string, seconds?: number, as?: { name: string; type: string }): string
|
|
46
46
|
/** the object written at `to`, through a file beside it renamed: no reader sees half of it */
|
|
47
47
|
get(key: string, to: string): Promise<void>
|
|
48
|
+
/** every object under the prefix, with its size, page after page (ListObjectsV2) */
|
|
49
|
+
list(prefix: string): Promise<{ key: string; size: number }[]>
|
|
48
50
|
/** the bucket's versioning: `Enabled`, `Suspended`, or `off` when it was never turned on (GetBucketVersioning) */
|
|
49
51
|
versioning(): Promise<'Enabled' | 'Suspended' | 'off'>
|
|
50
52
|
/** turns versioning on, so an object deleted or overwritten from outside keeps its older version (PutBucketVersioning) */
|
|
@@ -124,6 +126,16 @@ export function spaceOf(c: SpaceConfig): Space {
|
|
|
124
126
|
rmSync(tmp, { force: true })
|
|
125
127
|
}
|
|
126
128
|
},
|
|
129
|
+
async list(prefix) {
|
|
130
|
+
const out: { key: string; size: number }[] = []
|
|
131
|
+
let token: string | undefined
|
|
132
|
+
do {
|
|
133
|
+
const page = await client.list({ prefix, maxKeys: 1000, ...(token ? { continuationToken: token } : {}) })
|
|
134
|
+
for (const o of page.contents ?? []) out.push({ key: o.key, size: o.size ?? 0 })
|
|
135
|
+
token = page.isTruncated ? page.nextContinuationToken : undefined
|
|
136
|
+
} while (token)
|
|
137
|
+
return out
|
|
138
|
+
},
|
|
127
139
|
async versioning() {
|
|
128
140
|
const s = /<Status>([^<]+)<\/Status>/.exec(await bucketCall(c, 'GET', 'versioning'))?.[1]
|
|
129
141
|
return s === 'Enabled' || s === 'Suspended' ? s : 'off'
|
|
@@ -138,7 +150,14 @@ let held: Promise<{ space: Space | null; why: string }> | null = null
|
|
|
138
150
|
|
|
139
151
|
/** the machine's Space, from the house config and its key, read once per process; null with the reason when there is none */
|
|
140
152
|
export function machineSpace(): Promise<{ space: Space | null; why: string }> {
|
|
141
|
-
held ??= (
|
|
153
|
+
held ??= spaceFromHouse()
|
|
154
|
+
return held
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** the house's Space signed with the key pair of `secret` (the config's own key when none is given), read anew: a one
|
|
158
|
+
* time key with more rights (turning versioning on) never replaces the machine's held one */
|
|
159
|
+
export function spaceFromHouse(secret?: string): Promise<{ space: Space | null; why: string }> {
|
|
160
|
+
return (async () => {
|
|
142
161
|
if (process.env.SHIPKIT_SPACES === 'off') return { space: null, why: 'SHIPKIT_SPACES=off' }
|
|
143
162
|
const { houseRootOf } = await import('../home/home-start.ts')
|
|
144
163
|
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
@@ -148,17 +167,17 @@ export function machineSpace(): Promise<{ space: Space | null; why: string }> {
|
|
|
148
167
|
const r = c.serve?.mediaSpace
|
|
149
168
|
if (!r) return { space: null, why: `the house config (${house}) names no serve.mediaSpace` }
|
|
150
169
|
if (!c.credsReadCommand) return { space: null, why: `the house config (${house}) declares no credsReadCommand to read ${r.secret}` }
|
|
170
|
+
const name = secret ?? r.secret
|
|
151
171
|
let v = ''
|
|
152
172
|
try {
|
|
153
|
-
v = readSecret(c.credsReadCommand,
|
|
173
|
+
v = readSecret(c.credsReadCommand, name)
|
|
154
174
|
} catch (e) {
|
|
155
175
|
return { space: null, why: (e as Error).message }
|
|
156
176
|
}
|
|
157
177
|
const at = v.indexOf(':')
|
|
158
|
-
if (at <= 0) return { space: null, why: `the secret ${
|
|
178
|
+
if (at <= 0) return { space: null, why: `the secret ${name} is no KEY:SECRET pair` }
|
|
159
179
|
return { space: spaceOf({ ...r, cdn: r.cdn ?? null, creds: { accessKeyId: v.slice(0, at), secretAccessKey: v.slice(at + 1) } }), why: '' }
|
|
160
180
|
})().catch((e: unknown) => ({ space: null, why: `the house config does not load: ${(e as Error).message}` }))
|
|
161
|
-
return held
|
|
162
181
|
}
|
|
163
182
|
|
|
164
183
|
/** a test's own Space in place of the machine's; undefined gives the machine's back */
|