@firefunc-agent/runner 0.9.0 → 0.9.3
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 +90 -28
- package/dist/activity.d.ts +4 -1
- package/dist/activity.js +94 -8
- package/dist/api.d.ts +24 -0
- package/dist/api.js +74 -5
- package/dist/brief.d.ts +5 -0
- package/dist/brief.js +21 -0
- package/dist/build-info.json +2 -2
- package/dist/cli.js +10 -2
- package/dist/config.d.ts +2 -0
- package/dist/cut.d.ts +45 -0
- package/dist/cut.js +105 -0
- package/dist/daemon.d.ts +16 -0
- package/dist/daemon.js +156 -35
- package/dist/declined.d.ts +11 -0
- package/dist/declined.js +27 -0
- package/dist/engines/claude.js +129 -1
- package/dist/engines/types.d.ts +10 -0
- package/dist/exec.d.ts +3 -0
- package/dist/exec.js +48 -5
- package/dist/firefunc/agents.js +59 -7
- package/dist/firefunc/client.d.ts +1 -0
- package/dist/firefunc/client.js +3 -0
- package/dist/firefunc/configure.d.ts +6 -0
- package/dist/firefunc/configure.js +409 -0
- package/dist/firefunc/main.js +45 -7
- package/dist/firefunc/output.js +4 -1
- package/dist/firefunc/version.js +2 -17
- package/dist/held.d.ts +18 -0
- package/dist/held.js +95 -0
- package/dist/job.d.ts +3 -0
- package/dist/job.js +437 -76
- package/dist/keep-local.d.ts +6 -1
- package/dist/keep-local.js +171 -4
- package/dist/limit.d.ts +30 -0
- package/dist/limit.js +258 -0
- package/dist/locks.d.ts +14 -0
- package/dist/locks.js +164 -0
- package/dist/mcp-proxy.d.ts +21 -0
- package/dist/mcp-proxy.js +180 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +31 -2
- package/dist/orphans.d.ts +40 -0
- package/dist/orphans.js +235 -0
- package/dist/pool.d.ts +7 -0
- package/dist/pool.js +57 -9
- package/dist/pr-title.d.ts +11 -0
- package/dist/pr-title.js +63 -0
- package/dist/recover.d.ts +10 -0
- package/dist/recover.js +104 -0
- package/dist/session-stream.d.ts +8 -1
- package/dist/session-stream.js +9 -1
- package/dist/skills.d.ts +11 -0
- package/dist/skills.js +164 -0
- package/dist/stopped.d.ts +3 -0
- package/dist/stopped.js +10 -0
- package/dist/usage.d.ts +49 -0
- package/dist/usage.js +389 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +17 -0
- package/dist/worktrees.d.ts +15 -0
- package/dist/worktrees.js +96 -0
- package/package.json +1 -1
- package/skill/firefunc/SKILL.md +57 -8
package/README.md
CHANGED
|
@@ -51,11 +51,20 @@ That's it. When your QA files a bug (labeled for FireFunc), it appears here with
|
|
|
51
51
|
|
|
52
52
|
- Works in a throwaway **git worktree** off a clean base — it **never touches your working tree or current branch**.
|
|
53
53
|
- Opens a PR **only when there's a real diff** (no phantom PRs).
|
|
54
|
+
- Titles the commit and the draft PR with **one** conventional prefix (0.9.2): `test:` when every path the change touches is a test (a test file, a test folder's content, a test runner's config — a reproducer's failing test, a test writer's suite), otherwise `fix:`. The `fix:`, `feat:`, `chore:`, `refactor:`, `docs:` and `test:` prefixes the task's title already carried are taken off first, so a pull request raised from a FireFunc pull request is never titled "fix: fix: …".
|
|
54
55
|
- Pushes a **deterministic branch** with `--force-with-lease`, so a duplicate dispatch converges to one PR. A run that revises an existing pull request (0.8.1+) starts from that pull request's own branch and pushes **without** force, so git refuses rather than replace commits pushed while it worked.
|
|
55
56
|
- **Scans what it is about to push for secrets, on this machine**, and refuses the push on a key, a token or a private key (0.8.3+) — see [The secret scan before a push](#the-secret-scan-before-a-push).
|
|
56
57
|
- Refuses to push a commit that contains a `.env` file or the run's MCP config, whatever the agent committed.
|
|
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.
|
|
57
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.
|
|
58
|
-
- A per-job timeout (default 20 min) prevents a stuck run from hanging the daemon.
|
|
60
|
+
- 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
|
+
- **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
|
+
- **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.
|
|
63
|
+
- **One heavy command at a time per repository** (0.9.3). Its own setup commands and dependency install take a per-repository lock (`locks/` in its folder), and the engine is offered `$FIREFUNC_HEAVY` — the brief asks it to run a whole-project build, type-check or test suite as `"$FIREFUNC_HEAVY" <command>` — which waits on the same lock. Sessions on different repositories are untouched. `heavyLock: false` in the config turns it off.
|
|
64
|
+
- **A plan's usage limit is not a failure** (0.9.3). When the engine's own closing report says its plan stopped it (Claude Code's "You've hit your session limit · resets 3:50am"), the attempt is reported as stopped by the plan's usage limit with the reset time, the runner claims no work for that engine until then (`limits.json` in its folder keeps that across a restart), and it keeps the session's worktree: when FireFunc runs the task again after the reset, the same session continues where it stopped (`--resume`) instead of starting over. A kept worktree is removed a day after its reset if the task never comes back.
|
|
65
|
+
- **A session that ends before its result comes is continued once** (0.9.3). A headless session ends with the agent's turn, and a test it moved to the background is stopped with it. The brief says so; and when the engine's own stream shows a command it started still running at the close — or its closing words only promise a later check ("Waiting on the admission run.") — the runner continues the same session once to get the result. A session that ends that way again is reported as unfinished: its closing words are not sent as its answer and nothing it changed is pushed.
|
|
66
|
+
- **The GitHub MCP token is renewed as the run goes on** (0.9.3). FireFunc's token for the GitHub MCP server lasts an hour, and runs last longer, so the engine reaches that server through a relay on 127.0.0.1 (a random port and key) which adds the token itself and renews it through FireFunc before it is 55 minutes old or when GitHub answers 401. The token is then never written into the worktree. `mcpRelay: false` in the config writes it into the run's MCP config as before.
|
|
67
|
+
- **Stopping finishes the runs in flight** (0.9.3). The first Ctrl-C or SIGTERM stops claiming and lets the runs finish — the machine keeps telling FireFunc it is alive and draining meanwhile, so it does not look offline; a second one stops their engines now, and each run reports how it ended. Under the background service, which is killed soon after its SIGTERM, the engines are stopped after ten seconds so every run can report first.
|
|
59
68
|
|
|
60
69
|
## Commands
|
|
61
70
|
|
|
@@ -69,6 +78,7 @@ That's it. When your QA files a bug (labeled for FireFunc), it appears here with
|
|
|
69
78
|
| `firefunc-runner logs` | Recent runner output |
|
|
70
79
|
| `firefunc-runner uninstall` | Remove the background service |
|
|
71
80
|
| `firefunc-runner status` | Saved config **and** whether the service is installed + running |
|
|
81
|
+
| `firefunc-runner --version` | The version this build carries — the one it reports to FireFunc (`-v`) |
|
|
72
82
|
|
|
73
83
|
### `connect` flags
|
|
74
84
|
|
|
@@ -140,14 +150,21 @@ find their own logins). If you install a new agent CLI somewhere new, re-run
|
|
|
140
150
|
|
|
141
151
|
FireFunc never clones, fetches or stores your repository. The change goes from this
|
|
142
152
|
machine to **your** repository on GitHub — the push and the draft pull request — and
|
|
143
|
-
nowhere else. This is everything runner **0.
|
|
153
|
+
nowhere else. This is everything runner **0.9.3** sends to the FireFunc API you connected
|
|
144
154
|
it to:
|
|
145
155
|
|
|
146
156
|
**While it waits for work** (`POST /channel/claim`, every few seconds): its version,
|
|
147
|
-
hostname and platform; the engines it can run; the port of its local viewer;
|
|
157
|
+
hostname and platform; the engines it can run; the port of its local viewer; how many
|
|
158
|
+
sessions it runs at once (0.9.1+ — what FireFunc offered it, the largest "Runs at once"
|
|
159
|
+
among the projects it serves, or your `--max-parallel`, which overrides that); the
|
|
148
160
|
subscription usage its engines can read (percent used and when each window resets); and
|
|
149
161
|
the MCP servers this machine is signed in to — names, states, expiries and which login
|
|
150
|
-
holds each (the runner's own or Claude Code's), never a token.
|
|
162
|
+
holds each (the runner's own or Claude Code's), never a token. From 0.9.3 also: the ids of
|
|
163
|
+
the runs it holds (working on, or keeping a result for), the ids of runs the runner process
|
|
164
|
+
before it held and lost, and the plan limits it is waiting out (engine and reset time).
|
|
165
|
+
While it is finishing its runs before stopping, or waiting out a plan limit on every engine
|
|
166
|
+
it has, the same request goes every 30 seconds as a heartbeat that asks for no work
|
|
167
|
+
(`heartbeat`, and `draining` while it stops).
|
|
151
168
|
|
|
152
169
|
**While a run works** (`/channel/runs/<id>/events` and `/activity`): the stage it is at
|
|
153
170
|
(`cloning`, `fixing`, `pushing`, `pr_opened`, a heartbeat every five minutes) with the
|
|
@@ -171,11 +188,20 @@ A command's arguments are where a `sed` expression, a `python -c` body or a here
|
|
|
171
188
|
lives, so they stay here; so does a search pattern, which is often a line of code. Every
|
|
172
189
|
step is cut to one line and has anything shaped like a credential redacted. The files, the
|
|
173
190
|
commands' output and the transcript never leave: the local viewer and
|
|
174
|
-
`firefunc-runner logs` show them.
|
|
191
|
+
`firefunc-runner logs` show them. From 0.9.3 a step also says whether the engine marked
|
|
192
|
+
the call's result an error (`failed` — never what it returned) and whether an MCP tool it
|
|
193
|
+
called is one the run's config declares a write (`write`).
|
|
175
194
|
|
|
176
195
|
**When it finishes** (`POST /channel/runs/<id>/result`): the outcome; the pull request's
|
|
177
|
-
repository, number, URL, branch and title; the agent's closing summary
|
|
178
|
-
|
|
196
|
+
repository, number, URL, branch and title; the agent's closing summary (from 0.9.3 also
|
|
197
|
+
beside a change agent's "no code change" result, so its findings can be posted); a
|
|
198
|
+
failure's reason; and the secret scan (next section). From 0.9.3 also: the full id of the
|
|
199
|
+
commit the run started from (`readHead`); when a plan's limit stopped the engine, that and
|
|
200
|
+
when it resets (`limit`); that the session ended with its own command still running
|
|
201
|
+
(`openCommandAtEnd`); and, for a run the previous runner process lost, `lost`. A FireFunc
|
|
202
|
+
API older than one of these fields refuses a result that carries it; the runner then sends
|
|
203
|
+
the result again without the newest field, and the next, so an older API costs the new
|
|
204
|
+
fields and never the result.
|
|
179
205
|
|
|
180
206
|
- **The summary** keeps its prose, its lists and short inline names (`parseDate`,
|
|
181
207
|
`src/a.ts:14`). A fenced or indented code block, a diff, a run of statements pasted
|
|
@@ -201,15 +227,42 @@ reason; and the secret scan (next section).
|
|
|
201
227
|
|
|
202
228
|
- **A failure's reason** is the runner's own sentence and, at most, the one line of a
|
|
203
229
|
tool's output that says what went wrong. A failed setup command is named by its program
|
|
204
|
-
(`Setup command failed (exit 2): npm run build — src/total.ts:3:10 - error TS2322: …`)
|
|
205
|
-
|
|
230
|
+
(`Setup command failed (exit 2): npm run build — src/total.ts:3:10 - error TS2322: …`),
|
|
231
|
+
and from 0.9.2 by the file name of the script an interpreter ran (`zsh night-setup.sh`,
|
|
232
|
+
never its folder); when no line of its output reads like an error — a script's own "free
|
|
233
|
+
disk is below the floor" — the last line it printed that is not code and carries nothing
|
|
234
|
+
shaped like a credential is sent instead, with the machine's home folder written as `~`. An engine ended by a signal from outside —
|
|
235
|
+
SIGTERM (exit 143) or SIGKILL (exit 137): a person, the operating system or a time limit
|
|
236
|
+
on the machine — is sent as that (0.9.2), not as a crash: the runner stages, commits and
|
|
237
|
+
pushes nothing for it, opens no pull request, and does not start the session again. A refused push by
|
|
206
238
|
git's own `error:`, `fatal:` and `hint:` lines — what a pre-push hook printed stays
|
|
207
239
|
here; a crashed engine by its error line, never the source line a stack quotes. The
|
|
208
|
-
whole output is in the runner's log.
|
|
240
|
+
whole output is in the runner's log. A session the model's safety system declined
|
|
241
|
+
(0.9.1+ — Claude Code's "safeguards flagged" / usage-policy API error) is sent as that,
|
|
242
|
+
in the runner's own words, and neither the runner nor FireFunc runs it again. It is read
|
|
243
|
+
from how the engine ended — Claude Code's closing report says it closed on an error
|
|
244
|
+
and called it a refusal — never from what the agent wrote, so an answer that quotes a
|
|
245
|
+
refusal or links the usage policy is sent as the answer.
|
|
246
|
+
|
|
247
|
+
- **What the run spent** (0.9.1 and newer), read from the engine's own closing
|
|
248
|
+
report — Claude Code's `result` event: the tokens by class (input, output, thinking,
|
|
249
|
+
cache read, cache written) in total and per model id, the turns, the time the session's
|
|
250
|
+
main loop was working and the time in model requests (summed over concurrent requests,
|
|
251
|
+
so it can be longer), the engine's own estimate of those tokens at the API's list prices
|
|
252
|
+
or at the organization's managed rates (not a bill; none is sent when the engine guessed
|
|
253
|
+
the price), whether the engine was signed in with a plan or an API key, whether the plan
|
|
254
|
+
drew on its billed extra usage, and its version. Numbers and names only, nothing the
|
|
255
|
+
agent wrote; an engine that keeps no such count sends none, and a crash's zeroed
|
|
256
|
+
report is not sent as a count. A session whose sub-agents run in the background closes
|
|
257
|
+
once per stretch of its main loop: from 0.9.2 the turns and the working time are added
|
|
258
|
+
over every stretch (0.9.1 sent the last stretch's alone), and the session's totals are
|
|
259
|
+
read once. The plan's 5-hour and weekly percentages are not sent: today's Claude Code
|
|
260
|
+
carries them only in an undocumented field.
|
|
209
261
|
|
|
210
262
|
- **Credentials it asks for** (`/git-credential`, `/mcp-credential`) carry the run's id
|
|
211
263
|
and, for MCP, the server's name — nothing else. FireFunc works out the repository and
|
|
212
|
-
the account from the run.
|
|
264
|
+
the account from the run. From 0.9.3 the GitHub MCP credential is asked for again as it
|
|
265
|
+
nears its hour, or when GitHub refuses it, the same way.
|
|
213
266
|
|
|
214
267
|
FireFunc applies the same rules again when it stores what an older runner sent, so a
|
|
215
268
|
machine you have not updated yet is held to them too.
|
|
@@ -305,23 +358,32 @@ firefunc agents create --project "Web app" --template sentry-fix-pr --name "Sent
|
|
|
305
358
|
**Agents are created as drafts.** `agents create` answers with the draft and a link that
|
|
306
359
|
opens it in the composer; a person reviews it there and activates it. `firefunc agents
|
|
307
360
|
activate` works only with a key made with the `agents:activate` scope. Without that
|
|
308
|
-
scope the API refuses it and says why.
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
|
314
|
-
|
|
|
315
|
-
| `firefunc
|
|
316
|
-
| `firefunc
|
|
317
|
-
| `firefunc
|
|
318
|
-
| `firefunc
|
|
319
|
-
| `firefunc
|
|
320
|
-
| `firefunc agents
|
|
321
|
-
| `firefunc agents
|
|
322
|
-
| `firefunc
|
|
323
|
-
| `firefunc
|
|
324
|
-
| `firefunc
|
|
361
|
+
scope the API refuses it and says why. Installing or writing skills and setting a
|
|
362
|
+
project's standing instructions, repositories or claims likewise need a key made with
|
|
363
|
+
`workspace:configure`, which is off unless ticked — except that `agents create --template`
|
|
364
|
+
installs the curated skills that template names, as launching it from the gallery does.
|
|
365
|
+
|
|
366
|
+
| Command | Needs | What it does |
|
|
367
|
+
| ------------------------------------------------------------------------------ | ------------------------------------- | ------------------------------------------------------------------------- |
|
|
368
|
+
| `firefunc login` / `logout` / `whoami` | any key | Save, forget, or show the key this machine uses |
|
|
369
|
+
| `firefunc templates list` | `agents:read` | Whole agents to start from |
|
|
370
|
+
| `firefunc projects list` | `agents:read` | Where an agent can live |
|
|
371
|
+
| `firefunc connections list [--project …]` | `agents:read` | The tool accounts a project can use |
|
|
372
|
+
| `firefunc skills list` | `agents:read` | Skills an agent can carry |
|
|
373
|
+
| `firefunc agents list \| get <id or @handle>` | `agents:read` | Agents, one or all |
|
|
374
|
+
| `firefunc agents create --project … [--template …] [--name …] [--spec f.json]` | `agents:write` | A **draft**, and its composer link |
|
|
375
|
+
| `firefunc agents update <agent> --spec f.json` | `agents:write` | Change only the fields passed (a live agent also needs `agents:activate`) |
|
|
376
|
+
| `firefunc agents pause \| resume <agent>` | `agents:write` | Stop or restart an agent taking work |
|
|
377
|
+
| `firefunc agents activate <agent>` | `agents:activate` | Switch a draft on |
|
|
378
|
+
| `firefunc run <agent> --title … [--body …] [--watch]` | `tasks:write` | Start a task on an active agent (what "Run now" does) |
|
|
379
|
+
| `firefunc tasks list \| get <id> \| watch <id> \| states` | `tasks:read` | Follow tasks; `watch` stops when the agent's part is over |
|
|
380
|
+
| `firefunc skills directory` | `agents:read` | The curated skills, and which are installed here |
|
|
381
|
+
| `firefunc skills install <slug>` | `workspace:configure` | Install a directory skill so agents may carry it |
|
|
382
|
+
| `firefunc skills create --file SKILL.md` / `update <slug> --file …` | `workspace:configure` | Write or change a skill of the workspace's own |
|
|
383
|
+
| `firefunc projects instructions get \| set <project> --file f.json` | `agents:read` / `workspace:configure` | A project's standing instructions (set replaces all five fields) |
|
|
384
|
+
| `firefunc projects sources get \| set <project> --file f.json` | `agents:read` / `workspace:configure` | What work a project claims (set merges kind by kind) |
|
|
385
|
+
| `firefunc projects repos get \| set <project> --file f.json` | `agents:read` / `workspace:configure` | A project's repositories (set adds only ones its GitHub account can see) |
|
|
386
|
+
| `firefunc skill install [--dir …]` | — | Write the Claude Code skill (below) |
|
|
325
387
|
|
|
326
388
|
Every command has `--help`, and each one takes:
|
|
327
389
|
|
package/dist/activity.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare function stepOf(ev: SessionEvent, ctx: {
|
|
|
14
14
|
worktree: string;
|
|
15
15
|
seq: number;
|
|
16
16
|
now: () => Date;
|
|
17
|
+
writeTools?: ReadonlySet<string>;
|
|
17
18
|
}): ActivityStep | null;
|
|
18
19
|
export declare function createActivityReporter(opts: {
|
|
19
20
|
worktree: string;
|
|
@@ -21,9 +22,11 @@ export declare function createActivityReporter(opts: {
|
|
|
21
22
|
intervalMs?: number;
|
|
22
23
|
cap?: number;
|
|
23
24
|
now?: () => Date;
|
|
25
|
+
writeTools?: ReadonlySet<string>;
|
|
26
|
+
holdMs?: number;
|
|
24
27
|
}): {
|
|
25
28
|
push: (ev: SessionEvent) => void;
|
|
26
|
-
flush: () => Promise<void>;
|
|
29
|
+
flush: (final?: boolean) => Promise<void>;
|
|
27
30
|
readonly sent: number;
|
|
28
31
|
readonly seen: number;
|
|
29
32
|
};
|
package/dist/activity.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { commandName, stripCode } from './keep-local.js';
|
|
1
|
+
import { commandName, promisesLaterCheck, stripCode } from './keep-local.js';
|
|
2
2
|
const MAX_LABEL = 180;
|
|
3
3
|
const SECRET_PATTERNS = [
|
|
4
4
|
/\b(?:bearer|token|authorization)\s*[:=]?\s*[A-Za-z0-9._~+/-]{16,}=*/gi,
|
|
@@ -55,6 +55,8 @@ const TOOL_LABELS = {
|
|
|
55
55
|
};
|
|
56
56
|
export function stepOf(ev, ctx) {
|
|
57
57
|
const base = { seq: ctx.seq, at: ctx.now().toISOString() };
|
|
58
|
+
if (ev.kind === 'tool_result')
|
|
59
|
+
return null;
|
|
58
60
|
if (ev.kind === 'text') {
|
|
59
61
|
const first = stripCode(ev.text).replace(/\s+/g, ' ').trim();
|
|
60
62
|
if (!first)
|
|
@@ -62,7 +64,11 @@ export function stepOf(ev, ctx) {
|
|
|
62
64
|
return { ...base, kind: 'say', label: redact(first, 220) };
|
|
63
65
|
}
|
|
64
66
|
if (ev.kind === 'result') {
|
|
65
|
-
return {
|
|
67
|
+
return {
|
|
68
|
+
...base,
|
|
69
|
+
kind: promisesLaterCheck(ev.text) ? 'say' : 'done',
|
|
70
|
+
label: redact(stripCode(ev.text), 220),
|
|
71
|
+
};
|
|
66
72
|
}
|
|
67
73
|
const name = ev.name;
|
|
68
74
|
const arg = ev.arg ?? '';
|
|
@@ -72,11 +78,17 @@ export function stepOf(ev, ctx) {
|
|
|
72
78
|
const tool = viaFireFunc ? viaFireFunc[1] : mcp.server;
|
|
73
79
|
const action = viaFireFunc ? viaFireFunc[2] : mcp.action;
|
|
74
80
|
const server = TOOL_LABELS[tool] ?? tool;
|
|
81
|
+
const write = ctx.writeTools?.has(name) === true;
|
|
75
82
|
return {
|
|
76
83
|
...base,
|
|
77
84
|
kind: 'tool',
|
|
78
85
|
label: `${server} · ${action.replace(/_/g, ' ')}`,
|
|
79
|
-
detail: {
|
|
86
|
+
detail: {
|
|
87
|
+
tool,
|
|
88
|
+
action,
|
|
89
|
+
...(viaFireFunc ? { via: 'firefunc' } : {}),
|
|
90
|
+
...(write ? { write: true } : {}),
|
|
91
|
+
},
|
|
80
92
|
};
|
|
81
93
|
}
|
|
82
94
|
switch (name) {
|
|
@@ -153,13 +165,58 @@ function scopeOf(p, worktree) {
|
|
|
153
165
|
export function createActivityReporter(opts) {
|
|
154
166
|
const now = opts.now ?? (() => new Date());
|
|
155
167
|
const cap = opts.cap ?? 1500;
|
|
168
|
+
const holdMs = opts.holdMs ?? 2000;
|
|
169
|
+
const intervalMs = opts.intervalMs ?? 1500;
|
|
156
170
|
let seq = 0;
|
|
157
171
|
let sent = 0;
|
|
158
172
|
let pending = [];
|
|
159
173
|
let inflight = null;
|
|
160
174
|
let timer = null;
|
|
175
|
+
const awaiting = new Map();
|
|
176
|
+
const awaitingStep = new Map();
|
|
177
|
+
const arm = () => {
|
|
178
|
+
if (!timer)
|
|
179
|
+
timer = setTimeout(() => void flush(false), intervalMs);
|
|
180
|
+
};
|
|
181
|
+
const forget = (id) => {
|
|
182
|
+
const a = awaiting.get(id);
|
|
183
|
+
if (!a)
|
|
184
|
+
return;
|
|
185
|
+
awaiting.delete(id);
|
|
186
|
+
awaitingStep.delete(a.step);
|
|
187
|
+
};
|
|
188
|
+
const onResult = (id, isError) => {
|
|
189
|
+
const a = awaiting.get(id);
|
|
190
|
+
if (!a)
|
|
191
|
+
return;
|
|
192
|
+
forget(id);
|
|
193
|
+
if (!isError)
|
|
194
|
+
return;
|
|
195
|
+
if (!a.posted) {
|
|
196
|
+
a.step.detail = { ...(a.step.detail ?? {}), failed: true };
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
seq += 1;
|
|
200
|
+
pending.push({
|
|
201
|
+
seq,
|
|
202
|
+
at: now().toISOString(),
|
|
203
|
+
kind: a.step.kind,
|
|
204
|
+
label: a.step.label,
|
|
205
|
+
detail: { ...(a.step.detail ?? {}), failed: true, of: a.step.seq },
|
|
206
|
+
});
|
|
207
|
+
arm();
|
|
208
|
+
};
|
|
161
209
|
const push = (ev) => {
|
|
162
|
-
|
|
210
|
+
if (ev.kind === 'tool_result') {
|
|
211
|
+
onResult(ev.id, ev.isError);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const step = stepOf(ev, {
|
|
215
|
+
worktree: opts.worktree,
|
|
216
|
+
seq: seq + 1,
|
|
217
|
+
now,
|
|
218
|
+
writeTools: opts.writeTools,
|
|
219
|
+
});
|
|
163
220
|
if (!step || !step.label.trim())
|
|
164
221
|
return;
|
|
165
222
|
seq += 1;
|
|
@@ -168,10 +225,14 @@ export function createActivityReporter(opts) {
|
|
|
168
225
|
return;
|
|
169
226
|
}
|
|
170
227
|
pending.push(step);
|
|
171
|
-
if (
|
|
172
|
-
|
|
228
|
+
if (ev.kind === 'tool' && ev.id && awaiting.size < 5000) {
|
|
229
|
+
const a = { step, bornMs: now().getTime(), posted: false };
|
|
230
|
+
awaiting.set(ev.id, a);
|
|
231
|
+
awaitingStep.set(step, a);
|
|
232
|
+
}
|
|
233
|
+
arm();
|
|
173
234
|
};
|
|
174
|
-
const flush = async () => {
|
|
235
|
+
const flush = async (final = true) => {
|
|
175
236
|
if (timer) {
|
|
176
237
|
clearTimeout(timer);
|
|
177
238
|
timer = null;
|
|
@@ -180,14 +241,39 @@ export function createActivityReporter(opts) {
|
|
|
180
241
|
await inflight;
|
|
181
242
|
if (pending.length === 0)
|
|
182
243
|
return;
|
|
183
|
-
|
|
244
|
+
let batch = pending;
|
|
184
245
|
pending = [];
|
|
246
|
+
if (!final) {
|
|
247
|
+
const nowMs = now().getTime();
|
|
248
|
+
const held = batch.filter((st) => {
|
|
249
|
+
const a = awaitingStep.get(st);
|
|
250
|
+
return a !== undefined && !a.posted && nowMs - a.bornMs < holdMs;
|
|
251
|
+
});
|
|
252
|
+
if (held.length > 0) {
|
|
253
|
+
const keep = new Set(held);
|
|
254
|
+
batch = batch.filter((st) => !keep.has(st));
|
|
255
|
+
pending = held;
|
|
256
|
+
arm();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (batch.length === 0)
|
|
260
|
+
return;
|
|
261
|
+
for (const st of batch) {
|
|
262
|
+
const a = awaitingStep.get(st);
|
|
263
|
+
if (a)
|
|
264
|
+
a.posted = true;
|
|
265
|
+
}
|
|
185
266
|
inflight = opts
|
|
186
267
|
.post(batch)
|
|
187
268
|
.then(() => {
|
|
188
269
|
sent += batch.length;
|
|
189
270
|
})
|
|
190
271
|
.catch(() => {
|
|
272
|
+
for (const st of batch) {
|
|
273
|
+
const a = awaitingStep.get(st);
|
|
274
|
+
if (a)
|
|
275
|
+
a.posted = false;
|
|
276
|
+
}
|
|
191
277
|
pending = [...batch, ...pending].slice(-cap);
|
|
192
278
|
})
|
|
193
279
|
.finally(() => {
|
package/dist/api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RunUsage } from './usage.js';
|
|
1
2
|
export type ClaimedJob = {
|
|
2
3
|
runId: string;
|
|
3
4
|
workItemId: string;
|
|
@@ -28,8 +29,16 @@ export type ClaimedJob = {
|
|
|
28
29
|
}[];
|
|
29
30
|
contextPack?: unknown;
|
|
30
31
|
mcpConfig?: unknown;
|
|
32
|
+
maxMinutes?: number | null;
|
|
31
33
|
};
|
|
32
34
|
export type RunnerEvent = 'cloning' | 'fixing' | 'pushing' | 'pr_opened' | 'heartbeat' | 'log';
|
|
35
|
+
export type PlanLimitReport = {
|
|
36
|
+
kind: 'plan';
|
|
37
|
+
resetsAt: string | null;
|
|
38
|
+
};
|
|
39
|
+
export type EngineLimitReport = PlanLimitReport & {
|
|
40
|
+
engine: string;
|
|
41
|
+
};
|
|
33
42
|
export type SecretScanReport = {
|
|
34
43
|
scanned: true;
|
|
35
44
|
hits: Array<{
|
|
@@ -57,7 +66,16 @@ export type ResultPayload = ({
|
|
|
57
66
|
error: string;
|
|
58
67
|
}) & {
|
|
59
68
|
secretScan?: SecretScanReport;
|
|
69
|
+
usage?: RunUsage;
|
|
70
|
+
limit?: PlanLimitReport;
|
|
71
|
+
readHead?: string;
|
|
72
|
+
openCommandAtEnd?: true;
|
|
73
|
+
lost?: true;
|
|
60
74
|
};
|
|
75
|
+
export declare const REPORTED_SUMMARY_MAX = 65536;
|
|
76
|
+
export declare const OLDER_API_SUMMARY_MAX = 4000;
|
|
77
|
+
export declare function cutText(text: string, max: number): string;
|
|
78
|
+
export declare const RESULT_LADDER: readonly ["lost", "openCommandAtEnd", "readHead", "limit", "summary", "usage", "secretScan"];
|
|
61
79
|
export declare class RunnerApi {
|
|
62
80
|
private readonly apiUrl;
|
|
63
81
|
private readonly token;
|
|
@@ -69,6 +87,7 @@ export declare class RunnerApi {
|
|
|
69
87
|
platform: string;
|
|
70
88
|
viewerPort?: number | null;
|
|
71
89
|
engines?: string[];
|
|
90
|
+
maxParallel?: number;
|
|
72
91
|
budget?: Array<{
|
|
73
92
|
engine: string;
|
|
74
93
|
planLabel?: string;
|
|
@@ -86,6 +105,11 @@ export declare class RunnerApi {
|
|
|
86
105
|
expiresAt: string | null;
|
|
87
106
|
detail?: string;
|
|
88
107
|
}>;
|
|
108
|
+
heldRuns?: string[];
|
|
109
|
+
lostRuns?: string[];
|
|
110
|
+
heartbeat?: true;
|
|
111
|
+
draining?: true;
|
|
112
|
+
limits?: EngineLimitReport[];
|
|
89
113
|
}): Promise<ClaimedJob | null>;
|
|
90
114
|
repos(): Promise<string[]>;
|
|
91
115
|
probe(): Promise<boolean>;
|
package/dist/api.js
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
import { RUNNER_VERSION } from './version.js';
|
|
2
|
+
export const REPORTED_SUMMARY_MAX = 65_536;
|
|
3
|
+
export const OLDER_API_SUMMARY_MAX = 4000;
|
|
4
|
+
export function cutText(text, max) {
|
|
5
|
+
if (text.length <= max)
|
|
6
|
+
return text;
|
|
7
|
+
const last = text.charCodeAt(max - 1);
|
|
8
|
+
return text.slice(0, last >= 0xd800 && last <= 0xdbff ? max - 1 : max);
|
|
9
|
+
}
|
|
10
|
+
export const RESULT_LADDER = [
|
|
11
|
+
'lost',
|
|
12
|
+
'openCommandAtEnd',
|
|
13
|
+
'readHead',
|
|
14
|
+
'limit',
|
|
15
|
+
'summary',
|
|
16
|
+
'usage',
|
|
17
|
+
'secretScan',
|
|
18
|
+
];
|
|
19
|
+
function onLadder(body, k) {
|
|
20
|
+
if (k === 'summary') {
|
|
21
|
+
return typeof body.summary === 'string' && body.summary.length > OLDER_API_SUMMARY_MAX;
|
|
22
|
+
}
|
|
23
|
+
return body[k] !== undefined;
|
|
24
|
+
}
|
|
25
|
+
async function unreadFields(res) {
|
|
26
|
+
try {
|
|
27
|
+
const text = await res.text();
|
|
28
|
+
if (!text)
|
|
29
|
+
return [];
|
|
30
|
+
const body = JSON.parse(text);
|
|
31
|
+
const found = new Set();
|
|
32
|
+
const visit = (v, depth) => {
|
|
33
|
+
if (depth > 4 || !v || typeof v !== 'object')
|
|
34
|
+
return;
|
|
35
|
+
if (Array.isArray(v)) {
|
|
36
|
+
for (const item of v)
|
|
37
|
+
visit(item, depth + 1);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const o = v;
|
|
41
|
+
if (o.code === 'unrecognized_keys' && Array.isArray(o.keys)) {
|
|
42
|
+
for (const k of o.keys)
|
|
43
|
+
if (typeof k === 'string')
|
|
44
|
+
found.add(k);
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(o.path) && typeof o.path[0] === 'string')
|
|
47
|
+
found.add(o.path[0]);
|
|
48
|
+
for (const key of ['issues', 'details', 'errors', 'error'])
|
|
49
|
+
visit(o[key], depth + 1);
|
|
50
|
+
};
|
|
51
|
+
visit(body, 0);
|
|
52
|
+
return [...found];
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
1
58
|
export class RunnerApi {
|
|
2
59
|
apiUrl;
|
|
3
60
|
token;
|
|
@@ -55,7 +112,9 @@ export class RunnerApi {
|
|
|
55
112
|
}
|
|
56
113
|
async config() {
|
|
57
114
|
try {
|
|
58
|
-
const res = await fetch(`${this.apiUrl}/channel/config`, {
|
|
115
|
+
const res = await fetch(`${this.apiUrl}/channel/config`, {
|
|
116
|
+
headers: { ...this.headers(), 'x-firefunc-runner-version': RUNNER_VERSION },
|
|
117
|
+
});
|
|
59
118
|
if (!res.ok)
|
|
60
119
|
return null;
|
|
61
120
|
const body = (await res.json());
|
|
@@ -124,10 +183,20 @@ export class RunnerApi {
|
|
|
124
183
|
body: JSON.stringify(body),
|
|
125
184
|
});
|
|
126
185
|
let res = await post(payload);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
186
|
+
let sent = { ...payload };
|
|
187
|
+
const left = RESULT_LADDER.filter((k) => onLadder(sent, k));
|
|
188
|
+
while (res.status === 400 && left.length > 0) {
|
|
189
|
+
const named = (await unreadFields(res)).filter((k) => left.includes(k));
|
|
190
|
+
const drop = named.length > 0 ? named : [left[0]];
|
|
191
|
+
sent = { ...sent };
|
|
192
|
+
for (const k of drop) {
|
|
193
|
+
if (k === 'summary')
|
|
194
|
+
sent.summary = cutText(String(sent.summary), OLDER_API_SUMMARY_MAX);
|
|
195
|
+
else
|
|
196
|
+
delete sent[k];
|
|
197
|
+
left.splice(left.indexOf(k), 1);
|
|
198
|
+
}
|
|
199
|
+
res = await post(sent);
|
|
131
200
|
}
|
|
132
201
|
if (!res.ok)
|
|
133
202
|
throw new Error(`result report failed: ${res.status}`);
|
package/dist/brief.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ClaimedJob } from './api.js';
|
|
2
2
|
import type { RunnerConfig } from './config.js';
|
|
3
|
+
export declare function engineRules(opts: {
|
|
4
|
+
minutes: number;
|
|
5
|
+
heavy: boolean;
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function continueToFinishBrief(open: string[]): string;
|
|
3
8
|
export declare function scanBeforePush(worktree: string, from: string, branch: string): Promise<{
|
|
4
9
|
refusal: string | null;
|
|
5
10
|
note: string | null;
|
package/dist/brief.js
CHANGED
|
@@ -7,6 +7,27 @@ import { changeReads, hardFirst, refusesPush, scanAddedLines, secretRefusal, uni
|
|
|
7
7
|
function out(msg) {
|
|
8
8
|
process.stdout.write(`${msg}\n`);
|
|
9
9
|
}
|
|
10
|
+
export function engineRules(opts) {
|
|
11
|
+
const lines = [
|
|
12
|
+
'How this session runs: it is unattended — nobody answers questions — and it ends when your turn ends. Nothing comes back to it afterwards.',
|
|
13
|
+
'- Never start a command in the background (run_in_background, a trailing `&`, nohup) when you need its result to finish the task. Run it in the foreground and wait for it, however long it takes. Do not end your turn while a command you started is still running: whatever is still running when the session ends is stopped, and a promise to check later is never kept.',
|
|
14
|
+
];
|
|
15
|
+
if (opts.heavy) {
|
|
16
|
+
lines.push('- Other sessions on this machine may be working in this same repository. Run a heavy command — a build or type-check of the whole project, the full test suite — as `"$FIREFUNC_HEAVY" <command>`: it waits for any other heavy command in this repository to finish first, so they take turns instead of running at once.');
|
|
17
|
+
}
|
|
18
|
+
lines.push(`- You have at most ${opts.minutes} minutes; the session is stopped when they run out. Leave time to finish and to say what you proved.`);
|
|
19
|
+
return `${lines.join('\n')}\n\n`;
|
|
20
|
+
}
|
|
21
|
+
export function continueToFinishBrief(open) {
|
|
22
|
+
const what = open.length === 0
|
|
23
|
+
? 'on a promise to check a result later'
|
|
24
|
+
: open.length === 1
|
|
25
|
+
? `while a command you started (${open[0]}) was still running`
|
|
26
|
+
: `while commands you started (${open.join(', ')}) were still running`;
|
|
27
|
+
return (`Your session ended ${what}. Nothing comes back to a session once it ends, and whatever it left running was stopped. ` +
|
|
28
|
+
'Run what you need now, in the foreground, and wait for the result however long it takes; then finish the task with what it shows. ' +
|
|
29
|
+
'Do not end your turn before you have the result.');
|
|
30
|
+
}
|
|
10
31
|
const BRIEF_PROMPT = `You are bootstrapping a CLAUDE.md "runner briefing" for THIS repository.
|
|
11
32
|
|
|
12
33
|
Context: a headless, unattended FireFunc runner will load this file on every automated fix — no human to guide it, no prior context, a cold boot each time. Claude Code auto-loads a repo-root CLAUDE.md as project instructions, so this file is the runner's complete, always-loaded operating manual.
|
package/dist/build-info.json
CHANGED
package/dist/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { expandHome, loadConfig, saveConfig, configPath } from './config.js';
|
|
|
3
3
|
import { startDaemon } from './daemon.js';
|
|
4
4
|
import { runBrief } from './brief.js';
|
|
5
5
|
import { runMcpList, runMcpLogin, runMcpLogout } from './mcp-login.js';
|
|
6
|
+
import { RUNNER_VERSION } from './version.js';
|
|
6
7
|
import { currentPlatform, defaultServiceDeps, EPHEMERAL_INSTALL_MESSAGE, installService, isEphemeralInstall, readLogTail, renderLaunchdPlist, renderSystemdUnit, renderWindowsTaskXml, serviceStatus, servicePaths, startService, stopService, uninstallService, } from './service.js';
|
|
7
8
|
const HELP = `firefunc-runner — run YOUR local coding agent on work FireFunc routes to you.
|
|
8
9
|
(Claude Code, OpenAI Codex, Gemini CLI or Cursor CLI — whichever you have installed.)
|
|
@@ -21,6 +22,7 @@ Usage:
|
|
|
21
22
|
firefunc-runner mcp login <tool> Sign THIS machine in to a tool's MCP server
|
|
22
23
|
firefunc-runner mcp list Which MCP servers this machine is signed in to
|
|
23
24
|
firefunc-runner mcp logout <tool> Forget one MCP sign-in
|
|
25
|
+
firefunc-runner --version Print this runner's version (also -v)
|
|
24
26
|
firefunc-runner --help
|
|
25
27
|
|
|
26
28
|
After "connect", run "install" once. The runner then starts at login/boot and
|
|
@@ -66,7 +68,9 @@ fallback + each engine's auth here):
|
|
|
66
68
|
http://127.0.0.1:<n> to watch Claude work; FireFunc's "Watch live"
|
|
67
69
|
button opens it too. Bound to localhost only — never sent to FireFunc.
|
|
68
70
|
--no-viewer Don't serve the local live-session web terminal.
|
|
69
|
-
--max-parallel <n> Run up to N
|
|
71
|
+
--max-parallel <n> Run up to N sessions AT ONCE on this machine, overriding what
|
|
72
|
+
FireFunc offers (the highest "Runs at once" among the projects
|
|
73
|
+
it serves; 1 = serial when none is set).
|
|
70
74
|
Each runs in its own git worktree + dev-server port. Higher N
|
|
71
75
|
= faster throughput, more CPU/RAM, and may hit Claude-Max rate
|
|
72
76
|
limits. It's your machine + subscription — set what you like.
|
|
@@ -115,6 +119,10 @@ function parseFlags(args) {
|
|
|
115
119
|
}
|
|
116
120
|
async function main() {
|
|
117
121
|
const [cmd, ...rest] = process.argv.slice(2);
|
|
122
|
+
if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
|
|
123
|
+
process.stdout.write(`${RUNNER_VERSION}\n`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
118
126
|
if (!cmd || cmd === '--help' || cmd === '-h' || cmd === 'help') {
|
|
119
127
|
process.stdout.write(HELP);
|
|
120
128
|
return;
|
|
@@ -285,7 +293,7 @@ async function main() {
|
|
|
285
293
|
` gemini: ${cfg.geminiBin ?? 'gemini'}${cfg.geminiApiKey ? ' (API key set)' : ' (env auth)'}\n` +
|
|
286
294
|
` cursor: ${cfg.cursorAgentBin ?? 'cursor-agent'}${cfg.cursorApiKey ? ' (API key set)' : ' (no key — set --cursor-api-key)'}\n` +
|
|
287
295
|
` liveViewer:${cfg.viewerEnabled === false ? ' off' : ` http://127.0.0.1:${cfg.viewerPort ?? 8787} (local only)`}\n` +
|
|
288
|
-
` maxParallel:${cfg.maxParallel
|
|
296
|
+
` maxParallel:${cfg.maxParallel ? ` ${cfg.maxParallel} at once (set here — overrides FireFunc)` : ' from FireFunc (the highest "Runs at once" among the projects this machine serves)'}\n` +
|
|
289
297
|
` claudeAuth:${cfg.claudeUseApiKey
|
|
290
298
|
? ' ANTHROPIC_API_KEY (API billing — opted in)'
|
|
291
299
|
: cfg.claudeCodeOAuthToken
|
package/dist/config.d.ts
CHANGED