expxagents 0.28.2 → 0.29.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.
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import readline from 'node:readline';
|
|
2
|
+
import { AgentRunner, SessionManager, SUPPORTED_MODELS, DEFAULT_MODEL } from '@expxagents/agent';
|
|
3
|
+
const COLORS = {
|
|
4
|
+
reset: '\x1b[0m',
|
|
5
|
+
dim: '\x1b[2m',
|
|
6
|
+
green: '\x1b[32m',
|
|
7
|
+
cyan: '\x1b[36m',
|
|
8
|
+
yellow: '\x1b[33m',
|
|
9
|
+
magenta: '\x1b[35m',
|
|
10
|
+
bold: '\x1b[1m',
|
|
11
|
+
};
|
|
12
|
+
function printBanner(model) {
|
|
13
|
+
const modelInfo = SUPPORTED_MODELS.find(m => m.id === model);
|
|
14
|
+
const label = modelInfo?.name ?? model;
|
|
15
|
+
console.log(`\n${COLORS.bold}${COLORS.cyan}ExpxAgents CLI${COLORS.reset} ${COLORS.dim}— powered by OpenRouter${COLORS.reset}`);
|
|
16
|
+
console.log(`${COLORS.dim}Model: ${COLORS.yellow}${label}${COLORS.reset}`);
|
|
17
|
+
console.log(`${COLORS.dim}Working directory: ${process.cwd()}${COLORS.reset}`);
|
|
18
|
+
console.log(`${COLORS.dim}Type ${COLORS.bold}/help${COLORS.reset}${COLORS.dim} for commands, ${COLORS.bold}/quit${COLORS.reset}${COLORS.dim} to exit${COLORS.reset}\n`);
|
|
19
|
+
}
|
|
20
|
+
function printHelp() {
|
|
21
|
+
console.log(`
|
|
22
|
+
${COLORS.bold}Commands:${COLORS.reset}
|
|
23
|
+
${COLORS.cyan}/help${COLORS.reset} Show this help
|
|
24
|
+
${COLORS.cyan}/model <id>${COLORS.reset} Switch model (e.g. /model openai/gpt-4o)
|
|
25
|
+
${COLORS.cyan}/models${COLORS.reset} List available models
|
|
26
|
+
${COLORS.cyan}/clear${COLORS.reset} Clear conversation history
|
|
27
|
+
${COLORS.cyan}/quit${COLORS.reset} Exit
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
export async function cliChatCommand(options) {
|
|
31
|
+
const apiKey = process.env.OPENROUTER_API_KEY;
|
|
32
|
+
if (!apiKey) {
|
|
33
|
+
console.error('OPENROUTER_API_KEY is not set. Get one at https://openrouter.ai/keys');
|
|
34
|
+
console.error('Add it to your .env file or export it: export OPENROUTER_API_KEY=sk-or-...');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
let model = options.model ?? process.env.OPENROUTER_DEFAULT_MODEL ?? DEFAULT_MODEL;
|
|
38
|
+
const sessionManager = new SessionManager();
|
|
39
|
+
const sessionId = `cli-${Date.now()}`;
|
|
40
|
+
// Single prompt mode (non-interactive): expxagents cli -p "do something"
|
|
41
|
+
if (options.prompt) {
|
|
42
|
+
const agent = new AgentRunner({
|
|
43
|
+
prompt: options.prompt,
|
|
44
|
+
cwd: process.cwd(),
|
|
45
|
+
apiKey,
|
|
46
|
+
model,
|
|
47
|
+
sessionId,
|
|
48
|
+
sessionManager,
|
|
49
|
+
onChunk: (chunk) => process.stdout.write(chunk),
|
|
50
|
+
onToolCall: (tool, args) => {
|
|
51
|
+
const summary = typeof args === 'object' && args !== null
|
|
52
|
+
? Object.entries(args).map(([k, v]) => `${k}=${String(v).slice(0, 60)}`).join(', ')
|
|
53
|
+
: String(args).slice(0, 80);
|
|
54
|
+
process.stderr.write(`${COLORS.dim}[${tool}] ${summary}${COLORS.reset}\n`);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
await agent.run();
|
|
59
|
+
console.log('');
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
console.error(`\nError: ${err instanceof Error ? err.message : String(err)}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// Interactive REPL mode
|
|
68
|
+
printBanner(model);
|
|
69
|
+
const rl = readline.createInterface({
|
|
70
|
+
input: process.stdin,
|
|
71
|
+
output: process.stdout,
|
|
72
|
+
prompt: `${COLORS.green}>${COLORS.reset} `,
|
|
73
|
+
});
|
|
74
|
+
rl.prompt();
|
|
75
|
+
rl.on('line', async (line) => {
|
|
76
|
+
const input = line.trim();
|
|
77
|
+
if (!input) {
|
|
78
|
+
rl.prompt();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Handle slash commands
|
|
82
|
+
if (input.startsWith('/')) {
|
|
83
|
+
const [cmd, ...args] = input.split(' ');
|
|
84
|
+
switch (cmd) {
|
|
85
|
+
case '/quit':
|
|
86
|
+
case '/exit':
|
|
87
|
+
case '/q':
|
|
88
|
+
console.log(`${COLORS.dim}Goodbye!${COLORS.reset}`);
|
|
89
|
+
process.exit(0);
|
|
90
|
+
break;
|
|
91
|
+
case '/help':
|
|
92
|
+
printHelp();
|
|
93
|
+
rl.prompt();
|
|
94
|
+
return;
|
|
95
|
+
case '/models':
|
|
96
|
+
console.log(`\n${COLORS.bold}Available models:${COLORS.reset}`);
|
|
97
|
+
for (const m of SUPPORTED_MODELS) {
|
|
98
|
+
const active = m.id === model ? ` ${COLORS.green}(active)${COLORS.reset}` : '';
|
|
99
|
+
console.log(` ${COLORS.cyan}${m.id}${COLORS.reset} — ${m.name} (${(m.contextWindow / 1000).toFixed(0)}K ctx)${active}`);
|
|
100
|
+
}
|
|
101
|
+
console.log('');
|
|
102
|
+
rl.prompt();
|
|
103
|
+
return;
|
|
104
|
+
case '/model':
|
|
105
|
+
if (!args[0]) {
|
|
106
|
+
console.log(`Current model: ${COLORS.yellow}${model}${COLORS.reset}`);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
model = args[0];
|
|
110
|
+
const info = SUPPORTED_MODELS.find(m => m.id === model);
|
|
111
|
+
if (info) {
|
|
112
|
+
console.log(`${COLORS.green}Switched to ${info.name}${COLORS.reset}`);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
console.log(`${COLORS.yellow}Warning: "${model}" is not in curated list. Tool use may not work.${COLORS.reset}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
rl.prompt();
|
|
119
|
+
return;
|
|
120
|
+
case '/clear':
|
|
121
|
+
sessionManager.create(sessionId, process.cwd());
|
|
122
|
+
console.log(`${COLORS.dim}Conversation cleared.${COLORS.reset}`);
|
|
123
|
+
rl.prompt();
|
|
124
|
+
return;
|
|
125
|
+
default:
|
|
126
|
+
console.log(`${COLORS.dim}Unknown command: ${cmd}. Type /help for commands.${COLORS.reset}`);
|
|
127
|
+
rl.prompt();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Send to agent
|
|
132
|
+
console.log('');
|
|
133
|
+
const agent = new AgentRunner({
|
|
134
|
+
prompt: input,
|
|
135
|
+
cwd: process.cwd(),
|
|
136
|
+
apiKey,
|
|
137
|
+
model,
|
|
138
|
+
sessionId,
|
|
139
|
+
sessionManager,
|
|
140
|
+
onChunk: (chunk) => process.stdout.write(chunk),
|
|
141
|
+
onToolCall: (tool, args) => {
|
|
142
|
+
const summary = typeof args === 'object' && args !== null
|
|
143
|
+
? Object.entries(args).map(([k, v]) => `${k}=${String(v).slice(0, 60)}`).join(', ')
|
|
144
|
+
: String(args).slice(0, 80);
|
|
145
|
+
process.stderr.write(`${COLORS.dim}[${tool}] ${summary}${COLORS.reset}\n`);
|
|
146
|
+
},
|
|
147
|
+
onAskUser: async (question) => {
|
|
148
|
+
return new Promise((resolve) => {
|
|
149
|
+
rl.question(`${COLORS.magenta}Agent asks:${COLORS.reset} ${question}\n${COLORS.green}>${COLORS.reset} `, resolve);
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
try {
|
|
154
|
+
await agent.run();
|
|
155
|
+
console.log('\n');
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
console.error(`\n${COLORS.yellow}Error: ${err instanceof Error ? err.message : String(err)}${COLORS.reset}\n`);
|
|
159
|
+
}
|
|
160
|
+
rl.prompt();
|
|
161
|
+
});
|
|
162
|
+
rl.on('close', () => {
|
|
163
|
+
console.log(`\n${COLORS.dim}Goodbye!${COLORS.reset}`);
|
|
164
|
+
process.exit(0);
|
|
165
|
+
});
|
|
166
|
+
}
|
package/dist/cli/src/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { searchCommand } from './commands/search.js';
|
|
|
26
26
|
import { infoCommand } from './commands/info.js';
|
|
27
27
|
import { outdatedCommand } from './commands/outdated.js';
|
|
28
28
|
import { updateCommand } from './commands/update.js';
|
|
29
|
+
import { cliChatCommand } from './commands/cli-chat.js';
|
|
29
30
|
import { getVersion } from './utils/version.js';
|
|
30
31
|
const program = new Command();
|
|
31
32
|
program
|
|
@@ -114,4 +115,10 @@ program.addCommand(searchCommand);
|
|
|
114
115
|
program.addCommand(infoCommand);
|
|
115
116
|
program.addCommand(outdatedCommand);
|
|
116
117
|
program.addCommand(updateCommand);
|
|
118
|
+
program
|
|
119
|
+
.command('cli [prompt]')
|
|
120
|
+
.description('Interactive AI coding agent via OpenRouter (like claude/opencode)')
|
|
121
|
+
.option('-m, --model <model>', 'Model to use (e.g. anthropic/claude-sonnet-4)')
|
|
122
|
+
.option('-p, --prompt <prompt>', 'Single prompt mode (non-interactive)')
|
|
123
|
+
.action((prompt, options) => cliChatCommand({ model: options.model, prompt: prompt ?? options.prompt }));
|
|
117
124
|
program.parse();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,cAAc,E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