@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
package/dist/activity.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { commandName, promisesLaterCheck, stripCode } from './keep-local.js';
|
|
2
|
+
const MAX_LABEL = 180;
|
|
3
|
+
const SECRET_PATTERNS = [
|
|
4
|
+
/\b(?:bearer|token|authorization)\s*[:=]?\s*[A-Za-z0-9._~+/-]{16,}=*/gi,
|
|
5
|
+
/\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}\b/g,
|
|
6
|
+
/\bgithub_pat_[A-Za-z0-9_]{20,}\b/g,
|
|
7
|
+
/\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
8
|
+
/\bsk-[A-Za-z0-9_-]{16,}\b/g,
|
|
9
|
+
/\blin_(?:api|oauth)_[A-Za-z0-9]{16,}\b/g,
|
|
10
|
+
/\bsntry[su]_[A-Za-z0-9]{16,}\b/g,
|
|
11
|
+
/\bfigd_[A-Za-z0-9_-]{16,}\b/g,
|
|
12
|
+
/\bATATT3[A-Za-z0-9_-]{20,}\b/g,
|
|
13
|
+
/\bAKIA[0-9A-Z]{16}\b/g,
|
|
14
|
+
/\bffr_[A-Za-z0-9]{16,}\b/g,
|
|
15
|
+
/\b(?:password|passwd|secret|api[_-]?key|access[_-]?token|client[_-]?secret)\s*[:=]\s*\S+/gi,
|
|
16
|
+
/https?:\/\/[^\s/]*:[^\s@/]+@/g,
|
|
17
|
+
];
|
|
18
|
+
export function redact(text, max = MAX_LABEL) {
|
|
19
|
+
let out = text.replace(/\s+/g, ' ').trim();
|
|
20
|
+
for (const re of SECRET_PATTERNS)
|
|
21
|
+
out = out.replace(re, (m) => `${m.slice(0, 4)}…[redacted]`);
|
|
22
|
+
return out.length > max ? `${out.slice(0, max - 1)}…` : out;
|
|
23
|
+
}
|
|
24
|
+
export function relativePath(p, worktree) {
|
|
25
|
+
const norm = p.replace(/\\/g, '/');
|
|
26
|
+
const root = worktree.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
27
|
+
const roots = new Set([root, root.replace(/^\/private(\/|$)/, '/'), `/private${root}`]);
|
|
28
|
+
for (const r of roots)
|
|
29
|
+
if (norm.startsWith(`${r}/`))
|
|
30
|
+
return norm.slice(r.length + 1);
|
|
31
|
+
const parts = norm.split('/').filter(Boolean);
|
|
32
|
+
return parts.length > 1 ? `…/${parts.slice(-2).join('/')}` : norm;
|
|
33
|
+
}
|
|
34
|
+
export function stripWorktree(command, worktree) {
|
|
35
|
+
const root = worktree.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
36
|
+
const roots = [root, root.replace(/^\/private(\/|$)/, '/'), `/private${root}`]
|
|
37
|
+
.filter((r, i, all) => r && all.indexOf(r) === i)
|
|
38
|
+
.sort((a, b) => b.length - a.length);
|
|
39
|
+
let out = command;
|
|
40
|
+
for (const r of roots)
|
|
41
|
+
out = out.split(`${r}/`).join('./').split(r).join('.');
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
function mcpParts(name) {
|
|
45
|
+
const m = /^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(name);
|
|
46
|
+
return m ? { server: m[1], action: m[2] } : null;
|
|
47
|
+
}
|
|
48
|
+
const TOOL_LABELS = {
|
|
49
|
+
github: 'GitHub',
|
|
50
|
+
jira: 'Jira',
|
|
51
|
+
linear: 'Linear',
|
|
52
|
+
sentry: 'Sentry',
|
|
53
|
+
slack: 'Slack',
|
|
54
|
+
figma: 'Figma',
|
|
55
|
+
};
|
|
56
|
+
export function stepOf(ev, ctx) {
|
|
57
|
+
const base = { seq: ctx.seq, at: ctx.now().toISOString() };
|
|
58
|
+
if (ev.kind === 'tool_result')
|
|
59
|
+
return null;
|
|
60
|
+
if (ev.kind === 'text') {
|
|
61
|
+
const first = stripCode(ev.text).replace(/\s+/g, ' ').trim();
|
|
62
|
+
if (!first)
|
|
63
|
+
return null;
|
|
64
|
+
return { ...base, kind: 'say', label: redact(first, 220) };
|
|
65
|
+
}
|
|
66
|
+
if (ev.kind === 'result') {
|
|
67
|
+
return {
|
|
68
|
+
...base,
|
|
69
|
+
kind: promisesLaterCheck(ev.text) ? 'say' : 'done',
|
|
70
|
+
label: redact(stripCode(ev.text), 220),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const name = ev.name;
|
|
74
|
+
const arg = ev.arg ?? '';
|
|
75
|
+
const mcp = mcpParts(name);
|
|
76
|
+
if (mcp) {
|
|
77
|
+
const viaFireFunc = mcp.server === 'firefunc' ? /^([a-z]+)_(.+)$/.exec(mcp.action) : null;
|
|
78
|
+
const tool = viaFireFunc ? viaFireFunc[1] : mcp.server;
|
|
79
|
+
const action = viaFireFunc ? viaFireFunc[2] : mcp.action;
|
|
80
|
+
const server = TOOL_LABELS[tool] ?? tool;
|
|
81
|
+
const write = ctx.writeTools?.has(name) === true;
|
|
82
|
+
return {
|
|
83
|
+
...base,
|
|
84
|
+
kind: 'tool',
|
|
85
|
+
label: `${server} · ${action.replace(/_/g, ' ')}`,
|
|
86
|
+
detail: {
|
|
87
|
+
tool,
|
|
88
|
+
action,
|
|
89
|
+
...(viaFireFunc ? { via: 'firefunc' } : {}),
|
|
90
|
+
...(write ? { write: true } : {}),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
switch (name) {
|
|
95
|
+
case 'Read':
|
|
96
|
+
case 'NotebookRead':
|
|
97
|
+
return { ...base, kind: 'read', label: fileLabel(arg, ctx.worktree) };
|
|
98
|
+
case 'Edit':
|
|
99
|
+
case 'MultiEdit':
|
|
100
|
+
case 'Write':
|
|
101
|
+
case 'NotebookEdit':
|
|
102
|
+
return {
|
|
103
|
+
...base,
|
|
104
|
+
kind: 'edit',
|
|
105
|
+
label: fileLabel(arg, ctx.worktree),
|
|
106
|
+
detail: { create: name === 'Write' },
|
|
107
|
+
};
|
|
108
|
+
case 'Bash':
|
|
109
|
+
return { ...base, kind: 'run', label: redact(commandName(arg), 140) };
|
|
110
|
+
case 'Grep':
|
|
111
|
+
case 'LS':
|
|
112
|
+
return {
|
|
113
|
+
...base,
|
|
114
|
+
kind: 'search',
|
|
115
|
+
label: redact(scopeOf(name === 'LS' ? arg : (ev.path ?? ''), ctx.worktree), 120),
|
|
116
|
+
detail: { how: name },
|
|
117
|
+
};
|
|
118
|
+
case 'Glob': {
|
|
119
|
+
const glob = inCheckout(arg, ctx.worktree);
|
|
120
|
+
const scope = scopeOf(ev.path ?? '', ctx.worktree);
|
|
121
|
+
const label = glob && GLOB.test(glob) ? (scope === CHECKOUT ? glob : `${scope}/${glob}`) : scope;
|
|
122
|
+
return { ...base, kind: 'search', label: redact(label, 120), detail: { how: name } };
|
|
123
|
+
}
|
|
124
|
+
case 'Skill':
|
|
125
|
+
return { ...base, kind: 'skill', label: redact(arg || 'a skill', 80) };
|
|
126
|
+
case 'WebFetch':
|
|
127
|
+
case 'WebSearch': {
|
|
128
|
+
let host = arg;
|
|
129
|
+
try {
|
|
130
|
+
host = new URL(arg).host;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
}
|
|
134
|
+
return { ...base, kind: 'web', label: redact(host || 'the web', 120) };
|
|
135
|
+
}
|
|
136
|
+
case 'Task':
|
|
137
|
+
case 'Agent':
|
|
138
|
+
return { ...base, kind: 'agent', label: redact(stripCode(arg) || 'a sub-agent', 120) };
|
|
139
|
+
case 'TodoWrite':
|
|
140
|
+
return { ...base, kind: 'plan', label: 'updated its plan' };
|
|
141
|
+
default: {
|
|
142
|
+
const where = arg && PATH_ONLY.test(arg) ? ` ${relativePath(arg, ctx.worktree)}` : '';
|
|
143
|
+
return { ...base, kind: 'tool', label: redact(`${name}${where}`, 120) };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function fileLabel(p, worktree) {
|
|
148
|
+
const rel = relativePath(p, worktree);
|
|
149
|
+
if (!rel)
|
|
150
|
+
return 'a file';
|
|
151
|
+
return rel.length > 200 ? `…${rel.slice(-199)}` : rel;
|
|
152
|
+
}
|
|
153
|
+
const CHECKOUT = 'the checkout';
|
|
154
|
+
const GLOB = /^[\w@.\/*?{},[\]!-]+$/;
|
|
155
|
+
const PATH_ONLY = /^[\w@.\/\\:~-]+$/;
|
|
156
|
+
function inCheckout(p, worktree) {
|
|
157
|
+
const norm = p.trim().replace(/\\/g, '/').replace(/\/+$/, '');
|
|
158
|
+
const folded = stripWorktree(norm, worktree).replace(/^\.(?:\/|$)/, '');
|
|
159
|
+
return /^(?:\/|[A-Za-z]:\/)/.test(folded) ? relativePath(folded, worktree) : folded;
|
|
160
|
+
}
|
|
161
|
+
function scopeOf(p, worktree) {
|
|
162
|
+
const where = PATH_ONLY.test(p.trim()) ? inCheckout(p, worktree) : '';
|
|
163
|
+
return where || CHECKOUT;
|
|
164
|
+
}
|
|
165
|
+
export function createActivityReporter(opts) {
|
|
166
|
+
const now = opts.now ?? (() => new Date());
|
|
167
|
+
const cap = opts.cap ?? 1500;
|
|
168
|
+
const holdMs = opts.holdMs ?? 2000;
|
|
169
|
+
const intervalMs = opts.intervalMs ?? 1500;
|
|
170
|
+
let seq = 0;
|
|
171
|
+
let sent = 0;
|
|
172
|
+
let pending = [];
|
|
173
|
+
let inflight = null;
|
|
174
|
+
let timer = null;
|
|
175
|
+
const awaiting = new Map();
|
|
176
|
+
const awaitingStep = new Map();
|
|
177
|
+
const arm = () => {
|
|
178
|
+
if (!timer)
|
|
179
|
+
timer = setTimeout(() => void flush(false), intervalMs);
|
|
180
|
+
};
|
|
181
|
+
const forget = (id) => {
|
|
182
|
+
const a = awaiting.get(id);
|
|
183
|
+
if (!a)
|
|
184
|
+
return;
|
|
185
|
+
awaiting.delete(id);
|
|
186
|
+
awaitingStep.delete(a.step);
|
|
187
|
+
};
|
|
188
|
+
const onResult = (id, isError) => {
|
|
189
|
+
const a = awaiting.get(id);
|
|
190
|
+
if (!a)
|
|
191
|
+
return;
|
|
192
|
+
forget(id);
|
|
193
|
+
if (!isError)
|
|
194
|
+
return;
|
|
195
|
+
if (!a.posted) {
|
|
196
|
+
a.step.detail = { ...(a.step.detail ?? {}), failed: true };
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
seq += 1;
|
|
200
|
+
pending.push({
|
|
201
|
+
seq,
|
|
202
|
+
at: now().toISOString(),
|
|
203
|
+
kind: a.step.kind,
|
|
204
|
+
label: a.step.label,
|
|
205
|
+
detail: { ...(a.step.detail ?? {}), failed: true, of: a.step.seq },
|
|
206
|
+
});
|
|
207
|
+
arm();
|
|
208
|
+
};
|
|
209
|
+
const push = (ev) => {
|
|
210
|
+
if (ev.kind === 'tool_result') {
|
|
211
|
+
onResult(ev.id, ev.isError);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const step = stepOf(ev, {
|
|
215
|
+
worktree: opts.worktree,
|
|
216
|
+
seq: seq + 1,
|
|
217
|
+
now,
|
|
218
|
+
writeTools: opts.writeTools,
|
|
219
|
+
});
|
|
220
|
+
if (!step || !step.label.trim())
|
|
221
|
+
return;
|
|
222
|
+
seq += 1;
|
|
223
|
+
if (seq + pending.length > cap && (step.kind === 'read' || step.kind === 'search')) {
|
|
224
|
+
if (seq % 5 !== 0)
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
pending.push(step);
|
|
228
|
+
if (ev.kind === 'tool' && ev.id && awaiting.size < 5000) {
|
|
229
|
+
const a = { step, bornMs: now().getTime(), posted: false };
|
|
230
|
+
awaiting.set(ev.id, a);
|
|
231
|
+
awaitingStep.set(step, a);
|
|
232
|
+
}
|
|
233
|
+
arm();
|
|
234
|
+
};
|
|
235
|
+
const flush = async (final = true) => {
|
|
236
|
+
if (timer) {
|
|
237
|
+
clearTimeout(timer);
|
|
238
|
+
timer = null;
|
|
239
|
+
}
|
|
240
|
+
if (inflight)
|
|
241
|
+
await inflight;
|
|
242
|
+
if (pending.length === 0)
|
|
243
|
+
return;
|
|
244
|
+
let batch = pending;
|
|
245
|
+
pending = [];
|
|
246
|
+
if (!final) {
|
|
247
|
+
const nowMs = now().getTime();
|
|
248
|
+
const held = batch.filter((st) => {
|
|
249
|
+
const a = awaitingStep.get(st);
|
|
250
|
+
return a !== undefined && !a.posted && nowMs - a.bornMs < holdMs;
|
|
251
|
+
});
|
|
252
|
+
if (held.length > 0) {
|
|
253
|
+
const keep = new Set(held);
|
|
254
|
+
batch = batch.filter((st) => !keep.has(st));
|
|
255
|
+
pending = held;
|
|
256
|
+
arm();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (batch.length === 0)
|
|
260
|
+
return;
|
|
261
|
+
for (const st of batch) {
|
|
262
|
+
const a = awaitingStep.get(st);
|
|
263
|
+
if (a)
|
|
264
|
+
a.posted = true;
|
|
265
|
+
}
|
|
266
|
+
inflight = opts
|
|
267
|
+
.post(batch)
|
|
268
|
+
.then(() => {
|
|
269
|
+
sent += batch.length;
|
|
270
|
+
})
|
|
271
|
+
.catch(() => {
|
|
272
|
+
for (const st of batch) {
|
|
273
|
+
const a = awaitingStep.get(st);
|
|
274
|
+
if (a)
|
|
275
|
+
a.posted = false;
|
|
276
|
+
}
|
|
277
|
+
pending = [...batch, ...pending].slice(-cap);
|
|
278
|
+
})
|
|
279
|
+
.finally(() => {
|
|
280
|
+
inflight = null;
|
|
281
|
+
});
|
|
282
|
+
await inflight;
|
|
283
|
+
};
|
|
284
|
+
return {
|
|
285
|
+
push,
|
|
286
|
+
flush,
|
|
287
|
+
get sent() {
|
|
288
|
+
return sent;
|
|
289
|
+
},
|
|
290
|
+
get seen() {
|
|
291
|
+
return seq;
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=activity.js.map
|
package/dist/api.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import type { RunUsage } from './usage.js';
|
|
1
2
|
export type ClaimedJob = {
|
|
2
3
|
runId: string;
|
|
3
4
|
workItemId: string;
|
|
4
5
|
prompt: string;
|
|
5
6
|
repo: string | null;
|
|
6
7
|
branch: string | null;
|
|
8
|
+
toolsOnly?: boolean;
|
|
9
|
+
continuesBranch?: boolean;
|
|
10
|
+
review?: boolean;
|
|
11
|
+
baseBranch?: string | null;
|
|
7
12
|
externalId: string | null;
|
|
8
13
|
title: string | null;
|
|
9
14
|
type: string;
|
|
@@ -16,9 +21,34 @@ export type ClaimedJob = {
|
|
|
16
21
|
contentType?: string | null;
|
|
17
22
|
dataB64: string;
|
|
18
23
|
}[];
|
|
24
|
+
skills?: {
|
|
25
|
+
slug: string;
|
|
26
|
+
name: string;
|
|
27
|
+
description?: string | null;
|
|
28
|
+
content: string;
|
|
29
|
+
}[];
|
|
30
|
+
contextPack?: unknown;
|
|
31
|
+
mcpConfig?: unknown;
|
|
32
|
+
maxMinutes?: number | null;
|
|
19
33
|
};
|
|
20
34
|
export type RunnerEvent = 'cloning' | 'fixing' | 'pushing' | 'pr_opened' | 'heartbeat' | 'log';
|
|
21
|
-
export type
|
|
35
|
+
export type PlanLimitReport = {
|
|
36
|
+
kind: 'plan';
|
|
37
|
+
resetsAt: string | null;
|
|
38
|
+
};
|
|
39
|
+
export type EngineLimitReport = PlanLimitReport & {
|
|
40
|
+
engine: string;
|
|
41
|
+
};
|
|
42
|
+
export type SecretScanReport = {
|
|
43
|
+
scanned: true;
|
|
44
|
+
hits: Array<{
|
|
45
|
+
path: string;
|
|
46
|
+
kind: string;
|
|
47
|
+
line: number;
|
|
48
|
+
}>;
|
|
49
|
+
head?: string;
|
|
50
|
+
};
|
|
51
|
+
export type ResultPayload = ({
|
|
22
52
|
status: 'pr_opened';
|
|
23
53
|
pr: {
|
|
24
54
|
repo?: string;
|
|
@@ -30,10 +60,22 @@ export type ResultPayload = {
|
|
|
30
60
|
} | {
|
|
31
61
|
status: 'no_pr';
|
|
32
62
|
error?: string;
|
|
63
|
+
summary?: string;
|
|
33
64
|
} | {
|
|
34
65
|
status: 'failed';
|
|
35
66
|
error: string;
|
|
67
|
+
}) & {
|
|
68
|
+
secretScan?: SecretScanReport;
|
|
69
|
+
usage?: RunUsage;
|
|
70
|
+
limit?: PlanLimitReport;
|
|
71
|
+
readHead?: string;
|
|
72
|
+
openCommandAtEnd?: true;
|
|
73
|
+
lost?: true;
|
|
36
74
|
};
|
|
75
|
+
export declare const REPORTED_SUMMARY_MAX = 65536;
|
|
76
|
+
export declare const OLDER_API_SUMMARY_MAX = 4000;
|
|
77
|
+
export declare function cutText(text: string, max: number): string;
|
|
78
|
+
export declare const RESULT_LADDER: readonly ["lost", "openCommandAtEnd", "readHead", "limit", "summary", "usage", "secretScan"];
|
|
37
79
|
export declare class RunnerApi {
|
|
38
80
|
private readonly apiUrl;
|
|
39
81
|
private readonly token;
|
|
@@ -45,6 +87,7 @@ export declare class RunnerApi {
|
|
|
45
87
|
platform: string;
|
|
46
88
|
viewerPort?: number | null;
|
|
47
89
|
engines?: string[];
|
|
90
|
+
maxParallel?: number;
|
|
48
91
|
budget?: Array<{
|
|
49
92
|
engine: string;
|
|
50
93
|
planLabel?: string;
|
|
@@ -54,8 +97,22 @@ export declare class RunnerApi {
|
|
|
54
97
|
resetsAt: string | null;
|
|
55
98
|
}>;
|
|
56
99
|
}>;
|
|
100
|
+
mcpLogins?: Array<{
|
|
101
|
+
server: string;
|
|
102
|
+
state: 'logged_in' | 'expired' | 'error';
|
|
103
|
+
via: 'runner' | 'claude_code';
|
|
104
|
+
accountLabel: string | null;
|
|
105
|
+
expiresAt: string | null;
|
|
106
|
+
detail?: string;
|
|
107
|
+
}>;
|
|
108
|
+
heldRuns?: string[];
|
|
109
|
+
lostRuns?: string[];
|
|
110
|
+
heartbeat?: true;
|
|
111
|
+
draining?: true;
|
|
112
|
+
limits?: EngineLimitReport[];
|
|
57
113
|
}): Promise<ClaimedJob | null>;
|
|
58
114
|
repos(): Promise<string[]>;
|
|
115
|
+
probe(): Promise<boolean>;
|
|
59
116
|
config(): Promise<{
|
|
60
117
|
maxParallel: number;
|
|
61
118
|
} | null>;
|
|
@@ -64,6 +121,17 @@ export declare class RunnerApi {
|
|
|
64
121
|
expiresAt: string;
|
|
65
122
|
repo: string;
|
|
66
123
|
} | null>;
|
|
124
|
+
mcpCredential(runId: string, server: string): Promise<{
|
|
125
|
+
token: string;
|
|
126
|
+
expiresAt?: string;
|
|
127
|
+
} | null>;
|
|
67
128
|
event(runId: string, event: RunnerEvent, detail?: Record<string, unknown>): Promise<void>;
|
|
129
|
+
activity(runId: string, steps: Array<{
|
|
130
|
+
seq: number;
|
|
131
|
+
at: string;
|
|
132
|
+
kind: string;
|
|
133
|
+
label: string;
|
|
134
|
+
detail?: Record<string, unknown>;
|
|
135
|
+
}>): Promise<void>;
|
|
68
136
|
result(runId: string, payload: ResultPayload): Promise<void>;
|
|
69
137
|
}
|
package/dist/api.js
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
import { RUNNER_VERSION } from './version.js';
|
|
2
|
+
export const REPORTED_SUMMARY_MAX = 65_536;
|
|
3
|
+
export const OLDER_API_SUMMARY_MAX = 4000;
|
|
4
|
+
export function cutText(text, max) {
|
|
5
|
+
if (text.length <= max)
|
|
6
|
+
return text;
|
|
7
|
+
const last = text.charCodeAt(max - 1);
|
|
8
|
+
return text.slice(0, last >= 0xd800 && last <= 0xdbff ? max - 1 : max);
|
|
9
|
+
}
|
|
10
|
+
export const RESULT_LADDER = [
|
|
11
|
+
'lost',
|
|
12
|
+
'openCommandAtEnd',
|
|
13
|
+
'readHead',
|
|
14
|
+
'limit',
|
|
15
|
+
'summary',
|
|
16
|
+
'usage',
|
|
17
|
+
'secretScan',
|
|
18
|
+
];
|
|
19
|
+
function onLadder(body, k) {
|
|
20
|
+
if (k === 'summary') {
|
|
21
|
+
return typeof body.summary === 'string' && body.summary.length > OLDER_API_SUMMARY_MAX;
|
|
22
|
+
}
|
|
23
|
+
return body[k] !== undefined;
|
|
24
|
+
}
|
|
25
|
+
async function unreadFields(res) {
|
|
26
|
+
try {
|
|
27
|
+
const text = await res.text();
|
|
28
|
+
if (!text)
|
|
29
|
+
return [];
|
|
30
|
+
const body = JSON.parse(text);
|
|
31
|
+
const found = new Set();
|
|
32
|
+
const visit = (v, depth) => {
|
|
33
|
+
if (depth > 4 || !v || typeof v !== 'object')
|
|
34
|
+
return;
|
|
35
|
+
if (Array.isArray(v)) {
|
|
36
|
+
for (const item of v)
|
|
37
|
+
visit(item, depth + 1);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const o = v;
|
|
41
|
+
if (o.code === 'unrecognized_keys' && Array.isArray(o.keys)) {
|
|
42
|
+
for (const k of o.keys)
|
|
43
|
+
if (typeof k === 'string')
|
|
44
|
+
found.add(k);
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(o.path) && typeof o.path[0] === 'string')
|
|
47
|
+
found.add(o.path[0]);
|
|
48
|
+
for (const key of ['issues', 'details', 'errors', 'error'])
|
|
49
|
+
visit(o[key], depth + 1);
|
|
50
|
+
};
|
|
51
|
+
visit(body, 0);
|
|
52
|
+
return [...found];
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
1
58
|
export class RunnerApi {
|
|
2
59
|
apiUrl;
|
|
3
60
|
token;
|
|
@@ -44,9 +101,20 @@ export class RunnerApi {
|
|
|
44
101
|
return [];
|
|
45
102
|
}
|
|
46
103
|
}
|
|
47
|
-
async
|
|
104
|
+
async probe() {
|
|
48
105
|
try {
|
|
49
106
|
const res = await fetch(`${this.apiUrl}/channel/config`, { headers: this.headers() });
|
|
107
|
+
return res.ok || res.status === 401;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async config() {
|
|
114
|
+
try {
|
|
115
|
+
const res = await fetch(`${this.apiUrl}/channel/config`, {
|
|
116
|
+
headers: { ...this.headers(), 'x-firefunc-runner-version': RUNNER_VERSION },
|
|
117
|
+
});
|
|
50
118
|
if (!res.ok)
|
|
51
119
|
return null;
|
|
52
120
|
const body = (await res.json());
|
|
@@ -74,6 +142,24 @@ export class RunnerApi {
|
|
|
74
142
|
return null;
|
|
75
143
|
}
|
|
76
144
|
}
|
|
145
|
+
async mcpCredential(runId, server) {
|
|
146
|
+
try {
|
|
147
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/mcp-credential`, {
|
|
148
|
+
method: 'POST',
|
|
149
|
+
headers: this.headers(),
|
|
150
|
+
body: JSON.stringify({ server }),
|
|
151
|
+
});
|
|
152
|
+
if (!res.ok)
|
|
153
|
+
return null;
|
|
154
|
+
const body = (await res.json());
|
|
155
|
+
if (!body.ok || !body.token)
|
|
156
|
+
return null;
|
|
157
|
+
return { token: body.token, expiresAt: body.expiresAt };
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
77
163
|
async event(runId, event, detail) {
|
|
78
164
|
await fetch(`${this.apiUrl}/channel/runs/${runId}/events`, {
|
|
79
165
|
method: 'POST',
|
|
@@ -81,12 +167,37 @@ export class RunnerApi {
|
|
|
81
167
|
body: JSON.stringify({ event, detail }),
|
|
82
168
|
}).catch(() => { });
|
|
83
169
|
}
|
|
170
|
+
async activity(runId, steps) {
|
|
171
|
+
const res = await fetch(`${this.apiUrl}/channel/runs/${runId}/activity`, {
|
|
172
|
+
method: 'POST',
|
|
173
|
+
headers: this.headers(),
|
|
174
|
+
body: JSON.stringify({ steps }),
|
|
175
|
+
});
|
|
176
|
+
if (!res.ok)
|
|
177
|
+
throw new Error(`activity post failed: ${res.status}`);
|
|
178
|
+
}
|
|
84
179
|
async result(runId, payload) {
|
|
85
|
-
const
|
|
180
|
+
const post = (body) => fetch(`${this.apiUrl}/channel/runs/${runId}/result`, {
|
|
86
181
|
method: 'POST',
|
|
87
182
|
headers: this.headers(),
|
|
88
|
-
body: JSON.stringify(
|
|
183
|
+
body: JSON.stringify(body),
|
|
89
184
|
});
|
|
185
|
+
let res = await post(payload);
|
|
186
|
+
let sent = { ...payload };
|
|
187
|
+
const left = RESULT_LADDER.filter((k) => onLadder(sent, k));
|
|
188
|
+
while (res.status === 400 && left.length > 0) {
|
|
189
|
+
const named = (await unreadFields(res)).filter((k) => left.includes(k));
|
|
190
|
+
const drop = named.length > 0 ? named : [left[0]];
|
|
191
|
+
sent = { ...sent };
|
|
192
|
+
for (const k of drop) {
|
|
193
|
+
if (k === 'summary')
|
|
194
|
+
sent.summary = cutText(String(sent.summary), OLDER_API_SUMMARY_MAX);
|
|
195
|
+
else
|
|
196
|
+
delete sent[k];
|
|
197
|
+
left.splice(left.indexOf(k), 1);
|
|
198
|
+
}
|
|
199
|
+
res = await post(sent);
|
|
200
|
+
}
|
|
90
201
|
if (!res.ok)
|
|
91
202
|
throw new Error(`result report failed: ${res.status}`);
|
|
92
203
|
}
|
package/dist/brief.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
import type { ClaimedJob } from './api.js';
|
|
1
2
|
import type { RunnerConfig } from './config.js';
|
|
3
|
+
export declare function engineRules(opts: {
|
|
4
|
+
minutes: number;
|
|
5
|
+
heavy: boolean;
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function continueToFinishBrief(open: string[]): string;
|
|
8
|
+
export declare function scanBeforePush(worktree: string, from: string, branch: string): Promise<{
|
|
9
|
+
refusal: string | null;
|
|
10
|
+
note: string | null;
|
|
11
|
+
}>;
|
|
2
12
|
export declare function runBrief(repo: string, cfg: RunnerConfig): Promise<void>;
|
|
13
|
+
export declare function renderJobBrief(job: ClaimedJob): string;
|