@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
|
@@ -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
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type RunnerConfig } from './config.js';
|
|
2
|
+
export declare const LOCAL_TOOL_NAME: RegExp;
|
|
3
|
+
export type LocalToolRefusal = {
|
|
4
|
+
why: string;
|
|
5
|
+
fix: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function localToolNames(cfg: {
|
|
8
|
+
localTools?: Record<string, unknown>;
|
|
9
|
+
} | null | undefined): string[];
|
|
10
|
+
export declare function addLocalTool(cfg: RunnerConfig, name: string, argv: string[], env?: Record<string, string>, now?: Date): RunnerConfig | LocalToolRefusal;
|
|
11
|
+
export declare function removeLocalTool(cfg: RunnerConfig, name: string): RunnerConfig | null;
|
|
12
|
+
export type LocalServer = {
|
|
13
|
+
id: string;
|
|
14
|
+
command: string;
|
|
15
|
+
args: string[];
|
|
16
|
+
env: Record<string, string>;
|
|
17
|
+
};
|
|
18
|
+
export declare function localServersFor(cfg: Pick<RunnerConfig, 'localTools'> | null | undefined, granted: unknown): {
|
|
19
|
+
given: LocalServer[];
|
|
20
|
+
missing: string[];
|
|
21
|
+
};
|
|
22
|
+
export declare function missingLocalToolsNote(missing: readonly string[]): string | null;
|
|
23
|
+
export declare function parseAddArgs(rest: string[]): {
|
|
24
|
+
name: string | null;
|
|
25
|
+
env: Record<string, string>;
|
|
26
|
+
argv: string[];
|
|
27
|
+
bad: string | null;
|
|
28
|
+
};
|
|
29
|
+
export declare function runMcpAdd(rest: string[], out: (s: string) => void, err: (s: string) => void): boolean;
|
|
30
|
+
export declare function runMcpRemove(name: string | undefined, out: (s: string) => void, err: (s: string) => void): boolean;
|
|
31
|
+
export declare function localToolsListing(cfg: Pick<RunnerConfig, 'localTools'> | null): string;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { loadConfig, saveConfig } from './config.js';
|
|
2
|
+
export const LOCAL_TOOL_NAME = /^[a-z][a-z0-9-]{0,39}$/;
|
|
3
|
+
const RESERVED = new Set([
|
|
4
|
+
'firefunc',
|
|
5
|
+
'github',
|
|
6
|
+
'jira',
|
|
7
|
+
'linear',
|
|
8
|
+
'sentry',
|
|
9
|
+
'slack',
|
|
10
|
+
'figma',
|
|
11
|
+
'notion',
|
|
12
|
+
'confluence',
|
|
13
|
+
'atlassian',
|
|
14
|
+
]);
|
|
15
|
+
const MAX_TOOLS = 20;
|
|
16
|
+
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
17
|
+
export function localToolNames(cfg) {
|
|
18
|
+
return Object.keys(cfg?.localTools ?? {})
|
|
19
|
+
.filter((n) => LOCAL_TOOL_NAME.test(n))
|
|
20
|
+
.sort()
|
|
21
|
+
.slice(0, MAX_TOOLS);
|
|
22
|
+
}
|
|
23
|
+
export function addLocalTool(cfg, name, argv, env = {}, now = new Date()) {
|
|
24
|
+
if (!LOCAL_TOOL_NAME.test(name)) {
|
|
25
|
+
return {
|
|
26
|
+
why: `"${name}" is not a name FireFunc can show.`,
|
|
27
|
+
fix: 'Use lower-case letters, digits and hyphens, starting with a letter (windows-mcp).',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (RESERVED.has(name)) {
|
|
31
|
+
return {
|
|
32
|
+
why: `"${name}" is a name FireFunc's own tools use.`,
|
|
33
|
+
fix: 'Pick another name, such as my-' + name + '.',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const [command, ...args] = argv;
|
|
37
|
+
if (!command || !command.trim()) {
|
|
38
|
+
return {
|
|
39
|
+
why: 'No command was given to start it.',
|
|
40
|
+
fix: 'Put the command after --, e.g. firefunc-runner mcp add windows-mcp -- uvx windows-mcp serve',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
for (const k of Object.keys(env)) {
|
|
44
|
+
if (!ENV_NAME.test(k)) {
|
|
45
|
+
return { why: `"${k}" is not an environment variable name.`, fix: 'Use --env NAME=value.' };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const have = cfg.localTools ?? {};
|
|
49
|
+
if (!have[name] && Object.keys(have).length >= MAX_TOOLS) {
|
|
50
|
+
return {
|
|
51
|
+
why: `This machine already has ${MAX_TOOLS} local tools.`,
|
|
52
|
+
fix: 'Remove one first: firefunc-runner mcp remove <name>',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const tool = {
|
|
56
|
+
command,
|
|
57
|
+
...(args.length ? { args } : {}),
|
|
58
|
+
...(Object.keys(env).length ? { env } : {}),
|
|
59
|
+
addedAt: now.toISOString(),
|
|
60
|
+
};
|
|
61
|
+
return { ...cfg, localTools: { ...have, [name]: tool } };
|
|
62
|
+
}
|
|
63
|
+
export function removeLocalTool(cfg, name) {
|
|
64
|
+
if (!cfg.localTools?.[name])
|
|
65
|
+
return null;
|
|
66
|
+
const { [name]: _gone, ...rest } = cfg.localTools;
|
|
67
|
+
const next = { ...cfg, localTools: rest };
|
|
68
|
+
if (!Object.keys(rest).length)
|
|
69
|
+
delete next.localTools;
|
|
70
|
+
return next;
|
|
71
|
+
}
|
|
72
|
+
export function localServersFor(cfg, granted) {
|
|
73
|
+
const names = Array.isArray(granted)
|
|
74
|
+
? [
|
|
75
|
+
...new Set(granted.filter((g) => typeof g === 'string' && LOCAL_TOOL_NAME.test(g))),
|
|
76
|
+
].slice(0, MAX_TOOLS)
|
|
77
|
+
: [];
|
|
78
|
+
const given = [];
|
|
79
|
+
const missing = [];
|
|
80
|
+
for (const id of names) {
|
|
81
|
+
const t = cfg?.localTools?.[id];
|
|
82
|
+
if (t && typeof t.command === 'string' && t.command.trim() && !RESERVED.has(id)) {
|
|
83
|
+
given.push({
|
|
84
|
+
id,
|
|
85
|
+
command: t.command,
|
|
86
|
+
args: Array.isArray(t.args) ? t.args.filter((a) => typeof a === 'string') : [],
|
|
87
|
+
env: t.env && typeof t.env === 'object' ? { ...t.env } : {},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
missing.push(id);
|
|
92
|
+
}
|
|
93
|
+
return { given, missing };
|
|
94
|
+
}
|
|
95
|
+
export function missingLocalToolsNote(missing) {
|
|
96
|
+
if (!missing.length)
|
|
97
|
+
return null;
|
|
98
|
+
const list = missing.join(', ');
|
|
99
|
+
return `Local tools you are granted that this machine does not have: ${list}. They are not available in this run; do not try to call them. Say so if your task needs them.\n\n`;
|
|
100
|
+
}
|
|
101
|
+
export function parseAddArgs(rest) {
|
|
102
|
+
const dash = rest.indexOf('--');
|
|
103
|
+
const head = dash >= 0 ? rest.slice(0, dash) : rest;
|
|
104
|
+
const argv = dash >= 0 ? rest.slice(dash + 1) : [];
|
|
105
|
+
let name = null;
|
|
106
|
+
const env = {};
|
|
107
|
+
let bad = null;
|
|
108
|
+
for (let i = 0; i < head.length; i++) {
|
|
109
|
+
const a = head[i];
|
|
110
|
+
if (a === '--env') {
|
|
111
|
+
const kv = head[++i] ?? '';
|
|
112
|
+
const eq = kv.indexOf('=');
|
|
113
|
+
if (eq <= 0)
|
|
114
|
+
bad = `--env takes NAME=value, not "${kv}".`;
|
|
115
|
+
else
|
|
116
|
+
env[kv.slice(0, eq)] = kv.slice(eq + 1);
|
|
117
|
+
}
|
|
118
|
+
else if (!a.startsWith('--') && name === null)
|
|
119
|
+
name = a;
|
|
120
|
+
}
|
|
121
|
+
return { name, env, argv, bad };
|
|
122
|
+
}
|
|
123
|
+
const USAGE = 'Usage:\n' +
|
|
124
|
+
' firefunc-runner mcp add <name> [--env NAME=value]… -- <command> [args…]\n' +
|
|
125
|
+
' firefunc-runner mcp remove <name>\n' +
|
|
126
|
+
' firefunc-runner mcp list\n' +
|
|
127
|
+
'Example: firefunc-runner mcp add windows-mcp -- uvx windows-mcp serve\n';
|
|
128
|
+
export function runMcpAdd(rest, out, err) {
|
|
129
|
+
const cfg = loadConfig();
|
|
130
|
+
if (!cfg) {
|
|
131
|
+
err('This machine is not paired yet, so there is nowhere to keep a local tool.\nFix: firefunc-runner connect <pairing-token>, then add it again.\n');
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
const p = parseAddArgs(rest);
|
|
135
|
+
if (!p.name || p.bad) {
|
|
136
|
+
err(`${p.bad ?? 'Name the tool.'}\n${USAGE}`);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
const next = addLocalTool(cfg, p.name, p.argv, p.env);
|
|
140
|
+
if ('why' in next) {
|
|
141
|
+
err(`Not added: ${next.why}\nFix: ${next.fix}\n`);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
saveConfig(next);
|
|
145
|
+
out(`Added ${p.name} to this machine's local tools.\n` +
|
|
146
|
+
`FireFunc sees its name within a minute; a run gets it only when its agent is granted "${p.name}".\n` +
|
|
147
|
+
'It runs as you, on this machine, with what this account can reach. Remove it any time: ' +
|
|
148
|
+
`firefunc-runner mcp remove ${p.name}\n`);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
export function runMcpRemove(name, out, err) {
|
|
152
|
+
const cfg = loadConfig();
|
|
153
|
+
if (!cfg || !name) {
|
|
154
|
+
err(USAGE);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const next = removeLocalTool(cfg, name);
|
|
158
|
+
if (!next) {
|
|
159
|
+
const have = localToolNames(cfg);
|
|
160
|
+
err(`This machine has no local tool "${name}".${have.length ? ` It has: ${have.join(', ')}.` : ''}\n`);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
saveConfig(next);
|
|
164
|
+
out(`Removed ${name}. Runs that start from now on do not get it.\n`);
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
export function localToolsListing(cfg) {
|
|
168
|
+
const names = localToolNames(cfg);
|
|
169
|
+
if (!names.length)
|
|
170
|
+
return 'Local tools: none. Add one with firefunc-runner mcp add <name> -- <command…>\n';
|
|
171
|
+
const lines = names.map((n) => {
|
|
172
|
+
const t = cfg.localTools[n];
|
|
173
|
+
const env = Object.keys(t.env ?? {});
|
|
174
|
+
return ` ${n} ${[t.command, ...(t.args ?? [])].join(' ')}${env.length ? ` (env: ${env.join(', ')})` : ''}`;
|
|
175
|
+
});
|
|
176
|
+
return `Local tools (only agents granted them by name get them):\n${lines.join('\n')}\n`;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=local-tools.js.map
|
package/dist/machine-logins.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ListedTool } from './mcp-tools.js';
|
|
1
2
|
export type MachineLoginState = 'logged_in' | 'expired' | 'error';
|
|
2
3
|
export type MachineLogin = {
|
|
3
4
|
server: string;
|
|
@@ -7,7 +8,10 @@ export type MachineLogin = {
|
|
|
7
8
|
accountLabel: string | null;
|
|
8
9
|
expiresAt: string | null;
|
|
9
10
|
detail?: string;
|
|
11
|
+
tools?: ListedTool[];
|
|
12
|
+
toolsListedAt?: string;
|
|
10
13
|
};
|
|
14
|
+
export declare function toolsOfRecord(raw: unknown): ListedTool[] | undefined;
|
|
11
15
|
export declare const VENDOR_MCP_URLS: Readonly<Record<string, string>>;
|
|
12
16
|
export declare const CATALOG_ONLY: ReadonlySet<string>;
|
|
13
17
|
export declare function runnerLogins(now?: number): MachineLogin[];
|
package/dist/machine-logins.js
CHANGED
|
@@ -4,9 +4,30 @@ import { homedir, platform } from 'node:os';
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { mcpLoginPath } from './mcp.js';
|
|
6
6
|
import { configPath } from './config.js';
|
|
7
|
+
import { listedToolOf, MAX_LISTED_TOOLS } from './mcp-tools.js';
|
|
8
|
+
export function toolsOfRecord(raw) {
|
|
9
|
+
if (!Array.isArray(raw))
|
|
10
|
+
return undefined;
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const t of raw.slice(0, MAX_LISTED_TOOLS)) {
|
|
13
|
+
const tool = listedToolOf(t && typeof t === 'object'
|
|
14
|
+
? {
|
|
15
|
+
name: t.name,
|
|
16
|
+
annotations: {
|
|
17
|
+
readOnlyHint: t.readOnly,
|
|
18
|
+
destructiveHint: t.destructive,
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
: null);
|
|
22
|
+
if (tool)
|
|
23
|
+
out.push(tool);
|
|
24
|
+
}
|
|
25
|
+
return out.length ? out : undefined;
|
|
26
|
+
}
|
|
7
27
|
export const VENDOR_MCP_URLS = {
|
|
8
28
|
figma: 'https://mcp.figma.com/mcp',
|
|
9
29
|
jira: 'https://mcp.atlassian.com/v2/mcp',
|
|
30
|
+
atlassian: 'https://mcp.atlassian.com/v2/mcp',
|
|
10
31
|
linear: 'https://mcp.linear.app/mcp/readonly',
|
|
11
32
|
sentry: 'https://mcp.sentry.dev/mcp',
|
|
12
33
|
slack: 'https://mcp.slack.com/mcp',
|
|
@@ -81,10 +102,20 @@ export function runnerLogins(now = Date.now()) {
|
|
|
81
102
|
serverUrl: typeof r.serverUrl === 'string' ? r.serverUrl : null,
|
|
82
103
|
accountLabel: typeof r.accountLabel === 'string' ? r.accountLabel : null,
|
|
83
104
|
expiresAt: iso,
|
|
105
|
+
...withTools(r),
|
|
84
106
|
});
|
|
85
107
|
}
|
|
86
108
|
return out;
|
|
87
109
|
}
|
|
110
|
+
function withTools(r) {
|
|
111
|
+
const tools = toolsOfRecord(r.tools);
|
|
112
|
+
if (!tools)
|
|
113
|
+
return {};
|
|
114
|
+
return {
|
|
115
|
+
tools,
|
|
116
|
+
...(typeof r.toolsListedAt === 'string' ? { toolsListedAt: r.toolsListedAt } : {}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
88
119
|
export function readClaudeCodeStore() {
|
|
89
120
|
if (platform() === 'darwin') {
|
|
90
121
|
try {
|
package/dist/mcp-login.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ListedTool } from './mcp-tools.js';
|
|
1
2
|
export type McpLoginRecord = {
|
|
2
3
|
server: string;
|
|
3
4
|
tokenType: string;
|
|
@@ -14,6 +15,8 @@ export type McpLoginRecord = {
|
|
|
14
15
|
scope?: string;
|
|
15
16
|
refreshToken?: string;
|
|
16
17
|
obtainedAt: string;
|
|
18
|
+
tools?: ListedTool[];
|
|
19
|
+
toolsListedAt?: string;
|
|
17
20
|
};
|
|
18
21
|
export declare function mcpLoginDir(): string;
|
|
19
22
|
export declare function mcpLoginPath(server: string): string;
|
package/dist/mcp-login.js
CHANGED
|
@@ -7,6 +7,7 @@ import { dirname, join } from 'node:path';
|
|
|
7
7
|
import { createInterface } from 'node:readline';
|
|
8
8
|
import { configPath } from './config.js';
|
|
9
9
|
import { claudeCodeLogins } from './machine-logins.js';
|
|
10
|
+
import { listServerTools } from './mcp-tools.js';
|
|
10
11
|
function out(msg) {
|
|
11
12
|
process.stdout.write(`${msg}\n`);
|
|
12
13
|
}
|
|
@@ -30,7 +31,14 @@ const KNOWN_SERVERS = [
|
|
|
30
31
|
id: 'jira',
|
|
31
32
|
label: 'Atlassian Rovo MCP Server',
|
|
32
33
|
url: 'https://mcp.atlassian.com/v2/mcp',
|
|
33
|
-
dispatched:
|
|
34
|
+
dispatched: true,
|
|
35
|
+
refusal: null,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'atlassian',
|
|
39
|
+
label: 'Atlassian Rovo MCP Server',
|
|
40
|
+
url: 'https://mcp.atlassian.com/v2/mcp',
|
|
41
|
+
dispatched: true,
|
|
34
42
|
refusal: null,
|
|
35
43
|
},
|
|
36
44
|
{
|
|
@@ -723,7 +731,7 @@ export async function runMcpLogin(tool, opts = {}) {
|
|
|
723
731
|
scope: refreshed.scope ?? existing.scope,
|
|
724
732
|
obtainedAt: new Date().toISOString(),
|
|
725
733
|
};
|
|
726
|
-
|
|
734
|
+
await saveWithTools(renewed, existing);
|
|
727
735
|
out('\nRenewed the existing login with its refresh token — no browser needed.');
|
|
728
736
|
printSuccess(server, renewed);
|
|
729
737
|
return;
|
|
@@ -760,7 +768,7 @@ export async function runMcpLogin(tool, opts = {}) {
|
|
|
760
768
|
return;
|
|
761
769
|
}
|
|
762
770
|
const record = recordFrom(tool, server, meta, registered, result);
|
|
763
|
-
|
|
771
|
+
await saveWithTools(record, existing);
|
|
764
772
|
printSuccess(server, record);
|
|
765
773
|
return;
|
|
766
774
|
}
|
|
@@ -861,9 +869,28 @@ export async function runMcpLogin(tool, opts = {}) {
|
|
|
861
869
|
return;
|
|
862
870
|
}
|
|
863
871
|
const record = recordFrom(tool, server, meta, registered, token);
|
|
864
|
-
|
|
872
|
+
await saveWithTools(record, existing);
|
|
865
873
|
printSuccess(server, record);
|
|
866
874
|
}
|
|
875
|
+
async function saveWithTools(record, previous, list = listServerTools) {
|
|
876
|
+
const listed = await list(record.serverUrl, `${record.tokenType || 'Bearer'} ${record.accessToken}`);
|
|
877
|
+
if (listed.ok) {
|
|
878
|
+
record.tools = listed.tools;
|
|
879
|
+
record.toolsListedAt = new Date().toISOString();
|
|
880
|
+
const reads = listed.tools.filter((t) => t.readOnly === true).length;
|
|
881
|
+
out(`\n${record.server} offers ${listed.tools.length} tool${listed.tools.length === 1 ? '' : 's'}` +
|
|
882
|
+
` (${reads} marked read-only by the server). FireFunc lists them under Organization →` +
|
|
883
|
+
` MCP servers → Tools once this machine reports in.`);
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
if (previous?.tools) {
|
|
887
|
+
record.tools = previous.tools;
|
|
888
|
+
record.toolsListedAt = previous.toolsListedAt;
|
|
889
|
+
}
|
|
890
|
+
out(`\nSigned in, but the tools could not be listed: ${listed.message}. Run this again to retry.`);
|
|
891
|
+
}
|
|
892
|
+
writeLogin(record);
|
|
893
|
+
}
|
|
867
894
|
function recordFrom(tool, server, meta, client, token) {
|
|
868
895
|
return {
|
|
869
896
|
server: tool,
|
|
@@ -940,6 +967,9 @@ export function runMcpList() {
|
|
|
940
967
|
if (known && !known.dispatched) {
|
|
941
968
|
out(` ${pad} NOT USED BY RUNS — FireFunc does not configure this server for any agent.`);
|
|
942
969
|
}
|
|
970
|
+
if (Array.isArray(record.tools) && record.tools.length) {
|
|
971
|
+
out(` ${pad} ${record.tools.length} tool${record.tools.length === 1 ? '' : 's'} listed at sign-in, reported to FireFunc by name only`);
|
|
972
|
+
}
|
|
943
973
|
if (expiry.state === 'expired') {
|
|
944
974
|
if (known?.refusal) {
|
|
945
975
|
out(` ${pad} Nothing to renew: "mcp login ${id}" says why.`);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ListedTool = {
|
|
2
|
+
name: string;
|
|
3
|
+
readOnly: boolean | null;
|
|
4
|
+
destructive: boolean | null;
|
|
5
|
+
};
|
|
6
|
+
export type ToolListing = {
|
|
7
|
+
ok: true;
|
|
8
|
+
tools: ListedTool[];
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const MAX_LISTED_TOOLS = 300;
|
|
14
|
+
type RpcReply = {
|
|
15
|
+
result?: unknown;
|
|
16
|
+
error?: {
|
|
17
|
+
message?: unknown;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare function rpcReplyOf(body: string, contentType: string | null, id: number): RpcReply | null;
|
|
21
|
+
export declare function listedToolOf(raw: unknown): ListedTool | null;
|
|
22
|
+
export declare function listServerTools(url: string, authorization: string, fetchImpl?: typeof fetch): Promise<ToolListing>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const PROTOCOL_VERSION = '2025-06-18';
|
|
2
|
+
const PER_CALL_MS = 10_000;
|
|
3
|
+
const MAX_PAGES = 10;
|
|
4
|
+
export const MAX_LISTED_TOOLS = 300;
|
|
5
|
+
const TOOL_NAME = /^[A-Za-z0-9_.\-/:]{1,128}$/;
|
|
6
|
+
export function rpcReplyOf(body, contentType, id) {
|
|
7
|
+
const pick = (v) => {
|
|
8
|
+
const list = Array.isArray(v) ? v : [v];
|
|
9
|
+
for (const m of list) {
|
|
10
|
+
if (m && typeof m === 'object' && m.id === id)
|
|
11
|
+
return m;
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
if ((contentType ?? '').includes('text/event-stream')) {
|
|
16
|
+
for (const block of body.split(/\r?\n\r?\n/)) {
|
|
17
|
+
const data = block
|
|
18
|
+
.split(/\r?\n/)
|
|
19
|
+
.filter((l) => l.startsWith('data:'))
|
|
20
|
+
.map((l) => l.slice(5).trimStart())
|
|
21
|
+
.join('\n');
|
|
22
|
+
if (!data)
|
|
23
|
+
continue;
|
|
24
|
+
try {
|
|
25
|
+
const hit = pick(JSON.parse(data));
|
|
26
|
+
if (hit)
|
|
27
|
+
return hit;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return pick(JSON.parse(body));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function listedToolOf(raw) {
|
|
42
|
+
if (!raw || typeof raw !== 'object')
|
|
43
|
+
return null;
|
|
44
|
+
const t = raw;
|
|
45
|
+
if (typeof t.name !== 'string' || !TOOL_NAME.test(t.name))
|
|
46
|
+
return null;
|
|
47
|
+
const a = (t.annotations && typeof t.annotations === 'object' ? t.annotations : {});
|
|
48
|
+
return {
|
|
49
|
+
name: t.name,
|
|
50
|
+
readOnly: typeof a.readOnlyHint === 'boolean' ? a.readOnlyHint : null,
|
|
51
|
+
destructive: typeof a.destructiveHint === 'boolean' ? a.destructiveHint : null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export async function listServerTools(url, authorization, fetchImpl = fetch) {
|
|
55
|
+
let session = null;
|
|
56
|
+
let nextId = 1;
|
|
57
|
+
const call = async (method, params, notify = false) => {
|
|
58
|
+
const id = notify ? undefined : nextId++;
|
|
59
|
+
const res = await fetchImpl(url, {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers: {
|
|
62
|
+
'content-type': 'application/json',
|
|
63
|
+
accept: 'application/json, text/event-stream',
|
|
64
|
+
authorization,
|
|
65
|
+
'mcp-protocol-version': PROTOCOL_VERSION,
|
|
66
|
+
...(session ? { 'mcp-session-id': session } : {}),
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify({ jsonrpc: '2.0', method, params, ...(id ? { id } : {}) }),
|
|
69
|
+
signal: AbortSignal.timeout(PER_CALL_MS),
|
|
70
|
+
});
|
|
71
|
+
session = res.headers.get('mcp-session-id') ?? session;
|
|
72
|
+
const text = await res.text();
|
|
73
|
+
if (notify)
|
|
74
|
+
return { ok: true, result: null };
|
|
75
|
+
if (!res.ok)
|
|
76
|
+
return { ok: false, message: `the server answered ${res.status} to ${method}` };
|
|
77
|
+
const reply = rpcReplyOf(text, res.headers.get('content-type'), id);
|
|
78
|
+
if (!reply)
|
|
79
|
+
return { ok: false, message: `the server's answer to ${method} was not MCP` };
|
|
80
|
+
if (reply.error) {
|
|
81
|
+
const m = typeof reply.error.message === 'string' ? reply.error.message : 'an error';
|
|
82
|
+
return { ok: false, message: `${method} failed: ${m.slice(0, 200)}` };
|
|
83
|
+
}
|
|
84
|
+
return { ok: true, result: reply.result };
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
const init = await call('initialize', {
|
|
88
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
89
|
+
capabilities: {},
|
|
90
|
+
clientInfo: { name: 'firefunc-runner', version: '1' },
|
|
91
|
+
});
|
|
92
|
+
if (!init.ok)
|
|
93
|
+
return init;
|
|
94
|
+
await call('notifications/initialized', {}, true);
|
|
95
|
+
const tools = [];
|
|
96
|
+
let cursor;
|
|
97
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
98
|
+
const listed = await call('tools/list', cursor ? { cursor } : {});
|
|
99
|
+
if (!listed.ok)
|
|
100
|
+
return listed;
|
|
101
|
+
const r = (listed.result ?? {});
|
|
102
|
+
for (const raw of Array.isArray(r.tools) ? r.tools : []) {
|
|
103
|
+
const t = listedToolOf(raw);
|
|
104
|
+
if (t && !tools.some((x) => x.name === t.name))
|
|
105
|
+
tools.push(t);
|
|
106
|
+
}
|
|
107
|
+
cursor = typeof r.nextCursor === 'string' && r.nextCursor ? r.nextCursor : undefined;
|
|
108
|
+
if (!cursor || tools.length >= MAX_LISTED_TOOLS)
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
return { ok: true, tools: tools.slice(0, MAX_LISTED_TOOLS) };
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
return {
|
|
115
|
+
ok: false,
|
|
116
|
+
message: e instanceof Error && e.name === 'TimeoutError'
|
|
117
|
+
? 'the server took too long to answer'
|
|
118
|
+
: 'the server could not be reached',
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=mcp-tools.js.map
|
package/dist/mcp.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export type McpServerSpec = {
|
|
|
15
15
|
allowedTools: string[];
|
|
16
16
|
writeTools?: string[];
|
|
17
17
|
deniedTools?: string[];
|
|
18
|
+
local?: true;
|
|
19
|
+
env?: Record<string, string>;
|
|
18
20
|
};
|
|
19
21
|
export type McpRunConfig = {
|
|
20
22
|
servers: McpServerSpec[];
|
|
@@ -49,6 +51,12 @@ export type PrepareMcpOptions = {
|
|
|
49
51
|
log?: (msg: string) => void;
|
|
50
52
|
relay?: boolean;
|
|
51
53
|
onDrop?: (id: string, code: McpDropCode) => void;
|
|
54
|
+
local?: ReadonlyArray<{
|
|
55
|
+
id: string;
|
|
56
|
+
command: string;
|
|
57
|
+
args: string[];
|
|
58
|
+
env: Record<string, string>;
|
|
59
|
+
}>;
|
|
52
60
|
};
|
|
53
61
|
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
62
|
export declare function mcpServerIdsOf(raw: unknown): string[];
|