@firefunc-agent/runner 0.9.34 → 0.9.36

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 CHANGED
@@ -396,6 +396,16 @@ installs the curated skills that template names, as launching it from the galler
396
396
  | `firefunc projects instructions get \| set <project> --file f.json` | `agents:read` / `workspace:configure` | A project's standing instructions (set replaces all five fields) |
397
397
  | `firefunc projects sources get \| set <project> --file f.json` | `agents:read` / `workspace:configure` | What work a project claims (set merges kind by kind) |
398
398
  | `firefunc projects repos get \| set <project> --file f.json` | `agents:read` / `workspace:configure` | A project's repositories (set adds only ones its GitHub account can see) |
399
+ | `firefunc automations list \| get <id> \| templates \| check <id>` | `agents:read` | Workflows and orchestrations, one or all, and whether one would publish |
400
+ | `firefunc automations create --name … --spec f.json` | `agents:write` | A **draft** workflow or orchestration |
401
+ | `firefunc automations publish <id>` | `workspace:configure` | Make the draft the live version |
402
+ | `firefunc automations run <id> [--inputs json] [--watch]` | `tasks:write` | Start a run of a published automation |
403
+ | `firefunc automations runs <id> \| run-get <run>` | `tasks:read` | Its runs, and one run step by step |
404
+ | `firefunc automations retry-from <run> --step <key>` | `tasks:write` | Run a failed run again from that step |
405
+ | `firefunc machines list \| labels <id>` | `agents:read` | Machines, their engines, and one machine's labels |
406
+ | `firefunc machines labels <id> --set a,b` | `workspace:configure` | Replace a machine's labels |
407
+ | `firefunc webhooks list` | `agents:read` | Inbound webhooks and their addresses |
408
+ | `firefunc webhooks create --name … --project … \| rotate <id>` | `workspace:configure` | A new inbound webhook, or a new token for one (printed once) |
399
409
  | `firefunc skill install [--dir …]` | — | Write the Claude Code skill (below) |
400
410
 
401
411
  Every command has `--help`, and each one takes:
@@ -565,6 +575,52 @@ An agent's job may ask for one way. When this machine cannot honour it (no key,
565
575
  signed in) and no fallback allows the other way, the run ends at once with the reason and the fix,
566
576
  for example "No Google key on dan-mbp. Set GEMINI_API_KEY on it, then run the engine check again."
567
577
 
578
+ ## Claude Code through OpenRouter (0.9.35)
579
+
580
+ An agent, a routing job, a task or a workflow step may send Claude Code's requests to OpenRouter
581
+ instead of Anthropic. The runner then starts Claude Code with OpenRouter's documented setup:
582
+
583
+ ```text
584
+ ANTHROPIC_BASE_URL=https://openrouter.ai/api
585
+ ANTHROPIC_AUTH_TOKEN=<this machine's OPENROUTER_API_KEY>
586
+ ANTHROPIC_API_KEY=""
587
+ ```
588
+
589
+ The key is read from this machine only: the runner config's `claudeEnv.OPENROUTER_API_KEY`, else
590
+ the environment the runner was started in. FireFunc never stores it; the runner reports only whether
591
+ it is set. A machine without it ends such a run at once: set `OPENROUTER_API_KEY` there, restart
592
+ the runner, and run the task again. The model is passed as OpenRouter names it
593
+ (`anthropic/claude-sonnet-5.5`). A runner older than 0.9.35 is never handed one of these runs.
594
+
595
+ ## FireFunc's tools during a run (0.9.36)
596
+
597
+ A run's agent reaches FireFunc mid-run (its answer, its verdict, live reads, a Slack post) through
598
+ FireFunc's own MCP server, which the runner sets up just before the engine starts. When it cannot,
599
+ the runner now tells FireFunc why, as a code (`mcp_setup`: the engine has no MCP client, the
600
+ repository already holds the config path, `.git/info/exclude` could not be written, no pass was
601
+ issued, …) — never a path or a vendor's words. The task, the workflow step and Machines then say
602
+ the cause and the fix instead of "reported no answer".
603
+
604
+ On Windows an engine is mostly an npm shim (`claude.cmd`), which starts only through `cmd.exe`.
605
+ Before 0.9.36 the runner handed cmd.exe its arguments unquoted: a path with a space in it
606
+ (`C:\Users\Jane Doe\…`) reached Claude Code as two arguments, so `--mcp-config` (FireFunc's tools),
607
+ `--add-dir` and the tool list could be cut, and Codex's `-c key="value"` overrides lost their
608
+ quotes. Every argument is now quoted for the program and escaped for cmd.exe (twice for a `.cmd`
609
+ shim, which reads its line a second time), so spaces, quotes, `&`, `|`, `<`, `>`, `^` and `%`
610
+ arrive as written. This covers the engines, `npm install -g` for updates, and the version and
611
+ model checks. `mcp login` opens the browser with `rundll32` instead of `cmd /c start`, which cut the
612
+ sign-in address at its first `&`. If an engine that takes its brief on the command line
613
+ (OpenHands) cannot have it moved into the run's `.firefunc/brief` folder, the run stops with the
614
+ fix rather than send the task's words through cmd.exe.
615
+
616
+ A machine picks up new work faster: for two minutes after it claims or finishes a run (and after
617
+ it starts) it asks FireFunc for work every second, then backs off to every 8 seconds while idle.
618
+ A formatted block in an agent's answer (`html, `markdown) is kept on the machine like code
619
+ and now says so: "[formatted text kept on the machine: read it in the run's session log there]".
620
+
621
+ To update: `npm install -g @firefunc-agent/runner@latest; firefunc-runner restart --when-idle`
622
+ (PowerShell), or with `&&` in a POSIX shell.
623
+
568
624
  ## Licence
569
625
 
570
626
  `@firefunc-agent/runner` is the **client** half of FireFunc, published so the machines
package/dist/api.d.ts CHANGED
@@ -44,6 +44,7 @@ export type ClaimedJob = {
44
44
  model?: string | null;
45
45
  planModel?: string | null;
46
46
  signIn?: 'plan' | 'key' | null;
47
+ claudeEndpoint?: 'anthropic' | 'openrouter' | null;
47
48
  effort?: string | null;
48
49
  permissionMode?: string | null;
49
50
  attachments?: {
@@ -88,7 +89,7 @@ export type ClaimedJob = {
88
89
  mcpConfig?: unknown;
89
90
  maxMinutes?: number | null;
90
91
  };
91
- export type RunnerEvent = 'cloning' | 'fixing' | 'pushing' | 'pr_opened' | 'heartbeat' | 'log' | 'checkpoint' | 'worktree';
92
+ export type RunnerEvent = 'cloning' | 'fixing' | 'pushing' | 'pr_opened' | 'heartbeat' | 'log' | 'checkpoint' | 'worktree' | 'mcp_setup';
92
93
  export type PlanLimitReport = {
93
94
  kind: 'plan';
94
95
  resetsAt: string | null;
@@ -13,3 +13,4 @@ export declare function fenceBrief(inv: Invocation, prompt: string, opts: {
13
13
  seq: number;
14
14
  log: (m: string) => void;
15
15
  }): BriefFence;
16
+ export declare function refuseExposedOnWindows(fence: BriefFence, engine: string, platform?: NodeJS.Platform): Invocation;
@@ -33,4 +33,10 @@ export function fenceBrief(inv, prompt, opts) {
33
33
  args[at] = briefPointer(file);
34
34
  return { invocation: { ...inv, args }, file, exposed: false };
35
35
  }
36
+ export function refuseExposedOnWindows(fence, engine, platform = process.platform) {
37
+ if (fence.exposed && fence.invocation.shell && platform === 'win32') {
38
+ throw new Error(`${engine} takes its brief on the command line, and the runner could not write it to the run's .firefunc/brief folder, so the run was not started: on Windows the task's words would go through cmd.exe. Fix: check that the runner's user can write the repository checkout, then re-run the task.`);
39
+ }
40
+ return fence.invocation;
41
+ }
36
42
  //# sourceMappingURL=brief-file.js.map
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.9.34",
3
- "builtAt": "2026-11-19T14:37:50.065Z"
2
+ "version": "0.9.36",
3
+ "builtAt": "2026-11-25T07:39:42.553Z"
4
4
  }
package/dist/config.d.ts CHANGED
@@ -74,6 +74,7 @@ export type RunnerConfig = {
74
74
  maxHeavyRuns?: number;
75
75
  baseBranch?: string;
76
76
  claudeEnv?: Record<string, string>;
77
+ claudeEndpoint?: 'anthropic' | 'openrouter';
77
78
  setupCommands?: string[];
78
79
  autoInstall?: boolean;
79
80
  setupTimeoutMinutes?: number;
package/dist/daemon.js CHANGED
@@ -44,6 +44,7 @@ import { clearAlive, writeAlive } from './alive.js';
44
44
  import { backoffAfterFailure, describeTransportError, isTransportFailure, rebuildGlobalDispatcher, TRANSPORT_REBUILD_AFTER, TransportWatchdog, } from './transport.js';
45
45
  import { setWorkDir, workDirProblem, workRoots } from './work-dir.js';
46
46
  import { removeRunTemp, staleRunTemps, tempRoot } from './run-temp.js';
47
+ import { shellSafe } from './win-shell.js';
47
48
  function log(msg) {
48
49
  console.log(`[firefunc-runner] ${new Date().toISOString()} ${blankSecrets(msg)}`);
49
50
  }
@@ -383,10 +384,8 @@ export async function startDaemon(cfg) {
383
384
  return was;
384
385
  },
385
386
  install: (spec) => new Promise((resolve) => {
386
- const child = spawn('npm', ['install', '-g', spec], {
387
- shell: process.platform === 'win32',
388
- windowsHide: true,
389
- });
387
+ const line = shellSafe('npm', ['install', '-g', spec], process.platform === 'win32');
388
+ const child = spawn(line.cmd, line.args, { shell: line.shell, windowsHide: true });
390
389
  let output = '';
391
390
  const keep = (b) => {
392
391
  output = (output + b.toString('utf8')).slice(-4_000);
@@ -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) {
@@ -1,18 +1,20 @@
1
1
  import { spawnSync } from 'node:child_process';
2
2
  import { claudeApiKeyNow } from './api-fallback.js';
3
+ import { shellSafe } from './win-shell.js';
3
4
  export const spawnLoginProbe = (bin, args, env) => {
4
5
  try {
5
6
  const clean = {};
6
7
  for (const [k, v] of Object.entries(env))
7
8
  if (typeof v === 'string')
8
9
  clean[k] = v;
9
- const res = spawnSync(bin, args, {
10
+ const line = shellSafe(bin, args, process.platform === 'win32', clean);
11
+ const res = spawnSync(line.cmd, line.args, {
10
12
  env: clean,
11
13
  encoding: 'utf8',
12
14
  timeout: 5_000,
13
15
  stdio: ['ignore', 'pipe', 'ignore'],
14
16
  windowsHide: true,
15
- shell: process.platform === 'win32',
17
+ shell: line.shell,
16
18
  });
17
19
  if (res.error)
18
20
  return null;
@@ -1,5 +1,6 @@
1
1
  import { execFile } from 'node:child_process';
2
2
  import { getAdapter, OPEN_PROVIDER_KEY_VARS } from './engines/index.js';
3
+ import { shellSafe } from './win-shell.js';
3
4
  const MAX_MODELS = 400;
4
5
  const MODEL_ID = /^[A-Za-z0-9~][A-Za-z0-9._:/@[\]~+-]{0,119}$/;
5
6
  const ANSI = /\u001b\[[0-9;]*m/g;
@@ -60,10 +61,11 @@ export async function readEngineModels(cfg, ids, run = runLister, env = process.
60
61
  }
61
62
  function runLister(bin, args) {
62
63
  return new Promise((resolve) => {
63
- execFile(bin, args, {
64
+ const line = shellSafe(bin, args, process.platform === 'win32');
65
+ execFile(line.cmd, line.args, {
64
66
  timeout: 30_000,
65
67
  windowsHide: true,
66
- shell: process.platform === 'win32',
68
+ shell: line.shell,
67
69
  maxBuffer: 4 * 1024 * 1024,
68
70
  }, (_err, stdout) => resolve(String(stdout ?? '')));
69
71
  });
@@ -1,2 +1,4 @@
1
+ import type { RunUsage } from '../usage.js';
1
2
  import type { AgentAdapter } from './types.js';
3
+ export declare function antigravityUsage(stdout: string): RunUsage | null;
2
4
  export declare const antigravityAdapter: AgentAdapter;
@@ -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
  },
@@ -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
@@ -14,6 +14,7 @@ import { qwenAdapter } from './qwen.js';
14
14
  import { crushAdapter } from './crush.js';
15
15
  import { openhandsAdapter } from './openhands.js';
16
16
  import { parseCliVersion } from '../fleet-words.js';
17
+ import { shellSafe } from '../win-shell.js';
17
18
  export { claudeAdapter } from './claude.js';
18
19
  export { codexAdapter } from './codex.js';
19
20
  export { geminiAdapter } from './gemini.js';
@@ -147,10 +148,11 @@ export async function readEngineVersions(cfg, ids, run = runVersion) {
147
148
  }
148
149
  function runVersion(bin) {
149
150
  return new Promise((resolve) => {
150
- execFile(bin, ['--version'], {
151
+ const line = shellSafe(bin, ['--version'], process.platform === 'win32');
152
+ execFile(line.cmd, line.args, {
151
153
  timeout: 8_000,
152
154
  windowsHide: true,
153
- shell: process.platform === 'win32',
155
+ shell: line.shell,
154
156
  maxBuffer: 64 * 1024,
155
157
  }, (_err, stdout, stderr) => resolve(`${stdout ?? ''}\n${stderr ?? ''}`.slice(0, 2_000)));
156
158
  });
package/dist/exec.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { constants } from 'node:os';
3
+ import { shellSafe } from './win-shell.js';
3
4
  export function signalExitCode(signal) {
4
5
  const n = signal ? constants.signals[signal] : undefined;
5
6
  return typeof n === 'number' ? 128 + n : 1;
@@ -52,9 +53,11 @@ export async function killProcessTree(child) {
52
53
  export function exec(cmd, args, opts = {}) {
53
54
  return new Promise((resolve, reject) => {
54
55
  const grouped = opts.ownGroup === true && process.platform !== 'win32';
55
- const child = spawn(cmd, args, {
56
+ const env = mergeEnv(opts.env);
57
+ const line = shellSafe(cmd, args, opts.shell, env);
58
+ const child = spawn(line.cmd, line.args, {
56
59
  cwd: opts.cwd,
57
- env: mergeEnv(opts.env),
60
+ env,
58
61
  stdio: [opts.input != null ? 'pipe' : 'ignore', 'pipe', 'pipe'],
59
62
  shell: opts.shell,
60
63
  detached: grouped,
@@ -0,0 +1,2 @@
1
+ import { type Command } from './command.js';
2
+ export declare const automationCommands: Command[];