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