@firefunc-agent/runner 0.9.6 → 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/dist/api.d.ts +17 -0
- 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/cut.d.ts +1 -0
- package/dist/cut.js +7 -0
- package/dist/daemon.js +37 -3
- package/dist/engines/copilot.js +3 -2
- package/dist/firefunc/agents.js +1 -1
- package/dist/job.js +940 -797
- package/package.json +1 -1
- package/skill/firefunc/SKILL.md +3 -3
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;
|
|
@@ -68,6 +77,11 @@ export type ResultPayload = ({
|
|
|
68
77
|
} | {
|
|
69
78
|
status: 'failed';
|
|
70
79
|
error: string;
|
|
80
|
+
} | {
|
|
81
|
+
status: 'awaiting_approval';
|
|
82
|
+
changes: ChangeSummary;
|
|
83
|
+
head: string;
|
|
84
|
+
summary?: string;
|
|
71
85
|
}) & {
|
|
72
86
|
secretScan?: SecretScanReport;
|
|
73
87
|
usage?: RunUsage;
|
|
@@ -118,6 +132,9 @@ export declare class RunnerApi {
|
|
|
118
132
|
engine: string;
|
|
119
133
|
code: string;
|
|
120
134
|
}>;
|
|
135
|
+
awaitingRuns?: string[];
|
|
136
|
+
}, opts?: {
|
|
137
|
+
onDiscard?: (runIds: string[]) => void;
|
|
121
138
|
}): Promise<ClaimedJob | null>;
|
|
122
139
|
repos(): Promise<string[]>;
|
|
123
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/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,7 +12,8 @@ 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';
|
|
18
19
|
import { engineBlocks, unattendedContext } from './unattended.js';
|
|
@@ -193,6 +194,33 @@ export async function startDaemon(cfg) {
|
|
|
193
194
|
};
|
|
194
195
|
await dropExpiredCuts().catch(() => { });
|
|
195
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(() => { });
|
|
196
224
|
try {
|
|
197
225
|
const checkouts = Object.values(cfg.repos ?? {}).filter((p) => existsSync(p));
|
|
198
226
|
const removed = await sweepLeftoverWorktrees(checkouts, {
|
|
@@ -222,6 +250,7 @@ export async function startDaemon(cfg) {
|
|
|
222
250
|
expiresAt: l.expiresAt,
|
|
223
251
|
...(l.detail ? { detail: l.detail } : {}),
|
|
224
252
|
})),
|
|
253
|
+
awaitingRuns: keptRunIds(rdir),
|
|
225
254
|
...claimState({
|
|
226
255
|
holding: [...holding, ...heldByLiveProcesses(rdir)],
|
|
227
256
|
pending: pendingIds(),
|
|
@@ -252,7 +281,9 @@ export async function startDaemon(cfg) {
|
|
|
252
281
|
heartbeat: async ({ draining, paused: waitingOutLimit }) => {
|
|
253
282
|
if (waitingOutLimit && heartbeatIgnored)
|
|
254
283
|
return null;
|
|
255
|
-
const job = await api
|
|
284
|
+
const job = await api
|
|
285
|
+
.claim(claimBody({ heartbeat: true, draining }), { onDiscard })
|
|
286
|
+
.catch(() => null);
|
|
256
287
|
if (job) {
|
|
257
288
|
heartbeatIgnored = true;
|
|
258
289
|
log(`FireFunc handed ${job.runId} to a heartbeat — running it`);
|
|
@@ -268,8 +299,11 @@ export async function startDaemon(cfg) {
|
|
|
268
299
|
if (Date.now() - lastCutSweep > 10 * 60_000) {
|
|
269
300
|
lastCutSweep = Date.now();
|
|
270
301
|
await dropExpiredCuts().catch(() => { });
|
|
302
|
+
for (const k of expiredKept(rdir)) {
|
|
303
|
+
await letGo(k, 'was not answered in time').catch(() => { });
|
|
304
|
+
}
|
|
271
305
|
}
|
|
272
|
-
const job = await api.claim(claimBody());
|
|
306
|
+
const job = await api.claim(claimBody(), { onDiscard });
|
|
273
307
|
lostRuns = [];
|
|
274
308
|
backoffMs = 2_000;
|
|
275
309
|
return job;
|
package/dist/engines/copilot.js
CHANGED
|
@@ -61,8 +61,9 @@ export const copilotCliAdapter = {
|
|
|
61
61
|
];
|
|
62
62
|
if (ctx.model)
|
|
63
63
|
args.push('--model', ctx.model);
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const effort = ctx.ultracode || ctx.effort === 'ultracode' ? 'xhigh' : ctx.effort;
|
|
65
|
+
if (effort)
|
|
66
|
+
args.push('--effort', effort);
|
|
66
67
|
if (ctx.maxBudgetUsd)
|
|
67
68
|
args.push('--max-ai-credits', String(ctx.maxBudgetUsd));
|
|
68
69
|
if (ctx.attachDir && ctx.attachPaths.length)
|
package/dist/firefunc/agents.js
CHANGED
|
@@ -74,7 +74,7 @@ const SPEC_FIELDS = "The spec is the composer's own agent body, as JSON (firefun
|
|
|
74
74
|
' tool_grants { <tool or MCP server slug>: { read, write } } — only tools the\n' +
|
|
75
75
|
" project has bound. Left out: the template's, or GitHub read+write\n" +
|
|
76
76
|
' deliverables [{ id, action: "tool.action", params, gate, position }]\n' +
|
|
77
|
-
' guardrails left out:
|
|
77
|
+
' guardrails left out: Autonomous (dry_run_mode false, auto_merge false)\n' +
|
|
78
78
|
' caps { runs_per_day, max_in_flight } — left out: { runs_per_day: 5 }\n' +
|
|
79
79
|
' description, schedule, skills (installed slugs), engine, engine_firmness\n' +
|
|
80
80
|
"The API checks it the way the composer's Save does and refuses what it would refuse,\n" +
|