@mmmbuto/nexuscli 0.9.7004-termux → 0.10.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/CHANGELOG.md +84 -0
- package/README.md +89 -158
- package/bin/nexuscli.js +12 -0
- package/frontend/dist/assets/{index-D8XkscmI.js → index-Bztt9hew.js} +1704 -1704
- package/frontend/dist/assets/{index-CoLEGBO4.css → index-Dj7jz2fy.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/frontend/dist/sw.js +1 -1
- package/lib/cli/api.js +19 -1
- package/lib/cli/config.js +27 -5
- package/lib/cli/engines.js +84 -202
- package/lib/cli/init.js +56 -2
- package/lib/cli/model.js +17 -7
- package/lib/cli/start.js +37 -24
- package/lib/cli/stop.js +12 -41
- package/lib/cli/update.js +28 -0
- package/lib/cli/workspaces.js +4 -0
- package/lib/config/manager.js +112 -8
- package/lib/config/models.js +388 -192
- package/lib/server/db/migrations/001_ultra_light_schema.sql +1 -1
- package/lib/server/db/migrations/006_runtime_lane_tracking.sql +79 -0
- package/lib/server/lib/getPty.js +51 -0
- package/lib/server/lib/pty-adapter.js +101 -57
- package/lib/server/lib/pty-provider.js +63 -0
- package/lib/server/lib/pty-utils-loader.js +136 -0
- package/lib/server/middleware/auth.js +27 -4
- package/lib/server/models/Conversation.js +7 -3
- package/lib/server/models/Message.js +29 -5
- package/lib/server/routes/chat.js +27 -4
- package/lib/server/routes/codex.js +35 -8
- package/lib/server/routes/config.js +9 -1
- package/lib/server/routes/gemini.js +24 -5
- package/lib/server/routes/jobs.js +15 -156
- package/lib/server/routes/models.js +12 -10
- package/lib/server/routes/qwen.js +26 -7
- package/lib/server/routes/runtimes.js +68 -0
- package/lib/server/server.js +3 -0
- package/lib/server/services/claude-wrapper.js +60 -62
- package/lib/server/services/cli-loader.js +1 -1
- package/lib/server/services/codex-wrapper.js +79 -10
- package/lib/server/services/gemini-wrapper.js +9 -4
- package/lib/server/services/job-runner.js +156 -0
- package/lib/server/services/qwen-wrapper.js +26 -11
- package/lib/server/services/runtime-manager.js +467 -0
- package/lib/server/services/session-importer.js +6 -1
- package/lib/server/services/session-manager.js +56 -14
- package/lib/server/services/workspace-manager.js +121 -0
- package/lib/server/tests/integration.test.js +12 -0
- package/lib/server/tests/runtime-manager.test.js +46 -0
- package/lib/server/tests/runtime-persistence.test.js +97 -0
- package/lib/setup/postinstall-pty-check.js +183 -0
- package/lib/setup/postinstall.js +60 -41
- package/lib/utils/restart-warning.js +18 -0
- package/lib/utils/server.js +88 -0
- package/lib/utils/termux.js +1 -1
- package/lib/utils/update-check.js +153 -0
- package/lib/utils/update-runner.js +62 -0
- package/package.json +6 -5
|
@@ -11,7 +11,7 @@ const pty = require('../lib/pty-adapter');
|
|
|
11
11
|
const QwenOutputParser = require('./qwen-output-parser');
|
|
12
12
|
const BaseCliWrapper = require('./base-cli-wrapper');
|
|
13
13
|
|
|
14
|
-
const DEFAULT_MODEL = 'coder-
|
|
14
|
+
const DEFAULT_MODEL = 'qwen3-coder-plus';
|
|
15
15
|
const CLI_TIMEOUT_MS = 600000; // 10 minutes
|
|
16
16
|
|
|
17
17
|
const DANGEROUS_PATTERNS = [
|
|
@@ -85,7 +85,9 @@ class QwenWrapper extends BaseCliWrapper {
|
|
|
85
85
|
workspacePath,
|
|
86
86
|
includeDirectories = [],
|
|
87
87
|
onStatus,
|
|
88
|
-
processId: processIdOverride
|
|
88
|
+
processId: processIdOverride,
|
|
89
|
+
runtimeCommand,
|
|
90
|
+
envOverrides = {}
|
|
89
91
|
}) {
|
|
90
92
|
return new Promise((resolve, reject) => {
|
|
91
93
|
const parser = new QwenOutputParser();
|
|
@@ -125,7 +127,8 @@ class QwenWrapper extends BaseCliWrapper {
|
|
|
125
127
|
|
|
126
128
|
let ptyProcess;
|
|
127
129
|
try {
|
|
128
|
-
|
|
130
|
+
const command = runtimeCommand || this.qwenPath;
|
|
131
|
+
ptyProcess = pty.spawn(command, args, {
|
|
129
132
|
name: 'xterm-color',
|
|
130
133
|
cols: 120,
|
|
131
134
|
rows: 40,
|
|
@@ -135,6 +138,7 @@ class QwenWrapper extends BaseCliWrapper {
|
|
|
135
138
|
QWEN_CODE_MODEL: resolvedModel,
|
|
136
139
|
QWEN_MODEL: resolvedModel,
|
|
137
140
|
TERM: 'xterm-256color',
|
|
141
|
+
...envOverrides,
|
|
138
142
|
}
|
|
139
143
|
});
|
|
140
144
|
} catch (spawnError) {
|
|
@@ -227,10 +231,11 @@ class QwenWrapper extends BaseCliWrapper {
|
|
|
227
231
|
});
|
|
228
232
|
}
|
|
229
233
|
|
|
230
|
-
async isAvailable() {
|
|
234
|
+
async isAvailable(runtimeCommand) {
|
|
231
235
|
return new Promise((resolve) => {
|
|
232
236
|
const { exec } = require('child_process');
|
|
233
|
-
|
|
237
|
+
const command = runtimeCommand || this.qwenPath;
|
|
238
|
+
exec(`${command} --version`, { timeout: 5000 }, (error, stdout) => {
|
|
234
239
|
if (error) {
|
|
235
240
|
console.log('[QwenWrapper] CLI not available:', error.message);
|
|
236
241
|
resolve(false);
|
|
@@ -249,15 +254,25 @@ class QwenWrapper extends BaseCliWrapper {
|
|
|
249
254
|
getAvailableModels() {
|
|
250
255
|
return [
|
|
251
256
|
{
|
|
252
|
-
id: 'coder-
|
|
253
|
-
name: 'coder-
|
|
254
|
-
description: '
|
|
257
|
+
id: 'qwen3-coder-plus',
|
|
258
|
+
name: 'qwen3-coder-plus',
|
|
259
|
+
description: 'Qwen 3 Coder Plus',
|
|
255
260
|
default: true
|
|
256
261
|
},
|
|
257
262
|
{
|
|
258
|
-
id: '
|
|
259
|
-
name: '
|
|
260
|
-
description: '
|
|
263
|
+
id: 'qwen3-coder-next',
|
|
264
|
+
name: 'qwen3-coder-next',
|
|
265
|
+
description: 'Qwen 3 Coder Next'
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: 'qwen3.5-plus',
|
|
269
|
+
name: 'qwen3.5-plus',
|
|
270
|
+
description: 'Qwen 3.5 Plus'
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
id: 'qwen3-max',
|
|
274
|
+
name: 'qwen3-max',
|
|
275
|
+
description: 'Qwen 3 Max'
|
|
261
276
|
}
|
|
262
277
|
];
|
|
263
278
|
}
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
const { execFile } = require('child_process');
|
|
2
|
+
const { promisify } = require('util');
|
|
3
|
+
const { getCliTools, getModelById, getDefaultModelId } = require('../../config/models');
|
|
4
|
+
const { getConfig } = require('../../config/manager');
|
|
5
|
+
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
|
|
8
|
+
function isTermux() {
|
|
9
|
+
return (
|
|
10
|
+
process.env.PREFIX?.includes('com.termux') ||
|
|
11
|
+
process.env.TERMUX_VERSION !== undefined
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getPlatformId() {
|
|
16
|
+
if (isTermux()) return 'termux';
|
|
17
|
+
if (process.platform === 'darwin') return 'macos';
|
|
18
|
+
if (process.platform === 'linux') return 'linux';
|
|
19
|
+
return process.platform;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function npmCommand() {
|
|
23
|
+
if (isTermux()) return 'npm';
|
|
24
|
+
return 'npm';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function shellJoin(commands) {
|
|
28
|
+
return commands.filter(Boolean).join(' && ');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function buildProviderAuth({ providerId, dbKey, envVars = [], displayName, helpUrl, assignOpenAiKey = false }) {
|
|
32
|
+
return {
|
|
33
|
+
providerId,
|
|
34
|
+
dbKey,
|
|
35
|
+
envVars,
|
|
36
|
+
displayName,
|
|
37
|
+
helpUrl,
|
|
38
|
+
assignOpenAiKey,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function resolveClaudeCustomProfile(model) {
|
|
43
|
+
switch (model.id) {
|
|
44
|
+
case 'deepseek-reasoner':
|
|
45
|
+
case 'deepseek-chat':
|
|
46
|
+
return {
|
|
47
|
+
env: {
|
|
48
|
+
ANTHROPIC_BASE_URL: 'https://api.deepseek.com/anthropic',
|
|
49
|
+
ANTHROPIC_MODEL: model.id,
|
|
50
|
+
ANTHROPIC_SMALL_FAST_MODEL: 'deepseek-chat',
|
|
51
|
+
API_TIMEOUT_MS: '900000',
|
|
52
|
+
},
|
|
53
|
+
providerAuth: buildProviderAuth({
|
|
54
|
+
providerId: 'deepseek',
|
|
55
|
+
dbKey: 'deepseek',
|
|
56
|
+
envVars: ['DEEPSEEK_API_KEY'],
|
|
57
|
+
displayName: 'DeepSeek',
|
|
58
|
+
helpUrl: 'https://platform.deepseek.com/api_keys',
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
case 'glm-4.7':
|
|
62
|
+
case 'glm-5':
|
|
63
|
+
return {
|
|
64
|
+
env: {
|
|
65
|
+
ANTHROPIC_BASE_URL: 'https://api.z.ai/api/anthropic',
|
|
66
|
+
ANTHROPIC_MODEL: model.id === 'glm-5' ? 'GLM-5' : 'GLM-4.7',
|
|
67
|
+
ANTHROPIC_SMALL_FAST_MODEL: 'GLM-4.5-Air',
|
|
68
|
+
API_TIMEOUT_MS: '3000000',
|
|
69
|
+
},
|
|
70
|
+
providerAuth: buildProviderAuth({
|
|
71
|
+
providerId: 'zai',
|
|
72
|
+
dbKey: 'zai',
|
|
73
|
+
envVars: ['ZAI_API_KEY', 'ZAI_API_KEY_A', 'ZAI_API_KEY_P'],
|
|
74
|
+
displayName: 'Z.ai',
|
|
75
|
+
helpUrl: 'https://z.ai',
|
|
76
|
+
}),
|
|
77
|
+
};
|
|
78
|
+
case 'qwen3.5-plus':
|
|
79
|
+
case 'qwen3-max-2026-01-23':
|
|
80
|
+
case 'kimi-k2.5':
|
|
81
|
+
return {
|
|
82
|
+
env: {
|
|
83
|
+
ANTHROPIC_BASE_URL: 'https://coding-intl.dashscope.aliyuncs.com/apps/anthropic',
|
|
84
|
+
ANTHROPIC_MODEL: model.id,
|
|
85
|
+
ANTHROPIC_SMALL_FAST_MODEL: 'qwen3.5-plus',
|
|
86
|
+
API_TIMEOUT_MS: '3000000',
|
|
87
|
+
},
|
|
88
|
+
providerAuth: buildProviderAuth({
|
|
89
|
+
providerId: 'alibaba',
|
|
90
|
+
dbKey: 'alibaba',
|
|
91
|
+
envVars: ['ALIBABA_CODE_API_KEY'],
|
|
92
|
+
displayName: 'Alibaba Code',
|
|
93
|
+
helpUrl: 'https://dashscope.aliyun.com',
|
|
94
|
+
}),
|
|
95
|
+
};
|
|
96
|
+
case 'MiniMax-M2.7':
|
|
97
|
+
return {
|
|
98
|
+
env: {
|
|
99
|
+
ANTHROPIC_BASE_URL: 'https://api.minimax.io/anthropic',
|
|
100
|
+
ANTHROPIC_MODEL: 'MiniMax-M2.7',
|
|
101
|
+
ANTHROPIC_SMALL_FAST_MODEL: 'MiniMax-M2.7',
|
|
102
|
+
API_TIMEOUT_MS: '120000',
|
|
103
|
+
},
|
|
104
|
+
providerAuth: buildProviderAuth({
|
|
105
|
+
providerId: 'minimax',
|
|
106
|
+
dbKey: 'minimax',
|
|
107
|
+
envVars: ['MINIMAX_API_KEY'],
|
|
108
|
+
displayName: 'MiniMax',
|
|
109
|
+
helpUrl: 'https://api.minimax.io',
|
|
110
|
+
}),
|
|
111
|
+
};
|
|
112
|
+
default:
|
|
113
|
+
return { env: {}, providerAuth: null };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function resolveCodexCustomProfile(model) {
|
|
118
|
+
if (model.providerId === 'alibaba') {
|
|
119
|
+
const providerName = 'alibaba-code';
|
|
120
|
+
return {
|
|
121
|
+
env: {},
|
|
122
|
+
configOverrides: [
|
|
123
|
+
`model="${model.id}"`,
|
|
124
|
+
`model_provider="${providerName}"`,
|
|
125
|
+
`model_providers.${providerName}.name="Alibaba-Code"`,
|
|
126
|
+
`model_providers.${providerName}.base_url="https://coding-intl.dashscope.aliyuncs.com/v1"`,
|
|
127
|
+
`model_providers.${providerName}.env_key="ALIBABA_CODE_API_KEY"`,
|
|
128
|
+
`model_providers.${providerName}.wire_api="chat"`,
|
|
129
|
+
],
|
|
130
|
+
providerAuth: buildProviderAuth({
|
|
131
|
+
providerId: 'alibaba',
|
|
132
|
+
dbKey: 'alibaba',
|
|
133
|
+
envVars: ['ALIBABA_CODE_API_KEY'],
|
|
134
|
+
displayName: 'Alibaba Code',
|
|
135
|
+
helpUrl: 'https://dashscope.aliyun.com',
|
|
136
|
+
assignOpenAiKey: true,
|
|
137
|
+
}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (model.providerId === 'zai') {
|
|
142
|
+
const providerName = 'zai';
|
|
143
|
+
return {
|
|
144
|
+
env: {},
|
|
145
|
+
configOverrides: [
|
|
146
|
+
`model="${model.id}"`,
|
|
147
|
+
`model_provider="${providerName}"`,
|
|
148
|
+
`model_providers.${providerName}.name="ZAI"`,
|
|
149
|
+
`model_providers.${providerName}.base_url="https://api.z.ai/api/coding/paas/v4"`,
|
|
150
|
+
`model_providers.${providerName}.env_key="ZAI_API_KEY"`,
|
|
151
|
+
`model_providers.${providerName}.wire_api="chat"`,
|
|
152
|
+
],
|
|
153
|
+
providerAuth: buildProviderAuth({
|
|
154
|
+
providerId: 'zai',
|
|
155
|
+
dbKey: 'zai',
|
|
156
|
+
envVars: ['ZAI_API_KEY', 'ZAI_API_KEY_A', 'ZAI_API_KEY_P'],
|
|
157
|
+
displayName: 'Z.ai',
|
|
158
|
+
helpUrl: 'https://z.ai',
|
|
159
|
+
assignOpenAiKey: true,
|
|
160
|
+
}),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (model.providerId === 'chutes') {
|
|
165
|
+
const providerName = 'chutes';
|
|
166
|
+
return {
|
|
167
|
+
env: {},
|
|
168
|
+
configOverrides: [
|
|
169
|
+
`model="${model.id}"`,
|
|
170
|
+
`model_provider="${providerName}"`,
|
|
171
|
+
`model_providers.${providerName}.name="Chutes"`,
|
|
172
|
+
`model_providers.${providerName}.base_url="https://llm.chutes.ai/v1"`,
|
|
173
|
+
`model_providers.${providerName}.env_key="CHUTES_API_KEY"`,
|
|
174
|
+
`model_providers.${providerName}.wire_api="chat"`,
|
|
175
|
+
],
|
|
176
|
+
providerAuth: buildProviderAuth({
|
|
177
|
+
providerId: 'chutes',
|
|
178
|
+
dbKey: 'chutes',
|
|
179
|
+
envVars: ['CHUTES_API_KEY'],
|
|
180
|
+
displayName: 'Chutes',
|
|
181
|
+
helpUrl: 'https://chutes.ai',
|
|
182
|
+
assignOpenAiKey: true,
|
|
183
|
+
}),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return { env: {}, configOverrides: [], providerAuth: null };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function resolveCustomRuntimeProfile(model) {
|
|
191
|
+
if (!model?.custom) {
|
|
192
|
+
return { env: {}, configOverrides: [], providerAuth: null };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (model.engine === 'claude') {
|
|
196
|
+
return {
|
|
197
|
+
configOverrides: [],
|
|
198
|
+
...resolveClaudeCustomProfile(model),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (model.engine === 'codex') {
|
|
203
|
+
return resolveCodexCustomProfile(model);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return { env: {}, configOverrides: [], providerAuth: null };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function getRuntimeDefaults(platformId) {
|
|
210
|
+
return {
|
|
211
|
+
claude: {
|
|
212
|
+
native: {
|
|
213
|
+
runtimeId: 'claude-native',
|
|
214
|
+
command: 'claude',
|
|
215
|
+
source: 'npm',
|
|
216
|
+
installCommand: `${npmCommand()} install -g @anthropic-ai/claude-code@latest`,
|
|
217
|
+
updateCommand: `${npmCommand()} update -g @anthropic-ai/claude-code`,
|
|
218
|
+
checkCommand: 'claude --version',
|
|
219
|
+
sharedBinary: true,
|
|
220
|
+
},
|
|
221
|
+
custom: {
|
|
222
|
+
runtimeId: 'claude-custom',
|
|
223
|
+
command: 'claude',
|
|
224
|
+
source: 'shared-cli',
|
|
225
|
+
installCommand: `${npmCommand()} install -g @anthropic-ai/claude-code@latest`,
|
|
226
|
+
updateCommand: `${npmCommand()} update -g @anthropic-ai/claude-code`,
|
|
227
|
+
checkCommand: 'claude --version',
|
|
228
|
+
sharedBinary: true,
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
codex: {
|
|
232
|
+
native: {
|
|
233
|
+
runtimeId: 'codex-native',
|
|
234
|
+
command: 'codex',
|
|
235
|
+
source: 'npm',
|
|
236
|
+
installCommand: `${npmCommand()} install -g @openai/codex@latest`,
|
|
237
|
+
updateCommand: `${npmCommand()} update -g @openai/codex`,
|
|
238
|
+
checkCommand: 'codex --version',
|
|
239
|
+
},
|
|
240
|
+
custom: {
|
|
241
|
+
runtimeId: 'codex-custom',
|
|
242
|
+
command: 'codex-lts',
|
|
243
|
+
source: platformId === 'termux' ? 'npm' : 'manual',
|
|
244
|
+
installCommand: platformId === 'termux'
|
|
245
|
+
? `${npmCommand()} install -g @mmmbuto/codex-cli-termux@0.80.6-lts`
|
|
246
|
+
: null,
|
|
247
|
+
updateCommand: platformId === 'termux'
|
|
248
|
+
? `${npmCommand()} update -g @mmmbuto/codex-cli-termux`
|
|
249
|
+
: null,
|
|
250
|
+
checkCommand: 'codex-lts --version',
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
gemini: {
|
|
254
|
+
native: {
|
|
255
|
+
runtimeId: 'gemini-native',
|
|
256
|
+
command: 'gemini',
|
|
257
|
+
source: 'npm',
|
|
258
|
+
installCommand: `${npmCommand()} install -g @google/gemini-cli@latest`,
|
|
259
|
+
updateCommand: `${npmCommand()} update -g @google/gemini-cli`,
|
|
260
|
+
checkCommand: 'gemini --version',
|
|
261
|
+
},
|
|
262
|
+
custom: {
|
|
263
|
+
runtimeId: 'gemini-custom',
|
|
264
|
+
command: 'gemini',
|
|
265
|
+
source: 'npm',
|
|
266
|
+
installCommand: `${npmCommand()} install -g @google/gemini-cli@latest`,
|
|
267
|
+
updateCommand: `${npmCommand()} update -g @google/gemini-cli`,
|
|
268
|
+
checkCommand: 'gemini --version',
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
qwen: {
|
|
272
|
+
native: {
|
|
273
|
+
runtimeId: 'qwen-native',
|
|
274
|
+
command: 'qwen',
|
|
275
|
+
source: platformId === 'termux' ? 'npm' : 'npm',
|
|
276
|
+
installCommand: `${npmCommand()} install -g @qwen-code/qwen-code@latest`,
|
|
277
|
+
updateCommand: `${npmCommand()} update -g @qwen-code/qwen-code`,
|
|
278
|
+
checkCommand: 'qwen --version',
|
|
279
|
+
},
|
|
280
|
+
custom: {
|
|
281
|
+
runtimeId: 'qwen-custom',
|
|
282
|
+
command: 'qwen',
|
|
283
|
+
source: platformId === 'termux' ? 'npm' : 'npm',
|
|
284
|
+
installCommand: `${npmCommand()} install -g @qwen-code/qwen-code@latest`,
|
|
285
|
+
updateCommand: `${npmCommand()} update -g @qwen-code/qwen-code`,
|
|
286
|
+
checkCommand: 'qwen --version',
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
class RuntimeManager {
|
|
293
|
+
constructor() {
|
|
294
|
+
this.platformId = getPlatformId();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
getToolCatalog() {
|
|
298
|
+
return getCliTools();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
getRuntimeDefinitions() {
|
|
302
|
+
const config = getConfig();
|
|
303
|
+
const defaults = getRuntimeDefaults(this.platformId);
|
|
304
|
+
const engines = this.getToolCatalog();
|
|
305
|
+
|
|
306
|
+
return Object.fromEntries(
|
|
307
|
+
Object.entries(engines).map(([engineId, engine]) => {
|
|
308
|
+
const configEngine = config.engines?.[engineId] || {};
|
|
309
|
+
const configLanes = configEngine.lanes || {};
|
|
310
|
+
const lanes = Object.fromEntries(
|
|
311
|
+
Object.entries(engine.lanes || {}).map(([laneId, lane]) => {
|
|
312
|
+
const defaultLane = defaults[engineId]?.[laneId] || {};
|
|
313
|
+
const configuredLane = configLanes[laneId] || {};
|
|
314
|
+
const command = configuredLane.command || configEngine.path || defaultLane.command;
|
|
315
|
+
const runtimeId = configuredLane.runtimeId || lane.runtimeId || defaultLane.runtimeId;
|
|
316
|
+
const enabled = configuredLane.enabled ?? configEngine.enabled ?? true;
|
|
317
|
+
|
|
318
|
+
return [laneId, {
|
|
319
|
+
engine: engineId,
|
|
320
|
+
lane: laneId,
|
|
321
|
+
laneLabel: lane.label || laneId,
|
|
322
|
+
runtimeId,
|
|
323
|
+
command,
|
|
324
|
+
enabled,
|
|
325
|
+
source: configuredLane.source || defaultLane.source || 'manual',
|
|
326
|
+
installCommand: configuredLane.installCommand || defaultLane.installCommand || null,
|
|
327
|
+
updateCommand: configuredLane.updateCommand || defaultLane.updateCommand || null,
|
|
328
|
+
checkCommand: configuredLane.checkCommand || defaultLane.checkCommand || `${command} --version`,
|
|
329
|
+
sharedBinary: configuredLane.sharedBinary ?? defaultLane.sharedBinary ?? false,
|
|
330
|
+
}];
|
|
331
|
+
})
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
return [engineId, lanes];
|
|
335
|
+
})
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async probeCommand(command) {
|
|
340
|
+
if (!command) {
|
|
341
|
+
return { available: false, version: null, error: 'command not configured' };
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
try {
|
|
345
|
+
const { stdout, stderr } = await execFileAsync(command, ['--version'], {
|
|
346
|
+
timeout: 10000,
|
|
347
|
+
env: process.env,
|
|
348
|
+
});
|
|
349
|
+
return {
|
|
350
|
+
available: true,
|
|
351
|
+
version: (stdout || stderr || '').trim() || 'unknown',
|
|
352
|
+
error: null,
|
|
353
|
+
};
|
|
354
|
+
} catch (error) {
|
|
355
|
+
return {
|
|
356
|
+
available: false,
|
|
357
|
+
version: null,
|
|
358
|
+
error: error.message,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async getRuntimeInventory() {
|
|
364
|
+
const definitions = this.getRuntimeDefinitions();
|
|
365
|
+
const tools = this.getToolCatalog();
|
|
366
|
+
const inventory = [];
|
|
367
|
+
|
|
368
|
+
for (const [engineId, lanes] of Object.entries(definitions)) {
|
|
369
|
+
for (const [laneId, runtime] of Object.entries(lanes)) {
|
|
370
|
+
const probe = await this.probeCommand(runtime.command);
|
|
371
|
+
const laneModels = tools[engineId]?.models?.filter((model) => model.lane === laneId) || [];
|
|
372
|
+
inventory.push({
|
|
373
|
+
...runtime,
|
|
374
|
+
platform: this.platformId,
|
|
375
|
+
status: probe.available ? 'available' : 'missing',
|
|
376
|
+
installedVersion: probe.version,
|
|
377
|
+
latestVersion: 'upstream',
|
|
378
|
+
available: probe.available,
|
|
379
|
+
error: probe.error,
|
|
380
|
+
models: laneModels.map((model) => ({
|
|
381
|
+
id: model.id,
|
|
382
|
+
label: model.label,
|
|
383
|
+
providerId: model.providerId,
|
|
384
|
+
})),
|
|
385
|
+
actions: [
|
|
386
|
+
runtime.installCommand ? 'install' : null,
|
|
387
|
+
runtime.updateCommand ? 'update' : null,
|
|
388
|
+
'check',
|
|
389
|
+
].filter(Boolean),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return inventory;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
async getRuntimeInventoryMap() {
|
|
398
|
+
const inventory = await this.getRuntimeInventory();
|
|
399
|
+
return Object.fromEntries(inventory.map((item) => [item.runtimeId, item]));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
async getRuntimeAwareCliTools() {
|
|
403
|
+
const tools = this.getToolCatalog();
|
|
404
|
+
const inventoryMap = await this.getRuntimeInventoryMap();
|
|
405
|
+
|
|
406
|
+
return Object.fromEntries(Object.entries(tools).map(([engineId, engine]) => {
|
|
407
|
+
const models = (engine.models || []).map((model) => {
|
|
408
|
+
const runtime = inventoryMap[model.runtimeId];
|
|
409
|
+
return {
|
|
410
|
+
...model,
|
|
411
|
+
availability: runtime?.status || 'unknown',
|
|
412
|
+
runtimeStatus: runtime?.status || 'unknown',
|
|
413
|
+
runtimeCommand: runtime?.command || null,
|
|
414
|
+
runtimeSource: runtime?.source || null,
|
|
415
|
+
available: runtime?.available ?? false,
|
|
416
|
+
};
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
return [engineId, {
|
|
420
|
+
...engine,
|
|
421
|
+
models,
|
|
422
|
+
}];
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
resolveModel(modelId) {
|
|
427
|
+
return getModelById(modelId) || getModelById(getDefaultModelId());
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
resolveRuntimeSelection({ engine, lane, runtimeId, modelId }) {
|
|
431
|
+
const model = this.resolveModel(modelId);
|
|
432
|
+
const resolvedEngine = engine || model?.engine;
|
|
433
|
+
const resolvedLane = lane || model?.lane || 'native';
|
|
434
|
+
const definitions = this.getRuntimeDefinitions();
|
|
435
|
+
const runtime = runtimeId
|
|
436
|
+
? Object.values(definitions[resolvedEngine] || {}).find((entry) => entry.runtimeId === runtimeId)
|
|
437
|
+
: definitions[resolvedEngine]?.[resolvedLane];
|
|
438
|
+
const customProfile = resolveCustomRuntimeProfile(model);
|
|
439
|
+
|
|
440
|
+
return {
|
|
441
|
+
engine: resolvedEngine,
|
|
442
|
+
lane: resolvedLane,
|
|
443
|
+
runtimeId: runtime?.runtimeId || model?.runtimeId || null,
|
|
444
|
+
command: runtime?.command || null,
|
|
445
|
+
env: customProfile.env || {},
|
|
446
|
+
configOverrides: customProfile.configOverrides || [],
|
|
447
|
+
providerAuth: customProfile.providerAuth || null,
|
|
448
|
+
model,
|
|
449
|
+
runtime,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
resolveAction(runtimeId, action) {
|
|
454
|
+
const definitions = this.getRuntimeDefinitions();
|
|
455
|
+
for (const lanes of Object.values(definitions)) {
|
|
456
|
+
for (const runtime of Object.values(lanes)) {
|
|
457
|
+
if (runtime.runtimeId !== runtimeId) continue;
|
|
458
|
+
if (action === 'install') return runtime.installCommand;
|
|
459
|
+
if (action === 'update') return runtime.updateCommand;
|
|
460
|
+
if (action === 'check') return runtime.checkCommand;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
module.exports = RuntimeManager;
|
|
@@ -161,14 +161,19 @@ class SessionImporter {
|
|
|
161
161
|
|
|
162
162
|
/**
|
|
163
163
|
* Controlla se la sessione esiste già
|
|
164
|
+
* Returns false if sessions table doesn't exist (allows import)
|
|
164
165
|
*/
|
|
165
166
|
sessionExists(sessionId) {
|
|
166
167
|
try {
|
|
167
168
|
const stmt = prepare('SELECT 1 FROM sessions WHERE id = ?');
|
|
168
169
|
return !!stmt.get(sessionId);
|
|
169
170
|
} catch (err) {
|
|
171
|
+
// If sessions table doesn't exist, return false to allow import
|
|
172
|
+
if (err.message && err.message.includes('no such table')) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
170
175
|
console.warn(`[SessionImporter] exists check failed: ${err.message}`);
|
|
171
|
-
return true; // default to skip to avoid duplicates
|
|
176
|
+
return true; // default to skip to avoid duplicates on other errors
|
|
172
177
|
}
|
|
173
178
|
}
|
|
174
179
|
|
|
@@ -172,6 +172,37 @@ class SessionManager {
|
|
|
172
172
|
return workspacePath.replace(/\/+$/, '');
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
_buildRuntimeState(engine, options = {}) {
|
|
176
|
+
const normalizedEngine = this._normalizeEngine(engine);
|
|
177
|
+
return {
|
|
178
|
+
lane: options.lane || 'native',
|
|
179
|
+
runtimeId: options.runtimeId || `${normalizedEngine}-native`,
|
|
180
|
+
providerId: options.providerId || null,
|
|
181
|
+
modelId: options.modelId || null,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
_saveSessionRuntimeState(sessionId, runtimeState = {}) {
|
|
186
|
+
try {
|
|
187
|
+
const stmt = prepare(`
|
|
188
|
+
UPDATE sessions
|
|
189
|
+
SET lane = ?, runtime_id = ?, provider_id = ?, model_id = ?, last_used_at = ?
|
|
190
|
+
WHERE id = ?
|
|
191
|
+
`);
|
|
192
|
+
stmt.run(
|
|
193
|
+
runtimeState.lane || 'native',
|
|
194
|
+
runtimeState.runtimeId || null,
|
|
195
|
+
runtimeState.providerId || null,
|
|
196
|
+
runtimeState.modelId || null,
|
|
197
|
+
Date.now(),
|
|
198
|
+
sessionId
|
|
199
|
+
);
|
|
200
|
+
saveDb();
|
|
201
|
+
} catch (error) {
|
|
202
|
+
console.warn(`[SessionManager] Failed to save runtime state for ${sessionId}:`, error.message);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
175
206
|
/**
|
|
176
207
|
* Get or create session for conversation + engine
|
|
177
208
|
*
|
|
@@ -187,10 +218,11 @@ class SessionManager {
|
|
|
187
218
|
* @param {string} workspacePath - Workspace directory path
|
|
188
219
|
* @returns {{ sessionId: string, isNew: boolean }}
|
|
189
220
|
*/
|
|
190
|
-
async getOrCreateSession(conversationId, engine, workspacePath) {
|
|
221
|
+
async getOrCreateSession(conversationId, engine, workspacePath, options = {}) {
|
|
191
222
|
const normalizedEngine = this._normalizeEngine(engine);
|
|
192
223
|
const normalizedPath = this._normalizePath(workspacePath);
|
|
193
224
|
const cacheKey = this._getCacheKey(conversationId, normalizedEngine);
|
|
225
|
+
const runtimeState = this._buildRuntimeState(normalizedEngine, options);
|
|
194
226
|
|
|
195
227
|
console.log(`[SessionManager] getOrCreateSession(${conversationId}, ${normalizedEngine}, ${normalizedPath})`);
|
|
196
228
|
|
|
@@ -223,6 +255,7 @@ class SessionManager {
|
|
|
223
255
|
// 3. Verify session file exists on filesystem
|
|
224
256
|
if (this.sessionFileExists(row.id, normalizedEngine, row.workspace_path || normalizedPath)) {
|
|
225
257
|
// Valid session - update cache and return
|
|
258
|
+
this._saveSessionRuntimeState(row.id, runtimeState);
|
|
226
259
|
this.sessionMap.set(cacheKey, row.id);
|
|
227
260
|
this.lastAccess.set(cacheKey, Date.now());
|
|
228
261
|
console.log(`[SessionManager] DB hit, verified: ${row.id}`);
|
|
@@ -245,11 +278,26 @@ class SessionManager {
|
|
|
245
278
|
// 5. Save to DB (metadata only - file created by CLI)
|
|
246
279
|
try {
|
|
247
280
|
const insertStmt = prepare(`
|
|
248
|
-
INSERT INTO sessions (
|
|
249
|
-
|
|
281
|
+
INSERT INTO sessions (
|
|
282
|
+
id, workspace_path, engine, conversation_id, title, created_at, last_used_at,
|
|
283
|
+
lane, runtime_id, provider_id, model_id
|
|
284
|
+
)
|
|
285
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
250
286
|
`);
|
|
251
287
|
const title = 'New Chat'; // Will be updated after first response
|
|
252
|
-
insertStmt.run(
|
|
288
|
+
insertStmt.run(
|
|
289
|
+
sessionId,
|
|
290
|
+
normalizedPath,
|
|
291
|
+
normalizedEngine,
|
|
292
|
+
conversationId,
|
|
293
|
+
title,
|
|
294
|
+
now,
|
|
295
|
+
now,
|
|
296
|
+
runtimeState.lane,
|
|
297
|
+
runtimeState.runtimeId,
|
|
298
|
+
runtimeState.providerId,
|
|
299
|
+
runtimeState.modelId
|
|
300
|
+
);
|
|
253
301
|
saveDb();
|
|
254
302
|
console.log(`[SessionManager] Saved to DB: ${sessionId}`);
|
|
255
303
|
} catch (dbErr) {
|
|
@@ -310,15 +358,6 @@ class SessionManager {
|
|
|
310
358
|
}
|
|
311
359
|
}
|
|
312
360
|
|
|
313
|
-
/**
|
|
314
|
-
* Convert workspace path to slug (matches Claude Code behavior)
|
|
315
|
-
* /path/to/dir → -path-to-dir (also converts dots to dashes)
|
|
316
|
-
*/
|
|
317
|
-
_pathToSlug(workspacePath) {
|
|
318
|
-
if (!workspacePath) return '-default';
|
|
319
|
-
return workspacePath.replace(/[\/\.]/g, '-');
|
|
320
|
-
}
|
|
321
|
-
|
|
322
361
|
/**
|
|
323
362
|
* Delete all sessions for a conversation (cleanup)
|
|
324
363
|
* Called when conversation is deleted
|
|
@@ -578,8 +617,11 @@ class SessionManager {
|
|
|
578
617
|
const sessionManager = new SessionManager();
|
|
579
618
|
|
|
580
619
|
// Periodic cache cleanup (every 10 minutes)
|
|
581
|
-
setInterval(() => {
|
|
620
|
+
const cleanupTimer = setInterval(() => {
|
|
582
621
|
sessionManager.cleanCache();
|
|
583
622
|
}, 10 * 60 * 1000);
|
|
623
|
+
if (typeof cleanupTimer.unref === 'function') {
|
|
624
|
+
cleanupTimer.unref();
|
|
625
|
+
}
|
|
584
626
|
|
|
585
627
|
module.exports = sessionManager;
|