@firefunc-agent/runner 0.9.35 → 0.9.37
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 +50 -0
- package/dist/api.d.ts +1 -1
- package/dist/brief-file.d.ts +1 -0
- package/dist/brief-file.js +6 -0
- package/dist/build-info.json +2 -2
- package/dist/cli.js +84 -10
- package/dist/daemon.js +35 -5
- package/dist/engine-login.js +4 -2
- package/dist/engine-models.js +4 -2
- package/dist/engines/index.js +4 -2
- package/dist/exec.js +5 -2
- package/dist/firefunc/automations.js +22 -0
- package/dist/firefunc/catalog.js +8 -1
- package/dist/firefunc/machines.d.ts +2 -0
- package/dist/firefunc/machines.js +85 -0
- package/dist/firefunc/main.js +9 -0
- package/dist/firefunc/tasks.js +2 -0
- package/dist/firefunc/webhooks.d.ts +2 -0
- package/dist/firefunc/webhooks.js +78 -0
- package/dist/job.js +17 -4
- package/dist/keep-local.d.ts +1 -0
- package/dist/keep-local.js +6 -1
- package/dist/live-runner.d.ts +47 -0
- package/dist/live-runner.js +109 -0
- package/dist/mcp-login.d.ts +1 -0
- package/dist/mcp-login.js +42 -5
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.js +35 -3
- package/dist/newer-runner.d.ts +9 -0
- package/dist/newer-runner.js +38 -0
- package/dist/pool.d.ts +2 -0
- package/dist/pool.js +12 -1
- package/dist/update.d.ts +41 -0
- package/dist/update.js +176 -0
- package/dist/win-shell.d.ts +14 -0
- package/dist/win-shell.js +51 -0
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { str, UsageError } from './args.js';
|
|
2
|
+
import { listIn, resolveProjectId } from './catalog.js';
|
|
3
|
+
import { enc } from './command.js';
|
|
4
|
+
import { printJson, table, text } from './output.js';
|
|
5
|
+
function printToken(ctx, body, what) {
|
|
6
|
+
const h = body.webhook ?? {};
|
|
7
|
+
ctx.io.stdout.write([
|
|
8
|
+
`${what} "${text(h.name)}" (${text(h.id)}).`,
|
|
9
|
+
`Send deliveries to: ${ctx.credentials().apiUrl}${text(h.path)}`,
|
|
10
|
+
`Token (shown this once, keep it): ${text(body.token)}`,
|
|
11
|
+
'Send it as "Authorization: Bearer <token>" or ?token=<token>.',
|
|
12
|
+
].join('\n') + '\n');
|
|
13
|
+
}
|
|
14
|
+
export const webhookCommands = [
|
|
15
|
+
{
|
|
16
|
+
path: ['webhooks', 'list'],
|
|
17
|
+
summary: "The workspace's inbound webhooks",
|
|
18
|
+
usage: 'webhooks list',
|
|
19
|
+
async run(ctx) {
|
|
20
|
+
const body = await ctx.api().get('/api/v1/webhooks');
|
|
21
|
+
if (ctx.json)
|
|
22
|
+
return printJson(ctx.io, body);
|
|
23
|
+
const rows = listIn(body, 'webhooks');
|
|
24
|
+
if (!rows.length) {
|
|
25
|
+
ctx.io.stdout.write('No inbound webhook yet. Make one: firefunc webhooks create\n');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
table(ctx.io, rows, [
|
|
29
|
+
{ head: 'ID', get: (h) => h.id },
|
|
30
|
+
{ head: 'NAME', get: (h) => h.name },
|
|
31
|
+
{ head: 'ON', get: (h) => (h.enabled ? 'yes' : 'no') },
|
|
32
|
+
{ head: 'DELIVERIES', get: (h) => h.receivedCount },
|
|
33
|
+
{ head: 'TOKEN STARTS', get: (h) => `${text(h.tokenPrefix)}…` },
|
|
34
|
+
{ head: 'PATH', get: (h) => h.path, max: 90 },
|
|
35
|
+
]);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
path: ['webhooks', 'create'],
|
|
40
|
+
summary: 'Make an inbound webhook in a project (prints its token once)',
|
|
41
|
+
usage: 'webhooks create --name <name> --project <id or name> [--vendor <catalogue slug>]',
|
|
42
|
+
flags: { name: 'string', project: 'string', vendor: 'string' },
|
|
43
|
+
flagHelp: [
|
|
44
|
+
['--name <name>', 'what people call it'],
|
|
45
|
+
['--project <id or name>', 'the project its tasks belong to'],
|
|
46
|
+
['--vendor <slug>', "start from a catalogue vendor's mapping (pagerduty, …)"],
|
|
47
|
+
],
|
|
48
|
+
async run(ctx) {
|
|
49
|
+
const name = str(ctx.args, 'name');
|
|
50
|
+
const project = str(ctx.args, 'project');
|
|
51
|
+
if (!name || !project)
|
|
52
|
+
throw new UsageError('--name and --project are both required.');
|
|
53
|
+
const vendor = str(ctx.args, 'vendor');
|
|
54
|
+
const body = await ctx.api().post('/api/v1/webhooks', {
|
|
55
|
+
name,
|
|
56
|
+
projectId: await resolveProjectId(ctx, project),
|
|
57
|
+
...(vendor ? { catalogueSlug: vendor } : {}),
|
|
58
|
+
});
|
|
59
|
+
if (ctx.json)
|
|
60
|
+
return printJson(ctx.io, body);
|
|
61
|
+
printToken(ctx, body, 'Made');
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
path: ['webhooks', 'rotate'],
|
|
66
|
+
summary: 'Give a webhook a new token (the old one stops working)',
|
|
67
|
+
usage: 'webhooks rotate <webhook id>',
|
|
68
|
+
positional: { min: 1, max: 1 },
|
|
69
|
+
async run(ctx) {
|
|
70
|
+
const id = ctx.args.positional[0];
|
|
71
|
+
const body = await ctx.api().post(`/api/v1/webhooks/${enc(id)}/rotate`, {});
|
|
72
|
+
if (ctx.json)
|
|
73
|
+
return printJson(ctx.io, body);
|
|
74
|
+
printToken(ctx, body, 'Rotated');
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
//# sourceMappingURL=webhooks.js.map
|
package/dist/job.js
CHANGED
|
@@ -40,9 +40,9 @@ import { jobClaudeEndpoint } from './openrouter.js';
|
|
|
40
40
|
import { ACCOUNT_RETRY_FIRST_MS, accountBlock, accountProblemOf, cannotWorkSentence, } from './engine-account.js';
|
|
41
41
|
import { createKeyedMutex, deviceLockDir, ensureDeviceScript, ensureHeavyScript, heavyLockDir, heavySlots, heavyTag, withHeavyLock, } from './locks.js';
|
|
42
42
|
import { getAdapter, stripForeignEngineCreds } from './engines/index.js';
|
|
43
|
-
import { mcpFormatForEngine, prepareMcp } from './mcp.js';
|
|
43
|
+
import { mcpFormatForEngine, mcpServerIdsOf, prepareMcp } from './mcp.js';
|
|
44
44
|
import { continueToFinishBrief, engineRules } from './brief.js';
|
|
45
|
-
import { BRIEF_FOLDER, fenceBrief, prepareBriefFolder } from './brief-file.js';
|
|
45
|
+
import { BRIEF_FOLDER, fenceBrief, prepareBriefFolder, refuseExposedOnWindows, } from './brief-file.js';
|
|
46
46
|
import { prepareReleaseFolder, stageDraftRelease } from './release-draft.js';
|
|
47
47
|
import { limitSentence } from './limit.js';
|
|
48
48
|
import { cannotRunUnattendedSentence, unattendedContext } from './unattended.js';
|
|
@@ -1366,7 +1366,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1366
1366
|
const heavyHelper = heavyLock ? ensureHeavyScript(rdir) : null;
|
|
1367
1367
|
let briefSeq = 0;
|
|
1368
1368
|
let briefDir;
|
|
1369
|
-
const buildInvocation = (c) => fenceBrief(adapter.buildInvocation(c), c.prompt, {
|
|
1369
|
+
const buildInvocation = (c) => refuseExposedOnWindows(fenceBrief(adapter.buildInvocation(c), c.prompt, {
|
|
1370
1370
|
seq: ++briefSeq,
|
|
1371
1371
|
log,
|
|
1372
1372
|
folder: () => {
|
|
@@ -1378,7 +1378,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1378
1378
|
}
|
|
1379
1379
|
return briefDir;
|
|
1380
1380
|
},
|
|
1381
|
-
}).
|
|
1381
|
+
}), adapter.displayName);
|
|
1382
1382
|
const slots = heavySlots(cfg.heavySlots);
|
|
1383
1383
|
const deviceHelper = heavyHelper ? ensureDeviceScript(rdir) : null;
|
|
1384
1384
|
const heavily = (fn) => heavyLock
|
|
@@ -1455,6 +1455,7 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1455
1455
|
const isWin = process.platform === 'win32';
|
|
1456
1456
|
if (job.mcpConfig != null) {
|
|
1457
1457
|
const format = mcpFormatForEngine(adapter.id);
|
|
1458
|
+
const dropped = [];
|
|
1458
1459
|
if (format) {
|
|
1459
1460
|
mcp = await prepareMcp({
|
|
1460
1461
|
raw: job.mcpConfig,
|
|
@@ -1464,9 +1465,21 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
1464
1465
|
api,
|
|
1465
1466
|
log,
|
|
1466
1467
|
relay: cfg.mcpRelay !== false,
|
|
1468
|
+
onDrop: (id, code) => dropped.push({ id, code }),
|
|
1467
1469
|
});
|
|
1468
1470
|
}
|
|
1471
|
+
else {
|
|
1472
|
+
for (const id of mcpServerIdsOf(job.mcpConfig))
|
|
1473
|
+
dropped.push({ id, code: 'engine_has_no_mcp' });
|
|
1474
|
+
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
|
+
}
|
|
1469
1476
|
log(mcp ? `mcp: ${mcp.logLine}` : 'mcp: no server was injected for this run');
|
|
1477
|
+
await api.event(job.runId, 'mcp_setup', {
|
|
1478
|
+
engine: adapter.id,
|
|
1479
|
+
platform: process.platform,
|
|
1480
|
+
injected: mcp?.serverIds ?? [],
|
|
1481
|
+
dropped: dropped.slice(0, 20),
|
|
1482
|
+
});
|
|
1470
1483
|
}
|
|
1471
1484
|
const temp = makeRunTemp(job.runId);
|
|
1472
1485
|
if (temp) {
|
package/dist/keep-local.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const CODE_NOTE = "code kept on the machine";
|
|
2
2
|
export declare function codeNote(ref: string | null): string;
|
|
3
|
+
export declare const FORMATTED_NOTE = "[formatted text kept on the machine: read it in the run's session log there]";
|
|
3
4
|
export declare function textCarriesSecret(text: string): boolean;
|
|
4
5
|
export declare function stripCode(text: string): string;
|
|
5
6
|
export declare const UNNAMED_COMMAND = "a command";
|
package/dist/keep-local.js
CHANGED
|
@@ -3,6 +3,8 @@ export const CODE_NOTE = 'code kept on the machine';
|
|
|
3
3
|
export function codeNote(ref) {
|
|
4
4
|
return ref ? `[${CODE_NOTE} — see ${ref}]` : `[${CODE_NOTE}]`;
|
|
5
5
|
}
|
|
6
|
+
export const FORMATTED_NOTE = "[formatted text kept on the machine: read it in the run's session log there]";
|
|
7
|
+
const FORMATTED_LANG = /^(?:html?|xml|markdown|md|text|txt|plain)$/i;
|
|
6
8
|
const EXTENSIONS = 'tsx?|jsx?|mjs|cjs|py|rb|go|rs|java|kts?|swift|c|h|cc|cpp|hpp|cs|php|sql|json|ya?ml|toml|md|css|scss|less|html?|vue|svelte|sh|bash|zsh|tf|hcl|graphql|gql|prisma|ex|exs|scala|dart|lua|pl|proto|xml|gradle|ini|env|lock|conf|cfg';
|
|
7
9
|
const PATH_REF = new RegExp(`((?:[\\w@.-]+/)*[\\w@-][\\w@.-]*\\.(?:${EXTENSIONS}))(?![\\w])(?:(?::|#L)(\\d+))?`, 'i');
|
|
8
10
|
const CODE_REF = /^(\d+):\d+:(\S+)$/;
|
|
@@ -122,7 +124,10 @@ export function stripCode(text) {
|
|
|
122
124
|
let j = i + 1;
|
|
123
125
|
while (j < lines.length && !close.test(lines[j]))
|
|
124
126
|
j++;
|
|
125
|
-
|
|
127
|
+
const lang = (open[3] ?? '').trim().split(/\s+/)[0] ?? '';
|
|
128
|
+
before = FORMATTED_LANG.test(lang)
|
|
129
|
+
? `${indent}${FORMATTED_NOTE}`
|
|
130
|
+
: `${indent}${codeNote(blockRef(open[3], lines.slice(i + 1, j), before))}`;
|
|
126
131
|
fenced.push(before);
|
|
127
132
|
i = j;
|
|
128
133
|
}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
async function gone(d, pid, ms) {
|
|
2
|
+
const until = d.now() + ms;
|
|
3
|
+
for (;;) {
|
|
4
|
+
if (!d.pidAlive(pid))
|
|
5
|
+
return true;
|
|
6
|
+
if (d.now() >= until)
|
|
7
|
+
return false;
|
|
8
|
+
await d.sleep(d.pollMs ?? 500);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export async function endLiveRunner(d) {
|
|
12
|
+
const rec = d.readAlive();
|
|
13
|
+
if (!rec || !d.pidAlive(rec.pid))
|
|
14
|
+
return { ok: true, message: '', pid: null, version: null };
|
|
15
|
+
const { pid, version } = rec;
|
|
16
|
+
const grace = d.graceMs ?? 15_000;
|
|
17
|
+
if (d.os === 'win32') {
|
|
18
|
+
await d.exec('taskkill', ['/PID', String(pid), '/T']);
|
|
19
|
+
if (!(await gone(d, pid, grace))) {
|
|
20
|
+
await d.exec('taskkill', ['/PID', String(pid), '/T', '/F']);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
try {
|
|
25
|
+
d.signal(pid, 'SIGTERM');
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
}
|
|
29
|
+
if (!(await gone(d, pid, grace))) {
|
|
30
|
+
try {
|
|
31
|
+
d.signal(pid, 'SIGKILL');
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (await gone(d, pid, 5_000))
|
|
38
|
+
return { ok: true, message: '', pid, version };
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
pid,
|
|
42
|
+
version,
|
|
43
|
+
message: d.os === 'win32'
|
|
44
|
+
? `The runner (pid ${pid}, runner ${version || 'unknown'}) would not stop. Fix: in PowerShell run Stop-Process -Id ${pid} -Force, then firefunc-runner start-service.`
|
|
45
|
+
: `The runner (pid ${pid}, runner ${version || 'unknown'}) would not stop. Fix: kill -9 ${pid}, then firefunc-runner start-service.`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export async function stopRunner(d) {
|
|
49
|
+
const svc = await d.service.stop();
|
|
50
|
+
if (!svc.ok)
|
|
51
|
+
return svc;
|
|
52
|
+
const ended = await endLiveRunner(d);
|
|
53
|
+
if (!ended.ok)
|
|
54
|
+
return { ok: false, message: ended.message };
|
|
55
|
+
return {
|
|
56
|
+
ok: true,
|
|
57
|
+
message: `Stopped${ended.pid ? ` (pid ${ended.pid}, runner ${ended.version || 'unknown'})` : ''}. Run "firefunc-runner start-service" to start it again.`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export async function startRunner(d, want) {
|
|
61
|
+
const ended = await endLiveRunner(d);
|
|
62
|
+
if (!ended.ok)
|
|
63
|
+
return { ...ended, pid: ended.pid };
|
|
64
|
+
const old = ended.pid;
|
|
65
|
+
const svc = await d.service.start();
|
|
66
|
+
if (!svc.ok)
|
|
67
|
+
return { ok: false, message: svc.message, pid: null };
|
|
68
|
+
const until = d.now() + (d.startMs ?? 60_000);
|
|
69
|
+
let last = null;
|
|
70
|
+
for (;;) {
|
|
71
|
+
const rec = d.readAlive();
|
|
72
|
+
if (rec && rec.pid !== old && d.pidAlive(rec.pid)) {
|
|
73
|
+
last = rec;
|
|
74
|
+
if (!want || rec.version === want) {
|
|
75
|
+
return {
|
|
76
|
+
ok: true,
|
|
77
|
+
pid: rec.pid,
|
|
78
|
+
message: `Started runner ${rec.version} (pid ${rec.pid}).`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (d.now() >= until)
|
|
83
|
+
break;
|
|
84
|
+
await d.sleep(d.pollMs ?? 1_000);
|
|
85
|
+
}
|
|
86
|
+
const still = d.readAlive();
|
|
87
|
+
const running = still && d.pidAlive(still.pid)
|
|
88
|
+
? `pid ${still.pid} runs runner ${still.version || 'unknown'}`
|
|
89
|
+
: 'no runner is running';
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
pid: null,
|
|
93
|
+
message: last && want
|
|
94
|
+
? `The service started runner ${last.version} (pid ${last.pid}), not ${want}. Fix: run firefunc-runner update, or reinstall: npm install -g @firefunc-agent/runner@latest, then firefunc-runner install.`
|
|
95
|
+
: `The service was asked to start, but no new runner${want ? ` on ${want}` : ''} came up within ${Math.round((d.startMs ?? 60_000) / 1000)} s; ${running}. Fix: run firefunc-runner logs to see why, then firefunc-runner start-service again.`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function versionGapWords(installed, running) {
|
|
99
|
+
if (!running?.version || running.version === installed)
|
|
100
|
+
return null;
|
|
101
|
+
return ` versions: installed ${installed}, running ${running.version}: restart needed — run firefunc-runner restart --when-idle\n`;
|
|
102
|
+
}
|
|
103
|
+
export function windowsRestartLater(taskName, delaySeconds = 5) {
|
|
104
|
+
return {
|
|
105
|
+
cmd: 'cmd.exe',
|
|
106
|
+
args: ['/d', '/c', `timeout /t ${delaySeconds} /nobreak >nul & schtasks /Run /TN ${taskName}`],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=live-runner.js.map
|
package/dist/mcp-login.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type McpLoginRecord = {
|
|
|
17
17
|
};
|
|
18
18
|
export declare function mcpLoginDir(): string;
|
|
19
19
|
export declare function mcpLoginPath(server: string): string;
|
|
20
|
+
export declare function atlassianDomainHelp(serverUrl: string, redirectUri: string): string[] | null;
|
|
20
21
|
export declare function runMcpLogin(tool: string, opts?: {
|
|
21
22
|
noBrowser?: boolean;
|
|
22
23
|
}): Promise<void>;
|
package/dist/mcp-login.js
CHANGED
|
@@ -371,7 +371,7 @@ function browserOpener() {
|
|
|
371
371
|
if (process.platform === 'darwin')
|
|
372
372
|
return { cmd: 'open', args: [] };
|
|
373
373
|
if (process.platform === 'win32')
|
|
374
|
-
return { cmd: '
|
|
374
|
+
return { cmd: 'rundll32', args: ['url.dll,FileProtocolHandler'] };
|
|
375
375
|
if (!process.env.DISPLAY && !process.env.WAYLAND_DISPLAY)
|
|
376
376
|
return null;
|
|
377
377
|
return { cmd: 'xdg-open', args: [] };
|
|
@@ -488,6 +488,27 @@ async function registerClient(meta, redirectUri, grantTypes) {
|
|
|
488
488
|
}
|
|
489
489
|
return { clientId, clientSecret: str(doc, 'client_secret') ?? undefined };
|
|
490
490
|
}
|
|
491
|
+
export function atlassianDomainHelp(serverUrl, redirectUri) {
|
|
492
|
+
let host = '';
|
|
493
|
+
let back = null;
|
|
494
|
+
try {
|
|
495
|
+
host = new URL(serverUrl).hostname.toLowerCase();
|
|
496
|
+
back = new URL(redirectUri);
|
|
497
|
+
}
|
|
498
|
+
catch {
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
if (host !== 'mcp.atlassian.com')
|
|
502
|
+
return null;
|
|
503
|
+
const domain = `${back.protocol}//${back.hostname}/**`;
|
|
504
|
+
return [
|
|
505
|
+
'Atlassian lets only approved apps sign in. If Atlassian says the domain is restricted, an admin',
|
|
506
|
+
'of your Atlassian organization adds this domain at admin.atlassian.com › Apps › AI and Rovo ›',
|
|
507
|
+
'Atlassian MCP server › Domains › Add domain:',
|
|
508
|
+
` ${domain}`,
|
|
509
|
+
`(this sign-in returns to ${redirectUri} on this machine). Then run this command again.`,
|
|
510
|
+
];
|
|
511
|
+
}
|
|
491
512
|
function waitForCode(server, state, acceptPaste, timeoutMs) {
|
|
492
513
|
return new Promise((resolve) => {
|
|
493
514
|
let settled = false;
|
|
@@ -508,16 +529,24 @@ function waitForCode(server, state, acceptPaste, timeoutMs) {
|
|
|
508
529
|
const url = new URL(req.url ?? '/', 'http://127.0.0.1');
|
|
509
530
|
const returned = url.searchParams;
|
|
510
531
|
const vendorError = returned.get('error');
|
|
532
|
+
const vendorWords = (returned.get('error_description') ?? '')
|
|
533
|
+
.replace(/[\u0000-\u001f\u007f]+/g, ' ')
|
|
534
|
+
.replace(/\s+/g, ' ')
|
|
535
|
+
.trim()
|
|
536
|
+
.slice(0, 300);
|
|
511
537
|
const code = returned.get('code');
|
|
512
538
|
const body = vendorError
|
|
513
|
-
? `Sign-in was refused: ${vendorError}. You can close this tab.`
|
|
539
|
+
? `Sign-in was refused: ${vendorError}${vendorWords ? ` (${vendorWords})` : ''}. You can close this tab.`
|
|
514
540
|
: code
|
|
515
541
|
? 'Signed in. You can close this tab and return to the terminal.'
|
|
516
542
|
: 'Waiting for the sign-in redirect.';
|
|
517
543
|
res.writeHead(vendorError ? 400 : 200, { 'content-type': 'text/plain; charset=utf-8' });
|
|
518
544
|
res.end(`FireFunc runner — ${body}\n`);
|
|
519
|
-
if (vendorError)
|
|
520
|
-
return finish({
|
|
545
|
+
if (vendorError) {
|
|
546
|
+
return finish({
|
|
547
|
+
failed: `the vendor refused the sign-in (${vendorError}${vendorWords ? `: ${vendorWords}` : ''})`,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
521
550
|
if (!code)
|
|
522
551
|
return;
|
|
523
552
|
if (returned.get('state') !== state) {
|
|
@@ -775,6 +804,12 @@ export async function runMcpLogin(tool, opts = {}) {
|
|
|
775
804
|
authorizeUrl.searchParams.set('scope', meta.scope);
|
|
776
805
|
if (meta.resource)
|
|
777
806
|
authorizeUrl.searchParams.set('resource', meta.resource);
|
|
807
|
+
const domainHelp = atlassianDomainHelp(server.url, loopback.redirectUri);
|
|
808
|
+
if (domainHelp) {
|
|
809
|
+
out('');
|
|
810
|
+
for (const line of domainHelp)
|
|
811
|
+
out(line);
|
|
812
|
+
}
|
|
778
813
|
const opened = opener ? openBrowser(authorizeUrl.href, opener) : false;
|
|
779
814
|
out('');
|
|
780
815
|
if (opened) {
|
|
@@ -802,7 +837,9 @@ export async function runMcpLogin(tool, opts = {}) {
|
|
|
802
837
|
out(`Waiting up to ${Math.round(CALLBACK_TIMEOUT_MS / 60_000)} minutes…`);
|
|
803
838
|
const code = await waitForCode(loopback.server, state, canPaste && !opened, CALLBACK_TIMEOUT_MS);
|
|
804
839
|
if ('failed' in code) {
|
|
805
|
-
err(
|
|
840
|
+
err(domainHelp
|
|
841
|
+
? `\nSign-in did not complete: ${code.failed}.\n\n${domainHelp.join('\n')}`
|
|
842
|
+
: `\nSign-in did not complete: ${code.failed}.\n\nFix: run the command again.`);
|
|
806
843
|
process.exitCode = 1;
|
|
807
844
|
return;
|
|
808
845
|
}
|
package/dist/mcp.d.ts
CHANGED
|
@@ -48,7 +48,10 @@ export type PrepareMcpOptions = {
|
|
|
48
48
|
api: McpCredentialClient;
|
|
49
49
|
log?: (msg: string) => void;
|
|
50
50
|
relay?: boolean;
|
|
51
|
+
onDrop?: (id: string, code: McpDropCode) => void;
|
|
51
52
|
};
|
|
53
|
+
export type McpDropCode = 'engine_has_no_mcp' | 'rejected' | 'unusable_on_engine' | 'config_path_taken' | 'git_exclude_failed' | 'no_credential' | 'not_signed_in' | 'write_failed';
|
|
54
|
+
export declare function mcpServerIdsOf(raw: unknown): string[];
|
|
52
55
|
export declare function mcpFormatForEngine(engine: string | null | undefined): McpFormat | null;
|
|
53
56
|
declare function parseServer(raw: unknown): {
|
|
54
57
|
spec: McpServerSpec;
|
package/dist/mcp.js
CHANGED
|
@@ -4,6 +4,17 @@ import { configPath } from './config.js';
|
|
|
4
4
|
import { CATALOG_ONLY, claudeCodeSignInFix, claudeCodeSignsFor } from './machine-logins.js';
|
|
5
5
|
import { execOut } from './exec.js';
|
|
6
6
|
import { startCredentialRelay } from './mcp-proxy.js';
|
|
7
|
+
export function mcpServerIdsOf(raw) {
|
|
8
|
+
if (!isRecord(raw) || !Array.isArray(raw.servers))
|
|
9
|
+
return [];
|
|
10
|
+
const ids = [];
|
|
11
|
+
for (const s of raw.servers) {
|
|
12
|
+
const id = isRecord(s) ? s.id : null;
|
|
13
|
+
if (typeof id === 'string' && SERVER_ID_PATTERN.test(id) && !ids.includes(id))
|
|
14
|
+
ids.push(id);
|
|
15
|
+
}
|
|
16
|
+
return ids.slice(0, 20);
|
|
17
|
+
}
|
|
7
18
|
const RELAYED_SERVERS = new Set(['github']);
|
|
8
19
|
const SERVER_ID_PATTERN = /^[a-z][a-z0-9_-]*$/;
|
|
9
20
|
const HEADER_NAME_PATTERN = /^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/;
|
|
@@ -199,7 +210,7 @@ function parseServer(raw) {
|
|
|
199
210
|
}
|
|
200
211
|
return { spec };
|
|
201
212
|
}
|
|
202
|
-
function parseRunConfig(raw, log) {
|
|
213
|
+
function parseRunConfig(raw, log, onReject) {
|
|
203
214
|
if (!isRecord(raw))
|
|
204
215
|
return null;
|
|
205
216
|
if (!Array.isArray(raw.servers))
|
|
@@ -209,6 +220,9 @@ function parseRunConfig(raw, log) {
|
|
|
209
220
|
const parsed = parseServer(entry);
|
|
210
221
|
if ('reject' in parsed) {
|
|
211
222
|
log(`mcp: ignoring a server FireFunc sent — ${parsed.reject}.`);
|
|
223
|
+
const id = isRecord(entry) ? entry.id : null;
|
|
224
|
+
if (typeof id === 'string' && SERVER_ID_PATTERN.test(id))
|
|
225
|
+
onReject?.(id);
|
|
212
226
|
continue;
|
|
213
227
|
}
|
|
214
228
|
servers.push(parsed.spec);
|
|
@@ -291,7 +305,7 @@ async function excludeFromGit(worktree, patterns, log) {
|
|
|
291
305
|
mkdirSync(info, { recursive: true });
|
|
292
306
|
const file = join(info, 'exclude');
|
|
293
307
|
const existing = existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
294
|
-
const lines = existing.split(
|
|
308
|
+
const lines = existing.split(/\r?\n/);
|
|
295
309
|
const missing = patterns.filter((p) => !lines.includes(p));
|
|
296
310
|
if (missing.length) {
|
|
297
311
|
const header = existing.includes(EXCLUDE_HEADER) ? '' : `\n${EXCLUDE_HEADER}\n`;
|
|
@@ -432,7 +446,14 @@ function codexOverrides(resolved) {
|
|
|
432
446
|
const NO_LOG = () => { };
|
|
433
447
|
export async function prepareMcp(opts) {
|
|
434
448
|
const log = opts.log ?? NO_LOG;
|
|
435
|
-
const
|
|
449
|
+
const drop = (id, code) => {
|
|
450
|
+
try {
|
|
451
|
+
opts.onDrop?.(id, code);
|
|
452
|
+
}
|
|
453
|
+
catch {
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const config = parseRunConfig(opts.raw, log, (id) => drop(id, 'rejected'));
|
|
436
457
|
if (!config || config.servers.length === 0)
|
|
437
458
|
return null;
|
|
438
459
|
const usable = [];
|
|
@@ -440,6 +461,7 @@ export async function prepareMcp(opts) {
|
|
|
440
461
|
const reason = whyUnusable(spec, opts.format);
|
|
441
462
|
if (reason) {
|
|
442
463
|
log(`mcp: skipping ${spec.id} on ${opts.format} — ${reason}.`);
|
|
464
|
+
drop(spec.id, 'unusable_on_engine');
|
|
443
465
|
continue;
|
|
444
466
|
}
|
|
445
467
|
usable.push(spec);
|
|
@@ -453,12 +475,16 @@ export async function prepareMcp(opts) {
|
|
|
453
475
|
if (existsSync(target)) {
|
|
454
476
|
log(`mcp: ${relative} already exists in this repo, so MCP is off for this run — FireFunc will not overwrite a file the repo owns, and an exclude cannot protect a tracked one. ` +
|
|
455
477
|
`Fix: remove ${relative} from the repository, or run this project on an engine that reads a different path.`);
|
|
478
|
+
for (const s of usable)
|
|
479
|
+
drop(s.id, 'config_path_taken');
|
|
456
480
|
return null;
|
|
457
481
|
}
|
|
458
482
|
const excluded = await excludeFromGit(opts.worktree, opts.format === 'antigravity' ? [`/${dirname(relative)}/`] : [`/${relative}`], log);
|
|
459
483
|
if (!excluded) {
|
|
460
484
|
log('mcp: MCP is off for this run because the config could not be kept out of the commit. ' +
|
|
461
485
|
'Fix: check that the runner can write .git/info/exclude in the repository checkout.');
|
|
486
|
+
for (const s of usable)
|
|
487
|
+
drop(s.id, 'git_exclude_failed');
|
|
462
488
|
return null;
|
|
463
489
|
}
|
|
464
490
|
}
|
|
@@ -478,6 +504,7 @@ export async function prepareMcp(opts) {
|
|
|
478
504
|
if (spec.auth === 'header') {
|
|
479
505
|
if (!spec.headerName) {
|
|
480
506
|
log(`mcp: skipping ${spec.id} — its credential did not survive validation.`);
|
|
507
|
+
drop(spec.id, 'no_credential');
|
|
481
508
|
continue;
|
|
482
509
|
}
|
|
483
510
|
let value = spec.secret;
|
|
@@ -489,6 +516,7 @@ export async function prepareMcp(opts) {
|
|
|
489
516
|
log(`mcp: skipping ${spec.id} — FireFunc issued no credential for it. ` +
|
|
490
517
|
'Fix: check the server is still granted to this workspace and its secret is set, in Settings → Connections. ' +
|
|
491
518
|
'The run continues without it, on the context pack it already has.');
|
|
519
|
+
drop(spec.id, 'no_credential');
|
|
492
520
|
continue;
|
|
493
521
|
}
|
|
494
522
|
resolved.push({
|
|
@@ -526,6 +554,7 @@ export async function prepareMcp(opts) {
|
|
|
526
554
|
`person's allowance. `
|
|
527
555
|
: '') +
|
|
528
556
|
'The run continues without it, on the context pack it already has.');
|
|
557
|
+
drop(spec.id, 'not_signed_in');
|
|
529
558
|
continue;
|
|
530
559
|
}
|
|
531
560
|
resolved.push({
|
|
@@ -538,6 +567,7 @@ export async function prepareMcp(opts) {
|
|
|
538
567
|
if (!minted?.token) {
|
|
539
568
|
log(`mcp: skipping ${spec.id} — FireFunc issued no read-only credential for it. ` +
|
|
540
569
|
'Fix: the API log names the reason; a 403 usually means GitHub is not connected to this workspace, and a 503 that the GitHub App is not configured. The context pack still carries the repository context.');
|
|
570
|
+
drop(spec.id, 'no_credential');
|
|
541
571
|
continue;
|
|
542
572
|
}
|
|
543
573
|
if (opts.relay && RELAYED_SERVERS.has(spec.id) && spec.transport !== 'stdio' && spec.url) {
|
|
@@ -585,6 +615,8 @@ export async function prepareMcp(opts) {
|
|
|
585
615
|
}
|
|
586
616
|
catch (e) {
|
|
587
617
|
log(`mcp: could not write ${relative} (${e.message}) — MCP is off for this run.`);
|
|
618
|
+
for (const r of resolved)
|
|
619
|
+
drop(r.spec.id, 'write_failed');
|
|
588
620
|
closeRelays();
|
|
589
621
|
return null;
|
|
590
622
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const RUNNER_REGISTRY_URL = "https://registry.npmjs.org/@firefunc-agent/runner";
|
|
2
|
+
export declare const NEWER_RUNNER_CHECK_MS: number;
|
|
3
|
+
export declare function isNewer(latest: string | null | undefined, version: string | null | undefined): boolean;
|
|
4
|
+
export declare const UPDATE_COMMAND = "firefunc-runner update";
|
|
5
|
+
export declare function newerRunnerLine(version: string, latest: string | null, service: boolean): string | null;
|
|
6
|
+
export declare function readLatestRunner(opts?: {
|
|
7
|
+
fetch?: typeof fetch;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}): Promise<string | null>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const RUNNER_REGISTRY_URL = 'https://registry.npmjs.org/@firefunc-agent/runner';
|
|
2
|
+
export const NEWER_RUNNER_CHECK_MS = 24 * 60 * 60 * 1000;
|
|
3
|
+
const SEMVER = /^(\d+)\.(\d+)\.(\d+)$/;
|
|
4
|
+
export function isNewer(latest, version) {
|
|
5
|
+
const a = SEMVER.exec(latest ?? '');
|
|
6
|
+
const b = SEMVER.exec(version ?? '');
|
|
7
|
+
if (!a || !b)
|
|
8
|
+
return false;
|
|
9
|
+
for (let i = 1; i <= 3; i += 1) {
|
|
10
|
+
const x = Number(a[i]);
|
|
11
|
+
const y = Number(b[i]);
|
|
12
|
+
if (x !== y)
|
|
13
|
+
return x > y;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
export const UPDATE_COMMAND = 'firefunc-runner update';
|
|
18
|
+
export function newerRunnerLine(version, latest, service) {
|
|
19
|
+
if (!isNewer(latest, version))
|
|
20
|
+
return null;
|
|
21
|
+
return `A newer runner is out: ${latest} (this is ${version}). Update: ${UPDATE_COMMAND}${service ? ' — or it installs itself when idle, if the workspace keeps updates automatic' : ''}`;
|
|
22
|
+
}
|
|
23
|
+
export async function readLatestRunner(opts = {}) {
|
|
24
|
+
try {
|
|
25
|
+
const res = await (opts.fetch ?? fetch)(RUNNER_REGISTRY_URL, {
|
|
26
|
+
headers: { accept: 'application/vnd.npm.install-v1+json' },
|
|
27
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? 10_000),
|
|
28
|
+
});
|
|
29
|
+
if (!res.ok)
|
|
30
|
+
return null;
|
|
31
|
+
const v = (await res.json())?.['dist-tags']?.latest;
|
|
32
|
+
return typeof v === 'string' && SEMVER.test(v) ? v : null;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=newer-runner.js.map
|
package/dist/pool.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export type JobPoolDeps<J> = {
|
|
|
8
8
|
onStart?: (job: J, inFlight: number) => void;
|
|
9
9
|
idleDelayMs?: number;
|
|
10
10
|
maxIdleDelayMs?: number;
|
|
11
|
+
activePollMs?: number;
|
|
12
|
+
activeWindowMs?: number;
|
|
11
13
|
sleep?: (ms: number) => Promise<void>;
|
|
12
14
|
paused?: () => boolean;
|
|
13
15
|
heartbeat?: (state: {
|
package/dist/pool.js
CHANGED
|
@@ -4,7 +4,16 @@ export async function runJobPool(deps) {
|
|
|
4
4
|
const baseIdleMs = deps.idleDelayMs ?? 800;
|
|
5
5
|
const maxIdleMs = Math.max(baseIdleMs, deps.maxIdleDelayMs ?? 8_000);
|
|
6
6
|
let emptyClaims = 0;
|
|
7
|
-
const
|
|
7
|
+
const activePollMs = deps.activePollMs ?? 1_000;
|
|
8
|
+
const activeWindowMs = deps.activeWindowMs ?? 120_000;
|
|
9
|
+
const clock = deps.now ?? (() => Date.now());
|
|
10
|
+
let lastActivity = clock();
|
|
11
|
+
const idleDelay = () => {
|
|
12
|
+
const backoff = Math.min(maxIdleMs, baseIdleMs * 2 ** Math.min(emptyClaims, 10));
|
|
13
|
+
return clock() - lastActivity < activeWindowMs
|
|
14
|
+
? Math.max(Math.min(baseIdleMs, backoff), Math.min(activePollMs, backoff))
|
|
15
|
+
: backoff;
|
|
16
|
+
};
|
|
8
17
|
const cap = () => {
|
|
9
18
|
const n = Math.floor(typeof deps.maxParallel === 'function' ? deps.maxParallel() : deps.maxParallel);
|
|
10
19
|
return Number.isFinite(n) ? Math.max(0, n) : 1;
|
|
@@ -16,8 +25,10 @@ export async function runJobPool(deps) {
|
|
|
16
25
|
let lastContact = now();
|
|
17
26
|
const spawn = (job) => {
|
|
18
27
|
deps.onStart?.(job, active.size + 1);
|
|
28
|
+
lastActivity = now();
|
|
19
29
|
const p = deps.run(job).finally(() => {
|
|
20
30
|
active.delete(p);
|
|
31
|
+
lastActivity = now();
|
|
21
32
|
});
|
|
22
33
|
active.add(p);
|
|
23
34
|
};
|