@causyne/agent 1.14.0 → 1.18.0

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.
@@ -11,8 +11,13 @@
11
11
  // ZERO-MALWARE: Pure TypeScript/ESM. Strictly respects timeouts, no secret leakage, no unprompted background calls.
12
12
  import fs from 'node:fs';
13
13
  import path from 'node:path';
14
+ import { execFile } from 'node:child_process';
15
+ import { promisify } from 'node:util';
14
16
  import { causyneHome } from './utils/paths.js';
15
- import { MODEL_CATALOGUE, DEFAULT_MODEL_BY_PROVIDER } from './modelCatalogue.js';
17
+ import { MODEL_CATALOGUE, PEER_MODEL_CATALOGUE, DEFAULT_MODEL_BY_PROVIDER } from './modelCatalogue.js';
18
+ import { ANTIGRAVITY_MODELS, ANTIGRAVITY_LABEL_BY_ID, resolveAgyBinary } from './providers/antigravity.js';
19
+ import { isBinaryOnPath, BUILTIN_PEER_PRESETS } from './acp/agentCatalog.js';
20
+ const execFileAsync = promisify(execFile);
16
21
  const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
17
22
  const REQUEST_TIMEOUT_MS = 3500; // Fast timeout to never block user interaction
18
23
  export function cacheFilePath() {
@@ -40,11 +45,41 @@ export function normalizeProviderKey(provider) {
40
45
  return 'muse';
41
46
  if (p === 'openai-compatible' || p === 'custom')
42
47
  return 'openai-compatible';
48
+ if (p === 'antigravity' || p === 'agy')
49
+ return 'antigravity';
50
+ if (p === 'acp')
51
+ return 'acp';
52
+ if (p.startsWith('acp/')) {
53
+ const peer = p.slice(4).split('/')[0];
54
+ return peer ? `acp/${peer}` : 'acp';
55
+ }
43
56
  return p;
44
57
  }
58
+ /**
59
+ * The peer id behind an `acp/<peer>` provider key, or null.
60
+ *
61
+ * Peer agents are providers in exactly the same sense as an HTTP API: the user
62
+ * already owns the credential (their CLI login), and the models available are
63
+ * whatever that account can reach. The provider key carries the peer so the
64
+ * catalogue, the cache and the picker cannot disagree about which one is meant.
65
+ */
66
+ export function peerIdFromProviderKey(provider) {
67
+ const p = (provider || '').toLowerCase().trim();
68
+ if (!p.startsWith('acp/'))
69
+ return null;
70
+ const peer = p.slice(4).split('/')[0];
71
+ return peer || null;
72
+ }
45
73
  /** Get the static curated models for a provider id. */
46
74
  export function getCuratedModels(provider) {
47
75
  const norm = normalizeProviderKey(provider);
76
+ if (norm === 'antigravity')
77
+ return [...ANTIGRAVITY_MODELS];
78
+ const peer = peerIdFromProviderKey(norm);
79
+ if (peer)
80
+ return [...(PEER_MODEL_CATALOGUE[peer] ?? [])];
81
+ if (norm === 'acp')
82
+ return [...(MODEL_CATALOGUE['ACP (Peer Agents)'] ?? [])];
48
83
  const mapping = {
49
84
  'deepseek': 'DeepSeek',
50
85
  'qwen': 'Qwen',
@@ -64,6 +99,200 @@ export function getCuratedModels(provider) {
64
99
  }
65
100
  return [];
66
101
  }
102
+ /**
103
+ * Categorize available providers into BYOK and ACP peer agents,
104
+ * checking configured state for BYOK and installation status for ACP agents.
105
+ */
106
+ export function getAvailableProvidersOverview(config = {}) {
107
+ const currentProvider = config.provider || '';
108
+ const currentModel = config.model || '';
109
+ const byokDefs = [
110
+ {
111
+ id: 'anthropic',
112
+ label: 'Anthropic',
113
+ envVar: 'ANTHROPIC_API_KEY',
114
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['anthropic'] || 'claude-3-7-sonnet',
115
+ models: MODEL_CATALOGUE['Anthropic'] ? [...MODEL_CATALOGUE['Anthropic']] : []
116
+ },
117
+ {
118
+ id: 'openai',
119
+ label: 'OpenAI',
120
+ envVar: 'OPENAI_API_KEY',
121
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['openai'] || 'gpt-4o',
122
+ models: MODEL_CATALOGUE['OpenAI'] ? [...MODEL_CATALOGUE['OpenAI']] : []
123
+ },
124
+ {
125
+ id: 'gemini',
126
+ label: 'Google Gemini',
127
+ envVar: 'GEMINI_API_KEY',
128
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['gemini'] || 'gemini-2.5-pro',
129
+ models: MODEL_CATALOGUE['Gemini'] ? [...MODEL_CATALOGUE['Gemini']] : []
130
+ },
131
+ {
132
+ id: 'deepseek',
133
+ label: 'DeepSeek',
134
+ envVar: 'DEEPSEEK_API_KEY',
135
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['deepseek'] || 'deepseek-chat',
136
+ models: MODEL_CATALOGUE['DeepSeek'] ? [...MODEL_CATALOGUE['DeepSeek']] : []
137
+ },
138
+ {
139
+ id: 'qwen',
140
+ label: 'Qwen / DashScope',
141
+ envVar: 'DASHSCOPE_API_KEY',
142
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['qwen'] || 'qwen2.5-coder-32b-instruct',
143
+ models: MODEL_CATALOGUE['Qwen'] ? [...MODEL_CATALOGUE['Qwen']] : []
144
+ },
145
+ {
146
+ id: 'ollama',
147
+ label: 'Ollama (Local Server)',
148
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['ollama'] || 'llama3.3',
149
+ models: MODEL_CATALOGUE['Ollama (Local)'] ? [...MODEL_CATALOGUE['Ollama (Local)']] : []
150
+ },
151
+ {
152
+ id: 'xai',
153
+ label: 'xAI (Grok)',
154
+ envVar: 'XAI_API_KEY',
155
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['xai'] || 'grok-3',
156
+ models: MODEL_CATALOGUE['xAI (Grok)'] ? [...MODEL_CATALOGUE['xAI (Grok)']] : []
157
+ },
158
+ {
159
+ id: 'moonshot',
160
+ label: 'Moonshot (Kimi)',
161
+ envVar: 'MOONSHOT_API_KEY',
162
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['moonshot'] || 'kimi-k3',
163
+ models: MODEL_CATALOGUE['Moonshot (Kimi)'] ? [...MODEL_CATALOGUE['Moonshot (Kimi)']] : []
164
+ }
165
+ ];
166
+ const byok = byokDefs.map((def) => {
167
+ const isCurrent = currentProvider === def.id || (def.id === 'qwen' && currentProvider === 'dashscope-byok');
168
+ const isConfigured = def.id === 'ollama'
169
+ || Boolean(isCurrent && config.apiKey)
170
+ || Boolean(def.envVar && process.env[def.envVar]);
171
+ return {
172
+ id: def.id,
173
+ label: def.label,
174
+ isConfigured,
175
+ isCurrent,
176
+ models: def.models,
177
+ defaultModel: def.defaultModel
178
+ };
179
+ });
180
+ const acpPeers = [];
181
+ // Antigravity (special native local provider)
182
+ const hasAgy = Boolean(resolveAgyBinary());
183
+ acpPeers.push({
184
+ id: 'antigravity',
185
+ providerKey: 'antigravity',
186
+ label: 'Google Antigravity (AGY)',
187
+ installed: hasAgy,
188
+ status: hasAgy ? 'ready' : 'not_installed',
189
+ isCurrent: currentProvider === 'antigravity',
190
+ command: 'agy --output-format json',
191
+ models: [...ANTIGRAVITY_MODELS],
192
+ setupInstruction: 'Install Antigravity IDE or agy CLI to enable Google AGY models.'
193
+ });
194
+ // Standard ACP presets
195
+ const presetOrder = ['opencode', 'claude', 'codex', 'gemini', 'cursor', 'hermes', 'qwen', 'copilot', 'kimi', 'goose'];
196
+ for (const presetId of presetOrder) {
197
+ const preset = BUILTIN_PEER_PRESETS[presetId];
198
+ if (!preset)
199
+ continue;
200
+ let installed = false;
201
+ if (preset.id === 'cursor') {
202
+ installed = isBinaryOnPath('cursor-agent') || isBinaryOnPath('cursor');
203
+ }
204
+ else {
205
+ installed = isBinaryOnPath(preset.binaryName);
206
+ }
207
+ const providerKey = `acp/${preset.id}`;
208
+ const isCurrent = currentProvider === providerKey;
209
+ let models = [];
210
+ if (PEER_MODEL_CATALOGUE[preset.id]) {
211
+ models = [...(PEER_MODEL_CATALOGUE[preset.id] || [])];
212
+ }
213
+ else if (DEFAULT_MODEL_BY_PROVIDER[providerKey]) {
214
+ models = [DEFAULT_MODEL_BY_PROVIDER[providerKey]];
215
+ }
216
+ else {
217
+ models = [preset.id];
218
+ }
219
+ acpPeers.push({
220
+ id: preset.id,
221
+ providerKey,
222
+ label: preset.label,
223
+ installed,
224
+ status: installed ? 'ready' : 'not_installed',
225
+ isCurrent,
226
+ command: `${preset.command} ${preset.args.join(' ')}`,
227
+ models,
228
+ setupInstruction: preset.setupInstruction || `Install ${preset.label} CLI on your system.`
229
+ });
230
+ }
231
+ return {
232
+ activeProvider: currentProvider,
233
+ activeModel: currentModel,
234
+ byok,
235
+ acp: acpPeers
236
+ };
237
+ }
238
+ const MODEL_LIST_TIMEOUT_MS = 8000;
239
+ const ANSI_ESCAPE = /\u001b\[[0-9;]*[A-Za-z]/g;
240
+ const PEER_MODEL_COMMANDS = {
241
+ opencode: { command: 'opencode', args: ['models'] },
242
+ cursor: { command: 'cursor-agent', args: ['models'] }
243
+ };
244
+ async function runModelList(command, args) {
245
+ try {
246
+ const { stdout } = await execFileAsync(command, args, {
247
+ timeout: MODEL_LIST_TIMEOUT_MS,
248
+ maxBuffer: 4 * 1024 * 1024,
249
+ windowsHide: true
250
+ });
251
+ return stdout.replace(ANSI_ESCAPE, '').split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
252
+ }
253
+ catch {
254
+ return [];
255
+ }
256
+ }
257
+ function parseModelIds(lines) {
258
+ const models = [];
259
+ for (const line of lines) {
260
+ if (/^(fetching|loading|no models|error)/i.test(line))
261
+ continue;
262
+ if (line.endsWith('…') || line.endsWith('...'))
263
+ continue;
264
+ const firstColumn = (line.split('\t')[0] ?? '').trim();
265
+ if (!firstColumn || firstColumn.includes(' '))
266
+ continue;
267
+ models.push(firstColumn);
268
+ }
269
+ return [...new Set(models)];
270
+ }
271
+ /**
272
+ * Ask a peer CLI which models its account can reach. Zero tokens: this runs the
273
+ * peer's own listing command, never a model request.
274
+ */
275
+ export async function discoverPeerModels(peerId) {
276
+ const peer = (peerId || '').toLowerCase().trim();
277
+ const listing = PEER_MODEL_COMMANDS[peer];
278
+ if (!listing)
279
+ return [];
280
+ return parseModelIds(await runModelList(listing.command, listing.args));
281
+ }
282
+ /** Ask Antigravity for its live model list and return the readable labels. */
283
+ export async function discoverAntigravityModels() {
284
+ const lines = await runModelList(resolveAgyBinary(), ['models']);
285
+ const models = [];
286
+ for (const line of lines) {
287
+ if (/^(fetching|loading|no models|error)/i.test(line))
288
+ continue;
289
+ const [id, label] = line.split('\t').map((part) => part.trim());
290
+ if (!id || id.includes(' '))
291
+ continue;
292
+ models.push(label || ANTIGRAVITY_LABEL_BY_ID[id] || id);
293
+ }
294
+ return [...new Set(models)];
295
+ }
67
296
  /** Read cache safely from ~/.causyne/models_cache.json */
68
297
  export function readModelCache() {
69
298
  try {
@@ -127,6 +356,11 @@ export function saveCachedModels(provider, models) {
127
356
  export async function fetchLiveModels(provider, config = {}) {
128
357
  const norm = normalizeProviderKey(provider);
129
358
  const { apiKey, baseUrl } = config;
359
+ if (norm === 'antigravity')
360
+ return discoverAntigravityModels();
361
+ const peer = peerIdFromProviderKey(norm);
362
+ if (peer)
363
+ return discoverPeerModels(peer);
130
364
  try {
131
365
  if (norm === 'ollama') {
132
366
  const host = (baseUrl || 'http://127.0.0.1:11434').replace(/\/+$/, '');
@@ -257,8 +491,11 @@ export async function resolveAvailableModels(provider, config = {}, forceRefresh
257
491
  const combined = [...new Set([...cached, ...curated])];
258
492
  return { models: combined, source: 'cache' };
259
493
  }
260
- // Attempt lazy background discovery if credentials exist
261
- if (config.apiKey || norm === 'ollama') {
494
+ // Attempt lazy background discovery if credentials exist. Peer agents and
495
+ // Antigravity are credentialed by their own CLI login, so they qualify even
496
+ // with no apiKey in Causyne's vault.
497
+ const localAgent = norm === 'antigravity' || peerIdFromProviderKey(norm) !== null;
498
+ if (config.apiKey || norm === 'ollama' || localAgent) {
262
499
  const live = await fetchLiveModels(norm, config);
263
500
  if (live.length > 0) {
264
501
  const combined = [...new Set([...live, ...curated])];
@@ -12,8 +12,18 @@
12
12
 
13
13
  import fs from 'node:fs';
14
14
  import path from 'node:path';
15
+ import { execFile } from 'node:child_process';
16
+ import { promisify } from 'node:util';
15
17
  import { causyneHome } from './utils/paths.js';
16
- import { MODEL_CATALOGUE, DEFAULT_MODEL_BY_PROVIDER } from './modelCatalogue.js';
18
+ import { MODEL_CATALOGUE, PEER_MODEL_CATALOGUE, DEFAULT_MODEL_BY_PROVIDER } from './modelCatalogue.js';
19
+ import {
20
+ ANTIGRAVITY_MODELS,
21
+ ANTIGRAVITY_LABEL_BY_ID,
22
+ resolveAgyBinary
23
+ } from './providers/antigravity.js';
24
+ import { isBinaryOnPath, BUILTIN_PEER_PRESETS } from './acp/agentCatalog.js';
25
+
26
+ const execFileAsync = promisify(execFile);
17
27
 
18
28
  export interface DynamicCatalogueCache {
19
29
  version: 1;
@@ -43,12 +53,37 @@ export function normalizeProviderKey(provider: string): string {
43
53
  if (p === 'moonshot' || p === 'kimi') return 'moonshot';
44
54
  if (p === 'muse' || p === 'meta') return 'muse';
45
55
  if (p === 'openai-compatible' || p === 'custom') return 'openai-compatible';
56
+ if (p === 'antigravity' || p === 'agy') return 'antigravity';
57
+ if (p === 'acp') return 'acp';
58
+ if (p.startsWith('acp/')) {
59
+ const peer = p.slice(4).split('/')[0];
60
+ return peer ? `acp/${peer}` : 'acp';
61
+ }
46
62
  return p;
47
63
  }
48
64
 
65
+ /**
66
+ * The peer id behind an `acp/<peer>` provider key, or null.
67
+ *
68
+ * Peer agents are providers in exactly the same sense as an HTTP API: the user
69
+ * already owns the credential (their CLI login), and the models available are
70
+ * whatever that account can reach. The provider key carries the peer so the
71
+ * catalogue, the cache and the picker cannot disagree about which one is meant.
72
+ */
73
+ export function peerIdFromProviderKey(provider: string): string | null {
74
+ const p = (provider || '').toLowerCase().trim();
75
+ if (!p.startsWith('acp/')) return null;
76
+ const peer = p.slice(4).split('/')[0];
77
+ return peer || null;
78
+ }
79
+
49
80
  /** Get the static curated models for a provider id. */
50
81
  export function getCuratedModels(provider: string): string[] {
51
82
  const norm = normalizeProviderKey(provider);
83
+ if (norm === 'antigravity') return [...ANTIGRAVITY_MODELS];
84
+ const peer = peerIdFromProviderKey(norm);
85
+ if (peer) return [...(PEER_MODEL_CATALOGUE[peer] ?? [])];
86
+ if (norm === 'acp') return [...(MODEL_CATALOGUE['ACP (Peer Agents)'] ?? [])];
52
87
  const mapping: Record<string, keyof typeof MODEL_CATALOGUE> = {
53
88
  'deepseek': 'DeepSeek',
54
89
  'qwen': 'Qwen',
@@ -69,6 +104,237 @@ export function getCuratedModels(provider: string): string[] {
69
104
  return [];
70
105
  }
71
106
 
107
+ export interface ByokProviderInfo {
108
+ id: string;
109
+ label: string;
110
+ isConfigured: boolean;
111
+ isCurrent: boolean;
112
+ models: string[];
113
+ defaultModel: string;
114
+ }
115
+
116
+ export interface AcpPeerInfo {
117
+ id: string;
118
+ providerKey: string;
119
+ label: string;
120
+ installed: boolean;
121
+ status: 'ready' | 'not_installed';
122
+ isCurrent: boolean;
123
+ command: string;
124
+ models: string[];
125
+ setupInstruction: string;
126
+ }
127
+
128
+ export interface ProviderOverview {
129
+ activeProvider: string;
130
+ activeModel: string;
131
+ byok: ByokProviderInfo[];
132
+ acp: AcpPeerInfo[];
133
+ }
134
+
135
+ /**
136
+ * Categorize available providers into BYOK and ACP peer agents,
137
+ * checking configured state for BYOK and installation status for ACP agents.
138
+ */
139
+ export function getAvailableProvidersOverview(
140
+ config: { provider?: string; apiKey?: string; model?: string } = {}
141
+ ): ProviderOverview {
142
+ const currentProvider = config.provider || '';
143
+ const currentModel = config.model || '';
144
+
145
+ const byokDefs: Array<{ id: string; label: string; envVar?: string; defaultModel: string; models: string[] }> = [
146
+ {
147
+ id: 'anthropic',
148
+ label: 'Anthropic',
149
+ envVar: 'ANTHROPIC_API_KEY',
150
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['anthropic'] || 'claude-3-7-sonnet',
151
+ models: MODEL_CATALOGUE['Anthropic'] ? [...MODEL_CATALOGUE['Anthropic']] : []
152
+ },
153
+ {
154
+ id: 'openai',
155
+ label: 'OpenAI',
156
+ envVar: 'OPENAI_API_KEY',
157
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['openai'] || 'gpt-4o',
158
+ models: MODEL_CATALOGUE['OpenAI'] ? [...MODEL_CATALOGUE['OpenAI']] : []
159
+ },
160
+ {
161
+ id: 'gemini',
162
+ label: 'Google Gemini',
163
+ envVar: 'GEMINI_API_KEY',
164
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['gemini'] || 'gemini-2.5-pro',
165
+ models: MODEL_CATALOGUE['Gemini'] ? [...MODEL_CATALOGUE['Gemini']] : []
166
+ },
167
+ {
168
+ id: 'deepseek',
169
+ label: 'DeepSeek',
170
+ envVar: 'DEEPSEEK_API_KEY',
171
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['deepseek'] || 'deepseek-chat',
172
+ models: MODEL_CATALOGUE['DeepSeek'] ? [...MODEL_CATALOGUE['DeepSeek']] : []
173
+ },
174
+ {
175
+ id: 'qwen',
176
+ label: 'Qwen / DashScope',
177
+ envVar: 'DASHSCOPE_API_KEY',
178
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['qwen'] || 'qwen2.5-coder-32b-instruct',
179
+ models: MODEL_CATALOGUE['Qwen'] ? [...MODEL_CATALOGUE['Qwen']] : []
180
+ },
181
+ {
182
+ id: 'ollama',
183
+ label: 'Ollama (Local Server)',
184
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['ollama'] || 'llama3.3',
185
+ models: MODEL_CATALOGUE['Ollama (Local)'] ? [...MODEL_CATALOGUE['Ollama (Local)']] : []
186
+ },
187
+ {
188
+ id: 'xai',
189
+ label: 'xAI (Grok)',
190
+ envVar: 'XAI_API_KEY',
191
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['xai'] || 'grok-3',
192
+ models: MODEL_CATALOGUE['xAI (Grok)'] ? [...MODEL_CATALOGUE['xAI (Grok)']] : []
193
+ },
194
+ {
195
+ id: 'moonshot',
196
+ label: 'Moonshot (Kimi)',
197
+ envVar: 'MOONSHOT_API_KEY',
198
+ defaultModel: DEFAULT_MODEL_BY_PROVIDER['moonshot'] || 'kimi-k3',
199
+ models: MODEL_CATALOGUE['Moonshot (Kimi)'] ? [...MODEL_CATALOGUE['Moonshot (Kimi)']] : []
200
+ }
201
+ ];
202
+
203
+ const byok: ByokProviderInfo[] = byokDefs.map((def) => {
204
+ const isCurrent = currentProvider === def.id || (def.id === 'qwen' && currentProvider === 'dashscope-byok');
205
+ const isConfigured = def.id === 'ollama'
206
+ || Boolean(isCurrent && config.apiKey)
207
+ || Boolean(def.envVar && process.env[def.envVar]);
208
+
209
+ return {
210
+ id: def.id,
211
+ label: def.label,
212
+ isConfigured,
213
+ isCurrent,
214
+ models: def.models,
215
+ defaultModel: def.defaultModel
216
+ };
217
+ });
218
+
219
+ const acpPeers: AcpPeerInfo[] = [];
220
+
221
+ // Antigravity (special native local provider)
222
+ const hasAgy = Boolean(resolveAgyBinary());
223
+ acpPeers.push({
224
+ id: 'antigravity',
225
+ providerKey: 'antigravity',
226
+ label: 'Google Antigravity (AGY)',
227
+ installed: hasAgy,
228
+ status: hasAgy ? 'ready' : 'not_installed',
229
+ isCurrent: currentProvider === 'antigravity',
230
+ command: 'agy --output-format json',
231
+ models: [...ANTIGRAVITY_MODELS],
232
+ setupInstruction: 'Install Antigravity IDE or agy CLI to enable Google AGY models.'
233
+ });
234
+
235
+ // Standard ACP presets
236
+ const presetOrder = ['opencode', 'claude', 'codex', 'gemini', 'cursor', 'hermes', 'qwen', 'copilot', 'kimi', 'goose'];
237
+ for (const presetId of presetOrder) {
238
+ const preset = BUILTIN_PEER_PRESETS[presetId];
239
+ if (!preset) continue;
240
+
241
+ let installed = false;
242
+ if (preset.id === 'cursor') {
243
+ installed = isBinaryOnPath('cursor-agent') || isBinaryOnPath('cursor');
244
+ } else {
245
+ installed = isBinaryOnPath(preset.binaryName);
246
+ }
247
+
248
+ const providerKey = `acp/${preset.id}`;
249
+ const isCurrent = currentProvider === providerKey;
250
+
251
+ let models: string[] = [];
252
+ if (PEER_MODEL_CATALOGUE[preset.id]) {
253
+ models = [...(PEER_MODEL_CATALOGUE[preset.id] || [])];
254
+ } else if (DEFAULT_MODEL_BY_PROVIDER[providerKey]) {
255
+ models = [DEFAULT_MODEL_BY_PROVIDER[providerKey]];
256
+ } else {
257
+ models = [preset.id];
258
+ }
259
+
260
+ acpPeers.push({
261
+ id: preset.id,
262
+ providerKey,
263
+ label: preset.label,
264
+ installed,
265
+ status: installed ? 'ready' : 'not_installed',
266
+ isCurrent,
267
+ command: `${preset.command} ${preset.args.join(' ')}`,
268
+ models,
269
+ setupInstruction: preset.setupInstruction || `Install ${preset.label} CLI on your system.`
270
+ });
271
+ }
272
+
273
+ return {
274
+ activeProvider: currentProvider,
275
+ activeModel: currentModel,
276
+ byok,
277
+ acp: acpPeers
278
+ };
279
+ }
280
+
281
+ const MODEL_LIST_TIMEOUT_MS = 8000;
282
+ const ANSI_ESCAPE = /\u001b\[[0-9;]*[A-Za-z]/g;
283
+
284
+ const PEER_MODEL_COMMANDS: Record<string, { command: string; args: string[] }> = {
285
+ opencode: { command: 'opencode', args: ['models'] },
286
+ cursor: { command: 'cursor-agent', args: ['models'] }
287
+ };
288
+
289
+ async function runModelList(command: string, args: string[]): Promise<string[]> {
290
+ try {
291
+ const { stdout } = await execFileAsync(command, args, {
292
+ timeout: MODEL_LIST_TIMEOUT_MS,
293
+ maxBuffer: 4 * 1024 * 1024,
294
+ windowsHide: true
295
+ });
296
+ return stdout.replace(ANSI_ESCAPE, '').split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
297
+ } catch {
298
+ return [];
299
+ }
300
+ }
301
+
302
+ function parseModelIds(lines: string[]): string[] {
303
+ const models: string[] = [];
304
+ for (const line of lines) {
305
+ if (/^(fetching|loading|no models|error)/i.test(line)) continue;
306
+ if (line.endsWith('…') || line.endsWith('...')) continue;
307
+ const firstColumn = (line.split('\t')[0] ?? '').trim();
308
+ if (!firstColumn || firstColumn.includes(' ')) continue;
309
+ models.push(firstColumn);
310
+ }
311
+ return [...new Set(models)];
312
+ }
313
+
314
+ /**
315
+ * Ask a peer CLI which models its account can reach. Zero tokens: this runs the
316
+ * peer's own listing command, never a model request.
317
+ */
318
+ export async function discoverPeerModels(peerId: string): Promise<string[]> {
319
+ const peer = (peerId || '').toLowerCase().trim();
320
+ const listing = PEER_MODEL_COMMANDS[peer];
321
+ if (!listing) return [];
322
+ return parseModelIds(await runModelList(listing.command, listing.args));
323
+ }
324
+
325
+ /** Ask Antigravity for its live model list and return the readable labels. */
326
+ export async function discoverAntigravityModels(): Promise<string[]> {
327
+ const lines = await runModelList(resolveAgyBinary(), ['models']);
328
+ const models: string[] = [];
329
+ for (const line of lines) {
330
+ if (/^(fetching|loading|no models|error)/i.test(line)) continue;
331
+ const [id, label] = line.split('\t').map((part) => part.trim());
332
+ if (!id || id.includes(' ')) continue;
333
+ models.push(label || ANTIGRAVITY_LABEL_BY_ID[id] || id);
334
+ }
335
+ return [...new Set(models)];
336
+ }
337
+
72
338
  /** Read cache safely from ~/.causyne/models_cache.json */
73
339
  export function readModelCache(): DynamicCatalogueCache | null {
74
340
  try {
@@ -134,6 +400,10 @@ export async function fetchLiveModels(
134
400
  const norm = normalizeProviderKey(provider);
135
401
  const { apiKey, baseUrl } = config;
136
402
 
403
+ if (norm === 'antigravity') return discoverAntigravityModels();
404
+ const peer = peerIdFromProviderKey(norm);
405
+ if (peer) return discoverPeerModels(peer);
406
+
137
407
  try {
138
408
  if (norm === 'ollama') {
139
409
  const host = (baseUrl || 'http://127.0.0.1:11434').replace(/\/+$/, '');
@@ -269,8 +539,11 @@ export async function resolveAvailableModels(
269
539
  return { models: combined, source: 'cache' };
270
540
  }
271
541
 
272
- // Attempt lazy background discovery if credentials exist
273
- if (config.apiKey || norm === 'ollama') {
542
+ // Attempt lazy background discovery if credentials exist. Peer agents and
543
+ // Antigravity are credentialed by their own CLI login, so they qualify even
544
+ // with no apiKey in Causyne's vault.
545
+ const localAgent = norm === 'antigravity' || peerIdFromProviderKey(norm) !== null;
546
+ if (config.apiKey || norm === 'ollama' || localAgent) {
274
547
  const live = await fetchLiveModels(norm, config);
275
548
  if (live.length > 0) {
276
549
  const combined = [...new Set([...live, ...curated])];
@@ -1,4 +1,5 @@
1
1
  export const MODEL_CATALOGUE: Record<string, string[]>;
2
+ export const PEER_MODEL_CATALOGUE: Record<string, string[]>;
2
3
  export const PROVIDER_LABELS: string[];
3
4
  export const DEFAULT_MODEL_BY_PROVIDER: Record<string, string>;
4
5
  export const UTILITY_MODEL_BY_PROVIDER: Record<string, string>;
@@ -28,6 +28,26 @@
28
28
  // WHEN A PROVIDER SHIPS A NEW MODEL: add it here, run `npm test`, and the test
29
29
  // will name every other file that must be updated to match.
30
30
 
31
+ /**
32
+ * Models published by a peer CLI's own `models` command. Only ids verified
33
+ * against the installed binary live here; a peer with no published list is
34
+ * absent and uses its own default rather than an invented id.
35
+ */
36
+ export const PEER_MODEL_CATALOGUE = {
37
+ opencode: [
38
+ 'opencode/beam-free',
39
+ 'opencode/big-pickle',
40
+ 'opencode/deepseek-v4.1-flash-free',
41
+ 'opencode/flint-40b-free',
42
+ 'opencode/glm-5.3-flash-free',
43
+ 'opencode/mimo-v2.6-flash-free',
44
+ 'opencode/nemotron-3-ultra-free',
45
+ 'opencode/nemotron-3.5-lightning-free',
46
+ 'opencode/nemotron-3.5-super-vl-free'
47
+ ],
48
+ claude: ['sonnet', 'opus', 'haiku']
49
+ };
50
+
31
51
  /**
32
52
  * Selectable models per provider, newest first.
33
53
  *
@@ -98,7 +118,25 @@ export const MODEL_CATALOGUE = {
98
118
  'deepseek-v4-flash', 'deepseek-v4-pro'
99
119
  ],
100
120
  'Moonshot (Kimi)': ['kimi-k3', 'kimi-k2.7-code', 'kimi-k2.6'],
101
- 'xAI (Grok)': ['grok-3', 'grok-3-mini', 'grok-2-1212', 'grok-4.5', 'grok-latest']
121
+ 'xAI (Grok)': ['grok-3', 'grok-3-mini', 'grok-2-1212', 'grok-4.5', 'grok-latest'],
122
+ 'Google Antigravity': [
123
+ 'Gemini 3.8 Flash (Low)',
124
+ 'Gemini 3.8 Flash (Medium)',
125
+ 'Gemini 3.8 Flash (High)',
126
+ 'Gemini 4 Argon (Low)',
127
+ 'Gemini 4 Argon (Medium)',
128
+ 'Gemini 4 Argon (High)',
129
+ 'Claude Sonnet 5.5 (Low)',
130
+ 'Claude Sonnet 5.5 (Medium)',
131
+ 'Claude Sonnet 5.5 (High)',
132
+ 'Claude Opus 5.5 (Low)',
133
+ 'Claude Opus 5.5 (Medium)',
134
+ 'Claude Opus 5.5 (High)',
135
+ 'GPT-OSS 120B (Medium)'
136
+ ],
137
+ 'ACP (Peer Agents)': ['opencode', 'claude', 'codex', 'gemini', 'cursor', 'hermes', 'qwen', 'copilot', 'kimi', 'goose'],
138
+ 'OpenCode (ACP)': PEER_MODEL_CATALOGUE.opencode,
139
+ 'Claude Code (ACP)': PEER_MODEL_CATALOGUE.claude
102
140
  };
103
141
 
104
142
  /** Provider labels in picker order. */
@@ -117,6 +155,18 @@ export const DEFAULT_MODEL_BY_PROVIDER = {
117
155
  moonshot: 'kimi-k3',
118
156
  xai: 'grok-3',
119
157
  ollama: 'llama3.3',
158
+ acp: 'opencode',
159
+ 'acp/opencode': 'opencode/beam-free',
160
+ 'acp/claude': 'sonnet',
161
+ 'acp/codex': 'codex',
162
+ 'acp/gemini': 'gemini',
163
+ 'acp/cursor': 'cursor',
164
+ 'acp/qwen': 'qwen',
165
+ 'acp/copilot': 'copilot',
166
+ 'acp/kimi': 'kimi',
167
+ 'acp/goose': 'goose',
168
+ 'acp/hermes': 'hermes',
169
+ antigravity: 'Gemini 3.8 Flash (Low)',
120
170
  'openai-compatible': ''
121
171
  };
122
172