@firefunc-agent/runner 0.7.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE +7 -3
  2. package/README.md +296 -4
  3. package/dist/activity.d.ts +32 -0
  4. package/dist/activity.js +295 -0
  5. package/dist/api.d.ts +69 -1
  6. package/dist/api.js +114 -3
  7. package/dist/brief.d.ts +11 -0
  8. package/dist/brief.js +278 -0
  9. package/dist/build-info.json +4 -0
  10. package/dist/cli.js +59 -2
  11. package/dist/config.d.ts +7 -0
  12. package/dist/config.js +3 -0
  13. package/dist/cut.d.ts +45 -0
  14. package/dist/cut.js +105 -0
  15. package/dist/daemon.d.ts +16 -0
  16. package/dist/daemon.js +196 -7
  17. package/dist/declined.d.ts +11 -0
  18. package/dist/declined.js +27 -0
  19. package/dist/engines/antigravity.d.ts +2 -0
  20. package/dist/engines/antigravity.js +102 -0
  21. package/dist/engines/claude-budget.d.ts +1 -1
  22. package/dist/engines/claude-budget.js +2 -72
  23. package/dist/engines/claude.js +139 -2
  24. package/dist/engines/codex.js +10 -3
  25. package/dist/engines/copilot.d.ts +2 -0
  26. package/dist/engines/copilot.js +117 -0
  27. package/dist/engines/cursor.js +4 -0
  28. package/dist/engines/gemini.js +6 -1
  29. package/dist/engines/index.d.ts +2 -0
  30. package/dist/engines/index.js +22 -4
  31. package/dist/engines/types.d.ts +12 -1
  32. package/dist/exec.d.ts +3 -0
  33. package/dist/exec.js +48 -5
  34. package/dist/firefunc/agents.d.ts +2 -0
  35. package/dist/firefunc/agents.js +343 -0
  36. package/dist/firefunc/args.d.ts +18 -0
  37. package/dist/firefunc/args.js +82 -0
  38. package/dist/firefunc/auth.d.ts +21 -0
  39. package/dist/firefunc/auth.js +129 -0
  40. package/dist/firefunc/catalog.d.ts +10 -0
  41. package/dist/firefunc/catalog.js +201 -0
  42. package/dist/firefunc/cli.d.ts +2 -0
  43. package/dist/firefunc/cli.js +24 -0
  44. package/dist/firefunc/client.d.ts +36 -0
  45. package/dist/firefunc/client.js +177 -0
  46. package/dist/firefunc/command.d.ts +28 -0
  47. package/dist/firefunc/command.js +35 -0
  48. package/dist/firefunc/config.d.ts +29 -0
  49. package/dist/firefunc/config.js +111 -0
  50. package/dist/firefunc/configure.d.ts +6 -0
  51. package/dist/firefunc/configure.js +409 -0
  52. package/dist/firefunc/io.d.ts +25 -0
  53. package/dist/firefunc/io.js +14 -0
  54. package/dist/firefunc/main.d.ts +4 -0
  55. package/dist/firefunc/main.js +259 -0
  56. package/dist/firefunc/output.d.ts +29 -0
  57. package/dist/firefunc/output.js +131 -0
  58. package/dist/firefunc/prompt.d.ts +14 -0
  59. package/dist/firefunc/prompt.js +58 -0
  60. package/dist/firefunc/skill.d.ts +3 -0
  61. package/dist/firefunc/skill.js +80 -0
  62. package/dist/firefunc/tasks.d.ts +2 -0
  63. package/dist/firefunc/tasks.js +279 -0
  64. package/dist/firefunc/version.d.ts +2 -0
  65. package/dist/firefunc/version.js +8 -0
  66. package/dist/git-auth.d.ts +4 -1
  67. package/dist/git-auth.js +6 -2
  68. package/dist/held.d.ts +18 -0
  69. package/dist/held.js +95 -0
  70. package/dist/job.d.ts +3 -0
  71. package/dist/job.js +818 -102
  72. package/dist/keep-local.d.ts +12 -0
  73. package/dist/keep-local.js +651 -0
  74. package/dist/limit.d.ts +30 -0
  75. package/dist/limit.js +258 -0
  76. package/dist/locks.d.ts +14 -0
  77. package/dist/locks.js +164 -0
  78. package/dist/machine-logins.d.ts +19 -0
  79. package/dist/machine-logins.js +187 -0
  80. package/dist/mcp-login.d.ts +24 -0
  81. package/dist/mcp-login.js +993 -0
  82. package/dist/mcp-proxy.d.ts +21 -0
  83. package/dist/mcp-proxy.js +180 -0
  84. package/dist/mcp.d.ts +62 -0
  85. package/dist/mcp.js +611 -0
  86. package/dist/network.d.ts +20 -0
  87. package/dist/network.js +76 -0
  88. package/dist/orphans.d.ts +40 -0
  89. package/dist/orphans.js +235 -0
  90. package/dist/pending.d.ts +14 -0
  91. package/dist/pending.js +56 -0
  92. package/dist/pool.d.ts +7 -0
  93. package/dist/pool.js +57 -9
  94. package/dist/pr-title.d.ts +11 -0
  95. package/dist/pr-title.js +63 -0
  96. package/dist/recover.d.ts +10 -0
  97. package/dist/recover.js +104 -0
  98. package/dist/secret-scan.d.ts +19 -0
  99. package/dist/secret-scan.js +161 -0
  100. package/dist/session-stream.d.ts +9 -1
  101. package/dist/session-stream.js +20 -2
  102. package/dist/skills.d.ts +11 -0
  103. package/dist/skills.js +164 -0
  104. package/dist/stopped.d.ts +3 -0
  105. package/dist/stopped.js +10 -0
  106. package/dist/usage.d.ts +49 -0
  107. package/dist/usage.js +389 -0
  108. package/dist/version.d.ts +1 -0
  109. package/dist/version.js +17 -0
  110. package/dist/viewer.js +7 -1
  111. package/dist/worktrees.d.ts +15 -0
  112. package/dist/worktrees.js +96 -0
  113. package/package.json +8 -5
  114. package/skill/firefunc/SKILL.md +222 -0
@@ -1,5 +1,9 @@
1
1
  import { makeStreamJsonParser } from '../session-stream.js';
2
2
  import { readClaudeBudget } from './claude-budget.js';
3
+ import { readClaudeUsage } from '../usage.js';
4
+ import { mcpFromContext } from '../mcp.js';
5
+ import { readClaudeLimit } from '../limit.js';
6
+ import { commandName } from '../keep-local.js';
3
7
  function claudeSummary(streamJson) {
4
8
  const lines = streamJson.trim().split('\n');
5
9
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -23,10 +27,111 @@ function claudeSummary(streamJson) {
23
27
  }
24
28
  return '';
25
29
  }
30
+ function claudeEnding(streamJson) {
31
+ const lines = streamJson.trim().split('\n');
32
+ for (let i = lines.length - 1; i >= 0; i--) {
33
+ let ev;
34
+ try {
35
+ ev = JSON.parse(lines[i]);
36
+ }
37
+ catch {
38
+ continue;
39
+ }
40
+ if (!ev || typeof ev !== 'object' || ev.type !== 'result')
41
+ continue;
42
+ const refusal = ev.stop_reason === 'refusal';
43
+ if (ev.is_error !== true && !refusal)
44
+ return { error: null, refusal: false };
45
+ return { error: typeof ev.result === 'string' ? ev.result : '', refusal };
46
+ }
47
+ return undefined;
48
+ }
49
+ const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9-]{7,79}$/;
50
+ function claudeSessionId(streamJson) {
51
+ let id = null;
52
+ for (const line of streamJson.split('\n')) {
53
+ const t = line.trim();
54
+ if (!t.startsWith('{') || !t.includes('"session_id"'))
55
+ continue;
56
+ if (!t.includes('"subtype":"init"') && !t.includes('"type":"result"'))
57
+ continue;
58
+ try {
59
+ const ev = JSON.parse(t);
60
+ if (typeof ev.session_id === 'string' && SESSION_ID.test(ev.session_id))
61
+ id = ev.session_id;
62
+ }
63
+ catch {
64
+ }
65
+ }
66
+ return id;
67
+ }
68
+ const TASK_ENDED = new Set(['completed', 'failed', 'killed', 'stopped', 'cancelled', 'error']);
69
+ function claudeOpenCommands(streamJson) {
70
+ const open = new Map();
71
+ const commands = new Map();
72
+ let atClose = [];
73
+ for (const line of streamJson.split('\n')) {
74
+ const t = line.trim();
75
+ if (!t.startsWith('{'))
76
+ continue;
77
+ if (t.includes('"type":"assistant"')) {
78
+ if (!t.includes('"name":"Bash"'))
79
+ continue;
80
+ try {
81
+ const ev = JSON.parse(t);
82
+ for (const c of ev.message?.content ?? []) {
83
+ if (c.type === 'tool_use' &&
84
+ c.name === 'Bash' &&
85
+ c.id &&
86
+ typeof c.input?.command === 'string') {
87
+ commands.set(c.id, c.input.command);
88
+ }
89
+ }
90
+ }
91
+ catch {
92
+ }
93
+ continue;
94
+ }
95
+ if (t.includes('"type":"result"')) {
96
+ atClose = [...open.values()];
97
+ continue;
98
+ }
99
+ if (!t.includes('"type":"system"') || !t.includes('"task_id"'))
100
+ continue;
101
+ let ev;
102
+ try {
103
+ ev = JSON.parse(t);
104
+ }
105
+ catch {
106
+ continue;
107
+ }
108
+ if (typeof ev.task_id !== 'string')
109
+ continue;
110
+ if (ev.subtype === 'task_started') {
111
+ if (ev.task_type === 'local_bash') {
112
+ open.set(ev.task_id, typeof ev.tool_use_id === 'string' ? ev.tool_use_id : null);
113
+ }
114
+ }
115
+ else if (ev.subtype === 'task_updated') {
116
+ if (typeof ev.patch?.status === 'string' && TASK_ENDED.has(ev.patch.status)) {
117
+ open.delete(ev.task_id);
118
+ }
119
+ }
120
+ else if (ev.subtype === 'task_notification') {
121
+ if (typeof ev.status === 'string' && TASK_ENDED.has(ev.status))
122
+ open.delete(ev.task_id);
123
+ }
124
+ }
125
+ return atClose.map((id) => {
126
+ const command = id ? commands.get(id) : undefined;
127
+ return command ? commandName(command) : 'a command';
128
+ });
129
+ }
26
130
  export const claudeAdapter = {
27
131
  id: 'claude_code',
28
132
  displayName: 'Claude Code',
29
133
  branchPrefix: 'claude',
134
+ resumesSessions: true,
30
135
  bin(cfg) {
31
136
  return cfg.claudeBin ?? 'claude';
32
137
  },
@@ -34,11 +139,17 @@ export const claudeAdapter = {
34
139
  const { cfg } = ctx;
35
140
  const model = ctx.model ?? 'opus';
36
141
  const effortFlag = ctx.ultracode ? 'xhigh' : ctx.effort;
37
- const tools = ctx.allowedTools ??
142
+ const baseTools = ctx.allowedTools ??
38
143
  'Read Edit Write Bash Glob Grep WebFetch WebSearch Task TodoWrite NotebookEdit';
144
+ const mcp = mcpFromContext(ctx, 'claude');
145
+ const tools = mcp?.toolNames.length ? `${baseTools} ${mcp.toolNames.join(' ')}` : baseTools;
146
+ const resume = ctx.resumeSessionId && SESSION_ID.test(ctx.resumeSessionId)
147
+ ? ['--resume', ctx.resumeSessionId]
148
+ : [];
39
149
  const args = [
40
150
  '-p',
41
151
  ...(ctx.isWin ? [] : [ctx.prompt]),
152
+ ...resume,
42
153
  '--output-format',
43
154
  'stream-json',
44
155
  '--verbose',
@@ -47,6 +158,9 @@ export const claudeAdapter = {
47
158
  '--allowedTools',
48
159
  tools,
49
160
  ];
161
+ if (mcp?.deniedToolNames.length) {
162
+ args.push('--disallowedTools', mcp.deniedToolNames.join(' '));
163
+ }
50
164
  if (model)
51
165
  args.push('--model', model);
52
166
  if (effortFlag)
@@ -55,6 +169,9 @@ export const claudeAdapter = {
55
169
  args.push('--add-dir', ctx.attachDir);
56
170
  if (ctx.maxBudgetUsd)
57
171
  args.push('--max-budget-usd', String(ctx.maxBudgetUsd));
172
+ if (mcp?.configPath) {
173
+ args.push('--mcp-config', mcp.configPath, '--strict-mcp-config');
174
+ }
58
175
  args.push(...(cfg.claudeArgs ?? []));
59
176
  const env = cfg.claudeUseApiKey
60
177
  ? ctx.runEnv
@@ -83,13 +200,16 @@ export const claudeAdapter = {
83
200
  process.stdout.write(` │ ${short(ev.text)}\n`);
84
201
  else if (ev.kind === 'tool')
85
202
  process.stdout.write(` │ ⚒ ${ev.name}${ev.arg ? ` ${short(ev.arg, 90)}` : ''}\n`);
86
- else
203
+ else if (ev.kind === 'result')
87
204
  process.stdout.write(` └ ${short(ev.text, 240)}\n`);
88
205
  });
89
206
  },
90
207
  summarize(stdout) {
91
208
  return claudeSummary(stdout);
92
209
  },
210
+ ending(stdout) {
211
+ return claudeEnding(stdout);
212
+ },
93
213
  authFailureHint(text) {
94
214
  const t = text.toLowerCase();
95
215
  if (t.includes('credit balance is too low')) {
@@ -117,5 +237,22 @@ export const claudeAdapter = {
117
237
  readBudget(cfg) {
118
238
  return readClaudeBudget(cfg);
119
239
  },
240
+ meter(stdout) {
241
+ return readClaudeUsage(stdout);
242
+ },
243
+ planLimit(stdout, now) {
244
+ return readClaudeLimit(stdout, now);
245
+ },
246
+ sessionId(stdout) {
247
+ return claudeSessionId(stdout);
248
+ },
249
+ openCommandsAtEnd(stdout) {
250
+ try {
251
+ return claudeOpenCommands(stdout);
252
+ }
253
+ catch {
254
+ return [];
255
+ }
256
+ },
120
257
  };
121
258
  //# sourceMappingURL=claude.js.map
@@ -1,3 +1,4 @@
1
+ import { mcpFromContext } from '../mcp.js';
1
2
  function codexSummary(stdout) {
2
3
  const lines = stdout.trim().split('\n');
3
4
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -38,10 +39,16 @@ export const codexAdapter = {
38
39
  if (effort && ['minimal', 'low', 'medium', 'high', 'xhigh'].includes(effort)) {
39
40
  args.push('-c', `model_reasoning_effort="${effort}"`);
40
41
  }
42
+ const mcp = mcpFromContext(ctx, 'codex');
43
+ for (const override of mcp?.inlineOverrides ?? [])
44
+ args.push('-c', override);
41
45
  args.push(...(cfg.codexArgs ?? []));
42
- const env = cfg.codexUseApiKey
43
- ? ctx.runEnv
44
- : { ...ctx.runEnv, OPENAI_API_KEY: undefined, CODEX_API_KEY: undefined };
46
+ const env = {
47
+ ...(cfg.codexUseApiKey
48
+ ? ctx.runEnv
49
+ : { ...ctx.runEnv, OPENAI_API_KEY: undefined, CODEX_API_KEY: undefined }),
50
+ ...mcp?.env,
51
+ };
45
52
  const authLogLine = cfg.codexUseApiKey
46
53
  ? 'OPENAI_API_KEY / CODEX_API_KEY (API billing — opted in)'
47
54
  : 'your machine `codex login` (API keys hidden — ChatGPT-plan billing)';
@@ -0,0 +1,2 @@
1
+ import type { AgentAdapter } from './types.js';
2
+ export declare const copilotCliAdapter: AgentAdapter;
@@ -0,0 +1,117 @@
1
+ import { mcpFromContext } from '../mcp.js';
2
+ function copilotSummary(stdout) {
3
+ const lines = stdout.trim().split('\n');
4
+ for (let i = lines.length - 1; i >= 0; i--) {
5
+ try {
6
+ const ev = JSON.parse(lines[i]);
7
+ if (typeof ev.result === 'string' && ev.result.trim())
8
+ return ev.result.trim();
9
+ const content = ev.message?.content ?? ev.content;
10
+ if (typeof content === 'string' && content.trim())
11
+ return content.trim();
12
+ if (Array.isArray(content)) {
13
+ const text = content
14
+ .filter((c) => c.text)
15
+ .map((c) => c.text)
16
+ .join('')
17
+ .trim();
18
+ if (text)
19
+ return text;
20
+ }
21
+ if (typeof ev.text === 'string' && ev.text.trim() && ev.role !== 'user') {
22
+ return ev.text.trim();
23
+ }
24
+ }
25
+ catch {
26
+ }
27
+ }
28
+ return '';
29
+ }
30
+ const REDACT_VARS = [
31
+ 'GIT_ASKPASS_PASSWORD',
32
+ 'GITHUB_TOKEN',
33
+ 'GH_TOKEN',
34
+ 'ANTHROPIC_API_KEY',
35
+ 'OPENAI_API_KEY',
36
+ 'GEMINI_API_KEY',
37
+ 'CURSOR_API_KEY',
38
+ ];
39
+ export const copilotCliAdapter = {
40
+ id: 'copilot_cli',
41
+ displayName: 'GitHub Copilot CLI',
42
+ branchPrefix: 'copilot',
43
+ bin(cfg) {
44
+ return cfg.copilotBin ?? 'copilot';
45
+ },
46
+ buildInvocation(ctx) {
47
+ const { cfg } = ctx;
48
+ const args = [
49
+ ...(ctx.isWin ? [] : ['-p', ctx.prompt]),
50
+ '--allow-all-tools',
51
+ '--output-format',
52
+ 'json',
53
+ '--no-ask-user',
54
+ '--no-remote',
55
+ '--no-remote-export',
56
+ '--no-auto-update',
57
+ '--log-level',
58
+ 'none',
59
+ '--secret-env-vars',
60
+ REDACT_VARS.join(','),
61
+ ];
62
+ if (ctx.model)
63
+ args.push('--model', ctx.model);
64
+ if (ctx.effort)
65
+ args.push('--effort', ctx.effort);
66
+ if (ctx.maxBudgetUsd)
67
+ args.push('--max-ai-credits', String(ctx.maxBudgetUsd));
68
+ if (ctx.attachDir && ctx.attachPaths.length)
69
+ args.push('--add-dir', ctx.attachDir);
70
+ const mcp = mcpFromContext(ctx, 'copilot');
71
+ if (mcp?.configPath)
72
+ args.push('--additional-mcp-config', `@${mcp.configPath}`);
73
+ if (!mcp?.serverIds.length)
74
+ args.push('--disable-builtin-mcps');
75
+ if (mcp?.deniedToolNames.length) {
76
+ args.push('--deny-tool', ...mcp.deniedToolNames);
77
+ }
78
+ if (ctx.allowedTools)
79
+ args.push('--available-tools', ctx.allowedTools);
80
+ args.push(...(cfg.copilotArgs ?? []));
81
+ return {
82
+ bin: this.bin(cfg),
83
+ args,
84
+ env: ctx.runEnv,
85
+ stdinInput: ctx.isWin ? ctx.prompt : undefined,
86
+ shell: ctx.isWin,
87
+ authLogLine: 'your machine’s `copilot login` (GitHub Copilot plan — Free tier included)',
88
+ };
89
+ },
90
+ makeStreamPrinter() {
91
+ return undefined;
92
+ },
93
+ summarize(stdout) {
94
+ return copilotSummary(stdout);
95
+ },
96
+ authFailureHint(text) {
97
+ const t = text.toLowerCase();
98
+ if (t.includes('not signed in') ||
99
+ t.includes('please log in') ||
100
+ t.includes('/login') ||
101
+ t.includes('authentication required') ||
102
+ t.includes('no copilot subscription') ||
103
+ t.includes('copilot access') ||
104
+ /\b401\b/.test(t)) {
105
+ return 'GitHub Copilot CLI is not signed in on this machine, or the account has no Copilot access. Run `copilot` there once and use `/login`, then retry. Copilot CLI is included in every Copilot plan including Free — but an organization can disable it by policy, so if sign-in succeeds and runs still fail, check with whoever administers your GitHub org.';
106
+ }
107
+ return null;
108
+ },
109
+ rateLimitHint(text) {
110
+ const t = text.toLowerCase();
111
+ if (/rate limit|too many requests|\b429\b|quota exceeded|credit limit|ai credits? (exhausted|limit)/.test(t)) {
112
+ return 'GitHub Copilot hit a usage limit on your plan — its AI-credit ceiling is a soft cap and the Free tier reaches it quickly under unattended runs. This run was throttled, not failed: retry shortly, lower "max parallel", or move this agent to a paid Copilot plan.';
113
+ }
114
+ return null;
115
+ },
116
+ };
117
+ //# sourceMappingURL=copilot.js.map
@@ -1,3 +1,4 @@
1
+ import { mcpFromContext } from '../mcp.js';
1
2
  function cursorSummary(stdout) {
2
3
  const lines = stdout.trim().split('\n');
3
4
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -38,6 +39,9 @@ export const cursorAdapter = {
38
39
  throw new Error('The Cursor CLI engine is not supported on native Windows runners (Cursor supports Windows via WSL only). Run the firefunc-runner inside WSL, or pick another engine for this project.');
39
40
  }
40
41
  const args = ['-p', ctx.prompt, '--force', '--output-format', 'stream-json', '--trust'];
42
+ const mcp = mcpFromContext(ctx, 'cursor');
43
+ if (mcp?.configPath)
44
+ args.push('--approve-mcps');
41
45
  if (ctx.model)
42
46
  args.push('--model', ctx.model);
43
47
  args.push(...(cfg.cursorArgs ?? []));
@@ -1,3 +1,4 @@
1
+ import { mcpFromContext } from '../mcp.js';
1
2
  function geminiSummary(stdout) {
2
3
  const trimmed = stdout.trim();
3
4
  try {
@@ -25,7 +26,7 @@ function geminiSummary(stdout) {
25
26
  catch {
26
27
  }
27
28
  }
28
- return trimmed.split('\n').slice(-8).join(' ').replace(/\s+/g, ' ').trim().slice(0, 800);
29
+ return trimmed.split('\n').slice(-8).join('\n').trim().slice(0, 800);
29
30
  }
30
31
  export const geminiAdapter = {
31
32
  id: 'gemini_cli',
@@ -46,6 +47,10 @@ export const geminiAdapter = {
46
47
  ];
47
48
  if (ctx.model)
48
49
  args.push('--model', ctx.model);
50
+ const mcp = mcpFromContext(ctx, 'gemini');
51
+ if (mcp?.serverIds.length) {
52
+ args.push('--allowed-mcp-server-names', mcp.serverIds.join(','));
53
+ }
49
54
  args.push(...(cfg.geminiArgs ?? []));
50
55
  const env = cfg.geminiApiKey
51
56
  ? { ...ctx.runEnv, GEMINI_API_KEY: cfg.geminiApiKey }
@@ -5,6 +5,8 @@ export { claudeAdapter } from './claude.js';
5
5
  export { codexAdapter } from './codex.js';
6
6
  export { geminiAdapter } from './gemini.js';
7
7
  export { cursorAdapter } from './cursor.js';
8
+ export { antigravityAdapter } from './antigravity.js';
9
+ export { copilotCliAdapter } from './copilot.js';
8
10
  export declare function getAdapter(engine: string | null | undefined): AgentAdapter;
9
11
  export declare function supportedEngines(): EngineId[];
10
12
  export declare function binaryOnPath(bin: string): boolean;
@@ -4,15 +4,21 @@ import { claudeAdapter } from './claude.js';
4
4
  import { codexAdapter } from './codex.js';
5
5
  import { geminiAdapter } from './gemini.js';
6
6
  import { cursorAdapter } from './cursor.js';
7
+ import { antigravityAdapter } from './antigravity.js';
8
+ import { copilotCliAdapter } from './copilot.js';
7
9
  export { claudeAdapter } from './claude.js';
8
10
  export { codexAdapter } from './codex.js';
9
11
  export { geminiAdapter } from './gemini.js';
10
12
  export { cursorAdapter } from './cursor.js';
13
+ export { antigravityAdapter } from './antigravity.js';
14
+ export { copilotCliAdapter } from './copilot.js';
11
15
  const REGISTRY = {
12
16
  claude_code: claudeAdapter,
13
17
  codex_cli: codexAdapter,
14
18
  gemini_cli: geminiAdapter,
15
19
  cursor_cli: cursorAdapter,
20
+ antigravity: antigravityAdapter,
21
+ copilot_cli: copilotCliAdapter,
16
22
  };
17
23
  export function getAdapter(engine) {
18
24
  if (engine && engine in REGISTRY)
@@ -50,10 +56,22 @@ export function availableEngines(cfg) {
50
56
  return supportedEngines().filter((id) => binaryOnPath(REGISTRY[id].bin(cfg)));
51
57
  }
52
58
  const ENGINE_CRED_VARS = {
53
- claude_code: ['ANTHROPIC_API_KEY', 'CLAUDE_CODE_OAUTH_TOKEN'],
54
- codex_cli: ['OPENAI_API_KEY', 'CODEX_API_KEY'],
55
- gemini_cli: ['GEMINI_API_KEY', 'GOOGLE_API_KEY'],
59
+ claude_code: [
60
+ 'ANTHROPIC_API_KEY',
61
+ 'CLAUDE_CODE_OAUTH_TOKEN',
62
+ 'ANTHROPIC_AUTH_TOKEN',
63
+ 'ANTHROPIC_BASE_URL',
64
+ ],
65
+ codex_cli: ['OPENAI_API_KEY', 'CODEX_API_KEY', 'OPENAI_BASE_URL'],
66
+ gemini_cli: [
67
+ 'GEMINI_API_KEY',
68
+ 'GOOGLE_API_KEY',
69
+ 'GOOGLE_APPLICATION_CREDENTIALS',
70
+ 'GOOGLE_GENAI_USE_GCA',
71
+ ],
56
72
  cursor_cli: ['CURSOR_API_KEY'],
73
+ antigravity: [],
74
+ copilot_cli: [],
57
75
  };
58
76
  export function stripForeignEngineCreds(env, engine) {
59
77
  const out = { ...env };
@@ -61,7 +79,7 @@ export function stripForeignEngineCreds(env, engine) {
61
79
  if (id === engine)
62
80
  continue;
63
81
  for (const v of vars)
64
- delete out[v];
82
+ out[v] = undefined;
65
83
  }
66
84
  return out;
67
85
  }
@@ -1,5 +1,8 @@
1
1
  import type { RunnerConfig } from '../config.js';
2
- export type EngineId = 'claude_code' | 'codex_cli' | 'gemini_cli' | 'cursor_cli';
2
+ import type { RunUsage } from '../usage.js';
3
+ import type { EngineEnding } from '../declined.js';
4
+ import type { PlanLimit } from '../limit.js';
5
+ export type EngineId = 'claude_code' | 'codex_cli' | 'gemini_cli' | 'cursor_cli' | 'antigravity' | 'copilot_cli';
3
6
  export type InvocationContext = {
4
7
  prompt: string;
5
8
  model: string | null;
@@ -7,12 +10,14 @@ export type InvocationContext = {
7
10
  ultracode: boolean;
8
11
  permissionMode: string;
9
12
  allowedTools?: string;
13
+ deniedToolNames?: string[];
10
14
  maxBudgetUsd?: number;
11
15
  attachDir?: string;
12
16
  attachPaths: string[];
13
17
  isWin: boolean;
14
18
  runEnv: NodeJS.ProcessEnv;
15
19
  cfg: RunnerConfig;
20
+ resumeSessionId?: string;
16
21
  };
17
22
  export type Invocation = {
18
23
  bin: string;
@@ -43,5 +48,11 @@ export interface AgentAdapter {
43
48
  summarize(stdout: string): string;
44
49
  authFailureHint(text: string): string | null;
45
50
  rateLimitHint(text: string): string | null;
51
+ ending?(stdout: string): EngineEnding | undefined;
52
+ meter?(stdout: string): RunUsage | null;
53
+ planLimit?(stdout: string, now: Date): PlanLimit | null;
54
+ sessionId?(stdout: string): string | null;
55
+ openCommandsAtEnd?(stdout: string): string[];
56
+ readonly resumesSessions?: boolean;
46
57
  readBudget?(cfg: RunnerConfig): Promise<EngineBudgetReport | null>;
47
58
  }
package/dist/exec.d.ts CHANGED
@@ -4,6 +4,7 @@ export type ExecResult = {
4
4
  stdout: string;
5
5
  stderr: string;
6
6
  };
7
+ export declare function signalExitCode(signal: NodeJS.Signals | null): number;
7
8
  export declare function spawnBackground(cmd: string, opts?: {
8
9
  cwd?: string;
9
10
  env?: NodeJS.ProcessEnv;
@@ -16,5 +17,7 @@ export declare function exec(cmd: string, args: string[], opts?: {
16
17
  input?: string;
17
18
  shell?: boolean;
18
19
  onStdout?: (chunk: string) => void;
20
+ ownGroup?: boolean;
21
+ onSpawn?: (pid: number) => void;
19
22
  }): Promise<ExecResult>;
20
23
  export declare function execOut(cmd: string, args: string[], cwd?: string): Promise<string>;
package/dist/exec.js CHANGED
@@ -1,4 +1,9 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { constants } from 'node:os';
3
+ export function signalExitCode(signal) {
4
+ const n = signal ? constants.signals[signal] : undefined;
5
+ return typeof n === 'number' ? 128 + n : 1;
6
+ }
2
7
  function mergeEnv(extra) {
3
8
  const env = { ...process.env, ...extra };
4
9
  for (const k of Object.keys(env))
@@ -46,12 +51,40 @@ export async function killProcessTree(child) {
46
51
  }
47
52
  export function exec(cmd, args, opts = {}) {
48
53
  return new Promise((resolve, reject) => {
54
+ const grouped = opts.ownGroup === true && process.platform !== 'win32';
49
55
  const child = spawn(cmd, args, {
50
56
  cwd: opts.cwd,
51
57
  env: mergeEnv(opts.env),
52
58
  stdio: [opts.input != null ? 'pipe' : 'ignore', 'pipe', 'pipe'],
53
59
  shell: opts.shell,
60
+ detached: grouped,
61
+ });
62
+ if (child.pid)
63
+ opts.onSpawn?.(child.pid);
64
+ let exited = false;
65
+ let settled = false;
66
+ let exitTimer = null;
67
+ child.on('exit', (code, signal) => {
68
+ exited = true;
69
+ exitTimer = setTimeout(() => {
70
+ child.stdout?.destroy();
71
+ child.stderr?.destroy();
72
+ finish(code, signal);
73
+ }, EXIT_GRACE_MS);
54
74
  });
75
+ const stop = (sig) => {
76
+ if (exited)
77
+ return;
78
+ if (grouped && child.pid) {
79
+ try {
80
+ process.kill(-child.pid, sig);
81
+ return;
82
+ }
83
+ catch {
84
+ }
85
+ }
86
+ child.kill(sig);
87
+ };
55
88
  if (opts.input != null) {
56
89
  child.stdin?.on('error', () => { });
57
90
  child.stdin?.write(opts.input);
@@ -64,8 +97,8 @@ export function exec(cmd, args, opts = {}) {
64
97
  if (opts.timeoutMs) {
65
98
  timer = setTimeout(() => {
66
99
  timedOut = true;
67
- child.kill('SIGTERM');
68
- setTimeout(() => child.kill('SIGKILL'), 5_000);
100
+ stop('SIGTERM');
101
+ setTimeout(() => stop('SIGKILL'), 5_000);
69
102
  }, opts.timeoutMs);
70
103
  }
71
104
  child.stdout?.on('data', (d) => {
@@ -77,19 +110,29 @@ export function exec(cmd, args, opts = {}) {
77
110
  child.on('error', (err) => {
78
111
  if (timer)
79
112
  clearTimeout(timer);
113
+ if (settled)
114
+ return;
115
+ settled = true;
80
116
  reject(err);
81
117
  });
82
- child.on('close', (code) => {
118
+ const finish = (code, signal) => {
119
+ if (settled)
120
+ return;
121
+ settled = true;
83
122
  if (timer)
84
123
  clearTimeout(timer);
124
+ if (exitTimer)
125
+ clearTimeout(exitTimer);
85
126
  resolve({
86
- code: timedOut ? 124 : (code ?? 1),
127
+ code: timedOut ? 124 : (code ?? signalExitCode(signal)),
87
128
  stdout,
88
129
  stderr: timedOut ? `${stderr}\n[firefunc-runner] timed out` : stderr,
89
130
  });
90
- });
131
+ };
132
+ child.on('close', finish);
91
133
  });
92
134
  }
135
+ const EXIT_GRACE_MS = 3_000;
93
136
  export async function execOut(cmd, args, cwd) {
94
137
  const r = await exec(cmd, args, { cwd });
95
138
  return r.code === 0 ? r.stdout.trim() : '';
@@ -0,0 +1,2 @@
1
+ import { type Command } from './command.js';
2
+ export declare const agentCommands: Command[];