@firefunc-agent/runner 0.9.36 → 0.9.40
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 +32 -0
- package/dist/activity.d.ts +2 -0
- package/dist/activity.js +3 -0
- package/dist/alive.d.ts +8 -0
- package/dist/alive.js +29 -0
- package/dist/api.d.ts +32 -0
- package/dist/api.js +18 -2
- package/dist/ask-replace.d.ts +6 -0
- package/dist/ask-replace.js +49 -0
- package/dist/awake-timer.d.ts +8 -0
- package/dist/awake-timer.js +30 -0
- package/dist/brief.js +2 -2
- package/dist/build-info.json +2 -2
- package/dist/clean-up.d.ts +29 -0
- package/dist/clean-up.js +131 -0
- package/dist/cli.js +141 -16
- package/dist/config.d.ts +7 -0
- package/dist/cut.d.ts +2 -0
- package/dist/cut.js +20 -3
- package/dist/daemon.js +147 -6
- package/dist/disk-reclaim.d.ts +40 -0
- package/dist/disk-reclaim.js +95 -0
- package/dist/drives.d.ts +29 -0
- package/dist/drives.js +270 -0
- package/dist/engine-account.d.ts +1 -1
- package/dist/engine-account.js +12 -1
- package/dist/engines/types.d.ts +1 -1
- package/dist/exec.js +5 -6
- package/dist/firefunc/automations.js +3 -3
- package/dist/firefunc/machines.js +20 -0
- package/dist/firefunc/main.js +1 -1
- package/dist/firefunc/oauth-login.js +1 -1
- package/dist/gh-repos.d.ts +41 -0
- package/dist/gh-repos.js +68 -0
- package/dist/git-auth.d.ts +1 -0
- package/dist/git-auth.js +1 -1
- package/dist/held.d.ts +4 -2
- package/dist/held.js +19 -5
- package/dist/job.d.ts +1 -0
- package/dist/job.js +148 -33
- package/dist/keep-local.d.ts +1 -0
- package/dist/keep-local.js +63 -0
- package/dist/live-runner.d.ts +47 -0
- package/dist/live-runner.js +109 -0
- package/dist/local-tools.d.ts +31 -0
- package/dist/local-tools.js +178 -0
- package/dist/machine-logins.d.ts +4 -0
- package/dist/machine-logins.js +31 -0
- package/dist/mcp-login.d.ts +3 -0
- package/dist/mcp-login.js +34 -4
- package/dist/mcp-tools.d.ts +23 -0
- package/dist/mcp-tools.js +122 -0
- package/dist/mcp.d.ts +8 -0
- package/dist/mcp.js +37 -3
- package/dist/newer-runner.d.ts +9 -0
- package/dist/newer-runner.js +38 -0
- package/dist/pool.d.ts +1 -0
- package/dist/pool.js +1 -0
- package/dist/pr-title.d.ts +1 -0
- package/dist/pr-title.js +7 -0
- package/dist/repo-path.d.ts +15 -0
- package/dist/repo-path.js +56 -0
- package/dist/resources.d.ts +38 -0
- package/dist/resources.js +47 -1
- package/dist/restart-idle.d.ts +1 -0
- package/dist/restart-idle.js +20 -5
- package/dist/run-folders.d.ts +25 -0
- package/dist/run-folders.js +89 -0
- package/dist/update.d.ts +41 -0
- package/dist/update.js +176 -0
- package/dist/viewer.d.ts +1 -1
- package/dist/viewer.js +3 -1
- package/dist/work-dir.d.ts +30 -0
- package/dist/work-dir.js +153 -22
- package/dist/worktrees.d.ts +7 -0
- package/dist/worktrees.js +26 -5
- package/package.json +1 -1
package/dist/git-auth.js
CHANGED
|
@@ -56,7 +56,7 @@ export async function openDraftPr(args) {
|
|
|
56
56
|
const res = await fetch(`https://api.github.com/repos/${repo}/pulls`, {
|
|
57
57
|
method: 'POST',
|
|
58
58
|
headers,
|
|
59
|
-
body: JSON.stringify({ title, head, base, body, draft:
|
|
59
|
+
body: JSON.stringify({ title, head, base, body, draft: args.draft !== false }),
|
|
60
60
|
});
|
|
61
61
|
if (res.ok) {
|
|
62
62
|
const j = (await res.json());
|
package/dist/held.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export declare function recordHeld(runnerDir: string, runId: string, pid?: numbe
|
|
|
16
16
|
export declare function updateHeld(runnerDir: string, runId: string, patch: Partial<Omit<HeldRun, 'runId' | 'pid' | 'claimedAt'>>): void;
|
|
17
17
|
export declare function releaseHeld(runnerDir: string, runId: string): void;
|
|
18
18
|
export declare function listHeld(runnerDir: string): HeldRun[];
|
|
19
|
-
export declare function
|
|
20
|
-
export declare function
|
|
19
|
+
export declare function bootedAt(now?: number, up?: number): number;
|
|
20
|
+
export declare function claimedBeforeBoot(r: Pick<HeldRun, 'claimedAt'>, boot?: number): boolean;
|
|
21
|
+
export declare function heldByGoneProcesses(runnerDir: string, self?: number, boot?: number): HeldRun[];
|
|
22
|
+
export declare function heldByLiveProcesses(runnerDir: string, self?: number, boot?: number): string[];
|
|
21
23
|
export declare function liveWorktrees(runnerDir: string): Set<string>;
|
package/dist/held.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { uptime } from 'node:os';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import { isAlive } from './orphans.js';
|
|
4
5
|
const RUN_ID = /^[A-Za-z0-9][A-Za-z0-9-]{3,79}$/;
|
|
@@ -72,18 +73,31 @@ export function listHeld(runnerDir) {
|
|
|
72
73
|
}
|
|
73
74
|
return out.sort((a, b) => a.claimedAt.localeCompare(b.claimedAt));
|
|
74
75
|
}
|
|
75
|
-
export function
|
|
76
|
-
return
|
|
76
|
+
export function bootedAt(now = Date.now(), up = uptime()) {
|
|
77
|
+
return now - up * 1000;
|
|
77
78
|
}
|
|
78
|
-
export function
|
|
79
|
+
export function claimedBeforeBoot(r, boot = bootedAt()) {
|
|
80
|
+
const at = Date.parse(r.claimedAt);
|
|
81
|
+
return Number.isFinite(at) && at < boot - 60_000;
|
|
82
|
+
}
|
|
83
|
+
function goneRecord(r, self, boot) {
|
|
84
|
+
if (r.pid === self)
|
|
85
|
+
return false;
|
|
86
|
+
return claimedBeforeBoot(r, boot) || !isAlive(r.pid);
|
|
87
|
+
}
|
|
88
|
+
export function heldByGoneProcesses(runnerDir, self = process.pid, boot = bootedAt()) {
|
|
89
|
+
return listHeld(runnerDir).filter((r) => goneRecord(r, self, boot));
|
|
90
|
+
}
|
|
91
|
+
export function heldByLiveProcesses(runnerDir, self = process.pid, boot = bootedAt()) {
|
|
79
92
|
return listHeld(runnerDir)
|
|
80
|
-
.filter((r) => r
|
|
93
|
+
.filter((r) => !goneRecord(r, self, boot))
|
|
81
94
|
.map((r) => r.runId);
|
|
82
95
|
}
|
|
83
96
|
export function liveWorktrees(runnerDir) {
|
|
84
97
|
const out = new Set();
|
|
98
|
+
const boot = bootedAt();
|
|
85
99
|
for (const r of listHeld(runnerDir)) {
|
|
86
|
-
if (
|
|
100
|
+
if (goneRecord(r, -1, boot))
|
|
87
101
|
continue;
|
|
88
102
|
if (r.worktree)
|
|
89
103
|
out.add(r.worktree);
|
package/dist/job.d.ts
CHANGED
|
@@ -36,3 +36,4 @@ export declare function waitForStoppedHolder(runnerDir: string, worktree: string
|
|
|
36
36
|
pollMs?: number;
|
|
37
37
|
}): Promise<BranchHolder | null>;
|
|
38
38
|
export declare function runJob(job: ClaimedJob, cfg: RunnerConfig, api: RunnerApi, viewer?: SessionViewer, opts?: RunJobOptions): Promise<void>;
|
|
39
|
+
export declare function timeoutWords(engineName: string, limitMinutes: number, budget: number | null, machineMinutes: number | undefined): string;
|
package/dist/job.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { declaredChecksOf, makeLocalChecksReader } from './local-checks.js';
|
|
2
|
+
import { expandPath } from './repo-path.js';
|
|
2
3
|
import { endedState, reportWorktree } from './worktree-report.js';
|
|
3
|
-
import { mkdtempSync, rmSync, existsSync, mkdirSync, writeFileSync, copyFileSync, appendFileSync, chmodSync, readdirSync, } from 'node:fs';
|
|
4
|
+
import { mkdtempSync, rmSync, existsSync, mkdirSync, writeFileSync, copyFileSync, appendFileSync, chmodSync, readdirSync, readFileSync, } from 'node:fs';
|
|
4
5
|
import { readFile } from 'node:fs/promises';
|
|
5
|
-
import { homedir, hostname } from 'node:os';
|
|
6
|
+
import { homedir, hostname, tmpdir } from 'node:os';
|
|
6
7
|
import { diskOf } from './resources.js';
|
|
7
8
|
import { cargoTargetEnv } from './build-caches.js';
|
|
8
9
|
import { checkpointEveryMs, readCheckpoint, restoreCheckpoint, resumeFromCheckpointBrief, saveCheckpoint, } from './checkpoint.js';
|
|
9
|
-
import { setWorkDir, workRoot, workTempEnv } from './work-dir.js';
|
|
10
|
+
import { scratchRoot, setWorkDir, workRoot, workTempEnv } from './work-dir.js';
|
|
11
|
+
import { RUN_MARKER, makeRunFolder, writeRunMarker } from './run-folders.js';
|
|
10
12
|
import { makeRunTemp, removeRunTemp } from './run-temp.js';
|
|
11
|
-
import { join, basename, dirname, relative, sep } from 'node:path';
|
|
13
|
+
import { join, basename, dirname, isAbsolute, relative, sep } from 'node:path';
|
|
12
14
|
import {} from 'node:child_process';
|
|
13
15
|
import { exec, execOut, spawnBackground, killProcessTree } from './exec.js';
|
|
14
16
|
import { REPORTED_SUMMARY_MAX, cutText } from './api.js';
|
|
15
17
|
import { configPath, loadConfig, saveConfig } from './config.js';
|
|
18
|
+
import { localServersFor, missingLocalToolsNote } from './local-tools.js';
|
|
16
19
|
import { cloneRepo, endedPullRequestForHead, endedPullRequestSentence, gitAuthEnv, openDraftPr, PUSH_TIMEOUT_MS, pushBranch, pushFlags, redact, } from './git-auth.js';
|
|
17
20
|
import { createActivityReporter, redact as oneLine, stripWorktree } from './activity.js';
|
|
18
21
|
import { errorLine, foldHome, promisesLaterCheck, pushRefusal, setupCommandName, setupReason, stripCode, } from './keep-local.js';
|
|
@@ -22,7 +25,7 @@ import { firefuncReconnectedBrief, mcpServersFailedAtStart } from './mcp-init.js
|
|
|
22
25
|
import { endedOnRefusal, modelDeclinedSentence } from './declined.js';
|
|
23
26
|
import { endedBySignal, stoppedSentence } from './stopped.js';
|
|
24
27
|
import { isStopped, stoppedByPersonSentence, trackRunGroup, untrackRunGroup } from './run-stops.js';
|
|
25
|
-
import { AGENT_PR_FILE, changeKind, parseAgentPullRequest, pullRequestBody, provenanceTrailers, withProvenanceFooter, pullRequestTitle, } from './pr-title.js';
|
|
28
|
+
import { AGENT_PR_FILE, changeKind, parseAgentPullRequest, pullRequestBody, provenanceTrailers, withProvenanceFooter, pullRequestTitle, withTicketKey, } from './pr-title.js';
|
|
26
29
|
import { savePendingResult } from './pending.js';
|
|
27
30
|
import { runnerDir } from './config.js';
|
|
28
31
|
import { attemptUsage, combineUsage, describeUsage, } from './usage.js';
|
|
@@ -98,11 +101,17 @@ export function resolveRepoPath(repo, cfg) {
|
|
|
98
101
|
if (!repo)
|
|
99
102
|
return null;
|
|
100
103
|
const want = repo.toLowerCase();
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
let onDisk = {};
|
|
105
|
+
try {
|
|
106
|
+
onDisk = loadConfig()?.repos ?? {};
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
}
|
|
110
|
+
const repos = { ...(cfg.repos ?? {}), ...onDisk };
|
|
111
|
+
for (const [k, v] of Object.entries(repos)) {
|
|
112
|
+
const path = expandPath(v);
|
|
113
|
+
if (k.toLowerCase() === want && existsSync(path))
|
|
114
|
+
return path;
|
|
106
115
|
}
|
|
107
116
|
if (cfg.reposDir) {
|
|
108
117
|
const guess = join(cfg.reposDir, basename(repo));
|
|
@@ -111,6 +120,30 @@ export function resolveRepoPath(repo, cfg) {
|
|
|
111
120
|
}
|
|
112
121
|
return null;
|
|
113
122
|
}
|
|
123
|
+
async function longPaths(repo) {
|
|
124
|
+
if (process.platform !== 'win32')
|
|
125
|
+
return;
|
|
126
|
+
await exec('git', ['-C', repo, 'config', 'core.longpaths', 'true'], {
|
|
127
|
+
timeoutMs: 15_000,
|
|
128
|
+
}).catch(() => { });
|
|
129
|
+
}
|
|
130
|
+
async function markRunFolder(worktree, runId) {
|
|
131
|
+
try {
|
|
132
|
+
const common = (await execOut('git', ['-C', worktree, 'rev-parse', '--git-common-dir'])).trim();
|
|
133
|
+
if (common) {
|
|
134
|
+
const abs = isAbsolute(common) ? common : join(worktree, common);
|
|
135
|
+
const file = join(abs, 'info', 'exclude');
|
|
136
|
+
mkdirSync(join(abs, 'info'), { recursive: true });
|
|
137
|
+
const text = existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
138
|
+
if (!text.split(/\r?\n/).includes(RUN_MARKER)) {
|
|
139
|
+
appendFileSync(file, `\n# FireFunc: the run folder's marker\n${RUN_MARKER}\n`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
}
|
|
145
|
+
writeRunMarker(worktree, runId);
|
|
146
|
+
}
|
|
114
147
|
export function cloneDestination(repo, cfg) {
|
|
115
148
|
const name = basename(repo);
|
|
116
149
|
if (!name)
|
|
@@ -276,6 +309,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
276
309
|
const localChecks = makeLocalChecksReader(declaredChecksOf(job.checks));
|
|
277
310
|
let usage;
|
|
278
311
|
let readHead;
|
|
312
|
+
let engineSession;
|
|
279
313
|
let restoredFrom = null;
|
|
280
314
|
let openCommandAtEnd = false;
|
|
281
315
|
let attachFolder = null;
|
|
@@ -347,7 +381,9 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
347
381
|
};
|
|
348
382
|
}
|
|
349
383
|
};
|
|
384
|
+
let lastStatus = null;
|
|
350
385
|
const report = async (reported) => {
|
|
386
|
+
lastStatus = reported.status;
|
|
351
387
|
await sendAttachments(reported.status);
|
|
352
388
|
const release = reported.release ? null : await stageRelease(reported.status);
|
|
353
389
|
if (release)
|
|
@@ -366,6 +402,8 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
366
402
|
payload = { ...payload, localChecks: checks };
|
|
367
403
|
if (readHead && !payload.readHead)
|
|
368
404
|
payload = { ...payload, readHead };
|
|
405
|
+
if (engineSession && !payload.session)
|
|
406
|
+
payload = { ...payload, session: engineSession };
|
|
369
407
|
if (openCommandAtEnd && !payload.openCommandAtEnd) {
|
|
370
408
|
payload = { ...payload, openCommandAtEnd: true };
|
|
371
409
|
}
|
|
@@ -568,8 +606,14 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
568
606
|
return written;
|
|
569
607
|
};
|
|
570
608
|
let repoPath = toolsOnly ? null : resolveRepoPath(job.repo, cfg);
|
|
609
|
+
let credentialRefused = null;
|
|
571
610
|
if (!repoPath && job.repo) {
|
|
572
|
-
const
|
|
611
|
+
const got = api.gitCredentialOrRefusal
|
|
612
|
+
? await api.gitCredentialOrRefusal(job.runId)
|
|
613
|
+
: await api.gitCredential(job.runId);
|
|
614
|
+
const cred = got && 'token' in got ? got : null;
|
|
615
|
+
if (got && 'refused' in got)
|
|
616
|
+
credentialRefused = got.refused;
|
|
573
617
|
const dest = cloneDestination(job.repo, cfg);
|
|
574
618
|
if (cred && dest) {
|
|
575
619
|
log(`no local checkout for ${job.repo} — cloning into ${dest}`);
|
|
@@ -577,6 +621,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
577
621
|
const cloned = await cloneRepo(job.repo, dest, cred);
|
|
578
622
|
if (cloned.code === 0) {
|
|
579
623
|
repoPath = dest;
|
|
624
|
+
await longPaths(dest);
|
|
580
625
|
rememberRepoPath(job.repo, dest, cfg);
|
|
581
626
|
}
|
|
582
627
|
else {
|
|
@@ -591,9 +636,12 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
591
636
|
log(`no local checkout for ${job.repo} and no credential to clone with`);
|
|
592
637
|
return await report({
|
|
593
638
|
status: 'failed',
|
|
594
|
-
error:
|
|
595
|
-
`
|
|
596
|
-
|
|
639
|
+
error: credentialRefused
|
|
640
|
+
? `Runner has no local checkout for ${job.repo}, and FireFunc could not give it a ` +
|
|
641
|
+
`credential to clone: ${credentialRefused.reason} Fix: ${credentialRefused.fix}`
|
|
642
|
+
: `Runner has no local checkout for ${job.repo} and could not obtain a ` +
|
|
643
|
+
`credential to clone it. Either map it with \`firefunc-runner repo ` +
|
|
644
|
+
`${job.repo} <path>\`, set --repos-dir, or connect GitHub in FireFunc.`,
|
|
597
645
|
});
|
|
598
646
|
}
|
|
599
647
|
const branch = job.branch ?? `${adapter.branchPrefix}/firefunc-${job.runId.slice(0, 8)}`;
|
|
@@ -678,6 +726,16 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
678
726
|
title: job.title ?? job.externalId ?? undefined,
|
|
679
727
|
repo: job.repo ?? undefined,
|
|
680
728
|
});
|
|
729
|
+
const reportNoChange = async (engineName, summary) => {
|
|
730
|
+
log(`no changes produced for ${job.runId} — reporting no_pr`);
|
|
731
|
+
return await report({
|
|
732
|
+
status: 'no_pr',
|
|
733
|
+
error: summary
|
|
734
|
+
? `No code change made. ${engineName}: ${oneLine(shareable(summary), 800)}`
|
|
735
|
+
: `${engineName} made no changes (could not reproduce or fix).`,
|
|
736
|
+
...(summary ? { summary: reportedSummary(summary) } : {}),
|
|
737
|
+
});
|
|
738
|
+
};
|
|
681
739
|
const ship = async (s) => {
|
|
682
740
|
const { worktree, branch, base, title, kind, engineName, summary } = s;
|
|
683
741
|
const agentText = s.agentText ?? null;
|
|
@@ -970,6 +1028,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
970
1028
|
body,
|
|
971
1029
|
cred: gitCred,
|
|
972
1030
|
update: !!agentText,
|
|
1031
|
+
draft: job.prDraft !== false,
|
|
973
1032
|
}), {
|
|
974
1033
|
label: `pull request for ${job.runId}`,
|
|
975
1034
|
maxWaitMs: 10 * 60_000,
|
|
@@ -1001,7 +1060,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1001
1060
|
const r = await exec('gh', [
|
|
1002
1061
|
'pr',
|
|
1003
1062
|
'create',
|
|
1004
|
-
'--draft',
|
|
1063
|
+
...(job.prDraft === false ? [] : ['--draft']),
|
|
1005
1064
|
'--head',
|
|
1006
1065
|
branch,
|
|
1007
1066
|
'--base',
|
|
@@ -1052,6 +1111,8 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1052
1111
|
}
|
|
1053
1112
|
if (!resolved) {
|
|
1054
1113
|
const why = (create.stderr || create.stdout).replace(/\s+/g, ' ').trim().slice(0, 400);
|
|
1114
|
+
if (/no commits between/i.test(why))
|
|
1115
|
+
return await reportNoChange(s.engineName, s.summary);
|
|
1055
1116
|
return await fail(`The branch ${branch} was pushed, but the pull request could not be created${why ? `: ${why}` : ''}. ` +
|
|
1056
1117
|
`Open it from that branch on GitHub (FireFunc will link it to this task), or re-run.`);
|
|
1057
1118
|
}
|
|
@@ -1108,7 +1169,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1108
1169
|
log(`continuing the session a plan limit cut for this task, in ${worktree}`);
|
|
1109
1170
|
}
|
|
1110
1171
|
else if (toolsOnly) {
|
|
1111
|
-
worktree = mkdtempSync(join(
|
|
1172
|
+
worktree = mkdtempSync(join(scratchRoot(), 'firefunc-tools-'));
|
|
1112
1173
|
updateHeld(rdir, job.runId, { scratch: [worktree] });
|
|
1113
1174
|
writeSkills(worktree, job.skills, log);
|
|
1114
1175
|
const refs = await writeRefs(worktree);
|
|
@@ -1175,7 +1236,9 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1175
1236
|
}
|
|
1176
1237
|
let wt;
|
|
1177
1238
|
try {
|
|
1178
|
-
|
|
1239
|
+
const root = workRoot();
|
|
1240
|
+
wt =
|
|
1241
|
+
root === tmpdir() ? mkdtempSync(join(root, 'firefunc-')) : makeRunFolder(root, job);
|
|
1179
1242
|
}
|
|
1180
1243
|
catch (err) {
|
|
1181
1244
|
const msg = err.message ?? String(err);
|
|
@@ -1196,6 +1259,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1196
1259
|
const add = () => exec('git', ['-C', checkout, 'worktree', 'add', '--force', '-B', branch, wt, startPoint], {
|
|
1197
1260
|
timeoutMs: 120_000,
|
|
1198
1261
|
});
|
|
1262
|
+
await longPaths(checkout);
|
|
1199
1263
|
let result = await add();
|
|
1200
1264
|
const holder = result.code !== 0 ? staleHolder(result.stderr) : null;
|
|
1201
1265
|
let heldBy = null;
|
|
@@ -1207,6 +1271,8 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1207
1271
|
result = await add();
|
|
1208
1272
|
}
|
|
1209
1273
|
}
|
|
1274
|
+
if (result.code === 0)
|
|
1275
|
+
await markRunFolder(wt, job.runId);
|
|
1210
1276
|
return { base: b, wt, add: result, branchMissing: false, startPoint, heldBy, holder };
|
|
1211
1277
|
});
|
|
1212
1278
|
let prep = await prepare();
|
|
@@ -1279,7 +1345,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1279
1345
|
}
|
|
1280
1346
|
const attachPaths = [];
|
|
1281
1347
|
if (job.attachments?.length) {
|
|
1282
|
-
attachDir = mkdtempSync(join(
|
|
1348
|
+
attachDir = mkdtempSync(join(scratchRoot(), 'firefunc-attach-'));
|
|
1283
1349
|
updateHeld(rdir, job.runId, { scratch: [attachDir] });
|
|
1284
1350
|
mkdirSync(attachDir, { recursive: true });
|
|
1285
1351
|
job.attachments.forEach((att, i) => {
|
|
@@ -1444,7 +1510,9 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1444
1510
|
toolsOnly,
|
|
1445
1511
|
});
|
|
1446
1512
|
const carriedNote = carriedNotes.length ? `${carriedNotes.join('\n\n')}\n\n` : '';
|
|
1447
|
-
const
|
|
1513
|
+
const localGrant = localServersFor(loadConfig() ?? cfg, job.localTools);
|
|
1514
|
+
const prompt = (missingLocalToolsNote(localGrant.missing) ?? '') +
|
|
1515
|
+
(restoredFrom ? resumeFromCheckpointBrief(restoredFrom.at) : '') +
|
|
1448
1516
|
rules +
|
|
1449
1517
|
observeNote +
|
|
1450
1518
|
attachNote +
|
|
@@ -1453,12 +1521,13 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1453
1521
|
const tools = cfg.allowedTools ??
|
|
1454
1522
|
'Read Edit Write Bash Glob Grep WebFetch WebSearch Task TodoWrite NotebookEdit';
|
|
1455
1523
|
const isWin = process.platform === 'win32';
|
|
1456
|
-
if (job.mcpConfig != null) {
|
|
1524
|
+
if (job.mcpConfig != null || localGrant.given.length || localGrant.missing.length) {
|
|
1457
1525
|
const format = mcpFormatForEngine(adapter.id);
|
|
1458
1526
|
const dropped = [];
|
|
1459
1527
|
if (format) {
|
|
1460
1528
|
mcp = await prepareMcp({
|
|
1461
|
-
raw: job.mcpConfig,
|
|
1529
|
+
raw: job.mcpConfig ?? null,
|
|
1530
|
+
local: localGrant.given,
|
|
1462
1531
|
worktree,
|
|
1463
1532
|
format,
|
|
1464
1533
|
runId: job.runId,
|
|
@@ -1471,6 +1540,8 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1471
1540
|
else {
|
|
1472
1541
|
for (const id of mcpServerIdsOf(job.mcpConfig))
|
|
1473
1542
|
dropped.push({ id, code: 'engine_has_no_mcp' });
|
|
1543
|
+
for (const l of localGrant.given)
|
|
1544
|
+
dropped.push({ id: l.id, code: 'engine_has_no_mcp' });
|
|
1474
1545
|
log(`mcp: ${adapter.displayName} has no MCP client this runner can configure, so FireFunc's tools are off for this run. Fix: run this agent on Claude Code, Codex, Gemini, Copilot, OpenCode, Cursor or Antigravity.`);
|
|
1475
1546
|
}
|
|
1476
1547
|
log(mcp ? `mcp: ${mcp.logLine}` : 'mcp: no server was injected for this run');
|
|
@@ -1479,7 +1550,15 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1479
1550
|
platform: process.platform,
|
|
1480
1551
|
injected: mcp?.serverIds ?? [],
|
|
1481
1552
|
dropped: dropped.slice(0, 20),
|
|
1553
|
+
...(localGrant.given.length || localGrant.missing.length
|
|
1554
|
+
? {
|
|
1555
|
+
local: localGrant.given.map((l) => l.id).filter((id) => mcp?.serverIds.includes(id)),
|
|
1556
|
+
localMissing: localGrant.missing,
|
|
1557
|
+
}
|
|
1558
|
+
: {}),
|
|
1482
1559
|
});
|
|
1560
|
+
if (localGrant.missing.length)
|
|
1561
|
+
log(`mcp: the agent is granted ${localGrant.missing.join(', ')}, which this machine does not have. Fix: on this machine, firefunc-runner mcp add <name> -- <command…>.`);
|
|
1483
1562
|
}
|
|
1484
1563
|
const temp = makeRunTemp(job.runId);
|
|
1485
1564
|
if (temp) {
|
|
@@ -1568,6 +1647,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1568
1647
|
worktree,
|
|
1569
1648
|
post: (steps) => api.activity(job.runId, steps),
|
|
1570
1649
|
writeTools: new Set(mcp?.writeToolNames ?? []),
|
|
1650
|
+
localServers: new Set(localGrant.given.map((l) => l.id)),
|
|
1571
1651
|
seqStart: activitySeen,
|
|
1572
1652
|
});
|
|
1573
1653
|
for (const name of mcp?.writeToolNames ?? [])
|
|
@@ -1660,6 +1740,12 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1660
1740
|
try {
|
|
1661
1741
|
const r = await runEngineOnce(limitMs);
|
|
1662
1742
|
code = r.code;
|
|
1743
|
+
const named = adapter.resumesSessions ? (adapter.sessionId?.(r.stdout) ?? null) : null;
|
|
1744
|
+
engineSession = {
|
|
1745
|
+
engine: adapter.id,
|
|
1746
|
+
id: named ?? (resumeCut?.sessionId || null),
|
|
1747
|
+
continued: !!resumeCut?.sessionId,
|
|
1748
|
+
};
|
|
1663
1749
|
return r;
|
|
1664
1750
|
}
|
|
1665
1751
|
finally {
|
|
@@ -1918,6 +2004,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1918
2004
|
'.',
|
|
1919
2005
|
':(exclude).env',
|
|
1920
2006
|
':(exclude).claude/skills',
|
|
2007
|
+
`:(exclude,literal)${RUN_MARKER}`,
|
|
1921
2008
|
`:(exclude,literal)${AGENT_PR_FILE}`,
|
|
1922
2009
|
...writtenSkills.pathspecs,
|
|
1923
2010
|
];
|
|
@@ -1999,6 +2086,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1999
2086
|
runId: job.runId,
|
|
2000
2087
|
engine: adapter.id,
|
|
2001
2088
|
sessionId,
|
|
2089
|
+
...(resumeCut?.sessions ? { sessions: resumeCut.sessions } : {}),
|
|
2002
2090
|
repo: job.repo ?? null,
|
|
2003
2091
|
branch: toolsOnly ? '' : branch,
|
|
2004
2092
|
base,
|
|
@@ -2065,9 +2153,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
2065
2153
|
}
|
|
2066
2154
|
if (engineRun.code === 124) {
|
|
2067
2155
|
const keptOnTimeout = keepForNextRun('timeout');
|
|
2068
|
-
const limitWords =
|
|
2069
|
-
? `${engineName} timed out after ${limitMinutes} min — the agent's time budget.`
|
|
2070
|
-
: `${engineName} timed out after ${limitMinutes} min.`;
|
|
2156
|
+
const limitWords = timeoutWords(engineName, limitMinutes, budget, cfg.jobTimeoutMinutes);
|
|
2071
2157
|
return await fail(keptOnTimeout
|
|
2072
2158
|
? `${limitWords} Its work is kept on this machine for a day: Re-run continues it from where it stopped.`
|
|
2073
2159
|
: limitWords);
|
|
@@ -2086,6 +2172,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
2086
2172
|
runId: job.runId,
|
|
2087
2173
|
engine: adapter.id,
|
|
2088
2174
|
sessionId: cutSession ?? '',
|
|
2175
|
+
...(resumeCut?.sessions ? { sessions: resumeCut.sessions } : {}),
|
|
2089
2176
|
repo: job.repo ?? null,
|
|
2090
2177
|
branch: toolsOnly ? '' : branch,
|
|
2091
2178
|
base,
|
|
@@ -2264,14 +2351,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
2264
2351
|
const hinted = scanHints();
|
|
2265
2352
|
if (hinted)
|
|
2266
2353
|
return await report(hinted);
|
|
2267
|
-
|
|
2268
|
-
return await report({
|
|
2269
|
-
status: 'no_pr',
|
|
2270
|
-
error: summary
|
|
2271
|
-
? `No code change made. ${engineName}: ${oneLine(shareable(summary), 800)}`
|
|
2272
|
-
: `${engineName} made no changes (could not reproduce or fix).`,
|
|
2273
|
-
...(summary ? { summary: reportedSummary(summary) } : {}),
|
|
2274
|
-
});
|
|
2354
|
+
return await reportNoChange(engineName, summary);
|
|
2275
2355
|
}
|
|
2276
2356
|
const touched = await exec('git', [
|
|
2277
2357
|
'-C',
|
|
@@ -2287,10 +2367,26 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
2287
2367
|
const agentText = await readFile(join(worktree, AGENT_PR_FILE), 'utf8')
|
|
2288
2368
|
.then((t) => parseAgentPullRequest(blankSecrets(t.slice(0, 70_000))))
|
|
2289
2369
|
.catch(() => null);
|
|
2290
|
-
const title = agentText?.title ?? pullRequestTitle(job, kind);
|
|
2370
|
+
const title = withTicketKey(agentText?.title ?? pullRequestTitle(job, kind), job.ticketKey);
|
|
2291
2371
|
if (agentText)
|
|
2292
2372
|
log(`the agent named the pull request in ${AGENT_PR_FILE}`);
|
|
2293
2373
|
log(`${kind === 'test' ? 'the change touches tests only — ' : ''}titled "${title}"`);
|
|
2374
|
+
if (!continuesBranch) {
|
|
2375
|
+
const staged = await exec('git', ['-C', worktree, 'diff', '--cached', '--quiet', 'HEAD']);
|
|
2376
|
+
const ahead = await exec('git', [
|
|
2377
|
+
'-C',
|
|
2378
|
+
worktree,
|
|
2379
|
+
'rev-list',
|
|
2380
|
+
'--count',
|
|
2381
|
+
`origin/${base}..HEAD`,
|
|
2382
|
+
]);
|
|
2383
|
+
if (staged.code === 0 && ahead.code === 0 && ahead.stdout.trim() === '0') {
|
|
2384
|
+
const hinted = scanHints();
|
|
2385
|
+
if (hinted)
|
|
2386
|
+
return await report(hinted);
|
|
2387
|
+
return await reportNoChange(engineName, summary);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2294
2390
|
const uncommitted = await exec('git', ['-C', worktree, 'diff', '--cached', '--quiet', 'HEAD']);
|
|
2295
2391
|
if (uncommitted.code !== 0) {
|
|
2296
2392
|
const trailers = provenanceTrailers(job);
|
|
@@ -2348,6 +2444,18 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
2348
2444
|
groups: engineGroups.map((g) => ({ ...g, leaderExited: true })),
|
|
2349
2445
|
}, { log }).catch(() => { });
|
|
2350
2446
|
}
|
|
2447
|
+
if (resumeCut?.handedFrom &&
|
|
2448
|
+
!keepWorktree &&
|
|
2449
|
+
worktree &&
|
|
2450
|
+
lastStatus !== 'pr_opened' &&
|
|
2451
|
+
lastStatus !== 'no_pr' &&
|
|
2452
|
+
existsSync(worktree)) {
|
|
2453
|
+
const { handedFrom } = resumeCut;
|
|
2454
|
+
if (saveCut(rdir, handedFrom)) {
|
|
2455
|
+
keepWorktree = true;
|
|
2456
|
+
log(`kept ${handedFrom.engine}'s session for this task: it continues when the task returns to it`);
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2351
2459
|
if (worktree && repoPath && !keepWorktree) {
|
|
2352
2460
|
const checkout = repoPath;
|
|
2353
2461
|
await gitMutex
|
|
@@ -2389,4 +2497,11 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
2389
2497
|
await reportWorktree(api, job.runId, worktree, endedState(worktree, keepWorktree));
|
|
2390
2498
|
}
|
|
2391
2499
|
}
|
|
2500
|
+
export function timeoutWords(engineName, limitMinutes, budget, machineMinutes) {
|
|
2501
|
+
if (budget !== null && limitMinutes === budget)
|
|
2502
|
+
return `${engineName} timed out after ${limitMinutes} min — the agent's time limit. Raise it on the agent (Limits → Time per run).`;
|
|
2503
|
+
if (machineMinutes && limitMinutes === machineMinutes)
|
|
2504
|
+
return `${engineName} timed out after ${limitMinutes} min — this machine's limit (jobTimeoutMinutes${budget !== null ? `, under the agent's ${budget}` : ''}). Raise jobTimeoutMinutes in ~/.firefunc-runner/config.json on this machine, then firefunc-runner restart.`;
|
|
2505
|
+
return `${engineName} timed out after ${limitMinutes} min — the runner's default, as the agent sets no time limit. Set one on the agent (Limits → Time per run).`;
|
|
2506
|
+
}
|
|
2392
2507
|
//# sourceMappingURL=job.js.map
|
package/dist/keep-local.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare const CODE_NOTE = "code kept on the machine";
|
|
|
2
2
|
export declare function codeNote(ref: string | null): string;
|
|
3
3
|
export declare const FORMATTED_NOTE = "[formatted text kept on the machine: read it in the run's session log there]";
|
|
4
4
|
export declare function textCarriesSecret(text: string): boolean;
|
|
5
|
+
export declare function isPlainJson(text: string): boolean;
|
|
5
6
|
export declare function stripCode(text: string): string;
|
|
6
7
|
export declare const UNNAMED_COMMAND = "a command";
|
|
7
8
|
export declare function commandName(command: string): string;
|
package/dist/keep-local.js
CHANGED
|
@@ -101,6 +101,59 @@ function inlineSpan(whole, inner) {
|
|
|
101
101
|
(/\s/.test(inner.trim()) && INLINE_STATEMENT.test(settingsReadOut(inner)));
|
|
102
102
|
return (code && !named) || carriesSecret(inner) ? codeNote(null) : whole;
|
|
103
103
|
}
|
|
104
|
+
const JSON_MAX_CHARS = 200_000;
|
|
105
|
+
function jsonCarriesSecret(v, depth = 0) {
|
|
106
|
+
if (depth > 40)
|
|
107
|
+
return true;
|
|
108
|
+
if (typeof v === 'string')
|
|
109
|
+
return carriesSecret(v);
|
|
110
|
+
if (Array.isArray(v))
|
|
111
|
+
return v.some((x) => jsonCarriesSecret(x, depth + 1));
|
|
112
|
+
if (v && typeof v === 'object')
|
|
113
|
+
return Object.entries(v).some(([k, x]) => carriesSecret(k) || jsonCarriesSecret(x, depth + 1));
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
export function isPlainJson(text) {
|
|
117
|
+
const t = text.trim();
|
|
118
|
+
if (t.length < 2 || t.length > JSON_MAX_CHARS)
|
|
119
|
+
return false;
|
|
120
|
+
if (!((t[0] === '{' && t.endsWith('}')) || (t[0] === '[' && t.endsWith(']'))))
|
|
121
|
+
return false;
|
|
122
|
+
try {
|
|
123
|
+
const v = JSON.parse(t);
|
|
124
|
+
return typeof v === 'object' && v !== null && !jsonCarriesSecret(v);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function jsonBlockEnd(lines, i) {
|
|
131
|
+
const first = lines[i].trim();
|
|
132
|
+
if (first[0] !== '{' && first[0] !== '[')
|
|
133
|
+
return null;
|
|
134
|
+
let text = '';
|
|
135
|
+
for (let j = i; j < lines.length && j < i + 2000; j++) {
|
|
136
|
+
text += (j > i ? '\n' : '') + lines[j];
|
|
137
|
+
if (text.length > JSON_MAX_CHARS)
|
|
138
|
+
return null;
|
|
139
|
+
const t = lines[j].trim();
|
|
140
|
+
if ((t.endsWith('}') || t.endsWith(']')) && isPlainJson(text))
|
|
141
|
+
return j + 1;
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
function endsInJson(line) {
|
|
146
|
+
const t = line.trimEnd();
|
|
147
|
+
if (!t.endsWith('}') && !t.endsWith(']'))
|
|
148
|
+
return false;
|
|
149
|
+
for (let k = 0; k < t.length; k++) {
|
|
150
|
+
if ((t[k] === '{' || t[k] === '[') && (k === 0 || /[\s:=(,]/.test(t[k - 1]))) {
|
|
151
|
+
if (isPlainJson(t.slice(k)))
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
104
157
|
export function stripCode(text) {
|
|
105
158
|
if (!text)
|
|
106
159
|
return text;
|
|
@@ -141,6 +194,16 @@ export function stripCode(text) {
|
|
|
141
194
|
for (let i = 0; i < fenced.length; i++) {
|
|
142
195
|
const line = fenced[i];
|
|
143
196
|
const prev = out.length ? out[out.length - 1] : '';
|
|
197
|
+
const jsonEnd = jsonBlockEnd(fenced, i);
|
|
198
|
+
if (jsonEnd !== null) {
|
|
199
|
+
fenced.slice(i, jsonEnd).forEach(keep);
|
|
200
|
+
i = jsonEnd - 1;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (endsInJson(line)) {
|
|
204
|
+
keep(line);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
144
207
|
if (DIFF_HEAD.test(line)) {
|
|
145
208
|
let end = i + 1;
|
|
146
209
|
for (; end < fenced.length; end++) {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AliveRecord } from './alive.js';
|
|
2
|
+
export type LiveRunnerDeps = {
|
|
3
|
+
os: 'darwin' | 'linux' | 'win32' | null;
|
|
4
|
+
readAlive: () => AliveRecord | null;
|
|
5
|
+
pidAlive: (pid: number) => boolean;
|
|
6
|
+
exec: (cmd: string, args: string[]) => Promise<{
|
|
7
|
+
code: number;
|
|
8
|
+
out: string;
|
|
9
|
+
}>;
|
|
10
|
+
signal: (pid: number, sig: 'SIGTERM' | 'SIGKILL') => void;
|
|
11
|
+
service: {
|
|
12
|
+
stop: () => Promise<{
|
|
13
|
+
ok: boolean;
|
|
14
|
+
message: string;
|
|
15
|
+
}>;
|
|
16
|
+
start: () => Promise<{
|
|
17
|
+
ok: boolean;
|
|
18
|
+
message: string;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
sleep: (ms: number) => Promise<void>;
|
|
22
|
+
now: () => number;
|
|
23
|
+
graceMs?: number;
|
|
24
|
+
startMs?: number;
|
|
25
|
+
pollMs?: number;
|
|
26
|
+
};
|
|
27
|
+
export type StopResult = {
|
|
28
|
+
ok: boolean;
|
|
29
|
+
message: string;
|
|
30
|
+
pid: number | null;
|
|
31
|
+
version: string | null;
|
|
32
|
+
};
|
|
33
|
+
export declare function endLiveRunner(d: LiveRunnerDeps): Promise<StopResult>;
|
|
34
|
+
export declare function stopRunner(d: LiveRunnerDeps): Promise<{
|
|
35
|
+
ok: boolean;
|
|
36
|
+
message: string;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function startRunner(d: LiveRunnerDeps, want: string | null): Promise<{
|
|
39
|
+
ok: boolean;
|
|
40
|
+
message: string;
|
|
41
|
+
pid: number | null;
|
|
42
|
+
}>;
|
|
43
|
+
export declare function versionGapWords(installed: string, running: AliveRecord | null): string | null;
|
|
44
|
+
export declare function windowsRestartLater(taskName: string, delaySeconds?: number): {
|
|
45
|
+
cmd: string;
|
|
46
|
+
args: string[];
|
|
47
|
+
};
|