@firefunc-agent/runner 0.9.7 → 0.9.34
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 +169 -10
- package/dist/activity.d.ts +1 -0
- package/dist/activity.js +1 -1
- package/dist/alive.d.ts +40 -0
- package/dist/alive.js +138 -0
- package/dist/api-fallback.d.ts +11 -0
- package/dist/api-fallback.js +80 -0
- package/dist/api.d.ts +186 -3
- package/dist/api.js +311 -6
- package/dist/ask/index.d.ts +20 -0
- package/dist/ask/index.js +64 -0
- package/dist/ask-first.d.ts +8 -0
- package/dist/brief-file.d.ts +15 -0
- package/dist/brief-file.js +36 -0
- package/dist/brief.d.ts +5 -0
- package/dist/brief.js +19 -3
- package/dist/build-caches.d.ts +7 -0
- package/dist/build-caches.js +63 -0
- package/dist/build-info.json +2 -2
- package/dist/checkpoint.d.ts +40 -0
- package/dist/checkpoint.js +98 -0
- package/dist/cli.js +184 -18
- package/dist/cloud-boot.d.ts +41 -0
- package/dist/cloud-boot.js +239 -0
- package/dist/command-activity.d.ts +23 -0
- package/dist/command-activity.js +89 -0
- package/dist/command-step.d.ts +58 -0
- package/dist/command-step.js +248 -0
- package/dist/config.d.ts +40 -0
- package/dist/config.js +23 -0
- package/dist/cut.d.ts +2 -1
- package/dist/cut.js +19 -5
- package/dist/daemon.js +375 -14
- package/dist/device-lease.d.ts +15 -0
- package/dist/device-lease.js +608 -0
- package/dist/editor/fs-server.d.ts +31 -0
- package/dist/editor/fs-server.js +159 -0
- package/dist/editor/relay-crypto.d.ts +68 -0
- package/dist/editor/relay-crypto.js +191 -0
- package/dist/editor/sessions.d.ts +50 -0
- package/dist/editor/sessions.js +279 -0
- package/dist/editor/worktree-of.d.ts +1 -0
- package/dist/editor/worktree-of.js +23 -0
- package/dist/editor/ws-client.d.ts +26 -0
- package/dist/editor/ws-client.js +227 -0
- package/dist/engine-account.d.ts +24 -0
- package/dist/engine-account.js +118 -0
- package/dist/engine-login.d.ts +12 -0
- package/dist/engine-login.js +88 -0
- package/dist/engine-models.d.ts +13 -0
- package/dist/engine-models.js +71 -0
- package/dist/engine-watch.d.ts +1 -0
- package/dist/engine-watch.js +22 -6
- package/dist/engines/antigravity.js +19 -4
- package/dist/engines/claude.js +15 -8
- package/dist/engines/codex.js +16 -2
- package/dist/engines/copilot.js +12 -0
- package/dist/engines/crush.d.ts +2 -0
- package/dist/engines/crush.js +58 -0
- package/dist/engines/cursor.js +12 -0
- package/dist/engines/gemini.js +14 -9
- package/dist/engines/index.d.ts +8 -0
- package/dist/engines/index.js +73 -1
- package/dist/engines/kilo.d.ts +2 -0
- package/dist/engines/kilo.js +63 -0
- package/dist/engines/opencode.d.ts +9 -0
- package/dist/engines/opencode.js +234 -0
- package/dist/engines/openhands.d.ts +10 -0
- package/dist/engines/openhands.js +271 -0
- package/dist/engines/pi.d.ts +10 -0
- package/dist/engines/pi.js +248 -0
- package/dist/engines/qwen.d.ts +8 -0
- package/dist/engines/qwen.js +153 -0
- package/dist/engines/sessions.d.ts +6 -0
- package/dist/engines/sessions.js +68 -0
- package/dist/engines/types.d.ts +3 -3
- package/dist/exec.d.ts +1 -0
- package/dist/exec.js +10 -4
- package/dist/firefunc/agents.d.ts +8 -1
- package/dist/firefunc/agents.js +53 -3
- package/dist/firefunc/auth.js +72 -19
- package/dist/firefunc/cli.js +25 -0
- package/dist/firefunc/client.d.ts +5 -1
- package/dist/firefunc/client.js +12 -2
- package/dist/firefunc/config.d.ts +11 -1
- package/dist/firefunc/config.js +6 -4
- package/dist/firefunc/io.d.ts +1 -0
- package/dist/firefunc/main.js +8 -1
- package/dist/firefunc/oauth-login.d.ts +23 -0
- package/dist/firefunc/oauth-login.js +304 -0
- package/dist/firefunc/tasks.d.ts +4 -0
- package/dist/firefunc/tasks.js +89 -2
- package/dist/fleet-words.d.ts +2 -0
- package/dist/fleet-words.js +7 -0
- package/dist/git-auth.d.ts +16 -0
- package/dist/git-auth.js +48 -2
- package/dist/held.d.ts +3 -0
- package/dist/job.d.ts +26 -3
- package/dist/job.js +1109 -132
- package/dist/keep-awake.d.ts +17 -0
- package/dist/keep-awake.js +90 -0
- package/dist/keep-local.d.ts +2 -1
- package/dist/keep-local.js +8 -3
- package/dist/limit.d.ts +10 -1
- package/dist/limit.js +264 -4
- package/dist/local-checks.d.ts +19 -0
- package/dist/local-checks.js +79 -0
- package/dist/locks.d.ts +21 -1
- package/dist/locks.js +279 -66
- package/dist/machine-commands.d.ts +21 -0
- package/dist/machine-commands.js +107 -0
- package/dist/machine-profile.d.ts +18 -0
- package/dist/machine-profile.js +69 -0
- package/dist/mcp-init.d.ts +2 -0
- package/dist/mcp-init.js +28 -0
- package/dist/mcp.d.ts +13 -1
- package/dist/mcp.js +23 -2
- package/dist/network.js +3 -2
- package/dist/orphans.d.ts +4 -0
- package/dist/orphans.js +96 -4
- package/dist/plan-phase/index.d.ts +11 -0
- package/dist/plan-phase/index.js +46 -0
- package/dist/pool.d.ts +1 -0
- package/dist/pool.js +29 -4
- package/dist/pr-title.d.ts +15 -0
- package/dist/pr-title.js +33 -0
- package/dist/recover.d.ts +3 -1
- package/dist/recover.js +27 -7
- package/dist/reference-files.d.ts +27 -0
- package/dist/reference-files.js +202 -0
- package/dist/release-draft.d.ts +79 -0
- package/dist/release-draft.js +301 -0
- package/dist/resources.d.ts +86 -0
- package/dist/resources.js +217 -0
- package/dist/restart-idle.d.ts +23 -0
- package/dist/restart-idle.js +67 -0
- package/dist/run-attachments.d.ts +84 -0
- package/dist/run-attachments.js +281 -0
- package/dist/run-stops.d.ts +15 -0
- package/dist/run-stops.js +90 -0
- package/dist/run-temp.d.ts +12 -0
- package/dist/run-temp.js +57 -0
- package/dist/secret-scan.d.ts +6 -1
- package/dist/secret-scan.js +33 -0
- package/dist/secret-values.d.ts +17 -0
- package/dist/secret-values.js +81 -0
- package/dist/self-upgrade.d.ts +36 -0
- package/dist/self-upgrade.js +78 -0
- package/dist/service.d.ts +7 -1
- package/dist/service.js +50 -7
- package/dist/sign-in.d.ts +41 -0
- package/dist/sign-in.js +239 -0
- package/dist/tool-call.d.ts +59 -0
- package/dist/tool-call.js +375 -0
- package/dist/trail/chain.d.ts +12 -0
- package/dist/trail/chain.js +89 -0
- package/dist/trail/deltas.d.ts +34 -0
- package/dist/trail/deltas.js +206 -0
- package/dist/trail/index.d.ts +27 -0
- package/dist/trail/index.js +128 -0
- package/dist/trail/keys.d.ts +14 -0
- package/dist/trail/keys.js +61 -0
- package/dist/trail/recorder.d.ts +118 -0
- package/dist/trail/recorder.js +697 -0
- package/dist/trail/rules.d.ts +30 -0
- package/dist/trail/rules.js +158 -0
- package/dist/trail/stream.d.ts +41 -0
- package/dist/trail/stream.js +86 -0
- package/dist/transport.d.ts +26 -0
- package/dist/transport.js +118 -0
- package/dist/work-dir.d.ts +11 -0
- package/dist/work-dir.js +69 -0
- package/dist/worktree-report.d.ts +10 -0
- package/dist/worktree-report.js +17 -0
- package/dist/worktrees.d.ts +16 -1
- package/dist/worktrees.js +62 -17
- package/package.json +4 -4
- package/skill/firefunc/SKILL.md +4 -3
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { exec } from './exec.js';
|
|
2
|
+
import { deviceProcesses } from './orphans.js';
|
|
3
|
+
export const BUSY_CPU_MS = 2_000;
|
|
4
|
+
export const BUSY_REPORT_MS = 30 * 60_000;
|
|
5
|
+
export function parseCpuTime(text) {
|
|
6
|
+
const m = /^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+(?:\.\d+)?)$/.exec(text.trim());
|
|
7
|
+
if (!m)
|
|
8
|
+
return null;
|
|
9
|
+
const [, d, h, mm, ss] = m;
|
|
10
|
+
return Math.round(((Number(d ?? 0) * 24 + Number(h ?? 0)) * 3600 + Number(mm) * 60 + Number(ss)) * 1000);
|
|
11
|
+
}
|
|
12
|
+
export function parseCpuRows(stdout) {
|
|
13
|
+
const out = [];
|
|
14
|
+
for (const line of stdout.split('\n')) {
|
|
15
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/.exec(line);
|
|
16
|
+
if (!m)
|
|
17
|
+
continue;
|
|
18
|
+
const cpuMs = parseCpuTime(m[4]);
|
|
19
|
+
if (cpuMs === null)
|
|
20
|
+
continue;
|
|
21
|
+
out.push({
|
|
22
|
+
pid: Number(m[1]),
|
|
23
|
+
ppid: Number(m[2]),
|
|
24
|
+
pgid: Number(m[3]),
|
|
25
|
+
cpuMs,
|
|
26
|
+
command: m[5].trim(),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
export function commandCpuByGroup(rows, groups) {
|
|
32
|
+
const devices = deviceProcesses(rows);
|
|
33
|
+
const out = new Map();
|
|
34
|
+
for (const r of rows) {
|
|
35
|
+
if (!groups.has(r.pgid) || r.pid === r.pgid || devices.has(r.pid))
|
|
36
|
+
continue;
|
|
37
|
+
out.set(r.pgid, (out.get(r.pgid) ?? 0) + r.cpuMs);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
export function commandActivityWatch(deps = {}) {
|
|
42
|
+
const ps = deps.ps ??
|
|
43
|
+
(async () => {
|
|
44
|
+
if (process.platform === 'win32')
|
|
45
|
+
return null;
|
|
46
|
+
const r = await exec('ps', ['-A', '-ww', '-o', 'pid=,ppid=,pgid=,time=,command='], {
|
|
47
|
+
timeoutMs: 20_000,
|
|
48
|
+
}).catch(() => null);
|
|
49
|
+
return r && r.code === 0 ? r.stdout : null;
|
|
50
|
+
});
|
|
51
|
+
const now = deps.now ?? Date.now;
|
|
52
|
+
const last = new Map();
|
|
53
|
+
const busyAt = new Map();
|
|
54
|
+
const sample = async (held) => {
|
|
55
|
+
const live = held.filter((h) => Number.isInteger(h.engineGroup) && h.engineGroup > 1);
|
|
56
|
+
for (const id of [...last.keys()])
|
|
57
|
+
if (!live.some((h) => h.runId === id))
|
|
58
|
+
last.delete(id);
|
|
59
|
+
for (const id of [...busyAt.keys()])
|
|
60
|
+
if (!held.some((h) => h.runId === id))
|
|
61
|
+
busyAt.delete(id);
|
|
62
|
+
if (live.length === 0)
|
|
63
|
+
return;
|
|
64
|
+
const out = await ps();
|
|
65
|
+
if (!out)
|
|
66
|
+
return;
|
|
67
|
+
const cpu = commandCpuByGroup(parseCpuRows(out), new Set(live.map((h) => h.engineGroup)));
|
|
68
|
+
const t = now();
|
|
69
|
+
for (const h of live) {
|
|
70
|
+
const used = cpu.get(h.engineGroup) ?? 0;
|
|
71
|
+
const before = last.get(h.runId);
|
|
72
|
+
if (before && before.pgid === h.engineGroup && used - before.cpuMs >= BUSY_CPU_MS) {
|
|
73
|
+
busyAt.set(h.runId, t);
|
|
74
|
+
}
|
|
75
|
+
last.set(h.runId, { pgid: h.engineGroup, cpuMs: used });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const report = () => {
|
|
79
|
+
const t = now();
|
|
80
|
+
const out = [];
|
|
81
|
+
for (const [runId, at] of busyAt) {
|
|
82
|
+
if (t - at <= BUSY_REPORT_MS)
|
|
83
|
+
out.push({ runId, at: new Date(at).toISOString() });
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
};
|
|
87
|
+
return { sample, report };
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=command-activity.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { RunnerConfig } from './config.js';
|
|
2
|
+
export type CommandJob = {
|
|
3
|
+
id: string;
|
|
4
|
+
repo: string;
|
|
5
|
+
command: string;
|
|
6
|
+
timeoutMs: number;
|
|
7
|
+
};
|
|
8
|
+
export type CommandReport = {
|
|
9
|
+
ok: true;
|
|
10
|
+
exit: number;
|
|
11
|
+
output: string;
|
|
12
|
+
lines: number;
|
|
13
|
+
timedOut?: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
error: {
|
|
17
|
+
code: string;
|
|
18
|
+
reason: string;
|
|
19
|
+
fix: string;
|
|
20
|
+
transient?: boolean;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare const COMMANDS_AT_ONCE = 2;
|
|
24
|
+
export declare const COMMAND_KEEP_LINES = 2000;
|
|
25
|
+
export declare function readCommands(raw: unknown): ({
|
|
26
|
+
job: CommandJob;
|
|
27
|
+
} | {
|
|
28
|
+
id: string;
|
|
29
|
+
report: CommandReport;
|
|
30
|
+
})[];
|
|
31
|
+
export declare function lineKeeper(keep?: number): {
|
|
32
|
+
write(chunk: string): void;
|
|
33
|
+
end(): {
|
|
34
|
+
output: string;
|
|
35
|
+
lines: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare function runCommandJob(job: CommandJob, cfg: RunnerConfig, opts: {
|
|
39
|
+
allowed: () => boolean;
|
|
40
|
+
log: (msg: string) => void;
|
|
41
|
+
onStart?: (stop: () => void) => void;
|
|
42
|
+
}): Promise<CommandReport>;
|
|
43
|
+
export type CommandClient = {
|
|
44
|
+
commandResult(id: string, report: CommandReport): Promise<boolean>;
|
|
45
|
+
};
|
|
46
|
+
export declare function createCommandPump(opts: {
|
|
47
|
+
api: CommandClient;
|
|
48
|
+
cfg: RunnerConfig;
|
|
49
|
+
allowed: () => boolean;
|
|
50
|
+
log: (msg: string) => void;
|
|
51
|
+
run?: typeof runCommandJob;
|
|
52
|
+
atOnce?: number;
|
|
53
|
+
}): {
|
|
54
|
+
take(raw: unknown): void;
|
|
55
|
+
stop(ids: unknown): void;
|
|
56
|
+
free(): number;
|
|
57
|
+
idle(): Promise<void>;
|
|
58
|
+
};
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { resolveRepoPath } from './job.js';
|
|
3
|
+
export const COMMANDS_AT_ONCE = 2;
|
|
4
|
+
export const COMMAND_KEEP_LINES = 2000;
|
|
5
|
+
const LINE_MAX = 2000;
|
|
6
|
+
const TIMEOUT_FLOOR_MS = 1_000;
|
|
7
|
+
const TIMEOUT_CEILING_MS = 120 * 60_000;
|
|
8
|
+
const isRecord = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
9
|
+
export function readCommands(raw) {
|
|
10
|
+
if (!Array.isArray(raw))
|
|
11
|
+
return [];
|
|
12
|
+
const out = [];
|
|
13
|
+
for (const c of raw) {
|
|
14
|
+
if (!isRecord(c) || typeof c.id !== 'string' || !c.id)
|
|
15
|
+
continue;
|
|
16
|
+
if (typeof c.repo !== 'string' || typeof c.command !== 'string' || !c.command.trim()) {
|
|
17
|
+
out.push({
|
|
18
|
+
id: c.id,
|
|
19
|
+
report: {
|
|
20
|
+
ok: false,
|
|
21
|
+
error: {
|
|
22
|
+
code: 'command_unreadable',
|
|
23
|
+
reason: 'This machine could not read the command FireFunc sent: it names no repository or no command.',
|
|
24
|
+
fix: 'Check the step in the builder, then retry the run from it.',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const t = typeof c.timeoutMs === 'number' && Number.isFinite(c.timeoutMs) ? c.timeoutMs : 600_000;
|
|
31
|
+
out.push({
|
|
32
|
+
job: {
|
|
33
|
+
id: c.id,
|
|
34
|
+
repo: c.repo,
|
|
35
|
+
command: c.command,
|
|
36
|
+
timeoutMs: Math.min(Math.max(t, TIMEOUT_FLOOR_MS), TIMEOUT_CEILING_MS),
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
export function lineKeeper(keep = COMMAND_KEEP_LINES) {
|
|
43
|
+
const lines = [];
|
|
44
|
+
let partial = '';
|
|
45
|
+
let count = 0;
|
|
46
|
+
const push = (line) => {
|
|
47
|
+
count += 1;
|
|
48
|
+
lines.push(line.length > LINE_MAX ? `${line.slice(0, LINE_MAX)}…` : line);
|
|
49
|
+
if (lines.length > keep)
|
|
50
|
+
lines.shift();
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
write(chunk) {
|
|
54
|
+
const text = partial + chunk.replace(/\r\n?/g, '\n');
|
|
55
|
+
const parts = text.split('\n');
|
|
56
|
+
partial = parts.pop() ?? '';
|
|
57
|
+
for (const p of parts)
|
|
58
|
+
push(p);
|
|
59
|
+
if (partial.length > LINE_MAX * 4) {
|
|
60
|
+
push(partial);
|
|
61
|
+
partial = '';
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
end() {
|
|
65
|
+
if (partial)
|
|
66
|
+
push(partial);
|
|
67
|
+
partial = '';
|
|
68
|
+
return { output: lines.join('\n'), lines: count };
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function stopTree(child) {
|
|
73
|
+
if (child.pid === undefined || child.exitCode !== null)
|
|
74
|
+
return;
|
|
75
|
+
try {
|
|
76
|
+
if (process.platform === 'win32') {
|
|
77
|
+
spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { windowsHide: true });
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
try {
|
|
85
|
+
child.kill('SIGKILL');
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export async function runCommandJob(job, cfg, opts) {
|
|
92
|
+
if (!opts.allowed()) {
|
|
93
|
+
return {
|
|
94
|
+
ok: false,
|
|
95
|
+
error: {
|
|
96
|
+
code: 'commands_not_allowed',
|
|
97
|
+
reason: 'This machine does not allow automations to run commands.',
|
|
98
|
+
fix: 'Its owner runs "firefunc-runner allow-commands" on it, or the step names another machine. Then retry the run from the step.',
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const cwd = resolveRepoPath(job.repo, cfg);
|
|
103
|
+
if (!cwd) {
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
error: {
|
|
107
|
+
code: 'no_checkout',
|
|
108
|
+
reason: `This machine has no checkout of ${job.repo}, and a command never clones one.`,
|
|
109
|
+
fix: `Clone it here and map it ("firefunc-runner repo add ${job.repo} <path>", or keep it under --repos-dir), then retry the run from the step.`,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return new Promise((resolve) => {
|
|
114
|
+
const keeper = lineKeeper();
|
|
115
|
+
let timedOut = false;
|
|
116
|
+
let child;
|
|
117
|
+
try {
|
|
118
|
+
child = spawn(job.command, {
|
|
119
|
+
cwd,
|
|
120
|
+
shell: true,
|
|
121
|
+
env: { ...process.env, ...(cfg.claudeEnv ?? {}), FIREFUNC_COMMAND: '1' },
|
|
122
|
+
detached: process.platform !== 'win32',
|
|
123
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
124
|
+
windowsHide: true,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
resolve({
|
|
129
|
+
ok: false,
|
|
130
|
+
error: {
|
|
131
|
+
code: 'command_not_started',
|
|
132
|
+
reason: `This machine could not start the command: ${err.message}`.slice(0, 400),
|
|
133
|
+
fix: 'Check the shell on this machine, then retry the run from the step.',
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const stop = () => stopTree(child);
|
|
139
|
+
opts.onStart?.(stop);
|
|
140
|
+
const timer = setTimeout(() => {
|
|
141
|
+
timedOut = true;
|
|
142
|
+
opts.log(`command ${job.id}: past its time limit — stopping it`);
|
|
143
|
+
stop();
|
|
144
|
+
}, job.timeoutMs);
|
|
145
|
+
timer.unref?.();
|
|
146
|
+
child.stdout?.setEncoding('utf8').on('data', (d) => keeper.write(d));
|
|
147
|
+
child.stderr?.setEncoding('utf8').on('data', (d) => keeper.write(d));
|
|
148
|
+
child.on('error', (err) => {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
resolve({
|
|
151
|
+
ok: false,
|
|
152
|
+
error: {
|
|
153
|
+
code: 'command_not_started',
|
|
154
|
+
reason: `This machine could not start the command: ${err.message}`.slice(0, 400),
|
|
155
|
+
fix: 'Check the shell on this machine, then retry the run from the step.',
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
child.on('close', (code, signal) => {
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
const kept = keeper.end();
|
|
162
|
+
const exit = typeof code === 'number' ? code : signal ? 128 + 9 : -1;
|
|
163
|
+
resolve({
|
|
164
|
+
ok: true,
|
|
165
|
+
exit: Math.max(-1, Math.min(255, exit)),
|
|
166
|
+
output: kept.output,
|
|
167
|
+
lines: kept.lines,
|
|
168
|
+
...(timedOut ? { timedOut: true } : {}),
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
export function createCommandPump(opts) {
|
|
174
|
+
const atOnce = opts.atOnce ?? COMMANDS_AT_ONCE;
|
|
175
|
+
const run = opts.run ?? runCommandJob;
|
|
176
|
+
const active = new Map();
|
|
177
|
+
const waiting = [];
|
|
178
|
+
const report = async (id, what) => {
|
|
179
|
+
const sent = await opts.api.commandResult(id, what).catch(() => false);
|
|
180
|
+
if (!sent)
|
|
181
|
+
opts.log(`command ${id}: FireFunc did not take the result (stopped, or not reachable)`);
|
|
182
|
+
};
|
|
183
|
+
const start = (job) => {
|
|
184
|
+
const entry = {
|
|
185
|
+
done: Promise.resolve(),
|
|
186
|
+
stop: null,
|
|
187
|
+
};
|
|
188
|
+
entry.done = (async () => {
|
|
189
|
+
opts.log(`command ${job.id}: running in ${job.repo} (no engine)`);
|
|
190
|
+
const what = await run(job, opts.cfg, {
|
|
191
|
+
allowed: opts.allowed,
|
|
192
|
+
log: opts.log,
|
|
193
|
+
onStart: (s) => {
|
|
194
|
+
entry.stop = s;
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
opts.log(`command ${job.id}: ${what.ok ? `exited with ${what.exit}${what.timedOut ? ' (time limit)' : ''}` : what.error.reason}`);
|
|
198
|
+
await report(job.id, what);
|
|
199
|
+
})()
|
|
200
|
+
.catch(() => { })
|
|
201
|
+
.finally(() => {
|
|
202
|
+
active.delete(job.id);
|
|
203
|
+
const next = waiting.shift();
|
|
204
|
+
if (next)
|
|
205
|
+
start(next);
|
|
206
|
+
});
|
|
207
|
+
active.set(job.id, entry);
|
|
208
|
+
};
|
|
209
|
+
return {
|
|
210
|
+
take(raw) {
|
|
211
|
+
for (const item of readCommands(raw)) {
|
|
212
|
+
const id = 'job' in item ? item.job.id : item.id;
|
|
213
|
+
if (active.has(id) || waiting.some((w) => w.id === id))
|
|
214
|
+
continue;
|
|
215
|
+
if (!('job' in item)) {
|
|
216
|
+
void report(item.id, item.report);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (active.size < atOnce)
|
|
220
|
+
start(item.job);
|
|
221
|
+
else
|
|
222
|
+
waiting.push(item.job);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
stop(ids) {
|
|
226
|
+
if (!Array.isArray(ids))
|
|
227
|
+
return;
|
|
228
|
+
for (const id of ids) {
|
|
229
|
+
if (typeof id !== 'string')
|
|
230
|
+
continue;
|
|
231
|
+
const at = waiting.findIndex((w) => w.id === id);
|
|
232
|
+
if (at >= 0)
|
|
233
|
+
waiting.splice(at, 1);
|
|
234
|
+
const a = active.get(id);
|
|
235
|
+
if (a?.stop) {
|
|
236
|
+
opts.log(`command ${id}: stopped in FireFunc — ending it`);
|
|
237
|
+
a.stop();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
free: () => Math.max(0, atOnce - active.size - waiting.length),
|
|
242
|
+
idle: async () => {
|
|
243
|
+
while (active.size > 0)
|
|
244
|
+
await Promise.allSettled([...active.values()].map((a) => a.done));
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=command-step.js.map
|
package/dist/config.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
export declare function expandHome(p: string): string;
|
|
2
2
|
export type RunnerConfig = {
|
|
3
3
|
apiUrl: string;
|
|
4
|
+
cloud?: {
|
|
5
|
+
provider: 'aws' | 'azure' | 'gcp';
|
|
6
|
+
connectionId: string;
|
|
7
|
+
engineSecrets: Record<string, string>;
|
|
8
|
+
store: Record<string, string>;
|
|
9
|
+
};
|
|
4
10
|
token: string;
|
|
5
11
|
name?: string;
|
|
6
12
|
repos?: Record<string, string>;
|
|
7
13
|
reposDir?: string;
|
|
14
|
+
workDir?: string;
|
|
8
15
|
claudeBin?: string;
|
|
9
16
|
engine?: string;
|
|
10
17
|
codexBin?: string;
|
|
@@ -15,6 +22,18 @@ export type RunnerConfig = {
|
|
|
15
22
|
geminiArgs?: string[];
|
|
16
23
|
antigravityBin?: string;
|
|
17
24
|
antigravityArgs?: string[];
|
|
25
|
+
opencodeBin?: string;
|
|
26
|
+
opencodeArgs?: string[];
|
|
27
|
+
piBin?: string;
|
|
28
|
+
piArgs?: string[];
|
|
29
|
+
kiloBin?: string;
|
|
30
|
+
kiloArgs?: string[];
|
|
31
|
+
qwenBin?: string;
|
|
32
|
+
qwenArgs?: string[];
|
|
33
|
+
crushBin?: string;
|
|
34
|
+
crushArgs?: string[];
|
|
35
|
+
openhandsBin?: string;
|
|
36
|
+
openhandsArgs?: string[];
|
|
18
37
|
copilotBin?: string;
|
|
19
38
|
copilotArgs?: string[];
|
|
20
39
|
cursorAgentBin?: string;
|
|
@@ -24,6 +43,14 @@ export type RunnerConfig = {
|
|
|
24
43
|
viewerPort?: number;
|
|
25
44
|
viewerEnabled?: boolean;
|
|
26
45
|
maxParallel?: number;
|
|
46
|
+
drain?: boolean;
|
|
47
|
+
allowCommands?: boolean;
|
|
48
|
+
devMode?: {
|
|
49
|
+
editor?: boolean;
|
|
50
|
+
};
|
|
51
|
+
keepAwake?: boolean;
|
|
52
|
+
minFreeDiskGB?: number;
|
|
53
|
+
minFreeMemoryGB?: number;
|
|
27
54
|
devServerBasePort?: number;
|
|
28
55
|
model?: string;
|
|
29
56
|
effort?: string;
|
|
@@ -32,10 +59,19 @@ export type RunnerConfig = {
|
|
|
32
59
|
maxBudgetUsd?: number;
|
|
33
60
|
claudeCodeOAuthToken?: string;
|
|
34
61
|
claudeUseApiKey?: boolean;
|
|
62
|
+
claudeApiKeyFallback?: boolean;
|
|
63
|
+
claudeKeyToPlan?: boolean;
|
|
64
|
+
claudeApiKeyFile?: string;
|
|
35
65
|
claudeArgs?: string[];
|
|
36
66
|
jobTimeoutMinutes?: number;
|
|
67
|
+
checkpointMinutes?: number;
|
|
68
|
+
cargoTarget?: 'per-run' | 'shared';
|
|
37
69
|
mcpRelay?: boolean;
|
|
38
70
|
heavyLock?: boolean;
|
|
71
|
+
heavySlots?: number;
|
|
72
|
+
devices?: string[];
|
|
73
|
+
maxEmulators?: number;
|
|
74
|
+
maxHeavyRuns?: number;
|
|
39
75
|
baseBranch?: string;
|
|
40
76
|
claudeEnv?: Record<string, string>;
|
|
41
77
|
setupCommands?: string[];
|
|
@@ -48,3 +84,7 @@ export declare function configPath(): string;
|
|
|
48
84
|
export declare function loadConfig(): RunnerConfig | null;
|
|
49
85
|
export declare function saveConfig(cfg: RunnerConfig): void;
|
|
50
86
|
export declare function runnerDir(): string;
|
|
87
|
+
export declare function isDraining(cfg: Pick<RunnerConfig, 'drain' | 'maxParallel'>): boolean;
|
|
88
|
+
export declare function drainSetting(cfg: RunnerConfig, on: boolean): RunnerConfig;
|
|
89
|
+
export declare function effectiveMaxParallel(cfg: Pick<RunnerConfig, 'drain' | 'maxParallel'>, offered: number): number;
|
|
90
|
+
export declare function editorsAllowed(cfg: Pick<RunnerConfig, 'devMode'> | null | undefined): boolean;
|
package/dist/config.js
CHANGED
|
@@ -30,4 +30,27 @@ export function saveConfig(cfg) {
|
|
|
30
30
|
export function runnerDir() {
|
|
31
31
|
return dirname(configPath());
|
|
32
32
|
}
|
|
33
|
+
export function isDraining(cfg) {
|
|
34
|
+
return cfg.drain === true || cfg.maxParallel === 0;
|
|
35
|
+
}
|
|
36
|
+
export function drainSetting(cfg, on) {
|
|
37
|
+
const next = { ...cfg };
|
|
38
|
+
if (on) {
|
|
39
|
+
next.drain = true;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
delete next.drain;
|
|
43
|
+
if (next.maxParallel === 0)
|
|
44
|
+
delete next.maxParallel;
|
|
45
|
+
}
|
|
46
|
+
return next;
|
|
47
|
+
}
|
|
48
|
+
export function effectiveMaxParallel(cfg, offered) {
|
|
49
|
+
if (isDraining(cfg))
|
|
50
|
+
return 0;
|
|
51
|
+
return Math.max(1, Math.floor(cfg.maxParallel ?? offered));
|
|
52
|
+
}
|
|
53
|
+
export function editorsAllowed(cfg) {
|
|
54
|
+
return cfg?.devMode?.editor === true;
|
|
55
|
+
}
|
|
33
56
|
//# sourceMappingURL=config.js.map
|
package/dist/cut.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export type CutSession = {
|
|
|
20
20
|
continuesBranch: boolean;
|
|
21
21
|
usage?: RunUsage;
|
|
22
22
|
writtenSkills?: WrittenSkills;
|
|
23
|
+
reason?: 'plan_limit' | 'timeout' | 'network' | 'auth' | 'lost' | 'push';
|
|
23
24
|
};
|
|
24
25
|
export declare function cutDir(runnerDir: string): string;
|
|
25
26
|
export declare function promptHash(prompt: string): string;
|
|
@@ -43,4 +44,4 @@ export declare function cutFor(runnerDir: string, key: CutKey, now?: number): {
|
|
|
43
44
|
export declare function expiredCuts(runnerDir: string, now?: number): CutSession[];
|
|
44
45
|
export declare function keptWorktrees(runnerDir: string): Set<string>;
|
|
45
46
|
export declare function cutWorktrees(runnerDir: string): Set<string>;
|
|
46
|
-
export declare function resumeAfterResetBrief(prompt: string, briefChanged: boolean): string;
|
|
47
|
+
export declare function resumeAfterResetBrief(prompt: string, briefChanged: boolean, reason?: CutSession['reason']): string;
|
package/dist/cut.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { keptChangeWorktrees } from './ask-first.js';
|
|
5
|
+
import { dropBuildCaches } from './build-caches.js';
|
|
5
6
|
const DAY = 86_400_000;
|
|
6
7
|
const ITEM_ID = /^[A-Za-z0-9][A-Za-z0-9-]{3,79}$/;
|
|
7
8
|
export function cutDir(runnerDir) {
|
|
@@ -29,11 +30,13 @@ export function saveCut(runnerDir, cut) {
|
|
|
29
30
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
30
31
|
writeFileSync(tmp, `${JSON.stringify(cut, null, 2)}\n`, { mode: 0o600 });
|
|
31
32
|
renameSync(tmp, file);
|
|
32
|
-
return true;
|
|
33
33
|
}
|
|
34
34
|
catch {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
|
+
if (cut.worktree)
|
|
38
|
+
dropBuildCaches(cut.worktree);
|
|
39
|
+
return true;
|
|
37
40
|
}
|
|
38
41
|
export function listCuts(runnerDir) {
|
|
39
42
|
const dir = cutDir(runnerDir);
|
|
@@ -100,10 +103,21 @@ export function keptWorktrees(runnerDir) {
|
|
|
100
103
|
export function cutWorktrees(runnerDir) {
|
|
101
104
|
return new Set(listCuts(runnerDir).map((c) => c.worktree));
|
|
102
105
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
const CUT_BY = {
|
|
107
|
+
timeout: "reached this machine's time limit before it finished",
|
|
108
|
+
network: 'was cut short by a network outage that lasted longer than the runner waits, before it finished',
|
|
109
|
+
auth: "stopped because the engine's sign-in on this machine expired, before it finished",
|
|
110
|
+
lost: 'was cut short when the runner on this machine stopped (a restart or a crash), before it finished',
|
|
111
|
+
push: 'finished and was committed, but the push to the repository failed — make sure the work is complete, then end your turn so the runner pushes it again',
|
|
112
|
+
};
|
|
113
|
+
export function resumeAfterResetBrief(prompt, briefChanged, reason = 'plan_limit') {
|
|
114
|
+
return ((reason && reason !== 'plan_limit'
|
|
115
|
+
? `Your previous attempt on this task ${CUT_BY[reason]}. ` +
|
|
116
|
+
'The worktree still holds everything you did — check `git status` and `git diff`, then ' +
|
|
117
|
+
'continue from where you stopped and finish the task; do not redo what is already done.'
|
|
118
|
+
: "Your session on this task was stopped by the plan's usage limit, which has now reset. " +
|
|
119
|
+
'The worktree still holds everything you did — check `git status` and `git diff`, then ' +
|
|
120
|
+
'continue from where you stopped and finish the task.') +
|
|
107
121
|
(briefChanged
|
|
108
122
|
? ' FireFunc sent this run a brief that differs from the one you started with; it follows, and where the two differ, follow this one.\n\n' +
|
|
109
123
|
prompt
|