@firefunc-agent/runner 0.9.14 → 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.
Files changed (158) hide show
  1. package/README.md +184 -10
  2. package/dist/alive.d.ts +40 -0
  3. package/dist/alive.js +138 -0
  4. package/dist/api-fallback.d.ts +4 -2
  5. package/dist/api-fallback.js +26 -1
  6. package/dist/api.d.ts +66 -3
  7. package/dist/api.js +164 -3
  8. package/dist/brief-file.d.ts +15 -0
  9. package/dist/brief-file.js +36 -0
  10. package/dist/brief.d.ts +3 -0
  11. package/dist/brief.js +14 -4
  12. package/dist/build-caches.d.ts +7 -0
  13. package/dist/build-caches.js +63 -0
  14. package/dist/build-info.json +2 -2
  15. package/dist/checkpoint.d.ts +40 -0
  16. package/dist/checkpoint.js +98 -0
  17. package/dist/cli.js +184 -18
  18. package/dist/cloud-boot.d.ts +41 -0
  19. package/dist/cloud-boot.js +239 -0
  20. package/dist/command-activity.d.ts +23 -0
  21. package/dist/command-activity.js +89 -0
  22. package/dist/command-step.d.ts +58 -0
  23. package/dist/command-step.js +248 -0
  24. package/dist/config.d.ts +39 -0
  25. package/dist/config.js +23 -0
  26. package/dist/cut.d.ts +1 -1
  27. package/dist/cut.js +13 -3
  28. package/dist/daemon.js +364 -15
  29. package/dist/device-lease.d.ts +15 -0
  30. package/dist/device-lease.js +608 -0
  31. package/dist/editor/fs-server.d.ts +31 -0
  32. package/dist/editor/fs-server.js +159 -0
  33. package/dist/editor/relay-crypto.d.ts +68 -0
  34. package/dist/editor/relay-crypto.js +191 -0
  35. package/dist/editor/sessions.d.ts +50 -0
  36. package/dist/editor/sessions.js +279 -0
  37. package/dist/editor/worktree-of.d.ts +1 -0
  38. package/dist/editor/worktree-of.js +23 -0
  39. package/dist/editor/ws-client.d.ts +26 -0
  40. package/dist/editor/ws-client.js +227 -0
  41. package/dist/engine-account.d.ts +24 -0
  42. package/dist/engine-account.js +118 -0
  43. package/dist/engine-login.d.ts +12 -0
  44. package/dist/engine-login.js +88 -0
  45. package/dist/engine-models.d.ts +13 -0
  46. package/dist/engine-models.js +71 -0
  47. package/dist/engine-watch.d.ts +1 -0
  48. package/dist/engine-watch.js +22 -6
  49. package/dist/engines/antigravity.d.ts +2 -0
  50. package/dist/engines/antigravity.js +74 -4
  51. package/dist/engines/claude.js +22 -9
  52. package/dist/engines/codex.js +16 -2
  53. package/dist/engines/copilot.js +12 -0
  54. package/dist/engines/crush.d.ts +2 -0
  55. package/dist/engines/crush.js +58 -0
  56. package/dist/engines/cursor.js +12 -0
  57. package/dist/engines/gemini.js +14 -9
  58. package/dist/engines/index.d.ts +8 -0
  59. package/dist/engines/index.js +73 -1
  60. package/dist/engines/kilo.d.ts +2 -0
  61. package/dist/engines/kilo.js +63 -0
  62. package/dist/engines/opencode.d.ts +9 -0
  63. package/dist/engines/opencode.js +234 -0
  64. package/dist/engines/openhands.d.ts +10 -0
  65. package/dist/engines/openhands.js +271 -0
  66. package/dist/engines/pi.d.ts +10 -0
  67. package/dist/engines/pi.js +248 -0
  68. package/dist/engines/qwen.d.ts +8 -0
  69. package/dist/engines/qwen.js +153 -0
  70. package/dist/engines/sessions.d.ts +6 -0
  71. package/dist/engines/sessions.js +68 -0
  72. package/dist/engines/types.d.ts +3 -3
  73. package/dist/exec.d.ts +1 -0
  74. package/dist/exec.js +10 -4
  75. package/dist/firefunc/agents.d.ts +8 -1
  76. package/dist/firefunc/agents.js +53 -3
  77. package/dist/firefunc/auth.js +72 -19
  78. package/dist/firefunc/automations.d.ts +2 -0
  79. package/dist/firefunc/automations.js +290 -0
  80. package/dist/firefunc/cli.js +25 -0
  81. package/dist/firefunc/client.d.ts +5 -1
  82. package/dist/firefunc/client.js +12 -2
  83. package/dist/firefunc/config.d.ts +11 -1
  84. package/dist/firefunc/config.js +6 -4
  85. package/dist/firefunc/io.d.ts +1 -0
  86. package/dist/firefunc/main.js +34 -2
  87. package/dist/firefunc/oauth-login.d.ts +23 -0
  88. package/dist/firefunc/oauth-login.js +304 -0
  89. package/dist/firefunc/tasks.d.ts +4 -0
  90. package/dist/firefunc/tasks.js +89 -2
  91. package/dist/fleet-words.d.ts +2 -0
  92. package/dist/fleet-words.js +7 -0
  93. package/dist/git-auth.d.ts +15 -0
  94. package/dist/git-auth.js +39 -1
  95. package/dist/held.d.ts +3 -0
  96. package/dist/job.d.ts +26 -3
  97. package/dist/job.js +763 -152
  98. package/dist/keep-awake.d.ts +17 -0
  99. package/dist/keep-awake.js +90 -0
  100. package/dist/keep-local.d.ts +1 -1
  101. package/dist/keep-local.js +5 -3
  102. package/dist/limit.d.ts +9 -1
  103. package/dist/limit.js +260 -3
  104. package/dist/local-checks.d.ts +19 -0
  105. package/dist/local-checks.js +79 -0
  106. package/dist/locks.d.ts +18 -1
  107. package/dist/locks.js +249 -69
  108. package/dist/machine-commands.d.ts +21 -0
  109. package/dist/machine-commands.js +107 -0
  110. package/dist/machine-profile.d.ts +18 -0
  111. package/dist/machine-profile.js +69 -0
  112. package/dist/mcp-init.d.ts +2 -0
  113. package/dist/mcp-init.js +28 -0
  114. package/dist/mcp.d.ts +13 -1
  115. package/dist/mcp.js +48 -4
  116. package/dist/network.js +3 -2
  117. package/dist/openrouter.d.ts +15 -0
  118. package/dist/openrouter.js +39 -0
  119. package/dist/orphans.d.ts +4 -0
  120. package/dist/orphans.js +96 -4
  121. package/dist/pool.d.ts +1 -0
  122. package/dist/pool.js +25 -2
  123. package/dist/pr-title.d.ts +10 -0
  124. package/dist/pr-title.js +15 -0
  125. package/dist/recover.d.ts +3 -1
  126. package/dist/recover.js +27 -7
  127. package/dist/release-draft.d.ts +79 -0
  128. package/dist/release-draft.js +301 -0
  129. package/dist/resources.d.ts +86 -0
  130. package/dist/resources.js +217 -0
  131. package/dist/restart-idle.d.ts +23 -0
  132. package/dist/restart-idle.js +67 -0
  133. package/dist/run-attachments.d.ts +5 -0
  134. package/dist/run-attachments.js +14 -9
  135. package/dist/run-stops.d.ts +15 -0
  136. package/dist/run-stops.js +90 -0
  137. package/dist/run-temp.d.ts +12 -0
  138. package/dist/run-temp.js +57 -0
  139. package/dist/secret-scan.d.ts +5 -0
  140. package/dist/secret-scan.js +30 -0
  141. package/dist/self-upgrade.d.ts +36 -0
  142. package/dist/self-upgrade.js +78 -0
  143. package/dist/service.d.ts +7 -1
  144. package/dist/service.js +50 -7
  145. package/dist/sign-in.d.ts +42 -0
  146. package/dist/sign-in.js +243 -0
  147. package/dist/tool-call.d.ts +59 -0
  148. package/dist/tool-call.js +375 -0
  149. package/dist/transport.d.ts +26 -0
  150. package/dist/transport.js +118 -0
  151. package/dist/work-dir.d.ts +11 -0
  152. package/dist/work-dir.js +69 -0
  153. package/dist/worktree-report.d.ts +10 -0
  154. package/dist/worktree-report.js +17 -0
  155. package/dist/worktrees.d.ts +16 -1
  156. package/dist/worktrees.js +62 -17
  157. package/package.json +4 -4
  158. package/skill/firefunc/SKILL.md +22 -3
@@ -0,0 +1,118 @@
1
+ import { createHash } from 'node:crypto';
2
+ export const ACCOUNT_RETRY_FIRST_MS = 15 * 60_000;
3
+ export const ACCOUNT_RETRY_MAX_MS = 2 * 60 * 60_000;
4
+ const IN_A_ROW_MS = 24 * 60 * 60_000;
5
+ function noticeLine(text) {
6
+ const first = text.trim().split('\n', 1)[0]?.trim() ?? '';
7
+ return first && first.length <= 300 ? first : null;
8
+ }
9
+ const NO_CREDIT = /\bcredit balance is too low\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
+ export function accountProblemOf(ending, opts) {
12
+ let line;
13
+ if (ending) {
14
+ if (ending.error === null || ending.refusal)
15
+ return null;
16
+ line = noticeLine(ending.error);
17
+ }
18
+ else {
19
+ const last = (opts.stderr ?? '').trim().split('\n').at(-1) ?? '';
20
+ line = noticeLine(last);
21
+ }
22
+ if (!line)
23
+ return null;
24
+ if (NO_CREDIT.test(line))
25
+ return 'api_key_no_credit';
26
+ if (SIGNED_OUT.test(line)) {
27
+ if (opts.billedKey && /api key|x-api-key/i.test(line))
28
+ return null;
29
+ return 'not_signed_in';
30
+ }
31
+ return null;
32
+ }
33
+ export function accountBlock(code, engineName, retryInMinutes) {
34
+ const again = `The runner tries ${engineName} again in ${retryInMinutes} minutes, or as soon as it sees the change.`;
35
+ if (code === 'not_signed_in') {
36
+ return {
37
+ code,
38
+ reason: `${engineName} is not signed in on this machine for the runner's user: its last session ended on its sign-in ("Not logged in", or a login that expired or was refused), so every run it started would stop the same way.`,
39
+ fix: `Run \`claude\` on this machine as the runner's user and sign in with \`/login\` (or \`claude auth login\`). ${again}`,
40
+ detail: `${engineName} is not signed in on this machine — run \`claude\` and \`/login\` there`,
41
+ };
42
+ }
43
+ return {
44
+ code,
45
+ reason: `The Anthropic API key ${engineName} bills on this machine has no credit left ("Credit balance is too low"), so every run it started would stop the same way.`,
46
+ fix: `Top up the key's balance in the Anthropic Console, or replace the key in the runner's \`anthropic-api-key\` file. ${again}`,
47
+ detail: `the API key ${engineName} bills here has no credit left — top it up or replace it`,
48
+ };
49
+ }
50
+ export function cannotWorkSentence(engineName, block) {
51
+ return `${engineName} cannot work on this machine: ${block.reason} ${block.fix} FireFunc gives the task back to the queue; it runs once the machine can take it.`;
52
+ }
53
+ export function keyFingerprint(key) {
54
+ return key ? createHash('sha256').update(key).digest('hex').slice(0, 16) : null;
55
+ }
56
+ export function accountHolds(deps) {
57
+ const now = deps.now ?? (() => Date.now());
58
+ const holds = new Map();
59
+ const streak = new Map();
60
+ const letGo = (engine, why, real) => {
61
+ holds.delete(engine);
62
+ if (real)
63
+ streak.delete(engine);
64
+ deps.log?.(`${engine}: ${why} — claiming its work again`);
65
+ };
66
+ return {
67
+ hold(engine, code, engineName) {
68
+ const at = now();
69
+ const held = holds.get(engine);
70
+ if (held && held.code === code)
71
+ return false;
72
+ const last = streak.get(engine);
73
+ const count = last && at - last.at < IN_A_ROW_MS ? last.count + 1 : 1;
74
+ streak.set(engine, { count, at });
75
+ const waitMs = Math.min(ACCOUNT_RETRY_FIRST_MS * 2 ** (count - 1), ACCOUNT_RETRY_MAX_MS);
76
+ holds.set(engine, {
77
+ code,
78
+ retryAt: at + waitMs,
79
+ probeSawOut: false,
80
+ key: code === 'api_key_no_credit' ? (deps.billedKey?.(engine) ?? null) : null,
81
+ block: accountBlock(code, engineName, Math.round(waitMs / 60_000)),
82
+ });
83
+ return true;
84
+ },
85
+ heldBlock(engine) {
86
+ return holds.get(engine)?.block ?? null;
87
+ },
88
+ standing(installed, probed) {
89
+ const t = now();
90
+ for (const [engine, h] of [...holds]) {
91
+ if (!installed.includes(engine)) {
92
+ holds.delete(engine);
93
+ continue;
94
+ }
95
+ if (h.code === 'not_signed_in') {
96
+ if (probed.includes(engine)) {
97
+ h.probeSawOut = true;
98
+ continue;
99
+ }
100
+ if (h.probeSawOut)
101
+ letGo(engine, 'it is signed in again', true);
102
+ else if (t >= h.retryAt)
103
+ letGo(engine, 'trying its sign-in again', false);
104
+ continue;
105
+ }
106
+ const key = deps.billedKey?.(engine) ?? null;
107
+ if (key === null)
108
+ letGo(engine, 'it no longer bills the API key', true);
109
+ else if (key !== h.key)
110
+ letGo(engine, 'the API key on file changed', true);
111
+ else if (t >= h.retryAt)
112
+ letGo(engine, 'trying the API key again', false);
113
+ }
114
+ return [...holds].map(([engine, h]) => ({ ...h.block, engine }));
115
+ },
116
+ };
117
+ }
118
+ //# sourceMappingURL=engine-account.js.map
@@ -0,0 +1,12 @@
1
+ import type { RunnerConfig } from './config.js';
2
+ import type { EngineId, UnattendedBlock } from './engines/types.js';
3
+ export type LoginProbe = (bin: string, args: string[], env: NodeJS.ProcessEnv) => {
4
+ status: number | null;
5
+ stdout: string;
6
+ } | null;
7
+ export declare const spawnLoginProbe: LoginProbe;
8
+ type LoginCfg = Pick<RunnerConfig, 'claudeEnv' | 'claudeCodeOAuthToken' | 'claudeUseApiKey' | 'claudeApiKeyFallback' | 'claudeApiKeyFile'>;
9
+ export declare function claudeLoginEnv(cfg: LoginCfg, base?: NodeJS.ProcessEnv, fallbackKey?: string | null): NodeJS.ProcessEnv;
10
+ export declare function claudeLoginBlock(cfg: LoginCfg & Pick<RunnerConfig, 'claudeBin'>, probe?: LoginProbe, base?: NodeJS.ProcessEnv): UnattendedBlock | null;
11
+ export declare function engineLoginBlock(engine: EngineId, cfg: RunnerConfig, probe?: LoginProbe, base?: NodeJS.ProcessEnv): UnattendedBlock | null;
12
+ export {};
@@ -0,0 +1,88 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { claudeApiKeyNow } from './api-fallback.js';
3
+ export const spawnLoginProbe = (bin, args, env) => {
4
+ try {
5
+ const clean = {};
6
+ for (const [k, v] of Object.entries(env))
7
+ if (typeof v === 'string')
8
+ clean[k] = v;
9
+ const res = spawnSync(bin, args, {
10
+ env: clean,
11
+ encoding: 'utf8',
12
+ timeout: 5_000,
13
+ stdio: ['ignore', 'pipe', 'ignore'],
14
+ windowsHide: true,
15
+ shell: process.platform === 'win32',
16
+ });
17
+ if (res.error)
18
+ return null;
19
+ return { status: res.status, stdout: res.stdout ?? '' };
20
+ }
21
+ catch {
22
+ return null;
23
+ }
24
+ };
25
+ const TRUTHY = new Set(['1', 'true', 'yes', 'on']);
26
+ const SIGNED_ELSEWHERE = [
27
+ 'ANTHROPIC_BASE_URL',
28
+ 'ANTHROPIC_AUTH_TOKEN',
29
+ 'CLAUDECODE',
30
+ 'CLAUDE_CODE_USE_BEDROCK',
31
+ 'CLAUDE_CODE_USE_VERTEX',
32
+ 'CLAUDE_CODE_USE_FOUNDRY',
33
+ ];
34
+ export function claudeLoginEnv(cfg, base = process.env, fallbackKey = cfg.claudeApiKeyFallback ? claudeApiKeyNow(cfg).key : null) {
35
+ const env = {
36
+ ...base,
37
+ ...(cfg.claudeEnv ?? {}),
38
+ ...(cfg.claudeCodeOAuthToken ? { CLAUDE_CODE_OAUTH_TOKEN: cfg.claudeCodeOAuthToken } : {}),
39
+ };
40
+ if (!cfg.claudeUseApiKey) {
41
+ delete env.ANTHROPIC_API_KEY;
42
+ if (fallbackKey)
43
+ env.ANTHROPIC_API_KEY = fallbackKey;
44
+ }
45
+ return env;
46
+ }
47
+ export function claudeLoginBlock(cfg, probe = spawnLoginProbe, base = process.env) {
48
+ const env = claudeLoginEnv(cfg, base);
49
+ for (const name of SIGNED_ELSEWHERE) {
50
+ const v = (env[name] ?? '').trim();
51
+ if (!v)
52
+ continue;
53
+ if (name.startsWith('CLAUDE_CODE_USE_') && !TRUTHY.has(v.toLowerCase()))
54
+ continue;
55
+ return null;
56
+ }
57
+ const res = probe(cfg.claudeBin ?? 'claude', ['auth', 'status', '--json'], env);
58
+ if (!res)
59
+ return null;
60
+ let said;
61
+ try {
62
+ said = JSON.parse(res.stdout.trim());
63
+ }
64
+ catch {
65
+ return null;
66
+ }
67
+ if (!said || typeof said !== 'object')
68
+ return null;
69
+ const o = said;
70
+ if (o.loggedIn !== false || o.authMethod !== 'none')
71
+ return null;
72
+ return {
73
+ code: 'not_signed_in',
74
+ reason: 'Claude Code is not signed in for the account the runner runs as (`claude auth status` says "not logged in"), so every run it started would stop at once.',
75
+ fix: 'Sign Claude Code in as the user the runner runs as: run `claude auth login` (or `claude setup-token` and start the runner with `--claude-oauth-token`). A runner installed as a service may not see the sign-in of your desktop session. The runner checks again within two minutes.',
76
+ detail: 'Claude Code is not signed in for the runner’s user — run `claude auth login`',
77
+ };
78
+ }
79
+ export function engineLoginBlock(engine, cfg, probe = spawnLoginProbe, base = process.env) {
80
+ try {
81
+ if (engine === 'claude_code')
82
+ return claudeLoginBlock(cfg, probe, base);
83
+ }
84
+ catch {
85
+ }
86
+ return null;
87
+ }
88
+ //# sourceMappingURL=engine-login.js.map
@@ -0,0 +1,13 @@
1
+ import type { RunnerConfig } from './config.js';
2
+ import { type EngineId } from './engines/index.js';
3
+ export type EngineModelsEntry = {
4
+ models: string[];
5
+ providers: string[];
6
+ keyVars?: string[];
7
+ truncated?: boolean;
8
+ };
9
+ export declare function parseIdLines(out: string): string[];
10
+ export declare function parsePiTable(out: string): string[];
11
+ export declare function keyVarsSet(env: NodeJS.ProcessEnv): string[];
12
+ export declare function entryFrom(ids: string[], keyVars: string[]): EngineModelsEntry | null;
13
+ export declare function readEngineModels(cfg: RunnerConfig, ids: readonly EngineId[], run?: (bin: string, args: string[]) => Promise<string>, env?: NodeJS.ProcessEnv): Promise<Record<string, EngineModelsEntry>>;
@@ -0,0 +1,71 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { getAdapter, OPEN_PROVIDER_KEY_VARS } from './engines/index.js';
3
+ const MAX_MODELS = 400;
4
+ const MODEL_ID = /^[A-Za-z0-9~][A-Za-z0-9._:/@[\]~+-]{0,119}$/;
5
+ const ANSI = /\u001b\[[0-9;]*m/g;
6
+ const LISTERS = {
7
+ opencode: { args: ['models'], parse: parseIdLines },
8
+ kilo: { args: ['models'], parse: parseIdLines },
9
+ crush: { args: ['models'], parse: parseIdLines },
10
+ pi: { args: ['--list-models'], parse: parsePiTable },
11
+ };
12
+ export function parseIdLines(out) {
13
+ return out
14
+ .replace(ANSI, '')
15
+ .split('\n')
16
+ .map((l) => l.trim())
17
+ .filter((l) => l.includes('/') && MODEL_ID.test(l));
18
+ }
19
+ export function parsePiTable(out) {
20
+ const ids = [];
21
+ for (const line of out.replace(ANSI, '').split('\n')) {
22
+ const cols = line.trim().split(/\s+/);
23
+ if (cols.length < 2 || cols[0] === 'provider')
24
+ continue;
25
+ const id = `${cols[0]}/${cols[1]}`;
26
+ if (/^[a-z0-9][a-z0-9._-]*$/.test(cols[0]) && MODEL_ID.test(id))
27
+ ids.push(id);
28
+ }
29
+ return ids;
30
+ }
31
+ export function keyVarsSet(env) {
32
+ return OPEN_PROVIDER_KEY_VARS.filter((v) => typeof env[v] === 'string' && env[v].trim() !== '');
33
+ }
34
+ export function entryFrom(ids, keyVars) {
35
+ const unique = [...new Set(ids)];
36
+ const models = unique.slice(0, MAX_MODELS);
37
+ const providers = [...new Set(unique.map((m) => m.split('/')[0]).filter(Boolean))].sort();
38
+ if (!models.length && !keyVars.length)
39
+ return null;
40
+ return {
41
+ models,
42
+ providers,
43
+ ...(keyVars.length ? { keyVars } : {}),
44
+ ...(unique.length > models.length ? { truncated: true } : {}),
45
+ };
46
+ }
47
+ export async function readEngineModels(cfg, ids, run = runLister, env = process.env) {
48
+ const out = {};
49
+ const keyVars = keyVarsSet(env);
50
+ for (const id of ids) {
51
+ const lister = LISTERS[id];
52
+ if (!lister)
53
+ continue;
54
+ const text = await run(getAdapter(id).bin(cfg), lister.args).catch(() => '');
55
+ const entry = entryFrom(lister.parse(text), keyVars);
56
+ if (entry)
57
+ out[id] = entry;
58
+ }
59
+ return out;
60
+ }
61
+ function runLister(bin, args) {
62
+ return new Promise((resolve) => {
63
+ execFile(bin, args, {
64
+ timeout: 30_000,
65
+ windowsHide: true,
66
+ shell: process.platform === 'win32',
67
+ maxBuffer: 4 * 1024 * 1024,
68
+ }, (_err, stdout) => resolve(String(stdout ?? '')));
69
+ });
70
+ }
71
+ //# sourceMappingURL=engine-models.js.map
@@ -6,6 +6,7 @@ export type EngineWatch = {
6
6
  readonly blocked: EngineBlock[];
7
7
  readonly engines: EngineId[];
8
8
  blockedReport(): ReturnType<typeof blockedEnginesReport>;
9
+ add(block: EngineBlock): void;
9
10
  rescan(): void;
10
11
  };
11
12
  export declare function engineWatch(deps: {
@@ -17,6 +17,14 @@ export function engineWatch(deps) {
17
17
  return runnableEngines(installed, blocked);
18
18
  },
19
19
  blockedReport: () => blockedEnginesReport(blocked),
20
+ add(block) {
21
+ if (!installed.includes(block.engine))
22
+ return;
23
+ const same = blocked.some((b) => b.engine === block.engine && b.code === block.code);
24
+ blocked = [...blocked.filter((b) => b.engine !== block.engine), block];
25
+ if (!same)
26
+ deps.onNewlyBlocked?.([block]);
27
+ },
20
28
  rescan() {
21
29
  if (now() - lastScan < everyMs)
22
30
  return;
@@ -28,13 +36,18 @@ export function engineWatch(deps) {
28
36
  catch {
29
37
  return;
30
38
  }
31
- if (found.join(',') === installed.join(','))
32
- return;
33
39
  const added = found.filter((e) => !installed.includes(e));
34
40
  const gone = installed.filter((e) => !found.includes(e));
35
41
  installed = found;
36
- const nowBlocked = deps.blocksOf(found);
37
- const newly = nowBlocked.filter((b) => !blocked.some((x) => x.engine === b.engine));
42
+ let nowBlocked;
43
+ try {
44
+ nowBlocked = deps.blocksOf(found);
45
+ }
46
+ catch {
47
+ nowBlocked = blocked.filter((b) => found.includes(b.engine));
48
+ }
49
+ const newly = nowBlocked.filter((b) => !blocked.some((x) => x.engine === b.engine && x.code === b.code));
50
+ const cleared = blocked.filter((b) => found.includes(b.engine) && !nowBlocked.some((x) => x.engine === b.engine));
38
51
  if (newly.length)
39
52
  deps.onNewlyBlocked?.(newly);
40
53
  blocked = nowBlocked;
@@ -42,6 +55,9 @@ export function engineWatch(deps) {
42
55
  deps.log?.(`engines now available: ${added.join(', ')}`);
43
56
  if (gone.length)
44
57
  deps.log?.(`engines no longer on PATH: ${gone.join(', ')}`);
58
+ if (cleared.length) {
59
+ deps.log?.(`${cleared.map((b) => b.engine).join(', ')} can run here again — claiming its work`);
60
+ }
45
61
  },
46
62
  };
47
63
  }
@@ -53,13 +69,13 @@ export function claimPause(deps) {
53
69
  const runnable = deps.watch.engines;
54
70
  if (noEngineCanRun(runnable, deps.watch.blocked)) {
55
71
  if (!wasBlocked) {
56
- deps.log('no engine on this machine can run unattended as this user — claiming no work; the Machines page in FireFunc shows why and the fix');
72
+ deps.log('no engine on this machine can run work as this user (it runs as root, or no engine is signed in) — claiming no work; the Machines page in FireFunc shows why and the fix');
57
73
  }
58
74
  wasBlocked = true;
59
75
  return true;
60
76
  }
61
77
  if (wasBlocked)
62
- deps.log(`${runnable.join(', ')} can run unattended here — claiming work`);
78
+ deps.log(`${runnable.join(', ')} can run here — claiming work`);
63
79
  wasBlocked = false;
64
80
  const engines = runnable.length > 0 ? runnable : ['claude_code'];
65
81
  const spent = engines.map((e) => deps.isLimited(e));
@@ -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;
@@ -1,11 +1,61 @@
1
1
  import { makeStreamJsonParser } from '../session-stream.js';
2
- function clampEffort(effort) {
2
+ import { readAntigravityLimit } from '../limit.js';
3
+ import { ENGINE_SESSION_ID, antigravitySessionId } from './sessions.js';
4
+ function antigravityEffort(effort) {
3
5
  if (effort === 'none' || effort === 'minimal' || effort === 'low')
4
6
  return 'low';
5
- if (effort === 'medium')
6
- return 'medium';
7
+ if (effort === 'medium' || effort === 'high' || effort === 'xhigh' || effort === 'max') {
8
+ return effort;
9
+ }
10
+ if (effort === 'ultracode')
11
+ return 'xhigh';
7
12
  return 'high';
8
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
+ }
9
59
  function antigravitySummary(stdout) {
10
60
  const lines = stdout.trim().split('\n');
11
61
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -14,6 +64,13 @@ function antigravitySummary(stdout) {
14
64
  if (ev.type === 'result' && typeof ev.result === 'string' && ev.result.trim()) {
15
65
  return ev.result.trim();
16
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
+ }
17
74
  if (typeof ev.response === 'string' && ev.response.trim())
18
75
  return ev.response.trim();
19
76
  if (ev.type === 'assistant' && ev.message?.content) {
@@ -58,7 +115,10 @@ export const antigravityAdapter = {
58
115
  if (ctx.model)
59
116
  args.push('--model', ctx.model);
60
117
  if (ctx.effort)
61
- args.push('--effort', clampEffort(ctx.effort));
118
+ args.push('--effort', antigravityEffort(ctx.effort));
119
+ if (ctx.resumeSessionId && ENGINE_SESSION_ID.test(ctx.resumeSessionId)) {
120
+ args.push('--conversation', ctx.resumeSessionId);
121
+ }
62
122
  args.push('--print-timeout', `${cfg.jobTimeoutMinutes ?? 20}m`);
63
123
  args.push('--disable-slash-commands');
64
124
  args.push(...(cfg.antigravityArgs ?? []));
@@ -74,6 +134,9 @@ export const antigravityAdapter = {
74
134
  makeStreamPrinter() {
75
135
  return makeStreamJsonParser(() => { });
76
136
  },
137
+ meter(stdout) {
138
+ return antigravityUsage(stdout);
139
+ },
77
140
  summarize(stdout) {
78
141
  return antigravitySummary(stdout);
79
142
  },
@@ -98,5 +161,12 @@ export const antigravityAdapter = {
98
161
  }
99
162
  return null;
100
163
  },
164
+ planLimit(stdout, now, stderr) {
165
+ return readAntigravityLimit(stdout, now, stderr ?? '');
166
+ },
167
+ resumesSessions: true,
168
+ sessionId(stdout) {
169
+ return antigravitySessionId(stdout);
170
+ },
101
171
  };
102
172
  //# sourceMappingURL=antigravity.js.map
@@ -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--) {
@@ -167,7 +168,6 @@ export const claudeAdapter = {
167
168
  : [];
168
169
  const args = [
169
170
  '-p',
170
- ...(ctx.isWin ? [] : [ctx.prompt]),
171
171
  ...resume,
172
172
  '--output-format',
173
173
  'stream-json',
@@ -192,24 +192,37 @@ export const claudeAdapter = {
192
192
  args.push('--mcp-config', mcp.configPath, '--strict-mcp-config');
193
193
  }
194
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
+ }
195
206
  const billing = claudeApiKeyNow(cfg);
196
- const env = cfg.claudeUseApiKey
207
+ const env = billing.why === 'opted-in'
197
208
  ? ctx.runEnv
198
209
  : billing.key
199
210
  ? { ...ctx.runEnv, ANTHROPIC_API_KEY: billing.key }
200
211
  : { ...ctx.runEnv, ANTHROPIC_API_KEY: undefined };
201
- const authLogLine = cfg.claudeUseApiKey
212
+ const authLogLine = billing.why === 'opted-in'
202
213
  ? 'ANTHROPIC_API_KEY (API billing — opted in)'
203
- : billing.key
204
- ? 'ANTHROPIC_API_KEY (API billing — the plan is spent, until it resets)'
205
- : cfg.claudeCodeOAuthToken
206
- ? 'subscription token'
207
- : 'your machine Claude login (API key hidden — subscription billing)';
214
+ : billing.why === 'key-spent'
215
+ ? 'your machine Claude login (the API key is out of credit — on the plan for a while)'
216
+ : billing.key
217
+ ? 'ANTHROPIC_API_KEY (API billing — the plan is spent, until it resets)'
218
+ : cfg.claudeCodeOAuthToken
219
+ ? 'subscription token'
220
+ : 'your machine Claude login (API key hidden — subscription billing)';
208
221
  return {
209
222
  bin: this.bin(cfg),
210
223
  args,
211
224
  env,
212
- stdinInput: ctx.isWin ? ctx.prompt : undefined,
225
+ stdinInput: ctx.prompt,
213
226
  shell: ctx.isWin,
214
227
  authLogLine,
215
228
  };
@@ -1,4 +1,6 @@
1
1
  import { mcpFromContext } from '../mcp.js';
2
+ import { readCodexLimit } from '../limit.js';
3
+ import { ENGINE_SESSION_ID, codexSessionId } from './sessions.js';
2
4
  function codexSummary(stdout) {
3
5
  const lines = stdout.trim().split('\n');
4
6
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -30,7 +32,10 @@ export const codexAdapter = {
30
32
  },
31
33
  buildInvocation(ctx) {
32
34
  const { cfg } = ctx;
33
- const args = ['exec', ...(ctx.isWin ? ['-'] : [ctx.prompt]), '--json'];
35
+ const resume = ctx.resumeSessionId && ENGINE_SESSION_ID.test(ctx.resumeSessionId)
36
+ ? ctx.resumeSessionId
37
+ : null;
38
+ const args = resume ? ['exec', '--json'] : ['exec', '-', '--json'];
34
39
  args.push('--sandbox', 'workspace-write', '-c', 'sandbox_workspace_write.network_access=true');
35
40
  if (ctx.model)
36
41
  args.push('--model', ctx.model);
@@ -43,6 +48,8 @@ export const codexAdapter = {
43
48
  for (const override of mcp?.inlineOverrides ?? [])
44
49
  args.push('-c', override);
45
50
  args.push(...(cfg.codexArgs ?? []));
51
+ if (resume)
52
+ args.push('resume', resume, '-');
46
53
  const env = {
47
54
  ...(cfg.codexUseApiKey
48
55
  ? ctx.runEnv
@@ -56,7 +63,7 @@ export const codexAdapter = {
56
63
  bin: this.bin(cfg),
57
64
  args,
58
65
  env,
59
- stdinInput: ctx.isWin ? ctx.prompt : undefined,
66
+ stdinInput: ctx.prompt,
60
67
  shell: ctx.isWin,
61
68
  authLogLine,
62
69
  };
@@ -120,5 +127,12 @@ export const codexAdapter = {
120
127
  }
121
128
  return null;
122
129
  },
130
+ planLimit(stdout, now) {
131
+ return readCodexLimit(stdout, now);
132
+ },
133
+ resumesSessions: true,
134
+ sessionId(stdout) {
135
+ return codexSessionId(stdout);
136
+ },
123
137
  };
124
138
  //# sourceMappingURL=codex.js.map
@@ -1,4 +1,6 @@
1
1
  import { mcpFromContext } from '../mcp.js';
2
+ import { readCopilotLimit } from '../limit.js';
3
+ import { ENGINE_SESSION_ID, copilotSessionId } from './sessions.js';
2
4
  function copilotSummary(stdout) {
3
5
  const lines = stdout.trim().split('\n');
4
6
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -61,6 +63,9 @@ export const copilotCliAdapter = {
61
63
  ];
62
64
  if (ctx.model)
63
65
  args.push('--model', ctx.model);
66
+ if (ctx.resumeSessionId && ENGINE_SESSION_ID.test(ctx.resumeSessionId)) {
67
+ args.push(`--resume=${ctx.resumeSessionId}`);
68
+ }
64
69
  const effort = ctx.ultracode || ctx.effort === 'ultracode' ? 'xhigh' : ctx.effort;
65
70
  if (effort)
66
71
  args.push('--effort', effort);
@@ -114,5 +119,12 @@ export const copilotCliAdapter = {
114
119
  }
115
120
  return null;
116
121
  },
122
+ planLimit(stdout, now, stderr) {
123
+ return readCopilotLimit(stdout, now, stderr ?? '');
124
+ },
125
+ resumesSessions: true,
126
+ sessionId(stdout) {
127
+ return copilotSessionId(stdout);
128
+ },
117
129
  };
118
130
  //# sourceMappingURL=copilot.js.map
@@ -0,0 +1,2 @@
1
+ import type { AgentAdapter } from './types.js';
2
+ export declare const crushAdapter: AgentAdapter;