@firefunc-agent/runner 0.9.37 → 0.9.40
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/README.md +21 -0
- package/dist/activity.d.ts +2 -0
- package/dist/activity.js +3 -0
- package/dist/alive.d.ts +8 -0
- package/dist/alive.js +29 -0
- package/dist/api.d.ts +32 -0
- package/dist/api.js +18 -2
- package/dist/ask-replace.d.ts +6 -0
- package/dist/ask-replace.js +49 -0
- package/dist/awake-timer.d.ts +8 -0
- package/dist/awake-timer.js +30 -0
- package/dist/brief.js +2 -2
- package/dist/build-info.json +2 -2
- package/dist/clean-up.d.ts +29 -0
- package/dist/clean-up.js +131 -0
- package/dist/cli.js +57 -6
- package/dist/config.d.ts +7 -0
- package/dist/cut.d.ts +2 -0
- package/dist/cut.js +20 -3
- package/dist/daemon.js +115 -5
- package/dist/disk-reclaim.d.ts +40 -0
- package/dist/disk-reclaim.js +95 -0
- package/dist/drives.d.ts +29 -0
- package/dist/drives.js +270 -0
- package/dist/engine-account.d.ts +1 -1
- package/dist/engine-account.js +12 -1
- package/dist/engines/types.d.ts +1 -1
- package/dist/exec.js +5 -6
- package/dist/firefunc/automations.js +3 -3
- package/dist/firefunc/main.js +1 -1
- package/dist/firefunc/oauth-login.js +1 -1
- package/dist/gh-repos.d.ts +41 -0
- package/dist/gh-repos.js +68 -0
- package/dist/git-auth.d.ts +1 -0
- package/dist/git-auth.js +1 -1
- package/dist/held.d.ts +4 -2
- package/dist/held.js +19 -5
- package/dist/job.d.ts +1 -0
- package/dist/job.js +148 -33
- package/dist/keep-local.d.ts +1 -0
- package/dist/keep-local.js +63 -0
- package/dist/local-tools.d.ts +31 -0
- package/dist/local-tools.js +178 -0
- package/dist/machine-logins.d.ts +4 -0
- package/dist/machine-logins.js +31 -0
- package/dist/mcp-login.d.ts +3 -0
- package/dist/mcp-login.js +34 -4
- package/dist/mcp-tools.d.ts +23 -0
- package/dist/mcp-tools.js +122 -0
- package/dist/mcp.d.ts +8 -0
- package/dist/mcp.js +37 -3
- package/dist/pool.d.ts +1 -0
- package/dist/pool.js +1 -0
- package/dist/pr-title.d.ts +1 -0
- package/dist/pr-title.js +7 -0
- package/dist/repo-path.d.ts +15 -0
- package/dist/repo-path.js +56 -0
- package/dist/resources.d.ts +38 -0
- package/dist/resources.js +47 -1
- package/dist/restart-idle.d.ts +1 -0
- package/dist/restart-idle.js +20 -5
- package/dist/run-folders.d.ts +25 -0
- package/dist/run-folders.js +89 -0
- package/dist/viewer.d.ts +1 -1
- package/dist/viewer.js +3 -1
- package/dist/work-dir.d.ts +30 -0
- package/dist/work-dir.js +153 -22
- package/dist/worktrees.d.ts +7 -0
- package/dist/worktrees.js +26 -5
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -80,6 +80,13 @@ export type RunnerConfig = {
|
|
|
80
80
|
setupTimeoutMinutes?: number;
|
|
81
81
|
envFile?: string;
|
|
82
82
|
backgroundCommands?: string[];
|
|
83
|
+
localTools?: Record<string, LocalTool>;
|
|
84
|
+
};
|
|
85
|
+
export type LocalTool = {
|
|
86
|
+
command: string;
|
|
87
|
+
args?: string[];
|
|
88
|
+
env?: Record<string, string>;
|
|
89
|
+
addedAt?: string;
|
|
83
90
|
};
|
|
84
91
|
export declare function configPath(): string;
|
|
85
92
|
export declare function loadConfig(): RunnerConfig | null;
|
package/dist/cut.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export type CutSession = {
|
|
|
21
21
|
usage?: RunUsage;
|
|
22
22
|
writtenSkills?: WrittenSkills;
|
|
23
23
|
reason?: 'plan_limit' | 'timeout' | 'network' | 'auth' | 'lost' | 'push';
|
|
24
|
+
sessions?: Record<string, string>;
|
|
25
|
+
handedFrom?: CutSession;
|
|
24
26
|
};
|
|
25
27
|
export declare function cutDir(runnerDir: string): string;
|
|
26
28
|
export declare function promptHash(prompt: string): string;
|
package/dist/cut.js
CHANGED
|
@@ -78,14 +78,31 @@ export function cutFor(runnerDir, key, now = Date.now()) {
|
|
|
78
78
|
const cut = listCuts(runnerDir).find((c) => c.workItemId === key.workItemId);
|
|
79
79
|
if (!cut)
|
|
80
80
|
return null;
|
|
81
|
-
const
|
|
82
|
-
(cut.repo ?? null) === (key.repo ?? null) &&
|
|
81
|
+
const sameWork = (cut.repo ?? null) === (key.repo ?? null) &&
|
|
83
82
|
cut.branch === key.branch &&
|
|
84
83
|
cut.review === key.review &&
|
|
85
84
|
cut.toolsOnly === key.toolsOnly;
|
|
86
|
-
if (!
|
|
85
|
+
if (!sameWork || Date.parse(cut.keepUntil) <= now || !existsSync(cut.worktree)) {
|
|
87
86
|
return { discard: cut };
|
|
88
87
|
}
|
|
88
|
+
if (cut.engine !== key.engine) {
|
|
89
|
+
const { handedFrom: _was, ...plain } = cut;
|
|
90
|
+
const others = { ...(plain.sessions ?? {}) };
|
|
91
|
+
const own = others[key.engine] ?? '';
|
|
92
|
+
delete others[key.engine];
|
|
93
|
+
if (plain.sessionId)
|
|
94
|
+
others[plain.engine] = plain.sessionId;
|
|
95
|
+
return {
|
|
96
|
+
resume: {
|
|
97
|
+
...plain,
|
|
98
|
+
engine: key.engine,
|
|
99
|
+
sessionId: own,
|
|
100
|
+
resetsAt: null,
|
|
101
|
+
sessions: others,
|
|
102
|
+
handedFrom: plain,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
89
106
|
const reset = cut.resetsAt ? Date.parse(cut.resetsAt) : Number.NaN;
|
|
90
107
|
if (Number.isFinite(reset) && reset > now)
|
|
91
108
|
return null;
|
package/dist/daemon.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { localToolNames } from './local-tools.js';
|
|
1
2
|
import { readEngineModels } from './engine-models.js';
|
|
2
3
|
import { windowsRestartLater } from './live-runner.js';
|
|
3
4
|
import { WINDOWS_TASK_NAME } from './service.js';
|
|
@@ -41,13 +42,18 @@ import { engineBlocks, unattendedContext } from './unattended.js';
|
|
|
41
42
|
import { claimPause, engineWatch } from './engine-watch.js';
|
|
42
43
|
import { engineLoginBlock } from './engine-login.js';
|
|
43
44
|
import { commandWatch, runPath } from './machine-commands.js';
|
|
45
|
+
import { ghRepoWatch } from './gh-repos.js';
|
|
44
46
|
import { forgetRun, stopRun } from './run-stops.js';
|
|
45
|
-
import { readResources, resourceWatch } from './resources.js';
|
|
46
|
-
import {
|
|
47
|
+
import { readResources, resourceWatch, shortOf } from './resources.js';
|
|
48
|
+
import { dirBytes } from './drives.js';
|
|
49
|
+
import { join } from 'node:path';
|
|
50
|
+
import { clearAlive, otherRunnerWarning, readAlive, viewerPortWords, writeAlive, } from './alive.js';
|
|
47
51
|
import { backoffAfterFailure, describeTransportError, isTransportFailure, rebuildGlobalDispatcher, TRANSPORT_REBUILD_AFTER, TransportWatchdog, } from './transport.js';
|
|
48
|
-
import { setWorkDir, workDirProblem, workRoots } from './work-dir.js';
|
|
52
|
+
import { loadWorkspaceRoot, saveWorkspaceRoot, setWorkDir, setWorkspaceRoot, workDirProblem, workRootProblem, workRoots, } from './work-dir.js';
|
|
53
|
+
import { cleanUpNow } from './clean-up.js';
|
|
49
54
|
import { removeRunTemp, staleRunTemps, tempRoot } from './run-temp.js';
|
|
50
55
|
import { shellSafe } from './win-shell.js';
|
|
56
|
+
import { noteReclaim, reclaimDisk, stillShortWords } from './disk-reclaim.js';
|
|
51
57
|
function log(msg) {
|
|
52
58
|
console.log(`[firefunc-runner] ${new Date().toISOString()} ${blankSecrets(msg)}`);
|
|
53
59
|
}
|
|
@@ -67,12 +73,23 @@ export async function startDaemon(cfg) {
|
|
|
67
73
|
const rdir = runnerDir();
|
|
68
74
|
const machine = cfg.name ?? hostname();
|
|
69
75
|
setWorkDir(cfg.workDir);
|
|
76
|
+
setWorkspaceRoot(loadWorkspaceRoot(rdir));
|
|
70
77
|
if (cfg.workDir) {
|
|
71
78
|
const problem = workDirProblem();
|
|
72
79
|
log(problem
|
|
73
80
|
? `WARNING: ${problem}`
|
|
74
81
|
: `runs work in ${cfg.workDir} (worktrees, setup's and the engine's temp folder)`);
|
|
75
82
|
}
|
|
83
|
+
else {
|
|
84
|
+
const problem = workRootProblem();
|
|
85
|
+
if (problem)
|
|
86
|
+
log(`WARNING: ${problem}`);
|
|
87
|
+
}
|
|
88
|
+
const before = readAlive(rdir);
|
|
89
|
+
const otherWarning = otherRunnerWarning(before, { os: platform() });
|
|
90
|
+
const otherRunner = otherWarning ? before : null;
|
|
91
|
+
for (const line of otherWarning ?? [])
|
|
92
|
+
log(line);
|
|
76
93
|
const alive = {
|
|
77
94
|
pid: process.pid,
|
|
78
95
|
user: (() => {
|
|
@@ -187,7 +204,7 @@ export async function startDaemon(cfg) {
|
|
|
187
204
|
: createSessionViewer({
|
|
188
205
|
port: cfg.viewerPort,
|
|
189
206
|
onListen: (u) => log(`live session viewer → ${u} (local only — watch Claude work in a browser)`),
|
|
190
|
-
onError: (m) => log(
|
|
207
|
+
onError: (m, port) => log(viewerPortWords(port, m, otherRunner, platform())),
|
|
191
208
|
});
|
|
192
209
|
const holding = new Set();
|
|
193
210
|
const pendingIds = () => {
|
|
@@ -234,8 +251,57 @@ export async function startDaemon(cfg) {
|
|
|
234
251
|
});
|
|
235
252
|
let serverMax = 1;
|
|
236
253
|
const commands = commandWatch({ path: () => runPath(cfg), log });
|
|
254
|
+
const ghRepos = ghRepoWatch({ log });
|
|
237
255
|
let localSignIn = signInFieldsOf(cfg);
|
|
238
256
|
let signInPrefs = null;
|
|
257
|
+
let lastCleanUpRequest = -Infinity;
|
|
258
|
+
let lastReclaimAt = -Infinity;
|
|
259
|
+
const diskNow = () => readResources(cfg, rdir).disk;
|
|
260
|
+
const reclaimNow = async () => {
|
|
261
|
+
const r = await reclaimDisk({
|
|
262
|
+
runnerDir: rdir,
|
|
263
|
+
short: () => {
|
|
264
|
+
const d = diskNow();
|
|
265
|
+
return !!d && d.floorBytes > 0 && d.freeBytes < d.floorBytes;
|
|
266
|
+
},
|
|
267
|
+
cleanUp: async () => (await cleanUpNow({
|
|
268
|
+
runnerDir: rdir,
|
|
269
|
+
checkouts: Object.values(cfg.repos ?? {}),
|
|
270
|
+
holding,
|
|
271
|
+
log,
|
|
272
|
+
}).catch(() => null))?.freedBytes ?? 0,
|
|
273
|
+
sizeOf: (p) => dirBytes(p),
|
|
274
|
+
log,
|
|
275
|
+
});
|
|
276
|
+
const own = await dirBytes(join(rdir, 'cargo-target')).catch(() => null);
|
|
277
|
+
noteReclaim({
|
|
278
|
+
at: new Date().toISOString(),
|
|
279
|
+
freedBytes: r.freedBytes,
|
|
280
|
+
stillShort: r.stillShort,
|
|
281
|
+
ownBytes: own,
|
|
282
|
+
});
|
|
283
|
+
if (r.stillShort) {
|
|
284
|
+
const d = diskNow();
|
|
285
|
+
if (d)
|
|
286
|
+
log(stillShortWords({
|
|
287
|
+
machine,
|
|
288
|
+
freeBytes: d.freeBytes,
|
|
289
|
+
floorBytes: d.floorBytes,
|
|
290
|
+
own: [{ label: 'build targets', bytes: own }],
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const runCleanUp = async (why) => {
|
|
295
|
+
const r = await cleanUpNow({
|
|
296
|
+
runnerDir: rdir,
|
|
297
|
+
checkouts: Object.values(cfg.repos ?? {}),
|
|
298
|
+
holding,
|
|
299
|
+
log,
|
|
300
|
+
}).catch(() => null);
|
|
301
|
+
if (r && r.freedBytes > 0) {
|
|
302
|
+
log(`clean-up (${why}) freed ${(r.freedBytes / 1024 ** 3).toFixed(2)} GB`);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
239
305
|
const refreshConfig = async () => {
|
|
240
306
|
const saved = loadConfig();
|
|
241
307
|
if (saved) {
|
|
@@ -264,12 +330,39 @@ export async function startDaemon(cfg) {
|
|
|
264
330
|
serverMax = Math.max(1, Math.floor(c.maxParallel));
|
|
265
331
|
if (c)
|
|
266
332
|
commands.update(c.requiredCommands);
|
|
333
|
+
if (c)
|
|
334
|
+
ghRepos.update(c.checkRepos);
|
|
267
335
|
if (c)
|
|
268
336
|
signInPrefs = c.signInPrefs;
|
|
269
337
|
Object.assign(cfg, applySignInPrefs(localSignIn, signInPrefs));
|
|
338
|
+
if (c && setWorkspaceRoot(c.workRoot)) {
|
|
339
|
+
saveWorkspaceRoot(rdir, c.workRoot);
|
|
340
|
+
const problem = cfg.workDir ? null : workRootProblem();
|
|
341
|
+
log(problem
|
|
342
|
+
? `WARNING: ${problem}`
|
|
343
|
+
: c.workRoot
|
|
344
|
+
? `the workspace's work folder is ${c.workRoot}${cfg.workDir ? ` (this machine's own ${cfg.workDir} wins)` : ''}`
|
|
345
|
+
: 'the workspace set no work folder');
|
|
346
|
+
}
|
|
347
|
+
if (c?.cleanUpRequestedAt && Date.parse(c.cleanUpRequestedAt) > lastCleanUpRequest) {
|
|
348
|
+
lastCleanUpRequest = Date.parse(c.cleanUpRequestedAt);
|
|
349
|
+
void runCleanUp('asked from FireFunc');
|
|
350
|
+
}
|
|
270
351
|
};
|
|
271
352
|
await refreshConfig().catch(() => { });
|
|
272
353
|
const cfgTimer = setInterval(() => void refreshConfig().catch(() => { }), 60_000);
|
|
354
|
+
const drainTimer = setInterval(() => {
|
|
355
|
+
const saved = loadConfig();
|
|
356
|
+
if (!saved)
|
|
357
|
+
return;
|
|
358
|
+
cfg.drain = saved.drain;
|
|
359
|
+
cfg.maxParallel = saved.maxParallel;
|
|
360
|
+
if (!isDraining(cfg) && alive.drainSeenAt) {
|
|
361
|
+
delete alive.drainSeenAt;
|
|
362
|
+
touchAlive();
|
|
363
|
+
}
|
|
364
|
+
}, 2_000);
|
|
365
|
+
drainTimer.unref?.();
|
|
273
366
|
const commandActivity = commandActivityWatch();
|
|
274
367
|
const activityTimer = setInterval(() => {
|
|
275
368
|
const mine = new Set(holding);
|
|
@@ -537,7 +630,10 @@ export async function startDaemon(cfg) {
|
|
|
537
630
|
gate.waive = (engine) => engine === 'claude_code' && fallbackKey(cfg, rdir) !== null;
|
|
538
631
|
const limitReports = () => gate.active().map((l) => ({ engine: l.engine, kind: 'plan', resetsAt: l.resetsAt }));
|
|
539
632
|
const enginesPaused = claimPause({ watch: declared, isLimited: (e) => gate.isLimited(e), log });
|
|
540
|
-
const room = resourceWatch({
|
|
633
|
+
const room = resourceWatch({
|
|
634
|
+
read: () => readResources(cfg, rdir, { localTools: () => localToolNames(loadConfig() ?? cfg) }),
|
|
635
|
+
log,
|
|
636
|
+
});
|
|
541
637
|
const paused = () => enginesPaused() || room.short();
|
|
542
638
|
const heavyWaitReport = (runIds) => {
|
|
543
639
|
const byTag = new Map(runIds.map((id) => [heavyTag(id), id]));
|
|
@@ -575,6 +671,7 @@ export async function startDaemon(cfg) {
|
|
|
575
671
|
maxParallel: effectiveMax(),
|
|
576
672
|
resources: room.report(),
|
|
577
673
|
commands: commands.report(),
|
|
674
|
+
...(ghRepos.report() ? { ghRepos: ghRepos.report() } : {}),
|
|
578
675
|
budget: budgets,
|
|
579
676
|
...(Object.keys(engineVersions).length > 0 ? { engineVersions } : {}),
|
|
580
677
|
...(Object.keys(engineModels).length > 0 ? { engineModels } : {}),
|
|
@@ -586,6 +683,7 @@ export async function startDaemon(cfg) {
|
|
|
586
683
|
accountLabel: l.accountLabel,
|
|
587
684
|
expiresAt: l.expiresAt,
|
|
588
685
|
...(l.detail ? { detail: l.detail } : {}),
|
|
686
|
+
...(l.tools ? { tools: l.tools, toolsListedAt: l.toolsListedAt } : {}),
|
|
589
687
|
})),
|
|
590
688
|
awaitingRuns: keptRunIds(rdir),
|
|
591
689
|
heavyWaits: heavyWaitReport([...holding, ...heldByLiveProcesses(rdir)]),
|
|
@@ -653,10 +751,15 @@ export async function startDaemon(cfg) {
|
|
|
653
751
|
}
|
|
654
752
|
await flushPendingTrails(rdir, (runId, batch) => api.trail(runId, batch)).catch(() => null);
|
|
655
753
|
declared.rescan();
|
|
754
|
+
if (shortOf(room.report()).includes('disk') && Date.now() - lastReclaimAt > 10 * 60_000) {
|
|
755
|
+
lastReclaimAt = Date.now();
|
|
756
|
+
await reclaimNow().catch(() => { });
|
|
757
|
+
}
|
|
656
758
|
if (Date.now() - lastCutSweep > 10 * 60_000) {
|
|
657
759
|
lastCutSweep = Date.now();
|
|
658
760
|
await dropExpiredCuts().catch(() => { });
|
|
659
761
|
sweepRunTemps();
|
|
762
|
+
await runCleanUp('every ten minutes');
|
|
660
763
|
for (const k of expiredKept(rdir)) {
|
|
661
764
|
await letGo(k, 'was not answered in time').catch(() => { });
|
|
662
765
|
}
|
|
@@ -688,6 +791,12 @@ export async function startDaemon(cfg) {
|
|
|
688
791
|
backoffMs = Math.min(backoffMs * 2, 60_000);
|
|
689
792
|
return 'retry';
|
|
690
793
|
},
|
|
794
|
+
onDrainSeen: () => {
|
|
795
|
+
if (alive.drainSeenAt)
|
|
796
|
+
return;
|
|
797
|
+
alive.drainSeenAt = new Date().toISOString();
|
|
798
|
+
touchAlive();
|
|
799
|
+
},
|
|
691
800
|
onStart: (job, inFlight) => {
|
|
692
801
|
holding.add(job.runId);
|
|
693
802
|
recordHeld(rdir, job.runId);
|
|
@@ -733,6 +842,7 @@ export async function startDaemon(cfg) {
|
|
|
733
842
|
await toolCalls.idle();
|
|
734
843
|
await commandSteps.idle();
|
|
735
844
|
clearInterval(cfgTimer);
|
|
845
|
+
clearInterval(drainTimer);
|
|
736
846
|
clearInterval(activityTimer);
|
|
737
847
|
clearInterval(budgetTimer);
|
|
738
848
|
clearInterval(aliveTimer);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const RECLAIM_IN_USE_MS: number;
|
|
2
|
+
export type Reclaimable = {
|
|
3
|
+
path: string;
|
|
4
|
+
label: string;
|
|
5
|
+
lastUsed: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const gbWords: (b: number) => string;
|
|
8
|
+
export declare function reclaimables(runnerDir: string, now?: number): Reclaimable[];
|
|
9
|
+
export type ReclaimDeps = {
|
|
10
|
+
runnerDir: string;
|
|
11
|
+
short: () => boolean;
|
|
12
|
+
cleanUp: () => Promise<number>;
|
|
13
|
+
sizeOf: (path: string) => Promise<number | null>;
|
|
14
|
+
remove?: (path: string) => void;
|
|
15
|
+
log: (line: string) => void;
|
|
16
|
+
now?: () => number;
|
|
17
|
+
};
|
|
18
|
+
export type ReclaimResult = {
|
|
19
|
+
freedBytes: number;
|
|
20
|
+
removed: string[];
|
|
21
|
+
stillShort: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type ReclaimReport = {
|
|
24
|
+
at: string;
|
|
25
|
+
freedBytes: number;
|
|
26
|
+
stillShort: boolean;
|
|
27
|
+
ownBytes: number | null;
|
|
28
|
+
};
|
|
29
|
+
export declare function lastReclaim(): ReclaimReport | null;
|
|
30
|
+
export declare function noteReclaim(r: ReclaimReport): void;
|
|
31
|
+
export declare function reclaimDisk(deps: ReclaimDeps): Promise<ReclaimResult>;
|
|
32
|
+
export declare function stillShortWords(input: {
|
|
33
|
+
machine: string;
|
|
34
|
+
freeBytes: number;
|
|
35
|
+
floorBytes: number;
|
|
36
|
+
own: ReadonlyArray<{
|
|
37
|
+
label: string;
|
|
38
|
+
bytes: number | null;
|
|
39
|
+
}>;
|
|
40
|
+
}): string;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
export const RECLAIM_IN_USE_MS = 15 * 60_000;
|
|
4
|
+
const GB = 1024 ** 3;
|
|
5
|
+
export const gbWords = (b) => `${(b / GB).toFixed(1)} GB`;
|
|
6
|
+
function lastUsedOf(dir) {
|
|
7
|
+
let newest = 0;
|
|
8
|
+
try {
|
|
9
|
+
newest = statSync(dir).mtimeMs;
|
|
10
|
+
for (const n of readdirSync(dir)) {
|
|
11
|
+
try {
|
|
12
|
+
newest = Math.max(newest, statSync(join(dir, n)).mtimeMs);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
return newest;
|
|
22
|
+
}
|
|
23
|
+
export function reclaimables(runnerDir, now = Date.now()) {
|
|
24
|
+
const root = join(runnerDir, 'cargo-target');
|
|
25
|
+
if (!existsSync(root))
|
|
26
|
+
return [];
|
|
27
|
+
const out = [];
|
|
28
|
+
let names = [];
|
|
29
|
+
try {
|
|
30
|
+
names = readdirSync(root);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
for (const n of names) {
|
|
36
|
+
const p = join(root, n);
|
|
37
|
+
try {
|
|
38
|
+
if (!statSync(p).isDirectory())
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const lastUsed = lastUsedOf(p);
|
|
45
|
+
if (now - lastUsed < RECLAIM_IN_USE_MS)
|
|
46
|
+
continue;
|
|
47
|
+
out.push({ path: p, label: `the shared Rust build target for ${n}`, lastUsed });
|
|
48
|
+
}
|
|
49
|
+
return out.sort((a, b) => a.lastUsed - b.lastUsed);
|
|
50
|
+
}
|
|
51
|
+
let lastReport = null;
|
|
52
|
+
export function lastReclaim() {
|
|
53
|
+
return lastReport;
|
|
54
|
+
}
|
|
55
|
+
export function noteReclaim(r) {
|
|
56
|
+
lastReport = r;
|
|
57
|
+
}
|
|
58
|
+
export async function reclaimDisk(deps) {
|
|
59
|
+
const remove = deps.remove ?? ((p) => rmSync(p, { recursive: true, force: true, maxRetries: 2 }));
|
|
60
|
+
let freed = 0;
|
|
61
|
+
const removed = [];
|
|
62
|
+
try {
|
|
63
|
+
const b = await deps.cleanUp();
|
|
64
|
+
if (b > 0) {
|
|
65
|
+
freed += b;
|
|
66
|
+
deps.log(`low on disk: the clean-up freed ${gbWords(b)} (finished run folders, leftover temp)`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
}
|
|
71
|
+
for (const r of reclaimables(deps.runnerDir, deps.now?.() ?? Date.now())) {
|
|
72
|
+
if (!deps.short())
|
|
73
|
+
break;
|
|
74
|
+
const bytes = (await deps.sizeOf(r.path).catch(() => null)) ?? 0;
|
|
75
|
+
try {
|
|
76
|
+
remove(r.path);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
deps.log(`low on disk: could not remove ${r.label} (${r.path}): ${String(err)}`);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
freed += bytes;
|
|
83
|
+
removed.push(r.path);
|
|
84
|
+
deps.log(`low on disk: removed ${r.label} (${r.path}), freeing ${gbWords(bytes)} — FireFunc made it, and the next build makes it again`);
|
|
85
|
+
}
|
|
86
|
+
return { freedBytes: freed, removed, stillShort: deps.short() };
|
|
87
|
+
}
|
|
88
|
+
export function stillShortWords(input) {
|
|
89
|
+
const own = input.own.filter((o) => (o.bytes ?? 0) > 0);
|
|
90
|
+
const held = own.length
|
|
91
|
+
? ` FireFunc's own folders hold ${own.map((o) => `${o.label} ${gbWords(o.bytes)}`).join(', ')}; it removed everything it could rebuild.`
|
|
92
|
+
: " FireFunc's own folders hold nothing it could remove.";
|
|
93
|
+
return `${input.machine} has ${gbWords(input.freeBytes)} free and keeps ${gbWords(input.floorBytes)} free, so it takes no new work.${held} The rest of the disk is used outside FireFunc. Fix: free space on ${input.machine}, or lower its floor (minFreeDiskGB in the runner's config).`;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=disk-reclaim.js.map
|
package/dist/drives.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type DriveReport = {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
path: string;
|
|
5
|
+
freeBytes: number;
|
|
6
|
+
totalBytes: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function dirBytes(dir: string, budgetMs?: number): Promise<number | null>;
|
|
9
|
+
export declare function parseWmicDrives(out: string): Array<{
|
|
10
|
+
id: string;
|
|
11
|
+
freeBytes: number;
|
|
12
|
+
totalBytes: number;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function parseCimDrives(out: string): Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
freeBytes: number;
|
|
17
|
+
totalBytes: number;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function parseDfMounts(out: string): Array<{
|
|
20
|
+
filesystem: string;
|
|
21
|
+
mount: string;
|
|
22
|
+
freeBytes: number;
|
|
23
|
+
totalBytes: number;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function mountOf(path: string, mounts: readonly string[]): string | null;
|
|
26
|
+
export declare function pickLinuxMounts(mounts: readonly string[], home: string, user: string, canWrite?: (p: string) => boolean): string[];
|
|
27
|
+
export declare function readDrives(os?: NodeJS.Platform): DriveReport[];
|
|
28
|
+
export declare function driveReport(now?: number, read?: () => DriveReport[]): DriveReport[];
|
|
29
|
+
export declare function rootBytes(root: string, now?: number, walk?: (dir: string) => Promise<number | null>): number | null;
|