@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,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
@@ -1,4 +1,6 @@
1
1
  import { mcpFromContext } from '../mcp.js';
2
+ import { readGeminiLimit } from '../limit.js';
3
+ import { ENGINE_SESSION_ID, geminiSessionId } from './sessions.js';
2
4
  function geminiSummary(stdout) {
3
5
  const trimmed = stdout.trim();
4
6
  try {
@@ -37,16 +39,12 @@ export const geminiAdapter = {
37
39
  },
38
40
  buildInvocation(ctx) {
39
41
  const { cfg } = ctx;
40
- const args = [
41
- ...(ctx.isWin ? [] : ['-p', ctx.prompt]),
42
- '--approval-mode',
43
- 'yolo',
44
- '--output-format',
45
- 'json',
46
- '--skip-trust',
47
- ];
42
+ const args = ['--approval-mode', 'yolo', '--output-format', 'json', '--skip-trust'];
48
43
  if (ctx.model)
49
44
  args.push('--model', ctx.model);
45
+ if (ctx.resumeSessionId && ENGINE_SESSION_ID.test(ctx.resumeSessionId)) {
46
+ args.push('--resume', ctx.resumeSessionId);
47
+ }
50
48
  const mcp = mcpFromContext(ctx, 'gemini');
51
49
  if (mcp?.serverIds.length) {
52
50
  args.push('--allowed-mcp-server-names', mcp.serverIds.join(','));
@@ -64,7 +62,7 @@ export const geminiAdapter = {
64
62
  bin: this.bin(cfg),
65
63
  args,
66
64
  env,
67
- stdinInput: ctx.isWin ? ctx.prompt : undefined,
65
+ stdinInput: ctx.prompt,
68
66
  shell: ctx.isWin,
69
67
  authLogLine,
70
68
  };
@@ -95,5 +93,12 @@ export const geminiAdapter = {
95
93
  }
96
94
  return null;
97
95
  },
96
+ planLimit(stdout, now) {
97
+ return readGeminiLimit(stdout, now);
98
+ },
99
+ resumesSessions: true,
100
+ sessionId(stdout) {
101
+ return geminiSessionId(stdout);
102
+ },
98
103
  };
99
104
  //# sourceMappingURL=gemini.js.map
@@ -7,8 +7,16 @@ export { geminiAdapter } from './gemini.js';
7
7
  export { cursorAdapter } from './cursor.js';
8
8
  export { antigravityAdapter } from './antigravity.js';
9
9
  export { copilotCliAdapter } from './copilot.js';
10
+ export { opencodeAdapter } from './opencode.js';
11
+ export { piAdapter } from './pi.js';
12
+ export { kiloAdapter } from './kilo.js';
13
+ export { qwenAdapter } from './qwen.js';
14
+ export { crushAdapter } from './crush.js';
15
+ export { openhandsAdapter } from './openhands.js';
10
16
  export declare function getAdapter(engine: string | null | undefined): AgentAdapter;
11
17
  export declare function supportedEngines(): EngineId[];
12
18
  export declare function binaryOnPath(bin: string): boolean;
13
19
  export declare function availableEngines(cfg: RunnerConfig): EngineId[];
20
+ export declare const OPEN_PROVIDER_KEY_VARS: readonly string[];
14
21
  export declare function stripForeignEngineCreds(env: NodeJS.ProcessEnv, engine: EngineId): NodeJS.ProcessEnv;
22
+ export declare function readEngineVersions(cfg: RunnerConfig, ids: readonly EngineId[], run?: (bin: string) => Promise<string>): Promise<Record<string, string>>;
@@ -1,3 +1,4 @@
1
+ import { execFile } from 'node:child_process';
1
2
  import { existsSync, statSync } from 'node:fs';
2
3
  import { delimiter, isAbsolute, join } from 'node:path';
3
4
  import { claudeAdapter } from './claude.js';
@@ -6,12 +7,25 @@ import { geminiAdapter } from './gemini.js';
6
7
  import { cursorAdapter } from './cursor.js';
7
8
  import { antigravityAdapter } from './antigravity.js';
8
9
  import { copilotCliAdapter } from './copilot.js';
10
+ import { opencodeAdapter } from './opencode.js';
11
+ import { piAdapter } from './pi.js';
12
+ import { kiloAdapter } from './kilo.js';
13
+ import { qwenAdapter } from './qwen.js';
14
+ import { crushAdapter } from './crush.js';
15
+ import { openhandsAdapter } from './openhands.js';
16
+ import { parseCliVersion } from '../fleet-words.js';
9
17
  export { claudeAdapter } from './claude.js';
10
18
  export { codexAdapter } from './codex.js';
11
19
  export { geminiAdapter } from './gemini.js';
12
20
  export { cursorAdapter } from './cursor.js';
13
21
  export { antigravityAdapter } from './antigravity.js';
14
22
  export { copilotCliAdapter } from './copilot.js';
23
+ export { opencodeAdapter } from './opencode.js';
24
+ export { piAdapter } from './pi.js';
25
+ export { kiloAdapter } from './kilo.js';
26
+ export { qwenAdapter } from './qwen.js';
27
+ export { crushAdapter } from './crush.js';
28
+ export { openhandsAdapter } from './openhands.js';
15
29
  const REGISTRY = {
16
30
  claude_code: claudeAdapter,
17
31
  codex_cli: codexAdapter,
@@ -19,6 +33,12 @@ const REGISTRY = {
19
33
  cursor_cli: cursorAdapter,
20
34
  antigravity: antigravityAdapter,
21
35
  copilot_cli: copilotCliAdapter,
36
+ opencode: opencodeAdapter,
37
+ pi: piAdapter,
38
+ kilo: kiloAdapter,
39
+ qwen_code: qwenAdapter,
40
+ crush: crushAdapter,
41
+ openhands: openhandsAdapter,
22
42
  };
23
43
  export function getAdapter(engine) {
24
44
  if (engine && engine in REGISTRY)
@@ -55,6 +75,27 @@ export function binaryOnPath(bin) {
55
75
  export function availableEngines(cfg) {
56
76
  return supportedEngines().filter((id) => binaryOnPath(REGISTRY[id].bin(cfg)));
57
77
  }
78
+ export const OPEN_PROVIDER_KEY_VARS = [
79
+ 'OPENROUTER_API_KEY',
80
+ 'OPENCODE_API_KEY',
81
+ 'ANTHROPIC_API_KEY',
82
+ 'ANTHROPIC_OAUTH_TOKEN',
83
+ 'OPENAI_API_KEY',
84
+ 'GEMINI_API_KEY',
85
+ 'GOOGLE_GENERATIVE_AI_API_KEY',
86
+ 'DEEPSEEK_API_KEY',
87
+ 'ZAI_API_KEY',
88
+ 'MOONSHOT_API_KEY',
89
+ 'KIMI_API_KEY',
90
+ 'GROQ_API_KEY',
91
+ 'CEREBRAS_API_KEY',
92
+ 'XAI_API_KEY',
93
+ 'MISTRAL_API_KEY',
94
+ 'MINIMAX_API_KEY',
95
+ 'FIREWORKS_API_KEY',
96
+ 'AI_GATEWAY_API_KEY',
97
+ 'AZURE_OPENAI_API_KEY',
98
+ ];
58
99
  const ENGINE_CRED_VARS = {
59
100
  claude_code: [
60
101
  'ANTHROPIC_API_KEY',
@@ -72,15 +113,46 @@ const ENGINE_CRED_VARS = {
72
113
  cursor_cli: ['CURSOR_API_KEY'],
73
114
  antigravity: [],
74
115
  copilot_cli: [],
116
+ opencode: OPEN_PROVIDER_KEY_VARS,
117
+ pi: OPEN_PROVIDER_KEY_VARS,
118
+ kilo: OPEN_PROVIDER_KEY_VARS,
119
+ qwen_code: [...OPEN_PROVIDER_KEY_VARS, 'OPENAI_BASE_URL', 'OPENAI_MODEL'],
120
+ crush: OPEN_PROVIDER_KEY_VARS,
121
+ openhands: [...OPEN_PROVIDER_KEY_VARS, 'LLM_API_KEY', 'LLM_BASE_URL', 'LLM_MODEL'],
75
122
  };
76
123
  export function stripForeignEngineCreds(env, engine) {
77
124
  const out = { ...env };
125
+ const own = new Set(ENGINE_CRED_VARS[engine] ?? []);
78
126
  for (const [id, vars] of Object.entries(ENGINE_CRED_VARS)) {
79
127
  if (id === engine)
80
128
  continue;
81
129
  for (const v of vars)
82
- out[v] = undefined;
130
+ if (!own.has(v))
131
+ out[v] = undefined;
83
132
  }
84
133
  return out;
85
134
  }
135
+ export async function readEngineVersions(cfg, ids, run = runVersion) {
136
+ const out = {};
137
+ for (const id of ids) {
138
+ const adapter = REGISTRY[id];
139
+ if (!adapter)
140
+ continue;
141
+ const text = await run(adapter.bin(cfg)).catch(() => '');
142
+ const v = parseCliVersion(text);
143
+ if (v)
144
+ out[id] = v;
145
+ }
146
+ return out;
147
+ }
148
+ function runVersion(bin) {
149
+ return new Promise((resolve) => {
150
+ execFile(bin, ['--version'], {
151
+ timeout: 8_000,
152
+ windowsHide: true,
153
+ shell: process.platform === 'win32',
154
+ maxBuffer: 64 * 1024,
155
+ }, (_err, stdout, stderr) => resolve(`${stdout ?? ''}\n${stderr ?? ''}`.slice(0, 2_000)));
156
+ });
157
+ }
86
158
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import type { AgentAdapter } from './types.js';
2
+ export declare const kiloAdapter: AgentAdapter;
@@ -0,0 +1,63 @@
1
+ import { readWordedLimit } from '../limit.js';
2
+ import { ENGINE_SESSION_ID } from './sessions.js';
3
+ import { opencodeAdapter, opencodeEnding, opencodeSessionId, opencodeSummary, opencodeUsage, opencodeVariant, } from './opencode.js';
4
+ export const kiloAdapter = {
5
+ ...opencodeAdapter,
6
+ id: 'kilo',
7
+ displayName: 'Kilo Code',
8
+ branchPrefix: 'kilo',
9
+ bin(cfg) {
10
+ return cfg.kiloBin ?? 'kilo';
11
+ },
12
+ buildInvocation(ctx) {
13
+ const { cfg } = ctx;
14
+ const args = ['run', '--format', 'json', '--auto'];
15
+ if (ctx.model)
16
+ args.push('-m', ctx.model);
17
+ const variant = opencodeVariant(ctx.effort, ctx.ultracode);
18
+ if (variant)
19
+ args.push('--variant', variant);
20
+ if (ctx.resumeSessionId && ENGINE_SESSION_ID.test(ctx.resumeSessionId)) {
21
+ args.push('-s', ctx.resumeSessionId);
22
+ }
23
+ args.push(...(cfg.kiloArgs ?? []));
24
+ const provider = ctx.model?.split('/')[0] ?? null;
25
+ return {
26
+ bin: this.bin(cfg),
27
+ args,
28
+ env: ctx.runEnv,
29
+ stdinInput: ctx.prompt,
30
+ shell: ctx.isWin,
31
+ authLogLine: provider
32
+ ? `Kilo Code with ${provider} — its key from the machine (env var or kilo auth)`
33
+ : 'Kilo Code with its own default model — keys from the machine (env vars or kilo auth)',
34
+ };
35
+ },
36
+ summarize: opencodeSummary,
37
+ authFailureHint(text) {
38
+ const t = text.toLowerCase();
39
+ if (t.includes('you need to sign in') ||
40
+ t.includes('missing authentication header') ||
41
+ t.includes('no api key') ||
42
+ t.includes('invalid api key') ||
43
+ /\b401\b/.test(t) ||
44
+ /\bunauthorized\b/.test(t)) {
45
+ return 'Kilo Code could not authenticate with the model’s provider. On the machine, set that provider’s key in the runner’s environment (OPENROUTER_API_KEY, ANTHROPIC_API_KEY, …) or run `kilo auth`, then retry; `kilo models` lists what it can use. With no key Kilo falls back to its own gateway, which needs a Kilo sign-in. FireFunc never holds the key.';
46
+ }
47
+ if (t.includes('model not found')) {
48
+ return 'Kilo Code does not know this model. Run `kilo models` on the machine for the ids it can use (provider/model), and set one on the agent or the project.';
49
+ }
50
+ return null;
51
+ },
52
+ ending: opencodeEnding,
53
+ meter: opencodeUsage,
54
+ planLimit(stdout, now, stderr) {
55
+ const ending = opencodeEnding(stdout);
56
+ if (ending && ending.error === null)
57
+ return null;
58
+ return readWordedLimit(ending?.error ?? null, stderr ?? '', now);
59
+ },
60
+ resumesSessions: true,
61
+ sessionId: opencodeSessionId,
62
+ };
63
+ //# sourceMappingURL=kilo.js.map
@@ -0,0 +1,9 @@
1
+ import type { AgentAdapter } from './types.js';
2
+ import type { EngineEnding } from '../declined.js';
3
+ import type { RunUsage } from '../usage.js';
4
+ export declare function opencodeEnding(stdout: string): EngineEnding | undefined;
5
+ export declare function opencodeSummary(stdout: string): string;
6
+ export declare function opencodeUsage(stdout: string): RunUsage | null;
7
+ export declare function opencodeSessionId(stdout: string): string | null;
8
+ export declare function opencodeVariant(effort: string | null, ultracode: boolean): string | null;
9
+ export declare const opencodeAdapter: AgentAdapter;
@@ -0,0 +1,234 @@
1
+ import { mcpFromContext } from '../mcp.js';
2
+ import { readWordedLimit } from '../limit.js';
3
+ import { ENGINE_SESSION_ID } from './sessions.js';
4
+ const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
5
+ function* events(stdout) {
6
+ for (const line of stdout.split('\n')) {
7
+ const t = line.trim();
8
+ if (!t.startsWith('{'))
9
+ continue;
10
+ try {
11
+ const ev = JSON.parse(t);
12
+ if (isObj(ev) && typeof ev.type === 'string')
13
+ yield ev;
14
+ }
15
+ catch {
16
+ }
17
+ }
18
+ }
19
+ function errorWords(ev) {
20
+ const err = isObj(ev.error) ? ev.error : {};
21
+ const data = isObj(err.data) ? err.data : {};
22
+ const msg = typeof data.message === 'string' ? data.message : '';
23
+ const name = typeof err.name === 'string' ? err.name : '';
24
+ const code = typeof data.statusCode === 'number' ? ` (${data.statusCode})` : '';
25
+ return (msg ? `${name ? `${name}: ` : ''}${msg}${code}` : name || 'OpenCode error').trim();
26
+ }
27
+ export function opencodeEnding(stdout) {
28
+ try {
29
+ let ending;
30
+ for (const ev of events(stdout)) {
31
+ if (ev.type === 'error')
32
+ ending = { error: errorWords(ev), refusal: false };
33
+ else if (ev.type === 'step_finish') {
34
+ const part = isObj(ev.part) ? ev.part : {};
35
+ if (part.reason === 'stop')
36
+ ending = { error: null, refusal: false };
37
+ }
38
+ }
39
+ return ending;
40
+ }
41
+ catch {
42
+ return undefined;
43
+ }
44
+ }
45
+ export function opencodeSummary(stdout) {
46
+ let lastText = '';
47
+ let error = '';
48
+ for (const ev of events(stdout)) {
49
+ const part = isObj(ev.part) ? ev.part : {};
50
+ if (ev.type === 'step_start')
51
+ continue;
52
+ if (ev.type === 'text' && typeof part.text === 'string' && part.text.trim()) {
53
+ lastText = part.text.trim();
54
+ error = '';
55
+ }
56
+ else if (ev.type === 'error') {
57
+ error = errorWords(ev);
58
+ }
59
+ }
60
+ if (error)
61
+ return error;
62
+ if (lastText)
63
+ return lastText;
64
+ return stdout.trim().split('\n').slice(-8).join('\n').trim().slice(0, 800);
65
+ }
66
+ const count = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : 0;
67
+ export function opencodeUsage(stdout) {
68
+ try {
69
+ let steps = 0;
70
+ let input = 0;
71
+ let output = 0;
72
+ let thinking = 0;
73
+ let cacheRead = 0;
74
+ let cacheWrite = 0;
75
+ let cost = 0;
76
+ let first = null;
77
+ let last = null;
78
+ for (const ev of events(stdout)) {
79
+ if (typeof ev.timestamp === 'number') {
80
+ first ??= ev.timestamp;
81
+ last = ev.timestamp;
82
+ }
83
+ if (ev.type !== 'step_finish')
84
+ continue;
85
+ const part = isObj(ev.part) ? ev.part : {};
86
+ const tokens = isObj(part.tokens) ? part.tokens : {};
87
+ const cache = isObj(tokens.cache) ? tokens.cache : {};
88
+ steps += 1;
89
+ input += count(tokens.input);
90
+ output += count(tokens.output);
91
+ thinking += count(tokens.reasoning);
92
+ cacheRead += count(cache.read);
93
+ cacheWrite += count(cache.write);
94
+ cost += count(part.cost);
95
+ }
96
+ if (!steps)
97
+ return null;
98
+ return {
99
+ input_tokens: input,
100
+ output_tokens: output,
101
+ ...(cacheRead ? { cache_read_input_tokens: cacheRead } : {}),
102
+ ...(cacheWrite ? { cache_creation_input_tokens: cacheWrite } : {}),
103
+ ...(thinking ? { thinking_tokens: thinking } : {}),
104
+ total_cost_usd: Math.round(cost * 1e6) / 1e6,
105
+ num_turns: steps,
106
+ ...(first !== null && last !== null && last >= first ? { duration_ms: last - first } : {}),
107
+ };
108
+ }
109
+ catch {
110
+ return null;
111
+ }
112
+ }
113
+ export function opencodeSessionId(stdout) {
114
+ try {
115
+ for (const ev of events(stdout)) {
116
+ if (typeof ev.sessionID === 'string' && ENGINE_SESSION_ID.test(ev.sessionID)) {
117
+ return ev.sessionID;
118
+ }
119
+ }
120
+ }
121
+ catch {
122
+ }
123
+ return null;
124
+ }
125
+ export function opencodeVariant(effort, ultracode) {
126
+ if (ultracode || effort === 'ultracode' || effort === 'max' || effort === 'xhigh')
127
+ return 'high';
128
+ return effort === 'low' || effort === 'medium' || effort === 'high' ? effort : null;
129
+ }
130
+ export const opencodeAdapter = {
131
+ id: 'opencode',
132
+ displayName: 'OpenCode',
133
+ branchPrefix: 'opencode',
134
+ bin(cfg) {
135
+ return cfg.opencodeBin ?? 'opencode';
136
+ },
137
+ buildInvocation(ctx) {
138
+ const { cfg } = ctx;
139
+ const args = ['run', '--format', 'json', '--auto'];
140
+ if (ctx.model)
141
+ args.push('-m', ctx.model);
142
+ const variant = opencodeVariant(ctx.effort, ctx.ultracode);
143
+ if (variant)
144
+ args.push('--variant', variant);
145
+ if (ctx.resumeSessionId && ENGINE_SESSION_ID.test(ctx.resumeSessionId)) {
146
+ args.push('--session', ctx.resumeSessionId);
147
+ }
148
+ args.push(...(cfg.opencodeArgs ?? []));
149
+ const mcp = mcpFromContext(ctx, 'opencode');
150
+ const env = mcp?.configPath
151
+ ? { ...ctx.runEnv, OPENCODE_CONFIG: mcp.configPath }
152
+ : ctx.runEnv;
153
+ const provider = ctx.model?.split('/')[0] ?? null;
154
+ return {
155
+ bin: this.bin(cfg),
156
+ args,
157
+ env,
158
+ stdinInput: ctx.prompt,
159
+ shell: ctx.isWin,
160
+ authLogLine: provider
161
+ ? `OpenCode with ${provider} — its key from the machine (env var or opencode auth login)`
162
+ : 'OpenCode with its own default model — keys from the machine (env vars or opencode auth login)',
163
+ };
164
+ },
165
+ makeStreamPrinter() {
166
+ const short = (s, n = 160) => {
167
+ const one = s.replace(/\s+/g, ' ').trim();
168
+ return one.length > n ? `${one.slice(0, n)}…` : one;
169
+ };
170
+ let buf = '';
171
+ return (chunk) => {
172
+ buf += chunk;
173
+ const lines = buf.split('\n');
174
+ buf = lines.pop() ?? '';
175
+ for (const ev of events(lines.join('\n'))) {
176
+ const part = isObj(ev.part) ? ev.part : {};
177
+ if (ev.type === 'text' && typeof part.text === 'string') {
178
+ process.stdout.write(` │ ${short(part.text)}\n`);
179
+ }
180
+ else if (ev.type === 'tool_use' && typeof part.tool === 'string') {
181
+ const state = isObj(part.state) ? part.state : {};
182
+ const title = typeof state.title === 'string' ? ` ${short(state.title, 100)}` : '';
183
+ process.stdout.write(` ⏺ ${part.tool}${title}\n`);
184
+ }
185
+ else if (ev.type === 'error') {
186
+ process.stdout.write(` ✗ ${short(errorWords(ev), 240)}\n`);
187
+ }
188
+ }
189
+ };
190
+ },
191
+ summarize(stdout) {
192
+ return opencodeSummary(stdout);
193
+ },
194
+ authFailureHint(text) {
195
+ const t = text.toLowerCase();
196
+ if (t.includes('missing authentication header') ||
197
+ t.includes('providerautherror') ||
198
+ t.includes('no api key') ||
199
+ t.includes('invalid api key') ||
200
+ t.includes('user not found') ||
201
+ /\b401\b/.test(t) ||
202
+ /\bunauthorized\b/.test(t)) {
203
+ return 'OpenCode could not authenticate with the model’s provider. On the machine, set that provider’s key in the runner’s environment (OPENROUTER_API_KEY, ANTHROPIC_API_KEY, …) or run `opencode auth login`, then retry. `opencode models` lists the models it can use. FireFunc never holds the key.';
204
+ }
205
+ if (t.includes('providermodelnotfound') || t.includes('model not found')) {
206
+ return 'OpenCode does not know this model. Run `opencode models` on the machine for the ids it can use (provider/model), and set one on the agent or the project.';
207
+ }
208
+ return null;
209
+ },
210
+ rateLimitHint(text) {
211
+ const t = text.toLowerCase();
212
+ if (/rate limit|too many requests|\b429\b|quota exceeded|insufficient credits|\b402\b/.test(t)) {
213
+ return 'OpenCode’s provider hit a rate, quota or credit limit. This run was throttled, not failed: retry shortly, top up the provider’s credit, or pick another model.';
214
+ }
215
+ return null;
216
+ },
217
+ ending(stdout) {
218
+ return opencodeEnding(stdout);
219
+ },
220
+ meter(stdout) {
221
+ return opencodeUsage(stdout);
222
+ },
223
+ planLimit(stdout, now, stderr) {
224
+ const ending = opencodeEnding(stdout);
225
+ if (ending && ending.error === null)
226
+ return null;
227
+ return readWordedLimit(ending?.error ?? null, stderr ?? '', now);
228
+ },
229
+ resumesSessions: true,
230
+ sessionId(stdout) {
231
+ return opencodeSessionId(stdout);
232
+ },
233
+ };
234
+ //# sourceMappingURL=opencode.js.map
@@ -0,0 +1,10 @@
1
+ import type { AgentAdapter, UnattendedBlock, UnattendedContext } from './types.js';
2
+ import type { EngineEnding } from '../declined.js';
3
+ export declare const OPENHANDS_LLM_VARS: readonly ["LLM_API_KEY", "LLM_BASE_URL", "LLM_MODEL"];
4
+ export declare function openhandsEnding(stdout: string): EngineEnding | undefined;
5
+ export declare function openhandsSummary(stdout: string): string;
6
+ export declare function openhandsSessionId(stdout: string): string | null;
7
+ export declare function openhandsEnv(runEnv: NodeJS.ProcessEnv, model: string | null, host?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
8
+ export declare function openhandsMissingVars(text: string): string[] | null;
9
+ export declare function openhandsUnattendedBlock(ctx: UnattendedContext, exists?: (path: string) => boolean): UnattendedBlock | null;
10
+ export declare const openhandsAdapter: AgentAdapter;