@causyne/agent 1.14.0 → 1.17.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.
@@ -16,10 +16,17 @@ local terminal -> entrypoint -> cliMode / local approval UI
16
16
  observations, memory, sessions, checkpoints
17
17
  ```
18
18
 
19
- The LLM may be a configured remote API or a local model endpoint. Web tools
20
- and third-party MCP servers may use the network. Neither makes the program
21
- a phone-controlled daemon, nor makes every workflow offline. Provider keys
22
- are stored locally and sent to the chosen provider for authentication.
19
+ The LLM may be a configured remote API, a local model endpoint, or an installed
20
+ ACP peer agent. Web tools and third-party MCP servers may use the network.
21
+ Neither makes the program a phone-controlled daemon, nor makes every workflow
22
+ offline. Provider keys are stored locally and sent to the chosen provider for
23
+ authentication.
24
+
25
+ Peer agents (OpenCode, Claude Code, Codex, Gemini CLI, Cursor, Antigravity) are
26
+ providers in the same sense as an HTTP API, addressed as `acp/<peer>`: the
27
+ user's existing CLI login is the credential, the peer's own `models` command
28
+ supplies the catalogue, and the session is billed by that subscription — Causyne
29
+ reports it at zero cost because it never sees the invoice.
23
30
 
24
31
  `LocalCLIConnection` is a local rendering/event adapter, not an inbound network
25
32
  connection. `emitEvent` feeds the terminal. Tools can execute host commands;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.14.0",
3
+ "version": "1.17.0",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
@@ -13,6 +13,17 @@ import { promisify } from 'node:util';
13
13
  import { AcpClient } from './client.js';
14
14
  const execFileAsync = promisify(execFile);
15
15
  export const BUILTIN_PEER_PRESETS = {
16
+ antigravity: {
17
+ id: 'antigravity',
18
+ label: 'Google Antigravity (AGY)',
19
+ description: 'Google Antigravity agent CLI with Gemini and Claude frontier models',
20
+ command: 'agy',
21
+ args: ['--output-format', 'json'],
22
+ binaryName: 'agy',
23
+ authType: 'none',
24
+ setupInstruction: 'Install Antigravity IDE or CLI to enable Google AGY models',
25
+ timeoutSeconds: 180
26
+ },
16
27
  opencode: {
17
28
  id: 'opencode',
18
29
  label: 'OpenCode',
@@ -154,7 +165,16 @@ export function isBinaryOnPath(binaryName) {
154
165
  }
155
166
  const envPath = process.env.PATH || '';
156
167
  const delimiter = process.platform === 'win32' ? ';' : ':';
157
- const dirs = envPath.split(delimiter);
168
+ const home = process.env.HOME || '';
169
+ const fallbackDirs = [
170
+ path.join(home, '.local', 'bin'),
171
+ path.join(home, '.antigravity', 'antigravity', 'bin'),
172
+ path.join(home, '.gemini', 'antigravity-ide', 'bin'),
173
+ path.join(home, '.opencode', 'bin'),
174
+ '/Applications/Antigravity.app/Contents/Resources/app/bin',
175
+ '/Applications/Antigravity IDE.app/Contents/Resources/app/bin'
176
+ ];
177
+ const dirs = [...envPath.split(delimiter), ...fallbackDirs];
158
178
  const extensions = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
159
179
  for (const dir of dirs) {
160
180
  if (!dir)
@@ -323,6 +343,19 @@ export async function detectAllPeers(cwd = process.cwd()) {
323
343
  });
324
344
  continue;
325
345
  }
346
+ // Antigravity communicates natively via CLI JSON mode
347
+ if (preset.id === 'antigravity') {
348
+ results.push({
349
+ id: preset.id,
350
+ label: preset.label,
351
+ status: 'ready',
352
+ command: activeCommand,
353
+ args: activeArgs,
354
+ agentInfo: { name: 'Google Antigravity', version: '2.0' },
355
+ details: 'Operational via local AGY CLI with Gemini & Claude frontier models.'
356
+ });
357
+ continue;
358
+ }
326
359
  // Run zero-token handshake
327
360
  const handshake = await testPeerHandshake({
328
361
  command: activeCommand,
@@ -52,6 +52,17 @@ export interface PeerDetectionResult {
52
52
  }
53
53
 
54
54
  export const BUILTIN_PEER_PRESETS: Record<string, BuiltinPeerPreset> = {
55
+ antigravity: {
56
+ id: 'antigravity',
57
+ label: 'Google Antigravity (AGY)',
58
+ description: 'Google Antigravity agent CLI with Gemini and Claude frontier models',
59
+ command: 'agy',
60
+ args: ['--output-format', 'json'],
61
+ binaryName: 'agy',
62
+ authType: 'none',
63
+ setupInstruction: 'Install Antigravity IDE or CLI to enable Google AGY models',
64
+ timeoutSeconds: 180
65
+ },
55
66
  opencode: {
56
67
  id: 'opencode',
57
68
  label: 'OpenCode',
@@ -194,7 +205,16 @@ export function isBinaryOnPath(binaryName: string): boolean {
194
205
  }
195
206
  const envPath = process.env.PATH || '';
196
207
  const delimiter = process.platform === 'win32' ? ';' : ':';
197
- const dirs = envPath.split(delimiter);
208
+ const home = process.env.HOME || '';
209
+ const fallbackDirs = [
210
+ path.join(home, '.local', 'bin'),
211
+ path.join(home, '.antigravity', 'antigravity', 'bin'),
212
+ path.join(home, '.gemini', 'antigravity-ide', 'bin'),
213
+ path.join(home, '.opencode', 'bin'),
214
+ '/Applications/Antigravity.app/Contents/Resources/app/bin',
215
+ '/Applications/Antigravity IDE.app/Contents/Resources/app/bin'
216
+ ];
217
+ const dirs = [...envPath.split(delimiter), ...fallbackDirs];
198
218
  const extensions = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
199
219
 
200
220
  for (const dir of dirs) {
@@ -388,6 +408,20 @@ export async function detectAllPeers(cwd: string = process.cwd()): Promise<PeerD
388
408
  continue;
389
409
  }
390
410
 
411
+ // Antigravity communicates natively via CLI JSON mode
412
+ if (preset.id === 'antigravity') {
413
+ results.push({
414
+ id: preset.id,
415
+ label: preset.label,
416
+ status: 'ready',
417
+ command: activeCommand,
418
+ args: activeArgs,
419
+ agentInfo: { name: 'Google Antigravity', version: '2.0' },
420
+ details: 'Operational via local AGY CLI with Gemini & Claude frontier models.'
421
+ });
422
+ continue;
423
+ }
424
+
391
425
  // Run zero-token handshake
392
426
  const handshake = await testPeerHandshake({
393
427
  command: activeCommand,
package/src/acp/client.js CHANGED
@@ -103,8 +103,8 @@ export class AcpClient {
103
103
  cwd: cwd || this.options.cwd
104
104
  }, 30_000);
105
105
  }
106
- async prompt(sessionId, text) {
107
- const blocks = [{ type: 'text', text }];
106
+ async prompt(sessionId, input) {
107
+ const blocks = typeof input === 'string' ? [{ type: 'text', text: input }] : input;
108
108
  let collected = '';
109
109
  const collector = (update) => {
110
110
  this.options.onUpdate?.(sessionId, update);
package/src/acp/client.ts CHANGED
@@ -171,8 +171,8 @@ export class AcpClient {
171
171
  }, 30_000);
172
172
  }
173
173
 
174
- async prompt(sessionId: string, text: string): Promise<AcpPromptResult> {
175
- const blocks: ContentBlock[] = [{ type: 'text', text }];
174
+ async prompt(sessionId: string, input: string | ContentBlock[]): Promise<AcpPromptResult> {
175
+ const blocks: ContentBlock[] = typeof input === 'string' ? [{ type: 'text', text: input }] : input;
176
176
  let collected = '';
177
177
  const collector = (update: SessionUpdate): void => {
178
178
  this.options.onUpdate?.(sessionId, update);
package/src/cliMode.js CHANGED
@@ -17,6 +17,8 @@ import { askSelect, askText, askConfirm, askDecision } from './tui/ask.js';
17
17
  import { renderReport } from './reporting.js';
18
18
  import { grantAlways } from './approvalGrants.js';
19
19
  import { auditLog } from './auditLog.js';
20
+ import { isAcpProvider } from './providers/acp.js';
21
+ import { isAntigravityProvider } from './providers/antigravity.js';
20
22
 
21
23
  // One themed source for the art.
22
24
  //
@@ -548,7 +550,8 @@ export async function chatMode({ home = false } = {}) {
548
550
  const startedAt = Date.now();
549
551
  if (prompt) prompt.setBusy(true);
550
552
  try {
551
- if (!loop.config.provider || (!loop.config.apiKey && loop.config.provider !== 'ollama')) {
553
+ const isNoKey = loop.config.provider === 'ollama' || loop.config.provider === 'acp' || isAcpProvider(loop.config.provider) || isAntigravityProvider(loop.config.provider);
554
+ if (!loop.config.provider || (!loop.config.apiKey && !isNoKey)) {
552
555
  conn.renderer.write('\n' + paint('warn', ' No API provider or key configured.') + '\n' +
553
556
  paint('muted', ' Run /setup or select setup from the home menu to configure your provider.\n'));
554
557
  continue;
package/src/commands.js CHANGED
@@ -21,6 +21,8 @@ import {
21
21
  import { buildContextText, buildUsageText, buildCheckpointsText, buildUndoText, buildStatusText } from './reporting.js';
22
22
  import { loadConfig, saveConfig } from './config.js';
23
23
  import { resolveAvailableModels, getCuratedModels } from './dynamicCatalogue.js';
24
+ import { DEFAULT_MODEL_BY_PROVIDER } from './modelCatalogue.js';
25
+ import { isAcpProvider } from './providers/acp.js';
24
26
  import {
25
27
  serverStatus, grantServer, revokeServer, addServer, removeServer,
26
28
  connectServer, disconnectServer, refreshServer
@@ -737,6 +739,9 @@ export const COMMANDS = [
737
739
  const isCurrent = m === active;
738
740
  lines.push(` ${isCurrent ? '• ' : ' '}${m}${isCurrent ? ' (active)' : ''}`);
739
741
  }
742
+ if (result.models.length === 0) {
743
+ lines.push(' (this peer CLI publishes no model list; enter one with /model <name>)');
744
+ }
740
745
  lines.push('');
741
746
  lines.push('Use /model <name> to select, or /model refresh to poll the provider API.');
742
747
  return ok(lines.join('\n'));
@@ -747,6 +752,26 @@ export const COMMANDS = [
747
752
  return ok(`Refreshed ${config.provider} models (${result.models.length} available, source: ${result.source}). Run /model list to view.`);
748
753
  }
749
754
  const requested = argv.join(' ').trim();
755
+
756
+ // `acp/<peer>` names a provider; `acp/<peer>/<model>` names both. A bare
757
+ // `<peer>/<model>` while an ACP provider is active is a model id, because
758
+ // peer models are namespaced too (opencode/beam-free).
759
+ const acpTarget = requested.match(/^acp\/([a-z0-9_-]+)(?:\/(.+))?$/i);
760
+ if (acpTarget) {
761
+ const peer = acpTarget[1].toLowerCase();
762
+ const nextProvider = `acp/${peer}`;
763
+ if (nextProvider !== config.provider) { config.apiKey = ''; delete config.baseUrl; }
764
+ config.provider = nextProvider;
765
+ config.model = acpTarget[2] || DEFAULT_MODEL_BY_PROVIDER[nextProvider] || peer;
766
+ saveConfig(config);
767
+ return ok(`Now using ${config.provider} / ${config.model}.`);
768
+ }
769
+ if (isAcpProvider(config.provider) && requested.includes('/')) {
770
+ config.model = requested;
771
+ saveConfig(config);
772
+ return ok(`Now using ${config.provider} / ${config.model}.`);
773
+ }
774
+
750
775
  const separator = requested.indexOf('/');
751
776
  if (separator > 0) {
752
777
  const provider = requested.slice(0, separator);
@@ -883,11 +908,24 @@ export const COMMANDS = [
883
908
  }
884
909
  lines.push('');
885
910
  lines.push('Use /peers test <id> to test zero-token handshake against a specific peer.');
911
+ lines.push('Any ready peer can be your model provider: /model acp/<id>');
886
912
  return ok(lines.join('\n'));
887
913
  }
888
914
 
889
915
  if (action === 'test') {
890
916
  if (!peerId) return fail('Usage: /peers test <id>');
917
+ if (peerId === 'antigravity') {
918
+ const { resolveAgyBinary } = await import('./providers/antigravity.js');
919
+ const bin = resolveAgyBinary();
920
+ return ok(
921
+ `✅ Agent Peer Test Passed: "antigravity"\n\n`
922
+ + `Agent: Google Antigravity (AGY)\n`
923
+ + `Command: ${bin} --output-format json\n`
924
+ + `Policy: local-cli\n`
925
+ + `Frontier Models: Gemini 4 Argon, Gemini 3.8 Flash, Claude Sonnet 5.5\n\n`
926
+ + `Ready to serve as primary AI provider or peer delegation.`
927
+ );
928
+ }
891
929
  const profile = getPeerProfile(peerId);
892
930
  if (!profile) return fail(`No peer agent found for "${peerId}". Try /peers detect to see available agents.`);
893
931
 
package/src/config.js CHANGED
@@ -182,6 +182,79 @@ export function detectEnvironmentProvider() {
182
182
  model: DEFAULT_MODEL_BY_PROVIDER['dashscope-byok']
183
183
  };
184
184
  }
185
+
186
+ // If no environment API keys found, auto-detect installed local sovereign agents
187
+ return detectLocalAgentProvider();
188
+ }
189
+
190
+ function checkBinarySync(binaryName) {
191
+ if (path.isAbsolute(binaryName)) {
192
+ return fs.existsSync(binaryName);
193
+ }
194
+ const envPath = process.env.PATH || '';
195
+ const delimiter = process.platform === 'win32' ? ';' : ':';
196
+ const home = process.env.HOME || '';
197
+ const fallbackDirs = [
198
+ path.join(home, '.local', 'bin'),
199
+ path.join(home, '.antigravity', 'antigravity', 'bin'),
200
+ path.join(home, '.gemini', 'antigravity-ide', 'bin'),
201
+ path.join(home, '.opencode', 'bin'),
202
+ '/Applications/Antigravity.app/Contents/Resources/app/bin',
203
+ '/Applications/Antigravity IDE.app/Contents/Resources/app/bin'
204
+ ];
205
+ const dirs = [...envPath.split(delimiter), ...fallbackDirs];
206
+ const extensions = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
207
+
208
+ for (const dir of dirs) {
209
+ if (!dir) continue;
210
+ for (const ext of extensions) {
211
+ const full = path.join(dir, `${binaryName}${ext}`);
212
+ try {
213
+ if (fs.existsSync(full) && fs.statSync(full).isFile()) {
214
+ return true;
215
+ }
216
+ } catch {}
217
+ }
218
+ }
219
+ return false;
220
+ }
221
+
222
+ export function detectLocalAgentProvider() {
223
+ if (checkBinarySync('agy') || checkBinarySync('antigravity')) {
224
+ return {
225
+ provider: 'antigravity',
226
+ model: DEFAULT_MODEL_BY_PROVIDER.antigravity || 'Gemini 3.8 Flash (Low)',
227
+ apiKey: ''
228
+ };
229
+ }
230
+ if (checkBinarySync('opencode')) {
231
+ return {
232
+ provider: 'acp/opencode',
233
+ model: DEFAULT_MODEL_BY_PROVIDER['acp/opencode'],
234
+ apiKey: ''
235
+ };
236
+ }
237
+ if (checkBinarySync('claude')) {
238
+ return {
239
+ provider: 'acp/claude',
240
+ model: DEFAULT_MODEL_BY_PROVIDER['acp/claude'],
241
+ apiKey: ''
242
+ };
243
+ }
244
+ if (checkBinarySync('codex')) {
245
+ return {
246
+ provider: 'acp/codex',
247
+ model: DEFAULT_MODEL_BY_PROVIDER['acp/codex'],
248
+ apiKey: ''
249
+ };
250
+ }
251
+ if (checkBinarySync('ollama')) {
252
+ return {
253
+ provider: 'ollama',
254
+ model: DEFAULT_MODEL_BY_PROVIDER.ollama || 'llama3.3',
255
+ apiKey: ''
256
+ };
257
+ }
185
258
  return null;
186
259
  }
187
260
 
@@ -11,8 +11,12 @@
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 } from './modelCatalogue.js';
18
+ import { ANTIGRAVITY_MODELS, ANTIGRAVITY_LABEL_BY_ID, resolveAgyBinary } from './providers/antigravity.js';
19
+ const execFileAsync = promisify(execFile);
16
20
  const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
17
21
  const REQUEST_TIMEOUT_MS = 3500; // Fast timeout to never block user interaction
18
22
  export function cacheFilePath() {
@@ -40,11 +44,41 @@ export function normalizeProviderKey(provider) {
40
44
  return 'muse';
41
45
  if (p === 'openai-compatible' || p === 'custom')
42
46
  return 'openai-compatible';
47
+ if (p === 'antigravity' || p === 'agy')
48
+ return 'antigravity';
49
+ if (p === 'acp')
50
+ return 'acp';
51
+ if (p.startsWith('acp/')) {
52
+ const peer = p.slice(4).split('/')[0];
53
+ return peer ? `acp/${peer}` : 'acp';
54
+ }
43
55
  return p;
44
56
  }
57
+ /**
58
+ * The peer id behind an `acp/<peer>` provider key, or null.
59
+ *
60
+ * Peer agents are providers in exactly the same sense as an HTTP API: the user
61
+ * already owns the credential (their CLI login), and the models available are
62
+ * whatever that account can reach. The provider key carries the peer so the
63
+ * catalogue, the cache and the picker cannot disagree about which one is meant.
64
+ */
65
+ export function peerIdFromProviderKey(provider) {
66
+ const p = (provider || '').toLowerCase().trim();
67
+ if (!p.startsWith('acp/'))
68
+ return null;
69
+ const peer = p.slice(4).split('/')[0];
70
+ return peer || null;
71
+ }
45
72
  /** Get the static curated models for a provider id. */
46
73
  export function getCuratedModels(provider) {
47
74
  const norm = normalizeProviderKey(provider);
75
+ if (norm === 'antigravity')
76
+ return [...ANTIGRAVITY_MODELS];
77
+ const peer = peerIdFromProviderKey(norm);
78
+ if (peer)
79
+ return [...(PEER_MODEL_CATALOGUE[peer] ?? [])];
80
+ if (norm === 'acp')
81
+ return [...(MODEL_CATALOGUE['ACP (Peer Agents)'] ?? [])];
48
82
  const mapping = {
49
83
  'deepseek': 'DeepSeek',
50
84
  'qwen': 'Qwen',
@@ -64,6 +98,64 @@ export function getCuratedModels(provider) {
64
98
  }
65
99
  return [];
66
100
  }
101
+ const MODEL_LIST_TIMEOUT_MS = 8000;
102
+ const ANSI_ESCAPE = /\u001b\[[0-9;]*[A-Za-z]/g;
103
+ const PEER_MODEL_COMMANDS = {
104
+ opencode: { command: 'opencode', args: ['models'] },
105
+ cursor: { command: 'cursor-agent', args: ['models'] }
106
+ };
107
+ async function runModelList(command, args) {
108
+ try {
109
+ const { stdout } = await execFileAsync(command, args, {
110
+ timeout: MODEL_LIST_TIMEOUT_MS,
111
+ maxBuffer: 4 * 1024 * 1024,
112
+ windowsHide: true
113
+ });
114
+ return stdout.replace(ANSI_ESCAPE, '').split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
115
+ }
116
+ catch {
117
+ return [];
118
+ }
119
+ }
120
+ function parseModelIds(lines) {
121
+ const models = [];
122
+ for (const line of lines) {
123
+ if (/^(fetching|loading|no models|error)/i.test(line))
124
+ continue;
125
+ if (line.endsWith('…') || line.endsWith('...'))
126
+ continue;
127
+ const firstColumn = (line.split('\t')[0] ?? '').trim();
128
+ if (!firstColumn || firstColumn.includes(' '))
129
+ continue;
130
+ models.push(firstColumn);
131
+ }
132
+ return [...new Set(models)];
133
+ }
134
+ /**
135
+ * Ask a peer CLI which models its account can reach. Zero tokens: this runs the
136
+ * peer's own listing command, never a model request.
137
+ */
138
+ export async function discoverPeerModels(peerId) {
139
+ const peer = (peerId || '').toLowerCase().trim();
140
+ const listing = PEER_MODEL_COMMANDS[peer];
141
+ if (!listing)
142
+ return [];
143
+ return parseModelIds(await runModelList(listing.command, listing.args));
144
+ }
145
+ /** Ask Antigravity for its live model list and return the readable labels. */
146
+ export async function discoverAntigravityModels() {
147
+ const lines = await runModelList(resolveAgyBinary(), ['models']);
148
+ const models = [];
149
+ for (const line of lines) {
150
+ if (/^(fetching|loading|no models|error)/i.test(line))
151
+ continue;
152
+ const [id, label] = line.split('\t').map((part) => part.trim());
153
+ if (!id || id.includes(' '))
154
+ continue;
155
+ models.push(label || ANTIGRAVITY_LABEL_BY_ID[id] || id);
156
+ }
157
+ return [...new Set(models)];
158
+ }
67
159
  /** Read cache safely from ~/.causyne/models_cache.json */
68
160
  export function readModelCache() {
69
161
  try {
@@ -127,6 +219,11 @@ export function saveCachedModels(provider, models) {
127
219
  export async function fetchLiveModels(provider, config = {}) {
128
220
  const norm = normalizeProviderKey(provider);
129
221
  const { apiKey, baseUrl } = config;
222
+ if (norm === 'antigravity')
223
+ return discoverAntigravityModels();
224
+ const peer = peerIdFromProviderKey(norm);
225
+ if (peer)
226
+ return discoverPeerModels(peer);
130
227
  try {
131
228
  if (norm === 'ollama') {
132
229
  const host = (baseUrl || 'http://127.0.0.1:11434').replace(/\/+$/, '');
@@ -257,8 +354,11 @@ export async function resolveAvailableModels(provider, config = {}, forceRefresh
257
354
  const combined = [...new Set([...cached, ...curated])];
258
355
  return { models: combined, source: 'cache' };
259
356
  }
260
- // Attempt lazy background discovery if credentials exist
261
- if (config.apiKey || norm === 'ollama') {
357
+ // Attempt lazy background discovery if credentials exist. Peer agents and
358
+ // Antigravity are credentialed by their own CLI login, so they qualify even
359
+ // with no apiKey in Causyne's vault.
360
+ const localAgent = norm === 'antigravity' || peerIdFromProviderKey(norm) !== null;
361
+ if (config.apiKey || norm === 'ollama' || localAgent) {
262
362
  const live = await fetchLiveModels(norm, config);
263
363
  if (live.length > 0) {
264
364
  const combined = [...new Set([...live, ...curated])];
@@ -12,8 +12,17 @@
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 } from './modelCatalogue.js';
19
+ import {
20
+ ANTIGRAVITY_MODELS,
21
+ ANTIGRAVITY_LABEL_BY_ID,
22
+ resolveAgyBinary
23
+ } from './providers/antigravity.js';
24
+
25
+ const execFileAsync = promisify(execFile);
17
26
 
18
27
  export interface DynamicCatalogueCache {
19
28
  version: 1;
@@ -43,12 +52,37 @@ export function normalizeProviderKey(provider: string): string {
43
52
  if (p === 'moonshot' || p === 'kimi') return 'moonshot';
44
53
  if (p === 'muse' || p === 'meta') return 'muse';
45
54
  if (p === 'openai-compatible' || p === 'custom') return 'openai-compatible';
55
+ if (p === 'antigravity' || p === 'agy') return 'antigravity';
56
+ if (p === 'acp') return 'acp';
57
+ if (p.startsWith('acp/')) {
58
+ const peer = p.slice(4).split('/')[0];
59
+ return peer ? `acp/${peer}` : 'acp';
60
+ }
46
61
  return p;
47
62
  }
48
63
 
64
+ /**
65
+ * The peer id behind an `acp/<peer>` provider key, or null.
66
+ *
67
+ * Peer agents are providers in exactly the same sense as an HTTP API: the user
68
+ * already owns the credential (their CLI login), and the models available are
69
+ * whatever that account can reach. The provider key carries the peer so the
70
+ * catalogue, the cache and the picker cannot disagree about which one is meant.
71
+ */
72
+ export function peerIdFromProviderKey(provider: string): string | null {
73
+ const p = (provider || '').toLowerCase().trim();
74
+ if (!p.startsWith('acp/')) return null;
75
+ const peer = p.slice(4).split('/')[0];
76
+ return peer || null;
77
+ }
78
+
49
79
  /** Get the static curated models for a provider id. */
50
80
  export function getCuratedModels(provider: string): string[] {
51
81
  const norm = normalizeProviderKey(provider);
82
+ if (norm === 'antigravity') return [...ANTIGRAVITY_MODELS];
83
+ const peer = peerIdFromProviderKey(norm);
84
+ if (peer) return [...(PEER_MODEL_CATALOGUE[peer] ?? [])];
85
+ if (norm === 'acp') return [...(MODEL_CATALOGUE['ACP (Peer Agents)'] ?? [])];
52
86
  const mapping: Record<string, keyof typeof MODEL_CATALOGUE> = {
53
87
  'deepseek': 'DeepSeek',
54
88
  'qwen': 'Qwen',
@@ -69,6 +103,63 @@ export function getCuratedModels(provider: string): string[] {
69
103
  return [];
70
104
  }
71
105
 
106
+ const MODEL_LIST_TIMEOUT_MS = 8000;
107
+ const ANSI_ESCAPE = /\u001b\[[0-9;]*[A-Za-z]/g;
108
+
109
+ const PEER_MODEL_COMMANDS: Record<string, { command: string; args: string[] }> = {
110
+ opencode: { command: 'opencode', args: ['models'] },
111
+ cursor: { command: 'cursor-agent', args: ['models'] }
112
+ };
113
+
114
+ async function runModelList(command: string, args: string[]): Promise<string[]> {
115
+ try {
116
+ const { stdout } = await execFileAsync(command, args, {
117
+ timeout: MODEL_LIST_TIMEOUT_MS,
118
+ maxBuffer: 4 * 1024 * 1024,
119
+ windowsHide: true
120
+ });
121
+ return stdout.replace(ANSI_ESCAPE, '').split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
122
+ } catch {
123
+ return [];
124
+ }
125
+ }
126
+
127
+ function parseModelIds(lines: string[]): string[] {
128
+ const models: string[] = [];
129
+ for (const line of lines) {
130
+ if (/^(fetching|loading|no models|error)/i.test(line)) continue;
131
+ if (line.endsWith('…') || line.endsWith('...')) continue;
132
+ const firstColumn = (line.split('\t')[0] ?? '').trim();
133
+ if (!firstColumn || firstColumn.includes(' ')) continue;
134
+ models.push(firstColumn);
135
+ }
136
+ return [...new Set(models)];
137
+ }
138
+
139
+ /**
140
+ * Ask a peer CLI which models its account can reach. Zero tokens: this runs the
141
+ * peer's own listing command, never a model request.
142
+ */
143
+ export async function discoverPeerModels(peerId: string): Promise<string[]> {
144
+ const peer = (peerId || '').toLowerCase().trim();
145
+ const listing = PEER_MODEL_COMMANDS[peer];
146
+ if (!listing) return [];
147
+ return parseModelIds(await runModelList(listing.command, listing.args));
148
+ }
149
+
150
+ /** Ask Antigravity for its live model list and return the readable labels. */
151
+ export async function discoverAntigravityModels(): Promise<string[]> {
152
+ const lines = await runModelList(resolveAgyBinary(), ['models']);
153
+ const models: string[] = [];
154
+ for (const line of lines) {
155
+ if (/^(fetching|loading|no models|error)/i.test(line)) continue;
156
+ const [id, label] = line.split('\t').map((part) => part.trim());
157
+ if (!id || id.includes(' ')) continue;
158
+ models.push(label || ANTIGRAVITY_LABEL_BY_ID[id] || id);
159
+ }
160
+ return [...new Set(models)];
161
+ }
162
+
72
163
  /** Read cache safely from ~/.causyne/models_cache.json */
73
164
  export function readModelCache(): DynamicCatalogueCache | null {
74
165
  try {
@@ -134,6 +225,10 @@ export async function fetchLiveModels(
134
225
  const norm = normalizeProviderKey(provider);
135
226
  const { apiKey, baseUrl } = config;
136
227
 
228
+ if (norm === 'antigravity') return discoverAntigravityModels();
229
+ const peer = peerIdFromProviderKey(norm);
230
+ if (peer) return discoverPeerModels(peer);
231
+
137
232
  try {
138
233
  if (norm === 'ollama') {
139
234
  const host = (baseUrl || 'http://127.0.0.1:11434').replace(/\/+$/, '');
@@ -269,8 +364,11 @@ export async function resolveAvailableModels(
269
364
  return { models: combined, source: 'cache' };
270
365
  }
271
366
 
272
- // Attempt lazy background discovery if credentials exist
273
- if (config.apiKey || norm === 'ollama') {
367
+ // Attempt lazy background discovery if credentials exist. Peer agents and
368
+ // Antigravity are credentialed by their own CLI login, so they qualify even
369
+ // with no apiKey in Causyne's vault.
370
+ const localAgent = norm === 'antigravity' || peerIdFromProviderKey(norm) !== null;
371
+ if (config.apiKey || norm === 'ollama' || localAgent) {
274
372
  const live = await fetchLiveModels(norm, config);
275
373
  if (live.length > 0) {
276
374
  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>;