rvlib-shipkit 2.22.1 → 2.24.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 +44 -0
- package/package.json +1 -1
- package/src/agent-time/render.ts +28 -14
- package/src/agent-time/report.ts +46 -25
- package/src/agent-time/store.ts +30 -10
- package/src/agent-time/timeline.ts +43 -15
- package/src/annex/annex.ts +3 -0
- package/src/annex/born.ts +464 -0
- package/src/annex/flush.ts +46 -0
- package/src/annex/offload.ts +171 -38
- package/src/annex/snapshots.ts +53 -0
- package/src/annex/tidy.ts +368 -0
- package/src/asks/asks-queue.ts +32 -11
- package/src/checks/SK041-annex-links.check.ts +4 -2
- package/src/checks/SK043-scratch-on-the-mac.check.ts +45 -0
- package/src/checks/SK044-behind-upstream.check.ts +38 -0
- package/src/cli/cmd_Annex.ts +60 -9
- package/src/cli/cmd_Asks.ts +2 -0
- package/src/cli/cmd_Backup.ts +7 -5
- package/src/cli/cmd_Bump.ts +1 -0
- package/src/cli/cmd_Capacity.ts +26 -0
- package/src/cli/cmd_Check.ts +1 -0
- package/src/cli/cmd_Checks.ts +1 -0
- package/src/cli/cmd_Ci.ts +1 -0
- package/src/cli/cmd_Commands.ts +50 -14
- package/src/cli/cmd_Home.ts +0 -1
- package/src/cli/cmd_Hooks.ts +1 -0
- package/src/cli/cmd_Mv.ts +1 -0
- package/src/cli/cmd_Rec.ts +17 -7
- package/src/cli/cmd_Reflect.ts +1 -0
- package/src/cli/cmd_Releases.ts +1 -0
- package/src/cli/cmd_Review.ts +124 -17
- package/src/cli/cmd_Secret.ts +41 -2
- package/src/cli/cmd_Shot.ts +1 -0
- package/src/cli/cmd_Status.ts +1 -0
- package/src/cli/cmd_Time.ts +3 -1
- package/src/cli/cmd_Tmp.ts +82 -0
- package/src/cli/cmd_Wiki.ts +1 -0
- package/src/cli/registry.ts +13 -1
- package/src/collections/pings.ts +1 -1
- package/src/core/capacity.ts +71 -0
- package/src/core/check-runner.ts +86 -15
- package/src/core/machine-db.ts +8 -0
- package/src/core/motherhome.ts +67 -9
- package/src/core/slots.ts +49 -12
- package/src/core/trace-audit.ts +4 -1
- package/src/drill/run.ts +5 -2
- package/src/home/daemon-jobs.ts +10 -3
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +1 -0
- package/src/home/home-launchd.ts +11 -3
- package/src/home/home-routes.ts +11 -4
- package/src/home/machine-host.ts +65 -0
- package/src/home/machine-stores.ts +30 -4
- package/src/home/machine-temp.ts +493 -0
- package/src/home/other-macs.ts +74 -0
- package/src/home/pm.ts +4 -1
- package/src/home/run-daemon.ts +10 -2
- package/src/home/run-pm.ts +1 -0
- package/src/home/serve-web.ts +2 -2
- package/src/home/via-hub.ts +6 -1
- package/src/identities/identities.ts +92 -24
- package/src/init-repo.ts +7 -3
- package/src/ledger/ledger.ts +6 -0
- package/src/ledger/store.ts +6 -0
- package/src/media-store/backup/keys.ts +21 -6
- package/src/media-store/backup/manifest.ts +52 -11
- package/src/media-store/backup/restore.ts +17 -10
- package/src/media-store/backup/run.ts +5 -2
- package/src/media-store/backup/sources.ts +2 -1
- package/src/media-store/daemon.ts +2 -2
- package/src/media-store/purge.ts +4 -0
- package/src/mv/mv-md.ts +121 -42
- package/src/recordings/load.ts +3 -3
- package/src/recordings/model.ts +7 -0
- package/src/recordings/open.ts +12 -0
- package/src/recordings/presets.ts +12 -5
- package/src/recordings/recorder-app/Capture.swift +34 -5
- package/src/recordings/recorder-app/Clip.swift +126 -17
- package/src/recordings/recorder-app/Editor.swift +177 -7
- package/src/recordings/recorder-app/Hud.swift +189 -0
- package/src/recordings/recorder-app/Tray.swift +179 -36
- package/src/recordings/recorder-app/icon.svg +16 -0
- package/src/recordings/recorder-app/main.swift +349 -18
- package/src/recordings/recorder-app.ts +8 -4
- package/src/recordings/recorder.shipkit.ts +2 -1
- package/src/recordings/routes.ts +52 -6
- package/src/recordings/run-recorder.ts +2 -1
- package/src/recordings/share.ts +27 -0
- package/src/recordings/take.ts +36 -4
- package/src/recordings/view.ts +11 -0
- package/src/reflect/transcript.ts +56 -11
- package/src/releases/from-card.ts +45 -3
- package/src/releases/model.ts +6 -0
- package/src/releases/store.ts +8 -1
- package/src/repo-config.ts +14 -4
- package/src/review/cells.ts +24 -3
- package/src/review/format.ts +33 -9
- package/src/review/media-kind.ts +14 -11
- package/src/review/media-read.ts +6 -5
- package/src/review/model.ts +104 -7
- package/src/review/paste.ts +2 -1
- package/src/review/previews.ts +123 -36
- package/src/review/routes.ts +29 -18
- package/src/review/store.ts +74 -12
- package/src/review/threads.ts +7 -5
- package/src/secrets/copy.ts +110 -0
- package/src/secrets/list.ts +17 -7
- package/src/serve/hub-app/home-strip.css +5 -0
- package/src/serve/hub-app/home-strip.tsx +18 -0
- package/src/serve/hub-app/hub-app.tsx +2 -1
- package/src/serve/hub-app/hub.css +18 -0
- package/src/serve/hub-app/inbox.css +1 -0
- package/src/serve/hub-app/pull-refresh.tsx +88 -0
- package/src/serve/hub-app/recordings-st.ts +135 -24
- package/src/serve/hub-app/recordings-view.tsx +293 -54
- package/src/serve/hub-app/recordings.css +77 -24
- package/src/serve/hub-app/review/review-cells.tsx +52 -13
- package/src/serve/hub-app/review/review-list.tsx +6 -1
- package/src/serve/hub-app/review/review-st.ts +6 -5
- package/src/serve/hub-app/review/review-thread.tsx +3 -1
- package/src/serve/hub-app/review/review-views.tsx +18 -11
- package/src/serve/hub-app/review/thread-st.ts +82 -14
- package/src/serve/hub-app/review.css +15 -2
- package/src/serve/hub-runtime.ts +2 -1
- package/src/serve/run-serve.ts +4 -2
- package/src/serve/serve-hub.ts +9 -2
- package/src/shipkit-files.ts +5 -0
- package/src/social/drafts.ts +4 -3
- package/src/social/load.ts +7 -2
- package/src/social/publish/discord.ts +10 -3
- package/src/suite/child-tools.ts +45 -0
- package/src/suite/judge-suites.ts +10 -22
- package/src/suite/select.ts +83 -8
- package/src/suite/suite-cli.ts +38 -14
- package/src/suite/suite-cores.ts +68 -0
- package/src/suite/suite-reads-preload.ts +8 -6
- package/src/ts/config.ts +44 -0
- package/src/ts/rename.ts +11 -1
package/src/home/via-hub.ts
CHANGED
|
@@ -66,7 +66,7 @@ export async function runViaHub(root: string, kind: 'ci' | 'check', opts: Record
|
|
|
66
66
|
...(Object.keys(env).length > 0 ? { env } : {}),
|
|
67
67
|
}
|
|
68
68
|
// the home waits for a hub still loading before it answers
|
|
69
|
-
const post = (): Promise<Response> => fetch(`${daemonUrl()}${hubBase(name)}/api/run`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ kind, opts: sent }) })
|
|
69
|
+
const post = (): Promise<Response> => fetch(`${daemonUrl()}${hubBase(name)}/api/run`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ kind, opts: sent, root: homeRepo(root) }) })
|
|
70
70
|
return followRun({ name, jobRoot: homeRepo(root), post, up: () => daemonUp(), io })
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -100,6 +100,11 @@ export async function followRun(o: {
|
|
|
100
100
|
if (r != null) {
|
|
101
101
|
// not one of the home's repos: nothing to send it to
|
|
102
102
|
if (r.status === 404) return null
|
|
103
|
+
// the home's repo of this name is another tree (a clone elsewhere)
|
|
104
|
+
if (r.status === 421) {
|
|
105
|
+
io.printErr(`note: ${await r.text()}, so this gate runs in process`)
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
103
108
|
if (r.status === 409) {
|
|
104
109
|
io.printErr(`note: the home could not load ${name}'s hub (${await r.text()}), so this gate runs in process`)
|
|
105
110
|
return null
|
|
@@ -6,7 +6,7 @@ import { homedir } from 'node:os'
|
|
|
6
6
|
import { isAbsolute, join } from 'node:path'
|
|
7
7
|
import { LAYOUT } from '../core/layout.ts'
|
|
8
8
|
import { parseFrontmatter, rows, section, table, type ProfileRow } from '../social/md.ts'
|
|
9
|
-
import { ceilingOf, type PostRating } from './rating.ts'
|
|
9
|
+
import { ceilingOf, ratingIn, type PostRating } from './rating.ts'
|
|
10
10
|
import { uploadsOf, type Upload } from './shown.ts'
|
|
11
11
|
import { stepRefs } from './steps.ts'
|
|
12
12
|
|
|
@@ -97,6 +97,10 @@ export type Account = {
|
|
|
97
97
|
ceiling: PostRating
|
|
98
98
|
/** the venue's own switch a rated post needs, said on its card (X: « mark the media sensitive »); empty, none */
|
|
99
99
|
sensitive: string
|
|
100
|
+
/** who links to it (`listed:`): every account, or only one rated nsfw */
|
|
101
|
+
listed: Listed
|
|
102
|
+
/** the most links its list holds (`links max:`, the venue's slots); null, no cap */
|
|
103
|
+
linksMax: number | null
|
|
100
104
|
/** the media a post there may carry (`limits:`); empty, none known */
|
|
101
105
|
limits: MediaLimits
|
|
102
106
|
/** absolute */
|
|
@@ -192,24 +196,61 @@ function merged(shared: ProfileRow[], own: ProfileRow[]): ProfileRow[] {
|
|
|
192
196
|
return [...shared.map((r) => mine.get(r.field) ?? r), ...own.filter((r) => !shared.some((s) => s.field === r.field))]
|
|
193
197
|
}
|
|
194
198
|
|
|
195
|
-
/** a text
|
|
196
|
-
*
|
|
199
|
+
/** a text as he pastes it: `[[field]]` that row's value, `<br>` a new line (a table cell holds none); `where` names
|
|
200
|
+
* the text in an error line. A row naming another row, or `self`, is refused, its words kept */
|
|
201
|
+
export function filledText(value: string, rows: readonly ProfileRow[], where: string, errors: string[], self?: ProfileRow): string {
|
|
202
|
+
if (!/\[\[|<br>/.test(value)) return value
|
|
203
|
+
return value
|
|
204
|
+
.replace(/\[\[([^\]]+)\]\]/g, (all, f: string) => {
|
|
205
|
+
const at = rows.find((r) => r.field === f)
|
|
206
|
+
if (at == null || at === self || /\[\[/.test(at.value)) {
|
|
207
|
+
errors.push(`${where} names [[${f}]], ${at == null ? 'no row' : 'a row that names another'}`)
|
|
208
|
+
return all
|
|
209
|
+
}
|
|
210
|
+
return at.value
|
|
211
|
+
})
|
|
212
|
+
.replace(/\s*<br>\s*/g, '\n')
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** each text row filled (`filledText`), so a venue's text says the bio once, never « the bio » in words */
|
|
197
216
|
export function filledRows(list: ProfileRow[], file: string, errors: string[]): ProfileRow[] {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
return list.map((r) => (r.files.length > 0 ? r : { ...r, value: filledText(r.value, list, `${file}: row ${r.field}`, errors, r) }))
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** the computed row an account lists its links in, `[[links]]` in a text */
|
|
221
|
+
export const LINKS = 'links'
|
|
222
|
+
/** `listed:` an account is linked from every account (`all`, the default), or only from an account rated nsfw */
|
|
223
|
+
const LISTED = ['all', 'nsfw'] as const
|
|
224
|
+
export type Listed = (typeof LISTED)[number]
|
|
225
|
+
/** the site's label in a list of links */
|
|
226
|
+
export const SITE_LABEL = 'Site'
|
|
227
|
+
|
|
228
|
+
export type LinkSource = { id: string; name: string; order: number; live: string; listed: Listed; rating: string; linksMax: number | null }
|
|
229
|
+
|
|
230
|
+
/** the links an account shows, one `<label>: <url>` a line: the identity's site first, then every other account online
|
|
231
|
+
* (`live`) in its order, but one `listed: nsfw` on an account not rated nsfw; its `links max` (its slot count) cuts
|
|
232
|
+
* the tail. Read from the accounts' own front matter, so an account that goes live joins every list by itself */
|
|
233
|
+
export function linksOf(self: LinkSource, all: readonly LinkSource[], site: string): string[] {
|
|
234
|
+
const out = site === '' ? [] : [`${SITE_LABEL}: ${site}`]
|
|
235
|
+
for (const a of [...all].sort((x, y) => x.order - y.order || x.id.localeCompare(y.id)))
|
|
236
|
+
if (a.id !== self.id && a.live !== '' && (a.listed === 'all' || self.rating === 'nsfw')) out.push(`${a.name}: ${a.live}`)
|
|
237
|
+
return self.linksMax == null ? out : out.slice(0, self.linksMax)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function listedOf(v: string | undefined, file: string, errors: string[]): Listed {
|
|
241
|
+
const w = (v ?? '').trim()
|
|
242
|
+
if (w === '') return 'all'
|
|
243
|
+
if ((LISTED as readonly string[]).includes(w)) return w as Listed
|
|
244
|
+
errors.push(`${file}: listed "${w}" is not ${LISTED.join(' or ')}`)
|
|
245
|
+
return 'all'
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function linksMaxOf(v: string | undefined, file: string, errors: string[]): number | null {
|
|
249
|
+
const w = (v ?? '').trim()
|
|
250
|
+
if (w === '') return null
|
|
251
|
+
if (/^\d+$/.test(w)) return Number(w)
|
|
252
|
+
errors.push(`${file}: links max "${w}" is no count`)
|
|
253
|
+
return null
|
|
213
254
|
}
|
|
214
255
|
|
|
215
256
|
function places(dir: string, errors: string[]): Place[] {
|
|
@@ -329,11 +370,28 @@ function legal(dir: string, files: string | null): Legal | null {
|
|
|
329
370
|
}
|
|
330
371
|
}
|
|
331
372
|
|
|
332
|
-
|
|
373
|
+
/** an account's file read, its rows not filled yet: every account's list of links needs each one's front matter first */
|
|
374
|
+
type AccountFile = { id: string; dir: string; file: string; meta: Record<string, string>; body: string; own: ProfileRow[]; src: LinkSource }
|
|
375
|
+
|
|
376
|
+
function accountFile(id: string, dir: string, files: string | null, errors: string[]): AccountFile {
|
|
333
377
|
const file = join(dir, 'account.md')
|
|
334
378
|
const { meta, body } = parseFrontmatter(read(file))
|
|
335
|
-
linkErrors(file, meta, ['profile', 'live', 'write', 'inbox', 'stats'], errors)
|
|
336
379
|
const own = rows(body, 'Profile', files)
|
|
380
|
+
const src: LinkSource = {
|
|
381
|
+
id,
|
|
382
|
+
name: meta.name ?? id,
|
|
383
|
+
order: Number(meta.order ?? 99),
|
|
384
|
+
live: meta.live ?? '',
|
|
385
|
+
listed: listedOf(meta.listed, file, errors),
|
|
386
|
+
rating: ratingIn(own),
|
|
387
|
+
linksMax: linksMaxOf(meta['links max'], file, errors),
|
|
388
|
+
}
|
|
389
|
+
return { id, dir, file, meta, body, own, src }
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function account(identity: string, f: AccountFile, shared: ProfileRow[], files: string | null, errors: string[]): Account {
|
|
393
|
+
const { id, dir, file, meta, body, own } = f
|
|
394
|
+
linkErrors(file, meta, ['profile', 'live', 'write', 'inbox', 'stats'], errors)
|
|
337
395
|
errors.push(...copiedRows(own, shared, file))
|
|
338
396
|
const merge = filledRows(merged(shared, own), file, errors)
|
|
339
397
|
const automation = meta.automation ?? 'none'
|
|
@@ -343,8 +401,8 @@ function account(identity: string, id: string, dir: string, shared: ProfileRow[]
|
|
|
343
401
|
return {
|
|
344
402
|
id,
|
|
345
403
|
identity,
|
|
346
|
-
name:
|
|
347
|
-
order:
|
|
404
|
+
name: f.src.name,
|
|
405
|
+
order: f.src.order,
|
|
348
406
|
handle: meta.handle ?? '',
|
|
349
407
|
profile: meta.profile ?? '',
|
|
350
408
|
live: meta.live ?? '',
|
|
@@ -364,6 +422,8 @@ function account(identity: string, id: string, dir: string, shared: ProfileRow[]
|
|
|
364
422
|
guild,
|
|
365
423
|
ceiling: ceilingOf(meta.posts, file, errors),
|
|
366
424
|
sensitive: meta.sensitive ?? '',
|
|
425
|
+
listed: f.src.listed,
|
|
426
|
+
linksMax: f.src.linksMax,
|
|
367
427
|
limits: limitsOf(meta.limits, file, errors),
|
|
368
428
|
file,
|
|
369
429
|
dir,
|
|
@@ -397,15 +457,23 @@ function identity(id: string, dir: string, errors: string[]): Identity {
|
|
|
397
457
|
// filled once here, so the profile shows and copies a shared text (a tier's lines) as an account does
|
|
398
458
|
const shared = filledRows(rows(body, 'Profile', files), file, errors)
|
|
399
459
|
const at = join(dir, 'accounts')
|
|
400
|
-
const
|
|
460
|
+
const found: AccountFile[] = []
|
|
401
461
|
if (existsSync(at))
|
|
402
462
|
for (const a of readdirSync(at).sort()) {
|
|
403
463
|
const adir = join(at, a)
|
|
404
464
|
if (!statSync(adir).isDirectory()) continue
|
|
405
465
|
if (!SLUG.test(a)) errors.push(`${adir}: an account folder is kebab case`)
|
|
406
466
|
else if (!existsSync(join(adir, 'account.md'))) errors.push(`${adir}: no account.md`)
|
|
407
|
-
else
|
|
467
|
+
else found.push(accountFile(a, adir, files, errors))
|
|
408
468
|
}
|
|
469
|
+
// the site is the `link` row; each account inherits its list as a row, `[[links]]` in its texts, none while the list
|
|
470
|
+
// is empty (no site, nothing online), so a text naming it says so loud
|
|
471
|
+
const site = shared.find((r) => r.field === 'link' && r.files.length === 0)?.value.trim() ?? ''
|
|
472
|
+
const sources = found.map((f) => f.src)
|
|
473
|
+
const accounts = found.map((f) => {
|
|
474
|
+
const links = linksOf(f.src, sources, site)
|
|
475
|
+
return account(id, f, links.length === 0 ? shared : [...shared, { field: LINKS, value: links.join('\n'), files: [] }], files, errors)
|
|
476
|
+
})
|
|
409
477
|
accounts.sort((a, b) => a.order - b.order || a.id.localeCompare(b.id))
|
|
410
478
|
for (const a of accounts) if (a.automation === 'live' && a.secret === '') errors.push(`${a.file}: automation live names no secret (its token name)`)
|
|
411
479
|
return {
|
package/src/init-repo.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { reportToMotherhome } from './core/motherhome.ts'
|
|
|
17
17
|
import { ensureGitRepo, publishRepo, type Run } from './git-bootstrap.ts'
|
|
18
18
|
import { defineRepo, loadRepoConfig, resolveFloor } from './repo-config.ts'
|
|
19
19
|
import { gitignorePolicy } from './checks/SK004-gitignore-policy.check.ts'
|
|
20
|
+
import { armHooks } from './hooks/run-hooks.ts'
|
|
20
21
|
|
|
21
22
|
// This lands as SOURCE in the repo being wired, so its comments answer to that
|
|
22
23
|
// repo's comment style, not to this file's. Dash punctuation is banned there
|
|
@@ -177,13 +178,16 @@ export async function initRepo(root: string, opts: InitOpts = {}): Promise<numbe
|
|
|
177
178
|
|
|
178
179
|
/** ONE WAY IN, both halves, through the SAME fixers `shipkit check --fix` runs
|
|
179
180
|
* (tools/shipkit/one-way-in.md). Nothing here is a second implementation: rule SK001
|
|
180
|
-
* routes the package.json scripts, rule SK013 writes the harness policy,
|
|
181
|
-
*
|
|
182
|
-
*
|
|
181
|
+
* routes the package.json scripts, rule SK013 writes the harness policy, the
|
|
182
|
+
* gate's own arming wires the commit hooks, and init just calls them so a
|
|
183
|
+
* wired repo is born enforced (its first commit is gated) and a re-run
|
|
184
|
+
* repairs one that was not. The deny is a RESTRICTION, which is why it lands
|
|
183
185
|
* unconditionally where the scaffold's allow list stays opt in. */
|
|
184
186
|
async function repairOneWayIn(root: string, config: Parameters<typeof defineRepo>[0], p: (line: string) => void): Promise<void> {
|
|
185
187
|
const pkg = await packageJsonShape.repair!(CheckCtx.open({ root, config }))
|
|
186
188
|
if (pkg.changed) p(`ok: package.json — ${pkg.summary}`)
|
|
187
189
|
const policy = await oneWayInPolicy.repair!(CheckCtx.open({ root, config }))
|
|
188
190
|
p(policy.changed ? `ok: ${policy.summary}` : `ok: .claude/settings.json already closes every raw runner`)
|
|
191
|
+
const hooks = armHooks(root, config)
|
|
192
|
+
p(hooks.state === 'armed' || hooks.state === 'current' ? `ok: commit gates ${hooks.state}, ${hooks.detail}` : `WARN commit gates not armed: ${hooks.detail}`)
|
|
189
193
|
}
|
package/src/ledger/ledger.ts
CHANGED
|
@@ -209,6 +209,12 @@ export class Ledger {
|
|
|
209
209
|
return { ...e.payload, at: e.at }
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
/** what this check's newest kept runs took, newest first, empty when none is kept. A scheduling hint only: no
|
|
213
|
+
* verdict reads it */
|
|
214
|
+
lastRuns(id: string): number[] {
|
|
215
|
+
return this.answers.lastRuns(NS, id)
|
|
216
|
+
}
|
|
217
|
+
|
|
212
218
|
/** the stored read set of a READS check, as the last store wrote it */
|
|
213
219
|
storedReads(id: string): ReadSet | null {
|
|
214
220
|
const k = this.key(id)
|
package/src/ledger/store.ts
CHANGED
|
@@ -193,6 +193,12 @@ export class Answers {
|
|
|
193
193
|
return this.with(READ_BUSY_MS, (h) => h.query("select name, at, json_extract(payload, '$.measuredMs') as ms, json_extract(payload, '$.status') as status from answers where ns = ? and json_valid(payload)").all(ns) as { name: string; at: number; ms: unknown; status: unknown }[]) ?? []
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
/** what the newest kept answers of one check took to measure, newest first: how a runner tells a short check from a long one */
|
|
197
|
+
lastRuns(ns: string, name: string, limit = 3): number[] {
|
|
198
|
+
const rows = this.with(READ_BUSY_MS, (h) => h.query("select case when json_valid(payload) then json_extract(payload, '$.measuredMs') end as ms from (select payload from answers where ns = ? and name = ? order by at desc limit ?)").all(ns, name, limit) as { ms: unknown }[]) ?? []
|
|
199
|
+
return rows.map((r) => Number(r.ms)).filter((ms) => Number.isFinite(ms) && ms >= 0)
|
|
200
|
+
}
|
|
201
|
+
|
|
196
202
|
/** a cheap fingerprint of one population, so a reader can cache on it */
|
|
197
203
|
stamp(ns: string): string {
|
|
198
204
|
const r = this.with(READ_BUSY_MS, (h) => h.query('select count(*) as n, max(at) as last from answers where ns = ?').get(ns) as { n: number; last: number | null } | null)
|
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
// where the backup keeps its objects in the private Space (wiki tools/shipkit/media-store.md, Backup): a file's bytes
|
|
2
2
|
// under `backup/<sha256>.<ext>`, a sqlite snapshot gzipped under `backup/<sha256 of the gz>.gz`, one manifest a run
|
|
3
|
-
// under `backup/runs/<time>-<digest>.json.gz
|
|
3
|
+
// under `backup/runs/<time>-<machine>-<digest>.json.gz` (two Macs back up into one Space; a run from before the name is
|
|
4
|
+
// `<time>-<digest>` and names its host only inside). Nothing under the prefix is ever deleted
|
|
4
5
|
export const BACKUP_LABEL = 'backup'
|
|
5
6
|
export const RUNS_PREFIX = `${BACKUP_LABEL}/runs/`
|
|
6
7
|
|
|
7
8
|
/** a time as the run keys write it: `20261104T135000Z`, sorted as text */
|
|
8
9
|
export const stampOf = (d: Date): string => d.toISOString().replace(/\.\d{3}Z$/, 'Z').replace(/[-:]/g, '')
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
/** a machine name as a key holds it: letters, digits and dashes */
|
|
12
|
+
const cleaned = (machine: string): string => machine.replace(/[^A-Za-z0-9-]+/g, '-').replace(/^-+|-+$/g, '')
|
|
13
|
+
const keyName = (machine: string): string => {
|
|
14
|
+
const name = cleaned(machine)
|
|
15
|
+
if (name === '') throw new Error(`a machine name with no letter or digit cannot key a backup run: ${JSON.stringify(machine)}`)
|
|
16
|
+
return name
|
|
17
|
+
}
|
|
11
18
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
export const runKey = (at: Date, digest: string, machine: string): string => `${RUNS_PREFIX}${stampOf(at)}-${keyName(machine)}-${digest.slice(0, 12)}.json.gz`
|
|
20
|
+
|
|
21
|
+
/** the time and machine a run key names (machine null for a run from before the name), null for a key that is no run */
|
|
22
|
+
export function ofRunKey(key: string): { at: Date; machine: string | null } | null {
|
|
23
|
+
const m = /^backup\/runs\/(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z-(?:([A-Za-z0-9-]+)-)?[0-9a-f]{12}\.json\.gz$/.exec(key)
|
|
24
|
+
return m ? { at: new Date(`${m[1]}-${m[2]}-${m[3]}T${m[4]}:${m[5]}:${m[6]}Z`), machine: m[7] ?? null } : null
|
|
16
25
|
}
|
|
17
26
|
|
|
27
|
+
/** the time a run key names, null for a key that is no run */
|
|
28
|
+
export const timeOfRun = (key: string): Date | null => ofRunKey(key)?.at ?? null
|
|
29
|
+
|
|
30
|
+
/** do two machine names name one Mac: as a key writes them, case aside */
|
|
31
|
+
export const sameMachine = (a: string, b: string): boolean => cleaned(a) !== '' && cleaned(a).toLowerCase() === cleaned(b).toLowerCase()
|
|
32
|
+
|
|
18
33
|
/** a time a person types: ISO (`2026-11-04T13:50`, `2026-11-04`) or a run stamp (`20261104T135000Z`) */
|
|
19
34
|
export function parseAt(text: string): Date {
|
|
20
35
|
const t = text.trim()
|
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
// its files in PARTS, one a group (the home, the memories, a house repo; a big group cut in buckets by folder), each
|
|
4
4
|
// part content addressed: a run that changes one file writes that file's part and the run's list of parts. A run of
|
|
5
5
|
// version 1 holds every file in one object, still read. A restore reads only this and the keys
|
|
6
|
-
import { rmSync } from 'node:fs'
|
|
6
|
+
import { mkdtempSync, rmSync } from 'node:fs'
|
|
7
|
+
import { tmpdir } from 'node:os'
|
|
7
8
|
import { gunzipSync, gzipSync } from 'node:zlib'
|
|
8
9
|
import { dirname, join } from 'node:path'
|
|
9
|
-
import { BACKUP_LABEL, RUNS_PREFIX,
|
|
10
|
+
import { BACKUP_LABEL, ofRunKey, RUNS_PREFIX, sameMachine } from './keys.ts'
|
|
11
|
+
import { hostLabel } from '../../home/machine-host.ts'
|
|
12
|
+
import { machineGet, machineSet } from '../../core/machine-db.ts'
|
|
10
13
|
import type { Space } from '../space.ts'
|
|
11
14
|
import type { SqliteCut } from './snapshot.ts'
|
|
12
15
|
|
|
@@ -129,19 +132,57 @@ export function encodeRun(m: Omit<Manifest, 'v'>, repos: readonly string[]): { r
|
|
|
129
132
|
export const encodeManifestV1 = (m: Omit<Manifest, 'v'>): Uint8Array => gz(JSON.stringify({ ...m, v: 1 }))
|
|
130
133
|
|
|
131
134
|
/** every run the Space holds, oldest first */
|
|
132
|
-
export
|
|
135
|
+
export type RunRef = { key: string; at: Date; size: number; machine: string | null }
|
|
136
|
+
|
|
137
|
+
export async function runsOf(space: Space): Promise<RunRef[]> {
|
|
133
138
|
return (await space.list(RUNS_PREFIX))
|
|
134
139
|
.flatMap((o) => {
|
|
135
|
-
const
|
|
136
|
-
return
|
|
140
|
+
const r = ofRunKey(o.key)
|
|
141
|
+
return r ? [{ key: o.key, at: r.at, size: o.size, machine: r.machine }] : []
|
|
137
142
|
})
|
|
138
143
|
.sort((a, b) => a.at.getTime() - b.at.getTime() || (a.key < b.key ? -1 : 1))
|
|
139
144
|
}
|
|
140
145
|
|
|
141
|
-
/** the last run at or before `at` (the last
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
146
|
+
/** the last run of `machine` at or before `at` (the last one when no time is given), null when the Space holds none.
|
|
147
|
+
* A run from before the name in the key is read for its host, newest first, only while no named run answered */
|
|
148
|
+
export async function runAt(space: Space, at: Date | undefined, machine: string, o: { namedOnly?: boolean } = {}): Promise<{ key: string; at: Date } | null> {
|
|
149
|
+
const runs = (await runsOf(space)).filter((r) => (!at || r.at.getTime() <= at.getTime()) && (!o.namedOnly || r.machine != null)).reverse()
|
|
150
|
+
const tmp = mkdtempSync(join(tmpdir(), 'shipkit-runs-'))
|
|
151
|
+
try {
|
|
152
|
+
for (const r of runs) {
|
|
153
|
+
const host = r.machine ?? (await hostOfOldRun(space, r.key, tmp))
|
|
154
|
+
if (host != null && sameMachine(host, machine)) return { key: r.key, at: r.at }
|
|
155
|
+
}
|
|
156
|
+
return null
|
|
157
|
+
} finally {
|
|
158
|
+
rmSync(tmp, { recursive: true, force: true })
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** the host inside a run whose key names none, kept in the machine db: a run key never changes, so its head is read
|
|
163
|
+
* once (the Space held 938 such runs when the name entered the key) */
|
|
164
|
+
async function hostOfOldRun(space: Space, key: string, tmp: string): Promise<string | null> {
|
|
165
|
+
const held = machineGet<string>(`backup-run-host:${key}`)
|
|
166
|
+
if (held != null) return held === '' ? null : held
|
|
167
|
+
const host = (await readRunHead(space, key, join(tmp, 'head.json.gz'))).host
|
|
168
|
+
const name = host == null ? null : hostLabel(host)
|
|
169
|
+
machineSet(`backup-run-host:${key}`, name ?? '')
|
|
170
|
+
return name
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** the machines the runs name, those from before the name read for their host */
|
|
174
|
+
export async function machinesOf(space: Space): Promise<string[]> {
|
|
175
|
+
const tmp = mkdtempSync(join(tmpdir(), 'shipkit-runs-'))
|
|
176
|
+
try {
|
|
177
|
+
const names = new Set<string>()
|
|
178
|
+
for (const r of await runsOf(space)) {
|
|
179
|
+
const host = r.machine ?? (await hostOfOldRun(space, r.key, tmp))
|
|
180
|
+
if (host != null) names.add(host)
|
|
181
|
+
}
|
|
182
|
+
return [...names].sort()
|
|
183
|
+
} finally {
|
|
184
|
+
rmSync(tmp, { recursive: true, force: true })
|
|
185
|
+
}
|
|
145
186
|
}
|
|
146
187
|
|
|
147
188
|
async function getJson<T>(space: Space, key: string, tmp: string): Promise<{ json: string; value: T }> {
|
|
@@ -167,8 +208,8 @@ async function readPart(space: Space, ref: PartRef, tmp: string): Promise<Entry[
|
|
|
167
208
|
}
|
|
168
209
|
|
|
169
210
|
/** the top of a run, without its parts: its digest and time */
|
|
170
|
-
export async function readRunHead(space: Space, key: string, tmp: string): Promise<{ v: number; digest: string; at: string; parts?: PartRef[] }> {
|
|
171
|
-
const { value: m } = await getJson<{ v: number; digest: string; at: string; parts?: PartRef[] }>(space, key, tmp)
|
|
211
|
+
export async function readRunHead(space: Space, key: string, tmp: string): Promise<{ v: number; digest: string; at: string; host?: string; parts?: PartRef[] }> {
|
|
212
|
+
const { value: m } = await getJson<{ v: number; digest: string; at: string; host?: string; parts?: PartRef[] }>(space, key, tmp)
|
|
172
213
|
if (m.v !== 1 && m.v !== 2) throw new Error(`${key}: no backup run of version 1 or 2`)
|
|
173
214
|
return m
|
|
174
215
|
}
|
|
@@ -9,8 +9,9 @@ import { dirname, join, resolve } from 'node:path'
|
|
|
9
9
|
import { gunzipSync } from 'node:zlib'
|
|
10
10
|
import { shaOf } from '../content.ts'
|
|
11
11
|
import type { Space } from '../space.ts'
|
|
12
|
-
import { stampOf } from './keys.ts'
|
|
13
|
-
import { readManifest, runAt, type Entry, type Manifest } from './manifest.ts'
|
|
12
|
+
import { sameMachine, stampOf } from './keys.ts'
|
|
13
|
+
import { machinesOf, readManifest, runAt, type Entry, type Manifest } from './manifest.ts'
|
|
14
|
+
import { machineName } from '../../home/machine-host.ts'
|
|
14
15
|
import { rowsOf } from './snapshot.ts'
|
|
15
16
|
|
|
16
17
|
export interface RestoreResult {
|
|
@@ -69,22 +70,28 @@ export interface RestoreOptions {
|
|
|
69
70
|
to?: string
|
|
70
71
|
inPlace?: boolean
|
|
71
72
|
at?: Date
|
|
73
|
+
/** the Mac whose runs are read, this one when absent */
|
|
74
|
+
machine?: string
|
|
72
75
|
/** only the paths under this prefix */
|
|
73
76
|
only?: string
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
/** the run a restore or a drill reads: the last at or before `at
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return run
|
|
79
|
+
/** the run a restore or a drill reads: the machine's last at or before `at`. Another Mac's run names files under that
|
|
80
|
+
* Mac's home, so it is read only when `machine` names it */
|
|
81
|
+
async function runFor(space: Space, at: Date | undefined, machine: string): Promise<{ key: string; at: Date }> {
|
|
82
|
+
const run = await runAt(space, at, machine)
|
|
83
|
+
if (run) return run
|
|
84
|
+
const others = (await machinesOf(space)).filter((m) => !sameMachine(m, machine))
|
|
85
|
+
const when = at ? ` at or before ${at.toISOString()}` : ''
|
|
86
|
+
if (others.length > 0) throw new Error(`no backup run of ${machine}${when}; the Space holds runs of ${others.join(', ')}: --host <machine> reads one of them`)
|
|
87
|
+
throw new Error(at ? `no backup run at or before ${at.toISOString()}` : 'the Space holds no backup run yet: sk backup')
|
|
81
88
|
}
|
|
82
89
|
|
|
83
90
|
export async function restore(space: Space, o: RestoreOptions): Promise<RestoreResult & { manifest: Manifest }> {
|
|
84
91
|
if ((o.inPlace === true) === (o.to !== undefined)) throw new Error('a restore goes --to <dir> (a folder that is empty or new) or --in-place, one of the two')
|
|
85
92
|
const to = o.to === undefined ? null : resolve(o.to)
|
|
86
93
|
if (to && existsSync(to) && readdirSync(to).length > 0) throw new Error(`${to} is not empty: a restore writes into an empty or new folder, never over files`)
|
|
87
|
-
const run = await runFor(space, o.at)
|
|
94
|
+
const run = await runFor(space, o.at, o.machine ?? machineName())
|
|
88
95
|
const scratch = mkdtempSync(join(tmpdir(), 'shipkit-restore-'))
|
|
89
96
|
const stamp = stampOf(new Date())
|
|
90
97
|
const aside = join(o.home, '.shipkit', 'backup-replaced', stamp)
|
|
@@ -158,10 +165,10 @@ export interface DrillResult {
|
|
|
158
165
|
|
|
159
166
|
/** a run (the last, or the last at or before `at`) restored into a scratch folder (or `to`), every sha read again and
|
|
160
167
|
* compared to the live files */
|
|
161
|
-
export async function drill(space: Space, o: { home: string; to?: string; keep?: boolean; at?: Date }): Promise<DrillResult & { v: number }> {
|
|
168
|
+
export async function drill(space: Space, o: { home: string; to?: string; keep?: boolean; at?: Date; machine?: string }): Promise<DrillResult & { v: number }> {
|
|
162
169
|
const dir = o.to ? resolve(o.to) : mkdtempSync(join(tmpdir(), 'shipkit-drill-'))
|
|
163
170
|
try {
|
|
164
|
-
const r = await restore(space, { home: o.home, to: dir, ...(o.at ? { at: o.at } : {}) })
|
|
171
|
+
const r = await restore(space, { home: o.home, to: dir, ...(o.at ? { at: o.at } : {}), ...(o.machine ? { machine: o.machine } : {}) })
|
|
165
172
|
const out: DrillResult & { v: number } = { v: r.manifest.v, run: r.run, at: r.at, files: r.files, bytes: r.bytes, restored: 0, sameAsLive: 0, liveMoved: [], liveGone: [], sqlite: [], failed: [...r.failed], dir }
|
|
166
173
|
const bad = new Set(r.failed.map((f) => f.path))
|
|
167
174
|
for (const e of r.manifest.files) {
|
|
@@ -18,6 +18,7 @@ import { digestOf, encodeRun, readManifest, readRunHead, runAt, type Entry, type
|
|
|
18
18
|
import { fileRefusal, refusal } from './secret.ts'
|
|
19
19
|
import { snapshotSqlite } from './snapshot.ts'
|
|
20
20
|
import { collect, type Collect, type Source } from './sources.ts'
|
|
21
|
+
import { machineName } from '../../home/machine-host.ts'
|
|
21
22
|
|
|
22
23
|
const LAST = 'backup-last'
|
|
23
24
|
/** the files named whole, by path: their size, time, sha and key, so an unchanged archive is never read again */
|
|
@@ -168,7 +169,9 @@ async function sendAll(space: Space, ready: readonly Ready[], scratch: string, j
|
|
|
168
169
|
async function lastOf(space: Space, scratch: string): Promise<Last | null> {
|
|
169
170
|
const held = lastRun()
|
|
170
171
|
if (held) return held
|
|
171
|
-
|
|
172
|
+
// only a run whose key names this Mac: the last run only spares an identical one, so a Mac that never named its
|
|
173
|
+
// runs sends one in full instead of reading every old run for its host
|
|
174
|
+
const run = await runAt(space, undefined, machineName(), { namedOnly: true })
|
|
172
175
|
if (!run) return null
|
|
173
176
|
const m = await readRunHead(space, run.key, join(scratch, 'last.json.gz'))
|
|
174
177
|
return { key: run.key, digest: m.digest, at: m.at }
|
|
@@ -235,7 +238,7 @@ export async function backupRun(space: Space, o: Collect & { now?: Date; jobs?:
|
|
|
235
238
|
}
|
|
236
239
|
}
|
|
237
240
|
if (out.failed.length > 0) return out
|
|
238
|
-
const key = runKey(now, digest)
|
|
241
|
+
const key = runKey(now, digest, machineName())
|
|
239
242
|
await sendOne(space, key, enc.run.length, { bytes: enc.run }, scratch, -1 - enc.parts.length)
|
|
240
243
|
out.record.runBytes = enc.run.length
|
|
241
244
|
machineSet(LAST, { key, digest, at: now.toISOString() } satisfies Last)
|
|
@@ -126,7 +126,8 @@ export async function collect(o: Collect): Promise<Source[]> {
|
|
|
126
126
|
// the backup's own objects and records, and the pids, move by themselves: left out, else every run differs
|
|
127
127
|
const sqlite = new Map<string, SqliteCut>([
|
|
128
128
|
[mediaDbPath(), { tables: ['files', 'objects'], except: { objects: "key like 'backup/%'" } }],
|
|
129
|
-
|
|
129
|
+
// the Mac's own names stay out: a run restored on another Mac must not make it take this one's name
|
|
130
|
+
[machineDbPath(), { tables: null, except: { state: "name like 'pid:%' or name like 'backup-%' or name in ('machine-name', 'tailnet-name')" } }],
|
|
130
131
|
])
|
|
131
132
|
await walk(join(homeDir(), 'veille'), () => true, files)
|
|
132
133
|
add(join(o.home, ORDER_FILE))
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { existsSync } from 'node:fs'
|
|
6
6
|
import { machineGet, machineSet } from '../core/machine-db.ts'
|
|
7
7
|
import type { MediaKind } from './kind.ts'
|
|
8
|
-
import { FREE_MIN_BYTES, freeBytes, purge, purgeCandidates } from './purge.ts'
|
|
8
|
+
import { FREE_MIN_BYTES, freeBytes, purge, purgeCandidates, windowDays } from './purge.ts'
|
|
9
9
|
import { machineSpace } from './space.ts'
|
|
10
10
|
import { syncKind } from './sync.ts'
|
|
11
11
|
import { mb, uploadWaiting } from './upload.ts'
|
|
@@ -65,7 +65,7 @@ export async function mediaTick(o: { roots: string[]; kinds: () => readonly Medi
|
|
|
65
65
|
machineSet(PURGED_AT, Date.now())
|
|
66
66
|
for (const { kind, root, dir } of stores) {
|
|
67
67
|
if (freeBytes(dir) >= FREE_MIN_BYTES) continue
|
|
68
|
-
const { candidates } = await purgeCandidates(kind, dir)
|
|
68
|
+
const { candidates } = await purgeCandidates(kind, dir, { olderDays: windowDays(freeBytes(dir)) })
|
|
69
69
|
const r = await purge(kind, dir, space, candidates, { enough: () => freeBytes(dir) >= FREE_MIN_BYTES })
|
|
70
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
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}`)
|
package/src/media-store/purge.ts
CHANGED
|
@@ -15,6 +15,10 @@ export const KEEP_DAYS = 14
|
|
|
15
15
|
/** under this much free disk the daemon purges, when the owner turned it on */
|
|
16
16
|
export const FREE_MIN_BYTES = 40e9
|
|
17
17
|
|
|
18
|
+
/** the daemon's window for a disk with `free` bytes: 14 days, 3 under FREE_MIN_BYTES, 1 under half of it. A young,
|
|
19
|
+
* heavy repo fills the disk in days, and a row its kind pins stays whatever the window */
|
|
20
|
+
export const windowDays = (free: number): number => (free >= FREE_MIN_BYTES ? KEEP_DAYS : free >= FREE_MIN_BYTES / 2 ? 3 : 1)
|
|
21
|
+
|
|
18
22
|
export interface Candidate {
|
|
19
23
|
item: string
|
|
20
24
|
name: string
|