rvlib-shipkit 2.22.0 → 2.23.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 +23 -0
- package/package.json +1 -1
- 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/checks/SK041-annex-links.check.ts +4 -2
- package/src/checks/SK043-scratch-on-the-mac.check.ts +45 -0
- package/src/cli/cmd_Annex.ts +60 -9
- package/src/cli/cmd_Home.ts +28 -0
- package/src/cli/cmd_Rec.ts +17 -7
- package/src/cli/cmd_Review.ts +27 -3
- package/src/core/machine-db.ts +8 -0
- package/src/home/claude-temp.ts +139 -0
- package/src/home/daemon-jobs.ts +10 -3
- package/src/home/global-units.ts +3 -0
- package/src/home/machine-stores.ts +27 -3
- package/src/home/pm.ts +4 -1
- package/src/home/run-pm.ts +1 -0
- package/src/identities/identities.ts +92 -24
- package/src/media-store/daemon.ts +2 -2
- package/src/media-store/purge.ts +4 -0
- 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 +218 -54
- 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 +363 -29
- 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/repo-config.ts +9 -1
- package/src/review/model.ts +33 -4
- package/src/serve/hub-app/hub.css +4 -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/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
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// scratch by itself (wiki tools/shipkit/annex.md, Scratch by itself): one pass, the daemon's `annex` job and `sk annex
|
|
2
|
+
// tidy`. Every offload record brought in line with the drive (born.ts: a spill while it is away, merged back when it
|
|
3
|
+
// returns), every folder a config declares born linked to the annex, stale scratch moved off the Mac once its disk is
|
|
4
|
+
// under the floor or the repo over its cap, and the annex's own scratch trimmed to its cap.
|
|
5
|
+
//
|
|
6
|
+
// the one constraint a reader breaks first: a folder is stale only when nothing under it moved for a day at the least,
|
|
7
|
+
// whatever the pressure: lanes write into scratch all day, and the offload's own checks are the net, not the plan
|
|
8
|
+
import { existsSync, lstatSync, readdirSync, readFileSync, rmSync, type Stats, writeFileSync } from 'node:fs'
|
|
9
|
+
import { dirname, join } from 'node:path'
|
|
10
|
+
import { machineDbPath, machineGet, machineSet } from '../core/machine-db.ts'
|
|
11
|
+
import { freeBytes } from '../media-store/purge.ts'
|
|
12
|
+
import { annexSpecs, type AnnexSpec, driveFree, isPresent, keepFree, type Sweep } from './annex.ts'
|
|
13
|
+
import { bear, bornCheck, deadStage, type Pass, sayOnce, settle } from './born.ts'
|
|
14
|
+
import { editOffloads, type Offload, offload, offloads, PART_MARK, type Probe, SCRATCH } from './offload.ts'
|
|
15
|
+
import { held, heldWords, localSnapshots } from './snapshots.ts'
|
|
16
|
+
|
|
17
|
+
const GB = 1e9
|
|
18
|
+
const DAY = 86_400_000
|
|
19
|
+
|
|
20
|
+
/** the house's scratch policy, `serve.annexScratch` of the house config: the default of every house repo */
|
|
21
|
+
export type AnnexScratch = {
|
|
22
|
+
/** scratch folders every house repo keeps on the annex from their first byte, repo relative */
|
|
23
|
+
born?: string[]
|
|
24
|
+
/** the most a repo's `.shipkit/tmp` and `.shipkit/cache` may hold on the Mac, in GB (20) */
|
|
25
|
+
capGb?: number
|
|
26
|
+
/** under this much free space on the Mac's disk, stale scratch moves to the annex, in GB (40) */
|
|
27
|
+
floorGb?: number
|
|
28
|
+
/** a folder nothing touched for this many days is stale (3); under the floor, 1 */
|
|
29
|
+
staleDays?: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** a repo's own scratch policy, `annex` in its repo.config.ts. Declaring it is the opt in: a repo without it is
|
|
33
|
+
* touched by no born folder and no stale pass, the house's included (`annex: {}` takes the house defaults) */
|
|
34
|
+
export type RepoAnnex = {
|
|
35
|
+
/** scratch folders this repo keeps on the annex from their first byte, beside the house's: each under
|
|
36
|
+
* `.shipkit/tmp` or `.shipkit/cache` */
|
|
37
|
+
born?: string[]
|
|
38
|
+
/** scratch folders that never leave the Mac: read hot, a measured slower read on the annex */
|
|
39
|
+
keep?: string[]
|
|
40
|
+
/** the most this repo's scratch may hold on the Mac, in GB, in place of the house's cap */
|
|
41
|
+
capGb?: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type ScratchPolicy = { born: string[]; keep: string[]; capGb: number; floorGb: number; staleDays: number }
|
|
45
|
+
|
|
46
|
+
export const SCRATCH_DEFAULTS = { capGb: 20, floorGb: 40, staleDays: 3 }
|
|
47
|
+
/** a file of the annex's scratch untouched for this long may go when the annex is over its scratch cap */
|
|
48
|
+
export const SCRATCH_KEEP_DAYS = 14
|
|
49
|
+
/** a stale folder smaller than this stays: a link per tiny folder frees nothing (measured on one repo: 164 folders
|
|
50
|
+
* stale for a day held 1.8 GB, one of them over 50 MB) */
|
|
51
|
+
const MIN_STALE_BYTES = 50e6
|
|
52
|
+
/** a fresh folder this big is looked into: its stale children move one by one */
|
|
53
|
+
const DESCEND_BYTES = 1e9
|
|
54
|
+
export const ANNEX_EVERY_MS = 30_000
|
|
55
|
+
/** the declarations, the stale scratch and the cap are read this often; the records every pass */
|
|
56
|
+
export const FULL_EVERY_MS = 10 * 60_000
|
|
57
|
+
const SWEEP_EVERY_MS = 60 * 60_000
|
|
58
|
+
const FULL_AT = 'annex-full-at'
|
|
59
|
+
const SWEPT_AT = 'annex-scratch-swept-at'
|
|
60
|
+
/** the last measure of each annex's scratch, `{ [path]: { files, bytes, at } }`: `sk annex` prints it */
|
|
61
|
+
export const SCRATCH_USE = 'annex-scratch-use'
|
|
62
|
+
|
|
63
|
+
/** the policy of a repo that declared `annex`; null for one that did not: nothing of its scratch moves by itself */
|
|
64
|
+
export function policyOf(house: AnnexScratch | undefined, repo: RepoAnnex): ScratchPolicy
|
|
65
|
+
export function policyOf(house: AnnexScratch | undefined, repo: RepoAnnex | undefined): ScratchPolicy | null
|
|
66
|
+
export function policyOf(house: AnnexScratch | undefined, repo: RepoAnnex | undefined): ScratchPolicy | null {
|
|
67
|
+
if (repo === undefined) return null
|
|
68
|
+
return {
|
|
69
|
+
born: [...new Set([...(house?.born ?? []), ...(repo?.born ?? [])])],
|
|
70
|
+
keep: [...(repo?.keep ?? [])],
|
|
71
|
+
capGb: repo?.capGb ?? house?.capGb ?? SCRATCH_DEFAULTS.capGb,
|
|
72
|
+
floorGb: house?.floorGb ?? SCRATCH_DEFAULTS.floorGb,
|
|
73
|
+
staleDays: Math.max(1, house?.staleDays ?? SCRATCH_DEFAULTS.staleDays),
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** bytes of a repo's scratch on the Mac: `.shipkit/tmp` and `.shipkit/cache`, links not followed, so an offloaded
|
|
78
|
+
* folder counts nothing and a spill counts whole (`du`: 0.5 s on 36 GB) */
|
|
79
|
+
export function scratchOnMac(root: string): number {
|
|
80
|
+
const dirs = SCRATCH.map((d) => join(root, d)).filter((d) => lstatSync(d, { throwIfNoEntry: false })?.isDirectory() === true)
|
|
81
|
+
if (dirs.length === 0) return 0
|
|
82
|
+
const r = Bun.spawnSync(['du', '-skP', ...dirs], { stdout: 'pipe', stderr: 'ignore' })
|
|
83
|
+
return r.stdout.toString().split('\n').reduce((n, l) => n + (Number(l.split('\t')[0]) || 0) * 1024, 0)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** every entry under `dir` by lstat, a link never followed (a recursive readdir follows one into a loop: a build's
|
|
87
|
+
* node_modules link), one that vanishes meanwhile skipped */
|
|
88
|
+
function eachEntry(dir: string, fn: (path: string, s: Stats) => void): void {
|
|
89
|
+
let names: string[]
|
|
90
|
+
try {
|
|
91
|
+
names = readdirSync(dir)
|
|
92
|
+
} catch {
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
for (const n of names) {
|
|
96
|
+
const p = join(dir, n)
|
|
97
|
+
const s = lstatSync(p, { throwIfNoEntry: false })
|
|
98
|
+
if (!s) continue
|
|
99
|
+
fn(p, s)
|
|
100
|
+
if (s.isDirectory()) eachEntry(p, fn)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** the bytes under `dir` and the newest time of anything in it, links not followed */
|
|
105
|
+
function walk(dir: string): { bytes: number; newest: number } {
|
|
106
|
+
const out = { bytes: 0, newest: lstatSync(dir).mtimeMs }
|
|
107
|
+
eachEntry(dir, (_, s) => {
|
|
108
|
+
out.newest = Math.max(out.newest, s.mtimeMs)
|
|
109
|
+
if (s.isFile()) out.bytes += s.size
|
|
110
|
+
})
|
|
111
|
+
return out
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** the name a move in flight leaves: an offload's `.part` or aside, a swap first move's aside, a copy brought back */
|
|
115
|
+
const IN_FLIGHT = /\.\d+\.(part|offloading|moving|back)$/
|
|
116
|
+
|
|
117
|
+
export type Stale = { rel: string; bytes: number; newest: number }
|
|
118
|
+
|
|
119
|
+
/** folders of the repo's scratch nothing touched for `days`, 50 MB or more, oldest first: each child of
|
|
120
|
+
* `.shipkit/tmp` and `.shipkit/cache`, and the children of a fresh one of 1 GB or more. Never a born or kept folder,
|
|
121
|
+
* nor one that holds one */
|
|
122
|
+
export function staleFolders(root: string, p: ScratchPolicy, now: number, days: number, o: { minBytes?: number; descendBytes?: number } = {}): Stale[] {
|
|
123
|
+
const minBytes = o.minBytes ?? MIN_STALE_BYTES
|
|
124
|
+
const descendBytes = o.descendBytes ?? DESCEND_BYTES
|
|
125
|
+
const fixed = [...p.born, ...p.keep]
|
|
126
|
+
const inside = (rel: string): boolean => fixed.some((k) => rel === k || rel.startsWith(`${k}/`))
|
|
127
|
+
const holds = (rel: string): boolean => fixed.some((k) => k.startsWith(`${rel}/`))
|
|
128
|
+
const out: Stale[] = []
|
|
129
|
+
const look = (rel: string, depth: number): void => {
|
|
130
|
+
for (const name of readdirSync(join(root, rel))) {
|
|
131
|
+
const r = `${rel}/${name}`
|
|
132
|
+
if (IN_FLIGHT.test(name) || inside(r) || lstatSync(join(root, r), { throwIfNoEntry: false })?.isDirectory() !== true) continue
|
|
133
|
+
let w
|
|
134
|
+
try {
|
|
135
|
+
w = walk(join(root, r))
|
|
136
|
+
} catch {
|
|
137
|
+
continue
|
|
138
|
+
}
|
|
139
|
+
if (!holds(r) && w.newest < now - days * DAY && w.bytes >= minBytes) out.push({ rel: r, ...w })
|
|
140
|
+
else if (depth === 1 && w.bytes >= descendBytes) look(r, 2)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
for (const base of SCRATCH) if (lstatSync(join(root, base), { throwIfNoEntry: false })?.isDirectory() && !inside(base)) look(base, 1)
|
|
144
|
+
return out.sort((a, b) => a.newest - b.newest || b.bytes - a.bytes)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type Aged = { moved: { rel: string; bytes: number }[]; refused: { rel: string; why: string }[]; onMac: number; free: number; days: number | null }
|
|
148
|
+
|
|
149
|
+
/** stale scratch of `root` to the annex, oldest first, while the disk is under the floor or the repo over its cap */
|
|
150
|
+
export async function agePass(root: string, p: ScratchPolicy, o: Probe & { now?: number; dry?: boolean; minBytes?: number }): Promise<Aged> {
|
|
151
|
+
const now = o.now ?? Date.now()
|
|
152
|
+
let onMac = scratchOnMac(root)
|
|
153
|
+
let free = freeBytes(root)
|
|
154
|
+
const pressed = (): boolean => free < p.floorGb * GB || onMac > p.capGb * GB
|
|
155
|
+
const out: Aged = { moved: [], refused: [], onMac, free, days: null }
|
|
156
|
+
if (!pressed()) return out
|
|
157
|
+
const days = free < p.floorGb * GB ? 1 : p.staleDays
|
|
158
|
+
out.days = days
|
|
159
|
+
for (const s of staleFolders(root, p, now, days, o)) {
|
|
160
|
+
if (!pressed()) break
|
|
161
|
+
try {
|
|
162
|
+
const m = await offload(root, s.rel, { ...o, dry: o.dry === true })
|
|
163
|
+
onMac -= m.bytes
|
|
164
|
+
if (o.dry) free += m.bytes
|
|
165
|
+
else free = freeBytes(root)
|
|
166
|
+
out.moved.push({ rel: s.rel, bytes: m.bytes })
|
|
167
|
+
} catch (e) {
|
|
168
|
+
out.refused.push({ rel: s.rel, why: (e as Error).message })
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
out.onMac = onMac
|
|
172
|
+
out.free = free
|
|
173
|
+
return out
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** trim an annex's scratch (`offload/`) under its `scratchMaxGb`, and its drive to `keepFreeGb`: files untouched for
|
|
177
|
+
* SCRATCH_KEEP_DAYS at the least, oldest first. A loser a merge kept is never one of them: it goes only by a hand.
|
|
178
|
+
* A staging folder shipkit marked whose process is dead goes at every sweep. Its measure is kept for `sk annex` */
|
|
179
|
+
export function scratchSweep(spec: AnnexSpec, o: { dry?: boolean; now?: number } = {}): Sweep {
|
|
180
|
+
const now = o.now ?? Date.now()
|
|
181
|
+
const dir = join(spec.path, 'offload')
|
|
182
|
+
const files: { path: string; size: number; used: number }[] = []
|
|
183
|
+
const out: Sweep = { annex: spec.path, files: 0, bytes: 0, freed: { files: 0, bytes: 0 } }
|
|
184
|
+
const present = isPresent(spec)
|
|
185
|
+
const kept = new Set(offloads().flatMap((r) => r.kept ?? []))
|
|
186
|
+
const stages: string[] = []
|
|
187
|
+
let parts = 0
|
|
188
|
+
let keptBytes = 0
|
|
189
|
+
eachEntry(dir, (path, s) => {
|
|
190
|
+
if (stages.some((st) => path.startsWith(`${st}/`))) return
|
|
191
|
+
if (s.isDirectory() && /\.\d+\.part$/.test(path) && existsSync(join(path, PART_MARK))) {
|
|
192
|
+
stages.push(path)
|
|
193
|
+
if (present && deadStage(path)) {
|
|
194
|
+
if (!o.dry) rmSync(path, { recursive: true, force: true })
|
|
195
|
+
parts++
|
|
196
|
+
out.freed.files++
|
|
197
|
+
}
|
|
198
|
+
} else if (s.isFile() && kept.has(path)) keptBytes += s.size
|
|
199
|
+
else if (s.isFile()) files.push({ path, size: s.size, used: s.mtimeMs })
|
|
200
|
+
})
|
|
201
|
+
files.sort((a, b) => a.used - b.used)
|
|
202
|
+
let bytes = files.reduce((n, f) => n + f.size, keptBytes)
|
|
203
|
+
out.files = files.length
|
|
204
|
+
out.bytes = bytes
|
|
205
|
+
if (!present) return out
|
|
206
|
+
const cap = spec.scratchMaxGb === undefined ? Infinity : spec.scratchMaxGb * GB
|
|
207
|
+
let free = driveFree(spec.path)
|
|
208
|
+
for (const f of files) {
|
|
209
|
+
if ((bytes <= cap && free >= keepFree(spec)) || f.used > now - SCRATCH_KEEP_DAYS * DAY) break
|
|
210
|
+
if (!o.dry) rmSync(f.path, { force: true })
|
|
211
|
+
bytes -= f.size
|
|
212
|
+
free += f.size
|
|
213
|
+
out.freed.files++
|
|
214
|
+
out.freed.bytes += f.size
|
|
215
|
+
}
|
|
216
|
+
if (!o.dry) machineSet(SCRATCH_USE, { ...(machineGet<Record<string, unknown>>(SCRATCH_USE) ?? {}), [spec.path]: { files: files.length - (out.freed.files - parts), bytes, at: now } })
|
|
217
|
+
return out
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** one pass at a time on the machine: the daemon's and a hand's. A holder that died frees it */
|
|
221
|
+
function passLock(): (() => void) | null {
|
|
222
|
+
const path = join(dirname(machineDbPath()), 'annex-pass.pid')
|
|
223
|
+
for (let i = 0; i < 2; i++) {
|
|
224
|
+
try {
|
|
225
|
+
writeFileSync(path, String(process.pid), { flag: 'wx' })
|
|
226
|
+
return () => rmSync(path, { force: true })
|
|
227
|
+
} catch {
|
|
228
|
+
const pid = Number(readFileSync(path, 'utf8').trim())
|
|
229
|
+
let alive = false
|
|
230
|
+
try {
|
|
231
|
+
alive = pid > 0 && process.kill(pid, 0)
|
|
232
|
+
} catch {
|
|
233
|
+
alive = false
|
|
234
|
+
}
|
|
235
|
+
if (alive) return null
|
|
236
|
+
rmSync(path, { force: true })
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return null
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** the daemon looks at this every 30 s, a few stats: a link that dangles, a spill whose drive is back, an aside left,
|
|
243
|
+
* a born folder gone, or the full pass due */
|
|
244
|
+
export function annexDue(now: number): boolean {
|
|
245
|
+
if (!annexAuto()) return false
|
|
246
|
+
if (now - (machineGet<number>(FULL_AT) ?? 0) >= FULL_EVERY_MS) return true
|
|
247
|
+
for (const r of offloads()) {
|
|
248
|
+
if (r.aside !== undefined) return true
|
|
249
|
+
const at = join(r.repo, r.rel)
|
|
250
|
+
const l = lstatSync(at, { throwIfNoEntry: false })
|
|
251
|
+
if (l?.isSymbolicLink() && !existsSync(at)) return true
|
|
252
|
+
if (r.spill !== undefined && existsSync(r.target)) return true
|
|
253
|
+
if (r.born && r.spill === undefined && !l?.isSymbolicLink()) return true
|
|
254
|
+
}
|
|
255
|
+
return false
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export type TickOpts = Probe & {
|
|
259
|
+
roots: string[]
|
|
260
|
+
/** the house repo, whose config holds `serve.annexScratch` */
|
|
261
|
+
house: string | null
|
|
262
|
+
print: (l: string) => void
|
|
263
|
+
printErr: (l: string) => void
|
|
264
|
+
now?: number
|
|
265
|
+
/** the declarations, the stale scratch and the cap now, whenever the last full pass ran */
|
|
266
|
+
full?: boolean
|
|
267
|
+
/** what the stale pass and the sweep would do; no record is settled, no folder linked */
|
|
268
|
+
dry?: boolean
|
|
269
|
+
openUnder?: Pass['openUnder']
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const AUTO_KEY = 'annex-auto'
|
|
273
|
+
/** the owner's switch, off until it is turned on (`sk annex tidy --auto on`): the daemon's job moves nothing before */
|
|
274
|
+
export const annexAuto = (): boolean => machineGet<boolean>(AUTO_KEY) === true
|
|
275
|
+
export const setAnnexAuto = (on: boolean): boolean => machineSet(AUTO_KEY, on)
|
|
276
|
+
|
|
277
|
+
/** one pass: the daemon's `annex` job (only once the switch is on), `sk annex tidy` (a hand's: `full`) */
|
|
278
|
+
export async function annexTick(o: TickOpts): Promise<void> {
|
|
279
|
+
if (!o.full && !annexAuto()) return
|
|
280
|
+
const release = passLock()
|
|
281
|
+
if (!release) {
|
|
282
|
+
o.printErr('annex: another annex pass runs: this one stops')
|
|
283
|
+
return
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
await tick(o)
|
|
287
|
+
} finally {
|
|
288
|
+
release()
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async function tick(o: TickOpts): Promise<void> {
|
|
293
|
+
const now = o.now ?? Date.now()
|
|
294
|
+
const say = (l: string): void => (l.startsWith('WARN') ? o.printErr(l) : o.print(l))
|
|
295
|
+
const pass: Pass = { ...o, say, now, loud: o.full === true }
|
|
296
|
+
const specs = await annexSpecs()
|
|
297
|
+
const roots = new Set(o.roots)
|
|
298
|
+
if (!o.dry)
|
|
299
|
+
for (const r of offloads())
|
|
300
|
+
if (roots.has(r.repo))
|
|
301
|
+
try {
|
|
302
|
+
settle(r, specs, pass)
|
|
303
|
+
} catch (e) {
|
|
304
|
+
o.printErr(`WARN annex: ${r.rel} of ${r.repo} not settled: ${(e as Error).message}`)
|
|
305
|
+
}
|
|
306
|
+
if (!o.full && now - (machineGet<number>(FULL_AT) ?? 0) < FULL_EVERY_MS) return
|
|
307
|
+
if (!o.dry) machineSet(FULL_AT, now)
|
|
308
|
+
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
309
|
+
const house = o.house ? ((await loadRepoConfig(o.house).catch(() => null))?.serve?.annexScratch ?? undefined) : undefined
|
|
310
|
+
let floor = policyOf(house, {}).floorGb
|
|
311
|
+
for (const root of roots) {
|
|
312
|
+
if (!existsSync(join(root, 'repo.config.ts'))) continue
|
|
313
|
+
let cfg
|
|
314
|
+
try {
|
|
315
|
+
cfg = await loadRepoConfig(root)
|
|
316
|
+
} catch (e) {
|
|
317
|
+
o.printErr(`WARN annex: ${root}: its repo.config.ts does not load, its scratch is left as it is: ${(e as Error).message}`)
|
|
318
|
+
continue
|
|
319
|
+
}
|
|
320
|
+
const p = policyOf(house, cfg.annex)
|
|
321
|
+
if (p === null) {
|
|
322
|
+
// not opted in: its records stay as they are, none of them born
|
|
323
|
+
if (o.dry) o.print(`${root}: no annex key in its repo.config.ts: nothing of its scratch moves by itself (annex: {} opts in)`)
|
|
324
|
+
else if (offloads().some((x) => x.repo === root && x.born === true)) editOffloads((list) => list.map((x) => (x.repo === root && x.born === true ? { ...x, born: false } : x)))
|
|
325
|
+
continue
|
|
326
|
+
}
|
|
327
|
+
if (o.dry) {
|
|
328
|
+
for (const rel of p.born) {
|
|
329
|
+
const r = offloads().find((x) => x.repo === root && x.rel === rel)
|
|
330
|
+
const c = r ? null : await bornCheck(root, rel, specs, { ...o, say: () => undefined })
|
|
331
|
+
o.print(`born ${rel}: ${r ? (r.spill !== undefined ? 'a spill on the Mac' : 'on the annex') : c && 'why' in c ? c.why : 'would be linked to the annex'}`)
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
for (const rel of p.born)
|
|
335
|
+
try {
|
|
336
|
+
await bear(root, rel, specs, pass)
|
|
337
|
+
} catch (e) {
|
|
338
|
+
o.printErr(`WARN annex: ${rel} of ${root} not linked: ${(e as Error).message}`)
|
|
339
|
+
}
|
|
340
|
+
const unborn = (x: Offload): boolean => x.repo === root && x.born === true && !p.born.includes(x.rel)
|
|
341
|
+
if (offloads().some(unborn)) editOffloads((list) => list.map((x) => (unborn(x) ? { ...x, born: false } : x)))
|
|
342
|
+
}
|
|
343
|
+
floor = p.floorGb
|
|
344
|
+
const a = await agePass(root, p, { ...o, now })
|
|
345
|
+
if (a.days === null) {
|
|
346
|
+
if (o.dry) o.print(`${root}: scratch on the Mac ${(a.onMac / GB).toFixed(1)} GB of ${p.capGb} GB, the disk ${(a.free / GB).toFixed(1)} GB free over its ${p.floorGb} GB floor: nothing to move`)
|
|
347
|
+
continue
|
|
348
|
+
}
|
|
349
|
+
for (const m of a.moved) o.print(`${o.dry ? 'would move' : 'ok: annex: moved'} ${m.rel} of ${root} (stale ${a.days} days, ${(m.bytes / GB).toFixed(1)} GB)`)
|
|
350
|
+
const key = `aged:${root}`
|
|
351
|
+
if (a.onMac > p.capGb * GB && !o.dry)
|
|
352
|
+
sayOnce(key, `WARN annex: ${root}: ${(a.onMac / GB).toFixed(1)} GB of scratch on the Mac, over its ${p.capGb} GB cap, and nothing more stale for ${a.days} days moves${a.refused.length > 0 ? `; refused: ${a.refused[0]!.rel}: ${a.refused[0]!.why}` : ''}: what is fresh stays, a folder that belongs on the annex goes in annex.born`, say, o.full)
|
|
353
|
+
else if (!o.dry) sayOnce(key, null, say)
|
|
354
|
+
if (o.dry) for (const r of a.refused) o.print(`refused ${r.rel}: ${r.why}`)
|
|
355
|
+
}
|
|
356
|
+
// the disk under its floor once every repo moved what it could: said once for the machine, never once a repo
|
|
357
|
+
const free = freeBytes(o.house ?? [...roots][0] ?? '/')
|
|
358
|
+
if (!o.dry) {
|
|
359
|
+
const words = free < floor * GB ? heldWords(held(offloads(), localSnapshots())) : null
|
|
360
|
+
sayOnce('floor', free < floor * GB ? `WARN annex: the Mac's disk has ${(free / GB).toFixed(1)} GB free, under its ${floor} GB floor, with every stale scratch folder moved${words ? `; ${words}` : ''}` : null, say, o.full)
|
|
361
|
+
}
|
|
362
|
+
if (!o.full && now - (machineGet<number>(SWEPT_AT) ?? 0) < SWEEP_EVERY_MS) return
|
|
363
|
+
if (!o.dry) machineSet(SWEPT_AT, now)
|
|
364
|
+
for (const a of specs.filter(isPresent)) {
|
|
365
|
+
const s = scratchSweep(a, { dry: o.dry === true, now })
|
|
366
|
+
if (s.freed.files > 0) o.print(`${o.dry ? 'would free' : 'ok: annex: freed'} ${s.freed.files} scratch files of ${a.path} (${(s.freed.bytes / GB).toFixed(1)} GB), untouched ${SCRATCH_KEEP_DAYS} days`)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// `sk annex offload` moved to an external drive still reaches its copy there.
|
|
3
3
|
// It warns, never fails: an unplugged drive is the world, not the repo. A link
|
|
4
4
|
// that reaches nothing, a recorded folder that is no longer a link (a reset made
|
|
5
|
-
// a real folder on the Mac),
|
|
6
|
-
//
|
|
5
|
+
// a real folder on the Mac), a move in flight (a Mac copy set aside, recorded or
|
|
6
|
+
// not), a spill, a loser a merge kept beside its winner, and a folder on the
|
|
7
|
+
// annex no link reaches are each named with what settles them; a born folder's
|
|
8
|
+
// never names `forget`
|
|
7
9
|
import { check } from '../check.ts'
|
|
8
10
|
|
|
9
11
|
export const annexLinks = check({
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// SK043 scratch on the Mac (tools/shipkit/annex.md, Scratch by itself): this repo's `.shipkit/tmp` and `.shipkit/cache`
|
|
2
|
+
// on the Mac's own disk, links not followed, stay under the cap (`annex.capGb`, else the house's `serve.annexScratch`,
|
|
3
|
+
// else 20 GB). A folder born on the annex or moved there is a link and counts nothing; a spill counts whole. It warns,
|
|
4
|
+
// never fails: the daemon's annex job moves stale scratch by itself in a repo that declared `annex`, and this row says
|
|
5
|
+
// when it could not, with the one command that runs the pass now; in a repo that declared none, it names the opt in
|
|
6
|
+
import { check } from '../check.ts'
|
|
7
|
+
|
|
8
|
+
const GB = 1e9
|
|
9
|
+
|
|
10
|
+
/** why the scratch on the Mac is over its cap, null while it is under. `opted`: the repo declares `annex`, so the
|
|
11
|
+
* pass may move its stale scratch */
|
|
12
|
+
export function scratchProblem(bytes: number, capGb: number, opted = true): string | null {
|
|
13
|
+
if (bytes <= capGb * GB) return null
|
|
14
|
+
if (!opted) return `${(bytes / GB).toFixed(1)} GB of .shipkit/tmp and .shipkit/cache on the Mac, over the ${capGb} GB cap, and repo.config.ts declares no annex key, so nothing of it moves by itself: add annex: {} (the house defaults; keep names a folder read hot, born one that lives on the annex), then sk annex tidy --dry lists what would move`
|
|
15
|
+
return `${(bytes / GB).toFixed(1)} GB of .shipkit/tmp and .shipkit/cache on the Mac, over its ${capGb} GB cap: sk annex tidy moves stale scratch to the annex now (sk annex tidy --dry lists it first); a folder that must live there from its first byte goes in annex.born of repo.config.ts`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const scratchOnTheMac = check({
|
|
19
|
+
id: 'SK043',
|
|
20
|
+
blocking: false,
|
|
21
|
+
title: 'scratch on the Mac',
|
|
22
|
+
description: "this repo's .shipkit/tmp and .shipkit/cache on the Mac's disk stay under the scratch cap",
|
|
23
|
+
owner: 'tools/shipkit/annex.md',
|
|
24
|
+
runs: { onPreCommit: false, onCi: false, onFull: true, onRelease: false, onHealth: true, onSave: false, onClock: false },
|
|
25
|
+
cache: { by: 'never', why: 'it measures scratch outside git, one du of about half a second' },
|
|
26
|
+
fix: 'none',
|
|
27
|
+
applies: 'always',
|
|
28
|
+
run: async (c) => {
|
|
29
|
+
const { policyOf, scratchOnMac } = await import('../annex/tidy.ts')
|
|
30
|
+
const { houseRootOf } = await import('../home/home-start.ts')
|
|
31
|
+
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
32
|
+
const house = houseRootOf(c.root)
|
|
33
|
+
const houseScratch = house == null || house === c.root ? c.config.serve?.annexScratch : (await loadRepoConfig(house).catch(() => null))?.serve?.annexScratch
|
|
34
|
+
const p = policyOf(houseScratch, c.config.annex ?? {})
|
|
35
|
+
const { offloads } = await import('../annex/offload.ts')
|
|
36
|
+
const { held, heldWords, localSnapshots } = await import('../annex/snapshots.ts')
|
|
37
|
+
const bytes = scratchOnMac(c.root)
|
|
38
|
+
const why = scratchProblem(bytes, p.capGb, c.config.annex !== undefined)
|
|
39
|
+
const words = heldWords(held(offloads().filter((x) => x.repo === c.root), localSnapshots()))
|
|
40
|
+
if (why) c.warn(words ? `${why}; ${words}` : why)
|
|
41
|
+
else c.ok(`${(bytes / GB).toFixed(1)} GB of scratch on the Mac, cap ${p.capGb} GB${words ? `; ${words}` : ''}`)
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
export default scratchOnTheMac
|
package/src/cli/cmd_Annex.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// to the cap. Every module loads inside execute: the cli registers this file on every `sk` call
|
|
4
4
|
import { Command, Option } from 'clipanion'
|
|
5
5
|
|
|
6
|
-
const DETAILS = `an annex is a folder on an external drive the house config lists (serve.annexes in the house repo config), present only while its root holds the marker sk annex init wrote. A media purge moves each file there before the Mac lets it go, a fetch back reads it before the Space, and sk annex offload moves a repo's .shipkit/cache or .shipkit/tmp folders there behind a symlink.
|
|
6
|
+
const DETAILS = `an annex is a folder on an external drive the house config lists (serve.annexes in the house repo config), present only while its root holds the marker sk annex init wrote. A media purge moves each file there before the Mac lets it go, a fetch back reads it before the Space, and sk annex offload moves a repo's .shipkit/cache or .shipkit/tmp folders there behind a symlink. The daemon's annex job does it by itself, in a repo that declares annex in its repo.config.ts: folders a config declares born live there from their first byte, stale scratch moves there when the disk is low or a repo over its cap, a local spill stands in while the drive is away. An offload, a stale folder and a born folder's first move refuse a db, a lock, a git worktree and a backed up file; what a tool writes into a born folder later lives on the annex. A merge never deletes a file that differs from its other copy: the loser is kept beside it and named here. Page: wiki tools/shipkit/annex.md`
|
|
7
7
|
|
|
8
8
|
type Ctx = { stdout: NodeJS.WritableStream; stderr: NodeJS.WritableStream }
|
|
9
9
|
|
|
@@ -39,8 +39,11 @@ export class AnnexCommand extends Command {
|
|
|
39
39
|
return run(this.context, async (out) => {
|
|
40
40
|
const { annexSpecs, driveFree, isPresent, mediaFiles } = await import('../annex/annex.ts')
|
|
41
41
|
const { drift, offloads } = await import('../annex/offload.ts')
|
|
42
|
+
const { SCRATCH_USE } = await import('../annex/tidy.ts')
|
|
43
|
+
const { machineGet } = await import('../core/machine-db.ts')
|
|
42
44
|
const { existsSync } = await import('node:fs')
|
|
43
45
|
const specs = await annexSpecs()
|
|
46
|
+
const use = machineGet<Record<string, { files: number; bytes: number; at: number }>>(SCRATCH_USE) ?? {}
|
|
44
47
|
if (specs.length === 0) out('no annex: the house config lists none (serve.annexes)')
|
|
45
48
|
for (const a of specs) {
|
|
46
49
|
if (!isPresent(a)) {
|
|
@@ -49,18 +52,34 @@ export class AnnexCommand extends Command {
|
|
|
49
52
|
}
|
|
50
53
|
const m = mediaFiles(a)
|
|
51
54
|
const bytes = m.reduce((s, f) => s + f.size, 0)
|
|
52
|
-
|
|
55
|
+
const u = use[a.path]
|
|
56
|
+
const scratch = u ? `${u.files} files ${gb(u.bytes)}${a.scratchMaxGb !== undefined ? ` of ${a.scratchMaxGb} GB` : ''} (measured ${new Date(u.at).toISOString().slice(0, 16)}Z)` : `not measured yet${a.scratchMaxGb !== undefined ? `, cap ${a.scratchMaxGb} GB` : ''}`
|
|
57
|
+
out(`${a.path} present free ${gb(driveFree(a.path))} media ${m.length} files ${gb(bytes)}${a.maxGb !== undefined ? ` of ${a.maxGb} GB` : ''} scratch ${scratch}`)
|
|
53
58
|
}
|
|
59
|
+
const { annexAuto } = await import('../annex/tidy.ts')
|
|
60
|
+
const { held, heldWords, localSnapshots } = await import('../annex/snapshots.ts')
|
|
54
61
|
const list = offloads()
|
|
62
|
+
out(`the daemon's annex job: ${annexAuto() ? 'on' : 'off (sk annex tidy --auto on turns it on)'}`)
|
|
63
|
+
const words = heldWords(held(list, localSnapshots()))
|
|
64
|
+
if (words) out(words)
|
|
65
|
+
const { waitingBorn } = await import('../annex/born.ts')
|
|
66
|
+
for (const l of waitingBorn()) out(` waits: ${l.replace(/^WARN annex: /, '')}`)
|
|
55
67
|
for (const repo of [...new Set(list.map((x) => x.repo))]) {
|
|
56
68
|
const bad = new Map((await drift(repo)).map((d) => [d.path, d] as const))
|
|
57
69
|
for (const x of list.filter((y) => y.repo === repo)) {
|
|
58
70
|
const d = bad.get(`${x.repo}/${x.rel}`)
|
|
59
|
-
out(` ${repo}/${x.rel} ${gb(x.bytes)} ${d ? `${d.kind.toUpperCase()}: ${d.why}` : 'link holds'}`)
|
|
71
|
+
out(` ${repo}/${x.rel} ${x.born ? 'born' : `${gb(x.bytes)} moved`} ${d ? `${d.kind.toUpperCase()}: ${d.why}` : 'link holds'}`)
|
|
60
72
|
}
|
|
61
|
-
for (const d of bad.values()) if (d.kind === 'orphan') out(`
|
|
73
|
+
for (const d of bad.values()) if (d.kind === 'orphan' || !list.some((x) => `${x.repo}/${x.rel}` === d.path)) out(` ${d.kind.toUpperCase()} ${d.path}: ${d.why}`)
|
|
62
74
|
for (const d of bad.values()) out(` → ${d.fix}`)
|
|
63
75
|
}
|
|
76
|
+
const { readdirSync } = await import('node:fs')
|
|
77
|
+
const { join } = await import('node:path')
|
|
78
|
+
for (const a of specs.filter(isPresent)) {
|
|
79
|
+
const trash = join(a.path, 'offload', '.trash')
|
|
80
|
+
const wiped = existsSync(trash) ? readdirSync(trash) : []
|
|
81
|
+
if (wiped.length > 0) out(`${trash}: ${wiped.length} wiped folders kept (the annex's scratch cap trims them): ${wiped.slice(-3).join(', ')}`)
|
|
82
|
+
}
|
|
64
83
|
return 0
|
|
65
84
|
})
|
|
66
85
|
}
|
|
@@ -141,7 +160,7 @@ export class AnnexForgetCommand extends Command {
|
|
|
141
160
|
static override usage = Command.Usage({
|
|
142
161
|
category: 'Annex',
|
|
143
162
|
description: 'drop an offload record the Mac no longer needs: a split, a dead link, or nothing left',
|
|
144
|
-
details: `${DETAILS}\n\nA split (a real folder where the link was, after a cache reset) keeps the Mac folder and
|
|
163
|
+
details: `${DETAILS}\n\nA split (a real folder where the link was, after a cache reset) keeps the Mac folder and moves the stale annex copy to the annex's trash. A dangling link (the drive gone for good) loses the link and its record. Refused while the link holds (sk annex back brings a folder home), when the link is gone while the annex copy is there (relink it), for a born folder (drop it from annex.born first), a spill (plug the drive in) and a move in flight (the next pass finishes it).`,
|
|
145
164
|
examples: [['settle a split', 'sk annex forget .shipkit/cache']],
|
|
146
165
|
})
|
|
147
166
|
folder = Option.String({ required: true })
|
|
@@ -159,21 +178,53 @@ export class AnnexSweepCommand extends Command {
|
|
|
159
178
|
static override paths = [['annex', 'sweep']]
|
|
160
179
|
static override usage = Command.Usage({
|
|
161
180
|
category: 'Annex',
|
|
162
|
-
description: "trim each annex's media to
|
|
163
|
-
details: `${DETAILS}\n\
|
|
181
|
+
description: "trim each annex's media and scratch to their caps, used longest ago first",
|
|
182
|
+
details: `${DETAILS}\n\nMedia: the Space holds every file, so any may go, used longest ago first; the purge runs it after each pass that kept a file on an annex. Scratch (offload/, born and offloaded folders): only files untouched for 14 days, oldest first, past the annex's scratchMaxGb or its keepFreeGb; the daemon's annex job runs it hourly.`,
|
|
164
183
|
examples: [['what would go', 'sk annex sweep --dry']],
|
|
165
184
|
})
|
|
166
185
|
dry = Option.Boolean('--dry', false, { description: 'print what would go, delete nothing' })
|
|
167
186
|
async execute(): Promise<number> {
|
|
168
187
|
return run(this.context, async (out) => {
|
|
169
188
|
const { annexSweep, presentAnnexes } = await import('../annex/annex.ts')
|
|
189
|
+
const { scratchSweep } = await import('../annex/tidy.ts')
|
|
170
190
|
for (const a of await presentAnnexes()) {
|
|
171
191
|
const s = annexSweep(a, { dry: this.dry })
|
|
172
|
-
out(`${a.path} ${s.files} files ${gb(s.bytes)} ${this.dry ? 'would free' : 'freed'} ${s.freed.files} files ${gb(s.freed.bytes)}`)
|
|
192
|
+
out(`${a.path} media ${s.files} files ${gb(s.bytes)} ${this.dry ? 'would free' : 'freed'} ${s.freed.files} files ${gb(s.freed.bytes)}`)
|
|
193
|
+
const c = scratchSweep(a, { dry: this.dry })
|
|
194
|
+
out(`${a.path} scratch ${c.files} files ${gb(c.bytes)} ${this.dry ? 'would free' : 'freed'} ${c.freed.files} files ${gb(c.freed.bytes)}`)
|
|
173
195
|
}
|
|
174
196
|
return 0
|
|
175
197
|
})
|
|
176
198
|
}
|
|
177
199
|
}
|
|
178
200
|
|
|
179
|
-
export
|
|
201
|
+
export class AnnexTidyCommand extends Command {
|
|
202
|
+
static override paths = [['annex', 'tidy']]
|
|
203
|
+
static override usage = Command.Usage({
|
|
204
|
+
category: 'Annex',
|
|
205
|
+
description: "the daemon's annex pass now, for this repo: born folders linked, spills merged, stale scratch moved",
|
|
206
|
+
details: `${DETAILS}\n\nThe daemon runs this pass by itself once the owner turned its switch on (--auto on; its annex job: the records every 30 s, the rest every 10 min). In every repo it keeps the records in line with the drive: a spill while it is away, taken back once it returns, a move a kill stopped finished. Only in a repo whose repo.config.ts declares annex (annex: {} takes the house defaults), it also links each folder the repo or house config declares born (annex.born, serve.annexScratch.born), keeps a born folder wiped on the Mac wiped (its old annex content to the annex's trash), and, when the disk is under its floor or the repo's scratch on the Mac over its cap, moves stale folders of .shipkit/tmp and .shipkit/cache to the annex, oldest first, through sk annex offload's own checks.`,
|
|
207
|
+
examples: [['what it would move', 'sk annex tidy --dry'], ['the pass now', 'sk annex tidy'], ['the daemon does it by itself from now on', 'sk annex tidy --auto on']],
|
|
208
|
+
})
|
|
209
|
+
dry = Option.Boolean('--dry', false, { description: 'print what the stale pass and the sweep would do, move nothing' })
|
|
210
|
+
auto = Option.String('--auto', { description: "on: the daemon's annex job runs this pass by itself, for every house repo; off stops it (off until the owner turns it on)" })
|
|
211
|
+
async execute(): Promise<number> {
|
|
212
|
+
return run(this.context, async (out) => {
|
|
213
|
+
const { annexAuto, annexTick, setAnnexAuto } = await import('../annex/tidy.ts')
|
|
214
|
+
if (this.auto !== undefined) {
|
|
215
|
+
if (this.auto !== 'on' && this.auto !== 'off') throw new Error(`--auto takes on or off, not ${this.auto}`)
|
|
216
|
+
if (!setAnnexAuto(this.auto === 'on')) throw new Error('the machine db does not open: the switch is not set')
|
|
217
|
+
out(`the daemon's annex job: ${annexAuto() ? 'on, every house repo, by itself' : 'off: nothing moves unless sk annex tidy runs by hand'}`)
|
|
218
|
+
return 0
|
|
219
|
+
}
|
|
220
|
+
const { findRepoRoot } = await import('../ts/config.ts')
|
|
221
|
+
const { houseRoot } = await import('../home/home-start.ts')
|
|
222
|
+
const root = findRepoRoot(process.cwd())
|
|
223
|
+
let warned = 0
|
|
224
|
+
await annexTick({ roots: [root], house: houseRoot(root), print: out, printErr: (l) => void (warned++, this.context.stderr.write(`${l}\n`)), full: true, dry: this.dry })
|
|
225
|
+
return warned > 0 ? 1 : 0
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export const ANNEX_COMMANDS = [AnnexCommand, AnnexInitCommand, AnnexOffloadCommand, AnnexBackCommand, AnnexForgetCommand, AnnexSweepCommand, AnnexTidyCommand]
|
package/src/cli/cmd_Home.ts
CHANGED
|
@@ -97,10 +97,14 @@ export class DaemonJobCommand extends Command {
|
|
|
97
97
|
['a retention sweep now', 'sk daemon job "retention sweep"'],
|
|
98
98
|
['one media store pass', 'sk daemon job "media store"'],
|
|
99
99
|
['the house\'s global context written now', 'sk daemon job "global context"'],
|
|
100
|
+
['what the sweep\'s claude temp pass would delete', 'sk daemon job "retention sweep" --dry'],
|
|
101
|
+
['the sweep trims claude temp from now on', 'sk daemon job "retention sweep" --claude-temp on'],
|
|
100
102
|
],
|
|
101
103
|
})
|
|
102
104
|
|
|
103
105
|
id = Option.String({ required: true, name: 'id' })
|
|
106
|
+
dry = Option.Boolean('--dry', false, { description: 'retention sweep only: print each claude temp folder the pass would delete (idle age, size) and the total, delete nothing, sweep no other store' })
|
|
107
|
+
claudeTemp = Option.String('--claude-temp', { description: 'retention sweep only: on, the sweep trims claude code\'s session temp folders (sessions idle 24 h or more past 5 GB, oldest first); off stops it (off until the owner turns it on)' })
|
|
104
108
|
|
|
105
109
|
async execute(): Promise<number> {
|
|
106
110
|
const { isJobId, DAEMON_JOBS, runJobBody } = await import('../home/daemon-jobs.ts')
|
|
@@ -108,6 +112,30 @@ export class DaemonJobCommand extends Command {
|
|
|
108
112
|
this.context.stderr.write(`FAIL: no daemon job ${JSON.stringify(this.id)}: ${DAEMON_JOBS.map((j) => j.id).join(', ')}\n`)
|
|
109
113
|
return 1
|
|
110
114
|
}
|
|
115
|
+
if (this.dry || this.claudeTemp !== undefined) {
|
|
116
|
+
if (this.id !== 'retention sweep') {
|
|
117
|
+
this.context.stderr.write(`FAIL: --dry and --claude-temp belong to the retention sweep, not ${this.id}\n`)
|
|
118
|
+
return 1
|
|
119
|
+
}
|
|
120
|
+
const t = await import('../home/claude-temp.ts')
|
|
121
|
+
const out = (l: string): void => void this.context.stdout.write(`${l}\n`)
|
|
122
|
+
const err = (l: string): void => void this.context.stderr.write(`${l}\n`)
|
|
123
|
+
if (this.claudeTemp !== undefined) {
|
|
124
|
+
if (this.claudeTemp !== 'on' && this.claudeTemp !== 'off') { err(`FAIL: --claude-temp takes on or off, not ${this.claudeTemp}`); return 1 }
|
|
125
|
+
if (!t.setClaudeTempAuto(this.claudeTemp === 'on')) { err('FAIL: the machine db does not open: the switch is not set'); return 1 }
|
|
126
|
+
}
|
|
127
|
+
out(`the sweep's claude temp pass: ${t.claudeTempAuto() ? 'on' : 'off (sk daemon job "retention sweep" --claude-temp on turns it on)'}`)
|
|
128
|
+
if (!this.dry) return 0
|
|
129
|
+
const root = t.claudeTempRoot()
|
|
130
|
+
if (root == null) { err('FAIL: no uid on this platform'); return 1 }
|
|
131
|
+
try {
|
|
132
|
+
t.trimClaudeTemp(root, { now: Date.now(), dry: true, print: out, printErr: err })
|
|
133
|
+
return 0
|
|
134
|
+
} catch (e) {
|
|
135
|
+
err(`FAIL: ${(e as Error).message}`)
|
|
136
|
+
return 1
|
|
137
|
+
}
|
|
138
|
+
}
|
|
111
139
|
const { homedir } = await import('node:os')
|
|
112
140
|
const { findRepoRoot } = await import('../ts/config.ts')
|
|
113
141
|
// its lines land in the daemon's log: each one stamped and named
|