@openagents-org/agent-launcher 0.2.209 → 0.2.211
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/icons/mimo-code.svg +1 -0
- package/icons/qoder-cn.svg +1 -0
- package/icons/qoder.svg +1 -0
- package/icons/qwen-code.svg +1 -0
- package/package.json +1 -1
- package/registry.json +374 -2
- package/src/adapters/base.js +31 -7
- package/src/adapters/claude.js +44 -10
- package/src/adapters/codex.js +48 -2
- package/src/adapters/cursor.js +5 -3
- package/src/adapters/deepseek.js +21 -3
- package/src/adapters/index.js +13 -1
- package/src/adapters/kimi-stream.js +6 -5
- package/src/adapters/mimo-code-runtime.js +266 -0
- package/src/adapters/mimo-code.js +581 -0
- package/src/adapters/opencode.js +21 -16
- package/src/adapters/pi.js +91 -8
- package/src/adapters/qoder-cn.js +24 -0
- package/src/adapters/qoder-runtime.js +611 -0
- package/src/adapters/qoder.js +946 -0
- package/src/adapters/qwen-code-stream.js +735 -0
- package/src/adapters/qwen-code.js +1125 -0
- package/src/adapters/utils.js +8 -2
- package/src/adapters/workspace-prompt.js +7 -1
- package/src/agent-login.js +93 -0
- package/src/cli-models.js +45 -2
- package/src/cli.js +94 -0
- package/src/daemon.js +80 -4
- package/src/env.js +3 -0
- package/src/installer.js +99 -21
- package/src/node-engines.js +173 -0
- package/src/paths.js +21 -0
- package/src/probe.js +58 -1
- package/src/workspace-client.js +14 -2
package/src/adapters/codex.js
CHANGED
|
@@ -403,6 +403,7 @@ class CodexAdapter extends BaseAdapter {
|
|
|
403
403
|
const fullPrompt = `${context}\n\n---\n\nUser message:\n${content}${this._attachmentInstructions(attachments)}`;
|
|
404
404
|
|
|
405
405
|
// Run up to 2 attempts: first with resume, then fresh if stale
|
|
406
|
+
let relocated = false;
|
|
406
407
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
407
408
|
const cmd = [this._codexBin, 'exec'];
|
|
408
409
|
|
|
@@ -478,6 +479,22 @@ class CodexAdapter extends BaseAdapter {
|
|
|
478
479
|
return;
|
|
479
480
|
}
|
|
480
481
|
} catch (e) {
|
|
482
|
+
// The binary was looked up once, when the adapter started. A reinstall
|
|
483
|
+
// or update since then can move or remove it, and every turn failed
|
|
484
|
+
// with "spawn …/.bin/codex ENOENT" until the agent was restarted.
|
|
485
|
+
// Look again and rerun this attempt once.
|
|
486
|
+
if (e && e.code === 'ENOENT' && !relocated) {
|
|
487
|
+
relocated = true;
|
|
488
|
+
const found = this._findCodexBinary();
|
|
489
|
+
if (found) {
|
|
490
|
+
this._log(`Codex binary moved: ${this._codexBin} → ${found}`);
|
|
491
|
+
this._codexBin = found;
|
|
492
|
+
attempt--;
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
await this.sendError(msgChannel, "⚠️ **Codex couldn't run** — the Codex CLI is no longer installed on this device. Reinstall it from OpenAgents Launcher (Agents → Codex), then try again.");
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
481
498
|
this._log(`Error in subprocess: ${e.message}`);
|
|
482
499
|
await this.sendError(msgChannel, `⚠️ **Codex couldn't run** — ${CodexAdapter._redact(e.message)}`);
|
|
483
500
|
return;
|
|
@@ -730,14 +747,43 @@ class CodexAdapter extends BaseAdapter {
|
|
|
730
747
|
* turn.failed / error event message → stderr tail → exit code. Redacted.
|
|
731
748
|
*/
|
|
732
749
|
static _failureDetail({ errorMessage, stderr, exitCode } = {}) {
|
|
733
|
-
const stderrTail = String(stderr || '').trim().split('\n').slice(-5).join('\n').trim();
|
|
734
750
|
const raw = String(errorMessage || '').trim()
|
|
735
|
-
||
|
|
751
|
+
|| CodexAdapter._stderrReason(stderr)
|
|
736
752
|
|| (exitCode ? `codex exited with code ${exitCode}` : '');
|
|
737
753
|
const detail = CodexAdapter._explain(CodexAdapter._unwrap(raw));
|
|
738
754
|
return CodexAdapter._redact(detail).slice(0, 500).trim();
|
|
739
755
|
}
|
|
740
756
|
|
|
757
|
+
/**
|
|
758
|
+
* The part of codex's stderr that says why the run died.
|
|
759
|
+
*
|
|
760
|
+
* codex logs through `tracing` on stderr — `2026-10-27T04:08:56.500Z WARN
|
|
761
|
+
* codex_skills::interface: …` — and echoes "Reading prompt from stdin..."
|
|
762
|
+
* (or "Reading additional input from stdin...").
|
|
763
|
+
* A plain tail of the last lines was mostly that noise, so a usage limit or
|
|
764
|
+
* a model the account cannot use reached the chat buried under plugin-cache
|
|
765
|
+
* and skill-icon warnings. Lines the CLI printed for a person win; failing
|
|
766
|
+
* those, the ERROR records with their timestamp and module stripped; only
|
|
767
|
+
* when neither exists does the raw tail stand.
|
|
768
|
+
*/
|
|
769
|
+
static _stderrReason(stderr) {
|
|
770
|
+
const lines = String(stderr || '').split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
771
|
+
if (!lines.length) return '';
|
|
772
|
+
const TRACE = /^\d{4}-\d{2}-\d{2}T[\d:.]+Z?\s+(TRACE|DEBUG|INFO|WARN|ERROR)\s+(?:[\w:]+:\s+)?(.*)$/;
|
|
773
|
+
const plain = [];
|
|
774
|
+
const errors = [];
|
|
775
|
+
for (const line of lines) {
|
|
776
|
+
const m = line.match(TRACE);
|
|
777
|
+
if (!m) {
|
|
778
|
+
if (!/^Reading (prompt|additional input) from stdin/i.test(line)) plain.push(line);
|
|
779
|
+
} else if (m[1] === 'ERROR' && m[2] && !errors.includes(m[2])) {
|
|
780
|
+
errors.push(m[2]);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const picked = plain.length ? plain : errors;
|
|
784
|
+
return (picked.length ? picked : lines).slice(-5).join('\n').trim();
|
|
785
|
+
}
|
|
786
|
+
|
|
741
787
|
/**
|
|
742
788
|
* Unwrap the API's JSON error envelope so the user reads the sentence, not
|
|
743
789
|
* the transport. The backend rejects a run with a body like
|
package/src/adapters/cursor.js
CHANGED
|
@@ -638,7 +638,10 @@ class CursorAdapter extends BaseAdapter {
|
|
|
638
638
|
// BaseAdapter._handleUserStop cancels the plan before announcing.
|
|
639
639
|
} else if (!msg._todoNudge) {
|
|
640
640
|
try {
|
|
641
|
-
|
|
641
|
+
// Pending includes work waiting for a human or an earlier step.
|
|
642
|
+
// Only explicitly active work is eligible for automatic continuation.
|
|
643
|
+
const remaining = (await this.getRemainingTodos(msgChannel))
|
|
644
|
+
.filter((todo) => todo.status === 'in_progress');
|
|
642
645
|
if (remaining.length > 0) {
|
|
643
646
|
const items = remaining.map((t) => `- ${t.content}`).join('\n');
|
|
644
647
|
const nudge = `You have ${remaining.length} remaining task(s) from your plan:\n${items}\n\nPlease continue working on them.`;
|
|
@@ -653,9 +656,8 @@ class CursorAdapter extends BaseAdapter {
|
|
|
653
656
|
});
|
|
654
657
|
}
|
|
655
658
|
} catch {}
|
|
656
|
-
} else {
|
|
657
|
-
try { await this.cleanupTodos(msgChannel); } catch {}
|
|
658
659
|
}
|
|
660
|
+
// Finishing a reminder does not cancel tasks waiting for user input.
|
|
659
661
|
|
|
660
662
|
if (stoppedByUser) {
|
|
661
663
|
this._stoppingChannels.delete(msgChannel);
|
package/src/adapters/deepseek.js
CHANGED
|
@@ -54,7 +54,7 @@ const { execFileSync, execSync } = require('child_process');
|
|
|
54
54
|
const { spawn } = require('../wsl');
|
|
55
55
|
|
|
56
56
|
const BaseAdapter = require('./base');
|
|
57
|
-
const { whichBinary, getEnhancedEnv } = require('../paths');
|
|
57
|
+
const { whichBinary, getEnhancedEnv, resolveManagedNpmBinary } = require('../paths');
|
|
58
58
|
const { formatAttachmentsForPrompt } = require('./utils');
|
|
59
59
|
const { buildDeepSeekTaskFile } = require('./workspace-prompt');
|
|
60
60
|
const { sampleRecap } = require('./decision-log');
|
|
@@ -252,7 +252,14 @@ class DeepSeekAdapter extends BaseAdapter {
|
|
|
252
252
|
* when nothing resolves.
|
|
253
253
|
*/
|
|
254
254
|
_resolveDshCommand() {
|
|
255
|
-
|
|
255
|
+
// The launcher-managed copy first, the same Tier 0 the installer uses. A
|
|
256
|
+
// plain PATH lookup ranks every global npm prefix above
|
|
257
|
+
// ~/.openagents/runtimes, so an old global dsh (a 0.1.0-rc.6 left from
|
|
258
|
+
// before the pin moved) shadowed the managed pinned one: the launcher
|
|
259
|
+
// reported the pinned version with nothing to update, while every start
|
|
260
|
+
// refused the global copy as unsupported.
|
|
261
|
+
const bin = resolveManagedNpmBinary('deepseek', '@deepseek-ai/dsh', 'dsh')
|
|
262
|
+
|| whichBinary('dsh');
|
|
256
263
|
if (!bin) return null;
|
|
257
264
|
const nodeBin = this._findNodeBin();
|
|
258
265
|
|
|
@@ -273,6 +280,15 @@ class DeepSeekAdapter extends BaseAdapter {
|
|
|
273
280
|
return null;
|
|
274
281
|
}
|
|
275
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Drop the resolved dsh so the next preflight resolves it afresh — after the
|
|
285
|
+
* daemon installed the pinned version into the managed prefix.
|
|
286
|
+
*/
|
|
287
|
+
forgetRuntime() {
|
|
288
|
+
this._nodeBin = null;
|
|
289
|
+
this._jsEntry = null;
|
|
290
|
+
}
|
|
291
|
+
|
|
276
292
|
/** `dsh -V` output, or null. Synchronous: preflight() is a sync contract. */
|
|
277
293
|
_readDshVersion() {
|
|
278
294
|
if (!this._jsEntry) return null;
|
|
@@ -363,7 +379,9 @@ class DeepSeekAdapter extends BaseAdapter {
|
|
|
363
379
|
|| defaultInstallCommand(supported);
|
|
364
380
|
const gate = classifyDshVersion(this._readDshVersion(), supported, installCmd);
|
|
365
381
|
if (gate.compatible === false || gate.compatible === null) {
|
|
366
|
-
|
|
382
|
+
// repairable: the daemon installs the pinned version and asks again
|
|
383
|
+
// (see Daemon._repairRuntime), so a stale dsh never reaches the user.
|
|
384
|
+
return { ok: false, reason: REASON.VERSION_INCOMPATIBLE, message: gate.message, repairable: true };
|
|
367
385
|
}
|
|
368
386
|
|
|
369
387
|
if (!this._apiKey()) {
|
package/src/adapters/index.js
CHANGED
|
@@ -27,6 +27,10 @@ const CommandCodeAdapter = require('./commandcode');
|
|
|
27
27
|
const OpenWorkerAdapter = require('./openworker');
|
|
28
28
|
const CodeBuddyAdapter = require('./codebuddy');
|
|
29
29
|
const CodeArtsAdapter = require('./codearts');
|
|
30
|
+
const MiMoCodeAdapter = require('./mimo-code');
|
|
31
|
+
const QoderAdapter = require('./qoder');
|
|
32
|
+
const QoderCnAdapter = require('./qoder-cn');
|
|
33
|
+
const QwenCodeAdapter = require('./qwen-code');
|
|
30
34
|
|
|
31
35
|
const ADAPTER_MAP = {
|
|
32
36
|
openclaw: OpenClawAdapter,
|
|
@@ -51,11 +55,15 @@ const ADAPTER_MAP = {
|
|
|
51
55
|
openworker: OpenWorkerAdapter,
|
|
52
56
|
codebuddy: CodeBuddyAdapter,
|
|
53
57
|
codearts: CodeArtsAdapter,
|
|
58
|
+
'mimo-code': MiMoCodeAdapter,
|
|
59
|
+
qoder: QoderAdapter,
|
|
60
|
+
'qoder-cn': QoderCnAdapter,
|
|
61
|
+
'qwen-code': QwenCodeAdapter,
|
|
54
62
|
};
|
|
55
63
|
|
|
56
64
|
/**
|
|
57
65
|
* Create an adapter instance for the given agent type.
|
|
58
|
-
* @param {string} type - Agent type (openclaw, claude, codex, opencode, nanoclaw, cursor, hermes, gemini, kimi, aider, goose, copilot, cline, amp, mini-swe-agent, pi, deepseek, antigravity, commandcode, openworker, codebuddy, codearts)
|
|
66
|
+
* @param {string} type - Agent type (openclaw, claude, codex, opencode, nanoclaw, cursor, hermes, gemini, kimi, aider, goose, copilot, cline, amp, mini-swe-agent, pi, deepseek, antigravity, commandcode, openworker, codebuddy, codearts, mimo-code, qoder, qoder-cn, qwen-code)
|
|
59
67
|
* @param {object} opts - Adapter constructor options
|
|
60
68
|
* @returns {BaseAdapter}
|
|
61
69
|
*/
|
|
@@ -90,6 +98,10 @@ module.exports = {
|
|
|
90
98
|
CommandCodeAdapter,
|
|
91
99
|
OpenWorkerAdapter,
|
|
92
100
|
CodeArtsAdapter,
|
|
101
|
+
MiMoCodeAdapter,
|
|
102
|
+
QoderAdapter,
|
|
103
|
+
QoderCnAdapter,
|
|
104
|
+
QwenCodeAdapter,
|
|
93
105
|
createAdapter,
|
|
94
106
|
ADAPTER_MAP,
|
|
95
107
|
};
|
|
@@ -19,9 +19,10 @@
|
|
|
19
19
|
* 1 permanent failure (config/auth/quota), 75 transient (retryable).
|
|
20
20
|
*
|
|
21
21
|
* IMPORTANT product distinction: two Moonshot products install a `kimi`
|
|
22
|
-
* binary. Kimi Code CLI (npm `@moonshot-ai/kimi-code`) versions are 0.x
|
|
23
|
-
* the legacy Python `kimi-cli` (PyPI) is 1.x and has a
|
|
24
|
-
* interface. A 1.x `kimi --version` therefore means the
|
|
22
|
+
* binary. Kimi Code CLI (npm `@moonshot-ai/kimi-code`) versions are 0.x and
|
|
23
|
+
* 2.x+ (current line); the legacy Python `kimi-cli` (PyPI) is 1.x and has a
|
|
24
|
+
* DIFFERENT headless interface. A 1.x `kimi --version` therefore means the
|
|
25
|
+
* WRONG product.
|
|
25
26
|
*/
|
|
26
27
|
|
|
27
28
|
'use strict';
|
|
@@ -42,7 +43,7 @@ function parseKimiVersion(raw) {
|
|
|
42
43
|
/**
|
|
43
44
|
* Classify `kimi --version` output into a product identity.
|
|
44
45
|
* @returns {{version: string|null, product: 'kimi-code'|'legacy'|null}}
|
|
45
|
-
* 'kimi-code' → the real Kimi Code CLI (0.x) this adapter drives
|
|
46
|
+
* 'kimi-code' → the real Kimi Code CLI (0.x, 2.x+) this adapter drives
|
|
46
47
|
* 'legacy' → the wound-down Python kimi-cli (1.x) — incompatible
|
|
47
48
|
* null → undetermined (unparseable output); proceed leniently
|
|
48
49
|
*/
|
|
@@ -50,7 +51,7 @@ function classifyKimiVersion(rawVersion) {
|
|
|
50
51
|
const version = parseKimiVersion(rawVersion);
|
|
51
52
|
if (!version) return { version: null, product: null };
|
|
52
53
|
const major = parseInt(version.split('.')[0], 10);
|
|
53
|
-
return { version, product: major ===
|
|
54
|
+
return { version, product: major === 1 ? 'legacy' : 'kimi-code' };
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for MiMoCodeAdapter: which provider and model a run goes to,
|
|
3
|
+
* the per-run config handed to the CLI, the process-tree walk Stop needs, and
|
|
4
|
+
* reading the CLI's own error output. No I/O here — the adapter supplies the
|
|
5
|
+
* environment, the process table and the CLI's output.
|
|
6
|
+
*
|
|
7
|
+
* Verified against MiMo Code 0.1.14 and 0.1.15.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
/** MiMo's own OpenAI-compatible API — where a form key goes when no base URL is given. */
|
|
13
|
+
const MIMO_DEFAULT_BASE_URL = 'https://api.xiaomimimo.com/v1';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* MiMo Code's built-in provider for MiMo's API. Routing a MiMo key through it,
|
|
17
|
+
* rather than through a provider we declare, keeps what the CLI's catalog knows
|
|
18
|
+
* about each model: its context window, and that its reasoning has to be sent
|
|
19
|
+
* back between tool calls.
|
|
20
|
+
*/
|
|
21
|
+
const XIAOMI_PROVIDER = 'xiaomi';
|
|
22
|
+
|
|
23
|
+
/** The provider declared for any other OpenAI-compatible endpoint. */
|
|
24
|
+
const CUSTOM_PROVIDER = 'openagents';
|
|
25
|
+
|
|
26
|
+
/** Name of the workspace MCP server; MiMo names its tools `<server>_<tool>`. */
|
|
27
|
+
const MCP_SERVER_NAME = 'openagents-workspace';
|
|
28
|
+
|
|
29
|
+
/** True for MiMo's API and its Token Plan endpoints (token-plan-<region>.xiaomimimo.com). */
|
|
30
|
+
function isMimoHost(baseUrl) {
|
|
31
|
+
let host = '';
|
|
32
|
+
try { host = new URL(String(baseUrl || '').trim()).hostname.toLowerCase(); } catch { return false; }
|
|
33
|
+
return host === 'xiaomimimo.com' || host.endsWith('.xiaomimimo.com');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Where one run goes.
|
|
38
|
+
*
|
|
39
|
+
* With an API key in the agent's configuration (LLM_API_KEY) the run uses that
|
|
40
|
+
* key and nothing else: the base URL defaults to MiMo's API, a MiMo endpoint
|
|
41
|
+
* runs on the built-in `xiaomi` provider and any other on a provider declared
|
|
42
|
+
* for this run. The model id is sent upstream as written — a gateway's
|
|
43
|
+
* `vendor/model` ids included — except that a `xiaomi/` prefix on a MiMo
|
|
44
|
+
* endpoint only repeats the provider and is dropped.
|
|
45
|
+
*
|
|
46
|
+
* Without a key the run is on the Xiaomi-account sign-in (`signIn`, the key
|
|
47
|
+
* and base URL MiMo stored for it, read by the adapter), declared for the run
|
|
48
|
+
* exactly as a key is — so nothing the user configured in MiMo, and no
|
|
49
|
+
* XIAOMI_API_KEY, can stand in for it. A model written `provider/model` with
|
|
50
|
+
* another provider names one the user set up in MiMo Code (`mode: 'own'`) and
|
|
51
|
+
* is taken as given.
|
|
52
|
+
*
|
|
53
|
+
* On MiMo's endpoints a blank model is `fallbackModel`, which the adapter asks
|
|
54
|
+
* the CLI for. There is no fixed default: MiMo drops every model its catalog
|
|
55
|
+
* marks deprecated, and the catalog moves — it marked the v2.5 line deprecated,
|
|
56
|
+
* after which `mimo-v2.5-pro` was "Model not found".
|
|
57
|
+
*
|
|
58
|
+
* The workspace's model choice, when there is one, replaces LLM_MODEL.
|
|
59
|
+
*/
|
|
60
|
+
function resolveMimoRoute(env = {}, workspaceModel = null, { signIn = null, fallbackModel = '' } = {}) {
|
|
61
|
+
const val = (k) => (env[k] == null ? '' : String(env[k])).trim();
|
|
62
|
+
const apiKey = val('LLM_API_KEY');
|
|
63
|
+
const requested = String(workspaceModel || '').trim() || val('LLM_MODEL');
|
|
64
|
+
const fallback = String(fallbackModel || '').trim();
|
|
65
|
+
const bare = (m) => (m.toLowerCase().startsWith(`${XIAOMI_PROVIDER}/`) ? m.slice(XIAOMI_PROVIDER.length + 1) : m);
|
|
66
|
+
const route = (mode, providerId, model, baseURL, key) => ({
|
|
67
|
+
mode, providerId, model, modelRef: model ? `${providerId}/${model}` : '', baseURL, apiKey: key,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (apiKey) {
|
|
71
|
+
const baseURL = val('LLM_BASE_URL') || MIMO_DEFAULT_BASE_URL;
|
|
72
|
+
if (!isMimoHost(baseURL)) return route('key', CUSTOM_PROVIDER, requested, baseURL, apiKey);
|
|
73
|
+
return route('key', XIAOMI_PROVIDER, bare(requested) || bare(fallback), baseURL, apiKey);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const slash = requested.indexOf('/');
|
|
77
|
+
if (slash > 0 && requested.slice(0, slash).toLowerCase() !== XIAOMI_PROVIDER) {
|
|
78
|
+
return route('own', requested.slice(0, slash), requested.slice(slash + 1), '', '');
|
|
79
|
+
}
|
|
80
|
+
const key = signIn && signIn.key ? String(signIn.key) : '';
|
|
81
|
+
const baseURL = key ? (String(signIn.baseURL || '').trim() || MIMO_DEFAULT_BASE_URL) : '';
|
|
82
|
+
return route('signin', XIAOMI_PROVIDER, bare(requested) || bare(fallback), baseURL, key);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* `mimo models xiaomi`: `xiaomi/<model> — window …` per line, deprecated
|
|
87
|
+
* models already left out. Returns the bare ids.
|
|
88
|
+
*/
|
|
89
|
+
function parseMimoModelList(out) {
|
|
90
|
+
const ids = [];
|
|
91
|
+
for (const line of String(out || '').split(/\r?\n/)) {
|
|
92
|
+
const m = line.trim().match(/^xiaomi\/([\w.-]+)(?:\s|$)/);
|
|
93
|
+
if (m && !ids.includes(m[1])) ids.push(m[1]);
|
|
94
|
+
}
|
|
95
|
+
return ids;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The first plain `-pro` model, else the first — the launcher preselects the same. */
|
|
99
|
+
function pickMimoModel(ids) {
|
|
100
|
+
return (ids || []).find((id) => /-pro$/.test(id)) || (ids || [])[0] || '';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The config one run is started with, passed as MIMOCODE_CONFIG_CONTENT. MiMo
|
|
105
|
+
* loads it after the user's global and project config, so what it sets wins;
|
|
106
|
+
* MiMo also keeps that variable out of the environment of the commands its
|
|
107
|
+
* tools run, which is why the key travels here and not as an env var.
|
|
108
|
+
*
|
|
109
|
+
* Routing is pinned to the one provider and model the route names. Without
|
|
110
|
+
* that the user's own MiMo config reroutes parts of the run, under the user's
|
|
111
|
+
* key for another provider: a `small_model` there received every session's
|
|
112
|
+
* first message for titling, and a subagent ran on the user's
|
|
113
|
+
* `agent.general.model`. Providers MiMo picks up from the environment
|
|
114
|
+
* (DASHSCOPE_API_KEY, XIAOMI_API_KEY, …) or its auth.json would likewise stay
|
|
115
|
+
* available to a model the agent names itself — the subagent tool takes a
|
|
116
|
+
* `provider/model` or a model group. Arrays in MiMo's config replace rather
|
|
117
|
+
* than merge, so the provider lists are exactly ours; anything still naming
|
|
118
|
+
* another provider fails instead of leaving.
|
|
119
|
+
*
|
|
120
|
+
* `instructions`, unlike other arrays, MiMo concatenates with the user's own —
|
|
121
|
+
* the workspace briefing is added to them, not swapped in for them.
|
|
122
|
+
*/
|
|
123
|
+
function buildMimoRunConfig(route, { mcp = null, instructions = [] } = {}) {
|
|
124
|
+
const ref = route.modelRef;
|
|
125
|
+
const config = { enabled_providers: [route.providerId], disabled_providers: [] };
|
|
126
|
+
// With no model (the CLI could not be asked for one) the pick is MiMo's; the
|
|
127
|
+
// provider pin alone still keeps every request on it.
|
|
128
|
+
if (ref) {
|
|
129
|
+
Object.assign(config, {
|
|
130
|
+
model: ref,
|
|
131
|
+
small_model: ref,
|
|
132
|
+
model_groups: { lite: ref, standard: ref, ultra: ref },
|
|
133
|
+
agent: { general: { model: ref }, explore: { model: ref } },
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// A key, or the sign-in's key, is declared for the run; MiMo's own
|
|
138
|
+
// credentials are kept out of it (MIMOCODE_AUTH_CONTENT, set by the adapter).
|
|
139
|
+
if (route.apiKey) {
|
|
140
|
+
// `id` is set explicitly: a model entry of the same name in the user's own
|
|
141
|
+
// provider config could otherwise rename what is sent upstream. `headers`
|
|
142
|
+
// is cleared for the same reason — objects merge, so headers the user set
|
|
143
|
+
// on this provider were sent with every request, and an `Authorization`
|
|
144
|
+
// among them replaced the agent's key.
|
|
145
|
+
//
|
|
146
|
+
// A model picked on MiMo's endpoint is marked `beta`: MiMo drops a model
|
|
147
|
+
// its catalog calls deprecated even when the run declares it, and the API
|
|
148
|
+
// the key belongs to still serves those (the picker lists them from it).
|
|
149
|
+
// Choosing one is the user's call. (`active` is not a status MiMo accepts.)
|
|
150
|
+
const xiaomi = route.providerId === XIAOMI_PROVIDER;
|
|
151
|
+
const models = route.model
|
|
152
|
+
? { [route.model]: { id: route.model, name: route.model, ...(xiaomi ? { status: 'beta' } : {}) } }
|
|
153
|
+
: undefined;
|
|
154
|
+
const options = { baseURL: route.baseURL, apiKey: route.apiKey, headers: null };
|
|
155
|
+
config.provider = {
|
|
156
|
+
[route.providerId]: xiaomi
|
|
157
|
+
? { options, ...(models ? { models } : {}) }
|
|
158
|
+
: { npm: '@ai-sdk/openai-compatible', name: 'OpenAgents', options, models },
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (mcp && mcp.command) {
|
|
163
|
+
config.mcp = {
|
|
164
|
+
[MCP_SERVER_NAME]: {
|
|
165
|
+
type: 'local',
|
|
166
|
+
command: [mcp.command, ...(mcp.args || [])],
|
|
167
|
+
environment: mcp.env || {},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const files = (instructions || []).filter(Boolean);
|
|
173
|
+
if (files.length) config.instructions = files;
|
|
174
|
+
return config;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The CLI's `run` arguments. A new session gets a title of ours: without one
|
|
179
|
+
* MiMo asks the model to write it, which is a second request carrying the
|
|
180
|
+
* user's first message. Plan mode is MiMo's own `plan` agent, whose edit ban
|
|
181
|
+
* the permission bypass does not lift.
|
|
182
|
+
*/
|
|
183
|
+
function buildMimoRunArgs({ runCwd, model, sessionId = null, title = '', plan = false } = {}) {
|
|
184
|
+
const args = ['run', '--format', 'json', '--dangerously-skip-permissions', '--dir', runCwd];
|
|
185
|
+
if (model) args.push('--model', model);
|
|
186
|
+
if (plan) args.push('--agent', 'plan');
|
|
187
|
+
if (sessionId) args.push('--session', sessionId);
|
|
188
|
+
else if (title) args.push('--title', title);
|
|
189
|
+
return args;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Every descendant of `rootPid` in a process table of { pid, ppid, pgid } rows,
|
|
194
|
+
* nearest first. MiMo runs each shell command in its own session, so these are
|
|
195
|
+
* not in the CLI's process group, and once the CLI is gone they are reparented
|
|
196
|
+
* — the table has to be read while it is still alive.
|
|
197
|
+
*/
|
|
198
|
+
function descendantsOf(rows, rootPid) {
|
|
199
|
+
const children = new Map();
|
|
200
|
+
for (const r of rows || []) {
|
|
201
|
+
if (!r || !Number.isInteger(r.pid) || r.pid === r.ppid) continue;
|
|
202
|
+
if (!children.has(r.ppid)) children.set(r.ppid, []);
|
|
203
|
+
children.get(r.ppid).push(r);
|
|
204
|
+
}
|
|
205
|
+
const out = [];
|
|
206
|
+
const seen = new Set([rootPid]);
|
|
207
|
+
const queue = [rootPid];
|
|
208
|
+
while (queue.length) {
|
|
209
|
+
const pid = queue.shift();
|
|
210
|
+
for (const c of children.get(pid) || []) {
|
|
211
|
+
if (seen.has(c.pid)) continue;
|
|
212
|
+
seen.add(c.pid);
|
|
213
|
+
out.push(c);
|
|
214
|
+
queue.push(c.pid);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Parse `ps -A -o pid=,ppid=,pgid=` output. */
|
|
221
|
+
function parseProcessTable(text) {
|
|
222
|
+
const rows = [];
|
|
223
|
+
for (const line of String(text || '').split('\n')) {
|
|
224
|
+
const m = line.trim().match(/^(\d+)\s+(\d+)\s+(\d+)$/);
|
|
225
|
+
if (m) rows.push({ pid: Number(m[1]), ppid: Number(m[2]), pgid: Number(m[3]) });
|
|
226
|
+
}
|
|
227
|
+
return rows;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The line that matters in the CLI's stderr. A failure that is not an API
|
|
232
|
+
* error (no credential, an unknown session) prints a chunk of the CLI's bundled
|
|
233
|
+
* source and a stack trace, then exits 0; classifying that source text would
|
|
234
|
+
* find "network" or "timeout" in someone's variable names, so only the error
|
|
235
|
+
* line itself is read: `error: <message>`, or a named error's `message: "…"`.
|
|
236
|
+
*/
|
|
237
|
+
function mimoErrorLine(stderr) {
|
|
238
|
+
const text = String(stderr || '');
|
|
239
|
+
const plain = text.match(/^\s*error:\s*(.+)$/gm);
|
|
240
|
+
if (plain) return plain[plain.length - 1].replace(/^\s*error:\s*/, '').trim();
|
|
241
|
+
const named = text.match(/^([A-Z][A-Za-z]*Error):[^\n]*\n(?:\s*data:\s*\{\s*\n)?\s*message:\s*"([^"\n]*)"/m);
|
|
242
|
+
if (named) return `${named[1]}: ${named[2]}`;
|
|
243
|
+
return '';
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** True when the CLI refused `--session` because it has no such session. */
|
|
247
|
+
function isMissingSession(stderr) {
|
|
248
|
+
return /Session not found/i.test(String(stderr || ''));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
module.exports = {
|
|
252
|
+
MIMO_DEFAULT_BASE_URL,
|
|
253
|
+
XIAOMI_PROVIDER,
|
|
254
|
+
CUSTOM_PROVIDER,
|
|
255
|
+
MCP_SERVER_NAME,
|
|
256
|
+
isMimoHost,
|
|
257
|
+
resolveMimoRoute,
|
|
258
|
+
parseMimoModelList,
|
|
259
|
+
pickMimoModel,
|
|
260
|
+
buildMimoRunConfig,
|
|
261
|
+
buildMimoRunArgs,
|
|
262
|
+
descendantsOf,
|
|
263
|
+
parseProcessTable,
|
|
264
|
+
mimoErrorLine,
|
|
265
|
+
isMissingSession,
|
|
266
|
+
};
|