@firefunc-agent/runner 0.9.34 → 0.9.35
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 +17 -0
- package/dist/api.d.ts +1 -0
- package/dist/build-info.json +2 -2
- package/dist/config.d.ts +1 -0
- package/dist/engine-account.js +1 -1
- package/dist/engines/antigravity.d.ts +2 -0
- package/dist/engines/antigravity.js +55 -0
- package/dist/engines/claude.js +12 -0
- package/dist/firefunc/automations.d.ts +2 -0
- package/dist/firefunc/automations.js +290 -0
- package/dist/firefunc/main.js +26 -1
- package/dist/job.js +11 -0
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +26 -3
- package/dist/openrouter.d.ts +15 -0
- package/dist/openrouter.js +39 -0
- package/dist/sign-in.d.ts +1 -0
- package/dist/sign-in.js +6 -2
- package/package.json +1 -1
- package/skill/firefunc/SKILL.md +18 -0
package/README.md
CHANGED
|
@@ -565,6 +565,23 @@ An agent's job may ask for one way. When this machine cannot honour it (no key,
|
|
|
565
565
|
signed in) and no fallback allows the other way, the run ends at once with the reason and the fix,
|
|
566
566
|
for example "No Google key on dan-mbp. Set GEMINI_API_KEY on it, then run the engine check again."
|
|
567
567
|
|
|
568
|
+
## Claude Code through OpenRouter (0.9.35)
|
|
569
|
+
|
|
570
|
+
An agent, a routing job, a task or a workflow step may send Claude Code's requests to OpenRouter
|
|
571
|
+
instead of Anthropic. The runner then starts Claude Code with OpenRouter's documented setup:
|
|
572
|
+
|
|
573
|
+
```text
|
|
574
|
+
ANTHROPIC_BASE_URL=https://openrouter.ai/api
|
|
575
|
+
ANTHROPIC_AUTH_TOKEN=<this machine's OPENROUTER_API_KEY>
|
|
576
|
+
ANTHROPIC_API_KEY=""
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
The key is read from this machine only: the runner config's `claudeEnv.OPENROUTER_API_KEY`, else
|
|
580
|
+
the environment the runner was started in. FireFunc never stores it; the runner reports only whether
|
|
581
|
+
it is set. A machine without it ends such a run at once: set `OPENROUTER_API_KEY` there, restart
|
|
582
|
+
the runner, and run the task again. The model is passed as OpenRouter names it
|
|
583
|
+
(`anthropic/claude-sonnet-5.5`). A runner older than 0.9.35 is never handed one of these runs.
|
|
584
|
+
|
|
568
585
|
## Licence
|
|
569
586
|
|
|
570
587
|
`@firefunc-agent/runner` is the **client** half of FireFunc, published so the machines
|
package/dist/api.d.ts
CHANGED
package/dist/build-info.json
CHANGED
package/dist/config.d.ts
CHANGED
package/dist/engine-account.js
CHANGED
|
@@ -7,7 +7,7 @@ function noticeLine(text) {
|
|
|
7
7
|
return first && first.length <= 300 ? first : null;
|
|
8
8
|
}
|
|
9
9
|
const NO_CREDIT = /\bcredit balance is too low\b/i;
|
|
10
|
-
const SIGNED_OUT = /^(?:error:\s*)?(?:not logged in\b|please run \/login\b|invalid api key\b|invalid x-api-key\b|oauth (?:access )?token (?:has )?(?:expired|been revoked)\b|failed to authenticate\b|api error: 401\b)|\bauthentication_error\b/i;
|
|
10
|
+
const SIGNED_OUT = /^(?:error:\s*)?(?:not logged in\b|login expired\b|(?:please )?run \/login\b|invalid api key\b|invalid x-api-key\b|oauth (?:access )?token (?:has )?(?:expired|been revoked)\b|failed to authenticate\b|api error: 401\b)|\bauthentication_error\b|\bineligibletiererror\b/i;
|
|
11
11
|
export function accountProblemOf(ending, opts) {
|
|
12
12
|
let line;
|
|
13
13
|
if (ending) {
|
|
@@ -11,6 +11,51 @@ function antigravityEffort(effort) {
|
|
|
11
11
|
return 'xhigh';
|
|
12
12
|
return 'high';
|
|
13
13
|
}
|
|
14
|
+
export function antigravityUsage(stdout) {
|
|
15
|
+
const lines = stdout.trim().split('\n');
|
|
16
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
17
|
+
let ev;
|
|
18
|
+
try {
|
|
19
|
+
ev = JSON.parse(lines[i]);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (typeof ev !== 'object' || ev === null)
|
|
25
|
+
continue;
|
|
26
|
+
const e = ev;
|
|
27
|
+
if (e.event !== 'result' && e.type !== 'result')
|
|
28
|
+
continue;
|
|
29
|
+
const u = (typeof e.result === 'object' && e.result !== null
|
|
30
|
+
? e.result.usage
|
|
31
|
+
: undefined) ?? e.usage;
|
|
32
|
+
if (typeof u !== 'object' || u === null)
|
|
33
|
+
return null;
|
|
34
|
+
const o = u;
|
|
35
|
+
const n = (...keys) => {
|
|
36
|
+
for (const k of keys) {
|
|
37
|
+
const v = o[k];
|
|
38
|
+
if (typeof v === 'number' && Number.isFinite(v) && v >= 0)
|
|
39
|
+
return v;
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
};
|
|
43
|
+
const input = n('input_tokens', 'inputTokens', 'prompt_tokens', 'promptTokenCount');
|
|
44
|
+
const output = n('output_tokens', 'outputTokens', 'completion_tokens', 'candidatesTokenCount');
|
|
45
|
+
if (input === undefined && output === undefined)
|
|
46
|
+
return null;
|
|
47
|
+
const thinking = n('thinking_tokens', 'thinkingTokens', 'thoughtsTokenCount');
|
|
48
|
+
const cached = n('cache_read_input_tokens', 'cachedTokens', 'cachedContentTokenCount');
|
|
49
|
+
return {
|
|
50
|
+
input_tokens: input ?? 0,
|
|
51
|
+
output_tokens: output ?? 0,
|
|
52
|
+
...(thinking !== undefined ? { thinking_tokens: thinking } : {}),
|
|
53
|
+
...(cached !== undefined ? { cache_read_input_tokens: cached } : {}),
|
|
54
|
+
auth: 'subscription',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
14
59
|
function antigravitySummary(stdout) {
|
|
15
60
|
const lines = stdout.trim().split('\n');
|
|
16
61
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
@@ -19,6 +64,13 @@ function antigravitySummary(stdout) {
|
|
|
19
64
|
if (ev.type === 'result' && typeof ev.result === 'string' && ev.result.trim()) {
|
|
20
65
|
return ev.result.trim();
|
|
21
66
|
}
|
|
67
|
+
if ((ev.event === 'result' || ev.type === 'result') &&
|
|
68
|
+
typeof ev.result === 'object' &&
|
|
69
|
+
ev.result !== null &&
|
|
70
|
+
typeof ev.result.response === 'string' &&
|
|
71
|
+
ev.result.response.trim()) {
|
|
72
|
+
return ev.result.response.trim();
|
|
73
|
+
}
|
|
22
74
|
if (typeof ev.response === 'string' && ev.response.trim())
|
|
23
75
|
return ev.response.trim();
|
|
24
76
|
if (ev.type === 'assistant' && ev.message?.content) {
|
|
@@ -82,6 +134,9 @@ export const antigravityAdapter = {
|
|
|
82
134
|
makeStreamPrinter() {
|
|
83
135
|
return makeStreamJsonParser(() => { });
|
|
84
136
|
},
|
|
137
|
+
meter(stdout) {
|
|
138
|
+
return antigravityUsage(stdout);
|
|
139
|
+
},
|
|
85
140
|
summarize(stdout) {
|
|
86
141
|
return antigravitySummary(stdout);
|
|
87
142
|
},
|
package/dist/engines/claude.js
CHANGED
|
@@ -5,6 +5,7 @@ import { mcpFromContext } from '../mcp.js';
|
|
|
5
5
|
import { readClaudeLimit } from '../limit.js';
|
|
6
6
|
import { claudeApiKeyNow } from '../api-fallback.js';
|
|
7
7
|
import { commandName } from '../keep-local.js';
|
|
8
|
+
import { openRouterClaudeEnv, openRouterKeyOf } from '../openrouter.js';
|
|
8
9
|
function claudeSummary(streamJson) {
|
|
9
10
|
const lines = streamJson.trim().split('\n');
|
|
10
11
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
@@ -191,6 +192,17 @@ export const claudeAdapter = {
|
|
|
191
192
|
args.push('--mcp-config', mcp.configPath, '--strict-mcp-config');
|
|
192
193
|
}
|
|
193
194
|
args.push(...(cfg.claudeArgs ?? []));
|
|
195
|
+
const openRouterKey = cfg.claudeEndpoint === 'openrouter' ? openRouterKeyOf(cfg) : null;
|
|
196
|
+
if (openRouterKey) {
|
|
197
|
+
return {
|
|
198
|
+
bin: this.bin(cfg),
|
|
199
|
+
args,
|
|
200
|
+
env: openRouterClaudeEnv(ctx.runEnv, openRouterKey),
|
|
201
|
+
stdinInput: ctx.prompt,
|
|
202
|
+
shell: ctx.isWin,
|
|
203
|
+
authLogLine: 'OpenRouter (OPENROUTER_API_KEY from this machine; ANTHROPIC_BASE_URL=https://openrouter.ai/api)',
|
|
204
|
+
};
|
|
205
|
+
}
|
|
194
206
|
const billing = claudeApiKeyNow(cfg);
|
|
195
207
|
const env = billing.why === 'opted-in'
|
|
196
208
|
? ctx.runEnv
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { bool, str, UsageError } from './args.js';
|
|
2
|
+
import { listIn, resolveProjectId } from './catalog.js';
|
|
3
|
+
import { enc, readInputFile } from './command.js';
|
|
4
|
+
import { Refusal } from './io.js';
|
|
5
|
+
import { printJson, table, text, wrap } from './output.js';
|
|
6
|
+
const MODES = ['live', 'dry', 'test'];
|
|
7
|
+
const FINAL = new Set(['succeeded', 'failed', 'canceled', 'skipped']);
|
|
8
|
+
function problemLines(problems) {
|
|
9
|
+
const list = Array.isArray(problems) ? problems : [];
|
|
10
|
+
const out = [];
|
|
11
|
+
for (const p of list) {
|
|
12
|
+
out.push(...wrap(`${text(p.level)}: ${text(p.text)}`, 78, ' ', ' '));
|
|
13
|
+
if (p.fix)
|
|
14
|
+
out.push(...wrap(`fix: ${text(p.fix)}`, 78, ' ', ' '));
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
function parseJsonFlag(raw, flag) {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(raw);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
throw new Refusal(`--${flag} is not JSON (${e.message}).`, `Write it as a JSON object, for example --${flag} '{"name": "value"}'.`, 'bad_json');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function runLine(r) {
|
|
27
|
+
const err = r.error;
|
|
28
|
+
return `run #${text(r.number)} ${text(r.state)} ${text(r.id)}${err ? ` ${text(err.reason)}` : ''}`;
|
|
29
|
+
}
|
|
30
|
+
async function printRun(ctx, body) {
|
|
31
|
+
const r = body.run ?? body;
|
|
32
|
+
const lines = [runLine(r)];
|
|
33
|
+
const err = r.error;
|
|
34
|
+
if (err?.fix)
|
|
35
|
+
lines.push(...wrap(`fix: ${text(err.fix)}`, 78, ' ', ' '));
|
|
36
|
+
const steps = Array.isArray(body.steps) ? body.steps : [];
|
|
37
|
+
for (const s of steps) {
|
|
38
|
+
const e = s.error;
|
|
39
|
+
lines.push(` ${text(s.nodeId ?? s.key)} ${text(s.state)} ${text(s.name)}${e ? ` ${text(e.reason ?? e.message)}` : ''}`);
|
|
40
|
+
}
|
|
41
|
+
ctx.io.stdout.write(`${lines.join('\n')}\n`);
|
|
42
|
+
}
|
|
43
|
+
export const automationCommands = [
|
|
44
|
+
{
|
|
45
|
+
path: ['automations', 'list'],
|
|
46
|
+
summary: 'The workflows and orchestrations in this workspace',
|
|
47
|
+
usage: 'automations list [--project <id or name>]',
|
|
48
|
+
flags: { project: 'string' },
|
|
49
|
+
flagHelp: [['--project <id or name>', "only this project's automations"]],
|
|
50
|
+
async run(ctx) {
|
|
51
|
+
const project = str(ctx.args, 'project');
|
|
52
|
+
const query = project ? { project: await resolveProjectId(ctx, project) } : undefined;
|
|
53
|
+
const body = await ctx.api().get('/api/v1/automations', query);
|
|
54
|
+
if (ctx.json)
|
|
55
|
+
return printJson(ctx.io, body);
|
|
56
|
+
const rows = listIn(body, 'automations');
|
|
57
|
+
if (!rows.length) {
|
|
58
|
+
ctx.io.stdout.write('No automations here yet. Make one: firefunc automations create\n');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
table(ctx.io, rows, [
|
|
62
|
+
{ head: 'ID', get: (r) => r.id },
|
|
63
|
+
{ head: 'NAME', get: (r) => r.name, max: 40 },
|
|
64
|
+
{ head: 'KIND', get: (r) => r.kind },
|
|
65
|
+
{ head: 'STATUS', get: (r) => r.status },
|
|
66
|
+
{ head: 'PROJECT', get: (r) => r.project?.name ?? 'whole workspace' },
|
|
67
|
+
]);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
path: ['automations', 'templates'],
|
|
72
|
+
summary: 'Automations to start from, and the agents each brings',
|
|
73
|
+
usage: 'automations templates',
|
|
74
|
+
async run(ctx) {
|
|
75
|
+
const body = await ctx.api().get('/api/v1/automations/templates');
|
|
76
|
+
if (ctx.json)
|
|
77
|
+
return printJson(ctx.io, body);
|
|
78
|
+
table(ctx.io, listIn(body, 'templates'), [
|
|
79
|
+
{ head: 'ID', get: (r) => r.id },
|
|
80
|
+
{ head: 'KIND', get: (r) => r.kind },
|
|
81
|
+
{ head: 'NAME', get: (r) => r.name, max: 40 },
|
|
82
|
+
{
|
|
83
|
+
head: 'BRINGS',
|
|
84
|
+
get: (r) => (Array.isArray(r.brings) ? r.brings : []).map((b) => b.name).join(', '),
|
|
85
|
+
max: 50,
|
|
86
|
+
},
|
|
87
|
+
]);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
path: ['automations', 'get'],
|
|
92
|
+
summary: 'One automation: how it starts, its inputs and its problems',
|
|
93
|
+
usage: 'automations get <id>',
|
|
94
|
+
positional: { min: 1, max: 1 },
|
|
95
|
+
async run(ctx) {
|
|
96
|
+
const id = ctx.args.positional[0];
|
|
97
|
+
const body = await ctx.api().get(`/api/v1/automations/${enc(id)}`);
|
|
98
|
+
if (ctx.json)
|
|
99
|
+
return printJson(ctx.io, body);
|
|
100
|
+
const a = body.automation ?? {};
|
|
101
|
+
const lines = [
|
|
102
|
+
`${text(a.name)}`,
|
|
103
|
+
` id: ${text(a.id)}`,
|
|
104
|
+
` kind: ${text(a.kind)}`,
|
|
105
|
+
` status: ${text(a.status)}`,
|
|
106
|
+
];
|
|
107
|
+
const problems = problemLines(body.problems);
|
|
108
|
+
lines.push(problems.length ? ' problems:' : ' problems: none', ...problems);
|
|
109
|
+
ctx.io.stdout.write(`${lines.join('\n')}\n`);
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
path: ['automations', 'create'],
|
|
114
|
+
summary: 'Make a workflow or orchestration as a DRAFT (nothing runs until it is published)',
|
|
115
|
+
usage: 'automations create --name <name> (--spec <file.json> | --from-template <id> | --kind workflow|orchestration) [--project <id or name>]',
|
|
116
|
+
flags: {
|
|
117
|
+
name: 'string',
|
|
118
|
+
spec: 'string',
|
|
119
|
+
'from-template': 'string',
|
|
120
|
+
kind: 'string',
|
|
121
|
+
project: 'string',
|
|
122
|
+
},
|
|
123
|
+
flagHelp: [
|
|
124
|
+
['--name <name>', 'what people call it'],
|
|
125
|
+
['--spec <file.json>', 'the whole definition as JSON ("-" for stdin)'],
|
|
126
|
+
[
|
|
127
|
+
'--from-template <id>',
|
|
128
|
+
'start from a template (automations templates); it brings its agents, paused',
|
|
129
|
+
],
|
|
130
|
+
['--kind <kind>', 'an empty workflow or orchestration'],
|
|
131
|
+
['--project <id or name>', 'the project it belongs to; left out: the whole workspace'],
|
|
132
|
+
],
|
|
133
|
+
async run(ctx) {
|
|
134
|
+
const name = str(ctx.args, 'name');
|
|
135
|
+
if (!name)
|
|
136
|
+
throw new UsageError('--name is required.', ctx.command);
|
|
137
|
+
const spec = str(ctx.args, 'spec');
|
|
138
|
+
const fromTemplate = str(ctx.args, 'from-template');
|
|
139
|
+
const kind = str(ctx.args, 'kind');
|
|
140
|
+
if (!spec && !fromTemplate && !kind)
|
|
141
|
+
throw new UsageError('Give --spec, --from-template or --kind.', ctx.command);
|
|
142
|
+
const project = str(ctx.args, 'project');
|
|
143
|
+
const body = {
|
|
144
|
+
name,
|
|
145
|
+
...(project ? { projectId: await resolveProjectId(ctx, project) } : {}),
|
|
146
|
+
...(spec ? { spec: parseJsonFlag(await readInputFile(ctx.io, spec, 'spec'), 'spec') } : {}),
|
|
147
|
+
...(fromTemplate ? { fromTemplate } : {}),
|
|
148
|
+
...(kind ? { kind } : {}),
|
|
149
|
+
};
|
|
150
|
+
const answer = await ctx.api().post('/api/v1/automations', body);
|
|
151
|
+
if (ctx.json)
|
|
152
|
+
return printJson(ctx.io, answer);
|
|
153
|
+
const a = answer.automation ?? {};
|
|
154
|
+
const lines = [`Made "${text(a.name)}" as a draft: ${text(a.id)}`];
|
|
155
|
+
const brought = Array.isArray(answer.brought) ? answer.brought : [];
|
|
156
|
+
for (const b of brought)
|
|
157
|
+
lines.push(` brought ${text(b.name)} (${text(b.how)}, ${text(b.status)})`);
|
|
158
|
+
const problems = problemLines(answer.problems);
|
|
159
|
+
if (problems.length)
|
|
160
|
+
lines.push(' problems before it can be published:', ...problems);
|
|
161
|
+
lines.push(`Next: firefunc automations publish ${text(a.id)}`);
|
|
162
|
+
ctx.io.stdout.write(`${lines.join('\n')}\n`);
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
path: ['automations', 'check'],
|
|
167
|
+
summary: 'The checks behind Publish, on the saved draft',
|
|
168
|
+
usage: 'automations check <id>',
|
|
169
|
+
positional: { min: 1, max: 1 },
|
|
170
|
+
async run(ctx) {
|
|
171
|
+
const id = ctx.args.positional[0];
|
|
172
|
+
const body = await ctx.api().post(`/api/v1/automations/${enc(id)}/check`, {});
|
|
173
|
+
if (ctx.json)
|
|
174
|
+
return printJson(ctx.io, body);
|
|
175
|
+
const problems = problemLines(body.problems);
|
|
176
|
+
ctx.io.stdout.write(`${problems.length ? problems.join('\n') : 'No problems.'}\n`);
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
path: ['automations', 'publish'],
|
|
181
|
+
summary: 'Publish the draft: from then on its triggers start REAL runs',
|
|
182
|
+
usage: 'automations publish <id> [--note <text>] --yes',
|
|
183
|
+
details: 'Publishing makes it live at once: a tool trigger takes the next real event, a schedule its\n' +
|
|
184
|
+
'next time. It asks for --yes so a script never does it by accident. The answer says where it\n' +
|
|
185
|
+
'went live and names the agents a run would wait at (a template brings its agents paused).',
|
|
186
|
+
positional: { min: 1, max: 1 },
|
|
187
|
+
flags: { note: 'string', yes: 'boolean' },
|
|
188
|
+
flagHelp: [
|
|
189
|
+
['--note <text>', 'what changed, for the version list'],
|
|
190
|
+
['--yes', 'yes, make it live now'],
|
|
191
|
+
],
|
|
192
|
+
async run(ctx) {
|
|
193
|
+
const id = ctx.args.positional[0];
|
|
194
|
+
if (!bool(ctx.args, 'yes')) {
|
|
195
|
+
const a = await ctx.api().get(`/api/v1/automations/${enc(id)}`);
|
|
196
|
+
const auto = a.automation ?? {};
|
|
197
|
+
throw new Refusal(`Publishing "${text(auto.name)}" makes it live at once: its triggers start real runs.`, `Read it first (firefunc automations get ${id}), then run this again with --yes.`, 'needs_yes');
|
|
198
|
+
}
|
|
199
|
+
const note = str(ctx.args, 'note');
|
|
200
|
+
const body = await ctx
|
|
201
|
+
.api()
|
|
202
|
+
.post(`/api/v1/automations/${enc(id)}/publish`, note ? { note } : {});
|
|
203
|
+
if (ctx.json)
|
|
204
|
+
return printJson(ctx.io, body);
|
|
205
|
+
const v = body.version ?? {};
|
|
206
|
+
const lines = [`Published version ${text(v.number)}.`];
|
|
207
|
+
if (body.goesLive)
|
|
208
|
+
lines.push(...wrap(text(body.goesLive), 78, ' ', ' '));
|
|
209
|
+
const held = Array.isArray(body.heldAgents) ? body.heldAgents : [];
|
|
210
|
+
if (held.length)
|
|
211
|
+
lines.push(...wrap(`Runs wait at ${held.map((h) => `${text(h.name)} (${text(h.status)})`).join(', ')} until each is switched on: firefunc agents resume <id>.`, 78, ' ', ' '));
|
|
212
|
+
const tokens = body.webhookTokens ?? {};
|
|
213
|
+
for (const [t, token] of Object.entries(tokens))
|
|
214
|
+
lines.push(` webhook token for ${t} (shown once): ${token}`);
|
|
215
|
+
lines.push(...problemLines(body.warnings));
|
|
216
|
+
ctx.io.stdout.write(`${lines.join('\n')}\n`);
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
path: ['automations', 'run'],
|
|
221
|
+
summary: 'Start a run of the published version by hand',
|
|
222
|
+
usage: 'automations run <id> [--inputs <json>] [--mode live|dry|test] [--watch]',
|
|
223
|
+
positional: { min: 1, max: 1 },
|
|
224
|
+
flags: { inputs: 'string', mode: 'string', watch: 'boolean' },
|
|
225
|
+
flagHelp: [
|
|
226
|
+
['--inputs <json>', 'the run’s inputs by name, as a JSON object'],
|
|
227
|
+
['--mode <mode>', 'live (default); dry starts nothing; test records writes without sending'],
|
|
228
|
+
['--watch', 'follow the run until it ends'],
|
|
229
|
+
],
|
|
230
|
+
async run(ctx) {
|
|
231
|
+
const id = ctx.args.positional[0];
|
|
232
|
+
const mode = str(ctx.args, 'mode');
|
|
233
|
+
if (mode && !MODES.includes(mode))
|
|
234
|
+
throw new UsageError(`--mode is one of ${MODES.join(', ')}.`, ctx.command);
|
|
235
|
+
const inputs = str(ctx.args, 'inputs');
|
|
236
|
+
const started = await ctx.api().post(`/api/v1/automations/${enc(id)}/runs`, {
|
|
237
|
+
...(inputs ? { inputs: parseJsonFlag(inputs, 'inputs') } : {}),
|
|
238
|
+
...(mode ? { mode } : {}),
|
|
239
|
+
});
|
|
240
|
+
const run = started.run ?? {};
|
|
241
|
+
if (!bool(ctx.args, 'watch')) {
|
|
242
|
+
if (ctx.json)
|
|
243
|
+
return printJson(ctx.io, started);
|
|
244
|
+
ctx.io.stdout.write(`Started ${runLine(run)}\nFollow it: firefunc automations run-get ${text(run.id)}\n`);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
let body = started;
|
|
248
|
+
for (let i = 0; i < 300; i++) {
|
|
249
|
+
body = await ctx.api().get(`/api/v1/automation-runs/${enc(String(run.id))}`);
|
|
250
|
+
const state = String((body.run ?? {}).state ?? '');
|
|
251
|
+
if (FINAL.has(state) || state === 'waiting')
|
|
252
|
+
break;
|
|
253
|
+
await ctx.io.sleep(2000);
|
|
254
|
+
}
|
|
255
|
+
if (ctx.json)
|
|
256
|
+
return printJson(ctx.io, body);
|
|
257
|
+
await printRun(ctx, body);
|
|
258
|
+
const state = String((body.run ?? {}).state ?? '');
|
|
259
|
+
return state === 'failed' ? 1 : 0;
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
path: ['automations', 'runs'],
|
|
264
|
+
summary: "An automation's recent runs",
|
|
265
|
+
usage: 'automations runs <id>',
|
|
266
|
+
positional: { min: 1, max: 1 },
|
|
267
|
+
async run(ctx) {
|
|
268
|
+
const id = ctx.args.positional[0];
|
|
269
|
+
const body = await ctx.api().get(`/api/v1/automations/${enc(id)}/runs`);
|
|
270
|
+
if (ctx.json)
|
|
271
|
+
return printJson(ctx.io, body);
|
|
272
|
+
const rows = listIn(body, 'runs');
|
|
273
|
+
ctx.io.stdout.write(rows.length ? `${rows.map(runLine).join('\n')}\n` : 'No runs yet.\n');
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
path: ['automations', 'run-get'],
|
|
278
|
+
summary: 'One run: its state and each step',
|
|
279
|
+
usage: 'automations run-get <run id>',
|
|
280
|
+
positional: { min: 1, max: 1 },
|
|
281
|
+
async run(ctx) {
|
|
282
|
+
const id = ctx.args.positional[0];
|
|
283
|
+
const body = await ctx.api().get(`/api/v1/automation-runs/${enc(id)}`);
|
|
284
|
+
if (ctx.json)
|
|
285
|
+
return printJson(ctx.io, body);
|
|
286
|
+
await printRun(ctx, body);
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
];
|
|
290
|
+
//# sourceMappingURL=automations.js.map
|
package/dist/firefunc/main.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GLOBAL_FLAGS, parseArgs, str, UsageError } from './args.js';
|
|
2
2
|
import { agentCommands } from './agents.js';
|
|
3
3
|
import { authCommands } from './auth.js';
|
|
4
|
+
import { automationCommands } from './automations.js';
|
|
4
5
|
import { catalogCommands } from './catalog.js';
|
|
5
6
|
import { freshAccessToken } from './oauth-login.js';
|
|
6
7
|
import { ApiClient } from './client.js';
|
|
@@ -17,10 +18,20 @@ export const COMMANDS = [
|
|
|
17
18
|
...catalogCommands,
|
|
18
19
|
...agentCommands,
|
|
19
20
|
...taskCommands,
|
|
21
|
+
...automationCommands,
|
|
20
22
|
...configureCommands,
|
|
21
23
|
...skillCommands,
|
|
22
24
|
];
|
|
23
|
-
const GROUPS = [
|
|
25
|
+
const GROUPS = [
|
|
26
|
+
'templates',
|
|
27
|
+
'projects',
|
|
28
|
+
'connections',
|
|
29
|
+
'skills',
|
|
30
|
+
'agents',
|
|
31
|
+
'tasks',
|
|
32
|
+
'automations',
|
|
33
|
+
'skill',
|
|
34
|
+
];
|
|
24
35
|
const SECTIONS = [
|
|
25
36
|
['Sign in', ['login', 'logout', 'whoami']],
|
|
26
37
|
[
|
|
@@ -40,6 +51,20 @@ const SECTIONS = [
|
|
|
40
51
|
],
|
|
41
52
|
],
|
|
42
53
|
['Tasks', ['run', 'tasks list', 'tasks get', 'tasks watch', 'tasks states']],
|
|
54
|
+
[
|
|
55
|
+
'Automations (workflows and orchestrations)',
|
|
56
|
+
[
|
|
57
|
+
'automations list',
|
|
58
|
+
'automations templates',
|
|
59
|
+
'automations get',
|
|
60
|
+
'automations create',
|
|
61
|
+
'automations check',
|
|
62
|
+
'automations publish',
|
|
63
|
+
'automations run',
|
|
64
|
+
'automations runs',
|
|
65
|
+
'automations run-get',
|
|
66
|
+
],
|
|
67
|
+
],
|
|
43
68
|
[
|
|
44
69
|
'Configure the workspace (writes need workspace:configure)',
|
|
45
70
|
[
|
package/dist/job.js
CHANGED
|
@@ -36,6 +36,7 @@ import { REFERENCE_FOLDER, mergeWritten, writeReferenceFiles, } from './referenc
|
|
|
36
36
|
import { blankSecrets, heldSecretValues, blankSecretsDeep, blankingApi, registerSecretValues, releaseSecretValues, } from './secret-values.js';
|
|
37
37
|
import { claudeApiKeyNow, fallbackKey, startFallback, startKeySpent } from './api-fallback.js';
|
|
38
38
|
import { ENGINE_KEY_VARS, jobSignIn, keySourceOf } from './sign-in.js';
|
|
39
|
+
import { jobClaudeEndpoint } from './openrouter.js';
|
|
39
40
|
import { ACCOUNT_RETRY_FIRST_MS, accountBlock, accountProblemOf, cannotWorkSentence, } from './engine-account.js';
|
|
40
41
|
import { createKeyedMutex, deviceLockDir, ensureDeviceScript, ensureHeavyScript, heavyLockDir, heavySlots, heavyTag, withHeavyLock, } from './locks.js';
|
|
41
42
|
import { getAdapter, stripForeignEngineCreds } from './engines/index.js';
|
|
@@ -454,6 +455,16 @@ async function runJobBody(job, cfg, api, viewer, opts) {
|
|
|
454
455
|
if (how.note)
|
|
455
456
|
log(`${job.runId}: signs in with ${how.note}`);
|
|
456
457
|
}
|
|
458
|
+
if (job.claudeEndpoint === 'openrouter') {
|
|
459
|
+
const how = jobClaudeEndpoint(adapter.id, job.claudeEndpoint, cfg, cfg.name ?? hostname());
|
|
460
|
+
if (!how.ok) {
|
|
461
|
+
log(`${job.runId}: ${how.reason}`);
|
|
462
|
+
return await report({ status: 'failed', error: `${how.reason} ${how.fix}` });
|
|
463
|
+
}
|
|
464
|
+
cfg = how.cfg;
|
|
465
|
+
if (how.note)
|
|
466
|
+
log(`${job.runId}: Claude Code sends its requests to ${how.note}`);
|
|
467
|
+
}
|
|
457
468
|
const unattended = adapter.unattendedBlock?.({
|
|
458
469
|
...unattendedContext(cfg, job.permissionMode),
|
|
459
470
|
...opts?.unattended,
|
package/dist/mcp.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type McpRunConfig = {
|
|
|
20
20
|
servers: McpServerSpec[];
|
|
21
21
|
callBudget: number | null;
|
|
22
22
|
};
|
|
23
|
-
export type McpFormat = 'claude' | 'cursor' | 'gemini' | 'codex' | 'copilot' | 'opencode';
|
|
23
|
+
export type McpFormat = 'claude' | 'cursor' | 'gemini' | 'codex' | 'copilot' | 'opencode' | 'antigravity';
|
|
24
24
|
export type McpCredentialClient = {
|
|
25
25
|
mcpCredential(runId: string, server: string): Promise<{
|
|
26
26
|
token: string;
|
package/dist/mcp.js
CHANGED
|
@@ -16,6 +16,7 @@ const CONFIG_PATHS = {
|
|
|
16
16
|
codex: null,
|
|
17
17
|
copilot: '.firefunc-copilot-mcp.json',
|
|
18
18
|
opencode: '.firefunc-opencode.json',
|
|
19
|
+
antigravity: '.agents/plugins/firefunc-run/mcp_config.json',
|
|
19
20
|
};
|
|
20
21
|
export function mcpFormatForEngine(engine) {
|
|
21
22
|
switch (engine) {
|
|
@@ -31,6 +32,8 @@ export function mcpFormatForEngine(engine) {
|
|
|
31
32
|
return 'copilot';
|
|
32
33
|
case 'opencode':
|
|
33
34
|
return 'opencode';
|
|
35
|
+
case 'antigravity':
|
|
36
|
+
return 'antigravity';
|
|
34
37
|
default:
|
|
35
38
|
return null;
|
|
36
39
|
}
|
|
@@ -360,6 +363,17 @@ function opencodeBody(resolved) {
|
|
|
360
363
|
}
|
|
361
364
|
return `${JSON.stringify({ $schema: 'https://opencode.ai/config.json', mcp: servers }, null, 2)}\n`;
|
|
362
365
|
}
|
|
366
|
+
function antigravityBody(resolved) {
|
|
367
|
+
const servers = {};
|
|
368
|
+
for (const { spec, cred } of resolved) {
|
|
369
|
+
const headers = { ...spec.headers, ...credentialHeaders(cred) };
|
|
370
|
+
servers[spec.id] =
|
|
371
|
+
spec.transport === 'stdio'
|
|
372
|
+
? { command: spec.command, ...(spec.args ? { args: spec.args } : {}) }
|
|
373
|
+
: { serverUrl: spec.url, headers };
|
|
374
|
+
}
|
|
375
|
+
return `${JSON.stringify({ mcpServers: servers }, null, 2)}\n`;
|
|
376
|
+
}
|
|
363
377
|
function geminiBody(resolved) {
|
|
364
378
|
const servers = {};
|
|
365
379
|
for (const { spec, cred } of resolved) {
|
|
@@ -441,7 +455,7 @@ export async function prepareMcp(opts) {
|
|
|
441
455
|
`Fix: remove ${relative} from the repository, or run this project on an engine that reads a different path.`);
|
|
442
456
|
return null;
|
|
443
457
|
}
|
|
444
|
-
const excluded = await excludeFromGit(opts.worktree, [`/${relative}`], log);
|
|
458
|
+
const excluded = await excludeFromGit(opts.worktree, opts.format === 'antigravity' ? [`/${dirname(relative)}/`] : [`/${relative}`], log);
|
|
445
459
|
if (!excluded) {
|
|
446
460
|
log('mcp: MCP is off for this run because the config could not be kept out of the commit. ' +
|
|
447
461
|
'Fix: check that the runner can write .git/info/exclude in the repository checkout.');
|
|
@@ -560,8 +574,14 @@ export async function prepareMcp(opts) {
|
|
|
560
574
|
? cursorBody(resolved)
|
|
561
575
|
: opts.format === 'opencode'
|
|
562
576
|
? opencodeBody(resolved)
|
|
563
|
-
:
|
|
577
|
+
: opts.format === 'antigravity'
|
|
578
|
+
? antigravityBody(resolved)
|
|
579
|
+
: geminiBody(resolved);
|
|
564
580
|
writeFileSync(target, body, { mode: 0o600 });
|
|
581
|
+
if (opts.format === 'antigravity')
|
|
582
|
+
writeFileSync(join(dirname(target), 'plugin.json'), '{ "name": "firefunc-run" }\n', {
|
|
583
|
+
mode: 0o600,
|
|
584
|
+
});
|
|
565
585
|
}
|
|
566
586
|
catch (e) {
|
|
567
587
|
log(`mcp: could not write ${relative} (${e.message}) — MCP is off for this run.`);
|
|
@@ -584,7 +604,10 @@ export async function prepareMcp(opts) {
|
|
|
584
604
|
if (!writtenPath)
|
|
585
605
|
return;
|
|
586
606
|
try {
|
|
587
|
-
|
|
607
|
+
if (opts.format === 'antigravity')
|
|
608
|
+
rmSync(dirname(writtenPath), { recursive: true, force: true });
|
|
609
|
+
else
|
|
610
|
+
rmSync(writtenPath, { force: true });
|
|
588
611
|
}
|
|
589
612
|
catch {
|
|
590
613
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RunnerConfig } from './config.js';
|
|
2
|
+
export declare const OPENROUTER_BASE_URL = "https://openrouter.ai/api";
|
|
3
|
+
export declare const OPENROUTER_KEY_VAR = "OPENROUTER_API_KEY";
|
|
4
|
+
export declare function openRouterKeyOf(cfg: Pick<RunnerConfig, 'claudeEnv'>, env?: NodeJS.ProcessEnv): string | null;
|
|
5
|
+
export declare function openRouterClaudeEnv(runEnv: NodeJS.ProcessEnv, key: string): NodeJS.ProcessEnv;
|
|
6
|
+
export type JobEndpoint = {
|
|
7
|
+
ok: true;
|
|
8
|
+
cfg: RunnerConfig;
|
|
9
|
+
note: string | null;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
reason: string;
|
|
13
|
+
fix: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function jobClaudeEndpoint(engine: string, want: unknown, cfg: RunnerConfig, machine: string, env?: NodeJS.ProcessEnv): JobEndpoint;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const OPENROUTER_BASE_URL = 'https://openrouter.ai/api';
|
|
2
|
+
export const OPENROUTER_KEY_VAR = 'OPENROUTER_API_KEY';
|
|
3
|
+
export function openRouterKeyOf(cfg, env = process.env) {
|
|
4
|
+
const v = (cfg.claudeEnv?.[OPENROUTER_KEY_VAR] ?? env[OPENROUTER_KEY_VAR] ?? '').trim();
|
|
5
|
+
return v ? v : null;
|
|
6
|
+
}
|
|
7
|
+
export function openRouterClaudeEnv(runEnv, key) {
|
|
8
|
+
return {
|
|
9
|
+
...runEnv,
|
|
10
|
+
ANTHROPIC_BASE_URL: OPENROUTER_BASE_URL,
|
|
11
|
+
ANTHROPIC_AUTH_TOKEN: key,
|
|
12
|
+
ANTHROPIC_API_KEY: '',
|
|
13
|
+
CLAUDE_CODE_OAUTH_TOKEN: undefined,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export function jobClaudeEndpoint(engine, want, cfg, machine, env = process.env) {
|
|
17
|
+
if (want !== 'openrouter')
|
|
18
|
+
return { ok: true, cfg, note: null };
|
|
19
|
+
if (engine !== 'claude_code') {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
reason: `This job asks for the OpenRouter endpoint, a setting of Claude Code only, and it runs on ${engine}.`,
|
|
23
|
+
fix: 'Set the Claude Code endpoint back to Anthropic for this work in FireFunc, or run it on Claude Code.',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (!openRouterKeyOf(cfg, env)) {
|
|
27
|
+
return {
|
|
28
|
+
ok: false,
|
|
29
|
+
reason: `This job's Claude Code sends its requests to OpenRouter, and ${OPENROUTER_KEY_VAR} is not set on ${machine}.`,
|
|
30
|
+
fix: `Set ${OPENROUTER_KEY_VAR} on this machine (in the environment the runner starts in, or in the runner config's claudeEnv), restart the runner, and run the task again — or set the Claude Code endpoint back to Anthropic. FireFunc never stores the key.`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
ok: true,
|
|
35
|
+
cfg: { ...cfg, claudeEndpoint: 'openrouter' },
|
|
36
|
+
note: `OpenRouter (${OPENROUTER_KEY_VAR} from this machine)`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=openrouter.js.map
|
package/dist/sign-in.d.ts
CHANGED
package/dist/sign-in.js
CHANGED
|
@@ -3,6 +3,7 @@ import { homedir } from 'node:os';
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { apiKeyFile, claudeApiKeyNow } from './api-fallback.js';
|
|
5
5
|
import { spawnLoginProbe } from './engine-login.js';
|
|
6
|
+
import { openRouterKeyOf } from './openrouter.js';
|
|
6
7
|
export const ENGINE_KEY_VARS = {
|
|
7
8
|
claude_code: ['ANTHROPIC_API_KEY'],
|
|
8
9
|
codex_cli: ['OPENAI_API_KEY', 'CODEX_API_KEY'],
|
|
@@ -103,9 +104,12 @@ export function signInReport(engines, cfg, opts = {}) {
|
|
|
103
104
|
continue;
|
|
104
105
|
}
|
|
105
106
|
const source = keySourceOf(engine, cfg, opts.env, opts.dir);
|
|
107
|
+
const openrouter = engine === 'claude_code'
|
|
108
|
+
? { openrouter: openRouterKeyOf(cfg, opts.env) ? 'found' : 'missing' }
|
|
109
|
+
: {};
|
|
106
110
|
out[engine] = source
|
|
107
|
-
? { plan, key: 'found', keySource: source, ...used }
|
|
108
|
-
: { plan, key: 'missing', ...used };
|
|
111
|
+
? { plan, key: 'found', keySource: source, ...used, ...openrouter }
|
|
112
|
+
: { plan, key: 'missing', ...used, ...openrouter };
|
|
109
113
|
}
|
|
110
114
|
return out;
|
|
111
115
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firefunc-agent/runner",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.35",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "FireFunc self-hosted runner — an always-on daemon that runs YOUR local coding agent (Claude Code, Codex, Gemini CLI, Cursor CLI, Copilot CLI, Antigravity) on work FireFunc routes to it, opens pull requests, and reports back. Your machine, your subscriptions.",
|
package/skill/firefunc/SKILL.md
CHANGED
|
@@ -227,3 +227,21 @@ for an agent that reads and reports, that is the work), `verdict` (`{id, word}`,
|
|
|
227
227
|
only for an agent that declares verdicts) and `findings` (one line each, with a
|
|
228
228
|
severity). Each is null or empty when nothing was recorded; say so rather than
|
|
229
229
|
guessing. Quote the answer as it came.
|
|
230
|
+
|
|
231
|
+
## Workflows and orchestrations
|
|
232
|
+
|
|
233
|
+
An automation chains steps (a workflow) or roles (an orchestration). It is made as a DRAFT and
|
|
234
|
+
does nothing until it is published:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
firefunc automations templates --json # what to start from, and the agents each brings
|
|
238
|
+
firefunc automations create --name "Error to fix" --from-template tpl-incident-fix --project "Payments" --json
|
|
239
|
+
firefunc automations check <id> --json # the checks behind Publish, each with its fix
|
|
240
|
+
firefunc automations run <id> --mode dry --watch --json # a dry run starts nothing and writes nothing
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Publishing makes it live at once: a tool trigger takes the next real event. Ask the person first,
|
|
244
|
+
naming what starts it and its project, then `firefunc automations publish <id> --yes --json`. The
|
|
245
|
+
answer says where it went live (`goesLive`) and the agents a run would wait at (`heldAgents`: a
|
|
246
|
+
template's agents arrive paused). Start one by hand with `firefunc automations run <id> --watch`;
|
|
247
|
+
read a run with `firefunc automations run-get <run id>`.
|