@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
package/dist/mcp.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type McpRunConfig = {
|
|
|
20
20
|
servers: McpServerSpec[];
|
|
21
21
|
callBudget: number | null;
|
|
22
22
|
};
|
|
23
|
-
export type McpFormat = 'claude' | 'cursor' | 'gemini' | 'codex' | 'copilot';
|
|
23
|
+
export type McpFormat = 'claude' | 'cursor' | 'gemini' | 'codex' | 'copilot' | 'opencode';
|
|
24
24
|
export type McpCredentialClient = {
|
|
25
25
|
mcpCredential(runId: string, server: string): Promise<{
|
|
26
26
|
token: string;
|
|
@@ -50,6 +50,11 @@ export type PrepareMcpOptions = {
|
|
|
50
50
|
relay?: boolean;
|
|
51
51
|
};
|
|
52
52
|
export declare function mcpFormatForEngine(engine: string | null | undefined): McpFormat | null;
|
|
53
|
+
declare function parseServer(raw: unknown): {
|
|
54
|
+
spec: McpServerSpec;
|
|
55
|
+
} | {
|
|
56
|
+
reject: string;
|
|
57
|
+
};
|
|
53
58
|
export type CachedMcpLogin = {
|
|
54
59
|
server: string;
|
|
55
60
|
tokenType: string;
|
|
@@ -58,5 +63,12 @@ export type CachedMcpLogin = {
|
|
|
58
63
|
accountLabel?: string | null;
|
|
59
64
|
};
|
|
60
65
|
export declare function mcpLoginPath(server: string): string;
|
|
66
|
+
type LoginLookup = {
|
|
67
|
+
login: CachedMcpLogin;
|
|
68
|
+
} | {
|
|
69
|
+
missing: 'none' | 'unreadable' | 'expired';
|
|
70
|
+
};
|
|
71
|
+
declare function readCachedLogin(server: string, now: number): LoginLookup;
|
|
61
72
|
export declare function prepareMcp(opts: PrepareMcpOptions): Promise<PreparedMcp | null>;
|
|
62
73
|
export declare function mcpFromContext(ctx: InvocationContext, format: McpFormat): PreparedMcp | null;
|
|
74
|
+
export { parseServer as parseMcpServerSpec, readCachedLogin as cachedMcpLogin };
|
package/dist/mcp.js
CHANGED
|
@@ -15,6 +15,7 @@ const CONFIG_PATHS = {
|
|
|
15
15
|
gemini: '.gemini/settings.json',
|
|
16
16
|
codex: null,
|
|
17
17
|
copilot: '.firefunc-copilot-mcp.json',
|
|
18
|
+
opencode: '.firefunc-opencode.json',
|
|
18
19
|
};
|
|
19
20
|
export function mcpFormatForEngine(engine) {
|
|
20
21
|
switch (engine) {
|
|
@@ -28,6 +29,8 @@ export function mcpFormatForEngine(engine) {
|
|
|
28
29
|
return 'codex';
|
|
29
30
|
case 'copilot_cli':
|
|
30
31
|
return 'copilot';
|
|
32
|
+
case 'opencode':
|
|
33
|
+
return 'opencode';
|
|
31
34
|
default:
|
|
32
35
|
return null;
|
|
33
36
|
}
|
|
@@ -258,7 +261,7 @@ function whyUnusable(spec, format) {
|
|
|
258
261
|
if (spec.allowedTools.length === 0) {
|
|
259
262
|
return 'no tools are declared for it, so it would connect and offer nothing';
|
|
260
263
|
}
|
|
261
|
-
const boundsTools = format !== 'cursor' && format !== 'codex';
|
|
264
|
+
const boundsTools = format !== 'cursor' && format !== 'codex' && format !== 'opencode';
|
|
262
265
|
if (spec.writeTools?.length && !boundsTools) {
|
|
263
266
|
return (`${format} has no per-tool allowlist, so every tool this server publishes would be callable — including the ${spec.writeTools.length} write tool(s) named in this spec, which is a mutation surface nothing here can bound. ` +
|
|
264
267
|
BOUNDABLE_ENGINES_FIX);
|
|
@@ -342,6 +345,21 @@ function cursorBody(resolved) {
|
|
|
342
345
|
}
|
|
343
346
|
return `${JSON.stringify({ mcpServers: servers }, null, 2)}\n`;
|
|
344
347
|
}
|
|
348
|
+
function opencodeBody(resolved) {
|
|
349
|
+
const servers = {};
|
|
350
|
+
for (const { spec, cred } of resolved) {
|
|
351
|
+
servers[spec.id] =
|
|
352
|
+
spec.transport === 'stdio'
|
|
353
|
+
? { type: 'local', command: [spec.command, ...(spec.args ?? [])], enabled: true }
|
|
354
|
+
: {
|
|
355
|
+
type: 'remote',
|
|
356
|
+
url: spec.url,
|
|
357
|
+
headers: { ...spec.headers, ...credentialHeaders(cred) },
|
|
358
|
+
enabled: true,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
return `${JSON.stringify({ $schema: 'https://opencode.ai/config.json', mcp: servers }, null, 2)}\n`;
|
|
362
|
+
}
|
|
345
363
|
function geminiBody(resolved) {
|
|
346
364
|
const servers = {};
|
|
347
365
|
for (const { spec, cred } of resolved) {
|
|
@@ -540,7 +558,9 @@ export async function prepareMcp(opts) {
|
|
|
540
558
|
? claudeBody(resolved)
|
|
541
559
|
: opts.format === 'cursor'
|
|
542
560
|
? cursorBody(resolved)
|
|
543
|
-
:
|
|
561
|
+
: opts.format === 'opencode'
|
|
562
|
+
? opencodeBody(resolved)
|
|
563
|
+
: geminiBody(resolved);
|
|
544
564
|
writeFileSync(target, body, { mode: 0o600 });
|
|
545
565
|
}
|
|
546
566
|
catch (e) {
|
|
@@ -608,4 +628,5 @@ export function mcpFromContext(ctx, format) {
|
|
|
608
628
|
return null;
|
|
609
629
|
return raw;
|
|
610
630
|
}
|
|
631
|
+
export { parseServer as parseMcpServerSpec, readCachedLogin as cachedMcpLogin };
|
|
611
632
|
//# sourceMappingURL=mcp.js.map
|
package/dist/network.js
CHANGED
|
@@ -13,7 +13,8 @@ const NETWORK_SIGNS = [
|
|
|
13
13
|
/\bfailed to connect\b/i,
|
|
14
14
|
/\bconnection (?:refused|reset|timed out|error)\b/i,
|
|
15
15
|
/\bnetwork (?:error|is unreachable|unreachable)\b/i,
|
|
16
|
-
/\bunable to (?:access|connect)\b/i,
|
|
16
|
+
/\bunable to (?:access|connect|reach)\b/i,
|
|
17
|
+
/\bcan(?:'|’|no)?t reach the (?:api|server)\b/i,
|
|
17
18
|
/\bthe remote end hung up\b/i,
|
|
18
19
|
/\bunexpected disconnect\b/i,
|
|
19
20
|
/\bHTTP\/?[12](?:\.[01])? 50[234]\b/i,
|
|
@@ -31,7 +32,7 @@ export function isNetworkError(input) {
|
|
|
31
32
|
export function networkFailureHint(text) {
|
|
32
33
|
if (!isNetworkError(text))
|
|
33
34
|
return null;
|
|
34
|
-
const m = /(fetch failed|ECONNRESET|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|socket hang up|connection (?:refused|reset|timed out|error)|network (?:error|is unreachable)|TLS handshake|could not resolve host|50[234])/i.exec(text);
|
|
35
|
+
const m = /(fetch failed|ECONNRESET|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|socket hang up|connection (?:refused|reset|timed out|error)|network (?:error|is unreachable)|TLS handshake|could not resolve host|can(?:'|’|no)?t reach the (?:api|server)|50[234])/i.exec(text);
|
|
35
36
|
return `the network went away (${m?.[1] ?? 'transport error'})`;
|
|
36
37
|
}
|
|
37
38
|
export const netDeps = {
|
package/dist/orphans.d.ts
CHANGED
|
@@ -19,9 +19,12 @@ export type OrphanScope = {
|
|
|
19
19
|
};
|
|
20
20
|
export type SelectScope = Omit<OrphanScope, 'groups'> & {
|
|
21
21
|
groups?: number[];
|
|
22
|
+
spareDevices?: boolean;
|
|
22
23
|
};
|
|
23
24
|
export declare function groupsStillOurs(groups: EngineGroup[], rows: ProcessRow[]): Promise<number[]>;
|
|
24
25
|
export declare function selectOrphans(rows: ProcessRow[], cwds: Map<number, string>, scope: SelectScope): number[];
|
|
26
|
+
export declare function isDeviceProcess(command: string): boolean;
|
|
27
|
+
export declare function deviceProcesses(rows: ProcessRow[]): Set<number>;
|
|
25
28
|
export declare function isAlive(pid: number): boolean;
|
|
26
29
|
export type OrphanSweep = {
|
|
27
30
|
stopped: Array<{
|
|
@@ -38,3 +41,4 @@ export declare function reviewCopiesOf(worktree: string): string[];
|
|
|
38
41
|
export declare function trackEngineGroup(pgid: number): void;
|
|
39
42
|
export declare function untrackEngineGroup(pgid: number): void;
|
|
40
43
|
export declare function signalEngineGroups(sig: NodeJS.Signals): number;
|
|
44
|
+
export declare function signalGroupSparingDevices(pgid: number, sig: NodeJS.Signals): boolean;
|
package/dist/orphans.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { readlinkSync, readdirSync, realpathSync } from 'node:fs';
|
|
2
3
|
import { tmpdir } from 'node:os';
|
|
4
|
+
import { workRoots } from './work-dir.js';
|
|
3
5
|
import { basename, join } from 'node:path';
|
|
4
6
|
import { exec } from './exec.js';
|
|
5
7
|
export async function listProcesses() {
|
|
@@ -10,8 +12,11 @@ export async function listProcesses() {
|
|
|
10
12
|
}).catch(() => null);
|
|
11
13
|
if (!ps || ps.code !== 0)
|
|
12
14
|
return [];
|
|
15
|
+
return parseProcesses(ps.stdout);
|
|
16
|
+
}
|
|
17
|
+
function parseProcesses(stdout) {
|
|
13
18
|
const rows = [];
|
|
14
|
-
for (const line of
|
|
19
|
+
for (const line of stdout.split('\n')) {
|
|
15
20
|
const m = /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*)$/.exec(line);
|
|
16
21
|
if (!m)
|
|
17
22
|
continue;
|
|
@@ -96,6 +101,9 @@ export function selectOrphans(rows, cwds, scope) {
|
|
|
96
101
|
for (let p = byPid.get(self)?.ppid; p && !protectedPids.has(p); p = byPid.get(p)?.ppid) {
|
|
97
102
|
protectedPids.add(p);
|
|
98
103
|
}
|
|
104
|
+
if (scope.spareDevices !== false)
|
|
105
|
+
for (const pid of deviceProcesses(rows))
|
|
106
|
+
protectedPids.add(pid);
|
|
99
107
|
const roots = scope.roots.flatMap(spellings);
|
|
100
108
|
const inRoot = roots.map((r) => new RegExp(`${escapeRe(r)}(?:/|\\s|$|['"])`));
|
|
101
109
|
const review = scope.reviewCopiesOf
|
|
@@ -129,6 +137,40 @@ export function selectOrphans(rows, cwds, scope) {
|
|
|
129
137
|
}
|
|
130
138
|
return [...hit].sort((a, b) => a - b);
|
|
131
139
|
}
|
|
140
|
+
const DEVICE_PROGRAMS = new Set(['emulator', 'netsimd', 'launchd_sim']);
|
|
141
|
+
export function isDeviceProcess(command) {
|
|
142
|
+
const program = command.trim().split(/\s+/)[0] ?? '';
|
|
143
|
+
const name = basename(program);
|
|
144
|
+
if (DEVICE_PROGRAMS.has(name))
|
|
145
|
+
return true;
|
|
146
|
+
if (/^(?:qemu-system-|emulator64-)/.test(name))
|
|
147
|
+
return true;
|
|
148
|
+
if (name === 'crashpad_handler' && /\/emulator\//.test(program))
|
|
149
|
+
return true;
|
|
150
|
+
if (name === 'adb' && /\s(?:fork-server|server|start-server)\b/.test(command))
|
|
151
|
+
return true;
|
|
152
|
+
return /\/CoreSimulator[./]|\/Simulator\.app\//.test(program);
|
|
153
|
+
}
|
|
154
|
+
export function deviceProcesses(rows) {
|
|
155
|
+
const spared = new Set(rows.filter((r) => isDeviceProcess(r.command)).map((r) => r.pid));
|
|
156
|
+
const children = new Map();
|
|
157
|
+
for (const r of rows) {
|
|
158
|
+
const list = children.get(r.ppid) ?? [];
|
|
159
|
+
list.push(r.pid);
|
|
160
|
+
children.set(r.ppid, list);
|
|
161
|
+
}
|
|
162
|
+
const queue = [...spared];
|
|
163
|
+
while (queue.length) {
|
|
164
|
+
const pid = queue.shift();
|
|
165
|
+
for (const child of children.get(pid) ?? []) {
|
|
166
|
+
if (spared.has(child))
|
|
167
|
+
continue;
|
|
168
|
+
spared.add(child);
|
|
169
|
+
queue.push(child);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return spared;
|
|
173
|
+
}
|
|
132
174
|
export function isAlive(pid) {
|
|
133
175
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
134
176
|
return false;
|
|
@@ -161,10 +203,19 @@ export async function killOrphans(scope, opts = {}) {
|
|
|
161
203
|
return result;
|
|
162
204
|
const groups = await groupsStillOurs(scope.groups ?? [], rows);
|
|
163
205
|
const select = { ...scope, groups };
|
|
206
|
+
const devices = deviceProcesses(rows);
|
|
207
|
+
const holdsDevice = new Set(rows.filter((r) => devices.has(r.pid)).map((r) => r.pgid));
|
|
164
208
|
for (const g of groups)
|
|
165
|
-
|
|
209
|
+
if (!holdsDevice.has(g))
|
|
210
|
+
signal(-g, 'SIGTERM');
|
|
166
211
|
const cwds = await workingDirs(rows.map((r) => r.pid));
|
|
167
212
|
const pids = selectOrphans(rows, cwds, select);
|
|
213
|
+
const wouldStop = new Set(selectOrphans(rows, cwds, { ...select, spareDevices: false }));
|
|
214
|
+
const kept = rows.filter((r) => wouldStop.has(r.pid) && isDeviceProcess(r.command));
|
|
215
|
+
if (kept.length > 0) {
|
|
216
|
+
opts.log?.(`left ${kept.map((r) => `${programOf(r.command)} (${r.pid})`).join(', ')} running: ` +
|
|
217
|
+
'a device belongs to the machine and other sessions may be using it, so a run never stops it');
|
|
218
|
+
}
|
|
168
219
|
const byPid = new Map(rows.map((r) => [r.pid, r]));
|
|
169
220
|
for (const pid of pids) {
|
|
170
221
|
signal(pid, 'SIGTERM');
|
|
@@ -202,7 +253,7 @@ export async function killOrphans(scope, opts = {}) {
|
|
|
202
253
|
export function reviewCopiesOf(worktree) {
|
|
203
254
|
const base = basename(worktree);
|
|
204
255
|
const out = new Set();
|
|
205
|
-
for (const dir of new Set([tmpdir(), '/tmp'])) {
|
|
256
|
+
for (const dir of new Set([tmpdir(), '/tmp', ...workRoots()])) {
|
|
206
257
|
let names;
|
|
207
258
|
try {
|
|
208
259
|
names = readdirSync(dir);
|
|
@@ -229,7 +280,48 @@ export function signalEngineGroups(sig) {
|
|
|
229
280
|
if (process.platform === 'win32')
|
|
230
281
|
return 0;
|
|
231
282
|
for (const g of engineGroups)
|
|
232
|
-
|
|
283
|
+
signalGroupSparingDevices(g, sig);
|
|
233
284
|
return engineGroups.size;
|
|
234
285
|
}
|
|
286
|
+
function listProcessesNow() {
|
|
287
|
+
try {
|
|
288
|
+
const out = execFileSync('ps', ['-A', '-ww', '-o', 'pid=,ppid=,pgid=,command='], {
|
|
289
|
+
encoding: 'utf8',
|
|
290
|
+
timeout: 10_000,
|
|
291
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
292
|
+
});
|
|
293
|
+
return parseProcesses(out);
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
return [];
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
export function signalGroupSparingDevices(pgid, sig) {
|
|
300
|
+
if (!(pgid > 1))
|
|
301
|
+
return false;
|
|
302
|
+
const rows = listProcessesNow();
|
|
303
|
+
const devices = deviceProcesses(rows);
|
|
304
|
+
const members = rows.filter((r) => r.pgid === pgid);
|
|
305
|
+
if (!members.some((r) => devices.has(r.pid))) {
|
|
306
|
+
try {
|
|
307
|
+
process.kill(-pgid, sig);
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
let any = false;
|
|
315
|
+
for (const r of members) {
|
|
316
|
+
if (devices.has(r.pid))
|
|
317
|
+
continue;
|
|
318
|
+
try {
|
|
319
|
+
process.kill(r.pid, sig);
|
|
320
|
+
any = true;
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return any;
|
|
326
|
+
}
|
|
235
327
|
//# sourceMappingURL=orphans.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Phase = 'plan' | 'work';
|
|
2
|
+
export declare function phaseOf(job: {
|
|
3
|
+
planFirst?: boolean;
|
|
4
|
+
planApproved?: boolean;
|
|
5
|
+
parkStep?: {
|
|
6
|
+
kind: string;
|
|
7
|
+
} | null;
|
|
8
|
+
}): Phase;
|
|
9
|
+
export declare function planPhaseBrief(round: number, note?: string | null): string;
|
|
10
|
+
export declare function planGoBrief(steps: readonly string[], by: string | null): string;
|
|
11
|
+
export declare function changedWhilePlanning(worktree: string): Promise<number | null>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { exec } from '../exec.js';
|
|
2
|
+
export function phaseOf(job) {
|
|
3
|
+
if (job.planFirst !== true)
|
|
4
|
+
return 'work';
|
|
5
|
+
if (job.planApproved === true)
|
|
6
|
+
return 'work';
|
|
7
|
+
if (job.parkStep?.kind === 'plan_go')
|
|
8
|
+
return 'work';
|
|
9
|
+
return 'plan';
|
|
10
|
+
}
|
|
11
|
+
export function planPhaseBrief(round, note) {
|
|
12
|
+
return [
|
|
13
|
+
`## Plan first — you are PLANNING (round ${round})`,
|
|
14
|
+
'A person approves this plan before any work is done. In this session:',
|
|
15
|
+
'- Read what you need to understand the task. Change NOTHING: no file edits, no commits, no installs that write into the checkout.',
|
|
16
|
+
'- Then call report_plan on the "firefunc" MCP server with the plan\'s steps — short titles in plain words, in order, no code — and an optional one-paragraph summary.',
|
|
17
|
+
'- Then end your session with one line saying the plan is waiting for approval.',
|
|
18
|
+
...(note
|
|
19
|
+
? [
|
|
20
|
+
'',
|
|
21
|
+
'A person looked at your earlier plan and asked for changes. Their note:',
|
|
22
|
+
'',
|
|
23
|
+
note.trim(),
|
|
24
|
+
'',
|
|
25
|
+
'Plan again with that in mind, and report the new plan.',
|
|
26
|
+
]
|
|
27
|
+
: []),
|
|
28
|
+
].join('\n');
|
|
29
|
+
}
|
|
30
|
+
export function planGoBrief(steps, by) {
|
|
31
|
+
return [
|
|
32
|
+
`${by ?? 'A person'} approved your plan. Now do the work, in this same checkout, following it:`,
|
|
33
|
+
...steps.map((s, i) => `${i + 1}. ${s}`),
|
|
34
|
+
'',
|
|
35
|
+
'Do not call report_plan again. When you finish, end as the task asks.',
|
|
36
|
+
].join('\n');
|
|
37
|
+
}
|
|
38
|
+
export async function changedWhilePlanning(worktree) {
|
|
39
|
+
const r = await exec('git', ['-C', worktree, 'status', '--porcelain'], {
|
|
40
|
+
timeoutMs: 60_000,
|
|
41
|
+
}).catch(() => null);
|
|
42
|
+
if (!r || r.code !== 0)
|
|
43
|
+
return null;
|
|
44
|
+
return r.stdout.split('\n').filter((l) => l.trim()).length;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
package/dist/pool.d.ts
CHANGED
package/dist/pool.js
CHANGED
|
@@ -5,7 +5,11 @@ export async function runJobPool(deps) {
|
|
|
5
5
|
const maxIdleMs = Math.max(baseIdleMs, deps.maxIdleDelayMs ?? 8_000);
|
|
6
6
|
let emptyClaims = 0;
|
|
7
7
|
const idleDelay = () => Math.min(maxIdleMs, baseIdleMs * 2 ** Math.min(emptyClaims, 10));
|
|
8
|
-
const cap = () =>
|
|
8
|
+
const cap = () => {
|
|
9
|
+
const n = Math.floor(typeof deps.maxParallel === 'function' ? deps.maxParallel() : deps.maxParallel);
|
|
10
|
+
return Number.isFinite(n) ? Math.max(0, n) : 1;
|
|
11
|
+
};
|
|
12
|
+
let drainedTold = false;
|
|
9
13
|
const active = new Set();
|
|
10
14
|
const now = deps.now ?? (() => Date.now());
|
|
11
15
|
const heartbeatMs = deps.heartbeatMs ?? 30_000;
|
|
@@ -58,9 +62,30 @@ export async function runJobPool(deps) {
|
|
|
58
62
|
}
|
|
59
63
|
continue;
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
const limit = cap();
|
|
66
|
+
if (limit === 0) {
|
|
67
|
+
if (active.size === 0 && !drainedTold) {
|
|
68
|
+
drainedTold = true;
|
|
69
|
+
deps.onDrained?.();
|
|
70
|
+
}
|
|
71
|
+
if (deps.heartbeat) {
|
|
72
|
+
await beat({ draining: true, paused: false });
|
|
73
|
+
await napUntilBeat();
|
|
74
|
+
}
|
|
75
|
+
else if (active.size > 0) {
|
|
76
|
+
await Promise.race([...active, sleep(idleDelay())]);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
await sleep(idleDelay());
|
|
80
|
+
}
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
drainedTold = false;
|
|
84
|
+
if (active.size >= limit) {
|
|
85
|
+
if (deps.heartbeat) {
|
|
86
|
+
await beat({ draining: false, paused: false });
|
|
87
|
+
await napUntilBeat();
|
|
88
|
+
}
|
|
64
89
|
else
|
|
65
90
|
await Promise.race(active);
|
|
66
91
|
continue;
|
package/dist/pr-title.d.ts
CHANGED
|
@@ -9,3 +9,18 @@ export declare function pullRequestTitle(job: {
|
|
|
9
9
|
export declare function pullRequestBody(kind: ChangeKind, engineName: string, externalId: string | null, opts?: {
|
|
10
10
|
continuesBranch?: boolean;
|
|
11
11
|
}): string;
|
|
12
|
+
export declare const AGENT_PR_FILE = ".firefunc/pull-request.md";
|
|
13
|
+
export declare function parseAgentPullRequest(text: string): {
|
|
14
|
+
title: string;
|
|
15
|
+
body: string;
|
|
16
|
+
} | null;
|
|
17
|
+
export declare function provenanceTrailers(job: {
|
|
18
|
+
provenance?: {
|
|
19
|
+
trailers?: string[];
|
|
20
|
+
} | null;
|
|
21
|
+
}): string | null;
|
|
22
|
+
export declare function withProvenanceFooter(body: string, job: {
|
|
23
|
+
provenance?: {
|
|
24
|
+
prFooter?: string | null;
|
|
25
|
+
} | null;
|
|
26
|
+
}): string;
|
package/dist/pr-title.js
CHANGED
|
@@ -60,4 +60,37 @@ export function pullRequestBody(kind, engineName, externalId, opts = {}) {
|
|
|
60
60
|
: `Automated fix by FireFunc (self-hosted ${engineName} runner) for ${externalId ?? 'a reported bug'}.`;
|
|
61
61
|
return `${what}\n\nReview before merging.`;
|
|
62
62
|
}
|
|
63
|
+
export const AGENT_PR_FILE = '.firefunc/pull-request.md';
|
|
64
|
+
export function parseAgentPullRequest(text) {
|
|
65
|
+
const lines = text.replace(/\r\n?/g, '\n').split('\n');
|
|
66
|
+
const i = lines.findIndex((l) => l.trim() !== '');
|
|
67
|
+
if (i < 0)
|
|
68
|
+
return null;
|
|
69
|
+
const title = lines[i].replace(/^#+\s*/, '')
|
|
70
|
+
.trim()
|
|
71
|
+
.slice(0, 256);
|
|
72
|
+
if (!title)
|
|
73
|
+
return null;
|
|
74
|
+
const body = lines
|
|
75
|
+
.slice(i + 1)
|
|
76
|
+
.join('\n')
|
|
77
|
+
.trim()
|
|
78
|
+
.slice(0, 60_000);
|
|
79
|
+
return { title, body };
|
|
80
|
+
}
|
|
81
|
+
export function provenanceTrailers(job) {
|
|
82
|
+
const lines = (job.provenance?.trailers ?? [])
|
|
83
|
+
.filter((t) => typeof t === 'string')
|
|
84
|
+
.map((t) => t.replace(/[\r\n]+/g, ' ').trim())
|
|
85
|
+
.filter((t) => /^[A-Za-z][\w-]{0,40}: \S.{0,300}$/.test(t))
|
|
86
|
+
.slice(0, 5);
|
|
87
|
+
return lines.length ? lines.join('\n') : null;
|
|
88
|
+
}
|
|
89
|
+
export function withProvenanceFooter(body, job) {
|
|
90
|
+
const footer = job.provenance?.prFooter
|
|
91
|
+
?.replace(/[\r\n]+/g, ' ')
|
|
92
|
+
.trim()
|
|
93
|
+
.slice(0, 500);
|
|
94
|
+
return footer ? `${body.trimEnd()}\n\n${footer}` : body;
|
|
95
|
+
}
|
|
63
96
|
//# sourceMappingURL=pr-title.js.map
|
package/dist/recover.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { RunnerApi } from './api.js';
|
|
2
|
-
|
|
2
|
+
import { type HeldRun } from './held.js';
|
|
3
|
+
export declare function lostSentence(machine: string, kept?: boolean): string;
|
|
4
|
+
export declare function keepLostSession(runnerDir: string, rec: HeldRun, now?: number): boolean;
|
|
3
5
|
export type RecoverDeps = {
|
|
4
6
|
runnerDir: string;
|
|
5
7
|
api: Pick<RunnerApi, 'result' | 'probe'>;
|
package/dist/recover.js
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
import { existsSync, rmSync } from 'node:fs';
|
|
2
2
|
import { basename } from 'node:path';
|
|
3
|
-
import { keptWorktrees } from './cut.js';
|
|
3
|
+
import { keepUntil, keptWorktrees, saveCut } from './cut.js';
|
|
4
4
|
import { heldByGoneProcesses, releaseHeld } from './held.js';
|
|
5
5
|
import { isNetworkError, withNetworkRetry } from './network.js';
|
|
6
6
|
import { killOrphans, reviewCopiesOf } from './orphans.js';
|
|
7
7
|
import { listPendingResults, savePendingResult } from './pending.js';
|
|
8
8
|
import { canonicalPath, removeRunnerWorktree } from './worktrees.js';
|
|
9
|
-
export function lostSentence(machine) {
|
|
9
|
+
export function lostSentence(machine, kept = false) {
|
|
10
10
|
return (`The attempt did not finish: the runner on ${machine} stopped while it was running — ` +
|
|
11
11
|
'the runner process was restarted, stopped or crashed — and the process that took over ' +
|
|
12
12
|
'does not hold it, so nothing more will be reported for it. What it left running on the ' +
|
|
13
|
-
|
|
13
|
+
(kept
|
|
14
|
+
? 'machine was stopped; its worktree and the engine’s session are kept on this machine for a day, so Re-run continues it from where it stopped.'
|
|
15
|
+
: 'machine was stopped and its worktree removed. Re-run the task.'));
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
export function keepLostSession(runnerDir, rec, now = Date.now()) {
|
|
18
|
+
if (!rec.resume || !rec.worktree || !existsSync(rec.worktree))
|
|
19
|
+
return false;
|
|
20
|
+
const cutAt = now;
|
|
21
|
+
return saveCut(runnerDir, {
|
|
22
|
+
...rec.resume,
|
|
23
|
+
runId: rec.runId,
|
|
24
|
+
worktree: rec.worktree,
|
|
25
|
+
resetsAt: null,
|
|
26
|
+
cutAt: new Date(cutAt).toISOString(),
|
|
27
|
+
keepUntil: keepUntil(null, cutAt),
|
|
28
|
+
reason: 'lost',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function clearUp(rec, keep, log, keepSession) {
|
|
16
32
|
const roots = [rec.worktree, ...(rec.scratch ?? [])].filter((p) => !!p);
|
|
17
|
-
const kept = rec.worktree ? keep.has(canonicalPath(rec.worktree)) : false;
|
|
33
|
+
const kept = keepSession || (rec.worktree ? keep.has(canonicalPath(rec.worktree)) : false);
|
|
18
34
|
const copies = rec.worktree ? reviewCopiesOf(rec.worktree) : [];
|
|
19
35
|
await killOrphans({
|
|
20
36
|
roots: [...roots, ...copies],
|
|
@@ -64,11 +80,15 @@ export async function recoverPreviousProcess(deps) {
|
|
|
64
80
|
let offline = false;
|
|
65
81
|
for (const rec of gone) {
|
|
66
82
|
try {
|
|
67
|
-
|
|
83
|
+
const keptSession = !pending.has(rec.runId) && keepLostSession(deps.runnerDir, rec);
|
|
84
|
+
if (keptSession) {
|
|
85
|
+
deps.log(`kept run ${rec.runId}'s worktree and session for the task's next run here (${rec.worktree})`);
|
|
86
|
+
}
|
|
87
|
+
await clearUp(rec, keep, deps.log, keptSession);
|
|
68
88
|
if (!pending.has(rec.runId)) {
|
|
69
89
|
const payload = {
|
|
70
90
|
status: 'failed',
|
|
71
|
-
error: lostSentence(deps.machine),
|
|
91
|
+
error: lostSentence(deps.machine, keptSession),
|
|
72
92
|
lost: true,
|
|
73
93
|
};
|
|
74
94
|
try {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { WrittenSkills } from './skills.js';
|
|
2
|
+
export declare const REFERENCE_FOLDER = ".firefunc/reference";
|
|
3
|
+
export type ReferenceToWrite = {
|
|
4
|
+
name: string;
|
|
5
|
+
size: number;
|
|
6
|
+
sha256: string;
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
export type WrittenReferences = WrittenSkills & {
|
|
10
|
+
names: string[];
|
|
11
|
+
skipped: Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
why: string;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
export declare function safeReferenceName(name: string): boolean;
|
|
17
|
+
export declare function downloadReference(f: ReferenceToWrite, fetcher?: typeof fetch): Promise<{
|
|
18
|
+
bytes: Buffer;
|
|
19
|
+
} | {
|
|
20
|
+
why: string;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function writeReferenceFiles(worktree: string, files: readonly ReferenceToWrite[] | null | undefined, log: (m: string) => void, download?: (f: ReferenceToWrite) => Promise<{
|
|
23
|
+
bytes: Buffer;
|
|
24
|
+
} | {
|
|
25
|
+
why: string;
|
|
26
|
+
}>): Promise<WrittenReferences>;
|
|
27
|
+
export declare function mergeWritten(a: WrittenSkills, b: WrittenSkills): WrittenSkills;
|