rvlib-shipkit 2.24.0 → 2.25.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 +20 -0
- package/package.json +1 -1
- package/src/agent-time/live.ts +153 -0
- package/src/annex/offload.ts +16 -7
- package/src/check.ts +3 -1
- package/src/checks/SK004-gitignore-policy.check.ts +32 -11
- package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
- package/src/checks/SK033-global-contribution.check.ts +1 -1
- package/src/checks/SK036-draft-media-size.check.ts +1 -1
- package/src/checks/SK040-release-words.check.ts +1 -1
- package/src/checks/SK042-post-kinds.check.ts +1 -1
- package/src/cli/cmd_Annex.ts +12 -7
- package/src/cli/cmd_Assets.ts +5 -5
- package/src/cli/cmd_Backup.ts +11 -5
- package/src/cli/cmd_Capacity.ts +10 -6
- package/src/cli/cmd_Checks.ts +12 -1
- package/src/cli/cmd_Ci.ts +2 -2
- package/src/cli/cmd_Commands.ts +11 -2
- package/src/cli/cmd_ConfigKeys.ts +17 -0
- package/src/cli/cmd_Home.ts +1 -1
- package/src/cli/cmd_Keys.ts +4 -1
- package/src/cli/cmd_Lanes.ts +35 -0
- package/src/cli/cmd_Mv.ts +6 -7
- package/src/cli/cmd_Rec.ts +22 -7
- package/src/cli/cmd_Review.ts +107 -39
- package/src/cli/cmd_Shot.ts +15 -4
- package/src/cli/cmd_Status.ts +6 -5
- package/src/cli/cmd_Time.ts +10 -4
- package/src/cli/cmd_Veille.ts +10 -6
- package/src/cli/family-help.ts +136 -0
- package/src/cli/family-pages.ts +0 -19
- package/src/cli/kit/calls.ts +35 -0
- package/src/cli/kit/project-cli.ts +2 -12
- package/src/cli/registry.ts +39 -6
- package/src/cli.ts +8 -4
- package/src/core/capacity.ts +89 -33
- package/src/core/check-runner.ts +5 -1
- package/src/core/floor-resolve.ts +6 -2
- package/src/core/floor.ts +6 -2
- package/src/core/history-files.ts +18 -0
- package/src/core/jobs.ts +35 -16
- package/src/core/layout.ts +2 -2
- package/src/core/nearest.ts +16 -0
- package/src/core/remove-tree.ts +19 -0
- package/src/core/runs.ts +12 -3
- package/src/core/throwaway-worktree.ts +22 -4
- package/src/core/trace-audit.ts +17 -4
- package/src/home/daemon-jobs.ts +41 -4
- package/src/home/machine-temp.ts +2 -10
- package/src/ledger/gate-checks.ts +3 -2
- package/src/ledger/git-key.ts +25 -4
- package/src/ledger/git-scan.ts +10 -0
- package/src/media-store/backup/daemon.ts +92 -20
- package/src/media-store/backup/run.ts +21 -15
- package/src/media-store/backup/sources.ts +166 -21
- package/src/media-store/backup/watch.ts +106 -0
- package/src/media-store/daemon.ts +36 -8
- package/src/media-store/hand.ts +3 -1
- package/src/mv/mv-md.ts +50 -18
- package/src/pb/run-pb.ts +2 -10
- package/src/plan/repo-source.ts +25 -14
- package/src/recordings/model.ts +1 -1
- package/src/release/run-bump.ts +3 -2
- package/src/release/run-release.ts +12 -4
- package/src/review/cells.ts +2 -1
- package/src/review/format.ts +1 -1
- package/src/review/model.ts +14 -1
- package/src/review/store.ts +15 -7
- package/src/review/trailer-model.ts +2 -2
- package/src/shot/client.ts +4 -2
- package/src/shot/serve-shot.ts +71 -2
- package/src/shot/shooter.ts +65 -11
- package/src/shot/shot-ask.ts +32 -9
- package/src/suite/select.ts +13 -2
- package/src/suite/test-units.ts +31 -12
- package/src/trailer/graph.ts +2 -1
- package/src/ts/config.ts +12 -35
- package/src/ts/rename.ts +31 -17
- package/src/ts/workspaces.ts +45 -0
- package/src/wiki/run-wiki.ts +7 -2
- package/src/wiki/scan-md.ts +2 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// the daemon's watch of the backup's sources: a path it hears that could be a source (`watchRoots`) is noted, and the
|
|
2
|
+
// next look reads only the noted paths again. The callback only notes: the loop answers every page. A clean stop hands
|
|
3
|
+
// what it heard to the next daemon (a reload in place); a daemon that did not stop cleanly starts with a full walk
|
|
4
|
+
import { watch, type FSWatcher } from 'node:fs'
|
|
5
|
+
import { basename, join } from 'node:path'
|
|
6
|
+
import { machineDelete, machineGet, machineSet } from '../../core/machine-db.ts'
|
|
7
|
+
import { backupDue, BATCH, NAMED, type Batch } from './daemon.ts'
|
|
8
|
+
import { isTransient, watchRoots } from './sources.ts'
|
|
9
|
+
|
|
10
|
+
/** what a stopping daemon heard and no look took yet, for the next one */
|
|
11
|
+
const HELD = 'backup-heard'
|
|
12
|
+
/** a stop this recent is a hand over (a reload in place): the next daemon takes what it heard, else it walks */
|
|
13
|
+
export const HANDOVER_MS = 60_000
|
|
14
|
+
/** past this many paths, the next look walks every source */
|
|
15
|
+
export const MAX_PATHS = 2_000
|
|
16
|
+
|
|
17
|
+
type Held = { at: number; paths: string[]; all: boolean }
|
|
18
|
+
|
|
19
|
+
export interface BackupWatchOptions {
|
|
20
|
+
home: string
|
|
21
|
+
/** the house repos, archived ones included */
|
|
22
|
+
repos: readonly string[]
|
|
23
|
+
now?: () => number
|
|
24
|
+
printErr?: (l: string) => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class BackupWatch {
|
|
28
|
+
private readonly heard = new Set<string>()
|
|
29
|
+
/** the next look walks every source */
|
|
30
|
+
private all = false
|
|
31
|
+
/** a watch stopped: every look walks, as with no watch */
|
|
32
|
+
private blind = false
|
|
33
|
+
private named: Record<string, string[]> = {}
|
|
34
|
+
private readonly watchers: FSWatcher[] = []
|
|
35
|
+
private readonly now: () => number
|
|
36
|
+
|
|
37
|
+
constructor(private readonly o: BackupWatchOptions) {
|
|
38
|
+
this.now = o.now ?? Date.now
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** no watch at all: every look walks every source, as before there was one */
|
|
42
|
+
blindly(): this {
|
|
43
|
+
this.blind = true
|
|
44
|
+
return this
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async start(): Promise<this> {
|
|
48
|
+
const held = machineGet<Held>(HELD)
|
|
49
|
+
machineDelete(HELD)
|
|
50
|
+
if (held != null && this.now() - held.at <= HANDOVER_MS) {
|
|
51
|
+
for (const p of held.paths) this.heard.add(p)
|
|
52
|
+
this.all = held.all
|
|
53
|
+
} else this.all = true
|
|
54
|
+
this.named = machineGet<Record<string, string[]>>(NAMED) ?? {}
|
|
55
|
+
for (const root of await watchRoots(this.o.home, this.o.repos, (r) => this.named[r] ?? [])) {
|
|
56
|
+
let w: FSWatcher
|
|
57
|
+
try {
|
|
58
|
+
w = watch(root.dir, { recursive: root.recursive }, (_event, name) => {
|
|
59
|
+
if (this.all) return
|
|
60
|
+
// no name, or the root itself: the system says its tree changed in ways it did not list
|
|
61
|
+
const rel = name == null ? '' : String(name)
|
|
62
|
+
if (rel === '') return void (this.all = true)
|
|
63
|
+
if (isTransient(basename(rel)) || root.heard(rel) == null) return
|
|
64
|
+
if (this.heard.size >= MAX_PATHS) {
|
|
65
|
+
this.all = true
|
|
66
|
+
this.heard.clear()
|
|
67
|
+
} else this.heard.add(join(root.dir, rel))
|
|
68
|
+
})
|
|
69
|
+
} catch {
|
|
70
|
+
// a root not on the disk yet: the safety walk finds what lands there
|
|
71
|
+
continue
|
|
72
|
+
}
|
|
73
|
+
w.on('error', (e) => {
|
|
74
|
+
if (!this.blind) this.o.printErr?.(`WARN backup: the watch of ${root.dir} stopped (${(e as Error).message}): each look walks every source until the daemon reloads`)
|
|
75
|
+
this.blind = true
|
|
76
|
+
})
|
|
77
|
+
this.watchers.push(w)
|
|
78
|
+
}
|
|
79
|
+
return this
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** the paths heard since the last look, for a test or a probe */
|
|
83
|
+
pending(): { paths: string[]; all: boolean } {
|
|
84
|
+
return { paths: [...this.heard].sort(), all: this.all || this.blind }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** the daemon's look: a few reads of the machine db, never a walk. When due, the paths heard go to the look it
|
|
88
|
+
* starts, with those of a look that did not finish */
|
|
89
|
+
due(now: number): boolean {
|
|
90
|
+
this.named = machineGet<Record<string, string[]>>(NAMED) ?? this.named
|
|
91
|
+
if (!backupDue(now, this.all || this.blind || this.heard.size > 0)) return false
|
|
92
|
+
const was = machineGet<Batch>(BATCH)
|
|
93
|
+
const undone = was?.done === false ? was : null
|
|
94
|
+
const paths = [...new Set([...(undone?.paths ?? []), ...this.heard])]
|
|
95
|
+
const all = this.all || this.blind || (undone?.all ?? false) || paths.length > MAX_PATHS
|
|
96
|
+
machineSet(BATCH, { paths: all ? [] : paths.sort(), all, done: false } satisfies Batch)
|
|
97
|
+
this.heard.clear()
|
|
98
|
+
this.all = false
|
|
99
|
+
return true
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
stop(): void {
|
|
103
|
+
for (const w of this.watchers.splice(0)) w.close()
|
|
104
|
+
machineSet(HELD, { at: this.now(), paths: [...this.heard], all: this.all || this.blind } satisfies Held)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// the daemon's media job (wiki tools/shipkit/media-store.md, The daemon): one pass, in a child process the daemon
|
|
2
|
-
// starts
|
|
3
|
-
// index once its store moved, what waits sent up, and (when the owner turned it on) the disk purged under
|
|
4
|
-
// Each failure is one line in the daemon's log
|
|
5
|
-
import { existsSync } from 'node:fs'
|
|
2
|
+
// starts when `mediaDue` says so (home/daemon-jobs.ts), never on its loop. Every kind of every house repo scanned into
|
|
3
|
+
// the machine index once its store moved, what waits sent up, and (when the owner turned it on) the disk purged under
|
|
4
|
+
// 40 GB free. Each failure is one line in the daemon's log
|
|
5
|
+
import { existsSync, statSync } from 'node:fs'
|
|
6
|
+
import { resolve } from 'node:path'
|
|
6
7
|
import { machineGet, machineSet } from '../core/machine-db.ts'
|
|
7
8
|
import type { MediaKind } from './kind.ts'
|
|
8
9
|
import { FREE_MIN_BYTES, freeBytes, purge, purgeCandidates, windowDays } from './purge.ts'
|
|
@@ -11,6 +12,8 @@ import { syncKind } from './sync.ts'
|
|
|
11
12
|
import { mb, uploadWaiting } from './upload.ts'
|
|
12
13
|
|
|
13
14
|
export const MEDIA_EVERY_MS = 30_000
|
|
15
|
+
/** a pass that found nothing to do: the next one this much later, unless a store's folder moves first */
|
|
16
|
+
export const MEDIA_QUIET_MS = 5 * 60_000
|
|
14
17
|
const PURGE_EVERY_MS = 10 * 60_000
|
|
15
18
|
const AUTO_KEY = 'media-purge-auto'
|
|
16
19
|
|
|
@@ -22,17 +25,34 @@ export const setAutoPurge = (on: boolean): boolean => machineSet(AUTO_KEY, on)
|
|
|
22
25
|
const SYNCED = 'media-synced'
|
|
23
26
|
const PURGED_AT = 'media-purged-at'
|
|
24
27
|
const NO_SPACE = 'media-no-space'
|
|
28
|
+
/** when the next pass is due, and the folders whose move brings it sooner */
|
|
29
|
+
const NEXT = 'media-next'
|
|
30
|
+
|
|
31
|
+
type Next = { at: number; since: number; dirs: string[] }
|
|
32
|
+
|
|
33
|
+
/** the daemon's look, in its own process: a stat of each store folder, never a walk. Due at the time the last pass
|
|
34
|
+
* named, or as soon as a store's folder moved since that pass began (a new card, a new take) */
|
|
35
|
+
export function mediaDue(now: number): boolean {
|
|
36
|
+
const n = machineGet<Next>(NEXT)
|
|
37
|
+
if (n == null || now >= n.at) return true
|
|
38
|
+
return n.dirs.some((d) => (statSync(d, { throwIfNoEntry: false })?.mtimeMs ?? 0) > n.since)
|
|
39
|
+
}
|
|
25
40
|
|
|
26
41
|
/** one pass of the daemon's media job, in its child process: what `startMediaStore` does each tick, with what it
|
|
27
42
|
* 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> {
|
|
43
|
+
export async function mediaTick(o: { roots: string[]; kinds: () => readonly MediaKind[]; print: (l: string) => void; printErr: (l: string) => void; now?: () => number }): Promise<void> {
|
|
44
|
+
const now = o.now ?? Date.now
|
|
45
|
+
const since = now()
|
|
29
46
|
const synced = machineGet<Record<string, string>>(SYNCED) ?? {}
|
|
47
|
+
const kinds = o.kinds()
|
|
30
48
|
const stores = o.roots.flatMap((root) =>
|
|
31
|
-
|
|
49
|
+
kinds.flatMap((kind) => {
|
|
32
50
|
const dir = kind.storeOf(root)
|
|
33
51
|
return dir && existsSync(dir) ? [{ kind, root, dir }] : []
|
|
34
52
|
}),
|
|
35
53
|
)
|
|
54
|
+
// work done or left: the next pass at the usual period, else after the quiet one
|
|
55
|
+
let busy = false
|
|
36
56
|
try {
|
|
37
57
|
let moved = false
|
|
38
58
|
for (const { kind, root, dir } of stores) {
|
|
@@ -44,8 +64,10 @@ export async function mediaTick(o: { roots: string[]; kinds: () => readonly Medi
|
|
|
44
64
|
// files left to hash: the next pass goes on with them
|
|
45
65
|
synced[id] = r.left > 0 ? '' : stamp
|
|
46
66
|
moved = true
|
|
67
|
+
if (r.filled > 0 || r.left > 0) busy = true
|
|
47
68
|
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
69
|
} catch (e) {
|
|
70
|
+
busy = true
|
|
49
71
|
o.printErr(`WARN media store: the ${kind.kind} files of ${root} did not sync: ${(e as Error).message}`)
|
|
50
72
|
}
|
|
51
73
|
}
|
|
@@ -59,10 +81,11 @@ export async function mediaTick(o: { roots: string[]; kinds: () => readonly Medi
|
|
|
59
81
|
}
|
|
60
82
|
machineSet(NO_SPACE, '')
|
|
61
83
|
const up = await uploadWaiting(space, { limit: 200, jobs: 3 })
|
|
84
|
+
if (up.up + up.there + up.failed.length > 0) busy = true
|
|
62
85
|
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
86
|
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() &&
|
|
65
|
-
machineSet(PURGED_AT,
|
|
87
|
+
if (autoPurgeOn() && now() - (machineGet<number>(PURGED_AT) ?? 0) > PURGE_EVERY_MS) {
|
|
88
|
+
machineSet(PURGED_AT, now())
|
|
66
89
|
for (const { kind, root, dir } of stores) {
|
|
67
90
|
if (freeBytes(dir) >= FREE_MIN_BYTES) continue
|
|
68
91
|
const { candidates } = await purgeCandidates(kind, dir, { olderDays: windowDays(freeBytes(dir)) })
|
|
@@ -72,6 +95,11 @@ export async function mediaTick(o: { roots: string[]; kinds: () => readonly Medi
|
|
|
72
95
|
}
|
|
73
96
|
}
|
|
74
97
|
} catch (e) {
|
|
98
|
+
busy = true
|
|
75
99
|
o.printErr(`WARN media store: the pass broke: ${(e as Error).message}`)
|
|
100
|
+
} finally {
|
|
101
|
+
// a store that is the repo itself (a hand label) moves with every save there: the index is its record
|
|
102
|
+
const dirs = [...new Set(stores.filter((s) => resolve(s.dir) !== resolve(s.root)).map((s) => s.dir))]
|
|
103
|
+
machineSet(NEXT, { at: since + (busy ? MEDIA_EVERY_MS : MEDIA_QUIET_MS), since, dirs } satisfies Next)
|
|
76
104
|
}
|
|
77
105
|
}
|
package/src/media-store/hand.ts
CHANGED
|
@@ -36,9 +36,11 @@ const rowsOf = (label: string, store: string): { item: string; name: string; key
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function handKind(label: string): MediaKind {
|
|
39
|
+
// read once per kind: a pass asks it for every house repo, and each read scans the whole files table
|
|
40
|
+
let held: string[] | null = null
|
|
39
41
|
return {
|
|
40
42
|
kind: label,
|
|
41
|
-
storeOf: (root) => (storesOf(label).includes(resolve(root)) ? resolve(root) : null),
|
|
43
|
+
storeOf: (root) => ((held ??= storesOf(label)).includes(resolve(root)) ? resolve(root) : null),
|
|
42
44
|
// the index is the record: read it again every 10 min, to see a file the disk let go
|
|
43
45
|
stamp: () => String(Math.floor(Date.now() / 600_000)),
|
|
44
46
|
async scan(store) {
|
package/src/mv/mv-md.ts
CHANGED
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
// script it runs after the moves (repo-specific re-stamps). TS module moves
|
|
7
7
|
// are a different concern (a TS-aware renamer owns import graphs).
|
|
8
8
|
import { execSync } from 'child_process'
|
|
9
|
+
import { isHistoryFile } from '../core/history-files.ts'
|
|
9
10
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs'
|
|
11
|
+
import { homedir } from 'os'
|
|
10
12
|
import { basename, dirname, join, relative } from 'path'
|
|
11
13
|
import { isVendored } from '../core/vendored.ts'
|
|
12
14
|
import { vendoredAround } from '../core/vendored-read.ts'
|
|
13
15
|
|
|
14
16
|
export type MvIo = { print: (l: string) => void; printErr: (l: string) => void }
|
|
15
|
-
export type MvOpts = { write?: boolean; commit?: boolean; /** run the repo's `mv:after` script (a batch runs it once, at the end) */ after?: boolean }
|
|
17
|
+
export type MvOpts = { write?: boolean; commit?: boolean; /** run the repo's `mv:after` script (a batch runs it once, at the end) */ after?: boolean; /** rewrite the plans, changelogs and journals too: by default they stay as written */ history?: boolean }
|
|
16
18
|
|
|
17
19
|
const sh = (cmd: string, cwd: string): string => execSync(cmd, { cwd }).toString()
|
|
18
20
|
|
|
@@ -32,15 +34,8 @@ const dirOf = (p: string): string => { const d = dirname(p); return d === '.' ?
|
|
|
32
34
|
// were confined to one directory. A move between directories invalidates both
|
|
33
35
|
// directions at once: the links the page carries out, and the links other
|
|
34
36
|
// pages aim at it. This pass runs FIRST so the token sweep finds those already
|
|
35
|
-
// rewritten.
|
|
36
|
-
//
|
|
37
|
-
// KNOWN RESIDUAL, do not read this as closed: the token sweep below is a
|
|
38
|
-
// substring replace, so a path that merely ENDS with the old path
|
|
39
|
-
// ('other/doc/bun.md' referenced as '../doc/bun.md' from a file that is not
|
|
40
|
-
// moving) is still rewritten to a path that does not exist. This pass declines
|
|
41
|
-
// that case on purpose, because neither the target nor the carrier moved.
|
|
42
|
-
// Closing it means teaching the sweep which character spans were already
|
|
43
|
-
// resolved here.
|
|
37
|
+
// rewritten. A path that merely ENDS with the old path is the sweep's to judge
|
|
38
|
+
// (`namesMoved`), never this pass's.
|
|
44
39
|
//
|
|
45
40
|
// A target must resolve to a FILE. Directories are excluded because the arrow
|
|
46
41
|
// form appears in prose ('→ shipkit ci'), and a bare word that happens to name
|
|
@@ -98,6 +93,19 @@ export function retargetRelativeRefs(
|
|
|
98
93
|
return out
|
|
99
94
|
}
|
|
100
95
|
|
|
96
|
+
/** whether the token at `at` names the moved path `full`, judged by the path characters right before it: none, a
|
|
97
|
+
* relative path that resolves to it from the carrier's folder, the repo's own absolute root, or a url's path. Any
|
|
98
|
+
* other longer path (`packages/p/agent/index.md` for `agent/index.md`) names another file */
|
|
99
|
+
export function namesMoved(text: string, at: number, tok: string, full: string, carrierDir: string, root: string): boolean {
|
|
100
|
+
let s = at
|
|
101
|
+
while (s > 0 && /[\w.\/~-]/.test(text[s - 1]!)) s--
|
|
102
|
+
const p = text.slice(s, at)
|
|
103
|
+
// `${root}/agent/x.md`: the folder is an expression, read as the root
|
|
104
|
+
if (p === '' || p.startsWith('//') || (p === '/' && s > 0 && /[})]/.test(text[s - 1]!))) return true
|
|
105
|
+
if (p.startsWith('/') || p.startsWith('~/')) return (p.startsWith('~/') ? join(homedir(), p.slice(2)) : p).replace(/\/+$/, '') === root.replace(/\/+$/, '')
|
|
106
|
+
return posix(join(carrierDir, p + tok)) === full
|
|
107
|
+
}
|
|
108
|
+
|
|
101
109
|
/** where a move reads and writes. Applied, it is the disk and git; a dry run is
|
|
102
110
|
* an overlay on them, so the dry run walks the very same steps, and a map's
|
|
103
111
|
* next line sees what the line before it moved */
|
|
@@ -124,6 +132,14 @@ class MvTree {
|
|
|
124
132
|
exists = (rel: string): boolean =>
|
|
125
133
|
this.isFile(rel) || (!this.live && this.files().some((f) => f.startsWith(`${rel}/`))) || (!this.isGone(rel) && existsSync(this.real(rel)))
|
|
126
134
|
read = (rel: string): string => this.text.get(rel) ?? readFileSync(this.real(rel), 'utf8')
|
|
135
|
+
/** false for a binary (a NUL in its first 8 KB, git's own test) and for a text without `needle`: no decode, no
|
|
136
|
+
* regex, ten times faster over a repo's tracked files */
|
|
137
|
+
holds(rel: string, needle: string): boolean {
|
|
138
|
+
const t = this.text.get(rel)
|
|
139
|
+
if (t !== undefined) return t.includes(needle)
|
|
140
|
+
const b = readFileSync(this.real(rel))
|
|
141
|
+
return !b.subarray(0, 8192).includes(0) && b.includes(needle)
|
|
142
|
+
}
|
|
127
143
|
write(rel: string, text: string): void {
|
|
128
144
|
if (this.live) writeFileSync(this.real(rel), text)
|
|
129
145
|
else this.text.set(rel, text)
|
|
@@ -179,11 +195,14 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
|
|
|
179
195
|
// asset dir BECOMES that folder instead of sitting beside the page
|
|
180
196
|
const indexForm = basename(newRel) === 'index.md' && basename(oldRel) !== 'index.md'
|
|
181
197
|
const oldBase = oldRel.slice(0, -3) // full path sans .md, the sibling dir
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
198
|
+
// in place: the page moves into its own asset dir (`x.md` to `x/index.md` or `x/x.md`), which stays the topic folder
|
|
199
|
+
const inPlace = dirOf(newRel) === oldBase
|
|
200
|
+
const newBase = indexForm || inPlace ? dirOf(newRel) : newRel.slice(0, -3)
|
|
201
|
+
// git cannot move a folder into itself, and the sweep would already have run
|
|
202
|
+
if (!inPlace && newRel.startsWith(`${oldBase}/`) && tree.exists(oldBase))
|
|
203
|
+
return die(`${newRel} sits deeper inside ${oldBase}/, the page's own folder, which git cannot move into itself. Two steps: sk mv ${oldRel} ${oldBase}/${basename(newRel)} --write, then sk mv ${oldBase}/${basename(newRel)} ${newRel} --write`)
|
|
185
204
|
if (indexForm && !inPlace && tree.exists(newBase)) return die(`${newBase}/ already exists: a topic folder is created by its move, never merged into`)
|
|
186
|
-
if (!indexForm && tree.exists(oldBase) && tree.exists(newBase))
|
|
205
|
+
if (!indexForm && !inPlace && tree.exists(oldBase) && tree.exists(newBase))
|
|
187
206
|
return die(`${newBase}/ already exists, and ${oldBase}/ would be nested inside it rather than become it: move or merge it by hand first`)
|
|
188
207
|
|
|
189
208
|
const write = tree.live
|
|
@@ -193,6 +212,7 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
|
|
|
193
212
|
// (`build/state`, not `wiki/build/state`), so the sweep takes both forms
|
|
194
213
|
const tail = (p: string): string | null => { const seg = p.split('/'); return seg.length >= 3 ? seg.slice(1).join('/') : null }
|
|
195
214
|
const oldId = tail(oldBase)
|
|
215
|
+
const top = oldBase.split('/')[0]!
|
|
196
216
|
const newId = tail(newBase)
|
|
197
217
|
const newPageId = tail(newRel.slice(0, -3))
|
|
198
218
|
|
|
@@ -242,14 +262,25 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
|
|
|
242
262
|
}
|
|
243
263
|
|
|
244
264
|
let touched = 0
|
|
265
|
+
let left = 0
|
|
245
266
|
for (const f of [...tracked]) {
|
|
246
267
|
// a submodule is one ls-files entry and a directory: nothing to read
|
|
247
268
|
if (!tree.isFile(f)) continue
|
|
269
|
+
// every token and every relative path that reaches a moved file names the page's stem
|
|
270
|
+
if (!moves.has(f) && !tree.holds(f, oldName)) continue
|
|
248
271
|
const before = tree.read(f)
|
|
249
272
|
let refs = 0
|
|
250
273
|
const linked = retargetRelativeRefs(root, before, dirOf(f), dirOf(moves.get(f) ?? f), moves, tree.isFile)
|
|
251
274
|
if (linked !== before) { const lines = before.split('\n'); refs += linked.split('\n').filter((l, i) => l !== lines[i]).length }
|
|
252
|
-
const after = linked.replace(sweep, (m
|
|
275
|
+
const after = linked.replace(sweep, (m: string, at: number) => {
|
|
276
|
+
// a docs-root-relative id names the path under the repo's top folder
|
|
277
|
+
if (!namesMoved(linked, at, m, m.startsWith(oldBase) ? m : `${top}/${m}`, dirOf(f), root)) return m
|
|
278
|
+
const next = to.get(m)!
|
|
279
|
+
if (next !== m) refs++
|
|
280
|
+
return next
|
|
281
|
+
})
|
|
282
|
+
// a record of what was true stays as written, unless it is itself what moves
|
|
283
|
+
if (after !== before && o.history !== true && isHistoryFile(f) && !moves.has(f)) { left++; continue }
|
|
253
284
|
if (after !== before) {
|
|
254
285
|
io.print(` ${f}: ${refs} ref(s)`)
|
|
255
286
|
io.print(` ${firstChanged(before, after)}`)
|
|
@@ -265,7 +296,7 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
|
|
|
265
296
|
if (indexForm && hasDir && !inPlace) tree.mv(oldBase, newBase)
|
|
266
297
|
tree.mv(oldRel, newRel)
|
|
267
298
|
if (hasDir) {
|
|
268
|
-
if (!indexForm) tree.mv(oldBase, newBase)
|
|
299
|
+
if (!indexForm && !inPlace) tree.mv(oldBase, newBase)
|
|
269
300
|
// the probe is named after its page, so it only moves when the NAME
|
|
270
301
|
// changed. A move that keeps the name and changes the directory takes
|
|
271
302
|
// the probe along inside the dir, and `git mv X X` is a fatal
|
|
@@ -274,7 +305,8 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
|
|
|
274
305
|
if (oldName !== newName && tree.exists(oldProbe)) tree.mv(oldProbe, `${newBase}/${newName}${sfx}`)
|
|
275
306
|
}
|
|
276
307
|
}
|
|
277
|
-
io.print(
|
|
308
|
+
if (left > 0) io.print(` left as written: ${left} plan, changelog or journal file(s) that name it (--history rewrites them too)`)
|
|
309
|
+
io.print(`${write ? 'renamed' : 'DRY RUN'}: ${oldRel} → ${newRel}, refs in ${touched} file(s)`)
|
|
278
310
|
if (!write) { io.print('re-run with --write (or --commit) to apply'); return 0 }
|
|
279
311
|
|
|
280
312
|
if (o.after !== false && !runAfter(root)) return die('mv:after failed, fix before committing')
|
|
@@ -284,7 +316,7 @@ export function movePage(root: string, oldRel: string, newRel: string, io: MvIo,
|
|
|
284
316
|
execSync(`git commit -m ${JSON.stringify(`docs: rename ${oldBase} → ${newBase}`)}`, { cwd: root, stdio: 'inherit' })
|
|
285
317
|
} catch { return die('commit failed (pre-commit gate?). The rename is applied, fix and commit yourself') }
|
|
286
318
|
}
|
|
287
|
-
io.print(`ok: ${
|
|
319
|
+
io.print(`ok: ${oldRel} → ${newRel}${o.commit === true ? ' (committed)' : ''}`)
|
|
288
320
|
return 0
|
|
289
321
|
}
|
|
290
322
|
|
package/src/pb/run-pb.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// the failure mode is a runtime throw rather than a compile error.
|
|
11
11
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
|
|
12
12
|
import { dirname, join } from 'path'
|
|
13
|
+
import { nearest } from '../core/nearest.ts'
|
|
13
14
|
import { scaffoldCollectionUI, type ScaffoldedFile } from './collection-scaffold.ts'
|
|
14
15
|
import { isSystemCollection, parsePbTypes, type PbCollection } from './pb-types.ts'
|
|
15
16
|
|
|
@@ -35,15 +36,6 @@ const REGISTRY_HEADER = [
|
|
|
35
36
|
'',
|
|
36
37
|
].join('\n')
|
|
37
38
|
|
|
38
|
-
/** names close enough to be the one that was meant */
|
|
39
|
-
function nearest(want: string, have: string[]): string[] {
|
|
40
|
-
const w = want.toLowerCase().replace(/[_-]/g, '')
|
|
41
|
-
return have.filter((n) => {
|
|
42
|
-
const h = n.toLowerCase().replace(/[_-]/g, '')
|
|
43
|
-
return h === w || h.startsWith(w) || w.startsWith(h)
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
39
|
export type PbCollectionOpts = { dryRun: boolean }
|
|
48
40
|
|
|
49
41
|
export function runPbCollection(root: string, name: string, io: PbIo, opts: PbCollectionOpts): number {
|
|
@@ -70,7 +62,7 @@ export function runPbCollection(root: string, name: string, io: PbIo, opts: PbCo
|
|
|
70
62
|
// pocketbase's own `_`-prefixed collections are never an app surface, so
|
|
71
63
|
// offering them as choices sends the reader somewhere they cannot go
|
|
72
64
|
const names = collections.filter((c) => !isSystemCollection(c.name)).map((c) => c.name)
|
|
73
|
-
const close = nearest(name, names)
|
|
65
|
+
const close = nearest(name, names, Infinity)
|
|
74
66
|
io.printErr(`FAIL: no collection '${name}' in ${typesRel}`)
|
|
75
67
|
if (close.length > 0) io.printErr(` fix: did you mean ${close.join(', ')} ?`)
|
|
76
68
|
io.printErr(` fix: known collections: ${names.join(', ')}`)
|
package/src/plan/repo-source.ts
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
//
|
|
5
5
|
// the one constraint a reader breaks first: `changed` asks the ledger, never
|
|
6
6
|
// the file event. A check is changed when its answer would not replay: a key
|
|
7
|
-
// that moved, a read set that drifted, no stored green
|
|
8
|
-
//
|
|
9
|
-
//
|
|
7
|
+
// that moved, a read set that drifted, no stored green. A red keyed on content
|
|
8
|
+
// counts only once its key moves, so a save elsewhere never re-runs it. A
|
|
9
|
+
// check with no key counts when a declared input of the repo moved (saveMoved).
|
|
10
10
|
import { gateInventory, type CheckRow } from '../ledger/gate-checks.ts'
|
|
11
11
|
import { Ledger } from '../ledger/ledger.ts'
|
|
12
|
+
import type { CheckKey } from '../ledger/git-key.ts'
|
|
12
13
|
import { answersDb } from '../ledger/store.ts'
|
|
13
14
|
import { hasWorld, worldKeyOf, type WorldCache } from '../ledger/world-cache.ts'
|
|
14
15
|
import { FOREVER, FOREVER_MS } from '../core/wire.ts'
|
|
@@ -36,7 +37,7 @@ export function planGap(row: CheckRow): string | null {
|
|
|
36
37
|
if (row.runs.onSave !== 'moved') return null
|
|
37
38
|
const pop = populationOf(row.decl)
|
|
38
39
|
if (pop === 'content' || pop === 'reads' || isForever(row)) return null
|
|
39
|
-
return `onSave 'moved' but nothing keys it (${row.decl.uncacheable ?? row.decl.declError ?? 'no key'}), so
|
|
40
|
+
return `onSave 'moved' but nothing keys it (${row.decl.uncacheable ?? row.decl.declError ?? 'no key'}), so a save runs it whenever any declared input of the repo moved`
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/** one inventory row as a plan check, straight from its declared axes:
|
|
@@ -103,6 +104,25 @@ export function lastStarted(path: string, o: { asked?: boolean } = {}): number |
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
/** whether a save moved one check, given the key it had at the last question (`seen`, updated here). A check with
|
|
108
|
+
* no key (an input git cannot name, a toolchain nobody can describe, a scan that failed) is due when its reason
|
|
109
|
+
* changes or when `tree` moved: what the scan saw of every declared input of the repo that git does not ignore,
|
|
110
|
+
* null when the scan failed.
|
|
111
|
+
* Never at each save whatever moved: the run it starts writes files of its own, so that is a loop. With no tree
|
|
112
|
+
* to compare (the scan failed) it is due once for the reason */
|
|
113
|
+
export function saveMoved(seen: Map<string, string>, id: string, k: Pick<CheckKey, 'key' | 'population' | 'reason'>, replays: () => boolean, tree: string | null = null): boolean {
|
|
114
|
+
const before = seen.get(id)
|
|
115
|
+
if (k.key == null) {
|
|
116
|
+
// long runs of digits out: a reason that names a pid or a time is the same reason, a file name keeps its number
|
|
117
|
+
const mark = `no key: ${(k.reason ?? '').replace(/\d{4,}/g, '#')} @ ${tree ?? ''}`
|
|
118
|
+
seen.set(id, mark)
|
|
119
|
+
return before !== mark
|
|
120
|
+
}
|
|
121
|
+
seen.set(id, k.key)
|
|
122
|
+
if (replays()) return false
|
|
123
|
+
return !(k.population === 'content' && before === k.key)
|
|
124
|
+
}
|
|
125
|
+
|
|
106
126
|
export type RepoSourceDeps = {
|
|
107
127
|
repo: string
|
|
108
128
|
root: string
|
|
@@ -179,16 +199,7 @@ export function repoSource(d: RepoSourceDeps): PlanSource {
|
|
|
179
199
|
}
|
|
180
200
|
// 'burst': every quiet save burst, whatever moved
|
|
181
201
|
if (r.runs.onSave === 'burst') { out.push(c.id); continue }
|
|
182
|
-
|
|
183
|
-
if (k.key == null) {
|
|
184
|
-
out.push(c.id)
|
|
185
|
-
continue
|
|
186
|
-
}
|
|
187
|
-
const before = seen.get(c.id)
|
|
188
|
-
seen.set(c.id, k.key)
|
|
189
|
-
if (ledger.replay(c.id) != null) continue
|
|
190
|
-
if (k.population === 'content' && before === k.key) continue
|
|
191
|
-
out.push(c.id)
|
|
202
|
+
if (saveMoved(seen, c.id, ledger.layer.keyFor(c.id), () => ledger.replay(c.id) != null, ledger.layer.treeStamp())) out.push(c.id)
|
|
192
203
|
}
|
|
193
204
|
return out
|
|
194
205
|
},
|
package/src/recordings/model.ts
CHANGED
|
@@ -128,7 +128,7 @@ export async function findRecording(ref: string, o: { repo?: string } = {}): Pro
|
|
|
128
128
|
const hits = all.filter((r) => r.name === word || r.id === word)
|
|
129
129
|
if (hits.length === 1) return hits[0]!
|
|
130
130
|
if (hits.length > 1) throw new Error(`${ref}: ${hits.length} recordings answer to it (${hits.map((r) => `${r.repo}/${r.name}`).join(', ')}); name the repo`)
|
|
131
|
-
throw new Error(`${ref}: no recording of that name${repo ? ` in ${repo}` : ''} (sk rec
|
|
131
|
+
throw new Error(`${ref}: no recording of that name${repo ? ` in ${repo}` : ''} (sk rec lists them)`)
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/** the name given, checked free in the repo folder */
|
package/src/release/run-bump.ts
CHANGED
|
@@ -40,7 +40,7 @@ import { unitBlockers } from './unit-gate.ts'
|
|
|
40
40
|
import { publicCleanBlockers } from './public-clean.ts'
|
|
41
41
|
import { releaseScope } from './release-scope.ts'
|
|
42
42
|
import { formatUnitError, releaseOrder, renderTag, resolveUnits, unitById, unitPrepublishScripts, unknownUnit, type ReleaseUnit } from './units.ts'
|
|
43
|
-
import { environmentBlockers, runReleaseGate, releaseUnit } from './run-release.ts'
|
|
43
|
+
import { environmentBlockers, gateStop, runReleaseGate, releaseUnit } from './run-release.ts'
|
|
44
44
|
import type { RepoConfig } from '../repo-config.ts'
|
|
45
45
|
import { nestedIn, nestedRefusal } from '../core/nesting.ts'
|
|
46
46
|
import { LAYOUT } from '../core/layout.ts'
|
|
@@ -492,7 +492,8 @@ export async function runBump(root: string, config: RepoConfig, kind: BumpKind |
|
|
|
492
492
|
// same thing. Frozen, and fatal on non-blocking failures when the repo
|
|
493
493
|
// declared requireHealthy. releaseUnit then skips it, because bump
|
|
494
494
|
// already proved this exact commit.
|
|
495
|
-
|
|
495
|
+
const gate = await runReleaseGate(root, print, { units: picked, allowDirty: o.allowDirty })
|
|
496
|
+
if (gate !== 0) return fail(gateStop(gate, 'bump'))
|
|
496
497
|
print('ok: ci gate green')
|
|
497
498
|
|
|
498
499
|
for (const s of selected) {
|
|
@@ -124,8 +124,11 @@ export type ReleaseOpts = {
|
|
|
124
124
|
* classifying severity from one config while the rules ran from another
|
|
125
125
|
* downgrades a blocking failure to a warning.
|
|
126
126
|
*
|
|
127
|
-
* it also runs the FULL test tier, which `shipkit ci` skips while you work.
|
|
128
|
-
|
|
127
|
+
* it also runs the FULL test tier, which `shipkit ci` skips while you work.
|
|
128
|
+
*
|
|
129
|
+
* 'not run' when the checkout could not be made ready (its FAIL line says why): nothing was judged, so a caller
|
|
130
|
+
* never reports it as a red gate. */
|
|
131
|
+
export async function runReleaseGate(root: string, print: (l: string) => void, o: { units?: ReleaseUnit[]; allowDirty?: boolean } = {}): Promise<number | 'not run'> {
|
|
129
132
|
const r = await withHeadCheckout(root, async (dir, sha) => {
|
|
130
133
|
print(`note: gating HEAD ${sha.slice(0, 8)} in a clean checkout (${dir}): uncommitted work here is in no tag, so the gate never reads it`)
|
|
131
134
|
let config: RepoConfig
|
|
@@ -178,9 +181,13 @@ export async function runReleaseGate(root: string, print: (l: string) => void, o
|
|
|
178
181
|
})
|
|
179
182
|
if (typeof r === 'number') return r
|
|
180
183
|
print(`FAIL: ${r.error}`)
|
|
181
|
-
return
|
|
184
|
+
return 'not run'
|
|
182
185
|
}
|
|
183
186
|
|
|
187
|
+
/** the line a release or a bump stops on when the gate did not pass: a gate that never ran is not a red one */
|
|
188
|
+
export const gateStop = (gate: number | 'not run', what: 'release' | 'bump'): string =>
|
|
189
|
+
gate === 'not run' ? `the ci gate did not run, so nothing was judged red: fix what the FAIL line above names, then ${what} again` : `ci gate is red on HEAD${what === 'bump' ? ' (the merged result)' : ''} — fix it, commit, then ${what}`
|
|
190
|
+
|
|
184
191
|
/** the test checks of every sub-unit this release does not ship. No list
|
|
185
192
|
* given means the caller did not say, and every unit's suite runs. The root
|
|
186
193
|
* depends on what it contains, so a release that ships it runs them all. A
|
|
@@ -307,7 +314,8 @@ export async function releaseUnit(root: string, config: RepoConfig, unit: Releas
|
|
|
307
314
|
if (o.skipGate === true)
|
|
308
315
|
print(o.skipGateReason != null ? `ok: ci gate ${o.skipGateReason}` : 'WARN ci gate SKIPPED by --skip-gate — publishing unverified')
|
|
309
316
|
else {
|
|
310
|
-
|
|
317
|
+
const gate = await runReleaseGate(root, print, { units: [unit], allowDirty: o.allowDirty })
|
|
318
|
+
if (gate !== 0) { print(`FAIL: ${gateStop(gate, 'release')}`); return 1 }
|
|
311
319
|
print('ok: ci gate green')
|
|
312
320
|
}
|
|
313
321
|
|
package/src/review/cells.ts
CHANGED
|
@@ -297,7 +297,8 @@ export function cellsOf(t: Thread, items: readonly ReviewItem[]): Cell[] {
|
|
|
297
297
|
cells.sort((a, b) => a.at.localeCompare(b.at) || rank[a.kind] - rank[b.kind] || a.id.localeCompare(b.id))
|
|
298
298
|
const last = t.head.item.id
|
|
299
299
|
const latest = cells.find((c) => c.id === last)
|
|
300
|
-
|
|
300
|
+
// no findLast: a consumer's own typecheck reads this source, under whatever lib its tsconfig names
|
|
301
|
+
const answer = [...cells].reverse().find((c) => c.party === 'owner' && c.kind !== 'event' && c.id !== last)
|
|
301
302
|
const unreadIds = new Set(membersOf(t).flatMap((x) => unreadBy(x, 'owner').map((m) => `${x.item.id}/${m.id}`)))
|
|
302
303
|
for (const c of cells) {
|
|
303
304
|
if (c.kind === 'event') continue
|
package/src/review/format.ts
CHANGED
|
@@ -150,7 +150,7 @@ export function detail(x: ReviewItem, dir: string, full = false, followed = fals
|
|
|
150
150
|
const words = full ? x.thread.filter((m) => (m.text !== undefined || m.op !== undefined) && m.op !== 'seen') : said.filter((m) => m.text !== undefined && m.op === undefined)
|
|
151
151
|
const pins = said.filter((m) => m.rects !== undefined).at(-1)
|
|
152
152
|
const first = r.views[0]
|
|
153
|
-
const image = first &&
|
|
153
|
+
const image = first && !isGallery(first) ? Object.values(first.files) : []
|
|
154
154
|
return [
|
|
155
155
|
`${r.id} ${st.state.toUpperCase()}${st.why ? ` (${st.why})` : ''} raised by ${raisedBy(r.origin)} ${r.created}${r.commit ? ` at ${r.commit}` : ''}`,
|
|
156
156
|
head,
|
package/src/review/model.ts
CHANGED
|
@@ -166,6 +166,12 @@ export const tileName = (t: GalleryTile): string => (t.group ? `${t.group}/${t.l
|
|
|
166
166
|
export interface GalleryView {
|
|
167
167
|
label: string
|
|
168
168
|
gallery: GalleryTile[]
|
|
169
|
+
// a media view's optional fields, absent: `view.marks` reads on any ReviewView. `files` and `size` stay off
|
|
170
|
+
// this type: a consumer narrows with `'files' in view`, which an optional key here would stop
|
|
171
|
+
clip?: undefined
|
|
172
|
+
audio?: undefined
|
|
173
|
+
marks?: undefined
|
|
174
|
+
note?: undefined
|
|
169
175
|
}
|
|
170
176
|
|
|
171
177
|
export type ReviewView = MediaView | GalleryView
|
|
@@ -782,7 +788,14 @@ export function notAnswererOf(x: ReviewItem, me: { lane: string | null; session:
|
|
|
782
788
|
const s = stateOf(x, false)
|
|
783
789
|
if (op === 'seen' && s.state === 'closed' && s.why === 'approved') return null
|
|
784
790
|
const id = x.item.id
|
|
785
|
-
|
|
791
|
+
// the way out names claim only where claim takes it
|
|
792
|
+
const noClaim = allowed(s, 'claim', me.lane ?? 'agent', null, false)
|
|
793
|
+
const takeOver =
|
|
794
|
+
noClaim === null
|
|
795
|
+
? `another lane takes it over with sk review claim ${id} --as <lane>`
|
|
796
|
+
: s.state === 'asks' || s.state === 'draft'
|
|
797
|
+
? 'no other lane takes it over before the verdict'
|
|
798
|
+
: `no takeover: ${noClaim}`
|
|
786
799
|
const claimed = s.state === 'claimed' && s.since !== undefined ? s.worker : undefined
|
|
787
800
|
const lane = claimed ?? o.lane
|
|
788
801
|
if (lane) return me.lane === lane ? null : `${id} is answered by lane ${lane} (${claimed ? 'its claim' : 'it made the card'}): as that lane, SK_AGENT=${lane} or --as ${lane}; ${takeOver}`
|