@firefunc-agent/runner 0.9.14 → 0.9.35
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 +184 -10
- package/dist/alive.d.ts +40 -0
- package/dist/alive.js +138 -0
- package/dist/api-fallback.d.ts +4 -2
- package/dist/api-fallback.js +26 -1
- package/dist/api.d.ts +66 -3
- package/dist/api.js +164 -3
- package/dist/brief-file.d.ts +15 -0
- package/dist/brief-file.js +36 -0
- package/dist/brief.d.ts +3 -0
- package/dist/brief.js +14 -4
- 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 +39 -0
- package/dist/config.js +23 -0
- package/dist/cut.d.ts +1 -1
- package/dist/cut.js +13 -3
- package/dist/daemon.js +364 -15
- 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.d.ts +2 -0
- package/dist/engines/antigravity.js +74 -4
- package/dist/engines/claude.js +22 -9
- 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/automations.d.ts +2 -0
- package/dist/firefunc/automations.js +290 -0
- 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 +34 -2
- 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 +15 -0
- package/dist/git-auth.js +39 -1
- package/dist/held.d.ts +3 -0
- package/dist/job.d.ts +26 -3
- package/dist/job.js +763 -152
- package/dist/keep-awake.d.ts +17 -0
- package/dist/keep-awake.js +90 -0
- package/dist/keep-local.d.ts +1 -1
- package/dist/keep-local.js +5 -3
- package/dist/limit.d.ts +9 -1
- package/dist/limit.js +260 -3
- package/dist/local-checks.d.ts +19 -0
- package/dist/local-checks.js +79 -0
- package/dist/locks.d.ts +18 -1
- package/dist/locks.js +249 -69
- 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 +48 -4
- package/dist/network.js +3 -2
- package/dist/openrouter.d.ts +15 -0
- package/dist/openrouter.js +39 -0
- package/dist/orphans.d.ts +4 -0
- package/dist/orphans.js +96 -4
- package/dist/pool.d.ts +1 -0
- package/dist/pool.js +25 -2
- package/dist/pr-title.d.ts +10 -0
- package/dist/pr-title.js +15 -0
- package/dist/recover.d.ts +3 -1
- package/dist/recover.js +27 -7
- 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 +5 -0
- package/dist/run-attachments.js +14 -9
- 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 +5 -0
- package/dist/secret-scan.js +30 -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 +42 -0
- package/dist/sign-in.js +243 -0
- package/dist/tool-call.d.ts +59 -0
- package/dist/tool-call.js +375 -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 +22 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type TransportState = {
|
|
2
|
+
failingSince: string | null;
|
|
3
|
+
failures: number;
|
|
4
|
+
lastError: string | null;
|
|
5
|
+
rebuilds: number;
|
|
6
|
+
lastRebuildAt: string | null;
|
|
7
|
+
};
|
|
8
|
+
export type TransportDeps = {
|
|
9
|
+
rebuild: () => boolean;
|
|
10
|
+
now: () => number;
|
|
11
|
+
log: (line: string) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare function isTransportFailure(err: unknown): boolean;
|
|
14
|
+
export declare function describeTransportError(err: unknown): string;
|
|
15
|
+
export declare function rebuildGlobalDispatcher(graceMs?: number): boolean;
|
|
16
|
+
export declare class TransportWatchdog {
|
|
17
|
+
private readonly threshold;
|
|
18
|
+
private readonly deps;
|
|
19
|
+
private readonly state;
|
|
20
|
+
constructor(threshold: number, deps: TransportDeps);
|
|
21
|
+
ok(): void;
|
|
22
|
+
failed(err: unknown): boolean;
|
|
23
|
+
snapshot(): TransportState;
|
|
24
|
+
}
|
|
25
|
+
export declare function backoffAfterFailure(backoffMs: number, rebuilt: boolean, rebuildsThisOutage: number): number;
|
|
26
|
+
export declare const TRANSPORT_REBUILD_AFTER = 3;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { isNetworkError } from './network.js';
|
|
2
|
+
const GLOBAL_DISPATCHER = Symbol.for('undici.globalDispatcher.1');
|
|
3
|
+
export function isTransportFailure(err) {
|
|
4
|
+
if (err instanceof Error && (err.name === 'AbortError' || err.name === 'TimeoutError')) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (isNetworkError(err))
|
|
8
|
+
return true;
|
|
9
|
+
const code = causeCode(err);
|
|
10
|
+
return !!code && /^(?:UND_ERR_|ECONN|EPIPE|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|EHOST|ENET)/.test(code);
|
|
11
|
+
}
|
|
12
|
+
function causeCode(err) {
|
|
13
|
+
const cause = err?.cause;
|
|
14
|
+
if (!cause)
|
|
15
|
+
return null;
|
|
16
|
+
if (typeof cause.code === 'string')
|
|
17
|
+
return cause.code;
|
|
18
|
+
const first = Array.isArray(cause.errors) ? cause.errors[0]?.code : undefined;
|
|
19
|
+
return typeof first === 'string' ? first : null;
|
|
20
|
+
}
|
|
21
|
+
export function describeTransportError(err) {
|
|
22
|
+
const msg = err instanceof Error ? err.message : String(err ?? 'unknown error');
|
|
23
|
+
const code = causeCode(err);
|
|
24
|
+
const causeMsg = err?.cause?.message;
|
|
25
|
+
const under = code ?? (typeof causeMsg === 'string' && causeMsg ? causeMsg : null);
|
|
26
|
+
const text = under && !msg.includes(under) ? `${msg} (${under})` : msg;
|
|
27
|
+
return text.length > 200 ? `${text.slice(0, 199)}…` : text;
|
|
28
|
+
}
|
|
29
|
+
export function rebuildGlobalDispatcher(graceMs = 30_000) {
|
|
30
|
+
const g = globalThis;
|
|
31
|
+
const old = g[GLOBAL_DISPATCHER];
|
|
32
|
+
if (!old || typeof old.constructor !== 'function')
|
|
33
|
+
return false;
|
|
34
|
+
let next;
|
|
35
|
+
try {
|
|
36
|
+
next = new old.constructor();
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
g[GLOBAL_DISPATCHER] = next;
|
|
42
|
+
try {
|
|
43
|
+
void Promise.resolve(old.close?.()).catch(() => { });
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
}
|
|
47
|
+
const t = setTimeout(() => {
|
|
48
|
+
try {
|
|
49
|
+
void Promise.resolve(old.destroy?.()).catch(() => { });
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
}
|
|
53
|
+
}, graceMs);
|
|
54
|
+
t.unref?.();
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
export class TransportWatchdog {
|
|
58
|
+
threshold;
|
|
59
|
+
deps;
|
|
60
|
+
state = {
|
|
61
|
+
failingSince: null,
|
|
62
|
+
failures: 0,
|
|
63
|
+
lastError: null,
|
|
64
|
+
rebuilds: 0,
|
|
65
|
+
lastRebuildAt: null,
|
|
66
|
+
};
|
|
67
|
+
constructor(threshold, deps) {
|
|
68
|
+
this.threshold = threshold;
|
|
69
|
+
this.deps = deps;
|
|
70
|
+
if (!Number.isInteger(threshold) || threshold < 1) {
|
|
71
|
+
throw new Error(`transport watchdog threshold must be a positive integer (got ${threshold})`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
ok() {
|
|
75
|
+
if (this.state.failures > 0) {
|
|
76
|
+
const since = this.state.failingSince ? Date.parse(this.state.failingSince) : NaN;
|
|
77
|
+
const mins = Number.isNaN(since) ? null : Math.round((this.deps.now() - since) / 60_000);
|
|
78
|
+
this.deps.log(`FireFunc reachable again after ${this.state.failures} failed poll${this.state.failures === 1 ? '' : 's'}` +
|
|
79
|
+
(mins !== null ? ` (${mins} min)` : '') +
|
|
80
|
+
(this.state.rebuilds > 0
|
|
81
|
+
? `; the connection was rebuilt ${this.state.rebuilds} time${this.state.rebuilds === 1 ? '' : 's'}`
|
|
82
|
+
: ''));
|
|
83
|
+
}
|
|
84
|
+
this.state.failures = 0;
|
|
85
|
+
this.state.failingSince = null;
|
|
86
|
+
this.state.lastError = null;
|
|
87
|
+
this.state.rebuilds = 0;
|
|
88
|
+
}
|
|
89
|
+
failed(err) {
|
|
90
|
+
if (!isTransportFailure(err))
|
|
91
|
+
return false;
|
|
92
|
+
const at = new Date(this.deps.now()).toISOString();
|
|
93
|
+
if (this.state.failures === 0)
|
|
94
|
+
this.state.failingSince = at;
|
|
95
|
+
this.state.failures += 1;
|
|
96
|
+
this.state.lastError = describeTransportError(err);
|
|
97
|
+
if (this.state.failures % this.threshold !== 0)
|
|
98
|
+
return false;
|
|
99
|
+
const replaced = this.deps.rebuild();
|
|
100
|
+
if (replaced) {
|
|
101
|
+
this.state.rebuilds += 1;
|
|
102
|
+
this.state.lastRebuildAt = at;
|
|
103
|
+
this.deps.log(`${this.state.failures} polls in a row failed (${this.state.lastError}) — dropped the HTTP connections and reconnecting with a fresh client`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
this.deps.log(`${this.state.failures} polls in a row failed (${this.state.lastError}) — the HTTP client could not be rebuilt here; if this continues while FireFunc answers elsewhere, restart the runner (firefunc-runner stop, then firefunc-runner start-service)`);
|
|
107
|
+
}
|
|
108
|
+
return replaced;
|
|
109
|
+
}
|
|
110
|
+
snapshot() {
|
|
111
|
+
return { ...this.state };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function backoffAfterFailure(backoffMs, rebuilt, rebuildsThisOutage) {
|
|
115
|
+
return rebuilt && rebuildsThisOutage === 1 ? 2_000 : backoffMs;
|
|
116
|
+
}
|
|
117
|
+
export const TRANSPORT_REBUILD_AFTER = 3;
|
|
118
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function setWorkDir(dir: string | null | undefined): void;
|
|
2
|
+
export declare function workDir(): string | null;
|
|
3
|
+
export declare function workRoot(): string;
|
|
4
|
+
export declare function workDirFailure(): string | null;
|
|
5
|
+
export declare function workDirProblem(): string | null;
|
|
6
|
+
export declare function workRoots(): string[];
|
|
7
|
+
export declare function workTempEnv(): Record<string, string>;
|
|
8
|
+
export declare function workDirWords(dir: string | undefined, disk: (dir: string) => {
|
|
9
|
+
freeBytes: number;
|
|
10
|
+
totalBytes: number;
|
|
11
|
+
} | null, problem?: string | null): string;
|
package/dist/work-dir.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
let configured = null;
|
|
5
|
+
let problem = null;
|
|
6
|
+
export function setWorkDir(dir) {
|
|
7
|
+
configured = typeof dir === 'string' && dir.trim() ? dir.trim() : null;
|
|
8
|
+
problem = null;
|
|
9
|
+
}
|
|
10
|
+
export function workDir() {
|
|
11
|
+
return configured;
|
|
12
|
+
}
|
|
13
|
+
export function workRoot() {
|
|
14
|
+
if (!configured)
|
|
15
|
+
return tmpdir();
|
|
16
|
+
try {
|
|
17
|
+
mkdirSync(configured, { recursive: true });
|
|
18
|
+
problem = null;
|
|
19
|
+
return configured;
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
problem = err instanceof Error ? err.message : String(err);
|
|
23
|
+
return tmpdir();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function workDirFailure() {
|
|
27
|
+
if (!configured)
|
|
28
|
+
return null;
|
|
29
|
+
workRoot();
|
|
30
|
+
return problem;
|
|
31
|
+
}
|
|
32
|
+
export function workDirProblem() {
|
|
33
|
+
const why = workDirFailure();
|
|
34
|
+
return why
|
|
35
|
+
? `the work folder ${configured} cannot be made (${why}), so runs work in the OS temp folder ${tmpdir()} instead. Fix: connect the drive or pick a folder this user can write, with connect --work-dir <dir>.`
|
|
36
|
+
: null;
|
|
37
|
+
}
|
|
38
|
+
export function workRoots() {
|
|
39
|
+
const roots = [tmpdir()];
|
|
40
|
+
if (configured)
|
|
41
|
+
roots.push(configured, join(configured, 'tmp'));
|
|
42
|
+
return [...new Set(roots)];
|
|
43
|
+
}
|
|
44
|
+
export function workTempEnv() {
|
|
45
|
+
if (!configured)
|
|
46
|
+
return {};
|
|
47
|
+
const tmp = join(configured, 'tmp');
|
|
48
|
+
try {
|
|
49
|
+
mkdirSync(tmp, { recursive: true });
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
return { TMPDIR: tmp, TEMP: tmp, TMP: tmp };
|
|
55
|
+
}
|
|
56
|
+
export function workDirWords(dir, disk, problem = null) {
|
|
57
|
+
const where = dir?.trim() ? dir.trim() : tmpdir();
|
|
58
|
+
if (dir?.trim() && problem) {
|
|
59
|
+
const t = disk(tmpdir());
|
|
60
|
+
const tFree = t ? `${(t.freeBytes / 1024 ** 3).toFixed(1)} GB free` : 'free space unknown';
|
|
61
|
+
return `${where} cannot be made (${problem}) — runs work in ${tmpdir()} (${tFree}) instead; connect the drive or set another with connect --work-dir <dir>`;
|
|
62
|
+
}
|
|
63
|
+
const d = disk(where);
|
|
64
|
+
const free = d ? `${(d.freeBytes / 1024 ** 3).toFixed(1)} GB free` : 'free space unknown';
|
|
65
|
+
return dir?.trim()
|
|
66
|
+
? `${where} (${free}) — worktrees and the engine's temp folder`
|
|
67
|
+
: `${where} (${free}) — the OS temp folder; set one with connect --work-dir <dir>`;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=work-dir.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type WorktreeState = 'live' | 'kept' | 'gone';
|
|
2
|
+
export type WorktreeReport = {
|
|
3
|
+
path: string;
|
|
4
|
+
state: WorktreeState;
|
|
5
|
+
};
|
|
6
|
+
export declare function worktreeReport(path: string | null | undefined, state: WorktreeState): WorktreeReport | null;
|
|
7
|
+
export declare function endedState(path: string, kept: boolean): 'kept' | 'gone';
|
|
8
|
+
export declare function reportWorktree(api: {
|
|
9
|
+
event: (runId: string, event: 'worktree', detail?: Record<string, unknown>) => Promise<void>;
|
|
10
|
+
}, runId: string, path: string | null | undefined, state: WorktreeState): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute } from 'node:path';
|
|
3
|
+
export function worktreeReport(path, state) {
|
|
4
|
+
if (!path || !isAbsolute(path) || path.length > 1024)
|
|
5
|
+
return null;
|
|
6
|
+
return { path, state };
|
|
7
|
+
}
|
|
8
|
+
export function endedState(path, kept) {
|
|
9
|
+
return kept && existsSync(path) ? 'kept' : 'gone';
|
|
10
|
+
}
|
|
11
|
+
export async function reportWorktree(api, runId, path, state) {
|
|
12
|
+
const detail = worktreeReport(path, state);
|
|
13
|
+
if (!detail)
|
|
14
|
+
return;
|
|
15
|
+
await api.event(runId, 'worktree', detail).catch(() => { });
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=worktree-report.js.map
|
package/dist/worktrees.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export declare function canonicalPath(path: string): string;
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function canonicalPathOn(path: string, platform: NodeJS.Platform): string;
|
|
3
|
+
export declare function isRunnerWorktree(path: string, opts?: {
|
|
4
|
+
platform?: NodeJS.Platform;
|
|
5
|
+
tmp?: string;
|
|
6
|
+
roots?: readonly string[];
|
|
7
|
+
}): boolean;
|
|
3
8
|
export type WorktreeEntry = {
|
|
4
9
|
path: string;
|
|
5
10
|
branch?: string;
|
|
@@ -7,6 +12,16 @@ export type WorktreeEntry = {
|
|
|
7
12
|
};
|
|
8
13
|
export declare function worktreesOf(checkout: string): Promise<WorktreeEntry[]>;
|
|
9
14
|
export declare function staleHolder(stderr: string): string | null;
|
|
15
|
+
export type BranchHolder = {
|
|
16
|
+
kind: 'live';
|
|
17
|
+
runId: string | null;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'kept';
|
|
20
|
+
runId: string;
|
|
21
|
+
parked: boolean;
|
|
22
|
+
};
|
|
23
|
+
export declare function branchHolderOf(runnerDir: string, worktree: string): BranchHolder | null;
|
|
24
|
+
export declare function branchHeldSentence(branch: string, holder: BranchHolder): string;
|
|
10
25
|
export declare function removeRunnerWorktree(checkout: string, path: string, log: (line: string) => void): Promise<void>;
|
|
11
26
|
export declare function sweepLeftoverWorktrees(checkouts: string[], opts: {
|
|
12
27
|
live: Set<string>;
|
package/dist/worktrees.js
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
|
-
import {
|
|
3
|
+
import { workRoots } from './work-dir.js';
|
|
4
|
+
import { basename } from 'node:path';
|
|
4
5
|
import { exec } from './exec.js';
|
|
5
|
-
import { killOrphans, reviewCopiesOf } from './orphans.js';
|
|
6
|
+
import { isAlive, killOrphans, reviewCopiesOf } from './orphans.js';
|
|
7
|
+
import { listHeld } from './held.js';
|
|
8
|
+
import { listKept } from './ask-first.js';
|
|
6
9
|
const RUNNER_WORKTREE_NAME = /^firefunc-[A-Za-z0-9]{6}$/;
|
|
7
|
-
function tempRoots() {
|
|
8
|
-
const t = tmpdir().replace(/\/+$/, '');
|
|
9
|
-
const out = new Set([t]);
|
|
10
|
-
if (t.startsWith('/private/'))
|
|
11
|
-
out.add(t.slice('/private'.length));
|
|
12
|
-
else if (t.startsWith('/var/'))
|
|
13
|
-
out.add(`/private${t}`);
|
|
14
|
-
out.add('/tmp');
|
|
15
|
-
out.add('/private/tmp');
|
|
16
|
-
return out;
|
|
17
|
-
}
|
|
18
10
|
export function canonicalPath(path) {
|
|
19
|
-
|
|
11
|
+
return canonicalPathOn(path, process.platform);
|
|
12
|
+
}
|
|
13
|
+
export function canonicalPathOn(path, platform) {
|
|
14
|
+
let clean = path;
|
|
15
|
+
if (platform === 'win32')
|
|
16
|
+
clean = clean.replace(/\\/g, '/').toLowerCase();
|
|
17
|
+
clean = clean.replace(/\/+$/, '');
|
|
20
18
|
return /^\/private\/(?:var|tmp)(?:\/|$)/.test(clean) ? clean.slice('/private'.length) : clean;
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
function tempRoots(platform, tmp, extra) {
|
|
21
|
+
return new Set([
|
|
22
|
+
canonicalPathOn(tmp, platform),
|
|
23
|
+
'/tmp',
|
|
24
|
+
...extra.map((d) => canonicalPathOn(d, platform)),
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
export function isRunnerWorktree(path, opts = {}) {
|
|
28
|
+
const platform = opts.platform ?? process.platform;
|
|
29
|
+
const clean = canonicalPathOn(path, platform);
|
|
30
|
+
const cut = clean.lastIndexOf('/');
|
|
31
|
+
if (cut < 0)
|
|
32
|
+
return false;
|
|
33
|
+
const name = path
|
|
34
|
+
.replace(/[\\/]+$/, '')
|
|
35
|
+
.split(/[\\/]/)
|
|
36
|
+
.pop() ?? '';
|
|
37
|
+
return (RUNNER_WORKTREE_NAME.test(name) &&
|
|
38
|
+
tempRoots(platform, opts.tmp ?? tmpdir(), opts.roots ?? workRoots()).has(clean.slice(0, cut)));
|
|
25
39
|
}
|
|
26
40
|
export async function worktreesOf(checkout) {
|
|
27
41
|
const r = await exec('git', ['-C', checkout, 'worktree', 'list', '--porcelain'], {
|
|
@@ -50,6 +64,37 @@ export function staleHolder(stderr) {
|
|
|
50
64
|
const path = m?.[1];
|
|
51
65
|
return path && isRunnerWorktree(path) ? path : null;
|
|
52
66
|
}
|
|
67
|
+
export function branchHolderOf(runnerDir, worktree) {
|
|
68
|
+
const path = canonicalPath(worktree);
|
|
69
|
+
for (const r of listHeld(runnerDir)) {
|
|
70
|
+
if (!isAlive(r.pid))
|
|
71
|
+
continue;
|
|
72
|
+
const mine = [r.worktree, ...(r.scratch ?? [])].some((p) => p && canonicalPath(p) === path);
|
|
73
|
+
if (mine)
|
|
74
|
+
return { kind: 'live', runId: r.runId };
|
|
75
|
+
}
|
|
76
|
+
for (const k of listKept(runnerDir)) {
|
|
77
|
+
if (canonicalPath(k.worktree) === path) {
|
|
78
|
+
return { kind: 'kept', runId: k.runId, parked: !!k.park };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
export function branchHeldSentence(branch, holder) {
|
|
84
|
+
return `git worktree add failed: ${heldWords(branch, holder)}`;
|
|
85
|
+
}
|
|
86
|
+
function heldWords(branch, holder) {
|
|
87
|
+
const which = holder.runId ? ` (run ${holder.runId.slice(0, 8)})` : '';
|
|
88
|
+
if (holder.kind === 'live') {
|
|
89
|
+
return (`another run on this machine${which} is still working on ${branch}, so this attempt could not start beside it. Nothing was changed. ` +
|
|
90
|
+
'Fix: wait for that run to finish, or stop it on its task page, then Re-run this task.');
|
|
91
|
+
}
|
|
92
|
+
return holder.parked
|
|
93
|
+
? `${branch} is held on this machine by a run waiting for a person's answer${which}, so this attempt could not start. Nothing was changed. ` +
|
|
94
|
+
'Fix: answer or stop that run on its task page, then Re-run this task.'
|
|
95
|
+
: `${branch} is held on this machine by a change kept for a person's approval${which}, so this attempt could not start. Nothing was changed. ` +
|
|
96
|
+
'Fix: approve, reject or ask for changes on that task, then Re-run this task.';
|
|
97
|
+
}
|
|
53
98
|
export async function removeRunnerWorktree(checkout, path, log) {
|
|
54
99
|
const copies = reviewCopiesOf(path);
|
|
55
100
|
await killOrphans({ roots: [path, ...copies], reviewCopiesOf: basename(path) }, { log }).catch(() => { });
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firefunc-agent/runner",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.35",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "FireFunc self-hosted runner — an always-on daemon that runs YOUR local coding agent (Claude Code, Codex, Gemini CLI, Cursor CLI) on work FireFunc routes to it, opens pull requests, and reports back. Your machine, your subscriptions.",
|
|
6
|
+
"description": "FireFunc self-hosted runner — an always-on daemon that runs YOUR local coding agent (Claude Code, Codex, Gemini CLI, Cursor CLI, Copilot CLI, Antigravity) on work FireFunc routes to it, opens pull requests, and reports back. Your machine, your subscriptions.",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"firefunc",
|
|
9
9
|
"runner",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
],
|
|
18
18
|
"license": "SEE LICENSE IN LICENSE",
|
|
19
19
|
"bin": {
|
|
20
|
-
"firefunc-runner": "
|
|
21
|
-
"firefunc": "
|
|
20
|
+
"firefunc-runner": "dist/cli.js",
|
|
21
|
+
"firefunc": "dist/firefunc/cli.js"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
package/skill/firefunc/SKILL.md
CHANGED
|
@@ -23,9 +23,10 @@ with a composer link; the person opens it, reviews the agent and activates it.
|
|
|
23
23
|
in 0.9.1; if npm still installs an older one, those are not on npm yet.
|
|
24
24
|
Tell the person that, rather than retrying.
|
|
25
25
|
2. Check the sign-in: `firefunc whoami --json`.
|
|
26
|
-
- `not_signed_in`: ask the person to
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
- `not_signed_in`: ask the person to run `firefunc login` **in their own
|
|
27
|
+
terminal**. It opens FireFunc in their browser, where they pick the workspace
|
|
28
|
+
and press Allow (runner 0.9.26; on an older one it asks for a workspace key
|
|
29
|
+
from Settings → API keys, without showing it).
|
|
29
30
|
3. Read the `scopes` in that answer. `agents:read` lets you look,
|
|
30
31
|
`agents:write` lets you create and edit drafts, `tasks:write` starts tasks,
|
|
31
32
|
`tasks:read` reads them, `agents:activate` lets the key activate an agent,
|
|
@@ -226,3 +227,21 @@ for an agent that reads and reports, that is the work), `verdict` (`{id, word}`,
|
|
|
226
227
|
only for an agent that declares verdicts) and `findings` (one line each, with a
|
|
227
228
|
severity). Each is null or empty when nothing was recorded; say so rather than
|
|
228
229
|
guessing. Quote the answer as it came.
|
|
230
|
+
|
|
231
|
+
## Workflows and orchestrations
|
|
232
|
+
|
|
233
|
+
An automation chains steps (a workflow) or roles (an orchestration). It is made as a DRAFT and
|
|
234
|
+
does nothing until it is published:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
firefunc automations templates --json # what to start from, and the agents each brings
|
|
238
|
+
firefunc automations create --name "Error to fix" --from-template tpl-incident-fix --project "Payments" --json
|
|
239
|
+
firefunc automations check <id> --json # the checks behind Publish, each with its fix
|
|
240
|
+
firefunc automations run <id> --mode dry --watch --json # a dry run starts nothing and writes nothing
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Publishing makes it live at once: a tool trigger takes the next real event. Ask the person first,
|
|
244
|
+
naming what starts it and its project, then `firefunc automations publish <id> --yes --json`. The
|
|
245
|
+
answer says where it went live (`goesLive`) and the agents a run would wait at (`heldAgents`: a
|
|
246
|
+
template's agents arrive paused). Start one by hand with `firefunc automations run <id> --watch`;
|
|
247
|
+
read a run with `firefunc automations run-get <run id>`.
|