@firefunc-agent/runner 0.7.1 → 0.9.3
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 +296 -4
- package/dist/activity.d.ts +32 -0
- package/dist/activity.js +295 -0
- package/dist/api.d.ts +69 -1
- package/dist/api.js +114 -3
- package/dist/brief.d.ts +11 -0
- package/dist/brief.js +278 -0
- package/dist/build-info.json +4 -0
- package/dist/cli.js +59 -2
- package/dist/config.d.ts +7 -0
- package/dist/config.js +3 -0
- package/dist/cut.d.ts +45 -0
- package/dist/cut.js +105 -0
- package/dist/daemon.d.ts +16 -0
- package/dist/daemon.js +196 -7
- package/dist/declined.d.ts +11 -0
- package/dist/declined.js +27 -0
- 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 +139 -2
- 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 +12 -1
- package/dist/exec.d.ts +3 -0
- package/dist/exec.js +48 -5
- package/dist/firefunc/agents.d.ts +2 -0
- package/dist/firefunc/agents.js +343 -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 +36 -0
- package/dist/firefunc/client.js +177 -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/configure.d.ts +6 -0
- package/dist/firefunc/configure.js +409 -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 +259 -0
- package/dist/firefunc/output.d.ts +29 -0
- package/dist/firefunc/output.js +131 -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 +8 -0
- package/dist/git-auth.d.ts +4 -1
- package/dist/git-auth.js +6 -2
- package/dist/held.d.ts +18 -0
- package/dist/held.js +95 -0
- package/dist/job.d.ts +3 -0
- package/dist/job.js +818 -102
- package/dist/keep-local.d.ts +12 -0
- package/dist/keep-local.js +651 -0
- package/dist/limit.d.ts +30 -0
- package/dist/limit.js +258 -0
- package/dist/locks.d.ts +14 -0
- package/dist/locks.js +164 -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-proxy.d.ts +21 -0
- package/dist/mcp-proxy.js +180 -0
- package/dist/mcp.d.ts +62 -0
- package/dist/mcp.js +611 -0
- package/dist/network.d.ts +20 -0
- package/dist/network.js +76 -0
- package/dist/orphans.d.ts +40 -0
- package/dist/orphans.js +235 -0
- package/dist/pending.d.ts +14 -0
- package/dist/pending.js +56 -0
- package/dist/pool.d.ts +7 -0
- package/dist/pool.js +57 -9
- package/dist/pr-title.d.ts +11 -0
- package/dist/pr-title.js +63 -0
- package/dist/recover.d.ts +10 -0
- package/dist/recover.js +104 -0
- package/dist/secret-scan.d.ts +19 -0
- package/dist/secret-scan.js +161 -0
- package/dist/session-stream.d.ts +9 -1
- package/dist/session-stream.js +20 -2
- package/dist/skills.d.ts +11 -0
- package/dist/skills.js +164 -0
- package/dist/stopped.d.ts +3 -0
- package/dist/stopped.js +10 -0
- package/dist/usage.d.ts +49 -0
- package/dist/usage.js +389 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +17 -0
- package/dist/viewer.js +7 -1
- package/dist/worktrees.d.ts +15 -0
- package/dist/worktrees.js +96 -0
- package/package.json +8 -5
- package/skill/firefunc/SKILL.md +222 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type RelayCredential = {
|
|
2
|
+
token: string;
|
|
3
|
+
expiresAt?: string;
|
|
4
|
+
};
|
|
5
|
+
export type CredentialRelay = {
|
|
6
|
+
url: string;
|
|
7
|
+
readonly renewals: number;
|
|
8
|
+
close(): void;
|
|
9
|
+
};
|
|
10
|
+
export type RelayOptions = {
|
|
11
|
+
upstream: string;
|
|
12
|
+
name: string;
|
|
13
|
+
initial: RelayCredential;
|
|
14
|
+
renew: () => Promise<RelayCredential | null>;
|
|
15
|
+
maxAgeMs?: number;
|
|
16
|
+
earlyMs?: number;
|
|
17
|
+
now?: () => number;
|
|
18
|
+
log?: (line: string) => void;
|
|
19
|
+
maxBodyBytes?: number;
|
|
20
|
+
};
|
|
21
|
+
export declare function startCredentialRelay(opts: RelayOptions): Promise<CredentialRelay>;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { createServer, request as httpRequest, } from 'node:http';
|
|
3
|
+
import { request as httpsRequest } from 'node:https';
|
|
4
|
+
const HOP_BY_HOP = new Set([
|
|
5
|
+
'connection',
|
|
6
|
+
'keep-alive',
|
|
7
|
+
'proxy-authenticate',
|
|
8
|
+
'proxy-authorization',
|
|
9
|
+
'proxy-connection',
|
|
10
|
+
'te',
|
|
11
|
+
'trailer',
|
|
12
|
+
'transfer-encoding',
|
|
13
|
+
'upgrade',
|
|
14
|
+
]);
|
|
15
|
+
function requestHeaders(from, upstream, token, length) {
|
|
16
|
+
const out = {};
|
|
17
|
+
for (const [k, v] of Object.entries(from)) {
|
|
18
|
+
const key = k.toLowerCase();
|
|
19
|
+
if (HOP_BY_HOP.has(key) || key === 'host' || key === 'authorization')
|
|
20
|
+
continue;
|
|
21
|
+
if (key === 'content-length' || v === undefined)
|
|
22
|
+
continue;
|
|
23
|
+
out[key] = v;
|
|
24
|
+
}
|
|
25
|
+
out.host = upstream.host;
|
|
26
|
+
out.authorization = `Bearer ${token}`;
|
|
27
|
+
if (length > 0)
|
|
28
|
+
out['content-length'] = String(length);
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
function responseHeaders(from) {
|
|
32
|
+
const out = {};
|
|
33
|
+
for (const [k, v] of Object.entries(from)) {
|
|
34
|
+
if (HOP_BY_HOP.has(k.toLowerCase()) || v === undefined)
|
|
35
|
+
continue;
|
|
36
|
+
out[k] = v;
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
function targetFor(upstream, rest, search) {
|
|
41
|
+
const t = new URL(upstream.toString());
|
|
42
|
+
if (rest)
|
|
43
|
+
t.pathname = `${t.pathname.replace(/\/+$/, '')}/${rest}`;
|
|
44
|
+
t.search = search;
|
|
45
|
+
return t;
|
|
46
|
+
}
|
|
47
|
+
export async function startCredentialRelay(opts) {
|
|
48
|
+
const upstream = new URL(opts.upstream);
|
|
49
|
+
const loopback = ['127.0.0.1', 'localhost', '[::1]', '::1'].includes(upstream.hostname);
|
|
50
|
+
if (upstream.protocol !== 'https:' && !(upstream.protocol === 'http:' && loopback)) {
|
|
51
|
+
throw new Error('a token is only relayed over https');
|
|
52
|
+
}
|
|
53
|
+
const now = opts.now ?? (() => Date.now());
|
|
54
|
+
const log = opts.log ?? (() => { });
|
|
55
|
+
const maxAgeMs = opts.maxAgeMs ?? 55 * 60_000;
|
|
56
|
+
const earlyMs = opts.earlyMs ?? 5 * 60_000;
|
|
57
|
+
const maxBody = opts.maxBodyBytes ?? 10 * 1024 * 1024;
|
|
58
|
+
const key = randomBytes(24).toString('hex');
|
|
59
|
+
const keyBuf = Buffer.from(key);
|
|
60
|
+
let token = opts.initial.token;
|
|
61
|
+
let issuedAt = now();
|
|
62
|
+
let expiresAt = opts.initial.expiresAt ? Date.parse(opts.initial.expiresAt) : Number.NaN;
|
|
63
|
+
let renewals = 0;
|
|
64
|
+
let renewing = null;
|
|
65
|
+
let lastRenewAt = 0;
|
|
66
|
+
let refusedAt = Number.NEGATIVE_INFINITY;
|
|
67
|
+
const due = () => Number.isFinite(expiresAt) ? now() >= expiresAt - earlyMs : now() - issuedAt >= maxAgeMs;
|
|
68
|
+
const renewOnce = (why) => {
|
|
69
|
+
if (renewing)
|
|
70
|
+
return renewing;
|
|
71
|
+
if (now() - lastRenewAt < 30_000 || now() - refusedAt < 5 * 60_000) {
|
|
72
|
+
return Promise.resolve(false);
|
|
73
|
+
}
|
|
74
|
+
renewing = (async () => {
|
|
75
|
+
try {
|
|
76
|
+
const fresh = await opts.renew();
|
|
77
|
+
if (!fresh?.token) {
|
|
78
|
+
refusedAt = now();
|
|
79
|
+
log(`mcp: FireFunc did not renew the ${opts.name} credential (${why}) — its calls keep the old token until it expires, then fail. ` +
|
|
80
|
+
'Fix: nothing on this machine; a run is allowed a few MCP credentials, and a run that needs more should be split. The API log names the refusal.');
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
token = fresh.token;
|
|
84
|
+
issuedAt = now();
|
|
85
|
+
lastRenewAt = issuedAt;
|
|
86
|
+
expiresAt = fresh.expiresAt ? Date.parse(fresh.expiresAt) : Number.NaN;
|
|
87
|
+
renewals += 1;
|
|
88
|
+
log(`mcp: renewed the ${opts.name} credential (${why}) — the run keeps reading ${opts.name}`);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
refusedAt = now();
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
renewing = null;
|
|
97
|
+
}
|
|
98
|
+
})();
|
|
99
|
+
return renewing;
|
|
100
|
+
};
|
|
101
|
+
const send = (target, method, headers, body) => new Promise((resolve, reject) => {
|
|
102
|
+
const req = (target.protocol === 'https:' ? httpsRequest : httpRequest)(target, { method, headers: requestHeaders(headers, target, token, body.length) }, resolve);
|
|
103
|
+
req.on('error', reject);
|
|
104
|
+
req.end(body.length > 0 ? body : undefined);
|
|
105
|
+
});
|
|
106
|
+
const sockets = new Set();
|
|
107
|
+
const server = createServer((req, res) => {
|
|
108
|
+
void (async () => {
|
|
109
|
+
try {
|
|
110
|
+
const u = new URL(req.url ?? '/', 'http://127.0.0.1');
|
|
111
|
+
const [, first = '', ...rest] = u.pathname.split('/');
|
|
112
|
+
const given = Buffer.from(first);
|
|
113
|
+
if (given.length !== keyBuf.length || !timingSafeEqual(given, keyBuf)) {
|
|
114
|
+
res.writeHead(404).end();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const chunks = [];
|
|
118
|
+
let size = 0;
|
|
119
|
+
for await (const chunk of req) {
|
|
120
|
+
size += chunk.length;
|
|
121
|
+
if (size > maxBody) {
|
|
122
|
+
res.writeHead(413).end();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
chunks.push(chunk);
|
|
126
|
+
}
|
|
127
|
+
const body = Buffer.concat(chunks);
|
|
128
|
+
const target = targetFor(upstream, rest.join('/'), u.search);
|
|
129
|
+
const method = req.method ?? 'GET';
|
|
130
|
+
if (due())
|
|
131
|
+
await renewOnce('before it expires');
|
|
132
|
+
let up = await send(target, method, req.headers, body);
|
|
133
|
+
if (up.statusCode === 401 && (await renewOnce('the server answered 401'))) {
|
|
134
|
+
up.resume();
|
|
135
|
+
up = await send(target, method, req.headers, body);
|
|
136
|
+
}
|
|
137
|
+
res.writeHead(up.statusCode ?? 502, responseHeaders(up.headers));
|
|
138
|
+
up.pipe(res);
|
|
139
|
+
up.on('error', () => res.destroy());
|
|
140
|
+
res.on('close', () => up.destroy());
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
if (!res.headersSent)
|
|
144
|
+
res.writeHead(502).end();
|
|
145
|
+
else
|
|
146
|
+
res.destroy();
|
|
147
|
+
}
|
|
148
|
+
})();
|
|
149
|
+
});
|
|
150
|
+
server.on('connection', (s) => {
|
|
151
|
+
sockets.add(s);
|
|
152
|
+
s.on('close', () => sockets.delete(s));
|
|
153
|
+
});
|
|
154
|
+
server.on('clientError', (_err, socket) => socket.destroy());
|
|
155
|
+
await new Promise((resolve, reject) => {
|
|
156
|
+
server.once('error', reject);
|
|
157
|
+
server.listen(0, '127.0.0.1', () => {
|
|
158
|
+
server.off('error', reject);
|
|
159
|
+
resolve();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
server.on('error', () => { });
|
|
163
|
+
const port = server.address().port;
|
|
164
|
+
let closed = false;
|
|
165
|
+
return {
|
|
166
|
+
url: `http://127.0.0.1:${port}/${key}${upstream.pathname.endsWith('/') ? '/' : ''}`,
|
|
167
|
+
get renewals() {
|
|
168
|
+
return renewals;
|
|
169
|
+
},
|
|
170
|
+
close() {
|
|
171
|
+
if (closed)
|
|
172
|
+
return;
|
|
173
|
+
closed = true;
|
|
174
|
+
server.close();
|
|
175
|
+
for (const s of sockets)
|
|
176
|
+
s.destroy();
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=mcp-proxy.js.map
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { InvocationContext } from './engines/types.js';
|
|
2
|
+
export type McpTransport = 'stdio' | 'http' | 'sse';
|
|
3
|
+
export type McpAuth = 'minted' | 'oauth_local' | 'header' | 'none';
|
|
4
|
+
export type McpServerSpec = {
|
|
5
|
+
id: string;
|
|
6
|
+
transport: McpTransport;
|
|
7
|
+
url?: string;
|
|
8
|
+
command?: string;
|
|
9
|
+
args?: string[];
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
auth: McpAuth;
|
|
12
|
+
headerName?: string;
|
|
13
|
+
secret?: string;
|
|
14
|
+
secretRef?: string;
|
|
15
|
+
allowedTools: string[];
|
|
16
|
+
writeTools?: string[];
|
|
17
|
+
deniedTools?: string[];
|
|
18
|
+
};
|
|
19
|
+
export type McpRunConfig = {
|
|
20
|
+
servers: McpServerSpec[];
|
|
21
|
+
callBudget: number | null;
|
|
22
|
+
};
|
|
23
|
+
export type McpFormat = 'claude' | 'cursor' | 'gemini' | 'codex' | 'copilot';
|
|
24
|
+
export type McpCredentialClient = {
|
|
25
|
+
mcpCredential(runId: string, server: string): Promise<{
|
|
26
|
+
token: string;
|
|
27
|
+
expiresAt?: string;
|
|
28
|
+
} | null>;
|
|
29
|
+
};
|
|
30
|
+
export type PreparedMcp = {
|
|
31
|
+
format: McpFormat;
|
|
32
|
+
configPath: string | null;
|
|
33
|
+
serverIds: string[];
|
|
34
|
+
toolNames: string[];
|
|
35
|
+
writeToolNames: string[];
|
|
36
|
+
deniedToolNames: string[];
|
|
37
|
+
env: Record<string, string>;
|
|
38
|
+
inlineOverrides: string[];
|
|
39
|
+
callBudget: number | null;
|
|
40
|
+
logLine: string;
|
|
41
|
+
cleanup(): void;
|
|
42
|
+
};
|
|
43
|
+
export type PrepareMcpOptions = {
|
|
44
|
+
raw: unknown;
|
|
45
|
+
worktree: string;
|
|
46
|
+
format: McpFormat;
|
|
47
|
+
runId: string;
|
|
48
|
+
api: McpCredentialClient;
|
|
49
|
+
log?: (msg: string) => void;
|
|
50
|
+
relay?: boolean;
|
|
51
|
+
};
|
|
52
|
+
export declare function mcpFormatForEngine(engine: string | null | undefined): McpFormat | null;
|
|
53
|
+
export type CachedMcpLogin = {
|
|
54
|
+
server: string;
|
|
55
|
+
tokenType: string;
|
|
56
|
+
accessToken: string;
|
|
57
|
+
expiresAt: string | null;
|
|
58
|
+
accountLabel?: string | null;
|
|
59
|
+
};
|
|
60
|
+
export declare function mcpLoginPath(server: string): string;
|
|
61
|
+
export declare function prepareMcp(opts: PrepareMcpOptions): Promise<PreparedMcp | null>;
|
|
62
|
+
export declare function mcpFromContext(ctx: InvocationContext, format: McpFormat): PreparedMcp | null;
|