@causyne/agent 1.13.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.
Files changed (46) hide show
  1. package/docs/ARCHITECTURE.md +11 -4
  2. package/package.json +1 -1
  3. package/src/acp/agentCatalog.js +422 -0
  4. package/src/acp/agentCatalog.ts +489 -0
  5. package/src/acp/client.js +129 -6
  6. package/src/acp/client.ts +147 -7
  7. package/src/acp/peerProfiles.js +81 -3
  8. package/src/acp/peerProfiles.ts +85 -4
  9. package/src/acp/protocol.js +2 -0
  10. package/src/acp/protocol.ts +19 -0
  11. package/src/agentLoop.js +33 -12
  12. package/src/cliMode.js +4 -1
  13. package/src/commands.js +146 -0
  14. package/src/config.js +73 -0
  15. package/src/dynamicCatalogue.js +103 -3
  16. package/src/dynamicCatalogue.ts +101 -3
  17. package/src/entrypoint.js +11 -0
  18. package/src/modelCatalogue.d.ts +1 -0
  19. package/src/modelCatalogue.js +51 -1
  20. package/src/providers/acp.js +295 -0
  21. package/src/providers/anthropic.js +5 -13
  22. package/src/providers/antigravity.d.ts +9 -0
  23. package/src/providers/antigravity.js +272 -0
  24. package/src/providers/dashscope-byok.js +3 -4
  25. package/src/providers/deepseek.js +3 -4
  26. package/src/providers/factory.js +4 -0
  27. package/src/providers/gemini.js +17 -101
  28. package/src/providers/moonshot.js +3 -4
  29. package/src/providers/ollama.js +3 -4
  30. package/src/providers/openai-compatible.js +3 -4
  31. package/src/providers/qwen-byok.js +3 -4
  32. package/src/providers/xai.js +3 -4
  33. package/src/reporting.js +3 -1
  34. package/src/tokenTracker.js +19 -4
  35. package/src/tools/peerAgent.js +150 -31
  36. package/src/tools/peerAgent.ts +177 -32
  37. package/src/tools/registry.js +144 -16
  38. package/src/tools/toolScanner.js +349 -0
  39. package/src/tools/toolScanner.ts +451 -0
  40. package/src/tools/toolSelfRepair.js +759 -0
  41. package/src/tools/toolSelfRepair.ts +846 -0
  42. package/src/tui/banner.js +7 -1
  43. package/src/tui/banner.ts +7 -1
  44. package/src/tui/home.js +18 -3
  45. package/src/tui/setup.js +34 -2
  46. package/src/tui/setup.ts +36 -3
@@ -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.13.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",
@@ -0,0 +1,422 @@
1
+ /**
2
+ * Causyne Agent — ACP Agent Catalog & Zero-Token Discovery
3
+ *
4
+ * Provides built-in profiles, auth probing, and zero-token discovery for
5
+ * common external coding agents that support the Agent Client Protocol (ACP),
6
+ * such as Claude Code, Codex, OpenCode, Gemini CLI, Hermes, Cursor CLI,
7
+ * Qwen, Copilot, Kimi, and Goose.
8
+ */
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import { execFile } from 'node:child_process';
12
+ import { promisify } from 'node:util';
13
+ import { AcpClient } from './client.js';
14
+ const execFileAsync = promisify(execFile);
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
+ },
27
+ opencode: {
28
+ id: 'opencode',
29
+ label: 'OpenCode',
30
+ description: 'OpenCode AI coding agent with support for free and local models',
31
+ command: 'opencode',
32
+ args: ['acp'],
33
+ binaryName: 'opencode',
34
+ fallbackCommand: 'npx',
35
+ fallbackArgs: ['-y', 'opencode-ai', 'acp'],
36
+ authType: 'none',
37
+ setupInstruction: 'Run "opencode auth login" or configure a model in ~/.config/opencode',
38
+ timeoutSeconds: 180
39
+ },
40
+ claude: {
41
+ id: 'claude',
42
+ label: 'Claude Code',
43
+ description: 'Anthropic Claude Code CLI via official ACP bridge adapter',
44
+ command: 'npx',
45
+ args: ['-y', '@agentclientprotocol/claude-agent-acp@0.70.0'],
46
+ binaryName: 'claude',
47
+ authType: 'subscription',
48
+ authProbe: {
49
+ type: 'json',
50
+ command: 'claude',
51
+ args: ['auth', 'status', '--json'],
52
+ jsonField: 'loggedIn'
53
+ },
54
+ setupInstruction: 'Run "claude login" to authenticate with your Anthropic subscription or set ANTHROPIC_API_KEY',
55
+ timeoutSeconds: 300
56
+ },
57
+ codex: {
58
+ id: 'codex',
59
+ label: 'Codex CLI',
60
+ description: 'OpenAI Codex CLI coding agent via ACP adapter',
61
+ command: 'npx',
62
+ args: ['-y', '@agentclientprotocol/codex-acp@1.6.0'],
63
+ binaryName: 'codex',
64
+ authType: 'subscription',
65
+ authProbe: {
66
+ type: 'output_match',
67
+ command: 'codex',
68
+ args: ['login', 'status'],
69
+ positiveMatch: 'logged in',
70
+ negativeMatch: 'not logged in'
71
+ },
72
+ setupInstruction: 'Run "codex login" or set OPENAI_API_KEY in your environment',
73
+ timeoutSeconds: 300
74
+ },
75
+ gemini: {
76
+ id: 'gemini',
77
+ label: 'Gemini CLI',
78
+ description: 'Google Gemini CLI agent with free tier model support',
79
+ command: 'gemini',
80
+ args: ['--acp'],
81
+ binaryName: 'gemini',
82
+ fallbackCommand: 'npx',
83
+ fallbackArgs: ['-y', '@google/gemini-cli', '--acp'],
84
+ authType: 'oauth',
85
+ authProbe: {
86
+ type: 'file_exists',
87
+ filePath: path.join(process.env.HOME || '', '.gemini', 'oauth_creds.json')
88
+ },
89
+ setupInstruction: 'Run "gemini auth" or set GEMINI_API_KEY in your environment',
90
+ timeoutSeconds: 240
91
+ },
92
+ hermes: {
93
+ id: 'hermes',
94
+ label: 'Hermes Agent',
95
+ description: 'Nous Research Hermes autonomous AI agent',
96
+ command: 'hermes',
97
+ args: ['acp'],
98
+ binaryName: 'hermes',
99
+ authType: 'api_key',
100
+ setupInstruction: 'Run "hermes acp --setup" to configure provider credentials',
101
+ timeoutSeconds: 240
102
+ },
103
+ cursor: {
104
+ id: 'cursor',
105
+ label: 'Cursor CLI',
106
+ description: 'Cursor CLI coding agent over ACP',
107
+ command: 'cursor-agent',
108
+ args: ['acp'],
109
+ binaryName: 'cursor-agent',
110
+ authType: 'subscription',
111
+ setupInstruction: 'Run "cursor-agent login" to sign in to your Cursor account',
112
+ timeoutSeconds: 180
113
+ },
114
+ qwen: {
115
+ id: 'qwen',
116
+ label: 'Qwen Code',
117
+ description: 'Alibaba Qwen Code AI assistant over ACP',
118
+ command: 'qwen',
119
+ args: ['--acp'],
120
+ binaryName: 'qwen',
121
+ authType: 'api_key',
122
+ setupInstruction: 'Set DASHSCOPE_API_KEY or run "qwen login"',
123
+ timeoutSeconds: 180
124
+ },
125
+ copilot: {
126
+ id: 'copilot',
127
+ label: 'GitHub Copilot CLI',
128
+ description: 'GitHub Copilot CLI agent over ACP',
129
+ command: 'copilot',
130
+ args: ['--acp', '--stdio'],
131
+ binaryName: 'copilot',
132
+ authType: 'subscription',
133
+ setupInstruction: 'Run "copilot auth" to link your GitHub Copilot subscription',
134
+ timeoutSeconds: 180
135
+ },
136
+ kimi: {
137
+ id: 'kimi',
138
+ label: 'Kimi CLI',
139
+ description: 'Moonshot AI Kimi coding assistant via ACP',
140
+ command: 'kimi',
141
+ args: ['acp'],
142
+ binaryName: 'kimi',
143
+ authType: 'api_key',
144
+ setupInstruction: 'Set MOONSHOT_API_KEY in your environment',
145
+ timeoutSeconds: 180
146
+ },
147
+ goose: {
148
+ id: 'goose',
149
+ label: 'Goose CLI',
150
+ description: 'Block Goose extensible AI coding agent',
151
+ command: 'goose',
152
+ args: ['acp'],
153
+ binaryName: 'goose',
154
+ authType: 'api_key',
155
+ setupInstruction: 'Run "goose configure" to set up providers',
156
+ timeoutSeconds: 180
157
+ }
158
+ };
159
+ /**
160
+ * Check if a command or binary exists in PATH.
161
+ */
162
+ export function isBinaryOnPath(binaryName) {
163
+ if (path.isAbsolute(binaryName)) {
164
+ return fs.existsSync(binaryName);
165
+ }
166
+ const envPath = process.env.PATH || '';
167
+ const delimiter = process.platform === 'win32' ? ';' : ':';
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];
178
+ const extensions = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
179
+ for (const dir of dirs) {
180
+ if (!dir)
181
+ continue;
182
+ for (const ext of extensions) {
183
+ const full = path.join(dir, `${binaryName}${ext}`);
184
+ try {
185
+ if (fs.existsSync(full) && fs.statSync(full).isFile()) {
186
+ return true;
187
+ }
188
+ }
189
+ catch {
190
+ // Skip inaccessible path segments
191
+ }
192
+ }
193
+ }
194
+ return false;
195
+ }
196
+ /**
197
+ * Probe authorization state without spending model tokens.
198
+ */
199
+ export async function probePresetAuth(preset) {
200
+ if (!preset.authProbe) {
201
+ return { authenticated: true };
202
+ }
203
+ const probe = preset.authProbe;
204
+ if (probe.type === 'file_exists' && probe.filePath) {
205
+ const exists = fs.existsSync(probe.filePath);
206
+ return {
207
+ authenticated: exists,
208
+ reason: exists ? 'OAuth credentials file detected' : `Credentials file not found at ${probe.filePath}`
209
+ };
210
+ }
211
+ if (probe.type === 'json' && probe.command) {
212
+ if (!isBinaryOnPath(probe.command)) {
213
+ return { authenticated: false, reason: `${probe.command} CLI not found on PATH` };
214
+ }
215
+ try {
216
+ const { stdout } = await execFileAsync(probe.command, probe.args || [], { timeout: 8000 });
217
+ const parsed = JSON.parse(stdout.trim());
218
+ if (probe.jsonField && typeof parsed === 'object' && parsed !== null) {
219
+ const val = parsed[probe.jsonField];
220
+ const isAuth = Boolean(val);
221
+ return {
222
+ authenticated: isAuth,
223
+ reason: isAuth ? 'Valid CLI login session active' : 'CLI reports not logged in'
224
+ };
225
+ }
226
+ return { authenticated: true, reason: 'CLI auth responded' };
227
+ }
228
+ catch {
229
+ return { authenticated: false, reason: `Failed to probe ${probe.command} auth status` };
230
+ }
231
+ }
232
+ if (probe.type === 'output_match' && probe.command) {
233
+ if (!isBinaryOnPath(probe.command)) {
234
+ return { authenticated: false, reason: `${probe.command} CLI not found on PATH` };
235
+ }
236
+ try {
237
+ const result = await execFileAsync(probe.command, probe.args || [], { timeout: 8000 }).catch((e) => e);
238
+ const combined = `${result?.stdout || ''}\n${result?.stderr || ''}`.toLowerCase();
239
+ if (probe.negativeMatch && combined.includes(probe.negativeMatch.toLowerCase())) {
240
+ return { authenticated: false, reason: 'CLI reported not logged in' };
241
+ }
242
+ if (probe.positiveMatch && combined.includes(probe.positiveMatch.toLowerCase())) {
243
+ return { authenticated: true, reason: 'CLI login detected' };
244
+ }
245
+ return { authenticated: false, reason: 'No active login detected' };
246
+ }
247
+ catch {
248
+ return { authenticated: false, reason: `Failed to probe ${probe.command} auth` };
249
+ }
250
+ }
251
+ return { authenticated: true };
252
+ }
253
+ /**
254
+ * Execute a zero-token ACP handshake (initialize + session/new) with strict timeout.
255
+ * Never sends session/prompt, ensuring $0 token consumption.
256
+ */
257
+ export async function testPeerHandshake(options) {
258
+ const cwd = options.cwd || process.cwd();
259
+ const clientOptions = {
260
+ command: options.command,
261
+ cwd,
262
+ promptTimeoutMs: options.timeoutMs || 15000
263
+ };
264
+ if (options.args) {
265
+ clientOptions.args = options.args;
266
+ }
267
+ const client = new AcpClient(clientOptions);
268
+ const timeoutMs = options.timeoutMs || 12000;
269
+ try {
270
+ const init = await Promise.race([
271
+ client.start(),
272
+ new Promise((_, reject) => setTimeout(() => reject(new Error(`ACP initialization timed out after ${timeoutMs}ms`)), timeoutMs))
273
+ ]);
274
+ const agentInfo = init.agentInfo ? { name: init.agentInfo.name, version: init.agentInfo.version } : undefined;
275
+ const authMethods = Array.isArray(init.authMethods)
276
+ ? init.authMethods.map((m) => (typeof m === 'object' && m !== null && 'id' in m ? String(m.id) : String(m)))
277
+ : [];
278
+ // Attempt session/new to ensure agent is fully operational
279
+ try {
280
+ await client.newSession(cwd);
281
+ return {
282
+ ready: true,
283
+ ...(agentInfo ? { agentInfo } : {}),
284
+ authMethods
285
+ };
286
+ }
287
+ catch (sessionErr) {
288
+ const msg = sessionErr instanceof Error ? sessionErr.message : String(sessionErr);
289
+ return {
290
+ ready: false,
291
+ ...(agentInfo ? { agentInfo } : {}),
292
+ authMethods,
293
+ error: `Session creation failed: ${msg}`
294
+ };
295
+ }
296
+ }
297
+ catch (initErr) {
298
+ const msg = initErr instanceof Error ? initErr.message : String(initErr);
299
+ return { ready: false, error: msg };
300
+ }
301
+ finally {
302
+ await client.close().catch(() => { });
303
+ }
304
+ }
305
+ /**
306
+ * Detect all built-in ACP presets available on this machine and report their readiness.
307
+ */
308
+ export async function detectAllPeers(cwd = process.cwd()) {
309
+ const results = [];
310
+ for (const preset of Object.values(BUILTIN_PEER_PRESETS)) {
311
+ const hasDirectBinary = isBinaryOnPath(preset.binaryName);
312
+ const hasRunner = isBinaryOnPath(preset.command);
313
+ if (!hasDirectBinary && !hasRunner) {
314
+ results.push({
315
+ id: preset.id,
316
+ label: preset.label,
317
+ status: 'not_installed',
318
+ command: preset.command,
319
+ args: preset.args,
320
+ details: `Binary "${preset.binaryName}" and runner "${preset.command}" not found on PATH.`,
321
+ ...(preset.setupInstruction ? { setupInstruction: preset.setupInstruction } : {})
322
+ });
323
+ continue;
324
+ }
325
+ // Determine actual command to execute
326
+ let activeCommand = preset.command;
327
+ let activeArgs = preset.args;
328
+ if (!hasDirectBinary && preset.fallbackCommand && isBinaryOnPath(preset.fallbackCommand)) {
329
+ activeCommand = preset.fallbackCommand;
330
+ activeArgs = preset.fallbackArgs || [];
331
+ }
332
+ // Run auth probe
333
+ const auth = await probePresetAuth(preset);
334
+ if (!auth.authenticated) {
335
+ results.push({
336
+ id: preset.id,
337
+ label: preset.label,
338
+ status: 'needs_auth',
339
+ command: activeCommand,
340
+ args: activeArgs,
341
+ details: auth.reason || 'Authentication required.',
342
+ ...(preset.setupInstruction ? { setupInstruction: preset.setupInstruction } : {})
343
+ });
344
+ continue;
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
+ }
359
+ // Run zero-token handshake
360
+ const handshake = await testPeerHandshake({
361
+ command: activeCommand,
362
+ args: activeArgs,
363
+ cwd,
364
+ timeoutMs: 8000
365
+ });
366
+ if (handshake.ready) {
367
+ results.push({
368
+ id: preset.id,
369
+ label: preset.label,
370
+ status: 'ready',
371
+ command: activeCommand,
372
+ args: activeArgs,
373
+ ...(handshake.agentInfo ? { agentInfo: handshake.agentInfo } : {}),
374
+ ...(handshake.authMethods ? { authMethods: handshake.authMethods } : {}),
375
+ details: 'Operational and ready for delegation.'
376
+ });
377
+ }
378
+ else if (handshake.error && /auth/i.test(handshake.error)) {
379
+ results.push({
380
+ id: preset.id,
381
+ label: preset.label,
382
+ status: 'needs_auth',
383
+ command: activeCommand,
384
+ args: activeArgs,
385
+ ...(handshake.agentInfo ? { agentInfo: handshake.agentInfo } : {}),
386
+ ...(handshake.authMethods ? { authMethods: handshake.authMethods } : {}),
387
+ details: handshake.error,
388
+ ...(preset.setupInstruction ? { setupInstruction: preset.setupInstruction } : {})
389
+ });
390
+ }
391
+ else {
392
+ results.push({
393
+ id: preset.id,
394
+ label: preset.label,
395
+ status: hasDirectBinary ? 'error' : 'not_installed',
396
+ command: activeCommand,
397
+ args: activeArgs,
398
+ details: handshake.error || 'ACP handshake did not complete.',
399
+ ...(preset.setupInstruction ? { setupInstruction: preset.setupInstruction } : {})
400
+ });
401
+ }
402
+ }
403
+ return results;
404
+ }
405
+ /**
406
+ * Convert a preset to a runnable PeerProfile.
407
+ */
408
+ export function getPresetProfile(id) {
409
+ const preset = BUILTIN_PEER_PRESETS[id.toLowerCase()];
410
+ if (!preset)
411
+ return null;
412
+ return {
413
+ id: preset.id,
414
+ label: preset.label,
415
+ command: preset.command,
416
+ args: preset.args,
417
+ cwd: null,
418
+ policy: 'read-only',
419
+ timeoutSeconds: preset.timeoutSeconds || 180,
420
+ env: {}
421
+ };
422
+ }