@mmmbuto/nexuscli 0.9.5 → 0.9.7-termux
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/README.md +28 -5
- package/lib/cli/engines.js +51 -2
- package/lib/config/manager.js +5 -0
- package/lib/config/models.js +28 -0
- package/lib/server/lib/cli-wrapper.js +167 -0
- package/lib/server/lib/output-parser.js +132 -0
- package/lib/server/lib/pty-adapter.js +81 -0
- package/lib/server/middleware/rate-limit.js +1 -1
- package/lib/server/models/Message.js +1 -1
- package/lib/server/routes/models.js +2 -0
- package/lib/server/routes/qwen.js +240 -0
- package/lib/server/routes/sessions.js +13 -1
- package/lib/server/server.js +7 -4
- package/lib/server/services/cli-loader.js +83 -3
- package/lib/server/services/context-bridge.js +4 -2
- package/lib/server/services/qwen-output-parser.js +289 -0
- package/lib/server/services/qwen-wrapper.js +251 -0
- package/lib/server/services/session-importer.js +35 -2
- package/lib/server/services/session-manager.js +32 -5
- package/lib/server/tests/history-sync.test.js +11 -2
- package/lib/server/tests/integration-session-sync.test.js +40 -8
- package/lib/server/tests/integration.test.js +33 -16
- package/lib/server/tests/performance.test.js +16 -9
- package/lib/server/tests/services.test.js +17 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
## Overview
|
|
10
10
|
|
|
11
|
-
NexusCLI is a lightweight, Termux-first AI cockpit to orchestrate Claude Code, Codex CLI, and
|
|
11
|
+
NexusCLI is a lightweight, Termux-first AI cockpit to orchestrate Claude Code, Codex CLI, Gemini CLI, and Qwen Code CLI from a single web/terminal UI. It supports live interrupts, native session resume, and voice input with HTTPS auto-setup for remote devices.
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
@@ -27,7 +27,19 @@ NexusCLI is a lightweight, Termux-first AI cockpit to orchestrate Claude Code, C
|
|
|
27
27
|
|
|
28
28
|
---
|
|
29
29
|
|
|
30
|
-
## Highlights (v0.9.
|
|
30
|
+
## Highlights (v0.9.7-termux, testing)
|
|
31
|
+
|
|
32
|
+
- **QWEN Engine**: Integrated Qwen Code CLI with streaming statusbar events
|
|
33
|
+
- **QWEN Models**: `coder-model` and `vision-model` available in UI
|
|
34
|
+
- **Session Import**: Qwen sessions indexed alongside Claude/Codex/Gemini
|
|
35
|
+
|
|
36
|
+
### v0.9.6
|
|
37
|
+
|
|
38
|
+
- **Jobs Runner Restored**: `jobs` route works again after cleanup regression
|
|
39
|
+
- **Termux-Safe Execution**: no hardcoded `/bin` or `/usr/bin` paths for job tools
|
|
40
|
+
- **Cleaner Errors**: job SSE errors now display correctly in UI
|
|
41
|
+
|
|
42
|
+
### v0.9.5
|
|
31
43
|
|
|
32
44
|
- **GPT-5.2 Codex**: Added latest frontier agentic coding model as default
|
|
33
45
|
- Updated Codex model catalog to match latest OpenAI CLI
|
|
@@ -41,7 +53,7 @@ NexusCLI is a lightweight, Termux-first AI cockpit to orchestrate Claude Code, C
|
|
|
41
53
|
|
|
42
54
|
## Features
|
|
43
55
|
|
|
44
|
-
- Multi-engine support (Claude, Codex, Gemini)
|
|
56
|
+
- Multi-engine support (Claude, Codex, Gemini, Qwen)
|
|
45
57
|
- Session continuity with explicit workspace selection
|
|
46
58
|
- SSE streaming responses
|
|
47
59
|
- Model selector with think-mode toggle and default model preference
|
|
@@ -57,8 +69,9 @@ NexusCLI is a lightweight, Termux-first AI cockpit to orchestrate Claude Code, C
|
|
|
57
69
|
|--------|--------|----------|
|
|
58
70
|
| **Claude (native)** | Opus 4.5, Sonnet 4.5, Haiku 4.5 | Anthropic |
|
|
59
71
|
| **Claude-compatible** | DeepSeek (deepseek-*), GLM-4.6 | DeepSeek, Z.ai |
|
|
60
|
-
| **Codex** | GPT-5.
|
|
72
|
+
| **Codex** | GPT-5.2 Codex, GPT-5.2, GPT-5.1 Codex (Mini/Max), GPT-5.1 | OpenAI |
|
|
61
73
|
| **Gemini** | Gemini 3 Pro Preview, Gemini 3 Flash Preview | Google |
|
|
74
|
+
| **Qwen** | coder-model, vision-model | Alibaba |
|
|
62
75
|
|
|
63
76
|
---
|
|
64
77
|
|
|
@@ -72,6 +85,13 @@ npm install -g @mmmbuto/nexuscli
|
|
|
72
85
|
npm install -g github:DioNanos/nexuscli
|
|
73
86
|
```
|
|
74
87
|
|
|
88
|
+
### Release Channels
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Testing channel
|
|
92
|
+
npm install -g @mmmbuto/nexuscli@testing
|
|
93
|
+
```
|
|
94
|
+
|
|
75
95
|
## Setup
|
|
76
96
|
|
|
77
97
|
```bash
|
|
@@ -126,7 +146,7 @@ nexuscli api set openrouter <key> # Future: Multi-provider gateway
|
|
|
126
146
|
nexuscli api delete <provider> # Remove key
|
|
127
147
|
```
|
|
128
148
|
|
|
129
|
-
> **Note**: Claude/Codex/Gemini keys are managed by their respective CLIs.
|
|
149
|
+
> **Note**: Claude/Codex/Gemini/Qwen keys are managed by their respective CLIs.
|
|
130
150
|
> OpenAI key enables voice input via Whisper. HTTPS auto-generated for remote mic access.
|
|
131
151
|
|
|
132
152
|
---
|
|
@@ -138,6 +158,7 @@ nexuscli api delete <provider> # Remove key
|
|
|
138
158
|
- Claude Code CLI (`claude`)
|
|
139
159
|
- Codex CLI (`codex`)
|
|
140
160
|
- Gemini CLI (`gemini`)
|
|
161
|
+
- Qwen Code CLI (`qwen`)
|
|
141
162
|
|
|
142
163
|
---
|
|
143
164
|
|
|
@@ -171,9 +192,11 @@ It is a **research and learning tool**.
|
|
|
171
192
|
| `POST /api/v1/chat` | Claude | SSE streaming chat |
|
|
172
193
|
| `POST /api/v1/codex` | Codex | SSE streaming chat |
|
|
173
194
|
| `POST /api/v1/gemini` | Gemini | SSE streaming chat |
|
|
195
|
+
| `POST /api/v1/qwen` | Qwen | SSE streaming chat |
|
|
174
196
|
| `POST /api/v1/chat/interrupt` | Claude | Stop running generation |
|
|
175
197
|
| `POST /api/v1/codex/interrupt` | Codex | Stop running generation |
|
|
176
198
|
| `POST /api/v1/gemini/interrupt` | Gemini | Stop running generation |
|
|
199
|
+
| `POST /api/v1/qwen/interrupt` | Qwen | Stop running generation |
|
|
177
200
|
| `GET /api/v1/models` | All | List available models |
|
|
178
201
|
| `GET /api/v1/config` | - | Get user preferences (default model) |
|
|
179
202
|
| `GET /health` | - | Health check |
|
package/lib/cli/engines.js
CHANGED
|
@@ -18,7 +18,8 @@ function detectEngines() {
|
|
|
18
18
|
const engines = {
|
|
19
19
|
claude: { available: false, path: null, version: null },
|
|
20
20
|
codex: { available: false, path: null, version: null },
|
|
21
|
-
gemini: { available: false, path: null, version: null }
|
|
21
|
+
gemini: { available: false, path: null, version: null },
|
|
22
|
+
qwen: { available: false, path: null, version: null }
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
// Claude
|
|
@@ -42,6 +43,13 @@ function detectEngines() {
|
|
|
42
43
|
engines.gemini = { available: true, path: geminiPath, version: geminiVersion };
|
|
43
44
|
} catch {}
|
|
44
45
|
|
|
46
|
+
// Qwen
|
|
47
|
+
try {
|
|
48
|
+
const qwenPath = execSync('which qwen 2>/dev/null', { encoding: 'utf8' }).trim();
|
|
49
|
+
const qwenVersion = execSync('qwen --version 2>/dev/null', { encoding: 'utf8' }).trim().split('\n')[0];
|
|
50
|
+
engines.qwen = { available: true, path: qwenPath, version: qwenVersion };
|
|
51
|
+
} catch {}
|
|
52
|
+
|
|
45
53
|
return engines;
|
|
46
54
|
}
|
|
47
55
|
|
|
@@ -87,6 +95,16 @@ function listEngines() {
|
|
|
87
95
|
console.log(chalk.bold(`║ Gemini: ${chalk.gray('○ not installed')}`));
|
|
88
96
|
}
|
|
89
97
|
|
|
98
|
+
// Qwen
|
|
99
|
+
const qwenEnabled = config.engines?.qwen?.enabled === true;
|
|
100
|
+
if (detected.qwen.available) {
|
|
101
|
+
const status = qwenEnabled ? chalk.green('✓ enabled') : chalk.gray('○ disabled');
|
|
102
|
+
console.log(chalk.bold(`║ QWEN: ${status}`));
|
|
103
|
+
console.log(chalk.gray(`║ ${detected.qwen.version}`));
|
|
104
|
+
} else {
|
|
105
|
+
console.log(chalk.bold(`║ QWEN: ${chalk.gray('○ not installed')}`));
|
|
106
|
+
}
|
|
107
|
+
|
|
90
108
|
console.log(chalk.bold('╚═══════════════════════════════════════════╝'));
|
|
91
109
|
}
|
|
92
110
|
|
|
@@ -129,6 +147,17 @@ async function testEngine(engine) {
|
|
|
129
147
|
}
|
|
130
148
|
}
|
|
131
149
|
|
|
150
|
+
if (engine === 'qwen') {
|
|
151
|
+
try {
|
|
152
|
+
execSync('qwen --version', { stdio: 'inherit' });
|
|
153
|
+
console.log(chalk.green(` ✓ Qwen CLI is working`));
|
|
154
|
+
return true;
|
|
155
|
+
} catch {
|
|
156
|
+
console.log(chalk.red(` ✗ Qwen CLI not found`));
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
132
161
|
console.log(chalk.yellow(` Engine ${engine} not testable`));
|
|
133
162
|
return false;
|
|
134
163
|
}
|
|
@@ -149,10 +178,13 @@ async function addEngine() {
|
|
|
149
178
|
if (detected.gemini.available) {
|
|
150
179
|
choices.push({ name: `Gemini (${detected.gemini.version})`, value: 'gemini' });
|
|
151
180
|
}
|
|
181
|
+
if (detected.qwen.available) {
|
|
182
|
+
choices.push({ name: `QWEN (${detected.qwen.version})`, value: 'qwen' });
|
|
183
|
+
}
|
|
152
184
|
|
|
153
185
|
if (choices.length === 0) {
|
|
154
186
|
console.log(chalk.yellow(' No AI engines detected.'));
|
|
155
|
-
console.log(chalk.gray(' Install: claude, codex, or
|
|
187
|
+
console.log(chalk.gray(' Install: claude, codex, gemini, or qwen CLI'));
|
|
156
188
|
return;
|
|
157
189
|
}
|
|
158
190
|
|
|
@@ -206,6 +238,23 @@ async function addEngine() {
|
|
|
206
238
|
setConfigValue('engines.gemini.model', 'gemini-3-pro-preview');
|
|
207
239
|
console.log(chalk.green(` ✓ Gemini configured (gemini-3-pro-preview)`));
|
|
208
240
|
}
|
|
241
|
+
|
|
242
|
+
if (engine === 'qwen') {
|
|
243
|
+
const { model } = await inquirer.prompt([{
|
|
244
|
+
type: 'list',
|
|
245
|
+
name: 'model',
|
|
246
|
+
message: 'Default Qwen model:',
|
|
247
|
+
choices: [
|
|
248
|
+
{ name: 'Coder (default)', value: 'coder-model' },
|
|
249
|
+
{ name: 'Vision', value: 'vision-model' }
|
|
250
|
+
],
|
|
251
|
+
default: 'coder-model'
|
|
252
|
+
}]);
|
|
253
|
+
|
|
254
|
+
setConfigValue('engines.qwen.enabled', true);
|
|
255
|
+
setConfigValue('engines.qwen.model', model);
|
|
256
|
+
console.log(chalk.green(` ✓ QWEN configured (${model})`));
|
|
257
|
+
}
|
|
209
258
|
}
|
|
210
259
|
|
|
211
260
|
/**
|
package/lib/config/manager.js
CHANGED
package/lib/config/models.js
CHANGED
|
@@ -164,6 +164,34 @@ function getCliTools() {
|
|
|
164
164
|
}
|
|
165
165
|
]
|
|
166
166
|
}
|
|
167
|
+
,
|
|
168
|
+
|
|
169
|
+
// ============================================================
|
|
170
|
+
// QWEN - Qwen Code CLI (Termux fork)
|
|
171
|
+
// ============================================================
|
|
172
|
+
'qwen': {
|
|
173
|
+
name: 'QWEN',
|
|
174
|
+
icon: 'Cpu',
|
|
175
|
+
enabled: true,
|
|
176
|
+
endpoint: '/api/v1/qwen',
|
|
177
|
+
models: [
|
|
178
|
+
{
|
|
179
|
+
id: 'coder-model',
|
|
180
|
+
name: 'coder-model',
|
|
181
|
+
label: 'Qwen Coder',
|
|
182
|
+
description: '🔧 Default Qwen Coder model',
|
|
183
|
+
category: 'qwen',
|
|
184
|
+
default: true
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
id: 'vision-model',
|
|
188
|
+
name: 'vision-model',
|
|
189
|
+
label: 'Qwen Vision',
|
|
190
|
+
description: '👁️ Vision-capable model',
|
|
191
|
+
category: 'qwen'
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
}
|
|
167
195
|
};
|
|
168
196
|
}
|
|
169
197
|
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const pty = require('./pty-adapter');
|
|
2
|
+
const OutputParser = require('./output-parser');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* CLI Wrapper - Generic CLI tool execution (adapted from NexusChat claude-wrapper)
|
|
6
|
+
* Spawns PTY processes for any CLI tool (bash, git, docker, python, etc.)
|
|
7
|
+
* Streams output via SSE
|
|
8
|
+
*/
|
|
9
|
+
class CliWrapper {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.workspaceDir = options.workspaceDir || process.cwd();
|
|
12
|
+
this.activeJobs = new Map();
|
|
13
|
+
this.defaultShell = process.env.SHELL || 'bash';
|
|
14
|
+
this.defaultPython = 'python3';
|
|
15
|
+
this.defaultNode = process.execPath || 'node';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Execute command via PTY
|
|
20
|
+
* @param {Object} params - { jobId, tool, command, workingDir, timeout, onStatus }
|
|
21
|
+
* @returns {Promise<Object>} - { exitCode, stdout, stderr, duration }
|
|
22
|
+
*/
|
|
23
|
+
async execute({ jobId, tool = 'bash', command, workingDir, timeout = 30000, onStatus }) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const parser = new OutputParser();
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
|
|
28
|
+
// Determine shell command
|
|
29
|
+
let shellCmd = this.defaultShell;
|
|
30
|
+
let args = ['-c', command];
|
|
31
|
+
|
|
32
|
+
// Tool-specific handling
|
|
33
|
+
if (tool === 'bash') {
|
|
34
|
+
shellCmd = this.defaultShell;
|
|
35
|
+
args = ['-c', command];
|
|
36
|
+
} else if (tool === 'python') {
|
|
37
|
+
shellCmd = this.defaultPython;
|
|
38
|
+
args = ['-c', command];
|
|
39
|
+
} else if (tool === 'node') {
|
|
40
|
+
shellCmd = this.defaultNode;
|
|
41
|
+
args = ['-e', command];
|
|
42
|
+
} else {
|
|
43
|
+
// Generic: assume tool is in PATH
|
|
44
|
+
shellCmd = tool;
|
|
45
|
+
args = command.split(' ');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
console.log(`[CliWrapper] Executing: ${tool} - ${command.substring(0, 50)}...`);
|
|
49
|
+
console.log(`[CliWrapper] Working dir: ${workingDir || this.workspaceDir}`);
|
|
50
|
+
|
|
51
|
+
// Spawn PTY process
|
|
52
|
+
let ptyProcess;
|
|
53
|
+
try {
|
|
54
|
+
ptyProcess = pty.spawn(shellCmd, args, {
|
|
55
|
+
name: 'xterm-color',
|
|
56
|
+
cols: 80,
|
|
57
|
+
rows: 30,
|
|
58
|
+
cwd: workingDir || this.workspaceDir,
|
|
59
|
+
env: process.env,
|
|
60
|
+
});
|
|
61
|
+
} catch (err) {
|
|
62
|
+
return reject(err);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.activeJobs.set(jobId, ptyProcess);
|
|
66
|
+
|
|
67
|
+
let stdout = '';
|
|
68
|
+
let stderr = '';
|
|
69
|
+
|
|
70
|
+
// Handle timeout
|
|
71
|
+
const timer = setTimeout(() => {
|
|
72
|
+
console.log(`[CliWrapper] Job ${jobId} timeout`);
|
|
73
|
+
ptyProcess.kill('SIGTERM');
|
|
74
|
+
|
|
75
|
+
if (onStatus) {
|
|
76
|
+
onStatus({
|
|
77
|
+
type: 'error',
|
|
78
|
+
error: 'Command timeout exceeded',
|
|
79
|
+
timeout
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, timeout);
|
|
83
|
+
|
|
84
|
+
// Handle process errors
|
|
85
|
+
if (typeof ptyProcess.on === 'function') {
|
|
86
|
+
ptyProcess.on('error', (err) => {
|
|
87
|
+
console.error('[CliWrapper] Spawn error:', err);
|
|
88
|
+
reject(err);
|
|
89
|
+
});
|
|
90
|
+
} else if (typeof ptyProcess.onError === 'function') {
|
|
91
|
+
ptyProcess.onError((err) => {
|
|
92
|
+
console.error('[CliWrapper] Spawn error:', err);
|
|
93
|
+
reject(err);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Handle output
|
|
98
|
+
ptyProcess.onData((data) => {
|
|
99
|
+
stdout += data;
|
|
100
|
+
|
|
101
|
+
// Parse output and emit status events
|
|
102
|
+
if (onStatus) {
|
|
103
|
+
try {
|
|
104
|
+
const events = parser.parse(data);
|
|
105
|
+
events.forEach(event => {
|
|
106
|
+
onStatus(event);
|
|
107
|
+
});
|
|
108
|
+
} catch (parseError) {
|
|
109
|
+
console.error('[CliWrapper] Parser error:', parseError);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Handle exit
|
|
115
|
+
ptyProcess.onExit(({ exitCode }) => {
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
this.activeJobs.delete(jobId);
|
|
118
|
+
|
|
119
|
+
const duration = Date.now() - startTime;
|
|
120
|
+
|
|
121
|
+
// Clean ANSI escape codes
|
|
122
|
+
const cleanStdout = stdout
|
|
123
|
+
.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, '') // ANSI codes
|
|
124
|
+
.replace(/\x1B\[\?[0-9;]*[a-zA-Z]/g, '') // Private modes
|
|
125
|
+
.trim();
|
|
126
|
+
|
|
127
|
+
console.log(`[CliWrapper] Job ${jobId} exit: ${exitCode} (${duration}ms)`);
|
|
128
|
+
|
|
129
|
+
if (exitCode !== 0) {
|
|
130
|
+
// Extract stderr (if any)
|
|
131
|
+
stderr = cleanStdout; // In PTY mode, stderr is mixed with stdout
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
resolve({
|
|
135
|
+
exitCode,
|
|
136
|
+
stdout: cleanStdout,
|
|
137
|
+
stderr,
|
|
138
|
+
duration
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Kill running job
|
|
146
|
+
* @param {string} jobId - Job ID
|
|
147
|
+
*/
|
|
148
|
+
kill(jobId) {
|
|
149
|
+
const ptyProcess = this.activeJobs.get(jobId);
|
|
150
|
+
if (ptyProcess) {
|
|
151
|
+
ptyProcess.kill('SIGTERM');
|
|
152
|
+
this.activeJobs.delete(jobId);
|
|
153
|
+
console.log(`[CliWrapper] Killed job ${jobId}`);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Get active job count
|
|
161
|
+
*/
|
|
162
|
+
getActiveJobCount() {
|
|
163
|
+
return this.activeJobs.size;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
module.exports = CliWrapper;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OutputParser - Parse CLI stdout/stderr into structured events
|
|
3
|
+
* Adapted from NexusChat output-parser.js
|
|
4
|
+
*/
|
|
5
|
+
class OutputParser {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.state = 'idle';
|
|
8
|
+
this.buffer = '';
|
|
9
|
+
this.lineBuffer = '';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Regex patterns for detecting CLI output markers
|
|
14
|
+
*/
|
|
15
|
+
static PATTERNS = {
|
|
16
|
+
// Tool execution patterns (generic)
|
|
17
|
+
toolExecution: /(?:Running|Executing)\s+(\w+)(?:\s+(?:command|tool))?:\s*(.+)/i,
|
|
18
|
+
|
|
19
|
+
// Common CLI patterns
|
|
20
|
+
errorPattern: /(?:Error|ERROR|Failed|FAILED|Exception):\s*(.+)/i,
|
|
21
|
+
warningPattern: /(?:Warning|WARNING|warn):\s*(.+)/i,
|
|
22
|
+
|
|
23
|
+
// ANSI escape codes
|
|
24
|
+
ansiCodes: /\x1B\[[0-9;]*[a-zA-Z]/g,
|
|
25
|
+
ansiPrivate: /\x1B\[\?[0-9;]*[a-zA-Z]/g,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parse chunk of stdout and return array of events
|
|
30
|
+
* @param {string} chunk - Raw stdout chunk from PTY
|
|
31
|
+
* @returns {Array} Array of event objects
|
|
32
|
+
*/
|
|
33
|
+
parse(chunk) {
|
|
34
|
+
const events = [];
|
|
35
|
+
|
|
36
|
+
// Add to buffer
|
|
37
|
+
this.buffer += chunk;
|
|
38
|
+
this.lineBuffer += chunk;
|
|
39
|
+
|
|
40
|
+
// Process line by line
|
|
41
|
+
const lines = this.lineBuffer.split('\n');
|
|
42
|
+
this.lineBuffer = lines.pop(); // Keep incomplete line
|
|
43
|
+
|
|
44
|
+
for (const line of lines) {
|
|
45
|
+
const lineEvents = this.parseLine(line);
|
|
46
|
+
events.push(...lineEvents);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Also emit raw output chunks
|
|
50
|
+
const cleanChunk = this.cleanAnsi(chunk);
|
|
51
|
+
if (cleanChunk && cleanChunk.trim()) {
|
|
52
|
+
events.push({
|
|
53
|
+
type: 'output_chunk',
|
|
54
|
+
stream: 'stdout',
|
|
55
|
+
text: cleanChunk,
|
|
56
|
+
isIncremental: true,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return events;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Parse single line
|
|
65
|
+
* @param {string} line - Single line of output
|
|
66
|
+
* @returns {Array} Events from this line
|
|
67
|
+
*/
|
|
68
|
+
parseLine(line) {
|
|
69
|
+
const events = [];
|
|
70
|
+
const cleanLine = this.cleanAnsi(line);
|
|
71
|
+
|
|
72
|
+
// Check for tool execution
|
|
73
|
+
const toolMatch = cleanLine.match(OutputParser.PATTERNS.toolExecution);
|
|
74
|
+
if (toolMatch) {
|
|
75
|
+
const [, tool, command] = toolMatch;
|
|
76
|
+
events.push({
|
|
77
|
+
type: 'status',
|
|
78
|
+
category: 'tool',
|
|
79
|
+
tool,
|
|
80
|
+
message: `${tool}: ${command.substring(0, 60)}${command.length > 60 ? '...' : ''}`,
|
|
81
|
+
icon: '🔧',
|
|
82
|
+
timestamp: new Date().toISOString(),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Check for errors
|
|
87
|
+
if (OutputParser.PATTERNS.errorPattern.test(cleanLine)) {
|
|
88
|
+
const [, errorMsg] = cleanLine.match(OutputParser.PATTERNS.errorPattern);
|
|
89
|
+
events.push({
|
|
90
|
+
type: 'status',
|
|
91
|
+
category: 'warning',
|
|
92
|
+
message: `Error: ${errorMsg}`,
|
|
93
|
+
icon: '⚠️',
|
|
94
|
+
timestamp: new Date().toISOString(),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Check for warnings
|
|
99
|
+
if (OutputParser.PATTERNS.warningPattern.test(cleanLine)) {
|
|
100
|
+
const [, warnMsg] = cleanLine.match(OutputParser.PATTERNS.warningPattern);
|
|
101
|
+
events.push({
|
|
102
|
+
type: 'status',
|
|
103
|
+
category: 'warning',
|
|
104
|
+
message: `Warning: ${warnMsg}`,
|
|
105
|
+
icon: '⚠️',
|
|
106
|
+
timestamp: new Date().toISOString(),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return events;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Clean ANSI escape codes from text
|
|
115
|
+
*/
|
|
116
|
+
cleanAnsi(text) {
|
|
117
|
+
return text
|
|
118
|
+
.replace(OutputParser.PATTERNS.ansiCodes, '')
|
|
119
|
+
.replace(OutputParser.PATTERNS.ansiPrivate, '');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Reset parser state
|
|
124
|
+
*/
|
|
125
|
+
reset() {
|
|
126
|
+
this.state = 'idle';
|
|
127
|
+
this.buffer = '';
|
|
128
|
+
this.lineBuffer = '';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = OutputParser;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PTY Adapter for NexusCLI (Termux)
|
|
3
|
+
* Provides node-pty-like interface using child_process.spawn
|
|
4
|
+
* Termux-only: no native node-pty compilation needed
|
|
5
|
+
*
|
|
6
|
+
* @version 0.5.0 - Added stdin support for interrupt (ESC key)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { spawn: cpSpawn } = require('child_process');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Spawn a process with node-pty-like interface
|
|
13
|
+
* @param {string} command - Command to spawn
|
|
14
|
+
* @param {string[]} args - Arguments
|
|
15
|
+
* @param {Object} options - Spawn options (cwd, env)
|
|
16
|
+
* @returns {Object} PTY-like interface with onData, onExit, kill
|
|
17
|
+
*/
|
|
18
|
+
function spawn(command, args, options = {}) {
|
|
19
|
+
const proc = cpSpawn(command, args, {
|
|
20
|
+
cwd: options.cwd,
|
|
21
|
+
env: options.env,
|
|
22
|
+
shell: false,
|
|
23
|
+
stdio: ['pipe', 'pipe', 'pipe'], // stdin enabled for interrupt support
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const dataHandlers = [];
|
|
27
|
+
const exitHandlers = [];
|
|
28
|
+
const errorHandlers = [];
|
|
29
|
+
|
|
30
|
+
proc.stdout.on('data', (buf) => {
|
|
31
|
+
const data = buf.toString();
|
|
32
|
+
console.log('[PTY-Adapter] stdout:', data.substring(0, 200));
|
|
33
|
+
dataHandlers.forEach((fn) => fn(data));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
proc.stderr.on('data', (buf) => {
|
|
37
|
+
const data = buf.toString();
|
|
38
|
+
console.log('[PTY-Adapter] stderr:', data.substring(0, 200));
|
|
39
|
+
dataHandlers.forEach((fn) => fn(data));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
proc.on('close', (code) => {
|
|
43
|
+
exitHandlers.forEach((fn) => fn({ exitCode: code ?? 0 }));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
proc.on('error', (err) => {
|
|
47
|
+
console.error('[PTY-Adapter] Error:', err.message);
|
|
48
|
+
errorHandlers.forEach((fn) => fn(err));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
onData: (fn) => dataHandlers.push(fn),
|
|
53
|
+
onExit: (fn) => exitHandlers.push(fn),
|
|
54
|
+
onError: (fn) => errorHandlers.push(fn),
|
|
55
|
+
write: (data) => proc.stdin?.writable && proc.stdin.write(data),
|
|
56
|
+
/**
|
|
57
|
+
* Send ESC key (0x1B) to interrupt CLI
|
|
58
|
+
* Used to gracefully stop Claude/Gemini CLI execution
|
|
59
|
+
* @returns {boolean} true if ESC was sent successfully
|
|
60
|
+
*/
|
|
61
|
+
sendEsc: () => {
|
|
62
|
+
if (proc.stdin?.writable) {
|
|
63
|
+
proc.stdin.write('\x1B');
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
},
|
|
68
|
+
kill: (signal = 'SIGTERM') => proc.kill(signal),
|
|
69
|
+
pid: proc.pid,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Check if native PTY is available
|
|
75
|
+
* Always returns false on Termux (we use spawn adapter)
|
|
76
|
+
*/
|
|
77
|
+
function isPtyAvailable() {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = { spawn, isPtyAvailable };
|
|
@@ -10,7 +10,7 @@ const rateLimit = require('express-rate-limit');
|
|
|
10
10
|
/**
|
|
11
11
|
* Chat endpoints rate limiter
|
|
12
12
|
* - 10 requests per minute per user
|
|
13
|
-
* - Applies to: /api/v1/chat, /api/v1/codex, /api/v1/gemini
|
|
13
|
+
* - Applies to: /api/v1/chat, /api/v1/codex, /api/v1/gemini, /api/v1/qwen
|
|
14
14
|
*/
|
|
15
15
|
const chatRateLimiter = rateLimit({
|
|
16
16
|
windowMs: 60 * 1000, // 1 minute window
|
|
@@ -13,7 +13,7 @@ class Message {
|
|
|
13
13
|
* @param {string} content - Message content (markdown)
|
|
14
14
|
* @param {Object} metadata - Optional metadata
|
|
15
15
|
* @param {number} createdAt - Optional timestamp override
|
|
16
|
-
* @param {string} engine - Engine used ('claude' | 'codex')
|
|
16
|
+
* @param {string} engine - Engine used ('claude' | 'codex' | 'gemini' | 'qwen')
|
|
17
17
|
* @returns {Object} Created message
|
|
18
18
|
*/
|
|
19
19
|
static create(conversationId, role, content, metadata = null, createdAt = Date.now(), engine = 'claude') {
|
|
@@ -10,6 +10,7 @@ const { getCliTools } = require('../../config/models');
|
|
|
10
10
|
* - Claude: Opus 4.5, Sonnet 4.5, Haiku 4.5
|
|
11
11
|
* - Codex: GPT-5.1 variants
|
|
12
12
|
* - Gemini: Gemini 3 Pro Preview, Gemini 3 Flash Preview
|
|
13
|
+
* - Qwen: coder-model, vision-model
|
|
13
14
|
*/
|
|
14
15
|
router.get('/', (req, res) => {
|
|
15
16
|
try {
|
|
@@ -35,6 +36,7 @@ router.get('/:engine', (req, res) => {
|
|
|
35
36
|
if (normalizedEngine.includes('claude')) normalizedEngine = 'claude';
|
|
36
37
|
if (normalizedEngine.includes('codex') || normalizedEngine.includes('openai')) normalizedEngine = 'codex';
|
|
37
38
|
if (normalizedEngine.includes('gemini') || normalizedEngine.includes('google')) normalizedEngine = 'gemini';
|
|
39
|
+
if (normalizedEngine.includes('qwen')) normalizedEngine = 'qwen';
|
|
38
40
|
|
|
39
41
|
if (!cliTools[normalizedEngine]) {
|
|
40
42
|
return res.status(404).json({ error: `Engine not found: ${engine}` });
|