@firefunc-agent/runner 0.9.14 → 0.9.34

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 (153) hide show
  1. package/README.md +167 -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 +65 -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 +38 -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.js +19 -4
  50. package/dist/engines/claude.js +10 -9
  51. package/dist/engines/codex.js +16 -2
  52. package/dist/engines/copilot.js +12 -0
  53. package/dist/engines/crush.d.ts +2 -0
  54. package/dist/engines/crush.js +58 -0
  55. package/dist/engines/cursor.js +12 -0
  56. package/dist/engines/gemini.js +14 -9
  57. package/dist/engines/index.d.ts +8 -0
  58. package/dist/engines/index.js +73 -1
  59. package/dist/engines/kilo.d.ts +2 -0
  60. package/dist/engines/kilo.js +63 -0
  61. package/dist/engines/opencode.d.ts +9 -0
  62. package/dist/engines/opencode.js +234 -0
  63. package/dist/engines/openhands.d.ts +10 -0
  64. package/dist/engines/openhands.js +271 -0
  65. package/dist/engines/pi.d.ts +10 -0
  66. package/dist/engines/pi.js +248 -0
  67. package/dist/engines/qwen.d.ts +8 -0
  68. package/dist/engines/qwen.js +153 -0
  69. package/dist/engines/sessions.d.ts +6 -0
  70. package/dist/engines/sessions.js +68 -0
  71. package/dist/engines/types.d.ts +3 -3
  72. package/dist/exec.d.ts +1 -0
  73. package/dist/exec.js +10 -4
  74. package/dist/firefunc/agents.d.ts +8 -1
  75. package/dist/firefunc/agents.js +53 -3
  76. package/dist/firefunc/auth.js +72 -19
  77. package/dist/firefunc/cli.js +25 -0
  78. package/dist/firefunc/client.d.ts +5 -1
  79. package/dist/firefunc/client.js +12 -2
  80. package/dist/firefunc/config.d.ts +11 -1
  81. package/dist/firefunc/config.js +6 -4
  82. package/dist/firefunc/io.d.ts +1 -0
  83. package/dist/firefunc/main.js +8 -1
  84. package/dist/firefunc/oauth-login.d.ts +23 -0
  85. package/dist/firefunc/oauth-login.js +304 -0
  86. package/dist/firefunc/tasks.d.ts +4 -0
  87. package/dist/firefunc/tasks.js +89 -2
  88. package/dist/fleet-words.d.ts +2 -0
  89. package/dist/fleet-words.js +7 -0
  90. package/dist/git-auth.d.ts +15 -0
  91. package/dist/git-auth.js +39 -1
  92. package/dist/held.d.ts +3 -0
  93. package/dist/job.d.ts +26 -3
  94. package/dist/job.js +752 -152
  95. package/dist/keep-awake.d.ts +17 -0
  96. package/dist/keep-awake.js +90 -0
  97. package/dist/keep-local.d.ts +1 -1
  98. package/dist/keep-local.js +5 -3
  99. package/dist/limit.d.ts +9 -1
  100. package/dist/limit.js +260 -3
  101. package/dist/local-checks.d.ts +19 -0
  102. package/dist/local-checks.js +79 -0
  103. package/dist/locks.d.ts +18 -1
  104. package/dist/locks.js +249 -69
  105. package/dist/machine-commands.d.ts +21 -0
  106. package/dist/machine-commands.js +107 -0
  107. package/dist/machine-profile.d.ts +18 -0
  108. package/dist/machine-profile.js +69 -0
  109. package/dist/mcp-init.d.ts +2 -0
  110. package/dist/mcp-init.js +28 -0
  111. package/dist/mcp.d.ts +13 -1
  112. package/dist/mcp.js +23 -2
  113. package/dist/network.js +3 -2
  114. package/dist/orphans.d.ts +4 -0
  115. package/dist/orphans.js +96 -4
  116. package/dist/pool.d.ts +1 -0
  117. package/dist/pool.js +25 -2
  118. package/dist/pr-title.d.ts +10 -0
  119. package/dist/pr-title.js +15 -0
  120. package/dist/recover.d.ts +3 -1
  121. package/dist/recover.js +27 -7
  122. package/dist/release-draft.d.ts +79 -0
  123. package/dist/release-draft.js +301 -0
  124. package/dist/resources.d.ts +86 -0
  125. package/dist/resources.js +217 -0
  126. package/dist/restart-idle.d.ts +23 -0
  127. package/dist/restart-idle.js +67 -0
  128. package/dist/run-attachments.d.ts +5 -0
  129. package/dist/run-attachments.js +14 -9
  130. package/dist/run-stops.d.ts +15 -0
  131. package/dist/run-stops.js +90 -0
  132. package/dist/run-temp.d.ts +12 -0
  133. package/dist/run-temp.js +57 -0
  134. package/dist/secret-scan.d.ts +5 -0
  135. package/dist/secret-scan.js +30 -0
  136. package/dist/self-upgrade.d.ts +36 -0
  137. package/dist/self-upgrade.js +78 -0
  138. package/dist/service.d.ts +7 -1
  139. package/dist/service.js +50 -7
  140. package/dist/sign-in.d.ts +41 -0
  141. package/dist/sign-in.js +239 -0
  142. package/dist/tool-call.d.ts +59 -0
  143. package/dist/tool-call.js +375 -0
  144. package/dist/transport.d.ts +26 -0
  145. package/dist/transport.js +118 -0
  146. package/dist/work-dir.d.ts +11 -0
  147. package/dist/work-dir.js +69 -0
  148. package/dist/worktree-report.d.ts +10 -0
  149. package/dist/worktree-report.js +17 -0
  150. package/dist/worktrees.d.ts +16 -1
  151. package/dist/worktrees.js +62 -17
  152. package/package.json +4 -4
  153. package/skill/firefunc/SKILL.md +4 -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|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;
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,9 +1,14 @@
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
  }
9
14
  function antigravitySummary(stdout) {
@@ -58,7 +63,10 @@ export const antigravityAdapter = {
58
63
  if (ctx.model)
59
64
  args.push('--model', ctx.model);
60
65
  if (ctx.effort)
61
- args.push('--effort', clampEffort(ctx.effort));
66
+ args.push('--effort', antigravityEffort(ctx.effort));
67
+ if (ctx.resumeSessionId && ENGINE_SESSION_ID.test(ctx.resumeSessionId)) {
68
+ args.push('--conversation', ctx.resumeSessionId);
69
+ }
62
70
  args.push('--print-timeout', `${cfg.jobTimeoutMinutes ?? 20}m`);
63
71
  args.push('--disable-slash-commands');
64
72
  args.push(...(cfg.antigravityArgs ?? []));
@@ -98,5 +106,12 @@ export const antigravityAdapter = {
98
106
  }
99
107
  return null;
100
108
  },
109
+ planLimit(stdout, now, stderr) {
110
+ return readAntigravityLimit(stdout, now, stderr ?? '');
111
+ },
112
+ resumesSessions: true,
113
+ sessionId(stdout) {
114
+ return antigravitySessionId(stdout);
115
+ },
101
116
  };
102
117
  //# sourceMappingURL=antigravity.js.map
@@ -167,7 +167,6 @@ export const claudeAdapter = {
167
167
  : [];
168
168
  const args = [
169
169
  '-p',
170
- ...(ctx.isWin ? [] : [ctx.prompt]),
171
170
  ...resume,
172
171
  '--output-format',
173
172
  'stream-json',
@@ -193,23 +192,25 @@ export const claudeAdapter = {
193
192
  }
194
193
  args.push(...(cfg.claudeArgs ?? []));
195
194
  const billing = claudeApiKeyNow(cfg);
196
- const env = cfg.claudeUseApiKey
195
+ const env = billing.why === 'opted-in'
197
196
  ? ctx.runEnv
198
197
  : billing.key
199
198
  ? { ...ctx.runEnv, ANTHROPIC_API_KEY: billing.key }
200
199
  : { ...ctx.runEnv, ANTHROPIC_API_KEY: undefined };
201
- const authLogLine = cfg.claudeUseApiKey
200
+ const authLogLine = billing.why === 'opted-in'
202
201
  ? '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)';
202
+ : billing.why === 'key-spent'
203
+ ? 'your machine Claude login (the API key is out of credit — on the plan for a while)'
204
+ : billing.key
205
+ ? 'ANTHROPIC_API_KEY (API billing — the plan is spent, until it resets)'
206
+ : cfg.claudeCodeOAuthToken
207
+ ? 'subscription token'
208
+ : 'your machine Claude login (API key hidden — subscription billing)';
208
209
  return {
209
210
  bin: this.bin(cfg),
210
211
  args,
211
212
  env,
212
- stdinInput: ctx.isWin ? ctx.prompt : undefined,
213
+ stdinInput: ctx.prompt,
213
214
  shell: ctx.isWin,
214
215
  authLogLine,
215
216
  };
@@ -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;
@@ -0,0 +1,58 @@
1
+ import { readWordedLimit } from '../limit.js';
2
+ export const crushAdapter = {
3
+ id: 'crush',
4
+ displayName: 'Crush',
5
+ branchPrefix: 'crush',
6
+ bin(cfg) {
7
+ return cfg.crushBin ?? 'crush';
8
+ },
9
+ buildInvocation(ctx) {
10
+ const { cfg } = ctx;
11
+ const args = ['run', '-q', '-y'];
12
+ if (ctx.model)
13
+ args.push('-m', ctx.model);
14
+ const effort = ctx.ultracode || ['xhigh', 'max', 'ultracode'].includes(ctx.effort ?? '')
15
+ ? 'high'
16
+ : ctx.effort;
17
+ if (effort === 'low' || effort === 'medium' || effort === 'high') {
18
+ args.push('--reasoning-effort', effort);
19
+ }
20
+ args.push(...(cfg.crushArgs ?? []));
21
+ const provider = ctx.model?.includes('/') ? ctx.model.split('/')[0] : null;
22
+ return {
23
+ bin: this.bin(cfg),
24
+ args,
25
+ env: ctx.runEnv,
26
+ stdinInput: ctx.prompt,
27
+ shell: ctx.isWin,
28
+ authLogLine: provider
29
+ ? `Crush with ${provider} — its key from the machine (env var or crush login)`
30
+ : 'Crush with its own default model — keys from the machine (env vars or crush login)',
31
+ };
32
+ },
33
+ makeStreamPrinter: () => undefined,
34
+ summarize(stdout) {
35
+ return stdout.trim().split('\n').slice(-40).join('\n').trim().slice(0, 8000);
36
+ },
37
+ authFailureHint(text) {
38
+ const t = text.toLowerCase();
39
+ if (t.includes('no providers configured') ||
40
+ t.includes('invalid api key') ||
41
+ /\b401\b/.test(t) ||
42
+ /\bunauthorized\b/.test(t)) {
43
+ return 'Crush has no provider it can use. On the machine, set a provider’s key in the runner’s environment (OPENROUTER_API_KEY, ANTHROPIC_API_KEY, …) or run `crush login`, then retry; `crush models` lists what it can use. FireFunc never holds the key.';
44
+ }
45
+ return null;
46
+ },
47
+ rateLimitHint(text) {
48
+ const t = text.toLowerCase();
49
+ if (/rate limit|too many requests|\b429\b|quota exceeded|insufficient credits/.test(t)) {
50
+ return 'Crush’s provider hit a rate, quota or credit limit. This run was throttled, not failed: retry shortly or pick another model.';
51
+ }
52
+ return null;
53
+ },
54
+ planLimit(_stdout, now, stderr) {
55
+ return readWordedLimit(null, stderr ?? '', now);
56
+ },
57
+ };
58
+ //# sourceMappingURL=crush.js.map
@@ -1,4 +1,6 @@
1
1
  import { mcpFromContext } from '../mcp.js';
2
+ import { readCursorLimit } from '../limit.js';
3
+ import { ENGINE_SESSION_ID, cursorSessionId } from './sessions.js';
2
4
  function cursorSummary(stdout) {
3
5
  const lines = stdout.trim().split('\n');
4
6
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -44,6 +46,9 @@ export const cursorAdapter = {
44
46
  args.push('--approve-mcps');
45
47
  if (ctx.model)
46
48
  args.push('--model', ctx.model);
49
+ if (ctx.resumeSessionId && ENGINE_SESSION_ID.test(ctx.resumeSessionId)) {
50
+ args.push('--resume', ctx.resumeSessionId);
51
+ }
47
52
  args.push(...(cfg.cursorArgs ?? []));
48
53
  const env = cfg.cursorApiKey
49
54
  ? { ...ctx.runEnv, CURSOR_API_KEY: cfg.cursorApiKey }
@@ -120,5 +125,12 @@ export const cursorAdapter = {
120
125
  }
121
126
  return null;
122
127
  },
128
+ planLimit(stdout, now, stderr) {
129
+ return readCursorLimit(stdout, now, stderr ?? '');
130
+ },
131
+ resumesSessions: true,
132
+ sessionId(stdout) {
133
+ return cursorSessionId(stdout);
134
+ },
123
135
  };
124
136
  //# sourceMappingURL=cursor.js.map