@firefunc-agent/runner 0.9.14 → 0.9.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +167 -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 +65 -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 +38 -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.js +19 -4
- package/dist/engines/claude.js +10 -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/cli.js +25 -0
- package/dist/firefunc/client.d.ts +5 -1
- package/dist/firefunc/client.js +12 -2
- package/dist/firefunc/config.d.ts +11 -1
- package/dist/firefunc/config.js +6 -4
- package/dist/firefunc/io.d.ts +1 -0
- package/dist/firefunc/main.js +8 -1
- package/dist/firefunc/oauth-login.d.ts +23 -0
- package/dist/firefunc/oauth-login.js +304 -0
- package/dist/firefunc/tasks.d.ts +4 -0
- package/dist/firefunc/tasks.js +89 -2
- package/dist/fleet-words.d.ts +2 -0
- package/dist/fleet-words.js +7 -0
- package/dist/git-auth.d.ts +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 +752 -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 +23 -2
- package/dist/network.js +3 -2
- 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 +41 -0
- package/dist/sign-in.js +239 -0
- package/dist/tool-call.d.ts +59 -0
- package/dist/tool-call.js +375 -0
- package/dist/transport.d.ts +26 -0
- package/dist/transport.js +118 -0
- package/dist/work-dir.d.ts +11 -0
- package/dist/work-dir.js +69 -0
- package/dist/worktree-report.d.ts +10 -0
- package/dist/worktree-report.js +17 -0
- package/dist/worktrees.d.ts +16 -1
- package/dist/worktrees.js +62 -17
- package/package.json +4 -4
- package/skill/firefunc/SKILL.md +4 -3
package/dist/api.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { parseSignInPrefs } from './sign-in.js';
|
|
1
2
|
import { RUNNER_VERSION } from './version.js';
|
|
2
3
|
import { blankSecretsDeep } from './secret-values.js';
|
|
4
|
+
import { readStopList } from './run-stops.js';
|
|
3
5
|
export const REPORTED_SUMMARY_MAX = 65_536;
|
|
4
6
|
export const OLDER_API_SUMMARY_MAX = 4000;
|
|
5
7
|
export function cutText(text, max) {
|
|
@@ -9,6 +11,8 @@ export function cutText(text, max) {
|
|
|
9
11
|
return text.slice(0, last >= 0xd800 && last <= 0xdbff ? max - 1 : max);
|
|
10
12
|
}
|
|
11
13
|
export const RESULT_LADDER = [
|
|
14
|
+
'localChecks',
|
|
15
|
+
'release',
|
|
12
16
|
'lost',
|
|
13
17
|
'openCommandAtEnd',
|
|
14
18
|
'readHead',
|
|
@@ -64,6 +68,25 @@ export class RunnerApi {
|
|
|
64
68
|
this.token = token;
|
|
65
69
|
this.apiUrl = apiUrl.replace(/\/+$/, '');
|
|
66
70
|
}
|
|
71
|
+
setToken(token) {
|
|
72
|
+
this.token = token;
|
|
73
|
+
}
|
|
74
|
+
async rotateToken() {
|
|
75
|
+
const res = await fetch(`${this.apiUrl}/channel/token/rotate`, {
|
|
76
|
+
method: 'POST',
|
|
77
|
+
headers: this.headers(),
|
|
78
|
+
body: '{}',
|
|
79
|
+
});
|
|
80
|
+
if (!res.ok)
|
|
81
|
+
return null;
|
|
82
|
+
const body = (await res.json());
|
|
83
|
+
if (typeof body.token !== 'string' || !body.token.startsWith('ffr_'))
|
|
84
|
+
return null;
|
|
85
|
+
return {
|
|
86
|
+
token: body.token,
|
|
87
|
+
expiresAt: typeof body.expiresAt === 'string' ? body.expiresAt : null,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
67
90
|
headers() {
|
|
68
91
|
return { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' };
|
|
69
92
|
}
|
|
@@ -79,22 +102,135 @@ export class RunnerApi {
|
|
|
79
102
|
});
|
|
80
103
|
if (res.status === 204)
|
|
81
104
|
return null;
|
|
82
|
-
if (res.status === 401)
|
|
83
|
-
|
|
105
|
+
if (res.status === 401) {
|
|
106
|
+
const why = await res.json().catch(() => null);
|
|
107
|
+
throw new Error(`runner token rejected (${refusalWords(why) ?? 'revoked or wrong API URL'})`);
|
|
108
|
+
}
|
|
109
|
+
if (res.status === 426) {
|
|
110
|
+
const why = (await res.json().catch(() => null));
|
|
111
|
+
const up = readUpgrade(why?.upgrade);
|
|
112
|
+
if (up && opts.onUpgrade)
|
|
113
|
+
opts.onUpgrade(up);
|
|
114
|
+
throw new Error(`claim refused: ${refusalWords(why) ?? 'this runner is below the workspace’s minimum version'}`);
|
|
115
|
+
}
|
|
84
116
|
if (!res.ok)
|
|
85
117
|
throw new Error(`claim failed: ${res.status}`);
|
|
86
118
|
const body = (await res.json());
|
|
119
|
+
if (Array.isArray(body.editorSessions) &&
|
|
120
|
+
body.editorSessions.length > 0 &&
|
|
121
|
+
opts.onEditorSessions) {
|
|
122
|
+
opts.onEditorSessions(body.editorSessions);
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(body.stopCommands) && body.stopCommands.length > 0 && opts.onStopCommands) {
|
|
125
|
+
opts.onStopCommands(body.stopCommands);
|
|
126
|
+
}
|
|
127
|
+
if (Array.isArray(body.commandSteps) && body.commandSteps.length > 0 && opts.onCommands) {
|
|
128
|
+
opts.onCommands(body.commandSteps);
|
|
129
|
+
}
|
|
130
|
+
if (Array.isArray(body.toolCalls) && body.toolCalls.length > 0 && opts.onToolCalls) {
|
|
131
|
+
opts.onToolCalls(body.toolCalls);
|
|
132
|
+
}
|
|
133
|
+
const up = readUpgrade(body.upgrade);
|
|
134
|
+
if (up && opts.onUpgrade)
|
|
135
|
+
opts.onUpgrade(up);
|
|
136
|
+
const tok = body.token;
|
|
137
|
+
if (tok && tok.rotate === true && opts.onToken) {
|
|
138
|
+
opts.onToken({ rotate: true, why: typeof tok.why === 'string' ? tok.why : 'asked' });
|
|
139
|
+
}
|
|
87
140
|
if (Array.isArray(body.discard) && opts.onDiscard) {
|
|
88
141
|
const ids = body.discard.filter((x) => typeof x === 'string');
|
|
89
142
|
if (ids.length > 0)
|
|
90
143
|
opts.onDiscard(ids);
|
|
91
144
|
}
|
|
145
|
+
if (opts.onStop) {
|
|
146
|
+
const ids = readStopList(body);
|
|
147
|
+
if (ids.length > 0)
|
|
148
|
+
opts.onStop(ids);
|
|
149
|
+
}
|
|
92
150
|
return body.job ?? null;
|
|
93
151
|
}
|
|
94
152
|
finally {
|
|
95
153
|
clearTimeout(timer);
|
|
96
154
|
}
|
|
97
155
|
}
|
|
156
|
+
async commandResult(id, report) {
|
|
157
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
158
|
+
try {
|
|
159
|
+
const res = await fetch(`${this.apiUrl}/channel/commands/${id}/result`, {
|
|
160
|
+
method: 'POST',
|
|
161
|
+
headers: this.headers(),
|
|
162
|
+
body: JSON.stringify(report),
|
|
163
|
+
signal: AbortSignal.timeout(20_000),
|
|
164
|
+
});
|
|
165
|
+
if (res.ok)
|
|
166
|
+
return true;
|
|
167
|
+
if (res.status < 500 && res.status !== 429)
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
}
|
|
172
|
+
await new Promise((r) => setTimeout(r, 1_000 * (attempt + 1)));
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
async editorPost(path, body) {
|
|
177
|
+
try {
|
|
178
|
+
const res = await fetch(`${this.apiUrl}/channel/editor-grants/${path}`, {
|
|
179
|
+
method: 'POST',
|
|
180
|
+
headers: this.headers(),
|
|
181
|
+
body: JSON.stringify(body ?? {}),
|
|
182
|
+
signal: AbortSignal.timeout(30_000),
|
|
183
|
+
});
|
|
184
|
+
if (!res.ok)
|
|
185
|
+
return null;
|
|
186
|
+
return (await res.json().catch(() => ({}))) ?? {};
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
static relayOf(body) {
|
|
193
|
+
const r = body?.relay;
|
|
194
|
+
if (!r || typeof r.url !== 'string' || typeof r.ticket !== 'string')
|
|
195
|
+
return null;
|
|
196
|
+
return {
|
|
197
|
+
url: r.url,
|
|
198
|
+
ticket: r.ticket,
|
|
199
|
+
expiresAt: typeof r.expiresAt === 'string' ? r.expiresAt : null,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
async acceptEditorGrant(grantId, body) {
|
|
203
|
+
return RunnerApi.relayOf(await this.editorPost(`${encodeURIComponent(grantId)}/accept`, body));
|
|
204
|
+
}
|
|
205
|
+
async editorTicket(grantId) {
|
|
206
|
+
return RunnerApi.relayOf(await this.editorPost(`${encodeURIComponent(grantId)}/ticket`, {}));
|
|
207
|
+
}
|
|
208
|
+
async refuseEditorGrant(grantId, reason) {
|
|
209
|
+
return (await this.editorPost(`${encodeURIComponent(grantId)}/refuse`, { reason })) !== null;
|
|
210
|
+
}
|
|
211
|
+
async endEditorGrant(grantId, reason) {
|
|
212
|
+
return (await this.editorPost(`${encodeURIComponent(grantId)}/end`, { reason })) !== null;
|
|
213
|
+
}
|
|
214
|
+
async toolCallResult(id, report) {
|
|
215
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
216
|
+
try {
|
|
217
|
+
const res = await fetch(`${this.apiUrl}/channel/tool-calls/${id}/result`, {
|
|
218
|
+
method: 'POST',
|
|
219
|
+
headers: this.headers(),
|
|
220
|
+
body: JSON.stringify(report),
|
|
221
|
+
signal: AbortSignal.timeout(20_000),
|
|
222
|
+
});
|
|
223
|
+
if (res.ok)
|
|
224
|
+
return true;
|
|
225
|
+
if (res.status < 500 && res.status !== 429)
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
}
|
|
230
|
+
await new Promise((r) => setTimeout(r, 1_000 * (attempt + 1)));
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
98
234
|
async repos() {
|
|
99
235
|
try {
|
|
100
236
|
const res = await fetch(`${this.apiUrl}/channel/repos`, { headers: this.headers() });
|
|
@@ -124,7 +260,13 @@ export class RunnerApi {
|
|
|
124
260
|
if (!res.ok)
|
|
125
261
|
return null;
|
|
126
262
|
const body = (await res.json());
|
|
127
|
-
return {
|
|
263
|
+
return {
|
|
264
|
+
maxParallel: typeof body.maxParallel === 'number' ? body.maxParallel : 1,
|
|
265
|
+
requiredCommands: Array.isArray(body.requiredCommands)
|
|
266
|
+
? body.requiredCommands.filter((c) => typeof c === 'string')
|
|
267
|
+
: null,
|
|
268
|
+
signInPrefs: parseSignInPrefs(body.signInPrefs),
|
|
269
|
+
};
|
|
128
270
|
}
|
|
129
271
|
catch {
|
|
130
272
|
return null;
|
|
@@ -351,4 +493,23 @@ function missingOf(raw) {
|
|
|
351
493
|
})
|
|
352
494
|
: [];
|
|
353
495
|
}
|
|
496
|
+
function refusalWords(body) {
|
|
497
|
+
if (!body || typeof body !== 'object')
|
|
498
|
+
return null;
|
|
499
|
+
const b = body;
|
|
500
|
+
if (typeof b.message !== 'string')
|
|
501
|
+
return null;
|
|
502
|
+
return typeof b.fix === 'string' ? `${b.message} ${b.fix}` : b.message;
|
|
503
|
+
}
|
|
504
|
+
function readUpgrade(raw) {
|
|
505
|
+
if (!raw || typeof raw !== 'object')
|
|
506
|
+
return null;
|
|
507
|
+
const u = raw;
|
|
508
|
+
if (typeof u.version !== 'string' || !/^(latest|\d+\.\d+\.\d+)$/.test(u.version))
|
|
509
|
+
return null;
|
|
510
|
+
return {
|
|
511
|
+
version: u.version,
|
|
512
|
+
requestedAt: typeof u.requestedAt === 'string' ? u.requestedAt : '',
|
|
513
|
+
};
|
|
514
|
+
}
|
|
354
515
|
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Invocation } from './engines/types.js';
|
|
2
|
+
import { type PreparedAttach } from './run-attachments.js';
|
|
3
|
+
export declare const BRIEF_FOLDER = ".firefunc/brief";
|
|
4
|
+
export declare function prepareBriefFolder(worktree: string, log: (m: string) => void): PreparedAttach;
|
|
5
|
+
export declare function briefPointer(path: string): string;
|
|
6
|
+
export type BriefFence = {
|
|
7
|
+
invocation: Invocation;
|
|
8
|
+
file: string | null;
|
|
9
|
+
exposed: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function fenceBrief(inv: Invocation, prompt: string, opts: {
|
|
12
|
+
folder: () => string | null;
|
|
13
|
+
seq: number;
|
|
14
|
+
log: (m: string) => void;
|
|
15
|
+
}): BriefFence;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { prepareFireFuncFolder } from './run-attachments.js';
|
|
4
|
+
export const BRIEF_FOLDER = '.firefunc/brief';
|
|
5
|
+
const GITIGNORE = "# FireFunc: a run's brief, read by its engine, never committed\n*\n";
|
|
6
|
+
export function prepareBriefFolder(worktree, log) {
|
|
7
|
+
return prepareFireFuncFolder(worktree, { sub: 'brief', gitignore: GITIGNORE, what: 'the brief' }, log);
|
|
8
|
+
}
|
|
9
|
+
export function briefPointer(path) {
|
|
10
|
+
return (`Your whole brief for this task is in the file ${path}. Read all of it first ` +
|
|
11
|
+
`(for example \`cat '${path}'\`) and then do exactly what it says. ` +
|
|
12
|
+
'The file is kept out of every commit; do not copy it into the repository.');
|
|
13
|
+
}
|
|
14
|
+
export function fenceBrief(inv, prompt, opts) {
|
|
15
|
+
const at = prompt ? inv.args.indexOf(prompt) : -1;
|
|
16
|
+
if (at < 0)
|
|
17
|
+
return { invocation: inv, file: null, exposed: false };
|
|
18
|
+
const dir = opts.folder();
|
|
19
|
+
if (!dir) {
|
|
20
|
+
opts.log("the brief stays on the engine's command line, where another session's pattern kill can match it: " +
|
|
21
|
+
'no .firefunc/brief folder could be made in this checkout (the line above says why).');
|
|
22
|
+
return { invocation: inv, file: null, exposed: true };
|
|
23
|
+
}
|
|
24
|
+
const file = join(dir, `brief-${opts.seq}.md`);
|
|
25
|
+
try {
|
|
26
|
+
writeFileSync(file, prompt, { mode: 0o600 });
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
opts.log(`the brief stays on the engine's command line: it could not be written to ${file} (${e.message}).`);
|
|
30
|
+
return { invocation: inv, file: null, exposed: true };
|
|
31
|
+
}
|
|
32
|
+
const args = inv.args.slice();
|
|
33
|
+
args[at] = briefPointer(file);
|
|
34
|
+
return { invocation: { ...inv, args }, file, exposed: false };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=brief-file.js.map
|
package/dist/brief.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { ClaimedJob } from './api.js';
|
|
2
2
|
import type { RunnerConfig } from './config.js';
|
|
3
|
+
import { type ReleaseOffer } from './release-draft.js';
|
|
3
4
|
export declare function engineRules(opts: {
|
|
4
5
|
minutes: number;
|
|
5
6
|
heavy: boolean;
|
|
6
7
|
device?: boolean;
|
|
7
8
|
attach?: boolean;
|
|
9
|
+
release?: ReleaseOffer | null;
|
|
10
|
+
toolsOnly?: boolean;
|
|
8
11
|
}): string;
|
|
9
12
|
export declare function continueToFinishBrief(open: string[]): string;
|
|
10
13
|
export declare function scanBeforePush(worktree: string, from: string, branch: string): Promise<{
|
package/dist/brief.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { mkdtempSync, rmSync, existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { setWorkDir, workRoot } from './work-dir.js';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { exec, execOut } from './exec.js';
|
|
5
5
|
import { resolveRepoPath } from './job.js';
|
|
6
6
|
import { ATTACH_RULE } from './run-attachments.js';
|
|
7
|
+
import { releaseRule } from './release-draft.js';
|
|
7
8
|
import { changeReads, hardFirst, refusesPush, scanAddedLines, secretRefusal, uniqueHits, } from './secret-scan.js';
|
|
8
9
|
function out(msg) {
|
|
9
10
|
process.stdout.write(`${msg}\n`);
|
|
@@ -12,15 +13,23 @@ export function engineRules(opts) {
|
|
|
12
13
|
const lines = [
|
|
13
14
|
'How this session runs: it is unattended — nobody answers questions — and it ends when your turn ends. Nothing comes back to it afterwards.',
|
|
14
15
|
'- 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.',
|
|
16
|
+
"- Other sessions may be running on this machine. Never stop processes by name or pattern (`pkill`, `pkill -f`, `killall`): the pattern reaches other sessions' work. Stop only a process you started, by the pid you got when you started it.",
|
|
15
17
|
];
|
|
16
18
|
if (opts.heavy) {
|
|
17
|
-
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>`:
|
|
19
|
+
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>`: only a few heavy commands run at once in this repository on this machine, so it may wait its turn first (in the order commands arrived) — let it wait; never run the command around it.');
|
|
18
20
|
}
|
|
19
21
|
if (opts.device) {
|
|
20
|
-
lines.push('- The device (an Android emulator or a connected phone) is
|
|
22
|
+
lines.push('- The device (an Android emulator or a connected phone) belongs to this machine and is lent to one session at a time. Run all device work — installing on it, driving it, recording its screen, starting the emulator — through `"$FIREFUNC_DEVICE" <command>`, not through $FIREFUNC_HEAVY; on a machine with several devices it sets `ANDROID_SERIAL` to the one you were given. For a sequence that must not be interrupted (install, set up, then test), take the device first with `"$FIREFUNC_DEVICE" --hold`, run each step through `"$FIREFUNC_DEVICE"`, and let go with `"$FIREFUNC_DEVICE" --release` — another session cannot touch it in between. Build the APK first, outside the device, so you never hold one lock while waiting for the other. If no emulator is running, start one with `"$FIREFUNC_DEVICE" --boot <avd>` (it stays running for the machine); if one is running, use it as it is — never stop, restart or kill the emulator, and never stop a process you did not start. A command, or a hold, keeps the device at most 30 minutes and is stopped once the device stops answering adb; the device\'s airplane mode, wifi, data, proxy and touch sounds are put back as they were when you let go. Each lease starts with an emulator\'s host microphone on (`adb emu avd hostmicon`) and touch sounds off, which an audio check needs — the emulator\'s microphone goes silent when its own sound output stops. `"$FIREFUNC_DEVICE" --status` says who holds it.');
|
|
21
23
|
}
|
|
22
24
|
if (opts.attach)
|
|
23
25
|
lines.push(ATTACH_RULE);
|
|
26
|
+
if (opts.release)
|
|
27
|
+
lines.push(releaseRule(opts.release));
|
|
28
|
+
lines.push(opts.toolsOnly
|
|
29
|
+
? '- This working folder is removed when the session ends, and nothing outside it is yours to write to. What must outlive the session goes where people can find it: the tool you work in, the ticket' +
|
|
30
|
+
(opts.attach ? ` (pictures in \`.firefunc/attach/\`)` : '') +
|
|
31
|
+
' or a repository. Never leave files in your home folder or /tmp: nothing there is cleaned up, and no later run, on this machine or another, can find them.'
|
|
32
|
+
: '- Keep everything you make inside this checkout. Never leave files in your home folder or /tmp: nothing there is cleaned up, and no later run, on this machine or another, can find them.');
|
|
24
33
|
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.`);
|
|
25
34
|
return `${lines.join('\n')}\n\n`;
|
|
26
35
|
}
|
|
@@ -92,7 +101,8 @@ export async function runBrief(repo, cfg) {
|
|
|
92
101
|
const head = await execOut('git', ['-C', repoPath, 'symbolic-ref', 'refs/remotes/origin/HEAD'], repoPath);
|
|
93
102
|
base = head ? head.replace('refs/remotes/origin/', '') : 'main';
|
|
94
103
|
}
|
|
95
|
-
|
|
104
|
+
setWorkDir(cfg.workDir);
|
|
105
|
+
worktree = mkdtempSync(join(workRoot(), 'firefunc-brief-'));
|
|
96
106
|
const add = await exec('git', ['-C', repoPath, 'worktree', 'add', '--force', '-B', branch, worktree, `origin/${base}`], { timeoutMs: 120_000 });
|
|
97
107
|
if (add.code !== 0) {
|
|
98
108
|
out(`git worktree add failed: ${add.stderr.slice(0, 300)}`);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RunnerConfig } from './config.js';
|
|
2
|
+
export declare function isCacheDir(dir: string): boolean;
|
|
3
|
+
export declare function cacheDirsIn(root: string, depth?: number): string[];
|
|
4
|
+
export declare function dropBuildCaches(worktree: string, log?: (line: string) => void): string[];
|
|
5
|
+
export declare function cargoTargetEnv(cfg: Pick<RunnerConfig, 'cargoTarget' | 'claudeEnv'>, runnerDir: string, repo: string | null | undefined): {
|
|
6
|
+
CARGO_TARGET_DIR?: string;
|
|
7
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const CACHEDIR_SIGNATURE = 'Signature: 8a477f597d28d172789f06886806bc55';
|
|
4
|
+
const MAX_DEPTH = 4;
|
|
5
|
+
const SKIP = new Set(['.git', 'node_modules']);
|
|
6
|
+
export function isCacheDir(dir) {
|
|
7
|
+
const tag = join(dir, 'CACHEDIR.TAG');
|
|
8
|
+
if (!existsSync(tag))
|
|
9
|
+
return false;
|
|
10
|
+
try {
|
|
11
|
+
return readFileSync(tag, 'utf8').startsWith(CACHEDIR_SIGNATURE);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function cacheDirsIn(root, depth = MAX_DEPTH) {
|
|
18
|
+
const out = [];
|
|
19
|
+
const walk = (dir, left) => {
|
|
20
|
+
if (left <= 0)
|
|
21
|
+
return;
|
|
22
|
+
let entries;
|
|
23
|
+
try {
|
|
24
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
for (const e of entries) {
|
|
30
|
+
if (!e.isDirectory() || SKIP.has(e.name))
|
|
31
|
+
continue;
|
|
32
|
+
const p = join(dir, e.name);
|
|
33
|
+
if (isCacheDir(p))
|
|
34
|
+
out.push(p);
|
|
35
|
+
else
|
|
36
|
+
walk(p, left - 1);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
walk(root, depth);
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
export function dropBuildCaches(worktree, log) {
|
|
43
|
+
const gone = [];
|
|
44
|
+
for (const dir of cacheDirsIn(worktree)) {
|
|
45
|
+
try {
|
|
46
|
+
rmSync(dir, { recursive: true, force: true });
|
|
47
|
+
gone.push(dir);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (gone.length > 0) {
|
|
53
|
+
log?.(`removed ${gone.length} build cache folder(s) from the kept worktree ${worktree} (the next build makes them again)`);
|
|
54
|
+
}
|
|
55
|
+
return gone;
|
|
56
|
+
}
|
|
57
|
+
export function cargoTargetEnv(cfg, runnerDir, repo) {
|
|
58
|
+
if (cfg.cargoTarget !== 'shared' || !repo || cfg.claudeEnv?.CARGO_TARGET_DIR)
|
|
59
|
+
return {};
|
|
60
|
+
const slug = repo.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'repo';
|
|
61
|
+
return { CARGO_TARGET_DIR: join(runnerDir, 'cargo-target', slug) };
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=build-caches.js.map
|
package/dist/build-info.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { exec } from './exec.js';
|
|
2
|
+
export declare const CHECKPOINT_MINUTES_DEFAULT = 15;
|
|
3
|
+
export declare function checkpointRef(runId: string): string;
|
|
4
|
+
export declare function readCheckpoint(raw: unknown): {
|
|
5
|
+
ref: string;
|
|
6
|
+
sha: string;
|
|
7
|
+
at?: string;
|
|
8
|
+
} | null;
|
|
9
|
+
export declare function checkpointEveryMs(setting: unknown): number;
|
|
10
|
+
export type CheckpointDeps = {
|
|
11
|
+
run?: typeof exec;
|
|
12
|
+
log?: (line: string) => void;
|
|
13
|
+
};
|
|
14
|
+
export type CheckpointResult = {
|
|
15
|
+
saved: true;
|
|
16
|
+
sha: string;
|
|
17
|
+
ref: string;
|
|
18
|
+
} | {
|
|
19
|
+
saved: false;
|
|
20
|
+
why: 'unchanged' | 'secret' | 'git' | 'push';
|
|
21
|
+
};
|
|
22
|
+
export declare function saveCheckpoint(input: {
|
|
23
|
+
worktree: string;
|
|
24
|
+
runId: string;
|
|
25
|
+
from: string;
|
|
26
|
+
excludes: readonly string[];
|
|
27
|
+
env: NodeJS.ProcessEnv;
|
|
28
|
+
last?: {
|
|
29
|
+
tree: string;
|
|
30
|
+
} | null;
|
|
31
|
+
}, deps?: CheckpointDeps): Promise<CheckpointResult & {
|
|
32
|
+
tree?: string;
|
|
33
|
+
}>;
|
|
34
|
+
export declare function restoreCheckpoint(input: {
|
|
35
|
+
worktree: string;
|
|
36
|
+
ref: string;
|
|
37
|
+
sha: string;
|
|
38
|
+
env: NodeJS.ProcessEnv;
|
|
39
|
+
}, deps?: CheckpointDeps): Promise<boolean>;
|
|
40
|
+
export declare function resumeFromCheckpointBrief(at: string | undefined): string;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { exec } from './exec.js';
|
|
5
|
+
import { FULL_SHA, changeReads, scanAddedLines } from './secret-scan.js';
|
|
6
|
+
export const CHECKPOINT_MINUTES_DEFAULT = 15;
|
|
7
|
+
export function checkpointRef(runId) {
|
|
8
|
+
return `refs/firefunc/wip/${runId.toLowerCase()}`;
|
|
9
|
+
}
|
|
10
|
+
const REF = /^refs\/firefunc\/wip\/[0-9a-f-]{36}$/;
|
|
11
|
+
export function readCheckpoint(raw) {
|
|
12
|
+
const o = raw;
|
|
13
|
+
if (!o || typeof o.ref !== 'string' || typeof o.sha !== 'string')
|
|
14
|
+
return null;
|
|
15
|
+
if (!REF.test(o.ref) || !FULL_SHA.test(o.sha))
|
|
16
|
+
return null;
|
|
17
|
+
return { ref: o.ref, sha: o.sha, ...(typeof o.at === 'string' ? { at: o.at } : {}) };
|
|
18
|
+
}
|
|
19
|
+
export function checkpointEveryMs(setting) {
|
|
20
|
+
const n = typeof setting === 'number' && Number.isFinite(setting) ? setting : CHECKPOINT_MINUTES_DEFAULT;
|
|
21
|
+
return n <= 0 ? 0 : Math.max(5, Math.min(240, n)) * 60_000;
|
|
22
|
+
}
|
|
23
|
+
export async function saveCheckpoint(input, deps = {}) {
|
|
24
|
+
const run = deps.run ?? exec;
|
|
25
|
+
const dir = mkdtempSync(join(tmpdir(), 'ff-ckpt-'));
|
|
26
|
+
const index = join(dir, 'index');
|
|
27
|
+
const git = (args, extra = {}) => run('git', ['-C', input.worktree, ...args], {
|
|
28
|
+
timeoutMs: 120_000,
|
|
29
|
+
env: { GIT_INDEX_FILE: index, ...extra },
|
|
30
|
+
}).catch(() => null);
|
|
31
|
+
try {
|
|
32
|
+
if ((await git(['read-tree', 'HEAD']))?.code !== 0)
|
|
33
|
+
return { saved: false, why: 'git' };
|
|
34
|
+
const add = await git(['add', '-A', '--', '.', ...input.excludes]);
|
|
35
|
+
if (add?.code !== 0)
|
|
36
|
+
return { saved: false, why: 'git' };
|
|
37
|
+
const tree = (await git(['write-tree']))?.stdout.trim() ?? '';
|
|
38
|
+
if (!FULL_SHA.test(tree))
|
|
39
|
+
return { saved: false, why: 'git' };
|
|
40
|
+
if (input.last?.tree === tree)
|
|
41
|
+
return { saved: false, why: 'unchanged', tree };
|
|
42
|
+
const commit = await git(['commit-tree', tree, '-p', 'HEAD', '-m', `FireFunc checkpoint of run ${input.runId}`], {
|
|
43
|
+
GIT_AUTHOR_NAME: 'FireFunc',
|
|
44
|
+
GIT_AUTHOR_EMAIL: 'checkpoint@firefunc.com',
|
|
45
|
+
GIT_COMMITTER_NAME: 'FireFunc',
|
|
46
|
+
GIT_COMMITTER_EMAIL: 'checkpoint@firefunc.com',
|
|
47
|
+
});
|
|
48
|
+
const sha = commit?.stdout.trim() ?? '';
|
|
49
|
+
if (!FULL_SHA.test(sha))
|
|
50
|
+
return { saved: false, why: 'git' };
|
|
51
|
+
const reads = changeReads(input.from, '', sha);
|
|
52
|
+
const hits = [];
|
|
53
|
+
for (const args of [reads.whole, reads.commits]) {
|
|
54
|
+
const r = await run('git', ['-C', input.worktree, ...args], {
|
|
55
|
+
timeoutMs: 120_000,
|
|
56
|
+
env: reads.env,
|
|
57
|
+
}).catch(() => null);
|
|
58
|
+
if (!r || r.code !== 0)
|
|
59
|
+
return { saved: false, why: 'git' };
|
|
60
|
+
hits.push(...scanAddedLines(r.stdout));
|
|
61
|
+
}
|
|
62
|
+
if (hits.length > 0) {
|
|
63
|
+
deps.log?.(`checkpoint of ${input.runId} not pushed: it holds a credential-shaped line (the push's own scan decides at the end)`);
|
|
64
|
+
return { saved: false, why: 'secret', tree };
|
|
65
|
+
}
|
|
66
|
+
const ref = checkpointRef(input.runId);
|
|
67
|
+
const pushed = await run('git', ['-C', input.worktree, 'push', '--force', '--no-verify', 'origin', `${sha}:${ref}`], { timeoutMs: 180_000, env: input.env }).catch(() => null);
|
|
68
|
+
if (!pushed || pushed.code !== 0)
|
|
69
|
+
return { saved: false, why: 'push', tree };
|
|
70
|
+
return { saved: true, sha, ref, tree };
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
rmSync(dir, { recursive: true, force: true });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export async function restoreCheckpoint(input, deps = {}) {
|
|
77
|
+
const run = deps.run ?? exec;
|
|
78
|
+
const git = (args, env = {}) => run('git', ['-C', input.worktree, ...args], { timeoutMs: 180_000, env }).catch(() => null);
|
|
79
|
+
const start = (await git(['rev-parse', 'HEAD']))?.stdout.trim() ?? '';
|
|
80
|
+
const fetched = await git(['fetch', '--no-tags', 'origin', input.ref], input.env);
|
|
81
|
+
if (fetched?.code !== 0)
|
|
82
|
+
return false;
|
|
83
|
+
const got = (await git(['rev-parse', 'FETCH_HEAD']))?.stdout.trim();
|
|
84
|
+
if (got !== input.sha)
|
|
85
|
+
return false;
|
|
86
|
+
const ok = (await git(['reset', '--hard', `${input.sha}^`]))?.code === 0 &&
|
|
87
|
+
(await git(['read-tree', '-u', '-m', 'HEAD', input.sha]))?.code === 0 &&
|
|
88
|
+
(await git(['reset', '-q']))?.code === 0;
|
|
89
|
+
if (!ok && FULL_SHA.test(start))
|
|
90
|
+
await git(['reset', '--hard', start]);
|
|
91
|
+
return ok;
|
|
92
|
+
}
|
|
93
|
+
export function resumeFromCheckpointBrief(at) {
|
|
94
|
+
return (`This task's earlier attempt was cut short (its machine stopped, slept or lost it), and FireFunc had saved its work${at ? ` at ${at}` : ''}. ` +
|
|
95
|
+
'That work is in this worktree now — its commits on the branch and the rest as uncommitted changes. ' +
|
|
96
|
+
'Read what is there first (git status, git log, git diff), keep what is right, and go on from it rather than starting over.\n\n');
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=checkpoint.js.map
|