@oficiallyakshay/trash-panda 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +108 -2
- package/docs/reference.md +220 -0
- package/examples/in-charge.json +7 -0
- package/examples/live.json +17 -0
- package/package.json +38 -4
- package/scripts/claude-leftovers-cleanup.mjs +242 -0
- package/src/claude-leftovers.mjs +949 -0
- package/src/metrics.mjs +233 -0
- package/src/rebuildables.mjs +491 -0
- package/src/records.mjs +326 -0
- package/src/settings.mjs +205 -0
- package/src/setup.mjs +428 -0
- package/src/temp-entries.mjs +153 -0
- package/src/triggers.mjs +500 -0
- package/src/tui/format.mjs +177 -0
- package/src/tui/watch.mjs +118 -0
- package/src/update.mjs +281 -0
- package/src/worktree-git.mjs +145 -0
- package/src/worktree-liveness.mjs +87 -0
package/src/triggers.mjs
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/triggers.mjs — when a cleanup starts, and the state around it.
|
|
3
|
+
*
|
|
4
|
+
* Three triggers start a cleanup: low disk, a schedule, and the start of a
|
|
5
|
+
* Claude session. Each can be switched off in `~/.trash-panda/settings.json`.
|
|
6
|
+
* Whichever one fires, the start goes through `startRun`, so there is one lock,
|
|
7
|
+
* one set of exit codes and one child process that outlives its starter.
|
|
8
|
+
*
|
|
9
|
+
* Files in the folder (default `~/.trash-panda`, read at call time):
|
|
10
|
+
* settings.json the person's settings (src/settings.mjs)
|
|
11
|
+
* state.json internal: last full start, low-disk wait, critical flag, lines, last run
|
|
12
|
+
* lock/owner.json the run lock: { pid, startedAt }; held while that pid lives
|
|
13
|
+
* live.json public: what is happening now, replaced atomically
|
|
14
|
+
* history.jsonl public: one line per finished run (src/records.mjs)
|
|
15
|
+
* events.jsonl public: one line each time free space crosses a mark (src/records.mjs)
|
|
16
|
+
* errors.jsonl one line per failed command (src/records.mjs)
|
|
17
|
+
* in-charge.json written only by another tool; this package only reads it
|
|
18
|
+
* setup.json written only by setup and remove: the saved command
|
|
19
|
+
*
|
|
20
|
+
* Exit codes of a start: 0 started, 3 one is already running, 4 an automatic
|
|
21
|
+
* start waits for the tool in charge, 1 could not start.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { spawn } from "node:child_process";
|
|
25
|
+
import { randomBytes } from "node:crypto";
|
|
26
|
+
import { linkSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
27
|
+
import { join } from "node:path";
|
|
28
|
+
import { fileURLToPath } from "node:url";
|
|
29
|
+
import { CLASSES, CLEANUP_RULES, diskSpace, formatGb, formatSize, isLowSpace, runLeftoversCleanup, summaryLine } from "./claude-leftovers.mjs";
|
|
30
|
+
import { afterRun } from "./metrics.mjs";
|
|
31
|
+
import { isAlive as isProcessAlive } from "./rebuildables.mjs";
|
|
32
|
+
import { appendRecord, recordCrossings, runDetails, skippedRules } from "./records.mjs";
|
|
33
|
+
import { DEFAULTS, readSettings, settingsPath, trashPandaDir } from "./settings.mjs";
|
|
34
|
+
|
|
35
|
+
export { trashPandaDir };
|
|
36
|
+
|
|
37
|
+
/** The cleanup script a start runs, next to this package's other scripts. */
|
|
38
|
+
export const defaultScriptPath = fileURLToPath(new URL("../scripts/claude-leftovers-cleanup.mjs", import.meta.url));
|
|
39
|
+
/** The triggers that start a cleanup by themselves; a tool in charge holds these back. */
|
|
40
|
+
export const AUTOMATIC = ["lowDisk", "schedule", "sessionStart"];
|
|
41
|
+
/** Carries the session's name from the hook to the cleanup child. */
|
|
42
|
+
export const SESSION_ENV = "TRASH_PANDA_SESSION";
|
|
43
|
+
const BY_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
44
|
+
const STALE_WAIT_MS = 15_000;
|
|
45
|
+
|
|
46
|
+
const print = (line) => process.stdout.write(`${line}\n`);
|
|
47
|
+
const sleepMs = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
48
|
+
const statePath = (dir) => join(dir, "state.json");
|
|
49
|
+
const lockPath = (dir) => join(dir, "lock");
|
|
50
|
+
// One list (removed or kept) across every cleanup rule, in rule order.
|
|
51
|
+
const acrossRules = (result, list) => CLEANUP_RULES.flatMap(({ key }) => result[key][list]);
|
|
52
|
+
const isCritical = (disk, criticalMarkPct) => disk?.freePct != null && disk.freePct < criticalMarkPct;
|
|
53
|
+
const loadSettings = (dir) => readSettings(settingsPath(dir)).settings;
|
|
54
|
+
|
|
55
|
+
/** Write `path` whole or not at all: a temp file beside it, then a rename. */
|
|
56
|
+
function writeAtomic(path, text) {
|
|
57
|
+
const tmp = `${path}.tmp-${process.pid}`;
|
|
58
|
+
writeFileSync(tmp, text);
|
|
59
|
+
renameSync(tmp, path);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ── state ───────────────────────────────────────────────────────────────────
|
|
63
|
+
|
|
64
|
+
export function readState(dir = trashPandaDir()) {
|
|
65
|
+
try {
|
|
66
|
+
return JSON.parse(readFileSync(statePath(dir), "utf8"));
|
|
67
|
+
} catch {
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function writeState(dir, state) {
|
|
73
|
+
mkdirSync(dir, { recursive: true });
|
|
74
|
+
writeAtomic(statePath(dir), JSON.stringify(state, null, 2));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** True when no full run has started yet, or `everySec` seconds have passed since the last one started. */
|
|
78
|
+
export function isDue(state, now, everySec) {
|
|
79
|
+
const last = Date.parse(state.lastFullStartAt);
|
|
80
|
+
return !Number.isFinite(last) || now >= last + everySec * 1000;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Housekeeping on every tick and every finished run: space back over the low
|
|
85
|
+
* mark clears the low-disk wait, back over the critical mark re-arms the script.
|
|
86
|
+
*/
|
|
87
|
+
export function housekeeping(state, disk, { lowMarkPct, criticalMarkPct }) {
|
|
88
|
+
const next = { ...state };
|
|
89
|
+
if (disk?.freePct != null) {
|
|
90
|
+
if (disk.freePct >= lowMarkPct) next.lowDiskWaitPct = null;
|
|
91
|
+
if (disk.freePct >= criticalMarkPct) next.criticalFired = false;
|
|
92
|
+
}
|
|
93
|
+
return next;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The next state from a finished run: its summary line, the low-space line (on
|
|
98
|
+
* every run under the low mark, naming the largest folders, with one recovery
|
|
99
|
+
* line when it clears) and a plain line while space is critical.
|
|
100
|
+
*/
|
|
101
|
+
export function nextState(prev, result, startedAt, { disk = result.disk, lowMarkPct = DEFAULTS.lowMarkPct, criticalMarkPct = DEFAULTS.criticalMarkPct } = {}) {
|
|
102
|
+
const low = isLowSpace(disk, lowMarkPct);
|
|
103
|
+
const lowStreak = low ? (prev.lowStreak ?? 0) + 1 : 0;
|
|
104
|
+
const lines = [summaryLine(result)];
|
|
105
|
+
// Unreadable free space prints as "null GB".
|
|
106
|
+
const freeGb = disk?.freeBytes == null ? "null GB" : formatGb(disk.freeBytes);
|
|
107
|
+
if (low) {
|
|
108
|
+
const biggest = (result.largest ?? []).map((f) => `${f.path} ${formatGb(f.bytes)}`).join(", ");
|
|
109
|
+
lines.push(`Low disk: ${freeGb} free (${disk.freePct}%), under the ${lowMarkPct}% mark${lowStreak > 1 ? ` for ${lowStreak} cleanup runs in a row` : ""}${biggest ? `. Largest folders: ${biggest}` : ""}.`);
|
|
110
|
+
} else if ((prev.lowStreak ?? 0) >= 1) lines.push(`Disk recovered: ${freeGb} free.`);
|
|
111
|
+
if (isCritical(disk, criticalMarkPct)) lines.push(`Space is still critical: ${freeGb} free (${disk.freePct}%), under the ${criticalMarkPct}% mark.`);
|
|
112
|
+
return {
|
|
113
|
+
startedAt,
|
|
114
|
+
finishedAt: result.at,
|
|
115
|
+
lines,
|
|
116
|
+
duBytes: result.duBytes,
|
|
117
|
+
dfDeltaBytes: result.dfDeltaBytes,
|
|
118
|
+
freeBytesAfter: result.freeBytesAfter,
|
|
119
|
+
lowStreak,
|
|
120
|
+
removed: acrossRules(result, "removed").map(({ path, reason, bytes }) => ({ path, reason, bytes })),
|
|
121
|
+
kept: acrossRules(result, "kept"),
|
|
122
|
+
skipped: skippedRules(result),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ── the run lock ────────────────────────────────────────────────────────────
|
|
127
|
+
|
|
128
|
+
/** `{ pid, startedAt }` read from `file` when that process is alive, else null. */
|
|
129
|
+
function liveOwner(file, alive) {
|
|
130
|
+
try {
|
|
131
|
+
const owner = JSON.parse(readFileSync(file, "utf8"));
|
|
132
|
+
return Number.isInteger(owner.pid) && owner.pid > 0 && alive(owner.pid) ? owner : null;
|
|
133
|
+
} catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The live owner `{ pid, startedAt }` of the run lock, or null when nobody alive holds it. */
|
|
139
|
+
export function lockHolder(dir, { alive = isProcessAlive } = {}) {
|
|
140
|
+
return liveOwner(join(lockPath(dir), "owner.json"), alive);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Move a dead owner's lock aside, one taker at a time: each must first link its
|
|
145
|
+
* claim inside the lock folder, then see again that no live process holds it.
|
|
146
|
+
* False when this taker must give way.
|
|
147
|
+
*/
|
|
148
|
+
function removeStaleLock(dir, mine, aside, alive) {
|
|
149
|
+
const claim = join(lockPath(dir), "reclaim");
|
|
150
|
+
try {
|
|
151
|
+
linkSync(mine, claim);
|
|
152
|
+
} catch {
|
|
153
|
+
// another taker is removing it; the claim of one that died is cleared for the next try
|
|
154
|
+
if (!liveOwner(claim, alive)) rmSync(claim, { force: true });
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
if (lockHolder(dir, { alive })) {
|
|
158
|
+
// someone took the lock since it was read as dead
|
|
159
|
+
rmSync(claim, { force: true });
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
renameSync(lockPath(dir), aside);
|
|
163
|
+
rmSync(aside, { recursive: true, force: true });
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Take the run lock, or return false when a live process holds it. The owner
|
|
169
|
+
* file is built in a folder of its own and renamed into place, so the lock
|
|
170
|
+
* never exists half written. A dead pid, or an owner file that cannot be read,
|
|
171
|
+
* is moved aside and the take retried once. No age ever makes a live lock stale.
|
|
172
|
+
*/
|
|
173
|
+
export function acquireRunLock(dir, { pid = process.pid, startedAt = new Date().toISOString(), alive = isProcessAlive } = {}) {
|
|
174
|
+
const lock = lockPath(dir);
|
|
175
|
+
const rand = randomBytes(4).toString("hex");
|
|
176
|
+
const tmp = join(dir, `lock.tmp-${pid}-${rand}`);
|
|
177
|
+
try {
|
|
178
|
+
mkdirSync(dir, { recursive: true });
|
|
179
|
+
mkdirSync(tmp);
|
|
180
|
+
writeFileSync(join(tmp, "owner.json"), JSON.stringify({ pid, startedAt }));
|
|
181
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
182
|
+
try {
|
|
183
|
+
renameSync(tmp, lock);
|
|
184
|
+
return true;
|
|
185
|
+
} catch {
|
|
186
|
+
// the lock folder exists: see who holds it
|
|
187
|
+
}
|
|
188
|
+
if (attempt === 1 || lockHolder(dir, { alive })) return false;
|
|
189
|
+
if (!removeStaleLock(dir, join(tmp, "owner.json"), `${lock}.stale-${pid}-${rand}`, alive)) return false;
|
|
190
|
+
}
|
|
191
|
+
} catch {
|
|
192
|
+
// the folder cannot be written, or the stale lock could not be moved aside: no lock taken
|
|
193
|
+
return false;
|
|
194
|
+
} finally {
|
|
195
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function releaseRunLock(dir = trashPandaDir()) {
|
|
200
|
+
rmSync(lockPath(dir), { recursive: true, force: true });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ── the tool in charge ──────────────────────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
/** `{ tool, pid, at, ttlSec }` from in-charge.json, or null when absent or not exactly that shape. */
|
|
206
|
+
export function readInCharge(dir, { readImpl = readFileSync } = {}) {
|
|
207
|
+
try {
|
|
208
|
+
const s = JSON.parse(readImpl(join(dir, "in-charge.json"), "utf8"));
|
|
209
|
+
const ok = s?.format === 1 && typeof s.tool === "string" && s.tool !== "" && Number.isInteger(s.pid) && s.pid > 0 && typeof s.at === "string" && Number.isFinite(Date.parse(s.at)) && Number.isInteger(s.ttlSec) && s.ttlSec >= 10 && s.ttlSec <= 3600;
|
|
210
|
+
return ok ? { tool: s.tool, pid: s.pid, at: s.at, ttlSec: s.ttlSec } : null;
|
|
211
|
+
} catch {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** True when the signal's process is alive and it was written within its ttl. */
|
|
217
|
+
export function inChargeFresh(sig, { now, alive = isProcessAlive }) {
|
|
218
|
+
return Boolean(sig) && alive(sig.pid) && now - Date.parse(sig.at) <= sig.ttlSec * 1000;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The tool in charge, or null. A signal whose process is dead is none. A stale
|
|
223
|
+
* signal with a live process may only mean the machine slept: wait 15 s, read
|
|
224
|
+
* it again, and only a refreshed one counts.
|
|
225
|
+
*/
|
|
226
|
+
export async function whoIsInCharge({ dir = trashPandaDir(), now = Date.now, alive = isProcessAlive, sleep = sleepMs, readImpl } = {}) {
|
|
227
|
+
const sig = readInCharge(dir, { readImpl });
|
|
228
|
+
if (!sig || !alive(sig.pid)) return null;
|
|
229
|
+
if (inChargeFresh(sig, { now: now(), alive })) return sig.tool;
|
|
230
|
+
await sleep(STALE_WAIT_MS);
|
|
231
|
+
const again = readInCharge(dir, { readImpl });
|
|
232
|
+
return inChargeFresh(again, { now: now(), alive }) ? again.tool : null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ── the decision ────────────────────────────────────────────────────────────
|
|
236
|
+
|
|
237
|
+
/** Which trigger starts a cleanup now: "lowDisk", "schedule" or null. Pure. */
|
|
238
|
+
export function decideStart({ settings, state, disk, inCharge, now }) {
|
|
239
|
+
if (inCharge) return null;
|
|
240
|
+
const { lowDisk, schedule } = settings.triggers;
|
|
241
|
+
if (lowDisk.on && isLowSpace(disk, settings.lowMarkPct) && (state.lowDiskWaitPct == null || disk.freePct < state.lowDiskWaitPct)) return "lowDisk";
|
|
242
|
+
if (schedule.on && isDue(state, now, schedule.everySec)) return "schedule";
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ── starting a run ──────────────────────────────────────────────────────────
|
|
247
|
+
|
|
248
|
+
/** The first line the child prints, or "" when it ends or fails without one. */
|
|
249
|
+
const firstLine = (child) =>
|
|
250
|
+
new Promise((resolve) => {
|
|
251
|
+
let buf = "";
|
|
252
|
+
child.stdout.on("data", (d) => {
|
|
253
|
+
buf += d;
|
|
254
|
+
const i = buf.indexOf("\n");
|
|
255
|
+
if (i >= 0) resolve(buf.slice(0, i).trim());
|
|
256
|
+
});
|
|
257
|
+
child.on("error", () => resolve(""));
|
|
258
|
+
child.on("close", () => resolve(buf.trim()));
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const CHILD_SAYS = { started: 0, busy: 3, waits: 4 };
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* The one way every start happens. Spawns the cleanup as a child in its own
|
|
265
|
+
* process session and returns once it has said whether it began, so the child
|
|
266
|
+
* keeps going when this process ends. Exit codes: 0 started, 3 one is already
|
|
267
|
+
* running (nothing is kept for later), 4 an automatic start waits for the tool
|
|
268
|
+
* in charge, 1 could not start.
|
|
269
|
+
*/
|
|
270
|
+
export async function startRun({ dir = trashPandaDir(), by = "hand", only = null, limit = null, scriptPath = defaultScriptPath, spawnImpl = spawn, whoIsInChargeImpl = whoIsInCharge, alive = isProcessAlive } = {}) {
|
|
271
|
+
if ((only !== null && !Object.hasOwn(CLASSES, only)) || !BY_RE.test(by) || (limit !== null && !(Number.isInteger(limit) && limit > 0))) return 1;
|
|
272
|
+
if (AUTOMATIC.includes(by) && (await whoIsInChargeImpl({ dir }))) return 4;
|
|
273
|
+
if (lockHolder(dir, { alive })) return 3;
|
|
274
|
+
let child;
|
|
275
|
+
try {
|
|
276
|
+
child = spawnImpl(process.execPath, [scriptPath, "_cleanup", "--by", by, ...(only === null ? [] : ["--only", only]), ...(limit === null ? [] : ["--limit", String(limit)])], { detached: true, stdio: ["ignore", "pipe", "ignore"] });
|
|
277
|
+
} catch {
|
|
278
|
+
return 1;
|
|
279
|
+
}
|
|
280
|
+
const said = await firstLine(child);
|
|
281
|
+
child.unref();
|
|
282
|
+
child.stdout.destroy();
|
|
283
|
+
return CHILD_SAYS[said] ?? 1;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ── the critical script ─────────────────────────────────────────────────────
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Run the person's critical script in its own process group; after `timeoutSec`
|
|
290
|
+
* kill the whole group. Resolves `{ code, timedOut }` and never throws: a script
|
|
291
|
+
* that cannot start has code null.
|
|
292
|
+
*/
|
|
293
|
+
export function runCritical(cmd, { timeoutSec, freeGb, freePct, spawnImpl = spawn, killImpl = process.kill }) {
|
|
294
|
+
return new Promise((resolve) => {
|
|
295
|
+
let timedOut = false;
|
|
296
|
+
let timer;
|
|
297
|
+
const done = (code) => {
|
|
298
|
+
clearTimeout(timer);
|
|
299
|
+
resolve({ code, timedOut });
|
|
300
|
+
};
|
|
301
|
+
let child;
|
|
302
|
+
try {
|
|
303
|
+
child = spawnImpl(cmd[0], cmd.slice(1), { detached: true, stdio: "ignore", env: { ...process.env, TRASH_PANDA_FREE_GB: String(freeGb), TRASH_PANDA_FREE_PCT: String(freePct) } });
|
|
304
|
+
} catch {
|
|
305
|
+
resolve({ code: null, timedOut });
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
child.on("error", () => done(null));
|
|
309
|
+
child.on("close", (code) => done(code));
|
|
310
|
+
timer = setTimeout(() => {
|
|
311
|
+
timedOut = true;
|
|
312
|
+
try {
|
|
313
|
+
killImpl(-child.pid, "SIGKILL");
|
|
314
|
+
} catch {
|
|
315
|
+
// the group is already gone
|
|
316
|
+
}
|
|
317
|
+
}, timeoutSec * 1000);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ── live.json ───────────────────────────────────────────────────────────────
|
|
322
|
+
|
|
323
|
+
/** The saved command from setup.json, or null. Only setup and remove write that file. */
|
|
324
|
+
function readSavedCommand(dir) {
|
|
325
|
+
try {
|
|
326
|
+
const s = JSON.parse(readFileSync(join(dir, "setup.json"), "utf8"));
|
|
327
|
+
const ok = s?.format === 1 && Array.isArray(s.command) && s.command.length === 2 && s.command.every((c) => typeof c === "string" && c !== "");
|
|
328
|
+
return ok ? s.command : null;
|
|
329
|
+
} catch {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** The live.json content. Pure. */
|
|
335
|
+
export function buildLive({ now, settings, disk, state, holder, inCharge, command }) {
|
|
336
|
+
const { lowDisk, schedule, sessionStart: session } = settings.triggers;
|
|
337
|
+
const lastMs = Date.parse(state.lastFullStartAt);
|
|
338
|
+
const hasLast = Number.isFinite(lastMs);
|
|
339
|
+
const running = Boolean(holder && state.run);
|
|
340
|
+
return {
|
|
341
|
+
format: 1,
|
|
342
|
+
at: new Date(now).toISOString(),
|
|
343
|
+
preview: settings.preview,
|
|
344
|
+
state: running ? "running" : "idle",
|
|
345
|
+
disk: { freeBytes: disk.freeBytes, totalBytes: disk.totalBytes, freePct: disk.freePct },
|
|
346
|
+
marks: { lowPct: settings.lowMarkPct, criticalPct: settings.criticalMarkPct },
|
|
347
|
+
triggers: { lowDisk: lowDisk.on, schedule: schedule.on, sessionStart: session.on },
|
|
348
|
+
everySec: schedule.everySec,
|
|
349
|
+
run: running ? { by: state.run.by, only: state.run.only, startedAt: state.run.startedAt, item: state.run.item, freedBytes: state.run.freedBytes } : null,
|
|
350
|
+
last: state.last ?? null,
|
|
351
|
+
lastFullStartAt: hasLast ? state.lastFullStartAt : null,
|
|
352
|
+
nextRunAt: schedule.on ? new Date(hasLast ? lastMs + schedule.everySec * 1000 : now).toISOString() : null,
|
|
353
|
+
lowDiskWaitPct: state.lowDiskWaitPct ?? null,
|
|
354
|
+
inCharge,
|
|
355
|
+
command,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** Rebuild live.json from the folder and write it atomically; returns what it wrote. */
|
|
360
|
+
export function refreshLive({ dir = trashPandaDir(), now = Date.now, diskImpl = diskSpace, alive = isProcessAlive } = {}) {
|
|
361
|
+
mkdirSync(dir, { recursive: true });
|
|
362
|
+
const t = now();
|
|
363
|
+
const sig = readInCharge(dir);
|
|
364
|
+
const live = buildLive({
|
|
365
|
+
now: t,
|
|
366
|
+
settings: loadSettings(dir),
|
|
367
|
+
disk: diskImpl(),
|
|
368
|
+
state: readState(dir),
|
|
369
|
+
holder: lockHolder(dir, { alive }),
|
|
370
|
+
inCharge: inChargeFresh(sig, { now: t, alive }) ? sig.tool : null,
|
|
371
|
+
command: readSavedCommand(dir),
|
|
372
|
+
});
|
|
373
|
+
writeAtomic(join(dir, "live.json"), `${JSON.stringify(live, null, 2)}\n`);
|
|
374
|
+
return live;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** Add one finished run to history.jsonl. */
|
|
378
|
+
export function appendHistory(dir, line) {
|
|
379
|
+
appendRecord(dir, "history.jsonl", line);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// ── one cleanup (the child) ─────────────────────────────────────────────────
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* The cleanup child. Takes the lock, tells the starter through `report`
|
|
386
|
+
* ("busy", "waits" or "started") and then never reports again, runs the rules,
|
|
387
|
+
* writes state, history and live.json, runs the critical script once per fall
|
|
388
|
+
* and lets the lock go, then starts the opt-in metrics sender (src/metrics.mjs)
|
|
389
|
+
* without waiting for it. `now` is a clock function; `session` names the
|
|
390
|
+
* session behind a session-start run.
|
|
391
|
+
*/
|
|
392
|
+
export async function runOnce({ dir = trashPandaDir(), by = "hand", only = null, limit = null, session = null, report, runImpl = runLeftoversCleanup, now = Date.now, alive = isProcessAlive, diskImpl = diskSpace, criticalImpl = runCritical, spawnImpl = spawn } = {}) {
|
|
393
|
+
mkdirSync(dir, { recursive: true });
|
|
394
|
+
if (!acquireRunLock(dir, { alive })) {
|
|
395
|
+
report?.("busy");
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
let waits = false;
|
|
399
|
+
let done = null;
|
|
400
|
+
try {
|
|
401
|
+
waits = AUTOMATIC.includes(by) && inChargeFresh(readInCharge(dir), { now: now(), alive });
|
|
402
|
+
if (!waits) done = await runLocked({ dir, by, only, limit, session, report, runImpl, now, alive, diskImpl, criticalImpl });
|
|
403
|
+
} finally {
|
|
404
|
+
releaseRunLock(dir);
|
|
405
|
+
}
|
|
406
|
+
if (waits) {
|
|
407
|
+
report?.("waits");
|
|
408
|
+
refreshLive({ dir, now, alive, diskImpl });
|
|
409
|
+
} else afterRun({ dir, ...done, now, spawnImpl });
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// `limit` (test folders per run) goes to the rules only when it is set.
|
|
413
|
+
const withLimit = (opts, limit) => (limit === null || limit === undefined ? opts : { ...opts, limit });
|
|
414
|
+
|
|
415
|
+
async function runLocked({ dir, by, only, limit, session, report, runImpl, now, alive, diskImpl, criticalImpl }) {
|
|
416
|
+
const startedAt = new Date(now()).toISOString();
|
|
417
|
+
report?.("started");
|
|
418
|
+
const settings = loadSettings(dir);
|
|
419
|
+
const marks = { lowMarkPct: settings.lowMarkPct, criticalMarkPct: settings.criticalMarkPct };
|
|
420
|
+
let state = { ...readState(dir), run: { by, only, startedAt, item: null, freedBytes: 0 } };
|
|
421
|
+
// A run limited to one class never moves the schedule.
|
|
422
|
+
if (only === null) state.lastFullStartAt = startedAt;
|
|
423
|
+
writeState(dir, state);
|
|
424
|
+
const freePctBefore = refreshLive({ dir, now, alive, diskImpl }).disk.freePct;
|
|
425
|
+
|
|
426
|
+
const apply = !settings.preview;
|
|
427
|
+
const before = diskImpl();
|
|
428
|
+
recordCrossings(dir, { disk: before, settings, now: now() });
|
|
429
|
+
const result = await runImpl(withLimit({ apply, only, lowMarkPct: settings.lowMarkPct }, limit));
|
|
430
|
+
const disk = diskImpl();
|
|
431
|
+
recordCrossings(dir, { disk, settings, now: now() });
|
|
432
|
+
const critical = isCritical(disk, settings.criticalMarkPct);
|
|
433
|
+
if (critical && !state.criticalFired && settings.onCritical) {
|
|
434
|
+
await criticalImpl(settings.onCritical, { timeoutSec: settings.onCriticalTimeoutSec, freeGb: (disk.freeBytes / 1024 ** 3).toFixed(1), freePct: disk.freePct });
|
|
435
|
+
}
|
|
436
|
+
// Temp entries are counted, never listed.
|
|
437
|
+
const removed = acrossRules(result, "removed").length + (result.temp.removedCount ?? 0);
|
|
438
|
+
const last = { by, only, startedAt, finishedAt: new Date(now()).toISOString(), preview: settings.preview, removed, freedBytes: apply ? result.duBytes : 0, critical };
|
|
439
|
+
// The session's name stays in this file: live.json and state.json, which other tools read, never hold it.
|
|
440
|
+
appendHistory(dir, { ...last, ...(by === "sessionStart" ? { session } : {}), ...runDetails(result, { before, after: disk, deleted: apply }) });
|
|
441
|
+
state = {
|
|
442
|
+
...state,
|
|
443
|
+
...nextState(state, result, startedAt, { disk, ...marks }),
|
|
444
|
+
lowDiskWaitPct: isLowSpace(disk, marks.lowMarkPct) ? Math.round((disk.freePct - 1) * 10) / 10 : null,
|
|
445
|
+
criticalFired: critical,
|
|
446
|
+
last,
|
|
447
|
+
run: null,
|
|
448
|
+
};
|
|
449
|
+
writeState(dir, state);
|
|
450
|
+
refreshLive({ dir, now, alive, diskImpl });
|
|
451
|
+
return { last, result, freePctBefore, freePctAfter: disk.freePct };
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/** The report-only run: what the cleanup would remove and what it keeps, each with why, printed. */
|
|
455
|
+
export async function reportOnly({ runImpl = runLeftoversCleanup, log = print, only = null, limit = null } = {}) {
|
|
456
|
+
const result = await runImpl(withLimit(only === null ? { apply: false } : { apply: false, only }, limit));
|
|
457
|
+
log(summaryLine(result));
|
|
458
|
+
for (const k of acrossRules(result, "kept")) log(` keep ${k.path}: ${k.reason}`);
|
|
459
|
+
for (const r of acrossRules(result, "removed")) log(` would remove ${r.path} (${formatSize(r.bytes)}): ${r.reason}`);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// ── the tick and the session-start hook ─────────────────────────────────────
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* One look, from the scheduled job: housekeeping, a fresh live.json, and at
|
|
466
|
+
* most one cleanup started when a trigger says so. `now` is a clock function;
|
|
467
|
+
* `startOptions` go to the start (tests give the script path there).
|
|
468
|
+
*/
|
|
469
|
+
export async function tick({ dir = trashPandaDir(), now = Date.now, diskImpl = diskSpace, alive = isProcessAlive, startImpl = startRun, startOptions } = {}) {
|
|
470
|
+
mkdirSync(dir, { recursive: true });
|
|
471
|
+
const t = now();
|
|
472
|
+
const settings = loadSettings(dir);
|
|
473
|
+
const disk = diskImpl();
|
|
474
|
+
const state = housekeeping(readState(dir), disk, settings);
|
|
475
|
+
writeState(dir, state);
|
|
476
|
+
recordCrossings(dir, { disk, settings, now: t });
|
|
477
|
+
const sig = readInCharge(dir);
|
|
478
|
+
const inCharge = inChargeFresh(sig, { now: t, alive });
|
|
479
|
+
refreshLive({ dir, now, diskImpl, alive });
|
|
480
|
+
const by = decideStart({ settings, state, disk, inCharge, now: t });
|
|
481
|
+
if (!by) return { by: null, code: null };
|
|
482
|
+
return { by, code: await startImpl({ dir, by, ...startOptions }) };
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* The SessionStart hook: print the last lines, start a detached run when that
|
|
487
|
+
* trigger is on, never fail. The session's name goes in the environment, never
|
|
488
|
+
* in the arguments: a rule that keeps what a process names reads arguments.
|
|
489
|
+
*/
|
|
490
|
+
export function sessionStart({ dir = trashPandaDir(), session = null, spawnImpl = spawn, log = print, scriptPath = defaultScriptPath } = {}) {
|
|
491
|
+
try {
|
|
492
|
+
for (const line of readState(dir).lines ?? []) log(line);
|
|
493
|
+
if (loadSettings(dir).triggers.sessionStart.on) {
|
|
494
|
+
const env = session === null ? {} : { env: { ...process.env, [SESSION_ENV]: session } };
|
|
495
|
+
spawnImpl(process.execPath, [scriptPath, "run", "--by", "sessionStart"], { detached: true, stdio: "ignore", ...env }).unref();
|
|
496
|
+
}
|
|
497
|
+
} catch {
|
|
498
|
+
// a cleanup never blocks a session
|
|
499
|
+
}
|
|
500
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/tui/format.mjs — what the watch screen shows, as plain data.
|
|
3
|
+
*
|
|
4
|
+
* `buildFrame` turns a view (what src/tui/watch.mjs read from live.json,
|
|
5
|
+
* history.jsonl, the settings file and in-charge.json) into rows of pieces,
|
|
6
|
+
* each piece a text, a colour and a weight. It reads no file, clock or
|
|
7
|
+
* terminal. Four colours only: red for a problem, yellow for work, green for
|
|
8
|
+
* good and grey for the rest.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { formatGb } from "../claude-leftovers.mjs";
|
|
12
|
+
import { DEFAULTS } from "../settings.mjs";
|
|
13
|
+
|
|
14
|
+
export const COLOUR = Object.freeze({ problem: "red", work: "yellow", good: "green", rest: "gray" });
|
|
15
|
+
export const BAR_WIDTH = 24;
|
|
16
|
+
const TICK = "┃";
|
|
17
|
+
const NARROW = 40;
|
|
18
|
+
const LABEL = 9;
|
|
19
|
+
const TRIGGERS = [
|
|
20
|
+
["lowDisk", "low disk"],
|
|
21
|
+
["schedule", "schedule"],
|
|
22
|
+
["sessionStart", "session start"],
|
|
23
|
+
];
|
|
24
|
+
// Who started a run, in words; "hand" and a tool's own name read as they are.
|
|
25
|
+
const BY = Object.fromEntries(TRIGGERS);
|
|
26
|
+
|
|
27
|
+
const piece = (text, colour = null, bold = false) => ({ text, colour, bold });
|
|
28
|
+
const clock = (iso) => new Date(iso).toTimeString().slice(0, 5);
|
|
29
|
+
|
|
30
|
+
/** The disk bar: free space filled, a tick at each mark. Two marks that round to one cell stay two ticks. */
|
|
31
|
+
export function bar(freePct, { lowPct, criticalPct }, width = BAR_WIDTH) {
|
|
32
|
+
const cell = (pct) => Math.min(width - 1, Math.round((pct / 100) * width));
|
|
33
|
+
const critical = cell(criticalPct);
|
|
34
|
+
const low = Math.min(width - 1, Math.max(cell(lowPct), critical + 1));
|
|
35
|
+
const filled = freePct === null ? 0 : Math.round((freePct / 100) * width);
|
|
36
|
+
let out = "";
|
|
37
|
+
for (let i = 0; i < width; i++) out += i === low || i === critical ? TICK : i < filled ? "█" : "░";
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The status word and its colour, which the status box border takes too. */
|
|
42
|
+
function status({ live, old, inCharge }, running, critical) {
|
|
43
|
+
if (!live) return { text: "no data", tone: COLOUR.rest };
|
|
44
|
+
if (old) return { text: `old data, last written ${clock(live.at)}`, tone: COLOUR.problem };
|
|
45
|
+
if (running) return { text: "cleaning", tone: COLOUR.work };
|
|
46
|
+
if (critical) return { text: "space critical", tone: COLOUR.problem };
|
|
47
|
+
if (inCharge) return { text: "waiting for the tool in charge", tone: COLOUR.rest };
|
|
48
|
+
return { text: "idle", tone: COLOUR.good };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** One finished run: a row with its time, one coloured icon and short text, then an indented grey detail row. */
|
|
52
|
+
function historyRows(run) {
|
|
53
|
+
const [icon, colour] = run.critical ? ["✗", COLOUR.problem] : run.preview ? ["○", COLOUR.work] : ["✓", COLOUR.good];
|
|
54
|
+
const what = run.preview ? `preview, would remove ${run.removed ?? 0}` : `freed ${formatGb(run.freedBytes ?? 0)}, removed ${run.removed ?? 0}`;
|
|
55
|
+
const detail = [`by ${BY[run.by] ?? run.by}`, run.only && `only ${run.only}`, run.critical && "space still critical"].filter(Boolean).join(", ");
|
|
56
|
+
return [
|
|
57
|
+
[piece(clock(run.finishedAt), COLOUR.rest), piece(" "), piece(icon, colour, true), piece(` ${what}`)],
|
|
58
|
+
[piece(` ↳ ${detail}`, COLOUR.rest)],
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The frame for `view` in a terminal of `width` by `height`, with the history
|
|
64
|
+
* scrolled down by `scroll` runs (newest first). A short terminal drops every
|
|
65
|
+
* row but the status, the bar and the marks; the warning always stays.
|
|
66
|
+
* `keys` adds the key hint line of a live terminal.
|
|
67
|
+
*/
|
|
68
|
+
export function buildFrame(view, { width = 80, height = 24, scroll = 0, keys = false } = {}) {
|
|
69
|
+
const { live, old, settings, inCharge, history } = view;
|
|
70
|
+
const marks = { lowPct: settings.lowMarkPct, criticalPct: settings.criticalMarkPct };
|
|
71
|
+
const freePct = live ? live.disk.freePct : null;
|
|
72
|
+
const running = Boolean(live && !old && live.state === "running" && live.run);
|
|
73
|
+
const critical = freePct !== null && freePct < marks.criticalPct;
|
|
74
|
+
const narrow = width < NARROW;
|
|
75
|
+
// Labels line up in a column, except in a narrow terminal, where each takes only its own width.
|
|
76
|
+
const label = (text) => piece(narrow ? `${text} ` : text.padEnd(LABEL), COLOUR.rest);
|
|
77
|
+
const st = status(view, running, critical);
|
|
78
|
+
const diskTone = freePct === null ? COLOUR.rest : critical ? COLOUR.problem : freePct < marks.lowPct ? COLOUR.work : COLOUR.good;
|
|
79
|
+
const last = history.at(-1);
|
|
80
|
+
const total = history.reduce((sum, run) => sum + (run.freedBytes ?? 0), 0);
|
|
81
|
+
|
|
82
|
+
const title = [piece("trash-panda", null, true), piece(" · ", COLOUR.rest), piece(st.text, st.tone, true)];
|
|
83
|
+
if (settings.preview) title.push(piece(narrow ? " PREVIEW" : " PREVIEW: nothing is deleted", COLOUR.work, true));
|
|
84
|
+
const disk = [label("disk"), piece(bar(freePct, marks, narrow ? 10 : BAR_WIDTH), diskTone), piece(" ")];
|
|
85
|
+
if (freePct === null) disk.push(piece("no data", COLOUR.rest));
|
|
86
|
+
else disk.push(piece(narrow ? `${freePct}%` : `${freePct}% free`, diskTone, true));
|
|
87
|
+
if (freePct !== null && !narrow) disk.push(piece(` ${formatGb(live.disk.freeBytes)} of ${formatGb(live.disk.totalBytes)}`, COLOUR.rest));
|
|
88
|
+
const rows = [
|
|
89
|
+
{ keep: true, row: title },
|
|
90
|
+
{ keep: true, row: disk },
|
|
91
|
+
{ keep: true, row: [label("marks"), piece(`low ${marks.lowPct}%`, COLOUR.work), piece(narrow ? " " : " "), piece(`critical ${marks.criticalPct}%`, COLOUR.problem)] },
|
|
92
|
+
];
|
|
93
|
+
if (running) rows.push({ row: [label("now"), piece(`cleaning ${live.run.item ?? "..."}`, COLOUR.work), piece(`, ${formatGb(live.run.freedBytes ?? 0)} freed this run`, COLOUR.rest)] });
|
|
94
|
+
rows.push(
|
|
95
|
+
{ row: last ? [label("freed"), piece(formatGb(last.freedBytes ?? 0)), piece(" last run, ", COLOUR.rest), piece(formatGb(total)), piece(" in total", COLOUR.rest)] : [label("freed"), piece("no runs yet")] },
|
|
96
|
+
{ row: [label("next run"), piece(!live ? "no data" : settings.triggers.schedule.on && live.nextRunAt ? clock(live.nextRunAt) : "schedule off")] },
|
|
97
|
+
{ row: [label("starts"), inCharge ? piece(`${inCharge}, the tool in charge`, COLOUR.work) : piece("its own triggers")] },
|
|
98
|
+
{
|
|
99
|
+
row: [
|
|
100
|
+
label("triggers"),
|
|
101
|
+
...TRIGGERS.flatMap(([key, name], i) => {
|
|
102
|
+
const on = settings.triggers[key].on;
|
|
103
|
+
return [piece(`${i ? " " : ""}${name} `), piece(on ? "on" : "off", on ? COLOUR.good : COLOUR.rest, true)];
|
|
104
|
+
}),
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const stillCritical = Boolean(live?.last?.critical) && critical;
|
|
110
|
+
const warning = stillCritical ? [piece(narrow ? `Space still critical: ${freePct}%` : `Space is still critical after the last cleanup: ${formatGb(live.disk.freeBytes)} free (${freePct}%), under the ${marks.criticalPct}% mark.`, COLOUR.problem, true)] : null;
|
|
111
|
+
const hint = keys ? [piece("↑ ↓ scroll the history q quit", COLOUR.rest)] : null;
|
|
112
|
+
|
|
113
|
+
// Rows outside the box: its two border lines, the warning and the hint.
|
|
114
|
+
const fixed = 2 + (warning ? 1 : 0) + (hint ? 1 : 0);
|
|
115
|
+
const box = rows.length + fixed <= height ? rows : rows.filter((r) => r.keep);
|
|
116
|
+
const newestFirst = history.slice().reverse();
|
|
117
|
+
const fits = Math.max(0, Math.floor((height - fixed - box.length - 1) / 2));
|
|
118
|
+
const maxScroll = Math.max(0, newestFirst.length - fits);
|
|
119
|
+
const top = Math.min(Math.max(0, scroll), maxScroll);
|
|
120
|
+
const shown = newestFirst.slice(top, top + fits);
|
|
121
|
+
const head = [label("history"), piece(shown.length ? ` ${top + 1}-${top + shown.length} of ${newestFirst.length}` : " none yet", COLOUR.rest)];
|
|
122
|
+
return {
|
|
123
|
+
tone: st.tone,
|
|
124
|
+
box: box.map((r) => r.row),
|
|
125
|
+
warning,
|
|
126
|
+
history: fits ? [head, ...shown.flatMap(historyRows)] : [],
|
|
127
|
+
hint,
|
|
128
|
+
scroll: top,
|
|
129
|
+
maxScroll,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ── demo data: made-up, for `trash-panda watch --demo <state>` ───────────────
|
|
134
|
+
|
|
135
|
+
const GB = 1024 ** 3;
|
|
136
|
+
const MIN = 60_000;
|
|
137
|
+
const iso = (t) => new Date(t).toISOString();
|
|
138
|
+
|
|
139
|
+
function demoHistory(now, over = {}) {
|
|
140
|
+
return [5, 4, 3, 2, 1].map((h, i) => ({ by: ["schedule", "sessionStart", "hand", "lowDisk", "schedule"][i], only: i === 2 ? "chrome" : null, startedAt: iso(now - h * 60 * MIN - 2 * MIN), finishedAt: iso(now - h * 60 * MIN), preview: false, removed: 3 + i * 4, freedBytes: (0.6 + i * 1.3) * GB, critical: false, ...over }));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function demo(now, { live = {}, settings = {}, history = demoHistory(now), inCharge = null } = {}) {
|
|
144
|
+
const s = { ...structuredClone(DEFAULTS), preview: false, ...settings };
|
|
145
|
+
return {
|
|
146
|
+
live: {
|
|
147
|
+
format: 1,
|
|
148
|
+
at: iso(now),
|
|
149
|
+
state: "idle",
|
|
150
|
+
disk: { freeBytes: 182 * GB, totalBytes: 494 * GB, freePct: 36.8 },
|
|
151
|
+
run: null,
|
|
152
|
+
last: history.at(-1) ?? null,
|
|
153
|
+
nextRunAt: iso(now + 41 * MIN),
|
|
154
|
+
inCharge,
|
|
155
|
+
...live,
|
|
156
|
+
},
|
|
157
|
+
old: false,
|
|
158
|
+
settings: s,
|
|
159
|
+
inCharge,
|
|
160
|
+
history,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The demo states, each a function of the time now that gives a view. */
|
|
165
|
+
export const DEMOS = Object.freeze({
|
|
166
|
+
idle: (now) => demo(now),
|
|
167
|
+
running: (now) => demo(now, { live: { state: "running", disk: { freeBytes: 104 * GB, totalBytes: 494 * GB, freePct: 21.1 }, run: { by: "schedule", only: null, startedAt: iso(now - MIN), item: "~/.claude/worktrees/fix-login-form", freedBytes: 2.4 * GB } } }),
|
|
168
|
+
critical: (now) => {
|
|
169
|
+
const history = [...demoHistory(now).slice(0, 4), { by: "lowDisk", only: null, startedAt: iso(now - 7 * MIN), finishedAt: iso(now - 4 * MIN), preview: false, removed: 2, freedBytes: 0.3 * GB, critical: true }];
|
|
170
|
+
return demo(now, { history, live: { disk: { freeBytes: 30 * GB, totalBytes: 494 * GB, freePct: 6.1 } } });
|
|
171
|
+
},
|
|
172
|
+
"in-charge": (now) => demo(now, { inCharge: "disk-agent" }),
|
|
173
|
+
preview: (now) => demo(now, { settings: { preview: true }, history: demoHistory(now, { preview: true, freedBytes: 0 }) }),
|
|
174
|
+
empty: () => ({ live: null, old: false, settings: structuredClone(DEFAULTS), inCharge: null, history: [] }),
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export const demoView = (name, now) => DEMOS[name](now);
|