@firefunc-agent/runner 0.9.5 → 0.9.7
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 +18 -15
- package/dist/api.d.ts +26 -1
- package/dist/api.js +6 -1
- package/dist/ask-first.d.ts +51 -0
- package/dist/ask-first.js +126 -0
- package/dist/build-info.json +2 -2
- package/dist/cli.js +16 -1
- package/dist/cut.d.ts +1 -0
- package/dist/cut.js +7 -0
- package/dist/daemon.js +62 -50
- package/dist/engine-watch.d.ts +26 -0
- package/dist/engine-watch.js +85 -0
- package/dist/engines/claude.js +26 -0
- package/dist/engines/copilot.js +3 -2
- package/dist/engines/index.d.ts +1 -1
- package/dist/engines/types.d.ts +13 -0
- package/dist/firefunc/agents.js +8 -2
- package/dist/firefunc/tasks.js +20 -1
- package/dist/job.d.ts +2 -0
- package/dist/job.js +954 -797
- package/dist/keep-local.js +41 -3
- package/dist/unattended.d.ts +14 -0
- package/dist/unattended.js +37 -0
- package/package.json +1 -1
- package/skill/firefunc/SKILL.md +3 -3
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ That's it. When your QA files a bug (labeled for FireFunc), it appears here with
|
|
|
57
57
|
- Refuses to push a commit that contains a `.env` file or the run's MCP config, whatever the agent committed.
|
|
58
58
|
- Writes the agent's skills to `.claude/skills/<slug>/SKILL.md` and keeps them out of every commit **by their real path** (0.9.1+): when the repository keeps `.claude/skills` as a link into a folder it tracks (`.claude/skills -> ../.agents/skills`), the skill lands in that folder and is kept out there — by a `.gitignore` inside each skill folder (that worktree only; your clone's `.git/info/exclude` is not written), in what the runner stages, and at the push, which is refused if the agent committed one anyway. A folder already in the checkout under the same name — in any case, on a disk that ignores case — is never written into (the run sees the repository's, and the log names it), and a link that leads out of the checkout is refused: nothing is written outside the worktree. Runners before 0.9.1 appended `.claude/skills/` to your clone's `.git/info/exclude`; that line can be deleted.
|
|
59
59
|
- Runs Claude with `--permission-mode bypassPermissions` (the default; override with `permissionMode` in the config or per job) **without** `--dangerously-skip-permissions`, which hangs non-interactive daemons. Note what that mode means: the agent is not asked to confirm anything, so the bounds that matter are the ones passed alongside it — `--disallowedTools` for every tool the chain withheld, and `--strict-mcp-config` so the run's servers are the ones FireFunc chose rather than whatever the machine happens to have.
|
|
60
|
+
- **Claims no work an engine cannot run here** (0.9.6). Claude Code refuses that mode as root or under sudo — the default user of most containers — and exits before doing anything, so a runner started as root used to fail every run it claimed. The runner now asks at start (and whenever it finds a newly installed CLI) whether each engine can run unattended as its user: one that cannot is not offered to FireFunc, which hands this machine none of its work, the log and `firefunc-runner status` say why with the fix, and the Machines page in FireFunc shows it too. A run that reaches it anyway is answered at once, without starting the engine, as the machine not being ready — not as the task's failure. The fix: run the runner as a normal user.
|
|
60
61
|
- A per-job timeout (default 20 min) prevents a stuck run from hanging the daemon. An agent's own time budget (FireFunc sends it as `maxMinutes`, 0.9.3) is honoured under the `jobTimeoutMinutes` you set, and in its place when you set none; the engine is told how long it has.
|
|
61
62
|
- **Nothing a session starts outlives its job** (0.9.3). The engine runs in a process group of its own, and before the worktree is removed — however the job ended — the runner stops that group and every process whose working directory or command line is inside the worktree, its scratch folders or the review skills' `ff-review-*-<checkout>` copies of it, with their descendants; the copies are removed with the worktree. A session's backgrounded test run can no longer go on for hours in a deleted directory.
|
|
62
63
|
- **Cleans up after a stopped runner, and only after itself** (0.9.3). Each run it claims is written to `held/` in its folder; the next process to start reports the runs a gone process held as lost (so FireFunc can run them again at once), stops what they left running and removes their worktrees. At start, and whenever `git worktree add` finds one of its own leftover worktrees still holding the run's branch, it removes that worktree and tries once more. Only its own — `<temp>/firefunc-XXXXXX` — never yours.
|
|
@@ -68,17 +69,17 @@ That's it. When your QA files a bug (labeled for FireFunc), it appears here with
|
|
|
68
69
|
|
|
69
70
|
## Commands
|
|
70
71
|
|
|
71
|
-
| Command | What it does
|
|
72
|
-
| ----------------------------------------- |
|
|
73
|
-
| `firefunc-runner connect <token> [flags]` | Save your token + settings (`~/.firefunc-runner/config.json`, mode 0600)
|
|
74
|
-
| `firefunc-runner install` | Install as a background service — starts at login/boot, restarts on crash
|
|
75
|
-
| `firefunc-runner start` | Run in THIS terminal (stops when you close it) — for watching it work
|
|
76
|
-
| `firefunc-runner stop` | Stop the background service (stays stopped)
|
|
77
|
-
| `firefunc-runner start-service` | Start the background service again
|
|
78
|
-
| `firefunc-runner logs` | Recent runner output
|
|
79
|
-
| `firefunc-runner uninstall` | Remove the background service
|
|
80
|
-
| `firefunc-runner status` | Saved config
|
|
81
|
-
| `firefunc-runner --version` | The version this build carries — the one it reports to FireFunc (`-v`)
|
|
72
|
+
| Command | What it does |
|
|
73
|
+
| ----------------------------------------- | -------------------------------------------------------------------------- |
|
|
74
|
+
| `firefunc-runner connect <token> [flags]` | Save your token + settings (`~/.firefunc-runner/config.json`, mode 0600) |
|
|
75
|
+
| `firefunc-runner install` | Install as a background service — starts at login/boot, restarts on crash |
|
|
76
|
+
| `firefunc-runner start` | Run in THIS terminal (stops when you close it) — for watching it work |
|
|
77
|
+
| `firefunc-runner stop` | Stop the background service (stays stopped) |
|
|
78
|
+
| `firefunc-runner start-service` | Start the background service again |
|
|
79
|
+
| `firefunc-runner logs` | Recent runner output |
|
|
80
|
+
| `firefunc-runner uninstall` | Remove the background service |
|
|
81
|
+
| `firefunc-runner status` | Saved config, whether each engine can run unattended here, and the service |
|
|
82
|
+
| `firefunc-runner --version` | The version this build carries — the one it reports to FireFunc (`-v`) |
|
|
82
83
|
|
|
83
84
|
### `connect` flags
|
|
84
85
|
|
|
@@ -150,7 +151,7 @@ find their own logins). If you install a new agent CLI somewhere new, re-run
|
|
|
150
151
|
|
|
151
152
|
FireFunc never clones, fetches or stores your repository. The change goes from this
|
|
152
153
|
machine to **your** repository on GitHub — the push and the draft pull request — and
|
|
153
|
-
nowhere else. This is everything runner **0.9.
|
|
154
|
+
nowhere else. This is everything runner **0.9.6** sends to the FireFunc API you connected
|
|
154
155
|
it to:
|
|
155
156
|
|
|
156
157
|
**While it waits for work** (`POST /channel/claim`, every few seconds): its version,
|
|
@@ -162,9 +163,11 @@ the MCP servers this machine is signed in to — names, states, expiries and whi
|
|
|
162
163
|
holds each (the runner's own or Claude Code's), never a token. From 0.9.3 also: the ids of
|
|
163
164
|
the runs it holds (working on, or keeping a result for), the ids of runs the runner process
|
|
164
165
|
before it held and lost, and the plan limits it is waiting out (engine and reset time).
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
From 0.9.6 also: the engines installed here that cannot run unattended as the runner's user,
|
|
167
|
+
each with a word for why (`blockedEngines`, e.g. Claude Code and `runs_as_root`).
|
|
168
|
+
While it is finishing its runs before stopping, waiting out a plan limit on every engine
|
|
169
|
+
it has, or has no engine that can run unattended, the same request goes every 30 seconds as
|
|
170
|
+
a heartbeat that asks for no work (`heartbeat`, and `draining` while it stops).
|
|
168
171
|
|
|
169
172
|
**While a run works** (`/channel/runs/<id>/events` and `/activity`): the stage it is at
|
|
170
173
|
(`cloning`, `fixing`, `pushing`, `pr_opened`, a heartbeat every five minutes) with the
|
package/dist/api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ChangeSummary } from './ask-first.js';
|
|
1
2
|
import type { RunUsage } from './usage.js';
|
|
2
3
|
export type ClaimedJob = {
|
|
3
4
|
runId: string;
|
|
@@ -8,6 +9,14 @@ export type ClaimedJob = {
|
|
|
8
9
|
toolsOnly?: boolean;
|
|
9
10
|
continuesBranch?: boolean;
|
|
10
11
|
review?: boolean;
|
|
12
|
+
askFirst?: boolean;
|
|
13
|
+
askFirstStep?: {
|
|
14
|
+
kind: 'publish';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'revise';
|
|
17
|
+
note: string;
|
|
18
|
+
round: number;
|
|
19
|
+
};
|
|
11
20
|
baseBranch?: string | null;
|
|
12
21
|
externalId: string | null;
|
|
13
22
|
title: string | null;
|
|
@@ -39,6 +48,10 @@ export type PlanLimitReport = {
|
|
|
39
48
|
export type EngineLimitReport = PlanLimitReport & {
|
|
40
49
|
engine: string;
|
|
41
50
|
};
|
|
51
|
+
export type MachineLimitReport = {
|
|
52
|
+
kind: 'machine';
|
|
53
|
+
detail: string;
|
|
54
|
+
};
|
|
42
55
|
export type SecretScanReport = {
|
|
43
56
|
scanned: true;
|
|
44
57
|
hits: Array<{
|
|
@@ -64,10 +77,15 @@ export type ResultPayload = ({
|
|
|
64
77
|
} | {
|
|
65
78
|
status: 'failed';
|
|
66
79
|
error: string;
|
|
80
|
+
} | {
|
|
81
|
+
status: 'awaiting_approval';
|
|
82
|
+
changes: ChangeSummary;
|
|
83
|
+
head: string;
|
|
84
|
+
summary?: string;
|
|
67
85
|
}) & {
|
|
68
86
|
secretScan?: SecretScanReport;
|
|
69
87
|
usage?: RunUsage;
|
|
70
|
-
limit?: PlanLimitReport;
|
|
88
|
+
limit?: PlanLimitReport | MachineLimitReport;
|
|
71
89
|
readHead?: string;
|
|
72
90
|
openCommandAtEnd?: true;
|
|
73
91
|
lost?: true;
|
|
@@ -110,6 +128,13 @@ export declare class RunnerApi {
|
|
|
110
128
|
heartbeat?: true;
|
|
111
129
|
draining?: true;
|
|
112
130
|
limits?: EngineLimitReport[];
|
|
131
|
+
blockedEngines?: Array<{
|
|
132
|
+
engine: string;
|
|
133
|
+
code: string;
|
|
134
|
+
}>;
|
|
135
|
+
awaitingRuns?: string[];
|
|
136
|
+
}, opts?: {
|
|
137
|
+
onDiscard?: (runIds: string[]) => void;
|
|
113
138
|
}): Promise<ClaimedJob | null>;
|
|
114
139
|
repos(): Promise<string[]>;
|
|
115
140
|
probe(): Promise<boolean>;
|
package/dist/api.js
CHANGED
|
@@ -66,7 +66,7 @@ export class RunnerApi {
|
|
|
66
66
|
headers() {
|
|
67
67
|
return { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' };
|
|
68
68
|
}
|
|
69
|
-
async claim(meta) {
|
|
69
|
+
async claim(meta, opts = {}) {
|
|
70
70
|
const ctrl = new AbortController();
|
|
71
71
|
const timer = setTimeout(() => ctrl.abort(), 35_000);
|
|
72
72
|
try {
|
|
@@ -83,6 +83,11 @@ export class RunnerApi {
|
|
|
83
83
|
if (!res.ok)
|
|
84
84
|
throw new Error(`claim failed: ${res.status}`);
|
|
85
85
|
const body = (await res.json());
|
|
86
|
+
if (Array.isArray(body.discard) && opts.onDiscard) {
|
|
87
|
+
const ids = body.discard.filter((x) => typeof x === 'string');
|
|
88
|
+
if (ids.length > 0)
|
|
89
|
+
opts.onDiscard(ids);
|
|
90
|
+
}
|
|
86
91
|
return body.job ?? null;
|
|
87
92
|
}
|
|
88
93
|
finally {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { RunUsage } from './usage.js';
|
|
2
|
+
import type { WrittenSkills } from './skills.js';
|
|
3
|
+
import type { ChangeKind } from './pr-title.js';
|
|
4
|
+
export type KeptChange = {
|
|
5
|
+
runId: string;
|
|
6
|
+
workItemId: string;
|
|
7
|
+
engine: string;
|
|
8
|
+
sessionId: string | null;
|
|
9
|
+
repo: string;
|
|
10
|
+
branch: string;
|
|
11
|
+
base: string;
|
|
12
|
+
worktree: string;
|
|
13
|
+
repoPath: string | null;
|
|
14
|
+
continuesBranch: boolean;
|
|
15
|
+
readHead?: string;
|
|
16
|
+
head: string;
|
|
17
|
+
round: number;
|
|
18
|
+
title: string;
|
|
19
|
+
kind: ChangeKind;
|
|
20
|
+
summary: string | null;
|
|
21
|
+
keptAt: string;
|
|
22
|
+
keepUntil: string;
|
|
23
|
+
writtenSkills?: WrittenSkills;
|
|
24
|
+
attemptUsage?: RunUsage;
|
|
25
|
+
sessionReport?: RunUsage;
|
|
26
|
+
};
|
|
27
|
+
export declare const KEEP_DAYS = 15;
|
|
28
|
+
export declare function keptDir(runnerDir: string): string;
|
|
29
|
+
export declare function keepUntilFrom(at: number): string;
|
|
30
|
+
export declare function saveKept(runnerDir: string, rec: KeptChange): boolean;
|
|
31
|
+
export declare function listKept(runnerDir: string): KeptChange[];
|
|
32
|
+
export declare function keptFor(runnerDir: string, runId: string): KeptChange | null;
|
|
33
|
+
export declare function dropKept(runnerDir: string, runId: string): void;
|
|
34
|
+
export declare function keptRunIds(runnerDir: string): string[];
|
|
35
|
+
export declare function keptChangeWorktrees(runnerDir: string): Set<string>;
|
|
36
|
+
export declare function expiredKept(runnerDir: string, now?: number): KeptChange[];
|
|
37
|
+
export type ChangeSummary = {
|
|
38
|
+
files: Array<{
|
|
39
|
+
path: string;
|
|
40
|
+
added: number | null;
|
|
41
|
+
removed: number | null;
|
|
42
|
+
}>;
|
|
43
|
+
filesChanged: number;
|
|
44
|
+
added: number;
|
|
45
|
+
removed: number;
|
|
46
|
+
truncated: boolean;
|
|
47
|
+
};
|
|
48
|
+
export declare const FILES_MAX = 300;
|
|
49
|
+
export declare function parseNumstat(out: string): ChangeSummary;
|
|
50
|
+
export declare function changesOf(worktree: string, from: string, branch: string): Promise<ChangeSummary | null>;
|
|
51
|
+
export declare function reviseBrief(note: string, round: number): string;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { exec } from './exec.js';
|
|
4
|
+
const DAY = 86_400_000;
|
|
5
|
+
export const KEEP_DAYS = 15;
|
|
6
|
+
const RUN_ID = /^[A-Za-z0-9][A-Za-z0-9-]{3,79}$/;
|
|
7
|
+
export function keptDir(runnerDir) {
|
|
8
|
+
return join(runnerDir, 'kept');
|
|
9
|
+
}
|
|
10
|
+
function fileFor(runnerDir, runId) {
|
|
11
|
+
return typeof runId === 'string' && RUN_ID.test(runId)
|
|
12
|
+
? join(keptDir(runnerDir), `${runId}.json`)
|
|
13
|
+
: null;
|
|
14
|
+
}
|
|
15
|
+
export function keepUntilFrom(at) {
|
|
16
|
+
return new Date(at + KEEP_DAYS * DAY).toISOString();
|
|
17
|
+
}
|
|
18
|
+
export function saveKept(runnerDir, rec) {
|
|
19
|
+
const file = fileFor(runnerDir, rec.runId);
|
|
20
|
+
if (!file)
|
|
21
|
+
return false;
|
|
22
|
+
try {
|
|
23
|
+
mkdirSync(keptDir(runnerDir), { recursive: true, mode: 0o700 });
|
|
24
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
25
|
+
writeFileSync(tmp, `${JSON.stringify(rec, null, 2)}\n`, { mode: 0o600 });
|
|
26
|
+
renameSync(tmp, file);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function listKept(runnerDir) {
|
|
34
|
+
const dir = keptDir(runnerDir);
|
|
35
|
+
if (!existsSync(dir))
|
|
36
|
+
return [];
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const name of readdirSync(dir)) {
|
|
39
|
+
if (!name.endsWith('.json'))
|
|
40
|
+
continue;
|
|
41
|
+
try {
|
|
42
|
+
const rec = JSON.parse(readFileSync(join(dir, name), 'utf8'));
|
|
43
|
+
if (rec &&
|
|
44
|
+
typeof rec.runId === 'string' &&
|
|
45
|
+
typeof rec.worktree === 'string' &&
|
|
46
|
+
typeof rec.branch === 'string' &&
|
|
47
|
+
typeof rec.head === 'string' &&
|
|
48
|
+
typeof rec.keepUntil === 'string') {
|
|
49
|
+
out.push(rec);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
export function keptFor(runnerDir, runId) {
|
|
58
|
+
const file = fileFor(runnerDir, runId);
|
|
59
|
+
if (!file || !existsSync(file))
|
|
60
|
+
return null;
|
|
61
|
+
return listKept(runnerDir).find((k) => k.runId === runId) ?? null;
|
|
62
|
+
}
|
|
63
|
+
export function dropKept(runnerDir, runId) {
|
|
64
|
+
const file = fileFor(runnerDir, runId);
|
|
65
|
+
if (!file)
|
|
66
|
+
return;
|
|
67
|
+
try {
|
|
68
|
+
unlinkSync(file);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function keptRunIds(runnerDir) {
|
|
74
|
+
return listKept(runnerDir)
|
|
75
|
+
.map((k) => k.runId)
|
|
76
|
+
.sort();
|
|
77
|
+
}
|
|
78
|
+
export function keptChangeWorktrees(runnerDir) {
|
|
79
|
+
return new Set(listKept(runnerDir).map((k) => k.worktree));
|
|
80
|
+
}
|
|
81
|
+
export function expiredKept(runnerDir, now = Date.now()) {
|
|
82
|
+
return listKept(runnerDir).filter((k) => Date.parse(k.keepUntil) <= now);
|
|
83
|
+
}
|
|
84
|
+
export const FILES_MAX = 300;
|
|
85
|
+
export function parseNumstat(out) {
|
|
86
|
+
const files = [];
|
|
87
|
+
let added = 0;
|
|
88
|
+
let removed = 0;
|
|
89
|
+
let count = 0;
|
|
90
|
+
for (const entry of out.split('\0')) {
|
|
91
|
+
const m = /^(-|\d+)\t(-|\d+)\t([\s\S]+)$/.exec(entry.replace(/^\n+/, ''));
|
|
92
|
+
if (!m)
|
|
93
|
+
continue;
|
|
94
|
+
count += 1;
|
|
95
|
+
const a = m[1] === '-' ? null : Number(m[1]);
|
|
96
|
+
const r = m[2] === '-' ? null : Number(m[2]);
|
|
97
|
+
added += a ?? 0;
|
|
98
|
+
removed += r ?? 0;
|
|
99
|
+
if (files.length < FILES_MAX)
|
|
100
|
+
files.push({ path: m[3].slice(0, 1024), added: a, removed: r });
|
|
101
|
+
}
|
|
102
|
+
return { files, filesChanged: count, added, removed, truncated: count > files.length };
|
|
103
|
+
}
|
|
104
|
+
export async function changesOf(worktree, from, branch) {
|
|
105
|
+
const r = await exec('git', [
|
|
106
|
+
'-C',
|
|
107
|
+
worktree,
|
|
108
|
+
'-c',
|
|
109
|
+
'core.quotepath=off',
|
|
110
|
+
'diff',
|
|
111
|
+
'--numstat',
|
|
112
|
+
'--no-renames',
|
|
113
|
+
'-z',
|
|
114
|
+
`${from}...refs/heads/${branch}`,
|
|
115
|
+
], { timeoutMs: 120_000 }).catch(() => null);
|
|
116
|
+
if (!r || r.code !== 0)
|
|
117
|
+
return null;
|
|
118
|
+
return parseNumstat(r.stdout);
|
|
119
|
+
}
|
|
120
|
+
export function reviseBrief(note, round) {
|
|
121
|
+
return (`A person looked at the change you made on this task and asked for changes before anything is pushed (round ${round}). ` +
|
|
122
|
+
`Their note:\n\n${note.trim()}\n\n` +
|
|
123
|
+
'Make those changes in this same checkout, on top of what you already did. Nothing has been pushed yet: ' +
|
|
124
|
+
'when you finish, the person is asked again.');
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=ask-first.js.map
|
package/dist/build-info.json
CHANGED
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,8 @@ import { startDaemon } from './daemon.js';
|
|
|
4
4
|
import { runBrief } from './brief.js';
|
|
5
5
|
import { runMcpList, runMcpLogin, runMcpLogout } from './mcp-login.js';
|
|
6
6
|
import { RUNNER_VERSION } from './version.js';
|
|
7
|
+
import { availableEngines, getAdapter } from './engines/index.js';
|
|
8
|
+
import { engineBlocks, unattendedContext } from './unattended.js';
|
|
7
9
|
import { currentPlatform, defaultServiceDeps, EPHEMERAL_INSTALL_MESSAGE, installService, isEphemeralInstall, readLogTail, renderLaunchdPlist, renderSystemdUnit, renderWindowsTaskXml, serviceStatus, servicePaths, startService, stopService, uninstallService, } from './service.js';
|
|
8
10
|
const HELP = `firefunc-runner — run YOUR local coding agent on work FireFunc routes to you.
|
|
9
11
|
(Claude Code, OpenAI Codex, Gemini CLI or Cursor CLI — whichever you have installed.)
|
|
@@ -18,7 +20,8 @@ Usage:
|
|
|
18
20
|
firefunc-runner start-service Start the background service again
|
|
19
21
|
firefunc-runner logs Show recent runner output
|
|
20
22
|
firefunc-runner uninstall Remove the background service
|
|
21
|
-
firefunc-runner status Show the saved config
|
|
23
|
+
firefunc-runner status Show the saved config, whether each engine can
|
|
24
|
+
run unattended here, and the service state
|
|
22
25
|
firefunc-runner mcp login <tool> Sign THIS machine in to a tool's MCP server
|
|
23
26
|
firefunc-runner mcp list Which MCP servers this machine is signed in to
|
|
24
27
|
firefunc-runner mcp logout <tool> Forget one MCP sign-in
|
|
@@ -304,6 +307,18 @@ async function main() {
|
|
|
304
307
|
` autoInstall:${cfg.autoInstall === false ? ' off' : ' on (when no setup)'}\n` +
|
|
305
308
|
` background:${cfg.backgroundCommands?.length ? ' ' + cfg.backgroundCommands.join(' ; ') : ' (none)'}\n` +
|
|
306
309
|
` envFile: ${cfg.envFile ?? '(none)'}\n`);
|
|
310
|
+
const installed = availableEngines(cfg);
|
|
311
|
+
const blocks = engineBlocks(installed, unattendedContext(cfg));
|
|
312
|
+
process.stdout.write(`\nengines: ${installed.length ? '' : 'none found on PATH — install one (e.g. claude), or set --claude-bin'}\n` +
|
|
313
|
+
installed
|
|
314
|
+
.map((e) => {
|
|
315
|
+
const b = blocks.find((x) => x.engine === e);
|
|
316
|
+
const name = getAdapter(e).displayName;
|
|
317
|
+
return b
|
|
318
|
+
? ` ${e}: CANNOT RUN UNATTENDED as this user — ${b.reason}\n Fix: ${b.fix}\n The runner claims no ${name} work until then.\n`
|
|
319
|
+
: ` ${e}: ready (${name})\n`;
|
|
320
|
+
})
|
|
321
|
+
.join(''));
|
|
307
322
|
const os = currentPlatform();
|
|
308
323
|
const deps = defaultServiceDeps('', os);
|
|
309
324
|
const svc = await serviceStatus(deps);
|
package/dist/cut.d.ts
CHANGED
|
@@ -42,4 +42,5 @@ export declare function cutFor(runnerDir: string, key: CutKey, now?: number): {
|
|
|
42
42
|
} | null;
|
|
43
43
|
export declare function expiredCuts(runnerDir: string, now?: number): CutSession[];
|
|
44
44
|
export declare function keptWorktrees(runnerDir: string): Set<string>;
|
|
45
|
+
export declare function cutWorktrees(runnerDir: string): Set<string>;
|
|
45
46
|
export declare function resumeAfterResetBrief(prompt: string, briefChanged: boolean): string;
|
package/dist/cut.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
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
|
+
import { keptChangeWorktrees } from './ask-first.js';
|
|
4
5
|
const DAY = 86_400_000;
|
|
5
6
|
const ITEM_ID = /^[A-Za-z0-9][A-Za-z0-9-]{3,79}$/;
|
|
6
7
|
export function cutDir(runnerDir) {
|
|
@@ -91,6 +92,12 @@ export function expiredCuts(runnerDir, now = Date.now()) {
|
|
|
91
92
|
return listCuts(runnerDir).filter((c) => Date.parse(c.keepUntil) <= now);
|
|
92
93
|
}
|
|
93
94
|
export function keptWorktrees(runnerDir) {
|
|
95
|
+
return new Set([
|
|
96
|
+
...listCuts(runnerDir).map((c) => c.worktree),
|
|
97
|
+
...keptChangeWorktrees(runnerDir),
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
export function cutWorktrees(runnerDir) {
|
|
94
101
|
return new Set(listCuts(runnerDir).map((c) => c.worktree));
|
|
95
102
|
}
|
|
96
103
|
export function resumeAfterResetBrief(prompt, briefChanged) {
|
package/dist/daemon.js
CHANGED
|
@@ -12,9 +12,12 @@ import { RUNNER_VERSION } from './version.js';
|
|
|
12
12
|
import { LimitGate } from './limit.js';
|
|
13
13
|
import { heldByLiveProcesses, liveWorktrees, recordHeld, releaseHeld } from './held.js';
|
|
14
14
|
import { recoverPreviousProcess } from './recover.js';
|
|
15
|
-
import { dropCut, expiredCuts, keptWorktrees } from './cut.js';
|
|
15
|
+
import { cutWorktrees, dropCut, expiredCuts, keptWorktrees } from './cut.js';
|
|
16
|
+
import { dropKept, expiredKept, keptFor, keptRunIds } from './ask-first.js';
|
|
16
17
|
import { removeRunnerWorktree, sweepLeftoverWorktrees } from './worktrees.js';
|
|
17
18
|
import { signalEngineGroups } from './orphans.js';
|
|
19
|
+
import { engineBlocks, unattendedContext } from './unattended.js';
|
|
20
|
+
import { claimPause, engineWatch } from './engine-watch.js';
|
|
18
21
|
function log(msg) {
|
|
19
22
|
console.log(`[firefunc-runner] ${new Date().toISOString()} ${msg}`);
|
|
20
23
|
}
|
|
@@ -34,10 +37,10 @@ export async function startDaemon(cfg) {
|
|
|
34
37
|
const rdir = runnerDir();
|
|
35
38
|
const machine = cfg.name ?? hostname();
|
|
36
39
|
const viewerPort = cfg.viewerEnabled === false ? null : (cfg.viewerPort ?? 8787);
|
|
37
|
-
const
|
|
38
|
-
const skipped = supportedEngines().filter((e) => !
|
|
39
|
-
if (
|
|
40
|
-
log(`engines available on this machine: ${
|
|
40
|
+
const installedEngines = availableEngines(cfg);
|
|
41
|
+
const skipped = supportedEngines().filter((e) => !installedEngines.includes(e));
|
|
42
|
+
if (installedEngines.length > 0) {
|
|
43
|
+
log(`engines available on this machine: ${installedEngines.join(', ')}`);
|
|
41
44
|
}
|
|
42
45
|
else {
|
|
43
46
|
log('WARNING: no engine CLI found on PATH — this runner cannot run jobs. Install "claude" (or set --claude-bin).');
|
|
@@ -45,35 +48,26 @@ export async function startDaemon(cfg) {
|
|
|
45
48
|
if (skipped.length > 0) {
|
|
46
49
|
log(`engines not installed (skipped): ${skipped.join(', ')} — install the CLI to enable them`);
|
|
47
50
|
}
|
|
51
|
+
const blocksOf = (installed) => engineBlocks(installed, unattendedContext(cfg));
|
|
52
|
+
const sayBlocked = (blocks) => {
|
|
53
|
+
for (const b of blocks) {
|
|
54
|
+
const name = getAdapter(b.engine).displayName;
|
|
55
|
+
log(`WARNING: ${name} cannot run unattended on this machine: ${b.reason} ${b.fix} Claiming no ${name} work until then.`);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const declared = engineWatch({
|
|
59
|
+
installed: installedEngines,
|
|
60
|
+
scan: () => availableEngines(cfg),
|
|
61
|
+
blocksOf,
|
|
62
|
+
log,
|
|
63
|
+
onNewlyBlocked: sayBlocked,
|
|
64
|
+
});
|
|
65
|
+
sayBlocked(declared.blocked);
|
|
48
66
|
const meta = {
|
|
49
67
|
version: RUNNER_VERSION,
|
|
50
68
|
hostname: hostname(),
|
|
51
69
|
platform: platform(),
|
|
52
70
|
viewerPort,
|
|
53
|
-
engines: declaredEngines,
|
|
54
|
-
};
|
|
55
|
-
const ENGINE_RESCAN_MS = 120_000;
|
|
56
|
-
let lastEngineScan = Date.now();
|
|
57
|
-
const rescanEngines = () => {
|
|
58
|
-
if (Date.now() - lastEngineScan < ENGINE_RESCAN_MS)
|
|
59
|
-
return;
|
|
60
|
-
lastEngineScan = Date.now();
|
|
61
|
-
let found;
|
|
62
|
-
try {
|
|
63
|
-
found = availableEngines(cfg);
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (found.join(',') === meta.engines.join(','))
|
|
69
|
-
return;
|
|
70
|
-
const added = found.filter((e) => !meta.engines.includes(e));
|
|
71
|
-
const gone = meta.engines.filter((e) => !found.includes(e));
|
|
72
|
-
meta.engines = found;
|
|
73
|
-
if (added.length)
|
|
74
|
-
log(`engines now available: ${added.join(', ')}`);
|
|
75
|
-
if (gone.length)
|
|
76
|
-
log(`engines no longer on PATH: ${gone.join(', ')}`);
|
|
77
71
|
};
|
|
78
72
|
let stopping = false;
|
|
79
73
|
const viewer = cfg.viewerEnabled === false
|
|
@@ -200,6 +194,33 @@ export async function startDaemon(cfg) {
|
|
|
200
194
|
};
|
|
201
195
|
await dropExpiredCuts().catch(() => { });
|
|
202
196
|
let lastCutSweep = Date.now();
|
|
197
|
+
const letGo = async (k, why) => {
|
|
198
|
+
if (holding.has(k.runId))
|
|
199
|
+
return;
|
|
200
|
+
log(`the change kept for ${k.runId} ${why} — removing it from this machine`);
|
|
201
|
+
if (!cutWorktrees(rdir).has(k.worktree)) {
|
|
202
|
+
if (k.repoPath && existsSync(k.repoPath)) {
|
|
203
|
+
await removeRunnerWorktree(k.repoPath, k.worktree, log).catch(() => { });
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
try {
|
|
207
|
+
rmSync(k.worktree, { recursive: true, force: true });
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
dropKept(rdir, k.runId);
|
|
214
|
+
};
|
|
215
|
+
const onDiscard = (runIds) => {
|
|
216
|
+
for (const id of runIds) {
|
|
217
|
+
const k = keptFor(rdir, id);
|
|
218
|
+
if (k)
|
|
219
|
+
void letGo(k, 'is no longer waiting in FireFunc');
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
for (const k of expiredKept(rdir))
|
|
223
|
+
await letGo(k, 'was not answered in time').catch(() => { });
|
|
203
224
|
try {
|
|
204
225
|
const checkouts = Object.values(cfg.repos ?? {}).filter((p) => existsSync(p));
|
|
205
226
|
const removed = await sweepLeftoverWorktrees(checkouts, {
|
|
@@ -214,26 +235,11 @@ export async function startDaemon(cfg) {
|
|
|
214
235
|
}
|
|
215
236
|
const gate = new LimitGate(LimitGate.fileIn(rdir));
|
|
216
237
|
const limitReports = () => gate.active().map((l) => ({ engine: l.engine, kind: 'plan', resetsAt: l.resetsAt }));
|
|
217
|
-
|
|
218
|
-
const paused = () => {
|
|
219
|
-
const engines = meta.engines.length > 0 ? meta.engines : ['claude_code'];
|
|
220
|
-
const spent = engines.map((e) => gate.isLimited(e));
|
|
221
|
-
const now = spent.every((l) => l !== null);
|
|
222
|
-
if (now && !wasPaused) {
|
|
223
|
-
const until = spent
|
|
224
|
-
.map((l) => l.until)
|
|
225
|
-
.sort()
|
|
226
|
-
.at(-1);
|
|
227
|
-
log(`the plan's usage limit is spent on every engine here — claiming no work until ${until}`);
|
|
228
|
-
}
|
|
229
|
-
else if (!now && wasPaused) {
|
|
230
|
-
log("the plan's usage limit has reset — claiming work again");
|
|
231
|
-
}
|
|
232
|
-
wasPaused = now;
|
|
233
|
-
return now;
|
|
234
|
-
};
|
|
238
|
+
const paused = claimPause({ watch: declared, isLimited: (e) => gate.isLimited(e), log });
|
|
235
239
|
const claimBody = (extra = {}) => ({
|
|
236
240
|
...meta,
|
|
241
|
+
engines: declared.engines,
|
|
242
|
+
blockedEngines: declared.blockedReport(),
|
|
237
243
|
maxParallel: effectiveMax(),
|
|
238
244
|
budget: budgets,
|
|
239
245
|
mcpLogins: logins.map((l) => ({
|
|
@@ -244,6 +250,7 @@ export async function startDaemon(cfg) {
|
|
|
244
250
|
expiresAt: l.expiresAt,
|
|
245
251
|
...(l.detail ? { detail: l.detail } : {}),
|
|
246
252
|
})),
|
|
253
|
+
awaitingRuns: keptRunIds(rdir),
|
|
247
254
|
...claimState({
|
|
248
255
|
holding: [...holding, ...heldByLiveProcesses(rdir)],
|
|
249
256
|
pending: pendingIds(),
|
|
@@ -274,7 +281,9 @@ export async function startDaemon(cfg) {
|
|
|
274
281
|
heartbeat: async ({ draining, paused: waitingOutLimit }) => {
|
|
275
282
|
if (waitingOutLimit && heartbeatIgnored)
|
|
276
283
|
return null;
|
|
277
|
-
const job = await api
|
|
284
|
+
const job = await api
|
|
285
|
+
.claim(claimBody({ heartbeat: true, draining }), { onDiscard })
|
|
286
|
+
.catch(() => null);
|
|
278
287
|
if (job) {
|
|
279
288
|
heartbeatIgnored = true;
|
|
280
289
|
log(`FireFunc handed ${job.runId} to a heartbeat — running it`);
|
|
@@ -286,12 +295,15 @@ export async function startDaemon(cfg) {
|
|
|
286
295
|
if (flushed && (flushed.delivered || flushed.refused)) {
|
|
287
296
|
log(`pending results: ${flushed.delivered} delivered, ${flushed.refused} refused, ${flushed.kept} kept`);
|
|
288
297
|
}
|
|
289
|
-
|
|
298
|
+
declared.rescan();
|
|
290
299
|
if (Date.now() - lastCutSweep > 10 * 60_000) {
|
|
291
300
|
lastCutSweep = Date.now();
|
|
292
301
|
await dropExpiredCuts().catch(() => { });
|
|
302
|
+
for (const k of expiredKept(rdir)) {
|
|
303
|
+
await letGo(k, 'was not answered in time').catch(() => { });
|
|
304
|
+
}
|
|
293
305
|
}
|
|
294
|
-
const job = await api.claim(claimBody());
|
|
306
|
+
const job = await api.claim(claimBody(), { onDiscard });
|
|
295
307
|
lostRuns = [];
|
|
296
308
|
backoffMs = 2_000;
|
|
297
309
|
return job;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { EngineId } from './engines/types.js';
|
|
2
|
+
import { blockedEnginesReport, type EngineBlock } from './unattended.js';
|
|
3
|
+
export declare const ENGINE_RESCAN_MS = 120000;
|
|
4
|
+
export type EngineWatch = {
|
|
5
|
+
readonly installed: EngineId[];
|
|
6
|
+
readonly blocked: EngineBlock[];
|
|
7
|
+
readonly engines: EngineId[];
|
|
8
|
+
blockedReport(): ReturnType<typeof blockedEnginesReport>;
|
|
9
|
+
rescan(): void;
|
|
10
|
+
};
|
|
11
|
+
export declare function engineWatch(deps: {
|
|
12
|
+
installed: EngineId[];
|
|
13
|
+
scan: () => EngineId[];
|
|
14
|
+
blocksOf: (installed: EngineId[]) => EngineBlock[];
|
|
15
|
+
now?: () => number;
|
|
16
|
+
everyMs?: number;
|
|
17
|
+
log?: (msg: string) => void;
|
|
18
|
+
onNewlyBlocked?: (blocks: EngineBlock[]) => void;
|
|
19
|
+
}): EngineWatch;
|
|
20
|
+
export declare function claimPause(deps: {
|
|
21
|
+
watch: Pick<EngineWatch, 'rescan' | 'engines' | 'blocked'>;
|
|
22
|
+
isLimited: (engine: string) => {
|
|
23
|
+
until: string;
|
|
24
|
+
} | null;
|
|
25
|
+
log: (msg: string) => void;
|
|
26
|
+
}): () => boolean;
|