@firefunc-agent/runner 0.7.0 → 0.9.0
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/LICENSE +7 -3
- package/README.md +233 -3
- package/dist/activity.d.ts +29 -0
- package/dist/activity.js +209 -0
- package/dist/api.d.ts +45 -1
- package/dist/api.js +44 -2
- package/dist/brief.d.ts +6 -0
- package/dist/brief.js +257 -0
- package/dist/build-info.json +4 -0
- package/dist/cli.js +49 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +3 -0
- package/dist/daemon.js +70 -2
- package/dist/engines/antigravity.d.ts +2 -0
- package/dist/engines/antigravity.js +102 -0
- package/dist/engines/claude-budget.d.ts +1 -1
- package/dist/engines/claude-budget.js +2 -72
- package/dist/engines/claude.js +10 -1
- package/dist/engines/codex.js +10 -3
- package/dist/engines/copilot.d.ts +2 -0
- package/dist/engines/copilot.js +117 -0
- package/dist/engines/cursor.js +4 -0
- package/dist/engines/gemini.js +6 -1
- package/dist/engines/index.d.ts +2 -0
- package/dist/engines/index.js +22 -4
- package/dist/engines/types.d.ts +2 -1
- package/dist/firefunc/agents.d.ts +2 -0
- package/dist/firefunc/agents.js +291 -0
- package/dist/firefunc/args.d.ts +18 -0
- package/dist/firefunc/args.js +82 -0
- package/dist/firefunc/auth.d.ts +21 -0
- package/dist/firefunc/auth.js +129 -0
- package/dist/firefunc/catalog.d.ts +10 -0
- package/dist/firefunc/catalog.js +201 -0
- package/dist/firefunc/cli.d.ts +2 -0
- package/dist/firefunc/cli.js +24 -0
- package/dist/firefunc/client.d.ts +35 -0
- package/dist/firefunc/client.js +174 -0
- package/dist/firefunc/command.d.ts +28 -0
- package/dist/firefunc/command.js +35 -0
- package/dist/firefunc/config.d.ts +29 -0
- package/dist/firefunc/config.js +111 -0
- package/dist/firefunc/io.d.ts +25 -0
- package/dist/firefunc/io.js +14 -0
- package/dist/firefunc/main.d.ts +4 -0
- package/dist/firefunc/main.js +221 -0
- package/dist/firefunc/output.d.ts +29 -0
- package/dist/firefunc/output.js +128 -0
- package/dist/firefunc/prompt.d.ts +14 -0
- package/dist/firefunc/prompt.js +58 -0
- package/dist/firefunc/skill.d.ts +3 -0
- package/dist/firefunc/skill.js +80 -0
- package/dist/firefunc/tasks.d.ts +2 -0
- package/dist/firefunc/tasks.js +279 -0
- package/dist/firefunc/version.d.ts +2 -0
- package/dist/firefunc/version.js +23 -0
- package/dist/git-auth.d.ts +4 -1
- package/dist/git-auth.js +6 -2
- package/dist/job.js +476 -83
- package/dist/keep-local.d.ts +7 -0
- package/dist/keep-local.js +484 -0
- package/dist/machine-logins.d.ts +19 -0
- package/dist/machine-logins.js +187 -0
- package/dist/mcp-login.d.ts +24 -0
- package/dist/mcp-login.js +993 -0
- package/dist/mcp.d.ts +60 -0
- package/dist/mcp.js +582 -0
- package/dist/network.d.ts +20 -0
- package/dist/network.js +76 -0
- package/dist/pending.d.ts +14 -0
- package/dist/pending.js +56 -0
- package/dist/secret-scan.d.ts +19 -0
- package/dist/secret-scan.js +161 -0
- package/dist/session-stream.d.ts +1 -0
- package/dist/session-stream.js +11 -1
- package/dist/viewer.js +11 -1
- package/package.json +7 -4
- package/skill/firefunc/SKILL.md +173 -0
package/dist/api.js
CHANGED
|
@@ -44,6 +44,15 @@ export class RunnerApi {
|
|
|
44
44
|
return [];
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
async probe() {
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetch(`${this.apiUrl}/channel/config`, { headers: this.headers() });
|
|
50
|
+
return res.ok || res.status === 401;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
47
56
|
async config() {
|
|
48
57
|
try {
|
|
49
58
|
const res = await fetch(`${this.apiUrl}/channel/config`, { headers: this.headers() });
|
|
@@ -74,6 +83,24 @@ export class RunnerApi {
|
|
|
74
83
|
return null;
|
|
75
84
|
}
|
|
76
85
|
}
|
|
86
|
+
async mcpCredential(runId, server) {
|
|
87
|
+
try {
|
|
88
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/mcp-credential`, {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
headers: this.headers(),
|
|
91
|
+
body: JSON.stringify({ server }),
|
|
92
|
+
});
|
|
93
|
+
if (!res.ok)
|
|
94
|
+
return null;
|
|
95
|
+
const body = (await res.json());
|
|
96
|
+
if (!body.ok || !body.token)
|
|
97
|
+
return null;
|
|
98
|
+
return { token: body.token, expiresAt: body.expiresAt };
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
77
104
|
async event(runId, event, detail) {
|
|
78
105
|
await fetch(`${this.apiUrl}/channel/runs/${runId}/events`, {
|
|
79
106
|
method: 'POST',
|
|
@@ -81,12 +108,27 @@ export class RunnerApi {
|
|
|
81
108
|
body: JSON.stringify({ event, detail }),
|
|
82
109
|
}).catch(() => { });
|
|
83
110
|
}
|
|
111
|
+
async activity(runId, steps) {
|
|
112
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/activity`, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: this.headers(),
|
|
115
|
+
body: JSON.stringify({ steps }),
|
|
116
|
+
});
|
|
117
|
+
if (!res.ok)
|
|
118
|
+
throw new Error(`activity post failed: ${res.status}`);
|
|
119
|
+
}
|
|
84
120
|
async result(runId, payload) {
|
|
85
|
-
const
|
|
121
|
+
const post = (body) => fetch(`${this.apiUrl}/channel/runs/${runId}/result`, {
|
|
86
122
|
method: 'POST',
|
|
87
123
|
headers: this.headers(),
|
|
88
|
-
body: JSON.stringify(
|
|
124
|
+
body: JSON.stringify(body),
|
|
89
125
|
});
|
|
126
|
+
let res = await post(payload);
|
|
127
|
+
if (res.status === 400 && payload.secretScan) {
|
|
128
|
+
const bare = { ...payload };
|
|
129
|
+
delete bare.secretScan;
|
|
130
|
+
res = await post(bare);
|
|
131
|
+
}
|
|
90
132
|
if (!res.ok)
|
|
91
133
|
throw new Error(`result report failed: ${res.status}`);
|
|
92
134
|
}
|
package/dist/brief.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import type { ClaimedJob } from './api.js';
|
|
1
2
|
import type { RunnerConfig } from './config.js';
|
|
3
|
+
export declare function scanBeforePush(worktree: string, from: string, branch: string): Promise<{
|
|
4
|
+
refusal: string | null;
|
|
5
|
+
note: string | null;
|
|
6
|
+
}>;
|
|
2
7
|
export declare function runBrief(repo: string, cfg: RunnerConfig): Promise<void>;
|
|
8
|
+
export declare function renderJobBrief(job: ClaimedJob): string;
|
package/dist/brief.js
CHANGED
|
@@ -3,6 +3,7 @@ import { tmpdir } from 'node:os';
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { exec, execOut } from './exec.js';
|
|
5
5
|
import { resolveRepoPath } from './job.js';
|
|
6
|
+
import { changeReads, hardFirst, refusesPush, scanAddedLines, secretRefusal, uniqueHits, } from './secret-scan.js';
|
|
6
7
|
function out(msg) {
|
|
7
8
|
process.stdout.write(`${msg}\n`);
|
|
8
9
|
}
|
|
@@ -19,6 +20,33 @@ If a CLAUDE.md already exists at the repo root, only improve it where it is clea
|
|
|
19
20
|
- A "how to make a good autonomous fix" checklist: localize to the smallest correct change, add a test, run the gate locally, keep the diff reviewable (it ships as a draft PR).
|
|
20
21
|
|
|
21
22
|
CRITICAL: state only what you can VERIFY from the code — read package.json scripts, CI workflows, and the source before asserting a command or convention. Do not hallucinate. Do NOT modify any file other than CLAUDE.md.`;
|
|
23
|
+
export async function scanBeforePush(worktree, from, branch) {
|
|
24
|
+
const reads = changeReads(from, branch);
|
|
25
|
+
const read = (args) => exec('git', ['-C', worktree, ...args], { timeoutMs: 120_000, env: reads.env }).catch((e) => ({ code: 1, stdout: '', stderr: e.message }));
|
|
26
|
+
const whole = await read(reads.whole);
|
|
27
|
+
const commits = whole.code === 0 ? await read(reads.commits) : whole;
|
|
28
|
+
if (whole.code !== 0 || commits.code !== 0) {
|
|
29
|
+
const failed = whole.code !== 0 ? whole : commits;
|
|
30
|
+
return {
|
|
31
|
+
refusal: `Not pushing: the change could not be read to scan it for secrets (git exit ${failed.code}: ${failed.stderr.trim().slice(0, 200)}). ` +
|
|
32
|
+
`The commit stays on the local branch ${branch}: look it over with \`git show ${branch}\` and push it yourself, or run brief again.`,
|
|
33
|
+
note: null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const hits = hardFirst(uniqueHits([...scanAddedLines(whole.stdout), ...scanAddedLines(commits.stdout)]));
|
|
37
|
+
if (hits.some(refusesPush))
|
|
38
|
+
return { refusal: secretRefusal(hits, branch), note: null };
|
|
39
|
+
if (hits.length === 0)
|
|
40
|
+
return { refusal: null, note: null };
|
|
41
|
+
const named = hits
|
|
42
|
+
.slice(0, 5)
|
|
43
|
+
.map((h) => `${h.kind} at ${h.path}:${h.line}`)
|
|
44
|
+
.join(', ');
|
|
45
|
+
return {
|
|
46
|
+
refusal: null,
|
|
47
|
+
note: `The secret scan found a value set to a secret-looking name (${named}) — pushing; check it is a placeholder before you merge.`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
22
50
|
export async function runBrief(repo, cfg) {
|
|
23
51
|
const repoPath = resolveRepoPath(repo, cfg);
|
|
24
52
|
if (!repoPath) {
|
|
@@ -95,6 +123,14 @@ export async function runBrief(repo, cfg) {
|
|
|
95
123
|
'docs: add CLAUDE.md runner briefing',
|
|
96
124
|
'--quiet',
|
|
97
125
|
]);
|
|
126
|
+
const scan = await scanBeforePush(worktree, `origin/${base}`, branch);
|
|
127
|
+
if (scan.refusal) {
|
|
128
|
+
out(scan.refusal);
|
|
129
|
+
process.exitCode = 1;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (scan.note)
|
|
133
|
+
out(scan.note);
|
|
98
134
|
const push = await exec('git', ['-C', worktree, 'push', '--force-with-lease', 'origin', `${branch}:${branch}`], { timeoutMs: 120_000 });
|
|
99
135
|
if (push.code !== 0) {
|
|
100
136
|
out(`git push failed: ${push.stderr.slice(0, 300)}`);
|
|
@@ -135,4 +171,225 @@ export async function runBrief(repo, cfg) {
|
|
|
135
171
|
}
|
|
136
172
|
}
|
|
137
173
|
}
|
|
174
|
+
function packRecord(value) {
|
|
175
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
176
|
+
? value
|
|
177
|
+
: null;
|
|
178
|
+
}
|
|
179
|
+
function packString(value) {
|
|
180
|
+
return typeof value === 'string' && value.trim() !== '' ? value : null;
|
|
181
|
+
}
|
|
182
|
+
function packNumber(value) {
|
|
183
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
184
|
+
}
|
|
185
|
+
function packList(value) {
|
|
186
|
+
return Array.isArray(value) ? value : [];
|
|
187
|
+
}
|
|
188
|
+
function packStrings(value) {
|
|
189
|
+
return packList(value)
|
|
190
|
+
.map(packString)
|
|
191
|
+
.filter((s) => s !== null);
|
|
192
|
+
}
|
|
193
|
+
function cutLine(entry) {
|
|
194
|
+
const t = packRecord(entry);
|
|
195
|
+
const name = packString(t?.section);
|
|
196
|
+
if (!name)
|
|
197
|
+
return null;
|
|
198
|
+
const included = packNumber(t?.included);
|
|
199
|
+
const total = packNumber(t?.total);
|
|
200
|
+
return included !== null && total !== null
|
|
201
|
+
? ` [cut] ${name}: ${included} of ${total} included — the rest exists and was not sent.`
|
|
202
|
+
: ` [cut] ${name}: truncated — part of this section was not sent.`;
|
|
203
|
+
}
|
|
204
|
+
function cutLines(truncations, section) {
|
|
205
|
+
return truncations
|
|
206
|
+
.filter((entry) => {
|
|
207
|
+
const name = packString(packRecord(entry)?.section);
|
|
208
|
+
return name !== null && (name === section || name.startsWith(`${section}.`));
|
|
209
|
+
})
|
|
210
|
+
.map(cutLine)
|
|
211
|
+
.filter((l) => l !== null);
|
|
212
|
+
}
|
|
213
|
+
function spent(perSection, section) {
|
|
214
|
+
const bytes = packNumber(perSection?.[section]);
|
|
215
|
+
return bytes === null ? '' : ` — ${bytes} bytes`;
|
|
216
|
+
}
|
|
217
|
+
export function renderJobBrief(job) {
|
|
218
|
+
const pack = packRecord(job.contextPack);
|
|
219
|
+
if (!pack)
|
|
220
|
+
return job.prompt;
|
|
221
|
+
const budget = packRecord(pack.budget);
|
|
222
|
+
const perSection = packRecord(budget?.perSectionBytes);
|
|
223
|
+
const truncations = packList(budget?.truncations);
|
|
224
|
+
const blocks = [];
|
|
225
|
+
const rendered = new Set();
|
|
226
|
+
const event = packRecord(pack.event);
|
|
227
|
+
if (event) {
|
|
228
|
+
rendered.add('event');
|
|
229
|
+
const lines = [];
|
|
230
|
+
const tool = packString(event.tool);
|
|
231
|
+
const kind = packString(event.kind);
|
|
232
|
+
const account = packString(event.accountLabel);
|
|
233
|
+
const scope = packStrings(event.scopePath);
|
|
234
|
+
const occurred = packString(event.occurredAt);
|
|
235
|
+
const actor = packRecord(event.actor);
|
|
236
|
+
if (tool)
|
|
237
|
+
lines.push(` Tool: ${tool}`);
|
|
238
|
+
if (kind)
|
|
239
|
+
lines.push(` Event: ${kind}`);
|
|
240
|
+
if (account)
|
|
241
|
+
lines.push(` Account: ${account}`);
|
|
242
|
+
if (scope.length > 0)
|
|
243
|
+
lines.push(` Scope: ${scope.join(' / ')}`);
|
|
244
|
+
if (occurred)
|
|
245
|
+
lines.push(` Occurred: ${occurred}`);
|
|
246
|
+
if (actor) {
|
|
247
|
+
const who = packString(actor.displayName) ?? packString(actor.externalId);
|
|
248
|
+
if (who)
|
|
249
|
+
lines.push(` Actor: ${who}${actor.isBot === true ? ' (bot)' : ''}`);
|
|
250
|
+
}
|
|
251
|
+
const changes = packList(event.changes).length;
|
|
252
|
+
if (changes > 0)
|
|
253
|
+
lines.push(` Changed fields: ${changes}`);
|
|
254
|
+
lines.push(...cutLines(truncations, 'event'));
|
|
255
|
+
if (lines.length > 0)
|
|
256
|
+
blocks.push(`## Event${spent(perSection, 'event')}\n${lines.join('\n')}`);
|
|
257
|
+
}
|
|
258
|
+
const subject = packRecord(pack.subject);
|
|
259
|
+
if (subject) {
|
|
260
|
+
rendered.add('subject');
|
|
261
|
+
const lines = [];
|
|
262
|
+
const title = packString(subject.title);
|
|
263
|
+
const externalId = packString(subject.externalId);
|
|
264
|
+
const url = packString(subject.externalUrl);
|
|
265
|
+
const type = packString(subject.type);
|
|
266
|
+
const state = packString(subject.state);
|
|
267
|
+
const stateCategory = packString(subject.stateCategory);
|
|
268
|
+
const severity = packString(subject.severity);
|
|
269
|
+
const labels = packStrings(subject.labels);
|
|
270
|
+
const reporter = packString(subject.reporter);
|
|
271
|
+
const assignee = packString(subject.assignee);
|
|
272
|
+
const body = packString(subject.body);
|
|
273
|
+
if (title)
|
|
274
|
+
lines.push(` Title: ${title}`);
|
|
275
|
+
if (externalId)
|
|
276
|
+
lines.push(` Id: ${externalId}`);
|
|
277
|
+
if (type)
|
|
278
|
+
lines.push(` Type: ${type}`);
|
|
279
|
+
if (url)
|
|
280
|
+
lines.push(` URL: ${url}`);
|
|
281
|
+
if (state)
|
|
282
|
+
lines.push(` State: ${state}${stateCategory ? ` (${stateCategory})` : ''}`);
|
|
283
|
+
if (severity)
|
|
284
|
+
lines.push(` Severity: ${severity}`);
|
|
285
|
+
if (labels.length > 0)
|
|
286
|
+
lines.push(` Labels: ${labels.join(', ')}`);
|
|
287
|
+
if (reporter)
|
|
288
|
+
lines.push(` Reporter: ${reporter}`);
|
|
289
|
+
if (assignee)
|
|
290
|
+
lines.push(` Assignee: ${assignee}`);
|
|
291
|
+
if (body)
|
|
292
|
+
lines.push(` Body: ${body.length} characters`);
|
|
293
|
+
lines.push(...cutLines(truncations, 'subject'));
|
|
294
|
+
if (lines.length > 0)
|
|
295
|
+
blocks.push(`## Item${spent(perSection, 'subject')}\n${lines.join('\n')}`);
|
|
296
|
+
}
|
|
297
|
+
else if ('subject' in pack) {
|
|
298
|
+
rendered.add('subject');
|
|
299
|
+
blocks.push('## Item\n No source item was resolved for this run.');
|
|
300
|
+
}
|
|
301
|
+
const repo = packRecord(pack.repo);
|
|
302
|
+
if (repo) {
|
|
303
|
+
rendered.add('repo');
|
|
304
|
+
const lines = [];
|
|
305
|
+
const name = packString(repo.repo);
|
|
306
|
+
const baseBranch = packString(repo.baseBranch);
|
|
307
|
+
const offLimits = packStrings(repo.offLimitsPaths);
|
|
308
|
+
if (name)
|
|
309
|
+
lines.push(` Repository: ${name}`);
|
|
310
|
+
if (baseBranch)
|
|
311
|
+
lines.push(` Base branch: ${baseBranch}`);
|
|
312
|
+
if (offLimits.length > 0)
|
|
313
|
+
lines.push(` Off-limits paths: ${offLimits.join(', ')}`);
|
|
314
|
+
lines.push(...cutLines(truncations, 'repo'));
|
|
315
|
+
if (lines.length > 0) {
|
|
316
|
+
blocks.push(`## Repository${spent(perSection, 'repo')}\n${lines.join('\n')}`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const instruction = packRecord(pack.instruction);
|
|
320
|
+
if (instruction) {
|
|
321
|
+
rendered.add('instruction');
|
|
322
|
+
const lines = [];
|
|
323
|
+
const handle = packString(instruction.handle);
|
|
324
|
+
const triggeredBy = packString(instruction.triggeredBy);
|
|
325
|
+
const text = packString(instruction.text);
|
|
326
|
+
if (handle)
|
|
327
|
+
lines.push(` Addressed to: ${handle}`);
|
|
328
|
+
if (triggeredBy)
|
|
329
|
+
lines.push(` Triggered by: ${triggeredBy}`);
|
|
330
|
+
if (text)
|
|
331
|
+
lines.push(` Instruction text: ${text.length} characters`);
|
|
332
|
+
lines.push(...cutLines(truncations, 'instruction'));
|
|
333
|
+
if (lines.length > 0) {
|
|
334
|
+
blocks.push(`## Instruction${spent(perSection, 'instruction')}\n${lines.join('\n')}`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const related = Object.entries(packRecord(pack.related) ?? {});
|
|
338
|
+
const relatedCuts = cutLines(truncations, 'related');
|
|
339
|
+
if (related.length > 0 || relatedCuts.length > 0) {
|
|
340
|
+
rendered.add('related');
|
|
341
|
+
const lines = related.map(([tool, value]) => {
|
|
342
|
+
const entries = Array.isArray(value) ? ` (${value.length} entries)` : '';
|
|
343
|
+
return ` - ${tool}${entries}`;
|
|
344
|
+
});
|
|
345
|
+
if (lines.length === 0)
|
|
346
|
+
lines.push(' - nothing from another tool fit the budget');
|
|
347
|
+
lines.push(...relatedCuts);
|
|
348
|
+
blocks.push(`## Related context${spent(perSection, 'related')}\n${lines.join('\n')}`);
|
|
349
|
+
}
|
|
350
|
+
const attachments = packList(pack.attachments);
|
|
351
|
+
const attachmentCuts = cutLines(truncations, 'attachments');
|
|
352
|
+
if (attachments.length > 0 || attachmentCuts.length > 0) {
|
|
353
|
+
rendered.add('attachments');
|
|
354
|
+
const lines = attachments.map((entry) => {
|
|
355
|
+
const a = packRecord(entry);
|
|
356
|
+
const name = packString(a?.filename) ?? 'attachment';
|
|
357
|
+
const withheld = packString(a?.withheldReason);
|
|
358
|
+
if (withheld)
|
|
359
|
+
return ` - ${name}: withheld — ${withheld}`;
|
|
360
|
+
const size = packNumber(a?.size);
|
|
361
|
+
return ` - ${name}${size === null ? '' : ` (${size} bytes)`}`;
|
|
362
|
+
});
|
|
363
|
+
lines.push(...attachmentCuts);
|
|
364
|
+
blocks.push(`## Attachments${spent(perSection, 'attachments')}\n${lines.join('\n')}`);
|
|
365
|
+
}
|
|
366
|
+
if (job.skills && job.skills.length > 0) {
|
|
367
|
+
const lines = job.skills.map((s) => ` - ${s.name} (.claude/skills/${s.slug}/SKILL.md)${s.description ? ` — ${s.description}` : ''}`);
|
|
368
|
+
blocks.push(`## Skills\nThese skills are installed in this worktree for this run. Read the ones whose description applies before you start, and follow them:\n${lines.join('\n')}`);
|
|
369
|
+
}
|
|
370
|
+
const orphaned = truncations.filter((entry) => {
|
|
371
|
+
const name = packString(packRecord(entry)?.section);
|
|
372
|
+
return name !== null && !rendered.has(name.split('.')[0] ?? name);
|
|
373
|
+
});
|
|
374
|
+
if (orphaned.length > 0) {
|
|
375
|
+
const lines = orphaned.map(cutLine).filter((l) => l !== null);
|
|
376
|
+
blocks.push(`## Also cut\n${lines.join('\n')}`);
|
|
377
|
+
}
|
|
378
|
+
if (blocks.length === 0) {
|
|
379
|
+
return ('Context pack: this runner recognizes nothing in the pack the server sent, so it ' +
|
|
380
|
+
'cannot describe it. The engine still received the flat rendering as its prompt — ' +
|
|
381
|
+
'nothing was lost. To see the inventory, update the runner: ' +
|
|
382
|
+
'npm install -g @firefunc-agent/runner');
|
|
383
|
+
}
|
|
384
|
+
const total = packNumber(budget?.totalBytes);
|
|
385
|
+
const footer = truncations.length > 0
|
|
386
|
+
? 'Sections marked [cut] did not fit their budget.'
|
|
387
|
+
: 'No cuts are recorded in the pack.';
|
|
388
|
+
blocks.push(total === null ? footer : `Pack total: ${total} bytes. ${footer}`);
|
|
389
|
+
return [
|
|
390
|
+
'Context pack for this run — what FireFunc assembled for the engine ' +
|
|
391
|
+
"(the prompt it receives is the server's flat rendering of these same sections):",
|
|
392
|
+
...blocks,
|
|
393
|
+
].join('\n\n');
|
|
394
|
+
}
|
|
138
395
|
//# sourceMappingURL=brief.js.map
|
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { expandHome, loadConfig, saveConfig, configPath } from './config.js';
|
|
3
3
|
import { startDaemon } from './daemon.js';
|
|
4
4
|
import { runBrief } from './brief.js';
|
|
5
|
+
import { runMcpList, runMcpLogin, runMcpLogout } from './mcp-login.js';
|
|
5
6
|
import { currentPlatform, defaultServiceDeps, EPHEMERAL_INSTALL_MESSAGE, installService, isEphemeralInstall, readLogTail, renderLaunchdPlist, renderSystemdUnit, renderWindowsTaskXml, serviceStatus, servicePaths, startService, stopService, uninstallService, } from './service.js';
|
|
6
7
|
const HELP = `firefunc-runner — run YOUR local coding agent on work FireFunc routes to you.
|
|
7
8
|
(Claude Code, OpenAI Codex, Gemini CLI or Cursor CLI — whichever you have installed.)
|
|
@@ -17,6 +18,9 @@ Usage:
|
|
|
17
18
|
firefunc-runner logs Show recent runner output
|
|
18
19
|
firefunc-runner uninstall Remove the background service
|
|
19
20
|
firefunc-runner status Show the saved config + service state
|
|
21
|
+
firefunc-runner mcp login <tool> Sign THIS machine in to a tool's MCP server
|
|
22
|
+
firefunc-runner mcp list Which MCP servers this machine is signed in to
|
|
23
|
+
firefunc-runner mcp logout <tool> Forget one MCP sign-in
|
|
20
24
|
firefunc-runner --help
|
|
21
25
|
|
|
22
26
|
After "connect", run "install" once. The runner then starts at login/boot and
|
|
@@ -76,11 +80,26 @@ dev-environment (so Claude can REPRODUCE bugs live, not just read code):
|
|
|
76
80
|
--setup-timeout <min> Timeout for all setup commands (default: job timeout)
|
|
77
81
|
--no-auto-install Skip auto npm/pnpm/yarn install (default: auto-install deps when no --setup given)
|
|
78
82
|
|
|
83
|
+
mcp (let an agent look things up live in a tool, mid-run — the ticket next to
|
|
84
|
+
this one, the newest event on the issue):
|
|
85
|
+
mcp login <tool> Sign THIS MACHINE in to that tool's MCP server. The sign-in
|
|
86
|
+
happens in your browser, on your machine, and the token is
|
|
87
|
+
cached here, readable only by you — it is never sent to
|
|
88
|
+
FireFunc. Each machine running a runner needs its own.
|
|
89
|
+
mcp list What this machine is signed in to, and when each expires.
|
|
90
|
+
mcp logout <tool> Forget one sign-in (and revoke it where the vendor allows).
|
|
91
|
+
--no-browser Print the sign-in URL instead of opening a browser. Used
|
|
92
|
+
automatically on a headless box, which is also told so
|
|
93
|
+
rather than left waiting for a window that never opens.
|
|
94
|
+
GitHub needs no login: FireFunc mints it a read-only, one-repo, one-hour token
|
|
95
|
+
per run — narrower than any machine-wide sign-in could be.
|
|
96
|
+
|
|
79
97
|
Examples:
|
|
80
98
|
firefunc-runner connect ffr_xxx --repos-dir ~/code
|
|
81
99
|
firefunc-runner connect ffr_xxx --repo acme/api=/Users/me/code/api
|
|
82
100
|
firefunc-runner connect ffr_xxx --env AWS_PROFILE=app-ro --setup "npm ci" --bg "npm run dev"
|
|
83
101
|
firefunc-runner install
|
|
102
|
+
firefunc-runner mcp login jira
|
|
84
103
|
`;
|
|
85
104
|
function parseFlags(args) {
|
|
86
105
|
const out = {};
|
|
@@ -220,6 +239,36 @@ async function main() {
|
|
|
220
239
|
await runBrief(repo, cfg);
|
|
221
240
|
return;
|
|
222
241
|
}
|
|
242
|
+
if (cmd === 'mcp') {
|
|
243
|
+
const f = parseFlags(rest);
|
|
244
|
+
const positional = rest.filter((a) => !a.startsWith('--'));
|
|
245
|
+
const sub = positional[0];
|
|
246
|
+
const tool = positional[1];
|
|
247
|
+
if (sub === 'list') {
|
|
248
|
+
runMcpList();
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (sub === 'login' || sub === 'logout') {
|
|
252
|
+
if (!tool) {
|
|
253
|
+
process.stderr.write(`Usage: firefunc-runner mcp ${sub} <tool>\n` +
|
|
254
|
+
`Example: firefunc-runner mcp ${sub} jira\n` +
|
|
255
|
+
`Which tools this machine can sign in to: firefunc-runner mcp list\n`);
|
|
256
|
+
process.exitCode = 1;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (sub === 'login')
|
|
260
|
+
await runMcpLogin(tool, { noBrowser: Boolean(f['no-browser']) });
|
|
261
|
+
else
|
|
262
|
+
await runMcpLogout(tool);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
process.stderr.write(`Usage: firefunc-runner mcp <login|list|logout> [tool]\n` +
|
|
266
|
+
` firefunc-runner mcp login jira sign THIS machine in to Jira's MCP server\n` +
|
|
267
|
+
` firefunc-runner mcp list what this machine is signed in to\n` +
|
|
268
|
+
` firefunc-runner mcp logout jira forget that sign-in\n`);
|
|
269
|
+
process.exitCode = 1;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
223
272
|
if (cmd === 'status') {
|
|
224
273
|
const cfg = loadConfig();
|
|
225
274
|
if (!cfg) {
|
package/dist/config.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export type RunnerConfig = {
|
|
|
13
13
|
geminiBin?: string;
|
|
14
14
|
geminiApiKey?: string;
|
|
15
15
|
geminiArgs?: string[];
|
|
16
|
+
antigravityBin?: string;
|
|
17
|
+
antigravityArgs?: string[];
|
|
18
|
+
copilotBin?: string;
|
|
19
|
+
copilotArgs?: string[];
|
|
16
20
|
cursorAgentBin?: string;
|
|
17
21
|
cursorApiKey?: string;
|
|
18
22
|
cursorArgs?: string[];
|
|
@@ -41,3 +45,4 @@ export type RunnerConfig = {
|
|
|
41
45
|
export declare function configPath(): string;
|
|
42
46
|
export declare function loadConfig(): RunnerConfig | null;
|
|
43
47
|
export declare function saveConfig(cfg: RunnerConfig): void;
|
|
48
|
+
export declare function runnerDir(): string;
|
package/dist/config.js
CHANGED
package/dist/daemon.js
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
|
+
import { flushPendingResults } from './pending.js';
|
|
2
|
+
import { runnerDir } from './config.js';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
1
4
|
import { hostname, platform } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
2
7
|
import { RunnerApi } from './api.js';
|
|
3
8
|
import { availableEngines, getAdapter, supportedEngines } from './engines/index.js';
|
|
4
9
|
import { runJob, resolveRepoPath } from './job.js';
|
|
5
10
|
import { createSessionViewer } from './viewer.js';
|
|
6
11
|
import { runJobPool } from './pool.js';
|
|
7
|
-
|
|
12
|
+
import { machineLogins } from './machine-logins.js';
|
|
13
|
+
const VERSION = (() => {
|
|
14
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
for (const file of [join(here, 'build-info.json'), join(here, '..', 'package.json')]) {
|
|
16
|
+
try {
|
|
17
|
+
const v = JSON.parse(readFileSync(file, 'utf8')).version;
|
|
18
|
+
if (v)
|
|
19
|
+
return v;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return '0.0.0';
|
|
25
|
+
})();
|
|
8
26
|
function log(msg) {
|
|
9
27
|
console.log(`[firefunc-runner] ${new Date().toISOString()} ${msg}`);
|
|
10
28
|
}
|
|
@@ -29,6 +47,29 @@ export async function startDaemon(cfg) {
|
|
|
29
47
|
viewerPort,
|
|
30
48
|
engines: declaredEngines,
|
|
31
49
|
};
|
|
50
|
+
const ENGINE_RESCAN_MS = 120_000;
|
|
51
|
+
let lastEngineScan = Date.now();
|
|
52
|
+
const rescanEngines = () => {
|
|
53
|
+
if (Date.now() - lastEngineScan < ENGINE_RESCAN_MS)
|
|
54
|
+
return;
|
|
55
|
+
lastEngineScan = Date.now();
|
|
56
|
+
let found;
|
|
57
|
+
try {
|
|
58
|
+
found = availableEngines(cfg);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (found.join(',') === meta.engines.join(','))
|
|
64
|
+
return;
|
|
65
|
+
const added = found.filter((e) => !meta.engines.includes(e));
|
|
66
|
+
const gone = meta.engines.filter((e) => !found.includes(e));
|
|
67
|
+
meta.engines = found;
|
|
68
|
+
if (added.length)
|
|
69
|
+
log(`engines now available: ${added.join(', ')}`);
|
|
70
|
+
if (gone.length)
|
|
71
|
+
log(`engines no longer on PATH: ${gone.join(', ')}`);
|
|
72
|
+
};
|
|
32
73
|
let stopping = false;
|
|
33
74
|
const viewer = cfg.viewerEnabled === false
|
|
34
75
|
? undefined
|
|
@@ -72,6 +113,16 @@ export async function startDaemon(cfg) {
|
|
|
72
113
|
};
|
|
73
114
|
await refreshBudgets().catch(() => { });
|
|
74
115
|
const budgetTimer = setInterval(() => void refreshBudgets().catch(() => { }), 5 * 60_000);
|
|
116
|
+
let logins = [];
|
|
117
|
+
const refreshLogins = () => {
|
|
118
|
+
try {
|
|
119
|
+
logins = machineLogins();
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
refreshLogins();
|
|
125
|
+
const loginTimer = setInterval(refreshLogins, 5 * 60_000);
|
|
75
126
|
const effectiveMax = () => Math.max(1, Math.floor(cfg.maxParallel ?? serverMax));
|
|
76
127
|
log(`connected to ${cfg.apiUrl} as "${cfg.name ?? meta.hostname}" — watching for work` +
|
|
77
128
|
(effectiveMax() > 1 ? ` (up to ${effectiveMax()} parallel sessions).` : '.'));
|
|
@@ -108,7 +159,23 @@ export async function startDaemon(cfg) {
|
|
|
108
159
|
maxParallel: effectiveMax,
|
|
109
160
|
stopping: () => stopping,
|
|
110
161
|
claim: async () => {
|
|
111
|
-
const
|
|
162
|
+
const flushed = await flushPendingResults(runnerDir(), api, log).catch(() => null);
|
|
163
|
+
if (flushed && (flushed.delivered || flushed.refused)) {
|
|
164
|
+
log(`pending results: ${flushed.delivered} delivered, ${flushed.refused} refused, ${flushed.kept} kept`);
|
|
165
|
+
}
|
|
166
|
+
rescanEngines();
|
|
167
|
+
const job = await api.claim({
|
|
168
|
+
...meta,
|
|
169
|
+
budget: budgets,
|
|
170
|
+
mcpLogins: logins.map((l) => ({
|
|
171
|
+
server: l.server,
|
|
172
|
+
state: l.state,
|
|
173
|
+
via: l.via,
|
|
174
|
+
accountLabel: l.accountLabel,
|
|
175
|
+
expiresAt: l.expiresAt,
|
|
176
|
+
...(l.detail ? { detail: l.detail } : {}),
|
|
177
|
+
})),
|
|
178
|
+
});
|
|
112
179
|
backoffMs = 2_000;
|
|
113
180
|
return job;
|
|
114
181
|
},
|
|
@@ -146,6 +213,7 @@ export async function startDaemon(cfg) {
|
|
|
146
213
|
});
|
|
147
214
|
clearInterval(cfgTimer);
|
|
148
215
|
clearInterval(budgetTimer);
|
|
216
|
+
clearInterval(loginTimer);
|
|
149
217
|
viewer?.close();
|
|
150
218
|
log('stopped.');
|
|
151
219
|
}
|